Skip to content

Commit 9d59ddd

Browse files
committed
cleanup
1 parent d816664 commit 9d59ddd

File tree

6 files changed

+50
-36
lines changed

6 files changed

+50
-36
lines changed

e2e/chat.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ test.describe('Chat v2 Conversation tests', () => {
3838
await expect(page.getByTestId('assistant-message')).toContainText('OVER', { timeout: 6000 })
3939

4040
page.on('dialog', (dialog) => dialog.accept())
41-
await page.locator('#empty-conversation-button').click()
41+
await page.getByTestId('empty-conversation-button').click()
4242

4343
await expect(page.getByTestId('user-message')).not.toBeVisible()
4444
await expect(page.getByTestId('assistant-message')).not.toBeVisible()

e2e/chatFeatures.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test.describe('Chat v2 UI Features Tests', () => {
1919

2020
test('Disclaimer (help) can be opened manually', async ({ page }) => {
2121
await acceptDisclaimer(page)
22-
await page.locator('#help-button').click()
22+
await page.getByTestId('help-button').click()
2323
await expect(page.locator('#submit-accept-disclaimer')).toBeVisible()
2424
})
2525

e2e/prompts.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ test.describe('Prompts', () => {
3434

3535
// Clear chat
3636
page.on('dialog', (dialog) => dialog.accept())
37-
await page.locator('#empty-conversation-button').click()
37+
await page.getByTestId('empty-conversation-button').click()
3838

3939
// Reload page to ensure prompt is saved
4040
await page.reload()

src/client/components/ChatV2/ChatBox.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ export const ChatBox = ({
321321
</Typography>
322322
}
323323
>
324-
<OutlineButtonBlack sx={{ display: { sm: 'block', md: 'none' } }} onClick={() => setChatLeftSidePanelOpen(true)} id="left-panel-open">
324+
<OutlineButtonBlack sx={{ display: { sm: 'block', md: 'none' } }} onClick={() => setChatLeftSidePanelOpen(true)} data-testid="left-panel-open">
325325
<SettingsIcon sx={{ color: 'rgba(0, 0, 0, 0.7)' }} />
326326
</OutlineButtonBlack>
327327
</Tooltip>

src/client/components/ChatV2/ChatV2.tsx

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
1-
import RestartAltIcon from '@mui/icons-material/RestartAlt'
1+
import { ArrowDownward, ChevronLeft, MenuBookTwoTone, Tune } from '@mui/icons-material'
22
import HelpIcon from '@mui/icons-material/Help'
3-
import { Alert, Box, Drawer, Fab, FormControlLabel, Paper, Switch, SxProps, Typography, useMediaQuery, useTheme } from '@mui/material'
4-
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react'
3+
import RestartAltIcon from '@mui/icons-material/RestartAlt'
4+
import { Alert, Box, Drawer, Fab, FormControlLabel, Paper, Switch, Typography, useMediaQuery, useTheme } from '@mui/material'
5+
import type { TFunction } from 'i18next'
6+
import { enqueueSnackbar } from 'notistack'
7+
import { useCallback, useEffect, useRef, useState } from 'react'
58
import { useTranslation } from 'react-i18next'
69
import { useParams, useSearchParams } from 'react-router-dom'
710
import { DEFAULT_ASSISTANT_INSTRUCTIONS, DEFAULT_MODEL, DEFAULT_MODEL_TEMPERATURE, FREE_MODEL, inProduction, validModels } from '../../../config'
11+
import type { ToolCallResultEvent } from '../../../shared/chat'
12+
import type { RagIndexAttributes } from '../../../shared/types'
813
import { getLanguageValue } from '../../../shared/utils'
14+
import { useIsEmbedded } from '../../contexts/EmbeddedContext'
15+
import { useChatScroll } from '../../hooks/useChatScroll'
916
import useCourse from '../../hooks/useCourse'
17+
import useCurrentUser from '../../hooks/useCurrentUser'
1018
import useInfoTexts from '../../hooks/useInfoTexts'
1119
import useLocalStorageState from '../../hooks/useLocalStorageState'
1220
import { useCourseRagIndices } from '../../hooks/useRagIndices'
1321
import useRetryTimeout from '../../hooks/useRetryTimeout'
1422
import useUserStatus from '../../hooks/useUserStatus'
23+
import { useAnalyticsDispatch } from '../../stores/analytics'
1524
import type { Course, Message, Prompt } from '../../types'
25+
import Footer from '../Footer'
1626
import { ChatBox } from './ChatBox'
1727
import { Conversation } from './Conversation'
1828
import { DisclaimerModal } from './Disclaimer'
29+
import EmailButton from './EmailButton'
1930
import { handleCompletionStreamError } from './error'
31+
import FileSearchResults from './FileSearchResults'
32+
import { OutlineButtonBlack } from './general/Buttons'
2033
import { ChatInfo } from './general/ChatInfo'
2134
import RagSelector from './RagSelector'
2235
import { SettingsModal } from './SettingsModal'
23-
import { getCompletionStreamV3 } from './util'
24-
import { OutlineButtonBlack } from './general/Buttons'
25-
import useCurrentUser from '../../hooks/useCurrentUser'
26-
import { useChatStream } from './useChatStream'
27-
import FileSearchResults from './FileSearchResults'
28-
import { useIsEmbedded } from '../../contexts/EmbeddedContext'
29-
import { enqueueSnackbar } from 'notistack'
30-
import { useAnalyticsDispatch } from '../../stores/analytics'
31-
import EmailButton from './EmailButton'
32-
import { ArrowDownward, ChevronLeft, Close, MenuBookTwoTone, Tune } from '@mui/icons-material'
33-
import { useChatScroll } from '../../hooks/useChatScroll'
3436
import { TestUseInfoV2 } from './TestUseInfo'
35-
import Footer from '../Footer'
36-
import type { ToolCallResultEvent } from '../../../shared/chat'
37-
import { ChatToolResult } from '../../../shared/tools'
38-
import { TFunction } from 'i18next'
39-
import { RagIndexAttributes } from '../../../shared/types'
37+
import { useChatStream } from './useChatStream'
38+
import { getCompletionStreamV3 } from './util'
4039

4140
function useLocalStorageStateWithURLDefault(key: string, defaultValue: string, urlKey: string) {
4241
const [value, setValue] = useLocalStorageState(key, defaultValue)
@@ -142,14 +141,12 @@ export const ChatV2 = () => {
142141
handleCompletionStreamError(error, fileName)
143142
enqueueSnackbar(t('chat:errorInstructions'), { variant: 'error' })
144143
},
145-
/* @todo fix this: onFileSearchComplete: (fileSearch) => {
146-
setActiveToolResult(fileSearch)
147-
// Only auto-open FileSearchResults on desktop, not on mobile
144+
onToolCallComplete: (toolResult) => {
148145
if (!isMobile) {
149-
setShowToolResults(true)
146+
setActiveToolResult(toolResult)
150147
}
151148
dispatchAnalytics({ type: 'INCREMENT_FILE_SEARCHES' })
152-
}, */
149+
},
153150
})
154151

155152
const handleSubmit = async (message: string, ignoreTokenUsageWarning: boolean) => {
@@ -299,13 +296,10 @@ export const ChatV2 = () => {
299296
// Save the current proportional scroll position
300297
prevScrollYProportional.current = window.scrollY / document.body.scrollHeight
301298

302-
console.log('New scroll position:', window.scrollY, document.body.scrollHeight)
303-
304299
// Set timeout to restore after layout change
305300
setTimeout(() => {
306301
const scrollY = prevScrollYProportional.current * document.body.scrollHeight
307302
window.scrollTo(0, scrollY)
308-
console.log('Restored scroll position:', scrollY, document.body.scrollHeight)
309303
}, 0)
310304
}, [])
311305
const setActiveToolResult = useCallback(
@@ -395,7 +389,11 @@ export const ChatV2 = () => {
395389
</Drawer>
396390
) : (
397391
<LeftMenu
398-
sx={{ display: { sm: 'none', md: 'flex' }, position: 'fixed', top: 0 }}
392+
sx={{
393+
display: { sm: 'none', md: 'flex' },
394+
position: 'fixed',
395+
top: 0,
396+
}}
399397
course={course}
400398
handleReset={handleReset}
401399
t={t}
@@ -431,14 +429,27 @@ export const ChatV2 = () => {
431429
paddingLeft: '1rem',
432430
paddingRight: '1rem',
433431
paddingTop: '1rem',
434-
width: { sm: '100vw', md: `calc(100vw - 300px - ${rightMenuWidth})`, lg: `calc(100vw - 400px - ${rightMenuWidth})` },
432+
width: {
433+
sm: '100vw',
434+
md: `calc(100vw - 300px - ${rightMenuWidth})`,
435+
lg: `calc(100vw - 400px - ${rightMenuWidth})`,
436+
},
435437
}}
436438
ref={scrollRef}
437439
>
438440
{user?.preferences?.chatVersion !== 2 && <TestUseInfoV2 />}
439441

440442
{course?.saveDiscussions && (
441-
<Paper variant="outlined" sx={{ padding: 2, mt: 2, display: 'flex', flexDirection: 'column', gap: 2 }}>
443+
<Paper
444+
variant="outlined"
445+
sx={{
446+
padding: 2,
447+
mt: 2,
448+
display: 'flex',
449+
flexDirection: 'column',
450+
gap: 2,
451+
}}
452+
>
442453
<Box sx={{ display: 'flex', alignItems: 'center', gap: 2 }}>
443454
<Typography variant="body1" fontWeight={600}>
444455
{course?.notOptoutSaving ? t('course:isSavedNotOptOut') : t('course:isSavedOptOut')}
@@ -620,15 +631,15 @@ const LeftMenu = ({
620631
<Box p="1rem">
621632
{course && <ChatInfo course={course} />}
622633
<Box sx={{ display: 'flex', flexDirection: 'column', gap: '0.6rem' }}>
623-
<OutlineButtonBlack startIcon={<RestartAltIcon />} onClick={handleReset} id="empty-conversation-button">
634+
<OutlineButtonBlack startIcon={<RestartAltIcon />} onClick={handleReset} data-testid="empty-conversation-button">
624635
{t('chat:emptyConversation')}
625636
</OutlineButtonBlack>
626637

627638
<EmailButton messages={messages} disabled={!messages?.length} />
628639
<OutlineButtonBlack startIcon={<Tune />} onClick={() => setSettingsModalOpen(true)} data-testid="settings-button">
629640
{t('chat:settings')}
630641
</OutlineButtonBlack>
631-
<OutlineButtonBlack startIcon={<HelpIcon />} onClick={() => setDisclaimerStatus(true)} id="help-button">
642+
<OutlineButtonBlack startIcon={<HelpIcon />} onClick={() => setDisclaimerStatus(true)} data-testid="help-button">
632643
{t('info:title')}
633644
</OutlineButtonBlack>
634645
{course && showRagSelector && (

src/client/components/ChatV2/useChatStream.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ type ToolCallState = ToolCallStatusEvent
66

77
export const useChatStream = ({
88
onComplete,
9+
onToolCallComplete,
910
onError,
1011
onText,
1112
}: {
1213
onComplete: ({ previousResponseId, message }: { previousResponseId: string | undefined; message: Message }) => void
14+
onToolCallComplete: (toolResult: ToolCallResultEvent) => void
1315
onError: (error: unknown) => void
1416
onText: () => void
1517
}) => {
@@ -68,6 +70,7 @@ export const useChatStream = ({
6870
case 'toolCallStatus':
6971
if ('result' in parsedChunk) {
7072
toolCallResultsAccum[parsedChunk.callId] = parsedChunk
73+
onToolCallComplete(parsedChunk)
7174
}
7275
setToolCalls((prev) => ({ ...prev, [parsedChunk.callId]: parsedChunk }))
7376
break

0 commit comments

Comments
 (0)