@aigne/core 1.57.5 → 1.58.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.58.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.57.5...core-v1.58.0) (2025-09-05)
4
+
5
+
6
+ ### Features
7
+
8
+ * add modalities support for chat model ([#454](https://github.com/AIGNE-io/aigne-framework/issues/454)) ([70d1bf6](https://github.com/AIGNE-io/aigne-framework/commit/70d1bf631f4e711235d89c6df8ee210a19179b30))
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * add disabled observability env ([#453](https://github.com/AIGNE-io/aigne-framework/issues/453)) ([3e01107](https://github.com/AIGNE-io/aigne-framework/commit/3e01107deb07d3e4eb6fbe49a7b39919fa412df1))
14
+
15
+
16
+ ### Dependencies
17
+
18
+ * The following workspace dependencies were updated
19
+ * dependencies
20
+ * @aigne/observability-api bumped to 0.10.2
21
+
3
22
  ## [1.57.5](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.57.4...core-v1.57.5) (2025-09-01)
4
23
 
5
24
 
@@ -1,9 +1,10 @@
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 } from "./chat-model.js";
4
+ import type { ChatModel, ChatModelInput, FileOutputType } from "./chat-model.js";
5
5
  import type { GuideRailAgentOutput } from "./guide-rail-agent.js";
6
6
  export declare const DEFAULT_OUTPUT_KEY = "message";
7
+ export declare const DEFAULT_FILE_OUTPUT_KEY = "files";
7
8
  /**
8
9
  * Configuration options for an AI Agent
9
10
  *
@@ -31,12 +32,15 @@ export interface AIAgentOptions<I extends Message = Message, O extends Message =
31
32
  * Pick a message from input to use as the user's message
32
33
  */
33
34
  inputKey?: string;
35
+ fileInputKey?: string;
34
36
  /**
35
37
  * Custom key to use for text output in the response
36
38
  *
37
39
  * Defaults to `message` if not specified
38
40
  */
39
41
  outputKey?: string;
42
+ fileOutputKey?: string;
43
+ fileOutputType?: FileOutputType;
40
44
  /**
41
45
  * Controls how the agent uses tools during execution
42
46
  *
@@ -217,6 +221,7 @@ export declare class AIAgent<I extends Message = any, O extends Message = any> e
217
221
  * Pick a message from input to use as the user's message
218
222
  */
219
223
  inputKey?: string;
224
+ fileInputKey?: string;
220
225
  /**
221
226
  * Custom key to use for text output in the response
222
227
  *
@@ -225,6 +230,8 @@ export declare class AIAgent<I extends Message = any, O extends Message = any> e
225
230
  * {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-custom-output-key}
226
231
  */
227
232
  outputKey: string;
233
+ fileOutputKey: string;
234
+ fileOutputType?: FileOutputType;
228
235
  /**
229
236
  * Controls how the agent uses tools during execution
230
237
  *
@@ -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_OUTPUT_KEY = void 0;
3
+ exports.AIAgent = exports.aiAgentOptionsSchema = exports.aiAgentToolChoiceSchema = exports.AIAgentToolChoice = exports.DEFAULT_FILE_OUTPUT_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,6 +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
14
  /**
14
15
  * Tool choice options for AI agents
15
16
  *
@@ -111,7 +112,10 @@ class AIAgent extends agent_js_1.Agent {
111
112
  ? prompt_builder_js_1.PromptBuilder.from(options.instructions)
112
113
  : (options.instructions ?? new prompt_builder_js_1.PromptBuilder());
113
114
  this.inputKey = options.inputKey;
115
+ this.fileInputKey = options.fileInputKey;
114
116
  this.outputKey = options.outputKey || exports.DEFAULT_OUTPUT_KEY;
117
+ this.fileOutputKey = options.fileOutputKey || exports.DEFAULT_FILE_OUTPUT_KEY;
118
+ this.fileOutputType = options.fileOutputType;
115
119
  this.toolChoice = options.toolChoice;
116
120
  this.memoryAgentsAsTools = options.memoryAgentsAsTools;
117
121
  this.memoryPromptTemplate = options.memoryPromptTemplate;
@@ -151,6 +155,7 @@ class AIAgent extends agent_js_1.Agent {
151
155
  * Pick a message from input to use as the user's message
152
156
  */
153
157
  inputKey;
158
+ fileInputKey;
154
159
  /**
155
160
  * Custom key to use for text output in the response
156
161
  *
@@ -159,6 +164,8 @@ class AIAgent extends agent_js_1.Agent {
159
164
  * {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-custom-output-key}
160
165
  */
161
166
  outputKey;
167
+ fileOutputKey;
168
+ fileOutputType;
162
169
  /**
163
170
  * Controls how the agent uses tools during execution
164
171
  *
@@ -269,7 +276,7 @@ class AIAgent extends agent_js_1.Agent {
269
276
  }
270
277
  }
271
278
  }
272
- const { toolCalls, json, text } = modelOutput;
279
+ const { toolCalls, json, text, files } = modelOutput;
273
280
  if (toolCalls?.length) {
274
281
  const executedToolCalls = [];
275
282
  // Execute tools
@@ -308,6 +315,9 @@ class AIAgent extends agent_js_1.Agent {
308
315
  if (text) {
309
316
  Object.assign(result, { [outputKey]: text });
310
317
  }
318
+ if (files) {
319
+ Object.assign(result, { [this.fileOutputKey]: files });
320
+ }
311
321
  if (!(0, type_utils_js_1.isEmpty)(result)) {
312
322
  yield { delta: { json: result } };
313
323
  }
@@ -104,6 +104,10 @@ export declare abstract class ChatModel extends Agent<ChatModelInput, ChatModelO
104
104
  * @returns A promise or direct value containing the model's response
105
105
  */
106
106
  abstract process(input: ChatModelInput, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
107
+ transformFileOutput(input: ChatModelInput, data: FileUnionContent, options: AgentInvokeOptions): Promise<FileUnionContent>;
108
+ static getFileExtension(type: string): string | undefined;
109
+ static getMimeType(filename: string): string | undefined;
110
+ protected downloadFile(url: string): Promise<Response>;
107
111
  }
108
112
  /**
109
113
  * Input message format for ChatModel
@@ -128,6 +132,7 @@ export interface ChatModelInput extends Message {
128
132
  * Specifies the expected response format
129
133
  */
130
134
  responseFormat?: ChatModelInputResponseFormat;
135
+ fileOutputType?: FileOutputType;
131
136
  /**
132
137
  * List of tools available for the model to use
133
138
  */
@@ -190,7 +195,7 @@ export interface ChatModelInputMessage {
190
195
  *
191
196
  * Can be a simple string, or a mixed array of text and image content
192
197
  */
193
- export type ChatModelInputMessageContent = string | (TextContent | ImageUrlContent)[];
198
+ export type ChatModelInputMessageContent = string | UnionContent[];
194
199
  /**
195
200
  * Text content type
196
201
  *
@@ -200,15 +205,304 @@ export type TextContent = {
200
205
  type: "text";
201
206
  text: string;
202
207
  };
208
+ export declare const textContentSchema: z.ZodObject<{
209
+ type: z.ZodLiteral<"text">;
210
+ text: z.ZodString;
211
+ }, "strip", z.ZodTypeAny, {
212
+ type: "text";
213
+ text: string;
214
+ }, {
215
+ type: "text";
216
+ text: string;
217
+ }>;
218
+ export interface FileContentBase {
219
+ filename?: string;
220
+ mimeType?: string;
221
+ }
222
+ export declare const fileContentBaseSchema: z.ZodObject<{
223
+ filename: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
224
+ mimeType: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
225
+ }, "strip", z.ZodTypeAny, {
226
+ filename?: string | undefined;
227
+ mimeType?: string | undefined;
228
+ }, {
229
+ filename?: string | undefined;
230
+ mimeType?: string | undefined;
231
+ }>;
203
232
  /**
204
233
  * Image URL content type
205
234
  *
206
235
  * Used for image parts of message content, referencing images via URL
207
236
  */
208
- export type ImageUrlContent = {
209
- type: "image_url";
237
+ export interface UrlContent extends FileContentBase {
238
+ type: "url";
210
239
  url: string;
211
- };
240
+ }
241
+ export declare const urlContentSchema: z.ZodObject<{
242
+ filename: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
243
+ mimeType: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
244
+ } & {
245
+ type: z.ZodLiteral<"url">;
246
+ url: z.ZodString;
247
+ }, "strip", z.ZodTypeAny, {
248
+ type: "url";
249
+ url: string;
250
+ filename?: string | undefined;
251
+ mimeType?: string | undefined;
252
+ }, {
253
+ type: "url";
254
+ url: string;
255
+ filename?: string | undefined;
256
+ mimeType?: string | undefined;
257
+ }>;
258
+ export interface FileContent extends FileContentBase {
259
+ type: "file";
260
+ data: string;
261
+ }
262
+ export declare const fileContentSchema: z.ZodObject<{
263
+ filename: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
264
+ mimeType: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
265
+ } & {
266
+ type: z.ZodLiteral<"file">;
267
+ data: z.ZodString;
268
+ }, "strip", z.ZodTypeAny, {
269
+ type: "file";
270
+ data: string;
271
+ filename?: string | undefined;
272
+ mimeType?: string | undefined;
273
+ }, {
274
+ type: "file";
275
+ data: string;
276
+ filename?: string | undefined;
277
+ mimeType?: string | undefined;
278
+ }>;
279
+ export interface LocalContent extends FileContentBase {
280
+ type: "local";
281
+ path: string;
282
+ }
283
+ export declare const localContentSchema: z.ZodObject<{
284
+ filename: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
285
+ mimeType: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
286
+ } & {
287
+ type: z.ZodLiteral<"local">;
288
+ path: z.ZodString;
289
+ }, "strip", z.ZodTypeAny, {
290
+ path: string;
291
+ type: "local";
292
+ filename?: string | undefined;
293
+ mimeType?: string | undefined;
294
+ }, {
295
+ path: string;
296
+ type: "local";
297
+ filename?: string | undefined;
298
+ mimeType?: string | undefined;
299
+ }>;
300
+ export type FileUnionContent = LocalContent | UrlContent | FileContent;
301
+ export declare const fileUnionContentSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
302
+ filename: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
303
+ mimeType: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
304
+ } & {
305
+ type: z.ZodLiteral<"local">;
306
+ path: z.ZodString;
307
+ }, "strip", z.ZodTypeAny, {
308
+ path: string;
309
+ type: "local";
310
+ filename?: string | undefined;
311
+ mimeType?: string | undefined;
312
+ }, {
313
+ path: string;
314
+ type: "local";
315
+ filename?: string | undefined;
316
+ mimeType?: string | undefined;
317
+ }>, z.ZodObject<{
318
+ filename: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
319
+ mimeType: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
320
+ } & {
321
+ type: z.ZodLiteral<"url">;
322
+ url: z.ZodString;
323
+ }, "strip", z.ZodTypeAny, {
324
+ type: "url";
325
+ url: string;
326
+ filename?: string | undefined;
327
+ mimeType?: string | undefined;
328
+ }, {
329
+ type: "url";
330
+ url: string;
331
+ filename?: string | undefined;
332
+ mimeType?: string | undefined;
333
+ }>, z.ZodObject<{
334
+ filename: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
335
+ mimeType: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
336
+ } & {
337
+ type: z.ZodLiteral<"file">;
338
+ data: z.ZodString;
339
+ }, "strip", z.ZodTypeAny, {
340
+ type: "file";
341
+ data: string;
342
+ filename?: string | undefined;
343
+ mimeType?: string | undefined;
344
+ }, {
345
+ type: "file";
346
+ data: string;
347
+ filename?: string | undefined;
348
+ mimeType?: string | undefined;
349
+ }>]>;
350
+ export declare const fileUnionContentsSchema: z.ZodUnion<[z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
351
+ filename: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
352
+ mimeType: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
353
+ } & {
354
+ type: z.ZodLiteral<"local">;
355
+ path: z.ZodString;
356
+ }, "strip", z.ZodTypeAny, {
357
+ path: string;
358
+ type: "local";
359
+ filename?: string | undefined;
360
+ mimeType?: string | undefined;
361
+ }, {
362
+ path: string;
363
+ type: "local";
364
+ filename?: string | undefined;
365
+ mimeType?: string | undefined;
366
+ }>, z.ZodObject<{
367
+ filename: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
368
+ mimeType: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
369
+ } & {
370
+ type: z.ZodLiteral<"url">;
371
+ url: z.ZodString;
372
+ }, "strip", z.ZodTypeAny, {
373
+ type: "url";
374
+ url: string;
375
+ filename?: string | undefined;
376
+ mimeType?: string | undefined;
377
+ }, {
378
+ type: "url";
379
+ url: string;
380
+ filename?: string | undefined;
381
+ mimeType?: string | undefined;
382
+ }>, z.ZodObject<{
383
+ filename: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
384
+ mimeType: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
385
+ } & {
386
+ type: z.ZodLiteral<"file">;
387
+ data: z.ZodString;
388
+ }, "strip", z.ZodTypeAny, {
389
+ type: "file";
390
+ data: string;
391
+ filename?: string | undefined;
392
+ mimeType?: string | undefined;
393
+ }, {
394
+ type: "file";
395
+ data: string;
396
+ filename?: string | undefined;
397
+ mimeType?: string | undefined;
398
+ }>]>, z.ZodArray<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
399
+ filename: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
400
+ mimeType: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
401
+ } & {
402
+ type: z.ZodLiteral<"local">;
403
+ path: z.ZodString;
404
+ }, "strip", z.ZodTypeAny, {
405
+ path: string;
406
+ type: "local";
407
+ filename?: string | undefined;
408
+ mimeType?: string | undefined;
409
+ }, {
410
+ path: string;
411
+ type: "local";
412
+ filename?: string | undefined;
413
+ mimeType?: string | undefined;
414
+ }>, z.ZodObject<{
415
+ filename: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
416
+ mimeType: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
417
+ } & {
418
+ type: z.ZodLiteral<"url">;
419
+ url: z.ZodString;
420
+ }, "strip", z.ZodTypeAny, {
421
+ type: "url";
422
+ url: string;
423
+ filename?: string | undefined;
424
+ mimeType?: string | undefined;
425
+ }, {
426
+ type: "url";
427
+ url: string;
428
+ filename?: string | undefined;
429
+ mimeType?: string | undefined;
430
+ }>, z.ZodObject<{
431
+ filename: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
432
+ mimeType: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
433
+ } & {
434
+ type: z.ZodLiteral<"file">;
435
+ data: z.ZodString;
436
+ }, "strip", z.ZodTypeAny, {
437
+ type: "file";
438
+ data: string;
439
+ filename?: string | undefined;
440
+ mimeType?: string | undefined;
441
+ }, {
442
+ type: "file";
443
+ data: string;
444
+ filename?: string | undefined;
445
+ mimeType?: string | undefined;
446
+ }>]>, "many">]>;
447
+ export type UnionContent = TextContent | FileUnionContent;
448
+ export declare const unionContentSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
449
+ type: z.ZodLiteral<"text">;
450
+ text: z.ZodString;
451
+ }, "strip", z.ZodTypeAny, {
452
+ type: "text";
453
+ text: string;
454
+ }, {
455
+ type: "text";
456
+ text: string;
457
+ }>, z.ZodObject<{
458
+ filename: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
459
+ mimeType: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
460
+ } & {
461
+ type: z.ZodLiteral<"local">;
462
+ path: z.ZodString;
463
+ }, "strip", z.ZodTypeAny, {
464
+ path: string;
465
+ type: "local";
466
+ filename?: string | undefined;
467
+ mimeType?: string | undefined;
468
+ }, {
469
+ path: string;
470
+ type: "local";
471
+ filename?: string | undefined;
472
+ mimeType?: string | undefined;
473
+ }>, z.ZodObject<{
474
+ filename: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
475
+ mimeType: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
476
+ } & {
477
+ type: z.ZodLiteral<"url">;
478
+ url: z.ZodString;
479
+ }, "strip", z.ZodTypeAny, {
480
+ type: "url";
481
+ url: string;
482
+ filename?: string | undefined;
483
+ mimeType?: string | undefined;
484
+ }, {
485
+ type: "url";
486
+ url: string;
487
+ filename?: string | undefined;
488
+ mimeType?: string | undefined;
489
+ }>, z.ZodObject<{
490
+ filename: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
491
+ mimeType: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
492
+ } & {
493
+ type: z.ZodLiteral<"file">;
494
+ data: z.ZodString;
495
+ }, "strip", z.ZodTypeAny, {
496
+ type: "file";
497
+ data: string;
498
+ filename?: string | undefined;
499
+ mimeType?: string | undefined;
500
+ }, {
501
+ type: "file";
502
+ data: string;
503
+ filename?: string | undefined;
504
+ mimeType?: string | undefined;
505
+ }>]>;
212
506
  /**
213
507
  * Model response format settings
214
508
  *
@@ -277,6 +571,7 @@ export type ChatModelInputToolChoice = "auto" | "none" | "required" | {
277
571
  description?: string;
278
572
  };
279
573
  };
574
+ export type Modality = "text" | "image" | "audio";
280
575
  /**
281
576
  * Model-specific configuration options
282
577
  *
@@ -307,6 +602,7 @@ export interface ChatModelOptions {
307
602
  * Whether to allow parallel tool calls
308
603
  */
309
604
  parallelToolCalls?: boolean;
605
+ modalities?: Modality[];
310
606
  }
311
607
  /**
312
608
  * Output message format for ChatModel
@@ -342,6 +638,11 @@ export interface ChatModelOutput extends Message {
342
638
  * Model name or version used
343
639
  */
344
640
  model?: string;
641
+ files?: FileUnionContent[];
642
+ }
643
+ export declare enum FileOutputType {
644
+ local = "local",
645
+ file = "file"
345
646
  }
346
647
  /**
347
648
  * Tool call information in model output
@@ -32,10 +32,17 @@ 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
+ };
35
38
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.chatModelOutputUsageSchema = exports.ChatModel = exports.StructuredOutputError = void 0;
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;
40
+ const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
37
41
  const ajv_1 = require("ajv");
42
+ const mime_1 = __importDefault(require("mime"));
43
+ const uuid_1 = require("uuid");
38
44
  const zod_1 = require("zod");
45
+ const schema_js_1 = require("../loader/schema.js");
39
46
  const type_utils_js_1 = require("../utils/type-utils.js");
40
47
  const agent_js_1 = require("./agent.js");
41
48
  const CHAT_MODEL_DEFAULT_RETRY_OPTIONS = {
@@ -207,19 +214,101 @@ class ChatModel extends agent_js_1.Agent {
207
214
  options.context.usage.aigneHubCredits += usage.aigneHubCredits;
208
215
  }
209
216
  }
217
+ async transformFileOutput(input, data, options) {
218
+ const fileOutputType = input.fileOutputType || FileOutputType.local;
219
+ if (fileOutputType === data.type)
220
+ return data;
221
+ const common = (0, type_utils_js_1.pick)(data, "filename", "mimeType");
222
+ switch (fileOutputType) {
223
+ case FileOutputType.local: {
224
+ const dir = index_js_1.nodejs.path.join(index_js_1.nodejs.os.tmpdir(), options.context.id);
225
+ await index_js_1.nodejs.fs.mkdir(dir, { recursive: true });
226
+ const ext = ChatModel.getFileExtension(data.mimeType || data.filename || "");
227
+ const id = (0, uuid_1.v7)();
228
+ const filename = ext ? `${id}.${ext}` : id;
229
+ const path = index_js_1.nodejs.path.join(dir, filename);
230
+ if (data.type === "file") {
231
+ await index_js_1.nodejs.fs.writeFile(path, data.data, "base64");
232
+ }
233
+ else if (data.type === "url") {
234
+ await this.downloadFile(data.url)
235
+ .then((res) => res.body)
236
+ .then((body) => body && index_js_1.nodejs.fs.writeFile(path, body));
237
+ }
238
+ else {
239
+ throw new Error(`Unexpected file type: ${data.type}`);
240
+ }
241
+ return { ...common, type: "local", path };
242
+ }
243
+ case FileOutputType.file: {
244
+ let base64;
245
+ if (data.type === "local") {
246
+ base64 = await index_js_1.nodejs.fs.readFile(data.path, "base64");
247
+ }
248
+ else if (data.type === "url") {
249
+ base64 = Buffer.from(await (await this.downloadFile(data.url)).arrayBuffer()).toString("base64");
250
+ }
251
+ else {
252
+ throw new Error(`Unexpected file type: ${data.type}`);
253
+ }
254
+ return { ...common, type: "file", data: base64 };
255
+ }
256
+ }
257
+ }
258
+ static getFileExtension(type) {
259
+ return mime_1.default.getExtension(type) || undefined;
260
+ }
261
+ static getMimeType(filename) {
262
+ return mime_1.default.getType(filename) || undefined;
263
+ }
264
+ async downloadFile(url) {
265
+ const response = await fetch(url);
266
+ if (!response.ok) {
267
+ const text = await response.text().catch(() => null);
268
+ throw new Error(`Failed to download content from ${url}, ${response.status} ${response.statusText} ${text}`);
269
+ }
270
+ return response;
271
+ }
210
272
  }
211
273
  exports.ChatModel = ChatModel;
274
+ exports.textContentSchema = zod_1.z.object({
275
+ type: zod_1.z.literal("text"),
276
+ text: zod_1.z.string(),
277
+ });
278
+ exports.fileContentBaseSchema = zod_1.z.object({
279
+ filename: (0, schema_js_1.optionalize)(zod_1.z.string()),
280
+ mimeType: (0, schema_js_1.optionalize)(zod_1.z.string()),
281
+ });
282
+ exports.urlContentSchema = exports.fileContentBaseSchema.extend({
283
+ type: zod_1.z.literal("url"),
284
+ url: zod_1.z.string(),
285
+ });
286
+ exports.fileContentSchema = exports.fileContentBaseSchema.extend({
287
+ type: zod_1.z.literal("file"),
288
+ data: zod_1.z.string(),
289
+ });
290
+ exports.localContentSchema = exports.fileContentBaseSchema.extend({
291
+ type: zod_1.z.literal("local"),
292
+ path: zod_1.z.string(),
293
+ });
294
+ exports.fileUnionContentSchema = zod_1.z.discriminatedUnion("type", [
295
+ exports.localContentSchema,
296
+ exports.urlContentSchema,
297
+ exports.fileContentSchema,
298
+ ]);
299
+ exports.fileUnionContentsSchema = zod_1.z.union([
300
+ exports.fileUnionContentSchema,
301
+ zod_1.z.array(exports.fileUnionContentSchema),
302
+ ]);
303
+ exports.unionContentSchema = zod_1.z.discriminatedUnion("type", [
304
+ exports.textContentSchema,
305
+ exports.localContentSchema,
306
+ exports.urlContentSchema,
307
+ exports.fileContentSchema,
308
+ ]);
212
309
  const chatModelInputMessageSchema = zod_1.z.object({
213
310
  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")]),
214
- content: zod_1.z
215
- .union([
216
- zod_1.z.string(),
217
- zod_1.z.array(zod_1.z.union([
218
- zod_1.z.object({ type: zod_1.z.literal("text"), text: zod_1.z.string() }),
219
- zod_1.z.object({ type: zod_1.z.literal("image_url"), url: zod_1.z.string() }),
220
- ])),
221
- ])
222
- .optional(),
311
+ content: zod_1.z.union([zod_1.z.string(), zod_1.z.array(exports.unionContentSchema)]).optional(),
223
312
  toolCalls: zod_1.z
224
313
  .array(zod_1.z.object({
225
314
  id: zod_1.z.string(),
@@ -266,6 +355,7 @@ const chatModelOptionsSchema = zod_1.z.object({
266
355
  frequencyPenalty: zod_1.z.number().optional(),
267
356
  presencePenalty: zod_1.z.number().optional(),
268
357
  parallelToolCalls: zod_1.z.boolean().optional().default(true),
358
+ modalities: zod_1.z.array(zod_1.z.enum(["text", "image", "audio"])).optional(),
269
359
  });
270
360
  const chatModelInputSchema = zod_1.z.object({
271
361
  messages: zod_1.z.array(chatModelInputMessageSchema),
@@ -274,6 +364,11 @@ const chatModelInputSchema = zod_1.z.object({
274
364
  toolChoice: chatModelInputToolChoiceSchema.optional(),
275
365
  modelOptions: chatModelOptionsSchema.optional(),
276
366
  });
367
+ var FileOutputType;
368
+ (function (FileOutputType) {
369
+ FileOutputType["local"] = "local";
370
+ FileOutputType["file"] = "file";
371
+ })(FileOutputType || (exports.FileOutputType = FileOutputType = {}));
277
372
  const chatModelOutputToolCallSchema = zod_1.z.object({
278
373
  id: zod_1.z.string(),
279
374
  type: zod_1.z.literal("function"),
@@ -293,4 +388,5 @@ const chatModelOutputSchema = zod_1.z.object({
293
388
  toolCalls: zod_1.z.array(chatModelOutputToolCallSchema).optional(),
294
389
  usage: exports.chatModelOutputUsageSchema.optional(),
295
390
  model: zod_1.z.string().optional(),
391
+ files: zod_1.z.array(exports.fileUnionContentSchema).optional(),
296
392
  });
@@ -32,13 +32,13 @@ export declare const imageModelInputSchema: z.ZodObject<{
32
32
  }, "strip", z.ZodTypeAny, {
33
33
  prompt: string;
34
34
  model?: string | undefined;
35
- responseFormat?: "url" | "base64" | undefined;
35
+ responseFormat?: "base64" | "url" | undefined;
36
36
  image?: string | string[] | undefined;
37
37
  n?: number | undefined;
38
38
  }, {
39
39
  prompt: string;
40
40
  model?: string | undefined;
41
- responseFormat?: "url" | "base64" | undefined;
41
+ responseFormat?: "base64" | "url" | undefined;
42
42
  image?: string | string[] | undefined;
43
43
  n?: number | undefined;
44
44
  }>;
@@ -202,6 +202,8 @@ class AIGNEContext {
202
202
  return this.internal.events.emit(eventName, ...newArgs);
203
203
  }
204
204
  async trace(eventName, args, b) {
205
+ if (process.env.AIGNE_OBSERVABILITY_DISABLED)
206
+ return;
205
207
  const span = this.span;
206
208
  if (!span)
207
209
  return;
@@ -1,7 +1,7 @@
1
1
  import type { GetPromptResult } from "@modelcontextprotocol/sdk/types.js";
2
2
  import { Agent, type AgentInvokeOptions, type Message } from "../agents/agent.js";
3
- import type { AIAgent } from "../agents/ai-agent.js";
4
- import type { ChatModel, ChatModelInput } from "../agents/chat-model.js";
3
+ import { type AIAgent } from "../agents/ai-agent.js";
4
+ import { type ChatModel, type ChatModelInput } from "../agents/chat-model.js";
5
5
  import { ChatMessagesTemplate } from "./template.js";
6
6
  export interface PromptBuilderOptions {
7
7
  instructions?: string | ChatMessagesTemplate;