File tree Expand file tree Collapse file tree 1 file changed +28
-1
lines changed
Expand file tree Collapse file tree 1 file changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -95,6 +95,33 @@ export async function truncateConversationIfNeeded({
9595 // Truncate if we're within TOKEN_BUFFER_PERCENTAGE of the context window
9696 const allowedTokens = contextWindow * ( 1 - TOKEN_BUFFER_PERCENTAGE ) - reservedTokens
9797
98+ // Apply compression to reduce token usage while preserving information
99+ // Generate filenames with timestamp
100+ const timestamp = Date . now ( )
101+ const dateStr = new Date ( timestamp )
102+ . toLocaleString ( "en-US" , {
103+ month : "short" ,
104+ day : "2-digit" ,
105+ year : "numeric" ,
106+ hour : "2-digit" ,
107+ minute : "2-digit" ,
108+ second : "2-digit" ,
109+ hour12 : false ,
110+ } )
111+ . toLowerCase ( )
112+ . replace ( / [ , : ] / g, "-" )
113+ . replace ( / \s + / g, "-" )
114+
115+ const debugDir = path . join ( this . providerRef . deref ( ) ?. context . extensionUri . fsPath || "" , "debug" )
116+ const beforeName = path . join ( debugDir , `conversation_before_compression_${ timestamp } _${ dateStr } .json` )
117+ const afterName = path . join ( debugDir , `conversation_after_compression_${ timestamp } _${ dateStr } .json` )
118+
119+ await compressConversationHistory ( messages , this . taskId , beforeName , afterName )
120+
98121 // Determine if truncation is needed and apply if necessary
99- return effectiveTokens > allowedTokens ? truncateConversation ( messages , 0.5 ) : messages
122+ if ( effectiveTokens > allowedTokens ) {
123+ messages = truncateConversation ( messages , 0.5 )
124+ }
125+
126+ return messages
100127}
You can’t perform that action at this time.
0 commit comments