antigravity: a Google AI Pro account asks for its models with its plan named, as Antigravity does, and the log says what Google answered (Discord: a Pro account on magpie 0.1.770 had no Claude after Refresh while Antigravity 2.19.1's picker had Claude, 5.5 too) — magpie asked fetchAvailableModels with only {project}. Antigravity's language server (2.19.1, read from its binary) sends FetchAvailableModelsRequest{project, request_id, entitlement{user_tier}, location}, entitlement being the tier it keeps for the account (SetUserTier, with the plan's name) and the only v1internal request that has one. A Pro account's loadCodeAssist (CLIProxyAPI #6186) has currentTier standard-tier (usesGcpTos), paidTier g1-pro-tier "Google AI Pro", project aicode-consumers; asked with no tier, Google most likely serves it as standard-tier, Code Assist Standard, which has no Claude. Google checks the field: on our free account free-tier/bogus ids are INVALID_ARGUMENT, and standard-tier, g1-pro-tier, g1-ultra-tier and the other paid ids are FAILED_PRECONDITION, so paid ids are known and checked against the account. Ruled out on the free account: the project (none, random, aicode-consumers all the same), daily/prod/sandbox (all list Claude), and magpie's filters (only chat_/tab_ and six fixed ids, none Claude). Now fetchAvailableModels sends entitlement.userTier: the paid tier, then the current tier, skipping free-tier and legacy-tier, and on a refusal tries the next and at last none, as before; a free account sends none, so its request is unchanged. The tiers come from loadCodeAssist, which is now asked even when a project was kept with the sign-in (import, magpie accounts project), which used to skip it and so never learned the tier; if that fails the kept project is used as before. Logged: loadCodeAssist's current and paid tiers (with gcp-tos), project and ineligible tiers with reasons; each refresh's endpoint, User-Agent, project, tiers, entitlement sent, models listed and kept, the ids left out and why (not for chat, completion-only), those Google marks disabled (still listed), and the Claude ids; a tier refused, with Google's error. TestAntigravityProAccountNamesItsTier (Pro fixture: Claude only with g1-pro-tier named), TestAntigravityTierRefusedFallsBack and TestAntigravityTierFreeAndKeptProject fail on the old code (Gemini only) and pass. go vet, builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass. Not tried with a real Pro account: whether Google serves Claude to a Pro account only with its tier named is inferred from the client and the fixtures, not seen.

This commit is contained in:
yetone
2026-10-04 00:23:05 +08:00
parent bc141ad834
commit 7806395c74
3 changed files with 302 additions and 14 deletions
+168
View File
@@ -0,0 +1,168 @@
package provider
import (
"bytes"
"context"
"fmt"
"log"
"slices"
"strings"
"testing"
"time"
)
// A Google AI Pro account as loadCodeAssist answers it (CLIProxyAPI
// #6186): on standard-tier, paying for g1-pro-tier, in aicode-consumers.
const proLoad = `{
"currentTier":{"id":"standard-tier","name":"Antigravity","userDefinedCloudaicompanionProject":true,"usesGcpTos":true},
"paidTier":{"id":"g1-pro-tier","name":"Google AI Pro","availableCredits":[{"creditType":"GOOGLE_ONE_AI","minimumCreditAmountForUsage":"50"}]},
"cloudaicompanionProject":"aicode-consumers",
"ineligibleTiers":[{"tierId":"free-tier","reasonCode":"VALIDATION_REQUIRED","validationErrorMessage":"Verify your account to continue."}]}`
const (
geminiOnly = `{"models":{
"gemini-3.8-flash-high":{"displayName":"Gemini 3.8 Flash (High)","maxTokens":1048576,"quotaInfo":{"remainingFraction":1}},
"gemini-2.5-pro":{"displayName":"Gemini 2.5 Pro"},
"tab_flash_lite_preview":{},
"chat_20706":{}}}`
withClaude = `{"models":{
"gemini-3.8-flash-high":{"displayName":"Gemini 3.8 Flash (High)","maxTokens":1048576,"quotaInfo":{"remainingFraction":1}},
"claude-opus-5-5":{"displayName":"Claude Opus 5.5","maxTokens":250000,"quotaInfo":{"remainingFraction":1}},
"claude-sonnet-5-5":{"displayName":"Claude Sonnet 5.5","maxTokens":250000,"disabled":true,"quotaInfo":{"remainingFraction":1}},
"tab_flash_lite_preview":{}}}`
tierRefused = `{"error":{"code":400,"message":"Precondition check failed.","status":"FAILED_PRECONDITION"}}`
)
// Code Assist as it serves an account on tier has: the plan's models when
// asked with that tier named, Code Assist Standard's without one, and a
// 400 for a tier the account hasn't.
func tierModels(has string) func(map[string]any) (int, string) {
return func(body map[string]any) (int, string) {
e, _ := body["entitlement"].(map[string]any)
switch tier, _ := e["userTier"].(string); tier {
case "":
return 200, geminiOnly
case has:
return 200, withClaude
default:
return 400, tierRefused
}
}
}
func captureLog(t *testing.T) *bytes.Buffer {
t.Helper()
var buf bytes.Buffer
old := log.Writer()
log.SetOutput(&buf)
t.Cleanup(func() { log.SetOutput(old) })
return &buf
}
func antigravityModelIDs(t *testing.T, agent string) []string {
t.Helper()
ms, err := googleLogins(agent)[0].acct.models(context.Background())
if err != nil {
t.Fatal(err)
}
var ids []string
for _, m := range ms {
ids = append(ids, m.ID)
}
slices.Sort(ids)
return ids
}
// A Google AI Pro account's Antigravity has Claude (Discord: magpie 0.1.770
// listed a Pro account's models without any, while Antigravity's picker
// had Claude 5.5): fetchAvailableModels names the plan the account pays for
// in entitlement.userTier, as Antigravity's language server does, and the
// log says what Google answered and what magpie left out.
func TestAntigravityProAccountNamesItsTier(t *testing.T) {
f := &fakeGoogle{load: proLoad, modelsFor: tierModels("g1-pro-tier")}
googleSandbox(t, f)
buf := captureLog(t)
auth := googleAuth{AccessToken: "tok", RefreshToken: "rt-pro", Expiry: time.Now().Add(time.Hour).UnixMilli()}
if err := addGoogleLogin("antigravity", "pro@example.com", "", auth); err != nil {
t.Fatal(err)
}
if got, want := antigravityModelIDs(t, "antigravity"), []string{"claude-opus-5-5", "claude-sonnet-5-5", "gemini-3.8-flash-high"}; !slices.Equal(got, want) {
t.Fatalf("models %v, want %v", got, want)
}
if len(f.fetches) != 1 || fmt.Sprint(f.fetches[0]["entitlement"]) != "map[userTier:g1-pro-tier]" || f.fetches[0]["project"] != "aicode-consumers" {
t.Errorf("asked %v", f.fetches)
}
out := buf.String()
for _, w := range []string{
`loadCodeAssist at ` + codeAssistProd + `: current tier standard-tier (Antigravity) gcp-tos, paid tier g1-pro-tier (Google AI Pro), project "aicode-consumers", ineligible free-tier (VALIDATION_REQUIRED: Verify your account to continue.)`,
`fetchAvailableModels at ` + codeAssistDaily + ` (antigravity/hub/3.1.4 `,
`project "aicode-consumers", current tier "standard-tier", paid tier "g1-pro-tier", entitlement "g1-pro-tier"): 4 models, 3 kept; left out 1 not for chat [tab_flash_lite_preview], 0 completion-only []; disabled [claude-sonnet-5-5]; Claude [claude-opus-5-5 claude-sonnet-5-5]`,
} {
if !strings.Contains(out, w) {
t.Errorf("log lacks %q:\n%s", w, out)
}
}
}
// A tier Google won't take from the account is left out: the next is
// tried, then none, and the refusal is logged.
func TestAntigravityTierRefusedFallsBack(t *testing.T) {
f := &fakeGoogle{load: proLoad, modelsFor: tierModels("standard-tier")}
googleSandbox(t, f)
buf := captureLog(t)
auth := googleAuth{AccessToken: "tok", RefreshToken: "rt-pro2", Expiry: time.Now().Add(time.Hour).UnixMilli()}
addGoogleLogin("antigravity", "pro@example.com", "", auth)
if got := antigravityModelIDs(t, "antigravity"); !slices.Contains(got, "claude-opus-5-5") {
t.Fatalf("models %v", got)
}
var sent []string
for _, b := range f.fetches {
sent = append(sent, fmt.Sprint(b["entitlement"]))
}
if w := "map[userTier:g1-pro-tier] map[userTier:standard-tier]"; strings.Join(sent, " ") != w {
t.Errorf("sent %v, want %s", sent, w)
}
if !strings.Contains(buf.String(), "with entitlement g1-pro-tier: ") || !strings.Contains(buf.String(), "Precondition check failed.") {
t.Errorf("log:\n%s", buf.String())
}
// none taken: asked without one, as before
f.modelsFor = tierModels("g1-ultra-tier")
resetGoogleState()
if got := antigravityModelIDs(t, "antigravity"); !slices.Equal(got, []string{"gemini-3.8-flash-high"}) {
t.Fatalf("models %v", got)
}
if n := len(f.fetches); n != 5 || f.fetches[n-1]["entitlement"] != nil {
t.Errorf("asked %v", f.fetches)
}
}
// A free account names no tier (Google refuses "free-tier" there), as
// before; one whose project was kept with its sign-in still has its tiers
// asked for, so a Pro account imported with its project names its plan.
func TestAntigravityTierFreeAndKeptProject(t *testing.T) {
f := &fakeGoogle{
load: `{"currentTier":{"id":"free-tier","name":"Antigravity"},"paidTier":{"id":"free-tier","name":"Antigravity Starter Quota"},"cloudaicompanionProject":"aicode-consumers"}`,
modelsFor: tierModels("g1-pro-tier"),
}
googleSandbox(t, f)
captureLog(t)
auth := googleAuth{AccessToken: "tok", RefreshToken: "rt-free", Expiry: time.Now().Add(time.Hour).UnixMilli()}
addGoogleLogin("antigravity", "free@example.com", "", auth)
antigravityModelIDs(t, "antigravity")
if len(f.fetches) != 1 || f.fetches[0]["entitlement"] != nil {
t.Errorf("a free account asked %v", f.fetches)
}
f.load, f.fetches = proLoad, nil
resetGoogleState()
if err := SetGoogleProject("antigravity", "free@example.com", "kept-proj"); err != nil {
t.Fatal(err)
}
if got := antigravityModelIDs(t, "antigravity"); !slices.Contains(got, "claude-opus-5-5") {
t.Fatalf("models %v", got)
}
if len(f.fetches) != 1 || f.fetches[0]["project"] != "kept-proj" || fmt.Sprint(f.fetches[0]["entitlement"]) != "map[userTier:g1-pro-tier]" {
t.Errorf("asked %v", f.fetches)
}
}
+125 -14
View File
@@ -16,6 +16,7 @@ package provider
import (
"bufio"
"bytes"
"cmp"
"context"
"crypto/sha256"
"encoding/binary"
@@ -23,6 +24,7 @@ import (
"errors"
"fmt"
"io"
"log"
"net/http"
"net/url"
"os"
@@ -317,6 +319,27 @@ var googleState = struct {
type googleProject struct {
id, plan string
// the tiers loadCodeAssist gave (Antigravity's): the one the account
// is on ("free-tier", "standard-tier") and the Google One plan it pays
// for ("g1-pro-tier"), "" when not known
tier, paid string
}
// entitlements are the tiers to name in fetchAvailableModels'
// entitlement.userTier, best first. Antigravity's language server keeps
// the account's tier (SetUserTier, with the plan's name: "Google AI Pro")
// and sends it there (FetchAvailableModelsRequest.entitlement, the only
// request of Code Assist's that has one); Google takes a paid tier only
// from an account that has it (FAILED_PRECONDITION else). A free account
// names none (Google refuses "free-tier" there), as before.
func (p googleProject) entitlements() []string {
var out []string
for _, t := range []string{p.paid, p.tier} {
if t != "" && t != "free-tier" && t != "legacy-tier" && !slices.Contains(out, t) {
out = append(out, t)
}
}
return out
}
// token is a live access token for the account.
@@ -448,6 +471,7 @@ type codeAssistTier struct {
Name string `json:"name"`
IsDefault bool `json:"isDefault"`
UserDefinedCloudaicompanionProject bool `json:"userDefinedCloudaicompanionProject"`
UsesGcpTos bool `json:"usesGcpTos"`
}
// companionProject is Code Assist's project, which comes as an id or as
@@ -502,12 +526,50 @@ type loadCodeAssistReply struct {
AllowedTiers []codeAssistTier `json:"allowedTiers"`
CloudaicompanionProject companionProject `json:"cloudaicompanionProject"`
IneligibleTiers []struct {
ReasonCode string `json:"reasonCode"`
ReasonMessage string `json:"reasonMessage"`
TierID string `json:"tierId"`
ReasonCode string `json:"reasonCode"`
ReasonMessage string `json:"reasonMessage"`
TierID string `json:"tierId"`
ValidationErrorMessage string `json:"validationErrorMessage"`
} `json:"ineligibleTiers"`
}
// tiers are the ids of the tier the account is on and the one it pays for.
func (r loadCodeAssistReply) tiers() (current, paid string) {
if r.CurrentTier != nil {
current = r.CurrentTier.ID
}
if r.PaidTier != nil {
paid = r.PaidTier.ID
}
return current, paid
}
// describe is what loadCodeAssist said of the account, for the log.
func (r loadCodeAssistReply) describe() string {
tier := func(t *codeAssistTier) string {
if t == nil {
return "-"
}
s := t.ID
if t.Name != "" {
s += " (" + t.Name + ")"
}
if t.UsesGcpTos {
s += " gcp-tos"
}
return s
}
s := fmt.Sprintf("current tier %s, paid tier %s, project %q", tier(r.CurrentTier), tier(r.PaidTier), string(r.CloudaicompanionProject))
for _, t := range r.IneligibleTiers {
why := t.ReasonCode
if m := cmp.Or(t.ReasonMessage, t.ValidationErrorMessage); m != "" {
why += ": " + m
}
s += fmt.Sprintf(", ineligible %s (%s)", t.TierID, why)
}
return s
}
func (r loadCodeAssistReply) plan() string {
t := r.PaidTier
if t == nil || t.Name == "" {
@@ -549,10 +611,10 @@ func (g googleAccount) geminiProject(ctx context.Context) (googleProject, error)
}
if load.CurrentTier != nil {
if load.CloudaicompanionProject != "" {
return googleProject{string(load.CloudaicompanionProject), load.plan()}, nil
return googleProject{id: string(load.CloudaicompanionProject), plan: load.plan()}, nil
}
if want != "" {
return googleProject{want, load.plan()}, nil
return googleProject{id: want, plan: load.plan()}, nil
}
return googleProject{}, g.needsProject("")
}
@@ -581,7 +643,7 @@ func (g googleAccount) geminiProject(ctx context.Context) (googleProject, error)
if id == "" {
return googleProject{}, g.needsProject("")
}
return googleProject{id, tier.Name}, nil
return googleProject{id: id, plan: tier.Name}, nil
}
// needsProject says a Code Assist Standard or Enterprise account needs a
@@ -599,17 +661,28 @@ func (g googleAccount) needsProject(why string) error {
}
// antigravityProject sets the account up as Antigravity does.
// A project kept with the sign-in is still the one used, but the account's
// tiers are asked for all the same: fetchAvailableModels names them.
func (g googleAccount) antigravityProject(ctx context.Context) (googleProject, error) {
if g.auth.Project != "" {
return googleProject{id: g.auth.Project}, nil
}
var load loadCodeAssistReply
body := map[string]any{"metadata": map[string]any{"ideType": "ANTIGRAVITY"}}
if err := g.call(ctx, g.app.loadBase, "loadCodeAssist", body, &load, nil); err != nil {
err := g.call(ctx, g.app.loadBase, "loadCodeAssist", body, &load, nil)
if err == nil {
log.Printf("antigravity %s: loadCodeAssist at %s: %s", g.user, g.app.loadBase, load.describe())
}
cur, paid := load.tiers()
if g.auth.Project != "" {
if err != nil {
log.Printf("antigravity %s: loadCodeAssist: %v; using the project kept with the sign-in, its tier not known", g.user, err)
return googleProject{id: g.auth.Project}, nil
}
return googleProject{id: g.auth.Project, plan: load.plan(), tier: cur, paid: paid}, nil
}
if err != nil {
return googleProject{}, err
}
if load.CloudaicompanionProject != "" {
return googleProject{string(load.CloudaicompanionProject), load.plan()}, nil
return googleProject{id: string(load.CloudaicompanionProject), plan: load.plan(), tier: cur, paid: paid}, nil
}
tier := load.defaultTier()
if tier.ID == "" || tier.ID == "legacy-tier" {
@@ -637,7 +710,7 @@ func (g googleAccount) antigravityProject(ctx context.Context) (googleProject, e
}
return googleProject{}, errors.New(msg)
}
return googleProject{id, tier.Name}, nil
return googleProject{id: id, plan: tier.Name, tier: tier.ID, paid: paid}, nil
}
// onboardPoll is how long onboarding waits between asks; a var for tests.
@@ -854,6 +927,7 @@ func (g googleAccount) modelInfo(ctx context.Context) ([]googleModelInfo, error)
var res struct {
Models map[string]struct {
DisplayName string `json:"displayName"`
Disabled bool `json:"disabled"`
MaxTokens int `json:"maxTokens"`
MaxOutputTokens int `json:"maxOutputTokens"`
SupportsImages *bool `json:"supportsImages"`
@@ -869,12 +943,43 @@ func (g googleAccount) modelInfo(ctx context.Context) ([]googleModelInfo, error)
} `json:"groups"`
} `json:"agentModelSorts"`
}
if err := g.call(ctx, g.app.base, "fetchAvailableModels", map[string]any{"project": p.id}, &res, nil); err != nil {
// with the account's tier named, as Antigravity asks; a tier Google
// won't take from it is left out, down to none
sent := ""
for _, t := range append(p.entitlements(), "") {
body := map[string]any{"project": p.id}
if t != "" {
body["entitlement"] = map[string]any{"userTier": t}
}
if err = g.call(ctx, g.app.base, "fetchAvailableModels", body, &res, nil); err == nil {
sent = t
break
}
if ctx.Err() != nil {
return nil, err
}
if t != "" {
log.Printf("antigravity %s: fetchAvailableModels with entitlement %s: %v", g.user, t, err)
}
}
if err != nil {
return nil, err
}
var hidden, internal, disabled, claude []string
for id, m := range res.Models {
if antigravityHidden[id] || strings.HasPrefix(id, "chat_") || strings.HasPrefix(id, "tab_") {
switch {
case antigravityHidden[id]:
hidden = append(hidden, id)
continue
case strings.HasPrefix(id, "chat_") || strings.HasPrefix(id, "tab_"):
internal = append(internal, id)
continue
}
if m.Disabled {
disabled = append(disabled, id) // still listed, as before
}
if strings.HasPrefix(id, "claude") {
claude = append(claude, id)
}
mi := googleModelInfo{Model: catalog.Model{ID: id, Name: m.DisplayName,
Context: m.MaxTokens, Output: m.MaxOutputTokens, ImageInput: m.SupportsImages}, remaining: -1}
@@ -901,6 +1006,12 @@ func (g googleAccount) modelInfo(ctx context.Context) ([]googleModelInfo, error)
for i := range out {
out[i].picker = rank[out[i].ID]
}
for _, l := range [][]string{hidden, internal, disabled, claude} {
slices.Sort(l)
}
log.Printf("antigravity %s: fetchAvailableModels at %s (%s; project %q, current tier %q, paid tier %q, entitlement %q): %d models, %d kept; left out %d not for chat %v, %d completion-only %v; disabled %v; Claude %v",
g.user, g.app.base, g.app.userAgent(""), p.id, p.tier, p.paid, sent, len(res.Models), len(out),
len(hidden), hidden, len(internal), internal, disabled, claude)
} else {
var res struct {
Buckets []struct {
+9
View File
@@ -33,6 +33,10 @@ type fakeGoogle struct {
flags string // listExperiments' reply
models string // fetchAvailableModels' reply
summary string // retrieveUserQuotaSummary's reply
// fetchAvailableModels' status and reply for the body asked, in place
// of models
modelsFor func(body map[string]any) (int, string)
fetches []map[string]any
exps []map[string]any
heads map[string]http.Header
}
@@ -66,6 +70,11 @@ func (f *fakeGoogle) ServeHTTP(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, f.quota)
case strings.HasSuffix(r.URL.Path, ":retrieveUserQuotaSummary") && f.summary != "":
io.WriteString(w, f.summary)
case strings.HasSuffix(r.URL.Path, ":fetchAvailableModels") && f.modelsFor != nil:
f.fetches = append(f.fetches, body)
code, reply := f.modelsFor(body)
w.WriteHeader(code)
io.WriteString(w, reply)
case strings.HasSuffix(r.URL.Path, ":fetchAvailableModels") && f.models != "":
io.WriteString(w, f.models)
case strings.HasSuffix(r.URL.Path, ":listExperiments") && f.flags != "":