Raxol.AgentClientProtocol.Rpc.Message (Raxol Agent Client Protocol v0.1.0)

Copy Markdown View Source

Wraps a Request, Notification, or Response with the required "jsonrpc": "2.0" field, and decodes a raw wire frame into whichever of the three it turns out to be.

decode/1 is TOTAL:

  • malformed JSON (the bytes don't parse at all) -> {:error, :parse_error}
  • well-formed JSON that isn't a valid JSON-RPC 2.0 frame (wrong jsonrpc version, not an object, or missing the fields needed to classify it as a Request/Response/Notification) -> {:error, :invalid_request} (or the more specific {:error, :invalid_jsonrpc_version} when the jsonrpc field is present but not "2.0")

It never raises.

Ported from the MIT f1729/agent_client_protocol (c) 2025 f1729; see NOTICE.md.

Summary

Functions

Decode a JSON string into the inner Request, Notification, or Response. See moduledoc.

Encode to a JSON string (newline-delimited framing is the transport's concern).

Types

inner()

t()

@type t() :: %Raxol.AgentClientProtocol.Rpc.Message{message: inner()}

Functions

decode(json_string)

@spec decode(term()) ::
  {:ok,
   Raxol.AgentClientProtocol.Rpc.Request.t()
   | Raxol.AgentClientProtocol.Rpc.Notification.t()
   | Raxol.AgentClientProtocol.Rpc.Response.t()}
  | {:error, :parse_error | :invalid_request | :invalid_jsonrpc_version}

Decode a JSON string into the inner Request, Notification, or Response. See moduledoc.

encode!(msg)

@spec encode!(t()) :: String.t()

Encode to a JSON string (newline-delimited framing is the transport's concern).

to_json(message)

@spec to_json(t()) :: map()

wrap(message)

@spec wrap(inner()) :: t()