@vectorx/cloud-toolkit 0.0.0-beta-20251112071234

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 (55) hide show
  1. package/README.md +1 -0
  2. package/lib/agent.kit.js +275 -0
  3. package/lib/config/api.config.js +12 -0
  4. package/lib/config/index.js +17 -0
  5. package/lib/container/container.js +11 -0
  6. package/lib/container/identifiers.js +7 -0
  7. package/lib/container/index.js +31 -0
  8. package/lib/container/types.js +2 -0
  9. package/lib/index.js +30 -0
  10. package/lib/services/auth-service.js +148 -0
  11. package/lib/services/index.js +18 -0
  12. package/lib/services/upload-service.js +192 -0
  13. package/lib/utils/config-merger.js +54 -0
  14. package/lib/utils/cos-uploader.js +104 -0
  15. package/lib/utils/env-helper.js +4 -0
  16. package/lib/utils/helper.js +66 -0
  17. package/lib/utils/loading.js +68 -0
  18. package/lib/utils/logger.js +89 -0
  19. package/lib/utils/open-browser.js +24 -0
  20. package/lib/utils/openChrome.applescript +78 -0
  21. package/lib/utils/output.js +37 -0
  22. package/lib/utils/port-finder.js +55 -0
  23. package/lib/utils/project-validator.js +124 -0
  24. package/lib/utils/request.js +77 -0
  25. package/lib/utils/to-hump.js +5 -0
  26. package/lib/utils/tracker/device.js +85 -0
  27. package/lib/utils/tracker/index.js +134 -0
  28. package/lib/utils/tracker/tracker.js +2 -0
  29. package/package.json +55 -0
  30. package/types/agent.kit.d.ts +70 -0
  31. package/types/config/api.config.d.ts +2 -0
  32. package/types/config/index.d.ts +1 -0
  33. package/types/container/container.d.ts +3 -0
  34. package/types/container/identifiers.d.ts +6 -0
  35. package/types/container/index.d.ts +9 -0
  36. package/types/container/types.d.ts +19 -0
  37. package/types/index.d.ts +13 -0
  38. package/types/services/auth-service.d.ts +22 -0
  39. package/types/services/index.d.ts +2 -0
  40. package/types/services/upload-service.d.ts +95 -0
  41. package/types/utils/config-merger.d.ts +1 -0
  42. package/types/utils/cos-uploader.d.ts +41 -0
  43. package/types/utils/env-helper.d.ts +1 -0
  44. package/types/utils/helper.d.ts +6 -0
  45. package/types/utils/loading.d.ts +18 -0
  46. package/types/utils/logger.d.ts +24 -0
  47. package/types/utils/open-browser.d.ts +2 -0
  48. package/types/utils/output.d.ts +1 -0
  49. package/types/utils/port-finder.d.ts +2 -0
  50. package/types/utils/project-validator.d.ts +10 -0
  51. package/types/utils/request.d.ts +25 -0
  52. package/types/utils/to-hump.d.ts +1 -0
  53. package/types/utils/tracker/device.d.ts +4 -0
  54. package/types/utils/tracker/index.d.ts +27 -0
  55. package/types/utils/tracker/tracker.d.ts +22 -0
@@ -0,0 +1,37 @@
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.outputHelpInfo = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const outputHelpInfo = () => {
9
+ const commands = `
10
+ 命令
11
+ login [options] 登录小红书云账号
12
+ agent [cmd] 开发 AI Agent`;
13
+ const options = `
14
+ 选项
15
+ -v, --version 输出当前版本
16
+ -h, --help 查看命令帮助信息`;
17
+ const tips = `
18
+ Tips:
19
+
20
+ ${chalk_1.default.gray("–")} 登录管理
21
+ ${chalk_1.default.cyan("$ rcb login/logout")}
22
+
23
+ ${chalk_1.default.gray("–")} 创建 AI 智能体模版项目
24
+ ${chalk_1.default.cyan("$ rcb agent new <appName>")}
25
+
26
+ ${chalk_1.default.gray("–")} 启动 AI Agent 开发服务器
27
+ ${chalk_1.default.cyan("$ rcb agent dev")}
28
+
29
+ ${chalk_1.default.gray("–")} 打包 AI Agent 到云函数代码
30
+ ${chalk_1.default.cyan("$ rcb agent build")}
31
+
32
+ ${chalk_1.default.gray("–")} 查看 AI Agent 命令使用介绍
33
+ ${chalk_1.default.cyan("$ rcb agent -h")}
34
+ `;
35
+ console.log(commands, "\n", options, "\n", tips);
36
+ };
37
+ exports.outputHelpInfo = outputHelpInfo;
@@ -0,0 +1,55 @@
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.findAvailablePort = findAvailablePort;
16
+ exports.isPortAvailable = isPortAvailable;
17
+ const net_1 = __importDefault(require("net"));
18
+ function findAvailablePort(startPort) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ return new Promise((resolve, reject) => {
21
+ const server = net_1.default.createServer();
22
+ server.on("error", (err) => {
23
+ if (err.code === "EADDRINUSE") {
24
+ server.close();
25
+ resolve(findAvailablePort(startPort + 1));
26
+ }
27
+ else {
28
+ reject(err);
29
+ }
30
+ });
31
+ server.listen(startPort, () => {
32
+ const { port } = server.address();
33
+ server.close(() => resolve(port));
34
+ });
35
+ });
36
+ });
37
+ }
38
+ function isPortAvailable(port) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ return new Promise((resolve) => {
41
+ const server = net_1.default.createServer();
42
+ server.on("error", (err) => {
43
+ if (err.code === "EADDRINUSE") {
44
+ resolve(false);
45
+ }
46
+ else {
47
+ resolve(false);
48
+ }
49
+ });
50
+ server.listen(port, () => {
51
+ server.close(() => resolve(true));
52
+ });
53
+ });
54
+ });
55
+ }
@@ -0,0 +1,124 @@
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.ProjectValidator = void 0;
16
+ const fs_1 = __importDefault(require("fs"));
17
+ const path_1 = __importDefault(require("path"));
18
+ const util_1 = require("util");
19
+ const semver_1 = __importDefault(require("semver"));
20
+ const container_1 = require("../container");
21
+ const env_helper_1 = require("./env-helper");
22
+ const readFileAsync = (0, util_1.promisify)(fs_1.default.readFile);
23
+ const accessAsync = (0, util_1.promisify)(fs_1.default.access);
24
+ class ProjectValidator {
25
+ constructor(workDir, uploadInfo) {
26
+ this.workDir = workDir;
27
+ this.uploadInfo = uploadInfo;
28
+ }
29
+ validate() {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ var _a, _b;
32
+ const errors = [];
33
+ const functionsConfigPath = path_1.default.join(this.workDir, "agent-cloudbase-functions.json");
34
+ if (!fs_1.default.existsSync(functionsConfigPath)) {
35
+ errors.push("agent-cloudbase-functions.json 文件不存在");
36
+ return { valid: false, errors };
37
+ }
38
+ const projectConfigPath = path_1.default.join(this.workDir, "project.config.json");
39
+ if (!fs_1.default.existsSync(projectConfigPath)) {
40
+ errors.push("project.config.json 文件不存在");
41
+ return { valid: false, errors };
42
+ }
43
+ const packageJsonPath = path_1.default.join(this.workDir, "package.json");
44
+ if (!fs_1.default.existsSync(packageJsonPath)) {
45
+ errors.push("package.json 文件不存在");
46
+ return { valid: false, errors };
47
+ }
48
+ const nodeModulesPath = path_1.default.join(this.workDir, "node_modules");
49
+ if (!fs_1.default.existsSync(nodeModulesPath)) {
50
+ errors.push("node_modules 目录不存在,请先运行 npm install");
51
+ return { valid: false, errors };
52
+ }
53
+ try {
54
+ const functionsConfig = JSON.parse(yield readFileAsync(functionsConfigPath, "utf-8"));
55
+ if (functionsConfig.functions) {
56
+ for (const func of functionsConfig.functions) {
57
+ const funcPath = path_1.default.join(this.workDir, func.directory);
58
+ try {
59
+ yield accessAsync(funcPath, fs_1.default.constants.F_OK);
60
+ }
61
+ catch (_c) {
62
+ errors.push(`函数目录不存在: ${func.directory}`);
63
+ }
64
+ }
65
+ }
66
+ const packageJson = JSON.parse(yield readFileAsync(packageJsonPath, "utf-8"));
67
+ const dependencies = Object.assign(Object.assign({}, packageJson.dependencies), packageJson.devDependencies);
68
+ for (const [dep, version] of Object.entries(dependencies)) {
69
+ const depPath = path_1.default.join(nodeModulesPath, dep);
70
+ try {
71
+ yield accessAsync(depPath, fs_1.default.constants.F_OK);
72
+ }
73
+ catch (_d) {
74
+ errors.push(`依赖缺失: ${dep}@${version}`);
75
+ }
76
+ }
77
+ const projectConfig = JSON.parse(yield readFileAsync(projectConfigPath, "utf-8"));
78
+ if (!projectConfig.version) {
79
+ errors.push("project.config.json `version` 字段不存在");
80
+ return { valid: false, errors };
81
+ }
82
+ if (!projectConfig.agentId) {
83
+ errors.push("project.config.json `agentId` 字段不存在");
84
+ return { valid: false, errors };
85
+ }
86
+ if (!semver_1.default.valid(projectConfig.version)) {
87
+ errors.push("project.config.json 中的 version 非法!请参考 semver 规范: https://semver.org/");
88
+ return { valid: false, errors };
89
+ }
90
+ try {
91
+ const version = env_helper_1.isIDE ? ((_a = this.uploadInfo) === null || _a === void 0 ? void 0 : _a.version) || projectConfig.version : projectConfig.version;
92
+ const desc = env_helper_1.isIDE ? ((_b = this.uploadInfo) === null || _b === void 0 ? void 0 : _b.desc) || projectConfig.desc : projectConfig.desc;
93
+ const uploadService = container_1.container.get(container_1.SERVICE_IDENTIFIERS.UploadService);
94
+ const buildPreCheckResult = yield uploadService.buildPreCheck({
95
+ agent_id: projectConfig.agentId,
96
+ version,
97
+ desc,
98
+ });
99
+ if (!buildPreCheckResult.success) {
100
+ errors.push(`上传预检失败:${buildPreCheckResult.msg}`);
101
+ return { valid: false, errors };
102
+ }
103
+ }
104
+ catch (error) {
105
+ errors.push(`上传预检异常 ${error.message}`);
106
+ return { valid: false, errors };
107
+ }
108
+ }
109
+ catch (error) {
110
+ if (error instanceof Error) {
111
+ errors.push(`配置文件解析错误: ${error.message}`);
112
+ }
113
+ else {
114
+ errors.push("配置文件解析错误: 未知错误");
115
+ }
116
+ }
117
+ return {
118
+ valid: errors.length === 0,
119
+ errors,
120
+ };
121
+ });
122
+ }
123
+ }
124
+ exports.ProjectValidator = ProjectValidator;
@@ -0,0 +1,77 @@
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.request = exports.Request = void 0;
16
+ const node_fetch_1 = __importDefault(require("node-fetch"));
17
+ const env_helper_1 = require("./env-helper");
18
+ class Request {
19
+ fetch(options) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ const { method = "GET", url, data = {}, headers = {} } = options;
22
+ try {
23
+ let requestUrl = url;
24
+ let requestBody;
25
+ const queryParams = new URLSearchParams();
26
+ if (data.query) {
27
+ Object.entries(data.query).forEach(([key, value]) => {
28
+ queryParams.append(key, String(value));
29
+ });
30
+ }
31
+ if (method === "GET" && data.params) {
32
+ Object.entries(data.params).forEach(([key, value]) => {
33
+ queryParams.append(key, String(value));
34
+ });
35
+ }
36
+ requestUrl = queryParams.toString() ? `${url}?${queryParams.toString()}` : url;
37
+ if (method === "POST" && data.body) {
38
+ requestBody = JSON.stringify(data.body);
39
+ const contentTypeKey = Object.keys(headers).find((key) => key.toLowerCase() === "content-type");
40
+ if (!contentTypeKey) {
41
+ headers["Content-Type"] = "application/json";
42
+ }
43
+ }
44
+ const hostFetch = env_helper_1.isIDE ? globalThis.fetch : node_fetch_1.default;
45
+ const response = yield hostFetch(requestUrl, {
46
+ method,
47
+ headers,
48
+ body: requestBody,
49
+ timeout: 1000 * 20,
50
+ });
51
+ const responseData = yield response.json();
52
+ return {
53
+ status: response.status,
54
+ data: responseData,
55
+ headers: response.headers,
56
+ };
57
+ }
58
+ catch (error) {
59
+ throw new Error(`请求失败 ${error.message}`);
60
+ }
61
+ });
62
+ }
63
+ handleHttpStatus(response) {
64
+ if (response.status >= 200 && response.status < 300) {
65
+ return response.data;
66
+ }
67
+ throw new Error(`HTTP 错误: ${response.status}`);
68
+ }
69
+ handleCode(data) {
70
+ if (data.code === 0) {
71
+ return data;
72
+ }
73
+ throw new Error(`业务错误: ${data.msg || "未知错误"}`);
74
+ }
75
+ }
76
+ exports.Request = Request;
77
+ exports.request = new Request();
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toHump = void 0;
4
+ const toHump = (str) => str.replace(/\-(\w)/g, (letter) => letter[1].toUpperCase());
5
+ exports.toHump = toHump;
@@ -0,0 +1,85 @@
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.getDeviceInfo = getDeviceInfo;
7
+ exports.deviceUA = deviceUA;
8
+ exports.machineId = machineId;
9
+ const child_process_1 = require("child_process");
10
+ const crypto_1 = require("crypto");
11
+ const os_1 = __importDefault(require("os"));
12
+ const guid = {
13
+ darwin: "ioreg -rd1 -c IOPlatformExpertDevice",
14
+ win32: "%windir%\\System32\\REG.exe QUERY HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography /v MachineGuid",
15
+ linux: "( cat /var/lib/dbus/machine-id /etc/machine-id 2> /dev/null || hostname ) | head -n 1 || :",
16
+ };
17
+ function hash(guid) {
18
+ return (0, crypto_1.createHash)("sha256").update(guid).digest("hex");
19
+ }
20
+ function expose(result) {
21
+ switch (process.platform) {
22
+ case "darwin":
23
+ return result
24
+ .split("IOPlatformUUID")[1]
25
+ .split("\n")[0]
26
+ .replace(/\=|\s+|\"/gi, "")
27
+ .toLowerCase();
28
+ case "win32":
29
+ return result
30
+ .toString()
31
+ .split("REG_SZ")[1]
32
+ .replace(/\r+|\n+|\s+/gi, "")
33
+ .toLowerCase();
34
+ case "linux":
35
+ return result
36
+ .toString()
37
+ .replace(/\r+|\n+|\s+/gi, "")
38
+ .toLowerCase();
39
+ default:
40
+ throw new Error(`Unsupported platform: ${process.platform}`);
41
+ }
42
+ }
43
+ function getOsVersion() {
44
+ var _a, _b;
45
+ try {
46
+ if (process.platform === "darwin") {
47
+ return (_a = (0, child_process_1.execSync)("sw_vers -productVersion", { encoding: "utf-8" })) === null || _a === void 0 ? void 0 : _a.trim();
48
+ }
49
+ return (_b = os_1.default.release()) === null || _b === void 0 ? void 0 : _b.trim();
50
+ }
51
+ catch (error) { }
52
+ return "";
53
+ }
54
+ function formatCupSpeed(speed, arch) {
55
+ var _a;
56
+ const num = Number(speed);
57
+ if (arch === "arm64" && num < 100) {
58
+ return Number((_a = (num * 100)) === null || _a === void 0 ? void 0 : _a.toFixed(0));
59
+ }
60
+ return Number(num === null || num === void 0 ? void 0 : num.toFixed(0));
61
+ }
62
+ function getDeviceInfo() {
63
+ var _a, _b;
64
+ const cpus = os_1.default.cpus();
65
+ const cpuInfo = cpus === null || cpus === void 0 ? void 0 : cpus[0];
66
+ const result = {
67
+ os_platform: ((_b = (_a = process.platform) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.toUpperCase()) + process.platform.slice(1),
68
+ os_arch: process.arch,
69
+ cpu_speed: formatCupSpeed(cpuInfo === null || cpuInfo === void 0 ? void 0 : cpuInfo.speed, process.arch),
70
+ cpu_model: cpuInfo === null || cpuInfo === void 0 ? void 0 : cpuInfo.model,
71
+ machine_memory: Math.round(os_1.default.totalmem() / 1024 / 1024),
72
+ os_version: getOsVersion(),
73
+ };
74
+ return result;
75
+ }
76
+ function deviceUA() {
77
+ return Object.assign(Object.assign({}, getDeviceInfo()), { login_user: hash(os_1.default.userInfo().username || process.env.username), node_version: process.version });
78
+ }
79
+ function machineId() {
80
+ try {
81
+ return expose((0, child_process_1.execSync)(guid[process.platform]).toString());
82
+ }
83
+ catch (error) { }
84
+ return JSON.stringify(deviceUA());
85
+ }
@@ -0,0 +1,134 @@
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.APM = void 0;
7
+ const node_fetch_1 = __importDefault(require("node-fetch"));
8
+ const uuid_1 = __importDefault(require("uuid"));
9
+ const logger_1 = require("../logger");
10
+ const device_1 = require("./device");
11
+ const deviceInfo = (0, device_1.getDeviceInfo)();
12
+ const getUserAgent = () => {
13
+ var _a, _b;
14
+ const electronStr = typeof ((_a = process === null || process === void 0 ? void 0 : process.versions) === null || _a === void 0 ? void 0 : _a.electron) !== "undefined" ? `Electron/${(_b = process === null || process === void 0 ? void 0 : process.versions) === null || _b === void 0 ? void 0 : _b.electron}` : "";
15
+ const nodeStr = `Node/${process.version}`;
16
+ const os_version = `${deviceInfo.os_platform}/${deviceInfo.os_version}`;
17
+ const cpu = `CPU/${deviceInfo.cpu_speed}mhz (${deviceInfo.cpu_model}; ${deviceInfo.os_arch})`;
18
+ const mem = `Memory/${deviceInfo.machine_memory}mb`;
19
+ return [electronStr, nodeStr, os_version, cpu, mem]
20
+ .map((i) => { var _a; return (_a = i === null || i === void 0 ? void 0 : i.trim) === null || _a === void 0 ? void 0 : _a.call(i); })
21
+ .filter(Boolean)
22
+ .join(" ")
23
+ .trim();
24
+ };
25
+ const CONTEXT = {
26
+ context_nameTracker: "nodeT",
27
+ context_platform: deviceInfo.os_platform,
28
+ context_appVersion: "0.0.1",
29
+ context_osVersion: deviceInfo.os_version,
30
+ context_deviceModel: "",
31
+ context_deviceId: (0, device_1.machineId)(),
32
+ context_package: "",
33
+ context_networkType: "unknow",
34
+ context_matchedPath: "cli",
35
+ context_route: "xhsmp://cli",
36
+ context_userAgent: getUserAgent(),
37
+ context_artifactName: "miniprogram",
38
+ context_networkQuality: "UNKNOWN",
39
+ context_artifactVersion: "UNKNOWN",
40
+ context_userId: "",
41
+ };
42
+ const ENDPOINT = {
43
+ development: "https://apm-fe.xiaohongshu.com/api/data",
44
+ production: "https://apm-fe.xiaohongshu.com/api/data",
45
+ };
46
+ class APM {
47
+ constructor() {
48
+ this.reportQueue = [];
49
+ this.allowReport = false;
50
+ this.eventSeq = 1;
51
+ this.context = Object.assign({}, CONTEXT);
52
+ this.baseData = {};
53
+ this.timer = null;
54
+ }
55
+ setContext(userId, base = {}) {
56
+ this.context = Object.assign(Object.assign({}, this.context), { context_userId: userId });
57
+ this.baseData = base;
58
+ this.startReport();
59
+ }
60
+ startReport() {
61
+ this.allowReport = true;
62
+ this.bactchReport();
63
+ }
64
+ getSequence() {
65
+ return {
66
+ context_sdkSeqId: this.eventSeq++,
67
+ context_sdkSessionId: uuid_1.default.v4(),
68
+ context_pageSessionId: uuid_1.default.v4(),
69
+ clientTime: Date.now(),
70
+ };
71
+ }
72
+ _request(params, retry = true) {
73
+ const list = Array.isArray(params) ? params : [params];
74
+ const merged = list.map((i) => {
75
+ return Object.assign(Object.assign(Object.assign({}, this.context), i.suquence), { measurement_name: i.measurement_name, measurement_data: Object.assign(Object.assign({}, this.baseData), i.measurement_data) });
76
+ });
77
+ logger_1.logger.debug(`apm before send`, `${JSON.stringify(merged)}`, "warning");
78
+ return (0, node_fetch_1.default)(ENDPOINT.development, {
79
+ method: "post",
80
+ body: JSON.stringify(merged),
81
+ headers: {
82
+ accept: "*/*",
83
+ "accept-language": "zh-CN,zh;q=0.9",
84
+ batch: "true",
85
+ "biz-type": "apm_fe",
86
+ "cache-control": "no-cache",
87
+ "content-type": "application/json",
88
+ pragma: "no-cache",
89
+ },
90
+ })
91
+ .then((res) => res.json())
92
+ .then((res) => {
93
+ if (res === null || res === void 0 ? void 0 : res.success) {
94
+ logger_1.logger.debug("apm send success", "");
95
+ }
96
+ else {
97
+ throw new Error(res === null || res === void 0 ? void 0 : res.msg);
98
+ }
99
+ })
100
+ .catch((err) => {
101
+ if (retry) {
102
+ setTimeout(() => this._request(merged, false), 1000);
103
+ }
104
+ logger_1.logger.log(`apm send failed`, `${(err === null || err === void 0 ? void 0 : err.message) || null}`, "error");
105
+ });
106
+ }
107
+ bactchReport() {
108
+ const queue = [...this.reportQueue];
109
+ this.reportQueue = [];
110
+ while (queue.length) {
111
+ this._request(queue.splice(0, 5));
112
+ }
113
+ }
114
+ report(measurement_name, measurement_data = {}) {
115
+ const params = {
116
+ suquence: this.getSequence(),
117
+ measurement_name,
118
+ measurement_data,
119
+ };
120
+ this.reportQueue.push(params);
121
+ clearTimeout(this.timer);
122
+ if (this.allowReport) {
123
+ if (this.reportQueue.length >= 10) {
124
+ this.bactchReport();
125
+ }
126
+ else {
127
+ this.timer = setTimeout(() => {
128
+ this.bactchReport();
129
+ }, 200);
130
+ }
131
+ }
132
+ }
133
+ }
134
+ exports.APM = APM;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@vectorx/cloud-toolkit",
3
+ "version": "0.0.0-beta-20251112071234",
4
+ "description": "VectorX Cloud Toolkit",
5
+ "main": "lib/index.js",
6
+ "types": "types/index.d.ts",
7
+ "files": [
8
+ "lib",
9
+ "types",
10
+ "README.md"
11
+ ],
12
+ "keywords": [
13
+ "ai",
14
+ "sdk",
15
+ "cloud",
16
+ "sdk"
17
+ ],
18
+ "author": "",
19
+ "license": "ISC",
20
+ "engines": {
21
+ "node": ">=18.0.0"
22
+ },
23
+ "dependencies": {
24
+ "@vectorx/agent-simulator": "0.0.0-beta-20251112071234",
25
+ "@vectorx/functions-framework": "0.0.0-beta-20251112071234",
26
+ "archiver": "^5.3.1",
27
+ "cos-nodejs-sdk-v5": "2.x",
28
+ "crypto": "^1.0.1",
29
+ "dayjs": "^1.11.13",
30
+ "inversify": "^7.5.2",
31
+ "langfuse": "^3.38.4",
32
+ "lodash": "^4.17.21",
33
+ "log-symbols": "^3.0.0",
34
+ "lowdb": "^1.0.0",
35
+ "make-dir": "^3.0.0",
36
+ "node-fetch": "^2.6.0",
37
+ "open": "^7.4.2",
38
+ "ora": "^4.0.2",
39
+ "semver": "^7.5.4",
40
+ "terminal-link": "^2.1.1",
41
+ "uuid": "^11.1.0"
42
+ },
43
+ "devDependencies": {
44
+ "@types/archiver": "^5.3.2",
45
+ "@types/node": "^20.11.24",
46
+ "@types/semver": "^7.5.8",
47
+ "typescript": "^5.3.3"
48
+ },
49
+ "scripts": {
50
+ "dev": "rimraf lib types && tsc -w && cp -r src/utils/*.applescript lib/utils/",
51
+ "build": "rimraf lib types && tsc --resolveJsonModule && cp -r src/utils/*.applescript lib/utils/",
52
+ "test": "echo \"Error: no test specified\" && exit 1"
53
+ },
54
+ "readme": "### 云开发工具集合"
55
+ }
@@ -0,0 +1,70 @@
1
+ export interface AgentDevOptions {
2
+ workDir?: string;
3
+ port?: number;
4
+ simulatorPort?: number;
5
+ watch?: boolean;
6
+ open?: boolean;
7
+ nodePath?: string;
8
+ enableRedLangfuse?: boolean;
9
+ }
10
+ export interface IUploadOptions {
11
+ version: string;
12
+ desc: string;
13
+ }
14
+ export interface AgentBuildOptions {
15
+ workDir?: string;
16
+ outputDir?: string;
17
+ filename?: string;
18
+ upload?: boolean;
19
+ validator?: IProjectValidator;
20
+ uploadInfo?: IUploadOptions;
21
+ }
22
+ export interface AgentNewOptions {
23
+ projectName: string;
24
+ targetDir?: string;
25
+ }
26
+ export interface AgentDeployOptions {
27
+ targetPath: string;
28
+ projectConfigPath?: string;
29
+ agentId?: string;
30
+ version?: string;
31
+ desc?: string;
32
+ }
33
+ export interface ValidationResult {
34
+ valid: boolean;
35
+ errors: string[];
36
+ }
37
+ export interface IProjectValidator {
38
+ validate(): Promise<ValidationResult>;
39
+ }
40
+ export interface BuildResult {
41
+ outputPath: string;
42
+ size: number;
43
+ }
44
+ export interface DeployResult {
45
+ success: boolean;
46
+ code: number;
47
+ message?: string;
48
+ }
49
+ export interface IDeployService {
50
+ deploy(options: {
51
+ targetPath: string;
52
+ agentId: string;
53
+ version: string;
54
+ desc: string;
55
+ }): Promise<DeployResult>;
56
+ }
57
+ export declare function startRcbFramework(workDir: string, port: number, watch: boolean, nodePath?: string, options?: {
58
+ enableRedLangfuse?: boolean;
59
+ }): Promise<void>;
60
+ export declare function startDev(options: AgentDevOptions): Promise<{
61
+ port: number;
62
+ simulatorPort: number;
63
+ simulator: any;
64
+ rcbProcess: any;
65
+ }>;
66
+ export declare function build(options: AgentBuildOptions): Promise<BuildResult>;
67
+ export declare function createNew(options: AgentNewOptions): Promise<{
68
+ projectDir: string;
69
+ }>;
70
+ export declare function cleanup(): void;
@@ -0,0 +1,2 @@
1
+ declare function getBaseUrl(): string;
2
+ export { getBaseUrl };
@@ -0,0 +1 @@
1
+ export * from "./api.config";
@@ -0,0 +1,3 @@
1
+ import { Container } from "inversify";
2
+ declare const container: Container;
3
+ export { container };
@@ -0,0 +1,6 @@
1
+ import type { ServiceIdentifier } from "inversify";
2
+ import type { IAuthService, IUploadService } from "./types";
3
+ export declare const SERVICE_IDENTIFIERS: {
4
+ AuthService: ServiceIdentifier<IAuthService>;
5
+ UploadService: ServiceIdentifier<IUploadService>;
6
+ };