UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

79 lines (78 loc) 3.38 kB
import { c as isRecord } from "./record-coerce-DItp3I4t.js"; import { l as normalizeOptionalString } from "./string-coerce-CIXf7egm.js"; import { i as getGatewayPluginMetadataSnapshot } from "./current-plugin-metadata-state-B1UoAr4G.js"; import { r as loadPluginManifest } from "./manifest-ByRdkf9X.js"; import { n as discoverOpenClawPlugins } from "./discovery-D_VDsZuY.js"; import path from "node:path"; //#region src/plugins/bundled-sources.ts function findBundledPluginSourceInMap(params) { const targetValue = params.lookup.value.trim(); if (!targetValue) return; if (params.lookup.kind === "pluginId") return params.bundled.get(targetValue); for (const source of params.bundled.values()) if (params.lookup.kind === "npmSpec" && source.npmSpec === targetValue || params.lookup.kind === "localPath" && path.resolve(source.localPath) === path.resolve(targetValue)) return source; } function resolveBundledPluginSources(params) { const snapshot = params.discovery ? void 0 : getGatewayPluginMetadataSnapshot(); const sources = snapshot ? (snapshot.bundledManifestRegistry?.plugins ?? []).map((manifest) => ({ candidate: manifest, manifest })) : (params.discovery ?? discoverOpenClawPlugins({ workspaceDir: params.workspaceDir, env: params.env })).candidates.flatMap((candidate) => { if (candidate.origin !== "bundled") return []; const loaded = loadPluginManifest(candidate.rootDir, false); return loaded.ok ? [{ candidate, manifest: loaded.manifest }] : []; }); const bundled = /* @__PURE__ */ new Map(); for (const { candidate, manifest } of sources) { const pluginId = manifest.id; if (bundled.has(pluginId)) continue; const npmSpec = normalizeOptionalString(candidate.packageManifest?.install?.npmSpec) || normalizeOptionalString(candidate.packageName) || void 0; const version = normalizeOptionalString(candidate.packageVersion) || normalizeOptionalString(manifest.version) || void 0; bundled.set(pluginId, { pluginId, localPath: candidate.rootDir, npmSpec, version, ...isRecord(manifest.configSchema) ? { configSchema: manifest.configSchema } : {}, requiresConfig: pluginConfigSchemaHasRequiredFields(manifest.configSchema) }); } return bundled; } /** Projects bundled sources from the current generation's shared discovery facts. */ function getProcessBundledPluginSources() { return resolveBundledPluginSources({}); } function pluginConfigSchemaHasRequiredFields(schema) { if (!isRecord(schema)) return false; const required = schema.required; return Array.isArray(required) && required.some((entry) => typeof entry === "string"); } function findBundledPluginSource(params) { return findBundledPluginSourceInMap({ bundled: resolveBundledPluginSources({ workspaceDir: params.workspaceDir, env: params.env }), lookup: params.lookup }); } function resolveBundledPluginInstallCommandHint(params) { const bundledSource = findBundledPluginSource({ lookup: { kind: "pluginId", value: params.pluginId }, workspaceDir: params.workspaceDir, env: params.env }); if (!bundledSource?.localPath) return null; return `openclaw plugins install ${bundledSource.localPath}`; } //#endregion export { resolveBundledPluginSources as a, resolveBundledPluginInstallCommandHint as i, findBundledPluginSourceInMap as n, getProcessBundledPluginSources as r, findBundledPluginSource as t };