10#include <neograph/types.h>
11#include <core/native_archive.h>
21namespace neograph::program {
27enum class ProgramTerminalStatus : std::uint8_t {
35 CheckpointIncompatible,
38NEOGRAPH_PROGRAM_API std::string_view to_string(ProgramTerminalStatus status)
noexcept;
39NEOGRAPH_PROGRAM_API ProgramTerminalStatus
40program_terminal_status_from_string(std::string_view value);
43 std::uint64_t wall_time_ms = 0;
44 std::uint64_t model_tokens = 0;
45 std::uint64_t monetary_microunits = 0;
46 std::uint32_t max_concurrency = 0;
47 std::uint64_t max_program_operations = 0;
48 std::uint64_t max_core_steps = 0;
49 std::uint64_t max_dynamic_compiles = 0;
51 std::uint32_t max_child_depth = 0;
53 std::uint64_t max_total_children = 0;
57 std::optional<std::uint64_t> max_node_retries;
59 bool operator==(
const RunBudget&)
const =
default;
63 std::uint64_t wall_time_ms = 0;
64 std::uint64_t model_tokens = 0;
67 std::uint64_t monetary_microunits = 0;
68 std::uint64_t program_operations = 0;
69 std::uint64_t core_steps = 0;
70 std::uint32_t peak_concurrency = 0;
73 std::uint64_t node_retries = 0;
75 bool operator==(
const ProgramUsage&)
const =
default;
88NEOGRAPH_PROGRAM_API std::string_view to_string(ProgramMonetaryEvidence evidence)
noexcept;
89NEOGRAPH_PROGRAM_API ProgramMonetaryEvidence
90program_monetary_evidence_from_string(std::string_view value);
96 std::string operation_id;
114 std::string catalog_digest;
147struct CoreCheckpointIdentity {
148 std::string core_name;
149 std::string core_generation_id;
150 std::string core_thread_id;
151 std::string checkpoint_id;
152 std::uint32_t checkpoint_schema_version;
154 bool operator==(
const CoreCheckpointIdentity&)
const =
default;
157struct ProgramFailure {
160 std::string operation_id;
161 std::string core_node;
162 std::uint32_t attempts = 0;
166 sp::runtime::Result provider_outcome;
167 std::exception_ptr provider_cause;
169 bool operator==(
const ProgramFailure& other)
const {
170 return code == other.code && message == other.message &&
171 operation_id == other.operation_id && core_node == other.core_node &&
172 attempts == other.attempts && witness == other.witness;
176struct ProgramInterrupt {
177 std::string core_node;
179 std::optional<ProgramPendingInput> pending_input;
180 std::optional<ProgramPendingEffect> pending_effect;
184struct ProgramResultData {
185 ProgramTerminalStatus status = ProgramTerminalStatus::Failed;
187 std::string program_version_id;
188 std::string bundle_id;
189 std::string operation_id =
"root";
190 std::uint64_t attempt = 0;
191 json output = json::object();
193 RunBudget remaining_budget;
194 std::optional<CoreCheckpointIdentity> checkpoint;
195 std::optional<ProgramInterrupt> interrupt;
196 std::optional<ProgramFailure> failure;
197 std::vector<std::string> execution_trace;
200 std::optional<UsageAccumulator::AuthoritySnapshot> provider_budget_authority;
202 std::vector<ProgramMonetaryRecord> monetary_records;
205class NEOGRAPH_PROGRAM_API ProgramResult {
215 static ProgramResult create(ProgramResultData data);
218 static ProgramResult parse(std::string_view stored_bytes);
219 std::string serialize_canonical()
const;
220 const std::string& id() const noexcept;
221 ProgramTerminalStatus status() const noexcept;
222 const std::
string& run_id() const noexcept;
223 const std::
string& program_version_id() const noexcept;
224 const std::
string& bundle_id() const noexcept;
225 const std::
string& operation_id() const noexcept;
226 std::uint64_t attempt() const noexcept;
228 ProgramUsage usage() const noexcept;
229 RunBudget remaining_budget() const noexcept;
230 std::optional<CoreCheckpointIdentity> checkpoint() const;
231 std::optional<ProgramInterrupt> interrupt() const;
233 std::optional<ProgramFailure> failure() const;
234 std::vector<std::
string> execution_trace() const;
235 const std::optional<UsageAccumulator::AuthoritySnapshot>& provider_budget_authority() const noexcept;
238 const std::vector<ProgramMonetaryRecord>& monetary_records() const noexcept;
241 using ConstructionData = ProgramResultData;
244 explicit ProgramResult(ConstructionData data,
bool persistable = true);
245 ProgramResult restore_provider_failure(
246 std::string_view owner_scope, const std::shared_ptr<sp::NativeArchive>& archive) const;
247 static ProgramResult create_for_runtime(
248 ConstructionData data, std::string_view owner_scope,
249 const std::shared_ptr<sp::NativeArchive>& archive);
250 std::shared_ptr<const Impl> impl_;
252 friend class detail::RunControl;
@ Cancelled
"cancelled" — cancelled via session/cancel.
NEOGRAPH_API export/import macro for shared-library builds.
@ BudgetExhausted
NG.BudgetExhausted: budget or quota exhaustion.
Thin C++ RAII wrapper around yyjson with nlohmann-compatible API.
Protocol-neutral durable pending input and effect values.
ProgramMonetaryEvidence
Where the amount of one priced provider call came from.
@ Reported
The provider's own cost for the call (OpenRouter usage.cost).
@ Held
The outcome or its usage is unknown, so the call's reservation is charged.
One provider call of a Program attempt, priced in micro-USD (1e-6 USD).
std::string call_id
Stable logical call slot, the provider journal's dispatch id.
std::uint64_t microunits
Amount charged to the run.
json pricing
What priced an estimated or held amount, empty before 0.16.0: entry (the catalogue entry id),...
std::optional< std::string > served_by
The upstream a routing gateway named as having served the call, as the SDK reports it: OpenRouter's p...
std::string origin
The provider's base URL, for example "https://openrouter.ai".
bool replayed
Restored from the provider journal after a restart; its request was sent once, before the restart.
std::uint64_t reserved_microunits
Preflight reservation; 0 when none could be computed.
std::string node
Core node that made the call.
std::string basis
"provider_reported", "list_rates" or "route_ceiling".
std::string catalog_version
The catalogue that priced an estimated or held amount: "sp-model-catalogue/1" and the SchemaProvider ...
bool may_undercount
The amount may be below the bill: the catalogue gave no price for a dearer band and the cheaper one p...
bool conservative
Some tokens or tool uses were priced at the highest rate or count they could have billed at.
std::string reason
Why an amount is held (the usage state or the unknown outcome).