@mastra/agentcore 0.0.0 → 0.2.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/LICENSE.md +30 -0
- package/dist/index.cjs +331 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +328 -0
- package/dist/index.js.map +1 -0
- package/dist/provider.d.ts +22 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/sandbox/index.d.ts +90 -0
- package/dist/sandbox/index.d.ts.map +1 -0
- package/package.json +19 -19
package/CHANGELOG.md
CHANGED
|
@@ -1 +1,25 @@
|
|
|
1
1
|
# @mastra/agentcore
|
|
2
|
+
|
|
3
|
+
## 0.2.0-alpha.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added AWS Bedrock AgentCore Runtime sandbox support. ([#16642](https://github.com/mastra-ai/mastra/pull/16642))
|
|
8
|
+
|
|
9
|
+
You can now run Workspace commands in AWS Bedrock AgentCore Runtime through a sandbox provider.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { AgentCoreRuntimeSandbox } from '@mastra/agentcore';
|
|
13
|
+
|
|
14
|
+
const sandbox = new AgentCoreRuntimeSandbox({
|
|
15
|
+
region: 'us-west-2',
|
|
16
|
+
agentRuntimeArn: process.env.AGENTCORE_RUNTIME_ARN!,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const result = await sandbox.executeCommand('node', ['--version']);
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- Updated dependencies [[`8ace89d`](https://github.com/mastra-ai/mastra/commit/8ace89df77f762e622d3b9f7f65ad7524350d050), [`fa63872`](https://github.com/mastra-ai/mastra/commit/fa6387280954e6b667bec5714b55ba082bc627ff), [`f07b646`](https://github.com/mastra-ai/mastra/commit/f07b64604ab7d25391179790b7fd4823df9e2dff), [`d8838ae`](https://github.com/mastra-ai/mastra/commit/d8838ae80b69780361693d27098f7f6684af12fe), [`40f9297`](https://github.com/mastra-ai/mastra/commit/40f9297003b921c62373d3e8d3a4bda76c9f6de3), [`0f0d1ba`](https://github.com/mastra-ai/mastra/commit/0f0d1ba67bfcb2204e571401662f1eceefc03357), [`8c31bcd`](https://github.com/mastra-ai/mastra/commit/8c31bcdb00e597880d5939b1b7d7566fbe5dacae), [`95b14cd`](https://github.com/mastra-ai/mastra/commit/95b14cdd820e86d97ac05fe568424c513a252e31), [`aa36be2`](https://github.com/mastra-ai/mastra/commit/aa36be23aa513b7dc53cb8ca16b7fab8f20e43ad), [`212c635`](https://github.com/mastra-ai/mastra/commit/212c635203e61d036ab41db8ff86c3893dc795b3), [`d8838ae`](https://github.com/mastra-ai/mastra/commit/d8838ae80b69780361693d27098f7f6684af12fe), [`9aa5a73`](https://github.com/mastra-ai/mastra/commit/9aa5a73e7e110f6e9365eec69364a33d5f03bb56), [`f73c789`](https://github.com/mastra-ai/mastra/commit/f73c789e8ef21561580395d2c410119cab5848c8), [`8bd16da`](https://github.com/mastra-ai/mastra/commit/8bd16da73a4cb874d739373643dbd6a6e7f88684), [`c8630f8`](https://github.com/mastra-ai/mastra/commit/c8630f80d4f40cb5d22e60ab162b618b1907167a), [`47f71dc`](https://github.com/mastra-ai/mastra/commit/47f71dc6fbcbd12d71e21a979e676e20a02bd77d), [`50ceae2`](https://github.com/mastra-ai/mastra/commit/50ceae270878e2f8fb2b2c6c2faab09df0007c8a), [`8cdde58`](https://github.com/mastra-ai/mastra/commit/8cdde5875bbba6702d9df226f2b20232b8d75d6c), [`847ff1e`](https://github.com/mastra-ai/mastra/commit/847ff1e0d94368d94b2e173e4e0908e115568ef3), [`259d409`](https://github.com/mastra-ai/mastra/commit/259d409a514174299dbde1ff5e1121209b3ba850), [`9e16c68`](https://github.com/mastra-ai/mastra/commit/9e16c6818b6485ccb43df28aba6f3a2219d28662), [`cefca33`](https://github.com/mastra-ai/mastra/commit/cefca33ae666e69810c935fedf95a929c173d1d7), [`d00e8c5`](https://github.com/mastra-ai/mastra/commit/d00e8c50daebe5bce5bf2f48bde39c86fc3d2fe4), [`36fa7e2`](https://github.com/mastra-ai/mastra/commit/36fa7e24d14e58a1eb46147097b32f583e5b8775), [`87e9774`](https://github.com/mastra-ai/mastra/commit/87e97741c1e493cd6d62f478eb810b49bda4d57c), [`65a72e7`](https://github.com/mastra-ai/mastra/commit/65a72e70c25eedea8ff985a6624b96be2850236b), [`0f77241`](https://github.com/mastra-ai/mastra/commit/0f7724108806703799a8ba80ad0f09414afd5066), [`92ff509`](https://github.com/mastra-ai/mastra/commit/92ff5098ef8a990438ca038077021a5f7541ec1d), [`3fce5e7`](https://github.com/mastra-ai/mastra/commit/3fce5e70d011d289043e75003ef3336ed4aa43c3), [`a763592`](https://github.com/mastra-ai/mastra/commit/a763592c3db46963ef1011cfe16fe372816e775e), [`80c7737`](https://github.com/mastra-ai/mastra/commit/80c7737e32d7917b5f356957d67c169d01744fd3), [`3f1cf47`](https://github.com/mastra-ai/mastra/commit/3f1cf476f74c1e4cc2df908837e05853a5347e31)]:
|
|
25
|
+
- @mastra/core@1.38.0-alpha.3
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Portions of this software are licensed as follows:
|
|
2
|
+
|
|
3
|
+
- All content that resides under any directory named "ee/" within this
|
|
4
|
+
repository, including but not limited to:
|
|
5
|
+
- `packages/core/src/auth/ee/`
|
|
6
|
+
- `packages/server/src/server/auth/ee/`
|
|
7
|
+
is licensed under the license defined in `ee/LICENSE`.
|
|
8
|
+
|
|
9
|
+
- All third-party components incorporated into the Mastra Software are
|
|
10
|
+
licensed under the original license provided by the owner of the
|
|
11
|
+
applicable component.
|
|
12
|
+
|
|
13
|
+
- Content outside of the above-mentioned directories or restrictions is
|
|
14
|
+
available under the "Apache License 2.0" as defined below.
|
|
15
|
+
|
|
16
|
+
# Apache License 2.0
|
|
17
|
+
|
|
18
|
+
Copyright (c) 2025 Kepler Software, Inc.
|
|
19
|
+
|
|
20
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
21
|
+
you may not use this file except in compliance with the License.
|
|
22
|
+
You may obtain a copy of the License at
|
|
23
|
+
|
|
24
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
25
|
+
|
|
26
|
+
Unless required by applicable law or agreed to in writing, software
|
|
27
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
28
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
29
|
+
See the License for the specific language governing permissions and
|
|
30
|
+
limitations under the License.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var crypto = require('crypto');
|
|
4
|
+
var clientBedrockAgentcore = require('@aws-sdk/client-bedrock-agentcore');
|
|
5
|
+
var workspace = require('@mastra/core/workspace');
|
|
6
|
+
|
|
7
|
+
// src/sandbox/index.ts
|
|
8
|
+
var LOG_PREFIX = "[AgentCoreRuntimeSandbox]";
|
|
9
|
+
var DEFAULT_COMMAND_TIMEOUT_MS = 3e5;
|
|
10
|
+
var MAX_AGENTCORE_TIMEOUT_SECONDS = 3600;
|
|
11
|
+
var DEFAULT_ACCEPT = "application/vnd.amazon.eventstream";
|
|
12
|
+
var DEFAULT_CONTENT_TYPE = "application/json";
|
|
13
|
+
var CommandOutputAccumulator = class extends workspace.ProcessHandle {
|
|
14
|
+
pid = "agentcore-command";
|
|
15
|
+
exitCode;
|
|
16
|
+
async kill() {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
async sendStdin() {
|
|
20
|
+
throw new Error("AgentCore Runtime command execution does not support stdin");
|
|
21
|
+
}
|
|
22
|
+
async wait() {
|
|
23
|
+
return {
|
|
24
|
+
success: this.exitCode === 0,
|
|
25
|
+
exitCode: this.exitCode ?? 1,
|
|
26
|
+
stdout: this.stdout,
|
|
27
|
+
stderr: this.stderr,
|
|
28
|
+
executionTimeMs: 0
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
function shellQuote(arg) {
|
|
33
|
+
if (/^[a-zA-Z0-9._\-\/=:@]+$/.test(arg)) return arg;
|
|
34
|
+
return `'${arg.replace(/'/g, "'\\''")}'`;
|
|
35
|
+
}
|
|
36
|
+
function safeEnvName(name) {
|
|
37
|
+
return /^[A-Za-z_][A-Za-z0-9_]*$/.test(name);
|
|
38
|
+
}
|
|
39
|
+
function buildCommand(command, args, options) {
|
|
40
|
+
const baseCommand = args?.length ? `${command} ${args.map((arg) => shellQuote(arg)).join(" ")}` : command;
|
|
41
|
+
const parts = [];
|
|
42
|
+
if (options?.cwd) {
|
|
43
|
+
parts.push(`cd ${shellQuote(options.cwd)}`);
|
|
44
|
+
}
|
|
45
|
+
const env = options?.env ?? {};
|
|
46
|
+
const envAssignments = Object.entries(env).filter((entry) => entry[1] !== void 0).map(([key, value]) => {
|
|
47
|
+
if (!safeEnvName(key)) {
|
|
48
|
+
throw new Error(`Invalid environment variable name for AgentCore Runtime command: ${key}`);
|
|
49
|
+
}
|
|
50
|
+
return `${key}=${shellQuote(value)}`;
|
|
51
|
+
});
|
|
52
|
+
parts.push(`${envAssignments.length ? `${envAssignments.join(" ")} ` : ""}${baseCommand}`);
|
|
53
|
+
return parts.join(" && ");
|
|
54
|
+
}
|
|
55
|
+
function toAgentCoreTimeoutSeconds(timeoutMs) {
|
|
56
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
57
|
+
throw new RangeError("AgentCore Runtime command timeout must be a positive number of milliseconds");
|
|
58
|
+
}
|
|
59
|
+
const timeoutSeconds = Math.ceil(timeoutMs / 1e3);
|
|
60
|
+
if (timeoutSeconds > MAX_AGENTCORE_TIMEOUT_SECONDS) {
|
|
61
|
+
throw new RangeError(`AgentCore Runtime command timeout must be at most ${MAX_AGENTCORE_TIMEOUT_SECONDS} seconds`);
|
|
62
|
+
}
|
|
63
|
+
return timeoutSeconds;
|
|
64
|
+
}
|
|
65
|
+
function generateSessionId() {
|
|
66
|
+
return crypto.randomUUID();
|
|
67
|
+
}
|
|
68
|
+
function getStreamException(event) {
|
|
69
|
+
const exceptionKeys = [
|
|
70
|
+
"accessDeniedException",
|
|
71
|
+
"internalServerException",
|
|
72
|
+
"resourceNotFoundException",
|
|
73
|
+
"serviceQuotaExceededException",
|
|
74
|
+
"throttlingException",
|
|
75
|
+
"validationException",
|
|
76
|
+
"runtimeClientError"
|
|
77
|
+
];
|
|
78
|
+
for (const key of exceptionKeys) {
|
|
79
|
+
const value = event[key];
|
|
80
|
+
if (value) return { key, value };
|
|
81
|
+
}
|
|
82
|
+
if (event.$unknown) {
|
|
83
|
+
return { key: event.$unknown[0], value: event.$unknown[1] };
|
|
84
|
+
}
|
|
85
|
+
return void 0;
|
|
86
|
+
}
|
|
87
|
+
function formatStreamException(key, value) {
|
|
88
|
+
if (value && typeof value === "object") {
|
|
89
|
+
const exception = value;
|
|
90
|
+
const name = exception.name ?? key;
|
|
91
|
+
return exception.message ? `${name}: ${exception.message}` : name;
|
|
92
|
+
}
|
|
93
|
+
return `${key}: ${String(value)}`;
|
|
94
|
+
}
|
|
95
|
+
var AgentCoreRuntimeSandbox = class extends workspace.MastraSandbox {
|
|
96
|
+
id;
|
|
97
|
+
name = "AgentCoreRuntimeSandbox";
|
|
98
|
+
provider = "agentcore";
|
|
99
|
+
status = "pending";
|
|
100
|
+
_client;
|
|
101
|
+
_ownsClient;
|
|
102
|
+
_region;
|
|
103
|
+
_agentRuntimeArn;
|
|
104
|
+
_runtimeSessionId;
|
|
105
|
+
_qualifier;
|
|
106
|
+
_contentType;
|
|
107
|
+
_accept;
|
|
108
|
+
_commandTimeout;
|
|
109
|
+
_stopSessionOnLifecycle;
|
|
110
|
+
_stopClientToken;
|
|
111
|
+
_instructionsOverride;
|
|
112
|
+
_createdAt = /* @__PURE__ */ new Date();
|
|
113
|
+
_lastUsedAt;
|
|
114
|
+
constructor(options) {
|
|
115
|
+
super({ ...options, name: "AgentCoreRuntimeSandbox" });
|
|
116
|
+
if (!options.agentRuntimeArn) {
|
|
117
|
+
throw new Error(`${LOG_PREFIX} agentRuntimeArn is required`);
|
|
118
|
+
}
|
|
119
|
+
this.id = options.runtimeSessionId ?? generateSessionId();
|
|
120
|
+
this._agentRuntimeArn = options.agentRuntimeArn;
|
|
121
|
+
this._runtimeSessionId = this.id;
|
|
122
|
+
this._qualifier = options.qualifier;
|
|
123
|
+
this._contentType = options.contentType ?? DEFAULT_CONTENT_TYPE;
|
|
124
|
+
this._accept = options.accept ?? DEFAULT_ACCEPT;
|
|
125
|
+
this._commandTimeout = options.commandTimeout ?? DEFAULT_COMMAND_TIMEOUT_MS;
|
|
126
|
+
this._stopSessionOnLifecycle = options.stopSessionOnLifecycle ?? false;
|
|
127
|
+
this._stopClientToken = options.stopClientToken;
|
|
128
|
+
this._instructionsOverride = options.instructions;
|
|
129
|
+
this._client = options.client;
|
|
130
|
+
this._ownsClient = !options.client;
|
|
131
|
+
this._region = options.region;
|
|
132
|
+
}
|
|
133
|
+
get runtimeSessionId() {
|
|
134
|
+
return this._runtimeSessionId;
|
|
135
|
+
}
|
|
136
|
+
get agentRuntimeArn() {
|
|
137
|
+
return this._agentRuntimeArn;
|
|
138
|
+
}
|
|
139
|
+
async start() {
|
|
140
|
+
this.logger.debug(`${LOG_PREFIX} Using AgentCore Runtime session ${this._runtimeSessionId}`);
|
|
141
|
+
}
|
|
142
|
+
async stop() {
|
|
143
|
+
if (!this._stopSessionOnLifecycle) return;
|
|
144
|
+
await this.stopRuntimeSession();
|
|
145
|
+
}
|
|
146
|
+
async destroy() {
|
|
147
|
+
if (this._stopSessionOnLifecycle) {
|
|
148
|
+
await this.stopRuntimeSession();
|
|
149
|
+
}
|
|
150
|
+
if (this._ownsClient && this._client) {
|
|
151
|
+
this._client.destroy();
|
|
152
|
+
this._client = void 0;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Explicitly stops the AgentCore Runtime session used by this sandbox.
|
|
157
|
+
*
|
|
158
|
+
* This is separate from destroy() because AgentCore Runtime sessions can be
|
|
159
|
+
* shared with agent invocations outside the WorkspaceSandbox lifecycle.
|
|
160
|
+
*/
|
|
161
|
+
async stopRuntimeSession() {
|
|
162
|
+
await this._getClient().send(
|
|
163
|
+
new clientBedrockAgentcore.StopRuntimeSessionCommand({
|
|
164
|
+
agentRuntimeArn: this._agentRuntimeArn,
|
|
165
|
+
runtimeSessionId: this._runtimeSessionId,
|
|
166
|
+
qualifier: this._qualifier,
|
|
167
|
+
clientToken: this._stopClientToken ?? generateSessionId()
|
|
168
|
+
})
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
async executeCommand(command, args, options) {
|
|
172
|
+
await this.ensureRunning();
|
|
173
|
+
const fullCommand = buildCommand(command, args, options);
|
|
174
|
+
const timeoutMs = options?.timeout ?? this._commandTimeout;
|
|
175
|
+
const timeoutSeconds = toAgentCoreTimeoutSeconds(timeoutMs);
|
|
176
|
+
const startTime = Date.now();
|
|
177
|
+
const output = new CommandOutputAccumulator({
|
|
178
|
+
maxRetainedBytes: options?.maxRetainedBytes ?? Infinity,
|
|
179
|
+
onStdout: options?.onStdout,
|
|
180
|
+
onStderr: options?.onStderr
|
|
181
|
+
});
|
|
182
|
+
let stopStatus;
|
|
183
|
+
this.logger.debug(`${LOG_PREFIX} Executing command`, {
|
|
184
|
+
runtimeSessionId: this._runtimeSessionId,
|
|
185
|
+
command: fullCommand,
|
|
186
|
+
timeoutSeconds
|
|
187
|
+
});
|
|
188
|
+
const response = await this._getClient().send(
|
|
189
|
+
new clientBedrockAgentcore.InvokeAgentRuntimeCommandCommand({
|
|
190
|
+
agentRuntimeArn: this._agentRuntimeArn,
|
|
191
|
+
runtimeSessionId: this._runtimeSessionId,
|
|
192
|
+
qualifier: this._qualifier,
|
|
193
|
+
contentType: this._contentType,
|
|
194
|
+
accept: this._accept,
|
|
195
|
+
body: {
|
|
196
|
+
command: fullCommand,
|
|
197
|
+
timeout: timeoutSeconds
|
|
198
|
+
}
|
|
199
|
+
}),
|
|
200
|
+
{ abortSignal: options?.abortSignal }
|
|
201
|
+
);
|
|
202
|
+
for await (const event of response.stream ?? []) {
|
|
203
|
+
const streamEvent = event;
|
|
204
|
+
const streamException = getStreamException(streamEvent);
|
|
205
|
+
if (streamException) {
|
|
206
|
+
throw new Error(`${LOG_PREFIX} ${formatStreamException(streamException.key, streamException.value)}`);
|
|
207
|
+
}
|
|
208
|
+
const chunk = streamEvent.chunk;
|
|
209
|
+
if (!chunk) continue;
|
|
210
|
+
if (chunk.contentDelta?.stdout) {
|
|
211
|
+
output.emitStdout(chunk.contentDelta.stdout);
|
|
212
|
+
}
|
|
213
|
+
if (chunk.contentDelta?.stderr) {
|
|
214
|
+
output.emitStderr(chunk.contentDelta.stderr);
|
|
215
|
+
}
|
|
216
|
+
if (chunk.contentStop) {
|
|
217
|
+
output.exitCode = chunk.contentStop.exitCode ?? 1;
|
|
218
|
+
stopStatus = chunk.contentStop.status;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
const executionTimeMs = Date.now() - startTime;
|
|
222
|
+
const exitCode = output.exitCode ?? 1;
|
|
223
|
+
const timedOut = stopStatus === "TIMED_OUT";
|
|
224
|
+
const finalExitCode = timedOut ? 124 : exitCode;
|
|
225
|
+
this._lastUsedAt = /* @__PURE__ */ new Date();
|
|
226
|
+
return {
|
|
227
|
+
command: fullCommand,
|
|
228
|
+
args,
|
|
229
|
+
success: finalExitCode === 0 && !timedOut,
|
|
230
|
+
exitCode: finalExitCode,
|
|
231
|
+
stdout: output.stdout,
|
|
232
|
+
stderr: output.stderr,
|
|
233
|
+
executionTimeMs,
|
|
234
|
+
timedOut,
|
|
235
|
+
stdoutTruncated: output.stdoutTruncated,
|
|
236
|
+
stderrTruncated: output.stderrTruncated,
|
|
237
|
+
stdoutDroppedBytes: output.stdoutDroppedBytes,
|
|
238
|
+
stderrDroppedBytes: output.stderrDroppedBytes
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
getInstructions(opts) {
|
|
242
|
+
const defaultInstructions = this._getDefaultInstructions();
|
|
243
|
+
if (this._instructionsOverride === void 0) return defaultInstructions;
|
|
244
|
+
if (typeof this._instructionsOverride === "string") return this._instructionsOverride;
|
|
245
|
+
return this._instructionsOverride({ defaultInstructions, requestContext: opts?.requestContext });
|
|
246
|
+
}
|
|
247
|
+
async getInfo() {
|
|
248
|
+
return {
|
|
249
|
+
id: this.id,
|
|
250
|
+
name: this.name,
|
|
251
|
+
provider: this.provider,
|
|
252
|
+
status: this.status,
|
|
253
|
+
createdAt: this._createdAt,
|
|
254
|
+
lastUsedAt: this._lastUsedAt,
|
|
255
|
+
metadata: {
|
|
256
|
+
agentRuntimeArn: this._agentRuntimeArn,
|
|
257
|
+
runtimeSessionId: this._runtimeSessionId,
|
|
258
|
+
qualifier: this._qualifier ?? "DEFAULT",
|
|
259
|
+
stopSessionOnLifecycle: this._stopSessionOnLifecycle
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
_getDefaultInstructions() {
|
|
264
|
+
return [
|
|
265
|
+
"AWS Bedrock AgentCore Runtime sandbox.",
|
|
266
|
+
"Commands run inside the configured AgentCore Runtime session container.",
|
|
267
|
+
"Command output streams from AgentCore Runtime as stdout and stderr.",
|
|
268
|
+
"Limitations:",
|
|
269
|
+
"- Commands are one-shot and non-interactive.",
|
|
270
|
+
"- There is no persistent shell session between commands.",
|
|
271
|
+
"- Background process management is not exposed by this provider.",
|
|
272
|
+
"- Filesystem mounts are not exposed by this provider.",
|
|
273
|
+
"- Developer tools such as git, npm, Python, or Node must exist in the AgentCore container image.",
|
|
274
|
+
"- AgentCore Code Interpreter is a separate service and is not part of this runtime sandbox."
|
|
275
|
+
].join("\n");
|
|
276
|
+
}
|
|
277
|
+
_getClient() {
|
|
278
|
+
if (!this._client) {
|
|
279
|
+
this._client = new clientBedrockAgentcore.BedrockAgentCoreClient({ region: this._region });
|
|
280
|
+
}
|
|
281
|
+
return this._client;
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
// src/provider.ts
|
|
286
|
+
var agentCoreRuntimeSandboxProvider = {
|
|
287
|
+
id: "agentcore",
|
|
288
|
+
name: "AgentCore Runtime Sandbox",
|
|
289
|
+
description: "AWS Bedrock AgentCore Runtime command execution sandbox",
|
|
290
|
+
configSchema: {
|
|
291
|
+
type: "object",
|
|
292
|
+
required: ["agentRuntimeArn"],
|
|
293
|
+
properties: {
|
|
294
|
+
region: {
|
|
295
|
+
type: "string",
|
|
296
|
+
description: "AWS region for Bedrock AgentCore"
|
|
297
|
+
},
|
|
298
|
+
agentRuntimeArn: {
|
|
299
|
+
type: "string",
|
|
300
|
+
description: "AgentCore Runtime ARN"
|
|
301
|
+
},
|
|
302
|
+
runtimeSessionId: {
|
|
303
|
+
type: "string",
|
|
304
|
+
description: "Runtime session ID. Defaults to a generated UUID."
|
|
305
|
+
},
|
|
306
|
+
qualifier: {
|
|
307
|
+
type: "string",
|
|
308
|
+
description: "Agent runtime qualifier/endpoint",
|
|
309
|
+
default: "DEFAULT"
|
|
310
|
+
},
|
|
311
|
+
commandTimeout: {
|
|
312
|
+
type: "number",
|
|
313
|
+
description: "Default command timeout in milliseconds. Must be between 1 and 3,600,000.",
|
|
314
|
+
default: 3e5,
|
|
315
|
+
minimum: 1,
|
|
316
|
+
maximum: 36e5
|
|
317
|
+
},
|
|
318
|
+
stopSessionOnLifecycle: {
|
|
319
|
+
type: "boolean",
|
|
320
|
+
description: "Stop the AgentCore Runtime session during stop()/destroy()",
|
|
321
|
+
default: false
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
createSandbox: (config) => new AgentCoreRuntimeSandbox(config)
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
exports.AgentCoreRuntimeSandbox = AgentCoreRuntimeSandbox;
|
|
329
|
+
exports.agentCoreRuntimeSandboxProvider = agentCoreRuntimeSandboxProvider;
|
|
330
|
+
//# sourceMappingURL=index.cjs.map
|
|
331
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/sandbox/index.ts","../src/provider.ts"],"names":["ProcessHandle","randomUUID","MastraSandbox","StopRuntimeSessionCommand","InvokeAgentRuntimeCommandCommand","BedrockAgentCoreClient"],"mappings":";;;;;;;AA2BA,IAAM,UAAA,GAAa,2BAAA;AACnB,IAAM,0BAAA,GAA6B,GAAA;AACnC,IAAM,6BAAA,GAAgC,IAAA;AACtC,IAAM,cAAA,GAAiB,oCAAA;AACvB,IAAM,oBAAA,GAAuB,kBAAA;AA+B7B,IAAM,wBAAA,GAAN,cAAuCA,uBAAA,CAAc;AAAA,EAC1C,GAAA,GAAM,mBAAA;AAAA,EACf,QAAA;AAAA,EAEA,MAAM,IAAA,GAAyB;AAC7B,IAAA,OAAO,KAAA;AAAA,EACT;AAAA,EAEA,MAAM,SAAA,GAA2B;AAC/B,IAAA,MAAM,IAAI,MAAM,4DAA4D,CAAA;AAAA,EAC9E;AAAA,EAEA,MAAM,IAAA,GAA+B;AACnC,IAAA,OAAO;AAAA,MACL,OAAA,EAAS,KAAK,QAAA,KAAa,CAAA;AAAA,MAC3B,QAAA,EAAU,KAAK,QAAA,IAAY,CAAA;AAAA,MAC3B,QAAQ,IAAA,CAAK,MAAA;AAAA,MACb,QAAQ,IAAA,CAAK,MAAA;AAAA,MACb,eAAA,EAAiB;AAAA,KACnB;AAAA,EACF;AACF,CAAA;AAEA,SAAS,WAAW,GAAA,EAAqB;AACvC,EAAA,IAAI,yBAAA,CAA0B,IAAA,CAAK,GAAG,CAAA,EAAG,OAAO,GAAA;AAChD,EAAA,OAAO,CAAA,CAAA,EAAI,GAAA,CAAI,OAAA,CAAQ,IAAA,EAAM,OAAO,CAAC,CAAA,C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M,QAAA;AAAA,QACN,WAAA,EAAa;AAAA,OACf;AAAA,MACA,gBAAA,EAAkB;AAAA,QAChB,IAAA,EAAM,QAAA;AAAA,QACN,WAAA,EAAa;AAAA,OACf;AAAA,MACA,SAAA,EAAW;AAAA,QACT,IAAA,EAAM,QAAA;AAAA,QACN,WAAA,EAAa,kCAAA;AAAA,QACb,OAAA,EAAS;AAAA,OACX;AAAA,MACA,cAAA,EAAgB;AAAA,QACd,IAAA,EAAM,QAAA;AAAA,QACN,WAAA,EAAa,2EAAA;AAAA,QACb,OAAA,EAAS,GAAA;AAAA,QACT,OAAA,EAAS,CAAA;AAAA,QACT,OAAA,EAAS;AAAA,OACX;AAAA,MACA,sBAAA,EAAwB;AAAA,QACtB,IAAA,EAAM,SAAA;AAAA,QACN,WAAA,EAAa,4DAAA;AAAA,QACb,OAAA,EAAS;AAAA;AACX;AACF,GACF;AAAA,EACA,aAAA,EAAe,CAAA,MAAA,KAAU,IAAI,uBAAA,CAAwB,MAAM;AAC7D","file":"index.cjs","sourcesContent":["/**\n * AWS Bedrock AgentCore Runtime sandbox provider.\n *\n * This provider maps Mastra's one-shot command execution contract to\n * InvokeAgentRuntimeCommand. It intentionally does not expose process\n * management or filesystem mounts because AgentCore Runtime command execution\n * does not provide those WorkspaceSandbox semantics.\n *\n * @see https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime-execute-command.html\n */\n\nimport { randomUUID } from 'node:crypto';\nimport {\n BedrockAgentCoreClient,\n InvokeAgentRuntimeCommandCommand,\n StopRuntimeSessionCommand,\n} from '@aws-sdk/client-bedrock-agentcore';\nimport type { RequestContext } from '@mastra/core/di';\nimport type {\n CommandResult,\n ExecuteCommandOptions,\n MastraSandboxOptions,\n ProviderStatus,\n SandboxInfo,\n} from '@mastra/core/workspace';\nimport { MastraSandbox, ProcessHandle } from '@mastra/core/workspace';\n\nconst LOG_PREFIX = '[AgentCoreRuntimeSandbox]';\nconst DEFAULT_COMMAND_TIMEOUT_MS = 300_000;\nconst MAX_AGENTCORE_TIMEOUT_SECONDS = 3600;\nconst DEFAULT_ACCEPT = 'application/vnd.amazon.eventstream';\nconst DEFAULT_CONTENT_TYPE = 'application/json';\n\ntype AgentCoreRuntimeClient = Pick<BedrockAgentCoreClient, 'send' | 'destroy'>;\ntype InstructionsOption = string | ((opts: { defaultInstructions: string; requestContext?: RequestContext }) => string);\ntype AgentCoreStreamException = {\n name?: string;\n message?: string;\n};\n\ntype AgentCoreStreamEvent = {\n chunk?: {\n contentStart?: unknown;\n contentDelta?: {\n stdout?: string;\n stderr?: string;\n };\n contentStop?: {\n exitCode?: number;\n status?: string;\n };\n };\n accessDeniedException?: AgentCoreStreamException;\n internalServerException?: AgentCoreStreamException;\n resourceNotFoundException?: AgentCoreStreamException;\n serviceQuotaExceededException?: AgentCoreStreamException;\n throttlingException?: AgentCoreStreamException;\n validationException?: AgentCoreStreamException;\n runtimeClientError?: AgentCoreStreamException;\n $unknown?: [string, unknown];\n};\n\nclass CommandOutputAccumulator extends ProcessHandle {\n readonly pid = 'agentcore-command';\n exitCode: number | undefined;\n\n async kill(): Promise<boolean> {\n return false;\n }\n\n async sendStdin(): Promise<void> {\n throw new Error('AgentCore Runtime command execution does not support stdin');\n }\n\n async wait(): Promise<CommandResult> {\n return {\n success: this.exitCode === 0,\n exitCode: this.exitCode ?? 1,\n stdout: this.stdout,\n stderr: this.stderr,\n executionTimeMs: 0,\n };\n }\n}\n\nfunction shellQuote(arg: string): string {\n if (/^[a-zA-Z0-9._\\-\\/=:@]+$/.test(arg)) return arg;\n return `'${arg.replace(/'/g, \"'\\\\''\")}'`;\n}\n\nfunction safeEnvName(name: string): boolean {\n return /^[A-Za-z_][A-Za-z0-9_]*$/.test(name);\n}\n\nfunction buildCommand(command: string, args: string[] | undefined, options: ExecuteCommandOptions | undefined): string {\n const baseCommand = args?.length ? `${command} ${args.map(arg => shellQuote(arg)).join(' ')}` : command;\n const parts: string[] = [];\n\n if (options?.cwd) {\n parts.push(`cd ${shellQuote(options.cwd)}`);\n }\n\n const env = options?.env ?? {};\n const envAssignments = Object.entries(env)\n .filter((entry): entry is [string, string] => entry[1] !== undefined)\n .map(([key, value]) => {\n if (!safeEnvName(key)) {\n throw new Error(`Invalid environment variable name for AgentCore Runtime command: ${key}`);\n }\n return `${key}=${shellQuote(value)}`;\n });\n\n parts.push(`${envAssignments.length ? `${envAssignments.join(' ')} ` : ''}${baseCommand}`);\n return parts.join(' && ');\n}\n\nfunction toAgentCoreTimeoutSeconds(timeoutMs: number): number {\n if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {\n throw new RangeError('AgentCore Runtime command timeout must be a positive number of milliseconds');\n }\n\n const timeoutSeconds = Math.ceil(timeoutMs / 1000);\n if (timeoutSeconds > MAX_AGENTCORE_TIMEOUT_SECONDS) {\n throw new RangeError(`AgentCore Runtime command timeout must be at most ${MAX_AGENTCORE_TIMEOUT_SECONDS} seconds`);\n }\n\n return timeoutSeconds;\n}\n\nfunction generateSessionId(): string {\n return randomUUID();\n}\n\nfunction getStreamException(event: AgentCoreStreamEvent): { key: string; value: unknown } | undefined {\n const exceptionKeys = [\n 'accessDeniedException',\n 'internalServerException',\n 'resourceNotFoundException',\n 'serviceQuotaExceededException',\n 'throttlingException',\n 'validationException',\n 'runtimeClientError',\n ] as const;\n\n for (const key of exceptionKeys) {\n const value = event[key];\n if (value) return { key, value };\n }\n\n if (event.$unknown) {\n return { key: event.$unknown[0], value: event.$unknown[1] };\n }\n\n return undefined;\n}\n\nfunction formatStreamException(key: string, value: unknown): string {\n if (value && typeof value === 'object') {\n const exception = value as AgentCoreStreamException;\n const name = exception.name ?? key;\n return exception.message ? `${name}: ${exception.message}` : name;\n }\n\n return `${key}: ${String(value)}`;\n}\n\n// =============================================================================\n// Options\n// =============================================================================\n\nexport interface AgentCoreRuntimeSandboxOptions extends Omit<MastraSandboxOptions, 'processes'> {\n /** AWS region for the Bedrock AgentCore client. Falls back to the AWS SDK default region chain. */\n region?: string;\n /** AgentCore Runtime ARN where commands should execute. */\n agentRuntimeArn: string;\n /** Runtime session ID. Defaults to a generated UUID, which satisfies AgentCore's 33 character minimum. */\n runtimeSessionId?: string;\n /** Agent runtime qualifier/endpoint. Defaults to AWS AgentCore's DEFAULT qualifier. */\n qualifier?: string;\n /** MIME type sent for command requests. */\n contentType?: string;\n /** Accept header for command event streams. */\n accept?: string;\n /** Default command timeout in milliseconds. */\n commandTimeout?: number;\n /**\n * Stop the AgentCore Runtime session during stop()/destroy().\n *\n * Defaults to false because sessions are often shared with agent invocations\n * outside the WorkspaceSandbox instance.\n */\n stopSessionOnLifecycle?: boolean;\n /** Client token used for StopRuntimeSession. Defaults to a generated UUID when needed. */\n stopClientToken?: string;\n /** Optional preconfigured AWS SDK client, primarily for advanced credential setup and tests. */\n client?: AgentCoreRuntimeClient;\n /** Custom instructions for getInstructions(). String replaces the default; function receives it. */\n instructions?: InstructionsOption;\n}\n\n// =============================================================================\n// Implementation\n// =============================================================================\n\nexport class AgentCoreRuntimeSandbox extends MastraSandbox {\n readonly id: string;\n readonly name = 'AgentCoreRuntimeSandbox';\n readonly provider = 'agentcore';\n status: ProviderStatus = 'pending';\n\n private _client?: AgentCoreRuntimeClient;\n private readonly _ownsClient: boolean;\n private readonly _region?: string;\n private readonly _agentRuntimeArn: string;\n private readonly _runtimeSessionId: string;\n private readonly _qualifier?: string;\n private readonly _contentType: string;\n private readonly _accept: string;\n private readonly _commandTimeout: number;\n private readonly _stopSessionOnLifecycle: boolean;\n private readonly _stopClientToken?: string;\n private readonly _instructionsOverride?: InstructionsOption;\n private readonly _createdAt = new Date();\n private _lastUsedAt?: Date;\n\n constructor(options: AgentCoreRuntimeSandboxOptions) {\n super({ ...options, name: 'AgentCoreRuntimeSandbox' });\n\n if (!options.agentRuntimeArn) {\n throw new Error(`${LOG_PREFIX} agentRuntimeArn is required`);\n }\n\n this.id = options.runtimeSessionId ?? generateSessionId();\n this._agentRuntimeArn = options.agentRuntimeArn;\n this._runtimeSessionId = this.id;\n this._qualifier = options.qualifier;\n this._contentType = options.contentType ?? DEFAULT_CONTENT_TYPE;\n this._accept = options.accept ?? DEFAULT_ACCEPT;\n this._commandTimeout = options.commandTimeout ?? DEFAULT_COMMAND_TIMEOUT_MS;\n this._stopSessionOnLifecycle = options.stopSessionOnLifecycle ?? false;\n this._stopClientToken = options.stopClientToken;\n this._instructionsOverride = options.instructions;\n this._client = options.client;\n this._ownsClient = !options.client;\n this._region = options.region;\n }\n\n get runtimeSessionId(): string {\n return this._runtimeSessionId;\n }\n\n get agentRuntimeArn(): string {\n return this._agentRuntimeArn;\n }\n\n async start(): Promise<void> {\n this.logger.debug(`${LOG_PREFIX} Using AgentCore Runtime session ${this._runtimeSessionId}`);\n }\n\n async stop(): Promise<void> {\n if (!this._stopSessionOnLifecycle) return;\n await this.stopRuntimeSession();\n }\n\n async destroy(): Promise<void> {\n if (this._stopSessionOnLifecycle) {\n await this.stopRuntimeSession();\n }\n\n if (this._ownsClient && this._client) {\n this._client.destroy();\n this._client = undefined;\n }\n }\n\n /**\n * Explicitly stops the AgentCore Runtime session used by this sandbox.\n *\n * This is separate from destroy() because AgentCore Runtime sessions can be\n * shared with agent invocations outside the WorkspaceSandbox lifecycle.\n */\n async stopRuntimeSession(): Promise<void> {\n await this._getClient().send(\n new StopRuntimeSessionCommand({\n agentRuntimeArn: this._agentRuntimeArn,\n runtimeSessionId: this._runtimeSessionId,\n qualifier: this._qualifier,\n clientToken: this._stopClientToken ?? generateSessionId(),\n }),\n );\n }\n\n async executeCommand(command: string, args?: string[], options?: ExecuteCommandOptions): Promise<CommandResult> {\n await this.ensureRunning();\n\n const fullCommand = buildCommand(command, args, options);\n const timeoutMs = options?.timeout ?? this._commandTimeout;\n const timeoutSeconds = toAgentCoreTimeoutSeconds(timeoutMs);\n const startTime = Date.now();\n const output = new CommandOutputAccumulator({\n maxRetainedBytes: options?.maxRetainedBytes ?? Infinity,\n onStdout: options?.onStdout,\n onStderr: options?.onStderr,\n });\n let stopStatus: string | undefined;\n\n this.logger.debug(`${LOG_PREFIX} Executing command`, {\n runtimeSessionId: this._runtimeSessionId,\n command: fullCommand,\n timeoutSeconds,\n });\n\n const response = await this._getClient().send(\n new InvokeAgentRuntimeCommandCommand({\n agentRuntimeArn: this._agentRuntimeArn,\n runtimeSessionId: this._runtimeSessionId,\n qualifier: this._qualifier,\n contentType: this._contentType,\n accept: this._accept,\n body: {\n command: fullCommand,\n timeout: timeoutSeconds,\n },\n }),\n { abortSignal: options?.abortSignal },\n );\n\n for await (const event of response.stream ?? []) {\n const streamEvent = event as AgentCoreStreamEvent;\n const streamException = getStreamException(streamEvent);\n if (streamException) {\n throw new Error(`${LOG_PREFIX} ${formatStreamException(streamException.key, streamException.value)}`);\n }\n\n const chunk = streamEvent.chunk;\n if (!chunk) continue;\n\n if (chunk.contentDelta?.stdout) {\n output.emitStdout(chunk.contentDelta.stdout);\n }\n\n if (chunk.contentDelta?.stderr) {\n output.emitStderr(chunk.contentDelta.stderr);\n }\n\n if (chunk.contentStop) {\n output.exitCode = chunk.contentStop.exitCode ?? 1;\n stopStatus = chunk.contentStop.status;\n }\n }\n\n const executionTimeMs = Date.now() - startTime;\n const exitCode = output.exitCode ?? 1;\n const timedOut = stopStatus === 'TIMED_OUT';\n const finalExitCode = timedOut ? 124 : exitCode;\n this._lastUsedAt = new Date();\n\n return {\n command: fullCommand,\n args,\n success: finalExitCode === 0 && !timedOut,\n exitCode: finalExitCode,\n stdout: output.stdout,\n stderr: output.stderr,\n executionTimeMs,\n timedOut,\n stdoutTruncated: output.stdoutTruncated,\n stderrTruncated: output.stderrTruncated,\n stdoutDroppedBytes: output.stdoutDroppedBytes,\n stderrDroppedBytes: output.stderrDroppedBytes,\n };\n }\n\n getInstructions(opts?: { requestContext?: RequestContext }): string {\n const defaultInstructions = this._getDefaultInstructions();\n if (this._instructionsOverride === undefined) return defaultInstructions;\n if (typeof this._instructionsOverride === 'string') return this._instructionsOverride;\n return this._instructionsOverride({ defaultInstructions, requestContext: opts?.requestContext });\n }\n\n async getInfo(): Promise<SandboxInfo> {\n return {\n id: this.id,\n name: this.name,\n provider: this.provider,\n status: this.status,\n createdAt: this._createdAt,\n lastUsedAt: this._lastUsedAt,\n metadata: {\n agentRuntimeArn: this._agentRuntimeArn,\n runtimeSessionId: this._runtimeSessionId,\n qualifier: this._qualifier ?? 'DEFAULT',\n stopSessionOnLifecycle: this._stopSessionOnLifecycle,\n },\n };\n }\n\n private _getDefaultInstructions(): string {\n return [\n 'AWS Bedrock AgentCore Runtime sandbox.',\n 'Commands run inside the configured AgentCore Runtime session container.',\n 'Command output streams from AgentCore Runtime as stdout and stderr.',\n 'Limitations:',\n '- Commands are one-shot and non-interactive.',\n '- There is no persistent shell session between commands.',\n '- Background process management is not exposed by this provider.',\n '- Filesystem mounts are not exposed by this provider.',\n '- Developer tools such as git, npm, Python, or Node must exist in the AgentCore container image.',\n '- AgentCore Code Interpreter is a separate service and is not part of this runtime sandbox.',\n ].join('\\n');\n }\n\n private _getClient(): AgentCoreRuntimeClient {\n if (!this._client) {\n this._client = new BedrockAgentCoreClient({ region: this._region });\n }\n return this._client;\n }\n}\n","/**\n * AWS Bedrock AgentCore Runtime sandbox provider descriptor.\n *\n * Enables registration with MastraEditor for UI-driven sandbox configuration.\n */\n\nimport type { SandboxProvider } from '@mastra/core/editor';\nimport { AgentCoreRuntimeSandbox } from './sandbox';\n\nexport interface AgentCoreRuntimeProviderConfig {\n /** AWS region for the Bedrock AgentCore client */\n region?: string;\n /** AgentCore Runtime ARN where commands should execute */\n agentRuntimeArn: string;\n /** Runtime session ID */\n runtimeSessionId?: string;\n /** Agent runtime qualifier/endpoint */\n qualifier?: string;\n /** Default command timeout in milliseconds */\n commandTimeout?: number;\n /** Stop the runtime session during stop()/destroy() */\n stopSessionOnLifecycle?: boolean;\n}\n\nexport const agentCoreRuntimeSandboxProvider: SandboxProvider<AgentCoreRuntimeProviderConfig> = {\n id: 'agentcore',\n name: 'AgentCore Runtime Sandbox',\n description: 'AWS Bedrock AgentCore Runtime command execution sandbox',\n configSchema: {\n type: 'object',\n required: ['agentRuntimeArn'],\n properties: {\n region: {\n type: 'string',\n description: 'AWS region for Bedrock AgentCore',\n },\n agentRuntimeArn: {\n type: 'string',\n description: 'AgentCore Runtime ARN',\n },\n runtimeSessionId: {\n type: 'string',\n description: 'Runtime session ID. Defaults to a generated UUID.',\n },\n qualifier: {\n type: 'string',\n description: 'Agent runtime qualifier/endpoint',\n default: 'DEFAULT',\n },\n commandTimeout: {\n type: 'number',\n description: 'Default command timeout in milliseconds. Must be between 1 and 3,600,000.',\n default: 300_000,\n minimum: 1,\n maximum: 3_600_000,\n },\n stopSessionOnLifecycle: {\n type: 'boolean',\n description: 'Stop the AgentCore Runtime session during stop()/destroy()',\n default: false,\n },\n },\n },\n createSandbox: config => new AgentCoreRuntimeSandbox(config),\n};\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,KAAK,8BAA8B,EAAE,MAAM,WAAW,CAAC;AACzF,OAAO,EAAE,+BAA+B,EAAE,KAAK,8BAA8B,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import { randomUUID } from 'crypto';
|
|
2
|
+
import { StopRuntimeSessionCommand, InvokeAgentRuntimeCommandCommand, BedrockAgentCoreClient } from '@aws-sdk/client-bedrock-agentcore';
|
|
3
|
+
import { MastraSandbox, ProcessHandle } from '@mastra/core/workspace';
|
|
4
|
+
|
|
5
|
+
// src/sandbox/index.ts
|
|
6
|
+
var LOG_PREFIX = "[AgentCoreRuntimeSandbox]";
|
|
7
|
+
var DEFAULT_COMMAND_TIMEOUT_MS = 3e5;
|
|
8
|
+
var MAX_AGENTCORE_TIMEOUT_SECONDS = 3600;
|
|
9
|
+
var DEFAULT_ACCEPT = "application/vnd.amazon.eventstream";
|
|
10
|
+
var DEFAULT_CONTENT_TYPE = "application/json";
|
|
11
|
+
var CommandOutputAccumulator = class extends ProcessHandle {
|
|
12
|
+
pid = "agentcore-command";
|
|
13
|
+
exitCode;
|
|
14
|
+
async kill() {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
async sendStdin() {
|
|
18
|
+
throw new Error("AgentCore Runtime command execution does not support stdin");
|
|
19
|
+
}
|
|
20
|
+
async wait() {
|
|
21
|
+
return {
|
|
22
|
+
success: this.exitCode === 0,
|
|
23
|
+
exitCode: this.exitCode ?? 1,
|
|
24
|
+
stdout: this.stdout,
|
|
25
|
+
stderr: this.stderr,
|
|
26
|
+
executionTimeMs: 0
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
function shellQuote(arg) {
|
|
31
|
+
if (/^[a-zA-Z0-9._\-\/=:@]+$/.test(arg)) return arg;
|
|
32
|
+
return `'${arg.replace(/'/g, "'\\''")}'`;
|
|
33
|
+
}
|
|
34
|
+
function safeEnvName(name) {
|
|
35
|
+
return /^[A-Za-z_][A-Za-z0-9_]*$/.test(name);
|
|
36
|
+
}
|
|
37
|
+
function buildCommand(command, args, options) {
|
|
38
|
+
const baseCommand = args?.length ? `${command} ${args.map((arg) => shellQuote(arg)).join(" ")}` : command;
|
|
39
|
+
const parts = [];
|
|
40
|
+
if (options?.cwd) {
|
|
41
|
+
parts.push(`cd ${shellQuote(options.cwd)}`);
|
|
42
|
+
}
|
|
43
|
+
const env = options?.env ?? {};
|
|
44
|
+
const envAssignments = Object.entries(env).filter((entry) => entry[1] !== void 0).map(([key, value]) => {
|
|
45
|
+
if (!safeEnvName(key)) {
|
|
46
|
+
throw new Error(`Invalid environment variable name for AgentCore Runtime command: ${key}`);
|
|
47
|
+
}
|
|
48
|
+
return `${key}=${shellQuote(value)}`;
|
|
49
|
+
});
|
|
50
|
+
parts.push(`${envAssignments.length ? `${envAssignments.join(" ")} ` : ""}${baseCommand}`);
|
|
51
|
+
return parts.join(" && ");
|
|
52
|
+
}
|
|
53
|
+
function toAgentCoreTimeoutSeconds(timeoutMs) {
|
|
54
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
55
|
+
throw new RangeError("AgentCore Runtime command timeout must be a positive number of milliseconds");
|
|
56
|
+
}
|
|
57
|
+
const timeoutSeconds = Math.ceil(timeoutMs / 1e3);
|
|
58
|
+
if (timeoutSeconds > MAX_AGENTCORE_TIMEOUT_SECONDS) {
|
|
59
|
+
throw new RangeError(`AgentCore Runtime command timeout must be at most ${MAX_AGENTCORE_TIMEOUT_SECONDS} seconds`);
|
|
60
|
+
}
|
|
61
|
+
return timeoutSeconds;
|
|
62
|
+
}
|
|
63
|
+
function generateSessionId() {
|
|
64
|
+
return randomUUID();
|
|
65
|
+
}
|
|
66
|
+
function getStreamException(event) {
|
|
67
|
+
const exceptionKeys = [
|
|
68
|
+
"accessDeniedException",
|
|
69
|
+
"internalServerException",
|
|
70
|
+
"resourceNotFoundException",
|
|
71
|
+
"serviceQuotaExceededException",
|
|
72
|
+
"throttlingException",
|
|
73
|
+
"validationException",
|
|
74
|
+
"runtimeClientError"
|
|
75
|
+
];
|
|
76
|
+
for (const key of exceptionKeys) {
|
|
77
|
+
const value = event[key];
|
|
78
|
+
if (value) return { key, value };
|
|
79
|
+
}
|
|
80
|
+
if (event.$unknown) {
|
|
81
|
+
return { key: event.$unknown[0], value: event.$unknown[1] };
|
|
82
|
+
}
|
|
83
|
+
return void 0;
|
|
84
|
+
}
|
|
85
|
+
function formatStreamException(key, value) {
|
|
86
|
+
if (value && typeof value === "object") {
|
|
87
|
+
const exception = value;
|
|
88
|
+
const name = exception.name ?? key;
|
|
89
|
+
return exception.message ? `${name}: ${exception.message}` : name;
|
|
90
|
+
}
|
|
91
|
+
return `${key}: ${String(value)}`;
|
|
92
|
+
}
|
|
93
|
+
var AgentCoreRuntimeSandbox = class extends MastraSandbox {
|
|
94
|
+
id;
|
|
95
|
+
name = "AgentCoreRuntimeSandbox";
|
|
96
|
+
provider = "agentcore";
|
|
97
|
+
status = "pending";
|
|
98
|
+
_client;
|
|
99
|
+
_ownsClient;
|
|
100
|
+
_region;
|
|
101
|
+
_agentRuntimeArn;
|
|
102
|
+
_runtimeSessionId;
|
|
103
|
+
_qualifier;
|
|
104
|
+
_contentType;
|
|
105
|
+
_accept;
|
|
106
|
+
_commandTimeout;
|
|
107
|
+
_stopSessionOnLifecycle;
|
|
108
|
+
_stopClientToken;
|
|
109
|
+
_instructionsOverride;
|
|
110
|
+
_createdAt = /* @__PURE__ */ new Date();
|
|
111
|
+
_lastUsedAt;
|
|
112
|
+
constructor(options) {
|
|
113
|
+
super({ ...options, name: "AgentCoreRuntimeSandbox" });
|
|
114
|
+
if (!options.agentRuntimeArn) {
|
|
115
|
+
throw new Error(`${LOG_PREFIX} agentRuntimeArn is required`);
|
|
116
|
+
}
|
|
117
|
+
this.id = options.runtimeSessionId ?? generateSessionId();
|
|
118
|
+
this._agentRuntimeArn = options.agentRuntimeArn;
|
|
119
|
+
this._runtimeSessionId = this.id;
|
|
120
|
+
this._qualifier = options.qualifier;
|
|
121
|
+
this._contentType = options.contentType ?? DEFAULT_CONTENT_TYPE;
|
|
122
|
+
this._accept = options.accept ?? DEFAULT_ACCEPT;
|
|
123
|
+
this._commandTimeout = options.commandTimeout ?? DEFAULT_COMMAND_TIMEOUT_MS;
|
|
124
|
+
this._stopSessionOnLifecycle = options.stopSessionOnLifecycle ?? false;
|
|
125
|
+
this._stopClientToken = options.stopClientToken;
|
|
126
|
+
this._instructionsOverride = options.instructions;
|
|
127
|
+
this._client = options.client;
|
|
128
|
+
this._ownsClient = !options.client;
|
|
129
|
+
this._region = options.region;
|
|
130
|
+
}
|
|
131
|
+
get runtimeSessionId() {
|
|
132
|
+
return this._runtimeSessionId;
|
|
133
|
+
}
|
|
134
|
+
get agentRuntimeArn() {
|
|
135
|
+
return this._agentRuntimeArn;
|
|
136
|
+
}
|
|
137
|
+
async start() {
|
|
138
|
+
this.logger.debug(`${LOG_PREFIX} Using AgentCore Runtime session ${this._runtimeSessionId}`);
|
|
139
|
+
}
|
|
140
|
+
async stop() {
|
|
141
|
+
if (!this._stopSessionOnLifecycle) return;
|
|
142
|
+
await this.stopRuntimeSession();
|
|
143
|
+
}
|
|
144
|
+
async destroy() {
|
|
145
|
+
if (this._stopSessionOnLifecycle) {
|
|
146
|
+
await this.stopRuntimeSession();
|
|
147
|
+
}
|
|
148
|
+
if (this._ownsClient && this._client) {
|
|
149
|
+
this._client.destroy();
|
|
150
|
+
this._client = void 0;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Explicitly stops the AgentCore Runtime session used by this sandbox.
|
|
155
|
+
*
|
|
156
|
+
* This is separate from destroy() because AgentCore Runtime sessions can be
|
|
157
|
+
* shared with agent invocations outside the WorkspaceSandbox lifecycle.
|
|
158
|
+
*/
|
|
159
|
+
async stopRuntimeSession() {
|
|
160
|
+
await this._getClient().send(
|
|
161
|
+
new StopRuntimeSessionCommand({
|
|
162
|
+
agentRuntimeArn: this._agentRuntimeArn,
|
|
163
|
+
runtimeSessionId: this._runtimeSessionId,
|
|
164
|
+
qualifier: this._qualifier,
|
|
165
|
+
clientToken: this._stopClientToken ?? generateSessionId()
|
|
166
|
+
})
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
async executeCommand(command, args, options) {
|
|
170
|
+
await this.ensureRunning();
|
|
171
|
+
const fullCommand = buildCommand(command, args, options);
|
|
172
|
+
const timeoutMs = options?.timeout ?? this._commandTimeout;
|
|
173
|
+
const timeoutSeconds = toAgentCoreTimeoutSeconds(timeoutMs);
|
|
174
|
+
const startTime = Date.now();
|
|
175
|
+
const output = new CommandOutputAccumulator({
|
|
176
|
+
maxRetainedBytes: options?.maxRetainedBytes ?? Infinity,
|
|
177
|
+
onStdout: options?.onStdout,
|
|
178
|
+
onStderr: options?.onStderr
|
|
179
|
+
});
|
|
180
|
+
let stopStatus;
|
|
181
|
+
this.logger.debug(`${LOG_PREFIX} Executing command`, {
|
|
182
|
+
runtimeSessionId: this._runtimeSessionId,
|
|
183
|
+
command: fullCommand,
|
|
184
|
+
timeoutSeconds
|
|
185
|
+
});
|
|
186
|
+
const response = await this._getClient().send(
|
|
187
|
+
new InvokeAgentRuntimeCommandCommand({
|
|
188
|
+
agentRuntimeArn: this._agentRuntimeArn,
|
|
189
|
+
runtimeSessionId: this._runtimeSessionId,
|
|
190
|
+
qualifier: this._qualifier,
|
|
191
|
+
contentType: this._contentType,
|
|
192
|
+
accept: this._accept,
|
|
193
|
+
body: {
|
|
194
|
+
command: fullCommand,
|
|
195
|
+
timeout: timeoutSeconds
|
|
196
|
+
}
|
|
197
|
+
}),
|
|
198
|
+
{ abortSignal: options?.abortSignal }
|
|
199
|
+
);
|
|
200
|
+
for await (const event of response.stream ?? []) {
|
|
201
|
+
const streamEvent = event;
|
|
202
|
+
const streamException = getStreamException(streamEvent);
|
|
203
|
+
if (streamException) {
|
|
204
|
+
throw new Error(`${LOG_PREFIX} ${formatStreamException(streamException.key, streamException.value)}`);
|
|
205
|
+
}
|
|
206
|
+
const chunk = streamEvent.chunk;
|
|
207
|
+
if (!chunk) continue;
|
|
208
|
+
if (chunk.contentDelta?.stdout) {
|
|
209
|
+
output.emitStdout(chunk.contentDelta.stdout);
|
|
210
|
+
}
|
|
211
|
+
if (chunk.contentDelta?.stderr) {
|
|
212
|
+
output.emitStderr(chunk.contentDelta.stderr);
|
|
213
|
+
}
|
|
214
|
+
if (chunk.contentStop) {
|
|
215
|
+
output.exitCode = chunk.contentStop.exitCode ?? 1;
|
|
216
|
+
stopStatus = chunk.contentStop.status;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
const executionTimeMs = Date.now() - startTime;
|
|
220
|
+
const exitCode = output.exitCode ?? 1;
|
|
221
|
+
const timedOut = stopStatus === "TIMED_OUT";
|
|
222
|
+
const finalExitCode = timedOut ? 124 : exitCode;
|
|
223
|
+
this._lastUsedAt = /* @__PURE__ */ new Date();
|
|
224
|
+
return {
|
|
225
|
+
command: fullCommand,
|
|
226
|
+
args,
|
|
227
|
+
success: finalExitCode === 0 && !timedOut,
|
|
228
|
+
exitCode: finalExitCode,
|
|
229
|
+
stdout: output.stdout,
|
|
230
|
+
stderr: output.stderr,
|
|
231
|
+
executionTimeMs,
|
|
232
|
+
timedOut,
|
|
233
|
+
stdoutTruncated: output.stdoutTruncated,
|
|
234
|
+
stderrTruncated: output.stderrTruncated,
|
|
235
|
+
stdoutDroppedBytes: output.stdoutDroppedBytes,
|
|
236
|
+
stderrDroppedBytes: output.stderrDroppedBytes
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
getInstructions(opts) {
|
|
240
|
+
const defaultInstructions = this._getDefaultInstructions();
|
|
241
|
+
if (this._instructionsOverride === void 0) return defaultInstructions;
|
|
242
|
+
if (typeof this._instructionsOverride === "string") return this._instructionsOverride;
|
|
243
|
+
return this._instructionsOverride({ defaultInstructions, requestContext: opts?.requestContext });
|
|
244
|
+
}
|
|
245
|
+
async getInfo() {
|
|
246
|
+
return {
|
|
247
|
+
id: this.id,
|
|
248
|
+
name: this.name,
|
|
249
|
+
provider: this.provider,
|
|
250
|
+
status: this.status,
|
|
251
|
+
createdAt: this._createdAt,
|
|
252
|
+
lastUsedAt: this._lastUsedAt,
|
|
253
|
+
metadata: {
|
|
254
|
+
agentRuntimeArn: this._agentRuntimeArn,
|
|
255
|
+
runtimeSessionId: this._runtimeSessionId,
|
|
256
|
+
qualifier: this._qualifier ?? "DEFAULT",
|
|
257
|
+
stopSessionOnLifecycle: this._stopSessionOnLifecycle
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
_getDefaultInstructions() {
|
|
262
|
+
return [
|
|
263
|
+
"AWS Bedrock AgentCore Runtime sandbox.",
|
|
264
|
+
"Commands run inside the configured AgentCore Runtime session container.",
|
|
265
|
+
"Command output streams from AgentCore Runtime as stdout and stderr.",
|
|
266
|
+
"Limitations:",
|
|
267
|
+
"- Commands are one-shot and non-interactive.",
|
|
268
|
+
"- There is no persistent shell session between commands.",
|
|
269
|
+
"- Background process management is not exposed by this provider.",
|
|
270
|
+
"- Filesystem mounts are not exposed by this provider.",
|
|
271
|
+
"- Developer tools such as git, npm, Python, or Node must exist in the AgentCore container image.",
|
|
272
|
+
"- AgentCore Code Interpreter is a separate service and is not part of this runtime sandbox."
|
|
273
|
+
].join("\n");
|
|
274
|
+
}
|
|
275
|
+
_getClient() {
|
|
276
|
+
if (!this._client) {
|
|
277
|
+
this._client = new BedrockAgentCoreClient({ region: this._region });
|
|
278
|
+
}
|
|
279
|
+
return this._client;
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
// src/provider.ts
|
|
284
|
+
var agentCoreRuntimeSandboxProvider = {
|
|
285
|
+
id: "agentcore",
|
|
286
|
+
name: "AgentCore Runtime Sandbox",
|
|
287
|
+
description: "AWS Bedrock AgentCore Runtime command execution sandbox",
|
|
288
|
+
configSchema: {
|
|
289
|
+
type: "object",
|
|
290
|
+
required: ["agentRuntimeArn"],
|
|
291
|
+
properties: {
|
|
292
|
+
region: {
|
|
293
|
+
type: "string",
|
|
294
|
+
description: "AWS region for Bedrock AgentCore"
|
|
295
|
+
},
|
|
296
|
+
agentRuntimeArn: {
|
|
297
|
+
type: "string",
|
|
298
|
+
description: "AgentCore Runtime ARN"
|
|
299
|
+
},
|
|
300
|
+
runtimeSessionId: {
|
|
301
|
+
type: "string",
|
|
302
|
+
description: "Runtime session ID. Defaults to a generated UUID."
|
|
303
|
+
},
|
|
304
|
+
qualifier: {
|
|
305
|
+
type: "string",
|
|
306
|
+
description: "Agent runtime qualifier/endpoint",
|
|
307
|
+
default: "DEFAULT"
|
|
308
|
+
},
|
|
309
|
+
commandTimeout: {
|
|
310
|
+
type: "number",
|
|
311
|
+
description: "Default command timeout in milliseconds. Must be between 1 and 3,600,000.",
|
|
312
|
+
default: 3e5,
|
|
313
|
+
minimum: 1,
|
|
314
|
+
maximum: 36e5
|
|
315
|
+
},
|
|
316
|
+
stopSessionOnLifecycle: {
|
|
317
|
+
type: "boolean",
|
|
318
|
+
description: "Stop the AgentCore Runtime session during stop()/destroy()",
|
|
319
|
+
default: false
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
},
|
|
323
|
+
createSandbox: (config) => new AgentCoreRuntimeSandbox(config)
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
export { AgentCoreRuntimeSandbox, agentCoreRuntimeSandboxProvider };
|
|
327
|
+
//# sourceMappingURL=index.js.map
|
|
328
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/sandbox/index.ts","../src/provider.ts"],"names":[],"mappings":";;;;;AA2BA,IAAM,UAAA,GAAa,2BAAA;AACnB,IAAM,0BAAA,GAA6B,GAAA;AACnC,IAAM,6BAAA,GAAgC,IAAA;AACtC,IAAM,cAAA,GAAiB,oCAAA;AACvB,IAAM,oBAAA,GAAuB,kBAAA;AA+B7B,IAAM,wBAAA,GAAN,cAAuC,aAAA,CAAc;AAAA,EAC1C,GAAA,GAAM,mBAAA;AAAA,EACf,QAAA;AAAA,EAEA,MAAM,IAAA,GAAyB;AAC7B,IAAA,OAAO,KAAA;AAAA,EACT;AAAA,EAEA,MAAM,SAAA,GAA2B;AAC/B,IAAA,MAAM,IAAI,MAAM,4DAA4D,CAAA;AAAA,EAC9E;AAAA,EAEA,MAAM,IAAA,GAA+B;AACnC,IAAA,OAAO;AAAA,MACL,OAAA,EAAS,KAAK,QAAA,KAAa,CAAA;AAAA,MAC3B,QAAA,EAAU,KAAK,QAAA,IAAY,CAAA;AAAA,MAC3B,QAAQ,IAAA,CAAK,MAAA;AAAA,MACb,QAAQ,IAAA,CAAK,MAAA;AAAA,MACb,eAAA,EAAiB;AAAA,KACnB;AAAA,EACF;AACF,CAAA;AAEA,SAAS,WAAW,GAAA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AiB,CAAA;AAAA,IAC5B,UAAA,EAAY;AAAA,MACV,MAAA,EAAQ;AAAA,QACN,IAAA,EAAM,QAAA;AAAA,QACN,WAAA,EAAa;AAAA,OACf;AAAA,MACA,eAAA,EAAiB;AAAA,QACf,IAAA,EAAM,QAAA;AAAA,QACN,WAAA,EAAa;AAAA,OACf;AAAA,MACA,gBAAA,EAAkB;AAAA,QAChB,IAAA,EAAM,QAAA;AAAA,QACN,WAAA,EAAa;AAAA,OACf;AAAA,MACA,SAAA,EAAW;AAAA,QACT,IAAA,EAAM,QAAA;AAAA,QACN,WAAA,EAAa,kCAAA;AAAA,QACb,OAAA,EAAS;AAAA,OACX;AAAA,MACA,cAAA,EAAgB;AAAA,QACd,IAAA,EAAM,QAAA;AAAA,QACN,WAAA,EAAa,2EAAA;AAAA,QACb,OAAA,EAAS,GAAA;AAAA,QACT,OAAA,EAAS,CAAA;AAAA,QACT,OAAA,EAAS;AAAA,OACX;AAAA,MACA,sBAAA,EAAwB;AAAA,QACtB,IAAA,EAAM,SAAA;AAAA,QACN,WAAA,EAAa,4DAAA;AAAA,QACb,OAAA,EAAS;AAAA;AACX;AACF,GACF;AAAA,EACA,aAAA,EAAe,CAAA,MAAA,KAAU,IAAI,uBAAA,CAAwB,MAAM;AAC7D","file":"index.js","sourcesContent":["/**\n * AWS Bedrock AgentCore Runtime sandbox provider.\n *\n * This provider maps Mastra's one-shot command execution contract to\n * InvokeAgentRuntimeCommand. It intentionally does not expose process\n * management or filesystem mounts because AgentCore Runtime command execution\n * does not provide those WorkspaceSandbox semantics.\n *\n * @see https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime-execute-command.html\n */\n\nimport { randomUUID } from 'node:crypto';\nimport {\n BedrockAgentCoreClient,\n InvokeAgentRuntimeCommandCommand,\n StopRuntimeSessionCommand,\n} from '@aws-sdk/client-bedrock-agentcore';\nimport type { RequestContext } from '@mastra/core/di';\nimport type {\n CommandResult,\n ExecuteCommandOptions,\n MastraSandboxOptions,\n ProviderStatus,\n SandboxInfo,\n} from '@mastra/core/workspace';\nimport { MastraSandbox, ProcessHandle } from '@mastra/core/workspace';\n\nconst LOG_PREFIX = '[AgentCoreRuntimeSandbox]';\nconst DEFAULT_COMMAND_TIMEOUT_MS = 300_000;\nconst MAX_AGENTCORE_TIMEOUT_SECONDS = 3600;\nconst DEFAULT_ACCEPT = 'application/vnd.amazon.eventstream';\nconst DEFAULT_CONTENT_TYPE = 'application/json';\n\ntype AgentCoreRuntimeClient = Pick<BedrockAgentCoreClient, 'send' | 'destroy'>;\ntype InstructionsOption = string | ((opts: { defaultInstructions: string; requestContext?: RequestContext }) => string);\ntype AgentCoreStreamException = {\n name?: string;\n message?: string;\n};\n\ntype AgentCoreStreamEvent = {\n chunk?: {\n contentStart?: unknown;\n contentDelta?: {\n stdout?: string;\n stderr?: string;\n };\n contentStop?: {\n exitCode?: number;\n status?: string;\n };\n };\n accessDeniedException?: AgentCoreStreamException;\n internalServerException?: AgentCoreStreamException;\n resourceNotFoundException?: AgentCoreStreamException;\n serviceQuotaExceededException?: AgentCoreStreamException;\n throttlingException?: AgentCoreStreamException;\n validationException?: AgentCoreStreamException;\n runtimeClientError?: AgentCoreStreamException;\n $unknown?: [string, unknown];\n};\n\nclass CommandOutputAccumulator extends ProcessHandle {\n readonly pid = 'agentcore-command';\n exitCode: number | undefined;\n\n async kill(): Promise<boolean> {\n return false;\n }\n\n async sendStdin(): Promise<void> {\n throw new Error('AgentCore Runtime command execution does not support stdin');\n }\n\n async wait(): Promise<CommandResult> {\n return {\n success: this.exitCode === 0,\n exitCode: this.exitCode ?? 1,\n stdout: this.stdout,\n stderr: this.stderr,\n executionTimeMs: 0,\n };\n }\n}\n\nfunction shellQuote(arg: string): string {\n if (/^[a-zA-Z0-9._\\-\\/=:@]+$/.test(arg)) return arg;\n return `'${arg.replace(/'/g, \"'\\\\''\")}'`;\n}\n\nfunction safeEnvName(name: string): boolean {\n return /^[A-Za-z_][A-Za-z0-9_]*$/.test(name);\n}\n\nfunction buildCommand(command: string, args: string[] | undefined, options: ExecuteCommandOptions | undefined): string {\n const baseCommand = args?.length ? `${command} ${args.map(arg => shellQuote(arg)).join(' ')}` : command;\n const parts: string[] = [];\n\n if (options?.cwd) {\n parts.push(`cd ${shellQuote(options.cwd)}`);\n }\n\n const env = options?.env ?? {};\n const envAssignments = Object.entries(env)\n .filter((entry): entry is [string, string] => entry[1] !== undefined)\n .map(([key, value]) => {\n if (!safeEnvName(key)) {\n throw new Error(`Invalid environment variable name for AgentCore Runtime command: ${key}`);\n }\n return `${key}=${shellQuote(value)}`;\n });\n\n parts.push(`${envAssignments.length ? `${envAssignments.join(' ')} ` : ''}${baseCommand}`);\n return parts.join(' && ');\n}\n\nfunction toAgentCoreTimeoutSeconds(timeoutMs: number): number {\n if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {\n throw new RangeError('AgentCore Runtime command timeout must be a positive number of milliseconds');\n }\n\n const timeoutSeconds = Math.ceil(timeoutMs / 1000);\n if (timeoutSeconds > MAX_AGENTCORE_TIMEOUT_SECONDS) {\n throw new RangeError(`AgentCore Runtime command timeout must be at most ${MAX_AGENTCORE_TIMEOUT_SECONDS} seconds`);\n }\n\n return timeoutSeconds;\n}\n\nfunction generateSessionId(): string {\n return randomUUID();\n}\n\nfunction getStreamException(event: AgentCoreStreamEvent): { key: string; value: unknown } | undefined {\n const exceptionKeys = [\n 'accessDeniedException',\n 'internalServerException',\n 'resourceNotFoundException',\n 'serviceQuotaExceededException',\n 'throttlingException',\n 'validationException',\n 'runtimeClientError',\n ] as const;\n\n for (const key of exceptionKeys) {\n const value = event[key];\n if (value) return { key, value };\n }\n\n if (event.$unknown) {\n return { key: event.$unknown[0], value: event.$unknown[1] };\n }\n\n return undefined;\n}\n\nfunction formatStreamException(key: string, value: unknown): string {\n if (value && typeof value === 'object') {\n const exception = value as AgentCoreStreamException;\n const name = exception.name ?? key;\n return exception.message ? `${name}: ${exception.message}` : name;\n }\n\n return `${key}: ${String(value)}`;\n}\n\n// =============================================================================\n// Options\n// =============================================================================\n\nexport interface AgentCoreRuntimeSandboxOptions extends Omit<MastraSandboxOptions, 'processes'> {\n /** AWS region for the Bedrock AgentCore client. Falls back to the AWS SDK default region chain. */\n region?: string;\n /** AgentCore Runtime ARN where commands should execute. */\n agentRuntimeArn: string;\n /** Runtime session ID. Defaults to a generated UUID, which satisfies AgentCore's 33 character minimum. */\n runtimeSessionId?: string;\n /** Agent runtime qualifier/endpoint. Defaults to AWS AgentCore's DEFAULT qualifier. */\n qualifier?: string;\n /** MIME type sent for command requests. */\n contentType?: string;\n /** Accept header for command event streams. */\n accept?: string;\n /** Default command timeout in milliseconds. */\n commandTimeout?: number;\n /**\n * Stop the AgentCore Runtime session during stop()/destroy().\n *\n * Defaults to false because sessions are often shared with agent invocations\n * outside the WorkspaceSandbox instance.\n */\n stopSessionOnLifecycle?: boolean;\n /** Client token used for StopRuntimeSession. Defaults to a generated UUID when needed. */\n stopClientToken?: string;\n /** Optional preconfigured AWS SDK client, primarily for advanced credential setup and tests. */\n client?: AgentCoreRuntimeClient;\n /** Custom instructions for getInstructions(). String replaces the default; function receives it. */\n instructions?: InstructionsOption;\n}\n\n// =============================================================================\n// Implementation\n// =============================================================================\n\nexport class AgentCoreRuntimeSandbox extends MastraSandbox {\n readonly id: string;\n readonly name = 'AgentCoreRuntimeSandbox';\n readonly provider = 'agentcore';\n status: ProviderStatus = 'pending';\n\n private _client?: AgentCoreRuntimeClient;\n private readonly _ownsClient: boolean;\n private readonly _region?: string;\n private readonly _agentRuntimeArn: string;\n private readonly _runtimeSessionId: string;\n private readonly _qualifier?: string;\n private readonly _contentType: string;\n private readonly _accept: string;\n private readonly _commandTimeout: number;\n private readonly _stopSessionOnLifecycle: boolean;\n private readonly _stopClientToken?: string;\n private readonly _instructionsOverride?: InstructionsOption;\n private readonly _createdAt = new Date();\n private _lastUsedAt?: Date;\n\n constructor(options: AgentCoreRuntimeSandboxOptions) {\n super({ ...options, name: 'AgentCoreRuntimeSandbox' });\n\n if (!options.agentRuntimeArn) {\n throw new Error(`${LOG_PREFIX} agentRuntimeArn is required`);\n }\n\n this.id = options.runtimeSessionId ?? generateSessionId();\n this._agentRuntimeArn = options.agentRuntimeArn;\n this._runtimeSessionId = this.id;\n this._qualifier = options.qualifier;\n this._contentType = options.contentType ?? DEFAULT_CONTENT_TYPE;\n this._accept = options.accept ?? DEFAULT_ACCEPT;\n this._commandTimeout = options.commandTimeout ?? DEFAULT_COMMAND_TIMEOUT_MS;\n this._stopSessionOnLifecycle = options.stopSessionOnLifecycle ?? false;\n this._stopClientToken = options.stopClientToken;\n this._instructionsOverride = options.instructions;\n this._client = options.client;\n this._ownsClient = !options.client;\n this._region = options.region;\n }\n\n get runtimeSessionId(): string {\n return this._runtimeSessionId;\n }\n\n get agentRuntimeArn(): string {\n return this._agentRuntimeArn;\n }\n\n async start(): Promise<void> {\n this.logger.debug(`${LOG_PREFIX} Using AgentCore Runtime session ${this._runtimeSessionId}`);\n }\n\n async stop(): Promise<void> {\n if (!this._stopSessionOnLifecycle) return;\n await this.stopRuntimeSession();\n }\n\n async destroy(): Promise<void> {\n if (this._stopSessionOnLifecycle) {\n await this.stopRuntimeSession();\n }\n\n if (this._ownsClient && this._client) {\n this._client.destroy();\n this._client = undefined;\n }\n }\n\n /**\n * Explicitly stops the AgentCore Runtime session used by this sandbox.\n *\n * This is separate from destroy() because AgentCore Runtime sessions can be\n * shared with agent invocations outside the WorkspaceSandbox lifecycle.\n */\n async stopRuntimeSession(): Promise<void> {\n await this._getClient().send(\n new StopRuntimeSessionCommand({\n agentRuntimeArn: this._agentRuntimeArn,\n runtimeSessionId: this._runtimeSessionId,\n qualifier: this._qualifier,\n clientToken: this._stopClientToken ?? generateSessionId(),\n }),\n );\n }\n\n async executeCommand(command: string, args?: string[], options?: ExecuteCommandOptions): Promise<CommandResult> {\n await this.ensureRunning();\n\n const fullCommand = buildCommand(command, args, options);\n const timeoutMs = options?.timeout ?? this._commandTimeout;\n const timeoutSeconds = toAgentCoreTimeoutSeconds(timeoutMs);\n const startTime = Date.now();\n const output = new CommandOutputAccumulator({\n maxRetainedBytes: options?.maxRetainedBytes ?? Infinity,\n onStdout: options?.onStdout,\n onStderr: options?.onStderr,\n });\n let stopStatus: string | undefined;\n\n this.logger.debug(`${LOG_PREFIX} Executing command`, {\n runtimeSessionId: this._runtimeSessionId,\n command: fullCommand,\n timeoutSeconds,\n });\n\n const response = await this._getClient().send(\n new InvokeAgentRuntimeCommandCommand({\n agentRuntimeArn: this._agentRuntimeArn,\n runtimeSessionId: this._runtimeSessionId,\n qualifier: this._qualifier,\n contentType: this._contentType,\n accept: this._accept,\n body: {\n command: fullCommand,\n timeout: timeoutSeconds,\n },\n }),\n { abortSignal: options?.abortSignal },\n );\n\n for await (const event of response.stream ?? []) {\n const streamEvent = event as AgentCoreStreamEvent;\n const streamException = getStreamException(streamEvent);\n if (streamException) {\n throw new Error(`${LOG_PREFIX} ${formatStreamException(streamException.key, streamException.value)}`);\n }\n\n const chunk = streamEvent.chunk;\n if (!chunk) continue;\n\n if (chunk.contentDelta?.stdout) {\n output.emitStdout(chunk.contentDelta.stdout);\n }\n\n if (chunk.contentDelta?.stderr) {\n output.emitStderr(chunk.contentDelta.stderr);\n }\n\n if (chunk.contentStop) {\n output.exitCode = chunk.contentStop.exitCode ?? 1;\n stopStatus = chunk.contentStop.status;\n }\n }\n\n const executionTimeMs = Date.now() - startTime;\n const exitCode = output.exitCode ?? 1;\n const timedOut = stopStatus === 'TIMED_OUT';\n const finalExitCode = timedOut ? 124 : exitCode;\n this._lastUsedAt = new Date();\n\n return {\n command: fullCommand,\n args,\n success: finalExitCode === 0 && !timedOut,\n exitCode: finalExitCode,\n stdout: output.stdout,\n stderr: output.stderr,\n executionTimeMs,\n timedOut,\n stdoutTruncated: output.stdoutTruncated,\n stderrTruncated: output.stderrTruncated,\n stdoutDroppedBytes: output.stdoutDroppedBytes,\n stderrDroppedBytes: output.stderrDroppedBytes,\n };\n }\n\n getInstructions(opts?: { requestContext?: RequestContext }): string {\n const defaultInstructions = this._getDefaultInstructions();\n if (this._instructionsOverride === undefined) return defaultInstructions;\n if (typeof this._instructionsOverride === 'string') return this._instructionsOverride;\n return this._instructionsOverride({ defaultInstructions, requestContext: opts?.requestContext });\n }\n\n async getInfo(): Promise<SandboxInfo> {\n return {\n id: this.id,\n name: this.name,\n provider: this.provider,\n status: this.status,\n createdAt: this._createdAt,\n lastUsedAt: this._lastUsedAt,\n metadata: {\n agentRuntimeArn: this._agentRuntimeArn,\n runtimeSessionId: this._runtimeSessionId,\n qualifier: this._qualifier ?? 'DEFAULT',\n stopSessionOnLifecycle: this._stopSessionOnLifecycle,\n },\n };\n }\n\n private _getDefaultInstructions(): string {\n return [\n 'AWS Bedrock AgentCore Runtime sandbox.',\n 'Commands run inside the configured AgentCore Runtime session container.',\n 'Command output streams from AgentCore Runtime as stdout and stderr.',\n 'Limitations:',\n '- Commands are one-shot and non-interactive.',\n '- There is no persistent shell session between commands.',\n '- Background process management is not exposed by this provider.',\n '- Filesystem mounts are not exposed by this provider.',\n '- Developer tools such as git, npm, Python, or Node must exist in the AgentCore container image.',\n '- AgentCore Code Interpreter is a separate service and is not part of this runtime sandbox.',\n ].join('\\n');\n }\n\n private _getClient(): AgentCoreRuntimeClient {\n if (!this._client) {\n this._client = new BedrockAgentCoreClient({ region: this._region });\n }\n return this._client;\n }\n}\n","/**\n * AWS Bedrock AgentCore Runtime sandbox provider descriptor.\n *\n * Enables registration with MastraEditor for UI-driven sandbox configuration.\n */\n\nimport type { SandboxProvider } from '@mastra/core/editor';\nimport { AgentCoreRuntimeSandbox } from './sandbox';\n\nexport interface AgentCoreRuntimeProviderConfig {\n /** AWS region for the Bedrock AgentCore client */\n region?: string;\n /** AgentCore Runtime ARN where commands should execute */\n agentRuntimeArn: string;\n /** Runtime session ID */\n runtimeSessionId?: string;\n /** Agent runtime qualifier/endpoint */\n qualifier?: string;\n /** Default command timeout in milliseconds */\n commandTimeout?: number;\n /** Stop the runtime session during stop()/destroy() */\n stopSessionOnLifecycle?: boolean;\n}\n\nexport const agentCoreRuntimeSandboxProvider: SandboxProvider<AgentCoreRuntimeProviderConfig> = {\n id: 'agentcore',\n name: 'AgentCore Runtime Sandbox',\n description: 'AWS Bedrock AgentCore Runtime command execution sandbox',\n configSchema: {\n type: 'object',\n required: ['agentRuntimeArn'],\n properties: {\n region: {\n type: 'string',\n description: 'AWS region for Bedrock AgentCore',\n },\n agentRuntimeArn: {\n type: 'string',\n description: 'AgentCore Runtime ARN',\n },\n runtimeSessionId: {\n type: 'string',\n description: 'Runtime session ID. Defaults to a generated UUID.',\n },\n qualifier: {\n type: 'string',\n description: 'Agent runtime qualifier/endpoint',\n default: 'DEFAULT',\n },\n commandTimeout: {\n type: 'number',\n description: 'Default command timeout in milliseconds. Must be between 1 and 3,600,000.',\n default: 300_000,\n minimum: 1,\n maximum: 3_600_000,\n },\n stopSessionOnLifecycle: {\n type: 'boolean',\n description: 'Stop the AgentCore Runtime session during stop()/destroy()',\n default: false,\n },\n },\n },\n createSandbox: config => new AgentCoreRuntimeSandbox(config),\n};\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWS Bedrock AgentCore Runtime sandbox provider descriptor.
|
|
3
|
+
*
|
|
4
|
+
* Enables registration with MastraEditor for UI-driven sandbox configuration.
|
|
5
|
+
*/
|
|
6
|
+
import type { SandboxProvider } from '@mastra/core/editor';
|
|
7
|
+
export interface AgentCoreRuntimeProviderConfig {
|
|
8
|
+
/** AWS region for the Bedrock AgentCore client */
|
|
9
|
+
region?: string;
|
|
10
|
+
/** AgentCore Runtime ARN where commands should execute */
|
|
11
|
+
agentRuntimeArn: string;
|
|
12
|
+
/** Runtime session ID */
|
|
13
|
+
runtimeSessionId?: string;
|
|
14
|
+
/** Agent runtime qualifier/endpoint */
|
|
15
|
+
qualifier?: string;
|
|
16
|
+
/** Default command timeout in milliseconds */
|
|
17
|
+
commandTimeout?: number;
|
|
18
|
+
/** Stop the runtime session during stop()/destroy() */
|
|
19
|
+
stopSessionOnLifecycle?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare const agentCoreRuntimeSandboxProvider: SandboxProvider<AgentCoreRuntimeProviderConfig>;
|
|
22
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAG3D,MAAM,WAAW,8BAA8B;IAC7C,kDAAkD;IAClD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0DAA0D;IAC1D,eAAe,EAAE,MAAM,CAAC;IACxB,yBAAyB;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,uCAAuC;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,8CAA8C;IAC9C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,uDAAuD;IACvD,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC;AAED,eAAO,MAAM,+BAA+B,EAAE,eAAe,CAAC,8BAA8B,CAwC3F,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWS Bedrock AgentCore Runtime sandbox provider.
|
|
3
|
+
*
|
|
4
|
+
* This provider maps Mastra's one-shot command execution contract to
|
|
5
|
+
* InvokeAgentRuntimeCommand. It intentionally does not expose process
|
|
6
|
+
* management or filesystem mounts because AgentCore Runtime command execution
|
|
7
|
+
* does not provide those WorkspaceSandbox semantics.
|
|
8
|
+
*
|
|
9
|
+
* @see https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime-execute-command.html
|
|
10
|
+
*/
|
|
11
|
+
import { BedrockAgentCoreClient } from '@aws-sdk/client-bedrock-agentcore';
|
|
12
|
+
import type { RequestContext } from '@mastra/core/di';
|
|
13
|
+
import type { CommandResult, ExecuteCommandOptions, MastraSandboxOptions, ProviderStatus, SandboxInfo } from '@mastra/core/workspace';
|
|
14
|
+
import { MastraSandbox } from '@mastra/core/workspace';
|
|
15
|
+
type AgentCoreRuntimeClient = Pick<BedrockAgentCoreClient, 'send' | 'destroy'>;
|
|
16
|
+
type InstructionsOption = string | ((opts: {
|
|
17
|
+
defaultInstructions: string;
|
|
18
|
+
requestContext?: RequestContext;
|
|
19
|
+
}) => string);
|
|
20
|
+
export interface AgentCoreRuntimeSandboxOptions extends Omit<MastraSandboxOptions, 'processes'> {
|
|
21
|
+
/** AWS region for the Bedrock AgentCore client. Falls back to the AWS SDK default region chain. */
|
|
22
|
+
region?: string;
|
|
23
|
+
/** AgentCore Runtime ARN where commands should execute. */
|
|
24
|
+
agentRuntimeArn: string;
|
|
25
|
+
/** Runtime session ID. Defaults to a generated UUID, which satisfies AgentCore's 33 character minimum. */
|
|
26
|
+
runtimeSessionId?: string;
|
|
27
|
+
/** Agent runtime qualifier/endpoint. Defaults to AWS AgentCore's DEFAULT qualifier. */
|
|
28
|
+
qualifier?: string;
|
|
29
|
+
/** MIME type sent for command requests. */
|
|
30
|
+
contentType?: string;
|
|
31
|
+
/** Accept header for command event streams. */
|
|
32
|
+
accept?: string;
|
|
33
|
+
/** Default command timeout in milliseconds. */
|
|
34
|
+
commandTimeout?: number;
|
|
35
|
+
/**
|
|
36
|
+
* Stop the AgentCore Runtime session during stop()/destroy().
|
|
37
|
+
*
|
|
38
|
+
* Defaults to false because sessions are often shared with agent invocations
|
|
39
|
+
* outside the WorkspaceSandbox instance.
|
|
40
|
+
*/
|
|
41
|
+
stopSessionOnLifecycle?: boolean;
|
|
42
|
+
/** Client token used for StopRuntimeSession. Defaults to a generated UUID when needed. */
|
|
43
|
+
stopClientToken?: string;
|
|
44
|
+
/** Optional preconfigured AWS SDK client, primarily for advanced credential setup and tests. */
|
|
45
|
+
client?: AgentCoreRuntimeClient;
|
|
46
|
+
/** Custom instructions for getInstructions(). String replaces the default; function receives it. */
|
|
47
|
+
instructions?: InstructionsOption;
|
|
48
|
+
}
|
|
49
|
+
export declare class AgentCoreRuntimeSandbox extends MastraSandbox {
|
|
50
|
+
readonly id: string;
|
|
51
|
+
readonly name = "AgentCoreRuntimeSandbox";
|
|
52
|
+
readonly provider = "agentcore";
|
|
53
|
+
status: ProviderStatus;
|
|
54
|
+
private _client?;
|
|
55
|
+
private readonly _ownsClient;
|
|
56
|
+
private readonly _region?;
|
|
57
|
+
private readonly _agentRuntimeArn;
|
|
58
|
+
private readonly _runtimeSessionId;
|
|
59
|
+
private readonly _qualifier?;
|
|
60
|
+
private readonly _contentType;
|
|
61
|
+
private readonly _accept;
|
|
62
|
+
private readonly _commandTimeout;
|
|
63
|
+
private readonly _stopSessionOnLifecycle;
|
|
64
|
+
private readonly _stopClientToken?;
|
|
65
|
+
private readonly _instructionsOverride?;
|
|
66
|
+
private readonly _createdAt;
|
|
67
|
+
private _lastUsedAt?;
|
|
68
|
+
constructor(options: AgentCoreRuntimeSandboxOptions);
|
|
69
|
+
get runtimeSessionId(): string;
|
|
70
|
+
get agentRuntimeArn(): string;
|
|
71
|
+
start(): Promise<void>;
|
|
72
|
+
stop(): Promise<void>;
|
|
73
|
+
destroy(): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Explicitly stops the AgentCore Runtime session used by this sandbox.
|
|
76
|
+
*
|
|
77
|
+
* This is separate from destroy() because AgentCore Runtime sessions can be
|
|
78
|
+
* shared with agent invocations outside the WorkspaceSandbox lifecycle.
|
|
79
|
+
*/
|
|
80
|
+
stopRuntimeSession(): Promise<void>;
|
|
81
|
+
executeCommand(command: string, args?: string[], options?: ExecuteCommandOptions): Promise<CommandResult>;
|
|
82
|
+
getInstructions(opts?: {
|
|
83
|
+
requestContext?: RequestContext;
|
|
84
|
+
}): string;
|
|
85
|
+
getInfo(): Promise<SandboxInfo>;
|
|
86
|
+
private _getDefaultInstructions;
|
|
87
|
+
private _getClient;
|
|
88
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cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,aAAa,CAAC;IAiF/G,eAAe,CAAC,IAAI,CAAC,EAAE;QAAE,cAAc,CAAC,EAAE,cAAc,CAAA;KAAE,GAAG,MAAM;IAO7D,OAAO,IAAI,OAAO,CAAC,WAAW,CAAC;IAiBrC,OAAO,CAAC,uBAAuB;IAe/B,OAAO,CAAC,UAAU;CAMnB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/agentcore",
|
|
3
|
-
"version": "0.0.0",
|
|
3
|
+
"version": "0.2.0-alpha.0",
|
|
4
4
|
"description": "AWS Bedrock AgentCore Runtime sandbox provider for Mastra workspaces",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -18,32 +18,22 @@
|
|
|
18
18
|
},
|
|
19
19
|
"./package.json": "./package.json"
|
|
20
20
|
},
|
|
21
|
-
"scripts": {
|
|
22
|
-
"build": "tsup --silent --config tsup.config.ts",
|
|
23
|
-
"build:lib": "pnpm build",
|
|
24
|
-
"build:watch": "pnpm build --watch",
|
|
25
|
-
"test:unit": "vitest run --exclude '**/*.integration.test.ts'",
|
|
26
|
-
"test:watch": "vitest watch",
|
|
27
|
-
"test": "vitest run ./src/**/*.integration.test.ts",
|
|
28
|
-
"test:cloud": "pnpm test",
|
|
29
|
-
"lint": "eslint ."
|
|
30
|
-
},
|
|
31
21
|
"license": "Apache-2.0",
|
|
32
22
|
"dependencies": {
|
|
33
23
|
"@aws-sdk/client-bedrock-agentcore": "^3.1045.0"
|
|
34
24
|
},
|
|
35
25
|
"devDependencies": {
|
|
36
|
-
"@internal/lint": "workspace:*",
|
|
37
|
-
"@internal/types-builder": "workspace:*",
|
|
38
|
-
"@mastra/core": "workspace:*",
|
|
39
26
|
"@types/node": "22.19.15",
|
|
40
|
-
"@vitest/coverage-v8": "
|
|
41
|
-
"@vitest/ui": "
|
|
27
|
+
"@vitest/coverage-v8": "4.1.5",
|
|
28
|
+
"@vitest/ui": "4.1.5",
|
|
42
29
|
"dotenv": "^17.3.1",
|
|
43
30
|
"eslint": "^10.2.1",
|
|
44
31
|
"tsup": "^8.5.1",
|
|
45
|
-
"typescript": "
|
|
46
|
-
"vitest": "
|
|
32
|
+
"typescript": "^6.0.3",
|
|
33
|
+
"vitest": "4.1.5",
|
|
34
|
+
"@internal/types-builder": "0.0.74",
|
|
35
|
+
"@mastra/core": "1.38.0-alpha.3",
|
|
36
|
+
"@internal/lint": "0.0.99"
|
|
47
37
|
},
|
|
48
38
|
"peerDependencies": {
|
|
49
39
|
"@mastra/core": ">=1.12.0-0 <2.0.0-0"
|
|
@@ -63,5 +53,15 @@
|
|
|
63
53
|
},
|
|
64
54
|
"engines": {
|
|
65
55
|
"node": ">=22.13.0"
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "tsup --silent --config tsup.config.ts",
|
|
59
|
+
"build:lib": "pnpm build",
|
|
60
|
+
"build:watch": "pnpm build --watch",
|
|
61
|
+
"test:unit": "vitest run --exclude '**/*.integration.test.ts'",
|
|
62
|
+
"test:watch": "vitest watch",
|
|
63
|
+
"test": "vitest run ./src/**/*.integration.test.ts",
|
|
64
|
+
"test:cloud": "pnpm test",
|
|
65
|
+
"lint": "eslint ."
|
|
66
66
|
}
|
|
67
|
-
}
|
|
67
|
+
}
|