Skip to content

feat: advanced custom channel - #5590

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:feature/custom-ch
Jun 18, 2026
Merged

Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:feature/custom-ch

Conversation

@seefs001

@seefs001 seefs001 commented Jun 18, 2026 •

Copy link
Copy Markdown
Collaborator

⚠️ 提交说明 / PR Notice

Important

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

高级自定义渠道

📝 变更描述 / Description

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

🚀 变更类型 / Type of change

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

🔗 关联任务 / Related Issue

  • Closes # (如有)

✅ 提交前检查项 / Checklist

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

📸 运行证明 / Proof of Work

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

Summary by CodeRabbit

Release Notes

New Features

  • Advanced Custom channel type for multi-provider API routing with configurable routes
  • Per-route protocol conversion between OpenAI, Claude, and Gemini formats
  • Per-route authentication options and fallback routing behavior
  • UI editors for managing routes and advanced configuration

@coderabbitai

coderabbitai Bot commented Jun 18, 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

Run ID: eb37b49d-ce6b-4bb6-8786-600bce74e50c

📥 Commits

Reviewing files that changed from the base of the PR and between 21d4d18 and ff2b315.

📒 Files selected for processing (26)
  • common/api_type.go
  • constant/api_type.go
  • constant/channel.go
  • dto/channel_settings.go
  • model/channel.go
  • relay/channel/advancedcustom/adaptor.go
  • relay/channel/advancedcustom/adaptor_test.go
  • relay/common/relay_info.go
  • relay/relay_adaptor.go
  • web/default/src/components/ui/select.tsx
  • web/default/src/features/channels/components/dialogs/advanced-custom-editor-dialog.tsx
  • web/default/src/features/channels/components/drawers/channel-mutate-drawer.tsx
  • web/default/src/features/channels/constants.ts
  • web/default/src/features/channels/lib/advanced-custom.ts
  • web/default/src/features/channels/lib/channel-form-errors.ts
  • web/default/src/features/channels/lib/channel-form.ts
  • web/default/src/features/channels/lib/channel-type-config.ts
  • web/default/src/features/channels/lib/channel-utils.ts
  • web/default/src/features/channels/lib/index.ts
  • web/default/src/features/channels/types.ts
  • web/default/src/i18n/locales/en.json
  • web/default/src/i18n/locales/fr.json
  • web/default/src/i18n/locales/ja.json
  • web/default/src/i18n/locales/ru.json
  • web/default/src/i18n/locales/vi.json
  • web/default/src/i18n/locales/zh.json

Walkthrough

Adds a new "Advanced Custom" channel type (ID 58) with per-route request routing across OpenAI/Anthropic/Gemini backends. Includes Go constants, DTO structs with validation, a full relay adaptor with path matching and converter dispatch, React UI editor dialog, form/schema integration, and i18n strings for six locales.

Changes

Advanced Custom Channel Type

Layer / File(s) Summary
Backend constants, DTO structs, and validation
constant/api_type.go, constant/channel.go, common/api_type.go, dto/channel_settings.go
Defines ChannelTypeAdvancedCustom (58) and APITypeAdvancedCustom constants, extends ChannelBaseURLs/ChannelTypeNames, maps the channel type to its API type, and adds AdvancedCustomConfig/Route/Fallback/RouteAuth structs with converter and auth-type constants, IsAdvancedCustomConverterAllowed, and Validate() with full per-route incoming-path, upstream-path, converter, and auth validation.
Channel model validation and relay wiring
model/channel.go, relay/common/relay_info.go, relay/relay_adaptor.go
ValidateSettings unmarshals OtherSettings, enforces AdvancedCustom presence, requires base_url when fallback is enabled, and calls AdvancedCustom.Validate(). Adds AdvancedCustom to streamSupportedChannels. Registers advancedcustom.Adaptor{} in GetAdaptor.
advancedcustom relay adaptor
relay/channel/advancedcustom/adaptor.go
Implements Adaptor with Init, request conversion dispatch (OpenAI/Claude/Gemini/Rerank), GetRequestURL (route resolution, upstream URL construction, Gemini streaming rewrite, WS scheme switching), SetupRequestHeader (Bearer/custom/query auth, Claude headers), DoRequest (form/websocket/API selection), DoResponse (native/converter/fallback dispatch), path matching helpers ({model}, :generateContent), and conversion wrapper utilities.
Adaptor tests
relay/channel/advancedcustom/adaptor_test.go
Tests route matching with query-auth substitution, relative upstream path joining, missing base URL error, default Bearer and custom header auth, Claude headers for RelayFormatClaude, no-match error vs fallback URL, {model} placeholder replacement, Gemini streaming URL rewrite, and Gemini incoming-path template matching.
Frontend types, lib utilities, and form integration
web/default/src/features/channels/types.ts, web/default/src/features/channels/lib/advanced-custom.ts, web/default/src/features/channels/lib/channel-form.ts, web/default/src/features/channels/lib/channel-form-errors.ts, web/default/src/features/channels/lib/channel-type-config.ts, web/default/src/features/channels/lib/channel-utils.ts, web/default/src/features/channels/lib/index.ts, web/default/src/features/channels/constants.ts
Defines TypeScript interfaces/types for the config model; exports converter/auth/path option constants, template presets, parse/normalize/validate/stringify helpers, and stats computation in advanced-custom.ts. Registers channel 58 in display order, type configs, and icon mappings. Extends channelFormSchema with advanced_custom, adds superRefine validation with conditional base_url requirements, handles buildSettingsJSON and transformChannelToFormDefaults, and marks advanced_custom as an advanced settings field.
Frontend UI: editor dialog and drawer integration
web/default/src/features/channels/components/dialogs/advanced-custom-editor-dialog.tsx, web/default/src/features/channels/components/drawers/channel-mutate-drawer.tsx, web/default/src/components/ui/select.tsx
Adds AdvancedCustomEditorDialog with visual/JSON edit modes, template fill/append, RouteEditor subcomponent (converter, auth, incoming/upstream path fields), and FieldBlock layout helper. Extends ChannelMutateDrawer to compute stats badges (route count, fallback state, incomplete indicator), open the dialog, and write back to the form. Adds data-slot attribute to SelectItem's ItemText.
i18n: 6-locale translation keys
web/default/src/i18n/locales/en.json, web/default/src/i18n/locales/fr.json, web/default/src/i18n/locales/ja.json, web/default/src/i18n/locales/ru.json, web/default/src/i18n/locales/vi.json, web/default/src/i18n/locales/zh.json
Adds and reorders translation keys for all new Advanced Custom UI strings across all six locales: route/path/converter/auth labels, fallback routing, Gemini/Claude/OpenAI capability labels, validation messages, and routing behavior descriptions.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant ChannelMutateDrawer
  participant AdvancedCustomEditorDialog
  participant channelFormSchema
  participant ValidateSettings as model.ValidateSettings
  participant Adaptor as advancedcustom.Adaptor
  participant UpstreamAPI

  User->>ChannelMutateDrawer: Open "Configure routes"
  ChannelMutateDrawer->>AdvancedCustomEditorDialog: open=true, value=advanced_custom JSON
  User->>AdvancedCustomEditorDialog: Edit routes (visual/JSON), select template, save
  AdvancedCustomEditorDialog->>channelFormSchema: onSave → set advanced_custom field
  channelFormSchema->>channelFormSchema: superRefine: parseAdvancedCustomConfig + validateAdvancedCustomConfig
  channelFormSchema-->>ChannelMutateDrawer: validation errors / ok
  ChannelMutateDrawer->>ValidateSettings: Submit channel (OtherSettings.AdvancedCustom)
  ValidateSettings->>ValidateSettings: AdvancedCustom.Validate() per-route checks
  ValidateSettings-->>ChannelMutateDrawer: error or nil

  Note over Adaptor: At request time
  Adaptor->>Adaptor: resolve() — match incoming path to routes
  alt route matched
    Adaptor->>Adaptor: routeURL() — build upstream URL + auth
    Adaptor->>UpstreamAPI: HTTP request (converted or native)
    UpstreamAPI-->>Adaptor: response
    Adaptor->>Adaptor: DoResponse — converter-specific handling
  else fallback enabled
    Adaptor->>UpstreamAPI: openaiAdaptor pass-through to base URL
    UpstreamAPI-->>Adaptor: response
  end
  Adaptor-->>User: API response
Loading

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

Possibly related PRs

  • QuantumNous/new-api#2909: Modifies the same streamSupportedChannels map in relay/common/relay_info.go, adding other channel types in the same block that this PR also modifies to include AdvancedCustom.

Suggested reviewers

  • Calcium-Ion

Poem

🐇 A rabbit hops between routes, left and right,
Matching paths with {model} placeholders in flight.
Gemini streams, Claude headers appear,
Fallback base URLs when no route is near.
With 58 channels and converters aligned,
Advanced Custom routing — quite refined! ✨

✨ 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 and usage tips.

@Calcium-Ion
Calcium-Ion merged commit 3f2c0ae into QuantumNous:main Jun 18, 2026
1 check passed
ruanhangjian pushed a commit to ruanhangjian/new-api that referenced this pull request Jul 11, 2026
zhaodechao2008 pushed a commit to zhaodechao2008/new-api that referenced this pull request Jul 27, 2026
330079598 pushed a commit to 330079598/new-api that referenced this pull request Aug 19, 2026
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
junjundesk pushed a commit to junjundesk/new-api that referenced this pull request Oct 3, 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