openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 15.5 kB
JavaScript
import{i as e}from"./transcript-global-singleton-DIJgobpU.mjs";import{i as t,n}from"./transcript-path-guards-DYqTo0Vr.mjs";import{a as r}from"./transcript-string-coerce-BxRUqIXb.mjs";import{n as i,t as a}from"./transcript-regexp--qgq5Lua.mjs";import"./transcript-number-coercion-Dr06QpMa.mjs";import{d as o,f as s,l as c,t as l}from"./transcript-state-dir-BTeq06tQ.mjs";import"./transcript-src-DFL7yLCI.mjs";import{createRequire as u}from"node:module";import d from"node:path";import{AsyncLocalStorage as f,AsyncResource as p}from"node:async_hooks";import"node:fs";import"node:fs/promises";import m from"node:os";import"@openclaw/fs-safe/path";import{canUseRootFileOpen as h,openRootFileSync as g}from"@openclaw/fs-safe/advanced";import{FsSafeError as _}from"@openclaw/fs-safe/errors";import"@openclaw/fs-safe/output";import{openLocalFileSafely as v,root as y}from"@openclaw/fs-safe/root";import"@openclaw/fs-safe/secure-file";import"@openclaw/fs-safe/walk";const b=Symbol.for(`openclaw.provider-auth-persistence-error`);function isProviderAuthPersistenceError(e){try{return b in e&&e[b]===!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 coerceErrorMessage(e){return e instanceof Error?e.message:String(e)}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 readErrorName(e){if(!e||typeof e!=`object`)return``;let t=e.name;return typeof t==`string`?t:``}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 extractErrorCodeOrErrno(e){let t=extractErrorCode(e);if(t)return t.trim().toUpperCase();if(!e||typeof e!=`object`)return;let n=e.errno;if(typeof n==`string`&&n.trim())return n.trim().toUpperCase();if(typeof n==`number`&&Number.isFinite(n))return String(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 enterAsyncStore(e,t){return this.enterWith(e),t()}function runWithAsyncStore(e,t,n){return e.getStore()===t?n():new p(`OpenClawAsyncStore`).runInAsyncScope(enterAsyncStore,e,t,n)}const x=[`true`,`1`,`yes`,`on`],S=[`false`,`0`,`no`,`off`];function asBoolean(e){return typeof e==`boolean`?e:void 0}function parseBooleanValue(e,t={}){let n=asBoolean(e);if(n!==void 0)return n;let i=r(e);if(i){if((t.truthy??x).includes(i))return!0;if((t.falsy??S).includes(i))return!1}}const C=e(Symbol.for(`openclaw.processEnvironmentKey`),()=>({key:{},aliases:new WeakSet([process.env])}));function resolveEnvironmentKey(e){return e===void 0||e===process.env||C.aliases.has(e)?C.key:e}function captureEnvironmentKey(e=process.env){let t=resolveEnvironmentKey(e);return t===C.key&&C.aliases.add(e),t}const w=`OPENCLAW_FS_SAFE_NATIVE_MODE`,T=[`FS_SAFE_PYTHON_MODE`,`OPENCLAW_FS_SAFE_PYTHON_MODE`],E=[...T,`FS_SAFE_PYTHON`,`OPENCLAW_FS_SAFE_PYTHON`,`OPENCLAW_PINNED_PYTHON`,`OPENCLAW_PINNED_WRITE_PYTHON`],D=/* @__PURE__ */ new WeakMap;let O=!1;function nativeModeIsValid(e){let t=e?.trim().toLowerCase()??``;return/^(?:0|false|off|never|1|true|on|auto|required|require)$/u.test(t)}function currentFallback(e){let t=D.get(resolveEnvironmentKey(e));return t&&e[t.key]===t.value?t:void 0}function fsSafeEnvInput(e){let t=currentFallback(e);if(!t)return e;let n={...e,[t.key]:t.previous};return t.existed||delete n[t.key],n}function clearFsSafeEnvFallback(e){let t=currentFallback(e);D.delete(resolveEnvironmentKey(e)),t&&(t.existed?e[t.key]=t.previous:delete e[t.key])}function normalizeFsSafeNativeEnv(e=process.env){clearFsSafeEnvFallback(e);let t=E.filter(t=>e[t]!==void 0);if(t.length&&e===process.env&&!O&&(O=!0,process.emitWarning(`${t.join(`, `)} is deprecated. OpenClaw maps legacy mode values to native mode only when neither FS_SAFE_NATIVE_MODE nor OPENCLAW_FS_SAFE_NATIVE_MODE selects a mode. Replace Python mode variables with native mode variables; interpreter path settings are ignored.`,{code:`FS_SAFE_PYTHON_DEPRECATED`,type:`DeprecationWarning`})),nativeModeIsValid(e.FS_SAFE_NATIVE_MODE)||nativeModeIsValid(e[w]))return;let n=T.map(t=>e[t]).find(e=>e!==void 0);if(n===void 0)return;let r=Object.keys(e),i=!r.includes(w)&&Object.hasOwn(e,w)?r.find(e=>e.toUpperCase()===w)??w:w,a=Object.hasOwn(e,i),o=e[i];e[i]=n,D.set(captureEnvironmentKey(e),{key:i,value:n,previous:o,existed:a})}const k=[[`ZAI_API_KEY`,`Z_AI_API_KEY`]];function normalizeZaiEnv(e=process.env){!e.ZAI_API_KEY?.trim()&&e.Z_AI_API_KEY?.trim()&&(e.ZAI_API_KEY=e.Z_AI_API_KEY)}function expandEnvNormalizationKeys(e){let t=/* @__PURE__ */ new Set;for(let n of e)for(let e of resolveEnvNormalizationKeys(n))t.add(e);return t}function resolveEnvNormalizationKeys(e){let t=process.platform===`win32`?e.toUpperCase():e;return k.find(e=>e.some(e=>e===t))??[t]}function isTruthyEnvValue(e){return parseBooleanValue(e)===!0}const A=/* @__PURE__ */ new Set([`__proto__`,`prototype`,`constructor`]);function isBlockedObjectKey(e){return A.has(e)}let j;function isJson5Parser(e){return typeof e==`object`&&!!e&&`parse`in e&&typeof e.parse==`function`}function setJson5Runtime(e){let t=isJson5Parser(e)?e:typeof e==`object`&&e&&`default`in e?e.default:void 0;if(!isJson5Parser(t))throw Error(`json5 parser unavailable`);return j=t,t}function loadJson5Parser(){if(j)return j;let e=i();if(e!==void 0)return setJson5Runtime(e);if(typeof SEALED_RUNTIME_BUILD==`boolean`&&SEALED_RUNTIME_BUILD)throw Error(`sealed JSON5 runtime was not registered before use`);return setJson5Runtime(u(import.meta.url)(`json5`))}function parseJsonWithJson5Fallback(e,t){try{return JSON.parse(e)}catch{return(t??loadJson5Parser()).parse(e)}}function expectDefined(e,t){if(e==null)throw Error(`expected `+t+` to be defined`);return e}function isHighSurrogate(e){return e>=55296&&e<=56319}function isLowSurrogate(e){return e>=56320&&e<=57343}function avoidTrailingHighSurrogateBreak(e,t,n){if(n<=t||n>=e.length||!isHighSurrogate(e.charCodeAt(n-1))||!isLowSurrogate(e.charCodeAt(n)))return n;let r=n-1;return r>t?r:n+1}function sliceUtf16Safe(e,t,n){let r=e.length,i=t<0?Math.max(r+t,0):Math.min(t,r),a=n===void 0?r:n<0?Math.max(r+n,0):Math.min(n,r);return a<=i?``:(i>0&&i<r&&isLowSurrogate(e.charCodeAt(i))&&isHighSurrogate(e.charCodeAt(i-1))&&(i+=1),a>0&&a<r&&isHighSurrogate(e.charCodeAt(a-1))&&isLowSurrogate(e.charCodeAt(a))&&--a,e.slice(i,a))}function truncateUtf16Safe(e,t){let n=Math.max(0,Math.floor(t));return e.length<=n?e:sliceUtf16Safe(e,0,n)}const M=`(?:\\x1b\\]|\\x9d)`,N=`(?:\\x1b\\\\|\\x07|\\x9c)`,P=RegExp(`${M}[^\\x07\\x1b\\x9c]*${N}`,`y`);function matchAnsiOscAt(e,t){return P.lastIndex=t,P.exec(e)?.[0]}function scanAnsiCsiAt(e,t){let n=e.charCodeAt(t);if(n!==155&&(n!==27||e.charCodeAt(t+1)!==91))return;let r=t+(n===155?1:2),i=[],a=!1;for(;r<e.length;){let t=e.charCodeAt(r);if(t===24||t===26){r+=1,a=!0;break}if(t===27||t===155){a=!0;break}if(t<=31||t===127)i.push(e.charAt(r)),r+=1;else if(t>=32&&t<=63)r+=1;else{t>=64&&t<=126&&(r+=1),a=!0;break}}return{controls:i,ended:a,value:e.slice(t,r)}}const F=RegExp(`${`${M}[\\s\\S]*?${N}`}|[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]`,`y`);new Intl.Segmenter(void 0,{granularity:`grapheme`});function hasAnsiIntroducer(e){return e.includes(`\x1B`)||e.includes(``)||e.includes(``)}function stripAnsiInternal(e,t){if(!hasAnsiIntroducer(e))return e;let n=[],r=0,i=0;for(;i<e.length;){let a=e.charCodeAt(i);if(a!==27&&a!==155&&a!==157){i+=1;continue}let o=matchAnsiOscAt(e,i),s=o?void 0:scanAnsiCsiAt(e,i);F.lastIndex=i;let c=!o&&t.compatibilityGrammar?F.exec(e)?.[0]:void 0,l=o?.length??s?.value.length??c?.length;if(l===void 0)i+=1;else{if(s&&!s.ended&&t.preserveIncompleteCsi)break;s?.controls.length===0&&c&&(l=Math.max(l,c.length)),n.push(e.slice(r,i),...s?.controls??[]),i+=l,r=i}}return n.push(e.slice(r)),n.join(``)}function stripAnsi(e){return stripAnsiInternal(e,{compatibilityGrammar:!1})}const I=/* @__PURE__ */ RegExp(`[\0--]`,`g`);function sanitizeForLog(e){return stripAnsi(e).replace(I,``)}function sanitizeTerminalText(e){return stripAnsi(e).replace(/[\p{Cc}\p{Bidi_Control}]/gu,e=>e===`\r`?`\\r`:e===`
`?`\\n`:e===` `?`\\t`:``)}function resolveConfigDir(e=process.env,t=m.homedir){let n=e.OPENCLAW_STATE_DIR?.trim();if(n)return c(n,e,t);let r=e.OPENCLAW_CONFIG_PATH?.trim();return r?d.dirname(c(r,e,t)):l(e,t)}function shortenPathWithHome(e,{home:r,prefix:i}){if(e===r)return i;if(e.startsWith(`${r}/`)||process.platform===`win32`&&e.startsWith(`${r}\\`))return`${i}${e.slice(r.length)}`;if(process.platform===`win32`&&d.win32.isAbsolute(e)&&n(r,e)){let n=d.win32.relative(t(r),t(e));return d.win32.join(i,n)}return e}function isAbortError(e){if(!e||typeof e!=`object`)return!1;try{return(`name`in e?String(e.name):``)===`AbortError`||(`message`in e&&typeof e.message==`string`?e.message:``)===`This operation was aborted`}catch{return!1}}async function root$1(e,t){return await y(e,t)}function resolveHomeDir(){return s(process.env,m.homedir)}const L=String.raw`(?<=^|[\s"'\x60(\[{<=:;]|file://)`,R=String.raw`[\s"'\x60)\]}>]`,z=String.raw`[:;](?=[/\\~$]|[A-Za-z]:)`;function resolveHomeDisplayPrefix(){let e=resolveHomeDir();if(e)return o(process.env.OPENCLAW_HOME)?{home:e,prefix:`$OPENCLAW_HOME`}:{home:e,prefix:`~`}}function shortenHomePath(e){let t=resolveHomeDisplayPrefix();return t?shortenPathWithHome(e,t):e}function shortenHomeInString(e){if(!e)return e;let t=resolveHomeDisplayPrefix();if(!t||d.parse(t.home).root===t.home)return e;let n=process.platform===`win32`?String.raw`[\\/]`:`/`,r=RegExp(`${L}${a(t.home)}(?=$|${n}|${R}|[.,;:](?:$|${R})|${z})`,process.platform===`win32`?`giu`:`gu`);return e.replace(r,t.prefix)}resolveConfigDir(),e(Symbol.for(`openclaw.pluginSourceAcquisitionFailures`),()=>/* @__PURE__ */ new WeakSet),e(Symbol.for(`openclaw.pluginSourcePreparationOperations`),()=>/* @__PURE__ */ new WeakSet),e(Symbol.for(`openclaw.pluginInventoryRetiredError`),()=>class extends Error{constructor(){super(`Plugin inventory has retired; begin a new plugin operation.`),this.name=`PluginInventoryRetiredError`}}),e(Symbol.for(`openclaw.pluginSourceRecoveryUnavailableError`),()=>class extends Error{constructor(e){super(`Captured plugin source is missing; its previous code cannot be recovered.`,{cause:e}),this.name=`PluginSourceRecoveryUnavailableError`}});const B=e(Symbol.for(`openclaw.pluginInstanceDrainTimeoutError`),()=>class extends Error{constructor(e,t,n,r){super(e,n),this.settled=t,this.forcedRetirement=r,this.name=`PluginInstanceDrainTimeoutError`}});var V=class InvocationFrame{constructor(e,t=e.invocation){this.retentionOwner=e.retentionOwner,this.invocation=t,this.metadataScope=e.metadataScope,this.cacheScope=e.cacheScope,this.sourceCaptureStorage=e.sourceCaptureStorage}get runtimePluginId(){}get canUseInteractiveStateReadCapacity(){return!1}withScopes(e){return new InvocationFrame(e)}};function createPluginExecutionFrame(e,t){return t?t.withScopes(e):new V(e)}const H=e(Symbol.for(`openclaw.pluginInstanceInvocation`),()=>{let e=new f;return{invocation:{getStore(){return e.getStore()?.invocation},run(t,n){let r=e.getStore();return r?.invocation===t?n():runWithAsyncStore(e,createPluginExecutionFrame({...r,invocation:t},r),n)},exit(t){let n=e.getStore();return n?.invocation?runWithAsyncStore(e,n.withScopes({...n,invocation:void 0}),t):t()}},getFrame(){return e.getStore()},runFrame(t,n){return runWithAsyncStore(e,t,n)}}});H.invocation;const U=H.getFrame;H.runFrame;export{parseBooleanValue as A,toErrorObject as B,normalizeZaiEnv as C,normalizeFsSafeNativeEnv as D,fsSafeEnvInput as E,extractErrorCode as F,extractErrorCodeOrErrno as I,formatErrorMessage as L,coerceErrorMessage as M,collectErrorGraphCandidates as N,captureEnvironmentKey as O,collectNestedErrorCandidates as P,formatErrorStackWithMessage as R,isTruthyEnvValue as S,clearFsSafeEnvFallback as T,truncateUtf16Safe as _,shortenHomePath as a,isBlockedObjectKey as b,root$1 as c,sanitizeTerminalText as d,sanitizeForLog as f,sliceUtf16Safe as g,avoidTrailingHighSurrogateBreak as h,shortenHomeInString as i,runWithAsyncStore as j,resolveEnvironmentKey as k,isAbortError as l,g as m,U as n,_ as o,h as p,B as r,v as s,V as t,resolveConfigDir as u,expectDefined as v,resolveEnvNormalizationKeys as w,expandEnvNormalizationKeys as x,parseJsonWithJson5Fallback as y,readErrorName as z};