@codebolt/agent 5.0.2 → 5.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent.d.ts +86 -0
- package/dist/agent.js +324 -0
- package/dist/builderpattern/agent.js +2 -2
- package/dist/builderpattern/followupquestionbuilder.js +1 -1
- package/dist/builderpattern/llmoutputhandler.js +7 -7
- package/dist/builderpattern/usermessage.d.ts +1 -6
- package/dist/composablepattern/document.js +35 -2
- package/dist/followupquestionbuilder.d.ts +75 -0
- package/dist/followupquestionbuilder.js +197 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +23 -0
- package/dist/llmoutputhandler.d.ts +102 -0
- package/dist/llmoutputhandler.js +452 -0
- package/dist/processor/types/interfaces.d.ts +21 -44
- package/dist/processor-pieces/index.d.ts +3 -0
- package/dist/processor-pieces/index.js +3 -0
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.d.ts +5 -14
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.js +40 -41
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.d.ts +13 -5
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.js +58 -50
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.d.ts +8 -6
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.js +22 -66
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.d.ts +2 -3
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.js +2 -1
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.d.ts +2 -3
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.js +2 -1
- package/dist/processor-pieces/messageModifiers/toolInjectionModifier.js +4 -1
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.d.ts +2 -18
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.js +93 -291
- package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.d.ts +18 -0
- package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.js +41 -0
- package/dist/processor-pieces/postToolCallProcessors/index.d.ts +2 -1
- package/dist/processor-pieces/postToolCallProcessors/index.js +5 -0
- package/dist/processor-pieces/preInferenceProcessors/index.d.ts +1 -1
- package/dist/processor-pieces/preInferenceProcessors/index.js +3 -0
- package/dist/processor-pieces/pretoolCallProcessors/index.d.ts +2 -1
- package/dist/processor-pieces/pretoolCallProcessors/index.js +5 -0
- package/dist/processor-pieces/pretoolCallProcessors/toolParameterModifier.d.ts +21 -0
- package/dist/processor-pieces/pretoolCallProcessors/toolParameterModifier.js +32 -0
- package/dist/processor-pieces/pretoolCallProcessors/toolValidationModifier.d.ts +16 -0
- package/dist/processor-pieces/pretoolCallProcessors/toolValidationModifier.js +37 -0
- package/dist/promptbuilder.d.ts +382 -0
- package/dist/promptbuilder.js +805 -0
- package/dist/systemprompt.d.ts +20 -0
- package/dist/systemprompt.js +48 -0
- package/dist/taskInstruction.d.ts +37 -0
- package/dist/taskInstruction.js +57 -0
- package/dist/types/libFunctionTypes.d.ts +13 -19
- package/dist/types/libFunctionTypes.js +3 -0
- package/dist/types/processorTypes.d.ts +8 -8
- package/dist/types/processorTypes.js +6 -23
- package/dist/unified/agent/agent.js +2 -2
- package/dist/unified/agent/codeboltAgent.d.ts +122 -0
- package/dist/unified/agent/codeboltAgent.js +210 -0
- package/dist/unified/base/initialPromptGenerator.js +18 -4
- package/dist/unified/base/responseExecutor.d.ts +3 -2
- package/dist/unified/base/responseExecutor.js +109 -56
- package/dist/unified/index.d.ts +4 -0
- package/dist/unified/index.js +12 -1
- package/dist/usermessage.d.ts +70 -0
- package/dist/usermessage.js +123 -0
- package/package.json +11 -6
- package/dist/local-tools/fileTools.d.ts +0 -26
- package/dist/local-tools/fileTools.js +0 -162
- package/dist/processor-pieces/additionalModifiers/argumentProcessorModifier.d.ts +0 -13
- package/dist/processor-pieces/additionalModifiers/argumentProcessorModifier.js +0 -68
- package/dist/processor-pieces/additionalModifiers/atFileProcessorModifier.d.ts +0 -15
- package/dist/processor-pieces/additionalModifiers/atFileProcessorModifier.js +0 -212
- package/dist/processor-pieces/additionalModifiers/chatCompressionModifier.d.ts +0 -19
- package/dist/processor-pieces/additionalModifiers/chatCompressionModifier.js +0 -110
- package/dist/processor-pieces/additionalModifiers/chatRecordingModifier.d.ts +0 -23
- package/dist/processor-pieces/additionalModifiers/chatRecordingModifier.js +0 -173
- package/dist/processor-pieces/additionalModifiers/coreSystemPromptModifier.d.ts +0 -14
- package/dist/processor-pieces/additionalModifiers/coreSystemPromptModifier.js +0 -93
- package/dist/processor-pieces/additionalModifiers/directoryContextModifier.d.ts +0 -30
- package/dist/processor-pieces/additionalModifiers/directoryContextModifier.js +0 -330
- package/dist/processor-pieces/additionalModifiers/environmentContextModifier.d.ts +0 -26
- package/dist/processor-pieces/additionalModifiers/environmentContextModifier.js +0 -269
- package/dist/processor-pieces/additionalModifiers/fallbackHandlerModifier.d.ts +0 -38
- package/dist/processor-pieces/additionalModifiers/fallbackHandlerModifier.js +0 -217
- package/dist/processor-pieces/additionalModifiers/ideContextModifier.d.ts +0 -34
- package/dist/processor-pieces/additionalModifiers/ideContextModifier.js +0 -147
- package/dist/processor-pieces/additionalModifiers/index.d.ts +0 -12
- package/dist/processor-pieces/additionalModifiers/index.js +0 -28
- package/dist/processor-pieces/additionalModifiers/loopDetectionModifier.d.ts +0 -29
- package/dist/processor-pieces/additionalModifiers/loopDetectionModifier.js +0 -155
- package/dist/processor-pieces/additionalModifiers/memoryImportModifier.d.ts +0 -15
- package/dist/processor-pieces/additionalModifiers/memoryImportModifier.js +0 -129
- package/dist/processor-pieces/additionalModifiers/shellProcessorModifier.d.ts +0 -25
- package/dist/processor-pieces/additionalModifiers/shellProcessorModifier.js +0 -169
- package/dist/processor-pieces/additionalModifiers/toolInjectionModifier.d.ts +0 -20
- package/dist/processor-pieces/additionalModifiers/toolInjectionModifier.js +0 -152
- package/dist/processor-pieces/messageModifiers/addCurrentDirectoryRootFilesModifier.d.ts +0 -7
- package/dist/processor-pieces/messageModifiers/addCurrentDirectoryRootFilesModifier.js +0 -93
- package/dist/processor-pieces/messageModifiers/advancedSystemInstructionMessageModifier.d.ts +0 -9
- package/dist/processor-pieces/messageModifiers/advancedSystemInstructionMessageModifier.js +0 -77
- package/dist/processor-pieces/messageModifiers/chatCompressionModifier.d.ts +0 -19
- package/dist/processor-pieces/messageModifiers/chatCompressionModifier.js +0 -110
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.example.d.ts +0 -20
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.example.js +0 -124
- package/dist/processor-pieces/messageModifiers/environmentContext.d.ts +0 -41
- package/dist/processor-pieces/messageModifiers/environmentContext.js +0 -355
- package/dist/processor-pieces/messageModifiers/mentionedFilesModifier.d.ts +0 -23
- package/dist/processor-pieces/messageModifiers/mentionedFilesModifier.js +0 -207
- package/dist/processor-pieces/messageModifiers/simpleMessageModifier.d.ts +0 -7
- package/dist/processor-pieces/messageModifiers/simpleMessageModifier.js +0 -26
- package/dist/processor-pieces/postInference/llmOutputValidityProcessor.d.ts +0 -1
- package/dist/processor-pieces/postInference/llmOutputValidityProcessor.js +0 -2
- package/dist/processor-pieces/postInferenceProcessors/checkForNoToolCall.d.ts +0 -7
- package/dist/processor-pieces/postInferenceProcessors/checkForNoToolCall.js +0 -24
- package/dist/processor-pieces/postToolCall/advancedLoopDetectionProcessor.d.ts +0 -41
- package/dist/processor-pieces/postToolCall/advancedLoopDetectionProcessor.js +0 -197
- package/dist/processor-pieces/postToolCall/chatCompressionProcessor.d.ts +0 -26
- package/dist/processor-pieces/postToolCall/chatCompressionProcessor.js +0 -90
- package/dist/processor-pieces/postToolCall/chatRecordingProcessor.d.ts +0 -81
- package/dist/processor-pieces/postToolCall/chatRecordingProcessor.js +0 -329
- package/dist/processor-pieces/postToolCall/contextManagementProcessor.d.ts +0 -40
- package/dist/processor-pieces/postToolCall/contextManagementProcessor.js +0 -272
- package/dist/processor-pieces/postToolCall/conversationCompactorProcessor.d.ts +0 -49
- package/dist/processor-pieces/postToolCall/conversationCompactorProcessor.js +0 -291
- package/dist/processor-pieces/postToolCall/conversationContinuityProcessor.d.ts +0 -49
- package/dist/processor-pieces/postToolCall/conversationContinuityProcessor.js +0 -293
- package/dist/processor-pieces/postToolCall/followUpConversationProcessor.d.ts +0 -47
- package/dist/processor-pieces/postToolCall/followUpConversationProcessor.js +0 -249
- package/dist/processor-pieces/postToolCall/loopDetectionProcessor.d.ts +0 -30
- package/dist/processor-pieces/postToolCall/loopDetectionProcessor.js +0 -137
- package/dist/processor-pieces/postToolCall/responseValidationProcessor.d.ts +0 -30
- package/dist/processor-pieces/postToolCall/responseValidationProcessor.js +0 -228
- package/dist/processor-pieces/postToolCall/telemetryProcessor.d.ts +0 -99
- package/dist/processor-pieces/postToolCall/telemetryProcessor.js +0 -278
- package/dist/processor-pieces/postToolCall/tokenManagementProcessor.d.ts +0 -37
- package/dist/processor-pieces/postToolCall/tokenManagementProcessor.js +0 -178
- package/dist/processor-pieces/postToolCall/toolExecutionProcessor.d.ts +0 -43
- package/dist/processor-pieces/postToolCall/toolExecutionProcessor.js +0 -207
- package/dist/processor-pieces/preInference/conversationCompactorProcessor.d.ts +0 -52
- package/dist/processor-pieces/preInference/conversationCompactorProcessor.js +0 -264
- package/dist/processor-pieces/preInference/conversationContinuityProcessor.d.ts +0 -49
- package/dist/processor-pieces/preInference/conversationContinuityProcessor.js +0 -293
- package/dist/processor-pieces/preInferenceProcessors/conversationCompaction.d.ts +0 -7
- package/dist/processor-pieces/preInferenceProcessors/conversationCompaction.js +0 -31
- package/dist/processor-pieces/preToolCall/index.d.ts +0 -9
- package/dist/processor-pieces/preToolCall/index.js +0 -18
- package/dist/processor-pieces/preToolCall/localToolInterceptorProcessor.d.ts +0 -58
- package/dist/processor-pieces/preToolCall/localToolInterceptorProcessor.js +0 -444
- package/dist/processor-pieces/preToolCall/toolParameterModifierProcessor.d.ts +0 -44
- package/dist/processor-pieces/preToolCall/toolParameterModifierProcessor.js +0 -367
- package/dist/processor-pieces/preToolCall/toolValidationProcessor.d.ts +0 -58
- package/dist/processor-pieces/preToolCall/toolValidationProcessor.js +0 -391
- package/dist/unified/agent/tool.d.ts +0 -99
- package/dist/unified/agent/tool.js +0 -440
- package/dist/unified/examples/agentExample.d.ts +0 -46
- package/dist/unified/examples/agentExample.js +0 -464
- package/dist/unified/examples/documentationPatternExample.d.ts +0 -10
- package/dist/unified/examples/documentationPatternExample.js +0 -385
- package/dist/unified/examples/followUpProcessorsExample.d.ts +0 -45
- package/dist/unified/examples/followUpProcessorsExample.js +0 -311
- package/dist/unified/examples/orchestratorExample.d.ts +0 -16
- package/dist/unified/examples/orchestratorExample.js +0 -415
- package/dist/unified/examples/preToolCallProcessorsExample.d.ts +0 -36
- package/dist/unified/examples/preToolCallProcessorsExample.js +0 -458
- package/dist/unified/examples/workflowExample.d.ts +0 -12
- package/dist/unified/examples/workflowExample.js +0 -497
- package/dist/unified/orchestrator/orchestrator.d.ts +0 -260
- package/dist/unified/orchestrator/orchestrator.js +0 -519
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { BaseProcessor, ProcessorInput, ProcessorOutput } from '../../processor';
|
|
2
|
-
export interface ChatRecordingProcessorOptions {
|
|
3
|
-
enableTokenTracking?: boolean;
|
|
4
|
-
exportFormat?: 'json' | 'txt' | 'csv';
|
|
5
|
-
outputDirectory?: string;
|
|
6
|
-
maxFileSize?: number;
|
|
7
|
-
enableCompression?: boolean;
|
|
8
|
-
includeMetadata?: boolean;
|
|
9
|
-
autoExport?: boolean;
|
|
10
|
-
exportInterval?: number;
|
|
11
|
-
}
|
|
12
|
-
export interface TokensSummary {
|
|
13
|
-
input: number;
|
|
14
|
-
output: number;
|
|
15
|
-
cached: number;
|
|
16
|
-
thoughts?: number;
|
|
17
|
-
tool?: number;
|
|
18
|
-
total: number;
|
|
19
|
-
}
|
|
20
|
-
export interface MessageRecord {
|
|
21
|
-
id: string;
|
|
22
|
-
timestamp: string;
|
|
23
|
-
role: string;
|
|
24
|
-
content: string;
|
|
25
|
-
metadata?: Record<string, any>;
|
|
26
|
-
tokens?: TokensSummary;
|
|
27
|
-
toolCalls?: ToolCallRecord[];
|
|
28
|
-
}
|
|
29
|
-
export interface ToolCallRecord {
|
|
30
|
-
id: string;
|
|
31
|
-
name: string;
|
|
32
|
-
args: Record<string, unknown>;
|
|
33
|
-
result?: any;
|
|
34
|
-
status: 'pending' | 'success' | 'error' | 'cancelled';
|
|
35
|
-
timestamp: string;
|
|
36
|
-
executionTime?: number;
|
|
37
|
-
}
|
|
38
|
-
export interface ConversationSession {
|
|
39
|
-
sessionId: string;
|
|
40
|
-
startTime: string;
|
|
41
|
-
endTime?: string;
|
|
42
|
-
messages: MessageRecord[];
|
|
43
|
-
totalTokens: TokensSummary;
|
|
44
|
-
toolCallCount: number;
|
|
45
|
-
metadata: Record<string, any>;
|
|
46
|
-
}
|
|
47
|
-
export declare class ChatRecordingProcessor extends BaseProcessor {
|
|
48
|
-
private readonly enableTokenTracking;
|
|
49
|
-
private readonly exportFormat;
|
|
50
|
-
private readonly outputDirectory;
|
|
51
|
-
private readonly maxFileSize;
|
|
52
|
-
private readonly enableCompression;
|
|
53
|
-
private readonly includeMetadata;
|
|
54
|
-
private readonly autoExport;
|
|
55
|
-
private readonly exportInterval;
|
|
56
|
-
private currentSession;
|
|
57
|
-
private messageCount;
|
|
58
|
-
private sessions;
|
|
59
|
-
constructor(options?: ChatRecordingProcessorOptions);
|
|
60
|
-
processInput(input: ProcessorInput): Promise<ProcessorOutput[]>;
|
|
61
|
-
private initializeSession;
|
|
62
|
-
private createMessageRecord;
|
|
63
|
-
private extractContent;
|
|
64
|
-
private extractToolCalls;
|
|
65
|
-
private estimateTokens;
|
|
66
|
-
private updateSessionTotals;
|
|
67
|
-
private generateSessionId;
|
|
68
|
-
private generateMessageId;
|
|
69
|
-
private generateToolCallId;
|
|
70
|
-
exportSession(session: ConversationSession): Promise<string>;
|
|
71
|
-
private ensureDirectoryExists;
|
|
72
|
-
private formatAsText;
|
|
73
|
-
private formatAsCSV;
|
|
74
|
-
finalizeSession(): Promise<string | null>;
|
|
75
|
-
getCurrentSession(): ConversationSession | null;
|
|
76
|
-
getSessionStats(): {
|
|
77
|
-
currentSessionMessages: number;
|
|
78
|
-
totalSessions: number;
|
|
79
|
-
totalMessages: number;
|
|
80
|
-
};
|
|
81
|
-
}
|
|
@@ -1,329 +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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.ChatRecordingProcessor = void 0;
|
|
37
|
-
const processor_1 = require("../../processor");
|
|
38
|
-
const fs = __importStar(require("fs/promises"));
|
|
39
|
-
const path = __importStar(require("path"));
|
|
40
|
-
class ChatRecordingProcessor extends processor_1.BaseProcessor {
|
|
41
|
-
constructor(options = {}) {
|
|
42
|
-
super();
|
|
43
|
-
// Session tracking
|
|
44
|
-
this.currentSession = null;
|
|
45
|
-
this.messageCount = 0;
|
|
46
|
-
this.sessions = [];
|
|
47
|
-
this.enableTokenTracking = options.enableTokenTracking !== false;
|
|
48
|
-
this.exportFormat = options.exportFormat || 'json';
|
|
49
|
-
this.outputDirectory = options.outputDirectory || './chat-recordings';
|
|
50
|
-
this.maxFileSize = options.maxFileSize || 10 * 1024 * 1024; // 10MB
|
|
51
|
-
this.enableCompression = options.enableCompression || false;
|
|
52
|
-
this.includeMetadata = options.includeMetadata !== false;
|
|
53
|
-
this.autoExport = options.autoExport || false;
|
|
54
|
-
this.exportInterval = options.exportInterval || 50;
|
|
55
|
-
}
|
|
56
|
-
async processInput(input) {
|
|
57
|
-
const { message, context } = input;
|
|
58
|
-
try {
|
|
59
|
-
// Initialize session if not exists
|
|
60
|
-
if (!this.currentSession) {
|
|
61
|
-
this.initializeSession(context);
|
|
62
|
-
}
|
|
63
|
-
// Record the message
|
|
64
|
-
const messageRecord = this.createMessageRecord(message, context);
|
|
65
|
-
this.currentSession.messages.push(messageRecord);
|
|
66
|
-
this.messageCount++;
|
|
67
|
-
// Update session totals
|
|
68
|
-
this.updateSessionTotals(messageRecord);
|
|
69
|
-
const results = [
|
|
70
|
-
this.createEvent('MessageRecorded', {
|
|
71
|
-
messageId: messageRecord.id,
|
|
72
|
-
sessionId: this.currentSession.sessionId,
|
|
73
|
-
messageCount: this.messageCount
|
|
74
|
-
})
|
|
75
|
-
];
|
|
76
|
-
// Auto-export if enabled and interval reached
|
|
77
|
-
if (this.autoExport && this.messageCount % this.exportInterval === 0) {
|
|
78
|
-
try {
|
|
79
|
-
const exportPath = await this.exportSession(this.currentSession);
|
|
80
|
-
results.push(this.createEvent('SessionExported', {
|
|
81
|
-
sessionId: this.currentSession.sessionId,
|
|
82
|
-
exportPath,
|
|
83
|
-
messageCount: this.currentSession.messages.length
|
|
84
|
-
}));
|
|
85
|
-
}
|
|
86
|
-
catch (exportError) {
|
|
87
|
-
results.push(this.createEvent('ExportError', {
|
|
88
|
-
error: exportError instanceof Error ? exportError.message : String(exportError),
|
|
89
|
-
sessionId: this.currentSession.sessionId
|
|
90
|
-
}));
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return results;
|
|
94
|
-
}
|
|
95
|
-
catch (error) {
|
|
96
|
-
console.error('[ChatRecording] Error recording message:', error);
|
|
97
|
-
const messageStr = String(message);
|
|
98
|
-
return [this.createEvent('RecordingError', {
|
|
99
|
-
error: error instanceof Error ? error.message : String(error),
|
|
100
|
-
messageContent: messageStr.slice(0, 100)
|
|
101
|
-
})];
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
initializeSession(context) {
|
|
105
|
-
const sessionId = this.generateSessionId();
|
|
106
|
-
this.currentSession = {
|
|
107
|
-
sessionId,
|
|
108
|
-
startTime: new Date().toISOString(),
|
|
109
|
-
messages: [],
|
|
110
|
-
totalTokens: {
|
|
111
|
-
input: 0,
|
|
112
|
-
output: 0,
|
|
113
|
-
cached: 0,
|
|
114
|
-
total: 0
|
|
115
|
-
},
|
|
116
|
-
toolCallCount: 0,
|
|
117
|
-
metadata: {
|
|
118
|
-
llmConfig: (context === null || context === void 0 ? void 0 : context.llmconfig) || {},
|
|
119
|
-
userAgent: 'codebolt-agent',
|
|
120
|
-
version: '1.0.0',
|
|
121
|
-
...context === null || context === void 0 ? void 0 : context.sessionMetadata
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
createMessageRecord(message, context) {
|
|
126
|
-
const id = this.generateMessageId();
|
|
127
|
-
const timestamp = new Date().toISOString();
|
|
128
|
-
// Extract basic message info
|
|
129
|
-
let role = 'unknown';
|
|
130
|
-
let content = '';
|
|
131
|
-
let toolCalls = [];
|
|
132
|
-
if (message.messages && Array.isArray(message.messages) && message.messages.length > 0) {
|
|
133
|
-
const lastMessage = message.messages[message.messages.length - 1];
|
|
134
|
-
role = lastMessage.role || 'unknown';
|
|
135
|
-
content = this.extractContent(lastMessage.content);
|
|
136
|
-
if (lastMessage.tool_calls) {
|
|
137
|
-
toolCalls = this.extractToolCalls(lastMessage.tool_calls);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
else if (typeof message === 'string') {
|
|
141
|
-
role = 'user';
|
|
142
|
-
content = message;
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
content = JSON.stringify(message);
|
|
146
|
-
}
|
|
147
|
-
// Calculate tokens if enabled
|
|
148
|
-
let tokens;
|
|
149
|
-
if (this.enableTokenTracking) {
|
|
150
|
-
tokens = this.estimateTokens(content);
|
|
151
|
-
}
|
|
152
|
-
return {
|
|
153
|
-
id,
|
|
154
|
-
timestamp,
|
|
155
|
-
role,
|
|
156
|
-
content: content.slice(0, 10000), // Limit content length for storage
|
|
157
|
-
metadata: this.includeMetadata ? {
|
|
158
|
-
originalMessageLength: content.length,
|
|
159
|
-
hasToolCalls: toolCalls.length > 0,
|
|
160
|
-
contextKeys: context ? Object.keys(context) : [],
|
|
161
|
-
...message.metadata
|
|
162
|
-
} : undefined,
|
|
163
|
-
tokens,
|
|
164
|
-
toolCalls: toolCalls.length > 0 ? toolCalls : undefined
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
extractContent(content) {
|
|
168
|
-
if (typeof content === 'string') {
|
|
169
|
-
return content;
|
|
170
|
-
}
|
|
171
|
-
if (Array.isArray(content)) {
|
|
172
|
-
return content
|
|
173
|
-
.map(part => {
|
|
174
|
-
if (typeof part === 'string')
|
|
175
|
-
return part;
|
|
176
|
-
if (part === null || part === void 0 ? void 0 : part.text)
|
|
177
|
-
return part.text;
|
|
178
|
-
if ((part === null || part === void 0 ? void 0 : part.type) === 'text')
|
|
179
|
-
return part.text || '';
|
|
180
|
-
return JSON.stringify(part);
|
|
181
|
-
})
|
|
182
|
-
.join(' ');
|
|
183
|
-
}
|
|
184
|
-
return JSON.stringify(content);
|
|
185
|
-
}
|
|
186
|
-
extractToolCalls(toolCalls) {
|
|
187
|
-
return toolCalls.map(tc => {
|
|
188
|
-
var _a, _b, _c;
|
|
189
|
-
return ({
|
|
190
|
-
id: tc.id || this.generateToolCallId(),
|
|
191
|
-
name: ((_a = tc.function) === null || _a === void 0 ? void 0 : _a.name) || 'unknown',
|
|
192
|
-
args: typeof ((_b = tc.function) === null || _b === void 0 ? void 0 : _b.arguments) === 'string'
|
|
193
|
-
? JSON.parse(tc.function.arguments)
|
|
194
|
-
: ((_c = tc.function) === null || _c === void 0 ? void 0 : _c.arguments) || {},
|
|
195
|
-
status: 'pending',
|
|
196
|
-
timestamp: new Date().toISOString()
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
estimateTokens(content) {
|
|
201
|
-
// Simple token estimation
|
|
202
|
-
const charCount = content.length;
|
|
203
|
-
const estimated = Math.ceil(charCount / 4);
|
|
204
|
-
return {
|
|
205
|
-
input: estimated,
|
|
206
|
-
output: 0,
|
|
207
|
-
cached: 0,
|
|
208
|
-
total: estimated
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
updateSessionTotals(messageRecord) {
|
|
212
|
-
if (!this.currentSession || !messageRecord.tokens)
|
|
213
|
-
return;
|
|
214
|
-
this.currentSession.totalTokens.input += messageRecord.tokens.input;
|
|
215
|
-
this.currentSession.totalTokens.output += messageRecord.tokens.output;
|
|
216
|
-
this.currentSession.totalTokens.cached += messageRecord.tokens.cached;
|
|
217
|
-
this.currentSession.totalTokens.total += messageRecord.tokens.total;
|
|
218
|
-
if (messageRecord.toolCalls) {
|
|
219
|
-
this.currentSession.toolCallCount += messageRecord.toolCalls.length;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
generateSessionId() {
|
|
223
|
-
return `session-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
224
|
-
}
|
|
225
|
-
generateMessageId() {
|
|
226
|
-
return `msg-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
227
|
-
}
|
|
228
|
-
generateToolCallId() {
|
|
229
|
-
return `tool-${Date.now()}-${Math.random().toString(36).substr(2, 6)}`;
|
|
230
|
-
}
|
|
231
|
-
async exportSession(session) {
|
|
232
|
-
// Ensure output directory exists
|
|
233
|
-
await this.ensureDirectoryExists();
|
|
234
|
-
const filename = `chat-session-${session.sessionId}-${Date.now()}.${this.exportFormat}`;
|
|
235
|
-
const filepath = path.join(this.outputDirectory, filename);
|
|
236
|
-
// Update end time
|
|
237
|
-
session.endTime = new Date().toISOString();
|
|
238
|
-
let content;
|
|
239
|
-
switch (this.exportFormat) {
|
|
240
|
-
case 'json':
|
|
241
|
-
content = JSON.stringify(session, null, 2);
|
|
242
|
-
break;
|
|
243
|
-
case 'txt':
|
|
244
|
-
content = this.formatAsText(session);
|
|
245
|
-
break;
|
|
246
|
-
case 'csv':
|
|
247
|
-
content = this.formatAsCSV(session);
|
|
248
|
-
break;
|
|
249
|
-
default:
|
|
250
|
-
content = JSON.stringify(session, null, 2);
|
|
251
|
-
}
|
|
252
|
-
await fs.writeFile(filepath, content, 'utf-8');
|
|
253
|
-
return filepath;
|
|
254
|
-
}
|
|
255
|
-
async ensureDirectoryExists() {
|
|
256
|
-
try {
|
|
257
|
-
await fs.access(this.outputDirectory);
|
|
258
|
-
}
|
|
259
|
-
catch {
|
|
260
|
-
await fs.mkdir(this.outputDirectory, { recursive: true });
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
formatAsText(session) {
|
|
264
|
-
const lines = [];
|
|
265
|
-
lines.push(`Chat Session: ${session.sessionId}`);
|
|
266
|
-
lines.push(`Start Time: ${session.startTime}`);
|
|
267
|
-
lines.push(`End Time: ${session.endTime || 'Ongoing'}`);
|
|
268
|
-
lines.push(`Total Messages: ${session.messages.length}`);
|
|
269
|
-
lines.push(`Total Tokens: ${session.totalTokens.total}`);
|
|
270
|
-
lines.push(`Tool Calls: ${session.toolCallCount}`);
|
|
271
|
-
lines.push('---');
|
|
272
|
-
for (const message of session.messages) {
|
|
273
|
-
lines.push(`[${message.timestamp}] ${message.role.toUpperCase()}: ${message.content}`);
|
|
274
|
-
if (message.toolCalls) {
|
|
275
|
-
for (const tool of message.toolCalls) {
|
|
276
|
-
lines.push(` 🔧 ${tool.name}(${JSON.stringify(tool.args)})`);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
lines.push('');
|
|
280
|
-
}
|
|
281
|
-
return lines.join('\n');
|
|
282
|
-
}
|
|
283
|
-
formatAsCSV(session) {
|
|
284
|
-
var _a, _b;
|
|
285
|
-
const headers = ['timestamp', 'role', 'content', 'tokens', 'tool_calls'];
|
|
286
|
-
const rows = [headers.join(',')];
|
|
287
|
-
for (const message of session.messages) {
|
|
288
|
-
const row = [
|
|
289
|
-
message.timestamp,
|
|
290
|
-
message.role,
|
|
291
|
-
`"${message.content.replace(/"/g, '""')}"`, // Escape quotes
|
|
292
|
-
((_a = message.tokens) === null || _a === void 0 ? void 0 : _a.total) || 0,
|
|
293
|
-
((_b = message.toolCalls) === null || _b === void 0 ? void 0 : _b.length) || 0
|
|
294
|
-
];
|
|
295
|
-
rows.push(row.join(','));
|
|
296
|
-
}
|
|
297
|
-
return rows.join('\n');
|
|
298
|
-
}
|
|
299
|
-
// Public methods for session management
|
|
300
|
-
async finalizeSession() {
|
|
301
|
-
if (!this.currentSession)
|
|
302
|
-
return null;
|
|
303
|
-
try {
|
|
304
|
-
const exportPath = await this.exportSession(this.currentSession);
|
|
305
|
-
this.sessions.push(this.currentSession);
|
|
306
|
-
this.currentSession = null;
|
|
307
|
-
this.messageCount = 0;
|
|
308
|
-
return exportPath;
|
|
309
|
-
}
|
|
310
|
-
catch (error) {
|
|
311
|
-
console.error('[ChatRecording] Error finalizing session:', error);
|
|
312
|
-
return null;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
getCurrentSession() {
|
|
316
|
-
return this.currentSession;
|
|
317
|
-
}
|
|
318
|
-
getSessionStats() {
|
|
319
|
-
var _a, _b;
|
|
320
|
-
const totalMessages = this.sessions.reduce((sum, session) => sum + session.messages.length, 0) +
|
|
321
|
-
(((_a = this.currentSession) === null || _a === void 0 ? void 0 : _a.messages.length) || 0);
|
|
322
|
-
return {
|
|
323
|
-
currentSessionMessages: ((_b = this.currentSession) === null || _b === void 0 ? void 0 : _b.messages.length) || 0,
|
|
324
|
-
totalSessions: this.sessions.length + (this.currentSession ? 1 : 0),
|
|
325
|
-
totalMessages
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
exports.ChatRecordingProcessor = ChatRecordingProcessor;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { BaseProcessor, ProcessorInput, ProcessorOutput } from '../../processor';
|
|
2
|
-
export interface ContextInfo {
|
|
3
|
-
projectContext?: string;
|
|
4
|
-
ideContext?: any;
|
|
5
|
-
directoryContext?: string;
|
|
6
|
-
contextAdded: boolean;
|
|
7
|
-
}
|
|
8
|
-
export interface ContextManagementProcessorOptions {
|
|
9
|
-
enableProjectContext?: boolean;
|
|
10
|
-
enableIdeContext?: boolean;
|
|
11
|
-
enableDirectoryContext?: boolean;
|
|
12
|
-
forceFullContext?: boolean;
|
|
13
|
-
contextThreshold?: number;
|
|
14
|
-
}
|
|
15
|
-
export declare class ContextManagementProcessor extends BaseProcessor {
|
|
16
|
-
private readonly enableProjectContext;
|
|
17
|
-
private readonly enableIdeContext;
|
|
18
|
-
private readonly enableDirectoryContext;
|
|
19
|
-
private readonly forceFullContext;
|
|
20
|
-
private readonly contextThreshold;
|
|
21
|
-
private lastSentIdeContext;
|
|
22
|
-
private contextAddedToHistory;
|
|
23
|
-
constructor(options?: ContextManagementProcessorOptions);
|
|
24
|
-
processInput(input: ProcessorInput): Promise<ProcessorOutput[]>;
|
|
25
|
-
private collectContext;
|
|
26
|
-
private getProjectContext;
|
|
27
|
-
private getIdeContext;
|
|
28
|
-
private getDirectoryContext;
|
|
29
|
-
private detectIdeType;
|
|
30
|
-
private getOpenFiles;
|
|
31
|
-
private getActiveFile;
|
|
32
|
-
private addContextToMessage;
|
|
33
|
-
resetContext(): void;
|
|
34
|
-
forceContextRefresh(): void;
|
|
35
|
-
setContextThreshold(threshold: number): void;
|
|
36
|
-
enableProjectContextForSession(): void;
|
|
37
|
-
disableProjectContextForSession(): void;
|
|
38
|
-
enableIdeContextForSession(): void;
|
|
39
|
-
disableIdeContextForSession(): void;
|
|
40
|
-
}
|