From a0340d4ddeb5831e53910dc7f93c3d3fc95bfb53 Mon Sep 17 00:00:00 2001 From: Anankke Date: Sat, 14 Nov 2026 02:54:32 -0800 Subject: [PATCH] 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. --- backend/internal/service/account.go | 15 ++++++++++++--- .../service/gateway_websearch_emulation_test.go | 5 ++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/backend/internal/service/account.go b/backend/internal/service/account.go index 8899c2d70d..be94a95ed7 100644 --- a/backend/internal/service/account.go +++ b/backend/internal/service/account.go @@ -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(关闭)处理。 diff --git a/backend/internal/service/gateway_websearch_emulation_test.go b/backend/internal/service/gateway_websearch_emulation_test.go index 0c05563f66..2577e38dcc 100644 --- a/backend/internal/service/gateway_websearch_emulation_test.go +++ b/backend/internal/service/gateway_websearch_emulation_test.go @@ -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} {