Files
agentic-studio/network-poc/frontend/public/worker.js
Jaakko Vanhala 857afbe111 feat: complete revolution architecture modernization
- Decoupled robust frontend into an Astro framework in `frontend/`.
- Replaced direct WebSocket broadcast with Smart Routing to distribute workload only to idle capable nodes, preventing 503 errors and duplicate responses.
- Rewrote WASM panic points (`unwrap()` handling) into panic-safe match blocks in qwen_coder.rs preventing Node Web Workers from crashing.
- Integrated robust dynamic Three.js 3D visualization.
- Resolved mermaid and THREE.js frontend hydration issues.
2026-04-09 16:38:24 +03:00

39 lines
1.3 KiB
JavaScript

// 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);
}
};