11# Workflows Feature
22
3+ <!-- AGENTS-META {"title":"Workflows Visualization","version":"1.1.0","applies_to":"app/workflows/","last_updated":"2025-12-04T00:00:00Z","status":"stable"} -->
4+
35## Overview
46
57The workflows page provides an interactive visualization of Mastra workflows using AI Elements components (Canvas, Node, Edge, Panel, Controls, Toolbar, Connection) with real-time streaming via ` @ai-sdk/react ` and ` @mastra/ai-sdk ` .
@@ -10,67 +12,145 @@ Follows the same modular pattern as the chat feature:
1012
1113``` text
1214app/workflows/
13- ├── page.tsx # Main page component (clean, minimal)
15+ ├── page.tsx # Main page component (clean, minimal)
16+ ├── AGENTS.md # This documentation file
1417├── config/
15- │ └── workflows.ts # Workflow definitions and types
18+ │ └── workflows.ts # Workflow definitions and types (10 workflows)
1619├── providers/
17- │ └── workflow-context.tsx # State management with useChat
20+ │ └── workflow-context.tsx # State management with useChat + DefaultChatTransport
1821└── components/
19- ├── workflow-header.tsx # Header with workflow selector
20- ├── workflow-canvas.tsx # React Flow canvas wrapper
21- ├── workflow-node.tsx # Custom node component
22- ├── workflow-info-panel.tsx # Info panel (top-left)
23- ├── workflow-legend.tsx # Legend panel (bottom-left)
24- ├── workflow-actions.tsx # Actions panel (top-right)
25- └── workflow-output.tsx # Streaming output panel (bottom-right)
22+ ├── workflow-header.tsx # Header with workflow selector + status badges
23+ ├── workflow-canvas.tsx # React Flow canvas wrapper
24+ ├── workflow-node.tsx # Custom node component with status indicators
25+ ├── workflow-info-panel.tsx # Info panel (top-left) - name, description, progress
26+ ├── workflow-legend.tsx # Collapsible legend panel (top-right)
27+ ├── workflow-actions.tsx # Actions panel (top-right) - fit view, export, code
28+ ├── workflow-input-panel.tsx # Input panel (bottom-left) - query input + examples
29+ └── workflow-output.tsx # Streaming output panel (bottom-right)
2630```
2731
2832## AI SDK Integration
2933
30- Uses ` useChat ` from ` @ai-sdk/react ` with ` DefaultChatTransport ` to connect to Mastra's ` /workflow ` route :
34+ Uses ` useChat ` from ` @ai-sdk/react ` with ` DefaultChatTransport ` to connect to Mastra's ` /workflow/:workflowId ` routes :
3135
3236``` tsx
3337import { useChat } from " @ai-sdk/react"
3438import { DefaultChatTransport } from " ai"
3539
3640const { messages, sendMessage, stop, status } = useChat ({
3741 transport: new DefaultChatTransport ({
38- api: " http://localhost:4111/workflow" ,
42+ api: ` http://localhost:4111/workflow/${ selectedWorkflow } ` ,
3943 prepareSendMessagesRequest({ messages }) {
40- return {
41- body: {
42- inputData: { workflowId , input: messages [messages .length - 1 ]?.parts ?.[0 ]?.text },
43- },
44- }
44+ const inputText = messages [messages .length - 1 ]?.parts ?.[0 ]?.text ?? " "
45+ const inputData = buildWorkflowInputData (selectedWorkflow , inputText )
46+ return { body: { inputData } }
4547 },
4648 }),
4749})
4850```
4951
50- ## AI Elements Used
51-
52- - ** Canvas** : React Flow wrapper with pre-configured defaults
53- - ** Node** : Card-based node with header, content, footer
54- - ** Edge** : Animated and temporary edge types
55- - ** Panel** : Positioned panels for UI overlays
56- - ** Controls** : Zoom/pan controls
57- - ** Toolbar** : Node-attached toolbar with actions
58- - ** Connection** : Custom bezier curve connection lines
52+ ### Input Data Mapping
53+
54+ Each workflow expects specific input fields:
55+
56+ | Workflow | Input Field | Example |
57+ | ----------| -------------| ---------|
58+ | weatherWorkflow | ` { city } ` | "San Francisco" |
59+ | contentStudioWorkflow | ` { topic } ` | "AI trends 2025" |
60+ | stockAnalysisWorkflow | ` { symbol } ` | "AAPL" |
61+ | financialReportWorkflow | ` { symbol } ` | "TSLA" |
62+ | researchSynthesisWorkflow | ` { topic } ` | "ML best practices" |
63+ | documentProcessingWorkflow | ` { documentPath } ` | "./docs/report.pdf" |
64+ | telephoneGameWorkflow | ` { message } ` | "Hello world" |
65+ | changelogWorkflow | ` { repository } ` | "main..HEAD" |
66+ | contentReviewWorkflow | ` { content } ` | "Your content here" |
67+ | learningExtractionWorkflow | ` { content } ` | "Text to analyze" |
68+
69+ ## AI Elements Components Used
70+
71+ | Component | Purpose |
72+ | -----------| ---------|
73+ | ** Canvas** | React Flow wrapper with pre-configured defaults |
74+ | ** Node** | Card-based node with header, content, footer |
75+ | ** Edge** | Animated (active) and temporary (pending) edge types |
76+ | ** Panel** | Positioned panels for UI overlays |
77+ | ** Controls** | Zoom/pan controls |
78+ | ** Toolbar** | Node-attached toolbar with actions |
79+ | ** Connection** | Custom bezier curve connection lines |
5980
6081## Workflow Configuration
6182
6283All 10 Mastra workflows are configured in ` config/workflows.ts ` :
6384
64- - weatherWorkflow
65- - contentStudioWorkflow
66- - contentReviewWorkflow
67- - documentProcessingWorkflow
68- - financialReportWorkflow
69- - learningExtractionWorkflow
70- - researchSynthesisWorkflow
71- - stockAnalysisWorkflow
72- - telephoneGameWorkflow
73- - changelogWorkflow
85+ | Workflow | Category | Steps |
86+ | ----------| ----------| -------|
87+ | weatherWorkflow | utility | 2 |
88+ | contentStudioWorkflow | content | 8 |
89+ | contentReviewWorkflow | content | 3 |
90+ | documentProcessingWorkflow | data | 4 |
91+ | financialReportWorkflow | financial | 4 |
92+ | learningExtractionWorkflow | research | 3 |
93+ | researchSynthesisWorkflow | research | 4 |
94+ | stockAnalysisWorkflow | financial | 4 |
95+ | telephoneGameWorkflow | utility | 5 |
96+ | changelogWorkflow | utility | 3 |
97+
98+ ## Context API
99+
100+ ` useWorkflowContext() ` provides:
101+
102+ ``` tsx
103+ interface WorkflowContextValue {
104+ // State
105+ selectedWorkflow: WorkflowId
106+ workflowConfig: WorkflowConfig | undefined
107+ workflowStatus: " idle" | " running" | " paused" | " completed" | " error"
108+ currentRun: WorkflowRun | null
109+ activeStepIndex: number
110+
111+ // Actions
112+ selectWorkflow: (workflowId : WorkflowId ) => void
113+ runWorkflow: (inputData ? : Record <string , unknown >) => void
114+ pauseWorkflow: () => void
115+ resumeWorkflow: () => void
116+ stopWorkflow: () => void
117+ runStep: (stepId : string ) => Promise <void >
118+ getStepStatus: (stepId : string ) => StepStatus
119+
120+ // React Flow data
121+ nodes: WorkflowNode []
122+ edges: WorkflowEdge []
123+
124+ // Streaming
125+ messages: UIMessage []
126+ streamingOutput: string
127+ }
128+ ```
129+
130+ ## Panel Layout
131+
132+ ``` text
133+ ┌─────────────────────────────────────────────────────────────┐
134+ │ [Info Panel] [Actions] [Legend] │
135+ │ - Workflow name Fit / Export │
136+ │ - Description Code / Legend │
137+ │ - Progress & status │
138+ ├─────────────────────────────────────────────────────────────┤
139+ │ │
140+ │ [Canvas with Nodes] │
141+ │ │
142+ │ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ │
143+ │ │Step │ ──── │Step │ ──── │Step │ ──── │Step │ │
144+ │ │ 1 │ │ 2 │ │ 3 │ │ N │ │
145+ │ └─────┘ └─────┘ └─────┘ └─────┘ │
146+ │ │
147+ ├─────────────────────────────────────────────────────────────┤
148+ │ [Input Panel] [Output Panel] │
149+ │ - Placeholder by category - Status icon │
150+ │ - Example inputs - Streaming text │
151+ │ - Quick Run button - Message history │
152+ └─────────────────────────────────────────────────────────────┘
153+ ```
74154
75155## Usage
76156
@@ -79,21 +159,30 @@ import { WorkflowProvider } from "./providers/workflow-context"
79159import { WorkflowHeader } from " ./components/workflow-header"
80160import { WorkflowCanvas } from " ./components/workflow-canvas"
81161
82- <WorkflowProvider defaultWorkflow = " contentStudioWorkflow" >
83- <WorkflowHeader />
84- <WorkflowCanvas />
85- </WorkflowProvider >
162+ export default function WorkflowsPage() {
163+ return (
164+ <WorkflowProvider defaultWorkflow = " contentStudioWorkflow" >
165+ <main className = " flex h-screen flex-col bg-background" >
166+ <WorkflowHeader />
167+ <WorkflowCanvas />
168+ </main >
169+ </WorkflowProvider >
170+ )
171+ }
86172```
87173
88- ## Context API
174+ ## Server Routes (Mastra)
89175
90- ` useWorkflowContext() ` provides:
176+ The workflows connect to these routes in ` src/mastra/index.ts ` :
177+
178+ ``` typescript
179+ workflowRoute ({
180+ path: " /workflow" ,
181+ workflow: " weatherWorkflow" ,
182+ includeTextStreamParts: true ,
183+ }),
184+ // ... repeated for all 10 workflows
185+ ```
91186
92- - ` selectedWorkflow ` - Currently selected workflow ID
93- - ` workflowConfig ` - Current workflow configuration
94- - ` workflowStatus ` - idle | running | paused | completed | error
95- - ` nodes ` / ` edges ` - Generated React Flow nodes and edges
96- - ` runWorkflow(inputData?) ` - Execute via AI SDK streaming
97- - ` stopWorkflow() ` - Stop the streaming workflow
98- - ` messages ` - AI SDK message history
99- - ` streamingOutput ` - Current streaming text output
187+ ---
188+ Last updated: 2025-12-04
0 commit comments