@aigne/core 1.72.0-beta.2 → 1.72.0-beta.4

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 (105) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/lib/cjs/agents/agent.d.ts +31 -1
  3. package/lib/cjs/agents/agent.js +13 -0
  4. package/lib/cjs/agents/ai-agent.d.ts +7 -0
  5. package/lib/cjs/agents/ai-agent.js +85 -3
  6. package/lib/cjs/agents/chat-model.d.ts +153 -0
  7. package/lib/cjs/agents/chat-model.js +35 -1
  8. package/lib/cjs/agents/image-agent.d.ts +17 -1
  9. package/lib/cjs/agents/image-agent.js +16 -0
  10. package/lib/cjs/agents/image-model.d.ts +14 -4
  11. package/lib/cjs/agents/mcp-agent.d.ts +17 -0
  12. package/lib/cjs/agents/mcp-agent.js +18 -0
  13. package/lib/cjs/agents/team-agent.d.ts +55 -0
  14. package/lib/cjs/agents/team-agent.js +31 -0
  15. package/lib/cjs/agents/transform-agent.d.ts +12 -0
  16. package/lib/cjs/agents/transform-agent.js +13 -0
  17. package/lib/cjs/agents/video-model.d.ts +14 -4
  18. package/lib/cjs/aigne/usage.d.ts +4 -0
  19. package/lib/cjs/aigne/usage.js +6 -0
  20. package/lib/cjs/loader/agent-yaml.d.ts +5 -63
  21. package/lib/cjs/loader/agent-yaml.js +4 -129
  22. package/lib/cjs/loader/agents.d.ts +4 -0
  23. package/lib/cjs/loader/agents.js +17 -0
  24. package/lib/cjs/loader/index.d.ts +18 -14
  25. package/lib/cjs/loader/index.js +20 -81
  26. package/lib/cjs/loader/schema.d.ts +21 -6
  27. package/lib/cjs/loader/schema.js +60 -1
  28. package/lib/cjs/prompt/prompt-builder.js +0 -1
  29. package/lib/cjs/prompt/skills/afs/agent-skill/agent-skill.d.ts +17 -0
  30. package/lib/cjs/prompt/skills/afs/agent-skill/agent-skill.js +63 -0
  31. package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.d.ts +13 -0
  32. package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.js +61 -0
  33. package/lib/cjs/prompt/skills/afs/delete.js +15 -3
  34. package/lib/cjs/prompt/skills/afs/edit.js +30 -7
  35. package/lib/cjs/prompt/skills/afs/exec.js +17 -6
  36. package/lib/cjs/prompt/skills/afs/index.js +4 -1
  37. package/lib/cjs/prompt/skills/afs/list.js +26 -10
  38. package/lib/cjs/prompt/skills/afs/read.js +14 -3
  39. package/lib/cjs/prompt/skills/afs/rename.js +18 -4
  40. package/lib/cjs/prompt/skills/afs/search.js +21 -5
  41. package/lib/cjs/prompt/skills/afs/write.js +18 -4
  42. package/lib/cjs/prompt/template.d.ts +92 -17
  43. package/lib/cjs/prompt/template.js +46 -17
  44. package/lib/dts/agents/agent.d.ts +31 -1
  45. package/lib/dts/agents/ai-agent.d.ts +7 -0
  46. package/lib/dts/agents/chat-model.d.ts +153 -0
  47. package/lib/dts/agents/image-agent.d.ts +17 -1
  48. package/lib/dts/agents/image-model.d.ts +14 -4
  49. package/lib/dts/agents/mcp-agent.d.ts +17 -0
  50. package/lib/dts/agents/team-agent.d.ts +55 -0
  51. package/lib/dts/agents/transform-agent.d.ts +12 -0
  52. package/lib/dts/agents/video-model.d.ts +14 -4
  53. package/lib/dts/aigne/context.d.ts +2 -2
  54. package/lib/dts/aigne/usage.d.ts +4 -0
  55. package/lib/dts/loader/agent-yaml.d.ts +5 -63
  56. package/lib/dts/loader/agents.d.ts +4 -0
  57. package/lib/dts/loader/index.d.ts +18 -14
  58. package/lib/dts/loader/schema.d.ts +21 -6
  59. package/lib/dts/prompt/skills/afs/agent-skill/agent-skill.d.ts +17 -0
  60. package/lib/dts/prompt/skills/afs/agent-skill/skill-loader.d.ts +13 -0
  61. package/lib/dts/prompt/template.d.ts +92 -17
  62. package/lib/esm/agents/agent.d.ts +31 -1
  63. package/lib/esm/agents/agent.js +13 -0
  64. package/lib/esm/agents/ai-agent.d.ts +7 -0
  65. package/lib/esm/agents/ai-agent.js +85 -3
  66. package/lib/esm/agents/chat-model.d.ts +153 -0
  67. package/lib/esm/agents/chat-model.js +34 -0
  68. package/lib/esm/agents/image-agent.d.ts +17 -1
  69. package/lib/esm/agents/image-agent.js +16 -0
  70. package/lib/esm/agents/image-model.d.ts +14 -4
  71. package/lib/esm/agents/mcp-agent.d.ts +17 -0
  72. package/lib/esm/agents/mcp-agent.js +18 -0
  73. package/lib/esm/agents/team-agent.d.ts +55 -0
  74. package/lib/esm/agents/team-agent.js +31 -0
  75. package/lib/esm/agents/transform-agent.d.ts +12 -0
  76. package/lib/esm/agents/transform-agent.js +13 -0
  77. package/lib/esm/agents/video-model.d.ts +14 -4
  78. package/lib/esm/aigne/context.d.ts +2 -2
  79. package/lib/esm/aigne/usage.d.ts +4 -0
  80. package/lib/esm/aigne/usage.js +6 -0
  81. package/lib/esm/loader/agent-yaml.d.ts +5 -63
  82. package/lib/esm/loader/agent-yaml.js +4 -128
  83. package/lib/esm/loader/agents.d.ts +4 -0
  84. package/lib/esm/loader/agents.js +14 -0
  85. package/lib/esm/loader/index.d.ts +18 -14
  86. package/lib/esm/loader/index.js +21 -81
  87. package/lib/esm/loader/schema.d.ts +21 -6
  88. package/lib/esm/loader/schema.js +57 -0
  89. package/lib/esm/prompt/prompt-builder.js +1 -2
  90. package/lib/esm/prompt/skills/afs/agent-skill/agent-skill.d.ts +17 -0
  91. package/lib/esm/prompt/skills/afs/agent-skill/agent-skill.js +59 -0
  92. package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.d.ts +13 -0
  93. package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.js +53 -0
  94. package/lib/esm/prompt/skills/afs/delete.js +15 -3
  95. package/lib/esm/prompt/skills/afs/edit.js +30 -7
  96. package/lib/esm/prompt/skills/afs/exec.js +17 -6
  97. package/lib/esm/prompt/skills/afs/index.js +4 -1
  98. package/lib/esm/prompt/skills/afs/list.js +26 -10
  99. package/lib/esm/prompt/skills/afs/read.js +14 -3
  100. package/lib/esm/prompt/skills/afs/rename.js +18 -4
  101. package/lib/esm/prompt/skills/afs/search.js +21 -5
  102. package/lib/esm/prompt/skills/afs/write.js +18 -4
  103. package/lib/esm/prompt/template.d.ts +92 -17
  104. package/lib/esm/prompt/template.js +46 -17
  105. package/package.json +5 -4
@@ -7,14 +7,25 @@ class AFSExecAgent extends base_js_1.AFSSkillBase {
7
7
  constructor(options) {
8
8
  super({
9
9
  name: "afs_exec",
10
- description: `
11
- Execute files marked as executable in the Agentic File System (AFS).
12
- Use this to run executable files registered at a given path with specified arguments.
13
- `.trim(),
10
+ description: `Execute files marked as executable in the Agentic File System (AFS)
11
+ - Runs executable entries (functions, agents, skills) registered at a given AFS path
12
+ - Passes arguments to the executable and returns its output
13
+ - Use this to invoke dynamic functionality stored in AFS
14
+
15
+ Usage:
16
+ - The path must be an absolute AFS path to an executable entry (e.g., "/skills/summarize", "/agents/translator")
17
+ - This is NOT a local system file path - it operates within the AFS virtual file system
18
+ - Use afs_list to discover available executables (look for entries with execute metadata)
19
+ - Arguments must be a valid JSON string matching the executable's input schema
20
+ - The executable's input/output schema can be found in its metadata`,
14
21
  ...options,
15
22
  inputSchema: zod_1.z.object({
16
- path: zod_1.z.string().describe("Absolute path to the executable file in AFS"),
17
- args: zod_1.z.string().describe("JSON string of arguments matching the function's input schema"),
23
+ path: zod_1.z
24
+ .string()
25
+ .describe("Absolute AFS path to the executable (e.g., '/skills/summarize'). Must start with '/'"),
26
+ args: zod_1.z
27
+ .string()
28
+ .describe('JSON string of arguments matching the executable\'s input schema (e.g., \'{"text": "hello"}\')'),
18
29
  }),
19
30
  outputSchema: zod_1.z.object({
20
31
  data: zod_1.z.record(zod_1.z.any()),
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getAFSSkills = getAFSSkills;
4
+ const type_utils_js_1 = require("../../../utils/type-utils.js");
5
+ const skill_loader_js_1 = require("./agent-skill/skill-loader.js");
4
6
  const delete_js_1 = require("./delete.js");
5
7
  const edit_js_1 = require("./edit.js");
6
8
  const exec_js_1 = require("./exec.js");
@@ -19,5 +21,6 @@ async function getAFSSkills(afs) {
19
21
  new delete_js_1.AFSDeleteAgent({ afs }),
20
22
  new rename_js_1.AFSRenameAgent({ afs }),
21
23
  new exec_js_1.AFSExecAgent({ afs }),
22
- ];
24
+ await (0, skill_loader_js_1.loadAgentSkillFromAFS)({ afs }),
25
+ ].filter(type_utils_js_1.isNonNullable);
23
26
  }
@@ -7,26 +7,42 @@ class AFSListAgent extends base_js_1.AFSSkillBase {
7
7
  constructor(options) {
8
8
  super({
9
9
  name: "afs_list",
10
- description: "Browse directory structure as a tree view. Use when exploring directory contents or understanding file organization.",
10
+ description: `List contents within the Agentic File System (AFS)
11
+ - Returns files and directories at the specified AFS path
12
+ - Supports recursive listing with configurable depth
13
+ - Supports glob pattern filtering to match specific files
14
+ - By default respects .gitignore rules to filter out ignored files
15
+ - Use this tool when you need to explore AFS contents or understand file organization
16
+
17
+ Usage:
18
+ - The path must be an absolute AFS path starting with "/" (e.g., "/", "/docs", "/memory/user")
19
+ - This is NOT a local system file path - it operates within the AFS virtual file system
20
+ - Use maxDepth to control recursion depth (default: 1, current directory only)
21
+ - Use pattern to filter entries by glob pattern:
22
+ - "*.ts" - match TypeScript files in current directory
23
+ - "**/*.js" - match all JavaScript files recursively
24
+ - "src/**/*.{ts,tsx}" - match TypeScript files in src directory
25
+ - Results are filtered by .gitignore by default; set disableGitignore to include ignored files`,
11
26
  ...options,
12
27
  inputSchema: zod_1.z.object({
13
- path: zod_1.z.string().describe("Absolute directory path to browse"),
28
+ path: zod_1.z
29
+ .string()
30
+ .describe("Absolute AFS path to list (e.g., '/', '/docs', '/memory/user'). Must start with '/'"),
14
31
  options: zod_1.z
15
32
  .object({
16
- maxDepth: zod_1.z.number().optional().describe("Tree depth limit (default: 1)"),
33
+ maxDepth: zod_1.z
34
+ .number()
35
+ .optional()
36
+ .describe("Maximum depth of directory recursion. 1 = current directory only, 2 = include subdirectories, etc. Default: 1"),
17
37
  disableGitignore: zod_1.z
18
38
  .boolean()
19
39
  .optional()
20
- .describe("Disable .gitignore filtering, default is enabled"),
40
+ .describe("Set to true to include files normally ignored by .gitignore rules. Default: false (respects .gitignore)"),
21
41
  maxChildren: zod_1.z
22
42
  .number()
23
43
  .optional()
24
- .describe("Maximum number of children to list per directory"),
25
- format: zod_1.z
26
- .union([zod_1.z.literal("simple-list"), zod_1.z.literal("tree")])
27
- .optional()
28
- .default("simple-list")
29
- .describe("Output format, either 'simple-list', or 'tree', default is 'simple-list'"),
44
+ .describe("Maximum number of entries to return per directory. Useful for large directories to avoid overwhelming output"),
45
+ pattern: zod_1.z.string().optional().describe("Glob pattern to filter entries by path"),
30
46
  })
31
47
  .optional(),
32
48
  }),
@@ -7,14 +7,25 @@ class AFSReadAgent extends base_js_1.AFSSkillBase {
7
7
  constructor(options) {
8
8
  super({
9
9
  name: "afs_read",
10
- description: "Read complete file contents. Use when you need to review, analyze, or understand file content before making changes.",
10
+ description: `Read file contents from the Agentic File System (AFS)
11
+ - Returns the complete content of a file at the specified AFS path
12
+ - Supports line numbers output for precise editing references
13
+ - Use this tool when you need to review, analyze, or understand file content
14
+
15
+ Usage:
16
+ - The path must be an absolute AFS path starting with "/" (e.g., "/docs/readme.md", "/memory/user/notes")
17
+ - This is NOT a local system file path - it operates within the AFS virtual file system
18
+ - IMPORTANT: You MUST set withLineNumbers to true before using afs_edit, as line numbers are required for precise edits
19
+ - Returns the file's content along with metadata (id, path, timestamps, etc.)`,
11
20
  ...options,
12
21
  inputSchema: zod_1.z.object({
13
- path: zod_1.z.string().describe("Absolute file path to read"),
22
+ path: zod_1.z
23
+ .string()
24
+ .describe("Absolute AFS path to the file to read (e.g., '/docs/readme.md'). Must start with '/'"),
14
25
  withLineNumbers: zod_1.z
15
26
  .boolean()
16
27
  .optional()
17
- .describe("Include line numbers in output (required when planning to edit the file)"),
28
+ .describe("MUST be set to true before using afs_edit. Adds line numbers to output (format: '1| line content')"),
18
29
  }),
19
30
  outputSchema: zod_1.z.object({
20
31
  status: zod_1.z.string(),
@@ -7,16 +7,30 @@ class AFSRenameAgent extends base_js_1.AFSSkillBase {
7
7
  constructor(options) {
8
8
  super({
9
9
  name: "afs_rename",
10
- description: "Rename or move files and directories. Use when reorganizing files, changing names, or moving to different locations.",
10
+ description: `Rename or move files and directories within the Agentic File System (AFS)
11
+ - Renames a file or directory to a new name
12
+ - Can also move files/directories to a different location
13
+ - Optionally overwrites existing files at the destination
14
+
15
+ Usage:
16
+ - Both paths must be absolute AFS paths starting with "/" (e.g., "/docs/old-name.md" -> "/docs/new-name.md")
17
+ - This is NOT a local system file path - it operates within the AFS virtual file system
18
+ - To move a file, specify a different directory in newPath (e.g., "/docs/file.md" -> "/archive/file.md")
19
+ - If newPath already exists, the operation will fail unless overwrite=true
20
+ - Moving directories moves all contents recursively`,
11
21
  ...options,
12
22
  inputSchema: zod_1.z.object({
13
- oldPath: zod_1.z.string().describe("Absolute current file or directory path"),
14
- newPath: zod_1.z.string().describe("Absolute new file or directory path"),
23
+ oldPath: zod_1.z
24
+ .string()
25
+ .describe("Current absolute AFS path (e.g., '/docs/old-name.md'). Must start with '/'"),
26
+ newPath: zod_1.z
27
+ .string()
28
+ .describe("New absolute AFS path (e.g., '/docs/new-name.md'). Must start with '/'"),
15
29
  overwrite: zod_1.z
16
30
  .boolean()
17
31
  .optional()
18
32
  .default(false)
19
- .describe("Overwrite if destination exists (default: false)"),
33
+ .describe("Set to true to overwrite if destination already exists. Default: false (fails if exists)"),
20
34
  }),
21
35
  outputSchema: zod_1.z.object({
22
36
  status: zod_1.z.string(),
@@ -7,18 +7,34 @@ class AFSSearchAgent extends base_js_1.AFSSkillBase {
7
7
  constructor(options) {
8
8
  super({
9
9
  name: "afs_search",
10
- description: "Search file contents by keywords. Use when finding files containing specific text or code patterns.",
10
+ description: `Search file contents within the Agentic File System (AFS)
11
+ - Searches for files containing specific text, keywords, or patterns
12
+ - Returns matching entries with their content and metadata
13
+ - Supports case-sensitive and case-insensitive search modes
14
+ - Use this tool when you need to find files by their content
15
+
16
+ Usage:
17
+ - The path must be an absolute AFS path starting with "/" (e.g., "/", "/docs", "/memory")
18
+ - This is NOT a local system file path - it operates within the AFS virtual file system
19
+ - The query can be keywords, phrases, or text patterns to search for
20
+ - Use limit to control the number of results returned
21
+ - Search is case-insensitive by default; set caseSensitive to true for exact case matching`,
11
22
  ...options,
12
23
  inputSchema: zod_1.z.object({
13
- path: zod_1.z.string().describe("Absolute directory path to search in"),
14
- query: zod_1.z.string().describe("Search keywords or patterns"),
24
+ path: zod_1.z
25
+ .string()
26
+ .describe("Absolute AFS path to search in (e.g., '/', '/docs', '/memory'). Must start with '/'"),
27
+ query: zod_1.z.string().describe("Text, keywords, or patterns to search for in file contents"),
15
28
  options: zod_1.z
16
29
  .object({
17
- limit: zod_1.z.number().optional().describe("Max results to return"),
30
+ limit: zod_1.z
31
+ .number()
32
+ .optional()
33
+ .describe("Maximum number of results to return. Useful for limiting output size"),
18
34
  caseSensitive: zod_1.z
19
35
  .boolean()
20
36
  .optional()
21
- .describe("Case-sensitive search (default: false)"),
37
+ .describe("Set to true for case-sensitive matching. Default: false (case-insensitive)"),
22
38
  })
23
39
  .optional(),
24
40
  }),
@@ -7,16 +7,30 @@ class AFSWriteAgent extends base_js_1.AFSSkillBase {
7
7
  constructor(options) {
8
8
  super({
9
9
  name: "afs_write",
10
- description: "Create new file or append content to existing file. Use when creating files, rewriting entire files, or appending to files.",
10
+ description: `Write or create files in the Agentic File System (AFS)
11
+ - Creates a new file or overwrites an existing file with the provided content
12
+ - Supports append mode to add content to the end of existing files
13
+ - Use this tool when creating new files or completely replacing file contents
14
+
15
+ Usage:
16
+ - The path must be an absolute AFS path starting with "/" (e.g., "/docs/new-file.md", "/memory/user/notes")
17
+ - This is NOT a local system file path - it operates within the AFS virtual file system
18
+ - By default, this tool overwrites the entire file content
19
+ - Use append mode to add content to the end of an existing file without replacing it
20
+ - For partial edits to existing files, prefer using afs_edit instead`,
11
21
  ...options,
12
22
  inputSchema: zod_1.z.object({
13
- path: zod_1.z.string().describe("Absolute file path to write"),
14
- content: zod_1.z.string().describe("Complete file content or content to append"),
23
+ path: zod_1.z
24
+ .string()
25
+ .describe("Absolute AFS path for the file to write (e.g., '/docs/new-file.md'). Must start with '/'"),
26
+ content: zod_1.z
27
+ .string()
28
+ .describe("The content to write to the file. In overwrite mode, this replaces the entire file"),
15
29
  append: zod_1.z
16
30
  .boolean()
17
31
  .optional()
18
32
  .default(false)
19
- .describe("Append mode: add content to end of file (default: false, overwrites file)"),
33
+ .describe("Set to true to append content to the end of an existing file. Default: false (overwrites entire file)"),
20
34
  }),
21
35
  outputSchema: zod_1.z.object({
22
36
  status: zod_1.z.string(),
@@ -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
- role: "agent" | "system" | "user" | "tool";
45
+ role: "system" | "user" | "agent" | "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
- role: "agent" | "system" | "user" | "tool";
57
+ role: "system" | "user" | "agent" | "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,25 +72,61 @@ 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
- role: "system";
74
86
  content: string;
87
+ role: "system";
88
+ cacheControl?: {
89
+ type: "ephemeral";
90
+ ttl?: "5m" | "1h" | undefined;
91
+ } | undefined;
75
92
  name?: string | undefined;
76
93
  }, {
77
- role: "system";
78
94
  content: string;
95
+ role: "system";
96
+ cacheControl?: {
97
+ type: "ephemeral";
98
+ ttl?: "5m" | "1h" | undefined;
99
+ } | undefined;
79
100
  name?: string | 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
- role: "user";
86
116
  content: string;
117
+ role: "user";
118
+ cacheControl?: {
119
+ type: "ephemeral";
120
+ ttl?: "5m" | "1h" | undefined;
121
+ } | undefined;
87
122
  name?: string | undefined;
88
123
  }, {
89
- role: "user";
90
124
  content: string;
125
+ role: "user";
126
+ cacheControl?: {
127
+ type: "ephemeral";
128
+ ttl?: "5m" | "1h" | undefined;
129
+ } | undefined;
91
130
  name?: string | undefined;
92
131
  }>, z.ZodObject<{
93
132
  role: z.ZodLiteral<"agent">;
@@ -121,10 +160,23 @@ 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
- name?: string | undefined;
127
175
  content?: string | undefined;
176
+ cacheControl?: {
177
+ type: "ephemeral";
178
+ ttl?: "5m" | "1h" | undefined;
179
+ } | undefined;
128
180
  toolCalls?: {
129
181
  function: {
130
182
  name: string;
@@ -133,10 +185,14 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
133
185
  type: "function";
134
186
  id: string;
135
187
  }[] | undefined;
188
+ name?: string | undefined;
136
189
  }, {
137
190
  role: "agent";
138
- name?: string | undefined;
139
191
  content?: string | undefined;
192
+ cacheControl?: {
193
+ type: "ephemeral";
194
+ ttl?: "5m" | "1h" | undefined;
195
+ } | undefined;
140
196
  toolCalls?: {
141
197
  function: {
142
198
  name: string;
@@ -145,20 +201,39 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
145
201
  type: "function";
146
202
  id: string;
147
203
  }[] | undefined;
204
+ name?: string | 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
- role: "tool";
155
221
  content: string;
222
+ role: "tool";
156
223
  toolCallId: string;
224
+ cacheControl?: {
225
+ type: "ephemeral";
226
+ ttl?: "5m" | "1h" | undefined;
227
+ } | undefined;
157
228
  name?: string | undefined;
158
229
  }, {
159
- role: "tool";
160
230
  content: string | Record<string, unknown>;
231
+ role: "tool";
161
232
  toolCallId: string;
233
+ cacheControl?: {
234
+ type: "ephemeral";
235
+ ttl?: "5m" | "1h" | undefined;
236
+ } | undefined;
162
237
  name?: string | undefined;
163
238
  }>]>;
164
239
  export declare function safeParseChatMessages(messages: unknown): ChatMessageTemplate[] | undefined;
@@ -80,11 +80,13 @@ class ChatMessageTemplate {
80
80
  content;
81
81
  name;
82
82
  options;
83
- constructor(role, content, name, options) {
83
+ cacheControl;
84
+ constructor(role, content, name, options, cacheControl) {
84
85
  this.role = role;
85
86
  this.content = content;
86
87
  this.name = name;
87
88
  this.options = options;
89
+ this.cacheControl = cacheControl;
88
90
  }
89
91
  async format(variables, options) {
90
92
  options = { ...this.options, ...(0, type_utils_js_1.omitBy)(options ?? {}, (v) => (0, type_utils_js_1.isNil)(v)) };
@@ -103,29 +105,30 @@ class ChatMessageTemplate {
103
105
  role: this.role,
104
106
  content,
105
107
  name: this.name,
108
+ cacheControl: this.cacheControl,
106
109
  };
107
110
  }
108
111
  }
109
112
  exports.ChatMessageTemplate = ChatMessageTemplate;
110
113
  class SystemMessageTemplate extends ChatMessageTemplate {
111
- static from(content, name, options) {
112
- return new SystemMessageTemplate("system", content, name, options);
114
+ static from(content, name, options, cacheControl) {
115
+ return new SystemMessageTemplate("system", content, name, options, cacheControl);
113
116
  }
114
117
  }
115
118
  exports.SystemMessageTemplate = SystemMessageTemplate;
116
119
  class UserMessageTemplate extends ChatMessageTemplate {
117
- static from(template, name, options) {
118
- return new UserMessageTemplate("user", template, name, options);
120
+ static from(template, name, options, cacheControl) {
121
+ return new UserMessageTemplate("user", template, name, options, cacheControl);
119
122
  }
120
123
  }
121
124
  exports.UserMessageTemplate = UserMessageTemplate;
122
125
  class AgentMessageTemplate extends ChatMessageTemplate {
123
126
  toolCalls;
124
- static from(template, toolCalls, name, options) {
125
- return new AgentMessageTemplate(template, toolCalls, name, options);
127
+ static from(template, toolCalls, name, options, cacheControl) {
128
+ return new AgentMessageTemplate(template, toolCalls, name, options, cacheControl);
126
129
  }
127
- constructor(content, toolCalls, name, options) {
128
- super("agent", content, name, options);
130
+ constructor(content, toolCalls, name, options, cacheControl) {
131
+ super("agent", content, name, options, cacheControl);
129
132
  this.toolCalls = toolCalls;
130
133
  }
131
134
  async format(_variables, _options) {
@@ -135,17 +138,18 @@ class AgentMessageTemplate extends ChatMessageTemplate {
135
138
  // NOTE: agent message should not rendered by template
136
139
  content: this.content,
137
140
  toolCalls: this.toolCalls,
141
+ cacheControl: this.cacheControl,
138
142
  };
139
143
  }
140
144
  }
141
145
  exports.AgentMessageTemplate = AgentMessageTemplate;
142
146
  class ToolMessageTemplate extends ChatMessageTemplate {
143
147
  toolCallId;
144
- static from(content, toolCallId, name, options) {
145
- return new ToolMessageTemplate(content, toolCallId, name, options);
148
+ static from(content, toolCallId, name, options, cacheControl) {
149
+ return new ToolMessageTemplate(content, toolCallId, name, options, cacheControl);
146
150
  }
147
- constructor(content, toolCallId, name, options) {
148
- super("tool", typeof content === "string" ? content : (0, yaml_1.stringify)(content), name, options);
151
+ constructor(content, toolCallId, name, options, cacheControl) {
152
+ super("tool", typeof content === "string" ? content : (0, yaml_1.stringify)(content), name, options, cacheControl);
149
153
  this.toolCallId = toolCallId;
150
154
  }
151
155
  async format(_variables, _options) {
@@ -155,6 +159,7 @@ class ToolMessageTemplate extends ChatMessageTemplate {
155
159
  // NOTE: tool result should not rendered by template
156
160
  content: this.content,
157
161
  toolCallId: this.toolCallId,
162
+ cacheControl: this.cacheControl,
158
163
  };
159
164
  }
160
165
  }
@@ -179,11 +184,23 @@ const systemChatMessageSchema = zod_1.z.object({
179
184
  role: zod_1.z.literal("system"),
180
185
  content: zod_1.z.string(),
181
186
  name: zod_1.z.string().optional(),
187
+ cacheControl: zod_1.z
188
+ .object({
189
+ type: zod_1.z.literal("ephemeral"),
190
+ ttl: zod_1.z.union([zod_1.z.literal("5m"), zod_1.z.literal("1h")]).optional(),
191
+ })
192
+ .optional(),
182
193
  });
183
194
  const userChatMessageSchema = zod_1.z.object({
184
195
  role: zod_1.z.literal("user"),
185
196
  content: zod_1.z.string(),
186
197
  name: zod_1.z.string().optional(),
198
+ cacheControl: zod_1.z
199
+ .object({
200
+ type: zod_1.z.literal("ephemeral"),
201
+ ttl: zod_1.z.union([zod_1.z.literal("5m"), zod_1.z.literal("1h")]).optional(),
202
+ })
203
+ .optional(),
187
204
  });
188
205
  const chatModelOutputToolCallSchema = zod_1.z.object({
189
206
  id: zod_1.z.string(),
@@ -198,6 +215,12 @@ const agentChatMessageSchema = zod_1.z.object({
198
215
  content: zod_1.z.string().optional(),
199
216
  toolCalls: zod_1.z.array(chatModelOutputToolCallSchema).optional(),
200
217
  name: zod_1.z.string().optional(),
218
+ cacheControl: zod_1.z
219
+ .object({
220
+ type: zod_1.z.literal("ephemeral"),
221
+ ttl: zod_1.z.union([zod_1.z.literal("5m"), zod_1.z.literal("1h")]).optional(),
222
+ })
223
+ .optional(),
201
224
  });
202
225
  const toolChatMessageSchema = zod_1.z.object({
203
226
  role: zod_1.z.literal("tool"),
@@ -206,6 +229,12 @@ const toolChatMessageSchema = zod_1.z.object({
206
229
  .transform((val) => (typeof val !== "string" ? JSON.stringify(val) : val)),
207
230
  toolCallId: zod_1.z.string(),
208
231
  name: zod_1.z.string().optional(),
232
+ cacheControl: zod_1.z
233
+ .object({
234
+ type: zod_1.z.literal("ephemeral"),
235
+ ttl: zod_1.z.union([zod_1.z.literal("5m"), zod_1.z.literal("1h")]).optional(),
236
+ })
237
+ .optional(),
209
238
  });
210
239
  const chatMessageSchema = zod_1.z.union([
211
240
  systemChatMessageSchema,
@@ -224,13 +253,13 @@ function parseChatMessages(messages) {
224
253
  return messages.map((message) => {
225
254
  switch (message.role) {
226
255
  case "system":
227
- return SystemMessageTemplate.from(message.content, message.name, message.options);
256
+ return SystemMessageTemplate.from(message.content, message.name, message.options, message.cacheControl);
228
257
  case "user":
229
- return UserMessageTemplate.from(message.content, message.name, message.options);
258
+ return UserMessageTemplate.from(message.content, message.name, message.options, message.cacheControl);
230
259
  case "agent":
231
- return AgentMessageTemplate.from(message.content, message.toolCalls, message.name, message.options);
260
+ return AgentMessageTemplate.from(message.content, message.toolCalls, message.name, message.options, message.cacheControl);
232
261
  case "tool":
233
- return ToolMessageTemplate.from(message.content, message.toolCallId, message.name, message.options);
262
+ return ToolMessageTemplate.from(message.content, message.toolCallId, message.name, message.options, message.cacheControl);
234
263
  }
235
264
  });
236
265
  }
@@ -1,7 +1,7 @@
1
1
  import { AFS, type AFSExecOptions, type AFSExecResult, type AFSListOptions, type AFSListResult, type AFSModule, type AFSOptions, type AFSReadResult, type AFSSearchOptions } from "@aigne/afs";
2
2
  import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
3
3
  import type * as prompts from "@inquirer/prompts";
4
- import { type ZodObject, type ZodType } from "zod";
4
+ import { type ZodObject, type ZodType, z } from "zod";
5
5
  import type { AgentEvent, Context, UserContext } from "../aigne/context.js";
6
6
  import type { MessagePayload } from "../aigne/message-queue.js";
7
7
  import type { ContextUsage } from "../aigne/usage.js";
@@ -783,6 +783,25 @@ export interface AgentResponseProgress {
783
783
  } | {
784
784
  event: "agentFailed";
785
785
  error: Error;
786
+ } | {
787
+ event: "message";
788
+ role: "user" | "agent";
789
+ message: ({
790
+ type: "text";
791
+ content: string;
792
+ } | {
793
+ type: "thinking";
794
+ thoughts: string;
795
+ } | {
796
+ type: "tool_use";
797
+ toolUseId: string;
798
+ name: string;
799
+ input: unknown;
800
+ } | {
801
+ type: "tool_result";
802
+ toolUseId: string;
803
+ content: unknown;
804
+ })[];
786
805
  }) & Omit<AgentEvent, "agent"> & {
787
806
  agent: {
788
807
  name: string;
@@ -870,6 +889,17 @@ export interface FunctionAgentOptions<I extends Message = Message, O extends Mes
870
889
  */
871
890
  export declare class FunctionAgent<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
872
891
  tag: string;
892
+ static schema(): ZodObject<{
893
+ process: ZodType<FunctionAgentFn>;
894
+ }, "strip", z.ZodTypeAny, {
895
+ process: FunctionAgentFn<any, any, FunctionAgent<any, any>>;
896
+ }, {
897
+ process: FunctionAgentFn<any, any, FunctionAgent<any, any>>;
898
+ }>;
899
+ static load<I extends Message = any, O extends Message = any>(options: {
900
+ filepath: string;
901
+ parsed: object;
902
+ }): Promise<Agent<I, O>>;
873
903
  /**
874
904
  * Create a function agent from a function or options
875
905
  *