UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

110 lines (109 loc) • 4 kB
import { n as sanitizeTerminalText } from "./safe-text-C80HAQ2e.mjs"; import { i as normalizeChatChannelId } from "./ids-BRSWrLzE.mjs"; import { c as normalizePluginId, u as normalizePluginsConfig } from "./config-state-B1JlHgba.mjs"; import { t as ensurePluginAllowlisted } from "./plugins-allowlist-DW5H7gQB.mjs"; import { t as ManagedPluginLifecycleError } from "./management-lifecycle-error-COJYzrtT.mjs"; import { t as setPluginEnabledInConfig } from "./toggle-config-DgGsLAY5.mjs"; //#region src/plugins/enable.ts /** Keep install policy while staging a plugin whose required settings are not configured yet. */ function prepareConfigForDisabledInstall(e, t) { const n = setPluginEnabledInConfig(e, t, false, { updateChannelConfig: false }); const r = normalizePluginId(normalizeChatChannelId(t) ?? t); const i = { ...n.plugins?.entries }; const a = { ...i[r] }; delete a.config; i[r] = a; return { ...n, plugins: { ...n.plugins, entries: i } }; } /** Enables a plugin in config unless global, denylist, or allowlist policy blocks it. */ function enablePluginInConfig(e, t, n = {}) { const r = normalizeChatChannelId(t); const i = normalizePluginId(r ?? t); const a = normalizePluginsConfig(e.plugins); if (!a.enabled) return { config: e, enabled: false, pluginId: i, reason: "plugins disabled" }; if (a.deny.includes(i)) return { config: e, enabled: false, pluginId: i, reason: "blocked by denylist" }; if (a.allow.length > 0 && !a.allow.includes(i)) return { config: e, enabled: false, pluginId: i, reason: "blocked by allowlist" }; return { config: setPluginEnabledInConfig(e, i, true, n), enabled: true, pluginId: i }; } /** * Enables a plugin selected through an explicit user action. * * ClickClack is bundled without a separate install trust record, so selecting * it is the trust gesture that materializes its id in a restrictive allowlist. */ function enableExplicitlySelectedPluginInConfig(e, t, n = {}) { const r = enablePluginInConfig(e, t, n); if (r.reason !== "blocked by allowlist" || r.pluginId !== "clickclack") return r; return enablePluginInConfig(ensurePluginAllowlisted(e, r.pluginId), r.pluginId, n); } /** Review a managed plugin before an explicit setup action activates it. */ async function enablePluginWithCapabilityConsent(e, t, n = {}) { const r = enableExplicitlySelectedPluginInConfig(e, t, n); if (!r.enabled) return r; try { const { withPluginLifecycleLeaseAsync: t } = await import("./plugin-lifecycle-lease-B1cHoIkh.mjs"); return await t({ env: n.env }, async () => { const { loadInstalledPluginIndexInstallRecords: t } = await import("./installed-plugin-index-records-DCg7VAGG.mjs"); const i = await t({ env: n.env }); if (Object.keys(i).length === 0) return r; const { resolvePluginMetadataSnapshot: a } = await import("./plugin-metadata-snapshot-PjL6_oGE.mjs"); const o = a({ config: e, env: n.env, workspaceDir: n.workspaceDir, allowCurrent: false }); const s = o.normalizePluginId(r.pluginId); const c = o.index.plugins.find((e) => e.pluginId === s); if (c && (!c.enabled || n.recordOfficialCapabilities) && c.origin !== "bundled") { const { resolvePluginCapabilityConsent: t } = await import("./capability-consent-DtN_u18Y.mjs"); await t({ config: e, pluginId: s, env: n.env, metadata: o, onCapabilityConsent: n.onCapabilityConsent, recordOfficialCapabilities: n.recordOfficialCapabilities, beforePersistentEffect: n.beforePersistentEffect, beforePersistentApply: n.beforePersistentApply }); } return r; }); } catch (t) { if (!(t instanceof ManagedPluginLifecycleError)) throw t; return { config: e, pluginId: r.pluginId, enabled: false, reason: sanitizeTerminalText(t.message) }; } } //#endregion export { prepareConfigForDisabledInstall as i, enablePluginInConfig as n, enablePluginWithCapabilityConsent as r, enableExplicitlySelectedPluginInConfig as t };