Wire up push_tool_call

Ben Brandt and Antonio Scandurra created

Co-authored-by: Antonio Scandurra <me@as-cii.com>

Change summary

crates/acp/src/acp.rs    | 31 ++++++++++++++++++++-----------
crates/acp/src/server.rs | 21 +++++++++++++++++++--
2 files changed, 39 insertions(+), 13 deletions(-)

Detailed changes

crates/acp/src/acp.rs 🔗

@@ -273,11 +273,20 @@ impl AcpThread {
         &mut self,
         title: String,
         description: String,
-        respond_tx: oneshot::Sender<bool>,
+        confirmation_tx: Option<oneshot::Sender<bool>>,
         cx: &mut Context<Self>,
     ) -> ToolCallId {
         let language_registry = self.project.read(cx).languages().clone();
 
+        let description = cx.new(|cx| {
+            Markdown::new(
+                description.into(),
+                Some(language_registry.clone()),
+                None,
+                cx,
+            )
+        });
+
         let entry_id = self.push_entry(
             AgentThreadEntryContent::ToolCall(ToolCall {
                 // todo! clean up id creation
@@ -285,16 +294,16 @@ impl AcpThread {
                 tool_name: cx.new(|cx| {
                     Markdown::new(title.into(), Some(language_registry.clone()), None, cx)
                 }),
-                status: ToolCallStatus::WaitingForConfirmation {
-                    description: cx.new(|cx| {
-                        Markdown::new(
-                            description.into(),
-                            Some(language_registry.clone()),
-                            None,
-                            cx,
-                        )
-                    }),
-                    respond_tx,
+                status: if let Some(respond_tx) = confirmation_tx {
+                    ToolCallStatus::WaitingForConfirmation {
+                        description,
+                        respond_tx,
+                    }
+                } else {
+                    ToolCallStatus::Allowed {
+                        status: acp::ToolCallStatus::Running,
+                        content: Some(description),
+                    }
                 },
             }),
             cx,

crates/acp/src/server.rs 🔗

@@ -214,8 +214,7 @@ impl acp::Client for AcpClientDelegate {
                             format!("Info: {prompt}\n{urls:?}")
                         }
                     };
-                    // todo! tools that don't require confirmation
-                    thread.push_tool_call(request.title, description, tx, cx)
+                    thread.push_tool_call(request.title, description, Some(tx), cx)
                 })
             })?
             .context("Failed to update thread")?;
@@ -232,6 +231,24 @@ impl acp::Client for AcpClientDelegate {
         })
     }
 
+    async fn push_tool_call(
+        &self,
+        request: acp::PushToolCallParams,
+    ) -> Result<acp::PushToolCallResponse> {
+        let cx = &mut self.cx.clone();
+        let entry_id = cx
+            .update(|cx| {
+                self.update_thread(&request.thread_id.into(), cx, |thread, cx| {
+                    thread.push_tool_call(request.title, request.description, None, cx)
+                })
+            })?
+            .context("Failed to update thread")?;
+
+        Ok(acp::PushToolCallResponse {
+            id: entry_id.into(),
+        })
+    }
+
     async fn update_tool_call(
         &self,
         request: acp::UpdateToolCallParams,