import { type SecretInputUnavailableReason } from "../../core/extensions/secret-input.ts";
import type { ExtensionUIInputOptions } from "../../core/extensions/types.ts";
import type { SealedSecretOffer } from "./secret-sealed-holders.ts";
import { type ExtensionUiResponseReply } from "./extension-ui-response.ts";
export type SecretInputOutcome = "answered" | "cancelled" | "timed_out" | "unavailable";
export interface SecretInputRoute {
    select(id: string, unavailable: () => void): SecretInputUnavailableReason | undefined;
    accepts(id: string): boolean;
    available(id: string): boolean;
    presenter(id: string): string | undefined;
    send(id: string, record: object): void;
    settled(id: string): void;
    forget(id: string): void;
    handshake?(capabilities: readonly string[]): void;
    /** The request has sealed holders (D11 secret phase 5.2); only an in-process route can. */
    sealed?(id: string): boolean;
    /** Signs the request for its sealed holders and sends it to each (4.3). */
    offerSealed?(id: string, offer: Omit<SealedSecretOffer, "uiRequestId">): void;
    /** Sends every sealed holder the value-free settle; `winner` is the grant whose answer won, if any (7.2). */
    sealedOutcome?(id: string, outcome: SecretInputOutcome, winnerGrant: string | undefined): void;
    /** Whether the request has a raiser route; a worker's `accepts` needs it (5.5). */
    raiser?(id: string): boolean;
    /** Registers this session's latch for sealed answers (7.1 steps 3 and 6). */
    bindSealedResponder?(latch: SealedLatch | undefined): void;
}
/**
 * A sealed answer the host authenticated (design 7.1 steps 1, 2, 4 and 5). Plain data, so it crosses into a worker
 * isolate unchanged (5.5); the latch owner runs steps 3 and 6 on it.
 */
export interface SealedAnswer {
    readonly uiRequestId: string;
    readonly principal: string;
    readonly grantId: string;
    readonly answerId: string;
    readonly req: string;
    /** Absent for a cancel. `jti` and `exp` come from the verified step-up token. */
    readonly value?: {
        readonly jti: string;
        readonly exp: number;
        readonly enc: string;
        readonly ct: string;
    };
}
/** What the latch owner checks at the claim: the grant (in-process only; 5.5) and the step-up `jti` cache. */
export interface SealedClaim {
    current(): boolean;
    admitJti(jti: string, exp: number): boolean;
}
export type SealedAnswerReply = {
    readonly disposition: "applied" | "replay";
} | {
    readonly error: "already_answered" | "unknown_extension_ui_request" | "secret_stepup_refused" | "invalid_secret_response" | "secret_answer_refused";
};
/** What a route's sealed answers reach at the session's latch. */
export interface SealedLatch {
    /** 7.1 step 3 for a request that is no longer pending; `undefined` while it is. */
    settled(uiRequestId: string, answerId: string, principal: string): SealedAnswerReply | undefined;
    respond(answer: SealedAnswer, claim: SealedClaim): SealedAnswerReply | Promise<SealedAnswerReply>;
}
/** Private, live-only state. Never registered in progress, snapshot, transcript or answer-ledger maps. */
export declare class SecretInputRequests {
    private readonly route;
    private readonly admit;
    private readonly pending;
    private readonly receipts;
    constructor(route: SecretInputRoute, admit: () => void);
    /** `created` receives the request id once the prompt is pending, for a local answer through `answerLocal`. */
    input(title: string, placeholder: string | undefined, opts?: ExtensionUIInputOptions, created?: (id: string) => void): Promise<string | undefined>;
    /** Generates the request key off the host loop, then offers the request to its sealed holders if it is still open. */
    private offerSealed;
    has(id: string): boolean;
    answered(): {
        uiRequestId: string;
        answerId: string;
    }[];
    respond(frame: Record<string, unknown>): ExtensionUiResponseReply;
    /**
     * Design 7.1 steps 3 and 6 at the latch, synchronously: a settled request answers `replay` or `already_answered`
     * from its receipt before the step-up token is consumed; then the claim re-checks the request, the deadline and the
     * grant, and only then opens the ciphertext. A losing answer is never decrypted.
     */
    respondSealed(answer: SealedAnswer, claim: SealedClaim): SealedAnswerReply;
    /** 7.1 step 3: `replay` for the same answer id and principal, else `already_answered`; no receipt is unknown. */
    private receipt;
    /**
     * The terminal's own answer to a prompt it also offered to sealed holders (D11 S3-6b parity): the same latch, so the
     * first answer wins. The terminal's component admits its own human answer, so this does not.
     */
    answerLocal(id: string, value: string | undefined): void;
    cancelAll(outcome?: SecretInputOutcome): void;
    recheck(): void;
    /** Final teardown: also releases the sealed latch, so the route no longer keeps this request set alive. */
    dispose(): void;
    /** Ends every prompt; the latch stays bound because the connection reuses this set on every rebind. */
    close(): void;
    private remember;
}
//# sourceMappingURL=secret-input-requests.d.ts.map