@mastra/daytona 0.2.0 → 0.2.1-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 +9 -0
- package/dist/index.cjs +20 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +21 -37
- package/dist/index.js.map +1 -1
- package/dist/sandbox/index.d.ts +2 -10
- package/dist/sandbox/index.d.ts.map +1 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Daytona, DaytonaNotFoundError,
|
|
1
|
+
import { Daytona, DaytonaNotFoundError, SandboxState } from '@daytonaio/sdk';
|
|
2
2
|
import { SandboxProcessManager, MastraSandbox, SandboxNotReadyError, ProcessHandle } from '@mastra/core/workspace';
|
|
3
3
|
import { createHash } from 'crypto';
|
|
4
4
|
|
|
@@ -478,6 +478,7 @@ var DaytonaSandbox = class _DaytonaSandbox extends MastraSandbox {
|
|
|
478
478
|
autoDeleteInterval;
|
|
479
479
|
volumeConfigs;
|
|
480
480
|
sandboxName;
|
|
481
|
+
_daytonaSandboxId;
|
|
481
482
|
sandboxUser;
|
|
482
483
|
sandboxPublic;
|
|
483
484
|
networkBlockAll;
|
|
@@ -562,6 +563,7 @@ var DaytonaSandbox = class _DaytonaSandbox extends MastraSandbox {
|
|
|
562
563
|
const existing = await this.findExistingSandbox();
|
|
563
564
|
if (existing) {
|
|
564
565
|
this._sandbox = existing;
|
|
566
|
+
this._daytonaSandboxId = existing.id;
|
|
565
567
|
this._createdAt = existing.createdAt ? new Date(existing.createdAt) : /* @__PURE__ */ new Date();
|
|
566
568
|
this.logger.debug(`${LOG_PREFIX} Reconnected to existing sandbox ${existing.id} for: ${this.id}`);
|
|
567
569
|
const expectedPaths = Array.from(this.mounts.entries.keys());
|
|
@@ -597,6 +599,7 @@ var DaytonaSandbox = class _DaytonaSandbox extends MastraSandbox {
|
|
|
597
599
|
resources: this.resources
|
|
598
600
|
}) : compact({ ...baseParams, snapshot: this.snapshotId });
|
|
599
601
|
this._sandbox = await this._daytona.create(createParams);
|
|
602
|
+
this._daytonaSandboxId = this._sandbox.id;
|
|
600
603
|
this.logger.debug(`${LOG_PREFIX} Created sandbox ${this._sandbox.id} for logical ID: ${this.id}`);
|
|
601
604
|
this._createdAt = /* @__PURE__ */ new Date();
|
|
602
605
|
await this.detectWorkingDir();
|
|
@@ -631,15 +634,17 @@ var DaytonaSandbox = class _DaytonaSandbox extends MastraSandbox {
|
|
|
631
634
|
} catch {
|
|
632
635
|
}
|
|
633
636
|
} else if (!this._sandbox && this._daytona) {
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
+
const lookupKey = this._daytonaSandboxId ?? this.sandboxName;
|
|
638
|
+
if (lookupKey) {
|
|
639
|
+
try {
|
|
640
|
+
const orphan = await this._daytona.get(lookupKey);
|
|
637
641
|
await this._daytona.delete(orphan);
|
|
642
|
+
} catch {
|
|
638
643
|
}
|
|
639
|
-
} catch {
|
|
640
644
|
}
|
|
641
645
|
}
|
|
642
646
|
this._sandbox = null;
|
|
647
|
+
this._daytonaSandboxId = void 0;
|
|
643
648
|
this._daytona = null;
|
|
644
649
|
this.mounts?.clear();
|
|
645
650
|
}
|
|
@@ -1017,16 +1022,7 @@ var DaytonaSandbox = class _DaytonaSandbox extends MastraSandbox {
|
|
|
1017
1022
|
// Internal Helpers
|
|
1018
1023
|
// ---------------------------------------------------------------------------
|
|
1019
1024
|
/**
|
|
1020
|
-
* Try to find and reconnect to an existing Daytona sandbox.
|
|
1021
|
-
*
|
|
1022
|
-
* Uses two strategies:
|
|
1023
|
-
* 1. `get()` by sandbox name — calls the getSandbox API directly, which
|
|
1024
|
-
* returns sandboxes in ANY state (including stopped). This is the
|
|
1025
|
-
* primary path and fixes reconnection after stop/start cycles.
|
|
1026
|
-
* 2. `findOne()` by label — falls back to label-based search. Note: the
|
|
1027
|
-
* SDK's list() API only returns started sandboxes by default (no states
|
|
1028
|
-
* param in v0.143.0), so this only finds running sandboxes.
|
|
1029
|
-
*
|
|
1025
|
+
* Try to find and reconnect to an existing Daytona sandbox by ID.
|
|
1030
1026
|
* Returns the sandbox if found and usable, or null if a fresh one should
|
|
1031
1027
|
* be created.
|
|
1032
1028
|
*/
|
|
@@ -1050,31 +1046,19 @@ var DaytonaSandbox = class _DaytonaSandbox extends MastraSandbox {
|
|
|
1050
1046
|
SandboxState.ERROR,
|
|
1051
1047
|
SandboxState.BUILD_FAILED
|
|
1052
1048
|
];
|
|
1053
|
-
|
|
1054
|
-
if (
|
|
1055
|
-
|
|
1056
|
-
sandbox = await this._daytona.get(this.sandboxName);
|
|
1057
|
-
} catch (error) {
|
|
1058
|
-
if (error instanceof DaytonaNotFoundError) ; else if (error instanceof DaytonaError && (error.statusCode === 401 || error.statusCode === 403)) {
|
|
1059
|
-
throw error;
|
|
1060
|
-
} else {
|
|
1061
|
-
this.logger.debug(`${LOG_PREFIX} Transient error looking up sandbox by name: ${error}`);
|
|
1062
|
-
}
|
|
1063
|
-
}
|
|
1049
|
+
const lookupKey = this._daytonaSandboxId ?? this.sandboxName;
|
|
1050
|
+
if (!lookupKey) {
|
|
1051
|
+
return null;
|
|
1064
1052
|
}
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
}
|
|
1072
|
-
if (error instanceof DaytonaError && (error.statusCode === 401 || error.statusCode === 403)) {
|
|
1073
|
-
throw error;
|
|
1074
|
-
}
|
|
1075
|
-
this.logger.debug(`${LOG_PREFIX} Transient error looking up sandbox by label: ${error}`);
|
|
1053
|
+
let sandbox;
|
|
1054
|
+
try {
|
|
1055
|
+
sandbox = await this._daytona.get(lookupKey);
|
|
1056
|
+
} catch (error) {
|
|
1057
|
+
if (error instanceof DaytonaNotFoundError) {
|
|
1058
|
+
this._daytonaSandboxId = void 0;
|
|
1076
1059
|
return null;
|
|
1077
1060
|
}
|
|
1061
|
+
throw error;
|
|
1078
1062
|
}
|
|
1079
1063
|
const state = sandbox.state;
|
|
1080
1064
|
if (state && DEAD_STATES.includes(state)) {
|