@mastra/core 1.6.0 → 1.7.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/CHANGELOG.md +236 -0
- package/dist/agent/agent.d.ts +6 -0
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/index.cjs +8 -8
- package/dist/agent/index.js +1 -1
- package/dist/{chunk-VJWRJWSC.cjs → chunk-2X66GWF5.cjs} +94 -16
- package/dist/chunk-2X66GWF5.cjs.map +1 -0
- package/dist/{chunk-YM6245EM.js → chunk-6OXW5E2O.js} +3 -3
- package/dist/{chunk-YM6245EM.js.map → chunk-6OXW5E2O.js.map} +1 -1
- package/dist/{chunk-XWZAKKFT.cjs → chunk-6QBN6MZY.cjs} +14 -14
- package/dist/{chunk-XWZAKKFT.cjs.map → chunk-6QBN6MZY.cjs.map} +1 -1
- package/dist/{chunk-AYHSPIT6.cjs → chunk-7UAJ6LMR.cjs} +820 -259
- package/dist/chunk-7UAJ6LMR.cjs.map +1 -0
- package/dist/{chunk-RZNHRIM7.cjs → chunk-A72NTLFT.cjs} +5 -5
- package/dist/{chunk-RZNHRIM7.cjs.map → chunk-A72NTLFT.cjs.map} +1 -1
- package/dist/{chunk-EEU5NHHU.js → chunk-DFCRXDVK.js} +3 -3
- package/dist/{chunk-EEU5NHHU.js.map → chunk-DFCRXDVK.js.map} +1 -1
- package/dist/{chunk-5K45E5VE.js → chunk-GPJGPARM.js} +3 -2
- package/dist/chunk-GPJGPARM.js.map +1 -0
- package/dist/{chunk-LNKS4TJ6.cjs → chunk-HB6T4554.cjs} +8 -7
- package/dist/chunk-HB6T4554.cjs.map +1 -0
- package/dist/{chunk-DGS2KGDI.js → chunk-KUXNBWN7.js} +6 -5
- package/dist/chunk-KUXNBWN7.js.map +1 -0
- package/dist/{chunk-IHDE4CJV.js → chunk-QSHV7GPT.js} +89 -12
- package/dist/chunk-QSHV7GPT.js.map +1 -0
- package/dist/{chunk-3U3XFMGJ.cjs → chunk-QTAS3HND.cjs} +13 -8
- package/dist/chunk-QTAS3HND.cjs.map +1 -0
- package/dist/{chunk-RHKNKJNM.js → chunk-QWTB53GS.js} +4 -4
- package/dist/{chunk-RHKNKJNM.js.map → chunk-QWTB53GS.js.map} +1 -1
- package/dist/{chunk-4WG5K4CK.js → chunk-R4N65TLG.js} +7 -7
- package/dist/{chunk-4WG5K4CK.js.map → chunk-R4N65TLG.js.map} +1 -1
- package/dist/{chunk-5VQPSWPG.cjs → chunk-RABITNTG.cjs} +48 -48
- package/dist/{chunk-5VQPSWPG.cjs.map → chunk-RABITNTG.cjs.map} +1 -1
- package/dist/{chunk-TVPANHLE.cjs → chunk-SBOHDNIZ.cjs} +3 -2
- package/dist/chunk-SBOHDNIZ.cjs.map +1 -0
- package/dist/{chunk-MWGGSA5Q.js → chunk-T6GAM3SQ.js} +10 -5
- package/dist/chunk-T6GAM3SQ.js.map +1 -0
- package/dist/{chunk-TL2TTA4X.cjs → chunk-YQG7NBPR.cjs} +9 -9
- package/dist/{chunk-TL2TTA4X.cjs.map → chunk-YQG7NBPR.cjs.map} +1 -1
- package/dist/{chunk-XB3DA67Q.js → chunk-ZSBM2SVU.js} +818 -259
- package/dist/chunk-ZSBM2SVU.js.map +1 -0
- package/dist/datasets/experiment/scorer.d.ts.map +1 -1
- package/dist/datasets/index.cjs +17 -17
- package/dist/datasets/index.js +2 -2
- package/dist/evals/index.cjs +20 -20
- package/dist/evals/index.js +3 -3
- package/dist/evals/scoreTraces/index.cjs +7 -6
- package/dist/evals/scoreTraces/index.cjs.map +1 -1
- package/dist/evals/scoreTraces/index.js +4 -3
- package/dist/evals/scoreTraces/index.js.map +1 -1
- package/dist/evals/scoreTraces/scoreTracesWorkflow.d.ts.map +1 -1
- package/dist/harness/harness.d.ts +21 -1
- package/dist/harness/harness.d.ts.map +1 -1
- package/dist/harness/index.cjs +422 -5
- package/dist/harness/index.cjs.map +1 -1
- package/dist/harness/index.d.ts +2 -1
- package/dist/harness/index.d.ts.map +1 -1
- package/dist/harness/index.js +418 -3
- package/dist/harness/index.js.map +1 -1
- package/dist/harness/types.d.ts +151 -0
- package/dist/harness/types.d.ts.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +1 -1
- package/dist/loop/index.cjs +12 -12
- package/dist/loop/index.js +1 -1
- package/dist/loop/test-utils/tools.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-loop/index.d.ts.map +1 -1
- package/dist/mastra/hooks.d.ts.map +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.js +1 -1
- package/dist/memory/index.cjs +14 -14
- package/dist/memory/index.js +1 -1
- package/dist/processor-provider/index.cjs +10 -10
- package/dist/processor-provider/index.js +1 -1
- package/dist/processors/index.cjs +45 -41
- package/dist/processors/index.js +1 -1
- package/dist/processors/processors/index.d.ts +1 -0
- package/dist/processors/processors/index.d.ts.map +1 -1
- package/dist/processors/processors/workspace-instructions.d.ts +50 -0
- package/dist/processors/processors/workspace-instructions.d.ts.map +1 -0
- package/dist/relevance/index.cjs +3 -3
- package/dist/relevance/index.js +1 -1
- package/dist/storage/constants.cjs +56 -56
- package/dist/storage/constants.d.ts.map +1 -1
- package/dist/storage/constants.js +1 -1
- package/dist/storage/index.cjs +160 -160
- package/dist/storage/index.js +2 -2
- package/dist/storage/types.d.ts +2 -0
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/compat/prepare-tools.d.ts.map +1 -1
- package/dist/stream/base/output.d.ts.map +1 -1
- package/dist/stream/index.cjs +8 -8
- package/dist/stream/index.js +1 -1
- package/dist/tool-loop-agent/index.cjs +4 -4
- package/dist/tool-loop-agent/index.js +1 -1
- package/dist/vector/index.cjs +7 -7
- package/dist/vector/index.js +1 -1
- package/dist/workflows/evented/index.cjs +10 -10
- package/dist/workflows/evented/index.js +1 -1
- package/dist/workflows/index.cjs +25 -25
- package/dist/workflows/index.js +1 -1
- package/dist/workspace/constants/index.d.ts +2 -0
- package/dist/workspace/constants/index.d.ts.map +1 -1
- package/dist/workspace/errors.d.ts +1 -1
- package/dist/workspace/errors.d.ts.map +1 -1
- package/dist/workspace/filesystem/composite-filesystem.d.ts +4 -1
- package/dist/workspace/filesystem/composite-filesystem.d.ts.map +1 -1
- package/dist/workspace/filesystem/file-write-lock.d.ts +35 -0
- package/dist/workspace/filesystem/file-write-lock.d.ts.map +1 -0
- package/dist/workspace/filesystem/filesystem.d.ts +5 -1
- package/dist/workspace/filesystem/filesystem.d.ts.map +1 -1
- package/dist/workspace/filesystem/index.d.ts +1 -0
- package/dist/workspace/filesystem/index.d.ts.map +1 -1
- package/dist/workspace/filesystem/local-filesystem.d.ts +17 -1
- package/dist/workspace/filesystem/local-filesystem.d.ts.map +1 -1
- package/dist/workspace/index.cjs +72 -64
- package/dist/workspace/index.d.ts +3 -2
- package/dist/workspace/index.d.ts.map +1 -1
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/lifecycle.d.ts +1 -9
- package/dist/workspace/lifecycle.d.ts.map +1 -1
- package/dist/workspace/sandbox/index.d.ts +2 -0
- package/dist/workspace/sandbox/index.d.ts.map +1 -1
- package/dist/workspace/sandbox/local-process-manager.d.ts +18 -0
- package/dist/workspace/sandbox/local-process-manager.d.ts.map +1 -0
- package/dist/workspace/sandbox/local-sandbox.d.ts +49 -35
- package/dist/workspace/sandbox/local-sandbox.d.ts.map +1 -1
- package/dist/workspace/sandbox/mastra-sandbox.d.ts +45 -11
- package/dist/workspace/sandbox/mastra-sandbox.d.ts.map +1 -1
- package/dist/workspace/sandbox/native-sandbox/bubblewrap.d.ts +2 -3
- package/dist/workspace/sandbox/native-sandbox/bubblewrap.d.ts.map +1 -1
- package/dist/workspace/sandbox/native-sandbox/seatbelt.d.ts +2 -3
- package/dist/workspace/sandbox/native-sandbox/seatbelt.d.ts.map +1 -1
- package/dist/workspace/sandbox/native-sandbox/wrapper.d.ts +4 -5
- package/dist/workspace/sandbox/native-sandbox/wrapper.d.ts.map +1 -1
- package/dist/workspace/sandbox/process-manager/index.d.ts +4 -0
- package/dist/workspace/sandbox/process-manager/index.d.ts.map +1 -0
- package/dist/workspace/sandbox/process-manager/process-handle.d.ts +107 -0
- package/dist/workspace/sandbox/process-manager/process-handle.d.ts.map +1 -0
- package/dist/workspace/sandbox/process-manager/process-manager.d.ts +59 -0
- package/dist/workspace/sandbox/process-manager/process-manager.d.ts.map +1 -0
- package/dist/workspace/sandbox/process-manager/types.d.ts +24 -0
- package/dist/workspace/sandbox/process-manager/types.d.ts.map +1 -0
- package/dist/workspace/sandbox/sandbox.d.ts +38 -2
- package/dist/workspace/sandbox/sandbox.d.ts.map +1 -1
- package/dist/workspace/sandbox/types.d.ts +9 -2
- package/dist/workspace/sandbox/types.d.ts.map +1 -1
- package/dist/workspace/sandbox/utils.d.ts +7 -0
- package/dist/workspace/sandbox/utils.d.ts.map +1 -0
- package/dist/workspace/tools/execute-command.d.ts +53 -2
- package/dist/workspace/tools/execute-command.d.ts.map +1 -1
- package/dist/workspace/tools/get-process-output.d.ts +6 -0
- package/dist/workspace/tools/get-process-output.d.ts.map +1 -0
- package/dist/workspace/tools/index.d.ts +4 -1
- package/dist/workspace/tools/index.d.ts.map +1 -1
- package/dist/workspace/tools/kill-process.d.ts +4 -0
- package/dist/workspace/tools/kill-process.d.ts.map +1 -0
- package/dist/workspace/tools/output-helpers.d.ts +21 -0
- package/dist/workspace/tools/output-helpers.d.ts.map +1 -0
- package/dist/workspace/tools/tools.d.ts.map +1 -1
- package/dist/workspace/types.d.ts +31 -0
- package/dist/workspace/types.d.ts.map +1 -1
- package/dist/workspace/utils.d.ts +11 -0
- package/dist/workspace/utils.d.ts.map +1 -0
- package/dist/workspace/workspace.d.ts +36 -0
- package/dist/workspace/workspace.d.ts.map +1 -1
- package/package.json +7 -7
- package/dist/chunk-3U3XFMGJ.cjs.map +0 -1
- package/dist/chunk-5K45E5VE.js.map +0 -1
- package/dist/chunk-AYHSPIT6.cjs.map +0 -1
- package/dist/chunk-DGS2KGDI.js.map +0 -1
- package/dist/chunk-IHDE4CJV.js.map +0 -1
- package/dist/chunk-LNKS4TJ6.cjs.map +0 -1
- package/dist/chunk-MWGGSA5Q.js.map +0 -1
- package/dist/chunk-TVPANHLE.cjs.map +0 -1
- package/dist/chunk-VJWRJWSC.cjs.map +0 -1
- package/dist/chunk-XB3DA67Q.js.map +0 -1
- package/dist/docs/SKILL.md +0 -301
- package/dist/docs/assets/SOURCE_MAP.json +0 -1413
- package/dist/docs/references/docs-agents-adding-voice.md +0 -353
- package/dist/docs/references/docs-agents-agent-approval.md +0 -377
- package/dist/docs/references/docs-agents-agent-memory.md +0 -212
- package/dist/docs/references/docs-agents-guardrails.md +0 -382
- package/dist/docs/references/docs-agents-network-approval.md +0 -275
- package/dist/docs/references/docs-agents-networks.md +0 -290
- package/dist/docs/references/docs-agents-overview.md +0 -309
- package/dist/docs/references/docs-agents-processors.md +0 -632
- package/dist/docs/references/docs-agents-structured-output.md +0 -271
- package/dist/docs/references/docs-agents-using-tools.md +0 -214
- package/dist/docs/references/docs-evals-custom-scorers.md +0 -519
- package/dist/docs/references/docs-evals-overview.md +0 -146
- package/dist/docs/references/docs-evals-running-in-ci.md +0 -106
- package/dist/docs/references/docs-mcp-overview.md +0 -370
- package/dist/docs/references/docs-mcp-publishing-mcp-server.md +0 -95
- package/dist/docs/references/docs-memory-memory-processors.md +0 -316
- package/dist/docs/references/docs-memory-observational-memory.md +0 -246
- package/dist/docs/references/docs-memory-overview.md +0 -45
- package/dist/docs/references/docs-memory-semantic-recall.md +0 -272
- package/dist/docs/references/docs-memory-storage.md +0 -261
- package/dist/docs/references/docs-memory-working-memory.md +0 -400
- package/dist/docs/references/docs-observability-datasets-overview.md +0 -188
- package/dist/docs/references/docs-observability-datasets-running-experiments.md +0 -266
- package/dist/docs/references/docs-observability-logging.md +0 -99
- package/dist/docs/references/docs-observability-overview.md +0 -70
- package/dist/docs/references/docs-observability-tracing-bridges-otel.md +0 -209
- package/dist/docs/references/docs-observability-tracing-exporters-arize.md +0 -274
- package/dist/docs/references/docs-observability-tracing-exporters-braintrust.md +0 -111
- package/dist/docs/references/docs-observability-tracing-exporters-cloud.md +0 -129
- package/dist/docs/references/docs-observability-tracing-exporters-datadog.md +0 -187
- package/dist/docs/references/docs-observability-tracing-exporters-default.md +0 -211
- package/dist/docs/references/docs-observability-tracing-exporters-laminar.md +0 -100
- package/dist/docs/references/docs-observability-tracing-exporters-langfuse.md +0 -217
- package/dist/docs/references/docs-observability-tracing-exporters-langsmith.md +0 -202
- package/dist/docs/references/docs-observability-tracing-exporters-otel.md +0 -479
- package/dist/docs/references/docs-observability-tracing-exporters-posthog.md +0 -148
- package/dist/docs/references/docs-observability-tracing-overview.md +0 -1114
- package/dist/docs/references/docs-rag-chunking-and-embedding.md +0 -183
- package/dist/docs/references/docs-rag-graph-rag.md +0 -215
- package/dist/docs/references/docs-rag-overview.md +0 -72
- package/dist/docs/references/docs-rag-retrieval.md +0 -521
- package/dist/docs/references/docs-rag-vector-databases.md +0 -648
- package/dist/docs/references/docs-server-auth-auth0.md +0 -222
- package/dist/docs/references/docs-server-auth-clerk.md +0 -132
- package/dist/docs/references/docs-server-auth-composite-auth.md +0 -234
- package/dist/docs/references/docs-server-auth-custom-auth-provider.md +0 -513
- package/dist/docs/references/docs-server-auth-firebase.md +0 -272
- package/dist/docs/references/docs-server-auth-jwt.md +0 -110
- package/dist/docs/references/docs-server-auth-simple-auth.md +0 -178
- package/dist/docs/references/docs-server-auth-supabase.md +0 -117
- package/dist/docs/references/docs-server-auth-workos.md +0 -190
- package/dist/docs/references/docs-server-custom-adapters.md +0 -374
- package/dist/docs/references/docs-server-custom-api-routes.md +0 -267
- package/dist/docs/references/docs-server-mastra-client.md +0 -243
- package/dist/docs/references/docs-server-mastra-server.md +0 -71
- package/dist/docs/references/docs-server-middleware.md +0 -228
- package/dist/docs/references/docs-server-request-context.md +0 -478
- package/dist/docs/references/docs-streaming-events.md +0 -247
- package/dist/docs/references/docs-streaming-tool-streaming.md +0 -178
- package/dist/docs/references/docs-streaming-workflow-streaming.md +0 -109
- package/dist/docs/references/docs-voice-overview.md +0 -979
- package/dist/docs/references/docs-voice-speech-to-speech.md +0 -103
- package/dist/docs/references/docs-voice-speech-to-text.md +0 -80
- package/dist/docs/references/docs-voice-text-to-speech.md +0 -84
- package/dist/docs/references/docs-workflows-agents-and-tools.md +0 -170
- package/dist/docs/references/docs-workflows-control-flow.md +0 -823
- package/dist/docs/references/docs-workflows-error-handling.md +0 -360
- package/dist/docs/references/docs-workflows-human-in-the-loop.md +0 -213
- package/dist/docs/references/docs-workflows-overview.md +0 -372
- package/dist/docs/references/docs-workflows-snapshots.md +0 -238
- package/dist/docs/references/docs-workflows-suspend-and-resume.md +0 -205
- package/dist/docs/references/docs-workflows-time-travel.md +0 -309
- package/dist/docs/references/docs-workflows-workflow-state.md +0 -181
- package/dist/docs/references/docs-workspace-filesystem.md +0 -162
- package/dist/docs/references/docs-workspace-overview.md +0 -239
- package/dist/docs/references/docs-workspace-sandbox.md +0 -63
- package/dist/docs/references/docs-workspace-search.md +0 -219
- package/dist/docs/references/docs-workspace-skills.md +0 -126
- package/dist/docs/references/guides-agent-frameworks-ai-sdk.md +0 -140
- package/dist/docs/references/reference-agents-agent.md +0 -142
- package/dist/docs/references/reference-agents-generate.md +0 -174
- package/dist/docs/references/reference-agents-generateLegacy.md +0 -176
- package/dist/docs/references/reference-agents-getDefaultGenerateOptions.md +0 -36
- package/dist/docs/references/reference-agents-getDefaultOptions.md +0 -34
- package/dist/docs/references/reference-agents-getDefaultStreamOptions.md +0 -36
- package/dist/docs/references/reference-agents-getDescription.md +0 -21
- package/dist/docs/references/reference-agents-getInstructions.md +0 -34
- package/dist/docs/references/reference-agents-getLLM.md +0 -37
- package/dist/docs/references/reference-agents-getMemory.md +0 -34
- package/dist/docs/references/reference-agents-getModel.md +0 -34
- package/dist/docs/references/reference-agents-getTools.md +0 -29
- package/dist/docs/references/reference-agents-getVoice.md +0 -34
- package/dist/docs/references/reference-agents-listAgents.md +0 -35
- package/dist/docs/references/reference-agents-listScorers.md +0 -34
- package/dist/docs/references/reference-agents-listTools.md +0 -34
- package/dist/docs/references/reference-agents-listWorkflows.md +0 -34
- package/dist/docs/references/reference-agents-network.md +0 -134
- package/dist/docs/references/reference-ai-sdk-chat-route.md +0 -82
- package/dist/docs/references/reference-ai-sdk-network-route.md +0 -74
- package/dist/docs/references/reference-ai-sdk-to-ai-sdk-stream.md +0 -232
- package/dist/docs/references/reference-ai-sdk-with-mastra.md +0 -59
- package/dist/docs/references/reference-ai-sdk-workflow-route.md +0 -79
- package/dist/docs/references/reference-auth-auth0.md +0 -73
- package/dist/docs/references/reference-auth-clerk.md +0 -36
- package/dist/docs/references/reference-auth-firebase.md +0 -80
- package/dist/docs/references/reference-auth-jwt.md +0 -26
- package/dist/docs/references/reference-auth-supabase.md +0 -33
- package/dist/docs/references/reference-auth-workos.md +0 -84
- package/dist/docs/references/reference-client-js-agents.md +0 -438
- package/dist/docs/references/reference-configuration.md +0 -749
- package/dist/docs/references/reference-core-addGateway.md +0 -42
- package/dist/docs/references/reference-core-getAgent.md +0 -21
- package/dist/docs/references/reference-core-getAgentById.md +0 -21
- package/dist/docs/references/reference-core-getDeployer.md +0 -22
- package/dist/docs/references/reference-core-getGateway.md +0 -38
- package/dist/docs/references/reference-core-getGatewayById.md +0 -41
- package/dist/docs/references/reference-core-getLogger.md +0 -22
- package/dist/docs/references/reference-core-getMCPServer.md +0 -45
- package/dist/docs/references/reference-core-getMCPServerById.md +0 -53
- package/dist/docs/references/reference-core-getMemory.md +0 -50
- package/dist/docs/references/reference-core-getScorer.md +0 -54
- package/dist/docs/references/reference-core-getScorerById.md +0 -54
- package/dist/docs/references/reference-core-getServer.md +0 -22
- package/dist/docs/references/reference-core-getStorage.md +0 -22
- package/dist/docs/references/reference-core-getStoredAgentById.md +0 -89
- package/dist/docs/references/reference-core-getTelemetry.md +0 -22
- package/dist/docs/references/reference-core-getVector.md +0 -22
- package/dist/docs/references/reference-core-getWorkflow.md +0 -40
- package/dist/docs/references/reference-core-listAgents.md +0 -21
- package/dist/docs/references/reference-core-listGateways.md +0 -40
- package/dist/docs/references/reference-core-listLogs.md +0 -38
- package/dist/docs/references/reference-core-listLogsByRunId.md +0 -36
- package/dist/docs/references/reference-core-listMCPServers.md +0 -51
- package/dist/docs/references/reference-core-listMemory.md +0 -56
- package/dist/docs/references/reference-core-listScorers.md +0 -29
- package/dist/docs/references/reference-core-listStoredAgents.md +0 -93
- package/dist/docs/references/reference-core-listVectors.md +0 -22
- package/dist/docs/references/reference-core-listWorkflows.md +0 -21
- package/dist/docs/references/reference-core-mastra-class.md +0 -66
- package/dist/docs/references/reference-core-mastra-model-gateway.md +0 -153
- package/dist/docs/references/reference-core-setLogger.md +0 -26
- package/dist/docs/references/reference-core-setStorage.md +0 -27
- package/dist/docs/references/reference-datasets-addItem.md +0 -35
- package/dist/docs/references/reference-datasets-addItems.md +0 -33
- package/dist/docs/references/reference-datasets-compareExperiments.md +0 -48
- package/dist/docs/references/reference-datasets-create.md +0 -49
- package/dist/docs/references/reference-datasets-dataset.md +0 -78
- package/dist/docs/references/reference-datasets-datasets-manager.md +0 -84
- package/dist/docs/references/reference-datasets-delete.md +0 -23
- package/dist/docs/references/reference-datasets-deleteExperiment.md +0 -25
- package/dist/docs/references/reference-datasets-deleteItem.md +0 -25
- package/dist/docs/references/reference-datasets-deleteItems.md +0 -27
- package/dist/docs/references/reference-datasets-get.md +0 -29
- package/dist/docs/references/reference-datasets-getDetails.md +0 -45
- package/dist/docs/references/reference-datasets-getExperiment.md +0 -28
- package/dist/docs/references/reference-datasets-getItem.md +0 -31
- package/dist/docs/references/reference-datasets-getItemHistory.md +0 -29
- package/dist/docs/references/reference-datasets-list.md +0 -29
- package/dist/docs/references/reference-datasets-listExperimentResults.md +0 -37
- package/dist/docs/references/reference-datasets-listExperiments.md +0 -31
- package/dist/docs/references/reference-datasets-listItems.md +0 -44
- package/dist/docs/references/reference-datasets-listVersions.md +0 -31
- package/dist/docs/references/reference-datasets-startExperiment.md +0 -60
- package/dist/docs/references/reference-datasets-startExperimentAsync.md +0 -41
- package/dist/docs/references/reference-datasets-update.md +0 -46
- package/dist/docs/references/reference-datasets-updateItem.md +0 -36
- package/dist/docs/references/reference-evals-answer-relevancy.md +0 -105
- package/dist/docs/references/reference-evals-answer-similarity.md +0 -99
- package/dist/docs/references/reference-evals-bias.md +0 -120
- package/dist/docs/references/reference-evals-completeness.md +0 -137
- package/dist/docs/references/reference-evals-content-similarity.md +0 -101
- package/dist/docs/references/reference-evals-context-precision.md +0 -196
- package/dist/docs/references/reference-evals-create-scorer.md +0 -270
- package/dist/docs/references/reference-evals-faithfulness.md +0 -114
- package/dist/docs/references/reference-evals-hallucination.md +0 -220
- package/dist/docs/references/reference-evals-keyword-coverage.md +0 -128
- package/dist/docs/references/reference-evals-mastra-scorer.md +0 -123
- package/dist/docs/references/reference-evals-run-evals.md +0 -138
- package/dist/docs/references/reference-evals-scorer-utils.md +0 -330
- package/dist/docs/references/reference-evals-textual-difference.md +0 -113
- package/dist/docs/references/reference-evals-tone-consistency.md +0 -119
- package/dist/docs/references/reference-evals-toxicity.md +0 -123
- package/dist/docs/references/reference-harness-harness-class.md +0 -645
- package/dist/docs/references/reference-logging-pino-logger.md +0 -117
- package/dist/docs/references/reference-memory-deleteMessages.md +0 -40
- package/dist/docs/references/reference-memory-memory-class.md +0 -147
- package/dist/docs/references/reference-memory-observational-memory.md +0 -565
- package/dist/docs/references/reference-observability-tracing-bridges-otel.md +0 -131
- package/dist/docs/references/reference-observability-tracing-configuration.md +0 -178
- package/dist/docs/references/reference-observability-tracing-exporters-console-exporter.md +0 -138
- package/dist/docs/references/reference-observability-tracing-exporters-datadog.md +0 -116
- package/dist/docs/references/reference-observability-tracing-instances.md +0 -109
- package/dist/docs/references/reference-observability-tracing-interfaces.md +0 -749
- package/dist/docs/references/reference-observability-tracing-processors-sensitive-data-filter.md +0 -144
- package/dist/docs/references/reference-observability-tracing-spans.md +0 -224
- package/dist/docs/references/reference-processors-batch-parts-processor.md +0 -61
- package/dist/docs/references/reference-processors-language-detector.md +0 -81
- package/dist/docs/references/reference-processors-message-history-processor.md +0 -85
- package/dist/docs/references/reference-processors-moderation-processor.md +0 -104
- package/dist/docs/references/reference-processors-pii-detector.md +0 -107
- package/dist/docs/references/reference-processors-processor-interface.md +0 -525
- package/dist/docs/references/reference-processors-prompt-injection-detector.md +0 -71
- package/dist/docs/references/reference-processors-semantic-recall-processor.md +0 -123
- package/dist/docs/references/reference-processors-system-prompt-scrubber.md +0 -80
- package/dist/docs/references/reference-processors-token-limiter-processor.md +0 -113
- package/dist/docs/references/reference-processors-tool-call-filter.md +0 -85
- package/dist/docs/references/reference-processors-tool-search-processor.md +0 -113
- package/dist/docs/references/reference-processors-unicode-normalizer.md +0 -62
- package/dist/docs/references/reference-processors-working-memory-processor.md +0 -154
- package/dist/docs/references/reference-rag-database-config.md +0 -264
- package/dist/docs/references/reference-rag-embeddings.md +0 -92
- package/dist/docs/references/reference-server-mastra-server.md +0 -298
- package/dist/docs/references/reference-server-register-api-route.md +0 -249
- package/dist/docs/references/reference-storage-cloudflare-d1.md +0 -218
- package/dist/docs/references/reference-storage-composite.md +0 -235
- package/dist/docs/references/reference-storage-lance.md +0 -131
- package/dist/docs/references/reference-storage-libsql.md +0 -135
- package/dist/docs/references/reference-storage-mongodb.md +0 -262
- package/dist/docs/references/reference-storage-mssql.md +0 -155
- package/dist/docs/references/reference-storage-overview.md +0 -121
- package/dist/docs/references/reference-storage-postgresql.md +0 -529
- package/dist/docs/references/reference-storage-upstash.md +0 -160
- package/dist/docs/references/reference-streaming-ChunkType.md +0 -292
- package/dist/docs/references/reference-streaming-agents-MastraModelOutput.md +0 -182
- package/dist/docs/references/reference-streaming-agents-streamLegacy.md +0 -142
- package/dist/docs/references/reference-streaming-workflows-observeStream.md +0 -42
- package/dist/docs/references/reference-streaming-workflows-resumeStream.md +0 -61
- package/dist/docs/references/reference-streaming-workflows-stream.md +0 -88
- package/dist/docs/references/reference-streaming-workflows-timeTravelStream.md +0 -142
- package/dist/docs/references/reference-templates-overview.md +0 -194
- package/dist/docs/references/reference-tools-create-tool.md +0 -237
- package/dist/docs/references/reference-tools-graph-rag-tool.md +0 -185
- package/dist/docs/references/reference-tools-mcp-client.md +0 -962
- package/dist/docs/references/reference-tools-mcp-server.md +0 -1275
- package/dist/docs/references/reference-tools-vector-query-tool.md +0 -459
- package/dist/docs/references/reference-vectors-libsql.md +0 -305
- package/dist/docs/references/reference-vectors-mongodb.md +0 -295
- package/dist/docs/references/reference-vectors-pg.md +0 -408
- package/dist/docs/references/reference-vectors-upstash.md +0 -294
- package/dist/docs/references/reference-voice-composite-voice.md +0 -121
- package/dist/docs/references/reference-voice-mastra-voice.md +0 -313
- package/dist/docs/references/reference-voice-voice.addInstructions.md +0 -56
- package/dist/docs/references/reference-voice-voice.addTools.md +0 -67
- package/dist/docs/references/reference-voice-voice.connect.md +0 -94
- package/dist/docs/references/reference-voice-voice.events.md +0 -37
- package/dist/docs/references/reference-voice-voice.listen.md +0 -164
- package/dist/docs/references/reference-voice-voice.on.md +0 -111
- package/dist/docs/references/reference-voice-voice.speak.md +0 -157
- package/dist/docs/references/reference-workflows-run-methods-cancel.md +0 -86
- package/dist/docs/references/reference-workflows-run-methods-restart.md +0 -33
- package/dist/docs/references/reference-workflows-run-methods-resume.md +0 -59
- package/dist/docs/references/reference-workflows-run-methods-start.md +0 -58
- package/dist/docs/references/reference-workflows-run-methods-startAsync.md +0 -67
- package/dist/docs/references/reference-workflows-run-methods-timeTravel.md +0 -142
- package/dist/docs/references/reference-workflows-run.md +0 -59
- package/dist/docs/references/reference-workflows-step.md +0 -119
- package/dist/docs/references/reference-workflows-workflow-methods-branch.md +0 -25
- package/dist/docs/references/reference-workflows-workflow-methods-commit.md +0 -17
- package/dist/docs/references/reference-workflows-workflow-methods-create-run.md +0 -63
- package/dist/docs/references/reference-workflows-workflow-methods-dountil.md +0 -25
- package/dist/docs/references/reference-workflows-workflow-methods-dowhile.md +0 -25
- package/dist/docs/references/reference-workflows-workflow-methods-foreach.md +0 -118
- package/dist/docs/references/reference-workflows-workflow-methods-map.md +0 -93
- package/dist/docs/references/reference-workflows-workflow-methods-parallel.md +0 -21
- package/dist/docs/references/reference-workflows-workflow-methods-sleep.md +0 -35
- package/dist/docs/references/reference-workflows-workflow-methods-sleepUntil.md +0 -35
- package/dist/docs/references/reference-workflows-workflow-methods-then.md +0 -21
- package/dist/docs/references/reference-workflows-workflow.md +0 -157
- package/dist/docs/references/reference-workspace-filesystem.md +0 -202
- package/dist/docs/references/reference-workspace-local-filesystem.md +0 -327
- package/dist/docs/references/reference-workspace-local-sandbox.md +0 -285
- package/dist/docs/references/reference-workspace-sandbox.md +0 -81
- package/dist/docs/references/reference-workspace-workspace-class.md +0 -226
- package/dist/docs/references/reference.md +0 -276
|
@@ -9,10 +9,11 @@ import picomatch from 'picomatch';
|
|
|
9
9
|
import * as crypto from 'crypto';
|
|
10
10
|
import { createHash } from 'crypto';
|
|
11
11
|
import matter from 'gray-matter';
|
|
12
|
-
import * as childProcess from 'child_process';
|
|
13
|
-
import { execFileSync } from 'child_process';
|
|
14
12
|
import * as os from 'os';
|
|
15
13
|
import os__default from 'os';
|
|
14
|
+
import * as childProcess from 'child_process';
|
|
15
|
+
import { execFileSync } from 'child_process';
|
|
16
|
+
import { Readable, Writable } from 'stream';
|
|
16
17
|
import { createRequire } from 'module';
|
|
17
18
|
import { z } from 'zod';
|
|
18
19
|
|
|
@@ -450,13 +451,13 @@ var CompositeFilesystem = class {
|
|
|
450
451
|
* Get instructions describing the mounted filesystems.
|
|
451
452
|
* Used by agents to understand available storage locations.
|
|
452
453
|
*/
|
|
453
|
-
getInstructions() {
|
|
454
|
+
getInstructions(_opts) {
|
|
454
455
|
const mountDescriptions = Array.from(this._mounts.entries()).map(([mountPath, fs5]) => {
|
|
455
456
|
const name = fs5.displayName || fs5.provider;
|
|
456
457
|
const access2 = fs5.readOnly ? "(read-only)" : "(read-write)";
|
|
457
458
|
return `- ${mountPath}: ${name} ${access2}`;
|
|
458
459
|
}).join("\n");
|
|
459
|
-
return `
|
|
460
|
+
return `Filesystem mount points:
|
|
460
461
|
${mountDescriptions}`;
|
|
461
462
|
}
|
|
462
463
|
};
|
|
@@ -628,6 +629,14 @@ var MastraFilesystem = class extends MastraBase {
|
|
|
628
629
|
async destroy() {
|
|
629
630
|
}
|
|
630
631
|
};
|
|
632
|
+
|
|
633
|
+
// src/workspace/utils.ts
|
|
634
|
+
function resolveInstructions(override, getDefault, requestContext) {
|
|
635
|
+
if (typeof override === "string") return override;
|
|
636
|
+
const defaultInstructions = getDefault();
|
|
637
|
+
if (override === void 0) return defaultInstructions;
|
|
638
|
+
return override({ defaultInstructions, requestContext });
|
|
639
|
+
}
|
|
631
640
|
function isEnoentError(error) {
|
|
632
641
|
return error !== null && typeof error === "object" && "code" in error && error.code === "ENOENT";
|
|
633
642
|
}
|
|
@@ -768,6 +777,7 @@ var LocalFilesystem = class extends MastraFilesystem {
|
|
|
768
777
|
_basePath;
|
|
769
778
|
_contained;
|
|
770
779
|
_allowedPaths;
|
|
780
|
+
_instructionsOverride;
|
|
771
781
|
/**
|
|
772
782
|
* The absolute base path on disk where files are stored.
|
|
773
783
|
* Useful for understanding how workspace paths map to disk paths.
|
|
@@ -806,6 +816,7 @@ var LocalFilesystem = class extends MastraFilesystem {
|
|
|
806
816
|
this._contained = options.contained ?? true;
|
|
807
817
|
this.readOnly = options.readOnly;
|
|
808
818
|
this._allowedPaths = (options.allowedPaths ?? []).map((p) => nodePath.resolve(p));
|
|
819
|
+
this._instructionsOverride = options.instructions;
|
|
809
820
|
}
|
|
810
821
|
generateId() {
|
|
811
822
|
return `local-fs-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
@@ -1268,7 +1279,10 @@ var LocalFilesystem = class extends MastraFilesystem {
|
|
|
1268
1279
|
}
|
|
1269
1280
|
};
|
|
1270
1281
|
}
|
|
1271
|
-
getInstructions() {
|
|
1282
|
+
getInstructions(opts) {
|
|
1283
|
+
return resolveInstructions(this._instructionsOverride, () => this._getDefaultInstructions(), opts?.requestContext);
|
|
1284
|
+
}
|
|
1285
|
+
_getDefaultInstructions() {
|
|
1272
1286
|
const allowedNote = this._allowedPaths.length > 0 ? ` Additionally, the following paths outside basePath are accessible: ${this._allowedPaths.join(", ")}.` : "";
|
|
1273
1287
|
if (this._contained) {
|
|
1274
1288
|
return `Local filesystem at "${this.basePath}". Files at workspace path "/foo" are stored at "${this.basePath}/foo" on disk.${allowedNote}`;
|
|
@@ -1316,6 +1330,57 @@ var InMemoryFileReadTracker = class {
|
|
|
1316
1330
|
return normalized.replace(/\/$/, "") || "/";
|
|
1317
1331
|
}
|
|
1318
1332
|
};
|
|
1333
|
+
var InMemoryFileWriteLock = class {
|
|
1334
|
+
queues = /* @__PURE__ */ new Map();
|
|
1335
|
+
timeoutMs;
|
|
1336
|
+
constructor(opts) {
|
|
1337
|
+
this.timeoutMs = opts?.timeoutMs ?? 3e4;
|
|
1338
|
+
}
|
|
1339
|
+
get size() {
|
|
1340
|
+
return this.queues.size;
|
|
1341
|
+
}
|
|
1342
|
+
withLock(filePath, fn) {
|
|
1343
|
+
const key = this.normalizePath(filePath);
|
|
1344
|
+
const currentQueue = this.queues.get(key) ?? Promise.resolve();
|
|
1345
|
+
let resolve3;
|
|
1346
|
+
let reject;
|
|
1347
|
+
const resultPromise = new Promise((res, rej) => {
|
|
1348
|
+
resolve3 = res;
|
|
1349
|
+
reject = rej;
|
|
1350
|
+
});
|
|
1351
|
+
const queuePromise = currentQueue.catch(() => {
|
|
1352
|
+
}).then(async () => {
|
|
1353
|
+
let timeoutId;
|
|
1354
|
+
try {
|
|
1355
|
+
const result = await Promise.race([
|
|
1356
|
+
fn(),
|
|
1357
|
+
new Promise((_, rej) => {
|
|
1358
|
+
timeoutId = setTimeout(
|
|
1359
|
+
() => rej(new Error(`write-lock timeout on "${key}" after ${this.timeoutMs}ms`)),
|
|
1360
|
+
this.timeoutMs
|
|
1361
|
+
);
|
|
1362
|
+
})
|
|
1363
|
+
]);
|
|
1364
|
+
clearTimeout(timeoutId);
|
|
1365
|
+
resolve3(result);
|
|
1366
|
+
} catch (error) {
|
|
1367
|
+
clearTimeout(timeoutId);
|
|
1368
|
+
reject(error);
|
|
1369
|
+
}
|
|
1370
|
+
});
|
|
1371
|
+
this.queues.set(key, queuePromise);
|
|
1372
|
+
void queuePromise.finally(() => {
|
|
1373
|
+
if (this.queues.get(key) === queuePromise) {
|
|
1374
|
+
this.queues.delete(key);
|
|
1375
|
+
}
|
|
1376
|
+
});
|
|
1377
|
+
return resultPromise;
|
|
1378
|
+
}
|
|
1379
|
+
normalizePath(pathStr) {
|
|
1380
|
+
const normalized = nodePath.posix.normalize(pathStr.replace(/\\/g, "/").replace(/^\/\/+/, "/"));
|
|
1381
|
+
return normalized.replace(/\/+$/, "") || "/";
|
|
1382
|
+
}
|
|
1383
|
+
};
|
|
1319
1384
|
var GLOB_CHARS = /[*?{}[\]]/;
|
|
1320
1385
|
function isGlobPattern(input) {
|
|
1321
1386
|
return GLOB_CHARS.test(input);
|
|
@@ -1695,8 +1760,16 @@ var MountManager = class {
|
|
|
1695
1760
|
}
|
|
1696
1761
|
};
|
|
1697
1762
|
|
|
1763
|
+
// src/workspace/sandbox/utils.ts
|
|
1764
|
+
function shellQuote(arg) {
|
|
1765
|
+
if (/^[a-zA-Z0-9._\-\/=:@]+$/.test(arg)) return arg;
|
|
1766
|
+
return `'${arg.replace(/'/g, "'\\''")}'`;
|
|
1767
|
+
}
|
|
1768
|
+
|
|
1698
1769
|
// src/workspace/sandbox/mastra-sandbox.ts
|
|
1699
1770
|
var MastraSandbox = class extends MastraBase {
|
|
1771
|
+
/** Process manager */
|
|
1772
|
+
processes;
|
|
1700
1773
|
/** Mount manager - automatically created if subclass implements mount() */
|
|
1701
1774
|
mounts;
|
|
1702
1775
|
// ---------------------------------------------------------------------------
|
|
@@ -1723,6 +1796,21 @@ var MastraSandbox = class extends MastraBase {
|
|
|
1723
1796
|
logger: this.logger
|
|
1724
1797
|
});
|
|
1725
1798
|
}
|
|
1799
|
+
if (options.processes) {
|
|
1800
|
+
const pm = options.processes;
|
|
1801
|
+
pm.sandbox = this;
|
|
1802
|
+
this.processes = pm;
|
|
1803
|
+
if (!this.executeCommand) {
|
|
1804
|
+
this.executeCommand = async (command, args, opts) => {
|
|
1805
|
+
const fullCommand = args?.length ? `${command} ${args.map((a) => shellQuote(a)).join(" ")}` : command;
|
|
1806
|
+
this.logger.debug(`[${this.name}] Executing: ${fullCommand}`, { cwd: opts?.cwd });
|
|
1807
|
+
const handle = await pm.spawn(fullCommand, opts ?? {});
|
|
1808
|
+
const result = await handle.wait();
|
|
1809
|
+
this.logger.debug(`[${this.name}] Exit code: ${result.exitCode} (${result.executionTimeMs}ms)`);
|
|
1810
|
+
return { ...result, command: fullCommand };
|
|
1811
|
+
};
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1726
1814
|
}
|
|
1727
1815
|
// ---------------------------------------------------------------------------
|
|
1728
1816
|
// Lifecycle Wrappers (race-condition-safe)
|
|
@@ -1809,6 +1897,12 @@ var MastraSandbox = class extends MastraBase {
|
|
|
1809
1897
|
* ```
|
|
1810
1898
|
*/
|
|
1811
1899
|
async ensureRunning() {
|
|
1900
|
+
if (this.status === "destroyed") {
|
|
1901
|
+
throw new SandboxNotReadyError(this.id);
|
|
1902
|
+
}
|
|
1903
|
+
if (this.status === "destroying" || this.status === "stopping") {
|
|
1904
|
+
return;
|
|
1905
|
+
}
|
|
1812
1906
|
if (this.status !== "running") {
|
|
1813
1907
|
await this._start();
|
|
1814
1908
|
}
|
|
@@ -1874,6 +1968,10 @@ var MastraSandbox = class extends MastraBase {
|
|
|
1874
1968
|
if (this.status === "destroyed") {
|
|
1875
1969
|
return;
|
|
1876
1970
|
}
|
|
1971
|
+
if (this.status === "pending") {
|
|
1972
|
+
this.status = "destroyed";
|
|
1973
|
+
return;
|
|
1974
|
+
}
|
|
1877
1975
|
if (this._startPromise) await this._startPromise.catch(() => {
|
|
1878
1976
|
});
|
|
1879
1977
|
if (this._stopPromise) await this._stopPromise.catch(() => {
|
|
@@ -3959,6 +4057,25 @@ var Workspace = class {
|
|
|
3959
4057
|
getToolsConfig() {
|
|
3960
4058
|
return this._config.tools;
|
|
3961
4059
|
}
|
|
4060
|
+
/**
|
|
4061
|
+
* Update the per-tool configuration for this workspace.
|
|
4062
|
+
* Takes effect on the next `createWorkspaceTools()` call.
|
|
4063
|
+
*
|
|
4064
|
+
* @example
|
|
4065
|
+
* ```typescript
|
|
4066
|
+
* // Disable write tools for read-only mode
|
|
4067
|
+
* workspace.setToolsConfig({
|
|
4068
|
+
* mastra_workspace_write_file: { enabled: false },
|
|
4069
|
+
* mastra_workspace_edit_file: { enabled: false },
|
|
4070
|
+
* });
|
|
4071
|
+
*
|
|
4072
|
+
* // Re-enable all tools
|
|
4073
|
+
* workspace.setToolsConfig(undefined);
|
|
4074
|
+
* ```
|
|
4075
|
+
*/
|
|
4076
|
+
setToolsConfig(config) {
|
|
4077
|
+
this._config.tools = config;
|
|
4078
|
+
}
|
|
3962
4079
|
/**
|
|
3963
4080
|
* Access skills stored in this workspace.
|
|
3964
4081
|
* Skills are SKILL.md files discovered from the configured skillPaths.
|
|
@@ -4197,10 +4314,58 @@ var Workspace = class {
|
|
|
4197
4314
|
}
|
|
4198
4315
|
return info;
|
|
4199
4316
|
}
|
|
4317
|
+
/**
|
|
4318
|
+
* Get human-readable instructions describing the workspace environment.
|
|
4319
|
+
*
|
|
4320
|
+
* When both a sandbox with mounts and a filesystem exist, each mount path
|
|
4321
|
+
* is classified as sandbox-accessible (state === 'mounted') or
|
|
4322
|
+
* workspace-only (pending / mounting / error / unsupported). When there's
|
|
4323
|
+
* no sandbox or no mounts, falls back to provider-level instructions.
|
|
4324
|
+
*
|
|
4325
|
+
* @param opts - Optional options including request context for per-request customisation
|
|
4326
|
+
* @returns Combined instructions string (may be empty)
|
|
4327
|
+
*/
|
|
4328
|
+
getInstructions(opts) {
|
|
4329
|
+
const parts = [];
|
|
4330
|
+
const sandboxInstructions = this._sandbox?.getInstructions?.(opts);
|
|
4331
|
+
if (sandboxInstructions) parts.push(sandboxInstructions);
|
|
4332
|
+
const mountEntries = this._sandbox?.mounts?.entries;
|
|
4333
|
+
if (mountEntries && mountEntries.size > 0) {
|
|
4334
|
+
const sandboxAccessible = [];
|
|
4335
|
+
const workspaceOnly = [];
|
|
4336
|
+
for (const [mountPath, entry] of mountEntries) {
|
|
4337
|
+
const fsName = entry.filesystem.displayName || entry.filesystem.provider;
|
|
4338
|
+
const access2 = entry.filesystem.readOnly ? "read-only" : "read-write";
|
|
4339
|
+
if (entry.state === "mounted") {
|
|
4340
|
+
sandboxAccessible.push(` - ${mountPath}: ${fsName} (${access2})`);
|
|
4341
|
+
} else {
|
|
4342
|
+
workspaceOnly.push(` - ${mountPath}: ${fsName} (${access2})`);
|
|
4343
|
+
}
|
|
4344
|
+
}
|
|
4345
|
+
if (sandboxAccessible.length) {
|
|
4346
|
+
parts.push(`Sandbox-mounted filesystems (accessible in shell commands):
|
|
4347
|
+
${sandboxAccessible.join("\n")}`);
|
|
4348
|
+
}
|
|
4349
|
+
if (workspaceOnly.length) {
|
|
4350
|
+
parts.push(
|
|
4351
|
+
`Workspace-only filesystems (use file tools, NOT available in shell commands):
|
|
4352
|
+
${workspaceOnly.join("\n")}`
|
|
4353
|
+
);
|
|
4354
|
+
}
|
|
4355
|
+
} else {
|
|
4356
|
+
const fsInstructions = this._fs?.getInstructions?.(opts);
|
|
4357
|
+
if (fsInstructions) parts.push(fsInstructions);
|
|
4358
|
+
}
|
|
4359
|
+
return parts.join("\n\n");
|
|
4360
|
+
}
|
|
4200
4361
|
/**
|
|
4201
4362
|
* Get information about how filesystem and sandbox paths relate.
|
|
4202
4363
|
* Useful for understanding how to access workspace files from sandbox code.
|
|
4203
4364
|
*
|
|
4365
|
+
* @deprecated Use {@link getInstructions} instead. `getInstructions()` is
|
|
4366
|
+
* mount-state-aware and feeds into the system message via
|
|
4367
|
+
* `WorkspaceInstructionsProcessor`.
|
|
4368
|
+
*
|
|
4204
4369
|
* @returns PathContext with paths and instructions from providers
|
|
4205
4370
|
*/
|
|
4206
4371
|
getPathContext() {
|
|
@@ -4236,6 +4401,274 @@ var Workspace = class {
|
|
|
4236
4401
|
}
|
|
4237
4402
|
}
|
|
4238
4403
|
};
|
|
4404
|
+
var ProcessHandle = class {
|
|
4405
|
+
/** The command that was spawned (set by the process manager) */
|
|
4406
|
+
command;
|
|
4407
|
+
/**
|
|
4408
|
+
* Wait for the process to finish and return the result.
|
|
4409
|
+
*
|
|
4410
|
+
* Optionally pass `onStdout`/`onStderr` callbacks to stream output chunks
|
|
4411
|
+
* while waiting. The callbacks are automatically removed when `wait()`
|
|
4412
|
+
* resolves, so there's no cleanup needed by the caller.
|
|
4413
|
+
*
|
|
4414
|
+
* Subclasses implement `wait()` with platform-specific logic — the base
|
|
4415
|
+
* constructor wraps it to handle the optional streaming callbacks.
|
|
4416
|
+
*/
|
|
4417
|
+
async wait(_options) {
|
|
4418
|
+
throw new Error(`${this.constructor.name} must implement wait()`);
|
|
4419
|
+
}
|
|
4420
|
+
_stdout = "";
|
|
4421
|
+
_stderr = "";
|
|
4422
|
+
_stdoutListeners = /* @__PURE__ */ new Set();
|
|
4423
|
+
_stderrListeners = /* @__PURE__ */ new Set();
|
|
4424
|
+
_reader;
|
|
4425
|
+
_writer;
|
|
4426
|
+
constructor(options) {
|
|
4427
|
+
if (options?.onStdout) this._stdoutListeners.add(options.onStdout);
|
|
4428
|
+
if (options?.onStderr) this._stderrListeners.add(options.onStderr);
|
|
4429
|
+
const implWait = this.wait.bind(this);
|
|
4430
|
+
this.wait = async (waitOptions) => {
|
|
4431
|
+
if (waitOptions?.onStdout) this._stdoutListeners.add(waitOptions.onStdout);
|
|
4432
|
+
if (waitOptions?.onStderr) this._stderrListeners.add(waitOptions.onStderr);
|
|
4433
|
+
try {
|
|
4434
|
+
return await implWait();
|
|
4435
|
+
} finally {
|
|
4436
|
+
if (waitOptions?.onStdout) this._stdoutListeners.delete(waitOptions.onStdout);
|
|
4437
|
+
if (waitOptions?.onStderr) this._stderrListeners.delete(waitOptions.onStderr);
|
|
4438
|
+
}
|
|
4439
|
+
};
|
|
4440
|
+
}
|
|
4441
|
+
/** Accumulated stdout so far */
|
|
4442
|
+
get stdout() {
|
|
4443
|
+
return this._stdout;
|
|
4444
|
+
}
|
|
4445
|
+
/** Accumulated stderr so far */
|
|
4446
|
+
get stderr() {
|
|
4447
|
+
return this._stderr;
|
|
4448
|
+
}
|
|
4449
|
+
/**
|
|
4450
|
+
* Emit stdout data — accumulates, dispatches to user callback, and pushes to reader stream.
|
|
4451
|
+
* @internal Called by subclasses and process managers to dispatch transport data.
|
|
4452
|
+
*/
|
|
4453
|
+
emitStdout(data) {
|
|
4454
|
+
this._stdout += data;
|
|
4455
|
+
for (const listener of this._stdoutListeners) listener(data);
|
|
4456
|
+
this._reader?.push(data);
|
|
4457
|
+
}
|
|
4458
|
+
/**
|
|
4459
|
+
* Emit stderr data — accumulates and dispatches to user callback.
|
|
4460
|
+
* @internal Called by subclasses and process managers to dispatch transport data.
|
|
4461
|
+
*/
|
|
4462
|
+
emitStderr(data) {
|
|
4463
|
+
this._stderr += data;
|
|
4464
|
+
for (const listener of this._stderrListeners) listener(data);
|
|
4465
|
+
}
|
|
4466
|
+
/** Readable stream of stdout (for use with StreamMessageReader, pipes, etc.) */
|
|
4467
|
+
get reader() {
|
|
4468
|
+
if (!this._reader) {
|
|
4469
|
+
this._reader = new Readable({ read() {
|
|
4470
|
+
} });
|
|
4471
|
+
void this.wait().then(
|
|
4472
|
+
() => this._reader.push(null),
|
|
4473
|
+
() => this._reader.push(null)
|
|
4474
|
+
);
|
|
4475
|
+
}
|
|
4476
|
+
return this._reader;
|
|
4477
|
+
}
|
|
4478
|
+
/** Writable stream to stdin (for use with StreamMessageWriter, pipes, etc.) */
|
|
4479
|
+
get writer() {
|
|
4480
|
+
if (!this._writer) {
|
|
4481
|
+
this._writer = new Writable({
|
|
4482
|
+
write: (chunk, _encoding, cb) => {
|
|
4483
|
+
this.sendStdin(chunk.toString()).then(() => cb(), cb);
|
|
4484
|
+
}
|
|
4485
|
+
});
|
|
4486
|
+
}
|
|
4487
|
+
return this._writer;
|
|
4488
|
+
}
|
|
4489
|
+
};
|
|
4490
|
+
|
|
4491
|
+
// src/workspace/sandbox/process-manager/process-manager.ts
|
|
4492
|
+
var SandboxProcessManager = class {
|
|
4493
|
+
/**
|
|
4494
|
+
* The sandbox this process manager belongs to.
|
|
4495
|
+
* Set automatically by MastraSandbox when processes are passed into the constructor.
|
|
4496
|
+
* @internal
|
|
4497
|
+
*/
|
|
4498
|
+
sandbox;
|
|
4499
|
+
env;
|
|
4500
|
+
/** Tracked process handles keyed by PID. Populated by spawn(), used by get()/kill(). */
|
|
4501
|
+
_tracked = /* @__PURE__ */ new Map();
|
|
4502
|
+
/** PIDs that have been read after exit and should not be re-discovered by subclass fallbacks. */
|
|
4503
|
+
_dismissed = /* @__PURE__ */ new Set();
|
|
4504
|
+
constructor({ env = {} } = {}) {
|
|
4505
|
+
this.env = env;
|
|
4506
|
+
const impl = {
|
|
4507
|
+
spawn: this.spawn.bind(this),
|
|
4508
|
+
list: this.list.bind(this),
|
|
4509
|
+
get: this.get.bind(this)
|
|
4510
|
+
};
|
|
4511
|
+
this.spawn = async (...args) => {
|
|
4512
|
+
await this.sandbox.ensureRunning();
|
|
4513
|
+
const handle = await impl.spawn(...args);
|
|
4514
|
+
handle.command = args[0];
|
|
4515
|
+
return handle;
|
|
4516
|
+
};
|
|
4517
|
+
this.list = async () => {
|
|
4518
|
+
await this.sandbox.ensureRunning();
|
|
4519
|
+
return impl.list();
|
|
4520
|
+
};
|
|
4521
|
+
this.get = async (...args) => {
|
|
4522
|
+
await this.sandbox.ensureRunning();
|
|
4523
|
+
if (this._dismissed.has(args[0])) return void 0;
|
|
4524
|
+
const handle = await impl.get(...args);
|
|
4525
|
+
if (handle?.exitCode !== void 0) {
|
|
4526
|
+
this._tracked.delete(handle.pid);
|
|
4527
|
+
this._dismissed.add(handle.pid);
|
|
4528
|
+
}
|
|
4529
|
+
return handle;
|
|
4530
|
+
};
|
|
4531
|
+
}
|
|
4532
|
+
/** Spawn a process. */
|
|
4533
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
4534
|
+
async spawn(command, options = {}) {
|
|
4535
|
+
throw new Error(`${this.constructor.name} must implement spawn()`);
|
|
4536
|
+
}
|
|
4537
|
+
/** List all tracked processes. */
|
|
4538
|
+
async list() {
|
|
4539
|
+
throw new Error(`${this.constructor.name} must implement list()`);
|
|
4540
|
+
}
|
|
4541
|
+
/** Get a handle to a process by PID. Subclasses can override for fallback behavior. */
|
|
4542
|
+
async get(pid) {
|
|
4543
|
+
return this._tracked.get(pid);
|
|
4544
|
+
}
|
|
4545
|
+
/** Kill a process by PID. Returns true if killed, false if not found. */
|
|
4546
|
+
async kill(pid) {
|
|
4547
|
+
const handle = await this.get(pid);
|
|
4548
|
+
if (!handle) return false;
|
|
4549
|
+
const killed = await handle.kill();
|
|
4550
|
+
if (killed) {
|
|
4551
|
+
await handle.wait().catch(() => {
|
|
4552
|
+
});
|
|
4553
|
+
}
|
|
4554
|
+
this._tracked.delete(pid);
|
|
4555
|
+
this._dismissed.add(pid);
|
|
4556
|
+
return killed;
|
|
4557
|
+
}
|
|
4558
|
+
};
|
|
4559
|
+
|
|
4560
|
+
// src/workspace/sandbox/local-process-manager.ts
|
|
4561
|
+
var LocalProcessHandle = class extends ProcessHandle {
|
|
4562
|
+
pid;
|
|
4563
|
+
exitCode;
|
|
4564
|
+
proc;
|
|
4565
|
+
waitPromise;
|
|
4566
|
+
startTime;
|
|
4567
|
+
constructor(proc, startTime, options) {
|
|
4568
|
+
super(options);
|
|
4569
|
+
if (!proc.pid) {
|
|
4570
|
+
throw new Error("Process has no PID - it may have failed to spawn");
|
|
4571
|
+
}
|
|
4572
|
+
this.pid = proc.pid;
|
|
4573
|
+
this.proc = proc;
|
|
4574
|
+
this.startTime = startTime;
|
|
4575
|
+
let timedOut = false;
|
|
4576
|
+
const timeoutId = options?.timeout ? setTimeout(() => {
|
|
4577
|
+
timedOut = true;
|
|
4578
|
+
try {
|
|
4579
|
+
process.kill(-this.pid, "SIGTERM");
|
|
4580
|
+
} catch {
|
|
4581
|
+
proc.kill("SIGTERM");
|
|
4582
|
+
}
|
|
4583
|
+
}, options.timeout) : void 0;
|
|
4584
|
+
this.waitPromise = new Promise((resolve3) => {
|
|
4585
|
+
proc.on("close", (code, signal) => {
|
|
4586
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
4587
|
+
if (timedOut) {
|
|
4588
|
+
const timeoutMsg = `
|
|
4589
|
+
Process timed out after ${options.timeout}ms`;
|
|
4590
|
+
this.emitStderr(timeoutMsg);
|
|
4591
|
+
this.exitCode = 124;
|
|
4592
|
+
} else {
|
|
4593
|
+
this.exitCode = signal && code === null ? 128 : code ?? 0;
|
|
4594
|
+
}
|
|
4595
|
+
resolve3({
|
|
4596
|
+
success: this.exitCode === 0,
|
|
4597
|
+
exitCode: this.exitCode,
|
|
4598
|
+
stdout: this.stdout,
|
|
4599
|
+
stderr: this.stderr,
|
|
4600
|
+
executionTimeMs: Date.now() - this.startTime,
|
|
4601
|
+
killed: signal !== null,
|
|
4602
|
+
timedOut
|
|
4603
|
+
});
|
|
4604
|
+
});
|
|
4605
|
+
proc.on("error", (err) => {
|
|
4606
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
4607
|
+
this.emitStderr(err.message);
|
|
4608
|
+
this.exitCode = 1;
|
|
4609
|
+
resolve3({
|
|
4610
|
+
success: false,
|
|
4611
|
+
exitCode: 1,
|
|
4612
|
+
stdout: this.stdout,
|
|
4613
|
+
stderr: this.stderr,
|
|
4614
|
+
executionTimeMs: Date.now() - this.startTime
|
|
4615
|
+
});
|
|
4616
|
+
});
|
|
4617
|
+
});
|
|
4618
|
+
proc.stdout?.on("data", (data) => {
|
|
4619
|
+
this.emitStdout(data.toString());
|
|
4620
|
+
});
|
|
4621
|
+
proc.stderr?.on("data", (data) => {
|
|
4622
|
+
this.emitStderr(data.toString());
|
|
4623
|
+
});
|
|
4624
|
+
}
|
|
4625
|
+
async wait() {
|
|
4626
|
+
return this.waitPromise;
|
|
4627
|
+
}
|
|
4628
|
+
async kill() {
|
|
4629
|
+
if (this.exitCode !== void 0) return false;
|
|
4630
|
+
try {
|
|
4631
|
+
process.kill(-this.pid, "SIGKILL");
|
|
4632
|
+
return true;
|
|
4633
|
+
} catch {
|
|
4634
|
+
return this.proc.kill("SIGKILL");
|
|
4635
|
+
}
|
|
4636
|
+
}
|
|
4637
|
+
async sendStdin(data) {
|
|
4638
|
+
if (this.exitCode !== void 0) {
|
|
4639
|
+
throw new Error(`Process ${this.pid} has already exited with code ${this.exitCode}`);
|
|
4640
|
+
}
|
|
4641
|
+
if (!this.proc.stdin) {
|
|
4642
|
+
throw new Error(`Process ${this.pid} does not have stdin available`);
|
|
4643
|
+
}
|
|
4644
|
+
return new Promise((resolve3, reject) => {
|
|
4645
|
+
this.proc.stdin.write(data, (err) => err ? reject(err) : resolve3());
|
|
4646
|
+
});
|
|
4647
|
+
}
|
|
4648
|
+
};
|
|
4649
|
+
var LocalProcessManager = class extends SandboxProcessManager {
|
|
4650
|
+
async spawn(command, options = {}) {
|
|
4651
|
+
const cwd = options.cwd ?? this.sandbox.workingDirectory;
|
|
4652
|
+
const env = this.sandbox.buildEnv(options.env);
|
|
4653
|
+
const wrapped = this.sandbox.wrapCommandForIsolation(command);
|
|
4654
|
+
const proc = childProcess.spawn(wrapped.command, wrapped.args, {
|
|
4655
|
+
cwd,
|
|
4656
|
+
env,
|
|
4657
|
+
shell: this.sandbox.isolation === "none",
|
|
4658
|
+
detached: true
|
|
4659
|
+
});
|
|
4660
|
+
const handle = new LocalProcessHandle(proc, Date.now(), options);
|
|
4661
|
+
this._tracked.set(handle.pid, handle);
|
|
4662
|
+
return handle;
|
|
4663
|
+
}
|
|
4664
|
+
async list() {
|
|
4665
|
+
return Array.from(this._tracked.values()).map((handle) => ({
|
|
4666
|
+
pid: handle.pid,
|
|
4667
|
+
running: handle.exitCode === void 0,
|
|
4668
|
+
exitCode: handle.exitCode
|
|
4669
|
+
}));
|
|
4670
|
+
}
|
|
4671
|
+
};
|
|
4239
4672
|
function commandExists(command) {
|
|
4240
4673
|
try {
|
|
4241
4674
|
execFileSync("which", [command], { stdio: "ignore" });
|
|
@@ -4376,10 +4809,10 @@ function generateSeatbeltProfile(workspacePath, config) {
|
|
|
4376
4809
|
}
|
|
4377
4810
|
return lines.join("\n");
|
|
4378
4811
|
}
|
|
4379
|
-
function buildSeatbeltCommand(command,
|
|
4812
|
+
function buildSeatbeltCommand(command, profile) {
|
|
4380
4813
|
return {
|
|
4381
4814
|
command: "sandbox-exec",
|
|
4382
|
-
args: ["-p", profile,
|
|
4815
|
+
args: ["-p", profile, "sh", "-c", command]
|
|
4383
4816
|
};
|
|
4384
4817
|
}
|
|
4385
4818
|
|
|
@@ -4401,11 +4834,11 @@ var DEFAULT_READONLY_BINDS = [
|
|
|
4401
4834
|
"/etc/ld.so.cache",
|
|
4402
4835
|
"/etc/localtime"
|
|
4403
4836
|
];
|
|
4404
|
-
function buildBwrapCommand(command,
|
|
4837
|
+
function buildBwrapCommand(command, workspacePath, config) {
|
|
4405
4838
|
if (config.bwrapArgs && config.bwrapArgs.length > 0) {
|
|
4406
4839
|
return {
|
|
4407
4840
|
command: "bwrap",
|
|
4408
|
-
args: [...config.bwrapArgs, "--",
|
|
4841
|
+
args: [...config.bwrapArgs, "--", "sh", "-c", command]
|
|
4409
4842
|
};
|
|
4410
4843
|
}
|
|
4411
4844
|
const bwrapArgs = [];
|
|
@@ -4424,8 +4857,8 @@ function buildBwrapCommand(command, args, workspacePath, config) {
|
|
|
4424
4857
|
bwrapArgs.push("--ro-bind", path4, path4);
|
|
4425
4858
|
}
|
|
4426
4859
|
if (config.allowSystemBinaries !== false) {
|
|
4427
|
-
const
|
|
4428
|
-
const nodeDir =
|
|
4860
|
+
const nodePath4 = process.execPath;
|
|
4861
|
+
const nodeDir = nodePath4.substring(0, nodePath4.lastIndexOf("/"));
|
|
4429
4862
|
if (!DEFAULT_READONLY_BINDS.some((p) => nodeDir.startsWith(p))) {
|
|
4430
4863
|
bwrapArgs.push("--ro-bind", nodeDir, nodeDir);
|
|
4431
4864
|
}
|
|
@@ -4438,7 +4871,7 @@ function buildBwrapCommand(command, args, workspacePath, config) {
|
|
|
4438
4871
|
}
|
|
4439
4872
|
bwrapArgs.push("--chdir", workspacePath);
|
|
4440
4873
|
bwrapArgs.push("--die-with-parent");
|
|
4441
|
-
bwrapArgs.push("--",
|
|
4874
|
+
bwrapArgs.push("--", "sh", "-c", command);
|
|
4442
4875
|
return {
|
|
4443
4876
|
command: "bwrap",
|
|
4444
4877
|
args: bwrapArgs
|
|
@@ -4446,141 +4879,59 @@ function buildBwrapCommand(command, args, workspacePath, config) {
|
|
|
4446
4879
|
}
|
|
4447
4880
|
|
|
4448
4881
|
// src/workspace/sandbox/native-sandbox/wrapper.ts
|
|
4449
|
-
function wrapCommand(command,
|
|
4882
|
+
function wrapCommand(command, options) {
|
|
4450
4883
|
switch (options.backend) {
|
|
4451
4884
|
case "seatbelt": {
|
|
4452
4885
|
const profile = options.seatbeltProfile ?? generateSeatbeltProfile(options.workspacePath, options.config);
|
|
4453
|
-
return buildSeatbeltCommand(command,
|
|
4886
|
+
return buildSeatbeltCommand(command, profile);
|
|
4454
4887
|
}
|
|
4455
4888
|
case "bwrap": {
|
|
4456
|
-
return buildBwrapCommand(command,
|
|
4889
|
+
return buildBwrapCommand(command, options.workspacePath, options.config);
|
|
4457
4890
|
}
|
|
4458
4891
|
case "none":
|
|
4459
4892
|
default:
|
|
4460
|
-
return { command, args };
|
|
4893
|
+
return { command, args: [] };
|
|
4461
4894
|
}
|
|
4462
4895
|
}
|
|
4463
4896
|
|
|
4464
4897
|
// src/workspace/sandbox/local-sandbox.ts
|
|
4465
|
-
function execWithStreaming(command, args, options) {
|
|
4466
|
-
const { timeout, onStdout, onStderr, cwd, env, ...spawnOptions } = options;
|
|
4467
|
-
return new Promise((resolve3, reject) => {
|
|
4468
|
-
const proc = childProcess.spawn(command, args, { cwd, env, ...spawnOptions });
|
|
4469
|
-
let stdout = "";
|
|
4470
|
-
let stderr = "";
|
|
4471
|
-
let killed = false;
|
|
4472
|
-
const timeoutId = timeout ? setTimeout(() => {
|
|
4473
|
-
killed = true;
|
|
4474
|
-
proc.kill("SIGTERM");
|
|
4475
|
-
}, timeout) : void 0;
|
|
4476
|
-
proc.stdout.on("data", (data) => {
|
|
4477
|
-
const str = data.toString();
|
|
4478
|
-
stdout += str;
|
|
4479
|
-
onStdout?.(str);
|
|
4480
|
-
});
|
|
4481
|
-
proc.stderr.on("data", (data) => {
|
|
4482
|
-
const str = data.toString();
|
|
4483
|
-
stderr += str;
|
|
4484
|
-
onStderr?.(str);
|
|
4485
|
-
});
|
|
4486
|
-
proc.on("error", (err) => {
|
|
4487
|
-
if (timeoutId) clearTimeout(timeoutId);
|
|
4488
|
-
const errorMsg = err.message;
|
|
4489
|
-
stderr += errorMsg;
|
|
4490
|
-
onStderr?.(errorMsg);
|
|
4491
|
-
reject(err);
|
|
4492
|
-
});
|
|
4493
|
-
proc.on("close", (code, signal) => {
|
|
4494
|
-
if (timeoutId) clearTimeout(timeoutId);
|
|
4495
|
-
if (killed) {
|
|
4496
|
-
const timeoutMsg = `
|
|
4497
|
-
Process timed out after ${timeout}ms`;
|
|
4498
|
-
onStderr?.(timeoutMsg);
|
|
4499
|
-
resolve3({ stdout, stderr: stderr + timeoutMsg, exitCode: 124 });
|
|
4500
|
-
} else if (signal) {
|
|
4501
|
-
const signalMsg = `
|
|
4502
|
-
Process terminated by ${signal}`;
|
|
4503
|
-
onStderr?.(signalMsg);
|
|
4504
|
-
resolve3({ stdout, stderr: stderr + signalMsg, exitCode: 128 });
|
|
4505
|
-
} else {
|
|
4506
|
-
resolve3({ stdout, stderr, exitCode: code ?? 0 });
|
|
4507
|
-
}
|
|
4508
|
-
});
|
|
4509
|
-
});
|
|
4510
|
-
}
|
|
4511
4898
|
var LocalSandbox = class extends MastraSandbox {
|
|
4512
4899
|
id;
|
|
4513
4900
|
name = "LocalSandbox";
|
|
4514
4901
|
provider = "local";
|
|
4515
4902
|
status = "pending";
|
|
4516
|
-
|
|
4903
|
+
workingDirectory;
|
|
4904
|
+
isolation;
|
|
4517
4905
|
env;
|
|
4518
|
-
timeout;
|
|
4519
|
-
_isolation;
|
|
4520
4906
|
_nativeSandboxConfig;
|
|
4521
4907
|
_seatbeltProfile;
|
|
4522
4908
|
_seatbeltProfilePath;
|
|
4523
4909
|
_sandboxFolderPath;
|
|
4524
4910
|
_userProvidedProfilePath = false;
|
|
4525
4911
|
_createdAt;
|
|
4526
|
-
|
|
4527
|
-
* The working directory where commands are executed.
|
|
4528
|
-
*/
|
|
4529
|
-
get workingDirectory() {
|
|
4530
|
-
return this._workingDirectory;
|
|
4531
|
-
}
|
|
4532
|
-
/**
|
|
4533
|
-
* The isolation backend being used.
|
|
4534
|
-
*/
|
|
4535
|
-
get isolation() {
|
|
4536
|
-
return this._isolation;
|
|
4537
|
-
}
|
|
4538
|
-
/**
|
|
4539
|
-
* Detect the best available isolation backend for this platform.
|
|
4540
|
-
* Returns detection result with backend recommendation and availability.
|
|
4541
|
-
*
|
|
4542
|
-
* @example
|
|
4543
|
-
* ```typescript
|
|
4544
|
-
* const result = LocalSandbox.detectIsolation();
|
|
4545
|
-
* const sandbox = new LocalSandbox({
|
|
4546
|
-
* isolation: result.available ? result.backend : 'none',
|
|
4547
|
-
* });
|
|
4548
|
-
* ```
|
|
4549
|
-
*/
|
|
4550
|
-
static detectIsolation() {
|
|
4551
|
-
return detectIsolation();
|
|
4552
|
-
}
|
|
4912
|
+
_instructionsOverride;
|
|
4553
4913
|
constructor(options = {}) {
|
|
4554
|
-
super({ ...options, name: "LocalSandbox" });
|
|
4555
|
-
this.id = options.id ?? this.generateId();
|
|
4556
|
-
this._createdAt = /* @__PURE__ */ new Date();
|
|
4557
|
-
this._workingDirectory = options.workingDirectory ?? nodePath.join(process.cwd(), ".sandbox");
|
|
4558
|
-
this.env = options.env ?? {};
|
|
4559
|
-
this.timeout = options.timeout;
|
|
4560
|
-
this._nativeSandboxConfig = options.nativeSandbox ?? {};
|
|
4561
4914
|
const requestedIsolation = options.isolation ?? "none";
|
|
4562
4915
|
if (requestedIsolation !== "none" && !isIsolationAvailable(requestedIsolation)) {
|
|
4563
4916
|
const detection = detectIsolation();
|
|
4564
4917
|
throw new IsolationUnavailableError(requestedIsolation, detection.message);
|
|
4565
4918
|
}
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
|
|
4572
|
-
|
|
4573
|
-
|
|
4574
|
-
|
|
4575
|
-
|
|
4576
|
-
|
|
4577
|
-
|
|
4578
|
-
PATH: process.env.PATH,
|
|
4579
|
-
// Always include PATH for finding executables
|
|
4580
|
-
...this.env,
|
|
4581
|
-
...additionalEnv
|
|
4582
|
-
};
|
|
4919
|
+
super({
|
|
4920
|
+
...options,
|
|
4921
|
+
name: "LocalSandbox",
|
|
4922
|
+
processes: new LocalProcessManager({ env: options.env ?? {} })
|
|
4923
|
+
});
|
|
4924
|
+
this.id = options.id ?? this.generateId();
|
|
4925
|
+
this._createdAt = /* @__PURE__ */ new Date();
|
|
4926
|
+
this.workingDirectory = options.workingDirectory ?? nodePath.join(process.cwd(), ".sandbox");
|
|
4927
|
+
this.env = options.env ?? {};
|
|
4928
|
+
this._nativeSandboxConfig = options.nativeSandbox ?? {};
|
|
4929
|
+
this.isolation = requestedIsolation;
|
|
4930
|
+
this._instructionsOverride = options.instructions;
|
|
4583
4931
|
}
|
|
4932
|
+
// ---------------------------------------------------------------------------
|
|
4933
|
+
// Lifecycle
|
|
4934
|
+
// ---------------------------------------------------------------------------
|
|
4584
4935
|
/**
|
|
4585
4936
|
* Start the local sandbox.
|
|
4586
4937
|
* Creates working directory and sets up seatbelt profile if using macOS isolation.
|
|
@@ -4588,11 +4939,11 @@ var LocalSandbox = class extends MastraSandbox {
|
|
|
4588
4939
|
*/
|
|
4589
4940
|
async start() {
|
|
4590
4941
|
this.logger.debug("[LocalSandbox] Starting sandbox", {
|
|
4591
|
-
workingDirectory: this.
|
|
4592
|
-
isolation: this.
|
|
4942
|
+
workingDirectory: this.workingDirectory,
|
|
4943
|
+
isolation: this.isolation
|
|
4593
4944
|
});
|
|
4594
4945
|
await fs2.mkdir(this.workingDirectory, { recursive: true });
|
|
4595
|
-
if (this.
|
|
4946
|
+
if (this.isolation === "seatbelt") {
|
|
4596
4947
|
const userProvidedPath = this._nativeSandboxConfig.seatbeltProfilePath;
|
|
4597
4948
|
if (userProvidedPath) {
|
|
4598
4949
|
this._seatbeltProfilePath = userProvidedPath;
|
|
@@ -4616,14 +4967,14 @@ var LocalSandbox = class extends MastraSandbox {
|
|
|
4616
4967
|
await fs2.writeFile(this._seatbeltProfilePath, this._seatbeltProfile, "utf-8");
|
|
4617
4968
|
}
|
|
4618
4969
|
}
|
|
4619
|
-
this.logger.debug("[LocalSandbox] Sandbox started", { workingDirectory: this.
|
|
4970
|
+
this.logger.debug("[LocalSandbox] Sandbox started", { workingDirectory: this.workingDirectory });
|
|
4620
4971
|
}
|
|
4621
4972
|
/**
|
|
4622
4973
|
* Stop the local sandbox.
|
|
4623
4974
|
* Status management is handled by the base class.
|
|
4624
4975
|
*/
|
|
4625
4976
|
async stop() {
|
|
4626
|
-
this.logger.debug("[LocalSandbox] Stopping sandbox", { workingDirectory: this.
|
|
4977
|
+
this.logger.debug("[LocalSandbox] Stopping sandbox", { workingDirectory: this.workingDirectory });
|
|
4627
4978
|
}
|
|
4628
4979
|
/**
|
|
4629
4980
|
* Destroy the local sandbox and clean up resources.
|
|
@@ -4631,7 +4982,9 @@ var LocalSandbox = class extends MastraSandbox {
|
|
|
4631
4982
|
* Status management is handled by the base class.
|
|
4632
4983
|
*/
|
|
4633
4984
|
async destroy() {
|
|
4634
|
-
this.logger.debug("[LocalSandbox] Destroying sandbox", { workingDirectory: this.
|
|
4985
|
+
this.logger.debug("[LocalSandbox] Destroying sandbox", { workingDirectory: this.workingDirectory });
|
|
4986
|
+
const procs = await this.processes.list();
|
|
4987
|
+
await Promise.all(procs.map((p) => this.processes.kill(p.pid)));
|
|
4635
4988
|
if (this._seatbeltProfilePath && !this._userProvidedProfilePath) {
|
|
4636
4989
|
try {
|
|
4637
4990
|
await fs2.unlink(this._seatbeltProfilePath);
|
|
@@ -4649,6 +5002,7 @@ var LocalSandbox = class extends MastraSandbox {
|
|
|
4649
5002
|
this._sandboxFolderPath = void 0;
|
|
4650
5003
|
}
|
|
4651
5004
|
}
|
|
5005
|
+
/** @deprecated Use `status === 'running'` instead. */
|
|
4652
5006
|
async isReady() {
|
|
4653
5007
|
return this.status === "running";
|
|
4654
5008
|
}
|
|
@@ -4667,8 +5021,8 @@ var LocalSandbox = class extends MastraSandbox {
|
|
|
4667
5021
|
workingDirectory: this.workingDirectory,
|
|
4668
5022
|
platform: os.platform(),
|
|
4669
5023
|
nodeVersion: process.version,
|
|
4670
|
-
isolation: this.
|
|
4671
|
-
isolationConfig: this.
|
|
5024
|
+
isolation: this.isolation,
|
|
5025
|
+
isolationConfig: this.isolation !== "none" ? {
|
|
4672
5026
|
allowNetwork: this._nativeSandboxConfig.allowNetwork ?? false,
|
|
4673
5027
|
readOnlyPaths: this._nativeSandboxConfig.readOnlyPaths,
|
|
4674
5028
|
readWritePaths: this._nativeSandboxConfig.readWritePaths
|
|
@@ -4676,63 +5030,61 @@ var LocalSandbox = class extends MastraSandbox {
|
|
|
4676
5030
|
}
|
|
4677
5031
|
};
|
|
4678
5032
|
}
|
|
4679
|
-
getInstructions() {
|
|
4680
|
-
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
return
|
|
5033
|
+
getInstructions(opts) {
|
|
5034
|
+
return resolveInstructions(this._instructionsOverride, () => this._getDefaultInstructions(), opts?.requestContext);
|
|
5035
|
+
}
|
|
5036
|
+
_getDefaultInstructions() {
|
|
5037
|
+
return `Local command execution. Working directory: "${this.workingDirectory}".`;
|
|
5038
|
+
}
|
|
5039
|
+
// ---------------------------------------------------------------------------
|
|
5040
|
+
// Internal Utils
|
|
5041
|
+
// ---------------------------------------------------------------------------
|
|
5042
|
+
generateId() {
|
|
5043
|
+
return `local-sandbox-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
5044
|
+
}
|
|
5045
|
+
/**
|
|
5046
|
+
* Build the environment object for execution.
|
|
5047
|
+
* Always includes PATH by default (needed for finding executables).
|
|
5048
|
+
* Merges the sandbox's configured env with any additional env from the command.
|
|
5049
|
+
* @internal Used by LocalProcessManager.
|
|
5050
|
+
*/
|
|
5051
|
+
buildEnv(additionalEnv) {
|
|
5052
|
+
return {
|
|
5053
|
+
PATH: process.env.PATH,
|
|
5054
|
+
// Always include PATH for finding executables
|
|
5055
|
+
...this.env,
|
|
5056
|
+
...additionalEnv
|
|
5057
|
+
};
|
|
4684
5058
|
}
|
|
4685
5059
|
/**
|
|
4686
5060
|
* Wrap a command with the configured isolation backend.
|
|
5061
|
+
* @internal Used by LocalProcessManager for background process isolation.
|
|
4687
5062
|
*/
|
|
4688
|
-
wrapCommandForIsolation(command
|
|
4689
|
-
if (this.
|
|
4690
|
-
return { command, args };
|
|
5063
|
+
wrapCommandForIsolation(command) {
|
|
5064
|
+
if (this.isolation === "none") {
|
|
5065
|
+
return { command, args: [] };
|
|
4691
5066
|
}
|
|
4692
|
-
return wrapCommand(command,
|
|
4693
|
-
backend: this.
|
|
5067
|
+
return wrapCommand(command, {
|
|
5068
|
+
backend: this.isolation,
|
|
4694
5069
|
workspacePath: this.workingDirectory,
|
|
4695
5070
|
seatbeltProfile: this._seatbeltProfile,
|
|
4696
5071
|
config: this._nativeSandboxConfig
|
|
4697
5072
|
});
|
|
4698
5073
|
}
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
success: result.exitCode === 0,
|
|
4714
|
-
stdout: result.stdout,
|
|
4715
|
-
stderr: result.stderr,
|
|
4716
|
-
exitCode: result.exitCode,
|
|
4717
|
-
executionTimeMs: Date.now() - startTime
|
|
4718
|
-
};
|
|
4719
|
-
this.logger.debug("[LocalSandbox] Command completed", {
|
|
4720
|
-
command,
|
|
4721
|
-
exitCode: commandResult.exitCode,
|
|
4722
|
-
executionTimeMs: commandResult.executionTimeMs
|
|
4723
|
-
});
|
|
4724
|
-
return commandResult;
|
|
4725
|
-
} catch (error) {
|
|
4726
|
-
const executionTimeMs = Date.now() - startTime;
|
|
4727
|
-
this.logger.error("[LocalSandbox] Command failed", { command, error, executionTimeMs });
|
|
4728
|
-
return {
|
|
4729
|
-
success: false,
|
|
4730
|
-
stdout: "",
|
|
4731
|
-
stderr: error instanceof Error ? error.message : String(error),
|
|
4732
|
-
exitCode: 1,
|
|
4733
|
-
executionTimeMs
|
|
4734
|
-
};
|
|
4735
|
-
}
|
|
5074
|
+
/**
|
|
5075
|
+
* Detect the best available isolation backend for this platform.
|
|
5076
|
+
* Returns detection result with backend recommendation and availability.
|
|
5077
|
+
*
|
|
5078
|
+
* @example
|
|
5079
|
+
* ```typescript
|
|
5080
|
+
* const result = LocalSandbox.detectIsolation();
|
|
5081
|
+
* const sandbox = new LocalSandbox({
|
|
5082
|
+
* isolation: result.available ? result.backend : 'none',
|
|
5083
|
+
* });
|
|
5084
|
+
* ```
|
|
5085
|
+
*/
|
|
5086
|
+
static detectIsolation() {
|
|
5087
|
+
return detectIsolation();
|
|
4736
5088
|
}
|
|
4737
5089
|
};
|
|
4738
5090
|
|
|
@@ -4751,7 +5103,9 @@ var WORKSPACE_TOOLS = {
|
|
|
4751
5103
|
AST_EDIT: `${WORKSPACE_TOOLS_PREFIX}_ast_edit`
|
|
4752
5104
|
},
|
|
4753
5105
|
SANDBOX: {
|
|
4754
|
-
EXECUTE_COMMAND: `${WORKSPACE_TOOLS_PREFIX}_execute_command
|
|
5106
|
+
EXECUTE_COMMAND: `${WORKSPACE_TOOLS_PREFIX}_execute_command`,
|
|
5107
|
+
GET_PROCESS_OUTPUT: `${WORKSPACE_TOOLS_PREFIX}_get_process_output`,
|
|
5108
|
+
KILL_PROCESS: `${WORKSPACE_TOOLS_PREFIX}_kill_process`
|
|
4755
5109
|
},
|
|
4756
5110
|
SEARCH: {
|
|
4757
5111
|
SEARCH: `${WORKSPACE_TOOLS_PREFIX}_search`,
|
|
@@ -5164,81 +5518,144 @@ Usage:
|
|
|
5164
5518
|
}
|
|
5165
5519
|
}
|
|
5166
5520
|
});
|
|
5167
|
-
var executeCommandTool = createTool({
|
|
5168
|
-
id: WORKSPACE_TOOLS.SANDBOX.EXECUTE_COMMAND,
|
|
5169
|
-
description: `Execute a shell command in the workspace sandbox.
|
|
5170
5521
|
|
|
5171
|
-
|
|
5172
|
-
|
|
5173
|
-
|
|
5174
|
-
|
|
5175
|
-
|
|
5176
|
-
|
|
5177
|
-
|
|
5178
|
-
|
|
5179
|
-
|
|
5180
|
-
|
|
5181
|
-
|
|
5182
|
-
|
|
5183
|
-
|
|
5184
|
-
|
|
5185
|
-
|
|
5522
|
+
// src/workspace/tools/output-helpers.ts
|
|
5523
|
+
var DEFAULT_TAIL_LINES = 200;
|
|
5524
|
+
var MAX_OUTPUT_CHARS = 3e4;
|
|
5525
|
+
function applyTail(output, tail) {
|
|
5526
|
+
if (!output) return output;
|
|
5527
|
+
const n = Math.abs(tail ?? DEFAULT_TAIL_LINES);
|
|
5528
|
+
if (n === 0) return output;
|
|
5529
|
+
const trailingNewline = output.endsWith("\n");
|
|
5530
|
+
const lines = (trailingNewline ? output.slice(0, -1) : output).split("\n");
|
|
5531
|
+
if (lines.length <= n) return output;
|
|
5532
|
+
const sliced = lines.slice(-n).join("\n");
|
|
5533
|
+
const body = trailingNewline ? sliced + "\n" : sliced;
|
|
5534
|
+
return `[showing last ${n} of ${lines.length} lines]
|
|
5535
|
+
${body}`;
|
|
5536
|
+
}
|
|
5537
|
+
function applyCharLimit(output, limit = MAX_OUTPUT_CHARS) {
|
|
5538
|
+
if (!output || output.length <= limit) return output;
|
|
5539
|
+
const truncated = output.slice(-limit);
|
|
5540
|
+
return `[output truncated: showing last ${limit} of ${output.length} characters]
|
|
5541
|
+
${truncated}`;
|
|
5542
|
+
}
|
|
5543
|
+
function truncateOutput(output, tail, charLimit) {
|
|
5544
|
+
return applyCharLimit(applyTail(output, tail), charLimit);
|
|
5545
|
+
}
|
|
5546
|
+
|
|
5547
|
+
// src/workspace/tools/execute-command.ts
|
|
5548
|
+
var executeCommandInputSchema = z.object({
|
|
5549
|
+
command: z.string().describe('The shell command to execute (e.g., "npm install", "ls -la src/", "cat file.txt | grep error")'),
|
|
5550
|
+
timeout: z.number().nullish().describe("Maximum execution time in milliseconds. Example: 60000 for 1 minute."),
|
|
5551
|
+
cwd: z.string().nullish().describe("Working directory for the command"),
|
|
5552
|
+
tail: z.number().nullish().describe(
|
|
5553
|
+
`For foreground commands: limit output to the last N lines, similar to tail -n. Defaults to ${DEFAULT_TAIL_LINES}. Use 0 for no limit.`
|
|
5554
|
+
)
|
|
5555
|
+
});
|
|
5556
|
+
var executeCommandWithBackgroundSchema = executeCommandInputSchema.extend({
|
|
5557
|
+
background: z.boolean().optional().describe(
|
|
5558
|
+
"Run the command in the background. Returns a PID immediately instead of waiting for completion. Use get_process_output to check on it later."
|
|
5559
|
+
)
|
|
5560
|
+
});
|
|
5561
|
+
async function executeCommand(input, context) {
|
|
5562
|
+
const { command, timeout, cwd, tail } = input;
|
|
5563
|
+
const background = input.background;
|
|
5564
|
+
const { sandbox } = requireSandbox(context);
|
|
5565
|
+
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.SANDBOX.EXECUTE_COMMAND);
|
|
5566
|
+
const toolCallId = context?.agent?.toolCallId;
|
|
5567
|
+
if (background) {
|
|
5568
|
+
if (!sandbox.processes) {
|
|
5569
|
+
throw new SandboxFeatureNotSupportedError("processes");
|
|
5186
5570
|
}
|
|
5187
|
-
await
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
|
|
5191
|
-
|
|
5192
|
-
|
|
5193
|
-
|
|
5194
|
-
|
|
5195
|
-
|
|
5196
|
-
|
|
5197
|
-
|
|
5198
|
-
|
|
5199
|
-
|
|
5200
|
-
|
|
5201
|
-
|
|
5202
|
-
|
|
5203
|
-
|
|
5204
|
-
|
|
5205
|
-
|
|
5206
|
-
|
|
5207
|
-
|
|
5208
|
-
|
|
5209
|
-
|
|
5210
|
-
|
|
5211
|
-
|
|
5212
|
-
|
|
5213
|
-
|
|
5214
|
-
|
|
5215
|
-
|
|
5216
|
-
executionTimeMs: result.executionTimeMs,
|
|
5217
|
-
toolCallId
|
|
5218
|
-
}
|
|
5219
|
-
});
|
|
5220
|
-
if (!result.success) {
|
|
5221
|
-
const parts = [result.stdout, result.stderr].filter(Boolean);
|
|
5222
|
-
parts.push(`Exit code: ${result.exitCode}`);
|
|
5223
|
-
return parts.join("\n");
|
|
5571
|
+
const handle = await sandbox.processes.spawn(command, {
|
|
5572
|
+
cwd: cwd ?? void 0,
|
|
5573
|
+
timeout: timeout ?? void 0
|
|
5574
|
+
});
|
|
5575
|
+
return `Started background process (PID: ${handle.pid})`;
|
|
5576
|
+
}
|
|
5577
|
+
if (!sandbox.executeCommand) {
|
|
5578
|
+
throw new SandboxFeatureNotSupportedError("executeCommand");
|
|
5579
|
+
}
|
|
5580
|
+
const startedAt = Date.now();
|
|
5581
|
+
let stdout = "";
|
|
5582
|
+
let stderr = "";
|
|
5583
|
+
try {
|
|
5584
|
+
const result = await sandbox.executeCommand(command, [], {
|
|
5585
|
+
timeout: timeout ?? void 0,
|
|
5586
|
+
cwd: cwd ?? void 0,
|
|
5587
|
+
onStdout: async (data) => {
|
|
5588
|
+
stdout += data;
|
|
5589
|
+
await context?.writer?.custom({
|
|
5590
|
+
type: "data-sandbox-stdout",
|
|
5591
|
+
data: { output: data, timestamp: Date.now(), toolCallId }
|
|
5592
|
+
});
|
|
5593
|
+
},
|
|
5594
|
+
onStderr: async (data) => {
|
|
5595
|
+
stderr += data;
|
|
5596
|
+
await context?.writer?.custom({
|
|
5597
|
+
type: "data-sandbox-stderr",
|
|
5598
|
+
data: { output: data, timestamp: Date.now(), toolCallId }
|
|
5599
|
+
});
|
|
5224
5600
|
}
|
|
5225
|
-
|
|
5226
|
-
|
|
5227
|
-
|
|
5228
|
-
|
|
5229
|
-
|
|
5230
|
-
|
|
5231
|
-
|
|
5232
|
-
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
const parts = [stdout, stderr].filter(Boolean);
|
|
5237
|
-
|
|
5238
|
-
parts.push(`Error: ${errorMessage}`);
|
|
5601
|
+
});
|
|
5602
|
+
await context?.writer?.custom({
|
|
5603
|
+
type: "data-sandbox-exit",
|
|
5604
|
+
data: {
|
|
5605
|
+
exitCode: result.exitCode,
|
|
5606
|
+
success: result.success,
|
|
5607
|
+
executionTimeMs: result.executionTimeMs,
|
|
5608
|
+
toolCallId
|
|
5609
|
+
}
|
|
5610
|
+
});
|
|
5611
|
+
if (!result.success) {
|
|
5612
|
+
const parts = [truncateOutput(result.stdout, tail), truncateOutput(result.stderr, tail)].filter(Boolean);
|
|
5613
|
+
parts.push(`Exit code: ${result.exitCode}`);
|
|
5239
5614
|
return parts.join("\n");
|
|
5240
5615
|
}
|
|
5616
|
+
return truncateOutput(result.stdout, tail) || "(no output)";
|
|
5617
|
+
} catch (error) {
|
|
5618
|
+
await context?.writer?.custom({
|
|
5619
|
+
type: "data-sandbox-exit",
|
|
5620
|
+
data: {
|
|
5621
|
+
exitCode: -1,
|
|
5622
|
+
success: false,
|
|
5623
|
+
executionTimeMs: Date.now() - startedAt,
|
|
5624
|
+
toolCallId
|
|
5625
|
+
}
|
|
5626
|
+
});
|
|
5627
|
+
const parts = [truncateOutput(stdout, tail), truncateOutput(stderr, tail)].filter(Boolean);
|
|
5628
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
5629
|
+
parts.push(`Error: ${errorMessage}`);
|
|
5630
|
+
return parts.join("\n");
|
|
5241
5631
|
}
|
|
5632
|
+
}
|
|
5633
|
+
var baseDescription = `Execute a shell command in the workspace sandbox.
|
|
5634
|
+
|
|
5635
|
+
Examples:
|
|
5636
|
+
"npm install && npm run build"
|
|
5637
|
+
"ls -la src/"
|
|
5638
|
+
"cat config.json | jq '.database'"
|
|
5639
|
+
"cd /app && python main.py"
|
|
5640
|
+
|
|
5641
|
+
Usage:
|
|
5642
|
+
- Commands run in a shell, so pipes, redirects, and chaining (&&, ||, ;) all work.
|
|
5643
|
+
- Always quote file paths that contain spaces (e.g., cd "/path/with spaces").
|
|
5644
|
+
- Use the timeout parameter to limit execution time. Behavior when omitted depends on the sandbox provider.
|
|
5645
|
+
- Optionally use cwd to override the working directory. Commands run from the sandbox default if omitted.`;
|
|
5646
|
+
var executeCommandTool = createTool({
|
|
5647
|
+
id: WORKSPACE_TOOLS.SANDBOX.EXECUTE_COMMAND,
|
|
5648
|
+
description: baseDescription,
|
|
5649
|
+
inputSchema: executeCommandInputSchema,
|
|
5650
|
+
execute: executeCommand
|
|
5651
|
+
});
|
|
5652
|
+
var executeCommandWithBackgroundTool = createTool({
|
|
5653
|
+
id: WORKSPACE_TOOLS.SANDBOX.EXECUTE_COMMAND,
|
|
5654
|
+
description: `${baseDescription}
|
|
5655
|
+
|
|
5656
|
+
Set background: true to run long-running commands (dev servers, watchers) without blocking. You'll get a PID to track the process.`,
|
|
5657
|
+
inputSchema: executeCommandWithBackgroundSchema,
|
|
5658
|
+
execute: executeCommand
|
|
5242
5659
|
});
|
|
5243
5660
|
var fileStatTool = createTool({
|
|
5244
5661
|
id: WORKSPACE_TOOLS.FILESYSTEM.FILE_STAT,
|
|
@@ -5264,6 +5681,82 @@ var fileStatTool = createTool({
|
|
|
5264
5681
|
}
|
|
5265
5682
|
}
|
|
5266
5683
|
});
|
|
5684
|
+
var getProcessOutputTool = createTool({
|
|
5685
|
+
id: WORKSPACE_TOOLS.SANDBOX.GET_PROCESS_OUTPUT,
|
|
5686
|
+
description: `Get the current output (stdout, stderr) and status of a background process by its PID.
|
|
5687
|
+
|
|
5688
|
+
Use this after starting a background command with execute_command (background: true) to check if the process is still running and read its output.`,
|
|
5689
|
+
inputSchema: z.object({
|
|
5690
|
+
pid: z.number().describe("The process ID returned when the background command was started"),
|
|
5691
|
+
tail: z.number().optional().describe(
|
|
5692
|
+
`Number of lines to return, similar to tail -n. Positive or negative returns last N lines from end. Defaults to ${DEFAULT_TAIL_LINES}. Use 0 for no limit.`
|
|
5693
|
+
),
|
|
5694
|
+
wait: z.boolean().optional().describe(
|
|
5695
|
+
"If true, block until the process exits and return the final output. Useful for short-lived background commands where you want to wait for the result."
|
|
5696
|
+
)
|
|
5697
|
+
}),
|
|
5698
|
+
execute: async ({ pid, tail, wait: shouldWait }, context) => {
|
|
5699
|
+
const { sandbox } = requireSandbox(context);
|
|
5700
|
+
if (!sandbox.processes) {
|
|
5701
|
+
throw new SandboxFeatureNotSupportedError("processes");
|
|
5702
|
+
}
|
|
5703
|
+
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.SANDBOX.GET_PROCESS_OUTPUT);
|
|
5704
|
+
const toolCallId = context?.agent?.toolCallId;
|
|
5705
|
+
const handle = await sandbox.processes.get(pid);
|
|
5706
|
+
if (!handle) {
|
|
5707
|
+
return `No background process found with PID ${pid}.`;
|
|
5708
|
+
}
|
|
5709
|
+
if (handle.command) {
|
|
5710
|
+
await context?.writer?.custom({
|
|
5711
|
+
type: "data-sandbox-command",
|
|
5712
|
+
data: { command: handle.command, pid, toolCallId }
|
|
5713
|
+
});
|
|
5714
|
+
}
|
|
5715
|
+
if (shouldWait && handle.exitCode === void 0) {
|
|
5716
|
+
const result = await handle.wait({
|
|
5717
|
+
onStdout: context?.writer ? async (data) => {
|
|
5718
|
+
await context.writer.custom({
|
|
5719
|
+
type: "data-sandbox-stdout",
|
|
5720
|
+
data: { output: data, timestamp: Date.now(), toolCallId }
|
|
5721
|
+
});
|
|
5722
|
+
} : void 0,
|
|
5723
|
+
onStderr: context?.writer ? async (data) => {
|
|
5724
|
+
await context.writer.custom({
|
|
5725
|
+
type: "data-sandbox-stderr",
|
|
5726
|
+
data: { output: data, timestamp: Date.now(), toolCallId }
|
|
5727
|
+
});
|
|
5728
|
+
} : void 0
|
|
5729
|
+
});
|
|
5730
|
+
await context?.writer?.custom({
|
|
5731
|
+
type: "data-sandbox-exit",
|
|
5732
|
+
data: {
|
|
5733
|
+
exitCode: result.exitCode,
|
|
5734
|
+
success: result.success,
|
|
5735
|
+
executionTimeMs: result.executionTimeMs,
|
|
5736
|
+
toolCallId
|
|
5737
|
+
}
|
|
5738
|
+
});
|
|
5739
|
+
}
|
|
5740
|
+
const running = handle.exitCode === void 0;
|
|
5741
|
+
const stdout = truncateOutput(handle.stdout, tail);
|
|
5742
|
+
const stderr = truncateOutput(handle.stderr, tail);
|
|
5743
|
+
if (!stdout && !stderr) {
|
|
5744
|
+
return "(no output yet)";
|
|
5745
|
+
}
|
|
5746
|
+
const parts = [];
|
|
5747
|
+
if (stdout && stderr) {
|
|
5748
|
+
parts.push("stdout:", stdout, "", "stderr:", stderr);
|
|
5749
|
+
} else if (stdout) {
|
|
5750
|
+
parts.push(stdout);
|
|
5751
|
+
} else {
|
|
5752
|
+
parts.push("stderr:", stderr);
|
|
5753
|
+
}
|
|
5754
|
+
if (!running) {
|
|
5755
|
+
parts.push("", `Exit code: ${handle.exitCode}`);
|
|
5756
|
+
}
|
|
5757
|
+
return parts.join("\n");
|
|
5758
|
+
}
|
|
5759
|
+
});
|
|
5267
5760
|
var grepTool = createTool({
|
|
5268
5761
|
id: WORKSPACE_TOOLS.FILESYSTEM.GREP,
|
|
5269
5762
|
description: `Search file contents using a regex pattern. Walks the filesystem and returns matching lines with file paths and line numbers.
|
|
@@ -5420,6 +5913,55 @@ var indexContentTool = createTool({
|
|
|
5420
5913
|
return `Indexed ${path4}`;
|
|
5421
5914
|
}
|
|
5422
5915
|
});
|
|
5916
|
+
var KILL_TAIL_LINES = 50;
|
|
5917
|
+
var killProcessTool = createTool({
|
|
5918
|
+
id: WORKSPACE_TOOLS.SANDBOX.KILL_PROCESS,
|
|
5919
|
+
description: `Kill a background process by its PID.
|
|
5920
|
+
|
|
5921
|
+
Use this to stop a long-running background process that was started with execute_command (background: true). Returns the last ${KILL_TAIL_LINES} lines of output.`,
|
|
5922
|
+
inputSchema: z.object({
|
|
5923
|
+
pid: z.number().describe("The process ID of the background process to kill")
|
|
5924
|
+
}),
|
|
5925
|
+
execute: async ({ pid }, context) => {
|
|
5926
|
+
const { sandbox } = requireSandbox(context);
|
|
5927
|
+
if (!sandbox.processes) {
|
|
5928
|
+
throw new SandboxFeatureNotSupportedError("processes");
|
|
5929
|
+
}
|
|
5930
|
+
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.SANDBOX.KILL_PROCESS);
|
|
5931
|
+
const toolCallId = context?.agent?.toolCallId;
|
|
5932
|
+
const handle = await sandbox.processes.get(pid);
|
|
5933
|
+
if (handle?.command) {
|
|
5934
|
+
await context?.writer?.custom({
|
|
5935
|
+
type: "data-sandbox-command",
|
|
5936
|
+
data: { command: handle.command, pid, toolCallId }
|
|
5937
|
+
});
|
|
5938
|
+
}
|
|
5939
|
+
const killed = await sandbox.processes.kill(pid);
|
|
5940
|
+
if (!killed) {
|
|
5941
|
+
await context?.writer?.custom({
|
|
5942
|
+
type: "data-sandbox-exit",
|
|
5943
|
+
data: { exitCode: handle?.exitCode ?? -1, success: false, killed: false, toolCallId }
|
|
5944
|
+
});
|
|
5945
|
+
return `Process ${pid} was not found or had already exited.`;
|
|
5946
|
+
}
|
|
5947
|
+
await context?.writer?.custom({
|
|
5948
|
+
type: "data-sandbox-exit",
|
|
5949
|
+
data: { exitCode: handle?.exitCode ?? 137, success: false, killed: true, toolCallId }
|
|
5950
|
+
});
|
|
5951
|
+
const parts = [`Process ${pid} has been killed.`];
|
|
5952
|
+
if (handle) {
|
|
5953
|
+
const stdout = handle.stdout ? truncateOutput(handle.stdout, KILL_TAIL_LINES) : "";
|
|
5954
|
+
const stderr = handle.stderr ? truncateOutput(handle.stderr, KILL_TAIL_LINES) : "";
|
|
5955
|
+
if (stdout) {
|
|
5956
|
+
parts.push("", "--- stdout (last output) ---", stdout);
|
|
5957
|
+
}
|
|
5958
|
+
if (stderr) {
|
|
5959
|
+
parts.push("", "--- stderr (last output) ---", stderr);
|
|
5960
|
+
}
|
|
5961
|
+
}
|
|
5962
|
+
return parts.join("\n");
|
|
5963
|
+
}
|
|
5964
|
+
});
|
|
5423
5965
|
|
|
5424
5966
|
// src/workspace/tools/tree-formatter.ts
|
|
5425
5967
|
var BRANCH = "\u251C\u2500\u2500 ";
|
|
@@ -5754,10 +6296,22 @@ function wrapWithReadTracker(tool, workspace, readTracker, config, mode) {
|
|
|
5754
6296
|
}
|
|
5755
6297
|
};
|
|
5756
6298
|
}
|
|
6299
|
+
function wrapWithWriteLock(tool, writeLock) {
|
|
6300
|
+
return {
|
|
6301
|
+
...tool,
|
|
6302
|
+
execute: async (input, context = {}) => {
|
|
6303
|
+
if (!input.path) {
|
|
6304
|
+
throw new Error("wrapWithWriteLock: input.path is required");
|
|
6305
|
+
}
|
|
6306
|
+
return writeLock.withLock(input.path, () => tool.execute(input, context));
|
|
6307
|
+
}
|
|
6308
|
+
};
|
|
6309
|
+
}
|
|
5757
6310
|
function createWorkspaceTools(workspace) {
|
|
5758
6311
|
const tools = {};
|
|
5759
6312
|
const toolsConfig = workspace.getToolsConfig();
|
|
5760
6313
|
const isReadOnly = workspace.filesystem?.readOnly ?? false;
|
|
6314
|
+
const writeLock = new InMemoryFileWriteLock();
|
|
5761
6315
|
let readTracker;
|
|
5762
6316
|
const writeFileConfig = resolveToolConfig(toolsConfig, WORKSPACE_TOOLS.FILESYSTEM.WRITE_FILE);
|
|
5763
6317
|
const editFileConfig = resolveToolConfig(toolsConfig, WORKSPACE_TOOLS.FILESYSTEM.EDIT_FILE);
|
|
@@ -5769,31 +6323,39 @@ function createWorkspaceTools(workspace) {
|
|
|
5769
6323
|
const config = resolveToolConfig(toolsConfig, name);
|
|
5770
6324
|
if (!config.enabled) return;
|
|
5771
6325
|
if (opts?.requireWrite && isReadOnly) return;
|
|
6326
|
+
let wrapped;
|
|
5772
6327
|
if (readTracker && opts?.readTrackerMode) {
|
|
5773
|
-
|
|
6328
|
+
wrapped = wrapWithReadTracker(tool, workspace, readTracker, config, opts.readTrackerMode);
|
|
5774
6329
|
} else {
|
|
5775
|
-
|
|
6330
|
+
wrapped = wrapTool(tool, workspace, config);
|
|
6331
|
+
}
|
|
6332
|
+
if (opts?.useWriteLock) {
|
|
6333
|
+
wrapped = wrapWithWriteLock(wrapped, writeLock);
|
|
5776
6334
|
}
|
|
6335
|
+
tools[name] = wrapped;
|
|
5777
6336
|
};
|
|
5778
6337
|
if (workspace.filesystem) {
|
|
5779
6338
|
addTool(WORKSPACE_TOOLS.FILESYSTEM.READ_FILE, readFileTool, { readTrackerMode: "read" });
|
|
5780
6339
|
addTool(WORKSPACE_TOOLS.FILESYSTEM.WRITE_FILE, writeFileTool, {
|
|
5781
6340
|
requireWrite: true,
|
|
5782
|
-
readTrackerMode: "write"
|
|
6341
|
+
readTrackerMode: "write",
|
|
6342
|
+
useWriteLock: true
|
|
5783
6343
|
});
|
|
5784
6344
|
addTool(WORKSPACE_TOOLS.FILESYSTEM.EDIT_FILE, editFileTool, {
|
|
5785
6345
|
requireWrite: true,
|
|
5786
|
-
readTrackerMode: "write"
|
|
6346
|
+
readTrackerMode: "write",
|
|
6347
|
+
useWriteLock: true
|
|
5787
6348
|
});
|
|
5788
6349
|
addTool(WORKSPACE_TOOLS.FILESYSTEM.LIST_FILES, listFilesTool);
|
|
5789
|
-
addTool(WORKSPACE_TOOLS.FILESYSTEM.DELETE, deleteFileTool, { requireWrite: true });
|
|
6350
|
+
addTool(WORKSPACE_TOOLS.FILESYSTEM.DELETE, deleteFileTool, { requireWrite: true, useWriteLock: true });
|
|
5790
6351
|
addTool(WORKSPACE_TOOLS.FILESYSTEM.FILE_STAT, fileStatTool);
|
|
5791
6352
|
addTool(WORKSPACE_TOOLS.FILESYSTEM.MKDIR, mkdirTool, { requireWrite: true });
|
|
5792
6353
|
addTool(WORKSPACE_TOOLS.FILESYSTEM.GREP, grepTool);
|
|
5793
6354
|
if (isAstGrepAvailable()) {
|
|
5794
6355
|
addTool(WORKSPACE_TOOLS.FILESYSTEM.AST_EDIT, astEditTool, {
|
|
5795
6356
|
requireWrite: true,
|
|
5796
|
-
readTrackerMode: "write"
|
|
6357
|
+
readTrackerMode: "write",
|
|
6358
|
+
useWriteLock: true
|
|
5797
6359
|
});
|
|
5798
6360
|
}
|
|
5799
6361
|
}
|
|
@@ -5804,20 +6366,17 @@ function createWorkspaceTools(workspace) {
|
|
|
5804
6366
|
if (workspace.sandbox) {
|
|
5805
6367
|
const executeCommandConfig = resolveToolConfig(toolsConfig, WORKSPACE_TOOLS.SANDBOX.EXECUTE_COMMAND);
|
|
5806
6368
|
if (workspace.sandbox.executeCommand && executeCommandConfig.enabled) {
|
|
5807
|
-
const
|
|
5808
|
-
|
|
5809
|
-
|
|
5810
|
-
|
|
5811
|
-
|
|
5812
|
-
|
|
5813
|
-
...wrapTool(executeCommandTool, workspace, executeCommandConfig),
|
|
5814
|
-
description
|
|
5815
|
-
};
|
|
6369
|
+
const baseTool = workspace.sandbox.processes ? executeCommandWithBackgroundTool : executeCommandTool;
|
|
6370
|
+
tools[WORKSPACE_TOOLS.SANDBOX.EXECUTE_COMMAND] = wrapTool(baseTool, workspace, executeCommandConfig);
|
|
6371
|
+
}
|
|
6372
|
+
if (workspace.sandbox.processes) {
|
|
6373
|
+
addTool(WORKSPACE_TOOLS.SANDBOX.GET_PROCESS_OUTPUT, getProcessOutputTool);
|
|
6374
|
+
addTool(WORKSPACE_TOOLS.SANDBOX.KILL_PROCESS, killProcessTool);
|
|
5816
6375
|
}
|
|
5817
6376
|
}
|
|
5818
6377
|
return tools;
|
|
5819
6378
|
}
|
|
5820
6379
|
|
|
5821
|
-
export { BM25Index, CompositeFilesystem, CompositeVersionedSkillSource, DirectoryNotEmptyError, DirectoryNotFoundError, FileExistsError, FileNotFoundError, FileReadRequiredError, FilesystemError, FilesystemNotAvailableError, FilesystemNotMountableError, FilesystemNotReadyError, IsDirectoryError, IsolationUnavailableError, LocalFilesystem, LocalSandbox, LocalSkillSource, MastraFilesystem, MastraSandbox, MountError, MountManager, MountNotSupportedError, NotDirectoryError, PermissionError, SandboxError, SandboxExecutionError, SandboxFeatureNotSupportedError, SandboxNotAvailableError, SandboxNotReadyError, SandboxTimeoutError, SearchNotAvailableError, VersionedSkillSource, WORKSPACE_TOOLS, WORKSPACE_TOOLS_PREFIX, Workspace, WorkspaceError, WorkspaceNotAvailableError, WorkspaceNotReadyError, WorkspaceReadOnlyError, callLifecycle, collectSkillForPublish, createGlobMatcher, createWorkspaceTools, deleteFileTool, detectIsolation, editFileTool, executeCommandTool, extractGlobBase, extractLines, fileStatTool, getRecommendedIsolation, indexContentTool, isGlobPattern, isIsolationAvailable, listFilesTool, matchGlob, mkdirTool, publishSkillFromSource, readFileTool, requireFilesystem, requireSandbox, requireWorkspace, resolveToolConfig, searchTool, writeFileTool };
|
|
5822
|
-
//# sourceMappingURL=chunk-
|
|
5823
|
-
//# sourceMappingURL=chunk-
|
|
6380
|
+
export { BM25Index, CompositeFilesystem, CompositeVersionedSkillSource, DirectoryNotEmptyError, DirectoryNotFoundError, FileExistsError, FileNotFoundError, FileReadRequiredError, FilesystemError, FilesystemNotAvailableError, FilesystemNotMountableError, FilesystemNotReadyError, IsDirectoryError, IsolationUnavailableError, LocalFilesystem, LocalSandbox, LocalSkillSource, MastraFilesystem, MastraSandbox, MountError, MountManager, MountNotSupportedError, NotDirectoryError, PermissionError, ProcessHandle, SandboxError, SandboxExecutionError, SandboxFeatureNotSupportedError, SandboxNotAvailableError, SandboxNotReadyError, SandboxProcessManager, SandboxTimeoutError, SearchNotAvailableError, VersionedSkillSource, WORKSPACE_TOOLS, WORKSPACE_TOOLS_PREFIX, Workspace, WorkspaceError, WorkspaceNotAvailableError, WorkspaceNotReadyError, WorkspaceReadOnlyError, callLifecycle, collectSkillForPublish, createGlobMatcher, createWorkspaceTools, deleteFileTool, detectIsolation, editFileTool, executeCommandTool, extractGlobBase, extractLines, fileStatTool, getRecommendedIsolation, indexContentTool, isGlobPattern, isIsolationAvailable, listFilesTool, matchGlob, mkdirTool, publishSkillFromSource, readFileTool, requireFilesystem, requireSandbox, requireWorkspace, resolveToolConfig, searchTool, writeFileTool };
|
|
6381
|
+
//# sourceMappingURL=chunk-ZSBM2SVU.js.map
|
|
6382
|
+
//# sourceMappingURL=chunk-ZSBM2SVU.js.map
|