@@ -2,46 +2,20 @@ import { promises as fs } from 'fs';
22import path from 'path' ;
33
44import { logger } from '../utils' ;
5- import { CONTROL_MARKER , MCP_MARKER , TaskSegment } from './types' ;
6-
7- interface ApiHistoryEntry {
8- role : string ;
9- content : Array < {
10- type : string ;
11- text ?: string ;
12- } > ;
13- }
14-
15- interface UiMessage {
16- type : string ;
17- say ?: string ;
18- ask ?: string ;
19- from ?: string ;
20- text ?: string ;
21- ts ?: number ;
22- conversationHistoryIndex ?: number ;
23- }
24-
25- interface TaskBoundary {
26- taskNumber : number ;
27- directoryId : string ;
28- startIndex : number ;
29- startTime : number ;
30- apiCalls : ApiHistoryEntry [ ] ;
31- userMessages : UiMessage [ ] ;
32- endIndex : number | null ;
33- endTime : number | null ;
34- testType : string ;
35- apiCallCount ?: number ;
36- messageCount ?: number ;
37- }
5+ import {
6+ ApiHistoryEntry ,
7+ CONTROL_MARKER ,
8+ MCP_MARKER ,
9+ TaskSegment ,
10+ UIMessage ,
11+ } from './types' ;
3812
3913class ChatProcessor {
4014 private chatDir : string ;
4115
4216 private apiHistory : ApiHistoryEntry [ ] ;
4317
44- private uiMessages : UiMessage [ ] ;
18+ private uiMessages : UIMessage [ ] ;
4519
4620 private directoryId : string ;
4721
@@ -201,7 +175,7 @@ class ChatProcessor {
201175 return Promise . resolve ( [ ] ) ;
202176 }
203177
204- const taskBoundaries : TaskBoundary [ ] = [ ] ;
178+ const taskBoundaries : TaskSegment [ ] = [ ] ;
205179 const taskNumbers = new Set < number > ( ) ;
206180
207181 // Find task boundaries in UI messages
@@ -296,19 +270,19 @@ class ChatProcessor {
296270
297271 // Process task segments in parallel
298272 return Promise . all (
299- taskBoundaries . map ( ( boundary ) => this . processTaskSegment ( boundary ) ) ,
273+ taskBoundaries . map ( ( task ) => this . processTaskSegment ( task ) ) ,
300274 ) ;
301275 }
302276
303277 /**
304278 * Process a single task segment
305- * @param {TaskBoundary } boundary The task boundary information
279+ * @param {TaskSegment } task The task task information
306280 * @returns {Promise<TaskSegment> } The processed task segment
307281 */
308- async processTaskSegment ( boundary : TaskBoundary ) : Promise < TaskSegment > {
309- if ( ! boundary || ! this . initialized ) {
282+ async processTaskSegment ( task : TaskSegment ) : Promise < TaskSegment > {
283+ if ( ! task || ! this . initialized ) {
310284 return {
311- ...boundary ,
285+ ...task ,
312286 apiCalls : [ ] ,
313287 userMessages : [ ] ,
314288 apiCallCount : 0 ,
@@ -318,12 +292,12 @@ class ChatProcessor {
318292
319293 // Collect user messages
320294 const messages = this . uiMessages . slice (
321- boundary . startIndex ,
322- ( boundary . endIndex ?? this . uiMessages . length - 1 ) + 1 ,
295+ task . startIndex ,
296+ ( task . endIndex ?? this . uiMessages . length - 1 ) + 1 ,
323297 ) ;
324298
325299 logger . info (
326- `Processing ${ messages . length } messages for task ${ boundary . taskNumber } ` ,
300+ `Processing ${ messages . length } messages for task ${ task . taskNumber } ` ,
327301 ) ;
328302
329303 const TASK_SEGMENT_TEXTS = [
@@ -368,9 +342,9 @@ class ChatProcessor {
368342 return false ;
369343 } ) ;
370344
371- // Create a combined boundary timestamp for filtering API entries
372- const startBoundary = boundary . startTime - 60 * 1000 ; // 1 minute before task start
373- const endBoundary = ( boundary . endTime as number ) + 5 * 60 * 1000 ; // 5 minutes after task end
345+ // Create a combined task timestamp for filtering API entries
346+ const startBoundary = task . startTime - 60 * 1000 ; // 1 minute before task start
347+ const endBoundary = ( task . endTime as number ) + 5 * 60 * 1000 ; // 5 minutes after task end
374348
375349 // Filter API entries that fall within this task's time boundaries
376350 const apiEntries = this . apiHistory . filter ( ( entry ) => {
@@ -403,13 +377,13 @@ class ChatProcessor {
403377
404378 // Return the processed task segment
405379 return {
406- ...boundary ,
380+ ...task ,
407381 apiCalls : apiEntries ,
408382 userMessages : relevantMessages ,
409- taskNumber : boundary . taskNumber ,
383+ taskNumber : task . taskNumber ,
410384 apiCallCount : apiEntries . length ,
411385 messageCount : relevantMessages . length ,
412- } as TaskSegment ;
386+ } ;
413387 }
414388
415389 /**
0 commit comments