import type { DeliverHookPayload, DeliverPayload } from "#channel/types.js"; export type SessionControl = "clear" | "compact" | "expired" | "reset"; export interface DeliveryAdmission { readonly delivery: DeliverHookPayload; readonly sequence: number; } export interface TurnSelection { readonly delivery: DeliverHookPayload; /** * True only for a lone, callerless conversational delivery that arrived * while nothing else was pending. Such a delivery may move the session to * the deployment that accepted it. */ readonly handoffEligible: boolean; readonly kind: "turn"; /** Sequences of every admission folded into this turn. */ readonly sequences: readonly number[]; } export type SessionInputSelection = TurnSelection | { readonly control: SessionControl; readonly kind: "control"; }; /** * Ordered, admitted session input. Entries are private; callers receive typed * admission and selection values. Everything here is rebuilt deterministically * on replay. */ export declare class SessionInputQueue { private readonly entries; private nextSequence; get pendingCount(): number; enqueueDelivery(delivery: DeliverHookPayload): DeliveryAdmission; enqueueControl(control: SessionControl): void; /** Keeps one payload per authorization attempt; a repeated callback for the same attempt is dropped. */ enqueueAuthorization(payloads: readonly DeliverPayload[]): void; /** * Removes and returns the queued callbacks for `attemptIds` once every one * has arrived, so a turn holding several sign-ins resumes when all are done. */ takeAuthorizations(attemptIds: ReadonlySet): DeliverPayload[] | undefined; delivery(sequence: number): DeliverHookPayload | undefined; replaceDelivery(sequence: number, delivery: DeliverHookPayload | undefined): void; takeSteering(admitted: ReadonlySet, turn: SteeringTurn, options?: SteeringOptions): TurnSelection | undefined; /** * Takes the next turn or control. Sign-ins end with the turn that raised * them, so a callback still queued between turns is stale and dropped. */ takeNext(options?: { /** Sequence of a delivery admitted while nothing else was pending. */ readonly freshSequence?: number; }): SessionInputSelection | undefined; /** * Consecutive deliveries of one authenticated principal and one delegated * call share a turn, as they would steer it. Claims may change between * them; the turn runs with the latest. */ private takeFollowingDeliveriesFrom; private retain; } /** The running turn a delivery may steer. */ export interface SteeringTurn { /** The call id of the delegated caller the turn answers, if any. */ readonly callerCallId: string | undefined; readonly principal: string; } export interface SteeringOptions { /** * The turn waits on its own person for a sign-in or approval. Their message * steers even with `turnPolicy: "queue"`: queued, it would wait for a turn * that cannot end until they act. */ readonly heldOnPerson?: boolean; } /** * Only the turn's own principal steers it; another principal's message waits * for the turn to end. A delivery without auth acts as the session's current * identity, which is the turn's. */ export declare function isSteeringDelivery(delivery: DeliverHookPayload, turn: SteeringTurn, options?: SteeringOptions): boolean; /** A steering delivery with a message for the model, not only answers to requests. */ export declare function isSteeringMessage(delivery: DeliverHookPayload, turn: SteeringTurn): boolean;