openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 2.15 kB
JavaScript
import{i as e}from"./fs-safe-copy.worker-global-singleton-DIJgobpU.mjs";import{i as t,n,t as r}from"./fs-safe-copy.worker-runtime-process-manifest-BlrvoYG_.mjs";import{basename as i}from"node:path";import{AsyncLocalStorage as a}from"node:async_hooks";import{fileURLToPath as o}from"node:url";import"node:perf_hooks";const s=typeof process>`u`?void 0:process.getBuiltinModule?.(`node:async_hooks`),c=s?e(Symbol.for(`openclaw.detachedAsyncContext`),()=>new s.AsyncResource(`openclaw.detached-async-context`)):void 0;function runInDetachedAsyncContext(e){return c?c.runInAsyncScope(e):e()}const l=e(Symbol.for(`openclaw.asyncContext`),()=>new a);var AsyncContext=class{constructor(e){this.key=e}getStore(){return l.getStore()?.[this.key]}run(e,t){let n=l.getStore(),r=n?.[this.key];if(Object.is(r,e))return t();let i={...n,[this.key]:e};l.enterWith(i);try{return t()}finally{let e=l.getStore();l.enterWith(e===i?n:{...e,[this.key]:r})}}exit(e){return this.run(void 0,e)}enterWith(e){l.enterWith({...l.getStore(),[this.key]:e})}};const u=e(Symbol.for(`openclaw.mainThreadTask`),()=>({context:new a}));function runWithMainThreadTask(e,t,n){let r=u.observer;return r?r.run(e,t,n):t()}const scriptBasename=e=>i(e).replace(/\.[cm]?[jt]s$/u,`.js`),d=r(import.meta.url),f=/* @__PURE__ */ new Map;for(let e of Object.values(d)){let t=scriptBasename(e.distWorkerPath);f.set(t,t),f.set(scriptBasename(e.sourceModulePath),t)}for(let e of Object.values(n)){let t=scriptBasename(e.distWorkerPath);f.set(t,t),f.set(scriptBasename(e.package.distWorkerPath),t),f.set(scriptBasename(`${e.sourceWorkerName}.js`),t)}for(let e of Object.values(t))for(let[t,n]of e.entries){let e=scriptBasename(`${n}.mjs`);f.has(e)||f.set(e,scriptBasename(d[t].distWorkerPath))}const p=new Set(f.values());function normalizeDiagnosticWorkerScript(e){return typeof e==`string`&&p.has(e)?e:`other`}function workerScriptName(e,t=!1){return t||e instanceof URL&&e.protocol!==`file:`?`other`:f.get(scriptBasename(e instanceof URL?o(e):e))??`other`}export{runInDetachedAsyncContext as a,AsyncContext as i,workerScriptName as n,runWithMainThreadTask as r,normalizeDiagnosticWorkerScript as t};