openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
524 lines (523 loc) • 19.7 kB
JavaScript
import { c as normalizeOptionalLowercaseString, l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs";
import { v as floorPositiveFiniteNumber } from "./number-coercion-D6u-4YD8.mjs";
import { a as asOptionalRecord } from "./record-coerce-CVPuDqcc.mjs";
import { y as sortUniqueStrings } from "./string-normalization-DLmfYZXI.mjs";
import { o as getPluginRuntimeGatewayRequestScope } from "./gateway-request-scope-BvvDhs5D.mjs";
import { i as parseModelCatalogRef } from "./model-catalog-refs-Bk2MNoCv.mjs";
import { n as discoverOpenClawPlugins } from "./discovery-DvJYrQFY.mjs";
import { i as getGatewayPluginMetadataSnapshot } from "./current-plugin-metadata-state-BmYo9Q7A.mjs";
import { u as normalizePluginsConfig } from "./config-state-B1JlHgba.mjs";
import { _ as withBundledPluginEnablementCompat, h as isBundledProviderCompatContract, t as createInstalledPluginEnabledPredicate } from "./installed-plugin-index-DYqse_gE.mjs";
import { t as loadPluginManifestRegistryCore } from "./manifest-registry-CuWv8ibc.mjs";
import { i as getCurrentPluginMetadataSnapshot } from "./current-plugin-metadata-snapshot-H0TP3PFt.mjs";
import { o as resolveConfiguredTalkRealtimeProviderId, s as resolveConfiguredTalkSpeechProviderId } from "./talk-CqEDzucG.mjs";
import { n as findCapabilityProviderEntry } from "./provider-registry-shared-C3T4TYXW.mjs";
import { n as isManifestPluginAvailableForControlPlane, o as loadManifestContractSnapshot, r as isManifestPluginOwnerAllowedByControlPlanePolicy, t as hasManifestContractValue } from "./manifest-contract-eligibility-DoGGge-2.mjs";
import { a as pluginRuntimeLoaderLogger, n as buildPluginRuntimeLoadOptions, r as getPluginRuntimeLoadContext } from "./load-context-CwTU1iXB.mjs";
import { a as registryContainsRuntimePluginIds, n as getLoadedRuntimePluginRegistry } from "./active-runtime-registry-Y-wDXpG6.mjs";
import { d as resolveRuntimePluginRegistry, n as acquirePluginRegistryWithInternalOverrides, o as loadOpenClawPluginsWithInternalOverrides, u as resolvePluginCapabilityCatalogContext } from "./loader-runtime-load-Ba16vW6K.mjs";
import { s as capabilityCatalogFamilies } from "./registry-ClBzy_np.mjs";
import "./loader--j41eir2.mjs";
//#region src/tts/voice-models.ts
function parseVoiceModelRef(e) {
const t = typeof e === "string" ? parseModelCatalogRef(e) : null;
return t ? {
provider: t.provider,
model: t.modelId
} : void 0;
}
/** Match provider ids case-insensitively across canonical id and aliases. */
function providerMatchesId(e, t) {
const n = normalizeOptionalLowercaseString(t);
return Boolean(n && [e.id, ...e.aliases ?? []].some((e) => normalizeOptionalLowercaseString(e) === n));
}
function voiceProviderSupportsModel(e, t) {
if (!e) return false;
const n = normalizeOptionalString(t);
return [e.defaultModel, ...e.models ?? []].some((e) => normalizeOptionalString(e) === n);
}
function resolveVoiceModelRefs(e) {
if (typeof e === "string") {
const t = parseVoiceModelRef(e);
return t ? [t] : [];
}
const t = asOptionalRecord(e);
if (!t) return [];
const n = floorPositiveFiniteNumber(t.timeoutMs);
const r = [];
const addRef = (e) => {
const t = parseVoiceModelRef(e);
if (t) r.push({
...t,
...n === void 0 ? {} : { timeoutMs: n }
});
};
addRef(t.primary);
if (Array.isArray(t.fallbacks)) for (const e of t.fallbacks) addRef(e);
return r;
}
function resolveSupportedVoiceModelRefs(e) {
return resolveVoiceModelRefs(e.config).flatMap((t) => {
const n = e.providers.find((e) => providerMatchesId(e, t.provider));
if (!n || e.providerId && !providerMatchesId(n, e.providerId)) return [];
return voiceProviderSupportsModel(n, t.model) ? [{
...t,
provider: n.id
}] : [];
});
}
function resolveVoiceProviderCandidates(e) {
const t = e.providers.find((t) => providerMatchesId(t, e.primaryProvider))?.id ?? e.primaryProvider;
const n = [];
const r = /* @__PURE__ */ new Set();
const addCandidate = (e) => {
n.push(e);
r.add(e.provider);
};
const i = resolveSupportedVoiceModelRefs({
config: e.voiceModelConfig,
providers: e.providers
});
const a = i.filter((e) => e.provider === t);
for (const e of a) addCandidate({
provider: t,
voiceModel: e
});
if (a.length === 0) addCandidate({ provider: t });
for (const e of i) if (e.provider !== t) addCandidate({
provider: e.provider,
voiceModel: e
});
for (const t of e.providers) if (!r.has(t.id)) addCandidate({ provider: t.id });
return n;
}
/** Resolve only the primary provider candidate for direct synthesis paths. */
function resolvePrimaryVoiceProviderCandidate(e) {
const t = e.providers.find((t) => providerMatchesId(t, e.primaryProvider))?.id ?? e.primaryProvider;
const n = resolveSupportedVoiceModelRefs({
config: e.voiceModelConfig,
providers: e.providers,
providerId: t
})[0];
return n ? {
provider: t,
voiceModel: n
} : { provider: t };
}
/** Read provider config by configured id, canonical id, or alias. */
function getVoiceProviderConfig(e) {
const t = [
normalizeOptionalString(e.configuredProviderId),
e.provider.id,
...e.provider.aliases ?? []
].filter((e) => Boolean(e));
const n = Object.keys(e.providerConfigs);
for (const r of t) {
if (Object.hasOwn(e.providerConfigs, r)) return e.providerConfigs[r] ?? {};
const t = normalizeOptionalLowercaseString(r);
const i = n.find((e) => normalizeOptionalLowercaseString(e) === t);
if (i) return e.providerConfigs[i] ?? {};
}
return {};
}
//#endregion
//#region src/plugins/bundled-capability-runtime.ts
/** Loads capability providers through the canonical scoped plugin loader. */
function createCapabilityRegistrationRuntime(e) {
return { config: {
current: () => e,
mutateConfigFile: async () => {
throw new Error("Capability discovery cannot mutate plugin configuration.");
},
replaceConfigFile: async () => {
throw new Error("Capability discovery cannot replace plugin configuration.");
}
} };
}
function loadBundledCapabilityRuntimeRegistry(e) {
const { options: t, overrides: n } = prepareBundledCapabilityRuntime(e);
return loadOpenClawPluginsWithInternalOverrides(t, n);
}
function acquireBundledCapabilityRuntimeRegistry(e) {
const { options: t, overrides: n } = prepareBundledCapabilityRuntime(e);
return acquirePluginRegistryWithInternalOverrides(t, n);
}
function prepareBundledCapabilityRuntime(e) {
const { pluginIds: t, ...n } = e;
const r = e.env ?? process.env;
const i = e.config?.plugins?.enabled === false ? e.config : withBundledPluginEnablementCompat({
config: e.config,
pluginIds: e.pluginIds,
env: r
}) ?? {};
const a = !e.discovery && !e.installRecords ? getGatewayPluginMetadataSnapshot() : void 0;
const o = e.manifestRegistry ?? (a ? a.bundledManifestRegistry ?? {
plugins: [],
diagnostics: []
} : void 0);
const s = o ? void 0 : e.discovery ?? discoverOpenClawPlugins({
env: r,
workspaceDir: e.workspaceDir,
installRecords: e.installRecords
});
const c = new Set(e.pluginIds);
const l = o ?? loadPluginManifestRegistryCore({
config: i,
env: r,
workspaceDir: e.workspaceDir,
installRecords: e.installRecords,
candidates: s?.candidates,
diagnostics: s?.diagnostics
});
const u = {
plugins: l.plugins.filter((e) => e.origin === "bundled" && c.has(e.id)),
diagnostics: l.diagnostics
};
return {
options: {
...n,
config: i,
env: r,
onlyPluginIds: [...t],
cache: false,
activate: false,
channelPluginLoadIntent: "full",
manifestRegistry: u,
logger: pluginRuntimeLoaderLogger
},
overrides: {
runtime: createCapabilityRegistrationRuntime(i),
moduleLoader: {
installNativeSdkResolver: false,
loaderFilename: import.meta.url
}
}
};
}
//#endregion
//#region src/plugins/capability-provider-runtime.ts
function projectCapabilityProviderEntries(e, t) {
if (!t) return e;
return e.map((e) => ({
...e,
provider: t(e.provider, e.pluginId)
}));
}
function shouldMergeManifestProvidersWhenActive(e) {
return e === "mediaUnderstandingProviders" || e === "imageGenerationProviders" || e === "videoGenerationProviders" || e === "musicGenerationProviders";
}
function shouldSkipCapabilityResolution(e) {
return e.cfg?.plugins?.enabled === false && e.key !== "speechProviders";
}
function prepareCapabilityPluginResolution(e) {
const t = e.pluginMetadataSnapshot ?? loadManifestContractSnapshot({
config: e.cfg,
...e.workspaceDir ? { workspaceDir: e.workspaceDir } : {}
});
const n = createInstalledPluginEnabledPredicate(t.index.plugins, e.cfg);
let r;
return function resolve(i, a, o) {
const s = o ? /* @__PURE__ */ new Set() : void 0;
const c = t.plugins.filter((c) => {
if (!hasManifestContractValue({
plugin: c,
contract: i,
value: a
}) || o && !c.contracts?.[i]?.some((e) => o.has(e)) || !isManifestPluginAvailableForControlPlane({
snapshot: t,
plugin: c,
config: e.cfg,
isInstalledPluginEnabled: n,
normalizedConfig: e.cfg?.plugins && (r ??= normalizePluginsConfig(e.cfg.plugins)),
allowRestrictiveAllowlistBypass: i === "speechProviders" && e.cfg?.plugins?.enabled === false,
allowBundledProviderCompat: isBundledProviderCompatContract(i)
})) return false;
if (o && s) {
for (const e of c.contracts?.[i] ?? []) if (o.has(e)) s.add(e);
}
return true;
});
if (o && s?.size && s.size < o.size) return resolve(i, a);
return {
runtimePluginIds: sortUniqueStrings(c.map((e) => e.id)),
bundledCompatPluginIds: sortUniqueStrings(c.filter((e) => e.origin === "bundled").map((e) => e.id))
};
};
}
function createCapabilityLoad(e, t, n, r) {
const i = t.bundledCompatPluginIds;
const a = withBundledPluginEnablementCompat({
config: e.cfg,
pluginIds: i,
...n?.env ? { env: n.env } : {}
});
const o = {
...a === void 0 ? {} : { config: a },
onlyPluginIds: t.runtimePluginIds,
activate: false
};
const s = n ? buildPluginRuntimeLoadOptions(n, o) : o;
return {
key: e.key,
bundledCompatPluginIds: t.bundledCompatPluginIds,
loadOptions: s,
requested: r
};
}
function resolveCapabilityLoadContext(e, t) {
const n = getPluginRuntimeLoadContext(e);
if (!n?.metadataSnapshot || n.env !== process.env) return;
return getCurrentPluginMetadataSnapshot({
config: t,
workspaceDir: n.workspaceDir,
...t === void 0 ? { requireDefaultDiscoveryContext: true } : {}
}) === n.metadataSnapshot ? n : void 0;
}
function mergeCapabilityProviderEntries(e, t) {
const n = /* @__PURE__ */ new Map();
for (const r of [e, t]) for (const e of r) if (!n.has(e.provider.id)) n.set(e.provider.id, e);
return [...n.values()];
}
function addStringValue(e, t) {
const n = normalizeOptionalLowercaseString(t);
if (n) e.add(n);
}
function collectRequestedCapabilityProviderIds(e) {
if (!shouldScopeCapabilityLoadToRequestedProviders(e.key) || e.key === "realtimeTranscriptionProviders" && !e.includeVoiceModel) return;
const t = /* @__PURE__ */ new Set();
const n = e.cfg;
if (e.key === "speechProviders") for (const e of [
n?.tts?.provider,
...Object.keys(n?.tts?.providers ?? {}),
n && resolveConfiguredTalkSpeechProviderId(n)
]) addStringValue(t, e);
if (e.includeVoiceModel) for (const e of resolveVoiceModelRefs(n?.agents?.defaults?.voiceModel)) addStringValue(t, e.provider);
if (e.key === "speechProviders") for (const e of Object.keys(n?.models?.providers ?? {})) addStringValue(t, e);
else if (e.key === "realtimeVoiceProviders") {
addStringValue(t, resolveConfiguredTalkRealtimeProviderId(n ?? {}));
return t.size > 0 ? t : void 0;
}
return t;
}
function shouldScopeCapabilityLoadToRequestedProviders(e) {
return capabilityCatalogFamilies.some((t) => t === e);
}
function* capabilityProviderIds(e) {
yield e.id.toLowerCase();
if (Array.isArray(e.aliases)) {
for (const t of e.aliases) if (typeof t === "string") yield t.toLowerCase();
}
}
function removeActiveProviderIds(e, t) {
for (const { provider: n } of t) for (const t of capabilityProviderIds(n)) e.delete(t);
}
function filterPolicyAllowedCapabilityProviders(e) {
if (!e.cfg?.plugins) return e.entries;
let t;
const n = new Map((e.registry?.plugins ?? []).map((e) => [e.id, e.origin]));
return e.entries.filter((r) => {
const i = n.get(r.pluginId) ?? (e.bundledPluginIds?.has(r.pluginId) ? "bundled" : "global");
return isManifestPluginOwnerAllowedByControlPlanePolicy({
plugin: {
id: r.pluginId,
origin: i
},
config: e.cfg,
normalizedConfig: t ??= normalizePluginsConfig(e.cfg?.plugins),
allowRestrictiveAllowlistBypass: e.key === "speechProviders" && e.cfg?.plugins?.enabled === false,
allowBundledProviderCompat: isBundledProviderCompatContract(e.key)
});
});
}
function selectActiveCapabilityProviders(e, t) {
const n = getPluginRuntimeGatewayRequestScope()?.pluginRegistry ?? getLoadedRuntimePluginRegistry();
const r = t?.(n);
return {
registry: n,
providers: projectCapabilityProviderEntries(filterPolicyAllowedCapabilityProviders({
...e,
entries: n?.[e.key] ?? [],
registry: n
}), r)
};
}
function prepareCapabilityProviderLoad(e, t) {
const n = new Set(e.loadOptions.onlyPluginIds);
const r = getPluginRuntimeGatewayRequestScope()?.pluginRegistry;
const i = r ? registryContainsRuntimePluginIds(r, e.loadOptions.onlyPluginIds) ? r : void 0 : getLoadedRuntimePluginRegistry({
env: e.loadOptions.env,
loadOptions: e.loadOptions,
workspaceDir: e.loadOptions.workspaceDir,
requiredPluginIds: e.loadOptions.onlyPluginIds
});
const a = t?.(i);
const filterAllowedEntries = (r) => {
const o = r === i ? a : t?.(r);
return projectCapabilityProviderEntries((r?.[e.key] ?? []).filter((e) => n.has(e.pluginId)), o);
};
const o = shouldScopeCapabilityLoadToRequestedProviders(e.key) ? e.key : void 0;
return {
loadOptions: e.loadOptions,
loadedRegistry: i,
resolveLoadOptions: () => ({
...e.loadOptions,
...o ? { capabilityCatalog: {
family: o,
context: resolvePluginCapabilityCatalogContext()
} } : {}
}),
merge(e, t) {
return mergeCapabilityProviderEntries(e, filterAllowedEntries(t));
},
filterAllowedEntries,
fallback(t) {
const n = filterAllowedEntries(t);
const r = e.requested && e.requested.size > 0 ? new Set(e.requested) : void 0;
if (r) removeActiveProviderIds(r, n);
if (n.length > 0 && (!r || r.size === 0)) return {
entries: n,
pluginIds: []
};
return {
entries: n,
pluginIds: e.bundledCompatPluginIds.filter((e) => !t?.plugins.some((t) => t.id === e && o && t.capabilityCatalog?.includes(o)))
};
}
};
}
function loadCapabilityProviderEntries(e) {
const t = e.loadedRegistry ?? resolveRuntimePluginRegistry(e.resolveLoadOptions());
const { entries: n, pluginIds: r } = e.fallback(t);
if (r.length === 0) return n;
const i = e.filterAllowedEntries(loadBundledCapabilityRuntimeRegistry({
...e.loadOptions,
pluginIds: r
}));
return n.length > 0 ? mergeCapabilityProviderEntries(n, i) : i;
}
function resolvePluginCapabilityProvider(e, t) {
const n = preparePluginCapabilityProviderLookup(e, t);
return n.resolve(n.load ? loadCapabilityProviderEntries(n.prepareLoad()) : []);
}
function preparePluginCapabilityProviderLookup(e, t) {
if (shouldSkipCapabilityResolution(e)) return {
load: void 0,
resolve: (e) => void 0
};
const n = /* @__PURE__ */ new WeakMap();
const r = t && ((e) => {
const r = t(e);
return r ? (e, t) => {
n.set(e, () => r(e, t));
return e;
} : void 0;
});
const selectProvider = (t) => {
const r = findCapabilityProviderEntry(t, e.providerId)?.provider;
return r ? n.get(r)?.() ?? r : void 0;
};
const { registry: i, providers: a } = selectActiveCapabilityProviders(e, r);
const o = selectProvider(a);
if (o) return {
load: void 0,
resolve: (e) => o
};
const s = resolveCapabilityLoadContext(i, e.cfg);
const c = prepareCapabilityPluginResolution({
cfg: e.cfg,
pluginMetadataSnapshot: s?.metadataSnapshot
});
let l = c(e.key, e.providerId);
if (l.runtimePluginIds.length === 0) {
l = c(e.key);
if (l.runtimePluginIds.length === 0) return {
load: void 0,
resolve: (e) => void 0
};
}
const u = createCapabilityLoad(e, l, s, /* @__PURE__ */ new Set([e.providerId.toLowerCase()]));
return {
load: u,
prepareLoad: () => prepareCapabilityProviderLoad(u, r),
resolve: selectProvider
};
}
function preparePluginCapabilityProviderResolution(e, t) {
if (shouldSkipCapabilityResolution(e)) return {
load: void 0,
resolve: (e) => []
};
const { registry: n, providers: r } = selectActiveCapabilityProviders(e, t);
const i = collectRequestedCapabilityProviderIds({
key: e.key,
cfg: e.cfg,
includeVoiceModel: r.length > 0
}) ?? /* @__PURE__ */ new Set();
const a = shouldMergeManifestProvidersWhenActive(e.key);
if (i.size > 0 || r.length > 0 && !a) for (const t of e.additionalProviderIds ?? []) addStringValue(i, t);
removeActiveProviderIds(i, r);
const o = i.size > 0 ? i : void 0;
if (r.length > 0 && !o && !a) return {
load: void 0,
resolve: (e) => r.map((e) => e.provider)
};
const s = o && shouldScopeCapabilityLoadToRequestedProviders(e.key) ? o : void 0;
const c = resolveCapabilityLoadContext(n, e.cfg);
const l = prepareCapabilityPluginResolution({
cfg: e.cfg,
pluginMetadataSnapshot: c?.metadataSnapshot
});
const u = s ? l(e.key, void 0, s) : void 0;
const d = o && (!shouldScopeCapabilityLoadToRequestedProviders(e.key) || u?.runtimePluginIds.length) ? o : void 0;
const f = createCapabilityLoad(e, u?.runtimePluginIds.length ? u : l(e.key), c, d);
return {
load: f,
prepareLoad: () => prepareCapabilityProviderLoad(f, t),
resolve: (e) => {
const t = r.length > 0 ? o : d;
const n = t ? e.filter(({ provider: e }) => {
for (const n of capabilityProviderIds(e)) if (t.has(n)) return true;
return false;
}) : e;
return mergeCapabilityProviderEntries(r, n).map((e) => e.provider);
}
};
}
function resolvePluginCapabilityProviders(e, t) {
const n = preparePluginCapabilityProviderResolution(e, t);
return n.resolve(n.load ? loadCapabilityProviderEntries(n.prepareLoad()) : []);
}
function prepareMediaCapabilityProviders(e) {
const t = prepareCapabilityPluginResolution(e);
const providers = (n) => {
if (shouldSkipCapabilityResolution({
key: n,
cfg: e.cfg
})) return [];
const r = t(n);
const i = r.runtimePluginIds;
if (i.length === 0 && e.pluginMetadataSnapshot.plugins.some((e) => hasManifestContractValue({
plugin: e,
contract: n
}))) return Object.freeze([]);
if (!e.registry || !registryContainsRuntimePluginIds(e.registry, i)) return;
const a = new Set(i);
const o = filterPolicyAllowedCapabilityProviders({
entries: e.registry[n],
registry: e.registry,
cfg: e.cfg,
key: n,
bundledPluginIds: new Set(r.bundledCompatPluginIds)
});
if (o.some((e) => !a.has(e.pluginId))) return;
return Object.freeze(o.map((e) => e.provider));
};
return Object.freeze({
mediaUnderstandingProviders: providers("mediaUnderstandingProviders"),
imageGenerationProviders: providers("imageGenerationProviders"),
videoGenerationProviders: providers("videoGenerationProviders"),
musicGenerationProviders: providers("musicGenerationProviders")
});
}
//#endregion
export { resolvePluginCapabilityProviders as a, providerMatchesId as c, resolveVoiceModelRefs as d, resolveVoiceProviderCandidates as f, resolvePluginCapabilityProvider as i, resolvePrimaryVoiceProviderCandidate as l, preparePluginCapabilityProviderLookup as n, acquireBundledCapabilityRuntimeRegistry as o, voiceProviderSupportsModel as p, preparePluginCapabilityProviderResolution as r, getVoiceProviderConfig as s, prepareMediaCapabilityProviders as t, resolveSupportedVoiceModelRefs as u };