@vectorx/agent-runtime 0.1.2 → 0.3.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.
@@ -9,4 +9,5 @@ export declare class AgentDriver {
9
9
  private getHistoryMessagesFunc;
10
10
  private getAgentInfoFunc;
11
11
  private getConversationsFunc;
12
+ private queryTasksFunc;
12
13
  }
@@ -30,6 +30,7 @@ class AgentDriver {
30
30
  }
31
31
  const apiFuncs = {
32
32
  "POST:send-message": this.sendMessageFunc.bind(this),
33
+ "GET:query-tasks": this.queryTasksFunc.bind(this),
33
34
  "GET:messages": this.getHistoryMessagesFunc.bind(this),
34
35
  "GET:info": this.getAgentInfoFunc.bind(this),
35
36
  "GET:conversations": this.getConversationsFunc.bind(this),
@@ -90,5 +91,21 @@ class AgentDriver {
90
91
  }
91
92
  });
92
93
  }
94
+ queryTasksFunc(event, context) {
95
+ return __awaiter(this, void 0, void 0, function* () {
96
+ var _a, _b;
97
+ try {
98
+ const pathTaskId = (0, agent_helper_1.parseTaskIdFromPath)(context.httpContext.url);
99
+ const query = (0, agent_helper_1.parseQueryFromCtx)(context);
100
+ const parsed = schema_1.queryTasksParamsSchema.passthrough().parse({
101
+ task_id: query.task_id || pathTaskId,
102
+ });
103
+ return yield ((_b = (_a = this.agent).queryTasks) === null || _b === void 0 ? void 0 : _b.call(_a, parsed.task_id));
104
+ }
105
+ catch (e) {
106
+ return (0, integration_response_1.createIntegrationResponse)(500, codes_1.CODES.AGENT_API_ERROR, `Agent API 'queryTasks' failed, message: ${e}`);
107
+ }
108
+ });
109
+ }
93
110
  }
94
111
  exports.AgentDriver = AgentDriver;
@@ -79,3 +79,24 @@ export interface GetAgentInfoResponse {
79
79
  agentInfo: AgentInfo;
80
80
  };
81
81
  }
82
+ export interface QueryTasksData {
83
+ request_id: string;
84
+ output: {
85
+ task_id: string;
86
+ task_status: "PENDING" | "RUNNING" | "SUCCEEDED" | "FAILED" | "CANCELED" | "UNKNOWN";
87
+ results?: Array<{
88
+ url?: string;
89
+ [key: string]: any;
90
+ }>;
91
+ task_metrics?: {
92
+ TOTAL: number;
93
+ SUCCEEDED: number;
94
+ FAILED: number;
95
+ };
96
+ };
97
+ usage?: {
98
+ image_count?: number;
99
+ };
100
+ }
101
+ export type RawQueryTasksResponse = QueryTasksData;
102
+ export type QueryTasksResponse = BaseResponse<QueryTasksData>;
@@ -1,6 +1,6 @@
1
1
  import { type AI, type models } from "@vectorx/ai-sdk";
2
2
  import { type RcbContext } from "@vectorx/functions-framework";
3
- import type { CreateRecordPairResponse, GetAgentInfoResponse, GetConversationsResponse, GetHistoryMessagesResponse, KnowledgeBaseRetrieveResponse } from "./agent-types";
3
+ import type { CreateRecordPairResponse, GetAgentInfoResponse, GetConversationsResponse, GetHistoryMessagesResponse, KnowledgeBaseRetrieveResponse, QueryTasksResponse } from "./agent-types";
4
4
  import { type CreateRecordPairParams, type GetHistoryMessagesParams, type KnowledgeSearchInput } from "./schema";
5
5
  import { SSESender } from "./sse-sender";
6
6
  export declare enum AgentType {
@@ -11,7 +11,8 @@ export declare enum AgentType {
11
11
  AI_SDK_CREATE_RECORD_PAIR = "AI_SDK_CREATE_RECORD_PAIR",
12
12
  AI_SDK_GET_HISTORY_MESSAGES = "AI_SDK_GET_HISTORY_MESSAGES",
13
13
  AI_SDK_GET_CONVERSATIONS = "AI_SDK_GET_CONVERSATIONS",
14
- Ai_SDK_POST_KNOWLEDGE_BASE = "Ai_SDK_POST_KNOWLEDGE_BASE"
14
+ Ai_SDK_POST_KNOWLEDGE_BASE = "Ai_SDK_POST_KNOWLEDGE_BASE",
15
+ AI_SDK_QUERY_TASKS = "AI_SDK_QUERY_TASKS"
15
16
  }
16
17
  export declare enum AgentEventType {
17
18
  FRAMEWORK_EVENT = "FRAMEWORK_EVENT",
@@ -28,10 +29,11 @@ export declare class AgentRuntime {
28
29
  get version(): string;
29
30
  constructor(context: RcbContext);
30
31
  private createLoggedRequest;
31
- protected createModel(modelName: models.ModelName): models.ReactModel;
32
+ protected createModel(modelName: models.ModelName): models.ReActModel;
32
33
  protected createRecordPair(params: CreateRecordPairParams): Promise<CreateRecordPairResponse>;
33
34
  protected getHistoryMessages(params: GetHistoryMessagesParams): Promise<GetHistoryMessagesResponse>;
34
35
  protected getConversations(): Promise<GetConversationsResponse>;
35
36
  getAgentInfo(): Promise<GetAgentInfoResponse>;
36
37
  knowledgeBaseRetrieve(params: KnowledgeSearchInput): Promise<KnowledgeBaseRetrieveResponse>;
38
+ queryTasks(task_id?: string): Promise<QueryTasksResponse>;
37
39
  }
package/lib/agent.js CHANGED
@@ -25,6 +25,7 @@ var AgentType;
25
25
  AgentType["AI_SDK_GET_HISTORY_MESSAGES"] = "AI_SDK_GET_HISTORY_MESSAGES";
26
26
  AgentType["AI_SDK_GET_CONVERSATIONS"] = "AI_SDK_GET_CONVERSATIONS";
27
27
  AgentType["Ai_SDK_POST_KNOWLEDGE_BASE"] = "Ai_SDK_POST_KNOWLEDGE_BASE";
28
+ AgentType["AI_SDK_QUERY_TASKS"] = "AI_SDK_QUERY_TASKS";
28
29
  })(AgentType || (exports.AgentType = AgentType = {}));
29
30
  var AgentEventType;
30
31
  (function (AgentEventType) {
@@ -573,5 +574,69 @@ class AgentRuntime {
573
574
  }
574
575
  });
575
576
  }
577
+ queryTasks(task_id) {
578
+ return __awaiter(this, void 0, void 0, function* () {
579
+ const validated = schema_1.queryTasksParamsSchema.passthrough().parse({ task_id });
580
+ this.logger.logAccesslog(functions_framework_1.LogLevel.INFO, safeJsonStringify({
581
+ type: AgentEventType.FRAMEWORK_EVENT,
582
+ scene: AgentType.AI_SDK_QUERY_TASKS,
583
+ method: "GET",
584
+ url: `https://dashscope.aliyuncs.com/api/v1/tasks/${validated.task_id}`,
585
+ headers: {},
586
+ data: { task_id: validated.task_id },
587
+ eventId: this.context.eventID,
588
+ timestamp: new Date().toISOString(),
589
+ }));
590
+ try {
591
+ const token = yield this.ai.tokenManager.getValidToken();
592
+ const response = yield this.request.get({
593
+ url: `https://dashscope.aliyuncs.com/api/v1/tasks/${validated.task_id}`,
594
+ headers: {
595
+ Authorization: `Bearer ${token}`,
596
+ },
597
+ });
598
+ this.logger.logAccesslog(functions_framework_1.LogLevel.INFO, safeJsonStringify({
599
+ type: AgentEventType.FRAMEWORK_EVENT,
600
+ scene: AgentType.AI_SDK_QUERY_TASKS,
601
+ method: "GET",
602
+ url: `https://dashscope.aliyuncs.com/api/v1/tasks/${validated.task_id}`,
603
+ status: response.status,
604
+ data: response.data,
605
+ eventId: this.context.eventID,
606
+ timestamp: new Date().toISOString(),
607
+ }));
608
+ if (response.statusCode >= 200 && response.statusCode < 300) {
609
+ return {
610
+ code: 0,
611
+ msg: "success",
612
+ data: response.data,
613
+ };
614
+ }
615
+ else {
616
+ return {
617
+ code: response.status,
618
+ msg: response.statusText || "请求失败",
619
+ data: response.data,
620
+ };
621
+ }
622
+ }
623
+ catch (error) {
624
+ this.logger.logAccesslog(functions_framework_1.LogLevel.ERROR, safeJsonStringify({
625
+ type: AgentEventType.FRAMEWORK_EVENT,
626
+ scene: AgentType.AI_SDK_QUERY_TASKS,
627
+ method: "GET",
628
+ url: `https://dashscope.aliyuncs.com/api/v1/tasks/${validated.task_id}`,
629
+ error: error instanceof Error ? error.message : "查询任务失败",
630
+ stack: error instanceof Error ? error.stack : undefined,
631
+ eventId: this.context.eventID,
632
+ timestamp: new Date().toISOString(),
633
+ }));
634
+ return {
635
+ code: -1,
636
+ msg: error instanceof Error ? error.message : "查询任务失败",
637
+ };
638
+ }
639
+ });
640
+ }
576
641
  }
577
642
  exports.AgentRuntime = AgentRuntime;
@@ -2,3 +2,4 @@ export * from "./message.schema";
2
2
  export * from "./conversation.schema";
3
3
  export * from "./memory.schema";
4
4
  export * from "./knowledge.schema";
5
+ export * from "./task.schema";
@@ -18,3 +18,4 @@ __exportStar(require("./message.schema"), exports);
18
18
  __exportStar(require("./conversation.schema"), exports);
19
19
  __exportStar(require("./memory.schema"), exports);
20
20
  __exportStar(require("./knowledge.schema"), exports);
21
+ __exportStar(require("./task.schema"), exports);
@@ -0,0 +1,9 @@
1
+ import { z } from "zod";
2
+ export declare const queryTasksParamsSchema: z.ZodObject<{
3
+ task_id: z.ZodString;
4
+ }, "strip", z.ZodTypeAny, {
5
+ task_id?: string;
6
+ }, {
7
+ task_id?: string;
8
+ }>;
9
+ export type QueryTasksParams = z.infer<typeof queryTasksParamsSchema>;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.queryTasksParamsSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.queryTasksParamsSchema = zod_1.z.object({
6
+ task_id: zod_1.z.string().min(1),
7
+ });
@@ -4,5 +4,6 @@ export declare function parseAgentId(url: string): string;
4
4
  export declare function parseAgentTag(url: string): string;
5
5
  export declare function parseApiName(url: string): string;
6
6
  export declare function parseQueryFromCtx(ctx: RcbContext): queryString.ParsedQuery<string | boolean>;
7
+ export declare function parseTaskIdFromPath(url: string): string | null;
7
8
  export declare function genRecordId(): string;
8
9
  export declare function genRandomStr(length: number): string;
@@ -40,11 +40,12 @@ exports.parseAgentId = parseAgentId;
40
40
  exports.parseAgentTag = parseAgentTag;
41
41
  exports.parseApiName = parseApiName;
42
42
  exports.parseQueryFromCtx = parseQueryFromCtx;
43
+ exports.parseTaskIdFromPath = parseTaskIdFromPath;
43
44
  exports.genRecordId = genRecordId;
44
45
  exports.genRandomStr = genRandomStr;
45
46
  const crypto = __importStar(require("crypto"));
46
47
  const query_string_1 = __importDefault(require("query-string"));
47
- const AGENT_REG = /\/v1\/aiagent\/agents\/([^\\]+)\/([^\\]+)/;
48
+ const AGENT_REG = /\/v1\/aiagent\/agents\/([^\/]+)\/(.+)/;
48
49
  function parseAgentId(url) {
49
50
  return parseUrl(url).agentId;
50
51
  }
@@ -67,7 +68,11 @@ function parseUrl(url) {
67
68
  if (!regResult) {
68
69
  throw new Error("Invalid pathname");
69
70
  }
70
- const [_, agentId, apiName] = regResult;
71
+ const [_, agentId, remainingPath] = regResult;
72
+ let apiName = remainingPath;
73
+ if (remainingPath.startsWith("query-tasks/")) {
74
+ apiName = "query-tasks";
75
+ }
71
76
  return { agentId, apiName };
72
77
  }
73
78
  function parseQueryFromCtx(ctx) {
@@ -82,6 +87,20 @@ function parseQueryFromCtx(ctx) {
82
87
  parseFragmentIdentifier: true,
83
88
  });
84
89
  }
90
+ function parseTaskIdFromPath(url) {
91
+ try {
92
+ const { pathname } = new URL(url);
93
+ const parts = pathname.split("/").filter(Boolean);
94
+ const agentsIdx = parts.findIndex((p) => p === "agents");
95
+ if (agentsIdx >= 0 && parts[agentsIdx + 2] === "query-tasks" && parts[agentsIdx + 3]) {
96
+ return parts[agentsIdx + 3];
97
+ }
98
+ return null;
99
+ }
100
+ catch (_a) {
101
+ return null;
102
+ }
103
+ }
85
104
  function genRecordId() {
86
105
  return "record-" + genRandomStr(8);
87
106
  }
package/package.json CHANGED
@@ -1,9 +1,8 @@
1
1
  {
2
2
  "name": "@vectorx/agent-runtime",
3
- "version": "0.1.2",
3
+ "version": "0.3.0",
4
4
  "description": "Cloud AI agent runtime",
5
5
  "main": "lib/index.js",
6
- "types": "types/index.d.ts",
7
6
  "files": [
8
7
  "lib",
9
8
  "types",
@@ -21,8 +20,9 @@
21
20
  "node": ">=18.0.0"
22
21
  },
23
22
  "dependencies": {
24
- "@vectorx/ai-sdk": "0.1.2",
25
- "@vectorx/functions-framework": "0.1.2",
23
+ "@vectorx/ai-sdk": "0.3.0",
24
+ "@vectorx/functions-framework": "0.3.0",
25
+ "langfuse": "^3.38.4",
26
26
  "query-string": "^6.14.1",
27
27
  "zod": "^3.24.2"
28
28
  },
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes