import type { ToolChildChannel } from "./channel.ts";
import type { PayloadRefReader, PayloadRefWriter } from "./payload-ref.ts";
import type { HostCallKind, ToolChildMessage } from "./protocol.ts";
/** The side's ref writer (payloads it sends) and reader (payloads it receives); absent = inline only. */
export interface HostCallRefs {
    readonly writer: PayloadRefWriter;
    readonly reader: PayloadRefReader;
}
export interface HostCallRequest {
    readonly callId: string;
    readonly jobId: string;
    readonly kind: HostCallKind;
    readonly name: string | undefined;
    readonly args: unknown;
    readonly signal: AbortSignal;
    /** What the job's dispatcher attached to it (the calling tool call, for a session); undefined when none. */
    readonly context: unknown;
    /** The child generation the call came from: whether its job is still live, and when the child's exit is observed. */
    readonly generation: HostCallGeneration;
}
/** What a handler may know about the generation a call came from (file locks are held per generation). */
export interface HostCallGeneration {
    /** Settles once the child that made the call has exited (observed by the server). */
    readonly exited: Promise<void>;
    /** Whether the calling job is still live (the server has not settled it). */
    readonly jobLive: () => boolean;
    /**
     * Settles, with the holder's name, if the calling job becomes stuck: it outlived its deadline and grace and nothing
     * can stop it (an in-process module). Its locks stay held, and every waiter on them fails fast. A child job never
     * gets stuck - its process is killed - so this is unset there.
     */
    readonly stuck?: Promise<string>;
}
/** The generation facts ServerHostCalls hands each request. */
export interface HostCallScope {
    readonly exited: Promise<void>;
    readonly jobLive: (jobId: string) => boolean;
}
export type HostCallHandler = (request: HostCallRequest) => Promise<unknown>;
/** The job context a request carries; ServerHostCalls reads it per call. */
export type HostCallContextOf = (jobId: string) => unknown;
export declare class ServerHostCalls {
    #private;
    constructor(channel: Pick<ToolChildChannel, "send">, handler: HostCallHandler, contextOf?: HostCallContextOf, refs?: HostCallRefs, scope?: HostCallScope);
    /** Calls running and queued for one job (0 for a job with none). */
    load(jobId: string): {
        active: number;
        waiting: number;
    };
    /** Takes a `host_call`; returns false for every other frame. */
    handle(frame: ToolChildMessage): boolean;
    /** The job ended: its running calls are signalled, its queued calls are answered without running. */
    endJob(jobId: string): void;
}
//# sourceMappingURL=host-calls-server.d.ts.map