Entropic 2.3.8
Local-first agentic inference engine
Loading...
Searching...
No Matches
json_serializers.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
12#pragma once
13
17#include <nlohmann/json.hpp>
18#include <string>
19#include <vector>
20
21namespace facade_json {
22
39inline std::string serialize_messages(
40 const std::vector<entropic::Message>& messages) {
41 nlohmann::json arr = nlohmann::json::array();
42 for (const auto& m : messages) {
43 arr.push_back({{"role", m.role},
44 {"content", entropic::mcp::sanitize_utf8(m.content)}});
45 }
46 return arr.dump();
47}
48
56inline nlohmann::json parse(const char* str) {
57 if (!str) { return nlohmann::json(); }
58 return nlohmann::json::parse(str, nullptr, false);
59}
60
67inline nlohmann::json obj() { return nlohmann::json::object(); }
68
75inline nlohmann::json arr() { return nlohmann::json::array(); }
76
84inline std::string serialize_adapter_info(
85 const entropic::AdapterInfo& ai) {
86 nlohmann::json j;
87 j["name"] = ai.name;
88 j["state"] = static_cast<int>(ai.state);
89 j["scale"] = ai.scale;
90 j["ram_bytes"] = ai.ram_bytes;
91 j["path"] = ai.path.string();
92 j["tier_name"] = ai.tier_name;
93 j["base_model_path"] = ai.base_model_path;
94 return j.dump();
95}
96
104inline std::string serialize_adapter_list(
105 const std::vector<entropic::AdapterInfo>& adapters) {
106 nlohmann::json a = nlohmann::json::array();
107 for (const auto& ai : adapters) {
108 a.push_back({{"name", ai.name},
109 {"state", static_cast<int>(ai.state)},
110 {"scale", ai.scale},
111 {"tier_name", ai.tier_name}});
112 }
113 return a.dump();
114}
115
116} // namespace facade_json
Configuration structs with defaults.
std::string serialize_messages(const std::vector< entropic::Message > &messages)
Serialize messages to JSON array string.
std::string serialize_adapter_list(const std::vector< entropic::AdapterInfo > &adapters)
Serialize a list of AdapterInfo to JSON array string.
std::string serialize_adapter_info(const entropic::AdapterInfo &ai)
Serialize an AdapterInfo to JSON string.
nlohmann::json parse(const char *str)
Parse JSON string to nlohmann::json object.
nlohmann::json obj()
Create a JSON object from key-value pairs.
nlohmann::json arr()
Create an empty JSON array.
Message struct for conversation history.
Metadata for a loaded LoRA adapter.
Definition config.h:126
std::string tier_name
Tier this adapter is assigned to (empty = unassigned)
Definition config.h:131
size_t ram_bytes
RAM consumption when WARM/HOT (0 if COLD)
Definition config.h:133
std::string base_model_path
Path of the base model this adapter targets.
Definition config.h:132
std::filesystem::path path
Resolved path to .gguf adapter file.
Definition config.h:128
AdapterState state
Current lifecycle state.
Definition config.h:129
std::string name
Unique adapter identifier.
Definition config.h:127
float scale
LoRA scaling factor (alpha/rank)
Definition config.h:130
UTF-8 validation + replacement at every system boundary where bytes change ownership.