@@ -127,6 +127,10 @@ export function convertToAiSdkMessages(
127127 } else if ( message . role === "assistant" ) {
128128 const textParts : string [ ] = [ ]
129129 const reasoningParts : string [ ] = [ ]
130+ const reasoningContent = ( ( ) => {
131+ const maybe = ( message as unknown as { reasoning_content ?: unknown } ) . reasoning_content
132+ return typeof maybe === "string" && maybe . length > 0 ? maybe : undefined
133+ } ) ( )
130134 const toolCalls : Array < {
131135 type : "tool-call"
132136 toolCallId : string
@@ -154,6 +158,10 @@ export function convertToAiSdkMessages(
154158 // Task stores reasoning as a content block (type: "reasoning") and Anthropic extended
155159 // thinking as (type: "thinking"). Convert both to AI SDK's reasoning part.
156160 if ( ( part as unknown as { type ?: string } ) . type === "reasoning" ) {
161+ // If message-level reasoning_content is present, treat it as canonical and
162+ // avoid mixing it with content-block reasoning (which can cause duplication).
163+ if ( reasoningContent ) continue
164+
157165 const text = ( part as unknown as { text ?: string } ) . text
158166 if ( typeof text === "string" && text . length > 0 ) {
159167 reasoningParts . push ( text )
@@ -162,6 +170,8 @@ export function convertToAiSdkMessages(
162170 }
163171
164172 if ( ( part as unknown as { type ?: string } ) . type === "thinking" ) {
173+ if ( reasoningContent ) continue
174+
165175 const thinking = ( part as unknown as { thinking ?: string } ) . thinking
166176 if ( typeof thinking === "string" && thinking . length > 0 ) {
167177 reasoningParts . push ( thinking )
@@ -176,7 +186,9 @@ export function convertToAiSdkMessages(
176186 | { type : "tool-call" ; toolCallId : string ; toolName : string ; input : unknown }
177187 > = [ ]
178188
179- if ( reasoningParts . length > 0 ) {
189+ if ( reasoningContent ) {
190+ content . push ( { type : "reasoning" , text : reasoningContent } )
191+ } else if ( reasoningParts . length > 0 ) {
180192 content . push ( { type : "reasoning" , text : reasoningParts . join ( "" ) } )
181193 }
182194
0 commit comments