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

Method parse_event

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

Source from the content-addressed store, hash-verified

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