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

Method parse_event

atomic-agent/src/hooks/codex.rs:208–287  ·  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 let raw_json = self.parse_json(hook_type, input)?;
210
211 match hook_type {
212 HookType::SessionStart => {
213 let parsed: SessionStartInput = self.parse_value(hook_type, raw_json.clone())?;
214 let mut event = TurnEvent::new(
215 Self::extract_session_id(parsed.session_id, parsed.thread_id, &raw_json),
216 hook_type,
217 )
218 .with_raw_json(with_openai_provider(raw_json));
219 if let Some(path) = parsed.transcript_path {
220 event = event.with_transcript_path(path);
221 }
222 Ok(event)
223 }
224 HookType::TurnStart => {
225 let parsed: UserPromptSubmitInput =
226 self.parse_value(hook_type, raw_json.clone())?;
227 let mut event = TurnEvent::new(
228 Self::extract_session_id(parsed.session_id, parsed.thread_id, &raw_json),
229 hook_type,
230 )
231 .with_raw_json(with_openai_provider(raw_json));
232 if let Some(path) = parsed.transcript_path {
233 event = event.with_transcript_path(path);
234 }
235 if let Some(prompt) = parsed.prompt.filter(|p| !p.is_empty()) {
236 event = event.with_prompt(prompt);
237 }
238 Ok(event)
239 }
240 HookType::TurnEnd => {
241 let parsed: StopInput = self.parse_value(hook_type, raw_json.clone())?;
242 let raw_json = normalize_stop_raw(raw_json);
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 Ok(event)
252 }
253 HookType::PreToolUse | HookType::PostToolUse => {
254 let parsed: ToolUseInput = self.parse_value(hook_type, raw_json.clone())?;
255 let raw_json = if hook_type == HookType::PostToolUse {
256 normalize_tool_raw(raw_json)
257 } else {
258 raw_json
259 };
260 let mut event = TurnEvent::new(
261 Self::extract_session_id(parsed.session_id, parsed.thread_id, &raw_json),
262 hook_type,
263 )
264 .with_raw_json(with_openai_provider(raw_json));
265 if let Some(path) = parsed.transcript_path {

Calls 15

extract_session_idFunction · 0.85
with_openai_providerFunction · 0.85
normalize_stop_rawFunction · 0.85
normalize_tool_rawFunction · 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
parse_jsonMethod · 0.45
cloneMethod · 0.45
is_emptyMethod · 0.45