Commit Graph
2 Commits
Author SHA1 Message Date
yetone 47b7ba3030 models: a model its provider lists at $0 says free in the pickers and Routing (jiangguochao666 on X)
jiangguochao666 asked for each provider's free models to show in Routing
and the model settings, to route to them. The green free tag was shown
only for a plan's free model or a model with "free" in its name.

provider.PricedFree says a model is free only when its price for that
provider is known to be $0:
- A price the user set comes first (provider/model, provider/*, then
  the model's own key). A $0 one makes it free, and any other price, a
  paid tier included, makes it paid.
- Otherwise the provider's own catalogs decide. A $0 from a plan's
  catalog (-plan, membership catalogs) is the plan's per-token price,
  not free. A $0 from only the model's maker is not free either: a
  relay serving Zhipu's free glm-4.7-flash may charge for it.
- No known price means not free.
FreeModel (Free first, Cheapest first routing) is unchanged.

From the local models.dev cache this tags:
- every model of NVIDIA NIM and ModelScope;
- the :free / -free models of OpenRouter, OpenCode Zen and Go, Kilo,
  AIHubMix, ZenMux, Vercel, Requesty and other relays;
- Zhipu's and Z.ai's glm-4.x-flash.
No coding or token plan is tagged.

Where it shows, with the hover "free: listed at $0 on this provider":
- an agent's model picker (agent.Option.Zero);
- the provider editor's model chips, and its Free only button
  (modelJSON.Zero);
- Routing's Add a model and classifier pickers (modelRef.Zero).
The word is new in en, zh, zh-TW, ja and de.

Tests, each red on the old code:
- TestPricedFreeIsTheProvidersOwnZero: own, plan, maker-only, unpriced
  and user prices.
- TestPickerSaysAZeroPricedModelIsFree: Option.Zero, cleared at once by
  a price the user saves.
- TestZeroPricedModelsSayFree: the editor's and Routing's JSON.
- zero-priced-free.test.cjs: the three surfaces, in Chromium and WebKit,
  at 1100 and 420px, in all 5 languages. It checks the tag's text,
  hover and fit, that the paid model has no tag, that a plan's free
  model keeps its own hover, no sideways scroll and no page errors.

Broken by hand (each restored, diff checked):
- The source check ignored (maker and plan $0 count): the provider test
  goes red on the plan model and the relay's glm-4.7-flash.
- PricedFree always false: the provider, agent and gui tests go red.
- The user's price ignored: the provider and agent tests go red.
- The badge's o.zero / m.zero and Routing's zero dropped in app.js and
  routing/client.js: zero-priced-free goes red, "the $0 model has no
  free tag in the agent's picker".

Run at this commit's tree (base 3f1f1882a):
- mote, go test -timeout 45m ./...: 84 ok, 19 with no tests, 3 FAIL.
  Each red is filed and fails the same way at origin/main 7d022bdb6:
  - TestEveryRouteHasACommandOrIsNamed: /api/context/reply, #5026.
  - TestMainWindowCorners/macOS_26_SDK: macOS 27, #3949.
  - TestCompactionOverByteCapEveryTime: red only in the full gateway
    run, ok alone here and at main, #4862.
  TestCoreScriptBudget passed; no budget was raised.
- gofmt -l: clean. GOOS=windows go vet (mote): ok. go vet -tags gtk3 on
  Linux (wsl, magpie-desktop): ok. A cross GOOS=linux vet from macOS
  fails inside wails' cgo files on main too.
- wsl: zero-priced-free + i18n-keys, 24 of 24 pass.
- wsl: the whole GUI suite, concurrency 4: 19062 of 19585 pass,
  523 fail in 127 files, at load ~86 on a shared box. Those 127 files
  run again at concurrency 2: 465 red here and 417 at the base
  3f1f1882a, the same files on both. 11 files with a red only on this
  tree, the routing, model and search ones near this change, run again
  alone at load ~3: the same 7 fail on both trees
  (33 here, 27 at the base), and which cases fail changes from run to
  run with the same errors. None is in a test that reads the free tag.
  Filed already: #3096 and #5035/#5088 (routing-rule-*, rest-try-now),
  #4388 (model-chip-steady alone on WSL), #4585 and #4932 (under load).
  The other files red only on this tree (usage wheels, tray, archive
  rows) were not run again alone; nothing in them reads the free tag.

Not tried: a real provider's list in the live app (the tests use
fixture catalogs); Free first routing choosing a $0-priced model it
didn't choose before (FreeModel is unchanged on purpose).
2026-11-04 05:00:18 +08:00
yetone 60808fd9cf usage, gateway, gui: magpie's own requests are told apart from the agent's, and a classifier on a subscription says it asks it every turn (#1839)
kensenzhao saw a subscription's allowance spent by requests the agent
didn't make: a routing group's classifier, set to a subscription's model,
asks it as every turn begins, and those calls looked like the agent's own.

What changed
- usage.Group has an own share (calls, tokens, cost) of the calls magpie
  made by itself, filled for models, keys and accounts. Record.ByMagpie
  is the test: agent "magpie", or one of its own User-Agents
  (magpie-router/1, magpie-search/1, magpie-vision/1) where the agents
  aren't loaded. The calls still count in the group's totals, as they
  went to the same key or account. A group with none sends no "own".
- The classifier's calls are Kind "routing": callKind marks RouterAgent's
  requests, and the decision model's record (Jev / System One) is written
  with it. A "Routing classifier" purpose names them in the ledger.
- Usage page: magpie's row among the agents and its ledger rows carry a
  "magpie's own" mark; an account's, key's or model's row adds "{n} by
  magpie itself"; an account's card says how many of the period's
  requests were magpie's own, drawn again once the summary arrives after
  the allowances.
- Routing page: /api/groups marks a model a subscription account serves
  (modelRef.Sub, servedRef). Beside a classifier on such a model, or a
  group whose first member is one, the editor says every turn starts
  with a request to that subscription, two when it picks both intent and
  effort in words. A classifier on a key or a free model says nothing.
- New strings in zh, zh-TW, ja and de. The mark is a muted chip with an
  even border all round (no left stripe).

Tests
- TestSummaryCountsMagpiesOwnCallsApart, TestByMagpie (usage).
- TestIntentRoutesATurn and TestJevPicksTheIntent (gateway) now check
  the classifier's records are Kind routing and magpie's own, and the
  agent's records are not.
- TestServedRefSaysASubscription (gui).
- own-requests.test.cjs: Chromium and WebKit, 1100 and 390 wide,
  en/zh/zh-TW/ja/de, the API faked; no click scroll, no sideways page.
- Broken by hand, each turned its test red: addOwn counting nothing;
  callKind's routing case removed; decide.go's Kind blanked; the ledger
  mark, the agents' mark, the "{n} by magpie itself" line, the card's
  line, its redraw after the summary, the Routing hint, its group case
  and modelRef.Sub each removed.

Run: gofmt -l; go vet on darwin, linux -tags nogui and windows; go test
for usage, access, catalog, gui (-tags nogui) and gateway in full; the
GUI tests above, the ledger, routing-intent and translation tests.
Not done: the warmups (warmClaude/askClaude) write no usage record at
all, so they can't be marked; that is left as it was. Not tried with a
real subscription classifier against a live account.
2026-10-13 01:41:50 +08:00