fix(claude): forward workspace ID for Anthropic and Bedrock - #6751
fix(claude): forward workspace ID for Anthropic and Bedrock#6751hjxwz123 wants to merge 1 commit into
Conversation
WalkthroughThe change adds Anthropic workspace ID configuration to supported channel forms. Direct Anthropic requests forward the resolved header. AWS Bedrock requests pass it through signed SDK options for streaming and non-streaming invocations. Tests cover precedence, trimming, serialization, and signing. ChangesWorkspace ID configuration
Direct Anthropic forwarding
AWS Bedrock forwarding
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant ChannelForm
participant RelayAdapter
participant AWSBedrockSDK
ChannelForm->>RelayAdapter: Provide workspace ID setting
RelayAdapter->>RelayAdapter: Resolve configured or incoming header
RelayAdapter->>AWSBedrockSDK: Invoke with workspace header API option
AWSBedrockSDK->>AWSBedrockSDK: Sign workspace header
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Warning Tools execution failed with the following error: Failed to run tools: 14 UNAVAILABLE: read ECONNRESET 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.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@web/src/features/channels/lib/__tests__/anthropic-workspace-id.test.ts`:
- Around line 29-38: Add an explicit return type to the formValues function
while preserving its current parameter types and returned form-value structure.
In `@web/src/i18n/locales/vi.json`:
- Line 4163: Update the Vietnamese translation for the anthropic-workspace-id
description to translate “header” as “header anthropic-workspace-id” or “HTTP
header anthropic-workspace-id,” using the locale’s existing HTTP-header
terminology instead of “tiêu đề.”
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: cfb2862e-e15a-4da9-bef8-9439afdfbdf3
📒 Files selected for processing (18)
relay/channel/aws/adaptor.gorelay/channel/aws/relay-aws.gorelay/channel/aws/relay_aws_test.gorelay/channel/claude/adaptor.gorelay/channel/claude/adaptor_test.gorelay/channel/claude/constants.gorelaykit/dto/channel_settings.goweb/src/features/channels/components/drawers/channel-mutate-drawer.tsxweb/src/features/channels/lib/__tests__/anthropic-workspace-id.test.tsweb/src/features/channels/lib/channel-form.tsweb/src/features/channels/types.tsweb/src/i18n/locales/en.jsonweb/src/i18n/locales/fr.jsonweb/src/i18n/locales/ja.jsonweb/src/i18n/locales/ru.jsonweb/src/i18n/locales/vi.jsonweb/src/i18n/locales/zh-TW.jsonweb/src/i18n/locales/zh.json
| function formValues(type: number, workspaceID: string) { | ||
| return { | ||
| ...CHANNEL_FORM_DEFAULT_VALUES, | ||
| name: 'Claude upstream', | ||
| type, | ||
| key: 'test-key', | ||
| models: 'claude-sonnet-4-6', | ||
| anthropic_workspace_id: workspaceID, | ||
| } | ||
| } |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Add an explicit return type to formValues.
The coding guidelines require explicit parameter and return types in TypeScript files.
Proposed fix
+import type { ChannelFormValues } from '../channel-form'
+
-function formValues(type: number, workspaceID: string) {
+function formValues(
+ type: number,
+ workspaceID: string
+): ChannelFormValues {As per coding guidelines, “参数和返回值应显式标注类型.”
📝 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.
| function formValues(type: number, workspaceID: string) { | |
| return { | |
| ...CHANNEL_FORM_DEFAULT_VALUES, | |
| name: 'Claude upstream', | |
| type, | |
| key: 'test-key', | |
| models: 'claude-sonnet-4-6', | |
| anthropic_workspace_id: workspaceID, | |
| } | |
| } | |
| import type { ChannelFormValues } from '../channel-form' | |
| function formValues( | |
| type: number, | |
| workspaceID: string | |
| ): ChannelFormValues { | |
| return { | |
| ...CHANNEL_FORM_DEFAULT_VALUES, | |
| name: 'Claude upstream', | |
| type, | |
| key: 'test-key', | |
| models: 'claude-sonnet-4-6', | |
| anthropic_workspace_id: workspaceID, | |
| } | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@web/src/features/channels/lib/__tests__/anthropic-workspace-id.test.ts`
around lines 29 - 38, Add an explicit return type to the formValues function
while preserving its current parameter types and returned form-value structure.
Source: Coding guidelines
| "Sending...": "Đang gửi...", | ||
| "Sensitive channel settings are read-only for your account.": "Các cài đặt kênh nhạy cảm chỉ đọc đối với tài khoản của bạn.", | ||
| "Sensitive Words": "Từ ngữ nhạy cảm", | ||
| "Sent as anthropic-workspace-id to select the configured Anthropic workspace or Bedrock Mantle project.": "Được gửi dưới dạng tiêu đề anthropic-workspace-id để chọn không gian làm việc Anthropic hoặc dự án Bedrock Mantle đã cấu hình.", |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Use header for the HTTP header.
Line 4163 translates header as tiêu đề, which means “title” in Vietnamese. Use header anthropic-workspace-id or HTTP header anthropic-workspace-id for consistency with the existing locale terminology.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@web/src/i18n/locales/vi.json` at line 4163, Update the Vietnamese translation
for the anthropic-workspace-id description to translate “header” as “header
anthropic-workspace-id” or “HTTP header anthropic-workspace-id,” using the
locale’s existing HTTP-header terminology instead of “tiêu đề.”
|
CI baseline note: The failing
Current run: https://github.com/QuantumNous/new-api/actions/runs/31373819592/job/93408486945 Baseline #6749 run with the same annotations: https://github.com/QuantumNous/new-api/actions/runs/31357884778/job/93360891376 The backend CI and PR quality checks pass. The affected Claude/AWS packages, relaykit module, frontend typecheck, focused frontend regression test, and production frontend build also passed locally as listed in the PR description. |
51fdfc5 to
2b6f1df
Compare
Important
📝 变更描述 / Description
This fixes inconsistent
anthropic-workspace-idforwarding in the existing Anthropic and AWS Bedrock channels.anthropic_workspace_idchannel setting for Anthropic and AWS Bedrock.header_override> administrator setting > incoming client header.The change does not create or modify any AWS retention setting and does not enable
provider_data_share. Selecting a workspace/project can avoid unintended account-level fallback, but it cannot make an unsupported retention mode valid on the selected account or project.AI assistance disclosure: implementation and initial drafting were AI-assisted. The request paths, precedence, final outbound headers, signatures, tests, and submitted diff were reviewed for this specific issue.
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
Passed locally:
Focused lint and format checks pass for the changed frontend files. Repository-wide frontend lint/format checks still report unrelated pre-existing findings outside this patch.
Summary by CodeRabbit
New Features
Bug Fixes
Tests