providers: 鱼鱼连线 with a region switch, and a ui polish pass

A relay with several endpoints is one preset now: a Region selector
(Auto / Global / China Mainland) swaps the provider's base URLs, and the
endpoints list follows the choice. AiHubMix's key page moves to
console.aihubmix.com/token.

The rest is a pass over the gateway, usage and provider views: a copy
button that answers on itself, a cache hit rate in the usage tiles, the
chart's peak and last date no longer overlap, the tabs sit level with
the logo, the provider key column holds a line, pickers opened from the
editor show above its modal, and buttons drop the native webkit look so
their labels centre.
This commit is contained in:
yetone
2026-09-24 02:27:11 +08:00
parent 9f678458b9
commit 0ecc7b6218
5 changed files with 120 additions and 26 deletions
+10 -5
View File
@@ -93,7 +93,7 @@ body.panel { background: color-mix(in srgb, var(--bg) 93%, transparent); border-
:root:not([data-theme="dark"]) body.panel { --bg: #f2f2f5; --card: #ffffff; --card-2: #f8f8fa; --line: rgba(0, 0, 0, .07); --line-2: rgba(0, 0, 0, .06); --pill: #ffffff; --pill-hover: #f4f4f7; --pill-line: rgba(0, 0, 0, .12); --pill-shadow: 0 1px 1px rgba(0, 0, 0, .06); --faint: #9a9aa3; --card-edge: 0 0 0 1px rgba(0, 0, 0, .05), 0 1px 2px rgba(0, 0, 0, .04); }
}
:root[data-theme="light"] body.panel { --bg: #f2f2f5; --card: #ffffff; --card-2: #f8f8fa; --line: rgba(0, 0, 0, .07); --line-2: rgba(0, 0, 0, .06); --pill: #ffffff; --pill-hover: #f4f4f7; --pill-line: rgba(0, 0, 0, .12); --pill-shadow: 0 1px 1px rgba(0, 0, 0, .06); --faint: #9a9aa3; --card-edge: 0 0 0 1px rgba(0, 0, 0, .05), 0 1px 2px rgba(0, 0, 0, .04); }
button { font: inherit; color: inherit; background: none; border: 0; cursor: default; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: default; appearance: none; -webkit-appearance: none; text-align: center; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input { font: inherit; color: var(--fg); }
.grow { flex: 1; }
@@ -110,6 +110,7 @@ code { font: 11.5px var(--code); }
/* ---- header --------------------------------------------------------------- */
.top { display: flex; align-items: center; gap: 8px; padding: 0 10px 0 14px; height: 46px; flex: none; position: relative; }
body.window .top { padding-left: 88px; height: 50px; padding-top: 2px; } /* the traffic lights centre 25.75pt from the top, not 25 */
body.window .seg { top: calc(50% + 1px); } /* 50% centres in the padding box; the 2px top padding puts the flex row a pixel lower */
.brand { display: flex; align-items: center; gap: 6px; font-weight: 600; letter-spacing: .01em; }
.logo { color: var(--fg); display: inline-flex; } /* ink, like the wordmark; the accent blue fought the text in light mode */
.seg {
@@ -217,7 +218,7 @@ body.panel .field.open { box-shadow: inset 0 0 0 1px var(--accent), var(--pill-s
.kpi span { font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); margin-top: 3px; }
.kpi small { font-size: 11px; color: var(--muted); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chart { position: relative; margin-top: 8px; padding: 12px 14px 8px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; flex: none; }
.chart .peak { position: absolute; top: 8px; right: 12px; font-size: 10.5px; color: var(--faint); font-variant-numeric: tabular-nums; }
.chart .peak { font-size: 10.5px; color: var(--faint); font-variant-numeric: tabular-nums; text-align: right; margin: 0 0 5px; }
.chart .bars { display: flex; align-items: flex-end; gap: 3px; height: 72px; border-bottom: 1px solid var(--line-2); }
.chart .bar { flex: 1 1 0; min-width: 2px; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; border-radius: 3px 3px 0 0; overflow: hidden; }
.chart .bar:hover { background: var(--pill); }
@@ -225,6 +226,7 @@ body.panel .field.open { box-shadow: inset 0 0 0 1px var(--accent), var(--pill-s
.chart .bar i.in { opacity: .38; }
.chart .labels { display: flex; gap: 3px; margin-top: 5px; font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.chart .labels span { flex: 1 1 0; min-width: 0; white-space: nowrap; overflow: visible; }
.chart .labels span:last-child { text-align: right; }
.row.stat .who { flex: 0 0 180px; }
.row.stat .share { flex: 1 1 auto; height: 4px; border-radius: 2px; background: var(--pill); overflow: hidden; margin: 0 6px; }
.row.stat .share i { display: block; height: 100%; border-radius: 2px; background: var(--accent); opacity: .7; }
@@ -243,7 +245,7 @@ body.panel .field.open { box-shadow: inset 0 0 0 1px var(--accent), var(--pill-s
.label { font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.text { font-size: 12px; color: var(--muted); padding: 3px 7px; border-radius: 6px; transition: background .12s, color .12s; white-space: nowrap; }
.text:hover { color: var(--fg); background: var(--pill); }
.text.action { height: 27px; padding: 0 10px; border: 1px solid var(--line); background: var(--card); color: var(--fg-2); box-shadow: 0 1px 1px rgba(0, 0, 0, .04); }
.text.action { height: 27px; padding: 0 10px; border: 1px solid var(--line); background: var(--card); color: var(--fg-2); box-shadow: 0 1px 1px rgba(0, 0, 0, .04); display: inline-flex; align-items: center; justify-content: center; }
.text.action:hover { border-color: var(--muted); background: var(--card-2); color: var(--fg); }
.text.primary { color: var(--accent-fg); background: var(--accent); font-weight: 500; }
.text.primary:hover { filter: brightness(1.08); }
@@ -278,7 +280,7 @@ body.window .foot { padding-left: 18px; }
/* ---- picker popover ------------------------------------------------------- */
.pop {
position: fixed; z-index: 10;
position: fixed; z-index: 30; /* above the modal (20): a picker opened from the provider editor must show over it */
width: 320px; max-height: 340px;
display: flex; flex-direction: column;
background: var(--pop-bg);
@@ -420,6 +422,8 @@ body.window .foot { padding-left: 18px; }
.connect .stack { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.copy { width: 22px; height: 22px; border-radius: 5px; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); flex: none; transition: background .12s, color .12s; }
.copy:hover { background: var(--pill-hover); color: var(--fg); }
.copy.done { color: var(--green); background: var(--green-soft); animation: copy-pop .36s var(--ease); }
@keyframes copy-pop { 0% { transform: scale(.55); } 55% { transform: scale(1.16); } 100% { transform: scale(1); } }
.snip { position: relative; margin: 0; padding: 10px 40px 10px 12px; border-radius: 9px; background: var(--card); border: 1px solid var(--line); overflow-x: auto; line-height: 1.55; }
.snip code { font-size: 11.5px; color: var(--fg); white-space: pre; user-select: text; -webkit-user-select: text; }
.snip .copy { position: absolute; top: 6px; right: 6px; }
@@ -434,6 +438,7 @@ body.window .foot { padding-left: 18px; }
.row.model .name { font: 12px var(--code); }
.row.model .copy { opacity: 0; }
.row.model:hover .copy, .row.model.selected .copy { opacity: 1; }
.row.model .copy.done { opacity: 1; }
/* recent calls */
.activity { padding: 5px 8px 6px; font-size: 11.5px; }
@@ -483,7 +488,7 @@ body.window .foot { padding-left: 18px; }
.use.open { box-shadow: inset 0 0 0 1px var(--accent); }
.use.add { background: none; box-shadow: none; border: 1px dashed var(--line); color: var(--faint); }
.use.add:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.key { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border-radius: 6px; font: 11px var(--code); color: var(--muted); white-space: nowrap; flex: none; margin-left: 4px; font-variant-numeric: tabular-nums; }
.key { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border-radius: 6px; font: 11px var(--code); color: var(--muted); white-space: nowrap; flex: none; margin-left: 4px; min-width: 108px; font-variant-numeric: tabular-nums; }
.key::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--green); }
.key.free { font-family: var(--font); color: var(--faint); }
.key.free::before { background: var(--faint); }
+70 -12
View File
@@ -55,6 +55,7 @@ const CHEV = "m5.5 6.5 2.5 2.5 2.5-2.5";
const CHEV_R = "m6.5 4.5 3 3.5-3 3.5";
const CHECK = "m3.5 8.5 3 3 6-7";
const PLUS = "M8 3.5v9M3.5 8h9";
const COPY_ICON = "M5.5 5.5V3.5h7v7h-2M3.5 5.5h7v7h-7z";
// A brand icon: colour logos are images, mono logos take the text colour.
// Nothing is ever invented: a model with no known vendor keeps the slot
@@ -597,14 +598,35 @@ function accountPlan(a) {
// page that gets anything else connected to it: base URL, key, model ids,
// and a snippet in whichever language the reader is holding.
async function copy(text, what) {
try { await navigator.clipboard.writeText(text); status(t("{what} copied", { what }), "ok"); } catch { status(text); }
async function copy(text, what, btn) {
try { await navigator.clipboard.writeText(text); status(t("{what} copied", { what }), "ok"); flashCopied(btn); }
catch { status(text); }
}
// flashCopied answers on the button itself: the icon becomes a tick and
// the button takes a green breath, then it reverts on its own. The footer
// toast says what was copied; this says it landed. Clicking again restarts
// the pop and re-arms the timer.
function flashCopied(b) {
if (!b) return;
b.classList.remove("done");
void b.offsetWidth; // restart the animation when clicked again
b.classList.add("done");
b.title = t("Copied");
b.replaceChildren(svg(CHECK, 12, 1.7));
clearTimeout(b.copiedT);
b.copiedT = setTimeout(() => {
b.classList.remove("done");
b.title = t("Copy");
b.replaceChildren(svg(COPY_ICON, 12, 1.5));
}, 1200);
}
function copyBtn(text, what) {
const b = el("button", "copy");
b.title = t("Copy");
b.append(svg("M5.5 5.5V3.5h7v7h-2M3.5 5.5h7v7h-7z", 12, 1.5));
b.onclick = (ev) => { ev.stopPropagation(); copy(text, what); };
b.append(svg(COPY_ICON, 12, 1.5));
b.onclick = (ev) => { ev.stopPropagation(); copy(text, what, b); };
return b;
}
@@ -1187,7 +1209,7 @@ function renderEditor(p, presetID) {
acct.append(icon(a.agentIcon), el("span", "n", a.user), el("span", "plan", accountPlan(a)));
ed.append(...field(t("Account"), acct, t("{agent}'s sign-in, read from its own files. Sign out there and this provider goes away.", { agent: a.agentName })));
ed.append(...field(t("Models"), renderModels(p), ""));
ed.append(...field(t("Endpoints"), renderEndpoints(p, null)));
ed.append(...field(t("Endpoints"), renderEndpoints(p, p)));
const bar = el("div", "bar");
bar.append(el("span", "grow"));
const cancel = el("button", "text", t("Cancel"));
@@ -1224,6 +1246,26 @@ function renderEditor(p, presetID) {
keyWrap.append(key, side);
ed.append(...field(t("API key"), keyWrap, isNew ? t("Kept in ~/.config/magpie/providers.json, readable by you alone. Nothing is read from your shell.") : ""));
// a relay that offers several regional endpoints: one selector, and the
// provider's base URLs follow it
let refreshEndpoints = () => {};
if (pr?.regions?.length) {
const seg = el("div", "segs");
const cur = pr.regions.find((r) => r.chat && r.chat === (draft.chat || pr.chat)) || pr.regions[0];
for (const r of pr.regions) {
const b = el("button", "opt" + (r.id === cur.id ? " on" : ""), t(r.name));
b.onclick = () => {
draft.chat = r.chat || ""; draft.responses = r.responses || ""; draft.anthropic = r.anthropic || "";
for (const x of seg.querySelectorAll(".opt")) x.classList.toggle("on", x === b);
slide(seg, "regions");
refreshEndpoints();
};
seg.append(b);
}
queueMicrotask(() => slide(seg, "regions"));
ed.append(...field(t("Region"), seg, t("which endpoint {p} is reached through", { p: pr.name })));
}
if (p) ed.append(...field(t("Models"), renderModels(p), ""));
else if (custom) {
const ex = input("", t("model ids, comma separated · e.g. gpt-5.5, claude-sonnet-5"));
@@ -1231,7 +1273,16 @@ function renderEditor(p, presetID) {
ed.append(...field(t("Models"), ex, t("Optional: magpie asks the vendor for its list after saving.")));
}
if (!custom) ed.append(...field(t("Endpoints"), renderEndpoints(p, pr)));
if (!custom) {
const ebox = el("div");
refreshEndpoints = () => {
const base = p || pr || {};
const src = { chat: draft.chat || base.chat || "", responses: draft.responses || base.responses || "", anthropic: draft.anthropic || base.anthropic || "" };
ebox.replaceChildren(renderEndpoints(p, src));
};
refreshEndpoints();
ed.append(...field(t("Endpoints"), ebox, ""));
}
if (custom) {
const more = el("details", "more");
@@ -1279,16 +1330,16 @@ function renderEditor(p, presetID) {
// Which of the vendor's models the agents get to see: click to toggle, type
// to add one the vendor's list lacks, Refresh to ask the vendor again.
// The endpoints a provider serves, with a Test that reports against each one.
function renderEndpoints(p, pr) {
function renderEndpoints(p, src) {
const eps = el("div", "eps");
const slots = {};
const src = p || pr;
const urls = src || {};
for (const [proto, label, hint] of PROTOS) {
if (!src[proto]) continue;
if (!urls[proto]) continue;
const e = el("div", "ep");
const pl = el("span", "pl", label);
pl.title = t(hint);
e.append(pl, el("code", "", src[proto]), slots[proto] = el("span", "res"));
e.append(pl, el("code", "", urls[proto]), slots[proto] = el("span", "res"));
eps.append(e);
}
if (p) {
@@ -1526,14 +1577,21 @@ function renderUsage() {
return;
}
stats.classList.remove("empty");
const tile = (n, label, sub) => {
const tile = (n, label, sub, title) => {
const t = el("div", "kpi");
if (title) t.title = title;
t.append(el("b", "", n), el("span", "", label));
if (sub) t.append(el("small", "", sub));
stats.append(t);
};
tile(fmtN(tokensOf(u)), t("tokens"), t("{a} in · {b} out", { a: fmtN(u.input), b: fmtN(u.output) }));
tile(fmtN(u.cache_read), t("cache read"), u.cache_write ? t("{n} written", { n: fmtN(u.cache_write) }) : "");
// cache reads are billed at a fraction of input, so how much of the prompt
// came from cache is the number that explains the bill; input here already
// excludes the cached tokens (the gateway subtracts them). The written
// count is secondary and only fits in the tooltip.
const promptTokens = u.input + u.cache_read;
const hit = u.cache_read && promptTokens ? t("hit rate {p}", { p: Math.round(100 * u.cache_read / promptTokens) + "%" }) : "";
tile(fmtN(u.cache_read), t("cache read"), hit, u.cache_write ? t("{n} written", { n: fmtN(u.cache_write) }) : "");
tile(fmtN(u.reasoning), t("reasoning"), t("inside output"));
tile(String(u.calls), t(u.calls === 1 ? "call" : "calls"), u.errors ? t("{n} failed", { n: u.errors }) : "");
+7
View File
@@ -160,6 +160,12 @@ const I18N = {
"Copy the gateway URL": "复制网关地址",
"Gateway URL": "网关地址",
"Copy": "复制",
"Copied": "已复制",
"Region": "区域",
"Auto": "自动",
"Global": "国际",
"China Mainland": "中国大陆",
"which endpoint {p} is reached through": "通过哪个入口访问 {p}",
"{what} copied": "已复制{what}",
"Connect": "接入",
"Loopback only · the key can be anything": "仅限本机回环 · 密钥可以随意填",
@@ -223,6 +229,7 @@ const I18N = {
"tokens": "token",
"{a} in · {b} out": "输入 {a} · 输出 {b}",
"cache read": "缓存读取",
"hit rate {p}": "命中率 {p}",
"{n} written": "写入 {n}",
"reasoning": "推理",
"inside output": "计入输出",
File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 27 KiB

+28 -9
View File
@@ -13,19 +13,30 @@ const (
// PresetDef describes one preset.
type PresetDef struct {
ID string `json:"id"`
Name string `json:"name"`
Icon string `json:"icon"`
Kind Kind `json:"kind"`
Chat string `json:"chat,omitempty"`
Responses string `json:"responses,omitempty"`
Anthropic string `json:"anthropic,omitempty"`
Catalog string `json:"catalog,omitempty"`
Website string `json:"website,omitempty"`
KeysURL string `json:"keysUrl,omitempty"`
NoKey bool `json:"noKey,omitempty"` // local servers: a key is optional
Sponsored bool `json:"sponsored,omitempty"` // shown first, with a tag
Note string `json:"note,omitempty"` // one line under the name
Regions []Region `json:"regions,omitempty"` // base-URL choices (a relay's regional endpoints)
}
// Region is one base-URL option of a preset that offers several. The first
// is the default; picking another in the editor swaps the endpoints.
type Region struct {
ID string `json:"id"`
Name string `json:"name"`
Icon string `json:"icon"`
Kind Kind `json:"kind"`
Chat string `json:"chat,omitempty"`
Responses string `json:"responses,omitempty"`
Anthropic string `json:"anthropic,omitempty"`
Catalog string `json:"catalog,omitempty"`
Website string `json:"website,omitempty"`
KeysURL string `json:"keysUrl,omitempty"`
NoKey bool `json:"noKey,omitempty"` // local servers: a key is optional
Sponsored bool `json:"sponsored,omitempty"` // shown first, with a tag
Note string `json:"note,omitempty"` // one line under the name
}
// presets are ordered as they appear in the picker.
@@ -93,10 +104,18 @@ var presets = []PresetDef{
Website: "https://cloud.siliconflow.cn", KeysURL: "https://cloud.siliconflow.cn/account/ak"},
{ID: "aihubmix", Name: "AiHubMix", Icon: "aihubmix-color", Kind: KindRelay,
Chat: "https://aihubmix.com/v1", Anthropic: "https://aihubmix.com",
Website: "https://aihubmix.com", KeysURL: "https://aihubmix.com/token"},
Website: "https://aihubmix.com", KeysURL: "https://console.aihubmix.com/token"},
{ID: "302ai", Name: "302.AI", Icon: "ai302-color", Kind: KindRelay,
Chat: "https://api.302.ai/v1", Anthropic: "https://api.302.ai",
Website: "https://302.ai", KeysURL: "https://302.ai/api-keys/list"},
{ID: "yylx", Name: "鱼鱼连线", Icon: "yylx", Kind: KindRelay,
Chat: "https://app.yylx.io/v1", Anthropic: "https://app.yylx.io",
Website: "https://yylx.io", KeysURL: "https://app.yylx.io/keys",
Regions: []Region{
{ID: "auto", Name: "Auto", Chat: "https://app.yylx.io/v1", Anthropic: "https://app.yylx.io"},
{ID: "global", Name: "Global", Chat: "https://global.yylx.io/v1", Anthropic: "https://global.yylx.io"},
{ID: "cn", Name: "China Mainland", Chat: "https://cn.yylx.io/v1", Anthropic: "https://cn.yylx.io"},
}},
{ID: "ollama", Name: "Ollama", Icon: "ollama", Kind: KindLocal, NoKey: true,
Chat: "http://localhost:11434/v1", Anthropic: "http://localhost:11434",