@phpsandbox/sdk 0.0.37 → 0.0.38

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.
@@ -673,8 +673,46 @@ var PHPSandbox = (() => {
673
673
  listen(event, handler) {
674
674
  return this.okra.listen(event, handler);
675
675
  }
676
+ async attach(id, opts) {
677
+ const handle = this.processHandle(id, opts?.abortSignal);
678
+ const task = await this.okra.invoke(
679
+ "terminal.attach",
680
+ {
681
+ id,
682
+ replayHistory: opts?.replayHistory
683
+ },
684
+ { abortSignal: opts?.abortSignal }
685
+ );
686
+ if (!task) {
687
+ handle.dispose();
688
+ return false;
689
+ }
690
+ return {
691
+ ...handle.process,
692
+ ...task
693
+ };
694
+ }
676
695
  async spawn(command, args, opts) {
677
696
  const id = opts?.id || nanoid();
697
+ const handle = this.processHandle(id, opts?.abortSignal);
698
+ const { abortSignal, ...otherOpts } = opts ?? {};
699
+ const result = await this.okra.invoke(
700
+ "terminal.spawn",
701
+ {
702
+ command: [command, ...args],
703
+ opts: {
704
+ id,
705
+ ...otherOpts
706
+ }
707
+ },
708
+ { abortSignal }
709
+ );
710
+ return {
711
+ ...handle.process,
712
+ ...result
713
+ };
714
+ }
715
+ processHandle(id, abortSignal) {
678
716
  const disposables = /* @__PURE__ */ new Set();
679
717
  const dispose = () => {
680
718
  for (const disposable of disposables) {
@@ -724,28 +762,18 @@ var PHPSandbox = (() => {
724
762
  const resize = (dimensions) => {
725
763
  this.okra.invoke("terminal.resize", { id, width: dimensions.cols, height: dimensions.rows });
726
764
  };
727
- const { abortSignal, ...otherOpts } = opts ?? {};
728
765
  if (abortSignal) {
729
766
  abortSignal.addEventListener("abort", kill);
730
767
  }
731
- const result = await this.okra.invoke(
732
- "terminal.spawn",
733
- {
734
- command: [command, ...args],
735
- opts: {
736
- id,
737
- ...otherOpts
738
- }
739
- },
740
- { abortSignal }
741
- );
742
768
  return {
743
- exit,
744
- input,
745
- output,
746
- kill,
747
- resize,
748
- ...result
769
+ process: {
770
+ exit,
771
+ input,
772
+ output,
773
+ kill,
774
+ resize
775
+ },
776
+ dispose
749
777
  };
750
778
  }
751
779
  };