yymaxapi 1.0.35 → 1.0.37

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/bin/yymaxapi.js +65 -33
  2. package/package.json +1 -1
package/bin/yymaxapi.js CHANGED
@@ -2611,8 +2611,8 @@ async function autoActivate(paths, args = {}) {
2611
2611
 
2612
2612
  // Claude 侧
2613
2613
  const claudeBaseUrl = buildFullUrl(selectedEndpoint.url, 'claude');
2614
- const claudeModelId = 'claude-opus-4-6';
2615
- const claudeModel = CLAUDE_MODELS.find(m => m.id === claudeModelId) || { id: claudeModelId, name: 'Claude Opus 4.6' };
2614
+ const claudeModelId = 'claude-sonnet-4-6';
2615
+ const claudeModel = CLAUDE_MODELS.find(m => m.id === claudeModelId) || { id: claudeModelId, name: 'Claude Sonnet 4.6' };
2616
2616
  const claudeModelKey = `${claudeProviderName}/${claudeModelId}`;
2617
2617
 
2618
2618
  config.models.providers[claudeProviderName] = {
@@ -2941,6 +2941,7 @@ async function main() {
2941
2941
  new inquirer.Separator(' -- 配置模型 --'),
2942
2942
  { name: ' 一键激活', value: 'auto_activate' },
2943
2943
  new inquirer.Separator(' -- 工具 --'),
2944
+ { name: ' 切换模型', value: 'switch_model' },
2944
2945
  { name: ' 测试连接', value: 'test_connection' },
2945
2946
  { name: ' 查看配置', value: 'view_config' },
2946
2947
  { name: ' 恢复默认', value: 'restore' },
@@ -2966,6 +2967,9 @@ async function main() {
2966
2967
  case 'test_connection':
2967
2968
  await testConnection(paths, {});
2968
2969
  break;
2970
+ case 'switch_model':
2971
+ await switchModel(paths);
2972
+ break;
2969
2973
  case 'view_config':
2970
2974
  await viewConfig(paths);
2971
2975
  break;
@@ -3157,6 +3161,64 @@ async function activate(paths, type) {
3157
3161
  console.log(chalk.gray(` API Key: 已设置`));
3158
3162
  }
3159
3163
 
3164
+
3165
+ // ============ 切换模型 ============
3166
+ async function switchModel(paths) {
3167
+ console.log(chalk.cyan('🔄 切换 Claude 模型\n'));
3168
+
3169
+ const config = ensureConfigStructure(readConfig(paths.openclawConfig) || {});
3170
+ const primary = config.agents?.defaults?.model?.primary || '';
3171
+
3172
+ if (!primary.includes('/')) {
3173
+ console.log(chalk.yellow('⚠️ 请先通过「一键激活」设置主模型'));
3174
+ return;
3175
+ }
3176
+
3177
+ const providerName = primary.split('/')[0];
3178
+ const currentModelId = primary.split('/')[1] || '';
3179
+ const provider = config.models?.providers?.[providerName];
3180
+
3181
+ if (!provider) {
3182
+ console.log(chalk.yellow(`⚠️ 主模型对应的中转站不存在: ${providerName}`));
3183
+ return;
3184
+ }
3185
+
3186
+ const models = [
3187
+ { id: 'claude-opus-4-6', name: 'Claude Opus 4.6' },
3188
+ { id: 'claude-sonnet-4-6', name: 'Claude Sonnet 4.6' },
3189
+ ];
3190
+
3191
+ console.log(chalk.gray(`当前模型: ${currentModelId}`));
3192
+ console.log(chalk.gray(`中转节点: ${provider.baseUrl}\n`));
3193
+
3194
+ const { selected } = await inquirer.prompt([{
3195
+ type: 'list',
3196
+ name: 'selected',
3197
+ message: '选择模型:',
3198
+ default: currentModelId,
3199
+ choices: models.map(m => ({
3200
+ name: m.id === currentModelId ? `${m.name} (当前)` : m.name,
3201
+ value: m.id,
3202
+ })),
3203
+ }]);
3204
+
3205
+ if (selected === currentModelId) {
3206
+ console.log(chalk.gray('\n模型未变更'));
3207
+ return;
3208
+ }
3209
+
3210
+ const newPrimary = `${providerName}/${selected}`;
3211
+ config.agents.defaults.model.primary = newPrimary;
3212
+ if (!config.agents.defaults.models[newPrimary]) {
3213
+ config.agents.defaults.models[newPrimary] = { alias: providerName };
3214
+ }
3215
+ writeConfigWithSync(paths, config);
3216
+
3217
+ const selectedName = models.find(m => m.id === selected).name;
3218
+ console.log(chalk.green(`\n✅ 已切换到 ${selectedName}`));
3219
+ console.log(chalk.gray(` ${newPrimary}`));
3220
+ console.log(chalk.yellow('\n💡 切换后建议重启 Gateway: openclaw gateway restart'));
3221
+ }
3160
3222
  // ============ 测试连接 ============
3161
3223
  async function testConnection(paths, args = {}) {
3162
3224
  console.log(chalk.cyan('🧪 测试 OpenClaw Gateway 连接\n'));
@@ -3169,7 +3231,7 @@ async function testConnection(paths, args = {}) {
3169
3231
  }
3170
3232
 
3171
3233
  // 检查当前激活的是哪个
3172
- let primary = config.agents?.defaults?.model?.primary || '';
3234
+ const primary = config.agents?.defaults?.model?.primary || '';
3173
3235
  if (!primary.includes('/')) {
3174
3236
  console.log(chalk.yellow('⚠️ 请先设置主模型'));
3175
3237
  return;
@@ -3199,36 +3261,6 @@ async function testConnection(paths, args = {}) {
3199
3261
  console.log(chalk.gray(`中转节点: ${provider.baseUrl}`));
3200
3262
  console.log(chalk.gray(`模型: ${primary}`));
3201
3263
  console.log(chalk.gray(`Gateway: http://localhost:${gatewayPort}\n`));
3202
-
3203
- // 模型切换(仅 Claude)
3204
- if (apiType.startsWith('anthropic')) {
3205
- const currentModelId = primary.split('/')[1] || '';
3206
- const switchModels = [
3207
- { id: 'claude-opus-4-6', name: 'Claude Opus 4.6' },
3208
- { id: 'claude-sonnet-4-6', name: 'Claude Sonnet 4.6' },
3209
- ];
3210
- const { switchModel } = await inquirer.prompt([{
3211
- type: 'list',
3212
- name: 'switchModel',
3213
- message: '选择测试模型:',
3214
- default: currentModelId,
3215
- choices: switchModels.map(m => ({
3216
- name: m.id === currentModelId ? `${m.name} (当前)` : m.name,
3217
- value: m.id,
3218
- })),
3219
- }]);
3220
- if (switchModel !== currentModelId) {
3221
- primary = `${providerName}/${switchModel}`;
3222
- config.agents.defaults.model.primary = primary;
3223
- if (!config.agents.defaults.models) config.agents.defaults.models = {};
3224
- if (!config.agents.defaults.models[primary]) {
3225
- config.agents.defaults.models[primary] = { alias: providerName };
3226
- }
3227
- writeConfigWithSync(paths, config);
3228
- console.log(chalk.green(` ✅ 已切换到 ${switchModels.find(m => m.id === switchModel).name}\n`));
3229
- }
3230
- }
3231
-
3232
3264
  // 获取 Gateway token
3233
3265
  const gatewayToken = config.gateway?.auth?.token;
3234
3266
  if (!gatewayToken) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yymaxapi",
3
- "version": "1.0.35",
3
+ "version": "1.0.37",
4
4
  "description": "跨平台 OpenClaw/Clawdbot 配置管理工具 - 管理中转地址、模型切换、API Keys、测速优化",
5
5
  "main": "bin/yymaxapi.js",
6
6
  "bin": {