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
lines 81–94try { 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; }

Requirements

REQ-STOR-008

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

Show on the map →

Called by SCENARIO, record

Calls none

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
lines 54–54nlohmann::json j;lines 55–55j["caller_id"] = entry.caller_id;lines 56–56j["tool_name"] = entry.tool_name;lines 57–58j["params"] = nlohmann::json::parse( entry.params_json.empty() ? "{}" : entry.params_json);lines 59–59j["result"]["status"] = entry.result_status;lines 60–60j["result"]["content"] = entry.result_content;lines 61–61j["result"]["elapsed_ms"] = entry.elapsed_ms;lines 62–63j["directives"] = nlohmann::json::parse( entry.directives_json.empty() ? "[]" : entry.directives_json);lines 64–64j["delegation_depth"] = entry.delegation_depth;lines 65–65j["iteration"] = entry.iteration;lines 66–68j["parent_conversation_id"] = entry.parent_conversation_id.empty() ? nlohmann::json(nullptr) : nlohmann::json(entry.parent_conversation_id);lines 69–69return j;

Requirements

REQ-STOR-008

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
lines 25–26◇ if (j.contains("parent_conversation_id") && !j["parent_conversation_id"].is_null())lines 27–27return j["parent_conversation_id"].get<std::string>();lines 29–29return "";

Requirements

REQ-STOR-008

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>();
}
Activity · 3 steps
lines 41–41entry.result_status = result.at("status").get<std::string>();lines 42–42entry.result_content = result.at("content").get<std::string>();lines 43–43entry.elapsed_ms = result.at("elapsed_ms").get<double>();

Requirements

REQ-STOR-008