from __future__ import annotations from typing import Any from yuxi.channels.adapters.bluebubbles.client import BlueBubblesClient from yuxi.utils.logging_config import logger async def list_chats(client: BlueBubblesClient) -> list[dict[str, Any]]: try: result = await client.get("/api/v1/chat/query") return result.get("data", []) except Exception: logger.warning("[BlueBubbles] Failed to list chats") return [] async def list_contacts(client: BlueBubblesClient) -> list[dict[str, Any]]: try: result = await client.get("/api/v1/contact/query") return result.get("data", []) except Exception: logger.warning("[BlueBubbles] Failed to list contacts") return [] async def search_chats(client: BlueBubblesClient, query: str) -> list[dict[str, Any]]: try: result = await client.get("/api/v1/chat/query", params={"query": query}) return result.get("data", []) except Exception: logger.warning(f"[BlueBubbles] Failed to search chats for '{query}'") return [] async def search_contacts(client: BlueBubblesClient, query: str) -> list[dict[str, Any]]: try: result = await client.post( "/api/v1/contact/query", json={"addresses": [query]}, ) return result.get("data", []) except Exception: logger.warning(f"[BlueBubbles] Failed to search contacts for '{query}'") return []