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

Method parse_event

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

Source from the content-addressed store, hash-verified

252 }
253
254 fn parse_event(&self, hook_type: HookType, input: &[u8]) -> AgentResult<TurnEvent> {
255 if input.is_empty() {
256 return Err(AgentError::HookInputEmpty {
257 agent: self.name().to_string(),
258 hook_type: hook_type.as_str().to_string(),
259 });
260 }
261
262 // Preserve raw JSON for debugging and downstream use
263 let raw_json: serde_json::Value =
264 serde_json::from_slice(input).map_err(|e| AgentError::HookParseFailed {
265 agent: self.name().to_string(),
266 hook_type: hook_type.as_str().to_string(),
267 reason: e.to_string(),
268 })?;
269
270 let timestamp =
271 TimestampFormat::Rfc3339OrUnixMillis.parse(self.name(), hook_type, &raw_json)?;
272
273 match hook_type {
274 HookType::SessionStart => {
275 let parsed: SessionStartInput =
276 serde_json::from_value(raw_json.clone()).map_err(|e| {
277 AgentError::HookParseFailed {
278 agent: self.name().to_string(),
279 hook_type: hook_type.as_str().to_string(),
280 reason: e.to_string(),
281 }
282 })?;
283
284 let mut event =
285 TurnEvent::new(Self::extract_session_id(parsed.session_id), hook_type)
286 .with_raw_json(raw_json);
287
288 // Store model in raw_json for the orchestrator
289 if let Some(model) = parsed.model {
290 if let Some(ref mut raw) = event.raw_json {
291 if let Some(obj) = raw.as_object_mut() {
292 obj.insert("model".to_string(), serde_json::Value::String(model));
293 }
294 }
295 }
296
297 Ok(event)
298 }
299
300 HookType::SessionEnd => {
301 let parsed: SessionEndInput =
302 serde_json::from_value(raw_json.clone()).map_err(|e| {
303 AgentError::HookParseFailed {
304 agent: self.name().to_string(),
305 hook_type: hook_type.as_str().to_string(),
306 reason: e.to_string(),
307 }
308 })?;
309
310 let event = TurnEvent::new(Self::extract_session_id(parsed.session_id), hook_type)
311 .with_raw_json(raw_json);

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