11
22'use client' ;
33
4- import { ChatInput } from './ChatInput' ;
5- import { ChatLoader } from './ChatLoader' ;
6- import { MemoizedChatMessage } from './MemoizedChatMessage' ;
4+ import { v4 as uuidv4 } from 'uuid' ;
5+ import toast from 'react-hot-toast' ;
6+ import { useCallback , useContext , useEffect , useRef , useState } from 'react' ;
7+
78import { InteractionModal } from '@/components/Chat/ChatInteractionMessage' ;
89import HomeContext from '@/pages/api/home/home.context' ;
910import { ChatBody , Conversation , Message } from '@/types/chat' ;
1011import {
1112 WebSocketInbound ,
12- validateWebSocketMessage ,
1313 validateWebSocketMessageWithConversationId ,
14- validateConversationId ,
1514 isSystemResponseMessage ,
1615 isSystemIntermediateMessage ,
1716 isSystemInteractionMessage ,
1817 isErrorMessage ,
19- isSystemResponseInProgress ,
2018 isSystemResponseComplete ,
21- isOAuthConsentMessage ,
2219 extractOAuthUrl ,
23- shouldAppendResponseContent ,
2420} from '@/types/websocket' ;
2521import { getEndpoint } from '@/utils/app/api' ;
2622import { webSocketMessageTypes } from '@/utils/app/const' ;
2723import {
2824 saveConversation ,
2925 saveConversations ,
30- updateConversation ,
3126} from '@/utils/app/conversation' ;
3227import {
3328 fetchLastMessage ,
3429 processIntermediateMessage ,
35- updateConversationTitle ,
3630} from '@/utils/app/helper' ;
3731import {
3832 shouldAppendResponse ,
@@ -44,14 +38,11 @@ import {
4438 shouldRenderAssistantMessage ,
4539} from '@/utils/chatTransform' ;
4640import { throttle } from '@/utils/data/throttle' ;
47- import { useTranslation } from 'next-i18next' ;
48- import { useCallback , useContext , useEffect , useMemo , useRef , useState } from 'react' ;
49- import toast from 'react-hot-toast' ;
50- import { v4 as uuidv4 } from 'uuid' ;
51-
5241import { SESSION_COOKIE_NAME } from '@/constants/constants' ;
5342
54-
43+ import { ChatInput } from './ChatInput' ;
44+ import { ChatLoader } from './ChatLoader' ;
45+ import { MemoizedChatMessage } from './MemoizedChatMessage' ;
5546
5647// Streaming utilities for handling SSE and NDJSON safely
5748function normalizeNewlines ( s : string ) : string {
@@ -144,7 +135,6 @@ function parsePossiblyConcatenatedJson(payload: string): any[] {
144135// };
145136
146137export const Chat = ( ) => {
147- const { t } = useTranslation ( 'chat' ) ;
148138 const {
149139 state : {
150140 selectedConversation,
@@ -161,13 +151,11 @@ export const Chat = () => {
161151 intermediateStepOverride,
162152 enableIntermediateSteps,
163153 } ,
164- handleUpdateConversation,
165154 dispatch : homeDispatch ,
166155 } = useContext ( HomeContext ) ;
167156
168157 const [ currentMessage , setCurrentMessage ] = useState < Message > ( ) ;
169158 const [ autoScrollEnabled , setAutoScrollEnabled ] = useState < boolean > ( true ) ;
170- const [ showSettings , setShowSettings ] = useState < boolean > ( false ) ;
171159 const [ showScrollDownButton , setShowScrollDownButton ] =
172160 useState < boolean > ( false ) ;
173161
@@ -320,7 +308,9 @@ export const Chat = () => {
320308 'ws://127.0.0.1:8000/websocket' ;
321309
322310 // Determine if this is a cross-origin connection
311+ // eslint-disable-next-line no-unused-vars
323312 const wsUrlObj = new URL ( wsUrl ) ;
313+ // eslint-disable-next-line no-unused-vars
324314 const isCrossOrigin = wsUrlObj . origin !== window . location . origin ;
325315
326316 // Always add session cookie as query parameter for reliability
@@ -388,7 +378,7 @@ export const Chat = () => {
388378 }
389379 } ;
390380
391- ws . onerror = error => {
381+ ws . onerror = _error => {
392382 homeDispatch ( { field : 'webSocketConnected' , value : false } ) ;
393383 webSocketConnectedRef . current = false ;
394384 homeDispatch ( { field : 'loading' , value : false } ) ;
@@ -411,7 +401,8 @@ export const Chat = () => {
411401 /**
412402 * Handles OAuth consent flow by opening popup window
413403 */
414- const handleOAuthConsent = ( message : WebSocketInbound ) => {
404+ // eslint-disable-next-line no-unused-vars
405+ const _handleOAuthConsent = ( message : WebSocketInbound ) => {
415406 if ( ! isSystemInteractionMessage ( message ) ) return false ;
416407
417408 if ( message . content ?. input_type === 'oauth_consent' ) {
@@ -422,7 +413,7 @@ export const Chat = () => {
422413 'oauth-popup' ,
423414 'width=600,height=700,scrollbars=yes,resizable=yes'
424415 ) ;
425- const handleOAuthComplete = ( event : MessageEvent ) => {
416+ const handleOAuthComplete = ( _event : MessageEvent ) => {
426417 if ( popup && ! popup . closed ) popup . close ( ) ;
427418 window . removeEventListener ( 'message' , handleOAuthComplete ) ;
428419 } ;
@@ -702,7 +693,7 @@ export const Chat = () => {
702693 } ;
703694
704695 const handleSend = useCallback (
705- async ( message : Message , deleteCount = 0 , retry = false ) => {
696+ async ( message : Message , deleteCount = 0 , _retry = false ) => {
706697 message . id = uuidv4 ( ) ;
707698
708699 // Set the active user message ID for WebSocket message tracking
@@ -863,8 +854,7 @@ export const Chat = () => {
863854 } ;
864855
865856 const endpoint = getEndpoint ( { service : 'chat' } ) ;
866- let body ;
867- body = JSON . stringify ( {
857+ const body = JSON . stringify ( {
868858 ...chatBody ,
869859 } ) ;
870860
@@ -982,6 +972,7 @@ export const Chat = () => {
982972 chunkValue = String ( chunkValue ?? '' ) ;
983973 }
984974
975+ // eslint-disable-next-line no-unused-vars
985976 counter ++ ;
986977
987978 // First, handle any partial chunk from previous iteration
@@ -1006,8 +997,8 @@ export const Chat = () => {
1006997 }
1007998
1008999 // Process complete intermediate steps
1009- let rawIntermediateSteps : any [ ] = [ ] ;
1010- let stepMatches =
1000+ const rawIntermediateSteps : any [ ] = [ ] ;
1001+ const stepMatches =
10111002 chunkValue . match (
10121003 / < i n t e r m e d i a t e s t e p > ( [ \s \S ] * ?) < \/ i n t e r m e d i a t e s t e p > / g
10131004 ) || [ ] ;
@@ -1017,7 +1008,7 @@ export const Chat = () => {
10171008 . replace ( '<intermediatestep>' , '' )
10181009 . replace ( '</intermediatestep>' , '' )
10191010 . trim ( ) ;
1020- let rawIntermediateMessage = tryParseJson < any > ( jsonString ) ;
1011+ const rawIntermediateMessage = tryParseJson < any > ( jsonString ) ;
10211012 // handle intermediate data
10221013 if ( rawIntermediateMessage ?. type === 'system_intermediate' ) {
10231014 rawIntermediateSteps . push ( rawIntermediateMessage ) ;
0 commit comments