MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / fetchModels

Function fetchModels

cmd/fetch_antigravity_models/main.go:192–289  ·  view source on GitHub ↗
(ctx context.Context, auth *coreauth.Auth)

Source from the content-addressed store, hash-verified

190}
191
192func fetchModels(ctx context.Context, auth *coreauth.Auth) []modelEntry {
193 accessToken := metaStringValue(auth.Metadata, "access_token")
194 if accessToken == "" {
195 fmt.Fprintln(os.Stderr, "error: no access token found in auth")
196 return nil
197 }
198
199 baseURLs := []string{antigravityBaseURLProd, antigravityBaseURLDaily, antigravitySandboxBaseURLDaily}
200
201 for _, baseURL := range baseURLs {
202 modelsURL := baseURL + antigravityModelsPath
203
204 var payload []byte
205 if auth != nil && auth.Metadata != nil {
206 if pid, ok := auth.Metadata["project_id"].(string); ok && strings.TrimSpace(pid) != "" {
207 payload = []byte(fmt.Sprintf(`{"project": "%s"}`, strings.TrimSpace(pid)))
208 }
209 }
210 if len(payload) == 0 {
211 payload = []byte(`{}`)
212 }
213
214 httpReq, errReq := http.NewRequestWithContext(ctx, http.MethodPost, modelsURL, strings.NewReader(string(payload)))
215 if errReq != nil {
216 continue
217 }
218 httpReq.Close = true
219 httpReq.Header.Set("Content-Type", "application/json")
220 httpReq.Header.Set("Authorization", "Bearer "+accessToken)
221 httpReq.Header.Set("User-Agent", misc.AntigravityUserAgent())
222
223 httpClient := &http.Client{Timeout: 30 * time.Second}
224 if transport, _, errProxy := proxyutil.BuildHTTPTransport(auth.ProxyURL); errProxy == nil && transport != nil {
225 httpClient.Transport = transport
226 }
227 httpResp, errDo := httpClient.Do(httpReq)
228 if errDo != nil {
229 continue
230 }
231
232 bodyBytes, errRead := io.ReadAll(httpResp.Body)
233 httpResp.Body.Close()
234 if errRead != nil {
235 continue
236 }
237
238 if httpResp.StatusCode < http.StatusOK || httpResp.StatusCode >= http.StatusMultipleChoices {
239 continue
240 }
241
242 result := gjson.GetBytes(bodyBytes, "models")
243 if !result.Exists() {
244 continue
245 }
246
247 var models []modelEntry
248
249 for originalName, modelData := range result.Map() {

Callers 1

mainFunction · 0.70

Calls 8

AntigravityUserAgentFunction · 0.92
BuildHTTPTransportFunction · 0.92
metaStringValueFunction · 0.70
DoMethod · 0.65
CloseMethod · 0.65
SetMethod · 0.45
StringMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected