@mastra/mcp-docs-server 0.13.31 → 0.13.32-alpha.0

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 (65) hide show
  1. package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +14 -14
  2. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +8 -8
  3. package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +14 -14
  4. package/.docs/organized/changelogs/%40mastra%2Fcore.md +45 -45
  5. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +9 -9
  6. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +9 -9
  7. package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +9 -9
  8. package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +9 -9
  9. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +11 -11
  10. package/.docs/organized/changelogs/%40mastra%2Fevals.md +10 -10
  11. package/.docs/organized/changelogs/%40mastra%2Flibsql.md +14 -14
  12. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +8 -8
  13. package/.docs/organized/changelogs/%40mastra%2Fpg.md +12 -12
  14. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +14 -14
  15. package/.docs/organized/changelogs/%40mastra%2Freact.md +7 -0
  16. package/.docs/organized/changelogs/%40mastra%2Fserver.md +10 -10
  17. package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +11 -11
  18. package/.docs/organized/changelogs/create-mastra.md +3 -3
  19. package/.docs/organized/changelogs/mastra.md +11 -11
  20. package/.docs/organized/code-examples/agui.md +2 -2
  21. package/.docs/organized/code-examples/ai-elements.md +2 -2
  22. package/.docs/organized/code-examples/ai-sdk-useChat.md +2 -2
  23. package/.docs/organized/code-examples/ai-sdk-v5.md +2 -2
  24. package/.docs/organized/code-examples/assistant-ui.md +2 -2
  25. package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +2 -2
  26. package/.docs/organized/code-examples/bird-checker-with-nextjs.md +2 -2
  27. package/.docs/organized/code-examples/client-side-tools.md +2 -2
  28. package/.docs/organized/code-examples/crypto-chatbot.md +2 -2
  29. package/.docs/organized/code-examples/heads-up-game.md +2 -2
  30. package/.docs/organized/code-examples/openapi-spec-writer.md +2 -2
  31. package/.docs/raw/agents/agent-memory.mdx +48 -31
  32. package/.docs/raw/agents/guardrails.mdx +8 -1
  33. package/.docs/raw/agents/networks.mdx +197 -128
  34. package/.docs/raw/agents/overview.mdx +10 -9
  35. package/.docs/raw/frameworks/agentic-uis/ai-sdk.mdx +92 -1
  36. package/.docs/raw/getting-started/installation.mdx +61 -68
  37. package/.docs/raw/memory/conversation-history.mdx +2 -2
  38. package/.docs/raw/memory/semantic-recall.mdx +36 -10
  39. package/.docs/raw/rag/chunking-and-embedding.mdx +19 -7
  40. package/.docs/raw/reference/client-js/agents.mdx +44 -25
  41. package/.docs/raw/reference/scorers/answer-relevancy.mdx +3 -6
  42. package/.docs/raw/reference/scorers/answer-similarity.mdx +7 -13
  43. package/.docs/raw/reference/scorers/bias.mdx +3 -6
  44. package/.docs/raw/reference/scorers/completeness.mdx +3 -6
  45. package/.docs/raw/reference/scorers/context-precision.mdx +6 -9
  46. package/.docs/raw/reference/scorers/context-relevance.mdx +12 -18
  47. package/.docs/raw/reference/scorers/faithfulness.mdx +3 -6
  48. package/.docs/raw/reference/scorers/hallucination.mdx +3 -6
  49. package/.docs/raw/reference/scorers/noise-sensitivity.mdx +13 -23
  50. package/.docs/raw/reference/scorers/prompt-alignment.mdx +16 -20
  51. package/.docs/raw/reference/scorers/tool-call-accuracy.mdx +4 -5
  52. package/.docs/raw/reference/scorers/toxicity.mdx +3 -6
  53. package/.docs/raw/reference/workflows/step.mdx +1 -1
  54. package/.docs/raw/reference/workflows/workflow-methods/sendEvent.mdx +23 -2
  55. package/.docs/raw/reference/workflows/workflow-methods/sleep.mdx +22 -4
  56. package/.docs/raw/reference/workflows/workflow-methods/sleepUntil.mdx +14 -4
  57. package/.docs/raw/reference/workflows/workflow-methods/waitForEvent.mdx +18 -1
  58. package/.docs/raw/server-db/runtime-context.mdx +13 -3
  59. package/.docs/raw/streaming/tool-streaming.mdx +30 -0
  60. package/.docs/raw/tools-mcp/overview.mdx +1 -1
  61. package/.docs/raw/workflows/overview.mdx +1 -1
  62. package/.docs/raw/workflows/suspend-and-resume.mdx +34 -23
  63. package/CHANGELOG.md +7 -0
  64. package/package.json +4 -4
  65. package/.docs/raw/workflows/pausing-execution.mdx +0 -142
@@ -124,10 +124,9 @@ A toxicity score between 0 and 1:
124
124
  In this example, the response contains explicit personal attacks and harmful language, resulting in a high toxicity score.
125
125
 
126
126
  ```typescript filename="src/example-high-toxicity.ts" showLineNumbers copy
127
- import { openai } from "@ai-sdk/openai";
128
127
  import { createToxicityScorer } from "@mastra/evals/scorers/llm";
129
128
 
130
- const scorer = createToxicityScorer({ model: openai("gpt-4o-mini") });
129
+ const scorer = createToxicityScorer({ model: 'openai/gpt-4o-mini' });
131
130
 
132
131
  const query = 'What do you think about the new team member?';
133
132
  const response = 'That incompetent fool is a complete waste of space. They clearly bought their degree and have no business being here. Everyone hates working with them.';
@@ -157,10 +156,9 @@ The scorer returns a high score indicating severe toxic content. The `reason` fi
157
156
  In this example, the response combines toxic and professional elements. The scorer identifies the problematic language while acknowledging the constructive feedback, resulting in a moderate toxicity score.
158
157
 
159
158
  ```typescript filename="src/example-mixed-toxicity.ts" showLineNumbers copy
160
- import { openai } from "@ai-sdk/openai";
161
159
  import { createToxicityScorer } from "@mastra/evals/scorers/llm";
162
160
 
163
- const scorer = createToxicityScorer({ model: openai("gpt-4o-mini") });
161
+ const scorer = createToxicityScorer({ model: 'openai/gpt-4o-mini' });
164
162
 
165
163
  const query = 'How was the meeting discussion?';
166
164
  const response = [
@@ -193,10 +191,9 @@ The scorer returns a moderate score reflecting a combination of dismissive langu
193
191
  In this example, the response is professional and constructive, with no toxic or harmful language detected.
194
192
 
195
193
  ```typescript filename="src/example-no-toxicity.ts" showLineNumbers copy
196
- import { openai } from "@ai-sdk/openai";
197
194
  import { createToxicityScorer } from "@mastra/evals/scorers/llm";
198
195
 
199
- const scorer = createToxicityScorer({ model: openai("gpt-4o-mini") });
196
+ const scorer = createToxicityScorer({ model: 'openai/gpt-4o-mini' });
200
197
 
201
198
  const query = 'Can you provide feedback on the project proposal?';
202
199
  const response = 'The proposal has strong points in its technical approach but could benefit from more detailed market analysis. I suggest we collaborate with the research team to strengthen these sections.';
@@ -120,7 +120,7 @@ const step1 = createStep({
120
120
  },
121
121
  {
122
122
  name: "suspend",
123
- type: "() => Promise<void>",
123
+ type: "(suspendPayload: any, suspendOptions?: { resumeLabel?: string }) => Promise<void>",
124
124
  description: "Function to pause workflow execution",
125
125
  },
126
126
  {
@@ -10,7 +10,7 @@ The `.sendEvent()` resumes execution when an event is sent.
10
10
  ## Usage example
11
11
 
12
12
  ```typescript copy
13
- workflow.sendEvent('event-name', step1);
13
+ run.sendEvent('event-name', { value: "data" });
14
14
  ```
15
15
 
16
16
  ## Parameters
@@ -44,6 +44,27 @@ workflow.sendEvent('event-name', step1);
44
44
  ]}
45
45
  />
46
46
 
47
+ ## Extended usage example
48
+
49
+ ```typescript showLineNumbers copy
50
+ import { mastra } from "./mastra";
51
+
52
+ const run = await mastra.getWorkflow("testWorkflow").createRunAsync();
53
+
54
+ const result = run.start({
55
+ inputData: {
56
+ value: "hello"
57
+ }
58
+ });
59
+
60
+ setTimeout(() => {
61
+ run.sendEvent("event-name", { value: "from event" });
62
+ }, 3000);
63
+ ```
64
+
65
+ > In this example, avoid using `await run.start()` directly, as it would block sending the event before the workflow reaches its waiting state.
66
+
47
67
  ## Related
48
68
 
49
- - [Sleep & Events](../../../docs/workflows/pausing-execution.mdx)
69
+ - [.waitForEvent()](./waitForEvent.mdx)
70
+ - [Suspend & Resume](../../../docs/workflows/suspend-and-resume.mdx#sleep--events)
@@ -5,7 +5,7 @@ description: Documentation for the `Workflow.sleep()` method in workflows, which
5
5
 
6
6
  # Workflow.sleep()
7
7
 
8
- The `.sleep()` method pauses execution for a specified number of milliseconds.
8
+ The `.sleep()` method pauses execution for a specified number of milliseconds. It accepts either a static number or a callback function for dynamic delays.
9
9
 
10
10
  ## Usage example
11
11
 
@@ -19,8 +19,8 @@ workflow.sleep(5000);
19
19
  content={[
20
20
  {
21
21
  name: "milliseconds",
22
- type: "number",
23
- description: "The number of milliseconds to pause execution",
22
+ type: "number | ((context: { inputData: any }) => number | Promise<number>)",
23
+ description: "The number of milliseconds to pause execution, or a callback that returns the delay",
24
24
  isOptional: false,
25
25
  },
26
26
  ]}
@@ -38,6 +38,24 @@ workflow.sleep(5000);
38
38
  ]}
39
39
  />
40
40
 
41
+ ## Extended usage example
42
+
43
+ ```typescript showLineNumbers copy
44
+ import { createWorkflow, createStep } from "@mastra/core/workflows";
45
+
46
+ const step1 = createStep({...});
47
+ const step2 = createStep({...});
48
+
49
+ export const testWorkflow = createWorkflow({...})
50
+ .then(step1)
51
+ .sleep(async ({ inputData }) => {
52
+ const { delayInMs } = inputData;
53
+ return delayInMs;
54
+ })
55
+ .then(step2)
56
+ .commit();
57
+ ```
58
+
41
59
  ## Related
42
60
 
43
- - [Sleep & Events](../../../docs/workflows/pausing-execution.mdx)
61
+ - [Suspend & Resume](../../../docs/workflows/suspend-and-resume.mdx#sleep--events)
@@ -41,11 +41,21 @@ workflow.sleepUntil(new Date(Date.now() + 5000));
41
41
  ## Extended usage example
42
42
 
43
43
  ```typescript showLineNumbers copy
44
- workflow.sleepUntil(async ({ inputData }) => {
45
- return new Date(Date.now() + inputData.value);
46
- });
44
+ import { createWorkflow, createStep } from "@mastra/core/workflows";
45
+
46
+ const step1 = createStep({...});
47
+ const step2 = createStep({...});
48
+
49
+ export const testWorkflow = createWorkflow({...})
50
+ .then(step1)
51
+ .sleepUntil(async ({ inputData }) => {
52
+ const { delayInMs } = inputData;
53
+ return new Date(Date.now() + delayInMs);
54
+ })
55
+ .then(step2)
56
+ .commit();
47
57
  ```
48
58
 
49
59
  ## Related
50
60
 
51
- - [Sleep & Events](../../../docs/workflows/pausing-execution.mdx)
61
+ - [Suspend & Resume](../../../docs/workflows/suspend-and-resume.mdx#sleep--events)
@@ -44,6 +44,23 @@ workflow.waitForEvent('event-name', step1);
44
44
  ]}
45
45
  />
46
46
 
47
+ ## Extended usage example
48
+
49
+ ```typescript showLineNumbers copy
50
+ import { createWorkflow, createStep } from "@mastra/core/workflows";
51
+
52
+ const step1 = createStep({...});
53
+ const step2 = createStep({...});
54
+ const step3 = createStep({...});
55
+
56
+ export const testWorkflow = createWorkflow({...})
57
+ .then(step1)
58
+ .waitForEvent("event-name", step2)
59
+ .then(step3)
60
+ .commit();
61
+ ```
62
+
47
63
  ## Related
48
64
 
49
- - [Sleep & Events](../../../docs/workflows/pausing-execution.mdx)
65
+ - [.sendEvent()](./sendEvent.mdx)
66
+ - [Suspend & Resume](../../../docs/workflows/suspend-and-resume.mdx#sleep--events)
@@ -21,14 +21,14 @@ Use `RuntimeContext` when a primitive’s behavior should change based on runtim
21
21
 
22
22
  ## Setting values
23
23
 
24
- Pass `runtimeContext` into an agent, workflow, or tool call to make values available to all underlying primitives during execution. Use `.set()` to define values before making the call.
24
+ Pass `runtimeContext` into an agent, network, workflow, or tool call to make values available to all underlying primitives during execution. Use `.set()` to define values before making the call.
25
25
 
26
26
  The `.set()` method takes two arguments:
27
27
 
28
28
  1. **key**: The name used to identify the value.
29
29
  2. **value**: The data to associate with that key.
30
30
 
31
- ```typescript {7,9,13,21,28} showLineNumbers
31
+ ```typescript showLineNumbers
32
32
  import { RuntimeContext } from "@mastra/core/runtime-context";
33
33
 
34
34
  export type UserTier = {
@@ -36,7 +36,6 @@ export type UserTier = {
36
36
  };
37
37
 
38
38
  const runtimeContext = new RuntimeContext<UserTier>();
39
-
40
39
  runtimeContext.set("user-tier", "enterprise");
41
40
 
42
41
  const agent = mastra.getAgent("weatherAgent");
@@ -44,6 +43,11 @@ await agent.generate("What's the weather in London?", {
44
43
  runtimeContext
45
44
  })
46
45
 
46
+ const routingAgent = mastra.getAgent("routingAgent");
47
+ routingAgent.network("What's the weather in London?", {
48
+ runtimeContext
49
+ });
50
+
47
51
  const run = await mastra.getWorkflow("weatherWorkflow").createRunAsync();
48
52
  await run.start({
49
53
  inputData: {
@@ -51,6 +55,12 @@ await run.start({
51
55
  },
52
56
  runtimeContext
53
57
  });
58
+ await run.resume({
59
+ resumeData: {
60
+ city: "New York"
61
+ },
62
+ runtimeContext
63
+ });
54
64
 
55
65
  await weatherTool.execute({
56
66
  context: {
@@ -69,6 +69,36 @@ export const testTool = createTool({
69
69
  });
70
70
  ```
71
71
 
72
+ You can also use `writer.custom` if you want to emit top level stream chunks, This useful and relevant when
73
+ integrating with UI Frameworks
74
+
75
+ ```typescript {5,8,15} showLineNumbers copy
76
+ import { createTool } from "@mastra/core/tools";
77
+
78
+ export const testTool = createTool({
79
+ // ...
80
+ execute: async ({ context, writer }) => {
81
+ const { value } = context;
82
+
83
+ await writer?.custom({
84
+ type: "data-tool-progress",
85
+ status: "pending"
86
+ });
87
+
88
+ const response = await fetch(...);
89
+
90
+ await writer?.custom({
91
+ type: "data-tool-progress",
92
+ status: "success"
93
+ });
94
+
95
+ return {
96
+ value: ""
97
+ };
98
+ }
99
+ });
100
+ ```
101
+
72
102
  ### Inspecting stream payloads
73
103
 
74
104
  Events written to the stream are included in the emitted chunks. These chunks can be inspected to access any custom fields, such as event types, intermediate values, or tool-specific data.
@@ -58,7 +58,7 @@ To make tools available to an agent, you configure them in the agent's definitio
58
58
 
59
59
  ## Using `RuntimeContext`
60
60
 
61
- Use `RuntimeContext` to access request-specific values. This lets you conditionally adjust behavior based on the context of the request.
61
+ Use [RuntimeContext](../server-db/runtime-context.mdx) to access request-specific values. This lets you conditionally adjust behavior based on the context of the request.
62
62
 
63
63
  ```typescript filename="src/mastra/tools/test-tool.ts" showLineNumbers
64
64
  export type UserTier = {
@@ -233,7 +233,7 @@ The workflow output includes the full execution lifecycle, showing the input and
233
233
 
234
234
  ## Using `RuntimeContext`
235
235
 
236
- Use `RuntimeContext` to access request-specific values. This lets you conditionally adjust behavior based on the context of the request.
236
+ Use [RuntimeContext](../server-db/runtime-context.mdx) to access request-specific values. This lets you conditionally adjust behavior based on the context of the request.
237
237
 
238
238
  ```typescript filename="src/mastra/workflows/test-workflow.ts" showLineNumbers
239
239
  export type UserTier = {
@@ -5,7 +5,7 @@ description: "Suspend and resume in Mastra workflows allows you to pause executi
5
5
 
6
6
  # Suspend & Resume
7
7
 
8
- Workflows can be paused at any step, with their current state persisted as a snapshot in storage. Execution can then be resumed from this saved snapshot when ready. Persisting the snapshot ensures the workflow state is maintained across sessions, deployments, and server restarts, essential for workflows that may remain suspended while awaiting external input or resources.
8
+ Workflows can be paused at any step, with their current state persisted as a [snapshot](./snapshots.mdx) in storage. Execution can then be resumed from this saved snapshot when ready. Persisting the snapshot ensures the workflow state is maintained across sessions, deployments, and server restarts, essential for workflows that may remain suspended while awaiting external input or resources.
9
9
 
10
10
  Common scenarios for suspending workflows include:
11
11
 
@@ -215,6 +215,32 @@ const resumedResult = await run.resume({
215
215
  });
216
216
  ```
217
217
 
218
+ You can pass `runtimeContext` as an argument to both the `start` and `resume` commands.
219
+
220
+ ```typescript filename="src/mastra/workflows/test-workflow.ts"
221
+ import { RuntimeContext } from "@mastra/core/runtime-context";
222
+
223
+ const runtimeContext = new RuntimeContext();
224
+
225
+ const result = await run.start({
226
+ step: 'step-1',
227
+ inputData: {
228
+ city: "London"
229
+ },
230
+ runtimeContext
231
+ });
232
+
233
+ const resumedResult = await run.resume({
234
+ step: 'step-1',
235
+ resumeData: {
236
+ city: "New York"
237
+ },
238
+ runtimeContext
239
+ });
240
+ ```
241
+
242
+ > See [Runtime Context](../server-db/runtime-context.mdx) for more information.
243
+
218
244
  ### Resuming nested workflows
219
245
 
220
246
  To resume a suspended nested workflow pass the workflow instance to the `step` parameter of the `resume` function.
@@ -260,28 +286,13 @@ if (result.status === "suspended") {
260
286
  }
261
287
  ```
262
288
 
263
- ## Using `RuntimeContext` with suspend/resume
264
-
265
- When using suspend/resume with `RuntimeContext`, you can create the instance yourself, and pass it to the `start` and `resume` functions.
266
- `RuntimeContext` is not automatically shared on a workflow run.
267
-
268
- ```typescript {1,4,9,16} filename="src/mastra/workflows/test-workflow.tss" showLineNumbers copy
269
- import { RuntimeContext } from "@mastra/core/di";
270
- import { mastra } from "./mastra";
289
+ ## Sleep & Events
271
290
 
272
- const runtimeContext = new RuntimeContext();
273
- const run = await mastra.getWorkflow("testWorkflow").createRunAsync();
291
+ Workflows can also pause execution for timed delays or external events. These methods set the workflow status to `waiting` rather than `suspended`, and are useful for polling, delayed retries, or event-driven processes.
274
292
 
275
- const result = await run.start({
276
- inputData: { suggestions: ["London", "Paris", "New York"] },
277
- runtimeContext
278
- });
293
+ **Available methods:**
279
294
 
280
- if (result.status === "suspended") {
281
- const resumedResult = await run.resume({
282
- step: 'step-1',
283
- resumeData: { city: "New York" },
284
- runtimeContext
285
- });
286
- }
287
- ```
295
+ - [`.sleep()`](../../reference/workflows/workflow-methods/sleep.mdx): Pause for a specified number of milliseconds
296
+ - [`.sleepUntil()`](../../reference/workflows/workflow-methods/sleepUntil.mdx) : Pause until a specific date
297
+ - [`.waitForEvent()`](../../reference/workflows/workflow-methods/waitForEvent.mdx): Pause until an external event is received
298
+ - [`.sendEvent()`](../../reference/workflows/workflow-methods/sendEvent.mdx) : Send an event to resume a waiting workflow
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @mastra/mcp-docs-server
2
2
 
3
+ ## 0.13.32-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`c67ca32`](https://github.com/mastra-ai/mastra/commit/c67ca32e3c2cf69bfc146580770c720220ca44ac), [`dbc9e12`](https://github.com/mastra-ai/mastra/commit/dbc9e1216ba575ba59ead4afb727a01215f7de4f), [`99e41b9`](https://github.com/mastra-ai/mastra/commit/99e41b94957cdd25137d3ac12e94e8b21aa01b68), [`c28833c`](https://github.com/mastra-ai/mastra/commit/c28833c5b6d8e10eeffd7f7d39129d53b8bca240), [`f053e89`](https://github.com/mastra-ai/mastra/commit/f053e89160dbd0bd3333fc3492f68231b5c7c349), [`9a1a485`](https://github.com/mastra-ai/mastra/commit/9a1a4859b855e37239f652bf14b1ecd1029b8c4e), [`9257233`](https://github.com/mastra-ai/mastra/commit/9257233c4ffce09b2bedc2a9adbd70d7a83fa8e2), [`0f1a4c9`](https://github.com/mastra-ai/mastra/commit/0f1a4c984fb4b104b2f0b63ba18c9fa77f567700), [`2db6160`](https://github.com/mastra-ai/mastra/commit/2db6160e2022ff8827c15d30157e684683b934b5), [`8aeea37`](https://github.com/mastra-ai/mastra/commit/8aeea37efdde347c635a67fed56794943b7f74ec), [`02fe153`](https://github.com/mastra-ai/mastra/commit/02fe15351d6021d214da48ec982a0e9e4150bcee), [`74567b3`](https://github.com/mastra-ai/mastra/commit/74567b3d237ae3915cd0bca3cf55fa0a64e4e4a4), [`15a1733`](https://github.com/mastra-ai/mastra/commit/15a1733074cee8bd37370e1af34cd818e89fa7ac), [`fc2a774`](https://github.com/mastra-ai/mastra/commit/fc2a77468981aaddc3e77f83f0c4ad4a4af140da), [`4e08933`](https://github.com/mastra-ai/mastra/commit/4e08933625464dfde178347af5b6278fcf34188e)]:
8
+ - @mastra/core@0.21.2-alpha.0
9
+
3
10
  ## 0.13.31
4
11
 
5
12
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/mcp-docs-server",
3
- "version": "0.13.31",
3
+ "version": "0.13.32-alpha.0",
4
4
  "description": "MCP server for accessing Mastra.ai documentation, changelogs, and news.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -33,7 +33,7 @@
33
33
  "uuid": "^11.1.0",
34
34
  "zod": "^3.25.76",
35
35
  "zod-to-json-schema": "^3.24.6",
36
- "@mastra/core": "0.21.1",
36
+ "@mastra/core": "0.21.2-alpha.0",
37
37
  "@mastra/mcp": "^0.13.5"
38
38
  },
39
39
  "devDependencies": {
@@ -43,14 +43,14 @@
43
43
  "@types/turndown": "^5.0.5",
44
44
  "@wong2/mcp-cli": "^1.10.0",
45
45
  "cross-env": "^10.1.0",
46
- "eslint": "^9.36.0",
46
+ "eslint": "^9.37.0",
47
47
  "hono": "^4.9.7",
48
48
  "tsup": "^8.5.0",
49
49
  "tsx": "^4.19.4",
50
50
  "typescript": "^5.8.3",
51
51
  "vitest": "^3.2.4",
52
52
  "@internal/lint": "0.0.50",
53
- "@mastra/core": "0.21.1"
53
+ "@mastra/core": "0.21.2-alpha.0"
54
54
  },
55
55
  "homepage": "https://mastra.ai",
56
56
  "repository": {
@@ -1,142 +0,0 @@
1
- ---
2
- title: "Pausing Execution | Mastra Docs"
3
- description: "Pausing execution in Mastra workflows allows you to pause execution while waiting for external input or resources via .sleep(), .sleepUntil() and .waitForEvent()."
4
- ---
5
-
6
- # Sleep & Events
7
-
8
- Mastra lets you pause workflow execution when waiting for external input or timing conditions. This can be useful for things like polling, delayed retries, or waiting on user actions.
9
-
10
- You can pause execution using:
11
-
12
- - `sleep()`: Pause for a set number of milliseconds
13
- - `sleepUntil()`: Pause until a specific timestamp
14
- - `waitForEvent()`: Pause until an external event is received
15
- - `sendEvent()`: Send an event to resume a waiting workflow
16
-
17
- When using any of these methods, the workflow status is set to `waiting` until execution resumes.
18
-
19
- ## Pausing with `.sleep()`
20
-
21
- The `sleep()` method pauses execution between steps for a specified number of milliseconds.
22
-
23
- ```typescript {9} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
24
- import { createWorkflow, createStep } from "@mastra/core/workflows";
25
- import { z } from "zod";
26
-
27
- const step1 = createStep({...});
28
- const step2 = createStep({...});
29
-
30
- export const testWorkflow = createWorkflow({...})
31
- .then(step1)
32
- .sleep(1000)
33
- .then(step2)
34
- .commit();
35
- ```
36
-
37
- ### Pausing with `.sleep(callback)`
38
-
39
- The `sleep()` method also accepts a callback that returns the number of milliseconds to pause. The callback receives `inputData`, allowing the delay to be computed dynamically.
40
-
41
- ```typescript {9} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
42
- import { createWorkflow, createStep } from "@mastra/core/workflows";
43
- import { z } from "zod";
44
-
45
- const step1 = createStep({...});
46
- const step2 = createStep({...});
47
-
48
- export const testWorkflow = createWorkflow({...})
49
- .then(step1)
50
- .sleep(async ({ inputData }) => {
51
- const { delayInMs } = inputData
52
- return delayInMs;
53
- })
54
- .then(step2)
55
- .commit();
56
- ```
57
-
58
- ## Pausing with `.sleepUntil()`
59
-
60
- The `sleepUntil()` method pauses execution between steps until a specified date.
61
-
62
- ```typescript {9} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
63
- import { createWorkflow, createStep } from "@mastra/core/workflows";
64
- import { z } from "zod";
65
-
66
- const step1 = createStep({...});
67
- const step2 = createStep({...});
68
-
69
- export const testWorkflow = createWorkflow({...})
70
- .then(step1)
71
- .sleepUntil(new Date(Date.now() + 5000))
72
- .then(step2)
73
- .commit();
74
- ```
75
-
76
- ### Pausing with `.sleepUntil(callback)`
77
-
78
- The `sleepUntil()` method also accepts a callback that returns a `Date` object. The callback receives `inputData`, allowing the target time to be computed dynamically.
79
-
80
- ```typescript {9} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
81
- import { createWorkflow, createStep } from "@mastra/core/workflows";
82
- import { z } from "zod";
83
-
84
- const step1 = createStep({...});
85
- const step2 = createStep({...});
86
-
87
- export const testWorkflow = createWorkflow({...})
88
- .then(step1)
89
- .sleepUntil(async ({ inputData }) => {
90
- const { delayInMs } = inputData
91
- return new Date(Date.now() + delayInMs);
92
- })
93
- .then(step2)
94
- .commit();
95
- ```
96
-
97
-
98
- > `Date.now()` is evaluated when the workflow starts, not at the moment the `sleepUntil()` method is called.
99
-
100
- ## Pausing with `.waitForEvent()`
101
-
102
- The `waitForEvent()` method pauses execution until a specific event is received. Use `run.sendEvent()` to send the event. You must provide both the event name and the step to resume.
103
-
104
- ![Pausing with .waitForEvent()](/image/workflows/workflows-sleep-events-waitforevent.jpg)
105
-
106
- ```typescript {10} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
107
- import { createWorkflow, createStep } from "@mastra/core/workflows";
108
- import { z } from "zod";
109
-
110
- const step1 = createStep({...});
111
- const step2 = createStep({...});
112
- const step3 = createStep({...});
113
-
114
- export const testWorkflow = createWorkflow({...})
115
- .then(step1)
116
- .waitForEvent("my-event-name", step2)
117
- .then(step3)
118
- .commit();
119
- ```
120
- ## Sending an event with `.sendEvent()`
121
-
122
- The `.sendEvent()` method sends an event to the workflow. It accepts the event name and optional event data, which can be any JSON-serializable value.
123
-
124
- ```typescript {5,12,15} filename="src/test-workflow.ts" showLineNumbers copy
125
- import { mastra } from "./mastra";
126
-
127
- const run = await mastra.getWorkflow("testWorkflow").createRunAsync();
128
-
129
- const result = run.start({
130
- inputData: {
131
- value: "hello"
132
- }
133
- });
134
-
135
- setTimeout(() => {
136
- run.sendEvent("my-event-name", { value: "from event" });
137
- }, 3000);
138
-
139
- console.log(JSON.stringify(await result, null, 2));
140
- ```
141
-
142
- > In this example, avoid using `await run.start()` directly, it would block sending the event before the workflow reaches its waiting state.