21 lines
802 B
Python
21 lines
802 B
Python
import asyncio
|
|
from typing import Any, Dict
|
|
from tools.utils import ToolError
|
|
|
|
async def handle(args: Dict[str, Any], bridge: Any) -> list:
|
|
"""
|
|
Switches focus to the specified Tab ID. Gets the tab by its internal ID
|
|
(works across all windows), focuses that tab's window, and highlights it.
|
|
"""
|
|
tab_id = args.get("tab_id")
|
|
if tab_id is None:
|
|
raise ToolError("Missing required argument: 'tab_id'")
|
|
|
|
request_id = f"req_{asyncio.get_event_loop().time()}_{id(args)}"
|
|
result = await bridge.send_to_extension(request_id, "switch_tab", {"tab_id": int(tab_id)})
|
|
|
|
if result and result.get("url"):
|
|
return [{"type": "text", "text": f"Switched to tab {tab_id} ({result['url']})."}]
|
|
|
|
return [{"type": "text", "text": f"Switched to tab {tab_id}."}]
|