@@ -76,11 +76,7 @@ export class AssistantMessageParser {
7676 } else {
7777 // Partial param value is accumulating.
7878 // Write the currently accumulated param content in real time
79- const partialValue = currentParamValue
80- this . currentToolUse . params [ this . currentParamName ] =
81- this . currentParamName === "content"
82- ? partialValue . replace ( / ^ \n / , "" ) . replace ( / \n $ / , "" )
83- : partialValue . trim ( )
79+ this . currentToolUse . params [ this . currentParamName ] = currentParamValue
8480 continue
8581 }
8682 }
@@ -167,6 +163,8 @@ export class AssistantMessageParser {
167163 . slice ( 0 , - toolUseOpeningTag . slice ( 0 , - 1 ) . length )
168164 . trim ( )
169165
166+ this . currentTextContent . content = this . currentTextContent . content . trim ( )
167+
170168 // No need to push, currentTextContent is already in contentBlocks
171169 this . currentTextContent = undefined
172170 }
@@ -193,7 +191,7 @@ export class AssistantMessageParser {
193191 // Create a new text content block and add it to contentBlocks
194192 this . currentTextContent = {
195193 type : "text" ,
196- content : this . accumulator . slice ( this . currentTextContentStartIndex ) . trim ( ) ,
194+ content : this . accumulator . slice ( this . currentTextContentStartIndex ) ,
197195 partial : true ,
198196 }
199197
@@ -202,7 +200,7 @@ export class AssistantMessageParser {
202200 this . contentBlocks . push ( this . currentTextContent )
203201 } else {
204202 // Update the existing text content
205- this . currentTextContent . content = this . accumulator . slice ( this . currentTextContentStartIndex ) . trim ( )
203+ this . currentTextContent . content = this . accumulator . slice ( this . currentTextContentStartIndex )
206204 }
207205 }
208206 }
@@ -222,16 +220,9 @@ export class AssistantMessageParser {
222220 if ( block . partial ) {
223221 block . partial = false
224222 }
223+ if ( block . type === "text" && typeof block . content === "string" ) {
224+ block . content = block . content . trim ( )
225+ }
225226 }
226227 }
227-
228- /**
229- * Process a complete message and return the parsed content blocks.
230- * @param message The complete message to parse.
231- * @returns The parsed content blocks.
232- */
233- public parseCompleteMessage ( message : string ) : AssistantMessageContent [ ] {
234- this . reset ( )
235- return this . processChunk ( message )
236- }
237228}
0 commit comments