Flows and dashboards are created by POST under an issued or superuser-pinned id; PUT only updates; deleted flows leave a tombstone with their key; the controller stores by id and runs by key, hooks live under /hooks/<flow id>; a key with state or queued work behind it is refused until cleared

This commit is contained in:
2026-11-02 17:41:23 +01:00
parent fae85f5ecb
commit 08a6376836
63 changed files with 2832 additions and 936 deletions
+84
View File
@@ -668,6 +668,29 @@ chunk. A reference may carry a \`\`meta\`\` dict — sample rate, dimensions, a
sequence number — which nothing here interprets.`
} as const;
export const DashboardCreateSchema = {
properties: {
id: {
type: 'string',
title: 'Id',
default: ''
},
name: {
type: 'string',
title: 'Name'
},
title: {
type: 'string',
title: 'Title',
default: ''
}
},
type: 'object',
required: ['name'],
title: 'DashboardCreate',
description: 'A new dashboard: one empty grid under a key, filled in by saves after.'
} as const;
export const DashboardDef_InputSchema = {
properties: {
id: {
@@ -1504,6 +1527,67 @@ export const FlavorsPublicSchema = {
title: 'FlavorsPublic'
} as const;
export const FlowCreateSchema = {
properties: {
id: {
type: 'string',
title: 'Id',
default: ''
},
name: {
type: 'string',
title: 'Name'
},
title: {
type: 'string',
title: 'Title',
default: ''
},
nodes: {
items: {
'$ref': '#/components/schemas/NodeDef-Input'
},
type: 'array',
title: 'Nodes'
},
inputs: {
items: {
'$ref': '#/components/schemas/FlowInput-Input'
},
type: 'array',
title: 'Inputs'
},
mode: {
type: 'string',
enum: ['live', 'batch'],
title: 'Mode',
default: 'live'
},
outputs: {
items: {
type: 'string'
},
type: 'array',
title: 'Outputs'
},
origin: {
anyOf: [
{
'$ref': '#/components/schemas/FlowOrigin'
},
{
type: 'null'
}
]
}
},
type: 'object',
required: ['name'],
title: 'FlowCreate',
description: `A new flow as a client hands it over: a document but for what the
server owns. The fields mean what they do on \`FlowDef\`, but \`\`id\`\`.`
} as const;
export const FlowDef_InputSchema = {
properties: {
id: {
File diff suppressed because one or more lines are too long
+77 -42
View File
@@ -168,6 +168,15 @@ export type ControlWatch = {
node?: string;
};
/**
* A new dashboard: one empty grid under a key, filled in by saves after.
*/
export type DashboardCreate = {
id?: string;
name: string;
title?: string;
};
/**
* A dashboard as stored, and as the API hands it over.
*/
@@ -424,6 +433,23 @@ export type FlavorUpdate = {
description?: (string | null);
};
/**
* A new flow as a client hands it over: a document but for what the
* server owns. The fields mean what they do on `FlowDef`, but ``id``.
*/
export type FlowCreate = {
id?: string;
name: string;
title?: string;
nodes?: Array<NodeDef_Input>;
inputs?: Array<FlowInput_Input>;
mode?: 'live' | 'batch';
outputs?: Array<(string)>;
origin?: (FlowOrigin | null);
};
export type mode = 'live' | 'batch';
/**
* One atomic flow.
*/
@@ -448,11 +474,6 @@ export type FlowDef_Input = {
origin?: (FlowOrigin | null);
};
/**
* A live flow reacts to what arrives: its subscriptions, schedules and webhooks run until it is stopped. A batch flow only runs when a run asks it to, from its inputs to its outputs, and is never activated.
*/
export type mode = 'live' | 'batch';
/**
* One atomic flow.
*/
@@ -1846,55 +1867,59 @@ export type ConnectorsDeleteConnectorStateData = {
export type ConnectorsDeleteConnectorStateResponse = (Message);
export type DashboardsReadDashboardsResponse = (DashboardsPublic);
export type DashboardsReadDashboardData = {
draft?: boolean;
name: string;
export type DashboardsReadDashboardsData = {
name?: (string | null);
};
export type DashboardsReadDashboardResponse = (DashboardDef_Output);
export type DashboardsReadDashboardsResponse = (DashboardsPublic);
export type DashboardsCreateDashboardData = {
name: string;
requestBody: DashboardCreate;
};
export type DashboardsCreateDashboardResponse = (DashboardDef_Output);
export type DashboardsReadDashboardData = {
dashboardId: string;
draft?: boolean;
};
export type DashboardsReadDashboardResponse = (DashboardDef_Output);
export type DashboardsSaveDashboardData = {
name: string;
dashboardId: string;
requestBody: DashboardDef_Input;
};
export type DashboardsSaveDashboardResponse = (DashboardDef_Output);
export type DashboardsDeleteDashboardData = {
name: string;
dashboardId: string;
};
export type DashboardsDeleteDashboardResponse = (Message);
export type DashboardsGenerateResultsDashboardData = {
flow: string;
flowId: string;
};
export type DashboardsGenerateResultsDashboardResponse = (DashboardDef_Output);
export type DashboardsPublishDashboardData = {
name: string;
dashboardId: string;
requestBody: fluksio__api__routes__dashboards__PublishRequest;
};
export type DashboardsPublishDashboardResponse = (DashboardDef_Output);
export type DashboardsDiscardDashboardDraftData = {
name: string;
dashboardId: string;
};
export type DashboardsDiscardDashboardDraftResponse = (DashboardDef_Output);
export type DashboardsDuplicateDashboardData = {
name: string;
dashboardId: string;
};
export type DashboardsDuplicateDashboardResponse = (DashboardDef_Output);
@@ -1994,8 +2019,18 @@ export type FlavorsDeleteFlavorData = {
export type FlavorsDeleteFlavorResponse = (Message);
export type FlowsReadFlowsData = {
name?: (string | null);
};
export type FlowsReadFlowsResponse = (FlowsPublic);
export type FlowsCreateFlowData = {
requestBody: FlowCreate;
};
export type FlowsCreateFlowResponse = (FlowDetail);
export type FlowsReadNodeTypesResponse = (Array<NodeTypeInfo>);
export type FlowsReadGraphResponse = (BrainGraph);
@@ -2010,45 +2045,45 @@ export type FlowsDeleteSharedNodeData = {
export type FlowsDeleteSharedNodeResponse = (Message);
export type FlowsReadFlowData = {
name: string;
flowId: string;
};
export type FlowsReadFlowResponse = (FlowDetail);
export type FlowsSaveFlowData = {
name: string;
flowId: string;
requestBody: FlowDef_Input;
};
export type FlowsSaveFlowResponse = (FlowDetail);
export type FlowsDeleteFlowData = {
name: string;
flowId: string;
};
export type FlowsDeleteFlowResponse = (Message);
export type FlowsPublishFlowData = {
name: string;
flowId: string;
requestBody: fluksio__api__routes__flows__PublishRequest;
};
export type FlowsPublishFlowResponse = (FlowDetail);
export type FlowsDiscardDraftData = {
name: string;
flowId: string;
};
export type FlowsDiscardDraftResponse = (FlowDetail);
export type FlowsDuplicateFlowData = {
name: string;
flowId: string;
};
export type FlowsDuplicateFlowResponse = (FlowDetail);
export type FlowsReadNodeSourceData = {
name: string;
flowId: string;
nodeId: string;
};
@@ -2056,7 +2091,7 @@ export type FlowsReadNodeSourceResponse = (NodeSource);
export type FlowsSaveNodeSourceData = {
drop?: boolean;
name: string;
flowId: string;
nodeId: string;
requestBody: NodeSource;
};
@@ -2064,7 +2099,7 @@ export type FlowsSaveNodeSourceData = {
export type FlowsSaveNodeSourceResponse = (NodeSourceSaved);
export type FlowsShareNodeData = {
name: string;
flowId: string;
nodeId: string;
requestBody: ShareRequest;
};
@@ -2072,57 +2107,57 @@ export type FlowsShareNodeData = {
export type FlowsShareNodeResponse = (FlowDetail);
export type FlowsUnshareNodeData = {
name: string;
flowId: string;
nodeId: string;
};
export type FlowsUnshareNodeResponse = (FlowDetail);
export type FlowsStartFlowData = {
name: string;
flowId: string;
};
export type FlowsStartFlowResponse = (FlowDetail);
export type FlowsStopFlowData = {
name: string;
flowId: string;
};
export type FlowsStopFlowResponse = (FlowDetail);
export type FlowsPauseFlowData = {
name: string;
flowId: string;
};
export type FlowsPauseFlowResponse = (Message);
export type FlowsResumeFlowData = {
name: string;
flowId: string;
};
export type FlowsResumeFlowResponse = (Message);
export type FlowsStepFlowData = {
name: string;
flowId: string;
};
export type FlowsStepFlowResponse = (Message);
export type FlowsValidateFlowData = {
name: string;
flowId: string;
};
export type FlowsValidateFlowResponse = (ValidationResult);
export type FlowsRunFlowData = {
name: string;
flowId: string;
requestBody: RunRequest;
};
export type FlowsRunFlowResponse = (FlowStatePublic);
export type FlowsTriggerNodeData = {
name: string;
flowId: string;
nodeId: string;
requestBody: TriggerRequest;
};
@@ -2130,42 +2165,42 @@ export type FlowsTriggerNodeData = {
export type FlowsTriggerNodeResponse = (FlowStatePublic);
export type FlowsCancelNodeData = {
name: string;
flowId: string;
nodeId: string;
};
export type FlowsCancelNodeResponse = (Message);
export type FlowsAcknowledgeNodeErrorData = {
name: string;
flowId: string;
nodeId: string;
};
export type FlowsAcknowledgeNodeErrorResponse = (Message);
export type FlowsTrainNodeData = {
name: string;
flowId: string;
nodeId: string;
};
export type FlowsTrainNodeResponse = (Training);
export type FlowsReadTrainingData = {
name: string;
flowId: string;
nodeId: string;
};
export type FlowsReadTrainingResponse = ((Training | null));
export type FlowsReadFlowStateData = {
name: string;
flowId: string;
};
export type FlowsReadFlowStateResponse = (FlowStatePublic);
export type FlowsReadMessageHistoryData = {
flowId: string;
message: string;
name: string;
};
export type FlowsReadMessageHistoryResponse = (MessageHistory);
@@ -484,7 +484,8 @@ export function DashboardEditor({
}
const remove = useMutation({
mutationFn: () => DashboardsService.deleteDashboard({ name: draft.name }),
mutationFn: () =>
DashboardsService.deleteDashboard({ dashboardId: draft.name }),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: dashboardKeys.all })
navigate({ to: "/dashboards" })
+5 -4
View File
@@ -28,7 +28,7 @@ export const dashboardsQueryOptions = () => ({
*/
export const dashboardQueryOptions = (name: string, draft = false) => ({
queryKey: dashboardKeys.detail(name, draft),
queryFn: () => DashboardsService.readDashboard({ name, draft }),
queryFn: () => DashboardsService.readDashboard({ dashboardId: name, draft }),
})
/** Every message any flow declares — what a widget can be pointed at. */
@@ -50,7 +50,7 @@ export function useSaveDashboard(name: string) {
const queryClient = useQueryClient()
return useMutation({
mutationFn: (body: DashboardDef_Input) =>
DashboardsService.saveDashboard({ name, requestBody: body }),
DashboardsService.saveDashboard({ dashboardId: name, requestBody: body }),
onSuccess: (saved) => {
queryClient.setQueryData(dashboardKeys.detail(name, true), saved)
queryClient.invalidateQueries({ queryKey: dashboardKeys.all })
@@ -64,7 +64,7 @@ export function usePublishDashboard(name: string) {
return useMutation({
mutationFn: (version: number) =>
DashboardsService.publishDashboard({
name,
dashboardId: name,
requestBody: { version },
}),
onSuccess: (published) => {
@@ -79,7 +79,8 @@ export function usePublishDashboard(name: string) {
export function useDiscardDashboardDraft(name: string) {
const queryClient = useQueryClient()
return useMutation({
mutationFn: () => DashboardsService.discardDashboardDraft({ name }),
mutationFn: () =>
DashboardsService.discardDashboardDraft({ dashboardId: name }),
onSuccess: (published) => {
queryClient.setQueryData(dashboardKeys.detail(name, true), published)
queryClient.setQueryData(dashboardKeys.detail(name), published)
@@ -840,7 +840,7 @@ export function UseInFlow({
const flows = data?.data ?? []
const place = useMutation({
mutationFn: async (flowName: string) => {
const { definition } = await FlowsService.readFlow({ name: flowName })
const { definition } = await FlowsService.readFlow({ flowId: flowName })
const nodes = definition.nodes ?? []
const existing = deviceNodeOf(nodes, device.id)
const node = existing ?? {
@@ -854,7 +854,7 @@ export function UseInFlow({
const placed = port ? withPort(node, port) : node
if (placed !== existing) {
await FlowsService.saveFlow({
name: flowName,
flowId: flowName,
requestBody: {
...definition,
nodes: existing
@@ -64,7 +64,7 @@ export function EdgeInspector({
const replay = useMutation({
mutationFn: (value: unknown) =>
FlowsService.triggerNode({
name: flow,
flowId: flow,
nodeId: edge?.sourceId ?? "",
requestBody: { values: { [edge?.message ?? ""]: value } },
}),
+9 -9
View File
@@ -861,7 +861,7 @@ function FlowEditorInner({
const runMutation = useMutation({
mutationFn: (inputs: Record<string, unknown> = {}) =>
FlowsService.runFlow({ name: flowName, requestBody: { inputs } }),
FlowsService.runFlow({ flowId: flowName, requestBody: { inputs } }),
onSuccess: (state) => {
liveStore.setValues(
Object.fromEntries(
@@ -892,8 +892,8 @@ function FlowEditorInner({
const enableMutation = useMutation({
mutationFn: (next: boolean) =>
next
? FlowsService.startFlow({ name: flowName })
: FlowsService.stopFlow({ name: flowName }),
? FlowsService.startFlow({ flowId: flowName })
: FlowsService.stopFlow({ flowId: flowName }),
onSuccess: (detail) => {
queryClient.setQueryData(flowKeys.detail(flowName), detail)
queryClient.invalidateQueries({ queryKey: flowKeys.all, exact: true })
@@ -904,14 +904,14 @@ function FlowEditorInner({
const pauseMutation = useMutation({
mutationFn: (next: boolean) =>
next
? FlowsService.pauseFlow({ name: flowName })
: FlowsService.resumeFlow({ name: flowName }),
? FlowsService.pauseFlow({ flowId: flowName })
: FlowsService.resumeFlow({ flowId: flowName }),
// The engine answers with a flow_paused event, which is what the dock reads.
onError: () => showErrorToast("The flow could not be paused."),
})
const stepMutation = useMutation({
mutationFn: () => FlowsService.stepFlow({ name: flowName }),
mutationFn: () => FlowsService.stepFlow({ flowId: flowName }),
// Says which node ran, or that nothing was held back — both are answers.
onSuccess: (result) => showSuccessToast(result.message),
onError: () => showErrorToast("The flow could not be stepped."),
@@ -919,7 +919,7 @@ function FlowEditorInner({
const deleteMutation = useMutation({
mutationFn: async (withRuns: boolean) => {
await FlowsService.deleteFlow({ name: flowName })
await FlowsService.deleteFlow({ flowId: flowName })
// After the flow, which is refused while a run is live, so a refusal
// leaves both standing.
if (withRuns)
@@ -947,7 +947,7 @@ function FlowEditorInner({
// draft, so the ports on the canvas have to be there first.
await flush()
return FlowsService.saveNodeSource({
name: flowName,
flowId: flowName,
nodeId,
requestBody: { code },
drop,
@@ -1227,7 +1227,7 @@ function FlowEditorInner({
.filter((node) => !node.source_ref && sourceTypes.has(node.type ?? ""))
.map(async (node) => {
const { code } = await FlowsService.readNodeSource({
name: flowName,
flowId: flowName,
nodeId: node.id,
})
sources[node.id] = code
+1 -1
View File
@@ -278,7 +278,7 @@ function FlowNodeComponent({ data, selected }: NodeProps) {
// Best effort by nature: it may well have finished between
// the render and the click, which is the outcome asked for.
FlowsService.cancelNode({
name: flow,
flowId: flow,
nodeId: definition.id,
}).catch(() => {})
}}
+5 -4
View File
@@ -1647,7 +1647,7 @@ function SharingSection({
const share = useMutation({
mutationFn: (libName: string) =>
FlowsService.shareNode({
name: flow,
flowId: flow,
nodeId: node.id,
requestBody: { lib_name: libName },
}),
@@ -1657,7 +1657,8 @@ function SharingSection({
})
const unshare = useMutation({
mutationFn: () => FlowsService.unshareNode({ name: flow, nodeId: node.id }),
mutationFn: () =>
FlowsService.unshareNode({ flowId: flow, nodeId: node.id }),
onSuccess: done,
onError: () => showErrorToast("The node could not be unshared."),
})
@@ -1749,13 +1750,13 @@ function TrainingSection({
const queryKey = ["wren-training", flow, node.id]
const { data: training } = useQuery({
queryKey,
queryFn: () => FlowsService.readTraining({ name: flow, nodeId: node.id }),
queryFn: () => FlowsService.readTraining({ flowId: flow, nodeId: node.id }),
// Training takes minutes, so only a run still going is read again.
refetchInterval: (query) =>
query.state.data && isLive(query.state.data.status) ? 5_000 : false,
})
const train = useMutation({
mutationFn: () => FlowsService.trainNode({ name: flow, nodeId: node.id }),
mutationFn: () => FlowsService.trainNode({ flowId: flow, nodeId: node.id }),
onMutate: () => setProblem(null),
onSuccess: () => queryClient.invalidateQueries({ queryKey }),
onError: handleError.bind(setProblem),
+7 -7
View File
@@ -36,7 +36,7 @@ export const flowsQueryOptions = () => ({
export const flowQueryOptions = (name: string) => ({
queryKey: flowKeys.detail(name),
queryFn: () => FlowsService.readFlow({ name }),
queryFn: () => FlowsService.readFlow({ flowId: name }),
})
/** Names of the stored secrets, for pointing a credential parameter at one. */
@@ -71,13 +71,13 @@ export const nodeTypesQueryOptions = () => ({
export const nodeSourceQueryOptions = (name: string, nodeId: string) => ({
queryKey: flowKeys.source(name, nodeId),
queryFn: () => FlowsService.readNodeSource({ name, nodeId }),
queryFn: () => FlowsService.readNodeSource({ flowId: name, nodeId }),
})
/** The recent values of one message, for the panel's sparkline. */
export const messageHistoryQueryOptions = (name: string, message: string) => ({
queryKey: flowKeys.history(name, message),
queryFn: () => FlowsService.readMessageHistory({ name, message }),
queryFn: () => FlowsService.readMessageHistory({ flowId: name, message }),
})
/** Other flows change rarely; suggestions do not need them fresh to the second. */
@@ -134,7 +134,7 @@ export function usePublish(name: string) {
const queryClient = useQueryClient()
return useMutation({
mutationFn: (version: number) =>
FlowsService.publishFlow({ name, requestBody: { version } }),
FlowsService.publishFlow({ flowId: name, requestBody: { version } }),
onSuccess: (detail) => {
queryClient.setQueryData(flowKeys.detail(name), detail)
queryClient.invalidateQueries({ queryKey: flowKeys.all, exact: true })
@@ -146,7 +146,7 @@ export function usePublish(name: string) {
export function useDiscardDraft(name: string) {
const queryClient = useQueryClient()
return useMutation({
mutationFn: () => FlowsService.discardDraft({ name }),
mutationFn: () => FlowsService.discardDraft({ flowId: name }),
onSuccess: (detail) => {
queryClient.setQueryData(flowKeys.detail(name), detail)
queryClient.invalidateQueries({ queryKey: flowKeys.all, exact: true })
@@ -189,7 +189,7 @@ export function useAutosave(name: string): {
const mutation = useMutation({
mutationFn: (definition: FlowDef_Input) =>
FlowsService.saveFlow({
name,
flowId: name,
// 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,
@@ -254,7 +254,7 @@ export function useAutosave(name: string): {
})
return
}
const current = await FlowsService.readFlow({ name })
const current = await FlowsService.readFlow({ flowId: name })
version.current = current.definition.version ?? null
const definition = pending.current ?? sent.current
pending.current = null
+2 -2
View File
@@ -132,8 +132,8 @@ function Row({
const toggle = useMutation({
mutationFn: (next: boolean) =>
next
? FlowsService.startFlow({ name: flow.name })
: FlowsService.stopFlow({ name: flow.name }),
? FlowsService.startFlow({ flowId: flow.name })
: FlowsService.stopFlow({ flowId: flow.name }),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: flowKeys.all })
queryClient.invalidateQueries({ queryKey: flowKeys.detail(flow.name) })
@@ -59,7 +59,7 @@ export function OpenInDashboard({
const generate = useMutation({
mutationFn: (name: string) =>
DashboardsService.generateResultsDashboard({ flow: name }),
DashboardsService.generateResultsDashboard({ flowId: name }),
onSuccess: (made) => {
client.invalidateQueries({ queryKey: dashboardKeys.all })
show(made.name)
@@ -46,7 +46,7 @@ function Dashboards() {
const create = useMutation({
mutationFn: (dashboard: string) =>
DashboardsService.createDashboard({ name: dashboard }),
DashboardsService.createDashboard({ requestBody: { name: dashboard } }),
onSuccess: (created) => {
queryClient.invalidateQueries({ queryKey: dashboardKeys.all })
setDialogOpen(false)
@@ -64,7 +64,7 @@ function Dashboards() {
const publishAll = usePublishAll(
(dashboard) =>
DashboardsService.publishDashboard({
name: dashboard,
dashboardId: dashboard,
requestBody: {
version: data?.data.find((d) => d.name === dashboard)?.version ?? 1,
},
@@ -88,13 +88,15 @@ function Dashboards() {
const selection = useSelection(dashboards.map((dashboard) => dashboard.name))
const remove = useDeleteSelected(
(dashboard) => DashboardsService.deleteDashboard({ name: dashboard }),
(dashboard) =>
DashboardsService.deleteDashboard({ dashboardId: dashboard }),
"dashboard",
() => queryClient.invalidateQueries({ queryKey: dashboardKeys.all }),
)
const duplicate = useDuplicateSelected(
(dashboard) => DashboardsService.duplicateDashboard({ name: dashboard }),
(dashboard) =>
DashboardsService.duplicateDashboard({ dashboardId: dashboard }),
"dashboard",
() => {
selection.clear()
+4 -4
View File
@@ -50,7 +50,7 @@ function Flows() {
const create = useMutation({
mutationFn: (flow: string) =>
FlowsService.saveFlow({
name: flow,
flowId: flow,
requestBody: { name: flow, nodes: [], inputs: [] },
}),
onSuccess: (_saved, flow) => {
@@ -66,7 +66,7 @@ function Flows() {
const publishAll = usePublishAll(
(flow) =>
FlowsService.publishFlow({
name: flow,
flowId: flow,
requestBody: {
version: data?.data.find((f) => f.name === flow)?.version ?? 1,
},
@@ -90,7 +90,7 @@ function Flows() {
const selection = useSelection(flows.map((flow) => flow.name))
const remove = useDeleteSelected(
async (flow) => {
await FlowsService.deleteFlow({ name: flow })
await FlowsService.deleteFlow({ flowId: flow })
if (withRuns) await RunsService.deleteRuns({ flow, history: true })
},
"flow",
@@ -98,7 +98,7 @@ function Flows() {
)
const duplicate = useDuplicateSelected(
(flow) => FlowsService.duplicateFlow({ name: flow }),
(flow) => FlowsService.duplicateFlow({ flowId: flow }),
"flow",
() => {
selection.clear()