@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
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
- import { Agent, } from "../../../agents/agent.js";
3
- export class AFSListAgent extends Agent {
2
+ import { AFSSkillBase } from "./base.js";
3
+ export class AFSListAgent extends AFSSkillBase {
4
4
  constructor(options) {
5
5
  super({
6
6
  name: "afs_list",
@@ -20,10 +20,10 @@ export class AFSListAgent extends Agent {
20
20
  .optional()
21
21
  .describe("Maximum number of children to list per directory"),
22
22
  format: z
23
- .union([z.literal("tree"), z.literal("list")])
23
+ .union([z.literal("simple-list"), z.literal("tree")])
24
24
  .optional()
25
- .default("tree")
26
- .describe("Output format, either 'tree' or 'list' (default: 'tree')"),
25
+ .default("simple-list")
26
+ .describe("Output format, either 'simple-list', or 'tree', default is 'simple-list'"),
27
27
  })
28
28
  .optional(),
29
29
  }),
@@ -31,14 +31,7 @@ export class AFSListAgent extends Agent {
31
31
  status: z.string(),
32
32
  tool: z.string(),
33
33
  path: z.string(),
34
- options: z
35
- .object({
36
- maxDepth: z.number().optional(),
37
- disableGitignore: z.boolean().optional(),
38
- maxChildren: z.number().optional(),
39
- format: z.union([z.literal("tree"), z.literal("list")]).optional(),
40
- })
41
- .optional(),
34
+ options: z.record(z.any()).optional(),
42
35
  message: z.string().optional(),
43
36
  data: z.unknown(),
44
37
  }),
@@ -1,5 +1,6 @@
1
1
  import type { AFSEntry } 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 AFSReadInput extends Message {
4
5
  path: string;
5
6
  withLineNumbers?: boolean;
@@ -15,7 +16,7 @@ export interface AFSReadOutput extends Message {
15
16
  export interface AFSReadAgentOptions extends AgentOptions<AFSReadInput, AFSReadOutput> {
16
17
  afs: NonNullable<AgentOptions<AFSReadInput, AFSReadOutput>["afs"]>;
17
18
  }
18
- export declare class AFSReadAgent extends Agent<AFSReadInput, AFSReadOutput> {
19
+ export declare class AFSReadAgent extends AFSSkillBase<AFSReadInput, AFSReadOutput> {
19
20
  constructor(options: AFSReadAgentOptions);
20
21
  process(input: AFSReadInput, _options: AgentInvokeOptions): Promise<AFSReadOutput>;
21
22
  }
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
- import { Agent, } from "../../../agents/agent.js";
3
- export class AFSReadAgent extends Agent {
2
+ import { AFSSkillBase } from "./base.js";
3
+ export class AFSReadAgent extends AFSSkillBase {
4
4
  constructor(options) {
5
5
  super({
6
6
  name: "afs_read",
@@ -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 AFSRenameInput extends Message {
3
4
  oldPath: string;
4
5
  newPath: string;
@@ -14,7 +15,7 @@ export interface AFSRenameOutput extends Message {
14
15
  export interface AFSRenameAgentOptions extends AgentOptions<AFSRenameInput, AFSRenameOutput> {
15
16
  afs: NonNullable<AgentOptions<AFSRenameInput, AFSRenameOutput>["afs"]>;
16
17
  }
17
- export declare class AFSRenameAgent extends Agent<AFSRenameInput, AFSRenameOutput> {
18
+ export declare class AFSRenameAgent extends AFSSkillBase<AFSRenameInput, AFSRenameOutput> {
18
19
  constructor(options: AFSRenameAgentOptions);
19
20
  process(input: AFSRenameInput, _options: AgentInvokeOptions): Promise<AFSRenameOutput>;
20
21
  }
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
- import { Agent, } from "../../../agents/agent.js";
3
- export class AFSRenameAgent extends Agent {
2
+ import { AFSSkillBase } from "./base.js";
3
+ export class AFSRenameAgent extends AFSSkillBase {
4
4
  constructor(options) {
5
5
  super({
6
6
  name: "afs_rename",
@@ -1,5 +1,6 @@
1
1
  import type { AFSEntry, AFSSearchOptions } 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 AFSSearchInput extends Message {
4
5
  path: string;
5
6
  query: string;
@@ -17,7 +18,7 @@ export interface AFSSearchOutput extends Message {
17
18
  export interface AFSSearchAgentOptions extends AgentOptions<AFSSearchInput, AFSSearchOutput> {
18
19
  afs: NonNullable<AgentOptions<AFSSearchInput, AFSSearchOutput>["afs"]>;
19
20
  }
20
- export declare class AFSSearchAgent extends Agent<AFSSearchInput, AFSSearchOutput> {
21
+ export declare class AFSSearchAgent extends AFSSkillBase<AFSSearchInput, AFSSearchOutput> {
21
22
  constructor(options: AFSSearchAgentOptions);
22
23
  process(input: AFSSearchInput, _options: AgentInvokeOptions): Promise<AFSSearchOutput>;
23
24
  }
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
- import { Agent, } from "../../../agents/agent.js";
3
- export class AFSSearchAgent extends Agent {
2
+ import { AFSSkillBase } from "./base.js";
3
+ export class AFSSearchAgent extends AFSSkillBase {
4
4
  constructor(options) {
5
5
  super({
6
6
  name: "afs_search",
@@ -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 AFSWriteInput extends Message {
3
4
  path: string;
4
5
  content: string;
@@ -13,7 +14,7 @@ export interface AFSWriteOutput extends Message {
13
14
  export interface AFSWriteAgentOptions extends AgentOptions<AFSWriteInput, AFSWriteOutput> {
14
15
  afs: NonNullable<AgentOptions<AFSWriteInput, AFSWriteOutput>["afs"]>;
15
16
  }
16
- export declare class AFSWriteAgent extends Agent<AFSWriteInput, AFSWriteOutput> {
17
+ export declare class AFSWriteAgent extends AFSSkillBase<AFSWriteInput, AFSWriteOutput> {
17
18
  constructor(options: AFSWriteAgentOptions);
18
19
  process(input: AFSWriteInput, _options: AgentInvokeOptions): Promise<AFSWriteOutput>;
19
20
  }
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
- import { Agent, } from "../../../agents/agent.js";
3
- export class AFSWriteAgent extends Agent {
2
+ import { AFSSkillBase } from "./base.js";
3
+ export class AFSWriteAgent extends AFSSkillBase {
4
4
  constructor(options) {
5
5
  super({
6
6
  name: "afs_write",
@@ -27,35 +27,38 @@ export declare class ChatMessageTemplate {
27
27
  content?: ChatModelInputMessage["content"];
28
28
  name?: string | undefined;
29
29
  options?: FormatOptions | undefined;
30
- constructor(role: "system" | "user" | "agent" | "tool", content?: ChatModelInputMessage["content"], name?: string | undefined, options?: FormatOptions | undefined);
30
+ cacheControl?: ChatModelInputMessage["cacheControl"];
31
+ constructor(role: "system" | "user" | "agent" | "tool", content?: ChatModelInputMessage["content"], name?: string | undefined, options?: FormatOptions | undefined, cacheControl?: ChatModelInputMessage["cacheControl"]);
31
32
  format(variables?: Record<string, unknown>, options?: FormatOptions): Promise<ChatModelInputMessage>;
32
33
  }
33
34
  export declare class SystemMessageTemplate extends ChatMessageTemplate {
34
- static from(content: string, name?: string, options?: FormatOptions): SystemMessageTemplate;
35
+ static from(content: string, name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]): SystemMessageTemplate;
35
36
  }
36
37
  export declare class UserMessageTemplate extends ChatMessageTemplate {
37
- static from(template: ChatModelInputMessageContent, name?: string, options?: FormatOptions): UserMessageTemplate;
38
+ static from(template: ChatModelInputMessageContent, name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]): UserMessageTemplate;
38
39
  }
39
40
  export declare class AgentMessageTemplate extends ChatMessageTemplate {
40
41
  toolCalls?: ChatModelOutputToolCall[] | undefined;
41
- static from(template?: ChatModelInputMessage["content"], toolCalls?: ChatModelOutputToolCall[], name?: string, options?: FormatOptions): AgentMessageTemplate;
42
- constructor(content?: ChatModelInputMessage["content"], toolCalls?: ChatModelOutputToolCall[] | undefined, name?: string, options?: FormatOptions);
42
+ static from(template?: ChatModelInputMessage["content"], toolCalls?: ChatModelOutputToolCall[], name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]): AgentMessageTemplate;
43
+ constructor(content?: ChatModelInputMessage["content"], toolCalls?: ChatModelOutputToolCall[] | undefined, name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]);
43
44
  format(_variables?: Record<string, unknown>, _options?: FormatOptions): Promise<{
44
45
  role: "agent" | "system" | "user" | "tool";
45
46
  name: string | undefined;
46
47
  content: ChatModelInputMessageContent | undefined;
47
48
  toolCalls: ChatModelOutputToolCall[] | undefined;
49
+ cacheControl: import("../agents/chat-model.js").CacheControl | undefined;
48
50
  }>;
49
51
  }
50
52
  export declare class ToolMessageTemplate extends ChatMessageTemplate {
51
53
  toolCallId: string;
52
- static from(content: object | string, toolCallId: string, name?: string, options?: FormatOptions): ToolMessageTemplate;
53
- constructor(content: object | string, toolCallId: string, name?: string, options?: FormatOptions);
54
+ static from(content: object | string, toolCallId: string, name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]): ToolMessageTemplate;
55
+ constructor(content: object | string, toolCallId: string, name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]);
54
56
  format(_variables?: Record<string, unknown>, _options?: FormatOptions): Promise<{
55
57
  role: "agent" | "system" | "user" | "tool";
56
58
  name: string | undefined;
57
59
  content: ChatModelInputMessageContent | undefined;
58
60
  toolCallId: string;
61
+ cacheControl: import("../agents/chat-model.js").CacheControl | undefined;
59
62
  }>;
60
63
  }
61
64
  export declare class ChatMessagesTemplate {
@@ -69,26 +72,62 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
69
72
  role: z.ZodLiteral<"system">;
70
73
  content: z.ZodString;
71
74
  name: z.ZodOptional<z.ZodString>;
75
+ cacheControl: z.ZodOptional<z.ZodObject<{
76
+ type: z.ZodLiteral<"ephemeral">;
77
+ ttl: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"5m">, z.ZodLiteral<"1h">]>>;
78
+ }, "strip", z.ZodTypeAny, {
79
+ type: "ephemeral";
80
+ ttl?: "5m" | "1h" | undefined;
81
+ }, {
82
+ type: "ephemeral";
83
+ ttl?: "5m" | "1h" | undefined;
84
+ }>>;
72
85
  }, "strip", z.ZodTypeAny, {
73
86
  role: "system";
74
87
  content: string;
75
88
  name?: string | undefined;
89
+ cacheControl?: {
90
+ type: "ephemeral";
91
+ ttl?: "5m" | "1h" | undefined;
92
+ } | undefined;
76
93
  }, {
77
94
  role: "system";
78
95
  content: string;
79
96
  name?: string | undefined;
97
+ cacheControl?: {
98
+ type: "ephemeral";
99
+ ttl?: "5m" | "1h" | undefined;
100
+ } | undefined;
80
101
  }>, z.ZodObject<{
81
102
  role: z.ZodLiteral<"user">;
82
103
  content: z.ZodString;
83
104
  name: z.ZodOptional<z.ZodString>;
105
+ cacheControl: z.ZodOptional<z.ZodObject<{
106
+ type: z.ZodLiteral<"ephemeral">;
107
+ ttl: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"5m">, z.ZodLiteral<"1h">]>>;
108
+ }, "strip", z.ZodTypeAny, {
109
+ type: "ephemeral";
110
+ ttl?: "5m" | "1h" | undefined;
111
+ }, {
112
+ type: "ephemeral";
113
+ ttl?: "5m" | "1h" | undefined;
114
+ }>>;
84
115
  }, "strip", z.ZodTypeAny, {
85
116
  role: "user";
86
117
  content: string;
87
118
  name?: string | undefined;
119
+ cacheControl?: {
120
+ type: "ephemeral";
121
+ ttl?: "5m" | "1h" | undefined;
122
+ } | undefined;
88
123
  }, {
89
124
  role: "user";
90
125
  content: string;
91
126
  name?: string | undefined;
127
+ cacheControl?: {
128
+ type: "ephemeral";
129
+ ttl?: "5m" | "1h" | undefined;
130
+ } | undefined;
92
131
  }>, z.ZodObject<{
93
132
  role: z.ZodLiteral<"agent">;
94
133
  content: z.ZodOptional<z.ZodString>;
@@ -121,6 +160,16 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
121
160
  id: string;
122
161
  }>, "many">>;
123
162
  name: z.ZodOptional<z.ZodString>;
163
+ cacheControl: z.ZodOptional<z.ZodObject<{
164
+ type: z.ZodLiteral<"ephemeral">;
165
+ ttl: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"5m">, z.ZodLiteral<"1h">]>>;
166
+ }, "strip", z.ZodTypeAny, {
167
+ type: "ephemeral";
168
+ ttl?: "5m" | "1h" | undefined;
169
+ }, {
170
+ type: "ephemeral";
171
+ ttl?: "5m" | "1h" | undefined;
172
+ }>>;
124
173
  }, "strip", z.ZodTypeAny, {
125
174
  role: "agent";
126
175
  name?: string | undefined;
@@ -133,6 +182,10 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
133
182
  type: "function";
134
183
  id: string;
135
184
  }[] | undefined;
185
+ cacheControl?: {
186
+ type: "ephemeral";
187
+ ttl?: "5m" | "1h" | undefined;
188
+ } | undefined;
136
189
  }, {
137
190
  role: "agent";
138
191
  name?: string | undefined;
@@ -145,21 +198,43 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
145
198
  type: "function";
146
199
  id: string;
147
200
  }[] | undefined;
201
+ cacheControl?: {
202
+ type: "ephemeral";
203
+ ttl?: "5m" | "1h" | undefined;
204
+ } | undefined;
148
205
  }>, z.ZodObject<{
149
206
  role: z.ZodLiteral<"tool">;
150
207
  content: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>, string, string | Record<string, unknown>>;
151
208
  toolCallId: z.ZodString;
152
209
  name: z.ZodOptional<z.ZodString>;
210
+ cacheControl: z.ZodOptional<z.ZodObject<{
211
+ type: z.ZodLiteral<"ephemeral">;
212
+ ttl: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"5m">, z.ZodLiteral<"1h">]>>;
213
+ }, "strip", z.ZodTypeAny, {
214
+ type: "ephemeral";
215
+ ttl?: "5m" | "1h" | undefined;
216
+ }, {
217
+ type: "ephemeral";
218
+ ttl?: "5m" | "1h" | undefined;
219
+ }>>;
153
220
  }, "strip", z.ZodTypeAny, {
154
221
  role: "tool";
155
222
  content: string;
156
223
  toolCallId: string;
157
224
  name?: string | undefined;
225
+ cacheControl?: {
226
+ type: "ephemeral";
227
+ ttl?: "5m" | "1h" | undefined;
228
+ } | undefined;
158
229
  }, {
159
230
  role: "tool";
160
231
  content: string | Record<string, unknown>;
161
232
  toolCallId: string;
162
233
  name?: string | undefined;
234
+ cacheControl?: {
235
+ type: "ephemeral";
236
+ ttl?: "5m" | "1h" | undefined;
237
+ } | undefined;
163
238
  }>]>;
164
239
  export declare function safeParseChatMessages(messages: unknown): ChatMessageTemplate[] | undefined;
165
240
  export declare function parseChatMessages(messages: (z.infer<typeof chatMessageSchema> & {
@@ -70,11 +70,13 @@ export class ChatMessageTemplate {
70
70
  content;
71
71
  name;
72
72
  options;
73
- constructor(role, content, name, options) {
73
+ cacheControl;
74
+ constructor(role, content, name, options, cacheControl) {
74
75
  this.role = role;
75
76
  this.content = content;
76
77
  this.name = name;
77
78
  this.options = options;
79
+ this.cacheControl = cacheControl;
78
80
  }
79
81
  async format(variables, options) {
80
82
  options = { ...this.options, ...omitBy(options ?? {}, (v) => isNil(v)) };
@@ -93,26 +95,27 @@ export class ChatMessageTemplate {
93
95
  role: this.role,
94
96
  content,
95
97
  name: this.name,
98
+ cacheControl: this.cacheControl,
96
99
  };
97
100
  }
98
101
  }
99
102
  export class SystemMessageTemplate extends ChatMessageTemplate {
100
- static from(content, name, options) {
101
- return new SystemMessageTemplate("system", content, name, options);
103
+ static from(content, name, options, cacheControl) {
104
+ return new SystemMessageTemplate("system", content, name, options, cacheControl);
102
105
  }
103
106
  }
104
107
  export class UserMessageTemplate extends ChatMessageTemplate {
105
- static from(template, name, options) {
106
- return new UserMessageTemplate("user", template, name, options);
108
+ static from(template, name, options, cacheControl) {
109
+ return new UserMessageTemplate("user", template, name, options, cacheControl);
107
110
  }
108
111
  }
109
112
  export class AgentMessageTemplate extends ChatMessageTemplate {
110
113
  toolCalls;
111
- static from(template, toolCalls, name, options) {
112
- return new AgentMessageTemplate(template, toolCalls, name, options);
114
+ static from(template, toolCalls, name, options, cacheControl) {
115
+ return new AgentMessageTemplate(template, toolCalls, name, options, cacheControl);
113
116
  }
114
- constructor(content, toolCalls, name, options) {
115
- super("agent", content, name, options);
117
+ constructor(content, toolCalls, name, options, cacheControl) {
118
+ super("agent", content, name, options, cacheControl);
116
119
  this.toolCalls = toolCalls;
117
120
  }
118
121
  async format(_variables, _options) {
@@ -122,16 +125,17 @@ export class AgentMessageTemplate extends ChatMessageTemplate {
122
125
  // NOTE: agent message should not rendered by template
123
126
  content: this.content,
124
127
  toolCalls: this.toolCalls,
128
+ cacheControl: this.cacheControl,
125
129
  };
126
130
  }
127
131
  }
128
132
  export class ToolMessageTemplate extends ChatMessageTemplate {
129
133
  toolCallId;
130
- static from(content, toolCallId, name, options) {
131
- return new ToolMessageTemplate(content, toolCallId, name, options);
134
+ static from(content, toolCallId, name, options, cacheControl) {
135
+ return new ToolMessageTemplate(content, toolCallId, name, options, cacheControl);
132
136
  }
133
- constructor(content, toolCallId, name, options) {
134
- super("tool", typeof content === "string" ? content : stringify(content), name, options);
137
+ constructor(content, toolCallId, name, options, cacheControl) {
138
+ super("tool", typeof content === "string" ? content : stringify(content), name, options, cacheControl);
135
139
  this.toolCallId = toolCallId;
136
140
  }
137
141
  async format(_variables, _options) {
@@ -141,6 +145,7 @@ export class ToolMessageTemplate extends ChatMessageTemplate {
141
145
  // NOTE: tool result should not rendered by template
142
146
  content: this.content,
143
147
  toolCallId: this.toolCallId,
148
+ cacheControl: this.cacheControl,
144
149
  };
145
150
  }
146
151
  }
@@ -163,11 +168,23 @@ const systemChatMessageSchema = z.object({
163
168
  role: z.literal("system"),
164
169
  content: z.string(),
165
170
  name: z.string().optional(),
171
+ cacheControl: z
172
+ .object({
173
+ type: z.literal("ephemeral"),
174
+ ttl: z.union([z.literal("5m"), z.literal("1h")]).optional(),
175
+ })
176
+ .optional(),
166
177
  });
167
178
  const userChatMessageSchema = z.object({
168
179
  role: z.literal("user"),
169
180
  content: z.string(),
170
181
  name: z.string().optional(),
182
+ cacheControl: z
183
+ .object({
184
+ type: z.literal("ephemeral"),
185
+ ttl: z.union([z.literal("5m"), z.literal("1h")]).optional(),
186
+ })
187
+ .optional(),
171
188
  });
172
189
  const chatModelOutputToolCallSchema = z.object({
173
190
  id: z.string(),
@@ -182,6 +199,12 @@ const agentChatMessageSchema = z.object({
182
199
  content: z.string().optional(),
183
200
  toolCalls: z.array(chatModelOutputToolCallSchema).optional(),
184
201
  name: z.string().optional(),
202
+ cacheControl: z
203
+ .object({
204
+ type: z.literal("ephemeral"),
205
+ ttl: z.union([z.literal("5m"), z.literal("1h")]).optional(),
206
+ })
207
+ .optional(),
185
208
  });
186
209
  const toolChatMessageSchema = z.object({
187
210
  role: z.literal("tool"),
@@ -190,6 +213,12 @@ const toolChatMessageSchema = z.object({
190
213
  .transform((val) => (typeof val !== "string" ? JSON.stringify(val) : val)),
191
214
  toolCallId: z.string(),
192
215
  name: z.string().optional(),
216
+ cacheControl: z
217
+ .object({
218
+ type: z.literal("ephemeral"),
219
+ ttl: z.union([z.literal("5m"), z.literal("1h")]).optional(),
220
+ })
221
+ .optional(),
193
222
  });
194
223
  const chatMessageSchema = z.union([
195
224
  systemChatMessageSchema,
@@ -208,13 +237,13 @@ export function parseChatMessages(messages) {
208
237
  return messages.map((message) => {
209
238
  switch (message.role) {
210
239
  case "system":
211
- return SystemMessageTemplate.from(message.content, message.name, message.options);
240
+ return SystemMessageTemplate.from(message.content, message.name, message.options, message.cacheControl);
212
241
  case "user":
213
- return UserMessageTemplate.from(message.content, message.name, message.options);
242
+ return UserMessageTemplate.from(message.content, message.name, message.options, message.cacheControl);
214
243
  case "agent":
215
- return AgentMessageTemplate.from(message.content, message.toolCalls, message.name, message.options);
244
+ return AgentMessageTemplate.from(message.content, message.toolCalls, message.name, message.options, message.cacheControl);
216
245
  case "tool":
217
- return ToolMessageTemplate.from(message.content, message.toolCallId, message.name, message.options);
246
+ return ToolMessageTemplate.from(message.content, message.toolCallId, message.name, message.options, message.cacheControl);
218
247
  }
219
248
  });
220
249
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/core",
3
- "version": "1.72.0-beta.1",
3
+ "version": "1.72.0-beta.3",
4
4
  "description": "The functional core of agentic AI",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -92,10 +92,10 @@
92
92
  "zod": "^3.25.67",
93
93
  "zod-from-json-schema": "^0.0.5",
94
94
  "zod-to-json-schema": "^3.24.6",
95
- "@aigne/afs": "^1.4.0-beta.1",
96
- "@aigne/afs-history": "^1.2.0-beta.1",
97
- "@aigne/observability-api": "^0.11.14-beta",
98
- "@aigne/platform-helpers": "^0.6.7-beta"
95
+ "@aigne/afs": "^1.4.0-beta.2",
96
+ "@aigne/platform-helpers": "^0.6.7-beta",
97
+ "@aigne/observability-api": "^0.11.14-beta.1",
98
+ "@aigne/afs-history": "^1.2.0-beta.2"
99
99
  },
100
100
  "devDependencies": {
101
101
  "@types/bun": "^1.2.22",