openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
5 lines • 9.91 kB
JavaScript
import{l as normalizeOptionalString}from"../../string-coerce-CpTFcSwY.mjs";import{a as asOptionalRecord}from"../../record-coerce-BTbqdJ3-.mjs";import{t as findCrabboxBinary}from"../../crabbox-binary-Bo1EgOsf.mjs";import"../../string-coerce-runtime-BYDH9Quw.mjs";import{i as findManagedCrabboxBinary,o as probeCrabboxVersion,r as ensureManagedCrabboxBinary,s as resolveManagedCrabboxBinaryPath,t as CRABBOX_MIN_VERSION}from"../../crabbox-managed-binary-D_OJtHhk.mjs";import{c as isReservedCrabboxSetupSecretName,h as parseCrabboxSetupSecrets,r as CRABBOX_WORKER_PROVIDER_ID,x as resolveOpenClawRoot}from"../../crabbox-worker-profile-5DxAeX_h.mjs";import{f as projectCrabboxWarmImage,n as admitCrabboxWarmImageProfile}from"../../crabbox-worker-warm-image-store-Bkmwt6Qm.mjs";import{a as crabboxWarmImageRecoveryHint,i as crabboxWarmImageHoldingLeaseIds,t as CRABBOX_WARM_IMAGE_WAIT_HINT}from"../../crabbox-worker-warm-image-records-B8HI4d8j.mjs";import{fileURLToPath}from"node:url";import path from"node:path";
//!extensions/crabbox/src/doctor.ts
const CRABBOX_CLOUD_WORKER_PROFILE_CHECK_ID=`crabbox/cloud-worker-profiles`;const CRABBOX_SETUP_SECRETS_CHECK_ID=`crabbox/setup-secrets`;const CRABBOX_WARM_IMAGES_CHECK_ID=`crabbox/warm-images`;function createCrabboxCloudWorkerProfileCheck(e){return{id:CRABBOX_CLOUD_WORKER_PROFILE_CHECK_ID,kind:`plugin`,description:`Verify configured Crabbox cloud worker and sandbox binaries before use.`,source:`crabbox`,async detect(t){const n=Object.entries(t.cfg.cloudWorkers?.profiles??{}).filter(([,e])=>e.provider.trim().toLowerCase()===CRABBOX_WORKER_PROVIDER_ID).map(([e,t])=>({id:e,label:`Cloud worker profile "${e}"`,settings:asOptionalRecord(t.settings),ocPath:`cloudWorkers.profiles.${e}.settings.binary`}));const r=asOptionalRecord(asOptionalRecord(t.cfg.plugins?.entries?.crabbox?.config)?.sandbox);if(r)n.push({id:`sandbox`,label:`Crabbox sandbox`,settings:r,ocPath:`plugins.entries.crabbox.config.sandbox.binary`});if(n.length===0)return[];const i=/* @__PURE__ */ new Map;const probe=e=>{let t=i.get(e);if(!t){t=probeCrabboxVersion(e);i.set(e,t)}return t};let a;const o=[];for(const r of n){const n=normalizeOptionalString(r.settings?.binary);const i=findCrabboxBinary({...n?{explicit:n}:{},openclawRoot:e,pathEnv:t.env?.PATH??process.env.PATH});const s=i?await probe(i):void 0;if(s?.status===`supported`)continue;try{a??=findManagedCrabboxBinary({env:t.env});if(await a)continue}catch(e){o.push({checkId:CRABBOX_CLOUD_WORKER_PROFILE_CHECK_ID,severity:`warning`,source:`crabbox`,target:r.id,message:e instanceof Error?e.message:`Crabbox host is unsupported`});continue}const c=!s?`has no executable Crabbox binary`:s.status===`outdated`?`uses outdated Crabbox ${s.version}`:`could not determine its Crabbox version: ${s.reason}`;o.push({checkId:CRABBOX_CLOUD_WORKER_PROFILE_CHECK_ID,severity:`warning`,source:`crabbox`,message:`${r.label} ${c}. OpenClaw will install its managed Crabbox before use.`,...i??n?{path:i??n}:{},ocPath:r.ocPath,target:r.id,requirement:`Crabbox ${CRABBOX_MIN_VERSION} or newer`,fixHint:`Run \`openclaw doctor --fix\` to install the managed Crabbox now, or provision Crabbox ${CRABBOX_MIN_VERSION} or newer using \`${r.ocPath}\`. The existing executable and configuration are preserved.`})}return o},async repair(e,t){if(t.length===0||e.dryRun)return{status:`skipped`,changes:[]};try{const{binary:t}=await ensureManagedCrabboxBinary({binary:resolveManagedCrabboxBinaryPath(e.env),env:e.env});return{status:`repaired`,changes:[`Installed managed Crabbox at ${t}`],effects:[{kind:`package`,action:`install`,target:t}]}}catch(e){return{status:`failed`,changes:[],warnings:[e instanceof Error?e.message:`Managed Crabbox installation failed`]}}}}}function createCrabboxSetupSecretsCheck(e){const t=`Create or repair protected entries with explicit allowed hosts using openclaw secrets, then run openclaw doctor --fix. Store values and destination bindings are never inferred or overwritten.`;const inspect=async n=>{const r=[];const i=[];if(!Object.values(n.cfg.cloudWorkers?.profiles??{}).some(e=>e.provider.trim().toLowerCase()===`crabbox`&&asOptionalRecord(e.settings)?.setupEnv!==void 0))return{config:n.cfg,changes:r,findings:i};const a=structuredClone(n.cfg);for(const[o,s]of Object.entries(a.cloudWorkers?.profiles??{})){const a=asOptionalRecord(s.settings);if(s.provider.trim().toLowerCase()!==`crabbox`||!a||a.setupEnv===void 0)continue;const c=`cloudWorkers.profiles.${o}.settings.setupEnv`;let l;let u=t;const d=a.setupEnv;if(!Array.isArray(d)||d.length>16||!d.every(e=>typeof e===`string`&&/^[A-Za-z_][A-Za-z0-9_]*$/u.test(e))||new Set(d).size!==d.length)l=`legacy setupEnv is not a bounded list of distinct environment names`;else if(d.some(isReservedCrabboxSetupSecretName)){l=`legacy setupEnv contains reserved environment names: ${d.filter(isReservedCrabboxSetupSecretName).join(`, `)}`;u=`Manually map reserved names under non-reserved setupSecrets keys and update the setup command and repository setup files to use those keys. Existing protected store IDs and destination bindings can stay unchanged. Remove setupEnv after completing that manual migration; Doctor does not rewrite setup commands.`}else{const t=d.length?await e.inspectSetupSecrets(d,n.env):[];const i=t.filter(({status:e})=>e!==`ready`);if(t.length!==d.length||i.length)l=i.length?i.map(({name:e,status:t})=>`${e}: ${t}`).join(`, `):`secret-store inspection is incomplete`;else try{const e=parseCrabboxSetupSecrets(a.setupSecrets)??{};const t=n.cfg.secrets?.defaults?.store??`default`;const i={...e};for(const n of d){const r=e[n];if(r&&(r.provider!==t||r.id!==n))throw new Error(`setupSecrets mapping ${n} conflicts with its same-name store entry`);i[n]={source:`store`,provider:t,id:n}}a.setupSecrets=parseCrabboxSetupSecrets(i);delete a.setupEnv;r.push(`Migrated ${c} to setupSecrets using existing protected, destination-bound store entries.`)}catch(e){l=e instanceof Error?e.message:`setupSecrets mapping requires repair`}}i.push({checkId:CRABBOX_SETUP_SECRETS_CHECK_ID,severity:`warning`,source:`crabbox`,target:o,ocPath:c,message:`Crabbox profile ${o} uses retired plaintext setupEnv${l?` and needs repair (${l})`:`; protected store entries are ready to migrate`}.`,fixHint:u})}return{config:a,changes:r,findings:i}};return{id:CRABBOX_SETUP_SECRETS_CHECK_ID,kind:`plugin`,description:`Migrate retired setup environment forwarding to protected setup secrets.`,source:`crabbox`,async detect(e){return(await inspect(e)).findings},async repair(e){const t=await inspect(e);if(e.dryRun)return{status:`skipped`,changes:[],reason:`Run openclaw doctor --fix to persist setup secret migration.`};return{status:t.changes.length?`repaired`:`skipped`,config:t.changes.length?t.config:e.cfg,changes:t.changes,warnings:t.findings.filter(({target:e})=>{return asOptionalRecord(t.config.cloudWorkers?.profiles?.[e??``]?.settings)?.setupEnv!==void 0}).map(({message:e,fixHint:t})=>`${e} ${t}`)}}}}function registerCrabboxWorkerProviderDoctorChecks(e){if(!e.getHealthCheck(CRABBOX_SETUP_SECRETS_CHECK_ID))e.registerHealthCheck(createCrabboxSetupSecretsCheck(e));if(!e.getHealthCheck(`crabbox/cloud-worker-profiles`))e.registerHealthCheck(createCrabboxCloudWorkerProfileCheck(e.openclawRoot));if(!e.getHealthCheck(CRABBOX_WARM_IMAGES_CHECK_ID))e.registerHealthCheck({id:CRABBOX_WARM_IMAGES_CHECK_ID,kind:`plugin`,description:`Report paused Crabbox warm-image captures and retained cleanup obligations.`,source:`crabbox`,async detect(t){const n=[];const r=await e.listPluginStateEntries({namespace:`warm-images`,maxEntries:128,overflowPolicy:`reject-new`,...t.env?{env:t.env}:{}});for(const{key:e,value:t}of r){const r=projectCrabboxWarmImage(e,admitCrabboxWarmImageProfile(t));const i=[r.profileId,r.backend,r.machineClass,r.os,r.projectLabel].filter(Boolean);const a=i.length?` (${i.join(` · `)})`:``;const o={checkId:CRABBOX_WARM_IMAGES_CHECK_ID,severity:`warning`,source:`crabbox`,target:r.profileKey};if(r.captureUnsupported)n.push({...o,severity:`info`,message:`Warm-image native capture${a} is unsupported: ${r.captureUnsupported.message}`,fixHint:"Workers use an existing compatible snapshot when one is available and otherwise provision cold; capture attempts are skipped until `warmImages.refreshAfter` has elapsed since the refusal. Set `settings.warmImage: false` on the profile to stop capture attempts, or use a Crabbox configuration that supports native checkpoints."});if(r.capture){const e=r.capture.phase===`uncertain`;n.push({...o,severity:e||r.capture.stale?`warning`:`info`,message:e?`Warm-image capture ${r.capture.selector}${a} is paused; its provider outcome requires manual reconciliation.`:r.capture.stale?`Warm-image capture ${r.capture.selector}${a} is taking longer than usual.`:`Warm-image capture ${r.capture.selector}${a} is in progress.`,fixHint:e?crabboxWarmImageRecoveryHint(r.capture.selector,r.capture.checkpointIds):CRABBOX_WARM_IMAGE_WAIT_HINT})}if(r.retirement){const e=crabboxWarmImageHoldingLeaseIds(r,r.retirement.checkpointId);const t=e.length>0?` Held by allocation leases: ${e.join(`, `).slice(0,1024)}.`:``;n.push({...o,message:`Warm-image checkpoint ${r.retirement.checkpointId}${a} is still awaiting deletion.${t}`,fixHint:"Cleanup retries during periodic maintenance or the next warm-image capture or worker teardown. Confirmed-gone allocation leases are released automatically; live or unconfirmed leases keep their holds. Inspect `openclaw crabbox warm-images --json` and the Gateway log for holding leases or provider deletion errors if it remains pending."})}}return n}})}
//!extensions/crabbox/doctor-health-api.ts
const CRABBOX_PLUGIN_ROOT=path.dirname(fileURLToPath(import.meta.url));function registerWorkerProviderDoctorChecks(e){registerCrabboxWorkerProviderDoctorChecks({...e,openclawRoot:resolveOpenClawRoot(CRABBOX_PLUGIN_ROOT)})}export{CRABBOX_CLOUD_WORKER_PROFILE_CHECK_ID,registerWorkerProviderDoctorChecks};