assistant2: Order agent profiles in the order they are defined in settings (#27255)

This PR updates the ordering of the agent profiles in the tool selector
to respect the order they are defined in in the settings instead of
sorting them alphabetically.

This gives the user more control, and allows them to order the profiles
as they desire.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2025-03-21 11:38:02 -04:00 committed by GitHub
parent 6397872c49
commit 0de5c2ed53
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 17 additions and 15 deletions

3
Cargo.lock generated
View file

@ -472,6 +472,7 @@ dependencies = [
"heed", "heed",
"html_to_markdown", "html_to_markdown",
"http_client", "http_client",
"indexmap",
"indoc", "indoc",
"itertools 0.14.0", "itertools 0.14.0",
"language", "language",
@ -608,11 +609,11 @@ version = "0.1.0"
dependencies = [ dependencies = [
"anthropic", "anthropic",
"anyhow", "anyhow",
"collections",
"deepseek", "deepseek",
"feature_flags", "feature_flags",
"fs", "fs",
"gpui", "gpui",
"indexmap",
"language_model", "language_model",
"lmstudio", "lmstudio",
"log", "log",

View file

@ -44,6 +44,7 @@ gpui.workspace = true
heed.workspace = true heed.workspace = true
html_to_markdown.workspace = true html_to_markdown.workspace = true
http_client.workspace = true http_client.workspace = true
indexmap.workspace = true
itertools.workspace = true itertools.workspace = true
language.workspace = true language.workspace = true
language_model.workspace = true language_model.workspace = true

View file

@ -2,14 +2,14 @@ use std::sync::Arc;
use assistant_settings::{AgentProfile, AssistantSettings}; use assistant_settings::{AgentProfile, AssistantSettings};
use assistant_tool::{ToolSource, ToolWorkingSet}; use assistant_tool::{ToolSource, ToolWorkingSet};
use collections::BTreeMap;
use gpui::{Entity, Subscription}; use gpui::{Entity, Subscription};
use indexmap::IndexMap;
use scripting_tool::ScriptingTool; use scripting_tool::ScriptingTool;
use settings::{Settings as _, SettingsStore}; use settings::{Settings as _, SettingsStore};
use ui::{prelude::*, ContextMenu, PopoverMenu, Tooltip}; use ui::{prelude::*, ContextMenu, PopoverMenu, Tooltip};
pub struct ToolSelector { pub struct ToolSelector {
profiles: BTreeMap<Arc<str>, AgentProfile>, profiles: IndexMap<Arc<str>, AgentProfile>,
tools: Arc<ToolWorkingSet>, tools: Arc<ToolWorkingSet>,
_subscriptions: Vec<Subscription>, _subscriptions: Vec<Subscription>,
} }
@ -21,7 +21,7 @@ impl ToolSelector {
}); });
let mut this = Self { let mut this = Self {
profiles: BTreeMap::default(), profiles: IndexMap::default(),
tools, tools,
_subscriptions: vec![settings_subscription], _subscriptions: vec![settings_subscription],
}; };
@ -33,7 +33,7 @@ impl ToolSelector {
fn refresh_profiles(&mut self, cx: &mut Context<Self>) { fn refresh_profiles(&mut self, cx: &mut Context<Self>) {
let settings = AssistantSettings::get_global(cx); let settings = AssistantSettings::get_global(cx);
self.profiles = BTreeMap::from_iter(settings.profiles.clone()); self.profiles = settings.profiles.clone();
} }
fn build_context_menu( fn build_context_menu(

View file

@ -14,9 +14,9 @@ path = "src/assistant_settings.rs"
[dependencies] [dependencies]
anthropic = { workspace = true, features = ["schemars"] } anthropic = { workspace = true, features = ["schemars"] }
anyhow.workspace = true anyhow.workspace = true
collections.workspace = true
feature_flags.workspace = true feature_flags.workspace = true
gpui.workspace = true gpui.workspace = true
indexmap.workspace = true
language_model.workspace = true language_model.workspace = true
lmstudio = { workspace = true, features = ["schemars"] } lmstudio = { workspace = true, features = ["schemars"] }
log.workspace = true log.workspace = true

View file

@ -1,20 +1,20 @@
use std::sync::Arc; use std::sync::Arc;
use collections::HashMap;
use gpui::SharedString; use gpui::SharedString;
use indexmap::IndexMap;
/// A profile for the Zed Agent that controls its behavior. /// A profile for the Zed Agent that controls its behavior.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct AgentProfile { pub struct AgentProfile {
/// The name of the profile. /// The name of the profile.
pub name: SharedString, pub name: SharedString,
pub tools: HashMap<Arc<str>, bool>, pub tools: IndexMap<Arc<str>, bool>,
#[allow(dead_code)] #[allow(dead_code)]
pub context_servers: HashMap<Arc<str>, ContextServerPreset>, pub context_servers: IndexMap<Arc<str>, ContextServerPreset>,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct ContextServerPreset { pub struct ContextServerPreset {
#[allow(dead_code)] #[allow(dead_code)]
pub tools: HashMap<Arc<str>, bool>, pub tools: IndexMap<Arc<str>, bool>,
} }

View file

@ -4,10 +4,10 @@ use std::sync::Arc;
use ::open_ai::Model as OpenAiModel; use ::open_ai::Model as OpenAiModel;
use anthropic::Model as AnthropicModel; use anthropic::Model as AnthropicModel;
use collections::HashMap;
use deepseek::Model as DeepseekModel; use deepseek::Model as DeepseekModel;
use feature_flags::FeatureFlagAppExt; use feature_flags::FeatureFlagAppExt;
use gpui::{App, Pixels}; use gpui::{App, Pixels};
use indexmap::IndexMap;
use language_model::{CloudModel, LanguageModel}; use language_model::{CloudModel, LanguageModel};
use lmstudio::Model as LmStudioModel; use lmstudio::Model as LmStudioModel;
use ollama::Model as OllamaModel; use ollama::Model as OllamaModel;
@ -71,7 +71,7 @@ pub struct AssistantSettings {
pub inline_alternatives: Vec<LanguageModelSelection>, pub inline_alternatives: Vec<LanguageModelSelection>,
pub using_outdated_settings_version: bool, pub using_outdated_settings_version: bool,
pub enable_experimental_live_diffs: bool, pub enable_experimental_live_diffs: bool,
pub profiles: HashMap<Arc<str>, AgentProfile>, pub profiles: IndexMap<Arc<str>, AgentProfile>,
} }
impl AssistantSettings { impl AssistantSettings {
@ -362,7 +362,7 @@ pub struct AssistantSettingsContentV2 {
/// Default: false /// Default: false
enable_experimental_live_diffs: Option<bool>, enable_experimental_live_diffs: Option<bool>,
#[schemars(skip)] #[schemars(skip)]
profiles: Option<HashMap<Arc<str>, AgentProfileContent>>, profiles: Option<IndexMap<Arc<str>, AgentProfileContent>>,
} }
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)] #[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
@ -402,7 +402,7 @@ impl Default for LanguageModelSelection {
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] #[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)]
pub struct AgentProfileContent { pub struct AgentProfileContent {
pub name: Arc<str>, pub name: Arc<str>,
pub tools: HashMap<Arc<str>, bool>, pub tools: IndexMap<Arc<str>, bool>,
} }
#[derive(Clone, Serialize, Deserialize, JsonSchema, Debug)] #[derive(Clone, Serialize, Deserialize, JsonSchema, Debug)]
@ -509,7 +509,7 @@ impl Settings for AssistantSettings {
AgentProfile { AgentProfile {
name: profile.name.into(), name: profile.name.into(),
tools: profile.tools, tools: profile.tools,
context_servers: HashMap::default(), context_servers: IndexMap::default(),
}, },
) )
})); }));