nvent 0.5.15 → 1.0.0-alpha.2

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 (149) hide show
  1. package/dist/module.d.mts +181 -8
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +1257 -1196
  4. package/dist/runtime/app/composables/useFunctionCall.d.ts +17 -0
  5. package/dist/runtime/app/composables/useFunctionCall.js +25 -0
  6. package/dist/runtime/app/composables/useNventStream.d.ts +23 -0
  7. package/dist/runtime/app/composables/useNventStream.js +58 -0
  8. package/dist/runtime/nitro/plugins/00.iii-lifecycle.d.ts +19 -0
  9. package/dist/runtime/nitro/plugins/00.iii-lifecycle.js +62 -0
  10. package/dist/runtime/nitro/plugins/01.iii-worker.d.ts +15 -0
  11. package/dist/runtime/nitro/plugins/01.iii-worker.js +91 -0
  12. package/dist/runtime/nitro/routes/stream-proxy.d.ts +17 -0
  13. package/dist/runtime/nitro/routes/stream-proxy.js +45 -0
  14. package/dist/runtime/nitro/utils/console.d.ts +32 -0
  15. package/dist/runtime/nitro/utils/console.js +95 -0
  16. package/dist/runtime/nitro/utils/defineFunction.d.ts +378 -3
  17. package/dist/runtime/nitro/utils/defineFunction.js +224 -4
  18. package/dist/runtime/nitro/utils/engine.d.ts +25 -0
  19. package/dist/runtime/nitro/utils/engine.js +130 -0
  20. package/dist/runtime/nitro/utils/nventDir.d.ts +1 -0
  21. package/dist/runtime/nitro/utils/nventDir.js +20 -0
  22. package/dist/runtime/nitro/utils/useIii.d.ts +23 -0
  23. package/dist/runtime/nitro/utils/useIii.js +14 -0
  24. package/dist/runtime/nitro/utils/workers/node.d.ts +24 -0
  25. package/dist/runtime/nitro/utils/workers/node.js +57 -0
  26. package/dist/runtime/nitro/utils/workers/python.d.ts +67 -0
  27. package/dist/runtime/nitro/utils/workers/python.js +220 -0
  28. package/dist/runtime/python/nvent.py +208 -0
  29. package/dist/runtime/python/worker_runtime.py +659 -0
  30. package/dist/runtime/virtual.d.ts +17 -0
  31. package/dist/types.d.mts +5 -1
  32. package/package.json +11 -14
  33. package/dist/runtime/adapters/base/index.d.ts +0 -6
  34. package/dist/runtime/adapters/base/index.js +0 -1
  35. package/dist/runtime/adapters/base/store-validator.d.ts +0 -48
  36. package/dist/runtime/adapters/base/store-validator.js +0 -147
  37. package/dist/runtime/adapters/builtin/file-queue.d.ts +0 -67
  38. package/dist/runtime/adapters/builtin/file-queue.js +0 -499
  39. package/dist/runtime/adapters/builtin/file-store.d.ts +0 -32
  40. package/dist/runtime/adapters/builtin/file-store.js +0 -206
  41. package/dist/runtime/adapters/builtin/file-stream.d.ts +0 -39
  42. package/dist/runtime/adapters/builtin/file-stream.js +0 -56
  43. package/dist/runtime/adapters/builtin/index.d.ts +0 -10
  44. package/dist/runtime/adapters/builtin/index.js +0 -5
  45. package/dist/runtime/adapters/builtin/memory-queue.d.ts +0 -52
  46. package/dist/runtime/adapters/builtin/memory-queue.js +0 -243
  47. package/dist/runtime/adapters/builtin/memory-store.d.ts +0 -69
  48. package/dist/runtime/adapters/builtin/memory-store.js +0 -357
  49. package/dist/runtime/adapters/builtin/memory-stream.d.ts +0 -21
  50. package/dist/runtime/adapters/builtin/memory-stream.js +0 -56
  51. package/dist/runtime/adapters/factory.d.ts +0 -31
  52. package/dist/runtime/adapters/factory.js +0 -135
  53. package/dist/runtime/adapters/index.d.ts +0 -8
  54. package/dist/runtime/adapters/index.js +0 -3
  55. package/dist/runtime/adapters/interfaces/index.d.ts +0 -11
  56. package/dist/runtime/adapters/interfaces/index.js +0 -3
  57. package/dist/runtime/adapters/interfaces/queue.d.ts +0 -155
  58. package/dist/runtime/adapters/interfaces/queue.js +0 -0
  59. package/dist/runtime/adapters/interfaces/store.d.ts +0 -299
  60. package/dist/runtime/adapters/interfaces/store.js +0 -0
  61. package/dist/runtime/adapters/interfaces/stream.d.ts +0 -62
  62. package/dist/runtime/adapters/interfaces/stream.js +0 -0
  63. package/dist/runtime/adapters/registry.d.ts +0 -85
  64. package/dist/runtime/adapters/registry.js +0 -161
  65. package/dist/runtime/config/index.d.ts +0 -23
  66. package/dist/runtime/config/index.js +0 -200
  67. package/dist/runtime/config/types.d.ts +0 -439
  68. package/dist/runtime/config/types.js +0 -0
  69. package/dist/runtime/events/eventBus.d.ts +0 -20
  70. package/dist/runtime/events/eventBus.js +0 -35
  71. package/dist/runtime/events/types.d.ts +0 -144
  72. package/dist/runtime/events/types.js +0 -0
  73. package/dist/runtime/events/utils/scheduleTrigger.d.ts +0 -8
  74. package/dist/runtime/events/utils/scheduleTrigger.js +0 -71
  75. package/dist/runtime/events/utils/stallDetector.d.ts +0 -83
  76. package/dist/runtime/events/utils/stallDetector.js +0 -318
  77. package/dist/runtime/events/utils/triggerRuntime.d.ts +0 -58
  78. package/dist/runtime/events/utils/triggerRuntime.js +0 -212
  79. package/dist/runtime/events/wiring/flowWiring.d.ts +0 -34
  80. package/dist/runtime/events/wiring/flowWiring.js +0 -1258
  81. package/dist/runtime/events/wiring/registry.d.ts +0 -19
  82. package/dist/runtime/events/wiring/registry.js +0 -43
  83. package/dist/runtime/events/wiring/stateWiring.d.ts +0 -37
  84. package/dist/runtime/events/wiring/stateWiring.js +0 -92
  85. package/dist/runtime/events/wiring/streamWiring.d.ts +0 -36
  86. package/dist/runtime/events/wiring/streamWiring.js +0 -156
  87. package/dist/runtime/events/wiring/triggerWiring.d.ts +0 -21
  88. package/dist/runtime/events/wiring/triggerWiring.js +0 -422
  89. package/dist/runtime/nitro/plugins/00.adapters.d.ts +0 -14
  90. package/dist/runtime/nitro/plugins/00.adapters.js +0 -73
  91. package/dist/runtime/nitro/plugins/01.ws-lifecycle.d.ts +0 -5
  92. package/dist/runtime/nitro/plugins/01.ws-lifecycle.js +0 -69
  93. package/dist/runtime/nitro/plugins/02.workers.d.ts +0 -2
  94. package/dist/runtime/nitro/plugins/02.workers.js +0 -92
  95. package/dist/runtime/nitro/plugins/03.triggers.d.ts +0 -12
  96. package/dist/runtime/nitro/plugins/03.triggers.js +0 -55
  97. package/dist/runtime/nitro/routes/webhook.await.d.ts +0 -23
  98. package/dist/runtime/nitro/routes/webhook.await.js +0 -112
  99. package/dist/runtime/nitro/routes/webhook.trigger.d.ts +0 -86
  100. package/dist/runtime/nitro/routes/webhook.trigger.js +0 -73
  101. package/dist/runtime/nitro/utils/adapters.d.ts +0 -66
  102. package/dist/runtime/nitro/utils/adapters.js +0 -51
  103. package/dist/runtime/nitro/utils/awaitPatterns/event.d.ts +0 -15
  104. package/dist/runtime/nitro/utils/awaitPatterns/event.js +0 -128
  105. package/dist/runtime/nitro/utils/awaitPatterns/index.d.ts +0 -28
  106. package/dist/runtime/nitro/utils/awaitPatterns/index.js +0 -55
  107. package/dist/runtime/nitro/utils/awaitPatterns/schedule.d.ts +0 -16
  108. package/dist/runtime/nitro/utils/awaitPatterns/schedule.js +0 -83
  109. package/dist/runtime/nitro/utils/awaitPatterns/time.d.ts +0 -15
  110. package/dist/runtime/nitro/utils/awaitPatterns/time.js +0 -71
  111. package/dist/runtime/nitro/utils/awaitPatterns/webhook.d.ts +0 -15
  112. package/dist/runtime/nitro/utils/awaitPatterns/webhook.js +0 -128
  113. package/dist/runtime/nitro/utils/defineFunctionConfig.d.ts +0 -378
  114. package/dist/runtime/nitro/utils/defineFunctionConfig.js +0 -3
  115. package/dist/runtime/nitro/utils/defineHooks.d.ts +0 -95
  116. package/dist/runtime/nitro/utils/defineHooks.js +0 -9
  117. package/dist/runtime/nitro/utils/registerAdapter.d.ts +0 -59
  118. package/dist/runtime/nitro/utils/registerAdapter.js +0 -13
  119. package/dist/runtime/nitro/utils/useAwait.d.ts +0 -83
  120. package/dist/runtime/nitro/utils/useAwait.js +0 -169
  121. package/dist/runtime/nitro/utils/useEventManager.d.ts +0 -15
  122. package/dist/runtime/nitro/utils/useEventManager.js +0 -26
  123. package/dist/runtime/nitro/utils/useFlow.d.ts +0 -66
  124. package/dist/runtime/nitro/utils/useFlow.js +0 -310
  125. package/dist/runtime/nitro/utils/useHookRegistry.d.ts +0 -40
  126. package/dist/runtime/nitro/utils/useHookRegistry.js +0 -25
  127. package/dist/runtime/nitro/utils/useNventLogger.d.ts +0 -42
  128. package/dist/runtime/nitro/utils/useNventLogger.js +0 -54
  129. package/dist/runtime/nitro/utils/useRunContext.d.ts +0 -6
  130. package/dist/runtime/nitro/utils/useRunContext.js +0 -102
  131. package/dist/runtime/nitro/utils/useStreamTopics.d.ts +0 -83
  132. package/dist/runtime/nitro/utils/useStreamTopics.js +0 -94
  133. package/dist/runtime/nitro/utils/useTrigger.d.ts +0 -150
  134. package/dist/runtime/nitro/utils/useTrigger.js +0 -311
  135. package/dist/runtime/nitro/utils/wsPeerManager.d.ts +0 -44
  136. package/dist/runtime/nitro/utils/wsPeerManager.js +0 -32
  137. package/dist/runtime/scheduler/index.d.ts +0 -33
  138. package/dist/runtime/scheduler/index.js +0 -42
  139. package/dist/runtime/scheduler/scheduler.d.ts +0 -132
  140. package/dist/runtime/scheduler/scheduler.js +0 -799
  141. package/dist/runtime/scheduler/types.d.ts +0 -122
  142. package/dist/runtime/scheduler/types.js +0 -0
  143. package/dist/runtime/worker/node/runner.d.ts +0 -95
  144. package/dist/runtime/worker/node/runner.js +0 -272
  145. package/dist/runtime/worker/python/get_config.py +0 -64
  146. package/dist/runtime/worker/system/awaitHandlers.d.ts +0 -27
  147. package/dist/runtime/worker/system/awaitHandlers.js +0 -230
  148. package/dist/runtime/worker/system/index.d.ts +0 -24
  149. package/dist/runtime/worker/system/index.js +0 -39
@@ -0,0 +1,17 @@
1
+ /**
2
+ * useFunctionCall — call a nvent function via the /functions/** proxy.
3
+ *
4
+ * ```ts
5
+ * const { call, pending, data, error } = useFunctionCall('pipeline/start')
6
+ * const result = await call({ text: 'Hello' })
7
+ * // result may include a streamId to pass to useNventStream
8
+ * ```
9
+ */
10
+ export declare function useFunctionCall<TInput = unknown, TOutput = unknown>(path: string): {
11
+ pending: import('vue').Ref<boolean>;
12
+ error: import('vue').Ref<Error | null>;
13
+ data: import('vue').Ref<TOutput | null>;
14
+ call: (input?: TInput, options?: {
15
+ method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
16
+ }) => Promise<TOutput>;
17
+ };
@@ -0,0 +1,25 @@
1
+ import { ref } from "vue";
2
+ export function useFunctionCall(path) {
3
+ const pending = ref(false);
4
+ const error = ref(null);
5
+ const data = ref(null);
6
+ async function call(input, options = {}) {
7
+ pending.value = true;
8
+ error.value = null;
9
+ try {
10
+ const method = options.method ?? (input !== void 0 ? "POST" : "GET");
11
+ const result = await $fetch(`/functions/${path}`, {
12
+ method,
13
+ ...method === "GET" ? { params: input } : { body: input }
14
+ });
15
+ data.value = result;
16
+ return result;
17
+ } catch (e) {
18
+ error.value = e;
19
+ throw e;
20
+ } finally {
21
+ pending.value = false;
22
+ }
23
+ }
24
+ return { call, pending, data, error };
25
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * useNventStream — subscribe to an iii stream group via WebSocket.
3
+ *
4
+ * The iii stream module serves WebSocket connections at:
5
+ * ws://host/stream/{stream_name}/{group_id}/
6
+ *
7
+ * Nitro proxies `/stream/**` → `ws://iii-engine:3112/stream/**`, so connecting
8
+ * to the current page host is sufficient — no hardcoded ports needed.
9
+ *
10
+ * ```ts
11
+ * const { messages, status, subscribe, close } = useNventStream<MyEvent>()
12
+ * subscribe('pipeline', jobId) // start listening
13
+ * // messages.value grows as events arrive
14
+ * ```
15
+ */
16
+ import { ref } from 'vue';
17
+ export type NventStreamStatus = 'idle' | 'connecting' | 'connected' | 'closed' | 'error';
18
+ export declare function useNventStream<TMessage = unknown>(): {
19
+ messages: ReturnType<typeof ref<TMessage[]>>;
20
+ status: import("vue").Ref<NventStreamStatus, NventStreamStatus>;
21
+ subscribe: (streamName: string, groupId: string) => void;
22
+ close: () => void;
23
+ };
@@ -0,0 +1,58 @@
1
+ import { ref, onUnmounted } from "vue";
2
+ export function useNventStream() {
3
+ const messages = ref([]);
4
+ const status = ref("idle");
5
+ let ws = null;
6
+ function subscribe(streamName, groupId) {
7
+ close();
8
+ messages.value = [];
9
+ status.value = "connecting";
10
+ const protocol = typeof window !== "undefined" && window.location.protocol === "https:" ? "wss:" : "ws:";
11
+ const host = typeof window !== "undefined" ? window.location.host : "localhost";
12
+ ws = new WebSocket(`${protocol}//${host}/stream/${streamName}/${groupId}/`);
13
+ ws.onopen = () => {
14
+ status.value = "connected";
15
+ };
16
+ ws.onmessage = (e) => {
17
+ try {
18
+ const envelope = JSON.parse(e.data);
19
+ let payload;
20
+ if (envelope?.event?.type === "event") {
21
+ payload = envelope.event.event;
22
+ } else if (envelope?.event?.data !== void 0) {
23
+ payload = envelope.event.data;
24
+ } else {
25
+ payload = envelope;
26
+ }
27
+ if (Array.isArray(payload)) {
28
+ messages.value = [...messages.value, ...payload];
29
+ } else {
30
+ messages.value = [...messages.value, payload];
31
+ }
32
+ } catch {
33
+ messages.value = [...messages.value, e.data];
34
+ }
35
+ };
36
+ ws.onerror = () => {
37
+ status.value = "error";
38
+ };
39
+ ws.onclose = () => {
40
+ if (status.value !== "error") status.value = "closed";
41
+ ws = null;
42
+ };
43
+ }
44
+ function close() {
45
+ if (ws) {
46
+ ws.close();
47
+ ws = null;
48
+ status.value = "closed";
49
+ }
50
+ }
51
+ onUnmounted(close);
52
+ return {
53
+ messages,
54
+ status,
55
+ subscribe,
56
+ close
57
+ };
58
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * iii Lifecycle Plugin
3
+ *
4
+ * Manages the iii engine and console process lifecycle at **server runtime**.
5
+ *
6
+ * - **Development**: no-op. The Nuxt module (module.ts) starts engine + console
7
+ * in the parent Nuxt process so they survive Nitro hot-reloads naturally.
8
+ * - **Production** (`managed: true`, `mode: 'local'`): starts engine + console here.
9
+ *
10
+ * Binaries and iii-config.yaml are placed by `nuxt build` (module.ts) into
11
+ * `.output/nvent/`. The plugin finds them by walking up from import.meta.url —
12
+ * this is CWD-independent and works when .output/ is copied or deployed elsewhere.
13
+ *
14
+ * This plugin does NOT download anything — it finds what build already placed.
15
+ *
16
+ * Worker registration (Node.js + Python) is handled by 00.iii-worker.ts.
17
+ */
18
+ declare const _default: any;
19
+ export default _default;
@@ -0,0 +1,62 @@
1
+ import { defineNitroPlugin, useRuntimeConfig } from "#imports";
2
+ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { createEngineManager } from "../utils/engine.js";
5
+ import { ConsoleManager } from "../utils/console.js";
6
+ import { resolveNventDir } from "../utils/nventDir.js";
7
+ function findExisting(...candidates) {
8
+ return candidates.find((p) => existsSync(p));
9
+ }
10
+ export default defineNitroPlugin(async (nitroApp) => {
11
+ const rc = useRuntimeConfig();
12
+ const cfg = rc.nvent ?? {};
13
+ const iiiCfg = cfg.iii ?? {};
14
+ if (!iiiCfg.managed) return;
15
+ if ((iiiCfg.mode ?? "local") !== "local") return;
16
+ if (process.env.NODE_ENV === "development") return;
17
+ const httpPort = iiiCfg.httpPort ?? 3111;
18
+ const wsPort = iiiCfg.wsPort ?? 49134;
19
+ const logLevel = iiiCfg.logLevel ?? "warn";
20
+ const binaryName = process.platform === "win32" ? "iii.exe" : "iii";
21
+ const nventDir = resolveNventDir(import.meta.url);
22
+ const binDir = join(nventDir, "bin");
23
+ const binaryPath = findExisting(join(binDir, binaryName));
24
+ if (!binaryPath) {
25
+ console.error("[nvent] iii engine binary not found. Run `nuxt build` to install it.");
26
+ return;
27
+ }
28
+ let configPath = findExisting(join(nventDir, "iii-config.yaml"));
29
+ if (!configPath) {
30
+ if (!iiiCfg.engineConfigYaml) {
31
+ console.error("[nvent] iii-config.yaml not found and no stored config available. Skipping engine start.");
32
+ return;
33
+ }
34
+ mkdirSync(nventDir, { recursive: true });
35
+ configPath = join(nventDir, "iii-config.yaml");
36
+ writeFileSync(configPath, iiiCfg.engineConfigYaml, "utf-8");
37
+ }
38
+ const engine = createEngineManager({ binaryPath, configPath, httpPort, wsPort, logLevel });
39
+ await engine.start();
40
+ let consoleManager = null;
41
+ if (cfg.console?.enabled) {
42
+ const consoleBinaryName = process.platform === "win32" ? "iii-console.exe" : "iii-console";
43
+ const consoleBinPath = findExisting(join(binDir, consoleBinaryName));
44
+ if (consoleBinPath) {
45
+ consoleManager = new ConsoleManager({
46
+ binaryPath: consoleBinPath,
47
+ port: cfg.console.port ?? 3113,
48
+ enginePort: httpPort,
49
+ bridgePort: wsPort,
50
+ flow: cfg.console.flow ?? true,
51
+ logLevel
52
+ });
53
+ await consoleManager.start();
54
+ } else {
55
+ console.warn("[nvent] iii-console binary not found \u2014 console UI will not start.");
56
+ }
57
+ }
58
+ nitroApp.hooks.hookOnce("close", async () => {
59
+ await consoleManager?.stop();
60
+ await engine.stop();
61
+ });
62
+ });
@@ -0,0 +1,15 @@
1
+ /**
2
+ * iii Worker Plugin
3
+ *
4
+ * Unified worker plugin — connects Nitro to the running iii engine and manages
5
+ * all worker types: Node.js (TypeScript) and Python (and future runtimes).
6
+ * The iii instance is stored on nitroApp so consumers can reach it via useIii().
7
+ */
8
+ import { registerWorker } from 'iii-sdk';
9
+ declare module 'nitropack' {
10
+ interface NitroApp {
11
+ $iii: ReturnType<typeof registerWorker>;
12
+ }
13
+ }
14
+ declare const _default: any;
15
+ export default _default;
@@ -0,0 +1,91 @@
1
+ import { defineNitroPlugin, useRuntimeConfig } from "#imports";
2
+ import { existsSync, readFileSync } from "node:fs";
3
+ import { isAbsolute, join, resolve } from "node:path";
4
+ import { resolveNventDir } from "../utils/nventDir.js";
5
+ import { registerWorker } from "iii-sdk";
6
+ import { registerNodeFunctions } from "../utils/workers/node.js";
7
+ import { PythonWorkersOrchestrator } from "../utils/workers/python.js";
8
+ import { registry, pythonFunctions } from "#nvent/iii-registry";
9
+ function readProjectName() {
10
+ try {
11
+ const pkgPath = join(process.cwd(), "package.json");
12
+ if (!existsSync(pkgPath)) return void 0;
13
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
14
+ return typeof pkg.name === "string" ? pkg.name : void 0;
15
+ } catch {
16
+ return void 0;
17
+ }
18
+ }
19
+ export default defineNitroPlugin(async (nitroApp) => {
20
+ const runtimeConfig = useRuntimeConfig();
21
+ const nventCfg = runtimeConfig.nvent ?? {};
22
+ const cfg = nventCfg.iii ?? {};
23
+ const pythonCfg = nventCfg.python ?? {};
24
+ const wsUrl = cfg.wsUrl ?? process.env.III_BRIDGE_URL ?? "ws://localhost:49134";
25
+ const logLevel = cfg.logLevel ?? "warn";
26
+ const pythonBin = (() => {
27
+ const raw = process.env.NVENT_PYTHON_BIN ?? "python3";
28
+ if (!raw || raw === "python3" || raw === "python" || isAbsolute(raw)) return raw;
29
+ const roots = [
30
+ process.cwd(),
31
+ join(process.cwd(), ".."),
32
+ join(process.cwd(), "..", ".."),
33
+ join(process.cwd(), "..", "..", ".."),
34
+ process.env.NVENT_DIR ? join(process.env.NVENT_DIR, "..") : null
35
+ ].filter(Boolean);
36
+ for (const root of roots) {
37
+ const candidate = resolve(root, raw);
38
+ if (existsSync(candidate)) return candidate;
39
+ }
40
+ return raw;
41
+ })();
42
+ const workerName = cfg.workerName ?? `nvent-${process.pid}`;
43
+ const fnCount = (registry.functions ?? []).length;
44
+ const triggerCount = (registry.triggers ?? []).length;
45
+ console.log(`[nvent] iii-worker: connecting to ${wsUrl} \u2014 ${fnCount} function(s), ${triggerCount} trigger(s)`);
46
+ const iii = registerWorker(wsUrl, {
47
+ workerName,
48
+ otel: {
49
+ enabled: true,
50
+ serviceName: "nvent",
51
+ metricsExportIntervalMs: 1e4
52
+ },
53
+ telemetry: {
54
+ framework: "nvent",
55
+ project_name: readProjectName()
56
+ },
57
+ reconnectionConfig: {
58
+ initialDelayMs: 500,
59
+ maxDelayMs: 15e3,
60
+ maxRetries: -1
61
+ }
62
+ });
63
+ console.log(`[nvent] iii-worker: connected to engine (worker: ${workerName})`);
64
+ registerNodeFunctions(iii, registry.functions ?? []);
65
+ nitroApp.$iii = iii;
66
+ const nventArtifactsDir = resolveNventDir(import.meta.url);
67
+ const workersDir = join(nventArtifactsDir, "workers");
68
+ const runtimeFilePath = join(workersDir, "_runtime.py");
69
+ const nventHelperFilePath = join(workersDir, "nvent.py");
70
+ const runtimeContent = existsSync(runtimeFilePath) ? readFileSync(runtimeFilePath, "utf-8") : pythonCfg.runtimeContent ?? "";
71
+ const nventHelperContent = existsSync(nventHelperFilePath) ? readFileSync(nventHelperFilePath, "utf-8") : pythonCfg.nventHelperContent ?? "";
72
+ const orchestrator = new PythonWorkersOrchestrator(
73
+ workersDir,
74
+ runtimeContent,
75
+ nventHelperContent,
76
+ wsUrl,
77
+ pythonBin,
78
+ logLevel
79
+ );
80
+ if (process.env.NODE_ENV !== "development" && !pythonCfg.skip) {
81
+ const resolvedPythonFunctions = (pythonFunctions ?? []).map((fn) => ({
82
+ ...fn,
83
+ absPath: isAbsolute(fn.absPath) ? fn.absPath : join(nventArtifactsDir, "functions", fn.absPath)
84
+ }));
85
+ await orchestrator.start(resolvedPythonFunctions);
86
+ }
87
+ nitroApp.hooks.hookOnce("close", async () => {
88
+ await orchestrator.stop();
89
+ await iii.shutdown();
90
+ });
91
+ });
@@ -0,0 +1,17 @@
1
+ /**
2
+ * WebSocket proxy for the iii Stream module.
3
+ *
4
+ * The iii stream module listens on its own port (default 3112) and only accepts
5
+ * connections at the root path `ws://host:3112/`. After connecting, the client
6
+ * must send a join message to subscribe to a stream group:
7
+ *
8
+ * { type: 'join', data: { streamName, groupId, subscriptionId } }
9
+ *
10
+ * This handler matches `/stream/{streamName}/{groupId}[/]` on the Nuxt/Nitro
11
+ * side, extracts the stream name and group ID from the URL path, connects to
12
+ * the upstream root, sends the join message, and then transparently bridges
13
+ * all subsequent messages so the browser never needs to know about port 3112
14
+ * or the join protocol.
15
+ */
16
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, never>;
17
+ export default _default;
@@ -0,0 +1,45 @@
1
+ import { defineWebSocketHandler } from "h3";
2
+ export default defineWebSocketHandler({
3
+ open(peer) {
4
+ const { nvent } = useRuntimeConfig();
5
+ const host = nvent.iii.httpHost;
6
+ const port = nvent.iii.streamPort;
7
+ const rawUrl = peer.request.url;
8
+ const pathname = rawUrl.startsWith("http") ? new URL(rawUrl).pathname : rawUrl.split("?")[0];
9
+ const parts = pathname.replace(/^\/stream\//, "").replace(/\/$/, "").split("/");
10
+ const streamName = parts[0] ?? "";
11
+ const groupId = parts[1] ?? "";
12
+ const upstreamUrl = `ws://${host}:${port}/`;
13
+ const upstream = new WebSocket(upstreamUrl);
14
+ peer.context._upstream = upstream;
15
+ upstream.addEventListener("open", () => {
16
+ const subscriptionId = crypto.randomUUID();
17
+ upstream.send(JSON.stringify({
18
+ type: "join",
19
+ data: { streamName, groupId, subscriptionId }
20
+ }));
21
+ });
22
+ upstream.addEventListener("message", (e) => {
23
+ peer.send(typeof e.data === "string" ? e.data : JSON.stringify(e.data));
24
+ });
25
+ upstream.addEventListener("close", (e) => {
26
+ peer.close(e.code, e.reason);
27
+ });
28
+ upstream.addEventListener("error", () => {
29
+ peer.close(1011, "Upstream stream error");
30
+ });
31
+ },
32
+ message(peer, message) {
33
+ const upstream = peer.context._upstream;
34
+ if (upstream?.readyState === WebSocket.OPEN) {
35
+ upstream.send(message.rawData);
36
+ }
37
+ },
38
+ close(peer) {
39
+ const upstream = peer.context._upstream;
40
+ if (upstream && upstream.readyState < WebSocket.CLOSING) {
41
+ upstream.close();
42
+ }
43
+ delete peer.context._upstream;
44
+ }
45
+ });
@@ -0,0 +1,32 @@
1
+ /**
2
+ * iii Console Process Manager — runtime util
3
+ *
4
+ * Manages the lifecycle of the iii-console process.
5
+ * Lives in src/runtime/nitro/utils/ so it is bundled into the Nitro output.
6
+ * Binary installation is handled separately by ensureIiiConsole in src/iii/console.ts.
7
+ */
8
+ export interface ConsoleManagerOptions {
9
+ binaryPath: string;
10
+ /** Port for the console web UI. Default: 3113 */
11
+ port?: number;
12
+ /** Engine HTTP API host. Default: 127.0.0.1 */
13
+ engineHost?: string;
14
+ /** Engine HTTP port. Default: 3111 */
15
+ enginePort?: number;
16
+ /** Engine WebSocket port. Default: 3112 */
17
+ wsPort?: number;
18
+ /** SDK bridge port. Default: 49134 */
19
+ bridgePort?: number;
20
+ /** Enable the Flow visualization page. Default: true */
21
+ flow?: boolean;
22
+ /** Minimum log level for console process output. Default: 'warn' */
23
+ logLevel?: 'none' | 'error' | 'warn' | 'info';
24
+ }
25
+ export declare class ConsoleManager {
26
+ private process;
27
+ private readonly opts;
28
+ constructor(opts: ConsoleManagerOptions);
29
+ isRunning(): boolean;
30
+ start(): Promise<void>;
31
+ stop(): Promise<void>;
32
+ }
@@ -0,0 +1,95 @@
1
+ import { spawn } from "node:child_process";
2
+ import { consola } from "consola";
3
+ const logger = consola.withTag("nvent:console");
4
+ function parseConsoleLineLevel(line) {
5
+ if (line.includes(" ERROR ") || line.includes("[ERROR]")) return "error";
6
+ if (line.includes(" WARN ") || line.includes("[WARN]")) return "warn";
7
+ if (line.includes(" INFO ") || line.includes("[INFO]")) return "info";
8
+ return null;
9
+ }
10
+ const LOG_LEVEL_RANK = { none: 0, error: 1, warn: 2, info: 3 };
11
+ function shouldShow(lineLevel, minLevel) {
12
+ return LOG_LEVEL_RANK[lineLevel] <= LOG_LEVEL_RANK[minLevel];
13
+ }
14
+ export class ConsoleManager {
15
+ process = null;
16
+ opts;
17
+ constructor(opts) {
18
+ this.opts = {
19
+ port: 3113,
20
+ engineHost: "127.0.0.1",
21
+ enginePort: 3111,
22
+ wsPort: 3112,
23
+ bridgePort: 49134,
24
+ flow: true,
25
+ logLevel: "warn",
26
+ ...opts
27
+ };
28
+ }
29
+ isRunning() {
30
+ return this.process !== null && !this.process.killed && this.process.exitCode === null;
31
+ }
32
+ async start() {
33
+ if (this.isRunning()) {
34
+ logger.warn("iii-console is already running");
35
+ return;
36
+ }
37
+ const { binaryPath, port, engineHost, enginePort, wsPort, bridgePort, flow, logLevel } = this.opts;
38
+ const args = [
39
+ "--port",
40
+ String(port),
41
+ "--engine-host",
42
+ engineHost,
43
+ "--engine-port",
44
+ String(enginePort),
45
+ "--ws-port",
46
+ String(wsPort),
47
+ "--bridge-port",
48
+ String(bridgePort)
49
+ ];
50
+ if (flow) args.push("--enable-flow");
51
+ if (logLevel === "info") logger.info(`Starting iii-console on http://localhost:${port}`);
52
+ this.process = spawn(binaryPath, args, {
53
+ stdio: ["ignore", "pipe", "pipe"],
54
+ detached: false
55
+ });
56
+ this.process.stdout?.on("data", (chunk) => {
57
+ if (logLevel === "none") return;
58
+ for (const line of chunk.toString().split("\n").filter(Boolean)) {
59
+ const level = parseConsoleLineLevel(line) ?? "info";
60
+ if (!shouldShow(level, logLevel)) continue;
61
+ if (level === "error") logger.error(`[console] ${line}`);
62
+ else if (level === "warn") logger.warn(`[console] ${line}`);
63
+ else logger.info(`[console] ${line}`);
64
+ }
65
+ });
66
+ this.process.stderr?.on("data", (chunk) => {
67
+ if (logLevel === "none") return;
68
+ for (const line of chunk.toString().split("\n").filter(Boolean))
69
+ logger.warn(`[console] ${line}`);
70
+ });
71
+ this.process.on("exit", (code, signal) => {
72
+ if (logLevel === "info") logger.info(`iii-console exited (code=${code}, signal=${signal})`);
73
+ this.process = null;
74
+ });
75
+ this.process.on("error", (err) => {
76
+ logger.error(`iii-console process error: ${err.message}`);
77
+ this.process = null;
78
+ });
79
+ }
80
+ async stop() {
81
+ if (!this.isRunning() || !this.process) return;
82
+ const { logLevel } = this.opts;
83
+ return new Promise((resolve) => {
84
+ this.process.once("exit", () => {
85
+ this.process = null;
86
+ if (logLevel === "info") logger.info("iii-console stopped");
87
+ resolve();
88
+ });
89
+ this.process.kill("SIGTERM");
90
+ setTimeout(() => {
91
+ if (this.process) this.process.kill("SIGKILL");
92
+ }, 5e3);
93
+ });
94
+ }
95
+ }