audit_entry.cpp¶
src/storage/audit_entry.cpp
@file audit_entry.cpp @brief AuditEntry JSON serialization implementation.
Owners: @tvanfossen
audit_entry_from_json
bool entropic::audit_entry_from_json(const nlohmann::json &j, AuditEntry &entry)
Deserialize AuditEntry fields from a JSON object.
src/storage/audit_entry.cpp:80
Source · 16 lines
bool audit_entry_from_json(const nlohmann::json& j, AuditEntry& entry) {
try {
entry.caller_id = j.at("caller_id").get<std::string>();
entry.tool_name = j.at("tool_name").get<std::string>();
entry.params_json = j.at("params").dump();
parse_result_fields(j.at("result"), entry);
entry.directives_json = j.at("directives").dump();
entry.delegation_depth = j.at("delegation_depth").get<int>();
entry.iteration = j.at("iteration").get<int>();
entry.parent_conversation_id = extract_parent_id(j);
return true;
} catch (const nlohmann::json::exception& e) {
logger->warn("Failed to parse audit entry: {}", e.what());
return false;
}
}Activity · 1 steps
Requirements
audit_entry_to_json
nlohmann::json entropic::audit_entry_to_json(const AuditEntry &entry)
Serialize AuditEntry fields to a JSON object.
src/storage/audit_entry.cpp:53
Source · 18 lines
nlohmann::json audit_entry_to_json(const AuditEntry& entry) {
nlohmann::json j;
j["caller_id"] = entry.caller_id;
j["tool_name"] = entry.tool_name;
j["params"] = nlohmann::json::parse(
entry.params_json.empty() ? "{}" : entry.params_json);
j["result"]["status"] = entry.result_status;
j["result"]["content"] = entry.result_content;
j["result"]["elapsed_ms"] = entry.elapsed_ms;
j["directives"] = nlohmann::json::parse(
entry.directives_json.empty() ? "[]" : entry.directives_json);
j["delegation_depth"] = entry.delegation_depth;
j["iteration"] = entry.iteration;
j["parent_conversation_id"] = entry.parent_conversation_id.empty()
? nlohmann::json(nullptr)
: nlohmann::json(entry.parent_conversation_id);
return j;
}Activity · 12 steps
Requirements
extract_parent_id
static std::string entropic::extract_parent_id(const nlohmann::json &j)
Extract optional parent_conversation_id from JSON.
src/storage/audit_entry.cpp:24
Source · 7 lines
static std::string extract_parent_id(const nlohmann::json& j) {
if (j.contains("parent_conversation_id") &&
!j["parent_conversation_id"].is_null()) {
return j["parent_conversation_id"].get<std::string>();
}
return "";
}Activity · 3 steps
Requirements
parse_result_fields
static void entropic::parse_result_fields(const nlohmann::json &result, AuditEntry &entry)
Parse the result sub-object from JSON into AuditEntry fields.
src/storage/audit_entry.cpp:39
Source · 6 lines
static void parse_result_fields(
const nlohmann::json& result, AuditEntry& entry) {
entry.result_status = result.at("status").get<std::string>();
entry.result_content = result.at("content").get<std::string>();
entry.elapsed_ms = result.at("elapsed_ms").get<double>();
}