@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.
- package/CHANGELOG.md +27 -0
- package/lib/cjs/agents/agent.d.ts +3 -1
- package/lib/cjs/agents/agent.js +7 -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/cjs/utils/json-schema.d.ts +1 -0
- package/lib/cjs/utils/json-schema.js +6 -0
- package/lib/dts/agents/agent.d.ts +3 -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/dts/utils/json-schema.d.ts +1 -0
- package/lib/esm/agents/agent.d.ts +3 -1
- package/lib/esm/agents/agent.js +8 -2
- 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/lib/esm/utils/json-schema.d.ts +1 -0
- package/lib/esm/utils/json-schema.js +5 -0
- package/package.json +3 -3
- package/lib/cjs/prompt/skills/afs.js +0 -177
- package/lib/esm/prompt/skills/afs.js +0 -174
|
@@ -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;
|
|
@@ -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[];
|
|
@@ -5,6 +5,7 @@ exports.outputSchemaToResponseFormatSchema = outputSchemaToResponseFormatSchema;
|
|
|
5
5
|
exports.parseJSON = parseJSON;
|
|
6
6
|
exports.ensureZodUnionArray = ensureZodUnionArray;
|
|
7
7
|
exports.isZodSchema = isZodSchema;
|
|
8
|
+
exports.getZodObjectKeys = getZodObjectKeys;
|
|
8
9
|
const zod_1 = require("zod");
|
|
9
10
|
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
10
11
|
const json_utils_js_1 = require("./json-utils.js");
|
|
@@ -115,3 +116,8 @@ const wrapAutoParseJsonSchema = (schema) => {
|
|
|
115
116
|
return schema;
|
|
116
117
|
};
|
|
117
118
|
exports.wrapAutoParseJsonSchema = wrapAutoParseJsonSchema;
|
|
119
|
+
function getZodObjectKeys(schema) {
|
|
120
|
+
if ("shape" in schema && schema.shape)
|
|
121
|
+
return Object.keys(schema.shape);
|
|
122
|
+
return [];
|
|
123
|
+
}
|
|
@@ -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>>;
|
|
@@ -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
|
+
}
|
|
@@ -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[];
|
|
@@ -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>>;
|
package/lib/esm/agents/agent.js
CHANGED
|
@@ -6,7 +6,7 @@ import { joinURL } from "ufo";
|
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
8
8
|
import { sortHooks } from "../utils/agent-utils.js";
|
|
9
|
-
import { isZodSchema } from "../utils/json-schema.js";
|
|
9
|
+
import { getZodObjectKeys, isZodSchema } from "../utils/json-schema.js";
|
|
10
10
|
import { logger } from "../utils/logger.js";
|
|
11
11
|
import { agentResponseStreamToObject, asyncGeneratorToReadableStream, isAsyncGenerator, mergeAgentResponseChunk, objectToAgentResponseStream, onAgentResponseStreamEnd, } from "../utils/stream-utils.js";
|
|
12
12
|
import { checkArguments, createAccessorArray, flat, isEmpty, isNil, isNonNullable, isRecord, } from "../utils/type-utils.js";
|
|
@@ -230,6 +230,9 @@ export class Agent {
|
|
|
230
230
|
checkAgentInputOutputSchema(schema);
|
|
231
231
|
return schema.passthrough();
|
|
232
232
|
}
|
|
233
|
+
get inputKeys() {
|
|
234
|
+
return getZodObjectKeys(this.inputSchema);
|
|
235
|
+
}
|
|
233
236
|
/**
|
|
234
237
|
* Get the output data schema for this agent
|
|
235
238
|
*
|
|
@@ -244,6 +247,9 @@ export class Agent {
|
|
|
244
247
|
checkAgentInputOutputSchema(schema);
|
|
245
248
|
return schema.passthrough();
|
|
246
249
|
}
|
|
250
|
+
get outputKeys() {
|
|
251
|
+
return getZodObjectKeys(this.outputSchema);
|
|
252
|
+
}
|
|
247
253
|
/**
|
|
248
254
|
* Whether to include the original input in the output
|
|
249
255
|
*
|
|
@@ -868,7 +874,7 @@ export class FunctionAgent extends Agent {
|
|
|
868
874
|
* @returns Processing result
|
|
869
875
|
*/
|
|
870
876
|
process(input, options) {
|
|
871
|
-
return this._process(input, options);
|
|
877
|
+
return this._process.apply(this, [input, options]);
|
|
872
878
|
}
|
|
873
879
|
}
|
|
874
880
|
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
|
+
}
|