|
1 |
| -import RestartAltIcon from '@mui/icons-material/RestartAlt' |
| 1 | +import { ArrowDownward, ChevronLeft, MenuBookTwoTone, Tune } from '@mui/icons-material' |
2 | 2 | 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' |
5 | 8 | import { useTranslation } from 'react-i18next'
|
6 | 9 | import { useParams, useSearchParams } from 'react-router-dom'
|
7 | 10 | 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' |
8 | 13 | import { getLanguageValue } from '../../../shared/utils'
|
| 14 | +import { useIsEmbedded } from '../../contexts/EmbeddedContext' |
| 15 | +import { useChatScroll } from '../../hooks/useChatScroll' |
9 | 16 | import useCourse from '../../hooks/useCourse'
|
| 17 | +import useCurrentUser from '../../hooks/useCurrentUser' |
10 | 18 | import useInfoTexts from '../../hooks/useInfoTexts'
|
11 | 19 | import useLocalStorageState from '../../hooks/useLocalStorageState'
|
12 | 20 | import { useCourseRagIndices } from '../../hooks/useRagIndices'
|
13 | 21 | import useRetryTimeout from '../../hooks/useRetryTimeout'
|
14 | 22 | import useUserStatus from '../../hooks/useUserStatus'
|
| 23 | +import { useAnalyticsDispatch } from '../../stores/analytics' |
15 | 24 | import type { Course, Message, Prompt } from '../../types'
|
| 25 | +import Footer from '../Footer' |
16 | 26 | import { ChatBox } from './ChatBox'
|
17 | 27 | import { Conversation } from './Conversation'
|
18 | 28 | import { DisclaimerModal } from './Disclaimer'
|
| 29 | +import EmailButton from './EmailButton' |
19 | 30 | import { handleCompletionStreamError } from './error'
|
| 31 | +import FileSearchResults from './FileSearchResults' |
| 32 | +import { OutlineButtonBlack } from './general/Buttons' |
20 | 33 | import { ChatInfo } from './general/ChatInfo'
|
21 | 34 | import RagSelector from './RagSelector'
|
22 | 35 | 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' |
34 | 36 | 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' |
40 | 39 |
|
41 | 40 | function useLocalStorageStateWithURLDefault(key: string, defaultValue: string, urlKey: string) {
|
42 | 41 | const [value, setValue] = useLocalStorageState(key, defaultValue)
|
@@ -142,14 +141,12 @@ export const ChatV2 = () => {
|
142 | 141 | handleCompletionStreamError(error, fileName)
|
143 | 142 | enqueueSnackbar(t('chat:errorInstructions'), { variant: 'error' })
|
144 | 143 | },
|
145 |
| - /* @todo fix this: onFileSearchComplete: (fileSearch) => { |
146 |
| - setActiveToolResult(fileSearch) |
147 |
| - // Only auto-open FileSearchResults on desktop, not on mobile |
| 144 | + onToolCallComplete: (toolResult) => { |
148 | 145 | if (!isMobile) {
|
149 |
| - setShowToolResults(true) |
| 146 | + setActiveToolResult(toolResult) |
150 | 147 | }
|
151 | 148 | dispatchAnalytics({ type: 'INCREMENT_FILE_SEARCHES' })
|
152 |
| - }, */ |
| 149 | + }, |
153 | 150 | })
|
154 | 151 |
|
155 | 152 | const handleSubmit = async (message: string, ignoreTokenUsageWarning: boolean) => {
|
@@ -299,13 +296,10 @@ export const ChatV2 = () => {
|
299 | 296 | // Save the current proportional scroll position
|
300 | 297 | prevScrollYProportional.current = window.scrollY / document.body.scrollHeight
|
301 | 298 |
|
302 |
| - console.log('New scroll position:', window.scrollY, document.body.scrollHeight) |
303 |
| - |
304 | 299 | // Set timeout to restore after layout change
|
305 | 300 | setTimeout(() => {
|
306 | 301 | const scrollY = prevScrollYProportional.current * document.body.scrollHeight
|
307 | 302 | window.scrollTo(0, scrollY)
|
308 |
| - console.log('Restored scroll position:', scrollY, document.body.scrollHeight) |
309 | 303 | }, 0)
|
310 | 304 | }, [])
|
311 | 305 | const setActiveToolResult = useCallback(
|
@@ -395,7 +389,11 @@ export const ChatV2 = () => {
|
395 | 389 | </Drawer>
|
396 | 390 | ) : (
|
397 | 391 | <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 | + }} |
399 | 397 | course={course}
|
400 | 398 | handleReset={handleReset}
|
401 | 399 | t={t}
|
@@ -431,14 +429,27 @@ export const ChatV2 = () => {
|
431 | 429 | paddingLeft: '1rem',
|
432 | 430 | paddingRight: '1rem',
|
433 | 431 | 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 | + }, |
435 | 437 | }}
|
436 | 438 | ref={scrollRef}
|
437 | 439 | >
|
438 | 440 | {user?.preferences?.chatVersion !== 2 && <TestUseInfoV2 />}
|
439 | 441 |
|
440 | 442 | {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 | + > |
442 | 453 | <Box sx={{ display: 'flex', alignItems: 'center', gap: 2 }}>
|
443 | 454 | <Typography variant="body1" fontWeight={600}>
|
444 | 455 | {course?.notOptoutSaving ? t('course:isSavedNotOptOut') : t('course:isSavedOptOut')}
|
@@ -620,15 +631,15 @@ const LeftMenu = ({
|
620 | 631 | <Box p="1rem">
|
621 | 632 | {course && <ChatInfo course={course} />}
|
622 | 633 | <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"> |
624 | 635 | {t('chat:emptyConversation')}
|
625 | 636 | </OutlineButtonBlack>
|
626 | 637 |
|
627 | 638 | <EmailButton messages={messages} disabled={!messages?.length} />
|
628 | 639 | <OutlineButtonBlack startIcon={<Tune />} onClick={() => setSettingsModalOpen(true)} data-testid="settings-button">
|
629 | 640 | {t('chat:settings')}
|
630 | 641 | </OutlineButtonBlack>
|
631 |
| - <OutlineButtonBlack startIcon={<HelpIcon />} onClick={() => setDisclaimerStatus(true)} id="help-button"> |
| 642 | + <OutlineButtonBlack startIcon={<HelpIcon />} onClick={() => setDisclaimerStatus(true)} data-testid="help-button"> |
632 | 643 | {t('info:title')}
|
633 | 644 | </OutlineButtonBlack>
|
634 | 645 | {course && showRagSelector && (
|
|
0 commit comments