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

Method parse_event

atomic-agent/src/hooks/pi.rs:320–506  ·  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 let timestamp = TimestampFormat::Rfc3339.parse(self.name(), hook_type, &raw_json)?;
337
338 match hook_type {
339 HookType::SessionStart => {
340 let parsed: SessionStartInput =
341 serde_json::from_value(raw_json.clone()).map_err(|e| {
342 AgentError::HookParseFailed {
343 agent: self.name().to_string(),
344 hook_type: hook_type.as_str().to_string(),
345 reason: e.to_string(),
346 }
347 })?;
348
349 let mut event =
350 TurnEvent::new(Self::extract_session_id(parsed.session_id), hook_type)
351 .with_raw_json(raw_json);
352
353 // Store model and provider in raw_json for the orchestrator
354 if let Some(model) = parsed.model {
355 if let Some(ref mut raw) = event.raw_json {
356 if let Some(obj) = raw.as_object_mut() {
357 obj.insert("model".to_string(), serde_json::Value::String(model));
358 }
359 }
360 }
361 if let Some(source) = parsed.source {
362 if let Some(ref mut raw) = event.raw_json {
363 if let Some(obj) = raw.as_object_mut() {
364 obj.insert("source".to_string(), serde_json::Value::String(source));
365 }
366 }
367 }
368
369 Ok(event)
370 }
371
372 HookType::SessionEnd => {
373 let parsed: SessionEndInput =
374 serde_json::from_value(raw_json.clone()).map_err(|e| {
375 AgentError::HookParseFailed {
376 agent: self.name().to_string(),
377 hook_type: hook_type.as_str().to_string(),

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 12

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