import { z } from 'zod';

export interface Command {
    action: string;
    params: unknown;
    call_id?: number;
    runId?: string;
}
export type AsyncError = {
    message: string;
    code: string;
    category?: string;
};
export type AsyncResponse<T = unknown> = {
    ok: true;
    value: T;
} | {
    ok: false;
    error: AsyncError;
};
export interface ToolDocParam {
    name: string;
    type: string;
    required: boolean;
    description: string;
}
export interface ToolDoc {
    action: string;
    namespace: string;
    description: string;
    params: ToolDocParam[];
    returns: {
        type: string;
        description: string;
    };
    errorCode: string;
    errorCategory?: string;
}
export interface ToolDefinition<P, R> {
    action: string;
    namespace: string;
    description: string;
    params: z.ZodSchema<P>;
    returns: z.ZodSchema<R>;
    handler: (params: P, callId?: number, runId?: string, signal?: AbortSignal) => Promise<R>;
    paramTypes: ToolDocParam[];
    returnType?: string;
    returnDoc: string;
    errorCode: string;
    errorCategory?: string;
}
export type ExecutionContextId = string;
export type CallContext = {
    action: string;
    callId?: number;
    runId?: string;
    signal?: AbortSignal;
};
export type JsCallSpec<P, R> = {
    action: string;
    namespace: string;
    name: string;
    description: string;
    params: z.ZodSchema<P>;
    returns: z.ZodSchema<R>;
    fields?: string[];
    aliases?: Array<{
        namespace: string;
        name: string;
        fields?: string[];
    }>;
    owner: ExecutionContextId;
    handler: (params: P, ctx: CallContext) => Promise<R>;
    errorCode: string;
    errorCategory?: string;
    paramTypes?: ToolDocParam[];
    returnType?: string;
    returnDoc?: string;
};
export type SerializableJsCallManifestEntry = {
    action: string;
    namespace: string;
    name: string;
    publicName: string;
    description: string;
    fields: string[] | null;
    aliases: Array<{
        namespace: string;
        name: string;
        fields: string[] | null;
    }> | null;
    owner: ExecutionContextId;
    paramsDoc: ToolDocParam[];
    returnsDoc: {
        type: string;
        description: string;
    };
    errorCode: string;
    errorCategory?: string;
};
export declare function setRunnerAbortController(controller: AbortController | null): void;
export declare function getRunnerSignal(): AbortSignal | undefined;
export declare function throwIfAborted(): void;
export declare function registerJsCall<P, R>(spec: JsCallSpec<P, R>): void;
export declare function getTool(action: string): ToolDefinition<unknown, unknown> | undefined;
export declare function clearRegistry(): void;
export declare function freezeJsRegistry(): void;
export declare function clearJsRegistry(): void;
export declare function getSerializableJsManifest(): SerializableJsCallManifestEntry[];
/** Convert a serializable manifest entry to the shape expected by WASM registerJsCall/registerJsCallBatch. */
export declare function manifestEntryToWasm(entry: SerializableJsCallManifestEntry): Record<string, unknown>;
/** Rust/WASM often passes BTreeMap params as a JS Map; Zod object schemas need plain objects. */
export declare function coerceWasmParams(params: unknown): unknown;
export declare function dispatchTool(action: string, params: unknown, callId?: number, runId?: string, signal?: AbortSignal): Promise<AsyncResponse>;
export declare function listTools(): ToolDoc[];
