@aigne/core 1.57.4 → 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 +26 -0
- package/lib/cjs/agents/ai-agent.d.ts +8 -1
- package/lib/cjs/agents/ai-agent.js +12 -2
- package/lib/cjs/agents/chat-model.d.ts +305 -4
- package/lib/cjs/agents/chat-model.js +137 -12
- package/lib/cjs/agents/image-model.d.ts +2 -2
- package/lib/cjs/aigne/context.js +2 -0
- package/lib/cjs/prompt/prompt-builder.d.ts +2 -2
- package/lib/cjs/prompt/prompt-builder.js +63 -13
- package/lib/dts/agents/ai-agent.d.ts +8 -1
- package/lib/dts/agents/chat-model.d.ts +305 -4
- package/lib/dts/agents/image-model.d.ts +2 -2
- package/lib/dts/prompt/prompt-builder.d.ts +2 -2
- package/lib/esm/agents/ai-agent.d.ts +8 -1
- package/lib/esm/agents/ai-agent.js +11 -1
- package/lib/esm/agents/chat-model.d.ts +305 -4
- package/lib/esm/agents/chat-model.js +104 -12
- package/lib/esm/agents/image-model.d.ts +2 -2
- package/lib/esm/aigne/context.js +2 -0
- package/lib/esm/prompt/prompt-builder.d.ts +2 -2
- package/lib/esm/prompt/prompt-builder.js +64 -14
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
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
|
+
|
|
22
|
+
## [1.57.5](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.57.4...core-v1.57.5) (2025-09-01)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
* **core:** replace static import with dynamic import for CommonJS compatibility ([#448](https://github.com/AIGNE-io/aigne-framework/issues/448)) ([6db1e57](https://github.com/AIGNE-io/aigne-framework/commit/6db1e570858fff32f7352143585b98e900f1f71d))
|
|
28
|
+
|
|
3
29
|
## [1.57.4](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.57.3...core-v1.57.4) (2025-08-30)
|
|
4
30
|
|
|
5
31
|
|
|
@@ -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 |
|
|
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
|
|
209
|
-
type: "
|
|
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
|
|
@@ -1,17 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
5
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
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");
|
|
7
41
|
const ajv_1 = require("ajv");
|
|
8
|
-
const
|
|
42
|
+
const mime_1 = __importDefault(require("mime"));
|
|
43
|
+
const uuid_1 = require("uuid");
|
|
9
44
|
const zod_1 = require("zod");
|
|
45
|
+
const schema_js_1 = require("../loader/schema.js");
|
|
10
46
|
const type_utils_js_1 = require("../utils/type-utils.js");
|
|
11
47
|
const agent_js_1 = require("./agent.js");
|
|
12
48
|
const CHAT_MODEL_DEFAULT_RETRY_OPTIONS = {
|
|
13
49
|
retries: 3,
|
|
14
|
-
shouldRetry: (error) => error instanceof StructuredOutputError || (
|
|
50
|
+
shouldRetry: async (error) => error instanceof StructuredOutputError || (await Promise.resolve().then(() => __importStar(require("is-network-error")))).default(error),
|
|
15
51
|
};
|
|
16
52
|
class StructuredOutputError extends Error {
|
|
17
53
|
}
|
|
@@ -178,19 +214,101 @@ class ChatModel extends agent_js_1.Agent {
|
|
|
178
214
|
options.context.usage.aigneHubCredits += usage.aigneHubCredits;
|
|
179
215
|
}
|
|
180
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
|
+
}
|
|
181
272
|
}
|
|
182
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
|
+
]);
|
|
183
309
|
const chatModelInputMessageSchema = zod_1.z.object({
|
|
184
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")]),
|
|
185
|
-
content: zod_1.z
|
|
186
|
-
.union([
|
|
187
|
-
zod_1.z.string(),
|
|
188
|
-
zod_1.z.array(zod_1.z.union([
|
|
189
|
-
zod_1.z.object({ type: zod_1.z.literal("text"), text: zod_1.z.string() }),
|
|
190
|
-
zod_1.z.object({ type: zod_1.z.literal("image_url"), url: zod_1.z.string() }),
|
|
191
|
-
])),
|
|
192
|
-
])
|
|
193
|
-
.optional(),
|
|
311
|
+
content: zod_1.z.union([zod_1.z.string(), zod_1.z.array(exports.unionContentSchema)]).optional(),
|
|
194
312
|
toolCalls: zod_1.z
|
|
195
313
|
.array(zod_1.z.object({
|
|
196
314
|
id: zod_1.z.string(),
|
|
@@ -237,6 +355,7 @@ const chatModelOptionsSchema = zod_1.z.object({
|
|
|
237
355
|
frequencyPenalty: zod_1.z.number().optional(),
|
|
238
356
|
presencePenalty: zod_1.z.number().optional(),
|
|
239
357
|
parallelToolCalls: zod_1.z.boolean().optional().default(true),
|
|
358
|
+
modalities: zod_1.z.array(zod_1.z.enum(["text", "image", "audio"])).optional(),
|
|
240
359
|
});
|
|
241
360
|
const chatModelInputSchema = zod_1.z.object({
|
|
242
361
|
messages: zod_1.z.array(chatModelInputMessageSchema),
|
|
@@ -245,6 +364,11 @@ const chatModelInputSchema = zod_1.z.object({
|
|
|
245
364
|
toolChoice: chatModelInputToolChoiceSchema.optional(),
|
|
246
365
|
modelOptions: chatModelOptionsSchema.optional(),
|
|
247
366
|
});
|
|
367
|
+
var FileOutputType;
|
|
368
|
+
(function (FileOutputType) {
|
|
369
|
+
FileOutputType["local"] = "local";
|
|
370
|
+
FileOutputType["file"] = "file";
|
|
371
|
+
})(FileOutputType || (exports.FileOutputType = FileOutputType = {}));
|
|
248
372
|
const chatModelOutputToolCallSchema = zod_1.z.object({
|
|
249
373
|
id: zod_1.z.string(),
|
|
250
374
|
type: zod_1.z.literal("function"),
|
|
@@ -264,4 +388,5 @@ const chatModelOutputSchema = zod_1.z.object({
|
|
|
264
388
|
toolCalls: zod_1.z.array(chatModelOutputToolCallSchema).optional(),
|
|
265
389
|
usage: exports.chatModelOutputUsageSchema.optional(),
|
|
266
390
|
model: zod_1.z.string().optional(),
|
|
391
|
+
files: zod_1.z.array(exports.fileUnionContentSchema).optional(),
|
|
267
392
|
});
|