Class Screens

All Implemented Interfaces:
ContextProvider, PropertyChangeSource, Rebindable

public class Screens extends AnahataToolkit
A hardware-aware toolkit for capturing high-fidelity screenshots of the host system's displays and individual application windows.

This toolkit leverages the UICapture utility to perform native screen scraping. It is primarily used by the ASI to "see" the user's current workspace or specific application states.

Author:
anahata
  • Field Details

    • sharedDeviceIndexes

      private final List<Integer> sharedDeviceIndexes
      The list of physical device indexes currently being shared in multimodal turns.
    • sharedRegions

      private final List<Screens.SharedRegion> sharedRegions
      The list of rectangular regions currently being shared in multimodal turns.
  • Constructor Details

    • Screens

      public Screens()
  • Method Details

    • getSharedCount

      public int getSharedCount()
      Gets the total number of items currently being shared (displays plus custom regions).
      Returns:
      The total count of shared displays and regions.
    • getSystemInstructions

      public List<String> getSystemInstructions()
      Gets a list of system instruction strings provided by this context provider. These are typically prepended to the conversation as high-level guidance.
      Returns:
      A list of system instruction strings.
    • populateMessage

      public void populateMessage(RagMessage ragMessage)
      Populates the given RagMessage with dynamic, just-in-time context parts. These parts are appended to the end of the user's prompt (RAG).
      Parameters:
      ragMessage - The message to be augmented with context.
    • toggleDeviceSharing

      public String toggleDeviceSharing(int deviceIdx)
      Toggles sharing for a specific screen device.
      Parameters:
      deviceIdx - The index of the device.
      Returns:
      A status message.
    • startSharingRegion

      public String startSharingRegion(int x, int y, int w, int h, String name)
      Adds a specific rectangular region to the live share.
      Parameters:
      x - X coordinate.
      y - Y coordinate.
      w - Width.
      h - Height.
      name - Optional name for the region.
      Returns:
      A status message with the ID.
    • stopSharingRegion

      public String stopSharingRegion(String regionId)
      Stops sharing a specific region by its ID.
      Parameters:
      regionId - The UUID of the shared region.
      Returns:
      A status message.
    • takeScreenshot

      public String takeScreenshot(int deviceIdx) throws Exception
      Captures a screenshot of a specific physical display device identified by its index.

      The resulting image is automatically added as an attachment to the current tool response, making it immediately available to the model's vision system.

      Parameters:
      deviceIdx - The 0-based index of the graphics device (0 is usually the primary display).
      Returns:
      A descriptive status message confirming the capture and attachment.
      Throws:
      IOException - if the native capture operation fails.
      Exception
    • screenshotAllWindows

      public List<String> screenshotAllWindows() throws Exception
      Orchestrates a bulk capture of all visible application windows currently managed by the host's window manager.

      Each window is captured as a separate image and attached to the tool response. This is particularly useful for multi-window discovery tasks.

      Returns:
      A status message indicating the total number of windows captured.
      Throws:
      Exception - if the window enumeration or capture fails.
    • captureRegion

      public String captureRegion(int x, int y, int width, int height) throws Exception
      Captures a specific region of the primary screen.
      Parameters:
      x - X coordinate of the top-left corner.
      y - Y coordinate of the top-left corner.
      width - Width of the region.
      height - Height of the region.
      Returns:
      A status message with the file path.
      Throws:
      Exception - if the native capture operation fails.