From dd35bce141301db817155d05edbc8f20d9ec17d7 Mon Sep 17 00:00:00 2001 From: Toshii <94262432+0xToshii@users.noreply.github.com> Date: Tue, 6 May 2025 08:50:22 -0700 Subject: [PATCH] Breakpoint just in first user message for gemini for OR and cline provider (#3319) * breakpoint just in system prompt * changeset * user message included --- .changeset/happy-radios-enjoy.md | 5 +++++ src/api/transform/openrouter-stream.ts | 27 ++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 .changeset/happy-radios-enjoy.md diff --git a/.changeset/happy-radios-enjoy.md b/.changeset/happy-radios-enjoy.md new file mode 100644 index 00000000..e8910c7b --- /dev/null +++ b/.changeset/happy-radios-enjoy.md @@ -0,0 +1,5 @@ +--- +"claude-dev": minor +--- + +breakpoint just in system prompt for gemini for OR and cline provider diff --git a/src/api/transform/openrouter-stream.ts b/src/api/transform/openrouter-stream.ts index e9f3ce3e..69f68833 100644 --- a/src/api/transform/openrouter-stream.ts +++ b/src/api/transform/openrouter-stream.ts @@ -88,7 +88,30 @@ export async function createOpenRouterStream( ], } - const GEMINI_CACHE_USER_MESSAGE_INTERVAL = 4 // add new breakpoint every 4 turns + // for safety, but this should always be the case + if (openAiMessages.length >= 2) { + const msg = openAiMessages[1] + + if (msg) { + if (typeof msg.content === "string") { + msg.content = [{ type: "text", text: msg.content }] + } + if (Array.isArray(msg.content)) { + // NOTE: this is fine since env details will always be added at the end. but if it weren't there, and the user added a image_url type message, it would pop a text part before it and then move it after to the end. + let lastTextPart = msg.content.filter((part) => part.type === "text").pop() + + if (!lastTextPart) { + lastTextPart = { type: "text", text: "..." } + msg.content.push(lastTextPart) + } + // @ts-ignore-next-line + lastTextPart["cache_control"] = { type: "ephemeral" } + } + } + } + + // it doesn't make sense to alter breakpoints at all with the gemini cache implementation at this time + /*const GEMINI_CACHE_USER_MESSAGE_INTERVAL = 4 // add new breakpoint every 4 turns const userMessages = openAiMessages.filter((msg) => msg.role === "user") const userMessageCount = userMessages.length @@ -115,7 +138,7 @@ export async function createOpenRouterStream( lastTextPart["cache_control"] = { type: "ephemeral" } } } - } + }*/ break default: break