Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
assistant2: Reload profile when making changes to the active profile's tools (#27664)
Marshall Bowers4315b2fc8a46
diff --git a/crates/assistant2/src/assistant_configuration/manage_profiles_modal.rs b/crates/assistant2/src/assistant_configuration/manage_profiles_modal.rsindex 9c02b27b503..6df10953955 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<dyn Fs>,tools: Arc<ToolWorkingSet>,+ thread_store: WeakEntity<ThreadStore>,focus_handle: FocusHandle,mode: Mode,}@@ -93,9 +97,12 @@ impl ManageProfilesModal {workspace.register_action(|workspace, _: &ManageProfiles, window, cx| {if let Some(panel) = workspace.panel::<AssistantPanel>(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<dyn Fs>,tools: Arc<ToolWorkingSet>,+ thread_store: WeakEntity<ThreadStore>,window: &mut Window,cx: &mut Context<Self>,) -> 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.rsindex f9429b36f22..210c8cf8c61 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<Picker<ToolPickerDelegate>>,}@@ -46,6 +48,7 @@ pub struct ToolEntry {pub struct ToolPickerDelegate {tool_picker: WeakEntity<ToolPicker>,+ thread_store: WeakEntity<ThreadStore>,fs: Arc<dyn Fs>,tools: Vec<ToolEntry>,profile_id: Arc<str>,@@ -58,6 +61,7 @@ impl ToolPickerDelegate {pub fn new(fs: Arc<dyn Fs>,tool_set: Arc<ToolWorkingSet>,+ thread_store: WeakEntity<ThreadStore>,profile_id: Arc<str>,profile: AgentProfile,cx: &mut Context<ToolPicker>,@@ -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::<AssistantSettings>(self.fs.clone(), cx, {let profile_id = self.profile_id.clone();let default_profile = self.profile.clone();