@@ -18,6 +18,8 @@ interface ChatMessageAreaProps {
18
18
onRegenerateResponse ?: ( messageId : string ) => void ;
19
19
onEditMessage ?: ( messageId : string , newContent : string ) => void ;
20
20
isCurrentlyStreaming ?: boolean ;
21
+ selectedProvider : string ;
22
+ selectedModel : string ;
21
23
}
22
24
23
25
export const ChatMessageArea : React . FC < ChatMessageAreaProps > = ( {
@@ -29,6 +31,8 @@ export const ChatMessageArea: React.FC<ChatMessageAreaProps> = ({
29
31
onRegenerateResponse,
30
32
onEditMessage,
31
33
isCurrentlyStreaming = false ,
34
+ selectedProvider,
35
+ selectedModel,
32
36
} ) => {
33
37
const [ input , setInput ] = useState ( '' ) ;
34
38
const messagesEndRef = useRef < HTMLDivElement > ( null ) ;
@@ -37,6 +41,7 @@ export const ChatMessageArea: React.FC<ChatMessageAreaProps> = ({
37
41
const [ editingContent , setEditingContent ] = useState ( '' ) ;
38
42
const [ messagesList , setMessagesList ] = useState < Message [ ] > ( [ ] ) ;
39
43
const [ webSearchActive , setWebSearchActive ] = useState ( false ) ;
44
+ const [ isWebSearchAllowed , setIsWebSearchAllowed ] = useState ( false ) ;
40
45
41
46
// Scroll to bottom when messages change
42
47
useEffect ( ( ) => {
@@ -52,11 +57,25 @@ export const ChatMessageArea: React.FC<ChatMessageAreaProps> = ({
52
57
}
53
58
} , [ activeConversation , activeConversation ?. messages ] ) ;
54
59
60
+ // Load web search status on component mount
55
61
useEffect ( ( ) => {
56
- const webSearchActive = SettingsService . getInstance ( ) . getWebSearchEnabled ( ) ;
57
- setWebSearchActive ( webSearchActive ) ;
62
+ const loadWebSearchStatus = async ( ) => {
63
+ try {
64
+ const settingsService = SettingsService . getInstance ( ) ;
65
+ setWebSearchActive ( settingsService . getWebSearchEnabled ( ) ) ;
66
+ } catch ( error ) {
67
+ console . error ( 'Failed to load web search status:' , error ) ;
68
+ }
69
+ } ;
58
70
59
- } , [ SettingsService . getInstance ( ) . getWebSearchEnabled ( ) ] ) ;
71
+ loadWebSearchStatus ( ) ;
72
+ } , [ ] ) ;
73
+
74
+ useEffect ( ( ) => {
75
+ console . log ( 'Updated provider or model' ) ;
76
+ const result = ChatService . getInstance ( ) . getCurrentProviderModelCapabilities ( ) . includes ( AIServiceCapability . WebSearch ) ;
77
+ setIsWebSearchAllowed ( result ) ;
78
+ } , [ selectedProvider , selectedModel ] ) ;
60
79
61
80
const handleSubmit = ( e : FormEvent ) => {
62
81
e . preventDefault ( ) ;
@@ -183,14 +202,17 @@ export const ChatMessageArea: React.FC<ChatMessageAreaProps> = ({
183
202
return 0 ;
184
203
}
185
204
186
- const handleToggleWebSearch = ( ) => {
187
- setWebSearchActive ( ! webSearchActive ) ;
188
- SettingsService . getInstance ( ) . setWebSearchEnabled ( ! webSearchActive ) ;
189
- }
190
-
191
- const getWebSearchAllowed = ( ) => {
192
- return ChatService . getInstance ( ) . getCurrentProviderModelCapabilities ( ) . includes ( AIServiceCapability . WebSearch ) ;
193
- }
205
+ // Handle toggle web search
206
+ const handleToggleWebSearch = async ( ) => {
207
+ try {
208
+ const newStatus = ! webSearchActive ;
209
+ const settingsService = SettingsService . getInstance ( ) ;
210
+ await settingsService . setWebSearchEnabled ( newStatus ) ;
211
+ setWebSearchActive ( newStatus ) ;
212
+ } catch ( error ) {
213
+ console . error ( 'Failed to toggle web search:' , error ) ;
214
+ }
215
+ } ;
194
216
195
217
// If no active conversation is selected
196
218
if ( ! activeConversation ) {
@@ -355,7 +377,7 @@ export const ChatMessageArea: React.FC<ChatMessageAreaProps> = ({
355
377
356
378
< div className = "flex flex-row items-center justify-between px-2" >
357
379
{
358
- getWebSearchAllowed ( ) ? (
380
+ isWebSearchAllowed ? (
359
381
< button
360
382
type = "button"
361
383
onClick = { handleToggleWebSearch }
0 commit comments