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

Method parse_event

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

Source from the content-addressed store, hash-verified

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

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