import { type ToolHistoryRepairReport } from '../../compaction/dangling.js'; import { type ServingMember } from '../../provider/fallback.js'; import type { SessionTokenBudget } from '../../store/budget/index.js'; import type { SerializedSpanContext } from '../../telemetry/attributes.js'; import type { TaskScheduler } from '../../types/agent/scheduler.js'; import type { SessionApprovalPolicy } from '../../types/hitl/policy.js'; import type { CheckpointId, MessageId } from '../../types/ids/index.js'; import type { Message } from '../../types/message/index.js'; import type { LLMProvider } from '../../types/provider/index.js'; import type { TurnConfig } from '../../types/session/index.js'; import type { TurnState } from '../../types/session/turn-state.js'; import type { Logger } from '../../utils/logger.js'; import { type TurnContext } from './context.js'; import { EventTranslator } from './events.js'; import type { QueryParams } from './index.js'; import type { PromptCache } from './prompt-cache.js'; import { type SessionStorage } from './session-storage.js'; /** * Everything `query()` needs from its prelude, handed over as one value. * * The prelude is where the turn is DECIDED — what it refuses, which provider * chain serves it, which history it starts from — and it is deliberately * separated from the turn that then executes, because the two answer different * questions and only the second one streams. Nothing here is a bag of mutable * state passed back in: each field is a value the prelude produced and the * body reads afterwards. */ export interface PreparedTurn { readonly turnConfig: TurnConfig; readonly budget: SessionTokenBudget; /** Where the session's log, checkpoints and ledger live. */ readonly storage: SessionStorage; readonly log: Logger; readonly ctx: TurnContext; readonly resilientProvider: LLMProvider; readonly serving: { current: ServingMember; }; readonly providerContextWindow: number | undefined; readonly modelContextWindows: Map; readonly approvalPolicy: SessionApprovalPolicy; readonly eventTranslator: EventTranslator; readonly executeUserInterruptHooks: (terminalError: unknown) => Promise; /** * Repair reports this turn owes its log. * * Created here and KEPT: the turn's resume path pushes one more as it * restores a checkpoint, and the turn emits the whole list once it is * writable. The array identity is part of the contract, not an accident of * the return value being an object. */ readonly pendingHistoryRepairs: PendingHistoryRepairEvent[]; readonly initialMessages: Message[]; /** * The ids of the messages in {@link initialMessages} that the session log * already holds (its folded history); every other initial message is new * and is recorded when the turn begins. */ readonly historyIds: ReadonlyMap; readonly queuedForThisRun: readonly Message[]; readonly selectedResumeState: SelectedResumeState | undefined; readonly attachmentResolutionCancelled: boolean; readonly streamIdleTimeoutMs: number; readonly sandboxTeardownTimeoutMs: number; readonly promptCache: PromptCache | undefined; readonly taskScheduler: TaskScheduler | undefined; } export type SelectedResumeState = TurnState & { readonly checkpointId: CheckpointId; readonly traceContext?: SerializedSpanContext; /** Record ids of `messages` (the fold through the checkpoint), by message. */ readonly messageIds?: ReadonlyMap; }; export declare const selectedResumeStates: WeakMap; /** * Ask the driver what this model's window is, and never let the answer * cost the turn. * * Three outcomes collapse to two here on purpose. No member and a resolved * `undefined` both mean "no answer" — the distinction matters to a driver * author, not to a caller about to fall through to the table. A rejection * is the third, and it is logged rather than propagated: a turn that would * have worked on the table must not fail because a listing endpoint was * down. */ export declare function resolveProviderContextWindow(provider: LLMProvider, model: string | undefined, signal: AbortSignal | undefined, timeoutMs: number, log: Logger): Promise; export interface PendingHistoryRepairEvent { readonly source: 'fresh-history' | 'abandoned-checkpoint'; readonly report: ToolHistoryRepairReport; } /** * Project historical system messages exactly as a new turn will persist them. * * Arbitrary historical prompt floors are rebuilt for this turn and therefore * never reach its provider-bound conversation. Repair must happen AFTER that * removal: treating a soon-to-be-dropped system message as a tool-result * boundary can replace an exact real result with an invented unknown outcome. * The two state-bearing system forms survive; fresh inherited compaction is * pinned until this turn can prove it reconstructed equivalent state. */ export declare function projectStateBearingHistory(messages: readonly Message[], options: { readonly pinCompaction: boolean; }): Message[]; export declare function prepareTurn(params: QueryParams): Promise; //# sourceMappingURL=prepare-turn.d.ts.map