provider: a custom provider can be added with only a Responses URL - the editor's base URL was the OpenAI (chat completions) or the Anthropic one, so a vendor that serves only the Responses API had to be given a chat URL it answers with 404, and Test failed on it; the base URL now takes a third kind, OpenAI Responses, which is saved as the Responses URL alone, tested at /responses only, and served to chat and Anthropic clients through the gateway; switching the kind moves the URL over, and More endpoints lists the other two (#73)

This commit is contained in:
yetone
2026-09-26 00:32:13 +08:00
parent 20fe8b4fac
commit 75217233b8
2 changed files with 41 additions and 13 deletions
+39 -13
View File
@@ -2036,7 +2036,7 @@ function renderEditor(p, presetID) {
// more provider of it, under a name and id of its own
const another = isNew && !!pr?.added;
draft = draft || (p
? { id: p.id, name: p.name, preset: p.preset, chat: p.chat, responses: p.responses, anthropic: p.anthropic, catalog: p.catalog, key: "", api: p.anthropic && !p.chat ? "anthropic" : "openai", chosen: p.models.filter((m) => m.on).map((m) => m.id), extra: [], headers: headerRows(p.headers), icon: p.icon || "", fallback: [...(p.fallback || [])], unlisted: !!p.unlisted, balanceURL: p.balanceURL || "", balancePath: p.balancePath || "", modelsURL: p.modelsURL || "" }
? { id: p.id, name: p.name, preset: p.preset, chat: p.chat, responses: p.responses, anthropic: p.anthropic, catalog: p.catalog, key: "", api: p.chat ? "openai" : p.anthropic ? "anthropic" : p.responses ? "responses" : "openai", chosen: p.models.filter((m) => m.on).map((m) => m.id), extra: [], headers: headerRows(p.headers), icon: p.icon || "", fallback: [...(p.fallback || [])], unlisted: !!p.unlisted, balanceURL: p.balanceURL || "", balancePath: p.balancePath || "", modelsURL: p.modelsURL || "" }
: pr
? { id: pr.id, name: pr.name, preset: pr.id, key: "", chosen: [], extra: [], headers: [] }
: { id: "", name: "", preset: "", chat: "", responses: "", anthropic: "", catalog: "", key: "", api: "openai", chosen: [], extra: [], headers: [], icon: "" });
@@ -2083,21 +2083,34 @@ function renderEditor(p, presetID) {
wrap.append(name, hint);
ed.append(el("label", "", t("Name")), wrap);
}
let fillEndpoints = () => {};
if (custom) {
name = input(draft.name, t("e.g. My Relay"));
name.oninput = () => { draft.name = name.value; if (isNew) draft.id = slug(name.value); };
ed.append(...field(t("Name"), name));
// the base URL is the one the chosen protocol is asked at; a vendor
// that serves only the Responses API is added (and tested) with that
// alone, since /chat/completions would only fail (#73)
const seg = el("div", "segs");
for (const [v, l, hint] of [["openai", "OpenAI compatible", "…/v1 — chat completions, and responses when the vendor has it"], ["anthropic", "Anthropic compatible", "the root URL, what ANTHROPIC_BASE_URL would take"]]) {
for (const [v, l, hint] of [["openai", "OpenAI compatible", "…/v1 — chat completions, and responses when the vendor has it"], ["responses", "OpenAI Responses", "…/v1 — for a vendor that serves only the Responses API, not chat completions"], ["anthropic", "Anthropic compatible", "the root URL, what ANTHROPIC_BASE_URL would take"]]) {
const b = el("button", "opt" + (draft.api === v ? " on" : ""), t(l));
b.title = t(hint);
b.onclick = () => { draft.api = v; const u = url.value; if (v === "anthropic") { draft.anthropic = u; draft.chat = ""; } else { draft.chat = u; draft.anthropic = ""; } for (const x of seg.querySelectorAll(".opt")) x.classList.toggle("on", x === b); slide(seg, "api"); url.placeholder = v === "anthropic" ? "https://…" : "https://…/v1"; };
b.onclick = () => {
if (draft.api === v) return;
draft[apiField[draft.api]] = "";
draft.api = v;
draft[apiField[v]] = url.value;
for (const x of seg.querySelectorAll(".opt")) x.classList.toggle("on", x === b);
slide(seg, "api");
url.placeholder = v === "anthropic" ? "https://…" : "https://…/v1";
fillEndpoints();
};
seg.append(b);
}
queueMicrotask(() => slide(seg, "api"));
url = input(draft.api === "anthropic" ? draft.anthropic : draft.chat, draft.api === "anthropic" ? "https://…" : "https://…/v1", "url");
url.oninput = () => { if (draft.api === "anthropic") draft.anthropic = url.value; else draft.chat = url.value; };
url = input(draft[apiField[draft.api]], draft.api === "anthropic" ? "https://…" : "https://…/v1", "url");
url.oninput = () => { draft[apiField[draft.api]] = url.value; };
const urlWrap = el("div", "stack");
urlWrap.append(seg, url);
ed.append(...field("Base URL", urlWrap));
@@ -2233,14 +2246,23 @@ function renderEditor(p, presetID) {
const more = el("details", "more");
more.append(el("summary", "", t("More endpoints")));
const inner = el("div", "inner");
const add = (label, key, ph, hint) => {
const i = input(draft[key], ph, "url");
i.oninput = () => { draft[key] = i.value; };
inner.append(...field(t(label), i, t(hint)));
// the other protocols' URLs, drawn again when the base URL's changes
const eps = el("div");
eps.style.display = "contents";
fillEndpoints = () => {
eps.replaceChildren();
const add = (label, key, ph, hint) => {
if (apiField[draft.api] === key) return;
const i = input(draft[key], ph, "url");
i.oninput = () => { draft[key] = i.value; };
eps.append(...field(t(label), i, t(hint)));
};
add("OpenAI URL", "chat", "https://…/v1", "if the vendor also serves chat completions");
add("Anthropic URL", "anthropic", "https://…", "if the vendor also serves Anthropic messages");
add("Responses URL", "responses", "https://…/v1", "if the vendor serves the OpenAI Responses API (Codex uses it natively)");
};
if (draft.api === "anthropic") add("OpenAI URL", "chat", "https://…/v1", "if the vendor also serves chat completions");
else add("Anthropic URL", "anthropic", "https://…", "if the vendor also serves Anthropic messages");
add("Responses URL", "responses", "https://…/v1", "if the vendor serves the OpenAI Responses API (Codex uses it natively)");
fillEndpoints();
inner.append(eps);
const mu = input(draft.modelsURL, "https://…/v1/models", "url");
mu.oninput = () => { draft.modelsURL = mu.value; };
inner.append(...field(t("Models URL"), mu, t("Where the vendor lists its models, when that isn't under the base URL; asked with the key")));
@@ -2282,7 +2304,7 @@ function renderEditor(p, presetID) {
if (draft.balanceToken) body.balanceToken = draft.balanceToken;
else if (draft.clearBalanceToken) body.clearBalanceToken = true;
if (isNew && custom && !body.name) { name.focus(); return editorError(t("Give it a name"), "warn"); }
if (isNew && custom && !body.chat && !body.anthropic) { url.focus(); return editorError(t("A base URL is needed"), "warn"); }
if (isNew && custom && !body.chat && !body.anthropic && !body.responses) { url.focus(); return editorError(t("A base URL is needed"), "warn"); }
editorError("");
saveBtn.classList.add("busy");
providerAction("save", body, t(isNew ? "{name} added" : "{name} saved", { name: draft.name || draft.id }));
@@ -3252,6 +3274,10 @@ async function keyFingerprint(key) {
} catch { return ""; }
}
// apiField is the draft's URL a custom provider's base URL fills, by the
// protocol chosen for it.
const apiField = { openai: "chat", responses: "responses", anthropic: "anthropic" };
async function providerAction(action, body, okMsg, base = "provider/") {
try {
providers = await api(base + action, body);
+2
View File
@@ -156,6 +156,8 @@ const I18N = {
"Name": "名称",
"OpenAI compatible": "OpenAI 兼容",
"…/v1 — chat completions, and responses when the vendor has it": "…/v1 — chat completions,供应商支持时也含 responses",
"OpenAI Responses": "OpenAI Responses",
"…/v1 — for a vendor that serves only the Responses API, not chat completions": "…/v1 — 供应商只提供 Responses API、不提供 chat completions 时选这个",
"Anthropic compatible": "Anthropic 兼容",
"the root URL, what ANTHROPIC_BASE_URL would take": "根地址,即 ANTHROPIC_BASE_URL 的值",
"Account": "账号",