@aigne/core 1.72.0-beta.2 → 1.72.0-beta.3
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 +14 -0
- package/lib/cjs/agents/chat-model.d.ts +153 -0
- package/lib/cjs/agents/chat-model.js +35 -1
- package/lib/cjs/agents/image-model.d.ts +10 -0
- package/lib/cjs/agents/video-model.d.ts +10 -0
- package/lib/cjs/aigne/usage.d.ts +4 -0
- package/lib/cjs/aigne/usage.js +6 -0
- package/lib/cjs/loader/agent-yaml.d.ts +4 -0
- package/lib/cjs/loader/agent-yaml.js +15 -5
- package/lib/cjs/prompt/template.d.ts +82 -7
- package/lib/cjs/prompt/template.js +46 -17
- package/lib/dts/agents/chat-model.d.ts +153 -0
- package/lib/dts/agents/image-model.d.ts +10 -0
- package/lib/dts/agents/video-model.d.ts +10 -0
- package/lib/dts/aigne/usage.d.ts +4 -0
- package/lib/dts/loader/agent-yaml.d.ts +4 -0
- package/lib/dts/prompt/template.d.ts +82 -7
- package/lib/esm/agents/chat-model.d.ts +153 -0
- package/lib/esm/agents/chat-model.js +34 -0
- package/lib/esm/agents/image-model.d.ts +10 -0
- package/lib/esm/agents/video-model.d.ts +10 -0
- package/lib/esm/aigne/usage.d.ts +4 -0
- package/lib/esm/aigne/usage.js +6 -0
- package/lib/esm/loader/agent-yaml.d.ts +4 -0
- package/lib/esm/loader/agent-yaml.js +15 -5
- package/lib/esm/prompt/template.d.ts +82 -7
- package/lib/esm/prompt/template.js +46 -17
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.72.0-beta.3](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.72.0-beta.2...core-v1.72.0-beta.3) (2025-12-19)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add prompt caching for OpenAI/Gemini/Anthropic and cache token display ([#838](https://github.com/AIGNE-io/aigne-framework/issues/838)) ([46c628f](https://github.com/AIGNE-io/aigne-framework/commit/46c628f180572ea1b955d1a9888aad6145204842))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @aigne/observability-api bumped to 0.11.14-beta.1
|
|
16
|
+
|
|
3
17
|
## [1.72.0-beta.2](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.72.0-beta.1...core-v1.72.0-beta.2) (2025-12-19)
|
|
4
18
|
|
|
5
19
|
|
|
@@ -203,6 +203,13 @@ export interface ChatModelInputMessage {
|
|
|
203
203
|
* Name of the message sender (for multi-agent scenarios)
|
|
204
204
|
*/
|
|
205
205
|
name?: string;
|
|
206
|
+
/**
|
|
207
|
+
* Cache control marker for the entire message (only supported by Claude)
|
|
208
|
+
*
|
|
209
|
+
* This is syntactic sugar that applies cacheControl to the last content block
|
|
210
|
+
* of the message. See {@link CacheControl} for details.
|
|
211
|
+
*/
|
|
212
|
+
cacheControl?: CacheControl;
|
|
206
213
|
}
|
|
207
214
|
/**
|
|
208
215
|
* Type of input message content
|
|
@@ -218,27 +225,64 @@ export type ChatModelInputMessageContent = string | UnionContent[];
|
|
|
218
225
|
export type TextContent = {
|
|
219
226
|
type: "text";
|
|
220
227
|
text: string;
|
|
228
|
+
/**
|
|
229
|
+
* Cache control marker (only supported by Claude)
|
|
230
|
+
*
|
|
231
|
+
* When set, this content block will be marked as a cache breakpoint.
|
|
232
|
+
* See {@link CacheControl} for details.
|
|
233
|
+
*/
|
|
234
|
+
cacheControl?: CacheControl;
|
|
221
235
|
};
|
|
222
236
|
export declare const textContentSchema: z.ZodObject<{
|
|
223
237
|
type: z.ZodLiteral<"text">;
|
|
224
238
|
text: z.ZodString;
|
|
239
|
+
cacheControl: ZodType<{
|
|
240
|
+
type: "ephemeral";
|
|
241
|
+
ttl?: "5m" | "1h" | undefined;
|
|
242
|
+
} | undefined, z.ZodTypeDef, {
|
|
243
|
+
type: "ephemeral";
|
|
244
|
+
ttl?: "5m" | "1h" | undefined;
|
|
245
|
+
} | undefined>;
|
|
225
246
|
}, "strip", z.ZodTypeAny, {
|
|
226
247
|
type: "text";
|
|
227
248
|
text: string;
|
|
249
|
+
cacheControl?: {
|
|
250
|
+
type: "ephemeral";
|
|
251
|
+
ttl?: "5m" | "1h" | undefined;
|
|
252
|
+
} | undefined;
|
|
228
253
|
}, {
|
|
229
254
|
type: "text";
|
|
230
255
|
text: string;
|
|
256
|
+
cacheControl?: {
|
|
257
|
+
type: "ephemeral";
|
|
258
|
+
ttl?: "5m" | "1h" | undefined;
|
|
259
|
+
} | undefined;
|
|
231
260
|
}>;
|
|
232
261
|
export type UnionContent = TextContent | FileUnionContent;
|
|
233
262
|
export declare const unionContentSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
234
263
|
type: z.ZodLiteral<"text">;
|
|
235
264
|
text: z.ZodString;
|
|
265
|
+
cacheControl: ZodType<{
|
|
266
|
+
type: "ephemeral";
|
|
267
|
+
ttl?: "5m" | "1h" | undefined;
|
|
268
|
+
} | undefined, z.ZodTypeDef, {
|
|
269
|
+
type: "ephemeral";
|
|
270
|
+
ttl?: "5m" | "1h" | undefined;
|
|
271
|
+
} | undefined>;
|
|
236
272
|
}, "strip", z.ZodTypeAny, {
|
|
237
273
|
type: "text";
|
|
238
274
|
text: string;
|
|
275
|
+
cacheControl?: {
|
|
276
|
+
type: "ephemeral";
|
|
277
|
+
ttl?: "5m" | "1h" | undefined;
|
|
278
|
+
} | undefined;
|
|
239
279
|
}, {
|
|
240
280
|
type: "text";
|
|
241
281
|
text: string;
|
|
282
|
+
cacheControl?: {
|
|
283
|
+
type: "ephemeral";
|
|
284
|
+
ttl?: "5m" | "1h" | undefined;
|
|
285
|
+
} | undefined;
|
|
242
286
|
}>, z.ZodObject<{
|
|
243
287
|
filename: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
244
288
|
mimeType: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
@@ -340,6 +384,14 @@ export interface ChatModelInputTool {
|
|
|
340
384
|
* For example, Gemini's thought_signature
|
|
341
385
|
*/
|
|
342
386
|
metadata?: Record<string, any>;
|
|
387
|
+
/**
|
|
388
|
+
* Cache control marker (only supported by Claude)
|
|
389
|
+
*
|
|
390
|
+
* When set, this tool definition will be marked as a cache breakpoint.
|
|
391
|
+
* Typically applied to the last tool in the tools array.
|
|
392
|
+
* See {@link CacheControl} for details.
|
|
393
|
+
*/
|
|
394
|
+
cacheControl?: CacheControl;
|
|
343
395
|
}
|
|
344
396
|
/**
|
|
345
397
|
* Tool selection strategy
|
|
@@ -362,6 +414,82 @@ export type ChatModelInputToolChoice = "auto" | "none" | "required" | {
|
|
|
362
414
|
};
|
|
363
415
|
};
|
|
364
416
|
export type Modality = "text" | "image" | "audio";
|
|
417
|
+
/**
|
|
418
|
+
* Cache control marker for prompt caching
|
|
419
|
+
*
|
|
420
|
+
* Used to mark content blocks, messages, or tools for caching.
|
|
421
|
+
* Currently only supported by Anthropic (Claude) models.
|
|
422
|
+
*/
|
|
423
|
+
export interface CacheControl {
|
|
424
|
+
/**
|
|
425
|
+
* Cache type (currently only "ephemeral" is supported)
|
|
426
|
+
*/
|
|
427
|
+
type: "ephemeral";
|
|
428
|
+
/**
|
|
429
|
+
* Cache TTL (Time To Live)
|
|
430
|
+
* - "5m": 5 minutes (default)
|
|
431
|
+
* - "1h": 1 hour
|
|
432
|
+
*/
|
|
433
|
+
ttl?: "5m" | "1h";
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Cache configuration options
|
|
437
|
+
*
|
|
438
|
+
* Controls how prompt caching is used for supported providers.
|
|
439
|
+
* Prompt caching can significantly reduce costs and latency by reusing
|
|
440
|
+
* previously processed prompts (system messages, tool definitions, etc.).
|
|
441
|
+
*/
|
|
442
|
+
export interface CacheConfig {
|
|
443
|
+
/**
|
|
444
|
+
* Whether to enable prompt caching
|
|
445
|
+
*
|
|
446
|
+
* - OpenAI: Ignored (always enabled automatically)
|
|
447
|
+
* - Gemini: Controls explicit caching
|
|
448
|
+
* - Claude: Controls whether to add cache_control markers
|
|
449
|
+
*
|
|
450
|
+
* @default true
|
|
451
|
+
*/
|
|
452
|
+
enabled?: boolean;
|
|
453
|
+
/**
|
|
454
|
+
* Cache TTL (Time To Live)
|
|
455
|
+
*
|
|
456
|
+
* - OpenAI: Ignored (automatic)
|
|
457
|
+
* - Gemini: Supports custom seconds
|
|
458
|
+
* - Claude: Only supports "5m" or "1h"
|
|
459
|
+
*
|
|
460
|
+
* @default "5m"
|
|
461
|
+
*/
|
|
462
|
+
ttl?: "5m" | "1h" | number;
|
|
463
|
+
/**
|
|
464
|
+
* Caching strategy
|
|
465
|
+
*
|
|
466
|
+
* - "auto": Automatically add cache breakpoints at optimal locations
|
|
467
|
+
* - "manual": Require explicit cacheControl markers on messages/tools
|
|
468
|
+
*
|
|
469
|
+
* @default "auto"
|
|
470
|
+
*/
|
|
471
|
+
strategy?: "auto" | "manual";
|
|
472
|
+
/**
|
|
473
|
+
* Auto cache breakpoint locations (only effective when strategy="auto")
|
|
474
|
+
*
|
|
475
|
+
* @default { tools: true, system: true, lastMessage: false }
|
|
476
|
+
*/
|
|
477
|
+
autoBreakpoints?: {
|
|
478
|
+
/** Cache tool definitions */
|
|
479
|
+
tools?: boolean;
|
|
480
|
+
/** Cache system messages */
|
|
481
|
+
system?: boolean;
|
|
482
|
+
/** Cache last message in conversation history */
|
|
483
|
+
lastMessage?: boolean;
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Default cache configuration
|
|
488
|
+
*
|
|
489
|
+
* Enables automatic caching for system messages and tool definitions,
|
|
490
|
+
* which typically provides the best cost/performance tradeoff.
|
|
491
|
+
*/
|
|
492
|
+
export declare const DEFAULT_CACHE_CONFIG: CacheConfig;
|
|
365
493
|
/**
|
|
366
494
|
* Model-specific configuration options
|
|
367
495
|
*
|
|
@@ -395,6 +523,15 @@ export interface ChatModelInputOptions extends Record<string, unknown> {
|
|
|
395
523
|
modalities?: Modality[];
|
|
396
524
|
preferInputFileType?: "file" | "url";
|
|
397
525
|
reasoningEffort?: number | "minimal" | "low" | "medium" | "high";
|
|
526
|
+
/**
|
|
527
|
+
* Cache configuration for prompt caching
|
|
528
|
+
*
|
|
529
|
+
* Enables caching of system messages, tool definitions, and conversation history
|
|
530
|
+
* to reduce costs and latency. See {@link CacheConfig} for details.
|
|
531
|
+
*
|
|
532
|
+
* @default DEFAULT_CACHE_CONFIG (enabled with auto strategy)
|
|
533
|
+
*/
|
|
534
|
+
cacheConfig?: CacheConfig;
|
|
398
535
|
}
|
|
399
536
|
export type ChatModelInputOptionsWithGetter = GetterSchema<ChatModelInputOptions>;
|
|
400
537
|
/**
|
|
@@ -492,6 +629,16 @@ export interface ChatModelOutputUsage {
|
|
|
492
629
|
* AIGNE Hub credit usage
|
|
493
630
|
*/
|
|
494
631
|
aigneHubCredits?: number;
|
|
632
|
+
/**
|
|
633
|
+
* Number of tokens written to cache (first time caching)
|
|
634
|
+
* Only applicable for providers that support explicit cache creation (e.g., Anthropic)
|
|
635
|
+
*/
|
|
636
|
+
cacheCreationInputTokens?: number;
|
|
637
|
+
/**
|
|
638
|
+
* Number of tokens read from cache (cache hit)
|
|
639
|
+
* Supported by OpenAI, Anthropic, and Gemini
|
|
640
|
+
*/
|
|
641
|
+
cacheReadInputTokens?: number;
|
|
495
642
|
/**
|
|
496
643
|
* Credit prefix
|
|
497
644
|
*/
|
|
@@ -501,15 +648,21 @@ export declare const chatModelOutputUsageSchema: z.ZodObject<{
|
|
|
501
648
|
inputTokens: z.ZodNumber;
|
|
502
649
|
outputTokens: z.ZodNumber;
|
|
503
650
|
aigneHubCredits: ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
651
|
+
cacheCreationInputTokens: ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
652
|
+
cacheReadInputTokens: ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
504
653
|
creditPrefix: ZodType<"$" | "€" | "¥" | undefined, z.ZodTypeDef, "$" | "€" | "¥" | undefined>;
|
|
505
654
|
}, "strip", z.ZodTypeAny, {
|
|
506
655
|
inputTokens: number;
|
|
507
656
|
outputTokens: number;
|
|
508
657
|
aigneHubCredits?: number | undefined;
|
|
658
|
+
cacheCreationInputTokens?: number | undefined;
|
|
659
|
+
cacheReadInputTokens?: number | undefined;
|
|
509
660
|
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
510
661
|
}, {
|
|
511
662
|
inputTokens: number;
|
|
512
663
|
outputTokens: number;
|
|
513
664
|
aigneHubCredits?: number | undefined;
|
|
665
|
+
cacheCreationInputTokens?: number | undefined;
|
|
666
|
+
cacheReadInputTokens?: number | undefined;
|
|
514
667
|
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
515
668
|
}>;
|
|
@@ -33,7 +33,7 @@ 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");
|
|
@@ -225,6 +225,10 @@ class ChatModel extends model_js_1.Model {
|
|
|
225
225
|
options.context.usage.inputTokens += usage.inputTokens;
|
|
226
226
|
if (usage.aigneHubCredits)
|
|
227
227
|
options.context.usage.aigneHubCredits += usage.aigneHubCredits;
|
|
228
|
+
if (usage.cacheCreationInputTokens)
|
|
229
|
+
options.context.usage.cacheCreationInputTokens += usage.cacheCreationInputTokens;
|
|
230
|
+
if (usage.cacheReadInputTokens)
|
|
231
|
+
options.context.usage.cacheReadInputTokens += usage.cacheReadInputTokens;
|
|
228
232
|
if (usage.creditPrefix)
|
|
229
233
|
options.context.usage.creditPrefix = usage.creditPrefix;
|
|
230
234
|
}
|
|
@@ -282,6 +286,10 @@ exports.roleSchema = zod_1.z.union([
|
|
|
282
286
|
exports.textContentSchema = zod_1.z.object({
|
|
283
287
|
type: zod_1.z.literal("text"),
|
|
284
288
|
text: zod_1.z.string(),
|
|
289
|
+
cacheControl: (0, schema_js_1.optionalize)(zod_1.z.object({
|
|
290
|
+
type: zod_1.z.literal("ephemeral"),
|
|
291
|
+
ttl: (0, schema_js_1.optionalize)(zod_1.z.union([zod_1.z.literal("5m"), zod_1.z.literal("1h")])),
|
|
292
|
+
})),
|
|
285
293
|
});
|
|
286
294
|
exports.unionContentSchema = zod_1.z.discriminatedUnion("type", [
|
|
287
295
|
exports.textContentSchema,
|
|
@@ -303,6 +311,10 @@ const chatModelInputMessageSchema = zod_1.z.object({
|
|
|
303
311
|
}))),
|
|
304
312
|
toolCallId: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
305
313
|
name: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
314
|
+
cacheControl: (0, schema_js_1.optionalize)(zod_1.z.object({
|
|
315
|
+
type: zod_1.z.literal("ephemeral"),
|
|
316
|
+
ttl: (0, schema_js_1.optionalize)(zod_1.z.union([zod_1.z.literal("5m"), zod_1.z.literal("1h")])),
|
|
317
|
+
})),
|
|
306
318
|
});
|
|
307
319
|
const chatModelInputResponseFormatSchema = zod_1.z.discriminatedUnion("type", [
|
|
308
320
|
zod_1.z.object({ type: zod_1.z.literal("text") }),
|
|
@@ -324,6 +336,10 @@ const chatModelInputToolSchema = zod_1.z.object({
|
|
|
324
336
|
parameters: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()),
|
|
325
337
|
}),
|
|
326
338
|
metadata: (0, schema_js_1.optionalize)(zod_1.z.record(zod_1.z.string(), zod_1.z.unknown())),
|
|
339
|
+
cacheControl: (0, schema_js_1.optionalize)(zod_1.z.object({
|
|
340
|
+
type: zod_1.z.literal("ephemeral"),
|
|
341
|
+
ttl: (0, schema_js_1.optionalize)(zod_1.z.union([zod_1.z.literal("5m"), zod_1.z.literal("1h")])),
|
|
342
|
+
})),
|
|
327
343
|
});
|
|
328
344
|
const chatModelInputToolChoiceSchema = zod_1.z.union([
|
|
329
345
|
zod_1.z.literal("auto"),
|
|
@@ -331,6 +347,22 @@ const chatModelInputToolChoiceSchema = zod_1.z.union([
|
|
|
331
347
|
zod_1.z.literal("required"),
|
|
332
348
|
chatModelInputToolSchema,
|
|
333
349
|
]);
|
|
350
|
+
/**
|
|
351
|
+
* Default cache configuration
|
|
352
|
+
*
|
|
353
|
+
* Enables automatic caching for system messages and tool definitions,
|
|
354
|
+
* which typically provides the best cost/performance tradeoff.
|
|
355
|
+
*/
|
|
356
|
+
exports.DEFAULT_CACHE_CONFIG = {
|
|
357
|
+
enabled: true,
|
|
358
|
+
ttl: "5m",
|
|
359
|
+
strategy: "auto",
|
|
360
|
+
autoBreakpoints: {
|
|
361
|
+
tools: true,
|
|
362
|
+
system: true,
|
|
363
|
+
lastMessage: false,
|
|
364
|
+
},
|
|
365
|
+
};
|
|
334
366
|
const modelOptionsSchemaProperties = {
|
|
335
367
|
model: zod_1.z.string(),
|
|
336
368
|
temperature: zod_1.z.number(),
|
|
@@ -379,6 +411,8 @@ exports.chatModelOutputUsageSchema = zod_1.z.object({
|
|
|
379
411
|
inputTokens: zod_1.z.number(),
|
|
380
412
|
outputTokens: zod_1.z.number(),
|
|
381
413
|
aigneHubCredits: (0, schema_js_1.optionalize)(zod_1.z.number()),
|
|
414
|
+
cacheCreationInputTokens: (0, schema_js_1.optionalize)(zod_1.z.number()),
|
|
415
|
+
cacheReadInputTokens: (0, schema_js_1.optionalize)(zod_1.z.number()),
|
|
382
416
|
creditPrefix: (0, schema_js_1.optionalize)(zod_1.z.union([zod_1.z.literal("$"), zod_1.z.literal("€"), zod_1.z.literal("¥")])),
|
|
383
417
|
});
|
|
384
418
|
const chatModelOutputSchema = zod_1.z.object({
|
|
@@ -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
|
}>;
|
|
@@ -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;
|
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
|
}
|
|
@@ -30,27 +30,37 @@ async function loadAgentFromYamlFile(path, options) {
|
|
|
30
30
|
}, options), (error) => new Error(`Failed to validate agent definition from ${path}: ${error.message}`));
|
|
31
31
|
return agent;
|
|
32
32
|
}
|
|
33
|
-
const instructionItemSchema = zod_1.z.union([
|
|
33
|
+
const instructionItemSchema = (0, schema_js_1.camelizeSchema)(zod_1.z.union([
|
|
34
34
|
zod_1.z.object({
|
|
35
35
|
role: chat_model_js_1.roleSchema.default("system"),
|
|
36
36
|
url: zod_1.z.string(),
|
|
37
|
+
cacheControl: (0, schema_js_1.optionalize)(zod_1.z.object({
|
|
38
|
+
type: zod_1.z.literal("ephemeral"),
|
|
39
|
+
ttl: (0, schema_js_1.optionalize)(zod_1.z.union([zod_1.z.literal("5m"), zod_1.z.literal("1h")])),
|
|
40
|
+
})),
|
|
37
41
|
}),
|
|
38
42
|
zod_1.z.object({
|
|
39
43
|
role: chat_model_js_1.roleSchema.default("system"),
|
|
40
44
|
content: zod_1.z.string(),
|
|
45
|
+
cacheControl: (0, schema_js_1.optionalize)(zod_1.z.object({
|
|
46
|
+
type: zod_1.z.literal("ephemeral"),
|
|
47
|
+
ttl: (0, schema_js_1.optionalize)(zod_1.z.union([zod_1.z.literal("5m"), zod_1.z.literal("1h")])),
|
|
48
|
+
})),
|
|
41
49
|
}),
|
|
42
|
-
]);
|
|
43
|
-
const parseInstructionItem = ({ filepath }) => async ({ role, ...v }) => {
|
|
50
|
+
]));
|
|
51
|
+
const parseInstructionItem = ({ filepath }) => async ({ role, cacheControl, ...v }) => {
|
|
44
52
|
if (role === "tool")
|
|
45
53
|
throw new Error(`'tool' role is not allowed in instruction item in agent file ${filepath}`);
|
|
46
54
|
if ("content" in v && typeof v.content === "string") {
|
|
47
|
-
return { role, content: v.content, path: filepath };
|
|
55
|
+
return { role, content: v.content, path: filepath, cacheControl };
|
|
48
56
|
}
|
|
49
57
|
if ("url" in v && typeof v.url === "string") {
|
|
50
58
|
const url = index_js_1.nodejs.path.isAbsolute(v.url)
|
|
51
59
|
? v.url
|
|
52
60
|
: index_js_1.nodejs.path.join(index_js_1.nodejs.path.dirname(filepath), v.url);
|
|
53
|
-
return index_js_1.nodejs.fs
|
|
61
|
+
return index_js_1.nodejs.fs
|
|
62
|
+
.readFile(url, "utf8")
|
|
63
|
+
.then((content) => ({ role, content, path: url, cacheControl }));
|
|
54
64
|
}
|
|
55
65
|
throw new Error(`Invalid instruction item in agent file ${filepath}. Expected 'content' or 'url' property`);
|
|
56
66
|
};
|