From d3548d179bf9814e16cd4acdeb91411bd046aaac Mon Sep 17 00:00:00 2001 From: chrarnoldus <12196001+chrarnoldus@users.noreply.github.com> Date: Sat, 8 Aug 2026 18:52:47 +0000 Subject: [PATCH] refactor(cli): remove part.synthetic and any-cast from applyCaching Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com> --- packages/opencode/src/provider/transform.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/opencode/src/provider/transform.ts b/packages/opencode/src/provider/transform.ts index cf876f0c56..d8b04db466 100644 --- a/packages/opencode/src/provider/transform.ts +++ b/packages/opencode/src/provider/transform.ts @@ -388,18 +388,15 @@ function applyCaching(msgs: ModelMessage[], model: Provider.Model): ModelMessage if (shouldUseContentOptions) { // kilocode_change start - place caching breakpoint on stable content before trailing - const parts = msg.content as any[] - const targetIndex = parts.findLastIndex( + const target = msg.content.findLast( (part) => - part && typeof part === "object" && + part !== null && part.type !== "tool-approval-request" && part.type !== "tool-approval-response" && - !(part.type === "text" && typeof part.text === "string" && part.text.startsWith("")) && - !part.synthetic, + !(part.type === "text" && part.text.startsWith("")), ) - const lastContent = targetIndex >= 0 ? parts[targetIndex] : parts[parts.length - 1] - // kilocode_change end + const lastContent = target ?? msg.content[msg.content.length - 1] if ( lastContent && typeof lastContent === "object" && @@ -409,6 +406,7 @@ function applyCaching(msgs: ModelMessage[], model: Provider.Model): ModelMessage lastContent.providerOptions = mergeDeep(lastContent.providerOptions ?? {}, providerOptions) continue } + // kilocode_change end } msg.providerOptions = mergeDeep(msg.providerOptions ?? {}, providerOptions) @@ -476,6 +474,7 @@ function mapProviderOptions( export function message(msgs: ModelMessage[], model: Provider.Model, options: Record) { msgs = unsupportedParts(msgs, model) msgs = normalizeMessages(msgs, model, options) + // kilocode_change start - apply caching for anthropic, alibaba, and GPT-5.6+ openai/azure/kilo-gateway if ( (model.providerID === "anthropic" || model.providerID === "google-vertex-anthropic" || @@ -484,17 +483,16 @@ export function message(msgs: ModelMessage[], model: Provider.Model, options: Re model.id.includes("anthropic") || model.id.includes("claude") || model.api.npm === "@ai-sdk/anthropic" || - // kilocode_change start model.api.npm === "@ai-sdk/alibaba" || ((model.api.npm === "@ai-sdk/openai" || model.api.npm === "@ai-sdk/azure" || model.api.npm === "@kilocode/kilo-gateway") && supportsPromptCacheBreakpoint(model.api.id))) && - // kilocode_change end model.api.npm !== "@ai-sdk/gateway" ) { msgs = applyCaching(msgs, model) } + // kilocode_change end // Remap providerOptions keys from stored providerID to expected SDK key const key = sdkKey(model.api.npm)