@mastra/sprites 0.1.1-alpha.0 → 0.1.2-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/dist/index.cjs +3 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -6
- package/dist/index.js.map +1 -1
- package/package.json +13 -14
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
let _fly_sprites = require("@fly/sprites");
|
|
3
3
|
let _mastra_core_workspace = require("@mastra/core/workspace");
|
|
4
|
-
|
|
4
|
+
// src/sandbox/process-manager.ts
|
|
5
5
|
const LOG_PREFIX = "[SpritesSandbox]";
|
|
6
6
|
/** Exit code reported for processes terminated by `kill()` or a timeout. */
|
|
7
7
|
const KILLED_EXIT_CODE = 137;
|
|
@@ -135,8 +135,7 @@ function streamEnded(stream) {
|
|
|
135
135
|
stream.once("close", () => resolve());
|
|
136
136
|
});
|
|
137
137
|
}
|
|
138
|
-
|
|
139
|
-
//#region src/sandbox/index.ts
|
|
138
|
+
// src/sandbox/index.ts
|
|
140
139
|
/**
|
|
141
140
|
* Fly.io Sprites Sandbox Provider
|
|
142
141
|
*
|
|
@@ -293,8 +292,7 @@ var SpritesSandbox = class extends _mastra_core_workspace.MastraSandbox {
|
|
|
293
292
|
function isStatus(error, statusCode) {
|
|
294
293
|
return error instanceof _fly_sprites.APIError && error.statusCode === statusCode;
|
|
295
294
|
}
|
|
296
|
-
|
|
297
|
-
//#region src/provider.ts
|
|
295
|
+
// src/provider.ts
|
|
298
296
|
const spritesSandboxProvider = {
|
|
299
297
|
id: "sprites",
|
|
300
298
|
name: "Fly.io Sprites",
|
|
@@ -333,7 +331,6 @@ const spritesSandboxProvider = {
|
|
|
333
331
|
workingDirectory
|
|
334
332
|
})
|
|
335
333
|
};
|
|
336
|
-
//#endregion
|
|
337
334
|
exports.SpritesProcessManager = SpritesProcessManager;
|
|
338
335
|
exports.SpritesSandbox = SpritesSandbox;
|
|
339
336
|
exports.spritesSandboxProvider = spritesSandboxProvider;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +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,IAA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;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,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"}
|
|
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,KAAK,WAAW,KAAK,CAAC;EAE/D,IAAI,GAAG,UAAU,UAAiB;GAChC,KAAK,WAAW;EAClB,CAAC;EAID,KAAK,QAAQ,QAAQ,IAAI;GAAC,IAAI,KAAK;GAAG,YAAY,IAAI,MAAM;GAAG,YAAY,IAAI,MAAM;EAAC,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU;GACxG,aAAa,KAAK,UAAU;GAC5B,KAAK,YAAY,KAAK,UAAU,mBAAmB,OAAO,IAAI,IAAI;EACpE,CAAC;EAED,IAAI,YAAY,KAAA,KAAa,UAAU,GACrC,KAAK,aAAa,iBAAiB;GACjC,KAAK,YAAY;GACjB,KAAU,KAAK;EACjB,GAAG,OAAO;CAEd;CAEA,IAAI,WAA+B;EACjC,OAAO,KAAK;CACd;CAE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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.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { APIError, SpritesClient } from "@fly/sprites";
|
|
2
2
|
import { MastraSandbox, ProcessHandle, SandboxNotReadyError, SandboxProcessManager } from "@mastra/core/workspace";
|
|
3
|
-
|
|
3
|
+
// src/sandbox/process-manager.ts
|
|
4
4
|
const LOG_PREFIX = "[SpritesSandbox]";
|
|
5
5
|
/** Exit code reported for processes terminated by `kill()` or a timeout. */
|
|
6
6
|
const KILLED_EXIT_CODE = 137;
|
|
@@ -134,8 +134,7 @@ function streamEnded(stream) {
|
|
|
134
134
|
stream.once("close", () => resolve());
|
|
135
135
|
});
|
|
136
136
|
}
|
|
137
|
-
|
|
138
|
-
//#region src/sandbox/index.ts
|
|
137
|
+
// src/sandbox/index.ts
|
|
139
138
|
/**
|
|
140
139
|
* Fly.io Sprites Sandbox Provider
|
|
141
140
|
*
|
|
@@ -292,8 +291,7 @@ var SpritesSandbox = class extends MastraSandbox {
|
|
|
292
291
|
function isStatus(error, statusCode) {
|
|
293
292
|
return error instanceof APIError && error.statusCode === statusCode;
|
|
294
293
|
}
|
|
295
|
-
|
|
296
|
-
//#region src/provider.ts
|
|
294
|
+
// src/provider.ts
|
|
297
295
|
const spritesSandboxProvider = {
|
|
298
296
|
id: "sprites",
|
|
299
297
|
name: "Fly.io Sprites",
|
|
@@ -332,7 +330,6 @@ const spritesSandboxProvider = {
|
|
|
332
330
|
workingDirectory
|
|
333
331
|
})
|
|
334
332
|
};
|
|
335
|
-
//#endregion
|
|
336
333
|
export { SpritesProcessManager, SpritesSandbox, spritesSandboxProvider };
|
|
337
334
|
|
|
338
335
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +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,aAAa;;AAG1B,MAAM,mBAAmB;AAEzB,IAAM,uBAAN,cAAmC,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,KAAK,WAAW,KAAK,CAAC;EAE/D,IAAI,GAAG,UAAU,UA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,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"}
|
|
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,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3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2-alpha.0",
|
|
4
4
|
"description": "Fly.io Sprites sandbox provider for Mastra workspaces",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,21 +20,20 @@
|
|
|
20
20
|
},
|
|
21
21
|
"license": "Apache-2.0",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@fly/sprites": "^0.2.
|
|
23
|
+
"@fly/sprites": "^0.2.4"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@types/node": "22.
|
|
27
|
-
"@vitest/coverage-v8": "4.1.
|
|
28
|
-
"@vitest/ui": "4.1.
|
|
26
|
+
"@types/node": "22.19.15",
|
|
27
|
+
"@vitest/coverage-v8": "4.1.12",
|
|
28
|
+
"@vitest/ui": "4.1.12",
|
|
29
29
|
"dotenv": "^17.4.2",
|
|
30
|
-
"
|
|
31
|
-
"tsdown": "0.22.9",
|
|
30
|
+
"tsdown": "0.23.1",
|
|
32
31
|
"typescript": "^7.0.2",
|
|
33
|
-
"vitest": "4.1.
|
|
34
|
-
"@internal/lint": "0.0.
|
|
35
|
-
"@
|
|
36
|
-
"@internal/
|
|
37
|
-
"@
|
|
32
|
+
"vitest": "4.1.12",
|
|
33
|
+
"@internal/lint": "0.0.145",
|
|
34
|
+
"@internal/workspace-test-utils": "0.0.89",
|
|
35
|
+
"@internal/types-builder": "0.0.120",
|
|
36
|
+
"@mastra/core": "1.80.0-alpha.4"
|
|
38
37
|
},
|
|
39
38
|
"peerDependencies": {
|
|
40
39
|
"@mastra/core": ">=1.68.0-0 <2.0.0-0"
|
|
@@ -62,7 +61,7 @@
|
|
|
62
61
|
"test:watch": "vitest watch",
|
|
63
62
|
"test": "vitest run ./src/**/*.integration.test.ts",
|
|
64
63
|
"test:cloud": "pnpm test",
|
|
65
|
-
"lint": "oxlint
|
|
66
|
-
"lint:fix": "oxlint --
|
|
64
|
+
"lint": "oxlint --type-aware .",
|
|
65
|
+
"lint:fix": "oxlint --type-aware --fix ."
|
|
67
66
|
}
|
|
68
67
|
}
|