@codebolt/agent 5.0.2 → 5.0.7
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/agent.d.ts +86 -0
- package/dist/agent.js +324 -0
- 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 +1 -6
- package/dist/composablepattern/document.js +35 -2
- package/dist/followupquestionbuilder.d.ts +75 -0
- package/dist/followupquestionbuilder.js +197 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +23 -0
- package/dist/llmoutputhandler.d.ts +102 -0
- package/dist/llmoutputhandler.js +452 -0
- package/dist/processor/types/interfaces.d.ts +21 -44
- package/dist/processor-pieces/index.d.ts +3 -0
- package/dist/processor-pieces/index.js +3 -0
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.d.ts +5 -14
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.js +40 -41
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.d.ts +13 -5
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.js +58 -50
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.d.ts +8 -6
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.js +22 -66
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.d.ts +2 -3
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.js +2 -1
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.d.ts +2 -3
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.js +2 -1
- package/dist/processor-pieces/messageModifiers/toolInjectionModifier.js +4 -1
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.d.ts +2 -18
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.js +93 -291
- package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.d.ts +18 -0
- package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.js +41 -0
- package/dist/processor-pieces/postToolCallProcessors/index.d.ts +2 -1
- package/dist/processor-pieces/postToolCallProcessors/index.js +5 -0
- package/dist/processor-pieces/preInferenceProcessors/index.d.ts +1 -1
- package/dist/processor-pieces/preInferenceProcessors/index.js +3 -0
- package/dist/processor-pieces/pretoolCallProcessors/index.d.ts +2 -1
- package/dist/processor-pieces/pretoolCallProcessors/index.js +5 -0
- package/dist/processor-pieces/pretoolCallProcessors/toolParameterModifier.d.ts +21 -0
- package/dist/processor-pieces/pretoolCallProcessors/toolParameterModifier.js +32 -0
- package/dist/processor-pieces/pretoolCallProcessors/toolValidationModifier.d.ts +16 -0
- package/dist/processor-pieces/pretoolCallProcessors/toolValidationModifier.js +37 -0
- package/dist/promptbuilder.d.ts +382 -0
- package/dist/promptbuilder.js +805 -0
- package/dist/systemprompt.d.ts +20 -0
- package/dist/systemprompt.js +48 -0
- package/dist/taskInstruction.d.ts +37 -0
- package/dist/taskInstruction.js +57 -0
- package/dist/types/libFunctionTypes.d.ts +13 -19
- package/dist/types/libFunctionTypes.js +3 -0
- package/dist/types/processorTypes.d.ts +8 -8
- package/dist/types/processorTypes.js +6 -23
- package/dist/unified/agent/agent.js +2 -2
- package/dist/unified/agent/codeboltAgent.d.ts +122 -0
- package/dist/unified/agent/codeboltAgent.js +210 -0
- package/dist/unified/base/initialPromptGenerator.js +18 -4
- package/dist/unified/base/responseExecutor.d.ts +3 -2
- package/dist/unified/base/responseExecutor.js +109 -56
- package/dist/unified/index.d.ts +4 -0
- package/dist/unified/index.js +12 -1
- package/dist/usermessage.d.ts +70 -0
- package/dist/usermessage.js +123 -0
- package/package.json +11 -6
- package/dist/local-tools/fileTools.d.ts +0 -26
- package/dist/local-tools/fileTools.js +0 -162
- package/dist/processor-pieces/additionalModifiers/argumentProcessorModifier.d.ts +0 -13
- package/dist/processor-pieces/additionalModifiers/argumentProcessorModifier.js +0 -68
- package/dist/processor-pieces/additionalModifiers/atFileProcessorModifier.d.ts +0 -15
- package/dist/processor-pieces/additionalModifiers/atFileProcessorModifier.js +0 -212
- package/dist/processor-pieces/additionalModifiers/chatCompressionModifier.d.ts +0 -19
- package/dist/processor-pieces/additionalModifiers/chatCompressionModifier.js +0 -110
- package/dist/processor-pieces/additionalModifiers/chatRecordingModifier.d.ts +0 -23
- package/dist/processor-pieces/additionalModifiers/chatRecordingModifier.js +0 -173
- package/dist/processor-pieces/additionalModifiers/coreSystemPromptModifier.d.ts +0 -14
- package/dist/processor-pieces/additionalModifiers/coreSystemPromptModifier.js +0 -93
- package/dist/processor-pieces/additionalModifiers/directoryContextModifier.d.ts +0 -30
- package/dist/processor-pieces/additionalModifiers/directoryContextModifier.js +0 -330
- package/dist/processor-pieces/additionalModifiers/environmentContextModifier.d.ts +0 -26
- package/dist/processor-pieces/additionalModifiers/environmentContextModifier.js +0 -269
- package/dist/processor-pieces/additionalModifiers/fallbackHandlerModifier.d.ts +0 -38
- package/dist/processor-pieces/additionalModifiers/fallbackHandlerModifier.js +0 -217
- package/dist/processor-pieces/additionalModifiers/ideContextModifier.d.ts +0 -34
- package/dist/processor-pieces/additionalModifiers/ideContextModifier.js +0 -147
- package/dist/processor-pieces/additionalModifiers/index.d.ts +0 -12
- package/dist/processor-pieces/additionalModifiers/index.js +0 -28
- package/dist/processor-pieces/additionalModifiers/loopDetectionModifier.d.ts +0 -29
- package/dist/processor-pieces/additionalModifiers/loopDetectionModifier.js +0 -155
- package/dist/processor-pieces/additionalModifiers/memoryImportModifier.d.ts +0 -15
- package/dist/processor-pieces/additionalModifiers/memoryImportModifier.js +0 -129
- package/dist/processor-pieces/additionalModifiers/shellProcessorModifier.d.ts +0 -25
- package/dist/processor-pieces/additionalModifiers/shellProcessorModifier.js +0 -169
- package/dist/processor-pieces/additionalModifiers/toolInjectionModifier.d.ts +0 -20
- package/dist/processor-pieces/additionalModifiers/toolInjectionModifier.js +0 -152
- package/dist/processor-pieces/messageModifiers/addCurrentDirectoryRootFilesModifier.d.ts +0 -7
- package/dist/processor-pieces/messageModifiers/addCurrentDirectoryRootFilesModifier.js +0 -93
- package/dist/processor-pieces/messageModifiers/advancedSystemInstructionMessageModifier.d.ts +0 -9
- package/dist/processor-pieces/messageModifiers/advancedSystemInstructionMessageModifier.js +0 -77
- package/dist/processor-pieces/messageModifiers/chatCompressionModifier.d.ts +0 -19
- package/dist/processor-pieces/messageModifiers/chatCompressionModifier.js +0 -110
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.example.d.ts +0 -20
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.example.js +0 -124
- package/dist/processor-pieces/messageModifiers/environmentContext.d.ts +0 -41
- package/dist/processor-pieces/messageModifiers/environmentContext.js +0 -355
- package/dist/processor-pieces/messageModifiers/mentionedFilesModifier.d.ts +0 -23
- package/dist/processor-pieces/messageModifiers/mentionedFilesModifier.js +0 -207
- package/dist/processor-pieces/messageModifiers/simpleMessageModifier.d.ts +0 -7
- package/dist/processor-pieces/messageModifiers/simpleMessageModifier.js +0 -26
- package/dist/processor-pieces/postInference/llmOutputValidityProcessor.d.ts +0 -1
- package/dist/processor-pieces/postInference/llmOutputValidityProcessor.js +0 -2
- package/dist/processor-pieces/postInferenceProcessors/checkForNoToolCall.d.ts +0 -7
- package/dist/processor-pieces/postInferenceProcessors/checkForNoToolCall.js +0 -24
- package/dist/processor-pieces/postToolCall/advancedLoopDetectionProcessor.d.ts +0 -41
- package/dist/processor-pieces/postToolCall/advancedLoopDetectionProcessor.js +0 -197
- package/dist/processor-pieces/postToolCall/chatCompressionProcessor.d.ts +0 -26
- package/dist/processor-pieces/postToolCall/chatCompressionProcessor.js +0 -90
- package/dist/processor-pieces/postToolCall/chatRecordingProcessor.d.ts +0 -81
- package/dist/processor-pieces/postToolCall/chatRecordingProcessor.js +0 -329
- package/dist/processor-pieces/postToolCall/contextManagementProcessor.d.ts +0 -40
- package/dist/processor-pieces/postToolCall/contextManagementProcessor.js +0 -272
- package/dist/processor-pieces/postToolCall/conversationCompactorProcessor.d.ts +0 -49
- package/dist/processor-pieces/postToolCall/conversationCompactorProcessor.js +0 -291
- package/dist/processor-pieces/postToolCall/conversationContinuityProcessor.d.ts +0 -49
- package/dist/processor-pieces/postToolCall/conversationContinuityProcessor.js +0 -293
- package/dist/processor-pieces/postToolCall/followUpConversationProcessor.d.ts +0 -47
- package/dist/processor-pieces/postToolCall/followUpConversationProcessor.js +0 -249
- package/dist/processor-pieces/postToolCall/loopDetectionProcessor.d.ts +0 -30
- package/dist/processor-pieces/postToolCall/loopDetectionProcessor.js +0 -137
- package/dist/processor-pieces/postToolCall/responseValidationProcessor.d.ts +0 -30
- package/dist/processor-pieces/postToolCall/responseValidationProcessor.js +0 -228
- package/dist/processor-pieces/postToolCall/telemetryProcessor.d.ts +0 -99
- package/dist/processor-pieces/postToolCall/telemetryProcessor.js +0 -278
- package/dist/processor-pieces/postToolCall/tokenManagementProcessor.d.ts +0 -37
- package/dist/processor-pieces/postToolCall/tokenManagementProcessor.js +0 -178
- package/dist/processor-pieces/postToolCall/toolExecutionProcessor.d.ts +0 -43
- package/dist/processor-pieces/postToolCall/toolExecutionProcessor.js +0 -207
- package/dist/processor-pieces/preInference/conversationCompactorProcessor.d.ts +0 -52
- package/dist/processor-pieces/preInference/conversationCompactorProcessor.js +0 -264
- package/dist/processor-pieces/preInference/conversationContinuityProcessor.d.ts +0 -49
- package/dist/processor-pieces/preInference/conversationContinuityProcessor.js +0 -293
- package/dist/processor-pieces/preInferenceProcessors/conversationCompaction.d.ts +0 -7
- package/dist/processor-pieces/preInferenceProcessors/conversationCompaction.js +0 -31
- package/dist/processor-pieces/preToolCall/index.d.ts +0 -9
- package/dist/processor-pieces/preToolCall/index.js +0 -18
- package/dist/processor-pieces/preToolCall/localToolInterceptorProcessor.d.ts +0 -58
- package/dist/processor-pieces/preToolCall/localToolInterceptorProcessor.js +0 -444
- package/dist/processor-pieces/preToolCall/toolParameterModifierProcessor.d.ts +0 -44
- package/dist/processor-pieces/preToolCall/toolParameterModifierProcessor.js +0 -367
- package/dist/processor-pieces/preToolCall/toolValidationProcessor.d.ts +0 -58
- package/dist/processor-pieces/preToolCall/toolValidationProcessor.js +0 -391
- package/dist/unified/agent/tool.d.ts +0 -99
- package/dist/unified/agent/tool.js +0 -440
- package/dist/unified/examples/agentExample.d.ts +0 -46
- package/dist/unified/examples/agentExample.js +0 -464
- package/dist/unified/examples/documentationPatternExample.d.ts +0 -10
- package/dist/unified/examples/documentationPatternExample.js +0 -385
- package/dist/unified/examples/followUpProcessorsExample.d.ts +0 -45
- package/dist/unified/examples/followUpProcessorsExample.js +0 -311
- package/dist/unified/examples/orchestratorExample.d.ts +0 -16
- package/dist/unified/examples/orchestratorExample.js +0 -415
- package/dist/unified/examples/preToolCallProcessorsExample.d.ts +0 -36
- package/dist/unified/examples/preToolCallProcessorsExample.js +0 -458
- package/dist/unified/examples/workflowExample.d.ts +0 -12
- package/dist/unified/examples/workflowExample.js +0 -497
- package/dist/unified/orchestrator/orchestrator.d.ts +0 -260
- package/dist/unified/orchestrator/orchestrator.js +0 -519
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.AddToolsListMessageModifier = void 0;
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
constructor(options = {}) {
|
|
4
|
+
const processor_1 = require("../../processor");
|
|
5
|
+
class AddToolsListMessageModifier extends processor_1.BaseMessageModifier {
|
|
6
|
+
constructor(options) {
|
|
11
7
|
super({ context: options });
|
|
12
8
|
this.toolsList = options.toolsList;
|
|
13
9
|
this.addToolsLocation = options.addToolsLocation || 'SystemMessage';
|
|
@@ -15,10 +11,10 @@ class AddToolsListMessageModifier extends base_1.BaseMessageModifier {
|
|
|
15
11
|
this.maxToolExamples = options.maxToolExamples || 2;
|
|
16
12
|
this.includeToolDescriptions = options.includeToolDescriptions !== false; // default true
|
|
17
13
|
}
|
|
18
|
-
async modify(
|
|
14
|
+
async modify(input) {
|
|
19
15
|
try {
|
|
20
|
-
const
|
|
21
|
-
const tools = (
|
|
16
|
+
const { originalRequest, createdMessage, context } = input;
|
|
17
|
+
const tools = this.toolsList.getAllTools();
|
|
22
18
|
if (tools.length === 0) {
|
|
23
19
|
return createdMessage;
|
|
24
20
|
}
|
|
@@ -30,7 +26,7 @@ class AddToolsListMessageModifier extends base_1.BaseMessageModifier {
|
|
|
30
26
|
case 'Tool':
|
|
31
27
|
return this.addToolsAsToolCalls(createdMessage, tools);
|
|
32
28
|
default:
|
|
33
|
-
return
|
|
29
|
+
return createdMessage;
|
|
34
30
|
}
|
|
35
31
|
}
|
|
36
32
|
catch (error) {
|
|
@@ -41,8 +37,8 @@ class AddToolsListMessageModifier extends base_1.BaseMessageModifier {
|
|
|
41
37
|
addToolsInsidePrompt(createdMessage, tools) {
|
|
42
38
|
const toolsInfo = this.generateToolsInfo(tools);
|
|
43
39
|
// Modify the last user message to include tools information
|
|
44
|
-
const modifiedMessages = createdMessage.
|
|
45
|
-
if (message.role === 'user' && index === createdMessage.
|
|
40
|
+
const modifiedMessages = createdMessage.messages.map((message, index) => {
|
|
41
|
+
if (message.role === 'user' && index === createdMessage.messages.length - 1) {
|
|
46
42
|
return {
|
|
47
43
|
...message,
|
|
48
44
|
content: `${message.content}\n\n--- Available Tools ---\n${toolsInfo}`
|
|
@@ -51,10 +47,7 @@ class AddToolsListMessageModifier extends base_1.BaseMessageModifier {
|
|
|
51
47
|
return message;
|
|
52
48
|
});
|
|
53
49
|
return {
|
|
54
|
-
|
|
55
|
-
...createdMessage.message,
|
|
56
|
-
messages: modifiedMessages
|
|
57
|
-
},
|
|
50
|
+
messages: modifiedMessages,
|
|
58
51
|
metadata: {
|
|
59
52
|
...createdMessage.metadata,
|
|
60
53
|
toolsListAdded: true,
|
|
@@ -67,13 +60,11 @@ class AddToolsListMessageModifier extends base_1.BaseMessageModifier {
|
|
|
67
60
|
const toolsInfo = this.generateToolsInfo(tools);
|
|
68
61
|
const toolsMessage = {
|
|
69
62
|
role: 'system',
|
|
70
|
-
content: `Available Tools:\n${toolsInfo}
|
|
63
|
+
content: `Available Tools:\n${toolsInfo}`,
|
|
64
|
+
name: 'tools-list'
|
|
71
65
|
};
|
|
72
66
|
return {
|
|
73
|
-
|
|
74
|
-
...createdMessage.message,
|
|
75
|
-
messages: [toolsMessage, ...createdMessage.message.messages]
|
|
76
|
-
},
|
|
67
|
+
messages: [toolsMessage, ...createdMessage.messages],
|
|
77
68
|
metadata: {
|
|
78
69
|
...createdMessage.metadata,
|
|
79
70
|
toolsListAdded: true,
|
|
@@ -83,12 +74,20 @@ class AddToolsListMessageModifier extends base_1.BaseMessageModifier {
|
|
|
83
74
|
};
|
|
84
75
|
}
|
|
85
76
|
addToolsAsToolCalls(createdMessage, tools) {
|
|
77
|
+
// This would create a message that lists tools as available tool calls
|
|
78
|
+
const toolsMessage = {
|
|
79
|
+
role: 'assistant',
|
|
80
|
+
content: 'I have access to the following tools:',
|
|
81
|
+
tool_calls: tools.map((tool, index) => ({
|
|
82
|
+
id: `tool-info-${index}`,
|
|
83
|
+
function: {
|
|
84
|
+
name: tool.name,
|
|
85
|
+
arguments: tool.parameters || {}
|
|
86
|
+
}
|
|
87
|
+
}))
|
|
88
|
+
};
|
|
86
89
|
return {
|
|
87
|
-
|
|
88
|
-
...createdMessage.message,
|
|
89
|
-
tools,
|
|
90
|
-
tool_choice: 'auto'
|
|
91
|
-
},
|
|
90
|
+
messages: [...createdMessage.messages, toolsMessage],
|
|
92
91
|
metadata: {
|
|
93
92
|
...createdMessage.metadata,
|
|
94
93
|
toolsListAdded: true,
|
|
@@ -100,14 +99,14 @@ class AddToolsListMessageModifier extends base_1.BaseMessageModifier {
|
|
|
100
99
|
generateToolsInfo(tools) {
|
|
101
100
|
const toolsInfo = [];
|
|
102
101
|
tools.forEach((tool, index) => {
|
|
103
|
-
let toolInfo = `${index + 1}. **${tool.
|
|
104
|
-
if (this.includeToolDescriptions && tool.
|
|
105
|
-
toolInfo += `\n Description: ${tool.
|
|
102
|
+
let toolInfo = `${index + 1}. **${tool.name}**`;
|
|
103
|
+
if (this.includeToolDescriptions && tool.description) {
|
|
104
|
+
toolInfo += `\n Description: ${tool.description}`;
|
|
106
105
|
}
|
|
107
|
-
if (tool.
|
|
108
|
-
const params = typeof tool.
|
|
109
|
-
? Object.keys(tool.
|
|
110
|
-
: String(tool.
|
|
106
|
+
if (tool.parameters) {
|
|
107
|
+
const params = typeof tool.parameters === 'object'
|
|
108
|
+
? Object.keys(tool.parameters).join(', ')
|
|
109
|
+
: String(tool.parameters);
|
|
111
110
|
toolInfo += `\n Parameters: ${params}`;
|
|
112
111
|
}
|
|
113
112
|
if (this.giveToolExamples && index < this.maxToolExamples) {
|
|
@@ -122,24 +121,24 @@ class AddToolsListMessageModifier extends base_1.BaseMessageModifier {
|
|
|
122
121
|
}
|
|
123
122
|
generateToolExample(tool) {
|
|
124
123
|
// Generate simple examples based on tool name
|
|
125
|
-
const toolName = tool.
|
|
124
|
+
const toolName = tool.name.toLowerCase();
|
|
126
125
|
if (toolName.includes('read') && toolName.includes('file')) {
|
|
127
|
-
return `${tool.
|
|
126
|
+
return `${tool.name}({ filePath: "example.txt" })`;
|
|
128
127
|
}
|
|
129
128
|
if (toolName.includes('write') && toolName.includes('file')) {
|
|
130
|
-
return `${tool.
|
|
129
|
+
return `${tool.name}({ filePath: "output.txt", content: "Hello World" })`;
|
|
131
130
|
}
|
|
132
131
|
if (toolName.includes('delete') && toolName.includes('file')) {
|
|
133
|
-
return `${tool.
|
|
132
|
+
return `${tool.name}({ filePath: "temp.txt" })`;
|
|
134
133
|
}
|
|
135
134
|
if (toolName.includes('move') && toolName.includes('file')) {
|
|
136
|
-
return `${tool.
|
|
135
|
+
return `${tool.name}({ sourcePath: "old.txt", destinationPath: "new.txt" })`;
|
|
137
136
|
}
|
|
138
137
|
if (toolName.includes('copy') && toolName.includes('file')) {
|
|
139
|
-
return `${tool.
|
|
138
|
+
return `${tool.name}({ sourcePath: "source.txt", destinationPath: "copy.txt" })`;
|
|
140
139
|
}
|
|
141
140
|
// Generic example
|
|
142
|
-
return `${tool.
|
|
141
|
+
return `${tool.name}({ /* parameters */ })`;
|
|
143
142
|
}
|
|
144
143
|
}
|
|
145
144
|
exports.AddToolsListMessageModifier = AddToolsListMessageModifier;
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
import { ProcessedMessage } from
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { BaseMessageModifier, MessageModifierInput, ProcessedMessage } from '../../processor';
|
|
2
|
+
export interface BaseContextMessageModifierOptions {
|
|
3
|
+
prependmessage?: string;
|
|
4
|
+
datetime?: boolean;
|
|
5
|
+
osInfo?: boolean;
|
|
6
|
+
workingdir?: boolean;
|
|
7
|
+
}
|
|
4
8
|
export declare class BaseContextMessageModifier extends BaseMessageModifier {
|
|
5
|
-
|
|
6
|
-
|
|
9
|
+
private readonly prependMessage;
|
|
10
|
+
private readonly includeDateTime;
|
|
11
|
+
private readonly includeOsInfo;
|
|
12
|
+
private readonly includeWorkingDir;
|
|
13
|
+
constructor(options?: BaseContextMessageModifierOptions);
|
|
14
|
+
modify(input: MessageModifierInput): Promise<ProcessedMessage>;
|
|
7
15
|
}
|
|
@@ -4,64 +4,72 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.BaseContextMessageModifier = void 0;
|
|
7
|
-
const
|
|
7
|
+
const processor_1 = require("../../processor");
|
|
8
8
|
const codeboltjs_1 = __importDefault(require("@codebolt/codeboltjs"));
|
|
9
9
|
const os_1 = __importDefault(require("os"));
|
|
10
|
-
class BaseContextMessageModifier extends
|
|
11
|
-
constructor() {
|
|
12
|
-
super();
|
|
10
|
+
class BaseContextMessageModifier extends processor_1.BaseMessageModifier {
|
|
11
|
+
constructor(options = {}) {
|
|
12
|
+
super({ context: options });
|
|
13
|
+
this.prependMessage = options.prependmessage || '';
|
|
14
|
+
this.includeDateTime = options.datetime || false;
|
|
15
|
+
this.includeOsInfo = options.osInfo || false;
|
|
16
|
+
this.includeWorkingDir = options.workingdir || false;
|
|
13
17
|
}
|
|
14
|
-
async modify(
|
|
15
|
-
const contextParts = [];
|
|
16
|
-
const now = new Date();
|
|
17
|
-
contextParts.push(`Current Date/Time: ${now.toISOString()}`);
|
|
18
|
-
const osInfo = {
|
|
19
|
-
platform: os_1.default.platform(),
|
|
20
|
-
arch: os_1.default.arch(),
|
|
21
|
-
version: os_1.default.version(),
|
|
22
|
-
hostname: os_1.default.hostname()
|
|
23
|
-
};
|
|
24
|
-
contextParts.push(`Operating System: ${JSON.stringify(osInfo, null, 2)}`);
|
|
18
|
+
async modify(input) {
|
|
25
19
|
try {
|
|
26
|
-
const {
|
|
27
|
-
contextParts
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
if (contextParts.length > 0) {
|
|
33
|
-
const contextMessage = {
|
|
34
|
-
role: 'system',
|
|
35
|
-
content: contextParts.join('\n\n'),
|
|
36
|
-
};
|
|
37
|
-
// Create a copy of messages array
|
|
38
|
-
const messages = [...createdMessage.message.messages];
|
|
39
|
-
// Check if system message already exists in the messages array
|
|
40
|
-
const existingSystemMessageIndex = messages.findIndex(msg => msg.role == 'system');
|
|
41
|
-
if (existingSystemMessageIndex !== -1) {
|
|
42
|
-
// Append context to existing system message content
|
|
43
|
-
const existingContent = messages[existingSystemMessageIndex].content || '';
|
|
44
|
-
messages[existingSystemMessageIndex] = {
|
|
45
|
-
...messages[existingSystemMessageIndex],
|
|
46
|
-
content: existingContent + '\n\n' + contextMessage.content
|
|
47
|
-
};
|
|
20
|
+
const { originalRequest, createdMessage, context } = input;
|
|
21
|
+
const contextParts = [];
|
|
22
|
+
// Add prepend message if provided
|
|
23
|
+
if (this.prependMessage) {
|
|
24
|
+
contextParts.push(this.prependMessage);
|
|
48
25
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
26
|
+
// Add date/time if requested
|
|
27
|
+
if (this.includeDateTime) {
|
|
28
|
+
const now = new Date();
|
|
29
|
+
contextParts.push(`Current Date/Time: ${now.toISOString()}`);
|
|
52
30
|
}
|
|
53
|
-
//
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
31
|
+
// Add OS info if requested
|
|
32
|
+
if (this.includeOsInfo) {
|
|
33
|
+
const osInfo = {
|
|
34
|
+
platform: os_1.default.platform(),
|
|
35
|
+
arch: os_1.default.arch(),
|
|
36
|
+
version: os_1.default.version(),
|
|
37
|
+
hostname: os_1.default.hostname()
|
|
38
|
+
};
|
|
39
|
+
contextParts.push(`Operating System: ${JSON.stringify(osInfo, null, 2)}`);
|
|
40
|
+
}
|
|
41
|
+
// Add working directory if requested
|
|
42
|
+
if (this.includeWorkingDir) {
|
|
43
|
+
try {
|
|
44
|
+
const projectPath = await codeboltjs_1.default.project.getProjectPath();
|
|
45
|
+
contextParts.push(`Working Directory: ${projectPath}`);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
contextParts.push(`Working Directory: ${process.cwd()}`);
|
|
61
49
|
}
|
|
62
|
-
}
|
|
50
|
+
}
|
|
51
|
+
// Create context message if we have any context parts
|
|
52
|
+
if (contextParts.length > 0) {
|
|
53
|
+
const contextMessage = {
|
|
54
|
+
role: 'system',
|
|
55
|
+
content: contextParts.join('\n\n'),
|
|
56
|
+
name: 'base-context'
|
|
57
|
+
};
|
|
58
|
+
return {
|
|
59
|
+
messages: [contextMessage, ...createdMessage.messages],
|
|
60
|
+
metadata: {
|
|
61
|
+
...createdMessage.metadata,
|
|
62
|
+
baseContextAdded: true,
|
|
63
|
+
contextParts: contextParts.length
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return createdMessage;
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
console.error('Error in BaseContextMessageModifier:', error);
|
|
71
|
+
throw error;
|
|
63
72
|
}
|
|
64
|
-
return createdMessage;
|
|
65
73
|
}
|
|
66
74
|
}
|
|
67
75
|
exports.BaseContextMessageModifier = BaseContextMessageModifier;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { ProcessedMessage } from
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { BaseMessageModifier, MessageModifierInput, ProcessedMessage } from '../../processor';
|
|
2
|
+
export interface BaseSystemInstructionMessageModifierOptions {
|
|
3
|
+
systemInstruction?: string;
|
|
4
|
+
position?: 'start' | 'end';
|
|
5
|
+
}
|
|
4
6
|
export declare class BaseSystemInstructionMessageModifier extends BaseMessageModifier {
|
|
5
7
|
private readonly systemInstruction;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
private readonly position;
|
|
9
|
+
constructor(options?: BaseSystemInstructionMessageModifierOptions);
|
|
10
|
+
modify(input: MessageModifierInput): Promise<ProcessedMessage>;
|
|
9
11
|
}
|
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BaseSystemInstructionMessageModifier = void 0;
|
|
4
|
-
const
|
|
5
|
-
class BaseSystemInstructionMessageModifier extends
|
|
6
|
-
constructor(
|
|
7
|
-
super();
|
|
8
|
-
this.systemInstruction = systemInstruction ||
|
|
4
|
+
const processor_1 = require("../../processor");
|
|
5
|
+
class BaseSystemInstructionMessageModifier extends processor_1.BaseMessageModifier {
|
|
6
|
+
constructor(options = {}) {
|
|
7
|
+
super({ context: options });
|
|
8
|
+
this.systemInstruction = options.systemInstruction || 'You are a helpful assistant.';
|
|
9
|
+
this.position = options.position || 'start';
|
|
9
10
|
}
|
|
10
|
-
async modify(
|
|
11
|
+
async modify(input) {
|
|
11
12
|
try {
|
|
13
|
+
const { originalRequest, createdMessage, context } = input;
|
|
12
14
|
// Create system instruction message
|
|
13
15
|
const systemMessage = {
|
|
14
16
|
role: 'system',
|
|
15
|
-
content: this.systemInstruction
|
|
17
|
+
content: this.systemInstruction,
|
|
18
|
+
name: 'system-instruction'
|
|
16
19
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (existingSystemIndex !== -1) {
|
|
22
|
-
// Update existing system message
|
|
23
|
-
messages[existingSystemIndex] = systemMessage;
|
|
20
|
+
let messages;
|
|
21
|
+
if (this.position === 'start') {
|
|
22
|
+
// Add system instruction at the beginning
|
|
23
|
+
messages = [systemMessage, ...createdMessage.messages];
|
|
24
24
|
}
|
|
25
25
|
else {
|
|
26
|
-
// Add system
|
|
27
|
-
messages.
|
|
26
|
+
// Add system instruction at the end (before user message)
|
|
27
|
+
const userMessages = createdMessage.messages.filter(m => m.role === 'user');
|
|
28
|
+
const otherMessages = createdMessage.messages.filter(m => m.role !== 'user');
|
|
29
|
+
messages = [...otherMessages, systemMessage, ...userMessages];
|
|
28
30
|
}
|
|
29
|
-
// Return new ProcessedMessage object
|
|
30
31
|
return {
|
|
31
|
-
|
|
32
|
-
...createdMessage.message,
|
|
33
|
-
messages
|
|
34
|
-
},
|
|
32
|
+
messages,
|
|
35
33
|
metadata: {
|
|
36
|
-
...createdMessage.metadata
|
|
34
|
+
...createdMessage.metadata,
|
|
35
|
+
systemInstructionAdded: true,
|
|
36
|
+
systemInstructionPosition: this.position
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
}
|
|
@@ -42,49 +42,5 @@ class BaseSystemInstructionMessageModifier extends base_1.BaseMessageModifier {
|
|
|
42
42
|
throw error;
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
getCoreSystemPrompt() {
|
|
46
|
-
// Default system prompt similar to gemini-cli but simplified for CodeBolt context
|
|
47
|
-
const basePrompt = `
|
|
48
|
-
You are an interactive AI agent specializing in software engineering tasks. Your primary goal is to help users safely and efficiently, adhering strictly to the following instructions and utilizing your available tools.
|
|
49
|
-
|
|
50
|
-
# Core Mandates
|
|
51
|
-
|
|
52
|
-
- **Conventions:** Rigorously adhere to existing project conventions when reading or modifying code. Analyze surrounding code, tests, and configuration first.
|
|
53
|
-
- **Libraries/Frameworks:** NEVER assume a library/framework is available or appropriate. Verify its established usage within the project before employing it.
|
|
54
|
-
- **Style & Structure:** Mimic the style (formatting, naming), structure, framework choices, typing, and architectural patterns of existing code in the project.
|
|
55
|
-
- **Idiomatic Changes:** When editing, understand the local context (imports, functions/classes) to ensure your changes integrate naturally and idiomatically.
|
|
56
|
-
- **Comments:** Add code comments sparingly. Focus on *why* something is done, especially for complex logic, rather than *what* is done.
|
|
57
|
-
- **Proactiveness:** Fulfill the user's request thoroughly, including reasonable, directly implied follow-up actions.
|
|
58
|
-
- **Confirm Ambiguity/Expansion:** Do not take significant actions beyond the clear scope of the request without confirming with the user.
|
|
59
|
-
- **Explaining Changes:** After completing a code modification or file operation *do not* provide summaries unless asked.
|
|
60
|
-
|
|
61
|
-
# Primary Workflows
|
|
62
|
-
|
|
63
|
-
## Software Engineering Tasks
|
|
64
|
-
When requested to perform tasks like fixing bugs, adding features, refactoring, or explaining code, follow this sequence:
|
|
65
|
-
1. **Understand:** Think about the user's request and the relevant codebase context. Use search tools extensively to understand file structures, existing code patterns, and conventions.
|
|
66
|
-
2. **Plan:** Build a coherent and grounded plan for how you intend to resolve the user's task. Share a concise yet clear plan with the user if it would help.
|
|
67
|
-
3. **Implement:** Use the available tools to act on the plan, strictly adhering to the project's established conventions.
|
|
68
|
-
4. **Verify:** If applicable and feasible, verify the changes using the project's testing procedures and build/lint commands.
|
|
69
|
-
|
|
70
|
-
# Operational Guidelines
|
|
71
|
-
|
|
72
|
-
## Tone and Style
|
|
73
|
-
- **Concise & Direct:** Adopt a professional, direct, and concise tone.
|
|
74
|
-
- **Minimal Output:** Aim for fewer than 3 lines of text output per response whenever practical.
|
|
75
|
-
- **Clarity over Brevity:** While conciseness is key, prioritize clarity for essential explanations.
|
|
76
|
-
- **No Chitchat:** Avoid conversational filler. Get straight to the action or answer.
|
|
77
|
-
- **Formatting:** Use GitHub-flavored Markdown.
|
|
78
|
-
|
|
79
|
-
## Security and Safety Rules
|
|
80
|
-
- **Security First:** Always apply security best practices. Never introduce code that exposes, logs, or commits secrets, API keys, or other sensitive information.
|
|
81
|
-
- **File Operations:** Always use absolute paths when referring to files with tools.
|
|
82
|
-
|
|
83
|
-
# Final Reminder
|
|
84
|
-
Your core function is efficient and safe assistance. Balance extreme conciseness with the crucial need for clarity, especially regarding safety and potential system modifications. Always prioritize user control and project conventions.
|
|
85
|
-
Do not ask for more information than necessary. Use the tools provided to accomplish the user's request efficiently and effectively. When you've completed your task, you must use the attempt_completion tool to present the result to the user. The user may provide feedback, which you can use to make improvements and try again.
|
|
86
|
-
`.trim();
|
|
87
|
-
return basePrompt;
|
|
88
|
-
}
|
|
89
45
|
}
|
|
90
46
|
exports.BaseSystemInstructionMessageModifier = BaseSystemInstructionMessageModifier;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BaseMessageModifier, ProcessedMessage } from '../../processor';
|
|
1
|
+
import { BaseMessageModifier, MessageModifierInput, ProcessedMessage } from '../../processor';
|
|
3
2
|
export interface HandleUrlMessageModifierOptions {
|
|
4
3
|
googleSearchEnabled?: boolean;
|
|
5
4
|
fetchUrlContent?: boolean;
|
|
@@ -8,6 +7,6 @@ export declare class HandleUrlMessageModifier extends BaseMessageModifier {
|
|
|
8
7
|
private readonly googleSearchEnabled;
|
|
9
8
|
private readonly fetchUrlContent;
|
|
10
9
|
constructor(options?: HandleUrlMessageModifierOptions);
|
|
11
|
-
modify(
|
|
10
|
+
modify(input: MessageModifierInput): Promise<ProcessedMessage>;
|
|
12
11
|
private extractUrls;
|
|
13
12
|
}
|
|
@@ -8,8 +8,9 @@ class HandleUrlMessageModifier extends processor_1.BaseMessageModifier {
|
|
|
8
8
|
this.googleSearchEnabled = options.googleSearchEnabled || false;
|
|
9
9
|
this.fetchUrlContent = options.fetchUrlContent || false;
|
|
10
10
|
}
|
|
11
|
-
async modify(
|
|
11
|
+
async modify(input) {
|
|
12
12
|
try {
|
|
13
|
+
const { originalRequest, createdMessage, context } = input;
|
|
13
14
|
// Check if the request contains URLs
|
|
14
15
|
const urls = this.extractUrls(originalRequest);
|
|
15
16
|
if (urls.length > 0) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BaseMessageModifier, ProcessedMessage } from '../../processor';
|
|
1
|
+
import { BaseMessageModifier, MessageModifierInput, ProcessedMessage } from '../../processor';
|
|
3
2
|
export interface ImageAttachmentMessageModifierOptions {
|
|
4
3
|
passImageAs?: 'URL' | 'Base64' | 'Path';
|
|
5
4
|
supportedFormats?: string[];
|
|
@@ -10,7 +9,7 @@ export declare class ImageAttachmentMessageModifier extends BaseMessageModifier
|
|
|
10
9
|
private readonly supportedFormats;
|
|
11
10
|
private readonly maxImageSize;
|
|
12
11
|
constructor(options?: ImageAttachmentMessageModifierOptions);
|
|
13
|
-
modify(
|
|
12
|
+
modify(input: MessageModifierInput): Promise<ProcessedMessage>;
|
|
14
13
|
private extractImageReferences;
|
|
15
14
|
private isImagePath;
|
|
16
15
|
private processImage;
|
|
@@ -44,8 +44,9 @@ class ImageAttachmentMessageModifier extends processor_1.BaseMessageModifier {
|
|
|
44
44
|
this.supportedFormats = options.supportedFormats || ['.png', '.jpg', '.jpeg', '.gif', '.webp', '.bmp'];
|
|
45
45
|
this.maxImageSize = options.maxImageSize || 10 * 1024 * 1024; // 10MB default
|
|
46
46
|
}
|
|
47
|
-
async modify(
|
|
47
|
+
async modify(input) {
|
|
48
48
|
try {
|
|
49
|
+
const { originalRequest, createdMessage, context } = input;
|
|
49
50
|
// Extract image references from the request
|
|
50
51
|
const imageReferences = this.extractImageReferences(originalRequest);
|
|
51
52
|
if (imageReferences.length === 0) {
|
|
@@ -20,7 +20,10 @@ class ToolInjectionModifier extends base_1.BaseMessageModifier {
|
|
|
20
20
|
async modify(originalRequest, createdMessage) {
|
|
21
21
|
try {
|
|
22
22
|
const toolsResponse = await codeboltjs_1.default.mcp.listMcpFromServers(['codebolt']);
|
|
23
|
-
|
|
23
|
+
let tools = (toolsResponse === null || toolsResponse === void 0 ? void 0 : toolsResponse.data.tools) || (toolsResponse === null || toolsResponse === void 0 ? void 0 : toolsResponse.data) || [];
|
|
24
|
+
let mentionedMCPs = originalRequest.mentionedMCPs || [];
|
|
25
|
+
const { data: mentionedTools } = await codeboltjs_1.default.mcp.getTools(mentionedMCPs);
|
|
26
|
+
tools = [...tools, ...(mentionedTools || [])];
|
|
24
27
|
if (tools.length === 0) {
|
|
25
28
|
return createdMessage;
|
|
26
29
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { ProcessedMessage } from
|
|
2
|
-
import { BaseMessageModifier } from "../base";
|
|
3
|
-
import { FlatUserMessage } from "@codebolt/types/sdk";
|
|
1
|
+
import { BaseMessageModifier, MessageModifierInput, ProcessedMessage } from '../../processor';
|
|
4
2
|
export interface WorkingDirectoryMessageModifierOptions {
|
|
5
3
|
showFolderStructureSummary?: boolean;
|
|
6
4
|
listFiles?: boolean;
|
|
@@ -8,9 +6,6 @@ export interface WorkingDirectoryMessageModifierOptions {
|
|
|
8
6
|
listFilesLimit?: number;
|
|
9
7
|
listFilesIgnoreFromGitignore?: boolean;
|
|
10
8
|
listFilesIgnore?: string[];
|
|
11
|
-
maxItems?: number;
|
|
12
|
-
showFullDirectoryContext?: boolean;
|
|
13
|
-
[key: string]: unknown;
|
|
14
9
|
}
|
|
15
10
|
export declare class WorkingDirectoryMessageModifier extends BaseMessageModifier {
|
|
16
11
|
private readonly showFolderStructureSummary;
|
|
@@ -19,20 +14,9 @@ export declare class WorkingDirectoryMessageModifier extends BaseMessageModifier
|
|
|
19
14
|
private readonly listFilesLimit;
|
|
20
15
|
private readonly listFilesIgnoreFromGitignore;
|
|
21
16
|
private readonly listFilesIgnore;
|
|
22
|
-
private readonly maxItems;
|
|
23
|
-
private readonly showFullDirectoryContext;
|
|
24
|
-
private readonly defaultIgnoredFolders;
|
|
25
|
-
private readonly truncationIndicator;
|
|
26
17
|
constructor(options?: WorkingDirectoryMessageModifierOptions);
|
|
27
|
-
modify(
|
|
18
|
+
modify(input: MessageModifierInput): Promise<ProcessedMessage>;
|
|
28
19
|
private generateFolderStructureSummary;
|
|
29
20
|
private generateFilesList;
|
|
30
|
-
private collectDirectories;
|
|
31
|
-
private collectFiles;
|
|
32
21
|
private shouldIgnore;
|
|
33
|
-
private getDirectoryContextString;
|
|
34
|
-
private getFolderStructure;
|
|
35
|
-
private readFullStructure;
|
|
36
|
-
private formatStructure;
|
|
37
|
-
private isTruncated;
|
|
38
22
|
}
|