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

Method parse_input

atomic-agent/src/hooks/sherpa.rs:184–206  ·  view source on GitHub ↗

Parse the raw JSON bytes into a [`SherpaHookInput`], returning a well-typed [`AgentError`] on failure.

(
        agent: &str,
        hook_type: HookType,
        input: &[u8],
    )

Source from the content-addressed store, hash-verified

182 /// Parse the raw JSON bytes into a [`SherpaHookInput`], returning a
183 /// well-typed [`AgentError`] on failure.
184 fn parse_input(
185 agent: &str,
186 hook_type: HookType,
187 input: &[u8],
188 ) -> AgentResult<(SherpaHookInput, serde_json::Value, DateTime<Utc>)> {
189 let raw: serde_json::Value =
190 serde_json::from_slice(input).map_err(|e| AgentError::HookParseFailed {
191 agent: agent.to_string(),
192 hook_type: hook_type.as_str().to_string(),
193 reason: e.to_string(),
194 })?;
195
196 let timestamp = TimestampFormat::Rfc3339.parse(agent, hook_type, &raw)?;
197
198 let parsed: SherpaHookInput =
199 serde_json::from_value(raw.clone()).map_err(|e| AgentError::HookParseFailed {
200 agent: agent.to_string(),
201 hook_type: hook_type.as_str().to_string(),
202 reason: e.to_string(),
203 })?;
204
205 Ok((parsed, raw, timestamp))
206 }
207}
208
209impl AgentHook for SherpaHook {

Callers

nothing calls this directly

Calls 3

as_strMethod · 0.45
parseMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected