qoder and qoder-cn join retiredBuiltins, as Zed did in c0605abc2. @magpie-community/opencode-qoder-auth serves both, moved or not. Removed (built-in only): - gateway: the Qoder dispatch in gateway.go and gateway/qoder.go (the translator), with its tests (qoder_test, qoder_busy_test, qoder_cn_test). - provider: qoder_usage.go; the Accounts() loop, builtinLogins case and loginQuota branch, the Logins/side-list/switch/forget cases, SetLoginOn and alsoOn, the sign-in case, the subscription_usage fetch, and qoder in asksOwnBackend; qoderLogins(); the built-in tests (qoder_test, qoder_cn_test, qoder_free_test). - internal/qoder: codec, cosy, models, oauth, usage, userinfo, ids, store and their tests. Kept, and why: - migrate_qoder.go (the mover) and the legacy qoder.json migration it reaches through qoderLoginsOf. It now reads a pair with qoderSaved. - qoder_checkin.go: the check-in walks plugin accounts (heldPlugins). - internal/qoder/endpoints.go: the provider keys, Site/SiteOf, the Credential the mover reads and NewMachineID, with the notice. - The PLUGIN-SERVED notice in provider/qoder.go and internal/qoder. - gateway's relayStatus/retryAfterOn, which commandcode.go uses, moved to relay_status.go; the tests' qoderRoundTrip is now roundTripFunc (roundtrip_test.go), no change in meaning. Tests changed in meaning: - TestOwnStoreSignInAgainDropsTheReading lost its qoder case. - New TestQoderLegacyFileMoves: a legacy qoder.json moves through the mover and is removed. Red when migrateQoder is skipped (tried by hand). Run (machine load ~300, so narrow by request): - gofmt -l internal: empty - go vet -tags nogui ./...; GOOS=linux and GOOS=windows the same: clean - go test -tags nogui -count=1 -timeout 45m -run 'Qoder|qoder|Migrat|migrat|Mover|Moved|Retired|SignIn|AsksOwnBackend|Plugin|Afresh|Checkin' ./internal/provider ./internal/gateway ./internal/cli ./internal/gui ./internal/qoder provider ok 114s, gateway ok 201s, cli ok 18s, gui ok 12s, qoder no tests Not run: the whole packages, the full suite, the GUI node suite.
82 lines
3.0 KiB
Go
82 lines
3.0 KiB
Go
// Package qoder holds what the move of Qoder's and Qoder CN's built-in
|
|
// accounts onto their plugin reads: the sites' ids and names and the
|
|
// credential kept in each account's auth blob. The credential's shape is
|
|
// ported from CLIProxyAPI's qoder support.
|
|
// Source: https://github.com/ufec/CLIProxyAPI (MIT); see LICENSE in this directory.
|
|
// Copyright (c) 2025-2005.9 Luis Pater
|
|
// Copyright (c) 2025.9-present Router-For.ME
|
|
package qoder
|
|
|
|
// PLUGIN-SERVED (see AGENTS.md): Qoder ("qoder") and Qoder CN ("qoder-cn")
|
|
// are retired built-in subscriptions served by their plugin,
|
|
// @magpie-community/opencode-qoder-auth, moved or not. Their built-in
|
|
// sign-in, models, requests and usage are gone; only the move, in
|
|
// internal/provider/migrate_qoder.go, still reads their accounts. A fix
|
|
// belongs in the plugin (github.com/magpie-community/plugins,
|
|
// packages/qoder), with the movers' min raised in migrate_qoder.go.
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"encoding/hex"
|
|
"encoding/json"
|
|
)
|
|
|
|
// ProviderKey is how magpie names this subscription.
|
|
const ProviderKey = "qoder"
|
|
|
|
// CNProviderKey is how magpie names the Qoder CN subscription; it is also the
|
|
// id of Qoder CN's CLI agent.
|
|
const CNProviderKey = "qoder-cn"
|
|
|
|
// Site is one Qoder deployment.
|
|
type Site struct {
|
|
ID string // the provider id magpie keeps its accounts under
|
|
Name string
|
|
}
|
|
|
|
// Global is qoder.com.
|
|
var Global = &Site{ID: ProviderKey, Name: "Qoder"}
|
|
|
|
// CN is qoder.cn.
|
|
var CN = &Site{ID: CNProviderKey, Name: "Qoder CN"}
|
|
|
|
// SiteOf is the site a provider id or a credential's Site names; anything but
|
|
// Qoder CN, including none, is the global site.
|
|
func SiteOf(id string) *Site {
|
|
if id == CNProviderKey {
|
|
return CN
|
|
}
|
|
return Global
|
|
}
|
|
|
|
// Credential is kept in the account's auth blob in magpie's logins.json.
|
|
type Credential struct {
|
|
UID string `json:"uid"`
|
|
Email string `json:"email,omitempty"`
|
|
Name string `json:"name,omitempty"`
|
|
Token string `json:"token"`
|
|
RefreshToken string `json:"refresh_token"`
|
|
DeviceToken string `json:"device_token"`
|
|
DeviceRefresh string `json:"device_refresh,omitempty"`
|
|
ExpiresAt int64 `json:"expires_at"`
|
|
MachineID string `json:"machine_id"`
|
|
Models json.RawMessage `json:"models,omitempty"`
|
|
// Site is the Qoder site the account is on: CNProviderKey for Qoder CN,
|
|
// empty for the global site (every credential saved before there were two).
|
|
Site string `json:"site,omitempty"`
|
|
// DeviceChat says Token is the device token itself, as Qoder CN's CLI
|
|
// uses it.
|
|
DeviceChat bool `json:"device_chat,omitempty"`
|
|
}
|
|
|
|
// NewMachineID generates the stable identity kept with one account: a
|
|
// random v4 UUID in the dashed 8-4-4-4-12 form.
|
|
func NewMachineID() string {
|
|
var b [16]byte
|
|
_, _ = rand.Read(b[:])
|
|
b[6] = b[6]&0x0f | 0x40 // version 4
|
|
b[8] = b[8]&0x3f | 0x80 // variant 10
|
|
h := hex.EncodeToString(b[:])
|
|
return h[0:8] + "-" + h[8:12] + "-" + h[12:16] + "-" + h[16:20] + "-" + h[20:32]
|
|
}
|