Skip to content

fix(api): parse zh-locale usage labels and reset phrases - #2

Open
waknow wants to merge 1 commit into
v587d:mainfrom
waknow:fix/zh-locale-parsing
Open

fix(api): parse zh-locale usage labels and reset phrases#2
waknow wants to merge 1 commit into
v587d:mainfrom
waknow:fix/zh-locale-parsing

Conversation

@waknow

@waknow waknow commented Aug 17, 2026

Copy link
Copy Markdown

Problem

The opencode.ai dashboard renders the usage page in the UI locale negotiated from the cookie. With oc_locale=zh the data-slot=usage-label values come back as Chinese (rolling/weekly/monthly usage in Chinese) and the reset phrase as Chinese instead of Resets in.

The SSR scraper in src/api.ts only recognizes the English labels and the English reset phrase, so with a zh-locale cookie:

  1. labelToKind matches nothing -> all three windows are dropped
  2. fromSSRHTML returns an empty result
  3. fetchViaCookie treats empty page as a login redirect and throws UsageError('Usage page parsed empty (cookie expired or invalid?)', 'http302')

Net effect: the chip shows err:http302 even though the cookie is perfectly valid.

Fix

  • labelToKind: also recognize the Chinese labels
  • reset-time regex: accept both Resets in and the Chinese phrase prefix
  • parseDurationToSec: accept Chinese time units, including the counter for 1 month

Also rebuilt lib/ (the checked-in build output) so GitHub/npm installs work without a local build.

Tests

  • New zh-locale SSR fixture exercising all three windows with Chinese labels and reset phrases
  • New zh duration cases in the parseDurationToSec table

All 48 tests pass (pnpm test), typecheck and build pass.

The opencode.ai dashboard renders usage labels in the UI locale. For a
cookie with oc_locale=zh the labels are Chinese (rolling/weekly/monthly
usage) and the reset phrase is '重置于' instead of 'Resets in', so the
SSR scrape parsed every window as empty and the chip showed <err:http302>
(cookie expired or invalid?) despite the cookie being valid.

- labelToKind: recognize the Chinese labels
- reset-time regex: accept both 'Resets in' and '重置于'
- parseDurationToSec: accept Chinese time units (秒/分钟/小时/天/周/月/年)

Adds a zh-locale SSR fixture and zh unit tests.
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