1515
tc.arguments.chars().take(120).collect::<String>()
1516
);
1517
1518
+ // Model tool calls are agent actions in ACP too, not merely an
1519
+ // implementation detail of the completion loop. Announce each
1520
+ // one before it runs and close it afterwards so clients such as
1521
+ // Zed can render activity while the next inference round is in
1522
+ // flight. Previously only model loading emitted ToolCall events,
1523
+ // leaving an otherwise working tool round visually indistinct
1524
+ // from a stalled response.
1525
+ let raw_input: serde_json::Value = serde_json::from_str(&tc.arguments)
1526
+ .unwrap_or_else(|_| serde_json::Value::String(tc.arguments.clone()));
1527
+ self.send_tool_call_update(
1528
+ cx,
1529
+ session_id.clone(),
1530
+ SessionUpdate::ToolCall(
1531
+ ToolCall::new(tc.id.clone(), tc.name.clone())
1532
+ .kind(tool_kind_for(&tc.name))
1533
+ .status(ToolCallStatus::InProgress)
1534
+ .raw_input(raw_input),
1535
+ ),
1536
+ )
1537
+ .ok();
1538
+
1539
let signature = format!("{}\n{}", tc.name, tc.arguments);
1540
let repeat_count = repeated_tool_calls
1541
.entry(signature)
1606
),
1607
});
1608
}
1609
+ self.send_tool_call_update(
1610
+ cx,
1611
+ session_id.clone(),
1612
+ SessionUpdate::ToolCallUpdate(ToolCallUpdate::new(
1613
+ tc.id.clone(),
1614
+ ToolCallUpdateFields::new()
1615
+ .status(ToolCallStatus::Failed)
1616
+ .raw_output(serde_json::Value::String(
1617
+ "Not executed: the user cancelled the turn at the permission prompt."
1618
+ .to_string(),
1619
+ )),
1620
+ )),
1621
+ )
1622
+ .ok();
1623
backend.record_cancelled_tool_results(tool_results).await;
1624
return Ok(PromptResponse::new(StopReason::Cancelled));
1625
}
1630
1631
log::info!(" ← {} chars", output.len());
1632
1633
+ self.send_tool_call_update(
1634
+ cx,
1635
+ session_id.clone(),
1636
+ SessionUpdate::ToolCallUpdate(ToolCallUpdate::new(
1637
+ tc.id.clone(),
1638
+ ToolCallUpdateFields::new()
1639
+ .status(ToolCallStatus::Completed)
1640
+ .raw_output(serde_json::Value::String(output.clone())),
1641
+ )),
1642
+ )
1643
+ .ok();
1644
+
1645
tool_results.push(BackendToolResult {
1646
tool_call_id: tc.id.clone(),
1647
content: output,