UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 8.65 kB
import{i as collectNestedErrorCandidates}from"./error-coercion-DlKnt6w-.mjs";import{r as isErrno}from"./errno-DUBt6SQQ.mjs";import{t as formatErrorMessage}from"./errors-D37BJTfI.mjs";import{t as formatCliCommand}from"./command-format-D7KhNLP0.mjs";import{n as StartupMaintenanceRequiredError}from"./startup-maintenance-required-Cz4Y_ofl.mjs";import{r as GatewayLockNamespaceError}from"./gateway-lock-payload-CBa45_pI.mjs";import"./gateway-state-owner-D_klysuh.mjs";import{s as resolveOpenClawStateSqlitePath}from"./openclaw-state-db.paths-CbgXfEg1.mjs";import{t as GatewayStateOwnerContentionError}from"./gateway-state-owner-errors-Cke3Bshm.mjs";import{a as readStateLeaseProcessOwnerStatus}from"./state-lease-process-owner-B_MHpRIt.mjs";import{n as executeExistingOpenClawStateRead}from"./openclaw-state-db-readonly-Cd5_cxBs.mjs";import{a as withArtifactPreservingStateReads}from"./artifact-preserving-state-reads-CWuQPqxe.mjs";import{a as hasCommandProcessCleanupError}from"./exec-result-TD4w1Z1i.mjs";import{t as UpdateSchemaRefusalError}from"./openclaw-update-schema-refusal-CZZooTUg.mjs";import{o as UpdateDoctorError,t as DoctorMaintenanceRefusalError}from"./update-doctor-result-B09W3zwf.mjs";import{m as hasGatewayServiceStopUnsafeError}from"./service-inspection-error-D006EyWC.mjs";import{t as ConfigWritePostCommitError}from"./io.write-errors-CQyW8lY6.mjs";import{t as DoctorUnreadableStateDatabaseError}from"./state-repair-message-CmSHWF4H.mjs";import{t as ExecApprovalsMigrationRequiredError}from"./exec-approvals-migration-gate-Djh8ykMZ.mjs";import{n as GatewayLockError}from"./gateway-lock-CQoO1usb.mjs";import{t as DoctorStateMigrationRefusalError}from"./state-migrations.messages-BurXA9TV.mjs";import{t as formatGatewayLockFailure}from"./gateway-lock-diagnostics-_MClHYaH.mjs"; //!src/commands/doctor-maintenance-inspection.ts async function readOfflineAppOwnedDoctorInspection(e,t){const{GatewayServiceUpdateOwnershipError:n}=await import(`./update-command-service-plan-C4uLVD3F.mjs`);if(hasCommandProcessCleanupError(e)||!(e instanceof n)||!e.failureFacts.some(e=>e.check===`managed-service`&&e.code===`service-mutation-refused`))return;const{readGatewayServiceState:r,resolveGatewayService:i}=await import(`./service-flxrucEo.mjs`);const{assertDoctorServiceSelection:a}=await import(`./doctor-service-repair-policy-CMQ1nY67.mjs`);const o=await r(i(),{env:t,requireEffective:true,validateEnvBeforeStatusRead:e=>a(t,e)});if(!o.command)return;const{summarizeGatewayServiceLayout:s}=await import(`./service-layout-DqzESB0i.mjs`);const{readInstallOwner:c,formatInstallOwnerMessage:l}=await import(`./install-owner-DDsIt1aS.mjs`);const u=await c((await s(o.command))?.packageRootReal??null);const{isManagedGatewayServiceOffline:d}=await import(`./update-command-service-publication-lGFhCtGO.mjs`);if(!u||!await d(o))return;const f=`${l(u)} Doctor can repair offline state; Gateway service installation and activation remain with the app.`;return{stopped:false,inspected:true,runtimeInspected:true,running:false,offline:true,serviceEnv:o.env,serviceMutationAllowed:false,serviceUpdateVerdict:{kind:`unavailable`,message:f},serviceMutationSkipMessage:f}}async function readDoctorGatewayOwnerLease(e,t){const n={env:{...e},path:resolveOpenClawStateSqlitePath(e)};const r=await withArtifactPreservingStateReads(()=>executeExistingOpenClawStateRead(n,{type:`gatewayOwnerLease.read`,schemaMaintenance:true},{current:true,signal:t}));t.throwIfAborted();if(!r)return;return r.lease?{...r.lease,state:readStateLeaseProcessOwnerStatus(r.lease,r.lease.heartbeatAt)}:void 0}function createDoctorMaintenanceRefusal(e,t,n){const r=e instanceof GatewayLockError&&e.cause instanceof GatewayLockNamespaceError&&e.cause.legacyLock;return e instanceof DoctorMaintenanceRefusalError?e:new DoctorMaintenanceRefusalError(`Doctor could not enter maintenance. ${e instanceof GatewayLockError?formatGatewayLockFailure(e):String(e)}${n||r||hasGatewayServiceStopUnsafeError(e)?``:` Stop the Gateway service and other OpenClaw processes using this state, then run ${formatCliCommand(`openclaw doctor --fix`,t)} from an independent shell.`}`,classifyDoctorMaintenanceRefusal(e),{cause:e,...e instanceof UpdateDoctorError?{failureFacts:e.failureFacts}:{}})}function classifyDoctorMaintenanceRefusal(e){const t=collectNestedErrorCandidates(e);const n=t.find(e=>e instanceof DoctorMaintenanceRefusalError&&e.refusal.kind===`data-at-risk`);if(n)return n.refusal;if(hasGatewayServiceStopUnsafeError(e)||hasCommandProcessCleanupError(e))return{kind:`data-at-risk`,reason:`active-mutation`};if(t.some(e=>e instanceof DoctorUnreadableStateDatabaseError))return{kind:`data-at-risk`,reason:`unreadable-state`};if(t.some(e=>e instanceof DoctorStateMigrationRefusalError||e instanceof StartupMaintenanceRequiredError||e instanceof ExecApprovalsMigrationRequiredError||e instanceof UpdateSchemaRefusalError))return{kind:`data-at-risk`,reason:`incomplete-migration`};if(t.some(e=>e instanceof GatewayLockError||e instanceof ConfigWritePostCommitError&&e.rollbackStatus!==`restored`))return{kind:`data-at-risk`,reason:`gateway-state-unverified`};return{kind:`deferred`,reason:t.some(e=>e instanceof GatewayStateOwnerContentionError)?`coordinator-contention`:`admission-unavailable`}}async function reportDoctorReadOnlyFilesystemError(e,t){const n=collectNestedErrorCandidates(e).find(e=>isErrno(e)&&e.code===`EROFS`);if(!n)return;const quote=e=>JSON.stringify(e).replace(/[\p{Cc}\p{Bidi_Control}\u2028\u2029]/gu,e=>`\\u${e.charCodeAt(0).toString(16).padStart(4,`0`)}`);const r=`operation`in n&&typeof n.operation===`string`?n.operation:typeof n.syscall===`string`?n.syscall:`write`;const i=typeof n.path===`string`?quote(n.path):`an unreported target path`;(t??(await import(`./runtime-BQCaxGKj.mjs`)).defaultRuntime).error(`Doctor encountered a read-only filesystem (EROFS): ${quote(r)} at ${i}.\nProvide a writable mount covering the affected path; changing ownership or file modes alone cannot fix a read-only mount. Docker writable-storage layout: https://docs.openclaw.ai/install/docker#read-only-container-root`)}async function assertDoctorMaintenanceReady(e,t,n,r){let i=false;let a=[];const{assertSessionStoreMigrationComplete:o}=await import(`./startup-migration-CqWF21TG.mjs`);o({cfg:e,env:t,operation:`doctor`});const{assertOpenClawDatabasesReady:s}=await import(`./openclaw-database-preflight-BW_fgol_.mjs`);const{resolveConfiguredAgentDatabaseTargets:c}=await import(`./targets-C8LX-ajf.mjs`);try{await s({env:t,config:e,operation:`doctor`,onDeferredSchemaPublication:e=>{i=true;n(e.message)},onVerified:e=>{a=e.agentRefusals?.flatMap(e=>e.paths)??[]},configuredAgentDatabaseTargets:c(e,{env:t})})}catch(e){throw new DoctorMaintenanceRefusalError(formatErrorMessage(e),{kind:`data-at-risk`,reason:`incomplete-migration`},{cause:e})}const{assertConfiguredWorkspaceStateReady:l}=await import(`./workspace-state-dirs-qJc0YeSZ.mjs`);await l({cfg:e,operation:`doctor`});if(!i&&r){const{completeDoctorMigrationBackups:e}=await import(`./doctor-migration-backup-artifacts-B1HEXTfr.mjs`);try{e(t,r.filter(e=>!a.some(t=>t===e.path||t===e.realPath)).map(e=>e.path))}catch(e){n(`Migration backups remain protected; completion registration failed: ${String(e)}`)}}return{schemaPublicationDeferred:i}}function assertDoctorMaintenanceInspection(e,t){const n=e.serviceUpdateVerdict?.kind;if(!e.blockMessage&&(n===`unavailable`||e.inspected&&(n===`owned`||n===`absent`||e.offline===true)))return;const r=e.blockMessage??e.serviceMutationSkipMessage??`Gateway service ownership or shutdown could not be verified. Run ${formatCliCommand(`openclaw gateway status --deep`,t)} and stop it through its service owner before retrying.`;const i=n===`foreign`?`Run ${formatCliCommand(`openclaw gateway status --deep`,t)} to find the Gateway installation. If an operator-owned launcher override points there, update or remove that override; reinstalling alone will not fix it. Inspect systemd overrides with systemctl cat (--user for user services). The service was left unchanged.`:`Stop the Gateway service and other OpenClaw processes using this state, then run ${formatCliCommand(`openclaw doctor --fix`,t)} from an independent shell.`;throw new DoctorMaintenanceRefusalError(`Doctor could not enter maintenance. Error: ${r} ${i}`,{kind:`data-at-risk`,reason:`gateway-state-unverified`},{failureFacts:e.blockFailureFacts})}export{readDoctorGatewayOwnerLease as a,createDoctorMaintenanceRefusal as i,assertDoctorMaintenanceReady as n,readOfflineAppOwnedDoctorInspection as o,classifyDoctorMaintenanceRefusal as r,reportDoctorReadOnlyFilesystemError as s,assertDoctorMaintenanceInspection as t};