openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
103 lines (102 loc) • 5.31 kB
JavaScript
import { c as isRecord } from "./record-coerce-DItp3I4t.js";
import { c as normalizeOptionalLowercaseString } from "./string-coerce-CIXf7egm.js";
import { i as listAgentEntries } from "./agent-scope-config-DcbEhP0R.js";
import { o as resolveConfiguredTalkSpeechProviderId } from "./talk-DRVl_bf5.js";
import { n as resolveEffectiveTtsConfig } from "./tts-config-lx8wBLdc.js";
//#region src/plugins/gateway-startup-speech-providers.ts
const TTS_PROVIDER_CONFIG_RESERVED_KEYS = /* @__PURE__ */ new Set([
"auto",
"enabled",
"maxTextLength",
"mode",
"modelOverrides",
"persona",
"personas",
"prefsPath",
"provider",
"providers",
"summaryModel",
"timeoutMs"
]);
/** Treats missing activation as enabled while honoring explicit false values. */
function isConfigActivationValueEnabled(value) {
if (value === false) return false;
if (isRecord(value) && value.enabled === false) return false;
return true;
}
/** Normalizes configured TTS provider ids for startup plugin selection. */
function normalizeConfiguredSpeechProviderIdForStartup(value) {
const normalized = normalizeOptionalLowercaseString(value);
return normalized === "edge" ? "microsoft" : normalized;
}
/** Resolves provider activation from both canonical providers maps and legacy root keys. */
function resolveProviderConfigActivation(ttsConfig, providerId) {
let fromProviders;
if (isRecord(ttsConfig.providers)) {
for (const [key, providerConfig] of Object.entries(ttsConfig.providers)) if (normalizeConfiguredSpeechProviderIdForStartup(key) === providerId) fromProviders = isConfigActivationValueEnabled(providerConfig);
}
if (fromProviders !== void 0) return fromProviders;
for (const [key, providerConfig] of Object.entries(ttsConfig)) {
if (TTS_PROVIDER_CONFIG_RESERVED_KEYS.has(key) || !isRecord(providerConfig)) continue;
if (normalizeConfiguredSpeechProviderIdForStartup(key) === providerId) return isConfigActivationValueEnabled(providerConfig);
}
}
function addProviderIfEnabled(target, ttsConfig, providerId) {
const normalized = normalizeConfiguredSpeechProviderIdForStartup(providerId);
if (!normalized) return;
if (resolveProviderConfigActivation(ttsConfig, normalized) !== false) target.add(normalized);
}
function findActivePersona(ttsConfig) {
const personaId = normalizeOptionalLowercaseString(typeof ttsConfig.persona === "string" ? ttsConfig.persona : void 0);
if (!personaId || !isRecord(ttsConfig.personas)) return;
for (const [id, persona] of Object.entries(ttsConfig.personas)) if (normalizeOptionalLowercaseString(id) === personaId && isRecord(persona)) return persona;
}
function addActivePersonaProvider(target, ttsConfig) {
const persona = findActivePersona(ttsConfig);
if (!persona) return;
const provider = normalizeConfiguredSpeechProviderIdForStartup(persona.provider);
if (!provider) return;
const rootActivation = resolveProviderConfigActivation(ttsConfig, provider);
if ((resolveProviderConfigActivation(persona, provider) ?? rootActivation) !== false) target.add(provider);
}
function addConfiguredTtsProviderIds(target, value) {
if (!isRecord(value)) return;
addProviderIfEnabled(target, value, value.provider);
addActivePersonaProvider(target, value);
if (isRecord(value.providers)) {
for (const [providerId, providerConfig] of Object.entries(value.providers)) if (isConfigActivationValueEnabled(providerConfig)) addProviderIfEnabled(target, value, providerId);
}
for (const [key, providerConfig] of Object.entries(value)) {
if (TTS_PROVIDER_CONFIG_RESERVED_KEYS.has(key) || !isRecord(providerConfig)) continue;
if (isConfigActivationValueEnabled(providerConfig)) addProviderIfEnabled(target, value, key);
}
}
/** Collects active Talk and TTS provider ids across root, agent, channel, and plugin config. */
function collectConfiguredSpeechProviderIds(config) {
const configured = /* @__PURE__ */ new Set();
addConfiguredTtsProviderIds(configured, resolveEffectiveTtsConfig(config));
const talkProviderId = resolveConfiguredTalkSpeechProviderId(config);
if (talkProviderId) configured.add(talkProviderId.toLowerCase());
for (const agent of listAgentEntries(config)) addConfiguredTtsProviderIds(configured, resolveEffectiveTtsConfig(config, { agentId: agent.id }));
const channels = config.channels;
if (isRecord(channels)) for (const [channelId, channelConfig] of Object.entries(channels)) {
if (!isRecord(channelConfig)) continue;
addConfiguredTtsProviderIds(configured, resolveEffectiveTtsConfig(config, { channelId }));
if (isRecord(channelConfig.voice)) addConfiguredTtsProviderIds(configured, channelConfig.voice.tts);
if (isRecord(channelConfig.accounts)) for (const [accountId, accountConfig] of Object.entries(channelConfig.accounts)) {
if (!isRecord(accountConfig)) continue;
addConfiguredTtsProviderIds(configured, resolveEffectiveTtsConfig(config, {
channelId,
accountId
}));
if (isRecord(accountConfig.voice)) addConfiguredTtsProviderIds(configured, accountConfig.voice.tts);
}
}
const pluginEntries = config.plugins?.entries;
if (isRecord(pluginEntries)) {
for (const entry of Object.values(pluginEntries)) if (isRecord(entry) && isRecord(entry.config)) addConfiguredTtsProviderIds(configured, entry.config.tts);
}
return configured;
}
//#endregion
export { collectConfiguredSpeechProviderIds as t };