space-data-module-sdk 0.8.27 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/README.md +5 -4
  2. package/docs/assembly.js +0 -18
  3. package/docs/assets/ai-credits/ai-credits.js +116 -0
  4. package/docs/assets/sdn-chrome/sdn-chrome.css +434 -0
  5. package/docs/assets/sdn-chrome/sdn-chrome.js +236 -0
  6. package/docs/browser-wasmedge-isomorphic.html +29 -41
  7. package/docs/byo-wasm-quickstart.html +29 -41
  8. package/docs/conformance.html +29 -41
  9. package/docs/events-abi.html +29 -41
  10. package/docs/families/analytics.html +29 -41
  11. package/docs/families/attitude.html +29 -41
  12. package/docs/families/behavior.html +29 -41
  13. package/docs/families/breakup.html +29 -41
  14. package/docs/families/conjunction.html +29 -41
  15. package/docs/families/data-source.html +29 -41
  16. package/docs/families/effects.html +29 -41
  17. package/docs/families/environment.html +29 -41
  18. package/docs/families/estimation.html +29 -41
  19. package/docs/families/gnc.html +29 -41
  20. package/docs/families/maneuver.html +29 -41
  21. package/docs/families/obstruction.html +29 -41
  22. package/docs/families/propagator.html +29 -41
  23. package/docs/families/propulsion.html +29 -41
  24. package/docs/families/reentry.html +29 -41
  25. package/docs/families/rf.html +29 -41
  26. package/docs/families/scheduler.html +29 -41
  27. package/docs/families/sensor.html +29 -41
  28. package/docs/families/signature.html +29 -41
  29. package/docs/flatsql-host-contract.html +29 -41
  30. package/docs/flatsql-streaming-standard.html +29 -41
  31. package/docs/gpu-module-abi.html +29 -41
  32. package/docs/index.html +43 -47
  33. package/docs/isomorphic-pthreads.html +29 -41
  34. package/docs/isomorphic-sdn-runtime-plan.html +29 -41
  35. package/docs/language-runtime-matrix.html +29 -41
  36. package/docs/media/module-sdk-reel-poster.webp +0 -0
  37. package/docs/media/module-sdk-reel.mp4 +0 -0
  38. package/docs/media/module-sdk-reel.webm +0 -0
  39. package/docs/media/reel/reel.css +53 -0
  40. package/docs/media/reel/reel.js +272 -0
  41. package/docs/module-bundle-runtime-plan.html +29 -41
  42. package/docs/module-publication-standard.html +29 -41
  43. package/docs/node-red-default-node-parity.html +29 -41
  44. package/docs/protect-and-sign.html +29 -41
  45. package/docs/protocol-installation.html +29 -41
  46. package/docs/publication-submission.html +29 -41
  47. package/docs/secrets-capability.html +29 -41
  48. package/docs/styles.css +89 -157
  49. package/docs/testing-harness.html +29 -41
  50. package/docs/tri-runtime-parity-gate.html +29 -41
  51. package/docs/tri-runtime-parity.html +29 -41
  52. package/package.json +5 -3
  53. package/schemas/runtime/FlowNotice.fbs +39 -0
  54. package/schemas/runtime/HostOps.fbs +453 -0
  55. package/schemas/runtime/HttpRequest.fbs +25 -0
  56. package/schemas/runtime/HttpResponse.fbs +24 -0
  57. package/schemas/runtime/IngestRequest.fbs +58 -0
  58. package/schemas/runtime/IngestResult.fbs +23 -0
  59. package/schemas/runtime/ModuleConfig.fbs +41 -0
  60. package/schemas/runtime/RuntimeCommon.fbs +33 -0
  61. package/schemas/runtime/TimerTick.fbs +18 -0
  62. package/src/compiler/compileModule.js +20 -2
  63. package/src/generated/runtime/aligned/HostOps_aligned.js +3924 -0
  64. package/src/generated/runtime/aligned/HostOps_aligned.ts +4620 -0
  65. package/src/generated/runtime/aligned/HostOps_enums.js +14 -0
  66. package/src/generated/runtime/aligned/HostOps_enums.ts +7 -0
  67. package/src/generated/runtime/cpp/FlowNotice_generated.h +367 -0
  68. package/src/generated/runtime/cpp/HostOps_aligned.h +3547 -0
  69. package/src/generated/runtime/cpp/HttpRequest_generated.h +317 -0
  70. package/src/generated/runtime/cpp/HttpResponse_generated.h +315 -0
  71. package/src/generated/runtime/cpp/IngestRequest_generated.h +764 -0
  72. package/src/generated/runtime/cpp/IngestResult_generated.h +319 -0
  73. package/src/generated/runtime/cpp/ModuleConfig_generated.h +604 -0
  74. package/src/generated/runtime/cpp/RuntimeCommon_generated.h +410 -0
  75. package/src/generated/runtime/cpp/TimerTick_generated.h +229 -0
  76. package/src/generated/runtime/sdn/runtime/ArchiveTarget.js +78 -0
  77. package/src/generated/runtime/sdn/runtime/ArchiveTarget.ts +104 -0
  78. package/src/generated/runtime/sdn/runtime/ConfigEntry.js +202 -0
  79. package/src/generated/runtime/sdn/runtime/ConfigEntry.ts +251 -0
  80. package/src/generated/runtime/sdn/runtime/ConfigTable.js +80 -0
  81. package/src/generated/runtime/sdn/runtime/ConfigTable.ts +97 -0
  82. package/src/generated/runtime/sdn/runtime/FlowNotice.js +196 -0
  83. package/src/generated/runtime/sdn/runtime/FlowNotice.ts +254 -0
  84. package/src/generated/runtime/sdn/runtime/Header.js +79 -0
  85. package/src/generated/runtime/sdn/runtime/Header.ts +100 -0
  86. package/src/generated/runtime/sdn/runtime/HttpRequest.js +216 -0
  87. package/src/generated/runtime/sdn/runtime/HttpRequest.ts +265 -0
  88. package/src/generated/runtime/sdn/runtime/HttpResponse.js +216 -0
  89. package/src/generated/runtime/sdn/runtime/HttpResponse.ts +267 -0
  90. package/src/generated/runtime/sdn/runtime/IngestRequest.js +121 -0
  91. package/src/generated/runtime/sdn/runtime/IngestRequest.ts +155 -0
  92. package/src/generated/runtime/sdn/runtime/IngestResult.js +184 -0
  93. package/src/generated/runtime/sdn/runtime/IngestResult.ts +235 -0
  94. package/src/generated/runtime/sdn/runtime/ModuleConfig.js +92 -0
  95. package/src/generated/runtime/sdn/runtime/ModuleConfig.ts +114 -0
  96. package/src/generated/runtime/sdn/runtime/Provenance.js +288 -0
  97. package/src/generated/runtime/sdn/runtime/Provenance.ts +368 -0
  98. package/src/generated/runtime/sdn/runtime/SourceTags.js +181 -0
  99. package/src/generated/runtime/sdn/runtime/SourceTags.ts +253 -0
  100. package/src/generated/runtime/sdn/runtime/TimerTick.js +119 -0
  101. package/src/generated/runtime/sdn/runtime/TimerTick.ts +148 -0
  102. package/src/generated/runtime/sdn/runtime/configValueKind.js +12 -0
  103. package/src/generated/runtime/sdn/runtime/configValueKind.ts +19 -0
  104. package/src/generated/runtime/sdn/runtime/flowNoticeKind.js +11 -0
  105. package/src/generated/runtime/sdn/runtime/flowNoticeKind.ts +34 -0
  106. package/src/generated/runtime/sdn/runtime/reconcileMode.js +9 -0
  107. package/src/generated/runtime/sdn/runtime/reconcileMode.ts +23 -0
  108. package/src/generated/runtime/sdn/runtime.js +16 -0
  109. package/src/generated/runtime/sdn/runtime.ts +17 -0
  110. package/src/host/abi.js +20 -3
  111. package/src/host/browserHost.js +2 -0
  112. package/src/host/cpp/typedHostcall.hpp +201 -0
  113. package/src/host/hostWorkerBundleSources.js +3 -3
  114. package/src/host/nodeHost.js +1 -0
  115. package/src/host/typedDispatch.js +230 -0
  116. package/src/invoke/codec.js +3 -2
  117. package/src/standards/runtimeContracts.js +536 -0
  118. package/src/standards/sharedCatalog.js +27 -0
package/src/host/abi.js CHANGED
@@ -4,6 +4,8 @@ import {
4
4
  detachBinaryValues,
5
5
  encodeHostcallEnvelope,
6
6
  } from "./hostcallWire.js";
7
+ import { isTypedHostCall } from "../standards/runtimeContracts.js";
8
+ import { answerTypedHostCall } from "./typedDispatch.js";
7
9
 
8
10
  const textDecoder = new TextDecoder();
9
11
 
@@ -184,6 +186,9 @@ function isPromiseLike(value) {
184
186
 
185
187
  function assertSyncHostcallResult(value, operation) {
186
188
  if (isPromiseLike(value)) {
189
+ // The refused operation's promise may still reject (e.g. a capability the host does not grant): handle it here,
190
+ // or that rejection is unhandled and takes the process down.
191
+ if (typeof value.catch === "function") value.catch(() => {});
187
192
  throw new Error(
188
193
  `Operation "${operation}" is not available in the synchronous hostcall ABI.`,
189
194
  );
@@ -412,11 +417,23 @@ export function createHostcallBridge(options = {}) {
412
417
  const operation = textDecoder.decode(
413
418
  readMemoryBytes(getMemory, operationPtr, operationLen, "Operation"),
414
419
  );
415
- const params = parseHostcallParams(
416
- readMemoryBytes(getMemory, payloadPtr, payloadLen, "Payload"),
417
- );
420
+ const payload = readMemoryBytes(getMemory, payloadPtr, payloadLen, "Payload");
421
+ // An SDS $PIV hostcall (typed contracts 1.0) is answered with a $PIV response; the JSON envelope below goes
422
+ // once every module is typed (graph: sdk-compliance-typed-only-20261013).
423
+ if (isTypedHostCall(payload)) {
424
+ const response = answerTypedHostCall(payload.slice(), dispatch);
425
+ if (response.length > maxResponseBytes) {
426
+ throw new Error(`Hostcall response exceeds ${maxResponseBytes} byte limit.`);
427
+ }
428
+ lastStatusCode = HOSTCALL_STATUS_OK;
429
+ lastEnvelope = null;
430
+ lastResponseBytes = response;
431
+ return HOSTCALL_STATUS_OK;
432
+ }
433
+ const params = parseHostcallParams(payload);
418
434
  const result = dispatch(operation, params);
419
435
  if (isPromiseLike(result)) {
436
+ if (typeof result.catch === "function") result.catch(() => {});
420
437
  throw new Error(
421
438
  `Operation "${operation}" returned a Promise. The synchronous hostcall ABI only supports synchronous operations.`,
422
439
  );
@@ -503,6 +503,7 @@ export class BrowserHost {
503
503
  method: params.method ?? "GET",
504
504
  headers: params.headers ?? undefined,
505
505
  body: params.body ?? undefined,
506
+ redirect: params.redirect ?? "follow",
506
507
  signal: controller.signal,
507
508
  });
508
509
  const responseType = params.responseType ?? "utf8";
@@ -511,6 +512,7 @@ export class BrowserHost {
511
512
  else if (responseType === "bytes") body = new Uint8Array(await response.arrayBuffer());
512
513
  else body = await response.text();
513
514
  return {
515
+ url: response.url || String(params.url),
514
516
  status: response.status,
515
517
  statusText: response.statusText,
516
518
  ok: response.ok,
@@ -0,0 +1,201 @@
1
+ // C++ guest-side hostcall as an SDS $PIV invocation (module -> host), replacing the JSON meta + binary segments
2
+ // envelope: PIVRequest.METHOD_ID is the operation and PAYLOAD_ARENA holds its frames, named by TAB.PORT_ID - the
3
+ // "params" aligned record (schemas/runtime/HostOps.fbs, FlatBuffers aligned binary layout), list ports (runs of aligned
4
+ // records) and raw ports (unbounded bytes: bodies, record streams, urls, sql). The PIVResponse carries the "result"
5
+ // record and the operation's list / raw ports, or STATUS FAILED with ERROR_CODE / ERROR_MESSAGE. HOST_OPERATIONS in
6
+ // src/standards/runtimeContracts.js names each operation's frames. The same space_data_module_host.call import carries it.
7
+ //
8
+ // Include paths: the SDK-generated "sds/PIV/main_generated.h" (as every SDK-compiled module has), the runtime headers
9
+ // (src/generated/runtime/cpp: HostOps_aligned.h) and flatbuffers.
10
+ //
11
+ // sdn::runtime::Aligned::StorageExpireParams p{};
12
+ // sdm_piv::put(p.SCHEMA, "WXF.fbs"); p.set_has_SCHEMA(true);
13
+ // p.BEFORE_MS = cutoff_ms;
14
+ // auto r = sdm_piv::call("storage.expire", "StorageExpireParams", p);
15
+ // if (const auto* out = r.result<sdn::runtime::Aligned::StorageExpireResult>()) { out->DELETED; } else { r.error_message(); }
16
+ //
17
+ // auto get = sdm_piv::call("http.request", "HttpParams", http, {sdm_piv::raw("url", url)});
18
+ // std::string_view body = get.raw("body");
19
+ #ifndef SDM_PIV_HOSTCALL_HPP
20
+ #define SDM_PIV_HOSTCALL_HPP
21
+
22
+ #include <cstdint>
23
+ #include <cstring>
24
+ #include <initializer_list>
25
+ #include <string>
26
+ #include <string_view>
27
+ #include <utility>
28
+ #include <vector>
29
+
30
+ #include "sds/PIV/main_generated.h"
31
+ #include "HostOps_aligned.h"
32
+
33
+ extern "C" {
34
+ #if defined(__wasm__)
35
+ __attribute__((import_module("space_data_module_host"), import_name("call")))
36
+ #endif
37
+ int32_t sdm_piv_host_call(const uint8_t* op_ptr, int32_t op_len, const uint8_t* payload_ptr, int32_t payload_len);
38
+ #if defined(__wasm__)
39
+ __attribute__((import_module("space_data_module_host"), import_name("response_len")))
40
+ #endif
41
+ int32_t sdm_piv_host_response_len(void);
42
+ #if defined(__wasm__)
43
+ __attribute__((import_module("space_data_module_host"), import_name("read_response")))
44
+ #endif
45
+ int32_t sdm_piv_host_read_response(uint8_t* dst_ptr, int32_t dst_len);
46
+ }
47
+
48
+ namespace sdm_piv {
49
+
50
+ constexpr uint32_t kArenaAlignment = 8; // the SDK invoke codec's PAYLOAD_ARENA alignment (INVOKE_ARENA_ALIGNMENT)
51
+ constexpr const char* kHostOpsSchema = "HostOps.fbs";
52
+
53
+ /// Set an aligned string; false (and the field left empty) when the value does not fit - never truncated.
54
+ template <size_t N>
55
+ inline bool put(flatbuffers::aligned_runtime::AlignedString<N>& field, std::string_view value) {
56
+ if (value.size() > N) { field.clear(); return false; }
57
+ field.set(std::string(value));
58
+ return true;
59
+ }
60
+
61
+ /// A frame of the call: an aligned record or a run of them (root_type set), or raw bytes (root_type null).
62
+ struct Frame {
63
+ const char* port;
64
+ const uint8_t* data;
65
+ size_t size;
66
+ const char* root_type = nullptr;
67
+ uint32_t byte_length = 0; // the record stride; 0 = a run of records (a variable-length aligned stream)
68
+ uint16_t alignment = 1;
69
+ };
70
+ inline Frame raw(const char* port, std::string_view bytes) {
71
+ return {port, reinterpret_cast<const uint8_t*>(bytes.data()), bytes.size()};
72
+ }
73
+ inline Frame raw(const char* port, const uint8_t* data, size_t size) { return {port, data, size}; }
74
+ /// A list port: `count` records of T back to back.
75
+ template <typename T>
76
+ inline Frame list(const char* port, const char* root_type, const T* items, size_t count) {
77
+ return {port, reinterpret_cast<const uint8_t*>(items), sizeof(T) * count, root_type, 0, static_cast<uint16_t>(alignof(T))};
78
+ }
79
+
80
+ /// The host's $PIV response.
81
+ class Response {
82
+ public:
83
+ explicit Response(std::vector<uint8_t> bytes, std::string transport_error = {})
84
+ : bytes_(std::move(bytes)), error_(std::move(transport_error)) {
85
+ if (!error_.empty()) return;
86
+ flatbuffers::Verifier verifier(bytes_.data(), bytes_.size());
87
+ if (!VerifyPIVBuffer(verifier) || !GetPIV(bytes_.data())->RESPONSE()) error_ = "host answered without a $PIV response";
88
+ }
89
+ const PIVResponse* get() const { return error_.empty() ? GetPIV(bytes_.data())->RESPONSE() : nullptr; }
90
+ bool ok() const { const auto* r = get(); return r && r->STATUS() == pivStatus_OK && !r->ERROR_CODE(); }
91
+ std::string error_code() const {
92
+ const auto* r = get();
93
+ return !r ? "failed" : r->ERROR_CODE() ? r->ERROR_CODE()->str() : (ok() ? "" : "failed");
94
+ }
95
+ std::string error_message() const {
96
+ if (!error_.empty()) return error_;
97
+ const auto* r = get();
98
+ return r && r->ERROR_MESSAGE() ? r->ERROR_MESSAGE()->str() : std::string();
99
+ }
100
+ /// The bytes of output port `port` (empty when the call failed or the port is absent).
101
+ std::string_view raw(const char* port) const {
102
+ const auto [data, size] = frame(port, nullptr);
103
+ return {reinterpret_cast<const char*>(data), size};
104
+ }
105
+ /// The "result" record as T, read in place (nullptr when the call failed or the frame is not one T).
106
+ template <typename T>
107
+ const T* result(const char* root_type = nullptr) const {
108
+ const auto [data, size] = frame("result", root_type);
109
+ return data && size == sizeof(T) && reinterpret_cast<uintptr_t>(data) % alignof(T) == 0 ? T::fromBytes(data) : nullptr;
110
+ }
111
+ /// A list port as `count` records of T, read in place.
112
+ template <typename T>
113
+ std::pair<const T*, size_t> list(const char* port, const char* root_type = nullptr) const {
114
+ const auto [data, size] = frame(port, root_type);
115
+ if (!data || size % sizeof(T) || reinterpret_cast<uintptr_t>(data) % alignof(T)) return {nullptr, 0};
116
+ return {T::fromBytes(data), size / sizeof(T)};
117
+ }
118
+
119
+ private:
120
+ std::pair<const uint8_t*, size_t> frame(const char* port, const char* root_type) const {
121
+ const auto* r = get();
122
+ if (!ok() || !r->OUTPUTS() || !r->PAYLOAD_ARENA()) return {nullptr, 0};
123
+ for (const auto* tab : *r->OUTPUTS()) {
124
+ if (!tab->PORT_ID() || tab->PORT_ID()->str() != port) continue;
125
+ if (root_type && (!tab->TYPE_REF() || !tab->TYPE_REF()->ROOT_TYPE() || tab->TYPE_REF()->ROOT_TYPE()->str() != root_type)) return {nullptr, 0};
126
+ const uint64_t end = static_cast<uint64_t>(tab->OFFSET()) + tab->SIZE();
127
+ if (end > r->PAYLOAD_ARENA()->size()) return {nullptr, 0};
128
+ return {r->PAYLOAD_ARENA()->data() + tab->OFFSET(), tab->SIZE()};
129
+ }
130
+ return {nullptr, 0};
131
+ }
132
+ std::vector<uint8_t> bytes_;
133
+ std::string error_;
134
+ };
135
+
136
+ /// Call an operation with its frames (the "params" record first when it takes one - see call() below).
137
+ inline Response call_frames(const char* op, const std::vector<Frame>& frames) {
138
+ std::vector<uint8_t> arena;
139
+ std::vector<TABT> tabs;
140
+ for (const Frame& f : frames) {
141
+ const uint32_t align = f.alignment > kArenaAlignment ? f.alignment : kArenaAlignment;
142
+ arena.resize((arena.size() + align - 1) / align * align, 0);
143
+ TABT tab;
144
+ tab.OFFSET = static_cast<uint32_t>(arena.size());
145
+ tab.SIZE = static_cast<uint32_t>(f.size);
146
+ tab.ALIGNMENT = align;
147
+ tab.PORT_ID = f.port;
148
+ if (f.root_type) {
149
+ tab.WIRE_FORMAT = payloadWireFormat_ALIGNED_BINARY;
150
+ tab.TYPE_REF = std::make_unique<FlatBufferTypeRefT>();
151
+ tab.TYPE_REF->SCHEMA_NAME = kHostOpsSchema;
152
+ tab.TYPE_REF->ROOT_TYPE = f.root_type;
153
+ tab.TYPE_REF->WIRE_FORMAT = payloadWireFormat_ALIGNED_BINARY;
154
+ tab.TYPE_REF->BYTE_LENGTH = f.byte_length;
155
+ tab.TYPE_REF->REQUIRED_ALIGNMENT = f.alignment;
156
+ }
157
+ arena.insert(arena.end(), f.data, f.data + f.size);
158
+ tabs.push_back(std::move(tab));
159
+ }
160
+ flatbuffers::FlatBufferBuilder b(arena.size() + 256 * (tabs.size() + 1));
161
+ flatbuffers::Offset<flatbuffers::Vector<uint8_t>> arena_vector;
162
+ if (!arena.empty()) {
163
+ b.ForceVectorAlignment(arena.size(), sizeof(uint8_t), kArenaAlignment);
164
+ arena_vector = b.CreateVector(arena);
165
+ }
166
+ std::vector<flatbuffers::Offset<TAB>> inputs;
167
+ for (const TABT& tab : tabs) inputs.push_back(CreateTAB(b, &tab));
168
+ const auto inputs_vector = b.CreateVector(inputs);
169
+ const auto method = b.CreateString(op);
170
+ PIVRequestBuilder request(b);
171
+ request.add_METHOD_ID(method);
172
+ request.add_INPUTS(inputs_vector);
173
+ if (!arena.empty()) request.add_PAYLOAD_ARENA(arena_vector);
174
+ const auto request_offset = request.Finish();
175
+ PIVBuilder piv(b);
176
+ piv.add_REQUEST(request_offset);
177
+ FinishPIVBuffer(b, piv.Finish());
178
+
179
+ sdm_piv_host_call(reinterpret_cast<const uint8_t*>(op), static_cast<int32_t>(std::strlen(op)), b.GetBufferPointer(),
180
+ static_cast<int32_t>(b.GetSize()));
181
+ const int32_t len = sdm_piv_host_response_len();
182
+ if (len <= 0) return Response({}, "host returned no response");
183
+ std::vector<uint8_t> bytes(static_cast<size_t>(len));
184
+ if (sdm_piv_host_read_response(bytes.data(), len) != len) return Response({}, "host response was truncated");
185
+ return Response(std::move(bytes));
186
+ }
187
+
188
+ /// Call an operation with its "params" record (aligned type `params_type`) and any list / raw frames.
189
+ template <typename Params>
190
+ inline Response call(const char* op, const char* params_type, const Params& params, std::initializer_list<Frame> more = {}) {
191
+ std::vector<Frame> frames{{"params", reinterpret_cast<const uint8_t*>(&params), sizeof(Params), params_type,
192
+ static_cast<uint32_t>(sizeof(Params)), static_cast<uint16_t>(alignof(Params))}};
193
+ frames.insert(frames.end(), more.begin(), more.end());
194
+ return call_frames(op, frames);
195
+ }
196
+ /// Call an operation without a "params" record (clock.now, plugin.getConfig, filesystem.readFile with raw "path", ...).
197
+ inline Response call(const char* op, std::initializer_list<Frame> frames = {}) { return call_frames(op, std::vector<Frame>(frames)); }
198
+
199
+ } // namespace sdm_piv
200
+
201
+ #endif // SDM_PIV_HOSTCALL_HPP