@codebolt/agent 1.2.1 → 2.2.2
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/README.md +157 -66
- package/dist/builderpattern/agent.d.ts +86 -0
- package/dist/builderpattern/agent.js +324 -0
- package/dist/builderpattern/followupquestionbuilder.d.ts +75 -0
- package/dist/builderpattern/followupquestionbuilder.js +197 -0
- package/dist/builderpattern/index.d.ts +14 -0
- package/dist/builderpattern/index.js +23 -0
- package/dist/builderpattern/llmoutputhandler.d.ts +102 -0
- package/dist/builderpattern/llmoutputhandler.js +452 -0
- package/dist/builderpattern/promptbuilder.d.ts +382 -0
- package/dist/builderpattern/promptbuilder.js +805 -0
- package/dist/builderpattern/systemprompt.d.ts +20 -0
- package/dist/builderpattern/systemprompt.js +48 -0
- package/dist/builderpattern/taskInstruction.d.ts +37 -0
- package/dist/builderpattern/taskInstruction.js +57 -0
- package/dist/builderpattern/usermessage.d.ts +70 -0
- package/dist/builderpattern/usermessage.js +123 -0
- package/dist/composablepattern/agent.d.ts +169 -0
- package/dist/composablepattern/agent.js +598 -0
- package/dist/composablepattern/codebolt-storage.d.ts +67 -0
- package/dist/composablepattern/codebolt-storage.js +320 -0
- package/dist/composablepattern/document.d.ts +149 -0
- package/dist/composablepattern/document.js +405 -0
- package/dist/composablepattern/examples/codebolt-integration-example.d.ts +12 -0
- package/dist/composablepattern/examples/codebolt-integration-example.js +218 -0
- package/dist/composablepattern/examples/codebolt-storage-example.d.ts +40 -0
- package/dist/composablepattern/examples/codebolt-storage-example.js +223 -0
- package/dist/composablepattern/examples/custom-steps-example.d.ts +20 -0
- package/dist/composablepattern/examples/custom-steps-example.js +455 -0
- package/dist/composablepattern/examples/document-agent.d.ts +17 -0
- package/dist/composablepattern/examples/document-agent.js +107 -0
- package/dist/composablepattern/examples/simple-codebolt-integration.d.ts +8 -0
- package/dist/composablepattern/examples/simple-codebolt-integration.js +164 -0
- package/dist/composablepattern/examples/weather-agent.d.ts +18 -0
- package/dist/composablepattern/examples/weather-agent.js +86 -0
- package/dist/composablepattern/examples/workflow-example.d.ts +12 -0
- package/dist/composablepattern/examples/workflow-example.js +463 -0
- package/dist/composablepattern/index.d.ts +63 -0
- package/dist/composablepattern/index.js +115 -0
- package/dist/composablepattern/memory.d.ts +89 -0
- package/dist/composablepattern/memory.js +141 -0
- package/dist/composablepattern/tool.d.ts +84 -0
- package/dist/composablepattern/tool.js +260 -0
- package/dist/composablepattern/types.d.ts +194 -0
- package/dist/composablepattern/types.js +6 -0
- package/dist/composablepattern/user-context.d.ts +214 -0
- package/dist/composablepattern/user-context.js +275 -0
- package/dist/composablepattern/workflow.d.ts +388 -0
- package/dist/composablepattern/workflow.js +562 -0
- package/dist/processor/agent/agentStep.d.ts +49 -0
- package/dist/processor/agent/agentStep.js +241 -0
- package/dist/processor/agent/toolExecutor.d.ts +19 -0
- package/dist/processor/agent/toolExecutor.js +90 -0
- package/dist/processor/index.d.ts +7 -0
- package/dist/processor/index.js +36 -0
- package/dist/processor/messageModifiers/baseMessageModifier.d.ts +20 -0
- package/dist/processor/messageModifiers/baseMessageModifier.js +55 -0
- package/dist/processor/processors/baseProcessor.d.ts +14 -0
- package/dist/processor/processors/baseProcessor.js +29 -0
- package/dist/processor/tools/baseTool.d.ts +10 -0
- package/dist/processor/tools/baseTool.js +20 -0
- package/dist/processor/tools/toolList.d.ts +9 -0
- package/dist/processor/tools/toolList.js +22 -0
- package/dist/processor/types/interfaces.d.ts +94 -0
- package/dist/processor/types/interfaces.js +2 -0
- package/dist/processor-pieces/base/baseMessageModifier.d.ts +12 -0
- package/dist/processor-pieces/base/baseMessageModifier.js +15 -0
- package/dist/processor-pieces/base/basePostInferenceProcessor.d.ts +13 -0
- package/dist/processor-pieces/base/basePostInferenceProcessor.js +18 -0
- package/dist/processor-pieces/base/basePostToolCallProcessor.d.ts +15 -0
- package/dist/processor-pieces/base/basePostToolCallProcessor.js +25 -0
- package/dist/processor-pieces/base/basePreInferenceProcessor.d.ts +12 -0
- package/dist/processor-pieces/base/basePreInferenceProcessor.js +17 -0
- package/dist/processor-pieces/base/basePreToolCallProcessor.d.ts +18 -0
- package/dist/processor-pieces/base/basePreToolCallProcessor.js +66 -0
- package/dist/processor-pieces/base/index.d.ts +9 -0
- package/dist/processor-pieces/base/index.js +18 -0
- package/dist/processor-pieces/index.d.ts +1 -0
- package/dist/processor-pieces/index.js +59 -0
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.d.ts +22 -0
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.js +144 -0
- package/dist/processor-pieces/messageModifiers/argumentProcessorModifier.d.ts +13 -0
- package/dist/processor-pieces/messageModifiers/argumentProcessorModifier.js +68 -0
- package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.d.ts +25 -0
- package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.js +453 -0
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.d.ts +15 -0
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.js +75 -0
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.d.ts +11 -0
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.js +46 -0
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.d.ts +18 -0
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.js +104 -0
- package/dist/processor-pieces/messageModifiers/chatRecordingModifier.d.ts +23 -0
- package/dist/processor-pieces/messageModifiers/chatRecordingModifier.js +173 -0
- package/dist/processor-pieces/messageModifiers/coreSystemPromptModifier.d.ts +14 -0
- package/dist/processor-pieces/messageModifiers/coreSystemPromptModifier.js +130 -0
- package/dist/processor-pieces/messageModifiers/directoryContextModifier.d.ts +36 -0
- package/dist/processor-pieces/messageModifiers/directoryContextModifier.js +418 -0
- package/dist/processor-pieces/messageModifiers/environmentContextModifier.d.ts +26 -0
- package/dist/processor-pieces/messageModifiers/environmentContextModifier.js +260 -0
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.d.ts +12 -0
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.js +60 -0
- package/dist/processor-pieces/messageModifiers/ideContextModifier.d.ts +34 -0
- package/dist/processor-pieces/messageModifiers/ideContextModifier.js +157 -0
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.d.ts +18 -0
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.js +222 -0
- package/dist/processor-pieces/messageModifiers/index.d.ts +11 -0
- package/dist/processor-pieces/messageModifiers/index.js +26 -0
- package/dist/processor-pieces/messageModifiers/memoryImportModifier.d.ts +15 -0
- package/dist/processor-pieces/messageModifiers/memoryImportModifier.js +129 -0
- package/dist/processor-pieces/messageModifiers/toolInjectionModifier.d.ts +20 -0
- package/dist/processor-pieces/messageModifiers/toolInjectionModifier.js +152 -0
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.d.ts +22 -0
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.js +194 -0
- package/dist/processor-pieces/postInferenceProcessors/loopDetectionModifier.d.ts +29 -0
- package/dist/processor-pieces/postInferenceProcessors/loopDetectionModifier.js +174 -0
- package/dist/processor-pieces/postToolCallProcessors/index.d.ts +1 -0
- package/dist/processor-pieces/postToolCallProcessors/index.js +2 -0
- package/dist/processor-pieces/postToolCallProcessors/shellProcessorModifier.d.ts +25 -0
- package/dist/processor-pieces/postToolCallProcessors/shellProcessorModifier.js +225 -0
- package/dist/processor-pieces/preInferenceProcessors/chatCompressionModifier.d.ts +35 -0
- package/dist/processor-pieces/preInferenceProcessors/chatCompressionModifier.js +255 -0
- package/dist/processor-pieces/preInferenceProcessors/index.d.ts +1 -0
- package/dist/processor-pieces/preInferenceProcessors/index.js +2 -0
- package/dist/processor-pieces/pretoolCallProcessors/index.d.ts +1 -0
- package/dist/processor-pieces/pretoolCallProcessors/index.js +2 -0
- package/dist/processor-pieces/processors/advancedLoopDetectionProcessor.d.ts +41 -0
- package/dist/processor-pieces/processors/advancedLoopDetectionProcessor.js +197 -0
- package/dist/processor-pieces/processors/chatCompressionProcessor.d.ts +26 -0
- package/dist/processor-pieces/processors/chatCompressionProcessor.js +90 -0
- package/dist/processor-pieces/processors/chatRecordingProcessor.d.ts +81 -0
- package/dist/processor-pieces/processors/chatRecordingProcessor.js +329 -0
- package/dist/processor-pieces/processors/contextManagementProcessor.d.ts +40 -0
- package/dist/processor-pieces/processors/contextManagementProcessor.js +305 -0
- package/dist/processor-pieces/processors/loopDetectionProcessor.d.ts +30 -0
- package/dist/processor-pieces/processors/loopDetectionProcessor.js +137 -0
- package/dist/processor-pieces/processors/responseValidationProcessor.d.ts +30 -0
- package/dist/processor-pieces/processors/responseValidationProcessor.js +228 -0
- package/dist/processor-pieces/processors/telemetryProcessor.d.ts +99 -0
- package/dist/processor-pieces/processors/telemetryProcessor.js +311 -0
- package/dist/processor-pieces/processors/tokenManagementProcessor.d.ts +37 -0
- package/dist/processor-pieces/processors/tokenManagementProcessor.js +178 -0
- package/dist/processor-pieces/processors/toolExecutionProcessor.d.ts +43 -0
- package/dist/processor-pieces/processors/toolExecutionProcessor.js +207 -0
- package/dist/processor-pieces/tools/fileTools.d.ts +26 -0
- package/dist/processor-pieces/tools/fileTools.js +162 -0
- package/dist/processor-pieces/utils/messageModifierHelper.d.ts +4 -0
- package/dist/processor-pieces/utils/messageModifierHelper.js +58 -0
- package/dist/types/commonTypes.d.ts +4 -0
- package/dist/types/processorTypes.d.ts +67 -0
- package/dist/types/processorTypes.js +58 -0
- package/dist/unified/agent/agent.d.ts +17 -0
- package/dist/unified/agent/agent.js +79 -0
- package/dist/unified/agent/team.d.ts +2 -0
- package/dist/unified/agent/team.js +6 -0
- package/dist/unified/agent/tools.d.ts +44 -0
- package/dist/unified/agent/tools.js +487 -0
- package/dist/unified/agent/workflow.d.ts +24 -0
- package/dist/unified/agent/workflow.js +275 -0
- package/dist/unified/agent/workflowControls.d.ts +11 -0
- package/dist/unified/agent/workflowControls.js +20 -0
- package/dist/unified/agent/workflowSteps.d.ts +63 -0
- package/dist/unified/agent/workflowSteps.js +284 -0
- package/dist/unified/base/agentStep.d.ts +32 -0
- package/dist/unified/base/agentStep.js +96 -0
- package/dist/unified/base/create/createInitialPromptGenerators.d.ts +5 -0
- package/dist/unified/base/create/createInitialPromptGenerators.js +17 -0
- package/dist/unified/base/index.d.ts +5 -0
- package/dist/unified/base/index.js +13 -0
- package/dist/unified/base/initialPromptGenerator.d.ts +48 -0
- package/dist/unified/base/initialPromptGenerator.js +118 -0
- package/dist/unified/base/responseExecutor.d.ts +36 -0
- package/dist/unified/base/responseExecutor.js +283 -0
- package/dist/unified/index.d.ts +18 -0
- package/dist/unified/index.js +42 -0
- package/dist/unified/team/team.d.ts +1 -0
- package/dist/unified/team/team.js +2 -0
- package/dist/unified/types/libTypes.d.ts +378 -0
- package/dist/unified/types/libTypes.js +6 -0
- package/dist/unified/types/types.d.ts +212 -0
- package/dist/unified/types/types.js +43 -0
- package/dist/unified/utils/utils.d.ts +40 -0
- package/dist/unified/utils/utils.js +219 -0
- package/package.json +29 -7
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResponseValidationProcessor = void 0;
|
|
4
|
+
const processor_1 = require("../../processor");
|
|
5
|
+
class ResponseValidationProcessor extends processor_1.BaseProcessor {
|
|
6
|
+
constructor(options = {}) {
|
|
7
|
+
super();
|
|
8
|
+
this.enableToolCallValidation = options.validateToolCalls !== false;
|
|
9
|
+
this.validateContent = options.validateContent !== false;
|
|
10
|
+
this.validateStructure = options.validateStructure !== false;
|
|
11
|
+
this.allowEmptyContent = options.allowEmptyContent || false;
|
|
12
|
+
this.maxContentLength = options.maxContentLength || 100000;
|
|
13
|
+
this.requiredFields = options.requiredFields || ['role'];
|
|
14
|
+
}
|
|
15
|
+
async processInput(input) {
|
|
16
|
+
var _a;
|
|
17
|
+
const { message } = input;
|
|
18
|
+
const validationResult = this.validateMessage(message);
|
|
19
|
+
const results = [
|
|
20
|
+
this.createEvent('ValidationCompleted', {
|
|
21
|
+
result: validationResult,
|
|
22
|
+
messageId: ((_a = message.metadata) === null || _a === void 0 ? void 0 : _a.id) || 'unknown'
|
|
23
|
+
})
|
|
24
|
+
];
|
|
25
|
+
if (!validationResult.isValid) {
|
|
26
|
+
results.push(this.createEvent('ValidationFailed', {
|
|
27
|
+
errors: validationResult.errors,
|
|
28
|
+
warnings: validationResult.warnings,
|
|
29
|
+
fixes: validationResult.fixes
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
if (validationResult.warnings.length > 0) {
|
|
33
|
+
results.push(this.createEvent('ValidationWarnings', {
|
|
34
|
+
warnings: validationResult.warnings
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
return results;
|
|
38
|
+
}
|
|
39
|
+
validateMessage(message) {
|
|
40
|
+
const errors = [];
|
|
41
|
+
const warnings = [];
|
|
42
|
+
const fixes = [];
|
|
43
|
+
// Structure validation
|
|
44
|
+
if (this.validateStructure) {
|
|
45
|
+
const structureValidation = this.validateMessageStructure(message);
|
|
46
|
+
errors.push(...structureValidation.errors);
|
|
47
|
+
warnings.push(...structureValidation.warnings);
|
|
48
|
+
fixes.push(...structureValidation.fixes);
|
|
49
|
+
}
|
|
50
|
+
// Content validation
|
|
51
|
+
if (this.validateContent && message.messages) {
|
|
52
|
+
for (let i = 0; i < message.messages.length; i++) {
|
|
53
|
+
const msg = message.messages[i];
|
|
54
|
+
const contentValidation = this.validateMessageContent(msg, i);
|
|
55
|
+
errors.push(...contentValidation.errors);
|
|
56
|
+
warnings.push(...contentValidation.warnings);
|
|
57
|
+
fixes.push(...contentValidation.fixes);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Tool calls validation
|
|
61
|
+
if (this.enableToolCallValidation && message.messages) {
|
|
62
|
+
for (let i = 0; i < message.messages.length; i++) {
|
|
63
|
+
const msg = message.messages[i];
|
|
64
|
+
if (msg.tool_calls) {
|
|
65
|
+
const toolValidation = this.validateToolCallsInMessage(msg.tool_calls, i);
|
|
66
|
+
errors.push(...toolValidation.errors);
|
|
67
|
+
warnings.push(...toolValidation.warnings);
|
|
68
|
+
fixes.push(...toolValidation.fixes);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
isValid: errors.length === 0,
|
|
74
|
+
errors,
|
|
75
|
+
warnings,
|
|
76
|
+
fixes
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
validateMessageStructure(message) {
|
|
80
|
+
const errors = [];
|
|
81
|
+
const warnings = [];
|
|
82
|
+
const fixes = [];
|
|
83
|
+
// Check if message exists
|
|
84
|
+
if (!message) {
|
|
85
|
+
errors.push('Message is null or undefined');
|
|
86
|
+
fixes.push('Provide a valid message object');
|
|
87
|
+
return { isValid: false, errors, warnings, fixes };
|
|
88
|
+
}
|
|
89
|
+
// Check if messages array exists
|
|
90
|
+
if (!message.messages) {
|
|
91
|
+
errors.push('Message object missing required "messages" array');
|
|
92
|
+
fixes.push('Add a "messages" array to the message object');
|
|
93
|
+
}
|
|
94
|
+
else if (!Array.isArray(message.messages)) {
|
|
95
|
+
errors.push('Messages field must be an array');
|
|
96
|
+
fixes.push('Convert messages field to an array');
|
|
97
|
+
}
|
|
98
|
+
else if (message.messages.length === 0) {
|
|
99
|
+
warnings.push('Messages array is empty');
|
|
100
|
+
}
|
|
101
|
+
// Check metadata structure
|
|
102
|
+
if (message.metadata && typeof message.metadata !== 'object') {
|
|
103
|
+
warnings.push('Metadata should be an object');
|
|
104
|
+
fixes.push('Convert metadata to an object or remove it');
|
|
105
|
+
}
|
|
106
|
+
return { isValid: errors.length === 0, errors, warnings, fixes };
|
|
107
|
+
}
|
|
108
|
+
validateMessageContent(msg, index) {
|
|
109
|
+
const errors = [];
|
|
110
|
+
const warnings = [];
|
|
111
|
+
const fixes = [];
|
|
112
|
+
// Check required fields
|
|
113
|
+
for (const field of this.requiredFields) {
|
|
114
|
+
if (!(field in msg)) {
|
|
115
|
+
errors.push(`Message at index ${index} missing required field: ${field}`);
|
|
116
|
+
fixes.push(`Add ${field} field to message at index ${index}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// Validate role
|
|
120
|
+
if (msg.role) {
|
|
121
|
+
const validRoles = ['user', 'assistant', 'system', 'tool'];
|
|
122
|
+
if (!validRoles.includes(msg.role)) {
|
|
123
|
+
errors.push(`Invalid role "${msg.role}" at index ${index}. Must be one of: ${validRoles.join(', ')}`);
|
|
124
|
+
fixes.push(`Change role to one of: ${validRoles.join(', ')}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// Validate content
|
|
128
|
+
if (msg.content !== undefined) {
|
|
129
|
+
if (typeof msg.content === 'string') {
|
|
130
|
+
// String content validation
|
|
131
|
+
if (!this.allowEmptyContent && msg.content.trim() === '') {
|
|
132
|
+
warnings.push(`Empty content in message at index ${index}`);
|
|
133
|
+
fixes.push('Provide meaningful content or remove the message');
|
|
134
|
+
}
|
|
135
|
+
if (msg.content.length > this.maxContentLength) {
|
|
136
|
+
warnings.push(`Content too long at index ${index}: ${msg.content.length} chars (max: ${this.maxContentLength})`);
|
|
137
|
+
fixes.push('Truncate or compress the content');
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
else if (Array.isArray(msg.content)) {
|
|
141
|
+
// Array content validation (for multimodal messages)
|
|
142
|
+
for (let partIndex = 0; partIndex < msg.content.length; partIndex++) {
|
|
143
|
+
const part = msg.content[partIndex];
|
|
144
|
+
if (!part || (typeof part !== 'object' && typeof part !== 'string')) {
|
|
145
|
+
errors.push(`Invalid content part at message ${index}, part ${partIndex}`);
|
|
146
|
+
fixes.push('Ensure all content parts are valid objects or strings');
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else if (typeof msg.content !== 'object') {
|
|
151
|
+
warnings.push(`Unexpected content type at index ${index}: ${typeof msg.content}`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// Validate name field
|
|
155
|
+
if (msg.name && typeof msg.name !== 'string') {
|
|
156
|
+
warnings.push(`Name field should be a string at index ${index}`);
|
|
157
|
+
fixes.push('Convert name field to string');
|
|
158
|
+
}
|
|
159
|
+
return { isValid: errors.length === 0, errors, warnings, fixes };
|
|
160
|
+
}
|
|
161
|
+
validateToolCallsInMessage(toolCalls, messageIndex) {
|
|
162
|
+
const errors = [];
|
|
163
|
+
const warnings = [];
|
|
164
|
+
const fixes = [];
|
|
165
|
+
if (!Array.isArray(toolCalls)) {
|
|
166
|
+
errors.push(`Tool calls must be an array at message index ${messageIndex}`);
|
|
167
|
+
fixes.push('Convert tool_calls to an array');
|
|
168
|
+
return { isValid: false, errors, warnings, fixes };
|
|
169
|
+
}
|
|
170
|
+
for (let i = 0; i < toolCalls.length; i++) {
|
|
171
|
+
const toolCall = toolCalls[i];
|
|
172
|
+
// Check required tool call fields
|
|
173
|
+
if (!toolCall.id) {
|
|
174
|
+
errors.push(`Tool call at message ${messageIndex}, call ${i} missing required "id" field`);
|
|
175
|
+
fixes.push('Add unique id to tool call');
|
|
176
|
+
}
|
|
177
|
+
if (!toolCall.function) {
|
|
178
|
+
errors.push(`Tool call at message ${messageIndex}, call ${i} missing required "function" field`);
|
|
179
|
+
fixes.push('Add function object to tool call');
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
// Validate function object
|
|
183
|
+
if (!toolCall.function.name) {
|
|
184
|
+
errors.push(`Tool call function at message ${messageIndex}, call ${i} missing "name" field`);
|
|
185
|
+
fixes.push('Add function name to tool call');
|
|
186
|
+
}
|
|
187
|
+
if (toolCall.function.arguments === undefined) {
|
|
188
|
+
warnings.push(`Tool call function at message ${messageIndex}, call ${i} missing "arguments" field`);
|
|
189
|
+
fixes.push('Add arguments field (can be empty object)');
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
// Validate arguments
|
|
193
|
+
if (typeof toolCall.function.arguments === 'string') {
|
|
194
|
+
try {
|
|
195
|
+
JSON.parse(toolCall.function.arguments);
|
|
196
|
+
}
|
|
197
|
+
catch (e) {
|
|
198
|
+
errors.push(`Invalid JSON in tool call arguments at message ${messageIndex}, call ${i}`);
|
|
199
|
+
fixes.push('Ensure arguments are valid JSON string or object');
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
else if (typeof toolCall.function.arguments !== 'object') {
|
|
203
|
+
warnings.push(`Tool call arguments should be object or JSON string at message ${messageIndex}, call ${i}`);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return { isValid: errors.length === 0, errors, warnings, fixes };
|
|
209
|
+
}
|
|
210
|
+
// Utility method to get validation summary
|
|
211
|
+
getValidationSummary(validationResult) {
|
|
212
|
+
const summary = [];
|
|
213
|
+
if (validationResult.isValid) {
|
|
214
|
+
summary.push('✅ Validation passed');
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
summary.push('❌ Validation failed');
|
|
218
|
+
}
|
|
219
|
+
if (validationResult.errors.length > 0) {
|
|
220
|
+
summary.push(`${validationResult.errors.length} error(s)`);
|
|
221
|
+
}
|
|
222
|
+
if (validationResult.warnings.length > 0) {
|
|
223
|
+
summary.push(`${validationResult.warnings.length} warning(s)`);
|
|
224
|
+
}
|
|
225
|
+
return summary.join(' - ');
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
exports.ResponseValidationProcessor = ResponseValidationProcessor;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { BaseProcessor, ProcessorInput, ProcessorOutput } from '../../processor';
|
|
2
|
+
export interface TelemetryProcessorOptions {
|
|
3
|
+
enablePerformanceTracking?: boolean;
|
|
4
|
+
enableErrorTracking?: boolean;
|
|
5
|
+
enableUsageTracking?: boolean;
|
|
6
|
+
enableTokenTracking?: boolean;
|
|
7
|
+
sampleRate?: number;
|
|
8
|
+
batchSize?: number;
|
|
9
|
+
flushInterval?: number;
|
|
10
|
+
enableLocalStorage?: boolean;
|
|
11
|
+
exportPath?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface PerformanceMetric {
|
|
14
|
+
operation: string;
|
|
15
|
+
startTime: number;
|
|
16
|
+
endTime: number;
|
|
17
|
+
duration: number;
|
|
18
|
+
success: boolean;
|
|
19
|
+
metadata?: Record<string, any>;
|
|
20
|
+
}
|
|
21
|
+
export interface ErrorMetric {
|
|
22
|
+
type: string;
|
|
23
|
+
message: string;
|
|
24
|
+
stack?: string;
|
|
25
|
+
timestamp: number;
|
|
26
|
+
context?: Record<string, any>;
|
|
27
|
+
}
|
|
28
|
+
export interface UsageMetric {
|
|
29
|
+
feature: string;
|
|
30
|
+
count: number;
|
|
31
|
+
timestamp: number;
|
|
32
|
+
userId?: string;
|
|
33
|
+
sessionId?: string;
|
|
34
|
+
}
|
|
35
|
+
export interface TokenMetric {
|
|
36
|
+
model: string;
|
|
37
|
+
inputTokens: number;
|
|
38
|
+
outputTokens: number;
|
|
39
|
+
cachedTokens: number;
|
|
40
|
+
totalTokens: number;
|
|
41
|
+
timestamp: number;
|
|
42
|
+
cost?: number;
|
|
43
|
+
}
|
|
44
|
+
export interface TelemetryData {
|
|
45
|
+
sessionId: string;
|
|
46
|
+
timestamp: number;
|
|
47
|
+
performance: PerformanceMetric[];
|
|
48
|
+
errors: ErrorMetric[];
|
|
49
|
+
usage: UsageMetric[];
|
|
50
|
+
tokens: TokenMetric[];
|
|
51
|
+
metadata: Record<string, any>;
|
|
52
|
+
}
|
|
53
|
+
export declare class TelemetryProcessor extends BaseProcessor {
|
|
54
|
+
private readonly enablePerformanceTracking;
|
|
55
|
+
private readonly enableErrorTracking;
|
|
56
|
+
private readonly enableUsageTracking;
|
|
57
|
+
private readonly enableTokenTracking;
|
|
58
|
+
private readonly sampleRate;
|
|
59
|
+
private readonly batchSize;
|
|
60
|
+
private readonly flushInterval;
|
|
61
|
+
private readonly enableLocalStorage;
|
|
62
|
+
private readonly exportPath;
|
|
63
|
+
private performanceMetrics;
|
|
64
|
+
private errorMetrics;
|
|
65
|
+
private usageMetrics;
|
|
66
|
+
private tokenMetrics;
|
|
67
|
+
private sessionId;
|
|
68
|
+
private startTime;
|
|
69
|
+
private operationTimers;
|
|
70
|
+
private flushTimer?;
|
|
71
|
+
constructor(options?: TelemetryProcessorOptions);
|
|
72
|
+
processInput(input: ProcessorInput): Promise<ProcessorOutput[]>;
|
|
73
|
+
startOperation(operation: string): void;
|
|
74
|
+
endOperation(operation: string, success: boolean, metadata?: Record<string, any>): void;
|
|
75
|
+
trackError(type: string, message: string, stack?: string, context?: Record<string, any>): void;
|
|
76
|
+
trackUsage(feature: string, userId?: string, sessionId?: string): void;
|
|
77
|
+
trackTokens(model: string, inputTokens: number, outputTokens: number, cachedTokens?: number, cost?: number): void;
|
|
78
|
+
flushMetrics(): Promise<void>;
|
|
79
|
+
private saveToFile;
|
|
80
|
+
private clearMetrics;
|
|
81
|
+
private getTotalMetricsCount;
|
|
82
|
+
private generateSessionId;
|
|
83
|
+
getMetricsSummary(): {
|
|
84
|
+
sessionId: string;
|
|
85
|
+
sessionDuration: number;
|
|
86
|
+
performance: number;
|
|
87
|
+
errors: number;
|
|
88
|
+
usage: number;
|
|
89
|
+
tokens: number;
|
|
90
|
+
total: number;
|
|
91
|
+
};
|
|
92
|
+
getPerformanceStats(): {
|
|
93
|
+
averageDuration: number;
|
|
94
|
+
successRate: number;
|
|
95
|
+
slowestOperation: PerformanceMetric | null;
|
|
96
|
+
fastestOperation: PerformanceMetric | null;
|
|
97
|
+
};
|
|
98
|
+
destroy(): Promise<void>;
|
|
99
|
+
}
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.TelemetryProcessor = void 0;
|
|
37
|
+
const processor_1 = require("../../processor");
|
|
38
|
+
class TelemetryProcessor extends processor_1.BaseProcessor {
|
|
39
|
+
constructor(options = {}) {
|
|
40
|
+
super();
|
|
41
|
+
// Metrics storage
|
|
42
|
+
this.performanceMetrics = [];
|
|
43
|
+
this.errorMetrics = [];
|
|
44
|
+
this.usageMetrics = [];
|
|
45
|
+
this.tokenMetrics = [];
|
|
46
|
+
this.operationTimers = new Map();
|
|
47
|
+
this.enablePerformanceTracking = options.enablePerformanceTracking !== false;
|
|
48
|
+
this.enableErrorTracking = options.enableErrorTracking !== false;
|
|
49
|
+
this.enableUsageTracking = options.enableUsageTracking !== false;
|
|
50
|
+
this.enableTokenTracking = options.enableTokenTracking !== false;
|
|
51
|
+
this.sampleRate = options.sampleRate || 1.0;
|
|
52
|
+
this.batchSize = options.batchSize || 100;
|
|
53
|
+
this.flushInterval = options.flushInterval || 60000; // 1 minute
|
|
54
|
+
this.enableLocalStorage = options.enableLocalStorage !== false;
|
|
55
|
+
this.exportPath = options.exportPath || './telemetry';
|
|
56
|
+
this.sessionId = this.generateSessionId();
|
|
57
|
+
this.startTime = Date.now();
|
|
58
|
+
// Setup periodic flush
|
|
59
|
+
if (this.flushInterval > 0) {
|
|
60
|
+
this.flushTimer = setInterval(() => {
|
|
61
|
+
this.flushMetrics().catch(console.error);
|
|
62
|
+
}, this.flushInterval);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async processInput(input) {
|
|
66
|
+
var _a;
|
|
67
|
+
const { message, context } = input;
|
|
68
|
+
// Sample based on rate
|
|
69
|
+
if (Math.random() > this.sampleRate) {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
const results = [];
|
|
73
|
+
try {
|
|
74
|
+
// Track processing performance
|
|
75
|
+
if (this.enablePerformanceTracking) {
|
|
76
|
+
this.startOperation('message_processing');
|
|
77
|
+
}
|
|
78
|
+
// Track usage
|
|
79
|
+
if (this.enableUsageTracking) {
|
|
80
|
+
this.trackUsage('message_processed', context === null || context === void 0 ? void 0 : context.userId, this.sessionId);
|
|
81
|
+
}
|
|
82
|
+
// Track token usage if available
|
|
83
|
+
if (this.enableTokenTracking && (context === null || context === void 0 ? void 0 : context.tokenUsage)) {
|
|
84
|
+
this.trackTokens(((_a = context.llmconfig) === null || _a === void 0 ? void 0 : _a.model) || 'unknown', context.tokenUsage.input || 0, context.tokenUsage.output || 0, context.tokenUsage.cached || 0, context.tokenUsage.cost);
|
|
85
|
+
}
|
|
86
|
+
// Track tool usage
|
|
87
|
+
if (this.enableUsageTracking && message.messages) {
|
|
88
|
+
for (const msg of message.messages) {
|
|
89
|
+
if (msg.tool_calls && msg.tool_calls.length > 0) {
|
|
90
|
+
for (const toolCall of msg.tool_calls) {
|
|
91
|
+
this.trackUsage(`tool_${toolCall.function.name}`, context === null || context === void 0 ? void 0 : context.userId, this.sessionId);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
results.push(this.createEvent('TelemetryRecorded', {
|
|
97
|
+
sessionId: this.sessionId,
|
|
98
|
+
metricsCount: this.getTotalMetricsCount()
|
|
99
|
+
}));
|
|
100
|
+
// Check if we need to flush
|
|
101
|
+
if (this.getTotalMetricsCount() >= this.batchSize) {
|
|
102
|
+
await this.flushMetrics();
|
|
103
|
+
results.push(this.createEvent('TelemetryFlushed', {
|
|
104
|
+
sessionId: this.sessionId,
|
|
105
|
+
reason: 'batch_size_reached'
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
if (this.enableErrorTracking) {
|
|
111
|
+
this.trackError('telemetry_processing_error', error instanceof Error ? error.message : String(error), error instanceof Error ? error.stack : undefined, { messageType: typeof message, contextKeys: context ? Object.keys(context) : [] });
|
|
112
|
+
}
|
|
113
|
+
results.push(this.createEvent('TelemetryError', {
|
|
114
|
+
error: error instanceof Error ? error.message : String(error)
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
117
|
+
finally {
|
|
118
|
+
if (this.enablePerformanceTracking) {
|
|
119
|
+
this.endOperation('message_processing', true);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return results;
|
|
123
|
+
}
|
|
124
|
+
// Performance tracking methods
|
|
125
|
+
startOperation(operation) {
|
|
126
|
+
if (!this.enablePerformanceTracking)
|
|
127
|
+
return;
|
|
128
|
+
this.operationTimers.set(operation, Date.now());
|
|
129
|
+
}
|
|
130
|
+
endOperation(operation, success, metadata) {
|
|
131
|
+
if (!this.enablePerformanceTracking)
|
|
132
|
+
return;
|
|
133
|
+
const startTime = this.operationTimers.get(operation);
|
|
134
|
+
if (startTime === undefined)
|
|
135
|
+
return;
|
|
136
|
+
const endTime = Date.now();
|
|
137
|
+
const duration = endTime - startTime;
|
|
138
|
+
this.performanceMetrics.push({
|
|
139
|
+
operation,
|
|
140
|
+
startTime,
|
|
141
|
+
endTime,
|
|
142
|
+
duration,
|
|
143
|
+
success,
|
|
144
|
+
metadata
|
|
145
|
+
});
|
|
146
|
+
this.operationTimers.delete(operation);
|
|
147
|
+
}
|
|
148
|
+
// Error tracking methods
|
|
149
|
+
trackError(type, message, stack, context) {
|
|
150
|
+
if (!this.enableErrorTracking)
|
|
151
|
+
return;
|
|
152
|
+
this.errorMetrics.push({
|
|
153
|
+
type,
|
|
154
|
+
message,
|
|
155
|
+
stack,
|
|
156
|
+
timestamp: Date.now(),
|
|
157
|
+
context
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
// Usage tracking methods
|
|
161
|
+
trackUsage(feature, userId, sessionId) {
|
|
162
|
+
if (!this.enableUsageTracking)
|
|
163
|
+
return;
|
|
164
|
+
// Check if we already have a metric for this feature in the current batch
|
|
165
|
+
const existingMetric = this.usageMetrics.find(m => m.feature === feature &&
|
|
166
|
+
m.userId === userId &&
|
|
167
|
+
m.sessionId === sessionId &&
|
|
168
|
+
Date.now() - m.timestamp < 60000 // Within last minute
|
|
169
|
+
);
|
|
170
|
+
if (existingMetric) {
|
|
171
|
+
existingMetric.count++;
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
this.usageMetrics.push({
|
|
175
|
+
feature,
|
|
176
|
+
count: 1,
|
|
177
|
+
timestamp: Date.now(),
|
|
178
|
+
userId,
|
|
179
|
+
sessionId: sessionId || this.sessionId
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
// Token tracking methods
|
|
184
|
+
trackTokens(model, inputTokens, outputTokens, cachedTokens = 0, cost) {
|
|
185
|
+
if (!this.enableTokenTracking)
|
|
186
|
+
return;
|
|
187
|
+
this.tokenMetrics.push({
|
|
188
|
+
model,
|
|
189
|
+
inputTokens,
|
|
190
|
+
outputTokens,
|
|
191
|
+
cachedTokens,
|
|
192
|
+
totalTokens: inputTokens + outputTokens + cachedTokens,
|
|
193
|
+
timestamp: Date.now(),
|
|
194
|
+
cost
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
// Flush methods
|
|
198
|
+
async flushMetrics() {
|
|
199
|
+
if (!this.enableLocalStorage)
|
|
200
|
+
return;
|
|
201
|
+
const telemetryData = {
|
|
202
|
+
sessionId: this.sessionId,
|
|
203
|
+
timestamp: Date.now(),
|
|
204
|
+
performance: [...this.performanceMetrics],
|
|
205
|
+
errors: [...this.errorMetrics],
|
|
206
|
+
usage: [...this.usageMetrics],
|
|
207
|
+
tokens: [...this.tokenMetrics],
|
|
208
|
+
metadata: {
|
|
209
|
+
sessionStartTime: this.startTime,
|
|
210
|
+
flushTime: Date.now(),
|
|
211
|
+
totalOperationsTracked: this.performanceMetrics.length,
|
|
212
|
+
totalErrorsTracked: this.errorMetrics.length,
|
|
213
|
+
totalUsageEvents: this.usageMetrics.length,
|
|
214
|
+
totalTokenEvents: this.tokenMetrics.length
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
try {
|
|
218
|
+
// In a real implementation, you would send this to a telemetry service
|
|
219
|
+
// For now, we'll just log it and optionally save to file
|
|
220
|
+
console.log('[Telemetry] Flushing metrics:', {
|
|
221
|
+
sessionId: this.sessionId,
|
|
222
|
+
metricsCount: this.getTotalMetricsCount()
|
|
223
|
+
});
|
|
224
|
+
if (this.enableLocalStorage) {
|
|
225
|
+
await this.saveToFile(telemetryData);
|
|
226
|
+
}
|
|
227
|
+
// Clear metrics after successful flush
|
|
228
|
+
this.clearMetrics();
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
console.error('[Telemetry] Error flushing metrics:', error);
|
|
232
|
+
throw error;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
async saveToFile(data) {
|
|
236
|
+
try {
|
|
237
|
+
const fs = await Promise.resolve().then(() => __importStar(require('fs/promises')));
|
|
238
|
+
const path = await Promise.resolve().then(() => __importStar(require('path')));
|
|
239
|
+
// Ensure directory exists
|
|
240
|
+
try {
|
|
241
|
+
await fs.access(this.exportPath);
|
|
242
|
+
}
|
|
243
|
+
catch {
|
|
244
|
+
await fs.mkdir(this.exportPath, { recursive: true });
|
|
245
|
+
}
|
|
246
|
+
const filename = `telemetry-${this.sessionId}-${Date.now()}.json`;
|
|
247
|
+
const filepath = path.join(this.exportPath, filename);
|
|
248
|
+
await fs.writeFile(filepath, JSON.stringify(data, null, 2), 'utf-8');
|
|
249
|
+
}
|
|
250
|
+
catch (error) {
|
|
251
|
+
console.error('[Telemetry] Error saving to file:', error);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
clearMetrics() {
|
|
255
|
+
this.performanceMetrics = [];
|
|
256
|
+
this.errorMetrics = [];
|
|
257
|
+
this.usageMetrics = [];
|
|
258
|
+
this.tokenMetrics = [];
|
|
259
|
+
}
|
|
260
|
+
getTotalMetricsCount() {
|
|
261
|
+
return this.performanceMetrics.length +
|
|
262
|
+
this.errorMetrics.length +
|
|
263
|
+
this.usageMetrics.length +
|
|
264
|
+
this.tokenMetrics.length;
|
|
265
|
+
}
|
|
266
|
+
generateSessionId() {
|
|
267
|
+
return `telemetry-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
268
|
+
}
|
|
269
|
+
// Public methods for getting metrics
|
|
270
|
+
getMetricsSummary() {
|
|
271
|
+
return {
|
|
272
|
+
sessionId: this.sessionId,
|
|
273
|
+
sessionDuration: Date.now() - this.startTime,
|
|
274
|
+
performance: this.performanceMetrics.length,
|
|
275
|
+
errors: this.errorMetrics.length,
|
|
276
|
+
usage: this.usageMetrics.length,
|
|
277
|
+
tokens: this.tokenMetrics.length,
|
|
278
|
+
total: this.getTotalMetricsCount()
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
getPerformanceStats() {
|
|
282
|
+
if (this.performanceMetrics.length === 0) {
|
|
283
|
+
return {
|
|
284
|
+
averageDuration: 0,
|
|
285
|
+
successRate: 0,
|
|
286
|
+
slowestOperation: null,
|
|
287
|
+
fastestOperation: null
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
const totalDuration = this.performanceMetrics.reduce((sum, m) => sum + m.duration, 0);
|
|
291
|
+
const successCount = this.performanceMetrics.filter(m => m.success).length;
|
|
292
|
+
const sortedByDuration = [...this.performanceMetrics].sort((a, b) => a.duration - b.duration);
|
|
293
|
+
return {
|
|
294
|
+
averageDuration: totalDuration / this.performanceMetrics.length,
|
|
295
|
+
successRate: successCount / this.performanceMetrics.length,
|
|
296
|
+
slowestOperation: sortedByDuration[sortedByDuration.length - 1] || null,
|
|
297
|
+
fastestOperation: sortedByDuration[0] || null
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
// Cleanup
|
|
301
|
+
async destroy() {
|
|
302
|
+
if (this.flushTimer) {
|
|
303
|
+
clearInterval(this.flushTimer);
|
|
304
|
+
}
|
|
305
|
+
// Final flush
|
|
306
|
+
if (this.getTotalMetricsCount() > 0) {
|
|
307
|
+
await this.flushMetrics();
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
exports.TelemetryProcessor = TelemetryProcessor;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { BaseProcessor, ProcessorInput, ProcessorOutput } from '../../processor';
|
|
2
|
+
export interface TokenManagementProcessorOptions {
|
|
3
|
+
maxTokens?: number;
|
|
4
|
+
warningThreshold?: number;
|
|
5
|
+
enableCompression?: boolean;
|
|
6
|
+
compressionThreshold?: number;
|
|
7
|
+
enableCaching?: boolean;
|
|
8
|
+
modelTokenLimits?: Record<string, number>;
|
|
9
|
+
}
|
|
10
|
+
export interface TokenUsage {
|
|
11
|
+
input: number;
|
|
12
|
+
output: number;
|
|
13
|
+
cached: number;
|
|
14
|
+
total: number;
|
|
15
|
+
estimated?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare class TokenManagementProcessor extends BaseProcessor {
|
|
18
|
+
private readonly maxTokens;
|
|
19
|
+
private readonly warningThreshold;
|
|
20
|
+
private readonly enableCompression;
|
|
21
|
+
private readonly compressionThreshold;
|
|
22
|
+
private readonly enableCaching;
|
|
23
|
+
private readonly modelTokenLimits;
|
|
24
|
+
private tokenCache;
|
|
25
|
+
constructor(options?: TokenManagementProcessorOptions);
|
|
26
|
+
processInput(input: ProcessorInput): Promise<ProcessorOutput[]>;
|
|
27
|
+
private calculateTokenUsage;
|
|
28
|
+
private extractTextFromMessage;
|
|
29
|
+
private estimateTokens;
|
|
30
|
+
private getCacheKey;
|
|
31
|
+
getTokenUsageStats(): {
|
|
32
|
+
cacheSize: number;
|
|
33
|
+
cacheHitRate: number;
|
|
34
|
+
averageTokensPerMessage: number;
|
|
35
|
+
};
|
|
36
|
+
clearCache(): void;
|
|
37
|
+
}
|