Skip to content

fix: surface reasoning as collapsible thinking parts in Copilot Chat (#22, #71)#72

Merged
ltmoerdani merged 1 commit into
mainfrom
fix/thinking-part-byok-surfacing-22-71
Jul 9, 2026
Merged

fix: surface reasoning as collapsible thinking parts in Copilot Chat (#22, #71)#72
ltmoerdani merged 1 commit into
mainfrom
fix/thinking-part-byok-surfacing-22-71

Conversation

@ltmoerdani

Copy link
Copy Markdown
Owner

Summary

Reasoning content from OpenCode models (DeepSeek, Kimi, GLM, Qwen, MiniMax, MiMo) is now streamed live to the Copilot Chat UI as collapsible thinking blocks via the proposed LanguageModelThinkingPart API. This makes chat.agent.thinkingStyle (collapsed / collapsedPreview / fixedScrolling) work for OpenCode BYOK models, matching the behavior of Copilot-hosted models.

Previously, reasoning was accumulated internally but never emitted as a thinking part — so it either appeared as flat plain text or was silently dropped when text/tool calls were present.

Background

Issues #22 and #71 are duplicates reporting the same bug. The previous conclusion (doc 23-*, 2026-06-15) was that this was blocked on upstream microsoft/vscode#318211. Deep-dive research found that conclusion was wrong: LanguageModelThinkingPart has been available at runtime since VS Code ~1.102 (Aug 2025), well within our ^1.125.0 floor. A shipping Marketplace extension (Vizards/deepseek-v4-for-copilot) already solved this exact problem — proving the approach works without enabledApiProposals.

Full investigation: docs/issues/33-20260709-thinking-part-byok-surfacing-research.md

Changes

src/vscode.proposed.languageModelThinkingPart.d.ts (NEW)

  • Type augmentation for the proposed LanguageModelThinkingPart class (copied from VS Code repo src/vscode-dts/vscode.proposed.languageModelThinkingPart.d.ts).

src/streaming.ts (+202 / -17 lines)

  • Added thinkingPartConstructor module-level constant (runtime guard) + emitThinkingPart() helper.
  • Extended OpenAiResponseExtractor and AnthropicResponseExtractor constructors to accept progress + localRequestId.
  • Added handleReasoning() method to both extractors: accumulates reasoning for tool-call replication AND streams it live via LanguageModelThinkingPart.
  • Replaced all 9 this.reasoningContent += sites with this.handleReasoning().
  • Refactored both flushReasoningFallback() methods to early-return when the thinking part API is available.
  • Updated all 4 transport call sites (streamChatCompletions, streamAnthropicMessages, streamResponsesApi, streamGoogleGenerateContent).
  • Updated non-stream path (extractChatCompletionParts, extractAnthropicParts) to emit via thinking part for consistency.
  • Added totalReasoningChars monotonic counter for accurate [stream-summary] log metrics.

Not changed (by design):

  • package.json — no enabledApiProposals (proven unnecessary).
  • onReasoningContent callback wiring — tool-call replication intact.
  • opencodego.stripThinkTags — composes with the new surfacing.

Verification

  • npm run compile → pass (exit 0)
  • npx tsc --noEmit --strict → pass (exit 0)
  • Manual test: DeepSeek + Kimi in Copilot Chat → reasoning rendered as collapsible thinking block. chat.agent.thinkingStyle respected. Tool-call replication intact.

Coverage

All 4 transports covered in both streaming + non-stream paths:

Transport Streaming Non-stream
chat-completions (OpenAI)
messages (Anthropic)
responses (OpenAI Responses)
google (Gemini)

Fixes #22
Fixes #71

- Stream reasoning chunks via the proposed `LanguageModelThinkingPart` API.
- Extend OpenAI and Anthropic response extractors to handle reasoning emission.
- Add runtime guards to safely fall back to legacy text behavior on older hosts.
- Retain tool-call replication and think-tag filtering compatibility.
- Add type augmentation for the proposed VS Code API.
- Update changelog, devlog, and issue research documentation.

Fixes #22
Fixes #71
@ltmoerdani ltmoerdani merged commit 4ca0312 into main Jul 9, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Thinking token feedback not displaying respect setting chat.agent.thinkingStyle

1 participant