UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

65 lines (64 loc) • 2.37 kB
import { c as normalizeOptionalLowercaseString, l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs"; import { c as asFiniteNumberInRange, w as parseStrictFiniteNumber } from "./number-coercion-D6u-4YD8.mjs"; import { rmSync } from "node:fs"; //#region src/tts/tts-provider-helpers.ts const TEMP_FILE_CLEANUP_DELAY_MS = 3e5; /** Resolve the first non-blank API key in provider-defined precedence order. */ function resolveSpeechProviderApiKey(...e) { for (const t of e) { const e = normalizeOptionalString(t); if (e) return e; } } function requireInRange(e, t, n, r) { if (!Number.isFinite(e) || e < t || e > n) throw new Error(`${r} must be between ${t} and ${n}`); } function normalizeLanguageCode(e) { const t = normalizeOptionalLowercaseString(e); if (!t) return; if (!/^[a-z]{2}$/.test(t)) throw new Error("languageCode must be a 2-letter ISO 639-1 code (e.g. en, de, fr)"); return t; } function normalizeApplyTextNormalization(e) { const t = normalizeOptionalLowercaseString(e); if (!t) return; if (t === "auto" || t === "on" || t === "off") return t; throw new Error("applyTextNormalization must be one of: auto, on, off"); } function normalizeSeed(e) { if (e == null) return; const t = Math.floor(e); if (!Number.isFinite(t) || t < 0 || t > 4294967295) throw new Error("seed must be between 0 and 4294967295"); return t; } function scheduleCleanup(e, t = TEMP_FILE_CLEANUP_DELAY_MS) { setTimeout(() => { try { rmSync(e, { recursive: true, force: true }); } catch {} }, t).unref(); } //#endregion //#region src/tts/directive-number.ts /** Parse a numeric speech directive token and return provider overrides when policy allows it. */ function parseSpeechDirectiveNumberOverride(e) { if (!e.ctx.policy.allowVoiceSettings) return { handled: true }; const t = parseStrictFiniteNumber(e.ctx.value); if (t === void 0 || asFiniteNumberInRange(t, e.range) === void 0) return { handled: true, warnings: [e.warning(e.ctx.value)] }; const n = { [e.overrideKey]: t }; return { handled: true, overrides: e.mergeCurrentOverrides ? { ...e.ctx.currentOverrides, ...n } : n }; } //#endregion export { requireInRange as a, normalizeSeed as i, normalizeApplyTextNormalization as n, resolveSpeechProviderApiKey as o, normalizeLanguageCode as r, scheduleCleanup as s, parseSpeechDirectiveNumberOverride as t };