Antigravity:
- Client ID 保留双 ID 支持(二进制确认两个都存在)
- Daily URL 去掉 .sandbox 后缀(日志确认)
- Redirect URI /callback → /oauth-callback(extension.js 确认)
- User-Agent 动态 OS/arch: antigravity/{ver} {os}/{arch}
- 新增 x-goog-api-client: gl-go/{goVer} gax-go/v2 grpc-go/1.81.0-dev
- googleapis 不再走 Node.js proxy → Go 原生 TLS(匹配真实 BoringCrypto)
- 新增 Go 后端心跳服务(每5分钟 loadCodeAssist + fetchAvailableModels)
- Dockerfile 切换 BoringCrypto 编译(CGO_ENABLED=1 GOEXPERIMENT=boringcrypto)
GeminiCLI:
- User-Agent 动态化: GeminiCLI/0.1.5 ({OS}; {ARCH})
- AI Studio 请求补上 User-Agent
Claude:
- CLI 版本 2.1.84, 包版本 0.74.0, 运行时 v24.3.0
- Token 交换 axios/1.13.6, timeout 15s
- proxy.js 仅服务 api.anthropic.com(Claude 专属)
架构变更:
- Node.js proxy 仅用于 Claude (api.anthropic.com)
- Antigravity (googleapis) 走 Go 原生 HTTP + GOST proxy
- TLS 指纹: Go BoringCrypto ≈ 真实 Antigravity BoringCrypto
66 lines
3.4 KiB
Go
66 lines
3.4 KiB
Go
// Package geminicli provides helpers for interacting with Gemini CLI tools.
|
|
package geminicli
|
|
|
|
import (
|
|
"fmt"
|
|
"runtime"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
AIStudioBaseURL = "https://generativelanguage.googleapis.com"
|
|
GeminiCliBaseURL = "https://cloudcode-pa.googleapis.com"
|
|
|
|
AuthorizeURL = "https://accounts.google.com/o/oauth2/v2/auth"
|
|
TokenURL = "https://oauth2.googleapis.com/token"
|
|
|
|
// AIStudioOAuthRedirectURI is the default redirect URI used for AI Studio OAuth.
|
|
// This matches the "copy/paste callback URL" flow used by OpenAI OAuth in this project.
|
|
// Note: You still need to register this redirect URI in your Google OAuth client
|
|
// unless you use an OAuth client type that permits localhost redirect URIs.
|
|
AIStudioOAuthRedirectURI = "http://localhost:1455/auth/callback"
|
|
|
|
// DefaultScopes for Code Assist (includes cloud-platform for API access plus userinfo scopes)
|
|
// Required by Google's Code Assist API.
|
|
DefaultCodeAssistScopes = "https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile"
|
|
|
|
// DefaultScopes for AI Studio (uses generativelanguage API with OAuth)
|
|
// Reference: https://ai.google.dev/gemini-api/docs/oauth
|
|
// For regular Google accounts, supports API calls to generativelanguage.googleapis.com
|
|
// Note: Google Auth platform currently documents the OAuth scope as
|
|
// https://www.googleapis.com/auth/generative-language.retriever (often with cloud-platform).
|
|
DefaultAIStudioScopes = "https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/generative-language.retriever"
|
|
|
|
// DefaultGoogleOneScopes (DEPRECATED, no longer used)
|
|
// Google One now always uses the built-in Gemini CLI client with DefaultCodeAssistScopes.
|
|
// This constant is kept for backward compatibility but is not actively used.
|
|
DefaultGoogleOneScopes = "https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/generative-language.retriever https://www.googleapis.com/auth/drive.readonly https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile"
|
|
|
|
// GeminiCLIRedirectURI is the redirect URI used by Gemini CLI for Code Assist OAuth.
|
|
GeminiCLIRedirectURI = "https://codeassist.google.com/authcode"
|
|
|
|
// GeminiCLIOAuthClientID/Secret are the public OAuth client credentials used by Google Gemini CLI.
|
|
// They enable the "login without creating your own OAuth client" experience, but Google may
|
|
// restrict which scopes are allowed for this client.
|
|
GeminiCLIOAuthClientID = "681255809395-oo8ft2oprdrnp9e3aqf6av3hmdib135j.apps.googleusercontent.com"
|
|
GeminiCLIOAuthClientSecret = "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"
|
|
|
|
// GeminiCLIOAuthClientSecretEnv is the environment variable name for the built-in client secret.
|
|
GeminiCLIOAuthClientSecretEnv = "GEMINI_CLI_OAUTH_CLIENT_SECRET"
|
|
|
|
SessionTTL = 30 * time.Minute
|
|
|
|
// GeminiCLIUserAgent mimics Gemini CLI to maximize compatibility with internal endpoints.
|
|
// Note: The real Gemini CLI uses OS-appropriate platform strings.
|
|
// Use GetGeminiCLIUserAgent() for runtime-aware User-Agent.
|
|
GeminiCLIUserAgent = "GeminiCLI/0.1.5"
|
|
)
|
|
|
|
// GetGeminiCLIUserAgent 返回带有正确平台信息的 Gemini CLI User-Agent
|
|
func GetGeminiCLIUserAgent() string {
|
|
osName := strings.Title(runtime.GOOS) // Darwin, Linux, Windows
|
|
arch := strings.ToUpper(runtime.GOARCH)
|
|
return fmt.Sprintf("GeminiCLI/0.1.5 (%s; %s)", osName, arch)
|
|
}
|