@aigne/core 1.72.0-beta.1 → 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.
Files changed (79) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/lib/cjs/agents/chat-model.d.ts +160 -0
  3. package/lib/cjs/agents/chat-model.js +38 -1
  4. package/lib/cjs/agents/image-model.d.ts +15 -0
  5. package/lib/cjs/agents/image-model.js +2 -0
  6. package/lib/cjs/agents/video-model.d.ts +15 -0
  7. package/lib/cjs/agents/video-model.js +2 -0
  8. package/lib/cjs/aigne/usage.d.ts +5 -0
  9. package/lib/cjs/aigne/usage.js +6 -0
  10. package/lib/cjs/loader/agent-yaml.d.ts +4 -0
  11. package/lib/cjs/loader/agent-yaml.js +15 -5
  12. package/lib/cjs/prompt/context/afs/index.js +1 -2
  13. package/lib/cjs/prompt/skills/afs/base.d.ts +4 -0
  14. package/lib/cjs/prompt/skills/afs/base.js +8 -0
  15. package/lib/cjs/prompt/skills/afs/delete.d.ts +3 -2
  16. package/lib/cjs/prompt/skills/afs/delete.js +2 -2
  17. package/lib/cjs/prompt/skills/afs/edit.d.ts +3 -2
  18. package/lib/cjs/prompt/skills/afs/edit.js +2 -2
  19. package/lib/cjs/prompt/skills/afs/exec.d.ts +3 -2
  20. package/lib/cjs/prompt/skills/afs/exec.js +7 -4
  21. package/lib/cjs/prompt/skills/afs/list.d.ts +3 -2
  22. package/lib/cjs/prompt/skills/afs/list.js +6 -13
  23. package/lib/cjs/prompt/skills/afs/read.d.ts +3 -2
  24. package/lib/cjs/prompt/skills/afs/read.js +2 -2
  25. package/lib/cjs/prompt/skills/afs/rename.d.ts +3 -2
  26. package/lib/cjs/prompt/skills/afs/rename.js +2 -2
  27. package/lib/cjs/prompt/skills/afs/search.d.ts +3 -2
  28. package/lib/cjs/prompt/skills/afs/search.js +2 -2
  29. package/lib/cjs/prompt/skills/afs/write.d.ts +3 -2
  30. package/lib/cjs/prompt/skills/afs/write.js +2 -2
  31. package/lib/cjs/prompt/template.d.ts +82 -7
  32. package/lib/cjs/prompt/template.js +46 -17
  33. package/lib/dts/agents/chat-model.d.ts +160 -0
  34. package/lib/dts/agents/image-model.d.ts +15 -0
  35. package/lib/dts/agents/video-model.d.ts +15 -0
  36. package/lib/dts/aigne/usage.d.ts +5 -0
  37. package/lib/dts/loader/agent-yaml.d.ts +4 -0
  38. package/lib/dts/prompt/skills/afs/base.d.ts +4 -0
  39. package/lib/dts/prompt/skills/afs/delete.d.ts +3 -2
  40. package/lib/dts/prompt/skills/afs/edit.d.ts +3 -2
  41. package/lib/dts/prompt/skills/afs/exec.d.ts +3 -2
  42. package/lib/dts/prompt/skills/afs/list.d.ts +3 -2
  43. package/lib/dts/prompt/skills/afs/read.d.ts +3 -2
  44. package/lib/dts/prompt/skills/afs/rename.d.ts +3 -2
  45. package/lib/dts/prompt/skills/afs/search.d.ts +3 -2
  46. package/lib/dts/prompt/skills/afs/write.d.ts +3 -2
  47. package/lib/dts/prompt/template.d.ts +82 -7
  48. package/lib/esm/agents/chat-model.d.ts +160 -0
  49. package/lib/esm/agents/chat-model.js +37 -0
  50. package/lib/esm/agents/image-model.d.ts +15 -0
  51. package/lib/esm/agents/image-model.js +2 -0
  52. package/lib/esm/agents/video-model.d.ts +15 -0
  53. package/lib/esm/agents/video-model.js +2 -0
  54. package/lib/esm/aigne/usage.d.ts +5 -0
  55. package/lib/esm/aigne/usage.js +6 -0
  56. package/lib/esm/loader/agent-yaml.d.ts +4 -0
  57. package/lib/esm/loader/agent-yaml.js +15 -5
  58. package/lib/esm/prompt/context/afs/index.js +1 -2
  59. package/lib/esm/prompt/skills/afs/base.d.ts +4 -0
  60. package/lib/esm/prompt/skills/afs/base.js +4 -0
  61. package/lib/esm/prompt/skills/afs/delete.d.ts +3 -2
  62. package/lib/esm/prompt/skills/afs/delete.js +2 -2
  63. package/lib/esm/prompt/skills/afs/edit.d.ts +3 -2
  64. package/lib/esm/prompt/skills/afs/edit.js +2 -2
  65. package/lib/esm/prompt/skills/afs/exec.d.ts +3 -2
  66. package/lib/esm/prompt/skills/afs/exec.js +7 -4
  67. package/lib/esm/prompt/skills/afs/list.d.ts +3 -2
  68. package/lib/esm/prompt/skills/afs/list.js +6 -13
  69. package/lib/esm/prompt/skills/afs/read.d.ts +3 -2
  70. package/lib/esm/prompt/skills/afs/read.js +2 -2
  71. package/lib/esm/prompt/skills/afs/rename.d.ts +3 -2
  72. package/lib/esm/prompt/skills/afs/rename.js +2 -2
  73. package/lib/esm/prompt/skills/afs/search.d.ts +3 -2
  74. package/lib/esm/prompt/skills/afs/search.js +2 -2
  75. package/lib/esm/prompt/skills/afs/write.d.ts +3 -2
  76. package/lib/esm/prompt/skills/afs/write.js +2 -2
  77. package/lib/esm/prompt/template.d.ts +82 -7
  78. package/lib/esm/prompt/template.js +46 -17
  79. package/package.json +5 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
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
+
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)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * **afs:** set AFS tag for all AFS's skills ([#841](https://github.com/AIGNE-io/aigne-framework/issues/841)) ([0bd995a](https://github.com/AIGNE-io/aigne-framework/commit/0bd995aeb68aa68caac1ce19a200b42a022a9998))
23
+ * **afs:** use simple-list instead of tree as default type ([#839](https://github.com/AIGNE-io/aigne-framework/issues/839)) ([65a9a40](https://github.com/AIGNE-io/aigne-framework/commit/65a9a4054b3bdad6f7e40357299ef3dc48f7c3e4))
24
+ * **core:** add creditPrefix field to usage tracking ([#837](https://github.com/AIGNE-io/aigne-framework/issues/837)) ([9ef25e0](https://github.com/AIGNE-io/aigne-framework/commit/9ef25e0687b4e7b4ba39a27a35805f377f0979eb))
25
+
26
+
27
+ ### Dependencies
28
+
29
+ * The following workspace dependencies were updated
30
+ * dependencies
31
+ * @aigne/afs bumped to 1.4.0-beta.2
32
+ * @aigne/afs-history bumped to 1.2.0-beta.2
33
+
3
34
  ## [1.72.0-beta.1](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.72.0-beta...core-v1.72.0-beta.1) (2025-12-17)
4
35
 
5
36
 
@@ -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,17 +629,40 @@ 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;
642
+ /**
643
+ * Credit prefix
644
+ */
645
+ creditPrefix?: "$" | "€" | "¥";
495
646
  }
496
647
  export declare const chatModelOutputUsageSchema: z.ZodObject<{
497
648
  inputTokens: z.ZodNumber;
498
649
  outputTokens: z.ZodNumber;
499
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>;
653
+ creditPrefix: ZodType<"$" | "€" | "¥" | undefined, z.ZodTypeDef, "$" | "€" | "¥" | undefined>;
500
654
  }, "strip", z.ZodTypeAny, {
501
655
  inputTokens: number;
502
656
  outputTokens: number;
503
657
  aigneHubCredits?: number | undefined;
658
+ cacheCreationInputTokens?: number | undefined;
659
+ cacheReadInputTokens?: number | undefined;
660
+ creditPrefix?: "$" | "€" | "¥" | undefined;
504
661
  }, {
505
662
  inputTokens: number;
506
663
  outputTokens: number;
507
664
  aigneHubCredits?: number | undefined;
665
+ cacheCreationInputTokens?: number | undefined;
666
+ cacheReadInputTokens?: number | undefined;
667
+ creditPrefix?: "$" | "€" | "¥" | undefined;
508
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,12 @@ 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;
232
+ if (usage.creditPrefix)
233
+ options.context.usage.creditPrefix = usage.creditPrefix;
228
234
  }
229
235
  }
230
236
  async processAgentOutput(input, output, options) {
@@ -280,6 +286,10 @@ exports.roleSchema = zod_1.z.union([
280
286
  exports.textContentSchema = zod_1.z.object({
281
287
  type: zod_1.z.literal("text"),
282
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
+ })),
283
293
  });
284
294
  exports.unionContentSchema = zod_1.z.discriminatedUnion("type", [
285
295
  exports.textContentSchema,
@@ -301,6 +311,10 @@ const chatModelInputMessageSchema = zod_1.z.object({
301
311
  }))),
302
312
  toolCallId: (0, schema_js_1.optionalize)(zod_1.z.string()),
303
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
+ })),
304
318
  });
305
319
  const chatModelInputResponseFormatSchema = zod_1.z.discriminatedUnion("type", [
306
320
  zod_1.z.object({ type: zod_1.z.literal("text") }),
@@ -322,6 +336,10 @@ const chatModelInputToolSchema = zod_1.z.object({
322
336
  parameters: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()),
323
337
  }),
324
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
+ })),
325
343
  });
326
344
  const chatModelInputToolChoiceSchema = zod_1.z.union([
327
345
  zod_1.z.literal("auto"),
@@ -329,6 +347,22 @@ const chatModelInputToolChoiceSchema = zod_1.z.union([
329
347
  zod_1.z.literal("required"),
330
348
  chatModelInputToolSchema,
331
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
+ };
332
366
  const modelOptionsSchemaProperties = {
333
367
  model: zod_1.z.string(),
334
368
  temperature: zod_1.z.number(),
@@ -377,6 +411,9 @@ exports.chatModelOutputUsageSchema = zod_1.z.object({
377
411
  inputTokens: zod_1.z.number(),
378
412
  outputTokens: zod_1.z.number(),
379
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()),
416
+ creditPrefix: (0, schema_js_1.optionalize)(zod_1.z.union([zod_1.z.literal("$"), zod_1.z.literal("€"), zod_1.z.literal("¥")])),
380
417
  });
381
418
  const chatModelOutputSchema = zod_1.z.object({
382
419
  text: (0, schema_js_1.optionalize)(zod_1.z.string()),
@@ -196,14 +196,23 @@ 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>;
201
+ creditPrefix: ZodType<"$" | "€" | "¥" | undefined, z.ZodTypeDef, "$" | "€" | "¥" | undefined>;
199
202
  }, "strip", z.ZodTypeAny, {
200
203
  inputTokens: number;
201
204
  outputTokens: number;
202
205
  aigneHubCredits?: number | undefined;
206
+ cacheCreationInputTokens?: number | undefined;
207
+ cacheReadInputTokens?: number | undefined;
208
+ creditPrefix?: "$" | "€" | "¥" | undefined;
203
209
  }, {
204
210
  inputTokens: number;
205
211
  outputTokens: number;
206
212
  aigneHubCredits?: number | undefined;
213
+ cacheCreationInputTokens?: number | undefined;
214
+ cacheReadInputTokens?: number | undefined;
215
+ creditPrefix?: "$" | "€" | "¥" | undefined;
207
216
  }>>;
208
217
  model: z.ZodOptional<z.ZodString>;
209
218
  }, "strip", z.ZodTypeAny, {
@@ -228,6 +237,9 @@ export declare const imageModelOutputSchema: z.ZodObject<{
228
237
  inputTokens: number;
229
238
  outputTokens: number;
230
239
  aigneHubCredits?: number | undefined;
240
+ cacheCreationInputTokens?: number | undefined;
241
+ cacheReadInputTokens?: number | undefined;
242
+ creditPrefix?: "$" | "€" | "¥" | undefined;
231
243
  } | undefined;
232
244
  }, {
233
245
  images: ({
@@ -251,5 +263,8 @@ export declare const imageModelOutputSchema: z.ZodObject<{
251
263
  inputTokens: number;
252
264
  outputTokens: number;
253
265
  aigneHubCredits?: number | undefined;
266
+ cacheCreationInputTokens?: number | undefined;
267
+ cacheReadInputTokens?: number | undefined;
268
+ creditPrefix?: "$" | "€" | "¥" | undefined;
254
269
  } | undefined;
255
270
  }>;
@@ -61,6 +61,8 @@ class ImageModel extends model_js_1.Model {
61
61
  options.context.usage.inputTokens += usage.inputTokens;
62
62
  if (usage.aigneHubCredits)
63
63
  options.context.usage.aigneHubCredits += usage.aigneHubCredits;
64
+ if (usage.creditPrefix)
65
+ options.context.usage.creditPrefix = usage.creditPrefix;
64
66
  }
65
67
  }
66
68
  async processAgentOutput(input, output, options) {
@@ -203,14 +203,23 @@ 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>;
208
+ creditPrefix: ZodType<"$" | "€" | "¥" | undefined, z.ZodTypeDef, "$" | "€" | "¥" | undefined>;
206
209
  }, "strip", z.ZodTypeAny, {
207
210
  inputTokens: number;
208
211
  outputTokens: number;
209
212
  aigneHubCredits?: number | undefined;
213
+ cacheCreationInputTokens?: number | undefined;
214
+ cacheReadInputTokens?: number | undefined;
215
+ creditPrefix?: "$" | "€" | "¥" | undefined;
210
216
  }, {
211
217
  inputTokens: number;
212
218
  outputTokens: number;
213
219
  aigneHubCredits?: number | undefined;
220
+ cacheCreationInputTokens?: number | undefined;
221
+ cacheReadInputTokens?: number | undefined;
222
+ creditPrefix?: "$" | "€" | "¥" | undefined;
214
223
  }>>;
215
224
  model: z.ZodOptional<z.ZodString>;
216
225
  seconds: z.ZodOptional<z.ZodNumber>;
@@ -236,6 +245,9 @@ export declare const videoModelOutputSchema: z.ZodObject<{
236
245
  inputTokens: number;
237
246
  outputTokens: number;
238
247
  aigneHubCredits?: number | undefined;
248
+ cacheCreationInputTokens?: number | undefined;
249
+ cacheReadInputTokens?: number | undefined;
250
+ creditPrefix?: "$" | "€" | "¥" | undefined;
239
251
  } | undefined;
240
252
  seconds?: number | undefined;
241
253
  }, {
@@ -260,6 +272,9 @@ export declare const videoModelOutputSchema: z.ZodObject<{
260
272
  inputTokens: number;
261
273
  outputTokens: number;
262
274
  aigneHubCredits?: number | undefined;
275
+ cacheCreationInputTokens?: number | undefined;
276
+ cacheReadInputTokens?: number | undefined;
277
+ creditPrefix?: "$" | "€" | "¥" | undefined;
263
278
  } | undefined;
264
279
  seconds?: number | undefined;
265
280
  }>;
@@ -34,6 +34,8 @@ class VideoModel extends model_js_1.Model {
34
34
  options.context.usage.inputTokens += usage.inputTokens;
35
35
  if (usage.aigneHubCredits)
36
36
  options.context.usage.aigneHubCredits += usage.aigneHubCredits;
37
+ if (usage.creditPrefix)
38
+ options.context.usage.creditPrefix = usage.creditPrefix;
37
39
  }
38
40
  }
39
41
  async processAgentOutput(input, output, options) {
@@ -5,8 +5,13 @@ export interface ContextUsage {
5
5
  inputTokens: number;
6
6
  outputTokens: number;
7
7
  aigneHubCredits: number;
8
+ creditPrefix?: "$" | "€" | "¥";
8
9
  agentCalls: number;
9
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;
10
15
  }
11
16
  /**
12
17
  * @hidden
@@ -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
  }
@@ -72,6 +72,10 @@ export type Instructions = {
72
72
  role: Exclude<Role, "tool">;
73
73
  content: string;
74
74
  path: string;
75
+ cacheControl?: {
76
+ type: "ephemeral";
77
+ ttl?: "5m" | "1h";
78
+ };
75
79
  }[];
76
80
  export interface AIAgentSchema extends BaseAgentSchema {
77
81
  type: "ai";
@@ -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.readFile(url, "utf8").then((content) => ({ role, content, path: url }));
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
  };
@@ -31,8 +31,7 @@ function createAFSContext(agent, context) {
31
31
  async list(path, options) {
32
32
  if (!afs)
33
33
  throw new Error("AFS is not configured for this agent.");
34
- return (await afs.list(path, { ...options, context, format: options?.format || "tree" }))
35
- .data;
34
+ return (await afs.list(path, { ...options, context, format: options?.format || "simple-list" })).data;
36
35
  },
37
36
  async read(path) {
38
37
  if (!afs)
@@ -0,0 +1,4 @@
1
+ import { Agent, type Message } from "../../../agents/agent.js";
2
+ export declare abstract class AFSSkillBase<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
3
+ tag: string;
4
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AFSSkillBase = void 0;
4
+ const agent_js_1 = require("../../../agents/agent.js");
5
+ class AFSSkillBase extends agent_js_1.Agent {
6
+ tag = "AFS";
7
+ }
8
+ exports.AFSSkillBase = AFSSkillBase;
@@ -1,4 +1,5 @@
1
- import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from "../../../agents/agent.js";
1
+ import type { AgentInvokeOptions, AgentOptions, Message } from "../../../agents/agent.js";
2
+ import { AFSSkillBase } from "./base.js";
2
3
  export interface AFSDeleteInput extends Message {
3
4
  path: string;
4
5
  recursive?: boolean;
@@ -12,7 +13,7 @@ export interface AFSDeleteOutput extends Message {
12
13
  export interface AFSDeleteAgentOptions extends AgentOptions<AFSDeleteInput, AFSDeleteOutput> {
13
14
  afs: NonNullable<AgentOptions<AFSDeleteInput, AFSDeleteOutput>["afs"]>;
14
15
  }
15
- export declare class AFSDeleteAgent extends Agent<AFSDeleteInput, AFSDeleteOutput> {
16
+ export declare class AFSDeleteAgent extends AFSSkillBase<AFSDeleteInput, AFSDeleteOutput> {
16
17
  constructor(options: AFSDeleteAgentOptions);
17
18
  process(input: AFSDeleteInput, _options: AgentInvokeOptions): Promise<AFSDeleteOutput>;
18
19
  }
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AFSDeleteAgent = void 0;
4
4
  const zod_1 = require("zod");
5
- const agent_js_1 = require("../../../agents/agent.js");
6
- class AFSDeleteAgent extends agent_js_1.Agent {
5
+ const base_js_1 = require("./base.js");
6
+ class AFSDeleteAgent extends base_js_1.AFSSkillBase {
7
7
  constructor(options) {
8
8
  super({
9
9
  name: "afs_delete",
@@ -1,4 +1,5 @@
1
- import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from "../../../agents/agent.js";
1
+ import type { AgentInvokeOptions, AgentOptions, Message } from "../../../agents/agent.js";
2
+ import { AFSSkillBase } from "./base.js";
2
3
  export interface Patch {
3
4
  start_line: number;
4
5
  end_line: number;
@@ -19,7 +20,7 @@ export interface AFSEditOutput extends Message {
19
20
  export interface AFSEditAgentOptions extends AgentOptions<AFSEditInput, AFSEditOutput> {
20
21
  afs: NonNullable<AgentOptions<AFSEditInput, AFSEditOutput>["afs"]>;
21
22
  }
22
- export declare class AFSEditAgent extends Agent<AFSEditInput, AFSEditOutput> {
23
+ export declare class AFSEditAgent extends AFSSkillBase<AFSEditInput, AFSEditOutput> {
23
24
  constructor(options: AFSEditAgentOptions);
24
25
  process(input: AFSEditInput, _options: AgentInvokeOptions): Promise<AFSEditOutput>;
25
26
  applyCustomPatches(text: string, patches: Patch[]): string;
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AFSEditAgent = void 0;
4
4
  const zod_1 = require("zod");
5
- const agent_js_1 = require("../../../agents/agent.js");
6
- class AFSEditAgent extends agent_js_1.Agent {
5
+ const base_js_1 = require("./base.js");
6
+ class AFSEditAgent extends base_js_1.AFSSkillBase {
7
7
  constructor(options) {
8
8
  super({
9
9
  name: "afs_edit",
@@ -1,4 +1,5 @@
1
- import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from "../../../agents/agent.js";
1
+ import type { AgentInvokeOptions, AgentOptions, Message } from "../../../agents/agent.js";
2
+ import { AFSSkillBase } from "./base.js";
2
3
  export interface AFSExecInput extends Message {
3
4
  path: string;
4
5
  args: string;
@@ -9,7 +10,7 @@ export interface AFSExecOutput extends Message {
9
10
  export interface AFSExecAgentOptions extends AgentOptions<AFSExecInput, AFSExecOutput> {
10
11
  afs: NonNullable<AgentOptions<AFSExecInput, AFSExecOutput>["afs"]>;
11
12
  }
12
- export declare class AFSExecAgent extends Agent<AFSExecInput, AFSExecOutput> {
13
+ export declare class AFSExecAgent extends AFSSkillBase<AFSExecInput, AFSExecOutput> {
13
14
  constructor(options: AFSExecAgentOptions);
14
15
  process(input: AFSExecInput, options: AgentInvokeOptions): Promise<AFSExecOutput>;
15
16
  }