@cloudbase/cli 2.8.0-beta.4 → 2.8.0-beta.6

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 (43) hide show
  1. package/.augment-guidelines +119 -0
  2. package/.claude/settings.local.json +6 -0
  3. package/.clinerules/cloudbase-rules.mdc +119 -0
  4. package/.cursor/rules/cloudbase-rules.mdc +119 -0
  5. package/.env.local +5 -0
  6. package/.mcp.json +11 -0
  7. package/CLAUDE.md +119 -0
  8. package/README.md +13 -1
  9. package/bin/cloudbase-mcp.js +24 -0
  10. package/bin/tcb.js +0 -2
  11. package/cloudbaserc.json +3 -0
  12. package/lib/commands/ai/index.js +172 -0
  13. package/lib/commands/cloudrun/base.js +2 -2
  14. package/lib/commands/index.js +1 -0
  15. package/lib/commands/utils.js +10 -4
  16. package/lib/utils/ai/banner.js +88 -0
  17. package/lib/utils/ai/config.js +254 -0
  18. package/lib/utils/ai/const.js +156 -0
  19. package/lib/utils/ai/ensureFiles.js +26 -0
  20. package/lib/utils/ai/envLocalManager.js +144 -0
  21. package/lib/utils/ai/router.js +1089 -0
  22. package/lib/utils/ai/setup.js +550 -0
  23. package/package.json +11 -3
  24. package/rules/cloudbase-platform.mdc +44 -0
  25. package/rules/database.mdc +25 -0
  26. package/rules/miniprogram-development.mdc +61 -0
  27. package/rules/ui-design.mdc +24 -0
  28. package/rules/web-development.mdc +44 -0
  29. package/rules/workflows.mdc +30 -0
  30. package/specs/mcp-global-bin/design.md +57 -0
  31. package/specs/mcp-global-bin/requirements.md +43 -0
  32. package/specs/mcp-global-bin/tasks.md +54 -0
  33. package/types/commands/ai/index.d.ts +23 -0
  34. package/types/commands/index.d.ts +1 -0
  35. package/types/commands/utils.d.ts +6 -0
  36. package/types/utils/ai/banner.d.ts +2 -0
  37. package/types/utils/ai/config.d.ts +79 -0
  38. package/types/utils/ai/const.d.ts +328 -0
  39. package/types/utils/ai/ensureFiles.d.ts +1 -0
  40. package/types/utils/ai/envLocalManager.d.ts +23 -0
  41. package/types/utils/ai/router.d.ts +45 -0
  42. package/types/utils/ai/setup.d.ts +23 -0
  43. package/types/utils/config.d.ts +1 -0
@@ -0,0 +1,156 @@
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.getDefaultModelByBaseUrl = exports.BASE_URL_MODEL_MAPPING = exports.getAgentConfigValidator = exports.getDefaultConfig = exports.CLOUDBASE_PROVIDERS = exports.AGENTS = exports.NONE = exports.AIDER = 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;
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.AIDER = {
82
+ name: 'aider',
83
+ value: 'aider',
84
+ configSchema: v3_1.default
85
+ .object({
86
+ type: v3_1.default.enum(['custom', 'cloudbase']).optional(),
87
+ apiKey: v3_1.default.string().optional(),
88
+ baseUrl: v3_1.default.string().optional(),
89
+ model: v3_1.default.string().optional(),
90
+ provider: v3_1.default.string().optional()
91
+ })
92
+ .refine((data) => {
93
+ if (data.type === 'custom' || !data.type) {
94
+ return data.baseUrl && data.apiKey && data.model;
95
+ }
96
+ else if (data.type === 'cloudbase') {
97
+ return data.provider && data.model;
98
+ }
99
+ return false;
100
+ })
101
+ };
102
+ exports.NONE = {
103
+ name: '暂不配置',
104
+ value: 'none'
105
+ };
106
+ exports.AGENTS = [exports.CLAUDE, exports.QWEN, exports.CODEX, exports.AIDER, exports.NONE];
107
+ exports.CLOUDBASE_PROVIDERS = [
108
+ {
109
+ name: 'DeepSeek',
110
+ value: 'deepseek',
111
+ models: ['deepseek-v3'],
112
+ transformer: 'deepseek'
113
+ },
114
+ {
115
+ name: 'KIMI',
116
+ value: 'kimi',
117
+ models: ['Kimi-K2-Instruct-Online-128K'],
118
+ transformer: undefined
119
+ },
120
+ {
121
+ name: '自定义',
122
+ value: 'custom',
123
+ models: [],
124
+ transformer: undefined
125
+ }
126
+ ];
127
+ function getDefaultConfig(agent) {
128
+ const agentConfig = exports.AGENTS.find((a) => a.value === agent);
129
+ if (!agentConfig) {
130
+ return {};
131
+ }
132
+ if ('defaultConfig' in agentConfig) {
133
+ return agentConfig.defaultConfig;
134
+ }
135
+ else {
136
+ return {};
137
+ }
138
+ }
139
+ exports.getDefaultConfig = getDefaultConfig;
140
+ function getAgentConfigValidator(agent) {
141
+ const agentConfig = exports.AGENTS.find((a) => a.value === agent);
142
+ if (!agentConfig)
143
+ throw new Error('Agent not found');
144
+ return 'configSchema' in agentConfig
145
+ ? (x) => agentConfig.configSchema.safeParse(x)
146
+ : () => ({ success: true });
147
+ }
148
+ exports.getAgentConfigValidator = getAgentConfigValidator;
149
+ exports.BASE_URL_MODEL_MAPPING = {
150
+ 'https://api.moonshot.cn/v1': 'kimi-k2-0711-preview',
151
+ 'https://open.bigmodel.cn/api/paas/v4': 'glm-4.5'
152
+ };
153
+ function getDefaultModelByBaseUrl(baseUrl) {
154
+ return exports.BASE_URL_MODEL_MAPPING[baseUrl] || 'gpt-4';
155
+ }
156
+ exports.getDefaultModelByBaseUrl = getDefaultModelByBaseUrl;
@@ -0,0 +1,26 @@
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;
@@ -0,0 +1,144 @@
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.EnvLocalManager = void 0;
39
+ const fs_extra_1 = __importDefault(require("fs-extra"));
40
+ const error_1 = require("../../error");
41
+ const dotenvx = __importStar(require("@dotenvx/dotenvx"));
42
+ const const_1 = require("./const");
43
+ dotenvx.setLogLevel({
44
+ logLevel: 'error'
45
+ });
46
+ class EnvLocalManager {
47
+ updateEnvId(envId) {
48
+ this.setEnvLocal('ENV_ID', envId);
49
+ }
50
+ parseEnvFile() {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ const content = yield fs_extra_1.default.readFile(const_1.ENV_LOCAL_PATH, 'utf8');
53
+ return dotenvx.parse(content);
54
+ });
55
+ }
56
+ updateAIConfig(aiConfig) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ try {
59
+ yield this.addAIConfigToEnv(aiConfig);
60
+ }
61
+ catch (error) {
62
+ throw new error_1.CloudBaseError(`更新 AI 配置失败: ${error.message}`, { original: error });
63
+ }
64
+ });
65
+ }
66
+ removeAIConfig(agentName) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ try {
69
+ const envMap = yield this.parseEnvFile();
70
+ if (agentName) {
71
+ this.removeSpecificAgentConfig(envMap, agentName);
72
+ }
73
+ else {
74
+ this.removeAIConfigFromMap(envMap);
75
+ }
76
+ }
77
+ catch (error) {
78
+ throw new error_1.CloudBaseError(`移除 AI 配置失败: ${error.message}`, { original: error });
79
+ }
80
+ });
81
+ }
82
+ validateAIConfig(aiConfig) {
83
+ const errors = [];
84
+ if (!aiConfig.defaultAgent) {
85
+ errors.push('默认 AI 工具不能为空');
86
+ }
87
+ Object.entries(aiConfig.agents).forEach(([agentName, config]) => {
88
+ if (!config.apiKey) {
89
+ errors.push(`${agentName} 必须配置 API Key`);
90
+ }
91
+ if (config.baseUrl && !isValidUrl(config.baseUrl)) {
92
+ errors.push(`${agentName} 的 Base URL 格式不正确`);
93
+ }
94
+ });
95
+ return errors;
96
+ }
97
+ updateDefaultAgent(agent) {
98
+ this.setEnvLocal('AI_DEFAULT_AGENT', agent);
99
+ }
100
+ setEnvLocal(key, value) {
101
+ dotenvx.set(key, value, { path: const_1.ENV_LOCAL_PATH, encrypt: false });
102
+ }
103
+ removeEnvLocal(key) {
104
+ dotenvx.set(key, '', { path: const_1.ENV_LOCAL_PATH, encrypt: false });
105
+ }
106
+ removeAIConfigFromMap(envMap) {
107
+ Object.keys(envMap)
108
+ .filter((x) => x.startsWith('AI_'))
109
+ .forEach((x) => this.removeEnvLocal(x));
110
+ }
111
+ removeSpecificAgentConfig(envMap, agentName) {
112
+ const agentPrefix = `AI_${agentName.toUpperCase()}_`;
113
+ Object.keys(envMap)
114
+ .filter((x) => x.startsWith(agentPrefix))
115
+ .forEach((x) => this.removeEnvLocal(x));
116
+ }
117
+ addAIConfigToEnv(aiConfig) {
118
+ return __awaiter(this, void 0, void 0, function* () {
119
+ this.setEnvLocal('AI_DEFAULT_AGENT', aiConfig.defaultAgent);
120
+ Object.entries(aiConfig.agents).forEach(([agentName, agentConfig]) => {
121
+ const upperAgentName = agentName.toUpperCase();
122
+ if (agentConfig.apiKey) {
123
+ this.setEnvLocal(`AI_${upperAgentName}_API_KEY`, agentConfig.apiKey);
124
+ }
125
+ if (agentConfig.baseUrl) {
126
+ this.setEnvLocal(`AI_${upperAgentName}_BASE_URL`, agentConfig.baseUrl);
127
+ }
128
+ if (agentConfig.model) {
129
+ this.setEnvLocal(`AI_${upperAgentName}_MODEL`, agentConfig.model);
130
+ }
131
+ });
132
+ });
133
+ }
134
+ }
135
+ exports.EnvLocalManager = EnvLocalManager;
136
+ function isValidUrl(url) {
137
+ try {
138
+ new URL(url);
139
+ return true;
140
+ }
141
+ catch (_a) {
142
+ return false;
143
+ }
144
+ }