import { type Database } from "./database.js"; /** All amounts are integer USD micros, never dollars or floating-point credits. */ export type MemberAllowanceRule = { share: number; } | { credits: number; } | null; /** * How model calls that spend no Opengeni credits (subscription connections, * workspace keys, deployments without credit billing) count. "ignore" (the * default) keeps the allowance credit-only; "list_price" counts them at the * configured list-price estimate and admits their turns against it. */ export type UnbilledUsageMetering = "ignore" | "list_price"; export type WorkspaceAllowanceConfig = { includedCredits: number; period: "monthly" | "none"; anchorDay?: number; memberDefault?: "none" | "equal_share" | Exclude; thresholds?: { workspace?: number[]; member?: number[]; }; unbilledUsage?: UnbilledUsageMetering; }; export type WorkspaceAllowance = WorkspaceAllowanceConfig & { version: number; }; export type WorkspaceAllowanceState = { version: number; config: WorkspaceAllowance | null; }; export type AllowanceStatus = "ok" | "warning" | "exhausted"; export type AllowanceUsage = { limit: number | null; used: number; remaining: number | null; fraction: number | null; status: AllowanceStatus; resetsAt: string | null; }; export type MemberAllowance = { subjectId: string; rule: MemberAllowanceRule; version: number; }; export type WorkspaceUsage = { /** Every amount is an integer USD micro: 1 USD = 1,000,000. */ unit: "usd_micros"; /** The window the counters cover, configured or not; null when unknown or lifetime. */ period: { start: string | null; end: string | null; }; workspace: AllowanceUsage & { includedCredits: number; grantsRemaining: number; }; members: (AllowanceUsage & MemberAllowance & { externalIdentity: { source: string; externalId: string; } | null; })[]; nextCursor: string | null; }; export type AllowanceExhausted = { code: "allowance_exhausted"; scope: "workspace" | "member"; resetsAt: string | null; subjectId?: string; message: string; }; type Scope = { accountId: string; workspaceId: string; }; type Actor = { actorSubjectId: string; actorType?: string | undefined; }; export declare class UsageAllowanceVersionConflictError extends Error { constructor(); } export declare function validateMemberAllowanceRule(rule: MemberAllowanceRule): void; export declare function validateWorkspaceAllowanceConfig(config: WorkspaceAllowanceConfig): void; export declare function getWorkspaceAllowance(db: Database, input: Scope): Promise; /** Includes the lifecycle revision even when no configuration exists. */ export declare function getWorkspaceAllowanceState(db: Database, input: Scope): Promise; export declare function setWorkspaceAllowance(db: Database, input: Scope & Actor & WorkspaceAllowanceConfig & { expectedVersion: number; }): Promise; export declare function clearWorkspaceAllowance(db: Database, input: Scope & Actor & { expectedVersion: number; operationId?: string; }): Promise<{ version: number; }>; export declare function grantWorkspaceCredits(db: Database, input: Scope & Actor & { operationId: string; credits: number; expiresAt?: string | null; }): Promise<{ operationId: string; credits: number; remaining: number; expiresAt: string | null; }>; export declare function setMemberAllowance(db: Database, input: Scope & Actor & { rule: MemberAllowanceRule; expectedVersion: number; } & ({ subjectId: string; externalIdentity?: never; } | { externalIdentity: { source: string; externalId: string; }; subjectId?: never; })): Promise; export declare function allowanceUsage(limit: number | null, used: number, resetsAt: string | null, thresholds?: number[]): AllowanceUsage; export declare function getWorkspaceUsage(db: Database, input: Scope & { period?: "current" | string; limit?: number; cursor?: string | null; subjectId?: string; }): Promise; export declare function checkWorkspaceAllowance(db: Database, input: Scope & { subjectId?: string | null; /** * The work spends no Opengeni credits. It is admitted against the allowance * only when the allowance opts into `unbilledUsage: "list_price"`. */ fundedWithoutCredits?: boolean; }): Promise; /** Bounded periodic work, independent of reads/admission and webhook delivery. */ export declare function maintainWorkspaceAllowances(db: Database, input?: { limit?: number; memberLimit?: number; }): Promise; export {};