mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-20 00:18:55 +00:00
Merge pull request #4721 from superman2003/fix/ccswitch-grokbuild-4720
fix(frontend): import Grok keys into Grok Build
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
GROK_CC_SWITCH_MODEL,
|
||||
OPENAI_CC_SWITCH_CODEX_MODEL,
|
||||
buildCcSwitchImportDeeplink
|
||||
} from '@/utils/ccswitchImport'
|
||||
@@ -15,6 +16,10 @@ describe('ccswitchImport utils', () => {
|
||||
expect(OPENAI_CC_SWITCH_CODEX_MODEL).toBe('gpt-5.5')
|
||||
})
|
||||
|
||||
it('defaults Grok Build imports to the current Grok model', () => {
|
||||
expect(GROK_CC_SWITCH_MODEL).toBe('grok-4.5')
|
||||
})
|
||||
|
||||
const baseInput = {
|
||||
baseUrl: 'https://api.example.com',
|
||||
providerName: 'Sub2API',
|
||||
@@ -38,6 +43,26 @@ describe('ccswitchImport utils', () => {
|
||||
expect(atob(params.get('usageScript') || '')).toBe(baseInput.usageScript)
|
||||
})
|
||||
|
||||
it.each([
|
||||
'https://api.example.com',
|
||||
'https://api.example.com/',
|
||||
'https://api.example.com/v1',
|
||||
'https://api.example.com/v1/'
|
||||
])('imports Grok Build with one /v1 suffix for base URL %s', (baseUrl) => {
|
||||
const params = paramsFromDeeplink(
|
||||
buildCcSwitchImportDeeplink({
|
||||
...baseInput,
|
||||
baseUrl,
|
||||
platform: 'grok',
|
||||
clientType: 'claude'
|
||||
})
|
||||
)
|
||||
|
||||
expect(params.get('app')).toBe('grokbuild')
|
||||
expect(params.get('endpoint')).toBe('https://api.example.com/v1')
|
||||
expect(params.get('model')).toBe(GROK_CC_SWITCH_MODEL)
|
||||
})
|
||||
|
||||
it.each([
|
||||
{ platform: 'anthropic' as GroupPlatform, clientType: 'claude' as const, app: 'claude' },
|
||||
{ platform: 'gemini' as GroupPlatform, clientType: 'gemini' as const, app: 'gemini' }
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { GroupPlatform } from '@/types'
|
||||
|
||||
export const OPENAI_CC_SWITCH_CODEX_MODEL = 'gpt-5.5'
|
||||
export const GROK_CC_SWITCH_MODEL = 'grok-4.5'
|
||||
|
||||
export type CcSwitchClientType = 'claude' | 'gemini'
|
||||
|
||||
@@ -19,6 +20,11 @@ export interface CcSwitchImportDeeplinkInput {
|
||||
usageScript: string
|
||||
}
|
||||
|
||||
function withV1Endpoint(baseUrl: string): string {
|
||||
const normalizedBaseUrl = baseUrl.replace(/\/+$/, '')
|
||||
return normalizedBaseUrl.endsWith('/v1') ? normalizedBaseUrl : `${normalizedBaseUrl}/v1`
|
||||
}
|
||||
|
||||
export function resolveCcSwitchImportConfig(
|
||||
platform: GroupPlatform | undefined | null,
|
||||
clientType: CcSwitchClientType,
|
||||
@@ -41,6 +47,12 @@ export function resolveCcSwitchImportConfig(
|
||||
app: 'gemini',
|
||||
endpoint: baseUrl
|
||||
}
|
||||
case 'grok':
|
||||
return {
|
||||
app: 'grokbuild',
|
||||
endpoint: withV1Endpoint(baseUrl),
|
||||
model: GROK_CC_SWITCH_MODEL
|
||||
}
|
||||
default:
|
||||
return {
|
||||
app: 'claude',
|
||||
|
||||
Reference in New Issue
Block a user