Commit Graph
2 Commits
Author SHA1 Message Date
yetone 9ce59b8340 routing: a request's row says the credits its reply said it cost (jiabubu)
jiabubu on Discord (#feedback): the Routing page's request list showed no
credits for a request that spent them. The gateway already read a reply's
usage.credit (#2512) into the usage ledger, which the Usage page shows,
but the route trace's RouteUsage had no field for it.

RouteUsage now carries Credits (the reply's, nil when it said none). The
Routing page's request row shows "N credits" after its cost, or alone
when the request has no known price (it read "—" before), with the Usage
page's help text under the pointer; By session sums them in the session's
cost, shown even when no request in it was priced. The help text "What it
cost in its plan's credits, as the reply said" moves from the Usage
plugin's i18n.js to the core's, since two plugins say it now.

Tests: TestPluginPlanCreditsReachTheLedger also checks the route's usage
carries 0.01 on every endpoint (red without the field: Credits <nil>).
routing-credits.test.cjs: credits alone, priced plus credits, none, and
a session's sum, in chromium and webkit, en zh zh-TW ja de, at 1100 and
420, with no overflow.

Broken by hand: the old client.js makes routing-credits 10 of 10 red.

Run at the pushed head on mote: gofmt -l clean; go test -run 'TestDailyCredits|TestPluginPlanCredits|Credits' ./internal/provider ./internal/gateway ok; GOOS=linux go vet -tags nogui and GOOS=windows go vet of provider, gateway, gui ok (rebased on origin/main b92b3bc5b). The full GUI suite (WSL, both engines, every language) ran at the earlier base 50265256b; its 58 files red on head but not in main's run were run again, and the 11 files still in question were run on head and on origin/main b92b3bc5b side by side: routing-credits and i18n-keys pass, and every other red is a test main fails too, with an open issue (#4489 usage-ledger-ttft, #4719 usage-speed, #3593/#4560/#4585 routing-rules-line, #4713 routing-time-went, #2559/#4966 routing-bodies, #4400 sessions-bar-names, #1745 group-member-info, #5052 account-eye); head shows a few more languages of those same tests.

Not tried: a real WorkBuddy request through the GUI; history written
before this release has no credits in its routes and reads as before.
2026-11-04 01:27:06 +08:00
yetone c9824bb364 usage: each request's row says the credits its reply said
jiabubu (Discord, #feedback) saw a WorkBuddy request's credits shown
before, and now nowhere. The gateway still keeps them: usage.Record.Credits
from the chat usage's `credit` (#2512) reaches the ledger through the
WorkBuddy plugin on every endpoint shape. The ranking, Overview, tiles and
Sessions show them too. The Requests list's rows never did: a plan's model
there reads "—" for a price, and its detail had no line for credits.

Now the cost cell of a row whose reply said credits shows "N credits"
(the same ledCredits words as the ranking) in place of the dash, or under
the API price reference when the model also has a price. The expanded row
has a Credits line. A reply that said none still shows "—". This applies
to every credit-priced provider, since it reads the record's credits and not
the provider.

Tests:
- internal/gateway/plugin_plan_credits_test.go: a moved workbuddy-ai plugin
  replies with WorkBuddy's credit usage. Chat, Messages and Responses, each
  streamed and whole, each land 0.01 credits in the ledger.
- internal/gui/tests/plan-credits.test.cjs: a new test checks the row's
  cell, its title, a row with no credits, a priced row with credits and
  the detail, at 1400px and 420px.

Run at this head (mote, via mote-run):
- plan-credits.test.cjs: 36/36 in Chromium and WebKit, en, zh, zh-TW, ja,
  de, 1400px and 420px.
- go test -run 'PlanCredits|TestCoreScriptBudget|I18n|Lang' over
  internal/gateway, gui, usage and usageapi: ok.
- gofmt -l is clean. GOOS=linux and GOOS=windows go vet for gateway, gui
  and usage: ok.
- The other Usage page files the change reaches, alone, fail the same on
  the base as with it:
  - usage-agents-hide: 22 (#3414, #2276).
  - usage-fold: 4 (#3415).
  - usage-ledger: 6, "newest live route needs no return-to-live button"
    (#4078, #3104).
  usage-curve-zoom-back passes alone.
- Rebased from f49f6ba68 onto origin/main 6b8134430. plan-credits
  (36/36) and the Budget|PlanCredits Go tests ran again at the rebased
  tree: ok. vet and the other GUI files ran on f49f6ba68.

Broken by hand:
- With the old page.js, plan-credits goes 12 red (the new test in each
  engine and language).
- With chat.go's `out.Credits = c` dropped, all six cases of
  TestPluginPlanCreditsReachTheLedger go red.

Not tried: WorkBuddy China's Claude models, which the plugin sends to
/v1/messages. No real bytes were captured (the account answers 401), and
the gateway reads credit from chat usage only (#5011). There was no real
WorkBuddy request through the GUI; the fixture's usage follows #2512's.
2026-11-03 12:37:37 +08:00