UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

61 lines (60 loc) • 2.88 kB
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs"; import { a as asOptionalRecord, p as readStringField } from "./record-coerce-CVPuDqcc.mjs"; import { n as assertOkOrThrowHttpError } from "./provider-http-errors-Dtgw3x-5.mjs"; import { p as sanitizeConfiguredModelProviderRequest } from "./provider-request-config-CCij-nof.mjs"; import "./string-coerce-runtime-BwAZZDf5.mjs"; import { t as executeProviderOperationWithRetry } from "./operation-retry-CNR4uE0x.mjs"; import { c as fetchWithTimeoutGuarded } from "./shared-CfcMLHIP.mjs"; import { t as resolveProviderApiKeyHttpRequestConfig } from "./provider-http-LcawLneq.mjs"; //#region extensions/minimax/media-provider-runtime.ts const DEFAULT_MINIMAX_MEDIA_BASE_URL = "https://api.minimax.io"; function resolveMinimaxMediaBaseUrl(e, t) { const n = normalizeOptionalString(e?.models?.providers?.[t]?.baseUrl); return new URL(n ?? DEFAULT_MINIMAX_MEDIA_BASE_URL).origin; } async function resolveMinimaxMediaRequestConfig(e) { return resolveProviderApiKeyHttpRequestConfig({ req: e, missingApiKeyMessage: "MiniMax API key missing", jsonContentType: e.capability !== "audio", baseUrl: e.baseUrl ?? resolveMinimaxMediaBaseUrl(e.cfg, e.providerId), defaultBaseUrl: DEFAULT_MINIMAX_MEDIA_BASE_URL, provider: e.providerId, capability: e.capability, request: sanitizeConfiguredModelProviderRequest(e.cfg?.models?.providers?.[e.providerId]?.request) }); } function assertMinimaxBaseResp(e, t) { const n = asOptionalRecord(e); if (n && typeof n.status_code === "number" && n.status_code !== 0) throw new Error(`${t} (${n.status_code}): ${readStringField(n, "status_msg") ?? "unknown error"}`); } function normalizeMinimaxHexAudio(e, t) { const n = e.trim(); if (!/^[0-9a-f]+$/iu.test(n) || n.length % 2 !== 0) throw new Error(`${t} returned malformed hex audio`); return n; } function resolveMinimaxGuardedRequestOptions(e) { return e.allowPrivateNetwork || e.dispatcherPolicy ? { ...e.allowPrivateNetwork ? { ssrfPolicy: { allowPrivateNetwork: true } } : {}, ...e.dispatcherPolicy ? { dispatcherPolicy: e.dispatcherPolicy } : {} } : void 0; } async function fetchMinimaxResponse(e) { return await executeProviderOperationWithRetry({ provider: "minimax", stage: e.stage, operation: async () => { const t = typeof e.timeoutMs === "function" ? e.timeoutMs() : e.timeoutMs; const n = await fetchWithTimeoutGuarded(e.url, e.init ?? {}, typeof t === "number" && Number.isFinite(t) && t > 0 ? t : void 0, fetch, resolveMinimaxGuardedRequestOptions(e.policy)); try { await assertOkOrThrowHttpError(n.response, e.requestFailedMessage); } catch (e) { await n.release(); throw e; } return n; } }); } //#endregion export { resolveMinimaxMediaRequestConfig as i, fetchMinimaxResponse as n, normalizeMinimaxHexAudio as r, assertMinimaxBaseResp as t };