UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 21.2 kB
import{o as e}from"./transcript-record-coerce-eN4p5mcq.mjs";import{i as t}from"./transcript-global-singleton-DIJgobpU.mjs";import{a as n}from"./transcript-plugin-instance-invocation-7pP9ZY8b.mjs";import"./transcript-path-guards-DYqTo0Vr.mjs";import{a as r,i,n as a,r as o,t as s}from"./transcript-gateway-state-owner-errors-C0z_13ZD.mjs";import{S as c,T as l,a as u,c as d,i as f,x as p}from"./transcript-sqlite-error-diagnostics-Bzt01wuM.mjs";import{l as m}from"./transcript-state-dir-BTeq06tQ.mjs";import"./transcript-path-existence-DsAt-_G2.mjs";import{t as h}from"./transcript-version-cakuJMg_.mjs";import{t as g}from"./transcript-sqlite-jsonl-budget-error-DacbQ4UF.mjs";import{t as _}from"./transcript-goals-operations.types-B9w9O4_9.mjs";import{t as v}from"./transcript-session-canonical-key-error-BMfMRBaI.mjs";import{t as y}from"./transcript-session-transcript-read-fence-error-DfU0swK6.mjs";import{d as b,f as x,m as S,p as C}from"./transcript-sqlite-post-commit-BDZjIt2B.mjs";import{n as w,r as T,t as E}from"./transcript-session-metadata-unavailable-error-DL1m1RWN.mjs";import{t as D}from"./transcript-startup-maintenance-required-DocYc5R6.mjs";import{threadId as O}from"node:worker_threads";import k from"node:path";import"node:crypto";import A from"node:fs";const j=t(Symbol.for(`openclaw.quarantineReadCleanupError`),()=>class extends AggregateError{constructor(e,t){super(e,`OpenClaw quarantine reader cleanup failed.`,{cause:e[0]}),this.quarantine=t,this.name=`OpenClawQuarantineReadCleanupError`}}),M=t(Symbol.for(`openclaw.stateDatabaseFailurePaths`),()=>/* @__PURE__ */ new WeakMap);function markOpenClawStateDatabaseFailure(e,t){M.set(e,t)}function readOpenClawStateDatabaseFailurePath(e){return M.get(e)}function findOpenClawStateDatabaseFailure(e,t){let n=[e],r=/* @__PURE__ */ new Set;for(let e of n)if(e instanceof Error&&!r.has(e)){if(r.add(e),M.get(e)===t)return e;n.push(e.cause),e instanceof AggregateError&&n.push(...e.errors)}}var DuplicateAgentError=class extends Error{};const N=`openclaw doctor --fix`;var AuthProfileStoreUnreadableError=class extends Error{constructor(e){super(`Auth profile store ${n(e)} is unreadable; run ${N}.`),this.databasePath=e,this.code=`AUTH_PROFILE_STORE_UNREADABLE`,this.action=N,this.name=`AuthProfileStoreUnreadableError`}},McpOAuthStoreCorruptionError=class extends Error{constructor(e,t,n){super(`MCP OAuth store ${e} is invalid: ${t}`,n),this.name=`McpOAuthStoreCorruptionError`}},SandboxStateOwnerRequiredError=class extends Error{constructor(e){super(`Sandbox workspace preparation cannot run alongside a foreign live owner of the selected state root, or when that ownership cannot be verified. Run this SDK call inside the owning Gateway plugin/runtime, or stop the Gateway through its service owner and wait for any embedded run to finish, then retry offline. Inspect openclaw gateway status; this call does not acquire ownership or route remotely.`,{cause:e}),this.code=`GATEWAY_STATE_OWNER_REQUIRED`,this.name=`SandboxStateOwnerRequiredError`}};async function canonicalizeWorkspacePathAsync(e,t){let n=k.resolve(m(e)),r=t(n),i=/* @__PURE__ */ new Set;for(let e=0;e<40;e+=1){let e=[],a=n;for(;;){try{return t(k.join(await A.promises.realpath(a),...e.toReversed()))}catch{}try{if((await A.promises.lstat(a)).isSymbolicLink()){let t=k.normalize(a);if(i.has(t))return r;i.add(t),n=k.resolve(k.dirname(a),await A.promises.readlink(a),...e.toReversed());break}}catch{}let o=k.dirname(a);if(o===a)return r;e.push(k.basename(a)),a=o}}return r}async function resolveCanonicalWorkspacePathAsync(e){return canonicalizeWorkspacePathAsync(e,k.normalize)}var WorkspaceAliasRepointedError=class extends Error{constructor(e){super(`workspace path alias points to a different current target: ${e.aliasPath} now resolves to ${e.currentWorkspacePath}, but its stored workspace state belongs to ${e.storedWorkspacePath}. Run \`openclaw doctor --fix\` and confirm the move, or use \`openclaw doctor --fix --force\`.`),this.code=`WORKSPACE_ALIAS_REPOINTED`,this.name=`WorkspaceAliasRepointedError`,this.aliasPath=e.aliasPath,this.storedWorkspacePath=e.storedWorkspacePath,this.currentWorkspacePath=e.currentWorkspacePath}},WorktreeRemovalContentionError=class extends Error{constructor(e,t,n){super(t),this.kind=e,this.blockedByRun=n,this.name=`WorktreeRemovalContentionError`}},WorktreeRemovalLockError=class extends Error{constructor(e,t){super(t),this.kind=e,this.name=`WorktreeRemovalLockError`}},SessionWorktreeSourceChangedError=class extends Error{},SessionWorktreeLifecycleError=class extends Error{constructor(e,t){super(e),this.reason=t}},SqliteSessionMutationConflictError=class extends Error{constructor(e){super(`SQLite session state changed while preparing ${e}`),this.operationLabel=e,this.name=`SqliteSessionMutationConflictError`}},SqliteTranscriptMutationConflictError=class extends Error{constructor(e){super(`SQLite transcript changed while preparing rewrite for ${e}`),this.sessionId=e,this.name=`SqliteTranscriptMutationConflictError`}},SessionEntryLifecycleUpsertConflictError=class extends Error{constructor(e){super(`SQLite session entry changed before lifecycle upsert for ${e}`),this.sessionKey=e,this.name=`SessionEntryLifecycleUpsertConflictError`}},SessionPendingInputCustodyError=class extends Error{};function isRedactedIdentifier(e){return typeof e==`string`&&/^(?:-|sha256:[0-9a-f]{12})$/.test(e)}function parseTranscriptAppendRefusal(t){if(!e(t)||!isRedactedIdentifier(t.agentIdHash)||!isRedactedIdentifier(t.expectedSessionIdHash)||!isRedactedIdentifier(t.sessionKeyHash))return;let n={agentIdHash:t.agentIdHash,expectedSessionIdHash:t.expectedSessionIdHash,sessionKeyHash:t.sessionKeyHash};if(t.code===`session-entry-missing`)return{...n,code:t.code};if(t.code===`session-rebound`&&isRedactedIdentifier(t.actualSessionIdHash))return{...n,code:t.code,actualSessionIdHash:t.actualSessionIdHash}}var SessionTranscriptWriterClaimReboundError=class extends Error{constructor(e){super(`session writer claim changed before transcript persistence`,{cause:e}),this.name=`SessionTranscriptWriterClaimReboundError`}},ModelAccountConnectAuthorityError=class extends Error{constructor(){super(`This account action requires a current authorized connection; reconnect and try again.`)}},WorkerSessionAlreadyAttachedError=class extends Error{constructor(e,t){super(`Session ${e} is already attached to worker environment ${t}`),this.sessionId=e,this.environmentId=t}},PluginBlobStoreError=class extends Error{constructor(e,t){super(e,{cause:t.cause}),this.name=`PluginBlobStoreError`,this.code=t.code,this.operation=t.operation,t.path&&(this.path=t.path)}};function capturePluginStateErrorCause(e,t,n=/* @__PURE__ */ new Set){if(e===void 0)return;let r=t?.(e);if(r)return{canonical:r};if(e===null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`||typeof e==`bigint`||typeof e==`symbol`)return{name:`Error`,message:String(e)};if(typeof e!=`object`)return{name:`Error`,message:`Unknown SQLite error cause`};if(n.has(e)||n.size>=8)return{name:`Error`,message:`Additional SQLite error cause omitted`};n.add(e);let i=`name`in e&&typeof e.name==`string`?e.name:`Error`,a=`message`in e&&typeof e.message==`string`?e.message:i,o=`code`in e?e.code:void 0,s=`errcode`in e?e.errcode:void 0,c=`errno`in e?e.errno:void 0;return{name:i,message:a,...typeof o==`string`||typeof o==`number`?{errorCode:o}:{},...typeof s==`number`?{errcode:s}:{},...typeof c==`number`?{errno:c}:{},...`cause`in e?{cause:capturePluginStateErrorCause(e.cause,t,n)}:{},...e instanceof AggregateError?{errors:e.errors.slice(0,8).map(e=>capturePluginStateErrorCause(e,t,n))}:{}}}var PluginStateStoreError=class extends Error{constructor(e,t){super(e,{cause:t.cause}),this.name=`PluginStateStoreError`,this.code=t.code,this.operation=t.operation,this.owner=t.owner??{pid:process.pid,threadId:O,version:h},t.path&&(this.path=t.path)}toJSON(){return{name:this.name,message:this.message,code:this.code,operation:this.operation,path:this.path,owner:this.owner,cause:capturePluginStateErrorCause(this.cause)}}},SecretStoreValidationError=class extends Error{constructor(e,t){super(t),this.code=e,this.name=`SecretStoreValidationError`}};const P=`Model selection is locked for this session.`;var ModelSelectionLockedError=class extends Error{constructor(e=P){super(e),this.name=`ModelSelectionLockedError`}},SkillUploadRequestError=class extends Error{constructor(...e){super(...e),this.name=`SkillUploadRequestError`}},SkillLibraryError=class extends Error{constructor(e,t,n,r){super(t,r),this.code=e,this.currentRevision=n,this.name=`SkillLibraryError`}},OpenClawStateDatabaseSchemaMigrationRequiredError=class extends D{constructor(e,t){super(e,`OpenClaw state database schema migration required (${e}) at ${t}; run openclaw doctor --fix to migrate it.`),this.kind=e,this.pathname=t,this.name=`OpenClawStateDatabaseSchemaMigrationRequiredError`}};function normalizeOpenClawStateSchemaReadError(e,t){if(e instanceof Error&&e.message.startsWith(`malformed database schema (idx_skill_workshop_collection_reviews_workspace_time)`)){let n=new OpenClawStateDatabaseSchemaMigrationRequiredError(`legacy-workshop-review-index`,t);return n.cause=e,n}return e}function annotateStartupStateInspectionFailure(e,t,n){return!n?.aborted&&e instanceof Error&&!e.message.includes(t)&&(e.message=`OpenClaw state database ${t} failed startup inspection: ${e.message}`),e}var OpenClawStateLeaseError=class extends Error{constructor(e,t){super(e,{cause:t.cause}),this.name=`OpenClawStateLeaseError`,this.code=t.code,this.loss=t.loss}};const F={"worktree-source-changed":SessionWorktreeSourceChangedError,"model-account-authority":ModelAccountConnectAuthorityError,"duplicate-agent":DuplicateAgentError,"model-selection-locked":ModelSelectionLockedError,"session-canonical-key-migration":v,"session-pending-input-custody":SessionPendingInputCustodyError,"session-transcript-read-fence":y,"skill-upload-request":SkillUploadRequestError,"state-database-access":a,coordinator:S,ownership:x,"newer-schema":T,"jsonl-read-budget":g,"range-error":RangeError,"syntax-error":SyntaxError,"type-error":TypeError};function isMessageOnlyErrorIdentity(e){return typeof e.type==`string`&&Object.hasOwn(F,e.type)}function identifyError(e){if(e instanceof SandboxStateOwnerRequiredError)return{type:`sandbox-state-owner-required`};if(e instanceof AuthProfileStoreUnreadableError)return{type:`auth-profile-store-unreadable`,databasePath:e.databasePath};if(e instanceof SessionWorktreeLifecycleError&&e.reason===`owner-mismatch`)return{type:`session-worktree-owner-mismatch`};if(e instanceof WorktreeRemovalContentionError)return{type:`worktree-removal-contention`,kind:e.kind,...e.blockedByRun?{blockedByRun:{worktreeId:e.blockedByRun.worktreeId,pid:e.blockedByRun.pid}}:{}};if(e instanceof WorktreeRemovalLockError)return{type:`worktree-removal-lock`,kind:e.kind};if(e instanceof PluginStateStoreError)return{type:`plugin-state`,stateCode:e.code,operation:e.operation,path:e.path,owner:{pid:e.owner.pid,threadId:e.owner.threadId,version:e.owner.version}};if(e instanceof SkillLibraryError)return{type:`skill-library`,libraryCode:e.code,...e.currentRevision===void 0?{}:{currentRevision:e.currentRevision}};if(e instanceof SecretStoreValidationError)return{type:`secret-store-validation`,secretCode:e.code};if(e instanceof WorkerSessionAlreadyAttachedError)return{type:`worker-session-already-attached`,sessionId:e.sessionId,environmentId:e.environmentId};if(e instanceof PluginBlobStoreError)return{type:`plugin-blob`,blobCode:e.code,operation:e.operation,...e.path===void 0?{}:{path:e.path}};if(e instanceof WorkspaceAliasRepointedError)return{type:`workspace-alias-repointed`,aliasPath:e.aliasPath,storedWorkspacePath:e.storedWorkspacePath,currentWorkspacePath:e.currentWorkspacePath};if(e instanceof McpOAuthStoreCorruptionError)return{type:`mcp-oauth-corruption`};if(e instanceof _)return{type:`session-goal-operation`,goalCode:e.code};if(e instanceof SessionEntryLifecycleUpsertConflictError)return{type:`session-lifecycle-upsert-conflict`,sessionKey:e.sessionKey};if(e instanceof SessionTranscriptWriterClaimReboundError){let t=parseTranscriptAppendRefusal(e.cause);return{type:`session-transcript-writer-claim-rebound`,...t?{refusal:t}:{}}}if(e instanceof SqliteSessionMutationConflictError)return{type:`session-mutation-conflict`,operationLabel:e.operationLabel};if(e instanceof SqliteTranscriptMutationConflictError)return{type:`session-transcript-mutation-conflict`,sessionId:e.sessionId};if(e instanceof E)return{type:`session-metadata`,reason:e.reason,missingTables:[...e.missingTables]};if(e instanceof s)return{type:`state-owner-contention`,databasePath:e.databasePath};if(e instanceof o)return{type:`state-admission-pending`,databasePath:e.databasePath};if(e instanceof r)return{type:`state-offline-maintenance`,databasePath:e.databasePath};if(e instanceof i)return{type:`state-maintenance-scope`};if(e instanceof OpenClawStateLeaseError)return{type:`state-lease`,leaseCode:e.code,leaseLoss:e.loss};if(e instanceof C)return{type:`ownership-metadata`,databasePath:e.databasePath};if(e instanceof b)return{type:`external-ownership`,databasePath:e.databasePath,managerId:e.managerId};if(e instanceof OpenClawStateDatabaseSchemaMigrationRequiredError)return{type:`state-migration`,kind:e.kind,pathname:e.pathname};if(e instanceof w)return{type:`agent-media-migration`,pathname:e.pathname,schemaVersion:e.schemaVersion};for(let[t,n]of Object.entries(F))if(e instanceof n)return{type:t};return e instanceof D?{type:`maintenance`,kind:e.kind}:{type:e instanceof AggregateError?`aggregate`:`error`}}function createError(e){if(isMessageOnlyErrorIdentity(e)){let t=F[e.type];return new t(e.message)}switch(e.type){case`sandbox-state-owner-required`:return new SandboxStateOwnerRequiredError;case`session-worktree-owner-mismatch`:return new SessionWorktreeLifecycleError(e.message,`owner-mismatch`);case`worktree-removal-contention`:return new WorktreeRemovalContentionError(e.kind,e.message,e.blockedByRun);case`worktree-removal-lock`:return new WorktreeRemovalLockError(e.kind,e.message);case`plugin-state`:return new PluginStateStoreError(e.message,{code:e.stateCode,operation:e.operation,path:e.path,owner:e.owner});case`skill-library`:return new SkillLibraryError(e.libraryCode,e.message,e.currentRevision);case`secret-store-validation`:return new SecretStoreValidationError(e.secretCode,e.message);case`worker-session-already-attached`:return new WorkerSessionAlreadyAttachedError(e.sessionId,e.environmentId);case`workspace-alias-repointed`:return new WorkspaceAliasRepointedError(e);case`session-goal-operation`:return new _(e.goalCode,e.message);case`session-lifecycle-upsert-conflict`:return new SessionEntryLifecycleUpsertConflictError(e.sessionKey);case`session-mutation-conflict`:return new SqliteSessionMutationConflictError(e.operationLabel);case`session-transcript-mutation-conflict`:return new SqliteTranscriptMutationConflictError(e.sessionId);case`session-transcript-writer-claim-rebound`:return new SessionTranscriptWriterClaimReboundError(e.refusal);case`session-metadata`:return new E(e.reason,void 0,e.missingTables);case`error`:return Error(e.message);case`mcp-oauth-corruption`:return new McpOAuthStoreCorruptionError(``,``);case`aggregate`:return AggregateError([],e.message);case`auth-profile-store-unreadable`:return new AuthProfileStoreUnreadableError(e.databasePath);case`state-owner-contention`:return new s(e.databasePath);case`state-admission-pending`:return new o(e.databasePath,e.message);case`state-offline-maintenance`:return new r(e.databasePath,e.message);case`state-maintenance-scope`:return new i(``);case`ownership-metadata`:return new C(e.databasePath,``);case`external-ownership`:return new b(e.databasePath,e.managerId);case`plugin-blob`:return new PluginBlobStoreError(e.message,{code:e.blobCode,operation:e.operation,...e.path===void 0?{}:{path:e.path}});case`state-lease`:return new OpenClawStateLeaseError(e.message,{code:e.leaseCode,loss:e.leaseLoss});case`maintenance`:return new D(e.kind,e.message);case`state-migration`:return new OpenClawStateDatabaseSchemaMigrationRequiredError(e.kind,e.pathname)}return new w(e.pathname,e.schemaVersion)}function isScalar(e){return e===null||typeof e==`string`||typeof e==`boolean`||typeof e==`number`&&Number.isFinite(e)}function isNativeErrorCode(e){return typeof e==`number`&&Number.isInteger(e)&&e>=0&&e<=2147483647}function isWorkerOutcomeCode(e){return e===`outcome-unknown`||e===`unavailable`}function encodeOpenClawStateWorkerError(e,t={}){if(!(e instanceof Error))return;let n=[],r=[],i=/* @__PURE__ */ new Map,a=!1,encodeValue=e=>{if(!(e instanceof Error))return isScalar(e)?{value:e}:{undefined:!0};let t=i.get(e);if(t!==void 0)return{ref:t};let n=r.length;return i.set(e,n),r.push(e),{ref:n}};try{encodeValue(e);for(let e of r){let{name:t,message:r}=e;if(typeof t!=`string`||typeof r!=`string`)return;let i=identifyError(e);if(Object.entries(i).some(([e,t])=>(e===`owner`||e===`blockedByRun`||e===`refusal`||e===`leaseLoss`&&t!==void 0?Object.values(t):e===`missingTables`&&Array.isArray(t)?t:[t]).some(e=>e!==void 0&&!isScalar(e))))return;let o=u(e),s=c(e,`outcome-unknown`)||c(e,`unavailable`),l=readOpenClawStateDatabaseFailurePath(e),d=`errcode`in e?e.errcode:void 0;a||=s||l!==void 0||o||isNativeErrorCode(d)||f(e)||e instanceof j||i.type!==`error`&&i.type!==`aggregate`;let p=`code`in e?e.code:void 0,m=`errno`in e?e.errno:void 0;n.push({...i,name:s?`SqliteWorkerError`:t===`SqliteWorkerError`&&isWorkerOutcomeCode(p)?`Error`:t,message:r,...typeof p==`string`||typeof p==`number`&&Number.isFinite(p)?{code:p}:{},...isNativeErrorCode(d)?{errcode:d}:{},...typeof m==`number`&&Number.isInteger(m)?{errno:m}:{},...o?{nativeOpen:!0}:{},...l===void 0?{}:{stateDatabasePath:l},...`cause`in e&&!(i.type===`session-transcript-writer-claim-rebound`&&i.refusal)?{cause:encodeValue(e.cause)}:{},...e instanceof AggregateError?{errors:e.errors.map(encodeValue)}:{}})}return a||t.includeOrdinary===!0?{version:1,root:0,nodes:n}:void 0}catch{return}}function decodeErrorGraph(e,t){try{if(e.version!==1)return;let n=e.nodes;if(t.includeOrdinary!==!0&&!n.some(e=>e.stateDatabasePath!==void 0||e.nativeOpen===!0||e.name===`SqliteWorkerError`&&isWorkerOutcomeCode(e.code)||isNativeErrorCode(e.errcode)||f(e)||e.type===`aggregate`&&e.name===`OpenClawQuarantineReadCleanupError`||e.type!==`error`&&e.type!==`aggregate`))return;let r=n.map(e=>{if(e.name===`SqliteWorkerError`&&isWorkerOutcomeCode(e.code)){let t=new p(e.message,e.code);return e.type===`error`?t:l(createError(e),t)}return createError(e)}),decodeValue=e=>`ref`in e?r[e.ref]:`value`in e?e.value:void 0;for(let[e,t]of n.entries()){let n=r[e];n.name=t.name,n.message=t.message,t.nativeOpen&&d(n),t.stateDatabasePath!==void 0&&markOpenClawStateDatabaseFailure(n,t.stateDatabasePath);for(let[e,r]of Object.entries({...t.code===void 0?{}:{code:t.code},...t.errcode===void 0?{}:{errcode:t.errcode},...t.errno===void 0?{}:{errno:t.errno},...t.cause?{cause:decodeValue(t.cause)}:{}}))Object.defineProperty(n,e,{value:r,configurable:!0,writable:!0});n instanceof AggregateError&&(n.errors=(t.errors??[]).map(decodeValue))}return{errors:r,root:e.root}}catch{return}}const I=t(Symbol.for(`openclaw.sharedStateWorkerErrorPayloads`),()=>/* @__PURE__ */ new WeakMap);function retainOpenClawStateWorkerErrorPayload(e,t){t&&I.set(e,t)}function hydrateOpenClawStateWorkerError(e,t={}){if(!(e instanceof Error))return e;let n=/* @__PURE__ */ new Map,r=[{error:e,finish:!1}],replace=e=>e instanceof Error?n.get(e)??e:e;for(;r.length>0;){let e=r.pop(),{error:i}=e;if(!e.finish){if(n.has(i))continue;n.set(i,i);let e=I.get(i),a=e===void 0?void 0:decodeErrorGraph(e,t);if(a){n.set(i,a.errors[a.root]);continue}if(r.push({error:i,finish:!0}),i.cause instanceof Error&&r.push({error:i.cause,finish:!1}),i instanceof AggregateError)for(let e of i.errors)e instanceof Error&&r.push({error:e,finish:!1});continue}let a=replace(i.cause),o=i instanceof AggregateError?i.errors:void 0,s=o?.map(replace);if(a===i.cause&&(!s||s.every((e,t)=>e===o?.[t])))continue;let c=i instanceof AggregateError?AggregateError([],i.message):Error(i.message);Object.setPrototypeOf(c,Object.getPrototypeOf(i));let l=Object.getOwnPropertyDescriptors(i);`cause`in i&&(l.cause={configurable:!0,writable:!0,...l.cause,value:a}),s&&(l.errors={configurable:!0,writable:!0,...l.errors,value:s}),Object.defineProperties(c,l),n.set(i,c)}return n.get(e)}export{findOpenClawStateDatabaseFailure as _,annotateStartupStateInspectionFailure as a,ModelSelectionLockedError as c,SessionPendingInputCustodyError as d,SessionEntryLifecycleUpsertConflictError as f,resolveCanonicalWorkspacePathAsync as g,WorkspaceAliasRepointedError as h,OpenClawStateDatabaseSchemaMigrationRequiredError as i,SessionTranscriptWriterClaimReboundError as l,SqliteTranscriptMutationConflictError as m,hydrateOpenClawStateWorkerError as n,normalizeOpenClawStateSchemaReadError as o,SqliteSessionMutationConflictError as p,retainOpenClawStateWorkerErrorPayload as r,P as s,encodeOpenClawStateWorkerError as t,parseTranscriptAppendRefusal as u,markOpenClawStateDatabaseFailure as v,j as y};