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.
42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
package gateway
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net/http"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// probeServer is the gateway a translated test is asked through; a var so
|
|
// a test can give it a client of its own.
|
|
var probeServer = New
|
|
|
|
// probeTranslated asks model on p, on proto, the smallest "hi" as an
|
|
// agent's request to it is asked — built in the account's envelope by the
|
|
// translator — and reads the reply to the model's first word, thought or
|
|
// tool call, or its error (provider.ProbeTranslatedVia).
|
|
func probeTranslated(ctx context.Context, p provider.Provider, proto provider.Protocol, model string) (int, error) {
|
|
ctx, cancel := context.WithCancel(ctx)
|
|
defer cancel() // the reader stops once the first word is in
|
|
req := &Request{MaxTokens: 16, Messages: []Message{{Role: "user", Parts: []Part{{Kind: Text, Text: "hi"}}}}}
|
|
events, code, msg := probeServer().askTranslated(p, proto, model, http.Header{}, http.Header{})(ctx, req)
|
|
if events == nil {
|
|
return code, errors.New(msg)
|
|
}
|
|
for ev := range events {
|
|
switch ev.Kind {
|
|
case KError:
|
|
return ev.Status, errors.New(ev.Text)
|
|
case KText, KThink, KToolStart, KImage:
|
|
return 0, nil
|
|
}
|
|
}
|
|
if err := ctx.Err(); err != nil {
|
|
return 0, err
|
|
}
|
|
return 0, nil
|
|
}
|
|
|
|
func init() { provider.ProbeTranslatedVia(probeTranslated) }
|