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:
@@ -8,11 +8,13 @@
|
||||
#include "google/optimize/autorater.h"
|
||||
#include "google/optimize/calls.h"
|
||||
#include "google/optimize/clusterer.h"
|
||||
#include "google/optimize/direct_model.h"
|
||||
#include "google/optimize/model_factory.h"
|
||||
#include "google/optimize/eval_requests.h"
|
||||
#include "google/optimize/eval_resources.h"
|
||||
#include "google/optimize/evaluation_api.h"
|
||||
#include "google/optimize/observability.h"
|
||||
#include "google/optimize/operations_api.h"
|
||||
#include "google/optimize/telemetry_writer.h"
|
||||
#include "google/optimize/optimizer.h"
|
||||
#include "google/optimize/simulator.h"
|
||||
|
||||
@@ -131,7 +133,7 @@ void register_agent_optimize_demo(fw::Router& router, Services& services) {
|
||||
services.add_feature("agent optimize", "/agent/optimize");
|
||||
|
||||
auto model_for = [gclient]() {
|
||||
return google::optimize::DirectModel::from_env(gclient);
|
||||
return google::optimize::make_gemini_model(gclient);
|
||||
};
|
||||
|
||||
router.get("/agent/optimize", "agent-optimize-page", [env](fw::Request req) {
|
||||
@@ -287,6 +289,117 @@ void register_agent_optimize_demo(fw::Router& router, Services& services) {
|
||||
});
|
||||
});
|
||||
|
||||
// generateSyntheticData: `request` is the Discovery request object (or its
|
||||
// JSON text); top-level fields are checked against the call table.
|
||||
router.post("/agent/optimize/synthetic", "agent-optimize-synthetic", [gclient](fw::Request req) {
|
||||
Json body = parse_body(req);
|
||||
const Json* r = body.find("request");
|
||||
Json request;
|
||||
if (r && r->is_object()) request = *r;
|
||||
else if (r && r->is_string()) {
|
||||
try { request = Json::parse(r->as_string()); } catch (const clients::body::JsonError&) {}
|
||||
}
|
||||
if (!request.is_object() || request.as_object().empty())
|
||||
throw fw::HttpError(422, "validation_error", "request must be a non-empty JSON object");
|
||||
google::CloudContext ctx = require_context();
|
||||
return guarded([&] { return json_out(opt::EvaluationApi(gclient, ctx).generate_synthetic_data(request)); });
|
||||
});
|
||||
|
||||
// Operations of online evaluators (get, list, server-side wait, cancel;
|
||||
// delete is a DELETE route and removes the operation record only).
|
||||
auto op_json = [](const google::Operation& op) {
|
||||
Json o = Json::object();
|
||||
o.set("name", Json(op.name));
|
||||
o.set("done", Json(op.done));
|
||||
if (op.failed()) o.set("error_message", Json(op.error_message));
|
||||
return o;
|
||||
};
|
||||
router.post("/agent/optimize/operations/list", "agent-optimize-ops-list", [gclient, op_json](fw::Request req) {
|
||||
Json body = parse_body(req);
|
||||
std::string evaluator = text_field(body, "evaluator", true, 512);
|
||||
int limit = int_field(body, "limit", 20, 1, 100);
|
||||
google::CloudContext ctx = require_context();
|
||||
return guarded([&] {
|
||||
opt::OperationPage page = opt::OnlineEvaluatorOperations(gclient, ctx).list(evaluator, "", limit);
|
||||
Json arr = Json::array();
|
||||
for (const google::Operation& op : page.operations) arr.push(op_json(op));
|
||||
Json out = Json::object();
|
||||
out.set("operations", arr);
|
||||
out.set("count", Json(static_cast<int>(page.operations.size())));
|
||||
out.set("truncated", Json(page.truncated));
|
||||
out.set("next_page_token", Json(page.next_page_token));
|
||||
return json_out(out);
|
||||
});
|
||||
});
|
||||
router.post("/agent/optimize/operations/get", "agent-optimize-ops-get", [gclient](fw::Request req) {
|
||||
Json body = parse_body(req);
|
||||
std::string name = text_field(body, "name", true, 512);
|
||||
google::CloudContext ctx = require_context();
|
||||
return guarded([&] { return json_out(opt::OnlineEvaluatorOperations(gclient, ctx).get(name)); });
|
||||
});
|
||||
router.post("/agent/optimize/operations/wait", "agent-optimize-ops-wait", [gclient, op_json](fw::Request req) {
|
||||
Json body = parse_body(req);
|
||||
std::string name = text_field(body, "name", true, 512);
|
||||
int seconds = int_field(body, "timeout_seconds", 30, 1, opt::OptimizeCaps::kMaxServerWaitSeconds);
|
||||
google::CloudContext ctx = require_context();
|
||||
return guarded([&] {
|
||||
return json_out(op_json(opt::OnlineEvaluatorOperations(gclient, ctx).wait_server(name, seconds)));
|
||||
});
|
||||
});
|
||||
router.post("/agent/optimize/operations/cancel", "agent-optimize-ops-cancel", [gclient](fw::Request req) {
|
||||
Json body = parse_body(req);
|
||||
std::string name = text_field(body, "name", true, 512);
|
||||
google::CloudContext ctx = require_context();
|
||||
return guarded([&] {
|
||||
opt::OnlineEvaluatorOperations(gclient, ctx).cancel(name);
|
||||
Json out = Json::object();
|
||||
out.set("cancel_requested", Json(true));
|
||||
return json_out(out);
|
||||
});
|
||||
});
|
||||
router.del("/agent/optimize/operations", "agent-optimize-ops-delete", [gclient](fw::Request req) {
|
||||
std::string name = req.query_or("name", "");
|
||||
if (name.empty() || !opt::OnlineEvaluatorOperations::is_operation_name(name))
|
||||
throw fw::HttpError(422, "validation_error", "name must be an online evaluator operation name");
|
||||
google::CloudContext ctx = require_context();
|
||||
return guarded([&] {
|
||||
opt::OnlineEvaluatorOperations(gclient, ctx).remove(name);
|
||||
Json out = Json::object();
|
||||
out.set("deleted", Json(true));
|
||||
return json_out(out);
|
||||
});
|
||||
});
|
||||
|
||||
// entries:write. A dry run (nothing stored) unless confirm is "write".
|
||||
router.post("/agent/optimize/logs/write", "agent-optimize-logs-write", [gclient](fw::Request req) {
|
||||
Json body = parse_body(req);
|
||||
std::string log_id = text_field(body, "log_id", true, 100);
|
||||
std::string text = text_field(body, "text", true, 4000);
|
||||
std::string confirm = text_field(body, "confirm", false, 16);
|
||||
if (!google::valid_segment(log_id))
|
||||
throw fw::HttpError(422, "validation_error", "log_id has invalid characters");
|
||||
google::CloudContext ctx = require_context();
|
||||
bool real = confirm == "write";
|
||||
Json entry = Json::object();
|
||||
entry.set("textPayload", Json(text));
|
||||
Json entries = Json::array();
|
||||
entries.push(entry);
|
||||
Json resource = Json::object();
|
||||
resource.set("type", Json("global"));
|
||||
Json request = Json::object();
|
||||
request.set("logName", Json("projects/" + ctx.project + "/logs/" + log_id));
|
||||
request.set("resource", resource);
|
||||
request.set("entries", entries);
|
||||
request.set("dryRun", Json(!real));
|
||||
return guarded([&] {
|
||||
opt::LogWriter(gclient).write(request);
|
||||
Json out = Json::object();
|
||||
out.set("dry_run", Json(!real));
|
||||
out.set("written", Json(real));
|
||||
return json_out(out);
|
||||
});
|
||||
});
|
||||
|
||||
// Local autorater over a pasted transcript ("user: ..." / "agent: ...").
|
||||
router.post("/agent/optimize/score", "agent-optimize-score", [model_for](fw::Request req) {
|
||||
Json body = parse_body(req);
|
||||
|
||||
Reference in New Issue
Block a user