Files
magpie/internal/provider/mimo.go
T
yetone 30fcbf684b provider: Xiaomi MiMo's built-in is retired; its plugin serves it
mimo-app joins retiredBuiltins (migrate.go), the way Zed did in
c0605abc2. @magpie-community/opencode-mimo-auth serves sign-in, refresh,
models, requests and usage.

Removed: the built-in's sign-in (mimo_signin.go), its usage fetch
(mimo_usage.go), its tests (mimo_test.go, built-in only), and its
cases in signin.go begin(), logins_on.go (SetLoginOn and alsoOn),
logins.go (Logins, the side list, switch, forget), login_usage.go
(builtinLogins, quota), subscription_usage.go and account.go. MiMo had
no gateway dispatch of its own.

Kept: mimo.go holds the PLUGIN-SERVED notice ("mimo-app" and the
package name, for TestMovedBuiltinsSayTheirPlugin), MiMoID, mimoCreds,
mimoSaved and mimoLogins, which migrate_mimo.go's mover and
migrate_movers_test.go still read. The GUI's MiMo account label stays
for plugin accounts.

Run in this worktree:
  gofmt -l internal                                  (nothing)
  go vet -tags nogui ./internal/provider ./internal/gateway
    ./internal/cli ./internal/gui                    ok; also GOOS=linux,
                                                     GOOS=windows: ok
  go test -tags nogui -count=1 -run 'MiMo|Mimo|Migrat|Move|Moved|
    Retired|LoopbackSignIns|AsksOwnBackend|Mover|SayTheirPlugin'
    ./internal/provider ./internal/gateway ./internal/cli ./internal/gui
                                                     ok (all four)
Not run: whole packages, the full suite, the GUI node suite (machine
load ~300).
2026-10-17 23:11:00 +08:00

63 lines
2.0 KiB
Go

package provider
// PLUGIN-SERVED (see AGENTS.md): Xiaomi MiMo ("mimo-app") is a retired
// built-in subscription, served by its plugin alone,
// @magpie-community/opencode-mimo-auth (provider.BuiltinRetired). Its
// sign-in, models, requests and usage are the plugin's; all that is left
// here is reading the accounts signed in to the built-in, for the move onto
// the plugin (migrate_mimo.go). A fix belongs in the plugin
// (github.com/magpie-community/plugins, packages/mimo), with the mover's min
// raised in internal/provider/migrate_mimo.go.
import (
"encoding/json"
"time"
)
// MiMoID is the MiMo subscription's id, as a provider and in logins.json.
const MiMoID = "mimo-app"
// mimoCreds is what a MiMo sign-in leaves: the Xiaomi account's id and
// passToken (which signs it on again), the device id they were issued to,
// the MiMo server it is served at and the session cookies that server set,
// and when those were set.
type mimoCreds struct {
UserID string `json:"userId"`
CUserID string `json:"cUserId,omitempty"`
PassToken string `json:"passToken"`
DeviceID string `json:"deviceId"`
Region string `json:"region,omitempty"`
Base string `json:"base"`
Cookies map[string]string `json:"cookies,omitempty"`
Issued time.Time `json:"issued"`
Name string `json:"name,omitempty"`
}
func mimoSaved(l savedLogin) (mimoCreds, bool) {
var c mimoCreds
if json.Unmarshal(l.Auth, &c) != nil || c.UserID == "" || c.PassToken == "" || c.Base == "" {
return mimoCreds{}, false
}
return c, true
}
type mimoLogin struct {
Login
creds mimoCreds
}
// mimoLogins is every MiMo account signed in, the one in use first.
func mimoLogins() []mimoLogin {
var out []mimoLogin
for _, l := range sideLogins(MiMoID, "", func(l savedLogin) bool {
_, ok := mimoSaved(l)
return ok
}) {
c, _ := mimoSaved(l.saved)
a := mimoLogin{Login: l.Login, creds: c}
a.Lapsed = l.saved.Lapsed
out = append(out, a)
}
return out
}