@mastra/mcp-docs-server 0.13.2-alpha.1 → 0.13.2-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.docs/organized/changelogs/%40mastra%2Fastra.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +18 -18
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +15 -15
- package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +22 -22
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +21 -21
- package/.docs/organized/changelogs/%40mastra%2Flance.md +13 -0
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +9 -9
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +22 -22
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +13 -0
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +27 -27
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +14 -14
- package/.docs/organized/changelogs/mastra.md +22 -22
- package/.docs/organized/code-examples/agent.md +182 -5
- package/.docs/organized/code-examples/assistant-ui.md +1 -1
- package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +1 -1
- package/.docs/organized/code-examples/bird-checker-with-nextjs.md +1 -1
- package/.docs/organized/code-examples/crypto-chatbot.md +2 -2
- package/.docs/organized/code-examples/openapi-spec-writer.md +1 -1
- package/.docs/raw/agents/using-tools-and-mcp.mdx +3 -2
- package/.docs/raw/course/01-first-agent/04-project-structure.md +8 -3
- package/.docs/raw/course/01-first-agent/07-creating-your-agent.md +5 -3
- package/.docs/raw/course/01-first-agent/08-exporting-your-agent.md +20 -6
- package/.docs/raw/course/01-first-agent/11-creating-transactions-tool.md +5 -3
- package/.docs/raw/course/01-first-agent/12-connecting-tool-to-agent.md +2 -2
- package/.docs/raw/course/04-workflows/01-introduction-to-workflows.md +44 -0
- package/.docs/raw/course/04-workflows/02-understanding-steps.md +53 -0
- package/.docs/raw/course/04-workflows/03-creating-your-first-step.md +57 -0
- package/.docs/raw/course/04-workflows/04-creating-a-second-step.md +58 -0
- package/.docs/raw/course/04-workflows/05-chaining-steps-together.md +56 -0
- package/.docs/raw/course/04-workflows/06-registering-with-mastra.md +24 -0
- package/.docs/raw/course/04-workflows/07-using-playground.md +58 -0
- package/.docs/raw/course/04-workflows/08-running-workflows-programmatically.md +77 -0
- package/.docs/raw/course/04-workflows/09-adding-a-third-step.md +70 -0
- package/.docs/raw/course/04-workflows/10-updating-the-workflow.md +55 -0
- package/.docs/raw/course/04-workflows/11-creating-an-ai-agent.md +67 -0
- package/.docs/raw/course/04-workflows/12-using-agent-in-workflow.md +91 -0
- package/.docs/raw/course/04-workflows/13-creating-ai-enhanced-workflow.md +75 -0
- package/.docs/raw/course/04-workflows/14-understanding-parallel-execution.md +38 -0
- package/.docs/raw/course/04-workflows/15-creating-parallel-steps.md +115 -0
- package/.docs/raw/course/04-workflows/16-building-parallel-workflow.md +100 -0
- package/.docs/raw/course/04-workflows/17-testing-parallel-performance.md +40 -0
- package/.docs/raw/course/04-workflows/18-understanding-conditional-branching.md +58 -0
- package/.docs/raw/course/04-workflows/19-creating-conditional-steps.md +128 -0
- package/.docs/raw/course/04-workflows/20-building-conditional-workflow.md +60 -0
- package/.docs/raw/course/04-workflows/21-testing-conditional-logic.md +58 -0
- package/.docs/raw/course/04-workflows/22-conclusion.md +58 -0
- package/.docs/raw/deployment/cloud-providers/digital-ocean.mdx +111 -0
- package/.docs/raw/deployment/cloud-providers/index.mdx +15 -0
- package/.docs/raw/memory/working-memory.mdx +56 -0
- package/.docs/raw/networks-vnext/complex-task-execution.mdx +137 -0
- package/.docs/raw/networks-vnext/overview.mdx +85 -0
- package/.docs/raw/networks-vnext/single-task-execution.mdx +131 -0
- package/.docs/raw/reference/client-js/agents.mdx +41 -0
- package/.docs/raw/reference/deployer/netlify.mdx +22 -68
- package/.docs/raw/reference/deployer/vercel.mdx +7 -77
- package/.docs/raw/reference/tools/mcp-client.mdx +244 -0
- package/.docs/raw/reference/tools/mcp-server.mdx +186 -0
- package/.docs/raw/reference/workflows/create-run.mdx +1 -1
- package/.docs/raw/reference/workflows/resume.mdx +1 -1
- package/.docs/raw/reference/workflows/start.mdx +1 -1
- package/.docs/raw/reference/workflows/stream.mdx +1 -1
- package/.docs/raw/reference/workflows/watch.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow.mdx +6 -2
- package/.docs/raw/workflows/control-flow.mdx +42 -1
- package/.docs/raw/workflows/overview.mdx +73 -5
- package/.docs/raw/workflows/pausing-execution.mdx +1 -1
- package/.docs/raw/workflows/suspend-and-resume.mdx +68 -23
- package/.docs/raw/workflows/using-with-agents-and-tools.mdx +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# Building Parallel Workflow
|
|
2
|
+
|
|
3
|
+
Now you'll create a workflow that runs your analysis steps in parallel for maximum performance.
|
|
4
|
+
|
|
5
|
+
## Creating the Parallel Workflow
|
|
6
|
+
|
|
7
|
+
Add this workflow to your file:
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
export const parallelAnalysisWorkflow = createWorkflow({
|
|
11
|
+
id: "parallel-analysis-workflow",
|
|
12
|
+
description: "Run multiple content analyses in parallel",
|
|
13
|
+
inputSchema: z.object({
|
|
14
|
+
content: z.string(),
|
|
15
|
+
type: z.enum(["article", "blog", "social"]).default("article"),
|
|
16
|
+
}),
|
|
17
|
+
outputSchema: z.object({
|
|
18
|
+
results: z.object({
|
|
19
|
+
seo: z.object({
|
|
20
|
+
seoScore: z.number(),
|
|
21
|
+
keywords: z.array(z.string()),
|
|
22
|
+
}),
|
|
23
|
+
readability: z.object({
|
|
24
|
+
readabilityScore: z.number(),
|
|
25
|
+
gradeLevel: z.string(),
|
|
26
|
+
}),
|
|
27
|
+
sentiment: z.object({
|
|
28
|
+
sentiment: z.enum(["positive", "neutral", "negative"]),
|
|
29
|
+
confidence: z.number(),
|
|
30
|
+
}),
|
|
31
|
+
}),
|
|
32
|
+
}),
|
|
33
|
+
})
|
|
34
|
+
.parallel([seoAnalysisStep, readabilityStep, sentimentStep])
|
|
35
|
+
.then(
|
|
36
|
+
createStep({
|
|
37
|
+
id: "combine-results",
|
|
38
|
+
description: "Combines parallel analysis results",
|
|
39
|
+
inputSchema: z.object({
|
|
40
|
+
"seo-analysis": z.object({
|
|
41
|
+
seoScore: z.number(),
|
|
42
|
+
keywords: z.array(z.string()),
|
|
43
|
+
}),
|
|
44
|
+
"readability-analysis": z.object({
|
|
45
|
+
readabilityScore: z.number(),
|
|
46
|
+
gradeLevel: z.string(),
|
|
47
|
+
}),
|
|
48
|
+
"sentiment-analysis": z.object({
|
|
49
|
+
sentiment: z.enum(["positive", "neutral", "negative"]),
|
|
50
|
+
confidence: z.number(),
|
|
51
|
+
}),
|
|
52
|
+
}),
|
|
53
|
+
outputSchema: z.object({
|
|
54
|
+
results: z.object({
|
|
55
|
+
seo: z.object({
|
|
56
|
+
seoScore: z.number(),
|
|
57
|
+
keywords: z.array(z.string()),
|
|
58
|
+
}),
|
|
59
|
+
readability: z.object({
|
|
60
|
+
readabilityScore: z.number(),
|
|
61
|
+
gradeLevel: z.string(),
|
|
62
|
+
}),
|
|
63
|
+
sentiment: z.object({
|
|
64
|
+
sentiment: z.enum(["positive", "neutral", "negative"]),
|
|
65
|
+
confidence: z.number(),
|
|
66
|
+
}),
|
|
67
|
+
}),
|
|
68
|
+
}),
|
|
69
|
+
execute: async ({ inputData }) => {
|
|
70
|
+
console.log("🔄 Combining parallel results...");
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
results: {
|
|
74
|
+
seo: inputData["seo-analysis"],
|
|
75
|
+
readability: inputData["readability-analysis"],
|
|
76
|
+
sentiment: inputData["sentiment-analysis"],
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
}),
|
|
81
|
+
)
|
|
82
|
+
.commit();
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Understanding Parallel Data Flow
|
|
86
|
+
|
|
87
|
+
When steps run in parallel:
|
|
88
|
+
|
|
89
|
+
1. Each step receives the same input data
|
|
90
|
+
2. Steps execute simultaneously
|
|
91
|
+
3. Results are collected into an object with step IDs as keys
|
|
92
|
+
4. The next step receives all parallel results
|
|
93
|
+
|
|
94
|
+
## Key Points
|
|
95
|
+
|
|
96
|
+
- **`.parallel([step1, step2, step3])`**: Runs all steps simultaneously
|
|
97
|
+
- **Result object keys**: Use the step IDs (e.g., "seo-analysis")
|
|
98
|
+
- **Combine step**: Processes all parallel results together
|
|
99
|
+
|
|
100
|
+
Next, you'll test this parallel workflow and see the performance improvement!
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Testing Parallel Workflow
|
|
2
|
+
|
|
3
|
+
Let's test your parallel workflow.
|
|
4
|
+
|
|
5
|
+
## Registering the New Workflow
|
|
6
|
+
|
|
7
|
+
Update your Mastra configuration to include your new workflow workflows:
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
// In src/mastra/index.ts
|
|
11
|
+
import {
|
|
12
|
+
contentWorkflow,
|
|
13
|
+
aiContentWorkflow,
|
|
14
|
+
parallelAnalysisWorkflow,
|
|
15
|
+
} from "./workflows/content-workflow";
|
|
16
|
+
|
|
17
|
+
export const mastra = new Mastra({
|
|
18
|
+
workflows: {
|
|
19
|
+
contentWorkflow,
|
|
20
|
+
aiContentWorkflow,
|
|
21
|
+
parallelAnalysisWorkflow, // Add the parallel workflow
|
|
22
|
+
},
|
|
23
|
+
// ... rest of configuration
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Testing the Parallel Workflow
|
|
28
|
+
|
|
29
|
+
You can now test this new workflow in the Playground. You will notice that it processes the three analysis steps in parallel speeding up execution time.
|
|
30
|
+
|
|
31
|
+
## When to Use Parallel Execution
|
|
32
|
+
|
|
33
|
+
Use parallel execution when:
|
|
34
|
+
|
|
35
|
+
- Steps don't depend on each other's outputs
|
|
36
|
+
- Steps involve I/O operations (API calls, database queries)
|
|
37
|
+
- You want to maximize performance
|
|
38
|
+
- Steps process the same input data
|
|
39
|
+
|
|
40
|
+
Register your parallel workflow with Mastra to use it in the playground! Next, you'll learn about conditional branching.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Understanding Conditional Branching
|
|
2
|
+
|
|
3
|
+
Learn how to create workflows that take different paths based on data conditions, making your workflows more intelligent and adaptive.
|
|
4
|
+
|
|
5
|
+
## What is Conditional Branching?
|
|
6
|
+
|
|
7
|
+
Conditional branching allows workflows to:
|
|
8
|
+
- **Make decisions**: Choose different processing paths based on data
|
|
9
|
+
- **Handle variations**: Process different content types differently
|
|
10
|
+
- **Optimize performance**: Skip unnecessary steps for certain inputs
|
|
11
|
+
- **Customize behavior**: Provide different experiences based on conditions
|
|
12
|
+
|
|
13
|
+
## Real-World Example
|
|
14
|
+
|
|
15
|
+
Imagine a content processing workflow that:
|
|
16
|
+
- **Short content** (< 50 words): Gets quick processing
|
|
17
|
+
- **Medium content** (50-200 words): Gets standard processing
|
|
18
|
+
- **Long content** (> 200 words): Gets detailed processing with extra analysis
|
|
19
|
+
|
|
20
|
+
## Basic Branching Syntax
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
.branch([
|
|
24
|
+
[condition1, step1],
|
|
25
|
+
[condition2, step2],
|
|
26
|
+
[condition3, step3]
|
|
27
|
+
])
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Where:
|
|
31
|
+
- **condition**: An async function that returns `true` or `false`
|
|
32
|
+
- **step**: The step to execute if the condition is `true`
|
|
33
|
+
|
|
34
|
+
## Condition Functions
|
|
35
|
+
|
|
36
|
+
Conditions are functions that examine the input data:
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
// Example condition function
|
|
40
|
+
async ({ inputData }) => {
|
|
41
|
+
return inputData.wordCount < 50;
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Multiple Paths
|
|
46
|
+
|
|
47
|
+
- If multiple conditions are `true`, **all matching steps run in parallel**
|
|
48
|
+
- If no conditions are `true`, the workflow continues without executing any branch steps
|
|
49
|
+
- Conditions are evaluated in order, but matching steps run simultaneously
|
|
50
|
+
|
|
51
|
+
## Benefits
|
|
52
|
+
|
|
53
|
+
- **Smart routing**: Send data down the most appropriate path
|
|
54
|
+
- **Performance**: Skip expensive operations when not needed
|
|
55
|
+
- **Flexibility**: Handle different scenarios in one workflow
|
|
56
|
+
- **Maintainability**: Clear logic for different processing paths
|
|
57
|
+
|
|
58
|
+
Next, you'll create a workflow with conditional branches!
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# Creating Conditional Steps
|
|
2
|
+
|
|
3
|
+
Let's create two processing steps for different types of content: one for short and simple content, and one for everything else.
|
|
4
|
+
|
|
5
|
+
## Assessment Step
|
|
6
|
+
|
|
7
|
+
First, create a step that analyzes content to determine which path to take:
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
const assessContentStep = createStep({
|
|
11
|
+
id: "assess-content",
|
|
12
|
+
description: "Assesses content to determine processing path",
|
|
13
|
+
inputSchema: z.object({
|
|
14
|
+
content: z.string(),
|
|
15
|
+
type: z.enum(["article", "blog", "social"]).default("article"),
|
|
16
|
+
}),
|
|
17
|
+
outputSchema: z.object({
|
|
18
|
+
content: z.string(),
|
|
19
|
+
type: z.enum(["article", "blog", "social"]).default("article"),
|
|
20
|
+
wordCount: z.number(),
|
|
21
|
+
complexity: z.enum(["simple", "moderate", "complex"]),
|
|
22
|
+
category: z.enum(["short", "medium", "long"]),
|
|
23
|
+
}),
|
|
24
|
+
execute: async ({ inputData }) => {
|
|
25
|
+
const { content, type } = inputData;
|
|
26
|
+
const words = content.trim().split(/\s+/);
|
|
27
|
+
const wordCount = words.length;
|
|
28
|
+
|
|
29
|
+
// Determine category by length
|
|
30
|
+
let category: "short" | "medium" | "long" = "short";
|
|
31
|
+
if (wordCount >= 50) category = "medium";
|
|
32
|
+
if (wordCount >= 200) category = "long";
|
|
33
|
+
|
|
34
|
+
// Determine complexity by average word length
|
|
35
|
+
const avgWordLength =
|
|
36
|
+
words.reduce((sum, word) => sum + word.length, 0) / wordCount;
|
|
37
|
+
let complexity: "simple" | "moderate" | "complex" = "simple";
|
|
38
|
+
if (avgWordLength > 5) complexity = "moderate";
|
|
39
|
+
if (avgWordLength > 7) complexity = "complex";
|
|
40
|
+
|
|
41
|
+
console.log(`📋 Assessment: ${category} content, ${complexity} complexity`);
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
content,
|
|
45
|
+
type,
|
|
46
|
+
wordCount,
|
|
47
|
+
complexity,
|
|
48
|
+
category,
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Quick Processing Step
|
|
55
|
+
|
|
56
|
+
For short, simple content:
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
const quickProcessingStep = createStep({
|
|
60
|
+
id: "quick-processing",
|
|
61
|
+
description: "Quick processing for short and simple content",
|
|
62
|
+
inputSchema: z.object({
|
|
63
|
+
content: z.string(),
|
|
64
|
+
type: z.enum(["article", "blog", "social"]).default("article"),
|
|
65
|
+
wordCount: z.number(),
|
|
66
|
+
complexity: z.enum(["simple", "moderate", "complex"]),
|
|
67
|
+
category: z.enum(["short", "medium", "long"]),
|
|
68
|
+
}),
|
|
69
|
+
outputSchema: z.object({
|
|
70
|
+
processedContent: z.string(),
|
|
71
|
+
processingType: z.string(),
|
|
72
|
+
recommendations: z.array(z.string()),
|
|
73
|
+
}),
|
|
74
|
+
execute: async ({ inputData }) => {
|
|
75
|
+
console.log("⚡ Quick processing for short and simple content...");
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
processedContent: inputData.content,
|
|
79
|
+
processingType: "quick",
|
|
80
|
+
recommendations: [
|
|
81
|
+
"Content is concise",
|
|
82
|
+
"Consider expanding for more detail",
|
|
83
|
+
],
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## General Processing Step
|
|
90
|
+
|
|
91
|
+
For all other content (not short and simple):
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
const generalProcessingStep = createStep({
|
|
95
|
+
id: "general-processing",
|
|
96
|
+
description: "General processing for all other content",
|
|
97
|
+
inputSchema: z.object({
|
|
98
|
+
content: z.string(),
|
|
99
|
+
type: z.enum(["article", "blog", "social"]).default("article"),
|
|
100
|
+
wordCount: z.number(),
|
|
101
|
+
complexity: z.enum(["simple", "moderate", "complex"]),
|
|
102
|
+
category: z.enum(["short", "medium", "long"]),
|
|
103
|
+
}),
|
|
104
|
+
outputSchema: z.object({
|
|
105
|
+
processedContent: z.string(),
|
|
106
|
+
processingType: z.string(),
|
|
107
|
+
recommendations: z.array(z.string()),
|
|
108
|
+
}),
|
|
109
|
+
execute: async ({ inputData }) => {
|
|
110
|
+
console.log("📝 General processing for non-short/simple content...");
|
|
111
|
+
|
|
112
|
+
// Simulate more involved processing
|
|
113
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
processedContent: inputData.content,
|
|
117
|
+
processingType: "general",
|
|
118
|
+
recommendations: [
|
|
119
|
+
"Consider simplifying content",
|
|
120
|
+
"Break up long paragraphs",
|
|
121
|
+
"Add examples or explanations if needed",
|
|
122
|
+
],
|
|
123
|
+
};
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
These two steps will be used in different branches based on the content assessment. Next, you'll create the conditional workflow!
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Building Conditional Workflow
|
|
2
|
+
|
|
3
|
+
Now you'll create a workflow that uses conditional branching to route content through two different processing paths.
|
|
4
|
+
|
|
5
|
+
## Creating the Conditional Workflow
|
|
6
|
+
|
|
7
|
+
Add this workflow to your file:
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
export const conditionalWorkflow = createWorkflow({
|
|
11
|
+
id: "conditional-workflow",
|
|
12
|
+
description: "Content processing with conditional branching",
|
|
13
|
+
inputSchema: z.object({
|
|
14
|
+
content: z.string(),
|
|
15
|
+
type: z.enum(["article", "blog", "social"]).default("article"),
|
|
16
|
+
}),
|
|
17
|
+
outputSchema: z.object({
|
|
18
|
+
processedContent: z.string(),
|
|
19
|
+
processingType: z.string(),
|
|
20
|
+
recommendations: z.array(z.string()),
|
|
21
|
+
}),
|
|
22
|
+
})
|
|
23
|
+
.then(assessContentStep)
|
|
24
|
+
.branch([
|
|
25
|
+
// Branch 1: Short and simple content
|
|
26
|
+
[
|
|
27
|
+
async ({ inputData }) =>
|
|
28
|
+
inputData.category === "short" && inputData.complexity === "simple",
|
|
29
|
+
quickProcessingStep,
|
|
30
|
+
],
|
|
31
|
+
// Branch 2: Everything else
|
|
32
|
+
[
|
|
33
|
+
async ({ inputData }) =>
|
|
34
|
+
!(inputData.category === "short" && inputData.complexity === "simple"),
|
|
35
|
+
generalProcessingStep,
|
|
36
|
+
],
|
|
37
|
+
])
|
|
38
|
+
.commit();
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Understanding the Conditions
|
|
42
|
+
|
|
43
|
+
1. **Short + Simple**: Quick processing with minimal recommendations
|
|
44
|
+
2. **Everything Else**: General processing with more suggestions
|
|
45
|
+
|
|
46
|
+
## Multiple Conditions
|
|
47
|
+
|
|
48
|
+
You can combine conditions using logical operators:
|
|
49
|
+
|
|
50
|
+
- **`&&`**: AND - both conditions must be true
|
|
51
|
+
- **`||`**: OR - either condition can be true
|
|
52
|
+
- **`!`**: NOT - condition must be false
|
|
53
|
+
|
|
54
|
+
## Condition Evaluation
|
|
55
|
+
|
|
56
|
+
- Conditions are checked in order
|
|
57
|
+
- Multiple conditions can be true (steps run in parallel)
|
|
58
|
+
- If no conditions match, the branch is skipped
|
|
59
|
+
|
|
60
|
+
Next, you'll test this conditional workflow with different types of content!
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Testing Conditional Logic
|
|
2
|
+
|
|
3
|
+
Let's test your conditional workflow with different types of content to see how it routes to different processing paths.
|
|
4
|
+
|
|
5
|
+
## Registering the New Workflow
|
|
6
|
+
|
|
7
|
+
Update your Mastra configuration to include your new workflow workflows:
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
// In src/mastra/index.ts
|
|
11
|
+
import {
|
|
12
|
+
contentWorkflow,
|
|
13
|
+
aiContentWorkflow,
|
|
14
|
+
parallelAnalysisWorkflow,
|
|
15
|
+
conditionalWorkflow,
|
|
16
|
+
} from "./workflows/content-workflow";
|
|
17
|
+
|
|
18
|
+
export const mastra = new Mastra({
|
|
19
|
+
workflows: {
|
|
20
|
+
contentWorkflow,
|
|
21
|
+
aiContentWorkflow,
|
|
22
|
+
parallelAnalysisWorkflow,
|
|
23
|
+
conditionalWorkflow, // Add the conditional workflow
|
|
24
|
+
},
|
|
25
|
+
// ... rest of configuration
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Testing the conditional workflow
|
|
30
|
+
|
|
31
|
+
You can now test this new conditional workflow in the playground. Be sure to test different content lengths and content types.
|
|
32
|
+
|
|
33
|
+
## Understanding the Flow
|
|
34
|
+
|
|
35
|
+
1. **Assessment step** analyzes content and determines category/complexity
|
|
36
|
+
2. **Branch conditions** are evaluated against the assessment results
|
|
37
|
+
3. **Matching step** executes based on which condition(s) are true
|
|
38
|
+
4. **Results** show which processing path was taken
|
|
39
|
+
|
|
40
|
+
## Debugging Conditions
|
|
41
|
+
|
|
42
|
+
If a condition isn't working as expected:
|
|
43
|
+
|
|
44
|
+
- Check the assessment step output
|
|
45
|
+
- Verify condition logic matches your expectations
|
|
46
|
+
- Test individual conditions in isolation
|
|
47
|
+
- Add console.log statements to track condition evaluation
|
|
48
|
+
|
|
49
|
+
## Branch Benefits
|
|
50
|
+
|
|
51
|
+
Conditional workflows provide:
|
|
52
|
+
|
|
53
|
+
- **Intelligent routing**: Right processing for right content
|
|
54
|
+
- **Performance optimization**: Skip heavy processing for simple content
|
|
55
|
+
- **Customized experience**: Different handling for different scenarios
|
|
56
|
+
- **Scalable logic**: Easy to add new conditions and processing paths
|
|
57
|
+
|
|
58
|
+
Next, you'll learn about streaming workflow results for better user experience!
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Conclusion
|
|
2
|
+
|
|
3
|
+
Congratulations! You've completed the Mastra Workflows course and learned how to build powerful, type-safe workflows that can handle complex automation tasks.
|
|
4
|
+
|
|
5
|
+
## What You've Accomplished
|
|
6
|
+
|
|
7
|
+
Throughout this course, you've learned to:
|
|
8
|
+
|
|
9
|
+
### Core Concepts
|
|
10
|
+
|
|
11
|
+
- **Understanding workflows**: How they break complex tasks into manageable steps
|
|
12
|
+
- **Creating steps**: Building reusable units with clear inputs and outputs
|
|
13
|
+
- **Schema validation**: Using Zod for type safety and runtime validation
|
|
14
|
+
- **Error handling**: Making workflows robust and user-friendly
|
|
15
|
+
|
|
16
|
+
### Building Workflows
|
|
17
|
+
|
|
18
|
+
- **Chaining steps**: Connecting steps to create complete workflows
|
|
19
|
+
- **Testing thoroughly**: Ensuring reliability with comprehensive tests
|
|
20
|
+
- **Registering with Mastra**: Integrating workflows into your application
|
|
21
|
+
- **Using the playground**: Visual testing and debugging
|
|
22
|
+
|
|
23
|
+
### Advanced Features
|
|
24
|
+
|
|
25
|
+
- **AI integration**: Combining workflows with agents for intelligent processing
|
|
26
|
+
- **Parallel execution**: Running multiple steps simultaneously for better performance
|
|
27
|
+
- **Conditional branching**: Creating smart workflows that adapt to different scenarios
|
|
28
|
+
|
|
29
|
+
## Key Workflows You Built
|
|
30
|
+
|
|
31
|
+
1. **Content Processing Workflow**: Validates, enhances, and summarizes content
|
|
32
|
+
2. **AI-Enhanced Workflow**: Adds intelligent analysis with AI agents
|
|
33
|
+
3. **Parallel Analysis Workflow**: Demonstrates high-performance parallel execution
|
|
34
|
+
4. **Conditional Workflow**: Shows intelligent routing based on content characteristics
|
|
35
|
+
|
|
36
|
+
## Next Steps
|
|
37
|
+
|
|
38
|
+
Now that you understand workflows, you can:
|
|
39
|
+
|
|
40
|
+
### Expand Your Skills
|
|
41
|
+
|
|
42
|
+
- **Explore more integrations**: Connect workflows with databases, APIs, and external services
|
|
43
|
+
- **Build complex automations**: Create multi-step business processes
|
|
44
|
+
- **Integrate with web applications**: Use workflows in your frontend applications
|
|
45
|
+
- **Scale for production**: Deploy workflows with proper monitoring and error handling
|
|
46
|
+
|
|
47
|
+
## Final Thoughts
|
|
48
|
+
|
|
49
|
+
Workflows are a powerful way to build reliable, maintainable automation systems. The patterns and principles you've learned in this course will help you tackle increasingly complex challenges as you build AI-powered applications.
|
|
50
|
+
|
|
51
|
+
Remember:
|
|
52
|
+
|
|
53
|
+
- **Start simple**: Begin with basic workflows and add complexity gradually
|
|
54
|
+
- **Test thoroughly**: Good testing prevents production issues
|
|
55
|
+
- **Think in steps**: Break complex problems into smaller, manageable pieces
|
|
56
|
+
- **Embrace type safety**: Let schemas catch errors early
|
|
57
|
+
|
|
58
|
+
Thank you for completing the Mastra Workflows lesson. Happy building! 🚀
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Digital Ocean"
|
|
3
|
+
description: "Deploy your Mastra applications to Digital Ocean."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import { Callout, Steps, Tabs } from "nextra/components";
|
|
7
|
+
import ServerConfig from "@/components/content-blocks/server-config.mdx";
|
|
8
|
+
|
|
9
|
+
## Digital Ocean
|
|
10
|
+
|
|
11
|
+
Deploy your Mastra applications to Digital Ocean's App Platform and Droplets.
|
|
12
|
+
|
|
13
|
+
<Callout>
|
|
14
|
+
This guide assumes your Mastra application has been created using the default
|
|
15
|
+
`npx create-mastra@latest` command.
|
|
16
|
+
For more information on how to create a new Mastra application,
|
|
17
|
+
refer to our [getting started guide](./../../getting-started/installation.mdx)
|
|
18
|
+
</Callout>
|
|
19
|
+
|
|
20
|
+
<Tabs items={["App Platform", "Droplets"]}>
|
|
21
|
+
|
|
22
|
+
<Tabs.Tab>
|
|
23
|
+
|
|
24
|
+
### App Platform
|
|
25
|
+
|
|
26
|
+
#### Prerequisites [#app-platform-prerequisites]
|
|
27
|
+
|
|
28
|
+
- A Git repository containing your Mastra application. This can be a GitHub repository, GitLab repository, or any other compatible source provider.
|
|
29
|
+
- A Digital Ocean account
|
|
30
|
+
|
|
31
|
+
#### Deployment Steps
|
|
32
|
+
|
|
33
|
+
<Steps>
|
|
34
|
+
|
|
35
|
+
#### Create a new App
|
|
36
|
+
|
|
37
|
+
- Log in to your Digital Ocean dashboard.
|
|
38
|
+
- Navigate to the App Platform service.
|
|
39
|
+
- Select your source provider and create a new app.
|
|
40
|
+
|
|
41
|
+
#### Configure Deployment Source
|
|
42
|
+
|
|
43
|
+
- Connect and select your repository. You may also choose a container image or a sample app.
|
|
44
|
+
- Select the branch you want to deploy from.
|
|
45
|
+
- Configure the source directory if necessary. If your Mastra application uses the default directory structure, no action is required here.
|
|
46
|
+
- Head to the next step.
|
|
47
|
+
|
|
48
|
+
#### Configure Resource Settings and Environment Variables
|
|
49
|
+
|
|
50
|
+
- A Node.js build should be detected automatically.
|
|
51
|
+
- Add any required environment variables for your Mastra application. This includes API keys, database URLs, and other configuration values.
|
|
52
|
+
- You may choose to configure the size of your resource here.
|
|
53
|
+
- Other things you may optionally configure include, the region of your resource, the unique app name, and what project the resource belongs to.
|
|
54
|
+
- Once you're done, you may create the app after reviewing your configuration and pricing estimates.
|
|
55
|
+
|
|
56
|
+
#### Deployment
|
|
57
|
+
|
|
58
|
+
- Your app will be built and deployed automatically.
|
|
59
|
+
- Digital Ocean will provide you with a URL to access your deployed application.
|
|
60
|
+
|
|
61
|
+
</Steps>
|
|
62
|
+
|
|
63
|
+
You can now access your deployed application at the URL provided by Digital Ocean.
|
|
64
|
+
|
|
65
|
+
<Callout>
|
|
66
|
+
The Digital Ocean App Platform uses an ephemeral file system,
|
|
67
|
+
meaning that any files written to the file system are short-lived and may be lost.
|
|
68
|
+
Avoid using a Mastra storage provider that uses the file system,
|
|
69
|
+
such as `LibSQLStore` with a file URL.
|
|
70
|
+
</Callout>
|
|
71
|
+
|
|
72
|
+
</Tabs.Tab>
|
|
73
|
+
|
|
74
|
+
<Tabs.Tab>
|
|
75
|
+
|
|
76
|
+
### Droplets
|
|
77
|
+
|
|
78
|
+
Deploy your Mastra application to Digital Ocean's Droplets.
|
|
79
|
+
This guide will cover setting up a droplet, a reverse proxy using Nginx, and running your Mastra application.
|
|
80
|
+
|
|
81
|
+
<Callout>
|
|
82
|
+
The guide assumes your droplet runs Ubuntu 24+.
|
|
83
|
+
</Callout>
|
|
84
|
+
|
|
85
|
+
#### Prerequisites [#droplets-prerequisites]
|
|
86
|
+
|
|
87
|
+
- A Digital Ocean account
|
|
88
|
+
- A droplet running Ubuntu 24+
|
|
89
|
+
- A domain name with an A record pointing to your droplet
|
|
90
|
+
|
|
91
|
+
#### Setting up the droplet
|
|
92
|
+
|
|
93
|
+
<ServerConfig />
|
|
94
|
+
|
|
95
|
+
</Tabs.Tab>
|
|
96
|
+
|
|
97
|
+
</Tabs>
|
|
98
|
+
|
|
99
|
+
### Connect to your Mastra server
|
|
100
|
+
|
|
101
|
+
You can now connect to your Mastra server from your client application using a `MastraClient` from the `@mastra/client-js` package.
|
|
102
|
+
|
|
103
|
+
Refer to the [`MastraClient` documentation](../../client-js/overview.mdx) for more information.
|
|
104
|
+
|
|
105
|
+
```typescript copy showLineNumbers
|
|
106
|
+
import { MastraClient } from "@mastra/client-js";
|
|
107
|
+
|
|
108
|
+
const mastraClient = new MastraClient({
|
|
109
|
+
baseUrl: "https://<your-domain-name>",
|
|
110
|
+
});
|
|
111
|
+
```
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Cloud Providers"
|
|
3
|
+
description: "Deploy your Mastra applications to popular cloud providers."
|
|
4
|
+
asIndexPage: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
import { CardGrid, CardGridItem } from "@/components/cards/card-grid";
|
|
8
|
+
|
|
9
|
+
## Cloud Providers
|
|
10
|
+
|
|
11
|
+
Deploy your Mastra applicaitons to popular cloud providers.
|
|
12
|
+
|
|
13
|
+
<CardGrid>
|
|
14
|
+
<CardGridItem title="Digital Ocean" description="Deploy your Mastra applications to Digital Ocean" href="./cloud-providers/digital-ocean" />
|
|
15
|
+
</CardGrid>
|