UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

26 lines (25 loc) • 1.24 kB
import { describeRejectedValue } from "../core/tool-search-setting.js"; export const PROMPT_CACHE_KEY_WIRE = "prompt_cache_key"; const CARRYING_API = "openai-completions"; export function promptCacheKeyDefect(model) { const compat = model.compat; if (compat === null || typeof compat !== "object") return undefined; const declared = compat.sendPromptCacheKey; if (declared === undefined || declared === false) return undefined; if (declared !== true) return `compat.sendPromptCacheKey must be true or false when present (got ${describeRejectedValue(declared)})`; if (model.api !== CARRYING_API) return `compat.sendPromptCacheKey is true on an entry whose api is "${String(model.api)}" — only "${CARRYING_API}" sends a prompt-cache key; drop the member there`; return undefined; } export function sendsPromptCacheKey(model) { return model.api === CARRYING_API && model.compat?.sendPromptCacheKey === true; } export function hopOptionsWithCacheKey(sent, options) { if (options === undefined || !Object.hasOwn(options, "promptCacheKey") || sendsPromptCacheKey(sent)) return options; const { promptCacheKey: _dropped, ...rest } = options; return rest; }