openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
48 lines (47 loc) • 2.42 kB
JavaScript
import { o as normalizeLowercaseStringOrEmpty } from "./string-coerce-1VuiLaaR.mjs";
import { r as resolveAnthropicCacheRetentionFamily } from "./anthropic-family-cache-semantics-DIqapvPE.mjs";
import { resolveOpenAIPromptCacheKeySupport } from "@openclaw/ai/transports";
//#region src/agents/embedded-agent-runner/prompt-cache-retention.ts
/**
* Resolves provider/model prompt-cache retention behavior.
*/
function resolveExplicitCachedContent(extraParams) {
return (typeof extraParams?.cachedContent === "string" ? extraParams.cachedContent : typeof extraParams?.cached_content === "string" ? extraParams.cached_content : void 0)?.trim() || void 0;
}
function parseCacheRetention(value) {
return value === "none" || value === "short" || value === "long" ? value : void 0;
}
function isGooglePromptCacheEligible(params) {
if (params.modelApi !== "google-generative-ai") return false;
const normalizedModelId = normalizeLowercaseStringOrEmpty(params.modelId);
return normalizedModelId.startsWith("gemini-2.5") || normalizedModelId.startsWith("gemini-3");
}
function resolveCacheRetention(extraParams, provider, modelApi, modelId, compat, baseUrl) {
const hasExplicitCacheConfig = extraParams?.cacheRetention !== void 0 || extraParams?.cacheControlTtl !== void 0;
const family = resolveAnthropicCacheRetentionFamily({
provider,
modelApi,
modelId,
hasExplicitCacheConfig
});
const openAIEligible = (modelApi === "openai-responses" || modelApi === "openai-chatgpt-responses" || modelApi === "openai-completions") && resolveOpenAIPromptCacheKeySupport({
provider,
api: modelApi,
baseUrl,
compat
});
const googleEligible = isGooglePromptCacheEligible({
modelApi,
modelId
});
const compatEligible = compat?.supportsPromptCacheKey === true || compat?.cacheControlFormat === "anthropic";
if (!family && !googleEligible && !openAIEligible && !compatEligible && !(modelApi === "bedrock-converse-stream")) return;
const newVal = parseCacheRetention(extraParams?.cacheRetention);
if (newVal) return newVal;
const legacy = extraParams?.cacheControlTtl;
if (legacy === "5m" && (family || googleEligible)) return "short";
if (legacy === "1h" && (family || googleEligible)) return "long";
return family === "anthropic-direct" ? "short" : void 0;
}
//#endregion
export { resolveExplicitCachedContent as i, parseCacheRetention as n, resolveCacheRetention as r, isGooglePromptCacheEligible as t };