import type { CommandCodeData, WidgetRenderOut, WidgetStats } from '../../lib/contract/types'; /** * dsh-widgets - Command Code account usage shared render layer. * * The eight commandcode widgets (cc-whoami / cc-usage / cc-credits / * cc-windows / cc-subscription / cc-window-5h / cc-window-weekly / * cc-window-monthly) read the host-aggregated `/api/commandcode-usage` * payload (`stats.commandCode`) and render their card shapes here - NOT * copied into each unit - so the family stays consistent. * * Card title convention: the product name is long, so EVERY card titles * itself `Command Code` and puts its role word (account / usage / credits / * window / plan) on the small grey legend line directly under the title. * * Window sources (the four official endpoints): * - 5h / weekly: `billing/credits` -> windowLimits.{fiveHour,weekly} with an * explicit `used` and `cap`; * - monthly: the API serves NO monthly window object, so the month figure is * derived from the one monthly quantity the API DOES report — the remaining * balance: used = plan allowance - credits.monthlyCredits, against the * plan's published allowance. The old `used + remaining` denominator was * not the allowance at all (measured 17.26 + 59.01 = 76.27 on a $70 plan), * which is how the card read 22.6% where the official site read ~16%. * * The payload is fully nullable: the host fetches each endpoint independently, * so one failing endpoint degrades that slice to a placeholder instead of * blanking the whole rail. * * All strings come from each unit's manifest dictionary (family-shared keys * live in `src/widgets/_shared/locales.json`). */ /** Read the commandcode payload defensively: absent / malformed -> null. */ export declare function cc(stats: WidgetStats): CommandCodeData | null; /** Resolve a per-family hint when the payload is missing. The KEY is never * user-entered: the host auto-reads it (env -> $DSH_HOME/.credentials.yaml -> * .env), so the hint below explains the actual failure instead of asking the * user to configure anything. */ export declare function hint(stats: WidgetStats): string; /** The generic (whole-pool) view label. Deliberately the SAME literal in both * languages: the user asked for `AllUser` as the generic expression. */ export declare const CC_ALL = "AllUser"; /** What a Command Code card should currently show. */ export interface CcViewState { /** The payload to render for the CURRENT view (the member's own slices, or the * AllUser aggregate). */ data: CommandCodeData | null; /** The current view's label ('AllUser' or an account name). */ mode: string; /** Every switchable view, in tap order (AllUser first). EMPTY when the host * reported a single pool — the card then renders that account and a tap does * nothing. */ modes: string[]; /** The pool members' labels, for the AllUser account card's bottom line. */ names: string[]; /** True when there is more than one pool to switch between. */ multi: boolean; } /** * Resolve the current pool view and the payload it renders. * * `stats.ccView` is the instance's persisted selection (written by the card's own * tap-to-cycle). An unknown / stale value falls back to AllUser — the pool's * total is always a safe thing to show, and a renamed account must never leave a * card showing another account's numbers under a label it no longer matches. */ export declare function ccView(stats: WidgetStats): CcViewState; /** Tap-to-cycle descriptor for a multi-pool card. The selection persists in the * instance's `ccView` config — deliberately NOT the OpenCode pool's `poolView`, * so the two families never share a view, and naming a `store` also keeps the * tap from firing the multikey `prefer` call (that pool is not this one). */ export declare function cycleFor(view: CcViewState): WidgetRenderOut['cycle']; /** * Does this payload need a second look — a slice that did not answer, or a * period that has already rolled? * * The host route tolerates a failed upstream call by writing `null` for that * slice (deliberate: one dead endpoint must not blank the whole family), and the * browser only re-asks on mount and when a turn settles. A transient 5xx * therefore stayed on screen for the rest of a session: the pool's month lost a * member (or took the conservation fallback) and the 额度管理 card showed a * run-rate built from it — measured live 2026-09-20 as 20.2% / `账期 10-20` / * `今日推荐 59.9M` against a true 16.6% / `账期 10-10` / 645M. The collector asks * ONCE more shortly after seeing this, which is what makes such a state a blip * instead of the session's answer. * * @param c - the payload the route answered with (or null). * @returns true when re-asking shortly is worth one more round trip. */ export declare function ccPayloadDegraded(c: CommandCodeData | null | undefined): boolean; export interface WindowInfo { key: 'fiveHour' | 'weekly' | 'monthly'; label: string; used: number; cap: number; pct: number; resetAt?: number; resetIso?: string; exceeded?: boolean; } /** The 5h window (explicit used/cap from billing/credits). */ export declare function fiveHourWindow(c: CommandCodeData | null): WindowInfo | null; /** The weekly window (explicit used/cap from billing/credits). */ export declare function weeklyWindow(c: CommandCodeData | null): WindowInfo | null; /** * The monthly window of whatever payload this is — one account, or the AllUser * aggregate. * * The pool's month is the SUM of its members' own months (used and allowance * both add), and each member is measured against ITS OWN plan: the plan table is * keyed by plan id, so a two-GOAT pool is 2 × $70, and reading the summed * balance against a single plan's allowance reported 0% for a pool that was 14% * used. A member whose plan id the table does not carry keeps its own * balance-conservation fallback; a member whose slices did NOT answer is a * different story — the whole pool's month is then unknown (null), because a * partial sum reads LOWER than the truth. The reset is the earliest member * period end (the next renewal). * * Exported so widgets that reason ABOUT the month (not just print it) — e.g. * the 额度管理 quota card, which extrapolates the month-end percent — read the * same official-matching figure instead of re-deriving their own. */ export declare function monthlyWindow(c: CommandCodeData | null): WindowInfo | null;