(
&mut self,
mut stream: opencode_provider::StreamResult,
)
| 307 | } |
| 308 | |
| 309 | async fn process_stream( |
| 310 | &mut self, |
| 311 | mut stream: opencode_provider::StreamResult, |
| 312 | ) -> Result<(String, Vec<ToolCall>), AgentError> { |
| 313 | let mut content = String::new(); |
| 314 | let mut tool_calls: Vec<ToolCall> = Vec::new(); |
| 315 | |
| 316 | while let Some(event) = stream.next().await { |
| 317 | match event { |
| 318 | Ok(StreamEvent::TextDelta(text)) => { |
| 319 | content.push_str(&text); |
| 320 | } |
| 321 | Ok(StreamEvent::ToolCallStart { id, name }) => { |
| 322 | tool_calls.push(ToolCall { |
| 323 | id, |
| 324 | name, |
| 325 | arguments: serde_json::Value::Null, |
| 326 | }); |
| 327 | } |
| 328 | Ok(StreamEvent::ToolCallDelta { id, input }) => { |
| 329 | if let Some(tc) = tool_calls.iter_mut().find(|t| t.id == id) { |
| 330 | if tc.arguments.is_null() { |
| 331 | tc.arguments = |
| 332 | serde_json::from_str(&input).unwrap_or(serde_json::Value::Null); |
| 333 | } |
| 334 | } |
| 335 | } |
| 336 | Ok(StreamEvent::Done) => break, |
| 337 | Ok(StreamEvent::Error(e)) => { |
| 338 | return Err(AgentError::ProviderError(e)); |
| 339 | } |
| 340 | Err(e) => { |
| 341 | return Err(AgentError::ProviderError(e.to_string())); |
| 342 | } |
| 343 | _ => {} |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | Ok((content, tool_calls)) |
| 348 | } |
| 349 | |
| 350 | async fn execute_tool(&self, tool_call: &ToolCall) -> Result<String, ToolError> { |
| 351 | if self.disabled_tools.contains(&tool_call.name) { |
no test coverage detected