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

Method parse_event

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

Source from the content-addressed store, hash-verified

207 }
208
209 fn parse_event(&self, hook_type: HookType, input: &[u8]) -> AgentResult<TurnEvent> {
210 if input.is_empty() {
211 return Err(AgentError::HookInputEmpty {
212 agent: self.name().to_string(),
213 hook_type: hook_type.as_str().to_string(),
214 });
215 }
216
217 // Preserve raw JSON for debugging and downstream use
218 let raw_json: serde_json::Value =
219 serde_json::from_slice(input).map_err(|e| AgentError::HookParseFailed {
220 agent: self.name().to_string(),
221 hook_type: hook_type.as_str().to_string(),
222 reason: e.to_string(),
223 })?;
224
225 let timestamp = TimestampFormat::Rfc3339.parse(self.name(), hook_type, &raw_json)?;
226
227 match hook_type {
228 HookType::SessionStart => {
229 let parsed: SessionStartInput =
230 serde_json::from_value(raw_json.clone()).map_err(|e| {
231 AgentError::HookParseFailed {
232 agent: self.name().to_string(),
233 hook_type: hook_type.as_str().to_string(),
234 reason: e.to_string(),
235 }
236 })?;
237
238 let mut event =
239 TurnEvent::new(Self::extract_session_id(parsed.session_id), hook_type)
240 .with_raw_json(raw_json);
241
242 if let Some(model) = parsed.model {
243 if let Some(ref mut raw) = event.raw_json {
244 if let Some(obj) = raw.as_object_mut() {
245 obj.insert("model".to_string(), serde_json::Value::String(model));
246 }
247 }
248 }
249
250 Ok(event)
251 }
252
253 HookType::SessionEnd => {
254 let parsed: SessionEndInput =
255 serde_json::from_value(raw_json.clone()).map_err(|e| {
256 AgentError::HookParseFailed {
257 agent: self.name().to_string(),
258 hook_type: hook_type.as_str().to_string(),
259 reason: e.to_string(),
260 }
261 })?;
262
263 let event = TurnEvent::new(Self::extract_session_id(parsed.session_id), hook_type)
264 .with_raw_json(raw_json);
265
266 Ok(event)

Calls 11

extract_session_idFunction · 0.85
with_raw_jsonMethod · 0.80
with_promptMethod · 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