import type { QueuedInputPort } from "@earendil-works/pi-agent-core";
import type { ImageContent } from "@earendil-works/pi-ai";
import { SessionPendingInputJournal } from "./pending-input-journal.ts";
import type { PendingInputProjection } from "./pending-input-projection.ts";
import { type PendingInputJournal } from "./pending-input-store.ts";
import type { PendingInputMode, PendingInputOperationResult } from "./pending-input-types.ts";
import type { SessionManager } from "./session-manager.ts";
export interface IdentifiedInput {
    readonly clientMessageId: string;
    readonly text: string;
    readonly images?: readonly ImageContent[];
    readonly mode: PendingInputMode;
}
export interface SessionPendingInputsOptions {
    readonly sessionManager: ConstructorParameters<typeof SessionPendingInputJournal>[0] & Pick<SessionManager, "reduceHistory">;
    /** The session's own queue-id counter, so a store handle and the session's queued record share one id. */
    readonly nextQueuedId: () => string;
    /** Receives every committed change, in cursor order. */
    readonly onChange?: (update: PendingInputUpdate) => void;
    /** Defaults to the session JSONL; injectable so tests can fail an append. */
    readonly journal?: PendingInputJournal;
}
export interface PendingInputUpdate {
    readonly lifetimeId: string;
    readonly cursor: number;
    readonly changes: readonly PendingInputProjection[];
}
/** Every input that still needs an outcome, plus an explicit answer for each id the caller already knows. */
export interface PendingInputSnapshot {
    readonly lifetimeId: string;
    readonly throughCursor: number;
    readonly inputs: readonly PendingInputProjection[];
    readonly outcomes: readonly ({
        readonly clientMessageId: string;
        readonly status: "admitted";
        readonly projection: PendingInputProjection;
    } | {
        readonly clientMessageId: string;
        readonly status: "not_admitted";
    })[];
}
/** The legacy answers of `dequeue_message` / `edit_queued_message`. */
export type QueuedInputChangeOutcome = "removed" | "edited" | "already_delivered" | "not_found" | "conflict";
export interface QueuedInputChangeRequest {
    readonly clientMessageId: string;
    /** Undefined removes the input; a string replaces its text. */
    readonly text: string | undefined;
    readonly expectedRevision?: number;
    readonly effectId?: string;
}
export declare class ClientMessageIdConflictError extends Error {
    readonly code = "client_message_id_conflict";
    readonly clientMessageId: string;
    constructor(clientMessageId: string);
}
/**
 * The pending inputs of one AgentSession (senpi#3549): the store, opened on the first identified input, and the
 * agent queue port over it. Input without a client id never touches the store and keeps the legacy queue path.
 */
export declare class SessionPendingInputs {
    readonly lifetimeId: `${string}-${string}-${string}-${string}-${string}`;
    private readonly options;
    private storeOpening;
    private port;
    private attempts;
    /** Bumped synchronously by every clear, so a change can tell a clear it raced from a real divergence. */
    private clears;
    constructor(options: SessionPendingInputsOptions);
    /**
     * How a restored input (from the RPC admission ledger after a reopen) re-enters the native queue: under the
     * store's rebound queue id while it is still queued; not at all once the store retired it (delivered, removed,
     * failed); `undefined` when the store never held it, so the caller restores it as before.
     */
    restoreHandle(clientMessageId: string): Promise<{
        readonly queuedId: string;
    } | "retired" | undefined>;
    /**
     * Admits an identified input and, only when it is newly admitted, puts its native copy in the agent queue
     * inside the same gated step, so no drain, edit or removal can run between the two. A repeated submit of the
     * same input is answered from the record (`replayed`) and enqueues nothing.
     */
    /**
     * `refusal` is read before the input is recorded (a refusal there records nothing) and again in the same synchronous
     * step as `enqueue`. A turn that ended while the record was written makes the second read refuse: the record is
     * cancelled `turn_conflict`, which a later submit under the same id replaces, and the refusal is thrown.
     */
    admit(input: IdentifiedInput, enqueue: (queuedId: string) => void, refusal?: () => Error | undefined): Promise<PendingInputOperationResult | undefined>;
    /**
     * Edits or removes an identified input: the store transition is journaled first, and only when it answers
     * `edited`/`removed` does `applyNative` change the native queue, inside the same gated step, so no drain
     * can see one without the other. Returns undefined when the store never admitted this input.
     */
    change(request: QueuedInputChangeRequest, applyNative: () => QueuedInputChangeOutcome): Promise<QueuedInputChangeOutcome | undefined>;
    /**
     * Records an explicit clear (Stop, `clear_queue`, unload with clearQueue) of identified inputs that just left the
     * native queue: each still-queued one is removed by `stop`, so a reopen never queues it again.
     */
    recordCleared(clientMessageIds: readonly string[]): Promise<void>;
    /**
     * Pending inputs (queued, sending, failed) and the outcome of each known id, consistent through
     * `throughCursor`: apply it, then only updates with a later cursor. Absence from `inputs` is never an outcome.
     */
    snapshot(knownClientMessageIds?: readonly string[]): Promise<PendingInputSnapshot>;
    /** The agent's queue port. Before the store opens nothing identified is queued, so it drains natively. */
    queuedInputPort(): QueuedInputPort;
    private store;
    private openPort;
}
/** The store changed an input that the native queue no longer held: the two views disagree and must not be hidden. */
export declare class PendingInputDivergenceError extends Error {
    readonly code = "pending_input_divergence";
    constructor(clientMessageId: string, recorded: string, native: string);
}
//# sourceMappingURL=pending-input-session.d.ts.map