diff --git a/frontend/chat-ui/src/api.js b/frontend/chat-ui/src/api.js index 8cfb598..4c6bf67 100644 --- a/frontend/chat-ui/src/api.js +++ b/frontend/chat-ui/src/api.js @@ -1,5 +1,4 @@ export const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || ''; -const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || ''; const API_KEY = import.meta.env.VITE_API_KEY || ''; async function request(method, path, body) { diff --git a/frontend/chat-ui/src/components/ChatWindow.jsx b/frontend/chat-ui/src/components/ChatWindow.jsx index f9c6f0b..070b8ca 100644 --- a/frontend/chat-ui/src/components/ChatWindow.jsx +++ b/frontend/chat-ui/src/components/ChatWindow.jsx @@ -13,8 +13,6 @@ import { useStore } from '../store'; import MessageBubble from './MessageBubble.jsx'; import { API_BASE_URL } from '../api'; -const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || ''; - export default function ChatWindow() { const { state, dispatch } = useStore(); const bottomRef = useRef(); @@ -31,7 +29,6 @@ export default function ChatWindow() { url.searchParams.set('api_key', apiKey); } const events = new EventSource(url.toString()); - const events = new EventSource(`${API_BASE_URL}/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 a8efc41..b7a95e3 100644 --- a/frontend/chat-ui/src/components/InputBox.jsx +++ b/frontend/chat-ui/src/components/InputBox.jsx @@ -1,6 +1,5 @@ import React, { useState, useRef } from 'react'; import { useStore } from '../store'; -import { API_BASE_URL } from '../api'; import { post } from '../api'; export default function InputBox() { diff --git a/frontend/chat-ui/src/components/MessageActions.jsx b/frontend/chat-ui/src/components/MessageActions.jsx index 3ce6d96..85a3970 100644 --- a/frontend/chat-ui/src/components/MessageActions.jsx +++ b/frontend/chat-ui/src/components/MessageActions.jsx @@ -3,8 +3,7 @@ import { useStore } from '../store'; /** @typedef {import('../types').Message} Message */ -const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || ''; -import { API_BASE_URL } from '../api'; +import { post } from '../api'; /** * Action buttons associated with a message. @@ -24,13 +23,8 @@ export default function MessageActions({ message }) { const regenerate = async () => { if (!state.currentConversation) return; try { - await fetch(`${API_BASE_URL}/messages/${state.currentConversation.id}/regenerate`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'x-api-key': import.meta.env.VITE_API_KEY, - }, - body: JSON.stringify({ messageId: message.id }), + await post(`/messages/${state.currentConversation.id}/regenerate`, { + messageId: message.id, }); } catch (e) { console.error(e); @@ -39,14 +33,7 @@ export default function MessageActions({ message }) { const feedback = async (value) => { try { - await fetch(`${API_BASE_URL}/feedback`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'x-api-key': import.meta.env.VITE_API_KEY, - }, - body: JSON.stringify({ messageId: message.id, value }), - }); + await post('/feedback', { messageId: message.id, value }); } catch (e) { console.error(e); } diff --git a/frontend/chat-ui/src/components/Sidebar.jsx b/frontend/chat-ui/src/components/Sidebar.jsx index b158df6..a418b1d 100644 --- a/frontend/chat-ui/src/components/Sidebar.jsx +++ b/frontend/chat-ui/src/components/Sidebar.jsx @@ -16,9 +16,6 @@ import { useStore } from '../store'; * @typedef {import('../types').Message} Message */ -const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || ''; - -import { API_BASE_URL } from '../api'; import { get, post } from '../api'; /** @@ -56,13 +53,6 @@ export default function Sidebar() { */ const openConversation = async (c) => { try { - const res = await fetch(`${API_BASE_URL}/messages/${c.id}`, { - headers: { 'x-api-key': import.meta.env.VITE_API_KEY }, - }); - const msgs = /** @type {Message[]} */ (await res.json()); - dispatch({ type: 'SET_CURRENT_CONVERSATION', conversation: c }); - dispatch({ type: 'SET_MESSAGES', messages: msgs }); - const msgs = await get(`/messages/${c.id}`); dispatch({ type: 'SET_CURRENT_CONVERSATION', conversation: c }); dispatch({ type: 'SET_MESSAGES', messages: msgs }); diff --git a/frontend/chat-ui/src/components/TopBar.jsx b/frontend/chat-ui/src/components/TopBar.jsx index ff06c03..f7968b3 100644 --- a/frontend/chat-ui/src/components/TopBar.jsx +++ b/frontend/chat-ui/src/components/TopBar.jsx @@ -1,6 +1,6 @@ import React, { useState, useEffect } from 'react'; import { useStore } from '../store'; -import { API_BASE_URL } from '../api'; +import { put, del } from '../api'; export default function TopBar() { const { state, dispatch } = useStore(); @@ -16,14 +16,7 @@ export default function TopBar() { setTitle(t); if (!state.currentConversation) return; try { - await fetch(`${API_BASE_URL}/conversations/${state.currentConversation.id}`, { - method: 'PUT', - headers: { - 'Content-Type': 'application/json', - 'x-api-key': import.meta.env.VITE_API_KEY, - }, - body: JSON.stringify({ title: t }), - }); + await put(`/conversations/${state.currentConversation.id}`, { title: t }); const updated = { ...state.currentConversation, title: t }; dispatch({ type: 'SET_CURRENT_CONVERSATION', conversation: updated }); dispatch({ @@ -38,10 +31,7 @@ export default function TopBar() { const remove = async () => { if (!state.currentConversation) return; try { - await fetch(`${API_BASE_URL}/conversations/${state.currentConversation.id}`, { - method: 'DELETE', - headers: { 'x-api-key': import.meta.env.VITE_API_KEY }, - }); + await del(`/conversations/${state.currentConversation.id}`); dispatch({ type: 'SET_CONVERSATIONS', conversations: state.conversations.filter((c) => c.id !== state.currentConversation.id),