Transform the raw driver stream into a stream of [`Step`]s. Internal: the consumer stream is taken (once) by [`run_stream`](Algorithm::run_stream). A payload that does not match the expected type for its step becomes an `Err` item.
(&self)
| 296 | /// consumer stream is taken (once) by [`run_stream`](Algorithm::run_stream). A |
| 297 | /// payload that does not match the expected type for its step becomes an `Err` item. |
| 298 | pub(crate) fn stream(&self) -> impl Stream<Item = Result<Step>> + use<> { |
| 299 | self.driver.stream().map(|item| match item? { |
| 300 | DriverStep::Request(req) => Ok(Step::CallLlm(Box::new(CallLlmRequest::new(req)))), |
| 301 | DriverStep::Info(payload) => payload |
| 302 | .downcast::<Arc<dyn Decision>>() |
| 303 | .map(|decision| Step::Decision(*decision)) |
| 304 | .map_err(|_| { |
| 305 | DriverError::TypeMismatch { |
| 306 | expected: "Arc<dyn Decision>", |
| 307 | } |
| 308 | .into() |
| 309 | }), |
| 310 | DriverStep::Done(payload) => payload |
| 311 | .downcast::<Response>() |
| 312 | .map(Step::ReturnToAgent) |
| 313 | .map_err(|_| { |
| 314 | DriverError::TypeMismatch { |
| 315 | expected: "Response", |
| 316 | } |
| 317 | .into() |
| 318 | }), |
| 319 | }) |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | impl Default for Driver { |
no test coverage detected