UNPKG

woolball-client

Version:

Client-side library for Woolball enabling secure browser resource sharing for distributed AI task processing

55 lines (54 loc) 2.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.process = void 0; const tasks_1 = require("../../utils/tasks"); // This worker handles processing of WebLLM tasks const process = async ({ data }) => { const { task, ...taskData } = data; try { // Convert string 'true'/'false' values to booleans for (const key in taskData) { if (taskData[key] === 'true') { taskData[key] = true; } if (taskData[key] === 'false') { taskData[key] = false; } } const processor = tasks_1.taskProcessors[task]; if (!processor) { console.error(`[WebLLM Worker] Error: Unsupported task: ${task}`); throw new Error(`Unsupported task: ${task}`); } console.log(`[WebLLM Worker] Processing task ${task} with processor`); try { const result = await processor(taskData); console.log(`[WebLLM Worker] Task ${task} completed successfully`); self.postMessage(result); } catch (processorError) { console.error(`[WebLLM Worker] Error in ${task} processor:`, processorError); // Report error without specific filtering const errorMessage = processorError instanceof Error ? processorError.message : String(processorError); self.postMessage({ error: errorMessage }); throw processorError; // Re-throw for logging } } catch (e) { const errorMessage = e instanceof Error ? e.message : String(e); const errorStack = e instanceof Error ? e.stack : 'No stack trace available'; console.error('[WebLLM Worker] Error:', errorMessage); console.error('[WebLLM Worker] Stack:', errorStack); // We've already sent the message in the inner try/catch if it was a processor error if (!(e instanceof Error && e.message.includes('processor'))) { self.postMessage({ error: errorMessage }); } } }; exports.process = process; self.onmessage = (event) => { console.log('[WebLLM Worker] Message received'); (0, exports.process)(event).catch(err => { console.error('[WebLLM Worker] Unhandled error:', err); }); };