@mastra/mcp-docs-server 1.0.0-beta.13 → 1.0.0-beta.14
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%2Fagent-builder.md +19 -19
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +28 -28
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +98 -98
- package/.docs/organized/changelogs/%40mastra%2Fconvex.md +30 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +171 -171
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +15 -15
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +16 -16
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +15 -15
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +22 -22
- package/.docs/organized/changelogs/%40mastra%2Frag.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Freact.md +9 -2
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +94 -94
- package/.docs/organized/changelogs/create-mastra.md +3 -3
- package/.docs/organized/changelogs/mastra.md +17 -17
- package/.docs/organized/code-examples/agent-v6.md +151 -0
- package/.docs/organized/code-examples/ai-elements.md +1 -1
- package/.docs/raw/agents/adding-voice.mdx +2 -3
- package/.docs/raw/agents/agent-approval.mdx +5 -6
- package/.docs/raw/agents/agent-memory.mdx +22 -30
- package/.docs/raw/agents/guardrails.mdx +60 -50
- package/.docs/raw/agents/networks.mdx +8 -12
- package/.docs/raw/agents/overview.mdx +39 -23
- package/.docs/raw/agents/processors.mdx +20 -19
- package/.docs/raw/agents/structured-output.mdx +11 -7
- package/.docs/raw/agents/using-tools.mdx +4 -5
- package/.docs/raw/deployment/mastra-server.mdx +3 -3
- package/.docs/raw/deployment/overview.mdx +7 -0
- package/.docs/raw/deployment/web-framework.mdx +4 -6
- package/.docs/raw/evals/custom-scorers.mdx +9 -6
- package/.docs/raw/evals/overview.mdx +3 -6
- package/.docs/raw/evals/running-in-ci.mdx +2 -2
- package/.docs/raw/getting-started/manual-install.mdx +20 -20
- package/.docs/raw/getting-started/mcp-docs-server.mdx +2 -2
- package/.docs/raw/guides/agent-frameworks/ai-sdk.mdx +4 -4
- package/.docs/raw/guides/build-your-ui/ai-sdk-ui.mdx +30 -30
- package/.docs/raw/guides/build-your-ui/assistant-ui.mdx +8 -8
- package/.docs/raw/guides/build-your-ui/copilotkit.mdx +11 -11
- package/.docs/raw/guides/deployment/amazon-ec2.mdx +9 -9
- package/.docs/raw/guides/deployment/aws-lambda.mdx +11 -11
- package/.docs/raw/guides/deployment/azure-app-services.mdx +2 -2
- package/.docs/raw/guides/deployment/cloudflare-deployer.mdx +5 -6
- package/.docs/raw/guides/deployment/digital-ocean.mdx +10 -10
- package/.docs/raw/guides/deployment/index.mdx +1 -1
- package/.docs/raw/guides/deployment/inngest.mdx +386 -0
- package/.docs/raw/guides/deployment/netlify-deployer.mdx +4 -4
- package/.docs/raw/guides/deployment/vercel-deployer.mdx +5 -6
- package/.docs/raw/guides/getting-started/astro.mdx +292 -451
- package/.docs/raw/guides/getting-started/express.mdx +7 -7
- package/.docs/raw/guides/getting-started/hono.mdx +18 -18
- package/.docs/raw/guides/getting-started/next-js.mdx +19 -20
- package/.docs/raw/guides/getting-started/quickstart.mdx +4 -4
- package/.docs/raw/guides/getting-started/sveltekit.mdx +238 -409
- package/.docs/raw/guides/getting-started/vite-react.mdx +21 -21
- package/.docs/raw/guides/guide/ai-recruiter.mdx +10 -10
- package/.docs/raw/guides/guide/chef-michel.mdx +9 -11
- package/.docs/raw/guides/guide/notes-mcp-server.mdx +15 -15
- package/.docs/raw/guides/guide/research-assistant.mdx +13 -13
- package/.docs/raw/guides/guide/stock-agent.mdx +5 -5
- package/.docs/raw/guides/guide/web-search.mdx +8 -8
- package/.docs/raw/guides/guide/whatsapp-chat-bot.mdx +7 -7
- package/.docs/raw/guides/migrations/ai-sdk-v4-to-v5.mdx +2 -2
- package/.docs/raw/guides/migrations/upgrade-to-v1/agent.mdx +1 -1
- package/.docs/raw/guides/migrations/upgrade-to-v1/workflows.mdx +0 -2
- package/.docs/raw/guides/migrations/vnext-to-standard-apis.mdx +21 -23
- package/.docs/raw/index.mdx +2 -2
- package/.docs/raw/mastra-cloud/setting-up.mdx +6 -2
- package/.docs/raw/mcp/overview.mdx +31 -13
- package/.docs/raw/mcp/publishing-mcp-server.mdx +2 -2
- package/.docs/raw/memory/memory-processors.mdx +9 -9
- package/.docs/raw/memory/message-history.mdx +69 -0
- package/.docs/raw/memory/overview.mdx +34 -76
- package/.docs/raw/memory/semantic-recall.mdx +58 -49
- package/.docs/raw/memory/storage.mdx +188 -0
- package/.docs/raw/memory/working-memory.mdx +7 -7
- package/.docs/raw/observability/logging.mdx +9 -10
- package/.docs/raw/observability/overview.mdx +0 -1
- package/.docs/raw/observability/tracing/bridges/otel.mdx +2 -2
- package/.docs/raw/observability/tracing/exporters/default.mdx +3 -3
- package/.docs/raw/observability/tracing/exporters/langfuse.mdx +1 -2
- package/.docs/raw/observability/tracing/overview.mdx +23 -25
- package/.docs/raw/observability/tracing/processors/sensitive-data-filter.mdx +3 -3
- package/.docs/raw/rag/chunking-and-embedding.mdx +6 -6
- package/.docs/raw/rag/graph-rag.mdx +7 -7
- package/.docs/raw/rag/overview.mdx +1 -1
- package/.docs/raw/rag/retrieval.mdx +21 -22
- package/.docs/raw/rag/vector-databases.mdx +22 -22
- package/.docs/raw/reference/agents/agent.mdx +3 -3
- package/.docs/raw/reference/agents/generate.mdx +1 -1
- package/.docs/raw/reference/agents/generateLegacy.mdx +2 -2
- package/.docs/raw/reference/agents/getDefaultGenerateOptions.mdx +2 -2
- package/.docs/raw/reference/agents/getDefaultOptions.mdx +2 -2
- package/.docs/raw/reference/agents/getDefaultStreamOptions.mdx +2 -2
- package/.docs/raw/reference/agents/getDescription.mdx +1 -1
- package/.docs/raw/reference/agents/getInstructions.mdx +2 -2
- package/.docs/raw/reference/agents/getLLM.mdx +2 -2
- package/.docs/raw/reference/agents/getMemory.mdx +2 -2
- package/.docs/raw/reference/agents/getModel.mdx +2 -2
- package/.docs/raw/reference/agents/getTools.mdx +2 -2
- package/.docs/raw/reference/agents/getVoice.mdx +2 -2
- package/.docs/raw/reference/agents/listAgents.mdx +2 -2
- package/.docs/raw/reference/agents/listScorers.mdx +2 -2
- package/.docs/raw/reference/agents/listTools.mdx +2 -2
- package/.docs/raw/reference/agents/listWorkflows.mdx +2 -2
- package/.docs/raw/reference/agents/network.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/chat-route.mdx +2 -2
- package/.docs/raw/reference/ai-sdk/handle-chat-stream.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/handle-network-stream.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/handle-workflow-stream.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/network-route.mdx +2 -2
- package/.docs/raw/reference/ai-sdk/to-ai-sdk-stream.mdx +6 -6
- package/.docs/raw/reference/ai-sdk/to-ai-sdk-v4-messages.mdx +3 -3
- package/.docs/raw/reference/ai-sdk/to-ai-sdk-v5-messages.mdx +3 -3
- package/.docs/raw/reference/ai-sdk/with-mastra.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/workflow-route.mdx +2 -2
- package/.docs/raw/reference/auth/auth0.mdx +1 -2
- package/.docs/raw/reference/auth/clerk.mdx +1 -2
- package/.docs/raw/reference/auth/firebase.mdx +2 -4
- package/.docs/raw/reference/auth/jwt.mdx +1 -2
- package/.docs/raw/reference/auth/supabase.mdx +1 -2
- package/.docs/raw/reference/auth/workos.mdx +1 -2
- package/.docs/raw/reference/cli/create-mastra.mdx +10 -10
- package/.docs/raw/reference/cli/mastra.mdx +9 -9
- package/.docs/raw/reference/client-js/agents.mdx +1 -2
- package/.docs/raw/reference/client-js/mastra-client.mdx +1 -1
- package/.docs/raw/reference/core/getAgent.mdx +1 -1
- package/.docs/raw/reference/core/getAgentById.mdx +1 -1
- package/.docs/raw/reference/core/getDeployer.mdx +1 -1
- package/.docs/raw/reference/core/getLogger.mdx +1 -1
- package/.docs/raw/reference/core/getMCPServer.mdx +1 -1
- package/.docs/raw/reference/core/getMCPServerById.mdx +1 -1
- package/.docs/raw/reference/core/getMemory.mdx +2 -2
- package/.docs/raw/reference/core/getServer.mdx +1 -1
- package/.docs/raw/reference/core/getStorage.mdx +2 -2
- package/.docs/raw/reference/core/getStoredAgentById.mdx +3 -3
- package/.docs/raw/reference/core/getTelemetry.mdx +1 -1
- package/.docs/raw/reference/core/getVector.mdx +1 -1
- package/.docs/raw/reference/core/getWorkflow.mdx +1 -1
- package/.docs/raw/reference/core/listAgents.mdx +1 -1
- package/.docs/raw/reference/core/listLogs.mdx +1 -1
- package/.docs/raw/reference/core/listLogsByRunId.mdx +1 -1
- package/.docs/raw/reference/core/listMCPServers.mdx +1 -1
- package/.docs/raw/reference/core/listMemory.mdx +2 -2
- package/.docs/raw/reference/core/listStoredAgents.mdx +4 -4
- package/.docs/raw/reference/core/listVectors.mdx +1 -1
- package/.docs/raw/reference/core/listWorkflows.mdx +1 -1
- package/.docs/raw/reference/core/setLogger.mdx +1 -1
- package/.docs/raw/reference/core/setStorage.mdx +2 -2
- package/.docs/raw/reference/core/setTelemetry.mdx +1 -1
- package/.docs/raw/reference/deployer/cloudflare.mdx +1 -2
- package/.docs/raw/reference/deployer/deployer.mdx +0 -1
- package/.docs/raw/reference/deployer/netlify.mdx +1 -1
- package/.docs/raw/reference/deployer/vercel.mdx +2 -4
- package/.docs/raw/reference/evals/answer-relevancy.mdx +1 -1
- package/.docs/raw/reference/evals/answer-similarity.mdx +1 -1
- package/.docs/raw/reference/evals/bias.mdx +1 -1
- package/.docs/raw/reference/evals/completeness.mdx +1 -1
- package/.docs/raw/reference/evals/content-similarity.mdx +1 -1
- package/.docs/raw/reference/evals/context-precision.mdx +1 -1
- package/.docs/raw/reference/evals/faithfulness.mdx +1 -1
- package/.docs/raw/reference/evals/hallucination.mdx +1 -1
- package/.docs/raw/reference/evals/keyword-coverage.mdx +1 -1
- package/.docs/raw/reference/evals/prompt-alignment.mdx +7 -7
- package/.docs/raw/reference/evals/textual-difference.mdx +1 -1
- package/.docs/raw/reference/evals/tone-consistency.mdx +1 -1
- package/.docs/raw/reference/evals/tool-call-accuracy.mdx +10 -10
- package/.docs/raw/reference/evals/toxicity.mdx +1 -1
- package/.docs/raw/reference/logging/pino-logger.mdx +6 -7
- package/.docs/raw/reference/memory/createThread.mdx +2 -2
- package/.docs/raw/reference/memory/deleteMessages.mdx +2 -2
- package/.docs/raw/reference/memory/listThreadsByResourceId.mdx +2 -2
- package/.docs/raw/reference/memory/memory-class.mdx +3 -3
- package/.docs/raw/reference/memory/query.mdx +2 -2
- package/.docs/raw/reference/memory/recall.mdx +2 -2
- package/.docs/raw/reference/observability/tracing/exporters/langfuse.mdx +1 -1
- package/.docs/raw/reference/processors/batch-parts-processor.mdx +2 -2
- package/.docs/raw/reference/processors/language-detector.mdx +2 -2
- package/.docs/raw/reference/processors/message-history-processor.mdx +2 -2
- package/.docs/raw/reference/processors/moderation-processor.mdx +3 -3
- package/.docs/raw/reference/processors/pii-detector.mdx +3 -3
- package/.docs/raw/reference/processors/processor-interface.mdx +13 -13
- package/.docs/raw/reference/processors/prompt-injection-detector.mdx +2 -2
- package/.docs/raw/reference/processors/semantic-recall-processor.mdx +2 -2
- package/.docs/raw/reference/processors/system-prompt-scrubber.mdx +2 -2
- package/.docs/raw/reference/processors/token-limiter-processor.mdx +2 -2
- package/.docs/raw/reference/processors/tool-call-filter.mdx +3 -3
- package/.docs/raw/reference/processors/unicode-normalizer.mdx +2 -2
- package/.docs/raw/reference/processors/working-memory-processor.mdx +3 -3
- package/.docs/raw/reference/rag/chunk.mdx +1 -1
- package/.docs/raw/reference/rag/extract-params.mdx +2 -2
- package/.docs/raw/reference/rag/metadata-filters.mdx +7 -7
- package/.docs/raw/reference/server/create-route.mdx +13 -13
- package/.docs/raw/reference/server/express-adapter.mdx +6 -7
- package/.docs/raw/reference/server/hono-adapter.mdx +6 -7
- package/.docs/raw/reference/server/mastra-server.mdx +20 -20
- package/.docs/raw/reference/storage/cloudflare-d1.mdx +3 -3
- package/.docs/raw/reference/storage/cloudflare.mdx +2 -2
- package/.docs/raw/reference/storage/convex.mdx +6 -6
- package/.docs/raw/reference/storage/dynamodb.mdx +4 -4
- package/.docs/raw/reference/storage/lance.mdx +3 -3
- package/.docs/raw/reference/storage/libsql.mdx +69 -54
- package/.docs/raw/reference/storage/mongodb.mdx +80 -7
- package/.docs/raw/reference/storage/mssql.mdx +4 -4
- package/.docs/raw/{memory → reference}/storage/overview.mdx +12 -110
- package/.docs/raw/reference/storage/postgresql.mdx +78 -7
- package/.docs/raw/reference/storage/upstash.mdx +74 -2
- package/.docs/raw/reference/streaming/agents/stream.mdx +5 -5
- package/.docs/raw/reference/streaming/agents/streamLegacy.mdx +2 -2
- package/.docs/raw/reference/streaming/workflows/observeStream.mdx +1 -1
- package/.docs/raw/reference/streaming/workflows/resumeStream.mdx +1 -1
- package/.docs/raw/reference/streaming/workflows/stream.mdx +2 -2
- package/.docs/raw/reference/streaming/workflows/timeTravelStream.mdx +4 -4
- package/.docs/raw/reference/templates/overview.mdx +1 -2
- package/.docs/raw/reference/tools/create-tool.mdx +1 -4
- package/.docs/raw/reference/tools/vector-query-tool.mdx +1 -1
- package/.docs/raw/reference/vectors/astra.mdx +3 -3
- package/.docs/raw/reference/vectors/chroma.mdx +3 -3
- package/.docs/raw/reference/vectors/convex.mdx +12 -12
- package/.docs/raw/reference/vectors/couchbase.mdx +5 -5
- package/.docs/raw/reference/vectors/duckdb.mdx +10 -10
- package/.docs/raw/reference/vectors/elasticsearch.mdx +4 -4
- package/.docs/raw/reference/vectors/lance.mdx +4 -4
- package/.docs/raw/reference/vectors/libsql.mdx +61 -11
- package/.docs/raw/reference/vectors/mongodb.mdx +58 -5
- package/.docs/raw/reference/vectors/pg.mdx +53 -6
- package/.docs/raw/reference/vectors/pinecone.mdx +3 -3
- package/.docs/raw/reference/vectors/qdrant.mdx +3 -3
- package/.docs/raw/reference/vectors/s3vectors.mdx +6 -6
- package/.docs/raw/reference/vectors/turbopuffer.mdx +4 -4
- package/.docs/raw/reference/vectors/upstash.mdx +55 -6
- package/.docs/raw/reference/vectors/vectorize.mdx +3 -3
- package/.docs/raw/reference/workflows/run-methods/cancel.mdx +2 -2
- package/.docs/raw/reference/workflows/run-methods/restart.mdx +1 -3
- package/.docs/raw/reference/workflows/run-methods/resume.mdx +2 -2
- package/.docs/raw/reference/workflows/run-methods/start.mdx +2 -2
- package/.docs/raw/reference/workflows/run-methods/startAsync.mdx +2 -2
- package/.docs/raw/reference/workflows/run-methods/timeTravel.mdx +5 -5
- package/.docs/raw/reference/workflows/run.mdx +1 -1
- package/.docs/raw/reference/workflows/step.mdx +3 -3
- package/.docs/raw/reference/workflows/workflow-methods/branch.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/commit.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/create-run.mdx +3 -3
- package/.docs/raw/reference/workflows/workflow-methods/dountil.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/dowhile.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/foreach.mdx +6 -6
- package/.docs/raw/reference/workflows/workflow-methods/map.mdx +7 -7
- package/.docs/raw/reference/workflows/workflow-methods/parallel.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/sendEvent.mdx +2 -2
- package/.docs/raw/reference/workflows/workflow-methods/sleep.mdx +2 -2
- package/.docs/raw/reference/workflows/workflow-methods/sleepUntil.mdx +2 -2
- package/.docs/raw/reference/workflows/workflow-methods/then.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/waitForEvent.mdx +2 -2
- package/.docs/raw/reference/workflows/workflow.mdx +3 -3
- package/.docs/raw/server/auth/auth0.mdx +20 -14
- package/.docs/raw/server/auth/clerk.mdx +16 -9
- package/.docs/raw/server/auth/firebase.mdx +21 -15
- package/.docs/raw/server/auth/jwt.mdx +14 -7
- package/.docs/raw/server/auth/supabase.mdx +16 -9
- package/.docs/raw/server/auth/workos.mdx +19 -13
- package/.docs/raw/server/custom-adapters.mdx +10 -10
- package/.docs/raw/server/custom-api-routes.mdx +2 -4
- package/.docs/raw/server/mastra-client.mdx +24 -13
- package/.docs/raw/server/mastra-server.mdx +3 -3
- package/.docs/raw/server/middleware.mdx +7 -7
- package/.docs/raw/server/request-context.mdx +31 -30
- package/.docs/raw/server/server-adapters.mdx +6 -6
- package/.docs/raw/streaming/events.mdx +14 -7
- package/.docs/raw/streaming/overview.mdx +21 -10
- package/.docs/raw/streaming/tool-streaming.mdx +6 -6
- package/.docs/raw/streaming/workflow-streaming.mdx +6 -8
- package/.docs/raw/tools-mcp/advanced-usage.mdx +2 -2
- package/.docs/raw/tools-mcp/mcp-overview.mdx +31 -12
- package/.docs/raw/tools-mcp/overview.mdx +9 -10
- package/.docs/raw/voice/overview.mdx +1 -1
- package/.docs/raw/workflows/agents-and-tools.mdx +28 -19
- package/.docs/raw/workflows/control-flow.mdx +27 -40
- package/.docs/raw/workflows/error-handling.mdx +15 -22
- package/.docs/raw/workflows/human-in-the-loop.mdx +6 -7
- package/.docs/raw/workflows/inngest-workflow.mdx +8 -9
- package/.docs/raw/workflows/input-data-mapping.mdx +7 -7
- package/.docs/raw/workflows/overview.mdx +33 -22
- package/.docs/raw/workflows/snapshots.mdx +14 -44
- package/.docs/raw/workflows/suspend-and-resume.mdx +7 -7
- package/.docs/raw/workflows/time-travel.mdx +16 -16
- package/.docs/raw/workflows/workflow-state.mdx +5 -8
- package/CHANGELOG.md +9 -0
- package/dist/logger.d.ts +3 -0
- package/dist/logger.d.ts.map +1 -1
- package/dist/stdio.js +53 -0
- package/package.json +4 -4
- package/.docs/raw/memory/conversation-history.mdx +0 -24
- package/.docs/raw/memory/storage/memory-with-libsql.mdx +0 -140
- package/.docs/raw/memory/storage/memory-with-mongodb.mdx +0 -150
- package/.docs/raw/memory/storage/memory-with-pg.mdx +0 -138
- package/.docs/raw/memory/storage/memory-with-upstash.mdx +0 -146
- package/.docs/raw/memory/threads-and-resources.mdx +0 -95
|
@@ -22,9 +22,8 @@ Use `.then()` to run steps in order, allowing each step to access the result of
|
|
|
22
22
|
|
|
23
23
|

|
|
24
24
|
|
|
25
|
-
```typescript {
|
|
25
|
+
```typescript {27-28} title="src/mastra/workflows/test-workflow.ts"
|
|
26
26
|
const step1 = createStep({
|
|
27
|
-
//...
|
|
28
27
|
inputSchema: z.object({
|
|
29
28
|
message: z.string()
|
|
30
29
|
}),
|
|
@@ -34,7 +33,6 @@ const step1 = createStep({
|
|
|
34
33
|
});
|
|
35
34
|
|
|
36
35
|
const step2 = createStep({
|
|
37
|
-
// ...
|
|
38
36
|
inputSchema: z.object({
|
|
39
37
|
formatted: z.string()
|
|
40
38
|
}),
|
|
@@ -44,7 +42,6 @@ const step2 = createStep({
|
|
|
44
42
|
});
|
|
45
43
|
|
|
46
44
|
export const testWorkflow = createWorkflow({
|
|
47
|
-
// ...
|
|
48
45
|
inputSchema: z.object({
|
|
49
46
|
message: z.string()
|
|
50
47
|
}),
|
|
@@ -63,15 +60,13 @@ Use `.parallel()` to run steps at the same time. All parallel steps must complet
|
|
|
63
60
|
|
|
64
61
|

|
|
65
62
|
|
|
66
|
-
```typescript {
|
|
63
|
+
```typescript {39} title="src/mastra/workflows/test-workflow.ts"
|
|
67
64
|
const step1 = createStep({
|
|
68
65
|
id: "step-1",
|
|
69
|
-
// ...
|
|
70
66
|
});
|
|
71
67
|
|
|
72
68
|
const step2 = createStep({
|
|
73
69
|
id: "step-2",
|
|
74
|
-
// ...
|
|
75
70
|
});
|
|
76
71
|
|
|
77
72
|
const step3 = createStep({
|
|
@@ -97,7 +92,6 @@ const step3 = createStep({
|
|
|
97
92
|
});
|
|
98
93
|
|
|
99
94
|
export const testWorkflow = createWorkflow({
|
|
100
|
-
// ...
|
|
101
95
|
inputSchema: z.object({
|
|
102
96
|
message: z.string()
|
|
103
97
|
}),
|
|
@@ -116,7 +110,7 @@ export const testWorkflow = createWorkflow({
|
|
|
116
110
|
|
|
117
111
|
When steps run in parallel, the output is an object where each key is the step's `id` and the value is that step's output. This allows you to access each parallel step's result independently.
|
|
118
112
|
|
|
119
|
-
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
113
|
+
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
120
114
|
const step1 = createStep({
|
|
121
115
|
id: "format-step",
|
|
122
116
|
inputSchema: z.object({ message: z.string() }),
|
|
@@ -176,7 +170,11 @@ export const testWorkflow = createWorkflow({
|
|
|
176
170
|
- The next step receives an object containing all parallel step outputs
|
|
177
171
|
- You must define the `inputSchema` of the following step to match this structure
|
|
178
172
|
|
|
179
|
-
|
|
173
|
+
:::info
|
|
174
|
+
|
|
175
|
+
Visit [Choosing the right pattern](#choosing-the-right-pattern) to understand when to use `.parallel()` vs `.foreach()`.
|
|
176
|
+
|
|
177
|
+
:::
|
|
180
178
|
|
|
181
179
|
## Conditional logic with `.branch()`
|
|
182
180
|
|
|
@@ -184,11 +182,10 @@ Use `.branch()` to choose which step to run based on a condition. All steps in a
|
|
|
184
182
|
|
|
185
183
|

|
|
186
184
|
|
|
187
|
-
```typescript {33
|
|
185
|
+
```typescript {30-33} title="src/mastra/workflows/test-workflow.ts"
|
|
188
186
|
const step1 = createStep({...})
|
|
189
187
|
|
|
190
188
|
const stepA = createStep({
|
|
191
|
-
// ...
|
|
192
189
|
inputSchema: z.object({
|
|
193
190
|
value: z.number()
|
|
194
191
|
}),
|
|
@@ -198,7 +195,6 @@ const stepA = createStep({
|
|
|
198
195
|
});
|
|
199
196
|
|
|
200
197
|
const stepB = createStep({
|
|
201
|
-
// ...
|
|
202
198
|
inputSchema: z.object({
|
|
203
199
|
value: z.number()
|
|
204
200
|
}),
|
|
@@ -208,7 +204,6 @@ const stepB = createStep({
|
|
|
208
204
|
});
|
|
209
205
|
|
|
210
206
|
export const testWorkflow = createWorkflow({
|
|
211
|
-
// ...
|
|
212
207
|
inputSchema: z.object({
|
|
213
208
|
value: z.number()
|
|
214
209
|
}),
|
|
@@ -228,7 +223,7 @@ export const testWorkflow = createWorkflow({
|
|
|
228
223
|
|
|
229
224
|
When using conditional branching, only one branch executes based on which condition evaluates to `true` first. The output structure is similar to `.parallel()`, where the result is keyed by the executed step's `id`.
|
|
230
225
|
|
|
231
|
-
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
226
|
+
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
232
227
|
const step1 = createStep({
|
|
233
228
|
id: "initial-step",
|
|
234
229
|
inputSchema: z.object({ value: z.number() }),
|
|
@@ -309,7 +304,7 @@ When using `.then()`, `.parallel()`, or `.branch()`, it is sometimes necessary t
|
|
|
309
304
|
|
|
310
305
|

|
|
311
306
|
|
|
312
|
-
```typescript {9} title="src/mastra/workflows/test-workflow.ts"
|
|
307
|
+
```typescript {9} title="src/mastra/workflows/test-workflow.ts"
|
|
313
308
|
const step1 = createStep({...});
|
|
314
309
|
const step2 = createStep({...});
|
|
315
310
|
|
|
@@ -337,7 +332,7 @@ The `.map()` method provides additional helper functions for more complex mappin
|
|
|
337
332
|
|
|
338
333
|
When working with `.parallel()` or `.branch()` outputs, you can use `.map()` to transform the data structure before passing it to the next step. This is especially useful when you need to flatten or restructure the output.
|
|
339
334
|
|
|
340
|
-
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
335
|
+
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
341
336
|
export const testWorkflow = createWorkflow({...})
|
|
342
337
|
.parallel([step1, step2])
|
|
343
338
|
.map(async ({ inputData }) => {
|
|
@@ -352,7 +347,7 @@ export const testWorkflow = createWorkflow({...})
|
|
|
352
347
|
|
|
353
348
|
You can also use the helper functions provided by `.map()`:
|
|
354
349
|
|
|
355
|
-
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
350
|
+
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
356
351
|
export const testWorkflow = createWorkflow({...})
|
|
357
352
|
.branch([
|
|
358
353
|
[condition1, stepA],
|
|
@@ -380,11 +375,10 @@ Use `.dountil()` to run a step repeatedly until a condition becomes true.
|
|
|
380
375
|
|
|
381
376
|

|
|
382
377
|
|
|
383
|
-
```typescript {
|
|
378
|
+
```typescript {14} title="src/mastra/workflows/test-workflow.ts"
|
|
384
379
|
const step1 = createStep({...});
|
|
385
380
|
|
|
386
381
|
const step2 = createStep({
|
|
387
|
-
// ...
|
|
388
382
|
execute: async ({ inputData }) => {
|
|
389
383
|
const { number } = inputData;
|
|
390
384
|
return {
|
|
@@ -393,9 +387,7 @@ const step2 = createStep({
|
|
|
393
387
|
}
|
|
394
388
|
});
|
|
395
389
|
|
|
396
|
-
export const testWorkflow = createWorkflow({
|
|
397
|
-
// ...
|
|
398
|
-
})
|
|
390
|
+
export const testWorkflow = createWorkflow({})
|
|
399
391
|
.then(step1)
|
|
400
392
|
.dountil(step2, async ({ inputData: { number } }) => number > 10)
|
|
401
393
|
.commit();
|
|
@@ -407,11 +399,10 @@ Use `.dowhile()` to run a step repeatedly while a condition remains true.
|
|
|
407
399
|
|
|
408
400
|

|
|
409
401
|
|
|
410
|
-
```typescript {
|
|
402
|
+
```typescript {14} title="src/mastra/workflows/test-workflow.ts"
|
|
411
403
|
const step1 = createStep({...});
|
|
412
404
|
|
|
413
405
|
const step2 = createStep({
|
|
414
|
-
// ...
|
|
415
406
|
execute: async ({ inputData }) => {
|
|
416
407
|
const { number } = inputData;
|
|
417
408
|
return {
|
|
@@ -420,9 +411,7 @@ const step2 = createStep({
|
|
|
420
411
|
}
|
|
421
412
|
});
|
|
422
413
|
|
|
423
|
-
export const testWorkflow = createWorkflow({
|
|
424
|
-
// ...
|
|
425
|
-
})
|
|
414
|
+
export const testWorkflow = createWorkflow({})
|
|
426
415
|
.then(step1)
|
|
427
416
|
.dowhile(step2, async ({ inputData: { number } }) => number < 10)
|
|
428
417
|
.commit();
|
|
@@ -434,9 +423,8 @@ Use `.foreach()` to run the same step for each item in an array. The input must
|
|
|
434
423
|
|
|
435
424
|

|
|
436
425
|
|
|
437
|
-
```typescript {
|
|
426
|
+
```typescript {15} title="src/mastra/workflows/test-workflow.ts"
|
|
438
427
|
const step1 = createStep({
|
|
439
|
-
// ...
|
|
440
428
|
inputSchema: z.string(),
|
|
441
429
|
outputSchema: z.string(),
|
|
442
430
|
execute: async ({ inputData }) => {
|
|
@@ -447,7 +435,6 @@ const step1 = createStep({
|
|
|
447
435
|
const step2 = createStep({...});
|
|
448
436
|
|
|
449
437
|
export const testWorkflow = createWorkflow({
|
|
450
|
-
// ...
|
|
451
438
|
inputSchema: z.array(z.string()),
|
|
452
439
|
outputSchema: z.array(z.string())
|
|
453
440
|
})
|
|
@@ -460,7 +447,7 @@ export const testWorkflow = createWorkflow({
|
|
|
460
447
|
|
|
461
448
|
The `.foreach()` method always returns an array containing the output of each iteration. The order of outputs matches the order of inputs.
|
|
462
449
|
|
|
463
|
-
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
450
|
+
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
464
451
|
const addTenStep = createStep({
|
|
465
452
|
id: "add-ten",
|
|
466
453
|
inputSchema: z.object({ value: z.number() }),
|
|
@@ -486,7 +473,7 @@ export const testWorkflow = createWorkflow({
|
|
|
486
473
|
|
|
487
474
|
Use `concurrency` to control the number of array items processed at the same time. The default is `1`, which runs steps sequentially. Increasing the value allows `.foreach()` to process multiple items simultaneously.
|
|
488
475
|
|
|
489
|
-
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
476
|
+
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
490
477
|
const step1 = createStep({...})
|
|
491
478
|
|
|
492
479
|
export const testWorkflow = createWorkflow({...})
|
|
@@ -498,7 +485,7 @@ export const testWorkflow = createWorkflow({...})
|
|
|
498
485
|
|
|
499
486
|
Since `.foreach()` outputs an array, you can use `.then()` or `.map()` to aggregate or transform the results. The step following `.foreach()` receives the entire array as its input.
|
|
500
487
|
|
|
501
|
-
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
488
|
+
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
502
489
|
const processItemStep = createStep({
|
|
503
490
|
id: "process-item",
|
|
504
491
|
inputSchema: z.object({ value: z.number() }),
|
|
@@ -535,7 +522,7 @@ export const testWorkflow = createWorkflow({
|
|
|
535
522
|
|
|
536
523
|
You can also use `.map()` to transform the array output:
|
|
537
524
|
|
|
538
|
-
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
525
|
+
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
539
526
|
export const testWorkflow = createWorkflow({...})
|
|
540
527
|
.foreach(processItemStep)
|
|
541
528
|
.map(async ({ inputData }) => ({
|
|
@@ -551,7 +538,7 @@ export const testWorkflow = createWorkflow({...})
|
|
|
551
538
|
|
|
552
539
|
When you chain `.foreach()` calls, each operates on the array output of the previous step. This is useful when each item in your array needs to be transformed by multiple steps in sequence.
|
|
553
540
|
|
|
554
|
-
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
541
|
+
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
555
542
|
const chunkStep = createStep({
|
|
556
543
|
id: "chunk",
|
|
557
544
|
// Takes a document, returns an array of chunks
|
|
@@ -589,7 +576,7 @@ For processing multiple documents where each produces multiple chunks, you have
|
|
|
589
576
|
|
|
590
577
|
**Option 1: Process all documents in a single step with batching control**
|
|
591
578
|
|
|
592
|
-
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
579
|
+
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
593
580
|
const downloadAndChunkStep = createStep({
|
|
594
581
|
id: "download-and-chunk",
|
|
595
582
|
inputSchema: z.array(z.string()), // Array of URLs
|
|
@@ -614,7 +601,7 @@ export const multiDocWorkflow = createWorkflow({...})
|
|
|
614
601
|
|
|
615
602
|
**Option 2: Use foreach for documents, aggregate chunks, then foreach for embeddings**
|
|
616
603
|
|
|
617
|
-
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
604
|
+
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
618
605
|
const downloadStep = createStep({
|
|
619
606
|
id: "download",
|
|
620
607
|
inputSchema: z.string(), // Single URL
|
|
@@ -660,7 +647,7 @@ export const multiDocWorkflow = createWorkflow({
|
|
|
660
647
|
|
|
661
648
|
The step after `.foreach()` only executes after all iterations complete. If you need to run multiple sequential operations per item, use a nested workflow instead of chaining multiple `.foreach()` calls. This keeps all operations for each item together and makes the data flow clearer.
|
|
662
649
|
|
|
663
|
-
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
650
|
+
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
664
651
|
// Define a workflow that processes a single document
|
|
665
652
|
const processDocumentWorkflow = createWorkflow({
|
|
666
653
|
id: "process-document",
|
|
@@ -820,7 +807,7 @@ Loop conditions can be implemented in different ways depending on how you want t
|
|
|
820
807
|
|
|
821
808
|
Use `iterationCount` to limit how many times a loop runs. If the count exceeds your threshold, throw an error to fail the step and stop the workflow.
|
|
822
809
|
|
|
823
|
-
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
810
|
+
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
824
811
|
const step1 = createStep({...});
|
|
825
812
|
|
|
826
813
|
export const testWorkflow = createWorkflow({...})
|
|
@@ -13,7 +13,7 @@ When you run a workflow, the result object contains the status and any errors th
|
|
|
13
13
|
|
|
14
14
|
### Checking the result status
|
|
15
15
|
|
|
16
|
-
```typescript title="src/run-workflow.ts"
|
|
16
|
+
```typescript title="src/run-workflow.ts"
|
|
17
17
|
import { mastra } from "./mastra";
|
|
18
18
|
|
|
19
19
|
const workflow = mastra.getWorkflow("myWorkflow");
|
|
@@ -46,7 +46,7 @@ The result object contains:
|
|
|
46
46
|
|
|
47
47
|
You can inspect individual step results to understand where a failure occurred:
|
|
48
48
|
|
|
49
|
-
```typescript title="src/run-workflow.ts"
|
|
49
|
+
```typescript title="src/run-workflow.ts"
|
|
50
50
|
const result = await run.start({ inputData: { value: "test" } });
|
|
51
51
|
|
|
52
52
|
if (result.status === 'failed') {
|
|
@@ -67,7 +67,7 @@ For scenarios where you need to handle workflow completion without awaiting the
|
|
|
67
67
|
|
|
68
68
|
Called when a workflow completes with any status (success, failed, suspended, or tripwire):
|
|
69
69
|
|
|
70
|
-
```typescript {8-15} title="src/mastra/workflows/order-workflow.ts"
|
|
70
|
+
```typescript {8-15} title="src/mastra/workflows/order-workflow.ts"
|
|
71
71
|
import { createWorkflow } from "@mastra/core/workflows";
|
|
72
72
|
import { z } from "zod";
|
|
73
73
|
|
|
@@ -99,7 +99,7 @@ The `onFinish` callback receives:
|
|
|
99
99
|
|
|
100
100
|
Called only when a workflow fails (status is `'failed'` or `'tripwire'`):
|
|
101
101
|
|
|
102
|
-
```typescript {8-14} title="src/mastra/workflows/payment-workflow.ts"
|
|
102
|
+
```typescript {8-14} title="src/mastra/workflows/payment-workflow.ts"
|
|
103
103
|
import { createWorkflow } from "@mastra/core/workflows";
|
|
104
104
|
import { z } from "zod";
|
|
105
105
|
|
|
@@ -130,7 +130,7 @@ The `onError` callback receives:
|
|
|
130
130
|
|
|
131
131
|
You can use both callbacks together:
|
|
132
132
|
|
|
133
|
-
```typescript {8-16} title="src/mastra/workflows/pipeline-workflow.ts"
|
|
133
|
+
```typescript {8-16} title="src/mastra/workflows/pipeline-workflow.ts"
|
|
134
134
|
import { createWorkflow } from "@mastra/core/workflows";
|
|
135
135
|
import { z } from "zod";
|
|
136
136
|
|
|
@@ -172,14 +172,13 @@ Mastra has a retry mechanism for workflows or steps that fail due to transient e
|
|
|
172
172
|
|
|
173
173
|
You can configure retries at the workflow level, which applies to all steps in the workflow:
|
|
174
174
|
|
|
175
|
-
```typescript {
|
|
175
|
+
```typescript {7-10} title="src/mastra/workflows/test-workflow.ts"
|
|
176
176
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
177
177
|
import { z } from "zod";
|
|
178
178
|
|
|
179
179
|
const step1 = createStep({...});
|
|
180
180
|
|
|
181
181
|
export const testWorkflow = createWorkflow({
|
|
182
|
-
// ...
|
|
183
182
|
retryConfig: {
|
|
184
183
|
attempts: 5,
|
|
185
184
|
delay: 2000
|
|
@@ -193,14 +192,13 @@ export const testWorkflow = createWorkflow({
|
|
|
193
192
|
|
|
194
193
|
You can configure retries for individual steps using the `retries` property. This overrides the workflow-level retry configuration for that specific step:
|
|
195
194
|
|
|
196
|
-
```typescript {
|
|
195
|
+
```typescript {16} title="src/mastra/workflows/test-workflow.ts"
|
|
197
196
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
198
197
|
import { z } from "zod";
|
|
199
198
|
|
|
200
199
|
const step1 = createStep({
|
|
201
|
-
// ...
|
|
202
200
|
execute: async () => {
|
|
203
|
-
const response = await
|
|
201
|
+
const response = await fetch('example-url');
|
|
204
202
|
|
|
205
203
|
if (!response.ok) {
|
|
206
204
|
throw new Error('Error');
|
|
@@ -218,15 +216,14 @@ const step1 = createStep({
|
|
|
218
216
|
|
|
219
217
|
You can create alternative workflow paths based on the success or failure of previous steps using conditional logic:
|
|
220
218
|
|
|
221
|
-
```typescript {
|
|
219
|
+
```typescript {14,18,29-32} title="src/mastra/workflows/test-workflow.ts"
|
|
222
220
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
223
221
|
import { z } from "zod";
|
|
224
222
|
|
|
225
223
|
const step1 = createStep({
|
|
226
|
-
// ...
|
|
227
224
|
execute: async () => {
|
|
228
225
|
try {
|
|
229
|
-
const response = await
|
|
226
|
+
const response = await fetch('example-url');
|
|
230
227
|
|
|
231
228
|
if (!response.ok) {
|
|
232
229
|
throw new Error('error');
|
|
@@ -246,9 +243,7 @@ const step1 = createStep({
|
|
|
246
243
|
const step2 = createStep({...});
|
|
247
244
|
const fallback = createStep({...});
|
|
248
245
|
|
|
249
|
-
export const testWorkflow = createWorkflow({
|
|
250
|
-
// ...
|
|
251
|
-
})
|
|
246
|
+
export const testWorkflow = createWorkflow({})
|
|
252
247
|
.then(step1)
|
|
253
248
|
.branch([
|
|
254
249
|
[async ({ inputData: { status } }) => status === "ok", step2],
|
|
@@ -261,16 +256,14 @@ export const testWorkflow = createWorkflow({
|
|
|
261
256
|
|
|
262
257
|
Use `getStepResult()` to inspect a previous step’s results.
|
|
263
258
|
|
|
264
|
-
```typescript {
|
|
259
|
+
```typescript {8} title="src/mastra/workflows/test-workflow.ts"
|
|
265
260
|
import { createStep } from "@mastra/core/workflows";
|
|
266
261
|
import { z } from "zod";
|
|
267
262
|
|
|
268
263
|
const step1 = createStep({...});
|
|
269
264
|
|
|
270
265
|
const step2 = createStep({
|
|
271
|
-
// ...
|
|
272
266
|
execute: async ({ getStepResult }) => {
|
|
273
|
-
|
|
274
267
|
const step1Result = getStepResult(step1);
|
|
275
268
|
|
|
276
269
|
return {
|
|
@@ -284,7 +277,7 @@ const step2 = createStep({
|
|
|
284
277
|
|
|
285
278
|
Use `bail()` in a step to exit early with a successful result. This returns the provided payload as the step output and ends workflow execution.
|
|
286
279
|
|
|
287
|
-
```typescript {7} title="src/mastra/workflows/test-workflow.ts"
|
|
280
|
+
```typescript {7} title="src/mastra/workflows/test-workflow.ts"
|
|
288
281
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
289
282
|
import { z } from "zod";
|
|
290
283
|
|
|
@@ -306,7 +299,7 @@ export const testWorkflow = createWorkflow({...})
|
|
|
306
299
|
|
|
307
300
|
Use `throw new Error()` in a step to exit with an error.
|
|
308
301
|
|
|
309
|
-
```typescript {7} title="src/mastra/workflows/test-workflow.ts"
|
|
302
|
+
```typescript {7} title="src/mastra/workflows/test-workflow.ts"
|
|
310
303
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
311
304
|
import { z } from "zod";
|
|
312
305
|
|
|
@@ -328,7 +321,7 @@ export const testWorkflow = createWorkflow({...})
|
|
|
328
321
|
|
|
329
322
|
You can monitor workflows for errors using `stream`:
|
|
330
323
|
|
|
331
|
-
```typescript {11} title="src/test-workflow.ts"
|
|
324
|
+
```typescript {11} title="src/test-workflow.ts"
|
|
332
325
|
import { mastra } from "../src/mastra";
|
|
333
326
|
|
|
334
327
|
const workflow = mastra.getWorkflow("testWorkflow");
|
|
@@ -13,7 +13,7 @@ Human-in-the-loop input works much like [pausing a workflow](/docs/v1/workflows/
|
|
|
13
13
|
|
|
14
14
|

|
|
15
15
|
|
|
16
|
-
```typescript {12-17,22-26} title="src/mastra/workflows/test-workflow.ts"
|
|
16
|
+
```typescript {12-17,22-26} title="src/mastra/workflows/test-workflow.ts"
|
|
17
17
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
18
18
|
import { z } from "zod";
|
|
19
19
|
|
|
@@ -64,7 +64,7 @@ export const testWorkflow = createWorkflow({
|
|
|
64
64
|
|
|
65
65
|
When a workflow is suspended, you can access the payload returned by `suspend()` by identifying the suspended step and reading its `suspendPayload`.
|
|
66
66
|
|
|
67
|
-
```typescript {12} title="src/test-workflow.ts"
|
|
67
|
+
```typescript {12} title="src/test-workflow.ts"
|
|
68
68
|
const workflow = mastra.getWorkflow("testWorkflow");
|
|
69
69
|
const run = await workflow.createRun();
|
|
70
70
|
|
|
@@ -95,7 +95,7 @@ As with [restarting a workflow](/docs/v1/workflows/suspend-and-resume#restarting
|
|
|
95
95
|
|
|
96
96
|

|
|
97
97
|
|
|
98
|
-
```typescript {13}
|
|
98
|
+
```typescript {13}
|
|
99
99
|
const workflow = mastra.getWorkflow("testWorkflow");
|
|
100
100
|
const run = await workflow.createRun();
|
|
101
101
|
|
|
@@ -117,9 +117,8 @@ const handleResume = async () => {
|
|
|
117
117
|
|
|
118
118
|
Use `bail()` to stop workflow execution at a step without triggering an error. This can be useful when a human explicitly rejects an action. The workflow completes with a `success` status, and any logic after the call to `bail()` is skipped.
|
|
119
119
|
|
|
120
|
-
```typescript {
|
|
120
|
+
```typescript {6-10}
|
|
121
121
|
const step1 = createStep({
|
|
122
|
-
// ...
|
|
123
122
|
execute: async ({ inputData, resumeData, suspend, bail }) => {
|
|
124
123
|
const { userEmail } = inputData;
|
|
125
124
|
const { approved } = resumeData ?? {};
|
|
@@ -147,7 +146,7 @@ const step1 = createStep({
|
|
|
147
146
|
|
|
148
147
|
For workflows that require input at multiple stages, the suspend pattern remains the same. Each step defines a `resumeSchema`, and `suspendSchema` typically with a reason that can be used to provide user feedback.
|
|
149
148
|
|
|
150
|
-
```typescript {11-16,21-25} title="src/mastra/workflows/test-workflow.ts"
|
|
149
|
+
```typescript {11-16,21-25} title="src/mastra/workflows/test-workflow.ts"
|
|
151
150
|
const step1 = createStep({...});
|
|
152
151
|
|
|
153
152
|
const step2 = createStep({
|
|
@@ -196,7 +195,7 @@ export const testWorkflow = createWorkflow({
|
|
|
196
195
|
|
|
197
196
|
Each step must be resumed in sequence, with a separate call to `resume()` for each suspended step. This approach helps manage multi-step approvals with consistent UI feedback and clear input handling at each stage.
|
|
198
197
|
|
|
199
|
-
```typescript {4,11}
|
|
198
|
+
```typescript {4,11}
|
|
200
199
|
const handleResume = async () => {
|
|
201
200
|
const result = await run.resume({
|
|
202
201
|
step: "step-1",
|
|
@@ -33,7 +33,7 @@ Initialize the Inngest integration to obtain Mastra-compatible workflow helpers.
|
|
|
33
33
|
|
|
34
34
|
In development
|
|
35
35
|
|
|
36
|
-
```ts
|
|
36
|
+
```ts title="src/mastra/inngest/index.ts"
|
|
37
37
|
import { Inngest } from "inngest";
|
|
38
38
|
import { realtimeMiddleware } from "@inngest/realtime/middleware";
|
|
39
39
|
|
|
@@ -47,7 +47,7 @@ export const inngest = new Inngest({
|
|
|
47
47
|
|
|
48
48
|
In production
|
|
49
49
|
|
|
50
|
-
```ts
|
|
50
|
+
```ts title="src/mastra/inngest/index.ts"
|
|
51
51
|
import { Inngest } from "inngest";
|
|
52
52
|
import { realtimeMiddleware } from "@inngest/realtime/middleware";
|
|
53
53
|
|
|
@@ -61,7 +61,7 @@ export const inngest = new Inngest({
|
|
|
61
61
|
|
|
62
62
|
Define the individual steps that will compose your workflow:
|
|
63
63
|
|
|
64
|
-
```ts
|
|
64
|
+
```ts title="src/mastra/workflows/index.ts"
|
|
65
65
|
import { z } from "zod";
|
|
66
66
|
import { inngest } from "../inngest";
|
|
67
67
|
import { init } from "@mastra/inngest";
|
|
@@ -88,7 +88,7 @@ const incrementStep = createStep({
|
|
|
88
88
|
|
|
89
89
|
Compose the steps into a workflow using the `dountil` loop pattern. The createWorkflow function creates a function on inngest server that is invocable.
|
|
90
90
|
|
|
91
|
-
```ts
|
|
91
|
+
```ts title="src/mastra/workflows/index.ts"
|
|
92
92
|
// workflow that is registered as a function on inngest server
|
|
93
93
|
const workflow = createWorkflow({
|
|
94
94
|
id: "increment-workflow",
|
|
@@ -109,7 +109,7 @@ export { workflow as incrementWorkflow };
|
|
|
109
109
|
|
|
110
110
|
Register the workflow with Mastra and configure the Inngest API endpoint:
|
|
111
111
|
|
|
112
|
-
```ts
|
|
112
|
+
```ts title="src/mastra/index.ts"
|
|
113
113
|
import { Mastra } from "@mastra/core";
|
|
114
114
|
import { serve as inngestServe } from "@mastra/inngest";
|
|
115
115
|
import { incrementWorkflow } from "./workflows";
|
|
@@ -216,11 +216,10 @@ docker run --rm -p 8288:8288 \
|
|
|
216
216
|
|
|
217
217
|
1. Add Vercel Deployer to Mastra instance
|
|
218
218
|
|
|
219
|
-
```ts
|
|
219
|
+
```ts title="src/mastra/index.ts"
|
|
220
220
|
import { VercelDeployer } from "@mastra/deployer-vercel";
|
|
221
221
|
|
|
222
222
|
export const mastra = new Mastra({
|
|
223
|
-
// ...other config
|
|
224
223
|
deployer: new VercelDeployer({
|
|
225
224
|
teamSlug: "your_team_slug",
|
|
226
225
|
projectName: "your_project_name",
|
|
@@ -291,7 +290,7 @@ You can serve additional Inngest functions alongside your Mastra workflows by us
|
|
|
291
290
|
|
|
292
291
|
First, create your custom Inngest functions:
|
|
293
292
|
|
|
294
|
-
```ts
|
|
293
|
+
```ts title="src/inngest/custom-functions.ts"
|
|
295
294
|
import { inngest } from "./inngest";
|
|
296
295
|
|
|
297
296
|
// Define custom Inngest functions
|
|
@@ -320,7 +319,7 @@ export const customWebhookFunction = inngest.createFunction(
|
|
|
320
319
|
|
|
321
320
|
Update your Mastra configuration to include the custom functions:
|
|
322
321
|
|
|
323
|
-
```ts
|
|
322
|
+
```ts title="src/mastra/index.ts"
|
|
324
323
|
import { Mastra } from "@mastra/core";
|
|
325
324
|
import { serve as inngestServe } from "@mastra/inngest";
|
|
326
325
|
import { incrementWorkflow } from "./workflows";
|
|
@@ -18,7 +18,7 @@ In this example the `output` from `step1` is transformed to match the `inputSche
|
|
|
18
18
|
|
|
19
19
|

|
|
20
20
|
|
|
21
|
-
```typescript {9} title="src/mastra/workflows/test-workflow.ts"
|
|
21
|
+
```typescript {9} title="src/mastra/workflows/test-workflow.ts"
|
|
22
22
|
const step1 = createStep({...});
|
|
23
23
|
const step2 = createStep({...});
|
|
24
24
|
|
|
@@ -38,7 +38,7 @@ export const testWorkflow = createWorkflow({...})
|
|
|
38
38
|
|
|
39
39
|
Use `inputData` to access the full output of the previous step:
|
|
40
40
|
|
|
41
|
-
```typescript {3} title="src/mastra/workflows/test-workflow.ts"
|
|
41
|
+
```typescript {3} title="src/mastra/workflows/test-workflow.ts"
|
|
42
42
|
.then(step1)
|
|
43
43
|
.map(({ inputData }) => {
|
|
44
44
|
console.log(inputData);
|
|
@@ -49,7 +49,7 @@ Use `inputData` to access the full output of the previous step:
|
|
|
49
49
|
|
|
50
50
|
Use `getStepResult` to access the full output of a specific step by referencing the step's instance:
|
|
51
51
|
|
|
52
|
-
```typescript {3} title="src/mastra/workflows/test-workflow.ts"
|
|
52
|
+
```typescript {3} title="src/mastra/workflows/test-workflow.ts"
|
|
53
53
|
.then(step1)
|
|
54
54
|
.map(async ({ getStepResult }) => {
|
|
55
55
|
console.log(getStepResult(step1));
|
|
@@ -60,7 +60,7 @@ Use `getStepResult` to access the full output of a specific step by referencing
|
|
|
60
60
|
|
|
61
61
|
Use `getInitData` to access the initial input data provided to the workflow:
|
|
62
62
|
|
|
63
|
-
```typescript {3} title="src/mastra/workflows/test-workflow.ts"
|
|
63
|
+
```typescript {3} title="src/mastra/workflows/test-workflow.ts"
|
|
64
64
|
.then(step1)
|
|
65
65
|
.map(async ({ getInitData }) => {
|
|
66
66
|
console.log(getInitData());
|
|
@@ -71,7 +71,7 @@ Use `getInitData` to access the initial input data provided to the workflow:
|
|
|
71
71
|
|
|
72
72
|
To use `mapVariable` import the necessary function from the workflows module:
|
|
73
73
|
|
|
74
|
-
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
74
|
+
```typescript title="src/mastra/workflows/test-workflow.ts"
|
|
75
75
|
import { mapVariable } from "@mastra/core/workflows";
|
|
76
76
|
```
|
|
77
77
|
|
|
@@ -79,7 +79,7 @@ import { mapVariable } from "@mastra/core/workflows";
|
|
|
79
79
|
|
|
80
80
|
You can rename step outputs using the object syntax in `.map()`. In the example below, the `value` output from `step1` is renamed to `details`:
|
|
81
81
|
|
|
82
|
-
```typescript {3-6} title="src/mastra/workflows/test-workflow.ts"
|
|
82
|
+
```typescript {3-6} title="src/mastra/workflows/test-workflow.ts"
|
|
83
83
|
.then(step1)
|
|
84
84
|
.map({
|
|
85
85
|
details: mapVariable({
|
|
@@ -93,7 +93,7 @@ You can rename step outputs using the object syntax in `.map()`. In the example
|
|
|
93
93
|
|
|
94
94
|
You can rename workflow outputs by using **referential composition**. This involves passing the workflow instance as the `initData`.
|
|
95
95
|
|
|
96
|
-
```typescript {6-9} title="src/mastra/workflows/test-workflow.ts"
|
|
96
|
+
```typescript {6-9} title="src/mastra/workflows/test-workflow.ts"
|
|
97
97
|
export const testWorkflow = createWorkflow({...});
|
|
98
98
|
|
|
99
99
|
testWorkflow
|