Skip to content

update - #5143

Closed
bitzhjr wants to merge 8 commits into
QuantumNous:mainfrom
Wischoicer-Xian:develop
Closed

update#5143
bitzhjr wants to merge 8 commits into
QuantumNous:mainfrom
Wischoicer-Xian:develop

Conversation

@bitzhjr

@bitzhjr bitzhjr commented May 27, 2026

Copy link
Copy Markdown

⚠️ 提交说明 / PR Notice

Important

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

📝 变更描述 / Description

(简述:做了什么?为什么这样改能生效?请基于你对代码逻辑的理解来写,避免粘贴未经整理的内容)

🚀 变更类型 / Type of change

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

🔗 关联任务 / Related Issue

  • Closes # (如有)

✅ 提交前检查项 / Checklist

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

📸 运行证明 / Proof of Work

(请在此粘贴截图、关键日志或测试报告,以证明变更生效)

Summary by CodeRabbit

Release Notes

  • New Features

    • API responses now consistently display the caller's selected model name instead of backend model mappings across all providers.
  • Bug Fixes

    • Removed internal model mapping metadata from user-visible responses and logs to prevent unintended data exposure.
    • Suppressed integrity headers (ETag, Content-MD5) when response content is modified.
  • Improvements

    • Restricted admin-only model mapping details to admin users in the usage logs interface.
    • Updated repository reference for release update checks.

Review Change Stack

ApocalypseYun and others added 8 commits May 17, 2026 01:51
…Name

Prevents model mapping info leak in classic UI table model column for
non-admin users. renderModelName now accepts isAdminUser parameter and
only shows upstream model popover when the user is an admin.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Replace upstream Calcium-Ion/new-api GitHub API URLs with
Wischoicer-Xian/new-api in both classic and default frontend themes
so the admin "Check for updates" feature queries our own fork.

Files changed:
- web/default/.../update-checker-section.tsx (API URL)
- web/classic/.../OtherSetting.jsx (API URL + release page link + comment)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Classic theme: add response.ok check before JSON parsing to prevent
crash when fork has no releases. Handle 404 with a clear message
and validate tag_name before use. Fallback marked.parse to empty
string when body is undefined.

Default theme: distinguish 404 (no release yet) from other API
errors with a specific user-facing message.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
… error messages

Previously the catch block always showed a generic '检查更新失败' message,
overriding the 404/HTTP status errors thrown earlier in checkUpdate().

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- model/log.go: delete is_model_mapped and upstream_model_name in
  formatUserLogs() so USER /api/log/self no longer leaks mapping info
- controller/task.go: clear UpstreamModelName in tasksToDto() when
  fillUser=false (USER /api/task/self path)
- default/details-dialog.tsx: guard Model Mapping section with
  props.isAdmin condition
- default/format.ts: add isAdmin param to formatModelName(), return
  actualModel only for admins
- default/common-logs-columns.tsx: pass isAdmin to formatModelName()
- classic/useUsageLogsData.jsx: add isAdminUser && guard to
  modelMapped check

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Change GitHub API and release page URLs from Wischoicer-Xian/new-api
to QuantumNous/new-api (the active upstream). Calcium-Ion/new-api
returns 301 (renamed). Error handling from previous round preserved.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
When model_mapping is active, the upstream provider returns the mapped
model name (e.g. qwen3.5-plus). Callers now see their original requested
model name (e.g. qwen3.6-flash) in all API response `model` fields.

- Add relay/common/response_model_alias.go with GetCallerModelName,
  PatchTopLevelModelRaw, PatchResponsesEventModelRaw helpers
- Patch all relay channels: OpenAI compatible/responses/chat-via-responses,
  Claude, xAI, Gemini, Ollama, Cloudflare, Cohere, Coze
- Strip ETag/Content-MD5 headers when response body is rewritten

Related: WIS-93

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…am handler

isAudioModel was based on caller model name, causing false negatives under
model mapping where the alias doesn't contain "audio" but the upstream model
is audio-capable. This led to usage stats being computed via text estimation
instead of the dedicated audio usage extraction path.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

Pull request was closed or merged during review

Walkthrough

This PR implements caller-visible model name aliasing across all relay handlers and redacts internal model mapping details from non-admin users. Backend relay handlers now preserve the caller's selected model name in responses instead of exposing upstream model names. User-facing logs and task DTOs hide model mapping fields for non-admin users. Frontend components restrict model mapping UI visibility to admins only. Web frontends also migrate GitHub release endpoints to a new repository.

Changes

Backend model aliasing and visibility control

Layer / File(s) Summary
Model aliasing infrastructure
relay/common/response_model_alias.go
New module provides GetCallerModelName() to select caller-visible model names, PatchTopLevelModelRaw() and PatchResponsesEventModelRaw() to rewrite JSON response payloads, and context flags to track when response bodies are rewritten.
Response header filtering on body rewrite
service/http.go
ShouldCopyUpstreamHeader now suppresses copying ETag and Content-MD5 headers when response body has been rewritten, preventing integrity header mismatches after model name patching.
Claude relay model preservation
relay/channel/claude/relay-claude.go
StreamResponseClaude2OpenAI and ResponseClaude2OpenAI now accept callerModel parameter and preserve it through conversions; FormatClaudeResponseInfo conditionally sets model only when unset, preventing upstream model from overwriting caller selection.
OpenAI relay model handling
relay/channel/openai/relay-openai.go, relay/channel/openai/chat_via_responses.go, relay/channel/openai/helper.go, relay/channel/openai/relay_responses.go
OpenAI handlers derive caller model from GetCallerModelName and preserve it throughout response paths; audio-model detection explicitly checks info.UpstreamModelName (not caller model) to enable correct usage extraction from SSE chunks; raw passthrough and response-format paths patch JSON payloads with caller model.
Remaining relay integrations
relay/channel/cloudflare/relay_cloudflare.go, relay/channel/cohere/relay-cohere.go, relay/channel/coze/relay-coze.go, relay/channel/gemini/relay-gemini.go, relay/channel/ollama/relay-ollama.go, relay/channel/ollama/stream.go, relay/channel/xai/text.go
All relay handlers updated to use GetCallerModelName for response Model fields; Ollama and X.AI handlers accept callerModel parameter in conversion functions.
Task and log redaction
controller/task.go, model/log.go
Task DTOs strip UpstreamModelName from Properties when fillUser is false; user-visible logs redact is_model_mapped and upstream_model_name from Other metadata.

Frontend usage logs admin visibility gating

Layer / File(s) Summary
Classic frontend usage logs
web/classic/src/components/table/usage-logs/UsageLogsColumnDefs.jsx, web/classic/src/hooks/usage-logs/useUsageLogsData.jsx
renderModelName adds isAdminUser parameter and gates the model mapping popover UI; useUsageLogsData restricts model mapping detail fields to admin users only.
Default frontend usage logs
web/default/src/features/usage-logs/lib/format.ts, web/default/src/features/usage-logs/components/columns/common-logs-columns.tsx, web/default/src/features/usage-logs/components/dialogs/details-dialog.tsx
formatModelName accepts isAdmin parameter and only populates actualModel for admins; Model column and details dialog conditionally include model mapping information based on admin status.

Frontend GitHub repository migration

Layer / File(s) Summary
Classic frontend update checker
web/classic/src/components/settings/OtherSetting.jsx
GitHub releases fetching switched to QuantumNous/new-api; improved error handling with response.ok checks and response validation; release body is parsed via marked.parse().
Default frontend update checker
web/default/src/features/system-settings/maintenance/update-checker-section.tsx
GitHub releases endpoint switched to QuantumNous/new-api with status-code-specific error messages (404 vs other failures).

Sequence Diagram(s)

sequenceDiagram
  participant Caller as API Caller
  participant RelayHandler as Relay Handler<br/>(e.g., OaiStreamHandler)
  participant Upstream as Upstream Service<br/>(OpenAI/Claude/etc)
  participant CommonUtils as relaycommon

  Caller->>RelayHandler: request with model="my-model"
  RelayHandler->>CommonUtils: GetCallerModelName(ctx, info)
  CommonUtils-->>RelayHandler: "my-model"
  
  RelayHandler->>Upstream: forward request
  Upstream->>RelayHandler: response with model="upstream-actual-model"
  
  RelayHandler->>RelayHandler: preserve callerModel="my-model"<br/>(ignore upstream.model)
  
  alt raw passthrough path
    RelayHandler->>CommonUtils: PatchTopLevelModelRaw(body, "my-model")
    CommonUtils-->>RelayHandler: patched body
  end
  
  RelayHandler->>Caller: response with model="my-model"
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • QuantumNous/new-api#3080: Modifies Claude relay response conversion functions in the same file; introduces tool-call state handling alongside caller-model preservation.
  • QuantumNous/new-api#2629: Introduces the OpenAI "chat via responses" handlers that this PR modifies to preserve caller model names.

Suggested reviewers

  • Calcium-Ion
  • creamlike1024

Poem

🐰 A rabbit hops through relays with glee,
Caller's own model name, now all can see!
Admin eyes only for mapped affairs,
While simple users don't get those cares.
From Calcium-Ion's nest, to Quantum's new home—
Fresh code, fresh repos, the APIlands roam! 🌱

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 34.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 pull request title 'update' is extremely vague and generic, providing no meaningful information about what was actually changed or why. Replace the title with a specific, descriptive summary of the main change (e.g., 'Hide model-mapping metadata from non-admin users in API responses and UI').
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch develop

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.

@bitzhjr bitzhjr closed this May 27, 2026
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