import type { AgentSession } from "@mariozechner/pi-coding-agent"; import type { ClientMessage, ServerMessage } from "../protocol/types.js"; /** * Abstraction over the Noise-encrypted transport. * Wave 3 plugs the real channel; tests use a mock. */ export interface PeerChannel { send(msg: ServerMessage): void; } /** * Minimal subset of BeforeToolCallContext consumed by the bridge. * Shape-compatible with @mariozechner/pi-agent-core BeforeToolCallContext. */ export interface BridgeToolCallContext { toolCall: { toolCallId: string; toolCall: { name: string; arguments: Record; }; }; args: unknown; } /** * Bridges an AgentSession (Pi SDK) and a PeerChannel (remote app). * * Wire-up at session creation: * const bridge = new AgentBridge(session, channel) * // pass bridge.beforeToolCallHook to createAgentSession as beforeToolCall * * Then route incoming client messages: * channel.on('message', msg => bridge.onClientMessage(msg)) */ export declare class AgentBridge { private readonly session; private readonly channel; /** ID of the active user_message turn, used as in_reply_to for streaming. */ private currentTurnId; /** Pending tool approvals keyed by tool_call_id. */ private readonly pendingApprovals; private readonly unsubscribe; constructor(session: AgentSession, channel: PeerChannel); /** * Pass this as `beforeToolCall` in createAgentSession options. * Auto-approves whitelisted tools; pauses everything else for user approval. */ readonly beforeToolCallHook: (ctx: BridgeToolCallContext, signal?: AbortSignal) => Promise<{ block?: boolean; reason?: string; } | undefined>; onClientMessage(msg: ClientMessage): void; dispose(): void; private awaitApproval; private onSessionEvent; }