@sowonai/crewx-sdk 0.5.0 → 0.6.0-rc.0
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/dist/adapters/MastraToolAdapter.d.ts +9 -0
- package/dist/adapters/MastraToolAdapter.js +66 -0
- package/dist/adapters/MastraToolAdapter.js.map +1 -0
- package/dist/config/api-provider-parser.d.ts +56 -0
- package/dist/config/api-provider-parser.js +214 -0
- package/dist/config/api-provider-parser.js.map +1 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +2 -0
- package/dist/config/index.js.map +1 -1
- package/dist/core/agent/agent-factory.d.ts +4 -2
- package/dist/core/agent/agent-factory.js +11 -0
- package/dist/core/agent/agent-factory.js.map +1 -1
- package/dist/core/providers/MastraAPIProvider.d.ts +24 -0
- package/dist/core/providers/MastraAPIProvider.js +264 -0
- package/dist/core/providers/MastraAPIProvider.js.map +1 -0
- package/dist/core/providers/ai-provider.interface.d.ts +1 -0
- package/dist/core/providers/ai-provider.interface.js.map +1 -1
- package/dist/core/providers/provider-factory.js +38 -0
- package/dist/core/providers/provider-factory.js.map +1 -1
- package/dist/index.d.ts +10 -0
- package/dist/index.js +37 -2
- package/dist/index.js.map +1 -1
- package/dist/schemas/api-provider.schema.d.ts +429 -0
- package/dist/schemas/api-provider.schema.js +48 -0
- package/dist/schemas/api-provider.schema.js.map +1 -0
- package/dist/tools/file-system.service.d.ts +10 -0
- package/dist/tools/file-system.service.js +33 -0
- package/dist/tools/file-system.service.js.map +1 -0
- package/dist/tools/find.tool.d.ts +85 -0
- package/dist/tools/find.tool.js +140 -0
- package/dist/tools/find.tool.js.map +1 -0
- package/dist/tools/glob.tool.d.ts +100 -0
- package/dist/tools/glob.tool.js +153 -0
- package/dist/tools/glob.tool.js.map +1 -0
- package/dist/tools/grep.tool.d.ts +54 -0
- package/dist/tools/grep.tool.js +137 -0
- package/dist/tools/grep.tool.js.map +1 -0
- package/dist/tools/index.d.ts +12 -0
- package/dist/tools/index.js +40 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/ls.tool.d.ts +42 -0
- package/dist/tools/ls.tool.js +94 -0
- package/dist/tools/ls.tool.js.map +1 -0
- package/dist/tools/read-file.tool.d.ts +54 -0
- package/dist/tools/read-file.tool.js +69 -0
- package/dist/tools/read-file.tool.js.map +1 -0
- package/dist/tools/replace.tool.d.ts +66 -0
- package/dist/tools/replace.tool.js +68 -0
- package/dist/tools/replace.tool.js.map +1 -0
- package/dist/tools/run-shell-command.tool.d.ts +42 -0
- package/dist/tools/run-shell-command.tool.js +64 -0
- package/dist/tools/run-shell-command.tool.js.map +1 -0
- package/dist/tools/tree.tool.d.ts +42 -0
- package/dist/tools/tree.tool.js +109 -0
- package/dist/tools/tree.tool.js.map +1 -0
- package/dist/tools/types.d.ts +42 -0
- package/dist/tools/types.js +13 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/tools/utils/file-utils.d.ts +5 -0
- package/dist/tools/utils/file-utils.js +221 -0
- package/dist/tools/utils/file-utils.js.map +1 -0
- package/dist/tools/write-file.tool.d.ts +42 -0
- package/dist/tools/write-file.tool.js +55 -0
- package/dist/tools/write-file.tool.js.map +1 -0
- package/dist/types/agent.types.d.ts +2 -2
- package/dist/types/api-provider.types.d.ts +80 -0
- package/dist/types/api-provider.types.js +53 -0
- package/dist/types/api-provider.types.js.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/utils/api-provider-normalizer.d.ts +16 -0
- package/dist/utils/api-provider-normalizer.js +135 -0
- package/dist/utils/api-provider-normalizer.js.map +1 -0
- package/package.json +5 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.StandardFileSystemService = exports.globTool = exports.findTool = exports.grepTool = exports.writeFileTool = exports.treeTool = exports.lsTool = exports.runShellCommandTool = exports.replaceTool = exports.readFileTool = void 0;
|
|
18
|
+
var read_file_tool_js_1 = require("./read-file.tool.js");
|
|
19
|
+
Object.defineProperty(exports, "readFileTool", { enumerable: true, get: function () { return read_file_tool_js_1.readFileTool; } });
|
|
20
|
+
var replace_tool_js_1 = require("./replace.tool.js");
|
|
21
|
+
Object.defineProperty(exports, "replaceTool", { enumerable: true, get: function () { return replace_tool_js_1.replaceTool; } });
|
|
22
|
+
var run_shell_command_tool_js_1 = require("./run-shell-command.tool.js");
|
|
23
|
+
Object.defineProperty(exports, "runShellCommandTool", { enumerable: true, get: function () { return run_shell_command_tool_js_1.runShellCommandTool; } });
|
|
24
|
+
var ls_tool_js_1 = require("./ls.tool.js");
|
|
25
|
+
Object.defineProperty(exports, "lsTool", { enumerable: true, get: function () { return ls_tool_js_1.lsTool; } });
|
|
26
|
+
var tree_tool_js_1 = require("./tree.tool.js");
|
|
27
|
+
Object.defineProperty(exports, "treeTool", { enumerable: true, get: function () { return tree_tool_js_1.treeTool; } });
|
|
28
|
+
var write_file_tool_js_1 = require("./write-file.tool.js");
|
|
29
|
+
Object.defineProperty(exports, "writeFileTool", { enumerable: true, get: function () { return write_file_tool_js_1.writeFileTool; } });
|
|
30
|
+
var grep_tool_js_1 = require("./grep.tool.js");
|
|
31
|
+
Object.defineProperty(exports, "grepTool", { enumerable: true, get: function () { return grep_tool_js_1.grepTool; } });
|
|
32
|
+
var find_tool_js_1 = require("./find.tool.js");
|
|
33
|
+
Object.defineProperty(exports, "findTool", { enumerable: true, get: function () { return find_tool_js_1.findTool; } });
|
|
34
|
+
var glob_tool_js_1 = require("./glob.tool.js");
|
|
35
|
+
Object.defineProperty(exports, "globTool", { enumerable: true, get: function () { return glob_tool_js_1.globTool; } });
|
|
36
|
+
var file_system_service_js_1 = require("./file-system.service.js");
|
|
37
|
+
Object.defineProperty(exports, "StandardFileSystemService", { enumerable: true, get: function () { return file_system_service_js_1.StandardFileSystemService; } });
|
|
38
|
+
__exportStar(require("./types.js"), exports);
|
|
39
|
+
__exportStar(require("./utils/file-utils.js"), exports);
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAKA,yDAAmD;AAA1C,iHAAA,YAAY,OAAA;AACrB,qDAAgD;AAAvC,8GAAA,WAAW,OAAA;AACpB,yEAAkE;AAAzD,gIAAA,mBAAmB,OAAA;AAC5B,2CAAsC;AAA7B,oGAAA,MAAM,OAAA;AACf,+CAA0C;AAAjC,wGAAA,QAAQ,OAAA;AACjB,2DAAqD;AAA5C,mHAAA,aAAa,OAAA;AACtB,+CAA0C;AAAjC,wGAAA,QAAQ,OAAA;AACjB,+CAA0C;AAAjC,wGAAA,QAAQ,OAAA;AACjB,+CAA0C;AAAjC,wGAAA,QAAQ,OAAA;AACjB,mEAAqE;AAA5D,mIAAA,yBAAyB,OAAA;AAClC,6CAA2B;AAC3B,wDAAsC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const lsTool: import("@mastra/core/tools").Tool<z.ZodObject<{
|
|
3
|
+
path: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
4
|
+
recursive: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
path: string;
|
|
7
|
+
recursive: boolean;
|
|
8
|
+
}, {
|
|
9
|
+
path?: string | undefined;
|
|
10
|
+
recursive?: boolean | undefined;
|
|
11
|
+
}>, z.ZodString, any, any, import("@mastra/core/tools").ToolExecutionContext<z.ZodObject<{
|
|
12
|
+
path: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
13
|
+
recursive: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
14
|
+
}, "strip", z.ZodTypeAny, {
|
|
15
|
+
path: string;
|
|
16
|
+
recursive: boolean;
|
|
17
|
+
}, {
|
|
18
|
+
path?: string | undefined;
|
|
19
|
+
recursive?: boolean | undefined;
|
|
20
|
+
}>, any, any>> & {
|
|
21
|
+
inputSchema: z.ZodObject<{
|
|
22
|
+
path: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
23
|
+
recursive: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
24
|
+
}, "strip", z.ZodTypeAny, {
|
|
25
|
+
path: string;
|
|
26
|
+
recursive: boolean;
|
|
27
|
+
}, {
|
|
28
|
+
path?: string | undefined;
|
|
29
|
+
recursive?: boolean | undefined;
|
|
30
|
+
}>;
|
|
31
|
+
outputSchema: z.ZodString;
|
|
32
|
+
execute: (context: import("@mastra/core/tools").ToolExecutionContext<z.ZodObject<{
|
|
33
|
+
path: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
34
|
+
recursive: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
35
|
+
}, "strip", z.ZodTypeAny, {
|
|
36
|
+
path: string;
|
|
37
|
+
recursive: boolean;
|
|
38
|
+
}, {
|
|
39
|
+
path?: string | undefined;
|
|
40
|
+
recursive?: boolean | undefined;
|
|
41
|
+
}>, any, any>, options: import("@mastra/core/tools").MastraToolInvocationOptions) => Promise<any>;
|
|
42
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.lsTool = void 0;
|
|
7
|
+
const tools_1 = require("@mastra/core/tools");
|
|
8
|
+
const zod_1 = require("zod");
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
11
|
+
async function listRecursive(dirPath, basePath, maxDepth = 5, currentDepth = 0) {
|
|
12
|
+
if (currentDepth >= maxDepth) {
|
|
13
|
+
return [`${dirPath}/ (max depth reached)`];
|
|
14
|
+
}
|
|
15
|
+
const results = [];
|
|
16
|
+
const entries = await promises_1.default.readdir(dirPath, { withFileTypes: true });
|
|
17
|
+
for (const entry of entries) {
|
|
18
|
+
const fullPath = node_path_1.default.join(dirPath, entry.name);
|
|
19
|
+
const relativePath = node_path_1.default.relative(basePath, fullPath);
|
|
20
|
+
if (entry.isDirectory()) {
|
|
21
|
+
results.push(`${relativePath}/`);
|
|
22
|
+
try {
|
|
23
|
+
const subResults = await listRecursive(fullPath, basePath, maxDepth, currentDepth + 1);
|
|
24
|
+
results.push(...subResults);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
results.push(`${relativePath}/ (permission denied)`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
const stats = await promises_1.default.stat(fullPath);
|
|
32
|
+
results.push(`${relativePath} (${stats.size} bytes)`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return results;
|
|
36
|
+
}
|
|
37
|
+
exports.lsTool = (0, tools_1.createTool)({
|
|
38
|
+
id: 'ls',
|
|
39
|
+
description: `Lists contents of a directory. Can list recursively with the 'recursive' flag. Shows file sizes and distinguishes directories with trailing slashes.`,
|
|
40
|
+
inputSchema: zod_1.z.object({
|
|
41
|
+
path: zod_1.z
|
|
42
|
+
.string()
|
|
43
|
+
.optional()
|
|
44
|
+
.default('.')
|
|
45
|
+
.describe('The directory path to list (default: current directory).'),
|
|
46
|
+
recursive: zod_1.z
|
|
47
|
+
.boolean()
|
|
48
|
+
.optional()
|
|
49
|
+
.default(false)
|
|
50
|
+
.describe('Optional: List contents recursively (default: false).'),
|
|
51
|
+
}),
|
|
52
|
+
outputSchema: zod_1.z.string().describe('Directory listing or error message'),
|
|
53
|
+
execute: async ({ context }) => {
|
|
54
|
+
const { path: dirPath = '.', recursive = false } = context;
|
|
55
|
+
const resolvedPath = node_path_1.default.resolve(dirPath);
|
|
56
|
+
try {
|
|
57
|
+
const stats = await promises_1.default.stat(resolvedPath);
|
|
58
|
+
if (!stats.isDirectory()) {
|
|
59
|
+
throw new Error(`Path is not a directory: ${dirPath}`);
|
|
60
|
+
}
|
|
61
|
+
let output = `Directory listing: ${dirPath}\n\n`;
|
|
62
|
+
if (recursive) {
|
|
63
|
+
const entries = await listRecursive(resolvedPath, resolvedPath);
|
|
64
|
+
output += entries.join('\n');
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
const entries = await promises_1.default.readdir(resolvedPath, { withFileTypes: true });
|
|
68
|
+
const lines = [];
|
|
69
|
+
for (const entry of entries) {
|
|
70
|
+
const fullPath = node_path_1.default.join(resolvedPath, entry.name);
|
|
71
|
+
if (entry.isDirectory()) {
|
|
72
|
+
lines.push(`${entry.name}/`);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
const stats = await promises_1.default.stat(fullPath);
|
|
76
|
+
lines.push(`${entry.name} (${stats.size} bytes)`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
output += lines.join('\n');
|
|
80
|
+
}
|
|
81
|
+
return output || 'Directory is empty';
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
if (error.code === 'ENOENT') {
|
|
85
|
+
throw new Error(`Directory not found: ${dirPath}`);
|
|
86
|
+
}
|
|
87
|
+
if (error.code === 'EACCES') {
|
|
88
|
+
throw new Error(`Permission denied: ${dirPath}`);
|
|
89
|
+
}
|
|
90
|
+
throw error;
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
//# sourceMappingURL=ls.tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ls.tool.js","sourceRoot":"","sources":["../../src/tools/ls.tool.ts"],"names":[],"mappings":";;;;;;AAKA,8CAAgD;AAChD,6BAAwB;AACxB,0DAA6B;AAC7B,gEAAkC;AAKlC,KAAK,UAAU,aAAa,CAC1B,OAAe,EACf,QAAgB,EAChB,WAAmB,CAAC,EACpB,eAAuB,CAAC;IAExB,IAAI,YAAY,IAAI,QAAQ,EAAE,CAAC;QAC7B,OAAO,CAAC,GAAG,OAAO,uBAAuB,CAAC,CAAC;IAC7C,CAAC;IAED,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,MAAM,OAAO,GAAG,MAAM,kBAAE,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;IAEnE,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,MAAM,QAAQ,GAAG,mBAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QAChD,MAAM,YAAY,GAAG,mBAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAEvD,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;YACxB,OAAO,CAAC,IAAI,CAAC,GAAG,YAAY,GAAG,CAAC,CAAC;YACjC,IAAI,CAAC;gBACH,MAAM,UAAU,GAAG,MAA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AAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBAC5B,MAAM,IAAI,KAAK,CAAC,wBAAwB,OAAO,EAAE,CAAC,CAAC;YACrD,CAAC;YACD,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBAC5B,MAAM,IAAI,KAAK,CAAC,sBAAsB,OAAO,EAAE,CAAC,CAAC;YACnD,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const readFileTool: import("@mastra/core/tools").Tool<z.ZodObject<{
|
|
3
|
+
file_path: z.ZodString;
|
|
4
|
+
offset: z.ZodOptional<z.ZodNumber>;
|
|
5
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
file_path: string;
|
|
8
|
+
offset?: number | undefined;
|
|
9
|
+
limit?: number | undefined;
|
|
10
|
+
}, {
|
|
11
|
+
file_path: string;
|
|
12
|
+
offset?: number | undefined;
|
|
13
|
+
limit?: number | undefined;
|
|
14
|
+
}>, z.ZodString, any, any, import("@mastra/core/tools").ToolExecutionContext<z.ZodObject<{
|
|
15
|
+
file_path: z.ZodString;
|
|
16
|
+
offset: z.ZodOptional<z.ZodNumber>;
|
|
17
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
18
|
+
}, "strip", z.ZodTypeAny, {
|
|
19
|
+
file_path: string;
|
|
20
|
+
offset?: number | undefined;
|
|
21
|
+
limit?: number | undefined;
|
|
22
|
+
}, {
|
|
23
|
+
file_path: string;
|
|
24
|
+
offset?: number | undefined;
|
|
25
|
+
limit?: number | undefined;
|
|
26
|
+
}>, any, any>> & {
|
|
27
|
+
inputSchema: z.ZodObject<{
|
|
28
|
+
file_path: z.ZodString;
|
|
29
|
+
offset: z.ZodOptional<z.ZodNumber>;
|
|
30
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
31
|
+
}, "strip", z.ZodTypeAny, {
|
|
32
|
+
file_path: string;
|
|
33
|
+
offset?: number | undefined;
|
|
34
|
+
limit?: number | undefined;
|
|
35
|
+
}, {
|
|
36
|
+
file_path: string;
|
|
37
|
+
offset?: number | undefined;
|
|
38
|
+
limit?: number | undefined;
|
|
39
|
+
}>;
|
|
40
|
+
outputSchema: z.ZodString;
|
|
41
|
+
execute: (context: import("@mastra/core/tools").ToolExecutionContext<z.ZodObject<{
|
|
42
|
+
file_path: z.ZodString;
|
|
43
|
+
offset: z.ZodOptional<z.ZodNumber>;
|
|
44
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
45
|
+
}, "strip", z.ZodTypeAny, {
|
|
46
|
+
file_path: string;
|
|
47
|
+
offset?: number | undefined;
|
|
48
|
+
limit?: number | undefined;
|
|
49
|
+
}, {
|
|
50
|
+
file_path: string;
|
|
51
|
+
offset?: number | undefined;
|
|
52
|
+
limit?: number | undefined;
|
|
53
|
+
}>, any, any>, options: import("@mastra/core/tools").MastraToolInvocationOptions) => Promise<any>;
|
|
54
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.readFileTool = void 0;
|
|
7
|
+
const tools_1 = require("@mastra/core/tools");
|
|
8
|
+
const zod_1 = require("zod");
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
const file_utils_js_1 = require("./utils/file-utils.js");
|
|
11
|
+
const file_system_service_js_1 = require("./file-system.service.js");
|
|
12
|
+
exports.readFileTool = (0, tools_1.createTool)({
|
|
13
|
+
id: 'read_file',
|
|
14
|
+
description: `Reads and returns the content of a specified file. If the file is large, the content will be truncated. The tool's response will clearly indicate if truncation has occurred and will provide details on how to read more of the file using the 'offset' and 'limit' parameters. Handles text, images (PNG, JPG, GIF, WEBP, SVG, BMP), and PDF files. For text files, it can read specific line ranges.`,
|
|
15
|
+
inputSchema: zod_1.z.object({
|
|
16
|
+
file_path: zod_1.z
|
|
17
|
+
.string()
|
|
18
|
+
.describe('The path to the file to read.'),
|
|
19
|
+
offset: zod_1.z
|
|
20
|
+
.number()
|
|
21
|
+
.int()
|
|
22
|
+
.nonnegative()
|
|
23
|
+
.optional()
|
|
24
|
+
.describe("Optional: For text files, the 0-based line number to start reading from. Use for paginating through large files."),
|
|
25
|
+
limit: zod_1.z
|
|
26
|
+
.number()
|
|
27
|
+
.int()
|
|
28
|
+
.positive()
|
|
29
|
+
.optional()
|
|
30
|
+
.describe("Optional: For text files, maximum number of lines to read. Use with 'offset' to paginate through large files."),
|
|
31
|
+
}),
|
|
32
|
+
outputSchema: zod_1.z.string().describe('The file content or error message'),
|
|
33
|
+
execute: async ({ context }) => {
|
|
34
|
+
const { file_path, offset, limit } = context;
|
|
35
|
+
if (file_path.trim() === '') {
|
|
36
|
+
throw new Error("The 'file_path' parameter must be non-empty.");
|
|
37
|
+
}
|
|
38
|
+
const targetDir = process.cwd();
|
|
39
|
+
const resolvedPath = node_path_1.default.resolve(file_path);
|
|
40
|
+
const fileSystemService = new file_system_service_js_1.StandardFileSystemService();
|
|
41
|
+
const result = await (0, file_utils_js_1.processSingleFileContent)(resolvedPath, targetDir, fileSystemService, offset, limit);
|
|
42
|
+
if (result.error) {
|
|
43
|
+
throw new Error(result.error);
|
|
44
|
+
}
|
|
45
|
+
if (typeof result.llmContent === 'string') {
|
|
46
|
+
if (result.isTruncated) {
|
|
47
|
+
const [start, end] = result.linesShown;
|
|
48
|
+
const total = result.originalLineCount;
|
|
49
|
+
const nextOffset = offset ? offset + end - start + 1 : end;
|
|
50
|
+
return `IMPORTANT: The file content has been truncated.
|
|
51
|
+
Status: Showing lines ${start}-${end} of ${total} total lines.
|
|
52
|
+
Action: To read more of the file, you can use the 'offset' and 'limit' parameters in a subsequent 'read_file' call. For example, to read the next section of the file, use offset: ${nextOffset}.
|
|
53
|
+
|
|
54
|
+
--- FILE CONTENT (truncated) ---
|
|
55
|
+
${result.llmContent}`;
|
|
56
|
+
}
|
|
57
|
+
return result.llmContent;
|
|
58
|
+
}
|
|
59
|
+
const relativePath2 = (0, file_utils_js_1.makeRelative)(resolvedPath, targetDir);
|
|
60
|
+
const inlineData = result.llmContent.inlineData;
|
|
61
|
+
return `File read successfully: ${(0, file_utils_js_1.shortenPath)(relativePath2)}
|
|
62
|
+
Type: ${inlineData.mimeType}
|
|
63
|
+
Size: ${Buffer.from(inlineData.data, 'base64').length} bytes
|
|
64
|
+
|
|
65
|
+
Note: Binary content (image/PDF) has been loaded. The agent can work with this file.
|
|
66
|
+
Base64 data: ${inlineData.data.substring(0, 100)}...`;
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
//# sourceMappingURL=read-file.tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-file.tool.js","sourceRoot":"","sources":["../../src/tools/read-file.tool.ts"],"names":[],"mappings":";;;;;;AAKA,8CAAgD;AAChD,6BAAwB;AACxB,0DAA6B;AAG7B,yDAI+B;AAC/B,qEAAqE;AAQxD,QAAA,YAAY,GAAG,IAAA,kBAAU,EAAC;IACrC,EAAE,EAAE,WAAW;IACf,WAAW,EAAE,yYAAyY;IAEtZ,WAAW,EAAE,OAAC,CAAC,MAAM,CAAC;QACpB,SAAS,EAAE,OAAC;aACT,MAAM,EAAE;aACR,QAAQ,CAAC,+BAA+B,CAAC;QAC5C,MAAM,EAAE,OAAC;aACN,MAAM,EAAE;aACR,GAAG,EAAE;aACL,WAAW,EAAE;aACb,QAAQ,EAAE;aACV,QAAQ,CACP,kHAAkH,CACnH;QACH,KAAK,EAAE,OAAC;aACL,MAAM,EAAE;aACR,GAAG,EAAE;aACL,QAAQ,EAAE;aACV,QAAQ,EAAE;aACV,QAAQ,CACP,+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AAC;YAED,OAAO,MAAM,CAAC,UAAU,CAAC;QAC3B,CAAC;QAGD,MAAM,aAAa,GAAG,IAAA,4BAAY,EAAC,YAAY,EAAE,SAAS,CAAC,CAAC;QAC5D,MAAM,UAAU,GAAI,MAAM,CAAC,UAAkB,CAAC,UAAU,CAAC;QAEzD,OAAO,2BAA2B,IAAA,2BAAW,EAAC,aAAa,CAAC;QACxD,UAAU,CAAC,QAAQ;QACnB,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,MAAM;;;eAGtC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC;IACpD,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const replaceTool: import("@mastra/core/tools").Tool<z.ZodObject<{
|
|
3
|
+
file_path: z.ZodString;
|
|
4
|
+
start_line: z.ZodNumber;
|
|
5
|
+
end_line: z.ZodNumber;
|
|
6
|
+
new_text: z.ZodString;
|
|
7
|
+
}, "strip", z.ZodTypeAny, {
|
|
8
|
+
file_path: string;
|
|
9
|
+
start_line: number;
|
|
10
|
+
end_line: number;
|
|
11
|
+
new_text: string;
|
|
12
|
+
}, {
|
|
13
|
+
file_path: string;
|
|
14
|
+
start_line: number;
|
|
15
|
+
end_line: number;
|
|
16
|
+
new_text: string;
|
|
17
|
+
}>, z.ZodString, any, any, import("@mastra/core/tools").ToolExecutionContext<z.ZodObject<{
|
|
18
|
+
file_path: z.ZodString;
|
|
19
|
+
start_line: z.ZodNumber;
|
|
20
|
+
end_line: z.ZodNumber;
|
|
21
|
+
new_text: z.ZodString;
|
|
22
|
+
}, "strip", z.ZodTypeAny, {
|
|
23
|
+
file_path: string;
|
|
24
|
+
start_line: number;
|
|
25
|
+
end_line: number;
|
|
26
|
+
new_text: string;
|
|
27
|
+
}, {
|
|
28
|
+
file_path: string;
|
|
29
|
+
start_line: number;
|
|
30
|
+
end_line: number;
|
|
31
|
+
new_text: string;
|
|
32
|
+
}>, any, any>> & {
|
|
33
|
+
inputSchema: z.ZodObject<{
|
|
34
|
+
file_path: z.ZodString;
|
|
35
|
+
start_line: z.ZodNumber;
|
|
36
|
+
end_line: z.ZodNumber;
|
|
37
|
+
new_text: z.ZodString;
|
|
38
|
+
}, "strip", z.ZodTypeAny, {
|
|
39
|
+
file_path: string;
|
|
40
|
+
start_line: number;
|
|
41
|
+
end_line: number;
|
|
42
|
+
new_text: string;
|
|
43
|
+
}, {
|
|
44
|
+
file_path: string;
|
|
45
|
+
start_line: number;
|
|
46
|
+
end_line: number;
|
|
47
|
+
new_text: string;
|
|
48
|
+
}>;
|
|
49
|
+
outputSchema: z.ZodString;
|
|
50
|
+
execute: (context: import("@mastra/core/tools").ToolExecutionContext<z.ZodObject<{
|
|
51
|
+
file_path: z.ZodString;
|
|
52
|
+
start_line: z.ZodNumber;
|
|
53
|
+
end_line: z.ZodNumber;
|
|
54
|
+
new_text: z.ZodString;
|
|
55
|
+
}, "strip", z.ZodTypeAny, {
|
|
56
|
+
file_path: string;
|
|
57
|
+
start_line: number;
|
|
58
|
+
end_line: number;
|
|
59
|
+
new_text: string;
|
|
60
|
+
}, {
|
|
61
|
+
file_path: string;
|
|
62
|
+
start_line: number;
|
|
63
|
+
end_line: number;
|
|
64
|
+
new_text: string;
|
|
65
|
+
}>, any, any>, options: import("@mastra/core/tools").MastraToolInvocationOptions) => Promise<any>;
|
|
66
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.replaceTool = void 0;
|
|
7
|
+
const tools_1 = require("@mastra/core/tools");
|
|
8
|
+
const zod_1 = require("zod");
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
11
|
+
exports.replaceTool = (0, tools_1.createTool)({
|
|
12
|
+
id: 'replace',
|
|
13
|
+
description: `Replaces a range of lines in a file with new text. Useful for editing existing files. Requires start_line, end_line, and new_text parameters. Line numbers are 1-based.`,
|
|
14
|
+
inputSchema: zod_1.z.object({
|
|
15
|
+
file_path: zod_1.z
|
|
16
|
+
.string()
|
|
17
|
+
.describe('The path to the file to modify.'),
|
|
18
|
+
start_line: zod_1.z
|
|
19
|
+
.number()
|
|
20
|
+
.int()
|
|
21
|
+
.positive()
|
|
22
|
+
.describe('The starting line number to replace (1-based, inclusive).'),
|
|
23
|
+
end_line: zod_1.z
|
|
24
|
+
.number()
|
|
25
|
+
.int()
|
|
26
|
+
.positive()
|
|
27
|
+
.describe('The ending line number to replace (1-based, inclusive).'),
|
|
28
|
+
new_text: zod_1.z
|
|
29
|
+
.string()
|
|
30
|
+
.describe('The new text to insert in place of the specified lines.'),
|
|
31
|
+
}),
|
|
32
|
+
outputSchema: zod_1.z.string().describe('Success message or error'),
|
|
33
|
+
execute: async ({ context }) => {
|
|
34
|
+
const { file_path, start_line, end_line, new_text } = context;
|
|
35
|
+
if (file_path.trim() === '') {
|
|
36
|
+
throw new Error("The 'file_path' parameter must be non-empty.");
|
|
37
|
+
}
|
|
38
|
+
if (start_line > end_line) {
|
|
39
|
+
throw new Error(`Invalid line range: start_line (${start_line}) must be <= end_line (${end_line}).`);
|
|
40
|
+
}
|
|
41
|
+
const resolvedPath = node_path_1.default.resolve(file_path);
|
|
42
|
+
try {
|
|
43
|
+
await promises_1.default.access(resolvedPath);
|
|
44
|
+
const content = await promises_1.default.readFile(resolvedPath, 'utf-8');
|
|
45
|
+
const lines = content.split('\n');
|
|
46
|
+
if (start_line < 1 || start_line > lines.length) {
|
|
47
|
+
throw new Error(`start_line (${start_line}) is out of range. File has ${lines.length} lines.`);
|
|
48
|
+
}
|
|
49
|
+
if (end_line > lines.length) {
|
|
50
|
+
throw new Error(`end_line (${end_line}) is out of range. File has ${lines.length} lines.`);
|
|
51
|
+
}
|
|
52
|
+
const newLines = new_text.split('\n');
|
|
53
|
+
lines.splice(start_line - 1, end_line - start_line + 1, ...newLines);
|
|
54
|
+
await promises_1.default.writeFile(resolvedPath, lines.join('\n'), 'utf-8');
|
|
55
|
+
return `Successfully replaced lines ${start_line}-${end_line} in ${file_path}`;
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (error.code === 'ENOENT') {
|
|
59
|
+
throw new Error(`File not found: ${file_path}`);
|
|
60
|
+
}
|
|
61
|
+
if (error.code === 'EACCES') {
|
|
62
|
+
throw new Error(`Permission denied: ${file_path}`);
|
|
63
|
+
}
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
//# sourceMappingURL=replace.tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replace.tool.js","sourceRoot":"","sources":["../../src/tools/replace.tool.ts"],"names":[],"mappings":";;;;;;AAKA,8CAAgD;AAChD,6BAAwB;AACxB,0DAA6B;AAC7B,gEAAkC;AAOrB,QAAA,WAAW,GAAG,IAAA,kBAAU,EAAC;IACpC,EAAE,EAAE,SAAS;IACb,WAAW,EAAE,yKAAyK;IAEtL,WAAW,EAAE,OAAC,CAAC,MAAM,CAAC;QACpB,SAAS,EAAE,OAAC;aACT,MAAM,EAAE;aACR,QAAQ,CAAC,iCAAiC,CAAC;QAC9C,UAAU,EAAE,OAAC;aACV,MAAM,EAAE;aACR,GAAG,EAAE;aACL,QAAQ,EAAE;aACV,QAAQ,CAAC,2DAA2D,CAAC;QACxE,QAAQ,EAAE,OAAC;aACR,MAAM,EAAE;aACR,GAAG,EAAE;aACL,QAAQ,EAAE;aACV,QAAQ,CAAC,yDAAyD,CAAC;QACtE,QAAQ,EAAE,OAAC;aACR,MAAM,EAAE;aAC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KAAK,CAAC,MAAM,CAAC,UAAU,GAAG,CAAC,EAAE,QAAQ,GAAG,UAAU,GAAG,CAAC,EAAE,GAAG,QAAQ,CAAC,CAAC;YAGrE,MAAM,kBAAE,CAAC,SAAS,CAAC,YAAY,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC;YAE5D,OAAO,+BAA+B,UAAU,IAAI,QAAQ,OAAO,SAAS,EAAE,CAAC;QACjF,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBAC5B,MAAM,IAAI,KAAK,CAAC,mBAAmB,SAAS,EAAE,CAAC,CAAC;YAClD,CAAC;YACD,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBAC5B,MAAM,IAAI,KAAK,CAAC,sBAAsB,SAAS,EAAE,CAAC,CAAC;YACrD,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const runShellCommandTool: import("@mastra/core/tools").Tool<z.ZodObject<{
|
|
3
|
+
command: z.ZodString;
|
|
4
|
+
timeout_seconds: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
command: string;
|
|
7
|
+
timeout_seconds: number;
|
|
8
|
+
}, {
|
|
9
|
+
command: string;
|
|
10
|
+
timeout_seconds?: number | undefined;
|
|
11
|
+
}>, z.ZodString, any, any, import("@mastra/core/tools").ToolExecutionContext<z.ZodObject<{
|
|
12
|
+
command: z.ZodString;
|
|
13
|
+
timeout_seconds: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
14
|
+
}, "strip", z.ZodTypeAny, {
|
|
15
|
+
command: string;
|
|
16
|
+
timeout_seconds: number;
|
|
17
|
+
}, {
|
|
18
|
+
command: string;
|
|
19
|
+
timeout_seconds?: number | undefined;
|
|
20
|
+
}>, any, any>> & {
|
|
21
|
+
inputSchema: z.ZodObject<{
|
|
22
|
+
command: z.ZodString;
|
|
23
|
+
timeout_seconds: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
24
|
+
}, "strip", z.ZodTypeAny, {
|
|
25
|
+
command: string;
|
|
26
|
+
timeout_seconds: number;
|
|
27
|
+
}, {
|
|
28
|
+
command: string;
|
|
29
|
+
timeout_seconds?: number | undefined;
|
|
30
|
+
}>;
|
|
31
|
+
outputSchema: z.ZodString;
|
|
32
|
+
execute: (context: import("@mastra/core/tools").ToolExecutionContext<z.ZodObject<{
|
|
33
|
+
command: z.ZodString;
|
|
34
|
+
timeout_seconds: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
35
|
+
}, "strip", z.ZodTypeAny, {
|
|
36
|
+
command: string;
|
|
37
|
+
timeout_seconds: number;
|
|
38
|
+
}, {
|
|
39
|
+
command: string;
|
|
40
|
+
timeout_seconds?: number | undefined;
|
|
41
|
+
}>, any, any>, options: import("@mastra/core/tools").MastraToolInvocationOptions) => Promise<any>;
|
|
42
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runShellCommandTool = void 0;
|
|
4
|
+
const tools_1 = require("@mastra/core/tools");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const node_child_process_1 = require("node:child_process");
|
|
7
|
+
const node_util_1 = require("node:util");
|
|
8
|
+
const execAsync = (0, node_util_1.promisify)(node_child_process_1.exec);
|
|
9
|
+
exports.runShellCommandTool = (0, tools_1.createTool)({
|
|
10
|
+
id: 'run_shell_command',
|
|
11
|
+
description: `Executes a shell command and returns its output (stdout and stderr). Supports optional timeout in seconds. Use with caution as this can execute any shell command.`,
|
|
12
|
+
inputSchema: zod_1.z.object({
|
|
13
|
+
command: zod_1.z
|
|
14
|
+
.string()
|
|
15
|
+
.describe('The shell command to execute.'),
|
|
16
|
+
timeout_seconds: zod_1.z
|
|
17
|
+
.number()
|
|
18
|
+
.int()
|
|
19
|
+
.positive()
|
|
20
|
+
.optional()
|
|
21
|
+
.default(30)
|
|
22
|
+
.describe('Optional: Maximum execution time in seconds (default: 30).'),
|
|
23
|
+
}),
|
|
24
|
+
outputSchema: zod_1.z.string().describe('Command output or error message'),
|
|
25
|
+
execute: async ({ context }) => {
|
|
26
|
+
const { command, timeout_seconds = 30 } = context;
|
|
27
|
+
if (command.trim() === '') {
|
|
28
|
+
throw new Error("The 'command' parameter must be non-empty.");
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const { stdout, stderr } = await execAsync(command, {
|
|
32
|
+
timeout: timeout_seconds * 1000,
|
|
33
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
34
|
+
cwd: process.cwd(),
|
|
35
|
+
});
|
|
36
|
+
let output = '';
|
|
37
|
+
if (stdout) {
|
|
38
|
+
output += `STDOUT:\n${stdout}`;
|
|
39
|
+
}
|
|
40
|
+
if (stderr) {
|
|
41
|
+
output += stdout ? '\n\n' : '';
|
|
42
|
+
output += `STDERR:\n${stderr}`;
|
|
43
|
+
}
|
|
44
|
+
return output || 'Command executed successfully (no output)';
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (error.killed && error.signal === 'SIGTERM') {
|
|
48
|
+
throw new Error(`Command timed out after ${timeout_seconds} seconds`);
|
|
49
|
+
}
|
|
50
|
+
let errorMsg = `Command failed: ${command}\n`;
|
|
51
|
+
if (error.stdout) {
|
|
52
|
+
errorMsg += `\nSTDOUT:\n${error.stdout}`;
|
|
53
|
+
}
|
|
54
|
+
if (error.stderr) {
|
|
55
|
+
errorMsg += `\nSTDERR:\n${error.stderr}`;
|
|
56
|
+
}
|
|
57
|
+
if (error.code !== undefined) {
|
|
58
|
+
errorMsg += `\nExit code: ${error.code}`;
|
|
59
|
+
}
|
|
60
|
+
throw new Error(errorMsg);
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
//# sourceMappingURL=run-shell-command.tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-shell-command.tool.js","sourceRoot":"","sources":["../../src/tools/run-shell-command.tool.ts"],"names":[],"mappings":";;;AAKA,8CAAgD;AAChD,6BAAwB;AACxB,2DAA0C;AAC1C,yCAAsC;AAEtC,MAAM,SAAS,GAAG,IAAA,qBAAS,EAAC,yBAAI,CAAC,CAAC;AAOrB,QAAA,mBAAmB,GAAG,IAAA,kBAAU,EAAC;IAC5C,EAAE,EAAE,mBAAmB;IACvB,WAAW,EAAE,oKAAoK;IAEjL,WAAW,EAAE,OAAC,CAAC,MAAM,CAAC;QACpB,OAAO,EAAE,OAAC;aACP,MAAM,EAAE;aACR,QAAQ,CAAC,+BAA+B,CAAC;QAC5C,eAAe,EAAE,OAAC;aACf,MAAM,EAAE;aACR,GAAG,EAAE;aACL,QAAQ,EAAE;aACV,QAAQ,EAAE;aACV,OAAO,CAAC,EAAE,CAAC;aACX,QAAQ,CAAC,4DAA4D,CAAC;KAC1E,CAAC;IAEF,YAAY,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,iCAAiC,CAAC;IAEpE,OAAO,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;QAC7B,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC;QAGlD,IAAI,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;QAChE,CAAC;QAED,IAAI,CAAC;YACH,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,SAAS,CAAC,OAAO,EAAE;gBAClD,OAAO,EAAE,eAAe,GAAG,IAAI;gBAC/B,SAA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: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
4
|
+
max_depth: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
path: string;
|
|
7
|
+
max_depth: number;
|
|
8
|
+
}, {
|
|
9
|
+
path?: string | undefined;
|
|
10
|
+
max_depth?: number | undefined;
|
|
11
|
+
}>, z.ZodString, any, any, import("@mastra/core/tools").ToolExecutionContext<z.ZodObject<{
|
|
12
|
+
path: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
13
|
+
max_depth: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
14
|
+
}, "strip", z.ZodTypeAny, {
|
|
15
|
+
path: string;
|
|
16
|
+
max_depth: number;
|
|
17
|
+
}, {
|
|
18
|
+
path?: string | undefined;
|
|
19
|
+
max_depth?: number | undefined;
|
|
20
|
+
}>, any, any>> & {
|
|
21
|
+
inputSchema: z.ZodObject<{
|
|
22
|
+
path: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
23
|
+
max_depth: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
24
|
+
}, "strip", z.ZodTypeAny, {
|
|
25
|
+
path: string;
|
|
26
|
+
max_depth: number;
|
|
27
|
+
}, {
|
|
28
|
+
path?: string | undefined;
|
|
29
|
+
max_depth?: number | undefined;
|
|
30
|
+
}>;
|
|
31
|
+
outputSchema: z.ZodString;
|
|
32
|
+
execute: (context: import("@mastra/core/tools").ToolExecutionContext<z.ZodObject<{
|
|
33
|
+
path: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
34
|
+
max_depth: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
35
|
+
}, "strip", z.ZodTypeAny, {
|
|
36
|
+
path: string;
|
|
37
|
+
max_depth: number;
|
|
38
|
+
}, {
|
|
39
|
+
path?: string | undefined;
|
|
40
|
+
max_depth?: number | undefined;
|
|
41
|
+
}>, any, any>, options: import("@mastra/core/tools").MastraToolInvocationOptions) => Promise<any>;
|
|
42
|
+
};
|