Skip to content

fix: support Kimi Coding Plan and third-party SSE without space after…#303

Open
404805854 wants to merge 1 commit into
nashsu:mainfrom
404805854:fix-kimi-coding-plan-sse-parse
Open

fix: support Kimi Coding Plan and third-party SSE without space after…#303
404805854 wants to merge 1 commit into
nashsu:mainfrom
404805854:fix-kimi-coding-plan-sse-parse

Conversation

@404805854
Copy link
Copy Markdown

… data:

Kimi Coding Plan (api.kimi.com/coding) returns SSE events like data:{"type":...} without a space after the colon. The existing parsers (parseOpenAiLine, parseAnthropicLine, parseGoogleLine) strictly checked for startsWith("data: ") with a trailing space, causing every event to be silently discarded and the stream to produce empty content.

Changes:

  • Relax all three SSE prefix checks to startsWith("data:") and use slice(5).trim() so both data: {...} and data:{...} work.
  • Enhance parseAnthropicLine to handle:
    • content_block_delta with bare text field (no type inside delta)
    • complete message events (single-shot SSE)
    • OpenAI-shaped choices[0].delta.content fallback
  • Add Kimi Coding Plan and Moonshot to requiresBearerAuth so they get Authorization: Bearer instead of x-api-key.
  • Move anthropic-version to base headers so all Anthropic wires (including Bearer-auth ones) receive it.
  • Add kimi-coding-plan preset to the settings UI.
  • Add unit tests for new parsing paths and auth behavior.

Fixes #302

… data:

Kimi Coding Plan (api.kimi.com/coding) returns SSE events like
`data:{"type":...}` without a space after the colon. The existing
parsers (parseOpenAiLine, parseAnthropicLine, parseGoogleLine) strictly
checked for `startsWith("data: ")` with a trailing space, causing
every event to be silently discarded and the stream to produce empty
content.

Changes:
- Relax all three SSE prefix checks to `startsWith("data:")` and use
  `slice(5).trim()` so both `data: {...}` and `data:{...}` work.
- Enhance parseAnthropicLine to handle:
  - content_block_delta with bare `text` field (no `type` inside delta)
  - complete `message` events (single-shot SSE)
  - OpenAI-shaped `choices[0].delta.content` fallback
- Add Kimi Coding Plan and Moonshot to requiresBearerAuth so they get
  `Authorization: Bearer` instead of `x-api-key`.
- Move `anthropic-version` to base headers so all Anthropic wires
  (including Bearer-auth ones) receive it.
- Add `kimi-coding-plan` preset to the settings UI.
- Add unit tests for new parsing paths and auth behavior.

Fixes nashsu#302
@404805854
Copy link
Copy Markdown
Author

使用 kimi coding plan 以及 minimax coding plan完成相关测试确定修改可行,可以提供 kimi coding plan 的 key 用于测试

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.

使用kimi的coding plan报错Model connected but returned empty content.

1 participant