UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

77 lines (76 loc) • 4.2 kB
import { o as normalizeLowercaseStringOrEmpty } from "./string-coerce-CCIiB4H7.mjs"; import { b as uniqueStrings } from "./string-normalization-DLmfYZXI.mjs"; import { r as normalizeProviderId } from "./provider-id-b5XGSf9C.mjs"; import { u as normalizePluginsConfig } from "./config-state-B1JlHgba.mjs"; import { p as normalizePluginIdScope, u as createPluginIdScopeSet } from "./current-plugin-metadata-snapshot-H0TP3PFt.mjs"; import { i as passesManifestOwnerBasePolicy, r as isBundledManifestOwner, t as hasExplicitManifestOwnerTrust } from "./manifest-owner-policy-B8Brw4Zo.mjs"; import { n as loadPluginManifestRegistryForPluginRegistry } from "./plugin-registry-contributions-iAw3gSDD.mjs"; //#region src/plugins/activation-planner.ts /** Computes which manifest-owned plugins need activation for commands, routes, providers, or capabilities. */ /** Selects deterministic plugin ids without importing plugin runtime modules. */ function resolveManifestActivationPluginIds(e) { const t = createPluginIdScopeSet(normalizePluginIdScope(e.onlyPluginIds)); const n = e.manifestRecords ?? loadPluginManifestRegistryForPluginRegistry({ config: e.config, workspaceDir: e.workspaceDir, env: e.env, includeDisabled: true }).plugins; if (n.length === 0 || t?.size === 0) return []; const r = e.normalizedConfig ?? normalizePluginsConfig(e.config?.plugins); const i = normalizeActivationTrigger(e.trigger); const a = []; for (const o of n) { if (e.origin && o.origin !== e.origin) continue; if (t && !t.has(o.id)) continue; if (!passesManifestOwnerBasePolicy({ plugin: o, normalizedConfig: r, allowRestrictiveAllowlistBypass: e.allowRestrictiveAllowlistBypass })) continue; if (e.requireExplicitManifestOwnerTrust && !hasExplicitActivationPlannerManifestOwnerTrust({ plugin: o, normalizedConfig: r })) continue; if (matchesActivation(o, e.trigger, i)) a.push(o.id); } return uniqueStrings(a.toSorted((e, t) => e.localeCompare(t))); } function hasExplicitActivationPlannerManifestOwnerTrust(e) { return isBundledManifestOwner(e.plugin) || e.plugin.origin === "config" || hasExplicitManifestOwnerTrust({ plugin: e.plugin, normalizedConfig: e.normalizedConfig }); } function matchesActivation(e, t, n) { const { activation: r } = e; const i = t.kind === "capability" ? t.capability : void 0; if (i && r?.onCapabilities?.includes(i)) return true; const owns = (e, t) => i ? e?.length : listHasNormalizedValue(e, n, t); switch (t.kind === "capability" ? t.capability : t.kind) { case "command": return Boolean(listHasNormalizedValue(r?.onCommands, n, normalizeLowercaseStringOrEmpty) || e.cliCommands?.some((e) => normalizeLowercaseStringOrEmpty(e.name) === n) || e.commandAliases?.some((e) => normalizeLowercaseStringOrEmpty(e.cliCommand ?? e.name) === n)); case "provider": return Boolean(owns(r?.onProviders, normalizeProviderId) || owns(e.providers, normalizeProviderId) || !i && e.providerEndpoints?.some((e) => normalizeProviderId(e.endpointClass) === n) || (i ? e.setup?.providers?.length : e.setup?.providers?.some((e) => normalizeProviderId(e.id) === n))); case "agentHarness": return listHasNormalizedValue(r?.onAgentHarnesses, n, normalizeLowercaseStringOrEmpty); case "channel": return Boolean(owns(r?.onChannels, normalizeLowercaseStringOrEmpty) || owns(e.channels, normalizeLowercaseStringOrEmpty)); case "route": return listHasNormalizedValue(r?.onRoutes, n, normalizeLowercaseStringOrEmpty); case "tool": return Boolean(e.contracts?.tools?.length); case "hook": return Boolean(e.hooks?.length); } return false; } function normalizeActivationTrigger(e) { switch (e.kind) { case "command": return normalizeLowercaseStringOrEmpty(e.command); case "provider": return normalizeProviderId(e.provider); case "agentHarness": return normalizeLowercaseStringOrEmpty(e.runtime); case "channel": return normalizeLowercaseStringOrEmpty(e.channel); case "route": return normalizeLowercaseStringOrEmpty(e.route); case "capability": return e.capability; } return e; } function listHasNormalizedValue(e, t, n) { return e?.some((e) => n(e) === t) ?? false; } //#endregion export { resolveManifestActivationPluginIds as t };