/** * Turn a session's buffered opencode messages + parts into ReconstructedTurn[]. * * Segmentation: * - A turn opens at each user message and runs until the next user message * (or the end of the buffer). * - Each assistant message in the turn → one `chat` (model round-trip): its * text/reasoning parts are the output, its tool parts are that chat's tool * refs, and its `tokens` are that call's usage. (This is message-level, not * per-API-call, granularity — see reconstruct.test.ts and the README caveat.) * - Each tool part → one `execute_tool`, paired input→output within the part's * own `state`, timestamped from `state.time`. * * A turn is only considered *complete* (safe to export) when its last assistant * message has a `time.completed` — mirroring weave-codex waiting for * `task_complete`. Incomplete turns are returned with `complete: false` so the * caller can hold them for the next `session.idle`. */ import type { ReconstructedTurn } from '../model.js'; import { type OcMessage, type OcPart } from './types.js'; /** A reconstructed turn plus whether it looked fully flushed. */ export interface CandidateTurn { turn: ReconstructedTurn; complete: boolean; /** The message ids that composed this turn, so the caller can prune them once emitted. */ messageIds: string[]; } /** Everything buffered for one session, as the plugin accumulates it. */ export interface SessionSnapshot { sessionId: string; parentSessionId?: string; messages: OcMessage[]; /** partsByMessage[messageId] = parts for that message (any order). */ partsByMessage: Map; } export declare function reconstructSession(snap: SessionSnapshot): CandidateTurn[];