@mastra/mcp-docs-server 0.0.1-alpha.1
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 +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fcomposio.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fgithub.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +11 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Frag.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fragie.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-azure.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-deepgram.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-elevenlabs.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-google.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-ibm.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-murf.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-openai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-playai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-replicate.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-speechify.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fstabilityai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +59 -0
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +24 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +12 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +302 -0
- package/.docs/organized/changelogs/create-mastra.md +302 -0
- package/.docs/organized/changelogs/mastra.md +302 -0
- package/.docs/organized/code-examples/agent.md +385 -0
- package/.docs/organized/code-examples/ai-sdk-useChat.md +377 -0
- package/.docs/organized/code-examples/assistant-ui.md +37 -0
- package/.docs/organized/code-examples/bird-checker-with-express.md +235 -0
- package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +360 -0
- package/.docs/organized/code-examples/bird-checker-with-nextjs.md +250 -0
- package/.docs/organized/code-examples/crypto-chatbot.md +96 -0
- package/.docs/organized/code-examples/fireworks-r1.md +159 -0
- package/.docs/organized/code-examples/integrations.md +184 -0
- package/.docs/organized/code-examples/mcp-configuration.md +341 -0
- package/.docs/organized/code-examples/memory-todo-agent.md +161 -0
- package/.docs/organized/code-examples/memory-with-context.md +167 -0
- package/.docs/organized/code-examples/memory-with-libsql.md +204 -0
- package/.docs/organized/code-examples/memory-with-pg.md +224 -0
- package/.docs/organized/code-examples/memory-with-upstash.md +268 -0
- package/.docs/organized/code-examples/quick-start.md +127 -0
- package/.docs/organized/code-examples/stock-price-tool.md +124 -0
- package/.docs/organized/code-examples/weather-agent.md +352 -0
- package/.docs/organized/code-examples/workflow-ai-recruiter.md +159 -0
- package/.docs/organized/code-examples/workflow-with-inline-steps.md +111 -0
- package/.docs/organized/code-examples/workflow-with-memory.md +393 -0
- package/.docs/organized/code-examples/workflow-with-separate-steps.md +131 -0
- package/.docs/raw/agents/00-overview.mdx +185 -0
- package/.docs/raw/agents/01-agent-memory.mdx +610 -0
- package/.docs/raw/agents/02-adding-tools.mdx +224 -0
- package/.docs/raw/agents/03-adding-voice.mdx +170 -0
- package/.docs/raw/deployment/deployment.mdx +156 -0
- package/.docs/raw/deployment/logging-and-tracing.mdx +242 -0
- package/.docs/raw/deployment/server.mdx +114 -0
- package/.docs/raw/evals/00-overview.mdx +106 -0
- package/.docs/raw/evals/01-supported-evals.mdx +31 -0
- package/.docs/raw/evals/02-custom-eval.mdx +187 -0
- package/.docs/raw/faq/index.mdx +63 -0
- package/.docs/raw/frameworks/01-next-js.mdx +238 -0
- package/.docs/raw/frameworks/02-ai-sdk.mdx +218 -0
- package/.docs/raw/getting-started/installation.mdx +436 -0
- package/.docs/raw/getting-started/project-structure.mdx +80 -0
- package/.docs/raw/guides/01-chef-michel.mdx +242 -0
- package/.docs/raw/guides/02-stock-agent.mdx +182 -0
- package/.docs/raw/guides/03-recruiter.mdx +187 -0
- package/.docs/raw/index.mdx +22 -0
- package/.docs/raw/local-dev/creating-projects.mdx +74 -0
- package/.docs/raw/local-dev/integrations.mdx +127 -0
- package/.docs/raw/local-dev/mastra-dev.mdx +65 -0
- package/.docs/raw/rag/chunking-and-embedding.mdx +128 -0
- package/.docs/raw/rag/overview.mdx +85 -0
- package/.docs/raw/rag/retrieval.mdx +362 -0
- package/.docs/raw/rag/vector-databases.mdx +271 -0
- package/.docs/raw/reference/agents/createTool.mdx +190 -0
- package/.docs/raw/reference/agents/generate.mdx +327 -0
- package/.docs/raw/reference/agents/getAgent.mdx +54 -0
- package/.docs/raw/reference/agents/stream.mdx +361 -0
- package/.docs/raw/reference/cli/build.mdx +48 -0
- package/.docs/raw/reference/cli/deploy.mdx +22 -0
- package/.docs/raw/reference/cli/dev.mdx +97 -0
- package/.docs/raw/reference/cli/init.mdx +43 -0
- package/.docs/raw/reference/client-js/agents.mdx +90 -0
- package/.docs/raw/reference/client-js/error-handling.mdx +38 -0
- package/.docs/raw/reference/client-js/index.mdx +127 -0
- package/.docs/raw/reference/client-js/logs.mdx +24 -0
- package/.docs/raw/reference/client-js/memory.mdx +94 -0
- package/.docs/raw/reference/client-js/telemetry.mdx +20 -0
- package/.docs/raw/reference/client-js/tools.mdx +44 -0
- package/.docs/raw/reference/client-js/vectors.mdx +79 -0
- package/.docs/raw/reference/client-js/workflows.mdx +137 -0
- package/.docs/raw/reference/core/mastra-class.mdx +232 -0
- package/.docs/raw/reference/deployer/cloudflare.mdx +176 -0
- package/.docs/raw/reference/deployer/deployer.mdx +159 -0
- package/.docs/raw/reference/deployer/netlify.mdx +88 -0
- package/.docs/raw/reference/deployer/vercel.mdx +97 -0
- package/.docs/raw/reference/evals/answer-relevancy.mdx +186 -0
- package/.docs/raw/reference/evals/bias.mdx +186 -0
- package/.docs/raw/reference/evals/completeness.mdx +174 -0
- package/.docs/raw/reference/evals/content-similarity.mdx +183 -0
- package/.docs/raw/reference/evals/context-position.mdx +190 -0
- package/.docs/raw/reference/evals/context-precision.mdx +189 -0
- package/.docs/raw/reference/evals/context-relevancy.mdx +188 -0
- package/.docs/raw/reference/evals/contextual-recall.mdx +191 -0
- package/.docs/raw/reference/evals/faithfulness.mdx +193 -0
- package/.docs/raw/reference/evals/hallucination.mdx +219 -0
- package/.docs/raw/reference/evals/keyword-coverage.mdx +176 -0
- package/.docs/raw/reference/evals/prompt-alignment.mdx +238 -0
- package/.docs/raw/reference/evals/summarization.mdx +205 -0
- package/.docs/raw/reference/evals/textual-difference.mdx +161 -0
- package/.docs/raw/reference/evals/tone-consistency.mdx +181 -0
- package/.docs/raw/reference/evals/toxicity.mdx +165 -0
- package/.docs/raw/reference/index.mdx +8 -0
- package/.docs/raw/reference/memory/Memory.mdx +186 -0
- package/.docs/raw/reference/memory/createThread.mdx +93 -0
- package/.docs/raw/reference/memory/getThreadById.mdx +43 -0
- package/.docs/raw/reference/memory/getThreadsByResourceId.mdx +45 -0
- package/.docs/raw/reference/memory/query.mdx +164 -0
- package/.docs/raw/reference/observability/create-logger.mdx +106 -0
- package/.docs/raw/reference/observability/logger.mdx +55 -0
- package/.docs/raw/reference/observability/otel-config.mdx +120 -0
- package/.docs/raw/reference/observability/providers/braintrust.mdx +40 -0
- package/.docs/raw/reference/observability/providers/index.mdx +15 -0
- package/.docs/raw/reference/observability/providers/laminar.mdx +41 -0
- package/.docs/raw/reference/observability/providers/langfuse.mdx +51 -0
- package/.docs/raw/reference/observability/providers/langsmith.mdx +46 -0
- package/.docs/raw/reference/observability/providers/langwatch.mdx +45 -0
- package/.docs/raw/reference/observability/providers/new-relic.mdx +40 -0
- package/.docs/raw/reference/observability/providers/signoz.mdx +40 -0
- package/.docs/raw/reference/observability/providers/traceloop.mdx +40 -0
- package/.docs/raw/reference/rag/astra.mdx +258 -0
- package/.docs/raw/reference/rag/chroma.mdx +281 -0
- package/.docs/raw/reference/rag/chunk.mdx +237 -0
- package/.docs/raw/reference/rag/document.mdx +129 -0
- package/.docs/raw/reference/rag/embeddings.mdx +160 -0
- package/.docs/raw/reference/rag/extract-params.mdx +72 -0
- package/.docs/raw/reference/rag/graph-rag.mdx +182 -0
- package/.docs/raw/reference/rag/libsql.mdx +357 -0
- package/.docs/raw/reference/rag/metadata-filters.mdx +298 -0
- package/.docs/raw/reference/rag/pg.mdx +477 -0
- package/.docs/raw/reference/rag/pinecone.mdx +249 -0
- package/.docs/raw/reference/rag/qdrant.mdx +236 -0
- package/.docs/raw/reference/rag/rerank.mdx +212 -0
- package/.docs/raw/reference/rag/turbopuffer.mdx +249 -0
- package/.docs/raw/reference/rag/upstash.mdx +198 -0
- package/.docs/raw/reference/rag/vectorize.mdx +253 -0
- package/.docs/raw/reference/storage/libsql.mdx +74 -0
- package/.docs/raw/reference/storage/postgresql.mdx +48 -0
- package/.docs/raw/reference/storage/upstash.mdx +86 -0
- package/.docs/raw/reference/tools/client.mdx +180 -0
- package/.docs/raw/reference/tools/document-chunker-tool.mdx +141 -0
- package/.docs/raw/reference/tools/graph-rag-tool.mdx +154 -0
- package/.docs/raw/reference/tools/mcp-configuration.mdx +206 -0
- package/.docs/raw/reference/tools/vector-query-tool.mdx +212 -0
- package/.docs/raw/reference/voice/composite-voice.mdx +140 -0
- package/.docs/raw/reference/voice/deepgram.mdx +164 -0
- package/.docs/raw/reference/voice/elevenlabs.mdx +216 -0
- package/.docs/raw/reference/voice/google.mdx +198 -0
- package/.docs/raw/reference/voice/mastra-voice.mdx +394 -0
- package/.docs/raw/reference/voice/murf.mdx +251 -0
- package/.docs/raw/reference/voice/openai-realtime.mdx +431 -0
- package/.docs/raw/reference/voice/openai.mdx +168 -0
- package/.docs/raw/reference/voice/playai.mdx +159 -0
- package/.docs/raw/reference/voice/speechify.mdx +145 -0
- package/.docs/raw/reference/workflows/after.mdx +88 -0
- package/.docs/raw/reference/workflows/commit.mdx +37 -0
- package/.docs/raw/reference/workflows/createRun.mdx +77 -0
- package/.docs/raw/reference/workflows/else.mdx +72 -0
- package/.docs/raw/reference/workflows/execute.mdx +110 -0
- package/.docs/raw/reference/workflows/if.mdx +107 -0
- package/.docs/raw/reference/workflows/resume.mdx +155 -0
- package/.docs/raw/reference/workflows/start.mdx +84 -0
- package/.docs/raw/reference/workflows/step-class.mdx +100 -0
- package/.docs/raw/reference/workflows/step-condition.mdx +134 -0
- package/.docs/raw/reference/workflows/step-function.mdx +92 -0
- package/.docs/raw/reference/workflows/step-options.mdx +69 -0
- package/.docs/raw/reference/workflows/suspend.mdx +80 -0
- package/.docs/raw/reference/workflows/then.mdx +74 -0
- package/.docs/raw/reference/workflows/until.mdx +165 -0
- package/.docs/raw/reference/workflows/watch.mdx +118 -0
- package/.docs/raw/reference/workflows/while.mdx +168 -0
- package/.docs/raw/reference/workflows/workflow.mdx +233 -0
- package/.docs/raw/workflows/00-overview.mdx +168 -0
- package/.docs/raw/workflows/control-flow.mdx +712 -0
- package/.docs/raw/workflows/dynamic-workflows.mdx +232 -0
- package/.docs/raw/workflows/steps.mdx +98 -0
- package/.docs/raw/workflows/suspend-and-resume.mdx +196 -0
- package/.docs/raw/workflows/variables.mdx +248 -0
- package/LICENSE +44 -0
- package/README.md +129 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +19 -0
- package/dist/prepare-docs/code-examples.d.ts +4 -0
- package/dist/prepare-docs/code-examples.js +91 -0
- package/dist/prepare-docs/copy-raw.d.ts +1 -0
- package/dist/prepare-docs/copy-raw.js +41 -0
- package/dist/prepare-docs/index.d.ts +1 -0
- package/dist/prepare-docs/index.js +8 -0
- package/dist/prepare-docs/package-changes.d.ts +4 -0
- package/dist/prepare-docs/package-changes.js +92 -0
- package/dist/prepare-docs/prepare.d.ts +1 -0
- package/dist/prepare-docs/prepare.js +13 -0
- package/dist/sse.d.ts +1 -0
- package/dist/sse.js +9 -0
- package/dist/stdio.d.ts +1 -0
- package/dist/stdio.js +8 -0
- package/dist/tools/__tests__/blog.test.d.ts +1 -0
- package/dist/tools/__tests__/blog.test.js +48 -0
- package/dist/tools/__tests__/changes.test.d.ts +1 -0
- package/dist/tools/__tests__/changes.test.js +36 -0
- package/dist/tools/__tests__/docs.test.d.ts +1 -0
- package/dist/tools/__tests__/docs.test.js +46 -0
- package/dist/tools/__tests__/examples.test.d.ts +1 -0
- package/dist/tools/__tests__/examples.test.js +52 -0
- package/dist/tools/blog.d.ts +15 -0
- package/dist/tools/blog.js +73 -0
- package/dist/tools/changes.d.ts +11 -0
- package/dist/tools/changes.js +69 -0
- package/dist/tools/docs.d.ts +11 -0
- package/dist/tools/docs.js +176 -0
- package/dist/tools/examples.d.ts +11 -0
- package/dist/tools/examples.js +61 -0
- package/dist/utils.d.ts +6 -0
- package/dist/utils.js +9 -0
- package/package.json +66 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: Workflow.if() | Conditional Branching | Mastra Docs"
|
|
3
|
+
description: "Documentation for the `.if()` method in Mastra workflows, which creates conditional branches based on specified conditions."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Workflow.if()
|
|
7
|
+
|
|
8
|
+
> Experimental
|
|
9
|
+
|
|
10
|
+
The `.if()` method creates a conditional branch in the workflow, allowing steps to execute only when a specified condition is true. This enables dynamic workflow paths based on the results of previous steps.
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```typescript copy showLineNumbers
|
|
15
|
+
workflow
|
|
16
|
+
.step(startStep)
|
|
17
|
+
.if(async ({ context }) => {
|
|
18
|
+
const value = context.getStepResult<{ value: number }>('start')?.value;
|
|
19
|
+
return value < 10; // If true, execute the "if" branch
|
|
20
|
+
})
|
|
21
|
+
.then(ifBranchStep)
|
|
22
|
+
.else()
|
|
23
|
+
.then(elseBranchStep)
|
|
24
|
+
.commit();
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Parameters
|
|
28
|
+
|
|
29
|
+
<PropertiesTable
|
|
30
|
+
content={[
|
|
31
|
+
{
|
|
32
|
+
name: "condition",
|
|
33
|
+
type: "Function | ReferenceCondition",
|
|
34
|
+
description: "A function or reference condition that determines whether to execute the 'if' branch",
|
|
35
|
+
isOptional: false
|
|
36
|
+
}
|
|
37
|
+
]}
|
|
38
|
+
/>
|
|
39
|
+
|
|
40
|
+
## Condition Types
|
|
41
|
+
|
|
42
|
+
### Function Condition
|
|
43
|
+
|
|
44
|
+
You can use a function that returns a boolean:
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
workflow
|
|
48
|
+
.step(startStep)
|
|
49
|
+
.if(async ({ context }) => {
|
|
50
|
+
const result = context.getStepResult<{ status: string }>('start');
|
|
51
|
+
return result?.status === 'success'; // Execute "if" branch when status is "success"
|
|
52
|
+
})
|
|
53
|
+
.then(successStep)
|
|
54
|
+
.else()
|
|
55
|
+
.then(failureStep);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Reference Condition
|
|
59
|
+
|
|
60
|
+
You can use a reference-based condition with comparison operators:
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
workflow
|
|
64
|
+
.step(startStep)
|
|
65
|
+
.if({
|
|
66
|
+
ref: { step: startStep, path: 'value' },
|
|
67
|
+
query: { $lt: 10 }, // Execute "if" branch when value is less than 10
|
|
68
|
+
})
|
|
69
|
+
.then(ifBranchStep)
|
|
70
|
+
.else()
|
|
71
|
+
.then(elseBranchStep);
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Returns
|
|
75
|
+
|
|
76
|
+
<PropertiesTable
|
|
77
|
+
content={[
|
|
78
|
+
{
|
|
79
|
+
name: "workflow",
|
|
80
|
+
type: "Workflow",
|
|
81
|
+
description: "The workflow instance for method chaining"
|
|
82
|
+
}
|
|
83
|
+
]}
|
|
84
|
+
/>
|
|
85
|
+
|
|
86
|
+
## Error Handling
|
|
87
|
+
|
|
88
|
+
The `if` method requires a previous step to be defined. If you try to use it without a preceding step, an error will be thrown:
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
try {
|
|
92
|
+
// This will throw an error
|
|
93
|
+
workflow
|
|
94
|
+
.if(async ({ context }) => true)
|
|
95
|
+
.then(someStep)
|
|
96
|
+
.commit();
|
|
97
|
+
} catch (error) {
|
|
98
|
+
console.error(error); // "Condition requires a step to be executed after"
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Related
|
|
103
|
+
|
|
104
|
+
- [else Reference](./else.mdx)
|
|
105
|
+
- [then Reference](./then.mdx)
|
|
106
|
+
- [Control Flow Guide](../../workflows/control-flow.mdx)
|
|
107
|
+
- [Step Condition Reference](./step-condition.mdx)
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: run.resume() | Running Workflows | Mastra Docs"
|
|
3
|
+
description: Documentation for the `.resume()` method in workflows, which continues execution of a suspended workflow step.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# run.resume()
|
|
7
|
+
|
|
8
|
+
The `.resume()` method continues execution of a suspended workflow step, optionally providing new context data that can be accessed by the step on the inputData property.
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```typescript copy showLineNumbers
|
|
13
|
+
await run.resume({
|
|
14
|
+
runId: "abc-123",
|
|
15
|
+
stepId: "stepTwo",
|
|
16
|
+
context: {
|
|
17
|
+
secondValue: 100
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Parameters
|
|
23
|
+
|
|
24
|
+
<PropertiesTable
|
|
25
|
+
content={[
|
|
26
|
+
{
|
|
27
|
+
name: "config",
|
|
28
|
+
type: "object",
|
|
29
|
+
description: "Configuration for resuming the workflow",
|
|
30
|
+
isOptional: false
|
|
31
|
+
}
|
|
32
|
+
]}
|
|
33
|
+
/>
|
|
34
|
+
|
|
35
|
+
### config
|
|
36
|
+
|
|
37
|
+
<PropertiesTable
|
|
38
|
+
content={[
|
|
39
|
+
{
|
|
40
|
+
name: "runId",
|
|
41
|
+
type: "string",
|
|
42
|
+
description: "Unique identifier of the workflow run to resume",
|
|
43
|
+
isOptional: false
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: "stepId",
|
|
47
|
+
type: "string",
|
|
48
|
+
description: "ID of the suspended step to resume",
|
|
49
|
+
isOptional: false
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: "context",
|
|
53
|
+
type: "Record<string, any>",
|
|
54
|
+
description: "New context data to inject into the step's inputData property",
|
|
55
|
+
isOptional: true
|
|
56
|
+
}
|
|
57
|
+
]}
|
|
58
|
+
/>
|
|
59
|
+
|
|
60
|
+
## Returns
|
|
61
|
+
|
|
62
|
+
<PropertiesTable
|
|
63
|
+
content={[
|
|
64
|
+
{
|
|
65
|
+
name: "Promise<WorkflowResult>",
|
|
66
|
+
type: "object",
|
|
67
|
+
description: "Result of the resumed workflow execution"
|
|
68
|
+
}
|
|
69
|
+
]}
|
|
70
|
+
/>
|
|
71
|
+
|
|
72
|
+
## Async/Await Flow
|
|
73
|
+
|
|
74
|
+
When a workflow is resumed, execution continues from the point immediately after the `suspend()` call in the step's execution function. This creates a natural flow in your code:
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
// Step definition with suspend point
|
|
78
|
+
const reviewStep = new Step({
|
|
79
|
+
id: "review",
|
|
80
|
+
execute: async ({ context, suspend }) => {
|
|
81
|
+
// First part of execution
|
|
82
|
+
const initialAnalysis = analyzeData(context.inputData.data);
|
|
83
|
+
|
|
84
|
+
if (initialAnalysis.needsReview) {
|
|
85
|
+
// Suspend execution here
|
|
86
|
+
await suspend({ analysis: initialAnalysis });
|
|
87
|
+
|
|
88
|
+
// This code runs after resume() is called
|
|
89
|
+
// context.inputData now contains any data provided during resume
|
|
90
|
+
return {
|
|
91
|
+
reviewedData: enhanceWithFeedback(initialAnalysis, context.inputData.feedback)
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return { reviewedData: initialAnalysis };
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const { runId, resume, start } = workflow.createRun();
|
|
100
|
+
|
|
101
|
+
await start({
|
|
102
|
+
inputData: {
|
|
103
|
+
data: "some data"
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// Later, resume the workflow
|
|
108
|
+
const result = await resume({
|
|
109
|
+
runId: "workflow-123",
|
|
110
|
+
stepId: "review",
|
|
111
|
+
context: {
|
|
112
|
+
// This data will be available in `context.inputData`
|
|
113
|
+
feedback: "Looks good, but improve section 3"
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Execution Flow
|
|
119
|
+
|
|
120
|
+
1. The workflow runs until it hits `await suspend()` in the `review` step
|
|
121
|
+
2. The workflow state is persisted and execution pauses
|
|
122
|
+
3. Later, `run.resume()` is called with new context data
|
|
123
|
+
4. Execution continues from the point after `suspend()` in the `review` step
|
|
124
|
+
5. The new context data (`feedback`) is available to the step on the `inputData` property
|
|
125
|
+
6. The step completes and returns its result
|
|
126
|
+
7. The workflow continues with subsequent steps
|
|
127
|
+
|
|
128
|
+
## Error Handling
|
|
129
|
+
|
|
130
|
+
The resume function may throw several types of errors:
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
try {
|
|
134
|
+
await run.resume({
|
|
135
|
+
runId,
|
|
136
|
+
stepId: "stepTwo",
|
|
137
|
+
context: newData
|
|
138
|
+
});
|
|
139
|
+
} catch (error) {
|
|
140
|
+
if (error.message === "No snapshot found for workflow run") {
|
|
141
|
+
// Handle missing workflow state
|
|
142
|
+
}
|
|
143
|
+
if (error.message === "Failed to parse workflow snapshot") {
|
|
144
|
+
// Handle corrupted workflow state
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Related
|
|
150
|
+
|
|
151
|
+
- [Suspend and Resume](../../workflows/suspend-and-resume.mdx)
|
|
152
|
+
- [`suspend` Reference](./suspend.mdx)
|
|
153
|
+
- [`watch` Reference](./watch.mdx)
|
|
154
|
+
- [Workflow Class Reference](./workflow.mdx)
|
|
155
|
+
```
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: start() | Running Workflows | Mastra Docs"
|
|
3
|
+
description: "Documentation for the `start()` method in workflows, which begins execution of a workflow run."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# start()
|
|
7
|
+
|
|
8
|
+
The start function begins execution of a workflow run. It processes all steps in the defined workflow order, handling parallel execution, branching logic, and step dependencies.
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```typescript copy showLineNumbers
|
|
13
|
+
const { runId, start } = workflow.createRun();
|
|
14
|
+
const result = await start({
|
|
15
|
+
triggerData: { inputValue: 42 }
|
|
16
|
+
});
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Parameters
|
|
20
|
+
|
|
21
|
+
<PropertiesTable
|
|
22
|
+
content={[
|
|
23
|
+
{
|
|
24
|
+
name: "config",
|
|
25
|
+
type: "object",
|
|
26
|
+
description: "Configuration for starting the workflow run",
|
|
27
|
+
isOptional: true
|
|
28
|
+
}
|
|
29
|
+
]}
|
|
30
|
+
/>
|
|
31
|
+
|
|
32
|
+
### config
|
|
33
|
+
|
|
34
|
+
<PropertiesTable
|
|
35
|
+
content={[
|
|
36
|
+
{
|
|
37
|
+
name: "triggerData",
|
|
38
|
+
type: "Record<string, any>",
|
|
39
|
+
description: "Initial data that matches the workflow's triggerSchema",
|
|
40
|
+
isOptional: false
|
|
41
|
+
}
|
|
42
|
+
]}
|
|
43
|
+
/>
|
|
44
|
+
|
|
45
|
+
## Returns
|
|
46
|
+
|
|
47
|
+
<PropertiesTable
|
|
48
|
+
content={[
|
|
49
|
+
{
|
|
50
|
+
name: "results",
|
|
51
|
+
type: "Record<string, any>",
|
|
52
|
+
description: "Combined output from all completed workflow steps"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: "status",
|
|
56
|
+
type: "'completed' | 'error' | 'suspended'",
|
|
57
|
+
description: "Final status of the workflow run"
|
|
58
|
+
}
|
|
59
|
+
]}
|
|
60
|
+
/>
|
|
61
|
+
|
|
62
|
+
## Error Handling
|
|
63
|
+
|
|
64
|
+
The start function may throw several types of validation errors:
|
|
65
|
+
|
|
66
|
+
```typescript copy showLineNumbers
|
|
67
|
+
try {
|
|
68
|
+
const result = await start({ triggerData: data });
|
|
69
|
+
} catch (error) {
|
|
70
|
+
if (error instanceof ValidationError) {
|
|
71
|
+
console.log(error.type); // 'circular_dependency' | 'no_terminal_path' | 'unreachable_step'
|
|
72
|
+
console.log(error.details);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Related
|
|
78
|
+
|
|
79
|
+
- [Example: Creating a Workflow](../../../examples/workflows/creating-a-workflow.mdx)
|
|
80
|
+
- [Example: Suspend and Resume](../../../examples/workflows/suspend-and-resume.mdx)
|
|
81
|
+
- [createRun Reference](./createRun.mdx)
|
|
82
|
+
- [Workflow Class Reference](./workflow.mdx)
|
|
83
|
+
- [Step Class Reference](./step-class.mdx)
|
|
84
|
+
```
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: Step | Building Workflows | Mastra Docs"
|
|
3
|
+
description: Documentation for the Step class, which defines individual units of work within a workflow.
|
|
4
|
+
---
|
|
5
|
+
# Step
|
|
6
|
+
|
|
7
|
+
The Step class defines individual units of work within a workflow, encapsulating execution logic, data validation, and input/output handling.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
const processOrder = new Step({
|
|
13
|
+
id: "processOrder",
|
|
14
|
+
inputSchema: z.object({
|
|
15
|
+
orderId: z.string(),
|
|
16
|
+
userId: z.string()
|
|
17
|
+
}),
|
|
18
|
+
outputSchema: z.object({
|
|
19
|
+
status: z.string(),
|
|
20
|
+
orderId: z.string()
|
|
21
|
+
}),
|
|
22
|
+
execute: async ({ context, runId }) => {
|
|
23
|
+
return {
|
|
24
|
+
status: "processed",
|
|
25
|
+
orderId: context.orderId
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Constructor Parameters
|
|
32
|
+
|
|
33
|
+
<PropertiesTable
|
|
34
|
+
content={[
|
|
35
|
+
{
|
|
36
|
+
name: "id",
|
|
37
|
+
type: "string",
|
|
38
|
+
description: "Unique identifier for the step",
|
|
39
|
+
required: true
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: "inputSchema",
|
|
43
|
+
type: "z.ZodSchema",
|
|
44
|
+
description: "Zod schema to validate input data before execution",
|
|
45
|
+
required: false
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: "outputSchema",
|
|
49
|
+
type: "z.ZodSchema",
|
|
50
|
+
description: "Zod schema to validate step output data",
|
|
51
|
+
required: false
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: "payload",
|
|
55
|
+
type: "Record<string, any>",
|
|
56
|
+
description: "Static data to be merged with variables",
|
|
57
|
+
required: false
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: "execute",
|
|
61
|
+
type: "(params: ExecuteParams) => Promise<any>",
|
|
62
|
+
description: "Async function containing step logic",
|
|
63
|
+
required: true
|
|
64
|
+
}
|
|
65
|
+
]}
|
|
66
|
+
/>
|
|
67
|
+
|
|
68
|
+
### ExecuteParams
|
|
69
|
+
|
|
70
|
+
<PropertiesTable
|
|
71
|
+
content={[
|
|
72
|
+
{
|
|
73
|
+
name: "context",
|
|
74
|
+
type: "StepContext",
|
|
75
|
+
description: "Access to workflow context and step results"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: "runId",
|
|
79
|
+
type: "string",
|
|
80
|
+
description: "Unique identifier for current workflow run"
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
name: "suspend",
|
|
84
|
+
type: "() => Promise<void>",
|
|
85
|
+
description: "Function to suspend step execution"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: "mastra",
|
|
89
|
+
type: "Mastra",
|
|
90
|
+
description: "Access to Mastra instance"
|
|
91
|
+
}
|
|
92
|
+
]}
|
|
93
|
+
/>
|
|
94
|
+
|
|
95
|
+
## Related
|
|
96
|
+
|
|
97
|
+
- [Workflow Reference](./workflow.mdx)
|
|
98
|
+
- [Step Configuration Guide](../../workflows/steps.mdx)
|
|
99
|
+
- [Control Flow Guide](../../workflows/control-flow.mdx)
|
|
100
|
+
```
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: StepCondition | Building Workflows | Mastra"
|
|
3
|
+
description: Documentation for the step condition class in workflows, which determines whether a step should execute based on the output of previous steps or trigger data.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# StepCondition
|
|
7
|
+
|
|
8
|
+
Conditions determine whether a step should execute based on the output of previous steps or trigger data.
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
There are three ways to specify conditions: function, query object, and simple path comparison.
|
|
13
|
+
|
|
14
|
+
### 1. Function Condition
|
|
15
|
+
```typescript copy showLineNumbers
|
|
16
|
+
workflow.step(processOrder, {
|
|
17
|
+
when: async ({ context }) => {
|
|
18
|
+
const auth = context?.getStepResult<{status: string}>("auth");
|
|
19
|
+
return auth?.status === "authenticated";
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### 2. Query Object
|
|
25
|
+
```typescript copy showLineNumbers
|
|
26
|
+
workflow.step(processOrder, {
|
|
27
|
+
when: {
|
|
28
|
+
ref: { step: 'auth', path: 'status' },
|
|
29
|
+
query: { $eq: 'authenticated' }
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### 3. Simple Path Comparison
|
|
35
|
+
```typescript copy showLineNumbers
|
|
36
|
+
workflow.step(processOrder, {
|
|
37
|
+
when: {
|
|
38
|
+
"auth.status": "authenticated"
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Based on the type of condition, the workflow runner will try to match the condition to one of these types.
|
|
44
|
+
|
|
45
|
+
1. Simple Path Condition (when there's a dot in the key)
|
|
46
|
+
2. Base/Query Condition (when there's a 'ref' property)
|
|
47
|
+
3. Function Condition (when it's an async function)
|
|
48
|
+
|
|
49
|
+
## StepCondition
|
|
50
|
+
|
|
51
|
+
<PropertiesTable
|
|
52
|
+
content={[
|
|
53
|
+
{
|
|
54
|
+
name: "ref",
|
|
55
|
+
type: "{ stepId: string | 'trigger'; path: string }",
|
|
56
|
+
description: "Reference to step output value. stepId can be a step ID or 'trigger' for initial data. path specifies location of value in step result",
|
|
57
|
+
isOptional: false
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: "query",
|
|
61
|
+
type: "Query<any>",
|
|
62
|
+
description: "MongoDB-style query using sift operators ($eq, $gt, etc)",
|
|
63
|
+
isOptional: false
|
|
64
|
+
}
|
|
65
|
+
]}
|
|
66
|
+
/>
|
|
67
|
+
|
|
68
|
+
## Query
|
|
69
|
+
|
|
70
|
+
The Query object provides MongoDB-style query operators for comparing values from previous steps or trigger data. It supports basic comparison operators like `$eq`, `$gt`, `$lt` as well as array operators like `$in` and `$nin`, and can be combined with and/or operators for complex conditions.
|
|
71
|
+
|
|
72
|
+
This query syntax allows for readable conditional logic for determining whether a step should execute.
|
|
73
|
+
|
|
74
|
+
<PropertiesTable
|
|
75
|
+
content={[
|
|
76
|
+
{
|
|
77
|
+
name: "$eq",
|
|
78
|
+
type: "any",
|
|
79
|
+
description: "Equal to value"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: "$ne",
|
|
83
|
+
type: "any",
|
|
84
|
+
description: "Not equal to value"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: "$gt",
|
|
88
|
+
type: "number",
|
|
89
|
+
description: "Greater than value"
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: "$gte",
|
|
93
|
+
type: "number",
|
|
94
|
+
description: "Greater than or equal to value"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: "$lt",
|
|
98
|
+
type: "number",
|
|
99
|
+
description: "Less than value"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: "$lte",
|
|
103
|
+
type: "number",
|
|
104
|
+
description: "Less than or equal to value"
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: "$in",
|
|
108
|
+
type: "any[]",
|
|
109
|
+
description: "Value exists in array"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: "$nin",
|
|
113
|
+
type: "any[]",
|
|
114
|
+
description: "Value does not exist in array"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
name: "and",
|
|
118
|
+
type: "StepCondition[]",
|
|
119
|
+
description: "Array of conditions that must all be true"
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
name: "or",
|
|
123
|
+
type: "StepCondition[]",
|
|
124
|
+
description: "Array of conditions where at least one must be true"
|
|
125
|
+
}
|
|
126
|
+
]}
|
|
127
|
+
/>
|
|
128
|
+
|
|
129
|
+
## Related
|
|
130
|
+
|
|
131
|
+
- [Step Options Reference](./step-options.mdx)
|
|
132
|
+
- [Step Function Reference](./step-function.mdx)
|
|
133
|
+
- [Control Flow Guide](../../workflows/control-flow.mdx)
|
|
134
|
+
```
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: Workflow.step() | Workflows | Mastra Docs"
|
|
3
|
+
description: Documentation for the `.step()` method in workflows, which adds a new step to the workflow.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Workflow.step()
|
|
7
|
+
|
|
8
|
+
The `.step()` method adds a new step to the workflow, optionally configuring its variables and execution conditions.
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
workflow.step({
|
|
14
|
+
id: "stepTwo",
|
|
15
|
+
outputSchema: z.object({
|
|
16
|
+
result: z.number()
|
|
17
|
+
}),
|
|
18
|
+
execute: async ({ context }) => {
|
|
19
|
+
return { result: 42 };
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Parameters
|
|
25
|
+
|
|
26
|
+
<PropertiesTable
|
|
27
|
+
content={[
|
|
28
|
+
{
|
|
29
|
+
name: "stepConfig",
|
|
30
|
+
type: "Step | StepDefinition | string",
|
|
31
|
+
description: "Step instance, configuration object, or step ID to add to workflow",
|
|
32
|
+
isOptional: false
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: "options",
|
|
36
|
+
type: "StepOptions",
|
|
37
|
+
description: "Optional configuration for step execution",
|
|
38
|
+
isOptional: true
|
|
39
|
+
}
|
|
40
|
+
]}
|
|
41
|
+
/>
|
|
42
|
+
|
|
43
|
+
### StepDefinition
|
|
44
|
+
|
|
45
|
+
<PropertiesTable
|
|
46
|
+
content={[
|
|
47
|
+
{
|
|
48
|
+
name: "id",
|
|
49
|
+
type: "string",
|
|
50
|
+
description: "Unique identifier for the step",
|
|
51
|
+
isOptional: false
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: "outputSchema",
|
|
55
|
+
type: "z.ZodSchema",
|
|
56
|
+
description: "Schema for validating step output",
|
|
57
|
+
isOptional: true
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: "execute",
|
|
61
|
+
type: "(params: ExecuteParams) => Promise<any>",
|
|
62
|
+
description: "Function containing step logic",
|
|
63
|
+
isOptional: false
|
|
64
|
+
}
|
|
65
|
+
]}
|
|
66
|
+
/>
|
|
67
|
+
|
|
68
|
+
### StepOptions
|
|
69
|
+
|
|
70
|
+
<PropertiesTable
|
|
71
|
+
content={[
|
|
72
|
+
{
|
|
73
|
+
name: "variables",
|
|
74
|
+
type: "Record<string, VariableRef>",
|
|
75
|
+
description: "Map of variable names to their source references",
|
|
76
|
+
isOptional: true
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: "when",
|
|
80
|
+
type: "StepCondition",
|
|
81
|
+
description: "Condition that must be met for step to execute",
|
|
82
|
+
isOptional: true
|
|
83
|
+
}
|
|
84
|
+
]}
|
|
85
|
+
/>
|
|
86
|
+
|
|
87
|
+
## Related
|
|
88
|
+
- [Basic Usage with Step Instance](../../workflows/steps.mdx)
|
|
89
|
+
- [Step Class Reference](./step-class.mdx)
|
|
90
|
+
- [Workflow Class Reference](./workflow.mdx)
|
|
91
|
+
- [Control Flow Guide](../../workflows/control-flow.mdx)
|
|
92
|
+
```
|