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

Method parse_event

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

Source from the content-addressed store, hash-verified

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

Calls 9

extract_session_idFunction · 0.85
with_raw_jsonMethod · 0.80
with_promptMethod · 0.80
is_emptyMethod · 0.45
nameMethod · 0.45
as_strMethod · 0.45
cloneMethod · 0.45
insertMethod · 0.45
with_tool_nameMethod · 0.45