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

Method parse_event

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

Source from the content-addressed store, hash-verified

395 }
396
397 fn parse_event(&self, hook_type: HookType, input: &[u8]) -> AgentResult<TurnEvent> {
398 if input.is_empty() {
399 return Err(AgentError::HookInputEmpty {
400 agent: self.name().to_string(),
401 hook_type: hook_type.as_str().to_string(),
402 });
403 }
404
405 // Preserve raw JSON for debugging and downstream use
406 let raw_json: serde_json::Value =
407 serde_json::from_slice(input).map_err(|e| AgentError::HookParseFailed {
408 agent: self.name().to_string(),
409 hook_type: hook_type.as_str().to_string(),
410 reason: e.to_string(),
411 })?;
412
413 let timestamp = TimestampFormat::Rfc3339.parse(self.name(), hook_type, &raw_json)?;
414
415 match hook_type {
416 HookType::SessionStart => {
417 let parsed: SessionStartInput =
418 serde_json::from_value(raw_json.clone()).map_err(|e| {
419 AgentError::HookParseFailed {
420 agent: self.name().to_string(),
421 hook_type: hook_type.as_str().to_string(),
422 reason: e.to_string(),
423 }
424 })?;
425
426 // SessionStart: prefer session_id, fall back to conversation_id
427 let session_id =
428 Self::extract_session_id(parsed.conversation_id, parsed.session_id);
429
430 let mut event = TurnEvent::new(session_id, hook_type).with_raw_json(raw_json);
431
432 if let Some(transcript) = parsed.transcript_path {
433 event = event.with_transcript_path(transcript);
434 }
435
436 // Store model, composer_mode, is_background_agent in raw_json
437 if let Some(model) = parsed.model {
438 if let Some(ref mut raw) = event.raw_json {
439 if let Some(obj) = raw.as_object_mut() {
440 obj.insert("model".to_string(), serde_json::Value::String(model));
441 }
442 }
443 }
444 if let Some(mode) = parsed.composer_mode {
445 if let Some(ref mut raw) = event.raw_json {
446 if let Some(obj) = raw.as_object_mut() {
447 obj.insert(
448 "composer_mode".to_string(),
449 serde_json::Value::String(mode),
450 );
451 }
452 }
453 }
454 if let Some(bg) = parsed.is_background_agent {

Calls 14

extract_session_idFunction · 0.85
with_raw_jsonMethod · 0.80
with_transcript_pathMethod · 0.80
with_promptMethod · 0.80
with_tool_use_idMethod · 0.80
with_timestampMethod · 0.80
getMethod · 0.65
is_emptyMethod · 0.45
nameMethod · 0.45
as_strMethod · 0.45
parseMethod · 0.45
cloneMethod · 0.45