read_preview_tool.py 1.1 KB

12345678910111213141516171819202122232425
  1. #!/usr/bin/env python3
  2. """Read the in-app browser / preview pane in the Hermes desktop GUI.
  3. The preview's content lives in the renderer (a sandboxed ``<webview>``), so this
  4. round-trips through the gateway's blocking-prompt bridge like ``read_terminal``
  5. (``preview.read.request`` -> ``preview.read.respond``). Registered as action=read of
  6. `desktop_preview`; the agent dispatches here with the injected callback.
  7. """
  8. from typing import Callable, Optional
  9. from tools.read_terminal_tool import read_pane
  10. def read_preview_tool(
  11. start: Optional[int] = None, count: Optional[int] = None, callback: Optional[Callable] = None
  12. ) -> str:
  13. """Return the active preview tab's contents (+ metadata) as a JSON string."""
  14. return read_pane(callback, (("start", start, 0), ("count", count, 1)), (
  15. "read_preview is only available in the Hermes desktop app.",
  16. "start and count must be integers.",
  17. "Failed to read the preview pane: ",
  18. "No preview tab answered: no page is loaded (call open_preview first), "
  19. "or the bridge timed out. If the pane IS open, the desktop app may be older "
  20. "than this backend — update it and retry."))