openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
707 lines (706 loc) • 27 kB
JavaScript
import { n as shortenHomePath, p as isRecord } from "./utils-BclMknzT.mjs";
import { W as resolveGlobalSingleton } from "./path-guards-quCEQx1i.mjs";
import { i as retainSqliteWorkerErrorCode, n as hasSqliteWorkerErrorCode, t as SqliteWorkerError } from "./sqlite-worker-error-Q7g0aE9t.mjs";
import { a as markSqliteNativeOpenFailure, n as isSqliteLockError, r as isSqliteNativeOpenFailure } from "./sqlite-error-diagnostics-DXQCgyiD.mjs";
import { c as VERSION, s as StartupMaintenanceRequiredError, t as SqliteSchemaVersionError } from "./sqlite-user-version-D-rYjp-A.mjs";
import { i as SqliteCoordinatorError, n as OpenClawStateOwnershipError, r as OpenClawStateOwnershipMetadataError, t as OpenClawStateExternalOwnershipError } from "./sqlite-lifecycle-errors-D4bxhyEQ.mjs";
import { t as OpenClawStateDatabaseSchemaMigrationRequiredError } from "./openclaw-state-db-schema-migration-required-wTocmCbq.mjs";
import { t as GatewayStateOwnerContentionError } from "./gateway-state-owner-errors-ccLhqQIq.mjs";
import fsSync from "node:fs";
import path from "node:path";
import { createHash } from "node:crypto";
import { threadId } from "node:worker_threads";
//#region src/state/openclaw-quarantine-error.ts
const DATABASE_QUARANTINE_READ_CLEANUP_ERROR_NAME = "OpenClawQuarantineReadCleanupError";
const OpenClawQuarantineReadCleanupError = resolveGlobalSingleton(Symbol.for("openclaw.quarantineReadCleanupError"), () => class QuarantineReadCleanupError extends AggregateError {
constructor(e, t) {
super(e, "OpenClaw quarantine reader cleanup failed.", { cause: e[0] });
this.quarantine = t;
this.name = DATABASE_QUARANTINE_READ_CLEANUP_ERROR_NAME;
}
});
//#endregion
//#region src/state/openclaw-state-db-failure.ts
const failurePaths = resolveGlobalSingleton(Symbol.for("openclaw.stateDatabaseFailurePaths"), () => /* @__PURE__ */ new WeakMap());
/** Preserve the terminal admission owner's path through worker error transport. */
function markOpenClawStateDatabaseFailure(e, t) {
failurePaths.set(e, t);
}
function readOpenClawStateDatabaseFailurePath(e) {
return failurePaths.get(e);
}
/** Cleanup aggregates must retain the original refusal without attributing unrelated errors. */
function findOpenClawStateDatabaseFailure(e, t) {
const n = [e];
const r = /* @__PURE__ */ new Set();
for (const e of n) {
if (!(e instanceof Error) || r.has(e)) continue;
r.add(e);
if (failurePaths.get(e) === t) return e;
n.push(e.cause);
if (e instanceof AggregateError) n.push(...e.errors);
}
}
//#endregion
//#region src/agents/agent-create-error.ts
var DuplicateAgentError = class extends Error {};
//#endregion
//#region src/agents/auth-profiles/store-unreadable-error.ts
const AUTH_PROFILE_MIGRATION_COMMAND = "openclaw doctor --fix";
var AuthProfileStoreUnreadableError = class extends Error {
constructor(e) {
super(`Auth profile store ${shortenHomePath(e)} is unreadable; run ${AUTH_PROFILE_MIGRATION_COMMAND}.`);
this.databasePath = e;
this.code = "AUTH_PROFILE_STORE_UNREADABLE";
this.action = AUTH_PROFILE_MIGRATION_COMMAND;
this.name = "AuthProfileStoreUnreadableError";
}
};
//#endregion
//#region src/agents/mcp-oauth-store-error.ts
var McpOAuthStoreCorruptionError = class extends Error {
constructor(e, t, n) {
super(`MCP OAuth store ${e} is invalid: ${t}`, n);
this.name = "McpOAuthStoreCorruptionError";
}
};
//#endregion
//#region src/agents/workspace-state-identity.ts
const WORKSPACE_ALIAS_REPOINTED_ERROR_CODE = "WORKSPACE_ALIAS_REPOINTED";
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_ERROR_CODE;
this.name = "WorkspaceAliasRepointedError";
this.aliasPath = e.aliasPath;
this.storedWorkspacePath = e.storedWorkspacePath;
this.currentWorkspacePath = e.currentWorkspacePath;
}
};
//#endregion
//#region src/agents/worktrees/errors.ts
var WorktreeRemovalContentionError = class extends Error {
constructor(e, t, n) {
super(t);
this.kind = e;
this.blockedByRun = n;
this.name = "WorktreeRemovalContentionError";
}
};
var WorktreeRemovalLockError = class extends Error {
constructor(e, t) {
super(t);
this.kind = e;
this.name = "WorktreeRemovalLockError";
}
};
var SessionWorktreeSourceChangedError = class extends Error {};
var SessionWorktreeLifecycleError = class extends Error {
constructor(e, t) {
super(e);
this.reason = t;
}
};
//#endregion
//#region src/config/sessions/goals-operations.types.ts
var SessionGoalOperationError = class extends Error {
constructor(e, t) {
super(t);
this.code = e;
this.name = "SessionGoalOperationError";
}
};
//#endregion
//#region src/config/sessions/session-canonical-key-error.ts
var SessionCanonicalKeyMigrationRequiredError = class extends Error {
constructor(e) {
super(`${e}; stop the Gateway and run openclaw doctor --fix`);
this.code = "SESSION_CANONICAL_KEY_MIGRATION_REQUIRED";
this.name = "SessionCanonicalKeyMigrationRequiredError";
}
};
//#endregion
//#region src/config/sessions/session-mutation-conflict-error.ts
var SqliteSessionMutationConflictError = class extends Error {
constructor(e) {
super(`SQLite session state changed while preparing ${e}`);
this.operationLabel = e;
this.name = "SqliteSessionMutationConflictError";
}
};
var SqliteTranscriptMutationConflictError = class extends Error {
constructor(e) {
super(`SQLite transcript changed while preparing rewrite for ${e}`);
this.sessionId = e;
this.name = "SqliteTranscriptMutationConflictError";
}
};
var SessionEntryLifecycleUpsertConflictError = class extends Error {
constructor(e) {
super(`SQLite session entry changed before lifecycle upsert for ${e}`);
this.sessionKey = e;
this.name = "SessionEntryLifecycleUpsertConflictError";
}
};
//#endregion
//#region src/config/sessions/session-pending-input-custody-error.ts
/** Custody refusal must not release already accepted input for another dispatch. */
var SessionPendingInputCustodyError = class extends Error {};
//#endregion
//#region src/config/sessions/session-transcript-read-fence-error.ts
/**
* Thrown when a transcript read crosses the current-turn admission fence, such as a
* stored cursor that already passed the admitted user message during bootstrap or assembly.
*/
var SessionTranscriptReadFenceError = class extends Error {
constructor(e) {
super(e);
this.name = "SessionTranscriptReadFenceError";
}
};
//#endregion
//#region src/config/sessions/session-transcript-writer-claim-error.ts
function isRedactedIdentifier(e) {
return typeof e === "string" && /^(?:-|sha256:[0-9a-f]{12})$/.test(e);
}
/** Transport only the refusal owner's redacted identifiers, never incidental cause fields. */
function parseTranscriptAppendRefusal(e) {
if (!isRecord(e) || !isRedactedIdentifier(e.agentIdHash) || !isRedactedIdentifier(e.expectedSessionIdHash) || !isRedactedIdentifier(e.sessionKeyHash)) return;
const t = {
agentIdHash: e.agentIdHash,
expectedSessionIdHash: e.expectedSessionIdHash,
sessionKeyHash: e.sessionKeyHash
};
if (e.code === "session-entry-missing") return {
...t,
code: e.code
};
if (e.code === "session-rebound" && isRedactedIdentifier(e.actualSessionIdHash)) return {
...t,
code: e.code,
actualSessionIdHash: e.actualSessionIdHash
};
}
var SessionTranscriptWriterClaimReboundError = class extends Error {
constructor(e) {
super("session writer claim changed before transcript persistence", { cause: e });
this.name = "SessionTranscriptWriterClaimReboundError";
}
};
//#endregion
//#region src/gateway/model-account-connect-errors.ts
var ModelAccountConnectAuthorityError = class extends Error {
constructor() {
super("This account action requires a current authorized connection; reconnect and try again.");
}
};
//#endregion
//#region src/gateway/worker-environments/session-attachment.ts
var WorkerSessionAlreadyAttachedError = class extends Error {
constructor(e, t) {
super(`Session ${e} is already attached to worker environment ${t}`);
this.sessionId = e;
this.environmentId = t;
}
};
//#endregion
//#region src/infra/sqlite-jsonl-budget-error.ts
var SqliteJsonlReadBudgetExceededError = class extends Error {};
//#endregion
//#region src/plugin-state/plugin-blob-store.types.ts
var PluginBlobStoreError = class extends Error {
constructor(e, t) {
super(e, { cause: t.cause });
this.name = "PluginBlobStoreError";
this.code = t.code;
this.operation = t.operation;
if (t.path) this.path = t.path;
}
};
//#endregion
//#region src/plugin-state/plugin-state-error-cause.ts
function capturePluginStateErrorCause(e, t, n = /* @__PURE__ */ new Set()) {
if (e === void 0) return;
const 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);
const i = "name" in e && typeof e.name === "string" ? e.name : "Error";
const a = "message" in e && typeof e.message === "string" ? e.message : i;
const o = "code" in e ? e.code : void 0;
const s = "errcode" in e ? e.errcode : void 0;
const 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)) } : {}
};
}
//#endregion
//#region src/plugin-state/plugin-state-error.ts
/** Typed error thrown for plugin-state validation and sqlite failures. */
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,
version: VERSION
};
if (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)
};
}
};
//#endregion
//#region src/secrets/store/secret-store-validation-error.ts
var SecretStoreValidationError = class extends Error {
constructor(e, t) {
super(t);
this.code = e;
this.name = "SecretStoreValidationError";
}
};
const SECRET_STORE_VALUE_MAX_BYTES = 65536;
//#endregion
//#region src/sessions/model-selection-error.ts
const MODEL_SELECTION_LOCKED_MESSAGE = "Model selection is locked for this session.";
/** Retains the caller-visible refusal across the database worker boundary. */
var ModelSelectionLockedError = class extends Error {
constructor(e = MODEL_SELECTION_LOCKED_MESSAGE) {
super(e);
this.name = "ModelSelectionLockedError";
}
};
//#endregion
//#region src/skills/lifecycle/upload-store-error.ts
var SkillUploadRequestError = class extends Error {
constructor(...e) {
super(...e);
this.name = "SkillUploadRequestError";
}
};
//#endregion
//#region src/skills/skill-library-error.ts
var SkillLibraryError = class extends Error {
constructor(e, t, n, r) {
super(t, r);
this.code = e;
this.currentRevision = n;
this.name = "SkillLibraryError";
}
};
//#endregion
//#region src/state/openclaw-agent-db-migration-required.ts
var OpenClawAgentDatabaseMediaMigrationRequiredError = class extends StartupMaintenanceRequiredError {
constructor(e, t) {
super("agent-media", `OpenClaw agent database ${e} uses schema version ${t}; run openclaw doctor --fix to migrate persisted media before using it.`);
this.pathname = e;
this.schemaVersion = t;
this.name = "OpenClawAgentDatabaseMediaMigrationRequiredError";
}
};
//#endregion
//#region src/state/openclaw-state-lease-error.ts
var OpenClawStateLeaseError = class extends Error {
constructor(e, t) {
super(e, { cause: t.cause });
this.name = "OpenClawStateLeaseError";
this.code = t.code;
this.loss = t.loss;
}
};
//#endregion
//#region src/state/session-metadata-unavailable-error.ts
var SessionMetadataUnavailableError = class extends Error {
constructor(e, t, n = []) {
super(`Session metadata unavailable (${[e, ...n].join(": ")}); retry after the agent store is ready.`, t);
this.reason = e;
this.missingTables = n;
this.name = "SessionMetadataUnavailableError";
}
};
//#endregion
//#region src/state/openclaw-state-worker-error-identity.ts
const MESSAGE_ONLY_ERRORS = {
"worktree-source-changed": SessionWorktreeSourceChangedError,
"model-account-authority": ModelAccountConnectAuthorityError,
"duplicate-agent": DuplicateAgentError,
"model-selection-locked": ModelSelectionLockedError,
"session-canonical-key-migration": SessionCanonicalKeyMigrationRequiredError,
"session-pending-input-custody": SessionPendingInputCustodyError,
"session-transcript-read-fence": SessionTranscriptReadFenceError,
"skill-upload-request": SkillUploadRequestError,
coordinator: SqliteCoordinatorError,
ownership: OpenClawStateOwnershipError,
"newer-schema": SqliteSchemaVersionError,
"jsonl-read-budget": SqliteJsonlReadBudgetExceededError,
"range-error": RangeError,
"syntax-error": SyntaxError,
"type-error": TypeError
};
function isMessageOnlyErrorIdentity(e) {
return typeof e.type === "string" && Object.hasOwn(MESSAGE_ONLY_ERRORS, 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 SessionGoalOperationError) 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) {
const 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 SessionMetadataUnavailableError) return {
type: "session-metadata",
reason: e.reason,
missingTables: [...e.missingTables]
};
if (e instanceof GatewayStateOwnerContentionError) 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 OpenClawStateOwnershipMetadataError) return {
type: "ownership-metadata",
databasePath: e.databasePath
};
if (e instanceof OpenClawStateExternalOwnershipError) 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 OpenClawAgentDatabaseMediaMigrationRequiredError) return {
type: "agent-media-migration",
pathname: e.pathname,
schemaVersion: e.schemaVersion
};
for (const [t, n] of Object.entries(MESSAGE_ONLY_ERRORS)) if (e instanceof n) return { type: t };
if (e instanceof StartupMaintenanceRequiredError) return {
type: "maintenance",
kind: e.kind
};
return { type: e instanceof AggregateError ? "aggregate" : "error" };
}
function createError(e) {
if (isMessageOnlyErrorIdentity(e)) {
const t = MESSAGE_ONLY_ERRORS[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 SessionGoalOperationError(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 SessionMetadataUnavailableError(e.reason, void 0, e.missingTables);
case "error": return new Error(e.message);
case "mcp-oauth-corruption": return new McpOAuthStoreCorruptionError("", "");
case "aggregate": return new AggregateError([], e.message);
case "auth-profile-store-unreadable": return new AuthProfileStoreUnreadableError(e.databasePath);
case "state-owner-contention": return new GatewayStateOwnerContentionError(e.databasePath);
case "ownership-metadata": return new OpenClawStateOwnershipMetadataError(e.databasePath, "");
case "external-ownership": return new OpenClawStateExternalOwnershipError(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 StartupMaintenanceRequiredError(e.kind, e.message);
case "state-migration": return new OpenClawStateDatabaseSchemaMigrationRequiredError(e.kind, e.pathname);
}
return new OpenClawAgentDatabaseMediaMigrationRequiredError(e.pathname, e.schemaVersion);
}
//#endregion
//#region src/state/openclaw-state-worker-error.ts
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;
const n = [];
const r = [];
const i = /* @__PURE__ */ new Map();
let a = false;
const encodeValue = (e) => {
if (!(e instanceof Error)) return isScalar(e) ? { value: e } : { undefined: true };
const t = i.get(e);
if (t !== void 0) return { ref: t };
const n = r.length;
i.set(e, n);
r.push(e);
return { ref: n };
};
try {
encodeValue(e);
for (const e of r) {
const { name: t, message: r } = e;
if (typeof t !== "string" || typeof r !== "string") return;
const i = identifyError(e);
if (Object.entries(i).some(([e, t]) => {
return (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;
const o = isSqliteNativeOpenFailure(e);
const s = hasSqliteWorkerErrorCode(e, "outcome-unknown") || hasSqliteWorkerErrorCode(e, "unavailable");
const c = readOpenClawStateDatabaseFailurePath(e);
const l = "errcode" in e ? e.errcode : void 0;
a ||= s || c !== void 0 || o || isNativeErrorCode(l) || isSqliteLockError(e) || e instanceof OpenClawQuarantineReadCleanupError || i.type !== "error" && i.type !== "aggregate";
const u = "code" in e ? e.code : void 0;
const d = "errno" in e ? e.errno : void 0;
n.push({
...i,
name: s ? "SqliteWorkerError" : t === "SqliteWorkerError" && isWorkerOutcomeCode(u) ? "Error" : t,
message: r,
...typeof u === "string" || typeof u === "number" && Number.isFinite(u) ? { code: u } : {},
...isNativeErrorCode(l) ? { errcode: l } : {},
...typeof d === "number" && Number.isInteger(d) ? { errno: d } : {},
...o ? { nativeOpen: true } : {},
...c === void 0 ? {} : { stateDatabasePath: c },
..."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 === true ? {
version: 1,
root: 0,
nodes: n
} : void 0;
} catch {
return;
}
}
function decodeErrorGraph(e, t) {
try {
if (e.version !== 1) return;
const n = e.nodes;
if (t.includeOrdinary !== true && !n.some((e) => e.stateDatabasePath !== void 0 || e.nativeOpen === true || e.name === "SqliteWorkerError" && isWorkerOutcomeCode(e.code) || isNativeErrorCode(e.errcode) || isSqliteLockError(e) || e.type === "aggregate" && e.name === "OpenClawQuarantineReadCleanupError" || e.type !== "error" && e.type !== "aggregate")) return;
const r = n.map((e) => {
if (e.name === "SqliteWorkerError" && isWorkerOutcomeCode(e.code)) {
const t = new SqliteWorkerError(e.message, e.code);
return e.type === "error" ? t : retainSqliteWorkerErrorCode(createError(e), t);
}
return createError(e);
});
const decodeValue = (e) => "ref" in e ? r[e.ref] : "value" in e ? e.value : void 0;
for (const [e, t] of n.entries()) {
const n = r[e];
n.name = t.name;
n.message = t.message;
if (t.nativeOpen) markSqliteNativeOpenFailure(n);
if (t.stateDatabasePath !== void 0) markOpenClawStateDatabaseFailure(n, t.stateDatabasePath);
for (const [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: true,
writable: true
});
if (n instanceof AggregateError) n.errors = (t.errors ?? []).map(decodeValue);
}
return {
errors: r,
root: e.root
};
} catch {
return;
}
}
const retainedPayloads = resolveGlobalSingleton(Symbol.for("openclaw.sharedStateWorkerErrorPayloads"), () => /* @__PURE__ */ new WeakMap());
/** Keep the closed wire graph until the receiving caller hydrates it. */
function retainOpenClawStateWorkerErrorPayload(e, t) {
if (t) retainedPayloads.set(e, t);
}
function hydrateOpenClawStateWorkerError(e, t = {}) {
if (!(e instanceof Error)) return e;
const n = /* @__PURE__ */ new Map();
const r = [{
error: e,
finish: false
}];
const replace = (e) => e instanceof Error ? n.get(e) ?? e : e;
while (r.length > 0) {
const e = r.pop();
const { error: i } = e;
if (!e.finish) {
if (n.has(i)) continue;
n.set(i, i);
const e = retainedPayloads.get(i);
const a = e === void 0 ? void 0 : decodeErrorGraph(e, t);
if (a) {
n.set(i, a.errors[a.root]);
continue;
}
r.push({
error: i,
finish: true
});
if (i.cause instanceof Error) r.push({
error: i.cause,
finish: false
});
if (i instanceof AggregateError) {
for (const e of i.errors) if (e instanceof Error) r.push({
error: e,
finish: false
});
}
continue;
}
const a = replace(i.cause);
const o = i instanceof AggregateError ? i.errors : void 0;
const s = o?.map(replace);
if (a === i.cause && (!s || s.every((e, t) => e === o?.[t]))) continue;
const c = i instanceof AggregateError ? new AggregateError([], i.message) : new Error(i.message);
Object.setPrototypeOf(c, Object.getPrototypeOf(i));
const l = Object.getOwnPropertyDescriptors(i);
if ("cause" in i) l.cause = {
configurable: true,
writable: true,
...l.cause,
value: a
};
if (s) l.errors = {
configurable: true,
writable: true,
...l.errors,
value: s
};
Object.defineProperties(c, l);
n.set(i, c);
}
return n.get(e);
}
//#endregion
export { SecretStoreValidationError as a, OpenClawQuarantineReadCleanupError as c, SECRET_STORE_VALUE_MAX_BYTES as i, hydrateOpenClawStateWorkerError as n, findOpenClawStateDatabaseFailure as o, retainOpenClawStateWorkerErrorPayload as r, markOpenClawStateDatabaseFailure as s, encodeOpenClawStateWorkerError as t };