@@ -135,37 +135,31 @@ export namespace ProviderTransform {
135135
136136 if ( typeof model . capabilities . interleaved === "object" && model . capabilities . interleaved . field ) {
137137 const field = model . capabilities . interleaved . field
138- return msgs . map ( ( msg ) => {
139- if ( msg . role === "assistant" && Array . isArray ( msg . content ) ) {
140- const reasoningParts = msg . content . filter ( ( part : any ) => part . type === "reasoning" )
141- const reasoningText = reasoningParts . map ( ( part : any ) => part . text ) . join ( "" )
142-
143- // Filter out reasoning parts from content
144- const filteredContent = msg . content . filter ( ( part : any ) => part . type !== "reasoning" )
145-
146- // Include reasoning_content | reasoning_details directly on the message for all assistant messages
147- if ( reasoningText ) {
148- return {
149- ...msg ,
150- content : filteredContent ,
151- providerOptions : {
152- ...msg . providerOptions ,
153- openaiCompatible : {
154- ...( msg . providerOptions as any ) ?. openaiCompatible ,
155- [ field ] : reasoningText ,
138+ return msgs
139+ . map ( ( msg ) => {
140+ if ( msg . role === "assistant" && Array . isArray ( msg . content ) ) {
141+ const reasoningParts = msg . content . filter ( ( part : any ) => part . type === "reasoning" )
142+ const reasoningText = reasoningParts . map ( ( part : any ) => part . text ) . join ( "" )
143+ const filteredContent = msg . content . filter ( ( part : any ) => part . type !== "reasoning" )
144+ if ( filteredContent . length === 0 ) return undefined
145+ if ( reasoningText ) {
146+ return {
147+ ...msg ,
148+ content : filteredContent ,
149+ providerOptions : {
150+ ...msg . providerOptions ,
151+ openaiCompatible : {
152+ ...( msg . providerOptions as any ) ?. openaiCompatible ,
153+ [ field ] : reasoningText ,
154+ } ,
156155 } ,
157- } ,
156+ }
158157 }
158+ return { ...msg , content : filteredContent }
159159 }
160-
161- return {
162- ...msg ,
163- content : filteredContent ,
164- }
165- }
166-
167- return msg
168- } )
160+ return msg
161+ } )
162+ . filter ( ( msg ) : msg is ModelMessage => msg !== undefined )
169163 }
170164
171165 return msgs
0 commit comments