From 02cb7e7b71c560fb29d36f0bd56149ab6a5fa3ee Mon Sep 17 00:00:00 2001 From: "opencode-agent[bot]" Date: Mon, 11 May 2026 02:11:07 +0000 Subject: [PATCH] chore: generate --- packages/llm/README.md | 12 ++++++------ packages/llm/src/cache-policy.ts | 15 +++------------ packages/llm/src/schema/options.ts | 6 +----- packages/llm/test/cache-policy.test.ts | 6 +----- ...ds-cache-control-on-identical-second-call.json | 7 +------ ...ontenttokencount-on-identical-second-call.json | 7 +------ ...ts-cached-tokens-on-identical-second-call.json | 7 +------ 7 files changed, 14 insertions(+), 46 deletions(-) diff --git a/packages/llm/README.md b/packages/llm/README.md index 434ce369f8..e164c4bf53 100644 --- a/packages/llm/README.md +++ b/packages/llm/README.md @@ -82,12 +82,12 @@ LLM.request({ ### Provider behavior table -| Protocol | `cache: "auto"` | -|---|---| -| Anthropic Messages | emits up to 3 `cache_control` markers (4-breakpoint cap enforced) | -| Bedrock Converse | emits up to 3 `cachePoint` blocks (4-breakpoint cap enforced) | -| OpenAI Chat / Responses | no-op (implicit caching above 1024 tokens) | -| Gemini | no-op (implicit caching on 2.5+; explicit `CachedContent` is out-of-band) | +| Protocol | `cache: "auto"` | +| ----------------------- | ------------------------------------------------------------------------- | +| Anthropic Messages | emits up to 3 `cache_control` markers (4-breakpoint cap enforced) | +| Bedrock Converse | emits up to 3 `cachePoint` blocks (4-breakpoint cap enforced) | +| OpenAI Chat / Responses | no-op (implicit caching above 1024 tokens) | +| Gemini | no-op (implicit caching on 2.5+; explicit `CachedContent` is out-of-band) | Normalized cache usage is read back into `response.usage.cacheReadInputTokens` and `cacheWriteInputTokens` across every provider. diff --git a/packages/llm/src/cache-policy.ts b/packages/llm/src/cache-policy.ts index 46d924ab52..b9dca4e88f 100644 --- a/packages/llm/src/cache-policy.ts +++ b/packages/llm/src/cache-policy.ts @@ -44,10 +44,7 @@ const RESPECTS_INLINE_HINTS = new Set(["anthropic-messages", "bedrock-converse"] const makeHint = (ttlSeconds: number | undefined): CacheHint => ttlSeconds !== undefined ? new CacheHint({ type: "ephemeral", ttlSeconds }) : new CacheHint({ type: "ephemeral" }) -const markLastTool = ( - tools: ReadonlyArray, - hint: CacheHint, -): ReadonlyArray => { +const markLastTool = (tools: ReadonlyArray, hint: CacheHint): ReadonlyArray => { if (tools.length === 0) return tools const last = tools.length - 1 if (tools[last]!.cache) return tools @@ -67,11 +64,7 @@ const lastIndexOfRole = (messages: ReadonlyArray, role: Message["role"] // Mark the last text part of `messages[index]`. If no text part exists, mark // the last content part regardless of type — that's the breakpoint position // in tool-result-only messages too. -const markMessageAt = ( - messages: ReadonlyArray, - index: number, - hint: CacheHint, -): ReadonlyArray => { +const markMessageAt = (messages: ReadonlyArray, index: number, hint: CacheHint): ReadonlyArray => { if (index < 0 || index >= messages.length) return messages const target = messages[index]! if (target.content.length === 0) return messages @@ -79,9 +72,7 @@ const markMessageAt = ( const markAt = lastTextIndex >= 0 ? lastTextIndex : target.content.length - 1 const existing = target.content[markAt]! if ("cache" in existing && existing.cache) return messages - const nextContent = target.content.map((part, i) => - i === markAt ? ({ ...part, cache: hint } as ContentPart) : part, - ) + const nextContent = target.content.map((part, i) => (i === markAt ? ({ ...part, cache: hint } as ContentPart) : part)) const next = new Message({ ...target, content: nextContent }) // Single pass over `messages`, substituting the one updated entry. Long // conversations call this on every request, so avoid `.map()` here — its diff --git a/packages/llm/src/schema/options.ts b/packages/llm/src/schema/options.ts index cead47ee44..0f40196f7d 100644 --- a/packages/llm/src/schema/options.ts +++ b/packages/llm/src/schema/options.ts @@ -226,9 +226,5 @@ export const CachePolicyObject = Schema.Struct({ }) export type CachePolicyObject = Schema.Schema.Type -export const CachePolicy = Schema.Union([ - Schema.Literal("auto"), - Schema.Literal("none"), - CachePolicyObject, -]) +export const CachePolicy = Schema.Union([Schema.Literal("auto"), Schema.Literal("none"), CachePolicyObject]) export type CachePolicy = Schema.Schema.Type diff --git a/packages/llm/test/cache-policy.test.ts b/packages/llm/test/cache-policy.test.ts index 5cc931fbed..640556105e 100644 --- a/packages/llm/test/cache-policy.test.ts +++ b/packages/llm/test/cache-policy.test.ts @@ -56,11 +56,7 @@ describe("applyCachePolicy", () => { model: anthropicModel, system: "Sys A", tools: [{ name: "t1", description: "t1", inputSchema: { type: "object", properties: {} } }], - messages: [ - LLM.user("first user"), - LLM.assistant("assistant reply"), - LLM.user("latest user message"), - ], + messages: [LLM.user("first user"), LLM.assistant("assistant reply"), LLM.user("latest user message")], cache: "auto", }), ) diff --git a/packages/llm/test/fixtures/recordings/anthropic-messages-cache/writes-then-reads-cache-control-on-identical-second-call.json b/packages/llm/test/fixtures/recordings/anthropic-messages-cache/writes-then-reads-cache-control-on-identical-second-call.json index 697faea283..8cf2be05c1 100644 --- a/packages/llm/test/fixtures/recordings/anthropic-messages-cache/writes-then-reads-cache-control-on-identical-second-call.json +++ b/packages/llm/test/fixtures/recordings/anthropic-messages-cache/writes-then-reads-cache-control-on-identical-second-call.json @@ -3,12 +3,7 @@ "metadata": { "name": "anthropic-messages-cache/writes-then-reads-cache-control-on-identical-second-call", "recordedAt": "2026-05-11T01:52:54.319Z", - "tags": [ - "prefix:anthropic-messages-cache", - "provider:anthropic", - "protocol:anthropic-messages", - "cache" - ] + "tags": ["prefix:anthropic-messages-cache", "provider:anthropic", "protocol:anthropic-messages", "cache"] }, "interactions": [ { diff --git a/packages/llm/test/fixtures/recordings/gemini-cache/reports-cachedcontenttokencount-on-identical-second-call.json b/packages/llm/test/fixtures/recordings/gemini-cache/reports-cachedcontenttokencount-on-identical-second-call.json index 55c7c6c321..0145756887 100644 --- a/packages/llm/test/fixtures/recordings/gemini-cache/reports-cachedcontenttokencount-on-identical-second-call.json +++ b/packages/llm/test/fixtures/recordings/gemini-cache/reports-cachedcontenttokencount-on-identical-second-call.json @@ -3,12 +3,7 @@ "metadata": { "name": "gemini-cache/reports-cachedcontenttokencount-on-identical-second-call", "recordedAt": "2026-05-11T01:55:40.600Z", - "tags": [ - "prefix:gemini-cache", - "provider:google", - "protocol:gemini", - "cache" - ] + "tags": ["prefix:gemini-cache", "provider:google", "protocol:gemini", "cache"] }, "interactions": [ { diff --git a/packages/llm/test/fixtures/recordings/openai-responses-cache/reports-cached-tokens-on-identical-second-call.json b/packages/llm/test/fixtures/recordings/openai-responses-cache/reports-cached-tokens-on-identical-second-call.json index a9e7acbba0..25b561197c 100644 --- a/packages/llm/test/fixtures/recordings/openai-responses-cache/reports-cached-tokens-on-identical-second-call.json +++ b/packages/llm/test/fixtures/recordings/openai-responses-cache/reports-cached-tokens-on-identical-second-call.json @@ -3,12 +3,7 @@ "metadata": { "name": "openai-responses-cache/reports-cached-tokens-on-identical-second-call", "recordedAt": "2026-05-11T01:41:58.951Z", - "tags": [ - "prefix:openai-responses-cache", - "provider:openai", - "protocol:openai-responses", - "cache" - ] + "tags": ["prefix:openai-responses-cache", "provider:openai", "protocol:openai-responses", "cache"] }, "interactions": [ {