UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

39 lines • 1.3 kB
const computations = { diffDispatch: async () => (await import("../rs/diff_worker.js")).diffDispatch, }; async function execute(request) { try { if (request.wasm !== undefined) (await import("../rs/stream.js")).adoptModule(request.wasm); const load = computations[request.name]; const fn = (await load?.()); if (fn === undefined) throw new Error(`No computation named ${request.name}`); return { ok: true, value: await fn(...request.args) }; } catch (error) { return { ok: false, value: error }; } } // Replies keep arrival order even while a computation's module still loads. const node = globalThis.process?.versions?.node; if (node !== undefined) { const { parentPort } = await import('node:worker_threads'); let replies = Promise.resolve(); parentPort?.on('message', (request) => { replies = replies.then(async () => { parentPort.postMessage(await execute(request)); }); }); } else { const scope = globalThis; let replies = Promise.resolve(); scope.onmessage = (event) => { replies = replies.then(async () => { scope.postMessage(await execute(event.data)); }); }; } export {}; //# sourceMappingURL=worker_entry.js.map