@aigne/core 1.71.0-beta.4 → 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 +20 -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/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/dts/agents/agent.d.ts +1 -1
- 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/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/package.json +4 -4
- package/lib/cjs/prompt/skills/afs.js +0 -177
- package/lib/esm/prompt/skills/afs.js +0 -174
|
@@ -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;
|
|
@@ -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>>;
|
|
@@ -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,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,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,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,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,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,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,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
|
+
}
|
|
@@ -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/esm/agents/agent.js
CHANGED
|
@@ -868,7 +868,7 @@ export class FunctionAgent extends Agent {
|
|
|
868
868
|
* @returns Processing result
|
|
869
869
|
*/
|
|
870
870
|
process(input, options) {
|
|
871
|
-
return this._process(input, options);
|
|
871
|
+
return this._process.apply(this, [input, options]);
|
|
872
872
|
}
|
|
873
873
|
}
|
|
874
874
|
function functionToAgent(agent) {
|
|
@@ -29,7 +29,7 @@ export class UserAgent extends Agent {
|
|
|
29
29
|
});
|
|
30
30
|
async process(input, options) {
|
|
31
31
|
if (this._process) {
|
|
32
|
-
return this._process(input, options);
|
|
32
|
+
return this._process.apply(this, [input, options]);
|
|
33
33
|
}
|
|
34
34
|
if (this.activeAgent) {
|
|
35
35
|
const [output, agent] = await this.invokeChildAgent(this.activeAgent, input, {
|
|
@@ -12,7 +12,7 @@ import { checkArguments, flat, isNonNullable, isRecord, partition, pick, unique,
|
|
|
12
12
|
import { AFS_DESCRIPTION_PROMPT_TEMPLATE, AFS_EXECUTABLE_TOOLS_PROMPT_TEMPLATE, getAFSSystemPrompt, } from "./prompts/afs-builtin-prompt.js";
|
|
13
13
|
import { MEMORY_MESSAGE_TEMPLATE } from "./prompts/memory-message-template.js";
|
|
14
14
|
import { STRUCTURED_STREAM_INSTRUCTIONS } from "./prompts/structured-stream-instructions.js";
|
|
15
|
-
import { getAFSSkills } from "./skills/afs.js";
|
|
15
|
+
import { getAFSSkills } from "./skills/afs/index.js";
|
|
16
16
|
import { AgentMessageTemplate, ChatMessagesTemplate, PromptTemplate, SystemMessageTemplate, UserMessageTemplate, } from "./template.js";
|
|
17
17
|
export class PromptBuilder {
|
|
18
18
|
static from(instructions, { workingDir } = {}) {
|
|
@@ -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,38 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { Agent, } from "../../../agents/agent.js";
|
|
3
|
+
export class AFSDeleteAgent extends Agent {
|
|
4
|
+
constructor(options) {
|
|
5
|
+
super({
|
|
6
|
+
name: "afs_delete",
|
|
7
|
+
description: "Permanently delete files or directories. Use when removing unwanted files or cleaning up temporary data.",
|
|
8
|
+
...options,
|
|
9
|
+
inputSchema: z.object({
|
|
10
|
+
path: z.string().describe("Absolute file or directory path to delete"),
|
|
11
|
+
recursive: z
|
|
12
|
+
.boolean()
|
|
13
|
+
.optional()
|
|
14
|
+
.default(false)
|
|
15
|
+
.describe("Allow directory deletion (default: false, required for directories)"),
|
|
16
|
+
}),
|
|
17
|
+
outputSchema: z.object({
|
|
18
|
+
status: z.string(),
|
|
19
|
+
tool: z.string(),
|
|
20
|
+
path: z.string(),
|
|
21
|
+
message: z.string().optional(),
|
|
22
|
+
}),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
async process(input, _options) {
|
|
26
|
+
if (!this.afs)
|
|
27
|
+
throw new Error("AFS is not configured for this agent.");
|
|
28
|
+
const result = await this.afs.delete(input.path, {
|
|
29
|
+
recursive: input.recursive ?? false,
|
|
30
|
+
});
|
|
31
|
+
return {
|
|
32
|
+
status: "success",
|
|
33
|
+
tool: "afs_delete",
|
|
34
|
+
path: input.path,
|
|
35
|
+
...result,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -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,94 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { Agent, } from "../../../agents/agent.js";
|
|
3
|
+
export class AFSEditAgent extends Agent {
|
|
4
|
+
constructor(options) {
|
|
5
|
+
super({
|
|
6
|
+
name: "afs_edit",
|
|
7
|
+
description: "Apply precise line-based patches to modify file content. Use when making targeted changes without rewriting the entire file.",
|
|
8
|
+
...options,
|
|
9
|
+
inputSchema: z.object({
|
|
10
|
+
path: z.string().describe("Absolute file path to edit"),
|
|
11
|
+
patches: z
|
|
12
|
+
.array(z.object({
|
|
13
|
+
start_line: z.number().int().describe("Start line number (0-based, inclusive)"),
|
|
14
|
+
end_line: z.number().int().describe("End line number (0-based, exclusive)"),
|
|
15
|
+
replace: z.string().optional().describe("New content to replace the line range"),
|
|
16
|
+
delete: z.boolean().describe("Delete mode: true to delete lines, false to replace"),
|
|
17
|
+
}))
|
|
18
|
+
.min(1)
|
|
19
|
+
.describe("List of patches to apply sequentially"),
|
|
20
|
+
}),
|
|
21
|
+
outputSchema: z.object({
|
|
22
|
+
status: z.string(),
|
|
23
|
+
tool: z.string(),
|
|
24
|
+
path: z.string(),
|
|
25
|
+
message: z.string(),
|
|
26
|
+
content: z.string(),
|
|
27
|
+
}),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async process(input, _options) {
|
|
31
|
+
if (!this.afs)
|
|
32
|
+
throw new Error("AFS is not configured for this agent.");
|
|
33
|
+
if (!input.patches?.length) {
|
|
34
|
+
throw new Error("No patches provided for afs_edit.");
|
|
35
|
+
}
|
|
36
|
+
const readResult = await this.afs.read(input.path);
|
|
37
|
+
if (!readResult.result?.content || typeof readResult.result.content !== "string") {
|
|
38
|
+
throw new Error(`Cannot read file content from: ${input.path}`);
|
|
39
|
+
}
|
|
40
|
+
const originalContent = readResult.result.content;
|
|
41
|
+
const updatedContent = this.applyCustomPatches(originalContent, input.patches);
|
|
42
|
+
await this.afs.write(input.path, {
|
|
43
|
+
content: updatedContent,
|
|
44
|
+
});
|
|
45
|
+
return {
|
|
46
|
+
status: "success",
|
|
47
|
+
tool: "afs_edit",
|
|
48
|
+
path: input.path,
|
|
49
|
+
message: `Applied ${input.patches.length} patches to ${input.path}`,
|
|
50
|
+
content: updatedContent,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
applyCustomPatches(text, patches) {
|
|
54
|
+
// Sort by start_line to ensure sequential application
|
|
55
|
+
const sorted = [...patches].sort((a, b) => a.start_line - b.start_line);
|
|
56
|
+
const lines = text.split("\n");
|
|
57
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
58
|
+
const patch = sorted[i];
|
|
59
|
+
if (!patch)
|
|
60
|
+
continue;
|
|
61
|
+
const start = patch.start_line;
|
|
62
|
+
const end = patch.end_line;
|
|
63
|
+
const deleteCount = end - start; // [start, end) range
|
|
64
|
+
let delta = 0;
|
|
65
|
+
if (patch.delete) {
|
|
66
|
+
// Delete mode: remove the specified lines [start, end)
|
|
67
|
+
lines.splice(start, deleteCount);
|
|
68
|
+
delta = -deleteCount;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
// Replace mode: replace the specified lines with new content
|
|
72
|
+
const replaceLines = patch.replace ? patch.replace.split("\n") : [];
|
|
73
|
+
lines.splice(start, deleteCount, ...replaceLines);
|
|
74
|
+
delta = replaceLines.length - deleteCount;
|
|
75
|
+
}
|
|
76
|
+
// Update subsequent patches' line numbers
|
|
77
|
+
// For exclusive-end semantics [start, end), we adjust patches that start >= current patch's start_line
|
|
78
|
+
// after the current patch has been applied
|
|
79
|
+
if (delta !== 0) {
|
|
80
|
+
for (let j = i + 1; j < sorted.length; j++) {
|
|
81
|
+
const next = sorted[j];
|
|
82
|
+
if (!next)
|
|
83
|
+
continue;
|
|
84
|
+
// Adjust patches that start at or after the current patch's end line
|
|
85
|
+
if (next.start_line >= patch.end_line) {
|
|
86
|
+
next.start_line += delta;
|
|
87
|
+
next.end_line += delta;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return lines.join("\n");
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -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
|
+
}
|