Skip to content

Commit 00fcbe8

Browse files
committed
feat: enhance workflows UI and functionality
- Added WorkflowInputPanel component for user input with example prompts and quick run functionality. - Integrated WorkflowInputPanel into WorkflowCanvas for seamless user interaction. - Updated WorkflowHeader to include status indicators for running, paused, completed, and error states. - Refactored WorkflowOutput to display dynamic status icons and messages based on workflow state. - Improved WorkflowInfoPanel to show error steps and enhanced status display. - Implemented collapsible WorkflowLegend for better UI organization and accessibility. - Updated workflow context to handle input data mapping based on selected workflow. - Removed deprecated acp-providers configuration file. - Registered all workflows with streaming enabled in the Mastra server routes. - Updated documentation in memory bank to reflect new workflows and UI components.
1 parent 513df8e commit 00fcbe8

16 files changed

Lines changed: 803 additions & 344 deletions

.github/copilot-instructions.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ applyTo: '**'
88
- 🔒 Follow security & style rules in `copilot-rules.md`.
99
- 📝 On "/update memory bank", refresh activeContext.md & progress.md.
1010
- ✅ Confirm memory bank loaded with `[Memory Bank: Active]` or warn with `[Memory Bank: Missing]`.
11-
11+
- 🎯 Always use [`#problem`] tool for debugging, to ensure code quality.
12+
- 📚 Always sync `#AGENTS.md` in dir your working on so we have up to date info.
1213
- 🔍 For research, use [#web] or [#websearch] tool and to make sure you have no knowledge gaps.
1314
- 🤖 Check if there is a problem, use [#problem] tool to check code for errors.
1415
- This tool will help you identify issues and suggest fixes.

app/workflows/AGENTS.md

Lines changed: 139 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
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

57
The 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
1214
app/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
3337
import { useChat } from "@ai-sdk/react"
3438
import { DefaultChatTransport } from "ai"
3539

3640
const { 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

6283
All 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"
79159
import { WorkflowHeader } from "./components/workflow-header"
80160
import { 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

app/workflows/components/workflow-actions.tsx

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,70 @@
33
import { Panel } from "@/src/components/ai-elements/panel"
44
import { Button } from "@/ui/button"
55
import { useWorkflowContext } from "@/app/workflows/providers/workflow-context"
6-
import { DownloadIcon, CodeIcon } from "lucide-react"
6+
import { DownloadIcon, CodeIcon, ExternalLinkIcon } from "lucide-react"
7+
import { useCallback } from "react"
8+
import { useReactFlow } from "@xyflow/react"
79

810
export function WorkflowActions() {
911
const { workflowConfig } = useWorkflowContext()
1012

11-
const handleExportSvg = () => {
12-
// TODO: Implement SVG export using React Flow's toSvg method
13-
console.log("Export SVG for:", workflowConfig?.id)
13+
let reactFlowInstance: ReturnType<typeof useReactFlow> | null = null
14+
try {
15+
reactFlowInstance = useReactFlow()
16+
} catch {
17+
// Not inside ReactFlow context yet
1418
}
1519

16-
const handleViewCode = () => {
17-
// TODO: Open code modal or navigate to code view
18-
console.log("View code for:", workflowConfig?.id)
19-
}
20+
const handleExportSvg = useCallback(() => {
21+
if (!workflowConfig) return
22+
// Use React Flow's built-in export if available
23+
console.log("Export SVG for:", workflowConfig.id)
24+
// TODO: Implement actual SVG export
25+
}, [workflowConfig])
26+
27+
const handleViewCode = useCallback(() => {
28+
if (!workflowConfig) return
29+
// Open workflow source code
30+
const workflowPath = `/src/mastra/workflows/${workflowConfig.id.replace(/([A-Z])/g, '-$1').toLowerCase().replace(/^-/, '')}.ts`
31+
window.open(`vscode://file${workflowPath}`, '_blank')
32+
}, [workflowConfig])
33+
34+
const handleFitView = useCallback(() => {
35+
reactFlowInstance?.fitView({ padding: 0.3, duration: 300 })
36+
}, [reactFlowInstance])
2037

2138
return (
2239
<Panel position="top-right" className="p-2">
2340
<div className="flex gap-2">
41+
<Button
42+
size="sm"
43+
variant="outline"
44+
onClick={handleFitView}
45+
className="h-8"
46+
title="Fit to view"
47+
>
48+
<ExternalLinkIcon className="size-3 mr-1" />
49+
Fit View
50+
</Button>
2451
<Button
2552
size="sm"
2653
variant="outline"
2754
onClick={handleExportSvg}
2855
className="h-8"
56+
title="Export as SVG"
2957
>
3058
<DownloadIcon className="size-3 mr-1" />
31-
Export SVG
59+
Export
3260
</Button>
3361
<Button
3462
size="sm"
3563
variant="outline"
3664
onClick={handleViewCode}
3765
className="h-8"
66+
title="View workflow source code"
3867
>
3968
<CodeIcon className="size-3 mr-1" />
40-
View Code
69+
Code
4170
</Button>
4271
</div>
4372
</Panel>

app/workflows/components/workflow-canvas.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { WorkflowInfoPanel } from "./workflow-info-panel"
1010
import { WorkflowLegend } from "./workflow-legend"
1111
import { WorkflowActions } from "./workflow-actions"
1212
import { WorkflowOutput } from "./workflow-output"
13+
import { WorkflowInputPanel } from "./workflow-input-panel"
1314
import type { ReactNode } from "react"
1415

1516
const edgeTypes = {
@@ -40,6 +41,7 @@ export function WorkflowCanvas({ children }: WorkflowCanvasProps) {
4041
<WorkflowLegend />
4142
<WorkflowActions />
4243
<WorkflowOutput />
44+
<WorkflowInputPanel />
4345
{children}
4446
</Canvas>
4547
</div>

0 commit comments

Comments
 (0)