@@ -467,7 +467,7 @@ function formatAssistantErrorFromRecord(record: Record<string, unknown>): string
467467 return formatRawAssistantErrorForUi ( errorMessage ) ;
468468}
469469
470- function collectSanitizedBlockStrings ( params : {
470+ function collectBlockStrings ( params : {
471471 content : unknown ;
472472 blockType : "text" | "thinking" ;
473473 valueKey : "text" | "thinking" ;
@@ -482,7 +482,7 @@ function collectSanitizedBlockStrings(params: {
482482 }
483483 const rec = block as Record < string , unknown > ;
484484 if ( rec . type === params . blockType && typeof rec [ params . valueKey ] === "string" ) {
485- parts . push ( sanitizeRenderableText ( rec [ params . valueKey ] as string ) ) ;
485+ parts . push ( rec [ params . valueKey ] as string ) ;
486486 }
487487 }
488488 return parts ;
@@ -501,7 +501,7 @@ export function extractThinkingFromMessage(message: unknown): string {
501501 if ( typeof content === "string" ) {
502502 return "" ;
503503 }
504- const parts = collectSanitizedBlockStrings ( {
504+ const parts = collectBlockStrings ( {
505505 content,
506506 blockType : "thinking" ,
507507 valueKey : "thinking" ,
@@ -522,22 +522,26 @@ export function extractContentFromMessage(message: unknown): string {
522522
523523 if ( record . role === "assistant" ) {
524524 if ( typeof content === "string" ) {
525- return sanitizeRenderableText ( content ) . trim ( ) ;
525+ return content . trim ( ) ;
526526 }
527527 if ( Array . isArray ( content ) ) {
528- return extractAssistantRenderableContent ( record ) ;
528+ const text = ( extractAssistantPhaseText ( record ) ?? "" ) . trim ( ) ;
529+ const pairingQr = extractPairingQrTerminalText ( record ) ;
530+ return (
531+ [ text , pairingQr ] . filter ( Boolean ) . join ( "\n\n" ) || formatAssistantErrorFromRecord ( record )
532+ ) ;
529533 }
530534 }
531535
532536 if ( typeof content === "string" ) {
533537 return sanitizeRenderableText ( content ) . trim ( ) ;
534538 }
535539
536- const parts = collectSanitizedBlockStrings ( {
540+ const parts = collectBlockStrings ( {
537541 content,
538542 blockType : "text" ,
539543 valueKey : "text" ,
540- } ) ;
544+ } ) . map ( sanitizeRenderableText ) ;
541545 if ( parts . length > 0 ) {
542546 return parts . join ( "\n" ) . trim ( ) ;
543547 }
@@ -586,18 +590,14 @@ function extractTextBlocks(content: unknown, opts?: { includeThinking?: boolean
586590 return "" ;
587591 }
588592
589- const textParts = collectSanitizedBlockStrings ( {
590- content,
591- blockType : "text" ,
592- valueKey : "text" ,
593- } ) ;
593+ const textParts = collectBlockStrings ( { content, blockType : "text" , valueKey : "text" } ) . map (
594+ sanitizeRenderableText ,
595+ ) ;
594596 const thinkingParts =
595597 opts ?. includeThinking === true
596- ? collectSanitizedBlockStrings ( {
597- content,
598- blockType : "thinking" ,
599- valueKey : "thinking" ,
600- } )
598+ ? collectBlockStrings ( { content, blockType : "thinking" , valueKey : "thinking" } ) . map (
599+ sanitizeRenderableText ,
600+ )
601601 : [ ] ;
602602
603603 return composeThinkingAndContent ( {
0 commit comments