|
NeoGraph 0.16.0
A C++20 Graph Agent Engine Library — LangGraph for C++
|
Agent-side handle for issuing requests back to the editor. More...
#include <server.h>
Public Types | |
| using | ServerResolver = std::function< std::shared_ptr< ACPServer >(std::string_view session_id)> |
| Finds the ACPServer that serves a session, or an empty pointer when none does. | |
Public Member Functions | |
| ACPClient () | |
| Construct an unbound client. Bind it to a server later via bind or ACPServer::attach_client. This is the form you want when nodes capture the client during compile() — long before the ACPServer instance exists. | |
| ACPClient (ACPServer *server) | |
Construct a client already bound to server. | |
| ACPClient (ServerResolver resolver) | |
Construct a client for a host that serves several connections, each with its own ACPServer (see ACPHttpServer::client()): every call goes to the server resolver names for the call's session id, and throws std::runtime_error when it names none. The server stays alive for the duration of the call. | |
| void | bind (ACPServer *server) |
| Late-binding hook — set the back-pointer to the server. Idempotent. | |
| void | bind (ServerResolver resolver) |
Late-binding hook for a host that serves several connections (see ACPHttpServer::attach_client): route every call through resolver. | |
| bool | bound () const noexcept |
| True once bind has been called with a non-null server, or when the client was made with a resolver. | |
| std::string | read_text_file (std::string_view session_id, std::string_view path, std::optional< int > line={}, std::optional< int > limit={}) |
Read a workspace file via the editor. line is 1-based; omitted = from start. limit is the max line count; omitted = whole file. Throws if not yet bound to a server. | |
| RequestPermissionOutcome | request_permission (std::string_view session_id, const ToolCallUpdate &tool_call, const std::vector< PermissionOption > &options) |
| Ask the editor to surface a permission prompt for an upcoming tool call. Blocks until the user picks an option or the prompt is cancelled. The returned outcome tells the caller whether to proceed (kind == Selected, inspect optionId/kind) or abort (kind == Cancelled — the prompt turn itself was cancelled, either because the client answered "cancelled" or because session/cancel arrived while the request was pending). Throws if not yet bound to a server. | |
| std::vector< std::shared_ptr< neograph::Tool > > | session_tools (std::string_view session_id) const |
The tools of the session's client-supplied MCP servers (session/new mcpServers), in server order. Empty when the session has none, is unknown, or the library was built without the MCP client. A tool call goes to the MCP server process the client configured; the session owns those processes until it is replaced by session/resume or the server is destroyed. | |
| void | set_permission_timeout (std::optional< std::chrono::milliseconds > t) |
| Timeout for session/request_permission. Default: none — a permission prompt waits for the user until the prompt turn is cancelled. Pass a duration to bound it; on expiry the call throws. | |
| void | set_timeout (std::chrono::milliseconds t) |
| Per-call timeout for fs/* requests (default 30 s). Editors usually respond fast, but fs/* may be slow for large files. | |
| void | write_text_file (std::string_view session_id, std::string_view path, std::string_view content) |
| Write (create or overwrite) a workspace file via the editor. Throws if not yet bound to a server. | |
Agent-side handle for issuing requests back to the editor.
ACP is bidirectional — the client (editor) drives the agent with session/prompt etc., but the agent talks back not just via session/update notifications but also via requests like fs/read_text_file (read a workspace file) and fs/write_text_file (write a workspace file). These calls block until the editor responds.
Obtain an instance via ACPServer::client(). Capture it inside a node's lambda; pull session_id out of the graph state (the default ACPGraphAdapter writes it to the _acp_session_id channel).
Calls throw ACPClientError (a std::runtime_error) on a JSON-RPC error envelope, and std::runtime_error on transport failure and on timeout.