|
1 | 1 | import subprocess
|
2 | 2 | import uuid
|
3 | 3 |
|
| 4 | +from rich.markdown import Markdown |
| 5 | +from rich.panel import Panel |
| 6 | + |
4 | 7 | from goose.toolkit.base import Toolkit, tool
|
5 | 8 |
|
6 | 9 |
|
7 | 10 | class Screen(Toolkit):
|
8 | 11 | """Provides an instructions on when and how to work with screenshots"""
|
9 | 12 |
|
10 | 13 | @tool
|
11 |
| - def take_screenshot(self) -> str: |
| 14 | + def take_screenshot(self, display: int = 1) -> str: |
12 | 15 | """
|
13 |
| - Take a screenshot to assist the user in debugging or designing an app. They may need help with moving a screen element, or interacting in some way where you could do with seeing the screen. |
| 16 | + Take a screenshot to assist the user in debugging or designing an app. They may need |
| 17 | + help with moving a screen element, or interacting in some way where you could do with |
| 18 | + seeing the screen. |
14 | 19 |
|
15 |
| - Return: |
16 |
| - (str) a path to the screenshot file, in the format of image: followed by the path to the file. |
| 20 | + Args: |
| 21 | + display (int): Display to take the screen shot in. Default is the main display (1). Must be a value greater than 1. |
17 | 22 | """ # noqa: E501
|
18 | 23 | # Generate a random tmp filename for screenshot
|
19 |
| - filename = f"/tmp/goose_screenshot_{uuid.uuid4().hex}.png" |
| 24 | + filename = f"/tmp/goose_screenshot_{uuid.uuid4().hex}.jpg" |
| 25 | + screen_capture_command = ["screencapture", "-x", "-D", str(display), filename, "-f", "jpg"] |
| 26 | + |
| 27 | + subprocess.run(screen_capture_command, check=True, capture_output=True) |
| 28 | + |
| 29 | + resize_command = ["sips", "--resampleWidth", "768", filename, "-s", "format", "jpeg"] |
| 30 | + subprocess.run(resize_command, check=True, capture_output=True) |
20 | 31 |
|
21 |
| - subprocess.run(["screencapture", "-x", filename]) |
| 32 | + self.notifier.log( |
| 33 | + Panel.fit( |
| 34 | + Markdown(f"```bash\n{' '.join(screen_capture_command)}"), |
| 35 | + title="screen", |
| 36 | + ) |
| 37 | + ) |
22 | 38 |
|
23 | 39 | return f"image:{filename}"
|
24 | 40 |
|
|
0 commit comments