ltcraft-ai-auto 1.6.0 → 1.6.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/bin/index.js +11 -4
  2. package/package.json +1 -1
package/bin/index.js CHANGED
@@ -106,6 +106,7 @@ function readTomlValue(content, key) {
106
106
 
107
107
  function mergeTomlConfig(existing, name, baseUrl, apiKey) {
108
108
  let content = existing || '';
109
+ const newSection = `[model_providers.ltcraftai]\nname = "${name}"\nbase_url = "${baseUrl}"\napi_key = "${apiKey}"`;
109
110
 
110
111
  // 更新或插入顶层 model_provider
111
112
  if (/^model_provider\s*=/m.test(content)) {
@@ -114,11 +115,17 @@ function mergeTomlConfig(existing, name, baseUrl, apiKey) {
114
115
  content = `model_provider = "ltcraftai"\n` + content;
115
116
  }
116
117
 
117
- // 移除已有的 [model_providers.ltcraftai] 节(到下一个节或文件末尾)
118
- content = content.replace(/\[model_providers\.ltcraftai\][\s\S]*?(?=\n\[|\s*$)/, '');
118
+ // 原地替换 [model_providers.ltcraftai] 节;不存在则追加
119
+ const sectionStart = content.indexOf('[model_providers.ltcraftai]');
120
+ if (sectionStart !== -1) {
121
+ const afterSection = content.slice(sectionStart + 1);
122
+ const nextSection = afterSection.match(/\n\[/);
123
+ const sectionEnd = nextSection ? sectionStart + 1 + nextSection.index + 1 : content.length;
124
+ content = content.slice(0, sectionStart) + newSection + '\n' + content.slice(sectionEnd);
125
+ } else {
126
+ content = content.trimEnd() + `\n\n${newSection}\n`;
127
+ }
119
128
 
120
- // 追加新节
121
- content = content.trimEnd() + `\n\n[model_providers.ltcraftai]\nname = "${name}"\nbase_url = "${baseUrl}"\napi_key = "${apiKey}"\n`;
122
129
  return content;
123
130
  }
124
131
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ltcraft-ai-auto",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "description": "一键配置 Claude Code / OpenCode / OpenClaw 的 API 密钥工具",
5
5
  "type": "module",
6
6
  "main": "index.js",