NeoGraph 0.16.0
A C++20 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
native.h
Go to the documentation of this file.
1
5#pragma once
6
7#include <neograph/api.h>
11
12#include <chrono>
13#include <cstddef>
14#include <cstdint>
15#include <memory>
16#include <optional>
17#include <stdexcept>
18#include <string>
19
20namespace neograph::program {
27#if defined(__wasm32__)
28inline constexpr bool NATIVE_CONTROLS_AVAILABLE = false;
29#else
30inline constexpr bool NATIVE_CONTROLS_AVAILABLE = true;
31#endif
32
38class NEOGRAPH_PROGRAM_API NativeControlUnavailable final : public std::runtime_error,
40public:
42};
43
48inline constexpr std::uint32_t NATIVE_CONTROL_IMPORT_SLOT_MIN = 7;
49
50enum class NativeIdempotency : std::uint8_t {
51 Idempotent,
52 NonIdempotent,
53};
54
55NEOGRAPH_PROGRAM_API std::string_view to_string(NativeIdempotency value) noexcept;
56NEOGRAPH_PROGRAM_API NativeIdempotency native_idempotency_from_string(std::string_view value);
57
58enum class NativeReplayBehavior : std::uint8_t {
59 Deterministic,
60 Recorded,
61 Unmanaged,
62};
63
64NEOGRAPH_PROGRAM_API std::string_view to_string(NativeReplayBehavior value) noexcept;
65NEOGRAPH_PROGRAM_API NativeReplayBehavior
66native_replay_behavior_from_string(std::string_view value);
67
84 std::size_t max_input_bytes = 0;
85 std::size_t max_output_bytes = 0;
86 std::uint64_t advisory_wall_time_ms = 0;
87 std::size_t advisory_memory_bytes = 0;
88
89 bool operator==(const NativeResourceDeclaration&) const = default;
90};
91
94 ContractRecord input_contract;
95 ContractRecord output_contract;
96 NativeIdempotency idempotency = NativeIdempotency::NonIdempotent;
97 NativeReplayBehavior replay_behavior = NativeReplayBehavior::Recorded;
98 NativeResourceDeclaration resource_declaration;
99};
100
101enum class NativeInvocationStatus : std::uint8_t {
102 Success,
103 Failure,
104 Cancelled,
105 ProtocolFailure,
106};
107
110 NativeInvocationStatus status = NativeInvocationStatus::ProtocolFailure;
111 json value = nullptr;
112 std::string diagnostic_code;
113 std::string diagnostic_message;
114};
115
116namespace detail {
117struct NativeControlBindingImpl;
118struct NativeInvocationImpl;
119} // namespace detail
120
128class NEOGRAPH_PROGRAM_API NativeInvocation final {
129public:
130 NativeInvocation() = default;
132 NativeInvocation& operator=(NativeInvocation&&) noexcept;
133 NativeInvocation(const NativeInvocation&) = delete;
134 NativeInvocation& operator=(const NativeInvocation&) = delete;
136 void cancel();
137 bool cancel_requested() const noexcept;
138 bool finished() const noexcept;
139 bool wait_for(std::chrono::milliseconds timeout) const;
140 std::optional<NativeInvocationResult> result() const;
141
142private:
143 explicit NativeInvocation(std::shared_ptr<detail::NativeInvocationImpl> impl);
144
145 std::shared_ptr<detail::NativeInvocationImpl> impl_;
146 friend class NativeControlBinding;
147};
148
159class NEOGRAPH_PROGRAM_API NativeControlBinding final {
160public:
161 NativeControlBinding() = default;
164 NativeControlBinding& operator=(const NativeControlBinding&) noexcept;
165 NativeControlBinding& operator=(NativeControlBinding&&) noexcept;
167
170 NativeControlMetadata metadata);
171
172 bool valid() const noexcept;
173 const NativeControlMetadata& metadata() const;
174 NativeInvocation invoke(std::uint64_t invocation_id, const json& input) const;
175
176private:
177 explicit NativeControlBinding(std::shared_ptr<detail::NativeControlBindingImpl> impl);
178
179 std::shared_ptr<detail::NativeControlBindingImpl> impl_;
180};
181
182} // namespace neograph::program
NEOGRAPH_API export/import macro for shared-library builds.
Immutable, content-addressed Program compilation artifacts.
Marks an exception type as a configuration or definition verdict.
C++ wrapper over a C v1 plugin binding for trusted in-process dispatch only.
Definition native.h:159
static NativeControlBinding create(neograph_program_native_binding_v1 binding, NativeControlMetadata metadata)
Throws NativeControlUnavailable where NATIVE_CONTROLS_AVAILABLE is false.
Thrown by NativeControlBinding::create where NATIVE_CONTROLS_AVAILABLE is false.
Definition native.h:39
One move-only handle for an accepted native invocation.
Definition native.h:128
Marker for exceptions that are configuration or definition verdicts (#364).
constexpr std::uint32_t NATIVE_CONTROL_IMPORT_SLOT_MIN
Import slots below this value are reserved by the versioned ng command module.
Definition native.h:48
constexpr bool NATIVE_CONTROLS_AVAILABLE
Whether this build can load a native control plugin.
Definition native.h:30
Stable C v1 contract for externally implemented Program host bindings.
Immutable metadata which participates in the registry snapshot identity.
Definition native.h:93
Host-owned terminal result; no plugin storage survives this value.
Definition native.h:109
Declared native resource envelope.
Definition native.h:83
Versioned plugin binding supplied to the C++ Program registration surface.
Definition native_abi.h:134