Skip to content

Commit 5bda43a

Browse files
committed
Tool permission also working
1 parent de3a0c8 commit 5bda43a

File tree

1 file changed

+41
-7
lines changed

1 file changed

+41
-7
lines changed

crates/agent/src/cli/acp_agent.rs

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,48 @@ impl AcpSession {
165165

166166
eprintln!("Sending permission_request: {:?}", permission_request);
167167

168-
match request_cx.send_request(permission_request).block_task().await {
169-
Ok(response) => {
170-
eprintln!("Permission response: {:?}", response);
171-
},
172-
Err(err) => {
173-
eprintln!("Permission request failed: {:?}", err);
168+
let agent_for_approval = agent.clone();
169+
request_cx.send_request(permission_request).await_when_result_received(|result| async move {
170+
match result {
171+
Ok(response) => {
172+
match &response.outcome {
173+
sacp::RequestPermissionOutcome::Selected { option_id } => {
174+
let approval_result = if option_id.0.as_ref() == "allow" {
175+
agent::protocol::ApprovalResult::Approve
176+
} else {
177+
agent::protocol::ApprovalResult::Deny { reason: None }
178+
};
179+
180+
if let Err(e) = agent_for_approval.send_tool_use_approval_result(agent::protocol::SendApprovalResultArgs {
181+
id: id.clone(),
182+
result: approval_result,
183+
}).await {
184+
eprintln!("Failed to send approval result: {:?}", e);
185+
}
186+
},
187+
sacp::RequestPermissionOutcome::Cancelled => {
188+
if let Err(e) = agent_for_approval.send_tool_use_approval_result(agent::protocol::SendApprovalResultArgs {
189+
id: id.clone(),
190+
result: agent::protocol::ApprovalResult::Deny { reason: Some("Cancelled".to_string()) },
191+
}).await {
192+
eprintln!("Failed to send cancellation result: {:?}", e);
193+
}
194+
},
195+
}
196+
eprintln!("Permission response: {:?}", response);
197+
},
198+
Err(err) => {
199+
eprintln!("Permission request failed: {:?}", err);
200+
if let Err(e) = agent_for_approval.send_tool_use_approval_result(agent::protocol::SendApprovalResultArgs {
201+
id: id.clone(),
202+
result: agent::protocol::ApprovalResult::Deny { reason: Some("Request failed".to_string()) },
203+
}).await {
204+
eprintln!("Failed to send error result: {:?}", e);
205+
}
206+
}
174207
}
175-
}
208+
Ok(())
209+
})?;
176210

177211
eprintln!("End permission_request");
178212
},

0 commit comments

Comments
 (0)