@vectorx/cloud-toolkit 0.0.0-beta-20260108133839 → 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.
Files changed (53) hide show
  1. package/lib/agent.kit.js +274 -56
  2. package/lib/cloud-dev.kit.js +36 -0
  3. package/lib/config/api.config.js +2 -8
  4. package/lib/container/container.js +10 -0
  5. package/lib/container/identifiers.js +5 -0
  6. package/lib/container/index.js +15 -0
  7. package/lib/database.kit.js +56 -0
  8. package/lib/env.kit.js +40 -0
  9. package/lib/fun.kit.js +34 -0
  10. package/lib/index.js +6 -0
  11. package/lib/services/agent-service.js +132 -0
  12. package/lib/services/auth-service.js +2 -1
  13. package/lib/services/cloud-dev-service.js +97 -0
  14. package/lib/services/cloud-env-service.js +166 -0
  15. package/lib/services/database-service.js +142 -0
  16. package/lib/services/fun-service.js +378 -0
  17. package/lib/services/index.js +5 -0
  18. package/lib/utils/cos-uploader.js +3 -1
  19. package/lib/utils/fun-project-validator.js +212 -0
  20. package/lib/utils/open-browser.js +7 -1
  21. package/lib/utils/openChrome.applescript +2 -2
  22. package/lib/utils/output.js +53 -19
  23. package/lib/utils/project-validator.js +3 -1
  24. package/lib/utils/request.js +21 -0
  25. package/lib/utils/table.js +17 -0
  26. package/lib/utils/tracker/ai-apm.js +62 -0
  27. package/lib/utils/tracker/apm.js +137 -0
  28. package/lib/utils/tracker/cli-apm.js +108 -0
  29. package/lib/utils/tracker/device.js +3 -1
  30. package/lib/utils/tracker/index.js +18 -131
  31. package/package.json +15 -7
  32. package/types/agent.kit.d.ts +45 -2
  33. package/types/cloud-dev.kit.d.ts +18 -0
  34. package/types/config/api.config.d.ts +1 -2
  35. package/types/container/identifiers.d.ts +6 -1
  36. package/types/container/index.d.ts +6 -1
  37. package/types/container/types.d.ts +124 -0
  38. package/types/database.kit.d.ts +54 -0
  39. package/types/env.kit.d.ts +43 -0
  40. package/types/fun.kit.d.ts +63 -0
  41. package/types/index.d.ts +6 -0
  42. package/types/services/agent-service.d.ts +11 -0
  43. package/types/services/cloud-dev-service.d.ts +23 -0
  44. package/types/services/cloud-env-service.d.ts +10 -0
  45. package/types/services/database-service.d.ts +33 -0
  46. package/types/services/fun-service.d.ts +23 -0
  47. package/types/services/index.d.ts +5 -0
  48. package/types/utils/fun-project-validator.d.ts +22 -0
  49. package/types/utils/table.d.ts +2 -0
  50. package/types/utils/tracker/ai-apm.d.ts +54 -0
  51. package/types/utils/tracker/apm.d.ts +28 -0
  52. package/types/utils/tracker/cli-apm.d.ts +27 -0
  53. package/types/utils/tracker/index.d.ts +5 -27
package/lib/env.kit.js ADDED
@@ -0,0 +1,40 @@
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.getCloudEnvironments = getCloudEnvironments;
13
+ exports.getCloudEnvironment = getCloudEnvironment;
14
+ exports.createCloudEnvironment = createCloudEnvironment;
15
+ exports.updateCloudEnvironment = updateCloudEnvironment;
16
+ const container_1 = require("./container");
17
+ function getCloudEnvironments(cloudEnvId) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ const envService = container_1.ServiceProvider.getCloudEnvService();
20
+ return envService.getCloudEnvironments(cloudEnvId);
21
+ });
22
+ }
23
+ function getCloudEnvironment(cloudEnvId) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ const envService = container_1.ServiceProvider.getCloudEnvService();
26
+ return envService.getCloudEnvironment(cloudEnvId);
27
+ });
28
+ }
29
+ function createCloudEnvironment(payload) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ const envService = container_1.ServiceProvider.getCloudEnvService();
32
+ return envService.createCloudEnvironment(payload);
33
+ });
34
+ }
35
+ function updateCloudEnvironment(payload) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ const envService = container_1.ServiceProvider.getCloudEnvService();
38
+ return envService.updateCloudEnvironment(payload);
39
+ });
40
+ }
package/lib/fun.kit.js ADDED
@@ -0,0 +1,34 @@
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.startFunDev = startFunDev;
13
+ exports.deployFun = deployFun;
14
+ exports.getPublishHistory = getPublishHistory;
15
+ const container_1 = require("./container");
16
+ function startFunDev() {
17
+ return __awaiter(this, arguments, void 0, function* (options = {}) {
18
+ const funService = container_1.ServiceProvider.getFunService();
19
+ return funService.startFunDev(options);
20
+ });
21
+ }
22
+ function deployFun(options) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ const funService = container_1.ServiceProvider.getFunService();
25
+ const result = yield funService.deploy(options);
26
+ return result;
27
+ });
28
+ }
29
+ function getPublishHistory(options) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ const funService = container_1.ServiceProvider.getFunService();
32
+ return funService.getPublishHistory(options);
33
+ });
34
+ }
package/lib/index.js CHANGED
@@ -16,6 +16,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.Uploader = void 0;
18
18
  __exportStar(require("./agent.kit"), exports);
19
+ __exportStar(require("./fun.kit"), exports);
20
+ __exportStar(require("./env.kit"), exports);
21
+ __exportStar(require("./database.kit"), exports);
22
+ __exportStar(require("./cloud-dev.kit"), exports);
19
23
  var cos_uploader_1 = require("./utils/cos-uploader");
20
24
  Object.defineProperty(exports, "Uploader", { enumerable: true, get: function () { return cos_uploader_1.Uploader; } });
21
25
  __exportStar(require("./container"), exports);
@@ -28,3 +32,5 @@ __exportStar(require("./utils/tracker"), exports);
28
32
  __exportStar(require("./utils/port-finder"), exports);
29
33
  __exportStar(require("./utils/open-browser"), exports);
30
34
  __exportStar(require("./utils/output"), exports);
35
+ __exportStar(require("./utils/table"), exports);
36
+ __exportStar(require("./utils/fun-project-validator"), 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);
@@ -104,6 +104,7 @@ let AuthService = class AuthService {
104
104
  return loginInfo;
105
105
  }
106
106
  catch (error) {
107
+ yield this.clearLoginInfo();
107
108
  return null;
108
109
  }
109
110
  });
@@ -124,7 +125,7 @@ let AuthService = class AuthService {
124
125
  return response.data;
125
126
  }
126
127
  catch (error) {
127
- throw new Error("检查登录信息失败");
128
+ throw new Error("检查登录失败信息");
128
129
  }
129
130
  });
130
131
  }
@@ -0,0 +1,97 @@
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.CloudDevService = void 0;
22
+ const endpoints_1 = require("@vectorx/endpoints");
23
+ const inversify_1 = require("inversify");
24
+ const container_1 = require("../container");
25
+ const env_helper_1 = require("../utils/env-helper");
26
+ const request_1 = require("../utils/request");
27
+ const CLOUD_DEV_PREFIX = "/octopus-server/cloud-developement";
28
+ let CloudDevService = class CloudDevService {
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
+ getCloudDevBaseUrl() {
48
+ return `${(0, endpoints_1.getMiniappBetaBaseUrl)()}${CLOUD_DEV_PREFIX}`;
49
+ }
50
+ getLangfuseConfig(params) {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ const query = yield this.resolveAuthQuery(params);
53
+ const httpResponse = yield request_1.request.fetch({
54
+ method: "GET",
55
+ url: `${this.getCloudDevBaseUrl()}/langfuse/config`,
56
+ data: { query },
57
+ });
58
+ const data = request_1.request.handleCode(request_1.request.handleHttpStatus(httpResponse));
59
+ return {
60
+ secretKey: data.data.secret_key,
61
+ publicKey: data.data.public_key,
62
+ baseUrl: data.data.base_url,
63
+ };
64
+ });
65
+ }
66
+ getCloudDevLLMBaseURL(params) {
67
+ const base = `${this.getCloudDevBaseUrl()}/llm/chat/completions`;
68
+ if ((params === null || params === void 0 ? void 0 : params.secret_id) && (params === null || params === void 0 ? void 0 : params.cli_token)) {
69
+ return `${base}?secret_id=${params.secret_id}&cli_token=${params.cli_token}`;
70
+ }
71
+ return base;
72
+ }
73
+ getCloudDevAnthropicLLMBaseURL(params) {
74
+ const base = `${this.getCloudDevBaseUrl()}/llm/external/chat/completions`;
75
+ if ((params === null || params === void 0 ? void 0 : params.secret_id) && (params === null || params === void 0 ? void 0 : params.cli_token)) {
76
+ return `${base}?secret_id=${params.secret_id}&cli_token=${params.cli_token}`;
77
+ }
78
+ return base;
79
+ }
80
+ getUserInfo(params) {
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ const query = yield this.resolveAuthQuery(params);
83
+ const httpResponse = yield request_1.request.fetch({
84
+ method: "GET",
85
+ url: `${this.getCloudDevBaseUrl()}/user/info`,
86
+ data: { query },
87
+ });
88
+ const data = request_1.request.handleCode(request_1.request.handleHttpStatus(httpResponse));
89
+ return data.data;
90
+ });
91
+ }
92
+ };
93
+ exports.CloudDevService = CloudDevService;
94
+ exports.CloudDevService = CloudDevService = __decorate([
95
+ (0, inversify_1.injectable)(),
96
+ __metadata("design:paramtypes", [])
97
+ ], CloudDevService);
@@ -0,0 +1,166 @@
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.CloudEnvService = 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 CloudEnvService = class CloudEnvService {
29
+ constructor() {
30
+ this.authService = container_1.container.get(container_1.SERVICE_IDENTIFIERS.AuthService);
31
+ }
32
+ getCloudEnvironments(cloudEnvId) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ var _a, _b;
35
+ try {
36
+ let query = {};
37
+ if (!env_helper_1.isIDE) {
38
+ const loginInfo = yield this.authService.getLoginInfo();
39
+ if (!loginInfo) {
40
+ throw new Error("未登录,请先执行登录命令");
41
+ }
42
+ query = {
43
+ secret_id: loginInfo.secret_id,
44
+ cli_token: loginInfo.cli_token,
45
+ };
46
+ }
47
+ const httpResponse = yield request_1.request.fetch({
48
+ method: "POST",
49
+ url: `${(0, config_1.getBaseUrl)()}/api/eros/mp/red/code/cloud_env/query`,
50
+ headers: {
51
+ "Content-Type": "application/json",
52
+ },
53
+ data: {
54
+ query,
55
+ body: {
56
+ cloud_env_id: cloudEnvId !== null && cloudEnvId !== void 0 ? cloudEnvId : "",
57
+ },
58
+ },
59
+ });
60
+ const data = request_1.request.handleCode(request_1.request.handleHttpStatus(httpResponse));
61
+ return ((_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.env_list) || ((_b = data === null || data === void 0 ? void 0 : data.data) === null || _b === void 0 ? void 0 : _b.envs) || [];
62
+ }
63
+ catch (error) {
64
+ const msg = (error === null || error === void 0 ? void 0 : error.message) || String(error);
65
+ logger_1.logger.error(`云环境列表接口调用失败: ${msg}`);
66
+ throw error;
67
+ }
68
+ });
69
+ }
70
+ getCloudEnvironment(cloudEnvId) {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ if (!cloudEnvId) {
73
+ return null;
74
+ }
75
+ const envs = yield this.getCloudEnvironments(cloudEnvId);
76
+ if (!envs || envs.length === 0) {
77
+ return null;
78
+ }
79
+ const exact = envs.find((env) => env.cloud_env_id === cloudEnvId);
80
+ return exact || envs[0] || null;
81
+ });
82
+ }
83
+ createCloudEnvironment(payload) {
84
+ return __awaiter(this, void 0, void 0, function* () {
85
+ var _a, _b;
86
+ if (!(payload === null || payload === void 0 ? void 0 : payload.cloud_env_name)) {
87
+ throw new Error("cloud_env_name 为必填字段");
88
+ }
89
+ let query = {};
90
+ if (!env_helper_1.isIDE) {
91
+ const loginInfo = yield this.authService.getLoginInfo();
92
+ if (!loginInfo) {
93
+ throw new Error("未登录,请先执行登录命令");
94
+ }
95
+ query = {
96
+ secret_id: loginInfo.secret_id,
97
+ cli_token: loginInfo.cli_token,
98
+ };
99
+ }
100
+ const httpResponse = yield request_1.request.fetch({
101
+ method: "POST",
102
+ url: `${(0, config_1.getBaseUrl)()}/api/eros/mp/red/code/cloud_env/create`,
103
+ headers: {
104
+ "Content-Type": "application/json",
105
+ },
106
+ data: {
107
+ query,
108
+ body: {
109
+ cloud_env_name: payload.cloud_env_name,
110
+ description: (_a = payload.description) !== null && _a !== void 0 ? _a : "",
111
+ },
112
+ },
113
+ });
114
+ const res = request_1.request.handleCode(request_1.request.handleHttpStatus(httpResponse));
115
+ return ((_b = res.data) === null || _b === void 0 ? void 0 : _b.env_info) || res.data;
116
+ });
117
+ }
118
+ updateCloudEnvironment(payload) {
119
+ return __awaiter(this, void 0, void 0, function* () {
120
+ var _a, _b;
121
+ if (!(payload === null || payload === void 0 ? void 0 : payload.cloud_env_id)) {
122
+ throw new Error("cloud_env_id 为必填字段");
123
+ }
124
+ let query = {};
125
+ if (!env_helper_1.isIDE) {
126
+ const loginInfo = yield this.authService.getLoginInfo();
127
+ if (!loginInfo) {
128
+ throw new Error("未登录,请先执行登录命令");
129
+ }
130
+ query = {
131
+ secret_id: loginInfo.secret_id,
132
+ cli_token: loginInfo.cli_token,
133
+ };
134
+ }
135
+ const httpResponse = yield request_1.request.fetch({
136
+ method: "POST",
137
+ url: `${(0, config_1.getBaseUrl)()}/api/eros/mp/red/code/cloud_env/update`,
138
+ headers: {
139
+ "Content-Type": "application/json",
140
+ },
141
+ data: {
142
+ query,
143
+ body: {
144
+ cloud_env_id: payload.cloud_env_id,
145
+ env_variables: payload.env_variables,
146
+ },
147
+ },
148
+ });
149
+ if ((httpResponse === null || httpResponse === void 0 ? void 0 : httpResponse.status) === 401) {
150
+ const msg = ((_a = httpResponse === null || httpResponse === void 0 ? void 0 : httpResponse.data) === null || _a === void 0 ? void 0 : _a.msg) || "请先登录";
151
+ throw new Error(msg);
152
+ }
153
+ const res = request_1.request.handleCode(request_1.request.handleHttpStatus(httpResponse));
154
+ if ((res === null || res === void 0 ? void 0 : res.success) === false) {
155
+ const msg = (res === null || res === void 0 ? void 0 : res.msg) || (res === null || res === void 0 ? void 0 : res.message) || "更新云环境配置失败";
156
+ throw new Error(msg);
157
+ }
158
+ return ((_b = res.data) === null || _b === void 0 ? void 0 : _b.env_info) || res.data;
159
+ });
160
+ }
161
+ };
162
+ exports.CloudEnvService = CloudEnvService;
163
+ exports.CloudEnvService = CloudEnvService = __decorate([
164
+ (0, inversify_1.injectable)(),
165
+ __metadata("design:paramtypes", [])
166
+ ], CloudEnvService);
@@ -0,0 +1,142 @@
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.DatabaseService = void 0;
22
+ const cloud_database_client_1 = require("@vectorx/cloud-database-client");
23
+ const inversify_1 = require("inversify");
24
+ const container_1 = require("../container");
25
+ const stderrSink = {
26
+ debug: (...args) => process.stderr.write(`[debug] ${args.join(" ")}\n`),
27
+ info: (...args) => process.stderr.write(`[info] ${args.join(" ")}\n`),
28
+ warn: (...args) => process.stderr.write(`[warn] ${args.join(" ")}\n`),
29
+ error: (...args) => process.stderr.write(`[error] ${args.join(" ")}\n`),
30
+ };
31
+ let DatabaseService = class DatabaseService {
32
+ constructor() {
33
+ this.clientCache = new Map();
34
+ this.mockRdsEndpointInfo = {
35
+ InstanceName: "ra-supabase-ne5e81twbues8l",
36
+ RequestId: "D56F483E-3439-5228-B9FB-E56A221937DF",
37
+ DBInstanceEndpoints: [
38
+ {
39
+ IpType: "public",
40
+ Port: "5432",
41
+ ConnectionString: "pgm-uf6ib032536q2cq14o.pg.rds.aliyuncs.com",
42
+ },
43
+ ],
44
+ };
45
+ this.authService = container_1.container.get(container_1.SERVICE_IDENTIFIERS.AuthService);
46
+ }
47
+ pickDbEndpoint() {
48
+ const preferred = process.env.PG_ENDPOINT_IP_TYPE;
49
+ const ipType = preferred === "vpc" ? "vpc" : "public";
50
+ const endpoints = this.mockRdsEndpointInfo.DBInstanceEndpoints;
51
+ const hit = endpoints.find((e) => e.IpType === ipType);
52
+ if (!hit) {
53
+ throw new Error(`DB endpoint 不存在:ipType=${ipType}`);
54
+ }
55
+ const portNum = Number(hit.Port);
56
+ if (!Number.isFinite(portNum) || portNum <= 0) {
57
+ throw new Error(`DB endpoint 端口非法:${String(hit.Port)}`);
58
+ }
59
+ return { host: hit.ConnectionString, port: portNum, ipType };
60
+ }
61
+ getOrCreateClient(ctx) {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ var _a;
64
+ const envId = (_a = ctx.envId) !== null && _a !== void 0 ? _a : "default";
65
+ const key = `postgres::${envId}`;
66
+ const cached = this.clientCache.get(key);
67
+ if (cached)
68
+ return cached;
69
+ const endpoint = this.pickDbEndpoint();
70
+ const database = "supabase_db";
71
+ const password = "miniappSupabaseDatabase_0202";
72
+ const user = "supabase_admin";
73
+ const maxRaw = process.env.PG_POOL_MAX;
74
+ const idleRaw = process.env.PG_POOL_IDLE_TIMEOUT_MS;
75
+ const connTimeoutRaw = process.env.PG_POOL_CONNECTION_TIMEOUT_MS;
76
+ const max = typeof maxRaw === "string" && maxRaw.trim() ? Number(maxRaw) : undefined;
77
+ const idleTimeoutMillis = typeof idleRaw === "string" && idleRaw.trim() ? Number(idleRaw) : undefined;
78
+ const connectionTimeoutMillis = typeof connTimeoutRaw === "string" && connTimeoutRaw.trim()
79
+ ? Number(connTimeoutRaw)
80
+ : undefined;
81
+ const provider = new cloud_database_client_1.PostgresProvider({
82
+ config: {
83
+ host: endpoint.host,
84
+ port: endpoint.port,
85
+ user,
86
+ password,
87
+ database,
88
+ max,
89
+ idleTimeoutMillis,
90
+ connectionTimeoutMillis,
91
+ },
92
+ verbose: false,
93
+ logger: new cloud_database_client_1.OrmLikeDbLogger({
94
+ format: "pretty",
95
+ sink: stderrSink,
96
+ }),
97
+ maxValueLength: 200,
98
+ });
99
+ const client = (0, cloud_database_client_1.createDatabaseClient)({ provider });
100
+ this.clientCache.set(key, client);
101
+ stderrSink.info(`[DatabaseService] 创建数据库连接: envId=${envId}, host=${endpoint.host}:${endpoint.port}`);
102
+ return client;
103
+ });
104
+ }
105
+ listTables(ctx, params) {
106
+ return __awaiter(this, void 0, void 0, function* () {
107
+ const client = yield this.getOrCreateClient(ctx);
108
+ const tables = yield client.listTables({
109
+ schema: params === null || params === void 0 ? void 0 : params.schema,
110
+ });
111
+ return { tables };
112
+ });
113
+ }
114
+ getTableColumns(ctx, params) {
115
+ return __awaiter(this, void 0, void 0, function* () {
116
+ const client = yield this.getOrCreateClient(ctx);
117
+ const columns = yield client.getTableColumns({
118
+ schema: params.schema,
119
+ table: params.table,
120
+ });
121
+ return { columns };
122
+ });
123
+ }
124
+ previewTable(ctx, params) {
125
+ return __awaiter(this, void 0, void 0, function* () {
126
+ const client = yield this.getOrCreateClient(ctx);
127
+ const preview = yield client.previewTable({ schema: params.schema, table: params.table }, params.options);
128
+ return { preview };
129
+ });
130
+ }
131
+ executeSql(ctx, q) {
132
+ return __awaiter(this, void 0, void 0, function* () {
133
+ const client = yield this.getOrCreateClient(ctx);
134
+ return yield client.executeSql(q);
135
+ });
136
+ }
137
+ };
138
+ exports.DatabaseService = DatabaseService;
139
+ exports.DatabaseService = DatabaseService = __decorate([
140
+ (0, inversify_1.injectable)(),
141
+ __metadata("design:paramtypes", [])
142
+ ], DatabaseService);