feat(kap-server): expose the managed-account profile at GET /oauth/userinfo - #2363
feat(kap-server): expose the managed-account profile at GET /oauth/userinfo#2363liruifengv wants to merge 3 commits into
Conversation
🦋 Changeset detectedLatest commit: b00072d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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: 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".
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ 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". |
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/usageis the existing precedent — but there is no endpoint for the account profile.What changed
Adds
GET /api/v1/oauth/userinfo, mirroring the/oauth/usagechain end to end:@moonshot-ai/kimi-code-oauth— newmanaged-userinfo.ts:kimiCodeUserInfoUrl()(the cloud path stays/me, owned by the backend; only the local naming is "userinfo"), a tolerantparseManagedUserInfoPayload(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.getManagedUserInfo+AuthManagedUserInfoResult(alias ofManagedUserInfoResult), reusingensureFreshso expired tokens are refreshed before the call.IOAuthService.getManagedUserInfo/IOAuthToolkit.getManagedUserInfocontracts and theOAuthServiceimplementation (same runtime-auth resolution path as usage);oauthProtocol.tsre-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.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
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.