feat(alibaba): read Token Plan quota from the official CLI - #269
feat(alibaba): read Token Plan quota from the official CLI#269lucasrochaqw wants to merge 3 commits into
Conversation
Detected provider ids are canonical, but OpenCode authenticates providers under runtime ids (auth.json keys). Declaring the canonical id while a runtime alias (e.g. alibaba-token-plan) is authenticated left a phantom provider entry next to the real one in the model picker. Resolve the declaration key against authenticated auth.json ids, preferring catalog order (canonical, runtime ids, synonyms), falling back to the canonical id when nothing is authenticated. The already-declared check keeps accepting aliases, so existing fixed configs see no churn.
|
@niheaven Your Team Plan implementation may be complementary. Could you share the branch or PR, including the If the CLI indeed does not expose Team usage, we could consider keeping it as the preferred source for Personal Token Plan and adding an explicit, opt-in cookie-based source for Team Edition. We would need to review cookie storage, expiration, account binding, endpoint stability, and ensure credentials or raw responses are never logged or persisted by the plugin. |
|
@lucasrochaqw Please look at the branch in my fork: It needs an {
"sec_token": "XXXX",
"login_ticket": "XXXX",
"account": ["XXXX"] # optional to filter account
}
This method has been tested on the China endpoint for about three weeks. The international endpoint hasn't been tested yet, though it should work the same way. The tokens are likely valid for several hours, but I haven't verified the exact expiration time. |
|
@niheaven Thanks for sharing the implementation. One useful next step would be to test Would you be interested in opening a PR from your branch? My suggestion would be to keep #269 focused on the CLI integration and coordinate the Team support as a complementary change. @slkiser We should also align provider registration before combining the implementations: #269 treats |
|
So it must use the cookie to extract quota from console now, and the expiration is long enough (maybe six or eight hours) for the method. |
…expires `bl auth status` reports `authenticated: true` from token presence alone, while `bl usage token-plan` fails with exit 3 once the console session lapses. Because availability required an authenticated CLI or a Coding Plan credential, the provider disappeared from every quota surface as "Unavailable (not detected)" with no actionable reason. Treat any Alibaba credential in auth.json (including the alibaba-token-plan runtime id) as a presence signal so the provider stays visible, and surface the CLI's fixed safe message as an error. Timeouts and network faults stay retryable. Presence never grants a Coding Plan request allowance, so the local estimate fallback and its labels are unchanged. Adds alibaba_runtime_auth to the status allowlist to separate configured-but-failing from unconfigured.
|
@niheaven Thanks, that helps confirm the behavior. A couple of notes from my side: After the latest commit (9a4396d), if the CLI probe fails or returns no quota windows, the provider now stays visible with a clear message instead of disappearing. That should make the fallback to a Team-specific source easier to understand. I saw similar behavior with the console session expiring after a few hours while bl auth status still reports the token as present. So documenting the cookie re-auth flow will probably be important. The main open point seems to be provider registration. This PR currently treats alibaba-token-plan as an alias of alibaba-coding-plan, while your branch registers alibaba-token-plan / alibaba-token-plan-cn separately. @slkiser, once you decide which direction you prefer, I can adjust #269 so both implementations coexist cleanly without overlapping. @niheaven, do you prefer to open a separate PR for the Team cookie-based implementation, or would you rather have me use your branch as a reference and integrate that path into #269? |


Summary
Extend the existing Alibaba provider with real Token Plan quota from the official
bailian-cli, retaining the Coding Plan request estimate only as an explicitly distinct fallback.bl usage token-plan --output jsonwith configurable console region/site and binary path. Document the Singapore/international invocation and explicit console login.alibaba-token-planruntime ID and configuration alias while retaining the canonicalalibaba-coding-planprovider ID. No new slash command, model API calls, or token-count approximation.alibaba-cli/local-estimate), never arbitrary subprocess stdout/stderr, error messages, binary paths or console credentials.Linked Issue
Refs #268
The official CLI exposes the console quota source, so the issue's no-endpoint/local-token-estimate alternative is unnecessary here. The CLI contract uses quota fractions; the official console describes its allowance as Credits, not raw token counts. Tests use explicitly synthetic fixtures matching CLI 1.22.0, not captured account data.
Cache and Scope
/quota, status diagnostics, sidebar, compact status, toasts and CLIshowconsume the same rows. The running TUI's configured JSON export can use its own latest snapshot.show --jsonremains cache-only by design. A separate CLI process reports Alibaba asunavailable, and threshold mode returns 2, rather than silently fetching live data or reading another account's snapshot. This also means Coding Plan fallback snapshots are no longer durable for this provider. No JSON schema or public export API changes.blwith console login. Token Plan credentials/traffic are deliberately not relabeled as Coding Plan request allowances.alibaba-token-plan-cnruntime is explicitly out of scope pending validation. Windows.cmd/.batwrappers are not bridged through a shell; a native executable or WSL is required.OpenCode Validation
--console-region ap-southeast-1 --console-site international --output json; it returned weekly-only quota.alibaba_quota_source=alibaba-cli, detected version 1.22.0, and produced the expected remaining percentage/reset conversion. No raw credential/error payloads were printed or committed.show/cache-only JSON, status allowlisting, config validation, cache persistence policy, malformed/no-data responses, missing/auth/network/timeout failures, output bounds and secret sentinel non-disclosure.Quality Checklist
pnpm verifypassed, including typecheck, build, privacy/history, full tests, four-surface parity and package contents.The repository's existing non-fatal Biome warnings, known TypeScript peer mismatch and JSX/SQLite warnings remain visible; no quality gates were weakened.