UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

2 lines • 7.86 kB
import{i as e,n as t,t as n}from"./control-ui-file.worker-runtime-process-manifest-BlrvoYG_.mjs";import{AsyncLocalStorage as r}from"node:async_hooks";import i,{basename as a}from"node:path";import{fileURLToPath as o}from"node:url";import{hasNodeErrorCode as s,isNodeError as c,isPathInside as l}from"@openclaw/fs-safe/path";import"node:perf_hooks";function isRecord(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function isStringArray(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)}function asOptionalRecord(e){return isRecord(e)?e:void 0}const u=Symbol.for(`openclaw.globalSingletonLifecycleResets`);function resolveGlobalSingletonResetRegistry(){let e=globalThis,t=e[u];if(t instanceof Map)return t;let n=/* @__PURE__ */ new Map;return e[u]=n,n}function resolveGlobalSingleton(e,t,n,r=`close-and-restart`){let i=globalThis,a;return Object.hasOwn(i,e)?a=i[e]:(a=t(),i[e]=a),n&&resolveGlobalSingletonResetRegistry().set(e,{lifecycle:r,reset:()=>n(a)}),a}function resolveGlobalSet(e,t){return resolveGlobalSingleton(e,()=>/* @__PURE__ */ new Set,e=>e.clear(),t)}const d=typeof process>`u`?void 0:process.getBuiltinModule?.(`node:async_hooks`),f=d?resolveGlobalSingleton(Symbol.for(`openclaw.detachedAsyncContext`),()=>new d.AsyncResource(`openclaw.detached-async-context`)):void 0;function runInDetachedAsyncContext(e){return f?f.runInAsyncScope(e):e()}const p=Symbol.for(`openclaw.loggingState`),m=`unowned`;function createUnownedAppliedLoggingConfig(){return m}function createLoggingState(){return{appliedConfig:createUnownedAppliedLoggingConfig(),cachedLogger:null,cachedSettings:null,cachedConsoleSettings:null,overrideSettings:null,invalidEnvLogLevelValue:null,consolePatched:!1,forceConsoleToStderr:!1,earlyConsoleRoutingRestore:null,consoleTimestampPrefix:!1,consoleSubsystemFilter:null,streamErrorHandlersInstalled:!1,rawConsole:null}}const h=globalThis,g=h[p]??createLoggingState();h[p]=g;const _=Symbol.for(`openclaw.provider-auth-persistence-error`);function isProviderAuthPersistenceError(e){try{return _ in e&&e[_]===!0}catch{return!1}}function isErrorObject(e){try{return e instanceof Error||Object.prototype.toString.call(e)===`[object Error]`}catch{return!1}}function isAggregateErrorObject(e){try{if(e instanceof AggregateError)return!0;for(let t=Object.getPrototypeOf(e);t;t=Object.getPrototypeOf(t)){let e=Object.getOwnPropertyDescriptor(t,`constructor`)?.value;if(typeof e==`function`&&e.name===`AggregateError`)return!0}}catch{}return!1}function readProperty(e,t){try{return e[t]}catch{return}}function readErrorText(e,t){let n=readProperty(e,t);return typeof n==`string`?n:void 0}function formatStatusAndCode(e){if((typeof e!=`object`||!e)&&typeof e!=`function`)return;try{if(Object.keys(e).some(e=>e!==`status`&&e!==`code`))return}catch{}let t=readProperty(e,`status`),n=readProperty(e,`code`);if(t!==void 0||n!==void 0)return`status=${typeof t==`string`||typeof t==`number`?String(t):`unknown`} code=${typeof n==`string`||typeof n==`number`?String(n):`unknown`}`}function stringifyUnknown(e){if(e===null||typeof e!=`object`&&typeof e!=`function`)return String(e);try{let t=JSON.stringify(e);if(t!==void 0)return t}catch{}try{return Object.prototype.toString.call(e)}catch{return`Unknown error`}}function readErrorCauses(e){if(!isErrorObject(e))return[];let t=readProperty(e,`cause`),n=isAggregateErrorObject(e)?readProperty(e,`errors`):void 0,r=isProviderAuthPersistenceError(e)?[readProperty(e,`persistenceError`),readProperty(e,`cleanupError`)]:[],i=readErrorText(e,`name`)===`SuppressedError`?[readProperty(e,`error`),readProperty(e,`suppressed`)].map(e=>e??String(e)):[];return[...r,t||void 0,...Array.isArray(n)?n:[],...i]}function formatErrorMessage(e,t={}){let n;if(isErrorObject(e)){n=readErrorText(e,`message`)||readErrorText(e,`name`)||`Error`;let r=/* @__PURE__ */ new Set([n]),appendCauseMessage=e=>{e&&!r.has(e)&&(n+=` | ${e}`,r.add(e))};if(t.includeCode){let t=readProperty(e,`code`);(typeof t==`string`||typeof t==`number`)&&appendCauseMessage(String(t))}let i=collectErrorGraphCandidates(e,readErrorCauses);for(let e of i.slice(1))if(isErrorObject(e)){let t=readErrorText(e,`message`);t&&n.includes(t)?r.add(t):appendCauseMessage(t);let i=readProperty(e,`code`);(typeof i==`string`||typeof i==`number`)&&appendCauseMessage(String(i))}else appendCauseMessage(typeof e==`string`?e:formatStatusAndCode(e)??stringifyUnknown(e))}else n=formatStatusAndCode(e)??stringifyUnknown(e);return t.redact?t.redact(n):n}function formatErrorStackWithMessage(e){let t=readErrorText(e,`name`)||`Error`,n=readErrorText(e,`message`)??``,r=readProperty(e,`stack`);if(typeof r!=`string`||!r)return n||t;if(!n||r.includes(n))return r;let i=`${t}: ${n}`,a=r.indexOf(` `),o=a<0?r:r.slice(0,a);return o===t?i+r.slice(o.length):`${i}\n${r}`}function toErrorObject(e,t){if(e instanceof Error)return e;if(typeof e==`string`)return Error(e);let n=Error(t,{cause:e});return(typeof e==`object`&&e||typeof e==`function`)&&Object.assign(n,e),n}function extractErrorCode(e){if(!e||typeof e!=`object`)return;let t=readProperty(e,`code`);return typeof t==`string`||typeof t==`number`?String(t):void 0}function collectErrorGraphCandidates(e,t){if(e==null)return[];let n=[e],r=(/* @__PURE__ */ new Set()).add(e);for(let e of n)if(e&&typeof e==`object`&&t)for(let i of t(e))i!=null&&!r.has(i)&&(r.add(i),n.push(i));return n}function collectNestedErrorCandidates(e){return collectErrorGraphCandidates(e,e=>{let t=[readProperty(e,`cause`),readProperty(e,`reason`),readProperty(e,`original`),readProperty(e,`error`),readProperty(e,`suppressed`),readProperty(e,`data`)],n=readProperty(e,`errors`);return Array.isArray(n)&&t.push(...n),t})}function isMissingPathError(e){return s(e,`ENOENT`)||s(e,`ENOTDIR`)||s(e,`not-found`)}function normalizeWindowsPathPreservingCase(e){let t=i.win32.normalize(e);if(!t.startsWith(`\\\\?\\`))return t;let n=t.slice(4);return n.toUpperCase().startsWith(`UNC\\`)?`\\\\${n.slice(4)}`:n}const v=resolveGlobalSingleton(Symbol.for(`openclaw.asyncContext`),()=>new r);var AsyncContext=class{constructor(e){this.key=e}getStore(){return v.getStore()?.[this.key]}run(e,t){let n=v.getStore(),r=n?.[this.key];if(Object.is(r,e))return t();let i={...n,[this.key]:e};v.enterWith(i);try{return t()}finally{let e=v.getStore();v.enterWith(e===i?n:{...e,[this.key]:r})}}exit(e){return this.run(void 0,e)}enterWith(e){v.enterWith({...v.getStore(),[this.key]:e})}};const y=resolveGlobalSingleton(Symbol.for(`openclaw.mainThreadTask`),()=>({context:new r}));function runWithMainThreadTask(e,t,n){let r=y.observer;return r?r.run(e,t,n):t()}const scriptBasename=e=>a(e).replace(/\.[cm]?[jt]s$/u,`.js`),b=n(import.meta.url),x=/* @__PURE__ */ new Map;for(let e of Object.values(b)){let t=scriptBasename(e.distWorkerPath);x.set(t,t),x.set(scriptBasename(e.sourceModulePath),t)}for(let e of Object.values(t)){let t=scriptBasename(e.distWorkerPath);x.set(t,t),x.set(scriptBasename(e.package.distWorkerPath),t),x.set(scriptBasename(`${e.sourceWorkerName}.js`),t)}for(let t of Object.values(e))for(let[e,n]of t.entries){let t=scriptBasename(`${n}.mjs`);x.has(t)||x.set(t,scriptBasename(b[e].distWorkerPath))}const S=new Set(x.values());function normalizeDiagnosticWorkerScript(e){return typeof e==`string`&&S.has(e)?e:`other`}function workerScriptName(e,t=!1){return t||e instanceof URL&&e.protocol!==`file:`?`other`:x.get(scriptBasename(e instanceof URL?o(e):e))??`other`}export{isStringArray as S,runInDetachedAsyncContext as _,l as a,asOptionalRecord as b,c,extractErrorCode as d,formatErrorMessage as f,g,m as h,AsyncContext as i,isMissingPathError as l,toErrorObject as m,workerScriptName as n,normalizeWindowsPathPreservingCase as o,formatErrorStackWithMessage as p,runWithMainThreadTask as r,s,normalizeDiagnosticWorkerScript as t,collectNestedErrorCandidates as u,resolveGlobalSet as v,isRecord as x,resolveGlobalSingleton as y};