@vectorx/xhs-cloud-cli 1.0.1 → 1.1.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.
Files changed (73) hide show
  1. package/lib/commands/agent/dev.js +40 -8
  2. package/lib/commands/agent/index.js +2 -0
  3. package/lib/commands/agent/info.js +107 -0
  4. package/lib/commands/agent/list.js +95 -0
  5. package/lib/commands/agent/new.js +32 -6
  6. package/lib/commands/auth/login.js +53 -38
  7. package/lib/commands/env/info.js +3 -1
  8. package/lib/commands/env/set.js +3 -1
  9. package/lib/commands/fun/deploy.js +3 -1
  10. package/lib/commands/fun/dev.js +9 -3
  11. package/lib/commands/fun/new.js +32 -6
  12. package/lib/core/base.js +9 -1
  13. package/lib/decorators/auth.js +2 -1
  14. package/lib/main.js +3 -1
  15. package/lib/utils/agent-check.js +158 -0
  16. package/lib/utils/templates.js +75 -0
  17. package/package.json +10 -8
  18. package/templates/cloud-agents/agent-base-template/project.config.json +6 -0
  19. package/templates/{chatbox-agent → cloud-agents/agent-base-template}/src/index.js +0 -1
  20. package/templates/cloud-agents/agent-doc-template/.env.template +1 -0
  21. package/templates/cloud-agents/agent-doc-template/agent-cloudbase-functions.json +11 -0
  22. package/templates/cloud-agents/agent-doc-template/package.json +11 -0
  23. package/templates/cloud-agents/agent-doc-template/project.config.json +6 -0
  24. package/templates/cloud-agents/agent-doc-template/src/index.js +68 -0
  25. package/templates/cloud-agents/agent-image-template/.env.template +1 -0
  26. package/templates/cloud-agents/agent-image-template/agent-cloudbase-functions.json +11 -0
  27. package/templates/cloud-agents/agent-image-template/package.json +11 -0
  28. package/templates/cloud-agents/agent-image-template/project.config.json +6 -0
  29. package/templates/cloud-agents/agent-image-template/src/index.js +56 -0
  30. package/templates/cloud-agents/agent-text-template/.env.template +1 -0
  31. package/templates/cloud-agents/agent-text-template/agent-cloudbase-functions.json +11 -0
  32. package/templates/cloud-agents/agent-text-template/package.json +11 -0
  33. package/templates/cloud-agents/agent-text-template/project.config.json +6 -0
  34. package/templates/cloud-agents/agent-text-template/src/index.js +38 -0
  35. package/templates/cloud-agents/agent-voice-template/.env.template +1 -0
  36. package/templates/cloud-agents/agent-voice-template/agent-cloudbase-functions.json +11 -0
  37. package/templates/cloud-agents/agent-voice-template/package.json +11 -0
  38. package/templates/cloud-agents/agent-voice-template/project.config.json +6 -0
  39. package/templates/cloud-agents/agent-voice-template/src/index.js +81 -0
  40. package/templates/cloud-agents/templates.json +9 -0
  41. package/templates/cloud-dev/templates.json +6 -0
  42. package/types/commands/agent/index.d.ts +2 -0
  43. package/types/commands/agent/info.d.ts +14 -0
  44. package/types/commands/agent/list.d.ts +14 -0
  45. package/types/commands/auth/login.d.ts +2 -0
  46. package/types/utils/agent-check.d.ts +1 -0
  47. package/types/utils/templates.d.ts +17 -0
  48. package/templates/chatbox-agent/project.config.json +0 -5
  49. package/templates/weather-agent/index.js +0 -92
  50. package/templates/weather-agent/project.config.json +0 -4
  51. /package/templates/{chatbox-agent → cloud-agents/agent-base-template}/.env.template +0 -0
  52. /package/templates/{chatbox-agent → cloud-agents/agent-base-template}/agent-cloudbase-functions.json +0 -0
  53. /package/templates/{chatbox-agent → cloud-agents/agent-base-template}/package.json +0 -0
  54. /package/templates/{ai-cloud-functions-example → cloud-dev/cloudfunction-route-template}/.env.template +0 -0
  55. /package/templates/{ai-cloud-functions-example → cloud-dev/cloudfunction-route-template}/README.md +0 -0
  56. /package/templates/{ai-cloud-functions-example → cloud-dev/cloudfunction-route-template}/agent-cloudbase-functions.json +0 -0
  57. /package/templates/{ai-cloud-functions-example → cloud-dev/cloudfunction-route-template}/package.json +0 -0
  58. /package/templates/{ai-cloud-functions-example → cloud-dev/cloudfunction-route-template}/src/binary/index.js +0 -0
  59. /package/templates/{ai-cloud-functions-example → cloud-dev/cloudfunction-route-template}/src/context/context-service.js +0 -0
  60. /package/templates/{ai-cloud-functions-example → cloud-dev/cloudfunction-route-template}/src/context/index.js +0 -0
  61. /package/templates/{ai-cloud-functions-example → cloud-dev/cloudfunction-route-template}/src/env/index.js +0 -0
  62. /package/templates/{ai-cloud-functions-example → cloud-dev/cloudfunction-route-template}/src/form/index.js +0 -0
  63. /package/templates/{ai-cloud-functions-example → cloud-dev/cloudfunction-route-template}/src/index.js +0 -0
  64. /package/templates/{ai-cloud-functions-example → cloud-dev/cloudfunction-route-template}/src/json/index.js +0 -0
  65. /package/templates/{ai-cloud-functions-example → cloud-dev/cloudfunction-route-template}/src/multipart/index.js +0 -0
  66. /package/templates/{ai-cloud-functions-example → cloud-dev/cloudfunction-route-template}/src/text/index.js +0 -0
  67. /package/templates/{ai-cloud-functions-example → cloud-dev/cloudfunction-route-template}/src/user/index.js +0 -0
  68. /package/templates/{cloudfunction-template → cloud-dev/cloudfunction-template}/.env.template +0 -0
  69. /package/templates/{cloudfunction-template → cloud-dev/cloudfunction-template}/agent-cloudbase-functions.json +0 -0
  70. /package/templates/{cloudfunction-template → cloud-dev/cloudfunction-template}/package.json +0 -0
  71. /package/templates/{cloudfunction-template → cloud-dev/cloudfunction-template}/project.config.json +0 -0
  72. /package/templates/{cloudfunction-template → cloud-dev/cloudfunction-template}/src/echo.js +0 -0
  73. /package/templates/{cloudfunction-template → cloud-dev/cloudfunction-template}/src/index.js +0 -0
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "[从开放平台获取]",
3
+ "agentId": "[从开放平台获取]",
4
+ "desc": "文本模型智能体(最简版)",
5
+ "version": "0.0.1"
6
+ }
@@ -0,0 +1,38 @@
1
+ const { AgentRuntime, AgentDriver } = require("@vectorx/agent-runtime");
2
+
3
+ const systemPrompt = `你是一个友好的 AI 助手,用简洁清晰的语言回答用户问题。`;
4
+
5
+ class TextAgent extends AgentRuntime {
6
+ async sendMessage(input) {
7
+ try {
8
+ const userMsg = typeof input.msg === "string" ? input.msg : JSON.stringify(input.msg || "");
9
+ const model = this.createModel("qwen-plus");
10
+ const textStream = await model.streamText({
11
+ messages: [
12
+ { role: "system", content: systemPrompt },
13
+ { role: "user", content: [{ type: "text", text: userMsg }] },
14
+ ],
15
+ });
16
+
17
+ for await (const chunk of textStream) {
18
+ this.sseSender.send({ data: chunk });
19
+ }
20
+ } catch (e) {
21
+ console.error("TextAgent error:", e);
22
+ this.sseSender.send({
23
+ data: {
24
+ choices: [{
25
+ message: { role: "assistant", type: "error", content: "处理出错:" + (e?.message || "Unknown") },
26
+ finish_reason: "error",
27
+ }],
28
+ },
29
+ });
30
+ } finally {
31
+ this.sseSender.end();
32
+ }
33
+ }
34
+ }
35
+
36
+ exports.main = (event, context) => {
37
+ return AgentDriver.run(event, context, new TextAgent(context));
38
+ };
@@ -0,0 +1 @@
1
+ # 环境变量模板,复制为 .env 后填写
@@ -0,0 +1,11 @@
1
+ {
2
+ "functionsRoot": "./src",
3
+ "functions": [
4
+ {
5
+ "triggerPath": "/",
6
+ "name": "main",
7
+ "directory": "./",
8
+ "source": "index.js"
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "version": "1.0.0",
3
+ "description": "语音合成智能体模板(最简版)",
4
+ "scripts": {
5
+ "dev": "rcb-ff"
6
+ },
7
+ "dependencies": {
8
+ "@vectorx/agent-runtime": "latest",
9
+ "@vectorx/functions-framework": "latest"
10
+ }
11
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "[从开放平台获取]",
3
+ "agentId": "[从开放平台获取]",
4
+ "desc": "语音合成智能体(最简版)",
5
+ "version": "0.0.1"
6
+ }
@@ -0,0 +1,81 @@
1
+ const { AgentRuntime, AgentDriver } = require("@vectorx/agent-runtime");
2
+
3
+ const SYSTEM_PROMPT = `你是一个语音助手,用简洁清晰的语言回答用户问题。回答控制在 100 字以内,适合语音朗读。不要使用 Markdown 格式、代码块或特殊符号。`;
4
+
5
+ const TTS_VOICE = "longhouge_v3";
6
+ const TTS_MODEL = "cosyvoice-v3-flash";
7
+ const TTS_FORMAT = "mp3";
8
+
9
+ class VoiceAgent extends AgentRuntime {
10
+ async sendMessage(input) {
11
+ const userMsg = typeof input.msg === "string" ? input.msg : JSON.stringify(input.msg || "");
12
+
13
+ try {
14
+ // 1. 流式生成文本
15
+ const fullText = await this.streamTextResponse(userMsg);
16
+ if (!fullText) return;
17
+
18
+ // 2. TTS 合成语音
19
+ const ttsModel = this.createModel(TTS_MODEL);
20
+ const result = await ttsModel.generateSpeech({
21
+ text: fullText,
22
+ voice: TTS_VOICE,
23
+ format: TTS_FORMAT,
24
+ });
25
+
26
+ // 3. 发送音频 SSE 消息
27
+ const audioBase64 = result.audio.toString("base64");
28
+ this.sseSender.send({
29
+ data: {
30
+ choices: [{
31
+ message: {
32
+ role: "assistant",
33
+ type: "audio",
34
+ content: `data:audio/${TTS_FORMAT};base64,${audioBase64}`,
35
+ metadata: { model: TTS_MODEL, voice: TTS_VOICE },
36
+ },
37
+ finish_reason: "stop",
38
+ }],
39
+ },
40
+ });
41
+ } catch (error) {
42
+ console.error("[VoiceAgent] Error:", error);
43
+ this.sseSender.send({
44
+ data: {
45
+ choices: [{
46
+ message: {
47
+ role: "assistant",
48
+ type: "error",
49
+ content: "语音合成出错:" + (error?.message || "Unknown"),
50
+ },
51
+ finish_reason: "error",
52
+ }],
53
+ },
54
+ });
55
+ } finally {
56
+ this.sseSender.end();
57
+ }
58
+ }
59
+
60
+ async streamTextResponse(userMsg) {
61
+ const textModel = this.createModel("qwen-plus");
62
+ const textStream = await textModel.streamText({
63
+ messages: [
64
+ { role: "system", content: SYSTEM_PROMPT },
65
+ { role: "user", content: [{ type: "text", text: userMsg }] },
66
+ ],
67
+ });
68
+
69
+ let fullText = "";
70
+ for await (const chunk of textStream) {
71
+ this.sseSender.send({ data: chunk });
72
+ const delta = chunk.choices?.[0]?.delta?.content || chunk.choices?.[0]?.message?.content || "";
73
+ fullText += delta;
74
+ }
75
+ return fullText;
76
+ }
77
+ }
78
+
79
+ exports.main = (event, context) => {
80
+ return AgentDriver.run(event, context, new VoiceAgent(context));
81
+ };
@@ -0,0 +1,9 @@
1
+ {
2
+ "templates": [
3
+ { "id": "agent-base-template", "name": "基础智能体", "desc": "默认智能体模板" },
4
+ { "id": "agent-text-template", "name": "文本模型", "desc": "文本模型智能体(最简版)" },
5
+ { "id": "agent-voice-template", "name": "语音合成", "desc": "语音合成智能体(最简版)" },
6
+ { "id": "agent-image-template", "name": "文生图", "desc": "文生图智能体(最简版)" },
7
+ { "id": "agent-doc-template", "name": "文档理解", "desc": "文档理解智能体(最简版)" }
8
+ ]
9
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "templates": [
3
+ { "id": "cloudfunction-template", "name": "基础云函数", "desc": "智能体 + 云函数模板" },
4
+ { "id": "cloudfunction-route-template", "name": "多路由云函数", "desc": "支持多种触发方式的云函数示例" }
5
+ ]
6
+ }
@@ -1,3 +1,5 @@
1
1
  export * from "./dev";
2
2
  export * from "./build";
3
3
  export * from "./new";
4
+ export * from "./list";
5
+ export * from "./info";
@@ -0,0 +1,14 @@
1
+ import type { Logger } from "@vectorx/cloud-toolkit";
2
+ import { Command } from "../../core/base";
3
+ export declare class AgentInfoCommand 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
+ }
@@ -0,0 +1,14 @@
1
+ import type { Logger } from "@vectorx/cloud-toolkit";
2
+ import { Command } from "../../core/base";
3
+ export declare class AgentListCommand 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
+ }
@@ -1,12 +1,14 @@
1
1
  import { Command, type ICommandOptions } from "../../core/base";
2
2
  export declare class LoginCommand extends Command {
3
3
  private authService;
4
+ private cloudDevService;
4
5
  constructor();
5
6
  execute(ctx: any): Promise<void>;
6
7
  get options(): ICommandOptions;
7
8
  }
8
9
  export declare class GetLoginInfoCommand extends Command {
9
10
  private authService;
11
+ private cloudDevService;
10
12
  constructor();
11
13
  execute(ctx: any): Promise<void>;
12
14
  get options(): ICommandOptions;
@@ -0,0 +1 @@
1
+ export declare function checkAndGuideAgentProject(workDir: string): Promise<string | undefined>;
@@ -0,0 +1,17 @@
1
+ export interface TemplateEntry {
2
+ id: string;
3
+ name: string;
4
+ desc: string;
5
+ }
6
+ export interface TemplatesConfig {
7
+ templates: TemplateEntry[];
8
+ }
9
+ export declare const TEMPLATE_CATEGORIES: {
10
+ readonly "cloud-agents": string;
11
+ readonly "cloud-dev": string;
12
+ };
13
+ export declare function loadTemplatesConfig(category: keyof typeof TEMPLATE_CATEGORIES): TemplateEntry[];
14
+ export declare function resolveTemplatePath(category: keyof typeof TEMPLATE_CATEGORIES, templateId: string): string;
15
+ export declare function selectTemplate(category: keyof typeof TEMPLATE_CATEGORIES, options: {
16
+ template?: string;
17
+ }): Promise<string>;
@@ -1,5 +0,0 @@
1
- {
2
- "agentId": "[从开放平台获取]",
3
- "version": "0.0.1",
4
- "desc": "[从开放平台获取]"
5
- }
@@ -1,92 +0,0 @@
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
- };
@@ -1,4 +0,0 @@
1
- {
2
- "agentId": "xhs1234567890",
3
- "version": "0.0.1"
4
- }