Add the connector contract, reusable nodes and per-port intervals

Connectors are the device-facing node class third parties write, so the
surface they build against is versioned and documented: ConnectorNode carries
a declared contract version, a polling loop that publishes only what changed
and reports health around it, and parameters whose credential fields are
marked x-secret so the editor offers the secrets store instead of a text box.
They are found through the fluksio.node_types entry point group, with the
package's own metadata as the manifest. docs/connectors/ has the contract and
the authoring guide; connector-skeleton/ is a working one to copy.

The controller no longer knows what any node type is: start, stop and
report_health are protocol methods on Node, and the built-ins were migrated to
them first, so the hooks a connector implements are the ones the engine has
been driving all along.

Marking a node reusable moves its source to _lib/ and points the node at it by
name. Other flows instantiate it with their own ports and settings, one fix
reaches all of them, and a shared source still in use cannot be deleted.

Ports gained an interval: an output publishes, and an input wakes its node, at
most every n seconds. State keeps the latest value, so only the delivery is
skipped, and pressing Run is never throttled.

Also fixes autosave sending no version on its first save of a session, which
made every flow saved more than once conflict with itself.
This commit is contained in:
Melvin Strobl
2026-08-15 23:57:44 +02:00
parent 05dccdf88d
commit cb5e8f0ecc
22 changed files with 1541 additions and 62 deletions
+27 -2
View File
@@ -5,7 +5,12 @@ import {
} from "@tanstack/react-query"
import { useCallback, useEffect, useRef, useState } from "react"
import { ApiError, type FlowDef_Input, FlowsService } from "@/client"
import {
ApiError,
type FlowDef_Input,
FlowsService,
SecretsService,
} from "@/client"
export const flowKeys = {
all: ["flows"] as const,
@@ -15,6 +20,7 @@ export const flowKeys = {
history: (name: string, message: string) =>
["flows", name, "history", message] as const,
nodeTypes: ["flows", "node-types"] as const,
library: ["flows", "library"] as const,
}
export const flowsQueryOptions = () => ({
@@ -27,6 +33,18 @@ export const flowQueryOptions = (name: string) => ({
queryFn: () => FlowsService.readFlow({ name }),
})
/** Names of the stored secrets, for pointing a credential parameter at one. */
export const secretsQueryOptions = () => ({
queryKey: ["secrets"] as const,
queryFn: () => SecretsService.readSecrets(),
})
/** Node sources shared across flows, with the nodes using each. */
export const libraryQueryOptions = () => ({
queryKey: flowKeys.library,
queryFn: () => FlowsService.readLibrary(),
})
export const nodeTypesQueryOptions = () => ({
queryKey: flowKeys.nodeTypes,
queryFn: () => FlowsService.readNodeTypes(),
@@ -107,7 +125,14 @@ export function useAutosave(name: string): {
mutationFn: (definition: FlowDef_Input) =>
FlowsService.saveFlow({
name,
requestBody: { ...definition, version: version.current ?? undefined },
// The ref holds the freshest version this client has seen; before the
// first save that is the one the document was loaded with. Sending
// `undefined` would drop the field and let the server read the default,
// which conflicts with every flow saved more than once.
requestBody: {
...definition,
version: version.current ?? definition.version ?? 1,
},
}),
onMutate: (definition) => {
inFlight.current = true