@aigne/core 1.64.1-beta → 1.65.0-beta.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.65.0-beta.1](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.65.0-beta...core-v1.65.0-beta.1) (2025-10-26)
4
+
5
+
6
+ ### Features
7
+
8
+ * support define function agent by yaml ([#668](https://github.com/AIGNE-io/aigne-framework/issues/668)) ([2fde8cc](https://github.com/AIGNE-io/aigne-framework/commit/2fde8cc44b213fc2d4c20d91c3c8a8b3c2eb140e))
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **models:** aigne hub video params ([#665](https://github.com/AIGNE-io/aigne-framework/issues/665)) ([d00f836](https://github.com/AIGNE-io/aigne-framework/commit/d00f8368422d8e3707b974e1aff06714731ebb28))
14
+
15
+ ## [1.65.0-beta](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.64.1-beta...core-v1.65.0-beta) (2025-10-24)
16
+
17
+
18
+ ### Features
19
+
20
+ * **model:** support video model ([#647](https://github.com/AIGNE-io/aigne-framework/issues/647)) ([de81742](https://github.com/AIGNE-io/aigne-framework/commit/de817421ef1dd3246d0d8c51ff12f0a855658f9f))
21
+
3
22
  ## [1.64.1-beta](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.64.0...core-v1.64.1-beta) (2025-10-23)
4
23
 
5
24
 
@@ -0,0 +1,182 @@
1
+ import { type ZodType, z } from "zod";
2
+ import type { PromiseOrValue } from "../utils/type-utils.js";
3
+ import type { AgentInvokeOptions, AgentOptions, AgentProcessResult, AgentResponse, AgentResponseStream, Message } from "./agent.js";
4
+ import { type ChatModelOutputUsage } from "./chat-model.js";
5
+ import { type FileType, type FileUnionContent, Model } from "./model.js";
6
+ export interface VideoModelOptions<I extends VideoModelInput = VideoModelInput, O extends VideoModelOutput = VideoModelOutput> extends Omit<AgentOptions<I, O>, "model"> {
7
+ model?: string;
8
+ modelOptions?: Omit<VideoModelInputOptions, "model">;
9
+ }
10
+ export declare abstract class VideoModel<I extends VideoModelInput = VideoModelInput, O extends VideoModelOutput = VideoModelOutput> extends Model<I, O> {
11
+ options?: VideoModelOptions<I, O> | undefined;
12
+ tag: string;
13
+ constructor(options?: VideoModelOptions<I, O> | undefined);
14
+ get credential(): PromiseOrValue<{
15
+ url?: string;
16
+ apiKey?: string;
17
+ model?: string;
18
+ }>;
19
+ protected preprocess(input: I, options: AgentInvokeOptions): Promise<void>;
20
+ protected postprocess(input: I, output: O, options: AgentInvokeOptions): Promise<void>;
21
+ abstract process(input: I, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<O>>;
22
+ protected processAgentOutput(input: I, output: Exclude<AgentResponse<O>, AgentResponseStream<O>>, options: AgentInvokeOptions): Promise<O>;
23
+ }
24
+ export interface VideoModelInput extends Message {
25
+ prompt: string;
26
+ model?: string;
27
+ size?: string;
28
+ seconds?: string;
29
+ outputFileType?: FileType;
30
+ modelOptions?: VideoModelInputOptions;
31
+ }
32
+ export interface VideoModelInputOptions extends Record<string, unknown> {
33
+ model?: string;
34
+ }
35
+ export declare const videoModelInputSchema: z.ZodObject<{
36
+ prompt: z.ZodString;
37
+ model: z.ZodOptional<z.ZodString>;
38
+ size: z.ZodOptional<z.ZodString>;
39
+ seconds: z.ZodOptional<z.ZodString>;
40
+ outputFileType: z.ZodOptional<z.ZodEnum<["local", "file"]>>;
41
+ modelOptions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
42
+ }, "strip", z.ZodTypeAny, {
43
+ prompt: string;
44
+ model?: string | undefined;
45
+ modelOptions?: Record<string, unknown> | undefined;
46
+ outputFileType?: "local" | "file" | undefined;
47
+ size?: string | undefined;
48
+ seconds?: string | undefined;
49
+ }, {
50
+ prompt: string;
51
+ model?: string | undefined;
52
+ modelOptions?: Record<string, unknown> | undefined;
53
+ outputFileType?: "local" | "file" | undefined;
54
+ size?: string | undefined;
55
+ seconds?: string | undefined;
56
+ }>;
57
+ export interface VideoModelOutput extends Message {
58
+ videos: FileUnionContent[];
59
+ /**
60
+ * Token usage statistics
61
+ */
62
+ usage?: ChatModelOutputUsage;
63
+ /**
64
+ * Model name or version used
65
+ */
66
+ model?: string;
67
+ seconds?: number;
68
+ }
69
+ export declare const videoModelOutputSchema: z.ZodObject<{
70
+ videos: z.ZodArray<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
71
+ filename: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
72
+ mimeType: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
73
+ } & {
74
+ type: z.ZodLiteral<"local">;
75
+ path: z.ZodString;
76
+ }, "strip", z.ZodTypeAny, {
77
+ path: string;
78
+ type: "local";
79
+ filename?: string | undefined;
80
+ mimeType?: string | undefined;
81
+ }, {
82
+ path: string;
83
+ type: "local";
84
+ filename?: string | undefined;
85
+ mimeType?: string | undefined;
86
+ }>, z.ZodObject<{
87
+ filename: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
88
+ mimeType: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
89
+ } & {
90
+ type: z.ZodLiteral<"url">;
91
+ url: z.ZodString;
92
+ }, "strip", z.ZodTypeAny, {
93
+ type: "url";
94
+ url: string;
95
+ filename?: string | undefined;
96
+ mimeType?: string | undefined;
97
+ }, {
98
+ type: "url";
99
+ url: string;
100
+ filename?: string | undefined;
101
+ mimeType?: string | undefined;
102
+ }>, z.ZodObject<{
103
+ filename: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
104
+ mimeType: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
105
+ } & {
106
+ type: z.ZodLiteral<"file">;
107
+ data: z.ZodString;
108
+ }, "strip", z.ZodTypeAny, {
109
+ type: "file";
110
+ data: string;
111
+ filename?: string | undefined;
112
+ mimeType?: string | undefined;
113
+ }, {
114
+ type: "file";
115
+ data: string;
116
+ filename?: string | undefined;
117
+ mimeType?: string | undefined;
118
+ }>]>, "many">;
119
+ usage: z.ZodOptional<z.ZodObject<{
120
+ inputTokens: z.ZodNumber;
121
+ outputTokens: z.ZodNumber;
122
+ aigneHubCredits: z.ZodOptional<z.ZodNumber>;
123
+ }, "strip", z.ZodTypeAny, {
124
+ inputTokens: number;
125
+ outputTokens: number;
126
+ aigneHubCredits?: number | undefined;
127
+ }, {
128
+ inputTokens: number;
129
+ outputTokens: number;
130
+ aigneHubCredits?: number | undefined;
131
+ }>>;
132
+ model: z.ZodOptional<z.ZodString>;
133
+ seconds: z.ZodOptional<z.ZodNumber>;
134
+ }, "strip", z.ZodTypeAny, {
135
+ videos: ({
136
+ type: "url";
137
+ url: string;
138
+ filename?: string | undefined;
139
+ mimeType?: string | undefined;
140
+ } | {
141
+ type: "file";
142
+ data: string;
143
+ filename?: string | undefined;
144
+ mimeType?: string | undefined;
145
+ } | {
146
+ path: string;
147
+ type: "local";
148
+ filename?: string | undefined;
149
+ mimeType?: string | undefined;
150
+ })[];
151
+ model?: string | undefined;
152
+ usage?: {
153
+ inputTokens: number;
154
+ outputTokens: number;
155
+ aigneHubCredits?: number | undefined;
156
+ } | undefined;
157
+ seconds?: number | undefined;
158
+ }, {
159
+ videos: ({
160
+ type: "url";
161
+ url: string;
162
+ filename?: string | undefined;
163
+ mimeType?: string | undefined;
164
+ } | {
165
+ type: "file";
166
+ data: string;
167
+ filename?: string | undefined;
168
+ mimeType?: string | undefined;
169
+ } | {
170
+ path: string;
171
+ type: "local";
172
+ filename?: string | undefined;
173
+ mimeType?: string | undefined;
174
+ })[];
175
+ model?: string | undefined;
176
+ usage?: {
177
+ inputTokens: number;
178
+ outputTokens: number;
179
+ aigneHubCredits?: number | undefined;
180
+ } | undefined;
181
+ seconds?: number | undefined;
182
+ }>;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.videoModelOutputSchema = exports.videoModelInputSchema = exports.VideoModel = void 0;
4
+ const zod_1 = require("zod");
5
+ const chat_model_js_1 = require("./chat-model.js");
6
+ const model_js_1 = require("./model.js");
7
+ class VideoModel extends model_js_1.Model {
8
+ options;
9
+ tag = "VideoModelAgent";
10
+ constructor(options) {
11
+ super({
12
+ inputSchema: exports.videoModelInputSchema,
13
+ outputSchema: exports.videoModelOutputSchema,
14
+ ...options,
15
+ model: undefined,
16
+ });
17
+ this.options = options;
18
+ }
19
+ get credential() {
20
+ return {};
21
+ }
22
+ async preprocess(input, options) {
23
+ super.preprocess(input, options);
24
+ const { limits, usage } = options.context;
25
+ const usedTokens = usage.outputTokens + usage.inputTokens;
26
+ if (limits?.maxTokens && usedTokens >= limits.maxTokens) {
27
+ throw new Error(`Exceeded max tokens ${usedTokens}/${limits.maxTokens}`);
28
+ }
29
+ }
30
+ async postprocess(input, output, options) {
31
+ super.postprocess(input, output, options);
32
+ const { usage } = output;
33
+ if (usage) {
34
+ options.context.usage.outputTokens += usage.outputTokens;
35
+ options.context.usage.inputTokens += usage.inputTokens;
36
+ if (usage.aigneHubCredits)
37
+ options.context.usage.aigneHubCredits += usage.aigneHubCredits;
38
+ }
39
+ }
40
+ async processAgentOutput(input, output, options) {
41
+ if (output.videos) {
42
+ const videos = zod_1.z.array(model_js_1.fileUnionContentSchema).parse(output.videos);
43
+ output = {
44
+ ...output,
45
+ videos: await Promise.all(videos.map((video) => this.transformFileType(input.outputFileType, video, options))),
46
+ };
47
+ }
48
+ return super.processAgentOutput(input, output, options);
49
+ }
50
+ }
51
+ exports.VideoModel = VideoModel;
52
+ exports.videoModelInputSchema = zod_1.z.object({
53
+ prompt: zod_1.z.string().describe("Text prompt describing the video to generate"),
54
+ model: zod_1.z.string().optional().describe("Model to use for video generation"),
55
+ size: zod_1.z.string().optional().describe("Size/resolution of the video"),
56
+ seconds: zod_1.z.string().optional().describe("Duration of the video in seconds"),
57
+ outputFileType: model_js_1.fileTypeSchema.optional(),
58
+ modelOptions: zod_1.z.record(zod_1.z.unknown()).optional(),
59
+ });
60
+ exports.videoModelOutputSchema = zod_1.z.object({
61
+ videos: zod_1.z.array(model_js_1.fileUnionContentSchema),
62
+ usage: chat_model_js_1.chatModelOutputUsageSchema.optional(),
63
+ model: zod_1.z.string().optional(),
64
+ seconds: zod_1.z.number().optional(),
65
+ });
@@ -10,6 +10,7 @@ export * from "./agents/team-agent.js";
10
10
  export * from "./agents/transform-agent.js";
11
11
  export * from "./agents/types.js";
12
12
  export * from "./agents/user-agent.js";
13
+ export * from "./agents/video-model.js";
13
14
  export * from "./aigne/index.js";
14
15
  export * from "./memory/index.js";
15
16
  export * from "./prompt/prompt-builder.js";
package/lib/cjs/index.js CHANGED
@@ -26,6 +26,7 @@ __exportStar(require("./agents/team-agent.js"), exports);
26
26
  __exportStar(require("./agents/transform-agent.js"), exports);
27
27
  __exportStar(require("./agents/types.js"), exports);
28
28
  __exportStar(require("./agents/user-agent.js"), exports);
29
+ __exportStar(require("./agents/video-model.js"), exports);
29
30
  __exportStar(require("./aigne/index.js"), exports);
30
31
  __exportStar(require("./memory/index.js"), exports);
31
32
  __exportStar(require("./prompt/prompt-builder.js"), exports);
@@ -10,6 +10,7 @@ const ai_agent_js_1 = require("../agents/ai-agent.js");
10
10
  const chat_model_js_1 = require("../agents/chat-model.js");
11
11
  const team_agent_js_1 = require("../agents/team-agent.js");
12
12
  const type_utils_js_1 = require("../utils/type-utils.js");
13
+ const function_agent_js_1 = require("./function-agent.js");
13
14
  const schema_js_1 = require("./schema.js");
14
15
  async function parseAgentFile(path, data) {
15
16
  const agentSchema = zod_1.z.lazy(() => {
@@ -166,7 +167,7 @@ async function parseAgentFile(path, data) {
166
167
  zod_1.z
167
168
  .object({
168
169
  type: zod_1.z.literal("function"),
169
- process: zod_1.z.custom(),
170
+ process: zod_1.z.preprocess((v) => (typeof v === "string" ? (0, function_agent_js_1.codeToFunctionAgentFn)(v) : v), zod_1.z.custom()),
170
171
  })
171
172
  .extend(baseAgentSchema.shape),
172
173
  ]));
@@ -0,0 +1,2 @@
1
+ import type { FunctionAgentFn } from "../agents/agent.js";
2
+ export declare function codeToFunctionAgentFn(code: string): FunctionAgentFn;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.codeToFunctionAgentFn = codeToFunctionAgentFn;
4
+ function codeToFunctionAgentFn(code) {
5
+ const AsyncFunction = Object.getPrototypeOf(async () => { }).constructor;
6
+ return new AsyncFunction("input", "options", code);
7
+ }
@@ -0,0 +1,182 @@
1
+ import { type ZodType, z } from "zod";
2
+ import type { PromiseOrValue } from "../utils/type-utils.js";
3
+ import type { AgentInvokeOptions, AgentOptions, AgentProcessResult, AgentResponse, AgentResponseStream, Message } from "./agent.js";
4
+ import { type ChatModelOutputUsage } from "./chat-model.js";
5
+ import { type FileType, type FileUnionContent, Model } from "./model.js";
6
+ export interface VideoModelOptions<I extends VideoModelInput = VideoModelInput, O extends VideoModelOutput = VideoModelOutput> extends Omit<AgentOptions<I, O>, "model"> {
7
+ model?: string;
8
+ modelOptions?: Omit<VideoModelInputOptions, "model">;
9
+ }
10
+ export declare abstract class VideoModel<I extends VideoModelInput = VideoModelInput, O extends VideoModelOutput = VideoModelOutput> extends Model<I, O> {
11
+ options?: VideoModelOptions<I, O> | undefined;
12
+ tag: string;
13
+ constructor(options?: VideoModelOptions<I, O> | undefined);
14
+ get credential(): PromiseOrValue<{
15
+ url?: string;
16
+ apiKey?: string;
17
+ model?: string;
18
+ }>;
19
+ protected preprocess(input: I, options: AgentInvokeOptions): Promise<void>;
20
+ protected postprocess(input: I, output: O, options: AgentInvokeOptions): Promise<void>;
21
+ abstract process(input: I, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<O>>;
22
+ protected processAgentOutput(input: I, output: Exclude<AgentResponse<O>, AgentResponseStream<O>>, options: AgentInvokeOptions): Promise<O>;
23
+ }
24
+ export interface VideoModelInput extends Message {
25
+ prompt: string;
26
+ model?: string;
27
+ size?: string;
28
+ seconds?: string;
29
+ outputFileType?: FileType;
30
+ modelOptions?: VideoModelInputOptions;
31
+ }
32
+ export interface VideoModelInputOptions extends Record<string, unknown> {
33
+ model?: string;
34
+ }
35
+ export declare const videoModelInputSchema: z.ZodObject<{
36
+ prompt: z.ZodString;
37
+ model: z.ZodOptional<z.ZodString>;
38
+ size: z.ZodOptional<z.ZodString>;
39
+ seconds: z.ZodOptional<z.ZodString>;
40
+ outputFileType: z.ZodOptional<z.ZodEnum<["local", "file"]>>;
41
+ modelOptions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
42
+ }, "strip", z.ZodTypeAny, {
43
+ prompt: string;
44
+ model?: string | undefined;
45
+ modelOptions?: Record<string, unknown> | undefined;
46
+ outputFileType?: "local" | "file" | undefined;
47
+ size?: string | undefined;
48
+ seconds?: string | undefined;
49
+ }, {
50
+ prompt: string;
51
+ model?: string | undefined;
52
+ modelOptions?: Record<string, unknown> | undefined;
53
+ outputFileType?: "local" | "file" | undefined;
54
+ size?: string | undefined;
55
+ seconds?: string | undefined;
56
+ }>;
57
+ export interface VideoModelOutput extends Message {
58
+ videos: FileUnionContent[];
59
+ /**
60
+ * Token usage statistics
61
+ */
62
+ usage?: ChatModelOutputUsage;
63
+ /**
64
+ * Model name or version used
65
+ */
66
+ model?: string;
67
+ seconds?: number;
68
+ }
69
+ export declare const videoModelOutputSchema: z.ZodObject<{
70
+ videos: z.ZodArray<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
71
+ filename: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
72
+ mimeType: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
73
+ } & {
74
+ type: z.ZodLiteral<"local">;
75
+ path: z.ZodString;
76
+ }, "strip", z.ZodTypeAny, {
77
+ path: string;
78
+ type: "local";
79
+ filename?: string | undefined;
80
+ mimeType?: string | undefined;
81
+ }, {
82
+ path: string;
83
+ type: "local";
84
+ filename?: string | undefined;
85
+ mimeType?: string | undefined;
86
+ }>, z.ZodObject<{
87
+ filename: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
88
+ mimeType: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
89
+ } & {
90
+ type: z.ZodLiteral<"url">;
91
+ url: z.ZodString;
92
+ }, "strip", z.ZodTypeAny, {
93
+ type: "url";
94
+ url: string;
95
+ filename?: string | undefined;
96
+ mimeType?: string | undefined;
97
+ }, {
98
+ type: "url";
99
+ url: string;
100
+ filename?: string | undefined;
101
+ mimeType?: string | undefined;
102
+ }>, z.ZodObject<{
103
+ filename: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
104
+ mimeType: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
105
+ } & {
106
+ type: z.ZodLiteral<"file">;
107
+ data: z.ZodString;
108
+ }, "strip", z.ZodTypeAny, {
109
+ type: "file";
110
+ data: string;
111
+ filename?: string | undefined;
112
+ mimeType?: string | undefined;
113
+ }, {
114
+ type: "file";
115
+ data: string;
116
+ filename?: string | undefined;
117
+ mimeType?: string | undefined;
118
+ }>]>, "many">;
119
+ usage: z.ZodOptional<z.ZodObject<{
120
+ inputTokens: z.ZodNumber;
121
+ outputTokens: z.ZodNumber;
122
+ aigneHubCredits: z.ZodOptional<z.ZodNumber>;
123
+ }, "strip", z.ZodTypeAny, {
124
+ inputTokens: number;
125
+ outputTokens: number;
126
+ aigneHubCredits?: number | undefined;
127
+ }, {
128
+ inputTokens: number;
129
+ outputTokens: number;
130
+ aigneHubCredits?: number | undefined;
131
+ }>>;
132
+ model: z.ZodOptional<z.ZodString>;
133
+ seconds: z.ZodOptional<z.ZodNumber>;
134
+ }, "strip", z.ZodTypeAny, {
135
+ videos: ({
136
+ type: "url";
137
+ url: string;
138
+ filename?: string | undefined;
139
+ mimeType?: string | undefined;
140
+ } | {
141
+ type: "file";
142
+ data: string;
143
+ filename?: string | undefined;
144
+ mimeType?: string | undefined;
145
+ } | {
146
+ path: string;
147
+ type: "local";
148
+ filename?: string | undefined;
149
+ mimeType?: string | undefined;
150
+ })[];
151
+ model?: string | undefined;
152
+ usage?: {
153
+ inputTokens: number;
154
+ outputTokens: number;
155
+ aigneHubCredits?: number | undefined;
156
+ } | undefined;
157
+ seconds?: number | undefined;
158
+ }, {
159
+ videos: ({
160
+ type: "url";
161
+ url: string;
162
+ filename?: string | undefined;
163
+ mimeType?: string | undefined;
164
+ } | {
165
+ type: "file";
166
+ data: string;
167
+ filename?: string | undefined;
168
+ mimeType?: string | undefined;
169
+ } | {
170
+ path: string;
171
+ type: "local";
172
+ filename?: string | undefined;
173
+ mimeType?: string | undefined;
174
+ })[];
175
+ model?: string | undefined;
176
+ usage?: {
177
+ inputTokens: number;
178
+ outputTokens: number;
179
+ aigneHubCredits?: number | undefined;
180
+ } | undefined;
181
+ seconds?: number | undefined;
182
+ }>;
@@ -10,6 +10,7 @@ export * from "./agents/team-agent.js";
10
10
  export * from "./agents/transform-agent.js";
11
11
  export * from "./agents/types.js";
12
12
  export * from "./agents/user-agent.js";
13
+ export * from "./agents/video-model.js";
13
14
  export * from "./aigne/index.js";
14
15
  export * from "./memory/index.js";
15
16
  export * from "./prompt/prompt-builder.js";
@@ -0,0 +1,2 @@
1
+ import type { FunctionAgentFn } from "../agents/agent.js";
2
+ export declare function codeToFunctionAgentFn(code: string): FunctionAgentFn;
@@ -0,0 +1,182 @@
1
+ import { type ZodType, z } from "zod";
2
+ import type { PromiseOrValue } from "../utils/type-utils.js";
3
+ import type { AgentInvokeOptions, AgentOptions, AgentProcessResult, AgentResponse, AgentResponseStream, Message } from "./agent.js";
4
+ import { type ChatModelOutputUsage } from "./chat-model.js";
5
+ import { type FileType, type FileUnionContent, Model } from "./model.js";
6
+ export interface VideoModelOptions<I extends VideoModelInput = VideoModelInput, O extends VideoModelOutput = VideoModelOutput> extends Omit<AgentOptions<I, O>, "model"> {
7
+ model?: string;
8
+ modelOptions?: Omit<VideoModelInputOptions, "model">;
9
+ }
10
+ export declare abstract class VideoModel<I extends VideoModelInput = VideoModelInput, O extends VideoModelOutput = VideoModelOutput> extends Model<I, O> {
11
+ options?: VideoModelOptions<I, O> | undefined;
12
+ tag: string;
13
+ constructor(options?: VideoModelOptions<I, O> | undefined);
14
+ get credential(): PromiseOrValue<{
15
+ url?: string;
16
+ apiKey?: string;
17
+ model?: string;
18
+ }>;
19
+ protected preprocess(input: I, options: AgentInvokeOptions): Promise<void>;
20
+ protected postprocess(input: I, output: O, options: AgentInvokeOptions): Promise<void>;
21
+ abstract process(input: I, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<O>>;
22
+ protected processAgentOutput(input: I, output: Exclude<AgentResponse<O>, AgentResponseStream<O>>, options: AgentInvokeOptions): Promise<O>;
23
+ }
24
+ export interface VideoModelInput extends Message {
25
+ prompt: string;
26
+ model?: string;
27
+ size?: string;
28
+ seconds?: string;
29
+ outputFileType?: FileType;
30
+ modelOptions?: VideoModelInputOptions;
31
+ }
32
+ export interface VideoModelInputOptions extends Record<string, unknown> {
33
+ model?: string;
34
+ }
35
+ export declare const videoModelInputSchema: z.ZodObject<{
36
+ prompt: z.ZodString;
37
+ model: z.ZodOptional<z.ZodString>;
38
+ size: z.ZodOptional<z.ZodString>;
39
+ seconds: z.ZodOptional<z.ZodString>;
40
+ outputFileType: z.ZodOptional<z.ZodEnum<["local", "file"]>>;
41
+ modelOptions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
42
+ }, "strip", z.ZodTypeAny, {
43
+ prompt: string;
44
+ model?: string | undefined;
45
+ modelOptions?: Record<string, unknown> | undefined;
46
+ outputFileType?: "local" | "file" | undefined;
47
+ size?: string | undefined;
48
+ seconds?: string | undefined;
49
+ }, {
50
+ prompt: string;
51
+ model?: string | undefined;
52
+ modelOptions?: Record<string, unknown> | undefined;
53
+ outputFileType?: "local" | "file" | undefined;
54
+ size?: string | undefined;
55
+ seconds?: string | undefined;
56
+ }>;
57
+ export interface VideoModelOutput extends Message {
58
+ videos: FileUnionContent[];
59
+ /**
60
+ * Token usage statistics
61
+ */
62
+ usage?: ChatModelOutputUsage;
63
+ /**
64
+ * Model name or version used
65
+ */
66
+ model?: string;
67
+ seconds?: number;
68
+ }
69
+ export declare const videoModelOutputSchema: z.ZodObject<{
70
+ videos: z.ZodArray<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
71
+ filename: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
72
+ mimeType: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
73
+ } & {
74
+ type: z.ZodLiteral<"local">;
75
+ path: z.ZodString;
76
+ }, "strip", z.ZodTypeAny, {
77
+ path: string;
78
+ type: "local";
79
+ filename?: string | undefined;
80
+ mimeType?: string | undefined;
81
+ }, {
82
+ path: string;
83
+ type: "local";
84
+ filename?: string | undefined;
85
+ mimeType?: string | undefined;
86
+ }>, z.ZodObject<{
87
+ filename: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
88
+ mimeType: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
89
+ } & {
90
+ type: z.ZodLiteral<"url">;
91
+ url: z.ZodString;
92
+ }, "strip", z.ZodTypeAny, {
93
+ type: "url";
94
+ url: string;
95
+ filename?: string | undefined;
96
+ mimeType?: string | undefined;
97
+ }, {
98
+ type: "url";
99
+ url: string;
100
+ filename?: string | undefined;
101
+ mimeType?: string | undefined;
102
+ }>, z.ZodObject<{
103
+ filename: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
104
+ mimeType: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
105
+ } & {
106
+ type: z.ZodLiteral<"file">;
107
+ data: z.ZodString;
108
+ }, "strip", z.ZodTypeAny, {
109
+ type: "file";
110
+ data: string;
111
+ filename?: string | undefined;
112
+ mimeType?: string | undefined;
113
+ }, {
114
+ type: "file";
115
+ data: string;
116
+ filename?: string | undefined;
117
+ mimeType?: string | undefined;
118
+ }>]>, "many">;
119
+ usage: z.ZodOptional<z.ZodObject<{
120
+ inputTokens: z.ZodNumber;
121
+ outputTokens: z.ZodNumber;
122
+ aigneHubCredits: z.ZodOptional<z.ZodNumber>;
123
+ }, "strip", z.ZodTypeAny, {
124
+ inputTokens: number;
125
+ outputTokens: number;
126
+ aigneHubCredits?: number | undefined;
127
+ }, {
128
+ inputTokens: number;
129
+ outputTokens: number;
130
+ aigneHubCredits?: number | undefined;
131
+ }>>;
132
+ model: z.ZodOptional<z.ZodString>;
133
+ seconds: z.ZodOptional<z.ZodNumber>;
134
+ }, "strip", z.ZodTypeAny, {
135
+ videos: ({
136
+ type: "url";
137
+ url: string;
138
+ filename?: string | undefined;
139
+ mimeType?: string | undefined;
140
+ } | {
141
+ type: "file";
142
+ data: string;
143
+ filename?: string | undefined;
144
+ mimeType?: string | undefined;
145
+ } | {
146
+ path: string;
147
+ type: "local";
148
+ filename?: string | undefined;
149
+ mimeType?: string | undefined;
150
+ })[];
151
+ model?: string | undefined;
152
+ usage?: {
153
+ inputTokens: number;
154
+ outputTokens: number;
155
+ aigneHubCredits?: number | undefined;
156
+ } | undefined;
157
+ seconds?: number | undefined;
158
+ }, {
159
+ videos: ({
160
+ type: "url";
161
+ url: string;
162
+ filename?: string | undefined;
163
+ mimeType?: string | undefined;
164
+ } | {
165
+ type: "file";
166
+ data: string;
167
+ filename?: string | undefined;
168
+ mimeType?: string | undefined;
169
+ } | {
170
+ path: string;
171
+ type: "local";
172
+ filename?: string | undefined;
173
+ mimeType?: string | undefined;
174
+ })[];
175
+ model?: string | undefined;
176
+ usage?: {
177
+ inputTokens: number;
178
+ outputTokens: number;
179
+ aigneHubCredits?: number | undefined;
180
+ } | undefined;
181
+ seconds?: number | undefined;
182
+ }>;
@@ -0,0 +1,61 @@
1
+ import { z } from "zod";
2
+ import { chatModelOutputUsageSchema } from "./chat-model.js";
3
+ import { fileTypeSchema, fileUnionContentSchema, Model, } from "./model.js";
4
+ export class VideoModel extends Model {
5
+ options;
6
+ tag = "VideoModelAgent";
7
+ constructor(options) {
8
+ super({
9
+ inputSchema: videoModelInputSchema,
10
+ outputSchema: videoModelOutputSchema,
11
+ ...options,
12
+ model: undefined,
13
+ });
14
+ this.options = options;
15
+ }
16
+ get credential() {
17
+ return {};
18
+ }
19
+ async preprocess(input, options) {
20
+ super.preprocess(input, options);
21
+ const { limits, usage } = options.context;
22
+ const usedTokens = usage.outputTokens + usage.inputTokens;
23
+ if (limits?.maxTokens && usedTokens >= limits.maxTokens) {
24
+ throw new Error(`Exceeded max tokens ${usedTokens}/${limits.maxTokens}`);
25
+ }
26
+ }
27
+ async postprocess(input, output, options) {
28
+ super.postprocess(input, output, options);
29
+ const { usage } = output;
30
+ if (usage) {
31
+ options.context.usage.outputTokens += usage.outputTokens;
32
+ options.context.usage.inputTokens += usage.inputTokens;
33
+ if (usage.aigneHubCredits)
34
+ options.context.usage.aigneHubCredits += usage.aigneHubCredits;
35
+ }
36
+ }
37
+ async processAgentOutput(input, output, options) {
38
+ if (output.videos) {
39
+ const videos = z.array(fileUnionContentSchema).parse(output.videos);
40
+ output = {
41
+ ...output,
42
+ videos: await Promise.all(videos.map((video) => this.transformFileType(input.outputFileType, video, options))),
43
+ };
44
+ }
45
+ return super.processAgentOutput(input, output, options);
46
+ }
47
+ }
48
+ export const videoModelInputSchema = z.object({
49
+ prompt: z.string().describe("Text prompt describing the video to generate"),
50
+ model: z.string().optional().describe("Model to use for video generation"),
51
+ size: z.string().optional().describe("Size/resolution of the video"),
52
+ seconds: z.string().optional().describe("Duration of the video in seconds"),
53
+ outputFileType: fileTypeSchema.optional(),
54
+ modelOptions: z.record(z.unknown()).optional(),
55
+ });
56
+ export const videoModelOutputSchema = z.object({
57
+ videos: z.array(fileUnionContentSchema),
58
+ usage: chatModelOutputUsageSchema.optional(),
59
+ model: z.string().optional(),
60
+ seconds: z.number().optional(),
61
+ });
@@ -10,6 +10,7 @@ export * from "./agents/team-agent.js";
10
10
  export * from "./agents/transform-agent.js";
11
11
  export * from "./agents/types.js";
12
12
  export * from "./agents/user-agent.js";
13
+ export * from "./agents/video-model.js";
13
14
  export * from "./aigne/index.js";
14
15
  export * from "./memory/index.js";
15
16
  export * from "./prompt/prompt-builder.js";
package/lib/esm/index.js CHANGED
@@ -10,6 +10,7 @@ export * from "./agents/team-agent.js";
10
10
  export * from "./agents/transform-agent.js";
11
11
  export * from "./agents/types.js";
12
12
  export * from "./agents/user-agent.js";
13
+ export * from "./agents/video-model.js";
13
14
  export * from "./aigne/index.js";
14
15
  export * from "./memory/index.js";
15
16
  export * from "./prompt/prompt-builder.js";
@@ -6,6 +6,7 @@ import { AIAgentToolChoice } from "../agents/ai-agent.js";
6
6
  import { roleSchema } from "../agents/chat-model.js";
7
7
  import { ProcessMode } from "../agents/team-agent.js";
8
8
  import { tryOrThrow } from "../utils/type-utils.js";
9
+ import { codeToFunctionAgentFn } from "./function-agent.js";
9
10
  import { camelizeSchema, chatModelSchema, defaultInputSchema, imageModelSchema, inputOutputSchema, optionalize, } from "./schema.js";
10
11
  export async function parseAgentFile(path, data) {
11
12
  const agentSchema = z.lazy(() => {
@@ -162,7 +163,7 @@ export async function parseAgentFile(path, data) {
162
163
  z
163
164
  .object({
164
165
  type: z.literal("function"),
165
- process: z.custom(),
166
+ process: z.preprocess((v) => (typeof v === "string" ? codeToFunctionAgentFn(v) : v), z.custom()),
166
167
  })
167
168
  .extend(baseAgentSchema.shape),
168
169
  ]));
@@ -0,0 +1,2 @@
1
+ import type { FunctionAgentFn } from "../agents/agent.js";
2
+ export declare function codeToFunctionAgentFn(code: string): FunctionAgentFn;
@@ -0,0 +1,4 @@
1
+ export function codeToFunctionAgentFn(code) {
2
+ const AsyncFunction = Object.getPrototypeOf(async () => { }).constructor;
3
+ return new AsyncFunction("input", "options", code);
4
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/core",
3
- "version": "1.64.1-beta",
3
+ "version": "1.65.0-beta.1",
4
4
  "description": "The functional core of agentic AI",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -91,9 +91,9 @@
91
91
  "zod": "^3.25.67",
92
92
  "zod-from-json-schema": "^0.0.5",
93
93
  "zod-to-json-schema": "^3.24.6",
94
- "@aigne/platform-helpers": "^0.6.3",
94
+ "@aigne/afs": "^1.1.1-beta",
95
95
  "@aigne/observability-api": "^0.11.3",
96
- "@aigne/afs": "^1.1.1-beta"
96
+ "@aigne/platform-helpers": "^0.6.3"
97
97
  },
98
98
  "devDependencies": {
99
99
  "@types/bun": "^1.2.22",