From e2028a814e74d09f847919c30dde5cf894d2b815 Mon Sep 17 00:00:00 2001 From: haruka <1628615876@qq.com> Date: Tue, 14 Jul 2026 16:41:33 +0800 Subject: [PATCH] fix(frontend): update Codex API key snippets --- frontend/src/components/keys/UseKeyModal.vue | 45 +++++++-------- .../keys/__tests__/UseKeyModal.spec.ts | 55 +++++++++++++++++-- .../src/i18n/locales/en/admin/channels.ts | 2 +- frontend/src/i18n/locales/en/dashboard.ts | 10 ++-- .../src/i18n/locales/zh/admin/channels.ts | 2 +- frontend/src/i18n/locales/zh/dashboard.ts | 10 ++-- 6 files changed, 86 insertions(+), 38 deletions(-) diff --git a/frontend/src/components/keys/UseKeyModal.vue b/frontend/src/components/keys/UseKeyModal.vue index e6bce556da..87983f94cc 100644 --- a/frontend/src/components/keys/UseKeyModal.vue +++ b/frontend/src/components/keys/UseKeyModal.vue @@ -562,29 +562,36 @@ windows_wsl_setup_acknowledged = true name = "OpenAI" base_url = "${baseUrl}" wire_api = "responses" -requires_openai_auth = true +requires_openai_auth = false +env_key = "SUB2API_API_KEY" +http_headers = { "x-openai-actor-authorization" = "local-image-extension" } [features] +image_generation = true goals = true` - // auth.json content - const authContent = `{ - "OPENAI_API_KEY": "${apiKey}" -}` - return [ { path: `${configDir}/config.toml`, content: configContent, hint: t('keys.useKeyModal.openai.configTomlHint') }, - { - path: `${configDir}/auth.json`, - content: authContent - } + generateCodexAPIKeyEnvironment(apiKey, isWindows) ] } +function generateCodexAPIKeyEnvironment(apiKey: string, isWindows: boolean): FileConfig { + return isWindows + ? { + path: 'PowerShell', + content: `$env:SUB2API_API_KEY="${apiKey}"` + } + : { + path: 'Terminal', + content: `export SUB2API_API_KEY="${apiKey}"` + } +} + function generateGrokFiles(baseUrl: string, apiKey: string): FileConfig[] { const isWindows = activeTab.value === 'windows' const configDir = isWindows ? '%userprofile%\\.grok' : '~/.grok' @@ -613,7 +620,7 @@ function generateOpenAIWsFiles(baseUrl: string, apiKey: string): FileConfig[] { const isWindows = activeTab.value === 'windows' const configDir = isWindows ? '%userprofile%\\.codex' : '~/.codex' - // config.toml content with WebSocket v2 + // config.toml content with the Responses WebSocket transport enabled const configContent = `model_provider = "OpenAI" model = "gpt-5.5" review_model = "gpt-5.5" @@ -627,27 +634,21 @@ name = "OpenAI" base_url = "${baseUrl}" wire_api = "responses" supports_websockets = true -requires_openai_auth = true +requires_openai_auth = false +env_key = "SUB2API_API_KEY" +http_headers = { "x-openai-actor-authorization" = "local-image-extension" } [features] -responses_websockets_v2 = true +image_generation = true goals = true` - // auth.json content - const authContent = `{ - "OPENAI_API_KEY": "${apiKey}" -}` - return [ { path: `${configDir}/config.toml`, content: configContent, hint: t('keys.useKeyModal.openai.configTomlHint') }, - { - path: `${configDir}/auth.json`, - content: authContent - } + generateCodexAPIKeyEnvironment(apiKey, isWindows) ] } diff --git a/frontend/src/components/keys/__tests__/UseKeyModal.spec.ts b/frontend/src/components/keys/__tests__/UseKeyModal.spec.ts index 24581d9f6b..4e216de8da 100644 --- a/frontend/src/components/keys/__tests__/UseKeyModal.spec.ts +++ b/frontend/src/components/keys/__tests__/UseKeyModal.spec.ts @@ -78,7 +78,7 @@ describe('UseKeyModal', () => { expect(parsed.provider.grok.models['gpt-5.6']).toBeUndefined() }) - it('renders GPT-5.5 and goals feature in OpenAI Codex config', () => { + it('renders API key mode and local image generation in OpenAI Codex config', () => { const wrapper = mount(UseKeyModal, { props: { show: true, @@ -107,10 +107,17 @@ describe('UseKeyModal', () => { expect(configToml).not.toContain('model = "gpt-5.4"') expect(configToml).not.toContain('model_context_window') expect(configToml).not.toContain('model_auto_compact_token_limit') - expect(configToml).toContain('[features]\ngoals = true') + expect(configToml).toContain('requires_openai_auth = false') + expect(configToml).toContain('env_key = "SUB2API_API_KEY"') + expect(configToml).toContain('http_headers = { "x-openai-actor-authorization" = "local-image-extension" }') + expect(configToml).not.toContain('supports_websockets') + expect(configToml).not.toContain('responses_websockets_v2') + expect(configToml).toContain('[features]\nimage_generation = true\ngoals = true') + expect(codeBlocks).toContain('export SUB2API_API_KEY="sk-test"') + expect(wrapper.text()).not.toContain('auth.json') }) - it('renders GPT-5.5 and goals feature in OpenAI Codex WebSocket config', async () => { + it('renders API key mode and current WebSocket settings in OpenAI Codex config', async () => { const wrapper = mount(UseKeyModal, { props: { show: true, @@ -147,7 +154,47 @@ describe('UseKeyModal', () => { expect(configToml).not.toContain('model = "gpt-5.4"') expect(configToml).not.toContain('model_context_window') expect(configToml).not.toContain('model_auto_compact_token_limit') - expect(configToml).toContain('[features]\nresponses_websockets_v2 = true\ngoals = true') + expect(configToml).toContain('requires_openai_auth = false') + expect(configToml).toContain('env_key = "SUB2API_API_KEY"') + expect(configToml).toContain('http_headers = { "x-openai-actor-authorization" = "local-image-extension" }') + expect(configToml).toContain('supports_websockets = true') + expect(configToml).not.toContain('responses_websockets_v2') + expect(configToml).toContain('[features]\nimage_generation = true\ngoals = true') + expect(codeBlocks).toContain('export SUB2API_API_KEY="sk-test"') + expect(wrapper.text()).not.toContain('auth.json') + }) + + it('renders a PowerShell API key command for Codex on Windows', async () => { + const wrapper = mount(UseKeyModal, { + props: { + show: true, + apiKey: 'sk-test', + baseUrl: 'https://example.com/v1', + platform: 'openai' + }, + global: { + stubs: { + BaseDialog: { + template: '