Files
magpie/internal/provider/migrate_workbuddy.go
T
yetone 5ecb1dc365 provider: moved WorkBuddy subscriptions update to the plugin's 0.1.9, whose chats from Codex and Claude Code pass WorkBuddy's channel check (#182, snzkYuurei on X)
WorkBuddy answered "Illegal API invocation from an unapproved channel" to
Cindy's Codex and Claude Code modes. It matches a few exact phrases anywhere
in a chat (Claude Code's billing header, identity line and gitStatus main
branch line; Codex 0.159.2's first paragraph); workbuddy 0.1.9 rewrites them
to words that pass. Verified with real accounts through Cindy's bundled
Codex 0.159.2 and Claude Code 2.1.280 on workbuddy/glm-5.3-flash and
workbuddy-ai/deepseek-v4.1-flash.
2026-10-06 03:13:02 +08:00

84 lines
2.9 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.9", // 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
}