@mastra/mcp-docs-server 1.1.8 → 1.1.9-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.
- package/.docs/docs/agents/agent-memory.md +2 -2
- package/.docs/docs/agents/guardrails.md +3 -3
- package/.docs/docs/agents/network-approval.md +4 -1
- package/.docs/docs/agents/networks.md +1 -1
- package/.docs/docs/agents/overview.md +1 -1
- package/.docs/docs/agents/processors.md +35 -17
- package/.docs/docs/agents/structured-output.md +1 -1
- package/.docs/docs/agents/using-tools.md +2 -2
- package/.docs/docs/build-with-ai/mcp-docs-server.md +4 -4
- package/.docs/docs/build-with-ai/skills.md +1 -1
- package/.docs/docs/community/discord.md +1 -1
- package/.docs/docs/community/licensing.md +1 -1
- package/.docs/docs/deployment/mastra-server.md +1 -1
- package/.docs/docs/deployment/studio.md +2 -2
- package/.docs/docs/deployment/web-framework.md +1 -1
- package/.docs/docs/evals/overview.md +1 -1
- package/.docs/docs/getting-started/build-with-ai.md +1 -1
- package/.docs/docs/getting-started/project-structure.md +1 -1
- package/.docs/docs/index.md +62 -16
- package/.docs/docs/mastra-cloud/deployment.md +1 -1
- package/.docs/docs/mastra-cloud/studio.md +1 -1
- package/.docs/docs/mcp/publishing-mcp-server.md +1 -1
- package/.docs/docs/memory/memory-processors.md +1 -1
- package/.docs/docs/memory/message-history.md +2 -2
- package/.docs/docs/memory/observational-memory.md +6 -2
- package/.docs/docs/memory/semantic-recall.md +2 -2
- package/.docs/docs/memory/storage.md +1 -1
- package/.docs/docs/memory/working-memory.md +6 -6
- package/.docs/docs/observability/tracing/bridges/otel.md +2 -2
- package/.docs/docs/observability/tracing/exporters/default.md +1 -1
- package/.docs/docs/observability/tracing/overview.md +4 -4
- package/.docs/docs/observability/tracing/processors/sensitive-data-filter.md +2 -2
- package/.docs/docs/rag/chunking-and-embedding.md +1 -1
- package/.docs/docs/rag/vector-databases.md +2 -2
- package/.docs/docs/server/auth/auth0.md +1 -1
- package/.docs/docs/server/auth/firebase.md +1 -1
- package/.docs/docs/server/auth/simple-auth.md +1 -1
- package/.docs/docs/server/auth.md +1 -1
- package/.docs/docs/server/mastra-client.md +1 -1
- package/.docs/docs/server/mastra-server.md +1 -1
- package/.docs/docs/server/server-adapters.md +2 -2
- package/.docs/docs/streaming/events.md +1 -1
- package/.docs/docs/streaming/overview.md +1 -1
- package/.docs/docs/streaming/tool-streaming.md +44 -30
- package/.docs/docs/streaming/workflow-streaming.md +1 -1
- package/.docs/docs/workflows/control-flow.md +44 -2
- package/.docs/docs/workflows/error-handling.md +1 -1
- package/.docs/docs/workflows/overview.md +3 -3
- package/.docs/docs/workflows/snapshots.md +1 -1
- package/.docs/docs/workflows/time-travel.md +2 -2
- package/.docs/docs/workspace/filesystem.md +2 -2
- package/.docs/docs/workspace/overview.md +52 -7
- package/.docs/docs/workspace/sandbox.md +72 -13
- package/.docs/docs/workspace/skills.md +2 -2
- package/.docs/guides/build-your-ui/copilotkit.md +1 -1
- package/.docs/guides/deployment/inngest.md +4 -4
- package/.docs/guides/guide/ai-recruiter.md +1 -1
- package/.docs/guides/guide/github-actions-pr-description.md +2 -2
- package/.docs/guides/guide/notes-mcp-server.md +1 -1
- package/.docs/guides/guide/stock-agent.md +2 -2
- package/.docs/guides/migrations/agentnetwork.md +1 -1
- package/.docs/guides/migrations/upgrade-to-v1/client.md +2 -2
- package/.docs/guides/migrations/upgrade-to-v1/deployment.md +1 -1
- package/.docs/guides/migrations/upgrade-to-v1/memory.md +2 -2
- package/.docs/guides/migrations/upgrade-to-v1/storage.md +1 -1
- package/.docs/guides/migrations/upgrade-to-v1/tools.md +2 -2
- package/.docs/guides/migrations/upgrade-to-v1/workflows.md +5 -5
- package/.docs/guides/migrations/vnext-to-standard-apis.md +2 -2
- package/.docs/models/gateways/netlify.md +1 -2
- package/.docs/models/gateways/openrouter.md +8 -1
- package/.docs/models/gateways/vercel.md +3 -1
- package/.docs/models/index.md +1 -1
- package/.docs/models/providers/abacus.md +21 -11
- package/.docs/models/providers/aihubmix.md +7 -2
- package/.docs/models/providers/alibaba-cn.md +80 -71
- package/.docs/models/providers/alibaba-coding-plan-cn.md +78 -0
- package/.docs/models/providers/alibaba-coding-plan.md +78 -0
- package/.docs/models/providers/chutes.md +1 -1
- package/.docs/models/providers/clarifai.md +81 -0
- package/.docs/models/providers/cloudferro-sherlock.md +5 -4
- package/.docs/models/providers/cloudflare-workers-ai.md +3 -2
- package/.docs/models/providers/cortecs.md +7 -5
- package/.docs/models/providers/deepinfra.md +7 -2
- package/.docs/models/providers/deepseek.md +1 -1
- package/.docs/models/providers/drun.md +73 -0
- package/.docs/models/providers/firmware.md +28 -20
- package/.docs/models/providers/google.md +3 -1
- package/.docs/models/providers/inception.md +4 -2
- package/.docs/models/providers/kilo.md +3 -1
- package/.docs/models/providers/nano-gpt.md +519 -40
- package/.docs/models/providers/nebius.md +34 -34
- package/.docs/models/providers/nvidia.md +4 -2
- package/.docs/models/providers/ollama-cloud.md +1 -2
- package/.docs/models/providers/openai.md +3 -1
- package/.docs/models/providers/opencode.md +36 -33
- package/.docs/models/providers/poe.md +8 -2
- package/.docs/models/providers/qiniu-ai.md +20 -5
- package/.docs/models/providers/requesty.md +17 -1
- package/.docs/models/providers/siliconflow-cn.md +7 -1
- package/.docs/models/providers/togetherai.md +1 -3
- package/.docs/models/providers/xai.md +28 -25
- package/.docs/models/providers/xiaomi.md +1 -1
- package/.docs/models/providers/zenmux.md +3 -1
- package/.docs/models/providers.md +4 -0
- package/.docs/reference/agents/getDefaultGenerateOptions.md +1 -1
- package/.docs/reference/agents/getDefaultOptions.md +1 -1
- package/.docs/reference/agents/getDefaultStreamOptions.md +1 -1
- package/.docs/reference/agents/getDescription.md +1 -1
- package/.docs/reference/agents/network.md +3 -1
- package/.docs/reference/ai-sdk/handle-chat-stream.md +2 -0
- package/.docs/reference/ai-sdk/handle-network-stream.md +2 -0
- package/.docs/reference/ai-sdk/network-route.md +2 -0
- package/.docs/reference/ai-sdk/to-ai-sdk-v4-messages.md +1 -1
- package/.docs/reference/ai-sdk/to-ai-sdk-v5-messages.md +1 -1
- package/.docs/reference/auth/auth0.md +3 -3
- package/.docs/reference/auth/firebase.md +1 -1
- package/.docs/reference/auth/workos.md +2 -2
- package/.docs/reference/cli/mastra.md +4 -4
- package/.docs/reference/client-js/mastra-client.md +1 -1
- package/.docs/reference/configuration.md +62 -6
- package/.docs/reference/core/getDeployer.md +1 -1
- package/.docs/reference/core/getLogger.md +1 -1
- package/.docs/reference/core/getScorer.md +2 -2
- package/.docs/reference/core/getServer.md +1 -1
- package/.docs/reference/core/getStorage.md +1 -1
- package/.docs/reference/core/getStoredAgentById.md +1 -1
- package/.docs/reference/core/getTelemetry.md +1 -1
- package/.docs/reference/core/getWorkflow.md +1 -1
- package/.docs/reference/core/listAgents.md +1 -1
- package/.docs/reference/core/listMCPServers.md +1 -1
- package/.docs/reference/core/listStoredAgents.md +1 -1
- package/.docs/reference/core/listVectors.md +1 -1
- package/.docs/reference/core/mastra-class.md +1 -1
- package/.docs/reference/core/setLogger.md +1 -1
- package/.docs/reference/core/setStorage.md +1 -1
- package/.docs/reference/datasets/dataset.md +1 -1
- package/.docs/reference/datasets/datasets-manager.md +1 -1
- package/.docs/reference/datasets/get.md +2 -2
- package/.docs/reference/datasets/getDetails.md +1 -1
- package/.docs/reference/datasets/listItems.md +1 -1
- package/.docs/reference/deployer/vercel.md +1 -1
- package/.docs/reference/evals/answer-relevancy.md +1 -1
- package/.docs/reference/evals/completeness.md +1 -1
- package/.docs/reference/evals/context-precision.md +3 -3
- package/.docs/reference/evals/context-relevance.md +1 -1
- package/.docs/reference/evals/hallucination.md +3 -9
- package/.docs/reference/evals/keyword-coverage.md +1 -1
- package/.docs/reference/evals/mastra-scorer.md +1 -1
- package/.docs/reference/evals/noise-sensitivity.md +2 -2
- package/.docs/reference/evals/textual-difference.md +1 -1
- package/.docs/reference/evals/tone-consistency.md +1 -1
- package/.docs/reference/evals/tool-call-accuracy.md +1 -1
- package/.docs/reference/harness/harness-class.md +4 -2
- package/.docs/reference/index.md +2 -0
- package/.docs/reference/memory/cloneThread.md +1 -1
- package/.docs/reference/memory/observational-memory.md +7 -5
- package/.docs/reference/observability/tracing/bridges/otel.md +1 -1
- package/.docs/reference/observability/tracing/processors/sensitive-data-filter.md +1 -1
- package/.docs/reference/observability/tracing/spans.md +2 -0
- package/.docs/reference/processors/message-history-processor.md +1 -1
- package/.docs/reference/processors/processor-interface.md +6 -2
- package/.docs/reference/processors/token-limiter-processor.md +2 -2
- package/.docs/reference/rag/metadata-filters.md +10 -10
- package/.docs/reference/server/create-route.md +2 -0
- package/.docs/reference/server/koa-adapter.md +1 -1
- package/.docs/reference/server/register-api-route.md +2 -2
- package/.docs/reference/storage/cloudflare-d1.md +3 -3
- package/.docs/reference/storage/cloudflare.md +1 -1
- package/.docs/reference/storage/convex.md +1 -1
- package/.docs/reference/storage/dynamodb.md +2 -2
- package/.docs/reference/storage/lance.md +2 -2
- package/.docs/reference/storage/mongodb.md +1 -1
- package/.docs/reference/storage/mssql.md +1 -1
- package/.docs/reference/storage/postgresql.md +2 -2
- package/.docs/reference/storage/upstash.md +1 -1
- package/.docs/reference/streaming/workflows/observeStream.md +1 -1
- package/.docs/reference/templates/overview.md +1 -1
- package/.docs/reference/tools/create-tool.md +1 -1
- package/.docs/reference/tools/mcp-server.md +4 -4
- package/.docs/reference/vectors/chroma.md +2 -2
- package/.docs/reference/vectors/couchbase.md +6 -6
- package/.docs/reference/vectors/pg.md +2 -0
- package/.docs/reference/vectors/s3vectors.md +5 -5
- package/.docs/reference/voice/azure.md +4 -2
- package/.docs/reference/voice/cloudflare.md +4 -2
- package/.docs/reference/voice/elevenlabs.md +1 -1
- package/.docs/reference/voice/google-gemini-live.md +2 -2
- package/.docs/reference/voice/google.md +3 -3
- package/.docs/reference/voice/mastra-voice.md +1 -1
- package/.docs/reference/voice/murf.md +2 -2
- package/.docs/reference/voice/openai-realtime.md +3 -1
- package/.docs/reference/voice/openai.md +7 -3
- package/.docs/reference/voice/playai.md +4 -2
- package/.docs/reference/voice/sarvam.md +3 -1
- package/.docs/reference/voice/speechify.md +6 -4
- package/.docs/reference/voice/voice.addInstructions.md +2 -2
- package/.docs/reference/voice/voice.addTools.md +1 -1
- package/.docs/reference/voice/voice.close.md +2 -2
- package/.docs/reference/voice/voice.connect.md +4 -2
- package/.docs/reference/voice/voice.events.md +2 -2
- package/.docs/reference/voice/voice.getSpeakers.md +1 -1
- package/.docs/reference/voice/voice.listen.md +11 -5
- package/.docs/reference/voice/voice.off.md +2 -2
- package/.docs/reference/voice/voice.on.md +2 -2
- package/.docs/reference/voice/voice.speak.md +14 -4
- package/.docs/reference/voice/voice.updateConfig.md +1 -1
- package/.docs/reference/workflows/run-methods/timeTravel.md +1 -1
- package/.docs/reference/workspace/blaxel-sandbox.md +164 -0
- package/.docs/reference/workspace/daytona-sandbox.md +48 -139
- package/.docs/reference/workspace/e2b-sandbox.md +39 -75
- package/.docs/reference/workspace/filesystem.md +24 -10
- package/.docs/reference/workspace/gcs-filesystem.md +20 -0
- package/.docs/reference/workspace/local-filesystem.md +23 -9
- package/.docs/reference/workspace/local-sandbox.md +23 -98
- package/.docs/reference/workspace/process-manager.md +296 -0
- package/.docs/reference/workspace/s3-filesystem.md +20 -0
- package/.docs/reference/workspace/sandbox.md +9 -1
- package/.docs/reference/workspace/workspace-class.md +93 -25
- package/CHANGELOG.md +8 -0
- package/dist/tools/course.d.ts +7 -27
- package/dist/tools/course.d.ts.map +1 -1
- package/dist/tools/docs.d.ts +6 -18
- package/dist/tools/docs.d.ts.map +1 -1
- package/dist/tools/embedded-docs.d.ts +12 -112
- package/dist/tools/embedded-docs.d.ts.map +1 -1
- package/dist/tools/migration.d.ts +6 -26
- package/dist/tools/migration.d.ts.map +1 -1
- package/package.json +7 -7
|
@@ -116,7 +116,9 @@ const buffer = await filesystem.readFile('/image.png', { encoding: 'binary' })
|
|
|
116
116
|
|
|
117
117
|
**path** (`string`): File path relative to basePath
|
|
118
118
|
|
|
119
|
-
**options
|
|
119
|
+
**options** (`Options`): Configuration options.
|
|
120
|
+
|
|
121
|
+
**options.encoding** (`'utf-8' | 'binary'`): Text or binary encoding
|
|
120
122
|
|
|
121
123
|
### `writeFile(path, content, options?)`
|
|
122
124
|
|
|
@@ -133,9 +135,11 @@ await filesystem.writeFile('/nested/path/file.md', content, { recursive: true })
|
|
|
133
135
|
|
|
134
136
|
**content** (`string | Buffer`): File content
|
|
135
137
|
|
|
136
|
-
**options
|
|
138
|
+
**options** (`Options`): Configuration options.
|
|
139
|
+
|
|
140
|
+
**options.recursive** (`boolean`): Create parent directories if they don't exist
|
|
137
141
|
|
|
138
|
-
**options.overwrite** (`boolean`): Overwrite existing file
|
|
142
|
+
**options.overwrite** (`boolean`): Overwrite existing file
|
|
139
143
|
|
|
140
144
|
### `appendFile(path, content)`
|
|
141
145
|
|
|
@@ -164,7 +168,9 @@ await filesystem.deleteFile('/docs/maybe.md', { force: true }) // Don't throw if
|
|
|
164
168
|
|
|
165
169
|
**path** (`string`): File path
|
|
166
170
|
|
|
167
|
-
**options
|
|
171
|
+
**options** (`Options`): Configuration options.
|
|
172
|
+
|
|
173
|
+
**options.force** (`boolean`): Don't throw error if file doesn't exist
|
|
168
174
|
|
|
169
175
|
### `copyFile(src, dest, options?)`
|
|
170
176
|
|
|
@@ -181,7 +187,9 @@ await filesystem.copyFile('/src/config.json', '/backup/config.json', { overwrite
|
|
|
181
187
|
|
|
182
188
|
**dest** (`string`): Destination file path
|
|
183
189
|
|
|
184
|
-
**options
|
|
190
|
+
**options** (`Options`): Configuration options.
|
|
191
|
+
|
|
192
|
+
**options.overwrite** (`boolean`): Overwrite destination if it exists
|
|
185
193
|
|
|
186
194
|
### `moveFile(src, dest, options?)`
|
|
187
195
|
|
|
@@ -198,7 +206,9 @@ await filesystem.moveFile('/temp/upload.txt', '/files/document.txt')
|
|
|
198
206
|
|
|
199
207
|
**dest** (`string`): Destination file path
|
|
200
208
|
|
|
201
|
-
**options
|
|
209
|
+
**options** (`Options`): Configuration options.
|
|
210
|
+
|
|
211
|
+
**options.overwrite** (`boolean`): Overwrite destination if it exists
|
|
202
212
|
|
|
203
213
|
### `mkdir(path, options?)`
|
|
204
214
|
|
|
@@ -213,7 +223,9 @@ await filesystem.mkdir('/deeply/nested/path', { recursive: true })
|
|
|
213
223
|
|
|
214
224
|
**path** (`string`): Directory path
|
|
215
225
|
|
|
216
|
-
**options
|
|
226
|
+
**options** (`Options`): Configuration options.
|
|
227
|
+
|
|
228
|
+
**options.recursive** (`boolean`): Create parent directories
|
|
217
229
|
|
|
218
230
|
### `rmdir(path, options?)`
|
|
219
231
|
|
|
@@ -228,9 +240,11 @@ await filesystem.rmdir('/docs/nested', { recursive: true })
|
|
|
228
240
|
|
|
229
241
|
**path** (`string`): Directory path
|
|
230
242
|
|
|
231
|
-
**options
|
|
243
|
+
**options** (`Options`): Configuration options.
|
|
244
|
+
|
|
245
|
+
**options.recursive** (`boolean`): Remove contents recursively
|
|
232
246
|
|
|
233
|
-
**options.force** (`boolean`): Don't throw if directory doesn't exist
|
|
247
|
+
**options.force** (`boolean`): Don't throw if directory doesn't exist
|
|
234
248
|
|
|
235
249
|
### `readdir(path, options?)`
|
|
236
250
|
|
|
@@ -82,104 +82,7 @@ Configuration options for native OS sandboxing (used with `isolation: 'seatbelt'
|
|
|
82
82
|
|
|
83
83
|
**workingDirectory** (`string`): The configured working directory
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
### `start()`
|
|
88
|
-
|
|
89
|
-
Initialize and start the sandbox. Creates the working directory and sets up seatbelt profiles if using native isolation.
|
|
90
|
-
|
|
91
|
-
```typescript
|
|
92
|
-
await sandbox.start()
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
Called automatically by `workspace.init()` or on first `executeCommand()` call.
|
|
96
|
-
|
|
97
|
-
### `stop()`
|
|
98
|
-
|
|
99
|
-
Stop the sandbox.
|
|
100
|
-
|
|
101
|
-
```typescript
|
|
102
|
-
await sandbox.stop()
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
### `destroy()`
|
|
106
|
-
|
|
107
|
-
Clean up sandbox resources. Removes seatbelt profiles if they were auto-generated.
|
|
108
|
-
|
|
109
|
-
```typescript
|
|
110
|
-
await sandbox.destroy()
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
Called by `workspace.destroy()`.
|
|
114
|
-
|
|
115
|
-
### `isReady()`
|
|
116
|
-
|
|
117
|
-
Check if the sandbox is ready for operations.
|
|
118
|
-
|
|
119
|
-
```typescript
|
|
120
|
-
const ready = await sandbox.isReady()
|
|
121
|
-
// true if status is 'running'
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
### `executeCommand(command, args?, options?)`
|
|
125
|
-
|
|
126
|
-
Execute a shell command in the sandbox.
|
|
127
|
-
|
|
128
|
-
```typescript
|
|
129
|
-
const listResult = await sandbox.executeCommand('ls', ['-la'])
|
|
130
|
-
const installResult = await sandbox.executeCommand('npm', ['install', 'lodash'], {
|
|
131
|
-
timeout: 60000,
|
|
132
|
-
env: { NODE_ENV: 'development' },
|
|
133
|
-
})
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
**Parameters:**
|
|
137
|
-
|
|
138
|
-
**command** (`string`): Command to execute
|
|
139
|
-
|
|
140
|
-
**args** (`string[]`): Command arguments
|
|
141
|
-
|
|
142
|
-
**options.timeout** (`number`): Execution timeout in milliseconds
|
|
143
|
-
|
|
144
|
-
**options.cwd** (`string`): Working directory for the command
|
|
145
|
-
|
|
146
|
-
**options.env** (`Record<string, string>`): Additional environment variables
|
|
147
|
-
|
|
148
|
-
**options.onStdout** (`(data: string) => void`): Callback for stdout streaming
|
|
149
|
-
|
|
150
|
-
**options.onStderr** (`(data: string) => void`): Callback for stderr streaming
|
|
151
|
-
|
|
152
|
-
### `getInfo()`
|
|
153
|
-
|
|
154
|
-
Get sandbox status and resource information.
|
|
155
|
-
|
|
156
|
-
```typescript
|
|
157
|
-
const info = await sandbox.getInfo()
|
|
158
|
-
// { status: 'running', resources: { ... } }
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
### `getInstructions(opts?)`
|
|
162
|
-
|
|
163
|
-
Returns a description of how this sandbox works. When assigned to an agent, this is injected into the agent's system message.
|
|
164
|
-
|
|
165
|
-
```typescript
|
|
166
|
-
const instructions = sandbox.getInstructions()
|
|
167
|
-
// 'Local command execution. Working directory: "/workspace".'
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
Pass `requestContext` to enable per-request customization when the `instructions` constructor option is a function:
|
|
171
|
-
|
|
172
|
-
```typescript
|
|
173
|
-
const instructions = sandbox.getInstructions({ requestContext })
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
**Parameters:**
|
|
177
|
-
|
|
178
|
-
**opts.requestContext** (`RequestContext`): Forwarded to the \`instructions\` function if one was provided in the constructor.
|
|
179
|
-
|
|
180
|
-
**Returns:** `string`
|
|
181
|
-
|
|
182
|
-
To override the default output, pass an `instructions` option to the constructor. See [constructor parameters](#constructor-parameters).
|
|
85
|
+
**processes** (`LocalProcessManager`): Background process manager. See \[SandboxProcessManager reference]\(/reference/workspace/process-manager).
|
|
183
86
|
|
|
184
87
|
## Path Resolution
|
|
185
88
|
|
|
@@ -209,6 +112,27 @@ const sandbox = new LocalSandbox({
|
|
|
209
112
|
|
|
210
113
|
Set `WORKSPACE_PATH` in your environment to an absolute path like `/home/user/my-project/workspace`. This ensures commands run from a consistent directory regardless of how you run your code.
|
|
211
114
|
|
|
115
|
+
## Background processes
|
|
116
|
+
|
|
117
|
+
`LocalSandbox` includes a built-in process manager for spawning and managing background processes. Processes run as child processes on the local machine using `child_process.spawn`.
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
const sandbox = new LocalSandbox({ workingDirectory: './workspace' })
|
|
121
|
+
await sandbox.start()
|
|
122
|
+
|
|
123
|
+
// Spawn a background process
|
|
124
|
+
const handle = await sandbox.processes.spawn('node server.js')
|
|
125
|
+
|
|
126
|
+
// Read output, send stdin, kill
|
|
127
|
+
console.log(handle.stdout)
|
|
128
|
+
await handle.sendStdin('input\n')
|
|
129
|
+
await handle.kill()
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
When native isolation is enabled (`seatbelt` or `bwrap`), spawned processes are also wrapped with the same isolation backend.
|
|
133
|
+
|
|
134
|
+
See [`SandboxProcessManager` reference](https://mastra.ai/reference/workspace/process-manager) for the full API.
|
|
135
|
+
|
|
212
136
|
## Static Methods
|
|
213
137
|
|
|
214
138
|
### `detectIsolation()`
|
|
@@ -296,6 +220,7 @@ This separation prevents sandboxed processes from reading or modifying their own
|
|
|
296
220
|
|
|
297
221
|
## Related
|
|
298
222
|
|
|
223
|
+
- [SandboxProcessManager reference](https://mastra.ai/reference/workspace/process-manager)
|
|
299
224
|
- [WorkspaceSandbox Interface](https://mastra.ai/reference/workspace/sandbox)
|
|
300
225
|
- [Workspace Class](https://mastra.ai/reference/workspace/workspace-class)
|
|
301
226
|
- [Workspace Overview](https://mastra.ai/docs/workspace/overview)
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
# SandboxProcessManager
|
|
2
|
+
|
|
3
|
+
**Added in:** `@mastra/core@1.7.0`
|
|
4
|
+
|
|
5
|
+
Abstract base class for managing background processes in sandboxes. Provides methods to spawn processes, list them, get handles by PID, and kill them.
|
|
6
|
+
|
|
7
|
+
[`BlaxelSandbox`](https://mastra.ai/reference/workspace/blaxel-sandbox), [`DaytonaSandbox`](https://mastra.ai/reference/workspace/daytona-sandbox), [`E2BSandbox`](https://mastra.ai/reference/workspace/e2b-sandbox), and [`LocalSandbox`](https://mastra.ai/reference/workspace/local-sandbox) all include built-in process managers. You don't need to instantiate this class directly unless you're building a custom sandbox provider.
|
|
8
|
+
|
|
9
|
+
## Usage example
|
|
10
|
+
|
|
11
|
+
Access the process manager through the sandbox's `processes` property:
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { LocalSandbox } from '@mastra/core/workspace'
|
|
15
|
+
|
|
16
|
+
const sandbox = new LocalSandbox({ workingDirectory: './workspace' })
|
|
17
|
+
await sandbox.start()
|
|
18
|
+
|
|
19
|
+
// Spawn a background process
|
|
20
|
+
const handle = await sandbox.processes.spawn('node server.js', {
|
|
21
|
+
env: { PORT: '3000' },
|
|
22
|
+
onStdout: data => console.log(data),
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
// List all tracked processes
|
|
26
|
+
const procs = await sandbox.processes.list()
|
|
27
|
+
|
|
28
|
+
// Get a handle by PID
|
|
29
|
+
const proc = await sandbox.processes.get(handle.pid)
|
|
30
|
+
|
|
31
|
+
// Kill a process
|
|
32
|
+
await sandbox.processes.kill(handle.pid)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Methods
|
|
36
|
+
|
|
37
|
+
### `spawn(command, options?)`
|
|
38
|
+
|
|
39
|
+
Spawn a background process. Returns a `ProcessHandle` immediately without waiting for the process to finish.
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
const handle = await sandbox.processes.spawn('npm run dev', {
|
|
43
|
+
cwd: '/app',
|
|
44
|
+
env: { NODE_ENV: 'development' },
|
|
45
|
+
onStdout: data => console.log(data),
|
|
46
|
+
})
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
**Parameters:**
|
|
50
|
+
|
|
51
|
+
**command** (`string`): The command to run. Interpreted by the shell.
|
|
52
|
+
|
|
53
|
+
**options** (`SpawnProcessOptions`): Optional settings for the spawned process.
|
|
54
|
+
|
|
55
|
+
**options.timeout** (`number`): Timeout in milliseconds. Kills the process if exceeded.
|
|
56
|
+
|
|
57
|
+
**options.env** (`NodeJS.ProcessEnv`): Environment variables for the process.
|
|
58
|
+
|
|
59
|
+
**options.cwd** (`string`): Working directory for the process.
|
|
60
|
+
|
|
61
|
+
**options.onStdout** (`(data: string) => void`): Callback for stdout chunks. Called as data arrives.
|
|
62
|
+
|
|
63
|
+
**options.onStderr** (`(data: string) => void`): Callback for stderr chunks. Called as data arrives.
|
|
64
|
+
|
|
65
|
+
**options.abortSignal** (`AbortSignal`): Signal to abort the process. When aborted, the process is killed.
|
|
66
|
+
|
|
67
|
+
**Returns:** `Promise<ProcessHandle>`
|
|
68
|
+
|
|
69
|
+
### `list()`
|
|
70
|
+
|
|
71
|
+
List all tracked processes. Returns info about each process including PID, running state, and exit code.
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
const procs = await sandbox.processes.list()
|
|
75
|
+
for (const proc of procs) {
|
|
76
|
+
console.log(proc.pid, proc.running, proc.exitCode)
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**Returns:** `Promise<ProcessInfo[]>`
|
|
81
|
+
|
|
82
|
+
### `get(pid)`
|
|
83
|
+
|
|
84
|
+
Get a handle to a process by PID. Returns `undefined` if the process isn't found or has already been dismissed.
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
const handle = await sandbox.processes.get(1234)
|
|
88
|
+
if (handle) {
|
|
89
|
+
console.log(handle.stdout)
|
|
90
|
+
await handle.kill()
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**Returns:** `Promise<ProcessHandle | undefined>`
|
|
95
|
+
|
|
96
|
+
### `kill(pid)`
|
|
97
|
+
|
|
98
|
+
Kill a process by PID. Waits for the process to terminate before returning. Returns `true` if the process was killed, `false` if it wasn't found.
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
const killed = await sandbox.processes.kill(handle.pid)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**Returns:** `Promise<boolean>`
|
|
105
|
+
|
|
106
|
+
## ProcessInfo
|
|
107
|
+
|
|
108
|
+
Information about a tracked process, returned by `list()`.
|
|
109
|
+
|
|
110
|
+
**pid** (`number`): Process ID.
|
|
111
|
+
|
|
112
|
+
**command** (`string`): The command that was executed.
|
|
113
|
+
|
|
114
|
+
**running** (`boolean`): Whether the process is still running.
|
|
115
|
+
|
|
116
|
+
**exitCode** (`number`): Exit code if the process has finished.
|
|
117
|
+
|
|
118
|
+
***
|
|
119
|
+
|
|
120
|
+
## ProcessHandle
|
|
121
|
+
|
|
122
|
+
Handle to a spawned background process. Provides methods to read output, send stdin, wait for completion, and kill the process.
|
|
123
|
+
|
|
124
|
+
You don't create `ProcessHandle` instances directly — they're returned by `spawn()` and `get()`.
|
|
125
|
+
|
|
126
|
+
### Usage example
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
const handle = await sandbox.processes.spawn('npm run dev', {
|
|
130
|
+
onStdout: data => console.log(data),
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
// Read accumulated output
|
|
134
|
+
console.log(handle.pid)
|
|
135
|
+
console.log(handle.stdout)
|
|
136
|
+
console.log(handle.stderr)
|
|
137
|
+
console.log(handle.exitCode) // undefined while running
|
|
138
|
+
|
|
139
|
+
// Wait for completion
|
|
140
|
+
const result = await handle.wait()
|
|
141
|
+
|
|
142
|
+
// Send stdin
|
|
143
|
+
await handle.sendStdin('input data\n')
|
|
144
|
+
|
|
145
|
+
// Kill the process
|
|
146
|
+
await handle.kill()
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Properties
|
|
150
|
+
|
|
151
|
+
**pid** (`number`): Process ID.
|
|
152
|
+
|
|
153
|
+
**stdout** (`string`): Accumulated stdout output so far.
|
|
154
|
+
|
|
155
|
+
**stderr** (`string`): Accumulated stderr output so far.
|
|
156
|
+
|
|
157
|
+
**exitCode** (`number | undefined`): Exit code. undefined while the process is still running.
|
|
158
|
+
|
|
159
|
+
**command** (`string | undefined`): The command that was spawned. Set automatically by the process manager.
|
|
160
|
+
|
|
161
|
+
**reader** (`Readable`): Readable stream of stdout. Useful for protocols like LSP or JSON-RPC that communicate over stdio.
|
|
162
|
+
|
|
163
|
+
**writer** (`Writable`): Writable stream to stdin. Useful for protocols like LSP or JSON-RPC that communicate over stdio.
|
|
164
|
+
|
|
165
|
+
### Methods
|
|
166
|
+
|
|
167
|
+
#### `wait(options?)`
|
|
168
|
+
|
|
169
|
+
Wait for the process to exit and return the result. Optionally pass `onStdout`/`onStderr` callbacks to stream output while waiting. Callbacks are automatically removed when `wait()` resolves.
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
// Simple wait
|
|
173
|
+
const result = await handle.wait()
|
|
174
|
+
console.log(result.success, result.exitCode, result.stdout)
|
|
175
|
+
|
|
176
|
+
// Wait with streaming
|
|
177
|
+
const result = await handle.wait({
|
|
178
|
+
onStdout: data => process.stdout.write(data),
|
|
179
|
+
onStderr: data => process.stderr.write(data),
|
|
180
|
+
})
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
**Parameters:**
|
|
184
|
+
|
|
185
|
+
**options** (`WaitOptions`): Optional settings for waiting.
|
|
186
|
+
|
|
187
|
+
**options.onStdout** (`(data: string) => void`): Callback for stdout chunks while waiting.
|
|
188
|
+
|
|
189
|
+
**options.onStderr** (`(data: string) => void`): Callback for stderr chunks while waiting.
|
|
190
|
+
|
|
191
|
+
**Returns:** `Promise<CommandResult>`
|
|
192
|
+
|
|
193
|
+
The `CommandResult` object contains:
|
|
194
|
+
|
|
195
|
+
**success** (`boolean`): true if exit code is 0.
|
|
196
|
+
|
|
197
|
+
**exitCode** (`number`): Numeric exit code.
|
|
198
|
+
|
|
199
|
+
**stdout** (`string`): Full stdout output.
|
|
200
|
+
|
|
201
|
+
**stderr** (`string`): Full stderr output.
|
|
202
|
+
|
|
203
|
+
**executionTimeMs** (`number`): Execution time in milliseconds.
|
|
204
|
+
|
|
205
|
+
**timedOut** (`boolean`): true if the process was killed due to timeout.
|
|
206
|
+
|
|
207
|
+
**killed** (`boolean`): true if the process was killed by a signal.
|
|
208
|
+
|
|
209
|
+
#### `kill()`
|
|
210
|
+
|
|
211
|
+
Kill the process. Returns `true` if the process was killed, `false` if it had already exited.
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
const killed = await handle.kill()
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
**Returns:** `Promise<boolean>`
|
|
218
|
+
|
|
219
|
+
#### `sendStdin(data)`
|
|
220
|
+
|
|
221
|
+
Send data to the process's stdin. Throws if the process has already exited or stdin isn't available.
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
await handle.sendStdin('console.log("hello")\n')
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
**Returns:** `Promise<void>`
|
|
228
|
+
|
|
229
|
+
## Stream interop
|
|
230
|
+
|
|
231
|
+
`ProcessHandle` exposes `reader` and `writer` properties for integration with Node.js stream-based protocols like LSP or JSON-RPC:
|
|
232
|
+
|
|
233
|
+
```typescript
|
|
234
|
+
import {
|
|
235
|
+
createMessageConnection,
|
|
236
|
+
StreamMessageReader,
|
|
237
|
+
StreamMessageWriter,
|
|
238
|
+
} from 'vscode-jsonrpc/node'
|
|
239
|
+
|
|
240
|
+
const handle = await sandbox.processes.spawn('typescript-language-server --stdio')
|
|
241
|
+
|
|
242
|
+
const connection = createMessageConnection(
|
|
243
|
+
new StreamMessageReader(handle.reader),
|
|
244
|
+
new StreamMessageWriter(handle.writer),
|
|
245
|
+
)
|
|
246
|
+
connection.listen()
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
## Building a custom process manager
|
|
250
|
+
|
|
251
|
+
To build a process manager for a custom sandbox provider, extend `SandboxProcessManager` and implement `spawn()` and `list()`. The base class automatically wraps your methods with `ensureRunning()` so the sandbox starts before any process operation.
|
|
252
|
+
|
|
253
|
+
```typescript
|
|
254
|
+
import { SandboxProcessManager, ProcessHandle } from '@mastra/core/workspace'
|
|
255
|
+
import type { ProcessInfo, SpawnProcessOptions } from '@mastra/core/workspace'
|
|
256
|
+
|
|
257
|
+
class MyProcessManager extends SandboxProcessManager<MySandbox> {
|
|
258
|
+
async spawn(command: string, options: SpawnProcessOptions = {}): Promise<ProcessHandle> {
|
|
259
|
+
// Your spawn implementation
|
|
260
|
+
const handle = new MyProcessHandle(/* ... */)
|
|
261
|
+
this._tracked.set(handle.pid, handle)
|
|
262
|
+
return handle
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
async list(): Promise<ProcessInfo[]> {
|
|
266
|
+
return Array.from(this._tracked.values()).map(handle => ({
|
|
267
|
+
pid: handle.pid,
|
|
268
|
+
running: handle.exitCode === undefined,
|
|
269
|
+
exitCode: handle.exitCode,
|
|
270
|
+
}))
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
Pass the process manager to your sandbox via the `processes` option in `MastraSandbox`:
|
|
276
|
+
|
|
277
|
+
```typescript
|
|
278
|
+
class MySandbox extends MastraSandbox {
|
|
279
|
+
constructor() {
|
|
280
|
+
super({
|
|
281
|
+
name: 'MySandbox',
|
|
282
|
+
processes: new MyProcessManager(),
|
|
283
|
+
})
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
When a process manager is provided, `MastraSandbox` automatically creates a default `executeCommand` implementation that uses `spawn()` + `wait()`, so you don't need to implement both.
|
|
289
|
+
|
|
290
|
+
## Related
|
|
291
|
+
|
|
292
|
+
- [Sandbox](https://mastra.ai/docs/workspace/sandbox)
|
|
293
|
+
- [WorkspaceSandbox interface](https://mastra.ai/reference/workspace/sandbox)
|
|
294
|
+
- [LocalSandbox reference](https://mastra.ai/reference/workspace/local-sandbox)
|
|
295
|
+
- [E2BSandbox reference](https://mastra.ai/reference/workspace/e2b-sandbox)
|
|
296
|
+
- [DaytonaSandbox reference](https://mastra.ai/reference/workspace/daytona-sandbox)
|
|
@@ -6,10 +6,30 @@ Stores files in Amazon S3 or S3-compatible storage services like Cloudflare R2,
|
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
9
|
+
**npm**:
|
|
10
|
+
|
|
9
11
|
```bash
|
|
10
12
|
npm install @mastra/s3
|
|
11
13
|
```
|
|
12
14
|
|
|
15
|
+
**pnpm**:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm add @mastra/s3
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**Yarn**:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
yarn add @mastra/s3
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
**Bun**:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
bun add @mastra/s3
|
|
31
|
+
```
|
|
32
|
+
|
|
13
33
|
## Usage
|
|
14
34
|
|
|
15
35
|
Add an `S3Filesystem` to a workspace and assign it to an agent:
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
**Added in:** `@mastra/core@1.1.0`
|
|
4
4
|
|
|
5
|
-
The `WorkspaceSandbox` interface defines how workspaces execute commands.
|
|
5
|
+
The `WorkspaceSandbox` interface defines how workspaces execute commands and manage background processes.
|
|
6
|
+
|
|
7
|
+
## Properties
|
|
8
|
+
|
|
9
|
+
**processes** (`SandboxProcessManager`): Background process manager. If not implemented, process management tools won't be available. See SandboxProcessManager reference.
|
|
6
10
|
|
|
7
11
|
## Methods
|
|
8
12
|
|
|
@@ -47,6 +51,8 @@ const result = await sandbox.executeCommand('npm', ['install', 'lodash'])
|
|
|
47
51
|
|
|
48
52
|
**args** (`string[]`): Command arguments
|
|
49
53
|
|
|
54
|
+
**options** (`Options`): Configuration options.
|
|
55
|
+
|
|
50
56
|
**options.timeout** (`number`): Execution timeout in milliseconds
|
|
51
57
|
|
|
52
58
|
**options.cwd** (`string`): Working directory for the command
|
|
@@ -83,5 +89,7 @@ const instructions = sandbox.getInstructions?.()
|
|
|
83
89
|
|
|
84
90
|
## Related
|
|
85
91
|
|
|
92
|
+
- [SandboxProcessManager reference](https://mastra.ai/reference/workspace/process-manager)
|
|
93
|
+
- [Sandbox](https://mastra.ai/docs/workspace/sandbox)
|
|
86
94
|
- [Workspace Class](https://mastra.ai/reference/workspace/workspace-class)
|
|
87
95
|
- [Filesystem Interface](https://mastra.ai/reference/workspace/filesystem)
|