space-data-module-sdk 0.5.8 → 0.5.10

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.
@@ -0,0 +1,62 @@
1
+ import {
2
+ createPluginInvokeProcessClient,
3
+ resolveWasmEdgePluginLaunchPlan,
4
+ } from "./processInvoke.js";
5
+
6
+ function normalizeRuntimeDescriptor(options = {}) {
7
+ if (options.runtime && typeof options.runtime === "object") {
8
+ return options.runtime;
9
+ }
10
+ return options;
11
+ }
12
+
13
+ export function resolveModuleHarnessLaunchPlan(options = {}) {
14
+ const runtime = normalizeRuntimeDescriptor(options);
15
+ if (runtime.launchPlan && typeof runtime.launchPlan === "object") {
16
+ return runtime.launchPlan;
17
+ }
18
+
19
+ const kind = String(runtime.kind ?? "process").trim().toLowerCase();
20
+ if (kind === "wasmedge") {
21
+ return resolveWasmEdgePluginLaunchPlan(runtime);
22
+ }
23
+ if (kind === "process") {
24
+ if (typeof runtime.command !== "string" || runtime.command.trim().length === 0) {
25
+ throw new Error(
26
+ "resolveModuleHarnessLaunchPlan requires runtime.command for process runtimes.",
27
+ );
28
+ }
29
+ return {
30
+ command: runtime.command,
31
+ args: Array.isArray(runtime.args) ? runtime.args : [],
32
+ env: runtime.env,
33
+ cwd: runtime.cwd,
34
+ };
35
+ }
36
+
37
+ throw new Error(`Unsupported module harness runtime kind: ${kind}`);
38
+ }
39
+
40
+ export async function createModuleHarness(options = {}) {
41
+ const runtime = normalizeRuntimeDescriptor(options);
42
+ const kind = String(runtime.kind ?? "process").trim().toLowerCase();
43
+ const launchPlan = resolveModuleHarnessLaunchPlan(options);
44
+ const processClient = await createPluginInvokeProcessClient({ launchPlan });
45
+
46
+ return {
47
+ runtime: {
48
+ ...runtime,
49
+ kind,
50
+ },
51
+ launchPlan,
52
+ invokeRaw(requestBytes) {
53
+ return processClient.invokeRaw(requestBytes);
54
+ },
55
+ invoke(request) {
56
+ return processClient.invoke(request);
57
+ },
58
+ destroy() {
59
+ return processClient.destroy();
60
+ },
61
+ };
62
+ }