routing: a skipped member's story line leads with its own logo (#3953)
A story line about a member the gateway skipped before trying it (r.left, "API key is left out: this request is longer than its 200K context window…") got no logo, or another member's: logoed walked only r.order. MYCF711 found it and proposed walking r.left too, skipped members first, with r.left in the logos memo keys; this ports that (their branch MYCF711/magpie fix/routing-left-logos, 003611a02). Changed from their patch: list order alone can't settle two members named alike (an order key and a skipped account both "API key"). Left first gave a failed order key's try line the skipped one's logo; order first gives the skipped one's line the order key's. So a line now carries the member it is about where it has one (a skipped one's line via leftWhy, a try's via tried()), and that member wins a tie at the same place; otherwise order before left. The memo keys take that member's seat and every r.order + r.left logo. Siblings checked: say()'s caption is plain text; the rows (3650) and the stage list (1911) already read r.left; app.js has no story logos. Run (mote-run, at8bade6c5e): - routing-log-icons.test.cjs, chromium + webkit, en/zh (+ the live case's en/zh/zh-TW/ja/de): 14/14 ok. New case: order [glm, DeepSeek key "API key", gpt], left [Zen "API key", 200K window], DeepSeek tried and failed; the 200K line must lead with opencode, the DeepSeek try line with deepseek-color. - Broken by hand, each red: r.order only (skipped line got deepseek-color, the reporter's symptom), the reporter's left-first without the about member (try line got opencode), order-first without it (skipped line got deepseek-color). - Every GUI file that reaches the Routing page (184 files with i18n-keys, 2375 tests): 98 red; the 15 red files run again side by side on a clean origin/main8bade6c5ecopy and this tree: 99 red on main, 93 here, the same files, under load ~100 on mote. Each has an open issue: #3897 (i18n-keys "Runs as"), #3402, #3408, #3409, #2115/#2658, #3410, #3799, #3789, #3411, #3094/#3096, #3593, #3412, #3954, #1905, #1345/#1948. - go test -tags nogui ./internal/gui -run 'Budget|Size|I18n|Plugin': ok (client.js is the routing plugin's, not a core script). Not tried: the real app with a real skipped Zen member; Windows/Linux webviews. Co-authored-by: MYCF711 <323101370+MYCF711@users.noreply.github.com>
This commit is contained in:
@@ -796,6 +796,21 @@ function routingPage(part) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// leftWhy is why a member was skipped before it was tried (r.left)
|
||||
const leftWhy = (x) => x.held
|
||||
? t("{who} is left out: the gateway key asking may not use its account.", { who: who(x) })
|
||||
: x.window
|
||||
? t("{who} is left out: this request is longer than its {n} context window, so it would only refuse it. It's asked only once every one with room is out of its allowance.", { who: who(x), n: ctxShort(x.window) })
|
||||
: x.noCredits
|
||||
? t("{who} is left out: a usage window is used up, and the account is set not to spend its credits, so it counts as used up until that window renews.", { who: who(x) })
|
||||
: x.capped
|
||||
? t("{who} is left out: a usage window is at {n}, past the {cap}% cap set on the account, so it counts as used up until that window renews.", { who: who(x), n: pct(x.used), cap: x.capped })
|
||||
: x.barred
|
||||
? t("{who} is left out: it is set to serve other models, not {model}.", { who: who(x), model: x.model })
|
||||
: x.kind === "key"
|
||||
? t("{who} is left out: {name} lists {model} to its other keys, not this one.", { who: who(x), name: x.name, model: x.model })
|
||||
: t("{who} is left out: its plan doesn't list {model}.", { who: who(x), model: x.model });
|
||||
|
||||
// asides: the others' places, where they say something
|
||||
function asides(r) {
|
||||
const out = [];
|
||||
@@ -848,19 +863,7 @@ function routingPage(part) {
|
||||
}
|
||||
const pooled = r.order.find((x) => !x.aside && x.kind === "key");
|
||||
for (const x of r.order.filter((x) => x.aside)) out.push(t("{who} is made for {api}, not {other} as the keys routed over are, so it isn't one of them: it's tried after them.", { who: who(x), api: API[x.speaks] || x.speaks || t("any API"), other: API[pooled?.speaks] || pooled?.speaks || t("any API") }));
|
||||
for (const x of r.left || []) out.push(x.held
|
||||
? t("{who} is left out: the gateway key asking may not use its account.", { who: who(x) })
|
||||
: x.window
|
||||
? t("{who} is left out: this request is longer than its {n} context window, so it would only refuse it. It's asked only once every one with room is out of its allowance.", { who: who(x), n: ctxShort(x.window) })
|
||||
: x.noCredits
|
||||
? t("{who} is left out: a usage window is used up, and the account is set not to spend its credits, so it counts as used up until that window renews.", { who: who(x) })
|
||||
: x.capped
|
||||
? t("{who} is left out: a usage window is at {n}, past the {cap}% cap set on the account, so it counts as used up until that window renews.", { who: who(x), n: pct(x.used), cap: x.capped })
|
||||
: x.barred
|
||||
? t("{who} is left out: it is set to serve other models, not {model}.", { who: who(x), model: x.model })
|
||||
: x.kind === "key"
|
||||
? t("{who} is left out: {name} lists {model} to its other keys, not this one.", { who: who(x), name: x.name, model: x.model })
|
||||
: t("{who} is left out: its plan doesn't list {model}.", { who: who(x), model: x.model }));
|
||||
for (const x of r.left || []) out.push(leftWhy(x));
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -2702,10 +2705,15 @@ function routingPage(part) {
|
||||
// provider a line of the story names, so who it is about reads at a
|
||||
// glance (the owner: 这里在前面显示对应的 provider 图标会不会更直观一点)
|
||||
const logoOf = (w) => w.icon || w.preset || "generic";
|
||||
function logoed(s, r) {
|
||||
// A line names an order member, one skipped before it was tried (r.left,
|
||||
// #3953: a skipped OpenCode Zen Free's line had no logo, or another
|
||||
// member's), or both. Where two share the name at the same place (a key
|
||||
// called "API key" on two providers), the member the line is about wins,
|
||||
// then an order member over a skipped one.
|
||||
function logoed(s, r, about) {
|
||||
const word = /[A-Za-z0-9_]/;
|
||||
let hit = null;
|
||||
for (const w of r.order) {
|
||||
for (const w of new Set([about, ...r.order, ...(r.left || [])].filter(Boolean))) {
|
||||
for (const n of new Set([who(w), w.name].filter(Boolean))) {
|
||||
for (let i = s.indexOf(n); i >= 0; i = s.indexOf(n, i + 1)) {
|
||||
if (word.test(s[i - 1] || "") || word.test(s[i + n.length] || "")) continue;
|
||||
@@ -2736,9 +2744,11 @@ function routingPage(part) {
|
||||
: "This subagent task is encrypted. Only ChatGPT accounts can read it."), "aside"]);
|
||||
items.push([affWhy(r, true) || ruleWhy(r, true) || firstWhy(r), "why"]);
|
||||
for (const s of nestedWhy(r)) items.push([s, "why"]);
|
||||
for (const a of asides(r)) items.push([a, "aside"]);
|
||||
// the member a line is about, where it is one: a skipped one's line, a try's
|
||||
const skipped = new Map((r.left || []).map((x) => [leftWhy(x), x]));
|
||||
for (const a of asides(r)) items.push([a, "aside", undefined, skipped.get(a)]);
|
||||
r.tries.forEach((tr, i) => {
|
||||
items.push([tryWhy(r, i), tr.done ? (tryOk(tr) ? "ok" : "bad") : "wait"]);
|
||||
items.push([tryWhy(r, i), tr.done ? (tryOk(tr) ? "ok" : "bad") : "wait", undefined, tried(r, tr)]);
|
||||
// where its time went, once it is done: the first try's has the
|
||||
// request's masking before it
|
||||
const timed = i === 0 && r.masking > 0 ? { ...tr, masking: r.masking } : tr;
|
||||
@@ -2768,7 +2778,9 @@ function routingPage(part) {
|
||||
if (tr.done && tryOk(tr) && tr.upstream) items.push([upstreamWhy(tr), "aside upstream-said", tr]);
|
||||
});
|
||||
if (r.done && !r.tries.length) items.push([t("Nothing was tried: {error}", { error: r.error || r.status }), "bad"]);
|
||||
const key = JSON.stringify([tagKind(r), items.map(([s, c, tr]) => [s, c, tr?.model, tr?.served]), r.order.map(logoOf)]);
|
||||
const aboutKey = (w) => w ? seat(w) : "";
|
||||
const logos = [...r.order, ...(r.left || [])].map(logoOf);
|
||||
const key = JSON.stringify([tagKind(r), items.map(([s, c, tr, w]) => [s, c, tr?.model, tr?.served, aboutKey(w)]), logos]);
|
||||
// a different request starts its steps at the top, even when they say
|
||||
// what the last one's said (the box is routing.css's, #3764); the same
|
||||
// request keeps its scroll while its steps grow
|
||||
@@ -2780,21 +2792,20 @@ function routingPage(part) {
|
||||
// again and, in WebKit, blinks out for a frame, and the story is drawn
|
||||
// again on every request that comes in and at each of its steps, so
|
||||
// with an agent at work every logo in it blinked on and off
|
||||
const logos = r.order.map(logoOf);
|
||||
const was = new Map([...steps.children].map((li) => [li.dataset.k, li]));
|
||||
const lis = items.map(([s, c, tr]) => {
|
||||
const k = JSON.stringify([tagKind(r), s, c, tr?.model, tr?.served, logos]);
|
||||
const lis = items.map(([s, c, tr, w]) => {
|
||||
const k = JSON.stringify([tagKind(r), s, c, tr?.model, tr?.served, aboutKey(w), logos]);
|
||||
const old = was.get(k);
|
||||
if (old) { was.delete(k); return { li: old }; }
|
||||
return { k, s, c, tr };
|
||||
return { k, s, c, tr, w };
|
||||
});
|
||||
keepIcons(...was.values());
|
||||
replaceKeeping(steps, lis.map((x) => {
|
||||
if (x.li) return x.li;
|
||||
const { k, s, c, tr } = x;
|
||||
const { k, s, c, tr, w } = x;
|
||||
const li = el("li", c);
|
||||
li.dataset.k = k;
|
||||
li.append(...(/^(why|ok|bad|wait|aside)$/.test(c) ? logoed(s, r) : [s]));
|
||||
li.append(...(/^(why|ok|bad|wait|aside)$/.test(c) ? logoed(s, r, w) : [s]));
|
||||
if (c === "aside kind") li.prepend(kindTag(r), " ");
|
||||
if (c === "swap") li.prepend(swapTag(tr), " ");
|
||||
if (c === "aside time") li.replaceChildren(timeElement(tr));
|
||||
|
||||
@@ -14,11 +14,17 @@ const day = [now.getFullYear(), now.getMonth() + 1, now.getDate()].map((n) => St
|
||||
const at = (i) => new Date(now.getTime() - (i + 1) * 60e3).toISOString();
|
||||
const glm = { id: "zhipu/a1", provider: "zhipu", name: "Zhipu", icon: "zhipu-color", who: "18610345303", kind: "account", agent: "claude", model: "glm-5.3-flash", routing: "order", shared: true, used: 20 };
|
||||
const gpt = { id: "openai/k1", provider: "openai", name: "OpenAI", icon: "openai", who: "work", kind: "key", model: "glm-5.3-flash", routing: "order", fallback: true, used: 0 };
|
||||
// two named alike (#3953, MYCF711): a key in the order and a member the
|
||||
// gateway skipped before trying it (r.left), each "API key"
|
||||
const ds = { id: "deepseek/k1", provider: "deepseek", name: "DeepSeek", icon: "deepseek-color", who: "API key", kind: "key", model: "glm-5.3-flash", routing: "order", fallback: true, used: 0 };
|
||||
const zen = { id: "opencode-zen-free", provider: "opencode-zen-free", name: "OpenCode Zen Free", icon: "opencode", who: "API key", kind: "account", agent: "claude", model: "deepseek-v4.1-flash-free", routing: "", used: 0, window: 200000 };
|
||||
const routes = [{
|
||||
id: 100, seq: 100, time: at(0), agent: "claude", model: "glm-5.3-flash", provider: "zhipu",
|
||||
order: [glm, gpt],
|
||||
order: [glm, ds, gpt],
|
||||
left: [zen],
|
||||
tries: [
|
||||
{ id: glm.id, model: glm.model, start: at(0), done: true, status: 429, ms: 400, error: "rate limited" },
|
||||
{ id: ds.id, model: ds.model, start: at(0), done: true, status: 500, ms: 300, error: "upstream error" },
|
||||
{ id: gpt.id, model: gpt.model, start: at(0), done: true, status: 200, ms: 22000 },
|
||||
],
|
||||
done: true, status: 200, ms: 22400, tokens: 1200,
|
||||
@@ -89,6 +95,16 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert.deepEqual(l.size, [14, 14], JSON.stringify(l));
|
||||
assert(l.before && l.inline, JSON.stringify(l));
|
||||
}
|
||||
// a line about one of the two named "API key" leads with that one's
|
||||
// logo: the skipped one's line with Zen's, the order key's try with
|
||||
// DeepSeek's, whichever list is looked in first
|
||||
const skipped = lines.find((l) => l.cls === "aside" && l.text.includes("200K"));
|
||||
assert.equal(skipped?.logo, "opencode", JSON.stringify(lines));
|
||||
assert.equal(skipped.name, "API key", JSON.stringify(skipped));
|
||||
assert(skipped.before && skipped.inline, JSON.stringify(skipped));
|
||||
const dsTry = of("bad")[1];
|
||||
assert.equal(dsTry?.logo, "deepseek-color", JSON.stringify(lines));
|
||||
assert.equal(dsTry.name, "API key", JSON.stringify(dsTry));
|
||||
// what the vendor said is word for word, with no logo in it
|
||||
assert(!lines.some((l) => /said/.test(l.cls) && l.logo), JSON.stringify(lines));
|
||||
assert.deepEqual(errors, []);
|
||||
|
||||
Reference in New Issue
Block a user