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

Method parse_event

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

Source from the content-addressed store, hash-verified

188 }
189
190 fn parse_event(&self, hook_type: HookType, input: &[u8]) -> AgentResult<TurnEvent> {
191 if input.is_empty() {
192 return Err(AgentError::HookInputEmpty {
193 agent: self.name().to_string(),
194 hook_type: hook_type.as_str().to_string(),
195 });
196 }
197
198 // Preserve raw JSON for debugging and downstream use
199 let raw_json: serde_json::Value =
200 serde_json::from_slice(input).map_err(|e| AgentError::HookParseFailed {
201 agent: self.name().to_string(),
202 hook_type: hook_type.as_str().to_string(),
203 reason: e.to_string(),
204 })?;
205
206 let timestamp = TimestampFormat::Rfc3339.parse(self.name(), hook_type, &raw_json)?;
207
208 match hook_type {
209 HookType::TurnStart => {
210 let parsed: PromptSubmitInput =
211 serde_json::from_value(raw_json.clone()).map_err(|e| {
212 AgentError::HookParseFailed {
213 agent: self.name().to_string(),
214 hook_type: hook_type.as_str().to_string(),
215 reason: e.to_string(),
216 }
217 })?;
218
219 let mut event =
220 TurnEvent::new(Self::extract_session_id(parsed.session_id), hook_type)
221 .with_raw_json(raw_json);
222
223 if let Some(prompt) = parsed.prompt {
224 event = event.with_prompt(prompt);
225 }
226
227 // Store model in raw_json for the orchestrator
228 if let Some(model) = parsed.model {
229 if let Some(ref mut raw) = event.raw_json {
230 if let Some(obj) = raw.as_object_mut() {
231 obj.insert("model".to_string(), serde_json::Value::String(model));
232 }
233 }
234 }
235
236 Ok(event)
237 }
238
239 HookType::TurnEnd => {
240 let parsed: AgentStopInput =
241 serde_json::from_value(raw_json.clone()).map_err(|e| {
242 AgentError::HookParseFailed {
243 agent: self.name().to_string(),
244 hook_type: hook_type.as_str().to_string(),
245 reason: e.to_string(),
246 }
247 })?;

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