/**
 * Which hand runs a headless session's tools (R4; the DK2a engine half). A hand directory says which hands this engine
 * can reach, and the user's choice is recorded per session, so it survives a restart. A chosen hand runs every tool
 * call of that session through a remote ToolHost. A chosen hand that cannot run them makes the calls fail as error
 * results; nothing falls back to this process. Choosing `null` gives the session back its own ToolHost (the fused
 * path, untouched).
 */
import { type Agent, type HandPlacement, type ToolHost, type Transport } from "@earendil-works/pi-agent-core";
import type { PromptSurface } from "../../core/dynamic-prompt/build.ts";
import type { SessionManager } from "../../core/session-manager.ts";
export interface HandRow {
    readonly device: string;
    readonly label: string;
    readonly platform: string;
    /** Listed but with no carrier up: it can be shown, not chosen. */
    readonly reachable: boolean;
}
/**
 * Where hands come from: the device service in production, an in-process link in tests. `link` is called only for a
 * listed, reachable hand, once per session that chooses it, and returns a transport of its own for that session: the
 * selection closes it when the session leaves the hand or ends, which never touches another session on the same hand.
 */
export interface HandDirectory {
    readonly list: () => readonly HandRow[];
    readonly link: (device: string) => {
        readonly transport: Transport;
        readonly placement: HandPlacement;
    };
}
/** The session-file entry that records a session's choice; `device: null` is local. */
export declare const HAND_SELECTION_ENTRY = "hand_selection";
export type HandRefusal = "hand_not_listed" | "hand_unreachable" | "session_busy";
export interface HandSession {
    readonly agent: Pick<Agent, "toolHost" | "subscribe">;
    /** A run copies its ToolHost when it starts, so the choice changes only between runs. */
    readonly isStreaming: boolean;
    readonly sessionManager: Pick<SessionManager, "appendCustomEntry" | "getEntries">;
    /** Sent with each call to the hand, so a tool there reports what this session's host does (senpi#6921). */
    readonly promptSurface: PromptSurface;
}
export interface HandSelection {
    readonly hands: () => readonly HandRow[];
    /** The recorded hand of a session (by durable id), `null` when local. */
    readonly selected: (durableSessionId: string) => string | null;
    readonly select: (durableSessionId: string, session: HandSession, device: string | null) => {
        readonly ok: true;
    } | {
        readonly ok: false;
        readonly refusal: HandRefusal;
    };
    /**
     * Starts tracking a session that just opened and re-applies the choice its file recorded; a hand that cannot be
     * linked now fails the session's calls. Nothing from an earlier runtime of the same id is kept.
     */
    readonly restore: (durableSessionId: string, session: HandSession) => void;
    /** Forgets a session that ended and closes its link to the hand. */
    readonly release: (durableSessionId: string) => void;
}
export interface HandSelectionOptions {
    /** Wraps every host the selection installs (the presence gate on a headless engine with presence). */
    readonly gate?: (durableSessionId: string, host: ToolHost) => ToolHost;
    /** Called after a session's hand changes, with the device or `null` for local. */
    readonly onChange?: (durableSessionId: string, device: string | null) => void;
    /** Called when a session ends and its hand state is forgotten. */
    readonly onRelease?: (durableSessionId: string) => void;
}
export declare function createHandSelection(directory: HandDirectory, options?: HandSelectionOptions): HandSelection;
//# sourceMappingURL=hand-selection.d.ts.map