diff --git a/src/interface/web/app/common/chatFunctions.ts b/src/interface/web/app/common/chatFunctions.ts index e1a5f5a5..a1657ad5 100644 --- a/src/interface/web/app/common/chatFunctions.ts +++ b/src/interface/web/app/common/chatFunctions.ts @@ -33,88 +33,6 @@ export function handleCompiledReferences(chunk: string, currentResponse: string) return references; } -async function sendChatStream( - message: string, - conversationId: string, - setIsLoading: (loading: boolean) => void, - setInitialResponse: (response: string) => void, - setInitialReferences: (references: ResponseWithReferences) => void) { - setIsLoading(true); - // Send a message to the chat server to verify the fact - const chatURL = "/api/chat"; - const apiURL = `${chatURL}?q=${encodeURIComponent(message)}&client=web&stream=true&conversation_id=${conversationId}`; - try { - const response = await fetch(apiURL); - if (!response.body) throw new Error("No response body found"); - - const reader = response.body?.getReader(); - let decoder = new TextDecoder(); - let result = ""; - - while (true) { - const { done, value } = await reader.read(); - if (done) break; - - let chunk = decoder.decode(value, { stream: true }); - - if (chunk.includes("### compiled references:")) { - const references = handleCompiledReferences(chunk, result); - if (references.response) { - result = references.response; - setInitialResponse(references.response); - setInitialReferences(references); - } - } else { - result += chunk; - setInitialResponse(result); - } - } - } catch (error) { - console.error("Error verifying statement: ", error); - } finally { - setIsLoading(false); - } -} - -export const setupWebSocket = async (conversationId: string, initialMessage?: string) => { - const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; - - const host = process.env.NODE_ENV === 'production' ? window.location.host : 'localhost:42110'; - - let webSocketUrl = `${wsProtocol}//${host}/api/chat/ws`; - - if (conversationId === null) { - return null; - } - - if (conversationId) { - webSocketUrl += `?conversation_id=${conversationId}`; - } - - const chatWS = new WebSocket(webSocketUrl); - - chatWS.onopen = () => { - console.log('WebSocket connection established'); - if (initialMessage) { - chatWS.send(initialMessage); - } - }; - - chatWS.onmessage = (event) => { - console.log(event.data); - }; - - chatWS.onerror = (error) => { - console.error('WebSocket error: ', error); - }; - - chatWS.onclose = () => { - console.log('WebSocket connection closed'); - }; - - return chatWS; -}; - interface MessageChunk { type: string; data: string | object; diff --git a/src/interface/web/app/share/chat/page.tsx b/src/interface/web/app/share/chat/page.tsx index f02ed1a1..56d27bbc 100644 --- a/src/interface/web/app/share/chat/page.tsx +++ b/src/interface/web/app/share/chat/page.tsx @@ -15,7 +15,7 @@ import { useAuthenticatedData } from '@/app/common/auth'; import ChatInputArea, { ChatOptions } from '@/app/components/chatInputArea/chatInputArea'; import { StreamMessage } from '@/app/components/chatMessage/chatMessage'; -import { convertMessageChunkToJson, handleCompiledReferences, handleImageResponse, RawReferenceData, setupWebSocket } from '@/app/common/chatFunctions'; +import { convertMessageChunkToJson, handleCompiledReferences, handleImageResponse, RawReferenceData } from '@/app/common/chatFunctions'; import { AgentData } from '@/app/agents/page';