@aigne/core 1.60.3 → 1.61.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.
Files changed (47) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/lib/cjs/agents/ai-agent.d.ts +9 -8
  3. package/lib/cjs/agents/ai-agent.js +9 -9
  4. package/lib/cjs/agents/chat-model.d.ts +14 -250
  5. package/lib/cjs/agents/chat-model.js +11 -101
  6. package/lib/cjs/agents/image-agent.d.ts +3 -0
  7. package/lib/cjs/agents/image-agent.js +5 -1
  8. package/lib/cjs/agents/image-model.d.ts +164 -30
  9. package/lib/cjs/agents/image-model.js +29 -29
  10. package/lib/cjs/agents/model.d.ts +236 -0
  11. package/lib/cjs/agents/model.js +103 -0
  12. package/lib/cjs/index.d.ts +1 -0
  13. package/lib/cjs/index.js +1 -0
  14. package/lib/cjs/loader/agent-js.d.ts +1 -2
  15. package/lib/cjs/loader/agent-js.js +4 -4
  16. package/lib/cjs/loader/index.d.ts +0 -1
  17. package/lib/cjs/loader/index.js +1 -2
  18. package/lib/cjs/prompt/prompt-builder.d.ts +1 -1
  19. package/lib/cjs/prompt/prompt-builder.js +11 -11
  20. package/lib/dts/agents/ai-agent.d.ts +9 -8
  21. package/lib/dts/agents/chat-model.d.ts +14 -250
  22. package/lib/dts/agents/image-agent.d.ts +3 -0
  23. package/lib/dts/agents/image-model.d.ts +164 -30
  24. package/lib/dts/agents/model.d.ts +236 -0
  25. package/lib/dts/index.d.ts +1 -0
  26. package/lib/dts/loader/agent-js.d.ts +1 -2
  27. package/lib/dts/loader/index.d.ts +0 -1
  28. package/lib/dts/prompt/prompt-builder.d.ts +1 -1
  29. package/lib/esm/agents/ai-agent.d.ts +9 -8
  30. package/lib/esm/agents/ai-agent.js +8 -8
  31. package/lib/esm/agents/chat-model.d.ts +14 -250
  32. package/lib/esm/agents/chat-model.js +7 -94
  33. package/lib/esm/agents/image-agent.d.ts +3 -0
  34. package/lib/esm/agents/image-agent.js +5 -1
  35. package/lib/esm/agents/image-model.d.ts +164 -30
  36. package/lib/esm/agents/image-model.js +29 -29
  37. package/lib/esm/agents/model.d.ts +236 -0
  38. package/lib/esm/agents/model.js +96 -0
  39. package/lib/esm/index.d.ts +1 -0
  40. package/lib/esm/index.js +1 -0
  41. package/lib/esm/loader/agent-js.d.ts +1 -2
  42. package/lib/esm/loader/agent-js.js +4 -4
  43. package/lib/esm/loader/index.d.ts +0 -1
  44. package/lib/esm/loader/index.js +1 -2
  45. package/lib/esm/prompt/prompt-builder.d.ts +1 -1
  46. package/lib/esm/prompt/prompt-builder.js +10 -10
  47. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # Changelog
2
2
 
3
+ ## [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)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * 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))
9
+
10
+ ## [1.61.0-beta](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.60.3...core-v1.61.0-beta) (2025-09-22)
11
+
12
+
13
+ ### Features
14
+
15
+ * 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))
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * 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))
21
+
22
+
23
+ ### Dependencies
24
+
25
+ * The following workspace dependencies were updated
26
+ * dependencies
27
+ * @aigne/platform-helpers bumped to 0.6.3-beta
28
+
3
29
  ## [1.60.3](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.60.2...core-v1.60.3) (2025-09-18)
4
30
 
5
31
 
@@ -1,10 +1,11 @@
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 { FileType } from "./model.js";
6
7
  export declare const DEFAULT_OUTPUT_KEY = "message";
7
- export declare const DEFAULT_FILE_OUTPUT_KEY = "files";
8
+ export declare const DEFAULT_OUTPUT_FILE_KEY = "files";
8
9
  /**
9
10
  * Configuration options for an AI Agent
10
11
  *
@@ -26,15 +27,15 @@ export interface AIAgentOptions<I extends Message = Message, O extends Message =
26
27
  * Pick a message from input to use as the user's message
27
28
  */
28
29
  inputKey?: string;
29
- fileInputKey?: string;
30
+ inputFileKey?: string;
30
31
  /**
31
32
  * Custom key to use for text output in the response
32
33
  *
33
34
  * Defaults to `message` if not specified
34
35
  */
35
36
  outputKey?: string;
36
- fileOutputKey?: string;
37
- fileOutputType?: FileOutputType;
37
+ outputFileKey?: string;
38
+ outputFileType?: FileType;
38
39
  /**
39
40
  * Controls how the agent uses tools during execution
40
41
  *
@@ -209,7 +210,7 @@ export declare class AIAgent<I extends Message = any, O extends Message = any> e
209
210
  * Pick a message from input to use as the user's message
210
211
  */
211
212
  inputKey?: string;
212
- fileInputKey?: string;
213
+ inputFileKey?: string;
213
214
  /**
214
215
  * Custom key to use for text output in the response
215
216
  *
@@ -218,8 +219,8 @@ export declare class AIAgent<I extends Message = any, O extends Message = any> e
218
219
  * {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-custom-output-key}
219
220
  */
220
221
  outputKey: string;
221
- fileOutputKey: string;
222
- fileOutputType?: FileOutputType;
222
+ outputFileKey: string;
223
+ outputFileType?: FileType;
223
224
  /**
224
225
  * Controls how the agent uses tools during execution
225
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,11 +1,12 @@
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 FileType, 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"> {
7
8
  model?: string;
8
- modelOptions?: Omit<ModelOptions, "model">;
9
+ modelOptions?: Omit<ChatModelInputOptions, "model">;
9
10
  }
10
11
  /**
11
12
  * ChatModel is an abstract base class for interacting with Large Language Models (LLMs).
@@ -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
@@ -138,7 +135,7 @@ export interface ChatModelInput extends Message {
138
135
  * Specifies the expected response format
139
136
  */
140
137
  responseFormat?: ChatModelInputResponseFormat;
141
- fileOutputType?: FileOutputType;
138
+ outputFileType?: FileType;
142
139
  /**
143
140
  * List of tools available for the model to use
144
141
  */
@@ -150,7 +147,7 @@ export interface ChatModelInput extends Message {
150
147
  /**
151
148
  * Model-specific configuration options
152
149
  */
153
- modelOptions?: ModelOptions;
150
+ modelOptions?: ChatModelInputOptions;
154
151
  }
155
152
  /**
156
153
  * Message role types
@@ -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
@@ -583,7 +351,7 @@ export type Modality = "text" | "image" | "audio";
583
351
  *
584
352
  * Contains various parameters for controlling model behavior, such as model name, temperature, etc.
585
353
  */
586
- export interface ModelOptions {
354
+ export interface ChatModelInputOptions {
587
355
  /**
588
356
  * Model name or version
589
357
  */
@@ -609,7 +377,7 @@ export interface ModelOptions {
609
377
  */
610
378
  parallelToolCalls?: boolean;
611
379
  modalities?: Modality[];
612
- preferFileInputType?: "file" | "url";
380
+ preferInputFileType?: "file" | "url";
613
381
  }
614
382
  /**
615
383
  * Output message format for ChatModel
@@ -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) {
@@ -191,8 +186,8 @@ class ChatModel extends agent_js_1.Agent {
191
186
  mimeType: item.mimeType || ChatModel.getMimeType(item.filename || item.path),
192
187
  };
193
188
  }
194
- if ((input.modelOptions?.preferFileInputType ||
195
- this.options?.modelOptions?.preferFileInputType) !== "url") {
189
+ if ((input.modelOptions?.preferInputFileType ||
190
+ this.options?.modelOptions?.preferInputFileType) !== "url") {
196
191
  if (item.type === "url") {
197
192
  return {
198
193
  ...item,
@@ -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.transformFileType(input.outputFileType, 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
  });