Skip to content

fix(claude): forward workspace ID for Anthropic and Bedrock - #6751

Draft
hjxwz123 wants to merge 1 commit into
QuantumNous:mainfrom
hjxwz123:fix/forward-anthropic-workspace-id
Draft

fix(claude): forward workspace ID for Anthropic and Bedrock#6751
hjxwz123 wants to merge 1 commit into
QuantumNous:mainfrom
hjxwz123:fix/forward-anthropic-workspace-id

Conversation

@hjxwz123

@hjxwz123 hjxwz123 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

⚠️ 提交说明 / PR Notice

Important

  • 请提供人工撰写的简洁摘要,避免直接粘贴未经整理的 AI 输出。

📝 变更描述 / Description

This fixes inconsistent anthropic-workspace-id forwarding in the existing Anthropic and AWS Bedrock channels.

  • Add an optional administrator-managed anthropic_workspace_id channel setting for Anthropic and AWS Bedrock.
  • Forward the selected value on direct Anthropic requests and Bedrock API-key HTTP requests.
  • Insert the header through the AWS SDK before SigV4 signing for AK/SK requests, including both streaming and non-streaming operations.
  • Use the precedence 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

  • 🐛 Bug 修复 (Bug fix) - 请关联对应 Issue,避免将设计取舍、理解偏差或预期不一致直接归类为 bug
  • ✨ 新功能 (New feature) - 重大特性建议先通过 Issue 沟通
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 IssuesPRs,确认不是重复提交。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

Passed locally:

go test ./relay/channel/claude ./relay/channel/aws -count=1
go vet ./relay/channel/claude ./relay/channel/aws
go test ./...
cd relaykit && GOWORK=off go build ./...
cd relaykit && GOWORK=off go test ./... -count=1
npm run typecheck
npx tsx --test src/features/channels/lib/__tests__/anthropic-workspace-id.test.ts
npm run build
git diff --check

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

    • Added Anthropic Workspace ID configuration for Anthropic and AWS Bedrock channels.
    • Workspace IDs are forwarded with Claude requests and support incoming header overrides.
    • Added channel form input, validation, persistence, and guidance for workspace or Bedrock Mantle project identifiers.
    • Added localized labels and instructions across supported languages.
  • Bug Fixes

    • Prevented unsupported channel types from retaining stale workspace ID settings.
  • Tests

    • Added coverage for trimming, precedence, persistence, and request forwarding in streaming and non-streaming scenarios.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The 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.

Changes

Workspace ID configuration

Layer / File(s) Summary
Channel settings and form serialization
relaykit/dto/channel_settings.go, web/src/features/channels/lib/channel-form.ts, web/src/features/channels/types.ts, web/src/features/channels/lib/__tests__/*
Channel settings and form values support anthropic_workspace_id. Supported Anthropic and AWS channels serialize trimmed values. Other channels remove stale values.
Channel editor and localization
web/src/features/channels/components/drawers/channel-mutate-drawer.tsx, web/src/i18n/locales/*
The channel editor shows the workspace ID field for channel types 14 and 33. Labels, examples, and header guidance are localized.

Direct Anthropic forwarding

Layer / File(s) Summary
Header resolution and forwarding
relay/channel/claude/constants.go, relay/channel/claude/adaptor.go, relay/channel/claude/adaptor_test.go
The adapter forwards a trimmed configured workspace ID, then an incoming header when no configured value exists. Tests verify precedence and upstream header output.

AWS Bedrock forwarding

Layer / File(s) Summary
SDK request options and coverage
relay/channel/aws/adaptor.go, relay/channel/aws/relay-aws.go, relay/channel/aws/relay_aws_test.go
AWS invocations pass the workspace header through Smithy API options. Nova requests clear the value. Tests cover overrides, trimming, streaming, non-streaming, and signed headers.

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
Loading

Poem

A rabbit hops through headers bright,
Trimming spaces left and right.
Claude carries the workspace key,
Bedrock signs it faithfully.
Forms and tests now spring with cheer.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: forwarding the workspace ID for Anthropic and AWS Bedrock.
Linked Issues check ✅ Passed The changes satisfy issue [#6750] by adding configuration, precedence handling, and signed workspace-ID forwarding for direct Anthropic and AWS Bedrock requests.
Out of Scope Changes check ✅ Passed The code, tests, form updates, DTO changes, and translations directly support workspace-ID configuration and forwarding.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

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

@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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between 9c97e78 and a6fb4a0.

📒 Files selected for processing (18)
  • relay/channel/aws/adaptor.go
  • relay/channel/aws/relay-aws.go
  • relay/channel/aws/relay_aws_test.go
  • relay/channel/claude/adaptor.go
  • relay/channel/claude/adaptor_test.go
  • relay/channel/claude/constants.go
  • relaykit/dto/channel_settings.go
  • web/src/features/channels/components/drawers/channel-mutate-drawer.tsx
  • web/src/features/channels/lib/__tests__/anthropic-workspace-id.test.ts
  • web/src/features/channels/lib/channel-form.ts
  • web/src/features/channels/types.ts
  • web/src/i18n/locales/en.json
  • web/src/i18n/locales/fr.json
  • web/src/i18n/locales/ja.json
  • web/src/i18n/locales/ru.json
  • web/src/i18n/locales/vi.json
  • web/src/i18n/locales/zh-TW.json
  • web/src/i18n/locales/zh.json

Comment on lines +29 to +38
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,
}
}

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.

📐 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.

Suggested change
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.",

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.

📐 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 đề.”

@hjxwz123

Copy link
Copy Markdown
Contributor Author

CI baseline note:

The failing Frontend typecheck and test job does not report an error in this PR's changed files. Its 10 annotations are the same existing failures seen on the immediately preceding merged PR #6749:

  • Seven existing node:test files fail under Bun 1.3.14 with describe() inside another test() is not yet implemented in Bun.
  • Three existing assertions fail in web/src/features/keys/components/__tests__/api-key-group-cell.test.tsx.
  • None of those paths are changed by this PR.

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.

@Calcium-Ion
Calcium-Ion force-pushed the main branch 2 times, most recently from 51fdfc5 to 2b6f1df Compare August 30, 2026 15:03
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.

Anthropic and AWS Bedrock channels do not consistently forward anthropic-workspace-id

1 participant