@saber2pr/ai-agent 0.0.17 → 0.0.18
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/README.md +7 -5
- package/lib/tools/filesystem/index.js +12 -12
- package/lib/utils/jsonSchemaToZod.d.ts +10 -0
- package/lib/utils/jsonSchemaToZod.js +7 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -48,7 +48,7 @@ npm run build
|
|
|
48
48
|
Best for quick scripts and simple chat interactions. It uses a straightforward message-loop logic.
|
|
49
49
|
|
|
50
50
|
```javascript
|
|
51
|
-
|
|
51
|
+
import McpAgent from "@saber2pr/ai-agent";
|
|
52
52
|
|
|
53
53
|
const agent = new McpAgent({
|
|
54
54
|
targetDir: "/path/to/project"
|
|
@@ -63,10 +63,10 @@ await agent.chat("Analyze the directory structure.");
|
|
|
63
63
|
Best for complex tasks like "Audit the whole project and fix bugs." It supports autonomous tool usage.
|
|
64
64
|
|
|
65
65
|
```javascript
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
import { McpChainAgent } from "@saber2pr/ai-agent";
|
|
67
|
+
import { MyPrivateLLM } from "./your-custom-llm";
|
|
68
68
|
|
|
69
|
-
const agent = new
|
|
69
|
+
const agent = new McpChainAgent({
|
|
70
70
|
apiModel: new MyPrivateLLM(), // Inject custom LLM
|
|
71
71
|
maxIterations: 15,
|
|
72
72
|
targetDir: "/path/to/project"
|
|
@@ -85,7 +85,7 @@ await agent.chat("Scan for hardcoded colors and submit a review report.");
|
|
|
85
85
|
For LangChain mode, extend `AgentChainModel` which provides a simplified interface for integrating custom LLMs:
|
|
86
86
|
|
|
87
87
|
```javascript
|
|
88
|
-
|
|
88
|
+
import { AgentChainModel } from "@saber2pr/ai-agent";
|
|
89
89
|
|
|
90
90
|
class MyPrivateLLM extends AgentChainModel {
|
|
91
91
|
constructor(fields) {
|
|
@@ -175,6 +175,8 @@ The toolkit provides a comprehensive set of built-in tools organized into two ca
|
|
|
175
175
|
You can pass structured rules via the `extraSystemPrompt`:
|
|
176
176
|
|
|
177
177
|
```javascript
|
|
178
|
+
import McpAgent from "@saber2pr/ai-agent";
|
|
179
|
+
|
|
178
180
|
const agent = new McpAgent({
|
|
179
181
|
extraSystemPrompt: {
|
|
180
182
|
role: "Code Auditor",
|
|
@@ -7,10 +7,10 @@ exports.getFilesystemTools = void 0;
|
|
|
7
7
|
const zod_1 = require("zod");
|
|
8
8
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
|
-
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
11
10
|
const createTool_1 = require("../../utils/createTool");
|
|
12
11
|
const minimatch_1 = require("minimatch");
|
|
13
12
|
const lib_1 = require("./lib");
|
|
13
|
+
const jsonSchemaToZod_1 = require("../../utils/jsonSchemaToZod");
|
|
14
14
|
// Schema definitions
|
|
15
15
|
const ReadTextFileArgsSchema = zod_1.z.object({
|
|
16
16
|
path: zod_1.z.string(),
|
|
@@ -90,7 +90,7 @@ const getFilesystemTools = (targetDir) => {
|
|
|
90
90
|
"the contents of a single file. Use the 'head' parameter to read only " +
|
|
91
91
|
"the first N lines of a file, or the 'tail' parameter to read only " +
|
|
92
92
|
"the last N lines of a file. Operates on the file as text regardless of extension.",
|
|
93
|
-
parameters: (0,
|
|
93
|
+
parameters: (0, jsonSchemaToZod_1.zodObjectToJsonSchema)(ReadTextFileArgsSchema, 'ReadTextFileArgsSchema'),
|
|
94
94
|
validateParams: ["path"],
|
|
95
95
|
handler: readTextFileHandler
|
|
96
96
|
});
|
|
@@ -101,7 +101,7 @@ const getFilesystemTools = (targetDir) => {
|
|
|
101
101
|
"or compare multiple files. Each file's content is returned with its " +
|
|
102
102
|
"path as a reference. Failed reads for individual files won't stop " +
|
|
103
103
|
"the entire operation. Only works within allowed directories.",
|
|
104
|
-
parameters: (0,
|
|
104
|
+
parameters: (0, jsonSchemaToZod_1.zodObjectToJsonSchema)(ReadMultipleFilesArgsSchema, 'ReadMultipleFilesArgsSchema'),
|
|
105
105
|
validateParams: ["paths"],
|
|
106
106
|
handler: async (args) => {
|
|
107
107
|
const results = await Promise.all(args.paths.map(async (filePath) => {
|
|
@@ -124,7 +124,7 @@ const getFilesystemTools = (targetDir) => {
|
|
|
124
124
|
description: "Create a new file or completely overwrite an existing file with new content. " +
|
|
125
125
|
"Use with caution as it will overwrite existing files without warning. " +
|
|
126
126
|
"Handles text content with proper encoding. Only works within allowed directories.",
|
|
127
|
-
parameters: (0,
|
|
127
|
+
parameters: (0, jsonSchemaToZod_1.zodObjectToJsonSchema)(WriteFileArgsSchema, 'WriteFileArgsSchema'),
|
|
128
128
|
validateParams: ["path", "content"],
|
|
129
129
|
handler: async (args) => {
|
|
130
130
|
const validPath = await (0, lib_1.validatePath)(targetDir, args.path);
|
|
@@ -138,7 +138,7 @@ const getFilesystemTools = (targetDir) => {
|
|
|
138
138
|
description: "Make line-based edits to a text file. Each edit replaces exact line sequences " +
|
|
139
139
|
"with new content. Returns a git-style diff showing the changes made. " +
|
|
140
140
|
"Only works within allowed directories.",
|
|
141
|
-
parameters: (0,
|
|
141
|
+
parameters: (0, jsonSchemaToZod_1.zodObjectToJsonSchema)(EditFileArgsSchema, 'EditFileArgsSchema'),
|
|
142
142
|
validateParams: ["path", "edits"],
|
|
143
143
|
handler: async (args) => {
|
|
144
144
|
const validPath = await (0, lib_1.validatePath)(targetDir, args.path);
|
|
@@ -152,7 +152,7 @@ const getFilesystemTools = (targetDir) => {
|
|
|
152
152
|
"nested directories in one operation. If the directory already exists, " +
|
|
153
153
|
"this operation will succeed silently. Perfect for setting up directory " +
|
|
154
154
|
"structures for projects or ensuring required paths exist. Only works within allowed directories.",
|
|
155
|
-
parameters: (0,
|
|
155
|
+
parameters: (0, jsonSchemaToZod_1.zodObjectToJsonSchema)(CreateDirectoryArgsSchema, 'CreateDirectoryArgsSchema'),
|
|
156
156
|
validateParams: ["path"],
|
|
157
157
|
handler: async (args) => {
|
|
158
158
|
const validPath = await (0, lib_1.validatePath)(targetDir, args.path);
|
|
@@ -167,7 +167,7 @@ const getFilesystemTools = (targetDir) => {
|
|
|
167
167
|
"Results clearly distinguish between files and directories with [FILE] and [DIR] " +
|
|
168
168
|
"prefixes. This tool is essential for understanding directory structure and " +
|
|
169
169
|
"finding specific files within a directory. Only works within allowed directories.",
|
|
170
|
-
parameters: (0,
|
|
170
|
+
parameters: (0, jsonSchemaToZod_1.zodObjectToJsonSchema)(ListDirectoryArgsSchema, 'ListDirectoryArgsSchema'),
|
|
171
171
|
validateParams: ["path"],
|
|
172
172
|
handler: async (args) => {
|
|
173
173
|
const validPath = await (0, lib_1.validatePath)(targetDir, args.path);
|
|
@@ -184,7 +184,7 @@ const getFilesystemTools = (targetDir) => {
|
|
|
184
184
|
"Results clearly distinguish between files and directories with [FILE] and [DIR] " +
|
|
185
185
|
"prefixes. This tool is useful for understanding directory structure and " +
|
|
186
186
|
"finding specific files within a directory. Only works within allowed directories.",
|
|
187
|
-
parameters: (0,
|
|
187
|
+
parameters: (0, jsonSchemaToZod_1.zodObjectToJsonSchema)(ListDirectoryWithSizesArgsSchema, 'ListDirectoryWithSizesArgsSchema'),
|
|
188
188
|
validateParams: ["path"],
|
|
189
189
|
handler: async (args) => {
|
|
190
190
|
const validPath = await (0, lib_1.validatePath)(targetDir, args.path);
|
|
@@ -239,7 +239,7 @@ const getFilesystemTools = (targetDir) => {
|
|
|
239
239
|
"Each entry includes 'name', 'type' (file/directory), and 'children' for directories. " +
|
|
240
240
|
"Files have no children array, while directories always have a children array (which may be empty). " +
|
|
241
241
|
"The output is formatted with 2-space indentation for readability. Only works within allowed directories.",
|
|
242
|
-
parameters: (0,
|
|
242
|
+
parameters: (0, jsonSchemaToZod_1.zodObjectToJsonSchema)(DirectoryTreeArgsSchema, 'DirectoryTreeArgsSchema'),
|
|
243
243
|
validateParams: ["path"],
|
|
244
244
|
handler: async (args) => {
|
|
245
245
|
const rootPath = args.path;
|
|
@@ -284,7 +284,7 @@ const getFilesystemTools = (targetDir) => {
|
|
|
284
284
|
"and rename them in a single operation. If the destination exists, the " +
|
|
285
285
|
"operation will fail. Works across different directories and can be used " +
|
|
286
286
|
"for simple renaming within the same directory. Both source and destination must be within allowed directories.",
|
|
287
|
-
parameters: (0,
|
|
287
|
+
parameters: (0, jsonSchemaToZod_1.zodObjectToJsonSchema)(MoveFileArgsSchema, 'MoveFileArgsSchema'),
|
|
288
288
|
validateParams: ["source", "destination"],
|
|
289
289
|
handler: async (args) => {
|
|
290
290
|
const validSourcePath = await (0, lib_1.validatePath)(targetDir, args.source);
|
|
@@ -298,7 +298,7 @@ const getFilesystemTools = (targetDir) => {
|
|
|
298
298
|
name: "search_files",
|
|
299
299
|
description: "Search for files matching a specific pattern in a specified path. " +
|
|
300
300
|
"Returns a list of files that match the pattern. Only works within allowed directories.",
|
|
301
|
-
parameters: (0,
|
|
301
|
+
parameters: (0, jsonSchemaToZod_1.zodObjectToJsonSchema)(SearchFilesArgsSchema, 'SearchFilesArgsSchema'),
|
|
302
302
|
validateParams: ["path", "pattern"],
|
|
303
303
|
handler: async (args) => {
|
|
304
304
|
const validPath = await (0, lib_1.validatePath)(targetDir, args.path);
|
|
@@ -311,7 +311,7 @@ const getFilesystemTools = (targetDir) => {
|
|
|
311
311
|
name: "get_file_info",
|
|
312
312
|
description: "Get detailed information about a file, including its size, last modified time, and type. " +
|
|
313
313
|
"Only works within allowed directories.",
|
|
314
|
-
parameters: (0,
|
|
314
|
+
parameters: (0, jsonSchemaToZod_1.zodObjectToJsonSchema)(GetFileInfoArgsSchema, 'GetFileInfoArgsSchema'),
|
|
315
315
|
validateParams: ["path"],
|
|
316
316
|
handler: async (args) => {
|
|
317
317
|
const validPath = await (0, lib_1.validatePath)(targetDir, args.path);
|
|
@@ -1,2 +1,12 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
export declare const zodObjectToJsonSchema: (zodObject: z.ZodObject<any>, name: string) => z.ZodObject<any, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
3
|
+
[x: string]: any;
|
|
4
|
+
}, {
|
|
5
|
+
[x: string]: any;
|
|
6
|
+
}> | {
|
|
7
|
+
title?: string;
|
|
8
|
+
default?: any;
|
|
9
|
+
description?: string;
|
|
10
|
+
markdownDescription?: string;
|
|
11
|
+
};
|
|
2
12
|
export declare function jsonSchemaToZod(parameters: any): z.ZodObject<any>;
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.zodObjectToJsonSchema = void 0;
|
|
3
4
|
exports.jsonSchemaToZod = jsonSchemaToZod;
|
|
4
5
|
const zod_1 = require("zod");
|
|
6
|
+
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
7
|
+
const zodObjectToJsonSchema = (zodObject, name) => {
|
|
8
|
+
var _a, _b;
|
|
9
|
+
return ((_b = (_a = (0, zod_to_json_schema_1.zodToJsonSchema)(zodObject, name)) === null || _a === void 0 ? void 0 : _a.definitions) === null || _b === void 0 ? void 0 : _b[name]) || zodObject;
|
|
10
|
+
};
|
|
11
|
+
exports.zodObjectToJsonSchema = zodObjectToJsonSchema;
|
|
5
12
|
function jsonSchemaToZod(parameters) {
|
|
6
13
|
var _a;
|
|
7
14
|
if (!parameters || typeof parameters !== 'object') {
|