refactor: move search_usage to utils/searchusage, remove brave stub

- Rename agent/tools/search_usage.py → utils/searchusage.py
  (not an LLM tool, matches utils/ naming convention)
- Remove redundant _fetch_brave_usage — handled by else branch
- Move test to tests/utils/test_searchusage.py

Made-with: Cursor
This commit is contained in:
Xubin Ren 2026-04-06 05:34:44 +00:00 committed by Xubin Ren
parent bc0ff7f214
commit 7ffd93f48d
3 changed files with 3 additions and 15 deletions

View File

@ -64,7 +64,7 @@ async def cmd_status(ctx: CommandContext) -> OutboundMessage:
# Fetch web search provider usage (best-effort, never blocks the response)
search_usage_text: str | None = None
try:
from nanobot.agent.tools.search_usage import fetch_search_usage
from nanobot.utils.searchusage import fetch_search_usage
web_cfg = getattr(getattr(loop, "config", None), "tools", None)
web_cfg = getattr(web_cfg, "web", None) if web_cfg else None
search_cfg = getattr(web_cfg, "search", None) if web_cfg else None

View File

@ -81,10 +81,8 @@ async def fetch_search_usage(
if p == "tavily":
return await _fetch_tavily_usage(api_key)
elif p == "brave":
return await _fetch_brave_usage(api_key)
else:
# duckduckgo, searxng, jina, unknown — no usage API
# brave, duckduckgo, searxng, jina, unknown — no usage API
return SearchUsageInfo(provider=p, supported=False)
@ -171,13 +169,3 @@ def _parse_tavily_usage(data: dict[str, Any]) -> SearchUsageInfo:
)
# ---------------------------------------------------------------------------
# Brave
# ---------------------------------------------------------------------------
async def _fetch_brave_usage(api_key: str | None) -> SearchUsageInfo:
"""
Brave Search does not have a public usage/quota endpoint.
Rate-limit headers are returned per-request, not queryable standalone.
"""
return SearchUsageInfo(provider="brave", supported=False)

View File

@ -5,7 +5,7 @@ from __future__ import annotations
import pytest
from unittest.mock import AsyncMock, MagicMock, patch
from nanobot.agent.tools.search_usage import (
from nanobot.utils.searchusage import (
SearchUsageInfo,
_parse_tavily_usage,
fetch_search_usage,