From 48e0ddc3f243edc82d0a9361987808f3104b9417 Mon Sep 17 00:00:00 2001 From: Calvin Secrest Date: Sun, 7 Sep 2025 21:51:01 -0400 Subject: [PATCH] Use stable message IDs in InputBox --- amplify.yml | 2 ++ frontend/chat-ui/src/components/ChatWindow.jsx | 9 ++------- frontend/chat-ui/src/components/InputBox.jsx | 4 +++- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/amplify.yml b/amplify.yml index 42b1bbe..4857b00 100644 --- a/amplify.yml +++ b/amplify.yml @@ -9,6 +9,8 @@ frontend: - npm ci build: commands: + - nvm use 20 + - cd frontend/chat-ui - npm run build - BACKEND_URL=$BACKEND_URL node ../federationStatusCLI.js artifacts: diff --git a/frontend/chat-ui/src/components/ChatWindow.jsx b/frontend/chat-ui/src/components/ChatWindow.jsx index 070b8ca..c093bb5 100644 --- a/frontend/chat-ui/src/components/ChatWindow.jsx +++ b/frontend/chat-ui/src/components/ChatWindow.jsx @@ -11,7 +11,7 @@ import React, { useEffect, useRef } from 'react'; import { useStore } from '../store'; import MessageBubble from './MessageBubble.jsx'; -import { API_BASE_URL } from '../api'; +import { stream } from '../api'; export default function ChatWindow() { const { state, dispatch } = useStore(); @@ -23,12 +23,7 @@ export default function ChatWindow() { useEffect(() => { if (!state.currentConversation) return; - const url = new URL(`${API_BASE_URL}/stream/${state.currentConversation.id}`); - const apiKey = import.meta.env.VITE_API_KEY; - if (apiKey) { - url.searchParams.set('api_key', apiKey); - } - const events = new EventSource(url.toString()); + const events = stream(`/stream/${state.currentConversation.id}`); const handleToken = (e) => { try { diff --git a/frontend/chat-ui/src/components/InputBox.jsx b/frontend/chat-ui/src/components/InputBox.jsx index b7a95e3..91af3f2 100644 --- a/frontend/chat-ui/src/components/InputBox.jsx +++ b/frontend/chat-ui/src/components/InputBox.jsx @@ -14,7 +14,9 @@ export default function InputBox() { if (!state.currentConversation || (!text && !file) || pending) return; setPending(true); try { + const id = crypto.randomUUID ? crypto.randomUUID() : Date.now().toString(); const payload = { + id, from: 'user', to: 'assistant', content: text, @@ -29,7 +31,7 @@ export default function InputBox() { }; } await post(`/messages/${state.currentConversation.id}`, payload); - dispatch({ type: 'ADD_MESSAGE', message: { id: Date.now().toString(), ...payload } }); + dispatch({ type: 'ADD_MESSAGE', message: payload }); setText(''); setFile(null); setFileData('');