@runloop/agent-axon-client
    Preparing search index...

    Class ACPAxonConnection

    High-level ACP connection backed by an Axon transport.

    Wraps a ClientSideConnection with an axonStream, providing:

    • Proxied ACP agent methods (initialize, prompt, newSession, etc.)
    • Session update listener registration
    • Raw Axon event tapping for debugging
    • Configurable permission handling
    • Lifecycle management (signal, closed, disconnect)

    The underlying ClientSideConnection is accessible via .protocol for advanced use cases (e.g. unstable/experimental ACP methods).

    Index

    ACP Protocol

    • Creates a new ACP connection over the given Axon channel and devbox.

      The constructor does not open an SSE subscription. Call connect to open the transport, then initialize to negotiate protocol capabilities.

      Parameters

      • axon: Axon

        The Axon channel to communicate over (from @runloop/api-client).

      • devbox: Devbox

        The Runloop devbox hosting the ACP agent.

      • Optionaloptions: ACPAxonConnectionOptions

        Optional configuration for error handling, permissions, and lifecycle hooks.

      Returns ACPAxonConnection

    axonId: string

    The Axon channel ID this connection is bound to.

    devboxId: string

    The Runloop devbox ID.

    • get closed(): Promise<void>

      Promise that resolves when the connection closes.

      Returns Promise<void>

      A promise that settles once the protocol connection is fully closed.

    • get protocol(): ClientSideConnection

      The underlying ACP SDK ClientSideConnection.

      Use this for direct access to experimental/unstable protocol methods (e.g. unstable_forkSession, unstable_closeSession). For stable methods, prefer the proxied methods on this class directly.

      Only available after connect has been called.

      Returns ClientSideConnection

    • get signal(): AbortSignal

      AbortSignal that fires when the connection closes.

      Returns AbortSignal

      The underlying protocol's abort signal.

    • Opens the Axon SSE subscription and creates the underlying ClientSideConnection. Must be called before initialize.

      When replay is true (the default), queries the axon for the current head sequence and replays all events up to that point without invoking handlers. Unresolved permission requests are dispatched to handlers after replay completes.

      Returns Promise<void>

      If already connected (code: "already_connected").

      If both replay and afterSequence are set.

    • Aborts the Axon stream, resets protocol state so connect can be called again, and runs the onDisconnect callback (e.g. devbox teardown) if one was provided.

      User-registered listeners (onSessionUpdate, onAxonEvent, onTimelineEvent) are preserved across disconnect/reconnect.

      Returns Promise<void>

      Resolves once the onDisconnect callback (if any) completes.

    • Sends an arbitrary extension request not part of the ACP spec.

      Parameters

      • method: string

        The custom method name.

      • params: Record<string, unknown>

        Arbitrary key-value payload for the request.

      Returns Promise<Record<string, unknown>>

      The agent's response payload.

    • Sends an arbitrary extension notification not part of the ACP spec. Unlike extMethod, notifications do not expect a response.

      Parameters

      • method: string

        The custom method name.

      • params: Record<string, unknown>

        Arbitrary key-value payload for the notification.

      Returns Promise<void>

    • Runs the ACP initialize protocol step (capability negotiation with the agent).

      This is required once after connect on first startup of the agent session: the transport is already open after connect(), but the ACP wire protocol expects initialize before newSession, prompt, or other agent methods.

      Parameters

      • params: InitializeRequest

        Protocol version, client info, and capability negotiation fields.

      Returns Promise<InitializeResponse>

      The agent's supported capabilities and protocol version.

      If the handshake fails (wraps the underlying cause).

    • Registers a listener for every Axon event (before JSON-RPC translation). Useful for debugging, observability, and building event viewers.

      Parameters

      Returns () => void

      An unsubscribe function that removes the listener.

    • Registers a listener for session/update notifications from the agent.

      Parameters

      • listener: SessionUpdateListener

        Callback invoked with the session ID and the update payload each time the agent emits a session update (message chunks, tool calls, etc.).

      Returns () => void

      An unsubscribe function that removes the listener.

    • Registers a listener for classified timeline events (push API).

      Every Axon event on the channel is classified into one of:

      • acp_protocol — a known ACP protocol event (agent or client method)
      • system — a broker system event (turn.started, turn.completed, broker.error)
      • unknown — anything else

      For a pull-based alternative, see receiveTimelineEvents. Both APIs deliver the same events; choose whichever fits your consumption pattern.

      Parameters

      Returns () => void

      An unsubscribe function that removes the listener.

    • Sends a user prompt within a session and processes the agent's turn.

      The returned promise resolves when the agent acknowledges the prompt, but session update notifications (tokens, tool calls, messages) may continue arriving after resolution. Listen via onSessionUpdate to capture the full turn.

      Parameters

      Returns Promise<PromptResponse>

      The agent's prompt acknowledgement.

    • Publishes a custom event to the Axon channel.

      The event will appear in the SSE stream and be classified by the timeline (typically as kind: "unknown" unless the event_type matches a known ACP protocol method).

      Parameters

      • params: AxonPublishParams

        The event to publish (same shape as Axon.publish()).

      Returns Promise<PublishResultView>

      The publish result with sequence number and timestamp.

    • Async generator that yields classified timeline events (pull API).

      Mirrors the pull-based pattern of receiveMessages() in the Claude module. The generator completes when the connection is disconnected or the abort signal fires.

      For a push-based alternative, see onTimelineEvent. Both APIs deliver the same events; choose whichever fits your consumption pattern.

      Returns AsyncGenerator<ACPTimelineEvent, void, undefined>

      An async generator of ACPTimelineEvent.