UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

141 lines (140 loc) • 4.48 kB
import { E as hasLegacyAccountStreamingAliases, L as asNullableRecord, O as normalizeChannelAccounts, a as defineChannelAliasMigration, o as stripRetiredChannelKeys } from "./runtime-doctor-migrations-JGL9tD-z.js"; //#region src/talk/activation-name.ts const REALTIME_VOICE_ACTIVATION_NAME_MAX_WORDS = 2; /** Extract the supported leading activation-name prefix from a longer phrase. */ function normalizeRealtimeVoiceActivationNamePrefix(e, t = REALTIME_VOICE_ACTIVATION_NAME_MAX_WORDS) { const n = Array.from(e.matchAll(/[a-z0-9]+/gi), (e) => e[0]); if (n.length === 0) return; return n.slice(0, t).join(" "); } function isSupportedRealtimeVoiceActivationName(e, t = REALTIME_VOICE_ACTIVATION_NAME_MAX_WORDS) { const n = Array.from(e.matchAll(/[a-z0-9]+/gi)).length; return n >= 1 && n <= t; } //#endregion //#region extensions/discord/src/doctor-contract.ts const RETIRED_TUNING_KEYS = /* @__PURE__ */ new Set([ "gatewayInfoTimeoutMs", "gatewayReadyTimeoutMs", "gatewayRuntimeReadyTimeoutMs", "eventQueue", "retry" ]); const streamingAliasMigration = defineChannelAliasMigration({ channelId: "discord", streaming: { defaultMode: "progress", includePreviewChunk: true }, accountStreamingReplacesRoot: true, dm: { root: true, accounts: true } }); function hasUnsupportedDiscordRealtimeWakeNames(e) { const t = asNullableRecord(asNullableRecord(e)?.voice); const n = asNullableRecord(t?.realtime)?.wakeNames; return Array.isArray(n) ? n.length === 0 || n.some((e) => typeof e === "string" && !isSupportedRealtimeVoiceActivationName(e)) : false; } function normalizeUnsupportedRealtimeWakeNames(e, t, n) { const r = asNullableRecord(e.voice); const i = asNullableRecord(r?.realtime); const a = i?.wakeNames; if (!r || !i || !Array.isArray(a)) return { entry: e, changed: false }; let o = 0; let s = 0; const c = a.flatMap((e) => { if (typeof e !== "string" || isSupportedRealtimeVoiceActivationName(e)) return [e]; const t = normalizeRealtimeVoiceActivationNamePrefix(e); if (!t) { s += 1; return []; } o += 1; return [t]; }); if (a.length > 0 && o === 0 && s === 0) return { entry: e, changed: false }; const l = Array.from(new Set(c)); if (a.length === 0) n.push(`Removed empty ${t}.voice.realtime.wakeNames; unset wake names use the default agent/OpenClaw fallback.`); const u = { ...i }; if (l.length > 0) u.wakeNames = l; else delete u.wakeNames; if (o > 0) n.push(`Shortened ${o} unsupported ${t}.voice.realtime.wakeNames entries to one or two words.`); if (s > 0) n.push(`Removed ${s} unsupported ${t}.voice.realtime.wakeNames entries with no usable words.`); return { entry: { ...e, voice: { ...r, realtime: u } }, changed: true }; } const legacyConfigRules = [ { path: ["channels", "discord"], message: "channels.discord.voice.realtime.wakeNames entries longer than two words are unsupported; use one- or two-word activation names. Run \"openclaw doctor --fix\".", match: hasUnsupportedDiscordRealtimeWakeNames }, { path: [ "channels", "discord", "accounts" ], message: "channels.discord.accounts.<id>.voice.realtime.wakeNames entries longer than two words are unsupported; use one- or two-word activation names. Run \"openclaw doctor --fix\".", match: (e) => hasLegacyAccountStreamingAliases(e, hasUnsupportedDiscordRealtimeWakeNames) }, ...streamingAliasMigration.legacyConfigRules ]; function normalizeCompatibilityConfig({ cfg: e }) { const t = []; const n = streamingAliasMigration.normalizeChannelConfig({ cfg: e, changes: t }); const r = stripRetiredChannelKeys({ cfg: n.config, channelId: "discord", keys: RETIRED_TUNING_KEYS, scope: "root-and-accounts" }); const i = asNullableRecord(r.config.channels?.discord); if (!i) return { config: e, changes: [] }; if (r.changed) t.push("Removed retired Discord tuning knobs."); const a = normalizeChannelAccounts({ entry: i, pathPrefix: "channels.discord", changes: t, normalizeAccount: ({ account: e, pathPrefix: t, changes: n }) => normalizeUnsupportedRealtimeWakeNames(e, t, n) }); const o = normalizeUnsupportedRealtimeWakeNames(a.entry, "channels.discord", t); if (r.config === e && !a.changed && !o.changed) return { config: e, changes: [] }; return { config: { ...r.config, channels: { ...r.config.channels, discord: o.entry } }, changes: t }; } //#endregion export { legacyConfigRules, normalizeCompatibilityConfig };