UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

49 lines (48 loc) 2 kB
import { c as normalizeOptionalString } from "./string-coerce-mnp54Vah.js"; import { o as coerceSecretRef } from "./types.secrets-_0JOMGE5.js"; import { g as resolveNonEnvSecretRefApiKeyMarker } from "./model-auth-markers-Sq8HdQFX.js"; import "./string-coerce-runtime-CEGJWkQ_.js"; import "./provider-auth-DAOC_qI9.js"; import { a as resolveCloudflareAiGatewayBaseUrl, i as buildCloudflareAiGatewayModelDefinition } from "./models-Ds0snX1K.js"; //#region extensions/cloudflare-ai-gateway/catalog-provider.ts /** * Builds runtime model catalog entries from stored Cloudflare AI Gateway auth * profiles. */ function resolveCloudflareAiGatewayApiKey(cred) { if (!cred || cred.type !== "api_key") return; const keyRef = coerceSecretRef(cred.keyRef); const keyRefId = normalizeOptionalString(keyRef?.id); if (keyRef && keyRefId) return keyRef.source === "env" ? keyRefId : resolveNonEnvSecretRefApiKeyMarker(keyRef.source); return normalizeOptionalString(cred.key); } function resolveCloudflareAiGatewayMetadata(cred) { if (!cred || cred.type !== "api_key") return {}; return { accountId: normalizeOptionalString(cred.metadata?.accountId), gatewayId: normalizeOptionalString(cred.metadata?.gatewayId) }; } /** * Returns a provider catalog entry when credentials and Gateway metadata are * complete enough to construct an Anthropic-compatible base URL. */ function buildCloudflareAiGatewayCatalogProvider(params) { const apiKey = normalizeOptionalString(params.envApiKey) ?? resolveCloudflareAiGatewayApiKey(params.credential); if (!apiKey) return null; const { accountId, gatewayId } = resolveCloudflareAiGatewayMetadata(params.credential); if (!accountId || !gatewayId) return null; const baseUrl = resolveCloudflareAiGatewayBaseUrl({ accountId, gatewayId }); if (!baseUrl) return null; return { baseUrl, api: "anthropic-messages", apiKey, models: [buildCloudflareAiGatewayModelDefinition()] }; } //#endregion export { buildCloudflareAiGatewayCatalogProvider as t };