24 lines
853 B
Python
24 lines
853 B
Python
import asyncio
|
|
from typing import Any, Dict
|
|
from tools.utils import ToolError
|
|
|
|
async def handle(args: Dict[str, Any], bridge: Any) -> list:
|
|
"""
|
|
Returns a reader-mode version of the page text.
|
|
"""
|
|
request_id = f"req_{asyncio.get_event_loop().time()}_{id(args)}"
|
|
params: Dict[str, Any] = {}
|
|
if args.get("tab_id") is not None:
|
|
params["tab_id"] = int(args["tab_id"])
|
|
if args.get("window_id") is not None:
|
|
params["window_id"] = int(args["window_id"])
|
|
|
|
result = await bridge.send_to_extension(request_id, "read_page_text", params)
|
|
|
|
text = result if isinstance(result, str) else str(result)
|
|
|
|
if not text or text.strip() == "":
|
|
return [{"type": "text", "text": "No readable text found on this page."}]
|
|
|
|
return [{"type": "text", "text": f"# Page Text (Reader Mode)\n\n{text}"}]
|