gateway: a fast pick can be sent as Ultrafast where the account offers it (#1954)
zhenghaowen0967 asked for an agent's fast pick of a ChatGPT model to go as
Codex's Ultrafast without the client asking for it. settings.UltraPicks
holds the agent's fast picks that are set to Ultrafast; each one is in
FastPicks too.
- The gateway marks those candidates `ultra` in fastPick.
- On Chat and Responses, a try sends service_tier "ultrafast".
- From Messages, a try carries withUltra to forwardTranslated, which
sets Request.Ultrafast for the ChatGPT backend.
- In every case, the #1784 check decides the account. One whose list
doesn't offer Ultrafast goes after a mate that does (tierMate). With
no mate left, it is sent priority.
- That check now covers Chat as well as Responses.
- Sibling fix: chat.go dropped a Chat client's own service_tier
"ultrafast" (Fast was false, Ultrafast unset). It now parses as
Responses does.
- provider: SetFastTier (""/priority/ultrafast) behind SetFastPick.
CanUltra and UltraModels say whether one of Codex's accounts lists
Ultrafast on the model. UltraPicks follow a provider rename
(renameModelPrefs) and survive a GUI settings save.
- GUI: an option gets ultraOk/ultra. Where ultraOk is set, the bolt in
the picker steps usual -> Fast -> Ultrafast -> usual, as a camera's
flash button steps its modes. Ultrafast shows two overlapped bolts, in
the row and after the field's model. Tooltips and the status line are
in en, zh, zh-TW, ja and de. POST /api/agent-fast takes `ultra`.
- No `:ultrafast` suffix for routing groups yet.
Tests, each broken by hand and seen red:
- TestUltraPickSentUltrafast covers omp/Responses with no tier asked
(acct-pro:ultrafast), the Pro account out (then acct-plus:priority),
another agent unchanged, opencode/Chat and claude/Messages picks, a
Chat client's own ultrafast, and switching back to Fast or off.
- Red with ultra forced false (4 cases).
- Red without withUltra (claude went priority).
- Red without the chat.go parse (2 cases).
- TestSetFastPick: red without UltraPicks in renameModelPrefs.
- TestSettingsSaveKeepsWhatItDoesNotSend: red without the api.go carry.
- fast-ultra.test.cjs (en zh ja de, window and 440px panel): red (9/9)
without the Ultrafast step.
Run (vet, gofmt, GUI and full suite at base 8b84dc902; the reruns
below at a rebase onto 6b3ee5a03 and then onto 63be47717 origin/main):
- gofmt -l: clean.
- go vet -tags nogui ./... for darwin, linux and windows: clean.
- GUI, chromium + webkit: fast-ultra, fast-pick, group-member-fast,
i18n-keys, model-pick and 14 other agent-model/picker files. 197/197
pass.
- Full suite: set -o pipefail; go test -timeout 45m ./... (sandbox
HOME, macOS, 3 other sessions' suites running at the same time):
every package ok except two.
- internal/gateway: TestMaxRPMGroupPrefersMemberWithRoom hit its fixed
1s bar (1.126s) under load. It passes 5/5 alone (-count=5). Filed
as #2520.
- internal/gui: TestPanelJoinsFullScreenSpaces, red on macOS 26.2 on
main already, filed as #2450.
- Rerun of internal/gateway and internal/library after the rebase onto
6b3ee5a03 (both packages changed upstream), -timeout 60m, load
average ~290: library ok. gateway hit the 60m timeout (the test
running, TestPauseByFolder, was 13s in) and
TestQueueRefusalIsInTheUsageLedger saw b's 1s queue timeout as a
second 429. Filed as #2541. TestQueueRefusalIsInTheUsageLedger,
TestPauseByFolder and TestUltraPickSentUltrafast, -count=5 at this
head: ok.
- At the 63be47717 rebase: gofmt clean; vet darwin/linux/windows clean.
internal/provider ok, internal/settings ok. internal/agent hit the
45m timeout under load ~295 (in TestCursorLocalEffort, at 0s), so
this is not a green for that package. Its -run
"Fast|Option|Models|Picker|Cursor|Codex" subset, run through the
shared 3-slot queue, was ok in 794s. The whole package is left to
CI's Test run.
Not tried: a real Pro account's Ultrafast. The fake ChatGPT backend's
model lists offer it on one account only.
This commit is contained in:
+2
-1
@@ -322,7 +322,8 @@ handed on, and isn't counted as a request. The CSV's last columns are
|
||||
`tries` (on the final row, when the request took more than one),
|
||||
`handed_on`, then `tier_asked`, `tier_sent` and `tier_served`: the
|
||||
service tier the client asked for (Claude's fast speed reads `fast`), the
|
||||
one that try went out at (a fast pick sends `priority`; Ultrafast becomes
|
||||
one that try went out at (a fast pick sends `priority`, or `ultrafast`
|
||||
where the pick is set to Ultrafast; Ultrafast becomes
|
||||
`priority` on an account whose plan doesn't offer it), and the one the
|
||||
vendor's reply said it ran at, empty when the reply doesn't say. The JSON
|
||||
log keeps them as `tier_asked`, `tier_sent` and `tier_served`, and each
|
||||
|
||||
@@ -101,6 +101,7 @@ recorded as a prediction failure (`noPrediction`).
|
||||
- A refusal that comes as an error (#2400, Jichao). An error whose own `message` is, whole, `The request was rejected because it was considered high risk` is a refusal with no code beside it (`highRiskRefusal` in `policyRefusal`): in an HTTP error body or a stream's error event, never in an answer's text, which may quote it. The vendor that sends it isn't known; it says the request was turned away, so it goes to the next candidate under `RefusalRetries` like any refusal and rests nobody. A refusal error event before any content ends the try at once (`eventRefusalError`, `stop` as for any error), so an upstream that keeps the stream open doesn't hold the next candidate back; a refusal's stop or finish marker is still read to the end for the usage and terminator after it. After content, every write is read for a late refusal (`refusalAfter`), so one whose `event: error` name and data come in separate writes is still noted, and nothing is replayed. `TestHighRisk*`, `TestRefusalErrorDoesNotWaitForEOF` in [`refusal_error_test.go`](../../internal/gateway/refusal_error_test.go).
|
||||
- A request is one usage record, counted once by how it ended (小一 on Discord: Codex on credits showed "5,482 · 1,094 failed" while rows said "2 tries/3 tries" and had been answered). The final record carries `tries` when the route took more than one (`rec.Tries`, from the trace's `Tries`). A try a vendor refused or turned away (`hw.refused`, `hw.turnedAway`) still writes its own record, for what it billed and why it failed, marked `handed_on`; `usage.Totals.count` skips such a record for calls and failures. A request failed only when the agent got an error (`LostRequest`); one answered after a failed try is counted beside it as answered on a retry (`Totals.Retried`, `RetriedRequest`, the `retried` filter). Logs written before `handed_on` are read the same way: the log index marks a failed, non-rejected record followed by another of the same route id as handed on (`routeRows` in [`log_index.go`](../../internal/usage/log_index.go)). Counts by account or route (`vias`, window holds) still count every try. A turn relayed on Codex's own ChatGPT sign-in is recorded as that codex account (`codexServed` in [`codex_backend.go`](../../internal/gateway/codex_backend.go)), so the account card's window counts it; the Routing view still names the seat OpenAI, an API-key call stays `openai` with no account, as does one whose `chatgpt-account-id` isn't the account Codex's auth.json here is signed in to (a Codex in WSL or under another `CODEX_HOME`), and a row already written without an account is left as it is. Those relay rows are still not a lead's answerer (`loggedAnswers`, #1367); a row an account answered, its host `host as email`, still is.
|
||||
- Each record keeps the service tier three ways (#1784): `tier_asked` is what the client's body asked (`bodyTier`; Claude's speed fast reads `fast`), `tier_sent` is what that try's last request went out with, noted in `forwardOnce` after every rewrite (fast picks, Ultrafast to priority on a plan without it) onto the per-attempt `wireAt`, and `tier_served` is only what the reply said it ran at (`upstreamTier`, read by the sniffer and the translated readers), empty when it says nothing. The route's tries carry `tier` and `tier_served` the same way. A bridge that doesn't go through `forwardOnce` (the Claude subscription, Cursor's built-in) leaves `tier_sent` empty. Code: [`tier_record.go`](../../internal/gateway/tier_record.go).
|
||||
- An agent's fast pick (`settings.FastPicks`, the bolt in its picker, #954) may also be in `settings.UltraPicks` (#1954), offered by the GUI only where one of Codex's accounts lists Ultrafast on the model (`provider.CanUltra`, `UltraModels`). `fastPick` marks its candidates `ultra`; a try of one goes with `service_tier: "ultrafast"` on Chat and Responses, and an agent on Messages carries it in the context (`withUltra`) to `forwardTranslated`, which sets `Request.Ultrafast` for the ChatGPT backend. Either way the same check as a client's own Ultrafast ask applies, now on Chat as well as Responses: an account whose list doesn't offer it is put after a mate that does (`tierMate`), or, with none left, sent `priority`. A Chat body's own `service_tier: "ultrafast"` is parsed as Ultrafast too (`chat.go`). `TestUltraPickSentUltrafast`.
|
||||
- A usage record carries its prompt's cache beside `in` and `out` (#1839): `cache_read` (tokens read from the vendor's cache) and `cache_write` (cache creation, Anthropic's `cache_creation_input_tokens`; `cache_write_1h` the part written for an hour). `in` holds neither. Both are written on every record, 0 too, so a prompt that missed the cache reads as that. A record from before then has neither and reads as 0. Every route fills them: Anthropic's messages, Chat (OpenAI's `prompt_tokens_details.cached_tokens`, DeepSeek's `prompt_cache_hit_tokens`), Responses (`input_tokens_details.cached_tokens`) and Gemini (`cachedContentTokenCount`), passed through or translated, whole or streamed, a plugin's fetch, and the Claude subscription bridge. System One's decision calls report no cache. `TestUsageRecordsCacheTokensOnEveryRoute`, `TestPluginUsageRecordsCacheTokens`, `TestClaudeSubscriptionUsageKeepsCacheTokens`, `TestRecordAlwaysCarriesCacheTokens`.
|
||||
- A request whose key is a Claude sign-in (`claudeSignIn`: `Authorization: Bearer sk-ant-oat…`, Claude Code signed in to claude.ai with magpie as its base URL) is never told a 401, nor a 403 saying "OAuth token has been revoked". magpie never passes that sign-in on, so such an answer is a provider refusing magpie's credential, or one of magpie's own Claude accounts lapsing; told it, Claude Code renews its own sign-in before each of its retries (ten for one request) and then asks to `/login`. Any error whose message mentions x-api-key, whatever its status, Claude Code tells as "Not logged in · Please run /login" too. It is told as a 502 in magpie's words, an `api_error` saying "<provider> refused magpie's credential (HTTP 401): …" with x-api-key said as "API key", and any other error such a request is told keeps its status with x-api-key said as "API key", as does a stream's error after its 200 (`keepsSignIn`, `claude_signin.go`). Recent calls and the usage log keep the provider's status and message. Any other 403, and a request with magpie's key or an API key, is answered as before. The sign-in's beta (`oauth-…` in `anthropic-beta`) isn't passed on either (`askedBetas`), so a provider gets the request as Claude Code with magpie's key sends it; a provider's own `header.anthropic-beta` still goes.
|
||||
- A 2xx that can't be an API's answer is the 502 it stands for (`notAnAPIReply`, #1012): a web page (`text/html`, or a body that begins as one: a sign-in page, Cloudflare's challenge), a body with nothing in it, or one sent as JSON that doesn't begin as JSON. Every upstream request goes through it (`forwardOnce`, and the built-in clients' own: the ChatGPT backend's `/responses`, Kiro, Zed, Qoder, Devin, Cursor, Command Code), so it fails over, rests and is logged as a 502 does, its reason naming the page's title. Only the first bytes are peeked, which a stream waits for anyway, and a compressed body is left as it came.
|
||||
|
||||
@@ -70,6 +70,11 @@ type Option struct {
|
||||
// by its address (provider.OwnFast, #1615), asked for there as OpenAI's
|
||||
// priority, which the provider may or may not serve
|
||||
OwnFast bool `json:"ownFast,omitempty"`
|
||||
// UltraOK: an account offers the model as Ultrafast (provider.CanUltra,
|
||||
// #1954), so the fast switch has a third setting; Ultra is whether it
|
||||
// is on (provider.IsUltraPick)
|
||||
UltraOK bool `json:"ultraOk,omitempty"`
|
||||
Ultra bool `json:"ultra,omitempty"`
|
||||
|
||||
// own: served on the agent's own sign-in (viaMagpie), for Same
|
||||
own bool
|
||||
|
||||
@@ -68,7 +68,8 @@ func viaMagpie(agent, prefix string) []Option {
|
||||
}
|
||||
return u
|
||||
}
|
||||
fast := provider.FastPicks(agent)
|
||||
fast, ultra := provider.FastPicks(agent), provider.UltraPicks(agent)
|
||||
var tiered map[string]bool // provider.UltraModels, read at the first fast model
|
||||
for _, e := range shown {
|
||||
if e.Group != "" {
|
||||
groups = append(groups, Option{Value: prefix + e.ID, Label: e.Name, Note: "routing group · via magpie",
|
||||
@@ -86,6 +87,12 @@ func viaMagpie(agent, prefix string) []Option {
|
||||
if provider.CanFast(e.Provider, e.Model) {
|
||||
o.FastFor, o.Fast = agent, slices.Contains(fast, e.ID)
|
||||
o.OwnFast = provider.OwnFast(e.Provider, e.Model)
|
||||
if tiered == nil {
|
||||
tiered = provider.UltraModels()
|
||||
}
|
||||
if provider.UltraOn(e.Provider, e.Model, tiered) {
|
||||
o.UltraOK, o.Ultra = true, o.Fast && slices.Contains(ultra, e.ID)
|
||||
}
|
||||
}
|
||||
out = append(out, o)
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ func parseChat(body []byte) (*Request, error) {
|
||||
return nil, fmt.Errorf("invalid request: %v", err)
|
||||
}
|
||||
r := &Request{Model: c.Model, MaxTokens: c.MaxCompletionTokens, Temp: c.Temperature, TopP: c.TopP,
|
||||
Stream: c.Stream, Effort: effortOf(c.ReasoningEffort), Parallel: c.ParallelToolCalls, Fast: c.ServiceTier == "priority", Tier: c.ServiceTier,
|
||||
Stream: c.Stream, Effort: effortOf(c.ReasoningEffort), Parallel: c.ParallelToolCalls, Fast: c.ServiceTier == "priority" || c.ServiceTier == "ultrafast", Ultrafast: c.ServiceTier == "ultrafast", Tier: c.ServiceTier,
|
||||
CacheKey: c.PromptCacheKey, Format: openAIFormat(c.ResponseFormat), AccessPrograms: c.AccessPrograms}
|
||||
if r.MaxTokens == 0 {
|
||||
r.MaxTokens = c.MaxTokens
|
||||
|
||||
@@ -44,8 +44,8 @@ type candidate struct {
|
||||
// ("provider/model:low"); "" for one that follows the agent or the group
|
||||
effort string
|
||||
// fast is set on a member the group sends in its vendor's fast mode
|
||||
// (Group.Fast)
|
||||
fast bool
|
||||
// (Group.Fast); ultra on an agent's fast pick sent Ultrafast (#1954)
|
||||
fast, ultra bool
|
||||
// rank is its place in its provider's own list of accounts or keys,
|
||||
// the order the provider's page shows and a drag sets (#217)
|
||||
rank int
|
||||
|
||||
@@ -1939,7 +1939,7 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Pro
|
||||
// the agent's pick of it is sent in its vendor's fast mode
|
||||
// (#954), as a group's member may be; its fallbacks, other
|
||||
// models, go as they are
|
||||
fastPick(cands, pl, p.ID, model)
|
||||
fastPick(cands, pl, p.ID, model, provider.IsUltraPick(agent, p.ID+"/"+model))
|
||||
}
|
||||
}
|
||||
agentPick := provider.AgentEffort(agent)
|
||||
@@ -2447,6 +2447,12 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Pro
|
||||
// forwardTranslated)
|
||||
attemptBody = withFast(from, attemptBody)
|
||||
}
|
||||
// a pick sent Ultrafast (#1954) asks for it in OpenAI's words; in
|
||||
// Claude's, which have none, the try carries it (withUltra)
|
||||
ultra := fast && c.ultra && !ownFast
|
||||
if ultra && (from == provider.Chat || from == provider.Responses) {
|
||||
attemptBody = withFields(attemptBody, map[string]any{"service_tier": "ultrafast"})
|
||||
}
|
||||
// a member known not to think is sent no reasoning ask (#950): the
|
||||
// group reasons for the members that do, and asking one that can't
|
||||
// is what some vendors turn away with a 400. Every other field goes
|
||||
@@ -2480,8 +2486,10 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Pro
|
||||
}
|
||||
// Ultrafast goes first to an account whose plan offers it, and an
|
||||
// account whose own list doesn't is asked for priority (Fast)
|
||||
// instead, which every plan with Fast takes (yxinyu715 on X)
|
||||
if from == provider.Responses && askedTier(attemptBody) == "ultrafast" && !takesTier(c, "ultrafast") {
|
||||
// instead, which every plan with Fast takes (yxinyu715 on X): asked
|
||||
// by the client in either of OpenAI's APIs, or by a pick (#1954)
|
||||
openAI := from == provider.Chat || from == provider.Responses
|
||||
if (openAI && askedTier(attemptBody) == "ultrafast" || ultra && from == provider.Anthropic) && !takesTier(c, "ultrafast") {
|
||||
if j := tierMate(cands[i+1:], c, "ultrafast"); j >= 0 {
|
||||
j += i + 1
|
||||
cs := slices.Clone(cands)
|
||||
@@ -2489,7 +2497,10 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Pro
|
||||
i--
|
||||
continue
|
||||
}
|
||||
attemptBody = withFields(attemptBody, map[string]any{"service_tier": "priority"})
|
||||
if openAI {
|
||||
attemptBody = withFields(attemptBody, map[string]any{"service_tier": "priority"})
|
||||
}
|
||||
ultra = false
|
||||
}
|
||||
// an effort changed mid-thread goes as an update in the history,
|
||||
// which keeps the prompt the upstream cached (#617)
|
||||
@@ -2537,6 +2548,9 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Pro
|
||||
if ownFast {
|
||||
ctx = withOwnFast(ctx)
|
||||
}
|
||||
if ultra && from == provider.Anthropic {
|
||||
ctx = withUltra(ctx)
|
||||
}
|
||||
hw.stop = stop
|
||||
if autoPicks(c) {
|
||||
// the reply names the pick it went as last (#256: it
|
||||
@@ -4826,6 +4840,13 @@ func (s *Server) forwardTranslated(ctx context.Context, p provider.Provider, to
|
||||
r := *req
|
||||
r.Tier, req = "priority", &r
|
||||
}
|
||||
// a pick sent Ultrafast from an agent on Claude's API, whose words
|
||||
// for it are speed "fast" (#1954): on the ChatGPT backend alone
|
||||
// (buildResponses)
|
||||
if req.Fast && !req.Ultrafast && isUltra(ctx) && to == provider.Responses {
|
||||
r := *req
|
||||
r.Ultrafast, req = true, &r
|
||||
}
|
||||
// Anthropic's API needs a reply limit: one the client didn't name
|
||||
// is the model's own, not a flat 16384 (#1792, askedOutput)
|
||||
if to == provider.Anthropic && req.MaxTokens <= 0 {
|
||||
|
||||
@@ -34,11 +34,12 @@ func withFast(proto provider.Protocol, body []byte) []byte {
|
||||
}
|
||||
|
||||
// fastPick sends the model an agent picked to be sent fast (#954) so:
|
||||
// every account and key of it, not a fallback to another.
|
||||
func fastPick(cands []candidate, pl planned, providerID, model string) {
|
||||
// every account and key of it, not a fallback to another. Ultra sends it
|
||||
// as Ultrafast where the account offers that (#1954).
|
||||
func fastPick(cands []candidate, pl planned, providerID, model string, ultra bool) {
|
||||
for i, c := range cands {
|
||||
if c.p.ID == providerID && c.model == model {
|
||||
cands[i].fast = true
|
||||
cands[i].fast, cands[i].ultra = true, ultra
|
||||
}
|
||||
}
|
||||
for _, ws := range [][]Weighed{pl.order, pl.left} {
|
||||
@@ -65,3 +66,17 @@ func isOwnFast(ctx context.Context) bool {
|
||||
v, _ := ctx.Value(ownFastKey{}).(bool)
|
||||
return v
|
||||
}
|
||||
|
||||
// ultraKey marks a try of a pick sent Ultrafast (#1954) from an agent on
|
||||
// Claude's API: its speed "fast" goes to the ChatGPT backend as Ultrafast
|
||||
// (forwardTranslated), on an account that offers it.
|
||||
type ultraKey struct{}
|
||||
|
||||
func withUltra(ctx context.Context) context.Context {
|
||||
return context.WithValue(ctx, ultraKey{}, true)
|
||||
}
|
||||
|
||||
func isUltra(ctx context.Context) bool {
|
||||
v, _ := ctx.Value(ultraKey{}).(bool)
|
||||
return v
|
||||
}
|
||||
|
||||
@@ -315,3 +315,87 @@ func TestTierRecordedPerTry(t *testing.T) {
|
||||
t.Fatalf("codex: %d %+v", rec.Code, recs[len(recs)-1])
|
||||
}
|
||||
}
|
||||
|
||||
// #1954, zhenghaowen0967: a fast pick switched to Ultrafast is asked for
|
||||
// Ultrafast without the client saying a tier, first of the account that
|
||||
// offers it, and for priority of one that doesn't when that one can't
|
||||
// answer; whatever API the agent spoke. Another agent's requests go as
|
||||
// they did, and a Chat client's own Ultrafast ask is kept too.
|
||||
func TestUltraPickSentUltrafast(t *testing.T) {
|
||||
proOut := false
|
||||
tried := tierAccounts(t, &proOut, nil)
|
||||
to, _ := url.Parse(provider.CodexBase)
|
||||
provider.CodexBase = "https://chatgpt.com/backend-api/codex"
|
||||
s := New()
|
||||
s.client = &http.Client{Transport: qoderRoundTrip(func(r *http.Request) (*http.Response, error) {
|
||||
r.URL.Scheme, r.URL.Host = to.Scheme, to.Host
|
||||
return http.DefaultTransport.RoundTrip(r)
|
||||
})}
|
||||
if !provider.UltraModels()["gpt-6-luna"] {
|
||||
t.Fatal("the Pro account's Ultrafast not seen")
|
||||
}
|
||||
if err := provider.SetFastTier("omp", "codex/gpt-6-luna", "ultrafast"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !provider.IsFastPick("omp", "codex/gpt-6-luna") || !provider.IsUltraPick("omp", "codex/gpt-6-luna") {
|
||||
t.Fatal("not picked")
|
||||
}
|
||||
send := func(agent, path, body string) string {
|
||||
t.Helper()
|
||||
r := postFrom(t, s, agent, path, body)
|
||||
if len(r.Tries) == 0 {
|
||||
t.Errorf("%s: no tries", agent)
|
||||
}
|
||||
return strings.Join(tried(), ",")
|
||||
}
|
||||
responses := `{"model":"codex/gpt-6-luna","input":"ping"}`
|
||||
if got := send("omp", "/v1/responses", responses); got != "acct-pro:ultrafast" {
|
||||
t.Errorf("omp: tried %s", got)
|
||||
}
|
||||
proOut = true
|
||||
if got := send("omp", "/v1/responses", responses); got != "acct-pro:ultrafast,acct-plus:priority" {
|
||||
t.Errorf("pro out: tried %s", got)
|
||||
}
|
||||
proOut = false
|
||||
if got := send("opencode", "/v1/responses", responses); got != "acct-plus:" {
|
||||
t.Errorf("another agent: tried %s", got)
|
||||
}
|
||||
|
||||
chat := `{"model":"codex/gpt-6-luna","messages":[{"role":"user","content":"ping"}]}`
|
||||
messages := `{"model":"codex/gpt-6-luna","max_tokens":64,"messages":[{"role":"user","content":"ping"}]}`
|
||||
for _, a := range []struct{ agent, path, body string }{
|
||||
{"opencode", "/v1/chat/completions", chat},
|
||||
{"claude", "/v1/messages", messages},
|
||||
} {
|
||||
if err := provider.SetFastTier(a.agent, "codex/gpt-6-luna", "ultrafast"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := send(a.agent, a.path, a.body); got != "acct-pro:ultrafast" {
|
||||
t.Errorf("%s: tried %s", a.agent, got)
|
||||
}
|
||||
// switched back to Fast, it is priority on the first account
|
||||
if err := provider.SetFastPick(a.agent, "codex/gpt-6-luna", true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if provider.IsUltraPick(a.agent, "codex/gpt-6-luna") {
|
||||
t.Errorf("%s: still Ultrafast", a.agent)
|
||||
}
|
||||
if got := send(a.agent, a.path, a.body); got != "acct-plus:priority" {
|
||||
t.Errorf("%s fast: tried %s", a.agent, got)
|
||||
}
|
||||
}
|
||||
// a Chat client's own Ultrafast, not switched in the picker
|
||||
if got := send("cline", "/v1/chat/completions", `{"model":"codex/gpt-6-luna","service_tier":"ultrafast","messages":[{"role":"user","content":"ping"}]}`); got != "acct-pro:ultrafast" {
|
||||
t.Errorf("chat's own ultrafast: tried %s", got)
|
||||
}
|
||||
// off: none of it is kept
|
||||
if err := provider.SetFastPick("omp", "codex/gpt-6-luna", false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if provider.IsUltraPick("omp", "codex/gpt-6-luna") {
|
||||
t.Error("Ultrafast kept after the pick was switched off")
|
||||
}
|
||||
if got := send("omp", "/v1/responses", responses); got != "acct-plus:" {
|
||||
t.Errorf("off: tried %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,21 +180,29 @@ func agentModelList(a *agent.Agent) []agentModelJSON {
|
||||
|
||||
func agentModelsAPI(mux *http.ServeMux) {
|
||||
// a model the agent picks sent in its vendor's fast mode, or not (#954):
|
||||
// for is the option's fastFor, the agent whose requests it goes on
|
||||
// for is the option's fastFor, the agent whose requests it goes on. Ultra
|
||||
// sends it as Ultrafast where the account offers that (#1954)
|
||||
mux.HandleFunc("POST /api/agent-fast", func(rw http.ResponseWriter, r *http.Request) {
|
||||
var in struct {
|
||||
For, Ref string
|
||||
Fast bool
|
||||
For, Ref string
|
||||
Fast, Ultra bool
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&in); err != nil {
|
||||
fail(rw, err)
|
||||
return
|
||||
}
|
||||
if err := provider.SetFastPick(in.For, in.Ref, in.Fast); err != nil {
|
||||
tier := ""
|
||||
switch {
|
||||
case in.Fast && in.Ultra:
|
||||
tier = "ultrafast"
|
||||
case in.Fast:
|
||||
tier = "priority"
|
||||
}
|
||||
if err := provider.SetFastTier(in.For, in.Ref, tier); err != nil {
|
||||
fail(rw, err)
|
||||
return
|
||||
}
|
||||
writeJSON(rw, map[string]any{"fast": provider.IsFastPick(in.For, in.Ref)})
|
||||
writeJSON(rw, map[string]any{"fast": provider.IsFastPick(in.For, in.Ref), "ultra": provider.IsUltraPick(in.For, in.Ref)})
|
||||
})
|
||||
mux.HandleFunc("GET /api/agent-models/{id}", func(rw http.ResponseWriter, r *http.Request) {
|
||||
a, err := agent.Find(r.PathValue("id"))
|
||||
|
||||
@@ -1185,6 +1185,7 @@ func Handler(w Windows, gw *gateway.Server) http.Handler {
|
||||
in.PickedModels = cur.PickedModels // "only models I pick" (#1337)
|
||||
in.OwnModelsHidden = cur.OwnModelsHidden // an agent's own models left out (#1642)
|
||||
in.FastPicks = cur.FastPicks // switched in the agents' pickers (#954)
|
||||
in.UltraPicks = cur.UltraPicks // and sent Ultrafast (#1954)
|
||||
in.AgentEfforts = cur.AgentEfforts // picked in an agent's row (#1003)
|
||||
in.PluginCheckins = cur.PluginCheckins // set on its own (plugin-checkin below)
|
||||
in.PluginOptions = cur.PluginOptions // set on its own (plugin-option below)
|
||||
|
||||
@@ -2061,6 +2061,10 @@ body.window .foot { padding-left: 18px; }
|
||||
.field .fast-tag { display: inline-flex; flex: none; color: var(--accent); }
|
||||
.field .fast-tag path { fill: currentColor; }
|
||||
.ag-open .field .fast-tag { order: 1; }
|
||||
/* Ultrafast (#1954): two bolts, overlapped to fit the bolt's place */
|
||||
.bolts { display: inline-flex; align-items: center; }
|
||||
.bolts svg + svg { margin-left: -8px; }
|
||||
.field .fast-tag .bolts svg + svg { margin-left: -6px; }
|
||||
.pop.explained li { height: auto; padding: 7px 8px; white-space: normal; align-items: flex-start; }
|
||||
.pop.explained li .option-words { flex-direction: column; align-items: flex-start; gap: 2px; }
|
||||
.pop.explained li .n { flex: none; overflow: visible; line-height: 1.4; }
|
||||
|
||||
+33
-19
@@ -441,7 +441,7 @@ function renderAgents() {
|
||||
const shown = f.menu ? f.summary : effort ? effortName(opt || { value: f.value }) : (opt?.label || f.value || t(FOLLOWS_MODEL.includes(f.label) ? "same as model" : "default"));
|
||||
if (f.menu) b.title = f.options.map((o) => `${o.label}: ${o.note}`).join("\n");
|
||||
b.append(el("span", "v" + (f.value || f.custom ? "" : " empty"), shown));
|
||||
if (f.value && opt?.fast) b.append(fastTag());
|
||||
if (f.value && opt?.fast) b.append(fastTag(opt.ultra));
|
||||
const c = el("span", "chev");
|
||||
c.append(svg(CHEV, 11, 1.7));
|
||||
b.append(c);
|
||||
@@ -5067,10 +5067,12 @@ function renderList() {
|
||||
// fastToggle: a model with a fast mode (a ChatGPT account's GPT, Cursor's
|
||||
// -fast, …) is sent in it, or not, for the agent the picker is of (#954),
|
||||
// switched by the model as a routing group's member is; the pick itself
|
||||
// stays as it is
|
||||
// stays as it is. Where an account offers it Ultrafast too (ultraOk,
|
||||
// #1954), a click steps usual → Fast → Ultrafast → usual, as a camera's
|
||||
// flash button steps its modes
|
||||
const BOLT = "M9.25 1.75 3.75 9h4l-1 5.25L12.25 7h-4z";
|
||||
function fastToggle(o) {
|
||||
const b = el("button", "fast" + (o.fast ? " on" : ""));
|
||||
const b = el("button", "fast" + (o.fast ? " on" : "") + (o.fast && o.ultra ? " ultra" : ""));
|
||||
const name = o.label || o.value;
|
||||
const agent = pick.agent.name || o.fastFor;
|
||||
// on a provider the user added (ownFast, #1615) fast is only asked for:
|
||||
@@ -5078,45 +5080,57 @@ function fastToggle(o) {
|
||||
b.title = o.ownFast
|
||||
? (o.fast ? t("{model} is asked for OpenAI's fast mode for {agent}, where your provider serves it. Click to send it as {agent} asks", { model: name, agent })
|
||||
: t("Ask your provider for OpenAI's fast mode (service_tier \"priority\") on {model} for {agent}: quicker, at a higher price, where it serves it", { model: name, agent }))
|
||||
: o.fast && o.ultra ? t("{model} is sent Ultrafast for {agent} where the account offers it, and fast where it doesn't. Click to send it at the usual speed", { model: name, agent })
|
||||
: o.fast && o.ultraOk ? t("{model} is sent fast for {agent}: quicker, at a higher price. Click to send it Ultrafast, where the account offers it", { model: name, agent })
|
||||
: o.fast ? t("{model} is sent fast for {agent}: quicker, at a higher price. Click to send it at the usual speed", { model: name, agent })
|
||||
: t("Send {model} fast for {agent}: quicker, at a higher price", { model: name, agent });
|
||||
b.setAttribute("aria-pressed", String(!!o.fast));
|
||||
b.setAttribute("aria-label", t("Fast"));
|
||||
b.append(svg(BOLT, 14, 1.4));
|
||||
b.setAttribute("aria-label", t(o.fast && o.ultra ? "Ultrafast" : "Fast"));
|
||||
b.append(boltIcon(o.fast && o.ultra, 14));
|
||||
b.onclick = async (ev) => {
|
||||
ev.stopPropagation();
|
||||
const fast = !o.fast;
|
||||
setFast(o, fast);
|
||||
const was = { fast: !!o.fast, ultra: !!(o.fast && o.ultra) };
|
||||
const next = !was.fast ? { fast: true, ultra: false } : o.ultraOk && !was.ultra ? { fast: true, ultra: true } : { fast: false, ultra: false };
|
||||
setFast(o, next.fast, next.ultra);
|
||||
try {
|
||||
await api("agent-fast", { for: o.fastFor, ref: o.ref, fast });
|
||||
status(t(fast ? "{model} is sent fast for {agent}" : "{model} is sent at the usual speed for {agent}", { model: name, agent }), "ok");
|
||||
await api("agent-fast", { for: o.fastFor, ref: o.ref, fast: next.fast, ...(next.ultra ? { ultra: true } : {}) });
|
||||
status(t(next.ultra ? "{model} is sent Ultrafast for {agent}" : next.fast ? "{model} is sent fast for {agent}" : "{model} is sent at the usual speed for {agent}", { model: name, agent }), "ok");
|
||||
} catch (e) {
|
||||
setFast(o, !fast);
|
||||
setFast(o, was.fast, was.ultra);
|
||||
status(e.message, "err");
|
||||
}
|
||||
};
|
||||
return b;
|
||||
}
|
||||
// boltIcon: Fast's bolt, or Ultrafast's two
|
||||
function boltIcon(ultra, size) {
|
||||
if (!ultra) return svg(BOLT, size, 1.4);
|
||||
const s = el("span", "bolts");
|
||||
s.append(svg(BOLT, size, 1.4), svg(BOLT, size, 1.4));
|
||||
return s;
|
||||
}
|
||||
// setFast marks the model fast or not in every list it is in for the agent:
|
||||
// the open picker's, and the agent's fields (its tiers pick the same model)
|
||||
function setFast(o, fast) {
|
||||
function setFast(o, fast, ultra = false) {
|
||||
const same = (x) => x.ref === o.ref && x.fastFor === o.fastFor;
|
||||
for (const a of state.agents) for (const f of a.fields) for (const x of f.options || []) if (same(x)) x.fast = fast;
|
||||
for (const x of [...(pick?.options || []), ...(pick?.items || [])]) if (same(x)) x.fast = fast;
|
||||
for (const a of state.agents) for (const f of a.fields) for (const x of f.options || []) if (same(x)) { x.fast = fast; x.ultra = ultra; }
|
||||
for (const x of [...(pick?.options || []), ...(pick?.items || [])]) if (same(x)) { x.fast = fast; x.ultra = ultra; }
|
||||
o.fast = fast;
|
||||
o.ultra = ultra;
|
||||
// the field's button says it of the model it has
|
||||
const anchor = pick?.anchor;
|
||||
if (anchor?.classList.contains("field") && optionFor(pick.field, pick.field.value)?.ref === o.ref) {
|
||||
anchor.querySelector(".fast-tag")?.remove();
|
||||
if (fast) anchor.querySelector(".v")?.after(fastTag());
|
||||
if (fast) anchor.querySelector(".v")?.after(fastTag(ultra));
|
||||
}
|
||||
if (pick) renderList();
|
||||
}
|
||||
// fastTag: the bolt after a field's model that is sent fast
|
||||
function fastTag() {
|
||||
const s = el("span", "fast-tag");
|
||||
s.title = t("Fast");
|
||||
s.append(svg(BOLT, 11, 1.4));
|
||||
// fastTag: the bolt after a field's model that is sent fast, two for
|
||||
// Ultrafast
|
||||
function fastTag(ultra) {
|
||||
const s = el("span", "fast-tag" + (ultra ? " ultra" : ""));
|
||||
s.title = t(ultra ? "Ultrafast" : "Fast");
|
||||
s.append(boltIcon(ultra, 11));
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
@@ -2431,6 +2431,10 @@ const I18N = {
|
||||
"{model} is sent fast for {agent}: quicker, at a higher price. Click to send it at the usual speed": "{agent} 用 {model} 时走快速模式:更快,价格更高。点一下改回标准速度",
|
||||
"Send {model} fast for {agent}: quicker, at a higher price": "{agent} 用 {model} 时走快速模式:更快,价格更高",
|
||||
"{model} is sent fast for {agent}": "{agent} 用 {model} 时走快速模式",
|
||||
"{model} is sent Ultrafast for {agent} where the account offers it, and fast where it doesn't. Click to send it at the usual speed": "{agent} 用 {model} 时,账号支持极速就走极速,不支持则走快速模式。点一下改回标准速度",
|
||||
"{model} is sent fast for {agent}: quicker, at a higher price. Click to send it Ultrafast, where the account offers it": "{agent} 用 {model} 时走快速模式:更快,价格更高。点一下改为极速(账号支持时)",
|
||||
"{model} is sent Ultrafast for {agent}": "{agent} 用 {model} 时走极速",
|
||||
"Ultrafast": "极速",
|
||||
"{model} is sent at the usual speed for {agent}": "{agent} 用 {model} 时走标准速度",
|
||||
"Add a provider, or sign in to Codex or Copilot; their models show up here for every agent.": "添加供应商,或登录 Codex / Copilot;其模型会列在这里,供所有 Agent 使用。",
|
||||
"Use this model in the snippets": "在示例中使用此模型",
|
||||
@@ -6085,6 +6089,10 @@ const I18N = {
|
||||
"{model} is sent fast for {agent}: quicker, at a higher price. Click to send it at the usual speed": "{agent} 用 {model} 時走快速模式:更快,價格更高。點一下改回標準速度",
|
||||
"Send {model} fast for {agent}: quicker, at a higher price": "{agent} 用 {model} 時走快速模式:更快,價格更高",
|
||||
"{model} is sent fast for {agent}": "{agent} 用 {model} 時走快速模式",
|
||||
"{model} is sent Ultrafast for {agent} where the account offers it, and fast where it doesn't. Click to send it at the usual speed": "{agent} 用 {model} 時,帳號支援極速就走極速,不支援則走快速模式。點一下改回標準速度",
|
||||
"{model} is sent fast for {agent}: quicker, at a higher price. Click to send it Ultrafast, where the account offers it": "{agent} 用 {model} 時走快速模式:更快,價格更高。點一下改為極速(帳號支援時)",
|
||||
"{model} is sent Ultrafast for {agent}": "{agent} 用 {model} 時走極速",
|
||||
"Ultrafast": "極速",
|
||||
"{model} is sent at the usual speed for {agent}": "{agent} 用 {model} 時走標準速度",
|
||||
"Add a provider, or sign in to Codex or Copilot; their models show up here for every agent.": "新增供應商,或登入 Codex / Copilot;其模型會列在這裡,供所有 Agent 使用。",
|
||||
"Use this model in the snippets": "在範例中使用此模型",
|
||||
@@ -9737,6 +9745,10 @@ const I18N = {
|
||||
"{model} is sent fast for {agent}: quicker, at a higher price. Click to send it at the usual speed": "{agent} の {model} は高速モードで送ります:速く、料金は高め。クリックで標準速度に戻します",
|
||||
"Send {model} fast for {agent}: quicker, at a higher price": "{agent} の {model} を高速モードで送る:速く、料金は高め",
|
||||
"{model} is sent fast for {agent}": "{agent} の {model} は高速モードで送ります",
|
||||
"{model} is sent Ultrafast for {agent} where the account offers it, and fast where it doesn't. Click to send it at the usual speed": "{agent} の {model} は、アカウントが対応していれば超高速、していなければ高速モードで送ります。クリックで標準速度に戻します",
|
||||
"{model} is sent fast for {agent}: quicker, at a higher price. Click to send it Ultrafast, where the account offers it": "{agent} の {model} は高速モードで送ります:速く、料金は高め。クリックで超高速にします(アカウントが対応している場合)",
|
||||
"{model} is sent Ultrafast for {agent}": "{agent} の {model} は超高速で送ります",
|
||||
"Ultrafast": "超高速",
|
||||
"{model} is sent at the usual speed for {agent}": "{agent} の {model} は標準速度で送ります",
|
||||
"Add a provider, or sign in to Codex or Copilot; their models show up here for every agent.": "プロバイダを追加するか、Codex または Copilot にサインインしてください。そのモデルがここに表示され、すべてのエージェントで使えます。",
|
||||
"Use this model in the snippets": "このモデルをスニペットで使う",
|
||||
@@ -13399,6 +13411,10 @@ const I18N = {
|
||||
"{model} is sent fast for {agent}: quicker, at a higher price. Click to send it at the usual speed": "{model} geht für {agent} im Schnellmodus: schneller, zu einem höheren Preis. Klicken für die normale Geschwindigkeit",
|
||||
"Send {model} fast for {agent}: quicker, at a higher price": "{model} für {agent} im Schnellmodus senden: schneller, zu einem höheren Preis",
|
||||
"{model} is sent fast for {agent}": "{model} geht für {agent} im Schnellmodus",
|
||||
"{model} is sent Ultrafast for {agent} where the account offers it, and fast where it doesn't. Click to send it at the usual speed": "{model} geht für {agent} als Ultrafast, wo das Konto es anbietet, sonst im Schnellmodus. Klicken für die normale Geschwindigkeit",
|
||||
"{model} is sent fast for {agent}: quicker, at a higher price. Click to send it Ultrafast, where the account offers it": "{model} geht für {agent} im Schnellmodus: schneller, zu einem höheren Preis. Klicken für Ultrafast, wo das Konto es anbietet",
|
||||
"{model} is sent Ultrafast for {agent}": "{model} geht für {agent} als Ultrafast",
|
||||
"Ultrafast": "Ultrafast",
|
||||
"{model} is sent at the usual speed for {agent}": "{model} geht für {agent} mit normaler Geschwindigkeit",
|
||||
"Add a provider, or sign in to Codex or Copilot; their models show up here for every agent.": "Fügen Sie einen Anbieter hinzu oder melden Sie sich bei Codex oder Copilot an; deren Modelle erscheinen hier für jeden Agenten.",
|
||||
"Use this model in the snippets": "Dieses Modell in den Snippets verwenden",
|
||||
|
||||
@@ -117,6 +117,7 @@ func TestSettingsSaveKeepsWhatItDoesNotSend(t *testing.T) {
|
||||
OwnModelsHidden: []string{"dsh"},
|
||||
OrderedModels: map[string][]string{"codex": {"group/g", "p/n"}},
|
||||
FastPicks: map[string][]string{"codex": {"p/n"}},
|
||||
UltraPicks: map[string][]string{"codex": {"p/n"}},
|
||||
AgentEfforts: map[string]string{"cursor-local": "high"},
|
||||
PluginCheckins: map[string]bool{"fakeco": true},
|
||||
PluginOptions: map[string]map[string]bool{"fakeco": {"auto": true}},
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// #1954, zhenghaowen0967: a fast pick of a ChatGPT model an account offers
|
||||
// as Ultrafast (ultraOk) steps usual → Fast → Ultrafast → usual at the
|
||||
// bolt, as a camera's flash button steps its modes. Ultrafast posts
|
||||
// /api/agent-fast with ultra, shows two bolts in the row and after the
|
||||
// field's model, and says so in the tooltip and status. A refusal puts it
|
||||
// back. Window and 440px tray panel, en zh ja de, Chromium and WebKit.
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
const path = require("node:path");
|
||||
const { test } = require("node:test");
|
||||
const { chromium, webkit } = require("playwright");
|
||||
|
||||
const assets = path.resolve(__dirname, "../assets");
|
||||
|
||||
function fixtures() {
|
||||
const options = [
|
||||
{ value: "magpie/codex/gpt-5.5", ref: "codex/gpt-5.5", label: "GPT-5.5", group: "ChatGPT", fastFor: "codex", ultraOk: true },
|
||||
{ value: "magpie/codex/gpt-5.4-mini", ref: "codex/gpt-5.4-mini", label: "GPT-5.4 mini", group: "ChatGPT" },
|
||||
{ value: "magpie/zai/glm-5", ref: "zai/glm-5", label: "GLM-5", group: "Z.ai" },
|
||||
// a GPT model on a provider the user added by its address (#1615)
|
||||
{ value: "magpie/rl/o4-mini", ref: "rl/o4-mini", label: "o4-mini", group: "Relay", fastFor: "codex", ownFast: true },
|
||||
];
|
||||
const agents = [{ id: "codex", name: "Codex", path: "/test/codex", wired: true, fields: [{ key: "model", label: "model", value: "magpie/codex/gpt-5.5", options }] }];
|
||||
const providers = { providers: [{
|
||||
id: "codex", name: "ChatGPT", icon: "codex-color", chat: "", responses: "", anthropic: "", catalog: "",
|
||||
models: [{ id: "gpt-5.5", name: "", on: true }], fallback: [], headers: {}, keyList: [], proxy: "",
|
||||
agents: [{ id: "codex", name: "Codex", current: true, model: "gpt-5.5" }],
|
||||
account: { agent: "codex", agentName: "Codex", user: "me@example.com", plan: "PLUS", logins: [{ user: "me@example.com", plan: "PLUS", active: true, on: true }] },
|
||||
}], presets: [], excluded: [], gateway: { running: true, window: true } };
|
||||
return { agents, providers };
|
||||
}
|
||||
|
||||
function server(lang, posts, refuse) {
|
||||
const { agents, providers } = fixtures();
|
||||
return async (route) => {
|
||||
const req = route.request();
|
||||
const url = new URL(req.url());
|
||||
const json = (data) => route.fulfill({ json: data });
|
||||
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
|
||||
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
// the panel fitting its window is no setting
|
||||
if (req.method() === "POST" && url.pathname.startsWith("/api/") && !url.pathname.startsWith("/api/window/")) {
|
||||
posts.push({ path: url.pathname, body: req.postDataJSON() });
|
||||
if (url.pathname === "/api/agent-fast") {
|
||||
if (refuse()) return route.fulfill({ status: 500, contentType: "text/plain", body: "codex/gpt-5.5 has no fast mode magpie can ask for" });
|
||||
return json({ fast: req.postDataJSON().fast, ultra: !!req.postDataJSON().ultra });
|
||||
}
|
||||
return json({});
|
||||
}
|
||||
if (url.pathname === "/api/state") return json({ agents, profiles: [], settings: { lang, theme: "light" } });
|
||||
if (url.pathname === "/api/providers") return json(providers);
|
||||
if (url.pathname === "/api/usage/quotas") return json([]);
|
||||
if (url.pathname === "/api/groups") return json({ groups: [] });
|
||||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||||
if (url.pathname === "/api/agents/cli") return json({ agents: {}, pending: false });
|
||||
if (url.pathname.startsWith("/api/")) return json({});
|
||||
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
||||
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
|
||||
await route.fulfill({ body: await fs.readFile(file), contentType });
|
||||
};
|
||||
}
|
||||
|
||||
const said = {
|
||||
en: { fast: "GPT-5.5 is sent fast for Codex: quicker, at a higher price. Click to send it Ultrafast, where the account offers it",
|
||||
ultra: "GPT-5.5 is sent Ultrafast for Codex where the account offers it, and fast where it doesn't. Click to send it at the usual speed", status: "GPT-5.5 is sent Ultrafast for Codex", name: "Ultrafast" },
|
||||
zh: { fast: "Codex 用 GPT-5.5 时走快速模式:更快,价格更高。点一下改为极速(账号支持时)",
|
||||
ultra: "Codex 用 GPT-5.5 时,账号支持极速就走极速,不支持则走快速模式。点一下改回标准速度", status: "Codex 用 GPT-5.5 时走极速", name: "极速" },
|
||||
ja: { fast: "Codex の GPT-5.5 は高速モードで送ります:速く、料金は高め。クリックで超高速にします(アカウントが対応している場合)",
|
||||
ultra: "Codex の GPT-5.5 は、アカウントが対応していれば超高速、していなければ高速モードで送ります。クリックで標準速度に戻します", status: "Codex の GPT-5.5 は超高速で送ります", name: "超高速" },
|
||||
de: { fast: "GPT-5.5 geht für Codex im Schnellmodus: schneller, zu einem höheren Preis. Klicken für Ultrafast, wo das Konto es anbietet",
|
||||
ultra: "GPT-5.5 geht für Codex als Ultrafast, wo das Konto es anbietet, sonst im Schnellmodus. Klicken für die normale Geschwindigkeit", status: "GPT-5.5 geht für Codex als Ultrafast", name: "Ultrafast" },
|
||||
};
|
||||
const row = '.row.agent[data-id="codex"]';
|
||||
const pop = "#pop:not([hidden]) #list li";
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
test(engine + ": a fast pick steps on to Ultrafast where an account offers it", async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
const errors = [];
|
||||
t.after(() => browser.close());
|
||||
for (const lang of ["en", "zh", "ja", "de"]) for (const panel of [false, true]) {
|
||||
await t.test(`${lang} ${panel ? "tray panel 440px" : "window"}`, async () => {
|
||||
const posts = [];
|
||||
let refusing = false;
|
||||
const page = await (await browser.newContext({ viewport: panel ? { width: 440, height: 560 } : { width: 980, height: 600 }, reducedMotion: "reduce" })).newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", server(lang, posts, () => refusing));
|
||||
await page.goto("http://magpie.test/" + (panel ? "?mode=panel" : "?view=agents"));
|
||||
await page.locator(row).waitFor();
|
||||
const field = panel ? `${row} .ag-open .field[data-key="model"]` : `${row} > .field.ag-start[data-key="model"]`;
|
||||
if (panel && !(await page.locator(field).isVisible())) {
|
||||
await page.locator(`${row} .ag-sum`).click();
|
||||
await page.waitForTimeout(700);
|
||||
}
|
||||
await page.locator(field).click();
|
||||
await page.locator(pop).first().waitFor();
|
||||
const gpt = page.locator(pop).filter({ hasText: "GPT-5.5" }).first();
|
||||
const bolt = gpt.locator("button.fast");
|
||||
const body = (fast, ultra) => ({ for: "codex", ref: "codex/gpt-5.5", fast, ...(ultra ? { ultra: true } : {}) });
|
||||
|
||||
// usual → Fast, which says the next click is Ultrafast
|
||||
await bolt.click();
|
||||
await page.waitForTimeout(150);
|
||||
assert.deepEqual(posts.map((p) => p.body), [body(true)]);
|
||||
assert.equal(await bolt.getAttribute("title"), said[lang].fast);
|
||||
assert.equal(await bolt.locator("svg").count(), 1);
|
||||
|
||||
// Fast → Ultrafast: two bolts, in the row and after the field's model
|
||||
await bolt.click();
|
||||
await page.waitForTimeout(150);
|
||||
assert.deepEqual(posts.at(-1).body, body(true, true));
|
||||
assert.match(await bolt.evaluate((b) => b.className), /\bon\b.*\bultra\b/);
|
||||
assert.equal(await bolt.getAttribute("aria-label"), said[lang].name);
|
||||
assert.equal(await bolt.getAttribute("title"), said[lang].ultra);
|
||||
assert.equal(await bolt.locator("svg").count(), 2);
|
||||
assert.equal(await page.locator("#status").textContent(), said[lang].status);
|
||||
const fits = await gpt.evaluate((li) => {
|
||||
const r = li.getBoundingClientRect(), b = li.querySelector("button.fast").getBoundingClientRect();
|
||||
return [...li.querySelectorAll("button.fast svg")].every((s) => { const q = s.getBoundingClientRect(); return q.left >= b.left - 0.5 && q.right <= b.right + 0.5; }) && b.right <= r.right + 0.5;
|
||||
});
|
||||
assert(fits, "the two bolts fit in the button and the row");
|
||||
const tag = page.locator(`${field} .fast-tag`);
|
||||
assert.equal(await tag.count(), 1);
|
||||
assert.match(await tag.evaluate((s) => s.className), /\bultra\b/);
|
||||
assert.equal(await tag.locator("svg").count(), 2);
|
||||
assert.equal(await tag.getAttribute("title"), said[lang].name);
|
||||
|
||||
// a refusal puts Ultrafast back
|
||||
refusing = true;
|
||||
await bolt.click();
|
||||
await page.waitForTimeout(150);
|
||||
assert.deepEqual(posts.at(-1).body, body(false));
|
||||
assert.equal(await bolt.locator("svg").count(), 2, "refused: still Ultrafast");
|
||||
refusing = false;
|
||||
|
||||
// Ultrafast → usual
|
||||
await bolt.click();
|
||||
await page.waitForTimeout(150);
|
||||
assert.deepEqual(posts.at(-1).body, body(false));
|
||||
assert.equal(await bolt.getAttribute("aria-pressed"), "false");
|
||||
assert.equal(await page.locator(`${field} .fast-tag`).count(), 0);
|
||||
await page.context().close();
|
||||
});
|
||||
}
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
)
|
||||
|
||||
@@ -14,6 +15,10 @@ import (
|
||||
// the agent's picker, kept by agent (settings' FastPicks), and asked for by
|
||||
// the gateway on every request the agent sends that model. A group takes
|
||||
// none: its members are sent as it says.
|
||||
//
|
||||
// A fast pick of a ChatGPT model may be sent as Ultrafast instead (#1954,
|
||||
// settings' UltraPicks): the gateway asks it of each account that offers it
|
||||
// on the model, and priority of one that doesn't.
|
||||
|
||||
// IsFastPick reports whether agent's requests for the entry id
|
||||
// ("<provider>/<model>") are sent fast.
|
||||
@@ -27,14 +32,70 @@ func FastPicks(agent string) []string {
|
||||
return heldSettings().FastPicks[strings.ToLower(agent)]
|
||||
}
|
||||
|
||||
// IsUltraPick reports whether agent's requests for the entry id are sent as
|
||||
// Ultrafast where the account offers it.
|
||||
func IsUltraPick(agent, id string) bool {
|
||||
return slices.Contains(UltraPicks(agent), id)
|
||||
}
|
||||
|
||||
// UltraPicks are the fast picks agent's requests for are sent as Ultrafast.
|
||||
func UltraPicks(agent string) []string {
|
||||
return heldSettings().UltraPicks[strings.ToLower(agent)]
|
||||
}
|
||||
|
||||
// CanUltra reports whether a fast pick of model on p can be sent as
|
||||
// Ultrafast: a ChatGPT model that one of Codex's accounts lists the tier
|
||||
// on (Account.Tiers). A list that doesn't say tiers offers none.
|
||||
func CanUltra(p Provider, model string) bool {
|
||||
return UltraOn(p, model, UltraModels())
|
||||
}
|
||||
|
||||
// UltraOn is CanUltra with UltraModels read once, for a list of them all.
|
||||
func UltraOn(p Provider, model string, ultra map[string]bool) bool {
|
||||
return !p.IsPlugin() && p.Account != nil && p.Account.Agent == "codex" && CanFast(p, model) && ultra[model]
|
||||
}
|
||||
|
||||
// UltraModels are the models one of Codex's accounts offers Ultrafast on.
|
||||
func UltraModels() map[string]bool {
|
||||
out := map[string]bool{}
|
||||
for _, l := range Logins("codex") {
|
||||
live, _, found := catalog.Live(accountModels("codex", l.User))
|
||||
if !found {
|
||||
continue
|
||||
}
|
||||
for _, m := range live {
|
||||
if slices.Contains(m.Tiers, "ultrafast") {
|
||||
out[m.ID] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// SetFastPick sends agent's requests for the entry id fast, or not. Only a
|
||||
// model with a fast mode magpie can ask for (CanFast) is switched on.
|
||||
func SetFastPick(agent, id string, fast bool) error {
|
||||
tier := ""
|
||||
if fast {
|
||||
tier = "priority"
|
||||
}
|
||||
return SetFastTier(agent, id, tier)
|
||||
}
|
||||
|
||||
// SetFastTier sends agent's requests for the entry id at tier: "" the usual
|
||||
// speed, "priority" fast, "ultrafast" Ultrafast where the account offers it
|
||||
// (CanUltra), priority where it doesn't.
|
||||
func SetFastTier(agent, id, tier string) error {
|
||||
agent, id = strings.ToLower(strings.TrimSpace(agent)), strings.TrimSpace(id)
|
||||
if agent == "" {
|
||||
return errors.New("no agent")
|
||||
}
|
||||
if fast {
|
||||
switch tier {
|
||||
case "", "priority", "ultrafast":
|
||||
default:
|
||||
return fmt.Errorf("magpie knows no tier %q", tier)
|
||||
}
|
||||
if tier != "" {
|
||||
if strings.HasPrefix(id, GroupPrefix) {
|
||||
return fmt.Errorf("%s is a routing group: its members are sent fast as it says, on the Routing page", id)
|
||||
}
|
||||
@@ -48,27 +109,41 @@ func SetFastPick(agent, id string, fast bool) error {
|
||||
if !CanFast(p, model) {
|
||||
return fmt.Errorf("%s has no fast mode magpie can ask for", id)
|
||||
}
|
||||
if tier == "ultrafast" && !CanUltra(p, model) {
|
||||
return fmt.Errorf("no account offers Ultrafast on %s", id)
|
||||
}
|
||||
}
|
||||
s := settings.Load()
|
||||
was := s.FastPicks[agent]
|
||||
keep := slices.DeleteFunc(slices.Clone(was), func(x string) bool { return x == id })
|
||||
if fast {
|
||||
keep = append(keep, id)
|
||||
}
|
||||
if slices.Equal(was, keep) {
|
||||
fast := setPick(&s.FastPicks, agent, id, tier != "")
|
||||
ultra := setPick(&s.UltraPicks, agent, id, tier == "ultrafast")
|
||||
if !fast && !ultra {
|
||||
return nil
|
||||
}
|
||||
if len(keep) == 0 {
|
||||
delete(s.FastPicks, agent)
|
||||
} else {
|
||||
if s.FastPicks == nil {
|
||||
s.FastPicks = map[string][]string{}
|
||||
}
|
||||
s.FastPicks[agent] = keep
|
||||
}
|
||||
if err := settings.Save(s); err != nil {
|
||||
return err
|
||||
}
|
||||
Changed() // a held settings read sees it
|
||||
return nil
|
||||
}
|
||||
|
||||
// setPick puts id in agent's list in m, or takes it out, and reports
|
||||
// whether that changed the list.
|
||||
func setPick(m *map[string][]string, agent, id string, on bool) bool {
|
||||
was := (*m)[agent]
|
||||
keep := slices.DeleteFunc(slices.Clone(was), func(x string) bool { return x == id })
|
||||
if on {
|
||||
keep = append(keep, id)
|
||||
}
|
||||
if slices.Equal(was, keep) {
|
||||
return false
|
||||
}
|
||||
if len(keep) == 0 {
|
||||
delete(*m, agent)
|
||||
} else {
|
||||
if *m == nil {
|
||||
*m = map[string][]string{}
|
||||
}
|
||||
(*m)[agent] = keep
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -38,6 +38,8 @@ func TestSetFastPick(t *testing.T) {
|
||||
}
|
||||
|
||||
st := settings.Load()
|
||||
// an Ultrafast pick moves with it (#1954)
|
||||
st.UltraPicks = map[string][]string{"codex": {"oa/gpt-6.1-sol"}}
|
||||
if !renameModelPrefs(&st, "oa", "openai") {
|
||||
t.Fatal("the rename moved nothing")
|
||||
}
|
||||
@@ -48,6 +50,9 @@ func TestSetFastPick(t *testing.T) {
|
||||
if !IsFastPick("codex", "openai/gpt-6.1-sol") || IsFastPick("codex", "oa/gpt-6.1-sol") {
|
||||
t.Fatalf("after the rename: %v", settings.Load().FastPicks)
|
||||
}
|
||||
if !IsUltraPick("codex", "openai/gpt-6.1-sol") || IsUltraPick("codex", "oa/gpt-6.1-sol") {
|
||||
t.Fatalf("after the rename: %v", settings.Load().UltraPicks)
|
||||
}
|
||||
|
||||
// switching off is allowed whatever the model is now, and drops the agent
|
||||
if err := SetFastPick("codex", "openai/gpt-6.1-sol", false); err != nil {
|
||||
@@ -56,4 +61,7 @@ func TestSetFastPick(t *testing.T) {
|
||||
if _, ok := settings.Load().FastPicks["codex"]; ok {
|
||||
t.Fatalf("an agent with none kept: %v", settings.Load().FastPicks)
|
||||
}
|
||||
if _, ok := settings.Load().UltraPicks["codex"]; ok {
|
||||
t.Fatalf("Ultrafast kept with fast off: %v", settings.Load().UltraPicks)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -668,9 +668,9 @@ func renameModelPrefs(s *settings.Settings, from, to string) bool {
|
||||
// well, and are not one of the per-model preference maps: they say
|
||||
// which models are shown, not what a model is called or costs
|
||||
// (and so is the order they are listed in, the ones picked for an agent
|
||||
// shown only its picks, and the ones sent fast)
|
||||
// shown only its picks, and the ones sent fast or Ultrafast)
|
||||
hidden := false
|
||||
for _, m := range []map[string][]string{s.HiddenModels, s.PickedModels, s.OrderedModels, s.FastPicks} {
|
||||
for _, m := range []map[string][]string{s.HiddenModels, s.PickedModels, s.OrderedModels, s.FastPicks, s.UltraPicks} {
|
||||
for _, ids := range m {
|
||||
for i, id := range ids {
|
||||
if rest, ok := strings.CutPrefix(id, from+"/"); ok {
|
||||
|
||||
@@ -559,6 +559,10 @@ type Settings struct {
|
||||
// switched by the model in the agent's picker, as a routing group's
|
||||
// member is (Group.Fast), without making a group of it.
|
||||
FastPicks map[string][]string `json:"fastPicks,omitempty"`
|
||||
// UltraPicks are the fast picks an agent's requests for are sent as
|
||||
// Ultrafast instead (#1954), by agent id: each is in FastPicks too. An
|
||||
// account that doesn't offer Ultrafast on the model is sent priority.
|
||||
UltraPicks map[string][]string `json:"ultraPicks,omitempty"`
|
||||
|
||||
// The three maps below, and every one added beside them, are the
|
||||
// per-model ones: a field named Model* whose type is a map[string]X,
|
||||
|
||||
Reference in New Issue
Block a user