1
1
use makepad_widgets:: * ;
2
- use moly_protocol:: data:: FileID ;
3
2
use std:: cell:: { Ref , RefCell , RefMut } ;
4
3
5
4
use crate :: {
6
5
chat:: {
7
6
chat_line:: { ChatLineAction , ChatLineWidgetRefExt } ,
8
- model_selector:: ModelSelectorWidgetExt ,
9
7
model_selector_item:: ModelSelectorAction ,
10
8
} ,
11
9
data:: {
@@ -16,8 +14,8 @@ use crate::{
16
14
} ;
17
15
18
16
use super :: {
19
- chat_history_card:: ChatHistoryCardAction , prompt_input :: PromptInputWidgetExt ,
20
- shared:: ChatAgentAvatarWidgetRefExt ,
17
+ chat_history_card:: ChatHistoryCardAction , model_selector_list :: ModelSelectorListAction ,
18
+ prompt_input :: PromptInputWidgetExt , shared:: ChatAgentAvatarWidgetRefExt ,
21
19
} ;
22
20
23
21
live_design ! {
@@ -491,6 +489,10 @@ impl WidgetMatchEvent for ChatPanel {
491
489
self . redraw ( cx) ;
492
490
}
493
491
492
+ if let ModelSelectorListAction :: AddedOrDeletedModel = action. cast ( ) {
493
+ self . redraw ( cx) ;
494
+ }
495
+
494
496
match action. cast ( ) {
495
497
ChatAction :: Start ( handler) => match handler {
496
498
ChatHandler :: Model ( file_id) => {
@@ -568,32 +570,29 @@ impl ChatPanel {
568
570
. get_current_chat ( )
569
571
. and_then ( |c| c. borrow ( ) . associated_entity . clone ( ) ) ;
570
572
571
- self . state = match chat_entity {
572
- Some ( _ ) => {
573
- // Model or Agent is selected
574
- let is_loading = store . chats . model_loader . is_loading ( ) ;
575
-
576
- store . chats . get_current_chat ( ) . map_or (
577
- State :: ModelSelectedWithEmptyChat { is_loading } ,
578
- |chat| {
579
- if chat. borrow ( ) . messages . is_empty ( ) {
580
- State :: ModelSelectedWithEmptyChat { is_loading }
581
- } else {
582
- State :: ModelSelectedWithChat {
583
- is_loading ,
584
- sticked_to_bottom : self . portal_list_end_reached
585
- || ! matches ! ( self . state , State :: ModelSelectedWithChat { .. } ) ,
586
- receiving_response : chat . borrow ( ) . is_receiving ( ) ,
587
- was_cancelled : chat. borrow ( ) . was_cancelled ( ) ,
588
- }
573
+ self . state = if chat_entity. is_none ( ) && store . chats . loaded_model . is_none ( ) {
574
+ State :: NoModelSelected
575
+ } else {
576
+ // Model or Agent is selected
577
+ let is_loading = store . chats . model_loader . is_loading ( ) ;
578
+
579
+ store . chats . get_current_chat ( ) . map_or (
580
+ State :: ModelSelectedWithEmptyChat { is_loading } ,
581
+ | chat| {
582
+ if chat . borrow ( ) . messages . is_empty ( ) {
583
+ State :: ModelSelectedWithEmptyChat { is_loading }
584
+ } else {
585
+ State :: ModelSelectedWithChat {
586
+ is_loading ,
587
+ sticked_to_bottom : self . portal_list_end_reached
588
+ || ! matches ! ( self . state , State :: ModelSelectedWithChat { .. } ) ,
589
+ receiving_response : chat. borrow ( ) . is_receiving ( ) ,
590
+ was_cancelled : chat . borrow ( ) . was_cancelled ( ) ,
589
591
}
590
- } ,
591
- )
592
- }
593
- None => {
594
- State :: NoModelSelected
595
- }
596
- } ;
592
+ }
593
+ } ,
594
+ )
595
+ }
597
596
}
598
597
599
598
fn update_prompt_input ( & mut self , cx : & mut Cx ) {
@@ -666,8 +665,12 @@ impl ChatPanel {
666
665
} ,
667
666
) ;
668
667
669
- let send_button = self . prompt_input ( id ! ( main_prompt_input) ) . button ( id ! ( prompt_send_button) ) ;
670
- let stop_button = self . prompt_input ( id ! ( main_prompt_input) ) . button ( id ! ( prompt_stop_button) ) ;
668
+ let send_button = self
669
+ . prompt_input ( id ! ( main_prompt_input) )
670
+ . button ( id ! ( prompt_send_button) ) ;
671
+ let stop_button = self
672
+ . prompt_input ( id ! ( main_prompt_input) )
673
+ . button ( id ! ( prompt_stop_button) ) ;
671
674
match button {
672
675
PromptInputButton :: Send => {
673
676
// The send button is enabled or not based on the prompt input
0 commit comments