28 lines
926 B
Python
28 lines
926 B
Python
import asyncio
|
|
from typing import Any, Dict
|
|
from tools.utils import ToolError
|
|
|
|
async def handle(args: Dict[str, Any], bridge: Any) -> list:
|
|
"""
|
|
Lists all open Firefox tabs.
|
|
"""
|
|
request_id = f"req_{asyncio.get_event_loop().time()}_{id(args)}"
|
|
result = await bridge.send_to_extension(request_id, "list_tabs", {})
|
|
|
|
tabs = result if isinstance(result, list) else []
|
|
|
|
lines = ["# Open Tabs\n"]
|
|
if not tabs:
|
|
lines.append("No tabs found.")
|
|
else:
|
|
for tab in tabs:
|
|
tid = tab.get("id", "?")
|
|
title = tab.get("title", "(no title)")
|
|
url = tab.get("url", "")
|
|
active = " (ACTIVE)" if tab.get("active") else ""
|
|
wid = tab.get("windowId", "?")
|
|
lines.append(f"- **Tab {tid}** (window {wid}): {title}{active}")
|
|
lines.append(f" URL: {url}")
|
|
|
|
return [{"type": "text", "text": "\n".join(lines)}]
|