New run: start a run from the app, on the working copy

The site promises simulated inputs and mocked sensor values, and nothing in
the app was that. A run already is: the values are the caller's, the state is
the run's own namespace, and nothing it computes reaches the live flow. What
was missing was a screen to do it from, and the draft flag being honoured.

`/runs/new` is a flow, a field per declared input, a seed and Run; `/runs`
stays the log. A comma-separated list in a number field expands into the grid
`fluksio sweep --param` builds and goes to the sweep route, so launching one
no longer needs a terminal. Only numbers split: a comma in a string is
content, and one in JSON is syntax.

`RunCreate.draft` was validated at submit and dropped before the run
executed, so "try the working copy" ran the published one. `Run.draft` is a
column now, the driver reads the same copy the submit checked, and a retry
carries it. `FlowSummary.mode` came with it so the rail can say which flows
are batch before one is picked.

Also here: a Retry button on a finished run, which the route has always had
and the UI never did, and parameter cells truncated to their column with the
full value on hover.
This commit is contained in:
2026-09-02 15:10:24 +02:00
parent 40864d5ca5
commit 954496de0d
20 changed files with 926 additions and 91 deletions
+102 -63
View File
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react"
import type { FlowDef_Input } from "@/client"
import type { DType, FlowDef_Input, FlowInput_Input } from "@/client"
import { Button } from "@/components/ui/button"
import {
Dialog,
@@ -22,6 +22,83 @@ import {
import { parseByDtype } from "./FlowBoundary"
import { asText } from "./NodePanel"
/**
* A field per declared input, the way its type is entered.
*
* Held as text rather than as values: half-typed input is normal ("-", "1.",
* a JSON object with one brace), and a list of them is a sweep — both of
* which a parsed value would have thrown away. The caller parses on submit.
*/
export function ParamFields({
inputs,
values,
placeholderFor,
onChange,
}: {
inputs: FlowInput_Input[]
values: Record<string, string>
/** What an empty field says it takes, when the default is not enough. */
placeholderFor?: (dtype: DType | undefined) => string
onChange: (values: Record<string, string>) => void
}) {
return (
<div className="grid gap-3">
{inputs.map((declared) => {
const name = declared.spec?.name ?? ""
const dtype = declared.spec?.dtype
return (
<div key={name} className="grid gap-1.5">
<Label htmlFor={`param-${name}`} className="font-mono text-xs">
{name}
</Label>
{dtype === "bool" ? (
<Select
value={values[name] === "true" ? "true" : "false"}
onValueChange={(next) => onChange({ ...values, [name]: next })}
>
<SelectTrigger id={`param-${name}`} className="text-sm">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="true">true</SelectItem>
<SelectItem value="false">false</SelectItem>
</SelectContent>
</Select>
) : (
<Input
id={`param-${name}`}
value={values[name] ?? ""}
placeholder={
placeholderFor?.(dtype) ??
(dtype === "artifact"
? "@run:<id>.<output> or sha256:…"
: `${dtype ?? "float"} or @run:<id>.<output>`)
}
className="text-sm"
onChange={(event) =>
onChange({ ...values, [name]: event.target.value })
}
/>
)}
</div>
)
})}
</div>
)
}
/** What the fields start from: the declared value of each, as text. */
export function initialText(inputs: FlowInput_Input[]): Record<string, string> {
return Object.fromEntries(
inputs.map((one) => [one.spec?.name ?? "", asText(one.initial)]),
)
}
/** The declared inputs worth drawing a field for. */
export function declaredInputs(definition: FlowDef_Input): FlowInput_Input[] {
return (definition.inputs ?? []).filter((one) => one.spec?.name)
}
/**
* The parameters of one run, taken from the flow's inputs.
*
@@ -42,8 +119,8 @@ export function RunDialog({
onOpenChange: (open: boolean) => void
onRun: (params: Record<string, unknown>) => void
}) {
const inputs = (definition.inputs ?? []).filter((one) => one.spec?.name)
const [values, setValues] = useState<Record<string, unknown>>({})
const inputs = declaredInputs(definition)
const [values, setValues] = useState<Record<string, string>>({})
// Opening is what fills the form: an edit to the flow between two runs
// should show up, and the last run's values should not linger. The inputs
@@ -51,11 +128,7 @@ export function RunDialog({
// biome-ignore lint/correctness/useExhaustiveDependencies: opening is the dependency.
useEffect(() => {
if (!open) return
setValues(
Object.fromEntries(
inputs.map((one) => [one.spec?.name ?? "", one.initial ?? null]),
),
)
setValues(initialText(inputs))
}, [open])
return (
@@ -70,52 +143,7 @@ export function RunDialog({
</DialogDescription>
</DialogHeader>
<div className="grid gap-3">
{inputs.map((declared) => {
const name = declared.spec?.name ?? ""
const dtype = declared.spec?.dtype
return (
<div key={name} className="grid gap-1.5">
<Label htmlFor={`param-${name}`} className="font-mono text-xs">
{name}
</Label>
{dtype === "bool" ? (
<Select
value={values[name] === true ? "true" : "false"}
onValueChange={(next) =>
setValues({ ...values, [name]: next === "true" })
}
>
<SelectTrigger id={`param-${name}`} className="text-sm">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="true">true</SelectItem>
<SelectItem value="false">false</SelectItem>
</SelectContent>
</Select>
) : (
<Input
id={`param-${name}`}
value={asText(values[name])}
placeholder={
dtype === "artifact"
? "@run:<id>.<output> or sha256:…"
: `${dtype ?? "float"} or @run:<id>.<output>`
}
className="text-sm"
onChange={(event) =>
setValues({
...values,
[name]: parseByDtype(dtype, event.target.value),
})
}
/>
)}
</div>
)
})}
</div>
<ParamFields inputs={inputs} values={values} onChange={setValues} />
<DialogFooter>
<Button variant="outline" onClick={() => onOpenChange(false)}>
@@ -125,15 +153,7 @@ export function RunDialog({
variant="brand"
disabled={pending}
data-testid="submit-run"
onClick={() =>
// A parameter nobody filled in keeps its declared value, which is
// what leaving it out means.
onRun(
Object.fromEntries(
Object.entries(values).filter(([, value]) => value !== null),
),
)
}
onClick={() => onRun(parseParams(inputs, values))}
>
Run
</Button>
@@ -142,3 +162,22 @@ export function RunDialog({
</Dialog>
)
}
/**
* The fields as the engine takes them.
*
* A field nobody filled in is left out, which is what keeps its declared
* value — an empty parameter is not the same as a zero.
*/
export function parseParams(
inputs: FlowInput_Input[],
values: Record<string, string>,
): Record<string, unknown> {
const params: Record<string, unknown> = {}
for (const declared of inputs) {
const name = declared.spec?.name ?? ""
const parsed = parseByDtype(declared.spec?.dtype, values[name] ?? "")
if (parsed !== null) params[name] = parsed
}
return params
}