/** * config-cache — Per-database LLM billing configuration cache * * Caches resolved billing function names per database_id. * Uses an LRU cache with TTL so config changes propagate within a bounded window * without requiring a server restart. * * Resolution flow: * Billing config from `metaschema_modules_public.billing_module` * (schema name + function names for record_usage, check_billing_quota) * * All queries run through the Graphile `withPgClient` callback, which gives us * a client connected to the tenant database with proper role settings. * * The LLM module config (provider, model, etc.) is already resolved by the * LlmModulePlugin at schema-build time. This cache handles the runtime-only * billing piece. */ /** * Generic pg client interface matching what Graphile's withPgClient provides. * Avoids a hard dependency on the `pg` package. */ export interface PgClient { query(sql: string, values?: unknown[]): Promise<{ rows: Record[]; }>; } /** * Billing function metadata resolved from the billing_module metaschema table. */ export interface BillingConfig { /** Private schema containing the billing functions */ privateSchema: string; /** Name of the record_usage function */ recordUsageFunction: string; /** Name of the check_billing_quota function */ checkBillingQuotaFunction: string; /** Public schema containing meters table */ publicSchema: string; } /** * Inference log table metadata resolved from the inference_log_module. */ export interface InferenceLogConfig { /** Schema containing the usage_log_inference table */ schema: string; /** Name of the inference log table */ tableName: string; } /** * Per-database cached configuration for the LLM billing integration. */ export interface LlmBillingCacheEntry { /** Billing function references (null if billing_module not provisioned) */ billing: BillingConfig | null; /** Inference log table references (null if inference_log_module not provisioned) */ inferenceLog: InferenceLogConfig | null; } /** * Resolve billing config for a database. * Results are cached per database_id with a 5-minute TTL. * * @param pgClient - A client connected to the tenant database (from withPgClient) * @param databaseId - The database UUID */ export declare function getLlmBillingConfig(pgClient: PgClient, databaseId: string): Promise; /** * Invalidate the cached config for a specific database (or all). */ export declare function invalidateLlmBillingConfig(databaseId?: string): void; /** * Get cache stats for diagnostics. */ export declare function getLlmBillingCacheStats(): { size: number; max: number; };