@mastra/mcp-docs-server 1.0.0-beta.4 → 1.0.0-beta.6
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%2Fstorage-test-utils.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fastra.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fconvex.md +29 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +411 -211
- package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fduckdb.md +42 -0
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Felasticsearch.md +52 -0
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Flance.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Frag.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Freact.md +89 -1
- package/.docs/organized/changelogs/%40mastra%2Fs3vectors.md +9 -0
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +42 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-gladia.md +92 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google-gemini-live.md +67 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +201 -1
- package/.docs/organized/changelogs/create-mastra.md +201 -1
- package/.docs/organized/changelogs/mastra.md +201 -1
- package/.docs/organized/code-examples/agui.md +1 -0
- package/.docs/organized/code-examples/ai-sdk-v5.md +1 -0
- package/.docs/organized/code-examples/mcp-server-adapters.md +721 -0
- package/.docs/organized/code-examples/memory-with-processors.md +1 -1
- package/.docs/organized/code-examples/quick-start.md +1 -1
- package/.docs/organized/code-examples/server-app-access.md +342 -0
- package/.docs/raw/agents/adding-voice.mdx +7 -10
- package/.docs/raw/agents/agent-approval.mdx +189 -0
- package/.docs/raw/agents/guardrails.mdx +26 -23
- package/.docs/raw/agents/networks.mdx +2 -2
- package/.docs/raw/agents/overview.mdx +27 -62
- package/.docs/raw/agents/processors.mdx +279 -0
- package/.docs/raw/agents/using-tools.mdx +4 -5
- package/.docs/raw/course/01-first-agent/05-running-playground.md +5 -5
- package/.docs/raw/course/01-first-agent/09-testing-your-agent.md +3 -3
- package/.docs/raw/course/01-first-agent/13-testing-your-tool.md +3 -3
- package/.docs/raw/course/01-first-agent/17-testing-memory.md +2 -2
- package/.docs/raw/course/04-workflows/07-using-playground.md +1 -1
- package/.docs/raw/deployment/building-mastra.mdx +1 -1
- package/.docs/raw/deployment/cloud-providers/amazon-ec2.mdx +1 -1
- package/.docs/raw/deployment/cloud-providers/aws-lambda.mdx +1 -1
- package/.docs/raw/deployment/cloud-providers/azure-app-services.mdx +1 -1
- package/.docs/raw/deployment/cloud-providers/digital-ocean.mdx +1 -1
- package/.docs/raw/deployment/cloud-providers/index.mdx +20 -27
- package/.docs/raw/deployment/cloud-providers/netlify-deployer.mdx +44 -13
- package/.docs/raw/deployment/mastra-cloud/observability.mdx +19 -17
- package/.docs/raw/deployment/mastra-cloud/setting-up.mdx +1 -1
- package/.docs/raw/deployment/overview.mdx +2 -2
- package/.docs/raw/deployment/web-framework.mdx +5 -5
- package/.docs/raw/evals/custom-scorers.mdx +3 -5
- package/.docs/raw/evals/overview.mdx +2 -3
- package/.docs/raw/evals/running-in-ci.mdx +0 -2
- package/.docs/raw/{guides/guide → getting-started}/manual-install.mdx +2 -2
- package/.docs/raw/getting-started/project-structure.mdx +1 -1
- package/.docs/raw/getting-started/start.mdx +72 -0
- package/.docs/raw/getting-started/studio.mdx +1 -1
- package/.docs/raw/{frameworks/agentic-uis/ai-sdk.mdx → guides/build-your-ui/ai-sdk-ui.mdx} +113 -11
- package/.docs/raw/{frameworks/web-frameworks → guides/getting-started}/astro.mdx +23 -25
- package/.docs/raw/{frameworks/servers → guides/getting-started}/express.mdx +3 -4
- package/.docs/raw/guides/{quickstarts/nextjs.mdx → getting-started/next-js.mdx} +11 -11
- package/.docs/raw/guides/{quickstarts/standalone-server.mdx → getting-started/quickstart.mdx} +7 -7
- package/.docs/raw/{frameworks/web-frameworks → guides/getting-started}/sveltekit.mdx +23 -25
- package/.docs/raw/{frameworks/web-frameworks → guides/getting-started}/vite-react.mdx +7 -7
- package/.docs/raw/guides/guide/ai-recruiter.mdx +2 -3
- package/.docs/raw/guides/guide/chef-michel.mdx +2 -3
- package/.docs/raw/guides/guide/notes-mcp-server.mdx +2 -2
- package/.docs/raw/guides/guide/research-assistant.mdx +7 -8
- package/.docs/raw/guides/guide/stock-agent.mdx +4 -6
- package/.docs/raw/guides/guide/web-search.mdx +12 -10
- package/.docs/raw/guides/guide/whatsapp-chat-bot.mdx +421 -0
- package/.docs/raw/guides/index.mdx +3 -35
- package/.docs/raw/guides/migrations/agentnetwork.mdx +4 -4
- package/.docs/raw/guides/migrations/ai-sdk-v4-to-v5.mdx +1 -1
- package/.docs/raw/guides/migrations/upgrade-to-v1/agent.mdx +40 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/tools.mdx +5 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/workflows.mdx +51 -0
- package/.docs/raw/guides/migrations/vnext-to-standard-apis.mdx +2 -2
- package/.docs/raw/index.mdx +2 -2
- package/.docs/raw/mcp/overview.mdx +3 -5
- package/.docs/raw/memory/memory-processors.mdx +264 -79
- package/.docs/raw/memory/semantic-recall.mdx +7 -7
- package/.docs/raw/memory/storage/memory-with-libsql.mdx +2 -4
- package/.docs/raw/memory/storage/memory-with-mongodb.mdx +2 -4
- package/.docs/raw/memory/storage/memory-with-pg.mdx +2 -4
- package/.docs/raw/memory/storage/memory-with-upstash.mdx +2 -4
- package/.docs/raw/memory/threads-and-resources.mdx +3 -3
- package/.docs/raw/memory/working-memory.mdx +14 -7
- package/.docs/raw/{logging.mdx → observability/logging.mdx} +1 -1
- package/.docs/raw/observability/overview.mdx +2 -3
- package/.docs/raw/observability/tracing/bridges/otel.mdx +176 -0
- package/.docs/raw/observability/tracing/exporters/arize.mdx +17 -0
- package/.docs/raw/observability/tracing/exporters/braintrust.mdx +19 -0
- package/.docs/raw/observability/tracing/exporters/langfuse.mdx +20 -0
- package/.docs/raw/observability/tracing/exporters/langsmith.mdx +12 -0
- package/.docs/raw/observability/tracing/exporters/otel.mdx +25 -5
- package/.docs/raw/observability/tracing/exporters/posthog.mdx +107 -0
- package/.docs/raw/observability/tracing/overview.mdx +74 -8
- package/.docs/raw/observability/tracing/processors/sensitive-data-filter.mdx +0 -1
- package/.docs/raw/rag/chunking-and-embedding.mdx +16 -17
- package/.docs/raw/rag/overview.mdx +3 -2
- package/.docs/raw/rag/retrieval.mdx +43 -38
- package/.docs/raw/rag/vector-databases.mdx +93 -2
- package/.docs/raw/reference/agents/agent.mdx +7 -10
- package/.docs/raw/reference/agents/generate.mdx +55 -6
- package/.docs/raw/reference/agents/generateLegacy.mdx +2 -2
- package/.docs/raw/reference/agents/getLLM.mdx +1 -1
- package/.docs/raw/reference/agents/network.mdx +46 -3
- package/.docs/raw/reference/cli/mastra.mdx +2 -1
- package/.docs/raw/reference/client-js/agents.mdx +3 -3
- package/.docs/raw/reference/client-js/memory.mdx +43 -0
- package/.docs/raw/reference/client-js/workflows.mdx +92 -63
- package/.docs/raw/reference/core/getLogger.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/mastra-model-gateway.mdx +5 -19
- package/.docs/raw/reference/core/setLogger.mdx +1 -1
- package/.docs/raw/reference/core/setTelemetry.mdx +1 -1
- package/.docs/raw/reference/deployer/netlify.mdx +1 -2
- package/.docs/raw/reference/evals/answer-relevancy.mdx +28 -98
- package/.docs/raw/reference/evals/answer-similarity.mdx +12 -258
- package/.docs/raw/reference/evals/bias.mdx +29 -87
- package/.docs/raw/reference/evals/completeness.mdx +31 -90
- package/.docs/raw/reference/evals/content-similarity.mdx +28 -88
- package/.docs/raw/reference/evals/context-precision.mdx +28 -130
- package/.docs/raw/reference/evals/context-relevance.mdx +11 -11
- package/.docs/raw/reference/evals/faithfulness.mdx +28 -101
- package/.docs/raw/reference/evals/hallucination.mdx +28 -103
- package/.docs/raw/reference/evals/keyword-coverage.mdx +28 -107
- package/.docs/raw/reference/evals/noise-sensitivity.mdx +11 -11
- package/.docs/raw/reference/evals/prompt-alignment.mdx +15 -15
- package/.docs/raw/reference/evals/scorer-utils.mdx +362 -0
- package/.docs/raw/reference/evals/textual-difference.mdx +27 -100
- package/.docs/raw/reference/evals/tone-consistency.mdx +25 -98
- package/.docs/raw/reference/evals/tool-call-accuracy.mdx +7 -7
- package/.docs/raw/reference/evals/toxicity.mdx +29 -92
- package/.docs/raw/reference/index.mdx +1 -0
- package/.docs/raw/reference/memory/memory-class.mdx +5 -7
- package/.docs/raw/reference/observability/tracing/bridges/otel.mdx +150 -0
- package/.docs/raw/reference/observability/tracing/configuration.mdx +0 -4
- package/.docs/raw/reference/observability/tracing/exporters/arize.mdx +4 -0
- package/.docs/raw/reference/observability/tracing/exporters/langsmith.mdx +17 -1
- package/.docs/raw/reference/observability/tracing/exporters/otel.mdx +6 -0
- package/.docs/raw/reference/observability/tracing/exporters/posthog.mdx +132 -0
- package/.docs/raw/reference/observability/tracing/instances.mdx +0 -4
- package/.docs/raw/reference/observability/tracing/interfaces.mdx +29 -4
- package/.docs/raw/reference/observability/tracing/spans.mdx +0 -4
- package/.docs/raw/reference/processors/batch-parts-processor.mdx +1 -1
- package/.docs/raw/reference/processors/language-detector.mdx +10 -3
- package/.docs/raw/reference/processors/message-history-processor.mdx +131 -0
- package/.docs/raw/reference/processors/moderation-processor.mdx +12 -5
- package/.docs/raw/reference/processors/pii-detector.mdx +12 -5
- package/.docs/raw/reference/processors/processor-interface.mdx +502 -0
- package/.docs/raw/reference/processors/prompt-injection-detector.mdx +10 -3
- package/.docs/raw/reference/processors/semantic-recall-processor.mdx +197 -0
- package/.docs/raw/reference/processors/system-prompt-scrubber.mdx +3 -4
- package/.docs/raw/reference/processors/token-limiter-processor.mdx +2 -2
- package/.docs/raw/reference/processors/tool-call-filter.mdx +125 -0
- package/.docs/raw/reference/processors/unicode-normalizer.mdx +1 -1
- package/.docs/raw/reference/processors/working-memory-processor.mdx +221 -0
- package/.docs/raw/reference/rag/embeddings.mdx +5 -5
- package/.docs/raw/reference/rag/rerank.mdx +1 -2
- package/.docs/raw/reference/rag/rerankWithScorer.mdx +0 -1
- package/.docs/raw/reference/storage/cloudflare-d1.mdx +37 -0
- package/.docs/raw/reference/storage/convex.mdx +164 -0
- package/.docs/raw/reference/storage/lance.mdx +33 -0
- package/.docs/raw/reference/storage/libsql.mdx +37 -0
- package/.docs/raw/reference/storage/mongodb.mdx +39 -0
- package/.docs/raw/reference/storage/mssql.mdx +37 -0
- package/.docs/raw/reference/storage/postgresql.mdx +37 -0
- package/.docs/raw/reference/streaming/ChunkType.mdx +1 -1
- package/.docs/raw/reference/streaming/agents/stream.mdx +64 -2
- package/.docs/raw/reference/streaming/workflows/observeStream.mdx +7 -9
- package/.docs/raw/reference/streaming/workflows/{resumeStreamVNext.mdx → resumeStream.mdx} +51 -11
- package/.docs/raw/reference/streaming/workflows/stream.mdx +83 -24
- package/.docs/raw/reference/templates/overview.mdx +1 -4
- package/.docs/raw/reference/tools/client.mdx +1 -2
- package/.docs/raw/reference/tools/create-tool.mdx +132 -0
- package/.docs/raw/reference/tools/graph-rag-tool.mdx +5 -5
- package/.docs/raw/reference/tools/mcp-client.mdx +76 -21
- package/.docs/raw/reference/tools/mcp-server.mdx +1 -2
- package/.docs/raw/reference/tools/vector-query-tool.mdx +14 -15
- package/.docs/raw/reference/vectors/chroma.mdx +81 -1
- package/.docs/raw/reference/vectors/convex.mdx +429 -0
- package/.docs/raw/reference/vectors/couchbase.mdx +24 -17
- package/.docs/raw/reference/vectors/duckdb.mdx +462 -0
- package/.docs/raw/reference/vectors/elasticsearch.mdx +310 -0
- package/.docs/raw/reference/vectors/lance.mdx +38 -22
- package/.docs/raw/reference/vectors/libsql.mdx +35 -2
- package/.docs/raw/reference/vectors/mongodb.mdx +35 -2
- package/.docs/raw/reference/vectors/opensearch.mdx +37 -16
- package/.docs/raw/reference/vectors/pg.mdx +43 -36
- package/.docs/raw/reference/vectors/pinecone.mdx +48 -1
- package/.docs/raw/reference/vectors/qdrant.mdx +36 -1
- package/.docs/raw/reference/vectors/turbopuffer.mdx +74 -0
- package/.docs/raw/reference/voice/google.mdx +159 -20
- package/.docs/raw/reference/voice/openai-realtime.mdx +2 -2
- package/.docs/raw/reference/voice/voice.addInstructions.mdx +2 -3
- package/.docs/raw/reference/voice/voice.addTools.mdx +1 -1
- package/.docs/raw/reference/voice/voice.answer.mdx +1 -1
- package/.docs/raw/reference/voice/voice.close.mdx +1 -1
- package/.docs/raw/reference/voice/voice.connect.mdx +1 -1
- package/.docs/raw/reference/voice/voice.off.mdx +1 -1
- package/.docs/raw/reference/voice/voice.on.mdx +1 -1
- package/.docs/raw/reference/voice/voice.send.mdx +1 -1
- package/.docs/raw/reference/voice/voice.updateConfig.mdx +1 -1
- package/.docs/raw/reference/workflows/run-methods/restart.mdx +142 -0
- package/.docs/raw/reference/workflows/run-methods/resume.mdx +44 -0
- package/.docs/raw/reference/workflows/run-methods/start.mdx +44 -0
- package/.docs/raw/reference/workflows/run.mdx +13 -5
- package/.docs/raw/reference/workflows/step.mdx +13 -0
- package/.docs/raw/reference/workflows/workflow.mdx +19 -0
- package/.docs/raw/server-db/mastra-client.mdx +1 -2
- package/.docs/raw/server-db/mastra-server.mdx +30 -1
- package/.docs/raw/server-db/request-context.mdx +0 -1
- package/.docs/raw/server-db/storage.mdx +11 -0
- package/.docs/raw/streaming/overview.mdx +26 -15
- package/.docs/raw/streaming/tool-streaming.mdx +48 -5
- package/.docs/raw/streaming/workflow-streaming.mdx +5 -11
- package/.docs/raw/tools-mcp/advanced-usage.mdx +1 -2
- package/.docs/raw/tools-mcp/mcp-overview.mdx +3 -5
- package/.docs/raw/voice/overview.mdx +21 -41
- package/.docs/raw/voice/speech-to-speech.mdx +4 -4
- package/.docs/raw/voice/speech-to-text.mdx +1 -2
- package/.docs/raw/voice/text-to-speech.mdx +1 -2
- package/.docs/raw/workflows/control-flow.mdx +180 -0
- package/.docs/raw/workflows/error-handling.mdx +1 -0
- package/.docs/raw/workflows/human-in-the-loop.mdx +4 -4
- package/.docs/raw/workflows/overview.mdx +56 -44
- package/.docs/raw/workflows/snapshots.mdx +1 -0
- package/.docs/raw/workflows/suspend-and-resume.mdx +85 -16
- package/.docs/raw/workflows/time-travel.mdx +313 -0
- package/.docs/raw/workflows/workflow-state.mdx +191 -0
- package/CHANGELOG.md +18 -0
- package/dist/{chunk-5NJC7NRO.js → chunk-4CM2BQNP.js} +24 -4
- package/dist/prepare-docs/package-changes.d.ts.map +1 -1
- package/dist/prepare-docs/prepare.js +1 -1
- package/dist/stdio.js +1 -1
- package/package.json +7 -7
- package/.docs/raw/agents/human-in-the-loop-with-tools.mdx +0 -90
- package/.docs/raw/frameworks/agentic-uis/cedar-os.mdx +0 -102
- package/.docs/raw/frameworks/agentic-uis/openrouter.mdx +0 -179
- package/.docs/raw/frameworks/web-frameworks/next-js.mdx +0 -379
- package/.docs/raw/getting-started/quickstart.mdx +0 -27
- package/.docs/raw/getting-started/templates.mdx +0 -73
- package/.docs/raw/reference/streaming/workflows/observeStreamVNext.mdx +0 -47
- package/.docs/raw/reference/streaming/workflows/streamVNext.mdx +0 -153
- /package/.docs/raw/{frameworks/agentic-uis → guides/build-your-ui}/assistant-ui.mdx +0 -0
- /package/.docs/raw/{frameworks/agentic-uis → guides/build-your-ui}/copilotkit.mdx +0 -0
|
@@ -90,60 +90,28 @@ Workflows can be composed using a number of different methods. The method you ch
|
|
|
90
90
|
|
|
91
91
|
## Workflow state
|
|
92
92
|
|
|
93
|
-
Workflow state lets you share values across steps without passing them through every step
|
|
93
|
+
Workflow state lets you share values across steps without passing them through every step's inputSchema and outputSchema. Use state for tracking progress, accumulating results, or sharing configuration across the entire workflow.
|
|
94
94
|
|
|
95
95
|
```typescript title="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
96
96
|
const step1 = createStep({
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}),
|
|
97
|
+
id: "step-1",
|
|
98
|
+
inputSchema: z.object({ message: z.string() }),
|
|
99
|
+
outputSchema: z.object({ formatted: z.string() }),
|
|
100
|
+
stateSchema: z.object({ counter: z.number() }),
|
|
101
101
|
execute: async ({ inputData, state, setState }) => {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
setState({
|
|
106
|
-
...state,
|
|
107
|
-
processedItems: [...processedItems, "item-1", "item-2"],
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
return {
|
|
111
|
-
formatted: message.toUpperCase(),
|
|
112
|
-
};
|
|
113
|
-
},
|
|
114
|
-
});
|
|
102
|
+
// Read from state
|
|
103
|
+
console.log(state.counter);
|
|
115
104
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
stateSchema: z.object({
|
|
119
|
-
metadata: z.object({
|
|
120
|
-
processedBy: z.string(),
|
|
121
|
-
}),
|
|
122
|
-
}),
|
|
123
|
-
execute: async ({ inputData, state }) => {
|
|
124
|
-
const { formatted } = inputData;
|
|
125
|
-
const { metadata } = state;
|
|
105
|
+
// Update state for subsequent steps
|
|
106
|
+
setState({ ...state, counter: state.counter + 1 });
|
|
126
107
|
|
|
127
|
-
return {
|
|
128
|
-
emphasized: `${formatted}!! ${metadata.processedBy}`,
|
|
129
|
-
};
|
|
108
|
+
return { formatted: inputData.message.toUpperCase() };
|
|
130
109
|
},
|
|
131
110
|
});
|
|
132
|
-
|
|
133
|
-
export const testWorkflow = createWorkflow({
|
|
134
|
-
// ...
|
|
135
|
-
stateSchema: z.object({
|
|
136
|
-
processedItems: z.array(z.string()),
|
|
137
|
-
metadata: z.object({
|
|
138
|
-
processedBy: z.string(),
|
|
139
|
-
}),
|
|
140
|
-
}),
|
|
141
|
-
})
|
|
142
|
-
.then(step1)
|
|
143
|
-
.then(step2)
|
|
144
|
-
.commit();
|
|
145
111
|
```
|
|
146
112
|
|
|
113
|
+
> See [Workflow State](/docs/v1/workflows/workflow-state) for complete documentation on state schemas, initial state, persistence across suspend/resume, and nested workflows.
|
|
114
|
+
|
|
147
115
|
## Workflows as steps
|
|
148
116
|
|
|
149
117
|
Use a workflow as a step to reuse its logic within a larger composition. Input and output follow the same schema rules described in [Core principles](/docs/v1/workflows/control-flow).
|
|
@@ -302,6 +270,49 @@ The workflow output includes the full execution lifecycle, showing the input and
|
|
|
302
270
|
}
|
|
303
271
|
```
|
|
304
272
|
|
|
273
|
+
## Restarting active workflow runs
|
|
274
|
+
|
|
275
|
+
When a workflow run loses connection to the server, it can be restarted from the last active step. This is useful for long-running workflows that might still be running when the server loses connection. Restarting a workflow run will resume execution from the last active step, and the workflow will continue from there.
|
|
276
|
+
|
|
277
|
+
### Restarting all active workflow runs of a workflow with `restartAllActiveWorkflowRuns()`
|
|
278
|
+
|
|
279
|
+
Use `restartAllActiveWorkflowRuns()` to restart all active workflow runs of a workflow. This helps restart all active workflow runs of a workflow, without having to manually loop through each run and restart.
|
|
280
|
+
|
|
281
|
+
```typescript showLineNumbers copy
|
|
282
|
+
workflow.restartAllActiveWorkflowRuns();
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### Restarting an active workflow run with `restart()`
|
|
286
|
+
|
|
287
|
+
Use `restart()` to restart an active workflow run from the last active step. This will resume execution from the last active step, and the workflow will continue from there.
|
|
288
|
+
|
|
289
|
+
```typescript showLineNumbers copy
|
|
290
|
+
const run = await workflow.createRun();
|
|
291
|
+
|
|
292
|
+
const result = await run.start({ inputData: { value: "initial data" } });
|
|
293
|
+
|
|
294
|
+
//.. server connection lost,
|
|
295
|
+
|
|
296
|
+
const restartedResult = await run.restart();
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### Identifying active workflow runs
|
|
300
|
+
|
|
301
|
+
When a workflow run is active, it will have a `status` of `running` or `waiting`. You can check the workflow's `status` to confirm it's active, and use `active` to identify the active workflow run.
|
|
302
|
+
|
|
303
|
+
```typescript showLineNumbers copy
|
|
304
|
+
const activeRuns = await workflow.listActiveWorkflowRuns();
|
|
305
|
+
if (activeRuns.runs.length > 0) {
|
|
306
|
+
console.log(activeRuns.runs);
|
|
307
|
+
}
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
:::Note
|
|
311
|
+
|
|
312
|
+
When running the local mastra server, all active workflow runs will be restarted automatically when the server starts.
|
|
313
|
+
|
|
314
|
+
:::
|
|
315
|
+
|
|
305
316
|
## Using `RequestContext`
|
|
306
317
|
|
|
307
318
|
Use [RequestContext](/docs/v1/server-db/request-context) to access request-specific values. This lets you conditionally adjust behavior based on the context of the request.
|
|
@@ -335,6 +346,7 @@ Use [Studio](/docs/v1/getting-started/studio) to easily run workflows with diffe
|
|
|
335
346
|
|
|
336
347
|
For a closer look at workflows, see our [Workflow Guide](/guides/v1/guide/ai-recruiter), which walks through the core concepts with a practical example.
|
|
337
348
|
|
|
349
|
+
- [Workflow State](/docs/v1/workflows/workflow-state)
|
|
338
350
|
- [Control Flow](/docs/v1/workflows/control-flow)
|
|
339
351
|
- [Suspend & Resume](/docs/v1/workflows/suspend-and-resume)
|
|
340
352
|
- [Error Handling](/docs/v1/workflows/error-handling)
|
|
@@ -268,4 +268,5 @@ if (result.status === "suspended") {
|
|
|
268
268
|
|
|
269
269
|
- [Control Flow](/docs/v1/workflows/control-flow)
|
|
270
270
|
- [Suspend & Resume](/docs/v1/workflows/suspend-and-resume)
|
|
271
|
+
- [Time Travel](/docs/v1/workflows/time-travel)
|
|
271
272
|
- [Human-in-the-loop](/docs/v1/workflows/human-in-the-loop)
|
|
@@ -13,7 +13,7 @@ Use `suspend()` to pause workflow execution at a specific step. You can define a
|
|
|
13
13
|
- If the condition isn’t met, the workflow pauses and returns `suspend()`.
|
|
14
14
|
- If the condition is met, the workflow continues with the remaining logic in the step.
|
|
15
15
|
|
|
16
|
-
](/img/workflows/workflows-suspend.jpg)
|
|
17
17
|
|
|
18
18
|
```typescript {9-11,16-18} title="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
19
19
|
const step1 = createStep({
|
|
@@ -56,13 +56,15 @@ export const testWorkflow = createWorkflow({
|
|
|
56
56
|
|
|
57
57
|
## Restarting a workflow with `resume()`
|
|
58
58
|
|
|
59
|
-
Use `resume()` to restart a suspended workflow from the step where it paused.
|
|
59
|
+
Use `resume()` to restart a suspended workflow from the step where it paused. Pass `resumeData` matching the step's `resumeSchema` to satisfy the suspend condition and continue execution.
|
|
60
60
|
|
|
61
|
-
](/img/workflows/workflows-resume.jpg)
|
|
62
|
+
|
|
63
|
+
```typescript showLineNumbers copy
|
|
64
|
+
import { step1 } from "./workflows/test-workflow";
|
|
62
65
|
|
|
63
|
-
```typescript {13} showLineNumbers copy
|
|
64
66
|
const workflow = mastra.getWorkflow("testWorkflow");
|
|
65
|
-
const run = await workflow.
|
|
67
|
+
const run = await workflow.createRun();
|
|
66
68
|
|
|
67
69
|
await run.start({
|
|
68
70
|
inputData: {
|
|
@@ -72,34 +74,99 @@ await run.start({
|
|
|
72
74
|
|
|
73
75
|
const handleResume = async () => {
|
|
74
76
|
const result = await run.resume({
|
|
75
|
-
step:
|
|
77
|
+
step: step1,
|
|
76
78
|
resumeData: { approved: true }
|
|
77
79
|
});
|
|
78
80
|
};
|
|
79
81
|
```
|
|
80
82
|
|
|
81
|
-
|
|
83
|
+
Passing the `step` object provides full type-safety for `resumeData`. Alternatively, you can pass a step ID for more flexibility when the ID comes from user input or a database.
|
|
82
84
|
|
|
83
|
-
```typescript
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
85
|
+
```typescript showLineNumbers copy
|
|
86
|
+
const result = await run.resume({
|
|
87
|
+
step: "step-1",
|
|
88
|
+
resumeData: { approved: true }
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
If only one step is suspended, you can omit the step argument entirely and Mastra will resume the last suspended step in the workflow.
|
|
93
|
+
|
|
94
|
+
When resuming with only a `runId`, create a run instance first using `createRunAsync()`.
|
|
90
95
|
|
|
96
|
+
```typescript showLineNumbers copy
|
|
97
|
+
const workflow = mastra.getWorkflow("testWorkflow");
|
|
98
|
+
const run = await workflow.createRunAsync({ runId: "123" });
|
|
99
|
+
|
|
100
|
+
const stream = run.resume({
|
|
101
|
+
resumeData: { approved: true }
|
|
102
|
+
});
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
You can call `resume()` from anywhere in your application, including HTTP endpoints, event handlers, in response to [human input](/docs/v1/workflows/human-in-the-loop), or timers.
|
|
106
|
+
|
|
107
|
+
```typescript showLineNumbers copy
|
|
91
108
|
const midnight = new Date();
|
|
92
109
|
midnight.setUTCHours(24, 0, 0, 0);
|
|
93
|
-
|
|
110
|
+
|
|
111
|
+
setTimeout(async () => {
|
|
112
|
+
await run.resume({
|
|
113
|
+
step: "step-1",
|
|
114
|
+
resumeData: { approved: true }
|
|
115
|
+
});
|
|
116
|
+
}, midnight.getTime() - Date.now());
|
|
94
117
|
```
|
|
95
118
|
|
|
119
|
+
## Accessing suspend data with `suspendData`
|
|
120
|
+
When a step is suspended, you may want to access the data that was provided to `suspend()` when the step is later resumed. Use the `suspendData` parameter in your step's execute function to access this data.
|
|
121
|
+
|
|
122
|
+
```typescript {22-25,29-30} title="src/mastra/workflows/user-approval.ts" showLineNumbers copy
|
|
123
|
+
const approvalStep = createStep({
|
|
124
|
+
id: "user-approval",
|
|
125
|
+
inputSchema: z.object({
|
|
126
|
+
requestId: z.string()
|
|
127
|
+
}),
|
|
128
|
+
resumeSchema: z.object({
|
|
129
|
+
approved: z.boolean()
|
|
130
|
+
}),
|
|
131
|
+
suspendSchema: z.object({
|
|
132
|
+
reason: z.string(),
|
|
133
|
+
requestDetails: z.string()
|
|
134
|
+
}),
|
|
135
|
+
outputSchema: z.object({
|
|
136
|
+
result: z.string()
|
|
137
|
+
}),
|
|
138
|
+
execute: async ({ inputData, resumeData, suspend, suspendData }) => {
|
|
139
|
+
const { requestId } = inputData;
|
|
140
|
+
const { approved } = resumeData ?? {};
|
|
141
|
+
|
|
142
|
+
// On first execution, suspend with context
|
|
143
|
+
if (!approved) {
|
|
144
|
+
return await suspend({
|
|
145
|
+
reason: "User approval required",
|
|
146
|
+
requestDetails: `Request ${requestId} pending review`
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// On resume, access the original suspend data
|
|
151
|
+
const suspendReason = suspendData?.reason || "Unknown";
|
|
152
|
+
const details = suspendData?.requestDetails || "No details";
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
result: `${details} - ${suspendReason} - Decision: ${approved ? 'Approved' : 'Rejected'}`
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
The `suspendData` parameter is automatically populated when a step is resumed and contains the exact data that was passed to the `suspend()` function during the original suspension. This allows you to maintain context about why the workflow was suspended and use that information during the resume process.
|
|
162
|
+
|
|
96
163
|
## Identifying suspended executions
|
|
97
164
|
|
|
98
165
|
When a workflow is suspended, it restarts from the step where it paused. You can check the workflow's `status` to confirm it's suspended, and use `suspended` to identify the paused step or [nested workflow](/docs/v1/workflows/overview#workflows-as-steps).
|
|
99
166
|
|
|
100
167
|
```typescript {11} showLineNumbers copy
|
|
101
168
|
const workflow = mastra.getWorkflow("testWorkflow");
|
|
102
|
-
const run = await workflow.
|
|
169
|
+
const run = await workflow.createRun();
|
|
103
170
|
|
|
104
171
|
const result = await run.start({
|
|
105
172
|
inputData: {
|
|
@@ -139,3 +206,5 @@ Sleep and event methods can be used to pause execution at the workflow level, wh
|
|
|
139
206
|
|
|
140
207
|
- [Control Flow](/docs/v1/workflows/control-flow)
|
|
141
208
|
- [Human-in-the-loop](/docs/v1/workflows/human-in-the-loop)
|
|
209
|
+
- [Snapshots](/docs/v1/workflows/snapshots)
|
|
210
|
+
- [Time Travel](/docs/v1/workflows/time-travel)
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Time Travel | Workflows"
|
|
3
|
+
description: "Re-execute workflow steps from a specific point using time travel debugging in Mastra"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Time Travel
|
|
7
|
+
|
|
8
|
+
Time travel allows you to re-execute a workflow starting from any specific step, using either stored snapshot data or custom context you provide. This is useful for debugging failed workflows, testing individual steps with different inputs, or recovering from errors without re-running the entire workflow.
|
|
9
|
+
You can also use time travel to execute a workflow that has not been run yet, starting from any specific step.
|
|
10
|
+
|
|
11
|
+
## How time travel works
|
|
12
|
+
|
|
13
|
+
When you call `timeTravel()` on a workflow run:
|
|
14
|
+
|
|
15
|
+
1. The workflow loads the existing snapshot from storage (if available)
|
|
16
|
+
2. Step results before the target step are reconstructed from the snapshot or provided context
|
|
17
|
+
3. Execution begins from the specified step with the provided or reconstructed input data
|
|
18
|
+
4. The workflow continues to completion from that point forward
|
|
19
|
+
|
|
20
|
+
Time travel requires storage to be configured since it relies on persisted workflow snapshots.
|
|
21
|
+
|
|
22
|
+
## Basic usage
|
|
23
|
+
|
|
24
|
+
Use `run.timeTravel()` to re-execute a workflow from a specific step:
|
|
25
|
+
|
|
26
|
+
```typescript showLineNumbers copy
|
|
27
|
+
import { mastra } from "./mastra";
|
|
28
|
+
|
|
29
|
+
const workflow = mastra.getWorkflow("myWorkflow");
|
|
30
|
+
const run = await workflow.createRun();
|
|
31
|
+
|
|
32
|
+
const result = await run.timeTravel({
|
|
33
|
+
step: "step2",
|
|
34
|
+
inputData: { previousStepResult: "custom value" },
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Specifying the target step
|
|
39
|
+
|
|
40
|
+
You can specify the target step using either a step reference or a step ID:
|
|
41
|
+
|
|
42
|
+
### Using step reference
|
|
43
|
+
|
|
44
|
+
```typescript showLineNumbers copy
|
|
45
|
+
const result = await run.timeTravel({
|
|
46
|
+
step: step2,
|
|
47
|
+
inputData: { value: 10 },
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Using step ID
|
|
52
|
+
|
|
53
|
+
```typescript showLineNumbers copy
|
|
54
|
+
const result = await run.timeTravel({
|
|
55
|
+
step: "step2",
|
|
56
|
+
inputData: { value: 10 },
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Nested workflow steps
|
|
61
|
+
|
|
62
|
+
For steps inside nested workflows, use dot notation, an array of step IDS or an array of step references:
|
|
63
|
+
|
|
64
|
+
```typescript showLineNumbers copy
|
|
65
|
+
// Using dot notation
|
|
66
|
+
const result = await run.timeTravel({
|
|
67
|
+
step: "nestedWorkflow.step3",
|
|
68
|
+
inputData: { value: 10 },
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Using array of step IDs
|
|
72
|
+
const result = await run.timeTravel({
|
|
73
|
+
step: ["nestedWorkflow", "step3"],
|
|
74
|
+
inputData: { value: 10 },
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// Using array of step references
|
|
78
|
+
const result = await run.timeTravel({
|
|
79
|
+
step: [nestedWorkflow, step3],
|
|
80
|
+
inputData: { value: 10 },
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Providing execution context
|
|
85
|
+
|
|
86
|
+
You can provide context to specify the state of previous steps when time traveling:
|
|
87
|
+
|
|
88
|
+
```typescript {3-13} showLineNumbers copy
|
|
89
|
+
const result = await run.timeTravel({
|
|
90
|
+
step: "step2",
|
|
91
|
+
context: {
|
|
92
|
+
step1: {
|
|
93
|
+
status: "success",
|
|
94
|
+
payload: { value: 0 },
|
|
95
|
+
output: { step1Result: 2 },
|
|
96
|
+
startedAt: Date.now(),
|
|
97
|
+
endedAt: Date.now(),
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The context object contains step results keyed by step ID. Each step result includes:
|
|
104
|
+
|
|
105
|
+
- `status`: The step's execution status (`success`, `failed`, `suspended`)
|
|
106
|
+
- `payload`: The input data passed to the step
|
|
107
|
+
- `output`: The step's output data (for successful steps)
|
|
108
|
+
- `startedAt`: Timestamp when the step started
|
|
109
|
+
- `endedAt`: Timestamp when the step ended (for completed steps)
|
|
110
|
+
- `suspendPayload`: Data passed to `suspend()` (for suspended steps)
|
|
111
|
+
- `resumePayload`: Data passed to `resume()` (for resumed steps)
|
|
112
|
+
|
|
113
|
+
## Re-running failed workflows
|
|
114
|
+
|
|
115
|
+
Time travel is particularly useful for debugging and recovering from failed workflow executions:
|
|
116
|
+
|
|
117
|
+
```typescript showLineNumbers copy
|
|
118
|
+
const workflow = mastra.getWorkflow("myWorkflow");
|
|
119
|
+
const run = await workflow.createRun();
|
|
120
|
+
|
|
121
|
+
// Initial run fails at step2
|
|
122
|
+
const failedResult = await run.start({
|
|
123
|
+
inputData: { value: 1 },
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
if (failedResult.status === "failed") {
|
|
127
|
+
// Re-run from step2 with corrected input
|
|
128
|
+
const recoveredResult = await run.timeTravel({
|
|
129
|
+
step: "step2",
|
|
130
|
+
inputData: { step1Result: 5 }, // Provide corrected input
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Time travel with suspended workflows
|
|
136
|
+
|
|
137
|
+
You can time travel to resume a suspended workflow from an earlier step:
|
|
138
|
+
|
|
139
|
+
```typescript showLineNumbers copy
|
|
140
|
+
const run = await workflow.createRun();
|
|
141
|
+
|
|
142
|
+
// Start workflow - suspends at promptAgent step
|
|
143
|
+
const initialResult = await run.start({
|
|
144
|
+
inputData: { input: "test" },
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
if (initialResult.status === "suspended") {
|
|
148
|
+
// Time travel back to an earlier step with resume data
|
|
149
|
+
const result = await run.timeTravel({
|
|
150
|
+
step: "getUserInput",
|
|
151
|
+
resumeData: {
|
|
152
|
+
userInput: "corrected input",
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Streaming time travel results
|
|
159
|
+
|
|
160
|
+
Use `timeTravelStream()` to receive streaming events during time travel execution:
|
|
161
|
+
|
|
162
|
+
```typescript showLineNumbers copy
|
|
163
|
+
const run = await workflow.createRun();
|
|
164
|
+
|
|
165
|
+
const output = run.timeTravelStream({
|
|
166
|
+
step: "step2",
|
|
167
|
+
inputData: { value: 10 },
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// Access the stream
|
|
171
|
+
for await (const event of output.fullStream) {
|
|
172
|
+
console.log(event.type, event.payload);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Get final result
|
|
176
|
+
const result = await output.result;
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## Time travel with initial state
|
|
180
|
+
|
|
181
|
+
You can provide initial state when time traveling to set workflow-level state:
|
|
182
|
+
|
|
183
|
+
```typescript showLineNumbers copy
|
|
184
|
+
const result = await run.timeTravel({
|
|
185
|
+
step: "step2",
|
|
186
|
+
inputData: { value: 10 },
|
|
187
|
+
initialState: {
|
|
188
|
+
counter: 5,
|
|
189
|
+
metadata: { source: "time-travel" },
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Error handling
|
|
195
|
+
|
|
196
|
+
Time travel throws errors in specific situations:
|
|
197
|
+
|
|
198
|
+
### Running workflow
|
|
199
|
+
|
|
200
|
+
You cannot time travel to a workflow that is currently running:
|
|
201
|
+
|
|
202
|
+
```typescript showLineNumbers copy
|
|
203
|
+
try {
|
|
204
|
+
await run.timeTravel({ step: "step2" });
|
|
205
|
+
} catch (error) {
|
|
206
|
+
// "This workflow run is still running, cannot time travel"
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Invalid step ID
|
|
211
|
+
|
|
212
|
+
Time travel throws if the target step doesn't exist in the workflow:
|
|
213
|
+
|
|
214
|
+
```typescript showLineNumbers copy
|
|
215
|
+
try {
|
|
216
|
+
await run.timeTravel({ step: "nonExistentStep" });
|
|
217
|
+
} catch (error) {
|
|
218
|
+
// "Time travel target step not found in execution graph: 'nonExistentStep'. Verify the step id/path."
|
|
219
|
+
}
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Invalid input data
|
|
223
|
+
|
|
224
|
+
When `validateInputs` is enabled, time travel validates the input data against the step's schema:
|
|
225
|
+
|
|
226
|
+
```typescript showLineNumbers copy
|
|
227
|
+
try {
|
|
228
|
+
await run.timeTravel({
|
|
229
|
+
step: "step2",
|
|
230
|
+
inputData: { invalidField: "value" },
|
|
231
|
+
});
|
|
232
|
+
} catch (error) {
|
|
233
|
+
// "Invalid inputData: \n- step1Result: Required"
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Nested workflows context
|
|
238
|
+
|
|
239
|
+
When time traveling into a nested workflow, you can provide context for both the parent and nested workflow steps:
|
|
240
|
+
|
|
241
|
+
```typescript showLineNumbers copy
|
|
242
|
+
const result = await run.timeTravel({
|
|
243
|
+
step: "nestedWorkflow.step3",
|
|
244
|
+
context: {
|
|
245
|
+
step1: {
|
|
246
|
+
status: "success",
|
|
247
|
+
payload: { value: 0 },
|
|
248
|
+
output: { step1Result: 2 },
|
|
249
|
+
startedAt: Date.now(),
|
|
250
|
+
endedAt: Date.now(),
|
|
251
|
+
},
|
|
252
|
+
nestedWorkflow: {
|
|
253
|
+
status: "running",
|
|
254
|
+
payload: { step1Result: 2 },
|
|
255
|
+
startedAt: Date.now(),
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
nestedStepsContext: {
|
|
259
|
+
nestedWorkflow: {
|
|
260
|
+
step2: {
|
|
261
|
+
status: "success",
|
|
262
|
+
payload: { step1Result: 2 },
|
|
263
|
+
output: { step2Result: 3 },
|
|
264
|
+
startedAt: Date.now(),
|
|
265
|
+
endedAt: Date.now(),
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
});
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
## Use cases
|
|
273
|
+
|
|
274
|
+
### Debugging failed steps
|
|
275
|
+
|
|
276
|
+
Re-run a failed step with the same or modified input to diagnose issues:
|
|
277
|
+
|
|
278
|
+
```typescript showLineNumbers copy
|
|
279
|
+
const result = await run.timeTravel({
|
|
280
|
+
step: failedStepId,
|
|
281
|
+
context: originalContext, // Use context from the failed run
|
|
282
|
+
});
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### Testing step logic on new workflow run
|
|
286
|
+
|
|
287
|
+
Test individual steps with specific inputs on a new workflow run, useful for testing a step logic without starting workflow execution from the beginning.
|
|
288
|
+
|
|
289
|
+
```typescript showLineNumbers copy
|
|
290
|
+
const result = await run.timeTravel({
|
|
291
|
+
step: "processData",
|
|
292
|
+
inputData: { testData: "specific test case" },
|
|
293
|
+
});
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
### Recovering from transient failures
|
|
297
|
+
|
|
298
|
+
Re-run steps that failed due to temporary issues (network errors, rate limits):
|
|
299
|
+
|
|
300
|
+
```typescript showLineNumbers copy
|
|
301
|
+
// After fixing the external service issue
|
|
302
|
+
const result = await run.timeTravel({
|
|
303
|
+
step: "callExternalApi",
|
|
304
|
+
inputData: savedInputData,
|
|
305
|
+
});
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
## Related
|
|
309
|
+
|
|
310
|
+
- [Snapshots](/docs/v1/workflows/snapshots)
|
|
311
|
+
- [Suspend & Resume](/docs/v1/workflows/suspend-and-resume)
|
|
312
|
+
- [Error Handling](/docs/v1/workflows/error-handling)
|
|
313
|
+
- [Control Flow](/docs/v1/workflows/control-flow)
|