Start, stop and pause flows, and show what their nodes print
Flows can now be taken off the engine and put back. Stopped state lives in a runtime.json beside the flow, not in the flow document: the canvas autosaves that document, so a stopped flow would otherwise start itself again on the next edit. A stopped flow gets no subscriptions, schedules or webhooks, its nodes are skipped by the scheduler, and running it answers 409. Pausing holds a flow's nodes while its values keep arriving, so the canvas still shows what is coming in. Node code is user code and print is how it says things, so stdout is teed through a contextvar sink active only during a node execution — one event per execution, capped, so a chatty node cannot outrun the stream. A node that fails sends its traceback the same way, trimmed to the author's own frames. The dock gains a logs panel and a pause control; the dashboard replaces its placeholder with what is running, stopped or failing; the edge inspector can send the last message again. Single-stepping is deferred and noted: the scheduler keeps no progress between calls, so a step button would re-run the same node rather than advance. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
606ab3c423
commit
7344eac262
@@ -13,14 +13,28 @@ export type LiveStatus = {
|
||||
status: "active" | "error" | "running" | "success"
|
||||
error?: string | null
|
||||
}
|
||||
/** One node execution's output, as the log panel shows it. */
|
||||
export type LogLine = {
|
||||
flow: string
|
||||
node: string
|
||||
text: string
|
||||
level: "info" | "error"
|
||||
truncated?: boolean
|
||||
ts: number
|
||||
}
|
||||
|
||||
type Listener = () => void
|
||||
|
||||
/** Enough to see what a flow has been doing, not a log store. */
|
||||
const LOG_LIMIT = 500
|
||||
|
||||
const values = new Map<string, LiveValue>()
|
||||
const statuses = new Map<string, LiveStatus>()
|
||||
// How many times a node has emitted. The number itself means nothing; a change
|
||||
// is what restarts the pulse.
|
||||
const emits = new Map<string, number>()
|
||||
let logLines: LogLine[] = []
|
||||
const paused = new Set<string>()
|
||||
const listeners = new Map<string, Set<Listener>>()
|
||||
|
||||
let connected = false
|
||||
@@ -79,6 +93,33 @@ export const liveStore = {
|
||||
emits.set(nodeId, (emits.get(nodeId) ?? 0) + 1)
|
||||
notify(`emit:${nodeId}`)
|
||||
},
|
||||
appendLog(line: LogLine) {
|
||||
// A new array each time, so the hook's snapshot comparison sees the change.
|
||||
logLines = [...logLines, line].slice(-LOG_LIMIT)
|
||||
notify("logs")
|
||||
},
|
||||
setLogs(lines: LogLine[]) {
|
||||
logLines = lines.slice(-LOG_LIMIT)
|
||||
notify("logs")
|
||||
},
|
||||
clearLogs() {
|
||||
logLines = []
|
||||
notify("logs")
|
||||
},
|
||||
setPaused(flow: string, isPaused: boolean) {
|
||||
if (isPaused) paused.add(flow)
|
||||
else paused.delete(flow)
|
||||
notify(`paused:${flow}`)
|
||||
},
|
||||
setPausedFlows(flows: string[]) {
|
||||
const next = new Set(flows)
|
||||
for (const flow of new Set([...paused, ...next])) {
|
||||
if (paused.has(flow) === next.has(flow)) continue
|
||||
if (next.has(flow)) paused.add(flow)
|
||||
else paused.delete(flow)
|
||||
notify(`paused:${flow}`)
|
||||
}
|
||||
},
|
||||
setConnected(next: boolean) {
|
||||
if (connected === next) return
|
||||
connected = next
|
||||
@@ -94,6 +135,10 @@ export const liveStore = {
|
||||
statuses.clear()
|
||||
for (const key of emits.keys()) notify(`emit:${key}`)
|
||||
emits.clear()
|
||||
logLines = []
|
||||
notify("logs")
|
||||
for (const flow of paused) notify(`paused:${flow}`)
|
||||
paused.clear()
|
||||
},
|
||||
}
|
||||
|
||||
@@ -119,6 +164,21 @@ export function useNodeEmits(nodeId: string): number {
|
||||
)
|
||||
}
|
||||
|
||||
/** Every captured line, newest last. Filtered by the panel that shows it. */
|
||||
export function useLiveLogs(): LogLine[] {
|
||||
return useSyncExternalStore(
|
||||
(listener) => subscribeKey("logs", listener),
|
||||
() => logLines,
|
||||
)
|
||||
}
|
||||
|
||||
export function useFlowPaused(flow: string): boolean {
|
||||
return useSyncExternalStore(
|
||||
(listener) => subscribeKey(`paused:${flow}`, listener),
|
||||
() => paused.has(flow),
|
||||
)
|
||||
}
|
||||
|
||||
export function useLiveConnection(): boolean {
|
||||
return useSyncExternalStore(
|
||||
(listener) => {
|
||||
|
||||
Reference in New Issue
Block a user