Skip to content

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

Open
liruifengv wants to merge 3 commits into
mainfrom
feat/managed-userinfo
Open

feat(kap-server): expose the managed-account profile at GET /oauth/userinfo#2363
liruifengv wants to merge 3 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

🦋 Changeset detected

Latest commit: b00072d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Minor

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 Jul 29, 2026

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

commit: b00072d

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

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