mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 09:20:22 +08:00
feat(provider): 原生接入 Windsurf provider
This commit is contained in:
@@ -79,6 +79,137 @@ export interface OAuthBatchImportTaskStatusResponse {
|
||||
updated_at: number
|
||||
}
|
||||
|
||||
export type BatchImportCredentialsNormalization =
|
||||
| { ok: true; isBatch: boolean; credentials: string }
|
||||
| { ok: false; message: string }
|
||||
|
||||
function getImportCredentialLines(text: string): Array<{ lineNumber: number; text: string }> {
|
||||
return text
|
||||
.split('\n')
|
||||
.map((line, index) => ({ lineNumber: index + 1, text: line.trim() }))
|
||||
.filter(line => line.text && !line.text.startsWith('#'))
|
||||
}
|
||||
|
||||
function jsonParseErrorMessage(error: unknown): string {
|
||||
return error instanceof Error ? error.message : String(error)
|
||||
}
|
||||
|
||||
function normalizeBatchImportItem(
|
||||
value: unknown,
|
||||
location: string,
|
||||
): { ok: true; value: string | Record<string, unknown> } | { ok: false; message: string } {
|
||||
if (typeof value === 'string') {
|
||||
const trimmed = value.trim()
|
||||
if (trimmed) return { ok: true, value: trimmed }
|
||||
return { ok: false, message: `${location} 不能为空字符串` }
|
||||
}
|
||||
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
||||
return { ok: true, value: value as Record<string, unknown> }
|
||||
}
|
||||
return { ok: false, message: `${location} 必须是 JSON 对象或字符串` }
|
||||
}
|
||||
|
||||
function normalizeBatchImportArray(items: unknown[]): BatchImportCredentialsNormalization {
|
||||
if (items.length === 0) {
|
||||
return { ok: false, message: 'JSON 数组不能为空' }
|
||||
}
|
||||
|
||||
const normalized: Array<string | Record<string, unknown>> = []
|
||||
for (const [index, item] of items.entries()) {
|
||||
const result = normalizeBatchImportItem(item, `JSON 数组第 ${index + 1} 项`)
|
||||
if (!result.ok) return result
|
||||
normalized.push(result.value)
|
||||
}
|
||||
|
||||
return {
|
||||
ok: true,
|
||||
isBatch: true,
|
||||
credentials: JSON.stringify(normalized),
|
||||
}
|
||||
}
|
||||
|
||||
function parseImportCredentialLines(
|
||||
lines: Array<{ lineNumber: number; text: string }>,
|
||||
): BatchImportCredentialsNormalization {
|
||||
const normalized: Array<string | Record<string, unknown>> = []
|
||||
|
||||
for (const line of lines) {
|
||||
const firstChar = line.text[0]
|
||||
if (firstChar === '{' || firstChar === '[') {
|
||||
let parsed: unknown
|
||||
try {
|
||||
parsed = JSON.parse(line.text)
|
||||
} catch (error) {
|
||||
return {
|
||||
ok: false,
|
||||
message: `JSON Lines 格式无效,请检查第 ${line.lineNumber} 行: ${jsonParseErrorMessage(error)}`,
|
||||
}
|
||||
}
|
||||
|
||||
if (Array.isArray(parsed)) {
|
||||
for (const [index, item] of parsed.entries()) {
|
||||
const result = normalizeBatchImportItem(item, `第 ${line.lineNumber} 行数组第 ${index + 1} 项`)
|
||||
if (!result.ok) return result
|
||||
normalized.push(result.value)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
const result = normalizeBatchImportItem(parsed, `第 ${line.lineNumber} 行`)
|
||||
if (!result.ok) return result
|
||||
normalized.push(result.value)
|
||||
continue
|
||||
}
|
||||
|
||||
normalized.push(line.text)
|
||||
}
|
||||
|
||||
return normalizeBatchImportArray(normalized)
|
||||
}
|
||||
|
||||
export function normalizeBatchImportCredentials(text: string): BatchImportCredentialsNormalization {
|
||||
const trimmed = text.trim()
|
||||
if (!trimmed) {
|
||||
return { ok: false, message: '请输入凭据数据' }
|
||||
}
|
||||
|
||||
const firstChar = trimmed[0]
|
||||
if (firstChar === '[') {
|
||||
try {
|
||||
const parsed: unknown = JSON.parse(trimmed)
|
||||
if (!Array.isArray(parsed)) {
|
||||
return { ok: false, message: 'JSON 批量凭据必须是数组' }
|
||||
}
|
||||
return normalizeBatchImportArray(parsed)
|
||||
} catch (error) {
|
||||
return { ok: false, message: `JSON 数组格式无效: ${jsonParseErrorMessage(error)}` }
|
||||
}
|
||||
}
|
||||
|
||||
if (firstChar === '{') {
|
||||
try {
|
||||
const parsed: unknown = JSON.parse(trimmed)
|
||||
if (typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)) {
|
||||
return { ok: true, isBatch: false, credentials: trimmed }
|
||||
}
|
||||
return { ok: false, message: '单条 JSON 凭据必须是对象' }
|
||||
} catch (error) {
|
||||
const lines = getImportCredentialLines(trimmed)
|
||||
if (lines.length > 1) {
|
||||
return parseImportCredentialLines(lines)
|
||||
}
|
||||
return { ok: false, message: `JSON 格式无效: ${jsonParseErrorMessage(error)}` }
|
||||
}
|
||||
}
|
||||
|
||||
const lines = getImportCredentialLines(trimmed)
|
||||
if (lines.length > 1) {
|
||||
return parseImportCredentialLines(lines)
|
||||
}
|
||||
|
||||
return { ok: true, isBatch: false, credentials: trimmed }
|
||||
}
|
||||
|
||||
export async function refreshProviderOAuth(keyId: string): Promise<ProviderOAuthCompleteResponse> {
|
||||
const resp = await client.post(`/api/admin/provider-oauth/keys/${keyId}/refresh`)
|
||||
return resp.data
|
||||
@@ -102,8 +233,14 @@ export async function completeProviderLevelOAuth(
|
||||
export async function importProviderRefreshToken(
|
||||
providerId: string,
|
||||
data: {
|
||||
api_key?: string
|
||||
apiKey?: string
|
||||
token?: string
|
||||
auth_token?: string
|
||||
authToken?: string
|
||||
refresh_token?: string
|
||||
access_token?: string
|
||||
password?: string
|
||||
expires_at?: number
|
||||
name?: string
|
||||
proxy_node_id?: string
|
||||
@@ -150,7 +287,8 @@ export async function getBatchImportOAuthTaskStatus(
|
||||
export interface DeviceAuthorizeRequest {
|
||||
start_url?: string
|
||||
region?: string
|
||||
auth_type?: 'builder_id' | 'identity_center' | 'google' | 'github'
|
||||
auth_type?: 'builder_id' | 'identity_center' | 'google' | 'github' | 'browser'
|
||||
login_option?: 'google' | 'github' | 'default'
|
||||
redirect_uri?: string
|
||||
proxy_node_id?: string
|
||||
}
|
||||
@@ -170,6 +308,7 @@ export interface DeviceAuthorizeResponse {
|
||||
export interface DevicePollRequest {
|
||||
session_id: string
|
||||
callback_url?: string
|
||||
token?: string
|
||||
}
|
||||
|
||||
export interface DevicePollResponse {
|
||||
|
||||
@@ -5,6 +5,7 @@ import type {
|
||||
FailoverRulesConfig,
|
||||
PoolAdvancedConfig,
|
||||
ProviderConfig,
|
||||
ProviderType,
|
||||
ProviderWithEndpointsSummary,
|
||||
ProxyConfig,
|
||||
} from './types'
|
||||
@@ -92,7 +93,7 @@ export async function updateProvider(
|
||||
providerId: string,
|
||||
data: Partial<{
|
||||
name: string
|
||||
provider_type: 'custom' | 'vertex_ai' | 'claude_code' | 'codex' | 'chatgpt_web' | 'gemini_cli' | 'antigravity' | 'kiro' | 'grok'
|
||||
provider_type: ProviderType
|
||||
description: string | null
|
||||
website: string
|
||||
provider_priority: number
|
||||
@@ -127,7 +128,7 @@ export async function updateProvider(
|
||||
export async function createProvider(
|
||||
data: {
|
||||
name: string
|
||||
provider_type?: 'custom' | 'vertex_ai' | 'claude_code' | 'codex' | 'chatgpt_web' | 'gemini_cli' | 'antigravity' | 'kiro' | 'grok'
|
||||
provider_type?: ProviderType
|
||||
description?: string
|
||||
website?: string
|
||||
billing_type?: 'monthly_quota' | 'pay_as_you_go' | 'free_tier'
|
||||
|
||||
@@ -370,6 +370,32 @@ export interface KiroUpstreamMetadata {
|
||||
banned_at?: number // 封禁时间(Unix 时间戳,秒)
|
||||
}
|
||||
|
||||
// Windsurf 上游配额信息
|
||||
export interface WindsurfUpstreamMetadata {
|
||||
updated_at?: number
|
||||
plan_name?: string
|
||||
daily_remaining_percent?: number | null
|
||||
weekly_remaining_percent?: number | null
|
||||
daily_reset_at?: number | null
|
||||
weekly_reset_at?: number | null
|
||||
prompt_used?: number | null
|
||||
prompt_limit?: number | null
|
||||
prompt_remaining?: number | null
|
||||
flex_used?: number | null
|
||||
flex_limit?: number | null
|
||||
flex_remaining?: number | null
|
||||
allowed_models_count?: number | null
|
||||
models?: Array<{
|
||||
model_uid?: string | null
|
||||
label?: string | null
|
||||
provider?: string | null
|
||||
supports_images?: boolean | null
|
||||
credit_multiplier?: number | null
|
||||
}> | null
|
||||
rate_limit?: Record<string, unknown> | null
|
||||
last_error?: string | null
|
||||
}
|
||||
|
||||
export interface ChatGPTWebUpstreamMetadata {
|
||||
updated_at?: number // Unix 时间戳(秒)
|
||||
plan_type?: string | null
|
||||
@@ -439,6 +465,7 @@ export interface UpstreamMetadata {
|
||||
codex?: CodexUpstreamMetadata
|
||||
antigravity?: AntigravityUpstreamMetadata
|
||||
kiro?: KiroUpstreamMetadata
|
||||
windsurf?: WindsurfUpstreamMetadata
|
||||
chatgpt_web?: ChatGPTWebUpstreamMetadata
|
||||
grok?: GrokUpstreamMetadata
|
||||
balance_query?: BalanceQueryUpstreamMetadata
|
||||
@@ -569,7 +596,7 @@ export interface PublicEndpointStatusMonitorResponse {
|
||||
formats: PublicEndpointStatusMonitor[]
|
||||
}
|
||||
|
||||
export type ProviderType = 'custom' | 'claude_code' | 'codex' | 'chatgpt_web' | 'gemini_cli' | 'antigravity' | 'kiro' | 'grok' | 'vertex_ai'
|
||||
export type ProviderType = 'custom' | 'claude_code' | 'codex' | 'chatgpt_web' | 'gemini_cli' | 'antigravity' | 'kiro' | 'grok' | 'windsurf' | 'vertex_ai'
|
||||
|
||||
export interface ClaudeCodeAdvancedConfig {
|
||||
// 会话数量控制:null/undefined 表示不限制
|
||||
|
||||
@@ -66,6 +66,8 @@ export interface QuotaStatusSnapshot {
|
||||
plan_type?: string | null
|
||||
pool_tier?: string | null
|
||||
credits?: QuotaCreditsSnapshot | null
|
||||
allowed_models_count?: number | null
|
||||
rate_limit?: Record<string, unknown> | null
|
||||
windows?: QuotaWindowSnapshot[] | null
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
]"
|
||||
@click="switchMode('oauth')"
|
||||
>
|
||||
{{ isKiroProvider ? '设备授权' : '获取授权' }}
|
||||
{{ isDeviceBrowserProvider ? (isWindsurfProvider ? '浏览器登录' : '设备授权') : '获取授权' }}
|
||||
</button>
|
||||
<button
|
||||
class="flex-1 px-3 py-1.5 text-xs font-medium rounded-md transition-all"
|
||||
@@ -93,8 +93,132 @@
|
||||
class="space-y-4 transition-opacity duration-150"
|
||||
:class="mode === 'oauth' ? 'opacity-100' : 'opacity-0 pointer-events-none'"
|
||||
>
|
||||
<!-- Windsurf: 浏览器 session/poll 授权 -->
|
||||
<template v-if="isWindsurfProvider">
|
||||
<div class="space-y-4">
|
||||
<div class="grid grid-cols-3 gap-1.5">
|
||||
<button
|
||||
v-for="opt in ([
|
||||
{ key: 'default', label: '默认' },
|
||||
{ key: 'google', label: 'Google' },
|
||||
{ key: 'github', label: 'GitHub' },
|
||||
] as const)"
|
||||
:key="opt.key"
|
||||
class="h-8 text-xs font-medium rounded-md border transition-colors"
|
||||
:class="device.auth_type === opt.key
|
||||
? 'border-primary bg-primary/5 text-foreground'
|
||||
: 'border-border text-muted-foreground hover:text-foreground hover:border-foreground/20'"
|
||||
@click="selectWindsurfLoginOption(opt.key)"
|
||||
>
|
||||
{{ opt.label }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="device.status === 'error' || device.status === 'expired'"
|
||||
class="rounded-xl border border-destructive/20 bg-destructive/5 p-5"
|
||||
>
|
||||
<div class="flex flex-col items-center text-center space-y-3">
|
||||
<div class="w-10 h-10 rounded-full bg-destructive/10 flex items-center justify-center">
|
||||
<AlertCircle class="w-5 h-5 text-destructive" />
|
||||
</div>
|
||||
<div class="space-y-1">
|
||||
<p class="text-sm font-medium text-destructive">
|
||||
{{ device.status === 'expired' ? '授权已过期' : '授权失败' }}
|
||||
</p>
|
||||
<p class="text-xs text-muted-foreground">
|
||||
{{ device.error || '请重试' }}
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
@click="resetDevice"
|
||||
>
|
||||
重新开始
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-else-if="device.starting && !device.session_id"
|
||||
class="flex items-center justify-center py-12"
|
||||
>
|
||||
<div class="text-center">
|
||||
<div class="animate-spin rounded-full h-6 w-6 border-b-2 border-primary mx-auto mb-3" />
|
||||
<p class="text-xs text-muted-foreground">
|
||||
正在准备登录...
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-else
|
||||
class="space-y-4"
|
||||
>
|
||||
<div class="space-y-2">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="flex items-center justify-center w-4 h-4 rounded-full bg-primary/10 text-primary text-[10px] font-semibold shrink-0">1</span>
|
||||
<span class="text-xs font-medium">前往登录</span>
|
||||
</div>
|
||||
<div class="flex gap-2 pl-6">
|
||||
<Button
|
||||
size="sm"
|
||||
:disabled="device.starting || device.completing || !device.verification_uri_complete"
|
||||
@click="openDeviceVerificationUrl"
|
||||
>
|
||||
<ExternalLink class="w-3 h-3 mr-1" />
|
||||
打开
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
:disabled="device.starting || device.completing || !device.verification_uri_complete"
|
||||
@click="copyToClipboard(device.verification_uri_complete)"
|
||||
>
|
||||
<Copy class="w-3 h-3 mr-1" />
|
||||
复制
|
||||
</Button>
|
||||
<Button
|
||||
v-if="!device.session_id"
|
||||
size="sm"
|
||||
variant="outline"
|
||||
:disabled="device.starting"
|
||||
@click="startDeviceAuth"
|
||||
>
|
||||
开始
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="space-y-2">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="flex items-center justify-center w-4 h-4 rounded-full bg-primary/10 text-primary text-[10px] font-semibold shrink-0">2</span>
|
||||
<span class="text-xs font-medium">粘贴回调 URL 或 token</span>
|
||||
</div>
|
||||
<div class="pl-6">
|
||||
<Textarea
|
||||
v-model="device.callback_url"
|
||||
:disabled="device.completing"
|
||||
:placeholder="deviceCallbackPlaceholder"
|
||||
class="min-h-[150px] text-xs font-mono break-all !rounded-xl"
|
||||
spellcheck="false"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
v-if="device.session_id && device.status === 'pending'"
|
||||
class="pl-6 flex items-center gap-1.5 text-[11px] text-muted-foreground"
|
||||
>
|
||||
<div class="animate-spin rounded-full h-3 w-3 border-[1.5px] border-primary/30 border-t-primary" />
|
||||
<span>会话剩余 {{ deviceCountdownFormatted }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- Kiro: 设备授权模式 -->
|
||||
<template v-if="isKiroProvider">
|
||||
<template v-else-if="isKiroProvider">
|
||||
<div class="space-y-3">
|
||||
<!-- 授权类型切换 -->
|
||||
<div class="grid grid-cols-2 gap-1.5">
|
||||
@@ -198,7 +322,7 @@
|
||||
<Textarea
|
||||
v-model="device.callback_url"
|
||||
:disabled="device.completing"
|
||||
:placeholder="kiroSocialCallbackPlaceholder"
|
||||
:placeholder="deviceCallbackPlaceholder"
|
||||
class="h-full min-h-0 overflow-y-auto text-xs font-mono break-all !rounded-xl"
|
||||
spellcheck="false"
|
||||
/>
|
||||
@@ -527,15 +651,15 @@
|
||||
取消
|
||||
</Button>
|
||||
<Button
|
||||
v-if="mode === 'oauth' && showAuthorizationMode && !isKiroProvider"
|
||||
v-if="mode === 'oauth' && showAuthorizationMode && !isDeviceBrowserProvider"
|
||||
:disabled="!canCompleteOAuth"
|
||||
@click="handleCompleteOAuth"
|
||||
>
|
||||
{{ oauth.completing ? '验证中...' : '验证' }}
|
||||
</Button>
|
||||
<Button
|
||||
v-if="mode === 'oauth' && isKiroSocialManualCallbackMode"
|
||||
:disabled="!canCompleteKiroSocialDeviceAuth"
|
||||
v-if="mode === 'oauth' && isManualDeviceCallbackMode"
|
||||
:disabled="!canCompleteDeviceAuth"
|
||||
@click="completeDeviceAuth"
|
||||
>
|
||||
{{ device.completing ? '验证中...' : '验证' }}
|
||||
@@ -577,6 +701,7 @@ import {
|
||||
getBatchImportOAuthTaskStatus,
|
||||
startDeviceAuthorize,
|
||||
pollDeviceAuthorize,
|
||||
normalizeBatchImportCredentials,
|
||||
getAwsRegions,
|
||||
} from '@/api/endpoints'
|
||||
import type {
|
||||
@@ -678,7 +803,8 @@ let oauthInitRequestId = 0
|
||||
let oauthCompleteRequestId = 0
|
||||
|
||||
// 设备授权状态
|
||||
type DeviceAuthType = 'google' | 'github' | 'builder_id' | 'identity_center'
|
||||
type DeviceAuthType = 'default' | 'google' | 'github' | 'builder_id' | 'identity_center'
|
||||
type WindsurfLoginOption = 'default' | 'google' | 'github'
|
||||
|
||||
interface DeviceAuthState {
|
||||
auth_type: DeviceAuthType
|
||||
@@ -741,6 +867,8 @@ const isOpen = computed(() => props.open)
|
||||
|
||||
const isKiroProvider = computed(() => (props.providerType || '').toLowerCase() === 'kiro')
|
||||
const isGrokProvider = computed(() => (props.providerType || '').toLowerCase() === 'grok')
|
||||
const isWindsurfProvider = computed(() => (props.providerType || '').toLowerCase() === 'windsurf')
|
||||
const isDeviceBrowserProvider = computed(() => isKiroProvider.value || isWindsurfProvider.value)
|
||||
const showAuthorizationMode = computed(() => !isGrokProvider.value)
|
||||
const defaultMode = computed<DialogMode>(() => (isGrokProvider.value ? 'import' : 'oauth'))
|
||||
|
||||
@@ -752,14 +880,20 @@ const isKiroSocialManualCallbackMode = computed(() =>
|
||||
isKiroProvider.value && isSocialDeviceAuth.value
|
||||
)
|
||||
|
||||
const isKiroSocialManualCallbackPending = computed(() =>
|
||||
isKiroSocialManualCallbackMode.value
|
||||
const isManualDeviceCallbackMode = computed(() =>
|
||||
isKiroSocialManualCallbackMode.value || isWindsurfProvider.value
|
||||
)
|
||||
|
||||
const isManualDeviceCallbackPending = computed(() =>
|
||||
isManualDeviceCallbackMode.value
|
||||
&& device.value.session_id.length > 0
|
||||
&& device.value.status === 'pending'
|
||||
)
|
||||
|
||||
const kiroSocialCallbackPlaceholder = computed(() =>
|
||||
`http://localhost:49153/oauth/callback?login_option=${device.value.auth_type}&code=...&state=...`
|
||||
const deviceCallbackPlaceholder = computed(() =>
|
||||
isWindsurfProvider.value
|
||||
? `粘贴包含 token=...&state=... 的回调 URL;session token/apiKey 也可直接粘贴,普通 token 请用导入授权`
|
||||
: `http://localhost:49153/oauth/callback?login_option=${device.value.auth_type}&code=...&state=...`
|
||||
)
|
||||
|
||||
const deviceCountdownFormatted = computed(() => {
|
||||
@@ -779,8 +913,8 @@ const canCompleteOAuth = computed(() => {
|
||||
return !oauthBusy.value
|
||||
})
|
||||
|
||||
const canCompleteKiroSocialDeviceAuth = computed(() => {
|
||||
if (!isKiroSocialManualCallbackPending.value) return false
|
||||
const canCompleteDeviceAuth = computed(() => {
|
||||
if (!isManualDeviceCallbackPending.value) return false
|
||||
if (!device.value.callback_url.trim()) return false
|
||||
return !device.value.starting && !device.value.completing
|
||||
})
|
||||
@@ -957,6 +1091,7 @@ function resetDeviceRuntimeState() {
|
||||
}
|
||||
|
||||
function isKiroDeviceAuthOptionDisabled(_authType: DeviceAuthType): boolean {
|
||||
if (!isKiroProvider.value) return false
|
||||
if (device.value.starting) {
|
||||
return !isSocialDeviceAuth.value
|
||||
}
|
||||
@@ -967,6 +1102,14 @@ function isKiroDeviceAuthOptionDisabled(_authType: DeviceAuthType): boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
function selectWindsurfLoginOption(loginOption: WindsurfLoginOption) {
|
||||
if (!isWindsurfProvider.value) return
|
||||
if (device.value.auth_type === loginOption && device.value.session_id && device.value.status === 'pending') return
|
||||
deviceAuthRequestId += 1
|
||||
resetDeviceRuntimeState()
|
||||
device.value.auth_type = loginOption
|
||||
}
|
||||
|
||||
function selectDeviceAuthType(authType: DeviceAuthType) {
|
||||
if (device.value.auth_type === authType) return
|
||||
if (isKiroDeviceAuthOptionDisabled(authType)) return
|
||||
@@ -985,11 +1128,11 @@ function resetDevice() {
|
||||
totp.stop()
|
||||
const { auth_type, start_url, region, totp_secret } = device.value
|
||||
device.value = createInitialDeviceState()
|
||||
device.value.auth_type = auth_type
|
||||
device.value.auth_type = isWindsurfProvider.value ? (auth_type === 'google' || auth_type === 'github' ? auth_type : 'default') : auth_type
|
||||
device.value.start_url = start_url
|
||||
device.value.region = region
|
||||
device.value.totp_secret = totp_secret
|
||||
if (device.value.auth_type === 'google' || device.value.auth_type === 'github') {
|
||||
if (!isWindsurfProvider.value && (device.value.auth_type === 'google' || device.value.auth_type === 'github')) {
|
||||
void ensureKiroSocialDeviceAuth()
|
||||
}
|
||||
}
|
||||
@@ -1003,6 +1146,9 @@ function resetForm() {
|
||||
stopDevicePolling()
|
||||
totp.stop()
|
||||
device.value = createInitialDeviceState()
|
||||
if (isWindsurfProvider.value) {
|
||||
device.value.auth_type = 'default'
|
||||
}
|
||||
importText.value = ''
|
||||
importing.value = false
|
||||
importTask.value = null
|
||||
@@ -1046,7 +1192,7 @@ function openAuthorizationUrl() {
|
||||
async function initOAuth() {
|
||||
if (!props.providerId) return
|
||||
if (!showAuthorizationMode.value) return
|
||||
if (isKiroProvider.value) return
|
||||
if (isDeviceBrowserProvider.value) return
|
||||
if (oauth.value.starting) return
|
||||
|
||||
const requestId = ++oauthInitRequestId
|
||||
@@ -1095,35 +1241,12 @@ async function handleCompleteOAuth() {
|
||||
}
|
||||
}
|
||||
|
||||
// 检测是否为批量导入格式
|
||||
function isBatchImport(text: string): boolean {
|
||||
const trimmed = text.trim()
|
||||
// JSON 数组(含单元素数组)
|
||||
if (trimmed.startsWith('[')) {
|
||||
try {
|
||||
const parsed = JSON.parse(trimmed)
|
||||
return Array.isArray(parsed) && parsed.length >= 1
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
// 单个 JSON 对象(可能是 pretty-printed 多行)不算批量导入
|
||||
if (trimmed.startsWith('{')) {
|
||||
try {
|
||||
JSON.parse(trimmed)
|
||||
return false // 可解析的单个 JSON 对象,走单条导入
|
||||
} catch {
|
||||
// 解析失败:可能是多个 JSON 对象(JSON Lines 格式),继续检查
|
||||
}
|
||||
}
|
||||
// 多行文本(纯 Token 一行一个)
|
||||
const lines = trimmed.split('\n').filter(line => line.trim() && !line.trim().startsWith('#'))
|
||||
return lines.length > 1
|
||||
}
|
||||
|
||||
function parseImportText(text: string): {
|
||||
api_key?: string
|
||||
token?: string
|
||||
refresh_token?: string
|
||||
access_token?: string
|
||||
password?: string
|
||||
expires_at?: number
|
||||
name?: string
|
||||
email?: string
|
||||
@@ -1154,6 +1277,35 @@ function parseImportText(text: string): {
|
||||
}
|
||||
}
|
||||
|
||||
if (isWindsurfProvider.value) {
|
||||
try {
|
||||
const parsed: unknown = JSON.parse(trimmed)
|
||||
if (typeof parsed === 'object' && parsed !== null) {
|
||||
const obj = parsed as Record<string, unknown>
|
||||
const apiKey = normalizeStringField(obj.api_key) ?? normalizeStringField(obj.apiKey)
|
||||
const token = normalizeStringField(obj.token) ?? normalizeStringField(obj.auth_token) ?? normalizeStringField(obj.authToken)
|
||||
const refreshToken = normalizeStringField(obj.refresh_token) ?? normalizeStringField(obj.refreshToken)
|
||||
const accessToken = normalizeStringField(obj.access_token) ?? normalizeStringField(obj.accessToken)
|
||||
const email = normalizeStringField(obj.email)
|
||||
const password = normalizeStringField(obj.password)
|
||||
if (apiKey || token || refreshToken || accessToken || (email && password)) {
|
||||
return {
|
||||
api_key: apiKey,
|
||||
token,
|
||||
refresh_token: refreshToken,
|
||||
access_token: accessToken,
|
||||
email,
|
||||
password,
|
||||
name: normalizeStringField(obj.name) ?? email,
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Not JSON: treat as token copied from show-auth-token.
|
||||
}
|
||||
return { token: trimmed }
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed: unknown = JSON.parse(trimmed)
|
||||
if (typeof parsed === 'object' && parsed !== null) {
|
||||
@@ -1325,13 +1477,19 @@ async function handleImport() {
|
||||
return
|
||||
}
|
||||
|
||||
const normalizedCredentials = normalizeBatchImportCredentials(inputText)
|
||||
if (!normalizedCredentials.ok) {
|
||||
showError(normalizedCredentials.message, '格式错误')
|
||||
return
|
||||
}
|
||||
|
||||
importing.value = true
|
||||
let keepImporting = false
|
||||
try {
|
||||
const proxyNodeId = selectedProxyNodeId.value || undefined
|
||||
// Kiro 的单条 JSON 凭据也必须走 batch-import 路径,后端需要完整 auth_config。
|
||||
if (isKiroProvider.value || isBatchImport(inputText)) {
|
||||
const task = await startBatchImportOAuthTask(props.providerId, inputText, proxyNodeId)
|
||||
if (isKiroProvider.value || normalizedCredentials.isBatch) {
|
||||
const task = await startBatchImportOAuthTask(props.providerId, normalizedCredentials.credentials, proxyNodeId)
|
||||
importTask.value = {
|
||||
task_id: task.task_id,
|
||||
provider_id: props.providerId,
|
||||
@@ -1356,7 +1514,7 @@ async function handleImport() {
|
||||
scheduleImportPoll(task.task_id, 400)
|
||||
} else {
|
||||
// 单条导入
|
||||
const parsed = parseImportText(inputText)
|
||||
const parsed = parseImportText(normalizedCredentials.credentials)
|
||||
if (!parsed) {
|
||||
showError('无法解析输入内容,请检查格式', '格式错误')
|
||||
return
|
||||
@@ -1413,12 +1571,18 @@ async function startDeviceAuth() {
|
||||
device.value.starting = true
|
||||
device.value.error = ''
|
||||
try {
|
||||
const isWindsurf = isWindsurfProvider.value
|
||||
const isBuilderID = requestedAuthType === 'builder_id'
|
||||
const isSocial = requestedAuthType === 'google' || requestedAuthType === 'github'
|
||||
const windsurfLoginOption: WindsurfLoginOption = isSocial ? requestedAuthType : 'default'
|
||||
const authTypeForRequest = isWindsurf
|
||||
? 'browser'
|
||||
: (requestedAuthType === 'default' ? 'google' : requestedAuthType)
|
||||
const resp = await startDeviceAuthorize(props.providerId, {
|
||||
auth_type: requestedAuthType,
|
||||
start_url: isBuilderID ? BUILDER_ID_START_URL : (isSocial ? undefined : (device.value.start_url.trim() || undefined)),
|
||||
region: isBuilderID || isSocial ? BUILDER_ID_REGION : (device.value.region.trim() || undefined),
|
||||
auth_type: authTypeForRequest,
|
||||
login_option: isWindsurf ? windsurfLoginOption : undefined,
|
||||
start_url: isWindsurf ? undefined : (isBuilderID ? BUILDER_ID_START_URL : (isSocial ? undefined : (device.value.start_url.trim() || undefined))),
|
||||
region: isWindsurf ? undefined : (isBuilderID || isSocial ? BUILDER_ID_REGION : (device.value.region.trim() || undefined)),
|
||||
proxy_node_id: selectedProxyNodeId.value || undefined,
|
||||
})
|
||||
if (requestId !== deviceAuthRequestId || device.value.auth_type !== requestedAuthType) return
|
||||
@@ -1428,7 +1592,7 @@ async function startDeviceAuth() {
|
||||
device.value.verification_uri_complete = resp.verification_uri_complete
|
||||
device.value.expires_at = Date.now() + resp.expires_in * 1000
|
||||
device.value.interval = resp.interval || 5
|
||||
device.value.callback_required = resp.callback_required === true || isSocial
|
||||
device.value.callback_required = resp.callback_required === true || isSocial || isWindsurf
|
||||
device.value.status = 'pending'
|
||||
startCountdown()
|
||||
if (!device.value.callback_required) {
|
||||
@@ -1464,7 +1628,7 @@ function scheduleDevicePoll() {
|
||||
}
|
||||
|
||||
async function completeDeviceAuth() {
|
||||
if (device.value.completing || !canCompleteKiroSocialDeviceAuth.value) return
|
||||
if (device.value.completing || !canCompleteDeviceAuth.value) return
|
||||
device.value.completing = true
|
||||
try {
|
||||
await pollDevice(true)
|
||||
@@ -1473,13 +1637,39 @@ async function completeDeviceAuth() {
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeWindsurfSubmittedCredential(value: string): { callback_url?: string, token?: string } {
|
||||
const trimmed = value.trim()
|
||||
if (!trimmed) return {}
|
||||
if (/^https?:\/\//i.test(trimmed)) {
|
||||
return { callback_url: trimmed }
|
||||
}
|
||||
|
||||
const query = trimmed.replace(/^[?#&]+/, '')
|
||||
const params = new URLSearchParams(query)
|
||||
const hasTokenParam = ['token', 'auth_token', 'access_token'].some(key => params.has(key))
|
||||
const hasStateParam = params.has('state')
|
||||
if (hasTokenParam && hasStateParam) {
|
||||
return { callback_url: `https://windsurf.com/show-auth-token?${query}` }
|
||||
}
|
||||
if (hasTokenParam) {
|
||||
return { token: params.get('token') || params.get('auth_token') || params.get('access_token') || trimmed }
|
||||
}
|
||||
|
||||
return { token: trimmed }
|
||||
}
|
||||
|
||||
async function pollDevice(withCallback = false) {
|
||||
if (!props.providerId || !device.value.session_id || device.value.status !== 'pending') return
|
||||
|
||||
try {
|
||||
const submittedCredential = withCallback ? device.value.callback_url.trim() : ''
|
||||
const windsurfSubmitted = isWindsurfProvider.value
|
||||
? normalizeWindsurfSubmittedCredential(submittedCredential)
|
||||
: {}
|
||||
const result = await pollDeviceAuthorize(props.providerId, {
|
||||
session_id: device.value.session_id,
|
||||
callback_url: withCallback ? device.value.callback_url.trim() : undefined,
|
||||
callback_url: withCallback ? (windsurfSubmitted.callback_url || (!isWindsurfProvider.value ? submittedCredential : undefined)) : undefined,
|
||||
token: withCallback ? windsurfSubmitted.token : undefined,
|
||||
})
|
||||
|
||||
switch (result.status) {
|
||||
@@ -1535,7 +1725,9 @@ watch(() => props.open, (newOpen) => {
|
||||
if (!showAuthorizationMode.value) {
|
||||
return
|
||||
}
|
||||
if (isKiroProvider.value) {
|
||||
if (isWindsurfProvider.value) {
|
||||
device.value.auth_type = 'default'
|
||||
} else if (isKiroProvider.value) {
|
||||
void ensureKiroSocialDeviceAuth()
|
||||
} else {
|
||||
initOAuth()
|
||||
@@ -1552,7 +1744,11 @@ watch(
|
||||
mode.value = 'import'
|
||||
return
|
||||
}
|
||||
if (props.open && isKiroProvider.value && mode.value === 'oauth') {
|
||||
if (props.open && isWindsurfProvider.value && mode.value === 'oauth') {
|
||||
device.value.auth_type = ['default', 'google', 'github'].includes(device.value.auth_type)
|
||||
? device.value.auth_type
|
||||
: 'default'
|
||||
} else if (props.open && isKiroProvider.value && mode.value === 'oauth') {
|
||||
void ensureKiroSocialDeviceAuth()
|
||||
}
|
||||
},
|
||||
|
||||
@@ -960,6 +960,138 @@
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<!-- Windsurf 上游额度信息 -->
|
||||
<div
|
||||
v-if="provider.provider_type === 'windsurf' && (hasWindsurfQuotaDisplayData(key) || isWindsurfUnavailableKey(key) || isWindsurfExhaustedKey(key))"
|
||||
class="mt-2 p-2 rounded-md"
|
||||
:class="isWindsurfUnavailableKey(key) ? 'bg-destructive/10 border border-destructive/30' : (isWindsurfExhaustedKey(key) ? 'bg-amber-50 dark:bg-amber-950/20 border border-amber-200 dark:border-amber-900/50' : 'bg-muted/30')"
|
||||
>
|
||||
<div
|
||||
v-if="isWindsurfUnavailableKey(key)"
|
||||
class="flex items-center gap-2 text-destructive"
|
||||
>
|
||||
<ShieldX class="w-4 h-4 shrink-0" />
|
||||
<div class="flex-1 min-w-0">
|
||||
<div class="text-[11px] font-medium">
|
||||
账号不可用
|
||||
</div>
|
||||
<div
|
||||
v-if="getWindsurfQuotaDisplay(key)?.last_error"
|
||||
class="text-[10px] text-destructive/80 truncate"
|
||||
:title="getWindsurfQuotaDisplay(key)?.last_error || ''"
|
||||
>
|
||||
{{ getWindsurfQuotaDisplay(key)?.last_error }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<template v-else>
|
||||
<div
|
||||
v-if="isWindsurfExhaustedKey(key)"
|
||||
class="mb-2 flex items-center gap-2 text-amber-700 dark:text-amber-300"
|
||||
>
|
||||
<ShieldX class="w-4 h-4 shrink-0" />
|
||||
<div class="flex-1 min-w-0">
|
||||
<div class="text-[11px] font-medium">
|
||||
{{ getWindsurfQuotaStatusLabel(key) }}
|
||||
</div>
|
||||
<div
|
||||
v-if="getWindsurfQuotaDisplay(key)?.last_error"
|
||||
class="text-[10px] text-amber-700/80 dark:text-amber-300/80 truncate"
|
||||
:title="getWindsurfQuotaDisplay(key)?.last_error || ''"
|
||||
>
|
||||
{{ getWindsurfQuotaDisplay(key)?.last_error }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center justify-between mb-1">
|
||||
<span class="text-[10px] text-muted-foreground">账号配额</span>
|
||||
<div class="flex items-center gap-1">
|
||||
<RefreshCw
|
||||
v-if="refreshingQuota"
|
||||
class="w-3 h-3 text-muted-foreground/70 animate-spin"
|
||||
/>
|
||||
<span
|
||||
v-if="getWindsurfQuotaDisplay(key)?.updated_at"
|
||||
class="text-[9px] text-muted-foreground/70"
|
||||
>
|
||||
{{ formatKiroUpdatedAt(getWindsurfQuotaDisplay(key)?.updated_at || 0) }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<div v-if="getWindsurfQuotaDisplay(key)?.daily_remaining_percent !== undefined">
|
||||
<div class="flex items-center justify-between text-[10px] mb-0.5">
|
||||
<span class="text-muted-foreground">日额度</span>
|
||||
<span :class="getQuotaRemainingClass(getWindsurfQuotaDisplay(key)?.daily_used_percent || 0)">
|
||||
{{ (getWindsurfQuotaDisplay(key)?.daily_remaining_percent || 0).toFixed(1) }}%
|
||||
</span>
|
||||
</div>
|
||||
<div class="relative w-full h-1.5 bg-border rounded-full overflow-hidden">
|
||||
<div
|
||||
class="absolute left-0 top-0 h-full transition-all duration-300"
|
||||
:class="getQuotaRemainingBarColor(getWindsurfQuotaDisplay(key)?.daily_used_percent || 0)"
|
||||
:style="{ width: `${Math.max(getWindsurfQuotaDisplay(key)?.daily_remaining_percent || 0, 0)}%` }"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
v-if="getWindsurfQuotaDisplay(key)?.daily_reset_at"
|
||||
class="text-[9px] text-muted-foreground/70 mt-0.5"
|
||||
>
|
||||
{{ formatKiroResetTime(getWindsurfQuotaDisplay(key)?.daily_reset_at || 0) }}重置
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="getWindsurfQuotaDisplay(key)?.weekly_remaining_percent !== undefined">
|
||||
<div class="flex items-center justify-between text-[10px] mb-0.5">
|
||||
<span class="text-muted-foreground">周额度</span>
|
||||
<span :class="getQuotaRemainingClass(getWindsurfQuotaDisplay(key)?.weekly_used_percent || 0)">
|
||||
{{ (getWindsurfQuotaDisplay(key)?.weekly_remaining_percent || 0).toFixed(1) }}%
|
||||
</span>
|
||||
</div>
|
||||
<div class="relative w-full h-1.5 bg-border rounded-full overflow-hidden">
|
||||
<div
|
||||
class="absolute left-0 top-0 h-full transition-all duration-300"
|
||||
:class="getQuotaRemainingBarColor(getWindsurfQuotaDisplay(key)?.weekly_used_percent || 0)"
|
||||
:style="{ width: `${Math.max(getWindsurfQuotaDisplay(key)?.weekly_remaining_percent || 0, 0)}%` }"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
v-if="getWindsurfQuotaDisplay(key)?.weekly_reset_at"
|
||||
class="text-[9px] text-muted-foreground/70 mt-0.5"
|
||||
>
|
||||
{{ formatKiroResetTime(getWindsurfQuotaDisplay(key)?.weekly_reset_at || 0) }}重置
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-if="hasWindsurfPromptQuota(key) || hasWindsurfFlexQuota(key)"
|
||||
class="mt-2 flex items-center gap-3 text-[9px] text-muted-foreground/70"
|
||||
>
|
||||
<span v-if="hasWindsurfPromptQuota(key)">
|
||||
Prompt {{ formatKiroUsage(getWindsurfQuotaDisplay(key)?.prompt_used || 0) }} /
|
||||
{{ formatKiroUsage(getWindsurfQuotaDisplay(key)?.prompt_limit || 0) }}
|
||||
</span>
|
||||
<span v-if="hasWindsurfFlexQuota(key)">
|
||||
Flex {{ formatKiroUsage(getWindsurfQuotaDisplay(key)?.flex_used || 0) }} /
|
||||
{{ formatKiroUsage(getWindsurfQuotaDisplay(key)?.flex_limit || 0) }}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
v-if="hasWindsurfModelCount(key) || hasWindsurfModelPreview(key)"
|
||||
class="mt-2 flex items-center justify-between gap-2 text-[9px] text-muted-foreground/70"
|
||||
>
|
||||
<span>
|
||||
模型 {{ getWindsurfQuotaDisplay(key)?.allowed_models_count ?? getWindsurfQuotaDisplay(key)?.models?.length }} 个
|
||||
</span>
|
||||
<span
|
||||
v-if="getWindsurfModelPreview(key)"
|
||||
class="truncate"
|
||||
:title="getWindsurfModelPreview(key) || ''"
|
||||
>
|
||||
{{ getWindsurfModelPreview(key) }}
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<!-- ChatGPT Web 上游额度信息(生图配额) -->
|
||||
<div
|
||||
v-if="provider.provider_type === 'chatgpt_web' && hasChatGPTWebQuotaDisplayData(key)"
|
||||
@@ -1357,6 +1489,7 @@ import type {
|
||||
ChatGPTWebUpstreamMetadata,
|
||||
GrokUpstreamMetadata,
|
||||
KiroUpstreamMetadata,
|
||||
WindsurfUpstreamMetadata,
|
||||
QuotaStatusSnapshot,
|
||||
QuotaWindowSnapshot,
|
||||
} from '@/api/endpoints/types'
|
||||
@@ -2185,7 +2318,7 @@ async function handleClearOAuthInvalid(key: EndpointAPIKey) {
|
||||
}
|
||||
}
|
||||
|
||||
// Codex / Antigravity / Kiro / ChatGPT Web:打开抽屉后自动后台刷新(配额缓存缺失/过期,或 Token 即将过期时触发)
|
||||
// Codex / Antigravity / Kiro / Windsurf / ChatGPT Web:打开抽屉后自动后台刷新(配额缓存缺失/过期,或 Token 即将过期时触发)
|
||||
const AUTO_QUOTA_REFRESH_STALE_SECONDS = 5 * 60
|
||||
// 与后端 OAuth 懒刷新阈值对齐:到期前 2 分钟内视为需要刷新
|
||||
const AUTO_TOKEN_REFRESH_SKEW_SECONDS = 2 * 60
|
||||
@@ -2204,7 +2337,7 @@ function quotaSnapshotHasDisplayData(quota: QuotaStatusSnapshot | null | undefin
|
||||
|
||||
function getQuotaSnapshotForProvider(
|
||||
key: EndpointAPIKey,
|
||||
providerType: 'codex' | 'kiro' | 'antigravity' | 'chatgpt_web' | 'gemini_cli' | 'grok',
|
||||
providerType: 'codex' | 'kiro' | 'windsurf' | 'antigravity' | 'chatgpt_web' | 'gemini_cli' | 'grok',
|
||||
): QuotaStatusSnapshot | null {
|
||||
const quota = key.status_snapshot?.quota
|
||||
if (!quota) return null
|
||||
@@ -2463,11 +2596,137 @@ function getGrokQuotaDisplay(key: EndpointAPIKey): GrokQuotaDisplay | null {
|
||||
return Object.keys(display).length > 0 ? display : null
|
||||
}
|
||||
|
||||
type WindsurfQuotaDisplay = WindsurfUpstreamMetadata & {
|
||||
daily_used_percent?: number
|
||||
weekly_used_percent?: number
|
||||
}
|
||||
|
||||
function getWindsurfQuotaDisplay(key: EndpointAPIKey): WindsurfQuotaDisplay | null {
|
||||
const quota = getQuotaSnapshotForProvider(key, 'windsurf')
|
||||
const upstream = key.upstream_metadata?.windsurf
|
||||
if (!quota && !upstream) return null
|
||||
|
||||
const display: WindsurfQuotaDisplay = {}
|
||||
const updatedAt = getQuotaSnapshotUpdatedAt(quota) ?? upstream?.updated_at
|
||||
if (updatedAt !== undefined) display.updated_at = updatedAt
|
||||
if (quota?.plan_type) display.plan_name = quota.plan_type
|
||||
else if (upstream?.plan_name) display.plan_name = upstream.plan_name
|
||||
if (quota?.reason) display.last_error = quota.reason
|
||||
else if (upstream?.last_error) display.last_error = upstream.last_error
|
||||
if (typeof quota?.allowed_models_count === 'number') display.allowed_models_count = quota.allowed_models_count
|
||||
else if (typeof upstream?.allowed_models_count === 'number') display.allowed_models_count = upstream.allowed_models_count
|
||||
if (quota?.rate_limit) display.rate_limit = quota.rate_limit
|
||||
else if (upstream?.rate_limit) display.rate_limit = upstream.rate_limit
|
||||
if (Array.isArray(upstream?.models)) display.models = upstream.models
|
||||
|
||||
const dailyWindow = getQuotaWindow(quota, 'daily')
|
||||
const dailyRemaining = getQuotaWindowRemainingPercent(dailyWindow)
|
||||
const dailyUsed = getQuotaWindowUsedPercent(dailyWindow)
|
||||
if (dailyRemaining !== undefined) display.daily_remaining_percent = dailyRemaining
|
||||
else if (typeof upstream?.daily_remaining_percent === 'number') display.daily_remaining_percent = upstream.daily_remaining_percent
|
||||
if (dailyUsed !== undefined) display.daily_used_percent = dailyUsed
|
||||
else if (typeof upstream?.daily_remaining_percent === 'number') display.daily_used_percent = Math.max(100 - upstream.daily_remaining_percent, 0)
|
||||
const dailyResetAt = getQuotaWindowResetAt(dailyWindow)
|
||||
if (dailyResetAt !== undefined) display.daily_reset_at = dailyResetAt
|
||||
else if (typeof upstream?.daily_reset_at === 'number') display.daily_reset_at = upstream.daily_reset_at
|
||||
|
||||
const weeklyWindow = getQuotaWindow(quota, 'weekly')
|
||||
const weeklyRemaining = getQuotaWindowRemainingPercent(weeklyWindow)
|
||||
const weeklyUsed = getQuotaWindowUsedPercent(weeklyWindow)
|
||||
if (weeklyRemaining !== undefined) display.weekly_remaining_percent = weeklyRemaining
|
||||
else if (typeof upstream?.weekly_remaining_percent === 'number') display.weekly_remaining_percent = upstream.weekly_remaining_percent
|
||||
if (weeklyUsed !== undefined) display.weekly_used_percent = weeklyUsed
|
||||
else if (typeof upstream?.weekly_remaining_percent === 'number') display.weekly_used_percent = Math.max(100 - upstream.weekly_remaining_percent, 0)
|
||||
const weeklyResetAt = getQuotaWindowResetAt(weeklyWindow)
|
||||
if (weeklyResetAt !== undefined) display.weekly_reset_at = weeklyResetAt
|
||||
else if (typeof upstream?.weekly_reset_at === 'number') display.weekly_reset_at = upstream.weekly_reset_at
|
||||
|
||||
const promptWindow = getQuotaWindow(quota, 'prompt')
|
||||
if (typeof promptWindow?.used_value === 'number') display.prompt_used = promptWindow.used_value
|
||||
else if (typeof upstream?.prompt_used === 'number') display.prompt_used = upstream.prompt_used
|
||||
if (typeof promptWindow?.limit_value === 'number') display.prompt_limit = promptWindow.limit_value
|
||||
else if (typeof upstream?.prompt_limit === 'number') display.prompt_limit = upstream.prompt_limit
|
||||
if (typeof promptWindow?.remaining_value === 'number') display.prompt_remaining = promptWindow.remaining_value
|
||||
else if (typeof upstream?.prompt_remaining === 'number') display.prompt_remaining = upstream.prompt_remaining
|
||||
|
||||
const flexWindow = getQuotaWindow(quota, 'flex')
|
||||
if (typeof flexWindow?.used_value === 'number') display.flex_used = flexWindow.used_value
|
||||
else if (typeof upstream?.flex_used === 'number') display.flex_used = upstream.flex_used
|
||||
if (typeof flexWindow?.limit_value === 'number') display.flex_limit = flexWindow.limit_value
|
||||
else if (typeof upstream?.flex_limit === 'number') display.flex_limit = upstream.flex_limit
|
||||
if (typeof flexWindow?.remaining_value === 'number') display.flex_remaining = flexWindow.remaining_value
|
||||
else if (typeof upstream?.flex_remaining === 'number') display.flex_remaining = upstream.flex_remaining
|
||||
|
||||
return Object.keys(display).length > 0 ? display : null
|
||||
}
|
||||
|
||||
function hasGrokQuotaDisplayData(key: EndpointAPIKey): boolean {
|
||||
const grok = getGrokQuotaDisplay(key)
|
||||
return !!grok && (grok.usage_percentage !== undefined || grok.usage_limit !== undefined)
|
||||
}
|
||||
|
||||
function hasWindsurfQuotaDisplayData(key: EndpointAPIKey): boolean {
|
||||
const windsurf = getWindsurfQuotaDisplay(key)
|
||||
return !!windsurf && (
|
||||
windsurf.daily_remaining_percent !== undefined
|
||||
|| windsurf.weekly_remaining_percent !== undefined
|
||||
|| windsurf.prompt_limit !== undefined
|
||||
|| windsurf.flex_limit !== undefined
|
||||
|| windsurf.allowed_models_count !== undefined
|
||||
|| windsurf.rate_limit !== undefined
|
||||
|| !!windsurf.last_error
|
||||
|| (Array.isArray(windsurf.models) && windsurf.models.length > 0)
|
||||
)
|
||||
}
|
||||
|
||||
function isWindsurfUnavailableKey(key: EndpointAPIKey): boolean {
|
||||
const code = String(getQuotaSnapshotForProvider(key, 'windsurf')?.code || '').trim().toLowerCase()
|
||||
return code === 'banned' || code === 'forbidden' || code === 'quarantined'
|
||||
}
|
||||
|
||||
function isWindsurfExhaustedKey(key: EndpointAPIKey): boolean {
|
||||
const code = String(getQuotaSnapshotForProvider(key, 'windsurf')?.code || '').trim().toLowerCase()
|
||||
return code === 'exhausted' || code === 'rate_limited' || code === 'rate_limit' || code === 'cooldown'
|
||||
}
|
||||
|
||||
function getWindsurfQuotaStatusLabel(key: EndpointAPIKey): string {
|
||||
const quota = getQuotaSnapshotForProvider(key, 'windsurf')
|
||||
const label = quota?.label?.trim()
|
||||
if (label) return label
|
||||
const code = String(quota?.code || '').trim().toLowerCase()
|
||||
return code === 'rate_limited' || code === 'rate_limit' || code === 'cooldown' ? '速率受限' : '额度耗尽'
|
||||
}
|
||||
|
||||
function getWindsurfModelPreview(key: EndpointAPIKey): string | null {
|
||||
const models = getWindsurfQuotaDisplay(key)?.models
|
||||
if (!Array.isArray(models) || models.length === 0) return null
|
||||
return models
|
||||
.slice(0, 3)
|
||||
.map(model => (model.label || model.model_uid || '').trim())
|
||||
.filter(Boolean)
|
||||
.join(' / ') || null
|
||||
}
|
||||
|
||||
function hasFiniteNumber(value: unknown): value is number {
|
||||
return typeof value === 'number' && Number.isFinite(value)
|
||||
}
|
||||
|
||||
function hasWindsurfPromptQuota(key: EndpointAPIKey): boolean {
|
||||
return hasFiniteNumber(getWindsurfQuotaDisplay(key)?.prompt_limit)
|
||||
}
|
||||
|
||||
function hasWindsurfFlexQuota(key: EndpointAPIKey): boolean {
|
||||
return hasFiniteNumber(getWindsurfQuotaDisplay(key)?.flex_limit)
|
||||
}
|
||||
|
||||
function hasWindsurfModelCount(key: EndpointAPIKey): boolean {
|
||||
return hasFiniteNumber(getWindsurfQuotaDisplay(key)?.allowed_models_count)
|
||||
}
|
||||
|
||||
function hasWindsurfModelPreview(key: EndpointAPIKey): boolean {
|
||||
return !!getWindsurfModelPreview(key)
|
||||
}
|
||||
|
||||
type ChatGPTWebQuotaDisplay = ChatGPTWebUpstreamMetadata & {
|
||||
image_quota_remaining_percent?: number
|
||||
image_quota_used_percent?: number
|
||||
@@ -2680,7 +2939,7 @@ function shouldAutoRefreshCodexQuota(): boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
// 检查 OAuth Token 是否即将过期(Codex / Antigravity / Kiro / ChatGPT Web)
|
||||
// 检查 OAuth Token 是否即将过期(Codex / Antigravity / Kiro / Windsurf / ChatGPT Web)
|
||||
function isTokenExpiringSoon(key: EndpointAPIKey, now: number): boolean {
|
||||
const oauthCode = String(key.status_snapshot?.oauth?.code || '').trim().toLowerCase()
|
||||
if (oauthCode && oauthCode !== 'valid' && oauthCode !== 'expiring') {
|
||||
@@ -2757,6 +3016,28 @@ function shouldAutoRefreshGrokQuota(): boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
function shouldAutoRefreshWindsurfQuota(): boolean {
|
||||
if (provider.value?.provider_type !== 'windsurf') return false
|
||||
const now = Math.floor(Date.now() / 1000)
|
||||
|
||||
for (const { key } of allKeys.value) {
|
||||
if (!key.is_active) continue
|
||||
|
||||
if (isTokenExpiringSoon(key, now)) return true
|
||||
|
||||
if (!hasWindsurfQuotaDisplayData(key)) {
|
||||
return true
|
||||
}
|
||||
|
||||
const updatedAt = getWindsurfQuotaDisplay(key)?.updated_at
|
||||
if (typeof updatedAt !== 'number' || (now - updatedAt) > AUTO_QUOTA_REFRESH_STALE_SECONDS) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
function shouldAutoRefreshChatGPTWebQuota(): boolean {
|
||||
if (provider.value?.provider_type !== 'chatgpt_web') return false
|
||||
const now = Math.floor(Date.now() / 1000)
|
||||
@@ -2856,14 +3137,14 @@ function applyQuotaResults(
|
||||
return applied
|
||||
}
|
||||
|
||||
// 通用的自动刷新配额函数(支持 Codex、Antigravity、Kiro 和 ChatGPT Web)
|
||||
// 通用的自动刷新配额函数(支持 Codex、Antigravity、Kiro、Windsurf 和 ChatGPT Web)
|
||||
async function autoRefreshQuotaInBackground(options: { ignoreCooldown?: boolean } = {}) {
|
||||
const providerId = props.providerId
|
||||
if (!providerId) return
|
||||
if (refreshingQuota.value) return
|
||||
|
||||
const providerType = provider.value?.provider_type
|
||||
if (providerType !== 'codex' && providerType !== 'antigravity' && providerType !== 'kiro' && providerType !== 'chatgpt_web' && providerType !== 'grok') return
|
||||
if (providerType !== 'codex' && providerType !== 'antigravity' && providerType !== 'kiro' && providerType !== 'windsurf' && providerType !== 'chatgpt_web' && providerType !== 'grok') return
|
||||
|
||||
// 检查是否需要刷新
|
||||
let shouldRefresh = false
|
||||
@@ -2875,6 +3156,8 @@ async function autoRefreshQuotaInBackground(options: { ignoreCooldown?: boolean
|
||||
shouldRefresh = shouldAutoRefreshKiroQuota()
|
||||
} else if (providerType === 'grok') {
|
||||
shouldRefresh = shouldAutoRefreshGrokQuota()
|
||||
} else if (providerType === 'windsurf') {
|
||||
shouldRefresh = shouldAutoRefreshWindsurfQuota()
|
||||
} else if (providerType === 'chatgpt_web') {
|
||||
shouldRefresh = shouldAutoRefreshChatGPTWebQuota()
|
||||
}
|
||||
@@ -2890,6 +3173,8 @@ async function autoRefreshQuotaInBackground(options: { ignoreCooldown?: boolean
|
||||
hadCachedQuota = allKeys.value.some(({ key }) => key.is_active && hasKiroQuotaDisplayData(key))
|
||||
} else if (providerType === 'grok') {
|
||||
hadCachedQuota = allKeys.value.some(({ key }) => key.is_active && hasGrokQuotaDisplayData(key))
|
||||
} else if (providerType === 'windsurf') {
|
||||
hadCachedQuota = allKeys.value.some(({ key }) => key.is_active && hasWindsurfQuotaDisplayData(key))
|
||||
} else if (providerType === 'chatgpt_web') {
|
||||
hadCachedQuota = allKeys.value.some(({ key }) => key.is_active && hasChatGPTWebQuotaDisplayData(key))
|
||||
}
|
||||
|
||||
@@ -66,6 +66,9 @@
|
||||
<SelectItem value="kiro">
|
||||
Kiro
|
||||
</SelectItem>
|
||||
<SelectItem value="windsurf">
|
||||
Windsurf
|
||||
</SelectItem>
|
||||
<SelectItem value="antigravity">
|
||||
Antigravity
|
||||
</SelectItem>
|
||||
@@ -96,6 +99,9 @@
|
||||
<SelectItem value="kiro">
|
||||
Kiro
|
||||
</SelectItem>
|
||||
<SelectItem value="windsurf">
|
||||
Windsurf
|
||||
</SelectItem>
|
||||
<SelectItem value="antigravity">
|
||||
Antigravity
|
||||
</SelectItem>
|
||||
@@ -342,6 +348,7 @@ import {
|
||||
createProvider,
|
||||
normalizePoolAdvancedConfig,
|
||||
updateProvider,
|
||||
type ProviderType,
|
||||
type ProviderWithEndpointsSummary,
|
||||
} from '@/api/endpoints'
|
||||
import { parseApiError } from '@/utils/errorParser'
|
||||
@@ -377,7 +384,7 @@ const defaultPriority = computed(() => {
|
||||
// 表单数据
|
||||
const form = ref({
|
||||
name: '',
|
||||
provider_type: 'custom' as 'custom' | 'vertex_ai' | 'claude_code' | 'codex' | 'chatgpt_web' | 'gemini_cli' | 'antigravity' | 'kiro' | 'grok',
|
||||
provider_type: 'custom' as ProviderType,
|
||||
description: '',
|
||||
website: '',
|
||||
// 计费配置
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { normalizeBatchImportCredentials } from '@/api/endpoints/provider_oauth'
|
||||
import { isKeyManagedProviderType, isOAuthAccountProviderType } from '../providerTypeUtils'
|
||||
|
||||
describe('providerTypeUtils', () => {
|
||||
@@ -14,4 +15,47 @@ describe('providerTypeUtils', () => {
|
||||
expect(isOAuthAccountProviderType('GROK')).toBe(true)
|
||||
expect(isKeyManagedProviderType('grok')).toBe(false)
|
||||
})
|
||||
|
||||
it('treats Windsurf as an OAuth account provider', () => {
|
||||
expect(isOAuthAccountProviderType('windsurf')).toBe(true)
|
||||
expect(isOAuthAccountProviderType('Windsurf')).toBe(true)
|
||||
expect(isKeyManagedProviderType('windsurf')).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('normalizeBatchImportCredentials', () => {
|
||||
it('converts JSON Lines objects into a JSON array payload', () => {
|
||||
const result = normalizeBatchImportCredentials([
|
||||
'{"refresh_token":"rt-1","email":"one@example.com"}',
|
||||
'{"token":"token-2","email":"two@example.com"}',
|
||||
].join('\n'))
|
||||
|
||||
expect(result).toEqual({
|
||||
ok: true,
|
||||
isBatch: true,
|
||||
credentials: JSON.stringify([
|
||||
{ refresh_token: 'rt-1', email: 'one@example.com' },
|
||||
{ token: 'token-2', email: 'two@example.com' },
|
||||
]),
|
||||
})
|
||||
})
|
||||
|
||||
it('rejects malformed JSON Lines instead of treating them as raw tokens', () => {
|
||||
const result = normalizeBatchImportCredentials('{"refresh_token":"rt-1"}\n{"refresh_token":')
|
||||
|
||||
expect(result.ok).toBe(false)
|
||||
if (!result.ok) {
|
||||
expect(result.message).toContain('第 2 行')
|
||||
}
|
||||
})
|
||||
|
||||
it('converts multiple raw token lines into a JSON array payload', () => {
|
||||
const result = normalizeBatchImportCredentials('token-a\n# comment\ntoken-b')
|
||||
|
||||
expect(result).toEqual({
|
||||
ok: true,
|
||||
isBatch: true,
|
||||
credentials: JSON.stringify(['token-a', 'token-b']),
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -12,6 +12,7 @@ const oauthAccountProviderTypes = new Set([
|
||||
'antigravity',
|
||||
'kiro',
|
||||
'grok',
|
||||
'windsurf',
|
||||
])
|
||||
|
||||
export const isOAuthAccountProviderType = (providerType?: string | null): boolean =>
|
||||
|
||||
@@ -104,4 +104,74 @@ describe('providerKeyQuota', () => {
|
||||
},
|
||||
}, 'grok')).toBe('Auto剩余 40.0% (60/150) | Heavy剩余 0.0% (0/20)')
|
||||
})
|
||||
|
||||
it('surfaces Windsurf hard account states', () => {
|
||||
expect(getQuotaDisplayText({
|
||||
status_snapshot: {
|
||||
quota: {
|
||||
provider_type: 'windsurf',
|
||||
code: 'quarantined',
|
||||
label: '账号隔离中',
|
||||
exhausted: false,
|
||||
},
|
||||
},
|
||||
}, 'windsurf')).toBe('账号隔离中')
|
||||
|
||||
expect(getQuotaDisplayText({
|
||||
status_snapshot: {
|
||||
quota: {
|
||||
provider_type: 'windsurf',
|
||||
code: 'cooldown',
|
||||
label: '冷却中',
|
||||
exhausted: false,
|
||||
},
|
||||
},
|
||||
}, 'windsurf')).toBe('冷却中')
|
||||
})
|
||||
|
||||
it('includes Windsurf quota windows and model availability in display text', () => {
|
||||
expect(getQuotaDisplayText({
|
||||
status_snapshot: {
|
||||
quota: {
|
||||
provider_type: 'windsurf',
|
||||
code: 'ok',
|
||||
exhausted: false,
|
||||
allowed_models_count: 7,
|
||||
windows: [
|
||||
{
|
||||
code: 'daily',
|
||||
remaining_ratio: 0.75,
|
||||
},
|
||||
{
|
||||
code: 'weekly',
|
||||
remaining_ratio: 0.5,
|
||||
},
|
||||
{
|
||||
code: 'prompt',
|
||||
remaining_value: 12,
|
||||
limit_value: 20,
|
||||
},
|
||||
{
|
||||
code: 'flex',
|
||||
used_value: 2,
|
||||
limit_value: 5,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
}, 'windsurf')).toBe('日剩余 75.0% | 周剩余 50.0% | Prompt 剩余 12/20 | Flex 剩余 3/5 | 可用模型 7 个')
|
||||
})
|
||||
|
||||
it('uses Windsurf model availability when no quota window is present', () => {
|
||||
expect(getQuotaDisplayText({
|
||||
status_snapshot: {
|
||||
quota: {
|
||||
provider_type: 'windsurf',
|
||||
code: 'ok',
|
||||
exhausted: false,
|
||||
allowed_models_count: 3,
|
||||
},
|
||||
},
|
||||
}, 'windsurf')).toBe('可用模型 3 个')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -214,6 +214,53 @@ function getGrokQuotaText(quota: QuotaStatusSnapshot): string | null {
|
||||
return normalizeText(quota.label)
|
||||
}
|
||||
|
||||
function getWindsurfQuotaText(quota: QuotaStatusSnapshot): string | null {
|
||||
const code = normalizeText(quota.code)?.toLowerCase()
|
||||
if (code === 'banned' || code === 'forbidden' || code === 'quarantined') {
|
||||
return normalizeText(quota.label) || '账号不可用'
|
||||
}
|
||||
if (code === 'rate_limited' || code === 'rate_limit' || code === 'cooldown') {
|
||||
return normalizeText(quota.label) || '速率受限'
|
||||
}
|
||||
if (code === 'exhausted') {
|
||||
return normalizeText(quota.label) || '额度已耗尽'
|
||||
}
|
||||
|
||||
const parts: string[] = []
|
||||
const dailyRemaining = getQuotaWindowRemainingPercent(getQuotaWindow(quota, 'daily'))
|
||||
const weeklyRemaining = getQuotaWindowRemainingPercent(getQuotaWindow(quota, 'weekly'))
|
||||
if (dailyRemaining != null) parts.push(`日剩余 ${formatPercent(dailyRemaining)}`)
|
||||
if (weeklyRemaining != null) parts.push(`周剩余 ${formatPercent(weeklyRemaining)}`)
|
||||
|
||||
for (const [label, code] of [
|
||||
['Prompt', 'prompt'],
|
||||
['Flex', 'flex'],
|
||||
] as const) {
|
||||
const window = getQuotaWindow(quota, code)
|
||||
if (!window) continue
|
||||
if (typeof window.remaining_value === 'number' && typeof window.limit_value === 'number' && window.limit_value > 0) {
|
||||
parts.push(`${label} 剩余 ${formatQuotaValue(window.remaining_value)}/${formatQuotaValue(window.limit_value)}`)
|
||||
continue
|
||||
}
|
||||
if (typeof window.used_value === 'number' && typeof window.limit_value === 'number' && window.limit_value > 0) {
|
||||
parts.push(`${label} 剩余 ${formatQuotaValue(Math.max(window.limit_value - window.used_value, 0))}/${formatQuotaValue(window.limit_value)}`)
|
||||
continue
|
||||
}
|
||||
const remainingPercent = getQuotaWindowRemainingPercent(window)
|
||||
if (remainingPercent != null) {
|
||||
parts.push(`${label} 剩余 ${formatPercent(remainingPercent)}`)
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof quota.allowed_models_count === 'number') {
|
||||
parts.push(`可用模型 ${quota.allowed_models_count} 个`)
|
||||
}
|
||||
|
||||
if (parts.length > 0) return parts.join(' | ')
|
||||
|
||||
return normalizeText(quota.label)
|
||||
}
|
||||
|
||||
function getAntigravityQuotaText(quota: QuotaStatusSnapshot): string | null {
|
||||
const code = normalizeText(quota.code)?.toLowerCase()
|
||||
if (code === 'forbidden') {
|
||||
@@ -312,6 +359,8 @@ export function getQuotaSnapshotFallbackText(
|
||||
return getKiroQuotaText(quota)
|
||||
case 'grok':
|
||||
return getGrokQuotaText(quota)
|
||||
case 'windsurf':
|
||||
return getWindsurfQuotaText(quota)
|
||||
case 'antigravity':
|
||||
return getAntigravityQuotaText(quota)
|
||||
case 'gemini_cli':
|
||||
|
||||
@@ -2076,6 +2076,7 @@ const showAccountQuotaColumn = computed(() => {
|
||||
return selectedProviderType.value === 'codex'
|
||||
|| selectedProviderType.value === 'gemini_cli'
|
||||
|| selectedProviderType.value === 'kiro'
|
||||
|| selectedProviderType.value === 'windsurf'
|
||||
|| selectedProviderType.value === 'antigravity'
|
||||
|| selectedProviderType.value === 'grok'
|
||||
|| selectedProviderType.value === 'chatgpt_web'
|
||||
@@ -2475,6 +2476,7 @@ function getPoolKeyAccountStatsMetrics(key: PoolKeyDetail): PoolStatsMetric[] {
|
||||
const quotaRefreshSupported = computed(() => {
|
||||
return selectedProviderType.value === 'codex'
|
||||
|| selectedProviderType.value === 'kiro'
|
||||
|| selectedProviderType.value === 'windsurf'
|
||||
|| selectedProviderType.value === 'antigravity'
|
||||
|| selectedProviderType.value === 'grok'
|
||||
|| selectedProviderType.value === 'chatgpt_web'
|
||||
@@ -3622,11 +3624,15 @@ function getQuotaAlertSnapshotState(key: PoolKeyDetail): { label: string, title:
|
||||
if (!quota) return null
|
||||
|
||||
const code = String(quota.code || '').trim().toLowerCase()
|
||||
if (code !== 'banned' && code !== 'forbidden') return null
|
||||
if (!['banned', 'forbidden', 'quarantined', 'rate_limited', 'exhausted'].includes(code)) return null
|
||||
|
||||
let label = String(quota.label || '').trim()
|
||||
if (!label) {
|
||||
label = code === 'banned' ? '账号封禁' : '访问受限'
|
||||
if (code === 'banned') label = '账号封禁'
|
||||
else if (code === 'forbidden') label = '访问受限'
|
||||
else if (code === 'quarantined') label = '账号隔离'
|
||||
else if (code === 'rate_limited') label = '速率受限'
|
||||
else label = '额度耗尽'
|
||||
} else if (label === '账号已封禁' || label === '封禁') {
|
||||
label = '账号封禁'
|
||||
}
|
||||
@@ -3683,6 +3689,7 @@ function normalizeQuotaLabel(label: string): string {
|
||||
}
|
||||
|
||||
function getQuotaProgressLabel(label: string): string {
|
||||
if (label === '日') return '日'
|
||||
if (label === '5H') return '5H'
|
||||
if (label === '周') return '周'
|
||||
if (label === 'Spark5H') return 'Spark5H'
|
||||
@@ -3693,7 +3700,7 @@ function getQuotaProgressLabel(label: string): string {
|
||||
}
|
||||
|
||||
function getQuotaProgressCountdown(item: QuotaProgressItem) {
|
||||
if (!['5H', '周', 'Spark5H', 'Spark周', 'Auto', 'Fast', 'Expert', 'Heavy', 'Grok 4.3'].includes(item.label)) return null
|
||||
if (!['日', '5H', '周', 'Spark5H', 'Spark周', 'Auto', 'Fast', 'Expert', 'Heavy', 'Grok 4.3'].includes(item.label)) return null
|
||||
if (item.resetAtSeconds == null && item.resetSeconds == null) return null
|
||||
return getCodexResetCountdown(
|
||||
item.resetAtSeconds,
|
||||
@@ -3747,14 +3754,19 @@ function getQuotaLabelOrder(label: string): number {
|
||||
if (label === 'Expert') return 2
|
||||
if (label === 'Heavy') return 3
|
||||
if (label === 'Grok 4.3') return 4
|
||||
if (label === '5H') return 0
|
||||
if (label === '周') return 1
|
||||
if (label === 'Spark5H') return 2
|
||||
if (label === 'Spark周') return 3
|
||||
if (label === '剩余') return 4
|
||||
if (label === '最低') return 5
|
||||
if (label === '生图') return 6
|
||||
return 10
|
||||
if (label === '日') return 5
|
||||
if (label === '5H') return 6
|
||||
if (label === '周') return 7
|
||||
if (label === 'Spark5H') return 8
|
||||
if (label === 'Spark周') return 9
|
||||
if (label === 'Prompt') return 10
|
||||
if (label === 'Flex') return 11
|
||||
if (label === '剩余') return 12
|
||||
if (label === '最低') return 13
|
||||
if (label === '生图') return 14
|
||||
if (label === '速率') return 15
|
||||
if (label === '模型') return 16
|
||||
return 20
|
||||
}
|
||||
|
||||
function clampPercent(value: number): number {
|
||||
@@ -3998,6 +4010,57 @@ function buildQuotaProgressItemsFromSnapshot(key: PoolKeyDetail): QuotaProgressI
|
||||
}]
|
||||
}
|
||||
|
||||
if (providerType === 'windsurf') {
|
||||
const items: QuotaProgressItem[] = []
|
||||
for (const [label, code] of [
|
||||
['日', 'daily'],
|
||||
['周', 'weekly'],
|
||||
['Prompt', 'prompt'],
|
||||
['Flex', 'flex'],
|
||||
] as const) {
|
||||
const window = getQuotaSnapshotWindow(quota, code)
|
||||
const remainingPercent = getQuotaWindowRemainingPercent(window)
|
||||
if (remainingPercent == null) continue
|
||||
const detail = typeof window?.used_value === 'number' && typeof window?.limit_value === 'number'
|
||||
? `${formatQuotaValue(window.used_value)}/${formatQuotaValue(window.limit_value)}`
|
||||
: typeof window?.remaining_value === 'number' && typeof window?.limit_value === 'number'
|
||||
? `剩余 ${formatQuotaValue(window.remaining_value)}/${formatQuotaValue(window.limit_value)}`
|
||||
: undefined
|
||||
items.push({
|
||||
label,
|
||||
remainingPercent,
|
||||
detail,
|
||||
resetAtSeconds: normalizeUnixSeconds(window?.reset_at ?? null),
|
||||
resetSeconds: normalizeRemainingSeconds(window?.reset_seconds ?? null),
|
||||
updatedAtSeconds: getQuotaSnapshotUpdatedAtSeconds(quota),
|
||||
})
|
||||
}
|
||||
|
||||
const rateLimitWindow = getQuotaSnapshotWindow(quota, 'rate_limit')
|
||||
if (rateLimitWindow) {
|
||||
items.push({
|
||||
label: '速率',
|
||||
remainingPercent: rateLimitWindow.is_exhausted ? 0 : 100,
|
||||
resetAtSeconds: normalizeUnixSeconds(rateLimitWindow.reset_at ?? null),
|
||||
resetSeconds: normalizeRemainingSeconds(rateLimitWindow.reset_seconds ?? null),
|
||||
updatedAtSeconds: getQuotaSnapshotUpdatedAtSeconds(quota),
|
||||
})
|
||||
}
|
||||
|
||||
if (typeof quota.allowed_models_count === 'number' && Number.isFinite(quota.allowed_models_count)) {
|
||||
items.push({
|
||||
label: '模型',
|
||||
remainingPercent: 100,
|
||||
detail: `${quota.allowed_models_count} 个`,
|
||||
resetAtSeconds: null,
|
||||
resetSeconds: null,
|
||||
updatedAtSeconds: getQuotaSnapshotUpdatedAtSeconds(quota),
|
||||
})
|
||||
}
|
||||
|
||||
return items
|
||||
}
|
||||
|
||||
if (providerType === 'antigravity') {
|
||||
const windows = getQuotaSnapshotWindowsByScope(quota, 'model')
|
||||
if (windows.length === 0) return []
|
||||
|
||||
Reference in New Issue
Block a user