mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-08 02:17:46 +08:00
feat(providers): add xAI provider with device code OAuth
Add a separate `xai` provider type for xAI Grok CLI subscription accounts. It is independent of the existing `grok` provider, which reverse-proxies grok.com with browser cookies; behavior of `grok` is unchanged. Account binding uses the xAI device code flow, so no local callback listener is needed and headless deployments can bind accounts. Refresh tokens can also be imported individually or in batches, and are rotated on refresh. OAuth requests default to the cli-chat-proxy Responses API; API keys and compact stay on api.x.ai. Explicit custom gateways are preserved. Only `openai:responses` and `openai:responses:compact` are exposed; Chat, Claude and Gemini clients reach the provider through Aether's existing cross-format conversion rather than new native endpoints. Upstream Responses payloads are sanitized for what xAI actually rejects: `previous_response_id` and `metadata.user_id` are dropped, hosted `tool_choice` is rewritten, `web_search` is restored for converted clients, `image_generation` is stripped on older Grok conversation models, unsupported reasoning effort is removed, and requested `reasoning.encrypted_content` is preserved with a replay policy keyed on the configured provider type rather than the model name. Quota refresh reads /user and /billing?format=credits and stores a structured usage snapshot; a prepaid balance keeps an account selectable after the weekly allowance is exhausted. API-key accounts skip the subscription billing surface. The admin UI shows remaining weekly quota as a labeled bar in the provider drawer and the pool list. Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
@@ -1700,6 +1700,7 @@ const showAccountQuotaColumn = computed(() => {
|
||||
|| selectedProviderType.value === 'antigravity'
|
||||
|| selectedProviderType.value === 'grok'
|
||||
|| selectedProviderType.value === 'chatgpt_web'
|
||||
|| selectedProviderType.value === 'xai'
|
||||
})
|
||||
|
||||
const desktopColumnWidths = computed(() => {
|
||||
@@ -2149,6 +2150,7 @@ const quotaRefreshSupported = computed(() => {
|
||||
|| selectedProviderType.value === 'antigravity'
|
||||
|| selectedProviderType.value === 'grok'
|
||||
|| selectedProviderType.value === 'chatgpt_web'
|
||||
|| selectedProviderType.value === 'xai'
|
||||
})
|
||||
|
||||
function canResetCycleStats(_key: PoolKeyDetail): boolean {
|
||||
@@ -3480,8 +3482,10 @@ function normalizeQuotaLabel(label: string): string {
|
||||
if (/spark/i.test(normalized) && normalized.includes('周')) return 'Spark周'
|
||||
if (normalized.includes('5H')) return '5H'
|
||||
if (normalized.includes('周')) return '周'
|
||||
if (normalized.includes('月')) return '月'
|
||||
if (normalized.includes('最低剩余')) return '最低'
|
||||
if (normalized === '剩余' || normalized.includes('剩余')) return '剩余'
|
||||
if (normalized === '额度') return '额度'
|
||||
return normalized
|
||||
}
|
||||
|
||||
@@ -3490,6 +3494,9 @@ function getQuotaProgressLabel(label: string): string {
|
||||
if (label === '5H') return '5H'
|
||||
if (label === '周') return '周'
|
||||
if (label === '月') return '月'
|
||||
if (label === '周额度') return '周'
|
||||
if (label === '月额度') return '月'
|
||||
if (label === '额度') return '额度'
|
||||
if (label === 'Spark5H') return 'Spark5H'
|
||||
if (label === 'Spark周') return 'Spark周'
|
||||
if (label === '最低') return '最低'
|
||||
@@ -3498,7 +3505,7 @@ function getQuotaProgressLabel(label: string): string {
|
||||
}
|
||||
|
||||
function getQuotaProgressCountdown(item: QuotaProgressItem) {
|
||||
const staticResetLabels = ['日', '5H', '周', '月', 'Spark5H', 'Spark周', 'Spark月', 'Auto', 'Fast', 'Expert', 'Heavy', 'Grok 4.3', '生图']
|
||||
const staticResetLabels = ['日', '5H', '周', '月', '周额度', '月额度', '额度', 'Spark5H', 'Spark周', 'Spark月', 'Auto', 'Fast', 'Expert', 'Heavy', 'Grok 4.3', '生图']
|
||||
if (!item.allowDynamicReset && !staticResetLabels.includes(item.label)) return null
|
||||
if (item.resetAtSeconds == null && item.resetSeconds == null) return null
|
||||
return getCodexResetCountdown(
|
||||
@@ -3567,6 +3574,7 @@ function getQuotaLabelOrder(label: string): number {
|
||||
if (label === 'Prompt') return 12
|
||||
if (label === 'Flex') return 13
|
||||
if (label === '剩余') return 14
|
||||
if (label === '额度') return 14
|
||||
if (label === '最低') return 15
|
||||
if (label === '生图') return 16
|
||||
if (label === '速率') return 17
|
||||
@@ -3758,7 +3766,7 @@ function buildQuotaProgressItemsFromSnapshot(key: PoolKeyDetail): QuotaProgressI
|
||||
.filter((item): item is QuotaProgressItem => item != null)
|
||||
}
|
||||
|
||||
if (providerType === 'kiro') {
|
||||
if (providerType === 'kiro' || providerType === 'xai') {
|
||||
const quotaResetAtSeconds = getQuotaSnapshotResetAtSeconds(quota)
|
||||
const quotaResetSeconds = getQuotaSnapshotResetSeconds(quota)
|
||||
const window = getQuotaSnapshotWindow(quota, 'usage')
|
||||
@@ -3772,12 +3780,13 @@ function buildQuotaProgressItemsFromSnapshot(key: PoolKeyDetail): QuotaProgressI
|
||||
: undefined
|
||||
|
||||
return [{
|
||||
label: '剩余',
|
||||
label: normalizeQuotaLabel(String(window?.label || '').trim() || '剩余'),
|
||||
remainingPercent,
|
||||
detail,
|
||||
resetAtSeconds: normalizeUnixSeconds(window?.reset_at ?? quotaResetAtSeconds ?? null),
|
||||
resetSeconds: normalizeRemainingSeconds(window?.reset_seconds ?? quotaResetSeconds ?? null),
|
||||
updatedAtSeconds: getQuotaSnapshotUpdatedAtSeconds(quota),
|
||||
allowDynamicReset: true,
|
||||
}]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user