assistant2: Allow creating agent profiles via settings (#27216)
This PR adds support for creating new agent profiles via the settings: ```json { "assistant": { "profiles": { "lua": { "name": "Lua", "tools": { "lua-interpreter": true } }, "lua-thinking": { "name": "Lua + Thinking", "tools": { "lua-interpreter": true, "thinking": true } } } } } ``` Release Notes: - N/A
This commit is contained in:
parent
48b1a43f5e
commit
4b5df2189b
6 changed files with 61 additions and 9 deletions
|
@ -1,23 +1,34 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use assistant_settings::{AgentProfile, AssistantSettings};
|
||||
use assistant_tool::{ToolSource, ToolWorkingSet};
|
||||
use collections::HashMap;
|
||||
use gpui::Entity;
|
||||
use scripting_tool::ScriptingTool;
|
||||
use settings::Settings as _;
|
||||
use ui::{prelude::*, ContextMenu, PopoverMenu, Tooltip};
|
||||
|
||||
use crate::agent_profile::AgentProfile;
|
||||
|
||||
pub struct ToolSelector {
|
||||
profiles: Vec<AgentProfile>,
|
||||
profiles: HashMap<Arc<str>, AgentProfile>,
|
||||
tools: Arc<ToolWorkingSet>,
|
||||
}
|
||||
|
||||
impl ToolSelector {
|
||||
pub fn new(tools: Arc<ToolWorkingSet>, _cx: &mut Context<Self>) -> Self {
|
||||
Self {
|
||||
profiles: vec![AgentProfile::read_only(), AgentProfile::code_writer()],
|
||||
tools,
|
||||
pub fn new(tools: Arc<ToolWorkingSet>, cx: &mut Context<Self>) -> Self {
|
||||
let settings = AssistantSettings::get_global(cx);
|
||||
let mut profiles = settings.profiles.clone();
|
||||
|
||||
let read_only = AgentProfile::read_only();
|
||||
if !profiles.contains_key(read_only.name.as_ref()) {
|
||||
profiles.insert(read_only.name.clone().into(), read_only);
|
||||
}
|
||||
|
||||
let code_writer = AgentProfile::code_writer();
|
||||
if !profiles.contains_key(code_writer.name.as_ref()) {
|
||||
profiles.insert(code_writer.name.clone().into(), code_writer);
|
||||
}
|
||||
|
||||
Self { profiles, tools }
|
||||
}
|
||||
|
||||
fn build_context_menu(
|
||||
|
@ -31,7 +42,7 @@ impl ToolSelector {
|
|||
let icon_position = IconPosition::End;
|
||||
|
||||
menu = menu.header("Profiles");
|
||||
for profile in profiles.clone() {
|
||||
for (_id, profile) in profiles.clone() {
|
||||
menu = menu.toggleable_entry(profile.name.clone(), false, icon_position, None, {
|
||||
let tools = tool_set.clone();
|
||||
move |_window, cx| {
|
||||
|
@ -44,6 +55,10 @@ impl ToolSelector {
|
|||
.filter_map(|(tool, enabled)| enabled.then(|| tool.clone()))
|
||||
.collect::<Vec<_>>(),
|
||||
);
|
||||
|
||||
if profile.tools.contains_key(ScriptingTool::NAME) {
|
||||
tools.enable_scripting_tool();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue