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

Method parse_event

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

Source from the content-addressed store, hash-verified

318 }
319
320 fn parse_event(&self, hook_type: HookType, input: &[u8]) -> AgentResult<TurnEvent> {
321 if input.is_empty() {
322 return Err(AgentError::HookInputEmpty {
323 agent: self.name().to_string(),
324 hook_type: hook_type.as_str().to_string(),
325 });
326 }
327
328 // Preserve raw JSON for debugging and downstream use
329 let raw_json: serde_json::Value =
330 serde_json::from_slice(input).map_err(|e| AgentError::HookParseFailed {
331 agent: self.name().to_string(),
332 hook_type: hook_type.as_str().to_string(),
333 reason: e.to_string(),
334 })?;
335
336 match hook_type {
337 HookType::SessionStart => {
338 let parsed: SessionStartInput =
339 serde_json::from_value(raw_json.clone()).map_err(|e| {
340 AgentError::HookParseFailed {
341 agent: self.name().to_string(),
342 hook_type: hook_type.as_str().to_string(),
343 reason: e.to_string(),
344 }
345 })?;
346
347 let mut event =
348 TurnEvent::new(Self::extract_session_id(parsed.session_id), hook_type)
349 .with_raw_json(raw_json);
350
351 // Store model and provider in raw_json for the orchestrator
352 if let Some(model) = parsed.model {
353 if let Some(ref mut raw) = event.raw_json {
354 if let Some(obj) = raw.as_object_mut() {
355 obj.insert("model".to_string(), serde_json::Value::String(model));
356 }
357 }
358 }
359 if let Some(source) = parsed.source {
360 if let Some(ref mut raw) = event.raw_json {
361 if let Some(obj) = raw.as_object_mut() {
362 obj.insert("source".to_string(), serde_json::Value::String(source));
363 }
364 }
365 }
366
367 Ok(event)
368 }
369
370 HookType::SessionEnd => {
371 let parsed: SessionEndInput =
372 serde_json::from_value(raw_json.clone()).map_err(|e| {
373 AgentError::HookParseFailed {
374 agent: self.name().to_string(),
375 hook_type: hook_type.as_str().to_string(),
376 reason: e.to_string(),
377 }

Callers 15

runMethod · 0.45
test_parse_session_startFunction · 0.45
test_parse_session_endFunction · 0.45
test_parse_user_promptFunction · 0.45
test_parse_stopFunction · 0.45
test_parse_before_toolFunction · 0.45

Calls 10

extract_session_idFunction · 0.85
with_raw_jsonMethod · 0.80
with_promptMethod · 0.80
with_tool_use_idMethod · 0.80
is_emptyMethod · 0.45
nameMethod · 0.45
as_strMethod · 0.45
cloneMethod · 0.45
insertMethod · 0.45
with_tool_nameMethod · 0.45