/** * How the AI-credits meter turns the workspace ledger into one `used / limit`. * * ★★ The ledger is the one that is actually charged. `reportAiTokenUsage` * (wspace-vibecontrols-svc) charges through wspace-activity `trackUsage`, which * increments `used` on the workspace's `WorkspaceQuotaAssignment` rows for * `vibecontrols.ai.credits`. The meter used to read global-billing's * `getQuotaUsageAndLimit` instead — a ledger this path never writes, so even * when that query answered, the meter could not move (BOFF-7305). * * ★★ A workspace can hold SEVERAL active rows for this quota. Measured in prod * on 2026-09-15: workspace f423fce9 has four (220000, 220000, 220000, 50000), * and only the oldest carries `used` (912), because `trackUsage` charges the * earliest assignment. This function aggregates them exactly the way the * charge path's pre-flight does — wspace-activity-svc * `WorkspaceQuotaAssignmentService.checkWorkspaceQuota`, which `checkAiCredits` * runs through `@usage(checkQuota: true)`: * * - active rows for the quota, oldest first, at most 100 * (`MAX_ASSIGNMENTS_PER_QUOTA`); * - no row at all → not provisioned (here: null, the meter hides); * - any unlimited row → the whole quota is unlimited (`aggregateQuotaLimit`); * - otherwise limits SUM and `used` SUMS. * * So the meter shows 912 / 710000 for that workspace, which is the same budget * the gate enforces (`checkWorkspaceQuota.limitLeft` = 709088 = 710000 − 912). * Whether those duplicate rows should be summed at all is BOFF-7307. If that * ticket changes the server rule, change this with it — the meter must keep * agreeing with the gate, not with a separate opinion of what the limit is. * * One branch is not mirrored: `checkWorkspaceQuota` prefers a scraped * `WorkspaceQuotaStatus.currentValue` over the summed `used` when one exists. * That gauge comes from the quota scraper, which reads Prometheus collectors * for durational/concurrent quotas, and no VibeControls collector publishes * `vibecontrols.ai.credits` (wspace-vibecontrols-svc * `src/modules/main/metrics/quota-collectors.ts`, origin/main afd6268). So the * gate takes the summed-`used` branch for this quota too, which the prod * numbers above confirm. */ export declare const AI_CREDITS_QUOTA_NAME = "vibecontrols.ai.credits"; /** Mirrors wspace-activity-svc `MAX_ASSIGNMENTS_PER_QUOTA`. */ export declare const MAX_ASSIGNMENTS_PER_QUOTA = 100; /** The assignment fields the meter reads (`GetAiCreditsLedger`). */ export interface AiCreditsLedgerRow { quotaName: string; limit?: number | null; used: number; noLimit: boolean; isActive: boolean; createdAt: string; } export interface AiCreditsQuota { /** AI credits charged since the last reset, across every active row. */ used: number; /** Summed limit in AI credits, or null when the quota is unlimited. */ limit: number | null; noLimit: boolean; } /** * Aggregates the workspace's active `vibecontrols.ai.credits` assignments. * Returns null when there is none — the quota is not provisioned for this * workspace, so there is nothing to meter. */ export declare function summarizeAiCreditsLedger(rows: readonly AiCreditsLedgerRow[], quotaName?: string): AiCreditsQuota | null;