Files
jmj 3889b6d910 feat(repair): add toggle for offscreen sandbox precheck
The offscreen WebView validation runs once per page and is the heaviest
part of the render pipeline on low-end TV boxes: it wakes an invisible
WebView, loads the sandbox page, injects the full DOM and waits ~550ms
before mounting the real page.

Add RepairAiConfig.precheckEnabled (default true) so it can be disabled:

- Android: skip validateInOffscreenSandbox and mount directly, reporting
  status "rendered_precheck_skipped" so the outcome stays distinguishable
  in render results. Exposed in the terminal settings dialog and accepted
  from hub config pushes.
- Hub: add precheck_enabled to RepairAIConfig, the admin form and the
  config payload so the switch can be toggled remotely.

Trade-off: with precheck off, malformed pages surface on screen instead
of being caught and repaired before mounting.
2026-11-30 11:06:17 +08:00

115 lines
4.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from __future__ import annotations
from typing import Any, Literal
from pydantic import BaseModel, Field
class DisplayProfile(BaseModel):
device_type: Literal["phone", "tablet", "tv", "unknown"] = "phone"
orientation: Literal["portrait", "landscape"] = "portrait"
width_px: int = 1080
height_px: int = 2340
viewport_css_w: int = 392
viewport_css_h: int = 850
dpr: float = 2.75
safe_area_top_dp: int = 28
safe_area_bottom_dp: int = 16
font_scale: float = 1.0
webview_version: str = "unknown"
class DeviceTelemetry(BaseModel):
battery_pct: int | None = None
is_charging: bool | None = None
battery_temp_c: float | None = None
battery_current_ma: int | None = None
cpu_usage_pct: float | None = None
gpu_usage_pct: float | None = None
mem_used_mb: int | None = None
mem_total_mb: int | None = None
storage_used_mb: int | None = None
storage_total_mb: int | None = None
thermal_zones: dict[str, float] = Field(default_factory=dict)
wifi_rssi_dbm: int | None = None
screen_on: bool | None = None
extra: dict[str, Any] = Field(default_factory=dict)
class RepairAIConfig(BaseModel):
enabled: bool = False
precheck_enabled: bool = True
base_url: str = "https://api.openai.com/v1"
api_key: str = ""
model: str = "gpt-4o-mini"
timeout_sec: int = 30
max_retries: int = 3
runtime_cooldown_sec: int = 30
class HubChatAIConfig(BaseModel):
base_url: str = "https://api.openai.com/v1"
api_key: str = ""
model: str = "gpt-4o-mini"
timeout_sec: int = 60
max_tool_steps: int = Field(default=30, ge=1, le=100)
system_prompt: str = (
"你是 PulseWall 中心桥控制助手,可以通过工具查询连接的 Android 手机/平板/机顶盒设备状态与屏幕参数,"
"推送动态信息、触发分层告警(含全屏红屏警报与预设交互按钮)、动态生成并渲染适配该设备分辨率与 WebView 版本的 HTML/Vue 页面,"
"以及查询用户的反向操作回复。渲染页面前务必先调用 get_device_status 获取目标设备的 viewport_css_w/h、device_type 和本地内置库清单。"
"App 本地已离线内置 Vue3、tailwind-lite、dayjs、PwIcons,以及可按需 `await window.PulseWall.loadLib([...])` 零延迟加载的 "
"plyr、hls、echarts(裁剪版)、konva、three、rough、lodash、zustand、anime,优先使用本地库避免外网 CDN 依赖,非必要不加载重库(three/echarts);"
"在 Android 机顶盒/平板大屏上尽量减少高频 60fps 全屏 Canvas 重绘与大面积 backdrop-filter 模糊,以保持低 CPU/低发热。"
)
class HubConfig(BaseModel):
repair_ai: RepairAIConfig = Field(default_factory=RepairAIConfig)
hub_chat_ai: HubChatAIConfig = Field(default_factory=HubChatAIConfig)
telemetry_interval_sec: int = Field(default=3, ge=1, le=120)
theme: str = "dark-glass"
lan_debug_enabled: bool = False
auth_token: str = ""
class PresetOption(BaseModel):
id: str
label: str
style: Literal["primary", "secondary", "danger", "success"] = "primary"
class InteractionSpec(BaseModel):
interaction_id: str
mode: Literal["ack_required", "action_required"] = "ack_required"
presets: list[PresetOption] = Field(
default_factory=lambda: [PresetOption(id="ack", label="确认收到", style="primary")]
)
allow_custom_input: bool = True
custom_input_placeholder: str = "其他说明或指令..."
class AlertPayload(BaseModel):
alert_id: str
title: str
message: str
level: Literal["info", "notice", "warning", "error", "critical"] = "warning"
presentation: Literal["toast", "modal", "fullscreen_alarm"] = "modal"
sound: Literal["none", "ding", "warning", "siren", "tts"] = "warning"
vibrate: bool = True
wake_screen: bool = False
tts_text: str | None = None
details_code: str | None = None
custom_html: str | None = None
interaction: InteractionSpec | None = None
class FeedItemPayload(BaseModel):
item_id: str
title: str
body: str
level: Literal["info", "notice", "warning", "error", "critical"] = "info"
source: str = "ai"
sound: Literal["none", "ding", "warning"] = "ding"
html_snippet: str | None = None
tags: list[str] = Field(default_factory=list)
ts: int