refactor: reorganize client transport and extension internals
- Split client, native, remote, serve, markdown, and SDK internals into focused packages with direct imports. - Move local and remote transport framing/protocol helpers behind clearer module boundaries. - Break up the extension injected DOM logic into a separate content dispatch bundle and dedicated content modules. - Add explicit client handling for passive remote discovery without noisy PQ warnings. - Keep behavior covered with updated unit, integration, and extension tests.
This commit is contained in:
+35
-40
@@ -1,56 +1,51 @@
|
||||
"""Tab groups namespace: ``b.groups.*``."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from browser_cli.models import Group, Tab
|
||||
from browser_cli.models import BrowserCounts, Group, Tab
|
||||
from browser_cli.sdk.base import Namespace
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from browser_cli import BrowserCounts
|
||||
|
||||
class GroupsNS(Namespace):
|
||||
"""List, create, query, and modify tab groups."""
|
||||
"""List, create, query, and modify tab groups."""
|
||||
|
||||
def list(self) -> list[Group]:
|
||||
"""Return all tab groups.
|
||||
def list(self) -> list[Group]:
|
||||
"""Return all tab groups.
|
||||
|
||||
When multiple browsers are active and no browser was specified, each Group
|
||||
includes ``group.browser`` naming its source browser.
|
||||
"""
|
||||
return self._c._multi_list("group.list", {}, self._c._make_group_for)
|
||||
When multiple browsers are active and no browser was specified, each Group
|
||||
includes ``group.browser`` naming its source browser.
|
||||
"""
|
||||
return self.multi_list("group.list", {}, self.group_from_target)
|
||||
|
||||
def count(self) -> "int | BrowserCounts":
|
||||
"""Return the number of tab groups.
|
||||
def count(self) -> "int | BrowserCounts":
|
||||
"""Return the number of tab groups.
|
||||
|
||||
Returns ``BrowserCounts`` in implicit multi-browser mode.
|
||||
"""
|
||||
return self._c._multi_count("group.count", {})
|
||||
Returns ``BrowserCounts`` in implicit multi-browser mode.
|
||||
"""
|
||||
return self.multi_count("group.count", {})
|
||||
|
||||
def query(self, search: str) -> list[Group]:
|
||||
"""Search groups by name."""
|
||||
return [self._c._make_group(g) for g in (self._c._cmd("group.query", {"search": search}) or [])]
|
||||
def query(self, search: str) -> list[Group]:
|
||||
"""Search groups by name."""
|
||||
return [self.group_from(g) for g in (self.command("group.query", {"search": search}) or [])]
|
||||
|
||||
def create(self, name: str) -> Group:
|
||||
"""Create a new tab group with *name*. Returns the created Group."""
|
||||
data = self._c._cmd("group.open", {"name": name})
|
||||
if isinstance(data, dict):
|
||||
return self._c._make_group(data)
|
||||
return Group(id=data, title=name, color="", collapsed=False, tab_count=0)
|
||||
def create(self, name: str) -> Group:
|
||||
"""Create a new tab group with *name*. Returns the created Group."""
|
||||
data = self.command("group.open", {"name": name})
|
||||
if isinstance(data, dict):
|
||||
return self.group_from(data)
|
||||
return Group(id=data, title=name, color="", collapsed=False, tab_count=0)
|
||||
|
||||
def tabs(self, group_id: int) -> list[Tab]:
|
||||
"""Return all tabs inside a group."""
|
||||
return [self._c._make_tab(t) for t in (self._c._cmd("group.tabs", {"groupId": group_id}) or [])]
|
||||
def tabs(self, group_id: int) -> list[Tab]:
|
||||
"""Return all tabs inside a group."""
|
||||
return [self.tab_from(t) for t in (self.command("group.tabs", {"groupId": group_id}) or [])]
|
||||
|
||||
def add_tab(self, group: str | int, url: str | None = None) -> int | None:
|
||||
"""Open a new tab (optionally at URL) inside a group. Returns the new tab ID."""
|
||||
result = self._c._cmd("group.add_tab", {"group": str(group), "url": url})
|
||||
return self._c._field(result, "tabId", fallback=result)
|
||||
def add_tab(self, group: str | int, url: str | None = None) -> int | None:
|
||||
"""Open a new tab (optionally at URL) inside a group. Returns the new tab ID."""
|
||||
result = self.command("group.add_tab", {"group": str(group), "url": url})
|
||||
return self.field(result, "tabId", fallback=result)
|
||||
|
||||
def move(self, group: str | int, *, forward: bool = False, backward: bool = False) -> dict | None:
|
||||
"""Move a tab group forward or backward. Returns the raw move result."""
|
||||
return self._c._cmd("group.move", {"group": str(group), "forward": forward, "backward": backward})
|
||||
def move(self, group: str | int, *, forward: bool = False, backward: bool = False) -> dict | None:
|
||||
"""Move a tab group forward or backward. Returns the raw move result."""
|
||||
return self.command("group.move", {"group": str(group), "forward": forward, "backward": backward})
|
||||
|
||||
def close(self, group_id: int, *, gentle_mode: str = "auto") -> None:
|
||||
"""Ungroup (and close) a tab group by ID."""
|
||||
self._c._cmd("group.close", {"groupId": group_id, "gentleMode": gentle_mode})
|
||||
def close(self, group_id: int, *, gentle_mode: str = "auto") -> None:
|
||||
"""Ungroup (and close) a tab group by ID."""
|
||||
self.command("group.close", {"groupId": group_id, "gentleMode": gentle_mode})
|
||||
|
||||
Reference in New Issue
Block a user