@aigne/core 1.71.0-beta.2 → 1.71.0-beta.5
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.
- package/CHANGELOG.md +56 -0
- package/lib/cjs/agents/agent.d.ts +1 -1
- package/lib/cjs/agents/agent.js +1 -1
- package/lib/cjs/agents/user-agent.js +1 -1
- package/lib/cjs/aigne/aigne.d.ts +6 -1
- package/lib/cjs/aigne/aigne.js +13 -4
- package/lib/cjs/aigne/context.d.ts +2 -2
- package/lib/cjs/aigne/context.js +5 -22
- package/lib/cjs/loader/agent-js.d.ts +2 -1
- package/lib/cjs/loader/agent-js.js +2 -2
- package/lib/cjs/loader/agent-yaml.d.ts +4 -3
- package/lib/cjs/loader/agent-yaml.js +21 -17
- package/lib/cjs/loader/index.d.ts +3 -3
- package/lib/cjs/loader/index.js +1 -1
- package/lib/cjs/loader/schema.d.ts +1 -0
- package/lib/cjs/loader/schema.js +4 -0
- package/lib/cjs/memory/recorder.js +1 -1
- package/lib/cjs/memory/retriever.js +1 -1
- package/lib/cjs/prompt/prompt-builder.js +3 -3
- package/lib/cjs/prompt/skills/afs/delete.d.ts +18 -0
- package/lib/cjs/prompt/skills/afs/delete.js +42 -0
- package/lib/cjs/prompt/skills/afs/edit.d.ts +26 -0
- package/lib/cjs/prompt/skills/afs/edit.js +98 -0
- package/lib/cjs/prompt/skills/afs/exec.d.ts +15 -0
- package/lib/cjs/prompt/skills/afs/exec.js +27 -0
- package/lib/cjs/prompt/skills/{afs.d.ts → afs/index.d.ts} +1 -1
- package/lib/cjs/prompt/skills/afs/index.js +23 -0
- package/lib/cjs/prompt/skills/afs/list.d.ts +22 -0
- package/lib/cjs/prompt/skills/afs/list.js +90 -0
- package/lib/cjs/prompt/skills/afs/read.d.ts +21 -0
- package/lib/cjs/prompt/skills/afs/read.js +53 -0
- package/lib/cjs/prompt/skills/afs/rename.d.ts +20 -0
- package/lib/cjs/prompt/skills/afs/rename.js +45 -0
- package/lib/cjs/prompt/skills/afs/search.d.ts +23 -0
- package/lib/cjs/prompt/skills/afs/search.js +55 -0
- package/lib/cjs/prompt/skills/afs/write.d.ts +19 -0
- package/lib/cjs/prompt/skills/afs/write.js +45 -0
- package/lib/cjs/utils/event-stream.js +1 -0
- package/lib/dts/agents/agent.d.ts +1 -1
- package/lib/dts/aigne/aigne.d.ts +6 -1
- package/lib/dts/aigne/context.d.ts +2 -2
- package/lib/dts/loader/agent-js.d.ts +2 -1
- package/lib/dts/loader/agent-yaml.d.ts +4 -3
- package/lib/dts/loader/index.d.ts +3 -3
- package/lib/dts/loader/schema.d.ts +1 -0
- package/lib/dts/prompt/skills/afs/delete.d.ts +18 -0
- package/lib/dts/prompt/skills/afs/edit.d.ts +26 -0
- package/lib/dts/prompt/skills/afs/exec.d.ts +15 -0
- package/lib/dts/prompt/skills/{afs.d.ts → afs/index.d.ts} +1 -1
- package/lib/dts/prompt/skills/afs/list.d.ts +22 -0
- package/lib/dts/prompt/skills/afs/read.d.ts +21 -0
- package/lib/dts/prompt/skills/afs/rename.d.ts +20 -0
- package/lib/dts/prompt/skills/afs/search.d.ts +23 -0
- package/lib/dts/prompt/skills/afs/write.d.ts +19 -0
- package/lib/esm/agents/agent.d.ts +1 -1
- package/lib/esm/agents/agent.js +1 -1
- package/lib/esm/agents/user-agent.js +1 -1
- package/lib/esm/aigne/aigne.d.ts +6 -1
- package/lib/esm/aigne/aigne.js +13 -4
- package/lib/esm/aigne/context.d.ts +2 -2
- package/lib/esm/aigne/context.js +5 -22
- package/lib/esm/loader/agent-js.d.ts +2 -1
- package/lib/esm/loader/agent-js.js +2 -2
- package/lib/esm/loader/agent-yaml.d.ts +4 -3
- package/lib/esm/loader/agent-yaml.js +22 -18
- package/lib/esm/loader/index.d.ts +3 -3
- package/lib/esm/loader/index.js +1 -1
- package/lib/esm/loader/schema.d.ts +1 -0
- package/lib/esm/loader/schema.js +3 -0
- package/lib/esm/memory/recorder.js +1 -1
- package/lib/esm/memory/retriever.js +1 -1
- package/lib/esm/prompt/prompt-builder.js +1 -1
- package/lib/esm/prompt/skills/afs/delete.d.ts +18 -0
- package/lib/esm/prompt/skills/afs/delete.js +38 -0
- package/lib/esm/prompt/skills/afs/edit.d.ts +26 -0
- package/lib/esm/prompt/skills/afs/edit.js +94 -0
- package/lib/esm/prompt/skills/afs/exec.d.ts +15 -0
- package/lib/esm/prompt/skills/afs/exec.js +23 -0
- package/lib/esm/prompt/skills/{afs.d.ts → afs/index.d.ts} +1 -1
- package/lib/esm/prompt/skills/afs/index.js +20 -0
- package/lib/esm/prompt/skills/afs/list.d.ts +22 -0
- package/lib/esm/prompt/skills/afs/list.js +86 -0
- package/lib/esm/prompt/skills/afs/read.d.ts +21 -0
- package/lib/esm/prompt/skills/afs/read.js +49 -0
- package/lib/esm/prompt/skills/afs/rename.d.ts +20 -0
- package/lib/esm/prompt/skills/afs/rename.js +41 -0
- package/lib/esm/prompt/skills/afs/search.d.ts +23 -0
- package/lib/esm/prompt/skills/afs/search.js +51 -0
- package/lib/esm/prompt/skills/afs/write.d.ts +19 -0
- package/lib/esm/prompt/skills/afs/write.js +41 -0
- package/lib/esm/utils/event-stream.js +2 -1
- package/package.json +5 -5
- package/lib/cjs/prompt/skills/afs.js +0 -170
- package/lib/esm/prompt/skills/afs.js +0 -167
|
@@ -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;
|
|
@@ -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;
|
|
@@ -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,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AFSSearchAgent = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const agent_js_1 = require("../../../agents/agent.js");
|
|
6
|
+
class AFSSearchAgent extends agent_js_1.Agent {
|
|
7
|
+
constructor(options) {
|
|
8
|
+
super({
|
|
9
|
+
name: "afs_search",
|
|
10
|
+
description: "Search file contents by keywords. Use when finding files containing specific text or code patterns.",
|
|
11
|
+
...options,
|
|
12
|
+
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"),
|
|
15
|
+
options: zod_1.z
|
|
16
|
+
.object({
|
|
17
|
+
limit: zod_1.z.number().optional().describe("Max results to return"),
|
|
18
|
+
caseSensitive: zod_1.z
|
|
19
|
+
.boolean()
|
|
20
|
+
.optional()
|
|
21
|
+
.describe("Case-sensitive search (default: false)"),
|
|
22
|
+
})
|
|
23
|
+
.optional(),
|
|
24
|
+
}),
|
|
25
|
+
outputSchema: zod_1.z.object({
|
|
26
|
+
status: zod_1.z.string(),
|
|
27
|
+
tool: zod_1.z.string(),
|
|
28
|
+
path: zod_1.z.string(),
|
|
29
|
+
query: zod_1.z.string(),
|
|
30
|
+
options: zod_1.z
|
|
31
|
+
.object({
|
|
32
|
+
limit: zod_1.z.number().optional(),
|
|
33
|
+
caseSensitive: zod_1.z.boolean().optional(),
|
|
34
|
+
})
|
|
35
|
+
.optional(),
|
|
36
|
+
list: zod_1.z.array(zod_1.z.custom()),
|
|
37
|
+
message: zod_1.z.string().optional(),
|
|
38
|
+
}),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async process(input, _options) {
|
|
42
|
+
if (!this.afs)
|
|
43
|
+
throw new Error("AFS is not configured for this agent.");
|
|
44
|
+
const result = await this.afs.search(input.path, input.query, input.options);
|
|
45
|
+
return {
|
|
46
|
+
status: "success",
|
|
47
|
+
tool: "afs_search",
|
|
48
|
+
path: input.path,
|
|
49
|
+
query: input.query,
|
|
50
|
+
options: input.options,
|
|
51
|
+
...result,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.AFSSearchAgent = AFSSearchAgent;
|
|
@@ -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,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AFSWriteAgent = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const agent_js_1 = require("../../../agents/agent.js");
|
|
6
|
+
class AFSWriteAgent extends agent_js_1.Agent {
|
|
7
|
+
constructor(options) {
|
|
8
|
+
super({
|
|
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.",
|
|
11
|
+
...options,
|
|
12
|
+
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"),
|
|
15
|
+
append: zod_1.z
|
|
16
|
+
.boolean()
|
|
17
|
+
.optional()
|
|
18
|
+
.default(false)
|
|
19
|
+
.describe("Append mode: add content to end of file (default: false, overwrites file)"),
|
|
20
|
+
}),
|
|
21
|
+
outputSchema: zod_1.z.object({
|
|
22
|
+
status: zod_1.z.string(),
|
|
23
|
+
tool: zod_1.z.string(),
|
|
24
|
+
path: zod_1.z.string(),
|
|
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.write(input.path, {
|
|
33
|
+
content: input.content,
|
|
34
|
+
}, {
|
|
35
|
+
append: input.append ?? false,
|
|
36
|
+
});
|
|
37
|
+
return {
|
|
38
|
+
status: "success",
|
|
39
|
+
tool: "afs_write",
|
|
40
|
+
path: input.path,
|
|
41
|
+
...result,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.AFSWriteAgent = AFSWriteAgent;
|
|
@@ -5,6 +5,7 @@ const eventsource_parser_1 = require("eventsource-parser");
|
|
|
5
5
|
const immer_1 = require("immer");
|
|
6
6
|
const agent_js_1 = require("../agents/agent.js");
|
|
7
7
|
const type_utils_js_1 = require("./type-utils.js");
|
|
8
|
+
(0, immer_1.setAutoFreeze)(false);
|
|
8
9
|
class EventStreamParser extends TransformStream {
|
|
9
10
|
constructor() {
|
|
10
11
|
let parser;
|
|
@@ -938,4 +938,4 @@ export declare class FunctionAgent<I extends Message = Message, O extends Messag
|
|
|
938
938
|
* @param context Execution context
|
|
939
939
|
* @returns Processing result, can be synchronous or asynchronous
|
|
940
940
|
*/
|
|
941
|
-
export type FunctionAgentFn<I extends Message = any, O extends Message = any> = (input: I, options: AgentInvokeOptions) => PromiseOrValue<AgentProcessResult<O>>;
|
|
941
|
+
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>>;
|
package/lib/dts/aigne/aigne.d.ts
CHANGED
|
@@ -113,6 +113,10 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
113
113
|
* @hidden
|
|
114
114
|
*/
|
|
115
115
|
readonly messageQueue: MessageQueue;
|
|
116
|
+
/**
|
|
117
|
+
* Collection of all context IDs created by this AIGNE instance.
|
|
118
|
+
*/
|
|
119
|
+
readonly contextIds: Set<string>;
|
|
116
120
|
/**
|
|
117
121
|
* Collection of skill agents available to this AIGNE instance.
|
|
118
122
|
* Provides indexed access by skill name.
|
|
@@ -324,7 +328,8 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
324
328
|
[Symbol.asyncDispose](): Promise<void>;
|
|
325
329
|
/**
|
|
326
330
|
* Initializes handlers for process exit events to ensure clean shutdown.
|
|
327
|
-
* This registers handlers for SIGINT
|
|
331
|
+
* This registers handlers for SIGINT/SIGTERM to properly terminate all agents.
|
|
332
|
+
* Note: 'exit' event cannot run async code, so we handle cleanup in signal handlers.
|
|
328
333
|
*/
|
|
329
334
|
private initProcessExitHandler;
|
|
330
335
|
}
|
|
@@ -149,7 +149,6 @@ export interface Context<U extends UserContext = UserContext> extends TypedEvent
|
|
|
149
149
|
* @hidden
|
|
150
150
|
*/
|
|
151
151
|
export declare class AIGNEContext implements Context {
|
|
152
|
-
static exitCount: number;
|
|
153
152
|
constructor(parent?: ConstructorParameters<typeof AIGNEContextShared>[0], { reset }?: {
|
|
154
153
|
reset?: boolean;
|
|
155
154
|
});
|
|
@@ -183,7 +182,6 @@ export declare class AIGNEContext implements Context {
|
|
|
183
182
|
subscribe: Context["subscribe"];
|
|
184
183
|
unsubscribe: Context["unsubscribe"];
|
|
185
184
|
emit<K extends keyof ContextEmitEventMap>(eventName: K, ...args: Args<K, ContextEmitEventMap>): boolean;
|
|
186
|
-
initProcessExitHandler(): void;
|
|
187
185
|
private trace;
|
|
188
186
|
on<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
|
|
189
187
|
once<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
|
|
@@ -194,6 +192,7 @@ declare class AIGNEContextShared {
|
|
|
194
192
|
constructor(parent?: (Pick<Context, "model" | "imageModel" | "agents" | "skills" | "limits" | "observer" | "metadata"> & {
|
|
195
193
|
messageQueue?: MessageQueue;
|
|
196
194
|
events?: Emitter<any>;
|
|
195
|
+
contextIds?: Set<string>;
|
|
197
196
|
}) | undefined);
|
|
198
197
|
readonly messageQueue: MessageQueue;
|
|
199
198
|
readonly events: Emitter<any>;
|
|
@@ -205,6 +204,7 @@ declare class AIGNEContextShared {
|
|
|
205
204
|
get metadata(): AIGNEMetadata | undefined;
|
|
206
205
|
get limits(): ContextLimits | undefined;
|
|
207
206
|
usage: ContextUsage;
|
|
207
|
+
contextIds: Set<string>;
|
|
208
208
|
userContext: Context["userContext"];
|
|
209
209
|
memories: Context["memories"];
|
|
210
210
|
hooks: AgentHooks[];
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { LoadOptions } from "./index.js";
|
|
2
|
+
export declare function loadAgentFromJsFile(path: string, options: LoadOptions): Promise<import("../index.js").Agent<any, any> | import("./agent-yaml.js").AgentSchema>;
|