import { type DB } from '../db/client.js'; import type { AICallLogRow } from '../db/schema/ai_call_log.js'; export type CallStatus = 'success' | 'rate_limited' | 'timeout' | 'error' | 'parse_error' | 'skipped_open' | 'skipped_budget'; export type CallField = 'id' | 'task' | 'provider' | 'model' | 'status' | 'httpStatus' | 'latencyMs' | 'tokensIn' | 'tokensOut' | 'estCostMicroUsd' | 'errorKind' | 'errorMessage' | 'tenantId' | 'whatsapp' | 'turnId' | 'createdAt'; export declare const DEFAULT_CALL_LOG_COLUMNS: Readonly>; export interface AICallLedgerOptions { db: D1Database | DB; /** Physical table name. Default `'ai_call_log'`. */ tableName?: string; columnMap?: Partial>; omitColumns?: ReadonlyArray; allowedExtraColumns?: ReadonlyArray; } export interface RecordCallArgs { task: string; provider: string; status: CallStatus; model?: string | null; httpStatus?: number | null; latencyMs?: number | null; tokensIn?: number | null; tokensOut?: number | null; /** Integer micro-USD (1/1_000_000 USD). NULL when unknown. */ estCostMicroUsd?: number | null; errorKind?: string | null; errorMessage?: string | null; tenantId?: string | null; whatsapp?: string | null; /** * Correlate this row to an `AgentLoop.run(...)` invocation (v0.11). * NULL for standalone `AIRouter` calls with no surrounding loop. */ turnId?: string | null; extraColumns?: Record; } export interface ListCallsOptions { task?: string; provider?: string; status?: CallStatus; tenantId?: string; whatsapp?: string; turnId?: string; /** ISO date range (e.g. `'2026-06-19'`). Inclusive. */ since?: string; limit?: number; } export type CallRow = AICallLogRow; export declare class AICallLedger { readonly db: DB; readonly tableName: string; readonly columns: Readonly>; readonly omitColumns: ReadonlySet; readonly allowedExtraColumns: ReadonlySet; constructor({ db, tableName, columnMap, omitColumns, allowedExtraColumns }: AICallLedgerOptions); record(args: RecordCallArgs): Promise; byId(id: string): Promise; list({ task, provider, status, tenantId, whatsapp, turnId, since, limit }?: ListCallsOptions): Promise; countByStatus(status: CallStatus, opts?: { task?: string; tenantId?: string; since?: string; }): Promise; /** * Sum of `est_cost_micro_usd` grouped by provider, filtered by * optional task / tenant / time window. Returns micro-USD integers; * callers divide by 1_000_000 for USD. */ costByProvider(opts?: { task?: string; tenantId?: string; since?: string; }): Promise>; private selectList; } //# sourceMappingURL=ai_call_log.d.ts.map