From da09f8ba1eda5ed347433d37064a3b4ab49e627e Mon Sep 17 00:00:00 2001 From: release-bot Date: Thu, 12 Feb 2026 16:18:29 +0100 Subject: [PATCH] refactor: move debug node into runtime --- app/src/lib/node-registry/debugNode.ts | 23 +++++++++++++++++++ app/src/lib/runtime/runtime-executor.ts | 17 ++++++++++++++ .../worker-runtime-executor-backend.ts | 7 +++++- app/src/routes/+page.svelte | 14 +---------- 4 files changed, 47 insertions(+), 14 deletions(-) create mode 100644 app/src/lib/node-registry/debugNode.ts diff --git a/app/src/lib/node-registry/debugNode.ts b/app/src/lib/node-registry/debugNode.ts new file mode 100644 index 0000000..d03231d --- /dev/null +++ b/app/src/lib/node-registry/debugNode.ts @@ -0,0 +1,23 @@ +const data: Record = {}; + +export function clearDebugData() { + for (const key in data) { + delete data[key]; + } +} + +export function getDebugData() { + return { ...data }; +} + +export const debugNode = { + id: 'max/plantarium/debug', + inputs: { + a: { + type: '*' + } + }, + execute(data: Int32Array) { + return data; + } +} as const; diff --git a/app/src/lib/runtime/runtime-executor.ts b/app/src/lib/runtime/runtime-executor.ts index 0248f25..8974257 100644 --- a/app/src/lib/runtime/runtime-executor.ts +++ b/app/src/lib/runtime/runtime-executor.ts @@ -59,6 +59,7 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor { private definitionMap: Map = new Map(); private seed = Math.floor(Math.random() * 100000000); + private debugData: Record = {}; perf?: PerformanceStore; @@ -139,6 +140,14 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor { nodes.push(node); } + for (const node of graphNodes) { + if (node.type.endsWith('/debug')) { + node.state = node.state || {}; + node.state.depth = Math.min(...node.state.parents.map(s => s.state.depth), 1) - 1; + nodes.push(node); + } + } + return [outputNode, nodes] as const; } @@ -146,6 +155,7 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor { this.perf?.addPoint('runtime'); let a = performance.now(); + this.debugData = {}; // Then we add some metadata to the graph const [outputNode, nodes] = await this.addMetaData(graph); @@ -245,6 +255,9 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor { log.log(`Inputs:`, inputs); a = performance.now(); results[node.id] = node_type.execute(encoded_inputs); + if (node_type.id.endsWith('/debug')) { + this.debugData[node.id] = results[node.id]; + } log.log('Executed', node.type, node.id); b = performance.now(); @@ -273,6 +286,10 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor { return res as unknown as Int32Array; } + getDebugData() { + return this.debugData; + } + getPerformanceData() { return this.perf?.get(); } diff --git a/app/src/lib/runtime/worker-runtime-executor-backend.ts b/app/src/lib/runtime/worker-runtime-executor-backend.ts index 1e7f581..2def545 100644 --- a/app/src/lib/runtime/worker-runtime-executor-backend.ts +++ b/app/src/lib/runtime/worker-runtime-executor-backend.ts @@ -1,3 +1,4 @@ +import { debugNode } from '$lib/node-registry/debugNode'; import { IndexDBCache, RemoteNodeRegistry } from '$lib/node-registry/index'; import type { Graph } from '@nodarium/types'; import { createPerformanceStore } from '@nodarium/utils'; @@ -5,7 +6,7 @@ import { MemoryRuntimeExecutor } from './runtime-executor'; import { MemoryRuntimeCache } from './runtime-executor-cache'; const indexDbCache = new IndexDBCache('node-registry'); -const nodeRegistry = new RemoteNodeRegistry('', indexDbCache); +const nodeRegistry = new RemoteNodeRegistry('', indexDbCache, [debugNode]); const cache = new MemoryRuntimeCache(); const executor = new MemoryRuntimeExecutor(nodeRegistry, cache); @@ -43,3 +44,7 @@ export async function executeGraph( export function getPerformanceData() { return performanceStore.get(); } + +export function getDebugData() { + return executor.getDebugData(); +} diff --git a/app/src/routes/+page.svelte b/app/src/routes/+page.svelte index eaf23d2..33a4e53 100644 --- a/app/src/routes/+page.svelte +++ b/app/src/routes/+page.svelte @@ -4,6 +4,7 @@ import Grid from '$lib/grid'; import { debounceAsyncFunction } from '$lib/helpers'; import { createKeyMap } from '$lib/helpers/createKeyMap'; + import { debugNode } from '$lib/node-registry/debugNode.js'; import { IndexDBCache, RemoteNodeRegistry } from '$lib/node-registry/index'; import NodeStore from '$lib/node-store/NodeStore.svelte'; import PerformanceViewer from '$lib/performance/PerformanceViewer.svelte'; @@ -33,19 +34,6 @@ const registryCache = new IndexDBCache('node-registry'); - const debugNode = { - id: 'max/plantarium/debug', - inputs: { - a: { - type: '*' - } - }, - execute(data: Int32Array) { - console.log({ data }); - return data; - } - } as const; - const nodeRegistry = new RemoteNodeRegistry('', registryCache, [debugNode]); const workerRuntime = new WorkerRuntimeExecutor(); const runtimeCache = new MemoryRuntimeCache();