@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.
@@ -624,8 +624,46 @@ var Terminal = class {
624
624
  listen(event, handler) {
625
625
  return this.okra.listen(event, handler);
626
626
  }
627
+ async attach(id, opts) {
628
+ const handle = this.processHandle(id, opts?.abortSignal);
629
+ const task = await this.okra.invoke(
630
+ "terminal.attach",
631
+ {
632
+ id,
633
+ replayHistory: opts?.replayHistory
634
+ },
635
+ { abortSignal: opts?.abortSignal }
636
+ );
637
+ if (!task) {
638
+ handle.dispose();
639
+ return false;
640
+ }
641
+ return {
642
+ ...handle.process,
643
+ ...task
644
+ };
645
+ }
627
646
  async spawn(command, args, opts) {
628
647
  const id = opts?.id || nanoid();
648
+ const handle = this.processHandle(id, opts?.abortSignal);
649
+ const { abortSignal, ...otherOpts } = opts ?? {};
650
+ const result = await this.okra.invoke(
651
+ "terminal.spawn",
652
+ {
653
+ command: [command, ...args],
654
+ opts: {
655
+ id,
656
+ ...otherOpts
657
+ }
658
+ },
659
+ { abortSignal }
660
+ );
661
+ return {
662
+ ...handle.process,
663
+ ...result
664
+ };
665
+ }
666
+ processHandle(id, abortSignal) {
629
667
  const disposables = /* @__PURE__ */ new Set();
630
668
  const dispose = () => {
631
669
  for (const disposable of disposables) {
@@ -675,28 +713,18 @@ var Terminal = class {
675
713
  const resize = (dimensions) => {
676
714
  this.okra.invoke("terminal.resize", { id, width: dimensions.cols, height: dimensions.rows });
677
715
  };
678
- const { abortSignal, ...otherOpts } = opts ?? {};
679
716
  if (abortSignal) {
680
717
  abortSignal.addEventListener("abort", kill);
681
718
  }
682
- const result = await this.okra.invoke(
683
- "terminal.spawn",
684
- {
685
- command: [command, ...args],
686
- opts: {
687
- id,
688
- ...otherOpts
689
- }
690
- },
691
- { abortSignal }
692
- );
693
719
  return {
694
- exit,
695
- input,
696
- output,
697
- kill,
698
- resize,
699
- ...result
720
+ process: {
721
+ exit,
722
+ input,
723
+ output,
724
+ kill,
725
+ resize
726
+ },
727
+ dispose
700
728
  };
701
729
  }
702
730
  };