feat(kimi-code): add China/International region selection for OAuth login - #2862
feat(kimi-code): add China/International region selection for OAuth login#2862liruifengv wants to merge 4 commits into
Conversation
…ogin - Add region profiles (cn/overseas) and resolver in @moonshot-ai/kimi-code-oauth: env override → persisted login host → install-channel marker → default cn - /login now offers Kimi Code (China) / Kimi Code (International); the CLI login entries (kimi login, kimi acp --login) accept --region cn|overseas - Update/plugin/site/telemetry endpoints derive from the selected region; plugin trust list covers both .com and .ai hosts - kap-server: POST /oauth/login accepts an optional region; new GET /oauth/region
🦋 Changeset detectedLatest commit: 605ada1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 59d9eb13f5
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…marker A China login persists no oauthHost (the default credential slot carries no host trace), so after switching back from International the resolver fell through to a stale overseas install marker. Treat a persisted default-slot oauth ref (key === oauth/kimi-code) as an explicit-cn signal that outranks the marker; getRegion() on the v2 side mirrors it.
|
@codex review |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ddfd3c80db
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…gion resolution Capability installs resolved the region from the persisted oauthHost only, so an explicit China login (which persists no host) lost to a stale overseas install marker. Pass the oauth ref key through as well, matching getRegion(). Also move the region contract notes into the auth.ts file header per the package comment convention.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b0b7116b28
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
… endpoint Hosts that set KIMI_CODE_REGION_MARKER=off (the desktop embedded server) skip the install marker in getRegion(), but the default telemetry endpoint still consulted it, so a stale overseas marker could split the reported region from the telemetry destination.
Related Issue
No linked issue — the problem is described below.
Problem
Kimi Code currently hardcodes every off-session endpoint (OAuth host, managed API, update CDN, site links, telemetry) to the mainland-China
.comdeployment. To serve international users, the client needs to support a second, international (.ai) deployment — two login options whose choice is remembered and followed by all derived behavior (updates, plugin marketplace, docs/console links, telemetry).What changed
Introduces a region concept (
cn/overseas) with a single source of truth in@moonshot-ai/kimi-code-oauth:packages/oauth/src/region.ts): each region bundles its OAuth host, managed API base, CDN base, site base, and telemetry endpoint. Resolution order: env override (KIMI_CODE_OAUTH_HOST/KIMI_OAUTH_HOST) → persisted login host (config.toml) → install-channel marker file (~/.kimi-code/region, written by install scripts) → defaultcn. The OAuth client_id stays shared across regions; credential slots already isolate by (host, baseUrl) digest, so both regions can stay logged in side by side./loginnow offers Kimi Code (China) and Kimi Code (International) (suggested region listed first);kimi loginandkimi acp --loginaccept--region cn|overseasfor the non-interactive paths (ACP terminal-auth has no UI). The SDK facade'slogintakes an optionalregion, mapped to profile hosts viakimiRegionLoginHosts(env overrides keep priority; an explicit 'cn' overrides a previously persisted overseas login).cdn.kimi.aimirror coverage is still being confirmed, so those stay on.comfor now). The plugin trust list recognizes both.comand.aihost families.POST /oauth/loginaccepts an optionalregion; newGET /oauth/regionexposes the resolved region for frontends (used by the web/desktop login UIs and the desktop updater).KIMI_CODE_REGION_MARKER=offlets the desktop's embedded server opt out of marker reading.Default behavior is unchanged for existing users (region resolves to
cn).Verified: package/CLI unit and integration tests (incl. login against overseas hosts and switching back to cn), plus a live smoke run of the dev server —
GET /oauth/regionanswers correctly for default/marker/garbage-marker states, andPOST /oauth/login {region:'overseas'}reaches the international OAuth host.Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update. — No doc update in this PR: the International entry depends on service-side rollout (.aisite/console pages); user docs will follow when it publicly launches.