diff --git a/crates/assistant2/src/assistant_configuration/manage_profiles_modal.rs b/crates/assistant2/src/assistant_configuration/manage_profiles_modal.rs index 9c02b27b50331e517e19bb0610f580a5c2e58b65..6df10953955595594df8aae34d42e44a706d958c 100644 --- a/crates/assistant2/src/assistant_configuration/manage_profiles_modal.rs +++ b/crates/assistant2/src/assistant_configuration/manage_profiles_modal.rs @@ -10,7 +10,10 @@ use assistant_tool::ToolWorkingSet; use convert_case::{Case, Casing as _}; use editor::Editor; use fs::Fs; -use gpui::{prelude::*, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, Subscription}; +use gpui::{ + prelude::*, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, Subscription, + WeakEntity, +}; use settings::{update_settings_file, Settings as _}; use ui::{prelude::*, ListItem, ListItemSpacing, ListSeparator, Navigable, NavigableEntry}; use workspace::{ModalView, Workspace}; @@ -18,7 +21,7 @@ use workspace::{ModalView, Workspace}; use crate::assistant_configuration::manage_profiles_modal::profile_modal_header::ProfileModalHeader; use crate::assistant_configuration::profile_picker::{ProfilePicker, ProfilePickerDelegate}; use crate::assistant_configuration::tool_picker::{ToolPicker, ToolPickerDelegate}; -use crate::{AssistantPanel, ManageProfiles}; +use crate::{AssistantPanel, ManageProfiles, ThreadStore}; enum Mode { ChooseProfile { @@ -80,6 +83,7 @@ pub struct NewProfileMode { pub struct ManageProfilesModal { fs: Arc, tools: Arc, + thread_store: WeakEntity, focus_handle: FocusHandle, mode: Mode, } @@ -93,9 +97,12 @@ impl ManageProfilesModal { workspace.register_action(|workspace, _: &ManageProfiles, window, cx| { if let Some(panel) = workspace.panel::(cx) { let fs = workspace.app_state().fs.clone(); - let thread_store = panel.read(cx).thread_store().read(cx); - let tools = thread_store.tools(); - workspace.toggle_modal(window, cx, |window, cx| Self::new(fs, tools, window, cx)) + let thread_store = panel.read(cx).thread_store(); + let tools = thread_store.read(cx).tools(); + let thread_store = thread_store.downgrade(); + workspace.toggle_modal(window, cx, |window, cx| { + Self::new(fs, tools, thread_store, window, cx) + }) } }); } @@ -103,6 +110,7 @@ impl ManageProfilesModal { pub fn new( fs: Arc, tools: Arc, + thread_store: WeakEntity, window: &mut Window, cx: &mut Context, ) -> Self { @@ -111,6 +119,7 @@ impl ManageProfilesModal { Self { fs, tools, + thread_store, focus_handle, mode: Mode::choose_profile(window, cx), } @@ -168,6 +177,7 @@ impl ManageProfilesModal { let delegate = ToolPickerDelegate::new( self.fs.clone(), self.tools.clone(), + self.thread_store.clone(), profile_id.clone(), profile, cx, diff --git a/crates/assistant2/src/assistant_configuration/tool_picker.rs b/crates/assistant2/src/assistant_configuration/tool_picker.rs index f9429b36f22e63bf8b9e53ffd4d17c37c59d576a..210c8cf8c611ac8e55355fcaaff5d0b301ff6342 100644 --- a/crates/assistant2/src/assistant_configuration/tool_picker.rs +++ b/crates/assistant2/src/assistant_configuration/tool_picker.rs @@ -9,10 +9,12 @@ use fs::Fs; use fuzzy::{match_strings, StringMatch, StringMatchCandidate}; use gpui::{App, Context, DismissEvent, Entity, EventEmitter, Focusable, Task, WeakEntity, Window}; use picker::{Picker, PickerDelegate}; -use settings::update_settings_file; +use settings::{update_settings_file, Settings as _}; use ui::{prelude::*, HighlightedLabel, ListItem, ListItemSpacing}; use util::ResultExt as _; +use crate::ThreadStore; + pub struct ToolPicker { picker: Entity>, } @@ -46,6 +48,7 @@ pub struct ToolEntry { pub struct ToolPickerDelegate { tool_picker: WeakEntity, + thread_store: WeakEntity, fs: Arc, tools: Vec, profile_id: Arc, @@ -58,6 +61,7 @@ impl ToolPickerDelegate { pub fn new( fs: Arc, tool_set: Arc, + thread_store: WeakEntity, profile_id: Arc, profile: AgentProfile, cx: &mut Context, @@ -73,6 +77,7 @@ impl ToolPickerDelegate { Self { tool_picker: cx.entity().downgrade(), + thread_store, fs, tools: tool_entries, profile_id, @@ -183,6 +188,15 @@ impl PickerDelegate for ToolPickerDelegate { } }; + let active_profile_id = &AssistantSettings::get_global(cx).default_profile; + if active_profile_id == &self.profile_id { + self.thread_store + .update(cx, |this, _cx| { + this.load_profile(&self.profile); + }) + .log_err(); + } + update_settings_file::(self.fs.clone(), cx, { let profile_id = self.profile_id.clone(); let default_profile = self.profile.clone();