codemate-ai 1.0.6 → 1.0.7

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/dist/cli.js +115 -15
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -384,10 +384,14 @@ var init_ConfigManager = __esm({
384
384
  constructor(options) {
385
385
  const { cwd, productName, argvConfig = {} } = options;
386
386
  const lowerProductName = productName.toLowerCase();
387
+ const legacyGlobalConfigPath = path18.join(homedir(), ".aiclirc.json");
387
388
  this.globalConfigPath = path18.join(homedir(), `.${lowerProductName}`, "config.json");
388
389
  this.projectConfigPath = path18.join(cwd, `.${lowerProductName}`, "config.json");
389
390
  const projectLocalConfigPath = path18.join(cwd, `.${lowerProductName}`, "config.local.json");
390
- this.globalConfig = this.loadConfig(this.globalConfigPath);
391
+ this.globalConfig = defu(
392
+ this.loadConfig(this.globalConfigPath),
393
+ this.loadConfig(legacyGlobalConfigPath)
394
+ );
391
395
  this.projectConfig = defu(
392
396
  this.loadConfig(projectLocalConfigPath),
393
397
  // 优先级高
@@ -423,6 +427,7 @@ var init_ConfigManager = __esm({
423
427
  )
424
428
  )
425
429
  );
430
+ this.normalizeConfig(config);
426
431
  config.planModel = config.planModel || config.model;
427
432
  config.smallModel = config.smallModel || config.model;
428
433
  config.visionModel = config.visionModel || config.model;
@@ -485,6 +490,26 @@ var init_ConfigManager = __esm({
485
490
  return {};
486
491
  }
487
492
  }
493
+ normalizeConfig(config) {
494
+ const legacyModel = config.model;
495
+ if (!legacyModel || typeof legacyModel !== "object") {
496
+ return;
497
+ }
498
+ const modelName = typeof legacyModel.model === "string" ? legacyModel.model : "deepseek-chat";
499
+ const providerKey = config._metadata?.provider || "deepseek";
500
+ config.model = modelName;
501
+ if (!config.provider) {
502
+ config.provider = {};
503
+ }
504
+ const existingProvider = config.provider[providerKey] || {};
505
+ config.provider[providerKey] = {
506
+ apiKey: existingProvider.apiKey || legacyModel.apiKey,
507
+ baseURL: existingProvider.baseURL || legacyModel.baseURL
508
+ };
509
+ if (config.temperature === void 0 && legacyModel.temperature !== void 0) {
510
+ config.temperature = legacyModel.temperature;
511
+ }
512
+ }
488
513
  /**
489
514
  * 保存配置文件
490
515
  *
@@ -20916,12 +20941,72 @@ var ConfigService = class {
20916
20941
  */
20917
20942
  getModelConfig() {
20918
20943
  const config = this.getConfig();
20944
+ const legacyModel = typeof config.model === "object" ? config.model : void 0;
20945
+ const providerKey = this.getProviderKey(config) || "deepseek";
20946
+ const providerConfig = config.provider?.[providerKey];
20947
+ const envConfig = this.getProviderEnvConfig(providerKey);
20919
20948
  return {
20920
- apiKey: process.env.DEEPSEEK_API_KEY || "",
20921
- baseURL: process.env.DEEPSEEK_BASE_URL || "https://api.deepseek.com",
20922
- model: config.model || "deepseek-chat",
20923
- temperature: config.temperature || 0.7
20949
+ apiKey: envConfig.apiKey || providerConfig?.apiKey || legacyModel?.apiKey || "",
20950
+ baseURL: envConfig.baseURL || providerConfig?.baseURL || legacyModel?.baseURL || this.getDefaultBaseURL(providerKey),
20951
+ model: (typeof config.model === "string" ? config.model : void 0) || legacyModel?.model || this.getDefaultModel(providerKey),
20952
+ temperature: config.temperature ?? legacyModel?.temperature ?? 0.7
20953
+ };
20954
+ }
20955
+ getProviderKey(config) {
20956
+ const metadataProvider = config._metadata?.provider;
20957
+ if (typeof metadataProvider === "string" && metadataProvider.trim()) {
20958
+ return metadataProvider;
20959
+ }
20960
+ const providerKeys = config.provider ? Object.keys(config.provider) : [];
20961
+ if (providerKeys.length === 1) {
20962
+ return providerKeys[0];
20963
+ }
20964
+ return void 0;
20965
+ }
20966
+ getDefaultModel(providerKey) {
20967
+ const defaults = {
20968
+ openai: "gpt-4",
20969
+ anthropic: "claude-3-5-sonnet-20241022",
20970
+ deepseek: "deepseek-chat",
20971
+ openrouter: "anthropic/claude-3.5-sonnet",
20972
+ custom: "gpt-4"
20973
+ };
20974
+ return defaults[providerKey] || "deepseek-chat";
20975
+ }
20976
+ getDefaultBaseURL(providerKey) {
20977
+ const defaults = {
20978
+ openai: "https://api.openai.com/v1",
20979
+ anthropic: "https://api.anthropic.com",
20980
+ deepseek: "https://api.deepseek.com",
20981
+ openrouter: "https://openrouter.ai/api/v1",
20982
+ custom: "https://api.openai.com/v1"
20924
20983
  };
20984
+ return defaults[providerKey] || "https://api.deepseek.com";
20985
+ }
20986
+ getProviderEnvConfig(providerKey) {
20987
+ const envMap = {
20988
+ openai: {
20989
+ apiKey: process.env.OPENAI_API_KEY,
20990
+ baseURL: process.env.OPENAI_BASE_URL
20991
+ },
20992
+ anthropic: {
20993
+ apiKey: process.env.ANTHROPIC_API_KEY,
20994
+ baseURL: process.env.ANTHROPIC_BASE_URL
20995
+ },
20996
+ deepseek: {
20997
+ apiKey: process.env.DEEPSEEK_API_KEY,
20998
+ baseURL: process.env.DEEPSEEK_BASE_URL
20999
+ },
21000
+ openrouter: {
21001
+ apiKey: process.env.OPENROUTER_API_KEY,
21002
+ baseURL: process.env.OPENROUTER_BASE_URL
21003
+ },
21004
+ custom: {
21005
+ apiKey: process.env.OPENAI_API_KEY,
21006
+ baseURL: process.env.OPENAI_BASE_URL
21007
+ }
21008
+ };
21009
+ return envMap[providerKey] || {};
20925
21010
  }
20926
21011
  /**
20927
21012
  * 获取应用配置(向后兼容)
@@ -22182,11 +22267,20 @@ function AppContent() {
22182
22267
  try {
22183
22268
  modelService.updateConfig({ model: modelId });
22184
22269
  setCurrentModelId(modelId);
22270
+ let missingApiKey = false;
22271
+ let configPath = "~/.codemate/config.json";
22185
22272
  try {
22186
22273
  const configService = app.getContainer().get("config");
22187
22274
  if (configService && typeof configService.setConfig === "function") {
22188
22275
  configService.setConfig(false, "model", modelId);
22189
22276
  }
22277
+ if (configService && typeof configService.getGlobalConfigPath === "function") {
22278
+ configPath = configService.getGlobalConfigPath();
22279
+ }
22280
+ if (configService && typeof configService.getModelConfig === "function") {
22281
+ const modelConfig = configService.getModelConfig();
22282
+ missingApiKey = !modelConfig.apiKey;
22283
+ }
22190
22284
  } catch (error) {
22191
22285
  console.log("ConfigService not available, model change is temporary");
22192
22286
  }
@@ -22194,7 +22288,7 @@ function AppContent() {
22194
22288
  role: "assistant",
22195
22289
  content: `\u2705 Model changed to ${modelId}
22196
22290
 
22197
- \u{1F504} The model has been updated for this session. To make this change permanent, update your .aiclirc.json configuration file.`
22291
+ \u{1F504} The model has been updated for this session. To make this change permanent, update your ${configPath} configuration file.${missingApiKey ? "\n\n\u26A0\uFE0F No API key configured. Run `codemate config` or set the provider API key in the config file to use this model." : ""}`
22198
22292
  });
22199
22293
  const eventBus = app.getContainer().get("eventBus");
22200
22294
  eventBus.emit("model_changed", { newModel: modelId, previousModel: previousModelId });
@@ -22460,10 +22554,13 @@ function App({ app }) {
22460
22554
  // src/utils/firstRun.ts
22461
22555
  init_esm_shims();
22462
22556
  function isFirstRun() {
22463
- const configPath = getConfigPath();
22464
- return !fs21__default.existsSync(configPath);
22557
+ return !fs21__default.existsSync(getConfigPath()) && !fs21__default.existsSync(getLegacyConfigPath());
22465
22558
  }
22466
22559
  function getConfigPath() {
22560
+ const homeDir = os4__default.homedir();
22561
+ return path18.join(homeDir, ".codemate", "config.json");
22562
+ }
22563
+ function getLegacyConfigPath() {
22467
22564
  const homeDir = os4__default.homedir();
22468
22565
  return path18.join(homeDir, ".aiclirc.json");
22469
22566
  }
@@ -22489,12 +22586,14 @@ function createDefaultConfig(apiKey, provider, model, baseURL) {
22489
22586
  logLevel: "info",
22490
22587
  workDir: process.cwd()
22491
22588
  },
22492
- model: {
22493
- apiKey,
22494
- baseURL: baseURL || defaultBaseURLs[provider] || "https://api.openai.com/v1",
22495
- model: model || defaultModels[provider] || "gpt-4",
22496
- temperature: 0.7
22589
+ model: model || defaultModels[provider] || "gpt-4",
22590
+ provider: {
22591
+ [provider]: {
22592
+ apiKey,
22593
+ baseURL: baseURL || defaultBaseURLs[provider] || "https://api.openai.com/v1"
22594
+ }
22497
22595
  },
22596
+ temperature: 0.7,
22498
22597
  tools: {
22499
22598
  enabled: [
22500
22599
  "read_file",
@@ -22528,6 +22627,7 @@ function createDefaultConfig(apiKey, provider, model, baseURL) {
22528
22627
  }
22529
22628
  };
22530
22629
  const configPath = getConfigPath();
22630
+ fs21__default.mkdirSync(path18.dirname(configPath), { recursive: true });
22531
22631
  fs21__default.writeFileSync(configPath, JSON.stringify(config, null, 2));
22532
22632
  }
22533
22633
 
@@ -22588,7 +22688,7 @@ async function runFirstTimeSetup() {
22588
22688
  rl.close();
22589
22689
  createDefaultConfig(apiKey.trim(), providerKey, model, baseURL || PROVIDERS[providerKey].baseURL);
22590
22690
  console.log("");
22591
- console.log("\u2705 \u914D\u7F6E\u5DF2\u4FDD\u5B58\u5230: ~/.aiclirc.json");
22691
+ console.log("\u2705 \u914D\u7F6E\u5DF2\u4FDD\u5B58\u5230: ~/.codemate/config.json");
22592
22692
  console.log("");
22593
22693
  console.log(`\u63D0\u4F9B\u5546: ${PROVIDERS[providerKey].name}`);
22594
22694
  console.log(`\u6A21\u578B: ${model}`);
@@ -22656,7 +22756,7 @@ program.command("config").description("Configure or reconfigure CodeMate AI").ac
22656
22756
  try {
22657
22757
  console.log("\n\u{1F527} CodeMate AI \u914D\u7F6E\u5411\u5BFC\n");
22658
22758
  if (!isFirstRun()) {
22659
- console.log("\u5F53\u524D\u914D\u7F6E\u6587\u4EF6: ~/.aiclirc.json");
22759
+ console.log("\u5F53\u524D\u914D\u7F6E\u6587\u4EF6: ~/.codemate/config.json");
22660
22760
  console.log("\u6B64\u64CD\u4F5C\u5C06\u8986\u76D6\u73B0\u6709\u914D\u7F6E\u3002\n");
22661
22761
  }
22662
22762
  await runFirstTimeSetup();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codemate-ai",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "type": "module",
5
5
  "description": "Enterprise-grade AI coding assistant CLI",
6
6
  "main": "dist/cli.js",