Use User-Agent header as well as HTTP-Referer/X-Title#1318
Use User-Agent header as well as HTTP-Referer/X-Title#1318zerob13 merged 1 commit intoThinkInAIXYZ:devfrom
Conversation
Switches from HTTP-Referer/X-Title to a standard User-Agent: DeepChat/{version}
header for Anthropic API identification.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthroughAdds a dynamic User-Agent header to DevicePresenter.getDefaultHeaders by initializing a version constant from app.getVersion() and setting it as Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
test/main/presenter/devicePresenter.test.ts (1)
25-37: Tests are well-structured; regex assertion could be strengthenedThe two
itblocks cover the newUser-Agentheader and the pre-existingHTTP-Referer/X-Titleheaders, which is exactly the right scope for this change. File placement (test/main/presenter/devicePresenter.test.ts) correctly mirrors the source structure.One optional improvement: the current assertion
toMatch(/^DeepChat\//)confirms the prefix but not that a non-empty version follows. If the electron mock ever returns an empty string the test would still pass.🔧 Optional tighter assertion
- expect(headers['User-Agent']).toMatch(/^DeepChat\//) + expect(headers['User-Agent']).toMatch(/^DeepChat\/\S+/)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/main/presenter/devicePresenter.test.ts` around lines 25 - 37, The User-Agent regex in the DevicePresenter.getDefaultHeaders test is too loose; update the assertion to require a non-empty version after the "DeepChat/" prefix (e.g., use a regex like /^DeepChat\/.+$/ or /^DeepChat\/\S+$/) so the test fails if an empty string follows the slash; modify the second expect in the 'should include User-Agent header with DeepChat/ prefix' spec to use the tighter pattern while leaving the HTTP-Referer and X-Title assertions unchanged.src/main/presenter/devicePresenter/index.ts (1)
18-18:versionconstant should useSCREAMING_SNAKE_CASEPer the project's TypeScript coding guidelines,
constidentifiers should useSCREAMING_SNAKE_CASE.♻️ Proposed fix
- const version = app.getVersion() + const VERSION = app.getVersion() return { 'HTTP-Referer': 'https://deepchatai.cn', 'X-Title': 'DeepChat', - 'User-Agent': `DeepChat/${version}` + 'User-Agent': `DeepChat/${VERSION}` }As per coding guidelines: "use SCREAMING_SNAKE_CASE for constants."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/main/presenter/devicePresenter/index.ts` at line 18, The constant named "version" should follow SCREAMING_SNAKE_CASE per project guidelines: rename the const declaration "version" to "VERSION" in src/main/presenter/devicePresenter/index.ts (const version = app.getVersion() -> const VERSION = app.getVersion()) and update every usage/reference in this module (and any exported identifier consumers) to use "VERSION" instead of "version".
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/main/presenter/devicePresenter/index.ts`:
- Line 18: The constant named "version" should follow SCREAMING_SNAKE_CASE per
project guidelines: rename the const declaration "version" to "VERSION" in
src/main/presenter/devicePresenter/index.ts (const version = app.getVersion() ->
const VERSION = app.getVersion()) and update every usage/reference in this
module (and any exported identifier consumers) to use "VERSION" instead of
"version".
In `@test/main/presenter/devicePresenter.test.ts`:
- Around line 25-37: The User-Agent regex in the
DevicePresenter.getDefaultHeaders test is too loose; update the assertion to
require a non-empty version after the "DeepChat/" prefix (e.g., use a regex like
/^DeepChat\/.+$/ or /^DeepChat\/\S+$/) so the test fails if an empty string
follows the slash; modify the second expect in the 'should include User-Agent
header with DeepChat/ prefix' spec to use the tighter pattern while leaving the
HTTP-Referer and X-Title assertions unchanged.
Adds a standard User-Agent: DeepChat/{version} header for API identification, beyond just HTTP-Referer/X-Title
Summary by CodeRabbit
Chores
Tests