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

Method parse_event

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

Source from the content-addressed store, hash-verified

186 }
187
188 fn parse_event(&self, hook_type: HookType, input: &[u8]) -> AgentResult<TurnEvent> {
189 if input.is_empty() {
190 return Err(AgentError::HookInputEmpty {
191 agent: self.name().to_string(),
192 hook_type: hook_type.as_str().to_string(),
193 });
194 }
195
196 let (parsed, raw) = Self::parse_input(self.name(), hook_type, input)?;
197
198 if parsed.session_id.is_empty() {
199 return Err(AgentError::HookParseFailed {
200 agent: self.name().to_string(),
201 hook_type: hook_type.as_str().to_string(),
202 reason: "session_id is empty".to_string(),
203 });
204 }
205
206 let mut event = TurnEvent::new(parsed.session_id.clone(), hook_type).with_raw_json(raw);
207
208 // Stamp model and provider so the orchestrator can persist them on
209 // the AgentSession — same pattern as OpenCode.
210 if let Some(model) = &parsed.model {
211 if !model.is_empty() {
212 if let Some(ref mut raw_json) = event.raw_json {
213 if let Some(obj) = raw_json.as_object_mut() {
214 obj.insert(
215 "model".to_string(),
216 serde_json::Value::String(model.clone()),
217 );
218 }
219 }
220 }
221 }
222 if let Some(provider) = &parsed.provider {
223 if !provider.is_empty() {
224 if let Some(ref mut raw_json) = event.raw_json {
225 if let Some(obj) = raw_json.as_object_mut() {
226 obj.insert(
227 "provider".to_string(),
228 serde_json::Value::String(provider.clone()),
229 );
230 }
231 }
232 }
233 }
234
235 match hook_type {
236 HookType::TurnStart => {
237 // intent_title doubles as the turn prompt — used by the
238 // orchestrator to set session.current_prompt so the atomic
239 // record message is meaningful.
240 if let Some(title) = &parsed.intent_title {
241 event = event.with_prompt(title.clone());
242 }
243 }
244
245 HookType::TurnEnd => {

Calls 7

with_raw_jsonMethod · 0.80
with_promptMethod · 0.80
is_emptyMethod · 0.45
nameMethod · 0.45
as_strMethod · 0.45
cloneMethod · 0.45
insertMethod · 0.45