diff --git a/core/server/dashboard.cpp b/core/server/dashboard.cpp index eb52ea51..7732e9cf 100644 --- a/core/server/dashboard.cpp +++ b/core/server/dashboard.cpp @@ -30,6 +30,47 @@ namespace server { * Derived rates are the page's job: they are counter differences over wall time, and only the * browser holds both ends of its poll interval. Computing them here would need per-client state. */ +/* ------------------------------------------------------------------ /admin/control-vector + * + * The control vector's runtime switch (core/cvec.h). Turning it on for the next + * request costs a boolean: the direction table was uploaded at startup and the per-request mask + * is a derived buffer the core fills every step, so there is nothing to rebuild and nothing to + * reload. The engine's own log records the load; this records the flip, because a deployment's + * answer to "was that text produced with the vector" should not depend on a browser's memory. + * + * GET reports the state (and is what the Model view renders); POST takes {"enabled": true|false} + * and answers with the same object. A deployment with no vector loaded answers 404 on both: it has + * no such feature, and its requests refuse `control_vector: true` by name. */ +HttpResponse Server::handle_control_vector(const HttpRequest& req) { + const bool have = deps_.control_vector.available && deps_.control_vector.available(); + if (!have) + return error_response(err_not_implemented( + "this deployment found no control vector for its model; there is nothing to switch"), + req.peer); + + if (req.method == "POST") { + json body; + try { + body = json::parse(req.body.empty() ? "{}" : req.body); + } catch (const std::exception& e) { + return error_response(err_bad("body", std::string("not JSON: ") + e.what()), req.peer); + } + const auto it = body.find("enabled"); + if (it == body.end() || !it->is_boolean()) + return error_response(err_bad("enabled", "a boolean is required"), req.peer); + const bool on = it->get(); + if (deps_.control_vector.set_default) deps_.control_vector.set_default(on); + RAD_INFO("control vector: default %s by an admin request%s", on ? "ON" : "OFF", + req.peer.empty() ? "" : (" from " + req.peer).c_str()); + } else if (req.method != "GET") { + return HttpResponse::json_body(405, err_bad("method", "GET or POST").dump()); + } + + metrics_.observe_http(200); + return HttpResponse::json_body( + 200, deps_.control_vector.json ? deps_.control_vector.json() : std::string("{}")); +} + /* ------------------------------------------------------------------ /sessions * * A separate route, not a /stats field: /stats is polled every second, while a stored session @@ -124,6 +165,16 @@ HttpResponse Server::handle_stats(const HttpRequest&) { json o; o["model"] = opt_.model_id; o["version"] = opt_.version; + /* The control vector (core/cvec.h), when this deployment has one: `available` is what a UI + * tests before offering the control, `default` what a request that names no choice runs. The + * dashboard's own control asks /admin/control-vector, which also reports this. */ + if (deps_.control_vector.json) { + try { + o["control_vector"] = json::parse(deps_.control_vector.json()); + } catch (const std::exception&) { + /* A malformed snapshot is not worth failing /stats over; the field is omitted. */ + } + } o["uptime_s"] = unix_now() - started_at_; /* Seconds this process took to come up, the cost of a restart; 0 before the server listens. */ o["startup_s"] = startup_s_; @@ -643,7 +694,8 @@ th + th, td + td { padding-left:14px; } it as a dot, because on a server with long-lived agent clients the second group is most of the table and none of it needs reading to understand the first. */ #view-sess .cell { height:auto; padding-bottom:12px; } -#view-sess .panel + .panel { margin-top:14px; } +/* Stacked panels in one view are 14px apart, the same gap the strip's own margin-bottom gives. */ +#view-sess .panel + .panel, #view-model .panel + .panel { margin-top:14px; } .stbl td, .stbl th { width:1%; } /* The two text columns take the slack and read left to right; the figures stay narrow. */ .stbl .l { text-align:left; width:auto; } @@ -1177,6 +1229,22 @@ nav button.on { color:var(--fg); background:var(--track); }