@mastra/mcp-docs-server 0.13.39 → 1.0.0-beta.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/%40internal%2Fai-sdk-v4.md +1 -0
- package/.docs/organized/changelogs/%40internal%2Fchangeset-cli.md +0 -10
- package/.docs/organized/changelogs/%40internal%2Fexternal-types.md +0 -10
- package/.docs/organized/changelogs/%40internal%2Fstorage-test-utils.md +36 -36
- package/.docs/organized/changelogs/%40internal%2Ftypes-builder.md +0 -10
- package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +70 -70
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +40 -40
- package/.docs/organized/changelogs/%40mastra%2Fastra.md +19 -19
- package/.docs/organized/changelogs/%40mastra%2Fauth.md +4 -14
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +18 -18
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +199 -199
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +220 -220
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +190 -190
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +199 -199
- package/.docs/organized/changelogs/%40mastra%2Fcodemod.md +7 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +210 -210
- package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +16 -16
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +69 -69
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +67 -67
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +70 -70
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +67 -67
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +209 -209
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +191 -191
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +34 -34
- package/.docs/organized/changelogs/%40mastra%2Ffastembed.md +5 -13
- package/.docs/organized/changelogs/%40mastra%2Flance.md +182 -182
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +199 -199
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +56 -56
- package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +65 -65
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +228 -228
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +199 -199
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +206 -206
- package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +19 -19
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +197 -197
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +16 -16
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +216 -216
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +16 -16
- package/.docs/organized/changelogs/%40mastra%2Frag.md +61 -61
- package/.docs/organized/changelogs/%40mastra%2Freact.md +66 -66
- package/.docs/organized/changelogs/%40mastra%2Fs3vectors.md +9 -17
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +6 -30
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +203 -203
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +16 -16
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +190 -190
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +18 -18
- package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +21 -21
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fvoice-gladia.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google-gemini-live.md +56 -56
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +56 -56
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +20 -20
- package/.docs/organized/changelogs/create-mastra.md +29 -29
- package/.docs/organized/changelogs/mastra.md +93 -93
- package/.docs/organized/code-examples/a2a.md +4 -2
- package/.docs/organized/code-examples/agui.md +12 -9
- package/.docs/organized/code-examples/ai-sdk-useChat.md +12 -18
- package/.docs/organized/code-examples/ai-sdk-v5.md +4 -2
- package/.docs/organized/code-examples/bird-checker-with-express.md +5 -4
- package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +4 -3
- package/.docs/organized/code-examples/bird-checker-with-nextjs.md +4 -3
- package/.docs/organized/code-examples/client-side-tools.md +1 -0
- package/.docs/organized/code-examples/crypto-chatbot.md +1 -1
- package/.docs/organized/code-examples/experimental-auth-weather-agent.md +8 -177
- package/.docs/organized/code-examples/fireworks-r1.md +2 -2
- package/.docs/organized/code-examples/heads-up-game.md +10 -7
- package/.docs/organized/code-examples/mcp-configuration.md +5 -3
- package/.docs/organized/code-examples/mcp-registry-registry.md +3 -2
- package/.docs/organized/code-examples/memory-per-resource-example.md +4 -2
- package/.docs/organized/code-examples/memory-todo-agent.md +1 -0
- package/.docs/organized/code-examples/memory-with-context.md +2 -1
- package/.docs/organized/code-examples/memory-with-libsql.md +4 -2
- package/.docs/organized/code-examples/memory-with-mongodb.md +4 -2
- package/.docs/organized/code-examples/memory-with-pg.md +4 -2
- package/.docs/organized/code-examples/memory-with-processors.md +13 -8
- package/.docs/organized/code-examples/memory-with-upstash.md +5 -3
- package/.docs/organized/code-examples/openapi-spec-writer.md +32 -41
- package/.docs/organized/code-examples/quick-start.md +5 -32
- package/.docs/organized/code-examples/stock-price-tool.md +6 -5
- package/.docs/organized/code-examples/weather-agent.md +21 -16
- package/.docs/organized/code-examples/workflow-ai-recruiter.md +3 -2
- package/.docs/organized/code-examples/workflow-with-inline-steps.md +9 -12
- package/.docs/organized/code-examples/workflow-with-memory.md +16 -15
- package/.docs/organized/code-examples/workflow-with-separate-steps.md +2 -2
- package/.docs/organized/code-examples/workflow-with-suspend-resume.md +3 -2
- package/.docs/raw/agents/adding-voice.mdx +27 -22
- package/.docs/raw/agents/agent-memory.mdx +24 -16
- package/.docs/raw/agents/guardrails.mdx +33 -12
- package/.docs/raw/agents/networks.mdx +8 -4
- package/.docs/raw/agents/overview.mdx +23 -17
- package/.docs/raw/agents/using-tools.mdx +11 -8
- package/.docs/raw/auth/auth0.mdx +9 -9
- package/.docs/raw/auth/clerk.mdx +7 -7
- package/.docs/raw/auth/firebase.mdx +9 -9
- package/.docs/raw/auth/index.mdx +6 -6
- package/.docs/raw/auth/jwt.mdx +7 -7
- package/.docs/raw/auth/supabase.mdx +8 -8
- package/.docs/raw/auth/workos.mdx +9 -9
- package/.docs/raw/community/contributing-templates.mdx +3 -3
- package/.docs/raw/community/discord.mdx +1 -1
- package/.docs/raw/course/01-first-agent/03-verifying-installation.md +1 -1
- package/.docs/raw/course/01-first-agent/08-exporting-your-agent.md +2 -1
- package/.docs/raw/course/01-first-agent/16-adding-memory-to-agent.md +2 -1
- package/.docs/raw/course/02-agent-tools-mcp/02-installing-mcp.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/31-enhancing-memory-configuration.md +2 -0
- package/.docs/raw/course/03-agent-memory/03-installing-memory.md +1 -1
- package/.docs/raw/course/03-agent-memory/04-creating-basic-memory-agent.md +1 -0
- package/.docs/raw/course/03-agent-memory/10-storage-configuration.md +2 -3
- package/.docs/raw/course/03-agent-memory/13-vector-store-configuration.md +2 -0
- package/.docs/raw/course/03-agent-memory/16-configuring-semantic-recall.md +2 -0
- package/.docs/raw/course/03-agent-memory/18-advanced-configuration-semantic-recall.md +1 -0
- package/.docs/raw/course/03-agent-memory/21-configuring-working-memory.md +2 -0
- package/.docs/raw/course/03-agent-memory/22-custom-working-memory-templates.md +1 -0
- package/.docs/raw/course/03-agent-memory/25-combining-memory-features.md +1 -0
- package/.docs/raw/course/03-agent-memory/27-creating-learning-assistant.md +1 -0
- package/.docs/raw/course/04-workflows/08-running-workflows-programmatically.md +2 -2
- package/.docs/raw/deployment/cloud-providers/amazon-ec2.mdx +6 -6
- package/.docs/raw/deployment/cloud-providers/aws-lambda.mdx +8 -6
- package/.docs/raw/deployment/cloud-providers/azure-app-services.mdx +5 -5
- package/.docs/raw/deployment/cloud-providers/digital-ocean.mdx +5 -5
- package/.docs/raw/deployment/cloud-providers/index.mdx +11 -8
- package/.docs/raw/deployment/monorepo.mdx +2 -2
- package/.docs/raw/deployment/overview.mdx +2 -2
- package/.docs/raw/deployment/server-deployment.mdx +2 -10
- package/.docs/raw/deployment/serverless-platforms/cloudflare-deployer.mdx +5 -5
- package/.docs/raw/deployment/serverless-platforms/index.mdx +10 -7
- package/.docs/raw/deployment/serverless-platforms/netlify-deployer.mdx +5 -5
- package/.docs/raw/deployment/serverless-platforms/vercel-deployer.mdx +5 -5
- package/.docs/raw/deployment/web-framework.mdx +8 -8
- package/.docs/raw/{scorers → evals}/custom-scorers.mdx +6 -6
- package/.docs/raw/evals/off-the-shelf-scorers.mdx +50 -0
- package/.docs/raw/{scorers → evals}/overview.mdx +9 -9
- package/.docs/raw/evals/running-in-ci.mdx +113 -0
- package/.docs/raw/frameworks/agentic-uis/ai-sdk.mdx +26 -25
- package/.docs/raw/frameworks/agentic-uis/assistant-ui.mdx +1 -1
- package/.docs/raw/frameworks/agentic-uis/copilotkit.mdx +17 -17
- package/.docs/raw/frameworks/agentic-uis/openrouter.mdx +4 -1
- package/.docs/raw/frameworks/servers/express.mdx +11 -10
- package/.docs/raw/frameworks/web-frameworks/astro.mdx +18 -18
- package/.docs/raw/frameworks/web-frameworks/next-js.mdx +7 -7
- package/.docs/raw/frameworks/web-frameworks/sveltekit.mdx +16 -16
- package/.docs/raw/frameworks/web-frameworks/vite-react.mdx +7 -7
- package/.docs/raw/getting-started/installation.mdx +26 -25
- package/.docs/raw/getting-started/mcp-docs-server.mdx +1 -1
- package/.docs/raw/getting-started/project-structure.mdx +4 -4
- package/.docs/raw/getting-started/studio.mdx +8 -8
- package/.docs/raw/getting-started/templates.mdx +6 -6
- package/.docs/raw/guides/guide/ai-recruiter.mdx +264 -0
- package/.docs/raw/guides/guide/chef-michel.mdx +271 -0
- package/.docs/raw/guides/guide/notes-mcp-server.mdx +450 -0
- package/.docs/raw/guides/guide/research-assistant.mdx +380 -0
- package/.docs/raw/guides/guide/stock-agent.mdx +185 -0
- package/.docs/raw/guides/guide/web-search.mdx +291 -0
- package/.docs/raw/guides/index.mdx +43 -0
- package/.docs/raw/guides/migrations/agentnetwork.mdx +114 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/_template.mdx +50 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/agent.mdx +265 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/cli.mdx +48 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/client.mdx +153 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/evals.mdx +230 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/mastra.mdx +171 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/mcp.mdx +114 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/memory.mdx +241 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/overview.mdx +83 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/processors.mdx +62 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/storage.mdx +270 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/tools.mdx +115 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/tracing.mdx +280 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/vectors.mdx +23 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/voice.mdx +39 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/workflows.mdx +178 -0
- package/.docs/raw/guides/migrations/vnext-to-standard-apis.mdx +367 -0
- package/.docs/raw/guides/quickstarts/nextjs.mdx +275 -0
- package/.docs/raw/index.mdx +9 -9
- package/.docs/raw/{observability/logging.mdx → logging.mdx} +4 -4
- package/.docs/raw/mastra-cloud/dashboard.mdx +2 -2
- package/.docs/raw/mastra-cloud/observability.mdx +6 -6
- package/.docs/raw/mastra-cloud/overview.mdx +2 -2
- package/.docs/raw/mastra-cloud/setting-up.mdx +4 -4
- package/.docs/raw/memory/conversation-history.mdx +1 -0
- package/.docs/raw/memory/memory-processors.mdx +4 -3
- package/.docs/raw/memory/overview.mdx +10 -6
- package/.docs/raw/memory/semantic-recall.mdx +13 -8
- package/.docs/raw/memory/storage/memory-with-libsql.mdx +12 -7
- package/.docs/raw/memory/storage/memory-with-pg.mdx +11 -6
- package/.docs/raw/memory/storage/memory-with-upstash.mdx +11 -6
- package/.docs/raw/memory/threads-and-resources.mdx +11 -13
- package/.docs/raw/memory/working-memory.mdx +30 -14
- package/.docs/raw/observability/overview.mdx +13 -30
- package/.docs/raw/observability/{ai-tracing → tracing}/exporters/arize.mdx +11 -19
- package/.docs/raw/observability/{ai-tracing → tracing}/exporters/braintrust.mdx +8 -17
- package/.docs/raw/observability/{ai-tracing → tracing}/exporters/cloud.mdx +11 -17
- package/.docs/raw/observability/{ai-tracing → tracing}/exporters/default.mdx +16 -20
- package/.docs/raw/observability/{ai-tracing → tracing}/exporters/langfuse.mdx +8 -17
- package/.docs/raw/observability/{ai-tracing → tracing}/exporters/langsmith.mdx +8 -17
- package/.docs/raw/observability/{ai-tracing → tracing}/exporters/otel.mdx +12 -21
- package/.docs/raw/observability/{ai-tracing → tracing}/overview.mdx +107 -142
- package/.docs/raw/observability/{ai-tracing → tracing}/processors/sensitive-data-filter.mdx +14 -13
- package/.docs/raw/rag/chunking-and-embedding.mdx +5 -5
- package/.docs/raw/rag/overview.mdx +3 -13
- package/.docs/raw/rag/retrieval.mdx +24 -12
- package/.docs/raw/rag/vector-databases.mdx +7 -1
- package/.docs/raw/reference/agents/agent.mdx +35 -30
- package/.docs/raw/reference/agents/generate.mdx +10 -10
- package/.docs/raw/reference/agents/generateLegacy.mdx +8 -8
- package/.docs/raw/reference/agents/getDefaultGenerateOptions.mdx +21 -15
- package/.docs/raw/reference/agents/getDefaultOptions.mdx +69 -0
- package/.docs/raw/reference/agents/getDefaultStreamOptions.mdx +22 -16
- package/.docs/raw/reference/agents/getDescription.mdx +1 -1
- package/.docs/raw/reference/agents/getInstructions.mdx +8 -8
- package/.docs/raw/reference/agents/getLLM.mdx +9 -9
- package/.docs/raw/reference/agents/getMemory.mdx +9 -9
- package/.docs/raw/reference/agents/getModel.mdx +10 -10
- package/.docs/raw/reference/agents/getVoice.mdx +8 -8
- package/.docs/raw/reference/agents/listAgents.mdx +9 -9
- package/.docs/raw/reference/agents/listScorers.mdx +7 -7
- package/.docs/raw/reference/agents/listTools.mdx +7 -7
- package/.docs/raw/reference/agents/listWorkflows.mdx +7 -7
- package/.docs/raw/reference/agents/network.mdx +11 -10
- package/.docs/raw/reference/auth/auth0.mdx +4 -4
- package/.docs/raw/reference/auth/clerk.mdx +4 -4
- package/.docs/raw/reference/auth/firebase.mdx +6 -6
- package/.docs/raw/reference/auth/jwt.mdx +4 -4
- package/.docs/raw/reference/auth/supabase.mdx +4 -4
- package/.docs/raw/reference/auth/workos.mdx +4 -4
- package/.docs/raw/reference/cli/create-mastra.mdx +10 -10
- package/.docs/raw/reference/cli/mastra.mdx +7 -7
- package/.docs/raw/reference/client-js/agents.mdx +6 -2
- package/.docs/raw/reference/client-js/mastra-client.mdx +7 -7
- package/.docs/raw/reference/client-js/memory.mdx +24 -16
- package/.docs/raw/reference/client-js/observability.mdx +11 -11
- package/.docs/raw/reference/client-js/workflows.mdx +6 -34
- 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 +2 -2
- package/.docs/raw/reference/core/getLogger.mdx +2 -2
- package/.docs/raw/reference/core/getMCPServer.mdx +31 -15
- package/.docs/raw/reference/core/getMCPServerById.mdx +81 -0
- package/.docs/raw/reference/core/getScorer.mdx +3 -3
- package/.docs/raw/reference/core/getScorerById.mdx +79 -0
- package/.docs/raw/reference/core/getServer.mdx +2 -2
- package/.docs/raw/reference/core/getStorage.mdx +2 -2
- package/.docs/raw/reference/core/getTelemetry.mdx +2 -2
- package/.docs/raw/reference/core/getVector.mdx +2 -2
- 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 +2 -2
- package/.docs/raw/reference/core/listLogsByRunId.mdx +2 -2
- package/.docs/raw/reference/core/listMCPServers.mdx +65 -0
- package/.docs/raw/reference/core/listScorers.mdx +3 -3
- package/.docs/raw/reference/core/listVectors.mdx +36 -0
- package/.docs/raw/reference/core/listWorkflows.mdx +6 -6
- package/.docs/raw/reference/core/mastra-class.mdx +3 -2
- package/.docs/raw/reference/core/setLogger.mdx +2 -2
- package/.docs/raw/reference/core/setStorage.mdx +3 -2
- package/.docs/raw/reference/core/setTelemetry.mdx +2 -2
- package/.docs/raw/reference/deployer/cloudflare.mdx +2 -2
- package/.docs/raw/reference/deployer/deployer.mdx +0 -6
- package/.docs/raw/reference/deployer/netlify.mdx +2 -2
- package/.docs/raw/reference/deployer/vercel.mdx +3 -3
- package/.docs/raw/reference/evals/answer-relevancy.mdx +164 -126
- package/.docs/raw/reference/{scorers → evals}/answer-similarity.mdx +27 -27
- package/.docs/raw/reference/evals/bias.mdx +149 -115
- package/.docs/raw/reference/evals/completeness.mdx +148 -117
- package/.docs/raw/reference/evals/content-similarity.mdx +126 -113
- package/.docs/raw/reference/evals/context-precision.mdx +290 -133
- package/.docs/raw/reference/{scorers → evals}/context-relevance.mdx +6 -6
- package/.docs/raw/reference/{scorers → evals}/create-scorer.mdx +69 -60
- package/.docs/raw/reference/evals/faithfulness.mdx +163 -121
- package/.docs/raw/reference/evals/hallucination.mdx +159 -132
- package/.docs/raw/reference/evals/keyword-coverage.mdx +169 -125
- package/.docs/raw/reference/{scorers → evals}/mastra-scorer.mdx +7 -5
- package/.docs/raw/reference/{scorers → evals}/noise-sensitivity.mdx +9 -9
- package/.docs/raw/reference/evals/prompt-alignment.mdx +604 -182
- package/.docs/raw/reference/{scorers/run-experiment.mdx → evals/run-evals.mdx} +17 -18
- package/.docs/raw/reference/evals/textual-difference.mdx +149 -117
- package/.docs/raw/reference/evals/tone-consistency.mdx +149 -125
- package/.docs/raw/reference/{scorers → evals}/tool-call-accuracy.mdx +8 -6
- package/.docs/raw/reference/evals/toxicity.mdx +152 -96
- package/.docs/raw/reference/{observability/logging → logging}/pino-logger.mdx +2 -2
- package/.docs/raw/reference/memory/createThread.mdx +5 -5
- package/.docs/raw/reference/memory/deleteMessages.mdx +7 -7
- package/.docs/raw/reference/memory/getThreadById.mdx +4 -4
- package/.docs/raw/reference/memory/listThreadsByResourceId.mdx +110 -0
- package/.docs/raw/reference/memory/memory-class.mdx +13 -9
- package/.docs/raw/reference/memory/query.mdx +58 -57
- package/.docs/raw/reference/memory/recall.mdx +185 -0
- package/.docs/raw/reference/observability/tracing/configuration.mdx +245 -0
- package/.docs/raw/reference/observability/{ai-tracing → tracing}/exporters/arize.mdx +13 -13
- package/.docs/raw/reference/observability/{ai-tracing → tracing}/exporters/braintrust.mdx +11 -8
- package/.docs/raw/reference/observability/{ai-tracing → tracing}/exporters/cloud-exporter.mdx +21 -19
- package/.docs/raw/reference/observability/{ai-tracing → tracing}/exporters/console-exporter.mdx +49 -17
- package/.docs/raw/reference/observability/{ai-tracing → tracing}/exporters/default-exporter.mdx +42 -41
- package/.docs/raw/reference/observability/{ai-tracing → tracing}/exporters/langfuse.mdx +10 -7
- package/.docs/raw/reference/observability/{ai-tracing → tracing}/exporters/langsmith.mdx +10 -7
- package/.docs/raw/reference/observability/{ai-tracing → tracing}/exporters/otel.mdx +5 -5
- package/.docs/raw/reference/observability/tracing/instances.mdx +168 -0
- package/.docs/raw/reference/observability/{ai-tracing → tracing}/interfaces.mdx +115 -89
- package/.docs/raw/reference/observability/{ai-tracing → tracing}/processors/sensitive-data-filter.mdx +3 -3
- package/.docs/raw/reference/observability/{ai-tracing/span.mdx → tracing/spans.mdx} +59 -41
- package/.docs/raw/reference/processors/batch-parts-processor.mdx +9 -3
- package/.docs/raw/reference/processors/language-detector.mdx +9 -3
- package/.docs/raw/reference/processors/moderation-processor.mdx +9 -3
- package/.docs/raw/reference/processors/pii-detector.mdx +9 -3
- package/.docs/raw/reference/processors/prompt-injection-detector.mdx +9 -3
- package/.docs/raw/reference/processors/system-prompt-scrubber.mdx +9 -3
- package/.docs/raw/reference/processors/token-limiter-processor.mdx +9 -3
- package/.docs/raw/reference/processors/unicode-normalizer.mdx +9 -3
- package/.docs/raw/reference/rag/chunk.mdx +1 -8
- package/.docs/raw/reference/rag/database-config.mdx +7 -7
- package/.docs/raw/reference/rag/metadata-filters.mdx +14 -11
- package/.docs/raw/reference/storage/cloudflare-d1.mdx +1 -1
- package/.docs/raw/reference/storage/cloudflare.mdx +1 -1
- package/.docs/raw/reference/storage/dynamodb.mdx +3 -3
- package/.docs/raw/reference/storage/lance.mdx +1 -1
- package/.docs/raw/reference/storage/libsql.mdx +3 -1
- package/.docs/raw/reference/storage/mongodb.mdx +1 -1
- package/.docs/raw/reference/storage/mssql.mdx +6 -1
- package/.docs/raw/reference/storage/postgresql.mdx +7 -1
- package/.docs/raw/reference/storage/upstash.mdx +2 -1
- package/.docs/raw/reference/streaming/agents/stream.mdx +12 -12
- package/.docs/raw/reference/streaming/agents/streamLegacy.mdx +8 -8
- package/.docs/raw/reference/streaming/workflows/observeStream.mdx +3 -3
- package/.docs/raw/reference/streaming/workflows/observeStreamVNext.mdx +3 -3
- package/.docs/raw/reference/streaming/workflows/resumeStreamVNext.mdx +6 -6
- package/.docs/raw/reference/streaming/workflows/stream.mdx +10 -10
- package/.docs/raw/reference/streaming/workflows/streamVNext.mdx +11 -11
- package/.docs/raw/reference/templates/overview.mdx +3 -3
- package/.docs/raw/reference/tools/create-tool.mdx +52 -35
- package/.docs/raw/reference/tools/graph-rag-tool.mdx +15 -15
- package/.docs/raw/reference/tools/mcp-client.mdx +1 -1
- package/.docs/raw/reference/tools/mcp-server.mdx +119 -35
- package/.docs/raw/reference/tools/vector-query-tool.mdx +27 -26
- package/.docs/raw/reference/vectors/couchbase.mdx +8 -2
- package/.docs/raw/reference/vectors/libsql.mdx +2 -1
- package/.docs/raw/reference/vectors/mongodb.mdx +7 -1
- package/.docs/raw/reference/vectors/pg.mdx +3 -0
- package/.docs/raw/reference/vectors/s3vectors.mdx +1 -1
- package/.docs/raw/reference/vectors/upstash.mdx +1 -0
- package/.docs/raw/reference/voice/google-gemini-live.mdx +1 -1
- package/.docs/raw/reference/voice/voice.addTools.mdx +3 -3
- package/.docs/raw/reference/workflows/run-methods/cancel.mdx +4 -4
- package/.docs/raw/reference/workflows/run-methods/resume.mdx +14 -14
- package/.docs/raw/reference/workflows/run-methods/start.mdx +17 -17
- package/.docs/raw/reference/workflows/run.mdx +1 -8
- package/.docs/raw/reference/workflows/step.mdx +5 -5
- package/.docs/raw/reference/workflows/workflow-methods/branch.mdx +2 -2
- package/.docs/raw/reference/workflows/workflow-methods/commit.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/create-run.mdx +7 -13
- 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 +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/map.mdx +5 -0
- 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 +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/sleepUntil.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/then.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/waitForEvent.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow.mdx +1 -1
- package/.docs/raw/server-db/custom-api-routes.mdx +2 -2
- package/.docs/raw/server-db/mastra-client.mdx +23 -22
- package/.docs/raw/server-db/middleware.mdx +7 -7
- package/.docs/raw/server-db/production-server.mdx +4 -4
- package/.docs/raw/server-db/{runtime-context.mdx → request-context.mdx} +46 -45
- package/.docs/raw/server-db/storage.mdx +29 -21
- package/.docs/raw/streaming/events.mdx +3 -3
- package/.docs/raw/streaming/overview.mdx +5 -5
- package/.docs/raw/streaming/tool-streaming.mdx +18 -17
- package/.docs/raw/streaming/workflow-streaming.mdx +1 -1
- package/.docs/raw/tools-mcp/advanced-usage.mdx +5 -4
- package/.docs/raw/tools-mcp/mcp-overview.mdx +33 -20
- package/.docs/raw/tools-mcp/overview.mdx +11 -11
- package/.docs/raw/voice/overview.mdx +63 -43
- package/.docs/raw/voice/speech-to-speech.mdx +5 -3
- package/.docs/raw/voice/speech-to-text.mdx +10 -9
- package/.docs/raw/voice/text-to-speech.mdx +13 -12
- package/.docs/raw/workflows/agents-and-tools.mdx +9 -5
- package/.docs/raw/workflows/control-flow.mdx +3 -3
- package/.docs/raw/workflows/error-handling.mdx +2 -21
- package/.docs/raw/workflows/human-in-the-loop.mdx +7 -4
- package/.docs/raw/workflows/inngest-workflow.mdx +3 -3
- package/.docs/raw/workflows/input-data-mapping.mdx +107 -0
- package/.docs/raw/workflows/overview.mdx +17 -16
- package/.docs/raw/workflows/snapshots.mdx +13 -11
- package/.docs/raw/workflows/suspend-and-resume.mdx +23 -15
- package/CHANGELOG.md +55 -53
- package/README.md +11 -2
- package/dist/{chunk-TUAHUTTB.js → chunk-5NJC7NRO.js} +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/prepare-docs/copy-raw.d.ts.map +1 -1
- package/dist/prepare-docs/prepare.js +1 -1
- package/dist/prompts/migration.d.ts +6 -0
- package/dist/prompts/migration.d.ts.map +1 -0
- package/dist/stdio.js +402 -30
- package/dist/tools/migration.d.ts +40 -0
- package/dist/tools/migration.d.ts.map +1 -0
- package/package.json +8 -12
- package/.docs/organized/changelogs/%40mastra%2Fcloud.md +0 -302
- package/.docs/raw/observability/nextjs-tracing.mdx +0 -109
- package/.docs/raw/observability/otel-tracing.mdx +0 -189
- package/.docs/raw/reference/agents/getScorers.mdx +0 -69
- package/.docs/raw/reference/agents/getTools.mdx +0 -69
- package/.docs/raw/reference/agents/getWorkflows.mdx +0 -69
- package/.docs/raw/reference/client-js/workflows-legacy.mdx +0 -143
- package/.docs/raw/reference/core/getAgents.mdx +0 -35
- package/.docs/raw/reference/core/getLogs.mdx +0 -96
- package/.docs/raw/reference/core/getLogsByRunId.mdx +0 -87
- package/.docs/raw/reference/core/getMCPServers.mdx +0 -36
- package/.docs/raw/reference/core/getMemory.mdx +0 -36
- package/.docs/raw/reference/core/getScorerByName.mdx +0 -78
- package/.docs/raw/reference/core/getScorers.mdx +0 -43
- package/.docs/raw/reference/core/getVectors.mdx +0 -36
- package/.docs/raw/reference/core/getWorkflows.mdx +0 -45
- package/.docs/raw/reference/evals/context-position.mdx +0 -197
- package/.docs/raw/reference/evals/context-relevancy.mdx +0 -196
- package/.docs/raw/reference/evals/contextual-recall.mdx +0 -196
- package/.docs/raw/reference/evals/summarization.mdx +0 -212
- package/.docs/raw/reference/legacyWorkflows/after.mdx +0 -89
- package/.docs/raw/reference/legacyWorkflows/afterEvent.mdx +0 -79
- package/.docs/raw/reference/legacyWorkflows/commit.mdx +0 -33
- package/.docs/raw/reference/legacyWorkflows/createRun.mdx +0 -76
- package/.docs/raw/reference/legacyWorkflows/else.mdx +0 -68
- package/.docs/raw/reference/legacyWorkflows/events.mdx +0 -305
- package/.docs/raw/reference/legacyWorkflows/execute.mdx +0 -110
- package/.docs/raw/reference/legacyWorkflows/if.mdx +0 -108
- package/.docs/raw/reference/legacyWorkflows/resume.mdx +0 -158
- package/.docs/raw/reference/legacyWorkflows/resumeWithEvent.mdx +0 -133
- package/.docs/raw/reference/legacyWorkflows/snapshots.mdx +0 -207
- package/.docs/raw/reference/legacyWorkflows/start.mdx +0 -87
- package/.docs/raw/reference/legacyWorkflows/step-class.mdx +0 -100
- package/.docs/raw/reference/legacyWorkflows/step-condition.mdx +0 -137
- package/.docs/raw/reference/legacyWorkflows/step-function.mdx +0 -93
- package/.docs/raw/reference/legacyWorkflows/step-options.mdx +0 -69
- package/.docs/raw/reference/legacyWorkflows/step-retries.mdx +0 -196
- package/.docs/raw/reference/legacyWorkflows/suspend.mdx +0 -70
- package/.docs/raw/reference/legacyWorkflows/then.mdx +0 -72
- package/.docs/raw/reference/legacyWorkflows/until.mdx +0 -168
- package/.docs/raw/reference/legacyWorkflows/watch.mdx +0 -124
- package/.docs/raw/reference/legacyWorkflows/while.mdx +0 -168
- package/.docs/raw/reference/legacyWorkflows/workflow.mdx +0 -234
- package/.docs/raw/reference/memory/getThreadsByResourceId.mdx +0 -79
- package/.docs/raw/reference/memory/getThreadsByResourceIdPaginated.mdx +0 -110
- package/.docs/raw/reference/observability/ai-tracing/ai-tracing.mdx +0 -185
- package/.docs/raw/reference/observability/ai-tracing/configuration.mdx +0 -238
- package/.docs/raw/reference/observability/otel-tracing/otel-config.mdx +0 -117
- package/.docs/raw/reference/observability/otel-tracing/providers/arize-ax.mdx +0 -81
- package/.docs/raw/reference/observability/otel-tracing/providers/arize-phoenix.mdx +0 -121
- package/.docs/raw/reference/observability/otel-tracing/providers/braintrust.mdx +0 -40
- package/.docs/raw/reference/observability/otel-tracing/providers/dash0.mdx +0 -40
- package/.docs/raw/reference/observability/otel-tracing/providers/index.mdx +0 -20
- package/.docs/raw/reference/observability/otel-tracing/providers/keywordsai.mdx +0 -73
- package/.docs/raw/reference/observability/otel-tracing/providers/laminar.mdx +0 -41
- package/.docs/raw/reference/observability/otel-tracing/providers/langfuse.mdx +0 -84
- package/.docs/raw/reference/observability/otel-tracing/providers/langsmith.mdx +0 -48
- package/.docs/raw/reference/observability/otel-tracing/providers/langwatch.mdx +0 -43
- package/.docs/raw/reference/observability/otel-tracing/providers/new-relic.mdx +0 -40
- package/.docs/raw/reference/observability/otel-tracing/providers/signoz.mdx +0 -40
- package/.docs/raw/reference/observability/otel-tracing/providers/traceloop.mdx +0 -40
- package/.docs/raw/reference/scorers/answer-relevancy.mdx +0 -227
- package/.docs/raw/reference/scorers/bias.mdx +0 -228
- package/.docs/raw/reference/scorers/completeness.mdx +0 -214
- package/.docs/raw/reference/scorers/content-similarity.mdx +0 -197
- package/.docs/raw/reference/scorers/context-precision.mdx +0 -352
- package/.docs/raw/reference/scorers/faithfulness.mdx +0 -241
- package/.docs/raw/reference/scorers/hallucination.mdx +0 -252
- package/.docs/raw/reference/scorers/keyword-coverage.mdx +0 -229
- package/.docs/raw/reference/scorers/prompt-alignment.mdx +0 -668
- package/.docs/raw/reference/scorers/textual-difference.mdx +0 -203
- package/.docs/raw/reference/scorers/tone-consistency.mdx +0 -211
- package/.docs/raw/reference/scorers/toxicity.mdx +0 -228
- package/.docs/raw/reference/workflows/run-methods/watch.mdx +0 -73
- package/.docs/raw/scorers/evals-old-api/custom-eval.mdx +0 -24
- package/.docs/raw/scorers/evals-old-api/overview.mdx +0 -106
- package/.docs/raw/scorers/evals-old-api/running-in-ci.mdx +0 -85
- package/.docs/raw/scorers/evals-old-api/textual-evals.mdx +0 -58
- package/.docs/raw/scorers/off-the-shelf-scorers.mdx +0 -50
- package/.docs/raw/workflows-legacy/control-flow.mdx +0 -774
- package/.docs/raw/workflows-legacy/dynamic-workflows.mdx +0 -239
- package/.docs/raw/workflows-legacy/error-handling.mdx +0 -187
- package/.docs/raw/workflows-legacy/nested-workflows.mdx +0 -360
- package/.docs/raw/workflows-legacy/overview.mdx +0 -182
- package/.docs/raw/workflows-legacy/runtime-variables.mdx +0 -156
- package/.docs/raw/workflows-legacy/steps.mdx +0 -115
- package/.docs/raw/workflows-legacy/suspend-and-resume.mdx +0 -406
- package/.docs/raw/workflows-legacy/variables.mdx +0 -318
|
@@ -1,774 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: "Control Flow in Legacy Workflows: Branching, Merging, and Conditions | Workflows (Legacy) | Mastra Docs"
|
|
3
|
-
sidebar_position: 7
|
|
4
|
-
sidebar_label: "Control Flow"
|
|
5
|
-
description: "Control flow in Mastra legacy workflows allows you to manage branching, merging, and conditions to construct legacy workflows that meet your logic requirements."
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# Control Flow in Legacy Workflows: Branching, Merging, and Conditions
|
|
9
|
-
|
|
10
|
-
When you create a multi-step process, you may need to run steps in parallel, chain them sequentially, or follow different paths based on outcomes. This page describes how you can manage branching, merging, and conditions to construct workflows that meet your logic requirements. The code snippets show the key patterns for structuring complex control flow.
|
|
11
|
-
|
|
12
|
-
## Parallel Execution
|
|
13
|
-
|
|
14
|
-
You can run multiple steps at the same time if they don't depend on each other. This approach can speed up your workflow when steps perform independent tasks. The code below shows how to add two steps in parallel:
|
|
15
|
-
|
|
16
|
-
```typescript
|
|
17
|
-
myWorkflow.step(fetchUserData).step(fetchOrderData);
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
See the [Parallel Steps](/examples/workflows_legacy/parallel-steps) example for more details.
|
|
21
|
-
|
|
22
|
-
## Sequential Execution
|
|
23
|
-
|
|
24
|
-
Sometimes you need to run steps in strict order to ensure outputs from one step become inputs for the next. Use .then() to link dependent operations. The code below shows how to chain steps sequentially:
|
|
25
|
-
|
|
26
|
-
```typescript
|
|
27
|
-
myWorkflow.step(fetchOrderData).then(validateData).then(processOrder);
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
See the [Sequential Steps](/examples/workflows_legacy/sequential-steps) example for more details.
|
|
31
|
-
|
|
32
|
-
## Branching and Merging Paths
|
|
33
|
-
|
|
34
|
-
When different outcomes require different paths, branching is helpful. You can also merge paths later once they complete. The code below shows how to branch after stepA and later converge on stepF:
|
|
35
|
-
|
|
36
|
-
```typescript
|
|
37
|
-
myWorkflow
|
|
38
|
-
.step(stepA)
|
|
39
|
-
.then(stepB)
|
|
40
|
-
.then(stepD)
|
|
41
|
-
.after(stepA)
|
|
42
|
-
.step(stepC)
|
|
43
|
-
.then(stepE)
|
|
44
|
-
.after([stepD, stepE])
|
|
45
|
-
.step(stepF);
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
In this example:
|
|
49
|
-
|
|
50
|
-
- stepA leads to stepB, then to stepD.
|
|
51
|
-
- Separately, stepA also triggers stepC, which in turn leads to stepE.
|
|
52
|
-
- Separately, stepF is triggered when both stepD and stepE are completed.
|
|
53
|
-
|
|
54
|
-
See the [Branching Paths](/examples/workflows_legacy/branching-paths) example for more details.
|
|
55
|
-
|
|
56
|
-
## Merging Multiple Branches
|
|
57
|
-
|
|
58
|
-
Sometimes you need a step to execute only after multiple other steps have completed. Mastra provides a compound `.after([])` syntax that allows you to specify multiple dependencies for a step.
|
|
59
|
-
|
|
60
|
-
```typescript
|
|
61
|
-
myWorkflow
|
|
62
|
-
.step(fetchUserData)
|
|
63
|
-
.then(validateUserData)
|
|
64
|
-
.step(fetchProductData)
|
|
65
|
-
.then(validateProductData)
|
|
66
|
-
// This step will only run after BOTH validateUserData AND validateProductData have completed
|
|
67
|
-
.after([validateUserData, validateProductData])
|
|
68
|
-
.step(processOrder);
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
In this example:
|
|
72
|
-
|
|
73
|
-
- `fetchUserData` and `fetchProductData` run in parallel branches
|
|
74
|
-
- Each branch has its own validation step
|
|
75
|
-
- The `processOrder` step only executes after both validation steps have completed successfully
|
|
76
|
-
|
|
77
|
-
This pattern is particularly useful for:
|
|
78
|
-
|
|
79
|
-
- Joining parallel execution paths
|
|
80
|
-
- Implementing synchronization points in your workflow
|
|
81
|
-
- Ensuring all required data is available before proceeding
|
|
82
|
-
|
|
83
|
-
You can also create complex dependency patterns by combining multiple `.after([])` calls:
|
|
84
|
-
|
|
85
|
-
```typescript
|
|
86
|
-
myWorkflow
|
|
87
|
-
// First branch
|
|
88
|
-
.step(stepA)
|
|
89
|
-
.then(stepB)
|
|
90
|
-
.then(stepC)
|
|
91
|
-
|
|
92
|
-
// Second branch
|
|
93
|
-
.step(stepD)
|
|
94
|
-
.then(stepE)
|
|
95
|
-
|
|
96
|
-
// Third branch
|
|
97
|
-
.step(stepF)
|
|
98
|
-
.then(stepG)
|
|
99
|
-
|
|
100
|
-
// This step depends on the completion of multiple branches
|
|
101
|
-
.after([stepC, stepE, stepG])
|
|
102
|
-
.step(finalStep);
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
## Cyclical Dependencies and Loops
|
|
106
|
-
|
|
107
|
-
Workflows often need to repeat steps until certain conditions are met. Mastra provides two powerful methods for creating loops: `until` and `while`. These methods offer an intuitive way to implement repetitive tasks.
|
|
108
|
-
|
|
109
|
-
### Using Manual Cyclical Dependencies (Legacy Approach)
|
|
110
|
-
|
|
111
|
-
In earlier versions, you could create loops by manually defining cyclical dependencies with conditions:
|
|
112
|
-
|
|
113
|
-
```typescript
|
|
114
|
-
myWorkflow
|
|
115
|
-
.step(fetchData)
|
|
116
|
-
.then(processData)
|
|
117
|
-
.after(processData)
|
|
118
|
-
.step(finalizeData, {
|
|
119
|
-
when: { "processData.status": "success" },
|
|
120
|
-
})
|
|
121
|
-
.step(fetchData, {
|
|
122
|
-
when: { "processData.status": "retry" },
|
|
123
|
-
});
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
While this approach still works, the newer `until` and `while` methods provide a cleaner and more maintainable way to create loops.
|
|
127
|
-
|
|
128
|
-
### Using `until` for Condition-Based Loops
|
|
129
|
-
|
|
130
|
-
The `until` method repeats a step until a specified condition becomes true. It takes these arguments:
|
|
131
|
-
|
|
132
|
-
1. A condition that determines when to stop looping
|
|
133
|
-
2. The step to repeat
|
|
134
|
-
3. Optional variables to pass to the repeated step
|
|
135
|
-
|
|
136
|
-
```typescript
|
|
137
|
-
import { LegacyStep, LegacyWorkflow } from "@mastra/core/workflows/legacy";
|
|
138
|
-
import { z } from "zod";
|
|
139
|
-
|
|
140
|
-
// Step that increments a counter until target is reached
|
|
141
|
-
const incrementStep = new LegacyStep({
|
|
142
|
-
id: "increment",
|
|
143
|
-
inputSchema: z.object({
|
|
144
|
-
// Current counter value
|
|
145
|
-
counter: z.number().optional(),
|
|
146
|
-
}),
|
|
147
|
-
outputSchema: z.object({
|
|
148
|
-
// Updated counter value
|
|
149
|
-
updatedCounter: z.number(),
|
|
150
|
-
}),
|
|
151
|
-
execute: async ({ context }) => {
|
|
152
|
-
const { counter = 0 } = context.inputData;
|
|
153
|
-
return { updatedCounter: counter + 1 };
|
|
154
|
-
},
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
workflow
|
|
158
|
-
.step(incrementStep)
|
|
159
|
-
.until(
|
|
160
|
-
async ({ context }) => {
|
|
161
|
-
// Stop when counter reaches 10
|
|
162
|
-
const result = context.getStepResult(incrementStep);
|
|
163
|
-
return (result?.updatedCounter ?? 0) >= 10;
|
|
164
|
-
},
|
|
165
|
-
incrementStep,
|
|
166
|
-
{
|
|
167
|
-
// Pass current counter to next iteration
|
|
168
|
-
counter: {
|
|
169
|
-
step: incrementStep,
|
|
170
|
-
path: "updatedCounter",
|
|
171
|
-
},
|
|
172
|
-
},
|
|
173
|
-
)
|
|
174
|
-
.then(finalStep);
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
You can also use a reference-based condition:
|
|
178
|
-
|
|
179
|
-
```typescript
|
|
180
|
-
workflow
|
|
181
|
-
.step(incrementStep)
|
|
182
|
-
.until(
|
|
183
|
-
{
|
|
184
|
-
ref: { step: incrementStep, path: "updatedCounter" },
|
|
185
|
-
query: { $gte: 10 },
|
|
186
|
-
},
|
|
187
|
-
incrementStep,
|
|
188
|
-
{
|
|
189
|
-
counter: {
|
|
190
|
-
step: incrementStep,
|
|
191
|
-
path: "updatedCounter",
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
|
-
)
|
|
195
|
-
.then(finalStep);
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
### Using `while` for Condition-Based Loops
|
|
199
|
-
|
|
200
|
-
The `while` method repeats a step as long as a specified condition remains true. It takes the same arguments as `until`:
|
|
201
|
-
|
|
202
|
-
1. A condition that determines when to continue looping
|
|
203
|
-
2. The step to repeat
|
|
204
|
-
3. Optional variables to pass to the repeated step
|
|
205
|
-
|
|
206
|
-
```typescript
|
|
207
|
-
// Step that increments a counter while below target
|
|
208
|
-
const incrementStep = new LegacyStep({
|
|
209
|
-
id: "increment",
|
|
210
|
-
inputSchema: z.object({
|
|
211
|
-
// Current counter value
|
|
212
|
-
counter: z.number().optional(),
|
|
213
|
-
}),
|
|
214
|
-
outputSchema: z.object({
|
|
215
|
-
// Updated counter value
|
|
216
|
-
updatedCounter: z.number(),
|
|
217
|
-
}),
|
|
218
|
-
execute: async ({ context }) => {
|
|
219
|
-
const { counter = 0 } = context.inputData;
|
|
220
|
-
return { updatedCounter: counter + 1 };
|
|
221
|
-
},
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
workflow
|
|
225
|
-
.step(incrementStep)
|
|
226
|
-
.while(
|
|
227
|
-
async ({ context }) => {
|
|
228
|
-
// Continue while counter is less than 10
|
|
229
|
-
const result = context.getStepResult(incrementStep);
|
|
230
|
-
return (result?.updatedCounter ?? 0) < 10;
|
|
231
|
-
},
|
|
232
|
-
incrementStep,
|
|
233
|
-
{
|
|
234
|
-
// Pass current counter to next iteration
|
|
235
|
-
counter: {
|
|
236
|
-
step: incrementStep,
|
|
237
|
-
path: "updatedCounter",
|
|
238
|
-
},
|
|
239
|
-
},
|
|
240
|
-
)
|
|
241
|
-
.then(finalStep);
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
You can also use a reference-based condition:
|
|
245
|
-
|
|
246
|
-
```typescript
|
|
247
|
-
workflow
|
|
248
|
-
.step(incrementStep)
|
|
249
|
-
.while(
|
|
250
|
-
{
|
|
251
|
-
ref: { step: incrementStep, path: "updatedCounter" },
|
|
252
|
-
query: { $lt: 10 },
|
|
253
|
-
},
|
|
254
|
-
incrementStep,
|
|
255
|
-
{
|
|
256
|
-
counter: {
|
|
257
|
-
step: incrementStep,
|
|
258
|
-
path: "updatedCounter",
|
|
259
|
-
},
|
|
260
|
-
},
|
|
261
|
-
)
|
|
262
|
-
.then(finalStep);
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
### Comparison Operators for Reference Conditions
|
|
266
|
-
|
|
267
|
-
When using reference-based conditions, you can use these comparison operators:
|
|
268
|
-
|
|
269
|
-
| Operator | Description |
|
|
270
|
-
| -------- | ------------------------ |
|
|
271
|
-
| `$eq` | Equal to |
|
|
272
|
-
| `$ne` | Not equal to |
|
|
273
|
-
| `$gt` | Greater than |
|
|
274
|
-
| `$gte` | Greater than or equal to |
|
|
275
|
-
| `$lt` | Less than |
|
|
276
|
-
| `$lte` | Less than or equal to |
|
|
277
|
-
|
|
278
|
-
## Conditions
|
|
279
|
-
|
|
280
|
-
Use the when property to control whether a step runs based on data from previous steps. Below are three ways to specify conditions.
|
|
281
|
-
|
|
282
|
-
### Option 1: Function
|
|
283
|
-
|
|
284
|
-
```typescript
|
|
285
|
-
myWorkflow.step(
|
|
286
|
-
new Step({
|
|
287
|
-
id: "processData",
|
|
288
|
-
execute: async ({ context }) => {
|
|
289
|
-
// Action logic
|
|
290
|
-
},
|
|
291
|
-
}),
|
|
292
|
-
{
|
|
293
|
-
when: async ({ context }) => {
|
|
294
|
-
const fetchData = context?.getStepResult<{ status: string }>("fetchData");
|
|
295
|
-
return fetchData?.status === "success";
|
|
296
|
-
},
|
|
297
|
-
},
|
|
298
|
-
);
|
|
299
|
-
```
|
|
300
|
-
|
|
301
|
-
### Option 2: Query Object
|
|
302
|
-
|
|
303
|
-
```typescript
|
|
304
|
-
myWorkflow.step(
|
|
305
|
-
new Step({
|
|
306
|
-
id: "processData",
|
|
307
|
-
execute: async ({ context }) => {
|
|
308
|
-
// Action logic
|
|
309
|
-
},
|
|
310
|
-
}),
|
|
311
|
-
{
|
|
312
|
-
when: {
|
|
313
|
-
ref: {
|
|
314
|
-
step: {
|
|
315
|
-
id: "fetchData",
|
|
316
|
-
},
|
|
317
|
-
path: "status",
|
|
318
|
-
},
|
|
319
|
-
query: { $eq: "success" },
|
|
320
|
-
},
|
|
321
|
-
},
|
|
322
|
-
);
|
|
323
|
-
```
|
|
324
|
-
|
|
325
|
-
### Option 3: Simple Path Comparison
|
|
326
|
-
|
|
327
|
-
```typescript
|
|
328
|
-
myWorkflow.step(
|
|
329
|
-
new Step({
|
|
330
|
-
id: "processData",
|
|
331
|
-
execute: async ({ context }) => {
|
|
332
|
-
// Action logic
|
|
333
|
-
},
|
|
334
|
-
}),
|
|
335
|
-
{
|
|
336
|
-
when: {
|
|
337
|
-
"fetchData.status": "success",
|
|
338
|
-
},
|
|
339
|
-
},
|
|
340
|
-
);
|
|
341
|
-
```
|
|
342
|
-
|
|
343
|
-
## Data Access Patterns
|
|
344
|
-
|
|
345
|
-
Mastra provides several ways to pass data between steps:
|
|
346
|
-
|
|
347
|
-
1. **Context Object** - Access step results directly through the context object
|
|
348
|
-
2. **Variable Mapping** - Explicitly map outputs from one step to inputs of another
|
|
349
|
-
3. **getStepResult Method** - Type-safe method to retrieve step outputs
|
|
350
|
-
|
|
351
|
-
Each approach has its advantages depending on your use case and requirements for type safety.
|
|
352
|
-
|
|
353
|
-
### Using getStepResult Method
|
|
354
|
-
|
|
355
|
-
The `getStepResult` method provides a type-safe way to access step results. This is the recommended approach when working with TypeScript as it preserves type information.
|
|
356
|
-
|
|
357
|
-
#### Basic Usage
|
|
358
|
-
|
|
359
|
-
For better type safety, you can provide a type parameter to `getStepResult`:
|
|
360
|
-
|
|
361
|
-
```typescript showLineNumbers title="src/mastra/workflows/get-step-result.ts" copy
|
|
362
|
-
import { LegacyStep, LegacyWorkflow } from "@mastra/core/workflows/legacy";
|
|
363
|
-
import { z } from "zod";
|
|
364
|
-
|
|
365
|
-
const fetchUserStep = new LegacyStep({
|
|
366
|
-
id: "fetchUser",
|
|
367
|
-
outputSchema: z.object({
|
|
368
|
-
name: z.string(),
|
|
369
|
-
userId: z.string(),
|
|
370
|
-
}),
|
|
371
|
-
execute: async ({ context }) => {
|
|
372
|
-
return { name: "John Doe", userId: "123" };
|
|
373
|
-
},
|
|
374
|
-
});
|
|
375
|
-
|
|
376
|
-
const analyzeDataStep = new LegacyStep({
|
|
377
|
-
id: "analyzeData",
|
|
378
|
-
execute: async ({ context }) => {
|
|
379
|
-
// Type-safe access to previous step result
|
|
380
|
-
const userData = context.getStepResult<{ name: string; userId: string }>(
|
|
381
|
-
"fetchUser",
|
|
382
|
-
);
|
|
383
|
-
|
|
384
|
-
if (!userData) {
|
|
385
|
-
return { status: "error", message: "User data not found" };
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
return {
|
|
389
|
-
analysis: `Analyzed data for user ${userData.name}`,
|
|
390
|
-
userId: userData.userId,
|
|
391
|
-
};
|
|
392
|
-
},
|
|
393
|
-
});
|
|
394
|
-
```
|
|
395
|
-
|
|
396
|
-
#### Using Step References
|
|
397
|
-
|
|
398
|
-
The most type-safe approach is to reference the step directly in the `getStepResult` call:
|
|
399
|
-
|
|
400
|
-
```typescript showLineNumbers title="src/mastra/workflows/step-reference.ts" copy
|
|
401
|
-
import { LegacyStep, LegacyWorkflow } from "@mastra/core/workflows/legacy";
|
|
402
|
-
import { z } from "zod";
|
|
403
|
-
|
|
404
|
-
// Define step with output schema
|
|
405
|
-
const fetchUserStep = new LegacyStep({
|
|
406
|
-
id: "fetchUser",
|
|
407
|
-
outputSchema: z.object({
|
|
408
|
-
userId: z.string(),
|
|
409
|
-
name: z.string(),
|
|
410
|
-
email: z.string(),
|
|
411
|
-
}),
|
|
412
|
-
execute: async () => {
|
|
413
|
-
return {
|
|
414
|
-
userId: "user123",
|
|
415
|
-
name: "John Doe",
|
|
416
|
-
email: "john@example.com",
|
|
417
|
-
};
|
|
418
|
-
},
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
const processUserStep = new LegacyStep({
|
|
422
|
-
id: "processUser",
|
|
423
|
-
execute: async ({ context }) => {
|
|
424
|
-
// TypeScript will infer the correct type from fetchUserStep's outputSchema
|
|
425
|
-
const userData = context.getStepResult(fetchUserStep);
|
|
426
|
-
|
|
427
|
-
return {
|
|
428
|
-
processed: true,
|
|
429
|
-
userName: userData?.name,
|
|
430
|
-
};
|
|
431
|
-
},
|
|
432
|
-
});
|
|
433
|
-
|
|
434
|
-
const workflow = new LegacyWorkflow({
|
|
435
|
-
name: "user-workflow",
|
|
436
|
-
});
|
|
437
|
-
|
|
438
|
-
workflow.step(fetchUserStep).then(processUserStep).commit();
|
|
439
|
-
```
|
|
440
|
-
|
|
441
|
-
### Using Variable Mapping
|
|
442
|
-
|
|
443
|
-
Variable mapping is an explicit way to define data flow between steps.
|
|
444
|
-
This approach makes dependencies clear and provides good type safety.
|
|
445
|
-
The data injected into the step is available in the `context.inputData` object, and typed based on the `inputSchema` of the step.
|
|
446
|
-
|
|
447
|
-
```typescript showLineNumbers title="src/mastra/workflows/variable-mapping.ts" copy
|
|
448
|
-
import { LegacyStep, LegacyWorkflow } from "@mastra/core/workflows/legacy";
|
|
449
|
-
import { z } from "zod";
|
|
450
|
-
|
|
451
|
-
const fetchUserStep = new LegacyStep({
|
|
452
|
-
id: "fetchUser",
|
|
453
|
-
outputSchema: z.object({
|
|
454
|
-
userId: z.string(),
|
|
455
|
-
name: z.string(),
|
|
456
|
-
email: z.string(),
|
|
457
|
-
}),
|
|
458
|
-
execute: async () => {
|
|
459
|
-
return {
|
|
460
|
-
userId: "user123",
|
|
461
|
-
name: "John Doe",
|
|
462
|
-
email: "john@example.com",
|
|
463
|
-
};
|
|
464
|
-
},
|
|
465
|
-
});
|
|
466
|
-
|
|
467
|
-
const sendEmailStep = new LegacyStep({
|
|
468
|
-
id: "sendEmail",
|
|
469
|
-
inputSchema: z.object({
|
|
470
|
-
recipientEmail: z.string(),
|
|
471
|
-
recipientName: z.string(),
|
|
472
|
-
}),
|
|
473
|
-
execute: async ({ context }) => {
|
|
474
|
-
const { recipientEmail, recipientName } = context.inputData;
|
|
475
|
-
|
|
476
|
-
// Send email logic here
|
|
477
|
-
return {
|
|
478
|
-
status: "sent",
|
|
479
|
-
to: recipientEmail,
|
|
480
|
-
};
|
|
481
|
-
},
|
|
482
|
-
});
|
|
483
|
-
|
|
484
|
-
const workflow = new LegacyWorkflow({
|
|
485
|
-
name: "email-workflow",
|
|
486
|
-
});
|
|
487
|
-
|
|
488
|
-
workflow
|
|
489
|
-
.step(fetchUserStep)
|
|
490
|
-
.then(sendEmailStep, {
|
|
491
|
-
variables: {
|
|
492
|
-
// Map specific fields from fetchUser to sendEmail inputs
|
|
493
|
-
recipientEmail: { step: fetchUserStep, path: "email" },
|
|
494
|
-
recipientName: { step: fetchUserStep, path: "name" },
|
|
495
|
-
},
|
|
496
|
-
})
|
|
497
|
-
.commit();
|
|
498
|
-
```
|
|
499
|
-
|
|
500
|
-
For more details on variable mapping, see the [Data Mapping with Workflow Variables](./variables) documentation.
|
|
501
|
-
|
|
502
|
-
### Using the Context Object
|
|
503
|
-
|
|
504
|
-
The context object provides direct access to all step results and their outputs. This approach is more flexible but requires careful handling to maintain type safety.
|
|
505
|
-
You can access step results directly through the `context.steps` object:
|
|
506
|
-
|
|
507
|
-
```typescript showLineNumbers title="src/mastra/workflows/context-access.ts" copy
|
|
508
|
-
import { LegacyStep, LegacyWorkflow } from "@mastra/core/workflows/legacy";
|
|
509
|
-
import { z } from "zod";
|
|
510
|
-
|
|
511
|
-
const processOrderStep = new LegacyStep({
|
|
512
|
-
id: "processOrder",
|
|
513
|
-
execute: async ({ context }) => {
|
|
514
|
-
// Access data from a previous step
|
|
515
|
-
let userData: { name: string; userId: string };
|
|
516
|
-
if (context.steps["fetchUser"]?.status === "success") {
|
|
517
|
-
userData = context.steps.fetchUser.output;
|
|
518
|
-
} else {
|
|
519
|
-
throw new Error("User data not found");
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
return {
|
|
523
|
-
orderId: "order123",
|
|
524
|
-
userId: userData.userId,
|
|
525
|
-
status: "processing",
|
|
526
|
-
};
|
|
527
|
-
},
|
|
528
|
-
});
|
|
529
|
-
|
|
530
|
-
const workflow = new LegacyWorkflow({
|
|
531
|
-
name: "order-workflow",
|
|
532
|
-
});
|
|
533
|
-
|
|
534
|
-
workflow.step(fetchUserStep).then(processOrderStep).commit();
|
|
535
|
-
```
|
|
536
|
-
|
|
537
|
-
### Workflow-Level Type Safety
|
|
538
|
-
|
|
539
|
-
For comprehensive type safety across your entire workflow, you can define types for all steps and pass them to the Workflow
|
|
540
|
-
This allows you to get type safety for the context object on conditions, and on step results in the final workflow output.
|
|
541
|
-
|
|
542
|
-
```typescript showLineNumbers title="src/mastra/workflows/workflow-typing.ts" copy
|
|
543
|
-
import { LegacyStep, LegacyWorkflow } from "@mastra/core/workflows/legacy";
|
|
544
|
-
import { z } from "zod";
|
|
545
|
-
|
|
546
|
-
// Create steps with typed outputs
|
|
547
|
-
const fetchUserStep = new LegacyStep({
|
|
548
|
-
id: "fetchUser",
|
|
549
|
-
outputSchema: z.object({
|
|
550
|
-
userId: z.string(),
|
|
551
|
-
name: z.string(),
|
|
552
|
-
email: z.string(),
|
|
553
|
-
}),
|
|
554
|
-
execute: async () => {
|
|
555
|
-
return {
|
|
556
|
-
userId: "user123",
|
|
557
|
-
name: "John Doe",
|
|
558
|
-
email: "john@example.com",
|
|
559
|
-
};
|
|
560
|
-
},
|
|
561
|
-
});
|
|
562
|
-
|
|
563
|
-
const processOrderStep = new LegacyStep({
|
|
564
|
-
id: "processOrder",
|
|
565
|
-
execute: async ({ context }) => {
|
|
566
|
-
// TypeScript knows the shape of userData
|
|
567
|
-
const userData = context.getStepResult(fetchUserStep);
|
|
568
|
-
|
|
569
|
-
return {
|
|
570
|
-
orderId: "order123",
|
|
571
|
-
status: "processing",
|
|
572
|
-
};
|
|
573
|
-
},
|
|
574
|
-
});
|
|
575
|
-
|
|
576
|
-
const workflow = new LegacyWorkflow<
|
|
577
|
-
[typeof fetchUserStep, typeof processOrderStep]
|
|
578
|
-
>({
|
|
579
|
-
name: "typed-workflow",
|
|
580
|
-
});
|
|
581
|
-
|
|
582
|
-
workflow
|
|
583
|
-
.step(fetchUserStep)
|
|
584
|
-
.then(processOrderStep)
|
|
585
|
-
.until(async ({ context }) => {
|
|
586
|
-
// TypeScript knows the shape of userData here
|
|
587
|
-
const res = context.getStepResult("fetchUser");
|
|
588
|
-
return res?.userId === "123";
|
|
589
|
-
}, processOrderStep)
|
|
590
|
-
.commit();
|
|
591
|
-
```
|
|
592
|
-
|
|
593
|
-
### Accessing Trigger Data
|
|
594
|
-
|
|
595
|
-
In addition to step results, you can access the original trigger data that started the workflow:
|
|
596
|
-
|
|
597
|
-
```typescript showLineNumbers title="src/mastra/workflows/trigger-data.ts" copy
|
|
598
|
-
import { LegacyStep, LegacyWorkflow } from "@mastra/core/workflows/legacy";
|
|
599
|
-
import { z } from "zod";
|
|
600
|
-
|
|
601
|
-
// Define trigger schema
|
|
602
|
-
const triggerSchema = z.object({
|
|
603
|
-
customerId: z.string(),
|
|
604
|
-
orderItems: z.array(z.string()),
|
|
605
|
-
});
|
|
606
|
-
|
|
607
|
-
type TriggerType = z.infer<typeof triggerSchema>;
|
|
608
|
-
|
|
609
|
-
const processOrderStep = new LegacyStep({
|
|
610
|
-
id: "processOrder",
|
|
611
|
-
execute: async ({ context }) => {
|
|
612
|
-
// Access trigger data with type safety
|
|
613
|
-
const triggerData = context.getStepResult<TriggerType>("trigger");
|
|
614
|
-
|
|
615
|
-
return {
|
|
616
|
-
customerId: triggerData?.customerId,
|
|
617
|
-
itemCount: triggerData?.orderItems.length || 0,
|
|
618
|
-
status: "processing",
|
|
619
|
-
};
|
|
620
|
-
},
|
|
621
|
-
});
|
|
622
|
-
|
|
623
|
-
const workflow = new LegacyWorkflow({
|
|
624
|
-
name: "order-workflow",
|
|
625
|
-
triggerSchema,
|
|
626
|
-
});
|
|
627
|
-
|
|
628
|
-
workflow.step(processOrderStep).commit();
|
|
629
|
-
```
|
|
630
|
-
|
|
631
|
-
### Accessing Resume Data
|
|
632
|
-
|
|
633
|
-
The data injected into the step is available in the `context.inputData` object, and typed based on the `inputSchema` of the step.
|
|
634
|
-
|
|
635
|
-
```typescript showLineNumbers title="src/mastra/workflows/resume-data.ts" copy
|
|
636
|
-
import { LegacyStep, LegacyWorkflow } from "@mastra/core/workflows/legacy";
|
|
637
|
-
import { z } from "zod";
|
|
638
|
-
|
|
639
|
-
const processOrderStep = new LegacyStep({
|
|
640
|
-
id: "processOrder",
|
|
641
|
-
inputSchema: z.object({
|
|
642
|
-
orderId: z.string(),
|
|
643
|
-
}),
|
|
644
|
-
execute: async ({ context, suspend }) => {
|
|
645
|
-
const { orderId } = context.inputData;
|
|
646
|
-
|
|
647
|
-
if (!orderId) {
|
|
648
|
-
await suspend();
|
|
649
|
-
return;
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
return {
|
|
653
|
-
orderId,
|
|
654
|
-
status: "processed",
|
|
655
|
-
};
|
|
656
|
-
},
|
|
657
|
-
});
|
|
658
|
-
|
|
659
|
-
const workflow = new LegacyWorkflow({
|
|
660
|
-
name: "order-workflow",
|
|
661
|
-
});
|
|
662
|
-
|
|
663
|
-
workflow.step(processOrderStep).commit();
|
|
664
|
-
|
|
665
|
-
const run = workflow.createRun();
|
|
666
|
-
const result = await run.start();
|
|
667
|
-
|
|
668
|
-
const resumedResult = await workflow.resume({
|
|
669
|
-
runId: result.runId,
|
|
670
|
-
stepId: "processOrder",
|
|
671
|
-
inputData: {
|
|
672
|
-
orderId: "123",
|
|
673
|
-
},
|
|
674
|
-
});
|
|
675
|
-
|
|
676
|
-
console.log({ resumedResult });
|
|
677
|
-
```
|
|
678
|
-
|
|
679
|
-
### Accessing Workflow Results
|
|
680
|
-
|
|
681
|
-
You can get typed access to the results of a workflow by injecting the step types into the `Workflow` type params:
|
|
682
|
-
|
|
683
|
-
```typescript showLineNumbers title="src/mastra/workflows/get-results.ts" copy
|
|
684
|
-
import { LegacyStep, LegacyWorkflow } from "@mastra/core/workflows/legacy";
|
|
685
|
-
import { z } from "zod";
|
|
686
|
-
|
|
687
|
-
const fetchUserStep = new LegacyStep({
|
|
688
|
-
id: "fetchUser",
|
|
689
|
-
outputSchema: z.object({
|
|
690
|
-
userId: z.string(),
|
|
691
|
-
name: z.string(),
|
|
692
|
-
email: z.string(),
|
|
693
|
-
}),
|
|
694
|
-
execute: async () => {
|
|
695
|
-
return {
|
|
696
|
-
userId: "user123",
|
|
697
|
-
name: "John Doe",
|
|
698
|
-
email: "john@example.com",
|
|
699
|
-
};
|
|
700
|
-
},
|
|
701
|
-
});
|
|
702
|
-
|
|
703
|
-
const processOrderStep = new LegacyStep({
|
|
704
|
-
id: "processOrder",
|
|
705
|
-
outputSchema: z.object({
|
|
706
|
-
orderId: z.string(),
|
|
707
|
-
status: z.string(),
|
|
708
|
-
}),
|
|
709
|
-
execute: async ({ context }) => {
|
|
710
|
-
const userData = context.getStepResult(fetchUserStep);
|
|
711
|
-
return {
|
|
712
|
-
orderId: "order123",
|
|
713
|
-
status: "processing",
|
|
714
|
-
};
|
|
715
|
-
},
|
|
716
|
-
});
|
|
717
|
-
|
|
718
|
-
const workflow = new LegacyWorkflow<
|
|
719
|
-
[typeof fetchUserStep, typeof processOrderStep]
|
|
720
|
-
>({
|
|
721
|
-
name: "typed-workflow",
|
|
722
|
-
});
|
|
723
|
-
|
|
724
|
-
workflow.step(fetchUserStep).then(processOrderStep).commit();
|
|
725
|
-
|
|
726
|
-
const run = workflow.createRun();
|
|
727
|
-
const result = await run.start();
|
|
728
|
-
|
|
729
|
-
// The result is a discriminated union of the step results
|
|
730
|
-
// So it needs to be narrowed down via status checks
|
|
731
|
-
if (result.results.processOrder.status === "success") {
|
|
732
|
-
// TypeScript will know the shape of the results
|
|
733
|
-
const orderId = result.results.processOrder.output.orderId;
|
|
734
|
-
console.log({ orderId });
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
if (result.results.fetchUser.status === "success") {
|
|
738
|
-
const userId = result.results.fetchUser.output.userId;
|
|
739
|
-
console.log({ userId });
|
|
740
|
-
}
|
|
741
|
-
```
|
|
742
|
-
|
|
743
|
-
### Best Practices for Data Flow
|
|
744
|
-
|
|
745
|
-
1. **Use getStepResult with Step References for Type Safety**
|
|
746
|
-
- Ensures TypeScript can infer the correct types
|
|
747
|
-
- Catches type errors at compile time
|
|
748
|
-
|
|
749
|
-
2. \*_Use Variable Mapping for Explicit Dependencies_
|
|
750
|
-
- Makes data flow clear and maintainable
|
|
751
|
-
- Provides good documentation of step dependencies
|
|
752
|
-
|
|
753
|
-
3. **Define Output Schemas for Steps**
|
|
754
|
-
- Validates data at runtime
|
|
755
|
-
- Validates return type of the `execute` function
|
|
756
|
-
- Improves type inference in TypeScript
|
|
757
|
-
|
|
758
|
-
4. **Handle Missing Data Gracefully**
|
|
759
|
-
- Always check if step results exist before accessing properties
|
|
760
|
-
- Provide fallback values for optional data
|
|
761
|
-
|
|
762
|
-
5. **Keep Data Transformations Simple**
|
|
763
|
-
- Transform data in dedicated steps rather than in variable mappings
|
|
764
|
-
- Makes workflows easier to test and debug
|
|
765
|
-
|
|
766
|
-
### Comparison of Data Flow Methods
|
|
767
|
-
|
|
768
|
-
| Method | Type Safety | Explicitness | Use Case |
|
|
769
|
-
| ---------------- | ----------- | ------------ | ------------------------------------------------- |
|
|
770
|
-
| getStepResult | Highest | High | Complex workflows with strict typing requirements |
|
|
771
|
-
| Variable Mapping | High | High | When dependencies need to be clear and explicit |
|
|
772
|
-
| context.steps | Medium | Low | Quick access to step data in simple workflows |
|
|
773
|
-
|
|
774
|
-
By choosing the right data flow method for your use case, you can create workflows that are both type-safe and maintainable.
|