@mastra/mcp-docs-server 0.0.0-a2a-20250421213654
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.docs/organized/changelogs/%40mastra%2Fastra.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +253 -0
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +16 -0
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +202 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fgithub.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +113 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmem0.md +281 -0
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Frag.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fragie.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-azure.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-deepgram.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-elevenlabs.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-google.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-ibm.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-murf.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-openai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-playai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-replicate.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-speechify.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +302 -0
- package/.docs/organized/changelogs/create-mastra.md +302 -0
- package/.docs/organized/changelogs/mastra.md +302 -0
- package/.docs/organized/code-examples/agent-network.md +282 -0
- package/.docs/organized/code-examples/agent.md +426 -0
- package/.docs/organized/code-examples/ai-sdk-useChat.md +378 -0
- package/.docs/organized/code-examples/assistant-ui.md +37 -0
- package/.docs/organized/code-examples/bird-checker-with-express.md +235 -0
- package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +360 -0
- package/.docs/organized/code-examples/bird-checker-with-nextjs.md +250 -0
- package/.docs/organized/code-examples/client-side-tools.md +69 -0
- package/.docs/organized/code-examples/crypto-chatbot.md +96 -0
- package/.docs/organized/code-examples/fireworks-r1.md +159 -0
- package/.docs/organized/code-examples/mcp-registry-registry.md +63 -0
- package/.docs/organized/code-examples/memory-todo-agent.md +164 -0
- package/.docs/organized/code-examples/memory-with-context.md +167 -0
- package/.docs/organized/code-examples/memory-with-libsql.md +204 -0
- package/.docs/organized/code-examples/memory-with-mem0.md +121 -0
- package/.docs/organized/code-examples/memory-with-pg.md +224 -0
- package/.docs/organized/code-examples/memory-with-upstash.md +268 -0
- package/.docs/organized/code-examples/quick-start.md +129 -0
- package/.docs/organized/code-examples/stock-price-tool.md +124 -0
- package/.docs/organized/code-examples/weather-agent.md +331 -0
- package/.docs/organized/code-examples/workflow-ai-recruiter.md +159 -0
- package/.docs/organized/code-examples/workflow-with-inline-steps.md +111 -0
- package/.docs/organized/code-examples/workflow-with-memory.md +393 -0
- package/.docs/organized/code-examples/workflow-with-separate-steps.md +131 -0
- package/.docs/raw/agents/adding-tools.mdx +288 -0
- package/.docs/raw/agents/adding-voice.mdx +200 -0
- package/.docs/raw/agents/agent-memory.mdx +62 -0
- package/.docs/raw/agents/mcp-guide.mdx +215 -0
- package/.docs/raw/agents/overview.mdx +303 -0
- package/.docs/raw/agents/runtime-variables.mdx +137 -0
- package/.docs/raw/community/discord.mdx +12 -0
- package/.docs/raw/community/licensing.mdx +63 -0
- package/.docs/raw/deployment/client.mdx +120 -0
- package/.docs/raw/deployment/deployment.mdx +127 -0
- package/.docs/raw/deployment/overview.mdx +63 -0
- package/.docs/raw/deployment/server.mdx +282 -0
- package/.docs/raw/evals/custom-eval.mdx +22 -0
- package/.docs/raw/evals/overview.mdx +95 -0
- package/.docs/raw/evals/running-in-ci.mdx +81 -0
- package/.docs/raw/evals/textual-evals.mdx +54 -0
- package/.docs/raw/faq/index.mdx +63 -0
- package/.docs/raw/frameworks/ai-sdk.mdx +296 -0
- package/.docs/raw/frameworks/next-js.mdx +238 -0
- package/.docs/raw/getting-started/installation.mdx +442 -0
- package/.docs/raw/getting-started/mcp-docs-server.mdx +141 -0
- package/.docs/raw/getting-started/model-capability.mdx +11 -0
- package/.docs/raw/getting-started/project-structure.mdx +80 -0
- package/.docs/raw/index.mdx +22 -0
- package/.docs/raw/integrations/index.mdx +213 -0
- package/.docs/raw/local-dev/add-to-existing-project.mdx +48 -0
- package/.docs/raw/local-dev/creating-a-new-project.mdx +54 -0
- package/.docs/raw/local-dev/mastra-dev.mdx +124 -0
- package/.docs/raw/mastra-cloud/deploying.mdx +136 -0
- package/.docs/raw/mastra-cloud/observability.mdx +163 -0
- package/.docs/raw/mastra-cloud/overview.mdx +57 -0
- package/.docs/raw/mastra-cloud/setting-up.mdx +122 -0
- package/.docs/raw/memory/memory-processors.mdx +131 -0
- package/.docs/raw/memory/overview.mdx +119 -0
- package/.docs/raw/memory/semantic-recall.mdx +126 -0
- package/.docs/raw/memory/working-memory.mdx +87 -0
- package/.docs/raw/observability/logging.mdx +38 -0
- package/.docs/raw/observability/nextjs-tracing.mdx +108 -0
- package/.docs/raw/observability/tracing.mdx +115 -0
- package/.docs/raw/rag/chunking-and-embedding.mdx +156 -0
- package/.docs/raw/rag/overview.mdx +85 -0
- package/.docs/raw/rag/retrieval.mdx +365 -0
- package/.docs/raw/rag/vector-databases.mdx +340 -0
- package/.docs/raw/reference/agents/createTool.mdx +229 -0
- package/.docs/raw/reference/agents/generate.mdx +334 -0
- package/.docs/raw/reference/agents/getAgent.mdx +54 -0
- package/.docs/raw/reference/agents/stream.mdx +369 -0
- package/.docs/raw/reference/cli/build.mdx +55 -0
- package/.docs/raw/reference/cli/dev.mdx +134 -0
- package/.docs/raw/reference/cli/init.mdx +43 -0
- package/.docs/raw/reference/client-js/agents.mdx +107 -0
- package/.docs/raw/reference/client-js/error-handling.mdx +38 -0
- package/.docs/raw/reference/client-js/logs.mdx +24 -0
- package/.docs/raw/reference/client-js/memory.mdx +97 -0
- package/.docs/raw/reference/client-js/telemetry.mdx +20 -0
- package/.docs/raw/reference/client-js/tools.mdx +44 -0
- package/.docs/raw/reference/client-js/vectors.mdx +79 -0
- package/.docs/raw/reference/client-js/workflows.mdx +136 -0
- package/.docs/raw/reference/core/mastra-class.mdx +232 -0
- package/.docs/raw/reference/deployer/cloudflare.mdx +212 -0
- package/.docs/raw/reference/deployer/deployer.mdx +159 -0
- package/.docs/raw/reference/deployer/netlify.mdx +116 -0
- package/.docs/raw/reference/deployer/vercel.mdx +122 -0
- package/.docs/raw/reference/evals/answer-relevancy.mdx +186 -0
- package/.docs/raw/reference/evals/bias.mdx +186 -0
- package/.docs/raw/reference/evals/completeness.mdx +174 -0
- package/.docs/raw/reference/evals/content-similarity.mdx +183 -0
- package/.docs/raw/reference/evals/context-position.mdx +190 -0
- package/.docs/raw/reference/evals/context-precision.mdx +189 -0
- package/.docs/raw/reference/evals/context-relevancy.mdx +188 -0
- package/.docs/raw/reference/evals/contextual-recall.mdx +191 -0
- package/.docs/raw/reference/evals/faithfulness.mdx +193 -0
- package/.docs/raw/reference/evals/hallucination.mdx +219 -0
- package/.docs/raw/reference/evals/keyword-coverage.mdx +176 -0
- package/.docs/raw/reference/evals/prompt-alignment.mdx +238 -0
- package/.docs/raw/reference/evals/summarization.mdx +205 -0
- package/.docs/raw/reference/evals/textual-difference.mdx +161 -0
- package/.docs/raw/reference/evals/tone-consistency.mdx +181 -0
- package/.docs/raw/reference/evals/toxicity.mdx +165 -0
- package/.docs/raw/reference/index.mdx +12 -0
- package/.docs/raw/reference/memory/Memory.mdx +212 -0
- package/.docs/raw/reference/memory/createThread.mdx +95 -0
- package/.docs/raw/reference/memory/getThreadById.mdx +46 -0
- package/.docs/raw/reference/memory/getThreadsByResourceId.mdx +48 -0
- package/.docs/raw/reference/memory/query.mdx +167 -0
- package/.docs/raw/reference/networks/agent-network.mdx +159 -0
- package/.docs/raw/reference/observability/create-logger.mdx +106 -0
- package/.docs/raw/reference/observability/logger.mdx +55 -0
- package/.docs/raw/reference/observability/otel-config.mdx +120 -0
- package/.docs/raw/reference/observability/providers/braintrust.mdx +40 -0
- package/.docs/raw/reference/observability/providers/dash0.mdx +40 -0
- package/.docs/raw/reference/observability/providers/index.mdx +16 -0
- package/.docs/raw/reference/observability/providers/laminar.mdx +41 -0
- package/.docs/raw/reference/observability/providers/langfuse.mdx +51 -0
- package/.docs/raw/reference/observability/providers/langsmith.mdx +48 -0
- package/.docs/raw/reference/observability/providers/langwatch.mdx +45 -0
- package/.docs/raw/reference/observability/providers/new-relic.mdx +40 -0
- package/.docs/raw/reference/observability/providers/signoz.mdx +40 -0
- package/.docs/raw/reference/observability/providers/traceloop.mdx +40 -0
- package/.docs/raw/reference/rag/astra.mdx +258 -0
- package/.docs/raw/reference/rag/chroma.mdx +281 -0
- package/.docs/raw/reference/rag/chunk.mdx +235 -0
- package/.docs/raw/reference/rag/document.mdx +127 -0
- package/.docs/raw/reference/rag/embeddings.mdx +160 -0
- package/.docs/raw/reference/rag/extract-params.mdx +249 -0
- package/.docs/raw/reference/rag/graph-rag.mdx +182 -0
- package/.docs/raw/reference/rag/libsql.mdx +357 -0
- package/.docs/raw/reference/rag/metadata-filters.mdx +298 -0
- package/.docs/raw/reference/rag/pg.mdx +501 -0
- package/.docs/raw/reference/rag/pinecone.mdx +281 -0
- package/.docs/raw/reference/rag/qdrant.mdx +236 -0
- package/.docs/raw/reference/rag/rerank.mdx +212 -0
- package/.docs/raw/reference/rag/turbopuffer.mdx +249 -0
- package/.docs/raw/reference/rag/upstash.mdx +247 -0
- package/.docs/raw/reference/rag/vectorize.mdx +298 -0
- package/.docs/raw/reference/storage/cloudflare-d1.mdx +89 -0
- package/.docs/raw/reference/storage/cloudflare.mdx +93 -0
- package/.docs/raw/reference/storage/libsql.mdx +74 -0
- package/.docs/raw/reference/storage/postgresql.mdx +93 -0
- package/.docs/raw/reference/storage/upstash.mdx +86 -0
- package/.docs/raw/reference/tools/client.mdx +321 -0
- package/.docs/raw/reference/tools/document-chunker-tool.mdx +141 -0
- package/.docs/raw/reference/tools/graph-rag-tool.mdx +154 -0
- package/.docs/raw/reference/tools/mcp-configuration.mdx +222 -0
- package/.docs/raw/reference/tools/vector-query-tool.mdx +212 -0
- package/.docs/raw/reference/voice/azure.mdx +215 -0
- package/.docs/raw/reference/voice/cloudflare.mdx +152 -0
- package/.docs/raw/reference/voice/composite-voice.mdx +140 -0
- package/.docs/raw/reference/voice/deepgram.mdx +164 -0
- package/.docs/raw/reference/voice/elevenlabs.mdx +216 -0
- package/.docs/raw/reference/voice/google.mdx +198 -0
- package/.docs/raw/reference/voice/mastra-voice.mdx +394 -0
- package/.docs/raw/reference/voice/murf.mdx +251 -0
- package/.docs/raw/reference/voice/openai-realtime.mdx +432 -0
- package/.docs/raw/reference/voice/openai.mdx +168 -0
- package/.docs/raw/reference/voice/playai.mdx +159 -0
- package/.docs/raw/reference/voice/sarvam.mdx +260 -0
- package/.docs/raw/reference/voice/speechify.mdx +145 -0
- package/.docs/raw/reference/voice/voice.addInstructions.mdx +70 -0
- package/.docs/raw/reference/voice/voice.addTools.mdx +77 -0
- package/.docs/raw/reference/voice/voice.answer.mdx +69 -0
- package/.docs/raw/reference/voice/voice.close.mdx +56 -0
- package/.docs/raw/reference/voice/voice.connect.mdx +124 -0
- package/.docs/raw/reference/voice/voice.events.mdx +80 -0
- package/.docs/raw/reference/voice/voice.getSpeakers.mdx +283 -0
- package/.docs/raw/reference/voice/voice.listen.mdx +198 -0
- package/.docs/raw/reference/voice/voice.off.mdx +72 -0
- package/.docs/raw/reference/voice/voice.on.mdx +129 -0
- package/.docs/raw/reference/voice/voice.send.mdx +81 -0
- package/.docs/raw/reference/voice/voice.speak.mdx +203 -0
- package/.docs/raw/reference/voice/voice.updateConfig.mdx +87 -0
- package/.docs/raw/reference/workflows/after.mdx +88 -0
- package/.docs/raw/reference/workflows/afterEvent.mdx +76 -0
- package/.docs/raw/reference/workflows/commit.mdx +37 -0
- package/.docs/raw/reference/workflows/createRun.mdx +77 -0
- package/.docs/raw/reference/workflows/else.mdx +72 -0
- package/.docs/raw/reference/workflows/events.mdx +305 -0
- package/.docs/raw/reference/workflows/execute.mdx +110 -0
- package/.docs/raw/reference/workflows/if.mdx +107 -0
- package/.docs/raw/reference/workflows/resume.mdx +155 -0
- package/.docs/raw/reference/workflows/resumeWithEvent.mdx +133 -0
- package/.docs/raw/reference/workflows/snapshots.mdx +207 -0
- package/.docs/raw/reference/workflows/start.mdx +84 -0
- package/.docs/raw/reference/workflows/step-class.mdx +100 -0
- package/.docs/raw/reference/workflows/step-condition.mdx +134 -0
- package/.docs/raw/reference/workflows/step-function.mdx +92 -0
- package/.docs/raw/reference/workflows/step-options.mdx +69 -0
- package/.docs/raw/reference/workflows/step-retries.mdx +203 -0
- package/.docs/raw/reference/workflows/suspend.mdx +70 -0
- package/.docs/raw/reference/workflows/then.mdx +74 -0
- package/.docs/raw/reference/workflows/until.mdx +165 -0
- package/.docs/raw/reference/workflows/watch.mdx +118 -0
- package/.docs/raw/reference/workflows/while.mdx +168 -0
- package/.docs/raw/reference/workflows/workflow.mdx +233 -0
- package/.docs/raw/storage/overview.mdx +378 -0
- package/.docs/raw/voice/overview.mdx +816 -0
- package/.docs/raw/voice/speech-to-speech.mdx +73 -0
- package/.docs/raw/voice/speech-to-text.mdx +84 -0
- package/.docs/raw/voice/text-to-speech.mdx +89 -0
- package/.docs/raw/workflows/control-flow.mdx +778 -0
- package/.docs/raw/workflows/dynamic-workflows.mdx +236 -0
- package/.docs/raw/workflows/error-handling.mdx +183 -0
- package/.docs/raw/workflows/nested-workflows.mdx +352 -0
- package/.docs/raw/workflows/overview.mdx +170 -0
- package/.docs/raw/workflows/runtime-variables.mdx +153 -0
- package/.docs/raw/workflows/steps.mdx +108 -0
- package/.docs/raw/workflows/suspend-and-resume.mdx +404 -0
- package/.docs/raw/workflows/variables.mdx +313 -0
- package/LICENSE.md +46 -0
- package/README.md +129 -0
- package/dist/_tsup-dts-rollup.d.ts +140 -0
- package/dist/chunk-HYPVNJL7.js +194 -0
- package/dist/prepare-docs/prepare.d.ts +1 -0
- package/dist/prepare-docs/prepare.js +1 -0
- package/dist/stdio.d.ts +1 -0
- package/dist/stdio.js +650 -0
- package/package.json +60 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: voice.send() | Voice Providers | Mastra Docs"
|
|
3
|
+
description: "Documentation for the send() method available in real-time voice providers, which streams audio data for continuous processing."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# voice.send()
|
|
7
|
+
|
|
8
|
+
The `send()` method streams audio data in real-time to voice providers for continuous processing. This method is essential for real-time speech-to-speech conversations, allowing you to send microphone input directly to the AI service.
|
|
9
|
+
|
|
10
|
+
## Usage Example
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { OpenAIRealtimeVoice } from "@mastra/voice-openai-realtime";
|
|
14
|
+
import Speaker from "@mastra/node-speaker";
|
|
15
|
+
import { getMicrophoneStream } from "@mastra/node-audio";
|
|
16
|
+
|
|
17
|
+
const speaker = new Speaker({
|
|
18
|
+
sampleRate: 24100, // Audio sample rate in Hz - standard for high-quality audio on MacBook Pro
|
|
19
|
+
channels: 1, // Mono audio output (as opposed to stereo which would be 2)
|
|
20
|
+
bitDepth: 16, // Bit depth for audio quality - CD quality standard (16-bit resolution)
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
// Initialize a real-time voice provider
|
|
25
|
+
const voice = new OpenAIRealtimeVoice({
|
|
26
|
+
realtimeConfig: {
|
|
27
|
+
model: "gpt-4o-mini-realtime",
|
|
28
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Connect to the real-time service
|
|
33
|
+
await voice.connect();
|
|
34
|
+
|
|
35
|
+
// Set up event listeners for responses
|
|
36
|
+
voice.on("writing", ({ text, role }) => {
|
|
37
|
+
console.log(`${role}: ${text}`);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
voice.on("speaker", (stream) => {
|
|
41
|
+
stream.pipe(speaker)
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Get microphone stream (implementation depends on your environment)
|
|
45
|
+
const microphoneStream = getMicrophoneStream();
|
|
46
|
+
|
|
47
|
+
// Send audio data to the voice provider
|
|
48
|
+
await voice.send(microphoneStream);
|
|
49
|
+
|
|
50
|
+
// You can also send audio data as Int16Array
|
|
51
|
+
const audioBuffer = getAudioBuffer(); // Assume this returns Int16Array
|
|
52
|
+
await voice.send(audioBuffer);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Parameters
|
|
56
|
+
<br/>
|
|
57
|
+
<PropertiesTable
|
|
58
|
+
content={[
|
|
59
|
+
{
|
|
60
|
+
name: "audioData",
|
|
61
|
+
type: "NodeJS.ReadableStream | Int16Array",
|
|
62
|
+
description: "Audio data to send to the voice provider. Can be a readable stream (like a microphone stream) or an Int16Array of audio samples.",
|
|
63
|
+
isOptional: false,
|
|
64
|
+
}
|
|
65
|
+
]}
|
|
66
|
+
/>
|
|
67
|
+
|
|
68
|
+
## Return Value
|
|
69
|
+
|
|
70
|
+
Returns a `Promise<void>` that resolves when the audio data has been accepted by the voice provider.
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
## Notes
|
|
74
|
+
|
|
75
|
+
- This method is only implemented by real-time voice providers that support speech-to-speech capabilities
|
|
76
|
+
- If called on a voice provider that doesn't support this functionality, it will log a warning and resolve immediately
|
|
77
|
+
- You must call `connect()` before using `send()` to establish the WebSocket connection
|
|
78
|
+
- The audio format requirements depend on the specific voice provider
|
|
79
|
+
- For continuous conversation, you typically call `send()` to transmit user audio, then `answer()` to trigger the AI response
|
|
80
|
+
- The provider will typically emit 'writing' events with transcribed text as it processes the audio
|
|
81
|
+
- When the AI responds, the provider will emit 'speaking' events with the audio response
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: voice.speak() | Voice Providers | Mastra Docs"
|
|
3
|
+
description: "Documentation for the speak() method available in all Mastra voice providers, which converts text to speech."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# voice.speak()
|
|
7
|
+
|
|
8
|
+
The `speak()` method is a core function available in all Mastra voice providers that converts text to speech. It takes text input and returns an audio stream that can be played or saved.
|
|
9
|
+
|
|
10
|
+
## Usage Example
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { OpenAIVoice } from "@mastra/voice-openai";
|
|
14
|
+
// Initialize a voice provider
|
|
15
|
+
const voice = new OpenAIVoice({
|
|
16
|
+
speaker: "alloy", // Default voice
|
|
17
|
+
});
|
|
18
|
+
// Basic usage with default settings
|
|
19
|
+
const audioStream = await voice.speak("Hello, world!");
|
|
20
|
+
// Using a different voice for this specific request
|
|
21
|
+
const audioStreamWithDifferentVoice = await voice.speak("Hello again!", {
|
|
22
|
+
speaker: "nova",
|
|
23
|
+
});
|
|
24
|
+
// Using provider-specific options
|
|
25
|
+
const audioStreamWithOptions = await voice.speak("Hello with options!", {
|
|
26
|
+
speaker: "echo",
|
|
27
|
+
speed: 1.2, // OpenAI-specific option
|
|
28
|
+
});
|
|
29
|
+
// Using a text stream as input
|
|
30
|
+
import { Readable } from "stream";
|
|
31
|
+
const textStream = Readable.from(["Hello", " from", " a", " stream!"]);
|
|
32
|
+
const audioStreamFromTextStream = await voice.speak(textStream);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
## Parameters
|
|
37
|
+
|
|
38
|
+
<PropertiesTable
|
|
39
|
+
content={[
|
|
40
|
+
{
|
|
41
|
+
name: "input",
|
|
42
|
+
type: "string | NodeJS.ReadableStream",
|
|
43
|
+
description: "Text to convert to speech. Can be a string or a readable stream of text.",
|
|
44
|
+
isOptional: false,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "options",
|
|
48
|
+
type: "object",
|
|
49
|
+
description: "Options for speech synthesis",
|
|
50
|
+
isOptional: true,
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: "options.speaker",
|
|
54
|
+
type: "string",
|
|
55
|
+
description: "Voice ID to use for this specific request. Overrides the default speaker set in the constructor.",
|
|
56
|
+
isOptional: true,
|
|
57
|
+
},
|
|
58
|
+
]}
|
|
59
|
+
/>
|
|
60
|
+
|
|
61
|
+
## Return Value
|
|
62
|
+
|
|
63
|
+
Returns a `Promise<NodeJS.ReadableStream | void>` where:
|
|
64
|
+
|
|
65
|
+
- `NodeJS.ReadableStream`: A stream of audio data that can be played or saved
|
|
66
|
+
- `void`: When using a realtime voice provider that emits audio through events instead of returning it directly
|
|
67
|
+
|
|
68
|
+
## Provider-Specific Options
|
|
69
|
+
|
|
70
|
+
Each voice provider may support additional options specific to their implementation. Here are some examples:
|
|
71
|
+
|
|
72
|
+
### OpenAI
|
|
73
|
+
|
|
74
|
+
<PropertiesTable
|
|
75
|
+
content={[
|
|
76
|
+
{
|
|
77
|
+
name: "options.speed",
|
|
78
|
+
type: "number",
|
|
79
|
+
description: "Speech speed multiplier. Values between 0.25 and 4.0 are supported.",
|
|
80
|
+
isOptional: true,
|
|
81
|
+
defaultValue: "1.0",
|
|
82
|
+
}
|
|
83
|
+
]}
|
|
84
|
+
/>
|
|
85
|
+
|
|
86
|
+
### ElevenLabs
|
|
87
|
+
|
|
88
|
+
<PropertiesTable
|
|
89
|
+
content={[
|
|
90
|
+
{
|
|
91
|
+
name: "options.stability",
|
|
92
|
+
type: "number",
|
|
93
|
+
description: "Voice stability. Higher values result in more stable, less expressive speech.",
|
|
94
|
+
isOptional: true,
|
|
95
|
+
defaultValue: "0.5",
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
name: "options.similarity_boost",
|
|
99
|
+
type: "number",
|
|
100
|
+
description: "Voice clarity and similarity to the original voice.",
|
|
101
|
+
isOptional: true,
|
|
102
|
+
defaultValue: "0.75",
|
|
103
|
+
}
|
|
104
|
+
]}
|
|
105
|
+
/>
|
|
106
|
+
|
|
107
|
+
### Google
|
|
108
|
+
|
|
109
|
+
<PropertiesTable
|
|
110
|
+
content={[
|
|
111
|
+
{
|
|
112
|
+
name: "options.languageCode",
|
|
113
|
+
type: "string",
|
|
114
|
+
description: "Language code for the voice (e.g., 'en-US').",
|
|
115
|
+
isOptional: true,
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
name: "options.audioConfig",
|
|
119
|
+
type: "object",
|
|
120
|
+
description: "Audio configuration options from Google Cloud Text-to-Speech API.",
|
|
121
|
+
isOptional: true,
|
|
122
|
+
defaultValue: "{ audioEncoding: 'LINEAR16' }",
|
|
123
|
+
}
|
|
124
|
+
]}
|
|
125
|
+
/>
|
|
126
|
+
|
|
127
|
+
### Murf
|
|
128
|
+
|
|
129
|
+
<PropertiesTable
|
|
130
|
+
content={[
|
|
131
|
+
{
|
|
132
|
+
name: "options.properties.rate",
|
|
133
|
+
type: "number",
|
|
134
|
+
description: "Speech rate multiplier.",
|
|
135
|
+
isOptional: true,
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
name: "options.properties.pitch",
|
|
139
|
+
type: "number",
|
|
140
|
+
description: "Voice pitch adjustment.",
|
|
141
|
+
isOptional: true,
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
name: "options.properties.format",
|
|
145
|
+
type: "'MP3' | 'WAV' | 'FLAC' | 'ALAW' | 'ULAW'",
|
|
146
|
+
description: "Output audio format.",
|
|
147
|
+
isOptional: true,
|
|
148
|
+
}
|
|
149
|
+
]}
|
|
150
|
+
/>
|
|
151
|
+
|
|
152
|
+
## Realtime Voice Providers
|
|
153
|
+
|
|
154
|
+
When using realtime voice providers like `OpenAIRealtimeVoice`, the `speak()` method behaves differently:
|
|
155
|
+
|
|
156
|
+
- Instead of returning an audio stream, it emits a 'speaking' event with the audio data
|
|
157
|
+
- You need to register an event listener to receive the audio chunks
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
import { OpenAIRealtimeVoice } from "@mastra/voice-openai-realtime";
|
|
161
|
+
import Speaker from "@mastra/node-speaker";
|
|
162
|
+
|
|
163
|
+
const speaker = new Speaker({
|
|
164
|
+
sampleRate: 24100, // Audio sample rate in Hz - standard for high-quality audio on MacBook Pro
|
|
165
|
+
channels: 1, // Mono audio output (as opposed to stereo which would be 2)
|
|
166
|
+
bitDepth: 16, // Bit depth for audio quality - CD quality standard (16-bit resolution)
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
const voice = new OpenAIRealtimeVoice();
|
|
170
|
+
await voice.connect();
|
|
171
|
+
// Register event listener for audio chunks
|
|
172
|
+
voice.on("speaker", (stream) => {
|
|
173
|
+
// Handle audio chunk (e.g., play it or save it)
|
|
174
|
+
stream.pipe(speaker)
|
|
175
|
+
});
|
|
176
|
+
// This will emit 'speaking' events instead of returning a stream
|
|
177
|
+
await voice.speak("Hello, this is realtime speech!");
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
## Using with CompositeVoice
|
|
182
|
+
|
|
183
|
+
When using `CompositeVoice`, the `speak()` method delegates to the configured speaking provider:
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
import { CompositeVoice } from "@mastra/core/voice";
|
|
187
|
+
import { OpenAIVoice } from "@mastra/voice-openai";
|
|
188
|
+
import { PlayAIVoice } from "@mastra/voice-playai";
|
|
189
|
+
const voice = new CompositeVoice({
|
|
190
|
+
speakProvider: new PlayAIVoice(),
|
|
191
|
+
listenProvider: new OpenAIVoice(),
|
|
192
|
+
});
|
|
193
|
+
// This will use the PlayAIVoice provider
|
|
194
|
+
const audioStream = await voice.speak("Hello, world!");
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Notes
|
|
198
|
+
|
|
199
|
+
- The behavior of `speak()` may vary slightly between providers, but all implementations follow the same basic interface.
|
|
200
|
+
- When using a realtime voice provider, the method might not return an audio stream directly but instead emit a 'speaking' event.
|
|
201
|
+
- If a text stream is provided as input, the provider will typically convert it to a string before processing.
|
|
202
|
+
- The audio format of the returned stream depends on the provider. Common formats include MP3, WAV, and OGG.
|
|
203
|
+
- For best performance, consider closing or ending the audio stream when you're done with it.
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: voice.updateConfig() | Voice Providers | Mastra Docs"
|
|
3
|
+
description: "Documentation for the updateConfig() method available in voice providers, which updates the configuration of a voice provider at runtime."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# voice.updateConfig()
|
|
7
|
+
|
|
8
|
+
The `updateConfig()` method allows you to update the configuration of a voice provider at runtime. This is useful for changing voice settings, API keys, or other provider-specific options without creating a new instance.
|
|
9
|
+
|
|
10
|
+
## Usage Example
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { OpenAIRealtimeVoice } from "@mastra/voice-openai-realtime";
|
|
14
|
+
|
|
15
|
+
// Initialize a real-time voice provider
|
|
16
|
+
const voice = new OpenAIRealtimeVoice({
|
|
17
|
+
realtimeConfig: {
|
|
18
|
+
model: "gpt-4o-mini-realtime",
|
|
19
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
20
|
+
},
|
|
21
|
+
speaker: "alloy",
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// Connect to the real-time service
|
|
25
|
+
await voice.connect();
|
|
26
|
+
|
|
27
|
+
// Later, update the configuration
|
|
28
|
+
voice.updateConfig({
|
|
29
|
+
voice: "nova", // Change the default voice
|
|
30
|
+
turn_detection: {
|
|
31
|
+
type: "server_vad",
|
|
32
|
+
threshold: 0.5,
|
|
33
|
+
silence_duration_ms: 1000
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// The next speak() call will use the new configuration
|
|
38
|
+
await voice.speak("Hello with my new voice!");
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Parameters
|
|
42
|
+
<br />
|
|
43
|
+
<PropertiesTable
|
|
44
|
+
content={[
|
|
45
|
+
{
|
|
46
|
+
name: "options",
|
|
47
|
+
type: "Record<string, unknown>",
|
|
48
|
+
description: "Configuration options to update. The specific properties depend on the voice provider.",
|
|
49
|
+
isOptional: false,
|
|
50
|
+
}
|
|
51
|
+
]}
|
|
52
|
+
/>
|
|
53
|
+
|
|
54
|
+
## Return Value
|
|
55
|
+
|
|
56
|
+
This method does not return a value.
|
|
57
|
+
|
|
58
|
+
## Configuration Options
|
|
59
|
+
|
|
60
|
+
Different voice providers support different configuration options:
|
|
61
|
+
|
|
62
|
+
### OpenAI Realtime
|
|
63
|
+
<br/>
|
|
64
|
+
<PropertiesTable
|
|
65
|
+
content={[
|
|
66
|
+
{
|
|
67
|
+
name: "voice",
|
|
68
|
+
type: "string",
|
|
69
|
+
description: "Voice ID to use for speech synthesis (e.g., 'alloy', 'echo', 'nova')",
|
|
70
|
+
isOptional: true,
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: "turn_detection",
|
|
74
|
+
type: "{ type: string, threshold?: number, silence_duration_ms?: number }",
|
|
75
|
+
description: "Configuration for detecting when a user has finished speaking",
|
|
76
|
+
isOptional: true,
|
|
77
|
+
}
|
|
78
|
+
]}
|
|
79
|
+
/>
|
|
80
|
+
|
|
81
|
+
## Notes
|
|
82
|
+
|
|
83
|
+
- The default implementation logs a warning if the provider doesn't support this method
|
|
84
|
+
- Configuration updates are typically applied to subsequent operations, not ongoing ones
|
|
85
|
+
- Not all properties that can be set in the constructor can be updated at runtime
|
|
86
|
+
- The specific behavior depends on the voice provider implementation
|
|
87
|
+
- For real-time voice providers, some configuration changes may require reconnecting to the service
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: .after() | Building Workflows | Mastra Docs"
|
|
3
|
+
description: Documentation for the `after()` method in workflows, enabling branching and merging paths.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# .after()
|
|
7
|
+
|
|
8
|
+
The `.after()` method defines explicit dependencies between workflow steps, enabling branching and merging paths in your workflow execution.
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
### Basic Branching
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
workflow
|
|
16
|
+
.step(stepA)
|
|
17
|
+
.then(stepB)
|
|
18
|
+
.after(stepA) // Create new branch after stepA completes
|
|
19
|
+
.step(stepC);
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Merging Multiple Branches
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
workflow
|
|
26
|
+
.step(stepA)
|
|
27
|
+
.then(stepB)
|
|
28
|
+
.step(stepC)
|
|
29
|
+
.then(stepD)
|
|
30
|
+
.after([stepB, stepD]) // Create a step that depends on multiple steps
|
|
31
|
+
.step(stepE);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Parameters
|
|
35
|
+
|
|
36
|
+
<PropertiesTable
|
|
37
|
+
content={[
|
|
38
|
+
{
|
|
39
|
+
name: "steps",
|
|
40
|
+
type: "Step | Step[]",
|
|
41
|
+
description: "A single step or array of steps that must complete before continuing",
|
|
42
|
+
isOptional: false
|
|
43
|
+
}
|
|
44
|
+
]}
|
|
45
|
+
/>
|
|
46
|
+
|
|
47
|
+
## Returns
|
|
48
|
+
|
|
49
|
+
<PropertiesTable
|
|
50
|
+
content={[
|
|
51
|
+
{
|
|
52
|
+
name: "workflow",
|
|
53
|
+
type: "Workflow",
|
|
54
|
+
description: "The workflow instance for method chaining"
|
|
55
|
+
}
|
|
56
|
+
]}
|
|
57
|
+
/>
|
|
58
|
+
|
|
59
|
+
## Examples
|
|
60
|
+
|
|
61
|
+
### Single Dependency
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
workflow
|
|
65
|
+
.step(fetchData)
|
|
66
|
+
.then(processData)
|
|
67
|
+
.after(fetchData) // Branch after fetchData
|
|
68
|
+
.step(logData);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Multiple Dependencies (Merging Branches)
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
workflow
|
|
75
|
+
.step(fetchUserData)
|
|
76
|
+
.then(validateUserData)
|
|
77
|
+
.step(fetchProductData)
|
|
78
|
+
.then(validateProductData)
|
|
79
|
+
.after([validateUserData, validateProductData]) // Wait for both validations to complete
|
|
80
|
+
.step(processOrder);
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Related
|
|
84
|
+
|
|
85
|
+
- [Branching Paths example](../../../examples/workflows/branching-paths.mdx)
|
|
86
|
+
- [Workflow Class Reference](./workflow.mdx)
|
|
87
|
+
- [Step Reference](./step-class.mdx)
|
|
88
|
+
- [Control Flow Guide](../../workflows/control-flow.mdx#merging-multiple-branches)
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: ".afterEvent() Method | Mastra Docs"
|
|
3
|
+
description: "Reference for the afterEvent method in Mastra workflows that creates event-based suspension points."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# afterEvent()
|
|
7
|
+
|
|
8
|
+
The `afterEvent()` method creates a suspension point in your workflow that waits for a specific event to occur before continuing execution.
|
|
9
|
+
|
|
10
|
+
## Syntax
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
workflow.afterEvent(eventName: string): Workflow
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Parameters
|
|
17
|
+
|
|
18
|
+
| Parameter | Type | Description |
|
|
19
|
+
|-----------|------|-------------|
|
|
20
|
+
| eventName | string | The name of the event to wait for. Must match an event defined in the workflow's `events` configuration. |
|
|
21
|
+
|
|
22
|
+
## Return Value
|
|
23
|
+
|
|
24
|
+
Returns the workflow instance for method chaining.
|
|
25
|
+
|
|
26
|
+
## Description
|
|
27
|
+
|
|
28
|
+
The `afterEvent()` method is used to create an automatic suspension point in your workflow that waits for a specific named event. It's essentially a declarative way to define a point where your workflow should pause and wait for an external event to occur.
|
|
29
|
+
|
|
30
|
+
When you call `afterEvent()`, Mastra:
|
|
31
|
+
|
|
32
|
+
1. Creates a special step with ID `__eventName_event`
|
|
33
|
+
2. This step automatically suspends the workflow execution
|
|
34
|
+
3. The workflow remains suspended until the specified event is triggered via `resumeWithEvent()`
|
|
35
|
+
4. When the event occurs, execution continues with the step following the `afterEvent()` call
|
|
36
|
+
|
|
37
|
+
This method is part of Mastra's event-driven workflow capabilities, allowing you to create workflows that coordinate with external systems or user interactions without manually implementing suspension logic.
|
|
38
|
+
|
|
39
|
+
## Usage Notes
|
|
40
|
+
|
|
41
|
+
- The event specified in `afterEvent()` must be defined in the workflow's `events` configuration with a schema
|
|
42
|
+
- The special step created has a predictable ID format: `__eventName_event` (e.g., `__approvalReceived_event`)
|
|
43
|
+
- Any step following `afterEvent()` can access the event data via `context.inputData.resumedEvent`
|
|
44
|
+
- Event data is validated against the schema defined for that event when `resumeWithEvent()` is called
|
|
45
|
+
|
|
46
|
+
## Examples
|
|
47
|
+
|
|
48
|
+
### Basic Usage
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
// Define workflow with events
|
|
52
|
+
const workflow = new Workflow({
|
|
53
|
+
name: 'approval-workflow',
|
|
54
|
+
events: {
|
|
55
|
+
approval: {
|
|
56
|
+
schema: z.object({
|
|
57
|
+
approved: z.boolean(),
|
|
58
|
+
approverName: z.string(),
|
|
59
|
+
}),
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Build workflow with event suspension point
|
|
65
|
+
workflow
|
|
66
|
+
.step(submitRequest)
|
|
67
|
+
.afterEvent('approval') // Workflow suspends here
|
|
68
|
+
.step(processApproval) // This step runs after the event occurs
|
|
69
|
+
.commit();
|
|
70
|
+
```
|
|
71
|
+
## Related
|
|
72
|
+
|
|
73
|
+
- [Event-Driven Workflows](./events.mdx)
|
|
74
|
+
- [resumeWithEvent()](./resumeWithEvent.mdx)
|
|
75
|
+
- [Suspend and Resume](../../workflows/suspend-and-resume.mdx)
|
|
76
|
+
- [Workflow Class](./workflow.mdx)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: Workflow.commit() | Running Workflows | Mastra Docs"
|
|
3
|
+
description: Documentation for the `.commit()` method in workflows, which re-initializes the workflow machine with the current step configuration.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Workflow.commit()
|
|
7
|
+
|
|
8
|
+
The `.commit()` method re-initializes the workflow's state machine with the current step configuration.
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
workflow
|
|
14
|
+
.step(stepA)
|
|
15
|
+
.then(stepB)
|
|
16
|
+
.commit();
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Returns
|
|
20
|
+
|
|
21
|
+
<PropertiesTable
|
|
22
|
+
content={[
|
|
23
|
+
{
|
|
24
|
+
name: "workflow",
|
|
25
|
+
type: "Workflow",
|
|
26
|
+
description: "The workflow instance"
|
|
27
|
+
}
|
|
28
|
+
]}
|
|
29
|
+
/>
|
|
30
|
+
|
|
31
|
+
## Related
|
|
32
|
+
|
|
33
|
+
- [Branching Paths example](../../../examples/workflows/branching-paths.mdx)
|
|
34
|
+
- [Workflow Class Reference](./workflow.mdx)
|
|
35
|
+
- [Step Reference](./step-class.mdx)
|
|
36
|
+
- [Control Flow Guide](../../workflows/control-flow.mdx)
|
|
37
|
+
```
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: Workflow.createRun() | Running Workflows | Mastra Docs"
|
|
3
|
+
description: "Documentation for the `.createRun()` method in workflows, which initializes a new workflow run instance."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Workflow.createRun()
|
|
7
|
+
|
|
8
|
+
The `.createRun()` method initializes a new workflow run instance. It generates a unique run ID for tracking and returns a start function that begins workflow execution when called.
|
|
9
|
+
|
|
10
|
+
One reason to use `.createRun()` vs `.execute()` is to get a unique run ID for tracking, logging, or subscribing via `.watch()`.
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
const { runId, start, watch } = workflow.createRun();
|
|
16
|
+
|
|
17
|
+
const result = await start();
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Returns
|
|
21
|
+
|
|
22
|
+
<PropertiesTable
|
|
23
|
+
content={[
|
|
24
|
+
{
|
|
25
|
+
name: "runId",
|
|
26
|
+
type: "string",
|
|
27
|
+
description: "Unique identifier for tracking this workflow run",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: "start",
|
|
31
|
+
type: "() => Promise<WorkflowResult>",
|
|
32
|
+
description: "Function that begins workflow execution when called",
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: "watch",
|
|
36
|
+
type: "(callback: (record: WorkflowResult) => void) => () => void",
|
|
37
|
+
description: "Function that accepts a callback function that will be called with each transition of the workflow run",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: "resume",
|
|
41
|
+
type: "({stepId: string, context: Record<string, any>}) => Promise<WorkflowResult>",
|
|
42
|
+
description: "Function that resumes a workflow run from a given step ID and context",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: "resumeWithEvent",
|
|
46
|
+
type: "(eventName: string, data: any) => Promise<WorkflowResult>",
|
|
47
|
+
description: "Function that resumes a workflow run from a given event name and data",
|
|
48
|
+
},
|
|
49
|
+
]}
|
|
50
|
+
/>
|
|
51
|
+
|
|
52
|
+
## Error Handling
|
|
53
|
+
|
|
54
|
+
The start function may throw validation errors if the workflow configuration is invalid:
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
try {
|
|
58
|
+
const { runId, start, watch, resume, resumeWithEvent } = workflow.createRun();
|
|
59
|
+
await start({ triggerData: data });
|
|
60
|
+
} catch (error) {
|
|
61
|
+
if (error instanceof ValidationError) {
|
|
62
|
+
// Handle validation errors
|
|
63
|
+
console.log(error.type); // 'circular_dependency' | 'no_terminal_path' | 'unreachable_step'
|
|
64
|
+
console.log(error.details);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Related
|
|
70
|
+
|
|
71
|
+
- [Workflow Class Reference](./workflow.mdx)
|
|
72
|
+
- [Step Class Reference](./step-class.mdx)
|
|
73
|
+
- See the [Creating a Workflow](../../../examples/workflows/creating-a-workflow.mdx) example for complete usage
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
```
|