@vectorx/cloud-toolkit 0.0.0-beta-20260109055258 → 0.0.0-beta-20260320063305
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/agent.kit.js +274 -56
- package/lib/cloud-dev.kit.js +36 -0
- package/lib/config/api.config.js +2 -8
- package/lib/container/container.js +10 -0
- package/lib/container/identifiers.js +5 -0
- package/lib/container/index.js +15 -0
- package/lib/database.kit.js +56 -0
- package/lib/env.kit.js +40 -0
- package/lib/fun.kit.js +34 -0
- package/lib/index.js +6 -0
- package/lib/services/agent-service.js +132 -0
- package/lib/services/auth-service.js +2 -1
- package/lib/services/cloud-dev-service.js +97 -0
- package/lib/services/cloud-env-service.js +166 -0
- package/lib/services/database-service.js +142 -0
- package/lib/services/fun-service.js +378 -0
- package/lib/services/index.js +5 -0
- package/lib/utils/cos-uploader.js +3 -1
- package/lib/utils/fun-project-validator.js +212 -0
- package/lib/utils/open-browser.js +7 -1
- package/lib/utils/openChrome.applescript +2 -2
- package/lib/utils/output.js +53 -19
- package/lib/utils/project-validator.js +3 -1
- package/lib/utils/request.js +21 -0
- package/lib/utils/table.js +17 -0
- package/lib/utils/tracker/ai-apm.js +62 -0
- package/lib/utils/tracker/apm.js +137 -0
- package/lib/utils/tracker/cli-apm.js +108 -0
- package/lib/utils/tracker/device.js +3 -1
- package/lib/utils/tracker/index.js +18 -131
- package/package.json +15 -7
- package/types/agent.kit.d.ts +45 -2
- package/types/cloud-dev.kit.d.ts +18 -0
- package/types/config/api.config.d.ts +1 -2
- package/types/container/identifiers.d.ts +6 -1
- package/types/container/index.d.ts +6 -1
- package/types/container/types.d.ts +124 -0
- package/types/database.kit.d.ts +54 -0
- package/types/env.kit.d.ts +43 -0
- package/types/fun.kit.d.ts +63 -0
- package/types/index.d.ts +6 -0
- package/types/services/agent-service.d.ts +11 -0
- package/types/services/cloud-dev-service.d.ts +23 -0
- package/types/services/cloud-env-service.d.ts +10 -0
- package/types/services/database-service.d.ts +33 -0
- package/types/services/fun-service.d.ts +23 -0
- package/types/services/index.d.ts +5 -0
- package/types/utils/fun-project-validator.d.ts +22 -0
- package/types/utils/table.d.ts +2 -0
- package/types/utils/tracker/ai-apm.d.ts +54 -0
- package/types/utils/tracker/apm.d.ts +28 -0
- package/types/utils/tracker/cli-apm.d.ts +27 -0
- package/types/utils/tracker/index.d.ts +5 -27
package/lib/agent.kit.js
CHANGED
|
@@ -17,16 +17,20 @@ exports.startDev = startDev;
|
|
|
17
17
|
exports.build = build;
|
|
18
18
|
exports.createNew = createNew;
|
|
19
19
|
exports.cleanup = cleanup;
|
|
20
|
+
exports.getAgentInfo = getAgentInfo;
|
|
21
|
+
exports.getAgentList = getAgentList;
|
|
22
|
+
exports.getAgentInfoById = getAgentInfoById;
|
|
20
23
|
const child_process_1 = require("child_process");
|
|
21
24
|
const fs_1 = __importDefault(require("fs"));
|
|
22
25
|
const path_1 = __importDefault(require("path"));
|
|
23
|
-
const
|
|
26
|
+
const endpoints_1 = require("@vectorx/endpoints");
|
|
24
27
|
const archiver_1 = __importDefault(require("archiver"));
|
|
25
28
|
const semver_1 = __importDefault(require("semver"));
|
|
26
29
|
const container_1 = require("./container");
|
|
27
30
|
const env_helper_1 = require("./utils/env-helper");
|
|
28
31
|
const port_finder_1 = require("./utils/port-finder");
|
|
29
32
|
const project_validator_1 = require("./utils/project-validator");
|
|
33
|
+
const request_1 = require("./utils/request");
|
|
30
34
|
let rcbProcess = null;
|
|
31
35
|
function validatePort(port, name = "端口") {
|
|
32
36
|
if (isNaN(port) || port < 1 || port > 65535) {
|
|
@@ -34,7 +38,7 @@ function validatePort(port, name = "端口") {
|
|
|
34
38
|
}
|
|
35
39
|
}
|
|
36
40
|
function startRcbFramework(workDir_1, port_1, watch_1) {
|
|
37
|
-
return __awaiter(this, arguments, void 0, function* (workDir, port, watch, nodePath = "node", options) {
|
|
41
|
+
return __awaiter(this, arguments, void 0, function* (workDir, port, watch, nodePath = "node", options, onLog) {
|
|
38
42
|
return new Promise((resolve, reject) => {
|
|
39
43
|
const args = [
|
|
40
44
|
...(watch ? ["--watch"] : []),
|
|
@@ -47,10 +51,31 @@ function startRcbFramework(workDir_1, port_1, watch_1) {
|
|
|
47
51
|
"localhost,127.0.0.1",
|
|
48
52
|
"--config",
|
|
49
53
|
"agent-cloudbase-functions.json",
|
|
54
|
+
...((options === null || options === void 0 ? void 0 : options.mode) ? ["--mode", options.mode] : []),
|
|
50
55
|
...((options === null || options === void 0 ? void 0 : options.enableRedLangfuse) ? ["--enableRedLangfuse"] : []),
|
|
51
56
|
];
|
|
52
57
|
try {
|
|
53
|
-
|
|
58
|
+
let packagePath;
|
|
59
|
+
try {
|
|
60
|
+
packagePath = require.resolve("@vectorx/functions-framework/package.json", {
|
|
61
|
+
paths: [workDir],
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
const msg = (err === null || err === void 0 ? void 0 : err.message) || String(err);
|
|
66
|
+
const isMissing = (err === null || err === void 0 ? void 0 : err.code) === "MODULE_NOT_FOUND" &&
|
|
67
|
+
(msg.includes("@vectorx/functions-framework") || msg.includes("functions-framework"));
|
|
68
|
+
if (!isMissing) {
|
|
69
|
+
throw err;
|
|
70
|
+
}
|
|
71
|
+
throw new Error([
|
|
72
|
+
"未检测到可选依赖 @vectorx/functions-framework,无法启动 rcb-ff 服务。",
|
|
73
|
+
"请在你的项目根目录安装(推荐):",
|
|
74
|
+
" pnpm add @vectorx/functions-framework",
|
|
75
|
+
"或在 monorepo 根目录安装:",
|
|
76
|
+
" pnpm add -w @vectorx/functions-framework",
|
|
77
|
+
].join("\n"));
|
|
78
|
+
}
|
|
54
79
|
const packageDir = path_1.default.dirname(packagePath);
|
|
55
80
|
const rcbFfPath = path_1.default.join(packageDir, "bin/rcb-ff.js");
|
|
56
81
|
console.log("开始启动 rcb-ff 服务...");
|
|
@@ -61,12 +86,32 @@ function startRcbFramework(workDir_1, port_1, watch_1) {
|
|
|
61
86
|
cwd: workDir,
|
|
62
87
|
});
|
|
63
88
|
rcbProcess.stdout.on("data", (data) => {
|
|
64
|
-
const
|
|
65
|
-
|
|
89
|
+
const logMessage = data.toString();
|
|
90
|
+
process.stdout.write(logMessage);
|
|
91
|
+
if (onLog) {
|
|
92
|
+
const lines = logMessage.split(/\r?\n/).filter((line) => line.trim().length > 0);
|
|
93
|
+
lines.forEach((line) => {
|
|
94
|
+
onLog({
|
|
95
|
+
level: "info",
|
|
96
|
+
message: line,
|
|
97
|
+
timestamp: new Date().toISOString(),
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
}
|
|
66
101
|
});
|
|
67
102
|
rcbProcess.stderr.on("data", (data) => {
|
|
68
|
-
const
|
|
69
|
-
|
|
103
|
+
const logMessage = data.toString();
|
|
104
|
+
process.stderr.write(logMessage);
|
|
105
|
+
if (onLog) {
|
|
106
|
+
const lines = logMessage.split(/\r?\n/).filter((line) => line.trim().length > 0);
|
|
107
|
+
lines.forEach((line) => {
|
|
108
|
+
onLog({
|
|
109
|
+
level: "error",
|
|
110
|
+
message: line,
|
|
111
|
+
timestamp: new Date().toISOString(),
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
}
|
|
70
115
|
});
|
|
71
116
|
rcbProcess.on("message", (message) => {
|
|
72
117
|
if ((message.type === "message" && message.data.type === "start-up") ||
|
|
@@ -96,10 +141,21 @@ function startRcbFramework(workDir_1, port_1, watch_1) {
|
|
|
96
141
|
}
|
|
97
142
|
function startDev(options) {
|
|
98
143
|
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
-
|
|
144
|
+
var _a, _b;
|
|
145
|
+
const { workDir = process.cwd(), port: specifiedPort, simulatorPort: specifiedSimulatorPort, idePort: specifiedIdePort, watch = false, enableRedLangfuse = false, mode = "agent", useIde = false, } = options;
|
|
100
146
|
if (!fs_1.default.existsSync(workDir)) {
|
|
101
147
|
throw new Error(`目录不存在: ${workDir}`);
|
|
102
148
|
}
|
|
149
|
+
const authService = container_1.container.get(container_1.SERVICE_IDENTIFIERS.AuthService);
|
|
150
|
+
const loginInfo = yield authService.getLoginInfo();
|
|
151
|
+
if (!loginInfo) {
|
|
152
|
+
console.warn([
|
|
153
|
+
"",
|
|
154
|
+
"⚠️ 检测到您尚未登录云服务 CLI。",
|
|
155
|
+
" IDE 工作台即将启动,您可以稍后在工作台内完成登录。",
|
|
156
|
+
"",
|
|
157
|
+
].join("\n"));
|
|
158
|
+
}
|
|
103
159
|
let port;
|
|
104
160
|
if (specifiedPort) {
|
|
105
161
|
validatePort(specifiedPort, "Agent Server 端口");
|
|
@@ -127,39 +183,177 @@ function startDev(options) {
|
|
|
127
183
|
else {
|
|
128
184
|
simulatorPort = yield (0, port_finder_1.findAvailablePort)(port + 1);
|
|
129
185
|
}
|
|
130
|
-
|
|
131
|
-
|
|
186
|
+
const logCollector = [];
|
|
187
|
+
let logBroadcastFn = null;
|
|
188
|
+
yield startRcbFramework(workDir, port, watch, undefined, { enableRedLangfuse, mode }, (log) => {
|
|
189
|
+
if (logBroadcastFn) {
|
|
190
|
+
logBroadcastFn(log);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
logCollector.push(log);
|
|
194
|
+
if (logCollector.length > 1000) {
|
|
195
|
+
logCollector.shift();
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
let AgentSimulator = (_a = options === null || options === void 0 ? void 0 : options.deps) === null || _a === void 0 ? void 0 : _a.AgentSimulator;
|
|
200
|
+
if (!AgentSimulator) {
|
|
201
|
+
try {
|
|
202
|
+
const mod = require("@vectorx/agent-simulator");
|
|
203
|
+
AgentSimulator = ((mod === null || mod === void 0 ? void 0 : mod.AgentSimulator) || (mod === null || mod === void 0 ? void 0 : mod.default) || mod);
|
|
204
|
+
}
|
|
205
|
+
catch (err) {
|
|
206
|
+
const msg = (err === null || err === void 0 ? void 0 : err.message) || String(err);
|
|
207
|
+
const isMissing = (err === null || err === void 0 ? void 0 : err.code) === "MODULE_NOT_FOUND" &&
|
|
208
|
+
(msg.includes("@vectorx/agent-simulator") || msg.includes("agent-simulator"));
|
|
209
|
+
if (!isMissing)
|
|
210
|
+
throw err;
|
|
211
|
+
throw new Error([
|
|
212
|
+
"未检测到可选依赖 @vectorx/agent-simulator,无法启动本地模拟器。",
|
|
213
|
+
"如在 CLI 中使用,请升级/使用最新的 rcb(CLI 会自动注入该依赖)。",
|
|
214
|
+
"如需在当前项目手动启用该能力,请安装:",
|
|
215
|
+
" pnpm add @vectorx/agent-simulator",
|
|
216
|
+
"或在 monorepo 根目录安装:",
|
|
217
|
+
" pnpm add -w @vectorx/agent-simulator",
|
|
218
|
+
].join("\n"));
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
let agentId;
|
|
222
|
+
try {
|
|
223
|
+
const projectConfigPath = path_1.default.join(workDir, "project.config.json");
|
|
224
|
+
if (fs_1.default.existsSync(projectConfigPath)) {
|
|
225
|
+
const projectInfo = JSON.parse(fs_1.default.readFileSync(projectConfigPath, "utf-8"));
|
|
226
|
+
agentId = projectInfo.agentId;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
catch (_c) {
|
|
230
|
+
console.warn("[agent-kit] project.config.json 信息格式不正确,无法读取 agentId");
|
|
231
|
+
}
|
|
232
|
+
const agentServerUrl = `http://localhost:${port}/v1/aiagent/agents/demo-agent`;
|
|
233
|
+
const simulator = new AgentSimulator({
|
|
132
234
|
port: simulatorPort,
|
|
133
|
-
agentServerUrl
|
|
235
|
+
agentServerUrl,
|
|
134
236
|
open: false,
|
|
237
|
+
quiet: useIde,
|
|
238
|
+
agentId,
|
|
135
239
|
});
|
|
136
240
|
yield simulator.start();
|
|
241
|
+
if (useIde) {
|
|
242
|
+
let startFunctionDebugger = (_b = options === null || options === void 0 ? void 0 : options.deps) === null || _b === void 0 ? void 0 : _b.startFunctionDebugger;
|
|
243
|
+
if (!startFunctionDebugger) {
|
|
244
|
+
try {
|
|
245
|
+
const mod = require("@vectorx/function-debugger/lib/App");
|
|
246
|
+
startFunctionDebugger = (mod === null || mod === void 0 ? void 0 : mod.startFunctionDebugger) || (mod === null || mod === void 0 ? void 0 : mod.default);
|
|
247
|
+
}
|
|
248
|
+
catch (err) {
|
|
249
|
+
const msg = (err === null || err === void 0 ? void 0 : err.message) || String(err);
|
|
250
|
+
const isMissing = (err === null || err === void 0 ? void 0 : err.code) === "MODULE_NOT_FOUND" &&
|
|
251
|
+
(msg.includes("@vectorx/function-debugger") || msg.includes("function-debugger"));
|
|
252
|
+
if (!isMissing)
|
|
253
|
+
throw err;
|
|
254
|
+
throw new Error([
|
|
255
|
+
"未检测到可选依赖 @vectorx/function-debugger,无法启动 Web IDE 模式。",
|
|
256
|
+
"如在 CLI 中使用,请升级/使用最新的 rcb(CLI 会自动注入该依赖)。",
|
|
257
|
+
"如需在当前项目手动启用该能力,请安装:",
|
|
258
|
+
" pnpm add @vectorx/function-debugger",
|
|
259
|
+
"或在 monorepo 根目录安装:",
|
|
260
|
+
" pnpm add -w @vectorx/function-debugger",
|
|
261
|
+
].join("\n"));
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
const ideRuntime = yield startFunctionDebugger({
|
|
265
|
+
source: workDir,
|
|
266
|
+
apiPort: specifiedIdePort,
|
|
267
|
+
watch,
|
|
268
|
+
quiet: true,
|
|
269
|
+
openBrowser: false,
|
|
270
|
+
targetBaseUrl: `http://localhost:${port}`,
|
|
271
|
+
devMode: "agent",
|
|
272
|
+
agentSimulatorUrl: `http://localhost:${simulatorPort}`,
|
|
273
|
+
onLogBroadcastReady: (broadcastFn) => {
|
|
274
|
+
logBroadcastFn = broadcastFn;
|
|
275
|
+
logCollector.forEach((log) => broadcastFn(log));
|
|
276
|
+
logCollector.length = 0;
|
|
277
|
+
},
|
|
278
|
+
});
|
|
279
|
+
console.log(`
|
|
280
|
+
┌──────────────────────────────────────────────────────────┐
|
|
281
|
+
│ │
|
|
282
|
+
│ 🚀 Agent Web IDE 开发环境已启动! │
|
|
283
|
+
│ │
|
|
284
|
+
│ 🖥️ Web IDE 地址: ${ideRuntime.uiUrl.padEnd(33)}│
|
|
285
|
+
│ 📡 Agent 模拟器: http://localhost:${String(simulatorPort).padEnd(22)}│
|
|
286
|
+
│ 🔗 Agent Server: http://localhost:${String(port).padEnd(22)}│
|
|
287
|
+
│ 🧩 Agent 服务入口: ${agentServerUrl.length > 33 ? agentServerUrl.slice(0, 30) + "..." : agentServerUrl.padEnd(33)}│
|
|
288
|
+
│ │
|
|
289
|
+
└──────────────────────────────────────────────────────────┘
|
|
290
|
+
`);
|
|
291
|
+
return {
|
|
292
|
+
port,
|
|
293
|
+
simulatorPort,
|
|
294
|
+
simulator,
|
|
295
|
+
ideUrl: ideRuntime.uiUrl,
|
|
296
|
+
rcbProcess,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
137
299
|
return {
|
|
138
300
|
port,
|
|
139
301
|
simulatorPort,
|
|
140
302
|
simulator,
|
|
303
|
+
ideUrl: undefined,
|
|
141
304
|
rcbProcess,
|
|
142
305
|
};
|
|
143
306
|
});
|
|
144
307
|
}
|
|
145
308
|
function build(options) {
|
|
146
309
|
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
-
const { workDir = process.cwd(), outputDir = path_1.default.join(workDir, "dist"), filename = "agent.zip", upload = false, uploadInfo, } = options;
|
|
310
|
+
const { workDir = process.cwd(), outputDir = path_1.default.join(workDir, "dist"), filename = "agent.zip", upload = false, uploadInfo, logCollector, } = options;
|
|
311
|
+
const log = (message_1, ...args_1) => __awaiter(this, [message_1, ...args_1], void 0, function* (message, type = "info", loading = false) {
|
|
312
|
+
if (logCollector) {
|
|
313
|
+
yield logCollector.addLog(message, type, loading);
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
switch (type) {
|
|
317
|
+
case "success":
|
|
318
|
+
console.log(`✓ ${message}`);
|
|
319
|
+
break;
|
|
320
|
+
case "error":
|
|
321
|
+
console.error(`✗ ${message}`);
|
|
322
|
+
break;
|
|
323
|
+
case "warn":
|
|
324
|
+
console.warn(`⚠ ${message}`);
|
|
325
|
+
break;
|
|
326
|
+
default:
|
|
327
|
+
console.log(message);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
yield log("初始化检查...", "info");
|
|
148
332
|
if (!fs_1.default.existsSync(workDir)) {
|
|
333
|
+
yield log(`目录不存在: ${workDir}`, "error");
|
|
149
334
|
throw new Error(`目录不存在: ${workDir}`);
|
|
150
335
|
}
|
|
336
|
+
yield log(`工作目录: ${workDir}`, "info");
|
|
337
|
+
yield log("开始校验项目结构与依赖...", "info", true);
|
|
151
338
|
const validator = new project_validator_1.ProjectValidator(workDir, uploadInfo);
|
|
152
339
|
if (validator) {
|
|
153
340
|
const validationResult = yield validator.validate();
|
|
154
341
|
if (!validationResult.valid) {
|
|
342
|
+
for (const err of validationResult.errors) {
|
|
343
|
+
yield log(`校验失败: ${err}`, "error");
|
|
344
|
+
}
|
|
155
345
|
throw new Error(`项目验证失败:\n${validationResult.errors.join("\n")}`);
|
|
156
346
|
}
|
|
157
347
|
}
|
|
348
|
+
yield log("项目校验通过", "success");
|
|
158
349
|
if (!fs_1.default.existsSync(outputDir)) {
|
|
159
350
|
fs_1.default.mkdirSync(outputDir, { recursive: true });
|
|
351
|
+
yield log(`创建输出目录: ${outputDir}`, "info");
|
|
160
352
|
}
|
|
161
353
|
const zipFilename = filename.endsWith(".zip") ? filename : `${filename}.zip`;
|
|
162
354
|
const outputPath = path_1.default.join(outputDir, zipFilename);
|
|
355
|
+
yield log("开始打包代码...", "info", true);
|
|
356
|
+
yield log(`打包文件: ${zipFilename}`, "info");
|
|
163
357
|
yield new Promise((resolve, reject) => {
|
|
164
358
|
const output = fs_1.default.createWriteStream(outputPath);
|
|
165
359
|
const archive = (0, archiver_1.default)("zip", {
|
|
@@ -172,61 +366,39 @@ function build(options) {
|
|
|
172
366
|
reject(err);
|
|
173
367
|
});
|
|
174
368
|
archive.pipe(output);
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
const fullPath = path_1.default.join(dir, file);
|
|
180
|
-
const relativePath = path_1.default.join(basePath, file);
|
|
181
|
-
const stat = fs_1.default.statSync(fullPath);
|
|
182
|
-
const excludePatterns = [/^\.git/, /^dist/, /\.zip$/, /\.DS_Store$/];
|
|
183
|
-
if (excludePatterns.some((pattern) => pattern.test(relativePath))) {
|
|
184
|
-
continue;
|
|
185
|
-
}
|
|
186
|
-
if (stat.isDirectory()) {
|
|
187
|
-
collectFiles(fullPath, relativePath);
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
const isExecutable = relativePath.startsWith("bin/") ||
|
|
191
|
-
relativePath.includes("/bin/") ||
|
|
192
|
-
(() => {
|
|
193
|
-
try {
|
|
194
|
-
const content = fs_1.default.readFileSync(fullPath, "utf8");
|
|
195
|
-
return content.startsWith("#!/");
|
|
196
|
-
}
|
|
197
|
-
catch (_a) {
|
|
198
|
-
return false;
|
|
199
|
-
}
|
|
200
|
-
})();
|
|
201
|
-
filesToAdd.push({ fullPath, relativePath, isExecutable });
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
collectFiles(workDir);
|
|
206
|
-
for (const { fullPath, relativePath, isExecutable } of filesToAdd) {
|
|
207
|
-
if (isExecutable) {
|
|
208
|
-
archive.file(fullPath, { name: relativePath, mode: 0o755 });
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
archive.file(fullPath, { name: relativePath });
|
|
369
|
+
archive.directory(workDir, false, (data) => {
|
|
370
|
+
const excludePatterns = [/^\.git/, /^\.agentConfig/, /^dist/, /\.zip$/, /\.DS_Store$/];
|
|
371
|
+
if (excludePatterns.some((pattern) => pattern.test(data.name))) {
|
|
372
|
+
return false;
|
|
212
373
|
}
|
|
213
|
-
|
|
374
|
+
return data;
|
|
375
|
+
});
|
|
214
376
|
archive.finalize();
|
|
215
377
|
});
|
|
216
378
|
const size = fs_1.default.statSync(outputPath).size;
|
|
379
|
+
const fileSizeMB = (size / 1024 / 1024).toFixed(2);
|
|
380
|
+
yield log(`代码打包完成,文件大小: ${fileSizeMB} MB`, "success");
|
|
217
381
|
const uploadService = container_1.container.get(container_1.SERVICE_IDENTIFIERS.UploadService);
|
|
218
382
|
if (upload && uploadService) {
|
|
219
383
|
try {
|
|
384
|
+
yield log("读取项目配置...", "info");
|
|
220
385
|
const projectConfigPath = path_1.default.join(workDir, "project.config.json");
|
|
221
386
|
if (!fs_1.default.existsSync(projectConfigPath)) {
|
|
387
|
+
yield log("找不到项目配置文件: project.config.json", "error");
|
|
222
388
|
throw new Error("找不到项目配置文件: project.config.json");
|
|
223
389
|
}
|
|
224
390
|
const projectInfo = JSON.parse(fs_1.default.readFileSync(projectConfigPath, "utf-8"));
|
|
225
391
|
if (!projectInfo.agentId) {
|
|
392
|
+
yield log("项目配置文件缺少必要字段 (agentId)", "error");
|
|
226
393
|
throw new Error("项目配置文件缺少必要字段 (agentId)");
|
|
227
394
|
}
|
|
395
|
+
yield log(`Agent ID: ${projectInfo.agentId}`, "info");
|
|
228
396
|
let version, desc;
|
|
229
|
-
if (
|
|
397
|
+
if (uploadInfo) {
|
|
398
|
+
version = uploadInfo.version;
|
|
399
|
+
desc = uploadInfo.desc;
|
|
400
|
+
}
|
|
401
|
+
else {
|
|
230
402
|
if (!projectInfo.version || !projectInfo.desc) {
|
|
231
403
|
throw new Error("项目配置文件缺少必要字段 (agentId, version, desc)");
|
|
232
404
|
}
|
|
@@ -236,10 +408,9 @@ function build(options) {
|
|
|
236
408
|
version = projectInfo.version;
|
|
237
409
|
desc = projectInfo.desc;
|
|
238
410
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
}
|
|
411
|
+
yield log(`版本号: ${version}`, "info");
|
|
412
|
+
yield log(`发布描述: ${desc}`, "info");
|
|
413
|
+
yield log("开始上传代码包...", "info", true);
|
|
243
414
|
const result = yield uploadService.deploy({
|
|
244
415
|
targetPath: outputPath,
|
|
245
416
|
agentId: projectInfo.agentId,
|
|
@@ -247,10 +418,15 @@ function build(options) {
|
|
|
247
418
|
desc,
|
|
248
419
|
});
|
|
249
420
|
if (!result.success || result.code !== 0) {
|
|
250
|
-
|
|
421
|
+
const errorMsg = result.message || "部署失败";
|
|
422
|
+
yield log(`部署失败: ${errorMsg}`, "error");
|
|
423
|
+
throw new Error(errorMsg);
|
|
251
424
|
}
|
|
425
|
+
yield log("代码包上传成功", "success");
|
|
426
|
+
yield log("Agent 发布完成!", "success");
|
|
252
427
|
}
|
|
253
428
|
catch (error) {
|
|
429
|
+
yield log(`部署失败: ${error.message}`, "error");
|
|
254
430
|
throw new Error(`部署失败: ${error.message}`);
|
|
255
431
|
}
|
|
256
432
|
}
|
|
@@ -305,3 +481,45 @@ function cleanup() {
|
|
|
305
481
|
rcbProcess = null;
|
|
306
482
|
}
|
|
307
483
|
}
|
|
484
|
+
function getAgentInfo() {
|
|
485
|
+
return __awaiter(this, arguments, void 0, function* (workDir = process.cwd()) {
|
|
486
|
+
var _a;
|
|
487
|
+
const projectConfigPath = path_1.default.join(workDir, "project.config.json");
|
|
488
|
+
if (!fs_1.default.existsSync(projectConfigPath)) {
|
|
489
|
+
throw new Error("找不到项目配置文件: project.config.json");
|
|
490
|
+
}
|
|
491
|
+
const projectInfo = JSON.parse(fs_1.default.readFileSync(projectConfigPath, "utf-8"));
|
|
492
|
+
if (!projectInfo.agentId) {
|
|
493
|
+
throw new Error("项目配置文件缺少必要字段 (agentId)");
|
|
494
|
+
}
|
|
495
|
+
const agentInfoUrl = `${(0, endpoints_1.getAgentbaseBaseUrl)()}/agent/info`;
|
|
496
|
+
const response = yield request_1.request.fetch({
|
|
497
|
+
method: "GET",
|
|
498
|
+
url: agentInfoUrl,
|
|
499
|
+
headers: {
|
|
500
|
+
"agent-id": projectInfo.agentId,
|
|
501
|
+
},
|
|
502
|
+
});
|
|
503
|
+
const data = request_1.request.handleHttpStatus(response);
|
|
504
|
+
const result = request_1.request.handleCode(data);
|
|
505
|
+
const agentInfo = (_a = result.data) === null || _a === void 0 ? void 0 : _a.agent_info;
|
|
506
|
+
if (!agentInfo) {
|
|
507
|
+
throw new Error("agentbase 返回数据异常:缺少 agent_info 字段");
|
|
508
|
+
}
|
|
509
|
+
return {
|
|
510
|
+
agentId: agentInfo.agent_id || "",
|
|
511
|
+
agentName: agentInfo.agent_name || "",
|
|
512
|
+
agentIcon: agentInfo.agent_icon || "",
|
|
513
|
+
};
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
function getAgentList(params) {
|
|
517
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
518
|
+
return container_1.ServiceProvider.getAgentService().getAgentList(params);
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
function getAgentInfoById(agentId) {
|
|
522
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
523
|
+
return container_1.ServiceProvider.getAgentService().getAgentInfoById(agentId);
|
|
524
|
+
});
|
|
525
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getLangfuseConfig = getLangfuseConfig;
|
|
13
|
+
exports.getCloudDevLLMBaseURL = getCloudDevLLMBaseURL;
|
|
14
|
+
exports.getCloudDevAnthropicLLMBaseURL = getCloudDevAnthropicLLMBaseURL;
|
|
15
|
+
exports.getUserInfo = getUserInfo;
|
|
16
|
+
const container_1 = require("./container");
|
|
17
|
+
function getLangfuseConfig(params) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const cloudDevService = container_1.ServiceProvider.getCloudDevService();
|
|
20
|
+
return cloudDevService.getLangfuseConfig(params);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function getCloudDevLLMBaseURL(params) {
|
|
24
|
+
const cloudDevService = container_1.ServiceProvider.getCloudDevService();
|
|
25
|
+
return cloudDevService.getCloudDevLLMBaseURL(params);
|
|
26
|
+
}
|
|
27
|
+
function getCloudDevAnthropicLLMBaseURL(params) {
|
|
28
|
+
const cloudDevService = container_1.ServiceProvider.getCloudDevService();
|
|
29
|
+
return cloudDevService.getCloudDevAnthropicLLMBaseURL(params);
|
|
30
|
+
}
|
|
31
|
+
function getUserInfo(params) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const cloudDevService = container_1.ServiceProvider.getCloudDevService();
|
|
34
|
+
return cloudDevService.getUserInfo(params);
|
|
35
|
+
});
|
|
36
|
+
}
|
package/lib/config/api.config.js
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getBaseUrl = getBaseUrl;
|
|
4
|
-
const
|
|
5
|
-
sit: "http://miniapp-tailiang.sl.sit.xiaohongshu.com",
|
|
6
|
-
development: "https://miniapp.beta.xiaohongshu.com",
|
|
7
|
-
production: "https://miniapp.xiaohongshu.com",
|
|
8
|
-
};
|
|
9
|
-
const env = process.env.AGENT_BUILD_ENV || "production";
|
|
10
|
-
const baseUrl = apiUrls[env] || apiUrls.development;
|
|
4
|
+
const endpoints_1 = require("@vectorx/endpoints");
|
|
11
5
|
function getBaseUrl() {
|
|
12
|
-
return baseUrl;
|
|
6
|
+
return (0, endpoints_1.resolveUrl)("@vectorx/cloud-toolkit", "baseUrl");
|
|
13
7
|
}
|
|
@@ -2,10 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.container = void 0;
|
|
4
4
|
const inversify_1 = require("inversify");
|
|
5
|
+
const agent_service_1 = require("../services/agent-service");
|
|
5
6
|
const auth_service_1 = require("../services/auth-service");
|
|
7
|
+
const cloud_dev_service_1 = require("../services/cloud-dev-service");
|
|
8
|
+
const cloud_env_service_1 = require("../services/cloud-env-service");
|
|
9
|
+
const database_service_1 = require("../services/database-service");
|
|
10
|
+
const fun_service_1 = require("../services/fun-service");
|
|
6
11
|
const upload_service_1 = require("../services/upload-service");
|
|
7
12
|
const identifiers_1 = require("./identifiers");
|
|
8
13
|
const container = new inversify_1.Container();
|
|
9
14
|
exports.container = container;
|
|
10
15
|
container.bind(identifiers_1.SERVICE_IDENTIFIERS.AuthService).to(auth_service_1.AuthService).inSingletonScope();
|
|
11
16
|
container.bind(identifiers_1.SERVICE_IDENTIFIERS.UploadService).to(upload_service_1.UploadService).inSingletonScope();
|
|
17
|
+
container.bind(identifiers_1.SERVICE_IDENTIFIERS.CloudEnvService).to(cloud_env_service_1.CloudEnvService).inSingletonScope();
|
|
18
|
+
container.bind(identifiers_1.SERVICE_IDENTIFIERS.CloudDevService).to(cloud_dev_service_1.CloudDevService).inSingletonScope();
|
|
19
|
+
container.bind(identifiers_1.SERVICE_IDENTIFIERS.FunService).to(fun_service_1.FunService).inSingletonScope();
|
|
20
|
+
container.bind(identifiers_1.SERVICE_IDENTIFIERS.DatabaseService).to(database_service_1.DatabaseService).inSingletonScope();
|
|
21
|
+
container.bind(identifiers_1.SERVICE_IDENTIFIERS.AgentService).to(agent_service_1.AgentService).inSingletonScope();
|
|
@@ -4,4 +4,9 @@ exports.SERVICE_IDENTIFIERS = void 0;
|
|
|
4
4
|
exports.SERVICE_IDENTIFIERS = {
|
|
5
5
|
AuthService: Symbol.for("AuthService"),
|
|
6
6
|
UploadService: Symbol.for("UploadService"),
|
|
7
|
+
CloudEnvService: Symbol.for("CloudEnvService"),
|
|
8
|
+
CloudDevService: Symbol.for("CloudDevService"),
|
|
9
|
+
FunService: Symbol.for("FunService"),
|
|
10
|
+
DatabaseService: Symbol.for("DatabaseService"),
|
|
11
|
+
AgentService: Symbol.for("AgentService"),
|
|
7
12
|
};
|
package/lib/container/index.js
CHANGED
|
@@ -26,6 +26,21 @@ class ServiceProvider {
|
|
|
26
26
|
static getUploadService() {
|
|
27
27
|
return container_1.container.get(identifiers_1.SERVICE_IDENTIFIERS.UploadService);
|
|
28
28
|
}
|
|
29
|
+
static getCloudEnvService() {
|
|
30
|
+
return container_1.container.get(identifiers_1.SERVICE_IDENTIFIERS.CloudEnvService);
|
|
31
|
+
}
|
|
32
|
+
static getCloudDevService() {
|
|
33
|
+
return container_1.container.get(identifiers_1.SERVICE_IDENTIFIERS.CloudDevService);
|
|
34
|
+
}
|
|
35
|
+
static getFunService() {
|
|
36
|
+
return container_1.container.get(identifiers_1.SERVICE_IDENTIFIERS.FunService);
|
|
37
|
+
}
|
|
38
|
+
static getDatabaseService() {
|
|
39
|
+
return container_1.container.get(identifiers_1.SERVICE_IDENTIFIERS.DatabaseService);
|
|
40
|
+
}
|
|
41
|
+
static getAgentService() {
|
|
42
|
+
return container_1.container.get(identifiers_1.SERVICE_IDENTIFIERS.AgentService);
|
|
43
|
+
}
|
|
29
44
|
}
|
|
30
45
|
exports.ServiceProvider = ServiceProvider;
|
|
31
46
|
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getDatabaseClient = getDatabaseClient;
|
|
13
|
+
exports.listDatabaseTables = listDatabaseTables;
|
|
14
|
+
exports.getDatabaseTableColumns = getDatabaseTableColumns;
|
|
15
|
+
exports.previewDatabaseTable = previewDatabaseTable;
|
|
16
|
+
exports.executeDatabaseSql = executeDatabaseSql;
|
|
17
|
+
const container_1 = require("./container");
|
|
18
|
+
function getDatabaseClient(ctx) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
const dbService = container_1.ServiceProvider.getDatabaseService();
|
|
21
|
+
return dbService.getOrCreateClient(ctx !== null && ctx !== void 0 ? ctx : {});
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function listDatabaseTables(ctx, params) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const dbService = container_1.ServiceProvider.getDatabaseService();
|
|
27
|
+
return dbService.listTables(ctx !== null && ctx !== void 0 ? ctx : {}, params);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function getDatabaseTableColumns(ctx, params) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
if (!(params === null || params === void 0 ? void 0 : params.table)) {
|
|
33
|
+
throw new Error("table 为必填字段");
|
|
34
|
+
}
|
|
35
|
+
const dbService = container_1.ServiceProvider.getDatabaseService();
|
|
36
|
+
return dbService.getTableColumns(ctx !== null && ctx !== void 0 ? ctx : {}, params);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function previewDatabaseTable(ctx, params) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
if (!(params === null || params === void 0 ? void 0 : params.table)) {
|
|
42
|
+
throw new Error("table 为必填字段");
|
|
43
|
+
}
|
|
44
|
+
const dbService = container_1.ServiceProvider.getDatabaseService();
|
|
45
|
+
return dbService.previewTable(ctx !== null && ctx !== void 0 ? ctx : {}, params);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function executeDatabaseSql(ctx, q) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
if (!(q === null || q === void 0 ? void 0 : q.sql)) {
|
|
51
|
+
throw new Error("sql 为必填字段");
|
|
52
|
+
}
|
|
53
|
+
const dbService = container_1.ServiceProvider.getDatabaseService();
|
|
54
|
+
return dbService.executeSql(ctx !== null && ctx !== void 0 ? ctx : {}, q);
|
|
55
|
+
});
|
|
56
|
+
}
|