@cloudbase/cli 2.10.0-beta.0 → 2.11.0-beta.0
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/lib/auth/login.js +51 -65
- package/lib/auth/logout.js +3 -14
- package/lib/commands/account/login.js +136 -149
- package/lib/commands/account/logout.js +3 -14
- package/lib/commands/ag/base.js +203 -0
- package/lib/commands/ag/create.js +301 -0
- package/lib/commands/ag/debug/index.html +699 -0
- package/lib/commands/ag/delete.js +200 -0
- package/lib/commands/ag/deploy.js +185 -0
- package/lib/commands/ag/detail.js +113 -0
- package/lib/commands/ag/index.js +22 -0
- package/lib/commands/ag/list.js +155 -0
- package/lib/commands/ag/run.js +644 -0
- package/lib/commands/ai/index.js +76 -95
- package/lib/commands/cloudfunction/base.js +182 -203
- package/lib/commands/cloudrun/base.js +578 -603
- package/lib/commands/common.js +48 -63
- package/lib/commands/config/delete.js +16 -27
- package/lib/commands/config/get.js +13 -24
- package/lib/commands/config/list.js +16 -27
- package/lib/commands/config/set.js +33 -44
- package/lib/commands/db/base.js +221 -240
- package/lib/commands/env/base.js +36 -49
- package/lib/commands/env/domain.js +79 -94
- package/lib/commands/env/login.js +120 -135
- package/lib/commands/framework/index.js +32 -49
- package/lib/commands/fun/base.js +223 -244
- package/lib/commands/functions/alias/getRoute.js +33 -44
- package/lib/commands/functions/alias/setRoute.js +36 -47
- package/lib/commands/functions/code-download.js +43 -54
- package/lib/commands/functions/code-update.js +23 -34
- package/lib/commands/functions/concurrency/delete.js +11 -22
- package/lib/commands/functions/concurrency/list.js +20 -31
- package/lib/commands/functions/concurrency/set.js +13 -24
- package/lib/commands/functions/config-update.js +30 -41
- package/lib/commands/functions/copy.js +12 -23
- package/lib/commands/functions/delete.js +30 -41
- package/lib/commands/functions/deploy.js +184 -202
- package/lib/commands/functions/detail.js +23 -34
- package/lib/commands/functions/invoke.js +69 -75
- package/lib/commands/functions/layer/bind.js +102 -105
- package/lib/commands/functions/layer/create.js +29 -35
- package/lib/commands/functions/layer/delete.js +42 -48
- package/lib/commands/functions/layer/download.js +52 -58
- package/lib/commands/functions/layer/list.js +44 -50
- package/lib/commands/functions/layer/sort.js +39 -45
- package/lib/commands/functions/list.js +25 -36
- package/lib/commands/functions/log.js +65 -73
- package/lib/commands/functions/run.js +118 -116
- package/lib/commands/functions/trigger-create.js +32 -43
- package/lib/commands/functions/trigger-delete.js +50 -61
- package/lib/commands/functions/version/list.js +29 -40
- package/lib/commands/functions/version/publish.js +11 -22
- package/lib/commands/gateway/create.js +50 -61
- package/lib/commands/gateway/delete.js +38 -49
- package/lib/commands/gateway/domain.js +65 -80
- package/lib/commands/gateway/list.js +31 -42
- package/lib/commands/gateway/switch.js +48 -61
- package/lib/commands/helpers/init.js +226 -249
- package/lib/commands/helpers/new.js +35 -46
- package/lib/commands/helpers/open.js +22 -33
- package/lib/commands/hosting/hosting.js +157 -178
- package/lib/commands/index.js +1 -0
- package/lib/commands/lowcode/app.js +114 -144
- package/lib/commands/lowcode/comps.js +136 -127
- package/lib/commands/lowcode/utils.js +11 -22
- package/lib/commands/pull/pull.js +33 -46
- package/lib/commands/run/delete.js +35 -46
- package/lib/commands/run/image/delete.js +32 -39
- package/lib/commands/run/image/download.js +26 -33
- package/lib/commands/run/image/list.js +41 -48
- package/lib/commands/run/image/upload.js +26 -33
- package/lib/commands/run/list.js +32 -43
- package/lib/commands/run/service/config.js +17 -28
- package/lib/commands/run/service/deploy.js +15 -26
- package/lib/commands/run/service/list.js +48 -59
- package/lib/commands/run/service/update.js +7 -18
- package/lib/commands/run/standalonegateway/create.js +35 -42
- package/lib/commands/run/standalonegateway/destroy.js +23 -30
- package/lib/commands/run/standalonegateway/list.js +19 -26
- package/lib/commands/run/standalonegateway/package.js +31 -38
- package/lib/commands/run/standalonegateway/turn.js +27 -34
- package/lib/commands/run/version/create.js +198 -205
- package/lib/commands/run/version/delete.js +31 -38
- package/lib/commands/run/version/list.js +42 -49
- package/lib/commands/run/version/modify.js +27 -34
- package/lib/commands/run/version/update.js +201 -208
- package/lib/commands/runf/base.js +216 -237
- package/lib/commands/self-update.js +59 -72
- package/lib/commands/smart.js +66 -79
- package/lib/commands/storage/storage.js +192 -219
- package/lib/commands/third/thirdAttach.js +16 -27
- package/lib/commands/utils.js +119 -149
- package/lib/db/index.js +48 -67
- package/lib/decorators/captureError.js +10 -21
- package/lib/decorators/guard.js +11 -22
- package/lib/decorators/injectParams.js +29 -40
- package/lib/decorators/params/common.js +5 -2
- package/lib/decorators/params/index.js +3 -12
- package/lib/env/domain.js +13 -28
- package/lib/env/index.js +25 -44
- package/lib/env/login.js +30 -45
- package/lib/function/alias.js +31 -44
- package/lib/function/base.js +187 -215
- package/lib/function/code.js +8 -19
- package/lib/function/concurrency.js +43 -58
- package/lib/function/create.js +43 -53
- package/lib/function/delete.js +22 -35
- package/lib/function/layer/attach.js +33 -46
- package/lib/function/layer/create.js +34 -45
- package/lib/function/layer/delete.js +5 -16
- package/lib/function/layer/download.js +11 -22
- package/lib/function/layer/list.js +12 -25
- package/lib/function/layer/sort.js +6 -17
- package/lib/function/trigger.js +65 -82
- package/lib/function/update.js +24 -32
- package/lib/function/version.js +29 -42
- package/lib/function/vpc.js +12 -25
- package/lib/gateway/index.js +77 -104
- package/lib/hosting.js +157 -188
- package/lib/run/delete.js +3 -12
- package/lib/run/image/build.js +6 -15
- package/lib/run/image/delete.js +3 -12
- package/lib/run/image/info.js +3 -12
- package/lib/run/image/list.js +6 -15
- package/lib/run/list.js +19 -30
- package/lib/run/repo.js +6 -15
- package/lib/run/service/common.js +160 -173
- package/lib/run/service/config.js +44 -57
- package/lib/run/service/deployPackage.js +33 -44
- package/lib/run/service/list.js +8 -14
- package/lib/run/service/showLogs.js +69 -90
- package/lib/run/service/update.js +50 -63
- package/lib/run/standalonegateway/create.js +3 -12
- package/lib/run/standalonegateway/destroy.js +3 -12
- package/lib/run/standalonegateway/list.js +3 -12
- package/lib/run/standalonegateway/package/list.js +3 -12
- package/lib/run/standalonegateway/turn/off.js +3 -12
- package/lib/run/standalonegateway/turn/on.js +3 -12
- package/lib/run/version/create.js +41 -31
- package/lib/run/version/delete.js +3 -12
- package/lib/run/version/list.js +3 -12
- package/lib/run/version/modify.js +3 -12
- package/lib/run/version/repo.js +6 -15
- package/lib/run/version/update.js +37 -26
- package/lib/storage.js +62 -93
- package/lib/third/index.js +6 -17
- package/lib/utils/ai/banner.js +49 -60
- package/lib/utils/ai/claudeWindows.js +2 -2
- package/lib/utils/ai/config.js +169 -206
- package/lib/utils/ai/ensureFiles.js +6 -17
- package/lib/utils/ai/env.js +16 -27
- package/lib/utils/ai/envLocalManager.js +35 -52
- package/lib/utils/ai/router.js +927 -1005
- package/lib/utils/ai/setup.js +527 -563
- package/lib/utils/auth.js +3 -14
- package/lib/utils/checkTcbrEnv.js +20 -31
- package/lib/utils/cli-table.js +6 -1
- package/lib/utils/config.js +4 -13
- package/lib/utils/dts.js +98 -113
- package/lib/utils/env.js +154 -175
- package/lib/utils/function-packer.js +29 -42
- package/lib/utils/log.js +10 -21
- package/lib/utils/mcp-config-modifier.js +105 -120
- package/lib/utils/net/cloud-api-request.js +15 -23
- package/lib/utils/net/credential.js +26 -39
- package/lib/utils/net/http-request.js +63 -80
- package/lib/utils/net/manager-service.js +22 -35
- package/lib/utils/notice.js +16 -27
- package/lib/utils/output/loading.js +3 -12
- package/lib/utils/parallel.js +32 -43
- package/lib/utils/platform/mac.js +4 -15
- package/lib/utils/platform/port.js +4 -15
- package/lib/utils/prompt/select.js +6 -15
- package/lib/utils/report.js +28 -33
- package/lib/utils/reporter/agree.js +11 -22
- package/lib/utils/reporter/download.js +17 -28
- package/lib/utils/reporter/usage.js +12 -23
- package/lib/utils/store/auth.js +17 -30
- package/lib/utils/store/config.js +11 -25
- package/lib/utils/store/db.js +17 -36
- package/lib/utils/tcbrApi/callTcbrApi.js +19 -28
- package/lib/utils/template-manager.js +215 -242
- package/lib/utils/template.js +81 -96
- package/lib/utils/tools/common.js +45 -56
- package/lib/utils/tools/time.js +5 -16
- package/lib/utils/url.js +10 -4
- package/package.json +2 -2
- package/specs/ag-command/design.md +421 -0
- package/specs/ag-command/doc.md +204 -0
- package/specs/ag-command/requirements.md +173 -0
- package/specs/ag-command/summary.md +174 -0
- package/specs/ag-command/tasks.md +197 -0
- package/specs/ag-command/usage-guide.md +420 -0
- package/tsconfig.json +1 -1
- package/types/commands/ag/base.d.ts +44 -0
- package/types/commands/ag/create.d.ts +25 -0
- package/types/commands/ag/delete.d.ts +32 -0
- package/types/commands/ag/deploy.d.ts +31 -0
- package/types/commands/ag/detail.d.ts +28 -0
- package/types/commands/ag/index.d.ts +6 -0
- package/types/commands/ag/list.d.ts +35 -0
- package/types/commands/ag/run.d.ts +52 -0
- package/types/commands/cloudrun/base.d.ts +10 -0
- package/types/commands/index.d.ts +1 -0
package/lib/utils/ai/config.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -65,226 +56,198 @@ class AIConfigManager {
|
|
|
65
56
|
constructor() {
|
|
66
57
|
this.envLocalManager = new envLocalManager_1.EnvLocalManager();
|
|
67
58
|
}
|
|
68
|
-
loadConfig() {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return config;
|
|
74
|
-
});
|
|
59
|
+
async loadConfig() {
|
|
60
|
+
const parser = createConfigParser();
|
|
61
|
+
const config = await parser.get('ai');
|
|
62
|
+
!config && notFoundError();
|
|
63
|
+
return config;
|
|
75
64
|
}
|
|
76
|
-
isConfigured() {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
65
|
+
async isConfigured() {
|
|
66
|
+
try {
|
|
67
|
+
const config = await this.loadConfig();
|
|
68
|
+
return Object.keys(config.agents).length > 0;
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async getAgentConfig(agent) {
|
|
75
|
+
const config = await this.loadConfig();
|
|
76
|
+
return config.agents[agent] || null;
|
|
77
|
+
}
|
|
78
|
+
async resetConfig() {
|
|
79
|
+
try {
|
|
80
|
+
await Promise.all([
|
|
81
|
+
new envLocalManager_1.EnvLocalManager().removeAIConfig(),
|
|
82
|
+
createConfigParser().update('ai', {})
|
|
83
|
+
]);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)('重置 AI 配置失败,请手动删除 `.env.local`、`cloudbaserc.json` 文件中的 AI 配置部分,或重新运行 tcb ai --setup'), { original: error });
|
|
87
|
+
}
|
|
86
88
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return
|
|
91
|
-
}
|
|
89
|
+
async checkToolkitConfig(agent) {
|
|
90
|
+
const toolkitConfig = exports.TOOLKIT_CONFIGS[agent];
|
|
91
|
+
if (!toolkitConfig) {
|
|
92
|
+
return { hasConfig: false, hasMcp: false, hasRules: false, missingFiles: [] };
|
|
93
|
+
}
|
|
94
|
+
const results = {
|
|
95
|
+
hasConfig: false,
|
|
96
|
+
hasMcp: false,
|
|
97
|
+
hasRules: false,
|
|
98
|
+
missingFiles: []
|
|
99
|
+
};
|
|
100
|
+
if ('mcp' in toolkitConfig) {
|
|
101
|
+
results.hasMcp = await fs_extra_1.default.pathExists(toolkitConfig.mcp);
|
|
102
|
+
results.hasConfig = results.hasMcp;
|
|
103
|
+
if (!results.hasMcp) {
|
|
104
|
+
results.missingFiles.push(toolkitConfig.mcp);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else if ('config' in toolkitConfig) {
|
|
108
|
+
results.hasConfig = await fs_extra_1.default.pathExists(toolkitConfig.config);
|
|
109
|
+
if (!results.hasConfig) {
|
|
110
|
+
results.missingFiles.push(toolkitConfig.config);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (toolkitConfig.rules) {
|
|
114
|
+
results.hasRules = await fs_extra_1.default.pathExists(toolkitConfig.rules);
|
|
115
|
+
if (!results.hasRules) {
|
|
116
|
+
results.missingFiles.push(toolkitConfig.rules);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return results;
|
|
92
120
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
121
|
+
async updateEnvId(envId) {
|
|
122
|
+
this.updateConfig('envId', envId, 'ENV_ID');
|
|
123
|
+
await fs_extra_1.default.ensureFile(const_1.CLOUDBASE_MCP_CONFIG_PATH);
|
|
124
|
+
await fs_extra_1.default.writeJson(const_1.CLOUDBASE_MCP_CONFIG_PATH, {
|
|
125
|
+
envId,
|
|
126
|
+
updatedAt: new Date().toISOString(),
|
|
127
|
+
version: '1.0'
|
|
128
|
+
}, { spaces: 2 });
|
|
129
|
+
}
|
|
130
|
+
async updateDefaultAgent(agent) {
|
|
131
|
+
const configParser = createConfigParser();
|
|
132
|
+
await configParser.update('ai.defaultAgent', '{{env.AI_DEFAULT_AGENT}}');
|
|
133
|
+
this.envLocalManager.updateDefaultAgent(agent);
|
|
134
|
+
}
|
|
135
|
+
async updateClaudeConfig(type, config) {
|
|
136
|
+
await this.updateConfig('ai.agents.claude', {});
|
|
137
|
+
await this.updateConfig('ai.agents.claude.type', type);
|
|
138
|
+
if (type === 'custom') {
|
|
139
|
+
if (config.baseUrl) {
|
|
140
|
+
await this.updateConfig('ai.agents.claude.baseUrl', config.baseUrl, 'AI_CLAUDE_BASE_URL');
|
|
100
141
|
}
|
|
101
|
-
|
|
102
|
-
|
|
142
|
+
if (config.apiKey) {
|
|
143
|
+
await this.updateConfig('ai.agents.claude.apiKey', config.apiKey, 'AI_CLAUDE_API_KEY');
|
|
103
144
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
checkToolkitConfig(agent) {
|
|
107
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
-
const toolkitConfig = exports.TOOLKIT_CONFIGS[agent];
|
|
109
|
-
if (!toolkitConfig) {
|
|
110
|
-
return { hasConfig: false, hasMcp: false, hasRules: false, missingFiles: [] };
|
|
145
|
+
if (config.model) {
|
|
146
|
+
await this.updateConfig('ai.agents.claude.model', config.model, 'ANTHROPIC_MODEL');
|
|
111
147
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
missingFiles: []
|
|
117
|
-
};
|
|
118
|
-
if ('mcp' in toolkitConfig) {
|
|
119
|
-
results.hasMcp = yield fs_extra_1.default.pathExists(toolkitConfig.mcp);
|
|
120
|
-
results.hasConfig = results.hasMcp;
|
|
121
|
-
if (!results.hasMcp) {
|
|
122
|
-
results.missingFiles.push(toolkitConfig.mcp);
|
|
123
|
-
}
|
|
148
|
+
}
|
|
149
|
+
else if (type === 'cloudbase') {
|
|
150
|
+
if (config.provider) {
|
|
151
|
+
await this.updateConfig('ai.agents.claude.provider', config.provider);
|
|
124
152
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (!results.hasConfig) {
|
|
128
|
-
results.missingFiles.push(toolkitConfig.config);
|
|
129
|
-
}
|
|
153
|
+
if (config.model) {
|
|
154
|
+
await this.updateConfig('ai.agents.claude.model', config.model);
|
|
130
155
|
}
|
|
131
|
-
if (
|
|
132
|
-
|
|
133
|
-
if (!results.hasRules) {
|
|
134
|
-
results.missingFiles.push(toolkitConfig.rules);
|
|
135
|
-
}
|
|
156
|
+
if (config.transformer) {
|
|
157
|
+
await this.updateConfig('ai.agents.claude.transformer', config.transformer);
|
|
136
158
|
}
|
|
137
|
-
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
updateEnvId(envId) {
|
|
141
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
142
|
-
this.updateConfig('envId', envId, 'ENV_ID');
|
|
143
|
-
yield fs_extra_1.default.ensureFile(const_1.CLOUDBASE_MCP_CONFIG_PATH);
|
|
144
|
-
yield fs_extra_1.default.writeJson(const_1.CLOUDBASE_MCP_CONFIG_PATH, {
|
|
145
|
-
envId,
|
|
146
|
-
updatedAt: new Date().toISOString(),
|
|
147
|
-
version: '1.0'
|
|
148
|
-
}, { spaces: 2 });
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
updateDefaultAgent(agent) {
|
|
152
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
-
const configParser = createConfigParser();
|
|
154
|
-
yield configParser.update('ai.defaultAgent', '{{env.AI_DEFAULT_AGENT}}');
|
|
155
|
-
this.envLocalManager.updateDefaultAgent(agent);
|
|
156
|
-
});
|
|
159
|
+
}
|
|
157
160
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if (
|
|
163
|
-
|
|
164
|
-
yield this.updateConfig('ai.agents.claude.baseUrl', config.baseUrl, 'AI_CLAUDE_BASE_URL');
|
|
165
|
-
}
|
|
166
|
-
if (config.apiKey) {
|
|
167
|
-
yield this.updateConfig('ai.agents.claude.apiKey', config.apiKey, 'AI_CLAUDE_API_KEY');
|
|
168
|
-
}
|
|
169
|
-
if (config.model) {
|
|
170
|
-
yield this.updateConfig('ai.agents.claude.model', config.model, 'ANTHROPIC_MODEL');
|
|
171
|
-
}
|
|
161
|
+
async updateQwenConfig(type, config) {
|
|
162
|
+
await this.updateConfig('ai.agents.qwen', {});
|
|
163
|
+
await this.updateConfig('ai.agents.qwen.type', type);
|
|
164
|
+
if (type === 'custom') {
|
|
165
|
+
if (config.baseUrl) {
|
|
166
|
+
await this.updateConfig('ai.agents.qwen.baseUrl', config.baseUrl, 'AI_QWEN_BASE_URL');
|
|
172
167
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
yield this.updateConfig('ai.agents.claude.provider', config.provider);
|
|
176
|
-
}
|
|
177
|
-
if (config.model) {
|
|
178
|
-
yield this.updateConfig('ai.agents.claude.model', config.model);
|
|
179
|
-
}
|
|
180
|
-
if (config.transformer) {
|
|
181
|
-
yield this.updateConfig('ai.agents.claude.transformer', config.transformer);
|
|
182
|
-
}
|
|
168
|
+
if (config.apiKey) {
|
|
169
|
+
await this.updateConfig('ai.agents.qwen.apiKey', config.apiKey, 'AI_QWEN_API_KEY');
|
|
183
170
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
if (config.baseUrl) {
|
|
192
|
-
yield this.updateConfig('ai.agents.qwen.baseUrl', config.baseUrl, 'AI_QWEN_BASE_URL');
|
|
193
|
-
}
|
|
194
|
-
if (config.apiKey) {
|
|
195
|
-
yield this.updateConfig('ai.agents.qwen.apiKey', config.apiKey, 'AI_QWEN_API_KEY');
|
|
196
|
-
}
|
|
197
|
-
if (config.model) {
|
|
198
|
-
yield this.updateConfig('ai.agents.qwen.model', config.model, 'AI_QWEN_MODEL');
|
|
199
|
-
}
|
|
171
|
+
if (config.model) {
|
|
172
|
+
await this.updateConfig('ai.agents.qwen.model', config.model, 'AI_QWEN_MODEL');
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
else if (type === 'cloudbase') {
|
|
176
|
+
if (config.provider) {
|
|
177
|
+
await this.updateConfig('ai.agents.qwen.provider', config.provider);
|
|
200
178
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
yield this.updateConfig('ai.agents.qwen.provider', config.provider);
|
|
204
|
-
}
|
|
205
|
-
if (config.model) {
|
|
206
|
-
yield this.updateConfig('ai.agents.qwen.model', config.model);
|
|
207
|
-
}
|
|
179
|
+
if (config.model) {
|
|
180
|
+
await this.updateConfig('ai.agents.qwen.model', config.model);
|
|
208
181
|
}
|
|
209
|
-
}
|
|
182
|
+
}
|
|
210
183
|
}
|
|
211
|
-
updateCodexConfig(type, config) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
if (
|
|
216
|
-
|
|
217
|
-
yield this.updateConfig('ai.agents.codex.baseUrl', config.baseUrl, 'AI_CODEX_BASE_URL');
|
|
218
|
-
}
|
|
219
|
-
if (config.apiKey) {
|
|
220
|
-
yield this.updateConfig('ai.agents.codex.apiKey', config.apiKey, 'AI_CODEX_API_KEY');
|
|
221
|
-
}
|
|
222
|
-
if (config.model) {
|
|
223
|
-
yield this.updateConfig('ai.agents.codex.model', config.model, 'AI_CODEX_MODEL');
|
|
224
|
-
}
|
|
184
|
+
async updateCodexConfig(type, config) {
|
|
185
|
+
await this.updateConfig('ai.agents.codex', {});
|
|
186
|
+
await this.updateConfig('ai.agents.codex.type', type);
|
|
187
|
+
if (type === 'custom') {
|
|
188
|
+
if (config.baseUrl) {
|
|
189
|
+
await this.updateConfig('ai.agents.codex.baseUrl', config.baseUrl, 'AI_CODEX_BASE_URL');
|
|
225
190
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
yield this.updateConfig('ai.agents.codex.provider', config.provider);
|
|
229
|
-
}
|
|
230
|
-
if (config.model) {
|
|
231
|
-
yield this.updateConfig('ai.agents.codex.model', config.model);
|
|
232
|
-
}
|
|
191
|
+
if (config.apiKey) {
|
|
192
|
+
await this.updateConfig('ai.agents.codex.apiKey', config.apiKey, 'AI_CODEX_API_KEY');
|
|
233
193
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
updateAiderConfig(type, config) {
|
|
237
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
238
|
-
yield this.updateConfig('ai.agents.aider', {});
|
|
239
|
-
yield this.updateConfig('ai.agents.aider.type', type);
|
|
240
|
-
if (type === 'custom') {
|
|
241
|
-
if (config.apiKey) {
|
|
242
|
-
yield this.updateConfig('ai.agents.aider.apiKey', config.apiKey, 'AI_AIDER_API_KEY');
|
|
243
|
-
}
|
|
244
|
-
if (config.baseUrl) {
|
|
245
|
-
yield this.updateConfig('ai.agents.aider.baseUrl', config.baseUrl, 'AI_AIDER_BASE_URL');
|
|
246
|
-
}
|
|
247
|
-
if (config.model) {
|
|
248
|
-
yield this.updateConfig('ai.agents.aider.model', config.model, 'AI_AIDER_MODEL');
|
|
249
|
-
}
|
|
194
|
+
if (config.model) {
|
|
195
|
+
await this.updateConfig('ai.agents.codex.model', config.model, 'AI_CODEX_MODEL');
|
|
250
196
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
if (config.model) {
|
|
256
|
-
yield this.updateConfig('ai.agents.aider.model', config.model);
|
|
257
|
-
}
|
|
197
|
+
}
|
|
198
|
+
else if (type === 'cloudbase') {
|
|
199
|
+
if (config.provider) {
|
|
200
|
+
await this.updateConfig('ai.agents.codex.provider', config.provider);
|
|
258
201
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
updateCursorConfig(type) {
|
|
262
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
263
|
-
yield this.updateConfig('ai.agents.cursor.type', type);
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
updateCodebuddyConfig(type, config) {
|
|
267
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
268
|
-
yield this.updateConfig('ai.agents.codebuddy', {});
|
|
269
|
-
yield this.updateConfig('ai.agents.codebuddy.type', type);
|
|
270
|
-
if (type === 'custom') {
|
|
271
|
-
if (config.apiKey) {
|
|
272
|
-
yield this.updateConfig('ai.agents.codebuddy.apiKey', config.apiKey, 'CODEBUDDY_API_KEY');
|
|
273
|
-
}
|
|
202
|
+
if (config.model) {
|
|
203
|
+
await this.updateConfig('ai.agents.codex.model', config.model);
|
|
274
204
|
}
|
|
275
|
-
}
|
|
205
|
+
}
|
|
276
206
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
207
|
+
async updateAiderConfig(type, config) {
|
|
208
|
+
await this.updateConfig('ai.agents.aider', {});
|
|
209
|
+
await this.updateConfig('ai.agents.aider.type', type);
|
|
210
|
+
if (type === 'custom') {
|
|
211
|
+
if (config.apiKey) {
|
|
212
|
+
await this.updateConfig('ai.agents.aider.apiKey', config.apiKey, 'AI_AIDER_API_KEY');
|
|
213
|
+
}
|
|
214
|
+
if (config.baseUrl) {
|
|
215
|
+
await this.updateConfig('ai.agents.aider.baseUrl', config.baseUrl, 'AI_AIDER_BASE_URL');
|
|
283
216
|
}
|
|
284
|
-
|
|
285
|
-
|
|
217
|
+
if (config.model) {
|
|
218
|
+
await this.updateConfig('ai.agents.aider.model', config.model, 'AI_AIDER_MODEL');
|
|
286
219
|
}
|
|
287
|
-
}
|
|
220
|
+
}
|
|
221
|
+
else if (type === 'cloudbase') {
|
|
222
|
+
if (config.provider) {
|
|
223
|
+
await this.updateConfig('ai.agents.aider.provider', config.provider);
|
|
224
|
+
}
|
|
225
|
+
if (config.model) {
|
|
226
|
+
await this.updateConfig('ai.agents.aider.model', config.model);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
async updateCursorConfig(type) {
|
|
231
|
+
await this.updateConfig('ai.agents.cursor.type', type);
|
|
232
|
+
}
|
|
233
|
+
async updateCodebuddyConfig(type, config) {
|
|
234
|
+
await this.updateConfig('ai.agents.codebuddy', {});
|
|
235
|
+
await this.updateConfig('ai.agents.codebuddy.type', type);
|
|
236
|
+
if (type === 'custom') {
|
|
237
|
+
if (config.apiKey) {
|
|
238
|
+
await this.updateConfig('ai.agents.codebuddy.apiKey', config.apiKey, 'CODEBUDDY_API_KEY');
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
async updateConfig(key, value, env) {
|
|
243
|
+
const configParser = createConfigParser();
|
|
244
|
+
if (env) {
|
|
245
|
+
this.envLocalManager.setEnvLocal(env, value);
|
|
246
|
+
await configParser.update(key, `{{env.${env}}}`);
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
await configParser.update(key, value);
|
|
250
|
+
}
|
|
288
251
|
}
|
|
289
252
|
}
|
|
290
253
|
exports.AIConfigManager = AIConfigManager;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -15,13 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
6
|
exports.ensureFiles = void 0;
|
|
16
7
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
17
8
|
const const_1 = require("./const");
|
|
18
|
-
function ensureFiles() {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
yield fs_extra_1.default.ensureDir(const_1.CLAUDE_CODE_ROUTER_LOGS_DIR_PATH);
|
|
25
|
-
});
|
|
9
|
+
async function ensureFiles() {
|
|
10
|
+
await fs_extra_1.default.ensureFile(const_1.ENV_LOCAL_PATH);
|
|
11
|
+
if (!(await fs_extra_1.default.exists(const_1.CONFIG_PATH))) {
|
|
12
|
+
await fs_extra_1.default.writeFile(const_1.CONFIG_PATH, const_1.DEFAULT_CONFIG);
|
|
13
|
+
}
|
|
14
|
+
await fs_extra_1.default.ensureDir(const_1.CLAUDE_CODE_ROUTER_LOGS_DIR_PATH);
|
|
26
15
|
}
|
|
27
16
|
exports.ensureFiles = ensureFiles;
|
package/lib/utils/ai/env.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.ensureValidEnv = void 0;
|
|
13
4
|
const env_1 = require("../../env");
|
|
@@ -15,23 +6,21 @@ const constants_1 = require("../../commands/constants");
|
|
|
15
6
|
const utils_1 = require("../../commands/utils");
|
|
16
7
|
const config_1 = require("./config");
|
|
17
8
|
const i18n_1 = require("../../i18n");
|
|
18
|
-
function ensureValidEnv(_envId, log) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return _envId;
|
|
35
|
-
});
|
|
9
|
+
async function ensureValidEnv(_envId, log) {
|
|
10
|
+
const envs = await (0, env_1.listEnvs)({ source: [constants_1.EnvSource.MINIAPP, constants_1.EnvSource.QCLOUD] });
|
|
11
|
+
const validEnv = envs.find((env) => env.EnvId === _envId);
|
|
12
|
+
if (!validEnv) {
|
|
13
|
+
log.error((0, i18n_1.t)('❌ 环境 {{envId}} 与当前账号不匹配,请重新选择', { envId: _envId }));
|
|
14
|
+
const envId = await (0, utils_1.selectEnv)({ source: [constants_1.EnvSource.MINIAPP, constants_1.EnvSource.QCLOUD] });
|
|
15
|
+
new config_1.AIConfigManager().updateEnvId(envId);
|
|
16
|
+
return envId;
|
|
17
|
+
}
|
|
18
|
+
if (validEnv.Status !== constants_1.EnvStatus.NORMAL) {
|
|
19
|
+
log.error((0, i18n_1.t)('❌ 环境 {{envId}} 不可用,请重新选择', { envId: _envId }));
|
|
20
|
+
const envId = await (0, utils_1.selectEnv)({ source: [constants_1.EnvSource.MINIAPP, constants_1.EnvSource.QCLOUD] });
|
|
21
|
+
new config_1.AIConfigManager().updateEnvId(envId);
|
|
22
|
+
return envId;
|
|
23
|
+
}
|
|
24
|
+
return _envId;
|
|
36
25
|
}
|
|
37
26
|
exports.ensureValidEnv = ensureValidEnv;
|
|
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
27
|
};
|
|
@@ -48,37 +39,31 @@ class EnvLocalManager {
|
|
|
48
39
|
updateEnvId(envId) {
|
|
49
40
|
this.setEnvLocal('ENV_ID', envId);
|
|
50
41
|
}
|
|
51
|
-
parseEnvFile() {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return dotenvx.parse(content);
|
|
55
|
-
});
|
|
42
|
+
async parseEnvFile() {
|
|
43
|
+
const content = await fs_extra_1.default.readFile(const_1.ENV_LOCAL_PATH, 'utf8');
|
|
44
|
+
return dotenvx.parse(content);
|
|
56
45
|
}
|
|
57
|
-
updateAIConfig(aiConfig) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
});
|
|
46
|
+
async updateAIConfig(aiConfig) {
|
|
47
|
+
try {
|
|
48
|
+
await this.addAIConfigToEnv(aiConfig);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)('更新 AI 配置失败: {{error}}', { error: error.message }), { original: error });
|
|
52
|
+
}
|
|
66
53
|
}
|
|
67
|
-
removeAIConfig(agentName) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
this.removeSpecificAgentConfig(envMap, agentName);
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
this.removeAIConfigFromMap(envMap);
|
|
76
|
-
}
|
|
54
|
+
async removeAIConfig(agentName) {
|
|
55
|
+
try {
|
|
56
|
+
const envMap = await this.parseEnvFile();
|
|
57
|
+
if (agentName) {
|
|
58
|
+
this.removeSpecificAgentConfig(envMap, agentName);
|
|
77
59
|
}
|
|
78
|
-
|
|
79
|
-
|
|
60
|
+
else {
|
|
61
|
+
this.removeAIConfigFromMap(envMap);
|
|
80
62
|
}
|
|
81
|
-
}
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)('移除 AI 配置失败: {{error}}', { error: error.message }), { original: error });
|
|
66
|
+
}
|
|
82
67
|
}
|
|
83
68
|
validateAIConfig(aiConfig) {
|
|
84
69
|
const errors = [];
|
|
@@ -115,21 +100,19 @@ class EnvLocalManager {
|
|
|
115
100
|
.filter((x) => x.startsWith(agentPrefix))
|
|
116
101
|
.forEach((x) => this.removeEnvLocal(x));
|
|
117
102
|
}
|
|
118
|
-
addAIConfigToEnv(aiConfig) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
});
|
|
103
|
+
async addAIConfigToEnv(aiConfig) {
|
|
104
|
+
this.setEnvLocal('AI_DEFAULT_AGENT', aiConfig.defaultAgent);
|
|
105
|
+
Object.entries(aiConfig.agents).forEach(([agentName, agentConfig]) => {
|
|
106
|
+
const upperAgentName = agentName.toUpperCase();
|
|
107
|
+
if (agentConfig.apiKey) {
|
|
108
|
+
this.setEnvLocal(`AI_${upperAgentName}_API_KEY`, agentConfig.apiKey);
|
|
109
|
+
}
|
|
110
|
+
if (agentConfig.baseUrl) {
|
|
111
|
+
this.setEnvLocal(`AI_${upperAgentName}_BASE_URL`, agentConfig.baseUrl);
|
|
112
|
+
}
|
|
113
|
+
if (agentConfig.model) {
|
|
114
|
+
this.setEnvLocal(`AI_${upperAgentName}_MODEL`, agentConfig.model);
|
|
115
|
+
}
|
|
133
116
|
});
|
|
134
117
|
}
|
|
135
118
|
}
|
|
@@ -139,7 +122,7 @@ function isValidUrl(url) {
|
|
|
139
122
|
new URL(url);
|
|
140
123
|
return true;
|
|
141
124
|
}
|
|
142
|
-
catch
|
|
125
|
+
catch {
|
|
143
126
|
return false;
|
|
144
127
|
}
|
|
145
128
|
}
|