Agentic.Protocol.ACP.Types
(agentic v0.2.2)
Copy Markdown
ACP (Agent Client Protocol) type definitions and conversions.
Defines the core types from the ACP specification and provides conversion functions between ACP wire format and Agentic internal format.
Wire format uses string keys (ACP is JSON-based). Agentic internal format uses atom keys in structs.
Reference: https://agentclientprotocol.com/protocol/schema.md
Summary
Functions
Builds a JSON-RPC error response.
Builds a JSON-RPC notification message (no id, no response expected).
Builds a JSON-RPC request message.
Builds a JSON-RPC success response.
Extracts text content from an ACP ContentBlock.
Converts Agentic messages to ACP ContentBlock[] format.
Returns true if the JSON-RPC message is a notification (no id).
Parses a JSON string into a JSON-RPC message.
Parses a permission kind string from ACP wire format to atom.
Parses a session update type string to atom.
Parses a stop reason string from ACP wire format to atom.
Parses a tool kind string from ACP wire format to atom.
Parses a tool status string from ACP wire format to atom.
Returns true if the JSON-RPC message is a request (has id and method).
Returns true if the JSON-RPC message is a response (has id and result/error).
Converts an ACP tool_call_update to Agentic pending_tool_call format.
Types
@type agent_capabilities() :: map()
@type client_capabilities() :: map()
@type permission_kind() :: :allow_once | :allow_always | :reject_once | :reject_always
@type protocol_version() :: pos_integer()
@type request_id() :: pos_integer()
@type session_id() :: String.t()
@type session_update_type() ::
:agent_message_chunk
| :user_message_chunk
| :tool_call
| :tool_call_update
| :plan
| :available_commands_update
| :config_option_update
| :current_mode_update
@type stop_reason() ::
:end_turn | :max_tokens | :max_turn_requests | :refusal | :cancelled
@type tool_kind() ::
:read
| :edit
| :delete
| :move
| :search
| :execute
| :think
| :fetch
| :other
@type tool_status() :: :pending | :in_progress | :completed | :failed
Functions
@spec build_error(request_id(), integer(), String.t(), term()) :: map()
Builds a JSON-RPC error response.
Builds a JSON-RPC notification message (no id, no response expected).
@spec build_request(request_id(), String.t(), map()) :: map()
Builds a JSON-RPC request message.
@spec build_response(request_id(), term()) :: map()
Builds a JSON-RPC success response.
@spec content_block_to_text(content_block()) :: String.t()
Extracts text content from an ACP ContentBlock.
Returns the text string or empty string if not a text block.
@spec messages_to_content_blocks([map()]) :: [content_block()]
Converts Agentic messages to ACP ContentBlock[] format.
Agentic messages use %{"role" => ..., "content" => ...} with string keys.
ACP prompts use ContentBlock[] with type, text, etc.
@spec notification?(json_rpc_message()) :: boolean()
Returns true if the JSON-RPC message is a notification (no id).
@spec parse_message(String.t()) :: {:ok, json_rpc_message()} | {:error, term()}
Parses a JSON string into a JSON-RPC message.
@spec parse_permission_kind(String.t()) :: permission_kind()
Parses a permission kind string from ACP wire format to atom.
@spec parse_session_update_type(String.t()) :: session_update_type()
Parses a session update type string to atom.
@spec parse_stop_reason(String.t()) :: stop_reason()
Parses a stop reason string from ACP wire format to atom.
Parses a tool kind string from ACP wire format to atom.
@spec parse_tool_status(String.t()) :: tool_status()
Parses a tool status string from ACP wire format to atom.
@spec request?(json_rpc_message()) :: boolean()
Returns true if the JSON-RPC message is a request (has id and method).
@spec response?(json_rpc_message()) :: boolean()
Returns true if the JSON-RPC message is a response (has id and result/error).
@spec tool_call_to_agentic(tool_call_update()) :: map()
Converts an ACP tool_call_update to Agentic pending_tool_call format.