@@ -656,15 +656,11 @@ const step = Effect.fn("MistralChat.step")(function* (state: ParserState, event:
656656 }
657657 const events : LLMEvent [ ] = [ ]
658658 const usage = mapUsage ( event . usage ) ?? state . usage
659- if ( state . finishReason ) {
660- if ( hasLateContent ( event ) )
661- return yield * ProviderShared . eventError (
662- ADAPTER ,
663- "Mistral Chat received content after the finish reason" ,
664- ProviderShared . encodeJson ( event ) ,
665- )
666- return [ { ...state , usage } , events ] as const
667- }
659+ // Trailing deltas after a terminal `finish_reason` are real model output:
660+ // absorb them into the stream instead of failing the response. The single
661+ // terminal finish event is emitted once at stream end, so late content still
662+ // precedes it.
663+ if ( state . finishReason && ! hasLateContent ( event ) ) return [ { ...state , usage } , events ] as const
668664 const choice = event . choices ?. [ 0 ]
669665 const withContent = choice ?. delta ?. content == null ? state : appendContent ( state , events , choice . delta . content )
670666 const withTools = yield * appendTools ( withContent , events , choice ?. delta ?. tool_calls ?? [ ] )
@@ -685,7 +681,10 @@ const step = Effect.fn("MistralChat.step")(function* (state: ParserState, event:
685681 } )
686682 }
687683 const incomplete = finishReason . normalized === "length" || finishReason . normalized === "content-filter"
688- if ( ! incomplete && Object . keys ( withTools . pendingTools ) . length > 0 )
684+ // Only the first terminal arrival rejects unidentifiable tool deltas; late
685+ // frames after a finish absorb malformed tool identities silently instead of
686+ // failing the response.
687+ if ( state . finishReason === undefined && ! incomplete && Object . keys ( withTools . pendingTools ) . length > 0 )
689688 return yield * ProviderShared . eventError (
690689 ADAPTER ,
691690 "Mistral Chat tool call delta is missing a name" ,
@@ -699,7 +698,7 @@ const step = Effect.fn("MistralChat.step")(function* (state: ParserState, event:
699698 {
700699 ...withTools ,
701700 tools : finished ?. tools ?? withTools . tools ,
702- completedTools : finished ?. events ?? withTools . completedTools ,
701+ completedTools : finished ? [ ... withTools . completedTools , ... finished . events ] : withTools . completedTools ,
703702 usage,
704703 finishReason,
705704 } ,
0 commit comments