fix: complete media provider type routing for Suno and fix dbTypeToMediaType map

- 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
This commit is contained in:
viettranx committed 2026-03-11 18:34:38 +07:00
1 parent 405a753239
commit 72779646c1
2 files changed
+11 -7

No files matched your search

+3 -1
View File
@@ -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)
+8 -6
View File
@@ -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",
}