@aigne/core 1.72.0-beta.2 → 1.72.0-beta.23
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 +261 -0
- package/lib/cjs/agents/agent.d.ts +42 -11
- package/lib/cjs/agents/agent.js +34 -8
- package/lib/cjs/agents/ai-agent.d.ts +63 -4
- package/lib/cjs/agents/ai-agent.js +154 -20
- package/lib/cjs/agents/chat-model.d.ts +157 -0
- package/lib/cjs/agents/chat-model.js +71 -6
- package/lib/cjs/agents/image-agent.d.ts +17 -1
- package/lib/cjs/agents/image-agent.js +16 -0
- package/lib/cjs/agents/image-model.d.ts +12 -2
- package/lib/cjs/agents/image-model.js +1 -1
- package/lib/cjs/agents/mcp-agent.d.ts +17 -0
- package/lib/cjs/agents/mcp-agent.js +18 -0
- package/lib/cjs/agents/model.d.ts +3 -3
- package/lib/cjs/agents/model.js +2 -2
- package/lib/cjs/agents/team-agent.d.ts +55 -0
- package/lib/cjs/agents/team-agent.js +31 -0
- package/lib/cjs/agents/transform-agent.d.ts +12 -0
- package/lib/cjs/agents/transform-agent.js +13 -0
- package/lib/cjs/agents/video-model.d.ts +10 -0
- package/lib/cjs/agents/video-model.js +1 -1
- package/lib/cjs/aigne/context.js +1 -3
- package/lib/cjs/aigne/usage.d.ts +4 -0
- package/lib/cjs/aigne/usage.js +6 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/loader/agent-yaml.d.ts +5 -63
- package/lib/cjs/loader/agent-yaml.js +4 -129
- package/lib/cjs/loader/agents.d.ts +4 -0
- package/lib/cjs/loader/agents.js +17 -0
- package/lib/cjs/loader/index.d.ts +16 -12
- package/lib/cjs/loader/index.js +20 -81
- package/lib/cjs/loader/schema.d.ts +21 -6
- package/lib/cjs/loader/schema.js +60 -1
- package/lib/cjs/memory/recorder.d.ts +4 -4
- package/lib/cjs/memory/retriever.d.ts +4 -4
- package/lib/cjs/prompt/agent-session.d.ts +163 -0
- package/lib/cjs/prompt/agent-session.js +1008 -0
- package/lib/cjs/prompt/compact/compactor.d.ts +7 -0
- package/lib/cjs/prompt/compact/compactor.js +52 -0
- package/lib/cjs/prompt/compact/session-memory-extractor.d.ts +7 -0
- package/lib/cjs/prompt/compact/session-memory-extractor.js +143 -0
- package/lib/cjs/prompt/compact/types.d.ts +336 -0
- package/lib/cjs/prompt/compact/types.js +53 -0
- package/lib/cjs/prompt/compact/user-memory-extractor.d.ts +7 -0
- package/lib/cjs/prompt/compact/user-memory-extractor.js +124 -0
- package/lib/cjs/prompt/context/afs/history.d.ts +5 -1
- package/lib/cjs/prompt/context/afs/history.js +3 -2
- package/lib/cjs/prompt/context/afs/index.js +8 -1
- package/lib/cjs/prompt/prompt-builder.d.ts +11 -9
- package/lib/cjs/prompt/prompt-builder.js +79 -120
- package/lib/cjs/prompt/skills/afs/agent-skill/agent-skill.d.ts +19 -0
- package/lib/cjs/prompt/skills/afs/agent-skill/agent-skill.js +69 -0
- package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.d.ts +12 -0
- package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.js +50 -0
- package/lib/cjs/prompt/skills/afs/delete.js +15 -3
- package/lib/cjs/prompt/skills/afs/edit.d.ts +6 -9
- package/lib/cjs/prompt/skills/afs/edit.js +85 -59
- package/lib/cjs/prompt/skills/afs/exec.js +17 -6
- package/lib/cjs/prompt/skills/afs/index.js +4 -1
- package/lib/cjs/prompt/skills/afs/list.d.ts +2 -0
- package/lib/cjs/prompt/skills/afs/list.js +35 -11
- package/lib/cjs/prompt/skills/afs/read.d.ts +9 -3
- package/lib/cjs/prompt/skills/afs/read.js +67 -15
- package/lib/cjs/prompt/skills/afs/rename.js +18 -4
- package/lib/cjs/prompt/skills/afs/search.js +21 -5
- package/lib/cjs/prompt/skills/afs/write.js +20 -6
- package/lib/cjs/prompt/template.d.ts +84 -9
- package/lib/cjs/prompt/template.js +46 -17
- package/lib/cjs/utils/mcp-utils.js +1 -1
- package/lib/cjs/utils/token-estimator.js +1 -1
- package/lib/dts/agents/agent.d.ts +42 -11
- package/lib/dts/agents/ai-agent.d.ts +63 -4
- package/lib/dts/agents/chat-model.d.ts +157 -0
- package/lib/dts/agents/image-agent.d.ts +17 -1
- package/lib/dts/agents/image-model.d.ts +12 -2
- package/lib/dts/agents/mcp-agent.d.ts +17 -0
- package/lib/dts/agents/model.d.ts +3 -3
- package/lib/dts/agents/team-agent.d.ts +55 -0
- package/lib/dts/agents/transform-agent.d.ts +12 -0
- package/lib/dts/agents/video-model.d.ts +10 -0
- package/lib/dts/aigne/context.d.ts +2 -2
- package/lib/dts/aigne/usage.d.ts +4 -0
- package/lib/dts/index.d.ts +1 -0
- package/lib/dts/loader/agent-yaml.d.ts +5 -63
- package/lib/dts/loader/agents.d.ts +4 -0
- package/lib/dts/loader/index.d.ts +16 -12
- package/lib/dts/loader/schema.d.ts +21 -6
- package/lib/dts/memory/recorder.d.ts +4 -4
- package/lib/dts/memory/retriever.d.ts +4 -4
- package/lib/dts/prompt/agent-session.d.ts +163 -0
- package/lib/dts/prompt/compact/compactor.d.ts +7 -0
- package/lib/dts/prompt/compact/session-memory-extractor.d.ts +7 -0
- package/lib/dts/prompt/compact/types.d.ts +336 -0
- package/lib/dts/prompt/compact/user-memory-extractor.d.ts +7 -0
- package/lib/dts/prompt/context/afs/history.d.ts +5 -1
- package/lib/dts/prompt/prompt-builder.d.ts +11 -9
- package/lib/dts/prompt/skills/afs/agent-skill/agent-skill.d.ts +19 -0
- package/lib/dts/prompt/skills/afs/agent-skill/skill-loader.d.ts +12 -0
- package/lib/dts/prompt/skills/afs/edit.d.ts +6 -9
- package/lib/dts/prompt/skills/afs/list.d.ts +2 -0
- package/lib/dts/prompt/skills/afs/read.d.ts +9 -3
- package/lib/dts/prompt/template.d.ts +84 -9
- package/lib/esm/agents/agent.d.ts +42 -11
- package/lib/esm/agents/agent.js +34 -8
- package/lib/esm/agents/ai-agent.d.ts +63 -4
- package/lib/esm/agents/ai-agent.js +154 -20
- package/lib/esm/agents/chat-model.d.ts +157 -0
- package/lib/esm/agents/chat-model.js +70 -5
- package/lib/esm/agents/image-agent.d.ts +17 -1
- package/lib/esm/agents/image-agent.js +16 -0
- package/lib/esm/agents/image-model.d.ts +12 -2
- package/lib/esm/agents/image-model.js +1 -1
- package/lib/esm/agents/mcp-agent.d.ts +17 -0
- package/lib/esm/agents/mcp-agent.js +18 -0
- package/lib/esm/agents/model.d.ts +3 -3
- package/lib/esm/agents/model.js +2 -2
- package/lib/esm/agents/team-agent.d.ts +55 -0
- package/lib/esm/agents/team-agent.js +31 -0
- package/lib/esm/agents/transform-agent.d.ts +12 -0
- package/lib/esm/agents/transform-agent.js +13 -0
- package/lib/esm/agents/video-model.d.ts +10 -0
- package/lib/esm/agents/video-model.js +1 -1
- package/lib/esm/aigne/context.d.ts +2 -2
- package/lib/esm/aigne/context.js +2 -4
- package/lib/esm/aigne/usage.d.ts +4 -0
- package/lib/esm/aigne/usage.js +6 -0
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/loader/agent-yaml.d.ts +5 -63
- package/lib/esm/loader/agent-yaml.js +4 -128
- package/lib/esm/loader/agents.d.ts +4 -0
- package/lib/esm/loader/agents.js +14 -0
- package/lib/esm/loader/index.d.ts +16 -12
- package/lib/esm/loader/index.js +21 -81
- package/lib/esm/loader/schema.d.ts +21 -6
- package/lib/esm/loader/schema.js +57 -0
- package/lib/esm/memory/recorder.d.ts +4 -4
- package/lib/esm/memory/retriever.d.ts +4 -4
- package/lib/esm/prompt/agent-session.d.ts +163 -0
- package/lib/esm/prompt/agent-session.js +968 -0
- package/lib/esm/prompt/compact/compactor.d.ts +7 -0
- package/lib/esm/prompt/compact/compactor.js +48 -0
- package/lib/esm/prompt/compact/session-memory-extractor.d.ts +7 -0
- package/lib/esm/prompt/compact/session-memory-extractor.js +139 -0
- package/lib/esm/prompt/compact/types.d.ts +336 -0
- package/lib/esm/prompt/compact/types.js +50 -0
- package/lib/esm/prompt/compact/user-memory-extractor.d.ts +7 -0
- package/lib/esm/prompt/compact/user-memory-extractor.js +120 -0
- package/lib/esm/prompt/context/afs/history.d.ts +5 -1
- package/lib/esm/prompt/context/afs/history.js +3 -2
- package/lib/esm/prompt/context/afs/index.js +8 -1
- package/lib/esm/prompt/prompt-builder.d.ts +11 -9
- package/lib/esm/prompt/prompt-builder.js +80 -121
- package/lib/esm/prompt/skills/afs/agent-skill/agent-skill.d.ts +19 -0
- package/lib/esm/prompt/skills/afs/agent-skill/agent-skill.js +65 -0
- package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.d.ts +12 -0
- package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.js +43 -0
- package/lib/esm/prompt/skills/afs/delete.js +15 -3
- package/lib/esm/prompt/skills/afs/edit.d.ts +6 -9
- package/lib/esm/prompt/skills/afs/edit.js +85 -59
- package/lib/esm/prompt/skills/afs/exec.js +17 -6
- package/lib/esm/prompt/skills/afs/index.js +4 -1
- package/lib/esm/prompt/skills/afs/list.d.ts +2 -0
- package/lib/esm/prompt/skills/afs/list.js +35 -11
- package/lib/esm/prompt/skills/afs/read.d.ts +9 -3
- package/lib/esm/prompt/skills/afs/read.js +67 -15
- package/lib/esm/prompt/skills/afs/rename.js +18 -4
- package/lib/esm/prompt/skills/afs/search.js +21 -5
- package/lib/esm/prompt/skills/afs/write.js +20 -6
- package/lib/esm/prompt/template.d.ts +84 -9
- package/lib/esm/prompt/template.js +46 -17
- package/lib/esm/utils/mcp-utils.js +1 -1
- package/lib/esm/utils/token-estimator.js +1 -1
- package/package.json +7 -6
|
@@ -33,13 +33,14 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.chatModelOutputUsageSchema = exports.unionContentSchema = exports.textContentSchema = exports.roleSchema = exports.ChatModel = exports.StructuredOutputError = void 0;
|
|
36
|
+
exports.chatModelOutputUsageSchema = exports.DEFAULT_CACHE_CONFIG = exports.unionContentSchema = exports.textContentSchema = exports.roleSchema = exports.ChatModel = exports.StructuredOutputError = void 0;
|
|
37
37
|
const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
|
|
38
38
|
const zod_1 = require("zod");
|
|
39
39
|
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
|
*
|
|
@@ -225,6 +242,10 @@ class ChatModel extends model_js_1.Model {
|
|
|
225
242
|
options.context.usage.inputTokens += usage.inputTokens;
|
|
226
243
|
if (usage.aigneHubCredits)
|
|
227
244
|
options.context.usage.aigneHubCredits += usage.aigneHubCredits;
|
|
245
|
+
if (usage.cacheCreationInputTokens)
|
|
246
|
+
options.context.usage.cacheCreationInputTokens += usage.cacheCreationInputTokens;
|
|
247
|
+
if (usage.cacheReadInputTokens)
|
|
248
|
+
options.context.usage.cacheReadInputTokens += usage.cacheReadInputTokens;
|
|
228
249
|
if (usage.creditPrefix)
|
|
229
250
|
options.context.usage.creditPrefix = usage.creditPrefix;
|
|
230
251
|
}
|
|
@@ -234,7 +255,7 @@ class ChatModel extends model_js_1.Model {
|
|
|
234
255
|
const files = zod_1.z.array(model_js_1.fileUnionContentSchema).parse(output.files);
|
|
235
256
|
output = {
|
|
236
257
|
...output,
|
|
237
|
-
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))),
|
|
238
259
|
};
|
|
239
260
|
}
|
|
240
261
|
// Remove fields with `null` value for validation
|
|
@@ -282,6 +303,10 @@ exports.roleSchema = zod_1.z.union([
|
|
|
282
303
|
exports.textContentSchema = zod_1.z.object({
|
|
283
304
|
type: zod_1.z.literal("text"),
|
|
284
305
|
text: zod_1.z.string(),
|
|
306
|
+
cacheControl: (0, schema_js_1.optionalize)(zod_1.z.object({
|
|
307
|
+
type: zod_1.z.literal("ephemeral"),
|
|
308
|
+
ttl: (0, schema_js_1.optionalize)(zod_1.z.union([zod_1.z.literal("5m"), zod_1.z.literal("1h")])),
|
|
309
|
+
})),
|
|
285
310
|
});
|
|
286
311
|
exports.unionContentSchema = zod_1.z.discriminatedUnion("type", [
|
|
287
312
|
exports.textContentSchema,
|
|
@@ -303,6 +328,10 @@ const chatModelInputMessageSchema = zod_1.z.object({
|
|
|
303
328
|
}))),
|
|
304
329
|
toolCallId: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
305
330
|
name: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
331
|
+
cacheControl: (0, schema_js_1.optionalize)(zod_1.z.object({
|
|
332
|
+
type: zod_1.z.literal("ephemeral"),
|
|
333
|
+
ttl: (0, schema_js_1.optionalize)(zod_1.z.union([zod_1.z.literal("5m"), zod_1.z.literal("1h")])),
|
|
334
|
+
})),
|
|
306
335
|
});
|
|
307
336
|
const chatModelInputResponseFormatSchema = zod_1.z.discriminatedUnion("type", [
|
|
308
337
|
zod_1.z.object({ type: zod_1.z.literal("text") }),
|
|
@@ -324,6 +353,10 @@ const chatModelInputToolSchema = zod_1.z.object({
|
|
|
324
353
|
parameters: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()),
|
|
325
354
|
}),
|
|
326
355
|
metadata: (0, schema_js_1.optionalize)(zod_1.z.record(zod_1.z.string(), zod_1.z.unknown())),
|
|
356
|
+
cacheControl: (0, schema_js_1.optionalize)(zod_1.z.object({
|
|
357
|
+
type: zod_1.z.literal("ephemeral"),
|
|
358
|
+
ttl: (0, schema_js_1.optionalize)(zod_1.z.union([zod_1.z.literal("5m"), zod_1.z.literal("1h")])),
|
|
359
|
+
})),
|
|
327
360
|
});
|
|
328
361
|
const chatModelInputToolChoiceSchema = zod_1.z.union([
|
|
329
362
|
zod_1.z.literal("auto"),
|
|
@@ -331,6 +364,22 @@ const chatModelInputToolChoiceSchema = zod_1.z.union([
|
|
|
331
364
|
zod_1.z.literal("required"),
|
|
332
365
|
chatModelInputToolSchema,
|
|
333
366
|
]);
|
|
367
|
+
/**
|
|
368
|
+
* Default cache configuration
|
|
369
|
+
*
|
|
370
|
+
* Enables automatic caching for system messages and tool definitions,
|
|
371
|
+
* which typically provides the best cost/performance tradeoff.
|
|
372
|
+
*/
|
|
373
|
+
exports.DEFAULT_CACHE_CONFIG = {
|
|
374
|
+
enabled: true,
|
|
375
|
+
ttl: "5m",
|
|
376
|
+
strategy: "auto",
|
|
377
|
+
autoBreakpoints: {
|
|
378
|
+
tools: true,
|
|
379
|
+
system: true,
|
|
380
|
+
lastMessage: false,
|
|
381
|
+
},
|
|
382
|
+
};
|
|
334
383
|
const modelOptionsSchemaProperties = {
|
|
335
384
|
model: zod_1.z.string(),
|
|
336
385
|
temperature: zod_1.z.number(),
|
|
@@ -346,15 +395,29 @@ const modelOptionsSchemaProperties = {
|
|
|
346
395
|
zod_1.z.literal("medium"),
|
|
347
396
|
zod_1.z.literal("high"),
|
|
348
397
|
]),
|
|
398
|
+
cacheConfig: zod_1.z.object({
|
|
399
|
+
enabled: (0, schema_js_1.optionalize)(zod_1.z.boolean().default(true)),
|
|
400
|
+
ttl: (0, schema_js_1.optionalize)(zod_1.z.union([zod_1.z.literal("5m"), zod_1.z.literal("1h"), zod_1.z.number()]).default("5m")),
|
|
401
|
+
strategy: (0, schema_js_1.optionalize)(zod_1.z.union([zod_1.z.literal("auto"), zod_1.z.literal("manual")]).default("auto")),
|
|
402
|
+
autoBreakpoints: (0, schema_js_1.optionalize)(zod_1.z.object({
|
|
403
|
+
tools: (0, schema_js_1.optionalize)(zod_1.z.boolean().default(true)),
|
|
404
|
+
system: (0, schema_js_1.optionalize)(zod_1.z.boolean().default(true)),
|
|
405
|
+
lastMessage: (0, schema_js_1.optionalize)(zod_1.z.boolean().default(false)),
|
|
406
|
+
})),
|
|
407
|
+
}),
|
|
349
408
|
};
|
|
350
|
-
const modelOptionsSchema = zod_1.z
|
|
409
|
+
const modelOptionsSchema = zod_1.z
|
|
410
|
+
.object(Object.fromEntries(Object.entries(modelOptionsSchemaProperties).map(([key, schema]) => [
|
|
351
411
|
key,
|
|
352
412
|
(0, schema_js_1.optionalize)(schema),
|
|
353
|
-
])))
|
|
354
|
-
|
|
413
|
+
])))
|
|
414
|
+
.passthrough();
|
|
415
|
+
const modelOptionsWithGetterSchema = zod_1.z
|
|
416
|
+
.object(Object.fromEntries(Object.entries(modelOptionsSchemaProperties).map(([key, schema]) => [
|
|
355
417
|
key,
|
|
356
418
|
(0, schema_js_1.optionalize)((0, agent_js_1.getterSchema)(schema)),
|
|
357
|
-
])))
|
|
419
|
+
])))
|
|
420
|
+
.passthrough();
|
|
358
421
|
const chatModelOptionsSchema = agent_js_1.agentOptionsSchema.extend({
|
|
359
422
|
model: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
360
423
|
modelOptions: (0, schema_js_1.optionalize)(modelOptionsWithGetterSchema),
|
|
@@ -379,6 +442,8 @@ exports.chatModelOutputUsageSchema = zod_1.z.object({
|
|
|
379
442
|
inputTokens: zod_1.z.number(),
|
|
380
443
|
outputTokens: zod_1.z.number(),
|
|
381
444
|
aigneHubCredits: (0, schema_js_1.optionalize)(zod_1.z.number()),
|
|
445
|
+
cacheCreationInputTokens: (0, schema_js_1.optionalize)(zod_1.z.number()),
|
|
446
|
+
cacheReadInputTokens: (0, schema_js_1.optionalize)(zod_1.z.number()),
|
|
382
447
|
creditPrefix: (0, schema_js_1.optionalize)(zod_1.z.union([zod_1.z.literal("$"), zod_1.z.literal("€"), zod_1.z.literal("¥")])),
|
|
383
448
|
});
|
|
384
449
|
const chatModelOutputSchema = zod_1.z.object({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ZodObject, type ZodType } from "zod";
|
|
1
|
+
import z, { type ZodObject, type ZodType } from "zod";
|
|
2
2
|
import { PromptBuilder } from "../prompt/prompt-builder.js";
|
|
3
3
|
import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from "./agent.js";
|
|
4
4
|
import { type ImageModelOutput } from "./image-model.js";
|
|
@@ -13,6 +13,22 @@ export declare const imageAgentOptionsSchema: ZodObject<{
|
|
|
13
13
|
}>;
|
|
14
14
|
export declare class ImageAgent<I extends Message = any, O extends ImageModelOutput = any> extends Agent<I, O> {
|
|
15
15
|
tag: string;
|
|
16
|
+
static schema({ filepath }: {
|
|
17
|
+
filepath: string;
|
|
18
|
+
}): z.ZodObject<{
|
|
19
|
+
instructions: z.ZodType<import("../loader/schema.js").Instructions, z.ZodTypeDef, import("../loader/schema.js").Instructions>;
|
|
20
|
+
inputFileKey: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
21
|
+
}, "strip", z.ZodTypeAny, {
|
|
22
|
+
instructions: import("../loader/schema.js").Instructions;
|
|
23
|
+
inputFileKey?: string | undefined;
|
|
24
|
+
}, {
|
|
25
|
+
instructions: import("../loader/schema.js").Instructions;
|
|
26
|
+
inputFileKey?: string | undefined;
|
|
27
|
+
}>;
|
|
28
|
+
static load<I extends Message = any, O extends Message = any>(options: {
|
|
29
|
+
filepath: string;
|
|
30
|
+
parsed: object;
|
|
31
|
+
}): Promise<Agent<I, O>>;
|
|
16
32
|
static from<I extends Message = any, O extends ImageModelOutput = any>(options: ImageAgentOptions<I, O>): ImageAgent<I, O>;
|
|
17
33
|
constructor(options: ImageAgentOptions<I, O>);
|
|
18
34
|
instructions: PromptBuilder;
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ImageAgent = exports.imageAgentOptionsSchema = void 0;
|
|
7
7
|
const zod_1 = __importDefault(require("zod"));
|
|
8
|
+
const schema_js_1 = require("../loader/schema.js");
|
|
8
9
|
const prompt_builder_js_1 = require("../prompt/prompt-builder.js");
|
|
9
10
|
const type_utils_js_1 = require("../utils/type-utils.js");
|
|
10
11
|
const agent_js_1 = require("./agent.js");
|
|
@@ -16,6 +17,21 @@ exports.imageAgentOptionsSchema = agent_js_1.agentOptionsSchema.extend({
|
|
|
16
17
|
});
|
|
17
18
|
class ImageAgent extends agent_js_1.Agent {
|
|
18
19
|
tag = "ImageAgent";
|
|
20
|
+
static schema({ filepath }) {
|
|
21
|
+
const instructionsSchema = (0, schema_js_1.getInstructionsSchema)({ filepath });
|
|
22
|
+
return (0, schema_js_1.camelizeSchema)(zod_1.default.object({
|
|
23
|
+
instructions: instructionsSchema,
|
|
24
|
+
inputFileKey: (0, schema_js_1.optionalize)(zod_1.default.string()),
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
static async load(options) {
|
|
28
|
+
const valid = await ImageAgent.schema({ filepath: options.filepath }).parseAsync(options.parsed);
|
|
29
|
+
return new ImageAgent({
|
|
30
|
+
...options.parsed,
|
|
31
|
+
...valid,
|
|
32
|
+
instructions: (0, schema_js_1.instructionsToPromptBuilder)(valid.instructions),
|
|
33
|
+
});
|
|
34
|
+
}
|
|
19
35
|
static from(options) {
|
|
20
36
|
return new ImageAgent(options);
|
|
21
37
|
}
|
|
@@ -107,8 +107,8 @@ export declare const imageModelInputSchema: z.ZodObject<{
|
|
|
107
107
|
filename?: string | undefined;
|
|
108
108
|
mimeType?: string | undefined;
|
|
109
109
|
})[] | undefined;
|
|
110
|
-
outputFileType?: "local" | "file" | "url" | undefined;
|
|
111
110
|
n?: number | undefined;
|
|
111
|
+
outputFileType?: "local" | "file" | "url" | undefined;
|
|
112
112
|
}, {
|
|
113
113
|
prompt: string;
|
|
114
114
|
modelOptions?: Record<string, unknown> | undefined;
|
|
@@ -128,8 +128,8 @@ export declare const imageModelInputSchema: z.ZodObject<{
|
|
|
128
128
|
filename?: string | undefined;
|
|
129
129
|
mimeType?: string | undefined;
|
|
130
130
|
})[] | undefined;
|
|
131
|
-
outputFileType?: "local" | "file" | "url" | undefined;
|
|
132
131
|
n?: number | undefined;
|
|
132
|
+
outputFileType?: "local" | "file" | "url" | undefined;
|
|
133
133
|
}>;
|
|
134
134
|
export interface ImageModelOutput extends Message {
|
|
135
135
|
images: FileUnionContent[];
|
|
@@ -196,16 +196,22 @@ export declare const imageModelOutputSchema: z.ZodObject<{
|
|
|
196
196
|
inputTokens: z.ZodNumber;
|
|
197
197
|
outputTokens: z.ZodNumber;
|
|
198
198
|
aigneHubCredits: ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
199
|
+
cacheCreationInputTokens: ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
200
|
+
cacheReadInputTokens: ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
199
201
|
creditPrefix: ZodType<"$" | "€" | "¥" | undefined, z.ZodTypeDef, "$" | "€" | "¥" | undefined>;
|
|
200
202
|
}, "strip", z.ZodTypeAny, {
|
|
201
203
|
inputTokens: number;
|
|
202
204
|
outputTokens: number;
|
|
203
205
|
aigneHubCredits?: number | undefined;
|
|
206
|
+
cacheCreationInputTokens?: number | undefined;
|
|
207
|
+
cacheReadInputTokens?: number | undefined;
|
|
204
208
|
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
205
209
|
}, {
|
|
206
210
|
inputTokens: number;
|
|
207
211
|
outputTokens: number;
|
|
208
212
|
aigneHubCredits?: number | undefined;
|
|
213
|
+
cacheCreationInputTokens?: number | undefined;
|
|
214
|
+
cacheReadInputTokens?: number | undefined;
|
|
209
215
|
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
210
216
|
}>>;
|
|
211
217
|
model: z.ZodOptional<z.ZodString>;
|
|
@@ -231,6 +237,8 @@ export declare const imageModelOutputSchema: z.ZodObject<{
|
|
|
231
237
|
inputTokens: number;
|
|
232
238
|
outputTokens: number;
|
|
233
239
|
aigneHubCredits?: number | undefined;
|
|
240
|
+
cacheCreationInputTokens?: number | undefined;
|
|
241
|
+
cacheReadInputTokens?: number | undefined;
|
|
234
242
|
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
235
243
|
} | undefined;
|
|
236
244
|
}, {
|
|
@@ -255,6 +263,8 @@ export declare const imageModelOutputSchema: z.ZodObject<{
|
|
|
255
263
|
inputTokens: number;
|
|
256
264
|
outputTokens: number;
|
|
257
265
|
aigneHubCredits?: number | undefined;
|
|
266
|
+
cacheCreationInputTokens?: number | undefined;
|
|
267
|
+
cacheReadInputTokens?: number | undefined;
|
|
258
268
|
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
259
269
|
} | undefined;
|
|
260
270
|
}>;
|
|
@@ -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);
|
|
@@ -58,6 +58,23 @@ export type SSEServerParameters = {
|
|
|
58
58
|
*/
|
|
59
59
|
export declare class MCPAgent extends Agent {
|
|
60
60
|
tag: string;
|
|
61
|
+
static schema(): z.ZodObject<{
|
|
62
|
+
url: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
63
|
+
command: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
64
|
+
args: ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
|
|
65
|
+
}, "strip", z.ZodTypeAny, {
|
|
66
|
+
url?: string | undefined;
|
|
67
|
+
command?: string | undefined;
|
|
68
|
+
args?: string[] | undefined;
|
|
69
|
+
}, {
|
|
70
|
+
url?: string | undefined;
|
|
71
|
+
command?: string | undefined;
|
|
72
|
+
args?: string[] | undefined;
|
|
73
|
+
}>;
|
|
74
|
+
static load<I extends Message = any, O extends Message = any>(options: {
|
|
75
|
+
filepath: string;
|
|
76
|
+
parsed: object;
|
|
77
|
+
}): Promise<Agent<I, O>>;
|
|
61
78
|
/**
|
|
62
79
|
* Create an MCPAgent from a connection to an SSE server.
|
|
63
80
|
*
|
|
@@ -41,6 +41,7 @@ const sse_js_1 = require("@modelcontextprotocol/sdk/client/sse.js");
|
|
|
41
41
|
const streamableHttp_js_1 = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
|
|
42
42
|
const uriTemplate_js_1 = require("@modelcontextprotocol/sdk/shared/uriTemplate.js");
|
|
43
43
|
const zod_1 = require("zod");
|
|
44
|
+
const schema_js_1 = require("../loader/schema.js");
|
|
44
45
|
const logger_js_1 = require("../utils/logger.js");
|
|
45
46
|
const mcp_utils_js_1 = require("../utils/mcp-utils.js");
|
|
46
47
|
const type_utils_js_1 = require("../utils/type-utils.js");
|
|
@@ -85,6 +86,23 @@ function getMCPServerString(options) {
|
|
|
85
86
|
*/
|
|
86
87
|
class MCPAgent extends agent_js_1.Agent {
|
|
87
88
|
tag = "MCPAgent";
|
|
89
|
+
static schema() {
|
|
90
|
+
return zod_1.z.object({
|
|
91
|
+
url: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
92
|
+
command: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
93
|
+
args: (0, schema_js_1.optionalize)(zod_1.z.array(zod_1.z.string())),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
static async load(options) {
|
|
97
|
+
const valid = await MCPAgent.schema().parseAsync(options.parsed);
|
|
98
|
+
if (!valid.url && !valid.command) {
|
|
99
|
+
throw new Error(`Missing url or command in mcp agent: ${options.filepath}`);
|
|
100
|
+
}
|
|
101
|
+
return MCPAgent.from({
|
|
102
|
+
...options.parsed,
|
|
103
|
+
...valid,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
88
106
|
static from(options) {
|
|
89
107
|
(0, type_utils_js_1.checkArguments)("MCPAgent.from", mcpAgentOptionsSchema, options);
|
|
90
108
|
if (isSSEServerParameters(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)();
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { AgentLoadOptions } from "../loader/index.js";
|
|
1
3
|
import { type PromiseOrValue } from "../utils/type-utils.js";
|
|
2
4
|
import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type Message } from "./agent.js";
|
|
3
5
|
/**
|
|
@@ -200,6 +202,59 @@ export interface TeamAgentOptions<I extends Message, O extends Message> extends
|
|
|
200
202
|
*/
|
|
201
203
|
export declare class TeamAgent<I extends Message, O extends Message> extends Agent<I, O> {
|
|
202
204
|
tag: string;
|
|
205
|
+
static schema({ filepath }: {
|
|
206
|
+
filepath: string;
|
|
207
|
+
}): z.ZodObject<{
|
|
208
|
+
mode: z.ZodType<ProcessMode | undefined, z.ZodTypeDef, ProcessMode | undefined>;
|
|
209
|
+
iterateOn: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
210
|
+
concurrency: z.ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
211
|
+
iterateWithPreviousOutput: z.ZodType<boolean | undefined, z.ZodTypeDef, boolean | undefined>;
|
|
212
|
+
includeAllStepsOutput: z.ZodType<boolean | undefined, z.ZodTypeDef, boolean | undefined>;
|
|
213
|
+
reflection: z.ZodType<{
|
|
214
|
+
reviewer: import("../loader/agent-yaml.js").NestAgentSchema;
|
|
215
|
+
isApproved: string;
|
|
216
|
+
maxIterations?: number | undefined;
|
|
217
|
+
returnLastOnMaxIterations?: boolean | undefined;
|
|
218
|
+
customErrorMessage?: string | undefined;
|
|
219
|
+
} | undefined, z.ZodTypeDef, {
|
|
220
|
+
reviewer: import("../loader/agent-yaml.js").NestAgentSchema;
|
|
221
|
+
isApproved: string;
|
|
222
|
+
maxIterations?: number | undefined;
|
|
223
|
+
returnLastOnMaxIterations?: boolean | undefined;
|
|
224
|
+
customErrorMessage?: string | undefined;
|
|
225
|
+
} | undefined>;
|
|
226
|
+
}, "strip", z.ZodTypeAny, {
|
|
227
|
+
mode?: ProcessMode | undefined;
|
|
228
|
+
reflection?: {
|
|
229
|
+
reviewer: import("../loader/agent-yaml.js").NestAgentSchema;
|
|
230
|
+
isApproved: string;
|
|
231
|
+
maxIterations?: number | undefined;
|
|
232
|
+
returnLastOnMaxIterations?: boolean | undefined;
|
|
233
|
+
customErrorMessage?: string | undefined;
|
|
234
|
+
} | undefined;
|
|
235
|
+
iterateOn?: string | undefined;
|
|
236
|
+
concurrency?: number | undefined;
|
|
237
|
+
iterateWithPreviousOutput?: boolean | undefined;
|
|
238
|
+
includeAllStepsOutput?: boolean | undefined;
|
|
239
|
+
}, {
|
|
240
|
+
mode?: ProcessMode | undefined;
|
|
241
|
+
reflection?: {
|
|
242
|
+
reviewer: import("../loader/agent-yaml.js").NestAgentSchema;
|
|
243
|
+
isApproved: string;
|
|
244
|
+
maxIterations?: number | undefined;
|
|
245
|
+
returnLastOnMaxIterations?: boolean | undefined;
|
|
246
|
+
customErrorMessage?: string | undefined;
|
|
247
|
+
} | undefined;
|
|
248
|
+
iterateOn?: string | undefined;
|
|
249
|
+
concurrency?: number | undefined;
|
|
250
|
+
iterateWithPreviousOutput?: boolean | undefined;
|
|
251
|
+
includeAllStepsOutput?: boolean | undefined;
|
|
252
|
+
}>;
|
|
253
|
+
static load<I extends Message = any, O extends Message = any>(options: {
|
|
254
|
+
filepath: string;
|
|
255
|
+
parsed: object;
|
|
256
|
+
options: AgentLoadOptions;
|
|
257
|
+
}): Promise<Agent<I, O>>;
|
|
203
258
|
/**
|
|
204
259
|
* Create a TeamAgent from the provided options.
|
|
205
260
|
*
|
|
@@ -39,6 +39,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.TeamAgent = exports.DEFAULT_REFLECTION_MAX_ITERATIONS = exports.ProcessMode = void 0;
|
|
40
40
|
const node_assert_1 = __importDefault(require("node:assert"));
|
|
41
41
|
const immer_1 = require("immer");
|
|
42
|
+
const zod_1 = require("zod");
|
|
43
|
+
const agent_yaml_js_1 = require("../loader/agent-yaml.js");
|
|
44
|
+
const schema_js_1 = require("../loader/schema.js");
|
|
42
45
|
const fastq = __importStar(require("../utils/queue.js"));
|
|
43
46
|
const stream_utils_js_1 = require("../utils/stream-utils.js");
|
|
44
47
|
const type_utils_js_1 = require("../utils/type-utils.js");
|
|
@@ -86,6 +89,34 @@ exports.DEFAULT_REFLECTION_MAX_ITERATIONS = 3;
|
|
|
86
89
|
*/
|
|
87
90
|
class TeamAgent extends agent_js_1.Agent {
|
|
88
91
|
tag = "TeamAgent";
|
|
92
|
+
static schema({ filepath }) {
|
|
93
|
+
const nestAgentSchema = (0, agent_yaml_js_1.getNestAgentSchema)({ filepath });
|
|
94
|
+
return zod_1.z.object({
|
|
95
|
+
mode: (0, schema_js_1.optionalize)(zod_1.z.nativeEnum(ProcessMode)),
|
|
96
|
+
iterateOn: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
97
|
+
concurrency: (0, schema_js_1.optionalize)(zod_1.z.number().int().min(1)),
|
|
98
|
+
iterateWithPreviousOutput: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
|
|
99
|
+
includeAllStepsOutput: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
|
|
100
|
+
reflection: (0, schema_js_1.camelizeSchema)((0, schema_js_1.optionalize)(zod_1.z.object({
|
|
101
|
+
reviewer: nestAgentSchema,
|
|
102
|
+
isApproved: zod_1.z.string(),
|
|
103
|
+
maxIterations: (0, schema_js_1.optionalize)(zod_1.z.number().int().min(1)),
|
|
104
|
+
returnLastOnMaxIterations: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
|
|
105
|
+
customErrorMessage: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
106
|
+
}))),
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
static async load(options) {
|
|
110
|
+
const valid = await TeamAgent.schema({ filepath: options.filepath }).parseAsync(options.parsed);
|
|
111
|
+
return TeamAgent.from({
|
|
112
|
+
...options.parsed,
|
|
113
|
+
...valid,
|
|
114
|
+
reflection: valid.reflection && {
|
|
115
|
+
...valid.reflection,
|
|
116
|
+
reviewer: await options.options.loadNestAgent(options.filepath, valid.reflection.reviewer, options.options),
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
}
|
|
89
120
|
/**
|
|
90
121
|
* Create a TeamAgent from the provided options.
|
|
91
122
|
*
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
1
2
|
import { Agent, type AgentOptions, type Message } from "./agent.js";
|
|
2
3
|
/**
|
|
3
4
|
* Configuration options for TransformAgent
|
|
@@ -47,6 +48,17 @@ export interface TransformAgentOptions<I extends Message, O extends Message> ext
|
|
|
47
48
|
*/
|
|
48
49
|
export declare class TransformAgent<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
|
|
49
50
|
static type: string;
|
|
51
|
+
static schema(): z.ZodObject<{
|
|
52
|
+
jsonata: z.ZodString;
|
|
53
|
+
}, "strip", z.ZodTypeAny, {
|
|
54
|
+
jsonata: string;
|
|
55
|
+
}, {
|
|
56
|
+
jsonata: string;
|
|
57
|
+
}>;
|
|
58
|
+
static load<I extends Message = any, O extends Message = any>(options: {
|
|
59
|
+
filepath: string;
|
|
60
|
+
parsed: object;
|
|
61
|
+
}): Promise<Agent<I, O>>;
|
|
50
62
|
/**
|
|
51
63
|
* Factory method to create a new TransformAgent instance
|
|
52
64
|
*
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.TransformAgent = void 0;
|
|
7
7
|
const jsonata_1 = __importDefault(require("jsonata"));
|
|
8
|
+
const zod_1 = require("zod");
|
|
8
9
|
const agent_js_1 = require("./agent.js");
|
|
9
10
|
/**
|
|
10
11
|
* TransformAgent - A specialized agent for data transformation using JSONata expressions
|
|
@@ -23,6 +24,18 @@ const agent_js_1 = require("./agent.js");
|
|
|
23
24
|
*/
|
|
24
25
|
class TransformAgent extends agent_js_1.Agent {
|
|
25
26
|
static type = "TransformAgent";
|
|
27
|
+
static schema() {
|
|
28
|
+
return zod_1.z.object({
|
|
29
|
+
jsonata: zod_1.z.string(),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
static async load(options) {
|
|
33
|
+
const parsed = await TransformAgent.schema().parseAsync(options.parsed);
|
|
34
|
+
return TransformAgent.from({
|
|
35
|
+
...options.parsed,
|
|
36
|
+
...parsed,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
26
39
|
/**
|
|
27
40
|
* Factory method to create a new TransformAgent instance
|
|
28
41
|
*
|
|
@@ -203,16 +203,22 @@ export declare const videoModelOutputSchema: z.ZodObject<{
|
|
|
203
203
|
inputTokens: z.ZodNumber;
|
|
204
204
|
outputTokens: z.ZodNumber;
|
|
205
205
|
aigneHubCredits: ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
206
|
+
cacheCreationInputTokens: ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
207
|
+
cacheReadInputTokens: ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
206
208
|
creditPrefix: ZodType<"$" | "€" | "¥" | undefined, z.ZodTypeDef, "$" | "€" | "¥" | undefined>;
|
|
207
209
|
}, "strip", z.ZodTypeAny, {
|
|
208
210
|
inputTokens: number;
|
|
209
211
|
outputTokens: number;
|
|
210
212
|
aigneHubCredits?: number | undefined;
|
|
213
|
+
cacheCreationInputTokens?: number | undefined;
|
|
214
|
+
cacheReadInputTokens?: number | undefined;
|
|
211
215
|
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
212
216
|
}, {
|
|
213
217
|
inputTokens: number;
|
|
214
218
|
outputTokens: number;
|
|
215
219
|
aigneHubCredits?: number | undefined;
|
|
220
|
+
cacheCreationInputTokens?: number | undefined;
|
|
221
|
+
cacheReadInputTokens?: number | undefined;
|
|
216
222
|
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
217
223
|
}>>;
|
|
218
224
|
model: z.ZodOptional<z.ZodString>;
|
|
@@ -239,6 +245,8 @@ export declare const videoModelOutputSchema: z.ZodObject<{
|
|
|
239
245
|
inputTokens: number;
|
|
240
246
|
outputTokens: number;
|
|
241
247
|
aigneHubCredits?: number | undefined;
|
|
248
|
+
cacheCreationInputTokens?: number | undefined;
|
|
249
|
+
cacheReadInputTokens?: number | undefined;
|
|
242
250
|
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
243
251
|
} | undefined;
|
|
244
252
|
seconds?: number | undefined;
|
|
@@ -264,6 +272,8 @@ export declare const videoModelOutputSchema: z.ZodObject<{
|
|
|
264
272
|
inputTokens: number;
|
|
265
273
|
outputTokens: number;
|
|
266
274
|
aigneHubCredits?: number | undefined;
|
|
275
|
+
cacheCreationInputTokens?: number | undefined;
|
|
276
|
+
cacheReadInputTokens?: number | undefined;
|
|
267
277
|
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
268
278
|
} | undefined;
|
|
269
279
|
seconds?: number | undefined;
|
|
@@ -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);
|
package/lib/cjs/aigne/context.js
CHANGED
|
@@ -347,11 +347,9 @@ class AIGNEContextShared {
|
|
|
347
347
|
}
|
|
348
348
|
}
|
|
349
349
|
const stream = await activeAgent.invoke(input, {
|
|
350
|
-
|
|
350
|
+
...(0, type_utils_js_1.pick)(options, "hooks", "model", "imageModel", "caller"),
|
|
351
351
|
context,
|
|
352
352
|
streaming: true,
|
|
353
|
-
model: options.model,
|
|
354
|
-
imageModel: options.imageModel,
|
|
355
353
|
});
|
|
356
354
|
for await (const value of stream) {
|
|
357
355
|
if ((0, agent_js_1.isAgentResponseDelta)(value)) {
|
package/lib/cjs/aigne/usage.d.ts
CHANGED
|
@@ -8,6 +8,10 @@ export interface ContextUsage {
|
|
|
8
8
|
creditPrefix?: "$" | "€" | "¥";
|
|
9
9
|
agentCalls: number;
|
|
10
10
|
duration: number;
|
|
11
|
+
/** Number of tokens written to cache (first time caching) */
|
|
12
|
+
cacheCreationInputTokens: number;
|
|
13
|
+
/** Number of tokens read from cache (cache hit) */
|
|
14
|
+
cacheReadInputTokens: number;
|
|
11
15
|
}
|
|
12
16
|
/**
|
|
13
17
|
* @hidden
|
package/lib/cjs/aigne/usage.js
CHANGED
|
@@ -12,6 +12,8 @@ function newEmptyContextUsage() {
|
|
|
12
12
|
aigneHubCredits: 0,
|
|
13
13
|
agentCalls: 0,
|
|
14
14
|
duration: 0,
|
|
15
|
+
cacheCreationInputTokens: 0,
|
|
16
|
+
cacheReadInputTokens: 0,
|
|
15
17
|
};
|
|
16
18
|
}
|
|
17
19
|
function mergeContextUsage(usage, additional) {
|
|
@@ -25,4 +27,8 @@ function mergeContextUsage(usage, additional) {
|
|
|
25
27
|
usage.agentCalls += additional.agentCalls;
|
|
26
28
|
if (additional.duration)
|
|
27
29
|
usage.duration += additional.duration;
|
|
30
|
+
if (additional.cacheCreationInputTokens)
|
|
31
|
+
usage.cacheCreationInputTokens += additional.cacheCreationInputTokens;
|
|
32
|
+
if (additional.cacheReadInputTokens)
|
|
33
|
+
usage.cacheReadInputTokens += additional.cacheReadInputTokens;
|
|
28
34
|
}
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export * from "./agents/user-agent.js";
|
|
|
13
13
|
export * from "./agents/video-model.js";
|
|
14
14
|
export * from "./aigne/index.js";
|
|
15
15
|
export * from "./memory/index.js";
|
|
16
|
+
export * from "./prompt/agent-session.js";
|
|
16
17
|
export * from "./prompt/prompt-builder.js";
|
|
17
18
|
export * from "./prompt/template.js";
|
|
18
19
|
export * from "./utils/json-utils.js";
|
package/lib/cjs/index.js
CHANGED
|
@@ -29,6 +29,7 @@ __exportStar(require("./agents/user-agent.js"), exports);
|
|
|
29
29
|
__exportStar(require("./agents/video-model.js"), exports);
|
|
30
30
|
__exportStar(require("./aigne/index.js"), exports);
|
|
31
31
|
__exportStar(require("./memory/index.js"), exports);
|
|
32
|
+
__exportStar(require("./prompt/agent-session.js"), exports);
|
|
32
33
|
__exportStar(require("./prompt/prompt-builder.js"), exports);
|
|
33
34
|
__exportStar(require("./prompt/template.js"), exports);
|
|
34
35
|
__exportStar(require("./utils/json-utils.js"), exports);
|