/
index.tsx
154 lines (145 loc) · 4.31 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import Paper from '@mui/material/Paper';
import InputBase from '@mui/material/InputBase';
import IconButton from '@mui/material/IconButton';
import MenuIcon from '@mui/icons-material/Menu';
import SendIcon from '@mui/icons-material/Send';
import Menu from '@mui/material/Menu';
import MenuItem from '@mui/material/MenuItem';
import ListItemIcon from '@mui/material/ListItemIcon';
import LongTermMemoryIcon from '@mui/icons-material/Psychology';
import AssistantIcon from '@mui/icons-material/Assistant';
import VisionIcon from '@mui/icons-material/Visibility';
import RagIcon from '@mui/icons-material/Storage';
import RecordVoiceOver from '@mui/icons-material/RecordVoiceOver';
import { useTheme } from '@mui/material/styles';
import useMediaQuery from '@mui/material/useMediaQuery';
import { useCustomInput } from '@/app/hooks/useCustomInput';
import AssistantDialog from '../Assistant';
import VisionDialog from '../Vision';
import SpeechDialog from '../Speech/tts';
import { Microphone } from '../Speech/stt';
import RagDialog from '../Rag';
import LongTermMemoryDialog from '../LongTermMemory';
const CustomizedInputBase = ({
onSendMessage,
}: {
onSendMessage: (message: string) => Promise<void>;
}) => {
const theme = useTheme();
const isSmallScreen = useMediaQuery(theme.breakpoints.down('sm'));
const {
inputValue,
appendText,
handleInputChange,
handleSendClick,
isDialogOpen,
toggleDialog,
handleMenuOpen,
handleMenuClose,
anchorEl,
} = useCustomInput({ onSendMessage });
return (
<>
<Paper
component="form"
sx={{
p: '2px 4px',
display: 'flex',
alignItems: 'center',
width: isSmallScreen ? '100%' : 650,
}}
onKeyDown={(event) => {
if (event.key === 'Enter') {
event.preventDefault();
handleSendClick();
}
}}
>
<Microphone onAppendText={appendText} />
<IconButton
sx={{ p: '10px' }}
aria-label="menu"
onClick={handleMenuOpen}
>
<MenuIcon />
</IconButton>
<Menu
anchorEl={anchorEl}
open={Boolean(anchorEl)}
onClose={handleMenuClose}
anchorOrigin={{
vertical: 'top',
horizontal: 'right',
}}
transformOrigin={{
vertical: 'top',
horizontal: 'right',
}}
>
<MenuItem onClick={() => toggleDialog('memory')}>
<ListItemIcon>
<LongTermMemoryIcon />
</ListItemIcon>
Memory
</MenuItem>
<MenuItem onClick={() => toggleDialog('rag')}>
<ListItemIcon>
<RagIcon />
</ListItemIcon>
R.A.G.
</MenuItem>
<MenuItem onClick={() => toggleDialog('assistant')}>
<ListItemIcon>
<AssistantIcon />
</ListItemIcon>
Assistant
</MenuItem>
<MenuItem onClick={() => toggleDialog('vision')}>
<ListItemIcon>
<VisionIcon fontSize="small" />
</ListItemIcon>
Vision
</MenuItem>
<MenuItem onClick={() => toggleDialog('speech')}>
<ListItemIcon>
<RecordVoiceOver />
</ListItemIcon>
Speech
</MenuItem>
</Menu>
<InputBase
sx={{ ml: 1, flex: 1 }}
placeholder="Enter your message"
value={inputValue}
onChange={handleInputChange}
/>
<IconButton
type="button"
sx={{ p: '10px' }}
aria-label="send"
onClick={handleSendClick}
>
<SendIcon />
</IconButton>
</Paper>
<LongTermMemoryDialog
open={isDialogOpen.memory}
onClose={() => toggleDialog('memory')}
/>
<AssistantDialog
open={isDialogOpen.assistant}
onClose={() => toggleDialog('assistant')}
/>
<VisionDialog
open={isDialogOpen.vision}
onClose={() => toggleDialog('vision')}
/>
<SpeechDialog
open={isDialogOpen.speech}
onClose={() => toggleDialog('speech')}
/>
<RagDialog open={isDialogOpen.rag} onClose={() => toggleDialog('rag')} />
</>
);
};
export default CustomizedInputBase;