feat(kap-server): expose the managed-account profile at GET /oauth/userinfo - #2363
Conversation
|
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". |
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.
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.