@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 CHANGED
@@ -1,5 +1,35 @@
1
1
  # @mastra/daytona
2
2
 
3
+ ## 0.2.0-alpha.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Added provider-specific `daytona` getter to access the underlying Daytona `Sandbox` instance directly. Deprecated the generic `instance` getter in favor of the new `daytona` getter for better IDE discoverability and consistency with other sandbox providers. ([#14166](https://github.com/mastra-ai/mastra/pull/14166))
8
+
9
+ ```typescript
10
+ // Before
11
+ const daytonaSandbox = sandbox.instance;
12
+
13
+ // After
14
+ const daytonaSandbox = sandbox.daytona;
15
+ ```
16
+
17
+ ### Patch Changes
18
+
19
+ - Improved Daytona process handling to use provider session IDs directly as `ProcessHandle.pid`. ([#13591](https://github.com/mastra-ai/mastra/pull/13591))
20
+
21
+ ```typescript
22
+ const handle = await sandbox.processes.spawn('node server.js');
23
+ await sandbox.processes.get(handle.pid);
24
+ ```
25
+
26
+ - Fixed sandbox reconnection when Daytona sandbox is externally stopped or times out due to inactivity. Previously, the error thrown by the Daytona SDK (e.g. "failed to resolve container IP") did not match the known dead-sandbox patterns, so the automatic retry logic would not trigger and the error would propagate to the user. Added two new error patterns to correctly detect stopped sandboxes and trigger automatic recovery. ([#14175](https://github.com/mastra-ai/mastra/pull/14175))
27
+
28
+ - dependencies updates: ([#13591](https://github.com/mastra-ai/mastra/pull/13591))
29
+ - Updated peerDependency `@mastra/core` to `>=1.12.0-0 <2.0.0-0`
30
+ - Updated dependencies [[`9cede11`](https://github.com/mastra-ai/mastra/commit/9cede110abac9d93072e0521bb3c8bcafb9fdadf), [`a59f126`](https://github.com/mastra-ai/mastra/commit/a59f1269104f54726699c5cdb98c72c93606d2df), [`c510833`](https://github.com/mastra-ai/mastra/commit/c5108333e8cbc19dafee5f8bfefbcb5ee935335c), [`7296fcc`](https://github.com/mastra-ai/mastra/commit/7296fcc599c876a68699a71c7054a16d5aaf2337), [`00c27f9`](https://github.com/mastra-ai/mastra/commit/00c27f9080731433230a61be69c44e39a7a7b4c7), [`ee19c9b`](https://github.com/mastra-ai/mastra/commit/ee19c9ba3ec3ed91feb214ad539bdc766c53bb01)]:
31
+ - @mastra/core@1.12.0-alpha.1
32
+
3
33
  ## 0.1.0
4
34
 
5
35
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -250,7 +250,6 @@ Sandbox network response: ${checkOutput}` : "")
250
250
  }
251
251
  var DaytonaProcessHandle = class extends workspace.ProcessHandle {
252
252
  pid;
253
- _sessionId;
254
253
  _cmdId;
255
254
  _sandbox;
256
255
  _startTime;
@@ -259,10 +258,9 @@ var DaytonaProcessHandle = class extends workspace.ProcessHandle {
259
258
  _waitPromise = null;
260
259
  _streamingPromise = null;
261
260
  _killed = false;
262
- constructor(pid, sessionId, cmdId, sandbox, startTime, options) {
261
+ constructor(sessionId, cmdId, sandbox, startTime, options) {
263
262
  super(options);
264
- this.pid = pid;
265
- this._sessionId = sessionId;
263
+ this.pid = sessionId;
266
264
  this._cmdId = cmdId;
267
265
  this._sandbox = sandbox;
268
266
  this._startTime = startTime;
@@ -280,7 +278,7 @@ var DaytonaProcessHandle = class extends workspace.ProcessHandle {
280
278
  async _resolveExitCode() {
281
279
  if (this._exitCode !== void 0) return;
282
280
  try {
283
- const cmd = await this._sandbox.process.getSessionCommand(this._sessionId, this._cmdId);
281
+ const cmd = await this._sandbox.process.getSessionCommand(this.pid, this._cmdId);
284
282
  this._exitCode = cmd.exitCode ?? 0;
285
283
  } catch {
286
284
  if (this._exitCode === void 0) {
@@ -346,7 +344,7 @@ var DaytonaProcessHandle = class extends workspace.ProcessHandle {
346
344
  this._killed = true;
347
345
  this._exitCode = 137;
348
346
  try {
349
- await this._sandbox.process.deleteSession(this._sessionId);
347
+ await this._sandbox.process.deleteSession(this.pid);
350
348
  } catch {
351
349
  }
352
350
  return true;
@@ -355,11 +353,11 @@ var DaytonaProcessHandle = class extends workspace.ProcessHandle {
355
353
  if (this._exitCode !== void 0) {
356
354
  throw new Error(`Process ${this.pid} has already exited with code ${this._exitCode}`);
357
355
  }
358
- await this._sandbox.process.sendSessionCommandInput(this._sessionId, this._cmdId, data);
356
+ await this._sandbox.process.sendSessionCommandInput(this.pid, this._cmdId, data);
359
357
  }
360
358
  };
361
359
  var DaytonaProcessManager = class extends workspace.SandboxProcessManager {
362
- _nextPid = 1;
360
+ _spawnCounter = 0;
363
361
  _defaultTimeout;
364
362
  constructor(opts = {}) {
365
363
  super({ env: opts.env });
@@ -371,20 +369,19 @@ var DaytonaProcessManager = class extends workspace.SandboxProcessManager {
371
369
  timeout: options.timeout ?? this._defaultTimeout
372
370
  };
373
371
  return this.sandbox.retryOnDead(async () => {
374
- const sandbox = this.sandbox.instance;
375
- const pid = this._nextPid++;
372
+ const sandbox = this.sandbox.daytona;
376
373
  const mergedEnv = { ...this.env, ...effectiveOptions.env };
377
374
  const envs = Object.fromEntries(
378
375
  Object.entries(mergedEnv).filter((entry) => entry[1] !== void 0)
379
376
  );
380
377
  const sessionCommand = buildSpawnCommand(command, effectiveOptions.cwd, envs);
381
- const sessionId = `mastra-proc-${Date.now().toString(36)}-${pid}`;
378
+ const sessionId = `mastra-proc-${Date.now().toString(36)}-${++this._spawnCounter}`;
382
379
  await sandbox.process.createSession(sessionId);
383
380
  const { cmdId } = await sandbox.process.executeSessionCommand(sessionId, {
384
381
  command: sessionCommand,
385
382
  runAsync: true
386
383
  });
387
- const handle = new DaytonaProcessHandle(pid, sessionId, cmdId, sandbox, Date.now(), effectiveOptions);
384
+ const handle = new DaytonaProcessHandle(sessionId, cmdId, sandbox, Date.now(), effectiveOptions);
388
385
  const streamingPromise = sandbox.process.getSessionCommandLogs(
389
386
  sessionId,
390
387
  cmdId,
@@ -393,7 +390,7 @@ var DaytonaProcessManager = class extends workspace.SandboxProcessManager {
393
390
  ).catch(() => {
394
391
  });
395
392
  handle.streamingPromise = streamingPromise;
396
- this._tracked.set(pid, handle);
393
+ this._tracked.set(handle.pid, handle);
397
394
  return handle;
398
395
  });
399
396
  }
@@ -409,9 +406,6 @@ var DaytonaProcessManager = class extends workspace.SandboxProcessManager {
409
406
  }
410
407
  return result;
411
408
  }
412
- async get(pid) {
413
- return this._tracked.get(pid);
414
- }
415
409
  };
416
410
  function buildSpawnCommand(command, cwd, envs) {
417
411
  const parts = [];
@@ -458,7 +452,9 @@ var SAFE_MARKER_NAME = /^mount-[a-z0-9]+$/;
458
452
  var SANDBOX_DEAD_PATTERNS = [
459
453
  /sandbox is not running/i,
460
454
  /sandbox already destroyed/i,
461
- /sandbox.*not found/i
455
+ /sandbox.*not found/i,
456
+ /failed to resolve container IP/i,
457
+ /is the sandbox started/i
462
458
  ];
463
459
  var DaytonaSandbox = class _DaytonaSandbox extends workspace.MastraSandbox {
464
460
  id;
@@ -535,16 +531,21 @@ var DaytonaSandbox = class _DaytonaSandbox extends workspace.MastraSandbox {
535
531
  *
536
532
  * @example Direct file operations
537
533
  * ```typescript
538
- * const daytonaSandbox = sandbox.instance;
534
+ * await sandbox.start();
535
+ * const daytonaSandbox = sandbox.daytona;
539
536
  * await daytonaSandbox.fs.uploadFile(Buffer.from('Hello'), '/tmp/test.txt');
540
537
  * ```
541
538
  */
542
- get instance() {
539
+ get daytona() {
543
540
  if (!this._sandbox) {
544
541
  throw new workspace.SandboxNotReadyError(this.id);
545
542
  }
546
543
  return this._sandbox;
547
544
  }
545
+ /** @deprecated Use `daytona` instead. */
546
+ get instance() {
547
+ return this.daytona;
548
+ }
548
549
  // ---------------------------------------------------------------------------
549
550
  // Lifecycle
550
551
  // ---------------------------------------------------------------------------