import type { RpcObservationScope } from "./subagent-rpc.ts"; import type { Attachment, BrokerMessage, DeliveryDetails, Message, SessionInfo } from "../extensions/pi-intercom/types.ts"; /** Dedicated same-process bridge. These channels are not externally callable RPC bus operations. */ export declare const INTERCOM_RPC_REQUEST_EVENT = "intercom:rpc-request"; export declare const INTERCOM_RPC_RESULT_EVENT = "intercom:rpc-result"; export declare const INTERCOM_RPC_EVENT = "intercom:rpc-event"; export declare const INTERCOM_RPC_ASK_TIMEOUT_MS = 600000; export interface IntercomRpcMessageOptions { message: string; attachments?: Attachment[]; replyTo?: string; } export type IntercomRpcCommand = { id?: string; type: "intercom_status"; } | { id?: string; type: "intercom_list"; } | { id?: string; type: "intercom_pending"; } | ({ id?: string; type: "intercom_send"; to: string; } & IntercomRpcMessageOptions) | ({ id?: string; type: "intercom_ask"; to: string; timeoutMs?: number; } & IntercomRpcMessageOptions) | ({ id?: string; type: "intercom_reply"; to?: string; } & IntercomRpcMessageOptions); export interface IntercomRpcStatus { scope: RpcObservationScope; enabled: boolean; connected: boolean; sessionId: string | null; name?: string; } export interface IntercomRpcDelivery extends DeliveryDetails { messageId: string; delivered: boolean; reason?: string; to: string; replyTo?: string; } export interface IntercomRpcDataMap { intercom_status: IntercomRpcStatus; intercom_list: { sessionId: string; sessions: SessionInfo[]; }; intercom_pending: { asks: Array<{ from: SessionInfo; message: Message; receivedAt: number; }>; }; intercom_send: IntercomRpcDelivery; intercom_reply: IntercomRpcDelivery; intercom_ask: IntercomRpcDelivery & { reply: Message; }; } export type IntercomRpcResponse = { [K in keyof IntercomRpcDataMap]: { id?: string; type: "response"; command: K; success: true; data: IntercomRpcDataMap[K]; }; }[keyof IntercomRpcDataMap]; export type IntercomRpcEvent = IntercomRpcEventData & { scope: RpcObservationScope; }; /** Internal event data; the stdio host adds its own binding scope. */ export type IntercomRpcEventData = { type: "intercom_connection"; enabled: boolean; connected: boolean; sessionId: string | null; reason?: string; } | { type: "intercom_message"; from: SessionInfo; message: Message; } | { type: "intercom_presence"; session: SessionInfo; } | { type: "intercom_session_joined"; session: SessionInfo; } | { type: "intercom_session_left"; sessionId: string; } | { type: "intercom_receipt"; from: SessionInfo; receipt: Extract["receipt"]; } | { type: "intercom_delivery"; result: Extract; }; export interface IntercomRpcRequest { requestId: string; command: IntercomRpcCommand; signal: AbortSignal; /** Synchronous acknowledgement allows the host to fail promptly if the extension is missing. */ accept(): void; } export type IntercomRpcResult = { requestId: string; } & ({ success: true; data: IntercomRpcDataMap[keyof IntercomRpcDataMap] | Omit; } | { success: false; error: string; }); export declare function intercomRpcTimeout(command: IntercomRpcCommand): number; export interface IntercomRpcEventEnvelope { sessionId: string | null; event: IntercomRpcEventData; } /** Fail closed before forwarding extension-bus payloads to a host client. */ export declare function isIntercomRpcEvent(value: unknown): value is IntercomRpcEventData;