openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
199 lines (198 loc) • 8.9 kB
JavaScript
import { c as normalizeOptionalLowercaseString } from "./string-coerce-CCIiB4H7.mjs";
import { n as sanitizeForLog } from "./ansi-CZa2t0Hf.mjs";
import { t as isPluginEnabledByDefaultForPlatform } from "./default-enablement-DLXVIwwO.mjs";
import { u as normalizePluginsConfig } from "./config-state-B1JlHgba.mjs";
import { t as listExplicitlyDisabledChannelIdsForConfig } from "./config-presence-G9kglnWa.mjs";
import { o as isSafeChannelEnvVarTriggerName } from "./package-state-probes-BxreN8Qk.mjs";
import { a as resolveManifestOwnerBasePolicyBlock, n as isActivatedManifestOwner, t as hasExplicitManifestOwnerTrust } from "./manifest-owner-policy-B8Brw4Zo.mjs";
import { n as loadPluginManifestRegistryForPluginRegistry } from "./plugin-registry-contributions-iAw3gSDD.mjs";
import { m as resolveConfiguredChannelPresencePolicy, r as hasExplicitChannelConfig, u as listExplicitConfiguredChannelIdsForConfig } from "./channel-presence-policy-6XNqNGJr.mjs";
import "./plugin-registry-BrQav-kR.mjs";
import { t as normalizeLowercaseStringSet } from "./normalized-string-set-CJDHSDuW.mjs";
import "./channel-plugin-ids-DZDzcpUB.mjs";
//#region src/commands/doctor/shared/channel-plugin-blockers.ts
const CHANNEL_PLUGIN_BLOCKERS_CHECK_ID = "core/doctor/channel-plugin-blockers";
/** Find configured channel ids whose backing plugins cannot activate. */
function scanConfiguredChannelPluginBlockers(e, t = process.env, n = e, r = {}) {
const i = listExplicitConfiguredChannelIdsForConfig(e).map((e) => normalizeOptionalLowercaseString(e)).filter((e) => Boolean(e));
const a = normalizePluginsConfig(n.plugins);
const o = normalizePluginsConfig(e.plugins);
const s = r.manifestRecords ?? loadPluginManifestRegistryForPluginRegistry({
config: e,
env: t,
includeDisabled: true
}).plugins;
const c = r.ambientEnvTriggers === "suppress" ? /* @__PURE__ */ new Map() : listPackageEnvConfiguredChannelTriggers(s, t);
const l = resolveConfiguredChannelPresencePolicy({
config: e,
activationSourceConfig: n,
env: t,
includePersistedAuthState: false,
ambientEnvTriggers: r.ambientEnvTriggers,
manifestRecords: s
}).filter((e) => !c.has(e.channelId) || e.sources.some((e) => e !== "env" && e !== "manifest-env")).map((e) => e.channelId);
const u = /* @__PURE__ */ new Set([...i, ...i.length === 0 ? l : []]);
for (const t of listExplicitlyDisabledChannelIdsForConfig(e)) {
const e = normalizeOptionalLowercaseString(t) ?? t;
u.delete(e);
c.delete(e);
}
if (u.size === 0 && c.size === 0) return [];
const d = [];
const f = /* @__PURE__ */ new Set();
const p = /* @__PURE__ */ new Set();
const addHits = (e, t, n = false) => {
for (const r of t) {
if (!r.reason) continue;
if (r.reason === "plugins disabled") {
if (p.has(e)) continue;
p.add(e);
}
const t = `${e}\0${r.pluginId}\0${r.reason}`;
if (f.has(t)) continue;
f.add(t);
const i = {
channelId: e,
pluginId: r.pluginId,
reason: r.reason
};
if (n) i.channelAvailable = true;
d.push(i);
}
};
const resolveChannelOwnerStates = (t) => s.filter((e) => e.channels.some((e) => normalizeOptionalLowercaseString(e) === t)).map((r) => {
const resolveBase = (e, n) => {
const i = r.origin === "bundled" && hasExplicitChannelConfig({
config: e,
channelId: t
});
const a = r.origin === "workspace" && n.slots.contextEngine === r.id;
return {
bundledChannelConfigured: i,
workspaceSlot: a,
block: resolveManifestOwnerBasePolicyBlock({
plugin: r,
normalizedConfig: n,
allowRestrictiveAllowlistBypass: i || a
})
};
};
const i = resolveBase(n, a);
const s = i.block;
const c = r.origin === "bundled" || hasExplicitManifestOwnerTrust({
plugin: r,
normalizedConfig: a
}) || i.workspaceSlot;
const l = r.origin === "bundled" && (i.bundledChannelConfigured || isActivatedManifestOwner({
plugin: r,
normalizedConfig: a,
rootConfig: n
}));
const u = r.origin === "bundled" && !isPluginEnabledByDefaultForPlatform(r) && a.entries[r.id]?.enabled !== true;
const d = resolveBase(e, o);
const f = d.block === null && c && (d.bundledChannelConfigured || isActivatedManifestOwner({
plugin: r,
normalizedConfig: o,
rootConfig: e
}));
return {
pluginId: r.id,
available: f,
reason: f ? void 0 : r.origin === "bundled" && s === "not-in-allowlist" && u ? "not enabled and not in allowlist" : mapManifestOwnerBlockerReason(s) ?? (!c && s === null ? "missing explicit enablement" : r.origin === "bundled" && s === null && !l ? "not enabled" : void 0)
};
});
for (const e of u) {
const t = resolveChannelOwnerStates(e);
if (t.some((e) => e.available)) continue;
addHits(e, t);
}
for (const [e, t] of c) {
const n = resolveChannelOwnerStates(e);
const r = n.some((e) => e.available);
for (const i of t.values()) {
const t = n.filter((e) => i.has(e.pluginId));
if (t.some((e) => e.available)) continue;
addHits(e, t, r);
}
}
return d;
}
function listPackageEnvConfiguredChannelTriggers(e, t) {
const n = /* @__PURE__ */ new Map();
for (const r of e) {
const e = normalizeLowercaseStringSet(r.channels.values());
const i = normalizeOptionalLowercaseString(r.packageChannel?.id);
if (!i || !e.has(i)) continue;
const a = r.packageChannel?.configuredState?.env;
const o = a?.allOf ?? [];
const s = a?.anyOf ?? [];
if (o.length === 0 && s.length === 0) continue;
let c = n.get(i);
if (!c) {
c = /* @__PURE__ */ new Map();
n.set(i, c);
}
const hasEnvValue = (e) => {
if (!isSafeChannelEnvVarTriggerName(e)) return false;
const n = t[e] ?? t[e.toUpperCase()];
return typeof n === "string" && n.trim().length > 0;
};
if (!o.every(hasEnvValue) || s.length > 0 && !s.some(hasEnvValue)) continue;
for (const e of [...o, ...s].filter(hasEnvValue)) {
const t = e.trim().toUpperCase();
let n = c.get(t);
if (!n) {
n = /* @__PURE__ */ new Set();
c.set(t, n);
}
n.add(r.id);
}
}
return n;
}
function mapManifestOwnerBlockerReason(e) {
return e === null ? void 0 : {
"plugins-disabled": "plugins disabled",
"plugin-disabled": "disabled in config",
"blocked-by-denylist": "blocked by denylist",
"not-in-allowlist": "not in allowlist"
}[e];
}
function formatReason(e) {
if (e.reason === "disabled in config") return `plugin "${sanitizeForLog(e.pluginId)}" is disabled by plugins.entries.${sanitizeForLog(e.pluginId)}.enabled=false.`;
if (e.reason === "blocked by denylist") return `plugin "${sanitizeForLog(e.pluginId)}" is blocked by plugins.deny. Remove "${sanitizeForLog(e.pluginId)}" from plugins.deny.`;
if (e.reason === "plugins disabled") return `plugins.enabled=false blocks channel plugins globally.`;
if (e.reason === "missing explicit enablement") return `external plugin "${sanitizeForLog(e.pluginId)}" is installed without explicit trust. Add plugins.entries.${sanitizeForLog(e.pluginId)}.enabled=true.`;
if (e.reason === "not enabled") return `plugin "${sanitizeForLog(e.pluginId)}" is installed but not enabled. Add plugins.entries.${sanitizeForLog(e.pluginId)}.enabled=true.`;
if (e.reason === "not enabled and not in allowlist") return `plugin "${sanitizeForLog(e.pluginId)}" is not enabled and is omitted from plugins.allow. Add plugins.entries.${sanitizeForLog(e.pluginId)}.enabled=true and include "${sanitizeForLog(e.pluginId)}" in plugins.allow.`;
return `plugin "${sanitizeForLog(e.pluginId)}" is installed but omitted from plugins.allow. Include "${sanitizeForLog(e.pluginId)}" in plugins.allow.`;
}
function formatChannelPluginBlocker(e) {
return `channels.${sanitizeForLog(e.channelId)}: channel is configured, but ${formatReason(e)} Fix plugin enablement before relying on setup guidance for this channel.`;
}
/** Format doctor warnings for configured channels blocked by plugin activation state. */
function collectConfiguredChannelPluginBlockerWarnings(e) {
return e.map((e) => `- ${formatChannelPluginBlocker(e)}`);
}
/** Convert a configured channel plugin blocker into a structured Doctor finding. */
function channelPluginBlockerHitToHealthFinding(e) {
return {
checkId: CHANNEL_PLUGIN_BLOCKERS_CHECK_ID,
severity: "warning",
message: formatChannelPluginBlocker(e),
path: `channels.${e.channelId}`,
target: e.pluginId,
requirement: e.reason,
fixHint: "Fix plugin enablement before relying on setup guidance for this channel."
};
}
/** Return true when a setup warning targets a channel already explained by plugin blockers. */
function isWarningBlockedByChannelPlugin(e, t) {
return t.some((t) => {
if (t.channelAvailable) return false;
const n = `channels.${sanitizeForLog(t.channelId)}`;
return e.includes(`${n}:`) || e.includes(`${n}.`);
});
}
//#endregion
export { channelPluginBlockerHitToHealthFinding, collectConfiguredChannelPluginBlockerWarnings, isWarningBlockedByChannelPlugin, scanConfiguredChannelPluginBlockers };