| 55 | |
| 56 | impl BlockingRunContext { |
| 57 | pub(super) async fn start( |
| 58 | session: &AgentSession, |
| 59 | prompt: &str, |
| 60 | persistence: Option<SessionPersistenceContext>, |
| 61 | ) -> Self { |
| 62 | let run = RunControlState::from_session(session) |
| 63 | .start_run(prompt) |
| 64 | .await; |
| 65 | let run_id = run.id().to_string(); |
| 66 | let mut agent_loop = build_agent_loop(session); |
| 67 | agent_loop.set_checkpoint_run(&run_id); |
| 68 | let (runtime_tx, runtime_rx) = mpsc::channel(2048); |
| 69 | let runtime_collector = |
| 70 | RuntimeEventSink::from_session(session, &run_id).spawn_collector(runtime_rx); |
| 71 | let lifecycle = BlockingRunLifecycle::from_session(session, &run_id, persistence); |
| 72 | let cancel_token = session.session_cancel.child_token(); |
| 73 | lifecycle.set_cancel_token(cancel_token.clone()).await; |
| 74 | |
| 75 | Self { |
| 76 | agent_loop, |
| 77 | runtime_tx, |
| 78 | cancel_token, |
| 79 | runtime_collector, |
| 80 | lifecycle, |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | pub(super) async fn execute_with_prompt( |
| 85 | self, |