import { QueryClient } from '@tanstack/react-query'; import { ApolloClient } from '@burdenoff/fe-libs/shared/graphql'; import { GetAiCreditsLedgerQuery } from '../generated/wspace-operations'; import { AiCreditsQuota } from '../utils/aiCreditsLedger'; export type { AiCreditsQuota } from '../utils/aiCreditsLedger'; /** Prefix of every workspace's meter query; the charge event invalidates all of them. */ export declare const AI_CREDITS_QUERY_KEY: readonly ["vibecontrols", "ai-credits-quota"]; /** One read of the workspace ledger, as the Apollo result reports it. */ export interface AiCreditsLedgerResult { data?: GetAiCreditsLedgerQuery | null; error?: unknown; } export type ReadAiCreditsLedger = (workspaceId: string) => Promise; /** * Reads the meter's `used / limit` from the ledger `reportAiTokenUsage` charges. * * Null — the meter hides — when there is no workspace, when the read errors * (FORBIDDEN, a gateway 500, a network failure), or when the workspace has no * active `vibecontrols.ai.credits` assignment. A failed read must never render * a number: "0 used" would read as "nothing spent" when the truth is "unknown". */ export declare function readAiCreditsQuota(workspaceId: string, readLedger: ReadAiCreditsLedger): Promise; /** * The ledger read over the wspace gateway client. `errorPolicy: 'all'` makes a * GraphQL error come back as `result.error` instead of a rejection, and * `readAiCreditsQuota` hides the meter on either. */ export declare function wspaceLedgerReader(client: ApolloClient): ReadAiCreditsLedger; /** * React Query options for the meter. The workspace is part of the key, so a * workspace switch never shows the previous workspace's balance; the query is * disabled until there is both a wspace client and a workspace. */ export declare function aiCreditsQueryOptions(client: ApolloClient | null, workspaceId: string): { queryKey: readonly ["vibecontrols", "ai-credits-quota", string]; enabled: boolean; staleTime: number; queryFn: () => Promise; }; /** * Refetches every meter query whenever an assistant turn charges credits * (AI_CREDITS_UPDATED_EVENT). Returns the unsubscribe function. */ export declare function refetchOnAiCreditsUpdated(target: EventTarget, queryClient: QueryClient): () => void; /** * Live AI-credits usage for the active workspace. * * ★★ Reads wspace-activity `workspaceQuotaAssignments` — the rows * `reportAiTokenUsage` increments via `trackUsage` and the `checkAiCredits` * pre-flight enforces against. It used to read global-billing * `getQuotaUsageAndLimit`, which nothing on the charge path writes, and which * answered INTERNAL_SERVER_ERROR in prod, so the meter never showed (BOFF-7305). * Multiple active rows are summed the way the pre-flight sums them; see * `summarizeAiCreditsLedger`. * * The workspace is the one the assistant sends turns to (`getWorkspaceId`). */ export declare function useAiCreditsQuota(): { data: AiCreditsQuota | null; loading: boolean; };