@@ -193,13 +193,26 @@ export class OpenAIChatService implements IChatService {
193193 ( tc ) : tc is ChatCompletionMessageToolCall => tc . type === 'function'
194194 ) ;
195195
196+ // 提取 reasoning_content(DeepSeek R1 等 thinking 模型的扩展字段)
197+ const extendedMessage = choice . message as typeof choice . message & {
198+ reasoning_content ?: string ;
199+ } ;
200+ const reasoningContent = extendedMessage . reasoning_content || undefined ;
201+
202+ // 提取 reasoning_tokens(thinking 模型的扩展 usage 字段)
203+ const extendedUsage = completion . usage as typeof completion . usage & {
204+ reasoning_tokens ?: number ;
205+ } ;
206+
196207 const response = {
197208 content : choice . message . content || '' ,
209+ reasoningContent,
198210 toolCalls : toolCalls ,
199211 usage : {
200212 promptTokens : completion . usage ?. prompt_tokens || 0 ,
201213 completionTokens : completion . usage ?. completion_tokens || 0 ,
202214 totalTokens : completion . usage ?. total_tokens || 0 ,
215+ reasoningTokens : extendedUsage ?. reasoning_tokens ,
203216 } ,
204217 } ;
205218
@@ -309,6 +322,7 @@ export class OpenAIChatService implements IChatService {
309322
310323 let chunkCount = 0 ;
311324 let totalContent = '' ;
325+ let totalReasoningContent = '' ;
312326 let toolCallsReceived = false ;
313327
314328 for await ( const chunk of stream ) {
@@ -326,10 +340,19 @@ export class OpenAIChatService implements IChatService {
326340 continue ;
327341 }
328342
343+ // 提取 reasoning_content(DeepSeek R1 等 thinking 模型的扩展字段)
344+ const extendedDelta = delta as typeof delta & {
345+ reasoning_content ?: string ;
346+ } ;
347+
329348 if ( delta . content ) {
330349 totalContent += delta . content ;
331350 }
332351
352+ if ( extendedDelta . reasoning_content ) {
353+ totalReasoningContent += extendedDelta . reasoning_content ;
354+ }
355+
333356 if ( delta . tool_calls && ! toolCallsReceived ) {
334357 toolCallsReceived = true ;
335358 _logger . debug ( '🔧 [ChatService] Tool calls detected in stream' ) ;
@@ -341,13 +364,15 @@ export class OpenAIChatService implements IChatService {
341364 _logger . debug ( '📊 [ChatService] Stream summary:' , {
342365 totalChunks : chunkCount ,
343366 totalContentLength : totalContent . length ,
367+ totalReasoningContentLength : totalReasoningContent . length ,
344368 hadToolCalls : toolCallsReceived ,
345369 duration : Date . now ( ) - startTime + 'ms' ,
346370 } ) ;
347371 }
348372
349373 yield {
350374 content : delta . content || undefined ,
375+ reasoningContent : extendedDelta . reasoning_content || undefined ,
351376 toolCalls : delta . tool_calls ,
352377 finishReason : finishReason || undefined ,
353378 } ;
0 commit comments