Skip to content

fix(kosong): preserve encrypted reasoning and data-URL MIME in provider conversion#731

Open
Dmatut7 wants to merge 3 commits into
MoonshotAI:mainfrom
Dmatut7:fix/kosong-provider-conversion
Open

fix(kosong): preserve encrypted reasoning and data-URL MIME in provider conversion#731
Dmatut7 wants to merge 3 commits into
MoonshotAI:mainfrom
Dmatut7:fix/kosong-provider-conversion

Conversation

@Dmatut7

@Dmatut7 Dmatut7 commented Jun 13, 2026

Copy link
Copy Markdown

Related Issue

No existing issue — two provider message-conversion bugs explained below.

Problem

(1) OpenAI Responses: in _convertNonStreamResponse, a reasoning output item only emitted a think part by iterating its summary; when summary was empty but encrypted_content was present, nothing was yielded and the encrypted reasoning was dropped — unlike the streaming output_item.done path, which preserves it. Since the provider requests include: ['reasoning.encrypted_content'] and round-trips that token, multi-turn tool-use lost reasoning context. (2) Google GenAI: convertMediaUrl only extracted the MIME type when the data-URL meta segment had both : and ;, so a valid data URL with an explicit type but no ;base64 (e.g. data:image/png,<raw>) fell back to the generic image/jpeg.

What changed

(1) The non-stream path now emits an empty think part carrying encrypted_content when the summary is empty, matching the streaming path. (2) End the MIME slice at the first ; when present, otherwise at the end of the meta segment, requiring only a leading : and a non-empty type; the common ;base64 path is unchanged. Tests added for both.

Note for reviewers: I could not end-to-end test these against the live OpenAI/Google APIs (no keys). The fixes are unit-tested and mirror the providers' existing behavior (the streaming path / RFC 2397) — please confirm against the live services.

Checklist

  • I have read the CONTRIBUTING document.
  • I have explained the problem above.
  • I have added tests (fail-before/pass-after).
  • Changeset included (patch, @moonshot-ai/kimi-code + @moonshot-ai/kimi-code-sdk).
  • This PR needs no doc update.

Dmatut7 and others added 3 commits June 14, 2026 03:46
In `_convertNonStreamResponse`, a `reasoning` output item only emitted a
think part by iterating its `summary`. When `summary` was empty but
`encrypted_content` was present, nothing was yielded and the encrypted
reasoning token was silently dropped — unlike the streaming
`response.output_item.done` path, which always emits an (empty) think
part carrying the encrypted content.

Since the provider explicitly requests `include:
['reasoning.encrypted_content']` and round-trips that token across turns,
the non-stream path now emits the same empty-think-with-encrypted part,
so multi-turn tool-use replay keeps the reasoning context.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
`convertMediaUrl` only extracted the MIME type when the data-URL meta
segment contained both `:` and `;`. A valid data URL with an explicit
type but no `;base64` parameter (e.g. `data:image/png,<raw>`) has no
semicolon, so its real MIME type was discarded in favor of the generic
`image/jpeg` fallback when handing the image to Google GenAI.

End the MIME slice at the first `;` when present, otherwise at the end of
the meta segment, requiring only the leading `:` and a non-empty type.
The common `data:<type>;base64,...` path is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Jun 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d21c555

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@moonshot-ai/kimi-code Patch
@moonshot-ai/kimi-code-sdk Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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