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

Method parse_event

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

Source from the content-addressed store, hash-verified

372 }
373
374 fn parse_event(&self, hook_type: HookType, input: &[u8]) -> AgentResult<TurnEvent> {
375 if input.is_empty() {
376 return Err(AgentError::HookInputEmpty {
377 agent: self.name().to_string(),
378 hook_type: hook_type.as_str().to_string(),
379 });
380 }
381
382 // Preserve raw JSON for debugging and downstream use
383 let raw_json: serde_json::Value =
384 serde_json::from_slice(input).map_err(|e| AgentError::HookParseFailed {
385 agent: self.name().to_string(),
386 hook_type: hook_type.as_str().to_string(),
387 reason: e.to_string(),
388 })?;
389
390 match hook_type {
391 HookType::SessionStart => {
392 let parsed: SessionStartInput =
393 serde_json::from_value(raw_json.clone()).map_err(|e| {
394 AgentError::HookParseFailed {
395 agent: self.name().to_string(),
396 hook_type: hook_type.as_str().to_string(),
397 reason: e.to_string(),
398 }
399 })?;
400
401 let mut event =
402 TurnEvent::new(Self::extract_session_id(parsed.session_id), hook_type)
403 .with_raw_json(raw_json);
404
405 // Store model and provider in raw_json for the orchestrator
406 if let Some(model) = parsed.model {
407 if let Some(ref mut raw) = event.raw_json {
408 if let Some(obj) = raw.as_object_mut() {
409 obj.insert("model".to_string(), serde_json::Value::String(model));
410 }
411 }
412 }
413 if let Some(source) = parsed.source {
414 if let Some(ref mut raw) = event.raw_json {
415 if let Some(obj) = raw.as_object_mut() {
416 obj.insert("source".to_string(), serde_json::Value::String(source));
417 }
418 }
419 }
420
421 Ok(event)
422 }
423
424 HookType::SessionEnd => {
425 let parsed: SessionEndInput =
426 serde_json::from_value(raw_json.clone()).map_err(|e| {
427 AgentError::HookParseFailed {
428 agent: self.name().to_string(),
429 hook_type: hook_type.as_str().to_string(),
430 reason: e.to_string(),
431 }

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