Device node: a device's ports are wired in flows

- flow/nodes/device.py: `device` node with params `device` and `config`;
  provides the device's `in` ports, requires its `out` ports without
  waking anything, never run (Node.passive), down "Offline" from presence
- DeviceDef.io and DevicePort go; GET /devices/{id} computes `io` and
  `bindings` from the device nodes of published flows, in a fixed order,
  cached by FlowStore.revision; the credential's scope comes from them
- issues `unknown_device` and `device_port` (wired twice; against a report
  the wrong direction or dtype, or unlisted as advisory), rechecked when a
  device is created or deleted; ValidationIssue.advisory is a field
- a device publishing on a bound port is credited to its node by the
  server; the panel endpoint kind is gone from `_endpoints` and the canvas
- a rebuild that moves a device's bindings sends `dashboard_changed` with
  an empty name, which the firmware refetches on
- startup moves each device's `io` rows into device nodes in the flows
  declaring their messages, draft and published, one commit; rows no
  flow declares are logged and left out
- frontend: Device node settings (device, Publishes, Follows, a port
  picker from a report), palette shortcuts per reported port, DeviceDetail
  lists bindings with "Use in flow" in place of the I/O editor
- docs: devices, flow editor, node types, issues, API
This commit is contained in:
Melvin Strobl
2026-10-16 16:40:31 +02:00
parent 91e3b703f9
commit 29d3ec467f
35 changed files with 2195 additions and 494 deletions
+42 -6
View File
@@ -25,6 +25,7 @@ import { motion } from "motion/react"
import { useCallback, useEffect, useMemo, useRef, useState } from "react"
import {
type DevicePublic,
type FlowDef_Input,
type FlowDetail,
FlowsService,
@@ -33,6 +34,12 @@ import {
RunsService,
} from "@/client"
import { DiscardDraftDialog } from "@/components/Common/Dock"
import {
DEVICE_TYPE,
deviceNodeOf,
type ReportedPort,
withPort,
} from "@/components/Devices/ports"
import { useTheme } from "@/components/theme-provider"
import { Button } from "@/components/ui/button"
import {
@@ -511,12 +518,6 @@ function FlowEditorInner({
to: "/dashboards/$name",
params: { name: (rest ?? "").split(":")[0] },
})
} else if (kind === "panel") {
// A device's own port: its page in the Devices tab.
navigate({
to: "/devices/$id",
params: { id: (rest ?? "").split(":")[0] },
})
} else if (kind === "flow") {
navigate({
to: "/flows/$flowName",
@@ -940,6 +941,40 @@ function FlowEditorInner({
[commit, definitions],
)
/**
* A port a device reports, on this flow's node for that device. One node per
* device keeps its ports together, so it is made only when there is none.
*/
const addDevicePort = useCallback(
(device: DevicePublic, port: ReportedPort) => {
const existing = deviceNodeOf(definitions, device.id)
if (existing) {
updateNode(withPort(existing, port))
setSelectedId(existing.id)
return
}
const id = uniqueNodeId(definitions, device.id)
const node = withPort(
{
id,
type: DEVICE_TYPE,
title: device.title || device.id,
params: { device: device.id, config: {} },
requires: [],
provides: [],
},
port,
)
setCanvasNodes([
...canvasNodes,
{ id, type: "flow", position: { x: 0, y: 0 }, data: {} },
])
commit([...definitions, node])
setSelectedId(id)
},
[canvasNodes, commit, definitions, setCanvasNodes, updateNode],
)
const deleteNodes = useCallback(
(ids: string[]) => {
const remaining = definitions.filter((node) => !ids.includes(node.id))
@@ -1510,6 +1545,7 @@ function FlowEditorInner({
onAddSharedNode={
mayEditCode ? (libName) => addNode("python", libName) : undefined
}
onAddDevicePort={addDevicePort}
onRun={startRun}
/>