@gradio/client 0.9.3 → 0.9.4

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
@@ -545,451 +545,441 @@ function api_factory(fetch_implementation, EventSource_factory) {
545
545
  if (typeof window !== "undefined") {
546
546
  url_params = new URLSearchParams(window.location.search).toString();
547
547
  }
548
- handle_blob2(
549
- `${http_protocol}//${resolve_root(host, config.path, true)}`,
550
- data,
551
- api_info,
552
- hf_token
553
- ).then((_payload) => {
554
- payload = { data: _payload || [], event_data, fn_index, trigger_id };
555
- if (skip_queue(fn_index, config)) {
556
- fire_event({
557
- type: "status",
558
- endpoint: _endpoint,
559
- stage: "pending",
560
- queue: false,
548
+ handle_blob2(`${config.root}`, data, api_info, hf_token).then(
549
+ (_payload) => {
550
+ payload = {
551
+ data: _payload || [],
552
+ event_data,
561
553
  fn_index,
562
- time: /* @__PURE__ */ new Date()
563
- });
564
- post_data2(
565
- `${http_protocol}//${resolve_root(host, config.path, true)}/run${_endpoint.startsWith("/") ? _endpoint : `/${_endpoint}`}${url_params ? "?" + url_params : ""}`,
566
- {
567
- ...payload,
568
- session_hash
569
- },
570
- hf_token
571
- ).then(([output, status_code]) => {
572
- const data2 = transform_files ? transform_output(
573
- output.data,
574
- api_info,
575
- config.root,
576
- config.root_url
577
- ) : output.data;
578
- if (status_code == 200) {
579
- fire_event({
580
- type: "data",
581
- endpoint: _endpoint,
582
- fn_index,
583
- data: data2,
584
- time: /* @__PURE__ */ new Date()
585
- });
586
- fire_event({
587
- type: "status",
588
- endpoint: _endpoint,
589
- fn_index,
590
- stage: "complete",
591
- eta: output.average_duration,
592
- queue: false,
593
- time: /* @__PURE__ */ new Date()
594
- });
595
- } else {
554
+ trigger_id
555
+ };
556
+ if (skip_queue(fn_index, config)) {
557
+ fire_event({
558
+ type: "status",
559
+ endpoint: _endpoint,
560
+ stage: "pending",
561
+ queue: false,
562
+ fn_index,
563
+ time: /* @__PURE__ */ new Date()
564
+ });
565
+ post_data2(
566
+ `${config.root}/run${_endpoint.startsWith("/") ? _endpoint : `/${_endpoint}`}${url_params ? "?" + url_params : ""}`,
567
+ {
568
+ ...payload,
569
+ session_hash
570
+ },
571
+ hf_token
572
+ ).then(([output, status_code]) => {
573
+ const data2 = transform_files ? transform_output(
574
+ output.data,
575
+ api_info,
576
+ config.root,
577
+ config.root_url
578
+ ) : output.data;
579
+ if (status_code == 200) {
580
+ fire_event({
581
+ type: "data",
582
+ endpoint: _endpoint,
583
+ fn_index,
584
+ data: data2,
585
+ time: /* @__PURE__ */ new Date()
586
+ });
587
+ fire_event({
588
+ type: "status",
589
+ endpoint: _endpoint,
590
+ fn_index,
591
+ stage: "complete",
592
+ eta: output.average_duration,
593
+ queue: false,
594
+ time: /* @__PURE__ */ new Date()
595
+ });
596
+ } else {
597
+ fire_event({
598
+ type: "status",
599
+ stage: "error",
600
+ endpoint: _endpoint,
601
+ fn_index,
602
+ message: output.error,
603
+ queue: false,
604
+ time: /* @__PURE__ */ new Date()
605
+ });
606
+ }
607
+ }).catch((e) => {
596
608
  fire_event({
597
609
  type: "status",
598
610
  stage: "error",
611
+ message: e.message,
599
612
  endpoint: _endpoint,
600
613
  fn_index,
601
- message: output.error,
602
614
  queue: false,
603
615
  time: /* @__PURE__ */ new Date()
604
616
  });
605
- }
606
- }).catch((e) => {
617
+ });
618
+ } else if (protocol == "ws") {
607
619
  fire_event({
608
620
  type: "status",
609
- stage: "error",
610
- message: e.message,
621
+ stage: "pending",
622
+ queue: true,
611
623
  endpoint: _endpoint,
612
624
  fn_index,
613
- queue: false,
614
625
  time: /* @__PURE__ */ new Date()
615
626
  });
616
- });
617
- } else if (protocol == "ws") {
618
- fire_event({
619
- type: "status",
620
- stage: "pending",
621
- queue: true,
622
- endpoint: _endpoint,
623
- fn_index,
624
- time: /* @__PURE__ */ new Date()
625
- });
626
- let url = new URL(`${ws_protocol}://${resolve_root(
627
- host,
628
- config.path,
629
- true
630
- )}
627
+ let url = new URL(`${ws_protocol}://${resolve_root(
628
+ host,
629
+ config.path,
630
+ true
631
+ )}
631
632
  /queue/join${url_params ? "?" + url_params : ""}`);
632
- if (jwt) {
633
- url.searchParams.set("__sign", jwt);
634
- }
635
- websocket = new WebSocket(url);
636
- websocket.onclose = (evt) => {
637
- if (!evt.wasClean) {
638
- fire_event({
639
- type: "status",
640
- stage: "error",
641
- broken: true,
642
- message: BROKEN_CONNECTION_MSG,
643
- queue: true,
644
- endpoint: _endpoint,
645
- fn_index,
646
- time: /* @__PURE__ */ new Date()
647
- });
633
+ if (jwt) {
634
+ url.searchParams.set("__sign", jwt);
648
635
  }
649
- };
650
- websocket.onmessage = function(event) {
651
- const _data = JSON.parse(event.data);
652
- const { type, status, data: data2 } = handle_message(
653
- _data,
654
- last_status[fn_index]
655
- );
656
- if (type === "update" && status && !complete) {
657
- fire_event({
658
- type: "status",
659
- endpoint: _endpoint,
660
- fn_index,
661
- time: /* @__PURE__ */ new Date(),
662
- ...status
663
- });
664
- if (status.stage === "error") {
665
- websocket.close();
636
+ websocket = new WebSocket(url);
637
+ websocket.onclose = (evt) => {
638
+ if (!evt.wasClean) {
639
+ fire_event({
640
+ type: "status",
641
+ stage: "error",
642
+ broken: true,
643
+ message: BROKEN_CONNECTION_MSG,
644
+ queue: true,
645
+ endpoint: _endpoint,
646
+ fn_index,
647
+ time: /* @__PURE__ */ new Date()
648
+ });
666
649
  }
667
- } else if (type === "hash") {
668
- websocket.send(JSON.stringify({ fn_index, session_hash }));
669
- return;
670
- } else if (type === "data") {
671
- websocket.send(JSON.stringify({ ...payload, session_hash }));
672
- } else if (type === "complete") {
673
- complete = status;
674
- } else if (type === "log") {
675
- fire_event({
676
- type: "log",
677
- log: data2.log,
678
- level: data2.level,
679
- endpoint: _endpoint,
680
- fn_index
681
- });
682
- } else if (type === "generating") {
683
- fire_event({
684
- type: "status",
685
- time: /* @__PURE__ */ new Date(),
686
- ...status,
687
- stage: status == null ? void 0 : status.stage,
688
- queue: true,
689
- endpoint: _endpoint,
690
- fn_index
691
- });
692
- }
693
- if (data2) {
694
- fire_event({
695
- type: "data",
696
- time: /* @__PURE__ */ new Date(),
697
- data: transform_files ? transform_output(
698
- data2.data,
699
- api_info,
700
- config.root,
701
- config.root_url
702
- ) : data2.data,
703
- endpoint: _endpoint,
704
- fn_index
705
- });
706
- if (complete) {
650
+ };
651
+ websocket.onmessage = function(event) {
652
+ const _data = JSON.parse(event.data);
653
+ const { type, status, data: data2 } = handle_message(
654
+ _data,
655
+ last_status[fn_index]
656
+ );
657
+ if (type === "update" && status && !complete) {
707
658
  fire_event({
708
659
  type: "status",
660
+ endpoint: _endpoint,
661
+ fn_index,
709
662
  time: /* @__PURE__ */ new Date(),
710
- ...complete,
663
+ ...status
664
+ });
665
+ if (status.stage === "error") {
666
+ websocket.close();
667
+ }
668
+ } else if (type === "hash") {
669
+ websocket.send(JSON.stringify({ fn_index, session_hash }));
670
+ return;
671
+ } else if (type === "data") {
672
+ websocket.send(JSON.stringify({ ...payload, session_hash }));
673
+ } else if (type === "complete") {
674
+ complete = status;
675
+ } else if (type === "log") {
676
+ fire_event({
677
+ type: "log",
678
+ log: data2.log,
679
+ level: data2.level,
680
+ endpoint: _endpoint,
681
+ fn_index
682
+ });
683
+ } else if (type === "generating") {
684
+ fire_event({
685
+ type: "status",
686
+ time: /* @__PURE__ */ new Date(),
687
+ ...status,
711
688
  stage: status == null ? void 0 : status.stage,
712
689
  queue: true,
713
690
  endpoint: _endpoint,
714
691
  fn_index
715
692
  });
716
- websocket.close();
717
693
  }
694
+ if (data2) {
695
+ fire_event({
696
+ type: "data",
697
+ time: /* @__PURE__ */ new Date(),
698
+ data: transform_files ? transform_output(
699
+ data2.data,
700
+ api_info,
701
+ config.root,
702
+ config.root_url
703
+ ) : data2.data,
704
+ endpoint: _endpoint,
705
+ fn_index
706
+ });
707
+ if (complete) {
708
+ fire_event({
709
+ type: "status",
710
+ time: /* @__PURE__ */ new Date(),
711
+ ...complete,
712
+ stage: status == null ? void 0 : status.stage,
713
+ queue: true,
714
+ endpoint: _endpoint,
715
+ fn_index
716
+ });
717
+ websocket.close();
718
+ }
719
+ }
720
+ };
721
+ if (semiver(config.version || "2.0.0", "3.6") < 0) {
722
+ addEventListener(
723
+ "open",
724
+ () => websocket.send(JSON.stringify({ hash: session_hash }))
725
+ );
718
726
  }
719
- };
720
- if (semiver(config.version || "2.0.0", "3.6") < 0) {
721
- addEventListener(
722
- "open",
723
- () => websocket.send(JSON.stringify({ hash: session_hash }))
724
- );
725
- }
726
- } else if (protocol == "sse") {
727
- fire_event({
728
- type: "status",
729
- stage: "pending",
730
- queue: true,
731
- endpoint: _endpoint,
732
- fn_index,
733
- time: /* @__PURE__ */ new Date()
734
- });
735
- var params = new URLSearchParams({
736
- fn_index: fn_index.toString(),
737
- session_hash
738
- }).toString();
739
- let url = new URL(
740
- `${http_protocol}//${resolve_root(
741
- host,
742
- config.path,
743
- true
744
- )}/queue/join?${url_params ? url_params + "&" : ""}${params}`
745
- );
746
- eventSource = EventSource_factory(url);
747
- eventSource.onmessage = async function(event) {
748
- const _data = JSON.parse(event.data);
749
- const { type, status, data: data2 } = handle_message(
750
- _data,
751
- last_status[fn_index]
727
+ } else if (protocol == "sse") {
728
+ fire_event({
729
+ type: "status",
730
+ stage: "pending",
731
+ queue: true,
732
+ endpoint: _endpoint,
733
+ fn_index,
734
+ time: /* @__PURE__ */ new Date()
735
+ });
736
+ var params = new URLSearchParams({
737
+ fn_index: fn_index.toString(),
738
+ session_hash
739
+ }).toString();
740
+ let url = new URL(
741
+ `${config.root}/queue/join?${url_params ? url_params + "&" : ""}${params}`
752
742
  );
753
- if (type === "update" && status && !complete) {
754
- fire_event({
755
- type: "status",
756
- endpoint: _endpoint,
757
- fn_index,
758
- time: /* @__PURE__ */ new Date(),
759
- ...status
760
- });
761
- if (status.stage === "error") {
762
- eventSource.close();
763
- }
764
- } else if (type === "data") {
765
- event_id = _data.event_id;
766
- let [_, status2] = await post_data2(
767
- `${http_protocol}//${resolve_root(
768
- host,
769
- config.path,
770
- true
771
- )}/queue/data`,
772
- {
773
- ...payload,
774
- session_hash,
775
- event_id
776
- },
777
- hf_token
743
+ eventSource = EventSource_factory(url);
744
+ eventSource.onmessage = async function(event) {
745
+ const _data = JSON.parse(event.data);
746
+ const { type, status, data: data2 } = handle_message(
747
+ _data,
748
+ last_status[fn_index]
778
749
  );
779
- if (status2 !== 200) {
750
+ if (type === "update" && status && !complete) {
780
751
  fire_event({
781
752
  type: "status",
782
- stage: "error",
783
- message: BROKEN_CONNECTION_MSG,
784
- queue: true,
785
753
  endpoint: _endpoint,
786
754
  fn_index,
787
- time: /* @__PURE__ */ new Date()
755
+ time: /* @__PURE__ */ new Date(),
756
+ ...status
788
757
  });
789
- eventSource.close();
790
- }
791
- } else if (type === "complete") {
792
- complete = status;
793
- } else if (type === "log") {
794
- fire_event({
795
- type: "log",
796
- log: data2.log,
797
- level: data2.level,
798
- endpoint: _endpoint,
799
- fn_index
800
- });
801
- } else if (type === "generating") {
802
- fire_event({
803
- type: "status",
804
- time: /* @__PURE__ */ new Date(),
805
- ...status,
806
- stage: status == null ? void 0 : status.stage,
807
- queue: true,
808
- endpoint: _endpoint,
809
- fn_index
810
- });
811
- }
812
- if (data2) {
813
- fire_event({
814
- type: "data",
815
- time: /* @__PURE__ */ new Date(),
816
- data: transform_files ? transform_output(
817
- data2.data,
818
- api_info,
819
- config.root,
820
- config.root_url
821
- ) : data2.data,
822
- endpoint: _endpoint,
823
- fn_index
824
- });
825
- if (complete) {
758
+ if (status.stage === "error") {
759
+ eventSource.close();
760
+ }
761
+ } else if (type === "data") {
762
+ event_id = _data.event_id;
763
+ let [_, status2] = await post_data2(
764
+ `${config.root}/queue/data`,
765
+ {
766
+ ...payload,
767
+ session_hash,
768
+ event_id
769
+ },
770
+ hf_token
771
+ );
772
+ if (status2 !== 200) {
773
+ fire_event({
774
+ type: "status",
775
+ stage: "error",
776
+ message: BROKEN_CONNECTION_MSG,
777
+ queue: true,
778
+ endpoint: _endpoint,
779
+ fn_index,
780
+ time: /* @__PURE__ */ new Date()
781
+ });
782
+ eventSource.close();
783
+ }
784
+ } else if (type === "complete") {
785
+ complete = status;
786
+ } else if (type === "log") {
787
+ fire_event({
788
+ type: "log",
789
+ log: data2.log,
790
+ level: data2.level,
791
+ endpoint: _endpoint,
792
+ fn_index
793
+ });
794
+ } else if (type === "generating") {
826
795
  fire_event({
827
796
  type: "status",
828
797
  time: /* @__PURE__ */ new Date(),
829
- ...complete,
798
+ ...status,
830
799
  stage: status == null ? void 0 : status.stage,
831
800
  queue: true,
832
801
  endpoint: _endpoint,
833
802
  fn_index
834
803
  });
835
- eventSource.close();
836
804
  }
837
- }
838
- };
839
- } else if (protocol == "sse_v1") {
840
- fire_event({
841
- type: "status",
842
- stage: "pending",
843
- queue: true,
844
- endpoint: _endpoint,
845
- fn_index,
846
- time: /* @__PURE__ */ new Date()
847
- });
848
- post_data2(
849
- `${http_protocol}//${resolve_root(
850
- host,
851
- config.path,
852
- true
853
- )}/queue/join?${url_params}`,
854
- {
855
- ...payload,
856
- session_hash
857
- },
858
- hf_token
859
- ).then(([response, status]) => {
860
- if (status === 503) {
861
- fire_event({
862
- type: "status",
863
- stage: "error",
864
- message: QUEUE_FULL_MSG,
865
- queue: true,
866
- endpoint: _endpoint,
867
- fn_index,
868
- time: /* @__PURE__ */ new Date()
869
- });
870
- } else if (status !== 200) {
871
- fire_event({
872
- type: "status",
873
- stage: "error",
874
- message: BROKEN_CONNECTION_MSG,
875
- queue: true,
876
- endpoint: _endpoint,
877
- fn_index,
878
- time: /* @__PURE__ */ new Date()
879
- });
880
- } else {
881
- event_id = response.event_id;
882
- let callback = async function(_data) {
883
- try {
884
- const { type, status: status2, data: data2 } = handle_message(
885
- _data,
886
- last_status[fn_index]
887
- );
888
- if (type == "heartbeat") {
889
- return;
890
- }
891
- if (type === "update" && status2 && !complete) {
892
- fire_event({
893
- type: "status",
894
- endpoint: _endpoint,
895
- fn_index,
896
- time: /* @__PURE__ */ new Date(),
897
- ...status2
898
- });
899
- } else if (type === "complete") {
900
- complete = status2;
901
- } else if (type == "unexpected_error") {
902
- console.error("Unexpected error", status2 == null ? void 0 : status2.message);
903
- fire_event({
904
- type: "status",
905
- stage: "error",
906
- message: "An Unexpected Error Occurred!",
907
- queue: true,
908
- endpoint: _endpoint,
909
- fn_index,
910
- time: /* @__PURE__ */ new Date()
911
- });
912
- } else if (type === "log") {
913
- fire_event({
914
- type: "log",
915
- log: data2.log,
916
- level: data2.level,
917
- endpoint: _endpoint,
918
- fn_index
919
- });
920
- return;
921
- } else if (type === "generating") {
922
- fire_event({
923
- type: "status",
924
- time: /* @__PURE__ */ new Date(),
925
- ...status2,
926
- stage: status2 == null ? void 0 : status2.stage,
927
- queue: true,
928
- endpoint: _endpoint,
929
- fn_index
930
- });
931
- }
932
- if (data2) {
933
- fire_event({
934
- type: "data",
935
- time: /* @__PURE__ */ new Date(),
936
- data: transform_files ? transform_output(
937
- data2.data,
938
- api_info,
939
- config.root,
940
- config.root_url
941
- ) : data2.data,
942
- endpoint: _endpoint,
943
- fn_index
944
- });
945
- if (complete) {
805
+ if (data2) {
806
+ fire_event({
807
+ type: "data",
808
+ time: /* @__PURE__ */ new Date(),
809
+ data: transform_files ? transform_output(
810
+ data2.data,
811
+ api_info,
812
+ config.root,
813
+ config.root_url
814
+ ) : data2.data,
815
+ endpoint: _endpoint,
816
+ fn_index
817
+ });
818
+ if (complete) {
819
+ fire_event({
820
+ type: "status",
821
+ time: /* @__PURE__ */ new Date(),
822
+ ...complete,
823
+ stage: status == null ? void 0 : status.stage,
824
+ queue: true,
825
+ endpoint: _endpoint,
826
+ fn_index
827
+ });
828
+ eventSource.close();
829
+ }
830
+ }
831
+ };
832
+ } else if (protocol == "sse_v1") {
833
+ fire_event({
834
+ type: "status",
835
+ stage: "pending",
836
+ queue: true,
837
+ endpoint: _endpoint,
838
+ fn_index,
839
+ time: /* @__PURE__ */ new Date()
840
+ });
841
+ post_data2(
842
+ `${config.root}/queue/join?${url_params}`,
843
+ {
844
+ ...payload,
845
+ session_hash
846
+ },
847
+ hf_token
848
+ ).then(([response, status]) => {
849
+ if (status === 503) {
850
+ fire_event({
851
+ type: "status",
852
+ stage: "error",
853
+ message: QUEUE_FULL_MSG,
854
+ queue: true,
855
+ endpoint: _endpoint,
856
+ fn_index,
857
+ time: /* @__PURE__ */ new Date()
858
+ });
859
+ } else if (status !== 200) {
860
+ fire_event({
861
+ type: "status",
862
+ stage: "error",
863
+ message: BROKEN_CONNECTION_MSG,
864
+ queue: true,
865
+ endpoint: _endpoint,
866
+ fn_index,
867
+ time: /* @__PURE__ */ new Date()
868
+ });
869
+ } else {
870
+ event_id = response.event_id;
871
+ let callback = async function(_data) {
872
+ try {
873
+ const { type, status: status2, data: data2 } = handle_message(
874
+ _data,
875
+ last_status[fn_index]
876
+ );
877
+ if (type == "heartbeat") {
878
+ return;
879
+ }
880
+ if (type === "update" && status2 && !complete) {
946
881
  fire_event({
947
882
  type: "status",
883
+ endpoint: _endpoint,
884
+ fn_index,
948
885
  time: /* @__PURE__ */ new Date(),
949
- ...complete,
886
+ ...status2
887
+ });
888
+ } else if (type === "complete") {
889
+ complete = status2;
890
+ } else if (type == "unexpected_error") {
891
+ console.error("Unexpected error", status2 == null ? void 0 : status2.message);
892
+ fire_event({
893
+ type: "status",
894
+ stage: "error",
895
+ message: "An Unexpected Error Occurred!",
896
+ queue: true,
897
+ endpoint: _endpoint,
898
+ fn_index,
899
+ time: /* @__PURE__ */ new Date()
900
+ });
901
+ } else if (type === "log") {
902
+ fire_event({
903
+ type: "log",
904
+ log: data2.log,
905
+ level: data2.level,
906
+ endpoint: _endpoint,
907
+ fn_index
908
+ });
909
+ return;
910
+ } else if (type === "generating") {
911
+ fire_event({
912
+ type: "status",
913
+ time: /* @__PURE__ */ new Date(),
914
+ ...status2,
950
915
  stage: status2 == null ? void 0 : status2.stage,
951
916
  queue: true,
952
917
  endpoint: _endpoint,
953
918
  fn_index
954
919
  });
955
920
  }
956
- }
957
- if ((status2 == null ? void 0 : status2.stage) === "complete" || (status2 == null ? void 0 : status2.stage) === "error") {
958
- if (event_callbacks[event_id]) {
959
- delete event_callbacks[event_id];
960
- if (Object.keys(event_callbacks).length === 0) {
961
- close_stream();
921
+ if (data2) {
922
+ fire_event({
923
+ type: "data",
924
+ time: /* @__PURE__ */ new Date(),
925
+ data: transform_files ? transform_output(
926
+ data2.data,
927
+ api_info,
928
+ config.root,
929
+ config.root_url
930
+ ) : data2.data,
931
+ endpoint: _endpoint,
932
+ fn_index
933
+ });
934
+ if (complete) {
935
+ fire_event({
936
+ type: "status",
937
+ time: /* @__PURE__ */ new Date(),
938
+ ...complete,
939
+ stage: status2 == null ? void 0 : status2.stage,
940
+ queue: true,
941
+ endpoint: _endpoint,
942
+ fn_index
943
+ });
944
+ }
945
+ }
946
+ if ((status2 == null ? void 0 : status2.stage) === "complete" || (status2 == null ? void 0 : status2.stage) === "error") {
947
+ if (event_callbacks[event_id]) {
948
+ delete event_callbacks[event_id];
949
+ if (Object.keys(event_callbacks).length === 0) {
950
+ close_stream();
951
+ }
962
952
  }
963
953
  }
954
+ } catch (e) {
955
+ console.error("Unexpected client exception", e);
956
+ fire_event({
957
+ type: "status",
958
+ stage: "error",
959
+ message: "An Unexpected Error Occurred!",
960
+ queue: true,
961
+ endpoint: _endpoint,
962
+ fn_index,
963
+ time: /* @__PURE__ */ new Date()
964
+ });
965
+ close_stream();
964
966
  }
965
- } catch (e) {
966
- console.error("Unexpected client exception", e);
967
- fire_event({
968
- type: "status",
969
- stage: "error",
970
- message: "An Unexpected Error Occurred!",
971
- queue: true,
972
- endpoint: _endpoint,
973
- fn_index,
974
- time: /* @__PURE__ */ new Date()
975
- });
976
- close_stream();
967
+ };
968
+ if (event_id in pending_stream_messages) {
969
+ pending_stream_messages[event_id].forEach(
970
+ (msg) => callback(msg)
971
+ );
972
+ delete pending_stream_messages[event_id];
973
+ }
974
+ event_callbacks[event_id] = callback;
975
+ if (!stream_open) {
976
+ open_stream();
977
977
  }
978
- };
979
- if (event_id in pending_stream_messages) {
980
- pending_stream_messages[event_id].forEach(
981
- (msg) => callback(msg)
982
- );
983
- delete pending_stream_messages[event_id];
984
- }
985
- event_callbacks[event_id] = callback;
986
- if (!stream_open) {
987
- open_stream();
988
978
  }
989
- }
990
- });
979
+ });
980
+ }
991
981
  }
992
- });
982
+ );
993
983
  function fire_event(event) {
994
984
  const narrowed_listener_map = listener_map;
995
985
  const listeners = narrowed_listener_map[event.type] || [];
@@ -1037,18 +1027,11 @@ function api_factory(fetch_implementation, EventSource_factory) {
1037
1027
  cancel_request = { event_id };
1038
1028
  }
1039
1029
  try {
1040
- await fetch_implementation(
1041
- `${http_protocol}//${resolve_root(
1042
- host,
1043
- config.path,
1044
- true
1045
- )}/reset`,
1046
- {
1047
- headers: { "Content-Type": "application/json" },
1048
- method: "POST",
1049
- body: JSON.stringify(cancel_request)
1050
- }
1051
- );
1030
+ await fetch_implementation(`${config.root}/reset`, {
1031
+ headers: { "Content-Type": "application/json" },
1032
+ method: "POST",
1033
+ body: JSON.stringify(cancel_request)
1034
+ });
1052
1035
  } catch (e) {
1053
1036
  console.warn(
1054
1037
  "The `/reset` endpoint could not be called. Subsequent endpoint results may be unreliable."
@@ -1074,13 +1057,7 @@ function api_factory(fetch_implementation, EventSource_factory) {
1074
1057
  let params = new URLSearchParams({
1075
1058
  session_hash
1076
1059
  }).toString();
1077
- let url = new URL(
1078
- `${http_protocol}//${resolve_root(
1079
- host,
1080
- config.path,
1081
- true
1082
- )}/queue/data?${params}`
1083
- );
1060
+ let url = new URL(`${config.root}/queue/data?${params}`);
1084
1061
  event_stream = new EventSource(url);
1085
1062
  event_stream.onmessage = async function(event) {
1086
1063
  let _data = JSON.parse(event.data);
@@ -1118,14 +1095,10 @@ function api_factory(fetch_implementation, EventSource_factory) {
1118
1095
  if ((_a = component == null ? void 0 : component.props) == null ? void 0 : _a.root_url) {
1119
1096
  root_url = component.props.root_url;
1120
1097
  } else {
1121
- root_url = `${http_protocol}//${resolve_root(
1122
- host,
1123
- config.path,
1124
- true
1125
- )}/`;
1098
+ root_url = config.root;
1126
1099
  }
1127
1100
  const response = await fetch_implementation(
1128
- `${root_url}component_server/`,
1101
+ `${root_url}/component_server/`,
1129
1102
  {
1130
1103
  method: "POST",
1131
1104
  body: JSON.stringify({