A port may now declare `image`, `audio` or `video`. Each is the artifact
reference the engine already had, narrowed by the `media_type` on it, so a
speech recogniser declares what it eats rather than taking any bytes at all and
finding out. Bytes still never travel as a message and nothing on the wire
stops being JSON: a camera publishes one reference per frame, a microphone one
per chunk, and a reference may carry a `meta` dict nothing here interprets.
Streaming media is therefore an ordinary streaming port — with one change to
what that means. An emission used to journal an item with no payload, so
downstream read whatever was current when the item was claimed; a consumer
slower than its producer saw only the newest chunk and the ones between were
lost. That is right for a training curve and wrong for a second of speech, so
an emission now journals a `kind="emission"` item carrying its values, and the
executor hands them to the nodes reading that message instead of writing them
to state again. The value in state stays the latest, which is what everything
else reads, and the wave is filtered by what actually changed rather than
walking everything reachable. No queue serialization change — the existing
`outputs` field carries it.
Continuous media makes the store's missing GC a real problem, so this closes
it: `sweep_artifacts` runs hourly, keeps every digest a `run_artifact` row
records or a live message holds, spares anything written in the last hour, and
stands aside entirely while a run is in flight, since a node may store a
checkpoint long before it returns the reference to it. That also collects the
orphans a deleted flow has always left behind. `ARTIFACT_GC_INTERVAL_S=0` turns
it off.
Around the edges: `GET /artifacts/{digest}` serves the media type the caller
passes and answers ranged requests, so a browser plays a clip rather than
downloading it; `PUT` spools to disk instead of holding the whole body in
memory, as does `save_artifact` given a path; a Media widget draws whatever its
message points at, and a wall panel may fetch the bytes its own tiles are
showing and nothing else; and a connector gets `save_artifact`, for a device
whose readings are bytes.
What this cannot do is live video: a frame every second or two is a glance, and
the honest answer above that is the camera's own stream, which the widget takes
as a URL and the browser plays from source.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
5.0 KiB
Writing a connector
A walkthrough from an empty directory to a node on the canvas. The normative surface is in the connector contract; this is how to use it.
Start from the skeleton
A working connector, kept as small as a correct one can be, lives at
skeleton/ in the connectors repository.
Copy it:
git clone https://git.stroblme.de/Fluksio/connectors.git
cp -r connectors/skeleton fluksio-connector-mydevice
cd fluksio-connector-mydevice
Rename the package (src/fluksio_connector_skeleton/ and the [project] name
in pyproject.toml), then point the entry point at your class:
[project.entry-points."fluksio.node_types"]
my_device = "fluksio_connector_mydevice:MyDevice"
Install it into the engine
Connectors are found through installed package metadata, so the engine has to have yours installed. During development, install it as an editable path dependency of the backend:
cd app/backend
uv add --editable ../../fluksio-connector-mydevice
Editing your connector's code then takes effect on the next engine restart,
with no reinstall. Changing its metadata — the entry point, the version,
the package name — needs uv sync to regenerate the installed metadata before
a restart picks it up.
Two things to know about this:
-
uv addwrites the path dependency intobackend/pyproject.tomlanduv.lock. That path does not exist inside the backend's Docker image, so revert both files before committing; the dependency belongs on your machine, not in the repo. Distribution is a later milestone. -
For the same reason, develop against the standalone backend rather than the Docker stack:
cd app && make dev-backend # FastAPI on :8000 make dev-frontend # Vite on :5173
Restart the backend and your node type appears in the add-node palette (⌘K), labelled with the package it came from.
Write the node
from typing import Any
from pydantic import Field
from fluksio.flow.connector import CONTRACT_VERSION, ConnectorNode
class MyDevice(ConnectorNode):
contract = CONTRACT_VERSION
title = "My device"
description = "Reads temperature and humidity over the device's HTTP API."
class Params(ConnectorNode.Params):
host: str = "192.168.1.50"
api_key: str | None = Field(
default=None, json_schema_extra={"x-secret": True}
)
async def poll(self) -> dict[str, Any] | None:
reading = await self._read()
return {"temperature": reading.temp, "humidity": reading.humidity}
Then, on the canvas: place the node, set poll_interval to how often the
device should be read, pick the API key from the secrets store, and add output
ports named temperature and humidity. The port names are the wiring — any
node consuming those messages is downstream of this one.
If the device is told rather than asked
A connector that commands something implements write() instead of, or
alongside, poll(). Input ports carry the values in:
def write(self, **ports: Any) -> None:
self._device.set(ports["level"])
Place the node with input ports named level, and whatever publishes that
message drives the device. Set idempotent = False on the class: a write is a
command, and a redelivery after a crash should not undo a newer one.
Keep the first version off the wire. A boolean setting the code checks before
it sends — artnet's transmit is the example — lets a flow be built and
watched in the logs before anything physically moves.
If the reading is bytes
A camera or a microphone publishes a reference rather than the bytes:
async def poll(self):
jpeg = await asyncio.to_thread(self._grab)
return {"frame": self.save_artifact(jpeg, "f.jpg", media_type="image/jpeg")}
Place the node with an image-typed output port and a Media widget draws each
frame as it lands. fluksio-connector-test-media publishes test frames and
tones this way, so the whole path can be wired up with no camera in the room —
copy it if yours is a media device.
Try it without a device
Give poll something predictable first and confirm the values reach the canvas
before pointing it at hardware:
async def poll(self):
return {"temperature": 21.5}
Press Run, or wait for the poll interval, and the value appears on the edge. Anything the connector prints shows up in the logs panel in the dock, and a raised exception shows there with its traceback and marks the node down.
Checklist before sharing it
contract = CONTRACT_VERSIONdeclared on the class itself.- Credentials marked
x-secret, never read from the environment. stop()is safe to call twice, and after a failedstart().- Blocking I/O wrapped in
asyncio.to_thread. poll()returnsNonerather than raising when there is simply nothing new.write()returns quickly; the thread it runs on is the scheduler's.- Health reported when the connection comes and goes.