NeoGraph 0.10.0
A C++17 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
types.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <neograph/api.h>
35#include <neograph/json.h>
36
37#include <optional>
38#include <string>
39#include <vector>
40
41namespace neograph::acp {
42
43using json = neograph::json;
44
45// ---------------------------------------------------------------------------
46// Capabilities
47// ---------------------------------------------------------------------------
48
50struct NEOGRAPH_API PromptCapabilities {
51 bool image = false;
52 bool audio = false;
53 bool embedded_context = false;
54};
55
57struct NEOGRAPH_API McpCapabilities {
58 bool http = false;
59 bool sse = false;
60};
61
63struct NEOGRAPH_API SessionCapabilities {
64 bool close = false;
65 bool list = false;
66 bool resume = false;
67};
68
70struct NEOGRAPH_API AgentCapabilities {
71 bool load_session = false;
72 PromptCapabilities prompt;
74 SessionCapabilities session;
75};
76
78struct NEOGRAPH_API FsCapabilities {
79 bool read_text_file = false;
80 bool write_text_file = false;
81};
82
84struct NEOGRAPH_API ClientCapabilities {
86 bool terminal = false;
87};
88
89// ---------------------------------------------------------------------------
90// Content blocks — the unit of payload in prompts and updates.
91// Discriminated by `type` ∈ {"text","image","audio","resource","resource_link"}.
92// ---------------------------------------------------------------------------
93
94struct NEOGRAPH_API ContentBlock {
95 std::string type;
96 std::string text;
97 std::string data;
98 std::string mime_type;
99 std::string uri;
100 std::string name;
101 std::optional<std::string> title;
102 std::optional<std::string> description;
103 std::optional<std::int64_t> size;
104
108 json resource;
109
111 json annotations;
112
114 static ContentBlock text_block(std::string s);
115
117 static ContentBlock resource_link(std::string uri,
118 std::string name,
119 std::string mime_type = {});
120};
121
122// ---------------------------------------------------------------------------
123// initialize
124// ---------------------------------------------------------------------------
125
127struct NEOGRAPH_API InitializeRequest {
128 int protocol_version = 1;
129 ClientCapabilities client_capabilities;
131};
132
133struct NEOGRAPH_API InitializeResponse {
134 int protocol_version = 1;
135 AgentCapabilities agent_capabilities;
138 std::vector<json> auth_methods;
139 json agent_info;
140};
141
142// ---------------------------------------------------------------------------
143// session/new
144// ---------------------------------------------------------------------------
145
148struct NEOGRAPH_API McpServerConfig {
149 json raw;
150};
151
152struct NEOGRAPH_API NewSessionRequest {
153 std::string cwd;
154 std::vector<McpServerConfig> mcp_servers;
155};
156
157struct NEOGRAPH_API NewSessionResponse {
158 std::string session_id;
161 json config_options;
162 json modes;
163};
164
165// ---------------------------------------------------------------------------
166// session/prompt
167// ---------------------------------------------------------------------------
168
169struct NEOGRAPH_API PromptRequest {
170 std::string session_id;
171 std::vector<ContentBlock> prompt;
172};
173
181enum class StopReason {
182 EndTurn,
183 MaxTokens,
185 Refusal,
186 Cancelled,
187};
188
189NEOGRAPH_API std::string stop_reason_to_string(StopReason s);
190NEOGRAPH_API StopReason stop_reason_from_string(std::string_view s);
191
192struct NEOGRAPH_API PromptResponse {
193 StopReason stop_reason = StopReason::EndTurn;
194};
195
196// ---------------------------------------------------------------------------
197// session/cancel — JSON-RPC notification (no response)
198// ---------------------------------------------------------------------------
199
200struct NEOGRAPH_API CancelNotification {
201 std::string session_id;
202};
203
204// ---------------------------------------------------------------------------
205// fs/read_text_file, fs/write_text_file — agent → client requests
206// ---------------------------------------------------------------------------
207
208struct NEOGRAPH_API ReadTextFileRequest {
209 std::string session_id;
210 std::string path;
211 std::optional<int> line;
212 std::optional<int> limit;
213};
214
215struct NEOGRAPH_API ReadTextFileResponse {
216 std::string content;
217};
218
219struct NEOGRAPH_API WriteTextFileRequest {
220 std::string session_id;
221 std::string path;
222 std::string content;
223};
224
225NEOGRAPH_API void to_json(json& j, const ReadTextFileRequest& r);
226NEOGRAPH_API void from_json(const json& j, ReadTextFileRequest& r);
227NEOGRAPH_API void to_json(json& j, const ReadTextFileResponse& r);
228NEOGRAPH_API void from_json(const json& j, ReadTextFileResponse& r);
229NEOGRAPH_API void to_json(json& j, const WriteTextFileRequest& r);
230NEOGRAPH_API void from_json(const json& j, WriteTextFileRequest& r);
231
232// ---------------------------------------------------------------------------
233// ToolCallUpdate — name matches the official ACP schema
234// (`session/request_permission.toolCall: ToolCallUpdate`). Modeled
235// minimally: spec carries more fields, preserved verbatim in `raw`.
236//
237// Renamed from `ToolCall` (which collided with the LLM-side
238// `neograph::ToolCall` in `<neograph/types.h>` whenever both
239// namespaces were brought in via `using namespace`). The two are
240// genuinely different concepts — keep them under distinct names.
241// ---------------------------------------------------------------------------
242
243struct NEOGRAPH_API ToolCallUpdate {
244 std::string tool_call_id;
245 std::string tool_name;
246 json input;
247 std::string kind;
248 std::string status;
249 std::vector<ContentBlock> content;
251 json raw;
252};
253
254NEOGRAPH_API void to_json(json& j, const ToolCallUpdate& t);
255NEOGRAPH_API void from_json(const json& j, ToolCallUpdate& t);
256
257// ---------------------------------------------------------------------------
258// session/request_permission — agent → client (the agent asks the editor
259// to surface a permission prompt before executing a tool call)
260// ---------------------------------------------------------------------------
261
262struct NEOGRAPH_API PermissionOption {
263 std::string option_id;
264 std::string name;
265 std::string kind;
266};
267
268NEOGRAPH_API void to_json(json& j, const PermissionOption& o);
269NEOGRAPH_API void from_json(const json& j, PermissionOption& o);
270
271struct NEOGRAPH_API RequestPermissionRequest {
272 std::string session_id;
273 ToolCallUpdate tool_call;
274 std::vector<PermissionOption> options;
275};
276
277NEOGRAPH_API void to_json(json& j, const RequestPermissionRequest& r);
278NEOGRAPH_API void from_json(const json& j, RequestPermissionRequest& r);
279
284enum class PermissionOutcomeKind { Selected, Cancelled };
285
286struct NEOGRAPH_API RequestPermissionOutcome {
287 PermissionOutcomeKind kind = PermissionOutcomeKind::Cancelled;
288 std::string option_id;
289};
290
291NEOGRAPH_API void to_json(json& j, const RequestPermissionOutcome& o);
292NEOGRAPH_API void from_json(const json& j, RequestPermissionOutcome& o);
293
294struct NEOGRAPH_API RequestPermissionResponse {
295 RequestPermissionOutcome outcome;
296};
297
298NEOGRAPH_API void to_json(json& j, const RequestPermissionResponse& r);
299NEOGRAPH_API void from_json(const json& j, RequestPermissionResponse& r);
300
301// ---------------------------------------------------------------------------
302// session/update — agent-emitted streaming notification
303// ---------------------------------------------------------------------------
304
317struct NEOGRAPH_API SessionUpdate {
318 std::string session_update;
319 ContentBlock content;
320 json raw;
321};
322
323struct NEOGRAPH_API SessionNotification {
324 std::string session_id;
325 SessionUpdate update;
326};
327
328// ---------------------------------------------------------------------------
329// JSON adapters (defined in src/acp/types.cpp).
330// ---------------------------------------------------------------------------
331NEOGRAPH_API void to_json(json& j, const PromptCapabilities& c);
332NEOGRAPH_API void from_json(const json& j, PromptCapabilities& c);
333
334NEOGRAPH_API void to_json(json& j, const McpCapabilities& c);
335NEOGRAPH_API void from_json(const json& j, McpCapabilities& c);
336
337NEOGRAPH_API void to_json(json& j, const SessionCapabilities& c);
338NEOGRAPH_API void from_json(const json& j, SessionCapabilities& c);
339
340NEOGRAPH_API void to_json(json& j, const AgentCapabilities& c);
341NEOGRAPH_API void from_json(const json& j, AgentCapabilities& c);
342
343NEOGRAPH_API void to_json(json& j, const FsCapabilities& c);
344NEOGRAPH_API void from_json(const json& j, FsCapabilities& c);
345
346NEOGRAPH_API void to_json(json& j, const ClientCapabilities& c);
347NEOGRAPH_API void from_json(const json& j, ClientCapabilities& c);
348
349NEOGRAPH_API void to_json(json& j, const ContentBlock& b);
350NEOGRAPH_API void from_json(const json& j, ContentBlock& b);
351
352NEOGRAPH_API void to_json(json& j, const InitializeRequest& r);
353NEOGRAPH_API void from_json(const json& j, InitializeRequest& r);
354
355NEOGRAPH_API void to_json(json& j, const InitializeResponse& r);
356NEOGRAPH_API void from_json(const json& j, InitializeResponse& r);
357
358NEOGRAPH_API void to_json(json& j, const McpServerConfig& c);
359NEOGRAPH_API void from_json(const json& j, McpServerConfig& c);
360
361NEOGRAPH_API void to_json(json& j, const NewSessionRequest& r);
362NEOGRAPH_API void from_json(const json& j, NewSessionRequest& r);
363
364NEOGRAPH_API void to_json(json& j, const NewSessionResponse& r);
365NEOGRAPH_API void from_json(const json& j, NewSessionResponse& r);
366
367NEOGRAPH_API void to_json(json& j, const PromptRequest& r);
368NEOGRAPH_API void from_json(const json& j, PromptRequest& r);
369
370NEOGRAPH_API void to_json(json& j, const PromptResponse& r);
371NEOGRAPH_API void from_json(const json& j, PromptResponse& r);
372
373NEOGRAPH_API void to_json(json& j, const CancelNotification& n);
374NEOGRAPH_API void from_json(const json& j, CancelNotification& n);
375
376NEOGRAPH_API void to_json(json& j, const SessionUpdate& u);
377NEOGRAPH_API void from_json(const json& j, SessionUpdate& u);
378
379NEOGRAPH_API void to_json(json& j, const SessionNotification& n);
380NEOGRAPH_API void from_json(const json& j, SessionNotification& n);
381
382} // namespace neograph::acp
StopReason
Why the agent stopped responding for this turn.
Definition types.h:181
@ 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:284
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:70
Capabilities advertised by the editor in InitializeRequest.
Definition types.h:84
File-system access methods the client offers (agent→client direction).
Definition types.h:78
Sent once by the editor when the connection comes up.
Definition types.h:127
json client_info
free-form metadata bag (e.g. name/version)
Definition types.h:130
MCP server transports the agent supports (stdio is implicit / required).
Definition types.h:57
Single MCP server entry attached to the session.
Definition types.h:148
Capabilities the agent advertises about which prompt content it accepts.
Definition types.h:50
Optional session-management features the agent supports.
Definition types.h:63
Streaming event the agent sends while a prompt is in flight.
Definition types.h:317
std::string session_update
discriminator
Definition types.h:318
ContentBlock content
populated for *_chunk variants
Definition types.h:319
json raw
full original JSON (always populated)
Definition types.h:320