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

Method parse_event

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

Source from the content-addressed store, hash-verified

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

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