SIGN IN SIGN UP

fix(deepseek): preserve reasoning_content for V4 thinking mode (via SDK patch) (#747)

* fix(deepseek): preserve reasoning_content for V4 thinking mode

DeepSeek's thinking mode requires the previous assistant turn's
reasoning_content to be passed back to the API for V4 models. Two
layers were stripping it, causing follow-up messages to fail with
"The reasoning_content in the thinking mode must be passed back to
the API."

- message-utils: convertAssistantContentParts now passes reasoning
  content parts through as ReasoningPart instead of dropping them.

- pnpm patch on @ai-sdk/deepseek@2.0.17 backports vercel/ai#14740
  (already merged into release-v6.0 branch upstream, but unreleased
  on npm at the time of writing). The patch is model-aware:
  - For deepseek-v4 / deepseek-v4-pro, reasoning_content from prior
    assistant turns is preserved, and an empty string is back-filled
    when an assistant message has no reasoning part at all.
  - For deepseek-reasoner (R1) and other models, the existing
    strip-prior-reasoning behavior is unchanged, matching DeepSeek's
    R1 documentation.

When @ai-sdk/deepseek 2.0.30+ ships with the upstream fix, drop the
patchedDependencies entry — no other code changes needed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(deepseek): gate reasoning preservation to DeepSeek only

Passing reasoning content parts through to all providers caused regressions:

- xAI Grok rejects requests with HTTP 400 ('property reasoning_content
  is unsupported') — strict schema validation on assistant messages.
- Mistral SDK concatenates reasoning text into assistant content with no
  separator (intentional upstream behavior since vercel/ai#8072 for
  magistral models, but produces corrupted context for non-thinking
  Mistral models).
- Google Gemini emits prior reasoning as `{thought: true}` parts that
  non-thinking models may reject.

DeepSeek V4 thinking mode is the only consumer that requires this round-trip.
Add a `preserveReasoning` opt-in to convertAssistantContentParts /
convertToModelMessages, and enable it from the orchestration paths only when
the active provider is DeepSeek. All other providers fall back to the prior
drop-on-conversion behavior.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
(cherry picked from commit 86a53f44507504f97228711377e02e10251096f7)
Z
Zeng Xian committed
0105863ab8ab47869210732799d16bd27143d981
Parent: 9f1e70c