fix: correct session.chat() return type to match server response#45
Open
illera88 wants to merge 1 commit intoanomalyco:mainfrom
Open
fix: correct session.chat() return type to match server response#45illera88 wants to merge 1 commit intoanomalyco:mainfrom
illera88 wants to merge 1 commit intoanomalyco:mainfrom
Conversation
The OpenCode server's POST /session/{id}/message endpoint returns a
wrapper object with 'info' (the assistant message) and 'parts' (the
message parts):
{"info": AssistantMessage, "parts": Part[]}
The SDK was casting this response to bare AssistantMessage, which
caused Pydantic to silently produce a hollow object where all fields
(id, role, tokens, etc.) were None.
This commit:
- Adds SessionChatResponse type with 'info: Message' and 'parts: List[Part]'
fields matching the actual server response shape
- Updates both sync and async chat() to return SessionChatResponse
- Exports the new type from types/__init__.py
- Updates api.md documentation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SessionChatResponsetype withinfo: Messageandparts: List[Part]fields matching the actual server response.chat()methods to returnSessionChatResponseinstead of bareAssistantMessage.Problem
The OpenCode server's
POST /session/{id}/messageendpoint returns a wrapper:{ "info": { "role": "assistant", "id": "msg_...", "tokens": {...}, ... }, "parts": [ { "type": "step-start", ... }, { "type": "text", "text": "Hello!", ... }, { "type": "step-finish", ... } ] }But
session.chat()was typed to cast this entire response toAssistantMessage, which only expects the fields insideinfo. Pydantic silently ignores the unknown top-level keys (info,parts) and produces a hollow object whereid,role,tokens, etc. are allNone.Reproduction
Fix
Added
SessionChatResponse(same shape asSessionMessagesResponseItem):After this fix: