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

Method parse_event

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

Source from the content-addressed store, hash-verified

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

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