fix(MAT-13): Add DNS fallback via web search for browse_url
When browse_url fails with DNS resolution error (common with STT-misrecognized domain names like "klicksports" instead of "clicksports"), automatically try a web search to find the correct domain and retry. Applied to both text and voice bot. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
19
bot.py
19
bot.py
@@ -2099,9 +2099,24 @@ class Bot:
|
||||
if tool_name == "web_search":
|
||||
return await self._brave_search(args.get("query", ""), args.get("count", 5))
|
||||
|
||||
# Browse URL — no auth needed
|
||||
# Browse URL — no auth needed, with DNS fallback via web search
|
||||
if tool_name == "browse_url":
|
||||
return await self._fetch_webpage(args.get("url", ""))
|
||||
url = args.get("url", "")
|
||||
result = await self._fetch_webpage(url)
|
||||
if "Name or service not known" in result or "Failed to fetch" in result:
|
||||
from urllib.parse import urlparse
|
||||
domain = urlparse(url).netloc or url
|
||||
logger.info("Browse DNS fail for %s — trying web search", domain)
|
||||
search_result = await self._brave_search(f"{domain} website", count=3)
|
||||
if search_result and "No results" not in search_result:
|
||||
url_match = re.search(r'https?://[^\s\)]+', search_result)
|
||||
if url_match:
|
||||
corrected_url = url_match.group(0).rstrip('.,;')
|
||||
retry = await self._fetch_webpage(corrected_url)
|
||||
if "Failed to fetch" not in retry:
|
||||
return f"[Original URL {url} unreachable. Found correct site at {corrected_url}]\n\n{retry}"
|
||||
return f"Could not reach {url}. The domain may be misspelled — ask the user to clarify."
|
||||
return result
|
||||
|
||||
# Atlassian tools — need per-user token
|
||||
token = await self.atlassian.get_token(sender) if sender else None
|
||||
|
||||
Reference in New Issue
Block a user