// Kipinä WASM Worker (ES module) — ajaa kielimallin inferenssin erillisessä säikeessä import init, { start_agent_node, set_gpu_load, set_auto_tasks } from './pkg/node.js'; let wasmReady = false; // Välitetään console.log -viestit pääsäikeelle jotta UI-kuuntelijat näkevät ne const _origLog = console.log; console.log = function(...args) { _origLog.apply(console, args); self.postMessage({ type: 'log', message: args.join(' ') }); }; self.onmessage = async (e) => { const { type, data } = e.data; if (type === 'init') { try { await init(); wasmReady = true; self.postMessage({ type: 'ready' }); } catch (err) { self.postMessage({ type: 'error', message: 'WASM init: ' + err.message }); } } else if (type === 'start') { if (!wasmReady) return; const { hubUrl, hasWebGPU, deviceInfo, taskId } = data; try { await start_agent_node(hubUrl, hasWebGPU, deviceInfo, taskId); self.postMessage({ type: 'started' }); } catch (err) { self.postMessage({ type: 'error', message: 'Node: ' + err.message }); } } else if (type === 'set_gpu_load') { if (wasmReady) set_gpu_load(data.load); } else if (type === 'set_auto_tasks') { if (wasmReady) set_auto_tasks(data.enabled); } };