refactor: simplify web backend priority detection (#4036)

* fix(gateway): honor default for invalid bool-like config values

* refactor: simplify web backend priority detection

Replace cascading boolean conditions with a priority-ordered loop.
Same behavior (verified against all 16 env var combinations),
half the lines, trivially extensible for new backends.

---------

Co-authored-by: aydnOktay <xaydinoktay@gmail.com>
This commit is contained in:
Teknium
2026-03-30 13:37:25 -07:00
committed by GitHub
parent eba8d52d54
commit 0d1003559d

View File

@@ -77,20 +77,18 @@ def _get_backend() -> str:
if configured in ("parallel", "firecrawl", "tavily", "exa"): if configured in ("parallel", "firecrawl", "tavily", "exa"):
return configured return configured
# Fallback for manual / legacy config — use whichever key is present. # Fallback for manual / legacy config — pick highest-priority backend
has_firecrawl = _has_env("FIRECRAWL_API_KEY") or _has_env("FIRECRAWL_API_URL") # that has a key configured. Order: firecrawl > parallel > tavily > exa.
has_parallel = _has_env("PARALLEL_API_KEY") for backend, keys in [
has_tavily = _has_env("TAVILY_API_KEY") ("firecrawl", ("FIRECRAWL_API_KEY", "FIRECRAWL_API_URL")),
has_exa = _has_env("EXA_API_KEY") ("parallel", ("PARALLEL_API_KEY",)),
if has_exa and not has_firecrawl and not has_parallel and not has_tavily: ("tavily", ("TAVILY_API_KEY",)),
return "exa" ("exa", ("EXA_API_KEY",)),
if has_tavily and not has_firecrawl and not has_parallel: ]:
return "tavily" if any(_has_env(k) for k in keys):
if has_parallel and not has_firecrawl: return backend
return "parallel"
# Default to firecrawl (backward compat, or when both are set) return "firecrawl" # default (backward compat)
return "firecrawl"
# ─── Firecrawl Client ──────────────────────────────────────────────────────── # ─── Firecrawl Client ────────────────────────────────────────────────────────