@mastra/daytona 0.8.0 → 0.9.0-alpha.1

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.js CHANGED
@@ -524,7 +524,7 @@ var DaytonaProcessManager = class extends SandboxProcessManager {
524
524
  _spawnCounter = 0;
525
525
  _defaultTimeout;
526
526
  constructor(opts = {}) {
527
- super({ env: opts.env });
527
+ super();
528
528
  this._defaultTimeout = opts.defaultTimeout;
529
529
  }
530
530
  async spawn(command, options = {}) {
@@ -533,11 +533,7 @@ var DaytonaProcessManager = class extends SandboxProcessManager {
533
533
  timeout: options.timeout ?? this._defaultTimeout,
534
534
  cwd: options.cwd ?? this.sandbox.mounts?.entries?.keys().next().value
535
535
  };
536
- const mergedEnv = {
537
- ...this.env,
538
- ...effectiveOptions.env
539
- };
540
- const envs = Object.fromEntries(Object.entries(mergedEnv).filter((entry) => entry[1] !== void 0));
536
+ const envs = Object.fromEntries(Object.entries(effectiveOptions.env ?? {}).filter((entry) => entry[1] !== void 0));
541
537
  const sessionCommand = buildSpawnCommand(command, effectiveOptions.cwd, envs);
542
538
  return this.sandbox.retryOnDead(async () => {
543
539
  const sandbox = this.sandbox.daytona;
@@ -696,7 +692,6 @@ var DaytonaSandbox = class DaytonaSandbox extends MastraSandbox {
696
692
  timeout;
697
693
  language;
698
694
  resources;
699
- env;
700
695
  labels;
701
696
  snapshotId;
702
697
  image;
@@ -712,22 +707,19 @@ var DaytonaSandbox = class DaytonaSandbox extends MastraSandbox {
712
707
  networkBlockAll;
713
708
  networkAllowList;
714
709
  domainAllowList;
710
+ secrets;
715
711
  connectionOpts;
716
712
  _constructorOptions;
717
713
  constructor(options = {}) {
718
714
  super({
719
715
  ...options,
720
716
  name: "DaytonaSandbox",
721
- processes: new DaytonaProcessManager({
722
- env: options.env,
723
- defaultTimeout: options.timeout ?? 3e5
724
- })
717
+ processes: new DaytonaProcessManager({ defaultTimeout: options.timeout ?? 3e5 })
725
718
  });
726
719
  this.id = options.id ?? this.generateId();
727
720
  this.timeout = options.timeout ?? 3e5;
728
721
  this.language = options.language ?? "typescript";
729
722
  this.resources = options.resources;
730
- this.env = options.env ?? {};
731
723
  this.labels = options.labels ?? {};
732
724
  this.snapshotId = options.snapshot;
733
725
  this.image = options.image;
@@ -742,6 +734,7 @@ var DaytonaSandbox = class DaytonaSandbox extends MastraSandbox {
742
734
  this.networkBlockAll = options.networkBlockAll;
743
735
  this.networkAllowList = options.networkAllowList;
744
736
  this.domainAllowList = options.domainAllowList;
737
+ this.secrets = options.secrets;
745
738
  this.connectionOpts = {
746
739
  ...options.apiKey !== void 0 && { apiKey: options.apiKey },
747
740
  ...options.apiUrl !== void 0 && { apiUrl: options.apiUrl },
@@ -799,26 +792,35 @@ var DaytonaSandbox = class DaytonaSandbox extends MastraSandbox {
799
792
  return this.daytona;
800
793
  }
801
794
  /**
802
- * Start the Daytona sandbox.
803
- * Reconnects to an existing sandbox with the same logical ID if one exists,
804
- * otherwise creates a new sandbox instance.
795
+ * Acquisition primitives (base-orchestrated start): the base derives
796
+ * `created` structurally from whether an existing sandbox was found, so
797
+ * reconnecting to one with the same logical ID reports `connected`.
798
+ * Lookup errors other than not-found propagate deliberately — creating a
799
+ * duplicate sandbox on a transient/auth error would be worse than failing.
805
800
  */
806
- async start() {
807
- if (this._sandbox) return;
801
+ async find() {
802
+ if (this._sandbox) return this._sandbox;
808
803
  if (!this._daytona) this._daytona = new Daytona(this.connectionOpts);
809
- const existing = await this.findExistingSandbox();
810
- if (existing) {
811
- this._sandbox = existing;
812
- this._daytonaSandboxId = existing.id;
813
- this._createdAt = existing.createdAt ? new Date(existing.createdAt) : /* @__PURE__ */ new Date();
814
- this.logger.debug(`${LOG_PREFIX} Reconnected to existing sandbox ${existing.id} for: ${this.id}`);
815
- const expectedPaths = Array.from(this.mounts.entries.keys());
816
- this.logger.debug(`${LOG_PREFIX} Running mount reconciliation...`);
817
- await this.reconcileMounts(expectedPaths);
818
- this.logger.debug(`${LOG_PREFIX} Mount reconciliation complete`);
819
- await this.detectWorkingDir();
820
- return;
804
+ return await this.findExistingSandbox() ?? void 0;
805
+ }
806
+ async connect(existing) {
807
+ if (existing === this._sandbox) return;
808
+ if (existing.state !== SandboxState.STARTED) {
809
+ this.logger.debug(`${LOG_PREFIX} Restarting sandbox ${existing.id} (state: ${existing.state})`);
810
+ await this.waitForStableStateAndStart(existing);
821
811
  }
812
+ this._sandbox = existing;
813
+ this._daytonaSandboxId = existing.id;
814
+ this._createdAt = existing.createdAt ? new Date(existing.createdAt) : /* @__PURE__ */ new Date();
815
+ this.logger.debug(`${LOG_PREFIX} Reconnected to existing sandbox ${existing.id} for: ${this.id}`);
816
+ const expectedPaths = Array.from(this.mounts.entries.keys());
817
+ this.logger.debug(`${LOG_PREFIX} Running mount reconciliation...`);
818
+ await this.reconcileMounts(expectedPaths);
819
+ this.logger.debug(`${LOG_PREFIX} Mount reconciliation complete`);
820
+ await this.detectWorkingDir();
821
+ }
822
+ async create() {
823
+ if (!this._daytona) this._daytona = new Daytona(this.connectionOpts);
822
824
  this.logger.debug(`${LOG_PREFIX} Creating sandbox for: ${this.id}`);
823
825
  const baseParams = compact({
824
826
  language: this.language,
@@ -836,7 +838,8 @@ var DaytonaSandbox = class DaytonaSandbox extends MastraSandbox {
836
838
  public: this.sandboxPublic,
837
839
  networkBlockAll: this.networkBlockAll,
838
840
  networkAllowList: this.networkAllowList,
839
- domainAllowList: this.domainAllowList
841
+ domainAllowList: this.domainAllowList,
842
+ secrets: this.secrets
840
843
  });
841
844
  if (this.resources && !this.image) this.logger.warn(`${LOG_PREFIX} 'resources' option requires 'image' to take effect — falling back to snapshot-based creation without custom resources`);
842
845
  const createParams = this.image && !this.snapshotId ? compact({
@@ -941,18 +944,6 @@ var DaytonaSandbox = class DaytonaSandbox extends MastraSandbox {
941
944
  return parts.join(" ");
942
945
  }
943
946
  /**
944
- * Execute a command in the sandbox and return the result.
945
- */
946
- async executeCommand(command, args = [], options = {}) {
947
- await this.ensureRunning();
948
- const fullCommand = args.length > 0 ? `${command} ${args.map(shellQuote).join(" ")}` : command;
949
- return {
950
- ...await (await this.processes.spawn(fullCommand, options)).wait(),
951
- command,
952
- args
953
- };
954
- }
955
- /**
956
947
  * Bulk-write files into the sandbox filesystem via the SDK's native upload.
957
948
  */
958
949
  async writeFiles(files) {
@@ -1323,10 +1314,6 @@ var DaytonaSandbox = class DaytonaSandbox extends MastraSandbox {
1323
1314
  } catch {}
1324
1315
  return null;
1325
1316
  }
1326
- if (state !== SandboxState.STARTED) {
1327
- this.logger.debug(`${LOG_PREFIX} Restarting sandbox ${sandbox.id} (state: ${state})`);
1328
- await this.waitForStableStateAndStart(sandbox);
1329
- }
1330
1317
  return sandbox;
1331
1318
  }
1332
1319
  /**