wasm-pack --target web generoi ES module -syntaksia (export). Worker käyttää nyt type:'module' ja import-lauseita importScripts:n sijaan. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
32 lines
1.1 KiB
JavaScript
32 lines
1.1 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;
|
|
|
|
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);
|
|
}
|
|
};
|