Entropic 2.14.3
Local-first agentic inference engine
Loading...
Searching...
No Matches
json_serializers.h File Reference

JSON serialization helpers for the facade. More...

#include <entropic/mcp/utf8_sanitize.h>
#include <entropic/types/config.h>
#include <entropic/types/content.h>
#include <entropic/types/message.h>
#include <nlohmann/json.hpp>
#include <cstddef>
#include <string>
#include <vector>
Include dependency graph for json_serializers.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

nlohmann::json facade_json::serialize_content_part (const entropic::ContentPart &p)
 Serialize one content part, losslessly (gh#165, v2.13.0).
 
nlohmann::json facade_json::serialize_metadata (const entropic::Message &m)
 Serialize a message's metadata map, sanitized (gh#165).
 
nlohmann::json facade_json::serialize_parts (const entropic::Message &m)
 Serialize a message's multimodal parts (gh#165).
 
nlohmann::json facade_json::serialize_message (const entropic::Message &m)
 Serialize ONE message, losslessly — see the file header (gh#165).
 
std::string facade_json::serialize_messages (const std::vector< entropic::Message > &messages)
 Serialize messages to JSON array string — see serialize_message.
 
nlohmann::json facade_json::parse (const char *str)
 Parse JSON string to nlohmann::json object.
 
nlohmann::json facade_json::obj ()
 Create a JSON object from key-value pairs.
 
nlohmann::json facade_json::arr ()
 Create an empty JSON array.
 
std::string facade_json::serialize_adapter_info (const entropic::AdapterInfo &ai)
 Serialize an AdapterInfo to JSON string.
 
std::string facade_json::serialize_adapter_list (const std::vector< entropic::AdapterInfo > &adapters)
 Serialize a list of AdapterInfo to JSON array string.
 

Detailed Description

JSON serialization helpers for the facade.

Concentrates all nlohmann/json usage in one private facade header. The main entropic.cpp should not include nlohmann/json.hpp directly.

UTF-8 boundary (issue #3, v2.1.1)
Every string is passed through entropic::mcp::sanitize_utf8 before it is pushed, so bytes that slipped past the inbound sanitize boundaries (model-stream desync, pre-2.1.1 audit-replayed history, pre-2.1.1 stored conversation state) cannot reach dump() and raise json::type_error 316. This is the C-API OUTBOUND boundary; see include/entropic/mcp/utf8_sanitize.h for the full policy.
Message emission is lossless (gh#165, v2.13.0)
serialize_messages emitted ONLY role + content until v2.13.0, which made entropic_session_context_get a lossy read: metadata (every tool_name that context_manager, compaction and the engine's tool-result folding key off, and every is_context_anchor) and content_parts were dropped. That was invisible for as long as nothing fed the output back; entropic_session_context_set is the reader that makes it matter — a write counterpart is only worth having if the read it round-trips with preserves what the engine acts on.

The addition is ADDITIVE by construction: the new keys appear only when there is something to carry, and content stays a STRING on every message, so a consumer reading role/content sees byte-identical output for every message it has ever seen. Parts go in their own content_parts key rather than turning content into an array (the INBOUND multimodal shape), precisely so that promise holds.

Version
2.13.0

Definition in file json_serializers.h.

Function Documentation

◆ arr()

nlohmann::json facade_json::arr ( )
inline

Create an empty JSON array.

Returns
Empty JSON array. @utility
Version
2.0.1

Definition at line 174 of file json_serializers.h.

◆ obj()

nlohmann::json facade_json::obj ( )
inline

Create a JSON object from key-value pairs.

Returns
Empty JSON object. @utility
Version
2.0.1

Definition at line 166 of file json_serializers.h.

◆ parse()

nlohmann::json facade_json::parse ( const char *  str)
inline

Parse JSON string to nlohmann::json object.

Parameters
strJSON string.
Returns
Parsed JSON (discarded on error). @utility
Version
2.0.1

Definition at line 155 of file json_serializers.h.

◆ serialize_adapter_info()

std::string facade_json::serialize_adapter_info ( const entropic::AdapterInfo &  ai)
inline

Serialize an AdapterInfo to JSON string.

Parameters
aiAdapter info struct.
Returns
JSON object string. @utility
Version
2.0.1

Definition at line 183 of file json_serializers.h.

◆ serialize_adapter_list()

std::string facade_json::serialize_adapter_list ( const std::vector< entropic::AdapterInfo > &  adapters)
inline

Serialize a list of AdapterInfo to JSON array string.

Parameters
adaptersAdapter info list.
Returns
JSON array string. @utility
Version
2.0.1

Definition at line 203 of file json_serializers.h.

◆ serialize_content_part()

nlohmann::json facade_json::serialize_content_part ( const entropic::ContentPart &  p)
inline

Serialize one content part, losslessly (gh#165, v2.13.0).

Image geometry is carried because width/height are set by the preprocessor and a restore that dropped them would silently re-run it.

Parameters
pContent part.
Returns
JSON object for that part. @utility
Version
2.13.0

Definition at line 61 of file json_serializers.h.

◆ serialize_message()

nlohmann::json facade_json::serialize_message ( const entropic::Message &  m)
inline

Serialize ONE message, losslessly — see the file header (gh#165).

Parameters
mMessage to serialize.
Returns
JSON object for that message. @req REQ-SAFE-001 @req REQ-LOOP-010
Version
2.13.0

Definition at line 120 of file json_serializers.h.

◆ serialize_messages()

std::string facade_json::serialize_messages ( const std::vector< entropic::Message > &  messages)
inline

Serialize messages to JSON array string — see serialize_message.

Parameters
messagesMessage vector.
Returns
JSON array string. @req REQ-SAFE-001 @req REQ-LOOP-010
Version
2.13.0

Definition at line 139 of file json_serializers.h.

◆ serialize_metadata()

nlohmann::json facade_json::serialize_metadata ( const entropic::Message &  m)
inline

Serialize a message's metadata map, sanitized (gh#165).

Parameters
mMessage.
Returns
JSON object; empty when the message carries no metadata. @utility
Version
2.13.0

Definition at line 83 of file json_serializers.h.

◆ serialize_parts()

nlohmann::json facade_json::serialize_parts ( const entropic::Message &  m)
inline

Serialize a message's multimodal parts (gh#165).

Parameters
mMessage.
Returns
JSON array; empty when the message is text-only. @utility
Version
2.13.0

Definition at line 98 of file json_serializers.h.