@codebolt/agent 2.2.2 → 2.2.5
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/builderpattern/agent.js +2 -2
- package/dist/builderpattern/followupquestionbuilder.js +1 -1
- package/dist/builderpattern/llmoutputhandler.js +7 -7
- package/dist/builderpattern/usermessage.d.ts +6 -1
- package/dist/composablepattern/document.js +2 -35
- package/dist/local-tools/fileTools.d.ts +26 -0
- package/dist/local-tools/fileTools.js +162 -0
- package/dist/processor/types/interfaces.d.ts +44 -21
- package/dist/processor-pieces/additionalModifiers/argumentProcessorModifier.d.ts +13 -0
- package/dist/processor-pieces/additionalModifiers/argumentProcessorModifier.js +68 -0
- package/dist/processor-pieces/additionalModifiers/atFileProcessorModifier.d.ts +15 -0
- package/dist/processor-pieces/additionalModifiers/atFileProcessorModifier.js +212 -0
- package/dist/processor-pieces/additionalModifiers/chatCompressionModifier.d.ts +19 -0
- package/dist/processor-pieces/additionalModifiers/chatCompressionModifier.js +110 -0
- package/dist/processor-pieces/additionalModifiers/chatRecordingModifier.d.ts +23 -0
- package/dist/processor-pieces/additionalModifiers/chatRecordingModifier.js +173 -0
- package/dist/processor-pieces/additionalModifiers/coreSystemPromptModifier.d.ts +14 -0
- package/dist/processor-pieces/additionalModifiers/coreSystemPromptModifier.js +93 -0
- package/dist/processor-pieces/additionalModifiers/directoryContextModifier.d.ts +30 -0
- package/dist/processor-pieces/additionalModifiers/directoryContextModifier.js +330 -0
- package/dist/processor-pieces/additionalModifiers/environmentContextModifier.d.ts +26 -0
- package/dist/processor-pieces/additionalModifiers/environmentContextModifier.js +269 -0
- package/dist/processor-pieces/additionalModifiers/fallbackHandlerModifier.d.ts +38 -0
- package/dist/processor-pieces/additionalModifiers/fallbackHandlerModifier.js +217 -0
- package/dist/processor-pieces/additionalModifiers/ideContextModifier.d.ts +34 -0
- package/dist/processor-pieces/additionalModifiers/ideContextModifier.js +147 -0
- package/dist/processor-pieces/additionalModifiers/index.d.ts +12 -0
- package/dist/processor-pieces/additionalModifiers/index.js +28 -0
- package/dist/processor-pieces/additionalModifiers/loopDetectionModifier.d.ts +29 -0
- package/dist/processor-pieces/additionalModifiers/loopDetectionModifier.js +155 -0
- package/dist/processor-pieces/additionalModifiers/memoryImportModifier.d.ts +15 -0
- package/dist/processor-pieces/additionalModifiers/memoryImportModifier.js +129 -0
- package/dist/processor-pieces/additionalModifiers/shellProcessorModifier.d.ts +25 -0
- package/dist/processor-pieces/additionalModifiers/shellProcessorModifier.js +169 -0
- package/dist/processor-pieces/additionalModifiers/toolInjectionModifier.d.ts +20 -0
- package/dist/processor-pieces/additionalModifiers/toolInjectionModifier.js +152 -0
- package/dist/processor-pieces/messageModifiers/addCurrentDirectoryRootFilesModifier.d.ts +7 -0
- package/dist/processor-pieces/messageModifiers/addCurrentDirectoryRootFilesModifier.js +93 -0
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.d.ts +14 -5
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.js +41 -40
- package/dist/processor-pieces/messageModifiers/advancedSystemInstructionMessageModifier.d.ts +9 -0
- package/dist/processor-pieces/messageModifiers/advancedSystemInstructionMessageModifier.js +77 -0
- package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.js +5 -5
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.d.ts +5 -13
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.js +50 -58
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.d.ts +6 -8
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.js +66 -22
- package/dist/processor-pieces/messageModifiers/chatCompressionModifier.d.ts +19 -0
- package/dist/processor-pieces/messageModifiers/chatCompressionModifier.js +110 -0
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.example.d.ts +20 -0
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.example.js +124 -0
- package/dist/processor-pieces/messageModifiers/environmentContext.d.ts +41 -0
- package/dist/processor-pieces/messageModifiers/environmentContext.js +355 -0
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.d.ts +3 -2
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.js +1 -2
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.d.ts +3 -2
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.js +1 -2
- package/dist/processor-pieces/messageModifiers/mentionedFilesModifier.d.ts +23 -0
- package/dist/processor-pieces/messageModifiers/mentionedFilesModifier.js +207 -0
- package/dist/processor-pieces/messageModifiers/simpleMessageModifier.d.ts +7 -0
- package/dist/processor-pieces/messageModifiers/simpleMessageModifier.js +26 -0
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.d.ts +18 -2
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.js +291 -93
- package/dist/processor-pieces/postInference/llmOutputValidityProcessor.d.ts +1 -0
- package/dist/processor-pieces/postInference/llmOutputValidityProcessor.js +2 -0
- package/dist/processor-pieces/postInferenceProcessors/checkForNoToolCall.d.ts +7 -0
- package/dist/processor-pieces/postInferenceProcessors/checkForNoToolCall.js +24 -0
- package/dist/processor-pieces/postToolCall/advancedLoopDetectionProcessor.d.ts +41 -0
- package/dist/processor-pieces/postToolCall/advancedLoopDetectionProcessor.js +197 -0
- package/dist/processor-pieces/postToolCall/chatCompressionProcessor.d.ts +26 -0
- package/dist/processor-pieces/postToolCall/chatCompressionProcessor.js +90 -0
- package/dist/processor-pieces/postToolCall/chatRecordingProcessor.d.ts +81 -0
- package/dist/processor-pieces/postToolCall/chatRecordingProcessor.js +329 -0
- package/dist/processor-pieces/postToolCall/contextManagementProcessor.d.ts +40 -0
- package/dist/processor-pieces/postToolCall/contextManagementProcessor.js +272 -0
- package/dist/processor-pieces/postToolCall/conversationCompactorProcessor.d.ts +49 -0
- package/dist/processor-pieces/postToolCall/conversationCompactorProcessor.js +291 -0
- package/dist/processor-pieces/postToolCall/conversationContinuityProcessor.d.ts +49 -0
- package/dist/processor-pieces/postToolCall/conversationContinuityProcessor.js +293 -0
- package/dist/processor-pieces/postToolCall/followUpConversationProcessor.d.ts +47 -0
- package/dist/processor-pieces/postToolCall/followUpConversationProcessor.js +249 -0
- package/dist/processor-pieces/postToolCall/loopDetectionProcessor.d.ts +30 -0
- package/dist/processor-pieces/postToolCall/loopDetectionProcessor.js +137 -0
- package/dist/processor-pieces/postToolCall/responseValidationProcessor.d.ts +30 -0
- package/dist/processor-pieces/postToolCall/responseValidationProcessor.js +228 -0
- package/dist/processor-pieces/postToolCall/telemetryProcessor.d.ts +99 -0
- package/dist/processor-pieces/postToolCall/telemetryProcessor.js +278 -0
- package/dist/processor-pieces/postToolCall/tokenManagementProcessor.d.ts +37 -0
- package/dist/processor-pieces/postToolCall/tokenManagementProcessor.js +178 -0
- package/dist/processor-pieces/postToolCall/toolExecutionProcessor.d.ts +43 -0
- package/dist/processor-pieces/postToolCall/toolExecutionProcessor.js +207 -0
- package/dist/processor-pieces/preInference/conversationCompactorProcessor.d.ts +52 -0
- package/dist/processor-pieces/preInference/conversationCompactorProcessor.js +264 -0
- package/dist/processor-pieces/preInference/conversationContinuityProcessor.d.ts +49 -0
- package/dist/processor-pieces/preInference/conversationContinuityProcessor.js +293 -0
- package/dist/processor-pieces/preInferenceProcessors/conversationCompaction.d.ts +7 -0
- package/dist/processor-pieces/preInferenceProcessors/conversationCompaction.js +31 -0
- package/dist/processor-pieces/preToolCall/index.d.ts +9 -0
- package/dist/processor-pieces/preToolCall/index.js +18 -0
- package/dist/processor-pieces/preToolCall/localToolInterceptorProcessor.d.ts +58 -0
- package/dist/processor-pieces/preToolCall/localToolInterceptorProcessor.js +444 -0
- package/dist/processor-pieces/preToolCall/toolParameterModifierProcessor.d.ts +44 -0
- package/dist/processor-pieces/preToolCall/toolParameterModifierProcessor.js +367 -0
- package/dist/processor-pieces/preToolCall/toolValidationProcessor.d.ts +58 -0
- package/dist/processor-pieces/preToolCall/toolValidationProcessor.js +391 -0
- package/dist/unified/agent/agent.js +2 -2
- package/dist/unified/agent/tool.d.ts +99 -0
- package/dist/unified/agent/tool.js +440 -0
- package/dist/unified/base/initialPromptGenerator.js +5 -5
- package/dist/unified/base/responseExecutor.js +6 -6
- package/dist/unified/examples/agentExample.d.ts +46 -0
- package/dist/unified/examples/agentExample.js +464 -0
- package/dist/unified/examples/documentationPatternExample.d.ts +10 -0
- package/dist/unified/examples/documentationPatternExample.js +385 -0
- package/dist/unified/examples/followUpProcessorsExample.d.ts +45 -0
- package/dist/unified/examples/followUpProcessorsExample.js +311 -0
- package/dist/unified/examples/orchestratorExample.d.ts +16 -0
- package/dist/unified/examples/orchestratorExample.js +415 -0
- package/dist/unified/examples/preToolCallProcessorsExample.d.ts +36 -0
- package/dist/unified/examples/preToolCallProcessorsExample.js +458 -0
- package/dist/unified/examples/workflowExample.d.ts +12 -0
- package/dist/unified/examples/workflowExample.js +497 -0
- package/dist/unified/orchestrator/orchestrator.d.ts +260 -0
- package/dist/unified/orchestrator/orchestrator.js +519 -0
- package/package.json +5 -5
- package/dist/agent.d.ts +0 -86
- package/dist/agent.js +0 -324
- 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/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
|
@@ -258,9 +258,9 @@ class Agent {
|
|
|
258
258
|
async executeTool(toolName, toolInput) {
|
|
259
259
|
//codebolttools--readfile
|
|
260
260
|
const [toolboxName, actualToolName] = toolName.split('--');
|
|
261
|
-
console.log("Toolbox name: ", toolboxName, "Actual tool name: ", actualToolName);
|
|
261
|
+
// console.log("Toolbox name: ", toolboxName, "Actual tool name: ", actualToolName);
|
|
262
262
|
const { data } = await mcp.executeTool(toolboxName, actualToolName, toolInput);
|
|
263
|
-
console.log("Tool result: ", data);
|
|
263
|
+
// console.log("Tool result: ", data);
|
|
264
264
|
return data;
|
|
265
265
|
}
|
|
266
266
|
/**
|
|
@@ -143,7 +143,7 @@ class FollowUpPromptBuilder {
|
|
|
143
143
|
return this.previousConversation;
|
|
144
144
|
}
|
|
145
145
|
try {
|
|
146
|
-
console.log("Summarizing conversation due to length:", this.previousConversation.length);
|
|
146
|
+
// console.log("Summarizing conversation due to length:", this.previousConversation.length);
|
|
147
147
|
// Convert OpenAI messages to the format expected by chatSummary
|
|
148
148
|
const messagesToSummarize = this.previousConversation.map(msg => ({
|
|
149
149
|
role: msg.role,
|
|
@@ -137,7 +137,7 @@ class LLMOutputHandler {
|
|
|
137
137
|
let toolResults = [];
|
|
138
138
|
let taskCompletedBlock;
|
|
139
139
|
let userRejectedToolUse = false;
|
|
140
|
-
console.log("Calling run tool: ", JSON.stringify(this.llmResponse.completion));
|
|
140
|
+
// console.log("Calling run tool: ", JSON.stringify(this.llmResponse.completion));
|
|
141
141
|
const contentBlock = this.llmResponse.completion.choices[0];
|
|
142
142
|
// Validate contentBlock structure
|
|
143
143
|
if (!contentBlock || !contentBlock.message) {
|
|
@@ -174,12 +174,12 @@ class LLMOutputHandler {
|
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
else {
|
|
177
|
-
console.log("Executing tool: ", toolName, toolInput);
|
|
177
|
+
// console.log("Executing tool: ", toolName, toolInput);
|
|
178
178
|
const [didUserReject, result] = await this.executeTool(toolName, toolInput);
|
|
179
|
-
console.log("Tool result: ", result);
|
|
179
|
+
// console.log("Tool result: ", result);
|
|
180
180
|
// toolResults.push(this.getToolResult(toolUseId, result));
|
|
181
181
|
let toolResult = this.getToolResult(toolUseId, result);
|
|
182
|
-
console.log("tool result after parsing", toolResult);
|
|
182
|
+
// console.log("tool result after parsing", toolResult);
|
|
183
183
|
this.toolResults.push({
|
|
184
184
|
role: "tool",
|
|
185
185
|
tool_call_id: toolResult.tool_call_id,
|
|
@@ -367,9 +367,9 @@ class LLMOutputHandler {
|
|
|
367
367
|
var _a;
|
|
368
368
|
//codeboltmcp--readfile
|
|
369
369
|
const [toolboxName, actualToolName] = toolName.split('--');
|
|
370
|
-
console.log("Toolbox name: ", toolboxName, "Actual tool name: ", actualToolName);
|
|
370
|
+
// console.log("Toolbox name: ", toolboxName, "Actual tool name: ", actualToolName);
|
|
371
371
|
const data = await ((_a = this.codebolt) === null || _a === void 0 ? void 0 : _a.mcp.executeTool(toolboxName, actualToolName, toolInput));
|
|
372
|
-
console.log("Tool result: ", data);
|
|
372
|
+
// console.log("Tool result: ", data);
|
|
373
373
|
return data;
|
|
374
374
|
}
|
|
375
375
|
/**
|
|
@@ -389,7 +389,7 @@ class LLMOutputHandler {
|
|
|
389
389
|
// Only attempt to parse if content looks like JSON
|
|
390
390
|
if (content.trim().startsWith('{') || content.trim().startsWith('[')) {
|
|
391
391
|
const parsed = JSON.parse(content);
|
|
392
|
-
console.log("Parsed Content: ", parsed);
|
|
392
|
+
// console.log("Parsed Content: ", parsed);
|
|
393
393
|
if (parsed && typeof parsed === 'object' && parsed.payload && parsed.payload.content) {
|
|
394
394
|
content = `The browser action has been executed. The screenshot have been captured for your analysis. The tool response is provided in the next user message`;
|
|
395
395
|
userMessage = parsed.payload.content;
|
|
@@ -58,7 +58,12 @@ declare class UserMessage {
|
|
|
58
58
|
*
|
|
59
59
|
* @returns Promise with an array of MCP tools
|
|
60
60
|
*/
|
|
61
|
-
getMentionedMcpsTools(): Promise<
|
|
61
|
+
getMentionedMcpsTools(): Promise<{
|
|
62
|
+
toolbox: string;
|
|
63
|
+
toolName: string;
|
|
64
|
+
description?: string;
|
|
65
|
+
parameters?: Record<string, unknown>;
|
|
66
|
+
}[] | undefined>;
|
|
62
67
|
/**
|
|
63
68
|
* Gets environment details for the current working directory.
|
|
64
69
|
*
|
|
@@ -3,39 +3,6 @@
|
|
|
3
3
|
* @fileoverview Document handling for Composable Agent Pattern
|
|
4
4
|
* @description Provides document processing, chunking, and embedding capabilities
|
|
5
5
|
*/
|
|
6
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
-
if (k2 === undefined) k2 = k;
|
|
8
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
-
}
|
|
12
|
-
Object.defineProperty(o, k2, desc);
|
|
13
|
-
}) : (function(o, m, k, k2) {
|
|
14
|
-
if (k2 === undefined) k2 = k;
|
|
15
|
-
o[k2] = m[k];
|
|
16
|
-
}));
|
|
17
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
-
}) : function(o, v) {
|
|
20
|
-
o["default"] = v;
|
|
21
|
-
});
|
|
22
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
-
var ownKeys = function(o) {
|
|
24
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
-
var ar = [];
|
|
26
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
-
return ar;
|
|
28
|
-
};
|
|
29
|
-
return ownKeys(o);
|
|
30
|
-
};
|
|
31
|
-
return function (mod) {
|
|
32
|
-
if (mod && mod.__esModule) return mod;
|
|
33
|
-
var result = {};
|
|
34
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
-
__setModuleDefault(result, mod);
|
|
36
|
-
return result;
|
|
37
|
-
};
|
|
38
|
-
})();
|
|
39
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
7
|
exports.MDocument = void 0;
|
|
41
8
|
/**
|
|
@@ -91,8 +58,8 @@ class MDocument {
|
|
|
91
58
|
* @returns Promise<MDocument> instance
|
|
92
59
|
*/
|
|
93
60
|
static async fromFile(filePath, metadata) {
|
|
94
|
-
const fs = await
|
|
95
|
-
const path = await
|
|
61
|
+
const fs = await import('fs/promises');
|
|
62
|
+
const path = await import('path');
|
|
96
63
|
const content = await fs.readFile(filePath, 'utf-8');
|
|
97
64
|
const extension = path.extname(filePath).toLowerCase();
|
|
98
65
|
let type = 'text';
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
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;
|
|
@@ -1,52 +1,75 @@
|
|
|
1
|
+
import type { FlatUserMessage } from '@codebolt/types';
|
|
1
2
|
export interface ToolCall {
|
|
3
|
+
/** Unique identifier for this tool call */
|
|
2
4
|
id: string;
|
|
5
|
+
/** The type of tool call */
|
|
6
|
+
type: 'function';
|
|
7
|
+
/** Function call details */
|
|
3
8
|
function: {
|
|
9
|
+
/** Name of the function to call */
|
|
4
10
|
name: string;
|
|
5
|
-
|
|
11
|
+
/** Arguments for the function call as JSON string */
|
|
12
|
+
arguments: string;
|
|
6
13
|
};
|
|
7
14
|
}
|
|
8
15
|
export interface Message {
|
|
9
|
-
|
|
10
|
-
|
|
16
|
+
/** Role of the message sender */
|
|
17
|
+
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
18
|
+
/** Content of the message */
|
|
19
|
+
content: string | Array<{
|
|
20
|
+
type: string;
|
|
21
|
+
text: string;
|
|
22
|
+
}>;
|
|
23
|
+
/** Optional name for the message sender */
|
|
11
24
|
name?: string;
|
|
12
|
-
|
|
25
|
+
/** Tool call ID for tool messages */
|
|
13
26
|
tool_call_id?: string;
|
|
14
|
-
|
|
27
|
+
/** Tool calls for assistant messages */
|
|
28
|
+
tool_calls?: Array<{
|
|
29
|
+
id: string;
|
|
30
|
+
type: 'function';
|
|
31
|
+
function: {
|
|
32
|
+
name: string;
|
|
33
|
+
arguments: string;
|
|
34
|
+
};
|
|
35
|
+
}>;
|
|
15
36
|
}
|
|
16
37
|
export interface ProcessedMessage {
|
|
38
|
+
/** Array of messages in OpenAI format */
|
|
17
39
|
messages: Message[];
|
|
18
|
-
metadata
|
|
40
|
+
/** Optional metadata about the processing */
|
|
41
|
+
metadata?: Record<string, unknown>;
|
|
19
42
|
}
|
|
20
43
|
export interface ProcessorInput {
|
|
21
44
|
message: ProcessedMessage;
|
|
22
|
-
context?: Record<string,
|
|
45
|
+
context?: Record<string, unknown>;
|
|
23
46
|
}
|
|
24
47
|
export interface ProcessorOutput {
|
|
25
48
|
type: string;
|
|
26
|
-
value?:
|
|
49
|
+
value?: unknown;
|
|
27
50
|
}
|
|
28
51
|
export interface Processor {
|
|
29
52
|
processInput(input: ProcessorInput): Promise<ProcessorOutput[]>;
|
|
30
|
-
setContext(key: string, value:
|
|
31
|
-
getContext(key: string):
|
|
53
|
+
setContext(key: string, value: unknown): void;
|
|
54
|
+
getContext(key: string): unknown;
|
|
32
55
|
clearContext(): void;
|
|
33
56
|
}
|
|
34
57
|
export interface MessageModifierInput {
|
|
35
|
-
originalRequest:
|
|
58
|
+
originalRequest: FlatUserMessage;
|
|
36
59
|
createdMessage: ProcessedMessage;
|
|
37
|
-
context?: Record<string,
|
|
60
|
+
context?: Record<string, unknown>;
|
|
38
61
|
}
|
|
39
62
|
export interface MessageModifier {
|
|
40
63
|
modify(input: MessageModifierInput): Promise<ProcessedMessage>;
|
|
41
|
-
setContext(key: string, value:
|
|
42
|
-
getContext(key: string):
|
|
64
|
+
setContext(key: string, value: unknown): void;
|
|
65
|
+
getContext(key: string): unknown;
|
|
43
66
|
clearContext(): void;
|
|
44
67
|
}
|
|
45
68
|
export interface Tool {
|
|
46
69
|
name: string;
|
|
47
70
|
description: string;
|
|
48
|
-
parameters: Record<string,
|
|
49
|
-
execute(params:
|
|
71
|
+
parameters: Record<string, unknown>;
|
|
72
|
+
execute(params: unknown, abortSignal?: AbortSignal): Promise<unknown>;
|
|
50
73
|
}
|
|
51
74
|
export interface ToolList {
|
|
52
75
|
getTool(name: string): Tool | undefined;
|
|
@@ -57,13 +80,13 @@ export interface ToolList {
|
|
|
57
80
|
export interface AgentStepInput {
|
|
58
81
|
message: ProcessedMessage;
|
|
59
82
|
tools: Tool[];
|
|
60
|
-
context?: Record<string,
|
|
83
|
+
context?: Record<string, unknown>;
|
|
61
84
|
}
|
|
62
85
|
export interface AgentStepOutput {
|
|
63
86
|
response: ProcessedMessage;
|
|
64
87
|
toolCalls?: Array<{
|
|
65
88
|
tool: string;
|
|
66
|
-
parameters:
|
|
89
|
+
parameters: unknown;
|
|
67
90
|
}>;
|
|
68
91
|
finished: boolean;
|
|
69
92
|
}
|
|
@@ -75,15 +98,15 @@ export interface IAgentStep {
|
|
|
75
98
|
export interface ToolExecutionInput {
|
|
76
99
|
toolCalls: Array<{
|
|
77
100
|
tool: string;
|
|
78
|
-
parameters:
|
|
101
|
+
parameters: unknown;
|
|
79
102
|
}>;
|
|
80
103
|
tools: ToolList;
|
|
81
|
-
context?: Record<string,
|
|
104
|
+
context?: Record<string, unknown>;
|
|
82
105
|
}
|
|
83
106
|
export interface ToolExecutionOutput {
|
|
84
107
|
results: Array<{
|
|
85
108
|
tool: string;
|
|
86
|
-
result:
|
|
109
|
+
result: unknown;
|
|
87
110
|
error?: string;
|
|
88
111
|
}>;
|
|
89
112
|
success: boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ProcessedMessage } from "@codebolt/types/agent";
|
|
2
|
+
import { BaseMessageModifier } from "../base";
|
|
3
|
+
import { FlatUserMessage } from "@codebolt/types/sdk";
|
|
4
|
+
export interface ArgumentProcessorOptions {
|
|
5
|
+
appendRawInvocation?: boolean;
|
|
6
|
+
argumentSeparator?: string;
|
|
7
|
+
includeCommandName?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare class ArgumentProcessorModifier extends BaseMessageModifier {
|
|
10
|
+
private readonly options;
|
|
11
|
+
constructor(options?: ArgumentProcessorOptions);
|
|
12
|
+
modify(originalRequest: FlatUserMessage, createdMessage: ProcessedMessage): Promise<ProcessedMessage>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArgumentProcessorModifier = void 0;
|
|
4
|
+
const base_1 = require("../base");
|
|
5
|
+
class ArgumentProcessorModifier extends base_1.BaseMessageModifier {
|
|
6
|
+
constructor(options = {}) {
|
|
7
|
+
super();
|
|
8
|
+
this.options = {
|
|
9
|
+
appendRawInvocation: options.appendRawInvocation !== false,
|
|
10
|
+
argumentSeparator: options.argumentSeparator || ' ',
|
|
11
|
+
includeCommandName: options.includeCommandName || false
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
modify(originalRequest, createdMessage) {
|
|
15
|
+
var _a;
|
|
16
|
+
try {
|
|
17
|
+
// Get arguments from metadata
|
|
18
|
+
const invocation = (_a = createdMessage.metadata) === null || _a === void 0 ? void 0 : _a.invocation;
|
|
19
|
+
if (!(invocation === null || invocation === void 0 ? void 0 : invocation.args)) {
|
|
20
|
+
return Promise.resolve(createdMessage);
|
|
21
|
+
}
|
|
22
|
+
// Find the user message to append arguments to
|
|
23
|
+
const userMessage = createdMessage.message.messages.find(msg => msg.role === 'user');
|
|
24
|
+
if (!userMessage || typeof userMessage.content !== 'string') {
|
|
25
|
+
return Promise.resolve(createdMessage);
|
|
26
|
+
}
|
|
27
|
+
let appendContent = '';
|
|
28
|
+
if (this.options.appendRawInvocation && invocation.raw) {
|
|
29
|
+
// Append the full raw command invocation
|
|
30
|
+
appendContent = `\n\nFull command: ${invocation.raw}`;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
// Append just the arguments
|
|
34
|
+
let argsToAppend = invocation.args;
|
|
35
|
+
if (this.options.includeCommandName && invocation.name) {
|
|
36
|
+
argsToAppend = `${invocation.name}${this.options.argumentSeparator}${argsToAppend}`;
|
|
37
|
+
}
|
|
38
|
+
appendContent = `\n\nArguments: ${argsToAppend}`;
|
|
39
|
+
}
|
|
40
|
+
// Update the user message with appended arguments
|
|
41
|
+
const updatedMessages = createdMessage.message.messages.map(msg => {
|
|
42
|
+
if (msg.role === 'user' && typeof msg.content === 'string' && msg === userMessage) {
|
|
43
|
+
return {
|
|
44
|
+
...msg,
|
|
45
|
+
content: msg.content + appendContent
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return msg;
|
|
49
|
+
});
|
|
50
|
+
return Promise.resolve({
|
|
51
|
+
message: {
|
|
52
|
+
...createdMessage.message,
|
|
53
|
+
messages: updatedMessages
|
|
54
|
+
},
|
|
55
|
+
metadata: {
|
|
56
|
+
...createdMessage.metadata,
|
|
57
|
+
argumentsProcessed: true,
|
|
58
|
+
argumentsAppended: appendContent.trim()
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
console.error('Error in ArgumentProcessorModifier:', error);
|
|
64
|
+
return Promise.resolve(createdMessage);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.ArgumentProcessorModifier = ArgumentProcessorModifier;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ProcessedMessage } from "@codebolt/types/agent";
|
|
2
|
+
import { BaseMessageModifier } from "../base";
|
|
3
|
+
import { FlatUserMessage } from "@codebolt/types/sdk";
|
|
4
|
+
export interface AtFileProcessorOptions {
|
|
5
|
+
maxFileSize?: number;
|
|
6
|
+
allowedExtensions?: string[];
|
|
7
|
+
basePath?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class AtFileProcessorModifier extends BaseMessageModifier {
|
|
10
|
+
private readonly options;
|
|
11
|
+
constructor(options?: AtFileProcessorOptions);
|
|
12
|
+
modify(originalRequest: FlatUserMessage, createdMessage: ProcessedMessage): Promise<ProcessedMessage>;
|
|
13
|
+
private readFileContent;
|
|
14
|
+
private getFolderStructure;
|
|
15
|
+
}
|