A provider or group can be routed `free`. Seats whose model the vendor serves at no cost to the allowance or credits go first, in listed order. The rest follow, also in listed order. Free means the vendor's own catalog.Model.Free word, or else a $0 list price on every count (provider.FreeModel). A pool with no free model behaves as In order. routes.Seat gains Free and Strategy gains ByFree. weighRouted works Free out only for a strategy that weighs by it, so other routings never read a model list for it. It is wired through every list a routing appears in: - both save whitelists; - plugins/rotation's Builtin; - app.js's ROUTINGS (appScriptBudget 1,269,000 → 1,271,000 for the description) and the Routing page's options, hints and trace text; - zh-TW, ja and de strings; - the TUI's routings; - the CLI's aliases (free, free-first). Written by keeuu (issue #3054, three commits), squashed ontodee5c9d75and reviewed: - the harm checks were clean; - FreeModel runs only for ByFree, so its Available() walk costs nothing for other routings; - accounts can list different models, so Free first means something for a provider's own accounts too, not only for groups. Run at this head: - gofmt -l: clean. - go vet: darwin (internal/routes, provider, gateway, cli, tui, gui); GOOS=windows ./internal/...; GOOS=linux -tags nogui ./... — all clean. - go test ./internal/routes ./internal/provider -run 'Free|Routing|Strateg|Builtin' ok; ./internal/gateway -run 'FreeFirst|Weigh|Routing' ok. - Broken by hand: with FreeFirst returning paid before free, internal/routes' Free tests and TestFreeFirstGroupSpendsTheFreeMemberFirst go red. Restored, green. - go test ./... -count=1 -timeout 45m, at load average ~460 from other sessions: 62 packages ok, 3 red: - internal/gui TestMainWindowCorners (#1936/#2645, AppKit window killed at its deadline under load); - internal/gateway TestClaudeAccountsSpentFallBackToCodex ("no answer"): ok alone in 46s; - internal/agent timed out at 45m inside TestSnowSmallModel (1s in): the package is ok alone in 1519s. - GUI, both engines (node --test, playwright 1.62.0), 23 files: account-arrange, builtins, context-text, context-scroll-end, context-window, group-member-weight, key-weight, rate-limited-sink, routing-reset-deadline, routing-compaction, routing-key-windows, routing-save, routing-sealed-task, routing-weight-chip, search-keys, i18n-keys, panel-routing-pick, panel-routing-providers, panel-routing, routing-columns, gui-de, gui-ja, gui-zh-tw. 230 of 236 pass. routing-save (the 6/7 counts), routing-columns, i18n-keys and the three language files are green. - account-arrange "every mode" (#2200): red in both engines, alone, and on origin/maindee5c9d75too. - builtins chromium "Plugins › Built-in" (#2960): a 5s wait for the Plugins page. Red alone and ondee5c9d75too; the webkit run checks the new Routing strategies subtitle and passes. - context-window and context-text, single cases in different language/engine pairs on each run: 5s waits under load (#1544, #2900). Untouched by this change. Co-authored-by: keeuu <159448501+keeuu@users.noreply.github.com>
49 lines
1.6 KiB
Go
49 lines
1.6 KiB
Go
// Package rotation is the routings a provider or group can be set to
|
|
// besides Smart: In order, In turn, Least used first, Weekly pace, By
|
|
// weight and Free first. While a provider or group is routed by one, it
|
|
// stays on.
|
|
//
|
|
// It is the first consumer of the gateway's router strategy point (P3 of
|
|
// docs/subsystems/plugin-runtime.md): Apply registers internal/routes'
|
|
// strategies, and off, a pool set to one of them is tried in its listed
|
|
// order and the window offers Smart alone.
|
|
package rotation
|
|
|
|
import (
|
|
"github.com/yetone/magpie/internal/pluginrt"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
"github.com/yetone/magpie/internal/routes"
|
|
)
|
|
|
|
func init() {
|
|
pluginrt.Register(pluginrt.Manifest{
|
|
ID: "rotation", API: "^1", Requires: []string{"providers", "gateway"}, Essential: true,
|
|
Name: "Routing strategies", Sub: "The routings besides Smart: In order, In turn, Least used first, Weekly pace, By weight and Free first",
|
|
One: "1 provider or group routed so", Many: "{n} providers and groups routed so",
|
|
InUse: inUse,
|
|
Parts: []pluginrt.Part{{Slot: "part", Key: "rotation"}},
|
|
Apply: func(c *pluginrt.Ctx) error {
|
|
for name, s := range routes.Builtin {
|
|
c.OnDispose(routes.Register(name, s))
|
|
}
|
|
return nil
|
|
},
|
|
})
|
|
}
|
|
|
|
// inUse counts the providers and groups routed by one of its strategies;
|
|
// a providers.json that can't be read is not known, so it stays on.
|
|
func inUse() (int, error) {
|
|
routings, err := provider.Routings()
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
n := 0
|
|
for _, r := range routings {
|
|
if _, ok := routes.Builtin[r]; ok {
|
|
n++
|
|
}
|
|
}
|
|
return n, nil
|
|
}
|