import type { AgentMessage } from "@oh-my-pi/pi-agent-core"; import { type Model, type OpenAIResponsesHistoryPayload, type ServiceTierByFamily } from "@oh-my-pi/pi-ai"; import * as snapcompact from "@oh-my-pi/snapcompact"; import { type CompactionEntry, type CustomMessageEntry, type SessionEntry, type SessionMessageEntry } from "./session-entries.js"; /** Byte budget and frame resolution for one archive's prompt blocks, as context rebuilding applies them. */ export declare function snapcompactHistoryBlockOptions(archive: snapcompact.Archive, options: BuildSessionContextOptions | undefined): snapcompact.HistoryBlockOptions; export interface SessionContext { messages: AgentMessage[]; thinkingLevel?: string; /** Configured thinking selector (`"auto"` or a concrete level) from the latest change. */ configuredThinkingLevel?: string; serviceTier?: ServiceTierByFamily; /** Model roles: { default: "provider/modelId", small: "provider/modelId", ... } */ models: Record; /** Names of TTSR rules that have been injected this session */ injectedTtsrRules: string[]; /** Active mode (e.g. "plan") or "none" if no special mode is active */ mode: string; /** Mode-specific data from the last mode_change entry */ modeData?: Record; /** * Array parallel to messages, indicating which assistant turns should * have their prompt-cache misses suppressed/explained (because a model, * compaction, or plan-mode transition directly preceded them). * Only populated in transcript mode. */ cacheMissExplainedAt?: boolean[]; } /** Lists session model strings to try when restoring, in fallback order. */ export declare function getRestorableSessionModels(models: Readonly>, lastModelChangeRole: string | undefined): string[]; export declare function getLatestCompactionEntry(entries: readonly SessionEntry[]): CompactionEntry | null; export interface BuildSessionContextOptions { /** * Build the display transcript instead of the LLM context. By default this * preserves every path entry with compactions inline; set * `collapseCompactedHistory` for the live TUI surface to render only the * latest compacted tail. */ transcript?: boolean; /** In transcript mode, elide entries replaced by the latest compaction. */ collapseCompactedHistory?: boolean; /** * Tool calls the live agent loop is still executing. They count as paired, so a * mid-turn rebuild keeps the in-flight assistant turn; the loop appends their results. */ inFlightToolCallIds?: ReadonlySet; /** Price and resolve persisted snapcompact frame payloads on demand. */ resolveFrameData?: (data: string) => snapcompact.LazyFrameData | undefined; /** Archive frame bytes the LLM context attaches: the active model's {@link snapcompact.frameDataBytesBudget} * (unset: {@link snapcompact.DEFAULT_FRAME_DATA_BYTES_BUDGET}). */ maxFrameDataBytes?: number; /** * The model that reads this context. A compaction whose provider-native * payload it cannot replay summarizes nothing for it (the stored summary is a * placeholder), so the context stands on the previous boundary it can read * and re-expands the history behind the unreadable one. Ignored for * transcripts. */ model?: Model; } /** Options for `AgentSession.buildTranscriptSessionContext` (via `SessionProviderBoundary`). */ export interface TranscriptSessionContextOptions extends Pick { /** * Keep the unpaired tool calls of the turn the agent loop is still executing, * so a mid-turn rebuild keeps them routable. Calls left unpaired by earlier * turns are stripped either way. Pass while the viewed session streams. */ keepInFlightToolCalls?: boolean; } /** * Display-only marker set on transcript assistant messages whose dangling * `toolCall` blocks were stripped (no paired result on the resolved path — * failed/retried turns, results on sibling branches). The TUI renders a * placeholder row from it so the turn's activity never silently vanishes. */ export interface StrippedToolCallsMarker { strippedToolCalls?: number; } /** Reads validated OpenAI Responses replacement history from a compaction entry. */ export declare function getOpenAiRemoteCompactionPayload(compaction: Pick | null | undefined): OpenAIResponsesHistoryPayload | undefined; /** Session entries that replay as transcript messages: persisted messages and custom messages. */ export type TranscriptEntry = SessionMessageEntry | CustomMessageEntry; export declare function isTranscriptEntry(entry: SessionEntry): entry is TranscriptEntry; /** * The newest compaction on `path` that `model` can read (see * {@link BuildSessionContextOptions.model}), or null when there is none. * Without a model the newest compaction is the boundary. */ export declare function getReadableCompactionEntry(path: readonly SessionEntry[], model: Model | undefined): CompactionEntry | null; export declare function buildSessionContext(entries: SessionEntry[], leafId?: string | null, byId?: Map, options?: BuildSessionContextOptions): SessionContext;