/** * Conversation domain state, tracks the active turn lifecycle, * message buffer, streaming deltas, and tool dispatch state. */ import type { TurnStopReason } from '../../../../events/turn.js'; /** States for the turn lifecycle machine. */ export type TurnState = 'idle' | 'preflight' | 'streaming' | 'tool_dispatch' | 'post_hooks' | 'completed' | 'failed' | 'cancelled'; /** States for the tool execution machine. */ export type ToolExecutionState = 'received' | 'validated' | 'prehooked' | 'permissioned' | 'executing' | 'mapped' | 'posthooked' | 'succeeded' | 'failed' | 'cancelled'; /** A lightweight record of an in-progress or recently completed tool call. */ export interface ActiveToolCall { /** Tool call ID from the provider. */ callId: string; /** Tool name. */ toolName: string; /** Serialized arguments (JSON string). */ args: string; /** Current execution state. */ state: ToolExecutionState; /** Epoch ms when this call entered the current state. */ stateEnteredAt: number; /** Phase timestamps keyed by ToolExecutionState. */ phaseTimestamps: Partial>; /** Error message if state === 'failed'. */ error?: string | undefined; } /** Token usage accumulated for the current or most recent turn. */ export interface TurnUsage { inputTokens: number; outputTokens: number; cacheReadTokens: number; cacheWriteTokens: number; reasoningTokens: number; } /** Streaming progress for the current turn. */ export interface StreamProgress { /** Accumulated text content so far. */ accumulated: string; /** Latest reasoning delta (if any). */ reasoningAccumulated: string; /** Compact preview of the most recent partial tool call streamed so far. */ partialToolPreview?: string | undefined; /** Number of delta events received. */ deltaCount: number; /** Epoch ms of the first delta. */ firstDeltaAt?: number | undefined; /** Epoch ms of the most recent delta. */ lastDeltaAt?: number | undefined; } export interface TurnReconciliationRecord { count: number; callIds: string[]; toolNames: string[]; reason: string; timestamp: number; isMalformed: boolean; } /** * ConversationDomainState, turn lifecycle and streaming state. */ export interface ConversationDomainState { /** Monotonic revision counter; increments on every mutation. */ revision: number; /** Timestamp of last mutation (Date.now()). */ lastUpdatedAt: number; /** Subsystem that triggered the last mutation. */ source: string; /** Current state of the turn lifecycle machine. */ turnState: TurnState; /** Unique ID of the current turn (undefined when idle). */ currentTurnId?: string | undefined; /** Epoch ms when the current turn started (undefined when idle). */ turnStartedAt?: number | undefined; /** Epoch ms when the current turn completed/failed (undefined while active). */ turnEndedAt?: number | undefined; /** Error from the most recent failed turn. */ lastTurnError?: string | undefined; /** Explicit terminal reason for the most recently finished turn. */ lastTurnStopReason?: TurnStopReason | undefined; /** Final assistant response for the most recently completed turn. */ lastTurnResponse?: string | undefined; /** Most recent preflight failure message, if any. */ lastPreflightFailure?: string | undefined; /** Total number of turns completed in this session. */ totalTurns: number; /** Live streaming progress (populated during 'streaming' state). */ stream: StreamProgress; /** Map of callId → ActiveToolCall for all in-flight tool calls. */ activeToolCalls: Map; /** Count of tool calls dispatched in the current turn. */ toolCallsThisTurn: number; /** Most recent reconciliation record for unresolved or malformed tool calls. */ lastToolReconciliation?: TurnReconciliationRecord | undefined; /** Usage for the current or most recent turn. */ currentTurnUsage: TurnUsage; /** Cumulative usage across all turns in this session. */ sessionUsage: TurnUsage; /** Estimated token count of the current context window. */ estimatedContextTokens: number; /** Message count in the current session conversation. */ messageCount: number; } /** * Returns the default initial state for the conversation domain. */ export declare function createInitialConversationState(): ConversationDomainState; //# sourceMappingURL=conversation.d.ts.map