@mastra/e2b 0.16.1-alpha.0 → 0.16.1-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.cjs CHANGED
@@ -528,6 +528,20 @@ var FilesApiFilesystem = class extends _mastra_core_workspace.MastraFilesystem {
528
528
  throw new Error(`${operation} ${subject} failed (exit ${result.exitCode}): ${result.stderr.trim()}`);
529
529
  }
530
530
  };
531
+ const KILL_DESCENDANTS_TIMEOUT_MS = 1e4;
532
+ /**
533
+ * A shell command that kills every process `pid` started, at any depth, but
534
+ * not `pid` itself. It pauses `pid` first: a wrapper like npm exits on its own
535
+ * once its child dies, and `kill(pid)` would then report it wasn't running.
536
+ */
537
+ function killDescendants(pid) {
538
+ return [
539
+ `kill -STOP ${pid}`,
540
+ "kill_children() { for child in $(pgrep -P \"$1\"); do kill -STOP \"$child\"; (kill_children \"$child\"); kill -KILL \"$child\"; done; }",
541
+ `kill_children ${pid}`,
542
+ "true"
543
+ ].join("\n");
544
+ }
531
545
  /**
532
546
  * Output callbacks for `run`/`connect` that hold output until the handle
533
547
  * exists. The SDK's handle reads events from construction, before `run()`
@@ -630,7 +644,16 @@ var CommandsApiProcessHandle = class extends _mastra_core_workspace.ProcessHandl
630
644
  }
631
645
  async kill() {
632
646
  if (this.exitCode !== void 0) return false;
633
- return this.manager.runCommands("kill", (commands) => commands.kill(this.inner.pid));
647
+ return this.manager.runCommands("kill", async (commands) => {
648
+ try {
649
+ await (await commands.run(killDescendants(this.inner.pid), {
650
+ background: true,
651
+ stdin: false,
652
+ timeoutMs: KILL_DESCENDANTS_TIMEOUT_MS
653
+ })).wait();
654
+ } catch {}
655
+ return commands.kill(this.inner.pid);
656
+ });
634
657
  }
635
658
  async sendStdin(data) {
636
659
  if (this.exitCode !== void 0) throw new Error(`Process ${this.pid} has already exited with code ${this.exitCode}`);