Flow inputs and outputs are visible and editable in the UI

A flow's inputs are the messages it takes from outside — a dashboard control,
a run, the API — and its outputs are what a batch run reports. Both existed in
the document and in the engine, and neither had any UI: the values looked
hard-coded on the canvas and the Run button always used the declared defaults.

The canvas now draws each as a labelled endpoint, the way it already draws a
dashboard tile or another flow, skipping an input something else already
accounts for. The flow panel edits them — mode, name, type, starting value,
and for a live flow the value it currently holds with a way to put a new one
in. Pressing Run on a batch flow asks for its parameters first.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NUb8YpL2s3gmN9WTACTt4q
This commit is contained in:
2026-08-20 18:10:16 +02:00
co-authored by Claude Opus 5
parent 3508713e85
commit 2abeae7f9c
10 changed files with 644 additions and 22 deletions
+61 -5
View File
@@ -1,8 +1,8 @@
import type { Edge, Node as FlowCanvasNode } from "@xyflow/react"
import type { Endpoint, NodeDef_Input } from "@/client"
import type { Endpoint, FlowDef_Input, NodeDef_Input } from "@/client"
import type { FlowEdgeData } from "./deriveEdges"
import { portOf, qualify } from "./deriveEdges"
import { displayName, portOf, qualify } from "./deriveEdges"
/**
* Canvas elements for things wired into a flow that are not nodes in it.
@@ -20,6 +20,9 @@ import { portOf, qualify } from "./deriveEdges"
/** Marks a canvas node as one of these, for anything that has to skip them. */
export const ENDPOINT_TYPE = "endpoint"
/** The id prefixes an endpoint may carry, none of which is a node id. */
const PREFIXES = ["dashboard:", "flow:", "input:", "output:"]
export type EndpointNodeData = {
label: string
kind: string
@@ -31,7 +34,57 @@ export type EndpointNodeData = {
}
export function isEndpointNode(node: { id: string }): boolean {
return node.id.startsWith("dashboard:") || node.id.startsWith("flow:")
return PREFIXES.some((prefix) => node.id.startsWith(prefix))
}
/**
* The flow's own boundary, as endpoints.
*
* An input is a message written from outside — a control, a run, the API — and
* an output is what a batch run reports. They come from the working document
* rather than from the server, so declaring one shows up on the canvas before
* it has been published.
*
* An input a dashboard or another flow already accounts for is left out: the
* label exists so a value has a visible origin, and it already has one.
*/
function boundaryOf(
doc: FlowDef_Input,
flow: string,
accounted: Set<string>,
): Endpoint[] {
const found: Endpoint[] = []
for (const declared of doc.inputs ?? []) {
const message = qualify(flow, declared.spec?.name ?? "")
if (!message || accounted.has(message)) continue
found.push({
kind: "input",
id: `input:${message}`,
label: displayName(flow, message),
detail: declared.spec?.dtype ?? "float",
provides: [message],
requires: [],
})
}
// Only a batch flow has a result; a live one never finishes to have one.
if (doc.mode === "batch") {
for (const name of doc.outputs ?? []) {
const message = qualify(flow, name)
if (!message) continue
found.push({
kind: "output",
id: `output:${message}`,
label: displayName(flow, message),
detail: "result",
provides: [],
requires: [message],
})
}
}
return found
}
/**
@@ -46,8 +99,11 @@ export function deriveEndpoints(
endpoints: Endpoint[],
definitions: NodeDef_Input[],
flow: string,
doc: FlowDef_Input,
): { nodes: FlowCanvasNode[]; edges: Edge[] } {
if (endpoints.length === 0) return { nodes: [], edges: [] }
const accounted = new Set(endpoints.flatMap((one) => one.provides ?? []))
const all = [...boundaryOf(doc, flow, accounted), ...endpoints]
if (all.length === 0) return { nodes: [], edges: [] }
// Which node consumes or produces each message, so a label can sit beside it.
const consumers = new Map<string, { node: string; port: string }[]>()
@@ -77,7 +133,7 @@ export function deriveEndpoints(
const nodes: FlowCanvasNode[] = []
const edges: Edge[] = []
for (const endpoint of endpoints) {
for (const endpoint of all) {
const produces = endpoint.provides ?? []
const reads = endpoint.requires ?? []