@mastra/mcp-docs-server 0.13.2-alpha.2 → 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%2Fdynamodb.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +8 -8
- 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/package.json +1 -1
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @mastra/dynamodb
|
|
2
2
|
|
|
3
|
+
## 0.12.0-alpha.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ab52239: dependencies updates:
|
|
8
|
+
- Updated dependency [`@aws-sdk/lib-dynamodb@^3.830.0` ↗︎](https://www.npmjs.com/package/@aws-sdk/lib-dynamodb/v/3.830.0) (from `^3.828.0`, in `dependencies`)
|
|
9
|
+
|
|
3
10
|
## 0.12.0-alpha.3
|
|
4
11
|
|
|
5
12
|
### Minor Changes
|
|
@@ -291,12 +298,5 @@
|
|
|
291
298
|
- Updated dependencies [2901125]
|
|
292
299
|
- @mastra/core@0.10.2-alpha.1
|
|
293
300
|
|
|
294
|
-
## 0.10.0
|
|
295
|
-
|
|
296
|
-
### Patch Changes
|
|
297
|
-
|
|
298
|
-
- b3a3d63: BREAKING: Make vnext workflow the default worklow, and old workflow legacy_workflow
|
|
299
|
-
- d2d4fe4: Add a DynamoDB storage connector using a single-table design pattern with ElectroDB.
|
|
300
|
-
|
|
301
301
|
|
|
302
|
-
...
|
|
302
|
+
... 63 more lines hidden. See full changelog in package directory.
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @mastra/mcp-docs-server
|
|
2
2
|
|
|
3
|
+
## 0.13.2-alpha.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d2a783c: Minor lesson 1 course updates, added lesson 4 on workflows
|
|
8
|
+
|
|
3
9
|
## 0.13.2-alpha.2
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -292,11 +298,5 @@
|
|
|
292
298
|
- Updated dependencies [f53a6ac]
|
|
293
299
|
- Updated dependencies [5eb5a99]
|
|
294
300
|
- Updated dependencies [7e632c5]
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
- Updated dependencies [90be034]
|
|
298
|
-
- Updated dependencies [99f050a]
|
|
299
|
-
- Updated dependencies [d0ee3c6]
|
|
300
|
-
- Updated dependencies [b2ae5aa]
|
|
301
|
-
|
|
302
|
-
... 855 more lines hidden. See full changelog in package directory.
|
|
301
|
+
|
|
302
|
+
... 861 more lines hidden. See full changelog in package directory.
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @mastra/playground-ui
|
|
2
2
|
|
|
3
|
+
## 5.1.7-alpha.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d569c16: dependencies updates:
|
|
8
|
+
- Updated dependency [`react-code-block@1.1.3` ↗︎](https://www.npmjs.com/package/react-code-block/v/1.1.3) (from `1.1.1`, in `dependencies`)
|
|
9
|
+
|
|
3
10
|
## 5.1.7-alpha.4
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
|
@@ -292,11 +299,4 @@
|
|
|
292
299
|
|
|
293
300
|
- e719504: don't start posthog when the browser is Brave
|
|
294
301
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
### Patch Changes
|
|
298
|
-
|
|
299
|
-
- 1ccccff: dependencies updates:
|
|
300
|
-
- Updated dependency [`zod@^3.25.56` ↗︎](https://www.npmjs.com/package/zod/v/3.25.56) (from `^3.24.3`, in `dependencies`)
|
|
301
|
-
|
|
302
|
-
... 1649 more lines hidden. See full changelog in package directory.
|
|
302
|
+
... 1656 more lines hidden. See full changelog in package directory.
|
|
@@ -4,9 +4,14 @@ Let's check that your project has the correct structure. You should have:
|
|
|
4
4
|
|
|
5
5
|
1. A `src/mastra` directory that contains:
|
|
6
6
|
- `index.ts` - The main entry point for your Mastra project
|
|
7
|
-
- `agents
|
|
8
|
-
- `tools
|
|
7
|
+
- `agents/` - Directory containing individual agent files
|
|
8
|
+
- `tools/` - Directory containing individual tool files
|
|
9
|
+
- `workflows/` - Directory containing individual workflow files
|
|
9
10
|
|
|
10
|
-
If
|
|
11
|
+
If the CLI created your project, you should see files like:
|
|
12
|
+
|
|
13
|
+
- `agents/weather-agent.ts` - Example weather agent
|
|
14
|
+
- `tools/weather-tool.ts` - Example weather tool
|
|
15
|
+
- `workflows/weather-workflow.ts` - Example weather workflow
|
|
11
16
|
|
|
12
17
|
This structure is important because it follows the Mastra convention for organizing your code. The `index.ts` file is the main entry point for your Mastra project, while the `agents` and `tools` directories contain the definitions for your agents and tools, respectively.
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
# Creating Your Agent
|
|
2
2
|
|
|
3
|
-
Let's create a simple agent that will help users analyze financial transaction data. We'll
|
|
3
|
+
Let's create a simple agent that will help users analyze financial transaction data. We'll create a new file called `agents/financial-agent.ts`.
|
|
4
4
|
|
|
5
|
-
First,
|
|
5
|
+
First, create the new agent file at src/mastra/agents/financial-agent.ts
|
|
6
|
+
|
|
7
|
+
Now add the necessary imports at the top of your file:
|
|
6
8
|
|
|
7
9
|
```typescript
|
|
8
|
-
import { Agent } from "@mastra/core";
|
|
10
|
+
import { Agent } from "@mastra/core/agent";
|
|
9
11
|
import { openai } from "@ai-sdk/openai";
|
|
10
12
|
// We'll import our tool in a later step
|
|
11
13
|
```
|
|
@@ -1,18 +1,32 @@
|
|
|
1
1
|
# Exporting Your Agent
|
|
2
2
|
|
|
3
|
-
To make your agent available to the playground, you need to export it through the Mastra class in your `src/mastra/index.ts` file
|
|
3
|
+
To make your agent available to the playground, you need to export it through the Mastra class in your `src/mastra/index.ts` file.
|
|
4
|
+
|
|
5
|
+
First, import the necessary dependencies and your agent:
|
|
4
6
|
|
|
5
7
|
```typescript
|
|
6
|
-
import { Mastra } from "@mastra/core";
|
|
7
|
-
import {
|
|
8
|
+
import { Mastra } from "@mastra/core/mastra";
|
|
9
|
+
import { PinoLogger } from "@mastra/loggers";
|
|
10
|
+
import { LibSQLStore } from "@mastra/libsql";
|
|
11
|
+
import { financialAgent } from "./agents/financial-agent";
|
|
8
12
|
|
|
9
|
-
export const mastra
|
|
13
|
+
export const mastra = new Mastra({
|
|
10
14
|
agents: {
|
|
11
15
|
financialAgent,
|
|
12
16
|
},
|
|
17
|
+
storage: new LibSQLStore({
|
|
18
|
+
url: ":memory:",
|
|
19
|
+
}),
|
|
20
|
+
logger: new PinoLogger({
|
|
21
|
+
name: 'Mastra',
|
|
22
|
+
level: 'info',
|
|
23
|
+
}),
|
|
13
24
|
});
|
|
14
25
|
```
|
|
15
26
|
|
|
16
|
-
This creates a new Mastra instance that includes
|
|
27
|
+
This creates a new Mastra instance that includes:
|
|
28
|
+
- Your financial agent
|
|
29
|
+
- In-memory storage for development
|
|
30
|
+
- A logger for debugging and monitoring
|
|
17
31
|
|
|
18
|
-
The Mastra class is the main entry point for your Mastra project. It's responsible for registering your agents and
|
|
32
|
+
The Mastra class is the main entry point for your Mastra project. It's responsible for registering your agents and configuring the core services like storage and logging.
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
# Creating the getTransactions Tool
|
|
2
2
|
|
|
3
|
-
Let's create a tool that fetches transaction data from a Google Sheet. We'll
|
|
3
|
+
Let's create a tool that fetches transaction data from a Google Sheet. We'll create a new file called `tools/get-transactions-tool.ts`.
|
|
4
4
|
|
|
5
|
-
First,
|
|
5
|
+
First, create the new tool file at src/mastra/tools/get-transactions-tool.ts
|
|
6
|
+
|
|
7
|
+
Now add the necessary imports:
|
|
6
8
|
|
|
7
9
|
```typescript
|
|
8
|
-
import { createTool } from "@mastra/core";
|
|
10
|
+
import { createTool } from "@mastra/core/tools";
|
|
9
11
|
import { z } from "zod";
|
|
10
12
|
```
|
|
11
13
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# Connecting the Tool to Your Agent
|
|
2
2
|
|
|
3
|
-
Now that we've created our tool, we need to connect it to our agent. Go back to your `agents/
|
|
3
|
+
Now that we've created our tool, we need to connect it to our agent. Go back to your `agents/financial-agent.ts` file and update it:
|
|
4
4
|
|
|
5
5
|
1. Import the tool:
|
|
6
6
|
|
|
7
7
|
```typescript
|
|
8
|
-
import { getTransactionsTool } from "../tools";
|
|
8
|
+
import { getTransactionsTool } from "../tools/get-transactions-tool";
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
2. Add the tool to your agent:
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Introduction to Workflows
|
|
2
|
+
|
|
3
|
+
Welcome to the fourth lesson of the Mastra course! In this lesson, you'll learn about Mastra Workflows - a powerful way to orchestrate complex sequences of operations.
|
|
4
|
+
|
|
5
|
+
## What are Workflows?
|
|
6
|
+
|
|
7
|
+
Workflows in Mastra let you chain together multiple operations in a predictable, type-safe manner. Think of them as a recipe that breaks down complex tasks into smaller, manageable steps.
|
|
8
|
+
|
|
9
|
+
Instead of writing one big function that does everything, workflows let you:
|
|
10
|
+
|
|
11
|
+
- Break complex operations into smaller, reusable steps
|
|
12
|
+
- Define clear inputs and outputs for each step
|
|
13
|
+
- Chain steps together with automatic data validation
|
|
14
|
+
- Handle errors gracefully at each step
|
|
15
|
+
|
|
16
|
+
## Simple Example
|
|
17
|
+
|
|
18
|
+
Without workflows, you might write:
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
async function processContent(text: string) {
|
|
22
|
+
// All logic in one function - hard to test and reuse
|
|
23
|
+
const validated = validateText(text);
|
|
24
|
+
const enhanced = enhanceText(validated);
|
|
25
|
+
const summarized = summarizeText(enhanced);
|
|
26
|
+
return summarized;
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
With workflows, the same logic becomes modular and reusable with tracing built in at every step.
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
export const contentWorkflow = createWorkflow({...})
|
|
34
|
+
.then(validateStep)
|
|
35
|
+
.then(enhanceStep)
|
|
36
|
+
.then(summarizeStep)
|
|
37
|
+
.commit();
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## What You'll Build
|
|
41
|
+
|
|
42
|
+
In this lesson, you'll create a content processing workflow that validates, enhances, and summarizes text content using multiple connected steps.
|
|
43
|
+
|
|
44
|
+
Let's start by understanding the basic building blocks!
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Understanding Steps
|
|
2
|
+
|
|
3
|
+
Steps are the building blocks of workflows. Each step is a self-contained unit that takes some input, processes it, and produces an output.
|
|
4
|
+
|
|
5
|
+
## What is a Step?
|
|
6
|
+
|
|
7
|
+
A step has three main parts:
|
|
8
|
+
|
|
9
|
+
1. **Input Schema** - what data it expects to receive
|
|
10
|
+
2. **Output Schema** - what data it will produce
|
|
11
|
+
3. **Execute Function** - the logic that transforms input to output
|
|
12
|
+
|
|
13
|
+
## Step Structure
|
|
14
|
+
|
|
15
|
+
Every step follows this pattern:
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
const myStep = createStep({
|
|
19
|
+
id: "unique-step-name",
|
|
20
|
+
description: "What this step does",
|
|
21
|
+
inputSchema: z.object({
|
|
22
|
+
// Define expected input structure
|
|
23
|
+
}),
|
|
24
|
+
outputSchema: z.object({
|
|
25
|
+
// Define output structure
|
|
26
|
+
}),
|
|
27
|
+
execute: async ({ inputData }) => {
|
|
28
|
+
// Your logic here
|
|
29
|
+
return {
|
|
30
|
+
// Return data matching output schema
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Why Use Schemas?
|
|
37
|
+
|
|
38
|
+
Schemas provide several benefits:
|
|
39
|
+
|
|
40
|
+
- **Type Safety**: TypeScript knows exactly what data flows between steps
|
|
41
|
+
- **Runtime Validation**: Invalid data is caught immediately with helpful error messages
|
|
42
|
+
- **Documentation**: Schemas serve as living documentation of your workflow
|
|
43
|
+
- **Debugging**: Clear contracts make it easy to identify issues
|
|
44
|
+
|
|
45
|
+
## Key Benefits
|
|
46
|
+
|
|
47
|
+
- **Reusable**: Steps can be used in multiple workflows
|
|
48
|
+
- **Testable**: Each step can be tested in isolation
|
|
49
|
+
- **Composable**: Steps can be combined in different ways
|
|
50
|
+
- **Reliable**: Schemas catch data flow issues early
|
|
51
|
+
- **Traceable**: Every step is traced so you can see the flow of data
|
|
52
|
+
|
|
53
|
+
Next, you'll create your first step!
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Creating Your First Step
|
|
2
|
+
|
|
3
|
+
Let's create your first workflow step! We'll build a step that validates text content.
|
|
4
|
+
|
|
5
|
+
## Setting Up
|
|
6
|
+
|
|
7
|
+
First, create a new file for your workflow in the `src/mastra/workflows` directory. Let's name this file `content-workflow.ts`
|
|
8
|
+
|
|
9
|
+
## Creating a Validation Step
|
|
10
|
+
|
|
11
|
+
Add this code to your workflow file:
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { createStep } from "@mastra/core/workflows";
|
|
15
|
+
import { z } from "zod";
|
|
16
|
+
|
|
17
|
+
const validateContentStep = createStep({
|
|
18
|
+
id: "validate-content",
|
|
19
|
+
description: "Validates incoming text content",
|
|
20
|
+
inputSchema: z.object({
|
|
21
|
+
content: z.string().min(1, "Content cannot be empty"),
|
|
22
|
+
type: z.enum(["article", "blog", "social"]).default("article"),
|
|
23
|
+
}),
|
|
24
|
+
outputSchema: z.object({
|
|
25
|
+
content: z.string(),
|
|
26
|
+
type: z.string(),
|
|
27
|
+
wordCount: z.number(),
|
|
28
|
+
isValid: z.boolean(),
|
|
29
|
+
}),
|
|
30
|
+
execute: async ({ inputData }) => {
|
|
31
|
+
const { content, type } = inputData;
|
|
32
|
+
|
|
33
|
+
const wordCount = content.trim().split(/\s+/).length;
|
|
34
|
+
const isValid = wordCount >= 5; // Minimum 5 words
|
|
35
|
+
|
|
36
|
+
if (!isValid) {
|
|
37
|
+
throw new Error(`Content too short: ${wordCount} words`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
content: content.trim(),
|
|
42
|
+
type,
|
|
43
|
+
wordCount,
|
|
44
|
+
isValid,
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Understanding the Code
|
|
51
|
+
|
|
52
|
+
- **ID**: Unique identifier for this step
|
|
53
|
+
- **Input Schema**: Expects `content` (string) and optional `type`
|
|
54
|
+
- **Output Schema**: Returns content, type, word count, and validation status
|
|
55
|
+
- **Execute**: Contains the validation logic
|
|
56
|
+
|
|
57
|
+
Your first step is ready! Next, you'll test it to make sure it works correctly.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Creating a Second Step
|
|
2
|
+
|
|
3
|
+
Now let's create a second step that enhances the validated content with metadata.
|
|
4
|
+
|
|
5
|
+
## The Enhancement Step
|
|
6
|
+
|
|
7
|
+
Add this step to your workflow file:
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
const enhanceContentStep = createStep({
|
|
11
|
+
id: "enhance-content",
|
|
12
|
+
description: "Adds metadata to validated content",
|
|
13
|
+
inputSchema: z.object({
|
|
14
|
+
content: z.string(),
|
|
15
|
+
type: z.string(),
|
|
16
|
+
wordCount: z.number(),
|
|
17
|
+
isValid: z.boolean(),
|
|
18
|
+
}),
|
|
19
|
+
outputSchema: z.object({
|
|
20
|
+
content: z.string(),
|
|
21
|
+
type: z.string(),
|
|
22
|
+
wordCount: z.number(),
|
|
23
|
+
metadata: z.object({
|
|
24
|
+
readingTime: z.number(),
|
|
25
|
+
difficulty: z.enum(["easy", "medium", "hard"]),
|
|
26
|
+
processedAt: z.string(),
|
|
27
|
+
}),
|
|
28
|
+
}),
|
|
29
|
+
execute: async ({ inputData }) => {
|
|
30
|
+
const { content, type, wordCount } = inputData;
|
|
31
|
+
|
|
32
|
+
// Calculate reading time (200 words per minute)
|
|
33
|
+
const readingTime = Math.ceil(wordCount / 200);
|
|
34
|
+
|
|
35
|
+
// Determine difficulty based on word count
|
|
36
|
+
let difficulty: "easy" | "medium" | "hard" = "easy";
|
|
37
|
+
if (wordCount > 100) difficulty = "medium";
|
|
38
|
+
if (wordCount > 300) difficulty = "hard";
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
content,
|
|
42
|
+
type,
|
|
43
|
+
wordCount,
|
|
44
|
+
metadata: {
|
|
45
|
+
readingTime,
|
|
46
|
+
difficulty,
|
|
47
|
+
processedAt: new Date().toISOString(),
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Notice the Input Schema
|
|
55
|
+
|
|
56
|
+
The input schema of this step matches the output schema of the previous step. This is important for chaining steps together!
|
|
57
|
+
|
|
58
|
+
Your second step is ready! Next, you'll learn how to chain these steps together into a complete workflow.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Chaining Steps Together
|
|
2
|
+
|
|
3
|
+
Now you'll learn how to chain your steps together to create a complete workflow.
|
|
4
|
+
|
|
5
|
+
## Creating the Workflow
|
|
6
|
+
|
|
7
|
+
Add this workflow definition to your file:
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { createWorkflow } from "@mastra/core/workflows";
|
|
11
|
+
|
|
12
|
+
export const contentWorkflow = createWorkflow({
|
|
13
|
+
id: "content-processing-workflow",
|
|
14
|
+
description: "Validates and enhances content",
|
|
15
|
+
inputSchema: z.object({
|
|
16
|
+
content: z.string(),
|
|
17
|
+
type: z.enum(["article", "blog", "social"]).default("article")
|
|
18
|
+
}),
|
|
19
|
+
outputSchema: z.object({
|
|
20
|
+
content: z.string(),
|
|
21
|
+
type: z.string(),
|
|
22
|
+
wordCount: z.number(),
|
|
23
|
+
metadata: z.object({
|
|
24
|
+
readingTime: z.number(),
|
|
25
|
+
difficulty: z.enum(["easy", "medium", "hard"]),
|
|
26
|
+
processedAt: z.string()
|
|
27
|
+
})
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
.then(validateContentStep)
|
|
31
|
+
.then(enhanceContentStep)
|
|
32
|
+
.commit();
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Understanding the Workflow
|
|
36
|
+
|
|
37
|
+
- **Input Schema**: Defines what data the workflow expects
|
|
38
|
+
- **Output Schema**: Defines what the workflow will return
|
|
39
|
+
- **Steps**: Chained using `.then()` in the order they should execute
|
|
40
|
+
- **Commit**: Finalizes the workflow definition
|
|
41
|
+
|
|
42
|
+
## How Data Flows
|
|
43
|
+
|
|
44
|
+
1. Workflow receives input matching the input schema
|
|
45
|
+
2. First step processes input and outputs validated data
|
|
46
|
+
3. Second step receives the first step's output as its input
|
|
47
|
+
4. Workflow returns the final step's output
|
|
48
|
+
|
|
49
|
+
## Schema Validation
|
|
50
|
+
|
|
51
|
+
The workflow automatically validates:
|
|
52
|
+
- Input data matches the workflow's input schema
|
|
53
|
+
- Each step's output matches the next step's input schema
|
|
54
|
+
- Final output matches the workflow's output schema
|
|
55
|
+
|
|
56
|
+
Your workflow is now ready to run! Next, you'll test the complete workflow.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Registering with Mastra
|
|
2
|
+
|
|
3
|
+
Now you'll register your workflow with the main Mastra instance so you can use it alongside agents and tools.
|
|
4
|
+
|
|
5
|
+
## Updating Your Mastra Configuration
|
|
6
|
+
|
|
7
|
+
Open your `src/mastra/index.ts` file and add your workflow:
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
// Import your workflow
|
|
11
|
+
import { contentWorkflow } from "./workflows/content-workflow";
|
|
12
|
+
|
|
13
|
+
export const mastra = new Mastra({
|
|
14
|
+
// Register your workflow here
|
|
15
|
+
workflows: {
|
|
16
|
+
contentWorkflow,
|
|
17
|
+
},
|
|
18
|
+
// ...Existing code
|
|
19
|
+
});
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Note: You may already have workflows registered, in which case, this workflow should be added to the workflows object.
|
|
23
|
+
|
|
24
|
+
Your workflow is now registered with Mastra! Next, you'll learn how to use it in the playground.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Using the Playground
|
|
2
|
+
|
|
3
|
+
The Mastra Playground provides a visual interface to test and run your workflows. Let's see your workflow in action!
|
|
4
|
+
|
|
5
|
+
## Starting the Development Server
|
|
6
|
+
|
|
7
|
+
Start your Mastra development server using the `mastra dev` command. If you are using npm the command is:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm run dev
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
You should see output like:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
🚀 Mastra Dev Server starting...
|
|
17
|
+
📊 Playground available at: http://localhost:4111
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Accessing Workflows in Playground
|
|
21
|
+
|
|
22
|
+
1. Open your browser and go to `http://localhost:4111`
|
|
23
|
+
2. Click on "Workflows" in the navigation
|
|
24
|
+
3. You should see your `contentWorkflow` listed
|
|
25
|
+
|
|
26
|
+
## Testing Your Workflow
|
|
27
|
+
|
|
28
|
+
1. Click on your `contentWorkflow`
|
|
29
|
+
2. You'll see an input form based on your workflow's input schema
|
|
30
|
+
3. Enter some test content in the form:
|
|
31
|
+
|
|
32
|
+
```json
|
|
33
|
+
{
|
|
34
|
+
"content": "Machine learning is revolutionizing healthcare by enabling faster diagnoses and personalized treatments.",
|
|
35
|
+
"type": "article"
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
4. Click "Run Workflow"
|
|
40
|
+
5. Watch the execution progress and see the results
|
|
41
|
+
|
|
42
|
+
## Understanding the Interface
|
|
43
|
+
|
|
44
|
+
The playground shows you:
|
|
45
|
+
|
|
46
|
+
- **Input Schema**: What data your workflow expects
|
|
47
|
+
- **Execution Progress**: Real-time updates as steps complete
|
|
48
|
+
- **Output**: The final result from your workflow
|
|
49
|
+
- **Execution Time**: How long the workflow took to run
|
|
50
|
+
|
|
51
|
+
## Benefits of the Playground
|
|
52
|
+
|
|
53
|
+
- **Visual Testing**: Easy way to test workflows without writing code
|
|
54
|
+
- **Schema Validation**: Automatic form generation from your schemas
|
|
55
|
+
- **Real-time Feedback**: See exactly what's happening during execution
|
|
56
|
+
- **Easy Debugging**: Quickly test different inputs and view traces from workflow runs
|
|
57
|
+
|
|
58
|
+
Great! You can now visually test your workflow. Next, you'll learn how to run workflows programmatically.
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# Running Workflows Programmatically
|
|
2
|
+
|
|
3
|
+
Learn how to execute your workflows from code, which is essential for integrating them into applications.
|
|
4
|
+
|
|
5
|
+
## Creating a Workflow Runner
|
|
6
|
+
|
|
7
|
+
Create a new file to test programmatic execution:
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
// src/run-workflow.ts
|
|
11
|
+
import { mastra } from "./mastra";
|
|
12
|
+
|
|
13
|
+
async function runContentWorkflow() {
|
|
14
|
+
console.log("🚀 Running workflow programmatically...\n");
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
// Get the workflow instance
|
|
18
|
+
const workflow = mastra.getWorkflow("contentWorkflow");
|
|
19
|
+
|
|
20
|
+
if (!workflow) {
|
|
21
|
+
throw new Error("Workflow not found");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Create a run instance
|
|
25
|
+
const run = workflow.createRun();
|
|
26
|
+
|
|
27
|
+
// Execute with test data
|
|
28
|
+
const result = await run.start({
|
|
29
|
+
inputData: {
|
|
30
|
+
content:
|
|
31
|
+
"Climate change is one of the most pressing challenges of our time, requiring immediate action from governments, businesses, and individuals worldwide.",
|
|
32
|
+
type: "blog",
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
if (result.status === "success") {
|
|
37
|
+
console.log("✅ Success!");
|
|
38
|
+
console.log(
|
|
39
|
+
"📊 Reading time:",
|
|
40
|
+
result.result.metadata.readingTime,
|
|
41
|
+
"minutes",
|
|
42
|
+
);
|
|
43
|
+
console.log("🎯 Difficulty:", result.result.metadata.difficulty);
|
|
44
|
+
console.log("📅 Processed at:", result.result.metadata.processedAt);
|
|
45
|
+
}
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.error("❌ Error:", (error as Error).message);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Run the workflow
|
|
52
|
+
runContentWorkflow();
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Running the Code
|
|
56
|
+
|
|
57
|
+
Execute your workflow runner:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
npx tsx src/run-workflow.ts
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Key Methods
|
|
64
|
+
|
|
65
|
+
- **`mastra.getWorkflow(id)`**: Gets a registered workflow by ID
|
|
66
|
+
- **`workflow.createRun()`**: Creates a new execution instance
|
|
67
|
+
- **`run.start(inputData)`**: Executes the workflow with provided data
|
|
68
|
+
|
|
69
|
+
## Return Value
|
|
70
|
+
|
|
71
|
+
The `start()` method returns:
|
|
72
|
+
|
|
73
|
+
- **`success`**: Boolean indicating if workflow completed successfully
|
|
74
|
+
- **`result`**: The final output from the workflow
|
|
75
|
+
- **`executionTime`**: How long the workflow took to run
|
|
76
|
+
|
|
77
|
+
Your workflow can now be run from anywhere in your application! Next, you'll learn about error handling.
|