@mastra/mcp-docs-server 1.2.4 → 1.2.5-alpha.3
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/docs/agent-builder/deploying.md +1 -1
- package/.docs/docs/agent-controller/overview.md +1 -1
- package/.docs/docs/agent-controller/session.md +1 -1
- package/.docs/docs/agents/overview.md +1 -1
- package/.docs/docs/agents/processors.md +1 -1
- package/.docs/docs/agents/supervisor-agents.md +3 -3
- package/.docs/docs/agents/using-tools.md +1 -1
- package/.docs/docs/{agents → long-running-agents}/background-tasks.md +2 -2
- package/.docs/docs/{agents → long-running-agents}/durable-agents.md +2 -2
- package/.docs/docs/{agents → long-running-agents}/goals.md +1 -1
- package/.docs/docs/{agents → long-running-agents}/heartbeats.md +5 -5
- package/.docs/docs/{agents → long-running-agents}/signal-providers.md +4 -4
- package/.docs/docs/memory/working-memory.md +1 -1
- package/.docs/docs/observability/config.md +1 -2
- package/.docs/docs/server/pubsub.md +2 -2
- package/.docs/docs/voice/overview.md +3 -3
- package/.docs/docs/voice/speech-to-speech.md +81 -1
- package/.docs/docs/voice/speech-to-text.md +19 -1
- package/.docs/docs/voice/text-to-speech.md +21 -1
- package/.docs/docs/workflows/control-flow.md +1 -1
- package/.docs/docs/workflows/error-handling.md +1 -1
- package/.docs/docs/workflows/human-in-the-loop.md +1 -1
- package/.docs/docs/workflows/overview.md +1 -1
- package/.docs/docs/workflows/snapshots.md +1 -1
- package/.docs/docs/workflows/suspend-and-resume.md +1 -1
- package/.docs/docs/workflows/time-travel.md +1 -1
- package/.docs/docs/workflows/workflow-state.md +1 -1
- package/.docs/guides/build-your-ui/copilotkit/channels.md +76 -0
- package/.docs/guides/build-your-ui/copilotkit/generative-ui.md +174 -0
- package/.docs/guides/build-your-ui/copilotkit/overview.md +411 -0
- package/.docs/guides/concepts/streaming.md +1 -1
- package/.docs/guides/deployment/vercel.md +1 -2
- package/.docs/guides/guide/signal-provider.md +5 -5
- package/.docs/models/environment-variables.md +2 -0
- package/.docs/models/index.md +1 -1
- package/.docs/models/providers/alibaba-cn.md +2 -1
- package/.docs/models/providers/friendli.md +1 -2
- package/.docs/models/providers/kenari.md +95 -0
- package/.docs/models/providers/nvidia.md +2 -3
- package/.docs/models/providers/tencent-token-plan.md +7 -7
- package/.docs/models/providers/tencent-tokenhub.md +5 -4
- package/.docs/models/providers.md +2 -0
- package/.docs/reference/acp/acp-agent.md +5 -5
- package/.docs/reference/acp/create-acp-tool.md +5 -5
- package/.docs/reference/agent-controller/agent-controller-class.md +27 -27
- package/.docs/reference/agents/agent.md +34 -34
- package/.docs/reference/agents/channels.md +19 -19
- package/.docs/reference/agents/createSkill.md +2 -2
- package/.docs/reference/agents/durable-agent.md +22 -22
- package/.docs/reference/agents/generate.md +10 -10
- package/.docs/reference/agents/generateLegacy.md +12 -12
- package/.docs/reference/agents/getMetadata.md +1 -1
- package/.docs/reference/agents/getVoice.md +1 -1
- package/.docs/reference/agents/inngest-agent.md +9 -9
- package/.docs/reference/agents/network.md +1 -1
- package/.docs/reference/ai-sdk/chat-route.md +4 -4
- package/.docs/reference/ai-sdk/handle-chat-stream.md +6 -6
- package/.docs/reference/ai-sdk/handle-network-stream.md +3 -3
- package/.docs/reference/ai-sdk/handle-workflow-stream.md +1 -1
- package/.docs/reference/ai-sdk/network-route.md +4 -4
- package/.docs/reference/ai-sdk/to-ai-sdk-messages.md +1 -1
- package/.docs/reference/ai-sdk/to-ai-sdk-stream.md +1 -1
- package/.docs/reference/ai-sdk/with-mastra.md +2 -2
- package/.docs/reference/ai-sdk/workflow-route.md +2 -2
- package/.docs/reference/ai-sdk/workflow-snapshot-to-stream.md +1 -1
- package/.docs/reference/auth/google.md +10 -10
- package/.docs/reference/auth/okta.md +11 -11
- package/.docs/reference/auth/workos.md +3 -3
- package/.docs/reference/channels/slack-provider.md +15 -15
- package/.docs/reference/cli/mastra.md +145 -0
- package/.docs/reference/client-js/agents.md +9 -9
- package/.docs/reference/client-js/mastra-client.md +5 -5
- package/.docs/reference/client-js/responses.md +3 -3
- package/.docs/reference/configuration.md +1 -1
- package/.docs/reference/core/getAgentById.md +3 -3
- package/.docs/reference/core/getWorkflow.md +1 -1
- package/.docs/reference/core/listWorkflows.md +1 -1
- package/.docs/reference/core/mastra-class.md +3 -3
- package/.docs/reference/core/removeWorkspace.md +2 -2
- package/.docs/reference/datasets/compareExperiments.md +1 -1
- package/.docs/reference/datasets/getItemHistory.md +1 -1
- package/.docs/reference/datasets/list.md +5 -5
- package/.docs/reference/datasets/listExperimentResults.md +4 -4
- package/.docs/reference/datasets/listExperiments.md +4 -4
- package/.docs/reference/datasets/listItems.md +5 -5
- package/.docs/reference/datasets/listVersions.md +3 -3
- package/.docs/reference/datasets/startExperiment.md +8 -8
- package/.docs/reference/datasets/startExperimentAsync.md +1 -1
- package/.docs/reference/editor/agent-builder/agent-builder-options.md +4 -4
- package/.docs/reference/editor/agent-builder/builder-agent-defaults.md +7 -7
- package/.docs/reference/editor/agent-builder/builder-models.md +4 -4
- package/.docs/reference/editor/blob-store-provider.md +2 -2
- package/.docs/reference/editor/browser-provider.md +2 -2
- package/.docs/reference/editor/filesystem-provider.md +2 -2
- package/.docs/reference/editor/mastra-editor.md +2 -2
- package/.docs/reference/editor/processor-provider.md +4 -4
- package/.docs/reference/editor/sandbox-provider.md +2 -2
- package/.docs/reference/editor/storage-browser-ref.md +2 -2
- package/.docs/reference/editor/storage-workspace-ref.md +7 -7
- package/.docs/reference/evals/create-scorer.md +8 -8
- package/.docs/reference/evals/rubric.md +1 -1
- package/.docs/reference/evals/run-evals.md +7 -7
- package/.docs/reference/evals/trajectory-accuracy.md +1 -1
- package/.docs/reference/index.md +2 -2
- package/.docs/reference/logging/pino-logger.md +4 -4
- package/.docs/reference/memory/cloneThread.md +35 -4
- package/.docs/reference/memory/memory-class.md +5 -5
- package/.docs/reference/memory/observational-memory.md +43 -43
- package/.docs/reference/memory/recall.md +4 -4
- package/.docs/reference/memory/serialized-memory-config.md +6 -6
- package/.docs/reference/observability/tracing/configuration.md +4 -4
- package/.docs/reference/processors/language-detector.md +1 -1
- package/.docs/reference/processors/moderation-processor.md +1 -1
- package/.docs/reference/processors/pii-detector.md +1 -1
- package/.docs/reference/processors/processor-interface.md +20 -20
- package/.docs/reference/processors/prompt-injection-detector.md +1 -1
- package/.docs/reference/processors/response-cache.md +6 -6
- package/.docs/reference/processors/unicode-normalizer.md +1 -1
- package/.docs/reference/pubsub/base.md +7 -7
- package/.docs/reference/pubsub/caching-pubsub.md +1 -1
- package/.docs/reference/pubsub/event-emitter.md +2 -2
- package/.docs/reference/pubsub/google-cloud-pubsub.md +1 -1
- package/.docs/reference/pubsub/lease-provider.md +3 -3
- package/.docs/reference/pubsub/redis-streams.md +6 -6
- package/.docs/reference/pubsub/unix-socket-pubsub.md +1 -1
- package/.docs/reference/rag/chunk.md +2 -2
- package/.docs/reference/server/create-route.md +3 -3
- package/.docs/reference/server/express-adapter.md +4 -4
- package/.docs/reference/server/fastify-adapter.md +4 -4
- package/.docs/reference/server/hono-adapter.md +4 -4
- package/.docs/reference/server/koa-adapter.md +4 -4
- package/.docs/reference/server/mastra-server.md +1 -1
- package/.docs/reference/server/nestjs-adapter.md +3 -3
- package/.docs/reference/server/register-api-route.md +3 -3
- package/.docs/reference/signals/create-notification-inbox-tool.md +3 -3
- package/.docs/reference/signals/signal-provider.md +7 -7
- package/.docs/reference/signals/webhook-signal-provider.md +2 -2
- package/.docs/reference/storage/clickhouse.md +7 -7
- package/.docs/reference/storage/composite.md +2 -2
- package/.docs/reference/storage/duckdb.md +1 -1
- package/.docs/reference/storage/dynamodb.md +1 -1
- package/.docs/reference/storage/libsql.md +1 -1
- package/.docs/reference/storage/postgresql.md +2 -2
- package/.docs/reference/storage/redis.md +2 -2
- package/.docs/reference/storage/retention.md +5 -5
- package/.docs/reference/storage/spanner.md +6 -6
- package/.docs/reference/streaming/ChunkType.md +3 -3
- package/.docs/reference/streaming/agents/stream.md +14 -14
- package/.docs/reference/streaming/agents/streamLegacy.md +10 -10
- package/.docs/reference/streaming/agents/streamUntilIdle.md +1 -1
- package/.docs/reference/streaming/workflows/resumeStream.md +1 -1
- package/.docs/reference/templates/overview.md +1 -140
- package/.docs/reference/tools/brightdata.md +4 -4
- package/.docs/reference/tools/create-code-mode.md +5 -5
- package/.docs/reference/tools/create-tool.md +15 -15
- package/.docs/reference/tools/graph-rag-tool.md +1 -1
- package/.docs/reference/tools/mcp-client.md +2 -2
- package/.docs/reference/tools/mcp-server.md +12 -12
- package/.docs/reference/tools/perplexity.md +3 -3
- package/.docs/reference/tools/tavily.md +1 -1
- package/.docs/reference/tools/vector-query-tool.md +1 -1
- package/.docs/reference/vectors/chroma.md +1 -1
- package/.docs/reference/vectors/mongodb.md +1 -1
- package/.docs/reference/vectors/pg.md +1 -1
- package/.docs/reference/vectors/s3vectors.md +4 -4
- package/.docs/reference/voice/google-gemini-live.md +3 -3
- package/.docs/reference/voice/inworld-realtime.md +12 -12
- package/.docs/reference/voice/inworld.md +2 -2
- package/.docs/reference/voice/voice.on.md +1 -1
- package/.docs/reference/workflows/run-methods/resume.md +1 -1
- package/.docs/reference/workflows/run-methods/timeTravel.md +1 -1
- package/.docs/reference/workspace/agentcore-runtime-sandbox.md +4 -4
- package/.docs/reference/workspace/agentfs-filesystem.md +1 -1
- package/.docs/reference/workspace/apple-container-sandbox.md +5 -5
- package/.docs/reference/workspace/archil-filesystem.md +5 -5
- package/.docs/reference/workspace/blaxel-sandbox.md +1 -1
- package/.docs/reference/workspace/daytona-sandbox.md +1 -1
- package/.docs/reference/workspace/docker-sandbox.md +2 -2
- package/.docs/reference/workspace/e2b-sandbox.md +2 -2
- package/.docs/reference/workspace/files-sdk-filesystem.md +1 -1
- package/.docs/reference/workspace/filesystem.md +1 -1
- package/.docs/reference/workspace/local-filesystem.md +3 -3
- package/.docs/reference/workspace/local-sandbox.md +1 -1
- package/.docs/reference/workspace/mesa-filesystem.md +3 -3
- package/.docs/reference/workspace/modal-sandbox.md +1 -1
- package/.docs/reference/workspace/railway-sandbox.md +1 -1
- package/.docs/reference/workspace/s3-filesystem.md +4 -4
- package/.docs/reference/workspace/sandbox.md +1 -1
- package/.docs/reference/workspace/{vercel-microvm-sandbox.md → vercel-sandbox.md} +21 -15
- package/.docs/reference/workspace/{vercel.md → vercel-serverless.md} +21 -14
- package/.docs/reference/workspace/workspace-class.md +15 -15
- package/CHANGELOG.md +15 -0
- package/package.json +5 -5
- package/.docs/docs/agents/adding-voice.md +0 -383
- package/.docs/docs/community/contributing-templates.md +0 -5
- package/.docs/docs/community/discord.md +0 -11
- package/.docs/guides/build-your-ui/copilotkit.md +0 -291
- package/LICENSE.md +0 -30
- /package/.docs/docs/{community/licensing.md → license.md} +0 -0
- /package/.docs/docs/{agents → long-running-agents}/signals.md +0 -0
|
@@ -1,383 +0,0 @@
|
|
|
1
|
-
> Discover all available pages from the documentation index: https://mastra.ai/llms.txt
|
|
2
|
-
|
|
3
|
-
# Voice
|
|
4
|
-
|
|
5
|
-
Mastra agents can be enhanced with voice capabilities, allowing them to speak responses and listen to user input. You can configure an agent to use either a single voice provider or combine multiple providers for different operations.
|
|
6
|
-
|
|
7
|
-
## Basic usage
|
|
8
|
-
|
|
9
|
-
The simplest way to add voice to an agent is to use a single provider for both speaking and listening:
|
|
10
|
-
|
|
11
|
-
```typescript
|
|
12
|
-
import { createReadStream } from 'fs'
|
|
13
|
-
import path from 'path'
|
|
14
|
-
import { Agent } from '@mastra/core/agent'
|
|
15
|
-
import { OpenAIVoice } from '@mastra/voice-openai'
|
|
16
|
-
|
|
17
|
-
// Initialize the voice provider with default settings
|
|
18
|
-
const voice = new OpenAIVoice()
|
|
19
|
-
|
|
20
|
-
// Create an agent with voice capabilities
|
|
21
|
-
export const agent = new Agent({
|
|
22
|
-
id: 'voice-agent',
|
|
23
|
-
name: 'Voice Agent',
|
|
24
|
-
instructions: `You are a helpful assistant with both STT and TTS capabilities.`,
|
|
25
|
-
model: 'openai/gpt-5.5',
|
|
26
|
-
voice,
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
// The agent can now use voice for interaction
|
|
30
|
-
const audioStream = await agent.voice.speak("Hello, I'm your AI assistant!", {
|
|
31
|
-
filetype: 'm4a',
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
playAudio(audioStream!)
|
|
35
|
-
|
|
36
|
-
try {
|
|
37
|
-
const transcription = await agent.voice.listen(audioStream)
|
|
38
|
-
console.log(transcription)
|
|
39
|
-
} catch (error) {
|
|
40
|
-
console.error('Error transcribing audio:', error)
|
|
41
|
-
}
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
## Working with audio streams
|
|
45
|
-
|
|
46
|
-
The `speak()` and `listen()` methods work with Node.js streams. Here's how to save and load audio files:
|
|
47
|
-
|
|
48
|
-
### Saving Speech Output
|
|
49
|
-
|
|
50
|
-
The `speak` method returns a stream that you can pipe to a file or speaker.
|
|
51
|
-
|
|
52
|
-
```typescript
|
|
53
|
-
import { createWriteStream } from 'fs'
|
|
54
|
-
import path from 'path'
|
|
55
|
-
|
|
56
|
-
// Generate speech and save to file
|
|
57
|
-
const audio = await agent.voice.speak('Hello, World!')
|
|
58
|
-
const filePath = path.join(process.cwd(), 'agent.mp3')
|
|
59
|
-
const writer = createWriteStream(filePath)
|
|
60
|
-
|
|
61
|
-
audio.pipe(writer)
|
|
62
|
-
|
|
63
|
-
await new Promise<void>((resolve, reject) => {
|
|
64
|
-
writer.on('finish', () => resolve())
|
|
65
|
-
writer.on('error', reject)
|
|
66
|
-
})
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
### Transcribing Audio Input
|
|
70
|
-
|
|
71
|
-
The `listen` method expects a stream of audio data from a microphone or file.
|
|
72
|
-
|
|
73
|
-
```typescript
|
|
74
|
-
import { createReadStream } from 'fs'
|
|
75
|
-
import path from 'path'
|
|
76
|
-
|
|
77
|
-
// Read audio file and transcribe
|
|
78
|
-
const audioFilePath = path.join(process.cwd(), '/agent.m4a')
|
|
79
|
-
const audioStream = createReadStream(audioFilePath)
|
|
80
|
-
|
|
81
|
-
try {
|
|
82
|
-
console.log('Transcribing audio file...')
|
|
83
|
-
const transcription = await agent.voice.listen(audioStream, {
|
|
84
|
-
filetype: 'm4a',
|
|
85
|
-
})
|
|
86
|
-
console.log('Transcription:', transcription)
|
|
87
|
-
} catch (error) {
|
|
88
|
-
console.error('Error transcribing audio:', error)
|
|
89
|
-
}
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
## Speech-to-speech voice interactions
|
|
93
|
-
|
|
94
|
-
For more dynamic and interactive voice experiences, you can use real-time voice providers that support speech-to-speech capabilities:
|
|
95
|
-
|
|
96
|
-
```typescript
|
|
97
|
-
import { Agent } from '@mastra/core/agent'
|
|
98
|
-
import { getMicrophoneStream } from '@mastra/node-audio'
|
|
99
|
-
import { OpenAIRealtimeVoice } from '@mastra/voice-openai-realtime'
|
|
100
|
-
import { search, calculate } from '../tools'
|
|
101
|
-
|
|
102
|
-
// Initialize the realtime voice provider
|
|
103
|
-
const voice = new OpenAIRealtimeVoice({
|
|
104
|
-
apiKey: process.env.OPENAI_API_KEY,
|
|
105
|
-
model: 'gpt-5.1-realtime',
|
|
106
|
-
speaker: 'alloy',
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
// Create an agent with speech-to-speech voice capabilities
|
|
110
|
-
export const agent = new Agent({
|
|
111
|
-
id: 'speech-to-speech-agent',
|
|
112
|
-
name: 'Speech-to-Speech Agent',
|
|
113
|
-
instructions: `You are a helpful assistant with speech-to-speech capabilities.`,
|
|
114
|
-
model: 'openai/gpt-5.5',
|
|
115
|
-
tools: {
|
|
116
|
-
// Tools configured on Agent are passed to voice provider
|
|
117
|
-
search,
|
|
118
|
-
calculate,
|
|
119
|
-
},
|
|
120
|
-
voice,
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
// Establish a WebSocket connection
|
|
124
|
-
await agent.voice.connect()
|
|
125
|
-
|
|
126
|
-
// Start a conversation
|
|
127
|
-
agent.voice.speak("Hello, I'm your AI assistant!")
|
|
128
|
-
|
|
129
|
-
// Stream audio from a microphone
|
|
130
|
-
const microphoneStream = getMicrophoneStream()
|
|
131
|
-
agent.voice.send(microphoneStream)
|
|
132
|
-
|
|
133
|
-
// When done with the conversation
|
|
134
|
-
agent.voice.close()
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
### Per-session voice for concurrent sessions
|
|
138
|
-
|
|
139
|
-
A static `voice` instance is shared across every request. For one-shot text-to-speech this is fine, but realtime and speech-to-speech providers store one WebSocket, one set of tools, and one request context per instance. If you deploy a single agent that handles several live sessions at once, a shared instance lets one session overwrite another session's tools, instructions, and request context.
|
|
140
|
-
|
|
141
|
-
To give each session its own voice, provide `voice` as a resolver. Mastra runs the resolver on every `getVoice()` call and returns a fresh, session-owned instance:
|
|
142
|
-
|
|
143
|
-
```typescript
|
|
144
|
-
import { Agent } from '@mastra/core/agent'
|
|
145
|
-
import { OpenAIRealtimeVoice } from '@mastra/voice-openai-realtime'
|
|
146
|
-
|
|
147
|
-
export const agent = new Agent({
|
|
148
|
-
id: 'support-line',
|
|
149
|
-
name: 'Support Line',
|
|
150
|
-
instructions: ({ requestContext }) => `Help user ${requestContext.get('user')}.`,
|
|
151
|
-
model: 'openai/gpt-5.5',
|
|
152
|
-
voice: ({ requestContext }) => new OpenAIRealtimeVoice({ apiKey: requestContext.get('apiKey') }),
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
// Each concurrent session resolves its own voice instance
|
|
156
|
-
const voice = await agent.getVoice({ requestContext })
|
|
157
|
-
await voice.connect()
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
When you use a resolver:
|
|
161
|
-
|
|
162
|
-
- Each call to `getVoice()` returns a new instance, so concurrent sessions never share state.
|
|
163
|
-
- Mastra doesn't add tools or instructions to a resolver instance. Configure those inside the resolver or on the provider.
|
|
164
|
-
- You own the lifecycle of the returned instance, so call `disconnect()` or `close()` when the session ends.
|
|
165
|
-
|
|
166
|
-
The `agent.voice` getter has no request context, so it throws when `voice` is a resolver. Use `agent.getVoice({ requestContext })` instead.
|
|
167
|
-
|
|
168
|
-
### Event System
|
|
169
|
-
|
|
170
|
-
The realtime voice provider emits several events you can listen for:
|
|
171
|
-
|
|
172
|
-
```typescript
|
|
173
|
-
// Listen for speech audio data sent from voice provider
|
|
174
|
-
agent.voice.on('speaking', ({ audio }) => {
|
|
175
|
-
// audio contains ReadableStream or Int16Array audio data
|
|
176
|
-
})
|
|
177
|
-
|
|
178
|
-
// Listen for transcribed text sent from both voice provider and user
|
|
179
|
-
agent.voice.on('writing', ({ text, role }) => {
|
|
180
|
-
console.log(`${role} said: ${text}`)
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
// Listen for errors
|
|
184
|
-
agent.voice.on('error', error => {
|
|
185
|
-
console.error('Voice error:', error)
|
|
186
|
-
})
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
## Examples
|
|
190
|
-
|
|
191
|
-
### End-to-end voice interaction
|
|
192
|
-
|
|
193
|
-
This example demonstrates a voice interaction between two agents. The hybrid voice agent, which uses multiple providers, speaks a question, which is saved as an audio file. The unified voice agent listens to that file, processes the question, generates a response, and speaks it back. Both audio outputs are saved to the `audio` directory.
|
|
194
|
-
|
|
195
|
-
The following files are created:
|
|
196
|
-
|
|
197
|
-
- **hybrid-question.mp3** – Hybrid agent's spoken question.
|
|
198
|
-
- **unified-response.mp3** – Unified agent's spoken response.
|
|
199
|
-
|
|
200
|
-
```typescript
|
|
201
|
-
import 'dotenv/config'
|
|
202
|
-
|
|
203
|
-
import path from 'path'
|
|
204
|
-
import { createReadStream } from 'fs'
|
|
205
|
-
import { Agent } from '@mastra/core/agent'
|
|
206
|
-
import { CompositeVoice } from '@mastra/core/voice'
|
|
207
|
-
import { OpenAIVoice } from '@mastra/voice-openai'
|
|
208
|
-
import { Mastra } from '@mastra/core'
|
|
209
|
-
|
|
210
|
-
// Saves an audio stream to a file in the audio directory, creating the directory if it doesn't exist.
|
|
211
|
-
export const saveAudioToFile = async (
|
|
212
|
-
audio: NodeJS.ReadableStream,
|
|
213
|
-
filename: string,
|
|
214
|
-
): Promise<void> => {
|
|
215
|
-
const audioDir = path.join(process.cwd(), 'audio')
|
|
216
|
-
const filePath = path.join(audioDir, filename)
|
|
217
|
-
|
|
218
|
-
await fs.promises.mkdir(audioDir, { recursive: true })
|
|
219
|
-
|
|
220
|
-
const writer = createWriteStream(filePath)
|
|
221
|
-
audio.pipe(writer)
|
|
222
|
-
return new Promise((resolve, reject) => {
|
|
223
|
-
writer.on('finish', resolve)
|
|
224
|
-
writer.on('error', reject)
|
|
225
|
-
})
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// Saves an audio stream to a file in the audio directory, creating the directory if it doesn't exist.
|
|
229
|
-
export const convertToText = async (input: string | NodeJS.ReadableStream): Promise<string> => {
|
|
230
|
-
if (typeof input === 'string') {
|
|
231
|
-
return input
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
const chunks: Buffer[] = []
|
|
235
|
-
return new Promise((resolve, reject) => {
|
|
236
|
-
inputData.on('data', chunk => chunks.push(Buffer.from(chunk)))
|
|
237
|
-
inputData.on('error', reject)
|
|
238
|
-
inputData.on('end', () => resolve(Buffer.concat(chunks).toString('utf-8')))
|
|
239
|
-
})
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
export const hybridVoiceAgent = new Agent({
|
|
243
|
-
id: 'hybrid-voice-agent',
|
|
244
|
-
name: 'Hybrid Voice Agent',
|
|
245
|
-
model: 'openai/gpt-5.5',
|
|
246
|
-
instructions: 'You can speak and listen using different providers.',
|
|
247
|
-
voice: new CompositeVoice({
|
|
248
|
-
input: new OpenAIVoice(),
|
|
249
|
-
output: new OpenAIVoice(),
|
|
250
|
-
}),
|
|
251
|
-
})
|
|
252
|
-
|
|
253
|
-
export const unifiedVoiceAgent = new Agent({
|
|
254
|
-
id: 'unified-voice-agent',
|
|
255
|
-
name: 'Unified Voice Agent',
|
|
256
|
-
instructions: 'You are an agent with both STT and TTS capabilities.',
|
|
257
|
-
model: 'openai/gpt-5.5',
|
|
258
|
-
voice: new OpenAIVoice(),
|
|
259
|
-
})
|
|
260
|
-
|
|
261
|
-
export const mastra = new Mastra({
|
|
262
|
-
agents: { hybridVoiceAgent, unifiedVoiceAgent },
|
|
263
|
-
})
|
|
264
|
-
|
|
265
|
-
const hybridVoiceAgent = mastra.getAgent('hybridVoiceAgent')
|
|
266
|
-
const unifiedVoiceAgent = mastra.getAgent('unifiedVoiceAgent')
|
|
267
|
-
|
|
268
|
-
const question = 'What is the meaning of life in one sentence?'
|
|
269
|
-
|
|
270
|
-
const hybridSpoken = await hybridVoiceAgent.voice.speak(question)
|
|
271
|
-
|
|
272
|
-
await saveAudioToFile(hybridSpoken!, 'hybrid-question.mp3')
|
|
273
|
-
|
|
274
|
-
const audioStream = createReadStream(path.join(process.cwd(), 'audio', 'hybrid-question.mp3'))
|
|
275
|
-
const unifiedHeard = await unifiedVoiceAgent.voice.listen(audioStream)
|
|
276
|
-
|
|
277
|
-
const inputText = await convertToText(unifiedHeard!)
|
|
278
|
-
|
|
279
|
-
const unifiedResponse = await unifiedVoiceAgent.generate(inputText)
|
|
280
|
-
const unifiedSpoken = await unifiedVoiceAgent.voice.speak(unifiedResponse.text)
|
|
281
|
-
|
|
282
|
-
await saveAudioToFile(unifiedSpoken!, 'unified-response.mp3')
|
|
283
|
-
```
|
|
284
|
-
|
|
285
|
-
### Using Multiple Providers
|
|
286
|
-
|
|
287
|
-
For more flexibility, you can use different providers for speaking and listening using the CompositeVoice class:
|
|
288
|
-
|
|
289
|
-
```typescript
|
|
290
|
-
import { Agent } from '@mastra/core/agent'
|
|
291
|
-
import { CompositeVoice } from '@mastra/core/voice'
|
|
292
|
-
import { OpenAIVoice } from '@mastra/voice-openai'
|
|
293
|
-
import { PlayAIVoice } from '@mastra/voice-playai'
|
|
294
|
-
|
|
295
|
-
export const agent = new Agent({
|
|
296
|
-
id: 'voice-agent',
|
|
297
|
-
name: 'Voice Agent',
|
|
298
|
-
instructions: `You are a helpful assistant with both STT and TTS capabilities.`,
|
|
299
|
-
model: 'openai/gpt-5.5',
|
|
300
|
-
|
|
301
|
-
// Create a composite voice using OpenAI for listening and PlayAI for speaking
|
|
302
|
-
voice: new CompositeVoice({
|
|
303
|
-
input: new OpenAIVoice(),
|
|
304
|
-
output: new PlayAIVoice(),
|
|
305
|
-
}),
|
|
306
|
-
})
|
|
307
|
-
```
|
|
308
|
-
|
|
309
|
-
### Using AI SDK
|
|
310
|
-
|
|
311
|
-
Mastra supports using AI SDK's transcription and speech models directly in `CompositeVoice`, giving you access to a wide range of providers through the AI SDK ecosystem:
|
|
312
|
-
|
|
313
|
-
```typescript
|
|
314
|
-
import { Agent } from '@mastra/core/agent'
|
|
315
|
-
import { CompositeVoice } from '@mastra/core/voice'
|
|
316
|
-
import { openai } from '@ai-sdk/openai'
|
|
317
|
-
import { elevenlabs } from '@ai-sdk/elevenlabs'
|
|
318
|
-
import { groq } from '@ai-sdk/groq'
|
|
319
|
-
|
|
320
|
-
export const agent = new Agent({
|
|
321
|
-
id: 'aisdk-voice-agent',
|
|
322
|
-
name: 'AI SDK Voice Agent',
|
|
323
|
-
instructions: `You are a helpful assistant with voice capabilities.`,
|
|
324
|
-
model: 'openai/gpt-5.5',
|
|
325
|
-
|
|
326
|
-
// Pass AI SDK models directly to CompositeVoice
|
|
327
|
-
voice: new CompositeVoice({
|
|
328
|
-
input: openai.transcription('whisper-1'), // AI SDK transcription model
|
|
329
|
-
output: elevenlabs.speech('eleven_turbo_v2'), // AI SDK speech model
|
|
330
|
-
}),
|
|
331
|
-
})
|
|
332
|
-
|
|
333
|
-
// Use voice capabilities as usual
|
|
334
|
-
const audioStream = await agent.voice.speak('Hello!')
|
|
335
|
-
const transcribedText = await agent.voice.listen(audioStream)
|
|
336
|
-
```
|
|
337
|
-
|
|
338
|
-
#### Mix and Match Providers
|
|
339
|
-
|
|
340
|
-
You can mix AI SDK models with Mastra voice providers:
|
|
341
|
-
|
|
342
|
-
```typescript
|
|
343
|
-
import { CompositeVoice } from '@mastra/core/voice'
|
|
344
|
-
import { PlayAIVoice } from '@mastra/voice-playai'
|
|
345
|
-
import { openai } from '@ai-sdk/openai'
|
|
346
|
-
|
|
347
|
-
// Use AI SDK for transcription and Mastra provider for speech
|
|
348
|
-
const voice = new CompositeVoice({
|
|
349
|
-
input: openai.transcription('whisper-1'), // AI SDK
|
|
350
|
-
output: new PlayAIVoice(), // Mastra provider
|
|
351
|
-
})
|
|
352
|
-
```
|
|
353
|
-
|
|
354
|
-
For the complete list of supported AI SDK providers and their capabilities:
|
|
355
|
-
|
|
356
|
-
- [Transcription](https://ai-sdk.dev/docs/providers/openai/transcription)
|
|
357
|
-
- [Speech](https://ai-sdk.dev/docs/providers/elevenlabs/speech)
|
|
358
|
-
|
|
359
|
-
## Supported voice providers
|
|
360
|
-
|
|
361
|
-
Mastra supports multiple voice providers for text-to-speech (TTS) and speech-to-text (STT) capabilities:
|
|
362
|
-
|
|
363
|
-
| Provider | Package | Features | Reference |
|
|
364
|
-
| --------------- | ------------------------------- | ----------------------------------------- | ------------------------------------------------------------------ |
|
|
365
|
-
| OpenAI | `@mastra/voice-openai` | TTS, STT | [Documentation](https://mastra.ai/reference/voice/openai) |
|
|
366
|
-
| OpenAI Realtime | `@mastra/voice-openai-realtime` | Realtime speech-to-speech | [Documentation](https://mastra.ai/reference/voice/openai-realtime) |
|
|
367
|
-
| AWS Nova Sonic | `@mastra/voice-aws-nova-sonic` | Realtime speech-to-speech via AWS Bedrock | [Documentation](https://mastra.ai/reference/voice/aws-nova-sonic) |
|
|
368
|
-
| ElevenLabs | `@mastra/voice-elevenlabs` | High-quality TTS | [Documentation](https://mastra.ai/reference/voice/elevenlabs) |
|
|
369
|
-
| PlayAI | `@mastra/voice-playai` | TTS | [Documentation](https://mastra.ai/reference/voice/playai) |
|
|
370
|
-
| Google | `@mastra/voice-google` | TTS, STT | [Documentation](https://mastra.ai/reference/voice/google) |
|
|
371
|
-
| Deepgram | `@mastra/voice-deepgram` | STT | [Documentation](https://mastra.ai/reference/voice/deepgram) |
|
|
372
|
-
| Murf | `@mastra/voice-murf` | TTS | [Documentation](https://mastra.ai/reference/voice/murf) |
|
|
373
|
-
| Speechify | `@mastra/voice-speechify` | TTS | [Documentation](https://mastra.ai/reference/voice/speechify) |
|
|
374
|
-
| Sarvam | `@mastra/voice-sarvam` | TTS, STT | [Documentation](https://mastra.ai/reference/voice/sarvam) |
|
|
375
|
-
| Azure | `@mastra/voice-azure` | TTS, STT | [Documentation](https://mastra.ai/reference/voice/mastra-voice) |
|
|
376
|
-
| Cloudflare | `@mastra/voice-cloudflare` | TTS | [Documentation](https://mastra.ai/reference/voice/mastra-voice) |
|
|
377
|
-
|
|
378
|
-
## Next steps
|
|
379
|
-
|
|
380
|
-
- [Voice API Reference](https://mastra.ai/reference/voice/mastra-voice): Detailed API documentation for voice capabilities
|
|
381
|
-
- [Text to Speech Examples](https://github.com/mastra-ai/voice-examples/tree/main/text-to-speech): Interactive story generator and other TTS implementations
|
|
382
|
-
- [Speech to Text Examples](https://github.com/mastra-ai/voice-examples/tree/main/speech-to-text): Voice memo app and other STT implementations
|
|
383
|
-
- [Speech to Speech Examples](https://github.com/mastra-ai/voice-examples/tree/main/speech-to-speech): Real-time voice conversation with call analysis
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
> Discover all available pages from the documentation index: https://mastra.ai/llms.txt
|
|
2
|
-
|
|
3
|
-
# Contributing templates
|
|
4
|
-
|
|
5
|
-
The Mastra community plays a vital role in creating templates that showcase innovative application patterns. We're currently reworking our template contribution process to ensure high-quality, valuable templates for the community. For the time being, we're not accepting new template contributions. Please keep an eye on this page for updates on when contributions will reopen and the new submission process.
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
> Discover all available pages from the documentation index: https://mastra.ai/llms.txt
|
|
2
|
-
|
|
3
|
-
# Discord community
|
|
4
|
-
|
|
5
|
-
The Discord server has over 1000 members and serves as the main discussion forum for Mastra. The Mastra team monitors Discord during North American and European business hours, with community members active across other time zones.
|
|
6
|
-
|
|
7
|
-
[Join the Discord server](https://discord.gg/BTYqqHKUrf)
|
|
8
|
-
|
|
9
|
-
## Discord MCP bot
|
|
10
|
-
|
|
11
|
-
In addition to community members, we've an (experimental!) Discord bot that can also help answer questions. It uses [Model Context Protocol (MCP)](https://mastra.ai/docs/mcp/overview). You can ask it a question with `/ask` (either in public channels or DMs) and clear history (in DMs only) with `/cleardm`.
|
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
> Discover all available pages from the documentation index: https://mastra.ai/llms.txt
|
|
2
|
-
|
|
3
|
-
# Using CopilotKit
|
|
4
|
-
|
|
5
|
-
[CopilotKit](https://www.copilotkit.ai/) provides React components to quickly integrate customizable AI copilots into your application. Combined with Mastra, you can build sophisticated AI apps featuring bidirectional state synchronization and interactive UIs.
|
|
6
|
-
|
|
7
|
-
Visit the [CopilotKit documentation](https://docs.copilotkit.ai/) to learn more about CopilotKit concepts, components, and advanced usage patterns.
|
|
8
|
-
|
|
9
|
-
> **Info:** For a full-stack integration approach where Mastra runs directly in your Next.js API routes, see the [CopilotKit Quickstart](https://docs.copilotkit.ai/mastra/quickstart) guide.
|
|
10
|
-
|
|
11
|
-
> **Tip:** Visit Mastra's [**"UI Dojo"**](https://ui-dojo.mastra.ai/) to see real-world examples of CopilotKit integrated with Mastra.
|
|
12
|
-
|
|
13
|
-
## Integration guide
|
|
14
|
-
|
|
15
|
-
Run Mastra as a standalone server and connect your Next.js frontend (with CopilotKit) to its API endpoints.
|
|
16
|
-
|
|
17
|
-
1. Set up your directory structure. A possible directory structure could look like this:
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
project-root
|
|
21
|
-
├── mastra-server
|
|
22
|
-
│ ├── src
|
|
23
|
-
│ │ └── mastra
|
|
24
|
-
│ └── package.json
|
|
25
|
-
└── my-copilot-app
|
|
26
|
-
└── package.json
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
Bootstrap your Mastra server:
|
|
30
|
-
|
|
31
|
-
**npm**:
|
|
32
|
-
|
|
33
|
-
```bash
|
|
34
|
-
npx create-mastra@latest
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
**pnpm**:
|
|
38
|
-
|
|
39
|
-
```bash
|
|
40
|
-
pnpm dlx create-mastra@latest
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
**Yarn**:
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
yarn dlx create-mastra@latest
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
**Bun**:
|
|
50
|
-
|
|
51
|
-
```bash
|
|
52
|
-
bun x create-mastra@latest
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
This command will launch an interactive wizard to help you scaffold a new Mastra project, including prompting you for a project name and setting up basic configurations. Follow the prompts to create your server project.
|
|
56
|
-
|
|
57
|
-
Navigate to your newly created Mastra server directory:
|
|
58
|
-
|
|
59
|
-
```bash
|
|
60
|
-
cd mastra-server # Replace with the actual directory name you provided
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
You now have a basic Mastra server project ready. You should have the following files and folders:
|
|
64
|
-
|
|
65
|
-
```bash
|
|
66
|
-
src
|
|
67
|
-
└── mastra
|
|
68
|
-
├── agents
|
|
69
|
-
│ └── weather-agent.ts
|
|
70
|
-
├── scorers
|
|
71
|
-
│ └── weather-scorer.ts
|
|
72
|
-
├── tools
|
|
73
|
-
│ └── weather-tool.ts
|
|
74
|
-
├── workflows
|
|
75
|
-
│ └── weather-workflow.ts
|
|
76
|
-
└── index.ts
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
> **Note:** Ensure that you have set the appropriate environment variables for your LLM provider in the `.env` file.
|
|
80
|
-
|
|
81
|
-
2. Create a chat route for the CopilotKit frontend by using the `registerCopilotKit()` helper from `@ag-ui/mastra`. Add it to your Mastra project (and its peer dependencies):
|
|
82
|
-
|
|
83
|
-
**npm**:
|
|
84
|
-
|
|
85
|
-
```bash
|
|
86
|
-
npm install @ag-ui/mastra @mastra/client-js @mastra/core @ag-ui/core @ag-ui/client @copilotkit/runtime
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
**pnpm**:
|
|
90
|
-
|
|
91
|
-
```bash
|
|
92
|
-
pnpm add @ag-ui/mastra @mastra/client-js @mastra/core @ag-ui/core @ag-ui/client @copilotkit/runtime
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
**Yarn**:
|
|
96
|
-
|
|
97
|
-
```bash
|
|
98
|
-
yarn add @ag-ui/mastra @mastra/client-js @mastra/core @ag-ui/core @ag-ui/client @copilotkit/runtime
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
**Bun**:
|
|
102
|
-
|
|
103
|
-
```bash
|
|
104
|
-
bun add @ag-ui/mastra @mastra/client-js @mastra/core @ag-ui/core @ag-ui/client @copilotkit/runtime
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
In your `src/mastra/index.ts` file, register the chat route:
|
|
108
|
-
|
|
109
|
-
```typescript
|
|
110
|
-
import { Mastra } from '@mastra/core/mastra'
|
|
111
|
-
import { registerCopilotKit } from '@ag-ui/mastra/copilotkit'
|
|
112
|
-
// Rest of the imports...
|
|
113
|
-
|
|
114
|
-
export const mastra = new Mastra({
|
|
115
|
-
// Rest of the configuration...
|
|
116
|
-
server: {
|
|
117
|
-
cors: {
|
|
118
|
-
origin: '*',
|
|
119
|
-
allowMethods: ['*'],
|
|
120
|
-
allowHeaders: ['*'],
|
|
121
|
-
},
|
|
122
|
-
apiRoutes: [
|
|
123
|
-
registerCopilotKit({
|
|
124
|
-
path: '/chat',
|
|
125
|
-
resourceId: 'weatherAgent',
|
|
126
|
-
}),
|
|
127
|
-
],
|
|
128
|
-
},
|
|
129
|
-
})
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
This will make the `weatherAgent` available at `/chat` in a CopilotKit-compatible format. You have to add the CORS configuration to allow the CopilotKit frontend to access the Mastra server. For production deployments, make sure to restrict the CORS origins to only your frontend domain.
|
|
133
|
-
|
|
134
|
-
3. Run the Mastra server using the following command:
|
|
135
|
-
|
|
136
|
-
**npm**:
|
|
137
|
-
|
|
138
|
-
```bash
|
|
139
|
-
npm run dev
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
**pnpm**:
|
|
143
|
-
|
|
144
|
-
```bash
|
|
145
|
-
pnpm run dev
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
**Yarn**:
|
|
149
|
-
|
|
150
|
-
```bash
|
|
151
|
-
yarn dev
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
**Bun**:
|
|
155
|
-
|
|
156
|
-
```bash
|
|
157
|
-
bun run dev
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
By default, the Mastra server will run on `http://localhost:4111`. Keep this server running for the next steps where we'll set up the CopilotKit frontend to connect to it.
|
|
161
|
-
|
|
162
|
-
4. Go up one directory to your project root.
|
|
163
|
-
|
|
164
|
-
```bash
|
|
165
|
-
cd ..
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
Create a new Next.js project with the name `my-copilot-app`:
|
|
169
|
-
|
|
170
|
-
**npm**:
|
|
171
|
-
|
|
172
|
-
```bash
|
|
173
|
-
npx create-next-app@latest my-copilot-app
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
**pnpm**:
|
|
177
|
-
|
|
178
|
-
```bash
|
|
179
|
-
pnpm dlx create-next-app@latest my-copilot-app
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
**Yarn**:
|
|
183
|
-
|
|
184
|
-
```bash
|
|
185
|
-
yarn dlx create-next-app@latest my-copilot-app
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
**Bun**:
|
|
189
|
-
|
|
190
|
-
```bash
|
|
191
|
-
bun x create-next-app@latest my-copilot-app
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
Navigate to your newly created Next.js project directory:
|
|
195
|
-
|
|
196
|
-
```bash
|
|
197
|
-
cd my-copilot-app
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
5. Install the CopilotKit UI packages which you'll use to display a chat interface:
|
|
201
|
-
|
|
202
|
-
**npm**:
|
|
203
|
-
|
|
204
|
-
```bash
|
|
205
|
-
npm install @copilotkit/react-ui @copilotkit/react-core
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
**pnpm**:
|
|
209
|
-
|
|
210
|
-
```bash
|
|
211
|
-
pnpm add @copilotkit/react-ui @copilotkit/react-core
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
**Yarn**:
|
|
215
|
-
|
|
216
|
-
```bash
|
|
217
|
-
yarn add @copilotkit/react-ui @copilotkit/react-core
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
**Bun**:
|
|
221
|
-
|
|
222
|
-
```bash
|
|
223
|
-
bun add @copilotkit/react-ui @copilotkit/react-core
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
Open the home route of the Next.js app (usually `app/page.tsx` or `src/app/page.tsx`) and replace the existing contents with the following code to set up a basic CopilotKit chat interface:
|
|
227
|
-
|
|
228
|
-
```typescript
|
|
229
|
-
import { CopilotChat } from '@copilotkit/react-ui'
|
|
230
|
-
import { CopilotKit } from '@copilotkit/react-core'
|
|
231
|
-
import '@copilotkit/react-ui/styles.css'
|
|
232
|
-
|
|
233
|
-
export default function Home() {
|
|
234
|
-
return (
|
|
235
|
-
<CopilotKit runtimeUrl="http://localhost:4111/chat" agent="weatherAgent">
|
|
236
|
-
<CopilotChat
|
|
237
|
-
labels={{
|
|
238
|
-
title: 'Weather Agent',
|
|
239
|
-
initial: 'Hi! 👋 Ask me about the weather, forecasts, and climate.',
|
|
240
|
-
}}
|
|
241
|
-
/>
|
|
242
|
-
</CopilotKit>
|
|
243
|
-
)
|
|
244
|
-
}
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
6. You're ready to connect the pieces! Make sure both the Mastra server and the CopilotKit frontend are running. Start the Next.js development server:
|
|
248
|
-
|
|
249
|
-
**npm**:
|
|
250
|
-
|
|
251
|
-
```bash
|
|
252
|
-
npm run dev
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
**pnpm**:
|
|
256
|
-
|
|
257
|
-
```bash
|
|
258
|
-
pnpm run dev
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
**Yarn**:
|
|
262
|
-
|
|
263
|
-
```bash
|
|
264
|
-
yarn dev
|
|
265
|
-
```
|
|
266
|
-
|
|
267
|
-
**Bun**:
|
|
268
|
-
|
|
269
|
-
```bash
|
|
270
|
-
bun run dev
|
|
271
|
-
```
|
|
272
|
-
|
|
273
|
-
You should now be able to chat with your agent in the browser.
|
|
274
|
-
|
|
275
|
-
Congratulations! You have successfully integrated Mastra with CopilotKit using a separate server approach. Your CopilotKit frontend now communicates with a standalone Mastra agent server.
|
|
276
|
-
|
|
277
|
-
## Deployment
|
|
278
|
-
|
|
279
|
-
When deploying your Mastra server with CopilotKit, you must exclude `@copilotkit/runtime` from the bundle. This package contains dependencies that aren't compatible with bundling and will cause 500 errors if included.
|
|
280
|
-
|
|
281
|
-
> **Note:** This issue doesn't occur during development with `mastra dev` since it doesn't require bundling. However, anyone running `mastra build` for deployment will encounter this issue.
|
|
282
|
-
|
|
283
|
-
Add the `@copilotkit/runtime` package to your bundler externals configuration:
|
|
284
|
-
|
|
285
|
-
```typescript
|
|
286
|
-
export const mastra = new Mastra({
|
|
287
|
-
bundler: {
|
|
288
|
-
externals: ['@copilotkit/runtime'],
|
|
289
|
-
},
|
|
290
|
-
})
|
|
291
|
-
```
|