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.
Files changed (2) hide show
  1. package/cli.js +51 -85
  2. 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: '🌐 选择节点 (测速 + 自动配置备用)', value: 'select_node' },
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 primaryEndpoint = sorted[primaryIndex];
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 primaryName = 'yunyi-001';
267
- config.models.providers[primaryName] = {
268
- baseUrl: buildFullUrl(primaryEndpoint.url),
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 = `${primaryName}/${modelConfig.id}`;
280
- config.agents.defaults.models[`${primaryName}/${modelConfig.id}`] = { alias: primaryName };
281
-
282
- // 添加备用节点
283
- const fallbacks = [];
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(` 主节点: ${primaryEndpoint.name} (${primaryEndpoint.url})`));
306
- console.log(chalk.gray(` 备用节点: ${fallbackEndpoints.length} 个`));
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
- // 更新所有 yunyi 节点的模型
330
- Object.keys(config.models.providers).forEach(name => {
331
- if (name.startsWith('yunyi-')) {
332
- config.models.providers[name].models = [{
333
- id: modelConfig.id,
334
- name: modelConfig.name,
335
- contextWindow: 200000,
336
- maxTokens: 8192
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
- const providers = Object.keys(config.models.providers).filter(k => k.startsWith('yunyi-')).sort();
343
- if (providers.length > 0) {
344
- config.agents.defaults.model.primary = `${providers[0]}/${modelConfig.id}`;
345
- config.agents.defaults.model.fallbacks = providers.slice(1).map(p => `${p}/${modelConfig.id}`);
346
- config.agents.defaults.models = {};
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
- // 为所有 yunyi 节点设置 API Key
376
- Object.keys(config.models.providers).forEach(name => {
377
- if (name.startsWith('yunyi-')) {
378
- config.models.providers[name].apiKey = apiKey.trim();
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
- Object.keys(config.models.providers).forEach(name => {
396
- if (name.startsWith('yunyi-')) {
397
- authProfiles[`${name}:default`] = { apiKey: apiKey.trim() };
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
- const fallbacks = config.agents?.defaults?.model?.fallbacks || [];
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 providers = Object.entries(config.models.providers).filter(([name]) => name.startsWith('yunyi-'));
433
- providers.slice(0, 5).forEach(([name, provider], i) => {
434
- const isPrimary = primary.startsWith(name);
435
- const marker = isPrimary ? chalk.green('') : chalk.gray('');
436
- const hasKey = provider.apiKey ? chalk.green('✓') : chalk.red('✗');
437
- console.log(` ${marker} ${name}: ${provider.baseUrl}`);
438
- console.log(` API Key: ${hasKey}`);
439
- });
440
- if (providers.length > 5) console.log(chalk.gray(` ... 还有 ${providers.length - 5} 个节点`));
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclawapi",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "跨平台 OpenClaw/Clawdbot 配置管理工具 - 管理中转地址、模型切换、API Keys、测速优化",
5
5
  "main": "cli.js",
6
6
  "bin": {