UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

5 lines • 4.79 kB
import{l as normalizeOptionalString}from"./string-coerce-CpTFcSwY.mjs";import{p as asPositiveSafeInteger}from"./number-coercion-B3CfI447.mjs";import{n as coerceErrorMessage}from"./error-coercion-DlKnt6w-.mjs";import{l as isRecord}from"./record-coerce-BTbqdJ3-.mjs";import{t as WorkerProviderError}from"./capability-provider.types-Bir_t_Rt.mjs";import"./string-coerce-runtime-BYDH9Quw.mjs";import"./error-runtime-DW-sj0iq.mjs";import"./plugin-entry-DhKiQ4Uu.mjs";import{c as runCrabboxCommand,h as runCrabboxProcess,n as crabboxCommandOutput,s as parseCrabboxJson}from"./crabbox-worker-command-DPZFykVB.mjs";import{a as CRABBOX_MACHINE_CATALOG_TIMEOUT_MS,t as CRABBOX_CONFIG_TIMEOUT_MS}from"./crabbox-worker-timeouts-C91C79jR.mjs";import{l as listCrabboxMachineOptions,m as parseCrabboxProfile,n as CRABBOX_OS_LABELS,s as isCrabboxSetupTargetCompatible,t as CRABBOX_ENROLLABLE_TARGETS}from"./crabbox-worker-profile-5DxAeX_h.mjs"; //!extensions/crabbox/src/crabbox-worker-machine-options.ts function parseCrabboxMachineShapes(e){const t=JSON.parse(e);if(!Array.isArray(t))throw new Error(`Crabbox providers returned invalid JSON`);return new Map(t.flatMap(e=>{if(!isRecord(e))return[];const t=normalizeOptionalString(e.provider)?.toLowerCase();if(!t)return[];const n=Array.isArray(e.targets)?e.targets:[];const r=CRABBOX_ENROLLABLE_TARGETS.filter(e=>n.includes(e));const i=isRecord(e.classCatalog)&&e.classCatalog.disposition===`mapped`&&Array.isArray(e.classCatalog.profiles)?e.classCatalog.profiles.filter(isRecord):[];const a={operatingSystems:r,machines:r.flatMap(e=>{const[t,n]=e.split(`/`);const r=i.filter(e=>e.target===t&&(n===void 0||e.windowsMode===n));const a=r.some(e=>e.architecture===`amd64`);return r.flatMap(t=>{if(a&&t.architecture!==`amd64`||!isRecord(t.primary))return[];const n=normalizeOptionalString(t.class);if(!n)return[];const r=asPositiveSafeInteger(t.primary.vcpu);const i=t.primary.memory;const o=isRecord(i)&&(i.unit===`GB`||i.unit===`GiB`)?asPositiveSafeInteger(i.value):void 0;return[{class:n,os:e,...r?{cpu:r}:{},...o?{memoryGb:o}:{}}]})})};return[t,...Array.isArray(e.aliases)?e.aliases:[]].flatMap(e=>{const t=normalizeOptionalString(e)?.toLowerCase();return t?[[t,a]]:[]})}))}function createCrabboxMachineCatalogResolver(e){const t=/* @__PURE__ */ new Map;const loadMachineShapes=async e=>{const t=await runCrabboxProcess([e,`providers`,`--json`],{maxOutputBytes:1048576,killProcessTree:true,timeoutMs:CRABBOX_MACHINE_CATALOG_TIMEOUT_MS});if(t.termination!==`exit`||t.code!==0)throw new Error(`Crabbox providers command failed (${t.termination}, code ${t.code})`);return parseCrabboxMachineShapes(t.stdout)};return async(n,r)=>{const i=await e.resolveBinary(r);let a=t.get(i);if(!a){a=loadMachineShapes(i).catch(n=>{t.delete(i);e.warn(`Crabbox machine shapes unavailable: ${coerceErrorMessage(n)}`);return/* @__PURE__ */ new Map});t.set(i,a)}return(await a).get(n)}}function createCrabboxMachineOptionsResolver(e){const t=createCrabboxMachineCatalogResolver(e);const resolveCatalog=async e=>{const n=parseCrabboxProfile(e);return{parsed:n,catalog:await t(n.provider,n.binary)}};return{async listMachineOptions(e){const{parsed:t,catalog:n}=await resolveCatalog(e);return listCrabboxMachineOptions(t.class,n?.machines.filter(({os:e})=>isCrabboxSetupTargetCompatible(t,e)))},async listOperatingSystems(e){const{parsed:t,catalog:n}=await resolveCatalog(e);return(n?.operatingSystems??[]).filter(e=>isCrabboxSetupTargetCompatible(t,e)).map(e=>{const n=CRABBOX_OS_LABELS[e];return e===t.target?{id:e,label:n,default:true}:{id:e,label:n}})}}} //!extensions/crabbox/src/crabbox-worker-preflight.ts async function loadCrabboxConfigShow(e){const t=await runCrabboxCommand({action:`config show`,args:[`config`,`show`,`--json`],binary:e.binary,signal:e.signal,timeoutMs:CRABBOX_CONFIG_TIMEOUT_MS});return parseCrabboxJson(crabboxCommandOutput(`config show`,t),`config show`)}async function assertAwsWorkerHasNoInstanceProfile(e){const t=await loadCrabboxConfigShow(e);const n=isRecord(t)&&isRecord(t.aws)?t.aws.instanceProfile:void 0;if(typeof n!==`string`)throw new WorkerProviderError(`Crabbox config show returned an invalid AWS instance profile`);if(normalizeOptionalString(n))throw new WorkerProviderError(`Crabbox AWS instance profile must be empty for cloud workers`)}async function assertHetznerDesktopHasManagedCoordinator(e){const t=await loadCrabboxConfigShow(e);const n=isRecord(t)?t:void 0;if(normalizeOptionalString(n?.coordinator)&&n?.brokerMode===`managed`)return;throw new Error(`Crabbox Hetzner desktop profiles require a managed coordinator`)}export{createCrabboxMachineOptionsResolver as a,createCrabboxMachineCatalogResolver as i,assertHetznerDesktopHasManagedCoordinator as n,loadCrabboxConfigShow as r,assertAwsWorkerHasNoInstanceProfile as t};