@aigne/core 1.71.0-beta.4 → 1.71.0-beta.6

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 (67) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/lib/cjs/agents/agent.d.ts +3 -1
  3. package/lib/cjs/agents/agent.js +7 -1
  4. package/lib/cjs/agents/user-agent.js +1 -1
  5. package/lib/cjs/memory/recorder.js +1 -1
  6. package/lib/cjs/memory/retriever.js +1 -1
  7. package/lib/cjs/prompt/prompt-builder.js +3 -3
  8. package/lib/cjs/prompt/skills/afs/delete.d.ts +18 -0
  9. package/lib/cjs/prompt/skills/afs/delete.js +42 -0
  10. package/lib/cjs/prompt/skills/afs/edit.d.ts +26 -0
  11. package/lib/cjs/prompt/skills/afs/edit.js +98 -0
  12. package/lib/cjs/prompt/skills/afs/exec.d.ts +15 -0
  13. package/lib/cjs/prompt/skills/afs/exec.js +27 -0
  14. package/lib/cjs/prompt/skills/{afs.d.ts → afs/index.d.ts} +1 -1
  15. package/lib/cjs/prompt/skills/afs/index.js +23 -0
  16. package/lib/cjs/prompt/skills/afs/list.d.ts +22 -0
  17. package/lib/cjs/prompt/skills/afs/list.js +90 -0
  18. package/lib/cjs/prompt/skills/afs/read.d.ts +21 -0
  19. package/lib/cjs/prompt/skills/afs/read.js +53 -0
  20. package/lib/cjs/prompt/skills/afs/rename.d.ts +20 -0
  21. package/lib/cjs/prompt/skills/afs/rename.js +45 -0
  22. package/lib/cjs/prompt/skills/afs/search.d.ts +23 -0
  23. package/lib/cjs/prompt/skills/afs/search.js +55 -0
  24. package/lib/cjs/prompt/skills/afs/write.d.ts +19 -0
  25. package/lib/cjs/prompt/skills/afs/write.js +45 -0
  26. package/lib/cjs/utils/json-schema.d.ts +1 -0
  27. package/lib/cjs/utils/json-schema.js +6 -0
  28. package/lib/dts/agents/agent.d.ts +3 -1
  29. package/lib/dts/prompt/skills/afs/delete.d.ts +18 -0
  30. package/lib/dts/prompt/skills/afs/edit.d.ts +26 -0
  31. package/lib/dts/prompt/skills/afs/exec.d.ts +15 -0
  32. package/lib/dts/prompt/skills/{afs.d.ts → afs/index.d.ts} +1 -1
  33. package/lib/dts/prompt/skills/afs/list.d.ts +22 -0
  34. package/lib/dts/prompt/skills/afs/read.d.ts +21 -0
  35. package/lib/dts/prompt/skills/afs/rename.d.ts +20 -0
  36. package/lib/dts/prompt/skills/afs/search.d.ts +23 -0
  37. package/lib/dts/prompt/skills/afs/write.d.ts +19 -0
  38. package/lib/dts/utils/json-schema.d.ts +1 -0
  39. package/lib/esm/agents/agent.d.ts +3 -1
  40. package/lib/esm/agents/agent.js +8 -2
  41. package/lib/esm/agents/user-agent.js +1 -1
  42. package/lib/esm/memory/recorder.js +1 -1
  43. package/lib/esm/memory/retriever.js +1 -1
  44. package/lib/esm/prompt/prompt-builder.js +1 -1
  45. package/lib/esm/prompt/skills/afs/delete.d.ts +18 -0
  46. package/lib/esm/prompt/skills/afs/delete.js +38 -0
  47. package/lib/esm/prompt/skills/afs/edit.d.ts +26 -0
  48. package/lib/esm/prompt/skills/afs/edit.js +94 -0
  49. package/lib/esm/prompt/skills/afs/exec.d.ts +15 -0
  50. package/lib/esm/prompt/skills/afs/exec.js +23 -0
  51. package/lib/esm/prompt/skills/{afs.d.ts → afs/index.d.ts} +1 -1
  52. package/lib/esm/prompt/skills/afs/index.js +20 -0
  53. package/lib/esm/prompt/skills/afs/list.d.ts +22 -0
  54. package/lib/esm/prompt/skills/afs/list.js +86 -0
  55. package/lib/esm/prompt/skills/afs/read.d.ts +21 -0
  56. package/lib/esm/prompt/skills/afs/read.js +49 -0
  57. package/lib/esm/prompt/skills/afs/rename.d.ts +20 -0
  58. package/lib/esm/prompt/skills/afs/rename.js +41 -0
  59. package/lib/esm/prompt/skills/afs/search.d.ts +23 -0
  60. package/lib/esm/prompt/skills/afs/search.js +51 -0
  61. package/lib/esm/prompt/skills/afs/write.d.ts +19 -0
  62. package/lib/esm/prompt/skills/afs/write.js +41 -0
  63. package/lib/esm/utils/json-schema.d.ts +1 -0
  64. package/lib/esm/utils/json-schema.js +5 -0
  65. package/package.json +3 -3
  66. package/lib/cjs/prompt/skills/afs.js +0 -177
  67. package/lib/esm/prompt/skills/afs.js +0 -174
package/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.71.0-beta.6](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.71.0-beta.5...core-v1.71.0-beta.6) (2025-12-11)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **orchestrator:** support custom input schema for planner/worker/completer ([#823](https://github.com/AIGNE-io/aigne-framework/issues/823)) ([3d26f8b](https://github.com/AIGNE-io/aigne-framework/commit/3d26f8bac8b679010f25d9e4eb59fc6e80afda4c))
9
+
10
+ ## [1.71.0-beta.5](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.71.0-beta.4...core-v1.71.0-beta.5) (2025-12-11)
11
+
12
+
13
+ ### Features
14
+
15
+ * **afs:** add edit/delete/rename methods for AFS ([#820](https://github.com/AIGNE-io/aigne-framework/issues/820)) ([68cb508](https://github.com/AIGNE-io/aigne-framework/commit/68cb508d1cfc9c516d56303018139f1e567f897e))
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * **core:** support access agent instance by `this` in function agent ([#822](https://github.com/AIGNE-io/aigne-framework/issues/822)) ([68103bc](https://github.com/AIGNE-io/aigne-framework/commit/68103bc8d6d553e1c1374595db98ff61f3046842))
21
+
22
+
23
+ ### Dependencies
24
+
25
+ * The following workspace dependencies were updated
26
+ * dependencies
27
+ * @aigne/afs bumped to 1.3.0-beta.3
28
+ * @aigne/afs-history bumped to 1.1.3-beta.3
29
+
3
30
  ## [1.71.0-beta.4](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.71.0-beta.3...core-v1.71.0-beta.4) (2025-12-10)
4
31
 
5
32
 
@@ -303,6 +303,7 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
303
303
  * @returns The Zod type definition for input data
304
304
  */
305
305
  get inputSchema(): ZodType<I>;
306
+ get inputKeys(): string[];
306
307
  /**
307
308
  * Get the output data schema for this agent
308
309
  *
@@ -312,6 +313,7 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
312
313
  * @returns The Zod type definition for output data
313
314
  */
314
315
  get outputSchema(): ZodType<O>;
316
+ get outputKeys(): string[];
315
317
  /**
316
318
  * Whether to include the original input in the output
317
319
  *
@@ -938,4 +940,4 @@ export declare class FunctionAgent<I extends Message = Message, O extends Messag
938
940
  * @param context Execution context
939
941
  * @returns Processing result, can be synchronous or asynchronous
940
942
  */
941
- export type FunctionAgentFn<I extends Message = any, O extends Message = any> = (input: I, options: AgentInvokeOptions) => PromiseOrValue<AgentProcessResult<O>>;
943
+ export type FunctionAgentFn<I extends Message = any, O extends Message = any, A extends FunctionAgent<I, O> = FunctionAgent<I, O>> = (this: A, input: I, options: AgentInvokeOptions) => PromiseOrValue<AgentProcessResult<O>>;
@@ -278,6 +278,9 @@ class Agent {
278
278
  checkAgentInputOutputSchema(schema);
279
279
  return schema.passthrough();
280
280
  }
281
+ get inputKeys() {
282
+ return (0, json_schema_js_1.getZodObjectKeys)(this.inputSchema);
283
+ }
281
284
  /**
282
285
  * Get the output data schema for this agent
283
286
  *
@@ -292,6 +295,9 @@ class Agent {
292
295
  checkAgentInputOutputSchema(schema);
293
296
  return schema.passthrough();
294
297
  }
298
+ get outputKeys() {
299
+ return (0, json_schema_js_1.getZodObjectKeys)(this.outputSchema);
300
+ }
295
301
  /**
296
302
  * Whether to include the original input in the output
297
303
  *
@@ -917,7 +923,7 @@ class FunctionAgent extends Agent {
917
923
  * @returns Processing result
918
924
  */
919
925
  process(input, options) {
920
- return this._process(input, options);
926
+ return this._process.apply(this, [input, options]);
921
927
  }
922
928
  }
923
929
  exports.FunctionAgent = FunctionAgent;
@@ -32,7 +32,7 @@ class UserAgent extends agent_js_1.Agent {
32
32
  });
33
33
  async process(input, options) {
34
34
  if (this._process) {
35
- return this._process(input, options);
35
+ return this._process.apply(this, [input, options]);
36
36
  }
37
37
  if (this.activeAgent) {
38
38
  const [output, agent] = await this.invokeChildAgent(this.activeAgent, input, {
@@ -57,7 +57,7 @@ class MemoryRecorder extends agent_js_1.Agent {
57
57
  if (!this._process) {
58
58
  throw new Error("MemoryRecorder process function is not defined.");
59
59
  }
60
- return this._process(input, options);
60
+ return this._process.apply(this, [input, options]);
61
61
  }
62
62
  }
63
63
  exports.MemoryRecorder = MemoryRecorder;
@@ -54,7 +54,7 @@ class MemoryRetriever extends agent_js_1.Agent {
54
54
  if (!this._process) {
55
55
  throw new Error("MemoryRetriever process function is not implemented.");
56
56
  }
57
- return this._process(input, options);
57
+ return this._process.apply(this, [input, options]);
58
58
  }
59
59
  }
60
60
  exports.MemoryRetriever = MemoryRetriever;
@@ -15,7 +15,7 @@ const type_utils_js_1 = require("../utils/type-utils.js");
15
15
  const afs_builtin_prompt_js_1 = require("./prompts/afs-builtin-prompt.js");
16
16
  const memory_message_template_js_1 = require("./prompts/memory-message-template.js");
17
17
  const structured_stream_instructions_js_1 = require("./prompts/structured-stream-instructions.js");
18
- const afs_js_1 = require("./skills/afs.js");
18
+ const index_js_2 = require("./skills/afs/index.js");
19
19
  const template_js_1 = require("./template.js");
20
20
  class PromptBuilder {
21
21
  static from(instructions, { workingDir } = {}) {
@@ -117,7 +117,7 @@ class PromptBuilder {
117
117
  const afs = options.agent?.afs;
118
118
  if (!afs)
119
119
  return [];
120
- return (0, afs_js_1.getAFSSkills)(afs).then((skills) => skills.map((s) => (0, type_utils_js_1.pick)(s, ["name", "description"])));
120
+ return (0, index_js_2.getAFSSkills)(afs).then((skills) => skills.map((s) => (0, type_utils_js_1.pick)(s, ["name", "description"])));
121
121
  },
122
122
  },
123
123
  $agent: {
@@ -364,7 +364,7 @@ class PromptBuilder {
364
364
  .concat(options.agent?.memoryAgentsAsTools ? options.agent.memories : [])
365
365
  .flatMap((i) => (i.isInvokable ? i : i.skills)), (i) => i.name);
366
366
  if (options.agent?.afs) {
367
- toolAgents.push(...(await (0, afs_js_1.getAFSSkills)(options.agent.afs)));
367
+ toolAgents.push(...(await (0, index_js_2.getAFSSkills)(options.agent.afs)));
368
368
  }
369
369
  const tools = toolAgents.map((i) => ({
370
370
  type: "function",
@@ -0,0 +1,18 @@
1
+ import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from "../../../agents/agent.js";
2
+ export interface AFSDeleteInput extends Message {
3
+ path: string;
4
+ recursive?: boolean;
5
+ }
6
+ export interface AFSDeleteOutput extends Message {
7
+ status: string;
8
+ tool: string;
9
+ path: string;
10
+ message?: string;
11
+ }
12
+ export interface AFSDeleteAgentOptions extends AgentOptions<AFSDeleteInput, AFSDeleteOutput> {
13
+ afs: NonNullable<AgentOptions<AFSDeleteInput, AFSDeleteOutput>["afs"]>;
14
+ }
15
+ export declare class AFSDeleteAgent extends Agent<AFSDeleteInput, AFSDeleteOutput> {
16
+ constructor(options: AFSDeleteAgentOptions);
17
+ process(input: AFSDeleteInput, _options: AgentInvokeOptions): Promise<AFSDeleteOutput>;
18
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AFSDeleteAgent = void 0;
4
+ const zod_1 = require("zod");
5
+ const agent_js_1 = require("../../../agents/agent.js");
6
+ class AFSDeleteAgent extends agent_js_1.Agent {
7
+ constructor(options) {
8
+ super({
9
+ name: "afs_delete",
10
+ description: "Permanently delete files or directories. Use when removing unwanted files or cleaning up temporary data.",
11
+ ...options,
12
+ inputSchema: zod_1.z.object({
13
+ path: zod_1.z.string().describe("Absolute file or directory path to delete"),
14
+ recursive: zod_1.z
15
+ .boolean()
16
+ .optional()
17
+ .default(false)
18
+ .describe("Allow directory deletion (default: false, required for directories)"),
19
+ }),
20
+ outputSchema: zod_1.z.object({
21
+ status: zod_1.z.string(),
22
+ tool: zod_1.z.string(),
23
+ path: zod_1.z.string(),
24
+ message: zod_1.z.string().optional(),
25
+ }),
26
+ });
27
+ }
28
+ async process(input, _options) {
29
+ if (!this.afs)
30
+ throw new Error("AFS is not configured for this agent.");
31
+ const result = await this.afs.delete(input.path, {
32
+ recursive: input.recursive ?? false,
33
+ });
34
+ return {
35
+ status: "success",
36
+ tool: "afs_delete",
37
+ path: input.path,
38
+ ...result,
39
+ };
40
+ }
41
+ }
42
+ exports.AFSDeleteAgent = AFSDeleteAgent;
@@ -0,0 +1,26 @@
1
+ import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from "../../../agents/agent.js";
2
+ export interface Patch {
3
+ start_line: number;
4
+ end_line: number;
5
+ replace?: string;
6
+ delete: boolean;
7
+ }
8
+ export interface AFSEditInput extends Message {
9
+ path: string;
10
+ patches: Patch[];
11
+ }
12
+ export interface AFSEditOutput extends Message {
13
+ status: string;
14
+ tool: string;
15
+ path: string;
16
+ message: string;
17
+ content: string;
18
+ }
19
+ export interface AFSEditAgentOptions extends AgentOptions<AFSEditInput, AFSEditOutput> {
20
+ afs: NonNullable<AgentOptions<AFSEditInput, AFSEditOutput>["afs"]>;
21
+ }
22
+ export declare class AFSEditAgent extends Agent<AFSEditInput, AFSEditOutput> {
23
+ constructor(options: AFSEditAgentOptions);
24
+ process(input: AFSEditInput, _options: AgentInvokeOptions): Promise<AFSEditOutput>;
25
+ applyCustomPatches(text: string, patches: Patch[]): string;
26
+ }
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AFSEditAgent = void 0;
4
+ const zod_1 = require("zod");
5
+ const agent_js_1 = require("../../../agents/agent.js");
6
+ class AFSEditAgent extends agent_js_1.Agent {
7
+ constructor(options) {
8
+ super({
9
+ name: "afs_edit",
10
+ description: "Apply precise line-based patches to modify file content. Use when making targeted changes without rewriting the entire file.",
11
+ ...options,
12
+ inputSchema: zod_1.z.object({
13
+ path: zod_1.z.string().describe("Absolute file path to edit"),
14
+ patches: zod_1.z
15
+ .array(zod_1.z.object({
16
+ start_line: zod_1.z.number().int().describe("Start line number (0-based, inclusive)"),
17
+ end_line: zod_1.z.number().int().describe("End line number (0-based, exclusive)"),
18
+ replace: zod_1.z.string().optional().describe("New content to replace the line range"),
19
+ delete: zod_1.z.boolean().describe("Delete mode: true to delete lines, false to replace"),
20
+ }))
21
+ .min(1)
22
+ .describe("List of patches to apply sequentially"),
23
+ }),
24
+ outputSchema: zod_1.z.object({
25
+ status: zod_1.z.string(),
26
+ tool: zod_1.z.string(),
27
+ path: zod_1.z.string(),
28
+ message: zod_1.z.string(),
29
+ content: zod_1.z.string(),
30
+ }),
31
+ });
32
+ }
33
+ async process(input, _options) {
34
+ if (!this.afs)
35
+ throw new Error("AFS is not configured for this agent.");
36
+ if (!input.patches?.length) {
37
+ throw new Error("No patches provided for afs_edit.");
38
+ }
39
+ const readResult = await this.afs.read(input.path);
40
+ if (!readResult.result?.content || typeof readResult.result.content !== "string") {
41
+ throw new Error(`Cannot read file content from: ${input.path}`);
42
+ }
43
+ const originalContent = readResult.result.content;
44
+ const updatedContent = this.applyCustomPatches(originalContent, input.patches);
45
+ await this.afs.write(input.path, {
46
+ content: updatedContent,
47
+ });
48
+ return {
49
+ status: "success",
50
+ tool: "afs_edit",
51
+ path: input.path,
52
+ message: `Applied ${input.patches.length} patches to ${input.path}`,
53
+ content: updatedContent,
54
+ };
55
+ }
56
+ applyCustomPatches(text, patches) {
57
+ // Sort by start_line to ensure sequential application
58
+ const sorted = [...patches].sort((a, b) => a.start_line - b.start_line);
59
+ const lines = text.split("\n");
60
+ for (let i = 0; i < sorted.length; i++) {
61
+ const patch = sorted[i];
62
+ if (!patch)
63
+ continue;
64
+ const start = patch.start_line;
65
+ const end = patch.end_line;
66
+ const deleteCount = end - start; // [start, end) range
67
+ let delta = 0;
68
+ if (patch.delete) {
69
+ // Delete mode: remove the specified lines [start, end)
70
+ lines.splice(start, deleteCount);
71
+ delta = -deleteCount;
72
+ }
73
+ else {
74
+ // Replace mode: replace the specified lines with new content
75
+ const replaceLines = patch.replace ? patch.replace.split("\n") : [];
76
+ lines.splice(start, deleteCount, ...replaceLines);
77
+ delta = replaceLines.length - deleteCount;
78
+ }
79
+ // Update subsequent patches' line numbers
80
+ // For exclusive-end semantics [start, end), we adjust patches that start >= current patch's start_line
81
+ // after the current patch has been applied
82
+ if (delta !== 0) {
83
+ for (let j = i + 1; j < sorted.length; j++) {
84
+ const next = sorted[j];
85
+ if (!next)
86
+ continue;
87
+ // Adjust patches that start at or after the current patch's end line
88
+ if (next.start_line >= patch.end_line) {
89
+ next.start_line += delta;
90
+ next.end_line += delta;
91
+ }
92
+ }
93
+ }
94
+ }
95
+ return lines.join("\n");
96
+ }
97
+ }
98
+ exports.AFSEditAgent = AFSEditAgent;
@@ -0,0 +1,15 @@
1
+ import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from "../../../agents/agent.js";
2
+ export interface AFSExecInput extends Message {
3
+ path: string;
4
+ args: string;
5
+ }
6
+ export interface AFSExecOutput extends Message {
7
+ result: Record<string, any>;
8
+ }
9
+ export interface AFSExecAgentOptions extends AgentOptions<AFSExecInput, AFSExecOutput> {
10
+ afs: NonNullable<AgentOptions<AFSExecInput, AFSExecOutput>["afs"]>;
11
+ }
12
+ export declare class AFSExecAgent extends Agent<AFSExecInput, AFSExecOutput> {
13
+ constructor(options: AFSExecAgentOptions);
14
+ process(input: AFSExecInput, options: AgentInvokeOptions): Promise<AFSExecOutput>;
15
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AFSExecAgent = void 0;
4
+ const zod_1 = require("zod");
5
+ const agent_js_1 = require("../../../agents/agent.js");
6
+ class AFSExecAgent extends agent_js_1.Agent {
7
+ constructor(options) {
8
+ super({
9
+ name: "afs_exec",
10
+ description: "Execute functions or commands from AFS modules. Use when running operations provided by mounted modules.",
11
+ ...options,
12
+ inputSchema: zod_1.z.object({
13
+ path: zod_1.z.string().describe("Absolute path to the executable function in AFS"),
14
+ args: zod_1.z.string().describe("JSON string of arguments matching the function's input schema"),
15
+ }),
16
+ outputSchema: zod_1.z.object({
17
+ result: zod_1.z.record(zod_1.z.any()),
18
+ }),
19
+ });
20
+ }
21
+ async process(input, options) {
22
+ if (!this.afs)
23
+ throw new Error("AFS is not configured for this agent.");
24
+ return await this.afs.exec(input.path, JSON.parse(input.args), options);
25
+ }
26
+ }
27
+ exports.AFSExecAgent = AFSExecAgent;
@@ -1,3 +1,3 @@
1
1
  import type { AFS } from "@aigne/afs";
2
- import { type Agent } from "../../agents/agent.js";
2
+ import type { Agent } from "../../../agents/agent.js";
3
3
  export declare function getAFSSkills(afs: AFS): Promise<Agent[]>;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAFSSkills = getAFSSkills;
4
+ const delete_js_1 = require("./delete.js");
5
+ const edit_js_1 = require("./edit.js");
6
+ const exec_js_1 = require("./exec.js");
7
+ const list_js_1 = require("./list.js");
8
+ const read_js_1 = require("./read.js");
9
+ const rename_js_1 = require("./rename.js");
10
+ const search_js_1 = require("./search.js");
11
+ const write_js_1 = require("./write.js");
12
+ async function getAFSSkills(afs) {
13
+ return [
14
+ new list_js_1.AFSListAgent({ afs }),
15
+ new search_js_1.AFSSearchAgent({ afs }),
16
+ new read_js_1.AFSReadAgent({ afs }),
17
+ new write_js_1.AFSWriteAgent({ afs }),
18
+ new edit_js_1.AFSEditAgent({ afs }),
19
+ new delete_js_1.AFSDeleteAgent({ afs }),
20
+ new rename_js_1.AFSRenameAgent({ afs }),
21
+ new exec_js_1.AFSExecAgent({ afs }),
22
+ ];
23
+ }
@@ -0,0 +1,22 @@
1
+ import type { AFSListOptions } from "@aigne/afs";
2
+ import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from "../../../agents/agent.js";
3
+ export interface AFSListInput extends Message {
4
+ path: string;
5
+ options?: AFSListOptions;
6
+ }
7
+ export interface AFSListOutput extends Message {
8
+ status: string;
9
+ tool: string;
10
+ path: string;
11
+ options?: AFSListOptions;
12
+ message?: string;
13
+ result: string;
14
+ }
15
+ export interface AFSListAgentOptions extends AgentOptions<AFSListInput, AFSListOutput> {
16
+ afs: NonNullable<AgentOptions<AFSListInput, AFSListOutput>["afs"]>;
17
+ }
18
+ export declare class AFSListAgent extends Agent<AFSListInput, AFSListOutput> {
19
+ constructor(options: AFSListAgentOptions);
20
+ process(input: AFSListInput, _options: AgentInvokeOptions): Promise<AFSListOutput>;
21
+ private buildTreeView;
22
+ }
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AFSListAgent = void 0;
4
+ const zod_1 = require("zod");
5
+ const agent_js_1 = require("../../../agents/agent.js");
6
+ class AFSListAgent extends agent_js_1.Agent {
7
+ constructor(options) {
8
+ super({
9
+ name: "afs_list",
10
+ description: "Browse directory structure as a tree view. Use when exploring directory contents or understanding file organization.",
11
+ ...options,
12
+ inputSchema: zod_1.z.object({
13
+ path: zod_1.z.string().describe("Absolute directory path to browse"),
14
+ options: zod_1.z
15
+ .object({
16
+ maxDepth: zod_1.z.number().optional().describe("Tree depth limit (default: 1)"),
17
+ })
18
+ .optional(),
19
+ }),
20
+ outputSchema: zod_1.z.object({
21
+ status: zod_1.z.string(),
22
+ tool: zod_1.z.string(),
23
+ path: zod_1.z.string(),
24
+ options: zod_1.z
25
+ .object({
26
+ maxDepth: zod_1.z.number().optional(),
27
+ })
28
+ .optional(),
29
+ message: zod_1.z.string().optional(),
30
+ result: zod_1.z.string(),
31
+ }),
32
+ });
33
+ }
34
+ async process(input, _options) {
35
+ if (!this.afs)
36
+ throw new Error("AFS is not configured for this agent.");
37
+ const { list, message } = await this.afs.list(input.path, input.options);
38
+ const result = this.buildTreeView(list);
39
+ return {
40
+ status: "success",
41
+ tool: "afs_list",
42
+ path: input.path,
43
+ options: input.options,
44
+ message,
45
+ result,
46
+ };
47
+ }
48
+ buildTreeView(entries) {
49
+ const tree = {};
50
+ const entryMap = new Map();
51
+ for (const entry of entries) {
52
+ entryMap.set(entry.path, entry);
53
+ const parts = entry.path.split("/").filter(Boolean);
54
+ let current = tree;
55
+ for (const part of parts) {
56
+ if (!current[part]) {
57
+ current[part] = {};
58
+ }
59
+ current = current[part];
60
+ }
61
+ }
62
+ const renderTree = (node, prefix = "", currentPath = "") => {
63
+ let result = "";
64
+ const keys = Object.keys(node);
65
+ keys.forEach((key, index) => {
66
+ const isLast = index === keys.length - 1;
67
+ const fullPath = currentPath ? `${currentPath}/${key}` : `/${key}`;
68
+ const entry = entryMap.get(fullPath);
69
+ // Build metadata suffix
70
+ const metadataParts = [];
71
+ // Children count
72
+ const childrenCount = entry?.metadata?.childrenCount;
73
+ if (childrenCount !== undefined && childrenCount > 0) {
74
+ metadataParts.push(`${childrenCount} items`);
75
+ }
76
+ // Executable
77
+ if (entry?.metadata?.execute) {
78
+ metadataParts.push("executable");
79
+ }
80
+ const metadataSuffix = metadataParts.length > 0 ? ` [${metadataParts.join(", ")}]` : "";
81
+ result += `${prefix}${isLast ? "└── " : "├── "}${key}${metadataSuffix}`;
82
+ result += `\n`;
83
+ result += renderTree(node[key], `${prefix}${isLast ? " " : "│ "}`, fullPath);
84
+ });
85
+ return result;
86
+ };
87
+ return renderTree(tree);
88
+ }
89
+ }
90
+ exports.AFSListAgent = AFSListAgent;
@@ -0,0 +1,21 @@
1
+ import type { AFSEntry } from "@aigne/afs";
2
+ import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from "../../../agents/agent.js";
3
+ export interface AFSReadInput extends Message {
4
+ path: string;
5
+ withLineNumbers?: boolean;
6
+ }
7
+ export interface AFSReadOutput extends Message {
8
+ status: string;
9
+ tool: string;
10
+ path: string;
11
+ withLineNumbers?: boolean;
12
+ result?: AFSEntry;
13
+ message?: string;
14
+ }
15
+ export interface AFSReadAgentOptions extends AgentOptions<AFSReadInput, AFSReadOutput> {
16
+ afs: NonNullable<AgentOptions<AFSReadInput, AFSReadOutput>["afs"]>;
17
+ }
18
+ export declare class AFSReadAgent extends Agent<AFSReadInput, AFSReadOutput> {
19
+ constructor(options: AFSReadAgentOptions);
20
+ process(input: AFSReadInput, _options: AgentInvokeOptions): Promise<AFSReadOutput>;
21
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AFSReadAgent = void 0;
4
+ const zod_1 = require("zod");
5
+ const agent_js_1 = require("../../../agents/agent.js");
6
+ class AFSReadAgent extends agent_js_1.Agent {
7
+ constructor(options) {
8
+ super({
9
+ name: "afs_read",
10
+ description: "Read complete file contents. Use when you need to review, analyze, or understand file content before making changes.",
11
+ ...options,
12
+ inputSchema: zod_1.z.object({
13
+ path: zod_1.z.string().describe("Absolute file path to read"),
14
+ withLineNumbers: zod_1.z
15
+ .boolean()
16
+ .optional()
17
+ .describe("Include line numbers in output (required when planning to edit the file)"),
18
+ }),
19
+ outputSchema: zod_1.z.object({
20
+ status: zod_1.z.string(),
21
+ tool: zod_1.z.string(),
22
+ path: zod_1.z.string(),
23
+ withLineNumbers: zod_1.z.boolean().optional(),
24
+ result: zod_1.z.custom().optional(),
25
+ message: zod_1.z.string().optional(),
26
+ }),
27
+ });
28
+ }
29
+ async process(input, _options) {
30
+ if (!this.afs)
31
+ throw new Error("AFS is not configured for this agent.");
32
+ const result = await this.afs.read(input.path);
33
+ let content = result.result?.content;
34
+ if (input.withLineNumbers && typeof content === "string") {
35
+ content = content
36
+ .split("\n")
37
+ .map((line, idx) => `${idx + 1}| ${line}`)
38
+ .join("\n");
39
+ }
40
+ return {
41
+ status: "success",
42
+ tool: "afs_read",
43
+ path: input.path,
44
+ withLineNumbers: input.withLineNumbers,
45
+ ...result,
46
+ result: result.result && {
47
+ ...result.result,
48
+ content,
49
+ },
50
+ };
51
+ }
52
+ }
53
+ exports.AFSReadAgent = AFSReadAgent;
@@ -0,0 +1,20 @@
1
+ import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from "../../../agents/agent.js";
2
+ export interface AFSRenameInput extends Message {
3
+ oldPath: string;
4
+ newPath: string;
5
+ overwrite?: boolean;
6
+ }
7
+ export interface AFSRenameOutput extends Message {
8
+ status: string;
9
+ tool: string;
10
+ oldPath: string;
11
+ newPath: string;
12
+ message?: string;
13
+ }
14
+ export interface AFSRenameAgentOptions extends AgentOptions<AFSRenameInput, AFSRenameOutput> {
15
+ afs: NonNullable<AgentOptions<AFSRenameInput, AFSRenameOutput>["afs"]>;
16
+ }
17
+ export declare class AFSRenameAgent extends Agent<AFSRenameInput, AFSRenameOutput> {
18
+ constructor(options: AFSRenameAgentOptions);
19
+ process(input: AFSRenameInput, _options: AgentInvokeOptions): Promise<AFSRenameOutput>;
20
+ }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AFSRenameAgent = void 0;
4
+ const zod_1 = require("zod");
5
+ const agent_js_1 = require("../../../agents/agent.js");
6
+ class AFSRenameAgent extends agent_js_1.Agent {
7
+ constructor(options) {
8
+ super({
9
+ name: "afs_rename",
10
+ description: "Rename or move files and directories. Use when reorganizing files, changing names, or moving to different locations.",
11
+ ...options,
12
+ 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"),
15
+ overwrite: zod_1.z
16
+ .boolean()
17
+ .optional()
18
+ .default(false)
19
+ .describe("Overwrite if destination exists (default: false)"),
20
+ }),
21
+ outputSchema: zod_1.z.object({
22
+ status: zod_1.z.string(),
23
+ tool: zod_1.z.string(),
24
+ oldPath: zod_1.z.string(),
25
+ newPath: zod_1.z.string(),
26
+ message: zod_1.z.string().optional(),
27
+ }),
28
+ });
29
+ }
30
+ async process(input, _options) {
31
+ if (!this.afs)
32
+ throw new Error("AFS is not configured for this agent.");
33
+ const result = await this.afs.rename(input.oldPath, input.newPath, {
34
+ overwrite: input.overwrite ?? false,
35
+ });
36
+ return {
37
+ status: "success",
38
+ tool: "afs_rename",
39
+ oldPath: input.oldPath,
40
+ newPath: input.newPath,
41
+ ...result,
42
+ };
43
+ }
44
+ }
45
+ exports.AFSRenameAgent = AFSRenameAgent;