/** * OpenCode / SuperGrok / DeepSeek quota and prepaid-balance parsers. */ /** A recognized OpenCode provider route, used by /usage and /quota. */ export type OpenCodeFlavor = 'zen' | 'go'; export interface OpenCodeSource { provider: string; flavor: OpenCodeFlavor; label: string; apiKeyEnv: string; baseURL?: string; } export interface LlmPiAiProviderProfile { displayName?: unknown; apiKeyEnv?: unknown; baseURL?: unknown; api?: unknown; models?: unknown; reasoning?: unknown; } export interface LlmPiAiSection { providers?: Record; } /** Build per-model reasoningEfforts from a provider-level reasoning default. */ export declare function reasoningEffortsForDefault(reasoning: unknown): Record | undefined; export declare const OPENCODE_GO_USAGE_URL = "https://opencode.ai/zen/go/v1/usage"; export declare const OPENCODE_ZEN_BASE_URL = "https://opencode.ai/zen/v1"; export declare const SUPERGROK_BILLING_URL = "https://cli-chat-proxy.grok.com/v1/billing?format=credits"; export declare const DEEPSEEK_PUBLIC_BASE_URL = "https://api.deepseek.com"; /** * Command Code's billing surface sits on the API root, not under the * `/provider/v1` route its chat requests use, so these are fixed: a configured * base URL only decides whether the canonical host is the right one to ask. */ export declare const COMMAND_CODE_BASE_URL = "https://api.commandcode.ai"; export declare const COMMAND_CODE_CREDITS_URL = "https://api.commandcode.ai/alpha/billing/credits"; export declare const COMMAND_CODE_SUBSCRIPTIONS_URL = "https://api.commandcode.ai/alpha/billing/subscriptions"; export declare const COMMAND_CODE_USAGE_URL = "https://api.commandcode.ai/alpha/usage/summary"; /** OpenAI-completions gateways: probe these relative to the configured base URL. */ export declare const OPENAI_COMPAT_BALANCE_PATHS: readonly ["/user/balance", "/dashboard/billing/credit_grants", "/v1/dashboard/billing/credit_grants", "/v1/dashboard/billing/subscription"]; /** * Classify the currently selected provider as an OpenCode route. Built-in * `opencode`/`opencode-go` ids are recognized directly, and custom llm-pi-ai * routes are recognized by their `opencode.ai` base URL. */ export declare function openCodeSourceFor(provider: string, llmPiAiSection: unknown): OpenCodeSource | null; /** A recognized Command Code route, used by the quota poller. */ export interface CommandCodeSource { provider: string; apiKeyEnv: string; label: string; } /** * Classify one route as Command Code's quota surface. * * Recognized by provider id or by a canonical base URL. The billing requests * always target the canonical host, so a lookalike base URL never receives the * credential even when the route keeps Command Code's provider id. * @param provider - the selected provider route. * @param llmPiAiSection - the `llm-pi-ai` settings section, if readable. * @returns the credential reference to use, or `null` for another provider. */ export declare function commandCodeSourceFor(provider: string, llmPiAiSection: unknown): CommandCodeSource | null; export type QuotaPeriod = 'hourly' | 'weekly' | 'monthly' | 'unknown'; /** * Which billing surface a snapshot came from. The footer shows a short plan * badge (`SuperGrok` / `OC·GO` / `CC·GOAT`), and the provider string alone is * not enough to tell the three apart. */ export type QuotaSource = 'supergrok' | 'opencode-go' | 'command-code'; export interface QuotaWindow { label: string; period: QuotaPeriod; /** Remaining percent of the window (100 = unused). */ remainingPercent: number; resetsAt?: string; /** Extra human-readable fact beside the percent, e.g. remaining USD credits. */ detail?: string; } export interface QuotaSnapshot { provider: string; plan: string; /** Billing surface, for the footer's short badge. Absent on hand-built snapshots. */ source?: QuotaSource; windows: QuotaWindow[]; } export declare function remainingPercentFromUsed(usedPercent: number): number; /** Cross a remaining-percent threshold from above (50 / 25 / 10 / 5). * Only the tightest (lowest) crossed threshold is returned, so one drop * never paints 50/25/10 as three identical warnings. */ export declare function crossedQuotaThresholds(previousRemaining: number | undefined, remaining: number): number[]; export declare function quotaAlertText(snapshot: QuotaSnapshot, window: QuotaWindow): string; /** * How often to re-fetch quota or prepaid balance, counted in model steps. * Default is every 10 steps. Near a remaining-percent threshold, hourly * windows refresh every 4 steps. */ export declare function quotaRefreshEverySteps(window: QuotaWindow | undefined): number; /** @deprecated Same cadence as {@link quotaRefreshEverySteps}; the name predates step accounting. */ export declare const quotaRefreshEveryTurns: typeof quotaRefreshEverySteps; export declare function parseSuperGrokBilling(payload: unknown): QuotaSnapshot; export declare function parseOpenCodeGoQuota(payload: unknown, provider: string): QuotaSnapshot; /** The billing-period start used to scope the spend query, when reported. */ export declare function commandCodePeriodStart(subscription: unknown): string | undefined; export interface CommandCodeQuotaPayload { /** Required `/alpha/billing/credits` reply. */ credits: unknown; /** Optional `/alpha/billing/subscriptions` reply, for the plan and period. */ subscription?: unknown; /** Optional `/alpha/usage/summary` reply, for period spend. */ summary?: unknown; } /** * Parse Command Code's credits reply into the shared quota snapshot. * * The rolling five-hour and weekly windows report used/cap; the credit pool * reports a remaining USD balance, which becomes a third window whose percent * divides period spend by spend plus remaining balance. * @param payload - the billing replies already fetched. * @param provider - the route the snapshot is labeled with. * @throws Error when no window could be read. */ export declare function parseCommandCodeQuota(payload: CommandCodeQuotaPayload, provider: string): QuotaSnapshot; export declare function formatQuotaSnapshot(snapshot: QuotaSnapshot): string; /** Compact `/status` quota line: tightest window first, then the rest. */ export declare function formatQuotaStatusLine(snapshot: QuotaSnapshot | undefined): string; /** Tightest remaining window — used for threshold alerts. */ export declare function tightestQuotaWindow(snapshot: QuotaSnapshot): QuotaWindow | undefined; /** * The window the footer shows by default: the *finest* one, not the tightest. * * A five-hour cap is what runs out first inside a working session, so it is the * number a glance should find; a monthly window at 12% would otherwise hide a * five-hour window at 3%. Ties (and a provider that reports only one window) * fall back to the lowest remaining percent. */ export declare function preferredQuotaWindow(snapshot: QuotaSnapshot): QuotaWindow | undefined; /** Render the OpenCode Go quota payload as a transcript block. */ export declare function formatOpenCodeGoUsage(payload: unknown, source: OpenCodeSource): string; export interface AccountBalanceLine { label: string; amount: string; currency?: string; } export interface AccountBalanceSnapshot { provider: string; plan: string; available?: boolean; lines: AccountBalanceLine[]; sourcePath?: string; } export declare function joinUrl(base: string, path: string): string; export declare function parseDeepSeekBalance(payload: unknown, provider?: string): AccountBalanceSnapshot; /** Best-effort parse of OpenAI-compatible credit/balance JSON. */ export declare function parseOpenAiCompatibleBalance(payload: unknown, provider: string, path: string): AccountBalanceSnapshot | undefined; /** Compact footer chip: `余额 86.42 CNY`. Prefers remaining/available lines. */ export declare function formatFooterBalance(snapshot: AccountBalanceSnapshot): string | undefined; export declare function formatAccountBalance(snapshot: AccountBalanceSnapshot): string; /** Extract a safe human-readable message from an OpenCode error payload. */ export declare function openCodeApiErrorMessage(payload: unknown): string;