NeoGraph 0.16.0
A C++20 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
types.h
Go to the documentation of this file.
1
35#pragma once
36
37#include <neograph/api.h>
38#include <neograph/json.h>
39
40#include <cstdint>
41#include <optional>
42#include <string>
43#include <string_view>
44#include <vector>
45
46namespace neograph::acp {
47
48using json = neograph::json;
49
50// ---------------------------------------------------------------------------
51// Capabilities
52// ---------------------------------------------------------------------------
53
55struct NEOGRAPH_API PromptCapabilities {
56 bool image = false;
57 bool audio = false;
58 bool embedded_context = false;
59};
60
62struct NEOGRAPH_API McpCapabilities {
63 bool http = false;
64 bool sse = false;
65};
66
68struct NEOGRAPH_API SessionCapabilities {
69 bool close = false;
70 bool list = false;
71 bool resume = false;
72};
73
75struct NEOGRAPH_API AgentCapabilities {
76 bool load_session = false;
77 PromptCapabilities prompt;
79 SessionCapabilities session;
80};
81
83struct NEOGRAPH_API FsCapabilities {
84 bool read_text_file = false;
85 bool write_text_file = false;
86};
87
89struct NEOGRAPH_API ClientCapabilities {
91 bool terminal = false;
94 bool elicitation = false;
95};
96
97// ---------------------------------------------------------------------------
98// Content blocks — the unit of payload in prompts and updates.
99// Discriminated by `type` ∈ {"text","image","audio","resource","resource_link"}.
100// ---------------------------------------------------------------------------
101
102struct NEOGRAPH_API ContentBlock {
103 std::string type;
104 std::string text;
105 std::string data;
106 std::string mime_type;
107 std::string uri;
108 std::string name;
109 std::optional<std::string> title;
110 std::optional<std::string> description;
111 std::optional<std::int64_t> size;
112
116 json resource;
117
119 json annotations;
120
122 static ContentBlock text_block(std::string s);
123
125 static ContentBlock resource_link(std::string uri,
126 std::string name,
127 std::string mime_type = {});
128};
129
130// ---------------------------------------------------------------------------
131// initialize
132// ---------------------------------------------------------------------------
133
135struct NEOGRAPH_API InitializeRequest {
136 int protocol_version = 1;
137 ClientCapabilities client_capabilities;
139};
140
141struct NEOGRAPH_API InitializeResponse {
142 int protocol_version = 1;
143 AgentCapabilities agent_capabilities;
146 std::vector<json> auth_methods;
147 json agent_info;
148};
149
150// ---------------------------------------------------------------------------
151// session/new
152// ---------------------------------------------------------------------------
153
156struct NEOGRAPH_API McpServerConfig {
157 json raw;
158};
159
160struct NEOGRAPH_API NewSessionRequest {
161 std::string cwd;
164 std::vector<std::string> additional_directories;
165 std::vector<McpServerConfig> mcp_servers;
166};
167
168struct NEOGRAPH_API NewSessionResponse {
169 std::string session_id;
172 json config_options;
173 json modes;
174};
175
176// ---------------------------------------------------------------------------
177// session/resume
178// ---------------------------------------------------------------------------
179
182struct NEOGRAPH_API ResumeSessionRequest {
183 std::string session_id;
184 std::string cwd;
186 std::vector<std::string> additional_directories;
187 std::vector<McpServerConfig> mcp_servers;
188};
189
190// ---------------------------------------------------------------------------
191// session/prompt
192// ---------------------------------------------------------------------------
193
194struct NEOGRAPH_API PromptRequest {
195 std::string session_id;
196 std::vector<ContentBlock> prompt;
197};
198
206enum class StopReason {
207 EndTurn,
208 MaxTokens,
210 Refusal,
211 Cancelled,
212};
213
214NEOGRAPH_API std::string stop_reason_to_string(StopReason s);
215NEOGRAPH_API StopReason stop_reason_from_string(std::string_view s);
216
217struct NEOGRAPH_API PromptResponse {
218 StopReason stop_reason = StopReason::EndTurn;
219};
220
221// ---------------------------------------------------------------------------
222// session/cancel — JSON-RPC notification (no response)
223// ---------------------------------------------------------------------------
224
225struct NEOGRAPH_API CancelNotification {
226 std::string session_id;
227};
228
229// ---------------------------------------------------------------------------
230// fs/read_text_file, fs/write_text_file — agent → client requests
231// ---------------------------------------------------------------------------
232
233struct NEOGRAPH_API ReadTextFileRequest {
234 std::string session_id;
235 std::string path;
236 std::optional<int> line;
237 std::optional<int> limit;
238};
239
240struct NEOGRAPH_API ReadTextFileResponse {
241 std::string content;
242};
243
244struct NEOGRAPH_API WriteTextFileRequest {
245 std::string session_id;
246 std::string path;
247 std::string content;
248};
249
250NEOGRAPH_API void to_json(json& j, const ReadTextFileRequest& r);
251NEOGRAPH_API void from_json(const json& j, ReadTextFileRequest& r);
252NEOGRAPH_API void to_json(json& j, const ReadTextFileResponse& r);
253NEOGRAPH_API void from_json(const json& j, ReadTextFileResponse& r);
254NEOGRAPH_API void to_json(json& j, const WriteTextFileRequest& r);
255NEOGRAPH_API void from_json(const json& j, WriteTextFileRequest& r);
256
257// ---------------------------------------------------------------------------
258// ToolCallUpdate — name matches the official ACP schema
259// (`session/request_permission.toolCall: ToolCallUpdate`). Modeled
260// minimally: spec carries more fields, preserved verbatim in `raw`.
261struct NEOGRAPH_API ToolCallUpdate {
262 std::string tool_call_id;
266 std::string tool_name;
267 json input;
268 std::string title;
269 std::string kind;
270 std::string status;
271 std::vector<ContentBlock> content;
273 json raw;
274};
275
276NEOGRAPH_API void to_json(json& j, const ToolCallUpdate& t);
277NEOGRAPH_API void from_json(const json& j, ToolCallUpdate& t);
278
279// ---------------------------------------------------------------------------
280// session/request_permission — agent → client (the agent asks the editor
281// to surface a permission prompt before executing a tool call)
282// ---------------------------------------------------------------------------
283
284struct NEOGRAPH_API PermissionOption {
285 std::string option_id;
286 std::string name;
287 std::string kind;
288};
289
290NEOGRAPH_API void to_json(json& j, const PermissionOption& o);
291NEOGRAPH_API void from_json(const json& j, PermissionOption& o);
292
293struct NEOGRAPH_API RequestPermissionRequest {
294 std::string session_id;
295 ToolCallUpdate tool_call;
296 std::vector<PermissionOption> options;
297};
298
299NEOGRAPH_API void to_json(json& j, const RequestPermissionRequest& r);
300NEOGRAPH_API void from_json(const json& j, RequestPermissionRequest& r);
301
306enum class PermissionOutcomeKind { Selected, Cancelled };
307
308struct NEOGRAPH_API RequestPermissionOutcome {
309 PermissionOutcomeKind kind = PermissionOutcomeKind::Cancelled;
310 std::string option_id;
311};
312
313NEOGRAPH_API void to_json(json& j, const RequestPermissionOutcome& o);
314NEOGRAPH_API void from_json(const json& j, RequestPermissionOutcome& o);
315
316struct NEOGRAPH_API RequestPermissionResponse {
317 RequestPermissionOutcome outcome;
318};
319
320NEOGRAPH_API void to_json(json& j, const RequestPermissionResponse& r);
321NEOGRAPH_API void from_json(const json& j, RequestPermissionResponse& r);
322
323// ---------------------------------------------------------------------------
324// session/update — agent-emitted streaming notification
325// ---------------------------------------------------------------------------
326
339struct NEOGRAPH_API SessionUpdate {
340 std::string session_update;
341 ContentBlock content;
342 json raw;
343};
344
345struct NEOGRAPH_API SessionNotification {
346 std::string session_id;
347 SessionUpdate update;
348};
349
350// ---------------------------------------------------------------------------
351// JSON adapters (defined in src/acp/types.cpp).
352// ---------------------------------------------------------------------------
353NEOGRAPH_API void to_json(json& j, const PromptCapabilities& c);
354NEOGRAPH_API void from_json(const json& j, PromptCapabilities& c);
355
356NEOGRAPH_API void to_json(json& j, const McpCapabilities& c);
357NEOGRAPH_API void from_json(const json& j, McpCapabilities& c);
358
359NEOGRAPH_API void to_json(json& j, const SessionCapabilities& c);
360NEOGRAPH_API void from_json(const json& j, SessionCapabilities& c);
361
362NEOGRAPH_API void to_json(json& j, const AgentCapabilities& c);
363NEOGRAPH_API void from_json(const json& j, AgentCapabilities& c);
364
365NEOGRAPH_API void to_json(json& j, const FsCapabilities& c);
366NEOGRAPH_API void from_json(const json& j, FsCapabilities& c);
367
368NEOGRAPH_API void to_json(json& j, const ClientCapabilities& c);
369NEOGRAPH_API void from_json(const json& j, ClientCapabilities& c);
370
371NEOGRAPH_API void to_json(json& j, const ContentBlock& b);
372NEOGRAPH_API void from_json(const json& j, ContentBlock& b);
373
374NEOGRAPH_API void to_json(json& j, const InitializeRequest& r);
375NEOGRAPH_API void from_json(const json& j, InitializeRequest& r);
376
377NEOGRAPH_API void to_json(json& j, const InitializeResponse& r);
378NEOGRAPH_API void from_json(const json& j, InitializeResponse& r);
379
380NEOGRAPH_API void to_json(json& j, const McpServerConfig& c);
381NEOGRAPH_API void from_json(const json& j, McpServerConfig& c);
382
383NEOGRAPH_API void to_json(json& j, const NewSessionRequest& r);
384NEOGRAPH_API void from_json(const json& j, NewSessionRequest& r);
385
386NEOGRAPH_API void to_json(json& j, const NewSessionResponse& r);
387NEOGRAPH_API void from_json(const json& j, NewSessionResponse& r);
388
389NEOGRAPH_API void to_json(json& j, const ResumeSessionRequest& r);
390NEOGRAPH_API void from_json(const json& j, ResumeSessionRequest& r);
391
392NEOGRAPH_API void to_json(json& j, const PromptRequest& r);
393NEOGRAPH_API void from_json(const json& j, PromptRequest& r);
394
395NEOGRAPH_API void to_json(json& j, const PromptResponse& r);
396NEOGRAPH_API void from_json(const json& j, PromptResponse& r);
397
398NEOGRAPH_API void to_json(json& j, const CancelNotification& n);
399NEOGRAPH_API void from_json(const json& j, CancelNotification& n);
400
401NEOGRAPH_API void to_json(json& j, const SessionUpdate& u);
402NEOGRAPH_API void from_json(const json& j, SessionUpdate& u);
403
404NEOGRAPH_API void to_json(json& j, const SessionNotification& n);
405NEOGRAPH_API void from_json(const json& j, SessionNotification& n);
406
407} // namespace neograph::acp
StopReason
Why the agent stopped responding for this turn.
Definition types.h:206
@ EndTurn
"end_turn" — turn finished normally.
@ MaxTurnRequests
"max_turn_requests" — agent reached its turn-request budget.
@ Refusal
"refusal" — agent refused to continue.
@ Cancelled
"cancelled" — cancelled via session/cancel.
@ MaxTokens
"max_tokens" — model hit the token cap.
PermissionOutcomeKind
The user's decision (or absence thereof).
Definition types.h:306
NEOGRAPH_API export/import macro for shared-library builds.
Thin C++ RAII wrapper around yyjson with nlohmann-compatible API.
Capabilities advertised in InitializeResponse.
Definition types.h:75
Capabilities advertised by the editor in InitializeRequest.
Definition types.h:89
File-system access methods the client offers (agent→client direction).
Definition types.h:83
Sent once by the editor when the connection comes up.
Definition types.h:135
json client_info
free-form metadata bag (e.g. name/version)
Definition types.h:138
MCP server transports the agent supports (stdio is implicit / required).
Definition types.h:62
Single MCP server entry attached to the session.
Definition types.h:156
Capabilities the agent advertises about which prompt content it accepts.
Definition types.h:55
Reconnect to a persisted session without replaying conversation history.
Definition types.h:182
std::vector< std::string > additional_directories
Complete replacement list of additional workspace roots.
Definition types.h:186
Optional session-management features the agent supports.
Definition types.h:68
Streaming event the agent sends while a prompt is in flight.
Definition types.h:339
std::string session_update
discriminator
Definition types.h:340
ContentBlock content
populated for *_chunk variants
Definition types.h:341
json raw
full original JSON (always populated)
Definition types.h:342