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

Method parse_event

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

Source from the content-addressed store, hash-verified

221 }
222
223 fn parse_event(&self, hook_type: HookType, input: &[u8]) -> AgentResult<TurnEvent> {
224 let raw_json = self.parse_json(hook_type, input)?;
225 let timestamp = TimestampFormat::Rfc3339.parse(self.name(), hook_type, &raw_json)?;
226
227 match hook_type {
228 HookType::SessionStart => {
229 let parsed: SessionStartInput = self.parse_value(hook_type, raw_json.clone())?;
230 let mut event = TurnEvent::new(
231 Self::extract_session_id(parsed.session_id, parsed.thread_id, &raw_json),
232 hook_type,
233 )
234 .with_raw_json(with_openai_provider(raw_json));
235 if let Some(path) = parsed.transcript_path {
236 event = event.with_transcript_path(path);
237 }
238 Ok(event)
239 }
240 HookType::TurnStart => {
241 let parsed: UserPromptSubmitInput =
242 self.parse_value(hook_type, raw_json.clone())?;
243 let mut event = TurnEvent::new(
244 Self::extract_session_id(parsed.session_id, parsed.thread_id, &raw_json),
245 hook_type,
246 )
247 .with_raw_json(with_openai_provider(raw_json));
248 if let Some(path) = parsed.transcript_path {
249 event = event.with_transcript_path(path);
250 }
251 if let Some(prompt) = parsed.prompt.filter(|p| !p.is_empty()) {
252 event = event.with_prompt(prompt);
253 }
254 Ok(event)
255 }
256 HookType::TurnEnd => {
257 let parsed: StopInput = self.parse_value(hook_type, raw_json.clone())?;
258 let raw_json = normalize_stop_raw(raw_json);
259 let mut event = TurnEvent::new(
260 Self::extract_session_id(parsed.session_id, parsed.thread_id, &raw_json),
261 hook_type,
262 )
263 .with_raw_json(with_openai_provider(raw_json));
264 if let Some(path) = parsed.transcript_path {
265 event = event.with_transcript_path(path);
266 }
267 Ok(event)
268 }
269 HookType::PreToolUse | HookType::PostToolUse => {
270 let parsed: ToolUseInput = self.parse_value(hook_type, raw_json.clone())?;
271 let raw_json = if hook_type == HookType::PostToolUse {
272 normalize_tool_raw(raw_json)
273 } else {
274 raw_json
275 };
276 let mut event = TurnEvent::new(
277 Self::extract_session_id(parsed.session_id, parsed.thread_id, &raw_json),
278 hook_type,
279 )
280 .with_raw_json(with_openai_provider(raw_json));

Calls 15

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
with_timestampMethod · 0.80
normalize_stop_rawFunction · 0.70
normalize_tool_rawFunction · 0.70
parse_jsonMethod · 0.45
parseMethod · 0.45