@mastra/sprites 0.0.0-stage → 0.1.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/LICENSE.md +32 -0
- package/README.md +46 -2
- package/dist/index.cjs +341 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +338 -0
- package/dist/index.js.map +1 -0
- package/dist/provider.d.ts +29 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/sandbox/index.d.ts +83 -0
- package/dist/sandbox/index.d.ts.map +1 -0
- package/dist/sandbox/process-manager.d.ts +24 -0
- package/dist/sandbox/process-manager.d.ts.map +1 -0
- package/package.json +65 -3
package/LICENSE.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
- `@mastra/core/auth/ee`
|
|
6
|
+
- `@mastra/core/agent-builder/ee`
|
|
7
|
+
- `@mastra/editor/ee`
|
|
8
|
+
|
|
9
|
+
is licensed under the license defined in [`ee/LICENSE`](https://github.com/mastra-ai/mastra/blob/main/ee/LICENSE).
|
|
10
|
+
|
|
11
|
+
- All third-party components incorporated into the Mastra Software are
|
|
12
|
+
licensed under the original license provided by the owner of the
|
|
13
|
+
applicable component.
|
|
14
|
+
|
|
15
|
+
- Content outside of the above-mentioned directories or restrictions is
|
|
16
|
+
available under the "Apache License 2.0" as defined below.
|
|
17
|
+
|
|
18
|
+
# Apache License 2.0
|
|
19
|
+
|
|
20
|
+
Copyright (c) 2025 Kepler Software, Inc.
|
|
21
|
+
|
|
22
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
23
|
+
you may not use this file except in compliance with the License.
|
|
24
|
+
You may obtain a copy of the License at
|
|
25
|
+
|
|
26
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
27
|
+
|
|
28
|
+
Unless required by applicable law or agreed to in writing, software
|
|
29
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
30
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
31
|
+
See the License for the specific language governing permissions and
|
|
32
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,47 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @mastra/sprites
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Fly.io Sprites sandbox provider for [Mastra](https://mastra.ai) workspaces.
|
|
4
|
+
|
|
5
|
+
Implements the `WorkspaceSandbox` interface using [Fly.io Sprites](https://sprites.dev) — persistent Linux VMs that keep their filesystem between runs and hibernate when idle — through the official `@fly/sprites` SDK. Supports get-or-create by Sprite name, command execution with streaming output, timeouts and cancellation, background processes with stdin, and checkpoint capture.
|
|
6
|
+
|
|
7
|
+
Requires Node.js 24 or later.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @mastra/sprites
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { Workspace } from '@mastra/core/workspace';
|
|
19
|
+
import { SpritesSandbox } from '@mastra/sprites';
|
|
20
|
+
|
|
21
|
+
const sandbox = new SpritesSandbox({
|
|
22
|
+
id: 'mastra-project',
|
|
23
|
+
// token read from SPRITES_TOKEN
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const workspace = new Workspace({ sandbox });
|
|
27
|
+
await workspace.init();
|
|
28
|
+
|
|
29
|
+
const result = await workspace.sandbox.executeCommand('echo', ['Hello!']);
|
|
30
|
+
console.log(result.stdout); // "Hello!"
|
|
31
|
+
|
|
32
|
+
// stop() keeps the Sprite and its files; destroy() deletes it.
|
|
33
|
+
await sandbox.destroy();
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Documentation
|
|
37
|
+
|
|
38
|
+
- [Fly.io Sprites integration guide](https://mastra.ai/integrations/sandboxes/sprites)
|
|
39
|
+
- [Workspace documentation](https://mastra.ai/docs/mastra-platform/workspaces)
|
|
40
|
+
|
|
41
|
+
## Changelog
|
|
42
|
+
|
|
43
|
+
See the [package changelog](https://github.com/mastra-ai/mastra/blob/main/workspaces/sprites/CHANGELOG.md) for version history and release notes.
|
|
44
|
+
|
|
45
|
+
## Support
|
|
46
|
+
|
|
47
|
+
We have an [open community Discord](https://discord.gg/mastra-ai). Come and say hello and let us know if you have any questions or need any help getting things running.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _fly_sprites = require("@fly/sprites");
|
|
3
|
+
let _mastra_core_workspace = require("@mastra/core/workspace");
|
|
4
|
+
//#region src/sandbox/process-manager.ts
|
|
5
|
+
const LOG_PREFIX = "[SpritesSandbox]";
|
|
6
|
+
/** Exit code reported for processes terminated by `kill()` or a timeout. */
|
|
7
|
+
const KILLED_EXIT_CODE = 137;
|
|
8
|
+
var SpritesProcessHandle = class extends _mastra_core_workspace.ProcessHandle {
|
|
9
|
+
pid;
|
|
10
|
+
_cmd;
|
|
11
|
+
_startTime = Date.now();
|
|
12
|
+
_done;
|
|
13
|
+
_exitCode;
|
|
14
|
+
_killed = false;
|
|
15
|
+
_timedOut = false;
|
|
16
|
+
_timeoutId;
|
|
17
|
+
_error;
|
|
18
|
+
constructor(pid, cmd, options, timeout) {
|
|
19
|
+
super(options);
|
|
20
|
+
this.pid = pid;
|
|
21
|
+
this._cmd = cmd;
|
|
22
|
+
cmd.stdout.setEncoding("utf8");
|
|
23
|
+
cmd.stderr.setEncoding("utf8");
|
|
24
|
+
cmd.stdout.on("data", (chunk) => this.emitStdout(chunk));
|
|
25
|
+
cmd.stderr.on("data", (chunk) => this.emitStderr(chunk));
|
|
26
|
+
cmd.on("error", (error) => {
|
|
27
|
+
this._error ??= error;
|
|
28
|
+
});
|
|
29
|
+
this._done = Promise.all([
|
|
30
|
+
cmd.wait(),
|
|
31
|
+
streamEnded(cmd.stdout),
|
|
32
|
+
streamEnded(cmd.stderr)
|
|
33
|
+
]).then(([code]) => {
|
|
34
|
+
clearTimeout(this._timeoutId);
|
|
35
|
+
this._exitCode = this._killed ? KILLED_EXIT_CODE : code < 0 ? 1 : code;
|
|
36
|
+
});
|
|
37
|
+
if (timeout !== void 0 && timeout > 0) this._timeoutId = setTimeout(() => {
|
|
38
|
+
this._timedOut = true;
|
|
39
|
+
this.kill();
|
|
40
|
+
}, timeout);
|
|
41
|
+
}
|
|
42
|
+
get exitCode() {
|
|
43
|
+
return this._exitCode;
|
|
44
|
+
}
|
|
45
|
+
async wait() {
|
|
46
|
+
await this._done;
|
|
47
|
+
const exitCode = this._exitCode;
|
|
48
|
+
let stderr = this.stderr;
|
|
49
|
+
if (exitCode !== 0 && !stderr && this._error && !this._killed) stderr = this._error.message;
|
|
50
|
+
return {
|
|
51
|
+
success: exitCode === 0,
|
|
52
|
+
exitCode,
|
|
53
|
+
stdout: this.stdout,
|
|
54
|
+
stderr,
|
|
55
|
+
executionTimeMs: Date.now() - this._startTime,
|
|
56
|
+
...this._killed && { killed: true },
|
|
57
|
+
...this._timedOut && { timedOut: true }
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
async kill() {
|
|
61
|
+
if (this._exitCode !== void 0 || this._killed) return false;
|
|
62
|
+
this._killed = true;
|
|
63
|
+
clearTimeout(this._timeoutId);
|
|
64
|
+
this._cmd.kill("SIGKILL");
|
|
65
|
+
this._cmd.close();
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
async sendStdin(data) {
|
|
69
|
+
if (this._exitCode !== void 0) throw new Error(`${LOG_PREFIX} Cannot write to stdin: process ${this.pid} has exited`);
|
|
70
|
+
await new Promise((resolve, reject) => {
|
|
71
|
+
this._cmd.stdin.write(data, (error) => error ? reject(error) : resolve());
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
async closeStdin() {
|
|
75
|
+
this._cmd.stdin.end();
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
var SpritesProcessManager = class extends _mastra_core_workspace.SandboxProcessManager {
|
|
79
|
+
_spawnCounter = 0;
|
|
80
|
+
async spawn(command, options = {}) {
|
|
81
|
+
const env = Object.fromEntries(Object.entries(options.env ?? {}).filter((entry) => entry[1] !== void 0));
|
|
82
|
+
const cwd = options.cwd ?? this.sandbox.workingDirectory;
|
|
83
|
+
const cmd = this.sandbox.sprite.spawn("sh", ["-c", command], {
|
|
84
|
+
...cwd && { cwd },
|
|
85
|
+
...Object.keys(env).length > 0 && { env }
|
|
86
|
+
});
|
|
87
|
+
try {
|
|
88
|
+
await waitForSpawn(cmd);
|
|
89
|
+
} catch (error) {
|
|
90
|
+
cmd.close();
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
if (options.stdinMode === "ignore") cmd.stdin.end();
|
|
94
|
+
const pid = `sprites-proc-${Date.now().toString(36)}-${(++this._spawnCounter).toString(36)}`;
|
|
95
|
+
const handle = new SpritesProcessHandle(pid, cmd, options, options.timeout ?? this.sandbox.defaultTimeout);
|
|
96
|
+
this._tracked.set(pid, handle);
|
|
97
|
+
return handle;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Lists processes spawned by this instance. The Sprites exec API has no
|
|
101
|
+
* listing for non-detachable commands, so processes started elsewhere are
|
|
102
|
+
* not included.
|
|
103
|
+
*/
|
|
104
|
+
async list() {
|
|
105
|
+
return [...this._tracked.values()].map((handle) => ({
|
|
106
|
+
pid: handle.pid,
|
|
107
|
+
command: handle.command,
|
|
108
|
+
running: handle.exitCode === void 0,
|
|
109
|
+
...handle.exitCode !== void 0 && { exitCode: handle.exitCode }
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
/** Kill every running process spawned by this instance. Does not start the sandbox. */
|
|
113
|
+
async killAll() {
|
|
114
|
+
const running = [...this._tracked.values()].filter((handle) => handle.exitCode === void 0);
|
|
115
|
+
await Promise.all(running.map((handle) => this.kill(handle.pid)));
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
function waitForSpawn(cmd) {
|
|
119
|
+
return new Promise((resolve, reject) => {
|
|
120
|
+
const onSpawn = () => {
|
|
121
|
+
cmd.off("error", onError);
|
|
122
|
+
resolve();
|
|
123
|
+
};
|
|
124
|
+
const onError = (error) => {
|
|
125
|
+
cmd.off("spawn", onSpawn);
|
|
126
|
+
reject(error);
|
|
127
|
+
};
|
|
128
|
+
cmd.once("spawn", onSpawn);
|
|
129
|
+
cmd.once("error", onError);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
function streamEnded(stream) {
|
|
133
|
+
return new Promise((resolve) => {
|
|
134
|
+
stream.once("end", () => resolve());
|
|
135
|
+
stream.once("close", () => resolve());
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
//#endregion
|
|
139
|
+
//#region src/sandbox/index.ts
|
|
140
|
+
/**
|
|
141
|
+
* Fly.io Sprites Sandbox Provider
|
|
142
|
+
*
|
|
143
|
+
* A Sprites sandbox implementation for Mastra workspaces. Gets or creates a
|
|
144
|
+
* persistent Fly.io Sprite by name and runs commands in it through the
|
|
145
|
+
* official `@fly/sprites` SDK. Sprites keep their filesystem between runs and
|
|
146
|
+
* hibernate on their own when idle.
|
|
147
|
+
*
|
|
148
|
+
* @see https://sprites.dev
|
|
149
|
+
*/
|
|
150
|
+
var SpritesSandbox = class extends _mastra_core_workspace.MastraSandbox {
|
|
151
|
+
id;
|
|
152
|
+
name = "SpritesSandbox";
|
|
153
|
+
provider = "sprites";
|
|
154
|
+
status = "pending";
|
|
155
|
+
_client = null;
|
|
156
|
+
_sprite = null;
|
|
157
|
+
_createdAt = null;
|
|
158
|
+
_token;
|
|
159
|
+
_baseURL;
|
|
160
|
+
_spriteConfig;
|
|
161
|
+
_timeout;
|
|
162
|
+
_instructionsOverride;
|
|
163
|
+
constructor(options = {}) {
|
|
164
|
+
super({
|
|
165
|
+
...options,
|
|
166
|
+
name: "SpritesSandbox",
|
|
167
|
+
processes: new SpritesProcessManager()
|
|
168
|
+
});
|
|
169
|
+
this.id = options.id ?? `mastra-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
170
|
+
this._token = options.token ?? process.env.SPRITES_TOKEN;
|
|
171
|
+
this._baseURL = options.baseURL;
|
|
172
|
+
this._spriteConfig = options.spriteConfig;
|
|
173
|
+
this._timeout = options.timeout;
|
|
174
|
+
this._instructionsOverride = options.instructions;
|
|
175
|
+
}
|
|
176
|
+
/** The underlying SDK `Sprite`. Throws if the sandbox has not been started. */
|
|
177
|
+
get sprite() {
|
|
178
|
+
if (!this._sprite) throw new _mastra_core_workspace.SandboxNotReadyError(this.id);
|
|
179
|
+
return this._sprite;
|
|
180
|
+
}
|
|
181
|
+
/** Default command timeout in milliseconds, if configured. */
|
|
182
|
+
get defaultTimeout() {
|
|
183
|
+
return this._timeout;
|
|
184
|
+
}
|
|
185
|
+
get client() {
|
|
186
|
+
if (!this._client) {
|
|
187
|
+
if (!this._token) throw new Error(`${LOG_PREFIX} Missing Sprites API token. Pass \`token\` or set the SPRITES_TOKEN environment variable.`);
|
|
188
|
+
this._client = new _fly_sprites.SpritesClient(this._token, this._baseURL ? { baseURL: this._baseURL } : void 0);
|
|
189
|
+
}
|
|
190
|
+
return this._client;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Get the Sprite named `id`, creating it when it does not exist.
|
|
194
|
+
* Reports `outcome: 'created'` only when a new Sprite was provisioned.
|
|
195
|
+
*/
|
|
196
|
+
async start() {
|
|
197
|
+
if (this._sprite) return { outcome: "connected" };
|
|
198
|
+
const client = this.client;
|
|
199
|
+
let outcome = "connected";
|
|
200
|
+
let sprite;
|
|
201
|
+
try {
|
|
202
|
+
sprite = await client.getSprite(this.id);
|
|
203
|
+
} catch (error) {
|
|
204
|
+
if (!isStatus(error, 404)) throw error;
|
|
205
|
+
try {
|
|
206
|
+
sprite = await client.createSprite(this.id, this._spriteConfig);
|
|
207
|
+
outcome = "created";
|
|
208
|
+
} catch (createError) {
|
|
209
|
+
if (!isStatus(createError, 409)) throw createError;
|
|
210
|
+
sprite = await client.getSprite(this.id);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
this._sprite = sprite;
|
|
214
|
+
this._createdAt = sprite.createdAt ?? /* @__PURE__ */ new Date();
|
|
215
|
+
this.logger.debug(`${LOG_PREFIX} Sprite ready`, {
|
|
216
|
+
id: this.id,
|
|
217
|
+
outcome
|
|
218
|
+
});
|
|
219
|
+
return { outcome };
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Release local resources: kill background processes started by this
|
|
223
|
+
* instance and close the SDK control connection.
|
|
224
|
+
*
|
|
225
|
+
* The Sprite itself is NOT deleted or suspended. Sprites hibernate on their
|
|
226
|
+
* own when idle, and `start()` reconnects to the same filesystem.
|
|
227
|
+
*/
|
|
228
|
+
async stop() {
|
|
229
|
+
await this._killTrackedProcesses();
|
|
230
|
+
this._sprite?.closeControlConnection();
|
|
231
|
+
this._sprite = null;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Permanently delete the Sprite and its filesystem. A Sprite that no longer
|
|
235
|
+
* exists is treated as already destroyed.
|
|
236
|
+
*/
|
|
237
|
+
async destroy() {
|
|
238
|
+
await this._killTrackedProcesses();
|
|
239
|
+
const sprite = this._sprite ?? this.client.sprite(this.id);
|
|
240
|
+
sprite.closeControlConnection();
|
|
241
|
+
this._sprite = null;
|
|
242
|
+
try {
|
|
243
|
+
await sprite.delete();
|
|
244
|
+
} catch (error) {
|
|
245
|
+
if (!isStatus(error, 404)) throw error;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Capture a checkpoint of the Sprite's current state.
|
|
250
|
+
*
|
|
251
|
+
* Checkpoints live inside this Sprite only and cannot seed other sandboxes,
|
|
252
|
+
* so `supportsCheckpoints` stays `false`.
|
|
253
|
+
*/
|
|
254
|
+
async snapshot() {
|
|
255
|
+
await this.ensureRunning();
|
|
256
|
+
await (await this.sprite.createCheckpoint("mastra snapshot")).processAll((message) => {
|
|
257
|
+
if (message.type === "error") throw new Error(`${LOG_PREFIX} Checkpoint failed: ${message.error ?? message.data ?? "unknown error"}`);
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
async _killTrackedProcesses() {
|
|
261
|
+
await this.processes.killAll().catch((error) => {
|
|
262
|
+
this.logger.warn(`${LOG_PREFIX} Failed to kill background processes`, { error });
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
async getInfo() {
|
|
266
|
+
const sprite = this._sprite;
|
|
267
|
+
return {
|
|
268
|
+
id: this.id,
|
|
269
|
+
name: this.name,
|
|
270
|
+
provider: this.provider,
|
|
271
|
+
status: this.status,
|
|
272
|
+
createdAt: this._createdAt ?? /* @__PURE__ */ new Date(),
|
|
273
|
+
metadata: { ...sprite && {
|
|
274
|
+
...sprite.id && { spriteId: sprite.id },
|
|
275
|
+
...sprite.status && { spriteStatus: sprite.status },
|
|
276
|
+
...sprite.url && { url: sprite.url },
|
|
277
|
+
...sprite.primaryRegion && { region: sprite.primaryRegion }
|
|
278
|
+
} }
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
getInstructions() {
|
|
282
|
+
const defaultInstructions = this._buildDefaultInstructions();
|
|
283
|
+
if (typeof this._instructionsOverride === "string") return this._instructionsOverride;
|
|
284
|
+
if (typeof this._instructionsOverride === "function") return this._instructionsOverride({ defaultInstructions });
|
|
285
|
+
return defaultInstructions;
|
|
286
|
+
}
|
|
287
|
+
_buildDefaultInstructions() {
|
|
288
|
+
const parts = ["Fly.io Sprite: a persistent Linux VM. Files written to disk survive between sessions.", this.workingDirectory ? `Commands run in ${this.workingDirectory} by default.` : "Commands run in the Sprite user home directory by default."];
|
|
289
|
+
if (this._timeout !== void 0) parts.push(`Default command timeout: ${Math.ceil(this._timeout / 1e3)}s.`);
|
|
290
|
+
return parts.join(" ");
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
function isStatus(error, statusCode) {
|
|
294
|
+
return error instanceof _fly_sprites.APIError && error.statusCode === statusCode;
|
|
295
|
+
}
|
|
296
|
+
//#endregion
|
|
297
|
+
//#region src/provider.ts
|
|
298
|
+
const spritesSandboxProvider = {
|
|
299
|
+
id: "sprites",
|
|
300
|
+
name: "Fly.io Sprites",
|
|
301
|
+
description: "Persistent Linux VM powered by Fly.io Sprites",
|
|
302
|
+
configSchema: {
|
|
303
|
+
type: "object",
|
|
304
|
+
properties: {
|
|
305
|
+
id: {
|
|
306
|
+
type: "string",
|
|
307
|
+
description: "Sprite name. An existing Sprite with this name is reused."
|
|
308
|
+
},
|
|
309
|
+
token: {
|
|
310
|
+
type: "string",
|
|
311
|
+
description: "Sprites API token (falls back to SPRITES_TOKEN)"
|
|
312
|
+
},
|
|
313
|
+
env: {
|
|
314
|
+
type: "object",
|
|
315
|
+
description: "Environment variables",
|
|
316
|
+
additionalProperties: { type: "string" }
|
|
317
|
+
},
|
|
318
|
+
timeout: {
|
|
319
|
+
type: "number",
|
|
320
|
+
description: "Default command timeout in ms"
|
|
321
|
+
},
|
|
322
|
+
workingDirectory: {
|
|
323
|
+
type: "string",
|
|
324
|
+
description: "Default working directory for commands"
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
createSandbox: ({ id, token, env, timeout, workingDirectory }) => new SpritesSandbox({
|
|
329
|
+
id,
|
|
330
|
+
token,
|
|
331
|
+
env,
|
|
332
|
+
timeout,
|
|
333
|
+
workingDirectory
|
|
334
|
+
})
|
|
335
|
+
};
|
|
336
|
+
//#endregion
|
|
337
|
+
exports.SpritesProcessManager = SpritesProcessManager;
|
|
338
|
+
exports.SpritesSandbox = SpritesSandbox;
|
|
339
|
+
exports.spritesSandboxProvider = spritesSandboxProvider;
|
|
340
|
+
|
|
341
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["ProcessHandle","SandboxProcessManager","MastraSandbox","SandboxNotReadyError","SpritesClient","APIError"],"sources":["../src/sandbox/process-manager.ts","../src/sandbox/index.ts","../src/provider.ts"],"sourcesContent":["/**\n * Sprites Process Manager\n *\n * Runs each spawned command as its own `SpriteCommand` (a WebSocket exec\n * session on the Sprite) and streams stdout/stderr into the core\n * `ProcessHandle` buffers as chunks arrive.\n */\n\nimport type { SpriteCommand } from '@fly/sprites';\nimport type { CommandResult, ProcessInfo, SpawnProcessOptions } from '@mastra/core/workspace';\nimport { ProcessHandle, SandboxProcessManager } from '@mastra/core/workspace';\nimport type { SpritesSandbox } from './index';\n\nexport const LOG_PREFIX = '[SpritesSandbox]';\n\n/** Exit code reported for processes terminated by `kill()` or a timeout. */\nconst KILLED_EXIT_CODE = 137;\n\nclass SpritesProcessHandle extends ProcessHandle {\n readonly pid: string;\n\n private readonly _cmd: SpriteCommand;\n private readonly _startTime = Date.now();\n private readonly _done: Promise<void>;\n private _exitCode: number | undefined;\n private _killed = false;\n private _timedOut = false;\n private _timeoutId: ReturnType<typeof setTimeout> | undefined;\n private _error: Error | undefined;\n\n constructor(pid: string, cmd: SpriteCommand, options: SpawnProcessOptions, timeout: number | undefined) {\n super(options);\n this.pid = pid;\n this._cmd = cmd;\n\n cmd.stdout.setEncoding('utf8');\n cmd.stderr.setEncoding('utf8');\n cmd.stdout.on('data', (chunk: string) => this.emitStdout(chunk));\n cmd.stderr.on('data', (chunk: string) => this.emitStderr(chunk));\n // SpriteCommand is an EventEmitter: an unhandled 'error' would crash the process.\n cmd.on('error', (error: Error) => {\n this._error ??= error;\n });\n\n // Output streams end right after the exit frame, so waiting for both\n // guarantees every chunk has been emitted before the exit code is published.\n this._done = Promise.all([cmd.wait(), streamEnded(cmd.stdout), streamEnded(cmd.stderr)]).then(([code]) => {\n clearTimeout(this._timeoutId);\n this._exitCode = this._killed ? KILLED_EXIT_CODE : code < 0 ? 1 : code;\n });\n\n if (timeout !== undefined && timeout > 0) {\n this._timeoutId = setTimeout(() => {\n this._timedOut = true;\n void this.kill();\n }, timeout);\n }\n }\n\n get exitCode(): number | undefined {\n return this._exitCode;\n }\n\n async wait(): Promise<CommandResult> {\n await this._done;\n const exitCode = this._exitCode!;\n let stderr = this.stderr;\n if (exitCode !== 0 && !stderr && this._error && !this._killed) {\n stderr = this._error.message;\n }\n return {\n success: exitCode === 0,\n exitCode,\n stdout: this.stdout,\n stderr,\n executionTimeMs: Date.now() - this._startTime,\n ...(this._killed && { killed: true }),\n ...(this._timedOut && { timedOut: true }),\n };\n }\n\n async kill(): Promise<boolean> {\n if (this._exitCode !== undefined || this._killed) return false;\n this._killed = true;\n clearTimeout(this._timeoutId);\n // Signal the remote process, then drop the connection. Closing the\n // (non-detachable) exec session makes the server reap the process even if\n // the signal could not be delivered.\n this._cmd.kill('SIGKILL');\n this._cmd.close();\n return true;\n }\n\n async sendStdin(data: string): Promise<void> {\n if (this._exitCode !== undefined) {\n throw new Error(`${LOG_PREFIX} Cannot write to stdin: process ${this.pid} has exited`);\n }\n await new Promise<void>((resolve, reject) => {\n this._cmd.stdin.write(data, error => (error ? reject(error) : resolve()));\n });\n }\n\n async closeStdin(): Promise<void> {\n this._cmd.stdin.end();\n }\n}\n\nexport class SpritesProcessManager extends SandboxProcessManager<SpritesSandbox> {\n private _spawnCounter = 0;\n\n async spawn(command: string, options: SpawnProcessOptions = {}): Promise<ProcessHandle> {\n // The base spawn wrapper has already merged the sandbox env into options.env.\n const env = Object.fromEntries(\n Object.entries(options.env ?? {}).filter((entry): entry is [string, string] => entry[1] !== undefined),\n );\n const cwd = options.cwd ?? this.sandbox.workingDirectory;\n\n const cmd = this.sandbox.sprite.spawn('sh', ['-c', command], {\n ...(cwd && { cwd }),\n ...(Object.keys(env).length > 0 && { env }),\n });\n try {\n await waitForSpawn(cmd);\n } catch (error) {\n // Drop any half-opened exec connection so failed spawns don't leak sockets.\n cmd.close();\n throw error;\n }\n\n if (options.stdinMode === 'ignore') {\n cmd.stdin.end();\n }\n\n const pid = `sprites-proc-${Date.now().toString(36)}-${(++this._spawnCounter).toString(36)}`;\n const handle = new SpritesProcessHandle(pid, cmd, options, options.timeout ?? this.sandbox.defaultTimeout);\n this._tracked.set(pid, handle);\n return handle;\n }\n\n /**\n * Lists processes spawned by this instance. The Sprites exec API has no\n * listing for non-detachable commands, so processes started elsewhere are\n * not included.\n */\n async list(): Promise<ProcessInfo[]> {\n return [...this._tracked.values()].map(handle => ({\n pid: handle.pid,\n command: handle.command,\n running: handle.exitCode === undefined,\n ...(handle.exitCode !== undefined && { exitCode: handle.exitCode }),\n }));\n }\n\n /** Kill every running process spawned by this instance. Does not start the sandbox. */\n async killAll(): Promise<void> {\n const running = [...this._tracked.values()].filter(handle => handle.exitCode === undefined);\n await Promise.all(running.map(handle => this.kill(handle.pid)));\n }\n}\n\nfunction waitForSpawn(cmd: SpriteCommand): Promise<void> {\n return new Promise((resolve, reject) => {\n const onSpawn = () => {\n cmd.off('error', onError);\n resolve();\n };\n const onError = (error: Error) => {\n cmd.off('spawn', onSpawn);\n reject(error);\n };\n cmd.once('spawn', onSpawn);\n cmd.once('error', onError);\n });\n}\n\nfunction streamEnded(stream: NodeJS.ReadableStream): Promise<void> {\n return new Promise(resolve => {\n stream.once('end', () => resolve());\n stream.once('close', () => resolve());\n });\n}\n","/**\n * Fly.io Sprites Sandbox Provider\n *\n * A Sprites sandbox implementation for Mastra workspaces. Gets or creates a\n * persistent Fly.io Sprite by name and runs commands in it through the\n * official `@fly/sprites` SDK. Sprites keep their filesystem between runs and\n * hibernate on their own when idle.\n *\n * @see https://sprites.dev\n */\n\nimport { APIError, SpritesClient } from '@fly/sprites';\nimport type { Sprite, SpriteConfig } from '@fly/sprites';\nimport type {\n InstructionsOption,\n MastraSandboxOptions,\n ProviderStatus,\n SandboxInfo,\n SandboxStartResult,\n} from '@mastra/core/workspace';\nimport { MastraSandbox, SandboxNotReadyError } from '@mastra/core/workspace';\nimport { LOG_PREFIX, SpritesProcessManager } from './process-manager';\n\nexport interface SpritesSandboxOptions extends Omit<MastraSandboxOptions, 'processes'> {\n /**\n * Sprite name, also used as the sandbox id. An existing Sprite with this\n * name is reused (including its filesystem); otherwise one is created.\n * Generated when omitted.\n */\n id?: string;\n /** Sprites API token. Falls back to the `SPRITES_TOKEN` environment variable. */\n token?: string;\n /** Sprites API base URL. Defaults to the SDK default (`https://api.sprites.dev`). */\n baseURL?: string;\n /** Machine configuration applied only when the Sprite is created. */\n spriteConfig?: SpriteConfig;\n /** Default command timeout in milliseconds. Per-command `timeout` wins. */\n timeout?: number;\n /** Override or extend the default agent instructions for this sandbox. */\n instructions?: InstructionsOption;\n}\n\nexport class SpritesSandbox extends MastraSandbox {\n readonly id: string;\n readonly name = 'SpritesSandbox';\n readonly provider = 'sprites';\n status: ProviderStatus = 'pending';\n\n declare readonly processes: SpritesProcessManager;\n\n private _client: SpritesClient | null = null;\n private _sprite: Sprite | null = null;\n private _createdAt: Date | null = null;\n private readonly _token?: string;\n private readonly _baseURL?: string;\n private readonly _spriteConfig?: SpriteConfig;\n private readonly _timeout?: number;\n private readonly _instructionsOverride?: InstructionsOption;\n\n constructor(options: SpritesSandboxOptions = {}) {\n super({ ...options, name: 'SpritesSandbox', processes: new SpritesProcessManager() });\n\n this.id = options.id ?? `mastra-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;\n this._token = options.token ?? process.env.SPRITES_TOKEN;\n this._baseURL = options.baseURL;\n this._spriteConfig = options.spriteConfig;\n this._timeout = options.timeout;\n this._instructionsOverride = options.instructions;\n }\n\n /** The underlying SDK `Sprite`. Throws if the sandbox has not been started. */\n get sprite(): Sprite {\n if (!this._sprite) {\n throw new SandboxNotReadyError(this.id);\n }\n return this._sprite;\n }\n\n /** Default command timeout in milliseconds, if configured. */\n get defaultTimeout(): number | undefined {\n return this._timeout;\n }\n\n private get client(): SpritesClient {\n if (!this._client) {\n if (!this._token) {\n throw new Error(\n `${LOG_PREFIX} Missing Sprites API token. Pass \\`token\\` or set the SPRITES_TOKEN environment variable.`,\n );\n }\n this._client = new SpritesClient(this._token, this._baseURL ? { baseURL: this._baseURL } : undefined);\n }\n return this._client;\n }\n\n // ---------------------------------------------------------------------------\n // Lifecycle\n // ---------------------------------------------------------------------------\n\n /**\n * Get the Sprite named `id`, creating it when it does not exist.\n * Reports `outcome: 'created'` only when a new Sprite was provisioned.\n */\n async start(): Promise<SandboxStartResult> {\n if (this._sprite) {\n return { outcome: 'connected' };\n }\n\n const client = this.client;\n let outcome: SandboxStartResult['outcome'] = 'connected';\n let sprite: Sprite;\n\n try {\n sprite = await client.getSprite(this.id);\n } catch (error) {\n if (!isStatus(error, 404)) throw error;\n try {\n sprite = await client.createSprite(this.id, this._spriteConfig);\n outcome = 'created';\n } catch (createError) {\n // Another process created the same Sprite between our get and create.\n if (!isStatus(createError, 409)) throw createError;\n sprite = await client.getSprite(this.id);\n }\n }\n\n this._sprite = sprite;\n this._createdAt = sprite.createdAt ?? new Date();\n this.logger.debug(`${LOG_PREFIX} Sprite ready`, { id: this.id, outcome });\n return { outcome };\n }\n\n /**\n * Release local resources: kill background processes started by this\n * instance and close the SDK control connection.\n *\n * The Sprite itself is NOT deleted or suspended. Sprites hibernate on their\n * own when idle, and `start()` reconnects to the same filesystem.\n */\n async stop(): Promise<void> {\n await this._killTrackedProcesses();\n this._sprite?.closeControlConnection();\n this._sprite = null;\n }\n\n /**\n * Permanently delete the Sprite and its filesystem. A Sprite that no longer\n * exists is treated as already destroyed.\n */\n async destroy(): Promise<void> {\n await this._killTrackedProcesses();\n const sprite = this._sprite ?? this.client.sprite(this.id);\n sprite.closeControlConnection();\n this._sprite = null;\n\n try {\n await sprite.delete();\n } catch (error) {\n if (!isStatus(error, 404)) throw error;\n }\n }\n\n /**\n * Capture a checkpoint of the Sprite's current state.\n *\n * Checkpoints live inside this Sprite only and cannot seed other sandboxes,\n * so `supportsCheckpoints` stays `false`.\n */\n async snapshot(): Promise<void> {\n await this.ensureRunning();\n const stream = await this.sprite.createCheckpoint('mastra snapshot');\n await stream.processAll(message => {\n if (message.type === 'error') {\n throw new Error(`${LOG_PREFIX} Checkpoint failed: ${message.error ?? message.data ?? 'unknown error'}`);\n }\n });\n }\n\n private async _killTrackedProcesses(): Promise<void> {\n await this.processes.killAll().catch(error => {\n this.logger.warn(`${LOG_PREFIX} Failed to kill background processes`, { error });\n });\n }\n\n // ---------------------------------------------------------------------------\n // Info & Instructions\n // ---------------------------------------------------------------------------\n\n async getInfo(): Promise<SandboxInfo> {\n const sprite = this._sprite;\n return {\n id: this.id,\n name: this.name,\n provider: this.provider,\n status: this.status,\n createdAt: this._createdAt ?? new Date(),\n metadata: {\n ...(sprite && {\n ...(sprite.id && { spriteId: sprite.id }),\n ...(sprite.status && { spriteStatus: sprite.status }),\n ...(sprite.url && { url: sprite.url }),\n ...(sprite.primaryRegion && { region: sprite.primaryRegion }),\n }),\n },\n };\n }\n\n getInstructions(): string {\n const defaultInstructions = this._buildDefaultInstructions();\n\n if (typeof this._instructionsOverride === 'string') {\n return this._instructionsOverride;\n }\n if (typeof this._instructionsOverride === 'function') {\n return this._instructionsOverride({ defaultInstructions });\n }\n return defaultInstructions;\n }\n\n private _buildDefaultInstructions(): string {\n const parts = [\n 'Fly.io Sprite: a persistent Linux VM. Files written to disk survive between sessions.',\n this.workingDirectory\n ? `Commands run in ${this.workingDirectory} by default.`\n : 'Commands run in the Sprite user home directory by default.',\n ];\n if (this._timeout !== undefined) {\n parts.push(`Default command timeout: ${Math.ceil(this._timeout / 1000)}s.`);\n }\n return parts.join(' ');\n }\n}\n\nfunction isStatus(error: unknown, statusCode: number): boolean {\n return error instanceof APIError && error.statusCode === statusCode;\n}\n","/**\n * Fly.io Sprites sandbox provider descriptor for MastraEditor.\n *\n * @example\n * ```typescript\n * import { spritesSandboxProvider } from '@mastra/sprites';\n *\n * const editor = new MastraEditor({\n * sandboxes: { [spritesSandboxProvider.id]: spritesSandboxProvider },\n * });\n * ```\n */\nimport type { SandboxProvider } from '@mastra/core/editor';\nimport { SpritesSandbox } from './sandbox';\n\n/**\n * Serializable subset of SpritesSandboxOptions for editor storage.\n *\n * `baseURL` is deliberately excluded: the sandbox falls back to the server's\n * SPRITES_TOKEN, so a stored API host could redirect that token elsewhere.\n */\ninterface SpritesProviderConfig {\n id?: string;\n token?: string;\n env?: Record<string, string>;\n timeout?: number;\n workingDirectory?: string;\n}\n\nexport const spritesSandboxProvider: SandboxProvider<SpritesProviderConfig> = {\n id: 'sprites',\n name: 'Fly.io Sprites',\n description: 'Persistent Linux VM powered by Fly.io Sprites',\n configSchema: {\n type: 'object',\n properties: {\n id: { type: 'string', description: 'Sprite name. An existing Sprite with this name is reused.' },\n token: { type: 'string', description: 'Sprites API token (falls back to SPRITES_TOKEN)' },\n env: {\n type: 'object',\n description: 'Environment variables',\n additionalProperties: { type: 'string' },\n },\n timeout: { type: 'number', description: 'Default command timeout in ms' },\n workingDirectory: { type: 'string', description: 'Default working directory for commands' },\n },\n },\n // Pick known fields so extra stored keys (such as baseURL) never reach the sandbox.\n createSandbox: ({ id, token, env, timeout, workingDirectory }) =>\n new SpritesSandbox({ id, token, env, timeout, workingDirectory }),\n};\n"],"mappings":";;;;AAaA,MAAa,aAAa;;AAG1B,MAAM,mBAAmB;AAEzB,IAAM,uBAAN,cAAmCA,uBAAAA,cAAc;CAC/C;CAEA;CACA,aAA8B,KAAK,IAAI;CACvC;CACA;CACA,UAAkB;CAClB,YAAoB;CACpB;CACA;CAEA,YAAY,KAAa,KAAoB,SAA8B,SAA6B;EACtG,MAAM,OAAO;EACb,KAAK,MAAM;EACX,KAAK,OAAO;EAEZ,IAAI,OAAO,YAAY,MAAM;EAC7B,IAAI,OAAO,YAAY,MAAM;EAC7B,IAAI,OAAO,GAAG,SAAS,UAAkB,KAAK,WAAW,KAAK,CAAC;EAC/D,IAAI,OAAO,GAAG,SAAS,UAAkB,K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zC,4DACN;EACA,IAAI,KAAK,aAAa,KAAA,GACpB,MAAM,KAAK,4BAA4B,KAAK,KAAK,KAAK,WAAW,GAAI,EAAE,GAAG;EAE5E,OAAO,MAAM,KAAK,GAAG;CACvB;AACF;AAEA,SAAS,SAAS,OAAgB,YAA6B;CAC7D,OAAO,iBAAiBC,aAAAA,YAAY,MAAM,eAAe;AAC3D;;;AC9MA,MAAa,yBAAiE;CAC5E,IAAI;CACJ,MAAM;CACN,aAAa;CACb,cAAc;EACZ,MAAM;EACN,YAAY;GACV,IAAI;IAAE,MAAM;IAAU,aAAa;GAA4D;GAC/F,OAAO;IAAE,MAAM;IAAU,aAAa;GAAkD;GACxF,KAAK;IACH,MAAM;IACN,aAAa;IACb,sBAAsB,EAAE,MAAM,SAAS;GACzC;GACA,SAAS;IAAE,MAAM;IAAU,aAAa;GAAgC;GACxE,kBAAkB;IAAE,MAAM;IAAU,aAAa;GAAyC;EAC5F;CACF;CAEA,gBAAgB,EAAE,IAAI,OAAO,KAAK,SAAS,uBACzC,IAAI,eAAe;EAAE;EAAI;EAAO;EAAK;EAAS;CAAiB,CAAC;AACpE"}
|
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,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,WAAW,CAAC;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { APIError, SpritesClient } from "@fly/sprites";
|
|
2
|
+
import { MastraSandbox, ProcessHandle, SandboxNotReadyError, SandboxProcessManager } from "@mastra/core/workspace";
|
|
3
|
+
//#region src/sandbox/process-manager.ts
|
|
4
|
+
const LOG_PREFIX = "[SpritesSandbox]";
|
|
5
|
+
/** Exit code reported for processes terminated by `kill()` or a timeout. */
|
|
6
|
+
const KILLED_EXIT_CODE = 137;
|
|
7
|
+
var SpritesProcessHandle = class extends ProcessHandle {
|
|
8
|
+
pid;
|
|
9
|
+
_cmd;
|
|
10
|
+
_startTime = Date.now();
|
|
11
|
+
_done;
|
|
12
|
+
_exitCode;
|
|
13
|
+
_killed = false;
|
|
14
|
+
_timedOut = false;
|
|
15
|
+
_timeoutId;
|
|
16
|
+
_error;
|
|
17
|
+
constructor(pid, cmd, options, timeout) {
|
|
18
|
+
super(options);
|
|
19
|
+
this.pid = pid;
|
|
20
|
+
this._cmd = cmd;
|
|
21
|
+
cmd.stdout.setEncoding("utf8");
|
|
22
|
+
cmd.stderr.setEncoding("utf8");
|
|
23
|
+
cmd.stdout.on("data", (chunk) => this.emitStdout(chunk));
|
|
24
|
+
cmd.stderr.on("data", (chunk) => this.emitStderr(chunk));
|
|
25
|
+
cmd.on("error", (error) => {
|
|
26
|
+
this._error ??= error;
|
|
27
|
+
});
|
|
28
|
+
this._done = Promise.all([
|
|
29
|
+
cmd.wait(),
|
|
30
|
+
streamEnded(cmd.stdout),
|
|
31
|
+
streamEnded(cmd.stderr)
|
|
32
|
+
]).then(([code]) => {
|
|
33
|
+
clearTimeout(this._timeoutId);
|
|
34
|
+
this._exitCode = this._killed ? KILLED_EXIT_CODE : code < 0 ? 1 : code;
|
|
35
|
+
});
|
|
36
|
+
if (timeout !== void 0 && timeout > 0) this._timeoutId = setTimeout(() => {
|
|
37
|
+
this._timedOut = true;
|
|
38
|
+
this.kill();
|
|
39
|
+
}, timeout);
|
|
40
|
+
}
|
|
41
|
+
get exitCode() {
|
|
42
|
+
return this._exitCode;
|
|
43
|
+
}
|
|
44
|
+
async wait() {
|
|
45
|
+
await this._done;
|
|
46
|
+
const exitCode = this._exitCode;
|
|
47
|
+
let stderr = this.stderr;
|
|
48
|
+
if (exitCode !== 0 && !stderr && this._error && !this._killed) stderr = this._error.message;
|
|
49
|
+
return {
|
|
50
|
+
success: exitCode === 0,
|
|
51
|
+
exitCode,
|
|
52
|
+
stdout: this.stdout,
|
|
53
|
+
stderr,
|
|
54
|
+
executionTimeMs: Date.now() - this._startTime,
|
|
55
|
+
...this._killed && { killed: true },
|
|
56
|
+
...this._timedOut && { timedOut: true }
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
async kill() {
|
|
60
|
+
if (this._exitCode !== void 0 || this._killed) return false;
|
|
61
|
+
this._killed = true;
|
|
62
|
+
clearTimeout(this._timeoutId);
|
|
63
|
+
this._cmd.kill("SIGKILL");
|
|
64
|
+
this._cmd.close();
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
async sendStdin(data) {
|
|
68
|
+
if (this._exitCode !== void 0) throw new Error(`${LOG_PREFIX} Cannot write to stdin: process ${this.pid} has exited`);
|
|
69
|
+
await new Promise((resolve, reject) => {
|
|
70
|
+
this._cmd.stdin.write(data, (error) => error ? reject(error) : resolve());
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
async closeStdin() {
|
|
74
|
+
this._cmd.stdin.end();
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
var SpritesProcessManager = class extends SandboxProcessManager {
|
|
78
|
+
_spawnCounter = 0;
|
|
79
|
+
async spawn(command, options = {}) {
|
|
80
|
+
const env = Object.fromEntries(Object.entries(options.env ?? {}).filter((entry) => entry[1] !== void 0));
|
|
81
|
+
const cwd = options.cwd ?? this.sandbox.workingDirectory;
|
|
82
|
+
const cmd = this.sandbox.sprite.spawn("sh", ["-c", command], {
|
|
83
|
+
...cwd && { cwd },
|
|
84
|
+
...Object.keys(env).length > 0 && { env }
|
|
85
|
+
});
|
|
86
|
+
try {
|
|
87
|
+
await waitForSpawn(cmd);
|
|
88
|
+
} catch (error) {
|
|
89
|
+
cmd.close();
|
|
90
|
+
throw error;
|
|
91
|
+
}
|
|
92
|
+
if (options.stdinMode === "ignore") cmd.stdin.end();
|
|
93
|
+
const pid = `sprites-proc-${Date.now().toString(36)}-${(++this._spawnCounter).toString(36)}`;
|
|
94
|
+
const handle = new SpritesProcessHandle(pid, cmd, options, options.timeout ?? this.sandbox.defaultTimeout);
|
|
95
|
+
this._tracked.set(pid, handle);
|
|
96
|
+
return handle;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Lists processes spawned by this instance. The Sprites exec API has no
|
|
100
|
+
* listing for non-detachable commands, so processes started elsewhere are
|
|
101
|
+
* not included.
|
|
102
|
+
*/
|
|
103
|
+
async list() {
|
|
104
|
+
return [...this._tracked.values()].map((handle) => ({
|
|
105
|
+
pid: handle.pid,
|
|
106
|
+
command: handle.command,
|
|
107
|
+
running: handle.exitCode === void 0,
|
|
108
|
+
...handle.exitCode !== void 0 && { exitCode: handle.exitCode }
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
/** Kill every running process spawned by this instance. Does not start the sandbox. */
|
|
112
|
+
async killAll() {
|
|
113
|
+
const running = [...this._tracked.values()].filter((handle) => handle.exitCode === void 0);
|
|
114
|
+
await Promise.all(running.map((handle) => this.kill(handle.pid)));
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
function waitForSpawn(cmd) {
|
|
118
|
+
return new Promise((resolve, reject) => {
|
|
119
|
+
const onSpawn = () => {
|
|
120
|
+
cmd.off("error", onError);
|
|
121
|
+
resolve();
|
|
122
|
+
};
|
|
123
|
+
const onError = (error) => {
|
|
124
|
+
cmd.off("spawn", onSpawn);
|
|
125
|
+
reject(error);
|
|
126
|
+
};
|
|
127
|
+
cmd.once("spawn", onSpawn);
|
|
128
|
+
cmd.once("error", onError);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
function streamEnded(stream) {
|
|
132
|
+
return new Promise((resolve) => {
|
|
133
|
+
stream.once("end", () => resolve());
|
|
134
|
+
stream.once("close", () => resolve());
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/sandbox/index.ts
|
|
139
|
+
/**
|
|
140
|
+
* Fly.io Sprites Sandbox Provider
|
|
141
|
+
*
|
|
142
|
+
* A Sprites sandbox implementation for Mastra workspaces. Gets or creates a
|
|
143
|
+
* persistent Fly.io Sprite by name and runs commands in it through the
|
|
144
|
+
* official `@fly/sprites` SDK. Sprites keep their filesystem between runs and
|
|
145
|
+
* hibernate on their own when idle.
|
|
146
|
+
*
|
|
147
|
+
* @see https://sprites.dev
|
|
148
|
+
*/
|
|
149
|
+
var SpritesSandbox = class extends MastraSandbox {
|
|
150
|
+
id;
|
|
151
|
+
name = "SpritesSandbox";
|
|
152
|
+
provider = "sprites";
|
|
153
|
+
status = "pending";
|
|
154
|
+
_client = null;
|
|
155
|
+
_sprite = null;
|
|
156
|
+
_createdAt = null;
|
|
157
|
+
_token;
|
|
158
|
+
_baseURL;
|
|
159
|
+
_spriteConfig;
|
|
160
|
+
_timeout;
|
|
161
|
+
_instructionsOverride;
|
|
162
|
+
constructor(options = {}) {
|
|
163
|
+
super({
|
|
164
|
+
...options,
|
|
165
|
+
name: "SpritesSandbox",
|
|
166
|
+
processes: new SpritesProcessManager()
|
|
167
|
+
});
|
|
168
|
+
this.id = options.id ?? `mastra-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
169
|
+
this._token = options.token ?? process.env.SPRITES_TOKEN;
|
|
170
|
+
this._baseURL = options.baseURL;
|
|
171
|
+
this._spriteConfig = options.spriteConfig;
|
|
172
|
+
this._timeout = options.timeout;
|
|
173
|
+
this._instructionsOverride = options.instructions;
|
|
174
|
+
}
|
|
175
|
+
/** The underlying SDK `Sprite`. Throws if the sandbox has not been started. */
|
|
176
|
+
get sprite() {
|
|
177
|
+
if (!this._sprite) throw new SandboxNotReadyError(this.id);
|
|
178
|
+
return this._sprite;
|
|
179
|
+
}
|
|
180
|
+
/** Default command timeout in milliseconds, if configured. */
|
|
181
|
+
get defaultTimeout() {
|
|
182
|
+
return this._timeout;
|
|
183
|
+
}
|
|
184
|
+
get client() {
|
|
185
|
+
if (!this._client) {
|
|
186
|
+
if (!this._token) throw new Error(`${LOG_PREFIX} Missing Sprites API token. Pass \`token\` or set the SPRITES_TOKEN environment variable.`);
|
|
187
|
+
this._client = new SpritesClient(this._token, this._baseURL ? { baseURL: this._baseURL } : void 0);
|
|
188
|
+
}
|
|
189
|
+
return this._client;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Get the Sprite named `id`, creating it when it does not exist.
|
|
193
|
+
* Reports `outcome: 'created'` only when a new Sprite was provisioned.
|
|
194
|
+
*/
|
|
195
|
+
async start() {
|
|
196
|
+
if (this._sprite) return { outcome: "connected" };
|
|
197
|
+
const client = this.client;
|
|
198
|
+
let outcome = "connected";
|
|
199
|
+
let sprite;
|
|
200
|
+
try {
|
|
201
|
+
sprite = await client.getSprite(this.id);
|
|
202
|
+
} catch (error) {
|
|
203
|
+
if (!isStatus(error, 404)) throw error;
|
|
204
|
+
try {
|
|
205
|
+
sprite = await client.createSprite(this.id, this._spriteConfig);
|
|
206
|
+
outcome = "created";
|
|
207
|
+
} catch (createError) {
|
|
208
|
+
if (!isStatus(createError, 409)) throw createError;
|
|
209
|
+
sprite = await client.getSprite(this.id);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
this._sprite = sprite;
|
|
213
|
+
this._createdAt = sprite.createdAt ?? /* @__PURE__ */ new Date();
|
|
214
|
+
this.logger.debug(`${LOG_PREFIX} Sprite ready`, {
|
|
215
|
+
id: this.id,
|
|
216
|
+
outcome
|
|
217
|
+
});
|
|
218
|
+
return { outcome };
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Release local resources: kill background processes started by this
|
|
222
|
+
* instance and close the SDK control connection.
|
|
223
|
+
*
|
|
224
|
+
* The Sprite itself is NOT deleted or suspended. Sprites hibernate on their
|
|
225
|
+
* own when idle, and `start()` reconnects to the same filesystem.
|
|
226
|
+
*/
|
|
227
|
+
async stop() {
|
|
228
|
+
await this._killTrackedProcesses();
|
|
229
|
+
this._sprite?.closeControlConnection();
|
|
230
|
+
this._sprite = null;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Permanently delete the Sprite and its filesystem. A Sprite that no longer
|
|
234
|
+
* exists is treated as already destroyed.
|
|
235
|
+
*/
|
|
236
|
+
async destroy() {
|
|
237
|
+
await this._killTrackedProcesses();
|
|
238
|
+
const sprite = this._sprite ?? this.client.sprite(this.id);
|
|
239
|
+
sprite.closeControlConnection();
|
|
240
|
+
this._sprite = null;
|
|
241
|
+
try {
|
|
242
|
+
await sprite.delete();
|
|
243
|
+
} catch (error) {
|
|
244
|
+
if (!isStatus(error, 404)) throw error;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Capture a checkpoint of the Sprite's current state.
|
|
249
|
+
*
|
|
250
|
+
* Checkpoints live inside this Sprite only and cannot seed other sandboxes,
|
|
251
|
+
* so `supportsCheckpoints` stays `false`.
|
|
252
|
+
*/
|
|
253
|
+
async snapshot() {
|
|
254
|
+
await this.ensureRunning();
|
|
255
|
+
await (await this.sprite.createCheckpoint("mastra snapshot")).processAll((message) => {
|
|
256
|
+
if (message.type === "error") throw new Error(`${LOG_PREFIX} Checkpoint failed: ${message.error ?? message.data ?? "unknown error"}`);
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
async _killTrackedProcesses() {
|
|
260
|
+
await this.processes.killAll().catch((error) => {
|
|
261
|
+
this.logger.warn(`${LOG_PREFIX} Failed to kill background processes`, { error });
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
async getInfo() {
|
|
265
|
+
const sprite = this._sprite;
|
|
266
|
+
return {
|
|
267
|
+
id: this.id,
|
|
268
|
+
name: this.name,
|
|
269
|
+
provider: this.provider,
|
|
270
|
+
status: this.status,
|
|
271
|
+
createdAt: this._createdAt ?? /* @__PURE__ */ new Date(),
|
|
272
|
+
metadata: { ...sprite && {
|
|
273
|
+
...sprite.id && { spriteId: sprite.id },
|
|
274
|
+
...sprite.status && { spriteStatus: sprite.status },
|
|
275
|
+
...sprite.url && { url: sprite.url },
|
|
276
|
+
...sprite.primaryRegion && { region: sprite.primaryRegion }
|
|
277
|
+
} }
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
getInstructions() {
|
|
281
|
+
const defaultInstructions = this._buildDefaultInstructions();
|
|
282
|
+
if (typeof this._instructionsOverride === "string") return this._instructionsOverride;
|
|
283
|
+
if (typeof this._instructionsOverride === "function") return this._instructionsOverride({ defaultInstructions });
|
|
284
|
+
return defaultInstructions;
|
|
285
|
+
}
|
|
286
|
+
_buildDefaultInstructions() {
|
|
287
|
+
const parts = ["Fly.io Sprite: a persistent Linux VM. Files written to disk survive between sessions.", this.workingDirectory ? `Commands run in ${this.workingDirectory} by default.` : "Commands run in the Sprite user home directory by default."];
|
|
288
|
+
if (this._timeout !== void 0) parts.push(`Default command timeout: ${Math.ceil(this._timeout / 1e3)}s.`);
|
|
289
|
+
return parts.join(" ");
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
function isStatus(error, statusCode) {
|
|
293
|
+
return error instanceof APIError && error.statusCode === statusCode;
|
|
294
|
+
}
|
|
295
|
+
//#endregion
|
|
296
|
+
//#region src/provider.ts
|
|
297
|
+
const spritesSandboxProvider = {
|
|
298
|
+
id: "sprites",
|
|
299
|
+
name: "Fly.io Sprites",
|
|
300
|
+
description: "Persistent Linux VM powered by Fly.io Sprites",
|
|
301
|
+
configSchema: {
|
|
302
|
+
type: "object",
|
|
303
|
+
properties: {
|
|
304
|
+
id: {
|
|
305
|
+
type: "string",
|
|
306
|
+
description: "Sprite name. An existing Sprite with this name is reused."
|
|
307
|
+
},
|
|
308
|
+
token: {
|
|
309
|
+
type: "string",
|
|
310
|
+
description: "Sprites API token (falls back to SPRITES_TOKEN)"
|
|
311
|
+
},
|
|
312
|
+
env: {
|
|
313
|
+
type: "object",
|
|
314
|
+
description: "Environment variables",
|
|
315
|
+
additionalProperties: { type: "string" }
|
|
316
|
+
},
|
|
317
|
+
timeout: {
|
|
318
|
+
type: "number",
|
|
319
|
+
description: "Default command timeout in ms"
|
|
320
|
+
},
|
|
321
|
+
workingDirectory: {
|
|
322
|
+
type: "string",
|
|
323
|
+
description: "Default working directory for commands"
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
},
|
|
327
|
+
createSandbox: ({ id, token, env, timeout, workingDirectory }) => new SpritesSandbox({
|
|
328
|
+
id,
|
|
329
|
+
token,
|
|
330
|
+
env,
|
|
331
|
+
timeout,
|
|
332
|
+
workingDirectory
|
|
333
|
+
})
|
|
334
|
+
};
|
|
335
|
+
//#endregion
|
|
336
|
+
export { SpritesProcessManager, SpritesSandbox, spritesSandboxProvider };
|
|
337
|
+
|
|
338
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/sandbox/process-manager.ts","../src/sandbox/index.ts","../src/provider.ts"],"sourcesContent":["/**\n * Sprites Process Manager\n *\n * Runs each spawned command as its own `SpriteCommand` (a WebSocket exec\n * session on the Sprite) and streams stdout/stderr into the core\n * `ProcessHandle` buffers as chunks arrive.\n */\n\nimport type { SpriteCommand } from '@fly/sprites';\nimport type { CommandResult, ProcessInfo, SpawnProcessOptions } from '@mastra/core/workspace';\nimport { ProcessHandle, SandboxProcessManager } from '@mastra/core/workspace';\nimport type { SpritesSandbox } from './index';\n\nexport const LOG_PREFIX = '[SpritesSandbox]';\n\n/** Exit code reported for processes terminated by `kill()` or a timeout. */\nconst KILLED_EXIT_CODE = 137;\n\nclass SpritesProcessHandle extends ProcessHandle {\n readonly pid: string;\n\n private readonly _cmd: SpriteCommand;\n private readonly _startTime = Date.now();\n private readonly _done: Promise<void>;\n private _exitCode: number | undefined;\n private _killed = false;\n private _timedOut = false;\n private _timeoutId: ReturnType<typeof setTimeout> | undefined;\n private _error: Error | undefined;\n\n constructor(pid: string, cmd: SpriteCommand, options: SpawnProcessOptions, timeout: number | undefined) {\n super(options);\n this.pid = pid;\n this._cmd = cmd;\n\n cmd.stdout.setEncoding('utf8');\n cmd.stderr.setEncoding('utf8');\n cmd.stdout.on('data', (chunk: string) => this.emitStdout(chunk));\n cmd.stderr.on('data', (chunk: string) => this.emitStderr(chunk));\n // SpriteCommand is an EventEmitter: an unhandled 'error' would crash the process.\n cmd.on('error', (error: Error) => {\n this._error ??= error;\n });\n\n // Output streams end right after the exit frame, so waiting for both\n // guarantees every chunk has been emitted before the exit code is published.\n this._done = Promise.all([cmd.wait(), streamEnded(cmd.stdout), streamEnded(cmd.stderr)]).then(([code]) => {\n clearTimeout(this._timeoutId);\n this._exitCode = this._killed ? KILLED_EXIT_CODE : code < 0 ? 1 : code;\n });\n\n if (timeout !== undefined && timeout > 0) {\n this._timeoutId = setTimeout(() => {\n this._timedOut = true;\n void this.kill();\n }, timeout);\n }\n }\n\n get exitCode(): number | undefined {\n return this._exitCode;\n }\n\n async wait(): Promise<CommandResult> {\n await this._done;\n const exitCode = this._exitCode!;\n let stderr = this.stderr;\n if (exitCode !== 0 && !stderr && this._error && !this._killed) {\n stderr = this._error.message;\n }\n return {\n success: exitCode === 0,\n exitCode,\n stdout: this.stdout,\n stderr,\n executionTimeMs: Date.now() - this._startTime,\n ...(this._killed && { killed: true }),\n ...(this._timedOut && { timedOut: true }),\n };\n }\n\n async kill(): Promise<boolean> {\n if (this._exitCode !== undefined || this._killed) return false;\n this._killed = true;\n clearTimeout(this._timeoutId);\n // Signal the remote process, then drop the connection. Closing the\n // (non-detachable) exec session makes the server reap the process even if\n // the signal could not be delivered.\n this._cmd.kill('SIGKILL');\n this._cmd.close();\n return true;\n }\n\n async sendStdin(data: string): Promise<void> {\n if (this._exitCode !== undefined) {\n throw new Error(`${LOG_PREFIX} Cannot write to stdin: process ${this.pid} has exited`);\n }\n await new Promise<void>((resolve, reject) => {\n this._cmd.stdin.write(data, error => (error ? reject(error) : resolve()));\n });\n }\n\n async closeStdin(): Promise<void> {\n this._cmd.stdin.end();\n }\n}\n\nexport class SpritesProcessManager extends SandboxProcessManager<SpritesSandbox> {\n private _spawnCounter = 0;\n\n async spawn(command: string, options: SpawnProcessOptions = {}): Promise<ProcessHandle> {\n // The base spawn wrapper has already merged the sandbox env into options.env.\n const env = Object.fromEntries(\n Object.entries(options.env ?? {}).filter((entry): entry is [string, string] => entry[1] !== undefined),\n );\n const cwd = options.cwd ?? this.sandbox.workingDirectory;\n\n const cmd = this.sandbox.sprite.spawn('sh', ['-c', command], {\n ...(cwd && { cwd }),\n ...(Object.keys(env).length > 0 && { env }),\n });\n try {\n await waitForSpawn(cmd);\n } catch (error) {\n // Drop any half-opened exec connection so failed spawns don't leak sockets.\n cmd.close();\n throw error;\n }\n\n if (options.stdinMode === 'ignore') {\n cmd.stdin.end();\n }\n\n const pid = `sprites-proc-${Date.now().toString(36)}-${(++this._spawnCounter).toString(36)}`;\n const handle = new SpritesProcessHandle(pid, cmd, options, options.timeout ?? this.sandbox.defaultTimeout);\n this._tracked.set(pid, handle);\n return handle;\n }\n\n /**\n * Lists processes spawned by this instance. The Sprites exec API has no\n * listing for non-detachable commands, so processes started elsewhere are\n * not included.\n */\n async list(): Promise<ProcessInfo[]> {\n return [...this._tracked.values()].map(handle => ({\n pid: handle.pid,\n command: handle.command,\n running: handle.exitCode === undefined,\n ...(handle.exitCode !== undefined && { exitCode: handle.exitCode }),\n }));\n }\n\n /** Kill every running process spawned by this instance. Does not start the sandbox. */\n async killAll(): Promise<void> {\n const running = [...this._tracked.values()].filter(handle => handle.exitCode === undefined);\n await Promise.all(running.map(handle => this.kill(handle.pid)));\n }\n}\n\nfunction waitForSpawn(cmd: SpriteCommand): Promise<void> {\n return new Promise((resolve, reject) => {\n const onSpawn = () => {\n cmd.off('error', onError);\n resolve();\n };\n const onError = (error: Error) => {\n cmd.off('spawn', onSpawn);\n reject(error);\n };\n cmd.once('spawn', onSpawn);\n cmd.once('error', onError);\n });\n}\n\nfunction streamEnded(stream: NodeJS.ReadableStream): Promise<void> {\n return new Promise(resolve => {\n stream.once('end', () => resolve());\n stream.once('close', () => resolve());\n });\n}\n","/**\n * Fly.io Sprites Sandbox Provider\n *\n * A Sprites sandbox implementation for Mastra workspaces. Gets or creates a\n * persistent Fly.io Sprite by name and runs commands in it through the\n * official `@fly/sprites` SDK. Sprites keep their filesystem between runs and\n * hibernate on their own when idle.\n *\n * @see https://sprites.dev\n */\n\nimport { APIError, SpritesClient } from '@fly/sprites';\nimport type { Sprite, SpriteConfig } from '@fly/sprites';\nimport type {\n InstructionsOption,\n MastraSandboxOptions,\n ProviderStatus,\n SandboxInfo,\n SandboxStartResult,\n} from '@mastra/core/workspace';\nimport { MastraSandbox, SandboxNotReadyError } from '@mastra/core/workspace';\nimport { LOG_PREFIX, SpritesProcessManager } from './process-manager';\n\nexport interface SpritesSandboxOptions extends Omit<MastraSandboxOptions, 'processes'> {\n /**\n * Sprite name, also used as the sandbox id. An existing Sprite with this\n * name is reused (including its filesystem); otherwise one is created.\n * Generated when omitted.\n */\n id?: string;\n /** Sprites API token. Falls back to the `SPRITES_TOKEN` environment variable. */\n token?: string;\n /** Sprites API base URL. Defaults to the SDK default (`https://api.sprites.dev`). */\n baseURL?: string;\n /** Machine configuration applied only when the Sprite is created. */\n spriteConfig?: SpriteConfig;\n /** Default command timeout in milliseconds. Per-command `timeout` wins. */\n timeout?: number;\n /** Override or extend the default agent instructions for this sandbox. */\n instructions?: InstructionsOption;\n}\n\nexport class SpritesSandbox extends MastraSandbox {\n readonly id: string;\n readonly name = 'SpritesSandbox';\n readonly provider = 'sprites';\n status: ProviderStatus = 'pending';\n\n declare readonly processes: SpritesProcessManager;\n\n private _client: SpritesClient | null = null;\n private _sprite: Sprite | null = null;\n private _createdAt: Date | null = null;\n private readonly _token?: string;\n private readonly _baseURL?: string;\n private readonly _spriteConfig?: SpriteConfig;\n private readonly _timeout?: number;\n private readonly _instructionsOverride?: InstructionsOption;\n\n constructor(options: SpritesSandboxOptions = {}) {\n super({ ...options, name: 'SpritesSandbox', processes: new SpritesProcessManager() });\n\n this.id = options.id ?? `mastra-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;\n this._token = options.token ?? process.env.SPRITES_TOKEN;\n this._baseURL = options.baseURL;\n this._spriteConfig = options.spriteConfig;\n this._timeout = options.timeout;\n this._instructionsOverride = options.instructions;\n }\n\n /** The underlying SDK `Sprite`. Throws if the sandbox has not been started. */\n get sprite(): Sprite {\n if (!this._sprite) {\n throw new SandboxNotReadyError(this.id);\n }\n return this._sprite;\n }\n\n /** Default command timeout in milliseconds, if configured. */\n get defaultTimeout(): number | undefined {\n return this._timeout;\n }\n\n private get client(): SpritesClient {\n if (!this._client) {\n if (!this._token) {\n throw new Error(\n `${LOG_PREFIX} Missing Sprites API token. Pass \\`token\\` or set the SPRITES_TOKEN environment variable.`,\n );\n }\n this._client = new SpritesClient(this._token, this._baseURL ? { baseURL: this._baseURL } : undefined);\n }\n return this._client;\n }\n\n // ---------------------------------------------------------------------------\n // Lifecycle\n // ---------------------------------------------------------------------------\n\n /**\n * Get the Sprite named `id`, creating it when it does not exist.\n * Reports `outcome: 'created'` only when a new Sprite was provisioned.\n */\n async start(): Promise<SandboxStartResult> {\n if (this._sprite) {\n return { outcome: 'connected' };\n }\n\n const client = this.client;\n let outcome: SandboxStartResult['outcome'] = 'connected';\n let sprite: Sprite;\n\n try {\n sprite = await client.getSprite(this.id);\n } catch (error) {\n if (!isStatus(error, 404)) throw error;\n try {\n sprite = await client.createSprite(this.id, this._spriteConfig);\n outcome = 'created';\n } catch (createError) {\n // Another process created the same Sprite between our get and create.\n if (!isStatus(createError, 409)) throw createError;\n sprite = await client.getSprite(this.id);\n }\n }\n\n this._sprite = sprite;\n this._createdAt = sprite.createdAt ?? new Date();\n this.logger.debug(`${LOG_PREFIX} Sprite ready`, { id: this.id, outcome });\n return { outcome };\n }\n\n /**\n * Release local resources: kill background processes started by this\n * instance and close the SDK control connection.\n *\n * The Sprite itself is NOT deleted or suspended. Sprites hibernate on their\n * own when idle, and `start()` reconnects to the same filesystem.\n */\n async stop(): Promise<void> {\n await this._killTrackedProcesses();\n this._sprite?.closeControlConnection();\n this._sprite = null;\n }\n\n /**\n * Permanently delete the Sprite and its filesystem. A Sprite that no longer\n * exists is treated as already destroyed.\n */\n async destroy(): Promise<void> {\n await this._killTrackedProcesses();\n const sprite = this._sprite ?? this.client.sprite(this.id);\n sprite.closeControlConnection();\n this._sprite = null;\n\n try {\n await sprite.delete();\n } catch (error) {\n if (!isStatus(error, 404)) throw error;\n }\n }\n\n /**\n * Capture a checkpoint of the Sprite's current state.\n *\n * Checkpoints live inside this Sprite only and cannot seed other sandboxes,\n * so `supportsCheckpoints` stays `false`.\n */\n async snapshot(): Promise<void> {\n await this.ensureRunning();\n const stream = await this.sprite.createCheckpoint('mastra snapshot');\n await stream.processAll(message => {\n if (message.type === 'error') {\n throw new Error(`${LOG_PREFIX} Checkpoint failed: ${message.error ?? message.data ?? 'unknown error'}`);\n }\n });\n }\n\n private async _killTrackedProcesses(): Promise<void> {\n await this.processes.killAll().catch(error => {\n this.logger.warn(`${LOG_PREFIX} Failed to kill background processes`, { error });\n });\n }\n\n // ---------------------------------------------------------------------------\n // Info & Instructions\n // ---------------------------------------------------------------------------\n\n async getInfo(): Promise<SandboxInfo> {\n const sprite = this._sprite;\n return {\n id: this.id,\n name: this.name,\n provider: this.provider,\n status: this.status,\n createdAt: this._createdAt ?? new Date(),\n metadata: {\n ...(sprite && {\n ...(sprite.id && { spriteId: sprite.id }),\n ...(sprite.status && { spriteStatus: sprite.status }),\n ...(sprite.url && { url: sprite.url }),\n ...(sprite.primaryRegion && { region: sprite.primaryRegion }),\n }),\n },\n };\n }\n\n getInstructions(): string {\n const defaultInstructions = this._buildDefaultInstructions();\n\n if (typeof this._instructionsOverride === 'string') {\n return this._instructionsOverride;\n }\n if (typeof this._instructionsOverride === 'function') {\n return this._instructionsOverride({ defaultInstructions });\n }\n return defaultInstructions;\n }\n\n private _buildDefaultInstructions(): string {\n const parts = [\n 'Fly.io Sprite: a persistent Linux VM. Files written to disk survive between sessions.',\n this.workingDirectory\n ? `Commands run in ${this.workingDirectory} by default.`\n : 'Commands run in the Sprite user home directory by default.',\n ];\n if (this._timeout !== undefined) {\n parts.push(`Default command timeout: ${Math.ceil(this._timeout / 1000)}s.`);\n }\n return parts.join(' ');\n }\n}\n\nfunction isStatus(error: unknown, statusCode: number): boolean {\n return error instanceof APIError && error.statusCode === statusCode;\n}\n","/**\n * Fly.io Sprites sandbox provider descriptor for MastraEditor.\n *\n * @example\n * ```typescript\n * import { spritesSandboxProvider } from '@mastra/sprites';\n *\n * const editor = new MastraEditor({\n * sandboxes: { [spritesSandboxProvider.id]: spritesSandboxProvider },\n * });\n * ```\n */\nimport type { SandboxProvider } from '@mastra/core/editor';\nimport { SpritesSandbox } from './sandbox';\n\n/**\n * Serializable subset of SpritesSandboxOptions for editor storage.\n *\n * `baseURL` is deliberately excluded: the sandbox falls back to the server's\n * SPRITES_TOKEN, so a stored API host could redirect that token elsewhere.\n */\ninterface SpritesProviderConfig {\n id?: string;\n token?: string;\n env?: Record<string, string>;\n timeout?: number;\n workingDirectory?: string;\n}\n\nexport const spritesSandboxProvider: SandboxProvider<SpritesProviderConfig> = {\n id: 'sprites',\n name: 'Fly.io Sprites',\n description: 'Persistent Linux VM powered by Fly.io Sprites',\n configSchema: {\n type: 'object',\n properties: {\n id: { type: 'string', description: 'Sprite name. An existing Sprite with this name is reused.' },\n token: { type: 'string', description: 'Sprites API token (falls back to SPRITES_TOKEN)' },\n env: {\n type: 'object',\n description: 'Environment variables',\n additionalProperties: { type: 'string' },\n },\n timeout: { type: 'number', description: 'Default command timeout in ms' },\n workingDirectory: { type: 'string', description: 'Default working directory for commands' },\n },\n },\n // Pick known fields so extra stored keys (such as baseURL) never reach the sandbox.\n createSandbox: ({ id, token, env, timeout, workingDirectory }) =>\n new SpritesSandbox({ id, token, env, timeout, workingDirectory }),\n};\n"],"mappings":";;;AAaA,MAAa,aA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IAAI;IACpC,GAAI,OAAO,iBAAiB,EAAE,QAAQ,OAAO,cAAc;GAC7D,EACF;EACF;CACF;CAEA,kBAA0B;EACxB,MAAM,sBAAsB,KAAK,0BAA0B;EAE3D,IAAI,OAAO,KAAK,0BAA0B,UACxC,OAAO,KAAK;EAEd,IAAI,OAAO,KAAK,0BAA0B,YACxC,OAAO,KAAK,sBAAsB,EAAE,oBAAoB,CAAC;EAE3D,OAAO;CACT;CAEA,4BAA4C;EAC1C,MAAM,QAAQ,CACZ,yFACA,KAAK,mBACD,mBAAmB,KAAK,iBAAiB,gBACzC,4DACN;EACA,IAAI,KAAK,aAAa,KAAA,GACpB,MAAM,KAAK,4BAA4B,KAAK,KAAK,KAAK,WAAW,GAAI,EAAE,GAAG;EAE5E,OAAO,MAAM,KAAK,GAAG;CACvB;AACF;AAEA,SAAS,SAAS,OAAgB,YAA6B;CAC7D,OAAO,iBAAiB,YAAY,MAAM,eAAe;AAC3D;;;AC9MA,MAAa,yBAAiE;CAC5E,IAAI;CACJ,MAAM;CACN,aAAa;CACb,cAAc;EACZ,MAAM;EACN,YAAY;GACV,IAAI;IAAE,MAAM;IAAU,aAAa;GAA4D;GAC/F,OAAO;IAAE,MAAM;IAAU,aAAa;GAAkD;GACxF,KAAK;IACH,MAAM;IACN,aAAa;IACb,sBAAsB,EAAE,MAAM,SAAS;GACzC;GACA,SAAS;IAAE,MAAM;IAAU,aAAa;GAAgC;GACxE,kBAAkB;IAAE,MAAM;IAAU,aAAa;GAAyC;EAC5F;CACF;CAEA,gBAAgB,EAAE,IAAI,OAAO,KAAK,SAAS,uBACzC,IAAI,eAAe;EAAE;EAAI;EAAO;EAAK;EAAS;CAAiB,CAAC;AACpE"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fly.io Sprites sandbox provider descriptor for MastraEditor.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* import { spritesSandboxProvider } from '@mastra/sprites';
|
|
7
|
+
*
|
|
8
|
+
* const editor = new MastraEditor({
|
|
9
|
+
* sandboxes: { [spritesSandboxProvider.id]: spritesSandboxProvider },
|
|
10
|
+
* });
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
import type { SandboxProvider } from '@mastra/core/editor';
|
|
14
|
+
/**
|
|
15
|
+
* Serializable subset of SpritesSandboxOptions for editor storage.
|
|
16
|
+
*
|
|
17
|
+
* `baseURL` is deliberately excluded: the sandbox falls back to the server's
|
|
18
|
+
* SPRITES_TOKEN, so a stored API host could redirect that token elsewhere.
|
|
19
|
+
*/
|
|
20
|
+
interface SpritesProviderConfig {
|
|
21
|
+
id?: string;
|
|
22
|
+
token?: string;
|
|
23
|
+
env?: Record<string, string>;
|
|
24
|
+
timeout?: number;
|
|
25
|
+
workingDirectory?: string;
|
|
26
|
+
}
|
|
27
|
+
export declare const spritesSandboxProvider: SandboxProvider<SpritesProviderConfig>;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAG3D;;;;;GAKG;AACH,UAAU,qBAAqB;IAC7B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,eAAO,MAAM,sBAAsB,EAAE,eAAe,CAAC,qBAAqB,CAqBzE,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fly.io Sprites Sandbox Provider
|
|
3
|
+
*
|
|
4
|
+
* A Sprites sandbox implementation for Mastra workspaces. Gets or creates a
|
|
5
|
+
* persistent Fly.io Sprite by name and runs commands in it through the
|
|
6
|
+
* official `@fly/sprites` SDK. Sprites keep their filesystem between runs and
|
|
7
|
+
* hibernate on their own when idle.
|
|
8
|
+
*
|
|
9
|
+
* @see https://sprites.dev
|
|
10
|
+
*/
|
|
11
|
+
import type { Sprite, SpriteConfig } from '@fly/sprites';
|
|
12
|
+
import type { InstructionsOption, MastraSandboxOptions, ProviderStatus, SandboxInfo, SandboxStartResult } from '@mastra/core/workspace';
|
|
13
|
+
import { MastraSandbox } from '@mastra/core/workspace';
|
|
14
|
+
import { SpritesProcessManager } from './process-manager.js';
|
|
15
|
+
export interface SpritesSandboxOptions extends Omit<MastraSandboxOptions, 'processes'> {
|
|
16
|
+
/**
|
|
17
|
+
* Sprite name, also used as the sandbox id. An existing Sprite with this
|
|
18
|
+
* name is reused (including its filesystem); otherwise one is created.
|
|
19
|
+
* Generated when omitted.
|
|
20
|
+
*/
|
|
21
|
+
id?: string;
|
|
22
|
+
/** Sprites API token. Falls back to the `SPRITES_TOKEN` environment variable. */
|
|
23
|
+
token?: string;
|
|
24
|
+
/** Sprites API base URL. Defaults to the SDK default (`https://api.sprites.dev`). */
|
|
25
|
+
baseURL?: string;
|
|
26
|
+
/** Machine configuration applied only when the Sprite is created. */
|
|
27
|
+
spriteConfig?: SpriteConfig;
|
|
28
|
+
/** Default command timeout in milliseconds. Per-command `timeout` wins. */
|
|
29
|
+
timeout?: number;
|
|
30
|
+
/** Override or extend the default agent instructions for this sandbox. */
|
|
31
|
+
instructions?: InstructionsOption;
|
|
32
|
+
}
|
|
33
|
+
export declare class SpritesSandbox extends MastraSandbox {
|
|
34
|
+
readonly id: string;
|
|
35
|
+
readonly name = "SpritesSandbox";
|
|
36
|
+
readonly provider = "sprites";
|
|
37
|
+
status: ProviderStatus;
|
|
38
|
+
readonly processes: SpritesProcessManager;
|
|
39
|
+
private _client;
|
|
40
|
+
private _sprite;
|
|
41
|
+
private _createdAt;
|
|
42
|
+
private readonly _token?;
|
|
43
|
+
private readonly _baseURL?;
|
|
44
|
+
private readonly _spriteConfig?;
|
|
45
|
+
private readonly _timeout?;
|
|
46
|
+
private readonly _instructionsOverride?;
|
|
47
|
+
constructor(options?: SpritesSandboxOptions);
|
|
48
|
+
/** The underlying SDK `Sprite`. Throws if the sandbox has not been started. */
|
|
49
|
+
get sprite(): Sprite;
|
|
50
|
+
/** Default command timeout in milliseconds, if configured. */
|
|
51
|
+
get defaultTimeout(): number | undefined;
|
|
52
|
+
private get client();
|
|
53
|
+
/**
|
|
54
|
+
* Get the Sprite named `id`, creating it when it does not exist.
|
|
55
|
+
* Reports `outcome: 'created'` only when a new Sprite was provisioned.
|
|
56
|
+
*/
|
|
57
|
+
start(): Promise<SandboxStartResult>;
|
|
58
|
+
/**
|
|
59
|
+
* Release local resources: kill background processes started by this
|
|
60
|
+
* instance and close the SDK control connection.
|
|
61
|
+
*
|
|
62
|
+
* The Sprite itself is NOT deleted or suspended. Sprites hibernate on their
|
|
63
|
+
* own when idle, and `start()` reconnects to the same filesystem.
|
|
64
|
+
*/
|
|
65
|
+
stop(): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Permanently delete the Sprite and its filesystem. A Sprite that no longer
|
|
68
|
+
* exists is treated as already destroyed.
|
|
69
|
+
*/
|
|
70
|
+
destroy(): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Capture a checkpoint of the Sprite's current state.
|
|
73
|
+
*
|
|
74
|
+
* Checkpoints live inside this Sprite only and cannot seed other sandboxes,
|
|
75
|
+
* so `supportsCheckpoints` stays `false`.
|
|
76
|
+
*/
|
|
77
|
+
snapshot(): Promise<void>;
|
|
78
|
+
private _killTrackedProcesses;
|
|
79
|
+
getInfo(): Promise<SandboxInfo>;
|
|
80
|
+
getInstructions(): string;
|
|
81
|
+
private _buildDefaultInstructions;
|
|
82
|
+
}
|
|
83
|
+
//# s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,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAe;IAC9C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAC,CAAqB;IAE5D,YAAY,OAAO,GAAE,qBAA0B,EAS9C;IAED,+EAA+E;IAC/E,IAAI,MAAM,IAAI,MAAM,CAKnB;IAED,8DAA8D;IAC9D,IAAI,cAAc,IAAI,MAAM,GAAG,SAAS,CAEvC;IAED,OAAO,KAAK,MAAM,GAUjB;IAMD;;;OAGG;IACG,KAAK,IAAI,OAAO,CAAC,kBAAkB,CAAC,CA2BzC;IAED;;;;;;OAMG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAI1B;IAED;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAW7B;IAED;;;;;OAKG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAQ9B;YAEa,qBAAqB;IAU7B,OAAO,IAAI,OAAO,CAAC,WAAW,CAAC,CAiBpC;IAED,eAAe,IAAI,MAAM,CAUxB;IAED,OAAO,CAAC,yBAAyB;CAYlC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sprites Process Manager
|
|
3
|
+
*
|
|
4
|
+
* Runs each spawned command as its own `SpriteCommand` (a WebSocket exec
|
|
5
|
+
* session on the Sprite) and streams stdout/stderr into the core
|
|
6
|
+
* `ProcessHandle` buffers as chunks arrive.
|
|
7
|
+
*/
|
|
8
|
+
import type { ProcessInfo, SpawnProcessOptions } from '@mastra/core/workspace';
|
|
9
|
+
import { ProcessHandle, SandboxProcessManager } from '@mastra/core/workspace';
|
|
10
|
+
import type { SpritesSandbox } from './index.js';
|
|
11
|
+
export declare const LOG_PREFIX = "[SpritesSandbox]";
|
|
12
|
+
export declare class SpritesProcessManager extends SandboxProcessManager<SpritesSandbox> {
|
|
13
|
+
private _spawnCounter;
|
|
14
|
+
spawn(command: string, options?: SpawnProcessOptions): Promise<ProcessHandle>;
|
|
15
|
+
/**
|
|
16
|
+
* Lists processes spawned by this instance. The Sprites exec API has no
|
|
17
|
+
* listing for non-detachable commands, so processes started elsewhere are
|
|
18
|
+
* not included.
|
|
19
|
+
*/
|
|
20
|
+
list(): Promise<ProcessInfo[]>;
|
|
21
|
+
/** Kill every running process spawned by this instance. Does not start the sandbox. */
|
|
22
|
+
killAll(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=process-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-manager.d.ts","sourceRoot":"","sources":["../../src/sandbox/process-manager.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAiB,WAAW,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC9F,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,eAAO,MAAM,UAAU,qBAAqB,CAAC;AA8F7C,qBAAa,qBAAsB,SAAQ,qBAAqB,CAAC,cAAc,CAAC;IAC9E,OAAO,CAAC,aAAa,CAAK;IAEpB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,aAAa,CAAC,CA2BtF;IAED;;;;OAIG;IACG,IAAI,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC,CAOnC;IAED,uFAAuF;IACjF,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAG7B;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,68 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/sprites",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0-alpha.0",
|
|
4
|
+
"description": "Fly.io Sprites sandbox provider for Mastra workspaces",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.cjs"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
21
|
+
"license": "Apache-2.0",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@fly/sprites": "^0.2.3"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/node": "22.20.1",
|
|
27
|
+
"@vitest/coverage-v8": "4.1.11",
|
|
28
|
+
"@vitest/ui": "4.1.11",
|
|
29
|
+
"dotenv": "^17.4.2",
|
|
30
|
+
"eslint": "^10.7.0",
|
|
31
|
+
"tsdown": "0.22.9",
|
|
32
|
+
"typescript": "^7.0.2",
|
|
33
|
+
"vitest": "4.1.11",
|
|
34
|
+
"@internal/types-builder": "0.0.116",
|
|
35
|
+
"@mastra/core": "1.76.0-alpha.9",
|
|
36
|
+
"@internal/workspace-test-utils": "0.0.85",
|
|
37
|
+
"@internal/lint": "0.0.141"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@mastra/core": ">=1.68.0-0 <2.0.0-0"
|
|
41
|
+
},
|
|
42
|
+
"files": [
|
|
43
|
+
"dist"
|
|
44
|
+
],
|
|
45
|
+
"homepage": "https://mastra.ai",
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "git+https://github.com/mastra-ai/mastra.git",
|
|
49
|
+
"directory": "workspaces/sprites"
|
|
50
|
+
},
|
|
51
|
+
"bugs": {
|
|
52
|
+
"url": "https://github.com/mastra-ai/mastra/issues"
|
|
53
|
+
},
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": ">=24.0.0"
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "tsdown --silent --config tsdown.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": "oxlint . && eslint .",
|
|
66
|
+
"lint:fix": "oxlint --fix . && eslint --fix ."
|
|
67
|
+
}
|
|
6
68
|
}
|