@agi-cli/server 0.1.84 → 0.1.86
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 +3 -3
- package/src/runtime/provider.ts +42 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agi-cli/server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.86",
|
|
4
4
|
"description": "HTTP API server for AGI CLI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"typecheck": "tsc --noEmit"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@agi-cli/sdk": "0.1.
|
|
33
|
-
"@agi-cli/database": "0.1.
|
|
32
|
+
"@agi-cli/sdk": "0.1.86",
|
|
33
|
+
"@agi-cli/database": "0.1.86",
|
|
34
34
|
"drizzle-orm": "^0.44.5",
|
|
35
35
|
"hono": "^4.9.9",
|
|
36
36
|
"zod": "^4.1.8"
|
package/src/runtime/provider.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import type { AGIConfig } from '@agi-cli/sdk';
|
|
2
|
-
import
|
|
1
|
+
import type { AGIConfig, ProviderId } from '@agi-cli/sdk';
|
|
2
|
+
import { catalog, getAuth, refreshToken, setAuth } from '@agi-cli/sdk';
|
|
3
3
|
import { openai, createOpenAI } from '@ai-sdk/openai';
|
|
4
4
|
import { anthropic, createAnthropic } from '@ai-sdk/anthropic';
|
|
5
5
|
import { google } from '@ai-sdk/google';
|
|
6
6
|
import { createOpenRouter } from '@openrouter/ai-sdk-provider';
|
|
7
7
|
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
|
|
8
|
-
import { getAuth } from '@agi-cli/sdk';
|
|
9
|
-
import { refreshToken } from '@agi-cli/sdk';
|
|
10
|
-
import { setAuth } from '@agi-cli/sdk';
|
|
11
8
|
|
|
12
9
|
export type ProviderName = ProviderId;
|
|
13
10
|
|
|
@@ -113,26 +110,59 @@ export async function resolveModel(
|
|
|
113
110
|
return openrouter.chat(model);
|
|
114
111
|
}
|
|
115
112
|
if (provider === 'opencode') {
|
|
116
|
-
const
|
|
113
|
+
const entry = catalog[provider];
|
|
114
|
+
const normalizedModel = normalizeModelIdentifier(provider, model);
|
|
115
|
+
const modelInfo =
|
|
116
|
+
entry?.models.find((m) => m.id === normalizedModel) ??
|
|
117
|
+
entry?.models.find((m) => m.id === model);
|
|
118
|
+
const resolvedModelId = modelInfo?.id ?? normalizedModel ?? model;
|
|
119
|
+
const binding = modelInfo?.provider?.npm ?? entry?.npm;
|
|
117
120
|
const apiKey = process.env.OPENCODE_API_KEY ?? '';
|
|
121
|
+
const baseURL =
|
|
122
|
+
modelInfo?.provider?.baseURL ||
|
|
123
|
+
modelInfo?.provider?.api ||
|
|
124
|
+
entry?.api ||
|
|
125
|
+
'https://opencode.ai/zen/v1';
|
|
126
|
+
const headers = apiKey ? { Authorization: `Bearer ${apiKey}` } : undefined;
|
|
127
|
+
if (binding === '@ai-sdk/openai') {
|
|
128
|
+
const instance = createOpenAI({ apiKey, baseURL });
|
|
129
|
+
return instance(resolvedModelId);
|
|
130
|
+
}
|
|
131
|
+
if (binding === '@ai-sdk/anthropic') {
|
|
132
|
+
const instance = createAnthropic({ apiKey, baseURL });
|
|
133
|
+
return instance(resolvedModelId);
|
|
134
|
+
}
|
|
135
|
+
if (binding === '@ai-sdk/openai-compatible') {
|
|
136
|
+
const instance = createOpenAICompatible({
|
|
137
|
+
name: entry?.label ?? 'opencode',
|
|
138
|
+
baseURL,
|
|
139
|
+
headers,
|
|
140
|
+
});
|
|
141
|
+
return instance(resolvedModelId);
|
|
142
|
+
}
|
|
118
143
|
|
|
119
144
|
const ocOpenAI = createOpenAI({ apiKey, baseURL });
|
|
120
145
|
const ocAnthropic = createAnthropic({ apiKey, baseURL });
|
|
121
146
|
const ocCompat = createOpenAICompatible({
|
|
122
|
-
name: 'opencode',
|
|
147
|
+
name: entry?.label ?? 'opencode',
|
|
123
148
|
baseURL,
|
|
124
|
-
headers
|
|
149
|
+
headers,
|
|
125
150
|
});
|
|
126
151
|
|
|
127
|
-
const id =
|
|
128
|
-
if (id.includes('claude')) return ocAnthropic(
|
|
152
|
+
const id = resolvedModelId.toLowerCase();
|
|
153
|
+
if (id.includes('claude')) return ocAnthropic(resolvedModelId);
|
|
129
154
|
if (
|
|
130
155
|
id.includes('qwen3-coder') ||
|
|
131
156
|
id.includes('grok-code') ||
|
|
132
157
|
id.includes('kimi-k2')
|
|
133
158
|
)
|
|
134
|
-
return ocCompat(
|
|
135
|
-
return ocOpenAI(
|
|
159
|
+
return ocCompat(resolvedModelId);
|
|
160
|
+
return ocOpenAI(resolvedModelId);
|
|
136
161
|
}
|
|
137
162
|
throw new Error(`Unsupported provider: ${provider}`);
|
|
138
163
|
}
|
|
164
|
+
|
|
165
|
+
function normalizeModelIdentifier(provider: ProviderId, model: string): string {
|
|
166
|
+
const prefix = `${provider}/`;
|
|
167
|
+
return model.startsWith(prefix) ? model.slice(prefix.length) : model;
|
|
168
|
+
}
|