Skip to content

Commit

Permalink
Merge branch 'dev' into multiple-agents-support
Browse files Browse the repository at this point in the history
  • Loading branch information
joulei committed Dec 11, 2024
2 parents d62f0aa + 69a90d9 commit ca9af02
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
6 changes: 1 addition & 5 deletions src/chat/chat_history.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::chat_history_card::{ChatHistoryCardAction, ChatHistoryCardWidgetRefExt};
use super::chat_history_card::ChatHistoryCardWidgetRefExt;
use crate::chat::entity_button::EntityButtonWidgetRefExt;
use crate::data::chats::chat::ChatID;
use crate::data::store::Store;
Expand Down Expand Up @@ -187,10 +187,6 @@ impl WidgetMatchEvent for ChatHistory {

if self.button(id!(new_chat_button)).clicked(&actions) {
store.chats.create_empty_chat();

// Make sure text input is focused and other necessary setup happens.
cx.action(ChatHistoryCardAction::ChatSelected);

self.redraw(cx);
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/chat/chat_history_card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ impl WidgetMatchEvent for ChatHistoryCard {

if let Some(fe) = self.view(id!(content)).finger_down(actions) {
if fe.tap_count == 1 {
cx.action(ChatHistoryCardAction::ChatSelected);
let store = scope.data.get_mut::<Store>().unwrap();
store.chats.set_current_chat(self.chat_id);
self.redraw(cx);
Expand Down Expand Up @@ -584,7 +583,6 @@ impl ChatHistoryCardRef {
#[derive(Clone, DefaultNone, Eq, Hash, PartialEq, Debug)]
pub enum ChatHistoryCardAction {
None,
ChatSelected,
ActivateTitleEdition(ChatID),
MenuClosed(ChatID),
DeleteChatOptionSelected(ChatID),
Expand Down
42 changes: 24 additions & 18 deletions src/chat/chat_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use crate::{
};

use super::{
chat_history_card::ChatHistoryCardAction, model_selector_list::ModelSelectorListAction,
prompt_input::PromptInputWidgetExt, shared::ChatAgentAvatarWidgetRefExt,
model_selector_list::ModelSelectorListAction, prompt_input::PromptInputWidgetExt,
shared::ChatAgentAvatarWidgetRefExt,
};

live_design! {
Expand Down Expand Up @@ -394,15 +394,25 @@ pub struct ChatPanel {

#[rust(false)]
focus_on_prompt_input_pending: bool,

#[rust]
current_chat_id: Option<ChatID>,
}

impl Widget for ChatPanel {
fn handle_event(&mut self, cx: &mut Cx, event: &Event, scope: &mut Scope) {
let store = scope.data.get_mut::<Store>().unwrap();

if store.chats.get_current_chat_id() != self.current_chat_id {
self.current_chat_id = store.chats.get_current_chat_id();
self.reset_scroll_messages(store);
self.redraw(cx);
}

self.view.handle_event(cx, event, scope);
self.widget_match_event(cx, event, scope);

let store = scope.data.get_mut::<Store>().unwrap();
self.update_state(store);
self.update_state(scope);
}

fn draw_walk(&mut self, cx: &mut Cx2d, scope: &mut Scope, walk: Walk) -> DrawStep {
Expand Down Expand Up @@ -484,12 +494,6 @@ impl WidgetMatchEvent for ChatPanel {
}

for action in actions.iter() {
if let ChatHistoryCardAction::ChatSelected = action.cast() {
self.reset_scroll_messages(&store);
self.focus_on_prompt_input_pending = true;
self.redraw(cx);
}

if let ModelSelectorListAction::AddedOrDeletedModel = action.cast() {
self.redraw(cx);
}
Expand Down Expand Up @@ -522,7 +526,7 @@ impl WidgetMatchEvent for ChatPanel {
}
ChatLineAction::Edit(id, updated, regenerate) => {
if regenerate {
self.send_message(cx, store, updated, Some(id));
self.send_message(cx, scope, updated, Some(id));
return;
} else {
store.edit_chat_message(id, updated);
Expand Down Expand Up @@ -570,7 +574,9 @@ impl WidgetMatchEvent for ChatPanel {
}

impl ChatPanel {
fn update_state(&mut self, store: &mut Store) {
fn update_state(&mut self, scope: &mut Scope) {
let store = scope.data.get_mut::<Store>().unwrap();

let chat_entity = store
.chats
.get_current_chat()
Expand Down Expand Up @@ -744,20 +750,18 @@ impl ChatPanel {
.button(id!(main_prompt_input.prompt_send_button))
.clicked(&actions)
{
let store = scope.data.get_mut::<Store>().unwrap();
self.send_message(cx, store, prompt_input.text(), None);
self.send_message(cx, scope, prompt_input.text(), None);
}

if let Some(prompt) = prompt_input.returned(actions) {
let store = scope.data.get_mut::<Store>().unwrap();
self.send_message(cx, store, prompt, None);
self.send_message(cx, scope, prompt, None);
}
}

fn send_message(
&mut self,
cx: &mut Cx,
store: &mut Store,
scope: &mut Scope,
prompt: String,
regenerate_from: Option<usize>,
) {
Expand All @@ -767,7 +771,7 @@ impl ChatPanel {
}

// Let's confirm we're in an appropriate state to send a message
self.update_state(store);
self.update_state(scope);
if matches!(
self.state,
State::ModelSelectedWithChat {
Expand All @@ -777,6 +781,8 @@ impl ChatPanel {
..
} | State::ModelSelectedWithEmptyChat { is_loading: false }
) {
let store = scope.data.get_mut::<Store>().unwrap();

if let Some(entity_selected) = &self
.prompt_input(id!(main_prompt_input))
.borrow()
Expand Down

0 comments on commit ca9af02

Please sign in to comment.