wayflow

The editor entry point — createWorkflowEditor and the handle it returns.

The umbrella entry point. createWorkflowEditor mounts the editor into an element and returns a handle you drive it with.

createWorkflowEditor(element, options?)

Mounts the editor into element and returns a WorkflowEditor.

editor.ts ts
const editor = createWorkflowEditor(element, { mode: 'preview' })

Options

OptionTypeDefaultNotes
mode'edit' / 'read-only' / 'preview''edit'Which surface to show. See Editor modes.
previewPreviewOptionsExtras honored in preview mode (footer, key button, theme toggle, zoom).
nodeTypesRecord<string, NodeTypeDefinition>built-insThe node types available; spread BUILTIN_NODE_TYPES to extend. See Custom node types.
portTypesRecord<string, PortTypeDefinition>built-insColors and labels for data types.
nodeRenderersRecord<string, NodeContentRenderer>Custom rendering for a node’s body on the canvas.
uiEditorUIOptions / falseHeader, palette, panels, and toolbar. See Layout & header.
onRunOnRunCallbackRuns the workflow; its presence is what shows the Run button. See Running workflows.
onReady() => voidCalled once the editor has mounted.
graphGraphemptyThe initial graph.
viewportViewportThe initial pan and zoom.
persistencePersistenceConfigAutosave and load. See Persistence.
showPortLabelsbooleantrueShow labels beside ports.
llm{ models?: ModelsOption }Models offered to LLM nodes. See Providers & models.
imageGeneration{ models?: ModelsOption }Models offered to Image Generation nodes.
toolsRecord<string, ToolMetadata>Tools selectable on LLM nodes. See Tools.
theme'auto' / 'light' / 'dark''auto'Color theme. See Theming.
iconsRecord<string, string>Override node-type icons (SVG path data).
renderResultFieldRenderResultFieldCustom rendering for a result field. See Custom result rendering.
renderMarkdownRenderMarkdownRender markdown-format string fields.
loggerLoggerA diagnostics sink. See Debugging.
debugbooleanfalseShorthand for a console logger.

The WorkflowEditor handle

The handle returned by createWorkflowEditor — for driving the editor after mount.

Graph

MethodNotes
getGraph(): GraphA structural clone of the current graph. Captured node refs are snapshots.
export(): stringSerialize the graph to a JSON string.
import(json: string): voidReplace the graph from a JSON string.
getMetadata(): GraphMetadataThe graph’s name, description, and other metadata.
setMetadata(updates): voidPatch the metadata.

Editing

MethodNotes
addNode(options): NodeAdd a node and return it. options: { type, position, data? }.
removeNode(nodeId): voidRemove the node and any edges connected to it.
addEdge(options)options: { sourceNodeId, sourcePortId, targetNodeId, targetPortId }. Returns the new Edge, or null if the connection is invalid.
removeEdge(edgeId): voidRemove the edge between two ports.
updateNodeData(nodeId, updates): voidPatch a node’s config data.
setNodeName(nodeId, name): voidSet or clear a node’s display name.
setNodePorts(nodeId, ports): voidReplace a node’s ports — for custom node types whose ports change with their config.
renamePort(nodeId, oldPortId, newPortId): voidRename a port, keeping its connected edges.
updateNodePreview(nodeId, preview): voidSet or clear the small data preview shown on a node.
beginRename(nodeId): voidStart an inline rename in the UI.

Selection & clipboard

MethodNotes
getSelection(): SelectionThe currently selected node ids.
selectNodes(nodeIds): void / selectAll(): voidReplace the current selection.
copySelection(): void / cutSelection(): voidCopy or cut the selection to the clipboard.
paste(opts?): voidPaste the clipboard, optionally at a given canvas position.
canPaste(): booleanWhether the clipboard holds something pasteable.
duplicateSelection(): void / deleteSelection(): voidDuplicate or delete the selected nodes.

History

MethodNotes
undo(): void / redo(): voidStep backward or forward through edit history.
canUndo(): boolean / canRedo(): booleanWhether an undo or redo is available — e.g. to enable a button.
clearHistory(): voidDrop all undo history.
untracked(fn): voidRun mutations without adding a history entry.

Viewport

MethodNotes
getViewport(): Viewport / setViewport(partial): voidRead or patch the pan and zoom — { x, y, zoom }.
screenToCanvas(x, y): PositionMap a screen point to canvas coordinates.
zoomIn(): void / zoomOut(): void / fitView(padding?): voidZoom in or out, or fit all nodes in view.
focusNode(nodeId): voidCenter and select a node.
getContainer(): HTMLElementThe editor’s mount element.

Models & approvals

MethodNotes
setModels({ llm?, imageGeneration? }): voidSet selectable models after creation (e.g. once fetched).
onModelsChange(cb): () => voidSubscribe; returns an unsubscribe function.
getModelAvailability(type)Returns { available, loading, reason? }, or undefined for types without a model.
requestApproval(request)Show the approval card. request: { nodeId, instructions, data }; resolves with { approved, data }, or null if cancelled. See Human-in-the-loop.
runSession(fn): Promise<void>Run a function inside the cancellable run UI.

Persistence & lifecycle

MethodNotes
getPersistenceState()The current save status, or null if no persistence is configured.
save(): Promise<void>Trigger a save now.
destroy(): voidTear down the editor and release resources.

Events

editor.on(type, callback) subscribes and returns an unsubscribe function.

EventPayloadFires when
changeGraphAny change to the graph.
selectionChangeSelectionThe selection changes.
dataChange{ nodeId, data }A node’s config changes.
edgeAdd / edgeRemove{ edge }An edge is added or removed.
metadataChange{ metadata }The name or description changes.
nameChange{ nodeId, name }A node is renamed.
viewportChange{ viewport }Pan or zoom changes.
nodeDragStart / nodeDragEndA node drag begins or ends.
render{ nodeIds }Nodes re-render.
persistenceStateChangePersistenceStateThe save status changes.
persistenceError{ phase, error }A save or load fails.
contextmenu{ nodeId?, selectionSize, canPaste, … }A context menu is requested.