Spaces:
Sleeping
Sleeping
File size: 3,605 Bytes
399b80c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | # OpenSpace Local Server
The local server is a **lightweight Flask service** that runs on the host machine and exposes HTTP endpoints for shell execution and GUI automation. It is only needed in **server mode** β most users should use the default **local mode** instead.
## When to Use Server Mode
| | Local Mode (default) | Server Mode |
|---|---|---|
| **Setup** | Zero β just run OpenSpace | Start `local_server` first |
| **Use case** | Same-machine development | Remote VMs, sandboxing, multi-machine |
| **Shell** | `asyncio.subprocess` in-process | HTTP β Flask β `subprocess` |
| **GUI** | Direct pyautogui | HTTP β Flask β pyautogui |
| **Network** | None required | HTTP between agent β server |
Use server mode when:
- **Controlling a remote VM** β the agent runs on your host, the server runs inside the VM
- **Process isolation / sandboxing** β script execution in a separate process
- **Multi-machine deployments** β agent and execution environment on different machines
## Enable Server Mode
Set `"mode": "server"` in `openspace/config/config_grounding.json`:
```jsonc
{
"shell": { "mode": "server", ... }, // default: "local"
"gui": { "mode": "server", ... } // default: "local"
}
```
## Platform-Specific Dependencies
> [!IMPORTANT]
> Install platform-specific dependencies **on the machine running the server** (not the agent).
<details>
<summary><b>macOS</b></summary>
```bash
pip install pyobjc-core pyobjc-framework-cocoa pyobjc-framework-quartz atomacos
```
**Permissions required** (macOS will prompt automatically on first run):
- **Accessibility** (for GUI control)
- **Screen Recording** (for screenshots and video capture)
> If prompts don't appear, grant manually in System Settings β Privacy & Security.
</details>
<details>
<summary><b>Linux</b></summary>
```bash
pip install python-xlib pyatspi numpy
sudo apt install at-spi2-core python3-tk scrot
```
> **Optional:** `wmctrl` (window management), `libx11-dev` + `libxfixes-dev` (cursor in screenshots)
</details>
<details>
<summary><b>Windows</b></summary>
```bash
pip install pywinauto pywin32 PyGetWindow
```
</details>
## Launch
```bash
# Python entry point
python -m openspace.local_server.main --host 127.0.0.1 --port 5000
# Or via helper script
./openspace/local_server/run.sh
```
Press `Ctrl+C` to stop.
## Configuration
Runtime options in `openspace/local_server/config.json`:
```json
{
"server": {
"host": "127.0.0.1",
"port": 5000,
"debug": false
}
}
```
## Architecture
- **PlatformAdapter** β abstracts OS-specific primitives (Windows, macOS, Linux)
- **Accessibility Helper** β queries the UI accessibility tree
- **Screenshot Helper** β captures full or partial screenshots (PNG)
- **Recorder** β streams screen recordings for analysis
- **Health / Feature Checker** β validates runtime capabilities and permissions
## REST Endpoints
| Path | Method | Description |
|------|--------|-------------|
| `/` | GET | Liveness probe |
| `/platform` | GET | Host OS metadata |
| `/execute` | POST | Execute a PyAutoGUI script fragment |
| `/execute_with_verification` | POST | Execute + verify via template matching |
| `/run_python` | POST | Run Python in sandbox |
| `/run_bash_script` | POST | Run shell script (optional conda activation) |
| `/screenshot` | GET | PNG screenshot (full or ROI) |
| `/cursor_position` | GET | Current mouse coordinates |
| `/screen_size` | GET/POST | Query or set virtual screen resolution |
| `/list_directory` | POST | List directory contents |
See `main.py` for ~20 additional endpoints.
|