@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.
- package/dist/processor-pieces/base/basePreToolCallProcessor.js +5 -2
- package/dist/processor-pieces/messageModifiers/argumentProcessorModifier.d.ts +1 -1
- package/dist/processor-pieces/messageModifiers/argumentProcessorModifier.js +2 -2
- package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.js +24 -34
- package/dist/processor-pieces/messageModifiers/chatRecordingModifier.d.ts +1 -1
- package/dist/processor-pieces/messageModifiers/chatRecordingModifier.js +2 -2
- package/dist/processor-pieces/messageModifiers/coreSystemPromptModifier.d.ts +1 -1
- package/dist/processor-pieces/messageModifiers/coreSystemPromptModifier.js +2 -2
- package/dist/processor-pieces/messageModifiers/directoryContextModifier.d.ts +1 -1
- package/dist/processor-pieces/messageModifiers/directoryContextModifier.js +8 -3
- package/dist/processor-pieces/messageModifiers/environmentContextModifier.d.ts +1 -1
- package/dist/processor-pieces/messageModifiers/environmentContextModifier.js +1 -1
- package/dist/processor-pieces/messageModifiers/ideContextModifier.js +114 -17
- package/dist/processor-pieces/messageModifiers/memoryImportModifier.d.ts +1 -1
- package/dist/processor-pieces/messageModifiers/memoryImportModifier.js +13 -5
- package/dist/processor-pieces/messageModifiers/toolInjectionModifier.d.ts +5 -0
- package/dist/processor-pieces/messageModifiers/toolInjectionModifier.js +4 -0
- package/dist/processor-pieces/postInferenceProcessors/loopDetectionModifier.js +24 -8
- package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.d.ts +202 -5
- package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.js +826 -19
- package/dist/processor-pieces/postToolCallProcessors/index.d.ts +1 -1
- package/dist/processor-pieces/postToolCallProcessors/index.js +2 -1
- package/dist/processor-pieces/postToolCallProcessors/shellProcessorModifier.js +7 -4
- package/dist/processor-pieces/preInferenceProcessors/chatCompressionModifier.d.ts +1 -1
- package/dist/processor-pieces/preInferenceProcessors/chatCompressionModifier.js +12 -16
- package/dist/processor-pieces/pretoolCallProcessors/toolParameterModifier.d.ts +2 -3
- package/dist/processor-pieces/pretoolCallProcessors/toolParameterModifier.js +1 -2
- package/dist/processor-pieces/utils/messageModifierHelper.js +5 -2
- package/dist/types/InternalTypes.d.ts +8 -6
- package/dist/unified/agent/agent.js +1 -2
- package/dist/unified/agent/codeboltAgent.d.ts +23 -2
- package/dist/unified/agent/codeboltAgent.js +55 -12
- package/dist/unified/agent/tools.d.ts +7 -11
- package/dist/unified/agent/tools.js +12 -3
- package/dist/unified/agent/workflow.js +38 -20
- package/dist/unified/agent/workflowSteps.d.ts +1 -1
- package/dist/unified/agent/workflowSteps.js +58 -23
- package/dist/unified/base/agentStep.js +20 -1
- package/dist/unified/base/initialPromptGenerator.js +3 -1
- package/dist/unified/base/responseExecutor.d.ts +3 -0
- package/dist/unified/base/responseExecutor.js +47 -21
- package/dist/unified/index.d.ts +1 -0
- package/dist/unified/index.js +4 -1
- package/dist/unified/services/LoopDetectionService.d.ts +44 -0
- package/dist/unified/services/LoopDetectionService.js +79 -0
- package/dist/unified/utils/utils.d.ts +20 -1
- package/dist/unified/utils/utils.js +8 -4
- package/package.json +5 -5
- package/dist/agent.d.ts +0 -86
- package/dist/agent.js +0 -324
- package/dist/builderpattern/agent.d.ts +0 -86
- package/dist/builderpattern/agent.js +0 -324
- package/dist/builderpattern/followupquestionbuilder.d.ts +0 -75
- package/dist/builderpattern/followupquestionbuilder.js +0 -197
- package/dist/builderpattern/index.d.ts +0 -14
- package/dist/builderpattern/index.js +0 -23
- package/dist/builderpattern/llmoutputhandler.d.ts +0 -102
- package/dist/builderpattern/llmoutputhandler.js +0 -452
- package/dist/builderpattern/promptbuilder.d.ts +0 -382
- package/dist/builderpattern/promptbuilder.js +0 -805
- package/dist/builderpattern/systemprompt.d.ts +0 -20
- package/dist/builderpattern/systemprompt.js +0 -48
- package/dist/builderpattern/taskInstruction.d.ts +0 -37
- package/dist/builderpattern/taskInstruction.js +0 -57
- package/dist/builderpattern/usermessage.d.ts +0 -70
- package/dist/builderpattern/usermessage.js +0 -123
- package/dist/composablepattern/agent.d.ts +0 -169
- package/dist/composablepattern/agent.js +0 -598
- package/dist/composablepattern/codebolt-storage.d.ts +0 -67
- package/dist/composablepattern/codebolt-storage.js +0 -320
- package/dist/composablepattern/document.d.ts +0 -149
- package/dist/composablepattern/document.js +0 -405
- package/dist/composablepattern/examples/codebolt-integration-example.d.ts +0 -12
- package/dist/composablepattern/examples/codebolt-integration-example.js +0 -218
- package/dist/composablepattern/examples/codebolt-storage-example.d.ts +0 -40
- package/dist/composablepattern/examples/codebolt-storage-example.js +0 -223
- package/dist/composablepattern/examples/custom-steps-example.d.ts +0 -20
- package/dist/composablepattern/examples/custom-steps-example.js +0 -455
- package/dist/composablepattern/examples/document-agent.d.ts +0 -17
- package/dist/composablepattern/examples/document-agent.js +0 -107
- package/dist/composablepattern/examples/simple-codebolt-integration.d.ts +0 -8
- package/dist/composablepattern/examples/simple-codebolt-integration.js +0 -164
- package/dist/composablepattern/examples/weather-agent.d.ts +0 -18
- package/dist/composablepattern/examples/weather-agent.js +0 -86
- package/dist/composablepattern/examples/workflow-example.d.ts +0 -12
- package/dist/composablepattern/examples/workflow-example.js +0 -463
- package/dist/composablepattern/index.d.ts +0 -63
- package/dist/composablepattern/index.js +0 -115
- package/dist/composablepattern/memory.d.ts +0 -89
- package/dist/composablepattern/memory.js +0 -141
- package/dist/composablepattern/tool.d.ts +0 -84
- package/dist/composablepattern/tool.js +0 -260
- package/dist/composablepattern/types.d.ts +0 -194
- package/dist/composablepattern/types.js +0 -6
- package/dist/composablepattern/user-context.d.ts +0 -214
- package/dist/composablepattern/user-context.js +0 -275
- package/dist/composablepattern/workflow.d.ts +0 -388
- package/dist/composablepattern/workflow.js +0 -562
- package/dist/followupquestionbuilder.d.ts +0 -75
- package/dist/followupquestionbuilder.js +0 -197
- package/dist/index.d.ts +0 -14
- package/dist/index.js +0 -23
- package/dist/llmoutputhandler.d.ts +0 -102
- package/dist/llmoutputhandler.js +0 -452
- package/dist/processor/agent/agentStep.d.ts +0 -49
- package/dist/processor/agent/agentStep.js +0 -241
- package/dist/processor/agent/toolExecutor.d.ts +0 -19
- package/dist/processor/agent/toolExecutor.js +0 -90
- package/dist/processor/index.d.ts +0 -7
- package/dist/processor/index.js +0 -36
- package/dist/processor/messageModifiers/baseMessageModifier.d.ts +0 -20
- package/dist/processor/messageModifiers/baseMessageModifier.js +0 -55
- package/dist/processor/processors/baseProcessor.d.ts +0 -14
- package/dist/processor/processors/baseProcessor.js +0 -29
- package/dist/processor/tools/baseTool.d.ts +0 -10
- package/dist/processor/tools/baseTool.js +0 -20
- package/dist/processor/tools/toolList.d.ts +0 -9
- package/dist/processor/tools/toolList.js +0 -22
- package/dist/processor/types/interfaces.d.ts +0 -94
- package/dist/processor/types/interfaces.js +0 -2
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.d.ts +0 -22
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.js +0 -144
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.d.ts +0 -15
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.js +0 -75
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.d.ts +0 -11
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.js +0 -46
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.d.ts +0 -12
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.js +0 -60
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.d.ts +0 -18
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.js +0 -222
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.d.ts +0 -22
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.js +0 -194
- package/dist/processor-pieces/processors/advancedLoopDetectionProcessor.d.ts +0 -41
- package/dist/processor-pieces/processors/advancedLoopDetectionProcessor.js +0 -197
- package/dist/processor-pieces/processors/chatCompressionProcessor.d.ts +0 -26
- package/dist/processor-pieces/processors/chatCompressionProcessor.js +0 -90
- package/dist/processor-pieces/processors/chatRecordingProcessor.d.ts +0 -81
- package/dist/processor-pieces/processors/chatRecordingProcessor.js +0 -329
- package/dist/processor-pieces/processors/contextManagementProcessor.d.ts +0 -40
- package/dist/processor-pieces/processors/contextManagementProcessor.js +0 -305
- package/dist/processor-pieces/processors/loopDetectionProcessor.d.ts +0 -30
- package/dist/processor-pieces/processors/loopDetectionProcessor.js +0 -137
- package/dist/processor-pieces/processors/responseValidationProcessor.d.ts +0 -30
- package/dist/processor-pieces/processors/responseValidationProcessor.js +0 -228
- package/dist/processor-pieces/processors/telemetryProcessor.d.ts +0 -99
- package/dist/processor-pieces/processors/telemetryProcessor.js +0 -311
- package/dist/processor-pieces/processors/tokenManagementProcessor.d.ts +0 -37
- package/dist/processor-pieces/processors/tokenManagementProcessor.js +0 -178
- package/dist/processor-pieces/processors/toolExecutionProcessor.d.ts +0 -43
- package/dist/processor-pieces/processors/toolExecutionProcessor.js +0 -207
- package/dist/processor-pieces/tools/fileTools.d.ts +0 -26
- package/dist/processor-pieces/tools/fileTools.js +0 -162
- package/dist/promptbuilder.d.ts +0 -382
- package/dist/promptbuilder.js +0 -805
- package/dist/systemprompt.d.ts +0 -20
- package/dist/systemprompt.js +0 -48
- package/dist/taskInstruction.d.ts +0 -37
- package/dist/taskInstruction.js +0 -57
- package/dist/usermessage.d.ts +0 -70
- 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;
|