From 3a3c4816e25619751c87a09eadbc2c5633fdaa82 Mon Sep 17 00:00:00 2001 From: "claude[bot]" <209825114+claude[bot]@users.noreply.github.com> Date: Mon, 28 Jul 2025 02:58:11 +0000 Subject: [PATCH] fix: correct system prompt handling to prevent display in user messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Modified useChatSession.ts to accept systemPrompt as separate parameter - Updated appendUserMessage to create proper system messages instead of concatenating - Fixed sendMessage function to pass system prompts separately - Fixed initial prompt processing to use separate system prompt parameter - System prompts now appear in dedicated SystemPromptMessage components - Resolved TypeScript and ESLint issues Fixes #164 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Anthony --- frontend/src/hooks/useChatSession.ts | 10 ++++++++-- frontend/src/routes/_auth.chat.$chatId.tsx | 14 ++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/frontend/src/hooks/useChatSession.ts b/frontend/src/hooks/useChatSession.ts index a520ac605..382c46c8d 100644 --- a/frontend/src/hooks/useChatSession.ts +++ b/frontend/src/hooks/useChatSession.ts @@ -149,7 +149,8 @@ export function useChatSession( content: string, images?: File[], documentText?: string, - documentMetadata?: { filename: string; fullContent: string } + documentMetadata?: { filename: string; fullContent: string }, + systemPrompt?: string ) => { if (phase !== "idle") { return; @@ -209,7 +210,12 @@ export function useChatSession( processingRef.current = true; setPhase("streaming"); - const newMessages = [...chat.messages, userMessage]; + // Add system message first if provided + const newMessages = [...chat.messages]; + if (systemPrompt && systemPrompt.trim()) { + newMessages.push({ role: "system", content: systemPrompt.trim() } as ChatMessage); + } + newMessages.push(userMessage); // Update optimistic state immediately setOptimisticChat({ diff --git a/frontend/src/routes/_auth.chat.$chatId.tsx b/frontend/src/routes/_auth.chat.$chatId.tsx index 793a0ae55..4110869ca 100644 --- a/frontend/src/routes/_auth.chat.$chatId.tsx +++ b/frontend/src/routes/_auth.chat.$chatId.tsx @@ -231,11 +231,8 @@ function ChatComponent() { setSystemPrompt(null); setUserImages([]); - // Combine prompts - const finalPrompt = sysPrompt ? `[System: ${sysPrompt}]\n\n${prompt}` : prompt; - - // Send message - appendUserMessage(finalPrompt, images).catch((error) => { + // Send message with system prompt as separate parameter + appendUserMessage(prompt, images, undefined, undefined, sysPrompt || undefined).catch((error) => { // Only reset if it wasn't an abort if (!(error instanceof Error) || error.message !== "Stream aborted") { console.error("[ChatComponent] Failed to append message:", error); @@ -361,11 +358,8 @@ function ChatComponent() { documentText?: string, documentMetadata?: { filename: string; fullContent: string } ) => { - // Handle system prompt if provided - const messageContent = systemPrompt ? `[System: ${systemPrompt}]\n\n${input}` : input; - - // Use the appendUserMessage from the hook - await appendUserMessage(messageContent, images, documentText, documentMetadata); + // Use the appendUserMessage from the hook with system prompt as separate parameter + await appendUserMessage(input, images, documentText, documentMetadata, systemPrompt); // Scroll to bottom after sending requestAnimationFrame(() => {