@vectorx/xhs-cloud-cli 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.
- package/README.md +34 -0
- package/bin/rcb.js +264 -0
- package/lib/commands/agent/build.js +222 -0
- package/lib/commands/agent/dev.js +117 -0
- package/lib/commands/agent/index.js +19 -0
- package/lib/commands/agent/new.js +125 -0
- package/lib/commands/auth/index.js +18 -0
- package/lib/commands/auth/login.js +196 -0
- package/lib/commands/auth/logout.js +87 -0
- package/lib/commands/index.js +18 -0
- package/lib/constants/cmd.js +37 -0
- package/lib/core/base.js +95 -0
- package/lib/decorators/auth.js +49 -0
- package/lib/decorators/captureError.js +28 -0
- package/lib/decorators/constants.js +15 -0
- package/lib/decorators/index.js +20 -0
- package/lib/decorators/injectParams.js +57 -0
- package/lib/decorators/params/common.js +16 -0
- package/lib/decorators/params/index.js +29 -0
- package/lib/index.js +17 -0
- package/lib/main.js +20 -0
- package/lib/output.js +7 -0
- package/package.json +104 -0
- package/templates/chatbox-agent/.env.template +2 -0
- package/templates/chatbox-agent/agent-cloudbase-functions.json +11 -0
- package/templates/chatbox-agent/package.json +11 -0
- package/templates/chatbox-agent/project.config.json +5 -0
- package/templates/chatbox-agent/src/index.js +51 -0
- package/templates/weather-agent/index.js +92 -0
- package/templates/weather-agent/project.config.json +4 -0
- package/types/commands/agent/build.d.ts +26 -0
- package/types/commands/agent/dev.d.ts +15 -0
- package/types/commands/agent/index.d.ts +3 -0
- package/types/commands/agent/new.d.ts +16 -0
- package/types/commands/auth/index.d.ts +2 -0
- package/types/commands/auth/login.d.ts +13 -0
- package/types/commands/auth/logout.d.ts +7 -0
- package/types/commands/index.d.ts +2 -0
- package/types/constants/cmd.d.ts +11 -0
- package/types/core/base.d.ts +40 -0
- package/types/decorators/auth.d.ts +1 -0
- package/types/decorators/captureError.d.ts +1 -0
- package/types/decorators/constants.d.ts +11 -0
- package/types/decorators/index.d.ts +4 -0
- package/types/decorators/injectParams.d.ts +1 -0
- package/types/decorators/params/common.d.ts +4 -0
- package/types/decorators/params/index.d.ts +8 -0
- package/types/index.d.ts +1 -0
- package/types/main.d.ts +3 -0
- package/types/output.d.ts +3 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParamTypes = exports.PARAM_METADATA = void 0;
|
|
4
|
+
exports.PARAM_METADATA = "PARAM_METADATA";
|
|
5
|
+
var ParamTypes;
|
|
6
|
+
(function (ParamTypes) {
|
|
7
|
+
ParamTypes["Credential"] = "__Credential__";
|
|
8
|
+
ParamTypes["Log"] = "__Log__";
|
|
9
|
+
ParamTypes["CmdContext"] = "__CmdContext__";
|
|
10
|
+
ParamTypes["EnvId"] = "__EnvId__";
|
|
11
|
+
ParamTypes["Config"] = "__Config__";
|
|
12
|
+
ParamTypes["ArgsOptions"] = "__ArgsOptions__";
|
|
13
|
+
ParamTypes["ArgsParams"] = "__ArgsParams__";
|
|
14
|
+
ParamTypes["IsPrivateEnv"] = "__ISPrivateEnv__";
|
|
15
|
+
})(ParamTypes || (exports.ParamTypes = ParamTypes = {}));
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./params"), exports);
|
|
18
|
+
__exportStar(require("./injectParams"), exports);
|
|
19
|
+
__exportStar(require("./captureError"), exports);
|
|
20
|
+
__exportStar(require("./params"), exports);
|
|
@@ -0,0 +1,57 @@
|
|
|
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.InjectParams = InjectParams;
|
|
13
|
+
const constants_1 = require("./constants");
|
|
14
|
+
function InjectParams() {
|
|
15
|
+
return (target, key, descriptor) => {
|
|
16
|
+
const rawFunc = descriptor.value;
|
|
17
|
+
const paramMetadata = Reflect.getMetadata(constants_1.PARAM_METADATA, target[key]);
|
|
18
|
+
if (paramMetadata) {
|
|
19
|
+
descriptor.value = function (...args) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
const ctx = args[0] || {};
|
|
22
|
+
for (const paramKey in paramMetadata) {
|
|
23
|
+
if (Object.prototype.hasOwnProperty.call(paramMetadata, paramKey)) {
|
|
24
|
+
const { getter, index } = paramMetadata[paramKey];
|
|
25
|
+
switch (paramKey) {
|
|
26
|
+
case constants_1.ParamTypes.CmdContext:
|
|
27
|
+
args[index] = ctx;
|
|
28
|
+
break;
|
|
29
|
+
case constants_1.ParamTypes.Config:
|
|
30
|
+
args[index] = ctx.config;
|
|
31
|
+
break;
|
|
32
|
+
case constants_1.ParamTypes.ArgsParams:
|
|
33
|
+
args[index] = ctx.params;
|
|
34
|
+
break;
|
|
35
|
+
case constants_1.ParamTypes.ArgsOptions:
|
|
36
|
+
args[index] = ctx.options;
|
|
37
|
+
break;
|
|
38
|
+
case constants_1.ParamTypes.EnvId:
|
|
39
|
+
args[index] = ctx.envId;
|
|
40
|
+
break;
|
|
41
|
+
case constants_1.ParamTypes.IsPrivateEnv:
|
|
42
|
+
args[index] = ctx.hasPrivateSettings;
|
|
43
|
+
break;
|
|
44
|
+
default: {
|
|
45
|
+
const injectValue = yield getter(target);
|
|
46
|
+
args[index] = injectValue;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return rawFunc.apply(this, args);
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return descriptor;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createParamDecorator = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const createParamDecorator = (paramtype, getter) => {
|
|
6
|
+
return () => {
|
|
7
|
+
return (target, key, index) => {
|
|
8
|
+
const data = Reflect.getMetadata(constants_1.PARAM_METADATA, target[key]) || {};
|
|
9
|
+
Reflect.defineMetadata(constants_1.PARAM_METADATA, Object.assign(Object.assign({}, data), { [paramtype]: {
|
|
10
|
+
index,
|
|
11
|
+
getter,
|
|
12
|
+
} }), target[key]);
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
exports.createParamDecorator = createParamDecorator;
|
|
@@ -0,0 +1,29 @@
|
|
|
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.IsPrivateEnv = exports.Config = exports.EnvId = exports.ArgsParams = exports.ArgsOptions = exports.CmdContext = exports.Log = exports.Credential = void 0;
|
|
13
|
+
const cloud_toolkit_1 = require("@vectorx/cloud-toolkit");
|
|
14
|
+
const constants_1 = require("../constants");
|
|
15
|
+
const common_1 = require("./common");
|
|
16
|
+
const EmptyValue = () => { };
|
|
17
|
+
exports.Credential = (0, common_1.createParamDecorator)(constants_1.ParamTypes.Credential, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
const credential = true;
|
|
19
|
+
return credential;
|
|
20
|
+
}));
|
|
21
|
+
exports.Log = (0, common_1.createParamDecorator)(constants_1.ParamTypes.Log, () => {
|
|
22
|
+
return cloud_toolkit_1.logger;
|
|
23
|
+
});
|
|
24
|
+
exports.CmdContext = (0, common_1.createParamDecorator)(constants_1.ParamTypes.CmdContext, EmptyValue);
|
|
25
|
+
exports.ArgsOptions = (0, common_1.createParamDecorator)(constants_1.ParamTypes.ArgsOptions, EmptyValue);
|
|
26
|
+
exports.ArgsParams = (0, common_1.createParamDecorator)(constants_1.ParamTypes.ArgsParams, EmptyValue);
|
|
27
|
+
exports.EnvId = (0, common_1.createParamDecorator)(constants_1.ParamTypes.EnvId, EmptyValue);
|
|
28
|
+
exports.Config = (0, common_1.createParamDecorator)(constants_1.ParamTypes.Config, EmptyValue);
|
|
29
|
+
exports.IsPrivateEnv = (0, common_1.createParamDecorator)(constants_1.ParamTypes.IsPrivateEnv, EmptyValue);
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./main"), exports);
|
package/lib/main.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
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.registerCommands = registerCommands;
|
|
13
|
+
require("reflect-metadata");
|
|
14
|
+
const base_1 = require("./core/base");
|
|
15
|
+
require("./commands");
|
|
16
|
+
function registerCommands() {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
base_1.registrableCommands.forEach(({ Command }) => new Command().init());
|
|
19
|
+
});
|
|
20
|
+
}
|
package/lib/output.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vectorx/xhs-cloud-cli",
|
|
3
|
+
"version": "0.0.0-beta-20251112071234",
|
|
4
|
+
"description": "xhs-cloud-cli 主要用于如下场景: - agent 调试、发布 - cloud 云函数的调试、部署",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "types/index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"rcb": "./bin/rcb.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"bin",
|
|
12
|
+
"lib",
|
|
13
|
+
"templates",
|
|
14
|
+
"README.md",
|
|
15
|
+
"types"
|
|
16
|
+
],
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@koa/router": "^12.0.1",
|
|
19
|
+
"@vectorx/agent-simulator": "0.0.0-beta-20251112071234",
|
|
20
|
+
"@vectorx/cloud-toolkit": "0.0.0-beta-20251112071234",
|
|
21
|
+
"@vectorx/functions-framework": "0.0.0-beta-20251112071234",
|
|
22
|
+
"address": "^1.1.2",
|
|
23
|
+
"archiver": "^6.0.1",
|
|
24
|
+
"camelcase-keys": "^7.0.2",
|
|
25
|
+
"chalk": "^2.4.2",
|
|
26
|
+
"cli-table3": "^0.5.1",
|
|
27
|
+
"commander": "7",
|
|
28
|
+
"cos-nodejs-sdk-v5": "^2.16.0-beta.3",
|
|
29
|
+
"crypto": "^1.0.1",
|
|
30
|
+
"dayjs": "^1.11.13",
|
|
31
|
+
"del": "^5.1.0",
|
|
32
|
+
"didyoumean": "^1.2.2",
|
|
33
|
+
"enquirer": "^2.3.6",
|
|
34
|
+
"execa": "^4.0.3",
|
|
35
|
+
"fs-extra": "^8.1.0",
|
|
36
|
+
"https-proxy-agent": "^5.0.1",
|
|
37
|
+
"inquirer": "^6.5.0",
|
|
38
|
+
"inversify": "^7.5.2",
|
|
39
|
+
"json-schema-to-typescript": "^14.0.5",
|
|
40
|
+
"koa": "^2.16.1",
|
|
41
|
+
"koa-body": "^6.0.1",
|
|
42
|
+
"koa-bodyparser": "^4.4.1",
|
|
43
|
+
"langfuse": "^3.38.4",
|
|
44
|
+
"lodash": "^4.17.21",
|
|
45
|
+
"log-symbols": "^3.0.0",
|
|
46
|
+
"lowdb": "^1.0.0",
|
|
47
|
+
"make-dir": "^3.0.0",
|
|
48
|
+
"node-fetch": "^2.6.0",
|
|
49
|
+
"nodemon": "^3.1.4",
|
|
50
|
+
"open": "^7.4.2",
|
|
51
|
+
"ora": "^4.0.2",
|
|
52
|
+
"portfinder": "^1.0.28",
|
|
53
|
+
"progress": "^2.0.3",
|
|
54
|
+
"query-string": "^6.8.1",
|
|
55
|
+
"raw-body": "^3.0.0",
|
|
56
|
+
"read-pkg-up": "^9.1.0",
|
|
57
|
+
"reflect-metadata": "^0.1.14",
|
|
58
|
+
"semver": "^7.3.7",
|
|
59
|
+
"tar-fs": "^2.0.1",
|
|
60
|
+
"terminal-link": "^2.1.1",
|
|
61
|
+
"unzipper": "^0.10.10",
|
|
62
|
+
"update-notifier": "^4.0.0",
|
|
63
|
+
"uuid": "^11.1.0",
|
|
64
|
+
"vscode": "^1.1.37",
|
|
65
|
+
"ws": "^8.18.2",
|
|
66
|
+
"xdg-basedir": "^4.0.0",
|
|
67
|
+
"yargs": "^16.2.0",
|
|
68
|
+
"yargs-parser": "^21.0.1"
|
|
69
|
+
},
|
|
70
|
+
"devDependencies": {
|
|
71
|
+
"@types/archiver": "^5.3.2",
|
|
72
|
+
"@types/fs-extra": "^11.0.4",
|
|
73
|
+
"@types/inquirer": "^9.0.8",
|
|
74
|
+
"@types/jest": "^27",
|
|
75
|
+
"@types/koa": "^2.13.12",
|
|
76
|
+
"@types/koa-bodyparser": "^4.3.12",
|
|
77
|
+
"@types/koa__router": "^8.0.11",
|
|
78
|
+
"@types/lodash": "^4.14.182",
|
|
79
|
+
"@types/node": "^12.12.38",
|
|
80
|
+
"@types/node-fetch": "^2.5.4",
|
|
81
|
+
"@types/read-pkg-up": "^6.0.0",
|
|
82
|
+
"@types/semver": "^7.3.9",
|
|
83
|
+
"@types/webpack-dev-server": "^3.11.1",
|
|
84
|
+
"@typescript-eslint/eslint-plugin": "^4.8.1",
|
|
85
|
+
"@typescript-eslint/parser": "^4.8.1",
|
|
86
|
+
"eslint": "^7.14.0",
|
|
87
|
+
"eslint-config-alloy": "^3.8.2",
|
|
88
|
+
"husky": "^3.0.9",
|
|
89
|
+
"jest": "^27",
|
|
90
|
+
"ts-jest": "^27",
|
|
91
|
+
"typescript": "^5.8.3"
|
|
92
|
+
},
|
|
93
|
+
"keywords": [],
|
|
94
|
+
"author": "",
|
|
95
|
+
"license": "ISC",
|
|
96
|
+
"scripts": {
|
|
97
|
+
"cli:dev": "cross-env ENABLE_FETCH_PROXY=true http_proxy=http://127.0.0.1:8899 https_proxy=http://127.0.0.1:8899 NODE_TLS_REJECT_UNAUTHORIZED=0 NODE_ENV=development HOST=0.0.0.0 PORT=1111 bin/rcb.js login --secretId de1wD91R5zWj46E8fepxFDw --secretKey qP3qUFb0BJbZDRft64ZMu96ey7O8aic6",
|
|
98
|
+
"build": "rimraf lib types && tsc --resolveJsonModule",
|
|
99
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
100
|
+
"dev": "rimraf lib types && tsc -w",
|
|
101
|
+
"gen:command": "ts-node scripts/generate-command.ts"
|
|
102
|
+
},
|
|
103
|
+
"readme": "# xhs cloud 命令行工具\nxhs-cloud-cli 主要用于如下场景:\n - agent 调试、发布\n - cloud 云函数的调试、部署\n\n使用方式:\n - xhs-cloud-cli agent dev \n\n - xhs-cloud-cli cloud dev\n\n## 安装 CloudBase CLI\n\nsrc/\n├── commands/\n│ └── agent/\n│ └── dev.ts # agent dev 命令实现\n├── core/\n│ └── server/\n│ ├── server.node.ts # Koa 服务器实现\n│ └── function-loader.ts # 函数加载器实现\n\n### npm\n\n```shell\nnpm install -g @cloudbase/cli\n```\n\n## 命令\n> xhs-cloud-cli\n\n## 命令\n- deploy\n- dev\n\n"
|
|
104
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const { AgentRuntime, AgentDriver } = require("@vectorx/agent-runtime");
|
|
2
|
+
|
|
3
|
+
let test_answer = "你好,我是开放平台智能体,我可以为你做很多事情";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {import('@vectorx/agent-runtime').IAgent} IAgent
|
|
7
|
+
*
|
|
8
|
+
* @class
|
|
9
|
+
* @implements {IAgent}
|
|
10
|
+
*/
|
|
11
|
+
class MyAgent extends AgentRuntime {
|
|
12
|
+
async sendMessage(message) {
|
|
13
|
+
console.log("==== message ====", JSON.stringify(message, null, 2));
|
|
14
|
+
return new Promise((res) => {
|
|
15
|
+
const charArr = test_answer.split("")
|
|
16
|
+
|
|
17
|
+
let id = new Date().getTime()
|
|
18
|
+
const interval = setInterval(() => {
|
|
19
|
+
const char = charArr.shift();
|
|
20
|
+
|
|
21
|
+
if (typeof char === "string") {
|
|
22
|
+
this.sseSender.send({
|
|
23
|
+
data: {
|
|
24
|
+
id,
|
|
25
|
+
object: "chat.completion",
|
|
26
|
+
created: new Date().getTime(),
|
|
27
|
+
model: "test",
|
|
28
|
+
choices: [
|
|
29
|
+
{
|
|
30
|
+
message: {
|
|
31
|
+
role: "assistant",
|
|
32
|
+
type: "answer",
|
|
33
|
+
content: char
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
} else {
|
|
40
|
+
clearInterval(interval);
|
|
41
|
+
this.sseSender.end();
|
|
42
|
+
res();
|
|
43
|
+
}
|
|
44
|
+
}, 50);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
exports.main = function (event, context) {
|
|
50
|
+
return AgentDriver.run(event, context, new MyAgent(context));
|
|
51
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
const { AgentRuntime, AgentDriver } = require("@vectorx/agent-runtime");
|
|
2
|
+
|
|
3
|
+
class AgentSSE extends AgentRuntime {
|
|
4
|
+
async sendMessage(input) {
|
|
5
|
+
try {
|
|
6
|
+
let conversation_id = ''
|
|
7
|
+
|
|
8
|
+
const result = await this.getConversations()
|
|
9
|
+
if (result.code === 0 && result.data) {
|
|
10
|
+
const { conversations } = result.data
|
|
11
|
+
if (conversations && conversations.length) {
|
|
12
|
+
conversation_id = conversations[conversations.length - 1].id
|
|
13
|
+
} else {
|
|
14
|
+
conversation_id = ''
|
|
15
|
+
}
|
|
16
|
+
} else {
|
|
17
|
+
conversation_id = ''
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const { data: { message_list }} = await this.getMessageList(conversation_id)
|
|
21
|
+
|
|
22
|
+
message_list.push({
|
|
23
|
+
role: 'user',
|
|
24
|
+
content: input.message.content
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
message_list.push({
|
|
28
|
+
role: 'assistant',
|
|
29
|
+
content: '你好,我是AI助手,很高兴为你服务。'
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
const model = this.createModel('deepseek-r1')
|
|
33
|
+
const modelResponse = await model.streamText({
|
|
34
|
+
messages: [
|
|
35
|
+
{
|
|
36
|
+
role: 'user',
|
|
37
|
+
content: {
|
|
38
|
+
type: 'text',
|
|
39
|
+
content: input.message.content
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
let assistant_output = ''
|
|
46
|
+
let reasoningContent = ''
|
|
47
|
+
|
|
48
|
+
for await (const chunk of modelResponse) {
|
|
49
|
+
if (chunk.choices[0].message.content) {
|
|
50
|
+
assistant_output += chunk.choices[0].message.content
|
|
51
|
+
}
|
|
52
|
+
if (chunk.choices[0].message.reasoning_content) {
|
|
53
|
+
reasoningContent += chunk.choices[0].message.reasoning_content
|
|
54
|
+
}
|
|
55
|
+
this.sseSender.send({ data: chunk });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
this.sseSender.end();
|
|
59
|
+
|
|
60
|
+
await this.createRecordPair({
|
|
61
|
+
conversation_id,
|
|
62
|
+
user_input: {
|
|
63
|
+
role: 'user',
|
|
64
|
+
content: input.message.content
|
|
65
|
+
},
|
|
66
|
+
assistant_output: {
|
|
67
|
+
role: 'assistant',
|
|
68
|
+
content: assistant_output,
|
|
69
|
+
reasoningContent: assistant_output
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
} catch (e) {
|
|
74
|
+
console.log("开发者 agent 捕获到错误", e);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async getMessageList(conversation_id) {
|
|
79
|
+
const historyMessages = await this.getHistoryMessages({
|
|
80
|
+
conversation_id,
|
|
81
|
+
cursor: 0,
|
|
82
|
+
count: 5,
|
|
83
|
+
sort: 'desc'
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
return historyMessages
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
exports.main = async (event, context) => {
|
|
91
|
+
return AgentDriver.run(event, context, new AgentSSE(context));
|
|
92
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type Logger } from "@vectorx/cloud-toolkit";
|
|
2
|
+
import { Command } from "../../core/base";
|
|
3
|
+
export declare class AgentBuildCommand extends Command {
|
|
4
|
+
execute(options: any, log: Logger): Promise<void>;
|
|
5
|
+
get options(): {
|
|
6
|
+
cmd: string;
|
|
7
|
+
childCmd: string;
|
|
8
|
+
desc: string;
|
|
9
|
+
options: {
|
|
10
|
+
flags: string;
|
|
11
|
+
desc: string;
|
|
12
|
+
}[];
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export declare class AgentDeployCommand extends Command {
|
|
16
|
+
execute(options: any, log: Logger): Promise<void>;
|
|
17
|
+
get options(): {
|
|
18
|
+
cmd: string;
|
|
19
|
+
childCmd: string;
|
|
20
|
+
desc: string;
|
|
21
|
+
options: {
|
|
22
|
+
flags: string;
|
|
23
|
+
desc: string;
|
|
24
|
+
}[];
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Logger } from "@vectorx/cloud-toolkit";
|
|
2
|
+
import { Command } from "../../core/base";
|
|
3
|
+
export declare class AgentDevCommand extends Command {
|
|
4
|
+
execute(options: any, log: Logger): Promise<void>;
|
|
5
|
+
private setupProcessCleanup;
|
|
6
|
+
get options(): {
|
|
7
|
+
cmd: string;
|
|
8
|
+
childCmd: string;
|
|
9
|
+
desc: string;
|
|
10
|
+
options: {
|
|
11
|
+
flags: string;
|
|
12
|
+
desc: string;
|
|
13
|
+
}[];
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Logger } from "@vectorx/cloud-toolkit";
|
|
2
|
+
import { Command } from "../../core/base";
|
|
3
|
+
export declare class AgentNewCommand extends Command {
|
|
4
|
+
execute(options: any, log: Logger): Promise<void>;
|
|
5
|
+
private copyTemplate;
|
|
6
|
+
get options(): {
|
|
7
|
+
cmd: string;
|
|
8
|
+
childCmd: string;
|
|
9
|
+
desc: string;
|
|
10
|
+
usage: string;
|
|
11
|
+
options: {
|
|
12
|
+
flags: string;
|
|
13
|
+
desc: string;
|
|
14
|
+
}[];
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Command, type ICommandOptions } from "../../core/base";
|
|
2
|
+
export declare class LoginCommand extends Command {
|
|
3
|
+
private authService;
|
|
4
|
+
constructor();
|
|
5
|
+
execute(ctx: any): Promise<void>;
|
|
6
|
+
get options(): ICommandOptions;
|
|
7
|
+
}
|
|
8
|
+
export declare class GetLoginInfoCommand extends Command {
|
|
9
|
+
private authService;
|
|
10
|
+
constructor();
|
|
11
|
+
execute(ctx: any): Promise<void>;
|
|
12
|
+
get options(): ICommandOptions;
|
|
13
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export declare const registrableCommands: {
|
|
2
|
+
Command: CommandConstructor;
|
|
3
|
+
}[];
|
|
4
|
+
export interface ICloudBaseConfig {
|
|
5
|
+
functionRoot?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function ICommand(): ClassDecorator;
|
|
8
|
+
export interface ICommandContext {
|
|
9
|
+
cmd: string;
|
|
10
|
+
envId: string;
|
|
11
|
+
config: ICloudBaseConfig;
|
|
12
|
+
options: any;
|
|
13
|
+
params: string[];
|
|
14
|
+
hasPrivateSettings: boolean;
|
|
15
|
+
}
|
|
16
|
+
export type CommandConstructor = new () => Command;
|
|
17
|
+
interface ICommandOption {
|
|
18
|
+
flags: string;
|
|
19
|
+
desc: string;
|
|
20
|
+
hideHelp?: boolean;
|
|
21
|
+
required?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface ICommandOptions {
|
|
24
|
+
deprecateCmd?: string;
|
|
25
|
+
cmd: string;
|
|
26
|
+
childCmd?: string | {
|
|
27
|
+
cmd: string;
|
|
28
|
+
desc: string;
|
|
29
|
+
};
|
|
30
|
+
childSubCmd?: string;
|
|
31
|
+
options: ICommandOption[];
|
|
32
|
+
desc: string;
|
|
33
|
+
}
|
|
34
|
+
export declare abstract class Command {
|
|
35
|
+
init(): void;
|
|
36
|
+
private createProgram;
|
|
37
|
+
abstract execute(...args: any[]): void;
|
|
38
|
+
abstract get options(): ICommandOptions;
|
|
39
|
+
}
|
|
40
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function AuthGuard(): ClassDecorator;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const CaptureError: () => MethodDecorator;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const PARAM_METADATA = "PARAM_METADATA";
|
|
2
|
+
export declare enum ParamTypes {
|
|
3
|
+
Credential = "__Credential__",
|
|
4
|
+
Log = "__Log__",
|
|
5
|
+
CmdContext = "__CmdContext__",
|
|
6
|
+
EnvId = "__EnvId__",
|
|
7
|
+
Config = "__Config__",
|
|
8
|
+
ArgsOptions = "__ArgsOptions__",
|
|
9
|
+
ArgsParams = "__ArgsParams__",
|
|
10
|
+
IsPrivateEnv = "__ISPrivateEnv__"
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function InjectParams(): MethodDecorator;
|