From 72779646c1932d9eb00ce041294c4565a78f9d5c Mon Sep 17 00:00:00 2001 From: viettranx Date: Wed, 11 Mar 2026 18:34:38 +0700 Subject: [PATCH] fix: complete media provider type routing for Suno and fix dbTypeToMediaType map MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Set providerType on Suno case in registerProvidersFromDB (was missing, causing misrouting for custom-named Suno providers) - Fix dbTypeToMediaType: replace dead "openai" key with "openai_compat" to match actual store constant, add "bailian" → "dashscope" mapping - Clone entry.Params before injecting _provider_type to avoid mutating the original chain config --- cmd/gateway_providers.go | 4 +++- internal/tools/media_provider_chain.go | 14 ++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cmd/gateway_providers.go b/cmd/gateway_providers.go index 4507fad0..395b4259 100644 --- a/cmd/gateway_providers.go +++ b/cmd/gateway_providers.go @@ -315,7 +315,9 @@ func registerProvidersFromDB(registry *providers.Registry, provStore store.Provi if base == "" { base = "https://api.sunoapi.org" } - registry.Register(providers.NewOpenAIProvider(p.Name, p.APIKey, base, "")) + prov := providers.NewOpenAIProvider(p.Name, p.APIKey, base, "") + prov.WithProviderType(p.ProviderType) + registry.Register(prov) default: prov := providers.NewOpenAIProvider(p.Name, p.APIKey, p.APIBase, "") prov.WithProviderType(p.ProviderType) diff --git a/internal/tools/media_provider_chain.go b/internal/tools/media_provider_chain.go index dfeda71c..5a6676d3 100644 --- a/internal/tools/media_provider_chain.go +++ b/internal/tools/media_provider_chain.go @@ -175,18 +175,19 @@ func ExecuteWithChain( cp, _ := p.(credentialProvider) // Inject resolved provider type into params so callProvider can route correctly. - // This uses the actual DB provider_type instead of guessing from the name. + // Clone params to avoid mutating the original entry config. resolvedType := ResolveProviderType(p) - if entry.Params == nil { - entry.Params = make(map[string]any) + callParams := make(map[string]any, len(entry.Params)+1) + for k, v := range entry.Params { + callParams[k] = v } - entry.Params["_provider_type"] = resolvedType + callParams["_provider_type"] = resolvedType // Retry loop for this provider for attempt := 1; attempt <= entry.MaxRetries; attempt++ { timeoutCtx, cancel := context.WithTimeout(ctx, time.Duration(entry.Timeout)*time.Second) - data, usage, callErr := fn(timeoutCtx, cp, entry.Provider, entry.Model, entry.Params) + data, usage, callErr := fn(timeoutCtx, cp, entry.Provider, entry.Model, callParams) cancel() if callErr == nil { @@ -298,10 +299,11 @@ type typedProvider interface { // used by callProvider switch statements. var dbTypeToMediaType = map[string]string{ "gemini_native": "gemini", - "openai": "openai", + "openai_compat": "openai_compat", "openrouter": "openrouter", "minimax_native": "minimax", "dashscope": "dashscope", + "bailian": "dashscope", "anthropic_native": "anthropic", "suno": "suno", }