feat: provider custom user agent#406
Conversation
Summary of ChangesHello @FaulknerWu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 此拉取请求引入了一项重要功能,允许用户为每个配置的供应商自定义User-Agent字符串。这一改进旨在解决与某些第三方服务(特别是Codex中转站)的兼容性问题,这些服务可能因特定的User-Agent要求而无法正常工作。通过提供灵活的User-Agent配置选项,系统能够更好地适应不同的外部API行为,从而提高服务的稳定性和可用性。 Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
本次 PR 新增了为 Provider 自定义 User-Agent 的功能,这是一个非常实用的改进,解决了部分中转服务商对 User-Agent 有特殊要求的痛点。代码实现清晰、完整,覆盖了数据库、后端逻辑、前端表单等各个层面。
主要变更点:
- 数据库与类型定义:在
providers表中新增了user_agent字段,并同步更新了相关的类型定义,结构清晰。 - 核心逻辑:在
forwarder.ts中实现了 User-Agent 的优先级处理逻辑(provider.userAgent> 客户端原始 UA > 默认 UA),实现方式正确且优雅地替代了之前针对codex的硬编码逻辑。 - 前端支持:在供应商设置表单中添加了自定义 User-Agent 的输入框,UI 实现简洁明了,并且对空字符串做了
null处理,保证了数据一致性。 - 代码一致性:新功能的添加贯穿了整个代码库,从数据模型到 API 服务再到 UI,修改一致且完整。
总体来说,这是一个高质量的 PR,代码整洁,逻辑严谨,很好地解决了实际问题。我没有发现任何需要修改的问题。
|
Packy 的包月 Codex 问题,目前建议通过 供应商 instruction策略选择透传解决。 关于这一功能,会在后续版本重构供应商时考虑。感谢你的贡献。 |
我这边两家codex现在35版本都是被认为第三方客户端,你说的方法我也试过了没管用。我是今天早上在priv群里看到有人问这个然后提到crs正常,我才看了crs的代码,仿照写了自定义UA,并且没有对源UA再做一层overrides的操作。这个开发分支在我本地上是可以正常接入了,在没修改前本地开发分支也是不能接入的,我感觉很玄学,但是在我这边确实是管用了。 |
Summary
Add custom User-Agent support for Providers, allowing each upstream provider to be configured with its own UA string.
为 Provider 添加自定义 User-Agent 支持,允许为每个供应商配置独立的 UA 字符串。
Problem
Some third-party API relay services (中转站) reject requests when using Codex endpoints, returning errors about not being allowed to run on third-party platforms. For example, Packy's monthly Codex subscription would fail with this error. This happens because the User-Agent header identifies the request as coming from a proxy.
某些中转站的 Codex 配置会报错提示不能在第三方平台运行(如 Packy 的包月 Codex)。Claude Code 本身没有遇到这个问题,但 Codex 类型的供应商需要能够自定义 User-Agent 来绕过这些限制。
Solution
Added a
userAgentfield to providers with the following priority:provider.userAgent(if configured)claude-code-hub/{version}User-Agent 优先级:
provider.userAgent> 客户端原始 UA > 默认 UA(claude-code-hub/{version})Related PRs:
Changes
Core Changes
src/drizzle/schema.tsuser_agentcolumn to providers tablesrc/app/v1/_lib/proxy/forwarder.tssrc/types/provider.tsuserAgentfield to Provider interfacessrc/repository/provider.tsSupporting Changes
src/app/[locale]/settings/providers/_components/forms/provider-form.tsxmessages/*.json(5 files)src/actions/providers.tssrc/repository/_shared/transformers.tsDatabase Migration
drizzle/0039_wet_sasquatch.sqlALTER TABLE "providers" ADD COLUMN "user_agent" varchar(512);Breaking Changes
user_agentcolumn added toproviderstablebun run db:migrateor enableAUTO_MIGRATE=trueBehavior Change
Before: Codex providers had special handling that used client UA or a hardcoded fallback (
codex_cli_rs/0.55.0...)After: All provider types use unified logic:
provider.userAgentis set → use itclaude-code-hub/{version}This change is backward compatible. Existing providers without
userAgentconfigured will continue to work with client UA passthrough.Testing
Checklist
devDescription enhanced by Claude AI