Metadata-Version: 2.4
Name: beeos-device-agent
Version: 0.2.1
Summary: BeeOS DeviceAgent — AI-powered device control agent with ACP, MQTT, and WebRTC
Author-email: BeeOS <dev@beeos.ai>
License-Expression: MIT
Keywords: agent,ai,automation,beeos,device,mobile,webrtc
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.11
Requires-Dist: adbutils>=2.0
Requires-Dist: aiohttp>=3.9
Requires-Dist: aiomqtt>=2.0
Requires-Dist: aiortc>=1.9
Requires-Dist: av>=12.0
Requires-Dist: beeos-bridge-client>=0.1.0
Requires-Dist: httpx>=0.27
Requires-Dist: numpy>=1.24
Requires-Dist: pillow>=10.0
Provides-Extra: desktop
Requires-Dist: pyautogui>=0.9; extra == 'desktop'
Provides-Extra: dev
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Provides-Extra: gpu
Requires-Dist: easyocr>=1.7; extra == 'gpu'
Requires-Dist: torch>=2.0; extra == 'gpu'
Provides-Extra: ocr
Requires-Dist: easyocr>=1.7; extra == 'ocr'
Description-Content-Type: text/markdown

# BeeOS DeviceAgent

AI-powered device control agent supporting ACP, MQTT, and WebRTC channels.

## Installation

```bash
pip install beeos-device-agent
```

For AI automation (MobileAgent v3.5):

```bash
pip install beeos-device-agent[ai]
```

## Local Development Setup

```bash
# Install bridge-client first (local dependency)
cd sdks/bridge-client-python && python3 -m venv .venv && .venv/bin/pip install -e ".[dev]"

# Install device-agent
cd sdks/device-agent && python3 -m venv .venv
.venv/bin/pip install -e ../bridge-client-python
.venv/bin/pip install -e ".[dev]"

# Run tests
.venv/bin/pytest tests/ -v
```

## Usage

### CLI (Android via ADB)

```bash
python -m device_agent \
    --bridge ws://localhost:18443 \
    --key ~/.beeos/test-device.key \
    --adb <serial> \
    --mqtt-host localhost --mqtt-port 1883 --no-mqtt-tls \
    --http --http-port 9090
```

### CLI (Desktop mode, no ADB needed)

```bash
python -m device_agent \
    --bridge ws://localhost:18443 \
    --key ~/.beeos/test-device.key \
    --mode desktop \
    --mqtt-host localhost --mqtt-port 1883 --no-mqtt-tls \
    --http --http-port 9090
```

### CLI Options

| Flag | Default | Description |
|------|---------|-------------|
| `--bridge` | (required) | Bridge WebSocket URL |
| `--key` | auto-generated | Ed25519 key file path |
| `--mode` | `android` | Runtime mode: `android` or `desktop` |
| `--adb` | auto-detect | ADB device serial (android mode) |
| `--mqtt-host` | (empty) | MQTT broker host (enables MQTT channel) |
| `--mqtt-port` | `8883` | MQTT broker port |
| `--no-mqtt-tls` | false | Disable MQTT TLS (for local dev) |
| `--http` | false | Enable REST API |
| `--http-port` | `8080` | REST API port |
| `--vlm-model` | `gpt-4o` | VLM model for AI automation |

### Python API

```python
from device_agent import DeviceAgent, DeviceAgentConfig
from device_agent.runtime.android_adb import AndroidADBRuntime

runtime = AndroidADBRuntime(serial="R5CT1234")
config = DeviceAgentConfig(
    bridge_url="ws://localhost:18443",
    key_file="~/.beeos/test-device.key",
    mqtt_host="localhost",
    mqtt_port=1883,
    mqtt_use_tls=False,
)
agent = DeviceAgent(config, runtime)
await agent.start()
```

### REST API (when `--http` is enabled)

| Endpoint | Method | Description |
|----------|--------|-------------|
| `/device/info` | GET | Device metadata |
| `/device/screenshot` | GET | PNG screenshot |
| `/device/action` | POST | Touch/key/shell actions |
| `/tasks` | POST | Submit AI task |
| `/tasks/{id}` | GET | Get task status |

## Docker

The Dockerfile uses the **repository root** as the build context (because it
needs `sdks/bridge-client-python` at build time).

```bash
docker build -f sdks/device-agent/Dockerfile -t beeos-device-agent .

docker run --rm \
  -e BRIDGE_URL=wss://bridge.beeos.ai \
  beeos-device-agent \
  python -m device_agent \
    --bridge wss://bridge.beeos.ai \
    --adb <device-serial> \
    --mqtt-host mqtt.beeos.ai
```

## Architecture

Three independent channels:
- **ACP** (via Bridge) — AI chat + device management (JSON-RPC 2.0 over WebSocket)
- **MQTT** (via EMQX) — WebRTC signaling + device telemetry
- **WebRTC** (P2P/TURN) — on-demand video streaming + DataChannel control

Each DeviceAgent instance represents one device (1 device = 1 process = 1 BeeOS Instance).
The agent manages all three channels independently and coordinates them for features
like on-demand streaming (auto-start when viewed, auto-cooldown when idle).
