assistant2: Add an option to enable/disable all tools (#26544)

This PR adds an option to enable or disable all tools in the tool
selector.

<img width="1297" alt="Screenshot 2025-03-12 at 10 40 28 AM"
src="https://github.com/user-attachments/assets/9125bdfb-5b54-461c-a065-2882a8585a67"
/>

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2025-03-12 10:53:38 -04:00 committed by GitHub
parent 669c6a3d5e
commit 6e89537830
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 50 additions and 4 deletions

View file

@ -26,11 +26,11 @@ struct WorkingSetState {
impl Default for WorkingSetState {
fn default() -> Self {
Self {
context_server_tools_by_id: Default::default(),
context_server_tools_by_name: Default::default(),
disabled_tools_by_source: Default::default(),
context_server_tools_by_id: HashMap::default(),
context_server_tools_by_name: HashMap::default(),
disabled_tools_by_source: HashMap::default(),
is_scripting_tool_disabled: true,
next_tool_id: Default::default(),
next_tool_id: ToolId::default(),
}
}
}
@ -58,6 +58,34 @@ impl ToolWorkingSet {
tools
}
pub fn are_all_tools_enabled(&self) -> bool {
let state = self.state.lock();
state.disabled_tools_by_source.is_empty() && !state.is_scripting_tool_disabled
}
pub fn enable_all_tools(&self) {
let mut state = self.state.lock();
state.disabled_tools_by_source.clear();
state.is_scripting_tool_disabled = false;
}
pub fn disable_all_tools(&self, cx: &App) {
let tools = self.tools_by_source(cx);
for (source, tools) in tools {
let tool_names = tools
.into_iter()
.map(|tool| tool.name().into())
.collect::<Vec<_>>();
self.disable(source, &tool_names);
}
self.disable_scripting_tool();
}
pub fn enabled_tools(&self, cx: &App) -> Vec<Arc<dyn Tool>> {
let all_tools = self.tools(cx);