openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
366 lines (365 loc) • 17.9 kB
JavaScript
import { c as normalizeOptionalLowercaseString } from "./string-coerce-CCIiB4H7.mjs";
import { t as isPluginEnabledByDefaultForPlatform } from "./default-enablement-DLXVIwwO.mjs";
import { t as normalizePluginPolicyId } from "./plugin-policy-id-CkilMowp.mjs";
import { C as normalizePluginsConfigWithResolverCore, b as withContextEngineOwner, p as resolveEffectivePluginActivationState, u as normalizePluginsConfig } from "./config-state-B1JlHgba.mjs";
import { _ as withBundledPluginEnablementCompat, g as isBundledProviderCompatPlugin } from "./installed-plugin-index-DYqse_gE.mjs";
import { p as resolvePluginMetadataSnapshot, x as createPluginRegistryIdNormalizer } from "./plugin-metadata-snapshot-By9ySblt.mjs";
import { t as listExplicitlyDisabledChannelIdsForConfig } from "./config-presence-G9kglnWa.mjs";
import "./plugin-registry-contributions-iAw3gSDD.mjs";
import { d as listGatewayActivatedChannelIds } from "./channel-presence-policy-6XNqNGJr.mjs";
import { t as canStartConfiguredChannelPlugin } from "./channel-startup-policy-Bi2dPqzS.mjs";
import { C as isWebSearchProviderAutoSelected, _ as collectConfiguredMemoryEmbeddingProviderIds, a as collectConfiguredProviderIds, b as collectConfiguredWebSearchProviderIds, c as collectValidationConfiguredShorthandModelIds, d as resolveAuthorizedGatewayStartupDreamingPluginIds, f as resolveContextEngineSlotStartupPluginId, g as collectConfiguredGenerationProviderIds, h as collectConfiguredAgentModelProviderIds, i as blocksPluginStartup, l as hasConfiguredActivationPath, m as shouldConsiderForGatewayStartup, n as addConfiguredSlotPluginIds, o as collectConfiguredStartupChannelIds, p as resolveMemorySlotStartupPluginId, r as addPluginConfigEntryIds, s as collectValidationConfiguredRefs, t as addConfiguredActivationPathPluginIds, u as readStartupBundledDiscoveryMode, w as manifestOwnsConfiguredModelProvider, y as collectConfiguredVoiceProviderIds } from "./gateway-startup-plugin-config-DY4atCe0.mjs";
import { t as getConfiguredDecisionProviderIds } from "./decision-model-setting-uB2lYmVW.mjs";
import { t as collectConfiguredAgentHarnessRuntimes } from "./harness-runtimes-BJ7G_AOQ.mjs";
import { r as sortUniquePluginIds, t as collectConfiguredSpeechProviderIds } from "./gateway-startup-speech-providers-BTIWPL7P.mjs";
import { r as manifestOwnsStorageProvider, t as collectConfiguredStorageProviderIds } from "./storage-provider-manifest-BceFektk.mjs";
import { n as normalizeWorkerProviderIds, t as collectConfiguredWorkerProviderIds } from "./worker-provider-config-DBBZKbtq.mjs";
import { n as manifestOwnsWorkerProvider } from "./worker-provider-manifest-Be6h0bIw.mjs";
import { t as createInstalledPluginIndexScopeLookup } from "./installed-plugin-index-scope-lookup-BDhPSNdH.mjs";
//#region src/plugins/gateway-startup-plugin-activation.ts
function addRequiredAgentHarnessPluginIds(e, t) {
const n = new Set(collectConfiguredAgentHarnessRuntimes(t.activationSourceConfig, { includeImplicitRuntimePreferences: false }));
if (n.size === 0) return;
for (const r of t.index.plugins) if (r.startup.agentHarnesses.some((e) => n.has(e)) && passesPluginStartupPolicy({
...t,
plugin: r
}, "harness")) e.add(r.pluginId);
}
function resolveStartupActivationState(e, t, n = false) {
const r = n ? withBundledPluginEnablementCompat({
config: e.config,
pluginIds: [e.plugin.pluginId],
env: e.env,
activation: "defaults"
}) ?? e.config : e.config;
return resolveEffectivePluginActivationState({
id: e.plugin.pluginId,
origin: e.plugin.origin,
channelIds: e.plugin.contributions?.channels,
config: n ? normalizePluginsConfig(r.plugins) : e.pluginsConfig,
rootConfig: r,
enabledByDefault: isPluginEnabledByDefaultForPlatform(e.plugin, e.platform),
activationSource: e.activationSource,
...t ? { autoEnabledReason: t } : {}
});
}
function isProviderCompatStartupPolicy(e) {
return e === "provider" || e === "worker" || e === "storage" || e === "speech" || e === "implicit-external";
}
function hasExplicitHookPolicyConfig(e) {
return e?.hooks?.allowConversationAccess === true || e?.hooks?.allowPromptInjection === true || e?.hooks?.timeoutMs !== void 0 || e?.hooks?.timeouts !== void 0 && Object.keys(e.hooks.timeouts).length > 0;
}
function passesPluginStartupPolicy(e, t) {
const { activationSource: n, plugin: r, pluginsConfig: i } = e;
const a = normalizePluginPolicyId(r.pluginId);
if (t !== "speech" && (!i.enabled || !n.plugins.enabled) || blocksPluginStartup({
pluginId: r.pluginId,
pluginsConfig: i,
activationSourcePlugins: n.plugins
})) return false;
if (t === "harness" && [i, n.plugins].some((e) => e.allow.length > 0 && !e.allow.includes(a))) return false;
const o = r.origin === "bundled";
if (o && (t === "harness" || t === "speech" || t === "root")) return true;
if (t === "root" && n.plugins.allow.length > 0 && !n.plugins.allow.includes(a)) return false;
const s = resolveStartupActivationState(e, t === "worker" ? "cloud worker provider required" : t === "storage" ? "storage provider required" : t === "decision" ? "decision model selected" : void 0, isProviderCompatStartupPolicy(t) && isBundledProviderCompatPlugin({
origin: r.origin,
providers: r.contributions?.providers,
contracts: r.contributions?.contracts
}));
if (!s.enabled) return false;
if (t === "harness" || t === "implicit-external" || t === "decision") return true;
if (t === "web-search-auto") return s.explicitlyEnabled;
if (t === "hook") return s.explicitlyEnabled || hasExplicitHookPolicyConfig(n.plugins.entries[a]);
return o || s.explicitlyEnabled;
}
function manifestOwnsConfiguredContract(e, t, n) {
return n.size > 0 && (e?.contracts?.[t] ?? []).some((e) => {
const t = normalizeOptionalLowercaseString(e);
return t ? n.has(t) : false;
});
}
function manifestOwnsConfiguredContractGroup(e, t) {
return Object.entries(t).some(([t, n]) => manifestOwnsConfiguredContract(e, t, n));
}
/** Evaluates manifest-owned startup surfaces in their original precedence order. */
function canStartGatewayStartupPlugin(e) {
const { manifest: t, plugin: n, activationSource: r, config: i } = e;
return manifestOwnsConfiguredContract(t, "decisionProviders", e.configuredDecisionProviderIds) && passesPluginStartupPolicy(e, "decision") || n.startup.agentHarnesses.some((t) => e.requiredAgentHarnessRuntimes.has(t)) && passesPluginStartupPolicy(e, "harness") || hasConfiguredActivationPath({
manifest: t,
config: r.rootConfig ?? i
}) && passesPluginStartupPolicy(e, "root") || manifestOwnsWorkerProvider(t, e.configuredWorkerProviderIds) && passesPluginStartupPolicy(e, "worker") || manifestOwnsStorageProvider(t, e.configuredStorageProviderIds) && passesPluginStartupPolicy(e, "storage") || manifestOwnsConfiguredContract(t, "speechProviders", e.configuredSpeechProviderIds) && passesPluginStartupPolicy(e, "speech") || manifestOwnsConfiguredContract(t, "webSearchProviders", e.configuredWebSearchProviderIds) && passesPluginStartupPolicy(e, "implicit-external") || e.autoSelectWebSearchProvider && (t?.contracts?.webSearchProviders?.length ?? 0) > 0 && passesPluginStartupPolicy(e, "web-search-auto") || manifestOwnsConfiguredModelProvider({
manifest: t,
configuredModelProviderIds: e.configuredModelProviderIds
}) && passesPluginStartupPolicy(e, "provider") || manifestOwnsConfiguredContractGroup(t, e.configuredGenerationProviderIds) && passesPluginStartupPolicy(e, "provider") || manifestOwnsConfiguredContractGroup(t, e.configuredVoiceProviderIds) && passesPluginStartupPolicy(e, "provider") || manifestOwnsConfiguredContract(t, "embeddingProviders", e.configuredMemoryEmbeddingProviderIds) && passesPluginStartupPolicy(e, "implicit-external") || (t?.activation?.onCapabilities?.includes("hook") === true || hasExplicitHookPolicyConfig(r.plugins.entries[normalizePluginPolicyId(n.pluginId)])) && passesPluginStartupPolicy(e, "hook") || (t?.contracts?.tools?.length ?? 0) > 0 && passesPluginStartupPolicy(e, "tool") || (t?.contracts?.trustedToolPolicies?.length ?? 0) > 0 && passesPluginStartupPolicy(e, "provider");
}
//#endregion
//#region src/plugins/gateway-startup-plugin-metadata.ts
function resolveGatewayStartupMetadataPluginIds(e) {
const t = createInstalledPluginIndexScopeLookup(e.index);
const n = e.activationSourceConfig ?? e.config;
const r = n === e.config;
const i = normalizePluginsConfigWithResolverCore(e.config.plugins, t.normalizePluginId);
const a = r ? i : normalizePluginsConfigWithResolverCore(n.plugins, t.normalizePluginId);
if (!i.enabled || !a.enabled) return [];
if (readStartupBundledDiscoveryMode(e.config, e.env) === "compat" || readStartupBundledDiscoveryMode(n, e.env) === "compat") return;
if (i.allow.length === 0 && a.allow.length === 0) return;
const o = r ? [e.config] : [e.config, n];
const s = r ? [i] : [i, a];
const c = new Set(s.flatMap((e) => e.allow.map(t.normalizePluginId)));
for (const e of s) addPluginConfigEntryIds(c, e, t.normalizePluginId);
const l = resolveMemorySlotStartupPluginId({
activationSourceConfig: n,
activationSourcePlugins: a,
normalizePluginId: t.normalizePluginId
});
addConfiguredSlotPluginIds(c, {
index: e.index,
activationSourceConfig: n,
activationSourcePlugins: a,
lookup: t
});
for (const t of resolveAuthorizedGatewayStartupDreamingPluginIds({
config: e.config,
pluginsConfig: i,
activationSource: {
plugins: a,
rootConfig: n
},
activationSourcePlugins: a,
selectedMemoryPluginId: l,
index: e.index,
platform: e.platform
})) c.add(t);
if (!t.hasCompleteConfigPathActivationMetadata()) return;
addConfiguredActivationPathPluginIds(c, {
activationSourceConfig: n,
index: e.index
});
const u = collectConfiguredStartupChannelIds({
configs: o,
env: e.env,
ambientEnvTriggers: e.ambientEnvTriggers
});
if (!t.hasDirectChannelOwners(u)) return;
t.addDirectChannelOwners(c, u);
const d = o.flatMap(collectConfiguredProviderIds);
const f = o.map(collectValidationConfiguredRefs);
const p = sortUniquePluginIds([...d, ...f.flatMap((e) => e.providerIds)]);
if (!t.canResolveDirectProviderIds(p, c)) return;
t.addDirectProviderOwners(c, p);
for (const n of [
() => o.flatMap(getConfiguredDecisionProviderIds),
() => normalizeWorkerProviderIds([...o.flatMap(collectConfiguredWorkerProviderIds), ...e.workerProviderIds ?? []]),
() => o.flatMap(collectConfiguredStorageProviderIds)
]) {
const e = n();
if (!t.hasProviderContributionOwners(e)) return;
t.addProviderContributionOwners(c, e);
}
const m = sortUniquePluginIds(f.flatMap((e) => collectValidationConfiguredShorthandModelIds(e.shorthandModelRefs)));
if (!t.hasShorthandModelOwners(m)) return;
t.addShorthandModelOwners(c, m);
addRequiredAgentHarnessPluginIds(c, {
activationSourceConfig: n,
config: e.config,
index: e.index,
pluginsConfig: i,
activationSource: {
plugins: a,
rootConfig: n
},
env: e.env,
platform: e.platform
});
const h = new Set(s.flatMap((e) => e.deny));
for (const e of h) c.delete(t.normalizePluginId(e));
for (const e of s) for (const [n, r] of Object.entries(e.entries)) if (r?.enabled === false) c.delete(t.normalizePluginId(n));
if (!t.hasInstalledPluginIds(c)) return;
return sortUniquePluginIds(c);
}
function createGatewayStartupMetadataPluginIdScope(e) {
const t = normalizeWorkerProviderIds(e.workerProviderIds ?? []);
return { resolve: ({ index: n }) => resolveGatewayStartupMetadataPluginIds({
config: e.config,
activationSourceConfig: e.activationSourceConfig,
env: e.env,
index: n,
...t.length > 0 ? { workerProviderIds: t } : {},
platform: e.platform,
ambientEnvTriggers: e.ambientEnvTriggers
}) };
}
//#endregion
//#region src/plugins/gateway-startup-plugin-plan.ts
function resolveChannelPluginIdsFromRegistry(e) {
const { manifestRegistry: t } = e;
return t.plugins.filter((e) => e.channels.length > 0).map((e) => e.id);
}
function resolveGatewayStartupPluginPlanFromRegistry(e) {
const t = resolveChannelPluginIdsFromRegistry({ manifestRegistry: e.manifestRegistry });
const n = e.activationSourceConfig ?? e.config;
const r = new Set(listGatewayActivatedChannelIds({
config: e.config,
activationSourceConfig: n,
env: e.env,
ambientEnvTriggers: e.ambientEnvTriggers,
manifestRecords: e.manifestRegistry.plugins,
discovery: e.discovery
}));
const i = e.normalizePluginId ?? createPluginRegistryIdNormalizer(e.index, { manifestRegistry: e.manifestRegistry });
const a = e.index.plugins.map((e) => ({
id: e.pluginId,
contextEngineIds: e.contextEngineIds
}));
const o = withContextEngineOwner(normalizePluginsConfigWithResolverCore(e.config.plugins, i), a, i);
const s = withContextEngineOwner(normalizePluginsConfigWithResolverCore(n.plugins, i), a, i);
const c = {
plugins: s,
rootConfig: n
};
const l = new Map(e.manifestRegistry.plugins.map((e) => [e.id, e]));
const u = new Set(listExplicitlyDisabledChannelIdsForConfig(e.config));
const d = {
config: e.config,
pluginsConfig: o,
activationSource: c,
env: e.env,
requiredAgentHarnessRuntimes: new Set(collectConfiguredAgentHarnessRuntimes(n)),
configuredSpeechProviderIds: collectConfiguredSpeechProviderIds(n),
configuredWebSearchProviderIds: collectConfiguredWebSearchProviderIds(n),
autoSelectWebSearchProvider: isWebSearchProviderAutoSelected(n),
configuredModelProviderIds: collectConfiguredAgentModelProviderIds(n, e.manifestRegistry),
configuredGenerationProviderIds: collectConfiguredGenerationProviderIds(n),
configuredVoiceProviderIds: collectConfiguredVoiceProviderIds(n),
configuredMemoryEmbeddingProviderIds: collectConfiguredMemoryEmbeddingProviderIds(n),
configuredDecisionProviderIds: new Set(getConfiguredDecisionProviderIds(n)),
configuredWorkerProviderIds: /* @__PURE__ */ new Set([...collectConfiguredWorkerProviderIds(n), ...normalizeWorkerProviderIds(e.workerProviderIds ?? [])]),
configuredStorageProviderIds: new Set(collectConfiguredStorageProviderIds(n)),
platform: e.platform
};
const f = resolveMemorySlotStartupPluginId({
activationSourceConfig: n,
activationSourcePlugins: s,
normalizePluginId: i
});
const p = resolveAuthorizedGatewayStartupDreamingPluginIds({
config: e.config,
pluginsConfig: o,
activationSource: c,
activationSourcePlugins: s,
selectedMemoryPluginId: f,
index: e.index,
platform: e.platform
});
const m = resolveContextEngineSlotStartupPluginId({
records: e.index.plugins.map((e) => ({
id: e.pluginId,
contextEngineIds: e.contextEngineIds
})),
activationSourceConfig: n,
activationSourcePlugins: s,
normalizePluginId: i
});
const h = [];
for (const t of e.index.plugins) {
const n = normalizePluginPolicyId(t.pluginId);
const i = l.get(t.pluginId);
const a = i?.channels ?? [];
const s = i?.channels?.some((e) => {
const t = normalizeOptionalLowercaseString(e);
return t ? !u.has(t) : false;
}) ?? false;
const g = t.origin !== "bundled" && s && o.entries[n]?.enabled === true && !o.deny.includes(n);
if (a.some((e) => r.has(e)) || g) {
if (canStartConfiguredChannelPlugin({
id: t.pluginId,
origin: t.origin,
channelIds: t.origin === "bundled" ? a : t.contributions?.channels,
config: e.config,
pluginsConfig: o,
activationSource: c
})) h.push(t.pluginId);
continue;
}
if (canStartGatewayStartupPlugin({
...d,
plugin: t,
manifest: i
})) {
h.push(t.pluginId);
continue;
}
if (!shouldConsiderForGatewayStartup({
plugin: t,
manifest: i,
startupDreamingPluginIds: p,
memorySlotStartupPluginId: f,
contextEngineSlotStartupPluginId: m
})) continue;
if (p.has(t.pluginId)) {
h.push(t.pluginId);
continue;
}
const _ = t.origin === "bundled" && t.packageBuild?.bundledDist === false ? "workspace" : t.origin;
const v = resolveEffectivePluginActivationState({
id: t.pluginId,
origin: _,
channelIds: t.contributions?.channels,
config: o,
rootConfig: e.config,
enabledByDefault: isPluginEnabledByDefaultForPlatform(t, e.platform),
activationSource: c
});
if (!v.enabled) continue;
if (_ !== "bundled" ? v.explicitlyEnabled : v.source === "explicit" || v.source === "default") h.push(t.pluginId);
}
return {
channelPluginIds: t,
pluginIds: h
};
}
//#endregion
//#region src/plugins/gateway-startup-plugin-loader.ts
function resolveChannelPluginIds(e) {
return [...loadGatewayStartupPluginPlan(e).channelPluginIds];
}
function loadGatewayStartupPluginPlanWithMetadata(e) {
const t = e.activationSourceConfig ?? e.config;
const n = e.metadataSnapshot ?? resolvePluginMetadataSnapshot({
config: t,
workspaceDir: e.workspaceDir,
env: e.env,
allowWorkspaceScopedCurrent: e.workspaceDir === void 0,
...e.index ? { index: e.index } : {},
pluginIdScope: createGatewayStartupMetadataPluginIdScope({
config: e.config,
activationSourceConfig: e.activationSourceConfig,
env: e.env,
workerProviderIds: e.workerProviderIds ?? [],
platform: e.platform,
ambientEnvTriggers: e.ambientEnvTriggers
})
});
const r = performance.now();
return {
plan: resolveGatewayStartupPluginPlanFromRegistry({
config: e.config,
activationSourceConfig: e.activationSourceConfig,
env: e.env,
index: n.index,
manifestRegistry: n.manifestRegistry,
discovery: n.discovery,
normalizePluginId: n.normalizePluginId,
workerProviderIds: e.workerProviderIds ?? [],
platform: e.platform,
ambientEnvTriggers: e.ambientEnvTriggers
}),
metadataSnapshot: n,
startupPlanMs: performance.now() - r
};
}
function loadGatewayStartupPluginPlan(e) {
return loadGatewayStartupPluginPlanWithMetadata(e).plan;
}
//#endregion
export { createGatewayStartupMetadataPluginIdScope as a, resolveGatewayStartupPluginPlanFromRegistry as i, loadGatewayStartupPluginPlanWithMetadata as n, resolveGatewayStartupMetadataPluginIds as o, resolveChannelPluginIds as r, loadGatewayStartupPluginPlan as t };