File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -182,13 +182,16 @@ export async function summarizeConversation(
182182 }
183183
184184 // Generate a unique condenseId for this condensation
185- const condenseId = `condense-${ Date . now ( ) } -${ Math . random ( ) . toString ( 36 ) . substr ( 2 , 9 ) } `
185+ const condenseId = `condense-${ Date . now ( ) } -${ Math . random ( ) . toString ( 36 ) . slice ( 2 , 11 ) } `
186+
187+ // Choose a unique timestamp that sorts just before the first kept tail message
188+ const summaryTs = Math . min ( ( keepMessages [ 0 ] ?. ts ?? Date . now ( ) ) - 1 , Date . now ( ) )
186189
187190 // Create the summary message with condenseId
188191 const summaryMessage : ApiMessage = {
189192 role : "assistant" ,
190193 content : summary ,
191- ts : keepMessages [ 0 ] . ts ,
194+ ts : summaryTs ,
192195 isSummary : true ,
193196 condenseId : condenseId ,
194197 }
@@ -197,7 +200,7 @@ export async function summarizeConversation(
197200 // Middle messages are those that were summarized but not kept
198201 const middleMessages = messages . slice ( 1 , - N_MESSAGES_TO_KEEP ) . map ( ( msg ) => ( {
199202 ...msg ,
200- condenseParent : condenseId ,
203+ condenseParent : msg . condenseParent ?? condenseId ,
201204 } ) )
202205
203206 // Reconstruct messages: [first message, tagged middle messages, summary, last N messages]
You can’t perform that action at this time.
0 commit comments