@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
@@ -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
  }>;
@@ -188,6 +188,12 @@ export class ChatModel extends Model {
188
188
  options.context.usage.inputTokens += usage.inputTokens;
189
189
  if (usage.aigneHubCredits)
190
190
  options.context.usage.aigneHubCredits += usage.aigneHubCredits;
191
+ if (usage.cacheCreationInputTokens)
192
+ options.context.usage.cacheCreationInputTokens += usage.cacheCreationInputTokens;
193
+ if (usage.cacheReadInputTokens)
194
+ options.context.usage.cacheReadInputTokens += usage.cacheReadInputTokens;
195
+ if (usage.creditPrefix)
196
+ options.context.usage.creditPrefix = usage.creditPrefix;
191
197
  }
192
198
  }
193
199
  async processAgentOutput(input, output, options) {
@@ -242,6 +248,10 @@ export const roleSchema = z.union([
242
248
  export const textContentSchema = z.object({
243
249
  type: z.literal("text"),
244
250
  text: z.string(),
251
+ cacheControl: optionalize(z.object({
252
+ type: z.literal("ephemeral"),
253
+ ttl: optionalize(z.union([z.literal("5m"), z.literal("1h")])),
254
+ })),
245
255
  });
246
256
  export const unionContentSchema = z.discriminatedUnion("type", [
247
257
  textContentSchema,
@@ -263,6 +273,10 @@ const chatModelInputMessageSchema = z.object({
263
273
  }))),
264
274
  toolCallId: optionalize(z.string()),
265
275
  name: optionalize(z.string()),
276
+ cacheControl: optionalize(z.object({
277
+ type: z.literal("ephemeral"),
278
+ ttl: optionalize(z.union([z.literal("5m"), z.literal("1h")])),
279
+ })),
266
280
  });
267
281
  const chatModelInputResponseFormatSchema = z.discriminatedUnion("type", [
268
282
  z.object({ type: z.literal("text") }),
@@ -284,6 +298,10 @@ const chatModelInputToolSchema = z.object({
284
298
  parameters: z.record(z.string(), z.unknown()),
285
299
  }),
286
300
  metadata: optionalize(z.record(z.string(), z.unknown())),
301
+ cacheControl: optionalize(z.object({
302
+ type: z.literal("ephemeral"),
303
+ ttl: optionalize(z.union([z.literal("5m"), z.literal("1h")])),
304
+ })),
287
305
  });
288
306
  const chatModelInputToolChoiceSchema = z.union([
289
307
  z.literal("auto"),
@@ -291,6 +309,22 @@ const chatModelInputToolChoiceSchema = z.union([
291
309
  z.literal("required"),
292
310
  chatModelInputToolSchema,
293
311
  ]);
312
+ /**
313
+ * Default cache configuration
314
+ *
315
+ * Enables automatic caching for system messages and tool definitions,
316
+ * which typically provides the best cost/performance tradeoff.
317
+ */
318
+ export const DEFAULT_CACHE_CONFIG = {
319
+ enabled: true,
320
+ ttl: "5m",
321
+ strategy: "auto",
322
+ autoBreakpoints: {
323
+ tools: true,
324
+ system: true,
325
+ lastMessage: false,
326
+ },
327
+ };
294
328
  const modelOptionsSchemaProperties = {
295
329
  model: z.string(),
296
330
  temperature: z.number(),
@@ -339,6 +373,9 @@ export const chatModelOutputUsageSchema = z.object({
339
373
  inputTokens: z.number(),
340
374
  outputTokens: z.number(),
341
375
  aigneHubCredits: optionalize(z.number()),
376
+ cacheCreationInputTokens: optionalize(z.number()),
377
+ cacheReadInputTokens: optionalize(z.number()),
378
+ creditPrefix: optionalize(z.union([z.literal("$"), z.literal("€"), z.literal("¥")])),
342
379
  });
343
380
  const chatModelOutputSchema = z.object({
344
381
  text: optionalize(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
  }>;
@@ -58,6 +58,8 @@ export class ImageModel extends Model {
58
58
  options.context.usage.inputTokens += usage.inputTokens;
59
59
  if (usage.aigneHubCredits)
60
60
  options.context.usage.aigneHubCredits += usage.aigneHubCredits;
61
+ if (usage.creditPrefix)
62
+ options.context.usage.creditPrefix = usage.creditPrefix;
61
63
  }
62
64
  }
63
65
  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
  }>;
@@ -31,6 +31,8 @@ export class VideoModel extends Model {
31
31
  options.context.usage.inputTokens += usage.inputTokens;
32
32
  if (usage.aigneHubCredits)
33
33
  options.context.usage.aigneHubCredits += usage.aigneHubCredits;
34
+ if (usage.creditPrefix)
35
+ options.context.usage.creditPrefix = usage.creditPrefix;
34
36
  }
35
37
  }
36
38
  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
@@ -8,6 +8,8 @@ export function newEmptyContextUsage() {
8
8
  aigneHubCredits: 0,
9
9
  agentCalls: 0,
10
10
  duration: 0,
11
+ cacheCreationInputTokens: 0,
12
+ cacheReadInputTokens: 0,
11
13
  };
12
14
  }
13
15
  export function mergeContextUsage(usage, additional) {
@@ -21,4 +23,8 @@ export function mergeContextUsage(usage, additional) {
21
23
  usage.agentCalls += additional.agentCalls;
22
24
  if (additional.duration)
23
25
  usage.duration += additional.duration;
26
+ if (additional.cacheCreationInputTokens)
27
+ usage.cacheCreationInputTokens += additional.cacheCreationInputTokens;
28
+ if (additional.cacheReadInputTokens)
29
+ usage.cacheReadInputTokens += additional.cacheReadInputTokens;
24
30
  }
@@ -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";
@@ -25,27 +25,37 @@ export async function loadAgentFromYamlFile(path, options) {
25
25
  }, options), (error) => new Error(`Failed to validate agent definition from ${path}: ${error.message}`));
26
26
  return agent;
27
27
  }
28
- const instructionItemSchema = z.union([
28
+ const instructionItemSchema = camelizeSchema(z.union([
29
29
  z.object({
30
30
  role: roleSchema.default("system"),
31
31
  url: z.string(),
32
+ cacheControl: optionalize(z.object({
33
+ type: z.literal("ephemeral"),
34
+ ttl: optionalize(z.union([z.literal("5m"), z.literal("1h")])),
35
+ })),
32
36
  }),
33
37
  z.object({
34
38
  role: roleSchema.default("system"),
35
39
  content: z.string(),
40
+ cacheControl: optionalize(z.object({
41
+ type: z.literal("ephemeral"),
42
+ ttl: optionalize(z.union([z.literal("5m"), z.literal("1h")])),
43
+ })),
36
44
  }),
37
- ]);
38
- const parseInstructionItem = ({ filepath }) => async ({ role, ...v }) => {
45
+ ]));
46
+ const parseInstructionItem = ({ filepath }) => async ({ role, cacheControl, ...v }) => {
39
47
  if (role === "tool")
40
48
  throw new Error(`'tool' role is not allowed in instruction item in agent file ${filepath}`);
41
49
  if ("content" in v && typeof v.content === "string") {
42
- return { role, content: v.content, path: filepath };
50
+ return { role, content: v.content, path: filepath, cacheControl };
43
51
  }
44
52
  if ("url" in v && typeof v.url === "string") {
45
53
  const url = nodejs.path.isAbsolute(v.url)
46
54
  ? v.url
47
55
  : nodejs.path.join(nodejs.path.dirname(filepath), v.url);
48
- return nodejs.fs.readFile(url, "utf8").then((content) => ({ role, content, path: url }));
56
+ return nodejs.fs
57
+ .readFile(url, "utf8")
58
+ .then((content) => ({ role, content, path: url, cacheControl }));
49
59
  }
50
60
  throw new Error(`Invalid instruction item in agent file ${filepath}. Expected 'content' or 'url' property`);
51
61
  };
@@ -28,8 +28,7 @@ export function createAFSContext(agent, context) {
28
28
  async list(path, options) {
29
29
  if (!afs)
30
30
  throw new Error("AFS is not configured for this agent.");
31
- return (await afs.list(path, { ...options, context, format: options?.format || "tree" }))
32
- .data;
31
+ return (await afs.list(path, { ...options, context, format: options?.format || "simple-list" })).data;
33
32
  },
34
33
  async read(path) {
35
34
  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,4 @@
1
+ import { Agent } from "../../../agents/agent.js";
2
+ export class AFSSkillBase extends Agent {
3
+ tag = "AFS";
4
+ }
@@ -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
  }
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
- import { Agent, } from "../../../agents/agent.js";
3
- export class AFSDeleteAgent extends Agent {
2
+ import { AFSSkillBase } from "./base.js";
3
+ export class AFSDeleteAgent extends AFSSkillBase {
4
4
  constructor(options) {
5
5
  super({
6
6
  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;
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
- import { Agent, } from "../../../agents/agent.js";
3
- export class AFSEditAgent extends Agent {
2
+ import { AFSSkillBase } from "./base.js";
3
+ export class AFSEditAgent extends AFSSkillBase {
4
4
  constructor(options) {
5
5
  super({
6
6
  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
  }
@@ -1,13 +1,16 @@
1
1
  import { z } from "zod";
2
- import { Agent, } from "../../../agents/agent.js";
3
- export class AFSExecAgent extends Agent {
2
+ import { AFSSkillBase } from "./base.js";
3
+ export class AFSExecAgent extends AFSSkillBase {
4
4
  constructor(options) {
5
5
  super({
6
6
  name: "afs_exec",
7
- description: "Execute functions or commands from AFS modules. Use when running operations provided by mounted modules.",
7
+ description: `
8
+ Execute files marked as executable in the Agentic File System (AFS).
9
+ Use this to run executable files registered at a given path with specified arguments.
10
+ `.trim(),
8
11
  ...options,
9
12
  inputSchema: z.object({
10
- path: z.string().describe("Absolute path to the executable function in AFS"),
13
+ path: z.string().describe("Absolute path to the executable file in AFS"),
11
14
  args: z.string().describe("JSON string of arguments matching the function's input schema"),
12
15
  }),
13
16
  outputSchema: z.object({
@@ -1,5 +1,6 @@
1
1
  import type { AFSListOptions } from "@aigne/afs";
2
- import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from "../../../agents/agent.js";
2
+ import type { AgentInvokeOptions, AgentOptions, Message } from "../../../agents/agent.js";
3
+ import { AFSSkillBase } from "./base.js";
3
4
  export interface AFSListInput extends Message {
4
5
  path: string;
5
6
  options?: AFSListOptions;
@@ -15,7 +16,7 @@ export interface AFSListOutput extends Message {
15
16
  export interface AFSListAgentOptions extends AgentOptions<AFSListInput, AFSListOutput> {
16
17
  afs: NonNullable<AgentOptions<AFSListInput, AFSListOutput>["afs"]>;
17
18
  }
18
- export declare class AFSListAgent extends Agent<AFSListInput, AFSListOutput> {
19
+ export declare class AFSListAgent extends AFSSkillBase<AFSListInput, AFSListOutput> {
19
20
  constructor(options: AFSListAgentOptions);
20
21
  process(input: AFSListInput, _options: AgentInvokeOptions): Promise<AFSListOutput>;
21
22
  }