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

Method parse_event

atomic-agent/src/hooks/gemini_cli.rs:538–702  ·  view source on GitHub ↗
(&self, hook_type: HookType, input: &[u8])

Source from the content-addressed store, hash-verified

536 }
537
538 fn parse_event(&self, hook_type: HookType, input: &[u8]) -> AgentResult<TurnEvent> {
539 if input.is_empty() {
540 return Err(AgentError::HookInputEmpty {
541 agent: self.name().to_string(),
542 hook_type: hook_type.as_str().to_string(),
543 });
544 }
545
546 let raw_json: serde_json::Value =
547 serde_json::from_slice(input).map_err(|e| AgentError::HookParseFailed {
548 agent: self.name().to_string(),
549 hook_type: hook_type.as_str().to_string(),
550 reason: e.to_string(),
551 })?;
552
553 match hook_type {
554 HookType::SessionStart => {
555 let parsed: SessionStartInput =
556 serde_json::from_value(raw_json.clone()).map_err(|e| {
557 AgentError::HookParseFailed {
558 agent: self.name().to_string(),
559 hook_type: hook_type.as_str().to_string(),
560 reason: e.to_string(),
561 }
562 })?;
563
564 let session_id = parsed
565 .session_id
566 .or_else(|| {
567 raw_json
568 .get("session_id")
569 .and_then(|v| v.as_str())
570 .map(String::from)
571 })
572 .unwrap_or_else(|| "unknown".to_string());
573
574 let mut event = TurnEvent::new(&session_id, hook_type).with_raw_json(raw_json);
575
576 if let Some(path) = parsed.transcript_path {
577 event = event.with_transcript_path(path);
578 }
579
580 Ok(event)
581 }
582
583 HookType::SessionEnd => {
584 let parsed: SessionEndInput =
585 serde_json::from_value(raw_json.clone()).map_err(|e| {
586 AgentError::HookParseFailed {
587 agent: self.name().to_string(),
588 hook_type: hook_type.as_str().to_string(),
589 reason: e.to_string(),
590 }
591 })?;
592
593 let session_id = parsed.session_id.unwrap_or_else(|| "unknown".to_string());
594
595 let mut event = TurnEvent::new(&session_id, hook_type).with_raw_json(raw_json);

Calls 9

with_raw_jsonMethod · 0.80
with_transcript_pathMethod · 0.80
with_promptMethod · 0.80
getMethod · 0.65
is_emptyMethod · 0.45
nameMethod · 0.45
as_strMethod · 0.45
cloneMethod · 0.45
with_tool_nameMethod · 0.45