Parse the raw JSON bytes into a [`SherpaHookInput`], returning a well-typed [`AgentError`] on failure.
(
agent: &str,
hook_type: HookType,
input: &[u8],
)
| 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 | |
| 209 | impl AgentHook for SherpaHook { |