Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 50 additions & 8 deletions crates/agent_ui/src/config_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct ConfigOptionsView {
selectors: Vec<Entity<ConfigOptionSelector>>,
agent_server: Rc<dyn AgentServer>,
fs: Arc<dyn Fs>,
persist_selected_categories_as_defaults: Vec<acp::SessionConfigOptionCategory>,
config_option_ids: Vec<acp::SessionConfigId>,
_refresh_task: Task<()>,
}
Expand All @@ -37,10 +38,18 @@ impl ConfigOptionsView {
config_options: Rc<dyn AgentSessionConfigOptions>,
agent_server: Rc<dyn AgentServer>,
fs: Arc<dyn Fs>,
persist_selected_categories_as_defaults: Vec<acp::SessionConfigOptionCategory>,
window: &mut Window,
cx: &mut Context<Self>,
) -> Self {
let selectors = Self::build_selectors(&config_options, &agent_server, &fs, window, cx);
let selectors = Self::build_selectors(
&config_options,
&agent_server,
&fs,
&persist_selected_categories_as_defaults,
window,
cx,
);
let config_option_ids = Self::config_option_ids(&config_options);

let rx = config_options.watch(cx);
Expand All @@ -61,6 +70,7 @@ impl ConfigOptionsView {
selectors,
agent_server,
fs,
persist_selected_categories_as_defaults,
config_option_ids,
_refresh_task: refresh_task,
}
Expand All @@ -72,7 +82,7 @@ impl ConfigOptionsView {
window: &mut Window,
cx: &mut Context<Self>,
) -> bool {
let Some(config_id) = self.first_config_option_id(category) else {
let Some(config_id) = self.first_config_option_id(category.clone()) else {
return false;
};

Expand All @@ -93,14 +103,26 @@ impl ConfigOptionsView {
favorites_only: bool,
cx: &mut Context<Self>,
) -> bool {
let Some(config_id) = self.first_config_option_id(category) else {
let Some(config_id) = self.first_config_option_id(category.clone()) else {
return false;
};

let Some(next_value) = self.next_value_for_config(&config_id, favorites_only, cx) else {
return false;
};

if self
.persist_selected_categories_as_defaults
.contains(&category)
{
self.agent_server.set_default_config_option(
config_id.0.as_ref(),
Some(next_value.0.as_ref()),
self.fs.clone(),
cx,
);
}

let task = self
.config_options
.set_config_option(config_id, next_value, cx);
Expand Down Expand Up @@ -191,6 +213,7 @@ impl ConfigOptionsView {
&self.config_options,
&self.agent_server,
&self.fs,
&self.persist_selected_categories_as_defaults,
window,
cx,
);
Expand All @@ -201,6 +224,7 @@ impl ConfigOptionsView {
config_options: &Rc<dyn AgentSessionConfigOptions>,
agent_server: &Rc<dyn AgentServer>,
fs: &Arc<dyn Fs>,
persist_selected_categories_as_defaults: &[acp::SessionConfigOptionCategory],
window: &mut Window,
cx: &mut Context<Self>,
) -> Vec<Entity<ConfigOptionSelector>> {
Expand All @@ -211,12 +235,17 @@ impl ConfigOptionsView {
let config_options = config_options.clone();
let agent_server = agent_server.clone();
let fs = fs.clone();
let should_persist_selected_value_as_default =
option.category.as_ref().is_some_and(|category| {
persist_selected_categories_as_defaults.contains(category)
});
cx.new(|cx| {
ConfigOptionSelector::new(
config_options,
option.id.clone(),
agent_server,
fs,
should_persist_selected_value_as_default,
window,
cx,
)
Expand Down Expand Up @@ -253,15 +282,15 @@ impl ConfigOptionSelector {
config_id: acp::SessionConfigId,
agent_server: Rc<dyn AgentServer>,
fs: Arc<dyn Fs>,
should_persist_selected_value_as_default: bool,
window: &mut Window,
cx: &mut Context<Self>,
) -> Self {
let option_count = config_options
let option = config_options
.config_options()
.iter()
.find(|opt| opt.id == config_id)
.map(count_config_options)
.unwrap_or(0);
.into_iter()
.find(|opt| opt.id == config_id);
let option_count = option.as_ref().map(count_config_options).unwrap_or(0);

let is_searchable = option_count >= PICKER_THRESHOLD;

Expand All @@ -276,6 +305,7 @@ impl ConfigOptionSelector {
config_id,
agent_server,
fs,
should_persist_selected_value_as_default,
window,
picker_cx,
);
Expand Down Expand Up @@ -409,6 +439,7 @@ struct ConfigOptionPickerDelegate {
config_id: acp::SessionConfigId,
agent_server: Rc<dyn AgentServer>,
fs: Arc<dyn Fs>,
should_persist_selected_value_as_default: bool,
filtered_entries: Vec<ConfigOptionPickerEntry>,
all_options: Vec<ConfigOptionValue>,
selected_index: usize,
Expand All @@ -423,6 +454,7 @@ impl ConfigOptionPickerDelegate {
config_id: acp::SessionConfigId,
agent_server: Rc<dyn AgentServer>,
fs: Arc<dyn Fs>,
should_persist_selected_value_as_default: bool,
window: &mut Window,
cx: &mut Context<Picker<Self>>,
) -> Self {
Expand Down Expand Up @@ -459,6 +491,7 @@ impl ConfigOptionPickerDelegate {
config_id,
agent_server,
fs,
should_persist_selected_value_as_default,
filtered_entries,
all_options,
selected_index,
Expand Down Expand Up @@ -564,6 +597,15 @@ impl PickerDelegate for ConfigOptionPickerDelegate {
self.fs.clone(),
cx,
);
} else {
if self.should_persist_selected_value_as_default {
self.agent_server.set_default_config_option(
self.config_id.0.as_ref(),
Some(option.value.0.as_ref()),
self.fs.clone(),
cx,
);
}
}

let task = self.config_options.set_config_option(
Expand Down
9 changes: 8 additions & 1 deletion crates/agent_ui/src/conversation_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,14 @@ impl ConversationView {
let fs = self.project.read(cx).fs().clone();
config_options_view =
Some(cx.new(|cx| {
ConfigOptionsView::new(config_options, agent_server, fs, window, cx)
ConfigOptionsView::new(
config_options,
agent_server,
fs,
vec![acp::SessionConfigOptionCategory::ThoughtLevel],
window,
cx,
)
}));
model_selector = None;
mode_selector = None;
Expand Down
42 changes: 38 additions & 4 deletions crates/agent_ui/src/conversation_view/thread_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3908,9 +3908,9 @@ impl ThreadView {
.cloned()
});

let label = selected
let active_effort = selected.clone().or(default_effort_level);
let label = active_effort
.clone()
.or(default_effort_level)
.map_or("Select Effort".into(), |effort| effort.name);

let (label_color, icon) = if self.thinking_effort_menu_handle.is_deployed() {
Expand Down Expand Up @@ -3966,11 +3966,16 @@ impl ThreadView {
tooltip,
)
.menu(move |window, cx| {
Some(ContextMenu::build(window, cx, |mut menu, _window, _cx| {
Some(ContextMenu::build(window, cx, |mut menu, window, cx| {
menu = menu.header("Change Thinking Effort");
let selected_index = active_effort.as_ref().and_then(|active_effort| {
supported_effort_levels
.iter()
.position(|level| level.value == active_effort.value)
});

for effort_level in supported_effort_levels.clone() {
let is_selected = selected
let is_selected = active_effort
.as_ref()
.is_some_and(|selected| selected.value == effort_level.value);
let entry = ContextMenuEntry::new(effort_level.name)
Expand Down Expand Up @@ -4027,6 +4032,13 @@ impl ThreadView {
}));
}

if let Some(selected_index) = selected_index {
menu.select_first(&menu::SelectFirst, window, cx);
for _ in 0..selected_index {
menu.select_next(&menu::SelectNext, window, cx);
}
}

menu
}))
})
Expand Down Expand Up @@ -9023,6 +9035,15 @@ impl ThreadView {

fn cycle_thinking_effort(&mut self, cx: &mut Context<Self>) {
let Some(thread) = self.as_native_thread(cx) else {
if let Some(config_options_view) = self.config_options_view.clone() {
config_options_view.update(cx, |view, cx| {
view.cycle_category_option(
acp::SessionConfigOptionCategory::ThoughtLevel,
false,
cx,
)
});
}
return;
};

Expand Down Expand Up @@ -9081,6 +9102,19 @@ impl ThreadView {
window: &mut Window,
cx: &mut Context<Self>,
) {
if self.as_native_thread(cx).is_none() {
if let Some(config_options_view) = self.config_options_view.clone() {
config_options_view.update(cx, |view, cx| {
view.toggle_category_picker(
acp::SessionConfigOptionCategory::ThoughtLevel,
window,
cx,
)
});
}
return;
}

let menu_handle = self.thinking_effort_menu_handle.clone();
window.defer(cx, move |window, cx| {
menu_handle.toggle(window, cx);
Expand Down
Loading