@mastra/daytona 0.1.0 → 0.2.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 +60 -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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,65 @@
|
|
|
1
1
|
# @mastra/daytona
|
|
2
2
|
|
|
3
|
+
## 0.2.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 [[`cddf895`](https://github.com/mastra-ai/mastra/commit/cddf895532b8ee7f9fa814136ec672f53d37a9ba), [`9cede11`](https://github.com/mastra-ai/mastra/commit/9cede110abac9d93072e0521bb3c8bcafb9fdadf), [`a59f126`](https://github.com/mastra-ai/mastra/commit/a59f1269104f54726699c5cdb98c72c93606d2df), [`ed8fd75`](https://github.com/mastra-ai/mastra/commit/ed8fd75cbff03bb5e19971ddb30ab7040fc60447), [`c510833`](https://github.com/mastra-ai/mastra/commit/c5108333e8cbc19dafee5f8bfefbcb5ee935335c), [`c4c7dad`](https://github.com/mastra-ai/mastra/commit/c4c7dadfe2e4584f079f6c24bfabdb8c4981827f), [`45c3112`](https://github.com/mastra-ai/mastra/commit/45c31122666a0cc56b94727099fcb1871ed1b3f6), [`7296fcc`](https://github.com/mastra-ai/mastra/commit/7296fcc599c876a68699a71c7054a16d5aaf2337), [`00c27f9`](https://github.com/mastra-ai/mastra/commit/00c27f9080731433230a61be69c44e39a7a7b4c7), [`5e7c287`](https://github.com/mastra-ai/mastra/commit/5e7c28701f2bce795dd5c811e4c3060bf2ea2242), [`7e17d3f`](https://github.com/mastra-ai/mastra/commit/7e17d3f656fdda2aad47c4beb8c491636d70820c), [`ee19c9b`](https://github.com/mastra-ai/mastra/commit/ee19c9ba3ec3ed91feb214ad539bdc766c53bb01)]:
|
|
31
|
+
- @mastra/core@1.12.0
|
|
32
|
+
|
|
33
|
+
## 0.2.0-alpha.0
|
|
34
|
+
|
|
35
|
+
### Minor Changes
|
|
36
|
+
|
|
37
|
+
- 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))
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
// Before
|
|
41
|
+
const daytonaSandbox = sandbox.instance;
|
|
42
|
+
|
|
43
|
+
// After
|
|
44
|
+
const daytonaSandbox = sandbox.daytona;
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Patch Changes
|
|
48
|
+
|
|
49
|
+
- Improved Daytona process handling to use provider session IDs directly as `ProcessHandle.pid`. ([#13591](https://github.com/mastra-ai/mastra/pull/13591))
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
const handle = await sandbox.processes.spawn('node server.js');
|
|
53
|
+
await sandbox.processes.get(handle.pid);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
- 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))
|
|
57
|
+
|
|
58
|
+
- dependencies updates: ([#13591](https://github.com/mastra-ai/mastra/pull/13591))
|
|
59
|
+
- Updated peerDependency `@mastra/core` to `>=1.12.0-0 <2.0.0-0`
|
|
60
|
+
- 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)]:
|
|
61
|
+
- @mastra/core@1.12.0-alpha.1
|
|
62
|
+
|
|
3
63
|
## 0.1.0
|
|
4
64
|
|
|
5
65
|
### 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(
|
|
261
|
+
constructor(sessionId, cmdId, sandbox, startTime, options) {
|
|
263
262
|
super(options);
|
|
264
|
-
this.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.
|
|
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.
|
|
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.
|
|
356
|
+
await this._sandbox.process.sendSessionCommandInput(this.pid, this._cmdId, data);
|
|
359
357
|
}
|
|
360
358
|
};
|
|
361
359
|
var DaytonaProcessManager = class extends workspace.SandboxProcessManager {
|
|
362
|
-
|
|
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.
|
|
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)}-${
|
|
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(
|
|
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
|
-
*
|
|
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
|
|
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
|
// ---------------------------------------------------------------------------
|