import { EventEmitter } from "node:events"; import type { AwaitStagedDeliveryResponse, SelfSettleUndispatchedResponse } from "../broker/ipc-server.js"; import type { NetworkPresence } from "../broker/network-presence.js"; import type { RuntimeProcessingState, RuntimeWorkTargetRef } from "../broker/runtime-processing-state-event-types.js"; import type { UndispatchedMessage } from "../broker/undispatched-inbox.js"; import { type InitializeResponseBody, type IpcCapabilities } from "../broker/version-handshake.js"; import type { EndpointBackgroundExchangeMode, EndpointExecutionSurface, RuntimeAssignmentFailureCategory, RuntimeConversationRef, RuntimeEndpointCapability, RuntimeSessionConversationHistoryResponse, SessionNamingBlock, WorkspaceMetadata } from "../runtime-endpoint-client.js"; export declare class ConnectorUnavailableError extends Error { readonly code: "connector_unavailable"; readonly retryable: true; constructor(message: string); } export declare class ConnectorSendOutcomeUnknownError extends Error { readonly code: "connector_send_outcome_unknown"; readonly retryable: false; constructor(message: string); } export declare class RuntimeAssignmentReplyHandleStaleError extends Error { readonly code: "reply_handle_stale"; readonly brokerCode: string; readonly retryable: false; constructor(message: string, brokerCode?: string); } export declare class RuntimeAssignmentProcessingStateError extends Error { readonly code: "runtime_processing_state_rejected"; readonly brokerCode: string; readonly assignmentFailureCategory: RuntimeAssignmentFailureCategory; readonly retryable: false; constructor(message: string, assignmentFailureCategory: RuntimeAssignmentFailureCategory, brokerCode?: string); } export interface BrokerClientDiscoverOptions { accountId: string; runtimeToken: string; userDataDir?: string; env?: Record; timeoutMs?: number; brokerEntry?: string; nodeBinary?: string; } export interface BrokerClientConnectOptions { pluginPid: number; clientKind: string; clientVersion: string; heartbeatIntervalMs?: number; heartbeatTimeoutMs?: number; heartbeatMissesBeforeDisconnect?: number; reconnectBackoffInitialMs?: number; reconnectBackoffMaxMs?: number; } export interface RegisterEndpointArgs { agentId: string; kind: string; sessionName?: string; workspace?: string | WorkspaceMetadata; trackingRef?: string; taskHint?: string; runtimeSessionId?: string; runtimeCapabilities?: RuntimeEndpointCapability[]; executionSurface?: EndpointExecutionSurface; backgroundExchangeMode?: EndpointBackgroundExchangeMode; spawnToken?: string; } export interface RegisterEndpointOutcome { endpoint_id: string; endpoint_owner_token?: string; session_naming?: SessionNamingBlock; } export interface BrokerInboundMessage { from: string; content: string; contentType: string; metadata?: Record; sourceMessageId?: string; runtimeAssignment?: BrokerRuntimeAssignmentContext; } export interface BrokerRuntimeAssignmentContext { undispatchedId: string; sourceMessageId: string; assignmentId: string; targetRef: RuntimeWorkTargetRef; deliveryIntent: "external_handoff"; replyCorrelationId?: string; originalTraceId?: string; } export interface SendRuntimeAssignmentReplyArgs { endpointId: string; sourceMessageId: string; assignmentId: string; replyRequestId: string; content: string; contentType?: string; metadata?: Record; } export interface ClaimRuntimeAssignmentArgs { endpointId: string; undispatchedId: string; recoverExisting?: boolean; assignmentMode?: "staged"; } export interface ClaimRuntimeAssignmentResponse { assignment: BrokerRuntimeAssignmentContext; message: { from: string; content: string; contentType: string; metadata: Record; sourceMessageId?: string; }; } export interface UndispatchedPresence { bound_continuation_count: number; } export interface ReadRuntimeConversationHistoryArgs { endpointId: string; conversationRef: RuntimeConversationRef; limit?: number; before?: string; after?: string; } export interface SelfSettleUndispatchedArgs { plugin_pid: number; endpoint_id: string; undispatched_id: string; } export interface SelfSettleRejected { error: string; message: string; } export type SelfSettleUndispatchedResult = SelfSettleUndispatchedResponse | SelfSettleRejected; export interface AwaitStagedDeliveryArgs { plugin_pid: number; endpoint_id: string; timeout_ms: number; mark_attempt?: boolean; } export type { UndispatchedMessage }; export type { RuntimeConversationRef, RuntimeSessionConversationHistoryResponse, }; export type AdapterRuntimeProcessingState = Exclude; export interface ReportRuntimeProcessingStateArgs { endpointId: string; sourceMessageId: string; assignmentId: string; stateEventId: string; stateSequence: number; state: AdapterRuntimeProcessingState; occurredAt?: number; undispatchedId?: string; retryable?: boolean; reasonCode?: string; detail?: string; replyRequestId?: string; outboundMessageId?: string; } export type BrokerConnectionPhase = "never_connected" | "connected" | "reconnecting"; export interface BrokerConnectionState { phase: BrokerConnectionPhase; lastFailureReason: string | null; since: number; } type Events = { message_received: (msg: BrokerInboundMessage) => void; connectionstate: (state: BrokerConnectionState) => void; presence: (presence: NetworkPresence, reason?: string) => void; disconnected: () => void; error: (err: Error) => void; }; export declare class BrokerClient extends EventEmitter { private handle; private readonly discoverOptions; private ws; private autoRecoverEnabled; private connectOptions; private _phase; private _lastFailureReason; private _phaseSince; private hasEverConnected; private reconnectTimer; private reconnectBackoffMs; private reconnectBackoffInitialMs; private reconnectBackoffMaxMs; private reconnectInFlight; private reconnectWakeupPending; private heartbeatInterval; private heartbeatTimeout; private heartbeatMisses; private heartbeatTimeoutMs; private heartbeatMissesBeforeDisconnect; private pluginPid; private _sessionId; private _networkPresence; private _serverCapabilities; private _serverVersion; private _clientKind; private _clientVersion; private readonly endpointOwnerTokens; private readonly endpointAliases; private readonly endpointRegistrations; private constructor(); static discover(opts: BrokerClientDiscoverOptions): Promise; get spawnedNew(): boolean; get ipcUrl(): string; get sessionId(): string | null; get networkPresence(): NetworkPresence | null; get serverCapabilities(): Readonly; get serverVersion(): string | null; get connectionState(): BrokerConnectionState; private setPhase; private emitConnectionState; private static describeFailure; connect(opts: BrokerClientConnectOptions): Promise; private connectOnce; registerEndpoint(args: RegisterEndpointArgs): Promise; private registerEndpointOnCurrentBroker; send(endpointId: string, to: string, content: string, contentType?: string, metadata?: Record): Promise<{ messageId: string; status: string; }>; sendRuntimeAssignmentReply(args: SendRuntimeAssignmentReplyArgs): Promise<{ messageId: string; status: string; }>; claimRuntimeAssignment(args: ClaimRuntimeAssignmentArgs): Promise; listUndispatched(args?: { endpointId?: string; }): Promise; readUndispatchedPresence(args: { endpointId: string; }): Promise; selfSettleUndispatched(args: SelfSettleUndispatchedArgs): Promise; awaitStagedDelivery(args: AwaitStagedDeliveryArgs): Promise; readRuntimeConversationHistory(args: ReadRuntimeConversationHistoryArgs): Promise; reportRuntimeProcessingState(args: ReportRuntimeProcessingStateArgs): Promise; close(endpointId?: string): Promise; unregisterEndpoint(endpointId: string): Promise; private forgetEndpointLocally; on(event: K, listener: Events[K]): this; on(event: string | symbol, listener: (...args: unknown[]) => void): this; once(event: K, listener: Events[K]): this; once(event: string | symbol, listener: (...args: unknown[]) => void): this; off(event: K, listener: Events[K]): this; off(event: string | symbol, listener: (...args: unknown[]) => void): this; emit(event: K, ...args: Parameters): boolean; emit(event: string | symbol, ...args: unknown[]): boolean; private httpJson; private onConnectSuccess; private scheduleReconnect; private runReconnectAttempt; private teardownWsForRecovery; private reregisterCachedEndpoints; private resolveEndpointId; private requireEndpointOwnerToken; private emitErrorIfObserved; private handleFrame; private sendPushAck; private startHeartbeat; private sendHeartbeatProbe; private markHeartbeatAlive; private clearHeartbeat; } //# sourceMappingURL=broker-client.d.ts.map