UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

136 lines (135 loc) • 5.47 kB
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs"; import { p as asPositiveSafeInteger } from "./number-coercion-D6u-4YD8.mjs"; import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs"; import { n as coerceErrorMessage } from "./error-coercion-hDrHOSGy.mjs"; import { t as WorkerProviderError } from "./capability-provider.types-qOxhG-PT.mjs"; import "./string-coerce-runtime-BwAZZDf5.mjs"; import "./error-runtime-BM740gJj.mjs"; import "./plugin-entry-CiJdaHtx.mjs"; import { c as runCrabboxCommand, f as runCrabboxProcess, n as crabboxCommandOutput, s as parseCrabboxJson } from "./crabbox-worker-command-C6ki_dj6.mjs"; import { a as CRABBOX_MACHINE_CATALOG_TIMEOUT_MS, t as CRABBOX_CONFIG_TIMEOUT_MS } from "./crabbox-worker-timeouts-pTo1LSUy.mjs"; import { c as listCrabboxMachineOptions, n as CRABBOX_OS_LABELS, p as parseCrabboxProfile, s as isCrabboxSetupTargetCompatible, t as CRABBOX_ENROLLABLE_TARGETS } from "./crabbox-worker-profile-Ckeez-8x.mjs"; //#region 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) : []; return [[t, { 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 } : {} }]; }); }) }]]; })); } 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 }; }); } }; } //#endregion //#region 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"); } //#endregion export { createCrabboxMachineOptionsResolver as a, createCrabboxMachineCatalogResolver as i, assertHetznerDesktopHasManagedCoordinator as n, loadCrabboxConfigShow as r, assertAwsWorkerHasNoInstanceProfile as t };