From a3a1575e9df524b529a92bb8cf4ef63231c34cf9 Mon Sep 17 00:00:00 2001 From: superman2003 <2112076433zcr@gmail.com> Date: Wed, 22 Jul 2026 16:12:47 +0800 Subject: [PATCH] fix(frontend): import Grok keys into Grok Build --- .../utils/__tests__/ccswitchImport.spec.ts | 25 +++++++++++++++++++ frontend/src/utils/ccswitchImport.ts | 12 +++++++++ 2 files changed, 37 insertions(+) diff --git a/frontend/src/utils/__tests__/ccswitchImport.spec.ts b/frontend/src/utils/__tests__/ccswitchImport.spec.ts index 9c1e6b27c7..50789b5003 100644 --- a/frontend/src/utils/__tests__/ccswitchImport.spec.ts +++ b/frontend/src/utils/__tests__/ccswitchImport.spec.ts @@ -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' } diff --git a/frontend/src/utils/ccswitchImport.ts b/frontend/src/utils/ccswitchImport.ts index 1446547bea..d7858eab4d 100644 --- a/frontend/src/utils/ccswitchImport.ts +++ b/frontend/src/utils/ccswitchImport.ts @@ -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',