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 fromf49f6ba68onto origin/main6b8134430. plan-credits (36/36) and the Budget|PlanCredits Go tests ran again at the rebased tree: ok. vet and the other GUI files ran onf49f6ba68. 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.
37 lines
1.8 KiB
Go
37 lines
1.8 KiB
Go
package gateway
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
// WorkBuddy served by its plugin keeps the credits a reply said on its
|
|
// row, however the agent asked: chat, Messages or Responses, streamed or
|
|
// whole, translated to WorkBuddy's chat stream (jiabubu on Discord: a
|
|
// request's credits should be said on its row). TestPlanCreditsReachTheLedger
|
|
// holds a provider of its own to it; this is the plugin host's way.
|
|
func TestPluginPlanCreditsReachTheLedger(t *testing.T) {
|
|
stream := sse(`data: {"id":"c","model":"fake-1","choices":[{"index":0,"delta":{"content":"hi"}}]}`,
|
|
`data: {"id":"c","model":"fake-1","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],`+wbCreditUsage+`}`, "data: [DONE]")
|
|
for _, c := range []struct{ name, path, body string }{
|
|
{"chat stream", "/v1/chat/completions", `{"model":"workbuddy-ai/fake-1","stream":true,"messages":[{"role":"user","content":"hi"}]}`},
|
|
{"chat whole", "/v1/chat/completions", `{"model":"workbuddy-ai/fake-1","messages":[{"role":"user","content":"hi"}]}`},
|
|
{"messages", "/v1/messages", `{"model":"workbuddy-ai/fake-1","max_tokens":10,"stream":true,"messages":[{"role":"user","content":"hi"}]}`},
|
|
{"messages whole", "/v1/messages", `{"model":"workbuddy-ai/fake-1","max_tokens":10,"messages":[{"role":"user","content":"hi"}]}`},
|
|
{"responses", "/v1/responses", `{"model":"workbuddy-ai/fake-1","stream":true,"input":"hi"}`},
|
|
{"responses whole", "/v1/responses", `{"model":"workbuddy-ai/fake-1","input":"hi"}`},
|
|
} {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
f := &fake{t: t, reply: stream}
|
|
movedFake(t, "workbuddy-ai", f)
|
|
code, body := postTo(t, New(), c.path, c.body)
|
|
if code != 200 {
|
|
t.Fatalf("%d %s", code, body)
|
|
}
|
|
r := lastUsage(t)
|
|
if r.Credits == nil || *r.Credits != 0.01 {
|
|
t.Fatalf("%s %s: credits %v, want 0.01", r.Provider, r.Endpoint, r.Credits)
|
|
}
|
|
})
|
|
}
|
|
}
|