ACP.Connection (agent_client_protocol v0.1.0)

Copy Markdown View Source

GenServer managing a bidirectional JSON-RPC 2.0 connection over IO streams.

Handles line-delimited JSON over stdin/stdout (or any IO streams). Manages request/response correlation and message routing via a Side module.

Summary

Functions

Returns a specification to start this module under a supervisor.

Send a notification (no response expected).

Send a request and wait for a response.

Send a response to a received request.

Start a connection GenServer.

Stop the connection.

Subscribe to stream messages. Returns a reference.

Types

t()

@type t() :: %ACP.Connection{
  handler_module: term(),
  handler_state: term(),
  input_port: term(),
  next_id: term(),
  output_io: term(),
  pending_responses: term(),
  side_module: term(),
  subscribers: term()
}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

notify(conn, method, params)

Send a notification (no response expected).

request(conn, method, params, timeout \\ 30000)

Send a request and wait for a response.

respond(conn, id, result)

Send a response to a received request.

start_link(opts)

Start a connection GenServer.

Options:

  • :side - The side module (ACP.ClientSide or ACP.AgentSide)
  • :handler - Module implementing ACP.MessageHandler
  • :handler_state - State passed to handler callbacks
  • :input - Input IO device or port (default: :stdio)
  • :output - Output IO device (default: :stdio)
  • :name - Optional GenServer name

stop(conn)

Stop the connection.

subscribe(conn)

Subscribe to stream messages. Returns a reference.