@aigne/core 1.72.0-beta.13 → 1.72.0-beta.15
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 +15 -0
- package/lib/cjs/agents/ai-agent.js +24 -6
- package/lib/cjs/agents/chat-model.d.ts +2 -0
- package/lib/cjs/agents/chat-model.js +18 -1
- package/lib/cjs/agents/image-model.js +1 -1
- package/lib/cjs/agents/model.d.ts +3 -3
- package/lib/cjs/agents/model.js +2 -2
- package/lib/cjs/agents/video-model.js +1 -1
- package/lib/cjs/utils/token-estimator.js +1 -1
- package/lib/dts/agents/chat-model.d.ts +2 -0
- package/lib/dts/agents/model.d.ts +3 -3
- package/lib/esm/agents/ai-agent.js +24 -6
- package/lib/esm/agents/chat-model.d.ts +2 -0
- package/lib/esm/agents/chat-model.js +18 -1
- package/lib/esm/agents/image-model.js +1 -1
- package/lib/esm/agents/model.d.ts +3 -3
- package/lib/esm/agents/model.js +2 -2
- package/lib/esm/agents/video-model.js +1 -1
- package/lib/esm/utils/token-estimator.js +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.72.0-beta.15](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.72.0-beta.14...core-v1.72.0-beta.15) (2026-01-10)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* **core:** simplify token-estimator logic for remaining characters ([45d43cc](https://github.com/AIGNE-io/aigne-framework/commit/45d43ccd3afd636cfb459eea2e6551e8f9c53765))
|
|
9
|
+
|
|
10
|
+
## [1.72.0-beta.14](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.72.0-beta.13...core-v1.72.0-beta.14) (2026-01-09)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* **core:** correct session schema for AIAgent ([30b1deb](https://github.com/AIGNE-io/aigne-framework/commit/30b1deb54ac20287580e0a85ef150b95010f8201))
|
|
16
|
+
* **core:** default enable auto breakpoints for chat model ([d4a6b83](https://github.com/AIGNE-io/aigne-framework/commit/d4a6b8323d6c83be45669885b32febb545bdf797))
|
|
17
|
+
|
|
3
18
|
## [1.72.0-beta.13](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.72.0-beta.12...core-v1.72.0-beta.13) (2026-01-08)
|
|
4
19
|
|
|
5
20
|
|
|
@@ -126,7 +126,7 @@ class AIAgent extends agent_js_1.Agent {
|
|
|
126
126
|
static schema({ filepath }) {
|
|
127
127
|
const instructionsSchema = (0, schema_js_1.getInstructionsSchema)({ filepath });
|
|
128
128
|
const nestAgentSchema = (0, agent_yaml_js_1.getNestAgentSchema)({ filepath });
|
|
129
|
-
|
|
129
|
+
const schema = (0, schema_js_1.camelizeSchema)(zod_1.z.object({
|
|
130
130
|
instructions: (0, schema_js_1.optionalize)(instructionsSchema),
|
|
131
131
|
inputKey: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
132
132
|
outputKey: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
@@ -137,14 +137,32 @@ class AIAgent extends agent_js_1.Agent {
|
|
|
137
137
|
keepTextInToolUses: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
|
|
138
138
|
catchToolsError: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
|
|
139
139
|
structuredStreamMode: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
|
|
140
|
-
|
|
140
|
+
session: (0, schema_js_1.optionalize)((0, schema_js_1.camelizeSchema)(zod_1.z.object({
|
|
141
141
|
mode: (0, schema_js_1.optionalize)(zod_1.z.enum(["auto", "disabled"])),
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
142
|
+
sessionMemory: (0, schema_js_1.optionalize)((0, schema_js_1.camelizeSchema)(zod_1.z.object({
|
|
143
|
+
mode: (0, schema_js_1.optionalize)(zod_1.z.enum(["auto", "disabled"])),
|
|
144
|
+
memoryRatio: (0, schema_js_1.optionalize)(zod_1.z.number().min(0).max(1)),
|
|
145
|
+
queryLimit: (0, schema_js_1.optionalize)(zod_1.z.number().int().min(0)),
|
|
146
|
+
async: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
|
|
147
|
+
extractor: (0, schema_js_1.optionalize)(nestAgentSchema),
|
|
148
|
+
}))),
|
|
149
|
+
userMemory: (0, schema_js_1.optionalize)((0, schema_js_1.camelizeSchema)(zod_1.z.object({
|
|
150
|
+
mode: (0, schema_js_1.optionalize)(zod_1.z.enum(["auto", "disabled"])),
|
|
151
|
+
memoryRatio: (0, schema_js_1.optionalize)(zod_1.z.number().min(0).max(1)),
|
|
152
|
+
queryLimit: (0, schema_js_1.optionalize)(zod_1.z.number().int().min(0)),
|
|
153
|
+
async: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
|
|
154
|
+
extractor: (0, schema_js_1.optionalize)(nestAgentSchema),
|
|
155
|
+
}))),
|
|
156
|
+
compact: (0, schema_js_1.optionalize)((0, schema_js_1.camelizeSchema)(zod_1.z.object({
|
|
157
|
+
mode: (0, schema_js_1.optionalize)(zod_1.z.enum(["auto", "disabled"])),
|
|
158
|
+
maxTokens: zod_1.z.number().int().min(0).optional(),
|
|
159
|
+
keepRecentRatio: (0, schema_js_1.optionalize)(zod_1.z.number().min(0).max(1)),
|
|
160
|
+
async: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
|
|
161
|
+
compactor: (0, schema_js_1.optionalize)(nestAgentSchema),
|
|
162
|
+
}))),
|
|
146
163
|
}))),
|
|
147
164
|
}));
|
|
165
|
+
return schema;
|
|
148
166
|
}
|
|
149
167
|
static async load(options) {
|
|
150
168
|
const schema = AIAgent.schema(options);
|
|
@@ -57,7 +57,9 @@ export declare abstract class ChatModel extends Model<ChatModelInput, ChatModelO
|
|
|
57
57
|
getModelCapabilities(): {
|
|
58
58
|
supportsParallelToolCalls: boolean;
|
|
59
59
|
};
|
|
60
|
+
getModelOptions(input: Message, options: AgentInvokeOptions): Promise<ChatModelInputOptions>;
|
|
60
61
|
private validateToolNames;
|
|
62
|
+
countTokens(input: ChatModelInput): Promise<number>;
|
|
61
63
|
/**
|
|
62
64
|
* Normalizes tool names to ensure compatibility with language models
|
|
63
65
|
*
|
|
@@ -40,6 +40,7 @@ const zod_from_json_schema_1 = require("zod-from-json-schema");
|
|
|
40
40
|
const schema_js_1 = require("../loader/schema.js");
|
|
41
41
|
const json_schema_js_1 = require("../utils/json-schema.js");
|
|
42
42
|
const logger_js_1 = require("../utils/logger.js");
|
|
43
|
+
const token_estimator_js_1 = require("../utils/token-estimator.js");
|
|
43
44
|
const type_utils_js_1 = require("../utils/type-utils.js");
|
|
44
45
|
const agent_js_1 = require("./agent.js");
|
|
45
46
|
const model_js_1 = require("./model.js");
|
|
@@ -117,6 +118,19 @@ class ChatModel extends model_js_1.Model {
|
|
|
117
118
|
supportsParallelToolCalls: this.supportsParallelToolCalls,
|
|
118
119
|
};
|
|
119
120
|
}
|
|
121
|
+
async getModelOptions(input, options) {
|
|
122
|
+
const modelOptions = (await super.getModelOptions(input, options));
|
|
123
|
+
return {
|
|
124
|
+
...modelOptions,
|
|
125
|
+
cacheConfig: {
|
|
126
|
+
...modelOptions.cacheConfig,
|
|
127
|
+
autoBreakpoints: {
|
|
128
|
+
...modelOptions.cacheConfig?.autoBreakpoints,
|
|
129
|
+
lastMessage: modelOptions.cacheConfig?.autoBreakpoints?.lastMessage ?? true,
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
120
134
|
validateToolNames(tools) {
|
|
121
135
|
for (const tool of tools ?? []) {
|
|
122
136
|
if (!/^[a-zA-Z0-9_]+$/.test(tool.function.name)) {
|
|
@@ -124,6 +138,9 @@ class ChatModel extends model_js_1.Model {
|
|
|
124
138
|
}
|
|
125
139
|
}
|
|
126
140
|
}
|
|
141
|
+
async countTokens(input) {
|
|
142
|
+
return (0, token_estimator_js_1.estimateTokens)(JSON.stringify(input));
|
|
143
|
+
}
|
|
127
144
|
/**
|
|
128
145
|
* Normalizes tool names to ensure compatibility with language models
|
|
129
146
|
*
|
|
@@ -238,7 +255,7 @@ class ChatModel extends model_js_1.Model {
|
|
|
238
255
|
const files = zod_1.z.array(model_js_1.fileUnionContentSchema).parse(output.files);
|
|
239
256
|
output = {
|
|
240
257
|
...output,
|
|
241
|
-
files: await Promise.all(files.map((file) => this.transformFileType(input.outputFileType, file
|
|
258
|
+
files: await Promise.all(files.map((file) => this.transformFileType(input.outputFileType, file))),
|
|
242
259
|
};
|
|
243
260
|
}
|
|
244
261
|
// Remove fields with `null` value for validation
|
|
@@ -70,7 +70,7 @@ class ImageModel extends model_js_1.Model {
|
|
|
70
70
|
const images = zod_1.z.array(model_js_1.fileUnionContentSchema).parse(output.images);
|
|
71
71
|
output = {
|
|
72
72
|
...output,
|
|
73
|
-
images: await Promise.all(images.map((image) => this.transformFileType(input.outputFileType, image
|
|
73
|
+
images: await Promise.all(images.map((image) => this.transformFileType(input.outputFileType, image))),
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
76
|
return super.processAgentOutput(input, output, options);
|
|
@@ -17,9 +17,9 @@ export declare abstract class Model<I extends Message = any, O extends Message =
|
|
|
17
17
|
*/
|
|
18
18
|
getModelOptions(input: Message, options: AgentInvokeOptions): Promise<Record<string, unknown>>;
|
|
19
19
|
protected preprocess(input: I, options: AgentInvokeOptions): Promise<void>;
|
|
20
|
-
transformFileType(fileType: "file", data: FileUnionContent
|
|
21
|
-
transformFileType(fileType: "local" | undefined, data: FileUnionContent
|
|
22
|
-
transformFileType(fileType: FileType | undefined, data: FileUnionContent
|
|
20
|
+
transformFileType(fileType: "file", data: FileUnionContent): Promise<FileContent>;
|
|
21
|
+
transformFileType(fileType: "local" | undefined, data: FileUnionContent): Promise<LocalContent>;
|
|
22
|
+
transformFileType(fileType: FileType | undefined, data: FileUnionContent): Promise<FileUnionContent>;
|
|
23
23
|
static getFileExtension(type: string): Promise<string | undefined>;
|
|
24
24
|
static getMimeType(filename: string): Promise<string | undefined>;
|
|
25
25
|
downloadFile(url: string): Promise<Response>;
|
package/lib/cjs/agents/model.js
CHANGED
|
@@ -89,13 +89,13 @@ class Model extends agent_js_1.Agent {
|
|
|
89
89
|
Object.assign(input, { modelOptions: await this.getModelOptions(input, options) });
|
|
90
90
|
return super.preprocess(input, options);
|
|
91
91
|
}
|
|
92
|
-
async transformFileType(fileType = "local", data
|
|
92
|
+
async transformFileType(fileType = "local", data) {
|
|
93
93
|
if (fileType === data.type)
|
|
94
94
|
return data;
|
|
95
95
|
const common = (0, type_utils_js_1.pick)(data, "filename", "mimeType");
|
|
96
96
|
switch (fileType) {
|
|
97
97
|
case "local": {
|
|
98
|
-
const dir = index_js_1.nodejs.path.join(index_js_1.nodejs.os.tmpdir(),
|
|
98
|
+
const dir = index_js_1.nodejs.path.join(index_js_1.nodejs.os.tmpdir(), (0, uuid_1.v7)());
|
|
99
99
|
await index_js_1.nodejs.fs.mkdir(dir, { recursive: true });
|
|
100
100
|
const ext = await Model.getFileExtension(data.mimeType || data.filename || "");
|
|
101
101
|
const id = (0, uuid_1.v7)();
|
|
@@ -43,7 +43,7 @@ class VideoModel extends model_js_1.Model {
|
|
|
43
43
|
const videos = zod_1.z.array(model_js_1.fileUnionContentSchema).parse(output.videos);
|
|
44
44
|
output = {
|
|
45
45
|
...output,
|
|
46
|
-
videos: await Promise.all(videos.map((video) => this.transformFileType(input.outputFileType, video
|
|
46
|
+
videos: await Promise.all(videos.map((video) => this.transformFileType(input.outputFileType, video))),
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
49
|
return super.processAgentOutput(input, output, options);
|
|
@@ -8,7 +8,7 @@ exports.estimateTokens = estimateTokens;
|
|
|
8
8
|
const CHAR_TYPE_RATIOS = {
|
|
9
9
|
chinese: 1.5, // Chinese characters: ~1.5 characters per token
|
|
10
10
|
word: 0.75, // English words: ~0.75 tokens per word (accounting for subword tokenization)
|
|
11
|
-
other:
|
|
11
|
+
other: 1, // Other characters (punctuation, numbers, etc.): ~1 character per token
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
14
|
* Regular expressions for character type detection
|
|
@@ -57,7 +57,9 @@ export declare abstract class ChatModel extends Model<ChatModelInput, ChatModelO
|
|
|
57
57
|
getModelCapabilities(): {
|
|
58
58
|
supportsParallelToolCalls: boolean;
|
|
59
59
|
};
|
|
60
|
+
getModelOptions(input: Message, options: AgentInvokeOptions): Promise<ChatModelInputOptions>;
|
|
60
61
|
private validateToolNames;
|
|
62
|
+
countTokens(input: ChatModelInput): Promise<number>;
|
|
61
63
|
/**
|
|
62
64
|
* Normalizes tool names to ensure compatibility with language models
|
|
63
65
|
*
|
|
@@ -17,9 +17,9 @@ export declare abstract class Model<I extends Message = any, O extends Message =
|
|
|
17
17
|
*/
|
|
18
18
|
getModelOptions(input: Message, options: AgentInvokeOptions): Promise<Record<string, unknown>>;
|
|
19
19
|
protected preprocess(input: I, options: AgentInvokeOptions): Promise<void>;
|
|
20
|
-
transformFileType(fileType: "file", data: FileUnionContent
|
|
21
|
-
transformFileType(fileType: "local" | undefined, data: FileUnionContent
|
|
22
|
-
transformFileType(fileType: FileType | undefined, data: FileUnionContent
|
|
20
|
+
transformFileType(fileType: "file", data: FileUnionContent): Promise<FileContent>;
|
|
21
|
+
transformFileType(fileType: "local" | undefined, data: FileUnionContent): Promise<LocalContent>;
|
|
22
|
+
transformFileType(fileType: FileType | undefined, data: FileUnionContent): Promise<FileUnionContent>;
|
|
23
23
|
static getFileExtension(type: string): Promise<string | undefined>;
|
|
24
24
|
static getMimeType(filename: string): Promise<string | undefined>;
|
|
25
25
|
downloadFile(url: string): Promise<Response>;
|
|
@@ -90,7 +90,7 @@ export class AIAgent extends Agent {
|
|
|
90
90
|
static schema({ filepath }) {
|
|
91
91
|
const instructionsSchema = getInstructionsSchema({ filepath });
|
|
92
92
|
const nestAgentSchema = getNestAgentSchema({ filepath });
|
|
93
|
-
|
|
93
|
+
const schema = camelizeSchema(z.object({
|
|
94
94
|
instructions: optionalize(instructionsSchema),
|
|
95
95
|
inputKey: optionalize(z.string()),
|
|
96
96
|
outputKey: optionalize(z.string()),
|
|
@@ -101,14 +101,32 @@ export class AIAgent extends Agent {
|
|
|
101
101
|
keepTextInToolUses: optionalize(z.boolean()),
|
|
102
102
|
catchToolsError: optionalize(z.boolean()),
|
|
103
103
|
structuredStreamMode: optionalize(z.boolean()),
|
|
104
|
-
|
|
104
|
+
session: optionalize(camelizeSchema(z.object({
|
|
105
105
|
mode: optionalize(z.enum(["auto", "disabled"])),
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
sessionMemory: optionalize(camelizeSchema(z.object({
|
|
107
|
+
mode: optionalize(z.enum(["auto", "disabled"])),
|
|
108
|
+
memoryRatio: optionalize(z.number().min(0).max(1)),
|
|
109
|
+
queryLimit: optionalize(z.number().int().min(0)),
|
|
110
|
+
async: optionalize(z.boolean()),
|
|
111
|
+
extractor: optionalize(nestAgentSchema),
|
|
112
|
+
}))),
|
|
113
|
+
userMemory: optionalize(camelizeSchema(z.object({
|
|
114
|
+
mode: optionalize(z.enum(["auto", "disabled"])),
|
|
115
|
+
memoryRatio: optionalize(z.number().min(0).max(1)),
|
|
116
|
+
queryLimit: optionalize(z.number().int().min(0)),
|
|
117
|
+
async: optionalize(z.boolean()),
|
|
118
|
+
extractor: optionalize(nestAgentSchema),
|
|
119
|
+
}))),
|
|
120
|
+
compact: optionalize(camelizeSchema(z.object({
|
|
121
|
+
mode: optionalize(z.enum(["auto", "disabled"])),
|
|
122
|
+
maxTokens: z.number().int().min(0).optional(),
|
|
123
|
+
keepRecentRatio: optionalize(z.number().min(0).max(1)),
|
|
124
|
+
async: optionalize(z.boolean()),
|
|
125
|
+
compactor: optionalize(nestAgentSchema),
|
|
126
|
+
}))),
|
|
110
127
|
}))),
|
|
111
128
|
}));
|
|
129
|
+
return schema;
|
|
112
130
|
}
|
|
113
131
|
static async load(options) {
|
|
114
132
|
const schema = AIAgent.schema(options);
|
|
@@ -57,7 +57,9 @@ export declare abstract class ChatModel extends Model<ChatModelInput, ChatModelO
|
|
|
57
57
|
getModelCapabilities(): {
|
|
58
58
|
supportsParallelToolCalls: boolean;
|
|
59
59
|
};
|
|
60
|
+
getModelOptions(input: Message, options: AgentInvokeOptions): Promise<ChatModelInputOptions>;
|
|
60
61
|
private validateToolNames;
|
|
62
|
+
countTokens(input: ChatModelInput): Promise<number>;
|
|
61
63
|
/**
|
|
62
64
|
* Normalizes tool names to ensure compatibility with language models
|
|
63
65
|
*
|
|
@@ -4,6 +4,7 @@ import { convertJsonSchemaToZod } from "zod-from-json-schema";
|
|
|
4
4
|
import { optionalize } from "../loader/schema.js";
|
|
5
5
|
import { wrapAutoParseJsonSchema } from "../utils/json-schema.js";
|
|
6
6
|
import { logger } from "../utils/logger.js";
|
|
7
|
+
import { estimateTokens } from "../utils/token-estimator.js";
|
|
7
8
|
import { checkArguments, isNil, omitByDeep } from "../utils/type-utils.js";
|
|
8
9
|
import { agentOptionsSchema, getterSchema, } from "./agent.js";
|
|
9
10
|
import { fileContentSchema, fileUnionContentSchema, localContentSchema, Model, urlContentSchema, } from "./model.js";
|
|
@@ -80,6 +81,19 @@ export class ChatModel extends Model {
|
|
|
80
81
|
supportsParallelToolCalls: this.supportsParallelToolCalls,
|
|
81
82
|
};
|
|
82
83
|
}
|
|
84
|
+
async getModelOptions(input, options) {
|
|
85
|
+
const modelOptions = (await super.getModelOptions(input, options));
|
|
86
|
+
return {
|
|
87
|
+
...modelOptions,
|
|
88
|
+
cacheConfig: {
|
|
89
|
+
...modelOptions.cacheConfig,
|
|
90
|
+
autoBreakpoints: {
|
|
91
|
+
...modelOptions.cacheConfig?.autoBreakpoints,
|
|
92
|
+
lastMessage: modelOptions.cacheConfig?.autoBreakpoints?.lastMessage ?? true,
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
83
97
|
validateToolNames(tools) {
|
|
84
98
|
for (const tool of tools ?? []) {
|
|
85
99
|
if (!/^[a-zA-Z0-9_]+$/.test(tool.function.name)) {
|
|
@@ -87,6 +101,9 @@ export class ChatModel extends Model {
|
|
|
87
101
|
}
|
|
88
102
|
}
|
|
89
103
|
}
|
|
104
|
+
async countTokens(input) {
|
|
105
|
+
return estimateTokens(JSON.stringify(input));
|
|
106
|
+
}
|
|
90
107
|
/**
|
|
91
108
|
* Normalizes tool names to ensure compatibility with language models
|
|
92
109
|
*
|
|
@@ -201,7 +218,7 @@ export class ChatModel extends Model {
|
|
|
201
218
|
const files = z.array(fileUnionContentSchema).parse(output.files);
|
|
202
219
|
output = {
|
|
203
220
|
...output,
|
|
204
|
-
files: await Promise.all(files.map((file) => this.transformFileType(input.outputFileType, file
|
|
221
|
+
files: await Promise.all(files.map((file) => this.transformFileType(input.outputFileType, file))),
|
|
205
222
|
};
|
|
206
223
|
}
|
|
207
224
|
// Remove fields with `null` value for validation
|
|
@@ -67,7 +67,7 @@ export class ImageModel extends Model {
|
|
|
67
67
|
const images = z.array(fileUnionContentSchema).parse(output.images);
|
|
68
68
|
output = {
|
|
69
69
|
...output,
|
|
70
|
-
images: await Promise.all(images.map((image) => this.transformFileType(input.outputFileType, image
|
|
70
|
+
images: await Promise.all(images.map((image) => this.transformFileType(input.outputFileType, image))),
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
73
|
return super.processAgentOutput(input, output, options);
|
|
@@ -17,9 +17,9 @@ export declare abstract class Model<I extends Message = any, O extends Message =
|
|
|
17
17
|
*/
|
|
18
18
|
getModelOptions(input: Message, options: AgentInvokeOptions): Promise<Record<string, unknown>>;
|
|
19
19
|
protected preprocess(input: I, options: AgentInvokeOptions): Promise<void>;
|
|
20
|
-
transformFileType(fileType: "file", data: FileUnionContent
|
|
21
|
-
transformFileType(fileType: "local" | undefined, data: FileUnionContent
|
|
22
|
-
transformFileType(fileType: FileType | undefined, data: FileUnionContent
|
|
20
|
+
transformFileType(fileType: "file", data: FileUnionContent): Promise<FileContent>;
|
|
21
|
+
transformFileType(fileType: "local" | undefined, data: FileUnionContent): Promise<LocalContent>;
|
|
22
|
+
transformFileType(fileType: FileType | undefined, data: FileUnionContent): Promise<FileUnionContent>;
|
|
23
23
|
static getFileExtension(type: string): Promise<string | undefined>;
|
|
24
24
|
static getMimeType(filename: string): Promise<string | undefined>;
|
|
25
25
|
downloadFile(url: string): Promise<Response>;
|
package/lib/esm/agents/model.js
CHANGED
|
@@ -53,13 +53,13 @@ export class Model extends Agent {
|
|
|
53
53
|
Object.assign(input, { modelOptions: await this.getModelOptions(input, options) });
|
|
54
54
|
return super.preprocess(input, options);
|
|
55
55
|
}
|
|
56
|
-
async transformFileType(fileType = "local", data
|
|
56
|
+
async transformFileType(fileType = "local", data) {
|
|
57
57
|
if (fileType === data.type)
|
|
58
58
|
return data;
|
|
59
59
|
const common = pick(data, "filename", "mimeType");
|
|
60
60
|
switch (fileType) {
|
|
61
61
|
case "local": {
|
|
62
|
-
const dir = nodejs.path.join(nodejs.os.tmpdir(),
|
|
62
|
+
const dir = nodejs.path.join(nodejs.os.tmpdir(), v7());
|
|
63
63
|
await nodejs.fs.mkdir(dir, { recursive: true });
|
|
64
64
|
const ext = await Model.getFileExtension(data.mimeType || data.filename || "");
|
|
65
65
|
const id = v7();
|
|
@@ -40,7 +40,7 @@ export class VideoModel extends Model {
|
|
|
40
40
|
const videos = z.array(fileUnionContentSchema).parse(output.videos);
|
|
41
41
|
output = {
|
|
42
42
|
...output,
|
|
43
|
-
videos: await Promise.all(videos.map((video) => this.transformFileType(input.outputFileType, video
|
|
43
|
+
videos: await Promise.all(videos.map((video) => this.transformFileType(input.outputFileType, video))),
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
return super.processAgentOutput(input, output, options);
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
const CHAR_TYPE_RATIOS = {
|
|
6
6
|
chinese: 1.5, // Chinese characters: ~1.5 characters per token
|
|
7
7
|
word: 0.75, // English words: ~0.75 tokens per word (accounting for subword tokenization)
|
|
8
|
-
other:
|
|
8
|
+
other: 1, // Other characters (punctuation, numbers, etc.): ~1 character per token
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
11
|
* Regular expressions for character type detection
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/core",
|
|
3
|
-
"version": "1.72.0-beta.
|
|
3
|
+
"version": "1.72.0-beta.15",
|
|
4
4
|
"description": "The functional core of agentic AI",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -93,10 +93,10 @@
|
|
|
93
93
|
"zod": "^3.25.67",
|
|
94
94
|
"zod-from-json-schema": "^0.0.5",
|
|
95
95
|
"zod-to-json-schema": "^3.24.6",
|
|
96
|
-
"@aigne/afs": "^1.4.0-beta.7",
|
|
97
|
-
"@aigne/afs-history": "^1.2.0-beta.8",
|
|
98
96
|
"@aigne/observability-api": "^0.11.14-beta.2",
|
|
99
|
-
"@aigne/platform-helpers": "^0.6.7-beta.1"
|
|
97
|
+
"@aigne/platform-helpers": "^0.6.7-beta.1",
|
|
98
|
+
"@aigne/afs": "^1.4.0-beta.7",
|
|
99
|
+
"@aigne/afs-history": "^1.2.0-beta.8"
|
|
100
100
|
},
|
|
101
101
|
"devDependencies": {
|
|
102
102
|
"@types/bun": "^1.2.22",
|