assistant2: Extract method for adding a new profile to the settings (#27810)
This PR extracts a method for adding a new profile to the settings to reduce the amount of code required inline. Release Notes: - N/A
This commit is contained in:
parent
9bbb1e5476
commit
8a212be0b1
2 changed files with 46 additions and 43 deletions
|
@ -2,10 +2,7 @@ mod profile_modal_header;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use assistant_settings::{
|
use assistant_settings::{AgentProfile, AssistantSettings};
|
||||||
AgentProfile, AgentProfileContent, AssistantSettings, AssistantSettingsContent,
|
|
||||||
ContextServerPresetContent, VersionedAssistantSettingsContent,
|
|
||||||
};
|
|
||||||
use assistant_tool::ToolWorkingSet;
|
use assistant_tool::ToolWorkingSet;
|
||||||
use convert_case::{Case, Casing as _};
|
use convert_case::{Case, Casing as _};
|
||||||
use editor::Editor;
|
use editor::Editor;
|
||||||
|
@ -18,6 +15,7 @@ use settings::{Settings as _, update_settings_file};
|
||||||
use ui::{
|
use ui::{
|
||||||
KeyBinding, ListItem, ListItemSpacing, ListSeparator, Navigable, NavigableEntry, prelude::*,
|
KeyBinding, ListItem, ListItemSpacing, ListSeparator, Navigable, NavigableEntry, prelude::*,
|
||||||
};
|
};
|
||||||
|
use util::ResultExt as _;
|
||||||
use workspace::{ModalView, Workspace};
|
use workspace::{ModalView, Workspace};
|
||||||
|
|
||||||
use crate::assistant_configuration::manage_profiles_modal::profile_modal_header::ProfileModalHeader;
|
use crate::assistant_configuration::manage_profiles_modal::profile_modal_header::ProfileModalHeader;
|
||||||
|
@ -261,37 +259,8 @@ impl ManageProfilesModal {
|
||||||
|
|
||||||
fn create_profile(&self, profile_id: Arc<str>, profile: AgentProfile, cx: &mut Context<Self>) {
|
fn create_profile(&self, profile_id: Arc<str>, profile: AgentProfile, cx: &mut Context<Self>) {
|
||||||
update_settings_file::<AssistantSettings>(self.fs.clone(), cx, {
|
update_settings_file::<AssistantSettings>(self.fs.clone(), cx, {
|
||||||
move |settings, _cx| match settings {
|
move |settings, _cx| {
|
||||||
AssistantSettingsContent::Versioned(VersionedAssistantSettingsContent::V2(
|
settings.create_profile(profile_id, profile).log_err();
|
||||||
settings,
|
|
||||||
)) => {
|
|
||||||
let profiles = settings.profiles.get_or_insert_default();
|
|
||||||
if profiles.contains_key(&profile_id) {
|
|
||||||
log::error!("profile with ID '{profile_id}' already exists");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
profiles.insert(
|
|
||||||
profile_id,
|
|
||||||
AgentProfileContent {
|
|
||||||
name: profile.name.into(),
|
|
||||||
tools: profile.tools,
|
|
||||||
context_servers: profile
|
|
||||||
.context_servers
|
|
||||||
.into_iter()
|
|
||||||
.map(|(server_id, preset)| {
|
|
||||||
(
|
|
||||||
server_id,
|
|
||||||
ContextServerPresetContent {
|
|
||||||
tools: preset.tools,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.collect(),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ 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 anyhow::{Result, bail};
|
||||||
use deepseek::Model as DeepseekModel;
|
use deepseek::Model as DeepseekModel;
|
||||||
use feature_flags::{Assistant2FeatureFlag, FeatureFlagAppExt};
|
use feature_flags::{Assistant2FeatureFlag, FeatureFlagAppExt};
|
||||||
use gpui::{App, Pixels};
|
use gpui::{App, Pixels};
|
||||||
|
@ -325,15 +326,48 @@ impl AssistantSettingsContent {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_profile(&mut self, profile_id: Arc<str>) {
|
pub fn set_profile(&mut self, profile_id: Arc<str>) {
|
||||||
match self {
|
let AssistantSettingsContent::Versioned(VersionedAssistantSettingsContent::V2(settings)) =
|
||||||
AssistantSettingsContent::Versioned(settings) => match settings {
|
self
|
||||||
VersionedAssistantSettingsContent::V2(settings) => {
|
else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
settings.default_profile = Some(profile_id);
|
settings.default_profile = Some(profile_id);
|
||||||
}
|
}
|
||||||
VersionedAssistantSettingsContent::V1(_) => {}
|
|
||||||
},
|
pub fn create_profile(&mut self, profile_id: Arc<str>, profile: AgentProfile) -> Result<()> {
|
||||||
AssistantSettingsContent::Legacy(_) => {}
|
let AssistantSettingsContent::Versioned(VersionedAssistantSettingsContent::V2(settings)) =
|
||||||
|
self
|
||||||
|
else {
|
||||||
|
return Ok(());
|
||||||
|
};
|
||||||
|
|
||||||
|
let profiles = settings.profiles.get_or_insert_default();
|
||||||
|
if profiles.contains_key(&profile_id) {
|
||||||
|
bail!("profile with ID '{profile_id}' already exists");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
profiles.insert(
|
||||||
|
profile_id,
|
||||||
|
AgentProfileContent {
|
||||||
|
name: profile.name.into(),
|
||||||
|
tools: profile.tools,
|
||||||
|
context_servers: profile
|
||||||
|
.context_servers
|
||||||
|
.into_iter()
|
||||||
|
.map(|(server_id, preset)| {
|
||||||
|
(
|
||||||
|
server_id,
|
||||||
|
ContextServerPresetContent {
|
||||||
|
tools: preset.tools,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue