@mastra/daytona 0.1.0 → 0.2.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/dist/index.cjs +20 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +20 -19
- package/dist/index.js.map +1 -1
- package/dist/sandbox/index.d.ts +4 -1
- package/dist/sandbox/index.d.ts.map +1 -1
- package/dist/sandbox/process-manager.d.ts +1 -2
- package/dist/sandbox/process-manager.d.ts.map +1 -1
- package/package.json +11 -11
package/dist/index.js
CHANGED
|
@@ -248,7 +248,6 @@ Sandbox network response: ${checkOutput}` : "")
|
|
|
248
248
|
}
|
|
249
249
|
var DaytonaProcessHandle = class extends ProcessHandle {
|
|
250
250
|
pid;
|
|
251
|
-
_sessionId;
|
|
252
251
|
_cmdId;
|
|
253
252
|
_sandbox;
|
|
254
253
|
_startTime;
|
|
@@ -257,10 +256,9 @@ var DaytonaProcessHandle = class extends ProcessHandle {
|
|
|
257
256
|
_waitPromise = null;
|
|
258
257
|
_streamingPromise = null;
|
|
259
258
|
_killed = false;
|
|
260
|
-
constructor(
|
|
259
|
+
constructor(sessionId, cmdId, sandbox, startTime, options) {
|
|
261
260
|
super(options);
|
|
262
|
-
this.pid =
|
|
263
|
-
this._sessionId = sessionId;
|
|
261
|
+
this.pid = sessionId;
|
|
264
262
|
this._cmdId = cmdId;
|
|
265
263
|
this._sandbox = sandbox;
|
|
266
264
|
this._startTime = startTime;
|
|
@@ -278,7 +276,7 @@ var DaytonaProcessHandle = class extends ProcessHandle {
|
|
|
278
276
|
async _resolveExitCode() {
|
|
279
277
|
if (this._exitCode !== void 0) return;
|
|
280
278
|
try {
|
|
281
|
-
const cmd = await this._sandbox.process.getSessionCommand(this.
|
|
279
|
+
const cmd = await this._sandbox.process.getSessionCommand(this.pid, this._cmdId);
|
|
282
280
|
this._exitCode = cmd.exitCode ?? 0;
|
|
283
281
|
} catch {
|
|
284
282
|
if (this._exitCode === void 0) {
|
|
@@ -344,7 +342,7 @@ var DaytonaProcessHandle = class extends ProcessHandle {
|
|
|
344
342
|
this._killed = true;
|
|
345
343
|
this._exitCode = 137;
|
|
346
344
|
try {
|
|
347
|
-
await this._sandbox.process.deleteSession(this.
|
|
345
|
+
await this._sandbox.process.deleteSession(this.pid);
|
|
348
346
|
} catch {
|
|
349
347
|
}
|
|
350
348
|
return true;
|
|
@@ -353,11 +351,11 @@ var DaytonaProcessHandle = class extends ProcessHandle {
|
|
|
353
351
|
if (this._exitCode !== void 0) {
|
|
354
352
|
throw new Error(`Process ${this.pid} has already exited with code ${this._exitCode}`);
|
|
355
353
|
}
|
|
356
|
-
await this._sandbox.process.sendSessionCommandInput(this.
|
|
354
|
+
await this._sandbox.process.sendSessionCommandInput(this.pid, this._cmdId, data);
|
|
357
355
|
}
|
|
358
356
|
};
|
|
359
357
|
var DaytonaProcessManager = class extends SandboxProcessManager {
|
|
360
|
-
|
|
358
|
+
_spawnCounter = 0;
|
|
361
359
|
_defaultTimeout;
|
|
362
360
|
constructor(opts = {}) {
|
|
363
361
|
super({ env: opts.env });
|
|
@@ -369,20 +367,19 @@ var DaytonaProcessManager = class extends SandboxProcessManager {
|
|
|
369
367
|
timeout: options.timeout ?? this._defaultTimeout
|
|
370
368
|
};
|
|
371
369
|
return this.sandbox.retryOnDead(async () => {
|
|
372
|
-
const sandbox = this.sandbox.
|
|
373
|
-
const pid = this._nextPid++;
|
|
370
|
+
const sandbox = this.sandbox.daytona;
|
|
374
371
|
const mergedEnv = { ...this.env, ...effectiveOptions.env };
|
|
375
372
|
const envs = Object.fromEntries(
|
|
376
373
|
Object.entries(mergedEnv).filter((entry) => entry[1] !== void 0)
|
|
377
374
|
);
|
|
378
375
|
const sessionCommand = buildSpawnCommand(command, effectiveOptions.cwd, envs);
|
|
379
|
-
const sessionId = `mastra-proc-${Date.now().toString(36)}-${
|
|
376
|
+
const sessionId = `mastra-proc-${Date.now().toString(36)}-${++this._spawnCounter}`;
|
|
380
377
|
await sandbox.process.createSession(sessionId);
|
|
381
378
|
const { cmdId } = await sandbox.process.executeSessionCommand(sessionId, {
|
|
382
379
|
command: sessionCommand,
|
|
383
380
|
runAsync: true
|
|
384
381
|
});
|
|
385
|
-
const handle = new DaytonaProcessHandle(
|
|
382
|
+
const handle = new DaytonaProcessHandle(sessionId, cmdId, sandbox, Date.now(), effectiveOptions);
|
|
386
383
|
const streamingPromise = sandbox.process.getSessionCommandLogs(
|
|
387
384
|
sessionId,
|
|
388
385
|
cmdId,
|
|
@@ -391,7 +388,7 @@ var DaytonaProcessManager = class extends SandboxProcessManager {
|
|
|
391
388
|
).catch(() => {
|
|
392
389
|
});
|
|
393
390
|
handle.streamingPromise = streamingPromise;
|
|
394
|
-
this._tracked.set(pid, handle);
|
|
391
|
+
this._tracked.set(handle.pid, handle);
|
|
395
392
|
return handle;
|
|
396
393
|
});
|
|
397
394
|
}
|
|
@@ -407,9 +404,6 @@ var DaytonaProcessManager = class extends SandboxProcessManager {
|
|
|
407
404
|
}
|
|
408
405
|
return result;
|
|
409
406
|
}
|
|
410
|
-
async get(pid) {
|
|
411
|
-
return this._tracked.get(pid);
|
|
412
|
-
}
|
|
413
407
|
};
|
|
414
408
|
function buildSpawnCommand(command, cwd, envs) {
|
|
415
409
|
const parts = [];
|
|
@@ -456,7 +450,9 @@ var SAFE_MARKER_NAME = /^mount-[a-z0-9]+$/;
|
|
|
456
450
|
var SANDBOX_DEAD_PATTERNS = [
|
|
457
451
|
/sandbox is not running/i,
|
|
458
452
|
/sandbox already destroyed/i,
|
|
459
|
-
/sandbox.*not found/i
|
|
453
|
+
/sandbox.*not found/i,
|
|
454
|
+
/failed to resolve container IP/i,
|
|
455
|
+
/is the sandbox started/i
|
|
460
456
|
];
|
|
461
457
|
var DaytonaSandbox = class _DaytonaSandbox extends MastraSandbox {
|
|
462
458
|
id;
|
|
@@ -533,16 +529,21 @@ var DaytonaSandbox = class _DaytonaSandbox extends MastraSandbox {
|
|
|
533
529
|
*
|
|
534
530
|
* @example Direct file operations
|
|
535
531
|
* ```typescript
|
|
536
|
-
*
|
|
532
|
+
* await sandbox.start();
|
|
533
|
+
* const daytonaSandbox = sandbox.daytona;
|
|
537
534
|
* await daytonaSandbox.fs.uploadFile(Buffer.from('Hello'), '/tmp/test.txt');
|
|
538
535
|
* ```
|
|
539
536
|
*/
|
|
540
|
-
get
|
|
537
|
+
get daytona() {
|
|
541
538
|
if (!this._sandbox) {
|
|
542
539
|
throw new SandboxNotReadyError(this.id);
|
|
543
540
|
}
|
|
544
541
|
return this._sandbox;
|
|
545
542
|
}
|
|
543
|
+
/** @deprecated Use `daytona` instead. */
|
|
544
|
+
get instance() {
|
|
545
|
+
return this.daytona;
|
|
546
|
+
}
|
|
546
547
|
// ---------------------------------------------------------------------------
|
|
547
548
|
// Lifecycle
|
|
548
549
|
// ---------------------------------------------------------------------------
|