fix(tools): add debug logging for token refresh and tighten domain check
- Add logger + debug log to read_nous_access_token() catch-all so token refresh failures are observable instead of silently swallowed - Tighten _is_nous_auxiliary_client() domain check to use proper URL hostname parsing instead of substring match, preventing false-positives on domains like not-nousresearch.com or nousresearch.com.evil.com
This commit is contained in:
@@ -3,11 +3,14 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Callable, Optional
|
from typing import Callable, Optional
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
from hermes_constants import get_hermes_home
|
from hermes_constants import get_hermes_home
|
||||||
from tools.tool_backend_helpers import managed_nous_tools_enabled
|
from tools.tool_backend_helpers import managed_nous_tools_enabled
|
||||||
|
|
||||||
@@ -93,8 +96,8 @@ def read_nous_access_token() -> Optional[str]:
|
|||||||
)
|
)
|
||||||
if isinstance(refreshed_token, str) and refreshed_token.strip():
|
if isinstance(refreshed_token, str) and refreshed_token.strip():
|
||||||
return refreshed_token.strip()
|
return refreshed_token.strip()
|
||||||
except Exception:
|
except Exception as exc:
|
||||||
pass
|
logger.debug("Nous access token refresh failed: %s", exc)
|
||||||
|
|
||||||
return cached_token
|
return cached_token
|
||||||
|
|
||||||
|
|||||||
@@ -445,8 +445,11 @@ DEFAULT_MIN_LENGTH_FOR_SUMMARIZATION = 5000
|
|||||||
|
|
||||||
def _is_nous_auxiliary_client(client: Any) -> bool:
|
def _is_nous_auxiliary_client(client: Any) -> bool:
|
||||||
"""Return True when the resolved auxiliary backend is Nous Portal."""
|
"""Return True when the resolved auxiliary backend is Nous Portal."""
|
||||||
base_url = str(getattr(client, "base_url", "") or "").lower()
|
from urllib.parse import urlparse
|
||||||
return "nousresearch.com" in base_url
|
|
||||||
|
base_url = str(getattr(client, "base_url", "") or "")
|
||||||
|
host = (urlparse(base_url).hostname or "").lower()
|
||||||
|
return host == "nousresearch.com" or host.endswith(".nousresearch.com")
|
||||||
|
|
||||||
|
|
||||||
def _resolve_web_extract_auxiliary(model: Optional[str] = None) -> tuple[Optional[Any], Optional[str], Dict[str, Any]]:
|
def _resolve_web_extract_auxiliary(model: Optional[str] = None) -> tuple[Optional[Any], Optional[str], Dict[str, Any]]:
|
||||||
|
|||||||
Reference in New Issue
Block a user