UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

78 lines (77 loc) • 3.51 kB
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs"; import "./string-coerce-runtime-BwAZZDf5.mjs"; //#region extensions/google/src/google-api-base-url.ts const DEFAULT_GOOGLE_API_BASE_URL = "https://generativelanguage.googleapis.com/v1beta"; function trimTrailingSlashes(e) { return e.replace(/\/+$/, ""); } function isGoogleGenerativeAiUrl(e) { return e.protocol === "https:" && e.hostname.toLowerCase() === "generativelanguage.googleapis.com"; } /** Exact official AI Studio request root eligible for native provider behavior. */ function isOfficialGoogleAiStudioBaseUrl(e) { const t = normalizeOptionalString(e) ?? "https://generativelanguage.googleapis.com/v1beta"; const n = URL.parse(t); const r = n ? trimTrailingSlashes(n.href) : void 0; return r === "https://generativelanguage.googleapis.com" || r === "https://generativelanguage.googleapis.com/v1beta"; } const GOOGLE_VERTEX_HOST = "aiplatform.googleapis.com"; const GOOGLE_VERTEX_REGION_HOST_SUFFIX = "-aiplatform.googleapis.com"; const GOOGLE_VERTEX_MULTI_REGION_HOSTS = /* @__PURE__ */ new Set(["aiplatform.eu.rep.googleapis.com", "aiplatform.us.rep.googleapis.com"]); function isGoogleVertexHostname(e) { const t = e.toLowerCase(); return t === GOOGLE_VERTEX_HOST || t.endsWith(GOOGLE_VERTEX_REGION_HOST_SUFFIX) || GOOGLE_VERTEX_MULTI_REGION_HOSTS.has(t); } function resolveGoogleVertexBaseUrlLocation(e) { const t = normalizeOptionalString(e); if (!t || t.includes("{location}")) return; const n = URL.parse(t); if (!n || !isGoogleVertexHostname(n.hostname)) return; if (n.hostname === GOOGLE_VERTEX_HOST) return "global"; return GOOGLE_VERTEX_MULTI_REGION_HOSTS.has(n.hostname) ? n.hostname.split(".")[1] : n.hostname.slice(0, -26); } function isGoogleVertexBaseUrl(e) { const t = normalizeOptionalString(e); if (!t) return false; const n = URL.parse(t); return n !== null && isGoogleVertexHostname(n.hostname); } function normalizeGoogleApiBaseUrl(e) { const t = trimTrailingSlashes(normalizeOptionalString(e) || "https://generativelanguage.googleapis.com/v1beta"); const n = URL.parse(t); if (!n) return t; n.hash = ""; n.search = ""; n.username = ""; n.password = ""; if (isGoogleGenerativeAiUrl(n)) n.pathname = trimTrailingSlashes(n.pathname || "") || "/v1beta"; return trimTrailingSlashes(n.toString()); } function isGoogleGenerativeAiApi(e) { return e === "google-generative-ai"; } function normalizeGoogleGenerativeAiBaseUrl(e) { const t = normalizeOptionalString(e); if (!t) return; const n = normalizeGoogleApiBaseUrl(t); const r = URL.parse(n); if (r) { if (isGoogleGenerativeAiUrl(r)) { r.pathname = trimTrailingSlashes(r.pathname || "").replace(/\/openai$/i, "") || "/v1beta"; return trimTrailingSlashes(r.toString()); } } return n; } /** Keep configured API version paths intact instead of appending the SDK default. */ function resolveGoogleGenerativeAiSdkHttpOptions(e) { const t = normalizeGoogleGenerativeAiBaseUrl(e); if (!t) return { apiVersion: "v1beta" }; const n = URL.parse(t)?.pathname ?? t; return { baseUrl: t, apiVersion: /(?:^|\/)v\d+(?:(?:alpha|beta)\d*)?(?:\/|$)/i.test(n) ? "" : "v1beta" }; } //#endregion export { isOfficialGoogleAiStudioBaseUrl as a, resolveGoogleGenerativeAiSdkHttpOptions as c, isGoogleVertexHostname as i, resolveGoogleVertexBaseUrlLocation as l, isGoogleGenerativeAiApi as n, normalizeGoogleApiBaseUrl as o, isGoogleVertexBaseUrl as r, normalizeGoogleGenerativeAiBaseUrl as s, DEFAULT_GOOGLE_API_BASE_URL as t };