Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ export function convertToOpenAICompatibleChatMessages(prompt: LanguageModelV3Pro
break
}
case "reasoning": {
if (part.text) reasoningText = part.text
// Preserve empty reasoning text — some providers (e.g. DeepSeek V4)
// require reasoning_content: "" to be sent back in multi-turn chains.
reasoningText = part.text ?? ""
break
}
case "tool-call": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,10 @@ export class OpenAICompatibleChatLanguageModel implements LanguageModelV3 {
}

// reasoning content (Copilot uses reasoning_text):
// Preserve empty reasoning_text (e.g. DeepSeek V4 returns reasoning_content: "")
// because some providers require it to be sent back verbatim in multi-turn chains.
const reasoning = choice.message.reasoning_text
if (reasoning != null && reasoning.length > 0) {
if (reasoning != null) {
content.push({
type: "reasoning",
text: reasoning,
Expand Down Expand Up @@ -477,22 +479,24 @@ export class OpenAICompatibleChatLanguageModel implements LanguageModelV3 {
reasoningOpaque = delta.reasoning_opaque
}

// enqueue reasoning before text deltas (Copilot uses reasoning_text):
// enqueue reasoning before text deltas (Copilot uses reasoning_text).
// Handle empty reasoning_text (e.g. DeepSeek V4 may stream reasoning_content: "").
const reasoningContent = delta.reasoning_text
if (reasoningContent) {
if ("reasoning_text" in delta) {
if (!isActiveReasoning) {
controller.enqueue({
type: "reasoning-start",
id: "reasoning-0",
})
isActiveReasoning = true
}

controller.enqueue({
type: "reasoning-delta",
id: "reasoning-0",
delta: reasoningContent,
})
if (reasoningContent) {
controller.enqueue({
type: "reasoning-delta",
id: "reasoning-0",
delta: reasoningContent,
})
}
}

if (delta.content) {
Expand Down
Loading