Files
moloapp/example/assets/ai_anthropic_admin.js

60 lines
2.5 KiB
JavaScript

// Anthropic admin page: thin client over /ai/anthropic/admin/* (all limits server side).
(function () {
"use strict";
var $ = function (id) { return document.getElementById(id); };
var out = $("ad-out"), err = $("ad-error");
function post(path, body) {
err.textContent = "";
out.textContent = "...";
return fetch(path, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body)
}).then(function (res) {
return res.text().then(function (t) {
var j;
try { j = JSON.parse(t); } catch (e) { j = { message: t }; }
if (!res.ok) {
err.textContent = j.message || ("HTTP " + res.status);
out.textContent = "";
} else {
out.textContent = JSON.stringify(j, null, 2);
}
});
}).catch(function (e) { err.textContent = String(e); out.textContent = ""; });
}
function json(id) {
try { return JSON.parse($(id).value || "{}"); }
catch (e) { err.textContent = "Not valid JSON: " + id; return null; }
}
fetch("/ai/anthropic/admin/status").then(function (r) { return r.json(); }).then(function (s) {
var l = s.lanes || {};
$("ad-config").textContent = "Admin key: " + (l.admin_key || {}).state +
", OAuth token: " + (l.oauth_token || {}).state + ", API key: " + (l.api_key || {}).state +
". " + s.calls + " calls, API version " + s.api_version + ".";
});
fetch("/ai/anthropic/admin/calls").then(function (r) { return r.json(); }).then(function (d) {
var sel = $("ad-call");
d.calls.forEach(function (c) {
var o = document.createElement("option");
o.value = c.name;
o.textContent = c.http + " " + c.name + (c.kind === "read" ? "" : " (" + c.kind + ")");
sel.appendChild(o);
});
});
$("ad-org").onclick = function () { post("/ai/anthropic/admin/organization", {}); };
$("ad-run-report").onclick = function () {
var group = $("ad-group").value.split(",").map(function (s) { return s.trim(); }).filter(Boolean);
post("/ai/anthropic/admin/" + $("ad-report").value, { starting_at: $("ad-start").value.trim(), group_by: group });
};
$("ad-send").onclick = function () {
var q = json("ad-query"), b = json("ad-body");
if (!q || !b) return;
var ids = $("ad-ids").value.split(",").map(function (s) { return s.trim(); }).filter(Boolean);
post("/ai/anthropic/admin/call", { call: $("ad-call").value, ids: ids, query: q, body: b, confirm: $("ad-confirm").checked });
};
})();