feat(clients): sessions+registry+optimize+armor: close gaps, loud list truncation, shared Gemini adapter
sessions: operations get/list/cancel/delete/wait for engine, session, memory and serving profile; servingProfiles CRUD. registry: ListResult with truncated flag, v1alpha twins, gateway/policy operations, authz IAM, deny policy update, boundary patch/bindings. optimize: make_gemini_model over models::VertexModel (DirectModel removed), generateSyntheticData, online evaluator operations, trace/log writers. armor: SecurityAdmin for all SCC v2 methods (attack exposure excluded), documented agent threat categories, floor settings fixed to location global after live run. check_discovery.py of all four enforce coverage. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -53,6 +53,19 @@ fw::Response json_reply(const Json& j, int status = 200) {
|
||||
return res;
|
||||
}
|
||||
|
||||
// A list answer. Truncation is part of the answer, never hidden: `truncated`
|
||||
// is true when more existed past the stated cap, `cap_items` names the cap.
|
||||
Json list_answer(const reg::ListResult& list, const char* items_key) {
|
||||
Json j = Json::object();
|
||||
j.set("count", Json(static_cast<int>(list.size())));
|
||||
j.set("pages", Json(static_cast<int>(list.pages)));
|
||||
j.set("truncated", Json(list.truncated));
|
||||
j.set("next_page_token", Json(list.next_page_token));
|
||||
j.set("cap_items", Json(static_cast<int>(reg::RegistryCaps::kMaxItems)));
|
||||
j.set(items_key, list.items);
|
||||
return j;
|
||||
}
|
||||
|
||||
std::string field(std::map<std::string, std::string>& in, const char* key) {
|
||||
auto it = in.find(key);
|
||||
return it == in.end() ? "" : it->second;
|
||||
@@ -87,7 +100,9 @@ class RegistryDemo {
|
||||
void require_credential() const {
|
||||
if (!configured()) throw google::NotConfiguredError("registry");
|
||||
}
|
||||
reg::AgentRegistry registry() const { return reg::AgentRegistry(client_, ready()); }
|
||||
reg::AgentRegistry registry(reg::RegistryVersion v = reg::RegistryVersion::kV1) const {
|
||||
return reg::AgentRegistry(client_, ready(), v);
|
||||
}
|
||||
reg::AgentGateway gateway() const { return reg::AgentGateway(client_, ready()); }
|
||||
reg::GatewayPolicies policies() const { return reg::GatewayPolicies(client_, ready()); }
|
||||
reg::AgentIdentity identity() const { return reg::AgentIdentity(client_, ready()); }
|
||||
@@ -122,6 +137,11 @@ here is a local list: the registry API has no approve method.</p>
|
||||
<option value="skills">Skills</option>
|
||||
<option value="bindings">Bindings</option>
|
||||
</select></label>
|
||||
<label class="inline">API version
|
||||
<select id="r-version">
|
||||
<option value="v1">v1</option>
|
||||
<option value="v1alpha">v1alpha</option>
|
||||
</select></label>
|
||||
<input id="r-q" type="text" maxlength="200" placeholder="Search text or asset id" autocomplete="off">
|
||||
<div class="registry-actions">
|
||||
<button id="r-list" type="button" class="primary">List</button>
|
||||
@@ -133,10 +153,14 @@ here is a local list: the registry API has no approve method.</p>
|
||||
<option value="gateways">Agent gateways</option>
|
||||
<option value="policies">Gateway policies</option>
|
||||
<option value="identity">Agent identity (engine id)</option>
|
||||
<option value="ops-registry">Operations: registry</option>
|
||||
<option value="ops-gateways">Operations: gateways</option>
|
||||
<option value="ops-policies">Operations: policies</option>
|
||||
<option value="approvals">Approvals (local)</option>
|
||||
<option value="audit">Approval audit (local)</option>
|
||||
</select></label>
|
||||
<button id="r-gov-go" type="button">Show</button>
|
||||
<p id="r-truncated" class="error" role="status" hidden></p>
|
||||
<p id="r-error" class="error" role="alert"></p>
|
||||
<pre id="r-out" class="scroll"></pre>
|
||||
</section>
|
||||
@@ -169,6 +193,7 @@ void register_agent_registry_demo(fw::Router& router, Services& services) {
|
||||
Json caps = Json::object();
|
||||
caps.set("page_size", Json(reg::RegistryCaps::kPageSize));
|
||||
caps.set("max_pages", Json(static_cast<int>(reg::RegistryCaps::kMaxPages)));
|
||||
caps.set("max_items", Json(static_cast<int>(reg::RegistryCaps::kMaxItems)));
|
||||
caps.set("max_ledger_entries", Json(static_cast<int>(reg::RegistryCaps::kMaxLedgerEntries)));
|
||||
caps.set("max_audit_entries", Json(static_cast<int>(reg::RegistryCaps::kMaxAuditEntries)));
|
||||
j.set("caps", caps);
|
||||
@@ -259,15 +284,17 @@ void register_agent_registry_demo(fw::Router& router, Services& services) {
|
||||
reg::AssetKind::kSkills, reg::AssetKind::kBindings,
|
||||
reg::AssetKind::kPublishers});
|
||||
bool approved_only = field(in, "approved_only") == "true";
|
||||
std::string version = field(in, "version");
|
||||
if (!version.empty() && version != "v1" && version != "v1alpha") bad("version must be v1 or v1alpha");
|
||||
return guarded([&] {
|
||||
reg::AgentRegistry registry = demo->registry();
|
||||
Json items = approved_only ? registry.list_approved(kind, demo->ledger())
|
||||
: registry.list(kind);
|
||||
Json j = Json::object();
|
||||
reg::AgentRegistry registry = demo->registry(version == "v1alpha" ? reg::RegistryVersion::kV1Alpha
|
||||
: reg::RegistryVersion::kV1);
|
||||
reg::ListResult list = approved_only ? registry.list_approved(kind, demo->ledger())
|
||||
: registry.list(kind);
|
||||
Json j = list_answer(list, "items");
|
||||
j.set("kind", Json(reg::asset_collection(kind)));
|
||||
j.set("version", Json(registry.version()));
|
||||
j.set("approved_only", Json(approved_only));
|
||||
j.set("count", Json(static_cast<int>(items.as_array().size())));
|
||||
j.set("items", items);
|
||||
return json_reply(j);
|
||||
});
|
||||
});
|
||||
@@ -377,11 +404,7 @@ void register_agent_registry_demo(fw::Router& router, Services& services) {
|
||||
// ---- Gateways and policies (reads, plus an explicit delete).
|
||||
router.post("/agent/registry/gateways/list", "agent-registry-gateways", [demo](fw::Request) {
|
||||
return guarded([&] {
|
||||
Json items = demo->gateway().list();
|
||||
Json j = Json::object();
|
||||
j.set("count", Json(static_cast<int>(items.as_array().size())));
|
||||
j.set("gateways", items);
|
||||
return json_reply(j);
|
||||
return json_reply(list_answer(demo->gateway().list(), "gateways"));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -400,14 +423,92 @@ void register_agent_registry_demo(fw::Router& router, Services& services) {
|
||||
|
||||
router.post("/agent/registry/policies/list", "agent-registry-policies", [demo](fw::Request) {
|
||||
return guarded([&] {
|
||||
Json items = demo->policies().list();
|
||||
Json j = Json::object();
|
||||
j.set("count", Json(static_cast<int>(items.as_array().size())));
|
||||
j.set("policies", items);
|
||||
return json_reply(list_answer(demo->policies().list(), "policies"));
|
||||
});
|
||||
});
|
||||
|
||||
// ---- Operations of the three registry-side hosts. Reads are POST (they
|
||||
// call out); delete is DELETE and explicit (the operation record only).
|
||||
auto scope_of = [](std::map<std::string, std::string>& in) {
|
||||
std::string s = field(in, "scope");
|
||||
if (s != "registry" && s != "gateways" && s != "policies")
|
||||
bad("scope must be registry, gateways or policies");
|
||||
return s;
|
||||
};
|
||||
router.post("/agent/registry/operations/list", "agent-registry-operations", [demo, scope_of](fw::Request req) {
|
||||
auto in = fw::parse_json_object_flat(req.body);
|
||||
std::string scope = scope_of(in);
|
||||
return guarded([&] {
|
||||
reg::ListResult ops = scope == "registry" ? demo->registry().operations()
|
||||
: scope == "gateways" ? demo->gateway().operations()
|
||||
: demo->policies().operations();
|
||||
Json j = list_answer(ops, "operations");
|
||||
j.set("scope", Json(scope));
|
||||
return json_reply(j);
|
||||
});
|
||||
});
|
||||
|
||||
router.post("/agent/registry/operations/cancel", "agent-registry-operation-cancel",
|
||||
[demo, scope_of](fw::Request req) {
|
||||
auto in = fw::parse_json_object_flat(req.body);
|
||||
std::string scope = scope_of(in);
|
||||
std::string id = field(in, "id");
|
||||
if (!google::valid_segment(id)) bad("id is empty or has invalid characters");
|
||||
return guarded([&] {
|
||||
Json r = scope == "registry" ? demo->registry().cancel_operation(id)
|
||||
: scope == "gateways" ? demo->gateway().cancel_operation(id)
|
||||
: demo->policies().cancel_operation(id);
|
||||
Json j = Json::object();
|
||||
j.set("scope", Json(scope));
|
||||
j.set("cancel_requested", Json(true));
|
||||
j.set("reply", r);
|
||||
return json_reply(j);
|
||||
});
|
||||
});
|
||||
|
||||
router.del("/agent/registry/operations", "agent-registry-operation-delete", [demo](fw::Request req) {
|
||||
std::string scope = req.query_or("scope", "");
|
||||
std::string id = req.query_or("id", "");
|
||||
if (scope != "registry" && scope != "gateways" && scope != "policies")
|
||||
bad("scope must be registry, gateways or policies");
|
||||
if (!google::valid_segment(id)) bad("id is empty or has invalid characters");
|
||||
return guarded([&] {
|
||||
Json r = scope == "registry" ? demo->registry().delete_operation(id)
|
||||
: scope == "gateways" ? demo->gateway().delete_operation(id)
|
||||
: demo->policies().delete_operation(id);
|
||||
Json j = Json::object();
|
||||
j.set("deleted", Json(true));
|
||||
j.set("reply", r);
|
||||
return json_reply(j);
|
||||
});
|
||||
});
|
||||
|
||||
// ---- IAM deny policies (iam v2) and boundary bindings (iam v3).
|
||||
router.post("/agent/registry/deny-policies/list", "agent-registry-deny-policies", [demo](fw::Request req) {
|
||||
auto in = fw::parse_json_object_flat(req.body);
|
||||
std::string number = field(in, "project_number");
|
||||
if (number.empty() || number.size() > 20 || number.find_first_not_of("0123456789") != std::string::npos)
|
||||
bad("project_number must be numeric");
|
||||
return guarded([&] {
|
||||
return json_reply(list_answer(
|
||||
demo->identity().deny_policies(reg::AgentIdentity::attachment_for_project(number)),
|
||||
"policies"));
|
||||
});
|
||||
});
|
||||
|
||||
router.post("/agent/registry/boundaries/bindings", "agent-registry-boundary-bindings",
|
||||
[demo](fw::Request req) {
|
||||
auto in = fw::parse_json_object_flat(req.body);
|
||||
std::string org = field(in, "org_id");
|
||||
std::string id = field(in, "id");
|
||||
if (org.empty() || org.size() > 20 || org.find_first_not_of("0123456789") != std::string::npos)
|
||||
bad("org_id must be numeric");
|
||||
if (!google::valid_segment(id)) bad("id is empty or has invalid characters");
|
||||
return guarded([&] {
|
||||
return json_reply(list_answer(demo->identity().boundary_bindings(org, id), "bindings"));
|
||||
});
|
||||
});
|
||||
|
||||
// ---- Identity of one deployed agent (engine id).
|
||||
router.post("/agent/registry/identity", "agent-registry-identity", [demo](fw::Request req) {
|
||||
auto in = fw::parse_json_object_flat(req.body);
|
||||
|
||||
Reference in New Issue
Block a user