(ctx context.Context, auth *coreauth.Auth)
| 190 | } |
| 191 | |
| 192 | func 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() { |
no test coverage detected