Skip to content

Commit dd35bce

Browse files
authored
Breakpoint just in first user message for gemini for OR and cline provider (RooCodeInc#3319)
* breakpoint just in system prompt * changeset * user message included
1 parent f1ed93a commit dd35bce

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

.changeset/happy-radios-enjoy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"claude-dev": minor
3+
---
4+
5+
breakpoint just in system prompt for gemini for OR and cline provider

src/api/transform/openrouter-stream.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,30 @@ export async function createOpenRouterStream(
8888
],
8989
}
9090

91-
const GEMINI_CACHE_USER_MESSAGE_INTERVAL = 4 // add new breakpoint every 4 turns
91+
// for safety, but this should always be the case
92+
if (openAiMessages.length >= 2) {
93+
const msg = openAiMessages[1]
94+
95+
if (msg) {
96+
if (typeof msg.content === "string") {
97+
msg.content = [{ type: "text", text: msg.content }]
98+
}
99+
if (Array.isArray(msg.content)) {
100+
// 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.
101+
let lastTextPart = msg.content.filter((part) => part.type === "text").pop()
102+
103+
if (!lastTextPart) {
104+
lastTextPart = { type: "text", text: "..." }
105+
msg.content.push(lastTextPart)
106+
}
107+
// @ts-ignore-next-line
108+
lastTextPart["cache_control"] = { type: "ephemeral" }
109+
}
110+
}
111+
}
112+
113+
// it doesn't make sense to alter breakpoints at all with the gemini cache implementation at this time
114+
/*const GEMINI_CACHE_USER_MESSAGE_INTERVAL = 4 // add new breakpoint every 4 turns
92115
const userMessages = openAiMessages.filter((msg) => msg.role === "user")
93116
94117
const userMessageCount = userMessages.length
@@ -115,7 +138,7 @@ export async function createOpenRouterStream(
115138
lastTextPart["cache_control"] = { type: "ephemeral" }
116139
}
117140
}
118-
}
141+
}*/
119142
break
120143
default:
121144
break

0 commit comments

Comments
 (0)