fix(kimi): tag content parts so serde emits the type discriminant - #99
Merged
raine merged 1 commit intoAug 2, 2026
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes Kimi request translation so multimodal user content and multi-part tool results serialize with an explicit "type" discriminant, matching the OpenAI-style content-part shape that Kimi expects (and preventing invalid part type: errors that break subagents and multimodal messages).
Changes:
- Switch
KimiUserContentPartandKimiToolResultPartfrom#[serde(untagged)]to#[serde(tag = "type", rename_all = "snake_case")]so serialized parts include"type": "text"/"type": "image_url". - Add regression tests verifying
"type"is present for both user content parts and tool result parts.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Owner
|
Thanks! |
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.
Addresses #98.
Problem
KimiUserContentPartandKimiToolResultPartare declared#[serde(untagged)], so they serialize without a discriminant:{"text": "..."} {"image_url": {"url": "..."}}Kimi expects the OpenAI multimodal shape and rejects the payload:
The value after the colon is empty because the discriminant is missing.
The practical impact is that subagents do not work through the proxy. Claude Code's
Tasktool returns a multi-blocktool_result, which always takes this path. Single-output tools such as Bash and Read are unaffected, becausetool_result_contentcollapses a lone text part back into a plain string before serializing.Change
Tag both enums:
#[serde(tag = "type", rename_all = "snake_case")]Output becomes
{"type":"text","text":"..."}and{"type":"image_url","image_url":{...}}.Tests
Two regression tests added, one per enum, asserting the discriminant is present:
user_content_parts_carry_a_type_discriminanttool_result_parts_carry_a_type_discriminantThe existing
translate_tool_result_with_image,translate_tool_result_with_unsupported_blocksandtranslate_user_text_and_image_collapse_correctlyassert only on thetextandimage_urlkeys, so they are unaffected.Verification
Built and tested against a live Kimi account on macOS arm64. Before the change, a multimodal user message and any subagent invocation both returned
invalid part type. After the change, both succeed.