@vectorx/agent-runtime 0.3.0 → 0.5.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.
@@ -10,4 +10,5 @@ export declare class AgentDriver {
10
10
  private getAgentInfoFunc;
11
11
  private getConversationsFunc;
12
12
  private queryTasksFunc;
13
+ private uploadFileFunc;
13
14
  }
@@ -30,6 +30,7 @@ class AgentDriver {
30
30
  }
31
31
  const apiFuncs = {
32
32
  "POST:send-message": this.sendMessageFunc.bind(this),
33
+ "POST:upload-file": this.uploadFileFunc.bind(this),
33
34
  "GET:query-tasks": this.queryTasksFunc.bind(this),
34
35
  "GET:messages": this.getHistoryMessagesFunc.bind(this),
35
36
  "GET:info": this.getAgentInfoFunc.bind(this),
@@ -107,5 +108,17 @@ class AgentDriver {
107
108
  }
108
109
  });
109
110
  }
111
+ uploadFileFunc(event, context) {
112
+ return __awaiter(this, void 0, void 0, function* () {
113
+ var _a, _b;
114
+ try {
115
+ const parsedEvent = schema_1.uploadFileInputSchema.passthrough().parse(event);
116
+ return yield ((_b = (_a = this.agent).uploadFile) === null || _b === void 0 ? void 0 : _b.call(_a, parsedEvent));
117
+ }
118
+ catch (e) {
119
+ return (0, integration_response_1.createIntegrationResponse)(500, codes_1.CODES.AGENT_API_ERROR, `Agent API 'uploadFile' failed, message: ${e}`);
120
+ }
121
+ });
122
+ }
110
123
  }
111
124
  exports.AgentDriver = AgentDriver;
@@ -100,3 +100,19 @@ export interface QueryTasksData {
100
100
  }
101
101
  export type RawQueryTasksResponse = QueryTasksData;
102
102
  export type QueryTasksResponse = BaseResponse<QueryTasksData>;
103
+ export interface UploadFileInput {
104
+ file: File | Buffer | string;
105
+ filename: string;
106
+ purpose?: string;
107
+ }
108
+ export interface UploadFileData {
109
+ id: string;
110
+ object: string;
111
+ bytes: number;
112
+ created_at: number;
113
+ filename: string;
114
+ purpose: string;
115
+ status: string;
116
+ status_details?: any;
117
+ }
118
+ export type UploadFileResponse = BaseResponse<UploadFileData>;
package/lib/agent.d.ts CHANGED
@@ -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, QueryTasksResponse } from "./agent-types";
3
+ import type { CreateRecordPairResponse, GetAgentInfoResponse, GetConversationsResponse, GetHistoryMessagesResponse, KnowledgeBaseRetrieveResponse, QueryTasksResponse, UploadFileResponse } 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 {
@@ -36,4 +36,5 @@ export declare class AgentRuntime {
36
36
  getAgentInfo(): Promise<GetAgentInfoResponse>;
37
37
  knowledgeBaseRetrieve(params: KnowledgeSearchInput): Promise<KnowledgeBaseRetrieveResponse>;
38
38
  queryTasks(task_id?: string): Promise<QueryTasksResponse>;
39
+ uploadFile(input: any): Promise<UploadFileResponse>;
39
40
  }
package/lib/agent.js CHANGED
@@ -638,5 +638,81 @@ class AgentRuntime {
638
638
  }
639
639
  });
640
640
  }
641
+ uploadFile(input) {
642
+ return __awaiter(this, void 0, void 0, function* () {
643
+ try {
644
+ const validatedInput = schema_1.uploadFileInputSchema.passthrough().parse(input);
645
+ this.logger.logAccesslog(functions_framework_1.LogLevel.INFO, safeJsonStringify({
646
+ type: AgentEventType.FRAMEWORK_EVENT,
647
+ scene: "AI_SDK_UPLOAD_FILE",
648
+ method: "POST",
649
+ url: "https://dashscope.aliyuncs.com/compatible-mode/v1/files",
650
+ headers: {},
651
+ data: { filename: validatedInput.filename, purpose: validatedInput.purpose },
652
+ eventId: this.context.eventID,
653
+ timestamp: new Date().toISOString(),
654
+ }));
655
+ const token = yield this.ai.tokenManager.getValidToken();
656
+ const fileBuffer = Buffer.from(validatedInput.fileContent, "base64");
657
+ const formData = {
658
+ file: {
659
+ value: fileBuffer,
660
+ options: {
661
+ filename: validatedInput.filename,
662
+ contentType: validatedInput.mimeType || "application/octet-stream",
663
+ },
664
+ },
665
+ purpose: validatedInput.purpose || "file-extract",
666
+ };
667
+ const response = yield this.request.upload({
668
+ url: "https://dashscope.aliyuncs.com/compatible-mode/v1/files",
669
+ headers: {
670
+ Authorization: `Bearer ${token}`,
671
+ },
672
+ data: formData,
673
+ });
674
+ this.logger.logAccesslog(functions_framework_1.LogLevel.INFO, safeJsonStringify({
675
+ type: AgentEventType.FRAMEWORK_EVENT,
676
+ scene: "AI_SDK_UPLOAD_FILE",
677
+ method: "POST",
678
+ url: "https://dashscope.aliyuncs.com/compatible-mode/v1/files",
679
+ status: response.status,
680
+ data: response.data,
681
+ eventId: this.context.eventID,
682
+ timestamp: new Date().toISOString(),
683
+ }));
684
+ if (response.statusCode >= 200 && response.statusCode < 300) {
685
+ return {
686
+ code: 0,
687
+ msg: "success",
688
+ data: response.data,
689
+ };
690
+ }
691
+ else {
692
+ return {
693
+ code: response.status,
694
+ msg: response.statusText || "文件上传失败",
695
+ data: response.data,
696
+ };
697
+ }
698
+ }
699
+ catch (error) {
700
+ this.logger.logAccesslog(functions_framework_1.LogLevel.ERROR, safeJsonStringify({
701
+ type: AgentEventType.FRAMEWORK_EVENT,
702
+ scene: "AI_SDK_UPLOAD_FILE",
703
+ method: "POST",
704
+ url: "https://dashscope.aliyuncs.com/compatible-mode/v1/files",
705
+ error: error instanceof Error ? error.message : "文件上传失败",
706
+ stack: error instanceof Error ? error.stack : undefined,
707
+ eventId: this.context.eventID,
708
+ timestamp: new Date().toISOString(),
709
+ }));
710
+ return {
711
+ code: -1,
712
+ msg: error instanceof Error ? error.message : "文件上传失败",
713
+ };
714
+ }
715
+ });
716
+ }
641
717
  }
642
718
  exports.AgentRuntime = AgentRuntime;
@@ -0,0 +1,18 @@
1
+ import { z } from "zod";
2
+ export declare const uploadFileInputSchema: z.ZodObject<{
3
+ filename: z.ZodString;
4
+ purpose: z.ZodDefault<z.ZodOptional<z.ZodString>>;
5
+ fileContent: z.ZodString;
6
+ mimeType: z.ZodOptional<z.ZodString>;
7
+ }, "strip", z.ZodTypeAny, {
8
+ filename?: string;
9
+ purpose?: string;
10
+ fileContent?: string;
11
+ mimeType?: string;
12
+ }, {
13
+ filename?: string;
14
+ purpose?: string;
15
+ fileContent?: string;
16
+ mimeType?: string;
17
+ }>;
18
+ export type UploadFileInputSchema = z.infer<typeof uploadFileInputSchema>;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.uploadFileInputSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.uploadFileInputSchema = zod_1.z.object({
6
+ filename: zod_1.z.string().min(1, "文件名不能为空"),
7
+ purpose: zod_1.z.string().optional().default("file-extract"),
8
+ fileContent: zod_1.z.string().min(1, "文件内容不能为空"),
9
+ mimeType: zod_1.z.string().optional(),
10
+ });
@@ -3,3 +3,4 @@ export * from "./conversation.schema";
3
3
  export * from "./memory.schema";
4
4
  export * from "./knowledge.schema";
5
5
  export * from "./task.schema";
6
+ export * from "./file.schema";
@@ -19,3 +19,4 @@ __exportStar(require("./conversation.schema"), exports);
19
19
  __exportStar(require("./memory.schema"), exports);
20
20
  __exportStar(require("./knowledge.schema"), exports);
21
21
  __exportStar(require("./task.schema"), exports);
22
+ __exportStar(require("./file.schema"), exports);
@@ -58,11 +58,11 @@ export declare const videoContentSchema: z.ZodObject<{
58
58
  type: z.ZodLiteral<"video">;
59
59
  video: z.ZodArray<z.ZodString, "many">;
60
60
  }, "strip", z.ZodTypeAny, {
61
- type?: "video";
62
61
  video?: string[];
63
- }, {
64
62
  type?: "video";
63
+ }, {
65
64
  video?: string[];
65
+ type?: "video";
66
66
  }>;
67
67
  export declare const videoUrlContentSchema: z.ZodObject<{
68
68
  type: z.ZodLiteral<"video_url">;
@@ -140,11 +140,11 @@ export declare const messageContentSchema: z.ZodUnion<[z.ZodObject<{
140
140
  type: z.ZodLiteral<"video">;
141
141
  video: z.ZodArray<z.ZodString, "many">;
142
142
  }, "strip", z.ZodTypeAny, {
143
- type?: "video";
144
143
  video?: string[];
145
- }, {
146
144
  type?: "video";
145
+ }, {
147
146
  video?: string[];
147
+ type?: "video";
148
148
  }>, z.ZodObject<{
149
149
  type: z.ZodLiteral<"video_url">;
150
150
  video_url: z.ZodObject<{
@@ -223,11 +223,11 @@ export declare const baseMessageSchema: z.ZodObject<{
223
223
  type: z.ZodLiteral<"video">;
224
224
  video: z.ZodArray<z.ZodString, "many">;
225
225
  }, "strip", z.ZodTypeAny, {
226
- type?: "video";
227
226
  video?: string[];
228
- }, {
229
227
  type?: "video";
228
+ }, {
230
229
  video?: string[];
230
+ type?: "video";
231
231
  }>, z.ZodObject<{
232
232
  type: z.ZodLiteral<"video_url">;
233
233
  video_url: z.ZodObject<{
@@ -249,7 +249,7 @@ export declare const baseMessageSchema: z.ZodObject<{
249
249
  };
250
250
  }>]>, "many">]>;
251
251
  }, "strip", z.ZodTypeAny, {
252
- role?: "system" | "user" | "assistant";
252
+ role?: "user" | "assistant" | "system";
253
253
  content?: string | ({
254
254
  type?: "text";
255
255
  text?: string;
@@ -265,8 +265,8 @@ export declare const baseMessageSchema: z.ZodObject<{
265
265
  format?: string;
266
266
  };
267
267
  } | {
268
- type?: "video";
269
268
  video?: string[];
269
+ type?: "video";
270
270
  } | {
271
271
  type?: "video_url";
272
272
  video_url?: {
@@ -274,7 +274,7 @@ export declare const baseMessageSchema: z.ZodObject<{
274
274
  };
275
275
  })[];
276
276
  }, {
277
- role?: "system" | "user" | "assistant";
277
+ role?: "user" | "assistant" | "system";
278
278
  content?: string | ({
279
279
  type?: "text";
280
280
  text?: string;
@@ -290,8 +290,8 @@ export declare const baseMessageSchema: z.ZodObject<{
290
290
  format?: string;
291
291
  };
292
292
  } | {
293
- type?: "video";
294
293
  video?: string[];
294
+ type?: "video";
295
295
  } | {
296
296
  type?: "video_url";
297
297
  video_url?: {
@@ -386,11 +386,11 @@ export declare const messageItemSchema: z.ZodUnion<[z.ZodObject<{
386
386
  type: z.ZodLiteral<"video">;
387
387
  video: z.ZodArray<z.ZodString, "many">;
388
388
  }, "strip", z.ZodTypeAny, {
389
- type?: "video";
390
389
  video?: string[];
391
- }, {
392
390
  type?: "video";
391
+ }, {
393
392
  video?: string[];
393
+ type?: "video";
394
394
  }>, z.ZodObject<{
395
395
  type: z.ZodLiteral<"video_url">;
396
396
  video_url: z.ZodObject<{
@@ -412,7 +412,7 @@ export declare const messageItemSchema: z.ZodUnion<[z.ZodObject<{
412
412
  };
413
413
  }>]>, "many">]>;
414
414
  }, "strip", z.ZodTypeAny, {
415
- role?: "system" | "user" | "assistant";
415
+ role?: "user" | "assistant" | "system";
416
416
  content?: string | ({
417
417
  type?: "text";
418
418
  text?: string;
@@ -428,8 +428,8 @@ export declare const messageItemSchema: z.ZodUnion<[z.ZodObject<{
428
428
  format?: string;
429
429
  };
430
430
  } | {
431
- type?: "video";
432
431
  video?: string[];
432
+ type?: "video";
433
433
  } | {
434
434
  type?: "video_url";
435
435
  video_url?: {
@@ -437,7 +437,7 @@ export declare const messageItemSchema: z.ZodUnion<[z.ZodObject<{
437
437
  };
438
438
  })[];
439
439
  }, {
440
- role?: "system" | "user" | "assistant";
440
+ role?: "user" | "assistant" | "system";
441
441
  content?: string | ({
442
442
  type?: "text";
443
443
  text?: string;
@@ -453,8 +453,8 @@ export declare const messageItemSchema: z.ZodUnion<[z.ZodObject<{
453
453
  format?: string;
454
454
  };
455
455
  } | {
456
- type?: "video";
457
456
  video?: string[];
457
+ type?: "video";
458
458
  } | {
459
459
  type?: "video_url";
460
460
  video_url?: {
@@ -547,11 +547,11 @@ export declare const messageHistorySchema: z.ZodArray<z.ZodUnion<[z.ZodObject<{
547
547
  type: z.ZodLiteral<"video">;
548
548
  video: z.ZodArray<z.ZodString, "many">;
549
549
  }, "strip", z.ZodTypeAny, {
550
- type?: "video";
551
550
  video?: string[];
552
- }, {
553
551
  type?: "video";
552
+ }, {
554
553
  video?: string[];
554
+ type?: "video";
555
555
  }>, z.ZodObject<{
556
556
  type: z.ZodLiteral<"video_url">;
557
557
  video_url: z.ZodObject<{
@@ -573,7 +573,7 @@ export declare const messageHistorySchema: z.ZodArray<z.ZodUnion<[z.ZodObject<{
573
573
  };
574
574
  }>]>, "many">]>;
575
575
  }, "strip", z.ZodTypeAny, {
576
- role?: "system" | "user" | "assistant";
576
+ role?: "user" | "assistant" | "system";
577
577
  content?: string | ({
578
578
  type?: "text";
579
579
  text?: string;
@@ -589,8 +589,8 @@ export declare const messageHistorySchema: z.ZodArray<z.ZodUnion<[z.ZodObject<{
589
589
  format?: string;
590
590
  };
591
591
  } | {
592
- type?: "video";
593
592
  video?: string[];
593
+ type?: "video";
594
594
  } | {
595
595
  type?: "video_url";
596
596
  video_url?: {
@@ -598,7 +598,7 @@ export declare const messageHistorySchema: z.ZodArray<z.ZodUnion<[z.ZodObject<{
598
598
  };
599
599
  })[];
600
600
  }, {
601
- role?: "system" | "user" | "assistant";
601
+ role?: "user" | "assistant" | "system";
602
602
  content?: string | ({
603
603
  type?: "text";
604
604
  text?: string;
@@ -614,8 +614,8 @@ export declare const messageHistorySchema: z.ZodArray<z.ZodUnion<[z.ZodObject<{
614
614
  format?: string;
615
615
  };
616
616
  } | {
617
- type?: "video";
618
617
  video?: string[];
618
+ type?: "video";
619
619
  } | {
620
620
  type?: "video_url";
621
621
  video_url?: {
@@ -710,11 +710,11 @@ export declare const sendMessageInputSchema: z.ZodObject<{
710
710
  type: z.ZodLiteral<"video">;
711
711
  video: z.ZodArray<z.ZodString, "many">;
712
712
  }, "strip", z.ZodTypeAny, {
713
- type?: "video";
714
713
  video?: string[];
715
- }, {
716
714
  type?: "video";
715
+ }, {
717
716
  video?: string[];
717
+ type?: "video";
718
718
  }>, z.ZodObject<{
719
719
  type: z.ZodLiteral<"video_url">;
720
720
  video_url: z.ZodObject<{
@@ -736,7 +736,7 @@ export declare const sendMessageInputSchema: z.ZodObject<{
736
736
  };
737
737
  }>]>, "many">]>;
738
738
  }, "strip", z.ZodTypeAny, {
739
- role?: "system" | "user" | "assistant";
739
+ role?: "user" | "assistant" | "system";
740
740
  content?: string | ({
741
741
  type?: "text";
742
742
  text?: string;
@@ -752,8 +752,8 @@ export declare const sendMessageInputSchema: z.ZodObject<{
752
752
  format?: string;
753
753
  };
754
754
  } | {
755
- type?: "video";
756
755
  video?: string[];
756
+ type?: "video";
757
757
  } | {
758
758
  type?: "video_url";
759
759
  video_url?: {
@@ -761,7 +761,7 @@ export declare const sendMessageInputSchema: z.ZodObject<{
761
761
  };
762
762
  })[];
763
763
  }, {
764
- role?: "system" | "user" | "assistant";
764
+ role?: "user" | "assistant" | "system";
765
765
  content?: string | ({
766
766
  type?: "text";
767
767
  text?: string;
@@ -777,8 +777,8 @@ export declare const sendMessageInputSchema: z.ZodObject<{
777
777
  format?: string;
778
778
  };
779
779
  } | {
780
- type?: "video";
781
780
  video?: string[];
781
+ type?: "video";
782
782
  } | {
783
783
  type?: "video_url";
784
784
  video_url?: {
@@ -816,7 +816,7 @@ export declare const sendMessageInputSchema: z.ZodObject<{
816
816
  }, "strip", z.ZodTypeAny, {
817
817
  msg?: string;
818
818
  history?: ({
819
- role?: "system" | "user" | "assistant";
819
+ role?: "user" | "assistant" | "system";
820
820
  content?: string | ({
821
821
  type?: "text";
822
822
  text?: string;
@@ -832,8 +832,8 @@ export declare const sendMessageInputSchema: z.ZodObject<{
832
832
  format?: string;
833
833
  };
834
834
  } | {
835
- type?: "video";
836
835
  video?: string[];
836
+ type?: "video";
837
837
  } | {
838
838
  type?: "video_url";
839
839
  video_url?: {
@@ -853,7 +853,7 @@ export declare const sendMessageInputSchema: z.ZodObject<{
853
853
  }, {
854
854
  msg?: string;
855
855
  history?: ({
856
- role?: "system" | "user" | "assistant";
856
+ role?: "user" | "assistant" | "system";
857
857
  content?: string | ({
858
858
  type?: "text";
859
859
  text?: string;
@@ -869,8 +869,8 @@ export declare const sendMessageInputSchema: z.ZodObject<{
869
869
  format?: string;
870
870
  };
871
871
  } | {
872
- type?: "video";
873
872
  video?: string[];
873
+ type?: "video";
874
874
  } | {
875
875
  type?: "video_url";
876
876
  video_url?: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vectorx/agent-runtime",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "Cloud AI agent runtime",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -20,8 +20,8 @@
20
20
  "node": ">=18.0.0"
21
21
  },
22
22
  "dependencies": {
23
- "@vectorx/ai-sdk": "0.3.0",
24
- "@vectorx/functions-framework": "0.3.0",
23
+ "@vectorx/ai-sdk": "0.5.0",
24
+ "@vectorx/functions-framework": "0.5.0",
25
25
  "langfuse": "^3.38.4",
26
26
  "query-string": "^6.14.1",
27
27
  "zod": "^3.24.2"