@agi-cli/sdk 0.1.85 → 0.1.87
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -3,6 +3,7 @@ import { anthropic, createAnthropic } from '@ai-sdk/anthropic';
|
|
|
3
3
|
import { google } from '@ai-sdk/google';
|
|
4
4
|
import { createOpenRouter } from '@openrouter/ai-sdk-provider';
|
|
5
5
|
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
|
|
6
|
+
import { catalog } from '../../../providers/src/index.ts';
|
|
6
7
|
|
|
7
8
|
export type ProviderName =
|
|
8
9
|
| 'openai'
|
|
@@ -58,27 +59,64 @@ export async function resolveModel(
|
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
if (provider === 'opencode') {
|
|
61
|
-
const
|
|
62
|
+
const entry = catalog[provider];
|
|
63
|
+
const normalizedModel = normalizeModelIdentifier(provider, model);
|
|
64
|
+
const modelInfo =
|
|
65
|
+
entry?.models.find((m) => m.id === normalizedModel) ??
|
|
66
|
+
entry?.models.find((m) => m.id === model);
|
|
67
|
+
const resolvedModelId = modelInfo?.id ?? normalizedModel ?? model;
|
|
68
|
+
const binding = modelInfo?.provider?.npm ?? entry?.npm;
|
|
62
69
|
const apiKey = config.apiKey || process.env.OPENCODE_API_KEY || '';
|
|
70
|
+
const baseURL =
|
|
71
|
+
config.baseURL ||
|
|
72
|
+
modelInfo?.provider?.baseURL ||
|
|
73
|
+
modelInfo?.provider?.api ||
|
|
74
|
+
entry?.api ||
|
|
75
|
+
'https://opencode.ai/zen/v1';
|
|
76
|
+
const headers = apiKey ? { Authorization: `Bearer ${apiKey}` } : undefined;
|
|
77
|
+
if (binding === '@ai-sdk/openai') {
|
|
78
|
+
const instance = createOpenAI({ apiKey, baseURL });
|
|
79
|
+
return instance(resolvedModelId);
|
|
80
|
+
}
|
|
81
|
+
if (binding === '@ai-sdk/anthropic') {
|
|
82
|
+
const instance = createAnthropic({ apiKey, baseURL });
|
|
83
|
+
return instance(resolvedModelId);
|
|
84
|
+
}
|
|
85
|
+
if (binding === '@ai-sdk/openai-compatible') {
|
|
86
|
+
const instance = createOpenAICompatible({
|
|
87
|
+
name: entry?.label ?? 'opencode',
|
|
88
|
+
baseURL,
|
|
89
|
+
headers,
|
|
90
|
+
});
|
|
91
|
+
return instance(resolvedModelId);
|
|
92
|
+
}
|
|
63
93
|
|
|
64
94
|
const ocOpenAI = createOpenAI({ apiKey, baseURL });
|
|
65
95
|
const ocAnthropic = createAnthropic({ apiKey, baseURL });
|
|
66
96
|
const ocCompat = createOpenAICompatible({
|
|
67
|
-
name: 'opencode',
|
|
97
|
+
name: entry?.label ?? 'opencode',
|
|
68
98
|
baseURL,
|
|
69
|
-
headers
|
|
99
|
+
headers,
|
|
70
100
|
});
|
|
71
101
|
|
|
72
|
-
const id =
|
|
73
|
-
if (id.includes('claude')) return ocAnthropic(
|
|
102
|
+
const id = resolvedModelId.toLowerCase();
|
|
103
|
+
if (id.includes('claude')) return ocAnthropic(resolvedModelId);
|
|
74
104
|
if (
|
|
75
105
|
id.includes('qwen3-coder') ||
|
|
76
106
|
id.includes('grok-code') ||
|
|
77
107
|
id.includes('kimi-k2')
|
|
78
108
|
)
|
|
79
|
-
return ocCompat(
|
|
80
|
-
return ocOpenAI(
|
|
109
|
+
return ocCompat(resolvedModelId);
|
|
110
|
+
return ocOpenAI(resolvedModelId);
|
|
81
111
|
}
|
|
82
112
|
|
|
83
113
|
throw new Error(`Unsupported provider: ${provider}`);
|
|
84
114
|
}
|
|
115
|
+
|
|
116
|
+
function normalizeModelIdentifier(
|
|
117
|
+
provider: ProviderName,
|
|
118
|
+
model: string,
|
|
119
|
+
): string {
|
|
120
|
+
const prefix = `${provider}/`;
|
|
121
|
+
return model.startsWith(prefix) ? model.slice(prefix.length) : model;
|
|
122
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -13,7 +13,12 @@
|
|
|
13
13
|
// Types (from internal types module)
|
|
14
14
|
// =======================
|
|
15
15
|
// Provider types
|
|
16
|
-
export type {
|
|
16
|
+
export type {
|
|
17
|
+
ProviderId,
|
|
18
|
+
ModelInfo,
|
|
19
|
+
ModelProviderBinding,
|
|
20
|
+
ProviderCatalogEntry,
|
|
21
|
+
} from './types/src/index.ts';
|
|
17
22
|
|
|
18
23
|
// Auth types
|
|
19
24
|
export type { ApiAuth, OAuth, AuthInfo, AuthFile } from './types/src/index.ts';
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
// AUTO-GENERATED by scripts/update-catalog.ts. Do not edit manually.
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
ProviderId,
|
|
5
|
+
ProviderCatalogEntry,
|
|
6
|
+
} from '../../types/src/index.ts';
|
|
4
7
|
|
|
5
|
-
export const catalog: Record<ProviderId,
|
|
8
|
+
export const catalog: Record<ProviderId, ProviderCatalogEntry> = {
|
|
6
9
|
openai: {
|
|
10
|
+
id: 'openai',
|
|
7
11
|
models: [
|
|
8
12
|
{
|
|
9
13
|
id: 'codex-mini-latest',
|
|
@@ -675,8 +679,13 @@ export const catalog: Record<ProviderId, { models: ModelInfo[] }> = {
|
|
|
675
679
|
},
|
|
676
680
|
},
|
|
677
681
|
],
|
|
682
|
+
label: 'OpenAI',
|
|
683
|
+
env: ['OPENAI_API_KEY'],
|
|
684
|
+
npm: '@ai-sdk/openai',
|
|
685
|
+
doc: 'https://platform.openai.com/docs/models',
|
|
678
686
|
},
|
|
679
687
|
anthropic: {
|
|
688
|
+
id: 'anthropic',
|
|
680
689
|
models: [
|
|
681
690
|
{
|
|
682
691
|
id: 'claude-3-5-haiku-20241022',
|
|
@@ -954,8 +963,13 @@ export const catalog: Record<ProviderId, { models: ModelInfo[] }> = {
|
|
|
954
963
|
},
|
|
955
964
|
},
|
|
956
965
|
],
|
|
966
|
+
label: 'Anthropic',
|
|
967
|
+
env: ['ANTHROPIC_API_KEY'],
|
|
968
|
+
npm: '@ai-sdk/anthropic',
|
|
969
|
+
doc: 'https://docs.anthropic.com/en/docs/about-claude/models',
|
|
957
970
|
},
|
|
958
971
|
google: {
|
|
972
|
+
id: 'google',
|
|
959
973
|
models: [
|
|
960
974
|
{
|
|
961
975
|
id: 'gemini-1.5-flash',
|
|
@@ -1528,8 +1542,13 @@ export const catalog: Record<ProviderId, { models: ModelInfo[] }> = {
|
|
|
1528
1542
|
},
|
|
1529
1543
|
},
|
|
1530
1544
|
],
|
|
1545
|
+
label: 'Google',
|
|
1546
|
+
env: ['GOOGLE_GENERATIVE_AI_API_KEY', 'GEMINI_API_KEY'],
|
|
1547
|
+
npm: '@ai-sdk/google',
|
|
1548
|
+
doc: 'https://ai.google.dev/gemini-api/docs/pricing',
|
|
1531
1549
|
},
|
|
1532
1550
|
openrouter: {
|
|
1551
|
+
id: 'openrouter',
|
|
1533
1552
|
models: [
|
|
1534
1553
|
{
|
|
1535
1554
|
id: 'anthropic/claude-3.5-haiku',
|
|
@@ -4072,9 +4091,39 @@ export const catalog: Record<ProviderId, { models: ModelInfo[] }> = {
|
|
|
4072
4091
|
},
|
|
4073
4092
|
},
|
|
4074
4093
|
],
|
|
4094
|
+
label: 'OpenRouter',
|
|
4095
|
+
env: ['OPENROUTER_API_KEY'],
|
|
4096
|
+
npm: '@ai-sdk/openai-compatible',
|
|
4097
|
+
api: 'https://openrouter.ai/api/v1',
|
|
4098
|
+
doc: 'https://openrouter.ai/models',
|
|
4075
4099
|
},
|
|
4076
4100
|
opencode: {
|
|
4101
|
+
id: 'opencode',
|
|
4077
4102
|
models: [
|
|
4103
|
+
{
|
|
4104
|
+
id: 'an-g8x',
|
|
4105
|
+
label: 'Code G8X (alpha)',
|
|
4106
|
+
modalities: {
|
|
4107
|
+
input: ['text'],
|
|
4108
|
+
output: ['text'],
|
|
4109
|
+
},
|
|
4110
|
+
toolCall: true,
|
|
4111
|
+
reasoning: true,
|
|
4112
|
+
attachment: false,
|
|
4113
|
+
temperature: true,
|
|
4114
|
+
knowledge: '2025-01',
|
|
4115
|
+
releaseDate: '2025-07-30',
|
|
4116
|
+
lastUpdated: '2025-07-30',
|
|
4117
|
+
openWeights: true,
|
|
4118
|
+
cost: {
|
|
4119
|
+
input: 0.5,
|
|
4120
|
+
output: 2,
|
|
4121
|
+
},
|
|
4122
|
+
limit: {
|
|
4123
|
+
context: 200000,
|
|
4124
|
+
output: 128000,
|
|
4125
|
+
},
|
|
4126
|
+
},
|
|
4078
4127
|
{
|
|
4079
4128
|
id: 'claude-3-5-haiku',
|
|
4080
4129
|
label: 'Claude Haiku 3.5',
|
|
@@ -4099,6 +4148,9 @@ export const catalog: Record<ProviderId, { models: ModelInfo[] }> = {
|
|
|
4099
4148
|
context: 200000,
|
|
4100
4149
|
output: 8192,
|
|
4101
4150
|
},
|
|
4151
|
+
provider: {
|
|
4152
|
+
npm: '@ai-sdk/anthropic',
|
|
4153
|
+
},
|
|
4102
4154
|
},
|
|
4103
4155
|
{
|
|
4104
4156
|
id: 'claude-opus-4-1',
|
|
@@ -4124,6 +4176,9 @@ export const catalog: Record<ProviderId, { models: ModelInfo[] }> = {
|
|
|
4124
4176
|
context: 200000,
|
|
4125
4177
|
output: 32000,
|
|
4126
4178
|
},
|
|
4179
|
+
provider: {
|
|
4180
|
+
npm: '@ai-sdk/anthropic',
|
|
4181
|
+
},
|
|
4127
4182
|
},
|
|
4128
4183
|
{
|
|
4129
4184
|
id: 'claude-sonnet-4',
|
|
@@ -4149,6 +4204,9 @@ export const catalog: Record<ProviderId, { models: ModelInfo[] }> = {
|
|
|
4149
4204
|
context: 1000000,
|
|
4150
4205
|
output: 64000,
|
|
4151
4206
|
},
|
|
4207
|
+
provider: {
|
|
4208
|
+
npm: '@ai-sdk/anthropic',
|
|
4209
|
+
},
|
|
4152
4210
|
},
|
|
4153
4211
|
{
|
|
4154
4212
|
id: 'claude-sonnet-4-5',
|
|
@@ -4174,53 +4232,8 @@ export const catalog: Record<ProviderId, { models: ModelInfo[] }> = {
|
|
|
4174
4232
|
context: 1000000,
|
|
4175
4233
|
output: 64000,
|
|
4176
4234
|
},
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
id: 'code-g1x',
|
|
4180
|
-
label: 'Code G1X (alpha)',
|
|
4181
|
-
modalities: {
|
|
4182
|
-
input: ['text'],
|
|
4183
|
-
output: ['text'],
|
|
4184
|
-
},
|
|
4185
|
-
toolCall: true,
|
|
4186
|
-
reasoning: true,
|
|
4187
|
-
attachment: false,
|
|
4188
|
-
temperature: true,
|
|
4189
|
-
knowledge: '2025-01',
|
|
4190
|
-
releaseDate: '2025-07-30',
|
|
4191
|
-
lastUpdated: '2025-07-30',
|
|
4192
|
-
openWeights: true,
|
|
4193
|
-
cost: {
|
|
4194
|
-
input: 0.5,
|
|
4195
|
-
output: 2,
|
|
4196
|
-
},
|
|
4197
|
-
limit: {
|
|
4198
|
-
context: 200000,
|
|
4199
|
-
output: 128000,
|
|
4200
|
-
},
|
|
4201
|
-
},
|
|
4202
|
-
{
|
|
4203
|
-
id: 'code-g8x',
|
|
4204
|
-
label: 'Code G8X (alpha)',
|
|
4205
|
-
modalities: {
|
|
4206
|
-
input: ['text'],
|
|
4207
|
-
output: ['text'],
|
|
4208
|
-
},
|
|
4209
|
-
toolCall: true,
|
|
4210
|
-
reasoning: true,
|
|
4211
|
-
attachment: false,
|
|
4212
|
-
temperature: true,
|
|
4213
|
-
knowledge: '2025-01',
|
|
4214
|
-
releaseDate: '2025-07-30',
|
|
4215
|
-
lastUpdated: '2025-07-30',
|
|
4216
|
-
openWeights: true,
|
|
4217
|
-
cost: {
|
|
4218
|
-
input: 0.5,
|
|
4219
|
-
output: 2,
|
|
4220
|
-
},
|
|
4221
|
-
limit: {
|
|
4222
|
-
context: 200000,
|
|
4223
|
-
output: 128000,
|
|
4235
|
+
provider: {
|
|
4236
|
+
npm: '@ai-sdk/anthropic',
|
|
4224
4237
|
},
|
|
4225
4238
|
},
|
|
4226
4239
|
{
|
|
@@ -4295,6 +4308,9 @@ export const catalog: Record<ProviderId, { models: ModelInfo[] }> = {
|
|
|
4295
4308
|
context: 400000,
|
|
4296
4309
|
output: 128000,
|
|
4297
4310
|
},
|
|
4311
|
+
provider: {
|
|
4312
|
+
npm: '@ai-sdk/openai',
|
|
4313
|
+
},
|
|
4298
4314
|
},
|
|
4299
4315
|
{
|
|
4300
4316
|
id: 'gpt-5-codex',
|
|
@@ -4320,6 +4336,9 @@ export const catalog: Record<ProviderId, { models: ModelInfo[] }> = {
|
|
|
4320
4336
|
context: 400000,
|
|
4321
4337
|
output: 128000,
|
|
4322
4338
|
},
|
|
4339
|
+
provider: {
|
|
4340
|
+
npm: '@ai-sdk/openai',
|
|
4341
|
+
},
|
|
4323
4342
|
},
|
|
4324
4343
|
{
|
|
4325
4344
|
id: 'grok-code',
|
|
@@ -4395,5 +4414,10 @@ export const catalog: Record<ProviderId, { models: ModelInfo[] }> = {
|
|
|
4395
4414
|
},
|
|
4396
4415
|
},
|
|
4397
4416
|
],
|
|
4417
|
+
label: 'OpenCode Zen',
|
|
4418
|
+
env: ['OPENCODE_API_KEY'],
|
|
4419
|
+
npm: '@ai-sdk/openai-compatible',
|
|
4420
|
+
api: 'https://opencode.ai/zen/v1',
|
|
4421
|
+
doc: 'https://opencode.ai/docs/zen',
|
|
4398
4422
|
},
|
|
4399
|
-
} as const satisfies Record<ProviderId,
|
|
4423
|
+
} as const satisfies Record<ProviderId, ProviderCatalogEntry>;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
export { isProviderAuthorized, ensureProviderEnv } from './authorization.ts';
|
|
2
2
|
export { catalog } from './catalog.ts';
|
|
3
|
-
export type {
|
|
3
|
+
export type {
|
|
4
|
+
ProviderId,
|
|
5
|
+
ModelInfo,
|
|
6
|
+
ModelProviderBinding,
|
|
7
|
+
ProviderCatalogEntry,
|
|
8
|
+
} from '../../types/src/index.ts';
|
|
4
9
|
export {
|
|
5
10
|
isProviderId,
|
|
6
11
|
providerIds,
|
package/src/types/src/index.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
// Provider types
|
|
2
|
-
export type {
|
|
2
|
+
export type {
|
|
3
|
+
ProviderId,
|
|
4
|
+
ModelInfo,
|
|
5
|
+
ModelProviderBinding,
|
|
6
|
+
ProviderCatalogEntry,
|
|
7
|
+
} from './provider';
|
|
3
8
|
|
|
4
9
|
// Auth types
|
|
5
10
|
export type { ApiAuth, OAuth, AuthInfo, AuthFile } from './auth';
|
|
@@ -8,6 +8,13 @@ export type ProviderId =
|
|
|
8
8
|
| 'openrouter'
|
|
9
9
|
| 'opencode';
|
|
10
10
|
|
|
11
|
+
export type ModelProviderBinding = {
|
|
12
|
+
id?: string;
|
|
13
|
+
npm?: string;
|
|
14
|
+
api?: string;
|
|
15
|
+
baseURL?: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
11
18
|
/**
|
|
12
19
|
* Information about a specific model
|
|
13
20
|
*/
|
|
@@ -25,4 +32,15 @@ export type ModelInfo = {
|
|
|
25
32
|
openWeights?: boolean;
|
|
26
33
|
cost?: { input?: number; output?: number; cacheRead?: number };
|
|
27
34
|
limit?: { context?: number; output?: number };
|
|
35
|
+
provider?: ModelProviderBinding;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type ProviderCatalogEntry = {
|
|
39
|
+
id: ProviderId;
|
|
40
|
+
label?: string;
|
|
41
|
+
env?: string[];
|
|
42
|
+
npm?: string;
|
|
43
|
+
api?: string;
|
|
44
|
+
doc?: string;
|
|
45
|
+
models: ModelInfo[];
|
|
28
46
|
};
|