Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
5b787334
Commit
5b787334
authored
Jan 28, 2026
by
song
Browse files
antigravity: 转发优先 daily
parent
f761afb1
Changes
2
Hide whitespace changes
Inline
Side-by-side
backend/internal/pkg/antigravity/oauth.go
View file @
5b787334
...
...
@@ -40,17 +40,48 @@ const (
// URL 可用性 TTL(不可用 URL 的恢复时间)
URLAvailabilityTTL
=
5
*
time
.
Minute
// Antigravity API 端点
antigravityProdBaseURL
=
"https://cloudcode-pa.googleapis.com"
antigravityDailyBaseURL
=
"https://daily-cloudcode-pa.sandbox.googleapis.com"
)
// BaseURLs 定义 Antigravity API 端点(与 Antigravity-Manager 保持一致)
var
BaseURLs
=
[]
string
{
"https://cloudcode-pa.googleapis.com"
,
// prod (优先)
"https://daily-cloudcode-pa.sandbox.googleapis.com"
,
// daily sandbox (备用)
antigravityProdBaseURL
,
// prod (优先)
antigravityDailyBaseURL
,
// daily sandbox (备用)
}
// BaseURL 默认 URL(保持向后兼容)
var
BaseURL
=
BaseURLs
[
0
]
// ForwardBaseURLs 返回 API 转发用的 URL 顺序(daily 优先)
func
ForwardBaseURLs
()
[]
string
{
if
len
(
BaseURLs
)
==
0
{
return
nil
}
urls
:=
append
([]
string
(
nil
),
BaseURLs
...
)
dailyIndex
:=
-
1
for
i
,
url
:=
range
urls
{
if
url
==
antigravityDailyBaseURL
{
dailyIndex
=
i
break
}
}
if
dailyIndex
<=
0
{
return
urls
}
reordered
:=
make
([]
string
,
0
,
len
(
urls
))
reordered
=
append
(
reordered
,
urls
[
dailyIndex
])
for
i
,
url
:=
range
urls
{
if
i
==
dailyIndex
{
continue
}
reordered
=
append
(
reordered
,
url
)
}
return
reordered
}
// URLAvailability 管理 URL 可用性状态(带 TTL 自动恢复和动态优先级)
type
URLAvailability
struct
{
mu
sync
.
RWMutex
...
...
@@ -100,22 +131,37 @@ func (u *URLAvailability) IsAvailable(url string) bool {
// GetAvailableURLs 返回可用的 URL 列表
// 最近成功的 URL 优先,其他按默认顺序
func
(
u
*
URLAvailability
)
GetAvailableURLs
()
[]
string
{
return
u
.
GetAvailableURLsWithBase
(
BaseURLs
)
}
// GetAvailableURLsWithBase 返回可用的 URL 列表(使用自定义顺序)
// 最近成功的 URL 优先,其他按传入顺序
func
(
u
*
URLAvailability
)
GetAvailableURLsWithBase
(
baseURLs
[]
string
)
[]
string
{
u
.
mu
.
RLock
()
defer
u
.
mu
.
RUnlock
()
now
:=
time
.
Now
()
result
:=
make
([]
string
,
0
,
len
(
B
aseURLs
))
result
:=
make
([]
string
,
0
,
len
(
b
aseURLs
))
// 如果有最近成功的 URL 且可用,放在最前面
if
u
.
lastSuccess
!=
""
{
expiry
,
exists
:=
u
.
unavailable
[
u
.
lastSuccess
]
if
!
exists
||
now
.
After
(
expiry
)
{
result
=
append
(
result
,
u
.
lastSuccess
)
found
:=
false
for
_
,
url
:=
range
baseURLs
{
if
url
==
u
.
lastSuccess
{
found
=
true
break
}
}
if
found
{
expiry
,
exists
:=
u
.
unavailable
[
u
.
lastSuccess
]
if
!
exists
||
now
.
After
(
expiry
)
{
result
=
append
(
result
,
u
.
lastSuccess
)
}
}
}
// 添加其他可用的 URL(按
默认
顺序)
for
_
,
url
:=
range
B
aseURLs
{
// 添加其他可用的 URL(按
传入
顺序)
for
_
,
url
:=
range
b
aseURLs
{
// 跳过已添加的 lastSuccess
if
url
==
u
.
lastSuccess
{
continue
...
...
backend/internal/service/antigravity_gateway_service.go
View file @
5b787334
...
...
@@ -77,9 +77,10 @@ func (e *PromptTooLongError) Error() string {
// antigravityRetryLoop 执行带 URL fallback 的重试循环
func
antigravityRetryLoop
(
p
antigravityRetryLoopParams
)
(
*
antigravityRetryLoopResult
,
error
)
{
availableURLs
:=
antigravity
.
DefaultURLAvailability
.
GetAvailableURLs
()
baseURLs
:=
antigravity
.
ForwardBaseURLs
()
availableURLs
:=
antigravity
.
DefaultURLAvailability
.
GetAvailableURLsWithBase
(
baseURLs
)
if
len
(
availableURLs
)
==
0
{
availableURLs
=
antigravity
.
B
aseURLs
availableURLs
=
b
aseURLs
}
maxRetries
:=
p
.
maxRetries
if
maxRetries
<=
0
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment