Skip to content

Commit 32937ca

Browse files
committed
Implement inline catalog support and schema merging in schema/manager.cc
1 parent 90a8951 commit 32937ca

1 file changed

Lines changed: 42 additions & 2 deletions

File tree

agent_sdks/cpp/src/schema/manager.cc

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,59 @@ A2uiCatalog A2uiSchemaManager::select_catalog(const std::optional<nlohmann::json
9595
}
9696
}
9797

98+
bool has_inline = client_ui_capabilities->contains("inlineCatalogs") && (*client_ui_capabilities)["inlineCatalogs"].is_array();
99+
100+
if (has_inline && !accepts_inline_catalogs_) {
101+
throw std::runtime_error("Inline catalogs are not accepted");
102+
}
103+
104+
A2uiCatalog selected_catalog = supported_catalogs_[0];
105+
bool found = false;
106+
98107
if (!client_supported_ids.empty()) {
99108
for (const auto& cscid : client_supported_ids) {
100109
for (const auto& c : supported_catalogs_) {
101110
if (c.catalog_id() == cscid) {
102-
return c;
111+
selected_catalog = c;
112+
found = true;
113+
break;
114+
}
115+
}
116+
if (found) break;
117+
}
118+
if (!found && !has_inline) {
119+
throw std::runtime_error("No client-supported catalog found");
120+
}
121+
}
122+
123+
if (has_inline) {
124+
nlohmann::json merged_schema = selected_catalog.catalog_schema();
125+
for (const auto& inline_cat : (*client_ui_capabilities)["inlineCatalogs"]) {
126+
nlohmann::json inline_schema = inline_cat;
127+
for (const auto& modifier : schema_modifiers_) {
128+
inline_schema = modifier(inline_schema);
129+
}
130+
131+
if (inline_schema.contains("components") && inline_schema["components"].is_object()) {
132+
if (!merged_schema.contains("components")) {
133+
merged_schema["components"] = nlohmann::json::object();
103134
}
135+
merged_schema["components"].update(inline_schema["components"]);
104136
}
105137
}
138+
return A2uiCatalog(
139+
selected_catalog.version(),
140+
"inline", // Match Python INLINE_CATALOG_NAME
141+
selected_catalog.s2c_schema(),
142+
selected_catalog.common_types_schema(),
143+
merged_schema
144+
);
106145
}
107146

108-
return supported_catalogs_[0];
147+
return selected_catalog;
109148
}
110149

150+
111151
A2uiCatalog A2uiSchemaManager::get_selected_catalog(
112152
const std::optional<nlohmann::json>& client_ui_capabilities,
113153
const std::optional<std::vector<std::string>>& allowed_components,

0 commit comments

Comments
 (0)