@aigne/core 1.61.0-beta → 1.61.0-beta.2

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,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.61.0-beta.2](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.61.0-beta.1...core-v1.61.0-beta.2) (2025-09-23)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * add prefer input file type option for image model ([#536](https://github.com/AIGNE-io/aigne-framework/issues/536)) ([3cba8a5](https://github.com/AIGNE-io/aigne-framework/commit/3cba8a5562233a1567b49b6dd5c446c0760f5c4c))
9
+
10
+ ## [1.61.0-beta.1](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.61.0-beta...core-v1.61.0-beta.1) (2025-09-23)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * standardize file parameter naming across models ([#534](https://github.com/AIGNE-io/aigne-framework/issues/534)) ([f159a9d](https://github.com/AIGNE-io/aigne-framework/commit/f159a9d6af21ec0e99641996b150560929845845))
16
+
3
17
  ## [1.61.0-beta](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.60.3...core-v1.61.0-beta) (2025-09-22)
4
18
 
5
19
 
@@ -3,9 +3,9 @@ import { PromptBuilder } from "../prompt/prompt-builder.js";
3
3
  import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessAsyncGenerator, type Message } from "./agent.js";
4
4
  import type { ChatModel, ChatModelInput } from "./chat-model.js";
5
5
  import type { GuideRailAgentOutput } from "./guide-rail-agent.js";
6
- import type { FileOutputType } from "./model.js";
6
+ import type { FileType } from "./model.js";
7
7
  export declare const DEFAULT_OUTPUT_KEY = "message";
8
- export declare const DEFAULT_FILE_OUTPUT_KEY = "files";
8
+ export declare const DEFAULT_OUTPUT_FILE_KEY = "files";
9
9
  /**
10
10
  * Configuration options for an AI Agent
11
11
  *
@@ -27,15 +27,15 @@ export interface AIAgentOptions<I extends Message = Message, O extends Message =
27
27
  * Pick a message from input to use as the user's message
28
28
  */
29
29
  inputKey?: string;
30
- fileInputKey?: string;
30
+ inputFileKey?: string;
31
31
  /**
32
32
  * Custom key to use for text output in the response
33
33
  *
34
34
  * Defaults to `message` if not specified
35
35
  */
36
36
  outputKey?: string;
37
- fileOutputKey?: string;
38
- fileOutputType?: FileOutputType;
37
+ outputFileKey?: string;
38
+ outputFileType?: FileType;
39
39
  /**
40
40
  * Controls how the agent uses tools during execution
41
41
  *
@@ -210,7 +210,7 @@ export declare class AIAgent<I extends Message = any, O extends Message = any> e
210
210
  * Pick a message from input to use as the user's message
211
211
  */
212
212
  inputKey?: string;
213
- fileInputKey?: string;
213
+ inputFileKey?: string;
214
214
  /**
215
215
  * Custom key to use for text output in the response
216
216
  *
@@ -219,8 +219,8 @@ export declare class AIAgent<I extends Message = any, O extends Message = any> e
219
219
  * {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-custom-output-key}
220
220
  */
221
221
  outputKey: string;
222
- fileOutputKey: string;
223
- fileOutputType?: FileOutputType;
222
+ outputFileKey: string;
223
+ outputFileType?: FileType;
224
224
  /**
225
225
  * Controls how the agent uses tools during execution
226
226
  *
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AIAgent = exports.aiAgentOptionsSchema = exports.aiAgentToolChoiceSchema = exports.AIAgentToolChoice = exports.DEFAULT_FILE_OUTPUT_KEY = exports.DEFAULT_OUTPUT_KEY = void 0;
3
+ exports.AIAgent = exports.aiAgentOptionsSchema = exports.aiAgentToolChoiceSchema = exports.AIAgentToolChoice = exports.DEFAULT_OUTPUT_FILE_KEY = exports.DEFAULT_OUTPUT_KEY = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const prompt_builder_js_1 = require("../prompt/prompt-builder.js");
6
6
  const structured_stream_instructions_js_1 = require("../prompt/prompts/structured-stream-instructions.js");
@@ -10,7 +10,7 @@ const type_utils_js_1 = require("../utils/type-utils.js");
10
10
  const agent_js_1 = require("./agent.js");
11
11
  const types_js_1 = require("./types.js");
12
12
  exports.DEFAULT_OUTPUT_KEY = "message";
13
- exports.DEFAULT_FILE_OUTPUT_KEY = "files";
13
+ exports.DEFAULT_OUTPUT_FILE_KEY = "files";
14
14
  /**
15
15
  * Tool choice options for AI agents
16
16
  *
@@ -111,10 +111,10 @@ class AIAgent extends agent_js_1.Agent {
111
111
  ? prompt_builder_js_1.PromptBuilder.from(options.instructions)
112
112
  : (options.instructions ?? new prompt_builder_js_1.PromptBuilder());
113
113
  this.inputKey = options.inputKey;
114
- this.fileInputKey = options.fileInputKey;
114
+ this.inputFileKey = options.inputFileKey;
115
115
  this.outputKey = options.outputKey || exports.DEFAULT_OUTPUT_KEY;
116
- this.fileOutputKey = options.fileOutputKey || exports.DEFAULT_FILE_OUTPUT_KEY;
117
- this.fileOutputType = options.fileOutputType;
116
+ this.outputFileKey = options.outputFileKey || exports.DEFAULT_OUTPUT_FILE_KEY;
117
+ this.outputFileType = options.outputFileType;
118
118
  this.toolChoice = options.toolChoice;
119
119
  this.memoryAgentsAsTools = options.memoryAgentsAsTools;
120
120
  this.memoryPromptTemplate = options.memoryPromptTemplate;
@@ -148,7 +148,7 @@ class AIAgent extends agent_js_1.Agent {
148
148
  * Pick a message from input to use as the user's message
149
149
  */
150
150
  inputKey;
151
- fileInputKey;
151
+ inputFileKey;
152
152
  /**
153
153
  * Custom key to use for text output in the response
154
154
  *
@@ -157,8 +157,8 @@ class AIAgent extends agent_js_1.Agent {
157
157
  * {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-custom-output-key}
158
158
  */
159
159
  outputKey;
160
- fileOutputKey;
161
- fileOutputType;
160
+ outputFileKey;
161
+ outputFileType;
162
162
  /**
163
163
  * Controls how the agent uses tools during execution
164
164
  *
@@ -309,7 +309,7 @@ class AIAgent extends agent_js_1.Agent {
309
309
  Object.assign(result, { [outputKey]: text });
310
310
  }
311
311
  if (files) {
312
- Object.assign(result, { [this.fileOutputKey]: files });
312
+ Object.assign(result, { [this.outputFileKey]: files });
313
313
  }
314
314
  if (!(0, type_utils_js_1.isEmpty)(result)) {
315
315
  yield { delta: { json: result } };
@@ -1,12 +1,12 @@
1
1
  import { z } from "zod";
2
2
  import { type PromiseOrValue } from "../utils/type-utils.js";
3
3
  import { type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type AgentResponse, type AgentResponseStream, type Message } from "./agent.js";
4
- import { type FileOutputType, type FileUnionContent, Model } from "./model.js";
4
+ import { type FileType, type FileUnionContent, Model } from "./model.js";
5
5
  export declare class StructuredOutputError extends Error {
6
6
  }
7
7
  export interface ChatModelOptions extends Omit<AgentOptions<ChatModelInput, ChatModelOutput>, "model" | "inputSchema" | "outputSchema"> {
8
8
  model?: string;
9
- modelOptions?: Omit<ModelOptions, "model">;
9
+ modelOptions?: Omit<ChatModelInputOptions, "model">;
10
10
  }
11
11
  /**
12
12
  * ChatModel is an abstract base class for interacting with Large Language Models (LLMs).
@@ -135,7 +135,7 @@ export interface ChatModelInput extends Message {
135
135
  * Specifies the expected response format
136
136
  */
137
137
  responseFormat?: ChatModelInputResponseFormat;
138
- fileOutputType?: FileOutputType;
138
+ outputFileType?: FileType;
139
139
  /**
140
140
  * List of tools available for the model to use
141
141
  */
@@ -147,7 +147,7 @@ export interface ChatModelInput extends Message {
147
147
  /**
148
148
  * Model-specific configuration options
149
149
  */
150
- modelOptions?: ModelOptions;
150
+ modelOptions?: ChatModelInputOptions;
151
151
  }
152
152
  /**
153
153
  * Message role types
@@ -351,7 +351,7 @@ export type Modality = "text" | "image" | "audio";
351
351
  *
352
352
  * Contains various parameters for controlling model behavior, such as model name, temperature, etc.
353
353
  */
354
- export interface ModelOptions {
354
+ export interface ChatModelInputOptions {
355
355
  /**
356
356
  * Model name or version
357
357
  */
@@ -377,7 +377,7 @@ export interface ModelOptions {
377
377
  */
378
378
  parallelToolCalls?: boolean;
379
379
  modalities?: Modality[];
380
- preferFileInputType?: "file" | "url";
380
+ preferInputFileType?: "file" | "url";
381
381
  }
382
382
  /**
383
383
  * Output message format for ChatModel
@@ -186,8 +186,8 @@ class ChatModel extends model_js_1.Model {
186
186
  mimeType: item.mimeType || ChatModel.getMimeType(item.filename || item.path),
187
187
  };
188
188
  }
189
- if ((input.modelOptions?.preferFileInputType ||
190
- this.options?.modelOptions?.preferFileInputType) !== "url") {
189
+ if ((input.modelOptions?.preferInputFileType ||
190
+ this.options?.modelOptions?.preferInputFileType) !== "url") {
191
191
  if (item.type === "url") {
192
192
  return {
193
193
  ...item,
@@ -240,7 +240,7 @@ class ChatModel extends model_js_1.Model {
240
240
  const files = zod_1.z.array(model_js_1.fileUnionContentSchema).parse(output.files);
241
241
  output = {
242
242
  ...output,
243
- files: await Promise.all(files.map((file) => this.transformFileOutput(input.fileOutputType, file, options))),
243
+ files: await Promise.all(files.map((file) => this.transformFileType(input.outputFileType, file, options))),
244
244
  };
245
245
  }
246
246
  // Remove fields with `null` value for validation
@@ -2,11 +2,11 @@ import { type ZodObject, type ZodType } from "zod";
2
2
  import { PromptBuilder } from "../prompt/prompt-builder.js";
3
3
  import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from "./agent.js";
4
4
  import { type ImageModelOutput } from "./image-model.js";
5
- import type { FileOutputType } from "./model.js";
5
+ import { type FileType } from "./model.js";
6
6
  export interface ImageAgentOptions<I extends Message = any, O extends ImageModelOutput = any> extends Omit<AgentOptions<I, O>, "outputSchema"> {
7
7
  instructions: string | PromptBuilder;
8
8
  modelOptions?: Record<string, any>;
9
- outputType?: FileOutputType;
9
+ outputFileType?: FileType;
10
10
  }
11
11
  export declare const imageAgentOptionsSchema: ZodObject<{
12
12
  [key in keyof ImageAgentOptions]: ZodType<ImageAgentOptions[key]>;
@@ -17,6 +17,6 @@ export declare class ImageAgent<I extends Message = any, O extends ImageModelOut
17
17
  constructor(options: ImageAgentOptions<I, O>);
18
18
  instructions: PromptBuilder;
19
19
  modelOptions?: Record<string, any>;
20
- outputType?: FileOutputType;
20
+ outputFileType?: FileType;
21
21
  process(input: I, options: AgentInvokeOptions): Promise<O>;
22
22
  }
@@ -9,9 +9,11 @@ const prompt_builder_js_1 = require("../prompt/prompt-builder.js");
9
9
  const type_utils_js_1 = require("../utils/type-utils.js");
10
10
  const agent_js_1 = require("./agent.js");
11
11
  const image_model_js_1 = require("./image-model.js");
12
+ const model_js_1 = require("./model.js");
12
13
  exports.imageAgentOptionsSchema = agent_js_1.agentOptionsSchema.extend({
13
14
  instructions: zod_1.default.union([zod_1.default.string(), zod_1.default.custom()]),
14
15
  modelOptions: zod_1.default.record(zod_1.default.any()).optional(),
16
+ outputFileType: model_js_1.fileTypeSchema.optional(),
15
17
  });
16
18
  class ImageAgent extends agent_js_1.Agent {
17
19
  tag = "ImageAgent";
@@ -26,17 +28,17 @@ class ImageAgent extends agent_js_1.Agent {
26
28
  ? prompt_builder_js_1.PromptBuilder.from(options.instructions)
27
29
  : options.instructions;
28
30
  this.modelOptions = options.modelOptions;
29
- this.outputType = options.outputType;
31
+ this.outputFileType = options.outputFileType;
30
32
  }
31
33
  instructions;
32
34
  modelOptions;
33
- outputType;
35
+ outputFileType;
34
36
  async process(input, options) {
35
37
  const imageModel = this.imageModel || options.imageModel || options.context.imageModel;
36
38
  if (!imageModel)
37
39
  throw new Error("image model is required to run ImageAgent");
38
40
  const { prompt } = await this.instructions.buildImagePrompt({ input });
39
- return (await this.invokeChildAgent(imageModel, { ...input, ...this.modelOptions, prompt, outputType: this.outputType }, { ...options, streaming: false }));
41
+ return (await this.invokeChildAgent(imageModel, { ...input, modelOptions: this.modelOptions, prompt, outputFileType: this.outputFileType }, { ...options, streaming: false }));
40
42
  }
41
43
  }
42
44
  exports.ImageAgent = ImageAgent;
@@ -2,12 +2,15 @@ import { type ZodType, z } from "zod";
2
2
  import type { PromiseOrValue } from "../utils/type-utils.js";
3
3
  import type { AgentInvokeOptions, AgentOptions, AgentProcessResult, AgentResponse, AgentResponseStream, Message } from "./agent.js";
4
4
  import { type ChatModelOutputUsage } from "./chat-model.js";
5
- import { FileOutputType, type FileUnionContent, Model } from "./model.js";
5
+ import { type FileType, type FileUnionContent, Model } from "./model.js";
6
6
  export interface ImageModelOptions<I extends ImageModelInput = ImageModelInput, O extends ImageModelOutput = ImageModelOutput> extends Omit<AgentOptions<I, O>, "model"> {
7
+ model?: string;
8
+ modelOptions?: Omit<ImageModelInputOptions, "model">;
7
9
  }
8
10
  export declare abstract class ImageModel<I extends ImageModelInput = ImageModelInput, O extends ImageModelOutput = ImageModelOutput> extends Model<I, O> {
11
+ options?: ImageModelOptions<I, O> | undefined;
9
12
  tag: string;
10
- constructor(options?: ImageModelOptions<I, O>);
13
+ constructor(options?: ImageModelOptions<I, O> | undefined);
11
14
  get credential(): PromiseOrValue<{
12
15
  url?: string;
13
16
  apiKey?: string;
@@ -20,14 +23,18 @@ export declare abstract class ImageModel<I extends ImageModelInput = ImageModelI
20
23
  }
21
24
  export type ImageModelInputImage = FileUnionContent[];
22
25
  export interface ImageModelInput extends Message {
23
- model?: string;
24
- image?: ImageModelInputImage;
25
26
  prompt: string;
27
+ image?: ImageModelInputImage;
26
28
  n?: number;
27
- outputType?: FileOutputType;
29
+ outputFileType?: FileType;
30
+ modelOptions?: ImageModelInputOptions;
31
+ }
32
+ export interface ImageModelInputOptions extends Record<string, unknown> {
33
+ model?: string;
34
+ preferInputFileType?: "file" | "url";
28
35
  }
29
36
  export declare const imageModelInputSchema: z.ZodObject<{
30
- model: z.ZodOptional<z.ZodString>;
37
+ prompt: z.ZodString;
31
38
  image: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
32
39
  filename: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
33
40
  mimeType: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
@@ -77,12 +84,12 @@ export declare const imageModelInputSchema: z.ZodObject<{
77
84
  filename?: string | undefined;
78
85
  mimeType?: string | undefined;
79
86
  }>]>, "many">>;
80
- prompt: z.ZodString;
81
87
  n: z.ZodOptional<z.ZodNumber>;
82
- outputType: z.ZodOptional<z.ZodNativeEnum<typeof FileOutputType>>;
88
+ outputFileType: z.ZodOptional<z.ZodEnum<["local", "file"]>>;
89
+ modelOptions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
83
90
  }, "strip", z.ZodTypeAny, {
84
91
  prompt: string;
85
- model?: string | undefined;
92
+ modelOptions?: Record<string, unknown> | undefined;
86
93
  image?: ({
87
94
  type: "url";
88
95
  url: string;
@@ -99,11 +106,11 @@ export declare const imageModelInputSchema: z.ZodObject<{
99
106
  filename?: string | undefined;
100
107
  mimeType?: string | undefined;
101
108
  })[] | undefined;
109
+ outputFileType?: "local" | "file" | undefined;
102
110
  n?: number | undefined;
103
- outputType?: FileOutputType | undefined;
104
111
  }, {
105
112
  prompt: string;
106
- model?: string | undefined;
113
+ modelOptions?: Record<string, unknown> | undefined;
107
114
  image?: ({
108
115
  type: "url";
109
116
  url: string;
@@ -120,8 +127,8 @@ export declare const imageModelInputSchema: z.ZodObject<{
120
127
  filename?: string | undefined;
121
128
  mimeType?: string | undefined;
122
129
  })[] | undefined;
130
+ outputFileType?: "local" | "file" | undefined;
123
131
  n?: number | undefined;
124
- outputType?: FileOutputType | undefined;
125
132
  }>;
126
133
  export interface ImageModelOutput extends Message {
127
134
  images: FileUnionContent[];
@@ -6,13 +6,16 @@ const zod_1 = require("zod");
6
6
  const chat_model_js_1 = require("./chat-model.js");
7
7
  const model_js_1 = require("./model.js");
8
8
  class ImageModel extends model_js_1.Model {
9
+ options;
9
10
  tag = "ImageModelAgent";
10
11
  constructor(options) {
11
12
  super({
12
13
  inputSchema: exports.imageModelInputSchema,
13
14
  outputSchema: exports.imageModelOutputSchema,
14
15
  ...options,
16
+ model: undefined,
15
17
  });
18
+ this.options = options;
16
19
  }
17
20
  get credential() {
18
21
  return {};
@@ -35,6 +38,18 @@ class ImageModel extends model_js_1.Model {
35
38
  mimeType: item.mimeType || ImageModel.getMimeType(item.filename || item.path),
36
39
  };
37
40
  }
41
+ if ((input.modelOptions?.preferInputFileType ||
42
+ this.options?.modelOptions?.preferInputFileType) !== "url") {
43
+ if (item.type === "url") {
44
+ return {
45
+ ...item,
46
+ type: "file",
47
+ data: Buffer.from(await (await this.downloadFile(item.url)).arrayBuffer()).toString("base64"),
48
+ url: undefined,
49
+ mimeType: item.mimeType || ImageModel.getMimeType(item.filename || item.url),
50
+ };
51
+ }
52
+ }
38
53
  return item;
39
54
  }));
40
55
  }
@@ -54,7 +69,7 @@ class ImageModel extends model_js_1.Model {
54
69
  const images = zod_1.z.array(model_js_1.fileUnionContentSchema).parse(output.images);
55
70
  output = {
56
71
  ...output,
57
- images: await Promise.all(images.map((image) => this.transformFileOutput(input.outputType, image, options))),
72
+ images: await Promise.all(images.map((image) => this.transformFileType(input.outputFileType, image, options))),
58
73
  };
59
74
  }
60
75
  return super.processAgentOutput(input, output, options);
@@ -62,11 +77,11 @@ class ImageModel extends model_js_1.Model {
62
77
  }
63
78
  exports.ImageModel = ImageModel;
64
79
  exports.imageModelInputSchema = zod_1.z.object({
65
- model: zod_1.z.string().optional(),
66
- image: zod_1.z.array(model_js_1.fileUnionContentSchema).optional().describe("Images used for editing"),
67
80
  prompt: zod_1.z.string(),
81
+ image: zod_1.z.array(model_js_1.fileUnionContentSchema).optional().describe("Images used for editing"),
68
82
  n: zod_1.z.number().int().min(1).optional(),
69
- outputType: zod_1.z.nativeEnum(model_js_1.FileOutputType).optional(),
83
+ outputFileType: model_js_1.fileTypeSchema.optional(),
84
+ modelOptions: zod_1.z.record(zod_1.z.unknown()).optional(),
70
85
  });
71
86
  exports.imageModelOutputSchema = zod_1.z.object({
72
87
  images: zod_1.z.array(model_js_1.fileUnionContentSchema),
@@ -1,17 +1,15 @@
1
1
  import { z } from "zod";
2
2
  import { Agent, type AgentInvokeOptions, type Message } from "./agent.js";
3
3
  export declare abstract class Model<I extends Message = any, O extends Message = any> extends Agent<I, O> {
4
- transformFileOutput(fileOutputType: FileOutputType.file, data: FileUnionContent, options: AgentInvokeOptions): Promise<FileContent>;
5
- transformFileOutput(fileOutputType: FileOutputType.local | undefined, data: FileUnionContent, options: AgentInvokeOptions): Promise<LocalContent>;
6
- transformFileOutput(fileOutputType: FileOutputType | undefined, data: FileUnionContent, options: AgentInvokeOptions): Promise<FileUnionContent>;
4
+ transformFileType(fileType: "file", data: FileUnionContent, options: AgentInvokeOptions): Promise<FileContent>;
5
+ transformFileType(fileType: "local" | undefined, data: FileUnionContent, options: AgentInvokeOptions): Promise<LocalContent>;
6
+ transformFileType(fileType: FileType | undefined, data: FileUnionContent, options: AgentInvokeOptions): Promise<FileUnionContent>;
7
7
  static getFileExtension(type: string): string | undefined;
8
8
  static getMimeType(filename: string): string | undefined;
9
9
  downloadFile(url: string): Promise<Response>;
10
10
  }
11
- export declare enum FileOutputType {
12
- local = "local",
13
- file = "file"
14
- }
11
+ export type FileType = "local" | "file";
12
+ export declare const fileTypeSchema: z.ZodEnum<["local", "file"]>;
15
13
  export interface FileContentBase {
16
14
  filename?: string;
17
15
  mimeType?: string;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.fileUnionContentsSchema = exports.fileUnionContentSchema = exports.localContentSchema = exports.fileContentSchema = exports.urlContentSchema = exports.fileContentBaseSchema = exports.FileOutputType = exports.Model = void 0;
6
+ exports.fileUnionContentsSchema = exports.fileUnionContentSchema = exports.localContentSchema = exports.fileContentSchema = exports.urlContentSchema = exports.fileContentBaseSchema = exports.fileTypeSchema = exports.Model = void 0;
7
7
  const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
8
8
  const mime_1 = __importDefault(require("mime"));
9
9
  const ufo_1 = require("ufo");
@@ -13,12 +13,12 @@ const schema_js_1 = require("../loader/schema.js");
13
13
  const type_utils_js_1 = require("../utils/type-utils.js");
14
14
  const agent_js_1 = require("./agent.js");
15
15
  class Model extends agent_js_1.Agent {
16
- async transformFileOutput(fileOutputType = FileOutputType.local, data, options) {
17
- if (fileOutputType === data.type)
16
+ async transformFileType(fileType = "local", data, options) {
17
+ if (fileType === data.type)
18
18
  return data;
19
19
  const common = (0, type_utils_js_1.pick)(data, "filename", "mimeType");
20
- switch (fileOutputType) {
21
- case FileOutputType.local: {
20
+ switch (fileType) {
21
+ case "local": {
22
22
  const dir = index_js_1.nodejs.path.join(index_js_1.nodejs.os.tmpdir(), options.context.id);
23
23
  await index_js_1.nodejs.fs.mkdir(dir, { recursive: true });
24
24
  const ext = Model.getFileExtension(data.mimeType || data.filename || "");
@@ -41,7 +41,7 @@ class Model extends agent_js_1.Agent {
41
41
  }
42
42
  return { ...common, type: "local", path, mimeType };
43
43
  }
44
- case FileOutputType.file: {
44
+ case "file": {
45
45
  let base64;
46
46
  let mimeType = data.mimeType;
47
47
  if (data.type === "local") {
@@ -75,11 +75,7 @@ class Model extends agent_js_1.Agent {
75
75
  }
76
76
  }
77
77
  exports.Model = Model;
78
- var FileOutputType;
79
- (function (FileOutputType) {
80
- FileOutputType["local"] = "local";
81
- FileOutputType["file"] = "file";
82
- })(FileOutputType || (exports.FileOutputType = FileOutputType = {}));
78
+ exports.fileTypeSchema = zod_1.z.enum(["local", "file"]);
83
79
  exports.fileContentBaseSchema = zod_1.z.object({
84
80
  filename: (0, schema_js_1.optionalize)(zod_1.z.string()),
85
81
  mimeType: (0, schema_js_1.optionalize)(zod_1.z.string()),
@@ -68,7 +68,7 @@ class PromptBuilder {
68
68
  responseFormat: options.agent?.structuredStreamMode
69
69
  ? undefined
70
70
  : this.buildResponseFormat(options),
71
- fileOutputType: options.agent?.fileOutputType,
71
+ outputFileType: options.agent?.outputFileType,
72
72
  ...this.buildTools(options),
73
73
  };
74
74
  }
@@ -87,9 +87,9 @@ class PromptBuilder {
87
87
  const messages = (await (typeof this.instructions === "string"
88
88
  ? template_js_1.ChatMessagesTemplate.from([template_js_1.SystemMessageTemplate.from(this.instructions)])
89
89
  : this.instructions)?.format(options.input, { workingDir: this.workingDir })) ?? [];
90
- const fileInputKey = options.agent?.fileInputKey;
91
- const files = (0, type_utils_js_1.flat)(fileInputKey
92
- ? (0, type_utils_js_1.checkArguments)("Check input files", (0, schema_js_1.optionalize)(model_js_1.fileUnionContentsSchema), input?.[fileInputKey])
90
+ const inputFileKey = options.agent?.inputFileKey;
91
+ const files = (0, type_utils_js_1.flat)(inputFileKey
92
+ ? (0, type_utils_js_1.checkArguments)("Check input files", (0, schema_js_1.optionalize)(model_js_1.fileUnionContentsSchema), input?.[inputFileKey])
93
93
  : null);
94
94
  const memories = [];
95
95
  if (options.agent && options.context) {
@@ -126,9 +126,9 @@ class PromptBuilder {
126
126
  const messages = [];
127
127
  const other = [];
128
128
  const inputKey = options.agent?.inputKey;
129
- const fileInputKey = options.agent?.fileInputKey;
129
+ const inputFileKey = options.agent?.inputFileKey;
130
130
  const outputKey = options.agent?.outputKey || ai_agent_js_1.DEFAULT_OUTPUT_KEY;
131
- const fileOutputKey = options.agent?.fileOutputKey || ai_agent_js_1.DEFAULT_FILE_OUTPUT_KEY;
131
+ const outputFileKey = options.agent?.outputFileKey || ai_agent_js_1.DEFAULT_OUTPUT_FILE_KEY;
132
132
  const stringOrStringify = (value) => typeof value === "string" ? value : (0, yaml_1.stringify)(value);
133
133
  const convertMemoryToMessage = async (content) => {
134
134
  const { input, output } = content;
@@ -138,7 +138,7 @@ class PromptBuilder {
138
138
  const userMessageContent = [];
139
139
  if (typeof input === "object") {
140
140
  const inputMessage = inputKey ? Reflect.get(input, inputKey) : undefined;
141
- const inputFiles = fileInputKey ? Reflect.get(input, fileInputKey) : undefined;
141
+ const inputFiles = inputFileKey ? Reflect.get(input, inputFileKey) : undefined;
142
142
  if (inputMessage) {
143
143
  userMessageContent.push({ type: "text", text: stringOrStringify(inputMessage) });
144
144
  }
@@ -153,7 +153,7 @@ class PromptBuilder {
153
153
  const agentMessageContent = [];
154
154
  if (typeof output === "object") {
155
155
  const outputMessage = Reflect.get(output, outputKey);
156
- const outputFiles = Reflect.get(output, fileOutputKey);
156
+ const outputFiles = Reflect.get(output, outputFileKey);
157
157
  if (outputMessage) {
158
158
  agentMessageContent.push({ type: "text", text: stringOrStringify(outputMessage) });
159
159
  }
@@ -3,9 +3,9 @@ import { PromptBuilder } from "../prompt/prompt-builder.js";
3
3
  import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessAsyncGenerator, type Message } from "./agent.js";
4
4
  import type { ChatModel, ChatModelInput } from "./chat-model.js";
5
5
  import type { GuideRailAgentOutput } from "./guide-rail-agent.js";
6
- import type { FileOutputType } from "./model.js";
6
+ import type { FileType } from "./model.js";
7
7
  export declare const DEFAULT_OUTPUT_KEY = "message";
8
- export declare const DEFAULT_FILE_OUTPUT_KEY = "files";
8
+ export declare const DEFAULT_OUTPUT_FILE_KEY = "files";
9
9
  /**
10
10
  * Configuration options for an AI Agent
11
11
  *
@@ -27,15 +27,15 @@ export interface AIAgentOptions<I extends Message = Message, O extends Message =
27
27
  * Pick a message from input to use as the user's message
28
28
  */
29
29
  inputKey?: string;
30
- fileInputKey?: string;
30
+ inputFileKey?: string;
31
31
  /**
32
32
  * Custom key to use for text output in the response
33
33
  *
34
34
  * Defaults to `message` if not specified
35
35
  */
36
36
  outputKey?: string;
37
- fileOutputKey?: string;
38
- fileOutputType?: FileOutputType;
37
+ outputFileKey?: string;
38
+ outputFileType?: FileType;
39
39
  /**
40
40
  * Controls how the agent uses tools during execution
41
41
  *
@@ -210,7 +210,7 @@ export declare class AIAgent<I extends Message = any, O extends Message = any> e
210
210
  * Pick a message from input to use as the user's message
211
211
  */
212
212
  inputKey?: string;
213
- fileInputKey?: string;
213
+ inputFileKey?: string;
214
214
  /**
215
215
  * Custom key to use for text output in the response
216
216
  *
@@ -219,8 +219,8 @@ export declare class AIAgent<I extends Message = any, O extends Message = any> e
219
219
  * {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-custom-output-key}
220
220
  */
221
221
  outputKey: string;
222
- fileOutputKey: string;
223
- fileOutputType?: FileOutputType;
222
+ outputFileKey: string;
223
+ outputFileType?: FileType;
224
224
  /**
225
225
  * Controls how the agent uses tools during execution
226
226
  *
@@ -1,12 +1,12 @@
1
1
  import { z } from "zod";
2
2
  import { type PromiseOrValue } from "../utils/type-utils.js";
3
3
  import { type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type AgentResponse, type AgentResponseStream, type Message } from "./agent.js";
4
- import { type FileOutputType, type FileUnionContent, Model } from "./model.js";
4
+ import { type FileType, type FileUnionContent, Model } from "./model.js";
5
5
  export declare class StructuredOutputError extends Error {
6
6
  }
7
7
  export interface ChatModelOptions extends Omit<AgentOptions<ChatModelInput, ChatModelOutput>, "model" | "inputSchema" | "outputSchema"> {
8
8
  model?: string;
9
- modelOptions?: Omit<ModelOptions, "model">;
9
+ modelOptions?: Omit<ChatModelInputOptions, "model">;
10
10
  }
11
11
  /**
12
12
  * ChatModel is an abstract base class for interacting with Large Language Models (LLMs).
@@ -135,7 +135,7 @@ export interface ChatModelInput extends Message {
135
135
  * Specifies the expected response format
136
136
  */
137
137
  responseFormat?: ChatModelInputResponseFormat;
138
- fileOutputType?: FileOutputType;
138
+ outputFileType?: FileType;
139
139
  /**
140
140
  * List of tools available for the model to use
141
141
  */
@@ -147,7 +147,7 @@ export interface ChatModelInput extends Message {
147
147
  /**
148
148
  * Model-specific configuration options
149
149
  */
150
- modelOptions?: ModelOptions;
150
+ modelOptions?: ChatModelInputOptions;
151
151
  }
152
152
  /**
153
153
  * Message role types
@@ -351,7 +351,7 @@ export type Modality = "text" | "image" | "audio";
351
351
  *
352
352
  * Contains various parameters for controlling model behavior, such as model name, temperature, etc.
353
353
  */
354
- export interface ModelOptions {
354
+ export interface ChatModelInputOptions {
355
355
  /**
356
356
  * Model name or version
357
357
  */
@@ -377,7 +377,7 @@ export interface ModelOptions {
377
377
  */
378
378
  parallelToolCalls?: boolean;
379
379
  modalities?: Modality[];
380
- preferFileInputType?: "file" | "url";
380
+ preferInputFileType?: "file" | "url";
381
381
  }
382
382
  /**
383
383
  * Output message format for ChatModel
@@ -2,11 +2,11 @@ import { type ZodObject, type ZodType } from "zod";
2
2
  import { PromptBuilder } from "../prompt/prompt-builder.js";
3
3
  import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from "./agent.js";
4
4
  import { type ImageModelOutput } from "./image-model.js";
5
- import type { FileOutputType } from "./model.js";
5
+ import { type FileType } from "./model.js";
6
6
  export interface ImageAgentOptions<I extends Message = any, O extends ImageModelOutput = any> extends Omit<AgentOptions<I, O>, "outputSchema"> {
7
7
  instructions: string | PromptBuilder;
8
8
  modelOptions?: Record<string, any>;
9
- outputType?: FileOutputType;
9
+ outputFileType?: FileType;
10
10
  }
11
11
  export declare const imageAgentOptionsSchema: ZodObject<{
12
12
  [key in keyof ImageAgentOptions]: ZodType<ImageAgentOptions[key]>;
@@ -17,6 +17,6 @@ export declare class ImageAgent<I extends Message = any, O extends ImageModelOut
17
17
  constructor(options: ImageAgentOptions<I, O>);
18
18
  instructions: PromptBuilder;
19
19
  modelOptions?: Record<string, any>;
20
- outputType?: FileOutputType;
20
+ outputFileType?: FileType;
21
21
  process(input: I, options: AgentInvokeOptions): Promise<O>;
22
22
  }
@@ -2,12 +2,15 @@ import { type ZodType, z } from "zod";
2
2
  import type { PromiseOrValue } from "../utils/type-utils.js";
3
3
  import type { AgentInvokeOptions, AgentOptions, AgentProcessResult, AgentResponse, AgentResponseStream, Message } from "./agent.js";
4
4
  import { type ChatModelOutputUsage } from "./chat-model.js";
5
- import { FileOutputType, type FileUnionContent, Model } from "./model.js";
5
+ import { type FileType, type FileUnionContent, Model } from "./model.js";
6
6
  export interface ImageModelOptions<I extends ImageModelInput = ImageModelInput, O extends ImageModelOutput = ImageModelOutput> extends Omit<AgentOptions<I, O>, "model"> {
7
+ model?: string;
8
+ modelOptions?: Omit<ImageModelInputOptions, "model">;
7
9
  }
8
10
  export declare abstract class ImageModel<I extends ImageModelInput = ImageModelInput, O extends ImageModelOutput = ImageModelOutput> extends Model<I, O> {
11
+ options?: ImageModelOptions<I, O> | undefined;
9
12
  tag: string;
10
- constructor(options?: ImageModelOptions<I, O>);
13
+ constructor(options?: ImageModelOptions<I, O> | undefined);
11
14
  get credential(): PromiseOrValue<{
12
15
  url?: string;
13
16
  apiKey?: string;
@@ -20,14 +23,18 @@ export declare abstract class ImageModel<I extends ImageModelInput = ImageModelI
20
23
  }
21
24
  export type ImageModelInputImage = FileUnionContent[];
22
25
  export interface ImageModelInput extends Message {
23
- model?: string;
24
- image?: ImageModelInputImage;
25
26
  prompt: string;
27
+ image?: ImageModelInputImage;
26
28
  n?: number;
27
- outputType?: FileOutputType;
29
+ outputFileType?: FileType;
30
+ modelOptions?: ImageModelInputOptions;
31
+ }
32
+ export interface ImageModelInputOptions extends Record<string, unknown> {
33
+ model?: string;
34
+ preferInputFileType?: "file" | "url";
28
35
  }
29
36
  export declare const imageModelInputSchema: z.ZodObject<{
30
- model: z.ZodOptional<z.ZodString>;
37
+ prompt: z.ZodString;
31
38
  image: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
32
39
  filename: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
33
40
  mimeType: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
@@ -77,12 +84,12 @@ export declare const imageModelInputSchema: z.ZodObject<{
77
84
  filename?: string | undefined;
78
85
  mimeType?: string | undefined;
79
86
  }>]>, "many">>;
80
- prompt: z.ZodString;
81
87
  n: z.ZodOptional<z.ZodNumber>;
82
- outputType: z.ZodOptional<z.ZodNativeEnum<typeof FileOutputType>>;
88
+ outputFileType: z.ZodOptional<z.ZodEnum<["local", "file"]>>;
89
+ modelOptions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
83
90
  }, "strip", z.ZodTypeAny, {
84
91
  prompt: string;
85
- model?: string | undefined;
92
+ modelOptions?: Record<string, unknown> | undefined;
86
93
  image?: ({
87
94
  type: "url";
88
95
  url: string;
@@ -99,11 +106,11 @@ export declare const imageModelInputSchema: z.ZodObject<{
99
106
  filename?: string | undefined;
100
107
  mimeType?: string | undefined;
101
108
  })[] | undefined;
109
+ outputFileType?: "local" | "file" | undefined;
102
110
  n?: number | undefined;
103
- outputType?: FileOutputType | undefined;
104
111
  }, {
105
112
  prompt: string;
106
- model?: string | undefined;
113
+ modelOptions?: Record<string, unknown> | undefined;
107
114
  image?: ({
108
115
  type: "url";
109
116
  url: string;
@@ -120,8 +127,8 @@ export declare const imageModelInputSchema: z.ZodObject<{
120
127
  filename?: string | undefined;
121
128
  mimeType?: string | undefined;
122
129
  })[] | undefined;
130
+ outputFileType?: "local" | "file" | undefined;
123
131
  n?: number | undefined;
124
- outputType?: FileOutputType | undefined;
125
132
  }>;
126
133
  export interface ImageModelOutput extends Message {
127
134
  images: FileUnionContent[];
@@ -1,17 +1,15 @@
1
1
  import { z } from "zod";
2
2
  import { Agent, type AgentInvokeOptions, type Message } from "./agent.js";
3
3
  export declare abstract class Model<I extends Message = any, O extends Message = any> extends Agent<I, O> {
4
- transformFileOutput(fileOutputType: FileOutputType.file, data: FileUnionContent, options: AgentInvokeOptions): Promise<FileContent>;
5
- transformFileOutput(fileOutputType: FileOutputType.local | undefined, data: FileUnionContent, options: AgentInvokeOptions): Promise<LocalContent>;
6
- transformFileOutput(fileOutputType: FileOutputType | undefined, data: FileUnionContent, options: AgentInvokeOptions): Promise<FileUnionContent>;
4
+ transformFileType(fileType: "file", data: FileUnionContent, options: AgentInvokeOptions): Promise<FileContent>;
5
+ transformFileType(fileType: "local" | undefined, data: FileUnionContent, options: AgentInvokeOptions): Promise<LocalContent>;
6
+ transformFileType(fileType: FileType | undefined, data: FileUnionContent, options: AgentInvokeOptions): Promise<FileUnionContent>;
7
7
  static getFileExtension(type: string): string | undefined;
8
8
  static getMimeType(filename: string): string | undefined;
9
9
  downloadFile(url: string): Promise<Response>;
10
10
  }
11
- export declare enum FileOutputType {
12
- local = "local",
13
- file = "file"
14
- }
11
+ export type FileType = "local" | "file";
12
+ export declare const fileTypeSchema: z.ZodEnum<["local", "file"]>;
15
13
  export interface FileContentBase {
16
14
  filename?: string;
17
15
  mimeType?: string;
@@ -3,9 +3,9 @@ import { PromptBuilder } from "../prompt/prompt-builder.js";
3
3
  import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessAsyncGenerator, type Message } from "./agent.js";
4
4
  import type { ChatModel, ChatModelInput } from "./chat-model.js";
5
5
  import type { GuideRailAgentOutput } from "./guide-rail-agent.js";
6
- import type { FileOutputType } from "./model.js";
6
+ import type { FileType } from "./model.js";
7
7
  export declare const DEFAULT_OUTPUT_KEY = "message";
8
- export declare const DEFAULT_FILE_OUTPUT_KEY = "files";
8
+ export declare const DEFAULT_OUTPUT_FILE_KEY = "files";
9
9
  /**
10
10
  * Configuration options for an AI Agent
11
11
  *
@@ -27,15 +27,15 @@ export interface AIAgentOptions<I extends Message = Message, O extends Message =
27
27
  * Pick a message from input to use as the user's message
28
28
  */
29
29
  inputKey?: string;
30
- fileInputKey?: string;
30
+ inputFileKey?: string;
31
31
  /**
32
32
  * Custom key to use for text output in the response
33
33
  *
34
34
  * Defaults to `message` if not specified
35
35
  */
36
36
  outputKey?: string;
37
- fileOutputKey?: string;
38
- fileOutputType?: FileOutputType;
37
+ outputFileKey?: string;
38
+ outputFileType?: FileType;
39
39
  /**
40
40
  * Controls how the agent uses tools during execution
41
41
  *
@@ -210,7 +210,7 @@ export declare class AIAgent<I extends Message = any, O extends Message = any> e
210
210
  * Pick a message from input to use as the user's message
211
211
  */
212
212
  inputKey?: string;
213
- fileInputKey?: string;
213
+ inputFileKey?: string;
214
214
  /**
215
215
  * Custom key to use for text output in the response
216
216
  *
@@ -219,8 +219,8 @@ export declare class AIAgent<I extends Message = any, O extends Message = any> e
219
219
  * {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-custom-output-key}
220
220
  */
221
221
  outputKey: string;
222
- fileOutputKey: string;
223
- fileOutputType?: FileOutputType;
222
+ outputFileKey: string;
223
+ outputFileType?: FileType;
224
224
  /**
225
225
  * Controls how the agent uses tools during execution
226
226
  *
@@ -7,7 +7,7 @@ import { checkArguments, isEmpty } from "../utils/type-utils.js";
7
7
  import { Agent, agentOptionsSchema, isAgentResponseDelta, } from "./agent.js";
8
8
  import { isTransferAgentOutput } from "./types.js";
9
9
  export const DEFAULT_OUTPUT_KEY = "message";
10
- export const DEFAULT_FILE_OUTPUT_KEY = "files";
10
+ export const DEFAULT_OUTPUT_FILE_KEY = "files";
11
11
  /**
12
12
  * Tool choice options for AI agents
13
13
  *
@@ -108,10 +108,10 @@ export class AIAgent extends Agent {
108
108
  ? PromptBuilder.from(options.instructions)
109
109
  : (options.instructions ?? new PromptBuilder());
110
110
  this.inputKey = options.inputKey;
111
- this.fileInputKey = options.fileInputKey;
111
+ this.inputFileKey = options.inputFileKey;
112
112
  this.outputKey = options.outputKey || DEFAULT_OUTPUT_KEY;
113
- this.fileOutputKey = options.fileOutputKey || DEFAULT_FILE_OUTPUT_KEY;
114
- this.fileOutputType = options.fileOutputType;
113
+ this.outputFileKey = options.outputFileKey || DEFAULT_OUTPUT_FILE_KEY;
114
+ this.outputFileType = options.outputFileType;
115
115
  this.toolChoice = options.toolChoice;
116
116
  this.memoryAgentsAsTools = options.memoryAgentsAsTools;
117
117
  this.memoryPromptTemplate = options.memoryPromptTemplate;
@@ -145,7 +145,7 @@ export class AIAgent extends Agent {
145
145
  * Pick a message from input to use as the user's message
146
146
  */
147
147
  inputKey;
148
- fileInputKey;
148
+ inputFileKey;
149
149
  /**
150
150
  * Custom key to use for text output in the response
151
151
  *
@@ -154,8 +154,8 @@ export class AIAgent extends Agent {
154
154
  * {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-custom-output-key}
155
155
  */
156
156
  outputKey;
157
- fileOutputKey;
158
- fileOutputType;
157
+ outputFileKey;
158
+ outputFileType;
159
159
  /**
160
160
  * Controls how the agent uses tools during execution
161
161
  *
@@ -306,7 +306,7 @@ export class AIAgent extends Agent {
306
306
  Object.assign(result, { [outputKey]: text });
307
307
  }
308
308
  if (files) {
309
- Object.assign(result, { [this.fileOutputKey]: files });
309
+ Object.assign(result, { [this.outputFileKey]: files });
310
310
  }
311
311
  if (!isEmpty(result)) {
312
312
  yield { delta: { json: result } };
@@ -1,12 +1,12 @@
1
1
  import { z } from "zod";
2
2
  import { type PromiseOrValue } from "../utils/type-utils.js";
3
3
  import { type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type AgentResponse, type AgentResponseStream, type Message } from "./agent.js";
4
- import { type FileOutputType, type FileUnionContent, Model } from "./model.js";
4
+ import { type FileType, type FileUnionContent, Model } from "./model.js";
5
5
  export declare class StructuredOutputError extends Error {
6
6
  }
7
7
  export interface ChatModelOptions extends Omit<AgentOptions<ChatModelInput, ChatModelOutput>, "model" | "inputSchema" | "outputSchema"> {
8
8
  model?: string;
9
- modelOptions?: Omit<ModelOptions, "model">;
9
+ modelOptions?: Omit<ChatModelInputOptions, "model">;
10
10
  }
11
11
  /**
12
12
  * ChatModel is an abstract base class for interacting with Large Language Models (LLMs).
@@ -135,7 +135,7 @@ export interface ChatModelInput extends Message {
135
135
  * Specifies the expected response format
136
136
  */
137
137
  responseFormat?: ChatModelInputResponseFormat;
138
- fileOutputType?: FileOutputType;
138
+ outputFileType?: FileType;
139
139
  /**
140
140
  * List of tools available for the model to use
141
141
  */
@@ -147,7 +147,7 @@ export interface ChatModelInput extends Message {
147
147
  /**
148
148
  * Model-specific configuration options
149
149
  */
150
- modelOptions?: ModelOptions;
150
+ modelOptions?: ChatModelInputOptions;
151
151
  }
152
152
  /**
153
153
  * Message role types
@@ -351,7 +351,7 @@ export type Modality = "text" | "image" | "audio";
351
351
  *
352
352
  * Contains various parameters for controlling model behavior, such as model name, temperature, etc.
353
353
  */
354
- export interface ModelOptions {
354
+ export interface ChatModelInputOptions {
355
355
  /**
356
356
  * Model name or version
357
357
  */
@@ -377,7 +377,7 @@ export interface ModelOptions {
377
377
  */
378
378
  parallelToolCalls?: boolean;
379
379
  modalities?: Modality[];
380
- preferFileInputType?: "file" | "url";
380
+ preferInputFileType?: "file" | "url";
381
381
  }
382
382
  /**
383
383
  * Output message format for ChatModel
@@ -149,8 +149,8 @@ export class ChatModel extends Model {
149
149
  mimeType: item.mimeType || ChatModel.getMimeType(item.filename || item.path),
150
150
  };
151
151
  }
152
- if ((input.modelOptions?.preferFileInputType ||
153
- this.options?.modelOptions?.preferFileInputType) !== "url") {
152
+ if ((input.modelOptions?.preferInputFileType ||
153
+ this.options?.modelOptions?.preferInputFileType) !== "url") {
154
154
  if (item.type === "url") {
155
155
  return {
156
156
  ...item,
@@ -203,7 +203,7 @@ export class ChatModel extends Model {
203
203
  const files = z.array(fileUnionContentSchema).parse(output.files);
204
204
  output = {
205
205
  ...output,
206
- files: await Promise.all(files.map((file) => this.transformFileOutput(input.fileOutputType, file, options))),
206
+ files: await Promise.all(files.map((file) => this.transformFileType(input.outputFileType, file, options))),
207
207
  };
208
208
  }
209
209
  // Remove fields with `null` value for validation
@@ -2,11 +2,11 @@ import { type ZodObject, type ZodType } from "zod";
2
2
  import { PromptBuilder } from "../prompt/prompt-builder.js";
3
3
  import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from "./agent.js";
4
4
  import { type ImageModelOutput } from "./image-model.js";
5
- import type { FileOutputType } from "./model.js";
5
+ import { type FileType } from "./model.js";
6
6
  export interface ImageAgentOptions<I extends Message = any, O extends ImageModelOutput = any> extends Omit<AgentOptions<I, O>, "outputSchema"> {
7
7
  instructions: string | PromptBuilder;
8
8
  modelOptions?: Record<string, any>;
9
- outputType?: FileOutputType;
9
+ outputFileType?: FileType;
10
10
  }
11
11
  export declare const imageAgentOptionsSchema: ZodObject<{
12
12
  [key in keyof ImageAgentOptions]: ZodType<ImageAgentOptions[key]>;
@@ -17,6 +17,6 @@ export declare class ImageAgent<I extends Message = any, O extends ImageModelOut
17
17
  constructor(options: ImageAgentOptions<I, O>);
18
18
  instructions: PromptBuilder;
19
19
  modelOptions?: Record<string, any>;
20
- outputType?: FileOutputType;
20
+ outputFileType?: FileType;
21
21
  process(input: I, options: AgentInvokeOptions): Promise<O>;
22
22
  }
@@ -3,9 +3,11 @@ import { PromptBuilder } from "../prompt/prompt-builder.js";
3
3
  import { checkArguments } from "../utils/type-utils.js";
4
4
  import { Agent, agentOptionsSchema, } from "./agent.js";
5
5
  import { imageModelOutputSchema } from "./image-model.js";
6
+ import { fileTypeSchema } from "./model.js";
6
7
  export const imageAgentOptionsSchema = agentOptionsSchema.extend({
7
8
  instructions: z.union([z.string(), z.custom()]),
8
9
  modelOptions: z.record(z.any()).optional(),
10
+ outputFileType: fileTypeSchema.optional(),
9
11
  });
10
12
  export class ImageAgent extends Agent {
11
13
  tag = "ImageAgent";
@@ -20,16 +22,16 @@ export class ImageAgent extends Agent {
20
22
  ? PromptBuilder.from(options.instructions)
21
23
  : options.instructions;
22
24
  this.modelOptions = options.modelOptions;
23
- this.outputType = options.outputType;
25
+ this.outputFileType = options.outputFileType;
24
26
  }
25
27
  instructions;
26
28
  modelOptions;
27
- outputType;
29
+ outputFileType;
28
30
  async process(input, options) {
29
31
  const imageModel = this.imageModel || options.imageModel || options.context.imageModel;
30
32
  if (!imageModel)
31
33
  throw new Error("image model is required to run ImageAgent");
32
34
  const { prompt } = await this.instructions.buildImagePrompt({ input });
33
- return (await this.invokeChildAgent(imageModel, { ...input, ...this.modelOptions, prompt, outputType: this.outputType }, { ...options, streaming: false }));
35
+ return (await this.invokeChildAgent(imageModel, { ...input, modelOptions: this.modelOptions, prompt, outputFileType: this.outputFileType }, { ...options, streaming: false }));
34
36
  }
35
37
  }
@@ -2,12 +2,15 @@ import { type ZodType, z } from "zod";
2
2
  import type { PromiseOrValue } from "../utils/type-utils.js";
3
3
  import type { AgentInvokeOptions, AgentOptions, AgentProcessResult, AgentResponse, AgentResponseStream, Message } from "./agent.js";
4
4
  import { type ChatModelOutputUsage } from "./chat-model.js";
5
- import { FileOutputType, type FileUnionContent, Model } from "./model.js";
5
+ import { type FileType, type FileUnionContent, Model } from "./model.js";
6
6
  export interface ImageModelOptions<I extends ImageModelInput = ImageModelInput, O extends ImageModelOutput = ImageModelOutput> extends Omit<AgentOptions<I, O>, "model"> {
7
+ model?: string;
8
+ modelOptions?: Omit<ImageModelInputOptions, "model">;
7
9
  }
8
10
  export declare abstract class ImageModel<I extends ImageModelInput = ImageModelInput, O extends ImageModelOutput = ImageModelOutput> extends Model<I, O> {
11
+ options?: ImageModelOptions<I, O> | undefined;
9
12
  tag: string;
10
- constructor(options?: ImageModelOptions<I, O>);
13
+ constructor(options?: ImageModelOptions<I, O> | undefined);
11
14
  get credential(): PromiseOrValue<{
12
15
  url?: string;
13
16
  apiKey?: string;
@@ -20,14 +23,18 @@ export declare abstract class ImageModel<I extends ImageModelInput = ImageModelI
20
23
  }
21
24
  export type ImageModelInputImage = FileUnionContent[];
22
25
  export interface ImageModelInput extends Message {
23
- model?: string;
24
- image?: ImageModelInputImage;
25
26
  prompt: string;
27
+ image?: ImageModelInputImage;
26
28
  n?: number;
27
- outputType?: FileOutputType;
29
+ outputFileType?: FileType;
30
+ modelOptions?: ImageModelInputOptions;
31
+ }
32
+ export interface ImageModelInputOptions extends Record<string, unknown> {
33
+ model?: string;
34
+ preferInputFileType?: "file" | "url";
28
35
  }
29
36
  export declare const imageModelInputSchema: z.ZodObject<{
30
- model: z.ZodOptional<z.ZodString>;
37
+ prompt: z.ZodString;
31
38
  image: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
32
39
  filename: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
33
40
  mimeType: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
@@ -77,12 +84,12 @@ export declare const imageModelInputSchema: z.ZodObject<{
77
84
  filename?: string | undefined;
78
85
  mimeType?: string | undefined;
79
86
  }>]>, "many">>;
80
- prompt: z.ZodString;
81
87
  n: z.ZodOptional<z.ZodNumber>;
82
- outputType: z.ZodOptional<z.ZodNativeEnum<typeof FileOutputType>>;
88
+ outputFileType: z.ZodOptional<z.ZodEnum<["local", "file"]>>;
89
+ modelOptions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
83
90
  }, "strip", z.ZodTypeAny, {
84
91
  prompt: string;
85
- model?: string | undefined;
92
+ modelOptions?: Record<string, unknown> | undefined;
86
93
  image?: ({
87
94
  type: "url";
88
95
  url: string;
@@ -99,11 +106,11 @@ export declare const imageModelInputSchema: z.ZodObject<{
99
106
  filename?: string | undefined;
100
107
  mimeType?: string | undefined;
101
108
  })[] | undefined;
109
+ outputFileType?: "local" | "file" | undefined;
102
110
  n?: number | undefined;
103
- outputType?: FileOutputType | undefined;
104
111
  }, {
105
112
  prompt: string;
106
- model?: string | undefined;
113
+ modelOptions?: Record<string, unknown> | undefined;
107
114
  image?: ({
108
115
  type: "url";
109
116
  url: string;
@@ -120,8 +127,8 @@ export declare const imageModelInputSchema: z.ZodObject<{
120
127
  filename?: string | undefined;
121
128
  mimeType?: string | undefined;
122
129
  })[] | undefined;
130
+ outputFileType?: "local" | "file" | undefined;
123
131
  n?: number | undefined;
124
- outputType?: FileOutputType | undefined;
125
132
  }>;
126
133
  export interface ImageModelOutput extends Message {
127
134
  images: FileUnionContent[];
@@ -1,15 +1,18 @@
1
1
  import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
2
2
  import { z } from "zod";
3
3
  import { chatModelOutputUsageSchema } from "./chat-model.js";
4
- import { FileOutputType, fileUnionContentSchema, Model } from "./model.js";
4
+ import { fileTypeSchema, fileUnionContentSchema, Model, } from "./model.js";
5
5
  export class ImageModel extends Model {
6
+ options;
6
7
  tag = "ImageModelAgent";
7
8
  constructor(options) {
8
9
  super({
9
10
  inputSchema: imageModelInputSchema,
10
11
  outputSchema: imageModelOutputSchema,
11
12
  ...options,
13
+ model: undefined,
12
14
  });
15
+ this.options = options;
13
16
  }
14
17
  get credential() {
15
18
  return {};
@@ -32,6 +35,18 @@ export class ImageModel extends Model {
32
35
  mimeType: item.mimeType || ImageModel.getMimeType(item.filename || item.path),
33
36
  };
34
37
  }
38
+ if ((input.modelOptions?.preferInputFileType ||
39
+ this.options?.modelOptions?.preferInputFileType) !== "url") {
40
+ if (item.type === "url") {
41
+ return {
42
+ ...item,
43
+ type: "file",
44
+ data: Buffer.from(await (await this.downloadFile(item.url)).arrayBuffer()).toString("base64"),
45
+ url: undefined,
46
+ mimeType: item.mimeType || ImageModel.getMimeType(item.filename || item.url),
47
+ };
48
+ }
49
+ }
35
50
  return item;
36
51
  }));
37
52
  }
@@ -51,18 +66,18 @@ export class ImageModel extends Model {
51
66
  const images = z.array(fileUnionContentSchema).parse(output.images);
52
67
  output = {
53
68
  ...output,
54
- images: await Promise.all(images.map((image) => this.transformFileOutput(input.outputType, image, options))),
69
+ images: await Promise.all(images.map((image) => this.transformFileType(input.outputFileType, image, options))),
55
70
  };
56
71
  }
57
72
  return super.processAgentOutput(input, output, options);
58
73
  }
59
74
  }
60
75
  export const imageModelInputSchema = z.object({
61
- model: z.string().optional(),
62
- image: z.array(fileUnionContentSchema).optional().describe("Images used for editing"),
63
76
  prompt: z.string(),
77
+ image: z.array(fileUnionContentSchema).optional().describe("Images used for editing"),
64
78
  n: z.number().int().min(1).optional(),
65
- outputType: z.nativeEnum(FileOutputType).optional(),
79
+ outputFileType: fileTypeSchema.optional(),
80
+ modelOptions: z.record(z.unknown()).optional(),
66
81
  });
67
82
  export const imageModelOutputSchema = z.object({
68
83
  images: z.array(fileUnionContentSchema),
@@ -1,17 +1,15 @@
1
1
  import { z } from "zod";
2
2
  import { Agent, type AgentInvokeOptions, type Message } from "./agent.js";
3
3
  export declare abstract class Model<I extends Message = any, O extends Message = any> extends Agent<I, O> {
4
- transformFileOutput(fileOutputType: FileOutputType.file, data: FileUnionContent, options: AgentInvokeOptions): Promise<FileContent>;
5
- transformFileOutput(fileOutputType: FileOutputType.local | undefined, data: FileUnionContent, options: AgentInvokeOptions): Promise<LocalContent>;
6
- transformFileOutput(fileOutputType: FileOutputType | undefined, data: FileUnionContent, options: AgentInvokeOptions): Promise<FileUnionContent>;
4
+ transformFileType(fileType: "file", data: FileUnionContent, options: AgentInvokeOptions): Promise<FileContent>;
5
+ transformFileType(fileType: "local" | undefined, data: FileUnionContent, options: AgentInvokeOptions): Promise<LocalContent>;
6
+ transformFileType(fileType: FileType | undefined, data: FileUnionContent, options: AgentInvokeOptions): Promise<FileUnionContent>;
7
7
  static getFileExtension(type: string): string | undefined;
8
8
  static getMimeType(filename: string): string | undefined;
9
9
  downloadFile(url: string): Promise<Response>;
10
10
  }
11
- export declare enum FileOutputType {
12
- local = "local",
13
- file = "file"
14
- }
11
+ export type FileType = "local" | "file";
12
+ export declare const fileTypeSchema: z.ZodEnum<["local", "file"]>;
15
13
  export interface FileContentBase {
16
14
  filename?: string;
17
15
  mimeType?: string;
@@ -7,12 +7,12 @@ import { optionalize } from "../loader/schema.js";
7
7
  import { pick } from "../utils/type-utils.js";
8
8
  import { Agent } from "./agent.js";
9
9
  export class Model extends Agent {
10
- async transformFileOutput(fileOutputType = FileOutputType.local, data, options) {
11
- if (fileOutputType === data.type)
10
+ async transformFileType(fileType = "local", data, options) {
11
+ if (fileType === data.type)
12
12
  return data;
13
13
  const common = pick(data, "filename", "mimeType");
14
- switch (fileOutputType) {
15
- case FileOutputType.local: {
14
+ switch (fileType) {
15
+ case "local": {
16
16
  const dir = nodejs.path.join(nodejs.os.tmpdir(), options.context.id);
17
17
  await nodejs.fs.mkdir(dir, { recursive: true });
18
18
  const ext = Model.getFileExtension(data.mimeType || data.filename || "");
@@ -35,7 +35,7 @@ export class Model extends Agent {
35
35
  }
36
36
  return { ...common, type: "local", path, mimeType };
37
37
  }
38
- case FileOutputType.file: {
38
+ case "file": {
39
39
  let base64;
40
40
  let mimeType = data.mimeType;
41
41
  if (data.type === "local") {
@@ -68,11 +68,7 @@ export class Model extends Agent {
68
68
  return response;
69
69
  }
70
70
  }
71
- export var FileOutputType;
72
- (function (FileOutputType) {
73
- FileOutputType["local"] = "local";
74
- FileOutputType["file"] = "file";
75
- })(FileOutputType || (FileOutputType = {}));
71
+ export const fileTypeSchema = z.enum(["local", "file"]);
76
72
  export const fileContentBaseSchema = z.object({
77
73
  filename: optionalize(z.string()),
78
74
  mimeType: optionalize(z.string()),
@@ -3,7 +3,7 @@ import { stringify } from "yaml";
3
3
  import { ZodObject } from "zod";
4
4
  import { zodToJsonSchema } from "zod-to-json-schema";
5
5
  import { Agent } from "../agents/agent.js";
6
- import { DEFAULT_FILE_OUTPUT_KEY, DEFAULT_OUTPUT_KEY } from "../agents/ai-agent.js";
6
+ import { DEFAULT_OUTPUT_FILE_KEY, DEFAULT_OUTPUT_KEY } from "../agents/ai-agent.js";
7
7
  import { fileUnionContentsSchema } from "../agents/model.js";
8
8
  import { optionalize } from "../loader/schema.js";
9
9
  import { outputSchemaToResponseFormatSchema } from "../utils/json-schema.js";
@@ -65,7 +65,7 @@ export class PromptBuilder {
65
65
  responseFormat: options.agent?.structuredStreamMode
66
66
  ? undefined
67
67
  : this.buildResponseFormat(options),
68
- fileOutputType: options.agent?.fileOutputType,
68
+ outputFileType: options.agent?.outputFileType,
69
69
  ...this.buildTools(options),
70
70
  };
71
71
  }
@@ -84,9 +84,9 @@ export class PromptBuilder {
84
84
  const messages = (await (typeof this.instructions === "string"
85
85
  ? ChatMessagesTemplate.from([SystemMessageTemplate.from(this.instructions)])
86
86
  : this.instructions)?.format(options.input, { workingDir: this.workingDir })) ?? [];
87
- const fileInputKey = options.agent?.fileInputKey;
88
- const files = flat(fileInputKey
89
- ? checkArguments("Check input files", optionalize(fileUnionContentsSchema), input?.[fileInputKey])
87
+ const inputFileKey = options.agent?.inputFileKey;
88
+ const files = flat(inputFileKey
89
+ ? checkArguments("Check input files", optionalize(fileUnionContentsSchema), input?.[inputFileKey])
90
90
  : null);
91
91
  const memories = [];
92
92
  if (options.agent && options.context) {
@@ -123,9 +123,9 @@ export class PromptBuilder {
123
123
  const messages = [];
124
124
  const other = [];
125
125
  const inputKey = options.agent?.inputKey;
126
- const fileInputKey = options.agent?.fileInputKey;
126
+ const inputFileKey = options.agent?.inputFileKey;
127
127
  const outputKey = options.agent?.outputKey || DEFAULT_OUTPUT_KEY;
128
- const fileOutputKey = options.agent?.fileOutputKey || DEFAULT_FILE_OUTPUT_KEY;
128
+ const outputFileKey = options.agent?.outputFileKey || DEFAULT_OUTPUT_FILE_KEY;
129
129
  const stringOrStringify = (value) => typeof value === "string" ? value : stringify(value);
130
130
  const convertMemoryToMessage = async (content) => {
131
131
  const { input, output } = content;
@@ -135,7 +135,7 @@ export class PromptBuilder {
135
135
  const userMessageContent = [];
136
136
  if (typeof input === "object") {
137
137
  const inputMessage = inputKey ? Reflect.get(input, inputKey) : undefined;
138
- const inputFiles = fileInputKey ? Reflect.get(input, fileInputKey) : undefined;
138
+ const inputFiles = inputFileKey ? Reflect.get(input, inputFileKey) : undefined;
139
139
  if (inputMessage) {
140
140
  userMessageContent.push({ type: "text", text: stringOrStringify(inputMessage) });
141
141
  }
@@ -150,7 +150,7 @@ export class PromptBuilder {
150
150
  const agentMessageContent = [];
151
151
  if (typeof output === "object") {
152
152
  const outputMessage = Reflect.get(output, outputKey);
153
- const outputFiles = Reflect.get(output, fileOutputKey);
153
+ const outputFiles = Reflect.get(output, outputFileKey);
154
154
  if (outputMessage) {
155
155
  agentMessageContent.push({ type: "text", text: stringOrStringify(outputMessage) });
156
156
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/core",
3
- "version": "1.61.0-beta",
3
+ "version": "1.61.0-beta.2",
4
4
  "description": "The functional core of agentic AI",
5
5
  "publishConfig": {
6
6
  "access": "public"