fix(websearch): honor account mode on every channel-toggle platform

GetWebSearchEmulationMode only read extra.web_search_emulation for anthropic and openai API key accounts and returned "default" for every other platform, although the channel form already lists zhipu, command_code, opencode_go and minimax for the same feature.
Those accounts reach shouldEmulateWebSearchFor through the OpenAI gateway /v1/messages path, so "enabled" was ignored and "disabled" could not override a channel that turns the emulation on.
Let every platform in the channel whitelist through the gate and extend the account and channel matrix test to them.
This commit is contained in:
Anankke committed 2026-11-14 04:10:41 -08:00
1 parent 530c5e3a4f
commit a0340d4dde
2 files changed
+16 -4

No files matched your search

+12 -3
View File
@@ -2410,10 +2410,8 @@ const (
// 三态:default(跟随渠道)/ enabled(强制开启)/ disabled(强制关闭)。
// 兼容旧 bool 值:true→enabled, false→default(并记录 debug 日志)。
func (a *Account) GetWebSearchEmulationMode() string {
// OpenAI API Key accounts reach this via /v1/messages; their upstreams
// (DeepSeek etc. over Chat Completions) have no web_search tool.
if a == nil || a.Type != AccountTypeAPIKey || a.Extra == nil ||
(a.Platform != PlatformAnthropic && a.Platform != PlatformOpenAI) {
!webSearchEmulationPlatformEnabled(a.Platform) {
return WebSearchModeDefault
}
raw := a.Extra[featureKeyWebSearchEmulation]
@@ -2437,6 +2435,17 @@ func (a *Account) GetWebSearchEmulationMode() string {
}
}
// webSearchEmulationPlatformEnabled reports whether API key accounts of the
// platform can set the account-level web search emulation mode. Keep it in sync
// with WEB_SEARCH_EMULATION_PLATFORMS in frontend/src/views/admin/ChannelsView.vue.
func webSearchEmulationPlatformEnabled(platform string) bool {
switch platform {
case PlatformAnthropic, PlatformOpenAI, PlatformZhipu, PlatformCommandCode, PlatformOpenCodeGo, PlatformMiniMax:
return true
}
return false
}
// IsCodexCLIOnlyEnabled 返回 OpenAI OAuth 账号是否启用"仅允许 Codex 官方客户端"。
// 字段:accounts.extra.codex_cli_only。
// 字段缺失或类型不正确时,按 false(关闭)处理。
@@ -418,7 +418,10 @@ func TestShouldEmulateWebSearchFor_AccountChannelModes(t *testing.T) {
settingSvc := newSettingServiceForWebSearchTest(true)
groupID := int64(42)
for _, platform := range []string{PlatformOpenAI, PlatformAnthropic} {
platforms := []string{
PlatformOpenAI, PlatformAnthropic, PlatformZhipu, PlatformCommandCode, PlatformOpenCodeGo, PlatformMiniMax,
}
for _, platform := range platforms {
for _, accountType := range []string{AccountTypeAPIKey, AccountTypeOAuth, AccountTypeSetupToken} {
for _, mode := range []string{WebSearchModeDefault, WebSearchModeEnabled, WebSearchModeDisabled} {
for _, channelEnabled := range []bool{false, true} {