Files
magpie/internal/provider/translated_probe.go
T
yetone 8b56cf2d57 provider: an Antigravity or Gemini CLI sign-in's models can be tested, asked through the gateway's translator (lc on Discord)
lc: "antigravity的测试按钮不可用,别的供应商正常" — even after restarting
magpie and signing in again. A Google sign-in speaks only Code Assist, an
API whose envelope (project, model variant, request wrapper) the gateway
builds for each agent request. The provider test only sends its own tiny
request to a Chat/Responses/Anthropic/Gemini URL, so ModelTest() returned
"own-api" and the GUI turned Test models and each model's test off.

Now the gateway registers provider.ProbeTranslatedVia, the same pattern as
ProbeClaudeVia. For a Google Code Assist account, Test and TestModels ask
the model a "hi" (max 16 tokens) through askTranslated, the same path an
agent's request takes. The reply is read up to the first word, thought or
tool call, or until the vendor's error, which is reported with its status.
ModelTest() is "" for such an account, so the GUI's buttons are on. Plugin
providers and other own-API sign-ins (Kiro, Cursor…) are unchanged.

Run:
- TestAntigravityModelTest (internal/gateway): an Antigravity login and a
  fake Code Assist upstream. ModelTest is "". TestModels is OK on
  CodeAssist with the account named, and sent one :streamGenerateContent
  with project p1 and "hi". Provider Test is OK. A 403 PERMISSION_DENIED
  comes back as status 403 with its message. With testsTranslated forced
  false by hand (the old behaviour), it fails: "own-api".
- go test -tags nogui ./internal/{provider,gateway,gui} under a temp HOME
  with pinned caches: ok. gofmt -l clean. go vet darwin/linux/windows on
  those packages: ok.
- Not tried against a real Antigravity account. Live state was read only.
2026-10-10 15:08:14 +08:00

52 lines
2.0 KiB
Go

package provider
import (
"context"
"time"
)
// A Google sign-in (Antigravity, Gemini CLI) speaks Code Assist alone, an
// API the gateway builds every request for in the account's envelope, so
// a test had no request of its own to send: Test models was off and said
// to ask the model from an agent (lc on Discord: Antigravity's test button
// was unusable while every other provider's worked). Its test is asked as
// an agent's request is, by the gateway's own translator (TranslatedProbe),
// the smallest "hi" in that envelope, read to the model's first word.
// translatedProbe asks model on proto through the gateway's translator,
// and says how it failed: status, when the vendor answered one, and its
// message. The gateway sets it (ProbeTranslatedVia).
var translatedProbe func(ctx context.Context, p Provider, proto Protocol, model string) (status int, err error)
// ProbeTranslatedVia sets how a model only the gateway can ask is tested.
func ProbeTranslatedVia(f func(ctx context.Context, p Provider, proto Protocol, model string) (int, error)) {
translatedProbe = f
}
// testsTranslated is whether p's models are tested through the gateway's
// translator: a Google sign-in, on Code Assist, when the gateway is there
// to ask it.
func (p Provider) testsTranslated() bool {
return translatedProbe != nil && p.Account != nil && !p.IsPlugin() && p.Account.codeAssist != ""
}
// testTranslated is the test of model on a provider testsTranslated.
func (p Provider) testTranslated(ctx context.Context, model string) Result {
r := Result{Protocol: CodeAssist, Model: model, Account: p.Account.User}
if model == "" {
r.Error = "no model to try: expose one, or refresh the model list"
return r
}
ctx, cancel := context.WithTimeout(ctx, testWait)
defer cancel()
start := time.Now()
status, err := translatedProbe(ctx, p, CodeAssist, model)
r.Millis = time.Since(start).Milliseconds()
if err != nil {
r.Status, r.Error = status, err.Error()
return r
}
r.OK, r.Status = true, 200
return r
}