/** * In-flight turn buffering primitives: the turn event model * (`BufferedTurnEvent`, `InProgressTurn`), replayability gating, turn * snapshots for reconnect replay, and persist-time credit extraction from * the events JSONL. Bodies moved verbatim from `session-stream.ts`. */ import type { InProgressTurnSnapshot, ReplayableTurnEvent, ServerEvent } from "../wire.js"; /** * Extract the `creditsUsed` value from a `token_usage` event embedded in an * events JSONL string. Returns `null` if no `token_usage` event is present * (e.g. it hasn't arrived yet at persist time — the race condition this * column exists to bridge). Best-effort: malformed lines are skipped. */ export declare function extractCreditsFromEventsJsonl(eventsJsonl: string): number | null; /** Per-round timing metrics extractable from a `token_usage` wire event. */ export interface PersistedMessageMetrics { outputTokens: number | null; durationMs: number | null; tokensPerSecond: number | null; ttftMs: number | null; } /** * Extract the per-round timing metrics (`durationMs` / `tokensPerSecond` / * `ttftMs` plus the authoritative `usage.outputTokens`) from a `token_usage` * event embedded in an events JSONL string. Returns `null` if no * `token_usage` event is present at persist time. Best-effort: malformed * lines are skipped. */ export declare function extractMessageMetricsFromEventsJsonl(eventsJsonl: string): PersistedMessageMetrics | null; export type BufferedTurnEvent = Exclude; export interface InProgressTurn { turnId: string; startedAt: number; events: BufferedTurnEvent[]; /** Text accumulated from `text_delta` events in this turn. Used by the * CURRENT message cycle only — reset on `message_start` so * `flushInFlightTurn` persists one message's text per row instead of the * accumulated text of every message cycle in the turn. */ assistantText: string; /** Text accumulated from `text_delta` events across ALL message cycles of * this turn (never reset mid-turn). Used by the loop-done marker check, * which scans the first 500 chars of the turn's response — the marker may * be emitted in an earlier message cycle than the last one. */ turnAssistantText: string; /** Number of leading events already persisted to SQLite. snapshotTurn uses this * to avoid sending already-stored events again on reconnect/refresh. */ persistedEventCount: number; cleanupStarted: boolean; } export declare function isReplayable(event: ServerEvent): event is BufferedTurnEvent; export declare function assistantMessageIdsForTurn(turn: InProgressTurn): Set; export declare function snapshotTurn(turn: InProgressTurn, includePersistedEvents?: boolean): InProgressTurnSnapshot; //# sourceMappingURL=turn-events.d.ts.map