From 7eca9454b08a9b15db1ca3a3be34035d9c5e6bef Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Tue, 12 May 2026 13:57:03 +0800 Subject: [PATCH] feat: DB-agent feature sync with conflict detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ConsoleFeature 增加 Available/Conflict 字段 - pageConsole 显示 agent 全部能力(含不可用的),不可用项 disabled - DB 已启用但 agent 不可用时标记为冲突 ⚠ - 不可用功能 hover 显示原因 --- internal/web/ui.go | 36 ++++++++++++++++++++------ internal/web/ui/templates/console.html | 6 +++-- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/internal/web/ui.go b/internal/web/ui.go index 32388f1..44cabb2 100644 --- a/internal/web/ui.go +++ b/internal/web/ui.go @@ -933,9 +933,10 @@ func (u *UI) pageConsole(w http.ResponseWriter, r *http.Request) { } features := make([]ConsoleFeature, 0, len(capsResp.Capabilities)) for _, c := range capsResp.Capabilities { - if c.Available { - features = append(features, ConsoleFeature{Key: c.Key, Label: c.Label, Description: c.Description, Enabled: false}) - } + features = append(features, ConsoleFeature{ + Key: c.Key, Label: c.Label, Description: c.Description, + Available: c.Available, Enabled: false, + }) } deviceAvailableFeatures[dev.DeviceID] = features } @@ -1038,19 +1039,36 @@ func (u *UI) pageConsole(w http.ResponseWriter, r *http.Request) { activeKeys = map[string]bool{} } - // Features from device capabilities (filtered by agent /v1/capabilities). - // Fall back to persisted keys if agent doesn't respond. + // Features from device capabilities (from agent /v1/capabilities). + // Overlay persisted DB state for checkmarks and conflict detection. available := deviceAvailableFeatures[dev.DeviceID] var features []ConsoleFeature if len(available) > 0 { for _, f := range available { f.Enabled = activeKeys[f.Key] + // Conflict: user enabled a feature that the device no longer supports. + if f.Enabled && !f.Available { + f.Conflict = true + } features = append(features, f) } - } else { - // Old agent: use persisted keys to show at least what's configured. + // Show persisted features that the agent didn't report (e.g. new features + // added to registry but old agent doesn't know them). + seen := map[string]bool{} + for _, f := range features { + seen[f.Key] = true + } for key := range activeKeys { - features = append(features, ConsoleFeature{Key: key, Label: key, Enabled: true}) + if !seen[key] { + features = append(features, ConsoleFeature{ + Key: key, Label: key, Enabled: true, Available: false, Conflict: true, + }) + } + } + } else { + // Old agent: show persisted keys. + for key := range activeKeys { + features = append(features, ConsoleFeature{Key: key, Label: key, Enabled: true, Available: true}) } } @@ -4732,4 +4750,6 @@ type ConsoleFeature struct { Label string Description string Enabled bool + Available bool // device actually supports this (from agent /v1/capabilities) + Conflict bool // enabled in DB but unavailable on device } diff --git a/internal/web/ui/templates/console.html b/internal/web/ui/templates/console.html index 231e124..ac8516b 100644 --- a/internal/web/ui/templates/console.html +++ b/internal/web/ui/templates/console.html @@ -61,8 +61,10 @@ {{range $f := $cd.Features}} - - + + {{end}}
{{$f.Label}} + {{$f.Label}}{{if $f.Conflict}} ⚠{{end}} +