@aigne/core 1.58.3 → 1.59.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 +7 -0
- package/lib/cjs/agents/chat-model.d.ts +9 -3
- package/lib/cjs/agents/chat-model.js +21 -3
- package/lib/cjs/agents/image-model.d.ts +2 -2
- package/lib/dts/agents/chat-model.d.ts +9 -3
- package/lib/dts/agents/image-model.d.ts +2 -2
- package/lib/esm/agents/chat-model.d.ts +9 -3
- package/lib/esm/agents/chat-model.js +21 -3
- package/lib/esm/agents/image-model.d.ts +2 -2
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.59.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.58.3...core-v1.59.0) (2025-09-09)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* support custom prefer input file type ([#469](https://github.com/AIGNE-io/aigne-framework/issues/469)) ([db0161b](https://github.com/AIGNE-io/aigne-framework/commit/db0161bbac52542c771ee2f40f361636b0668075))
|
|
9
|
+
|
|
3
10
|
## [1.58.3](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.58.2...core-v1.58.3) (2025-09-08)
|
|
4
11
|
|
|
5
12
|
|
|
@@ -3,6 +3,10 @@ import { type PromiseOrValue } from "../utils/type-utils.js";
|
|
|
3
3
|
import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type AgentResponse, type AgentResponseStream, type Message } from "./agent.js";
|
|
4
4
|
export declare class StructuredOutputError extends Error {
|
|
5
5
|
}
|
|
6
|
+
export interface ChatModelOptions extends Omit<AgentOptions<ChatModelInput, ChatModelOutput>, "inputSchema" | "outputSchema"> {
|
|
7
|
+
model?: string;
|
|
8
|
+
modelOptions?: Omit<ModelOptions, "model">;
|
|
9
|
+
}
|
|
6
10
|
/**
|
|
7
11
|
* ChatModel is an abstract base class for interacting with Large Language Models (LLMs).
|
|
8
12
|
*
|
|
@@ -27,8 +31,9 @@ export declare class StructuredOutputError extends Error {
|
|
|
27
31
|
* {@includeCode ../../test/agents/chat-model.test.ts#example-chat-model-tools}
|
|
28
32
|
*/
|
|
29
33
|
export declare abstract class ChatModel extends Agent<ChatModelInput, ChatModelOutput> {
|
|
34
|
+
options?: ChatModelOptions | undefined;
|
|
30
35
|
tag: string;
|
|
31
|
-
constructor(options?:
|
|
36
|
+
constructor(options?: ChatModelOptions | undefined);
|
|
32
37
|
get credential(): PromiseOrValue<{
|
|
33
38
|
url?: string;
|
|
34
39
|
apiKey?: string;
|
|
@@ -145,7 +150,7 @@ export interface ChatModelInput extends Message {
|
|
|
145
150
|
/**
|
|
146
151
|
* Model-specific configuration options
|
|
147
152
|
*/
|
|
148
|
-
modelOptions?:
|
|
153
|
+
modelOptions?: ModelOptions;
|
|
149
154
|
}
|
|
150
155
|
/**
|
|
151
156
|
* Message role types
|
|
@@ -578,7 +583,7 @@ export type Modality = "text" | "image" | "audio";
|
|
|
578
583
|
*
|
|
579
584
|
* Contains various parameters for controlling model behavior, such as model name, temperature, etc.
|
|
580
585
|
*/
|
|
581
|
-
export interface
|
|
586
|
+
export interface ModelOptions {
|
|
582
587
|
/**
|
|
583
588
|
* Model name or version
|
|
584
589
|
*/
|
|
@@ -604,6 +609,7 @@ export interface ChatModelOptions {
|
|
|
604
609
|
*/
|
|
605
610
|
parallelToolCalls?: boolean;
|
|
606
611
|
modalities?: Modality[];
|
|
612
|
+
preferFileInputType?: "file" | "url";
|
|
607
613
|
}
|
|
608
614
|
/**
|
|
609
615
|
* Output message format for ChatModel
|
|
@@ -76,10 +76,11 @@ exports.StructuredOutputError = StructuredOutputError;
|
|
|
76
76
|
* {@includeCode ../../test/agents/chat-model.test.ts#example-chat-model-tools}
|
|
77
77
|
*/
|
|
78
78
|
class ChatModel extends agent_js_1.Agent {
|
|
79
|
+
options;
|
|
79
80
|
tag = "ChatModelAgent";
|
|
80
81
|
constructor(options) {
|
|
81
82
|
if (options)
|
|
82
|
-
(0, type_utils_js_1.checkArguments)("ChatModel",
|
|
83
|
+
(0, type_utils_js_1.checkArguments)("ChatModel", chatModelOptionsSchema, options);
|
|
83
84
|
const retryOnError = options?.retryOnError === false
|
|
84
85
|
? false
|
|
85
86
|
: options?.retryOnError === true
|
|
@@ -94,6 +95,7 @@ class ChatModel extends agent_js_1.Agent {
|
|
|
94
95
|
outputSchema: chatModelOutputSchema,
|
|
95
96
|
retryOnError,
|
|
96
97
|
});
|
|
98
|
+
this.options = options;
|
|
97
99
|
}
|
|
98
100
|
get credential() {
|
|
99
101
|
return {};
|
|
@@ -188,6 +190,18 @@ class ChatModel extends agent_js_1.Agent {
|
|
|
188
190
|
mimeType: item.mimeType || ChatModel.getMimeType(item.filename || item.path),
|
|
189
191
|
};
|
|
190
192
|
}
|
|
193
|
+
if ((input.modelOptions?.preferFileInputType ||
|
|
194
|
+
this.options?.modelOptions?.preferFileInputType) !== "url") {
|
|
195
|
+
if (item.type === "url") {
|
|
196
|
+
return {
|
|
197
|
+
...item,
|
|
198
|
+
type: "file",
|
|
199
|
+
data: Buffer.from(await (await this.downloadFile(item.url)).arrayBuffer()).toString("base64"),
|
|
200
|
+
url: undefined,
|
|
201
|
+
mimeType: item.mimeType || ChatModel.getMimeType(item.filename || item.url),
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
}
|
|
191
205
|
return item;
|
|
192
206
|
})),
|
|
193
207
|
};
|
|
@@ -379,7 +393,7 @@ const chatModelInputToolChoiceSchema = zod_1.z.union([
|
|
|
379
393
|
zod_1.z.literal("required"),
|
|
380
394
|
chatModelInputToolSchema,
|
|
381
395
|
]);
|
|
382
|
-
const
|
|
396
|
+
const modelOptionsSchema = zod_1.z.object({
|
|
383
397
|
model: zod_1.z.string().optional(),
|
|
384
398
|
temperature: zod_1.z.number().optional(),
|
|
385
399
|
topP: zod_1.z.number().optional(),
|
|
@@ -388,12 +402,16 @@ const chatModelOptionsSchema = zod_1.z.object({
|
|
|
388
402
|
parallelToolCalls: zod_1.z.boolean().optional().default(true),
|
|
389
403
|
modalities: zod_1.z.array(zod_1.z.enum(["text", "image", "audio"])).optional(),
|
|
390
404
|
});
|
|
405
|
+
const chatModelOptionsSchema = agent_js_1.agentOptionsSchema.extend({
|
|
406
|
+
model: zod_1.z.string().optional(),
|
|
407
|
+
modelOptions: modelOptionsSchema.optional(),
|
|
408
|
+
});
|
|
391
409
|
const chatModelInputSchema = zod_1.z.object({
|
|
392
410
|
messages: zod_1.z.array(chatModelInputMessageSchema),
|
|
393
411
|
responseFormat: chatModelInputResponseFormatSchema.optional(),
|
|
394
412
|
tools: zod_1.z.array(chatModelInputToolSchema).optional(),
|
|
395
413
|
toolChoice: chatModelInputToolChoiceSchema.optional(),
|
|
396
|
-
modelOptions:
|
|
414
|
+
modelOptions: modelOptionsSchema.optional(),
|
|
397
415
|
});
|
|
398
416
|
var FileOutputType;
|
|
399
417
|
(function (FileOutputType) {
|
|
@@ -32,14 +32,14 @@ export declare const imageModelInputSchema: z.ZodObject<{
|
|
|
32
32
|
}, "strip", z.ZodTypeAny, {
|
|
33
33
|
prompt: string;
|
|
34
34
|
model?: string | undefined;
|
|
35
|
-
responseFormat?: "base64" | "url" | undefined;
|
|
36
35
|
image?: string | string[] | undefined;
|
|
36
|
+
responseFormat?: "base64" | "url" | undefined;
|
|
37
37
|
n?: number | undefined;
|
|
38
38
|
}, {
|
|
39
39
|
prompt: string;
|
|
40
40
|
model?: string | undefined;
|
|
41
|
-
responseFormat?: "base64" | "url" | undefined;
|
|
42
41
|
image?: string | string[] | undefined;
|
|
42
|
+
responseFormat?: "base64" | "url" | undefined;
|
|
43
43
|
n?: number | undefined;
|
|
44
44
|
}>;
|
|
45
45
|
export interface ImageModelOutput extends Message {
|
|
@@ -3,6 +3,10 @@ import { type PromiseOrValue } from "../utils/type-utils.js";
|
|
|
3
3
|
import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type AgentResponse, type AgentResponseStream, type Message } from "./agent.js";
|
|
4
4
|
export declare class StructuredOutputError extends Error {
|
|
5
5
|
}
|
|
6
|
+
export interface ChatModelOptions extends Omit<AgentOptions<ChatModelInput, ChatModelOutput>, "inputSchema" | "outputSchema"> {
|
|
7
|
+
model?: string;
|
|
8
|
+
modelOptions?: Omit<ModelOptions, "model">;
|
|
9
|
+
}
|
|
6
10
|
/**
|
|
7
11
|
* ChatModel is an abstract base class for interacting with Large Language Models (LLMs).
|
|
8
12
|
*
|
|
@@ -27,8 +31,9 @@ export declare class StructuredOutputError extends Error {
|
|
|
27
31
|
* {@includeCode ../../test/agents/chat-model.test.ts#example-chat-model-tools}
|
|
28
32
|
*/
|
|
29
33
|
export declare abstract class ChatModel extends Agent<ChatModelInput, ChatModelOutput> {
|
|
34
|
+
options?: ChatModelOptions | undefined;
|
|
30
35
|
tag: string;
|
|
31
|
-
constructor(options?:
|
|
36
|
+
constructor(options?: ChatModelOptions | undefined);
|
|
32
37
|
get credential(): PromiseOrValue<{
|
|
33
38
|
url?: string;
|
|
34
39
|
apiKey?: string;
|
|
@@ -145,7 +150,7 @@ export interface ChatModelInput extends Message {
|
|
|
145
150
|
/**
|
|
146
151
|
* Model-specific configuration options
|
|
147
152
|
*/
|
|
148
|
-
modelOptions?:
|
|
153
|
+
modelOptions?: ModelOptions;
|
|
149
154
|
}
|
|
150
155
|
/**
|
|
151
156
|
* Message role types
|
|
@@ -578,7 +583,7 @@ export type Modality = "text" | "image" | "audio";
|
|
|
578
583
|
*
|
|
579
584
|
* Contains various parameters for controlling model behavior, such as model name, temperature, etc.
|
|
580
585
|
*/
|
|
581
|
-
export interface
|
|
586
|
+
export interface ModelOptions {
|
|
582
587
|
/**
|
|
583
588
|
* Model name or version
|
|
584
589
|
*/
|
|
@@ -604,6 +609,7 @@ export interface ChatModelOptions {
|
|
|
604
609
|
*/
|
|
605
610
|
parallelToolCalls?: boolean;
|
|
606
611
|
modalities?: Modality[];
|
|
612
|
+
preferFileInputType?: "file" | "url";
|
|
607
613
|
}
|
|
608
614
|
/**
|
|
609
615
|
* Output message format for ChatModel
|
|
@@ -32,14 +32,14 @@ export declare const imageModelInputSchema: z.ZodObject<{
|
|
|
32
32
|
}, "strip", z.ZodTypeAny, {
|
|
33
33
|
prompt: string;
|
|
34
34
|
model?: string | undefined;
|
|
35
|
-
responseFormat?: "base64" | "url" | undefined;
|
|
36
35
|
image?: string | string[] | undefined;
|
|
36
|
+
responseFormat?: "base64" | "url" | undefined;
|
|
37
37
|
n?: number | undefined;
|
|
38
38
|
}, {
|
|
39
39
|
prompt: string;
|
|
40
40
|
model?: string | undefined;
|
|
41
|
-
responseFormat?: "base64" | "url" | undefined;
|
|
42
41
|
image?: string | string[] | undefined;
|
|
42
|
+
responseFormat?: "base64" | "url" | undefined;
|
|
43
43
|
n?: number | undefined;
|
|
44
44
|
}>;
|
|
45
45
|
export interface ImageModelOutput extends Message {
|
|
@@ -3,6 +3,10 @@ import { type PromiseOrValue } from "../utils/type-utils.js";
|
|
|
3
3
|
import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type AgentResponse, type AgentResponseStream, type Message } from "./agent.js";
|
|
4
4
|
export declare class StructuredOutputError extends Error {
|
|
5
5
|
}
|
|
6
|
+
export interface ChatModelOptions extends Omit<AgentOptions<ChatModelInput, ChatModelOutput>, "inputSchema" | "outputSchema"> {
|
|
7
|
+
model?: string;
|
|
8
|
+
modelOptions?: Omit<ModelOptions, "model">;
|
|
9
|
+
}
|
|
6
10
|
/**
|
|
7
11
|
* ChatModel is an abstract base class for interacting with Large Language Models (LLMs).
|
|
8
12
|
*
|
|
@@ -27,8 +31,9 @@ export declare class StructuredOutputError extends Error {
|
|
|
27
31
|
* {@includeCode ../../test/agents/chat-model.test.ts#example-chat-model-tools}
|
|
28
32
|
*/
|
|
29
33
|
export declare abstract class ChatModel extends Agent<ChatModelInput, ChatModelOutput> {
|
|
34
|
+
options?: ChatModelOptions | undefined;
|
|
30
35
|
tag: string;
|
|
31
|
-
constructor(options?:
|
|
36
|
+
constructor(options?: ChatModelOptions | undefined);
|
|
32
37
|
get credential(): PromiseOrValue<{
|
|
33
38
|
url?: string;
|
|
34
39
|
apiKey?: string;
|
|
@@ -145,7 +150,7 @@ export interface ChatModelInput extends Message {
|
|
|
145
150
|
/**
|
|
146
151
|
* Model-specific configuration options
|
|
147
152
|
*/
|
|
148
|
-
modelOptions?:
|
|
153
|
+
modelOptions?: ModelOptions;
|
|
149
154
|
}
|
|
150
155
|
/**
|
|
151
156
|
* Message role types
|
|
@@ -578,7 +583,7 @@ export type Modality = "text" | "image" | "audio";
|
|
|
578
583
|
*
|
|
579
584
|
* Contains various parameters for controlling model behavior, such as model name, temperature, etc.
|
|
580
585
|
*/
|
|
581
|
-
export interface
|
|
586
|
+
export interface ModelOptions {
|
|
582
587
|
/**
|
|
583
588
|
* Model name or version
|
|
584
589
|
*/
|
|
@@ -604,6 +609,7 @@ export interface ChatModelOptions {
|
|
|
604
609
|
*/
|
|
605
610
|
parallelToolCalls?: boolean;
|
|
606
611
|
modalities?: Modality[];
|
|
612
|
+
preferFileInputType?: "file" | "url";
|
|
607
613
|
}
|
|
608
614
|
/**
|
|
609
615
|
* Output message format for ChatModel
|
|
@@ -36,10 +36,11 @@ export class StructuredOutputError extends Error {
|
|
|
36
36
|
* {@includeCode ../../test/agents/chat-model.test.ts#example-chat-model-tools}
|
|
37
37
|
*/
|
|
38
38
|
export class ChatModel extends Agent {
|
|
39
|
+
options;
|
|
39
40
|
tag = "ChatModelAgent";
|
|
40
41
|
constructor(options) {
|
|
41
42
|
if (options)
|
|
42
|
-
checkArguments("ChatModel",
|
|
43
|
+
checkArguments("ChatModel", chatModelOptionsSchema, options);
|
|
43
44
|
const retryOnError = options?.retryOnError === false
|
|
44
45
|
? false
|
|
45
46
|
: options?.retryOnError === true
|
|
@@ -54,6 +55,7 @@ export class ChatModel extends Agent {
|
|
|
54
55
|
outputSchema: chatModelOutputSchema,
|
|
55
56
|
retryOnError,
|
|
56
57
|
});
|
|
58
|
+
this.options = options;
|
|
57
59
|
}
|
|
58
60
|
get credential() {
|
|
59
61
|
return {};
|
|
@@ -148,6 +150,18 @@ export class ChatModel extends Agent {
|
|
|
148
150
|
mimeType: item.mimeType || ChatModel.getMimeType(item.filename || item.path),
|
|
149
151
|
};
|
|
150
152
|
}
|
|
153
|
+
if ((input.modelOptions?.preferFileInputType ||
|
|
154
|
+
this.options?.modelOptions?.preferFileInputType) !== "url") {
|
|
155
|
+
if (item.type === "url") {
|
|
156
|
+
return {
|
|
157
|
+
...item,
|
|
158
|
+
type: "file",
|
|
159
|
+
data: Buffer.from(await (await this.downloadFile(item.url)).arrayBuffer()).toString("base64"),
|
|
160
|
+
url: undefined,
|
|
161
|
+
mimeType: item.mimeType || ChatModel.getMimeType(item.filename || item.url),
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
}
|
|
151
165
|
return item;
|
|
152
166
|
})),
|
|
153
167
|
};
|
|
@@ -338,7 +352,7 @@ const chatModelInputToolChoiceSchema = z.union([
|
|
|
338
352
|
z.literal("required"),
|
|
339
353
|
chatModelInputToolSchema,
|
|
340
354
|
]);
|
|
341
|
-
const
|
|
355
|
+
const modelOptionsSchema = z.object({
|
|
342
356
|
model: z.string().optional(),
|
|
343
357
|
temperature: z.number().optional(),
|
|
344
358
|
topP: z.number().optional(),
|
|
@@ -347,12 +361,16 @@ const chatModelOptionsSchema = z.object({
|
|
|
347
361
|
parallelToolCalls: z.boolean().optional().default(true),
|
|
348
362
|
modalities: z.array(z.enum(["text", "image", "audio"])).optional(),
|
|
349
363
|
});
|
|
364
|
+
const chatModelOptionsSchema = agentOptionsSchema.extend({
|
|
365
|
+
model: z.string().optional(),
|
|
366
|
+
modelOptions: modelOptionsSchema.optional(),
|
|
367
|
+
});
|
|
350
368
|
const chatModelInputSchema = z.object({
|
|
351
369
|
messages: z.array(chatModelInputMessageSchema),
|
|
352
370
|
responseFormat: chatModelInputResponseFormatSchema.optional(),
|
|
353
371
|
tools: z.array(chatModelInputToolSchema).optional(),
|
|
354
372
|
toolChoice: chatModelInputToolChoiceSchema.optional(),
|
|
355
|
-
modelOptions:
|
|
373
|
+
modelOptions: modelOptionsSchema.optional(),
|
|
356
374
|
});
|
|
357
375
|
export var FileOutputType;
|
|
358
376
|
(function (FileOutputType) {
|
|
@@ -32,14 +32,14 @@ export declare const imageModelInputSchema: z.ZodObject<{
|
|
|
32
32
|
}, "strip", z.ZodTypeAny, {
|
|
33
33
|
prompt: string;
|
|
34
34
|
model?: string | undefined;
|
|
35
|
-
responseFormat?: "base64" | "url" | undefined;
|
|
36
35
|
image?: string | string[] | undefined;
|
|
36
|
+
responseFormat?: "base64" | "url" | undefined;
|
|
37
37
|
n?: number | undefined;
|
|
38
38
|
}, {
|
|
39
39
|
prompt: string;
|
|
40
40
|
model?: string | undefined;
|
|
41
|
-
responseFormat?: "base64" | "url" | undefined;
|
|
42
41
|
image?: string | string[] | undefined;
|
|
42
|
+
responseFormat?: "base64" | "url" | undefined;
|
|
43
43
|
n?: number | undefined;
|
|
44
44
|
}>;
|
|
45
45
|
export interface ImageModelOutput extends Message {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.59.0",
|
|
4
4
|
"description": "The functional core of agentic AI",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -92,8 +92,8 @@
|
|
|
92
92
|
"yaml": "^2.8.0",
|
|
93
93
|
"zod": "^3.25.67",
|
|
94
94
|
"zod-to-json-schema": "^3.24.6",
|
|
95
|
-
"@aigne/
|
|
96
|
-
"@aigne/
|
|
95
|
+
"@aigne/observability-api": "^0.10.2",
|
|
96
|
+
"@aigne/platform-helpers": "^0.6.2"
|
|
97
97
|
},
|
|
98
98
|
"devDependencies": {
|
|
99
99
|
"@types/bun": "^1.2.18",
|