@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
|
@@ -10,8 +10,9 @@ var nodePath = require('path');
|
|
|
10
10
|
var picomatch = require('picomatch');
|
|
11
11
|
var crypto = require('crypto');
|
|
12
12
|
var matter = require('gray-matter');
|
|
13
|
-
var childProcess = require('child_process');
|
|
14
13
|
var os = require('os');
|
|
14
|
+
var childProcess = require('child_process');
|
|
15
|
+
var stream = require('stream');
|
|
15
16
|
var module$1 = require('module');
|
|
16
17
|
var zod = require('zod');
|
|
17
18
|
|
|
@@ -42,8 +43,8 @@ var nodePath__namespace = /*#__PURE__*/_interopNamespace(nodePath);
|
|
|
42
43
|
var picomatch__default = /*#__PURE__*/_interopDefault(picomatch);
|
|
43
44
|
var crypto__namespace = /*#__PURE__*/_interopNamespace(crypto);
|
|
44
45
|
var matter__default = /*#__PURE__*/_interopDefault(matter);
|
|
45
|
-
var childProcess__namespace = /*#__PURE__*/_interopNamespace(childProcess);
|
|
46
46
|
var os__namespace = /*#__PURE__*/_interopNamespace(os);
|
|
47
|
+
var childProcess__namespace = /*#__PURE__*/_interopNamespace(childProcess);
|
|
47
48
|
|
|
48
49
|
// src/workspace/errors.ts
|
|
49
50
|
var WorkspaceError = class extends Error {
|
|
@@ -479,13 +480,13 @@ var CompositeFilesystem = class {
|
|
|
479
480
|
* Get instructions describing the mounted filesystems.
|
|
480
481
|
* Used by agents to understand available storage locations.
|
|
481
482
|
*/
|
|
482
|
-
getInstructions() {
|
|
483
|
+
getInstructions(_opts) {
|
|
483
484
|
const mountDescriptions = Array.from(this._mounts.entries()).map(([mountPath, fs5]) => {
|
|
484
485
|
const name = fs5.displayName || fs5.provider;
|
|
485
486
|
const access2 = fs5.readOnly ? "(read-only)" : "(read-write)";
|
|
486
487
|
return `- ${mountPath}: ${name} ${access2}`;
|
|
487
488
|
}).join("\n");
|
|
488
|
-
return `
|
|
489
|
+
return `Filesystem mount points:
|
|
489
490
|
${mountDescriptions}`;
|
|
490
491
|
}
|
|
491
492
|
};
|
|
@@ -657,6 +658,14 @@ var MastraFilesystem = class extends chunkRO47SMI7_cjs.MastraBase {
|
|
|
657
658
|
async destroy() {
|
|
658
659
|
}
|
|
659
660
|
};
|
|
661
|
+
|
|
662
|
+
// src/workspace/utils.ts
|
|
663
|
+
function resolveInstructions(override, getDefault, requestContext) {
|
|
664
|
+
if (typeof override === "string") return override;
|
|
665
|
+
const defaultInstructions = getDefault();
|
|
666
|
+
if (override === void 0) return defaultInstructions;
|
|
667
|
+
return override({ defaultInstructions, requestContext });
|
|
668
|
+
}
|
|
660
669
|
function isEnoentError(error) {
|
|
661
670
|
return error !== null && typeof error === "object" && "code" in error && error.code === "ENOENT";
|
|
662
671
|
}
|
|
@@ -797,6 +806,7 @@ var LocalFilesystem = class extends MastraFilesystem {
|
|
|
797
806
|
_basePath;
|
|
798
807
|
_contained;
|
|
799
808
|
_allowedPaths;
|
|
809
|
+
_instructionsOverride;
|
|
800
810
|
/**
|
|
801
811
|
* The absolute base path on disk where files are stored.
|
|
802
812
|
* Useful for understanding how workspace paths map to disk paths.
|
|
@@ -835,6 +845,7 @@ var LocalFilesystem = class extends MastraFilesystem {
|
|
|
835
845
|
this._contained = options.contained ?? true;
|
|
836
846
|
this.readOnly = options.readOnly;
|
|
837
847
|
this._allowedPaths = (options.allowedPaths ?? []).map((p) => nodePath__namespace.resolve(p));
|
|
848
|
+
this._instructionsOverride = options.instructions;
|
|
838
849
|
}
|
|
839
850
|
generateId() {
|
|
840
851
|
return `local-fs-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
@@ -1297,7 +1308,10 @@ var LocalFilesystem = class extends MastraFilesystem {
|
|
|
1297
1308
|
}
|
|
1298
1309
|
};
|
|
1299
1310
|
}
|
|
1300
|
-
getInstructions() {
|
|
1311
|
+
getInstructions(opts) {
|
|
1312
|
+
return resolveInstructions(this._instructionsOverride, () => this._getDefaultInstructions(), opts?.requestContext);
|
|
1313
|
+
}
|
|
1314
|
+
_getDefaultInstructions() {
|
|
1301
1315
|
const allowedNote = this._allowedPaths.length > 0 ? ` Additionally, the following paths outside basePath are accessible: ${this._allowedPaths.join(", ")}.` : "";
|
|
1302
1316
|
if (this._contained) {
|
|
1303
1317
|
return `Local filesystem at "${this.basePath}". Files at workspace path "/foo" are stored at "${this.basePath}/foo" on disk.${allowedNote}`;
|
|
@@ -1345,6 +1359,57 @@ var InMemoryFileReadTracker = class {
|
|
|
1345
1359
|
return normalized.replace(/\/$/, "") || "/";
|
|
1346
1360
|
}
|
|
1347
1361
|
};
|
|
1362
|
+
var InMemoryFileWriteLock = class {
|
|
1363
|
+
queues = /* @__PURE__ */ new Map();
|
|
1364
|
+
timeoutMs;
|
|
1365
|
+
constructor(opts) {
|
|
1366
|
+
this.timeoutMs = opts?.timeoutMs ?? 3e4;
|
|
1367
|
+
}
|
|
1368
|
+
get size() {
|
|
1369
|
+
return this.queues.size;
|
|
1370
|
+
}
|
|
1371
|
+
withLock(filePath, fn) {
|
|
1372
|
+
const key = this.normalizePath(filePath);
|
|
1373
|
+
const currentQueue = this.queues.get(key) ?? Promise.resolve();
|
|
1374
|
+
let resolve3;
|
|
1375
|
+
let reject;
|
|
1376
|
+
const resultPromise = new Promise((res, rej) => {
|
|
1377
|
+
resolve3 = res;
|
|
1378
|
+
reject = rej;
|
|
1379
|
+
});
|
|
1380
|
+
const queuePromise = currentQueue.catch(() => {
|
|
1381
|
+
}).then(async () => {
|
|
1382
|
+
let timeoutId;
|
|
1383
|
+
try {
|
|
1384
|
+
const result = await Promise.race([
|
|
1385
|
+
fn(),
|
|
1386
|
+
new Promise((_, rej) => {
|
|
1387
|
+
timeoutId = setTimeout(
|
|
1388
|
+
() => rej(new Error(`write-lock timeout on "${key}" after ${this.timeoutMs}ms`)),
|
|
1389
|
+
this.timeoutMs
|
|
1390
|
+
);
|
|
1391
|
+
})
|
|
1392
|
+
]);
|
|
1393
|
+
clearTimeout(timeoutId);
|
|
1394
|
+
resolve3(result);
|
|
1395
|
+
} catch (error) {
|
|
1396
|
+
clearTimeout(timeoutId);
|
|
1397
|
+
reject(error);
|
|
1398
|
+
}
|
|
1399
|
+
});
|
|
1400
|
+
this.queues.set(key, queuePromise);
|
|
1401
|
+
void queuePromise.finally(() => {
|
|
1402
|
+
if (this.queues.get(key) === queuePromise) {
|
|
1403
|
+
this.queues.delete(key);
|
|
1404
|
+
}
|
|
1405
|
+
});
|
|
1406
|
+
return resultPromise;
|
|
1407
|
+
}
|
|
1408
|
+
normalizePath(pathStr) {
|
|
1409
|
+
const normalized = nodePath__namespace.posix.normalize(pathStr.replace(/\\/g, "/").replace(/^\/\/+/, "/"));
|
|
1410
|
+
return normalized.replace(/\/+$/, "") || "/";
|
|
1411
|
+
}
|
|
1412
|
+
};
|
|
1348
1413
|
var GLOB_CHARS = /[*?{}[\]]/;
|
|
1349
1414
|
function isGlobPattern(input) {
|
|
1350
1415
|
return GLOB_CHARS.test(input);
|
|
@@ -1724,8 +1789,16 @@ var MountManager = class {
|
|
|
1724
1789
|
}
|
|
1725
1790
|
};
|
|
1726
1791
|
|
|
1792
|
+
// src/workspace/sandbox/utils.ts
|
|
1793
|
+
function shellQuote(arg) {
|
|
1794
|
+
if (/^[a-zA-Z0-9._\-\/=:@]+$/.test(arg)) return arg;
|
|
1795
|
+
return `'${arg.replace(/'/g, "'\\''")}'`;
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1727
1798
|
// src/workspace/sandbox/mastra-sandbox.ts
|
|
1728
1799
|
var MastraSandbox = class extends chunkRO47SMI7_cjs.MastraBase {
|
|
1800
|
+
/** Process manager */
|
|
1801
|
+
processes;
|
|
1729
1802
|
/** Mount manager - automatically created if subclass implements mount() */
|
|
1730
1803
|
mounts;
|
|
1731
1804
|
// ---------------------------------------------------------------------------
|
|
@@ -1752,6 +1825,21 @@ var MastraSandbox = class extends chunkRO47SMI7_cjs.MastraBase {
|
|
|
1752
1825
|
logger: this.logger
|
|
1753
1826
|
});
|
|
1754
1827
|
}
|
|
1828
|
+
if (options.processes) {
|
|
1829
|
+
const pm = options.processes;
|
|
1830
|
+
pm.sandbox = this;
|
|
1831
|
+
this.processes = pm;
|
|
1832
|
+
if (!this.executeCommand) {
|
|
1833
|
+
this.executeCommand = async (command, args, opts) => {
|
|
1834
|
+
const fullCommand = args?.length ? `${command} ${args.map((a) => shellQuote(a)).join(" ")}` : command;
|
|
1835
|
+
this.logger.debug(`[${this.name}] Executing: ${fullCommand}`, { cwd: opts?.cwd });
|
|
1836
|
+
const handle = await pm.spawn(fullCommand, opts ?? {});
|
|
1837
|
+
const result = await handle.wait();
|
|
1838
|
+
this.logger.debug(`[${this.name}] Exit code: ${result.exitCode} (${result.executionTimeMs}ms)`);
|
|
1839
|
+
return { ...result, command: fullCommand };
|
|
1840
|
+
};
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1755
1843
|
}
|
|
1756
1844
|
// ---------------------------------------------------------------------------
|
|
1757
1845
|
// Lifecycle Wrappers (race-condition-safe)
|
|
@@ -1838,6 +1926,12 @@ var MastraSandbox = class extends chunkRO47SMI7_cjs.MastraBase {
|
|
|
1838
1926
|
* ```
|
|
1839
1927
|
*/
|
|
1840
1928
|
async ensureRunning() {
|
|
1929
|
+
if (this.status === "destroyed") {
|
|
1930
|
+
throw new SandboxNotReadyError(this.id);
|
|
1931
|
+
}
|
|
1932
|
+
if (this.status === "destroying" || this.status === "stopping") {
|
|
1933
|
+
return;
|
|
1934
|
+
}
|
|
1841
1935
|
if (this.status !== "running") {
|
|
1842
1936
|
await this._start();
|
|
1843
1937
|
}
|
|
@@ -1903,6 +1997,10 @@ var MastraSandbox = class extends chunkRO47SMI7_cjs.MastraBase {
|
|
|
1903
1997
|
if (this.status === "destroyed") {
|
|
1904
1998
|
return;
|
|
1905
1999
|
}
|
|
2000
|
+
if (this.status === "pending") {
|
|
2001
|
+
this.status = "destroyed";
|
|
2002
|
+
return;
|
|
2003
|
+
}
|
|
1906
2004
|
if (this._startPromise) await this._startPromise.catch(() => {
|
|
1907
2005
|
});
|
|
1908
2006
|
if (this._stopPromise) await this._stopPromise.catch(() => {
|
|
@@ -3988,6 +4086,25 @@ var Workspace = class {
|
|
|
3988
4086
|
getToolsConfig() {
|
|
3989
4087
|
return this._config.tools;
|
|
3990
4088
|
}
|
|
4089
|
+
/**
|
|
4090
|
+
* Update the per-tool configuration for this workspace.
|
|
4091
|
+
* Takes effect on the next `createWorkspaceTools()` call.
|
|
4092
|
+
*
|
|
4093
|
+
* @example
|
|
4094
|
+
* ```typescript
|
|
4095
|
+
* // Disable write tools for read-only mode
|
|
4096
|
+
* workspace.setToolsConfig({
|
|
4097
|
+
* mastra_workspace_write_file: { enabled: false },
|
|
4098
|
+
* mastra_workspace_edit_file: { enabled: false },
|
|
4099
|
+
* });
|
|
4100
|
+
*
|
|
4101
|
+
* // Re-enable all tools
|
|
4102
|
+
* workspace.setToolsConfig(undefined);
|
|
4103
|
+
* ```
|
|
4104
|
+
*/
|
|
4105
|
+
setToolsConfig(config) {
|
|
4106
|
+
this._config.tools = config;
|
|
4107
|
+
}
|
|
3991
4108
|
/**
|
|
3992
4109
|
* Access skills stored in this workspace.
|
|
3993
4110
|
* Skills are SKILL.md files discovered from the configured skillPaths.
|
|
@@ -4226,10 +4343,58 @@ var Workspace = class {
|
|
|
4226
4343
|
}
|
|
4227
4344
|
return info;
|
|
4228
4345
|
}
|
|
4346
|
+
/**
|
|
4347
|
+
* Get human-readable instructions describing the workspace environment.
|
|
4348
|
+
*
|
|
4349
|
+
* When both a sandbox with mounts and a filesystem exist, each mount path
|
|
4350
|
+
* is classified as sandbox-accessible (state === 'mounted') or
|
|
4351
|
+
* workspace-only (pending / mounting / error / unsupported). When there's
|
|
4352
|
+
* no sandbox or no mounts, falls back to provider-level instructions.
|
|
4353
|
+
*
|
|
4354
|
+
* @param opts - Optional options including request context for per-request customisation
|
|
4355
|
+
* @returns Combined instructions string (may be empty)
|
|
4356
|
+
*/
|
|
4357
|
+
getInstructions(opts) {
|
|
4358
|
+
const parts = [];
|
|
4359
|
+
const sandboxInstructions = this._sandbox?.getInstructions?.(opts);
|
|
4360
|
+
if (sandboxInstructions) parts.push(sandboxInstructions);
|
|
4361
|
+
const mountEntries = this._sandbox?.mounts?.entries;
|
|
4362
|
+
if (mountEntries && mountEntries.size > 0) {
|
|
4363
|
+
const sandboxAccessible = [];
|
|
4364
|
+
const workspaceOnly = [];
|
|
4365
|
+
for (const [mountPath, entry] of mountEntries) {
|
|
4366
|
+
const fsName = entry.filesystem.displayName || entry.filesystem.provider;
|
|
4367
|
+
const access2 = entry.filesystem.readOnly ? "read-only" : "read-write";
|
|
4368
|
+
if (entry.state === "mounted") {
|
|
4369
|
+
sandboxAccessible.push(` - ${mountPath}: ${fsName} (${access2})`);
|
|
4370
|
+
} else {
|
|
4371
|
+
workspaceOnly.push(` - ${mountPath}: ${fsName} (${access2})`);
|
|
4372
|
+
}
|
|
4373
|
+
}
|
|
4374
|
+
if (sandboxAccessible.length) {
|
|
4375
|
+
parts.push(`Sandbox-mounted filesystems (accessible in shell commands):
|
|
4376
|
+
${sandboxAccessible.join("\n")}`);
|
|
4377
|
+
}
|
|
4378
|
+
if (workspaceOnly.length) {
|
|
4379
|
+
parts.push(
|
|
4380
|
+
`Workspace-only filesystems (use file tools, NOT available in shell commands):
|
|
4381
|
+
${workspaceOnly.join("\n")}`
|
|
4382
|
+
);
|
|
4383
|
+
}
|
|
4384
|
+
} else {
|
|
4385
|
+
const fsInstructions = this._fs?.getInstructions?.(opts);
|
|
4386
|
+
if (fsInstructions) parts.push(fsInstructions);
|
|
4387
|
+
}
|
|
4388
|
+
return parts.join("\n\n");
|
|
4389
|
+
}
|
|
4229
4390
|
/**
|
|
4230
4391
|
* Get information about how filesystem and sandbox paths relate.
|
|
4231
4392
|
* Useful for understanding how to access workspace files from sandbox code.
|
|
4232
4393
|
*
|
|
4394
|
+
* @deprecated Use {@link getInstructions} instead. `getInstructions()` is
|
|
4395
|
+
* mount-state-aware and feeds into the system message via
|
|
4396
|
+
* `WorkspaceInstructionsProcessor`.
|
|
4397
|
+
*
|
|
4233
4398
|
* @returns PathContext with paths and instructions from providers
|
|
4234
4399
|
*/
|
|
4235
4400
|
getPathContext() {
|
|
@@ -4265,6 +4430,274 @@ var Workspace = class {
|
|
|
4265
4430
|
}
|
|
4266
4431
|
}
|
|
4267
4432
|
};
|
|
4433
|
+
var ProcessHandle = class {
|
|
4434
|
+
/** The command that was spawned (set by the process manager) */
|
|
4435
|
+
command;
|
|
4436
|
+
/**
|
|
4437
|
+
* Wait for the process to finish and return the result.
|
|
4438
|
+
*
|
|
4439
|
+
* Optionally pass `onStdout`/`onStderr` callbacks to stream output chunks
|
|
4440
|
+
* while waiting. The callbacks are automatically removed when `wait()`
|
|
4441
|
+
* resolves, so there's no cleanup needed by the caller.
|
|
4442
|
+
*
|
|
4443
|
+
* Subclasses implement `wait()` with platform-specific logic — the base
|
|
4444
|
+
* constructor wraps it to handle the optional streaming callbacks.
|
|
4445
|
+
*/
|
|
4446
|
+
async wait(_options) {
|
|
4447
|
+
throw new Error(`${this.constructor.name} must implement wait()`);
|
|
4448
|
+
}
|
|
4449
|
+
_stdout = "";
|
|
4450
|
+
_stderr = "";
|
|
4451
|
+
_stdoutListeners = /* @__PURE__ */ new Set();
|
|
4452
|
+
_stderrListeners = /* @__PURE__ */ new Set();
|
|
4453
|
+
_reader;
|
|
4454
|
+
_writer;
|
|
4455
|
+
constructor(options) {
|
|
4456
|
+
if (options?.onStdout) this._stdoutListeners.add(options.onStdout);
|
|
4457
|
+
if (options?.onStderr) this._stderrListeners.add(options.onStderr);
|
|
4458
|
+
const implWait = this.wait.bind(this);
|
|
4459
|
+
this.wait = async (waitOptions) => {
|
|
4460
|
+
if (waitOptions?.onStdout) this._stdoutListeners.add(waitOptions.onStdout);
|
|
4461
|
+
if (waitOptions?.onStderr) this._stderrListeners.add(waitOptions.onStderr);
|
|
4462
|
+
try {
|
|
4463
|
+
return await implWait();
|
|
4464
|
+
} finally {
|
|
4465
|
+
if (waitOptions?.onStdout) this._stdoutListeners.delete(waitOptions.onStdout);
|
|
4466
|
+
if (waitOptions?.onStderr) this._stderrListeners.delete(waitOptions.onStderr);
|
|
4467
|
+
}
|
|
4468
|
+
};
|
|
4469
|
+
}
|
|
4470
|
+
/** Accumulated stdout so far */
|
|
4471
|
+
get stdout() {
|
|
4472
|
+
return this._stdout;
|
|
4473
|
+
}
|
|
4474
|
+
/** Accumulated stderr so far */
|
|
4475
|
+
get stderr() {
|
|
4476
|
+
return this._stderr;
|
|
4477
|
+
}
|
|
4478
|
+
/**
|
|
4479
|
+
* Emit stdout data — accumulates, dispatches to user callback, and pushes to reader stream.
|
|
4480
|
+
* @internal Called by subclasses and process managers to dispatch transport data.
|
|
4481
|
+
*/
|
|
4482
|
+
emitStdout(data) {
|
|
4483
|
+
this._stdout += data;
|
|
4484
|
+
for (const listener of this._stdoutListeners) listener(data);
|
|
4485
|
+
this._reader?.push(data);
|
|
4486
|
+
}
|
|
4487
|
+
/**
|
|
4488
|
+
* Emit stderr data — accumulates and dispatches to user callback.
|
|
4489
|
+
* @internal Called by subclasses and process managers to dispatch transport data.
|
|
4490
|
+
*/
|
|
4491
|
+
emitStderr(data) {
|
|
4492
|
+
this._stderr += data;
|
|
4493
|
+
for (const listener of this._stderrListeners) listener(data);
|
|
4494
|
+
}
|
|
4495
|
+
/** Readable stream of stdout (for use with StreamMessageReader, pipes, etc.) */
|
|
4496
|
+
get reader() {
|
|
4497
|
+
if (!this._reader) {
|
|
4498
|
+
this._reader = new stream.Readable({ read() {
|
|
4499
|
+
} });
|
|
4500
|
+
void this.wait().then(
|
|
4501
|
+
() => this._reader.push(null),
|
|
4502
|
+
() => this._reader.push(null)
|
|
4503
|
+
);
|
|
4504
|
+
}
|
|
4505
|
+
return this._reader;
|
|
4506
|
+
}
|
|
4507
|
+
/** Writable stream to stdin (for use with StreamMessageWriter, pipes, etc.) */
|
|
4508
|
+
get writer() {
|
|
4509
|
+
if (!this._writer) {
|
|
4510
|
+
this._writer = new stream.Writable({
|
|
4511
|
+
write: (chunk, _encoding, cb) => {
|
|
4512
|
+
this.sendStdin(chunk.toString()).then(() => cb(), cb);
|
|
4513
|
+
}
|
|
4514
|
+
});
|
|
4515
|
+
}
|
|
4516
|
+
return this._writer;
|
|
4517
|
+
}
|
|
4518
|
+
};
|
|
4519
|
+
|
|
4520
|
+
// src/workspace/sandbox/process-manager/process-manager.ts
|
|
4521
|
+
var SandboxProcessManager = class {
|
|
4522
|
+
/**
|
|
4523
|
+
* The sandbox this process manager belongs to.
|
|
4524
|
+
* Set automatically by MastraSandbox when processes are passed into the constructor.
|
|
4525
|
+
* @internal
|
|
4526
|
+
*/
|
|
4527
|
+
sandbox;
|
|
4528
|
+
env;
|
|
4529
|
+
/** Tracked process handles keyed by PID. Populated by spawn(), used by get()/kill(). */
|
|
4530
|
+
_tracked = /* @__PURE__ */ new Map();
|
|
4531
|
+
/** PIDs that have been read after exit and should not be re-discovered by subclass fallbacks. */
|
|
4532
|
+
_dismissed = /* @__PURE__ */ new Set();
|
|
4533
|
+
constructor({ env = {} } = {}) {
|
|
4534
|
+
this.env = env;
|
|
4535
|
+
const impl = {
|
|
4536
|
+
spawn: this.spawn.bind(this),
|
|
4537
|
+
list: this.list.bind(this),
|
|
4538
|
+
get: this.get.bind(this)
|
|
4539
|
+
};
|
|
4540
|
+
this.spawn = async (...args) => {
|
|
4541
|
+
await this.sandbox.ensureRunning();
|
|
4542
|
+
const handle = await impl.spawn(...args);
|
|
4543
|
+
handle.command = args[0];
|
|
4544
|
+
return handle;
|
|
4545
|
+
};
|
|
4546
|
+
this.list = async () => {
|
|
4547
|
+
await this.sandbox.ensureRunning();
|
|
4548
|
+
return impl.list();
|
|
4549
|
+
};
|
|
4550
|
+
this.get = async (...args) => {
|
|
4551
|
+
await this.sandbox.ensureRunning();
|
|
4552
|
+
if (this._dismissed.has(args[0])) return void 0;
|
|
4553
|
+
const handle = await impl.get(...args);
|
|
4554
|
+
if (handle?.exitCode !== void 0) {
|
|
4555
|
+
this._tracked.delete(handle.pid);
|
|
4556
|
+
this._dismissed.add(handle.pid);
|
|
4557
|
+
}
|
|
4558
|
+
return handle;
|
|
4559
|
+
};
|
|
4560
|
+
}
|
|
4561
|
+
/** Spawn a process. */
|
|
4562
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
4563
|
+
async spawn(command, options = {}) {
|
|
4564
|
+
throw new Error(`${this.constructor.name} must implement spawn()`);
|
|
4565
|
+
}
|
|
4566
|
+
/** List all tracked processes. */
|
|
4567
|
+
async list() {
|
|
4568
|
+
throw new Error(`${this.constructor.name} must implement list()`);
|
|
4569
|
+
}
|
|
4570
|
+
/** Get a handle to a process by PID. Subclasses can override for fallback behavior. */
|
|
4571
|
+
async get(pid) {
|
|
4572
|
+
return this._tracked.get(pid);
|
|
4573
|
+
}
|
|
4574
|
+
/** Kill a process by PID. Returns true if killed, false if not found. */
|
|
4575
|
+
async kill(pid) {
|
|
4576
|
+
const handle = await this.get(pid);
|
|
4577
|
+
if (!handle) return false;
|
|
4578
|
+
const killed = await handle.kill();
|
|
4579
|
+
if (killed) {
|
|
4580
|
+
await handle.wait().catch(() => {
|
|
4581
|
+
});
|
|
4582
|
+
}
|
|
4583
|
+
this._tracked.delete(pid);
|
|
4584
|
+
this._dismissed.add(pid);
|
|
4585
|
+
return killed;
|
|
4586
|
+
}
|
|
4587
|
+
};
|
|
4588
|
+
|
|
4589
|
+
// src/workspace/sandbox/local-process-manager.ts
|
|
4590
|
+
var LocalProcessHandle = class extends ProcessHandle {
|
|
4591
|
+
pid;
|
|
4592
|
+
exitCode;
|
|
4593
|
+
proc;
|
|
4594
|
+
waitPromise;
|
|
4595
|
+
startTime;
|
|
4596
|
+
constructor(proc, startTime, options) {
|
|
4597
|
+
super(options);
|
|
4598
|
+
if (!proc.pid) {
|
|
4599
|
+
throw new Error("Process has no PID - it may have failed to spawn");
|
|
4600
|
+
}
|
|
4601
|
+
this.pid = proc.pid;
|
|
4602
|
+
this.proc = proc;
|
|
4603
|
+
this.startTime = startTime;
|
|
4604
|
+
let timedOut = false;
|
|
4605
|
+
const timeoutId = options?.timeout ? setTimeout(() => {
|
|
4606
|
+
timedOut = true;
|
|
4607
|
+
try {
|
|
4608
|
+
process.kill(-this.pid, "SIGTERM");
|
|
4609
|
+
} catch {
|
|
4610
|
+
proc.kill("SIGTERM");
|
|
4611
|
+
}
|
|
4612
|
+
}, options.timeout) : void 0;
|
|
4613
|
+
this.waitPromise = new Promise((resolve3) => {
|
|
4614
|
+
proc.on("close", (code, signal) => {
|
|
4615
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
4616
|
+
if (timedOut) {
|
|
4617
|
+
const timeoutMsg = `
|
|
4618
|
+
Process timed out after ${options.timeout}ms`;
|
|
4619
|
+
this.emitStderr(timeoutMsg);
|
|
4620
|
+
this.exitCode = 124;
|
|
4621
|
+
} else {
|
|
4622
|
+
this.exitCode = signal && code === null ? 128 : code ?? 0;
|
|
4623
|
+
}
|
|
4624
|
+
resolve3({
|
|
4625
|
+
success: this.exitCode === 0,
|
|
4626
|
+
exitCode: this.exitCode,
|
|
4627
|
+
stdout: this.stdout,
|
|
4628
|
+
stderr: this.stderr,
|
|
4629
|
+
executionTimeMs: Date.now() - this.startTime,
|
|
4630
|
+
killed: signal !== null,
|
|
4631
|
+
timedOut
|
|
4632
|
+
});
|
|
4633
|
+
});
|
|
4634
|
+
proc.on("error", (err) => {
|
|
4635
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
4636
|
+
this.emitStderr(err.message);
|
|
4637
|
+
this.exitCode = 1;
|
|
4638
|
+
resolve3({
|
|
4639
|
+
success: false,
|
|
4640
|
+
exitCode: 1,
|
|
4641
|
+
stdout: this.stdout,
|
|
4642
|
+
stderr: this.stderr,
|
|
4643
|
+
executionTimeMs: Date.now() - this.startTime
|
|
4644
|
+
});
|
|
4645
|
+
});
|
|
4646
|
+
});
|
|
4647
|
+
proc.stdout?.on("data", (data) => {
|
|
4648
|
+
this.emitStdout(data.toString());
|
|
4649
|
+
});
|
|
4650
|
+
proc.stderr?.on("data", (data) => {
|
|
4651
|
+
this.emitStderr(data.toString());
|
|
4652
|
+
});
|
|
4653
|
+
}
|
|
4654
|
+
async wait() {
|
|
4655
|
+
return this.waitPromise;
|
|
4656
|
+
}
|
|
4657
|
+
async kill() {
|
|
4658
|
+
if (this.exitCode !== void 0) return false;
|
|
4659
|
+
try {
|
|
4660
|
+
process.kill(-this.pid, "SIGKILL");
|
|
4661
|
+
return true;
|
|
4662
|
+
} catch {
|
|
4663
|
+
return this.proc.kill("SIGKILL");
|
|
4664
|
+
}
|
|
4665
|
+
}
|
|
4666
|
+
async sendStdin(data) {
|
|
4667
|
+
if (this.exitCode !== void 0) {
|
|
4668
|
+
throw new Error(`Process ${this.pid} has already exited with code ${this.exitCode}`);
|
|
4669
|
+
}
|
|
4670
|
+
if (!this.proc.stdin) {
|
|
4671
|
+
throw new Error(`Process ${this.pid} does not have stdin available`);
|
|
4672
|
+
}
|
|
4673
|
+
return new Promise((resolve3, reject) => {
|
|
4674
|
+
this.proc.stdin.write(data, (err) => err ? reject(err) : resolve3());
|
|
4675
|
+
});
|
|
4676
|
+
}
|
|
4677
|
+
};
|
|
4678
|
+
var LocalProcessManager = class extends SandboxProcessManager {
|
|
4679
|
+
async spawn(command, options = {}) {
|
|
4680
|
+
const cwd = options.cwd ?? this.sandbox.workingDirectory;
|
|
4681
|
+
const env = this.sandbox.buildEnv(options.env);
|
|
4682
|
+
const wrapped = this.sandbox.wrapCommandForIsolation(command);
|
|
4683
|
+
const proc = childProcess__namespace.spawn(wrapped.command, wrapped.args, {
|
|
4684
|
+
cwd,
|
|
4685
|
+
env,
|
|
4686
|
+
shell: this.sandbox.isolation === "none",
|
|
4687
|
+
detached: true
|
|
4688
|
+
});
|
|
4689
|
+
const handle = new LocalProcessHandle(proc, Date.now(), options);
|
|
4690
|
+
this._tracked.set(handle.pid, handle);
|
|
4691
|
+
return handle;
|
|
4692
|
+
}
|
|
4693
|
+
async list() {
|
|
4694
|
+
return Array.from(this._tracked.values()).map((handle) => ({
|
|
4695
|
+
pid: handle.pid,
|
|
4696
|
+
running: handle.exitCode === void 0,
|
|
4697
|
+
exitCode: handle.exitCode
|
|
4698
|
+
}));
|
|
4699
|
+
}
|
|
4700
|
+
};
|
|
4268
4701
|
function commandExists(command) {
|
|
4269
4702
|
try {
|
|
4270
4703
|
childProcess.execFileSync("which", [command], { stdio: "ignore" });
|
|
@@ -4405,10 +4838,10 @@ function generateSeatbeltProfile(workspacePath, config) {
|
|
|
4405
4838
|
}
|
|
4406
4839
|
return lines.join("\n");
|
|
4407
4840
|
}
|
|
4408
|
-
function buildSeatbeltCommand(command,
|
|
4841
|
+
function buildSeatbeltCommand(command, profile) {
|
|
4409
4842
|
return {
|
|
4410
4843
|
command: "sandbox-exec",
|
|
4411
|
-
args: ["-p", profile,
|
|
4844
|
+
args: ["-p", profile, "sh", "-c", command]
|
|
4412
4845
|
};
|
|
4413
4846
|
}
|
|
4414
4847
|
|
|
@@ -4430,11 +4863,11 @@ var DEFAULT_READONLY_BINDS = [
|
|
|
4430
4863
|
"/etc/ld.so.cache",
|
|
4431
4864
|
"/etc/localtime"
|
|
4432
4865
|
];
|
|
4433
|
-
function buildBwrapCommand(command,
|
|
4866
|
+
function buildBwrapCommand(command, workspacePath, config) {
|
|
4434
4867
|
if (config.bwrapArgs && config.bwrapArgs.length > 0) {
|
|
4435
4868
|
return {
|
|
4436
4869
|
command: "bwrap",
|
|
4437
|
-
args: [...config.bwrapArgs, "--",
|
|
4870
|
+
args: [...config.bwrapArgs, "--", "sh", "-c", command]
|
|
4438
4871
|
};
|
|
4439
4872
|
}
|
|
4440
4873
|
const bwrapArgs = [];
|
|
@@ -4453,8 +4886,8 @@ function buildBwrapCommand(command, args, workspacePath, config) {
|
|
|
4453
4886
|
bwrapArgs.push("--ro-bind", path4, path4);
|
|
4454
4887
|
}
|
|
4455
4888
|
if (config.allowSystemBinaries !== false) {
|
|
4456
|
-
const
|
|
4457
|
-
const nodeDir =
|
|
4889
|
+
const nodePath4 = process.execPath;
|
|
4890
|
+
const nodeDir = nodePath4.substring(0, nodePath4.lastIndexOf("/"));
|
|
4458
4891
|
if (!DEFAULT_READONLY_BINDS.some((p) => nodeDir.startsWith(p))) {
|
|
4459
4892
|
bwrapArgs.push("--ro-bind", nodeDir, nodeDir);
|
|
4460
4893
|
}
|
|
@@ -4467,7 +4900,7 @@ function buildBwrapCommand(command, args, workspacePath, config) {
|
|
|
4467
4900
|
}
|
|
4468
4901
|
bwrapArgs.push("--chdir", workspacePath);
|
|
4469
4902
|
bwrapArgs.push("--die-with-parent");
|
|
4470
|
-
bwrapArgs.push("--",
|
|
4903
|
+
bwrapArgs.push("--", "sh", "-c", command);
|
|
4471
4904
|
return {
|
|
4472
4905
|
command: "bwrap",
|
|
4473
4906
|
args: bwrapArgs
|
|
@@ -4475,141 +4908,59 @@ function buildBwrapCommand(command, args, workspacePath, config) {
|
|
|
4475
4908
|
}
|
|
4476
4909
|
|
|
4477
4910
|
// src/workspace/sandbox/native-sandbox/wrapper.ts
|
|
4478
|
-
function wrapCommand(command,
|
|
4911
|
+
function wrapCommand(command, options) {
|
|
4479
4912
|
switch (options.backend) {
|
|
4480
4913
|
case "seatbelt": {
|
|
4481
4914
|
const profile = options.seatbeltProfile ?? generateSeatbeltProfile(options.workspacePath, options.config);
|
|
4482
|
-
return buildSeatbeltCommand(command,
|
|
4915
|
+
return buildSeatbeltCommand(command, profile);
|
|
4483
4916
|
}
|
|
4484
4917
|
case "bwrap": {
|
|
4485
|
-
return buildBwrapCommand(command,
|
|
4918
|
+
return buildBwrapCommand(command, options.workspacePath, options.config);
|
|
4486
4919
|
}
|
|
4487
4920
|
case "none":
|
|
4488
4921
|
default:
|
|
4489
|
-
return { command, args };
|
|
4922
|
+
return { command, args: [] };
|
|
4490
4923
|
}
|
|
4491
4924
|
}
|
|
4492
4925
|
|
|
4493
4926
|
// src/workspace/sandbox/local-sandbox.ts
|
|
4494
|
-
function execWithStreaming(command, args, options) {
|
|
4495
|
-
const { timeout, onStdout, onStderr, cwd, env, ...spawnOptions } = options;
|
|
4496
|
-
return new Promise((resolve3, reject) => {
|
|
4497
|
-
const proc = childProcess__namespace.spawn(command, args, { cwd, env, ...spawnOptions });
|
|
4498
|
-
let stdout = "";
|
|
4499
|
-
let stderr = "";
|
|
4500
|
-
let killed = false;
|
|
4501
|
-
const timeoutId = timeout ? setTimeout(() => {
|
|
4502
|
-
killed = true;
|
|
4503
|
-
proc.kill("SIGTERM");
|
|
4504
|
-
}, timeout) : void 0;
|
|
4505
|
-
proc.stdout.on("data", (data) => {
|
|
4506
|
-
const str = data.toString();
|
|
4507
|
-
stdout += str;
|
|
4508
|
-
onStdout?.(str);
|
|
4509
|
-
});
|
|
4510
|
-
proc.stderr.on("data", (data) => {
|
|
4511
|
-
const str = data.toString();
|
|
4512
|
-
stderr += str;
|
|
4513
|
-
onStderr?.(str);
|
|
4514
|
-
});
|
|
4515
|
-
proc.on("error", (err) => {
|
|
4516
|
-
if (timeoutId) clearTimeout(timeoutId);
|
|
4517
|
-
const errorMsg = err.message;
|
|
4518
|
-
stderr += errorMsg;
|
|
4519
|
-
onStderr?.(errorMsg);
|
|
4520
|
-
reject(err);
|
|
4521
|
-
});
|
|
4522
|
-
proc.on("close", (code, signal) => {
|
|
4523
|
-
if (timeoutId) clearTimeout(timeoutId);
|
|
4524
|
-
if (killed) {
|
|
4525
|
-
const timeoutMsg = `
|
|
4526
|
-
Process timed out after ${timeout}ms`;
|
|
4527
|
-
onStderr?.(timeoutMsg);
|
|
4528
|
-
resolve3({ stdout, stderr: stderr + timeoutMsg, exitCode: 124 });
|
|
4529
|
-
} else if (signal) {
|
|
4530
|
-
const signalMsg = `
|
|
4531
|
-
Process terminated by ${signal}`;
|
|
4532
|
-
onStderr?.(signalMsg);
|
|
4533
|
-
resolve3({ stdout, stderr: stderr + signalMsg, exitCode: 128 });
|
|
4534
|
-
} else {
|
|
4535
|
-
resolve3({ stdout, stderr, exitCode: code ?? 0 });
|
|
4536
|
-
}
|
|
4537
|
-
});
|
|
4538
|
-
});
|
|
4539
|
-
}
|
|
4540
4927
|
var LocalSandbox = class extends MastraSandbox {
|
|
4541
4928
|
id;
|
|
4542
4929
|
name = "LocalSandbox";
|
|
4543
4930
|
provider = "local";
|
|
4544
4931
|
status = "pending";
|
|
4545
|
-
|
|
4932
|
+
workingDirectory;
|
|
4933
|
+
isolation;
|
|
4546
4934
|
env;
|
|
4547
|
-
timeout;
|
|
4548
|
-
_isolation;
|
|
4549
4935
|
_nativeSandboxConfig;
|
|
4550
4936
|
_seatbeltProfile;
|
|
4551
4937
|
_seatbeltProfilePath;
|
|
4552
4938
|
_sandboxFolderPath;
|
|
4553
4939
|
_userProvidedProfilePath = false;
|
|
4554
4940
|
_createdAt;
|
|
4555
|
-
|
|
4556
|
-
* The working directory where commands are executed.
|
|
4557
|
-
*/
|
|
4558
|
-
get workingDirectory() {
|
|
4559
|
-
return this._workingDirectory;
|
|
4560
|
-
}
|
|
4561
|
-
/**
|
|
4562
|
-
* The isolation backend being used.
|
|
4563
|
-
*/
|
|
4564
|
-
get isolation() {
|
|
4565
|
-
return this._isolation;
|
|
4566
|
-
}
|
|
4567
|
-
/**
|
|
4568
|
-
* Detect the best available isolation backend for this platform.
|
|
4569
|
-
* Returns detection result with backend recommendation and availability.
|
|
4570
|
-
*
|
|
4571
|
-
* @example
|
|
4572
|
-
* ```typescript
|
|
4573
|
-
* const result = LocalSandbox.detectIsolation();
|
|
4574
|
-
* const sandbox = new LocalSandbox({
|
|
4575
|
-
* isolation: result.available ? result.backend : 'none',
|
|
4576
|
-
* });
|
|
4577
|
-
* ```
|
|
4578
|
-
*/
|
|
4579
|
-
static detectIsolation() {
|
|
4580
|
-
return detectIsolation();
|
|
4581
|
-
}
|
|
4941
|
+
_instructionsOverride;
|
|
4582
4942
|
constructor(options = {}) {
|
|
4583
|
-
super({ ...options, name: "LocalSandbox" });
|
|
4584
|
-
this.id = options.id ?? this.generateId();
|
|
4585
|
-
this._createdAt = /* @__PURE__ */ new Date();
|
|
4586
|
-
this._workingDirectory = options.workingDirectory ?? nodePath__namespace.join(process.cwd(), ".sandbox");
|
|
4587
|
-
this.env = options.env ?? {};
|
|
4588
|
-
this.timeout = options.timeout;
|
|
4589
|
-
this._nativeSandboxConfig = options.nativeSandbox ?? {};
|
|
4590
4943
|
const requestedIsolation = options.isolation ?? "none";
|
|
4591
4944
|
if (requestedIsolation !== "none" && !isIsolationAvailable(requestedIsolation)) {
|
|
4592
4945
|
const detection = detectIsolation();
|
|
4593
4946
|
throw new IsolationUnavailableError(requestedIsolation, detection.message);
|
|
4594
4947
|
}
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
PATH: process.env.PATH,
|
|
4608
|
-
// Always include PATH for finding executables
|
|
4609
|
-
...this.env,
|
|
4610
|
-
...additionalEnv
|
|
4611
|
-
};
|
|
4948
|
+
super({
|
|
4949
|
+
...options,
|
|
4950
|
+
name: "LocalSandbox",
|
|
4951
|
+
processes: new LocalProcessManager({ env: options.env ?? {} })
|
|
4952
|
+
});
|
|
4953
|
+
this.id = options.id ?? this.generateId();
|
|
4954
|
+
this._createdAt = /* @__PURE__ */ new Date();
|
|
4955
|
+
this.workingDirectory = options.workingDirectory ?? nodePath__namespace.join(process.cwd(), ".sandbox");
|
|
4956
|
+
this.env = options.env ?? {};
|
|
4957
|
+
this._nativeSandboxConfig = options.nativeSandbox ?? {};
|
|
4958
|
+
this.isolation = requestedIsolation;
|
|
4959
|
+
this._instructionsOverride = options.instructions;
|
|
4612
4960
|
}
|
|
4961
|
+
// ---------------------------------------------------------------------------
|
|
4962
|
+
// Lifecycle
|
|
4963
|
+
// ---------------------------------------------------------------------------
|
|
4613
4964
|
/**
|
|
4614
4965
|
* Start the local sandbox.
|
|
4615
4966
|
* Creates working directory and sets up seatbelt profile if using macOS isolation.
|
|
@@ -4617,11 +4968,11 @@ var LocalSandbox = class extends MastraSandbox {
|
|
|
4617
4968
|
*/
|
|
4618
4969
|
async start() {
|
|
4619
4970
|
this.logger.debug("[LocalSandbox] Starting sandbox", {
|
|
4620
|
-
workingDirectory: this.
|
|
4621
|
-
isolation: this.
|
|
4971
|
+
workingDirectory: this.workingDirectory,
|
|
4972
|
+
isolation: this.isolation
|
|
4622
4973
|
});
|
|
4623
4974
|
await fs2__namespace.mkdir(this.workingDirectory, { recursive: true });
|
|
4624
|
-
if (this.
|
|
4975
|
+
if (this.isolation === "seatbelt") {
|
|
4625
4976
|
const userProvidedPath = this._nativeSandboxConfig.seatbeltProfilePath;
|
|
4626
4977
|
if (userProvidedPath) {
|
|
4627
4978
|
this._seatbeltProfilePath = userProvidedPath;
|
|
@@ -4645,14 +4996,14 @@ var LocalSandbox = class extends MastraSandbox {
|
|
|
4645
4996
|
await fs2__namespace.writeFile(this._seatbeltProfilePath, this._seatbeltProfile, "utf-8");
|
|
4646
4997
|
}
|
|
4647
4998
|
}
|
|
4648
|
-
this.logger.debug("[LocalSandbox] Sandbox started", { workingDirectory: this.
|
|
4999
|
+
this.logger.debug("[LocalSandbox] Sandbox started", { workingDirectory: this.workingDirectory });
|
|
4649
5000
|
}
|
|
4650
5001
|
/**
|
|
4651
5002
|
* Stop the local sandbox.
|
|
4652
5003
|
* Status management is handled by the base class.
|
|
4653
5004
|
*/
|
|
4654
5005
|
async stop() {
|
|
4655
|
-
this.logger.debug("[LocalSandbox] Stopping sandbox", { workingDirectory: this.
|
|
5006
|
+
this.logger.debug("[LocalSandbox] Stopping sandbox", { workingDirectory: this.workingDirectory });
|
|
4656
5007
|
}
|
|
4657
5008
|
/**
|
|
4658
5009
|
* Destroy the local sandbox and clean up resources.
|
|
@@ -4660,7 +5011,9 @@ var LocalSandbox = class extends MastraSandbox {
|
|
|
4660
5011
|
* Status management is handled by the base class.
|
|
4661
5012
|
*/
|
|
4662
5013
|
async destroy() {
|
|
4663
|
-
this.logger.debug("[LocalSandbox] Destroying sandbox", { workingDirectory: this.
|
|
5014
|
+
this.logger.debug("[LocalSandbox] Destroying sandbox", { workingDirectory: this.workingDirectory });
|
|
5015
|
+
const procs = await this.processes.list();
|
|
5016
|
+
await Promise.all(procs.map((p) => this.processes.kill(p.pid)));
|
|
4664
5017
|
if (this._seatbeltProfilePath && !this._userProvidedProfilePath) {
|
|
4665
5018
|
try {
|
|
4666
5019
|
await fs2__namespace.unlink(this._seatbeltProfilePath);
|
|
@@ -4678,6 +5031,7 @@ var LocalSandbox = class extends MastraSandbox {
|
|
|
4678
5031
|
this._sandboxFolderPath = void 0;
|
|
4679
5032
|
}
|
|
4680
5033
|
}
|
|
5034
|
+
/** @deprecated Use `status === 'running'` instead. */
|
|
4681
5035
|
async isReady() {
|
|
4682
5036
|
return this.status === "running";
|
|
4683
5037
|
}
|
|
@@ -4696,8 +5050,8 @@ var LocalSandbox = class extends MastraSandbox {
|
|
|
4696
5050
|
workingDirectory: this.workingDirectory,
|
|
4697
5051
|
platform: os__namespace.platform(),
|
|
4698
5052
|
nodeVersion: process.version,
|
|
4699
|
-
isolation: this.
|
|
4700
|
-
isolationConfig: this.
|
|
5053
|
+
isolation: this.isolation,
|
|
5054
|
+
isolationConfig: this.isolation !== "none" ? {
|
|
4701
5055
|
allowNetwork: this._nativeSandboxConfig.allowNetwork ?? false,
|
|
4702
5056
|
readOnlyPaths: this._nativeSandboxConfig.readOnlyPaths,
|
|
4703
5057
|
readWritePaths: this._nativeSandboxConfig.readWritePaths
|
|
@@ -4705,63 +5059,61 @@ var LocalSandbox = class extends MastraSandbox {
|
|
|
4705
5059
|
}
|
|
4706
5060
|
};
|
|
4707
5061
|
}
|
|
4708
|
-
getInstructions() {
|
|
4709
|
-
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
return
|
|
5062
|
+
getInstructions(opts) {
|
|
5063
|
+
return resolveInstructions(this._instructionsOverride, () => this._getDefaultInstructions(), opts?.requestContext);
|
|
5064
|
+
}
|
|
5065
|
+
_getDefaultInstructions() {
|
|
5066
|
+
return `Local command execution. Working directory: "${this.workingDirectory}".`;
|
|
5067
|
+
}
|
|
5068
|
+
// ---------------------------------------------------------------------------
|
|
5069
|
+
// Internal Utils
|
|
5070
|
+
// ---------------------------------------------------------------------------
|
|
5071
|
+
generateId() {
|
|
5072
|
+
return `local-sandbox-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
5073
|
+
}
|
|
5074
|
+
/**
|
|
5075
|
+
* Build the environment object for execution.
|
|
5076
|
+
* Always includes PATH by default (needed for finding executables).
|
|
5077
|
+
* Merges the sandbox's configured env with any additional env from the command.
|
|
5078
|
+
* @internal Used by LocalProcessManager.
|
|
5079
|
+
*/
|
|
5080
|
+
buildEnv(additionalEnv) {
|
|
5081
|
+
return {
|
|
5082
|
+
PATH: process.env.PATH,
|
|
5083
|
+
// Always include PATH for finding executables
|
|
5084
|
+
...this.env,
|
|
5085
|
+
...additionalEnv
|
|
5086
|
+
};
|
|
4713
5087
|
}
|
|
4714
5088
|
/**
|
|
4715
5089
|
* Wrap a command with the configured isolation backend.
|
|
5090
|
+
* @internal Used by LocalProcessManager for background process isolation.
|
|
4716
5091
|
*/
|
|
4717
|
-
wrapCommandForIsolation(command
|
|
4718
|
-
if (this.
|
|
4719
|
-
return { command, args };
|
|
5092
|
+
wrapCommandForIsolation(command) {
|
|
5093
|
+
if (this.isolation === "none") {
|
|
5094
|
+
return { command, args: [] };
|
|
4720
5095
|
}
|
|
4721
|
-
return wrapCommand(command,
|
|
4722
|
-
backend: this.
|
|
5096
|
+
return wrapCommand(command, {
|
|
5097
|
+
backend: this.isolation,
|
|
4723
5098
|
workspacePath: this.workingDirectory,
|
|
4724
5099
|
seatbeltProfile: this._seatbeltProfile,
|
|
4725
5100
|
config: this._nativeSandboxConfig
|
|
4726
5101
|
});
|
|
4727
5102
|
}
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
|
|
4742
|
-
success: result.exitCode === 0,
|
|
4743
|
-
stdout: result.stdout,
|
|
4744
|
-
stderr: result.stderr,
|
|
4745
|
-
exitCode: result.exitCode,
|
|
4746
|
-
executionTimeMs: Date.now() - startTime
|
|
4747
|
-
};
|
|
4748
|
-
this.logger.debug("[LocalSandbox] Command completed", {
|
|
4749
|
-
command,
|
|
4750
|
-
exitCode: commandResult.exitCode,
|
|
4751
|
-
executionTimeMs: commandResult.executionTimeMs
|
|
4752
|
-
});
|
|
4753
|
-
return commandResult;
|
|
4754
|
-
} catch (error) {
|
|
4755
|
-
const executionTimeMs = Date.now() - startTime;
|
|
4756
|
-
this.logger.error("[LocalSandbox] Command failed", { command, error, executionTimeMs });
|
|
4757
|
-
return {
|
|
4758
|
-
success: false,
|
|
4759
|
-
stdout: "",
|
|
4760
|
-
stderr: error instanceof Error ? error.message : String(error),
|
|
4761
|
-
exitCode: 1,
|
|
4762
|
-
executionTimeMs
|
|
4763
|
-
};
|
|
4764
|
-
}
|
|
5103
|
+
/**
|
|
5104
|
+
* Detect the best available isolation backend for this platform.
|
|
5105
|
+
* Returns detection result with backend recommendation and availability.
|
|
5106
|
+
*
|
|
5107
|
+
* @example
|
|
5108
|
+
* ```typescript
|
|
5109
|
+
* const result = LocalSandbox.detectIsolation();
|
|
5110
|
+
* const sandbox = new LocalSandbox({
|
|
5111
|
+
* isolation: result.available ? result.backend : 'none',
|
|
5112
|
+
* });
|
|
5113
|
+
* ```
|
|
5114
|
+
*/
|
|
5115
|
+
static detectIsolation() {
|
|
5116
|
+
return detectIsolation();
|
|
4765
5117
|
}
|
|
4766
5118
|
};
|
|
4767
5119
|
|
|
@@ -4780,7 +5132,9 @@ var WORKSPACE_TOOLS = {
|
|
|
4780
5132
|
AST_EDIT: `${WORKSPACE_TOOLS_PREFIX}_ast_edit`
|
|
4781
5133
|
},
|
|
4782
5134
|
SANDBOX: {
|
|
4783
|
-
EXECUTE_COMMAND: `${WORKSPACE_TOOLS_PREFIX}_execute_command
|
|
5135
|
+
EXECUTE_COMMAND: `${WORKSPACE_TOOLS_PREFIX}_execute_command`,
|
|
5136
|
+
GET_PROCESS_OUTPUT: `${WORKSPACE_TOOLS_PREFIX}_get_process_output`,
|
|
5137
|
+
KILL_PROCESS: `${WORKSPACE_TOOLS_PREFIX}_kill_process`
|
|
4784
5138
|
},
|
|
4785
5139
|
SEARCH: {
|
|
4786
5140
|
SEARCH: `${WORKSPACE_TOOLS_PREFIX}_search`,
|
|
@@ -4849,7 +5203,7 @@ function isAstGrepAvailable() {
|
|
|
4849
5203
|
return astGrepModule !== null;
|
|
4850
5204
|
}
|
|
4851
5205
|
try {
|
|
4852
|
-
const req = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-
|
|
5206
|
+
const req = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-7UAJ6LMR.cjs', document.baseURI).href)));
|
|
4853
5207
|
req.resolve("@ast-grep/napi");
|
|
4854
5208
|
return true;
|
|
4855
5209
|
} catch {
|
|
@@ -5193,81 +5547,144 @@ Usage:
|
|
|
5193
5547
|
}
|
|
5194
5548
|
}
|
|
5195
5549
|
});
|
|
5196
|
-
var executeCommandTool = chunkEAZ6YDCQ_cjs.createTool({
|
|
5197
|
-
id: WORKSPACE_TOOLS.SANDBOX.EXECUTE_COMMAND,
|
|
5198
|
-
description: `Execute a shell command in the workspace sandbox.
|
|
5199
5550
|
|
|
5200
|
-
|
|
5201
|
-
|
|
5202
|
-
|
|
5203
|
-
|
|
5204
|
-
|
|
5205
|
-
|
|
5206
|
-
|
|
5207
|
-
|
|
5208
|
-
|
|
5209
|
-
|
|
5210
|
-
|
|
5211
|
-
|
|
5212
|
-
|
|
5213
|
-
|
|
5214
|
-
|
|
5551
|
+
// src/workspace/tools/output-helpers.ts
|
|
5552
|
+
var DEFAULT_TAIL_LINES = 200;
|
|
5553
|
+
var MAX_OUTPUT_CHARS = 3e4;
|
|
5554
|
+
function applyTail(output, tail) {
|
|
5555
|
+
if (!output) return output;
|
|
5556
|
+
const n = Math.abs(tail ?? DEFAULT_TAIL_LINES);
|
|
5557
|
+
if (n === 0) return output;
|
|
5558
|
+
const trailingNewline = output.endsWith("\n");
|
|
5559
|
+
const lines = (trailingNewline ? output.slice(0, -1) : output).split("\n");
|
|
5560
|
+
if (lines.length <= n) return output;
|
|
5561
|
+
const sliced = lines.slice(-n).join("\n");
|
|
5562
|
+
const body = trailingNewline ? sliced + "\n" : sliced;
|
|
5563
|
+
return `[showing last ${n} of ${lines.length} lines]
|
|
5564
|
+
${body}`;
|
|
5565
|
+
}
|
|
5566
|
+
function applyCharLimit(output, limit = MAX_OUTPUT_CHARS) {
|
|
5567
|
+
if (!output || output.length <= limit) return output;
|
|
5568
|
+
const truncated = output.slice(-limit);
|
|
5569
|
+
return `[output truncated: showing last ${limit} of ${output.length} characters]
|
|
5570
|
+
${truncated}`;
|
|
5571
|
+
}
|
|
5572
|
+
function truncateOutput(output, tail, charLimit) {
|
|
5573
|
+
return applyCharLimit(applyTail(output, tail), charLimit);
|
|
5574
|
+
}
|
|
5575
|
+
|
|
5576
|
+
// src/workspace/tools/execute-command.ts
|
|
5577
|
+
var executeCommandInputSchema = zod.z.object({
|
|
5578
|
+
command: zod.z.string().describe('The shell command to execute (e.g., "npm install", "ls -la src/", "cat file.txt | grep error")'),
|
|
5579
|
+
timeout: zod.z.number().nullish().describe("Maximum execution time in milliseconds. Example: 60000 for 1 minute."),
|
|
5580
|
+
cwd: zod.z.string().nullish().describe("Working directory for the command"),
|
|
5581
|
+
tail: zod.z.number().nullish().describe(
|
|
5582
|
+
`For foreground commands: limit output to the last N lines, similar to tail -n. Defaults to ${DEFAULT_TAIL_LINES}. Use 0 for no limit.`
|
|
5583
|
+
)
|
|
5584
|
+
});
|
|
5585
|
+
var executeCommandWithBackgroundSchema = executeCommandInputSchema.extend({
|
|
5586
|
+
background: zod.z.boolean().optional().describe(
|
|
5587
|
+
"Run the command in the background. Returns a PID immediately instead of waiting for completion. Use get_process_output to check on it later."
|
|
5588
|
+
)
|
|
5589
|
+
});
|
|
5590
|
+
async function executeCommand(input, context) {
|
|
5591
|
+
const { command, timeout, cwd, tail } = input;
|
|
5592
|
+
const background = input.background;
|
|
5593
|
+
const { sandbox } = requireSandbox(context);
|
|
5594
|
+
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.SANDBOX.EXECUTE_COMMAND);
|
|
5595
|
+
const toolCallId = context?.agent?.toolCallId;
|
|
5596
|
+
if (background) {
|
|
5597
|
+
if (!sandbox.processes) {
|
|
5598
|
+
throw new SandboxFeatureNotSupportedError("processes");
|
|
5215
5599
|
}
|
|
5216
|
-
await
|
|
5217
|
-
|
|
5218
|
-
|
|
5219
|
-
|
|
5220
|
-
|
|
5221
|
-
|
|
5222
|
-
|
|
5223
|
-
|
|
5224
|
-
|
|
5225
|
-
|
|
5226
|
-
|
|
5227
|
-
|
|
5228
|
-
|
|
5229
|
-
|
|
5230
|
-
|
|
5231
|
-
|
|
5232
|
-
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
|
|
5237
|
-
|
|
5238
|
-
|
|
5239
|
-
|
|
5240
|
-
|
|
5241
|
-
|
|
5242
|
-
|
|
5243
|
-
|
|
5244
|
-
|
|
5245
|
-
executionTimeMs: result.executionTimeMs,
|
|
5246
|
-
toolCallId
|
|
5247
|
-
}
|
|
5248
|
-
});
|
|
5249
|
-
if (!result.success) {
|
|
5250
|
-
const parts = [result.stdout, result.stderr].filter(Boolean);
|
|
5251
|
-
parts.push(`Exit code: ${result.exitCode}`);
|
|
5252
|
-
return parts.join("\n");
|
|
5600
|
+
const handle = await sandbox.processes.spawn(command, {
|
|
5601
|
+
cwd: cwd ?? void 0,
|
|
5602
|
+
timeout: timeout ?? void 0
|
|
5603
|
+
});
|
|
5604
|
+
return `Started background process (PID: ${handle.pid})`;
|
|
5605
|
+
}
|
|
5606
|
+
if (!sandbox.executeCommand) {
|
|
5607
|
+
throw new SandboxFeatureNotSupportedError("executeCommand");
|
|
5608
|
+
}
|
|
5609
|
+
const startedAt = Date.now();
|
|
5610
|
+
let stdout = "";
|
|
5611
|
+
let stderr = "";
|
|
5612
|
+
try {
|
|
5613
|
+
const result = await sandbox.executeCommand(command, [], {
|
|
5614
|
+
timeout: timeout ?? void 0,
|
|
5615
|
+
cwd: cwd ?? void 0,
|
|
5616
|
+
onStdout: async (data) => {
|
|
5617
|
+
stdout += data;
|
|
5618
|
+
await context?.writer?.custom({
|
|
5619
|
+
type: "data-sandbox-stdout",
|
|
5620
|
+
data: { output: data, timestamp: Date.now(), toolCallId }
|
|
5621
|
+
});
|
|
5622
|
+
},
|
|
5623
|
+
onStderr: async (data) => {
|
|
5624
|
+
stderr += data;
|
|
5625
|
+
await context?.writer?.custom({
|
|
5626
|
+
type: "data-sandbox-stderr",
|
|
5627
|
+
data: { output: data, timestamp: Date.now(), toolCallId }
|
|
5628
|
+
});
|
|
5253
5629
|
}
|
|
5254
|
-
|
|
5255
|
-
|
|
5256
|
-
|
|
5257
|
-
|
|
5258
|
-
|
|
5259
|
-
|
|
5260
|
-
|
|
5261
|
-
|
|
5262
|
-
|
|
5263
|
-
|
|
5264
|
-
|
|
5265
|
-
const parts = [stdout, stderr].filter(Boolean);
|
|
5266
|
-
|
|
5267
|
-
parts.push(`Error: ${errorMessage}`);
|
|
5630
|
+
});
|
|
5631
|
+
await context?.writer?.custom({
|
|
5632
|
+
type: "data-sandbox-exit",
|
|
5633
|
+
data: {
|
|
5634
|
+
exitCode: result.exitCode,
|
|
5635
|
+
success: result.success,
|
|
5636
|
+
executionTimeMs: result.executionTimeMs,
|
|
5637
|
+
toolCallId
|
|
5638
|
+
}
|
|
5639
|
+
});
|
|
5640
|
+
if (!result.success) {
|
|
5641
|
+
const parts = [truncateOutput(result.stdout, tail), truncateOutput(result.stderr, tail)].filter(Boolean);
|
|
5642
|
+
parts.push(`Exit code: ${result.exitCode}`);
|
|
5268
5643
|
return parts.join("\n");
|
|
5269
5644
|
}
|
|
5645
|
+
return truncateOutput(result.stdout, tail) || "(no output)";
|
|
5646
|
+
} catch (error) {
|
|
5647
|
+
await context?.writer?.custom({
|
|
5648
|
+
type: "data-sandbox-exit",
|
|
5649
|
+
data: {
|
|
5650
|
+
exitCode: -1,
|
|
5651
|
+
success: false,
|
|
5652
|
+
executionTimeMs: Date.now() - startedAt,
|
|
5653
|
+
toolCallId
|
|
5654
|
+
}
|
|
5655
|
+
});
|
|
5656
|
+
const parts = [truncateOutput(stdout, tail), truncateOutput(stderr, tail)].filter(Boolean);
|
|
5657
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
5658
|
+
parts.push(`Error: ${errorMessage}`);
|
|
5659
|
+
return parts.join("\n");
|
|
5270
5660
|
}
|
|
5661
|
+
}
|
|
5662
|
+
var baseDescription = `Execute a shell command in the workspace sandbox.
|
|
5663
|
+
|
|
5664
|
+
Examples:
|
|
5665
|
+
"npm install && npm run build"
|
|
5666
|
+
"ls -la src/"
|
|
5667
|
+
"cat config.json | jq '.database'"
|
|
5668
|
+
"cd /app && python main.py"
|
|
5669
|
+
|
|
5670
|
+
Usage:
|
|
5671
|
+
- Commands run in a shell, so pipes, redirects, and chaining (&&, ||, ;) all work.
|
|
5672
|
+
- Always quote file paths that contain spaces (e.g., cd "/path/with spaces").
|
|
5673
|
+
- Use the timeout parameter to limit execution time. Behavior when omitted depends on the sandbox provider.
|
|
5674
|
+
- Optionally use cwd to override the working directory. Commands run from the sandbox default if omitted.`;
|
|
5675
|
+
var executeCommandTool = chunkEAZ6YDCQ_cjs.createTool({
|
|
5676
|
+
id: WORKSPACE_TOOLS.SANDBOX.EXECUTE_COMMAND,
|
|
5677
|
+
description: baseDescription,
|
|
5678
|
+
inputSchema: executeCommandInputSchema,
|
|
5679
|
+
execute: executeCommand
|
|
5680
|
+
});
|
|
5681
|
+
var executeCommandWithBackgroundTool = chunkEAZ6YDCQ_cjs.createTool({
|
|
5682
|
+
id: WORKSPACE_TOOLS.SANDBOX.EXECUTE_COMMAND,
|
|
5683
|
+
description: `${baseDescription}
|
|
5684
|
+
|
|
5685
|
+
Set background: true to run long-running commands (dev servers, watchers) without blocking. You'll get a PID to track the process.`,
|
|
5686
|
+
inputSchema: executeCommandWithBackgroundSchema,
|
|
5687
|
+
execute: executeCommand
|
|
5271
5688
|
});
|
|
5272
5689
|
var fileStatTool = chunkEAZ6YDCQ_cjs.createTool({
|
|
5273
5690
|
id: WORKSPACE_TOOLS.FILESYSTEM.FILE_STAT,
|
|
@@ -5293,6 +5710,82 @@ var fileStatTool = chunkEAZ6YDCQ_cjs.createTool({
|
|
|
5293
5710
|
}
|
|
5294
5711
|
}
|
|
5295
5712
|
});
|
|
5713
|
+
var getProcessOutputTool = chunkEAZ6YDCQ_cjs.createTool({
|
|
5714
|
+
id: WORKSPACE_TOOLS.SANDBOX.GET_PROCESS_OUTPUT,
|
|
5715
|
+
description: `Get the current output (stdout, stderr) and status of a background process by its PID.
|
|
5716
|
+
|
|
5717
|
+
Use this after starting a background command with execute_command (background: true) to check if the process is still running and read its output.`,
|
|
5718
|
+
inputSchema: zod.z.object({
|
|
5719
|
+
pid: zod.z.number().describe("The process ID returned when the background command was started"),
|
|
5720
|
+
tail: zod.z.number().optional().describe(
|
|
5721
|
+
`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.`
|
|
5722
|
+
),
|
|
5723
|
+
wait: zod.z.boolean().optional().describe(
|
|
5724
|
+
"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."
|
|
5725
|
+
)
|
|
5726
|
+
}),
|
|
5727
|
+
execute: async ({ pid, tail, wait: shouldWait }, context) => {
|
|
5728
|
+
const { sandbox } = requireSandbox(context);
|
|
5729
|
+
if (!sandbox.processes) {
|
|
5730
|
+
throw new SandboxFeatureNotSupportedError("processes");
|
|
5731
|
+
}
|
|
5732
|
+
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.SANDBOX.GET_PROCESS_OUTPUT);
|
|
5733
|
+
const toolCallId = context?.agent?.toolCallId;
|
|
5734
|
+
const handle = await sandbox.processes.get(pid);
|
|
5735
|
+
if (!handle) {
|
|
5736
|
+
return `No background process found with PID ${pid}.`;
|
|
5737
|
+
}
|
|
5738
|
+
if (handle.command) {
|
|
5739
|
+
await context?.writer?.custom({
|
|
5740
|
+
type: "data-sandbox-command",
|
|
5741
|
+
data: { command: handle.command, pid, toolCallId }
|
|
5742
|
+
});
|
|
5743
|
+
}
|
|
5744
|
+
if (shouldWait && handle.exitCode === void 0) {
|
|
5745
|
+
const result = await handle.wait({
|
|
5746
|
+
onStdout: context?.writer ? async (data) => {
|
|
5747
|
+
await context.writer.custom({
|
|
5748
|
+
type: "data-sandbox-stdout",
|
|
5749
|
+
data: { output: data, timestamp: Date.now(), toolCallId }
|
|
5750
|
+
});
|
|
5751
|
+
} : void 0,
|
|
5752
|
+
onStderr: context?.writer ? async (data) => {
|
|
5753
|
+
await context.writer.custom({
|
|
5754
|
+
type: "data-sandbox-stderr",
|
|
5755
|
+
data: { output: data, timestamp: Date.now(), toolCallId }
|
|
5756
|
+
});
|
|
5757
|
+
} : void 0
|
|
5758
|
+
});
|
|
5759
|
+
await context?.writer?.custom({
|
|
5760
|
+
type: "data-sandbox-exit",
|
|
5761
|
+
data: {
|
|
5762
|
+
exitCode: result.exitCode,
|
|
5763
|
+
success: result.success,
|
|
5764
|
+
executionTimeMs: result.executionTimeMs,
|
|
5765
|
+
toolCallId
|
|
5766
|
+
}
|
|
5767
|
+
});
|
|
5768
|
+
}
|
|
5769
|
+
const running = handle.exitCode === void 0;
|
|
5770
|
+
const stdout = truncateOutput(handle.stdout, tail);
|
|
5771
|
+
const stderr = truncateOutput(handle.stderr, tail);
|
|
5772
|
+
if (!stdout && !stderr) {
|
|
5773
|
+
return "(no output yet)";
|
|
5774
|
+
}
|
|
5775
|
+
const parts = [];
|
|
5776
|
+
if (stdout && stderr) {
|
|
5777
|
+
parts.push("stdout:", stdout, "", "stderr:", stderr);
|
|
5778
|
+
} else if (stdout) {
|
|
5779
|
+
parts.push(stdout);
|
|
5780
|
+
} else {
|
|
5781
|
+
parts.push("stderr:", stderr);
|
|
5782
|
+
}
|
|
5783
|
+
if (!running) {
|
|
5784
|
+
parts.push("", `Exit code: ${handle.exitCode}`);
|
|
5785
|
+
}
|
|
5786
|
+
return parts.join("\n");
|
|
5787
|
+
}
|
|
5788
|
+
});
|
|
5296
5789
|
var grepTool = chunkEAZ6YDCQ_cjs.createTool({
|
|
5297
5790
|
id: WORKSPACE_TOOLS.FILESYSTEM.GREP,
|
|
5298
5791
|
description: `Search file contents using a regex pattern. Walks the filesystem and returns matching lines with file paths and line numbers.
|
|
@@ -5449,6 +5942,55 @@ var indexContentTool = chunkEAZ6YDCQ_cjs.createTool({
|
|
|
5449
5942
|
return `Indexed ${path4}`;
|
|
5450
5943
|
}
|
|
5451
5944
|
});
|
|
5945
|
+
var KILL_TAIL_LINES = 50;
|
|
5946
|
+
var killProcessTool = chunkEAZ6YDCQ_cjs.createTool({
|
|
5947
|
+
id: WORKSPACE_TOOLS.SANDBOX.KILL_PROCESS,
|
|
5948
|
+
description: `Kill a background process by its PID.
|
|
5949
|
+
|
|
5950
|
+
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.`,
|
|
5951
|
+
inputSchema: zod.z.object({
|
|
5952
|
+
pid: zod.z.number().describe("The process ID of the background process to kill")
|
|
5953
|
+
}),
|
|
5954
|
+
execute: async ({ pid }, context) => {
|
|
5955
|
+
const { sandbox } = requireSandbox(context);
|
|
5956
|
+
if (!sandbox.processes) {
|
|
5957
|
+
throw new SandboxFeatureNotSupportedError("processes");
|
|
5958
|
+
}
|
|
5959
|
+
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.SANDBOX.KILL_PROCESS);
|
|
5960
|
+
const toolCallId = context?.agent?.toolCallId;
|
|
5961
|
+
const handle = await sandbox.processes.get(pid);
|
|
5962
|
+
if (handle?.command) {
|
|
5963
|
+
await context?.writer?.custom({
|
|
5964
|
+
type: "data-sandbox-command",
|
|
5965
|
+
data: { command: handle.command, pid, toolCallId }
|
|
5966
|
+
});
|
|
5967
|
+
}
|
|
5968
|
+
const killed = await sandbox.processes.kill(pid);
|
|
5969
|
+
if (!killed) {
|
|
5970
|
+
await context?.writer?.custom({
|
|
5971
|
+
type: "data-sandbox-exit",
|
|
5972
|
+
data: { exitCode: handle?.exitCode ?? -1, success: false, killed: false, toolCallId }
|
|
5973
|
+
});
|
|
5974
|
+
return `Process ${pid} was not found or had already exited.`;
|
|
5975
|
+
}
|
|
5976
|
+
await context?.writer?.custom({
|
|
5977
|
+
type: "data-sandbox-exit",
|
|
5978
|
+
data: { exitCode: handle?.exitCode ?? 137, success: false, killed: true, toolCallId }
|
|
5979
|
+
});
|
|
5980
|
+
const parts = [`Process ${pid} has been killed.`];
|
|
5981
|
+
if (handle) {
|
|
5982
|
+
const stdout = handle.stdout ? truncateOutput(handle.stdout, KILL_TAIL_LINES) : "";
|
|
5983
|
+
const stderr = handle.stderr ? truncateOutput(handle.stderr, KILL_TAIL_LINES) : "";
|
|
5984
|
+
if (stdout) {
|
|
5985
|
+
parts.push("", "--- stdout (last output) ---", stdout);
|
|
5986
|
+
}
|
|
5987
|
+
if (stderr) {
|
|
5988
|
+
parts.push("", "--- stderr (last output) ---", stderr);
|
|
5989
|
+
}
|
|
5990
|
+
}
|
|
5991
|
+
return parts.join("\n");
|
|
5992
|
+
}
|
|
5993
|
+
});
|
|
5452
5994
|
|
|
5453
5995
|
// src/workspace/tools/tree-formatter.ts
|
|
5454
5996
|
var BRANCH = "\u251C\u2500\u2500 ";
|
|
@@ -5783,10 +6325,22 @@ function wrapWithReadTracker(tool, workspace, readTracker, config, mode) {
|
|
|
5783
6325
|
}
|
|
5784
6326
|
};
|
|
5785
6327
|
}
|
|
6328
|
+
function wrapWithWriteLock(tool, writeLock) {
|
|
6329
|
+
return {
|
|
6330
|
+
...tool,
|
|
6331
|
+
execute: async (input, context = {}) => {
|
|
6332
|
+
if (!input.path) {
|
|
6333
|
+
throw new Error("wrapWithWriteLock: input.path is required");
|
|
6334
|
+
}
|
|
6335
|
+
return writeLock.withLock(input.path, () => tool.execute(input, context));
|
|
6336
|
+
}
|
|
6337
|
+
};
|
|
6338
|
+
}
|
|
5786
6339
|
function createWorkspaceTools(workspace) {
|
|
5787
6340
|
const tools = {};
|
|
5788
6341
|
const toolsConfig = workspace.getToolsConfig();
|
|
5789
6342
|
const isReadOnly = workspace.filesystem?.readOnly ?? false;
|
|
6343
|
+
const writeLock = new InMemoryFileWriteLock();
|
|
5790
6344
|
let readTracker;
|
|
5791
6345
|
const writeFileConfig = resolveToolConfig(toolsConfig, WORKSPACE_TOOLS.FILESYSTEM.WRITE_FILE);
|
|
5792
6346
|
const editFileConfig = resolveToolConfig(toolsConfig, WORKSPACE_TOOLS.FILESYSTEM.EDIT_FILE);
|
|
@@ -5798,31 +6352,39 @@ function createWorkspaceTools(workspace) {
|
|
|
5798
6352
|
const config = resolveToolConfig(toolsConfig, name);
|
|
5799
6353
|
if (!config.enabled) return;
|
|
5800
6354
|
if (opts?.requireWrite && isReadOnly) return;
|
|
6355
|
+
let wrapped;
|
|
5801
6356
|
if (readTracker && opts?.readTrackerMode) {
|
|
5802
|
-
|
|
6357
|
+
wrapped = wrapWithReadTracker(tool, workspace, readTracker, config, opts.readTrackerMode);
|
|
5803
6358
|
} else {
|
|
5804
|
-
|
|
6359
|
+
wrapped = wrapTool(tool, workspace, config);
|
|
6360
|
+
}
|
|
6361
|
+
if (opts?.useWriteLock) {
|
|
6362
|
+
wrapped = wrapWithWriteLock(wrapped, writeLock);
|
|
5805
6363
|
}
|
|
6364
|
+
tools[name] = wrapped;
|
|
5806
6365
|
};
|
|
5807
6366
|
if (workspace.filesystem) {
|
|
5808
6367
|
addTool(WORKSPACE_TOOLS.FILESYSTEM.READ_FILE, readFileTool, { readTrackerMode: "read" });
|
|
5809
6368
|
addTool(WORKSPACE_TOOLS.FILESYSTEM.WRITE_FILE, writeFileTool, {
|
|
5810
6369
|
requireWrite: true,
|
|
5811
|
-
readTrackerMode: "write"
|
|
6370
|
+
readTrackerMode: "write",
|
|
6371
|
+
useWriteLock: true
|
|
5812
6372
|
});
|
|
5813
6373
|
addTool(WORKSPACE_TOOLS.FILESYSTEM.EDIT_FILE, editFileTool, {
|
|
5814
6374
|
requireWrite: true,
|
|
5815
|
-
readTrackerMode: "write"
|
|
6375
|
+
readTrackerMode: "write",
|
|
6376
|
+
useWriteLock: true
|
|
5816
6377
|
});
|
|
5817
6378
|
addTool(WORKSPACE_TOOLS.FILESYSTEM.LIST_FILES, listFilesTool);
|
|
5818
|
-
addTool(WORKSPACE_TOOLS.FILESYSTEM.DELETE, deleteFileTool, { requireWrite: true });
|
|
6379
|
+
addTool(WORKSPACE_TOOLS.FILESYSTEM.DELETE, deleteFileTool, { requireWrite: true, useWriteLock: true });
|
|
5819
6380
|
addTool(WORKSPACE_TOOLS.FILESYSTEM.FILE_STAT, fileStatTool);
|
|
5820
6381
|
addTool(WORKSPACE_TOOLS.FILESYSTEM.MKDIR, mkdirTool, { requireWrite: true });
|
|
5821
6382
|
addTool(WORKSPACE_TOOLS.FILESYSTEM.GREP, grepTool);
|
|
5822
6383
|
if (isAstGrepAvailable()) {
|
|
5823
6384
|
addTool(WORKSPACE_TOOLS.FILESYSTEM.AST_EDIT, astEditTool, {
|
|
5824
6385
|
requireWrite: true,
|
|
5825
|
-
readTrackerMode: "write"
|
|
6386
|
+
readTrackerMode: "write",
|
|
6387
|
+
useWriteLock: true
|
|
5826
6388
|
});
|
|
5827
6389
|
}
|
|
5828
6390
|
}
|
|
@@ -5833,15 +6395,12 @@ function createWorkspaceTools(workspace) {
|
|
|
5833
6395
|
if (workspace.sandbox) {
|
|
5834
6396
|
const executeCommandConfig = resolveToolConfig(toolsConfig, WORKSPACE_TOOLS.SANDBOX.EXECUTE_COMMAND);
|
|
5835
6397
|
if (workspace.sandbox.executeCommand && executeCommandConfig.enabled) {
|
|
5836
|
-
const
|
|
5837
|
-
|
|
5838
|
-
|
|
5839
|
-
|
|
5840
|
-
|
|
5841
|
-
|
|
5842
|
-
...wrapTool(executeCommandTool, workspace, executeCommandConfig),
|
|
5843
|
-
description
|
|
5844
|
-
};
|
|
6398
|
+
const baseTool = workspace.sandbox.processes ? executeCommandWithBackgroundTool : executeCommandTool;
|
|
6399
|
+
tools[WORKSPACE_TOOLS.SANDBOX.EXECUTE_COMMAND] = wrapTool(baseTool, workspace, executeCommandConfig);
|
|
6400
|
+
}
|
|
6401
|
+
if (workspace.sandbox.processes) {
|
|
6402
|
+
addTool(WORKSPACE_TOOLS.SANDBOX.GET_PROCESS_OUTPUT, getProcessOutputTool);
|
|
6403
|
+
addTool(WORKSPACE_TOOLS.SANDBOX.KILL_PROCESS, killProcessTool);
|
|
5845
6404
|
}
|
|
5846
6405
|
}
|
|
5847
6406
|
return tools;
|
|
@@ -5871,11 +6430,13 @@ exports.MountManager = MountManager;
|
|
|
5871
6430
|
exports.MountNotSupportedError = MountNotSupportedError;
|
|
5872
6431
|
exports.NotDirectoryError = NotDirectoryError;
|
|
5873
6432
|
exports.PermissionError = PermissionError;
|
|
6433
|
+
exports.ProcessHandle = ProcessHandle;
|
|
5874
6434
|
exports.SandboxError = SandboxError;
|
|
5875
6435
|
exports.SandboxExecutionError = SandboxExecutionError;
|
|
5876
6436
|
exports.SandboxFeatureNotSupportedError = SandboxFeatureNotSupportedError;
|
|
5877
6437
|
exports.SandboxNotAvailableError = SandboxNotAvailableError;
|
|
5878
6438
|
exports.SandboxNotReadyError = SandboxNotReadyError;
|
|
6439
|
+
exports.SandboxProcessManager = SandboxProcessManager;
|
|
5879
6440
|
exports.SandboxTimeoutError = SandboxTimeoutError;
|
|
5880
6441
|
exports.SearchNotAvailableError = SearchNotAvailableError;
|
|
5881
6442
|
exports.VersionedSkillSource = VersionedSkillSource;
|
|
@@ -5912,5 +6473,5 @@ exports.requireWorkspace = requireWorkspace;
|
|
|
5912
6473
|
exports.resolveToolConfig = resolveToolConfig;
|
|
5913
6474
|
exports.searchTool = searchTool;
|
|
5914
6475
|
exports.writeFileTool = writeFileTool;
|
|
5915
|
-
//# sourceMappingURL=chunk-
|
|
5916
|
-
//# sourceMappingURL=chunk-
|
|
6476
|
+
//# sourceMappingURL=chunk-7UAJ6LMR.cjs.map
|
|
6477
|
+
//# sourceMappingURL=chunk-7UAJ6LMR.cjs.map
|