NeoGraph 0.16.0
A C++20 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
command.h
Go to the documentation of this file.
1
9#pragma once
10
11#include <neograph/api.h>
12#include <neograph/json.h>
13
14#include <cstddef>
15#include <cstdint>
16#include <memory>
17#include <string>
18#include <string_view>
19#include <vector>
20
21namespace neograph::program {
22
23enum class JavaScriptCommandKind : std::uint8_t {
24 CallCore,
25 Spawn,
26 Await,
27 Join,
28 Emit,
30 CancelScope,
31 HostCapability,
32};
33
34NEOGRAPH_PROGRAM_API std::string_view to_string(JavaScriptCommandKind kind) noexcept;
35NEOGRAPH_PROGRAM_API JavaScriptCommandKind
36javascript_command_kind_from_string(std::string_view value);
37
39inline constexpr std::uint32_t JAVASCRIPT_COMMAND_PROTOCOL_VERSION = 1;
41inline constexpr std::size_t JAVASCRIPT_COMMAND_MAX_STRUCTURED_DEPTH = 32;
43inline constexpr std::size_t JAVASCRIPT_COMMAND_MAX_AGGREGATE_MEMBERS = 4096;
44
46inline constexpr std::uint32_t JAVASCRIPT_IMPORT_SLOT_CALL_CORE = 0;
47inline constexpr std::uint32_t JAVASCRIPT_IMPORT_SLOT_SPAWN = 1;
48inline constexpr std::uint32_t JAVASCRIPT_IMPORT_SLOT_AWAIT = 2;
49inline constexpr std::uint32_t JAVASCRIPT_IMPORT_SLOT_JOIN = 3;
50inline constexpr std::uint32_t JAVASCRIPT_IMPORT_SLOT_EMIT = 4;
51inline constexpr std::uint32_t JAVASCRIPT_IMPORT_SLOT_CHECKPOINT = 5;
52inline constexpr std::uint32_t JAVASCRIPT_IMPORT_SLOT_CANCEL_SCOPE = 6;
53
62class NEOGRAPH_PROGRAM_API JavaScriptCommand final {
63public:
64 static constexpr std::uint32_t PROTOCOL_VERSION = JAVASCRIPT_COMMAND_PROTOCOL_VERSION;
65
66 JavaScriptCommand(const JavaScriptCommand&) = default;
67 JavaScriptCommand& operator=(const JavaScriptCommand&) = default;
68 JavaScriptCommand(JavaScriptCommand&&) noexcept = default;
69 JavaScriptCommand& operator=(JavaScriptCommand&&) noexcept = default;
71
73 static JavaScriptCommand from_json(const json& value);
74
76 static JavaScriptCommand make(std::uint32_t protocol_version,
77 JavaScriptCommandKind kind,
78 std::uint32_t import_slot,
79 std::string source_site,
80 json arguments);
81
82 static JavaScriptCommand call_core(std::string source_site,
83 std::string core_name,
84 json input);
85 static JavaScriptCommand spawn(std::string source_site,
86 std::string child_binding,
87 json input);
88 static JavaScriptCommand await(std::string source_site,
90 std::uint64_t timeout_ms = 0);
91 static JavaScriptCommand join(std::string source_site,
92 std::string mode,
93 std::vector<JavaScriptCommand> members,
94 std::uint64_t required_successes = 0,
95 std::uint64_t max_in_flight = 0,
96 std::string failure_policy = {});
97 static JavaScriptCommand emit(std::string source_site, json value);
98 static JavaScriptCommand checkpoint(std::string source_site, json value);
99 static JavaScriptCommand cancel_scope(std::string source_site,
100 std::string scope,
101 std::string reason = {});
102 static JavaScriptCommand host_capability(std::string source_site,
103 std::uint32_t import_slot,
104 json input);
105
106 std::uint32_t protocol_version() const noexcept;
107 JavaScriptCommandKind kind() const noexcept;
108 std::uint32_t import_slot() const noexcept;
109 const std::string& source_site() const noexcept;
111 json arguments() const;
113 json to_json() const;
114
115 bool operator==(const JavaScriptCommand& other) const;
116 bool operator!=(const JavaScriptCommand& other) const { return !(*this == other); }
117
118private:
119 struct Impl;
120 explicit JavaScriptCommand(std::shared_ptr<const Impl> impl);
121 std::shared_ptr<const Impl> impl_;
122};
123
124} // namespace neograph::program
NEOGRAPH_API export/import macro for shared-library builds.
Immutable host-owned JavaScript command.
Definition command.h:62
static JavaScriptCommand from_json(const json &value)
Strictly decode a canonical command object.
static JavaScriptCommand make(std::uint32_t protocol_version, JavaScriptCommandKind kind, std::uint32_t import_slot, std::string source_site, json arguments)
Construct a host-owned command after applying the same validation.
constexpr std::size_t JAVASCRIPT_COMMAND_MAX_AGGREGATE_MEMBERS
Maximum total command envelopes reachable through one structured command.
Definition command.h:43
constexpr std::uint32_t JAVASCRIPT_IMPORT_SLOT_CALL_CORE
Built-in import slots owned by the versioned ng command module.
Definition command.h:46
constexpr std::size_t JAVASCRIPT_COMMAND_MAX_STRUCTURED_DEPTH
Maximum number of nested await/join command envelopes, including the root.
Definition command.h:41
constexpr std::uint32_t JAVASCRIPT_COMMAND_PROTOCOL_VERSION
Protocol version carried by every JavaScript command.
Definition command.h:39
@ Checkpoint
Include value and version in checkpoints.
Thin C++ RAII wrapper around yyjson with nlohmann-compatible API.