@codebolt/agent 2.2.2 → 2.2.3
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 +15 -15
- 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
|
@@ -0,0 +1,330 @@
|
|
|
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.DirectoryContextModifier = 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
|
+
const MAX_ITEMS = 200;
|
|
45
|
+
const TRUNCATION_INDICATOR = '...';
|
|
46
|
+
const DEFAULT_IGNORED_FOLDERS = new Set(['node_modules', '.git', 'dist']);
|
|
47
|
+
// Error handling utility (simplified version of gemini-cli's getErrorMessage)
|
|
48
|
+
function getErrorMessage(error) {
|
|
49
|
+
if (error instanceof Error) {
|
|
50
|
+
return error.message;
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
return String(error);
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return 'Failed to get error details';
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Node error type guard
|
|
60
|
+
function isNodeError(error) {
|
|
61
|
+
return error instanceof Error && 'code' in error;
|
|
62
|
+
}
|
|
63
|
+
class DirectoryContextModifier extends base_1.BaseMessageModifier {
|
|
64
|
+
constructor(options = {}) {
|
|
65
|
+
super();
|
|
66
|
+
this.options = {
|
|
67
|
+
workspaceDirectories: options.workspaceDirectories || []
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
async modify(originalRequest, createdMessage) {
|
|
71
|
+
try {
|
|
72
|
+
// Get workspace directories from codebolt or use provided options
|
|
73
|
+
let workspaceDirectories = this.options.workspaceDirectories;
|
|
74
|
+
if (!workspaceDirectories || workspaceDirectories.length === 0) {
|
|
75
|
+
const { projectPath } = await codeboltjs_1.default.project.getProjectPath();
|
|
76
|
+
workspaceDirectories = projectPath ? [projectPath] : [];
|
|
77
|
+
}
|
|
78
|
+
if (workspaceDirectories.length === 0) {
|
|
79
|
+
return createdMessage;
|
|
80
|
+
}
|
|
81
|
+
const folderStructures = await Promise.all(workspaceDirectories.map((dir) => this.getFolderStructure(dir)));
|
|
82
|
+
const folderStructure = folderStructures.join('\n');
|
|
83
|
+
let workingDirPreamble;
|
|
84
|
+
if (workspaceDirectories.length === 1) {
|
|
85
|
+
workingDirPreamble = `I'm currently working in the directory: ${workspaceDirectories[0]}`;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
const dirList = workspaceDirectories.map((dir) => ` - ${dir}`).join('\n');
|
|
89
|
+
workingDirPreamble = `I'm currently working in the following directories:\n${dirList}`;
|
|
90
|
+
}
|
|
91
|
+
const directoryContext = `${workingDirPreamble}
|
|
92
|
+
Here is the folder structure of the current working directories:
|
|
93
|
+
|
|
94
|
+
${folderStructure}`;
|
|
95
|
+
const contextMessage = {
|
|
96
|
+
role: 'user', // Note: gemini-cli adds this as user message, not system
|
|
97
|
+
content: directoryContext
|
|
98
|
+
};
|
|
99
|
+
// Add as user message (like gemini-cli does)
|
|
100
|
+
const messages = [...createdMessage.message.messages, contextMessage];
|
|
101
|
+
return Promise.resolve({
|
|
102
|
+
message: {
|
|
103
|
+
...createdMessage.message,
|
|
104
|
+
messages
|
|
105
|
+
},
|
|
106
|
+
metadata: {
|
|
107
|
+
...createdMessage.metadata,
|
|
108
|
+
directoryContextAdded: true,
|
|
109
|
+
workspaceDirectories
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
console.error('Error in DirectoryContextModifier:', error);
|
|
115
|
+
return createdMessage;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Generates a string representation of a directory's structure,
|
|
120
|
+
* limiting the number of items displayed. Ignored folders are shown
|
|
121
|
+
* followed by '...' instead of their contents.
|
|
122
|
+
*
|
|
123
|
+
* @param directory The absolute or relative path to the directory.
|
|
124
|
+
* @param options Optional configuration settings.
|
|
125
|
+
* @returns A promise resolving to the formatted folder structure string.
|
|
126
|
+
*/
|
|
127
|
+
async getFolderStructure(directory, options) {
|
|
128
|
+
var _a, _b;
|
|
129
|
+
const resolvedPath = path.resolve(directory);
|
|
130
|
+
const mergedOptions = {
|
|
131
|
+
maxItems: (_a = options === null || options === void 0 ? void 0 : options.maxItems) !== null && _a !== void 0 ? _a : MAX_ITEMS,
|
|
132
|
+
ignoredFolders: (_b = options === null || options === void 0 ? void 0 : options.ignoredFolders) !== null && _b !== void 0 ? _b : DEFAULT_IGNORED_FOLDERS,
|
|
133
|
+
fileIncludePattern: options === null || options === void 0 ? void 0 : options.fileIncludePattern,
|
|
134
|
+
};
|
|
135
|
+
try {
|
|
136
|
+
// 1. Read the structure using BFS, respecting maxItems
|
|
137
|
+
const structureRoot = await this.readFullStructure(resolvedPath, mergedOptions);
|
|
138
|
+
if (!structureRoot) {
|
|
139
|
+
return `Error: Could not read directory "${resolvedPath}". Check path and permissions.`;
|
|
140
|
+
}
|
|
141
|
+
// 2. Format the structure into a string
|
|
142
|
+
const structureLines = [];
|
|
143
|
+
// Pass true for isRoot for the initial call
|
|
144
|
+
this.formatStructure(structureRoot, '', true, true, structureLines);
|
|
145
|
+
// 3. Build the final output string
|
|
146
|
+
function isTruncated(node) {
|
|
147
|
+
if (node.hasMoreFiles || node.hasMoreSubfolders || node.isIgnored) {
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
for (const sub of node.subFolders) {
|
|
151
|
+
if (isTruncated(sub)) {
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
let summary = `Showing up to ${mergedOptions.maxItems} items (files + folders).`;
|
|
158
|
+
if (isTruncated(structureRoot)) {
|
|
159
|
+
summary += ` Folders or files indicated with ${TRUNCATION_INDICATOR} contain more items not shown, were ignored, or the display limit (${mergedOptions.maxItems} items) was reached.`;
|
|
160
|
+
}
|
|
161
|
+
return `${summary}\n\n${resolvedPath}${path.sep}\n${structureLines.join('\n')}`;
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
console.error(`Error getting folder structure for ${resolvedPath}:`, error);
|
|
165
|
+
return `Error processing directory "${resolvedPath}": ${getErrorMessage(error)}`;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
async readFullStructure(rootPath, options) {
|
|
169
|
+
const rootName = path.basename(rootPath);
|
|
170
|
+
const rootNode = {
|
|
171
|
+
name: rootName,
|
|
172
|
+
path: rootPath,
|
|
173
|
+
files: [],
|
|
174
|
+
subFolders: [],
|
|
175
|
+
totalChildren: 0,
|
|
176
|
+
totalFiles: 0,
|
|
177
|
+
};
|
|
178
|
+
const queue = [
|
|
179
|
+
{ folderInfo: rootNode, currentPath: rootPath },
|
|
180
|
+
];
|
|
181
|
+
let currentItemCount = 0;
|
|
182
|
+
// Count the root node itself as one item if we are not just listing its content
|
|
183
|
+
const processedPaths = new Set(); // To avoid processing same path if symlinks create loops
|
|
184
|
+
while (queue.length > 0) {
|
|
185
|
+
const { folderInfo, currentPath } = queue.shift();
|
|
186
|
+
if (processedPaths.has(currentPath)) {
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
processedPaths.add(currentPath);
|
|
190
|
+
if (currentItemCount >= options.maxItems) {
|
|
191
|
+
// If the root itself caused us to exceed, we can't really show anything.
|
|
192
|
+
// Otherwise, this folder won't be processed further.
|
|
193
|
+
// The parent that queued this would have set its own hasMoreSubfolders flag.
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
let entries;
|
|
197
|
+
try {
|
|
198
|
+
const rawEntries = await fs.readdir(currentPath, { withFileTypes: true });
|
|
199
|
+
// Sort entries alphabetically by name for consistent processing order
|
|
200
|
+
entries = rawEntries.sort((a, b) => a.name.localeCompare(b.name));
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
if (isNodeError(error) &&
|
|
204
|
+
(error.code === 'EACCES' || error.code === 'ENOENT')) {
|
|
205
|
+
console.warn(`Warning: Could not read directory ${currentPath}: ${error.message}`);
|
|
206
|
+
if (currentPath === rootPath && error.code === 'ENOENT') {
|
|
207
|
+
return null; // Root directory itself not found
|
|
208
|
+
}
|
|
209
|
+
// For other EACCES/ENOENT on subdirectories, just skip them.
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
throw error;
|
|
213
|
+
}
|
|
214
|
+
const filesInCurrentDir = [];
|
|
215
|
+
const subFoldersInCurrentDir = [];
|
|
216
|
+
// Process files first in the current directory
|
|
217
|
+
for (const entry of entries) {
|
|
218
|
+
if (entry.isFile()) {
|
|
219
|
+
if (currentItemCount >= options.maxItems) {
|
|
220
|
+
folderInfo.hasMoreFiles = true;
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
const fileName = entry.name;
|
|
224
|
+
if (!options.fileIncludePattern ||
|
|
225
|
+
options.fileIncludePattern.test(fileName)) {
|
|
226
|
+
filesInCurrentDir.push(fileName);
|
|
227
|
+
currentItemCount++;
|
|
228
|
+
folderInfo.totalFiles++;
|
|
229
|
+
folderInfo.totalChildren++;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
folderInfo.files = filesInCurrentDir;
|
|
234
|
+
// Then process directories and queue them
|
|
235
|
+
for (const entry of entries) {
|
|
236
|
+
if (entry.isDirectory()) {
|
|
237
|
+
// Check if adding this directory ITSELF would meet or exceed maxItems
|
|
238
|
+
// (currentItemCount refers to items *already* added before this one)
|
|
239
|
+
if (currentItemCount >= options.maxItems) {
|
|
240
|
+
folderInfo.hasMoreSubfolders = true;
|
|
241
|
+
break; // Already at limit, cannot add this folder or any more
|
|
242
|
+
}
|
|
243
|
+
// If adding THIS folder makes us hit the limit exactly, and it might have children,
|
|
244
|
+
// it's better to show '...' for the parent, unless this is the very last item slot.
|
|
245
|
+
// This logic is tricky. Let's try a simpler: if we can't add this item, mark and break.
|
|
246
|
+
const subFolderName = entry.name;
|
|
247
|
+
const subFolderPath = path.join(currentPath, subFolderName);
|
|
248
|
+
if (options.ignoredFolders.has(subFolderName)) {
|
|
249
|
+
const ignoredSubFolder = {
|
|
250
|
+
name: subFolderName,
|
|
251
|
+
path: subFolderPath,
|
|
252
|
+
files: [],
|
|
253
|
+
subFolders: [],
|
|
254
|
+
totalChildren: 0,
|
|
255
|
+
totalFiles: 0,
|
|
256
|
+
isIgnored: true,
|
|
257
|
+
};
|
|
258
|
+
subFoldersInCurrentDir.push(ignoredSubFolder);
|
|
259
|
+
currentItemCount++; // Count the ignored folder itself
|
|
260
|
+
folderInfo.totalChildren++; // Also counts towards parent's children
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
const subFolderNode = {
|
|
264
|
+
name: subFolderName,
|
|
265
|
+
path: subFolderPath,
|
|
266
|
+
files: [],
|
|
267
|
+
subFolders: [],
|
|
268
|
+
totalChildren: 0,
|
|
269
|
+
totalFiles: 0,
|
|
270
|
+
};
|
|
271
|
+
subFoldersInCurrentDir.push(subFolderNode);
|
|
272
|
+
currentItemCount++;
|
|
273
|
+
folderInfo.totalChildren++; // Counts towards parent's children
|
|
274
|
+
// Add to queue for processing its children later
|
|
275
|
+
queue.push({ folderInfo: subFolderNode, currentPath: subFolderPath });
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
folderInfo.subFolders = subFoldersInCurrentDir;
|
|
279
|
+
}
|
|
280
|
+
return rootNode;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Reads the directory structure using BFS, respecting maxItems.
|
|
284
|
+
* @param node The current node in the reduced structure.
|
|
285
|
+
* @param indent The current indentation string.
|
|
286
|
+
* @param isLast Sibling indicator.
|
|
287
|
+
* @param builder Array to build the string lines.
|
|
288
|
+
*/
|
|
289
|
+
formatStructure(node, currentIndent, isLastChildOfParent, isProcessingRootNode, builder) {
|
|
290
|
+
const connector = isLastChildOfParent ? '└───' : '├───';
|
|
291
|
+
// The root node of the structure (the one passed initially to getFolderStructure)
|
|
292
|
+
// is not printed with a connector line itself, only its name as a header.
|
|
293
|
+
// Its children are printed relative to that conceptual root.
|
|
294
|
+
// Ignored root nodes ARE printed with a connector.
|
|
295
|
+
if (!isProcessingRootNode || node.isIgnored) {
|
|
296
|
+
builder.push(`${currentIndent}${connector}${node.name}${path.sep}${node.isIgnored ? TRUNCATION_INDICATOR : ''}`);
|
|
297
|
+
}
|
|
298
|
+
// Determine the indent for the children of *this* node.
|
|
299
|
+
// If *this* node was the root of the whole structure, its children start with no indent before their connectors.
|
|
300
|
+
// Otherwise, children's indent extends from the current node's indent.
|
|
301
|
+
const indentForChildren = isProcessingRootNode
|
|
302
|
+
? ''
|
|
303
|
+
: currentIndent + (isLastChildOfParent ? ' ' : '│ ');
|
|
304
|
+
// Render files of the current node
|
|
305
|
+
const fileCount = node.files.length;
|
|
306
|
+
for (let i = 0; i < fileCount; i++) {
|
|
307
|
+
const isLastFileAmongSiblings = i === fileCount - 1 &&
|
|
308
|
+
node.subFolders.length === 0 &&
|
|
309
|
+
!node.hasMoreSubfolders;
|
|
310
|
+
const fileConnector = isLastFileAmongSiblings ? '└───' : '├───';
|
|
311
|
+
builder.push(`${indentForChildren}${fileConnector}${node.files[i]}`);
|
|
312
|
+
}
|
|
313
|
+
if (node.hasMoreFiles) {
|
|
314
|
+
const isLastIndicatorAmongSiblings = node.subFolders.length === 0 && !node.hasMoreSubfolders;
|
|
315
|
+
const fileConnector = isLastIndicatorAmongSiblings ? '└───' : '├───';
|
|
316
|
+
builder.push(`${indentForChildren}${fileConnector}${TRUNCATION_INDICATOR}`);
|
|
317
|
+
}
|
|
318
|
+
// Render subfolders of the current node
|
|
319
|
+
const subFolderCount = node.subFolders.length;
|
|
320
|
+
for (let i = 0; i < subFolderCount; i++) {
|
|
321
|
+
const isLastSubfolderAmongSiblings = i === subFolderCount - 1 && !node.hasMoreSubfolders;
|
|
322
|
+
// Children are never the root node being processed initially.
|
|
323
|
+
this.formatStructure(node.subFolders[i], indentForChildren, isLastSubfolderAmongSiblings, false, builder);
|
|
324
|
+
}
|
|
325
|
+
if (node.hasMoreSubfolders) {
|
|
326
|
+
builder.push(`${indentForChildren}└───${TRUNCATION_INDICATOR}`);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
exports.DirectoryContextModifier = DirectoryContextModifier;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ProcessedMessage } from "@codebolt/types/agent";
|
|
2
|
+
import { BaseMessageModifier } from "../base";
|
|
3
|
+
import { FlatUserMessage } from "@codebolt/types/sdk";
|
|
4
|
+
export interface EnvironmentContextOptions {
|
|
5
|
+
enableFullContext?: boolean;
|
|
6
|
+
maxFiles?: number;
|
|
7
|
+
maxFileSize?: number;
|
|
8
|
+
includePatterns?: string[];
|
|
9
|
+
excludePatterns?: string[];
|
|
10
|
+
}
|
|
11
|
+
export declare class EnvironmentContextModifier extends BaseMessageModifier {
|
|
12
|
+
private readonly options;
|
|
13
|
+
private readonly defaultExcludePatterns;
|
|
14
|
+
constructor(options?: EnvironmentContextOptions);
|
|
15
|
+
modify(originalRequest: FlatUserMessage, createdMessage: ProcessedMessage): Promise<ProcessedMessage>;
|
|
16
|
+
private generateFullContext;
|
|
17
|
+
private findRelevantFiles;
|
|
18
|
+
private walkDirectory;
|
|
19
|
+
private isExcluded;
|
|
20
|
+
private isIncluded;
|
|
21
|
+
private matchesPattern;
|
|
22
|
+
private countContextFiles;
|
|
23
|
+
enableFullContext(): void;
|
|
24
|
+
disableFullContext(): void;
|
|
25
|
+
isFullContextEnabled(): boolean;
|
|
26
|
+
}
|
|
@@ -0,0 +1,269 @@
|
|
|
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.EnvironmentContextModifier = void 0;
|
|
40
|
+
const base_1 = require("../base");
|
|
41
|
+
const path = __importStar(require("path"));
|
|
42
|
+
const fs = __importStar(require("fs"));
|
|
43
|
+
const codeboltjs_1 = __importDefault(require("@codebolt/codeboltjs"));
|
|
44
|
+
class EnvironmentContextModifier extends base_1.BaseMessageModifier {
|
|
45
|
+
constructor(options = {}) {
|
|
46
|
+
super();
|
|
47
|
+
this.defaultExcludePatterns = [
|
|
48
|
+
'node_modules/**',
|
|
49
|
+
'.git/**',
|
|
50
|
+
'dist/**',
|
|
51
|
+
'build/**',
|
|
52
|
+
'*.log',
|
|
53
|
+
'*.tmp',
|
|
54
|
+
'.DS_Store',
|
|
55
|
+
'coverage/**',
|
|
56
|
+
'.next/**',
|
|
57
|
+
'.nuxt/**'
|
|
58
|
+
];
|
|
59
|
+
this.options = {
|
|
60
|
+
enableFullContext: options.enableFullContext || false,
|
|
61
|
+
maxFiles: options.maxFiles || 100,
|
|
62
|
+
maxFileSize: options.maxFileSize || 100 * 1024, // 100KB per file
|
|
63
|
+
includePatterns: options.includePatterns || ['**/*.ts', '**/*.js', '**/*.json', '**/*.md', '**/*.txt', '**/*.yml', '**/*.yaml'],
|
|
64
|
+
excludePatterns: [...this.defaultExcludePatterns, ...(options.excludePatterns || [])]
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
async modify(originalRequest, createdMessage) {
|
|
68
|
+
try {
|
|
69
|
+
// Get current date formatted to user's locale
|
|
70
|
+
const today = new Date().toLocaleDateString(undefined, {
|
|
71
|
+
weekday: 'long',
|
|
72
|
+
year: 'numeric',
|
|
73
|
+
month: 'long',
|
|
74
|
+
day: 'numeric',
|
|
75
|
+
});
|
|
76
|
+
const platform = process.platform;
|
|
77
|
+
const { projectPath } = await codeboltjs_1.default.project.getProjectPath();
|
|
78
|
+
if (!projectPath) {
|
|
79
|
+
return createdMessage;
|
|
80
|
+
}
|
|
81
|
+
const currentDir = projectPath;
|
|
82
|
+
// Get basic directory listing
|
|
83
|
+
let directoryListing = '';
|
|
84
|
+
try {
|
|
85
|
+
const files = await fs.promises.readdir(currentDir);
|
|
86
|
+
const fileList = files.slice(0, 20).join(', '); // Limit to first 20 files
|
|
87
|
+
const moreFiles = files.length > 20 ? ` ... and ${files.length - 20} more files` : '';
|
|
88
|
+
directoryListing = `Files in current directory: ${fileList}${moreFiles}`;
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
directoryListing = 'Unable to read current directory';
|
|
92
|
+
}
|
|
93
|
+
const environmentContext = `
|
|
94
|
+
This is the CodeBolt AI Agent. Setting up context for our chat.
|
|
95
|
+
Today's date is ${today} (formatted according to the user's locale).
|
|
96
|
+
Operating system: ${platform}
|
|
97
|
+
Current working directory: ${currentDir}
|
|
98
|
+
${directoryListing}
|
|
99
|
+
`.trim();
|
|
100
|
+
// Prepare context parts (same as gemini-cli)
|
|
101
|
+
const contextParts = [environmentContext];
|
|
102
|
+
// Add full file context if enabled (just like gemini-cli does)
|
|
103
|
+
if (this.options.enableFullContext) {
|
|
104
|
+
try {
|
|
105
|
+
const fullContextContent = await this.generateFullContext(currentDir);
|
|
106
|
+
if (fullContextContent) {
|
|
107
|
+
contextParts.push(`\n--- Full File Context ---\n${fullContextContent}`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
console.error('Error reading full file context:', error);
|
|
112
|
+
contextParts.push('\n--- Error reading full file context ---');
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const finalContent = contextParts.join('\n\n');
|
|
116
|
+
const contextMessage = {
|
|
117
|
+
role: 'system',
|
|
118
|
+
content: finalContent
|
|
119
|
+
};
|
|
120
|
+
// Find existing system message or add new one
|
|
121
|
+
const messages = [...createdMessage.message.messages];
|
|
122
|
+
const systemMessageIndex = messages.findIndex(msg => msg.role === 'system');
|
|
123
|
+
if (systemMessageIndex !== -1) {
|
|
124
|
+
// Append to existing system message
|
|
125
|
+
messages[systemMessageIndex] = {
|
|
126
|
+
...messages[systemMessageIndex],
|
|
127
|
+
content: `${messages[systemMessageIndex].content}\n\n${finalContent}`
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
// Add new system message at the beginning
|
|
132
|
+
messages.unshift(contextMessage);
|
|
133
|
+
}
|
|
134
|
+
return Promise.resolve({
|
|
135
|
+
message: {
|
|
136
|
+
...createdMessage.message,
|
|
137
|
+
messages
|
|
138
|
+
},
|
|
139
|
+
metadata: {
|
|
140
|
+
...createdMessage.metadata,
|
|
141
|
+
environmentContextAdded: true,
|
|
142
|
+
fullContextAdded: this.options.enableFullContext,
|
|
143
|
+
contextFilesCount: this.options.enableFullContext ? await this.countContextFiles(currentDir) : 0,
|
|
144
|
+
environmentInfo: {
|
|
145
|
+
date: today,
|
|
146
|
+
platform,
|
|
147
|
+
currentDir
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
console.error('Error in EnvironmentContextModifier:', error);
|
|
154
|
+
return createdMessage;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
// Full context methods (integrated like gemini-cli)
|
|
158
|
+
async generateFullContext(basePath) {
|
|
159
|
+
try {
|
|
160
|
+
const files = await this.findRelevantFiles(basePath);
|
|
161
|
+
const contextParts = [];
|
|
162
|
+
let processedFiles = 0;
|
|
163
|
+
for (const filePath of files) {
|
|
164
|
+
if (processedFiles >= this.options.maxFiles) {
|
|
165
|
+
contextParts.push(`\n... (${files.length - processedFiles} more files not shown due to limit)\n`);
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
try {
|
|
169
|
+
const relativePath = path.relative(basePath, filePath);
|
|
170
|
+
const stats = await fs.promises.stat(filePath);
|
|
171
|
+
// Skip files that are too large
|
|
172
|
+
if (stats.size > this.options.maxFileSize) {
|
|
173
|
+
contextParts.push(`--- ${relativePath} ---\n[File too large: ${stats.size} bytes]\n`);
|
|
174
|
+
processedFiles++;
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
const content = await fs.promises.readFile(filePath, 'utf-8');
|
|
178
|
+
contextParts.push(`--- ${relativePath} ---\n${content}\n`);
|
|
179
|
+
processedFiles++;
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
const relativePath = path.relative(basePath, filePath);
|
|
183
|
+
contextParts.push(`--- ${relativePath} ---\n[Error reading file: ${error instanceof Error ? error.message : 'Unknown error'}]\n`);
|
|
184
|
+
processedFiles++;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return contextParts.join('\n');
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
console.error('Error generating full context:', error);
|
|
191
|
+
return '';
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
async findRelevantFiles(basePath) {
|
|
195
|
+
const files = [];
|
|
196
|
+
try {
|
|
197
|
+
await this.walkDirectory(basePath, files, basePath);
|
|
198
|
+
return files.sort();
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
console.error('Error finding relevant files:', error);
|
|
202
|
+
return [];
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
async walkDirectory(dir, files, basePath) {
|
|
206
|
+
try {
|
|
207
|
+
const entries = await fs.promises.readdir(dir, { withFileTypes: true });
|
|
208
|
+
for (const entry of entries) {
|
|
209
|
+
const fullPath = path.join(dir, entry.name);
|
|
210
|
+
const relativePath = path.relative(basePath, fullPath);
|
|
211
|
+
// Check exclusion patterns
|
|
212
|
+
if (this.isExcluded(relativePath)) {
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
if (entry.isDirectory()) {
|
|
216
|
+
await this.walkDirectory(fullPath, files, basePath);
|
|
217
|
+
}
|
|
218
|
+
else if (entry.isFile()) {
|
|
219
|
+
// Check inclusion patterns
|
|
220
|
+
if (this.isIncluded(relativePath)) {
|
|
221
|
+
files.push(fullPath);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
// Skip directories we can't read
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
isExcluded(relativePath) {
|
|
231
|
+
return this.options.excludePatterns.some(pattern => {
|
|
232
|
+
return this.matchesPattern(relativePath, pattern);
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
isIncluded(relativePath) {
|
|
236
|
+
return this.options.includePatterns.some(pattern => {
|
|
237
|
+
return this.matchesPattern(relativePath, pattern);
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
matchesPattern(filePath, pattern) {
|
|
241
|
+
// Simple glob pattern matching - in production, use a proper glob library
|
|
242
|
+
const regexPattern = pattern
|
|
243
|
+
.replace(/\*\*/g, '.*')
|
|
244
|
+
.replace(/\*/g, '[^/]*')
|
|
245
|
+
.replace(/\?/g, '.');
|
|
246
|
+
const regex = new RegExp(`^${regexPattern}$`);
|
|
247
|
+
return regex.test(filePath);
|
|
248
|
+
}
|
|
249
|
+
async countContextFiles(basePath) {
|
|
250
|
+
try {
|
|
251
|
+
const files = await this.findRelevantFiles(basePath);
|
|
252
|
+
return Math.min(files.length, this.options.maxFiles);
|
|
253
|
+
}
|
|
254
|
+
catch (error) {
|
|
255
|
+
return 0;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
// Public methods to control full context
|
|
259
|
+
enableFullContext() {
|
|
260
|
+
this.options.enableFullContext = true;
|
|
261
|
+
}
|
|
262
|
+
disableFullContext() {
|
|
263
|
+
this.options.enableFullContext = false;
|
|
264
|
+
}
|
|
265
|
+
isFullContextEnabled() {
|
|
266
|
+
return this.options.enableFullContext || false;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
exports.EnvironmentContextModifier = EnvironmentContextModifier;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ProcessedMessage } from "@codebolt/types/agent";
|
|
2
|
+
import { BaseMessageModifier } from "../base";
|
|
3
|
+
import { FlatUserMessage } from "@codebolt/types/sdk";
|
|
4
|
+
export interface FallbackHandlerOptions {
|
|
5
|
+
enableFallback?: boolean;
|
|
6
|
+
maxRetries?: number;
|
|
7
|
+
fallbackStrategies?: FallbackStrategy[];
|
|
8
|
+
timeoutMs?: number;
|
|
9
|
+
}
|
|
10
|
+
export declare enum FallbackStrategy {
|
|
11
|
+
RETRY_WITH_SIMPLIFIED_CONTEXT = "retry_simplified",
|
|
12
|
+
RETRY_WITHOUT_TOOLS = "retry_no_tools",
|
|
13
|
+
RETRY_WITH_SHORTER_HISTORY = "retry_short_history",
|
|
14
|
+
USE_FALLBACK_MODEL = "fallback_model",
|
|
15
|
+
PROVIDE_ERROR_CONTEXT = "error_context"
|
|
16
|
+
}
|
|
17
|
+
export declare class FallbackHandlerModifier extends BaseMessageModifier {
|
|
18
|
+
private readonly options;
|
|
19
|
+
private fallbackContexts;
|
|
20
|
+
constructor(options?: FallbackHandlerOptions);
|
|
21
|
+
modify(originalRequest: FlatUserMessage, createdMessage: ProcessedMessage): Promise<ProcessedMessage>;
|
|
22
|
+
private generateMessageId;
|
|
23
|
+
private shouldApplyFallback;
|
|
24
|
+
private initializeFallbackContext;
|
|
25
|
+
private applyFallbackStrategy;
|
|
26
|
+
private getNextFallbackStrategy;
|
|
27
|
+
private simplifyContext;
|
|
28
|
+
private removeTools;
|
|
29
|
+
private shortenHistory;
|
|
30
|
+
private setFallbackModel;
|
|
31
|
+
private addErrorContextMessage;
|
|
32
|
+
private updateFallbackContext;
|
|
33
|
+
clearFallbackContext(messageId: string): void;
|
|
34
|
+
getFallbackStats(): {
|
|
35
|
+
totalContexts: number;
|
|
36
|
+
averageAttempts: number;
|
|
37
|
+
};
|
|
38
|
+
}
|