@codebolt/agent 5.0.7 → 5.0.9

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 (160) hide show
  1. package/dist/processor-pieces/base/basePreToolCallProcessor.js +5 -2
  2. package/dist/processor-pieces/messageModifiers/argumentProcessorModifier.d.ts +1 -1
  3. package/dist/processor-pieces/messageModifiers/argumentProcessorModifier.js +2 -2
  4. package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.js +24 -34
  5. package/dist/processor-pieces/messageModifiers/chatRecordingModifier.d.ts +1 -1
  6. package/dist/processor-pieces/messageModifiers/chatRecordingModifier.js +2 -2
  7. package/dist/processor-pieces/messageModifiers/coreSystemPromptModifier.d.ts +1 -1
  8. package/dist/processor-pieces/messageModifiers/coreSystemPromptModifier.js +2 -2
  9. package/dist/processor-pieces/messageModifiers/directoryContextModifier.d.ts +1 -1
  10. package/dist/processor-pieces/messageModifiers/directoryContextModifier.js +8 -3
  11. package/dist/processor-pieces/messageModifiers/environmentContextModifier.d.ts +1 -1
  12. package/dist/processor-pieces/messageModifiers/environmentContextModifier.js +1 -1
  13. package/dist/processor-pieces/messageModifiers/ideContextModifier.js +114 -17
  14. package/dist/processor-pieces/messageModifiers/memoryImportModifier.d.ts +1 -1
  15. package/dist/processor-pieces/messageModifiers/memoryImportModifier.js +13 -5
  16. package/dist/processor-pieces/messageModifiers/toolInjectionModifier.d.ts +5 -0
  17. package/dist/processor-pieces/messageModifiers/toolInjectionModifier.js +4 -0
  18. package/dist/processor-pieces/postInferenceProcessors/loopDetectionModifier.js +24 -8
  19. package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.d.ts +202 -5
  20. package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.js +826 -19
  21. package/dist/processor-pieces/postToolCallProcessors/index.d.ts +1 -1
  22. package/dist/processor-pieces/postToolCallProcessors/index.js +2 -1
  23. package/dist/processor-pieces/postToolCallProcessors/shellProcessorModifier.js +7 -4
  24. package/dist/processor-pieces/preInferenceProcessors/chatCompressionModifier.d.ts +1 -1
  25. package/dist/processor-pieces/preInferenceProcessors/chatCompressionModifier.js +12 -16
  26. package/dist/processor-pieces/pretoolCallProcessors/toolParameterModifier.d.ts +2 -3
  27. package/dist/processor-pieces/pretoolCallProcessors/toolParameterModifier.js +1 -2
  28. package/dist/processor-pieces/utils/messageModifierHelper.js +5 -2
  29. package/dist/types/InternalTypes.d.ts +8 -6
  30. package/dist/unified/agent/agent.js +1 -2
  31. package/dist/unified/agent/codeboltAgent.d.ts +23 -2
  32. package/dist/unified/agent/codeboltAgent.js +55 -12
  33. package/dist/unified/agent/tools.d.ts +7 -11
  34. package/dist/unified/agent/tools.js +12 -3
  35. package/dist/unified/agent/workflow.js +38 -20
  36. package/dist/unified/agent/workflowSteps.d.ts +1 -1
  37. package/dist/unified/agent/workflowSteps.js +58 -23
  38. package/dist/unified/base/agentStep.js +20 -1
  39. package/dist/unified/base/initialPromptGenerator.js +3 -1
  40. package/dist/unified/base/responseExecutor.d.ts +3 -0
  41. package/dist/unified/base/responseExecutor.js +47 -21
  42. package/dist/unified/index.d.ts +1 -0
  43. package/dist/unified/index.js +4 -1
  44. package/dist/unified/services/LoopDetectionService.d.ts +44 -0
  45. package/dist/unified/services/LoopDetectionService.js +79 -0
  46. package/dist/unified/utils/utils.d.ts +20 -1
  47. package/dist/unified/utils/utils.js +8 -4
  48. package/package.json +5 -5
  49. package/dist/agent.d.ts +0 -86
  50. package/dist/agent.js +0 -324
  51. package/dist/builderpattern/agent.d.ts +0 -86
  52. package/dist/builderpattern/agent.js +0 -324
  53. package/dist/builderpattern/followupquestionbuilder.d.ts +0 -75
  54. package/dist/builderpattern/followupquestionbuilder.js +0 -197
  55. package/dist/builderpattern/index.d.ts +0 -14
  56. package/dist/builderpattern/index.js +0 -23
  57. package/dist/builderpattern/llmoutputhandler.d.ts +0 -102
  58. package/dist/builderpattern/llmoutputhandler.js +0 -452
  59. package/dist/builderpattern/promptbuilder.d.ts +0 -382
  60. package/dist/builderpattern/promptbuilder.js +0 -805
  61. package/dist/builderpattern/systemprompt.d.ts +0 -20
  62. package/dist/builderpattern/systemprompt.js +0 -48
  63. package/dist/builderpattern/taskInstruction.d.ts +0 -37
  64. package/dist/builderpattern/taskInstruction.js +0 -57
  65. package/dist/builderpattern/usermessage.d.ts +0 -70
  66. package/dist/builderpattern/usermessage.js +0 -123
  67. package/dist/composablepattern/agent.d.ts +0 -169
  68. package/dist/composablepattern/agent.js +0 -598
  69. package/dist/composablepattern/codebolt-storage.d.ts +0 -67
  70. package/dist/composablepattern/codebolt-storage.js +0 -320
  71. package/dist/composablepattern/document.d.ts +0 -149
  72. package/dist/composablepattern/document.js +0 -405
  73. package/dist/composablepattern/examples/codebolt-integration-example.d.ts +0 -12
  74. package/dist/composablepattern/examples/codebolt-integration-example.js +0 -218
  75. package/dist/composablepattern/examples/codebolt-storage-example.d.ts +0 -40
  76. package/dist/composablepattern/examples/codebolt-storage-example.js +0 -223
  77. package/dist/composablepattern/examples/custom-steps-example.d.ts +0 -20
  78. package/dist/composablepattern/examples/custom-steps-example.js +0 -455
  79. package/dist/composablepattern/examples/document-agent.d.ts +0 -17
  80. package/dist/composablepattern/examples/document-agent.js +0 -107
  81. package/dist/composablepattern/examples/simple-codebolt-integration.d.ts +0 -8
  82. package/dist/composablepattern/examples/simple-codebolt-integration.js +0 -164
  83. package/dist/composablepattern/examples/weather-agent.d.ts +0 -18
  84. package/dist/composablepattern/examples/weather-agent.js +0 -86
  85. package/dist/composablepattern/examples/workflow-example.d.ts +0 -12
  86. package/dist/composablepattern/examples/workflow-example.js +0 -463
  87. package/dist/composablepattern/index.d.ts +0 -63
  88. package/dist/composablepattern/index.js +0 -115
  89. package/dist/composablepattern/memory.d.ts +0 -89
  90. package/dist/composablepattern/memory.js +0 -141
  91. package/dist/composablepattern/tool.d.ts +0 -84
  92. package/dist/composablepattern/tool.js +0 -260
  93. package/dist/composablepattern/types.d.ts +0 -194
  94. package/dist/composablepattern/types.js +0 -6
  95. package/dist/composablepattern/user-context.d.ts +0 -214
  96. package/dist/composablepattern/user-context.js +0 -275
  97. package/dist/composablepattern/workflow.d.ts +0 -388
  98. package/dist/composablepattern/workflow.js +0 -562
  99. package/dist/followupquestionbuilder.d.ts +0 -75
  100. package/dist/followupquestionbuilder.js +0 -197
  101. package/dist/index.d.ts +0 -14
  102. package/dist/index.js +0 -23
  103. package/dist/llmoutputhandler.d.ts +0 -102
  104. package/dist/llmoutputhandler.js +0 -452
  105. package/dist/processor/agent/agentStep.d.ts +0 -49
  106. package/dist/processor/agent/agentStep.js +0 -241
  107. package/dist/processor/agent/toolExecutor.d.ts +0 -19
  108. package/dist/processor/agent/toolExecutor.js +0 -90
  109. package/dist/processor/index.d.ts +0 -7
  110. package/dist/processor/index.js +0 -36
  111. package/dist/processor/messageModifiers/baseMessageModifier.d.ts +0 -20
  112. package/dist/processor/messageModifiers/baseMessageModifier.js +0 -55
  113. package/dist/processor/processors/baseProcessor.d.ts +0 -14
  114. package/dist/processor/processors/baseProcessor.js +0 -29
  115. package/dist/processor/tools/baseTool.d.ts +0 -10
  116. package/dist/processor/tools/baseTool.js +0 -20
  117. package/dist/processor/tools/toolList.d.ts +0 -9
  118. package/dist/processor/tools/toolList.js +0 -22
  119. package/dist/processor/types/interfaces.d.ts +0 -94
  120. package/dist/processor/types/interfaces.js +0 -2
  121. package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.d.ts +0 -22
  122. package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.js +0 -144
  123. package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.d.ts +0 -15
  124. package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.js +0 -75
  125. package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.d.ts +0 -11
  126. package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.js +0 -46
  127. package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.d.ts +0 -12
  128. package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.js +0 -60
  129. package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.d.ts +0 -18
  130. package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.js +0 -222
  131. package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.d.ts +0 -22
  132. package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.js +0 -194
  133. package/dist/processor-pieces/processors/advancedLoopDetectionProcessor.d.ts +0 -41
  134. package/dist/processor-pieces/processors/advancedLoopDetectionProcessor.js +0 -197
  135. package/dist/processor-pieces/processors/chatCompressionProcessor.d.ts +0 -26
  136. package/dist/processor-pieces/processors/chatCompressionProcessor.js +0 -90
  137. package/dist/processor-pieces/processors/chatRecordingProcessor.d.ts +0 -81
  138. package/dist/processor-pieces/processors/chatRecordingProcessor.js +0 -329
  139. package/dist/processor-pieces/processors/contextManagementProcessor.d.ts +0 -40
  140. package/dist/processor-pieces/processors/contextManagementProcessor.js +0 -305
  141. package/dist/processor-pieces/processors/loopDetectionProcessor.d.ts +0 -30
  142. package/dist/processor-pieces/processors/loopDetectionProcessor.js +0 -137
  143. package/dist/processor-pieces/processors/responseValidationProcessor.d.ts +0 -30
  144. package/dist/processor-pieces/processors/responseValidationProcessor.js +0 -228
  145. package/dist/processor-pieces/processors/telemetryProcessor.d.ts +0 -99
  146. package/dist/processor-pieces/processors/telemetryProcessor.js +0 -311
  147. package/dist/processor-pieces/processors/tokenManagementProcessor.d.ts +0 -37
  148. package/dist/processor-pieces/processors/tokenManagementProcessor.js +0 -178
  149. package/dist/processor-pieces/processors/toolExecutionProcessor.d.ts +0 -43
  150. package/dist/processor-pieces/processors/toolExecutionProcessor.js +0 -207
  151. package/dist/processor-pieces/tools/fileTools.d.ts +0 -26
  152. package/dist/processor-pieces/tools/fileTools.js +0 -162
  153. package/dist/promptbuilder.d.ts +0 -382
  154. package/dist/promptbuilder.js +0 -805
  155. package/dist/systemprompt.d.ts +0 -20
  156. package/dist/systemprompt.js +0 -48
  157. package/dist/taskInstruction.d.ts +0 -37
  158. package/dist/taskInstruction.js +0 -57
  159. package/dist/usermessage.d.ts +0 -70
  160. package/dist/usermessage.js +0 -123
@@ -1,207 +0,0 @@
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.ToolExecutionProcessor = void 0;
7
- const processor_1 = require("../../processor");
8
- const codeboltjs_1 = __importDefault(require("@codebolt/codeboltjs"));
9
- class ToolExecutionProcessor extends processor_1.BaseProcessor {
10
- constructor(options = {}) {
11
- super(options);
12
- this.executedTools = new Map();
13
- this.enableToolConfirmation = options.enableToolConfirmation !== false;
14
- this.maxRetries = options.maxRetries || 3;
15
- this.retryDelay = options.retryDelay || 1000;
16
- this.enableLogging = options.enableLogging !== false;
17
- }
18
- async processInput(input) {
19
- try {
20
- const { message, context } = input;
21
- // Check if message contains tool calls
22
- const toolCalls = this.extractToolCalls(message);
23
- if (toolCalls.length === 0) {
24
- return [this.createEvent('NoToolCalls', {
25
- reason: 'No tool calls found in message'
26
- })];
27
- }
28
- const events = [
29
- this.createEvent('ToolCallsDetected', {
30
- count: toolCalls.length,
31
- tools: toolCalls.map(tc => tc.function.name)
32
- })
33
- ];
34
- // Process each tool call
35
- for (const toolCall of toolCalls) {
36
- const executionInfo = await this.processToolCall(toolCall, context);
37
- if (executionInfo.needsConfirmation) {
38
- events.push(this.createEvent('ToolConfirmationRequired', executionInfo));
39
- }
40
- else {
41
- const result = await this.executeTool(executionInfo);
42
- events.push(this.createEvent('ToolExecuted', result));
43
- }
44
- }
45
- // Add summary event
46
- events.push(this.createEvent('ToolExecutionSummary', {
47
- totalTools: toolCalls.length,
48
- executedTools: Array.from(this.executedTools.values()),
49
- successRate: this.calculateSuccessRate()
50
- }));
51
- return events;
52
- }
53
- catch (error) {
54
- console.error('Error in ToolExecutionProcessor:', error);
55
- return [this.createEvent('ToolExecutionError', {
56
- error: error instanceof Error ? error.message : String(error)
57
- })];
58
- }
59
- }
60
- extractToolCalls(message) {
61
- const toolCalls = [];
62
- message.messages.forEach((msg) => {
63
- if (msg.tool_calls && Array.isArray(msg.tool_calls)) {
64
- toolCalls.push(...msg.tool_calls);
65
- }
66
- });
67
- return toolCalls;
68
- }
69
- async processToolCall(toolCall, context) {
70
- const [toolbox, toolName] = toolCall.function.name.split('--');
71
- if (!toolbox || !toolName) {
72
- throw new Error(`Invalid tool name format: ${toolCall.function.name}`);
73
- }
74
- // Parse tool arguments
75
- let parameters = {};
76
- try {
77
- parameters = typeof toolCall.function.arguments === 'string'
78
- ? JSON.parse(toolCall.function.arguments)
79
- : toolCall.function.arguments;
80
- }
81
- catch (error) {
82
- console.warn(`Failed to parse tool arguments for ${toolCall.function.name}:`, error);
83
- }
84
- // Check if tool needs confirmation
85
- const needsConfirmation = this.shouldConfirmTool(toolCall, parameters);
86
- return {
87
- toolCall,
88
- toolName,
89
- toolbox,
90
- parameters,
91
- needsConfirmation
92
- };
93
- }
94
- shouldConfirmTool(toolCall, parameters) {
95
- // Check for dangerous operations
96
- const dangerousOperations = [
97
- 'delete', 'remove', 'drop', 'destroy', 'format', 'wipe',
98
- 'shutdown', 'restart', 'kill', 'terminate'
99
- ];
100
- const toolName = toolCall.function.name.toLowerCase();
101
- const hasDangerousOperation = dangerousOperations.some(op => toolName.includes(op));
102
- // Check for file system operations with important paths
103
- if (parameters.filePath || parameters.path) {
104
- const path = (parameters.filePath || parameters.path || '').toLowerCase();
105
- const importantPaths = ['/', 'c:', 'system', 'windows', 'etc', 'usr'];
106
- const hasImportantPath = importantPaths.some(ip => path.includes(ip));
107
- if (hasImportantPath) {
108
- return true;
109
- }
110
- }
111
- // Check for network operations
112
- if (parameters.url || parameters.host || parameters.port) {
113
- return true;
114
- }
115
- return hasDangerousOperation;
116
- }
117
- async executeTool(executionInfo) {
118
- const startTime = Date.now();
119
- const { toolCall, toolbox, toolName, parameters } = executionInfo;
120
- try {
121
- // Execute tool using CodeBolt's MCP
122
- const { data } = await codeboltjs_1.default.mcp.executeTool(toolbox, toolName, parameters);
123
- // Data comes as [failure: boolean, content: string] from CodeBolt MCP
124
- let resultData;
125
- let success = true;
126
- if (Array.isArray(data) && data.length >= 2) {
127
- const [failure, content] = data;
128
- if (failure) {
129
- success = false;
130
- resultData = content; // Content is error message on failure
131
- }
132
- else {
133
- resultData = content; // Content is result on success
134
- }
135
- }
136
- else {
137
- // Fallback for unexpected data format
138
- console.warn(`[Tool] Unexpected data format from ${toolCall.function.name}:`, data);
139
- resultData = data;
140
- }
141
- const executionResult = {
142
- toolCallId: toolCall.id,
143
- result: resultData,
144
- success: success,
145
- executionTime: Date.now() - startTime,
146
- error: success ? undefined : String(resultData)
147
- };
148
- // Store result
149
- this.executedTools.set(toolCall.id, executionResult);
150
- // Log execution if enabled
151
- if (this.enableLogging) {
152
- console.log(`[Tool] Successfully executed ${toolbox}--${toolName} in ${executionResult.executionTime}ms`);
153
- }
154
- return executionResult;
155
- }
156
- catch (error) {
157
- const executionResult = {
158
- toolCallId: toolCall.id,
159
- result: null,
160
- error: error instanceof Error ? error.message : String(error),
161
- success: false,
162
- executionTime: Date.now() - startTime
163
- };
164
- // Store result
165
- this.executedTools.set(toolCall.id, executionResult);
166
- // Log error if enabled
167
- if (this.enableLogging) {
168
- console.error(`[Tool] Failed to execute ${toolbox}--${toolName}:`, error);
169
- }
170
- return executionResult;
171
- }
172
- }
173
- calculateSuccessRate() {
174
- if (this.executedTools.size === 0)
175
- return 0;
176
- const successfulTools = Array.from(this.executedTools.values())
177
- .filter(result => result.success).length;
178
- return (successfulTools / this.executedTools.size) * 100;
179
- }
180
- // Public methods for external control
181
- async confirmToolExecution(toolCallId, confirmed) {
182
- // This method can be used to track confirmation status in the future
183
- // For now, we'll just log the confirmation
184
- if (this.enableLogging) {
185
- console.log(`[ToolExecutor] Tool ${toolCallId} confirmation: ${confirmed}`);
186
- }
187
- }
188
- getToolExecutionHistory() {
189
- return Array.from(this.executedTools.values());
190
- }
191
- clearToolHistory() {
192
- this.executedTools.clear();
193
- }
194
- setMaxRetries(maxRetries) {
195
- this.maxRetries = Math.max(1, maxRetries);
196
- }
197
- setRetryDelay(delay) {
198
- this.retryDelay = Math.max(100, delay);
199
- }
200
- enableLoggingForSession() {
201
- this.enableLogging = true;
202
- }
203
- disableLoggingForSession() {
204
- this.enableLogging = false;
205
- }
206
- }
207
- exports.ToolExecutionProcessor = ToolExecutionProcessor;
@@ -1,26 +0,0 @@
1
- import { BaseTool } from '../../processor';
2
- export declare class FileReadTool extends BaseTool {
3
- constructor();
4
- execute(params: any, abortSignal?: AbortSignal): Promise<string>;
5
- protected validateParameters(params: any): boolean;
6
- }
7
- export declare class FileWriteTool extends BaseTool {
8
- constructor();
9
- execute(params: any, abortSignal?: AbortSignal): Promise<string>;
10
- protected validateParameters(params: any): boolean;
11
- }
12
- export declare class FileDeleteTool extends BaseTool {
13
- constructor();
14
- execute(params: any, abortSignal?: AbortSignal): Promise<string>;
15
- protected validateParameters(params: any): boolean;
16
- }
17
- export declare class FileMoveTool extends BaseTool {
18
- constructor();
19
- execute(params: any, abortSignal?: AbortSignal): Promise<string>;
20
- protected validateParameters(params: any): boolean;
21
- }
22
- export declare class FileCopyTool extends BaseTool {
23
- constructor();
24
- execute(params: any, abortSignal?: AbortSignal): Promise<string>;
25
- protected validateParameters(params: any): boolean;
26
- }
@@ -1,162 +0,0 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.FileCopyTool = exports.FileMoveTool = exports.FileDeleteTool = exports.FileWriteTool = exports.FileReadTool = void 0;
37
- const processor_1 = require("../../processor");
38
- const fs = __importStar(require("fs/promises"));
39
- const path = __importStar(require("path"));
40
- class FileReadTool extends processor_1.BaseTool {
41
- constructor() {
42
- super('FileRead', 'Read content from a file', {
43
- filePath: { type: 'string', required: true, description: 'Path to the file to read' }
44
- });
45
- }
46
- async execute(params, abortSignal) {
47
- await this.checkAbortSignal(abortSignal);
48
- if (!this.validateParameters(params)) {
49
- throw new Error('Invalid parameters: filePath is required');
50
- }
51
- const { filePath } = params;
52
- const content = await fs.readFile(filePath, 'utf-8');
53
- return content;
54
- }
55
- validateParameters(params) {
56
- return params && typeof params.filePath === 'string' && params.filePath.trim() !== '';
57
- }
58
- }
59
- exports.FileReadTool = FileReadTool;
60
- class FileWriteTool extends processor_1.BaseTool {
61
- constructor() {
62
- super('FileWrite', 'Write content to a file', {
63
- filePath: { type: 'string', required: true, description: 'Path to the file to write' },
64
- content: { type: 'string', required: true, description: 'Content to write to the file' }
65
- });
66
- }
67
- async execute(params, abortSignal) {
68
- await this.checkAbortSignal(abortSignal);
69
- if (!this.validateParameters(params)) {
70
- throw new Error('Invalid parameters: filePath and content are required');
71
- }
72
- const { filePath, content } = params;
73
- // Ensure directory exists
74
- const dir = path.dirname(filePath);
75
- await fs.mkdir(dir, { recursive: true });
76
- await fs.writeFile(filePath, content, 'utf-8');
77
- return `Successfully wrote ${content.length} characters to ${filePath}`;
78
- }
79
- validateParameters(params) {
80
- return params &&
81
- typeof params.filePath === 'string' &&
82
- params.filePath.trim() !== '' &&
83
- typeof params.content === 'string';
84
- }
85
- }
86
- exports.FileWriteTool = FileWriteTool;
87
- class FileDeleteTool extends processor_1.BaseTool {
88
- constructor() {
89
- super('FileDelete', 'Delete a file', {
90
- filePath: { type: 'string', required: true, description: 'Path to the file to delete' }
91
- });
92
- }
93
- async execute(params, abortSignal) {
94
- await this.checkAbortSignal(abortSignal);
95
- if (!this.validateParameters(params)) {
96
- throw new Error('Invalid parameters: filePath is required');
97
- }
98
- const { filePath } = params;
99
- await fs.unlink(filePath);
100
- return `Successfully deleted ${filePath}`;
101
- }
102
- validateParameters(params) {
103
- return params && typeof params.filePath === 'string' && params.filePath.trim() !== '';
104
- }
105
- }
106
- exports.FileDeleteTool = FileDeleteTool;
107
- class FileMoveTool extends processor_1.BaseTool {
108
- constructor() {
109
- super('FileMove', 'Move a file from one location to another', {
110
- sourcePath: { type: 'string', required: true, description: 'Source file path' },
111
- destinationPath: { type: 'string', required: true, description: 'Destination file path' }
112
- });
113
- }
114
- async execute(params, abortSignal) {
115
- await this.checkAbortSignal(abortSignal);
116
- if (!this.validateParameters(params)) {
117
- throw new Error('Invalid parameters: sourcePath and destinationPath are required');
118
- }
119
- const { sourcePath, destinationPath } = params;
120
- // Ensure destination directory exists
121
- const dir = path.dirname(destinationPath);
122
- await fs.mkdir(dir, { recursive: true });
123
- await fs.rename(sourcePath, destinationPath);
124
- return `Successfully moved ${sourcePath} to ${destinationPath}`;
125
- }
126
- validateParameters(params) {
127
- return params &&
128
- typeof params.sourcePath === 'string' &&
129
- params.sourcePath.trim() !== '' &&
130
- typeof params.destinationPath === 'string' &&
131
- params.destinationPath.trim() !== '';
132
- }
133
- }
134
- exports.FileMoveTool = FileMoveTool;
135
- class FileCopyTool extends processor_1.BaseTool {
136
- constructor() {
137
- super('FileCopy', 'Copy a file from one location to another', {
138
- sourcePath: { type: 'string', required: true, description: 'Source file path' },
139
- destinationPath: { type: 'string', required: true, description: 'Destination file path' }
140
- });
141
- }
142
- async execute(params, abortSignal) {
143
- await this.checkAbortSignal(abortSignal);
144
- if (!this.validateParameters(params)) {
145
- throw new Error('Invalid parameters: sourcePath and destinationPath are required');
146
- }
147
- const { sourcePath, destinationPath } = params;
148
- // Ensure destination directory exists
149
- const dir = path.dirname(destinationPath);
150
- await fs.mkdir(dir, { recursive: true });
151
- await fs.copyFile(sourcePath, destinationPath);
152
- return `Successfully copied ${sourcePath} to ${destinationPath}`;
153
- }
154
- validateParameters(params) {
155
- return params &&
156
- typeof params.sourcePath === 'string' &&
157
- params.sourcePath.trim() !== '' &&
158
- typeof params.destinationPath === 'string' &&
159
- params.destinationPath.trim() !== '';
160
- }
161
- }
162
- exports.FileCopyTool = FileCopyTool;