Create a tool context with streaming support. When `event_tx` is Some, spawns a forwarder task that converts `ToolStreamEvent::OutputDelta` into `AgentEvent::ToolOutputDelta` and sends them to the agent event channel. Returns the augmented `ToolContext`. The forwarder task runs until the tool-side sender is dropped (i.e., tool execution finishes).
(
&self,
event_tx: &Option<mpsc::Sender<AgentEvent>>,
tool_id: &str,
tool_name: &str,
)
| 177 | /// Returns the augmented `ToolContext`. The forwarder task runs until |
| 178 | /// the tool-side sender is dropped (i.e., tool execution finishes). |
| 179 | fn streaming_tool_context( |
| 180 | &self, |
| 181 | event_tx: &Option<mpsc::Sender<AgentEvent>>, |
| 182 | tool_id: &str, |
| 183 | tool_name: &str, |
| 184 | ) -> ToolContext { |
| 185 | let mut ctx = self.tool_context.clone(); |
| 186 | if let Some(agent_tx) = event_tx { |
| 187 | let (tool_tx, mut tool_rx) = mpsc::channel::<ToolStreamEvent>(64); |
| 188 | ctx.event_tx = Some(tool_tx); |
| 189 | |
| 190 | let agent_tx = agent_tx.clone(); |
| 191 | let tool_id = tool_id.to_string(); |
| 192 | let tool_name = tool_name.to_string(); |
| 193 | tokio::spawn(async move { |
| 194 | while let Some(event) = tool_rx.recv().await { |
| 195 | match event { |
| 196 | ToolStreamEvent::OutputDelta(delta) => { |
| 197 | agent_tx |
| 198 | .send(AgentEvent::ToolOutputDelta { |
| 199 | id: tool_id.clone(), |
| 200 | name: tool_name.clone(), |
| 201 | delta, |
| 202 | }) |
| 203 | .await |
| 204 | .ok(); |
| 205 | } |
| 206 | } |
| 207 | } |
| 208 | }); |
| 209 | } |
| 210 | ctx |
| 211 | } |
| 212 | } |
no test coverage detected