Clone the messages list instead of mutating them

This commit is contained in:
Alex Gleason committed 2026-01-08 01:17:46 -06:00
1 parent f58f75ae8b
commit 3666aac2a1
1 file changed
+1
+1
View File
@@ -68,6 +68,7 @@ export function createAIClient(provider: AIProvider, user?: NUser, corsProxy?: s
// https://openrouter.ai/docs/guides/best-practices/prompt-caching#anthropic-claude
if (body.model.startsWith("anthropic/")) {
// First normalize the message history to use content blocks
body.messages = structuredClone(body.messages);
body.messages = body.messages.map((m) => {
if (m.role !== "function" && typeof m.content === "string") {
return { ...m, content: [{ type: "text", text: m.content }] };