Merge branch 'worktree-agent-a89776b81b60a5fca'

This commit is contained in:
2026-10-25 15:24:27 +01:00
23 changed files with 3348 additions and 3 deletions
+72
View File
@@ -0,0 +1,72 @@
// Compat page: thin client over /ai/compat/* (all limits server side). The
// provider list comes from the registry table through /ai/compat/providers.
(function () {
"use strict";
var $ = function (id) { return document.getElementById(id); };
var out = $("cp-out"), err = $("cp-error");
var templates = {
"chat": { prompt: "Reply with the single word: ok", max_tokens: 8 },
"models": {},
"embeddings": { input: ["The food was delicious"] },
"images": { prompt: "a small red cube on white", size: "512x512" },
"transcribe": { filename: "clip.wav", data_base64: "" },
"speech": { input: "Hello", voice: "alloy", format: "mp3" }
};
var providers = [];
var rsel = $("cp-route"), psel = $("cp-provider");
Object.keys(templates).forEach(function (k) {
var o = document.createElement("option");
o.value = k; o.textContent = k;
rsel.appendChild(o);
});
function fill() {
var t = JSON.parse(JSON.stringify(templates[rsel.value]));
t.provider = psel.value;
$("cp-body").value = JSON.stringify(t, null, 1);
}
function info() {
var p = providers.filter(function (x) { return x.id === psel.value; })[0];
if (!p) { $("cp-info").textContent = ""; return; }
$("cp-info").textContent = p.name + " | " + p.base_url + " | " + p.features.join(", ") +
" | " + p.evidence + " | " + (p.configured ? "configured" : "needs " + p.missing_env);
}
rsel.onchange = fill;
psel.onchange = function () { info(); fill(); };
function send(confirm) {
var body;
try { body = JSON.parse($("cp-body").value || "{}"); }
catch (e) { err.textContent = "Body is not valid JSON"; return; }
if (confirm) body.confirm = true;
err.textContent = "";
out.textContent = "...";
fetch("/ai/compat/" + rsel.value, {
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 = ""; });
}
$("cp-send").onclick = function () { send(false); };
$("cp-confirm").onclick = function () { send(true); };
fetch("/ai/compat/providers").then(function (r) { return r.json(); }).then(function (s) {
providers = s.providers;
providers.forEach(function (p) {
var o = document.createElement("option");
o.value = p.id;
o.textContent = p.name + (p.configured ? " (key set)" : "");
psel.appendChild(o);
});
$("cp-config").textContent = providers.filter(function (p) { return p.configured; }).length +
" of " + providers.length + " providers have a credential. Others answer 503 until one is configured; dry runs still work.";
info();
fill();
});
})();