fix(provider): 修复 Windsurf 原生工具桥接

This commit is contained in:
Entropy.Xu
2026-05-20 23:42:12 +08:00
parent 82637ad882
commit 129c7c90c0
30 changed files with 9090 additions and 194 deletions

View File

@@ -76,6 +76,24 @@ function getQuotaWindow(
return getQuotaWindows(quota).find(window => normalizeText(window.code)?.toLowerCase() === normalizedCode) ?? null
}
function positiveNumber(value: unknown): number | null {
return typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : null
}
function windsurfCooldownHasPositiveReset(quota: QuotaStatusSnapshot): boolean {
const rateLimit = quota.rate_limit
if (rateLimit && typeof rateLimit === 'object') {
const retryAfterMs = positiveNumber(rateLimit.retry_after_ms) ?? positiveNumber(rateLimit.retryAfterMs)
if (retryAfterMs != null) return true
}
const rateLimitWindow = getQuotaWindow(quota, 'rate_limit')
return (
positiveNumber(rateLimitWindow?.reset_seconds) != null
|| positiveNumber(rateLimitWindow?.reset_at) != null
)
}
function getQuotaWindowsByScope(
quota: QuotaStatusSnapshot | null | undefined,
scope: string,
@@ -219,7 +237,10 @@ function getWindsurfQuotaText(quota: QuotaStatusSnapshot): string | null {
if (code === 'banned' || code === 'forbidden' || code === 'quarantined') {
return normalizeText(quota.label) || '账号不可用'
}
if (code === 'rate_limited' || code === 'rate_limit' || code === 'cooldown') {
if (code === 'cooldown' && windsurfCooldownHasPositiveReset(quota)) {
return normalizeText(quota.label) || '冷却中'
}
if (code === 'rate_limited' || code === 'rate_limit') {
return normalizeText(quota.label) || '速率受限'
}
if (code === 'exhausted') {
@@ -258,6 +279,10 @@ function getWindsurfQuotaText(quota: QuotaStatusSnapshot): string | null {
if (parts.length > 0) return parts.join(' | ')
if (code === 'cooldown') {
return normalizeText(quota.label) || '冷却中'
}
return normalizeText(quota.label)
}