@cloudbase/cli 2.8.0-beta.3 → 2.8.0-beta.4
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/bin/tcb.js +2 -0
- package/lib/commands/cloudrun/base.js +2 -2
- package/lib/commands/index.js +0 -1
- package/lib/commands/utils.js +4 -10
- package/package.json +2 -8
- package/types/commands/index.d.ts +0 -1
- package/types/commands/utils.d.ts +0 -6
- package/types/utils/config.d.ts +0 -1
- package/.augment-guidelines +0 -119
- package/.claude/settings.local.json +0 -6
- package/.clinerules/cloudbase-rules.mdc +0 -119
- package/.cursor/rules/cloudbase-rules.mdc +0 -119
- package/.mcp.json +0 -11
- package/CLAUDE.md +0 -119
- package/lib/commands/ai/index.js +0 -172
- package/lib/utils/ai/banner.js +0 -88
- package/lib/utils/ai/config.js +0 -228
- package/lib/utils/ai/const.js +0 -107
- package/lib/utils/ai/ensureFiles.js +0 -26
- package/lib/utils/ai/envLocalManager.js +0 -144
- package/lib/utils/ai/router.js +0 -812
- package/lib/utils/ai/setup.js +0 -419
- package/rules/cloudbase-platform.mdc +0 -44
- package/rules/database.mdc +0 -25
- package/rules/miniprogram-development.mdc +0 -61
- package/rules/ui-design.mdc +0 -24
- package/rules/web-development.mdc +0 -44
- package/rules/workflows.mdc +0 -30
- package/specs/ai-cli-bootstrap/QWEN.md +0 -196
- package/specs/ai-cli-bootstrap/design.md +0 -185
- package/specs/ai-cli-bootstrap/requirements.md +0 -51
- package/specs/ai-cli-bootstrap/tasks.md +0 -70
- package/specs/ai-cli-bootstrap/technical-docs.md +0 -421
- package/types/commands/ai/index.d.ts +0 -23
- package/types/utils/ai/banner.d.ts +0 -2
- package/types/utils/ai/config.d.ts +0 -68
- package/types/utils/ai/const.d.ts +0 -238
- package/types/utils/ai/ensureFiles.d.ts +0 -1
- package/types/utils/ai/envLocalManager.d.ts +0 -23
- package/types/utils/ai/router.d.ts +0 -38
- package/types/utils/ai/setup.d.ts +0 -21
package/lib/commands/ai/index.js
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.AICommand = void 0;
|
|
25
|
-
const common_1 = require("../common");
|
|
26
|
-
const decorators_1 = require("../../decorators");
|
|
27
|
-
const log_1 = require("../../utils/log");
|
|
28
|
-
const config_1 = require("../../utils/ai/config");
|
|
29
|
-
const router_1 = require("../../utils/ai/router");
|
|
30
|
-
const setup_1 = require("../../utils/ai/setup");
|
|
31
|
-
const report_1 = require("../../utils/report");
|
|
32
|
-
const error_1 = require("../../error");
|
|
33
|
-
const banner_1 = require("../../utils/ai/banner");
|
|
34
|
-
const ensureFiles_1 = require("../../utils/ai/ensureFiles");
|
|
35
|
-
let AICommand = class AICommand extends common_1.Command {
|
|
36
|
-
get options() {
|
|
37
|
-
return {
|
|
38
|
-
cmd: 'ai',
|
|
39
|
-
options: [
|
|
40
|
-
{
|
|
41
|
-
flags: '-a, --agent <agent>',
|
|
42
|
-
desc: 'AI CLI 工具 (claude, codex, gemini)'
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
flags: '-e, --envId <envId>',
|
|
46
|
-
desc: '云开发环境 ID'
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
flags: '--setup',
|
|
50
|
-
desc: '运行配置向导'
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
flags: '--config',
|
|
54
|
-
desc: '显示配置信息'
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
flags: '--reset',
|
|
58
|
-
desc: '重置配置'
|
|
59
|
-
}
|
|
60
|
-
],
|
|
61
|
-
desc: 'CloudBase AI ToolKit CLI - 快速启动和配置主流 AI 编程工具\n\n示例:\n tcb ai -a claude -- --continue\n\n说明:-- 后的参数会直接传递给目标 AI CLI。',
|
|
62
|
-
requiredEnvId: false,
|
|
63
|
-
withoutAuth: true,
|
|
64
|
-
allowUnknownOption: true
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
execute(options, ctx, log) {
|
|
68
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
yield (0, ensureFiles_1.ensureFiles)();
|
|
70
|
-
const { envId, setup, config, reset } = options;
|
|
71
|
-
let { agent } = options;
|
|
72
|
-
try {
|
|
73
|
-
yield (0, banner_1.showBanner)(log);
|
|
74
|
-
yield reportAIUsage(agent, Boolean(envId), this.getSubCommand(ctx.params));
|
|
75
|
-
const configManager = new config_1.AIConfigManager();
|
|
76
|
-
if (reset) {
|
|
77
|
-
return yield this.resetConfig(configManager, log);
|
|
78
|
-
}
|
|
79
|
-
if (setup) {
|
|
80
|
-
const wizard = new setup_1.AISetupWizard(envId);
|
|
81
|
-
return yield wizard.setUp(log);
|
|
82
|
-
}
|
|
83
|
-
if (config) {
|
|
84
|
-
return yield this.showConfig(configManager, log);
|
|
85
|
-
}
|
|
86
|
-
if (!(yield configManager.isConfigured())) {
|
|
87
|
-
log.info('AI 功能未配置,正在启动配置向导...');
|
|
88
|
-
const wizard = new setup_1.AISetupWizard(envId);
|
|
89
|
-
const { defaultAgent } = yield wizard.setUpDefault(log);
|
|
90
|
-
agent = defaultAgent;
|
|
91
|
-
}
|
|
92
|
-
const args = this.parseArgs();
|
|
93
|
-
const router = new router_1.AICommandRouter();
|
|
94
|
-
yield router.execute({
|
|
95
|
-
addtionalArgs: args,
|
|
96
|
-
log,
|
|
97
|
-
agent: agent || (yield configManager.loadConfig()).defaultAgent,
|
|
98
|
-
envId
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
yield reportAIError(agent, error.message);
|
|
103
|
-
throw error;
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
resetConfig(configManager, log) {
|
|
108
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
-
try {
|
|
110
|
-
yield configManager.resetConfig();
|
|
111
|
-
log.info('✅ AI 配置已重置');
|
|
112
|
-
}
|
|
113
|
-
catch (error) {
|
|
114
|
-
throw new error_1.CloudBaseError('重置配置失败', { original: error });
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
showConfig(configManager, log) {
|
|
119
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
-
try {
|
|
121
|
-
const aiConfig = yield configManager.loadConfig();
|
|
122
|
-
log.info('当前 AI 配置:');
|
|
123
|
-
log.info(JSON.stringify(aiConfig, null, 2));
|
|
124
|
-
}
|
|
125
|
-
catch (error) {
|
|
126
|
-
if (error instanceof error_1.CloudBaseError && error.code === config_1.CONFIG_NOT_FOUND) {
|
|
127
|
-
log.error(error.message);
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
throw new error_1.CloudBaseError('读取配置失败', { original: error });
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
parseArgs() {
|
|
136
|
-
const args = process.argv.slice(2);
|
|
137
|
-
const doubleDashIndex = args.indexOf('--');
|
|
138
|
-
if (doubleDashIndex !== -1) {
|
|
139
|
-
return args.slice(doubleDashIndex + 1);
|
|
140
|
-
}
|
|
141
|
-
return [];
|
|
142
|
-
}
|
|
143
|
-
getSubCommand(params) {
|
|
144
|
-
return params.length > 0 ? params[0] : 'default';
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
__decorate([
|
|
148
|
-
(0, decorators_1.InjectParams)(),
|
|
149
|
-
__param(0, (0, decorators_1.ArgsOptions)()),
|
|
150
|
-
__param(1, (0, decorators_1.CmdContext)()),
|
|
151
|
-
__param(2, (0, decorators_1.Log)()),
|
|
152
|
-
__metadata("design:type", Function),
|
|
153
|
-
__metadata("design:paramtypes", [Object, Object, log_1.Logger]),
|
|
154
|
-
__metadata("design:returntype", Promise)
|
|
155
|
-
], AICommand.prototype, "execute", null);
|
|
156
|
-
AICommand = __decorate([
|
|
157
|
-
(0, common_1.ICommand)()
|
|
158
|
-
], AICommand);
|
|
159
|
-
exports.AICommand = AICommand;
|
|
160
|
-
function reportAIUsage(agent, hasEnvId, subCommand) {
|
|
161
|
-
return report_1.beaconAction.report('ai_command_usage', {
|
|
162
|
-
agent,
|
|
163
|
-
hasEnvId,
|
|
164
|
-
subCommand
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
function reportAIError(agent, error) {
|
|
168
|
-
return report_1.beaconAction.report('ai_command_error', {
|
|
169
|
-
agent,
|
|
170
|
-
error
|
|
171
|
-
});
|
|
172
|
-
}
|
package/lib/utils/ai/banner.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
-
};
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.showBanner = void 0;
|
|
39
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
40
|
-
function showBanner(log) {
|
|
41
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
try {
|
|
43
|
-
const figlet = yield Promise.resolve().then(() => __importStar(require('figlet')));
|
|
44
|
-
const data = figlet.textSync(`CloudBase
|
|
45
|
-
AI ToolKit`, {
|
|
46
|
-
font: 'Slant',
|
|
47
|
-
horizontalLayout: 'fitted',
|
|
48
|
-
verticalLayout: 'fitted'
|
|
49
|
-
});
|
|
50
|
-
const supportsColor = process.stdout.isTTY && process.env.TERM !== 'dumb';
|
|
51
|
-
if (supportsColor) {
|
|
52
|
-
try {
|
|
53
|
-
const gradient = yield Promise.resolve().then(() => __importStar(require('gradient-string')));
|
|
54
|
-
const gradientText = gradient
|
|
55
|
-
.default(['cyan', 'rgb(0, 111, 150)', 'rgb(0, 246,136)'])
|
|
56
|
-
.multiline(data);
|
|
57
|
-
log.log(chalk_1.default.bold(gradientText + '\n'));
|
|
58
|
-
}
|
|
59
|
-
catch (gradientError) {
|
|
60
|
-
log.log(chalk_1.default.bold.cyan(data + '\n'));
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
log.log(data + '\n');
|
|
65
|
-
}
|
|
66
|
-
if (supportsColor) {
|
|
67
|
-
log.log(chalk_1.default.hex('#34495E')(' 🚀 统一集成各种 AI CLI 工具,内置云开发全栈能力'));
|
|
68
|
-
log.log(chalk_1.default.hex('#34495E')(' ⚡ 生成、部署和托管全栈 Web 应用与小程序、数据库和后端服务'));
|
|
69
|
-
log.log(chalk_1.default.hex('#34495E')(' 🎯 无需运维,极速上线你的创意 💫'));
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
log.log(' 🚀 统一集成各种 AI CLI 工具,内置云开发全栈能力');
|
|
73
|
-
log.log(' ⚡ 生成、部署和托管全栈 Web 应用与小程序、数据库和后端服务');
|
|
74
|
-
log.log(' 🎯 无需运维,极速上线你的创意 💫');
|
|
75
|
-
}
|
|
76
|
-
log.log('');
|
|
77
|
-
}
|
|
78
|
-
catch (e) {
|
|
79
|
-
log.log(chalk_1.default.bold.cyanBright('⛰︎'), chalk_1.default.bold.hex('#FFFFFF')(' CloudBase AI ToolKit CLI'));
|
|
80
|
-
log.log(chalk_1.default.bold.cyanBright(''));
|
|
81
|
-
log.log(chalk_1.default.hex('#34495E')(' 🚀 统一集成各种 AI CLI 工具,内置云开发全栈能力'));
|
|
82
|
-
log.log(chalk_1.default.hex('#34495E')(' ⚡ 生成、部署和托管全栈 Web 应用与小程序、数据库和后端服务'));
|
|
83
|
-
log.log(chalk_1.default.hex('#34495E')(' 🎯 无需运维,极速上线你的创意 💫'));
|
|
84
|
-
log.log('');
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
exports.showBanner = showBanner;
|
package/lib/utils/ai/config.js
DELETED
|
@@ -1,228 +0,0 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.AIConfigManager = exports.createConfigParser = exports.TOOLKIT_CONFIGS = exports.isValidAgent = exports.CONFIG_NOT_FOUND = void 0;
|
|
16
|
-
const error_1 = require("../../error");
|
|
17
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
18
|
-
const envLocalManager_1 = require("./envLocalManager");
|
|
19
|
-
const toolbox_1 = require("@cloudbase/toolbox");
|
|
20
|
-
const const_1 = require("./const");
|
|
21
|
-
exports.CONFIG_NOT_FOUND = 'CONFIG_NOT_FOUND';
|
|
22
|
-
const notFoundError = () => {
|
|
23
|
-
throw new error_1.CloudBaseError('AI 配置未找到,请运行 tcb ai --setup 进行配置', {
|
|
24
|
-
code: exports.CONFIG_NOT_FOUND
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
function isValidAgent(agent) {
|
|
28
|
-
return ['claude', 'qwen', 'codex'].includes(agent);
|
|
29
|
-
}
|
|
30
|
-
exports.isValidAgent = isValidAgent;
|
|
31
|
-
exports.TOOLKIT_CONFIGS = {
|
|
32
|
-
[const_1.CLAUDE.value]: {
|
|
33
|
-
mcp: '.mcp.json',
|
|
34
|
-
rules: 'CLAUDE.md'
|
|
35
|
-
},
|
|
36
|
-
[const_1.QWEN.value]: {
|
|
37
|
-
config: '.env.local',
|
|
38
|
-
rules: 'QWEN.md'
|
|
39
|
-
},
|
|
40
|
-
[const_1.CODEX.value]: {
|
|
41
|
-
config: '.env.local',
|
|
42
|
-
rules: 'CODEX.md'
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
function createConfigParser() {
|
|
46
|
-
return new toolbox_1.ConfigParser({ configPath: const_1.CONFIG_PATH });
|
|
47
|
-
}
|
|
48
|
-
exports.createConfigParser = createConfigParser;
|
|
49
|
-
class AIConfigManager {
|
|
50
|
-
constructor() {
|
|
51
|
-
this.envLocalManager = new envLocalManager_1.EnvLocalManager();
|
|
52
|
-
}
|
|
53
|
-
loadConfig() {
|
|
54
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
-
const parser = createConfigParser();
|
|
56
|
-
const config = yield parser.get('ai');
|
|
57
|
-
!config && notFoundError();
|
|
58
|
-
return config;
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
isConfigured() {
|
|
62
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
-
try {
|
|
64
|
-
const config = yield this.loadConfig();
|
|
65
|
-
return Object.keys(config.agents).length > 0;
|
|
66
|
-
}
|
|
67
|
-
catch (_a) {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
getAgentConfig(agent) {
|
|
73
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
const config = yield this.loadConfig();
|
|
75
|
-
return config.agents[agent] || null;
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
resetConfig() {
|
|
79
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
-
try {
|
|
81
|
-
yield Promise.all([
|
|
82
|
-
new envLocalManager_1.EnvLocalManager().removeAIConfig(),
|
|
83
|
-
createConfigParser().update('ai', {})
|
|
84
|
-
]);
|
|
85
|
-
}
|
|
86
|
-
catch (error) {
|
|
87
|
-
throw new error_1.CloudBaseError('重置 AI 配置失败,请手动删除 `.env.local`、`cloudbaserc.json` 文件中的 AI 配置部分,或重新运行 tcb ai --setup', { original: error });
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
checkToolkitConfig(agent) {
|
|
92
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
const toolkitConfig = exports.TOOLKIT_CONFIGS[agent];
|
|
94
|
-
if (!toolkitConfig) {
|
|
95
|
-
return { hasConfig: false, hasMcp: false, hasRules: false, missingFiles: [] };
|
|
96
|
-
}
|
|
97
|
-
const results = {
|
|
98
|
-
hasConfig: false,
|
|
99
|
-
hasMcp: false,
|
|
100
|
-
hasRules: false,
|
|
101
|
-
missingFiles: []
|
|
102
|
-
};
|
|
103
|
-
if ('mcp' in toolkitConfig) {
|
|
104
|
-
results.hasMcp = yield fs_extra_1.default.pathExists(toolkitConfig.mcp);
|
|
105
|
-
results.hasConfig = results.hasMcp;
|
|
106
|
-
if (!results.hasMcp) {
|
|
107
|
-
results.missingFiles.push(toolkitConfig.mcp);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
else if ('config' in toolkitConfig) {
|
|
111
|
-
results.hasConfig = yield fs_extra_1.default.pathExists(toolkitConfig.config);
|
|
112
|
-
if (!results.hasConfig) {
|
|
113
|
-
results.missingFiles.push(toolkitConfig.config);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
if (toolkitConfig.rules) {
|
|
117
|
-
results.hasRules = yield fs_extra_1.default.pathExists(toolkitConfig.rules);
|
|
118
|
-
if (!results.hasRules) {
|
|
119
|
-
results.missingFiles.push(toolkitConfig.rules);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return results;
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
updateEnvId(envId) {
|
|
126
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
-
this.updateConfig('envId', envId, 'ENV_ID');
|
|
128
|
-
yield fs_extra_1.default.ensureFile(const_1.CLOUDBASE_MCP_CONFIG_PATH);
|
|
129
|
-
yield fs_extra_1.default.writeJson(const_1.CLOUDBASE_MCP_CONFIG_PATH, {
|
|
130
|
-
envId,
|
|
131
|
-
updatedAt: new Date().toISOString(),
|
|
132
|
-
version: '1.0'
|
|
133
|
-
}, { spaces: 2 });
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
updateDefaultAgent(agent) {
|
|
137
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
-
const configParser = createConfigParser();
|
|
139
|
-
yield configParser.update('ai.defaultAgent', '{{env.AI_DEFAULT_AGENT}}');
|
|
140
|
-
this.envLocalManager.updateDefaultAgent(agent);
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
updateClaudeConfig(type, config) {
|
|
144
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
-
yield this.updateConfig('ai.agents.claude.type', type);
|
|
146
|
-
if (type === 'custom') {
|
|
147
|
-
if (config.baseUrl) {
|
|
148
|
-
yield this.updateConfig('ai.agents.claude.baseUrl', config.baseUrl, 'AI_CLAUDE_BASE_URL');
|
|
149
|
-
}
|
|
150
|
-
if (config.apiKey) {
|
|
151
|
-
yield this.updateConfig('ai.agents.claude.apiKey', config.apiKey, 'AI_CLAUDE_API_KEY');
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
else if (type === 'cloudbase') {
|
|
155
|
-
if (config.provider) {
|
|
156
|
-
yield this.updateConfig('ai.agents.claude.provider', config.provider);
|
|
157
|
-
}
|
|
158
|
-
if (config.model) {
|
|
159
|
-
yield this.updateConfig('ai.agents.claude.model', config.model);
|
|
160
|
-
}
|
|
161
|
-
if (config.transformer) {
|
|
162
|
-
yield this.updateConfig('ai.agents.claude.transformer', config.transformer);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
updateQwenConfig(type, config) {
|
|
168
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
169
|
-
yield this.updateConfig('ai.agents.qwen.type', type);
|
|
170
|
-
if (type === 'custom') {
|
|
171
|
-
if (config.baseUrl) {
|
|
172
|
-
yield this.updateConfig('ai.agents.qwen.baseUrl', config.baseUrl, 'AI_QWEN_BASE_URL');
|
|
173
|
-
}
|
|
174
|
-
if (config.apiKey) {
|
|
175
|
-
yield this.updateConfig('ai.agents.qwen.apiKey', config.apiKey, 'AI_QWEN_API_KEY');
|
|
176
|
-
}
|
|
177
|
-
if (config.model) {
|
|
178
|
-
yield this.updateConfig('ai.agents.qwen.model', config.model, 'AI_QWEN_MODEL');
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
else if (type === 'cloudbase') {
|
|
182
|
-
if (config.provider) {
|
|
183
|
-
yield this.updateConfig('ai.agents.qwen.provider', config.provider);
|
|
184
|
-
}
|
|
185
|
-
if (config.model) {
|
|
186
|
-
yield this.updateConfig('ai.agents.qwen.model', config.model);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
updateCodexConfig(type, config) {
|
|
192
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
193
|
-
yield this.updateConfig('ai.agents.codex.type', type);
|
|
194
|
-
if (type === 'custom') {
|
|
195
|
-
if (config.baseUrl) {
|
|
196
|
-
yield this.updateConfig('ai.agents.codex.baseUrl', config.baseUrl, 'AI_CODEX_BASE_URL');
|
|
197
|
-
}
|
|
198
|
-
if (config.apiKey) {
|
|
199
|
-
yield this.updateConfig('ai.agents.codex.apiKey', config.apiKey, 'AI_CODEX_API_KEY');
|
|
200
|
-
}
|
|
201
|
-
if (config.model) {
|
|
202
|
-
yield this.updateConfig('ai.agents.codex.model', config.model, 'AI_CODEX_MODEL');
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
else if (type === 'cloudbase') {
|
|
206
|
-
if (config.provider) {
|
|
207
|
-
yield this.updateConfig('ai.agents.codex.provider', config.provider);
|
|
208
|
-
}
|
|
209
|
-
if (config.model) {
|
|
210
|
-
yield this.updateConfig('ai.agents.codex.model', config.model);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
updateConfig(key, value, env) {
|
|
216
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
217
|
-
const configParser = createConfigParser();
|
|
218
|
-
if (env) {
|
|
219
|
-
this.envLocalManager.setEnvLocal(env, value);
|
|
220
|
-
yield configParser.update(key, `{{env.${env}}}`);
|
|
221
|
-
}
|
|
222
|
-
else {
|
|
223
|
-
yield configParser.update(key, value);
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
exports.AIConfigManager = AIConfigManager;
|
package/lib/utils/ai/const.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getAgentConfigValidator = exports.getDefaultConfig = exports.AGENTS = exports.NONE = exports.CODEX = exports.QWEN = exports.CLAUDE = exports.DEFAULT_CONFIG = exports.CLOUDBASE_MCP_CONFIG_PATH = exports.CLAUDE_CODE_ROUTER_CONFIG_PATH = exports.ENV_LOCAL_PATH = exports.CONFIG_PATH = void 0;
|
|
7
|
-
const os_1 = __importDefault(require("os"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const v3_1 = __importDefault(require("zod/v3"));
|
|
10
|
-
exports.CONFIG_PATH = path_1.default.join(process.cwd(), 'cloudbaserc.json');
|
|
11
|
-
exports.ENV_LOCAL_PATH = path_1.default.join(process.cwd(), '.env.local');
|
|
12
|
-
exports.CLAUDE_CODE_ROUTER_CONFIG_PATH = path_1.default.join(os_1.default.homedir(), '.claude-code-router', 'config.json');
|
|
13
|
-
exports.CLOUDBASE_MCP_CONFIG_PATH = path_1.default.join(os_1.default.homedir(), '.cloudbase-env-id');
|
|
14
|
-
exports.DEFAULT_CONFIG = `{
|
|
15
|
-
"envId": "{{env.ENV_ID}}"
|
|
16
|
-
}`;
|
|
17
|
-
exports.CLAUDE = {
|
|
18
|
-
name: 'Claude Code',
|
|
19
|
-
value: 'claude',
|
|
20
|
-
configSchema: v3_1.default
|
|
21
|
-
.object({
|
|
22
|
-
type: v3_1.default.enum(['custom', 'cloudbase']).optional(),
|
|
23
|
-
baseUrl: v3_1.default.string().optional(),
|
|
24
|
-
apiKey: v3_1.default.string().optional(),
|
|
25
|
-
provider: v3_1.default.string().optional(),
|
|
26
|
-
model: v3_1.default.string().optional(),
|
|
27
|
-
transformer: v3_1.default.string().optional()
|
|
28
|
-
})
|
|
29
|
-
.refine((data) => {
|
|
30
|
-
if (data.type === 'custom' || !data.type) {
|
|
31
|
-
return data.baseUrl && data.apiKey;
|
|
32
|
-
}
|
|
33
|
-
else if (data.type === 'cloudbase') {
|
|
34
|
-
return data.provider && data.model && data.transformer;
|
|
35
|
-
}
|
|
36
|
-
return false;
|
|
37
|
-
})
|
|
38
|
-
};
|
|
39
|
-
exports.QWEN = {
|
|
40
|
-
name: 'Qwen Code',
|
|
41
|
-
value: 'qwen',
|
|
42
|
-
configSchema: v3_1.default
|
|
43
|
-
.object({
|
|
44
|
-
type: v3_1.default.enum(['custom', 'cloudbase']).optional(),
|
|
45
|
-
baseUrl: v3_1.default.string().optional(),
|
|
46
|
-
apiKey: v3_1.default.string().optional(),
|
|
47
|
-
provider: v3_1.default.string().optional(),
|
|
48
|
-
model: v3_1.default.string().optional()
|
|
49
|
-
})
|
|
50
|
-
.refine((data) => {
|
|
51
|
-
if (data.type === 'custom' || !data.type) {
|
|
52
|
-
return data.baseUrl && data.apiKey;
|
|
53
|
-
}
|
|
54
|
-
else if (data.type === 'cloudbase') {
|
|
55
|
-
return data.provider && data.model;
|
|
56
|
-
}
|
|
57
|
-
return false;
|
|
58
|
-
})
|
|
59
|
-
};
|
|
60
|
-
exports.CODEX = {
|
|
61
|
-
name: 'OpenAI Codex',
|
|
62
|
-
value: 'codex',
|
|
63
|
-
configSchema: v3_1.default
|
|
64
|
-
.object({
|
|
65
|
-
type: v3_1.default.enum(['custom', 'cloudbase']).optional(),
|
|
66
|
-
baseUrl: v3_1.default.string().optional(),
|
|
67
|
-
apiKey: v3_1.default.string().optional(),
|
|
68
|
-
provider: v3_1.default.string().optional(),
|
|
69
|
-
model: v3_1.default.string().optional()
|
|
70
|
-
})
|
|
71
|
-
.refine((data) => {
|
|
72
|
-
if (data.type === 'custom' || !data.type) {
|
|
73
|
-
return data.baseUrl && data.apiKey && data.model;
|
|
74
|
-
}
|
|
75
|
-
else if (data.type === 'cloudbase') {
|
|
76
|
-
return data.provider && data.model;
|
|
77
|
-
}
|
|
78
|
-
return false;
|
|
79
|
-
})
|
|
80
|
-
};
|
|
81
|
-
exports.NONE = {
|
|
82
|
-
name: '暂不配置',
|
|
83
|
-
value: 'none'
|
|
84
|
-
};
|
|
85
|
-
exports.AGENTS = [exports.CLAUDE, exports.QWEN, exports.CODEX, exports.NONE];
|
|
86
|
-
function getDefaultConfig(agent) {
|
|
87
|
-
const agentConfig = exports.AGENTS.find((a) => a.value === agent);
|
|
88
|
-
if (!agentConfig) {
|
|
89
|
-
return {};
|
|
90
|
-
}
|
|
91
|
-
if ('defaultConfig' in agentConfig) {
|
|
92
|
-
return agentConfig.defaultConfig;
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
return {};
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
exports.getDefaultConfig = getDefaultConfig;
|
|
99
|
-
function getAgentConfigValidator(agent) {
|
|
100
|
-
const agentConfig = exports.AGENTS.find((a) => a.value === agent);
|
|
101
|
-
if (!agentConfig)
|
|
102
|
-
throw new Error('Agent not found');
|
|
103
|
-
return 'configSchema' in agentConfig
|
|
104
|
-
? (x) => agentConfig.configSchema.safeParse(x)
|
|
105
|
-
: () => ({ success: true });
|
|
106
|
-
}
|
|
107
|
-
exports.getAgentConfigValidator = getAgentConfigValidator;
|
|
@@ -1,26 +0,0 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.ensureFiles = void 0;
|
|
16
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
17
|
-
const const_1 = require("./const");
|
|
18
|
-
function ensureFiles() {
|
|
19
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
yield fs_extra_1.default.ensureFile(const_1.ENV_LOCAL_PATH);
|
|
21
|
-
if (!(yield fs_extra_1.default.exists(const_1.CONFIG_PATH))) {
|
|
22
|
-
yield fs_extra_1.default.writeFile(const_1.CONFIG_PATH, const_1.DEFAULT_CONFIG);
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
exports.ensureFiles = ensureFiles;
|