Add fail-closed AI web research discovery provider
CI / compose (push) Successful in 10m53s

This commit is contained in:
Marco0300
2026-09-03 20:32:33 +02:00
parent bf5b54679a
commit da91c188f3
7 changed files with 235 additions and 10 deletions
+14 -3
View File
@@ -13,7 +13,9 @@ from urllib.parse import urljoin, urldefrag, urlparse
from .contact_extractor import extract_contacts
from .website_scanner import MAX_BYTES, MAX_REDIRECTS, _fetch, validate_url
from .search_provider import search as search_provider
import os
from .ai_research import research as ai_research
from .search_provider import search as search_provider # deprecated compatibility adapter
MAX_SEEDS = 5
MAX_PAGES = 20
@@ -69,8 +71,17 @@ def discover(criteria, seed_urls=None, *, max_pages=MAX_PAGES, max_candidates=MA
except (TypeError, ValueError): raise ValueError("invalid_limits")
if not 1 <= max_pages <= MAX_PAGES or not 1 <= max_candidates <= MAX_CANDIDATES: raise ValueError("invalid_limits")
if seed_urls is None:
seeds = search_provider(criteria, max_candidates)
mechanism = "criteria_search_provider"
try:
seeds = ai_research(criteria, max_candidates)
mechanism = "ai_web_research_provider"
except Exception as exc:
# SEARCH_PROVIDER_* is retained only as a migration adapter. It is
# never reported as the primary provider and can be removed later.
if os.environ.get("SEARCH_PROVIDER_URL", "").strip() and getattr(exc, "args", (None,))[0] == "not_configured":
seeds = search_provider(criteria, max_candidates)
mechanism = "criteria_search_provider" # legacy provenance label
else:
raise
else:
if not isinstance(seed_urls, list) or not 0 < len(seed_urls) <= MAX_SEEDS: raise ValueError("seed_urls_required")
seeds = list(seed_urls)