/**
 * AgentRunTracker — per-run token/cost accounting for agent loops.
 *
 * Lifecycle:
 *   1. start(input)      → INSERT agent_run row with status='running', returns UUID.
 *   2. recordStep(uuid)  → UPDATE increments input/output/tool_calls/cost_usd counters.
 *   3. finish(uuid)      → UPDATE sets finished_at, status, stop_reason.
 *
 * Contract: agent_version is required at start().
 * Cost is NUMERIC(10,6) USD (Postgres returns as string from pg driver — we
 * normalise to string at the boundary).
 *
 * Persistence layer only — no side effects beyond DB. OTel spans are emitted
 * by the caller (loop) with `gen_ai.usage.*` attributes.
 */
/**
 * Minimal injectable Postgres interface.
 * Compatible with `pg.Pool`, `pg.Client`, and test mocks.
 */
export interface DbClient {
    query<T extends object>(sql: string, params?: unknown[]): Promise<{
        rows: T[];
        rowCount?: number;
    }>;
}
export interface AgentRunStartInput {
    agentId: string;
    agentVersion: string;
    /** Caller-generated run id (matches the loop's runId / trace). */
    runId: string;
    model: string;
    provider: string;
    tenantId?: string;
    /** OTel trace id for replay linkage. */
    traceId?: string;
}
export interface AgentRunStepDelta {
    inputTokens: number;
    outputTokens: number;
    toolCalls?: number;
    /**
     * USD delta for this step. Must be >= 0 (cumulative counter).
     * Accepts number or string; normalised to fixed(6) in SQL binding.
     */
    costUsd: number;
}
export type AgentRunFinalStatus = "success" | "failed" | "timeout" | "incoherent";
export interface AgentRunFinish {
    status: AgentRunFinalStatus;
    stopReason?: string;
    errorMessage?: string;
}
export interface AgentRunTracker {
    /** Insert a new row in 'running' status; returns the UUID. */
    start(input: AgentRunStartInput): Promise<string>;
    /** Increment counters atomically. Idempotent per-call (caller dedupes). */
    recordStep(uuid: string, delta: AgentRunStepDelta): Promise<void>;
    /** Terminal transition — sets finished_at + status. */
    finish(uuid: string, result: AgentRunFinish): Promise<void>;
}
/** Factory — inject a DbClient (pg.Pool or test mock). */
export declare function createAgentRunTracker(db: DbClient): AgentRunTracker;
//# sourceMappingURL=agent-run-tracker.d.ts.map