ExMCP.ACP.Adapters.Pi.RPC (ex_mcp v1.3.0)

Copy Markdown View Source

Pure native RPC protocol helpers for the Pi ACP adapter.

Owns NDJSON envelope construction, command type names, inbound response classification, and request-id correlation shapes. The root adapter retains process ownership, Port I/O, and lifecycle state.

Summary

Types

command()

@type command() :: String.t()

control_entry()

@type control_entry() :: %{
  rpc_id: request_id(),
  kind: control_kind(),
  group_id: String.t()
}

control_kind()

@type control_kind() :: atom()

inbound()

@type inbound() ::
  {:response, request_id(), {:ok, map()}}
  | {:response, request_id(), {:error, map()}}
  | {:event, String.t(), map()}
  | :unknown

request_id()

@type request_id() :: String.t()

Functions

classify_inbound(event)

@spec classify_inbound(term()) :: inbound()

compact(map)

@spec compact(map() | term()) :: map() | term()

control_entry(rpc_id, kind, group_id)

@spec control_entry(request_id(), control_kind(), String.t()) :: control_entry()

decode_line(line)

@spec decode_line(String.t()) :: inbound()

encode_many(messages)

@spec encode_many([map()]) :: binary()

encode_notification(type, fields \\ %{})

@spec encode_notification(String.t(), map()) :: String.t()

encode_request(id, type, fields \\ %{})

@spec encode_request(request_id(), String.t(), map()) :: String.t()

line(message)

@spec line(map()) :: String.t()

method(name)

@spec method(atom()) :: String.t()

methods()

@spec methods() :: %{required(atom()) => String.t()}

next_prompt_id(counter)

@spec next_prompt_id(integer()) :: {request_id(), integer()}

notification(type, fields \\ %{})

@spec notification(String.t(), map()) :: map()

prompt_id(n)

@spec prompt_id(integer()) :: request_id()

request(id, type, fields \\ %{})

@spec request(request_id(), String.t(), map()) :: map()

rpc_id(n)

@spec rpc_id(integer()) :: request_id()