3 Commits
Author SHA1 Message Date
yetone 396e0e4638 usage: a deleted provider's requests merged into another, or named, from the Requests filter
CyberCaius on Discord: a deleted provider's requests sat under its old id
("<date> 已删除"), and the only way to put them under a provider they
have was renaming that provider onto the old id. Now, with a deleted
provider picked in Usage › Requests' Provider filter, a "…" beside it
offers Merge into… (an app menu of the providers there are now) and
Rename… (the filter's button turns into a name field; Enter or leaving
it saves, Escape keeps it). With the merged-into provider picked, the
same "…" lists Separate <name> for each, the undo.

Nothing in the log is rewritten. Both live on the deletion's own record
in providers.json (Deleted.Into/MergedAt, Deleted.Label), so a provider
added later under the old id inherits neither: it is a different
provider, and its record of its own is what it has. Renaming the target
carries the merge (Rename rewrites Into); deleting the target ends it.

Renames.Both(id, time) gives the id a call is shown under and the one it
was made to (Own). Listing, filtering, the summary and vias go by the
shown id; pricing (Record.priceID, block_price's as), window holds and
the gateway's loggedAnswers go by the own one, so a merge moves no cost
or token, only whose name they sit under. The target's face lists what
was merged into it (Named.Merged). Routes: GET /api/usage/deleted/into,
POST /api/usage/deleted {id, into?, name?}; a field not sent stays.

Run (mote, at this tree on d50f84c9f):
- go test -tags nogui -timeout 45m ./... : every package ok, exit 0.
- GOOS=linux and GOOS=windows go vet -tags nogui on usage, usageapi,
  provider, gui, gateway: ok. gofmt -l clean.
- New: TestDeletedProviderMergedIntoAnother (usage: cost 306 before and
  after the merge, 3 calls under main, coster/pricer price a relay call
  at its own price, a new "relay" keeps only its own call, rename and
  delete of the target, undo), TestDeletedProviderNamedAndMerged
  (usageapi), TestUsageDeletedProviderRoutes (gui).
- GUI: usage-ledger-deleted-merge.test.cjs, chromium and webkit, en zh
  zh-TW ja de at 1400 and 760px: ok. All 63 usage-*/ledger-* files and
  i18n-keys, both engines: 923 of 954 ok. The reds are red the same on
  origin/main c3b0484a9 run alone: usage-agents-hide (#3414),
  usage-fold (#3415), usage-ledger's "newest live route needs no
  return-to-live button" (#3104), and i18n-keys' "a plugin's words are
  its own" on library's "Runs as" (#3897).

After rebasing on origin/main 3e96197da (i18n.js merged with c3b0484a9's
balance keys): go build ./..., go test of internal/usage/...,
usageapi/..., provider/..., gui/... ok; the new GUI file in both
engines and every language ok; i18n-keys only #3897's red.

Broken by hand:
- Both returning (to, to): TestDeletedProviderMergedIntoAnother red,
  "cost 900, before 306".
- renamesOf not setting into: both Go tests red (relay still listed).
- ledProviderMore returning at once: the GUI test red (timeout waiting
  for the …), 5 of 5 subtests in chromium.
- On the old code the new tests don't compile (no MergeDeleted).

Not tried: the real app on a real providers.json with a deleted
provider; Linux/Windows GUI. gateway_sessions still prices by the raw
id, and a deleted provider's per-provider price stops applying once its
id is reused (both before this change, unchanged by it).
2026-10-28 11:15:57 +08:00
yetone 3e22123c9c usage: a deleted provider's calls stay apart from a new one under its id
cybercaius (Discord): after deleting a provider and adding a new one
that took the same id, the old provider's usage showed under the new one.

Delete now records the provider in providers.json ("deleted": id, name,
icon, when, its Was and Gave). UsageRenames gives a deleted id to
<id>~<when> only once something reuses it (a live provider, a later
deleted record, or a later Was), so a deleted provider nobody replaced
keeps its raw id and the existing probe/usage tests stay as they were.
/api/usage's provider faces name a deleted id from its record and set
Named.deleted; the Usage provider picker notes "Deleted {date}" (zh, zh-TW,
ja, de translated). Old deletes, made before this, have no record and
stay merged: nothing tells their calls apart now.

Run (mote): go test -tags nogui -run 'Deleted|Rename|NotSetUp|Probe'
./internal/usage ./internal/usageapi ./internal/provider ok; gofmt -l
clean; go vet -tags nogui ok.
Broken by hand: dropping the f.Deleted append turns
TestDeletedProviderKeepsItsCallsFromOneAddedUnderItsID and
TestDeletedProviderListedApartAndMarked red; restored, green.
Not tried: a real delete-and-re-add in the GUI app.
2026-10-28 04:18:21 +08:00
yetone 6d19988416 usage: a provider the log names but that isn't set up now goes by its name, "Claude Code", not "claude" (@ByronVon1 on X)
The Requests page's Provider filter listed "claude" between named
providers. The usage log keeps the id of every provider a call went to,
and usageapi named those only from provider.All(). The Claude Code
subscription is in that list only while its account is discovered, so
after a sign-out, with account discovery off, or for a preset provider
removed since, the bare id showed. This happened in the filter, each
row's Provider column, the split-by-provider and model-at-provider
legends, the Account filter's provider notes, and the summary's model
and account subtitles (stateOf had its own copy of the same lookup).

- provider.KnownFace(id): the name and icon magpie knows an id by while
  it isn't set up. It covers the built-in subscriptions' card faces
  (accountCard: Claude Code, Codex, Copilot, Gemini, Antigravity, moved
  ones) and then the presets. A custom provider removed since stays its
  id, since nothing else knows its name.
- usageapi.providerFaces: one lookup for LedgerPage and stateOf, in
  order: the provider set up, "Local session" for session-unknown, then
  KnownFace, then the id.

Run:
- TestProvidersNotSetUpAreNamed (new, internal/usageapi). Fails on the
  old code with 13 errors across the filter, rows, both splits, the
  Account filter and the summary; passes with the fix.
- gofmt -l: clean. go vet for usageapi, provider, gateway, gui on darwin,
  and usageapi, provider on GOOS=linux and windows: clean.
- go test ./internal/usageapi ./internal/usage: ok.
- go test ./internal/provider ./internal/gateway ran at load average
  ~300 with other sessions' suites. Three timing tests went red, and each
  passes 3/3 alone (-count=3 -run): TestCopilotSecretToolUsername
  (#1627, commented), TestOTelFastRequestTranscriptDiscovery (#1811),
  and TestTranslatedStreamKeepsClientAlive (filed as #2169).
  TestUsageOverGateway and the gateway's TestUsage* pass.
- GUI: usage-ledger.test.cjs and usage-ledger-chart.test.cjs in chromium
  and webkit, 52/52 (playwright 1.62.0). app.js is unchanged, since the
  page already shows the name the API sends.

Not tried: the real GUI with a signed-out Claude account.
2026-10-14 18:19:16 +08:00