@@ -179,33 +179,41 @@ const filterCompressedRanges = (
179179 const msgId = msg . info . id
180180
181181 // Check if there's a summary to inject at this anchor point
182- const summary = state . compressSummaries ?. find ( ( s ) => s . anchorMessageId === msgId )
182+ const summary = state . compressSummaries ?. find ( ( s ) => s ? .anchorMessageId === msgId )
183183 if ( summary ) {
184- // Find user message for variant and as base for synthetic message
185- const msgIndex = messages . indexOf ( msg )
186- const userMessage = getLastUserMessage ( messages , msgIndex )
187-
188- if ( userMessage ) {
189- const userInfo = userMessage . info as UserMessage
190- const summaryContent = summary . summary
191- const summarySeed = `${ summary . blockId } :${ summary . anchorMessageId } `
192- result . push (
193- createSyntheticUserMessage (
194- userMessage ,
195- summaryContent ,
196- userInfo . variant ,
197- summarySeed ,
198- ) ,
199- )
200-
201- logger . info ( "Injected compress summary" , {
184+ const rawSummaryContent = ( summary as { summary ?: unknown } ) . summary
185+ if ( typeof rawSummaryContent !== "string" || rawSummaryContent . length === 0 ) {
186+ logger . warn ( "Skipping malformed compress summary" , {
202187 anchorMessageId : msgId ,
203- summaryLength : summary . summary . length ,
188+ blockId : ( summary as { blockId ?: unknown } ) . blockId ,
204189 } )
205190 } else {
206- logger . warn ( "No user message found for compress summary" , {
207- anchorMessageId : msgId ,
208- } )
191+ // Find user message for variant and as base for synthetic message
192+ const msgIndex = messages . indexOf ( msg )
193+ const userMessage = getLastUserMessage ( messages , msgIndex )
194+
195+ if ( userMessage ) {
196+ const userInfo = userMessage . info as UserMessage
197+ const summaryContent = rawSummaryContent
198+ const summarySeed = `${ summary . blockId } :${ summary . anchorMessageId } `
199+ result . push (
200+ createSyntheticUserMessage (
201+ userMessage ,
202+ summaryContent ,
203+ userInfo . variant ,
204+ summarySeed ,
205+ ) ,
206+ )
207+
208+ logger . info ( "Injected compress summary" , {
209+ anchorMessageId : msgId ,
210+ summaryLength : summaryContent . length ,
211+ } )
212+ } else {
213+ logger . warn ( "No user message found for compress summary" , {
214+ anchorMessageId : msgId ,
215+ } )
216+ }
209217 }
210218 }
211219
0 commit comments