@aigne/core 1.60.3 → 1.61.0-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/lib/cjs/agents/ai-agent.d.ts +2 -1
  3. package/lib/cjs/agents/chat-model.d.ts +9 -245
  4. package/lib/cjs/agents/chat-model.js +9 -99
  5. package/lib/cjs/agents/image-agent.d.ts +3 -0
  6. package/lib/cjs/agents/image-agent.js +3 -1
  7. package/lib/cjs/agents/image-model.d.ts +157 -26
  8. package/lib/cjs/agents/image-model.js +28 -28
  9. package/lib/cjs/agents/model.d.ts +238 -0
  10. package/lib/cjs/agents/model.js +107 -0
  11. package/lib/cjs/index.d.ts +1 -0
  12. package/lib/cjs/index.js +1 -0
  13. package/lib/cjs/loader/agent-js.d.ts +1 -2
  14. package/lib/cjs/loader/agent-js.js +4 -4
  15. package/lib/cjs/loader/index.d.ts +0 -1
  16. package/lib/cjs/loader/index.js +1 -2
  17. package/lib/cjs/prompt/prompt-builder.d.ts +1 -1
  18. package/lib/cjs/prompt/prompt-builder.js +4 -4
  19. package/lib/dts/agents/ai-agent.d.ts +2 -1
  20. package/lib/dts/agents/chat-model.d.ts +9 -245
  21. package/lib/dts/agents/image-agent.d.ts +3 -0
  22. package/lib/dts/agents/image-model.d.ts +157 -26
  23. package/lib/dts/agents/model.d.ts +238 -0
  24. package/lib/dts/index.d.ts +1 -0
  25. package/lib/dts/loader/agent-js.d.ts +1 -2
  26. package/lib/dts/loader/index.d.ts +0 -1
  27. package/lib/dts/prompt/prompt-builder.d.ts +1 -1
  28. package/lib/esm/agents/ai-agent.d.ts +2 -1
  29. package/lib/esm/agents/chat-model.d.ts +9 -245
  30. package/lib/esm/agents/chat-model.js +5 -92
  31. package/lib/esm/agents/image-agent.d.ts +3 -0
  32. package/lib/esm/agents/image-agent.js +3 -1
  33. package/lib/esm/agents/image-model.d.ts +157 -26
  34. package/lib/esm/agents/image-model.js +28 -28
  35. package/lib/esm/agents/model.d.ts +238 -0
  36. package/lib/esm/agents/model.js +100 -0
  37. package/lib/esm/index.d.ts +1 -0
  38. package/lib/esm/index.js +1 -0
  39. package/lib/esm/loader/agent-js.d.ts +1 -2
  40. package/lib/esm/loader/agent-js.js +4 -4
  41. package/lib/esm/loader/index.d.ts +0 -1
  42. package/lib/esm/loader/index.js +1 -2
  43. package/lib/esm/prompt/prompt-builder.d.ts +1 -1
  44. package/lib/esm/prompt/prompt-builder.js +1 -1
  45. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Changelog
2
2
 
3
+ ## [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
+
5
+
6
+ ### Features
7
+
8
+ * improve image model architecture and file handling ([#527](https://github.com/AIGNE-io/aigne-framework/issues/527)) ([4db50aa](https://github.com/AIGNE-io/aigne-framework/commit/4db50aa0387a1a0f045ca11aaa61613e36ca7597))
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * resolve Windows file import URI issues ([#528](https://github.com/AIGNE-io/aigne-framework/issues/528)) ([bf807c5](https://github.com/AIGNE-io/aigne-framework/commit/bf807c5a3563c4423dc82fddff7fba280ef57957))
14
+
15
+
16
+ ### Dependencies
17
+
18
+ * The following workspace dependencies were updated
19
+ * dependencies
20
+ * @aigne/platform-helpers bumped to 0.6.3-beta
21
+
3
22
  ## [1.60.3](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.60.2...core-v1.60.3) (2025-09-18)
4
23
 
5
24
 
@@ -1,8 +1,9 @@
1
1
  import { type ZodObject, type ZodType, z } from "zod";
2
2
  import { PromptBuilder } from "../prompt/prompt-builder.js";
3
3
  import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessAsyncGenerator, type Message } from "./agent.js";
4
- import type { ChatModel, ChatModelInput, FileOutputType } from "./chat-model.js";
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
7
  export declare const DEFAULT_OUTPUT_KEY = "message";
7
8
  export declare const DEFAULT_FILE_OUTPUT_KEY = "files";
8
9
  /**
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { type PromiseOrValue } from "../utils/type-utils.js";
3
- import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type AgentResponse, type AgentResponseStream, type Message } from "./agent.js";
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
5
  export declare class StructuredOutputError extends Error {
5
6
  }
6
7
  export interface ChatModelOptions extends Omit<AgentOptions<ChatModelInput, ChatModelOutput>, "model" | "inputSchema" | "outputSchema"> {
@@ -30,7 +31,7 @@ export interface ChatModelOptions extends Omit<AgentOptions<ChatModelInput, Chat
30
31
  * Here's an example with tool calls:
31
32
  * {@includeCode ../../test/agents/chat-model.test.ts#example-chat-model-tools}
32
33
  */
33
- export declare abstract class ChatModel extends Agent<ChatModelInput, ChatModelOutput> {
34
+ export declare abstract class ChatModel extends Model<ChatModelInput, ChatModelOutput> {
34
35
  options?: ChatModelOptions | undefined;
35
36
  tag: string;
36
37
  constructor(options?: ChatModelOptions | undefined);
@@ -110,10 +111,6 @@ export declare abstract class ChatModel extends Agent<ChatModelInput, ChatModelO
110
111
  */
111
112
  abstract process(input: ChatModelInput, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
112
113
  protected processAgentOutput(input: ChatModelInput, output: Exclude<AgentResponse<ChatModelOutput>, AgentResponseStream<ChatModelOutput>>, options: AgentInvokeOptions): Promise<ChatModelOutput>;
113
- transformFileOutput(input: ChatModelInput, data: FileUnionContent, options: AgentInvokeOptions): Promise<FileUnionContent>;
114
- static getFileExtension(type: string): string | undefined;
115
- static getMimeType(filename: string): string | undefined;
116
- protected downloadFile(url: string): Promise<Response>;
117
114
  }
118
115
  /**
119
116
  * Input message format for ChatModel
@@ -221,235 +218,6 @@ export declare const textContentSchema: z.ZodObject<{
221
218
  type: "text";
222
219
  text: string;
223
220
  }>;
224
- export interface FileContentBase {
225
- filename?: string;
226
- mimeType?: string;
227
- }
228
- export declare const fileContentBaseSchema: z.ZodObject<{
229
- filename: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
230
- mimeType: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
231
- }, "strip", z.ZodTypeAny, {
232
- mimeType?: string | undefined;
233
- filename?: string | undefined;
234
- }, {
235
- mimeType?: string | undefined;
236
- filename?: string | undefined;
237
- }>;
238
- /**
239
- * Image URL content type
240
- *
241
- * Used for image parts of message content, referencing images via URL
242
- */
243
- export interface UrlContent extends FileContentBase {
244
- type: "url";
245
- url: string;
246
- }
247
- export declare const urlContentSchema: z.ZodObject<{
248
- filename: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
249
- mimeType: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
250
- } & {
251
- type: z.ZodLiteral<"url">;
252
- url: z.ZodString;
253
- }, "strip", z.ZodTypeAny, {
254
- type: "url";
255
- url: string;
256
- mimeType?: string | undefined;
257
- filename?: string | undefined;
258
- }, {
259
- type: "url";
260
- url: string;
261
- mimeType?: string | undefined;
262
- filename?: string | undefined;
263
- }>;
264
- export interface FileContent extends FileContentBase {
265
- type: "file";
266
- data: string;
267
- }
268
- export declare const fileContentSchema: z.ZodObject<{
269
- filename: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
270
- mimeType: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
271
- } & {
272
- type: z.ZodLiteral<"file">;
273
- data: z.ZodString;
274
- }, "strip", z.ZodTypeAny, {
275
- type: "file";
276
- data: string;
277
- mimeType?: string | undefined;
278
- filename?: string | undefined;
279
- }, {
280
- type: "file";
281
- data: string;
282
- mimeType?: string | undefined;
283
- filename?: string | undefined;
284
- }>;
285
- export interface LocalContent extends FileContentBase {
286
- type: "local";
287
- path: string;
288
- }
289
- export declare const localContentSchema: z.ZodObject<{
290
- filename: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
291
- mimeType: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
292
- } & {
293
- type: z.ZodLiteral<"local">;
294
- path: z.ZodString;
295
- }, "strip", z.ZodTypeAny, {
296
- path: string;
297
- type: "local";
298
- mimeType?: string | undefined;
299
- filename?: string | undefined;
300
- }, {
301
- path: string;
302
- type: "local";
303
- mimeType?: string | undefined;
304
- filename?: string | undefined;
305
- }>;
306
- export type FileUnionContent = LocalContent | UrlContent | FileContent;
307
- export declare const fileUnionContentSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
308
- filename: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
309
- mimeType: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
310
- } & {
311
- type: z.ZodLiteral<"local">;
312
- path: z.ZodString;
313
- }, "strip", z.ZodTypeAny, {
314
- path: string;
315
- type: "local";
316
- mimeType?: string | undefined;
317
- filename?: string | undefined;
318
- }, {
319
- path: string;
320
- type: "local";
321
- mimeType?: string | undefined;
322
- filename?: string | undefined;
323
- }>, z.ZodObject<{
324
- filename: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
325
- mimeType: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
326
- } & {
327
- type: z.ZodLiteral<"url">;
328
- url: z.ZodString;
329
- }, "strip", z.ZodTypeAny, {
330
- type: "url";
331
- url: string;
332
- mimeType?: string | undefined;
333
- filename?: string | undefined;
334
- }, {
335
- type: "url";
336
- url: string;
337
- mimeType?: string | undefined;
338
- filename?: string | undefined;
339
- }>, z.ZodObject<{
340
- filename: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
341
- mimeType: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
342
- } & {
343
- type: z.ZodLiteral<"file">;
344
- data: z.ZodString;
345
- }, "strip", z.ZodTypeAny, {
346
- type: "file";
347
- data: string;
348
- mimeType?: string | undefined;
349
- filename?: string | undefined;
350
- }, {
351
- type: "file";
352
- data: string;
353
- mimeType?: string | undefined;
354
- filename?: string | undefined;
355
- }>]>;
356
- export declare const fileUnionContentsSchema: z.ZodUnion<[z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
357
- filename: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
358
- mimeType: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
359
- } & {
360
- type: z.ZodLiteral<"local">;
361
- path: z.ZodString;
362
- }, "strip", z.ZodTypeAny, {
363
- path: string;
364
- type: "local";
365
- mimeType?: string | undefined;
366
- filename?: string | undefined;
367
- }, {
368
- path: string;
369
- type: "local";
370
- mimeType?: string | undefined;
371
- filename?: string | undefined;
372
- }>, z.ZodObject<{
373
- filename: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
374
- mimeType: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
375
- } & {
376
- type: z.ZodLiteral<"url">;
377
- url: z.ZodString;
378
- }, "strip", z.ZodTypeAny, {
379
- type: "url";
380
- url: string;
381
- mimeType?: string | undefined;
382
- filename?: string | undefined;
383
- }, {
384
- type: "url";
385
- url: string;
386
- mimeType?: string | undefined;
387
- filename?: string | undefined;
388
- }>, z.ZodObject<{
389
- filename: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
390
- mimeType: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
391
- } & {
392
- type: z.ZodLiteral<"file">;
393
- data: z.ZodString;
394
- }, "strip", z.ZodTypeAny, {
395
- type: "file";
396
- data: string;
397
- mimeType?: string | undefined;
398
- filename?: string | undefined;
399
- }, {
400
- type: "file";
401
- data: string;
402
- mimeType?: string | undefined;
403
- filename?: string | undefined;
404
- }>]>, z.ZodArray<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
405
- filename: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
406
- mimeType: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
407
- } & {
408
- type: z.ZodLiteral<"local">;
409
- path: z.ZodString;
410
- }, "strip", z.ZodTypeAny, {
411
- path: string;
412
- type: "local";
413
- mimeType?: string | undefined;
414
- filename?: string | undefined;
415
- }, {
416
- path: string;
417
- type: "local";
418
- mimeType?: string | undefined;
419
- filename?: string | undefined;
420
- }>, z.ZodObject<{
421
- filename: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
422
- mimeType: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
423
- } & {
424
- type: z.ZodLiteral<"url">;
425
- url: z.ZodString;
426
- }, "strip", z.ZodTypeAny, {
427
- type: "url";
428
- url: string;
429
- mimeType?: string | undefined;
430
- filename?: string | undefined;
431
- }, {
432
- type: "url";
433
- url: string;
434
- mimeType?: string | undefined;
435
- filename?: string | undefined;
436
- }>, z.ZodObject<{
437
- filename: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
438
- mimeType: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
439
- } & {
440
- type: z.ZodLiteral<"file">;
441
- data: z.ZodString;
442
- }, "strip", z.ZodTypeAny, {
443
- type: "file";
444
- data: string;
445
- mimeType?: string | undefined;
446
- filename?: string | undefined;
447
- }, {
448
- type: "file";
449
- data: string;
450
- mimeType?: string | undefined;
451
- filename?: string | undefined;
452
- }>]>, "many">]>;
453
221
  export type UnionContent = TextContent | FileUnionContent;
454
222
  export declare const unionContentSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
455
223
  type: z.ZodLiteral<"text">;
@@ -469,13 +237,13 @@ export declare const unionContentSchema: z.ZodDiscriminatedUnion<"type", [z.ZodO
469
237
  }, "strip", z.ZodTypeAny, {
470
238
  path: string;
471
239
  type: "local";
472
- mimeType?: string | undefined;
473
240
  filename?: string | undefined;
241
+ mimeType?: string | undefined;
474
242
  }, {
475
243
  path: string;
476
244
  type: "local";
477
- mimeType?: string | undefined;
478
245
  filename?: string | undefined;
246
+ mimeType?: string | undefined;
479
247
  }>, z.ZodObject<{
480
248
  filename: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
481
249
  mimeType: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
@@ -485,13 +253,13 @@ export declare const unionContentSchema: z.ZodDiscriminatedUnion<"type", [z.ZodO
485
253
  }, "strip", z.ZodTypeAny, {
486
254
  type: "url";
487
255
  url: string;
488
- mimeType?: string | undefined;
489
256
  filename?: string | undefined;
257
+ mimeType?: string | undefined;
490
258
  }, {
491
259
  type: "url";
492
260
  url: string;
493
- mimeType?: string | undefined;
494
261
  filename?: string | undefined;
262
+ mimeType?: string | undefined;
495
263
  }>, z.ZodObject<{
496
264
  filename: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
497
265
  mimeType: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
@@ -501,13 +269,13 @@ export declare const unionContentSchema: z.ZodDiscriminatedUnion<"type", [z.ZodO
501
269
  }, "strip", z.ZodTypeAny, {
502
270
  type: "file";
503
271
  data: string;
504
- mimeType?: string | undefined;
505
272
  filename?: string | undefined;
273
+ mimeType?: string | undefined;
506
274
  }, {
507
275
  type: "file";
508
276
  data: string;
509
- mimeType?: string | undefined;
510
277
  filename?: string | undefined;
278
+ mimeType?: string | undefined;
511
279
  }>]>;
512
280
  /**
513
281
  * Model response format settings
@@ -647,10 +415,6 @@ export interface ChatModelOutput extends Message {
647
415
  model?: string;
648
416
  files?: FileUnionContent[];
649
417
  }
650
- export declare enum FileOutputType {
651
- local = "local",
652
- file = "file"
653
- }
654
418
  /**
655
419
  * Tool call information in model output
656
420
  *
@@ -32,19 +32,14 @@ var __importStar = (this && this.__importStar) || (function () {
32
32
  return result;
33
33
  };
34
34
  })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
35
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.chatModelOutputUsageSchema = exports.FileOutputType = exports.unionContentSchema = exports.fileUnionContentsSchema = exports.fileUnionContentSchema = exports.localContentSchema = exports.fileContentSchema = exports.urlContentSchema = exports.fileContentBaseSchema = exports.textContentSchema = exports.ChatModel = exports.StructuredOutputError = void 0;
36
+ exports.chatModelOutputUsageSchema = exports.unionContentSchema = exports.textContentSchema = exports.ChatModel = exports.StructuredOutputError = void 0;
40
37
  const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
41
38
  const ajv_1 = require("ajv");
42
- const mime_1 = __importDefault(require("mime"));
43
- const uuid_1 = require("uuid");
44
39
  const zod_1 = require("zod");
45
- const schema_js_1 = require("../loader/schema.js");
46
40
  const type_utils_js_1 = require("../utils/type-utils.js");
47
41
  const agent_js_1 = require("./agent.js");
42
+ const model_js_1 = require("./model.js");
48
43
  const CHAT_MODEL_DEFAULT_RETRY_OPTIONS = {
49
44
  retries: 3,
50
45
  shouldRetry: async (error) => error instanceof StructuredOutputError || (await Promise.resolve().then(() => __importStar(require("is-network-error")))).default(error),
@@ -75,7 +70,7 @@ exports.StructuredOutputError = StructuredOutputError;
75
70
  * Here's an example with tool calls:
76
71
  * {@includeCode ../../test/agents/chat-model.test.ts#example-chat-model-tools}
77
72
  */
78
- class ChatModel extends agent_js_1.Agent {
73
+ class ChatModel extends model_js_1.Model {
79
74
  options;
80
75
  tag = "ChatModelAgent";
81
76
  constructor(options) {
@@ -242,10 +237,10 @@ class ChatModel extends agent_js_1.Agent {
242
237
  }
243
238
  async processAgentOutput(input, output, options) {
244
239
  if (output.files) {
245
- const files = zod_1.z.array(exports.fileUnionContentSchema).parse(output.files);
240
+ const files = zod_1.z.array(model_js_1.fileUnionContentSchema).parse(output.files);
246
241
  output = {
247
242
  ...output,
248
- files: await Promise.all(files.map((file) => this.transformFileOutput(input, file, options))),
243
+ files: await Promise.all(files.map((file) => this.transformFileOutput(input.fileOutputType, file, options))),
249
244
  };
250
245
  }
251
246
  // Remove fields with `null` value for validation
@@ -260,97 +255,17 @@ class ChatModel extends agent_js_1.Agent {
260
255
  }
261
256
  return super.processAgentOutput(input, output, options);
262
257
  }
263
- async transformFileOutput(input, data, options) {
264
- const fileOutputType = input.fileOutputType || FileOutputType.local;
265
- if (fileOutputType === data.type)
266
- return data;
267
- const common = (0, type_utils_js_1.pick)(data, "filename", "mimeType");
268
- switch (fileOutputType) {
269
- case FileOutputType.local: {
270
- const dir = index_js_1.nodejs.path.join(index_js_1.nodejs.os.tmpdir(), options.context.id);
271
- await index_js_1.nodejs.fs.mkdir(dir, { recursive: true });
272
- const ext = ChatModel.getFileExtension(data.mimeType || data.filename || "");
273
- const id = (0, uuid_1.v7)();
274
- const filename = ext ? `${id}.${ext}` : id;
275
- const path = index_js_1.nodejs.path.join(dir, filename);
276
- if (data.type === "file") {
277
- await index_js_1.nodejs.fs.writeFile(path, data.data, "base64");
278
- }
279
- else if (data.type === "url") {
280
- await this.downloadFile(data.url)
281
- .then((res) => res.body)
282
- .then((body) => body && index_js_1.nodejs.fs.writeFile(path, body));
283
- }
284
- else {
285
- throw new Error(`Unexpected file type: ${data.type}`);
286
- }
287
- return { ...common, type: "local", path };
288
- }
289
- case FileOutputType.file: {
290
- let base64;
291
- if (data.type === "local") {
292
- base64 = await index_js_1.nodejs.fs.readFile(data.path, "base64");
293
- }
294
- else if (data.type === "url") {
295
- base64 = Buffer.from(await (await this.downloadFile(data.url)).arrayBuffer()).toString("base64");
296
- }
297
- else {
298
- throw new Error(`Unexpected file type: ${data.type}`);
299
- }
300
- return { ...common, type: "file", data: base64 };
301
- }
302
- }
303
- }
304
- static getFileExtension(type) {
305
- return mime_1.default.getExtension(type) || undefined;
306
- }
307
- static getMimeType(filename) {
308
- return mime_1.default.getType(filename) || undefined;
309
- }
310
- async downloadFile(url) {
311
- const response = await fetch(url);
312
- if (!response.ok) {
313
- const text = await response.text().catch(() => null);
314
- throw new Error(`Failed to download content from ${url}, ${response.status} ${response.statusText} ${text}`);
315
- }
316
- return response;
317
- }
318
258
  }
319
259
  exports.ChatModel = ChatModel;
320
260
  exports.textContentSchema = zod_1.z.object({
321
261
  type: zod_1.z.literal("text"),
322
262
  text: zod_1.z.string(),
323
263
  });
324
- exports.fileContentBaseSchema = zod_1.z.object({
325
- filename: (0, schema_js_1.optionalize)(zod_1.z.string()),
326
- mimeType: (0, schema_js_1.optionalize)(zod_1.z.string()),
327
- });
328
- exports.urlContentSchema = exports.fileContentBaseSchema.extend({
329
- type: zod_1.z.literal("url"),
330
- url: zod_1.z.string(),
331
- });
332
- exports.fileContentSchema = exports.fileContentBaseSchema.extend({
333
- type: zod_1.z.literal("file"),
334
- data: zod_1.z.string(),
335
- });
336
- exports.localContentSchema = exports.fileContentBaseSchema.extend({
337
- type: zod_1.z.literal("local"),
338
- path: zod_1.z.string(),
339
- });
340
- exports.fileUnionContentSchema = zod_1.z.discriminatedUnion("type", [
341
- exports.localContentSchema,
342
- exports.urlContentSchema,
343
- exports.fileContentSchema,
344
- ]);
345
- exports.fileUnionContentsSchema = zod_1.z.union([
346
- exports.fileUnionContentSchema,
347
- zod_1.z.array(exports.fileUnionContentSchema),
348
- ]);
349
264
  exports.unionContentSchema = zod_1.z.discriminatedUnion("type", [
350
265
  exports.textContentSchema,
351
- exports.localContentSchema,
352
- exports.urlContentSchema,
353
- exports.fileContentSchema,
266
+ model_js_1.localContentSchema,
267
+ model_js_1.urlContentSchema,
268
+ model_js_1.fileContentSchema,
354
269
  ]);
355
270
  const chatModelInputMessageSchema = zod_1.z.object({
356
271
  role: zod_1.z.union([zod_1.z.literal("system"), zod_1.z.literal("user"), zod_1.z.literal("agent"), zod_1.z.literal("tool")]),
@@ -414,11 +329,6 @@ const chatModelInputSchema = zod_1.z.object({
414
329
  toolChoice: chatModelInputToolChoiceSchema.optional(),
415
330
  modelOptions: modelOptionsSchema.optional(),
416
331
  });
417
- var FileOutputType;
418
- (function (FileOutputType) {
419
- FileOutputType["local"] = "local";
420
- FileOutputType["file"] = "file";
421
- })(FileOutputType || (exports.FileOutputType = FileOutputType = {}));
422
332
  const chatModelOutputToolCallSchema = zod_1.z.object({
423
333
  id: zod_1.z.string(),
424
334
  type: zod_1.z.literal("function"),
@@ -438,5 +348,5 @@ const chatModelOutputSchema = zod_1.z.object({
438
348
  toolCalls: zod_1.z.array(chatModelOutputToolCallSchema).optional(),
439
349
  usage: exports.chatModelOutputUsageSchema.optional(),
440
350
  model: zod_1.z.string().optional(),
441
- files: zod_1.z.array(exports.fileUnionContentSchema).optional(),
351
+ files: zod_1.z.array(model_js_1.fileUnionContentSchema).optional(),
442
352
  });
@@ -2,9 +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
6
  export interface ImageAgentOptions<I extends Message = any, O extends ImageModelOutput = any> extends Omit<AgentOptions<I, O>, "outputSchema"> {
6
7
  instructions: string | PromptBuilder;
7
8
  modelOptions?: Record<string, any>;
9
+ outputType?: FileOutputType;
8
10
  }
9
11
  export declare const imageAgentOptionsSchema: ZodObject<{
10
12
  [key in keyof ImageAgentOptions]: ZodType<ImageAgentOptions[key]>;
@@ -15,5 +17,6 @@ export declare class ImageAgent<I extends Message = any, O extends ImageModelOut
15
17
  constructor(options: ImageAgentOptions<I, O>);
16
18
  instructions: PromptBuilder;
17
19
  modelOptions?: Record<string, any>;
20
+ outputType?: FileOutputType;
18
21
  process(input: I, options: AgentInvokeOptions): Promise<O>;
19
22
  }
@@ -26,15 +26,17 @@ class ImageAgent extends agent_js_1.Agent {
26
26
  ? prompt_builder_js_1.PromptBuilder.from(options.instructions)
27
27
  : options.instructions;
28
28
  this.modelOptions = options.modelOptions;
29
+ this.outputType = options.outputType;
29
30
  }
30
31
  instructions;
31
32
  modelOptions;
33
+ outputType;
32
34
  async process(input, options) {
33
35
  const imageModel = this.imageModel || options.imageModel || options.context.imageModel;
34
36
  if (!imageModel)
35
37
  throw new Error("image model is required to run ImageAgent");
36
38
  const { prompt } = await this.instructions.buildImagePrompt({ input });
37
- return (await this.invokeChildAgent(imageModel, { ...input, ...this.modelOptions, prompt }, { ...options, streaming: false }));
39
+ return (await this.invokeChildAgent(imageModel, { ...input, ...this.modelOptions, prompt, outputType: this.outputType }, { ...options, streaming: false }));
38
40
  }
39
41
  }
40
42
  exports.ImageAgent = ImageAgent;