@codebolt/agent 5.0.1 → 5.0.6
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/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 +100 -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 +5 -5
- 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,207 +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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.MentionedFilesModifier = void 0;
|
|
40
|
-
const base_1 = require("../base");
|
|
41
|
-
const fs = __importStar(require("node:fs/promises"));
|
|
42
|
-
const path = __importStar(require("node:path"));
|
|
43
|
-
const codeboltjs_1 = __importDefault(require("@codebolt/codeboltjs"));
|
|
44
|
-
/**
|
|
45
|
-
* Message modifier that reads files and folders mentioned in the user message
|
|
46
|
-
* Uses mentionedFiles and mentionedFolders from FlatUserMessage
|
|
47
|
-
*/
|
|
48
|
-
class MentionedFilesModifier extends base_1.BaseMessageModifier {
|
|
49
|
-
constructor() {
|
|
50
|
-
super();
|
|
51
|
-
}
|
|
52
|
-
async modify(originalRequest, createdMessage) {
|
|
53
|
-
try {
|
|
54
|
-
const mentionedFiles = originalRequest.mentionedFiles || [];
|
|
55
|
-
const mentionedFolders = originalRequest.mentionedFolders || [];
|
|
56
|
-
const allMentionedPaths = [...mentionedFiles, ...mentionedFolders];
|
|
57
|
-
if (allMentionedPaths.length === 0) {
|
|
58
|
-
return createdMessage;
|
|
59
|
-
}
|
|
60
|
-
// Read all mentioned files and folders
|
|
61
|
-
const fileResults = [];
|
|
62
|
-
for (const mentionedPath of allMentionedPaths) {
|
|
63
|
-
try {
|
|
64
|
-
const result = await this.resolveAndReadFile(mentionedPath);
|
|
65
|
-
if (result) {
|
|
66
|
-
fileResults.push(result);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
fileResults.push({
|
|
71
|
-
path: mentionedPath,
|
|
72
|
-
content: '',
|
|
73
|
-
error: error instanceof Error ? error.message : 'Unknown error'
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
if (fileResults.length === 0) {
|
|
78
|
-
return createdMessage;
|
|
79
|
-
}
|
|
80
|
-
// Add file content to the user message
|
|
81
|
-
const fileContentText = this.formatFileContent(fileResults);
|
|
82
|
-
const updatedMessages = this.updateUserMessage(createdMessage.message.messages || [], fileContentText);
|
|
83
|
-
return {
|
|
84
|
-
message: {
|
|
85
|
-
...createdMessage.message,
|
|
86
|
-
messages: updatedMessages
|
|
87
|
-
},
|
|
88
|
-
metadata: {
|
|
89
|
-
...createdMessage.metadata,
|
|
90
|
-
mentionedFilesAdded: true,
|
|
91
|
-
resolvedFiles: fileResults.map(f => f.path)
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
catch (error) {
|
|
96
|
-
console.error('Error in MentionedFilesModifier:', error);
|
|
97
|
-
return createdMessage;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Resolves and reads a file, handling both files and directories
|
|
102
|
-
*/
|
|
103
|
-
async resolveAndReadFile(pathName) {
|
|
104
|
-
try {
|
|
105
|
-
// pathName is already a full absolute path
|
|
106
|
-
const absolutePath = pathName;
|
|
107
|
-
// Get project path for security check and relative path display
|
|
108
|
-
let projectPath;
|
|
109
|
-
try {
|
|
110
|
-
const { projectPath: path } = await codeboltjs_1.default.project.getProjectPath();
|
|
111
|
-
projectPath = path || process.cwd();
|
|
112
|
-
}
|
|
113
|
-
catch (error) {
|
|
114
|
-
projectPath = process.cwd();
|
|
115
|
-
}
|
|
116
|
-
// Check if path is within project (basic security check)
|
|
117
|
-
const relativePath = path.relative(projectPath, absolutePath);
|
|
118
|
-
if (relativePath.startsWith('..')) {
|
|
119
|
-
throw new Error(`Path ${pathName} is outside project directory`);
|
|
120
|
-
}
|
|
121
|
-
const stats = await fs.stat(absolutePath);
|
|
122
|
-
if (stats.isDirectory()) {
|
|
123
|
-
// For directories, list contents
|
|
124
|
-
const files = await fs.readdir(absolutePath);
|
|
125
|
-
const fileList = files.join('\n');
|
|
126
|
-
return {
|
|
127
|
-
path: relativePath || path.basename(pathName),
|
|
128
|
-
content: `Directory contents:\n${fileList}`
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
else if (stats.isFile()) {
|
|
132
|
-
// Check file size (limit to reasonable size)
|
|
133
|
-
const maxFileSize = 1024 * 1024; // 1MB
|
|
134
|
-
if (stats.size > maxFileSize) {
|
|
135
|
-
return {
|
|
136
|
-
path: relativePath || path.basename(pathName),
|
|
137
|
-
content: `File too large (${stats.size} bytes). Maximum allowed: ${maxFileSize} bytes.`
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
// Read file content
|
|
141
|
-
const content = await fs.readFile(absolutePath, 'utf-8');
|
|
142
|
-
return {
|
|
143
|
-
path: relativePath || path.basename(pathName),
|
|
144
|
-
content
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
catch (error) {
|
|
149
|
-
if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {
|
|
150
|
-
// File not found
|
|
151
|
-
return {
|
|
152
|
-
path: pathName,
|
|
153
|
-
content: '',
|
|
154
|
-
error: `File not found: ${pathName}`
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
throw error;
|
|
158
|
-
}
|
|
159
|
-
return null;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Formats file content for inclusion in the message
|
|
163
|
-
*/
|
|
164
|
-
formatFileContent(fileResults) {
|
|
165
|
-
const contentParts = [];
|
|
166
|
-
contentParts.push('\n--- Content from mentioned files ---');
|
|
167
|
-
for (const result of fileResults) {
|
|
168
|
-
if (result.error) {
|
|
169
|
-
contentParts.push(`\nError reading ${result.path}: ${result.error}`);
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
contentParts.push(`\nContent from ${result.path}:`);
|
|
173
|
-
contentParts.push(result.content);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return contentParts.join('\n');
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Updates the user message with file content
|
|
180
|
-
*/
|
|
181
|
-
updateUserMessage(messages, fileContent) {
|
|
182
|
-
const updatedMessages = [...messages];
|
|
183
|
-
// Find the last user message and append file content
|
|
184
|
-
for (let i = updatedMessages.length - 1; i >= 0; i--) {
|
|
185
|
-
if (updatedMessages[i].role === 'user') {
|
|
186
|
-
const currentContent = updatedMessages[i].content;
|
|
187
|
-
if (Array.isArray(currentContent)) {
|
|
188
|
-
// If content is array, add file content as new text element
|
|
189
|
-
updatedMessages[i] = {
|
|
190
|
-
...updatedMessages[i],
|
|
191
|
-
content: [...currentContent, { type: 'text', text: fileContent }]
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
// If content is string, append file content
|
|
196
|
-
updatedMessages[i] = {
|
|
197
|
-
...updatedMessages[i],
|
|
198
|
-
content: (currentContent || '') + fileContent
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
break;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
return updatedMessages;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
exports.MentionedFilesModifier = MentionedFilesModifier;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { ProcessedMessage } from "@codebolt/types/agent";
|
|
2
|
-
import { BaseMessageModifier } from "../base";
|
|
3
|
-
import { FlatUserMessage } from "@codebolt/types/sdk";
|
|
4
|
-
export declare class SimpleMessageModifier extends BaseMessageModifier {
|
|
5
|
-
constructor();
|
|
6
|
-
modify(originalRequest: FlatUserMessage, createdMessage: ProcessedMessage, context?: Record<string, unknown>): Promise<ProcessedMessage>;
|
|
7
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SimpleMessageModifier = void 0;
|
|
4
|
-
const base_1 = require("../base");
|
|
5
|
-
class SimpleMessageModifier extends base_1.BaseMessageModifier {
|
|
6
|
-
constructor() {
|
|
7
|
-
super();
|
|
8
|
-
}
|
|
9
|
-
modify(originalRequest, createdMessage, context) {
|
|
10
|
-
const contextMessage = {
|
|
11
|
-
role: 'user',
|
|
12
|
-
content: "hi"
|
|
13
|
-
};
|
|
14
|
-
return Promise.resolve({
|
|
15
|
-
message: {
|
|
16
|
-
...createdMessage.message,
|
|
17
|
-
messages: [...createdMessage.message.messages, contextMessage]
|
|
18
|
-
},
|
|
19
|
-
metadata: {
|
|
20
|
-
...createdMessage.metadata,
|
|
21
|
-
userMessageAdded: true
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.SimpleMessageModifier = SimpleMessageModifier;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { ProcessedMessage } from "@codebolt/types/agent";
|
|
2
|
-
import { BasePostInferenceProcessor } from "../base";
|
|
3
|
-
import { LLMResponse } from "@codebolt/types/sdk";
|
|
4
|
-
export declare class CheckForNoToolCall extends BasePostInferenceProcessor {
|
|
5
|
-
constructor();
|
|
6
|
-
modify(llmMessageSent: ProcessedMessage, llmResponseMessage: LLMResponse, nextPrompt: ProcessedMessage): Promise<ProcessedMessage>;
|
|
7
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CheckForNoToolCall = void 0;
|
|
4
|
-
const base_1 = require("../base");
|
|
5
|
-
class CheckForNoToolCall extends base_1.BasePostInferenceProcessor {
|
|
6
|
-
constructor() {
|
|
7
|
-
super();
|
|
8
|
-
}
|
|
9
|
-
modify(llmMessageSent, llmResponseMessage, nextPrompt) {
|
|
10
|
-
// Check if tool_calls exist in the LLM response
|
|
11
|
-
const hasToolCalls = llmResponseMessage.tool_calls && llmResponseMessage.tool_calls.length > 0;
|
|
12
|
-
if (!hasToolCalls) {
|
|
13
|
-
// Create a new message indicating no tool call was found
|
|
14
|
-
const noToolCallMessage = {
|
|
15
|
-
role: 'user',
|
|
16
|
-
content: 'no tool call found in request'
|
|
17
|
-
};
|
|
18
|
-
nextPrompt.message.messages.push(noToolCallMessage);
|
|
19
|
-
}
|
|
20
|
-
// If tool calls exist, return the nextPrompt unchanged
|
|
21
|
-
return Promise.resolve(nextPrompt);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
exports.CheckForNoToolCall = CheckForNoToolCall;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { BaseProcessor, ProcessorInput, ProcessorOutput } from '../../processor';
|
|
2
|
-
export interface AdvancedLoopDetectionProcessorOptions {
|
|
3
|
-
toolCallThreshold?: number;
|
|
4
|
-
contentLoopThreshold?: number;
|
|
5
|
-
contentChunkSize?: number;
|
|
6
|
-
maxHistoryLength?: number;
|
|
7
|
-
enableLLMDetection?: boolean;
|
|
8
|
-
llmCheckAfterTurns?: number;
|
|
9
|
-
defaultLLMCheckInterval?: number;
|
|
10
|
-
}
|
|
11
|
-
export declare class AdvancedLoopDetectionProcessor extends BaseProcessor {
|
|
12
|
-
private readonly toolCallThreshold;
|
|
13
|
-
private readonly contentLoopThreshold;
|
|
14
|
-
private readonly contentChunkSize;
|
|
15
|
-
private readonly maxHistoryLength;
|
|
16
|
-
private readonly enableLLMDetection;
|
|
17
|
-
private readonly llmCheckAfterTurns;
|
|
18
|
-
private readonly defaultLLMCheckInterval;
|
|
19
|
-
private lastToolCallKey;
|
|
20
|
-
private toolCallRepetitionCount;
|
|
21
|
-
private streamContentHistory;
|
|
22
|
-
private contentStats;
|
|
23
|
-
private lastContentIndex;
|
|
24
|
-
private loopDetected;
|
|
25
|
-
private inCodeBlock;
|
|
26
|
-
private turnsInCurrentPrompt;
|
|
27
|
-
private llmCheckInterval;
|
|
28
|
-
private lastCheckTurn;
|
|
29
|
-
constructor(options?: AdvancedLoopDetectionProcessorOptions);
|
|
30
|
-
processInput(input: ProcessorInput): Promise<ProcessorOutput[]>;
|
|
31
|
-
private getToolCallKey;
|
|
32
|
-
private checkToolCallLoop;
|
|
33
|
-
private checkContentLoop;
|
|
34
|
-
private truncateAndUpdate;
|
|
35
|
-
private analyzeContentChunksForLoop;
|
|
36
|
-
private hasMoreChunksToProcess;
|
|
37
|
-
private isLoopDetectedForChunk;
|
|
38
|
-
private isActualContentMatch;
|
|
39
|
-
private resetContentTracking;
|
|
40
|
-
reset(): void;
|
|
41
|
-
}
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AdvancedLoopDetectionProcessor = void 0;
|
|
4
|
-
const processor_1 = require("../../processor");
|
|
5
|
-
const crypto_1 = require("crypto");
|
|
6
|
-
class AdvancedLoopDetectionProcessor extends processor_1.BaseProcessor {
|
|
7
|
-
constructor(options = {}) {
|
|
8
|
-
super();
|
|
9
|
-
// Tool call tracking
|
|
10
|
-
this.lastToolCallKey = null;
|
|
11
|
-
this.toolCallRepetitionCount = 0;
|
|
12
|
-
// Content streaming tracking
|
|
13
|
-
this.streamContentHistory = '';
|
|
14
|
-
this.contentStats = new Map();
|
|
15
|
-
this.lastContentIndex = 0;
|
|
16
|
-
this.loopDetected = false;
|
|
17
|
-
this.inCodeBlock = false;
|
|
18
|
-
// Turn tracking
|
|
19
|
-
this.turnsInCurrentPrompt = 0;
|
|
20
|
-
this.lastCheckTurn = 0;
|
|
21
|
-
this.toolCallThreshold = options.toolCallThreshold || 5;
|
|
22
|
-
this.contentLoopThreshold = options.contentLoopThreshold || 10;
|
|
23
|
-
this.contentChunkSize = options.contentChunkSize || 50;
|
|
24
|
-
this.maxHistoryLength = options.maxHistoryLength || 1000;
|
|
25
|
-
this.enableLLMDetection = options.enableLLMDetection || false;
|
|
26
|
-
this.llmCheckAfterTurns = options.llmCheckAfterTurns || 30;
|
|
27
|
-
this.defaultLLMCheckInterval = options.defaultLLMCheckInterval || 3;
|
|
28
|
-
this.llmCheckInterval = this.defaultLLMCheckInterval;
|
|
29
|
-
}
|
|
30
|
-
async processInput(input) {
|
|
31
|
-
const { message, context } = input;
|
|
32
|
-
// Increment turn counter
|
|
33
|
-
this.turnsInCurrentPrompt++;
|
|
34
|
-
// Check for tool call loops in the last message
|
|
35
|
-
const lastMessage = message.messages[message.messages.length - 1];
|
|
36
|
-
if (lastMessage.tool_calls && lastMessage.tool_calls.length > 0) {
|
|
37
|
-
for (const toolCall of lastMessage.tool_calls) {
|
|
38
|
-
const isLoop = this.checkToolCallLoop({
|
|
39
|
-
name: toolCall.function.name,
|
|
40
|
-
args: typeof toolCall.function.arguments === 'string'
|
|
41
|
-
? JSON.parse(toolCall.function.arguments)
|
|
42
|
-
: toolCall.function.arguments
|
|
43
|
-
});
|
|
44
|
-
if (isLoop) {
|
|
45
|
-
this.loopDetected = true;
|
|
46
|
-
return [this.createEvent('LoopDetected', {
|
|
47
|
-
type: 'tool_call_loop',
|
|
48
|
-
toolCall: toolCall.function.name,
|
|
49
|
-
repetitionCount: this.toolCallRepetitionCount,
|
|
50
|
-
threshold: this.toolCallThreshold
|
|
51
|
-
})];
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
// Check for content loops
|
|
56
|
-
if (lastMessage.content && typeof lastMessage.content === 'string') {
|
|
57
|
-
const isContentLoop = this.checkContentLoop(lastMessage.content);
|
|
58
|
-
if (isContentLoop) {
|
|
59
|
-
this.loopDetected = true;
|
|
60
|
-
return [this.createEvent('LoopDetected', {
|
|
61
|
-
type: 'content_loop',
|
|
62
|
-
contentLength: this.streamContentHistory.length,
|
|
63
|
-
threshold: this.contentLoopThreshold
|
|
64
|
-
})];
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
// LLM-based loop detection (if enabled)
|
|
68
|
-
if (this.enableLLMDetection &&
|
|
69
|
-
this.turnsInCurrentPrompt >= this.llmCheckAfterTurns &&
|
|
70
|
-
this.turnsInCurrentPrompt - this.lastCheckTurn >= this.llmCheckInterval) {
|
|
71
|
-
this.lastCheckTurn = this.turnsInCurrentPrompt;
|
|
72
|
-
// For now, just log that LLM check would happen
|
|
73
|
-
// In a real implementation, this would call an LLM to analyze the conversation
|
|
74
|
-
console.log('[AdvancedLoopDetection] LLM-based loop check would be performed here');
|
|
75
|
-
}
|
|
76
|
-
return [this.createEvent('LoopCheckCompleted', {
|
|
77
|
-
loopDetected: this.loopDetected,
|
|
78
|
-
turnsInPrompt: this.turnsInCurrentPrompt,
|
|
79
|
-
toolCallCount: this.toolCallRepetitionCount
|
|
80
|
-
})];
|
|
81
|
-
}
|
|
82
|
-
getToolCallKey(toolCall) {
|
|
83
|
-
const argsString = JSON.stringify(toolCall.args);
|
|
84
|
-
const keyString = `${toolCall.name}:${argsString}`;
|
|
85
|
-
return (0, crypto_1.createHash)('sha256').update(keyString).digest('hex');
|
|
86
|
-
}
|
|
87
|
-
checkToolCallLoop(toolCall) {
|
|
88
|
-
const key = this.getToolCallKey(toolCall);
|
|
89
|
-
if (this.lastToolCallKey === key) {
|
|
90
|
-
this.toolCallRepetitionCount++;
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
this.lastToolCallKey = key;
|
|
94
|
-
this.toolCallRepetitionCount = 1;
|
|
95
|
-
}
|
|
96
|
-
return this.toolCallRepetitionCount >= this.toolCallThreshold;
|
|
97
|
-
}
|
|
98
|
-
checkContentLoop(content) {
|
|
99
|
-
var _a;
|
|
100
|
-
// Different content elements can often contain repetitive syntax that is not indicative of a loop.
|
|
101
|
-
// To avoid false positives, we detect when we encounter different content types and
|
|
102
|
-
// reset tracking to avoid analyzing content that spans across different element boundaries.
|
|
103
|
-
const numFences = ((_a = content.match(/```/g)) !== null && _a !== void 0 ? _a : []).length;
|
|
104
|
-
const hasTable = /(^|\n)\s*(\|.*\||[|+-]{3,})/.test(content);
|
|
105
|
-
const hasListItem = /(^|\n)\s*[*-+]\s/.test(content) || /(^|\n)\s*\d+\.\s/.test(content);
|
|
106
|
-
const hasHeading = /(^|\n)#+\s/.test(content);
|
|
107
|
-
const hasBlockquote = /(^|\n)>\s/.test(content);
|
|
108
|
-
if (numFences || hasTable || hasListItem || hasHeading || hasBlockquote) {
|
|
109
|
-
// Reset tracking when different content elements are detected
|
|
110
|
-
this.resetContentTracking();
|
|
111
|
-
}
|
|
112
|
-
const wasInCodeBlock = this.inCodeBlock;
|
|
113
|
-
this.inCodeBlock = numFences % 2 === 0 ? this.inCodeBlock : !this.inCodeBlock;
|
|
114
|
-
if (wasInCodeBlock || this.inCodeBlock) {
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
this.streamContentHistory += content;
|
|
118
|
-
this.truncateAndUpdate();
|
|
119
|
-
return this.analyzeContentChunksForLoop();
|
|
120
|
-
}
|
|
121
|
-
truncateAndUpdate() {
|
|
122
|
-
if (this.streamContentHistory.length <= this.maxHistoryLength) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
const truncationAmount = this.streamContentHistory.length - this.maxHistoryLength;
|
|
126
|
-
this.streamContentHistory = this.streamContentHistory.slice(truncationAmount);
|
|
127
|
-
this.lastContentIndex = Math.max(0, this.lastContentIndex - truncationAmount);
|
|
128
|
-
// Update all stored chunk indices to account for the truncation
|
|
129
|
-
for (const [hash, oldIndices] of this.contentStats.entries()) {
|
|
130
|
-
const adjustedIndices = oldIndices
|
|
131
|
-
.map((index) => index - truncationAmount)
|
|
132
|
-
.filter((index) => index >= 0);
|
|
133
|
-
if (adjustedIndices.length > 0) {
|
|
134
|
-
this.contentStats.set(hash, adjustedIndices);
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
this.contentStats.delete(hash);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
analyzeContentChunksForLoop() {
|
|
142
|
-
while (this.hasMoreChunksToProcess()) {
|
|
143
|
-
const currentChunk = this.streamContentHistory.substring(this.lastContentIndex, this.lastContentIndex + this.contentChunkSize);
|
|
144
|
-
const chunkHash = (0, crypto_1.createHash)('sha256').update(currentChunk).digest('hex');
|
|
145
|
-
if (this.isLoopDetectedForChunk(currentChunk, chunkHash)) {
|
|
146
|
-
return true;
|
|
147
|
-
}
|
|
148
|
-
this.lastContentIndex++;
|
|
149
|
-
}
|
|
150
|
-
return false;
|
|
151
|
-
}
|
|
152
|
-
hasMoreChunksToProcess() {
|
|
153
|
-
return this.lastContentIndex + this.contentChunkSize <= this.streamContentHistory.length;
|
|
154
|
-
}
|
|
155
|
-
isLoopDetectedForChunk(chunk, hash) {
|
|
156
|
-
const existingIndices = this.contentStats.get(hash);
|
|
157
|
-
if (!existingIndices) {
|
|
158
|
-
this.contentStats.set(hash, [this.lastContentIndex]);
|
|
159
|
-
return false;
|
|
160
|
-
}
|
|
161
|
-
if (!this.isActualContentMatch(chunk, existingIndices[0])) {
|
|
162
|
-
return false;
|
|
163
|
-
}
|
|
164
|
-
existingIndices.push(this.lastContentIndex);
|
|
165
|
-
if (existingIndices.length < this.contentLoopThreshold) {
|
|
166
|
-
return false;
|
|
167
|
-
}
|
|
168
|
-
// Analyze the most recent occurrences to see if they're clustered closely together
|
|
169
|
-
const recentIndices = existingIndices.slice(-this.contentLoopThreshold);
|
|
170
|
-
const totalDistance = recentIndices[recentIndices.length - 1] - recentIndices[0];
|
|
171
|
-
const averageDistance = totalDistance / (this.contentLoopThreshold - 1);
|
|
172
|
-
const maxAllowedDistance = this.contentChunkSize * 1.5;
|
|
173
|
-
return averageDistance <= maxAllowedDistance;
|
|
174
|
-
}
|
|
175
|
-
isActualContentMatch(currentChunk, originalIndex) {
|
|
176
|
-
const originalChunk = this.streamContentHistory.substring(originalIndex, originalIndex + this.contentChunkSize);
|
|
177
|
-
return originalChunk === currentChunk;
|
|
178
|
-
}
|
|
179
|
-
resetContentTracking(resetHistory = true) {
|
|
180
|
-
if (resetHistory) {
|
|
181
|
-
this.streamContentHistory = '';
|
|
182
|
-
}
|
|
183
|
-
this.contentStats.clear();
|
|
184
|
-
this.lastContentIndex = 0;
|
|
185
|
-
}
|
|
186
|
-
reset() {
|
|
187
|
-
this.lastToolCallKey = null;
|
|
188
|
-
this.toolCallRepetitionCount = 0;
|
|
189
|
-
this.resetContentTracking();
|
|
190
|
-
this.turnsInCurrentPrompt = 0;
|
|
191
|
-
this.llmCheckInterval = this.defaultLLMCheckInterval;
|
|
192
|
-
this.lastCheckTurn = 0;
|
|
193
|
-
this.loopDetected = false;
|
|
194
|
-
this.inCodeBlock = false;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
exports.AdvancedLoopDetectionProcessor = AdvancedLoopDetectionProcessor;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { BaseProcessor, ProcessorInput, ProcessorOutput } from '../../processor';
|
|
2
|
-
export interface ChatCompressionInfo {
|
|
3
|
-
originalTokenCount: number;
|
|
4
|
-
newTokenCount: number;
|
|
5
|
-
compressionRatio: number;
|
|
6
|
-
threshold: number;
|
|
7
|
-
}
|
|
8
|
-
export interface ChatCompressionProcessorOptions {
|
|
9
|
-
compressionThreshold?: number;
|
|
10
|
-
compressionPreserveThreshold?: number;
|
|
11
|
-
tokenLimit?: number;
|
|
12
|
-
enableCompression?: boolean;
|
|
13
|
-
}
|
|
14
|
-
export declare class ChatCompressionProcessor extends BaseProcessor {
|
|
15
|
-
private readonly compressionThreshold;
|
|
16
|
-
private readonly compressionPreserveThreshold;
|
|
17
|
-
private readonly tokenLimit;
|
|
18
|
-
private readonly enableCompression;
|
|
19
|
-
constructor(options?: ChatCompressionProcessorOptions);
|
|
20
|
-
processInput(input: ProcessorInput): Promise<ProcessorOutput[]>;
|
|
21
|
-
private estimateTokenCount;
|
|
22
|
-
setCompressionThreshold(threshold: number): void;
|
|
23
|
-
setTokenLimit(limit: number): void;
|
|
24
|
-
enableCompressionForSession(): void;
|
|
25
|
-
disableCompressionForSession(): void;
|
|
26
|
-
}
|
|
@@ -1,90 +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.ChatCompressionProcessor = void 0;
|
|
7
|
-
const processor_1 = require("../../processor");
|
|
8
|
-
const codeboltjs_1 = __importDefault(require("@codebolt/codeboltjs"));
|
|
9
|
-
class ChatCompressionProcessor extends processor_1.BaseProcessor {
|
|
10
|
-
constructor(options = {}) {
|
|
11
|
-
super(options);
|
|
12
|
-
this.compressionThreshold = options.compressionThreshold || 0.7;
|
|
13
|
-
this.compressionPreserveThreshold = options.compressionPreserveThreshold || 0.3;
|
|
14
|
-
this.tokenLimit = options.tokenLimit || 128000;
|
|
15
|
-
this.enableCompression = options.enableCompression !== false;
|
|
16
|
-
}
|
|
17
|
-
async processInput(input) {
|
|
18
|
-
try {
|
|
19
|
-
const { message, context } = input;
|
|
20
|
-
if (!this.enableCompression) {
|
|
21
|
-
return [this.createEvent('ChatCompressionDisabled', {
|
|
22
|
-
reason: 'Compression is disabled for this session'
|
|
23
|
-
})];
|
|
24
|
-
}
|
|
25
|
-
// Get chat history from CodeBolt
|
|
26
|
-
const chatHistory = await codeboltjs_1.default.chat.getChatHistory();
|
|
27
|
-
if (chatHistory.length === 0) {
|
|
28
|
-
return [this.createEvent('NoChatHistory', {
|
|
29
|
-
reason: 'No chat history available for compression'
|
|
30
|
-
})];
|
|
31
|
-
}
|
|
32
|
-
// Estimate token count (simple heuristic: 4 chars per token)
|
|
33
|
-
const estimatedTokens = this.estimateTokenCount(chatHistory);
|
|
34
|
-
const threshold = this.compressionThreshold * this.tokenLimit;
|
|
35
|
-
console.log(`[Compression] Estimated tokens: ${estimatedTokens}, threshold: ${threshold}`);
|
|
36
|
-
if (estimatedTokens < threshold) {
|
|
37
|
-
return [this.createEvent('ChatCompressionSkipped', {
|
|
38
|
-
estimatedTokens,
|
|
39
|
-
threshold,
|
|
40
|
-
reason: 'Below compression threshold'
|
|
41
|
-
})];
|
|
42
|
-
}
|
|
43
|
-
// Perform compression using CodeBolt's chatSummary
|
|
44
|
-
const compressionResult = await codeboltjs_1.default.chatSummary.summarizeAll();
|
|
45
|
-
if (compressionResult.success && compressionResult.data) {
|
|
46
|
-
const newTokenCount = this.estimateTokenCount(compressionResult.data);
|
|
47
|
-
const compressionInfo = {
|
|
48
|
-
originalTokenCount: estimatedTokens,
|
|
49
|
-
newTokenCount,
|
|
50
|
-
compressionRatio: newTokenCount / estimatedTokens,
|
|
51
|
-
threshold: this.compressionThreshold
|
|
52
|
-
};
|
|
53
|
-
// Send notification about compression
|
|
54
|
-
await codeboltjs_1.default.chat.sendNotificationEvent(`Chat compressed: ${estimatedTokens} → ${newTokenCount} tokens`, 'debug');
|
|
55
|
-
return [this.createEvent('ChatCompressed', compressionInfo)];
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
return [this.createEvent('ChatCompressionFailed', {
|
|
59
|
-
error: compressionResult.message || 'Unknown compression error',
|
|
60
|
-
originalTokenCount: estimatedTokens
|
|
61
|
-
})];
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
catch (error) {
|
|
65
|
-
console.error('Error in ChatCompressionProcessor:', error);
|
|
66
|
-
return [this.createEvent('ChatCompressionError', {
|
|
67
|
-
error: error instanceof Error ? error.message : String(error)
|
|
68
|
-
})];
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
estimateTokenCount(data) {
|
|
72
|
-
// Simple heuristic: 4 characters per token
|
|
73
|
-
const totalContent = JSON.stringify(data);
|
|
74
|
-
return Math.ceil(totalContent.length / 4);
|
|
75
|
-
}
|
|
76
|
-
// Public methods for external control
|
|
77
|
-
setCompressionThreshold(threshold) {
|
|
78
|
-
this.compressionThreshold = Math.max(0.1, Math.min(0.9, threshold));
|
|
79
|
-
}
|
|
80
|
-
setTokenLimit(limit) {
|
|
81
|
-
this.tokenLimit = Math.max(1000, limit);
|
|
82
|
-
}
|
|
83
|
-
enableCompressionForSession() {
|
|
84
|
-
this.enableCompression = true;
|
|
85
|
-
}
|
|
86
|
-
disableCompressionForSession() {
|
|
87
|
-
this.enableCompression = false;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
exports.ChatCompressionProcessor = ChatCompressionProcessor;
|