import { geoai } from "geoai"; let modelInstance = null; // Use a Function to obtain the global object without referencing `globalThis` or `self` const workerGlobal = Function("return this")(); workerGlobal.onmessage = async e => { const { type, payload } = e.data; try { switch (type) { case "init": console.log({payload}) modelInstance = await geoai.pipeline( payload.tasks, payload.providerParams ); workerGlobal.postMessage({ type: "ready" }); break; case "inference": const result = await modelInstance.inference(payload); workerGlobal.postMessage({ type: "result", payload: result }); break; } } catch (error) { workerGlobal.postMessage({ type: "error", payload: error.message }); } };