Skip to content

fix: 修复多处小型回归#4946

Open
wucm667 wants to merge 1 commit into
QuantumNous:mainfrom
wucm667:fix/bcdefg-issues
Open

fix: 修复多处小型回归#4946
wucm667 wants to merge 1 commit into
QuantumNous:mainfrom
wucm667:fix/bcdefg-issues

Conversation

@wucm667
Copy link
Copy Markdown

@wucm667 wucm667 commented May 18, 2026

⚠️ 提交说明 / PR Notice

Important

  • 已按模板整理本次 PR 的变更范围、关联 Issue 与本地验证结果。

📝 变更描述 / Description

本 PR 集中修复 6 个相互独立的小型回归:

  • Remix 基于已有任务提交时,查到原任务后改用保存的 upstream task ID,避免 Sora remix URL 继续使用客户端侧任务 ID。
  • Claude 流式 message_start 只有在未发生模型映射时才更新 UpstreamModelName,避免 AWS Claude 覆盖模型重定向后的计费/日志模型名。
  • 创建令牌接口返回插入后的 token 数据,使调用方可以拿到新建 ID。
  • classic 渠道新建弹窗在读取剪贴板前检查 navigator.clipboard.readText 是否存在,避免 HTTP 环境白屏。
  • default 分组筛选下拉框从固定 200px 改为自适应宽度并设置最大宽度,改善长分组名显示。
  • 补齐 classic 仪表盘“异常”在 fr/ja/ru/vi/zh-TW 的翻译;当前 main 上 en 已有翻译,因此未重复改动。

🚀 变更类型 / 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

  • go test ./controller ./relay ./relay/channel/task/sora:通过
  • go test ./controller -run TestAddTokenReturnsCreatedToken:通过
  • go test ./relay/channel/claude -run TestHandleStreamResponseDataPreservesMappedModelName:通过
  • cd web/default && npx --yes bun run build:通过(本机 Node 20.13.1 低于 Rspack 推荐版本,构建仍成功)
  • cd web/classic && npx --yes bun run build:通过(仅有 Browserslist 数据过期与 lottie-web eval 的既有警告)

备注:go test ./relay/channel/claude 整包测试目前会在既有 TestRequestOpenAI2ClaudeMessage_* file_content 转换断言上失败,和本 PR 修改的流式模型名逻辑无关;本 PR 新增的 Claude 回归用例已单独通过。

Summary by CodeRabbit

  • New Features

    • Token API responses now include the created token data.
  • Bug Fixes

    • Model name mappings are now preserved when already configured.
    • Improved clipboard detection in channel modal creation mode.
    • Task resolution now correctly uses upstream task identifiers.
  • Localization

    • Completed translations for French, Japanese, Russian, Vietnamese, and Traditional Chinese.
  • Style

    • Enhanced data table filter popover width and sizing.
  • Tests

    • Added tests for token creation response and model name mapping preservation.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 18, 2026

Walkthrough

This PR addresses four bug fixes and enhancements spanning backend APIs, relay stream handling, task orchestration, and frontend UX: token creation now returns the created token, Claude streaming preserves intentional model mapping, remix operations use upstream task identifiers, clipboard detection safeguards HTTP deployments, missing UI translations are filled for multiple locales, and popover styling becomes responsive.

Changes

Backend API and Relay Logic Improvements

Layer / File(s) Summary
Token creation returns token data
controller/token.go, controller/token_test.go
Token API response now includes the created token in a data field; test struct is reformatted and a new test (TestAddTokenReturnsCreatedToken) verifies response structure, token ID, name, and database persistence.
Claude streaming preserves mapped model names
relay/channel/claude/relay-claude.go, relay/channel/claude/relay_claude_test.go
message_start stream events now only update UpstreamModelName from response if model mapping is not already active (!IsModelMapped), preventing overwrites of deliberately mapped models; new test confirms preservation behavior.
Task remix uses upstream task ID
relay/relay_task.go
ResolveOriginTask overwrites OriginTaskID with the fetched origin task's upstream ID, ensuring subsequent channel locking and remix parameter extraction operate on the actual upstream identifier.

Frontend Polish and Localization

Layer / File(s) Summary
Clipboard detection guards HTTP contexts
web/classic/src/components/table/channels/modals/EditChannelModal.jsx
Clipboard auto-read logic now explicitly checks that navigator.clipboard.readText exists before invoking, preventing white-screen errors when clipboard API is unavailable in non-HTTPS deployments.
Complete missing exception translations
web/classic/src/i18n/locales/{fr,ja,ru,vi,zh-TW}.json
The i18n key "异常" (exception/anomaly) is translated and filled for French, Japanese, Russian, Vietnamese, and Traditional Chinese locales, replacing previous empty strings.
Responsive popover width styling
web/default/src/components/data-table/faceted-filter.tsx
PopoverContent width updates from fixed w-[200px] to responsive min-w-[200px], w-auto, and max-w-[320px], allowing content-aware expansion within bounds.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • QuantumNous/new-api#1833: Changes Claude response adaptor routing to claude.Claude*Handler, which works with the main PR's fix to stream message_start handling for model mapping preservation.

Suggested reviewers

  • Calcium-Ion
  • seefs001

Poem

🐰 Tokens now dance with data in tow,
Claude's models stay mapped through the flow,
Remix finds true upstream lanes,
Clipboards guard HTTP's reins,
Dropdowns breathe, translations glow!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The PR title is vague and non-descriptive, using only generic Chinese 'fix: 修复多处小型回归' (fix: fix multiple small regressions) without specifying which regressions or the main focus. Replace generic title with a specific, concise summary of the primary change(s), e.g., 'fix: use upstream task ID for remix and prevent model mapping override' or similar to clarify main objectives.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The PR successfully addresses all six linked issue requirements: (1) remix uses upstream task ID [#4120], (2) Claude streaming preserves mapped model name [#4522], (3) token creation returns created token data [#2908], (4) clipboard access checks for readText existence [#4014], (5) dropdown width becomes adaptive [#4905], (6) missing translations added for 异常 [#3111].
Out of Scope Changes check ✅ Passed All changes directly address the six linked issues. Code changes (token response, Claude streaming, remix task ID, clipboard check, dropdown width) plus translations are all scoped to the documented fixes without introducing unrelated modifications.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.42.2)
web/classic/src/components/table/channels/modals/EditChannelModal.jsx

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
Copy Markdown
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 (1)
relay/channel/claude/relay_claude_test.go (1)

55-75: ⚡ Quick win

Consider adding a complementary test case for when model is not mapped.

The test correctly verifies that mapped model names are preserved. For completeness, consider adding a test case that verifies the model name IS updated when IsModelMapped=false:

📝 Suggested additional test case
func TestHandleStreamResponseDataUpdatesUnmappedModelName(t *testing.T) {
	gin.SetMode(gin.TestMode)
	recorder := httptest.NewRecorder()
	c, _ := gin.CreateTestContext(recorder)
	c.Request = httptest.NewRequest("POST", "/v1/messages", nil)

	info := &relaycommon.RelayInfo{
		RelayFormat: types.RelayFormatClaude,
		ChannelMeta: &relaycommon.ChannelMeta{
			IsModelMapped:     false,
			UpstreamModelName: "original-model",
		},
	}
	claudeInfo := &ClaudeResponseInfo{Usage: &dto.Usage{}}
	data := `{"type":"message_start","message":{"id":"msg_123","model":"provider-claude-model","usage":{"input_tokens":1,"output_tokens":1}}}`

	err := HandleStreamResponseData(c, info, claudeInfo, data)

	require.Nil(t, err)
	require.Equal(t, "provider-claude-model", info.UpstreamModelName)
}
🤖 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 `@relay/channel/claude/relay_claude_test.go` around lines 55 - 75, Add a
complementary unit test to verify behaviour when the channel is not
model-mapped: create a test (e.g.,
TestHandleStreamResponseDataUpdatesUnmappedModelName) that sets
relaycommon.RelayInfo.ChannelMeta.IsModelMapped = false with an initial
UpstreamModelName, calls HandleStreamResponseData with a Claude stream payload
containing "model":"provider-claude-model", asserts no error, and asserts
info.UpstreamModelName was updated to "provider-claude-model"; this ensures
HandleStreamResponseData updates the upstream model when IsModelMapped is false.
🤖 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.

Nitpick comments:
In `@relay/channel/claude/relay_claude_test.go`:
- Around line 55-75: Add a complementary unit test to verify behaviour when the
channel is not model-mapped: create a test (e.g.,
TestHandleStreamResponseDataUpdatesUnmappedModelName) that sets
relaycommon.RelayInfo.ChannelMeta.IsModelMapped = false with an initial
UpstreamModelName, calls HandleStreamResponseData with a Claude stream payload
containing "model":"provider-claude-model", asserts no error, and asserts
info.UpstreamModelName was updated to "provider-claude-model"; this ensures
HandleStreamResponseData updates the upstream model when IsModelMapped is false.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fd1940ad-205e-452f-b63a-8df58554faa7

📥 Commits

Reviewing files that changed from the base of the PR and between 5dd0d3b and 14d57b8.

📒 Files selected for processing (12)
  • controller/token.go
  • controller/token_test.go
  • relay/channel/claude/relay-claude.go
  • relay/channel/claude/relay_claude_test.go
  • relay/relay_task.go
  • web/classic/src/components/table/channels/modals/EditChannelModal.jsx
  • web/classic/src/i18n/locales/fr.json
  • web/classic/src/i18n/locales/ja.json
  • web/classic/src/i18n/locales/ru.json
  • web/classic/src/i18n/locales/vi.json
  • web/classic/src/i18n/locales/zh-TW.json
  • web/default/src/components/data-table/faceted-filter.tsx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant