Skip to content

feat(kimi-code): add China/International region selection for OAuth login - #2862

Open
liruifengv wants to merge 4 commits into
mainfrom
feat/oauth-region-split
Open

feat(kimi-code): add China/International region selection for OAuth login#2862
liruifengv wants to merge 4 commits into
mainfrom
feat/oauth-region-split

Conversation

@liruifengv

Copy link
Copy Markdown
Collaborator

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 .com deployment. 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:

  • Region profiles + resolver (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) → default cn. 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.
  • Login entries: /login now offers Kimi Code (China) and Kimi Code (International) (suggested region listed first); kimi login and kimi acp --login accept --region cn|overseas for the non-interactive paths (ACP terminal-auth has no UI). The SDK facade's login takes an optional region, mapped to profile hosts via kimiRegionLoginHosts (env overrides keep priority; an explicit 'cn' overrides a previously persisted overseas login).
  • Derived endpoints: CLI update checks, plugin marketplace, tips banner, signup/install links, rg download, WebBridge/Computer-Use artifacts, and telemetry all derive from the current region (content-CDN URLs funnel through one helper — the cdn.kimi.ai mirror coverage is still being confirmed, so those stay on .com for now). The plugin trust list recognizes both .com and .ai host families.
  • Server surface: POST /oauth/login accepts an optional region; new GET /oauth/region exposes the resolved region for frontends (used by the web/desktop login UIs and the desktop updater). KIMI_CODE_REGION_MARKER=off lets 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/region answers correctly for default/marker/garbage-marker states, and POST /oauth/login {region:'overseas'} reaches the international OAuth host.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update. — No doc update in this PR: the International entry depends on service-side rollout (.ai site/console pages); user docs will follow when it publicly launches.

…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-bot

changeset-bot Bot commented Aug 12, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 605ada1

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 Minor
@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

@pkg-pr-new

pkg-pr-new Bot commented Aug 12, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@605ada1
npx https://pkg.pr.new/@moonshot-ai/kimi-code@605ada1

commit: 605ada1

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread apps/kimi-code/src/utils/region.ts Outdated
Comment thread packages/agent-core-v2/src/app/telemetry/cloudTransport.ts
…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.
@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Unknown error
ℹ️ 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".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread packages/agent-core-v2/src/app/capability/capabilityService.ts Outdated
Comment thread packages/agent-core-v2/src/app/auth/auth.ts Outdated
…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.
@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread packages/agent-core-v2/src/app/telemetry/cloudTransport.ts Outdated
… 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.
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