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.
This commit is contained in:
1 parent
14e27a4f16
commit
3889b6d910
5 files changed
+42
-1
No files matched your search
@@ -22,6 +22,7 @@ import android.webkit.WebResourceResponse
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebViewClient
|
||||
import android.widget.Button
|
||||
import android.widget.CheckBox
|
||||
import android.widget.EditText
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.LinearLayout
|
||||
@@ -486,6 +487,21 @@ class MainActivity : AppCompatActivity(), HubMessageListener {
|
||||
var lastFixSummary = ""
|
||||
var lastErrors: List<String> = emptyList()
|
||||
|
||||
// Precheck switch: when off, skip the offscreen sandbox validation entirely.
|
||||
// The offscreen WebView wake-up + full DOM render is by far the heaviest
|
||||
// part of this pipeline on low-end TV boxes, and it runs once per page.
|
||||
// Trade-off: pages render immediately without pre-flight error detection,
|
||||
// so malformed HTML will show up on screen instead of being repaired first.
|
||||
if (!aiCfg.precheckEnabled) {
|
||||
ctx.html = candidateHtml
|
||||
activeRender = ctx
|
||||
prefs.lastHealthySnapshotId = ctx.snapshotId
|
||||
prefs.lastHealthyHtml = candidateHtml
|
||||
mountHtmlOnMain(ctx)
|
||||
sendRenderResult(ctx, trigger, "rendered_precheck_skipped", attempts, candidateHtml, lastFixSummary, JSONArray(), emptyList())
|
||||
return
|
||||
}
|
||||
|
||||
// If upstream answered a clarification, let end-side Repair AI integrate the answer first
|
||||
if (upstreamAnswers != null && aiCfg.enabled) {
|
||||
val dec = sentinel.diagnoseAndRepair(
|
||||
@@ -805,6 +821,11 @@ class MainActivity : AppCompatActivity(), HubMessageListener {
|
||||
val tokEt = addField("鉴权 Token (可选)", prefs.authToken)
|
||||
|
||||
val aiCfg = prefs.getRepairAiConfig()
|
||||
val precheckCb = CheckBox(this).apply {
|
||||
text = "启用离屏沙箱预校验(关可降低低配设备发热)"
|
||||
isChecked = aiCfg.precheckEnabled
|
||||
}
|
||||
container.addView(precheckCb)
|
||||
container.addView(TextView(this).apply {
|
||||
text = "\n连接状态: $lastConnDetail\n版本: v${BuildConfig.VERSION_NAME} (build ${BuildConfig.VERSION_CODE}) · Root: ${if (telemetry.isRootAvailable()) "已启用" else "未检测到"}\n端侧修复 AI (由中心桥热下发): " +
|
||||
if (aiCfg.enabled) "已启用 (${aiCfg.model})" else "未启用"
|
||||
@@ -866,6 +887,7 @@ class MainActivity : AppCompatActivity(), HubMessageListener {
|
||||
prefs.deviceId = idEt.text.toString()
|
||||
prefs.deviceName = nameEt.text.toString()
|
||||
prefs.authToken = tokEt.text.toString()
|
||||
prefs.setRepairPrecheckEnabled(precheckCb.isChecked)
|
||||
wsClient.reconnect()
|
||||
Toast.makeText(this, "正在重连中心桥...", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.util.UUID
|
||||
|
||||
data class RepairAiConfig(
|
||||
val enabled: Boolean = false,
|
||||
val precheckEnabled: Boolean = true,
|
||||
val baseUrl: String = "https://api.openai.com/v1",
|
||||
val apiKey: String = "",
|
||||
val model: String = "gpt-4o-mini",
|
||||
@@ -61,6 +62,7 @@ class AppPrefs(context: Context) {
|
||||
fun getRepairAiConfig(): RepairAiConfig {
|
||||
return RepairAiConfig(
|
||||
enabled = sp.getBoolean("ai_enabled", false),
|
||||
precheckEnabled = sp.getBoolean("ai_precheck_enabled", true),
|
||||
baseUrl = sp.getString("ai_base_url", "https://api.openai.com/v1") ?: "https://api.openai.com/v1",
|
||||
apiKey = sp.getString("ai_api_key", "") ?: "",
|
||||
model = sp.getString("ai_model", "gpt-4o-mini") ?: "gpt-4o-mini",
|
||||
@@ -70,11 +72,16 @@ class AppPrefs(context: Context) {
|
||||
)
|
||||
}
|
||||
|
||||
fun setRepairPrecheckEnabled(enabled: Boolean) {
|
||||
sp.edit().putBoolean("ai_precheck_enabled", enabled).apply()
|
||||
}
|
||||
|
||||
fun applyHubConfigPush(payload: JSONObject) {
|
||||
val editor = sp.edit()
|
||||
val ai = payload.optJSONObject("repair_ai")
|
||||
if (ai != null) {
|
||||
editor.putBoolean("ai_enabled", ai.optBoolean("enabled", false))
|
||||
editor.putBoolean("ai_precheck_enabled", ai.optBoolean("precheck_enabled", true))
|
||||
editor.putString("ai_base_url", ai.optString("base_url", "https://api.openai.com/v1"))
|
||||
editor.putString("ai_api_key", ai.optString("api_key", ""))
|
||||
editor.putString("ai_model", ai.optString("model", "gpt-4o-mini"))
|
||||
|
||||
+4
-1
@@ -151,6 +151,7 @@ ADMIN_HTML = r"""<!DOCTYPE html>
|
||||
<span id="global_cfg_dirty" class="badge off" style="display:none;">有未保存修改</span>
|
||||
</h2>
|
||||
<label><input type="checkbox" id="g_ai_enabled" style="width:auto;margin-right:6px;">默认启用端侧自动修复哨兵</label>
|
||||
<label><input type="checkbox" id="g_ai_precheck" style="width:auto;margin-right:6px;">启用离屏沙箱预校验(关闭可降低低配设备发热)</label>
|
||||
<label>OpenAI Base URL</label>
|
||||
<input id="g_ai_base_url" placeholder="https://api.openai.com/v1" />
|
||||
<label>API Key</label>
|
||||
@@ -215,7 +216,7 @@ function switchTab(name) {
|
||||
}
|
||||
|
||||
// ---- Dirty tracking for Global & Hub Chat AI forms ----
|
||||
['g_ai_enabled','g_ai_base_url','g_ai_api_key','g_ai_model','g_ai_retries','g_ai_cooldown','g_lan_debug'].forEach(id => {
|
||||
['g_ai_enabled','g_ai_precheck','g_ai_base_url','g_ai_api_key','g_ai_model','g_ai_retries','g_ai_cooldown','g_lan_debug'].forEach(id => {
|
||||
const el = document.getElementById(id);
|
||||
el.addEventListener('input', () => { globalCfgDirty = true; document.getElementById('global_cfg_dirty').style.display='inline-block'; });
|
||||
el.addEventListener('change', () => { globalCfgDirty = true; document.getElementById('global_cfg_dirty').style.display='inline-block'; });
|
||||
@@ -231,6 +232,7 @@ async function loadGlobalAndChatConfig(force = false) {
|
||||
if (force || !globalCfgDirty) {
|
||||
const r = cfg.repair_ai || {};
|
||||
document.getElementById('g_ai_enabled').checked = !!r.enabled;
|
||||
document.getElementById('g_ai_precheck').checked = r.precheck_enabled !== false;
|
||||
document.getElementById('g_ai_base_url').value = r.base_url || '';
|
||||
document.getElementById('g_ai_api_key').value = r.api_key || '';
|
||||
document.getElementById('g_ai_model').value = r.model || '';
|
||||
@@ -255,6 +257,7 @@ async function saveGlobalConfig() {
|
||||
const body = {
|
||||
repair_ai: {
|
||||
enabled: document.getElementById('g_ai_enabled').checked,
|
||||
precheck_enabled: document.getElementById('g_ai_precheck').checked,
|
||||
base_url: document.getElementById('g_ai_base_url').value.trim(),
|
||||
api_key: document.getElementById('g_ai_api_key').value.trim(),
|
||||
model: document.getElementById('g_ai_model').value.trim(),
|
||||
|
||||
@@ -37,6 +37,7 @@ class DeviceTelemetry(BaseModel):
|
||||
|
||||
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"
|
||||
|
||||
@@ -14,6 +14,7 @@ const dirty = ref(false)
|
||||
const saving = ref(false)
|
||||
const form = ref({
|
||||
enabled: false,
|
||||
precheck_enabled: true,
|
||||
base_url: 'https://api.openai.com/v1',
|
||||
api_key: '',
|
||||
model: 'gpt-4o-mini',
|
||||
@@ -31,6 +32,7 @@ function loadFromProps(force = false) {
|
||||
const chatAi = props.globalConfig.hub_chat_ai || {}
|
||||
form.value = {
|
||||
enabled: !!r.enabled,
|
||||
precheck_enabled: r.precheck_enabled !== false,
|
||||
base_url: r.base_url || 'https://api.openai.com/v1',
|
||||
api_key: r.api_key || '',
|
||||
model: r.model || 'gpt-4o-mini',
|
||||
@@ -53,6 +55,7 @@ async function saveGlobal() {
|
||||
const body = {
|
||||
repair_ai: {
|
||||
enabled: form.value.enabled,
|
||||
precheck_enabled: form.value.precheck_enabled,
|
||||
base_url: form.value.base_url.trim(),
|
||||
api_key: form.value.api_key.trim(),
|
||||
model: form.value.model.trim(),
|
||||
@@ -107,6 +110,11 @@ async function pushOtaAll() {
|
||||
默认启用端侧自动修复哨兵
|
||||
</label>
|
||||
|
||||
<label class="check-line">
|
||||
<input v-model="form.precheck_enabled" type="checkbox" @change="dirty = true" />
|
||||
启用离屏沙箱预校验(关闭可降低低配设备发热)
|
||||
</label>
|
||||
|
||||
<label class="field-label">OpenAI Base URL</label>
|
||||
<input v-model="form.base_url" class="input mono" @input="dirty = true" />
|
||||
|
||||
|
||||
Reference in new issue
Block a user