Capability report: PUT /devices/{id}/report, a Capabilities section, offline devices degraded

A device reports its board, screen, camera and ports from its own
credential (16 KB, schema 1, replacing the last report), and the flows
are validated against it again. The node panel turns a reported port's
config schema into a form, a reported screen is a canvas preset and a
touch screen's first report turns Touch friendly on. An offline device
node is degraded: amber on the canvas, a warning on Home, never a fault.
This commit is contained in:
Melvin Strobl
2026-10-16 17:37:49 +02:00
parent 1dc891aa1b
commit 4286acadfd
28 changed files with 820 additions and 129 deletions
+18 -7
View File
@@ -424,18 +424,26 @@ function FlowEditorInner({
[nodeTypeInfo],
)
const issuesByNode = useMemo(() => {
const map = new Map<string, string[]>()
const [issuesByNode, warningsByNode] = useMemo(() => {
const faults = new Map<string, string[]>()
const warnings = new Map<string, string[]>()
for (const issue of issues) {
// A node's dot and border are its status channel, and status has no
// warning tier — an advisory is not a fault, so it says its piece in the
// dock rather than painting the node red.
if (!issue.node || issue.advisory) continue
// A node's dot and border are its status channel. An advisory is not a
// fault, so it says its piece in the dock rather than painting the node
// red. A degraded node, a device that is offline, is the one warning
// the node itself wears, in amber.
if (!issue.node) continue
const map = !issue.advisory
? faults
: issue.code === "node_degraded"
? warnings
: null
if (!map) continue
const list = map.get(issue.node) ?? []
list.push(issue.message)
map.set(issue.node, list)
}
return map
return [faults, warnings]
}, [issues])
const showLogs = useCallback((nodeId: string) => {
@@ -449,6 +457,7 @@ function FlowEditorInner({
canvasNodes.map((node) => {
const definition = definitions.find((entry) => entry.id === node.id)
const nodeIssues = issuesByNode.get(`${flowName}.${node.id}`) ?? []
const nodeWarnings = warningsByNode.get(`${flowName}.${node.id}`) ?? []
return {
...node,
selected: node.selected || node.id === selectedId,
@@ -459,6 +468,7 @@ function FlowEditorInner({
typeLabels.get(definition?.type ?? "") ?? definition?.type ?? "",
isPlugin: pluginTypes.has(definition?.type ?? ""),
issueText: nodeIssues.join("\n"),
warningText: nodeWarnings.join("\n"),
onShowLogs: showLogs,
} satisfies FlowNodeData,
}
@@ -468,6 +478,7 @@ function FlowEditorInner({
definitions,
flowName,
issuesByNode,
warningsByNode,
pluginTypes,
selectedId,
showLogs,
+24 -4
View File
@@ -77,6 +77,8 @@ const STATUS_STYLES = {
},
running: { dot: "bg-primary animate-pulse", label: "Running" },
success: { dot: "bg-status-success", label: "Last run succeeded" },
// Works, if not as it should: a device that is offline. Not a fault.
warning: { dot: "bg-status-warning", label: "Degraded" },
error: { dot: "bg-destructive", label: "Something went wrong" },
} as const
@@ -86,6 +88,8 @@ export type FlowNodeData = {
typeLabel: string
isPlugin?: boolean
issueText: string
/** Why the node is degraded, if it is: amber, never a fault. */
warningText?: string
/** Open the logs at this node's own lines. */
onShowLogs?: (nodeId: string) => void
[key: string]: unknown
@@ -126,8 +130,15 @@ function PortHandles({
}
function FlowNodeComponent({ data, selected }: NodeProps) {
const { definition, flow, typeLabel, isPlugin, issueText, onShowLogs } =
data as FlowNodeData
const {
definition,
flow,
typeLabel,
isPlugin,
issueText,
warningText,
onShowLogs,
} = data as FlowNodeData
const nodeId = `${flow}.${definition.id}`
const live = useNodeStatus(nodeId)
const emits = useNodeEmits(nodeId)
@@ -174,7 +185,12 @@ function FlowNodeComponent({ data, selected }: NodeProps) {
.join("\n")
.split("\n")
const problem = [...new Set(lines)].join("\n")
const status = problem ? "error" : live?.status
const warning = problem ? "" : (warningText ?? "")
const status = problem
? "error"
: warning && live?.status !== "running"
? "warning"
: live?.status
const running = status === "running"
const style = STATUS_STYLES[status as keyof typeof STATUS_STYLES]
// Failed at some point, fine as of the last run. It gets no dot and no
@@ -209,6 +225,7 @@ function FlowNodeComponent({ data, selected }: NodeProps) {
// Selection wins the border when it is both — the dot is the status
// channel, and it is still red underneath.
problem && "border-destructive",
status === "warning" && "border-status-warning",
selected && "border-primary shadow-e2",
)}
>
@@ -318,7 +335,10 @@ function FlowNodeComponent({ data, selected }: NodeProps) {
/>
</TooltipTrigger>
<TooltipContent className="max-h-60 max-w-xs overflow-y-auto whitespace-pre-line break-words">
{problem || live?.detail || style.label}
{problem ||
(status === "warning" ? warning : "") ||
live?.detail ||
style.label}
</TooltipContent>
</Tooltip>
) : null}
+72 -19
View File
@@ -27,10 +27,10 @@ import {
} from "@/client"
import {
DEVICE_TYPE,
PORT_SUGGESTIONS,
portOf,
type ReportedPort,
reportedPorts,
wiresAs,
} from "@/components/Devices/ports"
import { devicesQueryOptions } from "@/components/Devices/queries"
import { Button } from "@/components/ui/button"
@@ -637,8 +637,7 @@ function DevicePortList({
onChange: (next: MessageSpec[], renamed?: [string, string | null]) => void
onConfig: (port: string, next: Record<string, unknown>) => void
}) {
const offered = reported?.filter((port) => port.direction === direction)
const listId = `device-ports-${direction}`
const offered = reported?.filter((port) => wiresAs(port, direction))
// An out port is read when the device asks for it, never a reason to run.
const fresh = (port: ReportedPort | null): MessageSpec => ({
name: port ? port.port.replace(/\./g, "_") : "",
@@ -670,17 +669,19 @@ function DevicePortList({
Add
</Button>
</div>
<datalist id={listId}>
{PORT_SUGGESTIONS.map((port) => (
<option key={port} value={port} />
))}
</datalist>
{specs.length === 0 ? (
<p className="text-sm text-muted-foreground">No ports yet.</p>
) : null}
{specs.map((spec, index) => {
const port = spec.port ?? ""
const name = port || "new port"
const said = reported?.find((one) => one.port === port)
// The device says which settings it reads, so they get a form.
const schema =
said?.config &&
Object.keys((said.config.properties as object) ?? {}).length
? said.config
: undefined
return (
<div key={`port-${index}`} className="grid min-w-0 gap-1.5">
<div className="flex min-w-0 items-center gap-1.5">
@@ -730,7 +731,6 @@ function DevicePortList({
placeholder="Port, e.g. gpio.4"
aria-label={`Port of ${name}`}
autoComplete="off"
list={listId}
className="h-8 min-w-0 flex-1 font-mono text-sm"
onBlur={(event) => {
const next = portOf(event.currentTarget.value)
@@ -792,16 +792,35 @@ function DevicePortList({
autoFocus={false}
onChange={(next) => update(index, { name: next })}
/>
<JsonField
value={config[port] ?? {}}
label={`Config of ${name}`}
check={objectOnly}
className="h-8 w-24 shrink-0"
onChange={(next) => {
if (port) onConfig(port, next as Record<string, unknown>)
}}
/>
{schema ? null : (
<JsonField
value={config[port] ?? {}}
label={`Config of ${name}`}
check={objectOnly}
className="h-8 w-24 shrink-0"
onChange={(next) => {
if (port) onConfig(port, next as Record<string, unknown>)
}}
/>
)}
</div>
{reported && port && !said ? (
<p className="pl-5.5 text-xs text-muted-foreground">
The device does not report this port.
</p>
) : null}
{schema ? (
<div className="pl-5.5">
<ParamsForm
type={undefined}
title={`${port} settings`}
schema={schema}
params={(config[port] ?? {}) as Record<string, unknown>}
provides={[]}
onChange={(next) => onConfig(port, next)}
/>
</div>
) : null}
</div>
)
})}
@@ -1120,12 +1139,14 @@ function InjectPayloads({
/** A small form built from the node type's declared parameters. */
function ParamsForm({
type,
title = "Settings",
schema,
params,
provides,
onChange,
}: {
type: string | undefined
title?: string
schema: Record<string, unknown> | undefined
params: Record<string, unknown>
/** The ports an inject's payload fields follow; unused by every other type. */
@@ -1139,6 +1160,7 @@ function ParamsForm({
title?: string
description?: string
default?: unknown
enum?: unknown[]
"x-secret"?: boolean
}
>
@@ -1161,7 +1183,7 @@ function ParamsForm({
return (
<div className="grid gap-3">
<span className={SECTION}>Settings</span>
<span className={SECTION}>{title}</span>
{entries.map(([key, property]) => {
// In the schema's own place, so the payload keeps its position in the
// form even though it is now one field per port.
@@ -1261,6 +1283,37 @@ function ParamsForm({
)
}
// A closed set of choices, such as a pin's pull.
if (property.enum?.length) {
return (
<div key={key} className="grid gap-1.5">
<FieldLabel htmlFor={`param-${key}`} help={property.description}>
{label}
</FieldLabel>
<Select
value={String(value)}
onValueChange={(next) =>
set(
key,
property.enum?.find((choice) => String(choice) === next),
)
}
>
<SelectTrigger id={`param-${key}`} className="!h-8 text-sm">
<SelectValue />
</SelectTrigger>
<SelectContent>
{property.enum.map((choice) => (
<SelectItem key={String(choice)} value={String(choice)}>
{String(choice)}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
)
}
const numeric =
property.type === "integer" || property.type === "number"
return (
@@ -85,7 +85,7 @@ type FlowEvent =
type: "node_health"
flow?: string
node: string
health: "ok" | "down" | "unknown"
health: "ok" | "degraded" | "down" | "unknown"
detail?: string | null
ts?: number
}
@@ -335,7 +335,9 @@ function open(url: string) {
// or a rebuild, never when health actually flipped. The store had a
// health map of its own and nothing ever read it.
invalidateHealth(message.flow)
if (message.health === "down") {
// Degraded is held back by the same floor, as a warning rather than
// a fault.
if (message.health === "down" || message.health === "degraded") {
// This fires at the transition, while the floor is still hiding the
// node, and the engine publishes nothing when the floor expires — so
// read again ourselves at that moment, or the issue waits for an
@@ -355,7 +357,11 @@ function open(url: string) {
type: message.type,
flow: message.flow,
node: message.node,
detail: message.detail ?? "Reported itself down.",
detail:
message.detail ??
(message.health === "down"
? "Reported itself down."
: "Reported itself degraded."),
ts: message.ts ?? Date.now() / 1000,
})
} else {