openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 19.2 kB
JavaScript
import{a as e}from"./transcript-record-coerce-CPLgmAk9.mjs";import{i as t}from"./transcript-global-singleton-DIJgobpU.mjs";import{i as n}from"./transcript-plugin-instance-invocation-7y9lfaeO.mjs";import{t as r}from"./transcript-gateway-state-owner-errors-LqZAQ-y_.mjs";import{S as i,T as a,a as o,c as s,i as c,x as l}from"./transcript-sqlite-error-diagnostics-CLL4Z7ly.mjs";import{t as u}from"./transcript-version-B8n3Ftv8.mjs";import{t as d}from"./transcript-sqlite-jsonl-budget-error-DacbQ4UF.mjs";import{t as f}from"./transcript-goals-operations.types-CKwYUepY.mjs";import{t as p}from"./transcript-session-canonical-key-error-BMfMRBaI.mjs";import{t as m}from"./transcript-session-transcript-read-fence-error-DfU0swK6.mjs";import{_ as h,g,h as _,m as v}from"./transcript-sqlite-post-commit-B_pko32i.mjs";import{t as y}from"./transcript-sqlite-user-version-CMolZa8i.mjs";import{t as b}from"./transcript-startup-maintenance-required-DocYc5R6.mjs";import{n as x,t as S}from"./transcript-session-metadata-unavailable-error-o8iwpgAr.mjs";import{threadId as C}from"node:worker_threads";import"node:path";import"node:crypto";import"node:fs";const w=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`}}),T=t(Symbol.for(`openclaw.stateDatabaseFailurePaths`),()=>/* @__PURE__ */ new WeakMap);function markOpenClawStateDatabaseFailure(e,t){T.set(e,t)}function readOpenClawStateDatabaseFailurePath(e){return T.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),T.get(e)===t)return e;n.push(e.cause),e instanceof AggregateError&&n.push(...e.errors)}}var DuplicateAgentError=class extends Error{};const E=`openclaw doctor --fix`;var AuthProfileStoreUnreadableError=class extends Error{constructor(e){super(`Auth profile store ${n(e)} is unreadable; run ${E}.`),this.databasePath=e,this.code=`AUTH_PROFILE_STORE_UNREADABLE`,this.action=E,this.name=`AuthProfileStoreUnreadableError`}},McpOAuthStoreCorruptionError=class extends Error{constructor(e,t,n){super(`MCP OAuth store ${e} is invalid: ${t}`,n),this.name=`McpOAuthStoreCorruptionError`}},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:C,version:u},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 D=`Model selection is locked for this session.`;var ModelSelectionLockedError=class extends Error{constructor(e=D){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 b{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 O={"worktree-source-changed":SessionWorktreeSourceChangedError,"model-account-authority":ModelAccountConnectAuthorityError,"duplicate-agent":DuplicateAgentError,"model-selection-locked":ModelSelectionLockedError,"session-canonical-key-migration":p,"session-pending-input-custody":SessionPendingInputCustodyError,"session-transcript-read-fence":m,"skill-upload-request":SkillUploadRequestError,coordinator:h,ownership:_,"newer-schema":y,"jsonl-read-budget":d,"range-error":RangeError,"syntax-error":SyntaxError,"type-error":TypeError};function isMessageOnlyErrorIdentity(e){return typeof e.type==`string`&&Object.hasOwn(O,e.type)}function identifyError(e){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 f)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 S)return{type:`session-metadata`,reason:e.reason,missingTables:[...e.missingTables]};if(e instanceof r)return{type:`state-owner-contention`,databasePath:e.databasePath};if(e instanceof OpenClawStateLeaseError)return{type:`state-lease`,leaseCode:e.code,leaseLoss:e.loss};if(e instanceof g)return{type:`ownership-metadata`,databasePath:e.databasePath};if(e instanceof v)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 x)return{type:`agent-media-migration`,pathname:e.pathname,schemaVersion:e.schemaVersion};for(let[t,n]of Object.entries(O))if(e instanceof n)return{type:t};return e instanceof b?{type:`maintenance`,kind:e.kind}:{type:e instanceof AggregateError?`aggregate`:`error`}}function createError(e){if(isMessageOnlyErrorIdentity(e)){let t=O[e.type];return new t(e.message)}switch(e.type){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 f(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 S(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 r(e.databasePath);case`ownership-metadata`:return new g(e.databasePath,``);case`external-ownership`:return new v(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 b(e.kind,e.message);case`state-migration`:return new OpenClawStateDatabaseSchemaMigrationRequiredError(e.kind,e.pathname)}return new x(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=[],a=/* @__PURE__ */ new Map,s=!1,encodeValue=e=>{if(!(e instanceof Error))return isScalar(e)?{value:e}:{undefined:!0};let t=a.get(e);if(t!==void 0)return{ref:t};let n=r.length;return a.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 a=identifyError(e);if(Object.entries(a).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 l=o(e),u=i(e,`outcome-unknown`)||i(e,`unavailable`),d=readOpenClawStateDatabaseFailurePath(e),f=`errcode`in e?e.errcode:void 0;s||=u||d!==void 0||l||isNativeErrorCode(f)||c(e)||e instanceof w||a.type!==`error`&&a.type!==`aggregate`;let p=`code`in e?e.code:void 0,m=`errno`in e?e.errno:void 0;n.push({...a,name:u?`SqliteWorkerError`:t===`SqliteWorkerError`&&isWorkerOutcomeCode(p)?`Error`:t,message:r,...typeof p==`string`||typeof p==`number`&&Number.isFinite(p)?{code:p}:{},...isNativeErrorCode(f)?{errcode:f}:{},...typeof m==`number`&&Number.isInteger(m)?{errno:m}:{},...l?{nativeOpen:!0}:{},...d===void 0?{}:{stateDatabasePath:d},...`cause`in e&&!(a.type===`session-transcript-writer-claim-rebound`&&a.refusal)?{cause:encodeValue(e.cause)}:{},...e instanceof AggregateError?{errors:e.errors.map(encodeValue)}:{}})}return s||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)||c(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 l(e.message,e.code);return e.type===`error`?t:a(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&&s(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 k=t(Symbol.for(`openclaw.sharedStateWorkerErrorPayloads`),()=>/* @__PURE__ */ new WeakMap);function retainOpenClawStateWorkerErrorPayload(e,t){t&&k.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=k.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{w as _,annotateStartupStateInspectionFailure as a,ModelSelectionLockedError as c,SessionPendingInputCustodyError as d,SessionEntryLifecycleUpsertConflictError as f,markOpenClawStateDatabaseFailure as g,findOpenClawStateDatabaseFailure as h,OpenClawStateDatabaseSchemaMigrationRequiredError as i,SessionTranscriptWriterClaimReboundError as l,SqliteTranscriptMutationConflictError as m,hydrateOpenClawStateWorkerError as n,normalizeOpenClawStateSchemaReadError as o,SqliteSessionMutationConflictError as p,retainOpenClawStateWorkerErrorPayload as r,D as s,encodeOpenClawStateWorkerError as t,parseTranscriptAppendRefusal as u};