@mastra/mcp-docs-server 0.0.0-commonjs-20250414101718

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.
Files changed (254) hide show
  1. package/.docs/organized/changelogs/%40mastra%2Fastra.md +302 -0
  2. package/.docs/organized/changelogs/%40mastra%2Fchroma.md +302 -0
  3. package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +161 -0
  4. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +302 -0
  5. package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +110 -0
  6. package/.docs/organized/changelogs/%40mastra%2Fcore.md +302 -0
  7. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +302 -0
  8. package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +302 -0
  9. package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +302 -0
  10. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +302 -0
  11. package/.docs/organized/changelogs/%40mastra%2Fevals.md +302 -0
  12. package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +302 -0
  13. package/.docs/organized/changelogs/%40mastra%2Fgithub.md +302 -0
  14. package/.docs/organized/changelogs/%40mastra%2Floggers.md +302 -0
  15. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +302 -0
  16. package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +26 -0
  17. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +302 -0
  18. package/.docs/organized/changelogs/%40mastra%2Fmem0.md +196 -0
  19. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +302 -0
  20. package/.docs/organized/changelogs/%40mastra%2Fpg.md +302 -0
  21. package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +302 -0
  22. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +302 -0
  23. package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +302 -0
  24. package/.docs/organized/changelogs/%40mastra%2Frag.md +302 -0
  25. package/.docs/organized/changelogs/%40mastra%2Fragie.md +302 -0
  26. package/.docs/organized/changelogs/%40mastra%2Fserver.md +302 -0
  27. package/.docs/organized/changelogs/%40mastra%2Fspeech-azure.md +302 -0
  28. package/.docs/organized/changelogs/%40mastra%2Fspeech-deepgram.md +302 -0
  29. package/.docs/organized/changelogs/%40mastra%2Fspeech-elevenlabs.md +302 -0
  30. package/.docs/organized/changelogs/%40mastra%2Fspeech-google.md +302 -0
  31. package/.docs/organized/changelogs/%40mastra%2Fspeech-ibm.md +302 -0
  32. package/.docs/organized/changelogs/%40mastra%2Fspeech-murf.md +302 -0
  33. package/.docs/organized/changelogs/%40mastra%2Fspeech-openai.md +302 -0
  34. package/.docs/organized/changelogs/%40mastra%2Fspeech-playai.md +302 -0
  35. package/.docs/organized/changelogs/%40mastra%2Fspeech-replicate.md +302 -0
  36. package/.docs/organized/changelogs/%40mastra%2Fspeech-speechify.md +302 -0
  37. package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +302 -0
  38. package/.docs/organized/changelogs/%40mastra%2Fupstash.md +302 -0
  39. package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +302 -0
  40. package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +250 -0
  41. package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +250 -0
  42. package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +302 -0
  43. package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +302 -0
  44. package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +302 -0
  45. package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +302 -0
  46. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +302 -0
  47. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +302 -0
  48. package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +302 -0
  49. package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +302 -0
  50. package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +302 -0
  51. package/.docs/organized/changelogs/create-mastra.md +302 -0
  52. package/.docs/organized/changelogs/mastra.md +302 -0
  53. package/.docs/organized/code-examples/agent-network.md +282 -0
  54. package/.docs/organized/code-examples/agent.md +388 -0
  55. package/.docs/organized/code-examples/ai-sdk-useChat.md +378 -0
  56. package/.docs/organized/code-examples/assistant-ui.md +37 -0
  57. package/.docs/organized/code-examples/bird-checker-with-express.md +235 -0
  58. package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +360 -0
  59. package/.docs/organized/code-examples/bird-checker-with-nextjs.md +250 -0
  60. package/.docs/organized/code-examples/client-side-tools.md +69 -0
  61. package/.docs/organized/code-examples/crypto-chatbot.md +96 -0
  62. package/.docs/organized/code-examples/fireworks-r1.md +159 -0
  63. package/.docs/organized/code-examples/mcp-registry-registry.md +63 -0
  64. package/.docs/organized/code-examples/memory-todo-agent.md +164 -0
  65. package/.docs/organized/code-examples/memory-with-context.md +167 -0
  66. package/.docs/organized/code-examples/memory-with-libsql.md +204 -0
  67. package/.docs/organized/code-examples/memory-with-mem0.md +121 -0
  68. package/.docs/organized/code-examples/memory-with-pg.md +224 -0
  69. package/.docs/organized/code-examples/memory-with-upstash.md +268 -0
  70. package/.docs/organized/code-examples/quick-start.md +129 -0
  71. package/.docs/organized/code-examples/stock-price-tool.md +124 -0
  72. package/.docs/organized/code-examples/weather-agent.md +353 -0
  73. package/.docs/organized/code-examples/workflow-ai-recruiter.md +159 -0
  74. package/.docs/organized/code-examples/workflow-with-inline-steps.md +111 -0
  75. package/.docs/organized/code-examples/workflow-with-memory.md +393 -0
  76. package/.docs/organized/code-examples/workflow-with-separate-steps.md +131 -0
  77. package/.docs/raw/agents/adding-tools.mdx +317 -0
  78. package/.docs/raw/agents/adding-voice.mdx +175 -0
  79. package/.docs/raw/agents/agent-memory.mdx +62 -0
  80. package/.docs/raw/agents/mcp-guide.mdx +215 -0
  81. package/.docs/raw/agents/overview.mdx +303 -0
  82. package/.docs/raw/community/discord.mdx +12 -0
  83. package/.docs/raw/community/licensing.mdx +63 -0
  84. package/.docs/raw/deployment/client.mdx +120 -0
  85. package/.docs/raw/deployment/deployment.mdx +127 -0
  86. package/.docs/raw/deployment/server.mdx +282 -0
  87. package/.docs/raw/evals/custom-eval.mdx +22 -0
  88. package/.docs/raw/evals/overview.mdx +95 -0
  89. package/.docs/raw/evals/running-in-ci.mdx +81 -0
  90. package/.docs/raw/evals/textual-evals.mdx +54 -0
  91. package/.docs/raw/faq/index.mdx +63 -0
  92. package/.docs/raw/frameworks/ai-sdk.mdx +296 -0
  93. package/.docs/raw/frameworks/next-js.mdx +238 -0
  94. package/.docs/raw/getting-started/installation.mdx +442 -0
  95. package/.docs/raw/getting-started/mcp-docs-server.mdx +141 -0
  96. package/.docs/raw/getting-started/project-structure.mdx +80 -0
  97. package/.docs/raw/index.mdx +22 -0
  98. package/.docs/raw/integrations/index.mdx +213 -0
  99. package/.docs/raw/local-dev/add-to-existing-project.mdx +48 -0
  100. package/.docs/raw/local-dev/creating-a-new-project.mdx +54 -0
  101. package/.docs/raw/local-dev/mastra-dev.mdx +108 -0
  102. package/.docs/raw/memory/memory-processors.mdx +131 -0
  103. package/.docs/raw/memory/overview.mdx +119 -0
  104. package/.docs/raw/memory/semantic-recall.mdx +122 -0
  105. package/.docs/raw/memory/working-memory.mdx +87 -0
  106. package/.docs/raw/observability/logging.mdx +38 -0
  107. package/.docs/raw/observability/nextjs-tracing.mdx +108 -0
  108. package/.docs/raw/observability/tracing.mdx +115 -0
  109. package/.docs/raw/rag/chunking-and-embedding.mdx +156 -0
  110. package/.docs/raw/rag/overview.mdx +85 -0
  111. package/.docs/raw/rag/retrieval.mdx +365 -0
  112. package/.docs/raw/rag/vector-databases.mdx +340 -0
  113. package/.docs/raw/reference/agents/createTool.mdx +229 -0
  114. package/.docs/raw/reference/agents/generate.mdx +334 -0
  115. package/.docs/raw/reference/agents/getAgent.mdx +54 -0
  116. package/.docs/raw/reference/agents/stream.mdx +369 -0
  117. package/.docs/raw/reference/cli/build.mdx +55 -0
  118. package/.docs/raw/reference/cli/dev.mdx +134 -0
  119. package/.docs/raw/reference/cli/init.mdx +43 -0
  120. package/.docs/raw/reference/client-js/agents.mdx +107 -0
  121. package/.docs/raw/reference/client-js/error-handling.mdx +38 -0
  122. package/.docs/raw/reference/client-js/logs.mdx +24 -0
  123. package/.docs/raw/reference/client-js/memory.mdx +97 -0
  124. package/.docs/raw/reference/client-js/telemetry.mdx +20 -0
  125. package/.docs/raw/reference/client-js/tools.mdx +44 -0
  126. package/.docs/raw/reference/client-js/vectors.mdx +79 -0
  127. package/.docs/raw/reference/client-js/workflows.mdx +136 -0
  128. package/.docs/raw/reference/core/mastra-class.mdx +232 -0
  129. package/.docs/raw/reference/deployer/cloudflare.mdx +207 -0
  130. package/.docs/raw/reference/deployer/deployer.mdx +159 -0
  131. package/.docs/raw/reference/deployer/netlify.mdx +109 -0
  132. package/.docs/raw/reference/deployer/vercel.mdx +117 -0
  133. package/.docs/raw/reference/evals/answer-relevancy.mdx +186 -0
  134. package/.docs/raw/reference/evals/bias.mdx +186 -0
  135. package/.docs/raw/reference/evals/completeness.mdx +174 -0
  136. package/.docs/raw/reference/evals/content-similarity.mdx +183 -0
  137. package/.docs/raw/reference/evals/context-position.mdx +190 -0
  138. package/.docs/raw/reference/evals/context-precision.mdx +189 -0
  139. package/.docs/raw/reference/evals/context-relevancy.mdx +188 -0
  140. package/.docs/raw/reference/evals/contextual-recall.mdx +191 -0
  141. package/.docs/raw/reference/evals/faithfulness.mdx +193 -0
  142. package/.docs/raw/reference/evals/hallucination.mdx +219 -0
  143. package/.docs/raw/reference/evals/keyword-coverage.mdx +176 -0
  144. package/.docs/raw/reference/evals/prompt-alignment.mdx +238 -0
  145. package/.docs/raw/reference/evals/summarization.mdx +205 -0
  146. package/.docs/raw/reference/evals/textual-difference.mdx +161 -0
  147. package/.docs/raw/reference/evals/tone-consistency.mdx +181 -0
  148. package/.docs/raw/reference/evals/toxicity.mdx +165 -0
  149. package/.docs/raw/reference/index.mdx +12 -0
  150. package/.docs/raw/reference/memory/Memory.mdx +212 -0
  151. package/.docs/raw/reference/memory/createThread.mdx +95 -0
  152. package/.docs/raw/reference/memory/getThreadById.mdx +46 -0
  153. package/.docs/raw/reference/memory/getThreadsByResourceId.mdx +48 -0
  154. package/.docs/raw/reference/memory/query.mdx +167 -0
  155. package/.docs/raw/reference/networks/agent-network.mdx +159 -0
  156. package/.docs/raw/reference/observability/create-logger.mdx +106 -0
  157. package/.docs/raw/reference/observability/logger.mdx +55 -0
  158. package/.docs/raw/reference/observability/otel-config.mdx +120 -0
  159. package/.docs/raw/reference/observability/providers/braintrust.mdx +40 -0
  160. package/.docs/raw/reference/observability/providers/dash0.mdx +40 -0
  161. package/.docs/raw/reference/observability/providers/index.mdx +16 -0
  162. package/.docs/raw/reference/observability/providers/laminar.mdx +41 -0
  163. package/.docs/raw/reference/observability/providers/langfuse.mdx +51 -0
  164. package/.docs/raw/reference/observability/providers/langsmith.mdx +48 -0
  165. package/.docs/raw/reference/observability/providers/langwatch.mdx +45 -0
  166. package/.docs/raw/reference/observability/providers/new-relic.mdx +40 -0
  167. package/.docs/raw/reference/observability/providers/signoz.mdx +40 -0
  168. package/.docs/raw/reference/observability/providers/traceloop.mdx +40 -0
  169. package/.docs/raw/reference/rag/astra.mdx +258 -0
  170. package/.docs/raw/reference/rag/chroma.mdx +281 -0
  171. package/.docs/raw/reference/rag/chunk.mdx +235 -0
  172. package/.docs/raw/reference/rag/document.mdx +127 -0
  173. package/.docs/raw/reference/rag/embeddings.mdx +160 -0
  174. package/.docs/raw/reference/rag/extract-params.mdx +226 -0
  175. package/.docs/raw/reference/rag/graph-rag.mdx +182 -0
  176. package/.docs/raw/reference/rag/libsql.mdx +357 -0
  177. package/.docs/raw/reference/rag/metadata-filters.mdx +298 -0
  178. package/.docs/raw/reference/rag/pg.mdx +477 -0
  179. package/.docs/raw/reference/rag/pinecone.mdx +281 -0
  180. package/.docs/raw/reference/rag/qdrant.mdx +236 -0
  181. package/.docs/raw/reference/rag/rerank.mdx +212 -0
  182. package/.docs/raw/reference/rag/turbopuffer.mdx +249 -0
  183. package/.docs/raw/reference/rag/upstash.mdx +247 -0
  184. package/.docs/raw/reference/rag/vectorize.mdx +298 -0
  185. package/.docs/raw/reference/storage/libsql.mdx +74 -0
  186. package/.docs/raw/reference/storage/postgresql.mdx +48 -0
  187. package/.docs/raw/reference/storage/upstash.mdx +86 -0
  188. package/.docs/raw/reference/tools/client.mdx +207 -0
  189. package/.docs/raw/reference/tools/document-chunker-tool.mdx +141 -0
  190. package/.docs/raw/reference/tools/graph-rag-tool.mdx +154 -0
  191. package/.docs/raw/reference/tools/mcp-configuration.mdx +206 -0
  192. package/.docs/raw/reference/tools/vector-query-tool.mdx +212 -0
  193. package/.docs/raw/reference/voice/composite-voice.mdx +140 -0
  194. package/.docs/raw/reference/voice/deepgram.mdx +164 -0
  195. package/.docs/raw/reference/voice/elevenlabs.mdx +216 -0
  196. package/.docs/raw/reference/voice/google.mdx +198 -0
  197. package/.docs/raw/reference/voice/mastra-voice.mdx +394 -0
  198. package/.docs/raw/reference/voice/murf.mdx +251 -0
  199. package/.docs/raw/reference/voice/openai-realtime.mdx +431 -0
  200. package/.docs/raw/reference/voice/openai.mdx +168 -0
  201. package/.docs/raw/reference/voice/playai.mdx +159 -0
  202. package/.docs/raw/reference/voice/sarvam.mdx +260 -0
  203. package/.docs/raw/reference/voice/speechify.mdx +145 -0
  204. package/.docs/raw/reference/voice/voice.answer.mdx +122 -0
  205. package/.docs/raw/reference/voice/voice.connect.mdx +124 -0
  206. package/.docs/raw/reference/voice/voice.listen.mdx +195 -0
  207. package/.docs/raw/reference/voice/voice.on.mdx +189 -0
  208. package/.docs/raw/reference/voice/voice.send.mdx +118 -0
  209. package/.docs/raw/reference/voice/voice.speak.mdx +203 -0
  210. package/.docs/raw/reference/workflows/after.mdx +88 -0
  211. package/.docs/raw/reference/workflows/afterEvent.mdx +76 -0
  212. package/.docs/raw/reference/workflows/commit.mdx +37 -0
  213. package/.docs/raw/reference/workflows/createRun.mdx +77 -0
  214. package/.docs/raw/reference/workflows/else.mdx +72 -0
  215. package/.docs/raw/reference/workflows/events.mdx +305 -0
  216. package/.docs/raw/reference/workflows/execute.mdx +110 -0
  217. package/.docs/raw/reference/workflows/if.mdx +107 -0
  218. package/.docs/raw/reference/workflows/resume.mdx +155 -0
  219. package/.docs/raw/reference/workflows/resumeWithEvent.mdx +133 -0
  220. package/.docs/raw/reference/workflows/snapshots.mdx +207 -0
  221. package/.docs/raw/reference/workflows/start.mdx +84 -0
  222. package/.docs/raw/reference/workflows/step-class.mdx +100 -0
  223. package/.docs/raw/reference/workflows/step-condition.mdx +134 -0
  224. package/.docs/raw/reference/workflows/step-function.mdx +92 -0
  225. package/.docs/raw/reference/workflows/step-options.mdx +69 -0
  226. package/.docs/raw/reference/workflows/step-retries.mdx +203 -0
  227. package/.docs/raw/reference/workflows/suspend.mdx +70 -0
  228. package/.docs/raw/reference/workflows/then.mdx +74 -0
  229. package/.docs/raw/reference/workflows/until.mdx +165 -0
  230. package/.docs/raw/reference/workflows/watch.mdx +118 -0
  231. package/.docs/raw/reference/workflows/while.mdx +168 -0
  232. package/.docs/raw/reference/workflows/workflow.mdx +233 -0
  233. package/.docs/raw/storage/overview.mdx +378 -0
  234. package/.docs/raw/voice/overview.mdx +135 -0
  235. package/.docs/raw/voice/speech-to-text.mdx +45 -0
  236. package/.docs/raw/voice/text-to-speech.mdx +52 -0
  237. package/.docs/raw/voice/voice-to-voice.mdx +310 -0
  238. package/.docs/raw/workflows/control-flow.mdx +778 -0
  239. package/.docs/raw/workflows/dynamic-workflows.mdx +236 -0
  240. package/.docs/raw/workflows/error-handling.mdx +183 -0
  241. package/.docs/raw/workflows/nested-workflows.mdx +352 -0
  242. package/.docs/raw/workflows/overview.mdx +203 -0
  243. package/.docs/raw/workflows/steps.mdx +108 -0
  244. package/.docs/raw/workflows/suspend-and-resume.mdx +404 -0
  245. package/.docs/raw/workflows/variables.mdx +313 -0
  246. package/LICENSE.md +46 -0
  247. package/README.md +129 -0
  248. package/dist/_tsup-dts-rollup.d.ts +149 -0
  249. package/dist/chunk-QWYMT5LP.js +194 -0
  250. package/dist/prepare-docs/prepare.d.ts +1 -0
  251. package/dist/prepare-docs/prepare.js +1 -0
  252. package/dist/stdio.d.ts +1 -0
  253. package/dist/stdio.js +518 -0
  254. package/package.json +60 -0
@@ -0,0 +1,133 @@
1
+ ---
2
+ title: ".resumeWithEvent() Method | Mastra Docs"
3
+ description: "Reference for the resumeWithEvent method that resumes suspended workflows using event data."
4
+ ---
5
+
6
+ # resumeWithEvent()
7
+
8
+ The `resumeWithEvent()` method resumes workflow execution by providing data for a specific event that the workflow is waiting for.
9
+
10
+ ## Syntax
11
+
12
+ ```typescript
13
+ const run = workflow.createRun();
14
+
15
+ // After the workflow has started and suspended at an event step
16
+ await run.resumeWithEvent(eventName: string, data: any): Promise<WorkflowRunResult>
17
+ ```
18
+
19
+ ## Parameters
20
+
21
+ | Parameter | Type | Description |
22
+ | --------- | ------ | ------------------------------------------------------------------------------------------------------- |
23
+ | eventName | string | The name of the event to trigger. Must match an event defined in the workflow's `events` configuration. |
24
+ | data | any | The event data to provide. Must conform to the schema defined for that event. |
25
+
26
+ ## Return Value
27
+
28
+ Returns a Promise that resolves to a `WorkflowRunResult` object, containing:
29
+
30
+ - `results`: The result status and output of each step in the workflow
31
+ - `activePaths`: A map of active workflow paths and their states
32
+ - `value`: The current state value of the workflow
33
+ - Other workflow execution metadata
34
+
35
+ ## Description
36
+
37
+ The `resumeWithEvent()` method is used to resume a workflow that has been suspended at an event step created by the `afterEvent()` method. When called, this method:
38
+
39
+ 1. Validates the provided event data against the schema defined for that event
40
+ 2. Loads the workflow snapshot from storage
41
+ 3. Updates the context with the event data in the `resumedEvent` field
42
+ 4. Resumes execution from the event step
43
+ 5. Continues workflow execution with the subsequent steps
44
+
45
+ This method is part of Mastra's event-driven workflow capabilities, allowing you to create workflows that can respond to external events or user interactions.
46
+
47
+ ## Usage Notes
48
+
49
+ - The workflow must be in a suspended state, specifically at the event step created by `afterEvent(eventName)`
50
+ - The event data must conform to the schema defined for that event in the workflow configuration
51
+ - The workflow will continue execution from the point it was suspended
52
+ - If the workflow is not suspended or is suspended at a different step, this method may throw an error
53
+ - The event data is made available to subsequent steps via `context.inputData.resumedEvent`
54
+
55
+ ## Examples
56
+
57
+ ### Basic Usage
58
+
59
+ ```typescript
60
+ // Define and start a workflow
61
+ const workflow = mastra.getWorkflow("approval-workflow");
62
+ const run = workflow.createRun();
63
+
64
+ // Start the workflow
65
+ await run.start({ triggerData: { requestId: "req-123" } });
66
+
67
+ // Later, when the approval event occurs:
68
+ const result = await run.resumeWithEvent("approval", {
69
+ approved: true,
70
+ approverName: "John Doe",
71
+ comment: "Looks good to me!",
72
+ });
73
+
74
+ console.log(result.results);
75
+ ```
76
+
77
+ ### With Error Handling
78
+
79
+ ```typescript
80
+ try {
81
+ const result = await run.resumeWithEvent("paymentReceived", {
82
+ amount: 100.5,
83
+ transactionId: "tx-456",
84
+ paymentMethod: "credit-card",
85
+ });
86
+
87
+ console.log("Workflow resumed successfully:", result.results);
88
+ } catch (error) {
89
+ console.error("Failed to resume workflow with event:", error);
90
+ // Handle error - could be invalid event data, workflow not suspended, etc.
91
+ }
92
+ ```
93
+
94
+ ### Monitoring and Auto-Resuming
95
+
96
+ ```typescript
97
+ // Start a workflow
98
+ const { start, watch, resumeWithEvent } = workflow.createRun();
99
+
100
+ // Watch for suspended event steps
101
+ watch(async ({ activePaths }) => {
102
+ const isApprovalEventSuspended =
103
+ activePaths.get("__approval_event")?.status === "suspended";
104
+ // Check if suspended at the approval event step
105
+ if (isApprovalEventSuspended) {
106
+ console.log("Workflow waiting for approval");
107
+
108
+ // In a real scenario, you would wait for the actual event
109
+ // Here we're simulating with a timeout
110
+ setTimeout(async () => {
111
+ try {
112
+ await resumeWithEvent("approval", {
113
+ approved: true,
114
+ approverName: "Auto Approver",
115
+ });
116
+ } catch (error) {
117
+ console.error("Failed to auto-resume workflow:", error);
118
+ }
119
+ }, 5000); // Wait 5 seconds before auto-approving
120
+ }
121
+ });
122
+
123
+ // Start the workflow
124
+ await start({ triggerData: { requestId: "auto-123" } });
125
+ ```
126
+
127
+ ## Related
128
+
129
+ - [Event-Driven Workflows](./events.mdx)
130
+ - [afterEvent()](./afterEvent.mdx)
131
+ - [Suspend and Resume](../../workflows/suspend-and-resume.mdx)
132
+ - [resume()](./resume.mdx)
133
+ - [watch()](./watch.mdx)
@@ -0,0 +1,207 @@
1
+ ---
2
+ title: "Reference: Snapshots | Workflow State Persistence | Mastra Docs"
3
+ description: "Technical reference on snapshots in Mastra - the serialized workflow state that enables suspend and resume functionality"
4
+ ---
5
+
6
+ # Snapshots
7
+
8
+ In Mastra, a snapshot is a serializable representation of a workflow's complete execution state at a specific point in time. Snapshots capture all the information needed to resume a workflow from exactly where it left off, including:
9
+
10
+ - The current state of each step in the workflow
11
+ - The outputs of completed steps
12
+ - The execution path taken through the workflow
13
+ - Any suspended steps and their metadata
14
+ - The remaining retry attempts for each step
15
+ - Additional contextual data needed to resume execution
16
+
17
+ Snapshots are automatically created and managed by Mastra whenever a workflow is suspended, and are persisted to the configured storage system.
18
+
19
+ ## The Role of Snapshots in Suspend and Resume
20
+
21
+ Snapshots are the key mechanism enabling Mastra's suspend and resume capabilities. When a workflow step calls `await suspend()`:
22
+
23
+ 1. The workflow execution is paused at that exact point
24
+ 2. The current state of the workflow is captured as a snapshot
25
+ 3. The snapshot is persisted to storage
26
+ 4. The workflow step is marked as "suspended" with a status of `'suspended'`
27
+ 5. Later, when `resume()` is called on the suspended step, the snapshot is retrieved
28
+ 6. The workflow execution resumes from exactly where it left off
29
+
30
+ This mechanism provides a powerful way to implement human-in-the-loop workflows, handle rate limiting, wait for external resources, and implement complex branching workflows that may need to pause for extended periods.
31
+
32
+ ## Snapshot Anatomy
33
+
34
+ A Mastra workflow snapshot consists of several key components:
35
+
36
+ ```typescript
37
+ export interface WorkflowRunState {
38
+ // Core state info
39
+ value: Record<string, string>; // Current state machine value
40
+ context: {
41
+ // Workflow context
42
+ steps: Record<
43
+ string,
44
+ {
45
+ // Step execution results
46
+ status: "success" | "failed" | "suspended" | "waiting" | "skipped";
47
+ payload?: any; // Step-specific data
48
+ error?: string; // Error info if failed
49
+ }
50
+ >;
51
+ triggerData: Record<string, any>; // Initial trigger data
52
+ attempts: Record<string, number>; // Remaining retry attempts
53
+ inputData: Record<string, any>; // Initial input data
54
+ };
55
+
56
+ activePaths: Array<{
57
+ // Currently active execution paths
58
+ stepPath: string[];
59
+ stepId: string;
60
+ status: string;
61
+ }>;
62
+
63
+ // Metadata
64
+ runId: string; // Unique run identifier
65
+ timestamp: number; // Time snapshot was created
66
+
67
+ // For nested workflows and suspended steps
68
+ childStates?: Record<string, WorkflowRunState>; // Child workflow states
69
+ suspendedSteps?: Record<string, string>; // Mapping of suspended steps
70
+ }
71
+ ```
72
+
73
+ ## How Snapshots Are Saved and Retrieved
74
+
75
+ Mastra persists snapshots to the configured storage system. By default, snapshots are saved to a LibSQL database, but can be configured to use other storage providers like Upstash.
76
+ The snapshots are stored in the `workflow_snapshots` table and identified uniquely by the `run_id` for the associated run when using libsql.
77
+ Utilizing a persistence layer allows for the snapshots to be persisted across workflow runs, allowing for advanced human-in-the-loop functionality.
78
+
79
+ Read more about [libsql storage](../storage/libsql.mdx) and [upstash storage](../storage/upstash.mdx) here.
80
+
81
+ ### Saving Snapshots
82
+
83
+ When a workflow is suspended, Mastra automatically persists the workflow snapshot with these steps:
84
+
85
+ 1. The `suspend()` function in a step execution triggers the snapshot process
86
+ 2. The `WorkflowInstance.suspend()` method records the suspended machine
87
+ 3. `persistWorkflowSnapshot()` is called to save the current state
88
+ 4. The snapshot is serialized and stored in the configured database in the `workflow_snapshots` table
89
+ 5. The storage record includes the workflow name, run ID, and the serialized snapshot
90
+
91
+ ### Retrieving Snapshots
92
+
93
+ When a workflow is resumed, Mastra retrieves the persisted snapshot with these steps:
94
+
95
+ 1. The `resume()` method is called with a specific step ID
96
+ 2. The snapshot is loaded from storage using `loadWorkflowSnapshot()`
97
+ 3. The snapshot is parsed and prepared for resumption
98
+ 4. The workflow execution is recreated with the snapshot state
99
+ 5. The suspended step is resumed, and execution continues
100
+
101
+ ## Storage Options for Snapshots
102
+
103
+ Mastra provides multiple storage options for persisting snapshots.
104
+
105
+ A `storage` instance is configured on the `Mastra` class, and is used to setup a snapshot persistence layer for all workflows registered on the `Mastra` instance.
106
+ This means that storage is shared across all workflows registered with the same `Mastra` instance.
107
+
108
+ ### LibSQL (Default)
109
+
110
+ The default storage option is LibSQL, a SQLite-compatible database:
111
+
112
+ ```typescript
113
+ import { Mastra } from "@mastra/core/mastra";
114
+ import { DefaultStorage } from "@mastra/core/storage/libsql";
115
+
116
+ const mastra = new Mastra({
117
+ storage: new DefaultStorage({
118
+ config: {
119
+ url: "file:storage.db", // Local file-based database
120
+ // For production:
121
+ // url: process.env.DATABASE_URL,
122
+ // authToken: process.env.DATABASE_AUTH_TOKEN,
123
+ },
124
+ }),
125
+ workflows: {
126
+ weatherWorkflow,
127
+ travelWorkflow,
128
+ },
129
+ });
130
+ ```
131
+
132
+ ### Upstash (Redis-Compatible)
133
+
134
+ For serverless environments:
135
+
136
+ ```typescript
137
+ import { Mastra } from "@mastra/core/mastra";
138
+ import { UpstashStore } from "@mastra/upstash";
139
+
140
+ const mastra = new Mastra({
141
+ storage: new UpstashStore({
142
+ url: process.env.UPSTASH_URL,
143
+ token: process.env.UPSTASH_TOKEN,
144
+ }),
145
+ workflows: {
146
+ weatherWorkflow,
147
+ travelWorkflow,
148
+ },
149
+ });
150
+ ```
151
+
152
+ ## Best Practices for Working with Snapshots
153
+
154
+ 1. **Ensure Serializability**: Any data that needs to be included in the snapshot must be serializable (convertible to JSON).
155
+
156
+ 2. **Minimize Snapshot Size**: Avoid storing large data objects directly in the workflow context. Instead, store references to them (like IDs) and retrieve the data when needed.
157
+
158
+ 3. **Handle Resume Context Carefully**: When resuming a workflow, carefully consider what context to provide. This will be merged with the existing snapshot data.
159
+
160
+ 4. **Set Up Proper Monitoring**: Implement monitoring for suspended workflows, especially long-running ones, to ensure they are properly resumed.
161
+
162
+ 5. **Consider Storage Scaling**: For applications with many suspended workflows, ensure your storage solution is appropriately scaled.
163
+
164
+ ## Advanced Snapshot Patterns
165
+
166
+ ### Custom Snapshot Metadata
167
+
168
+ When suspending a workflow, you can include custom metadata that can help when resuming:
169
+
170
+ ```typescript
171
+ await suspend({
172
+ reason: "Waiting for customer approval",
173
+ requiredApprovers: ["manager", "finance"],
174
+ requestedBy: currentUser,
175
+ urgency: "high",
176
+ expires: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000),
177
+ });
178
+ ```
179
+
180
+ This metadata is stored with the snapshot and available when resuming.
181
+
182
+ ### Conditional Resumption
183
+
184
+ You can implement conditional logic based on the suspend payload when resuming:
185
+
186
+ ```typescript
187
+ run.watch(async ({ activePaths }) => {
188
+ const isApprovalStepSuspended =
189
+ activePaths.get("approval")?.status === "suspended";
190
+ if (isApprovalStepSuspended) {
191
+ const payload = activePaths.get("approval")?.suspendPayload;
192
+ if (payload.urgency === "high" && currentUser.role === "manager") {
193
+ await resume({
194
+ stepId: "approval",
195
+ context: { approved: true, approver: currentUser.id },
196
+ });
197
+ }
198
+ }
199
+ });
200
+ ```
201
+
202
+ ## Related
203
+
204
+ - [Suspend Function Reference](./suspend.mdx)
205
+ - [Resume Function Reference](./resume.mdx)
206
+ - [Watch Function Reference](./watch.mdx)
207
+ - [Suspend and Resume Guide](../../workflows/suspend-and-resume.mdx)
@@ -0,0 +1,84 @@
1
+ ---
2
+ title: "Reference: start() | Running Workflows | Mastra Docs"
3
+ description: "Documentation for the `start()` method in workflows, which begins execution of a workflow run."
4
+ ---
5
+
6
+ # start()
7
+
8
+ The start function begins execution of a workflow run. It processes all steps in the defined workflow order, handling parallel execution, branching logic, and step dependencies.
9
+
10
+ ## Usage
11
+
12
+ ```typescript copy showLineNumbers
13
+ const { runId, start } = workflow.createRun();
14
+ const result = await start({
15
+ triggerData: { inputValue: 42 }
16
+ });
17
+ ```
18
+
19
+ ## Parameters
20
+
21
+ <PropertiesTable
22
+ content={[
23
+ {
24
+ name: "config",
25
+ type: "object",
26
+ description: "Configuration for starting the workflow run",
27
+ isOptional: true
28
+ }
29
+ ]}
30
+ />
31
+
32
+ ### config
33
+
34
+ <PropertiesTable
35
+ content={[
36
+ {
37
+ name: "triggerData",
38
+ type: "Record<string, any>",
39
+ description: "Initial data that matches the workflow's triggerSchema",
40
+ isOptional: false
41
+ }
42
+ ]}
43
+ />
44
+
45
+ ## Returns
46
+
47
+ <PropertiesTable
48
+ content={[
49
+ {
50
+ name: "results",
51
+ type: "Record<string, any>",
52
+ description: "Combined output from all completed workflow steps"
53
+ },
54
+ {
55
+ name: "status",
56
+ type: "'completed' | 'error' | 'suspended'",
57
+ description: "Final status of the workflow run"
58
+ }
59
+ ]}
60
+ />
61
+
62
+ ## Error Handling
63
+
64
+ The start function may throw several types of validation errors:
65
+
66
+ ```typescript copy showLineNumbers
67
+ try {
68
+ const result = await start({ triggerData: data });
69
+ } catch (error) {
70
+ if (error instanceof ValidationError) {
71
+ console.log(error.type); // 'circular_dependency' | 'no_terminal_path' | 'unreachable_step'
72
+ console.log(error.details);
73
+ }
74
+ }
75
+ ```
76
+
77
+ ## Related
78
+
79
+ - [Example: Creating a Workflow](../../../examples/workflows/creating-a-workflow.mdx)
80
+ - [Example: Suspend and Resume](../../../examples/workflows/suspend-and-resume.mdx)
81
+ - [createRun Reference](./createRun.mdx)
82
+ - [Workflow Class Reference](./workflow.mdx)
83
+ - [Step Class Reference](./step-class.mdx)
84
+ ```
@@ -0,0 +1,100 @@
1
+ ---
2
+ title: "Reference: Step | Building Workflows | Mastra Docs"
3
+ description: Documentation for the Step class, which defines individual units of work within a workflow.
4
+ ---
5
+ # Step
6
+
7
+ The Step class defines individual units of work within a workflow, encapsulating execution logic, data validation, and input/output handling.
8
+
9
+ ## Usage
10
+
11
+ ```typescript
12
+ const processOrder = new Step({
13
+ id: "processOrder",
14
+ inputSchema: z.object({
15
+ orderId: z.string(),
16
+ userId: z.string()
17
+ }),
18
+ outputSchema: z.object({
19
+ status: z.string(),
20
+ orderId: z.string()
21
+ }),
22
+ execute: async ({ context, runId }) => {
23
+ return {
24
+ status: "processed",
25
+ orderId: context.orderId
26
+ };
27
+ }
28
+ });
29
+ ```
30
+
31
+ ## Constructor Parameters
32
+
33
+ <PropertiesTable
34
+ content={[
35
+ {
36
+ name: "id",
37
+ type: "string",
38
+ description: "Unique identifier for the step",
39
+ required: true
40
+ },
41
+ {
42
+ name: "inputSchema",
43
+ type: "z.ZodSchema",
44
+ description: "Zod schema to validate input data before execution",
45
+ required: false
46
+ },
47
+ {
48
+ name: "outputSchema",
49
+ type: "z.ZodSchema",
50
+ description: "Zod schema to validate step output data",
51
+ required: false
52
+ },
53
+ {
54
+ name: "payload",
55
+ type: "Record<string, any>",
56
+ description: "Static data to be merged with variables",
57
+ required: false
58
+ },
59
+ {
60
+ name: "execute",
61
+ type: "(params: ExecuteParams) => Promise<any>",
62
+ description: "Async function containing step logic",
63
+ required: true
64
+ }
65
+ ]}
66
+ />
67
+
68
+ ### ExecuteParams
69
+
70
+ <PropertiesTable
71
+ content={[
72
+ {
73
+ name: "context",
74
+ type: "StepContext",
75
+ description: "Access to workflow context and step results"
76
+ },
77
+ {
78
+ name: "runId",
79
+ type: "string",
80
+ description: "Unique identifier for current workflow run"
81
+ },
82
+ {
83
+ name: "suspend",
84
+ type: "() => Promise<void>",
85
+ description: "Function to suspend step execution"
86
+ },
87
+ {
88
+ name: "mastra",
89
+ type: "Mastra",
90
+ description: "Access to Mastra instance"
91
+ }
92
+ ]}
93
+ />
94
+
95
+ ## Related
96
+
97
+ - [Workflow Reference](./workflow.mdx)
98
+ - [Step Configuration Guide](../../workflows/steps.mdx)
99
+ - [Control Flow Guide](../../workflows/control-flow.mdx)
100
+ ```
@@ -0,0 +1,134 @@
1
+ ---
2
+ title: "Reference: StepCondition | Building Workflows | Mastra"
3
+ description: Documentation for the step condition class in workflows, which determines whether a step should execute based on the output of previous steps or trigger data.
4
+ ---
5
+
6
+ # StepCondition
7
+
8
+ Conditions determine whether a step should execute based on the output of previous steps or trigger data.
9
+
10
+ ## Usage
11
+
12
+ There are three ways to specify conditions: function, query object, and simple path comparison.
13
+
14
+ ### 1. Function Condition
15
+ ```typescript copy showLineNumbers
16
+ workflow.step(processOrder, {
17
+ when: async ({ context }) => {
18
+ const auth = context?.getStepResult<{status: string}>("auth");
19
+ return auth?.status === "authenticated";
20
+ }
21
+ });
22
+ ```
23
+
24
+ ### 2. Query Object
25
+ ```typescript copy showLineNumbers
26
+ workflow.step(processOrder, {
27
+ when: {
28
+ ref: { step: 'auth', path: 'status' },
29
+ query: { $eq: 'authenticated' }
30
+ }
31
+ });
32
+ ```
33
+
34
+ ### 3. Simple Path Comparison
35
+ ```typescript copy showLineNumbers
36
+ workflow.step(processOrder, {
37
+ when: {
38
+ "auth.status": "authenticated"
39
+ }
40
+ });
41
+ ```
42
+
43
+ Based on the type of condition, the workflow runner will try to match the condition to one of these types.
44
+
45
+ 1. Simple Path Condition (when there's a dot in the key)
46
+ 2. Base/Query Condition (when there's a 'ref' property)
47
+ 3. Function Condition (when it's an async function)
48
+
49
+ ## StepCondition
50
+
51
+ <PropertiesTable
52
+ content={[
53
+ {
54
+ name: "ref",
55
+ type: "{ stepId: string | 'trigger'; path: string }",
56
+ description: "Reference to step output value. stepId can be a step ID or 'trigger' for initial data. path specifies location of value in step result",
57
+ isOptional: false
58
+ },
59
+ {
60
+ name: "query",
61
+ type: "Query<any>",
62
+ description: "MongoDB-style query using sift operators ($eq, $gt, etc)",
63
+ isOptional: false
64
+ }
65
+ ]}
66
+ />
67
+
68
+ ## Query
69
+
70
+ The Query object provides MongoDB-style query operators for comparing values from previous steps or trigger data. It supports basic comparison operators like `$eq`, `$gt`, `$lt` as well as array operators like `$in` and `$nin`, and can be combined with and/or operators for complex conditions.
71
+
72
+ This query syntax allows for readable conditional logic for determining whether a step should execute.
73
+
74
+ <PropertiesTable
75
+ content={[
76
+ {
77
+ name: "$eq",
78
+ type: "any",
79
+ description: "Equal to value"
80
+ },
81
+ {
82
+ name: "$ne",
83
+ type: "any",
84
+ description: "Not equal to value"
85
+ },
86
+ {
87
+ name: "$gt",
88
+ type: "number",
89
+ description: "Greater than value"
90
+ },
91
+ {
92
+ name: "$gte",
93
+ type: "number",
94
+ description: "Greater than or equal to value"
95
+ },
96
+ {
97
+ name: "$lt",
98
+ type: "number",
99
+ description: "Less than value"
100
+ },
101
+ {
102
+ name: "$lte",
103
+ type: "number",
104
+ description: "Less than or equal to value"
105
+ },
106
+ {
107
+ name: "$in",
108
+ type: "any[]",
109
+ description: "Value exists in array"
110
+ },
111
+ {
112
+ name: "$nin",
113
+ type: "any[]",
114
+ description: "Value does not exist in array"
115
+ },
116
+ {
117
+ name: "and",
118
+ type: "StepCondition[]",
119
+ description: "Array of conditions that must all be true"
120
+ },
121
+ {
122
+ name: "or",
123
+ type: "StepCondition[]",
124
+ description: "Array of conditions where at least one must be true"
125
+ }
126
+ ]}
127
+ />
128
+
129
+ ## Related
130
+
131
+ - [Step Options Reference](./step-options.mdx)
132
+ - [Step Function Reference](./step-function.mdx)
133
+ - [Control Flow Guide](../../workflows/control-flow.mdx)
134
+ ```