MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / dispatch_turn_event

Method dispatch_turn_event

libatomic/src/daemon/services_agent.rs:4489–4618  ·  view source on GitHub ↗
(
        &self,
        request: Request<DispatchTurnEventRequest>,
    )

Source from the content-addressed store, hash-verified

4487 crate::daemon::services_provenance::load_hook_log_impl(&self.state, request).await
4488 }
4489 async fn dispatch_turn_event(
4490 &self,
4491 request: Request<DispatchTurnEventRequest>,
4492 ) -> Result<Response<DispatchTurnEventResponse>, Status> {
4493 let request = request.into_inner();
4494 let handle = self.state.resolve(request.repository.as_ref().unwrap())?;
4495 self.state.log_rpc("DispatchTurnEvent", Some(&handle));
4496 let gate_handle = handle.clone();
4497 let _gate = gate_handle.exclusive().await;
4498 let meta = request.meta.clone();
4499 let agent_id = request.agent_id.clone();
4500 let display = request
4501 .agent_display_name
4502 .clone()
4503 .unwrap_or_else(|| agent_id.clone());
4504 let identity = request.agent_identity.clone();
4505 let verb = request
4506 .event
4507 .as_ref()
4508 .map(|body| body.event_type.clone())
4509 .unwrap_or_else(|| "dispatch_turn_event".to_string());
4510 let mut hook_context = atomic_agent::hook_log::HookContext::default();
4511 if let Some(body) = &request.event {
4512 let raw_json = body
4513 .raw_json
4514 .as_ref()
4515 .and_then(|bytes| serde_json::from_slice(bytes).ok());
4516 let event = TurnEvent {
4517 session_id: body.session_id.clone(),
4518 raw_json,
4519 ..TurnEvent::new(
4520 &body.session_id,
4521 atomic_agent::event::HookType::SessionStart,
4522 )
4523 };
4524 hook_context = atomic_agent::hook_log::HookContext::from_event_payload(&event);
4525 if body
4526 .parent_session_id
4527 .as_deref()
4528 .is_some_and(|parent| !parent.is_empty())
4529 {
4530 hook_context.parent_session_id = body.parent_session_id.clone();
4531 }
4532 }
4533 let dispatch = async {
4534 let body = request
4535 .event
4536 .ok_or_else(|| domain_status(ErrorCode::InvalidArgument, "typed event required"))?;
4537 let hook_type = hook_type(&body.event_type).ok_or_else(|| {
4538 domain_status(
4539 ErrorCode::InvalidArgument,
4540 format!("unknown event type '{}'", body.event_type),
4541 )
4542 })?;
4543 let raw_json = body
4544 .raw_json
4545 .as_ref()
4546 .filter(|bytes| !bytes.is_empty())

Callers 1

fireMethod · 0.45

Calls 15

domain_statusFunction · 0.85
hook_typeFunction · 0.85
openFunction · 0.85
response_metaFunction · 0.85
flush_pendingFunction · 0.85
spoolFunction · 0.85
as_refMethod · 0.80
log_rpcMethod · 0.80
exclusiveMethod · 0.80
set_agentMethod · 0.80
set_agent_identityMethod · 0.80
set_journal_sinkMethod · 0.80

Tested by 1

fireMethod · 0.36