mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-05 16:07:33 +00:00
Merge pull request #9223 from r266-tech/codex/ccswitch-codex-transport
feat(keys): choose Codex transport for CC Switch imports
This commit is contained in:
6 files changed
+100
-45
No files matched your search
@@ -281,6 +281,11 @@ export default {
|
||||
ccsClientSelect: {
|
||||
title: 'Select Client',
|
||||
description: 'Please select the client type to import to CC-Switch:',
|
||||
transportTitle: 'Select Codex Transport',
|
||||
codexHttp: 'Codex CLI (HTTP)',
|
||||
codexHttpDesc: 'Use HTTP streaming',
|
||||
codexWebSocket: 'Codex CLI (WebSocket)',
|
||||
codexWebSocketDesc: 'Requires WebSocket support on the gateway and any reverse proxy',
|
||||
claudeCode: 'Claude Code',
|
||||
claudeCodeDesc: 'Import as Claude Code configuration',
|
||||
geminiCli: 'Gemini CLI',
|
||||
|
||||
@@ -286,6 +286,11 @@ export default {
|
||||
ccsClientSelect: {
|
||||
title: '选择客户端',
|
||||
description: '请选择您要导入到 CC-Switch 的客户端类型:',
|
||||
transportTitle: '选择 Codex 传输方式',
|
||||
codexHttp: 'Codex CLI (HTTP)',
|
||||
codexHttpDesc: '使用 HTTP 流式传输',
|
||||
codexWebSocket: 'Codex CLI (WebSocket)',
|
||||
codexWebSocketDesc: '需要网关及所用反向代理支持 WebSocket',
|
||||
claudeCode: 'Claude Code',
|
||||
claudeCodeDesc: '导入为 Claude Code 配置',
|
||||
geminiCli: 'Gemini CLI',
|
||||
|
||||
@@ -54,6 +54,7 @@ describe('ccswitchImport utils', () => {
|
||||
expect(payload.config).toContain(`model = "${OPENAI_CC_SWITCH_CODEX_MODEL}"`)
|
||||
expect(payload.config.split('[model_providers.')[0]).toContain('web_search = "live"')
|
||||
expect(payload.config).toContain('requires_openai_auth = false')
|
||||
expect(payload.config).not.toContain('supports_websockets')
|
||||
expect(payload.config).toContain('experimental_bearer_token = "sk-test"')
|
||||
expect(payload.config).toContain('"x-openai-actor-authorization" = "local-image-extension"')
|
||||
// Global feature choices are preserved by CC Switch, not imported per provider.
|
||||
|
||||
@@ -4,7 +4,7 @@ import { buildCodexApiKeyAuthConfig } from '@/utils/codexAuthConfig'
|
||||
export const OPENAI_CC_SWITCH_CODEX_MODEL = 'gpt-6.1-sol'
|
||||
export const GROK_CC_SWITCH_MODEL = 'grok-4.5'
|
||||
|
||||
export type CcSwitchClientType = 'claude' | 'gemini'
|
||||
export type CcSwitchClientType = 'claude' | 'gemini' | 'codex-http' | 'codex-websocket'
|
||||
|
||||
export interface CcSwitchImportConfig {
|
||||
app: string
|
||||
@@ -115,6 +115,9 @@ export function buildCcSwitchImportDeeplink(input: CcSwitchImportDeeplinkInput):
|
||||
if (config.app === 'codex') {
|
||||
// CC Switch's embedded-config import preserves provider auth and headers.
|
||||
// It deliberately leaves global [features] settings to the user.
|
||||
const transport = input.clientType === 'codex-http' || input.clientType === 'codex-websocket'
|
||||
? `supports_websockets = ${input.clientType === 'codex-websocket'}\n`
|
||||
: ''
|
||||
const codexConfig = `model_provider = "sub2api"
|
||||
model = ${JSON.stringify(config.model)}
|
||||
web_search = "live"
|
||||
@@ -123,7 +126,7 @@ web_search = "live"
|
||||
name = "Sub2API"
|
||||
base_url = ${JSON.stringify(config.endpoint)}
|
||||
wire_api = "responses"
|
||||
${buildCodexApiKeyAuthConfig(input.apiKey)}
|
||||
${transport}${buildCodexApiKeyAuthConfig(input.apiKey)}
|
||||
`
|
||||
const payload = JSON.stringify({ config: codexConfig })
|
||||
const bytes = new TextEncoder().encode(payload)
|
||||
|
||||
@@ -1091,44 +1091,35 @@
|
||||
@close="closeUseKeyModal"
|
||||
/>
|
||||
|
||||
<!-- CCS Client Selection Dialog for Antigravity -->
|
||||
<!-- CC Switch import options -->
|
||||
<BaseDialog
|
||||
:show="showCcsClientSelect"
|
||||
:title="t('keys.ccsClientSelect.title')"
|
||||
:show="pendingCcsRow !== null"
|
||||
:title="t(selectingCodexTransport ? 'keys.ccsClientSelect.transportTitle' : 'keys.ccsClientSelect.title')"
|
||||
width="narrow"
|
||||
@close="closeCcsClientSelect"
|
||||
>
|
||||
<div class="space-y-4">
|
||||
<p class="text-sm text-gray-600 dark:text-gray-400">
|
||||
<p v-if="!selectingCodexTransport" class="text-sm text-gray-600 dark:text-gray-400">
|
||||
{{ t('keys.ccsClientSelect.description') }}
|
||||
</p>
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<button
|
||||
@click="handleCcsClientSelect('claude')"
|
||||
class="flex flex-col items-center gap-2 p-4 rounded-xl border-2 border-gray-200 dark:border-dark-600 hover:border-primary-500 dark:hover:border-primary-500 hover:bg-primary-50 dark:hover:bg-primary-900/20 transition-all"
|
||||
>
|
||||
<Icon name="terminal" size="xl" class="text-gray-600 dark:text-gray-400" />
|
||||
<span class="font-medium text-gray-900 dark:text-white">{{
|
||||
t('keys.ccsClientSelect.claudeCode')
|
||||
}}</span>
|
||||
<span class="text-xs text-gray-500 dark:text-gray-400">{{
|
||||
t('keys.ccsClientSelect.claudeCodeDesc')
|
||||
}}</span>
|
||||
</button>
|
||||
<button
|
||||
@click="handleCcsClientSelect('gemini')"
|
||||
class="flex flex-col items-center gap-2 p-4 rounded-xl border-2 border-gray-200 dark:border-dark-600 hover:border-primary-500 dark:hover:border-primary-500 hover:bg-primary-50 dark:hover:bg-primary-900/20 transition-all"
|
||||
>
|
||||
<Icon name="sparkles" size="xl" class="text-gray-600 dark:text-gray-400" />
|
||||
<span class="font-medium text-gray-900 dark:text-white">{{
|
||||
t('keys.ccsClientSelect.geminiCli')
|
||||
}}</span>
|
||||
<span class="text-xs text-gray-500 dark:text-gray-400">{{
|
||||
t('keys.ccsClientSelect.geminiCliDesc')
|
||||
}}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</p>
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<button
|
||||
v-for="option in ccsClientOptions"
|
||||
:key="option.clientType"
|
||||
type="button"
|
||||
@click="handleCcsClientSelect(option.clientType)"
|
||||
class="flex flex-col items-center gap-2 p-4 rounded-xl border-2 border-gray-200 dark:border-dark-600 hover:border-primary-500 dark:hover:border-primary-500 hover:bg-primary-50 dark:hover:bg-primary-900/20 transition-all"
|
||||
>
|
||||
<Icon :name="option.icon" size="xl" class="text-gray-600 dark:text-gray-400" />
|
||||
<span class="font-medium text-gray-900 dark:text-white">{{
|
||||
t(`keys.ccsClientSelect.${option.label}`)
|
||||
}}</span>
|
||||
<span class="text-xs text-gray-500 dark:text-gray-400">{{
|
||||
t(`keys.ccsClientSelect.${option.label}Desc`)
|
||||
}}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<template #footer>
|
||||
<div class="flex justify-end">
|
||||
<button @click="closeCcsClientSelect" class="btn btn-secondary">
|
||||
@@ -1414,9 +1405,18 @@ const showDeleteDialog = ref(false)
|
||||
const showResetQuotaDialog = ref(false)
|
||||
const showResetRateLimitDialog = ref(false)
|
||||
const showUseKeyModal = ref(false)
|
||||
const showCcsClientSelect = ref(false)
|
||||
const showColumnDropdown = ref(false)
|
||||
const pendingCcsRow = ref<ApiKey | null>(null)
|
||||
const selectingCodexTransport = computed(() => pendingCcsRow.value?.group?.platform === 'openai')
|
||||
const ccsClientOptions = computed(() => selectingCodexTransport.value
|
||||
? [
|
||||
{ clientType: 'codex-http', icon: 'terminal', label: 'codexHttp' },
|
||||
{ clientType: 'codex-websocket', icon: 'terminal', label: 'codexWebSocket' }
|
||||
] as const
|
||||
: [
|
||||
{ clientType: 'claude', icon: 'terminal', label: 'claudeCode' },
|
||||
{ clientType: 'gemini', icon: 'sparkles', label: 'geminiCli' }
|
||||
] as const)
|
||||
const selectedKey = ref<ApiKey | null>(null)
|
||||
const copiedKeyId = ref<number | null>(null)
|
||||
const groupSelectorKeyId = ref<number | null>(null)
|
||||
@@ -2034,14 +2034,11 @@ const resetRateLimitUsage = async () => {
|
||||
const importToCcswitch = (row: ApiKey) => {
|
||||
const platform = row.group?.platform || 'anthropic'
|
||||
|
||||
// For antigravity platform, show client selection dialog
|
||||
if (platform === 'antigravity') {
|
||||
if (platform === 'antigravity' || platform === 'openai') {
|
||||
pendingCcsRow.value = row
|
||||
showCcsClientSelect.value = true
|
||||
return
|
||||
}
|
||||
|
||||
// For other platforms, execute directly
|
||||
executeCcsImport(row, platform === 'gemini' ? 'gemini' : 'claude')
|
||||
}
|
||||
|
||||
@@ -2076,15 +2073,12 @@ const executeCcsImport = (row: ApiKey, clientType: CcSwitchClientType) => {
|
||||
}
|
||||
|
||||
const handleCcsClientSelect = (clientType: CcSwitchClientType) => {
|
||||
if (pendingCcsRow.value) {
|
||||
executeCcsImport(pendingCcsRow.value, clientType)
|
||||
}
|
||||
showCcsClientSelect.value = false
|
||||
pendingCcsRow.value = null
|
||||
const row = pendingCcsRow.value
|
||||
closeCcsClientSelect()
|
||||
if (row) executeCcsImport(row, clientType)
|
||||
}
|
||||
|
||||
const closeCcsClientSelect = () => {
|
||||
showCcsClientSelect.value = false
|
||||
pendingCcsRow.value = null
|
||||
}
|
||||
|
||||
|
||||
@@ -300,6 +300,53 @@ describe('user KeysView column settings', () => {
|
||||
isCurrentStep.mockReturnValue(false)
|
||||
})
|
||||
|
||||
it.each([
|
||||
{ platform: 'openai', choice: 'codexHttp', app: 'codex', webSocket: false },
|
||||
{ platform: 'openai', choice: 'codexWebSocket', app: 'codex', webSocket: true },
|
||||
{ platform: 'antigravity', choice: 'geminiCli', app: 'gemini', webSocket: undefined },
|
||||
])('imports a $platform key to CC Switch after choosing $choice', async ({ platform, choice, app, webSocket }) => {
|
||||
listKeys.mockResolvedValueOnce({
|
||||
items: [{ ...createApiKey(), group_id: 1, group: { id: 1, name: 'Test group', platform } }],
|
||||
total: 1,
|
||||
page: 1,
|
||||
page_size: 20,
|
||||
pages: 1,
|
||||
})
|
||||
const wrapper = await mountView()
|
||||
const open = vi.spyOn(window, 'open').mockReturnValue(null)
|
||||
|
||||
try {
|
||||
const importButton = getButtonByText(wrapper, 'keys.importToCcSwitch')
|
||||
await importButton.trigger('click')
|
||||
expect(wrapper.find('[role="dialog"]').exists()).toBe(true)
|
||||
await wrapper.get('[data-test="close-dialog"]').trigger('click')
|
||||
expect(wrapper.find('[role="dialog"]').exists()).toBe(false)
|
||||
expect(open).not.toHaveBeenCalled()
|
||||
|
||||
await importButton.trigger('click')
|
||||
await getButtonByText(wrapper, `keys.ccsClientSelect.${choice}`).trigger('click')
|
||||
expect(wrapper.find('[role="dialog"]').exists()).toBe(false)
|
||||
expect(open).toHaveBeenCalledTimes(1)
|
||||
expect(open).toHaveBeenCalledWith(expect.stringMatching(/^ccswitch:\/\/v1\/import\?/), '_self')
|
||||
const params = new URL(open.mock.calls[0][0] as string).searchParams
|
||||
expect(params.get('app')).toBe(app)
|
||||
|
||||
if (webSocket === undefined) {
|
||||
expect(params.get('endpoint')).toBe(`${window.location.origin}/antigravity`)
|
||||
expect(params.has('config')).toBe(false)
|
||||
} else {
|
||||
const { config } = JSON.parse(atob(params.get('config') || '')) as { config: string }
|
||||
const [, provider] = config.split('[model_providers.sub2api]\n')
|
||||
expect(provider).toContain(`\nsupports_websockets = ${webSocket}\n`)
|
||||
expect(provider).toContain(`base_url = "${window.location.origin}"`)
|
||||
expect(provider).toContain('experimental_bearer_token = "sk-test-key"')
|
||||
}
|
||||
} finally {
|
||||
open.mockRestore()
|
||||
wrapper.unmount()
|
||||
}
|
||||
})
|
||||
|
||||
it.each([
|
||||
{ initialStatus: 'quota_exhausted', status: 'active', formStatus: 'active' },
|
||||
{ initialStatus: 'inactive', status: 'inactive', formStatus: 'inactive' },
|
||||
|
||||
Reference in new issue
Block a user