refactor(api): namespaced SDK + dedicated transport layer
Testing / remote-protocol-compat (0.9.3) (push) Successful in 42s
Testing / remote-protocol-compat (0.9.5) (push) Successful in 44s
Package Extension / package-extension (push) Successful in 43s
Build & Publish Package / publish (push) Successful in 43s
Testing / test (push) Successful in 45s
Testing / remote-protocol-compat (0.9.3) (push) Successful in 42s
Testing / remote-protocol-compat (0.9.5) (push) Successful in 44s
Package Extension / package-extension (push) Successful in 43s
Build & Publish Package / publish (push) Successful in 43s
Testing / test (push) Successful in 45s
Restructure the Python API and internals around composable namespaces and a standalone transport/endpoint layer. Bump to 0.12.0. Python API: - Replace flat methods (b.tabs_list(), b.group_list()) with namespaces: b.nav, b.tabs, b.groups, b.windows, b.dom, b.extract, b.page, b.storage, b.cookies, b.session, b.perf, b.extension. - Shrink browser_cli/__init__.py to a thin composition root; move all behaviour into browser_cli/sdk/ (one module per namespace + factories, base, routing). Internals: - Add browser_cli/transport.py and remote_transport.py to isolate IPC from command logic; client.py now delegates instead of owning transport. - Add browser_cli/endpoints.py for endpoint resolution and browser_cli/errors.py for shared error types. - Extract markdown rendering into browser_cli/markdown.py (out of extract). - Add USER_AGENT to version_manager. Tooling & tests: - Add justfile with common dev tasks. - Update CLI commands and demo to the namespaced API. - Rework tests for the new layout; add test_transport.py and test_refactor_boundaries.py to lock in module boundaries. BREAKING CHANGE: flat API methods are removed in favour of namespaces (e.g. b.tabs_list() -> b.tabs.list(), b.group_list() -> b.groups.list()).
This commit is contained in:
+17
-9
@@ -4,11 +4,11 @@ Typed dataclasses returned by the BrowserCLI Python API.
|
||||
Each object is bound to a BrowserCLI instance so you can call actions
|
||||
directly on it:
|
||||
|
||||
tabs = b.tabs_list()
|
||||
tabs = b.tabs.list()
|
||||
tabs[0].close()
|
||||
tabs[0].move(forward=True)
|
||||
|
||||
groups = b.group_list()
|
||||
groups = b.groups.list()
|
||||
groups[0].tabs()
|
||||
groups[0].add_tab("https://example.com")
|
||||
"""
|
||||
@@ -21,6 +21,14 @@ if TYPE_CHECKING:
|
||||
from browser_cli import BrowserCLI
|
||||
|
||||
|
||||
# ── BrowserCounts ───────────────────────────────────────────────────────────
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class BrowserCounts:
|
||||
"""Aggregated per-browser counts returned in implicit multi-browser mode."""
|
||||
total: int
|
||||
by_browser: dict[str, int]
|
||||
|
||||
# ── Tab ───────────────────────────────────────────────────────────────────────
|
||||
|
||||
@dataclass
|
||||
@@ -97,7 +105,7 @@ class Tab:
|
||||
|
||||
def screenshot(self, *, format: str = "png", quality: int | None = None) -> str:
|
||||
"""Capture this tab's visible area. Returns a base64 data URL."""
|
||||
return self._b().tabs_screenshot(self.id, format=format, quality=quality)
|
||||
return self._b().tabs.screenshot(self.id, format=format, quality=quality)
|
||||
|
||||
def pin(self) -> None:
|
||||
"""Pin this tab."""
|
||||
@@ -109,19 +117,19 @@ class Tab:
|
||||
|
||||
def refresh(self) -> Tab:
|
||||
"""Return a fresh snapshot of this tab."""
|
||||
return self._b().tabs_status(self.id)
|
||||
return self._b().tabs.status(self.id)
|
||||
|
||||
def wait_for_load(self, *, timeout: float = 30.0, ready_state: str = "complete") -> Tab:
|
||||
"""Wait until this tab reaches the requested readyState."""
|
||||
return self._b().wait_for_load(self.id, timeout=timeout, ready_state=ready_state)
|
||||
return self._b().tabs.wait_for_load(self.id, timeout=timeout, ready_state=ready_state)
|
||||
|
||||
def watch_url(self, pattern: str, *, timeout: float = 30.0) -> Tab:
|
||||
"""Wait until this tab's URL matches regex *pattern*."""
|
||||
return self._b().tabs_watch_url(pattern, tab_id=self.id, timeout=timeout)
|
||||
return self._b().tabs.watch_url(pattern, tab_id=self.id, timeout=timeout)
|
||||
|
||||
def open(self, url: str, *, background: bool = False) -> None:
|
||||
"""Navigate this tab to *url* in place."""
|
||||
self._b().navigate_tab(self.id, url)
|
||||
self._b().nav.to(self.id, url)
|
||||
|
||||
|
||||
# ── Group ─────────────────────────────────────────────────────────────────────
|
||||
@@ -148,7 +156,7 @@ class Group:
|
||||
|
||||
def tabs(self) -> list[Tab]:
|
||||
"""Return all tabs inside this group."""
|
||||
return self._b().group_tabs(self.id)
|
||||
return self._b().groups.tabs(self.id)
|
||||
|
||||
def move(self, *, forward: bool = False, backward: bool = False) -> None:
|
||||
"""Move this group forward or backward among groups."""
|
||||
@@ -160,4 +168,4 @@ class Group:
|
||||
|
||||
def add_tab(self, url: str | None = None) -> int | None:
|
||||
"""Open a new tab inside this group. Returns the new tab ID."""
|
||||
return self._b().group_add_tab(self.id, url)
|
||||
return self._b().groups.add_tab(self.id, url)
|
||||
|
||||
Reference in New Issue
Block a user