UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

67 lines (66 loc) • 3.67 kB
import { c as resolveUserPath } from "./home-dir-EKmgmdPG.mjs"; import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs"; import { r as isPathInside } from "./path-guards-TIjxtj6H.mjs"; import "./utils-C8YECn2Q.mjs"; import { a as getPluginCache } from "./plugin-cache-B_eRuqTM.mjs"; import { r as resolveOpenClawPackageRootSync } from "./openclaw-root-C-ayo09z.mjs"; import { a as pluginCacheRealpathSync, l as readPluginCacheJsonFile, r as pluginCacheExistsSync } from "./plugin-cache-files-e1aGp2KM.mjs"; import { a as isSourceCheckoutRoot, i as isPluginInPackageBundledRoots } from "./bundled-dir-BKvdAqkP.mjs"; import fs from "node:fs"; import path from "node:path"; //#region src/plugins/dev-source-root.ts /** Env var that points bundled-plugin lookup at an OpenClaw source checkout. */ const OPENCLAW_DEV_SOURCE_ROOT_ENV = "OPENCLAW_DEV_SOURCE_ROOT"; /** Packaging records this only for same-commit plugins in a non-release image. */ function readStagedOfficialPluginIds(e) { const t = readPluginCacheJsonFile(path.join(e, "dist", "build-info.json")); if (!t.ok || !isRecord(t.value)) return []; const { commit: n, stagedOfficialPlugins: r } = t.value; return typeof n === "string" && /^[0-9a-f]{40}$/.test(n) && isRecord(r) && r.commit === n && Array.isArray(r.pluginIds) ? r.pluginIds : []; } function readPackageName(e) { try { const t = JSON.parse(fs.readFileSync(e, "utf-8")); return typeof t.name === "string" ? t.name : null; } catch { return null; } } /** Resolves and validates the configured OpenClaw development source root. */ function resolveOpenClawDevSourceRoot(e = process.env) { const t = e[OPENCLAW_DEV_SOURCE_ROOT_ENV]?.trim(); if (!t) return null; const n = resolveUserPath(t, e); const r = getPluginCache().sdk.devSourceRoots; if (r.has(n)) return r.get(n) ?? null; const i = pluginCacheRealpathSync(n); const a = i && readPackageName(path.join(i, "package.json")) === "openclaw" && pluginCacheExistsSync(path.join(i, "src")) && pluginCacheExistsSync(path.join(i, "extensions")) ? i : null; r.set(n, a); return a; } /** Source builds own their bundled SDK consumers even without an explicit development selector. */ function resolveBundledPluginSourceRoot(e = process.env) { const t = resolveOpenClawDevSourceRoot(e); if (t) return t; const n = resolveOpenClawPackageRootSync({ moduleUrl: import.meta.url }); return n && (isSourceCheckoutRoot(n) || readStagedOfficialPluginIds(n).length > 0) ? n : null; } function formatSourceBundledPluginNotice(e) { return `Kept bundled plugin "${e}" from the OpenClaw source build; the registry artifact has no matching host SDK build identity. Matching version strings do not establish SDK compatibility.`; } /** Prioritizes already-bundled candidates; the selector itself never grants provenance. */ function isBundledPluginInsideDevSourceRoot(e) { const t = resolveBundledPluginSourceRoot(e.env); if (!t) return false; if (!isPluginInPackageBundledRoots({ packageRoot: t, rootDir: resolveUserPath(e.rootDir, e.env) })) return false; if (resolveOpenClawDevSourceRoot(e.env)) return true; const n = pluginCacheRealpathSync(t); const r = pluginCacheRealpathSync(resolveUserPath(e.rootDir, e.env)); if (!isSourceCheckoutRoot(t)) return Boolean(n && r && readStagedOfficialPluginIds(n).includes(path.basename(r)) && path.dirname(r) === path.join(n, "dist", "extensions")); return Boolean(n && r && ["dist", "dist-runtime"].some((e) => isPathInside(path.join(n, e, "extensions"), r))); } //#endregion export { resolveOpenClawDevSourceRoot as i, isBundledPluginInsideDevSourceRoot as n, resolveBundledPluginSourceRoot as r, formatSourceBundledPluginNotice as t };