@agi-cli/server 0.1.103 → 0.1.105
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 +56 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agi-cli/server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.105",
|
|
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.105",
|
|
33
|
+
"@agi-cli/database": "0.1.105",
|
|
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
|
@@ -14,6 +14,56 @@ import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
|
|
|
14
14
|
|
|
15
15
|
export type ProviderName = ProviderId;
|
|
16
16
|
|
|
17
|
+
async function getZaiInstance(cfg: AGIConfig, model: string) {
|
|
18
|
+
const auth = await getAuth('zai', cfg.projectRoot);
|
|
19
|
+
const entry = catalog.zai;
|
|
20
|
+
|
|
21
|
+
let apiKey = '';
|
|
22
|
+
const baseURL = entry?.api || 'https://api.z.ai/api/paas/v4';
|
|
23
|
+
|
|
24
|
+
if (auth?.type === 'api' && auth.key) {
|
|
25
|
+
apiKey = auth.key;
|
|
26
|
+
} else {
|
|
27
|
+
apiKey = process.env.ZAI_API_KEY || process.env.ZHIPU_API_KEY || '';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const headers = apiKey ? { Authorization: `Bearer ${apiKey}` } : undefined;
|
|
31
|
+
|
|
32
|
+
const instance = createOpenAICompatible({
|
|
33
|
+
name: entry?.label ?? 'Z.AI',
|
|
34
|
+
baseURL,
|
|
35
|
+
headers,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return instance(model);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function getZaiCodingInstance(cfg: AGIConfig, model: string) {
|
|
42
|
+
const auth =
|
|
43
|
+
(await getAuth('zai', cfg.projectRoot)) ||
|
|
44
|
+
(await getAuth('zai-coding', cfg.projectRoot));
|
|
45
|
+
const entry = catalog['zai-coding'];
|
|
46
|
+
|
|
47
|
+
let apiKey = '';
|
|
48
|
+
const baseURL = entry?.api || 'https://api.z.ai/api/coding/paas/v4';
|
|
49
|
+
|
|
50
|
+
if (auth?.type === 'api' && auth.key) {
|
|
51
|
+
apiKey = auth.key;
|
|
52
|
+
} else {
|
|
53
|
+
apiKey = process.env.ZAI_API_KEY || process.env.ZHIPU_API_KEY || '';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const headers = apiKey ? { Authorization: `Bearer ${apiKey}` } : undefined;
|
|
57
|
+
|
|
58
|
+
const instance = createOpenAICompatible({
|
|
59
|
+
name: entry?.label ?? 'Z.AI Coding',
|
|
60
|
+
baseURL,
|
|
61
|
+
headers,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
return instance(model);
|
|
65
|
+
}
|
|
66
|
+
|
|
17
67
|
function getOpenRouterInstance() {
|
|
18
68
|
const apiKey = process.env.OPENROUTER_API_KEY ?? '';
|
|
19
69
|
return createOpenRouter({ apiKey });
|
|
@@ -192,6 +242,12 @@ export async function resolveModel(
|
|
|
192
242
|
},
|
|
193
243
|
);
|
|
194
244
|
}
|
|
245
|
+
if (provider === 'zai') {
|
|
246
|
+
return getZaiInstance(cfg, model);
|
|
247
|
+
}
|
|
248
|
+
if (provider === 'zai-coding') {
|
|
249
|
+
return getZaiCodingInstance(cfg, model);
|
|
250
|
+
}
|
|
195
251
|
throw new Error(`Unsupported provider: ${provider}`);
|
|
196
252
|
}
|
|
197
253
|
|