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

Method parse_event

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

Source from the content-addressed store, hash-verified

237 }
238
239 fn parse_event(&self, hook_type: HookType, input: &[u8]) -> AgentResult<TurnEvent> {
240 let raw_json = self.parse_json(hook_type, input)?;
241
242 match hook_type {
243 HookType::SessionStart => {
244 let parsed: SessionStartInput = self.parse_value(hook_type, raw_json.clone())?;
245 let mut event = TurnEvent::new(
246 Self::extract_session_id(parsed.session_id, parsed.thread_id, &raw_json),
247 hook_type,
248 )
249 .with_raw_json(with_openai_provider(raw_json));
250 if let Some(path) = parsed.transcript_path {
251 event = event.with_transcript_path(path);
252 }
253 Ok(event)
254 }
255 HookType::TurnStart => {
256 let parsed: UserPromptSubmitInput =
257 self.parse_value(hook_type, raw_json.clone())?;
258 let mut event = TurnEvent::new(
259 Self::extract_session_id(parsed.session_id, parsed.thread_id, &raw_json),
260 hook_type,
261 )
262 .with_raw_json(with_openai_provider(raw_json));
263 if let Some(path) = parsed.transcript_path {
264 event = event.with_transcript_path(path);
265 }
266 if let Some(prompt) = parsed.prompt.filter(|p| !p.is_empty()) {
267 event = event.with_prompt(prompt);
268 }
269 Ok(event)
270 }
271 HookType::TurnEnd => {
272 let parsed: StopInput = self.parse_value(hook_type, raw_json.clone())?;
273 let raw_json = normalize_stop_raw(raw_json);
274 let mut event = TurnEvent::new(
275 Self::extract_session_id(parsed.session_id, parsed.thread_id, &raw_json),
276 hook_type,
277 )
278 .with_raw_json(with_openai_provider(raw_json));
279 if let Some(path) = parsed.transcript_path {
280 event = event.with_transcript_path(path);
281 }
282 Ok(event)
283 }
284 HookType::PreToolUse | HookType::PostToolUse => {
285 let parsed: ToolUseInput = self.parse_value(hook_type, raw_json.clone())?;
286 let raw_json = if hook_type == HookType::PostToolUse {
287 normalize_tool_raw(raw_json)
288 } else {
289 raw_json
290 };
291 let mut event = TurnEvent::new(
292 Self::extract_session_id(parsed.session_id, parsed.thread_id, &raw_json),
293 hook_type,
294 )
295 .with_raw_json(with_openai_provider(raw_json));
296 if let Some(path) = parsed.transcript_path {

Calls 13

extract_session_idFunction · 0.85
with_openai_providerFunction · 0.85
parse_valueMethod · 0.80
with_raw_jsonMethod · 0.80
with_transcript_pathMethod · 0.80
with_promptMethod · 0.80
with_tool_use_idMethod · 0.80
normalize_stop_rawFunction · 0.70
normalize_tool_rawFunction · 0.70
parse_jsonMethod · 0.45
cloneMethod · 0.45
is_emptyMethod · 0.45