browser_page_backend.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. """Browser page backend ABC: a browser that owns its pages outside Hermes's CDP session.
  2. ``browser_vault`` inspects and fills the page the agent is driving. For ``browser_exec`` that page sits
  3. behind the task's CDP supervisor. A plugin browser with its own transport (Camofox's REST server) has
  4. no CDP endpoint, so it registers one of these via :meth:`PluginContext.register_browser_page_backend`
  5. and the vault evaluates its inspection, origin-check and fill scripts through it instead.
  6. Core keeps the secret contract: it wraps every secret-bearing script so a page exception never reaches
  7. the backend's error text, replaces any failure on that path with fixed text, and registers the filled
  8. value with the browser-result redaction boundary. The backend only carries the script to its page.
  9. """
  10. from __future__ import annotations
  11. import abc
  12. from typing import Any
  13. from agent.provider_base import ProviderBase
  14. class BrowserPageBackend(ProviderBase):
  15. """A plugin browser whose live page ``browser_vault`` can evaluate JavaScript on."""
  16. @abc.abstractmethod
  17. def has_page(self, task_id: str) -> bool:
  18. """True when this backend already holds a live page for ``task_id`` (the agent navigated it).
  19. Cheap and side-effect free: never open a tab or a session to answer. ``False`` lets the vault
  20. fall back to the CDP session."""
  21. @abc.abstractmethod
  22. def evaluate(self, task_id: str, expression: str, *, secret: bool) -> Any:
  23. """Evaluate ``expression`` on the task's current page and return its value; raise on failure.
  24. Never open a tab. With ``secret=True`` the expression embeds a credential: send it only over a
  25. transport that keeps it out of argv and off the network in clear text (loopback or HTTPS), never
  26. follow a redirect with it, and never log it. Exception text on that path is discarded by core."""