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

Method parse_event

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

Source from the content-addressed store, hash-verified

217 }
218
219 fn parse_event(&self, hook_type: HookType, input: &[u8]) -> AgentResult<TurnEvent> {
220 if input.is_empty() {
221 return Err(AgentError::HookInputEmpty {
222 agent: self.name().to_string(),
223 hook_type: hook_type.as_str().to_string(),
224 });
225 }
226
227 // Preserve raw JSON for debugging and downstream use
228 let raw_json: serde_json::Value =
229 serde_json::from_slice(input).map_err(|e| AgentError::HookParseFailed {
230 agent: self.name().to_string(),
231 hook_type: hook_type.as_str().to_string(),
232 reason: e.to_string(),
233 })?;
234
235 let timestamp = TimestampFormat::Rfc3339.parse(self.name(), hook_type, &raw_json)?;
236
237 match hook_type {
238 HookType::TurnStart => {
239 let parsed: PromptSubmitInput =
240 serde_json::from_value(raw_json.clone()).map_err(|e| {
241 AgentError::HookParseFailed {
242 agent: self.name().to_string(),
243 hook_type: hook_type.as_str().to_string(),
244 reason: e.to_string(),
245 }
246 })?;
247
248 let mut event =
249 TurnEvent::new(Self::extract_session_id(parsed.session_id), hook_type)
250 .with_raw_json(raw_json);
251
252 if let Some(prompt) = parsed.prompt {
253 event = event.with_prompt(prompt);
254 }
255
256 // Store model in raw_json for the orchestrator
257 if let Some(model) = parsed.model {
258 if let Some(ref mut raw) = event.raw_json {
259 if let Some(obj) = raw.as_object_mut() {
260 obj.insert("model".to_string(), serde_json::Value::String(model));
261 }
262 }
263 }
264
265 Ok(event)
266 }
267
268 HookType::TurnEnd => {
269 let parsed: AgentStopInput =
270 serde_json::from_value(raw_json.clone()).map_err(|e| {
271 AgentError::HookParseFailed {
272 agent: self.name().to_string(),
273 hook_type: hook_type.as_str().to_string(),
274 reason: e.to_string(),
275 }
276 })?;

Calls 12

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