27 lines
1007 B
Python
27 lines
1007 B
Python
import asyncio
|
|
from typing import Any, Dict
|
|
from tools.utils import ToolError
|
|
|
|
async def handle(args: Dict[str, Any], bridge: Any) -> list:
|
|
"""
|
|
Scrolls the page by direction and amount.
|
|
"""
|
|
direction = args.get("direction")
|
|
amount = args.get("amount", 500)
|
|
|
|
if not direction:
|
|
raise ToolError("Missing required argument: 'direction'")
|
|
if direction not in ("up", "down", "left", "right"):
|
|
raise ToolError(f"Invalid direction '{direction}'. Must be: up, down, left, right")
|
|
|
|
request_id = f"req_{asyncio.get_event_loop().time()}_{id(args)}"
|
|
params: Dict[str, Any] = {"direction": direction, "amount": int(amount)}
|
|
if args.get("window_id") is not None:
|
|
params["window_id"] = int(args["window_id"])
|
|
if args.get("tab_id") is not None:
|
|
params["tab_id"] = int(args["tab_id"])
|
|
|
|
await bridge.send_to_extension(request_id, "scroll_page", params)
|
|
|
|
return [{"type": "text", "text": f"Scrolled {direction} by {amount}."}]
|