Skip to content

feat(kap-server): expose the managed-account profile at GET /oauth/userinfo - #2363

Merged
liruifengv merged 6 commits into
mainfrom
feat/managed-userinfo
Jul 30, 2026
Merged

feat(kap-server): expose the managed-account profile at GET /oauth/userinfo#2363
liruifengv merged 6 commits into
mainfrom
feat/managed-userinfo

Conversation

@liruifengv

@liruifengv liruifengv commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

None — see Problem below.

Problem

The desktop and web clients want to show the signed-in managed account's profile (avatar, nickname, user level) in their settings UI. The managed platform exposes this at GET {kimi_code_base_url}/me, but renderer clients cannot call the platform directly: OAuth credentials live only in the server process (~/.kimi-code/credentials, mode 0600) and the platform base URL is a server-side env var. All platform traffic therefore already goes through the local server — /api/v1/oauth/usage is the existing precedent — but there is no endpoint for the account profile.

What changed

Adds GET /api/v1/oauth/userinfo, mirroring the /oauth/usage chain end to end:

  • @moonshot-ai/kimi-code-oauth — new managed-userinfo.ts: kimiCodeUserInfoUrl() (the cloud path stays /me, owned by the backend; only the local naming is "userinfo"), a tolerant parseManagedUserInfoPayload (cloud snake_case → camelCase domain — the only case conversion in the chain; missing display fields degrade to zero values, unknown fields are dropped), fetchManagedUserInfo (Bearer auth, 8s timeout, { kind: 'ok' | 'error' } union instead of throwing), and the zod contract (managedUserInfoSchema / managedUserInfoResultSchema) — the single source of truth for the profile type, served on the wire as-is.
  • toolkitgetManagedUserInfo + AuthManagedUserInfoResult (alias of ManagedUserInfoResult), reusing ensureFresh so expired tokens are refreshed before the call.
  • agent-core-v2IOAuthService.getManagedUserInfo / IOAuthToolkit.getManagedUserInfo contracts and the OAuthService implementation (same runtime-auth resolution path as usage); oauthProtocol.ts re-exports the oauth package's schema so the kap-server import path is unchanged. New daemon endpoints speak the camelCase domain type end to end — no per-layer DTO mapping; existing snake_case endpoints are untouched.
  • kap-server — the route itself, returning the service result unmapped; API surface snapshot regenerated.

Tests cover payload parsing (full / minimal / degraded), the zod contract (required fields / unknown keys / both branches), the fetch wrapper (401 / 404 / timeout / malformed), toolkit and service delegation, and the route with provider forwarding.

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.

@changeset-bot

changeset-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 28029bb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@pkg-pr-new

pkg-pr-new Bot commented Jul 29, 2026

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

commit: 28029bb

@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: 9efa999657

ℹ️ 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/oauth/src/toolkit.ts
Comment thread packages/agent-core-v2/src/app/auth/authService.ts Outdated
@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: b00072d2a2

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

@liruifengv
liruifengv merged commit ea81c9a into main Jul 30, 2026
14 checks passed
@liruifengv
liruifengv deleted the feat/managed-userinfo branch July 30, 2026 07:05
zicochaos added a commit to zicochaos/kimi-code that referenced this pull request Jul 30, 2026
Conflict resolutions (6 files):
- agent-core-v2/docs/state-manifest.d.ts: took upstream, regenerated via gen:state-manifest.
- agent-core/test/harness/runtime.test.ts: kept all 3 added tests (fork stale plugin_session_start disabled-skill case + 2 upstream plugin agent layer cases).
- agent-core-v2/test/agent/loop/loop.test.ts + test/tool/tool.test.ts: tools-hash inline snapshots collided (fork Agent tool exact-alias model param vs upstream MoonshotAI#2379 non-blocking TaskOutput contract); kept fork side, regenerated snapshots from merged behavior — exact-alias model contract preserved.
- agent-core-v2/test/app/config/config.test.ts: kept both import additions (fork PERSIST_DEFAULT_MODEL_SECTION + upstream PROVIDERS_SECTION, atomic config refresh MoonshotAI#2410).
- kap-server/test/skills.test.ts: restartWithDisabledSkills helper now passes TEST_HOST_IDENTITY (upstream made StartServerOptions.hostIdentity required).

Verification:
- agent-core-v2: 4265/4265 pass; gen:state-manifest --check clean.
- kap-server: 927/927 pass.
- agent-core: 4147 pass; 4 failures in test/harness/coder-subagent-tools.test.ts are pre-existing spawn /bin/bash ENOENT on NixOS (not merge-related).
- kimi-code TUI: 2487 pass. typecheck: agent-core, agent-core-v2, kap-server clean.
- lint: 2 errors in packages/oauth/src/managed-userinfo.ts are pre-existing on upstream (no-redundant-type-constituents, MoonshotAI#2363), unchanged by this merge.

Closes the sync tracked in #23.
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