@vectorx/cloud-toolkit 1.0.1 → 2.0.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/agent.kit.js +202 -13
- package/lib/cloud-dev.kit.js +36 -0
- package/lib/container/container.js +6 -0
- package/lib/container/identifiers.js +3 -0
- package/lib/container/index.js +9 -0
- package/lib/database.kit.js +56 -0
- package/lib/index.js +2 -0
- package/lib/services/agent-service.js +132 -0
- package/lib/services/cloud-dev-service.js +97 -0
- package/lib/services/database-service.js +142 -0
- package/lib/services/fun-service.js +2 -2
- package/lib/services/index.js +3 -0
- package/lib/utils/cos-uploader.js +3 -1
- package/lib/utils/open-browser.js +7 -1
- package/lib/utils/openChrome.applescript +2 -2
- package/lib/utils/project-validator.js +3 -1
- package/lib/utils/request.js +2 -1
- package/lib/utils/tracker/ai-apm.js +62 -0
- package/lib/utils/tracker/apm.js +3 -1
- package/lib/utils/tracker/cli-apm.js +7 -2
- package/lib/utils/tracker/device.js +3 -1
- package/lib/utils/tracker/index.js +1 -0
- package/package.json +6 -6
- package/types/agent.kit.d.ts +25 -1
- package/types/cloud-dev.kit.d.ts +18 -0
- package/types/container/identifiers.d.ts +4 -1
- package/types/container/index.d.ts +4 -1
- package/types/container/types.d.ts +88 -0
- package/types/database.kit.d.ts +54 -0
- package/types/index.d.ts +2 -0
- package/types/services/agent-service.d.ts +11 -0
- package/types/services/cloud-dev-service.d.ts +23 -0
- package/types/services/database-service.d.ts +33 -0
- package/types/services/index.d.ts +3 -0
- package/types/utils/tracker/ai-apm.d.ts +54 -0
- package/types/utils/tracker/index.d.ts +1 -0
package/lib/agent.kit.js
CHANGED
|
@@ -17,15 +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"));
|
|
26
|
+
const endpoints_1 = require("@vectorx/endpoints");
|
|
23
27
|
const archiver_1 = __importDefault(require("archiver"));
|
|
24
28
|
const semver_1 = __importDefault(require("semver"));
|
|
25
29
|
const container_1 = require("./container");
|
|
26
30
|
const env_helper_1 = require("./utils/env-helper");
|
|
27
31
|
const port_finder_1 = require("./utils/port-finder");
|
|
28
32
|
const project_validator_1 = require("./utils/project-validator");
|
|
33
|
+
const request_1 = require("./utils/request");
|
|
29
34
|
let rcbProcess = null;
|
|
30
35
|
function validatePort(port, name = "端口") {
|
|
31
36
|
if (isNaN(port) || port < 1 || port > 65535) {
|
|
@@ -52,7 +57,9 @@ function startRcbFramework(workDir_1, port_1, watch_1) {
|
|
|
52
57
|
try {
|
|
53
58
|
let packagePath;
|
|
54
59
|
try {
|
|
55
|
-
packagePath = require.resolve("@vectorx/functions-framework/package.json", {
|
|
60
|
+
packagePath = require.resolve("@vectorx/functions-framework/package.json", {
|
|
61
|
+
paths: [workDir],
|
|
62
|
+
});
|
|
56
63
|
}
|
|
57
64
|
catch (err) {
|
|
58
65
|
const msg = (err === null || err === void 0 ? void 0 : err.message) || String(err);
|
|
@@ -134,11 +141,21 @@ function startRcbFramework(workDir_1, port_1, watch_1) {
|
|
|
134
141
|
}
|
|
135
142
|
function startDev(options) {
|
|
136
143
|
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
-
var _a;
|
|
138
|
-
const { workDir = process.cwd(), port: specifiedPort, simulatorPort: specifiedSimulatorPort, watch = false, enableRedLangfuse = false, mode = "agent", } = options;
|
|
144
|
+
var _a, _b;
|
|
145
|
+
const { workDir = process.cwd(), port: specifiedPort, simulatorPort: specifiedSimulatorPort, idePort: specifiedIdePort, watch = false, enableRedLangfuse = false, mode = "agent", useIde = false, } = options;
|
|
139
146
|
if (!fs_1.default.existsSync(workDir)) {
|
|
140
147
|
throw new Error(`目录不存在: ${workDir}`);
|
|
141
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
|
+
}
|
|
142
159
|
let port;
|
|
143
160
|
if (specifiedPort) {
|
|
144
161
|
validatePort(specifiedPort, "Agent Server 端口");
|
|
@@ -166,7 +183,19 @@ function startDev(options) {
|
|
|
166
183
|
else {
|
|
167
184
|
simulatorPort = yield (0, port_finder_1.findAvailablePort)(port + 1);
|
|
168
185
|
}
|
|
169
|
-
|
|
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
|
+
});
|
|
170
199
|
let AgentSimulator = (_a = options === null || options === void 0 ? void 0 : options.deps) === null || _a === void 0 ? void 0 : _a.AgentSimulator;
|
|
171
200
|
if (!AgentSimulator) {
|
|
172
201
|
try {
|
|
@@ -189,38 +218,142 @@ function startDev(options) {
|
|
|
189
218
|
].join("\n"));
|
|
190
219
|
}
|
|
191
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`;
|
|
192
233
|
const simulator = new AgentSimulator({
|
|
193
234
|
port: simulatorPort,
|
|
194
|
-
agentServerUrl
|
|
235
|
+
agentServerUrl,
|
|
195
236
|
open: false,
|
|
237
|
+
quiet: useIde,
|
|
238
|
+
agentId,
|
|
196
239
|
});
|
|
197
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
|
+
}
|
|
198
299
|
return {
|
|
199
300
|
port,
|
|
200
301
|
simulatorPort,
|
|
201
302
|
simulator,
|
|
303
|
+
ideUrl: undefined,
|
|
202
304
|
rcbProcess,
|
|
203
305
|
};
|
|
204
306
|
});
|
|
205
307
|
}
|
|
206
308
|
function build(options) {
|
|
207
309
|
return __awaiter(this, void 0, void 0, function* () {
|
|
208
|
-
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");
|
|
209
332
|
if (!fs_1.default.existsSync(workDir)) {
|
|
333
|
+
yield log(`目录不存在: ${workDir}`, "error");
|
|
210
334
|
throw new Error(`目录不存在: ${workDir}`);
|
|
211
335
|
}
|
|
336
|
+
yield log(`工作目录: ${workDir}`, "info");
|
|
337
|
+
yield log("开始校验项目结构与依赖...", "info", true);
|
|
212
338
|
const validator = new project_validator_1.ProjectValidator(workDir, uploadInfo);
|
|
213
339
|
if (validator) {
|
|
214
340
|
const validationResult = yield validator.validate();
|
|
215
341
|
if (!validationResult.valid) {
|
|
342
|
+
for (const err of validationResult.errors) {
|
|
343
|
+
yield log(`校验失败: ${err}`, "error");
|
|
344
|
+
}
|
|
216
345
|
throw new Error(`项目验证失败:\n${validationResult.errors.join("\n")}`);
|
|
217
346
|
}
|
|
218
347
|
}
|
|
348
|
+
yield log("项目校验通过", "success");
|
|
219
349
|
if (!fs_1.default.existsSync(outputDir)) {
|
|
220
350
|
fs_1.default.mkdirSync(outputDir, { recursive: true });
|
|
351
|
+
yield log(`创建输出目录: ${outputDir}`, "info");
|
|
221
352
|
}
|
|
222
353
|
const zipFilename = filename.endsWith(".zip") ? filename : `${filename}.zip`;
|
|
223
354
|
const outputPath = path_1.default.join(outputDir, zipFilename);
|
|
355
|
+
yield log("开始打包代码...", "info", true);
|
|
356
|
+
yield log(`打包文件: ${zipFilename}`, "info");
|
|
224
357
|
yield new Promise((resolve, reject) => {
|
|
225
358
|
const output = fs_1.default.createWriteStream(outputPath);
|
|
226
359
|
const archive = (0, archiver_1.default)("zip", {
|
|
@@ -234,7 +367,7 @@ function build(options) {
|
|
|
234
367
|
});
|
|
235
368
|
archive.pipe(output);
|
|
236
369
|
archive.directory(workDir, false, (data) => {
|
|
237
|
-
const excludePatterns = [/^\.git/, /^dist/, /\.zip$/, /\.DS_Store$/];
|
|
370
|
+
const excludePatterns = [/^\.git/, /^\.agentConfig/, /^dist/, /\.zip$/, /\.DS_Store$/];
|
|
238
371
|
if (excludePatterns.some((pattern) => pattern.test(data.name))) {
|
|
239
372
|
return false;
|
|
240
373
|
}
|
|
@@ -243,19 +376,29 @@ function build(options) {
|
|
|
243
376
|
archive.finalize();
|
|
244
377
|
});
|
|
245
378
|
const size = fs_1.default.statSync(outputPath).size;
|
|
379
|
+
const fileSizeMB = (size / 1024 / 1024).toFixed(2);
|
|
380
|
+
yield log(`代码打包完成,文件大小: ${fileSizeMB} MB`, "success");
|
|
246
381
|
const uploadService = container_1.container.get(container_1.SERVICE_IDENTIFIERS.UploadService);
|
|
247
382
|
if (upload && uploadService) {
|
|
248
383
|
try {
|
|
384
|
+
yield log("读取项目配置...", "info");
|
|
249
385
|
const projectConfigPath = path_1.default.join(workDir, "project.config.json");
|
|
250
386
|
if (!fs_1.default.existsSync(projectConfigPath)) {
|
|
387
|
+
yield log("找不到项目配置文件: project.config.json", "error");
|
|
251
388
|
throw new Error("找不到项目配置文件: project.config.json");
|
|
252
389
|
}
|
|
253
390
|
const projectInfo = JSON.parse(fs_1.default.readFileSync(projectConfigPath, "utf-8"));
|
|
254
391
|
if (!projectInfo.agentId) {
|
|
392
|
+
yield log("项目配置文件缺少必要字段 (agentId)", "error");
|
|
255
393
|
throw new Error("项目配置文件缺少必要字段 (agentId)");
|
|
256
394
|
}
|
|
395
|
+
yield log(`Agent ID: ${projectInfo.agentId}`, "info");
|
|
257
396
|
let version, desc;
|
|
258
|
-
if (
|
|
397
|
+
if (uploadInfo) {
|
|
398
|
+
version = uploadInfo.version;
|
|
399
|
+
desc = uploadInfo.desc;
|
|
400
|
+
}
|
|
401
|
+
else {
|
|
259
402
|
if (!projectInfo.version || !projectInfo.desc) {
|
|
260
403
|
throw new Error("项目配置文件缺少必要字段 (agentId, version, desc)");
|
|
261
404
|
}
|
|
@@ -265,10 +408,9 @@ function build(options) {
|
|
|
265
408
|
version = projectInfo.version;
|
|
266
409
|
desc = projectInfo.desc;
|
|
267
410
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
}
|
|
411
|
+
yield log(`版本号: ${version}`, "info");
|
|
412
|
+
yield log(`发布描述: ${desc}`, "info");
|
|
413
|
+
yield log("开始上传代码包...", "info", true);
|
|
272
414
|
const result = yield uploadService.deploy({
|
|
273
415
|
targetPath: outputPath,
|
|
274
416
|
agentId: projectInfo.agentId,
|
|
@@ -276,10 +418,15 @@ function build(options) {
|
|
|
276
418
|
desc,
|
|
277
419
|
});
|
|
278
420
|
if (!result.success || result.code !== 0) {
|
|
279
|
-
|
|
421
|
+
const errorMsg = result.message || "部署失败";
|
|
422
|
+
yield log(`部署失败: ${errorMsg}`, "error");
|
|
423
|
+
throw new Error(errorMsg);
|
|
280
424
|
}
|
|
425
|
+
yield log("代码包上传成功", "success");
|
|
426
|
+
yield log("Agent 发布完成!", "success");
|
|
281
427
|
}
|
|
282
428
|
catch (error) {
|
|
429
|
+
yield log(`部署失败: ${error.message}`, "error");
|
|
283
430
|
throw new Error(`部署失败: ${error.message}`);
|
|
284
431
|
}
|
|
285
432
|
}
|
|
@@ -334,3 +481,45 @@ function cleanup() {
|
|
|
334
481
|
rcbProcess = null;
|
|
335
482
|
}
|
|
336
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
|
+
}
|
|
@@ -2,8 +2,11 @@
|
|
|
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");
|
|
6
8
|
const cloud_env_service_1 = require("../services/cloud-env-service");
|
|
9
|
+
const database_service_1 = require("../services/database-service");
|
|
7
10
|
const fun_service_1 = require("../services/fun-service");
|
|
8
11
|
const upload_service_1 = require("../services/upload-service");
|
|
9
12
|
const identifiers_1 = require("./identifiers");
|
|
@@ -12,4 +15,7 @@ exports.container = container;
|
|
|
12
15
|
container.bind(identifiers_1.SERVICE_IDENTIFIERS.AuthService).to(auth_service_1.AuthService).inSingletonScope();
|
|
13
16
|
container.bind(identifiers_1.SERVICE_IDENTIFIERS.UploadService).to(upload_service_1.UploadService).inSingletonScope();
|
|
14
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();
|
|
15
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();
|
|
@@ -5,5 +5,8 @@ exports.SERVICE_IDENTIFIERS = {
|
|
|
5
5
|
AuthService: Symbol.for("AuthService"),
|
|
6
6
|
UploadService: Symbol.for("UploadService"),
|
|
7
7
|
CloudEnvService: Symbol.for("CloudEnvService"),
|
|
8
|
+
CloudDevService: Symbol.for("CloudDevService"),
|
|
8
9
|
FunService: Symbol.for("FunService"),
|
|
10
|
+
DatabaseService: Symbol.for("DatabaseService"),
|
|
11
|
+
AgentService: Symbol.for("AgentService"),
|
|
9
12
|
};
|
package/lib/container/index.js
CHANGED
|
@@ -29,9 +29,18 @@ class ServiceProvider {
|
|
|
29
29
|
static getCloudEnvService() {
|
|
30
30
|
return container_1.container.get(identifiers_1.SERVICE_IDENTIFIERS.CloudEnvService);
|
|
31
31
|
}
|
|
32
|
+
static getCloudDevService() {
|
|
33
|
+
return container_1.container.get(identifiers_1.SERVICE_IDENTIFIERS.CloudDevService);
|
|
34
|
+
}
|
|
32
35
|
static getFunService() {
|
|
33
36
|
return container_1.container.get(identifiers_1.SERVICE_IDENTIFIERS.FunService);
|
|
34
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
|
+
}
|
|
35
44
|
}
|
|
36
45
|
exports.ServiceProvider = ServiceProvider;
|
|
37
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
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -18,6 +18,8 @@ exports.Uploader = void 0;
|
|
|
18
18
|
__exportStar(require("./agent.kit"), exports);
|
|
19
19
|
__exportStar(require("./fun.kit"), exports);
|
|
20
20
|
__exportStar(require("./env.kit"), exports);
|
|
21
|
+
__exportStar(require("./database.kit"), exports);
|
|
22
|
+
__exportStar(require("./cloud-dev.kit"), exports);
|
|
21
23
|
var cos_uploader_1 = require("./utils/cos-uploader");
|
|
22
24
|
Object.defineProperty(exports, "Uploader", { enumerable: true, get: function () { return cos_uploader_1.Uploader; } });
|
|
23
25
|
__exportStar(require("./container"), exports);
|
|
@@ -0,0 +1,132 @@
|
|
|
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.AgentService = void 0;
|
|
22
|
+
const inversify_1 = require("inversify");
|
|
23
|
+
const config_1 = require("../config");
|
|
24
|
+
const container_1 = require("../container");
|
|
25
|
+
const env_helper_1 = require("../utils/env-helper");
|
|
26
|
+
const logger_1 = require("../utils/logger");
|
|
27
|
+
const request_1 = require("../utils/request");
|
|
28
|
+
let AgentService = class AgentService {
|
|
29
|
+
constructor() {
|
|
30
|
+
this.authService = container_1.container.get(container_1.SERVICE_IDENTIFIERS.AuthService);
|
|
31
|
+
}
|
|
32
|
+
resolveAuthQuery(params) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
if ((params === null || params === void 0 ? void 0 : params.secret_id) && (params === null || params === void 0 ? void 0 : params.cli_token)) {
|
|
35
|
+
return { secret_id: params.secret_id, cli_token: params.cli_token };
|
|
36
|
+
}
|
|
37
|
+
if (!env_helper_1.isIDE) {
|
|
38
|
+
const loginInfo = yield this.authService.getLoginInfo();
|
|
39
|
+
if (!loginInfo) {
|
|
40
|
+
throw new Error("未登录,请先执行登录命令");
|
|
41
|
+
}
|
|
42
|
+
return { secret_id: loginInfo.secret_id, cli_token: loginInfo.cli_token };
|
|
43
|
+
}
|
|
44
|
+
return {};
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
getAgentList(params) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
var _a, _b, _c, _d, _e;
|
|
50
|
+
try {
|
|
51
|
+
const pageNum = (_a = params === null || params === void 0 ? void 0 : params.pageNo) !== null && _a !== void 0 ? _a : 1;
|
|
52
|
+
const pageSize = (_b = params === null || params === void 0 ? void 0 : params.pageSize) !== null && _b !== void 0 ? _b : 10;
|
|
53
|
+
const query = yield this.resolveAuthQuery();
|
|
54
|
+
const httpResponse = yield request_1.request.fetch({
|
|
55
|
+
method: "POST",
|
|
56
|
+
url: `${(0, config_1.getBaseUrl)()}/api/eros/mp/red/code/agent/list`,
|
|
57
|
+
headers: {
|
|
58
|
+
"Content-Type": "application/json",
|
|
59
|
+
},
|
|
60
|
+
data: {
|
|
61
|
+
query,
|
|
62
|
+
body: {
|
|
63
|
+
pageNum,
|
|
64
|
+
pageSize,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
const data = request_1.request.handleHttpStatus(httpResponse);
|
|
69
|
+
if (data.code !== 0) {
|
|
70
|
+
throw new Error(data.msg || "获取 Agent 列表失败");
|
|
71
|
+
}
|
|
72
|
+
const list = (_d = (_c = data === null || data === void 0 ? void 0 : data.data) === null || _c === void 0 ? void 0 : _c.agentList) !== null && _d !== void 0 ? _d : [];
|
|
73
|
+
return Array.isArray(list) ? list : [];
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
const msg = (_e = error === null || error === void 0 ? void 0 : error.message) !== null && _e !== void 0 ? _e : String(error);
|
|
77
|
+
logger_1.logger.error(`Agent 列表接口调用失败: ${msg}`);
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
getAgentInfoById(agentId) {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
var _a, _b, _c, _d;
|
|
85
|
+
if (!(agentId === null || agentId === void 0 ? void 0 : agentId.trim())) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
const query = yield this.resolveAuthQuery();
|
|
90
|
+
const httpResponse = yield request_1.request.fetch({
|
|
91
|
+
method: "POST",
|
|
92
|
+
url: `${(0, config_1.getBaseUrl)()}/api/eros/mp/red/code/agent/info`,
|
|
93
|
+
headers: {
|
|
94
|
+
"Content-Type": "application/json",
|
|
95
|
+
},
|
|
96
|
+
data: {
|
|
97
|
+
query,
|
|
98
|
+
body: {
|
|
99
|
+
agentId: agentId.trim(),
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
const data = request_1.request.handleHttpStatus(httpResponse);
|
|
104
|
+
if (data.code !== 0) {
|
|
105
|
+
throw new Error(data.msg || "获取 Agent 详情失败");
|
|
106
|
+
}
|
|
107
|
+
const dto = (_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.agentDto;
|
|
108
|
+
if (!dto) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
agentId: (_b = dto.agentId) !== null && _b !== void 0 ? _b : "",
|
|
113
|
+
agentName: (_c = dto.agentName) !== null && _c !== void 0 ? _c : "",
|
|
114
|
+
agentAvatar: dto.agentAvatar,
|
|
115
|
+
description: dto.agentDesc,
|
|
116
|
+
status: dto.status != null ? String(dto.status) : undefined,
|
|
117
|
+
updateTime: dto.gmtUpdate != null ? new Date(dto.gmtUpdate).toLocaleString() : undefined,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
const msg = (_d = error === null || error === void 0 ? void 0 : error.message) !== null && _d !== void 0 ? _d : String(error);
|
|
122
|
+
logger_1.logger.error(`Agent 详情接口调用失败: ${msg}`);
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
exports.AgentService = AgentService;
|
|
129
|
+
exports.AgentService = AgentService = __decorate([
|
|
130
|
+
(0, inversify_1.injectable)(),
|
|
131
|
+
__metadata("design:paramtypes", [])
|
|
132
|
+
], AgentService);
|