openclawapi 1.2.0 → 1.2.1
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/cli.js +51 -85
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -162,7 +162,7 @@ async function main() {
|
|
|
162
162
|
name: 'action',
|
|
163
163
|
message: '请选择操作:',
|
|
164
164
|
choices: [
|
|
165
|
-
{ name: '🌐 选择节点
|
|
165
|
+
{ name: '🌐 选择节点', value: 'select_node' },
|
|
166
166
|
{ name: '🤖 选择默认模型', value: 'select_model' },
|
|
167
167
|
{ name: '🔑 设置 API Key', value: 'set_apikey' },
|
|
168
168
|
{ name: '📋 查看当前配置', value: 'view_config' },
|
|
@@ -221,11 +221,11 @@ async function selectNode(paths) {
|
|
|
221
221
|
|
|
222
222
|
console.log(chalk.green(`\n🏆 最快节点: ${sorted[0].name} (${sorted[0].latency}ms)\n`));
|
|
223
223
|
|
|
224
|
-
//
|
|
224
|
+
// 选择节点
|
|
225
225
|
const { selectedIndex } = await inquirer.prompt([{
|
|
226
226
|
type: 'list',
|
|
227
227
|
name: 'selectedIndex',
|
|
228
|
-
message: '
|
|
228
|
+
message: '选择节点:',
|
|
229
229
|
choices: [
|
|
230
230
|
{ name: `🚀 使用最快节点 (${sorted[0].name})`, value: -1 },
|
|
231
231
|
new inquirer.Separator('--- 或手动选择 ---'),
|
|
@@ -237,8 +237,7 @@ async function selectNode(paths) {
|
|
|
237
237
|
}]);
|
|
238
238
|
|
|
239
239
|
const primaryIndex = selectedIndex === -1 ? 0 : selectedIndex;
|
|
240
|
-
const
|
|
241
|
-
const fallbackEndpoints = sorted.filter((_, i) => i !== primaryIndex);
|
|
240
|
+
const selectedEndpoint = sorted[primaryIndex];
|
|
242
241
|
|
|
243
242
|
// 读取或创建配置
|
|
244
243
|
let config = readConfig(paths.openclawConfig) || {};
|
|
@@ -262,10 +261,10 @@ async function selectNode(paths) {
|
|
|
262
261
|
if (!config.agents.defaults.model) config.agents.defaults.model = {};
|
|
263
262
|
if (!config.agents.defaults.models) config.agents.defaults.models = {};
|
|
264
263
|
|
|
265
|
-
//
|
|
266
|
-
const
|
|
267
|
-
config.models.providers[
|
|
268
|
-
baseUrl: buildFullUrl(
|
|
264
|
+
// 添加选中的节点
|
|
265
|
+
const providerName = 'yunyi-001';
|
|
266
|
+
config.models.providers[providerName] = {
|
|
267
|
+
baseUrl: buildFullUrl(selectedEndpoint.url),
|
|
269
268
|
api: 'anthropic-messages',
|
|
270
269
|
models: [{
|
|
271
270
|
id: modelConfig.id,
|
|
@@ -275,36 +274,18 @@ async function selectNode(paths) {
|
|
|
275
274
|
}]
|
|
276
275
|
};
|
|
277
276
|
|
|
278
|
-
//
|
|
279
|
-
config.agents.defaults.model.primary = `${
|
|
280
|
-
config.agents.defaults.
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
fallbackEndpoints.forEach((endpoint, i) => {
|
|
285
|
-
const name = `yunyi-${String(i + 2).padStart(3, '0')}`;
|
|
286
|
-
config.models.providers[name] = {
|
|
287
|
-
baseUrl: buildFullUrl(endpoint.url),
|
|
288
|
-
api: 'anthropic-messages',
|
|
289
|
-
models: [{
|
|
290
|
-
id: modelConfig.id,
|
|
291
|
-
name: modelConfig.name,
|
|
292
|
-
contextWindow: 200000,
|
|
293
|
-
maxTokens: 8192
|
|
294
|
-
}]
|
|
295
|
-
};
|
|
296
|
-
fallbacks.push(`${name}/${modelConfig.id}`);
|
|
297
|
-
config.agents.defaults.models[`${name}/${modelConfig.id}`] = { alias: name };
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
config.agents.defaults.model.fallbacks = fallbacks;
|
|
277
|
+
// 设置主模型(无备用)
|
|
278
|
+
config.agents.defaults.model.primary = `${providerName}/${modelConfig.id}`;
|
|
279
|
+
config.agents.defaults.model.fallbacks = [];
|
|
280
|
+
config.agents.defaults.models = {
|
|
281
|
+
[`${providerName}/${modelConfig.id}`]: { alias: providerName }
|
|
282
|
+
};
|
|
301
283
|
|
|
302
284
|
writeConfig(paths.openclawConfig, config);
|
|
303
285
|
|
|
304
286
|
console.log(chalk.green(`\n✅ 配置完成!`));
|
|
305
|
-
console.log(chalk.cyan(`
|
|
306
|
-
console.log(chalk.gray(`
|
|
307
|
-
console.log(chalk.gray(` 当前模型: ${modelConfig.name}`));
|
|
287
|
+
console.log(chalk.cyan(` 节点: ${selectedEndpoint.name} (${selectedEndpoint.url})`));
|
|
288
|
+
console.log(chalk.gray(` 模型: ${modelConfig.name}`));
|
|
308
289
|
}
|
|
309
290
|
|
|
310
291
|
// ============ 选择模型 ============
|
|
@@ -326,27 +307,22 @@ async function selectModel(paths) {
|
|
|
326
307
|
return;
|
|
327
308
|
}
|
|
328
309
|
|
|
329
|
-
//
|
|
330
|
-
Object.keys(config.models.providers).
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
}
|
|
339
|
-
});
|
|
310
|
+
// 更新 yunyi 节点的模型
|
|
311
|
+
const providerName = Object.keys(config.models.providers).find(k => k.startsWith('yunyi-'));
|
|
312
|
+
if (providerName) {
|
|
313
|
+
config.models.providers[providerName].models = [{
|
|
314
|
+
id: modelConfig.id,
|
|
315
|
+
name: modelConfig.name,
|
|
316
|
+
contextWindow: 200000,
|
|
317
|
+
maxTokens: 8192
|
|
318
|
+
}];
|
|
340
319
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
config.agents.defaults.
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
providers.forEach(p => {
|
|
348
|
-
config.agents.defaults.models[`${p}/${modelConfig.id}`] = { alias: p };
|
|
349
|
-
});
|
|
320
|
+
// 更新主模型(无备用)
|
|
321
|
+
config.agents.defaults.model.primary = `${providerName}/${modelConfig.id}`;
|
|
322
|
+
config.agents.defaults.model.fallbacks = [];
|
|
323
|
+
config.agents.defaults.models = {
|
|
324
|
+
[`${providerName}/${modelConfig.id}`]: { alias: providerName }
|
|
325
|
+
};
|
|
350
326
|
}
|
|
351
327
|
|
|
352
328
|
writeConfig(paths.openclawConfig, config);
|
|
@@ -372,12 +348,11 @@ async function setApiKey(paths) {
|
|
|
372
348
|
return;
|
|
373
349
|
}
|
|
374
350
|
|
|
375
|
-
//
|
|
376
|
-
Object.keys(config.models.providers).
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
});
|
|
351
|
+
// 为 yunyi 节点设置 API Key
|
|
352
|
+
const providerName = Object.keys(config.models.providers).find(k => k.startsWith('yunyi-'));
|
|
353
|
+
if (providerName) {
|
|
354
|
+
config.models.providers[providerName].apiKey = apiKey.trim();
|
|
355
|
+
}
|
|
381
356
|
|
|
382
357
|
writeConfig(paths.openclawConfig, config);
|
|
383
358
|
|
|
@@ -392,11 +367,9 @@ async function setApiKey(paths) {
|
|
|
392
367
|
try { authProfiles = JSON.parse(fs.readFileSync(paths.authProfiles, 'utf8')); } catch {}
|
|
393
368
|
}
|
|
394
369
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
}
|
|
399
|
-
});
|
|
370
|
+
if (providerName) {
|
|
371
|
+
authProfiles[`${providerName}:default`] = { apiKey: apiKey.trim() };
|
|
372
|
+
}
|
|
400
373
|
|
|
401
374
|
fs.writeFileSync(paths.authProfiles, JSON.stringify(authProfiles, null, 2), 'utf8');
|
|
402
375
|
|
|
@@ -416,28 +389,21 @@ async function viewConfig(paths) {
|
|
|
416
389
|
|
|
417
390
|
// 主模型
|
|
418
391
|
const primary = config.agents?.defaults?.model?.primary || '未设置';
|
|
419
|
-
console.log(chalk.yellow('
|
|
392
|
+
console.log(chalk.yellow('当前模型:'));
|
|
420
393
|
console.log(` ${primary}\n`);
|
|
421
394
|
|
|
422
|
-
//
|
|
423
|
-
|
|
424
|
-
console.log(chalk.yellow(`备用模型 (${fallbacks.length} 个):`));
|
|
425
|
-
fallbacks.slice(0, 3).forEach((f, i) => console.log(` ${i + 1}. ${f}`));
|
|
426
|
-
if (fallbacks.length > 3) console.log(chalk.gray(` ... 还有 ${fallbacks.length - 3} 个`));
|
|
427
|
-
console.log('');
|
|
428
|
-
|
|
429
|
-
// 节点列表
|
|
430
|
-
console.log(chalk.yellow('节点列表:'));
|
|
395
|
+
// 节点信息
|
|
396
|
+
console.log(chalk.yellow('当前节点:'));
|
|
431
397
|
if (config.models?.providers) {
|
|
432
|
-
const
|
|
433
|
-
|
|
434
|
-
const
|
|
435
|
-
const
|
|
436
|
-
|
|
437
|
-
console.log(`
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
398
|
+
const provider = Object.entries(config.models.providers).find(([name]) => name.startsWith('yunyi-'));
|
|
399
|
+
if (provider) {
|
|
400
|
+
const [name, data] = provider;
|
|
401
|
+
const hasKey = data.apiKey ? chalk.green('✓ 已设置') : chalk.red('✗ 未设置');
|
|
402
|
+
console.log(` ${name}: ${data.baseUrl}`);
|
|
403
|
+
console.log(` API Key: ${hasKey}`);
|
|
404
|
+
} else {
|
|
405
|
+
console.log(' 未配置');
|
|
406
|
+
}
|
|
441
407
|
}
|
|
442
408
|
console.log('');
|
|
443
409
|
|