@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
@@ -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,23 @@
1
+ import { z } from "zod";
2
+ import { Agent, } from "../../../agents/agent.js";
3
+ export class AFSExecAgent extends Agent {
4
+ constructor(options) {
5
+ super({
6
+ name: "afs_exec",
7
+ description: "Execute functions or commands from AFS modules. Use when running operations provided by mounted modules.",
8
+ ...options,
9
+ inputSchema: z.object({
10
+ path: z.string().describe("Absolute path to the executable function in AFS"),
11
+ args: z.string().describe("JSON string of arguments matching the function's input schema"),
12
+ }),
13
+ outputSchema: z.object({
14
+ result: z.record(z.any()),
15
+ }),
16
+ });
17
+ }
18
+ async process(input, options) {
19
+ if (!this.afs)
20
+ throw new Error("AFS is not configured for this agent.");
21
+ return await this.afs.exec(input.path, JSON.parse(input.args), options);
22
+ }
23
+ }
@@ -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,20 @@
1
+ import { AFSDeleteAgent } from "./delete.js";
2
+ import { AFSEditAgent } from "./edit.js";
3
+ import { AFSExecAgent } from "./exec.js";
4
+ import { AFSListAgent } from "./list.js";
5
+ import { AFSReadAgent } from "./read.js";
6
+ import { AFSRenameAgent } from "./rename.js";
7
+ import { AFSSearchAgent } from "./search.js";
8
+ import { AFSWriteAgent } from "./write.js";
9
+ export async function getAFSSkills(afs) {
10
+ return [
11
+ new AFSListAgent({ afs }),
12
+ new AFSSearchAgent({ afs }),
13
+ new AFSReadAgent({ afs }),
14
+ new AFSWriteAgent({ afs }),
15
+ new AFSEditAgent({ afs }),
16
+ new AFSDeleteAgent({ afs }),
17
+ new AFSRenameAgent({ afs }),
18
+ new AFSExecAgent({ afs }),
19
+ ];
20
+ }
@@ -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,86 @@
1
+ import { z } from "zod";
2
+ import { Agent, } from "../../../agents/agent.js";
3
+ export class AFSListAgent extends Agent {
4
+ constructor(options) {
5
+ super({
6
+ name: "afs_list",
7
+ description: "Browse directory structure as a tree view. Use when exploring directory contents or understanding file organization.",
8
+ ...options,
9
+ inputSchema: z.object({
10
+ path: z.string().describe("Absolute directory path to browse"),
11
+ options: z
12
+ .object({
13
+ maxDepth: z.number().optional().describe("Tree depth limit (default: 1)"),
14
+ })
15
+ .optional(),
16
+ }),
17
+ outputSchema: z.object({
18
+ status: z.string(),
19
+ tool: z.string(),
20
+ path: z.string(),
21
+ options: z
22
+ .object({
23
+ maxDepth: z.number().optional(),
24
+ })
25
+ .optional(),
26
+ message: z.string().optional(),
27
+ result: z.string(),
28
+ }),
29
+ });
30
+ }
31
+ async process(input, _options) {
32
+ if (!this.afs)
33
+ throw new Error("AFS is not configured for this agent.");
34
+ const { list, message } = await this.afs.list(input.path, input.options);
35
+ const result = this.buildTreeView(list);
36
+ return {
37
+ status: "success",
38
+ tool: "afs_list",
39
+ path: input.path,
40
+ options: input.options,
41
+ message,
42
+ result,
43
+ };
44
+ }
45
+ buildTreeView(entries) {
46
+ const tree = {};
47
+ const entryMap = new Map();
48
+ for (const entry of entries) {
49
+ entryMap.set(entry.path, entry);
50
+ const parts = entry.path.split("/").filter(Boolean);
51
+ let current = tree;
52
+ for (const part of parts) {
53
+ if (!current[part]) {
54
+ current[part] = {};
55
+ }
56
+ current = current[part];
57
+ }
58
+ }
59
+ const renderTree = (node, prefix = "", currentPath = "") => {
60
+ let result = "";
61
+ const keys = Object.keys(node);
62
+ keys.forEach((key, index) => {
63
+ const isLast = index === keys.length - 1;
64
+ const fullPath = currentPath ? `${currentPath}/${key}` : `/${key}`;
65
+ const entry = entryMap.get(fullPath);
66
+ // Build metadata suffix
67
+ const metadataParts = [];
68
+ // Children count
69
+ const childrenCount = entry?.metadata?.childrenCount;
70
+ if (childrenCount !== undefined && childrenCount > 0) {
71
+ metadataParts.push(`${childrenCount} items`);
72
+ }
73
+ // Executable
74
+ if (entry?.metadata?.execute) {
75
+ metadataParts.push("executable");
76
+ }
77
+ const metadataSuffix = metadataParts.length > 0 ? ` [${metadataParts.join(", ")}]` : "";
78
+ result += `${prefix}${isLast ? "└── " : "├── "}${key}${metadataSuffix}`;
79
+ result += `\n`;
80
+ result += renderTree(node[key], `${prefix}${isLast ? " " : "│ "}`, fullPath);
81
+ });
82
+ return result;
83
+ };
84
+ return renderTree(tree);
85
+ }
86
+ }
@@ -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,49 @@
1
+ import { z } from "zod";
2
+ import { Agent, } from "../../../agents/agent.js";
3
+ export class AFSReadAgent extends Agent {
4
+ constructor(options) {
5
+ super({
6
+ name: "afs_read",
7
+ description: "Read complete file contents. Use when you need to review, analyze, or understand file content before making changes.",
8
+ ...options,
9
+ inputSchema: z.object({
10
+ path: z.string().describe("Absolute file path to read"),
11
+ withLineNumbers: z
12
+ .boolean()
13
+ .optional()
14
+ .describe("Include line numbers in output (required when planning to edit the file)"),
15
+ }),
16
+ outputSchema: z.object({
17
+ status: z.string(),
18
+ tool: z.string(),
19
+ path: z.string(),
20
+ withLineNumbers: z.boolean().optional(),
21
+ result: z.custom().optional(),
22
+ message: z.string().optional(),
23
+ }),
24
+ });
25
+ }
26
+ async process(input, _options) {
27
+ if (!this.afs)
28
+ throw new Error("AFS is not configured for this agent.");
29
+ const result = await this.afs.read(input.path);
30
+ let content = result.result?.content;
31
+ if (input.withLineNumbers && typeof content === "string") {
32
+ content = content
33
+ .split("\n")
34
+ .map((line, idx) => `${idx + 1}| ${line}`)
35
+ .join("\n");
36
+ }
37
+ return {
38
+ status: "success",
39
+ tool: "afs_read",
40
+ path: input.path,
41
+ withLineNumbers: input.withLineNumbers,
42
+ ...result,
43
+ result: result.result && {
44
+ ...result.result,
45
+ content,
46
+ },
47
+ };
48
+ }
49
+ }
@@ -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,41 @@
1
+ import { z } from "zod";
2
+ import { Agent, } from "../../../agents/agent.js";
3
+ export class AFSRenameAgent extends Agent {
4
+ constructor(options) {
5
+ super({
6
+ name: "afs_rename",
7
+ description: "Rename or move files and directories. Use when reorganizing files, changing names, or moving to different locations.",
8
+ ...options,
9
+ inputSchema: z.object({
10
+ oldPath: z.string().describe("Absolute current file or directory path"),
11
+ newPath: z.string().describe("Absolute new file or directory path"),
12
+ overwrite: z
13
+ .boolean()
14
+ .optional()
15
+ .default(false)
16
+ .describe("Overwrite if destination exists (default: false)"),
17
+ }),
18
+ outputSchema: z.object({
19
+ status: z.string(),
20
+ tool: z.string(),
21
+ oldPath: z.string(),
22
+ newPath: z.string(),
23
+ message: z.string().optional(),
24
+ }),
25
+ });
26
+ }
27
+ async process(input, _options) {
28
+ if (!this.afs)
29
+ throw new Error("AFS is not configured for this agent.");
30
+ const result = await this.afs.rename(input.oldPath, input.newPath, {
31
+ overwrite: input.overwrite ?? false,
32
+ });
33
+ return {
34
+ status: "success",
35
+ tool: "afs_rename",
36
+ oldPath: input.oldPath,
37
+ newPath: input.newPath,
38
+ ...result,
39
+ };
40
+ }
41
+ }
@@ -0,0 +1,23 @@
1
+ import type { AFSEntry, AFSSearchOptions } from "@aigne/afs";
2
+ import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from "../../../agents/agent.js";
3
+ export interface AFSSearchInput extends Message {
4
+ path: string;
5
+ query: string;
6
+ options?: AFSSearchOptions;
7
+ }
8
+ export interface AFSSearchOutput extends Message {
9
+ status: string;
10
+ tool: string;
11
+ path: string;
12
+ query: string;
13
+ options?: AFSSearchOptions;
14
+ list: AFSEntry[];
15
+ message?: string;
16
+ }
17
+ export interface AFSSearchAgentOptions extends AgentOptions<AFSSearchInput, AFSSearchOutput> {
18
+ afs: NonNullable<AgentOptions<AFSSearchInput, AFSSearchOutput>["afs"]>;
19
+ }
20
+ export declare class AFSSearchAgent extends Agent<AFSSearchInput, AFSSearchOutput> {
21
+ constructor(options: AFSSearchAgentOptions);
22
+ process(input: AFSSearchInput, _options: AgentInvokeOptions): Promise<AFSSearchOutput>;
23
+ }
@@ -0,0 +1,51 @@
1
+ import { z } from "zod";
2
+ import { Agent, } from "../../../agents/agent.js";
3
+ export class AFSSearchAgent extends Agent {
4
+ constructor(options) {
5
+ super({
6
+ name: "afs_search",
7
+ description: "Search file contents by keywords. Use when finding files containing specific text or code patterns.",
8
+ ...options,
9
+ inputSchema: z.object({
10
+ path: z.string().describe("Absolute directory path to search in"),
11
+ query: z.string().describe("Search keywords or patterns"),
12
+ options: z
13
+ .object({
14
+ limit: z.number().optional().describe("Max results to return"),
15
+ caseSensitive: z
16
+ .boolean()
17
+ .optional()
18
+ .describe("Case-sensitive search (default: false)"),
19
+ })
20
+ .optional(),
21
+ }),
22
+ outputSchema: z.object({
23
+ status: z.string(),
24
+ tool: z.string(),
25
+ path: z.string(),
26
+ query: z.string(),
27
+ options: z
28
+ .object({
29
+ limit: z.number().optional(),
30
+ caseSensitive: z.boolean().optional(),
31
+ })
32
+ .optional(),
33
+ list: z.array(z.custom()),
34
+ message: z.string().optional(),
35
+ }),
36
+ });
37
+ }
38
+ async process(input, _options) {
39
+ if (!this.afs)
40
+ throw new Error("AFS is not configured for this agent.");
41
+ const result = await this.afs.search(input.path, input.query, input.options);
42
+ return {
43
+ status: "success",
44
+ tool: "afs_search",
45
+ path: input.path,
46
+ query: input.query,
47
+ options: input.options,
48
+ ...result,
49
+ };
50
+ }
51
+ }
@@ -0,0 +1,19 @@
1
+ import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from "../../../agents/agent.js";
2
+ export interface AFSWriteInput extends Message {
3
+ path: string;
4
+ content: string;
5
+ append?: boolean;
6
+ }
7
+ export interface AFSWriteOutput extends Message {
8
+ status: string;
9
+ tool: string;
10
+ path: string;
11
+ message?: string;
12
+ }
13
+ export interface AFSWriteAgentOptions extends AgentOptions<AFSWriteInput, AFSWriteOutput> {
14
+ afs: NonNullable<AgentOptions<AFSWriteInput, AFSWriteOutput>["afs"]>;
15
+ }
16
+ export declare class AFSWriteAgent extends Agent<AFSWriteInput, AFSWriteOutput> {
17
+ constructor(options: AFSWriteAgentOptions);
18
+ process(input: AFSWriteInput, _options: AgentInvokeOptions): Promise<AFSWriteOutput>;
19
+ }
@@ -0,0 +1,41 @@
1
+ import { z } from "zod";
2
+ import { Agent, } from "../../../agents/agent.js";
3
+ export class AFSWriteAgent extends Agent {
4
+ constructor(options) {
5
+ super({
6
+ name: "afs_write",
7
+ description: "Create new file or append content to existing file. Use when creating files, rewriting entire files, or appending to files.",
8
+ ...options,
9
+ inputSchema: z.object({
10
+ path: z.string().describe("Absolute file path to write"),
11
+ content: z.string().describe("Complete file content or content to append"),
12
+ append: z
13
+ .boolean()
14
+ .optional()
15
+ .default(false)
16
+ .describe("Append mode: add content to end of file (default: false, overwrites file)"),
17
+ }),
18
+ outputSchema: z.object({
19
+ status: z.string(),
20
+ tool: z.string(),
21
+ path: z.string(),
22
+ message: z.string().optional(),
23
+ }),
24
+ });
25
+ }
26
+ async process(input, _options) {
27
+ if (!this.afs)
28
+ throw new Error("AFS is not configured for this agent.");
29
+ const result = await this.afs.write(input.path, {
30
+ content: input.content,
31
+ }, {
32
+ append: input.append ?? false,
33
+ });
34
+ return {
35
+ status: "success",
36
+ tool: "afs_write",
37
+ path: input.path,
38
+ ...result,
39
+ };
40
+ }
41
+ }
@@ -12,3 +12,4 @@ export declare function parseJSON(json: string): any;
12
12
  export declare function ensureZodUnionArray<T extends z.ZodType>(union: T[]): [T, T, ...T[]];
13
13
  export declare function isZodSchema(schema: ZodType): schema is ZodType;
14
14
  export declare const wrapAutoParseJsonSchema: <T extends ZodType>(schema: T) => T;
15
+ export declare function getZodObjectKeys(schema: ZodType): string[];
@@ -107,3 +107,8 @@ export const wrapAutoParseJsonSchema = (schema) => {
107
107
  }
108
108
  return schema;
109
109
  };
110
+ export function getZodObjectKeys(schema) {
111
+ if ("shape" in schema && schema.shape)
112
+ return Object.keys(schema.shape);
113
+ return [];
114
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/core",
3
- "version": "1.71.0-beta.4",
3
+ "version": "1.71.0-beta.6",
4
4
  "description": "The functional core of agentic AI",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -92,9 +92,9 @@
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.3.0-beta.2",
96
- "@aigne/afs-history": "^1.1.3-beta.2",
95
+ "@aigne/afs": "^1.3.0-beta.3",
97
96
  "@aigne/platform-helpers": "^0.6.6-beta",
97
+ "@aigne/afs-history": "^1.1.3-beta.3",
98
98
  "@aigne/observability-api": "^0.11.13-beta.1"
99
99
  },
100
100
  "devDependencies": {
@@ -1,177 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAFSSkills = getAFSSkills;
4
- const zod_1 = require("zod");
5
- const agent_js_1 = require("../../agents/agent.js");
6
- async function getAFSSkills(afs) {
7
- return [
8
- agent_js_1.FunctionAgent.from({
9
- name: "afs_list",
10
- description: "Get a tree view of directory contents in the AFS - shows hierarchical structure of files and folders",
11
- inputSchema: zod_1.z.object({
12
- path: zod_1.z.string().describe("The directory path to browse (e.g., '/', '/docs', '/src')"),
13
- options: zod_1.z
14
- .object({
15
- maxDepth: zod_1.z.number().optional().describe("Maximum depth to display in the tree view"),
16
- })
17
- .optional(),
18
- }),
19
- process: async (input) => {
20
- const { list, message } = await afs.list(input.path, input.options);
21
- const result = buildTreeView(list);
22
- return {
23
- status: "success",
24
- tool: "afs_list",
25
- path: input.path,
26
- options: input.options,
27
- message,
28
- result,
29
- };
30
- },
31
- }),
32
- agent_js_1.FunctionAgent.from({
33
- name: "afs_search",
34
- description: "Find files by searching content using keywords - returns matching files with their paths",
35
- inputSchema: zod_1.z.object({
36
- path: zod_1.z.string().describe("The directory path to search in (e.g., '/', '/docs')"),
37
- query: zod_1.z
38
- .string()
39
- .describe("Keywords to search for in file contents (e.g., 'function authentication', 'database config')"),
40
- options: zod_1.z
41
- .object({
42
- limit: zod_1.z.number().optional().describe("Maximum number of entries to return"),
43
- caseSensitive: zod_1.z
44
- .boolean()
45
- .optional()
46
- .describe("Whether the search is case sensitive, default is false"),
47
- })
48
- .optional(),
49
- }),
50
- process: async (input) => {
51
- const result = await afs.search(input.path, input.query, input.options);
52
- return {
53
- status: "success",
54
- tool: "afs_search",
55
- path: input.path,
56
- query: input.query,
57
- options: input.options,
58
- ...result,
59
- };
60
- },
61
- }),
62
- agent_js_1.FunctionAgent.from({
63
- name: "afs_read",
64
- description: `\
65
- Read file contents from the AFS - path must be an exact file path from list or search results
66
-
67
- Usage:
68
- - Use withLineNumbers=true to get line numbers for code reviews or edits
69
- `,
70
- inputSchema: zod_1.z.object({
71
- path: zod_1.z
72
- .string()
73
- .describe("Exact file path from list or search results (e.g., '/docs/api.md', '/src/utils/helper.js')"),
74
- withLineNumbers: zod_1.z
75
- .boolean()
76
- .optional()
77
- .describe(`Whether to include line numbers in the returned content, default is false`),
78
- }),
79
- process: async (input) => {
80
- const result = await afs.read(input.path);
81
- let content = result.result?.content;
82
- if (input.withLineNumbers && typeof content === "string") {
83
- content = content
84
- .split("\n")
85
- .map((line, idx) => `${idx + 1}| ${line}`)
86
- .join("\n");
87
- }
88
- return {
89
- status: "success",
90
- tool: "afs_read",
91
- path: input.path,
92
- withLineNumbers: input.withLineNumbers,
93
- ...result,
94
- result: {
95
- ...result.result,
96
- content,
97
- },
98
- };
99
- },
100
- }),
101
- agent_js_1.FunctionAgent.from({
102
- name: "afs_write",
103
- description: "Create or update a file in the AFS with new content - overwrites existing files",
104
- inputSchema: zod_1.z.object({
105
- path: zod_1.z
106
- .string()
107
- .describe("Full file path where to write content (e.g., '/docs/new-file.md', '/src/component.js')"),
108
- content: zod_1.z.string().describe("The text content to write to the file"),
109
- }),
110
- process: async (input) => {
111
- const result = await afs.write(input.path, {
112
- content: input.content,
113
- });
114
- return {
115
- status: "success",
116
- tool: "afs_write",
117
- path: input.path,
118
- ...result,
119
- };
120
- },
121
- }),
122
- agent_js_1.FunctionAgent.from({
123
- name: "afs_exec",
124
- description: "Execute a function or command available in the AFS modules",
125
- inputSchema: zod_1.z.object({
126
- path: zod_1.z.string().describe("The exact path to the executable entry in AFS"),
127
- args: zod_1.z
128
- .string()
129
- .describe("JSON stringified arguments to pass to the executable, must be an object matching the input schema of the executable"),
130
- }),
131
- process: async ({ path, args }, options) => {
132
- return await afs.exec(path, JSON.parse(args), options);
133
- },
134
- }),
135
- ];
136
- }
137
- function buildTreeView(entries) {
138
- const tree = {};
139
- const entryMap = new Map();
140
- for (const entry of entries) {
141
- entryMap.set(entry.path, entry);
142
- const parts = entry.path.split("/").filter(Boolean);
143
- let current = tree;
144
- for (const part of parts) {
145
- if (!current[part]) {
146
- current[part] = {};
147
- }
148
- current = current[part];
149
- }
150
- }
151
- function renderTree(node, prefix = "", currentPath = "") {
152
- let result = "";
153
- const keys = Object.keys(node);
154
- keys.forEach((key, index) => {
155
- const isLast = index === keys.length - 1;
156
- const fullPath = currentPath ? `${currentPath}/${key}` : `/${key}`;
157
- const entry = entryMap.get(fullPath);
158
- // Build metadata suffix
159
- const metadataParts = [];
160
- // Children count
161
- const childrenCount = entry?.metadata?.childrenCount;
162
- if (childrenCount !== undefined && childrenCount > 0) {
163
- metadataParts.push(`${childrenCount} items`);
164
- }
165
- // Executable
166
- if (entry?.metadata?.execute) {
167
- metadataParts.push("executable");
168
- }
169
- const metadataSuffix = metadataParts.length > 0 ? ` [${metadataParts.join(", ")}]` : "";
170
- result += `${prefix}${isLast ? "└── " : "├── "}${key}${metadataSuffix}`;
171
- result += `\n`;
172
- result += renderTree(node[key], `${prefix}${isLast ? " " : "│ "}`, fullPath);
173
- });
174
- return result;
175
- }
176
- return renderTree(tree);
177
- }