feat: 让 User-Agent 版本可通过环境变量 ANTIGRAVITY_USER_AGENT_VERSION 配置,默认 1.84.2
This commit is contained in:
@@ -33,7 +33,7 @@ func NewAPIRequestWithURL(ctx context.Context, baseURL, action, accessToken stri
|
|||||||
// 基础 Headers(与 Antigravity-Manager 保持一致,只设置这 3 个)
|
// 基础 Headers(与 Antigravity-Manager 保持一致,只设置这 3 个)
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("Authorization", "Bearer "+accessToken)
|
req.Header.Set("Authorization", "Bearer "+accessToken)
|
||||||
req.Header.Set("User-Agent", UserAgent)
|
req.Header.Set("User-Agent", GetUserAgent())
|
||||||
|
|
||||||
return req, nil
|
return req, nil
|
||||||
}
|
}
|
||||||
@@ -333,7 +333,7 @@ func (c *Client) LoadCodeAssist(ctx context.Context, accessToken string) (*LoadC
|
|||||||
}
|
}
|
||||||
req.Header.Set("Authorization", "Bearer "+accessToken)
|
req.Header.Set("Authorization", "Bearer "+accessToken)
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("User-Agent", UserAgent)
|
req.Header.Set("User-Agent", GetUserAgent())
|
||||||
|
|
||||||
resp, err := c.httpClient.Do(req)
|
resp, err := c.httpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -412,7 +412,7 @@ func (c *Client) OnboardUser(ctx context.Context, accessToken, tierID string) (s
|
|||||||
}
|
}
|
||||||
req.Header.Set("Authorization", "Bearer "+accessToken)
|
req.Header.Set("Authorization", "Bearer "+accessToken)
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("User-Agent", UserAgent)
|
req.Header.Set("User-Agent", GetUserAgent())
|
||||||
|
|
||||||
resp, err := c.httpClient.Do(req)
|
resp, err := c.httpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -532,7 +532,7 @@ func (c *Client) FetchAvailableModels(ctx context.Context, accessToken, projectI
|
|||||||
}
|
}
|
||||||
req.Header.Set("Authorization", "Bearer "+accessToken)
|
req.Header.Set("Authorization", "Bearer "+accessToken)
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("User-Agent", UserAgent)
|
req.Header.Set("User-Agent", GetUserAgent())
|
||||||
|
|
||||||
resp, err := c.httpClient.Do(req)
|
resp, err := c.httpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -32,9 +33,6 @@ const (
|
|||||||
"https://www.googleapis.com/auth/cclog " +
|
"https://www.googleapis.com/auth/cclog " +
|
||||||
"https://www.googleapis.com/auth/experimentsandconfigs"
|
"https://www.googleapis.com/auth/experimentsandconfigs"
|
||||||
|
|
||||||
// User-Agent(与 Antigravity-Manager 保持一致)
|
|
||||||
UserAgent = "antigravity/1.15.8 windows/amd64"
|
|
||||||
|
|
||||||
// Session 过期时间
|
// Session 过期时间
|
||||||
SessionTTL = 30 * time.Minute
|
SessionTTL = 30 * time.Minute
|
||||||
|
|
||||||
@@ -46,6 +44,21 @@ const (
|
|||||||
antigravityDailyBaseURL = "https://daily-cloudcode-pa.sandbox.googleapis.com"
|
antigravityDailyBaseURL = "https://daily-cloudcode-pa.sandbox.googleapis.com"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// defaultUserAgentVersion 可通过环境变量 ANTIGRAVITY_USER_AGENT_VERSION 配置,默认 1.84.2
|
||||||
|
var defaultUserAgentVersion = "1.84.2"
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
// 从环境变量读取版本号,未设置则使用默认值
|
||||||
|
if version := os.Getenv("ANTIGRAVITY_USER_AGENT_VERSION"); version != "" {
|
||||||
|
defaultUserAgentVersion = version
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetUserAgent 返回当前配置的 User-Agent
|
||||||
|
func GetUserAgent() string {
|
||||||
|
return fmt.Sprintf("antigravity/%s windows/amd64", defaultUserAgentVersion)
|
||||||
|
}
|
||||||
|
|
||||||
// BaseURLs 定义 Antigravity API 端点(与 Antigravity-Manager 保持一致)
|
// BaseURLs 定义 Antigravity API 端点(与 Antigravity-Manager 保持一致)
|
||||||
var BaseURLs = []string{
|
var BaseURLs = []string{
|
||||||
antigravityProdBaseURL, // prod (优先)
|
antigravityProdBaseURL, // prod (优先)
|
||||||
|
|||||||
Reference in New Issue
Block a user