import type { TurnResult } from '../types/channel.js'; import type { RunContext } from '../types/run-context.js'; export declare const TOKEN_USAGE_STATE_KEY = "__tokenUsage"; export declare const LAST_PROMPT_TOKENS_KEY = "__lastPromptTokens"; /** * Peak prompt size within the CURRENT user turn. * * A flow turn calls `driver.runAgentTurn` once per node, and each call builds a fresh usage * snapshot — so `LAST_PROMPT_TOKENS_KEY` alone records whichever node ran last. On a flow * turn that is typically a small extraction call, which is why a turn that sent 22,226 * tokens reported a context of 2,166. Reset at turn open; maxed on every node. */ export declare const TURN_PEAK_PROMPT_TOKENS_KEY = "__turnPeakPromptTokens"; /** Called when a user turn opens, so the peak measures one turn and not the session. */ export declare function resetTurnPeakPromptTokens(state: Record): void; export declare function readTurnPeakPromptTokens(state: Record): number | undefined; export interface PersistedTokenUsage { inputTokens: number; outputTokens: number; totalTokens: number; cacheReadTokens?: number; cacheWriteTokens?: number; } /** Record real turn usage onto run state (survives across turns via persistence). */ export declare function persistTurnUsageFromTurn(ctx: Pick, turn: Pick): Promise; export declare function readLastPromptTokens(state: Record): number | undefined; /** The session-cumulative usage persisted on run state (or undefined before any turn). */ export declare function readCumulativeUsage(state: Record): PersistedTokenUsage | undefined; export interface TraceTurnUsage { /** Input tokens consumed by THIS turn (cumulative delta since the turn opened). */ inputTokens?: number; /** Output tokens generated by THIS turn (cumulative delta since the turn opened). */ outputTokens?: number; /** Context-window occupancy — the last prompt's token count (not a per-turn delta). */ contextTokens?: number; /** Prompt-cache read tokens for THIS turn (delta). */ cacheReadTokens?: number; /** Prompt-cache write tokens for THIS turn (delta). */ cacheWriteTokens?: number; } /** Per-turn token usage for a trace's `done` event. `baseline` is the cumulative * usage captured when the turn OPENED, so input/output are strictly this turn's * consumption (correct for cost attribution — never the running session total). * `contextTokens` is the current window occupancy, which is inherently a snapshot. */ export declare function computeTurnTraceUsage(baseline: PersistedTokenUsage | undefined, state: Record): TraceTurnUsage;