Files
Open-AutoGLM/dashboard/models/device.py
let5sne.win10 3552df23d6 Add Web Dashboard with multi-device control and callback hooks
Features:
- Web Dashboard: FastAPI-based dashboard with Vue.js frontend
  - Multi-device support (ADB, HDC, iOS)
  - Real-time WebSocket updates for task progress
  - Device management with status tracking
  - Task queue with execution controls (start/stop/re-execute)
  - Detailed task information display (thinking, actions, completion messages)
  - Screenshot viewing per device
  - LAN deployment support with configurable CORS

- Callback Hooks: Interrupt and modify task execution
  - step_callback: Called after each step with StepResult
  - before_action_callback: Called before executing action
  - Support for task interruption and dynamic task switching
  - Example scripts demonstrating callback usage

- Configuration: Environment-based configuration
  - .env file support for all settings
  - .env.example template with documentation
  - Model API configuration (base URL, model name, API key)
  - Dashboard configuration (host, port, CORS, device type)
  - Phone agent configuration (delays, max steps, language)

Technical improvements:
- Fixed forward reference issue with StepResult
- Added package exports for callback types and configs
- Enhanced dependencies with FastAPI, WebSocket support
- Thread-safe task execution with device locking
- Async WebSocket broadcasting from sync thread pool

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-09 02:20:06 +08:00

68 lines
1.9 KiB
Python

"""
Device data models for the dashboard.
"""
from datetime import datetime
from enum import Enum
from typing import Optional
from pydantic import BaseModel, Field
class DeviceType(str, Enum):
"""Device connection type."""
ADB = "adb"
HDC = "hdc"
IOS = "ios"
class DeviceStatus(str, Enum):
"""Device status."""
ONLINE = "online"
OFFLINE = "offline"
BUSY = "busy"
ERROR = "error"
class DeviceSchema(BaseModel):
"""Device schema for API responses."""
device_id: str = Field(..., description="Unique device identifier")
status: DeviceStatus = Field(default=DeviceStatus.OFFLINE, description="Device status")
device_type: DeviceType = Field(..., description="Device connection type")
model: Optional[str] = Field(None, description="Device model name")
android_version: Optional[str] = Field(None, description="Android/iOS version")
current_app: Optional[str] = Field(None, description="Currently active app")
last_seen: datetime = Field(default_factory=datetime.now, description="Last connection time")
is_connected: bool = Field(True, description="Whether device is connected")
screenshot: Optional[str] = Field(None, description="Base64 encoded screenshot")
class Config:
json_schema_extra = {
"example": {
"device_id": "emulator-5554",
"status": "online",
"device_type": "adb",
"model": "sdk_gphone64_x86_64",
"android_version": "14",
"current_app": "com.android.launcher3",
"is_connected": True,
}
}
class DeviceInfo(BaseModel):
"""Extended device information."""
device_id: str
status: DeviceStatus
device_type: DeviceType
model: Optional[str] = None
android_version: Optional[str] = None
current_app: Optional[str] = None
last_seen: datetime
screenshot: Optional[str] = None
is_connected: bool = True