Skip to content

feat(oauth): return structured managed usage rows - #2300

Merged
liruifengv merged 3 commits into
mainfrom
feat/structured-managed-usage
Jul 28, 2026
Merged

feat(oauth): return structured managed usage rows#2300
liruifengv merged 3 commits into
mainfrom
feat/structured-managed-usage

Conversation

@liruifengv

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue — the problem is explained below.

Problem

GET /api/v1/oauth/usage returned server-formatted English strings (label: "5h limit", reset_hint: "resets in 5d 12h 57m") instead of data. Every client that wanted to localize or reformat had to reverse-parse those strings with regexes — the web/desktop settings card did exactly that, and any unrecognized label fell through as raw English. Formatting policy was also frozen server-side, so clients could not adapt it (e.g. the 5-hour window arrives from the platform as 300 MINUTE and was stringified as "5h limit" with no way to render it differently).

What changed

The oauth parser keeps absorbing backend field drift (numeric strings, used/remaining, four reset-time spellings, proto-style time units) but now emits a stable structured row, which kap-server passes through and clients localize themselves:

  • UsageRow{ name?, window?{ duration, unit }, used, limit, resetAt? } (wire: snake_case reset_at)
  • window: normalized from duration/timeUnit to minute|hour|day|week; whole-hour minute windows fold to hours (300 MINUTE5h); an unnamed summary row is the plan's weekly limit and gets { 1, week } (parity with the previous hardcoded "Weekly limit" fallback)
  • resetAt: absolute ISO timestamp; relative reset_in/ttl seconds are converted at parse time so clients never deal with relative math
  • Deleted limitLabel / resetHintFrom / formatResetTime; formatDuration stays exported for the TUI
  • TUI /usage panel formats labels and reset hints locally (English), same rendered output as before
  • Booster wallet (extra_usage) was already structured and is untouched

Wire compatibility: label/reset_hint are removed from the REST DTO — breaking for old clients, accepted since the desktop renderer and its embedded server ship together and the web UI is deployed in lockstep.

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 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9bbc504

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

This PR includes changesets to release 3 packages
Name Type
@moonshot-ai/kimi-code-oauth Patch
@moonshot-ai/agent-core-v2 Patch
@moonshot-ai/kap-server 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 Jul 28, 2026

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

commit: 9bbc504

Stop formatting plan-usage labels and reset hints into English strings
at the oauth layer. The parser still absorbs backend field drift, but
now emits a stable structured row (name / window{duration,unit} / used
/ limit / resetAt) that kap-server passes through and clients localize
themselves:

- window: normalized from duration/timeUnit (minute/hour/day/week),
  whole-hour minute windows fold to hours, unnamed summaries are the
  weekly limit
- resetAt: absolute ISO timestamp; relative reset_in/ttl seconds are
  converted at parse time
- TUI /usage panel formats labels and reset hints locally
@liruifengv
liruifengv force-pushed the feat/structured-managed-usage branch from d66d18c to 884a5ff Compare July 28, 2026 06:26

@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: d66d18ca19

ℹ️ 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/managed-usage.ts Outdated
Comment thread apps/kimi-code/src/tui/components/messages/usage-panel.ts
…shape

Drop the defensive drift tolerance (alternate reset-time spellings,
reset_in/ttl seconds, remaining-derived used, title/scope names,
top-level duration/timeUnit, fuzzy time-unit matching) and parse only
what the platform actually sends: numeric strings, resetTime, nested
detail/window records, TIME_UNIT_* enums.
@liruifengv
liruifengv merged commit b0f43ae into main Jul 28, 2026
14 checks passed
@liruifengv
liruifengv deleted the feat/structured-managed-usage branch July 28, 2026 07:03
@github-actions github-actions Bot mentioned this pull request Jul 28, 2026
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Aug 15, 2026
* feat(oauth): return structured managed usage rows

Stop formatting plan-usage labels and reset hints into English strings
at the oauth layer. The parser still absorbs backend field drift, but
now emits a stable structured row (name / window{duration,unit} / used
/ limit / resetAt) that kap-server passes through and clients localize
themselves:

- window: normalized from duration/timeUnit (minute/hour/day/week),
  whole-hour minute windows fold to hours, unnamed summaries are the
  weekly limit
- resetAt: absolute ISO timestamp; relative reset_in/ttl seconds are
  converted at parse time
- TUI /usage panel formats labels and reset hints locally

* refactor(oauth): parse managed usage strictly to the current payload shape

Drop the defensive drift tolerance (alternate reset-time spellings,
reset_in/ttl seconds, remaining-derived used, title/scope names,
top-level duration/timeUnit, fuzzy time-unit matching) and parse only
what the platform actually sends: numeric strings, resetTime, nested
detail/window records, TIME_UNIT_* enums.

* fix(node-sdk): update managed usage smoke example and facade tests for structured rows
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