Files
magpie/internal/gui/assets/modellimits.js
T
yetone e5b5397c96 providers: a model's context window and max output are set in its Model settings row
sayagoodbyeplz on Discord: WorkBuddy's deepseek-v4.1-flash replies 128000
tokens, not the 384000 models.dev lists, and there was no visible place
to set that for one model. The editor's Advanced Context window and Max
output already took "model=size", but a user looking at the model never
saw them.

Each model's row in Model settings now has a Context window box and a
Max output box beside "Listed as". The placeholder is the listed value
(the vendor's list, else models.dev's, within the window), or the "*"
value from Advanced when one is set. A value typed there is staged as
model=size in Advanced's field, so both say the same thing, and the Save
sends it in contexts/outputs as before. An empty box drops the model's
own value. A bad value is refused with Advanced's message. Restore
default clears both, and its title says so in every language. A
classifier-only provider has neither box, as in Advanced.
/api/providers gives each model a listedOutput (its reply limit without
the user's Max output) so the placeholder doesn't show the user's own
value back.

The boxes are drawn by modellimits.js, imported when the editor draws a
model's row (like keyspend.js), and nine comments in app.js are cut, so
the core stays in its budget with no raise (1,533,541 of 1,533,802 on a5c97cd83).

Run (mote before the modellimits.js move; WSL magpie-desktop, Go 1.26.8,
at this tree, after it, since mote went down):
- go vet ./... (mote, darwin; again on internal/gui, agent and provider
  at the rebased head on a5c97cd83); GOOS=windows go vet ./... and
  GOOS=linux go vet -tags nogui ./... (WSL): ok
- go test ./internal/gui/ ./internal/agent/ ./internal/provider/ (mote): ok,
  except the real-window AppKit tests TestCoveredWindowStaysUp and
  TestClosingWindowMarksPageOutOfSight killed at their deadlines (#4924,
  #2645); WSL, -tags nogui: TestProviderModelOutput*|Budget ok
- TestProviderModelOutputSaid gains a check that listedOutput is
  models.dev's 131072 while the user's 100000 is set
- node --test internal/gui/tests/model-limits.test.cjs (new): 20/20,
  Chromium and WebKit, en/zh/zh-TW/ja/de, 1200 and 420px: placeholder
  384K, 128k typed -> Advanced "deepseek-v4.1-flash=128k" and unsaved,
  a bad value refused, Advanced's "*" becomes the placeholder, the Save
  body's outputs/contexts, Restore default clears the model's own
- WSL, at this tree: model-limits, model-headers, model-price-tiers,
  model-api-preset, provider-detect, provider-listed-as,
  provider-same-as, provider-max-output, provider-output-picks,
  old-webkit, i18n-keys: 105/106, the one red i18n-keys' "a plugin's
  words are its own", red at a46190e1f too (#5332, #5426);
  TestCoreScriptBudget ok. Before that, every model-*, provider-*,
  editor-*, context-picks/tune*, i18n-*, menu-scroll, click-scroll and
  old-webkit file (2325 tests): the reds in model-chip-steady,
  model-copy-id, provider-models-rest, provider-picks-stay,
  provider-fetch-again, provider-typed, model-suffix-own, model-load,
  editor-advanced-align and click-scroll are red the same at a46190e1f on
  WSL (#4388, #4621, #4396, #4397, #5232, #4673, #4962, #4615, #4385).
  That run found two of this change's own: the rows' hooks kept on the
  draft made an untouched editor read as unsaved (model-price-tiers,
  model-api-preset), and a row filled after an await moved the page
  (provider-detect); the hooks are left out of the draft's value and a
  row is filled at once once modellimits.js is loaded.
Broken by hand: model-limits.test.cjs on origin/main's assets fails at
once (no .mlimit row).
Not tried: the real app window; the full GUI suite.
Full suite not run at push.

Reported-by: sayagoodbyeplz (Discord)
2026-11-08 19:05:36 +08:00

44 lines
2.7 KiB
JavaScript

// A model's own context window and max output in the provider editor's
// Model settings (sayagoodbyeplz on Discord: WorkBuddy's deepseek-v4.1-flash
// replies 128K, not models.dev's 384K). A size typed here is staged as
// model=size in Advanced's Context window and Max output, which the Save
// sends; Advanced's field is told so it says the same. The placeholder is
// what Advanced gives every model ("*"), else what is listed. app.js
// imports this when it draws a model's row, so it weighs nothing on the core.
window.modelLimitsFill = function (at, m, p, changed) {
const id = m.id;
return [
["contexts", "Context window", m.listed || m.context, p.contexts, t("The window agents are told {id} takes; empty: the vendor's or models.dev's", { id }), (v) => t("Context window: {v} is not a length like 128k or 1m", { v })],
["outputs", "Max output", m.listedOutput || m.output, p.outputs, t("The most a reply of {id} may hold, told to agents as their max tokens and kept to by magpie; empty: the vendor's or models.dev's", { id }), (v) => t("Max output: {v} is not a number of tokens like 32k", { v })],
].map(([k, label, listed, saved, tip, said]) => {
const box = el("label", "msame mlimit");
box.dataset.limit = k;
const now = () => parseContexts(draft[k] || "").map || {};
const own = () => now()[id];
const shownOf = () => own() ? tokenSize(own()) : "";
// a window over the listed one isn't told, so "*" shows as the listed
const placeholder = () => { const all = now()["*"]; return all ? tokenSize(k === "contexts" && listed && listed < all ? listed : all) : listed ? tokenSize(listed) : ""; };
const i = input(shownOf(), placeholder());
i.title = tip;
i.spellcheck = false;
i.onchange = () => {
const typed = i.value.trim();
const cx = parseContexts(draft[k] || "");
if (cx.error) { i.value = shownOf(); status(said(cx.error), "warn"); return; }
const n = typed === "" ? 0 : tokensTyped(typed);
if (!(n > 0) && typed !== "") { i.value = shownOf(); status(said(typed), "warn"); return; }
if (n) cx.map[id] = n; else delete cx.map[id];
draft[k] = contextsText(cx.map);
const adv = at.closest(".editor")?.querySelector("input." + k);
if (adv) { adv.value = draft[k]; adv.dispatchEvent(new Event("input")); }
i.value = shownOf();
changed();
};
i.onkeydown = (e) => { e.stopPropagation(); if (e.key === "Enter") i.blur(); else if (e.key === "Escape") { i.value = shownOf(); i.blur(); } };
box.append(el("span", "", t(label)), i);
at.append(box);
const again = () => { if (document.activeElement !== i) i.value = shownOf(); i.placeholder = placeholder(); };
return { i, own, again, saved: () => saved?.[id] || 0 };
});
};