UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

99 lines (98 loc) • 3.95 kB
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs"; import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs"; import { n as discoverOpenClawPlugins } from "./discovery-DvJYrQFY.mjs"; import { i as getGatewayPluginMetadataSnapshot } from "./current-plugin-metadata-state-BmYo9Q7A.mjs"; import { r as loadPluginManifest } from "./manifest-Y5vPZPOf.mjs"; import { n as isBundledPluginInsideDevSourceRoot, r as resolveBundledPluginSourceRoot } from "./dev-source-root-HNpp2lb0.mjs"; import { t as loadPluginManifestRegistryCore } from "./manifest-registry-CuWv8ibc.mjs"; import path from "node:path"; //#region src/plugins/bundled-sources.ts /** Use loader precedence, including explicit paths, when deciding which registry installs are dormant. */ function resolveSourceCheckoutBundledPluginIds(e) { const t = e.env ?? process.env; if (!resolveBundledPluginSourceRoot(t)) return /* @__PURE__ */ new Set(); const n = e.bundledSources ?? resolveBundledPluginSources({ env: t }); const r = new Set([...n].filter(([, e]) => isBundledPluginInsideDevSourceRoot({ rootDir: e.localPath, env: t })).map(([e]) => e)); if (r.size === 0) return r; return new Set(loadPluginManifestRegistryCore({ ...e, env: t }).plugins.filter((e) => r.has(e.id) && e.origin === "bundled" && isBundledPluginInsideDevSourceRoot({ rootDir: e.rootDir, env: t })).map((e) => e.id)); } function findBundledPluginSourceInMap(e) { const t = e.lookup.value.trim(); if (!t) return; if (e.lookup.kind === "pluginId") return e.bundled.get(t); for (const n of e.bundled.values()) if (e.lookup.kind === "npmSpec" && n.npmSpec === t || e.lookup.kind === "localPath" && path.resolve(n.localPath) === path.resolve(t)) return n; } function resolveBundledPluginSources(e) { const t = getGatewayPluginMetadataSnapshot(); const n = t ? (t.bundledManifestRegistry?.plugins ?? []).map((e) => ({ candidate: e, manifest: e })) : discoverOpenClawPlugins({ workspaceDir: e.workspaceDir, env: e.env }).candidates.flatMap((e) => { if (e.origin !== "bundled") return []; const t = loadPluginManifest(e.rootDir, false); return t.ok ? [{ candidate: e, manifest: t.manifest }] : []; }); const r = /* @__PURE__ */ new Map(); for (const { candidate: e, manifest: t } of n) { const n = t.id; if (r.has(n)) continue; const i = normalizeOptionalString(e.packageManifest?.install?.npmSpec) || normalizeOptionalString(e.packageName) || void 0; const a = normalizeOptionalString(e.packageVersion) || normalizeOptionalString(t.version) || void 0; r.set(n, { pluginId: n, localPath: e.rootDir, npmSpec: i, version: a, ...t.contextEngineIds ? { contextEngineIds: t.contextEngineIds } : {}, ...isRecord(t.configSchema) ? { configSchema: t.configSchema } : {}, requiresConfig: pluginConfigSchemaHasRequiredFields(t.configSchema) }); } return r; } /** Projects bundled sources from the current generation's shared discovery facts. */ function getProcessBundledPluginSources() { return resolveBundledPluginSources({}); } function pluginConfigSchemaHasRequiredFields(e) { if (!isRecord(e)) return false; const t = e.required; return Array.isArray(t) && t.some((e) => typeof e === "string"); } function findBundledPluginSource(e) { return findBundledPluginSourceInMap({ bundled: resolveBundledPluginSources({ workspaceDir: e.workspaceDir, env: e.env }), lookup: e.lookup }); } function resolveBundledPluginInstallCommandHint(e) { const t = findBundledPluginSource({ lookup: { kind: "pluginId", value: e.pluginId }, workspaceDir: e.workspaceDir }); if (!t?.localPath) return null; return `openclaw plugins install ${t.localPath}`; } //#endregion export { resolveBundledPluginSources as a, resolveBundledPluginInstallCommandHint as i, findBundledPluginSourceInMap as n, resolveSourceCheckoutBundledPluginIds as o, getProcessBundledPluginSources as r, findBundledPluginSource as t };