Skip to content

feat(codex): 为 Codex 添加 GitHub Copilot 供应商支持 - #6763

Open
Suaig wants to merge 6 commits into
farion1231:mainfrom
Suaig:feat/codex-github-copilot
Open

feat(codex): 为 Codex 添加 GitHub Copilot 供应商支持#6763
Suaig wants to merge 6 commits into
farion1231:mainfrom
Suaig:feat/codex-github-copilot

Conversation

@Suaig

@Suaig Suaig commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Summary / 概述

为 Codex 应用新增 GitHub Copilot 供应商预设与托管认证支持。

后端

  • CodexAdapter::extract_auth 增加 github_copilot 占位符分支,真实 token 由 forwarder 经
    CopilotAuthManager 按请求注入(与 Claude 侧同款托管路由)
  • CodexAdapter::get_auth_headers 增加 Copilot 指纹头分支(editor-version / copilot-integration-id
    / x-request-id 等)
  • forwarder 为 Copilot 请求直拼上游 URL(Copilot chat 端点无 /v1 前缀)

前端

  • codexProviderPresets 新增 GitHub Copilot 预设(requiresOAuth / apiFormat:
    openai_chat,模型留空由用户拉取账号模型后选择)
  • CodexFormFields 挂载 CopilotAuthSection 账号选择与「获取模型」;ProviderForm 放宽
    isCopilotProvider 至 codex 应用;新增空模型保存拦截
  • 软校验豁免:托管认证供应商无需填写 API Key/端点,不再误报「非官方供应商请填写 API Key」

流量路径:Codex CLI (Responses) → 本地代理 Responses→Chat 转换层 →
api.githubcopilot.com/chat/completions

Related Issue / 关联 Issue

Fixes #

Checklist / 检查清单

  • pnpm typecheck passes / 通过 TypeScript 类型检查
  • pnpm format:check passes / 通过代码格式检查
  • cargo clippy passes (if Rust code changed) / 通过 Clippy 检查(如修改了 Rust 代码)
  • Updated i18n files if user-facing text changed / 如修改了用户可见文本,已更新国际化文件

dd and others added 4 commits August 22, 2026 00:56
后端:
- CodexAdapter::extract_auth 增加 github_copilot 占位符分支,真实 token
  由 forwarder 经 CopilotAuthManager 按请求注入(与 Claude 侧同款托管路由)
- CodexAdapter::get_auth_headers 增加 Copilot 指纹头分支
  (editor-version / copilot-integration-id / x-request-id 等)
- forwarder 为 Codex/GrokBuild 下的 Copilot 请求直拼上游 URL:
  CodexAdapter::build_url 会给纯 origin 自动补 /v1,而 Copilot 的
  chat 端点无 /v1 前缀(…/chat/completions)

前端:
- codexProviderPresets 新增 GitHub Copilot 预设(providerType:
  github_copilot / requiresOAuth / apiFormat: openai_chat,model 留空
  由用户拉取账号模型后选择)
- ProviderForm 的 isCopilotProvider 放宽至 codex 应用,OAuth 登录校验
  与账号绑定 meta 自动生效;新增空模型保存拦截
- CodexFormFields 挂载 CopilotAuthSection 账号选择、隐藏 API Key 输入、
  「获取模型」走托管账号 token 拉取
- useProviderActions 切换提示文案分支同步放宽;proxyReasonCopilot
  文案通用化;新增 copilot.modelRequired 词条(zh/zh-TW/ja/en)

流量路径:Codex CLI (Responses) → 本地代理 Responses→Chat 转换层 →
api.githubcopilot.com/chat/completions,统一走转换层,兼容性问题
后续仅需在转换层修复。
托管认证(CopilotAuthManager 按请求注入 token)的供应商 auth.json
无需填写 API Key。与 claude 分支的既有豁免对齐,codex 软校验
端点 / API Key 两处条件补充 isCopilotProvider 判断;新增用例覆盖
空 key 保存不弹软校验确认框。
@Suaig
Suaig requested a review from farion1231 as a code owner August 24, 2026 08:08
@github-actions github-actions Bot added frontend Frontend (React/TypeScript) backend Backend (Rust/Tauri) i18n Internationalization (zh/en/ja) proxy Related to proxy/API forwarding labels Aug 24, 2026
@Suaig

Suaig commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

@farion1231 你好,PR 里 Backend Checks (Windows + WSL2 home) 两次 run 都挂在 LNK1327,调查后确认不是本 PR 代码的问题,是 CI 本身的一个隐患,报告如下:

现象:Run Windows-to-WSL2 filesystem contract 步骤中出现 Compiling cc-switch → 在 WSL UNC TEMP 下重新链接 → mt.exe 报 c1010070 → LNK1327。

根因链:

  1. 该 job 的设计是规避这个已知雷的:先用原生 TEMP 跑 cargo test --lib --no-run 编译链接完,再切 TEMP 纯运行——设计本身没问题;
  2. 日志证实 --no-run 步骤成功(6m34s,产出 cc_switch_lib-0e63d2a672627243.exe);
  3. 但运行步骤 cargo 误判产物过期,重新链接了同一个二进制(两次 /OUT 的 hash 完全相同 = 编译参数没变,纯 fingerprint 误判),此时 TEMP 已指向 \wsl.localhost...,撞雷;
  4. 误判的触发源排查:
    • 全 cargo registry 扫描:没有任何 build.rs 声明 rerun-if-env-changed=TEMP/TMP;
    • 本地复现 CI 的两步序列(--no-run 后改 TEMP 跑 --list):零重编,排除环境变量因素;
    • 剩余解释指向 CI runner 的 mtime 异常(长编译期间 NTP 时钟修正使产物时间戳错乱,cargo 误判 stale,同类问题 rust-lang/cargo 有多个 issue);
  5. 为什么 main 一直绿而 PR 挂:main 的 run 缓存命中、--no-run 全 Fresh 秒过,没有长编译窗口;PR 缓存 miss 触发 6m34s 全量编译,撞上时钟修正的概率大增。

修复建议:运行步骤绕开 cargo 的编译判定,直接执行 --no-run 已产出的测试二进制,从机制上杜绝在 UNC TEMP 下触发链接的可能:

  • name: Run Windows-to-WSL2 filesystem contract
    shell: pwsh
    run: |
    $env:TEMP = $env:CC_SWITCH_WSL_TEST_TEMP
    $env:TMP = $env:CC_SWITCH_WSL_TEST_TEMP
    $testName = "config::tests::atomic_write_replaces_existing_wsl_unc_file"
    $bin = Get-ChildItem "src-tauri/target/debug/deps/cc_switch_lib-*.exe" |
    Sort-Object LastWriteTime | Select-Object -Last 1
    if (-not $bin) {
    throw "test binary not found; did 'Compile backend tests with native temp' run?"
    }
    $expected = "${testName}: test"
    $testList = (& $bin.FullName --list --ignored | Out-String) -split "r?n"
    if ($testList -notcontains $expected) {
    throw "Expected ignored test was not discovered: $testName"
    }
    & $bin.FullName --exact --ignored --nocapture $testName
    if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }

此问题不阻塞本 PR 的功能代码

@farion1231

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fc3712199f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src-tauri/src/proxy/forwarder.rs
full-URL 分支优先于 Copilot URL builder,开启后请求直接发往 base_url
而非 /chat/completions,且跳过账号派生 endpoint 解析,用户可编辑的
base_url 会使托管 bearer token 发往任意主机。

三层修复(与 xAI OAuth 对齐):
- forwarder: is_full_url 排除 is_copilot(兜底已有脏数据)
- 表单: Claude/Codex 的 full-URL 开关对 Copilot 预设隐藏
- 持久化: meta.isFullUrl 不再对 Copilot 预设写盘
@Suaig

Suaig commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

@codex please help me review the latest changes.

@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend (Rust/Tauri) frontend Frontend (React/TypeScript) i18n Internationalization (zh/en/ja) proxy Related to proxy/API forwarding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants