flow: structured dtypes, and the widgets that read them

A series, record or list message declares its shape instead of riding
DType.JSON, so a widget binds a shape rather than some JSON and a wrong
binding is refused before anything runs. A list declares its item type,
which is what keeps list[float] expressible for a pipeline.

On top of that: an agenda over a list, a notification over a record, and
a dashboard alert channel that publishes engine faults as one — so a
panel can show what went wrong without a flow wiring it by hand.

Also: only None means a node published nothing, a falsy value of the
wrong shape is now the named error it always should have been; and the
gauge's readout says its size is viewBox geometry rather than type scale.
This commit is contained in:
2026-08-17 15:06:45 +02:00
parent 55f76ced06
commit 3b4450c211
16 changed files with 751 additions and 43 deletions
+24 -1
View File
@@ -16,6 +16,7 @@ import asyncio
import logging
import time
from collections import deque
from collections.abc import Callable
from typing import Any, Literal
import httpx
@@ -51,9 +52,10 @@ class Channel(BaseModel):
"""Somewhere to send an alert."""
name: str
kind: Literal["ntfy", "smtp", "webhook"]
kind: Literal["ntfy", "smtp", "webhook", "dashboard"]
enabled: bool = True
# ntfy: server + topic + optional token. smtp: to. webhook: url.
# dashboard: message — the record a notification widget reads.
config: dict[str, Any] = Field(default_factory=dict)
@@ -160,6 +162,10 @@ class AlertManager:
self._events = events
self.config = config or AlertsConfig()
self._now = now
#: How a "dashboard" channel puts its alert into the graph. Bound after
#: construction, because the controller that publishes does not exist
#: yet when the manager is built.
self.publish: Callable[[str, Any], None] | None = None
self._last_sent: dict[str, float] = {}
self._suppressed: dict[str, int] = {}
self._health_flips: dict[str, deque[float]] = {}
@@ -294,6 +300,8 @@ class AlertManager:
await self._send_ntfy(config, alert)
elif channel.kind == "webhook":
await self._send_webhook(config, alert)
elif channel.kind == "dashboard":
await self._send_dashboard(config, alert)
else:
await self._send_email(config, alert)
except Exception as exc:
@@ -319,6 +327,21 @@ class AlertManager:
)
response.raise_for_status()
async def _send_dashboard(self, config: dict[str, Any], alert: Alert) -> None:
"""Put the alert into the graph, where a notification widget shows it.
The message has to be one a flow declares, like any other a dashboard
writes to — so a panel that shows engine faults says so in a flow
rather than appearing from nowhere.
"""
message = str(config.get("message") or "")
if not message:
raise ValueError("a dashboard channel needs a message name")
if self.publish is None:
raise RuntimeError("nothing is wired up to publish this")
# Blocking: it reads the store to find the declared message.
await asyncio.to_thread(self.publish, message, alert.model_dump())
async def _send_webhook(self, config: dict[str, Any], alert: Alert) -> None:
url = config.get("url")
if not url: