Skip to content

Comments

Use User-Agent header as well as HTTP-Referer/X-Title#1318

Merged
zerob13 merged 1 commit intoThinkInAIXYZ:devfrom
mikelambert:mike/user-agent
Feb 24, 2026
Merged

Use User-Agent header as well as HTTP-Referer/X-Title#1318
zerob13 merged 1 commit intoThinkInAIXYZ:devfrom
mikelambert:mike/user-agent

Conversation

@mikelambert
Copy link
Contributor

@mikelambert mikelambert commented Feb 23, 2026

Adds a standard User-Agent: DeepChat/{version} header for API identification, beyond just HTTP-Referer/X-Title

Summary by CodeRabbit

  • Chores

    • Enhanced application identification in HTTP requests with dynamic version information in request headers.
  • Tests

    • Added test coverage for request header validation.

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>
@dosubot
Copy link

dosubot bot commented Feb 23, 2026

Related Documentation

Checked 0 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 23, 2026

📝 Walkthrough

Walkthrough

Adds a dynamic User-Agent header to DevicePresenter.getDefaultHeaders by initializing a version constant from app.getVersion() and setting it as DeepChat/{version}. Existing headers remain unchanged. A new test file is introduced to verify header values.

Changes

Cohort / File(s) Summary
DevicePresenter Implementation
src/main/presenter/devicePresenter/index.ts
Adds version constant initialized with app.getVersion() and sets dynamic User-Agent header formatted as DeepChat/{version} in getDefaultHeaders method.
DevicePresenter Tests
test/main/presenter/devicePresenter.test.ts
New test file with mocked event bus and svg sanitizer. Verifies getDefaultHeaders includes User-Agent with DeepChat/ prefix, and validates HTTP-Referer and X-Title header values using vitest framework.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A version string hops into the header,
DeepChat declares itself, bold and better,
Tests follow closely with mocked-up friends,
Checking that each HTTP header sends. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding a User-Agent header alongside existing HTTP-Referer and X-Title headers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
test/main/presenter/devicePresenter.test.ts (1)

25-37: Tests are well-structured; regex assertion could be strengthened

The two it blocks cover the new User-Agent header and the pre-existing HTTP-Referer/X-Title headers, 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: version constant should use SCREAMING_SNAKE_CASE

Per the project's TypeScript coding guidelines, const identifiers should use SCREAMING_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.

@zerob13 zerob13 merged commit 1e0591e into ThinkInAIXYZ:dev Feb 24, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants