dsh-volcengine-provider 0.0.0-stage → 0.1.0

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.
@@ -0,0 +1,344 @@
1
+ {
2
+ "agent-plan": {
3
+ "api": "anthropic-messages",
4
+ "baseURL": "https://ark.cn-beijing.volces.com/api/plan",
5
+ "defaultContextWindow": 1048576,
6
+ "defaultMaxTokens": 128000,
7
+ "reasoning": "low",
8
+ "compat": {
9
+ "allowEmptySignature": true,
10
+ "forceAdaptiveThinking": true
11
+ },
12
+ "models": [
13
+ {
14
+ "id": "ark-code-latest",
15
+ "name": "ark-code-latest",
16
+ "maxTokens": 32000,
17
+ "input": [
18
+ "text",
19
+ "image"
20
+ ],
21
+ "reasoningEfforts": {
22
+ "off": null,
23
+ "low": "low"
24
+ },
25
+ "compat": {
26
+ "forceAdaptiveThinking": false
27
+ }
28
+ },
29
+ {
30
+ "id": "doubao-seed-evolving",
31
+ "name": "doubao-seed-evolving",
32
+ "contextWindow": 1048576,
33
+ "maxTokens": 256000,
34
+ "input": [
35
+ "text",
36
+ "image"
37
+ ],
38
+ "reasoningEfforts": {
39
+ "low": "low",
40
+ "medium": "medium",
41
+ "high": "high"
42
+ },
43
+ "compat": {
44
+ "forceAdaptiveThinking": false
45
+ }
46
+ },
47
+ {
48
+ "id": "doubao-seed-2-1-pro-260915",
49
+ "name": "doubao-seed-2-1-pro-260915",
50
+ "contextWindow": 1048576,
51
+ "maxTokens": 256000,
52
+ "input": [
53
+ "text",
54
+ "image"
55
+ ],
56
+ "reasoningEfforts": {
57
+ "low": "low",
58
+ "medium": "medium",
59
+ "high": "high"
60
+ },
61
+ "compat": {
62
+ "forceAdaptiveThinking": false
63
+ }
64
+ },
65
+ {
66
+ "id": "doubao-seed-2-1-lite-260915",
67
+ "name": "doubao-seed-2-1-lite-260915",
68
+ "contextWindow": 1048576,
69
+ "maxTokens": 256000,
70
+ "input": [
71
+ "text",
72
+ "image"
73
+ ],
74
+ "reasoningEfforts": {
75
+ "low": "low",
76
+ "medium": "medium",
77
+ "high": "high"
78
+ },
79
+ "compat": {
80
+ "forceAdaptiveThinking": false
81
+ }
82
+ },
83
+ {
84
+ "id": "kimi-k2-8-preview",
85
+ "name": "kimi-k2-8-preview",
86
+ "contextWindow": 1048576,
87
+ "maxTokens": 131072,
88
+ "input": [
89
+ "text",
90
+ "image"
91
+ ],
92
+ "reasoningEfforts": {
93
+ "low": "low",
94
+ "high": "high",
95
+ "max": "max"
96
+ }
97
+ },
98
+ {
99
+ "id": "deepseek-v4-1-flash-260910",
100
+ "name": "deepseek-v4-1-flash-260910",
101
+ "contextWindow": 1048576,
102
+ "maxTokens": 384000,
103
+ "input": [
104
+ "text",
105
+ "image"
106
+ ],
107
+ "reasoningEfforts": {
108
+ "low": "low",
109
+ "high": "high",
110
+ "max": "max"
111
+ }
112
+ },
113
+ {
114
+ "id": "deepseek-v4-1-flash-economy-261017",
115
+ "name": "deepseek-v4-1-flash-economy-261017",
116
+ "contextWindow": 1048576,
117
+ "maxTokens": 384000,
118
+ "input": [
119
+ "text",
120
+ "image"
121
+ ],
122
+ "reasoningEfforts": {
123
+ "low": "low",
124
+ "high": "high",
125
+ "max": "max"
126
+ }
127
+ },
128
+ {
129
+ "id": "glm-5-3-flash-260828",
130
+ "name": "glm-5-3-flash-260828",
131
+ "contextWindow": 1048576,
132
+ "maxTokens": 128000,
133
+ "input": [
134
+ "text",
135
+ "image"
136
+ ],
137
+ "reasoningEfforts": {
138
+ "low": "low",
139
+ "high": "high",
140
+ "max": "max"
141
+ }
142
+ },
143
+ {
144
+ "id": "glm-5.3",
145
+ "name": "glm-5.3",
146
+ "maxTokens": 131072,
147
+ "input": [
148
+ "text"
149
+ ],
150
+ "reasoningEfforts": {
151
+ "low": "low",
152
+ "medium": "medium",
153
+ "high": "high"
154
+ }
155
+ },
156
+ {
157
+ "id": "kimi-k3",
158
+ "name": "kimi-k3",
159
+ "contextWindow": 1048576,
160
+ "maxTokens": 128000,
161
+ "input": [
162
+ "text",
163
+ "image"
164
+ ],
165
+ "reasoningEfforts": {
166
+ "low": "low",
167
+ "high": "high",
168
+ "max": "max"
169
+ }
170
+ }
171
+ ]
172
+ },
173
+ "coding-plan": {
174
+ "api": "anthropic-messages",
175
+ "baseURL": "https://ark.cn-beijing.volces.com/api/coding",
176
+ "defaultContextWindow": 1048576,
177
+ "defaultMaxTokens": 128000,
178
+ "reasoning": "low",
179
+ "compat": {
180
+ "allowEmptySignature": true,
181
+ "forceAdaptiveThinking": true
182
+ },
183
+ "models": [
184
+ {
185
+ "id": "ark-code-latest",
186
+ "name": "ark-code-latest",
187
+ "maxTokens": 32000,
188
+ "input": [
189
+ "text",
190
+ "image"
191
+ ],
192
+ "reasoningEfforts": {
193
+ "off": null,
194
+ "low": "low"
195
+ },
196
+ "compat": {
197
+ "forceAdaptiveThinking": false
198
+ }
199
+ },
200
+ {
201
+ "id": "doubao-seed-evolving",
202
+ "name": "doubao-seed-evolving",
203
+ "contextWindow": 1048576,
204
+ "maxTokens": 256000,
205
+ "input": [
206
+ "text",
207
+ "image"
208
+ ],
209
+ "reasoningEfforts": {
210
+ "low": "low",
211
+ "medium": "medium",
212
+ "high": "high"
213
+ },
214
+ "compat": {
215
+ "forceAdaptiveThinking": false
216
+ }
217
+ },
218
+ {
219
+ "id": "doubao-seed-2-1-pro",
220
+ "name": "doubao-seed-2-1-pro",
221
+ "contextWindow": 1048576,
222
+ "maxTokens": 256000,
223
+ "input": [
224
+ "text",
225
+ "image"
226
+ ],
227
+ "reasoningEfforts": {
228
+ "low": "low",
229
+ "medium": "medium",
230
+ "high": "high"
231
+ },
232
+ "compat": {
233
+ "forceAdaptiveThinking": false
234
+ }
235
+ },
236
+ {
237
+ "id": "doubao-seed-2-1-lite",
238
+ "name": "doubao-seed-2-1-lite",
239
+ "contextWindow": 1048576,
240
+ "maxTokens": 256000,
241
+ "input": [
242
+ "text",
243
+ "image"
244
+ ],
245
+ "reasoningEfforts": {
246
+ "low": "low",
247
+ "medium": "medium",
248
+ "high": "high"
249
+ },
250
+ "compat": {
251
+ "forceAdaptiveThinking": false
252
+ }
253
+ },
254
+ {
255
+ "id": "deepseek-v4-1-flash",
256
+ "name": "deepseek-v4-1-flash",
257
+ "contextWindow": 1048576,
258
+ "maxTokens": 384000,
259
+ "input": [
260
+ "text",
261
+ "image"
262
+ ],
263
+ "reasoningEfforts": {
264
+ "low": "low",
265
+ "high": "high",
266
+ "max": "max"
267
+ }
268
+ },
269
+ {
270
+ "id": "deepseek-v4-1-flash-economy",
271
+ "name": "deepseek-v4-1-flash-economy",
272
+ "contextWindow": 1048576,
273
+ "maxTokens": 384000,
274
+ "input": [
275
+ "text",
276
+ "image"
277
+ ],
278
+ "reasoningEfforts": {
279
+ "low": "low",
280
+ "high": "high",
281
+ "max": "max"
282
+ }
283
+ },
284
+ {
285
+ "id": "kimi-k2-8-preview",
286
+ "name": "kimi-k2-8-preview",
287
+ "contextWindow": 1048576,
288
+ "maxTokens": 131072,
289
+ "input": [
290
+ "text",
291
+ "image"
292
+ ],
293
+ "reasoningEfforts": {
294
+ "low": "low",
295
+ "high": "high",
296
+ "max": "max"
297
+ }
298
+ },
299
+ {
300
+ "id": "glm-5-3-flash",
301
+ "name": "glm-5-3-flash",
302
+ "contextWindow": 1048576,
303
+ "maxTokens": 128000,
304
+ "input": [
305
+ "text",
306
+ "image"
307
+ ],
308
+ "reasoningEfforts": {
309
+ "low": "low",
310
+ "high": "high",
311
+ "max": "max"
312
+ }
313
+ },
314
+ {
315
+ "id": "glm-5.3",
316
+ "name": "glm-5.3",
317
+ "maxTokens": 131072,
318
+ "input": [
319
+ "text"
320
+ ],
321
+ "reasoningEfforts": {
322
+ "low": "low",
323
+ "medium": "medium",
324
+ "high": "high"
325
+ }
326
+ },
327
+ {
328
+ "id": "kimi-k3",
329
+ "name": "kimi-k3",
330
+ "contextWindow": 1048576,
331
+ "maxTokens": 128000,
332
+ "input": [
333
+ "text",
334
+ "image"
335
+ ],
336
+ "reasoningEfforts": {
337
+ "low": "low",
338
+ "high": "high",
339
+ "max": "max"
340
+ }
341
+ }
342
+ ]
343
+ }
344
+ }
@@ -0,0 +1,47 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { assertPlan, LABELS, ROUTES } from './state.mjs';
3
+ export const snapshot = JSON.parse(await readFile(new URL('./catalog-snapshot.json', import.meta.url), 'utf8'));
4
+ const modelId = /^[A-Za-z0-9][A-Za-z0-9_.:/-]{0,199}$/;
5
+ export function normalizeCatalog(plan, response) {
6
+ assertPlan(plan);
7
+ if (response?.plan !== plan || !Array.isArray(response.models)) throw new Error('模型目录响应与所选订阅不匹配');
8
+ if (response.models.length > 1000) throw new Error('模型目录过大');
9
+ const seen = new Set();
10
+ const models = response.models.map(row => {
11
+ const id = row.output_name || row.model_id;
12
+ if (typeof id !== 'string' || !modelId.test(id) || seen.has(id)) throw new Error('模型目录包含非法或重复 ID');
13
+ seen.add(id);
14
+ const known = snapshot[plan].models.find(m => m.id === id || m.id === row.model_id);
15
+ return {
16
+ ...(known ? structuredClone(known) : { contextWindow: 32768, maxTokens: 8192, input: ['text'], reasoningEfforts: false, compat: { forceAdaptiveThinking: false } }),
17
+ id, name: typeof row.model_name === 'string' && row.model_name.length <= 200 ? row.model_name : id,
18
+ ...(known ? {} : { capabilityUnverified: true })
19
+ };
20
+ });
21
+ return { models, source: 'arkcli', updatedAt: new Date().toISOString() };
22
+ }
23
+ export function usableModels(catalog, plan) {
24
+ const rows = catalog === undefined || catalog === null ? snapshot[plan].models : catalog.models;
25
+ if (!Array.isArray(rows)) throw new Error('本地模型缓存格式错误');
26
+ return rows.map(row => {
27
+ if (!modelId.test(row.id)) throw new Error('本地模型缓存包含非法 ID');
28
+ const { capabilityUnverified: _unverified, ...model } = row;
29
+ return model;
30
+ });
31
+ }
32
+ export function providerProfile(plan, models) {
33
+ const base = snapshot[assertPlan(plan)];
34
+ return { ...base, models, displayName: LABELS[plan] };
35
+ }
36
+ export function profilesFor(state) {
37
+ const providers = {};
38
+ for (const plan of Object.keys(ROUTES)) {
39
+ const id = state.active[plan];
40
+ const owner = state.accounts.find(a => a.id === id);
41
+ if (!owner) continue;
42
+ const models = usableModels(state.catalogs[`${id}:${plan}`], plan);
43
+ // Credentials are resolved by a host-owned adapter closure, never in this document.
44
+ providers[ROUTES[plan]] = providerProfile(plan, models);
45
+ }
46
+ return providers;
47
+ }
package/lib/cli.mjs ADDED
@@ -0,0 +1,58 @@
1
+ import { execFile, spawn } from 'node:child_process';
2
+ import { access, mkdir } from 'node:fs/promises';
3
+ import { delimiter, dirname, join, isAbsolute } from 'node:path';
4
+ import { createRequire } from 'node:module';
5
+ import { assertPlan } from './state.mjs';
6
+ const require = createRequire(import.meta.url);
7
+ const maxBytes = 2 * 1024 * 1024;
8
+ export async function locateCli(explicit) {
9
+ if (explicit) {
10
+ if (!isAbsolute(explicit) || /\.(cmd|bat)$/i.test(explicit)) throw new Error('arkCliPath 必须是官方原生可执行文件绝对路径');
11
+ await access(explicit); return explicit;
12
+ }
13
+ const filename = process.platform === 'win32' ? 'arkcli-windows-amd64.exe' : `arkcli-${process.platform === 'darwin' ? 'darwin' : 'linux'}-${process.arch === 'arm64' ? 'arm64' : 'amd64'}`;
14
+ const candidates = [];
15
+ try { candidates.push(join(dirname(require.resolve('@volcengine/ark-cli/package.json')), 'bin', filename)); } catch (error) { if (error.code !== 'MODULE_NOT_FOUND' && error.code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED') throw error; }
16
+ for (const path of (process.env.PATH ?? '').split(delimiter)) {
17
+ if (!path) continue;
18
+ candidates.push(join(path, process.platform === 'win32' ? 'arkcli.exe' : 'arkcli'));
19
+ candidates.push(join(path, 'node_modules', '@volcengine', 'ark-cli', 'bin', filename));
20
+ }
21
+ for (const path of candidates) try { await access(path); return path; } catch (error) { if (error.code !== 'ENOENT' && error.code !== 'ENOTDIR') throw error; }
22
+ throw new Error('未找到官方 ArkCli;请安装后设置 arkCliPath(原生可执行文件)');
23
+ }
24
+ export function cliEnvironment(home, ambient = process.env) {
25
+ const env = { ...ambient, HOME: home, USERPROFILE: home, XDG_CONFIG_HOME: join(home, '.config') };
26
+ // An explicit isolated identity must never inherit ambient cloud credentials.
27
+ for (const key of Object.keys(env)) if (/^(ARK_|ARKCLI_|VOLC|AWS_)/i.test(key)) delete env[key];
28
+ env.ARKCLI_NO_UPDATE_NOTIFIER = '1';
29
+ env.ARKCLI_CALLER_TYPE = 'ai_agent';
30
+ env.ARKCLI_CALLER_NAME = 'dsh-volcengine-provider';
31
+ return env;
32
+ }
33
+ export function parseJsonOutput(text) {
34
+ try { return JSON.parse(text.trim()); } catch { throw new Error('ArkCli 未返回有效 JSON;请核对 CLI 版本'); }
35
+ }
36
+ export class ArkCli {
37
+ constructor({ executable, home, exec = execFile, spawnImpl = spawn }) { Object.assign(this, { executable, home, exec, spawnImpl }); }
38
+ async run(args, { signal, timeout = 30000, plain = false } = {}) {
39
+ await mkdir(this.home, { recursive: true, mode: 0o700 });
40
+ return new Promise((resolve, reject) => {
41
+ this.exec(this.executable, [...args, '--format', 'json'], { env: cliEnvironment(this.home), cwd: this.home, windowsHide: true, timeout, maxBuffer: maxBytes, signal, encoding: 'utf8' }, (error, stdout) => {
42
+ if (error) { reject(new Error(signal?.aborted ? 'ArkCli 操作已取消' : 'ArkCli 操作失败;请检查登录、网络和 CLI 版本(原始输出已隐藏)')); return; }
43
+ try { resolve(plain ? stdout.trim() : parseJsonOutput(stdout)); } catch (error) { reject(error); }
44
+ });
45
+ });
46
+ }
47
+ models(plan, profile, signal) {
48
+ assertPlan(plan);
49
+ return this.run(['plans', 'model-list', '--plan', plan, ...(profile ? ['--profile', profile] : [])], { signal });
50
+ }
51
+ whoami(signal) { return this.run(['auth', 'whoami'], { signal }); }
52
+ status(signal) { return this.run(['auth', 'status'], { signal }); }
53
+ apiKey(profile, signal) { return this.run(['profile', 'apikey', 'get', '--profile', profile, '--plain'], { signal, plain: true }); }
54
+ usage(plan, profile, signal) {
55
+ assertPlan(plan);
56
+ return this.run(['usage', 'plan', '--product', plan, ...(profile ? ['--profile', profile] : [])], { signal });
57
+ }
58
+ }