@@ -22,12 +22,19 @@ interface AnthropicCacheablePayload {
2222 * Marks the static request prefix (system prompt + tools) with an ephemeral
2323 * cache breakpoint when {@link shouldCacheStaticPrefix} deems it worthwhile, so
2424 * repeated calls reuse the cached prefix. Mutates `payload.system` (string → a
25- * single cached text block) and the last entry of `tools` in place.
25+ * single cached text block) and the last entry of `tools` in place; a no-op when
26+ * the prefix is too small or not present. Call after any structured-output
27+ * mutation of `payload.system`, since it may replace the string with a block array.
2628 *
27- * `systemPrompt` is the ORIGINAL request system prompt, used only for the
28- * worthiness gate: on the no-messages path the provider relocates the system
29- * text into a user message and blanks `payload.system`, but the tools prefix is
30- * still worth caching there.
29+ * The worthiness gate is sized on the LARGER of the final `payload.system`
30+ * (which may include appended structured-output schema text) and the original
31+ * `systemPrompt` (non-empty even when the no-messages path relocates the system
32+ * text into a user message and blanks `payload.system` — the tools prefix is
33+ * still worth caching there).
34+ *
35+ * @param payload - Anthropic request payload; `system` is mutated in place.
36+ * @param tools - Anthropic tool definitions; the last entry is mutated in place.
37+ * @param systemPrompt - The original request system prompt, used only for sizing.
3138 */
3239export function applyAnthropicPromptCache (
3340 payload : AnthropicCacheablePayload ,
@@ -36,9 +43,6 @@ export function applyAnthropicPromptCache(
3643) : void {
3744 const payloadSystem = typeof payload . system === 'string' ? payload . system : ''
3845
39- // Size the gate on the LARGER of the final payload.system (which may include
40- // appended structured-output schema text) and the original request prompt
41- // (non-empty even when the no-messages path relocates it out of payload.system).
4246 const gateSystem =
4347 payloadSystem . length >= ( systemPrompt ?. length ?? 0 ) ? payloadSystem : systemPrompt
4448
0 commit comments