An enterprise seat's /billing/meter/get-user-resource-summary answers with
no packages, so the card showed no quota. WorkBuddy's own usage page reads
/billing/meter/get-enterprise-user-usage (credit / limitNum, with the cycle's
start and reset in Beijing time). When the summary gives no credits, wbQuota
now asks that meter and shows a Credits window ("196.13 / 2000", resetting at
cycleResetTime). A personal account's refusal there (400 10001 "uid or
enterpriseID is empty", seen on a real WorkBuddy AI Pro account on
2026-10-13) is ignored and the card stays as before. A paid account with
packages never asks it.
Moved users get the same from @magpie-community/opencode-workbuddy-auth
0.1.19 (plugins 169e4e6, on npm); the mover's min is raised to 0.1.19.
Run: workbuddy_enterprise_test.go, built from the reporter's literal
response bytes. TestWorkBuddyEnterpriseCredits and
TestWorkBuddyPersonalNotEnterprise pass, and both fail with the fallback
taken out. go test -run TestWorkBuddy ./internal/provider passes. Not tried
with a real enterprise account; "credit" is read as used, which the
reporter is asked to confirm.
Also run, rebased on e1b70c13d: go test -tags nogui ./internal/provider
(the whole package, 430s) and go test ./internal/gateway -run WorkBuddy
pass under a sandbox HOME; gofmt clean; go vet for darwin, linux and
windows (-tags nogui) pass. The reporter's follow-up (04:27Z) saw
"Credits 218.67 / 2000" on the same enterprise account after reinstalling,
while get-user-resource-summary still answered empty Packages: the
reinstall installed the plugin's 0.1.19, which carries this fallback.
84 lines
4.2 KiB
Go
84 lines
4.2 KiB
Go
package provider
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"time"
|
|
)
|
|
|
|
// WorkBuddy's and WorkBuddy AI's accounts on
|
|
// @magpie-community/opencode-workbuddy-auth (one package, a provider for
|
|
// each build). The desktop app's own sign-in goes as a marker ({source:
|
|
// "desktop"}, the package from 0.1.1 on): the plugin reads the app's file
|
|
// on each request, as the built-in does, so no refresh token is held by
|
|
// both. An account magpie signed in goes whole.
|
|
func init() {
|
|
for _, w := range []*wbSite{wbCN, wbAI} {
|
|
movers[w.id] = &mover{
|
|
pkg: "@magpie-community/opencode-workbuddy-auth",
|
|
min: "0.1.19", // an enterprise account's card shows its credits, from the enterprise meter WorkBuddy's usage page reads (#1904); 0.1.18: WorkBuddy 5.6+ keeps its desktop sign-in encrypted, and the plugin says so and points to the browser sign-in instead of a 502 (plugins #18); 0.1.17: a restricted account's 403 11140 ends in provider.WBRestrictedHint, so it rests 2h as restricted (#1849); 0.1.16: WorkBuddy AI's GLM models are text-only, so magpie's image-describing model reads their images (Yirasumi on Discord); 0.1.15: a system prompt sent as a developer message passes the channel check, an object tool_choice is sent as WorkBuddy takes it, and max_completion_tokens goes as max_tokens so the cap holds (plugins #96); 0.1.14: the Credits window says when the soonest credits left run out, for Smart routing to spend them first (cdredfox on X); an enterprise account names its enterprise, so it lists and uses the enterprise's models, not the personal plan's (plugins #75); a chat's tools get shapes WorkBuddy AI's models take, so ZCode's and DeepSeek Harness's chats on deepseek-v4.1-flash aren't 400 "Invalid request parameters" (wyh on Discord); one user send is one request in the usage list: every step carries one X-Conversation-Request-ID, and both builds name the client (使用端) (plugins #48); credits used up (code 14018) say so, with the nested error message (plugins #25); Codex's and Claude Code's chats pass WorkBuddy's channel check (#182); a failure's status and its sign-in mark as the built-in's; each model's credit rate; the sign-in renewed ahead of time through auth.refresh; the credits' count beside their share (#659)
|
|
agents: []string{w.id},
|
|
out: func() ([]Moving, error) {
|
|
var out []Moving
|
|
for _, a := range wbLogins(w) {
|
|
m := Moving{User: a.User, First: a.Active, On: a.On, Lapsed: a.Lapsed != "", Own: a.own, Plan: a.Plan}
|
|
if a.own {
|
|
m.Auth = map[string]any{"type": "oauth", "source": "desktop", "access": "", "refresh": "", "expires": 0,
|
|
"accountId": a.User, "uid": a.creds.UID}
|
|
} else {
|
|
c := a.creds
|
|
m.Auth = map[string]any{"type": "oauth", "access": c.Access, "refresh": c.Refresh, "expires": c.ExpiresAt,
|
|
"accountId": a.User, "uid": c.UID, "domain": c.Domain}
|
|
if c.RefreshExpiresAt > 0 {
|
|
m.Auth["refreshExpiresAt"] = c.RefreshExpiresAt
|
|
}
|
|
if c.TokenType != "" {
|
|
m.Auth["tokenType"] = c.TokenType
|
|
}
|
|
}
|
|
out = append(out, m)
|
|
}
|
|
return out, nil
|
|
},
|
|
back: func(ls []savedLogin, user string, auth map[string]any) ([]savedLogin, string, error) {
|
|
if str(auth["source"]) != "" {
|
|
// the desktop app's: nothing of it was the plugin's
|
|
return ls, firstNonEmpty(user, str(auth["accountId"])), nil
|
|
}
|
|
c := wbCreds{UID: str(auth["uid"]), Access: str(auth["access"]), Refresh: str(auth["refresh"]),
|
|
ExpiresAt: msOf(auth["expires"]), RefreshExpiresAt: msOf(auth["refreshExpiresAt"]),
|
|
Domain: str(auth["domain"]), TokenType: str(auth["tokenType"])}
|
|
if c.UID == "" || c.Access == "" {
|
|
return ls, "", errors.New(w.name + ": an unreadable plugin sign-in")
|
|
}
|
|
if user == "" {
|
|
user = str(auth["accountId"])
|
|
}
|
|
i := backInto(&ls, w.id, user)
|
|
b, err := json.Marshal(c)
|
|
if err != nil {
|
|
return ls, "", err
|
|
}
|
|
ls[i].Auth, ls[i].Lapsed, ls[i].Seen = b, "", time.Now().UTC().Truncate(time.Second)
|
|
wbTokens.Lock()
|
|
delete(wbTokens.m, w.id+"|"+c.UID)
|
|
wbTokens.Unlock()
|
|
return ls, ls[i].User, nil
|
|
},
|
|
}
|
|
}
|
|
}
|
|
|
|
// msOf is a time in unix ms as JSON gave it.
|
|
func msOf(v any) int64 {
|
|
switch n := v.(type) {
|
|
case float64:
|
|
return int64(n)
|
|
case int64:
|
|
return n
|
|
case int:
|
|
return int64(n)
|
|
}
|
|
return 0
|
|
}
|