import { runtimeApi, segmentControl } from "./api.js"; const STATE_LABEL = { idle: "空闲", checking: "校验", executing: "执行", confirming: "等待确认", resetting: "复位", completed: "完成", blocked: "阻塞", faulted: "故障", manual_ack_required: "待人工确认", }; const STATE_CLASS = { idle: "state-idle", checking: "state-active", executing: "state-active", confirming: "state-active", resetting: "state-active", completed: "state-active", blocked: "state-warn", faulted: "state-error", manual_ack_required: "state-warn", }; const segments = new Map(); function escapeHtml(text) { if (text === null || text === undefined) return ""; return String(text) .replaceAll("&", "&") .replaceAll("<", "<") .replaceAll(">", ">"); } function renderState(runtime) { const state = runtime?.state || "idle"; const label = STATE_LABEL[state] || state; const cls = STATE_CLASS[state] || "state-idle"; return `${escapeHtml(label)}`; } function renderActions(seg) { const runtime = seg.runtime || {}; const autoOn = runtime.auto_enabled === true; const state = runtime.state || "idle"; const canAck = state === "faulted" || state === "manual_ack_required"; const canReset = canAck || state === "blocked"; return `