import { type Database } from "./database.js"; import { type TurnTimingAttempt, type TurnTimingEvent, type TurnTimingProfile } from "./turn-timing-profile.js"; /** The frozen turn dimensions stored next to a profile. */ export type TurnTimingProfileTurn = { id: string; accountId: string; sessionId: string; status: string; model: string; reasoningEffort: string; latencyMode: string; surface: string | null; source: string; createdAt: Date; startedAt: Date | null; finishedAt: Date; }; export type RecordedTurnTimingProfile = { turn: TurnTimingProfileTurn; profile: TurnTimingProfile; /** False when the row already existed and was recomputed. */ inserted: boolean; }; export type TurnTimingProfilePass = { /** Finished turns without a profile that this pass looked at. */ turns: number; /** New profiles written. */ inserted: number; /** Profiles another writer stored first and this pass recomputed. */ updated: number; failed: number; }; /** Load one page of turns' attempts and projected events in two reads. */ export declare function loadTurnTimingInputs(db: Database, workspaceId: string, turns: readonly Pick[]): Promise>; /** * Compute and store the profile of one turn, replacing any earlier one. The * caller supplies the workspace-scoped database. */ export declare function recordTurnTimingProfile(db: Database, workspaceId: string, turn: TurnTimingProfileTurn): Promise; /** * Profile every turn of one workspace that finished in `[since, until)` and * has no profile yet, page by page, each page in its own workspace-scoped * transaction. Idempotent: running it again finds nothing new, and two * replicas racing on a turn write the same row. A turn whose profile cannot be * computed is counted and skipped; the pass moves on. */ export declare function recordMissingTurnTimingProfiles(db: Database, input: { workspaceId: string; since: Date; until: Date; pageSize?: number; signal?: AbortSignal; onError?: (error: unknown, turnId: string) => void; /** Called for each stored profile once its page has committed. */ onRecorded?: (recorded: RecordedTurnTimingProfile) => void; }): Promise;