Skip to content

fix: handle ThinkingPart in OpenCode and OpenAI API converters (#174) - #418

Closed
Million-mo wants to merge 1 commit into
develop/agenticfrom
fix/issue-174-thinkingpart-protocol-converters
Closed

fix: handle ThinkingPart in OpenCode and OpenAI API converters (#174)#418
Million-mo wants to merge 1 commit into
develop/agenticfrom
fix/issue-174-thinkingpart-protocol-converters

Conversation

@Million-mo

Copy link
Copy Markdown
Owner

Summary

Fixes #174

ThinkingPart (LLM reasoning content) was silently dropped in two protocol server areas:

  1. OpenCode server — session restore via chat_message_to_opencode() had no case for ThinkingPart; opencode_to_chat_message() had no case for ReasoningPart
  2. OpenAI API server — all paths (streaming, non-streaming, responses) ignored thinking content; OpenAIMessage lacked reasoning_content field

Changes

OpenCode converters (converters.py + message.py)

  • chat_message_to_opencode(): Add ThinkingPart case in pydantic match/case AND dict path (part_kind == thinking), creating ReasoningPart with metadata preserving id/provider_name/signature/provider_details
  • opencode_to_chat_message(): Add ReasoningPart case restoring full ThinkingPart fields from metadata
  • MessageWithParts: Add add_reasoning_part() method following existing pattern

OpenAI API server (4 files)

  • completions/models.py: Add reasoning_content field to OpenAIMessage
  • completions/helpers.py: Add ThinkingPartDelta match arm in stream_response() emitting reasoning_content delta
  • server.py: Extract ThinkingPart content from messages in non-streaming path
  • responses/helpers.py + models.py: Add ResponseReasoning output type and include reasoning in responses API

Test Plan

  • 4 new tests in test_converters_thinking.py (ThinkingPart to ReasoningPart, empty skip, ReasoningPart to ThinkingPart with/without metadata)
  • All 735 existing server + session tests pass (1 skipped)
  • ruff check + format pass
  • mypy passes on all changed files

Relationship to #155 and #156

Three independent fixes covering the full chain. No overlap in changed files.

备份迁移自 SRC-PR#223 · 作者 @Million-mo · 创建于 2026-07-20T01:37:24Z · head=fix/issue-174-thinkingpart-protocol-converters base=develop/agentic
源状态: closed · merge_commit_sha=3d4a4e3b087ea726ea7444b0126bb3af29f58830

ThinkingPart (LLM reasoning content) was silently dropped in two areas:

1. OpenCode server session restore: chat_message_to_opencode() had no
   case for ThinkingPart in either the pydantic match/case or the dict
   path. opencode_to_chat_message() had no case for ReasoningPart.

2. OpenAI API server: all paths (streaming, non-streaming, responses)
   ignored thinking content. OpenAIMessage lacked reasoning_content
   field.

Fixes:
- converters.py: Add ThinkingPart case in chat_message_to_opencode()
  (both pydantic and dict paths), creating ReasoningPart with metadata
  preserving id/provider_name/signature/provider_details. Add
  ReasoningPart case in opencode_to_chat_message() restoring full
  ThinkingPart fields.
- message.py: Add add_reasoning_part() method to MessageWithParts
- completions/models.py: Add reasoning_content field to OpenAIMessage
- completions/helpers.py: Add ThinkingPartDelta match arm in
  stream_response() emitting reasoning_content delta
- server.py: Extract ThinkingPart content in non-streaming path
- responses/helpers.py + models.py: Add ResponseReasoning output type
  and include reasoning content in responses API
@Million-mo

Copy link
Copy Markdown
Owner Author

评论 by @Million-mo 于 2026-07-20T01:51:57Z(备份迁移)

Closing as duplicate — the core issue (#174, ThinkingPart silently dropped) was already fixed by #176 and merged into main.

This PR additionally preserved id/provider_name/signature/provider_details metadata during conversion, but that overlaps with the scope of #156 (tracked in PR #222). The metadata preservation fix will be delivered via #222 instead.

@Million-mo Million-mo closed this Aug 23, 2026
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.

1 participant