providers, gui: a custom provider saved as OpenAI Responses opens as OpenAI Responses, not OpenAI compatible (01huadalang on Discord: 我选 response 保存了然后再打开一会就变成 openai 兼容了)
The editor never saved which API the Base URL was picked as; reopening showed the first API with a URL, chat first. A provider added as OpenAI compatible keeps its chat URL when Responses is picked (#105), so after Responses was picked, its URL typed and saved, it opened as OpenAI compatible again. Picked with no URL of its own, the Save sent nothing for it and the pick was gone without a word. Now the pick is saved with the provider (baseAPI), sent back to the editor and shown while it has a URL; a save that doesn't say keeps it, and one whose URL is cleared elsewhere drops it. A Save with the picked API's URL empty while another has one says so in the form. Requests are unchanged: they go by which URLs are set. Verified: reproduced on origin/main in a sandbox HOME with the built binary (magpie web, real GUI via Playwright, fake Responses-only upstream): a provider added as OpenAI compatible, then saved as Responses with and without its URL typed, reopened as OpenAI compatible. With the change it reopens as OpenAI Responses after a reload, a 65s wait and an app restart, and the empty Save shows the message. A provider added as Responses from the start was already kept and still is. TestProviderBaseAPIKept fails without the change ("added as OpenAI compatible, shown as \"\""); provider-base-api.test.cjs fails on the old app.js (actual 'OpenAI compatible', expected 'OpenAI Responses') and passes in Chromium and WebKit, en and zh. gui-ja, gui-de, i18n-keys and the provider*/system-one/azure/add-sheet/menu-scroll GUI tests pass in both engines. go vet, GOOS=linux/windows builds, go test -tags nogui ./... pass under a temp HOME.
This commit is contained in:
@@ -17,7 +17,7 @@ keys and accounts per request is in [Gateway routing and fallback](gateway-routi
|
||||
|
||||
| Part | Responsibility | Source |
|
||||
| --- | --- | --- |
|
||||
| Provider | `Provider` holds the endpoint bases for each `Protocol` (Chat, Responses, Anthropic, Gemini), the keys, `Fallback`, `Routing`, `Sink`, `Affinity`, concurrency and queue limits, `Headers`, `Proxy`, models, and balance settings. `Account` is set only for a subscription and is never saved (`json:"-"`). | [`provider.go`](../../internal/provider/provider.go) |
|
||||
| Provider | `Provider` holds the endpoint bases for each `Protocol` (Chat, Responses, Anthropic, Gemini), the keys, `Fallback`, `Routing`, `Sink`, `Affinity`, concurrency and queue limits, `Headers`, `Proxy`, models, and balance settings. `BaseAPI` is the API a custom provider's editor shows its Base URL as: the one the user picked and saved, while it has a URL, so a provider with a chat URL beside its Responses one isn't shown as OpenAI compatible after Responses was picked. Requests go by which URLs are set. `Account` is set only for a subscription and is never saved (`json:"-"`). | [`provider.go`](../../internal/provider/provider.go) |
|
||||
| providers.json | `Path` is `providers.json` in magpie's config folder. A read that fails returns `ErrUnreadable` and is never treated as empty. `store` writes atomically through a rename and drops the cached catalog (`catalog.Touched`). | [`provider.go`](../../internal/provider/provider.go) |
|
||||
| The list | `All` merges stored providers with `Accounts()`. An entry with no URL stores the user's picks for an account. The order is `file.Order`. Reads within one request share one build (`Hold`, #746). | [`provider.go`](../../internal/provider/provider.go) |
|
||||
| Keys | Several keys per provider. Requests go to the first key that is on; the gateway moves on when it is out or rate limited. `Key` stays the first, so other code reads it as before. A key can be made for one protocol (`KeyProtocol`). | [`keys.go`](../../internal/provider/keys.go) |
|
||||
|
||||
@@ -7405,9 +7405,20 @@ function pickedOf(p) {
|
||||
return on.filter((m) => picks.has(m.id)).map((m) => m.id);
|
||||
}
|
||||
|
||||
// baseAPIOf is the API a saved provider's Base URL is shown as: the one the
|
||||
// user picked and saved (baseAPI), while it has a URL, else the first that
|
||||
// has one. Without the pick, a provider with a chat URL beside its Responses
|
||||
// one came back as OpenAI compatible after Responses was picked and saved
|
||||
// (01huadalang).
|
||||
function baseAPIOf(p) {
|
||||
const picked = p.baseAPI === "chat" ? "openai" : p.baseAPI;
|
||||
if (picked && p[apiField[picked]]) return picked;
|
||||
return p.chat ? "openai" : p.anthropic ? "anthropic" : p.responses ? "responses" : p.decide ? "decide" : "openai";
|
||||
}
|
||||
|
||||
// draftOf is a saved provider as its editor's form holds it.
|
||||
function draftOf(p) {
|
||||
return { id: p.id, name: p.name, preset: p.preset, chat: p.chat, responses: p.responses, anthropic: p.anthropic, catalog: p.catalog, decide: p.decide || "", key: "", api: p.chat ? "openai" : p.anthropic ? "anthropic" : p.responses ? "responses" : p.decide ? "decide" : "openai", chosen: pickedOf(p), extra: [], headers: headerRows(p.headers), icon: p.icon || "", fallback: [...(p.fallback || [])], unlisted: !!p.unlisted, searches: !!p.searches, unredacted: !!p.unredacted, pinUpstream: !!p.pinUpstream, balanceURL: p.balanceURL || "", balancePath: p.balancePath || "", modelsURL: p.modelsURL || "", contexts: contextsText(p.contexts), outputs: contextsText(p.outputs), compacts: contextsText(p.compacts), keysUrl: p.keysUrl || "", ...proxyDraft(p), ...concurrencyDraft(p) };
|
||||
return { id: p.id, name: p.name, preset: p.preset, chat: p.chat, responses: p.responses, anthropic: p.anthropic, catalog: p.catalog, decide: p.decide || "", key: "", api: baseAPIOf(p), chosen: pickedOf(p), extra: [], headers: headerRows(p.headers), icon: p.icon || "", fallback: [...(p.fallback || [])], unlisted: !!p.unlisted, searches: !!p.searches, unredacted: !!p.unredacted, pinUpstream: !!p.pinUpstream, balanceURL: p.balanceURL || "", balancePath: p.balancePath || "", modelsURL: p.modelsURL || "", contexts: contextsText(p.contexts), outputs: contextsText(p.outputs), compacts: contextsText(p.compacts), keysUrl: p.keysUrl || "", ...proxyDraft(p), ...concurrencyDraft(p) };
|
||||
}
|
||||
|
||||
// duplicateProvider opens the Add form on a copy of p (#268): its URLs,
|
||||
@@ -7561,8 +7572,8 @@ function drawEditor(p, presetID) {
|
||||
// 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"], ["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"], ["decide", "System One", "a decision API's root, POST …/systemone under it: its models are a routing group's classifier, never an agent's"]]) {
|
||||
const b = el("button", "opt" + (draft.api === v ? " on" : ""), t(l));
|
||||
for (const [v, hint] of [["openai", "…/v1 — chat completions, and responses when the vendor has it"], ["responses", "…/v1 — for a vendor that serves only the Responses API, not chat completions"], ["anthropic", "the root URL, what ANTHROPIC_BASE_URL would take"], ["decide", "a decision API's root, POST …/systemone under it: its models are a routing group's classifier, never an agent's"]]) {
|
||||
const b = el("button", "opt" + (draft.api === v ? " on" : ""), t(API_NAMES[v]));
|
||||
b.title = t(hint);
|
||||
b.onclick = () => {
|
||||
if (draft.api === v) return;
|
||||
@@ -7594,6 +7605,7 @@ function drawEditor(p, presetID) {
|
||||
};
|
||||
queueMicrotask(() => slide(seg, "api"));
|
||||
url = input(draft[apiField[draft.api]], draft.api === "anthropic" ? "https://…" : "https://…/v1", "url");
|
||||
url.classList.add("base-url");
|
||||
url.oninput = () => { draft[apiField[draft.api]] = url.value; showSearch(); showLocal(); };
|
||||
const urlWrap = el("div", "stack");
|
||||
urlWrap.append(seg, url);
|
||||
@@ -8043,6 +8055,15 @@ function drawEditor(p, presetID) {
|
||||
if (isNew && draft.copyOf) body.copyOf = draft.copyOf;
|
||||
if (decides || custom) body.decide = (custom && draft.api !== "decide" && !p?.decide ? "" : draft.decide || "").trim();
|
||||
if ((body.decide || "").includes(WORKSPACE)) { ed.querySelector(".workspace-id")?.focus({ preventScroll: true }); return editorError(t("Give the workspace ID your API key belongs to, or pick the Token Plan"), "warn"); }
|
||||
if (custom) {
|
||||
// the API picked for the Base URL is saved with it, and one left with
|
||||
// no URL is said rather than lost: the editor would open on another
|
||||
if (!(draft[apiField[draft.api]] || "").trim() && ["chat", "responses", "anthropic", "decide"].some((k) => (draft[k] || "").trim())) {
|
||||
ed.querySelector(".base-url")?.focus({ preventScroll: true });
|
||||
return editorError(t("Base URL: type the {api} URL, or pick the API the URL you have is for", { api: t(API_NAMES[draft.api]) }), "warn");
|
||||
}
|
||||
body.baseAPI = draft.api === "openai" ? "chat" : draft.api;
|
||||
}
|
||||
if (custom) { body.icon = draft.icon || "generic"; body.balanceURL = (draft.balanceURL || "").trim(); body.balancePath = (draft.balancePath || "").trim(); body.modelsURL = (draft.modelsURL || "").trim(); }
|
||||
if (p) { body.fallback = draft.fallback; body.unlisted = draft.unlisted; body.modelPrefs = modelPrefsOfDraft(); Object.assign(body, routingOfDraft(p)); }
|
||||
body.searches = !!draft.searches && searchable();
|
||||
@@ -11963,6 +11984,8 @@ async function keyFingerprint(key) {
|
||||
// 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", decide: "decide" };
|
||||
// the Base URL's APIs as the custom provider's editor names them
|
||||
const API_NAMES = { openai: "OpenAI compatible", responses: "OpenAI Responses", anthropic: "Anthropic compatible", decide: "System One" };
|
||||
|
||||
// respellURL turns a base URL into the one protocol api is asked at: the
|
||||
// root for Anthropic, which adds /v1 itself, …/v1 for OpenAI's two.
|
||||
|
||||
@@ -883,6 +883,7 @@ const I18N = {
|
||||
"e.g. My Relay": "例如 My Relay",
|
||||
"Name": "名称",
|
||||
"OpenAI compatible": "OpenAI 兼容",
|
||||
"Base URL: type the {api} URL, or pick the API the URL you have is for": "Base URL:请填写 {api} 的地址,或改选你已有地址所属的协议",
|
||||
"…/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 的供应商",
|
||||
@@ -4444,6 +4445,7 @@ const I18N = {
|
||||
"e.g. My Relay": "例:My Relay",
|
||||
"Name": "名前",
|
||||
"OpenAI compatible": "OpenAI 互換",
|
||||
"Base URL: type the {api} URL, or pick the API the URL you have is for": "Base URL:{api} の URL を入力するか、お持ちの URL が対応する API を選んでください",
|
||||
"…/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 — chat completions ではなく Responses API のみを提供するベンダー向け",
|
||||
@@ -8015,6 +8017,7 @@ const I18N = {
|
||||
"e.g. My Relay": "z. B. Mein Relay",
|
||||
"Name": "Name",
|
||||
"OpenAI compatible": "OpenAI-kompatibel",
|
||||
"Base URL: type the {api} URL, or pick the API the URL you have is for": "Base URL: Gib die {api}-URL ein, oder wähle die API, für die deine URL ist",
|
||||
"…/v1 — chat completions, and responses when the vendor has it": "…/v1 — Chat Completions und, falls der Anbieter sie hat, Responses",
|
||||
"OpenAI Responses": "OpenAI Responses",
|
||||
"…/v1 — for a vendor that serves only the Responses API, not chat completions": "…/v1 — für Anbieter, die nur die Responses API bereitstellen, keine Chat Completions",
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
// The API a custom provider's Base URL was given as in its editor is kept
|
||||
// (01huadalang on Discord: 我选 response 保存了然后再打开一会就变成 openai
|
||||
// 兼容了). A provider saved as OpenAI compatible, then given its URL as
|
||||
// OpenAI Responses, has both URLs: the editor showed the first, chat, and
|
||||
// so OpenAI compatible. The pick is saved, sent back to the editor, kept by
|
||||
// a save that doesn't say, and dropped once its URL is gone.
|
||||
func TestProviderBaseAPIKept(t *testing.T) {
|
||||
t.Setenv("HOME", t.TempDir())
|
||||
t.Setenv("USERPROFILE", os.Getenv("HOME"))
|
||||
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
||||
t.Setenv("XDG_CACHE_HOME", t.TempDir())
|
||||
mux := http.NewServeMux()
|
||||
providerRoutes(mux, nil)
|
||||
post := func(action, body string) {
|
||||
t.Helper()
|
||||
w := httptest.NewRecorder()
|
||||
mux.ServeHTTP(w, httptest.NewRequest("POST", "/api/provider/"+action, strings.NewReader(body)))
|
||||
if w.Code != 200 {
|
||||
t.Fatalf("%s: %d %s", action, w.Code, w.Body)
|
||||
}
|
||||
}
|
||||
shown := func() string {
|
||||
t.Helper()
|
||||
w := httptest.NewRecorder()
|
||||
mux.ServeHTTP(w, httptest.NewRequest("GET", "/api/providers", nil))
|
||||
var got struct{ Providers []map[string]any }
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &got); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, p := range got.Providers {
|
||||
if p["id"] == "relay" {
|
||||
s, _ := p["baseAPI"].(string)
|
||||
return s
|
||||
}
|
||||
}
|
||||
t.Fatalf("relay not listed: %s", w.Body)
|
||||
return ""
|
||||
}
|
||||
const u = "http://127.0.0.1:1/v1"
|
||||
// added as OpenAI compatible, as the editor sends it
|
||||
post("save", `{"id":"relay","name":"Relay","key":"sk-a","chat":"`+u+`","icon":"generic","baseAPI":"chat","new":true}`)
|
||||
if got := shown(); got != "chat" {
|
||||
t.Fatalf("added as OpenAI compatible, shown as %q", got)
|
||||
}
|
||||
// reopened, OpenAI Responses picked and its URL typed: chat's stays (#105)
|
||||
post("save", `{"id":"relay","from":"relay","name":"Relay","chat":"`+u+`","responses":"`+u+`","icon":"generic","baseAPI":"responses"}`)
|
||||
if got := shown(); got != "responses" {
|
||||
t.Fatalf("saved as OpenAI Responses, shown as %q", got)
|
||||
}
|
||||
p, err := provider.Find("relay")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if p.Chat != u || p.Responses != u {
|
||||
t.Fatalf("stored %+v", p)
|
||||
}
|
||||
// a save that doesn't say which (an older window, another page) keeps it
|
||||
post("save", `{"id":"relay","from":"relay","name":"Relay","chat":"`+u+`","responses":"`+u+`","icon":"generic"}`)
|
||||
if got := shown(); got != "responses" {
|
||||
t.Fatalf("a save without the pick lost it: %q", got)
|
||||
}
|
||||
// the Responses URL cleared elsewhere (the CLI): no pick is left to show
|
||||
p, _ = provider.Find("relay")
|
||||
p.Responses = ""
|
||||
if err := provider.Save(*p); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := shown(); got != "" {
|
||||
t.Fatalf("a pick with no URL kept: %q", got)
|
||||
}
|
||||
}
|
||||
@@ -67,6 +67,8 @@ type providerJSON struct {
|
||||
Website string `json:"website"`
|
||||
KeysURL string `json:"keysUrl"`
|
||||
Headers map[string]string `json:"headers,omitempty"`
|
||||
// the API the user gave a custom provider's Base URL as (BaseAPI)
|
||||
BaseAPI string `json:"baseAPI,omitempty"`
|
||||
// the vendor searches the web by itself (provider.Searches)
|
||||
Searches bool `json:"searches"`
|
||||
// on the Cline API: its DeepSeek models are served by DeepSeek's own
|
||||
@@ -403,7 +405,7 @@ func agentUses(agents []*agent.Agent, findGroup func(string) (provider.Group, []
|
||||
func providerInfo(p provider.Provider, agents []agentUse) providerJSON {
|
||||
out := providerJSON{
|
||||
ID: p.ID, Name: p.Name, Icon: p.Icon, Preset: p.Preset, Host: p.Host(),
|
||||
Chat: p.Chat, Responses: p.Responses, Anthropic: p.Anthropic, Decide: p.Decide, ModelTest: p.ModelTest(), DecideTest: p.AsksDecideModels(),
|
||||
Chat: p.Chat, Responses: p.Responses, Anthropic: p.Anthropic, Decide: p.Decide, BaseAPI: p.BaseAPI, ModelTest: p.ModelTest(), DecideTest: p.AsksDecideModels(),
|
||||
Catalog: p.Catalog, Website: p.Website, KeysURL: p.KeysURL,
|
||||
Proxy: p.Proxy, AccountProxies: p.AccountProxies, AccountModels: p.AccountModels, AccountCaps: p.AccountCaps, Headers: p.Headers, Searches: p.Searches, Cline: p.ClinePinnable(), PinUpstream: p.PinUpstream, Unredacted: p.Unredacted, BalanceURL: p.BalanceURL, BalancePath: p.BalancePath, ModelsURL: p.ModelsURL,
|
||||
Ready: p.Ready(), Chosen: p.Models, Models: []modelJSON{}, Agents: []providerAgent{},
|
||||
@@ -1120,6 +1122,11 @@ func providerRoutes(mux *http.ServeMux, w Windows) {
|
||||
in.KeyName, in.KeyProtocol, in.KeyWeight = old.KeyName, old.KeyProtocol, old.KeyWeight
|
||||
}
|
||||
}
|
||||
// the Base URL's API, as picked in the editor; a save that
|
||||
// doesn't say keeps it
|
||||
if in.BaseAPI == "" && old != nil {
|
||||
in.BaseAPI = old.BaseAPI
|
||||
}
|
||||
if in.Icon == "" && old != nil && in.Preset == "" {
|
||||
in.Icon = old.Icon
|
||||
}
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// A custom provider's Base URL opens on the API it was saved as
|
||||
// (01huadalang on Discord: 我选 response 保存了然后再打开一会就变成 openai
|
||||
// 兼容了). A provider with a chat URL beside its Responses one, saved as
|
||||
// OpenAI Responses, opens on OpenAI Responses, its chat URL under More
|
||||
// endpoints; one saved before the pick was kept opens on the first API with
|
||||
// a URL, as it did. OpenAI Responses picked and saved with no URL of its
|
||||
// own is said in the form, never dropped; with its URL typed, the Save says
|
||||
// which API the Base URL is. In English and Chinese, Chromium and WebKit.
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
const path = require("node:path");
|
||||
const { test } = require("node:test");
|
||||
const { chromium, webkit } = require("playwright");
|
||||
|
||||
const assets = path.resolve(__dirname, "../assets");
|
||||
const U = "https://relay.example.com/v1";
|
||||
|
||||
function serve(lang, posts) {
|
||||
const state = { agents: [], profiles: [], settings: { lang, theme: "light" } };
|
||||
const models = [{ id: "m", name: "m", on: true }];
|
||||
const base = { icon: "generic", anthropic: "", models, agents: [], fallback: [], headers: {}, key: { set: true, masked: "sk-…1234" }, keyList: [], ready: true };
|
||||
const providers = { providers: [
|
||||
{ ...base, id: "picked", name: "Picked", chat: U, responses: U, baseAPI: "responses" },
|
||||
{ ...base, id: "older", name: "Older", chat: U, responses: U },
|
||||
{ ...base, id: "plain", name: "Plain", chat: U, responses: "" },
|
||||
], presets: [], excluded: [], gateway: { running: true, window: true } };
|
||||
return async (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
const json = (data) => route.fulfill({ json: data });
|
||||
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:${JSON.stringify(lang)},theme:"light",web:true};` });
|
||||
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/state") return json(state);
|
||||
if (url.pathname === "/api/providers") return json(providers);
|
||||
if (url.pathname === "/api/groups") return json({ groups: [] });
|
||||
if (url.pathname.startsWith("/api/provider/")) {
|
||||
posts.push({ path: url.pathname, body: route.request().postDataJSON() });
|
||||
return json(providers);
|
||||
}
|
||||
if (url.pathname.startsWith("/api/")) return json({});
|
||||
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
||||
await route.fulfill({ body: await fs.readFile(file), contentType: { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)] });
|
||||
};
|
||||
}
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const lang of ["en", "zh"]) {
|
||||
test(`${engine} ${lang}: the Base URL opens on the API it was saved as`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: process.env.PLAYWRIGHT_CHANNEL || "chromium" }));
|
||||
const page = await (await browser.newContext({ viewport: { width: 900, height: 760 }, reducedMotion: "reduce" })).newPage();
|
||||
t.after(() => browser.close());
|
||||
page.setDefaultTimeout(5000);
|
||||
const errors = [], posts = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", serve(lang, posts));
|
||||
await page.goto("http://magpie.test/?view=providers");
|
||||
const zh = lang === "zh";
|
||||
const L = {
|
||||
openai: zh ? "OpenAI 兼容" : "OpenAI compatible", responses: zh ? "OpenAI Responses" : "OpenAI Responses",
|
||||
more: zh ? "更多端点" : "More endpoints", save: zh ? "保存" : "Save",
|
||||
empty: zh ? "Base URL:请填写 OpenAI Responses 的地址,或改选你已有地址所属的协议" : "Base URL: type the OpenAI Responses URL, or pick the API the URL you have is for",
|
||||
};
|
||||
const ed = page.locator(".editor");
|
||||
const open = async (id) => {
|
||||
if (await ed.count()) { await page.keyboard.press("Escape"); await ed.waitFor({ state: "detached" }); }
|
||||
await page.locator(`#providers .row[data-id="${id}"]`).click();
|
||||
await ed.locator(".base-url").waitFor();
|
||||
};
|
||||
const on = () => ed.locator(".segs:has(.opt[data-api]) .opt.on").textContent();
|
||||
|
||||
// saved as OpenAI Responses: opens there, chat's URL under More endpoints
|
||||
await open("picked");
|
||||
assert.equal(await on(), L.responses);
|
||||
assert.equal(await ed.locator(".base-url").inputValue(), U);
|
||||
const more = await ed.locator("details.more input[type=url]").evaluateAll((is) => is.map((i) => i.value));
|
||||
assert(more.includes(U), "the chat URL is under More endpoints: " + more);
|
||||
|
||||
// saved before the pick was kept: the first API with a URL, as before
|
||||
await open("older");
|
||||
assert.equal(await on(), L.openai);
|
||||
|
||||
// OpenAI Responses picked with no URL of its own: said, nothing sent
|
||||
await open("plain");
|
||||
assert.equal(await on(), L.openai);
|
||||
await ed.locator('.segs .opt[data-api="responses"]').click();
|
||||
assert.equal(await ed.locator(".base-url").inputValue(), "", "a saved chat URL stays chat's (#105)");
|
||||
await ed.locator(":scope > .bar").getByRole("button", { name: L.save, exact: true }).click();
|
||||
assert.equal(await ed.locator(".editor-error").textContent(), L.empty);
|
||||
assert.equal(posts.filter((p) => p.path === "/api/provider/save").length, 0, "nothing saved");
|
||||
|
||||
// its URL typed: the Save says the Base URL is the Responses one
|
||||
await ed.locator(".base-url").fill(U);
|
||||
await ed.locator(":scope > .bar").getByRole("button", { name: L.save, exact: true }).click();
|
||||
for (let i = 0; i < 60 && !posts.some((p) => p.path === "/api/provider/save"); i++) await page.waitForTimeout(50);
|
||||
const save = posts.find((p) => p.path === "/api/provider/save");
|
||||
assert(save, "saved");
|
||||
assert.equal(save.body.baseAPI, "responses");
|
||||
assert.equal(save.body.responses, U);
|
||||
assert.equal(save.body.chat, U, "chat's URL kept (#105)");
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -72,6 +72,12 @@ type Provider struct {
|
||||
// Jev answers), for routing groups' choices of model and effort. The
|
||||
// provider may also serve conversations on the other endpoints.
|
||||
Decide string `json:"decide,omitempty"`
|
||||
// BaseAPI is the API the user gave a custom provider's Base URL as,
|
||||
// in its editor: "chat", "responses", "anthropic" or "decide". The
|
||||
// editor shows that pick again, where it would otherwise show the
|
||||
// first API with a URL (01huadalang: Responses picked and saved came
|
||||
// back as OpenAI compatible). Requests go by which URLs are set.
|
||||
BaseAPI string `json:"baseAPI,omitempty"`
|
||||
|
||||
// Fallback is where a request goes when this provider can't take it —
|
||||
// out of quota, rate limited, overloaded or down — before any of the
|
||||
@@ -856,6 +862,10 @@ func normalize(p Provider) Provider {
|
||||
break
|
||||
}
|
||||
}
|
||||
// a pick whose URL is gone (cleared from the CLI) is no pick
|
||||
if p.BaseAPI != "" && p.baseOf(p.BaseAPI) == "" {
|
||||
p.BaseAPI = ""
|
||||
}
|
||||
p.Models = cleanList(p.Models)
|
||||
p.Fallback = cleanList(p.Fallback)
|
||||
// a provider saved under an id a preset carried before (presetAliases:
|
||||
@@ -976,6 +986,22 @@ func contains(xs []string, x string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// baseOf is the URL saved for one of the editor's Base URL APIs (BaseAPI),
|
||||
// "" for an API it doesn't know.
|
||||
func (p Provider) baseOf(api string) string {
|
||||
switch api {
|
||||
case "chat":
|
||||
return p.Chat
|
||||
case "responses":
|
||||
return p.Responses
|
||||
case "anthropic":
|
||||
return p.Anthropic
|
||||
case "decide":
|
||||
return p.Decide
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// Base returns the base URL for a protocol, or "" when the vendor lacks it.
|
||||
func (p Provider) Base(proto Protocol) string {
|
||||
switch proto {
|
||||
|
||||
Reference in New Issue
Block a user