use serde_json::{Map, Value};
pub(crate) mod normalize;
pub(crate) mod process;
pub(crate) mod redact;
pub(crate) mod sanitize;
pub(crate) mod settle;
pub(crate) mod tags;
pub(crate) mod truncate;
pub(crate) type EventObject = Map<String, Value>;
pub(crate) const TOOL_CALL_KEYS: [&str; 26] = [
"id",
"sessionId",
"projectId",
"eventType",
"timestamp",
"duration",
"inputTokens",
"outputTokens",
"ipAddress",
"sdkLanguage",
"agentcatVersion",
"serverName",
"serverVersion",
"clientName",
"clientVersion",
"identifyActorGivenId",
"identifyActorName",
"identifyActorData",
"resourceName",
"parameters",
"response",
"userIntent",
"isError",
"error",
"tags",
"properties",
];
pub(crate) fn set_field(event: &mut EventObject, key: &str, value: Value) {
if let Some(slot) = event.get_mut(key) {
*slot = value;
return;
}
let rank = |name: &str| TOOL_CALL_KEYS.iter().position(|known| *known == name);
let index = rank(key)
.and_then(|own| {
event
.keys()
.position(|present| rank(present).is_some_and(|other| other > own))
})
.unwrap_or(event.len());
event.shift_insert(index, key.to_owned(), value);
}