Skip to content

修复:新建渠道获取模型时应用代理与请求头覆盖 - #6663

Closed
nanoapple8888 wants to merge 19 commits into
QuantumNous:mainfrom
nanoapple8888:fix/fetch-models-create-preview-overrides
Closed

修复:新建渠道获取模型时应用代理与请求头覆盖#6663
nanoapple8888 wants to merge 19 commits into
QuantumNous:mainfrom
nanoapple8888:fix/fetch-models-create-preview-overrides

Conversation

@nanoapple8888

@nanoapple8888 nanoapple8888 commented Aug 5, 2026

Copy link
Copy Markdown

摘要

  • 新建普通渠道“从上游获取模型”时应用表单中的 proxyheader_override,与高级自定义预览及已保存渠道行为一致
  • 上游返回 HTML 时给出明确错误提示,不再暴露 invalid character '<' looking for beginning of value
  • 跳过密钥首行空行,避免误用空 Bearer

根因

新建未保存渠道走 POST /api/channel/fetch_models 表单预览路径,后端只组装了 Type/Key/BaseURL,丢弃前端已提交的 proxy/header_override。保存后走 GET /api/channel/fetch_models/:id 读取完整 DB 配置,因此表现为“先保存再获取就不报错”。

验证

  • go test ./controller -count=1 -run 'FetchModels|BuildFetchModels|ParseOpenAIModelIDs'
  • go test ./controller -count=1

风险

  • 仅影响渠道管理端“获取上游模型”预览;不改变已保存渠道的凭据复用策略
  • 未部署生产

AI 辅助

Codex / opencode 辅助定位、实现与测试编写;提交前已人工核对 diff 与测试结果。

Summary by CodeRabbit

  • New Features

    • Added configurable relay request tracing with failure-only or all-request modes, privacy-aware redaction, and optional full-body capture.
    • Added opt-in diagnostics for failed image-generation requests.
    • Gemini responses now correctly normalize Markdown-embedded images.
    • Improved model preview channel handling, saved-channel support, and request overrides.
    • Added automatic recovery from stale frontend chunk errors.
  • Bug Fixes

    • Missing static assets now return uncached 404 responses.
    • Improved upstream model-fetch error messages and routing accuracy.
    • Updated branding to Nanoapple and refined model-pricing terminology.
  • Documentation

    • Expanded configuration, contribution, and release guidance.

zaneWWWWWW and others added 19 commits July 22, 2026 16:41
支持全链路转发追踪、完整正文风险开关和模型映射上下游表达优化
关闭顶部导航文档后同步隐藏首页文档按钮
正确识别 error 接口中的空指针,避免成功请求被当作失败请求记录,同时补充仅失败与全部记录模式的回归测试。
通过中文 PR 补齐协作规范、PR 模板和前端旧分包故障审计记录。保留既有生产提交历史,不触发 Nanoapple 或 Macroapple 部署。
…fields

功能(web):模型价格统一为四项核心字段
修复(web):仅修改价格名称并恢复全部价格项
…el-key

修复:编辑普通渠道时使用已保存凭据获取模型
新建普通渠道预览此前只使用 type/key/base_url,丢弃前端提交的
proxy 与 header_override,导致“新建时获取失败、保存后再获取成功”。
同时将上游 HTML 响应的 JSON 解析错误改为可操作提示。
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7dbab18a-d7aa-40d6-b295-60a664b721ee

📥 Commits

Reviewing files that changed from the base of the PR and between 0ab0202 and 1691c19.

⛔ Files ignored due to path filters (3)
  • web/public/apple-touch-icon.png is excluded by !**/*.png
  • web/public/favicon.ico is excluded by !**/*.ico
  • web/public/logo.png is excluded by !**/*.png
📒 Files selected for processing (57)
  • .env.example
  • .github/PULL_REQUEST_TEMPLATE.md
  • CONTRIBUTING.md
  • README.en.md
  • README.zh_CN.md
  • common/init.go
  • constant/env.go
  • controller/channel.go
  • controller/channel_upstream_update.go
  • controller/channel_upstream_update_test.go
  • controller/relay.go
  • docs/changes/2026-08-02-stale-chunk-recovery.md
  • model/channel_cache.go
  • model/option.go
  • model/pricing_endpoint_test.go
  • relay/channel/api_request.go
  • relay/channel/gemini/markdown_image.go
  • relay/channel/gemini/markdown_image_test.go
  • relay/channel/gemini/relay-gemini-native.go
  • relay/channel/gemini/relay-gemini.go
  • relay/channel/gemini/relay_responses.go
  • relay/helper/image_failure_audit.go
  • relay/helper/image_failure_audit_test.go
  • relay/helper/relay_trace.go
  • relay/helper/relay_trace_test.go
  • router/web-router.go
  • router/web_router_test.go
  • setting/ratio_setting/group_ratio.go
  • web/index.html
  • web/src/assets/logo.tsx
  • web/src/components/layout/components/footer.tsx
  • web/src/components/layout/components/system-brand.tsx
  • web/src/features/channels/components/dialogs/edit-tag-dialog.tsx
  • web/src/features/channels/components/drawers/channel-mutate-drawer.tsx
  • web/src/features/channels/components/model-mapping-editor.tsx
  • web/src/features/errors/general-error.tsx
  • web/src/features/errors/lib/__tests__/stale-chunk-recovery.test.ts
  • web/src/features/errors/lib/stale-chunk-recovery.ts
  • web/src/features/home/components/sections/hero.tsx
  • web/src/features/system-settings/maintenance/relay-trace-section.tsx
  • web/src/features/system-settings/models/__tests__/pricing-lanes.test.ts
  • web/src/features/system-settings/models/model-pricing-core.ts
  • web/src/features/system-settings/models/model-pricing-sheet.tsx
  • web/src/features/system-settings/operations/index.tsx
  • web/src/features/system-settings/operations/section-registry.tsx
  • web/src/features/system-settings/site/index.tsx
  • web/src/features/system-settings/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
  • web/src/i18n/static-keys.ts
  • web/src/lib/constants.ts
  • web/src/routes/_authenticated/system-settings/operations/$section.tsx

Walkthrough

The pull request adds configurable relay tracing and image-failure auditing. It updates channel fetching, model routing, Gemini image handling, stale-chunk recovery, web fallback responses, frontend settings, branding, localization, and repository workflow documentation.

Changes

Relay observability

Layer / File(s) Summary
Trace configuration and settings
.env.example, common/*, constant/*, model/option.go, web/src/features/system-settings/*, web/src/i18n/*
Adds relay trace modes, body-capture limits, full-body capture settings, validation, persistence, UI controls, localization, and documentation.
Trace capture and image-failure auditing
relay/helper/*, relay/channel/api_request.go, controller/relay.go
Captures sanitized upstream and downstream request data, responses, errors, timing, retries, and bodies. Adds bounded image-failure request summaries.
Gemini image normalization
relay/channel/gemini/*
Converts valid Markdown data images into Gemini inlineData parts for streaming and non-streaming responses.
Validation coverage
relay/helper/*_test.go, relay/channel/gemini/*_test.go
Tests redaction, truncation, body capture, failure filtering, image conversion, metadata preservation, and streaming behavior.

Channel and routing behavior

Layer / File(s) Summary
Model-fetch construction and routing
controller/channel.go, controller/channel_upstream_update.go, model/channel_cache.go
Centralizes preview channel construction, applies overrides, validates channel types, improves upstream parse errors, and routes through explicit enabled abilities.
Regression coverage
controller/channel_upstream_update_test.go, model/pricing_endpoint_test.go
Tests overrides, saved credentials, type validation, HTML responses, key handling, and explicit ability mappings.

Frontend recovery and presentation

Layer / File(s) Summary
Stale chunk recovery and web fallback
router/*, web/src/features/errors/*, docs/changes/*
Returns uncached 404 responses for missing static assets, serves the frontend index for client routes, and performs guarded stale-chunk reloads.
Frontend terminology, pricing, and navigation
web/src/features/channels/*, web/src/features/home/*, web/src/features/system-settings/models/*, web/src/i18n/*
Clarifies downstream and upstream model labels, updates pricing terminology, conditionally displays documentation navigation, and adds pricing tests.
Nanoapple branding
web/index.html, web/src/assets/*, web/src/components/layout/*, web/src/lib/constants.ts, web/src/features/system-settings/site/*
Replaces default New API branding with Nanoapple across metadata, logos, layout defaults, and system settings.

Repository workflow

Layer / File(s) Summary
Contribution and pull request guidance
CONTRIBUTING.md, .github/PULL_REQUEST_TEMPLATE.md
Adds Chinese collaboration rules, branch and deployment requirements, AI disclosure fields, validation details, and rollback information.

Estimated code review effort: 5 (Critical) | ~120 minutes

Possibly related PRs

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Relay
  participant UpstreamChannel
  participant RelayTrace
  participant TraceLogger
  Client->>Relay: submit relay request
  Relay->>RelayTrace: start trace
  Relay->>UpstreamChannel: send upstream request
  UpstreamChannel->>RelayTrace: capture request and response
  Relay->>RelayTrace: finish with success or error
  RelayTrace->>TraceLogger: write sanitized trace
Loading

Poem

A rabbit watched the traces glow,
While hidden secrets stayed below.
Gemini split images bright,
Old chunks refreshed just right.
Nanoapple banners danced in view—
“Hop, these changes are good as new!”

✨ Finishing Touches 💡 1
⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch fix/fetch-models-create-preview-overrides
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@nanoapple8888

Copy link
Copy Markdown
Author

误开到上游仓库,正确 PR 在 nanoapple8888#9

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