"""Search services shared by REST routes and the AI tool layer.""" from __future__ import annotations from typing import Any def search_vaults( q: str, vault: str = "all", tag: str | None = None, limit: int = 50, offset: int = 0, ) -> dict[str, Any]: """Full-text search with pagination, returned as the API response payload. No permission filtering is applied here: callers that need it (the tool layer) filter the ``results`` list themselves. """ from backend.search import search all_results = search(q, vault_filter=vault, tag_filter=tag) total = len(all_results) page = all_results[offset: offset + limit] return { "query": q, "vault_filter": vault, "tag_filter": tag, "count": len(page), "total": total, "offset": offset, "limit": limit, "results": page, } def list_tags(vault: str | None = None) -> dict[str, int]: """Return tag → count, optionally restricted to a single vault.""" from backend.search import get_all_tags return get_all_tags(vault_filter=vault)