Skip to content

feat: add a Moonshot Kimi chat preset (#240) - #335

Merged
FayeSpica merged 2 commits into
ThinkFlowLab:mainfrom
Zhangbo-cn:feat/240-kimi-chat-preset
Nov 16, 2026
Merged

FayeSpica merged 2 commits into
ThinkFlowLab:mainfrom
Zhangbo-cn:feat/240-kimi-chat-preset

Conversation

@Zhangbo-cn

@Zhangbo-cn Zhangbo-cn commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

What

Adds the 月之暗面 Kimi / Moonshot Kimi chat presets requested in #240 (mainland chat row), in both billing forms requested in review.

  • src/canvas/providerPresets.ts: two rows, because the two billing routes do not share a key or a base URL.
    • kimi — 月之暗面 Kimi 开放平台 / Moonshot Kimi Open Platform, url: https://api.moonshot.cn/v1, pay-per-token on the open platform.
    • kimi-coding — 月之暗面 Kimi Code 订阅 / Moonshot Kimi Code subscription, url: https://api.kimi.com/coding/v1, draws on a Kimi Code Plan subscription quota.
    • Both: kinds: ["agent"], openai + api + bearer, logoOrganization: "moonshotai", placed after bailian-beijing, before zhipu.
  • No new adapter or endpoint code is needed: both endpoints are OpenAI-compatible, so the existing agent transport drives them unchanged.
  • modelsByKind is deliberately omitted on both rows, so Fetch models stays a live /models call and the picker lists whatever the entered key can actually reach (same approach as deepseek). With a mainland open-platform key that is kimi-k3 and kimi-k3.1-pro.
  • providerPresetFor() matches on the exact base URL, so a saved Kimi Code connection reopens as its own row instead of collapsing into the open-platform one. No routing code changed.
  • The international endpoint (api.moonshot.ai) is a separate row of the [tracking] providers: API integrations #240 matrix and is intentionally not matched — it stays a custom OpenAI-compatible service. The docs paragraph says so.
  • Logo: nothing to add, moonshotai already resolves through modelBrands.json → kimi.svg.
  • docs/guides/user-guide.md + user-guide.zh-CN.md: one paragraph per locale covering both routes, that the keys are not interchangeable, live discovery, and international → custom service.
  • tests/providerPresets.test.ts: 2 tests (both rows' shape + discovery-stays-on + localized labels + kind filtering + the two names stay distinct; and providerPresetFor() re-selecting kimi / kimi-coding for their saved connections while .ai, api.kimi.com/v1, deeper paths and other kinds fall back to custom).
  • tests/browser/kimi_real.mjs + manifest.json: an opt-in real-endpoint browser check. KIMI_ROUTE=open uses MOONSHOT_API_KEY, KIMI_ROUTE=coding uses KIMI_CODING_API_KEY; helper, incurs charges, no lane runs it.

How tested

Gates on the updated branch:

./node_modules/.bin/tsc --noEmit         # clean
npm test                                 # 820 pass, 0 fail
node scripts/check-i18n.mjs              # 3014 keys, 0 problems
node scripts/check-browser-locale.mjs    # 71 pages, 0 problems
node scripts/check-browser-manifest.mjs  # 76 entries OK
npm run build                            # built

The updated tests are mutation-checked: renaming the kimi-coding id fails 2 assertions, restoring passes 20/20.

Evidence

Open-platform route, a real turn against the real endpoint, unchanged from the first push: /models discovery returns kimi-k3, the streamed reply arrives in the UI, the agent-written asset comes back with provenance.source == "agent_written" and modelSnapshot.modelId == "kimi-k3", it appears in the asset list, adds a canvas node, and survives a reload.

Preset (zh-CN) preset zh
Preset (en-US) preset en
Streamed reply reply
Asset list assets
Canvas node node
After reload reopen

Kimi Code route, no subscription key available, so this stops at the endpoint and at everything the app does before a key is validated:

Both rows in one picker (zh-CN) rows zh
Kimi Code selected, URL prefilled (zh-CN) code zh
Kimi Code selected, URL prefilled (en-US) code en
Saved api.kimi.com connection reopens as its own row (zh-CN) reopen zh
Same, en-US reopen en

What that route does prove: https://api.kimi.com/coding/v1 is live and speaks the OpenAI shape (/models and /chat/completions both answer JSON), and an open-platform key is rejected there with 401 invalid_authentication_error — so the two keys are genuinely not interchangeable and one preset could not serve both. The rows are distinct in both locales, prefill their own URLs, save, and reopen with their own identity.

What it does not prove: which model ids the subscription exposes, whether a real turn streams, and whether tool calls work on that route. Those need a Kimi Code Plan key. The full path is exercised end to end against an OpenAI-compatible stub on 127.0.0.1 (slow_kimi_stub.py in the evidence branch): discovery, connection save, and a complete streamed turn with status=complete — this checks the app side, not Moonshot's coding endpoint.

Notes

  • Prompt used in the real run: write a text asset named kimi-note.txt inside the project. The agent completed it through opendirector asset write-text, so the whole tool-calling loop works over Kimi.
  • kimi-k3 is slow-ish for a full tool round trip (~2 min for 4 calls in my run), which is why the browser check allows long waits; that is the model, not the integration.
  • Unrelated but observed while testing: the vite pre-bundled dependency cache served stale preset data after an edit, so the new row did not appear until node_modules/.vite was cleared. Not part of this PR, no fix included.
  • Thanks @FayeSpica for the review — happy to rename either row, add a group/optionLabel pairing if you prefer one dropdown entry with two options, or drop the Kimi Code row until someone with a subscription can verify a real turn.

@github-actions github-actions Bot added area:provider Model providers and generation protocols type:feat New capability or behaviour labels Nov 15, 2026
Selecting MoonShot Kimi fills https://api.moonshot.cn/v1 and keeps live
model discovery, so the picker lists the models the entered key reaches.
The international endpoint stays a custom OpenAI-compatible service.
@Zhangbo-cn
Zhangbo-cn force-pushed the feat/240-kimi-chat-preset branch from 6c4557a to 347ad70 Compare November 15, 2026 07:08
@github-actions github-actions Bot added the area:docs Documentation / 文档 label Nov 15, 2026
@github-actions
github-actions Bot requested a review from wuzhf9 November 15, 2026 07:08

@FayeSpica FayeSpica left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you support both Moonshot Open Platform token billing and Kimi Coding Plan subscription quotas in this PR?

logoOrganization: "moonshotai",
name: "月之暗面 Kimi",
kinds: ["agent"],
url: "https://api.moonshot.cn/v1",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a separate Kimi Coding Plan preset alongside the pay-per-token Open Platform preset in this PR? Coding Plan uses https://api.kimi.com/coding/v1 with its own API key. Official configuration docs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GET, I'll make it

@FayeSpica FayeSpica mentioned this pull request Nov 16, 2026
3 of 10 tasks
…b#240)

The Kimi Code subscription uses its own base URL and its own key, so the
pay-per-token preset could not serve it: the same key returns 401 against
https://api.kimi.com/coding/v1. The open-platform row keeps
https://api.moonshot.cn/v1 and the new row points at
https://api.kimi.com/coding/v1, and both keep live /models discovery.

providerPresetFor matches on the exact base URL, so a saved Kimi Code
connection reopens as its own row instead of falling back to the
open-platform one. kimi_real.mjs takes KIMI_ROUTE to exercise either route.

The Kimi Code row is verified only up to the endpoint: it answers the
OpenAI-compatible shape with 401 for a key it does not own, and no
subscription key was available to run a real turn.
@Zhangbo-cn

Copy link
Copy Markdown
Contributor Author

Both routes are now in the PR: kimi (open platform, https://api.moonshot.cn/v1, pay per token) and kimi-coding (https://api.kimi.com/coding/v1, Kimi Code Plan quota). Two rows rather than one, because the base URL and the key both differ.

What is verified. https://api.kimi.com/coding/v1 is live and speaks the OpenAI shape — /models and /chat/completions answer JSON. My open-platform key is rejected there with 401 invalid_authentication_error, which is the direct evidence that one existing preset could not cover the subscription: it is not a URL swap. The new row appears next to the old one in both locales, prefills https://api.kimi.com/coding/v1, saves, and reopens as 月之暗面 Kimi Code 订阅 / Moonshot Kimi Code subscription rather than collapsing into the open-platform row. Screenshots for zh-CN and en-US are in the PR body.

What is not verified. I do not hold a Kimi Code Plan subscription, so I could not check which model ids the subscription exposes, whether a real turn streams, or whether tool calls work on that route. The model list is left to live /models discovery instead of pinning ids I would be guessing at. On the app side the full path is exercised end to end against an OpenAI-compatible stub, but that proves the connection plumbing, not Moonshot's coding endpoint.

If you have a subscription key, KIMI_ROUTE=coding KIMI_CODING_API_KEY=… node tests/browser/kimi_real.mjs runs the same assertions the open-platform route already passes, including /models discovery and a complete agent turn. Otherwise the honest options are to merge with the Kimi Code row marked as endpoint-verified only, or to hold it back until someone can run that once.

Two smaller things I can change on request: give both rows a shared group with optionLabel so the picker shows one Kimi entry with two options, or pin kimi-k3 in modelsByKind for the coding row if you would rather not depend on what /models returns there.

@FayeSpica FayeSpica left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding Coding Plan support. LGTM now.

I verified live model discovery, a completed SSE reply and tool-driven text asset creation with k3 on 20361fe0 using my subscription key.

@FayeSpica
FayeSpica merged commit 729b49b into ThinkFlowLab:main Nov 16, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:docs Documentation / 文档 area:provider Model providers and generation protocols type:feat New capability or behaviour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants