ACPex.Client behaviour (ACPex v0.1.0)
View SourceBehaviour for implementing an ACP client (typically a code editor).
A client is responsible for:
- Managing the connection to an agent
- Handling session updates from the agent
- Responding to agent requests for file system and terminal operations
Type-Safe API
All callbacks use strongly-typed structs from the ACPex.Schema.*
modules,
providing compile-time validation and better documentation.
Example
defmodule MyEditor do
@behaviour ACPex.Client
def init(_args), do: {:ok, %{files: %{}}}
def handle_session_update(notification, state) do
# Display update in UI
{:noreply, state}
end
def handle_fs_read_text_file(request, state) do
case File.read(request.path) do
{:ok, content} ->
response = %ACPex.Schema.Client.FsReadTextFileResponse{
content: content
}
{:ok, response, state}
{:error, _} ->
{:error, %{code: -32001, message: "File not found"}, state}
end
end
# ... other callbacks
end
Summary
Callbacks
Handle a request from the agent to read a text file.
Handle a request from the agent to write a text file.
Handle a session update notification from the agent.
Handle a request from the agent to create a terminal.
Handle a request from the agent to kill a terminal command.
Handle a request from the agent to get terminal output.
Handle a request from the agent to release a terminal.
Handle a request from the agent to wait for terminal exit.
Initialize the client with the given arguments.
Types
Callbacks
@callback handle_fs_read_text_file(ACPex.Schema.Client.FsReadTextFileRequest.t(), state()) :: {:ok, ACPex.Schema.Client.FsReadTextFileResponse.t(), state()} | {:error, error_response(), state()}
Handle a request from the agent to read a text file.
Parameters
request
- AFsReadTextFileRequest
struct with the file pathstate
- Current client state
Returns
{:ok, response, new_state}
where response is aFsReadTextFileResponse
struct{:error, error_map, new_state}
if file cannot be read
@callback handle_fs_write_text_file( ACPex.Schema.Client.FsWriteTextFileRequest.t(), state() ) :: {:ok, ACPex.Schema.Client.FsWriteTextFileResponse.t(), state()} | {:error, error_response(), state()}
Handle a request from the agent to write a text file.
Parameters
request
- AFsWriteTextFileRequest
struct with path and contentstate
- Current client state
Returns
{:ok, response, new_state}
where response is aFsWriteTextFileResponse
struct{:error, error_map, new_state}
if file cannot be written
@callback handle_session_update(ACPex.Schema.Session.UpdateNotification.t(), state()) :: {:noreply, state()}
Handle a session update notification from the agent.
These are streaming updates during prompt processing (thoughts, message chunks, tool calls, etc).
Parameters
notification
- AnUpdateNotification
struct with session_id and update datastate
- Current client state
Returns
{:noreply, new_state}
- Notifications don't send responses
@callback handle_terminal_create(ACPex.Schema.Client.Terminal.CreateRequest.t(), state()) :: {:ok, ACPex.Schema.Client.Terminal.CreateResponse.t(), state()} | {:error, error_response(), state()}
Handle a request from the agent to create a terminal.
Parameters
request
- ACreateRequest
struct with terminal configurationstate
- Current client state
Returns
{:ok, response, new_state}
where response is aCreateResponse
struct with terminal_id{:error, error_map, new_state}
if terminal cannot be created
@callback handle_terminal_kill(ACPex.Schema.Client.Terminal.KillRequest.t(), state()) :: {:ok, ACPex.Schema.Client.Terminal.KillResponse.t(), state()} | {:error, error_response(), state()}
Handle a request from the agent to kill a terminal command.
Parameters
request
- AKillRequest
struct with terminal_idstate
- Current client state
Returns
{:ok, response, new_state}
where response is aKillResponse
struct{:error, error_map, new_state}
if terminal not found
@callback handle_terminal_output(ACPex.Schema.Client.Terminal.OutputRequest.t(), state()) :: {:ok, ACPex.Schema.Client.Terminal.OutputResponse.t(), state()} | {:error, error_response(), state()}
Handle a request from the agent to get terminal output.
Parameters
request
- AnOutputRequest
struct with terminal_idstate
- Current client state
Returns
{:ok, response, new_state}
where response is anOutputResponse
struct with output data{:error, error_map, new_state}
if terminal not found
@callback handle_terminal_release( ACPex.Schema.Client.Terminal.ReleaseRequest.t(), state() ) :: {:ok, ACPex.Schema.Client.Terminal.ReleaseResponse.t(), state()} | {:error, error_response(), state()}
Handle a request from the agent to release a terminal.
Parameters
request
- AReleaseRequest
struct with terminal_idstate
- Current client state
Returns
{:ok, response, new_state}
where response is aReleaseResponse
struct{:error, error_map, new_state}
if terminal not found
@callback handle_terminal_wait_for_exit( ACPex.Schema.Client.Terminal.WaitForExitRequest.t(), state() ) :: {:ok, ACPex.Schema.Client.Terminal.WaitForExitResponse.t(), state()} | {:error, error_response(), state()}
Handle a request from the agent to wait for terminal exit.
Parameters
request
- AWaitForExitRequest
struct with terminal_idstate
- Current client state
Returns
{:ok, response, new_state}
where response is aWaitForExitResponse
struct with exit status{:error, error_map, new_state}
if terminal not found
Initialize the client with the given arguments.
Returns {:ok, initial_state}
.