Skip to content

feat(channel): 使用表单配置获取上游模型 - #5949

Open
zuiho-kai wants to merge 3 commits into
QuantumNous:mainfrom
zuiho-kai:codex/channel-form-fetch-models
Open

feat(channel): 使用表单配置获取上游模型#5949
zuiho-kai wants to merge 3 commits into
QuantumNous:mainfrom
zuiho-kai:codex/channel-form-fetch-models

Conversation

@zuiho-kai

@zuiho-kai zuiho-kai commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

⚠️ 提交说明 / PR Notice

Important

📝 变更描述 / Description

当前在创建或编辑渠道时,获取上游模型的行为没有完全使用表单里的未保存配置:创建模式只提交 type/key/base_url,后端单独手写了一套模型列表请求逻辑;编辑模式在未保存新 key 时仍使用已保存渠道配置。这会导致表单里刚填的代理设置、header override 等配置无法参与获取模型,也容易和已保存渠道的正式获取逻辑不一致。

本 PR 将 POST /api/channel/fetch_models 改为接收渠道表单配置并复用现有 fetchChannelUpstreamModelIDs。这样 provider 特殊路径、代理、header override、Ollama/Gemini 等逻辑都和已保存渠道获取上游模型保持一致。

前端新增从渠道表单生成获取模型 payload 的转换函数。创建渠道时会直接用当前表单中的 key、Base URL、代理设置和 header override 拉取模型;编辑已有渠道时,只有用户在表单中填入新 key 才会走表单配置请求,未填写新 key 时仍保持原有按已保存渠道获取的行为,避免把已保存密钥发送到任意未保存的 Base URL。

🚀 变更类型 / Type of change

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

🔗 关联任务 / Related Issue

✅ 提交前检查项 / Checklist

📸 运行证明 / Proof of Work

已执行:

bun run typecheck
bunx oxlint -c .oxlintrc.json src/features/channels/api.ts src/features/channels/components/drawers/channel-mutate-drawer.tsx src/features/channels/lib/channel-form.ts
git diff --check upstream/main..HEAD
bun run build

说明:当前本地 Windows 环境未安装 go / gofmt,因此 Go 编译与格式检查由 CI 继续验证。

Summary by CodeRabbit

  • New Features

    • Enhanced the “Fetch Models” flow to accept additional channel configuration options, including broader handling of settings and header overrides.
  • Bug Fixes

    • Improved “Fetch Models” reliability with stricter channel key/API key validation and consistent model ID results from upstream sources.
    • Refined when the “Fetch Models” dialog triggers during create vs. edit to avoid unnecessary fetch attempts.
  • Tests

    • Added unit tests covering channel key normalization, API key requirements by channel type, and request-to-channel handling.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2a30a0ee-3912-46bd-a4d7-bbe3705bc75d

📥 Commits

Reviewing files that changed from the base of the PR and between 1282637 and c27a409.

📒 Files selected for processing (2)
  • controller/channel.go
  • controller/channel_fetch_models_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • controller/channel.go

Walkthrough

The channel model-fetching flow was refactored end-to-end. The backend now binds channel-shaped request data and returns upstream model IDs, while the frontend builds fetch payloads from form state and adjusts the Fetch Models dialog wiring.

Changes

Channel model fetching refactor

Layer / File(s) Summary
Backend FetchModels rewrite
controller/channel.go, controller/channel_fetch_models_test.go
Removes the direct gemini import; FetchModels now binds JSON into a channel-shaped request, normalizes channel.Key, enforces key requirements for non-Ollama channels, calls fetchChannelUpstreamModelIDs, and returns upstream model IDs. Tests cover key normalization, key requirements, and channel conversion behavior.
Frontend payload contract and transform helper
web/default/src/features/channels/api.ts, web/default/src/features/channels/lib/channel-form.ts
fetchModels accepts optional setting, settings, and header_override fields; transformFormDataToFetchModelsPayload builds the request from ChannelFormValues, and related settings cleanup and ignored-model dedup logic are adjusted.
Drawer wiring and fetcher gating
web/default/src/features/channels/components/drawers/channel-mutate-drawer.tsx
The drawer now uses transformFormDataToFetchModelsPayload(form.getValues()) for fetch requests and enables FetchModelsDialog custom fetching in edit mode when a key is present.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

Suggested reviewers: seefs001

Poem

A bunny hopped through channel code,
And fetched the models on one road.
Keys got trimmed, the forms aligned,
IDs came back neat and kind.
Hop hop! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了本次改动:使用表单配置获取上游模型。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 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.

@zuiho-kai zuiho-kai reopened this Jul 8, 2026
@zuiho-kai zuiho-kai closed this Jul 8, 2026
@zuiho-kai zuiho-kai reopened this Jul 8, 2026
Signed-off-by: zuiho <2324465096@qq.com>
@zuiho-kai

Copy link
Copy Markdown
Contributor Author

@Calcium-Ion

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

🤖 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 `@controller/channel.go`:
- Around line 1171-1204: FetchModels currently binds the full model.Channel,
which lets client-supplied fields influence fetchChannelUpstreamModelIDs and
downstream GetNextEnabledKey/CacheGetChannelInfo behavior. Replace the
ShouldBindJSON target with a narrow request DTO containing only request-scoped
fields needed for model fetching, then resolve any persisted channel state
server-side before calling fetchChannelUpstreamModelIDs. Keep the existing
FetchModels flow and validation logic, but ensure channel.Id and
channel.ChannelInfo are not accepted from the client payload.
🪄 Autofix (Beta)

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

Run ID: 5b3978f3-be90-4cd6-8594-7a28e28e1565

📥 Commits

Reviewing files that changed from the base of the PR and between 8739c05 and 1282637.

📒 Files selected for processing (5)
  • controller/channel.go
  • controller/channel_fetch_models_test.go
  • web/default/src/features/channels/api.ts
  • web/default/src/features/channels/components/drawers/channel-mutate-drawer.tsx
  • web/default/src/features/channels/lib/channel-form.ts

Comment thread controller/channel.go
Signed-off-by: zuiho <2324465096@qq.com>
@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.

1 participant