space-data-module-sdk 0.8.3 → 0.8.5

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 (354) hide show
  1. package/README.md +117 -20
  2. package/bin/space-data-module.js +263 -0
  3. package/docs/.nojekyll +1 -0
  4. package/docs/AGENTS.md +34 -0
  5. package/docs/architecture.svg +141 -0
  6. package/docs/browser-wasmedge-isomorphic.md +179 -0
  7. package/docs/flatsql-streaming-standard.md +341 -0
  8. package/docs/gpu-module-abi.md +193 -0
  9. package/docs/index.html +125 -0
  10. package/docs/isomorphic-pthreads.md +188 -0
  11. package/docs/isomorphic-sdn-runtime-plan.md +167 -0
  12. package/docs/language-runtime-matrix.md +82 -0
  13. package/docs/manifest-structure.svg +114 -0
  14. package/docs/module-bundle-runtime-plan.md +19 -0
  15. package/docs/module-lifecycle.svg +70 -0
  16. package/docs/module-publication-standard.md +540 -0
  17. package/docs/node-red-default-node-parity.md +88 -0
  18. package/docs/protocol-installation.md +196 -0
  19. package/docs/secrets-capability.md +152 -0
  20. package/docs/styles.css +288 -0
  21. package/docs/testing-harness.md +408 -0
  22. package/docs/tri-runtime-parity.md +132 -0
  23. package/docs/wallet-callback.html +2 -0
  24. package/package.json +26 -6
  25. package/schemas/HttpRequestAbi.fbs +41 -0
  26. package/schemas/HttpResponseAbi.fbs +36 -0
  27. package/schemas/PluginManifest.fbs +2 -1
  28. package/src/AGENTS.md +1 -1
  29. package/src/app/codec.js +548 -0
  30. package/src/app/index.js +6 -0
  31. package/src/browser.js +5 -0
  32. package/src/bundle/constants.js +1 -0
  33. package/src/bundle/index.js +15 -0
  34. package/src/bundle/sigdomain.js +179 -0
  35. package/src/bundle/signing.js +767 -0
  36. package/src/bundle/wasm.js +3 -2
  37. package/src/capabilities.js +3 -0
  38. package/src/compat/index.js +7 -0
  39. package/src/compat/sdnLegacy.js +449 -0
  40. package/src/compiler/compileModule.js +556 -55
  41. package/src/compiler/flatcSupport.js +41 -27
  42. package/src/compiler/index.d.ts +2 -0
  43. package/src/compiler/index.js +18 -0
  44. package/src/compiler/invokeGlue.js +1212 -183
  45. package/src/compiler/pthreadArtifactGuard.js +910 -0
  46. package/src/compiler/sdnShimGenerator.js +323 -0
  47. package/src/compiler/wasiThreadsToolchain.js +150 -0
  48. package/src/compliance/index.js +11 -1
  49. package/src/compliance/legacyWildcardPorts.js +228 -0
  50. package/src/compliance/pluginCompliance.js +1000 -96
  51. package/src/field-stream/index.d.ts +31 -0
  52. package/src/field-stream/index.js +119 -0
  53. package/src/flow/dependencyStreamBridge.js +234 -0
  54. package/src/flow/flatsqlLinkShim.js +304 -0
  55. package/src/flow/flowCodec.js +107 -0
  56. package/src/flow/flowCompiler.js +2900 -0
  57. package/src/flow/flowRuntimeHost.js +877 -0
  58. package/src/flow/index.d.ts +117 -0
  59. package/src/flow/index.js +31 -0
  60. package/src/flow/isomorphicFlowHost.js +384 -0
  61. package/src/flow/jsFlowRuntime.js +275 -0
  62. package/src/flow/normalize.js +294 -0
  63. package/src/flow/runtime-src/flow_runtime.cpp +1699 -0
  64. package/src/flow/vendor/sdn-flow/MethodRegistry.js +400 -0
  65. package/src/flow/vendor/sdn-flow/constants.js +39 -0
  66. package/src/flow/vendor/sdn-flow/index.js +29 -0
  67. package/src/flow/vendor/sdn-flow/normalize.js +506 -0
  68. package/src/flow/vendor/sdn-flow/wasmCompatibility.js +189 -0
  69. package/src/generated/http/cpp/HttpRequestAbi_generated.h +285 -0
  70. package/src/generated/http/cpp/HttpResponseAbi_generated.h +192 -0
  71. package/src/generated/http/sdn/http/http-header.js +53 -0
  72. package/src/generated/http/sdn/http/http-header.ts +67 -0
  73. package/src/generated/http/sdn/http/http-request.js +132 -0
  74. package/src/generated/http/sdn/http/http-request.ts +179 -0
  75. package/src/generated/http/sdn/http/http-response.js +144 -0
  76. package/src/generated/http/sdn/http/http-response.ts +168 -0
  77. package/src/generated/http/sdn/http.js +11 -0
  78. package/src/generated/http/sdn/http.ts +4 -0
  79. package/src/generated/orbpro/flow/backpressure-policy.d.ts +12 -0
  80. package/src/generated/orbpro/flow/backpressure-policy.d.ts.map +1 -0
  81. package/src/generated/orbpro/flow/backpressure-policy.js +17 -0
  82. package/src/generated/orbpro/flow/backpressure-policy.js.map +1 -0
  83. package/src/generated/orbpro/flow/backpressure-policy.ts +15 -0
  84. package/src/generated/orbpro/flow/flow-bundle-manifest.d.ts +142 -0
  85. package/src/generated/orbpro/flow/flow-bundle-manifest.d.ts.map +1 -0
  86. package/src/generated/orbpro/flow/flow-bundle-manifest.js +304 -0
  87. package/src/generated/orbpro/flow/flow-bundle-manifest.js.map +1 -0
  88. package/src/generated/orbpro/flow/flow-bundle-manifest.ts +399 -0
  89. package/src/generated/orbpro/flow/flow-edge.d.ts +113 -0
  90. package/src/generated/orbpro/flow/flow-edge.d.ts.map +1 -0
  91. package/src/generated/orbpro/flow/flow-edge.js +221 -0
  92. package/src/generated/orbpro/flow/flow-edge.js.map +1 -0
  93. package/src/generated/orbpro/flow/flow-edge.ts +292 -0
  94. package/src/generated/orbpro/flow/flow-node.d.ts +80 -0
  95. package/src/generated/orbpro/flow/flow-node.d.ts.map +1 -0
  96. package/src/generated/orbpro/flow/flow-node.js +158 -0
  97. package/src/generated/orbpro/flow/flow-node.js.map +1 -0
  98. package/src/generated/orbpro/flow/flow-node.ts +202 -0
  99. package/src/generated/orbpro/flow/flow-program.d.ts +164 -0
  100. package/src/generated/orbpro/flow/flow-program.d.ts.map +1 -0
  101. package/src/generated/orbpro/flow/flow-program.js +350 -0
  102. package/src/generated/orbpro/flow/flow-program.js.map +1 -0
  103. package/src/generated/orbpro/flow/flow-program.ts +477 -0
  104. package/src/generated/orbpro/flow/flow-trigger.d.ts +108 -0
  105. package/src/generated/orbpro/flow/flow-trigger.d.ts.map +1 -0
  106. package/src/generated/orbpro/flow/flow-trigger.js +207 -0
  107. package/src/generated/orbpro/flow/flow-trigger.js.map +1 -0
  108. package/src/generated/orbpro/flow/flow-trigger.ts +276 -0
  109. package/src/generated/orbpro/flow/node-kind.d.ts +13 -0
  110. package/src/generated/orbpro/flow/node-kind.d.ts.map +1 -0
  111. package/src/generated/orbpro/flow/node-kind.js +16 -0
  112. package/src/generated/orbpro/flow/node-kind.js.map +1 -0
  113. package/src/generated/orbpro/{invoke.ts → flow/node-kind.ts} +12 -2
  114. package/src/generated/orbpro/flow/plugin-version-binding.d.ts +52 -0
  115. package/src/generated/orbpro/flow/plugin-version-binding.d.ts.map +1 -0
  116. package/src/generated/orbpro/flow/plugin-version-binding.js +85 -0
  117. package/src/generated/orbpro/flow/plugin-version-binding.js.map +1 -0
  118. package/src/generated/orbpro/flow/plugin-version-binding.ts +121 -0
  119. package/src/generated/orbpro/flow/schema-hash-binding.d.ts +70 -0
  120. package/src/generated/orbpro/flow/schema-hash-binding.d.ts.map +1 -0
  121. package/src/generated/orbpro/flow/schema-hash-binding.js +143 -0
  122. package/src/generated/orbpro/flow/schema-hash-binding.js.map +1 -0
  123. package/src/generated/orbpro/flow/schema-hash-binding.ts +189 -0
  124. package/src/generated/orbpro/flow/trigger-binding.d.ts +71 -0
  125. package/src/generated/orbpro/flow/trigger-binding.d.ts.map +1 -0
  126. package/src/generated/orbpro/flow/trigger-binding.js +142 -0
  127. package/src/generated/orbpro/flow/trigger-binding.js.map +1 -0
  128. package/src/generated/orbpro/flow/trigger-binding.ts +181 -0
  129. package/src/generated/orbpro/flow/trigger-kind.d.ts +14 -0
  130. package/src/generated/orbpro/flow/trigger-kind.d.ts.map +1 -0
  131. package/src/generated/orbpro/flow/trigger-kind.js +17 -0
  132. package/src/generated/orbpro/flow/trigger-kind.js.map +1 -0
  133. package/src/generated/orbpro/flow/trigger-kind.ts +17 -0
  134. package/src/generated/orbpro/flow.d.ts +21 -0
  135. package/src/generated/orbpro/flow.d.ts.map +1 -0
  136. package/src/generated/orbpro/flow.js +23 -0
  137. package/src/generated/orbpro/flow.js.map +1 -0
  138. package/src/generated/orbpro/flow.ts +24 -0
  139. package/src/generated/orbpro/manifest/capability-kind.d.ts +2 -1
  140. package/src/generated/orbpro/manifest/capability-kind.js +1 -0
  141. package/src/generated/orbpro/manifest/capability-kind.ts +1 -0
  142. package/src/generated/orbpro/plugin/stream-invoke-request.d.ts +93 -0
  143. package/src/generated/orbpro/plugin/stream-invoke-request.js +160 -0
  144. package/src/generated/orbpro/plugin/stream-invoke-request.ts +211 -0
  145. package/src/generated/orbpro/plugin/stream-invoke-response.d.ts +99 -0
  146. package/src/generated/orbpro/plugin/stream-invoke-response.js +175 -0
  147. package/src/generated/orbpro/plugin/stream-invoke-response.ts +226 -0
  148. package/src/generated/orbpro/plugin.js +8 -0
  149. package/src/generated/orbpro/stream.d.ts +12 -0
  150. package/src/generated/orbpro/stream.js +14 -0
  151. package/src/generated/orbpro/stream.ts +15 -0
  152. package/src/generated/spacedatastandards/plg/EntryFunction.d.ts +52 -0
  153. package/src/generated/spacedatastandards/plg/EntryFunction.d.ts.map +1 -0
  154. package/src/generated/spacedatastandards/plg/EntryFunction.js +106 -0
  155. package/src/generated/spacedatastandards/plg/EntryFunction.ts +162 -0
  156. package/src/generated/spacedatastandards/plg/FlatBufferTypeRef.d.ts +90 -0
  157. package/src/generated/spacedatastandards/plg/FlatBufferTypeRef.d.ts.map +1 -0
  158. package/src/generated/spacedatastandards/plg/FlatBufferTypeRef.js +189 -0
  159. package/src/generated/spacedatastandards/plg/FlatBufferTypeRef.ts +270 -0
  160. package/src/generated/spacedatastandards/plg/PLG.d.ts +492 -0
  161. package/src/generated/spacedatastandards/plg/PLG.d.ts.map +1 -0
  162. package/src/generated/spacedatastandards/plg/PLG.js +1139 -0
  163. package/src/generated/spacedatastandards/plg/PLG.ts +1600 -0
  164. package/src/generated/spacedatastandards/plg/PLGAcceptedTypeSet.d.ts +63 -0
  165. package/src/generated/spacedatastandards/plg/PLGAcceptedTypeSet.d.ts.map +1 -0
  166. package/src/generated/spacedatastandards/plg/PLGAcceptedTypeSet.js +138 -0
  167. package/src/generated/spacedatastandards/plg/PLGAcceptedTypeSet.ts +189 -0
  168. package/src/generated/spacedatastandards/plg/PLGBuildArtifact.d.ts +41 -0
  169. package/src/generated/spacedatastandards/plg/PLGBuildArtifact.d.ts.map +1 -0
  170. package/src/generated/spacedatastandards/plg/PLGBuildArtifact.js +104 -0
  171. package/src/generated/spacedatastandards/plg/PLGBuildArtifact.ts +151 -0
  172. package/src/generated/spacedatastandards/plg/PLGFlowEdge.d.ts +68 -0
  173. package/src/generated/spacedatastandards/plg/PLGFlowEdge.d.ts.map +1 -0
  174. package/src/generated/spacedatastandards/plg/PLGFlowEdge.js +124 -0
  175. package/src/generated/spacedatastandards/plg/PLGFlowEdge.ts +184 -0
  176. package/src/generated/spacedatastandards/plg/PLGFlowEdgeContract.d.ts +58 -0
  177. package/src/generated/spacedatastandards/plg/PLGFlowEdgeContract.d.ts.map +1 -0
  178. package/src/generated/spacedatastandards/plg/PLGFlowEdgeContract.js +126 -0
  179. package/src/generated/spacedatastandards/plg/PLGFlowEdgeContract.ts +161 -0
  180. package/src/generated/spacedatastandards/plg/PLGFlowNode.d.ts +82 -0
  181. package/src/generated/spacedatastandards/plg/PLGFlowNode.d.ts.map +1 -0
  182. package/src/generated/spacedatastandards/plg/PLGFlowNode.js +164 -0
  183. package/src/generated/spacedatastandards/plg/PLGFlowNode.ts +244 -0
  184. package/src/generated/spacedatastandards/plg/PLGFlowTrigger.d.ts +55 -0
  185. package/src/generated/spacedatastandards/plg/PLGFlowTrigger.d.ts.map +1 -0
  186. package/src/generated/spacedatastandards/plg/PLGFlowTrigger.js +105 -0
  187. package/src/generated/spacedatastandards/plg/PLGFlowTrigger.ts +162 -0
  188. package/src/generated/spacedatastandards/plg/PLGFlowTriggerBinding.d.ts +42 -0
  189. package/src/generated/spacedatastandards/plg/PLGFlowTriggerBinding.d.ts.map +1 -0
  190. package/src/generated/spacedatastandards/plg/PLGFlowTriggerBinding.js +83 -0
  191. package/src/generated/spacedatastandards/plg/PLGFlowTriggerBinding.ts +127 -0
  192. package/src/generated/spacedatastandards/plg/PLGHostCapability.d.ts +36 -0
  193. package/src/generated/spacedatastandards/plg/PLGHostCapability.d.ts.map +1 -0
  194. package/src/generated/spacedatastandards/plg/PLGHostCapability.js +90 -0
  195. package/src/generated/spacedatastandards/plg/PLGHostCapability.ts +127 -0
  196. package/src/generated/spacedatastandards/plg/PLGMethodManifest.d.ts +53 -0
  197. package/src/generated/spacedatastandards/plg/PLGMethodManifest.d.ts.map +1 -0
  198. package/src/generated/spacedatastandards/plg/PLGMethodManifest.js +153 -0
  199. package/src/generated/spacedatastandards/plg/PLGMethodManifest.ts +210 -0
  200. package/src/generated/spacedatastandards/plg/PLGPortManifest.d.ts +70 -0
  201. package/src/generated/spacedatastandards/plg/PLGPortManifest.d.ts.map +1 -0
  202. package/src/generated/spacedatastandards/plg/PLGPortManifest.js +149 -0
  203. package/src/generated/spacedatastandards/plg/PLGPortManifest.ts +212 -0
  204. package/src/generated/spacedatastandards/plg/PLGProtocolSpec.d.ts +73 -0
  205. package/src/generated/spacedatastandards/plg/PLGProtocolSpec.d.ts.map +1 -0
  206. package/src/generated/spacedatastandards/plg/PLGProtocolSpec.js +199 -0
  207. package/src/generated/spacedatastandards/plg/PLGProtocolSpec.ts +292 -0
  208. package/src/generated/spacedatastandards/plg/PLGTimerSpec.d.ts +40 -0
  209. package/src/generated/spacedatastandards/plg/PLGTimerSpec.d.ts.map +1 -0
  210. package/src/generated/spacedatastandards/plg/PLGTimerSpec.js +103 -0
  211. package/src/generated/spacedatastandards/plg/PLGTimerSpec.ts +148 -0
  212. package/src/generated/spacedatastandards/plg/PluginCapability.d.ts +41 -0
  213. package/src/generated/spacedatastandards/plg/PluginCapability.d.ts.map +1 -0
  214. package/src/generated/spacedatastandards/plg/PluginCapability.js +82 -0
  215. package/src/generated/spacedatastandards/plg/{plugin-capability.ts → PluginCapability.ts} +55 -18
  216. package/src/generated/spacedatastandards/plg/PluginDependency.d.ts +42 -0
  217. package/src/generated/spacedatastandards/plg/PluginDependency.d.ts.map +1 -0
  218. package/src/generated/spacedatastandards/plg/PluginDependency.js +80 -0
  219. package/src/generated/spacedatastandards/plg/PluginDependency.ts +124 -0
  220. package/src/generated/spacedatastandards/plg/TAB.d.ts +85 -0
  221. package/src/generated/spacedatastandards/plg/TAB.d.ts.map +1 -0
  222. package/src/generated/spacedatastandards/plg/TAB.js +173 -0
  223. package/src/generated/spacedatastandards/plg/TAB.ts +228 -0
  224. package/src/generated/spacedatastandards/plg/bufferMutability.d.ts +18 -0
  225. package/src/generated/spacedatastandards/plg/bufferMutability.d.ts.map +1 -0
  226. package/src/generated/spacedatastandards/plg/bufferMutability.js +20 -0
  227. package/src/generated/spacedatastandards/plg/bufferMutability.ts +23 -0
  228. package/src/generated/spacedatastandards/plg/bufferOwnership.d.ts +18 -0
  229. package/src/generated/spacedatastandards/plg/bufferOwnership.d.ts.map +1 -0
  230. package/src/generated/spacedatastandards/plg/bufferOwnership.js +20 -0
  231. package/src/generated/spacedatastandards/plg/bufferOwnership.ts +23 -0
  232. package/src/generated/spacedatastandards/plg/drainBehavior.d.ts +20 -0
  233. package/src/generated/spacedatastandards/plg/drainBehavior.d.ts.map +1 -0
  234. package/src/generated/spacedatastandards/plg/drainBehavior.js +22 -0
  235. package/src/generated/spacedatastandards/plg/drainBehavior.ts +25 -0
  236. package/src/generated/spacedatastandards/plg/flowEdgeRoutePolicy.d.ts +10 -0
  237. package/src/generated/spacedatastandards/plg/flowEdgeRoutePolicy.d.ts.map +1 -0
  238. package/src/generated/spacedatastandards/plg/flowEdgeRoutePolicy.js +12 -0
  239. package/src/generated/spacedatastandards/plg/flowEdgeRoutePolicy.ts +13 -0
  240. package/src/generated/spacedatastandards/plg/hostCapabilityKind.d.ts +51 -0
  241. package/src/generated/spacedatastandards/plg/hostCapabilityKind.d.ts.map +1 -0
  242. package/src/generated/spacedatastandards/plg/hostCapabilityKind.js +53 -0
  243. package/src/generated/spacedatastandards/plg/hostCapabilityKind.ts +55 -0
  244. package/src/generated/spacedatastandards/plg/invokeSurfaceKind.d.ts +15 -0
  245. package/src/generated/spacedatastandards/plg/invokeSurfaceKind.d.ts.map +1 -0
  246. package/src/generated/spacedatastandards/plg/invokeSurfaceKind.js +17 -0
  247. package/src/generated/spacedatastandards/plg/invokeSurfaceKind.ts +19 -0
  248. package/src/generated/spacedatastandards/plg/main.d.ts +29 -0
  249. package/src/generated/spacedatastandards/plg/main.d.ts.map +1 -0
  250. package/src/generated/spacedatastandards/plg/main.js +30 -0
  251. package/src/generated/spacedatastandards/plg/main.ts +32 -0
  252. package/src/generated/spacedatastandards/plg/payloadWireFormat.d.ts +17 -0
  253. package/src/generated/spacedatastandards/plg/payloadWireFormat.d.ts.map +1 -0
  254. package/src/generated/spacedatastandards/plg/payloadWireFormat.js +19 -0
  255. package/src/generated/spacedatastandards/plg/payloadWireFormat.ts +21 -0
  256. package/src/generated/spacedatastandards/plg/pluginCategory.d.ts +82 -0
  257. package/src/generated/spacedatastandards/plg/pluginCategory.d.ts.map +1 -0
  258. package/src/generated/spacedatastandards/plg/pluginCategory.js +84 -0
  259. package/src/generated/spacedatastandards/plg/pluginCategory.ts +103 -0
  260. package/src/generated/spacedatastandards/plg/publicationState.d.ts +18 -0
  261. package/src/generated/spacedatastandards/plg/publicationState.d.ts.map +1 -0
  262. package/src/generated/spacedatastandards/plg/publicationState.js +20 -0
  263. package/src/generated/spacedatastandards/plg/purchaseTier.d.ts +18 -0
  264. package/src/generated/spacedatastandards/plg/purchaseTier.d.ts.map +1 -0
  265. package/src/generated/spacedatastandards/plg/purchaseTier.js +20 -0
  266. package/src/host/AGENTS.md +2 -2
  267. package/src/host/abi.js +53 -66
  268. package/src/host/browserHost.js +355 -8
  269. package/src/host/cpp/keyslotClient.hpp +231 -0
  270. package/src/host/cpp/secretsClient.hpp +583 -0
  271. package/src/host/hostcallWire.js +183 -0
  272. package/src/host/index.js +2 -0
  273. package/src/host/isomorphicLoader.js +44 -7
  274. package/src/host/nodeHost.js +227 -8
  275. package/src/host/sabHostcallChannel.js +206 -0
  276. package/src/host/timerDriver.js +203 -0
  277. package/src/host/wasiShim.js +41 -1
  278. package/src/host/wasiThreadBrowserWorker.mjs +48 -0
  279. package/src/host/wasiThreadHost.js +393 -0
  280. package/src/host/wasiThreadWorker.mjs +32 -0
  281. package/src/host/wasiThreadWorkerRuntime.js +93 -0
  282. package/src/http/index.js +339 -0
  283. package/src/index.d.ts +716 -10
  284. package/src/index.js +4 -0
  285. package/src/invoke/codec.js +1202 -128
  286. package/src/invoke/index.js +5 -1
  287. package/src/licensing/index.d.ts +2 -0
  288. package/src/licensing/index.js +2 -0
  289. package/src/licensing/records.js +287 -8
  290. package/src/manifest/codec.js +62 -14
  291. package/src/manifest/index.js +2 -0
  292. package/src/manifest/legacyToPlg.js +164 -25
  293. package/src/manifest/normalize.js +1 -0
  294. package/src/manifest/plgCodec.js +1303 -62
  295. package/src/manifest/typeRefs.js +162 -24
  296. package/src/runtime/compiledRuntimeAbi.js +47 -0
  297. package/src/runtime/compiledRuntimeAbi.json +33 -0
  298. package/src/runtime/index.d.ts +32 -0
  299. package/src/runtime/index.js +1 -0
  300. package/src/runtime-host/index.js +3 -0
  301. package/src/runtime-host/methodRegistry.js +55 -0
  302. package/src/standards/index.js +200 -56
  303. package/src/standards/sharedCatalog.js +16 -0
  304. package/src/testing/browserModuleHarness.js +604 -31
  305. package/src/testing/docker/wasmedge-parity.Dockerfile +39 -0
  306. package/src/testing/index.d.ts +151 -0
  307. package/src/testing/index.js +21 -0
  308. package/src/testing/native/wasmedge_emscripten_pthread_runner.c +25 -1
  309. package/src/testing/parityBrowserRunner.js +138 -0
  310. package/src/testing/parityHarness.js +616 -0
  311. package/src/testing/parityLanes.js +537 -0
  312. package/src/testing/processInvoke.js +29 -21
  313. package/src/testing/streamInvokeCodec.js +10 -175
  314. package/src/testing/wasmedgePin.json +6 -0
  315. package/src/testing/workerModuleHarness.js +242 -0
  316. package/src/testing/workerModuleHarnessWorker.js +176 -0
  317. package/src/transport/index.js +3 -0
  318. package/src/transport/pki.js +299 -11
  319. package/src/transport/records.js +16 -7
  320. package/src/utils/ecdsaDer.js +106 -0
  321. package/src/utils/wasmCrypto.js +0 -43
  322. package/templates/gpu-module/README.md +48 -0
  323. package/templates/gpu-module/include/space_data_gpu_abi.h +122 -0
  324. package/templates/gpu-module/manifest.json +84 -0
  325. package/schemas/PluginInvokeRequest.fbs +0 -18
  326. package/schemas/PluginInvokeResponse.fbs +0 -30
  327. package/schemas/spacedatastandards/PLG.fbs +0 -191
  328. package/src/generated/orbpro/invoke/plugin-invoke-request.d.ts +0 -51
  329. package/src/generated/orbpro/invoke/plugin-invoke-request.d.ts.map +0 -1
  330. package/src/generated/orbpro/invoke/plugin-invoke-request.js +0 -131
  331. package/src/generated/orbpro/invoke/plugin-invoke-request.js.map +0 -1
  332. package/src/generated/orbpro/invoke/plugin-invoke-request.ts +0 -173
  333. package/src/generated/orbpro/invoke/plugin-invoke-response.d.ts +0 -76
  334. package/src/generated/orbpro/invoke/plugin-invoke-response.d.ts.map +0 -1
  335. package/src/generated/orbpro/invoke/plugin-invoke-response.js +0 -184
  336. package/src/generated/orbpro/invoke/plugin-invoke-response.js.map +0 -1
  337. package/src/generated/orbpro/invoke/plugin-invoke-response.ts +0 -243
  338. package/src/generated/orbpro/invoke.d.ts +0 -3
  339. package/src/generated/orbpro/invoke.js +0 -5
  340. package/src/generated/spacedatastandards/plg/entry-function.js +0 -86
  341. package/src/generated/spacedatastandards/plg/entry-function.ts +0 -119
  342. package/src/generated/spacedatastandards/plg/index.js +0 -16
  343. package/src/generated/spacedatastandards/plg/index.ts +0 -11
  344. package/src/generated/spacedatastandards/plg/plg.js +0 -657
  345. package/src/generated/spacedatastandards/plg/plg.ts +0 -924
  346. package/src/generated/spacedatastandards/plg/plugin-capability.js +0 -66
  347. package/src/generated/spacedatastandards/plg/plugin-category.js +0 -15
  348. package/src/generated/spacedatastandards/plg/plugin-category.ts +0 -53
  349. package/src/generated/spacedatastandards/plg/plugin-dependency.js +0 -63
  350. package/src/generated/spacedatastandards/plg/plugin-dependency.ts +0 -86
  351. package/src/generated/spacedatastandards/plg/publication-state.js +0 -9
  352. package/src/generated/spacedatastandards/plg/purchase-tier.js +0 -9
  353. /package/src/generated/spacedatastandards/plg/{publication-state.ts → publicationState.ts} +0 -0
  354. /package/src/generated/spacedatastandards/plg/{purchase-tier.ts → purchaseTier.ts} +0 -0
@@ -0,0 +1,206 @@
1
+ /**
2
+ * SharedArrayBuffer hostcall channel — the async in-WASM host bridge.
3
+ *
4
+ * Guest WASM modules issue synchronous `space_data_module_host.call`
5
+ * invocations, but browser host capabilities (http/ipfs/storage/pubsub/...)
6
+ * are async. This channel lets a guest running inside a Worker block while
7
+ * the async host operation resolves on the controlling thread:
8
+ *
9
+ * worker (guest thread) controlling thread (host)
10
+ * ───────────────────── ─────────────────────────
11
+ * dispatch(op, params):
12
+ * state ← PENDING
13
+ * postRequest({operation, params}) ────▶ onmessage:
14
+ * Atomics.wait(state == PENDING) value = await dispatch(op, params)
15
+ * write value envelope into SAB
16
+ * state ← DONE; Atomics.notify
17
+ * read + decode value envelope ◀────────┘
18
+ * return value (or throw on error status)
19
+ *
20
+ * The worker-side dispatch is synchronous, so it plugs directly into
21
+ * `createHostcallBridge({ dispatch })` (src/host/abi.js) — the existing
22
+ * envelope/error machinery is reused unchanged. `Atomics.wait` is illegal on
23
+ * the main thread, so the guest MUST run in a Worker (see
24
+ * src/testing/workerModuleHarness.js).
25
+ *
26
+ * Payloads cross the channel as hostcall value envelopes (hostcallWire.js),
27
+ * so binary leaves (Uint8Array) survive without base64/JSON round-trips.
28
+ */
29
+
30
+ import {
31
+ decodeHostcallValueEnvelope,
32
+ encodeHostcallValueEnvelope,
33
+ } from "./hostcallWire.js";
34
+
35
+ // Int32 header slots at the front of the SharedArrayBuffer.
36
+ const SLOT_STATE = 0;
37
+ const SLOT_STATUS = 1;
38
+ const SLOT_LENGTH = 2;
39
+ const HEADER_INT32S = 4; // one reserved slot keeps the data region 16-byte aligned
40
+
41
+ const STATE_IDLE = 0;
42
+ const STATE_PENDING = 1;
43
+ const STATE_DONE = 2;
44
+
45
+ export const SAB_HOSTCALL_STATUS_OK = 0;
46
+ export const SAB_HOSTCALL_STATUS_ERROR = 1;
47
+ export const SAB_HOSTCALL_DATA_OFFSET = HEADER_INT32S * 4;
48
+ export const DEFAULT_SAB_HOSTCALL_RESPONSE_BYTES = 4 * 1024 * 1024;
49
+
50
+ function assertSharedArrayBuffer(buffer) {
51
+ if (
52
+ typeof SharedArrayBuffer !== "function" ||
53
+ !(buffer instanceof SharedArrayBuffer)
54
+ ) {
55
+ throw new TypeError(
56
+ "SAB hostcall channel requires a SharedArrayBuffer (cross-origin isolation in browsers).",
57
+ );
58
+ }
59
+ }
60
+
61
+ function serializeChannelError(error, operation) {
62
+ return {
63
+ name: error?.name ?? "Error",
64
+ message: error?.message ?? String(error),
65
+ code: error?.code ?? null,
66
+ operation: error?.operation ?? operation ?? null,
67
+ capability: error?.capability ?? null,
68
+ };
69
+ }
70
+
71
+ /**
72
+ * Allocate the shared buffer backing one hostcall channel.
73
+ */
74
+ export function createSabHostcallBuffer(options = {}) {
75
+ if (typeof SharedArrayBuffer !== "function") {
76
+ throw new Error(
77
+ "SharedArrayBuffer is unavailable; the async hostcall bridge requires it " +
78
+ "(browsers additionally require cross-origin isolation: COOP+COEP).",
79
+ );
80
+ }
81
+ const maxResponseBytes = Number.isInteger(options.maxResponseBytes)
82
+ ? options.maxResponseBytes
83
+ : DEFAULT_SAB_HOSTCALL_RESPONSE_BYTES;
84
+ if (maxResponseBytes <= 0) {
85
+ throw new RangeError("maxResponseBytes must be a positive integer.");
86
+ }
87
+ return new SharedArrayBuffer(SAB_HOSTCALL_DATA_OFFSET + maxResponseBytes);
88
+ }
89
+
90
+ /**
91
+ * Worker-side half: a synchronous dispatch(operation, params) that blocks on
92
+ * Atomics.wait until the controlling thread services the request.
93
+ *
94
+ * options.postRequest({ operation, params }) must deliver the request to the
95
+ * controlling thread (postMessage). params/results are structured values with
96
+ * Uint8Array leaves.
97
+ */
98
+ export function createSabHostcallClientDispatch(options = {}) {
99
+ assertSharedArrayBuffer(options.buffer);
100
+ const postRequest = options.postRequest;
101
+ if (typeof postRequest !== "function") {
102
+ throw new TypeError(
103
+ "createSabHostcallClientDispatch requires a postRequest function.",
104
+ );
105
+ }
106
+ const timeoutMs =
107
+ Number.isFinite(options.timeoutMs) && options.timeoutMs > 0
108
+ ? options.timeoutMs
109
+ : 120_000;
110
+ const header = new Int32Array(options.buffer, 0, HEADER_INT32S);
111
+ const capacity = options.buffer.byteLength - SAB_HOSTCALL_DATA_OFFSET;
112
+
113
+ return function sabHostcallDispatch(operation, params = null) {
114
+ Atomics.store(header, SLOT_STATE, STATE_PENDING);
115
+ postRequest({ operation, params });
116
+ const outcome = Atomics.wait(header, SLOT_STATE, STATE_PENDING, timeoutMs);
117
+ if (outcome === "timed-out") {
118
+ Atomics.store(header, SLOT_STATE, STATE_IDLE);
119
+ throw new Error(
120
+ `Hostcall "${operation}" timed out after ${timeoutMs}ms waiting for the controlling thread.`,
121
+ );
122
+ }
123
+ const status = Atomics.load(header, SLOT_STATUS);
124
+ const length = Atomics.load(header, SLOT_LENGTH);
125
+ if (length < 0 || length > capacity) {
126
+ Atomics.store(header, SLOT_STATE, STATE_IDLE);
127
+ throw new RangeError(
128
+ `Hostcall "${operation}" response length ${length} exceeds channel capacity ${capacity}.`,
129
+ );
130
+ }
131
+ // Copy out of the SAB before decoding — decode keeps subarray views.
132
+ const bytes = new Uint8Array(length);
133
+ bytes.set(new Uint8Array(options.buffer, SAB_HOSTCALL_DATA_OFFSET, length));
134
+ Atomics.store(header, SLOT_STATE, STATE_IDLE);
135
+ const value = decodeHostcallValueEnvelope(bytes);
136
+ if (status !== SAB_HOSTCALL_STATUS_OK) {
137
+ const error = new Error(
138
+ value?.message ?? `Hostcall "${operation}" failed on the host thread.`,
139
+ );
140
+ error.name = value?.name ?? "Error";
141
+ error.code = value?.code ?? null;
142
+ error.operation = value?.operation ?? operation;
143
+ error.capability = value?.capability ?? null;
144
+ throw error;
145
+ }
146
+ return value;
147
+ };
148
+ }
149
+
150
+ /**
151
+ * Controlling-thread half: services one request at a time against an async
152
+ * dispatch (e.g. createAsyncHostDispatcher(host)) and wakes the worker.
153
+ */
154
+ export function createSabHostcallServer(options = {}) {
155
+ assertSharedArrayBuffer(options.buffer);
156
+ const dispatch = options.dispatch;
157
+ if (typeof dispatch !== "function") {
158
+ throw new TypeError("createSabHostcallServer requires a dispatch function.");
159
+ }
160
+ const header = new Int32Array(options.buffer, 0, HEADER_INT32S);
161
+ const capacity = options.buffer.byteLength - SAB_HOSTCALL_DATA_OFFSET;
162
+ const data = new Uint8Array(options.buffer, SAB_HOSTCALL_DATA_OFFSET, capacity);
163
+
164
+ function complete(status, bytes) {
165
+ data.set(bytes, 0);
166
+ Atomics.store(header, SLOT_STATUS, status);
167
+ Atomics.store(header, SLOT_LENGTH, bytes.length);
168
+ Atomics.store(header, SLOT_STATE, STATE_DONE);
169
+ Atomics.notify(header, SLOT_STATE);
170
+ }
171
+
172
+ async function handleRequest(request = {}) {
173
+ const operation = request.operation;
174
+ let status = SAB_HOSTCALL_STATUS_OK;
175
+ let value;
176
+ try {
177
+ value = await dispatch(operation, request.params ?? null);
178
+ if (value === undefined) value = null;
179
+ } catch (error) {
180
+ status = SAB_HOSTCALL_STATUS_ERROR;
181
+ value = serializeChannelError(error, operation);
182
+ }
183
+ let bytes;
184
+ try {
185
+ bytes = encodeHostcallValueEnvelope(value);
186
+ } catch (error) {
187
+ status = SAB_HOSTCALL_STATUS_ERROR;
188
+ bytes = encodeHostcallValueEnvelope(serializeChannelError(error, operation));
189
+ }
190
+ if (bytes.length > capacity) {
191
+ status = SAB_HOSTCALL_STATUS_ERROR;
192
+ bytes = encodeHostcallValueEnvelope(
193
+ serializeChannelError(
194
+ new RangeError(
195
+ `Hostcall response (${bytes.length} bytes) exceeds the channel capacity (${capacity} bytes); ` +
196
+ "raise maxHostcallResponseBytes on the worker harness.",
197
+ ),
198
+ operation,
199
+ ),
200
+ );
201
+ }
202
+ complete(status, bytes);
203
+ }
204
+
205
+ return { handleRequest };
206
+ }
@@ -0,0 +1,203 @@
1
+ /**
2
+ * Browser cron/timer driver (WS6.3).
3
+ *
4
+ * The node runtime re-invokes a module's manifest TIMERS through
5
+ * plugin_invoke_stream on a schedule (Go plugins.Manager.scheduleCronMethods).
6
+ * This is the browser-side counterpart: it reads the module's TIMERS
7
+ * (decoded PLG manifest), schedules an interval per enabled timer, and
8
+ * invokes the timer's method through the harness invoke surface
9
+ * (createBrowserModuleHarness / createWorkerModuleHarness `invoke`, i.e.
10
+ * plugin_invoke_stream).
11
+ *
12
+ * const driver = createModuleTimerDriver({
13
+ * harness, // or invoke: (request) => Promise
14
+ * manifestBytes, // or timers: [...] / manifest: {...}
15
+ * schedules: { "starlink-pull": { intervalMs: 1000 } },
16
+ * });
17
+ * driver.start();
18
+ * ...
19
+ * driver.stop();
20
+ *
21
+ * Semantics mirror the Go manager: one schedule per timer, runs are recorded
22
+ * ({trigger:"scheduled"|"manual", status:"ok"|"error"}), and runs of the same
23
+ * timer are serialized — a tick that lands while the previous invocation is
24
+ * still in flight is skipped (recorded as "skipped"). Unlike the Go manager,
25
+ * explicit schedule overrides are trusted (clamped only by minIntervalMs,
26
+ * default 1s) so tests and UIs can shorten long default cadences.
27
+ */
28
+
29
+ // Import the codec leaf, not manifest/index.js — the index pulls
30
+ // embeddedManifest.js (node:fs) and would break browser bundles.
31
+ import { decodePluginManifest } from "../manifest/codec.js";
32
+
33
+ const DEFAULT_MIN_INTERVAL_MS = 1_000;
34
+ const DEFAULT_MAX_RUN_HISTORY = 50;
35
+
36
+ function toIntervalMs(value) {
37
+ if (typeof value === "bigint") return Number(value);
38
+ const n = Number(value ?? 0);
39
+ return Number.isFinite(n) ? n : 0;
40
+ }
41
+
42
+ function normalizeTimer(timer) {
43
+ const timerId = String(timer?.timerId ?? timer?.timer_id ?? "").trim();
44
+ const methodId = String(timer?.methodId ?? timer?.method_id ?? "").trim();
45
+ if (!timerId || !methodId) return null;
46
+ return {
47
+ timerId,
48
+ methodId,
49
+ defaultIntervalMs: toIntervalMs(
50
+ timer.defaultIntervalMs ?? timer.default_interval_ms ?? 0,
51
+ ),
52
+ description: timer.description ?? "",
53
+ };
54
+ }
55
+
56
+ function resolveTimers(options) {
57
+ if (Array.isArray(options.timers)) {
58
+ return options.timers.map(normalizeTimer).filter(Boolean);
59
+ }
60
+ const manifest =
61
+ options.manifest ??
62
+ (options.manifestBytes ? decodePluginManifest(options.manifestBytes) : null);
63
+ const timers = Array.isArray(manifest?.timers) ? manifest.timers : [];
64
+ return timers.map(normalizeTimer).filter(Boolean);
65
+ }
66
+
67
+ export function createModuleTimerDriver(options = {}) {
68
+ const invoke =
69
+ typeof options.invoke === "function"
70
+ ? options.invoke
71
+ : typeof options.harness?.invoke === "function"
72
+ ? (request) => options.harness.invoke(request)
73
+ : null;
74
+ if (!invoke) {
75
+ throw new TypeError(
76
+ "createModuleTimerDriver requires an invoke function or a harness with invoke().",
77
+ );
78
+ }
79
+ const timers = resolveTimers(options);
80
+ const schedules =
81
+ options.schedules && typeof options.schedules === "object"
82
+ ? options.schedules
83
+ : {};
84
+ const minIntervalMs = Number.isFinite(options.minIntervalMs)
85
+ ? Math.max(1, options.minIntervalMs)
86
+ : DEFAULT_MIN_INTERVAL_MS;
87
+ const maxRunHistory = Number.isInteger(options.maxRunHistory)
88
+ ? options.maxRunHistory
89
+ : DEFAULT_MAX_RUN_HISTORY;
90
+ const setIntervalImpl = options.setIntervalImpl ?? globalThis.setInterval.bind(globalThis);
91
+ const clearIntervalImpl =
92
+ options.clearIntervalImpl ?? globalThis.clearInterval.bind(globalThis);
93
+ const now = typeof options.now === "function" ? options.now : () => Date.now();
94
+ const onRun = typeof options.onRun === "function" ? options.onRun : null;
95
+
96
+ const state = new Map(); // timerId -> { timer, intervalMs, enabled, handle, inFlight, runs }
97
+ for (const timer of timers) {
98
+ const override = schedules[timer.timerId] ?? {};
99
+ const enabled = override.enabled !== false;
100
+ const requested = toIntervalMs(override.intervalMs ?? timer.defaultIntervalMs);
101
+ const intervalMs = Math.max(minIntervalMs, requested);
102
+ state.set(timer.timerId, {
103
+ timer,
104
+ intervalMs,
105
+ enabled,
106
+ handle: null,
107
+ inFlight: false,
108
+ runs: [],
109
+ });
110
+ }
111
+
112
+ function record(entry, run) {
113
+ entry.runs.push(run);
114
+ if (entry.runs.length > maxRunHistory) {
115
+ entry.runs.splice(0, entry.runs.length - maxRunHistory);
116
+ }
117
+ if (onRun) onRun(run);
118
+ }
119
+
120
+ async function fire(entry, trigger) {
121
+ if (entry.inFlight) {
122
+ record(entry, {
123
+ timerId: entry.timer.timerId,
124
+ methodId: entry.timer.methodId,
125
+ trigger,
126
+ status: "skipped",
127
+ startedAt: now(),
128
+ finishedAt: now(),
129
+ message: "previous run still in flight",
130
+ });
131
+ return null;
132
+ }
133
+ entry.inFlight = true;
134
+ const run = {
135
+ timerId: entry.timer.timerId,
136
+ methodId: entry.timer.methodId,
137
+ trigger,
138
+ status: "running",
139
+ startedAt: now(),
140
+ };
141
+ try {
142
+ const response = await invoke({ methodId: entry.timer.methodId, inputs: [] });
143
+ run.status = "ok";
144
+ run.finishedAt = now();
145
+ return response;
146
+ } catch (error) {
147
+ run.status = "error";
148
+ run.message = error?.message ?? String(error);
149
+ run.finishedAt = now();
150
+ return null;
151
+ } finally {
152
+ entry.inFlight = false;
153
+ record(entry, run);
154
+ }
155
+ }
156
+
157
+ let started = false;
158
+
159
+ return {
160
+ listTimers() {
161
+ return [...state.values()].map((entry) => ({
162
+ timerId: entry.timer.timerId,
163
+ methodId: entry.timer.methodId,
164
+ description: entry.timer.description,
165
+ defaultIntervalMs: entry.timer.defaultIntervalMs,
166
+ intervalMs: entry.intervalMs,
167
+ enabled: entry.enabled,
168
+ scheduled: entry.handle !== null,
169
+ }));
170
+ },
171
+ runHistory(timerId) {
172
+ const entry = state.get(String(timerId ?? "").trim());
173
+ return entry ? entry.runs.map((run) => ({ ...run })) : [];
174
+ },
175
+ start() {
176
+ if (started) return this.listTimers();
177
+ started = true;
178
+ for (const entry of state.values()) {
179
+ if (!entry.enabled) continue;
180
+ entry.handle = setIntervalImpl(() => {
181
+ void fire(entry, "scheduled");
182
+ }, entry.intervalMs);
183
+ }
184
+ return this.listTimers();
185
+ },
186
+ async runNow(timerId) {
187
+ const entry = state.get(String(timerId ?? "").trim());
188
+ if (!entry) {
189
+ throw new Error(`Unknown timer: ${timerId}`);
190
+ }
191
+ return fire(entry, "manual");
192
+ },
193
+ stop() {
194
+ for (const entry of state.values()) {
195
+ if (entry.handle !== null) {
196
+ clearIntervalImpl(entry.handle);
197
+ entry.handle = null;
198
+ }
199
+ }
200
+ started = false;
201
+ },
202
+ };
203
+ }
@@ -5,10 +5,14 @@
5
5
  * WASI modules (the same .wasm that runs in WasmEdge) can be instantiated
6
6
  * directly in the browser via WebAssembly.instantiate().
7
7
  *
8
- * Covers the 11 imports observed across all SDN plugin standalone builds:
8
+ * Covers the preview1 imports observed across SDN plugin standalone builds:
9
9
  * clock_time_get, fd_write, fd_read, fd_close, fd_seek, fd_fdstat_get,
10
+ * fd_fdstat_set_flags, fd_prestat_get, fd_prestat_dir_name, path_open,
10
11
  * environ_sizes_get, environ_get, proc_exit, args_get, args_sizes_get,
11
12
  * random_get
13
+ *
14
+ * No filesystem is exposed: prestat/path_open report no preopened
15
+ * directories, so wasi-libc file APIs fail cleanly inside the guest.
12
16
  */
13
17
 
14
18
  const ERRNO_SUCCESS = 0;
@@ -156,6 +160,28 @@ export function createBrowserWasiShim(options = {}) {
156
160
  return ERRNO_SUCCESS;
157
161
  }
158
162
 
163
+ function fd_fdstat_set_flags(fd, _flags) {
164
+ if (fd <= 2) return ERRNO_SUCCESS;
165
+ return ERRNO_BADF;
166
+ }
167
+
168
+ // This browser shim exposes no ambient preopened directories. Toolchains
169
+ // commonly probe these preview1 calls during startup; returning BADF is
170
+ // the fail-closed WASI result and lets the guest continue without filesystem
171
+ // authority.
172
+ function fd_prestat_get(_fd, _bufPtr) {
173
+ return ERRNO_BADF;
174
+ }
175
+
176
+ function fd_prestat_dir_name(_fd, _pathPtr, _pathLen) {
177
+ return ERRNO_BADF;
178
+ }
179
+
180
+ function path_open() {
181
+ return ERRNO_BADF;
182
+ }
183
+
184
+
159
185
  function environ_sizes_get(countPtr, bufSizePtr) {
160
186
  const dv = view();
161
187
  dv.setUint32(countPtr, encodedEnvEntries.length, true);
@@ -223,6 +249,15 @@ export function createBrowserWasiShim(options = {}) {
223
249
  throw new WasiExitError(code);
224
250
  }
225
251
 
252
+ // wasm32-wasip1-threads (isomorphic-pthreads) modules import sched_yield —
253
+ // pthread spin/backoff loops call it. A cooperative no-op (yield to the
254
+ // engine) is the correct browser/Node semantics: real preemption is the
255
+ // host's job. Present on every shim so a threaded artifact instantiates
256
+ // (a missing import would fail instantiation for the whole module).
257
+ function sched_yield() {
258
+ return ERRNO_SUCCESS;
259
+ }
260
+
226
261
  // --- Output helpers ---
227
262
 
228
263
  function flushOutput() {
@@ -265,12 +300,17 @@ export function createBrowserWasiShim(options = {}) {
265
300
  fd_close,
266
301
  fd_seek,
267
302
  fd_fdstat_get,
303
+ fd_fdstat_set_flags,
304
+ fd_prestat_get,
305
+ fd_prestat_dir_name,
306
+ path_open,
268
307
  environ_sizes_get,
269
308
  environ_get,
270
309
  args_sizes_get,
271
310
  args_get,
272
311
  random_get,
273
312
  proc_exit,
313
+ sched_yield,
274
314
  },
275
315
  },
276
316
  setMemory,
@@ -0,0 +1,48 @@
1
+ import { createWasiThreadWorkerRuntime } from "./wasiThreadWorkerRuntime.js";
2
+
3
+ let wasmModule = null;
4
+ let memory = null;
5
+ let hostcallChannel = null;
6
+ let runtime = null;
7
+
8
+ self.onmessage = (event) => {
9
+ const message = event.data ?? {};
10
+ if (message.t === "probe") {
11
+ wasmModule = message.wasmModule;
12
+ memory = message.memory;
13
+ hostcallChannel = message.hostcallChannel ?? null;
14
+ try {
15
+ runtime = createWasiThreadWorkerRuntime({
16
+ wasmModule,
17
+ memory,
18
+ hostcallChannel,
19
+ });
20
+ runtime.instantiate();
21
+ self.postMessage({ t: "ready", ok: true });
22
+ } catch (error) {
23
+ runtime?.close();
24
+ runtime = null;
25
+ self.postMessage({
26
+ t: "ready",
27
+ ok: false,
28
+ error: String(error?.message ?? error),
29
+ });
30
+ }
31
+ return;
32
+ }
33
+ if (message.t !== "run") return;
34
+
35
+ try {
36
+ const instance = runtime.instantiate();
37
+ instance.exports.wasi_thread_start(message.tid, message.startArg);
38
+ } catch (error) {
39
+ if (!(error && error.name === "WasiExitError")) {
40
+ self.postMessage({
41
+ t: "error",
42
+ tid: message.tid,
43
+ error: String(error?.message ?? error),
44
+ });
45
+ }
46
+ }
47
+ self.postMessage({ t: "exit", tid: message.tid });
48
+ };