Fix ACP permission request with new tool calls (#37182)
Release Notes: - Gemini integration: Fixed a bug with permission requests when `always_allow_tool_calls` is enabled
This commit is contained in:
@@ -3,15 +3,13 @@ use acp_thread::AgentConnection;
|
||||
use acp_tools::AcpConnectionRegistry;
|
||||
use action_log::ActionLog;
|
||||
use agent_client_protocol::{self as acp, Agent as _, ErrorCode};
|
||||
use agent_settings::AgentSettings;
|
||||
use anyhow::anyhow;
|
||||
use collections::HashMap;
|
||||
use futures::AsyncBufReadExt as _;
|
||||
use futures::channel::oneshot;
|
||||
use futures::io::BufReader;
|
||||
use project::Project;
|
||||
use serde::Deserialize;
|
||||
use settings::Settings as _;
|
||||
|
||||
use std::{any::Any, cell::RefCell};
|
||||
use std::{path::Path, rc::Rc};
|
||||
use thiserror::Error;
|
||||
@@ -345,28 +343,7 @@ impl acp::Client for ClientDelegate {
|
||||
) -> Result<acp::RequestPermissionResponse, acp::Error> {
|
||||
let cx = &mut self.cx.clone();
|
||||
|
||||
// If always_allow_tool_actions is enabled, then auto-choose the first "Allow" button
|
||||
if AgentSettings::try_read_global(cx, |settings| settings.always_allow_tool_actions)
|
||||
.unwrap_or(false)
|
||||
{
|
||||
// Don't use AllowAlways, because then if you were to turn off always_allow_tool_actions,
|
||||
// some tools would (incorrectly) continue to auto-accept.
|
||||
if let Some(allow_once_option) = arguments.options.iter().find_map(|option| {
|
||||
if matches!(option.kind, acp::PermissionOptionKind::AllowOnce) {
|
||||
Some(option.id.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}) {
|
||||
return Ok(acp::RequestPermissionResponse {
|
||||
outcome: acp::RequestPermissionOutcome::Selected {
|
||||
option_id: allow_once_option,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let rx = self
|
||||
let task = self
|
||||
.sessions
|
||||
.borrow()
|
||||
.get(&arguments.session_id)
|
||||
@@ -374,14 +351,9 @@ impl acp::Client for ClientDelegate {
|
||||
.thread
|
||||
.update(cx, |thread, cx| {
|
||||
thread.request_tool_call_authorization(arguments.tool_call, arguments.options, cx)
|
||||
})?;
|
||||
})??;
|
||||
|
||||
let result = rx?.await;
|
||||
|
||||
let outcome = match result {
|
||||
Ok(option) => acp::RequestPermissionOutcome::Selected { option_id: option },
|
||||
Err(oneshot::Canceled) => acp::RequestPermissionOutcome::Cancelled,
|
||||
};
|
||||
let outcome = task.await;
|
||||
|
||||
Ok(acp::RequestPermissionResponse { outcome })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user