Skip to content

feat: claude context editing - #1925

Merged
seefs001 merged 1 commit into
QuantumNous:alphafrom
seefs001:feature/claude-context-editing
Sep 30, 2025
Merged

seefs001 merged 1 commit into
QuantumNous:alphafrom
seefs001:feature/claude-context-editing

Conversation

@seefs001

@seefs001 seefs001 commented Sep 30, 2025 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Settings: Expanded “BudgetTokens percentage” input to accept any value ≥0.1 (removed previous upper limit).
    • Localization: Added new translation string for “Decimal above 0.1” in English and French.
    • Integrations: Requests now forward optional Anthropic beta headers, enabling access to supported beta capabilities.
  • Chores

    • Internal request structure prepared for future context management (no user-facing changes).

@coderabbitai

coderabbitai Bot commented Sep 30, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Adds ContextManagement to ClaudeRequest DTO. Propagates anthropic-beta header in AWS and Claude adaptors during request setup. Updates UI to remove max=1 constraint and adjust helper text. Adds new i18n key "0.1以上的小数" to English and French locales.

Changes

Cohort / File(s) Summary
Claude DTO update
dto/claude.go
Added public field ContextManagement (json.RawMessage) to ClaudeRequest; reflowed formatting of existing fields.
Anthropic beta header propagation
relay/channel/aws/adaptor.go, relay/channel/claude/adaptor.go
In SetupRequestHeader, conditionally forward incoming anthropic-beta header to outgoing request alongside existing version handling.
Localization additions
web/src/i18n/locales/en.json, web/src/i18n/locales/fr.json
Added translation key "0.1以上的小数" to EN ("Decimal above 0.1") and FR ("Décimal supérieur à 0,1").
Claude model settings UI
web/src/pages/Setting/Model/SettingClaudeModel.jsx
Updated helper text from "0.1-1之间的小数" to "0.1以上的小数"; removed max={1} constraint from InputNumber.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client as Client
  participant Gateway as Relay Adaptor (AWS/Claude)
  participant Upstream as Anthropic API

  Client->>Gateway: HTTP request<br/>headers: anthropic-version, anthropic-beta?
  Note over Gateway: SetupRequestHeader<br/>reads anthropic-beta if present
  Gateway->>Upstream: Forwarded request<br/>headers: anthropic-version (+ anthropic-beta if present)
  Upstream-->>Gateway: Response
  Gateway-->>Client: Response
Loading
sequenceDiagram
  autonumber
  participant UI as Settings UI
  participant Store as Config Store

  UI->>UI: InputNumber change (no max=1)
  UI->>Store: Save BudgetTokens percentage
  Note over UI: Helper text uses key "0.1以上的小数" (i18n EN/FR added)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • Calcium-Ion

Poem

I thump my paw: a header hops by—beta!
New fields sprout in Claude’s spring data.
Sliders stretch beyond the upper sun,
While tiny strings learn tongues, two to one.
I nibble docs, ears high with delight—
Commit by commit, we leap into night. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly conveys the primary feature added—enabling context editing for the Claude model—without extraneous details, and aligns with the changes to the DTO, UI, translations, and header propagation needed to support that functionality.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🧪 Early access (Sonnet 4.5): enabled

We are currently testing the Sonnet 4.5 model, which is expected to improve code review quality. However, this model may lead to increased noise levels in the review comments. Please disable the early access features if the noise level causes any inconvenience.

Note:

  • Public repositories are always opted into early access features.
  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
web/src/pages/Setting/Model/SettingClaudeModel.jsx (1)

201-213: Enforce upper bound of 1.0 on BudgetTokens percentage input
No backend validation exists for values >1.0 on the thinking_adapter_budget_tokens_percentage float64 field (only the struct is defined in Go), so re-add max={1} to the InputNumber in web/src/pages/Setting/Model/SettingClaudeModel.jsx (lines 201–213).

🧹 Nitpick comments (2)
relay/channel/claude/adaptor.go (1)

70-73: Consistent anthropic-beta forwarding; confirm header precedence

Matches AWS adaptor. As coded, model_setting.WriteHeaders may overwrite the forwarded beta header. Confirm whether config should override client preference; if not, move Set("anthropic-beta", ...) after WriteHeaders.

To ensure consistency everywhere:

-  req.Set("anthropic-version", anthropicVersion)
-  anthropicBeta := c.Request.Header.Get("anthropic-beta")
-  if anthropicBeta != "" { req.Set("anthropic-beta", anthropicBeta) }
-  model_setting.GetClaudeSettings().WriteHeaders(info.OriginModelName, req)
+  req.Set("anthropic-version", anthropicVersion)
+  model_setting.GetClaudeSettings().WriteHeaders(info.OriginModelName, req)
+  if v := c.Request.Header.Get("anthropic-beta"); v != "" { req.Set("anthropic-beta", v) }
web/src/i18n/locales/en.json (1)

1407-1407: Clarify inclusive boundary in helper text

The key "0.1以上的小数" currently reads "Decimal above 0.1", which implies >0.1 but the Chinese means ≥0.1. Update to:

-  "0.1以上的小数": "Decimal above 0.1",
+  "0.1以上的小数": "Decimal ≥ 0.1",

Verify that the UI input validation enforces a minimum of 0.1.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3154440 and 30cb3b8.

📒 Files selected for processing (6)
  • dto/claude.go (1 hunks)
  • relay/channel/aws/adaptor.go (1 hunks)
  • relay/channel/claude/adaptor.go (1 hunks)
  • web/src/i18n/locales/en.json (1 hunks)
  • web/src/i18n/locales/fr.json (1 hunks)
  • web/src/pages/Setting/Model/SettingClaudeModel.jsx (1 hunks)
🔇 Additional comments (3)
relay/channel/aws/adaptor.go (1)

55-58: Confirm anthropic-beta header precedence
In both relay/channel/aws/adaptor.go (lines 55–58) and relay/channel/claude/adaptor.go (70–73), you propagate anthropic-beta before calling model_setting.WriteHeaders, which allows site-level config to overwrite the client’s header. If client-provided headers should take precedence, move this block below WriteHeaders in each adaptor. (Optional) Centralize anthropic-beta forwarding across adaptors to avoid duplication.

dto/claude.go (1)

199-204: All confirmed: no BC issues with ContextManagement

Both dto.ClaudeRequest literals in relay/channel/claude/relay-claude.go use fully keyed fields (no positional literals), so adding ContextManagement won’t break existing code. The override logic (ApplyParamOverride) unmarshals into a generic map and re-serializes, preserving any fields (including context_management).

web/src/pages/Setting/Model/SettingClaudeModel.jsx (1)

205-205: LGTM! Good i18n improvement.

The change to use a translated key for the helper text improves internationalization support.

"Claude思考适配 BudgetTokens = MaxTokens * BudgetTokens 百分比": "Adaptation de la pensée Claude BudgetTokens = MaxTokens * BudgetTokens pourcentage",
"思考适配 BudgetTokens 百分比": "Adaptation de la pensée BudgetTokens pourcentage",
"0.1-1之间的小数": "Décimal entre 0,1 et 1",
"0.1以上的小数": "Décimal supérieur à 0,1",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Correction: inclusive boundary in FR

Use “supérieur ou égal à 0,1” to reflect ≥.

-  "0.1以上的小数": "Décimal supérieur à 0,1",
+  "0.1以上的小数": "Décimal supérieur ou égal à 0,1",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"0.1以上的小数": "Décimal supérieur à 0,1",
"0.1以上的小数": "Décimal supérieur ou égal à 0,1",
🤖 Prompt for AI Agents
In web/src/i18n/locales/fr.json around line 1407, the French translation
currently reads "Décimal supérieur à 0,1" but should reflect an inclusive
boundary (≥); update the value to "Décimal supérieur ou égal à 0,1" to match the
intended meaning while preserving surrounding JSON formatting and quoting.

@seefs001
seefs001 merged commit 933ab43 into QuantumNous:alpha Sep 30, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Feb 28, 2026
x22x22 pushed a commit to x22x22/new-api that referenced this pull request Apr 24, 2026
…ext-editing

feat: claude context editing
@coderabbitai coderabbitai Bot mentioned this pull request Jun 16, 2026
8 of 11 tasks
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
…ext-editing

feat: claude context editing
junjundesk pushed a commit to junjundesk/new-api that referenced this pull request Oct 3, 2026
…ext-editing

feat: claude context editing
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.

1 participant