NeoGraph 0.16.0
A C++20 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
source.h
Go to the documentation of this file.
1
5#pragma once
6
9
10#include <cstdint>
11#include <memory>
12#include <string>
13#include <string_view>
14#include <vector>
15
16namespace neograph::program {
17
24enum class SourceKind { CanonicalJson, CppBuilder, JavaScript };
25
26struct ImportRef {
27 std::string source_id;
28 std::string content_identity;
29
30 bool operator==(const ImportRef&) const = default;
31};
32
39 std::string source_id;
40 std::string content_identity;
41 std::string source_text;
42
43 bool operator==(const SealedJavaScriptModule&) const = default;
44};
45
46struct SourceMapEntry {
47 std::string generated_pointer;
48 SourceCoordinate authored;
49
50 bool operator==(const SourceMapEntry&) const = default;
51};
52
59 std::string quickjs_release;
60 std::string quickjs_archive_digest;
61 std::string quickjs_build_options;
62 std::string profile;
63 std::uint32_t profile_version = 0;
64 std::uint32_t ng_api_version = 0;
65
66 bool operator==(const JavaScriptRuntimeIdentity&) const = default;
67};
68
69NEOGRAPH_PROGRAM_API std::string_view to_string(SourceKind kind) noexcept;
70NEOGRAPH_PROGRAM_API SourceKind source_kind_from_string(std::string_view value);
71NEOGRAPH_PROGRAM_API void to_json(json& value, const ImportRef& import_ref);
72NEOGRAPH_PROGRAM_API void from_json(const json& value, ImportRef& import_ref);
73NEOGRAPH_PROGRAM_API void to_json(json& value, const SourceMapEntry& entry);
74NEOGRAPH_PROGRAM_API void to_json(json& value,
75 const SealedJavaScriptModule& module);
76NEOGRAPH_PROGRAM_API void from_json(const json& value,
78NEOGRAPH_PROGRAM_API void from_json(const json& value, SourceMapEntry& entry);
79
80class NEOGRAPH_PROGRAM_API ProgramSource {
81public:
82 static constexpr std::uint32_t STORAGE_SCHEMA_VERSION = 1;
83 static constexpr std::uint32_t JAVASCRIPT_PROGRAM_SCHEMA_VERSION =
84 LATEST_PROGRAM_SCHEMA_VERSION;
85 static constexpr std::uint32_t JAVASCRIPT_LANGUAGE_VERSION = 1;
86 static constexpr std::uint32_t JAVASCRIPT_HOST_API_VERSION = 1;
87 static constexpr std::string_view JAVASCRIPT_ENGINE = "quickjs";
88 static constexpr std::string_view JAVASCRIPT_ENGINE_VERSION = "2026-06-04";
89 static constexpr std::string_view JAVASCRIPT_QUICKJS_ARCHIVE_DIGEST =
90 "sha256:b376e839b322978313d929fd20663b11ba58b75df5a46c126dd19ea2fa70ad2a";
91 static constexpr std::string_view JAVASCRIPT_QUICKJS_BUILD_OPTIONS =
92#if defined(_MSC_VER)
93 "CONFIG_VERSION=2026-06-04;QUICKJS_LIBC=disabled;STD_OS=disabled;"
94 "DYNAMIC_MODULES=disabled;MSVC_INTRINSICS=disabled;"
95 "NEOGRAPH_PLATFORM_PORT=msvc-v1;"
96 "NEOGRAPH_PLATFORM_PORT_SHA256="
97 "7f12d37b15bce57527714395552d1a0b64c4f5708c48fcb3f787f96ed0d1af51";
98#else
99 "CONFIG_VERSION=2026-06-04;QUICKJS_LIBC=disabled;STD_OS=disabled;"
100 "DYNAMIC_MODULES=disabled";
101#endif
102 static constexpr std::string_view JAVASCRIPT_PROFILE = "sealed-v1";
103 static constexpr std::uint32_t JAVASCRIPT_PROFILE_VERSION = 1;
104 static constexpr std::uint32_t JAVASCRIPT_NG_API_VERSION = 1;
105
106 static JavaScriptRuntimeIdentity default_javascript_runtime_identity();
107
113 static ProgramSource from_javascript(std::string source_id,
114 std::string source_text,
115 std::vector<ImportRef> imports = {},
116 std::vector<SourceMapEntry> source_map = {},
117 std::vector<SealedJavaScriptModule> sealed_modules = {});
118
119 static ProgramSource from_cpp_builder(std::string source_id,
120 std::uint32_t schema_version,
121 json document,
122 std::vector<ImportRef> imports = {},
123 std::vector<SourceMapEntry> source_map = {});
124
126 static ProgramSource parse(std::string_view stored_bytes);
127
128 SourceKind kind() const noexcept;
129 std::uint32_t schema_version() const noexcept;
130 const std::string& source_id() const noexcept;
131 json document() const;
132 const std::vector<ImportRef>& imports() const noexcept;
133 const std::vector<SourceMapEntry>& source_map() const noexcept;
138 const std::vector<SealedJavaScriptModule>& sealed_modules() const noexcept;
140 JavaScriptRuntimeIdentity javascript_runtime_identity() const;
146 const std::string& source_hash() const noexcept;
147 const std::string& canonical_document() const noexcept;
148 std::string serialize_canonical() const;
149
150private:
151 struct Impl;
152 explicit ProgramSource(std::shared_ptr<const Impl> impl);
153 std::shared_ptr<const Impl> impl_;
154};
155
156} // namespace neograph::program
Stable, transport-neutral Program diagnostics and source coordinates.
Published Program source-schema version identifiers.
SourceKind
Source identity carried by Program values.
Definition source.h:24
Exact identity of the private JavaScript frontend.
Definition source.h:58
Exact source bytes for one reviewed pure JavaScript module.
Definition source.h:38