(name: string | undefined)
| 14 | |
| 15 | /** Build a backend instance from a string id. Defaults to duckduckgo on unknown values. */ |
| 16 | export function selectBackend(name: string | undefined): WebSearchBackend { |
| 17 | switch ((name ?? 'duckduckgo').toLowerCase()) { |
| 18 | case 'tavily': |
| 19 | return new TavilyBackend(); |
| 20 | case 'brave': |
| 21 | return new BraveBackend(); |
| 22 | case 'firecrawl': |
| 23 | case 'fc': |
| 24 | return new FirecrawlBackend(); |
| 25 | case 'duckduckgo': |
| 26 | case 'ddg': |
| 27 | case undefined: |
| 28 | return new DuckDuckGoBackend(); |
| 29 | default: |
| 30 | logger.warn(`Unknown web_search backend '${name}', falling back to duckduckgo`); |
| 31 | return new DuckDuckGoBackend(); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Build the fallback chain. If the primary backend fails or returns nothing, |
no test coverage detected