fix: 调整为不同API提供商添加特定User-Agent,避免统一使用claude-cli/2.0.33#209
Conversation
- 在executeProviderApiTest接口中添加userAgent参数,支持渠道特定的User-Agent配置 - 更新Anthropic Messages API使用claude-cli/2.0.50 (external, cli) User-Agent - 更新OpenAI Chat Completions API使用OpenAI/NodeJS/3.2.1 User-Agent - 更新OpenAI Responses API使用codex_cli_rs/0.63.0 User-Agent - 更新Gemini API使用GeminiCLI/v0.17.1 User-Agent - 移除硬编码的通用User-Agent,改为使用各渠道特定的标识 - 避免被Cloudflare Bot检测系统拦截,提高API测试成功率
Summary of ChangesHello @Silentely, 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! 此拉取请求旨在通过为不同的API提供商配置特定的User-Agent字符串来提高API测试的可靠性。这一更改解决了因通用User-Agent被Cloudflare等服务识别为机器人而导致API请求失败的问题,确保了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 的目标是为不同的 API 提供商添加特定的 User-Agent,以避免被 Cloudflare 等服务拦截。整体实现思路清晰,通过为 executeProviderApiTest 函数添加 userAgent 参数,并将硬编码的通用 User-Agent 替换为各个 API 测试函数中传入的特定值,成功地实现了目标。
代码改动是有效的,但在多个地方引入了相同的语法错误:在对象字面量中,新添加的 userAgent 属性后面缺少了逗号,这将导致代码无法编译。我已在所有出现此问题的地方提出了修复建议。
此外,我还发现 testProviderOpenAIResponses 中使用的 User-Agent 字符串过于具体,包含了特定于 macOS 的平台信息,这可能会降低代码的可移植性。我也一并提出了修改建议。
请修正这些问题以确保代码的正确性和健壮性。
This comment was marked as off-topic.
This comment was marked as off-topic.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
🔒 Security Scan Results✅ No security vulnerabilities detected This PR has been scanned against OWASP Top 10, CWE Top 25, and common security anti-patterns. No security issues were identified in the code changes. Summary of Changes Reviewed
Security AnalysisChange Type: Refactoring of User-Agent header configuration Risk Assessment: ✅ None The changes in this PR:
Key Security Finding: The Scanned Categories
🛡️ Security PostureStrong - This is a low-risk refactoring change with no security implications. The change improves code organization without introducing any new attack vectors. 🤖 Automated security scan by Claude AI - OWASP Top 10 & CWE coverage |
ding113
left a comment
There was a problem hiding this comment.
📋 Code Review Summary
This PR introduces provider-specific User-Agent headers for API testing, replacing a hardcoded generic User-Agent. The implementation is clean, well-structured, and correctly adds the userAgent field to the options interface while updating all 4 provider test functions.
🔍 Issues Found
- Critical (🔴): 0 issues
- High (🟠): 0 issues
- Medium (🟡): 0 issues
- Low (🟢): 0 issues
🎯 Priority Actions
No significant issues identified that require changes before merge.
💡 General Observations
- The
userAgentfield is properly added as a required field in the interface, ensuring type safety - All 4 callers of
executeProviderApiTestcorrectly provide the newuserAgentparameter - The User-Agent strings appear to be realistic values mimicking actual CLI tools
- Minor note: The Gemini User-Agent
"GeminiCLI/v0.17.1 (platform; arch)"contains a literal(platform; arch)string rather than actual platform/architecture values, but this is a cosmetic detail that doesn't affect functionality
🤖 Automated review by Claude AI - focused on identifying issues for improvement
ding113
left a comment
There was a problem hiding this comment.
📋 Code Review Summary
This PR introduces provider-specific User-Agent headers for API testing, replacing a hardcoded generic User-Agent. The implementation is clean, well-structured, and correctly adds the userAgent field to the options interface while updating all 4 provider test functions.
🔍 Issues Found
- Critical (🔴): 0 issues
- High (🟠): 0 issues
- Medium (🟡): 0 issues
- Low (🟢): 0 issues
🎯 Priority Actions
No significant issues identified that require changes before merge.
💡 General Observations
- The
userAgentfield is properly added as a required field in the interface, ensuring type safety - All 4 callers of
executeProviderApiTestcorrectly provide the newuserAgentparameter - The User-Agent strings appear to be realistic values mimicking actual CLI tools
- Minor note: The Gemini User-Agent
"GeminiCLI/v0.17.1 (platform; arch)"contains a literal(platform; arch)string rather than actual platform/architecture values, but this is a cosmetic detail that doesn't affect functionality
🤖 Automated review by Claude AI - focused on identifying issues for improvement
Summary / 摘要
Add provider-specific User-Agent headers for API testing to avoid Cloudflare Bot detection and improve test success rates.
为 API 测试添加渠道特定的 User-Agent 头,避免被 Cloudflare Bot 检测系统拦截,提高 API 测试成功率。
Problem / 问题
The previous implementation used a hardcoded generic User-Agent (
claude-cli/2.0.33) for all provider API tests. This approach:Solution / 解决方案
Added a
userAgentparameter to theexecuteProviderApiTestinterface and configured provider-specific User-Agent headers:claude-cli/2.0.50 (external, cli)OpenAI/NodeJS/3.2.1codex_cli_rs/0.63.0GeminiCLI/v0.17.1Changes / 变更
userAgentfield to the test options interface inexecuteProviderApiTestFiles Changed / 文件变更
src/actions/providers.ts- Core changes to provider API testingTesting / 测试