Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/verify-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ jobs:
- name: Check format
run: npm run format

build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Setup Node.js
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version-file: '.nvmrc'
cache: npm
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build

test:
name: Test (${{ matrix.os }}, Node ${{ matrix.node-version }})
runs-on: ${{ matrix.os }}
Expand Down
21 changes: 15 additions & 6 deletions lifecycle/getModel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { anthropic } from '@ai-sdk/anthropic';
import { google } from '@ai-sdk/google';
import { openai } from '@ai-sdk/openai';
import { aisdk, AiSdkModel } from '@openai/agents-extensions/ai-sdk';
import type { Model } from '@openai/agents';
import { aisdk } from '@openai/agents-extensions/ai-sdk';
import { createOllama, ollama } from 'ollama-ai-provider-v2';
import { defaultOpenAIModel } from '../agent/defaults';
import type { ModelProvider } from '../ink/models/config';
Expand Down Expand Up @@ -36,24 +37,32 @@ export function getProvider(modelName: string): ModelProvider {
return 'OpenAI';
}

export function getModel(modelName: string): AiSdkModel {
export function getModel(modelName: string): Model {
// `aisdk()` returns an `AiSdkModel`, which implements `Model` but declares
// `getResponse`'s `rawUsage` as `Record<string, unknown> | undefined`. Under
// this repo's `exactOptionalPropertyTypes`, that is not assignable to core's
// `Model`, so bridge the upstream type-declaration mismatch with one cast.
return aisdk(getLanguageModel(modelName)) as Model;
}

function getLanguageModel(modelName: string) {
if (modelName.startsWith('claude-')) {
return aisdk(anthropic(modelName));
return anthropic(modelName);
}

if (modelName.startsWith('gemini-')) {
return aisdk(google(modelName));
return google(modelName);
}

if (modelName.startsWith('ollama-') || modelName.includes(':')) {
const ollamaBaseUrl = process.env.OLLAMA_BASE_URL ? normalizeOllamaBaseUrl(process.env.OLLAMA_BASE_URL) : undefined;
const ollamaProvider = ollamaBaseUrl
? createOllama({ baseURL: ollamaBaseUrl, compatibility: 'strict' })
: ollama;
return aisdk(ollamaProvider(getModelName(modelName)));
return ollamaProvider(getModelName(modelName));
}

return aisdk(openai(modelName));
return openai(modelName);
}

export function getModelName(modelName: string): string {
Expand Down
Loading