@sowonai/crewx-sdk 0.5.0 → 0.6.0-rc.1

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.
Files changed (75) hide show
  1. package/dist/adapters/MastraToolAdapter.d.ts +9 -0
  2. package/dist/adapters/MastraToolAdapter.js +66 -0
  3. package/dist/adapters/MastraToolAdapter.js.map +1 -0
  4. package/dist/config/api-provider-parser.d.ts +56 -0
  5. package/dist/config/api-provider-parser.js +214 -0
  6. package/dist/config/api-provider-parser.js.map +1 -0
  7. package/dist/config/index.d.ts +2 -0
  8. package/dist/config/index.js +2 -0
  9. package/dist/config/index.js.map +1 -1
  10. package/dist/core/agent/agent-factory.d.ts +4 -2
  11. package/dist/core/agent/agent-factory.js +11 -0
  12. package/dist/core/agent/agent-factory.js.map +1 -1
  13. package/dist/core/providers/MastraAPIProvider.d.ts +24 -0
  14. package/dist/core/providers/MastraAPIProvider.js +264 -0
  15. package/dist/core/providers/MastraAPIProvider.js.map +1 -0
  16. package/dist/core/providers/ai-provider.interface.d.ts +1 -0
  17. package/dist/core/providers/ai-provider.interface.js.map +1 -1
  18. package/dist/core/providers/provider-factory.js +38 -0
  19. package/dist/core/providers/provider-factory.js.map +1 -1
  20. package/dist/index.d.ts +10 -0
  21. package/dist/index.js +37 -2
  22. package/dist/index.js.map +1 -1
  23. package/dist/schemas/api-provider.schema.d.ts +429 -0
  24. package/dist/schemas/api-provider.schema.js +48 -0
  25. package/dist/schemas/api-provider.schema.js.map +1 -0
  26. package/dist/tools/file-system.service.d.ts +10 -0
  27. package/dist/tools/file-system.service.js +33 -0
  28. package/dist/tools/file-system.service.js.map +1 -0
  29. package/dist/tools/find.tool.d.ts +85 -0
  30. package/dist/tools/find.tool.js +140 -0
  31. package/dist/tools/find.tool.js.map +1 -0
  32. package/dist/tools/glob.tool.d.ts +100 -0
  33. package/dist/tools/glob.tool.js +153 -0
  34. package/dist/tools/glob.tool.js.map +1 -0
  35. package/dist/tools/grep.tool.d.ts +54 -0
  36. package/dist/tools/grep.tool.js +137 -0
  37. package/dist/tools/grep.tool.js.map +1 -0
  38. package/dist/tools/index.d.ts +12 -0
  39. package/dist/tools/index.js +40 -0
  40. package/dist/tools/index.js.map +1 -0
  41. package/dist/tools/ls.tool.d.ts +42 -0
  42. package/dist/tools/ls.tool.js +94 -0
  43. package/dist/tools/ls.tool.js.map +1 -0
  44. package/dist/tools/read-file.tool.d.ts +54 -0
  45. package/dist/tools/read-file.tool.js +69 -0
  46. package/dist/tools/read-file.tool.js.map +1 -0
  47. package/dist/tools/replace.tool.d.ts +66 -0
  48. package/dist/tools/replace.tool.js +68 -0
  49. package/dist/tools/replace.tool.js.map +1 -0
  50. package/dist/tools/run-shell-command.tool.d.ts +42 -0
  51. package/dist/tools/run-shell-command.tool.js +64 -0
  52. package/dist/tools/run-shell-command.tool.js.map +1 -0
  53. package/dist/tools/tree.tool.d.ts +42 -0
  54. package/dist/tools/tree.tool.js +109 -0
  55. package/dist/tools/tree.tool.js.map +1 -0
  56. package/dist/tools/types.d.ts +42 -0
  57. package/dist/tools/types.js +13 -0
  58. package/dist/tools/types.js.map +1 -0
  59. package/dist/tools/utils/file-utils.d.ts +5 -0
  60. package/dist/tools/utils/file-utils.js +221 -0
  61. package/dist/tools/utils/file-utils.js.map +1 -0
  62. package/dist/tools/write-file.tool.d.ts +42 -0
  63. package/dist/tools/write-file.tool.js +55 -0
  64. package/dist/tools/write-file.tool.js.map +1 -0
  65. package/dist/types/agent.types.d.ts +2 -2
  66. package/dist/types/api-provider.types.d.ts +80 -0
  67. package/dist/types/api-provider.types.js +53 -0
  68. package/dist/types/api-provider.types.js.map +1 -0
  69. package/dist/types/index.d.ts +1 -0
  70. package/dist/types/index.js +1 -0
  71. package/dist/types/index.js.map +1 -1
  72. package/dist/utils/api-provider-normalizer.d.ts +16 -0
  73. package/dist/utils/api-provider-normalizer.js +135 -0
  74. package/dist/utils/api-provider-normalizer.js.map +1 -0
  75. package/package.json +5 -1
@@ -0,0 +1,109 @@
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.treeTool = 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
+ const INDENT_UNIT = ' ';
12
+ async function buildTreeLines(dirPath, options) {
13
+ const { currentDepth, maxDepth } = options;
14
+ let entries;
15
+ try {
16
+ entries = await promises_1.default.readdir(dirPath, { withFileTypes: true });
17
+ }
18
+ catch (error) {
19
+ const indent = INDENT_UNIT.repeat(currentDepth);
20
+ const reason = error?.code === 'EACCES' ? 'permission denied' : error?.message || 'unknown error';
21
+ return [`${indent}(error reading directory: ${reason})`];
22
+ }
23
+ if (entries.length === 0) {
24
+ return [`${INDENT_UNIT.repeat(currentDepth)}(empty)`];
25
+ }
26
+ entries.sort((a, b) => {
27
+ if (a.isDirectory() && !b.isDirectory())
28
+ return -1;
29
+ if (!a.isDirectory() && b.isDirectory())
30
+ return 1;
31
+ return a.name.localeCompare(b.name);
32
+ });
33
+ const lines = [];
34
+ for (const entry of entries) {
35
+ const indent = INDENT_UNIT.repeat(currentDepth);
36
+ const fullPath = node_path_1.default.join(dirPath, entry.name);
37
+ if (entry.isDirectory()) {
38
+ lines.push(`${indent}[DIR] ${entry.name}/`);
39
+ if (currentDepth < maxDepth) {
40
+ const childLines = await buildTreeLines(fullPath, {
41
+ currentDepth: currentDepth + 1,
42
+ maxDepth,
43
+ });
44
+ lines.push(...childLines);
45
+ }
46
+ else {
47
+ lines.push(`${INDENT_UNIT.repeat(currentDepth + 1)}(max depth reached)`);
48
+ }
49
+ }
50
+ else {
51
+ try {
52
+ const stats = await promises_1.default.stat(fullPath);
53
+ lines.push(`${indent}[FILE] ${entry.name} (${stats.size} bytes)`);
54
+ }
55
+ catch (error) {
56
+ lines.push(`${indent}[FILE] ${entry.name} (error: ${error?.code || 'stat failed'})`);
57
+ }
58
+ }
59
+ }
60
+ return lines;
61
+ }
62
+ exports.treeTool = (0, tools_1.createTool)({
63
+ id: 'tree',
64
+ description: `Displays a directory tree similar to the Unix 'tree' command. Shows nested directories up to 'max_depth' levels with [DIR]/[FILE] labels and indentation to represent hierarchy.`,
65
+ inputSchema: zod_1.z.object({
66
+ path: zod_1.z
67
+ .string()
68
+ .optional()
69
+ .default('.')
70
+ .describe('Path of the directory to inspect (default: current working directory).'),
71
+ max_depth: zod_1.z
72
+ .number()
73
+ .int()
74
+ .min(1)
75
+ .optional()
76
+ .default(3)
77
+ .describe('Maximum depth to traverse relative to the root directory (default: 3).'),
78
+ }),
79
+ outputSchema: zod_1.z.string().describe('Formatted tree output or an error message'),
80
+ execute: async ({ context }) => {
81
+ const { path: targetPath = '.', max_depth = 3 } = context;
82
+ const resolvedPath = node_path_1.default.resolve(targetPath);
83
+ try {
84
+ const stats = await promises_1.default.stat(resolvedPath);
85
+ if (!stats.isDirectory()) {
86
+ throw new Error(`Path is not a directory: ${targetPath}`);
87
+ }
88
+ }
89
+ catch (error) {
90
+ if (error?.code === 'ENOENT') {
91
+ throw new Error(`Directory not found: ${targetPath}`);
92
+ }
93
+ if (error?.code === 'EACCES') {
94
+ throw new Error(`Permission denied: ${targetPath}`);
95
+ }
96
+ throw error;
97
+ }
98
+ const relativeRoot = node_path_1.default.relative(process.cwd(), resolvedPath);
99
+ const rootLabel = relativeRoot === '' ? '.' : relativeRoot;
100
+ const lines = [`Tree for ${rootLabel} (max depth: ${max_depth})`, `[DIR] ${rootLabel}/`];
101
+ const treeLines = await buildTreeLines(resolvedPath, {
102
+ currentDepth: 1,
103
+ maxDepth: max_depth,
104
+ });
105
+ lines.push(...treeLines);
106
+ return lines.join('\n');
107
+ },
108
+ });
109
+ //# sourceMappingURL=tree.tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"t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AAE,CAAC,CAAC;YACtD,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;QAED,MAAM,YAAY,GAAG,mBAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,YAAY,CAAC,CAAC;QAChE,MAAM,SAAS,GAAG,YAAY,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC;QAE3D,MAAM,KAAK,GAAG,CAAC,YAAY,SAAS,gBAAgB,SAAS,GAAG,EAAE,SAAS,SAAS,GAAG,CAAC,CAAC;QACzF,MAAM,SAAS,GAAG,MAAM,cAAc,CAAC,YAAY,EAAE;YACnD,YAAY,EAAE,CAAC;YACf,QAAQ,EAAE,SAAS;SACpB,CAAC,CAAC;QAEH,KAAK,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,CAAC;QAEzB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,42 @@
1
+ export interface ToolExecutionContext {
2
+ workingDirectory: string;
3
+ isPathWithinWorkspace(path: string): boolean;
4
+ fileSystemService: FileSystemService;
5
+ shouldIgnoreFile(path: string): boolean;
6
+ agentId: string;
7
+ provider: string;
8
+ model: string;
9
+ env: Record<string, string | undefined>;
10
+ vars: Record<string, any>;
11
+ }
12
+ export interface FileSystemService {
13
+ readFile(path: string): Promise<Buffer>;
14
+ exists(path: string): Promise<boolean>;
15
+ stat(path: string): Promise<{
16
+ size: number;
17
+ isDirectory: boolean;
18
+ }>;
19
+ readdir(path: string): Promise<string[]>;
20
+ }
21
+ export interface ProcessedFileReadResult {
22
+ llmContent: string | {
23
+ inlineData: {
24
+ data: string;
25
+ mimeType: string;
26
+ };
27
+ };
28
+ returnDisplay: string;
29
+ error?: string;
30
+ errorType?: ToolErrorType;
31
+ isTruncated?: boolean;
32
+ originalLineCount?: number;
33
+ linesShown?: [number, number];
34
+ }
35
+ export declare enum ToolErrorType {
36
+ FILE_NOT_FOUND = "FILE_NOT_FOUND",
37
+ PATH_IS_DIRECTORY = "PATH_IS_DIRECTORY",
38
+ FILE_TOO_LARGE = "FILE_TOO_LARGE",
39
+ BINARY_FILE = "BINARY_FILE",
40
+ PERMISSION_DENIED = "PERMISSION_DENIED",
41
+ UNKNOWN = "UNKNOWN"
42
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ToolErrorType = void 0;
4
+ var ToolErrorType;
5
+ (function (ToolErrorType) {
6
+ ToolErrorType["FILE_NOT_FOUND"] = "FILE_NOT_FOUND";
7
+ ToolErrorType["PATH_IS_DIRECTORY"] = "PATH_IS_DIRECTORY";
8
+ ToolErrorType["FILE_TOO_LARGE"] = "FILE_TOO_LARGE";
9
+ ToolErrorType["BINARY_FILE"] = "BINARY_FILE";
10
+ ToolErrorType["PERMISSION_DENIED"] = "PERMISSION_DENIED";
11
+ ToolErrorType["UNKNOWN"] = "UNKNOWN";
12
+ })(ToolErrorType || (exports.ToolErrorType = ToolErrorType = {}));
13
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/tools/types.ts"],"names":[],"mappings":";;;AAkDA,IAAY,aAOX;AAPD,WAAY,aAAa;IACvB,kDAAiC,CAAA;IACjC,wDAAuC,CAAA;IACvC,kDAAiC,CAAA;IACjC,4CAA2B,CAAA;IAC3B,wDAAuC,CAAA;IACvC,oCAAmB,CAAA;AACrB,CAAC,EAPW,aAAa,6BAAb,aAAa,QAOxB"}
@@ -0,0 +1,5 @@
1
+ import type { FileSystemService, ProcessedFileReadResult } from '../types.js';
2
+ export declare function getSpecificMimeType(filePath: string): string;
3
+ export declare function processSingleFileContent(filePath: string, rootDirectory: string, fileSystemService: FileSystemService, offset?: number, limit?: number): Promise<ProcessedFileReadResult>;
4
+ export declare function makeRelative(absolutePath: string, rootDir: string): string;
5
+ export declare function shortenPath(filePath: string, maxLength?: number): string;
@@ -0,0 +1,221 @@
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.getSpecificMimeType = getSpecificMimeType;
7
+ exports.processSingleFileContent = processSingleFileContent;
8
+ exports.makeRelative = makeRelative;
9
+ exports.shortenPath = shortenPath;
10
+ const node_path_1 = __importDefault(require("node:path"));
11
+ const MAX_FILE_SIZE = 20 * 1024 * 1024;
12
+ const MAX_LINE_LENGTH = 2000;
13
+ const DEFAULT_MAX_LINES = 2000;
14
+ const IMAGE_EXTENSIONS = new Set([
15
+ '.png',
16
+ '.jpg',
17
+ '.jpeg',
18
+ '.gif',
19
+ '.webp',
20
+ '.svg',
21
+ '.bmp',
22
+ ]);
23
+ const PDF_EXTENSION = '.pdf';
24
+ function detectBOM(buffer) {
25
+ if (buffer.length >= 3 &&
26
+ buffer[0] === 0xef &&
27
+ buffer[1] === 0xbb &&
28
+ buffer[2] === 0xbf) {
29
+ return { encoding: 'utf8', offset: 3 };
30
+ }
31
+ if (buffer.length >= 2 && buffer[0] === 0xfe && buffer[1] === 0xff) {
32
+ return { encoding: 'utf16le', offset: 2 };
33
+ }
34
+ if (buffer.length >= 2 && buffer[0] === 0xff && buffer[1] === 0xfe) {
35
+ if (buffer.length >= 4 && buffer[2] === 0x00 && buffer[3] === 0x00) {
36
+ return { encoding: 'utf8', offset: 4 };
37
+ }
38
+ return { encoding: 'utf16le', offset: 2 };
39
+ }
40
+ if (buffer.length >= 4 &&
41
+ buffer[0] === 0x00 &&
42
+ buffer[1] === 0x00 &&
43
+ buffer[2] === 0xfe &&
44
+ buffer[3] === 0xff) {
45
+ return { encoding: 'utf8', offset: 4 };
46
+ }
47
+ return { encoding: 'utf8', offset: 0 };
48
+ }
49
+ function isBinaryFile(buffer) {
50
+ const sampleSize = Math.min(8000, buffer.length);
51
+ const sample = buffer.subarray(0, sampleSize);
52
+ let nullBytes = 0;
53
+ let suspiciousBytes = 0;
54
+ for (let i = 0; i < sample.length; i++) {
55
+ const byte = sample[i];
56
+ if (byte === undefined)
57
+ continue;
58
+ if (byte === 0) {
59
+ nullBytes++;
60
+ }
61
+ if (byte < 32 && byte !== 9 && byte !== 10 && byte !== 13) {
62
+ suspiciousBytes++;
63
+ }
64
+ }
65
+ return (nullBytes > sampleSize * 0.01 || suspiciousBytes > sampleSize * 0.1);
66
+ }
67
+ function getSpecificMimeType(filePath) {
68
+ const ext = node_path_1.default.extname(filePath).toLowerCase();
69
+ const mimeTypes = {
70
+ '.png': 'image/png',
71
+ '.jpg': 'image/jpeg',
72
+ '.jpeg': 'image/jpeg',
73
+ '.gif': 'image/gif',
74
+ '.webp': 'image/webp',
75
+ '.svg': 'image/svg+xml',
76
+ '.bmp': 'image/bmp',
77
+ '.pdf': 'application/pdf',
78
+ };
79
+ return mimeTypes[ext] || 'application/octet-stream';
80
+ }
81
+ function detectFileType(filePath, buffer) {
82
+ const ext = node_path_1.default.extname(filePath).toLowerCase();
83
+ if (IMAGE_EXTENSIONS.has(ext)) {
84
+ return 'image';
85
+ }
86
+ if (ext === PDF_EXTENSION) {
87
+ return 'pdf';
88
+ }
89
+ if (isBinaryFile(buffer)) {
90
+ return 'binary';
91
+ }
92
+ return 'text';
93
+ }
94
+ async function processSingleFileContent(filePath, rootDirectory, fileSystemService, offset, limit) {
95
+ try {
96
+ const exists = await fileSystemService.exists(filePath);
97
+ if (!exists) {
98
+ return {
99
+ llmContent: '',
100
+ returnDisplay: `File not found: ${filePath}`,
101
+ error: `File not found: ${filePath}`,
102
+ errorType: 'FILE_NOT_FOUND',
103
+ };
104
+ }
105
+ const stats = await fileSystemService.stat(filePath);
106
+ if (stats.isDirectory) {
107
+ return {
108
+ llmContent: '',
109
+ returnDisplay: `Path is a directory: ${filePath}`,
110
+ error: `Path is a directory: ${filePath}`,
111
+ errorType: 'PATH_IS_DIRECTORY',
112
+ };
113
+ }
114
+ if (stats.size > MAX_FILE_SIZE) {
115
+ return {
116
+ llmContent: '',
117
+ returnDisplay: `File too large: ${stats.size} bytes (max: ${MAX_FILE_SIZE})`,
118
+ error: `File too large: ${stats.size} bytes (max: ${MAX_FILE_SIZE})`,
119
+ errorType: 'FILE_TOO_LARGE',
120
+ };
121
+ }
122
+ const buffer = await fileSystemService.readFile(filePath);
123
+ const fileType = detectFileType(filePath, buffer);
124
+ if (fileType === 'image' || fileType === 'pdf') {
125
+ const base64Data = buffer.toString('base64');
126
+ const mimeType = getSpecificMimeType(filePath);
127
+ return {
128
+ llmContent: {
129
+ inlineData: {
130
+ data: base64Data,
131
+ mimeType,
132
+ },
133
+ },
134
+ returnDisplay: `Read ${fileType} file: ${node_path_1.default.basename(filePath)} (${stats.size} bytes)`,
135
+ };
136
+ }
137
+ if (fileType === 'binary') {
138
+ return {
139
+ llmContent: '',
140
+ returnDisplay: `Binary file detected: ${filePath}`,
141
+ error: `Binary file detected: ${filePath}`,
142
+ errorType: 'BINARY_FILE',
143
+ };
144
+ }
145
+ const { encoding, offset: bomOffset } = detectBOM(buffer);
146
+ const content = buffer.subarray(bomOffset).toString(encoding);
147
+ const lines = content.split('\n');
148
+ let startLine = offset || 0;
149
+ let endLine = limit ? startLine + limit : lines.length;
150
+ let isTruncated = false;
151
+ if (!limit && lines.length > DEFAULT_MAX_LINES) {
152
+ endLine = DEFAULT_MAX_LINES;
153
+ isTruncated = true;
154
+ }
155
+ if (endLine > lines.length) {
156
+ endLine = lines.length;
157
+ }
158
+ else if (endLine < lines.length) {
159
+ isTruncated = true;
160
+ }
161
+ const selectedLines = lines.slice(startLine, endLine);
162
+ const truncatedLines = selectedLines.map((line) => {
163
+ if (line.length > MAX_LINE_LENGTH) {
164
+ return line.substring(0, MAX_LINE_LENGTH) + '...';
165
+ }
166
+ return line;
167
+ });
168
+ const formattedContent = truncatedLines
169
+ .map((line, i) => `${startLine + i + 1}→${line}`)
170
+ .join('\n');
171
+ const relativePath = node_path_1.default.relative(rootDirectory, filePath);
172
+ return {
173
+ llmContent: formattedContent,
174
+ returnDisplay: `Read ${relativePath} (lines ${startLine + 1}-${endLine})`,
175
+ isTruncated,
176
+ originalLineCount: lines.length,
177
+ linesShown: [startLine + 1, endLine],
178
+ };
179
+ }
180
+ catch (error) {
181
+ return {
182
+ llmContent: '',
183
+ returnDisplay: `Error reading file: ${error.message}`,
184
+ error: error.message,
185
+ errorType: 'UNKNOWN',
186
+ };
187
+ }
188
+ }
189
+ function makeRelative(absolutePath, rootDir) {
190
+ const relative = node_path_1.default.relative(rootDir, absolutePath);
191
+ if (relative.startsWith('..')) {
192
+ return absolutePath;
193
+ }
194
+ return relative;
195
+ }
196
+ function shortenPath(filePath, maxLength = 50) {
197
+ if (filePath.length <= maxLength) {
198
+ return filePath;
199
+ }
200
+ const parts = filePath.split(node_path_1.default.sep);
201
+ const filename = parts[parts.length - 1];
202
+ if (!filename) {
203
+ return filePath;
204
+ }
205
+ if (filename.length > maxLength) {
206
+ return '...' + filename.substring(filename.length - maxLength + 3);
207
+ }
208
+ let shortened = filename;
209
+ for (let i = parts.length - 2; i >= 0; i--) {
210
+ const part = parts[i];
211
+ if (!part)
212
+ continue;
213
+ const candidate = part + node_path_1.default.sep + shortened;
214
+ if (candidate.length > maxLength) {
215
+ return '...' + node_path_1.default.sep + shortened;
216
+ }
217
+ shortened = candidate;
218
+ }
219
+ return shortened;
220
+ }
221
+ //# sourceMappingURL=file-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-utils.js","sourceRoot":"","sources":["../../../src/tools/utils/file-utils.ts"],"names":[],"mappings":";;;;;AA+GA,kDAeC;AAgCD,4DAkIC;AAKD,oCAOC;AAKD,kCAgCC;AA5UD,0DAA6B;AAQ7B,MAAM,aAAa,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AACvC,MAAM,eAAe,GAAG,IAAI,CAAC;AAC7B,MAAM,iBAAiB,GAAG,IAAI,CAAC;A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,CAAC,CAAC,CAAC;IACzC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,QAAQ,CAAC;IAClB,CAAC;IAGD,IAAI,QAAQ,CAAC,MAAM,GAAG,SAAS,EAAE,CAAC;QAChC,OAAO,KAAK,GAAG,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,GAAG,SAAS,GAAG,CAAC,CAAC,CAAC;IACrE,CAAC;IAGD,IAAI,SAAS,GAAG,QAAQ,CAAC;IACzB,KAAK,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3C,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,CAAC,IAAI;YAAE,SAAS;QACpB,MAAM,SAAS,GAAG,IAAI,GAAG,mBAAI,CAAC,GAAG,GAAG,SAAS,CAAC;QAC9C,IAAI,SAAS,CAAC,MAAM,GAAG,SAAS,EAAE,CAAC;YACjC,OAAO,KAAK,GAAG,mBAAI,CAAC,GAAG,GAAG,SAAS,CAAC;QACtC,CAAC;QACD,SAAS,GAAG,SAAS,CAAC;IACxB,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,42 @@
1
+ import { z } from 'zod';
2
+ export declare const writeFileTool: import("@mastra/core/tools").Tool<z.ZodObject<{
3
+ file_path: z.ZodString;
4
+ content: z.ZodString;
5
+ }, "strip", z.ZodTypeAny, {
6
+ file_path: string;
7
+ content: string;
8
+ }, {
9
+ file_path: string;
10
+ content: string;
11
+ }>, z.ZodString, any, any, import("@mastra/core/tools").ToolExecutionContext<z.ZodObject<{
12
+ file_path: z.ZodString;
13
+ content: z.ZodString;
14
+ }, "strip", z.ZodTypeAny, {
15
+ file_path: string;
16
+ content: string;
17
+ }, {
18
+ file_path: string;
19
+ content: string;
20
+ }>, any, any>> & {
21
+ inputSchema: z.ZodObject<{
22
+ file_path: z.ZodString;
23
+ content: z.ZodString;
24
+ }, "strip", z.ZodTypeAny, {
25
+ file_path: string;
26
+ content: string;
27
+ }, {
28
+ file_path: string;
29
+ content: string;
30
+ }>;
31
+ outputSchema: z.ZodString;
32
+ execute: (context: import("@mastra/core/tools").ToolExecutionContext<z.ZodObject<{
33
+ file_path: z.ZodString;
34
+ content: z.ZodString;
35
+ }, "strip", z.ZodTypeAny, {
36
+ file_path: string;
37
+ content: string;
38
+ }, {
39
+ file_path: string;
40
+ content: string;
41
+ }>, any, any>, options: import("@mastra/core/tools").MastraToolInvocationOptions) => Promise<any>;
42
+ };
@@ -0,0 +1,55 @@
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.writeFileTool = 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.writeFileTool = (0, tools_1.createTool)({
12
+ id: 'write_file',
13
+ description: `Creates a new file or overwrites an existing file with the provided content. Use with caution as this will replace existing files without warning.`,
14
+ inputSchema: zod_1.z.object({
15
+ file_path: zod_1.z
16
+ .string()
17
+ .describe('The path to the file to create or overwrite.'),
18
+ content: zod_1.z
19
+ .string()
20
+ .describe('The content to write to the file.'),
21
+ }),
22
+ outputSchema: zod_1.z.string().describe('Success message or error'),
23
+ execute: async ({ context }) => {
24
+ const { file_path, content } = context;
25
+ if (file_path.trim() === '') {
26
+ throw new Error("The 'file_path' parameter must be non-empty.");
27
+ }
28
+ const resolvedPath = node_path_1.default.resolve(file_path);
29
+ try {
30
+ const parentDir = node_path_1.default.dirname(resolvedPath);
31
+ await promises_1.default.mkdir(parentDir, { recursive: true });
32
+ let fileExists = false;
33
+ try {
34
+ await promises_1.default.access(resolvedPath);
35
+ fileExists = true;
36
+ }
37
+ catch {
38
+ }
39
+ await promises_1.default.writeFile(resolvedPath, content, 'utf-8');
40
+ const action = fileExists ? 'Updated' : 'Created';
41
+ const size = Buffer.byteLength(content, 'utf-8');
42
+ return `${action} file: ${file_path} (${size} bytes)`;
43
+ }
44
+ catch (error) {
45
+ if (error.code === 'EACCES') {
46
+ throw new Error(`Permission denied: ${file_path}`);
47
+ }
48
+ if (error.code === 'EISDIR') {
49
+ throw new Error(`Path is a directory: ${file_path}`);
50
+ }
51
+ throw error;
52
+ }
53
+ },
54
+ });
55
+ //# sourceMappingURL=write-file.tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write-file.tool.js","sourceRoot":"","sources":["../../src/tools/write-file.tool.ts"],"names":[],"mappings":";;;;;;AAKA,8CAAgD;AAChD,6BAAwB;AACxB,0DAA6B;AAC7B,gEAAkC;AAOrB,QAAA,aAAa,GAAG,IAAA,kBAAU,EAAC;IACtC,EAAE,EAAE,YAAY;IAChB,WAAW,EAAE,oJAAoJ;IAEjK,WAAW,EAAE,OAAC,CAAC,MAAM,CAAC;QACpB,SAAS,EAAE,OAAC;aACT,MAAM,EAAE;aACR,QAAQ,CAAC,8CAA8C,CAAC;QAC3D,OAAO,EAAE,OAAC;aACP,MAAM,EAAE;aACR,QAAQ,CAAC,mCAAmC,CAAC;KACjD,CAAC;IAEF,YAAY,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,0BAA0B,CAAC;IAE7D,OAAO,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;QAC7B,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;QAGvC,IAAI,SAAS,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;QAClE,CAAC;QAED,MAAM,YAAY,GAAG,mBAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAE7C,IAAI,CAAC;YAEH,MAAM,SAAS,GAAG,mBAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;YAC7C,MAAM,kBAAE,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAG/C,IAAI,UAAU,GAAG,KAAK,CAAC;YACvB,IAAI,CAAC;gBACH,MAAM,kBAAE,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;gBAC9B,UAAU,GAAG,IAAI,CAAC;YACpB,CAAC;YAAC,MAAM,CAAC;YAET,CAAC;YAGD,MAAM,kBAAE,CAAC,SAAS,CAAC,YAAY,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;YAEnD,MAAM,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;YAClD,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YACjD,OAAO,GAAG,MAAM,UAAU,SAAS,KAAK,IAAI,SAAS,CAAC;QACxD,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBAC5B,MAAM,IAAI,KAAK,CAAC,sBAAsB,SAAS,EAAE,CAAC,CAAC;YACrD,CAAC;YACD,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBAC5B,MAAM,IAAI,KAAK,CAAC,wBAAwB,SAAS,EAAE,CAAC,CAAC;YACvD,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF,CAAC,CAAC"}
@@ -91,7 +91,7 @@ export interface AgentInfo {
91
91
  name?: string;
92
92
  role?: string;
93
93
  team?: string;
94
- provider: 'claude' | 'gemini' | 'copilot' | 'remote' | `remote/${string}` | ('claude' | 'gemini' | 'copilot')[];
94
+ provider: 'claude' | 'gemini' | 'copilot' | 'remote' | `remote/${string}` | `api/${string}` | ('claude' | 'gemini' | 'copilot')[];
95
95
  workingDirectory: string;
96
96
  capabilities: string[];
97
97
  description: string;
@@ -111,7 +111,7 @@ export interface AgentInfo {
111
111
  };
112
112
  inline?: {
113
113
  type: 'agent';
114
- provider?: 'claude' | 'gemini' | 'copilot' | 'remote' | `plugin/${string}` | `cli/${string}` | string;
114
+ provider?: 'claude' | 'gemini' | 'copilot' | 'remote' | `plugin/${string}` | `cli/${string}` | `api/${string}` | string;
115
115
  system_prompt?: string;
116
116
  prompt?: string;
117
117
  model?: string;
@@ -0,0 +1,80 @@
1
+ export type APIProviderType = 'api/openai' | 'api/anthropic' | 'api/google' | 'api/bedrock' | 'api/litellm' | 'api/ollama' | 'api/sowonai';
2
+ export type ProviderExecutionMode = 'query' | 'execute';
3
+ export interface ProviderModeOptions {
4
+ tools?: string[];
5
+ mcp?: string[];
6
+ }
7
+ export interface ProviderOptions {
8
+ query?: ProviderModeOptions;
9
+ execute?: ProviderModeOptions;
10
+ [customMode: string]: ProviderModeOptions | undefined;
11
+ }
12
+ export interface LegacyProviderPermissionConfig {
13
+ tools?: string[];
14
+ mcp?: string[];
15
+ mcp_servers?: string[];
16
+ }
17
+ export interface APIProviderConfig extends LegacyProviderPermissionConfig {
18
+ id?: string;
19
+ provider: APIProviderType;
20
+ url?: string;
21
+ apiKey?: string;
22
+ model: string;
23
+ temperature?: number;
24
+ maxTokens?: number;
25
+ options?: ProviderOptions;
26
+ }
27
+ export interface MCPServerConfig {
28
+ command: string;
29
+ args: string[];
30
+ env?: Record<string, string>;
31
+ }
32
+ export interface FrameworkToolDefinition {
33
+ name: string;
34
+ description: string;
35
+ parameters: any;
36
+ execute: (args: any, context: ToolExecutionContext) => Promise<any>;
37
+ }
38
+ export interface ToolExecutionContext {
39
+ agent: {
40
+ id: string;
41
+ provider: string;
42
+ model: string;
43
+ temperature?: number;
44
+ maxTokens?: number;
45
+ };
46
+ agentMetadata?: Record<string, any>;
47
+ env: Record<string, string>;
48
+ context?: Record<string, any>;
49
+ vars?: Record<string, any>;
50
+ mode?: 'query' | 'execute';
51
+ messages?: any[];
52
+ platform?: string;
53
+ tools?: {
54
+ available: string[];
55
+ count: number;
56
+ json?: string;
57
+ };
58
+ documents?: Record<string, {
59
+ content?: string;
60
+ toc?: string;
61
+ summary?: string;
62
+ }>;
63
+ request?: {
64
+ timestamp: Date;
65
+ conversationId?: string;
66
+ threadId?: string;
67
+ };
68
+ crewx?: CrewXInstance;
69
+ }
70
+ export interface CrewXInstance {
71
+ getAgent(agentId: string): any;
72
+ runAgent(agentId: string, options: {
73
+ input: string;
74
+ context?: Record<string, any>;
75
+ }): Promise<any>;
76
+ }
77
+ export declare function isProviderModeOptions(candidate: unknown): candidate is ProviderModeOptions;
78
+ export declare function isProviderOptions(candidate: unknown): candidate is ProviderOptions;
79
+ export declare function isLegacyProviderPermissionConfig(candidate: unknown): candidate is LegacyProviderPermissionConfig;
80
+ export declare function convertLegacyPermissionsToProviderOptions(legacy: LegacyProviderPermissionConfig, mode?: ProviderExecutionMode): ProviderOptions;