@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/src/client.ts CHANGED
@@ -461,492 +461,484 @@ export function api_factory(
461
461
  url_params = new URLSearchParams(window.location.search).toString();
462
462
  }
463
463
 
464
- handle_blob(
465
- `${http_protocol}//${resolve_root(host, config.path, true)}`,
466
- data,
467
- api_info,
468
- hf_token
469
- ).then((_payload) => {
470
- payload = { data: _payload || [], event_data, fn_index, trigger_id };
471
- if (skip_queue(fn_index, config)) {
472
- fire_event({
473
- type: "status",
474
- endpoint: _endpoint,
475
- stage: "pending",
476
- queue: false,
464
+ handle_blob(`${config.root}`, data, api_info, hf_token).then(
465
+ (_payload) => {
466
+ payload = {
467
+ data: _payload || [],
468
+ event_data,
477
469
  fn_index,
478
- time: new Date()
479
- });
470
+ trigger_id
471
+ };
472
+ if (skip_queue(fn_index, config)) {
473
+ fire_event({
474
+ type: "status",
475
+ endpoint: _endpoint,
476
+ stage: "pending",
477
+ queue: false,
478
+ fn_index,
479
+ time: new Date()
480
+ });
480
481
 
481
- post_data(
482
- `${http_protocol}//${resolve_root(host, config.path, true)}/run${
483
- _endpoint.startsWith("/") ? _endpoint : `/${_endpoint}`
484
- }${url_params ? "?" + url_params : ""}`,
485
- {
486
- ...payload,
487
- session_hash
488
- },
489
- hf_token
490
- )
491
- .then(([output, status_code]) => {
492
- const data = transform_files
493
- ? transform_output(
494
- output.data,
495
- api_info,
496
- config.root,
497
- config.root_url
498
- )
499
- : output.data;
500
- if (status_code == 200) {
501
- fire_event({
502
- type: "data",
503
- endpoint: _endpoint,
504
- fn_index,
505
- data: data,
506
- time: new Date()
507
- });
482
+ post_data(
483
+ `${config.root}/run${
484
+ _endpoint.startsWith("/") ? _endpoint : `/${_endpoint}`
485
+ }${url_params ? "?" + url_params : ""}`,
486
+ {
487
+ ...payload,
488
+ session_hash
489
+ },
490
+ hf_token
491
+ )
492
+ .then(([output, status_code]) => {
493
+ const data = transform_files
494
+ ? transform_output(
495
+ output.data,
496
+ api_info,
497
+ config.root,
498
+ config.root_url
499
+ )
500
+ : output.data;
501
+ if (status_code == 200) {
502
+ fire_event({
503
+ type: "data",
504
+ endpoint: _endpoint,
505
+ fn_index,
506
+ data: data,
507
+ time: new Date()
508
+ });
508
509
 
509
- fire_event({
510
- type: "status",
511
- endpoint: _endpoint,
512
- fn_index,
513
- stage: "complete",
514
- eta: output.average_duration,
515
- queue: false,
516
- time: new Date()
517
- });
518
- } else {
510
+ fire_event({
511
+ type: "status",
512
+ endpoint: _endpoint,
513
+ fn_index,
514
+ stage: "complete",
515
+ eta: output.average_duration,
516
+ queue: false,
517
+ time: new Date()
518
+ });
519
+ } else {
520
+ fire_event({
521
+ type: "status",
522
+ stage: "error",
523
+ endpoint: _endpoint,
524
+ fn_index,
525
+ message: output.error,
526
+ queue: false,
527
+ time: new Date()
528
+ });
529
+ }
530
+ })
531
+ .catch((e) => {
519
532
  fire_event({
520
533
  type: "status",
521
534
  stage: "error",
535
+ message: e.message,
522
536
  endpoint: _endpoint,
523
537
  fn_index,
524
- message: output.error,
525
538
  queue: false,
526
539
  time: new Date()
527
540
  });
528
- }
529
- })
530
- .catch((e) => {
531
- fire_event({
532
- type: "status",
533
- stage: "error",
534
- message: e.message,
535
- endpoint: _endpoint,
536
- fn_index,
537
- queue: false,
538
- time: new Date()
539
541
  });
542
+ } else if (protocol == "ws") {
543
+ fire_event({
544
+ type: "status",
545
+ stage: "pending",
546
+ queue: true,
547
+ endpoint: _endpoint,
548
+ fn_index,
549
+ time: new Date()
540
550
  });
541
- } else if (protocol == "ws") {
542
- fire_event({
543
- type: "status",
544
- stage: "pending",
545
- queue: true,
546
- endpoint: _endpoint,
547
- fn_index,
548
- time: new Date()
549
- });
550
- let url = new URL(`${ws_protocol}://${resolve_root(
551
- host,
552
- config.path,
553
- true
554
- )}
551
+ let url = new URL(`${ws_protocol}://${resolve_root(
552
+ host,
553
+ config.path,
554
+ true
555
+ )}
555
556
  /queue/join${url_params ? "?" + url_params : ""}`);
556
557
 
557
- if (jwt) {
558
- url.searchParams.set("__sign", jwt);
559
- }
560
-
561
- websocket = new WebSocket(url);
562
-
563
- websocket.onclose = (evt) => {
564
- if (!evt.wasClean) {
565
- fire_event({
566
- type: "status",
567
- stage: "error",
568
- broken: true,
569
- message: BROKEN_CONNECTION_MSG,
570
- queue: true,
571
- endpoint: _endpoint,
572
- fn_index,
573
- time: new Date()
574
- });
558
+ if (jwt) {
559
+ url.searchParams.set("__sign", jwt);
575
560
  }
576
- };
577
561
 
578
- websocket.onmessage = function (event) {
579
- const _data = JSON.parse(event.data);
580
- const { type, status, data } = handle_message(
581
- _data,
582
- last_status[fn_index]
583
- );
562
+ websocket = new WebSocket(url);
584
563
 
585
- if (type === "update" && status && !complete) {
586
- // call 'status' listeners
587
- fire_event({
588
- type: "status",
589
- endpoint: _endpoint,
590
- fn_index,
591
- time: new Date(),
592
- ...status
593
- });
594
- if (status.stage === "error") {
595
- websocket.close();
564
+ websocket.onclose = (evt) => {
565
+ if (!evt.wasClean) {
566
+ fire_event({
567
+ type: "status",
568
+ stage: "error",
569
+ broken: true,
570
+ message: BROKEN_CONNECTION_MSG,
571
+ queue: true,
572
+ endpoint: _endpoint,
573
+ fn_index,
574
+ time: new Date()
575
+ });
596
576
  }
597
- } else if (type === "hash") {
598
- websocket.send(JSON.stringify({ fn_index, session_hash }));
599
- return;
600
- } else if (type === "data") {
601
- websocket.send(JSON.stringify({ ...payload, session_hash }));
602
- } else if (type === "complete") {
603
- complete = status;
604
- } else if (type === "log") {
605
- fire_event({
606
- type: "log",
607
- log: data.log,
608
- level: data.level,
609
- endpoint: _endpoint,
610
- fn_index
611
- });
612
- } else if (type === "generating") {
613
- fire_event({
614
- type: "status",
615
- time: new Date(),
616
- ...status,
617
- stage: status?.stage!,
618
- queue: true,
619
- endpoint: _endpoint,
620
- fn_index
621
- });
622
- }
623
- if (data) {
624
- fire_event({
625
- type: "data",
626
- time: new Date(),
627
- data: transform_files
628
- ? transform_output(
629
- data.data,
630
- api_info,
631
- config.root,
632
- config.root_url
633
- )
634
- : data.data,
635
- endpoint: _endpoint,
636
- fn_index
637
- });
577
+ };
578
+
579
+ websocket.onmessage = function (event) {
580
+ const _data = JSON.parse(event.data);
581
+ const { type, status, data } = handle_message(
582
+ _data,
583
+ last_status[fn_index]
584
+ );
638
585
 
639
- if (complete) {
586
+ if (type === "update" && status && !complete) {
587
+ // call 'status' listeners
588
+ fire_event({
589
+ type: "status",
590
+ endpoint: _endpoint,
591
+ fn_index,
592
+ time: new Date(),
593
+ ...status
594
+ });
595
+ if (status.stage === "error") {
596
+ websocket.close();
597
+ }
598
+ } else if (type === "hash") {
599
+ websocket.send(JSON.stringify({ fn_index, session_hash }));
600
+ return;
601
+ } else if (type === "data") {
602
+ websocket.send(JSON.stringify({ ...payload, session_hash }));
603
+ } else if (type === "complete") {
604
+ complete = status;
605
+ } else if (type === "log") {
606
+ fire_event({
607
+ type: "log",
608
+ log: data.log,
609
+ level: data.level,
610
+ endpoint: _endpoint,
611
+ fn_index
612
+ });
613
+ } else if (type === "generating") {
640
614
  fire_event({
641
615
  type: "status",
642
616
  time: new Date(),
643
- ...complete,
617
+ ...status,
644
618
  stage: status?.stage!,
645
619
  queue: true,
646
620
  endpoint: _endpoint,
647
621
  fn_index
648
622
  });
649
- websocket.close();
650
623
  }
651
- }
652
- };
653
-
654
- // different ws contract for gradio versions older than 3.6.0
655
- //@ts-ignore
656
- if (semiver(config.version || "2.0.0", "3.6") < 0) {
657
- addEventListener("open", () =>
658
- websocket.send(JSON.stringify({ hash: session_hash }))
659
- );
660
- }
661
- } else if (protocol == "sse") {
662
- fire_event({
663
- type: "status",
664
- stage: "pending",
665
- queue: true,
666
- endpoint: _endpoint,
667
- fn_index,
668
- time: new Date()
669
- });
670
- var params = new URLSearchParams({
671
- fn_index: fn_index.toString(),
672
- session_hash: session_hash
673
- }).toString();
674
- let url = new URL(
675
- `${http_protocol}//${resolve_root(
676
- host,
677
- config.path,
678
- true
679
- )}/queue/join?${url_params ? url_params + "&" : ""}${params}`
680
- );
624
+ if (data) {
625
+ fire_event({
626
+ type: "data",
627
+ time: new Date(),
628
+ data: transform_files
629
+ ? transform_output(
630
+ data.data,
631
+ api_info,
632
+ config.root,
633
+ config.root_url
634
+ )
635
+ : data.data,
636
+ endpoint: _endpoint,
637
+ fn_index
638
+ });
681
639
 
682
- eventSource = EventSource_factory(url);
640
+ if (complete) {
641
+ fire_event({
642
+ type: "status",
643
+ time: new Date(),
644
+ ...complete,
645
+ stage: status?.stage!,
646
+ queue: true,
647
+ endpoint: _endpoint,
648
+ fn_index
649
+ });
650
+ websocket.close();
651
+ }
652
+ }
653
+ };
683
654
 
684
- eventSource.onmessage = async function (event) {
685
- const _data = JSON.parse(event.data);
686
- const { type, status, data } = handle_message(
687
- _data,
688
- last_status[fn_index]
655
+ // different ws contract for gradio versions older than 3.6.0
656
+ //@ts-ignore
657
+ if (semiver(config.version || "2.0.0", "3.6") < 0) {
658
+ addEventListener("open", () =>
659
+ websocket.send(JSON.stringify({ hash: session_hash }))
660
+ );
661
+ }
662
+ } else if (protocol == "sse") {
663
+ fire_event({
664
+ type: "status",
665
+ stage: "pending",
666
+ queue: true,
667
+ endpoint: _endpoint,
668
+ fn_index,
669
+ time: new Date()
670
+ });
671
+ var params = new URLSearchParams({
672
+ fn_index: fn_index.toString(),
673
+ session_hash: session_hash
674
+ }).toString();
675
+ let url = new URL(
676
+ `${config.root}/queue/join?${
677
+ url_params ? url_params + "&" : ""
678
+ }${params}`
689
679
  );
690
680
 
691
- if (type === "update" && status && !complete) {
692
- // call 'status' listeners
693
- fire_event({
694
- type: "status",
695
- endpoint: _endpoint,
696
- fn_index,
697
- time: new Date(),
698
- ...status
699
- });
700
- if (status.stage === "error") {
701
- eventSource.close();
702
- }
703
- } else if (type === "data") {
704
- event_id = _data.event_id as string;
705
- let [_, status] = await post_data(
706
- `${http_protocol}//${resolve_root(
707
- host,
708
- config.path,
709
- true
710
- )}/queue/data`,
711
- {
712
- ...payload,
713
- session_hash,
714
- event_id
715
- },
716
- hf_token
681
+ eventSource = EventSource_factory(url);
682
+
683
+ eventSource.onmessage = async function (event) {
684
+ const _data = JSON.parse(event.data);
685
+ const { type, status, data } = handle_message(
686
+ _data,
687
+ last_status[fn_index]
717
688
  );
718
- if (status !== 200) {
689
+
690
+ if (type === "update" && status && !complete) {
691
+ // call 'status' listeners
719
692
  fire_event({
720
693
  type: "status",
721
- stage: "error",
722
- message: BROKEN_CONNECTION_MSG,
723
- queue: true,
724
694
  endpoint: _endpoint,
725
695
  fn_index,
726
- time: new Date()
696
+ time: new Date(),
697
+ ...status
727
698
  });
728
- eventSource.close();
729
- }
730
- } else if (type === "complete") {
731
- complete = status;
732
- } else if (type === "log") {
733
- fire_event({
734
- type: "log",
735
- log: data.log,
736
- level: data.level,
737
- endpoint: _endpoint,
738
- fn_index
739
- });
740
- } else if (type === "generating") {
741
- fire_event({
742
- type: "status",
743
- time: new Date(),
744
- ...status,
745
- stage: status?.stage!,
746
- queue: true,
747
- endpoint: _endpoint,
748
- fn_index
749
- });
750
- }
751
- if (data) {
752
- fire_event({
753
- type: "data",
754
- time: new Date(),
755
- data: transform_files
756
- ? transform_output(
757
- data.data,
758
- api_info,
759
- config.root,
760
- config.root_url
761
- )
762
- : data.data,
763
- endpoint: _endpoint,
764
- fn_index
765
- });
766
-
767
- if (complete) {
699
+ if (status.stage === "error") {
700
+ eventSource.close();
701
+ }
702
+ } else if (type === "data") {
703
+ event_id = _data.event_id as string;
704
+ let [_, status] = await post_data(
705
+ `${config.root}/queue/data`,
706
+ {
707
+ ...payload,
708
+ session_hash,
709
+ event_id
710
+ },
711
+ hf_token
712
+ );
713
+ if (status !== 200) {
714
+ fire_event({
715
+ type: "status",
716
+ stage: "error",
717
+ message: BROKEN_CONNECTION_MSG,
718
+ queue: true,
719
+ endpoint: _endpoint,
720
+ fn_index,
721
+ time: new Date()
722
+ });
723
+ eventSource.close();
724
+ }
725
+ } else if (type === "complete") {
726
+ complete = status;
727
+ } else if (type === "log") {
728
+ fire_event({
729
+ type: "log",
730
+ log: data.log,
731
+ level: data.level,
732
+ endpoint: _endpoint,
733
+ fn_index
734
+ });
735
+ } else if (type === "generating") {
768
736
  fire_event({
769
737
  type: "status",
770
738
  time: new Date(),
771
- ...complete,
739
+ ...status,
772
740
  stage: status?.stage!,
773
741
  queue: true,
774
742
  endpoint: _endpoint,
775
743
  fn_index
776
744
  });
777
- eventSource.close();
778
745
  }
779
- }
780
- };
781
- } else if (protocol == "sse_v1") {
782
- fire_event({
783
- type: "status",
784
- stage: "pending",
785
- queue: true,
786
- endpoint: _endpoint,
787
- fn_index,
788
- time: new Date()
789
- });
790
-
791
- post_data(
792
- `${http_protocol}//${resolve_root(
793
- host,
794
- config.path,
795
- true
796
- )}/queue/join?${url_params}`,
797
- {
798
- ...payload,
799
- session_hash
800
- },
801
- hf_token
802
- ).then(([response, status]) => {
803
- if (status === 503) {
804
- fire_event({
805
- type: "status",
806
- stage: "error",
807
- message: QUEUE_FULL_MSG,
808
- queue: true,
809
- endpoint: _endpoint,
810
- fn_index,
811
- time: new Date()
812
- });
813
- } else if (status !== 200) {
814
- fire_event({
815
- type: "status",
816
- stage: "error",
817
- message: BROKEN_CONNECTION_MSG,
818
- queue: true,
819
- endpoint: _endpoint,
820
- fn_index,
821
- time: new Date()
822
- });
823
- } else {
824
- event_id = response.event_id as string;
825
- let callback = async function (_data: object): void {
826
- try {
827
- const { type, status, data } = handle_message(
828
- _data,
829
- last_status[fn_index]
830
- );
831
-
832
- // TODO: Find out how to print this information
833
- // only during testing
834
- // console.info("data", type, status, data);
746
+ if (data) {
747
+ fire_event({
748
+ type: "data",
749
+ time: new Date(),
750
+ data: transform_files
751
+ ? transform_output(
752
+ data.data,
753
+ api_info,
754
+ config.root,
755
+ config.root_url
756
+ )
757
+ : data.data,
758
+ endpoint: _endpoint,
759
+ fn_index
760
+ });
835
761
 
836
- if (type == "heartbeat") {
837
- return;
838
- }
762
+ if (complete) {
763
+ fire_event({
764
+ type: "status",
765
+ time: new Date(),
766
+ ...complete,
767
+ stage: status?.stage!,
768
+ queue: true,
769
+ endpoint: _endpoint,
770
+ fn_index
771
+ });
772
+ eventSource.close();
773
+ }
774
+ }
775
+ };
776
+ } else if (protocol == "sse_v1") {
777
+ fire_event({
778
+ type: "status",
779
+ stage: "pending",
780
+ queue: true,
781
+ endpoint: _endpoint,
782
+ fn_index,
783
+ time: new Date()
784
+ });
839
785
 
840
- if (type === "update" && status && !complete) {
841
- // call 'status' listeners
842
- fire_event({
843
- type: "status",
844
- endpoint: _endpoint,
845
- fn_index,
846
- time: new Date(),
847
- ...status
848
- });
849
- } else if (type === "complete") {
850
- complete = status;
851
- } else if (type == "unexpected_error") {
852
- console.error("Unexpected error", status?.message);
853
- fire_event({
854
- type: "status",
855
- stage: "error",
856
- message: "An Unexpected Error Occurred!",
857
- queue: true,
858
- endpoint: _endpoint,
859
- fn_index,
860
- time: new Date()
861
- });
862
- } else if (type === "log") {
863
- fire_event({
864
- type: "log",
865
- log: data.log,
866
- level: data.level,
867
- endpoint: _endpoint,
868
- fn_index
869
- });
870
- return;
871
- } else if (type === "generating") {
872
- fire_event({
873
- type: "status",
874
- time: new Date(),
875
- ...status,
876
- stage: status?.stage!,
877
- queue: true,
878
- endpoint: _endpoint,
879
- fn_index
880
- });
881
- }
882
- if (data) {
883
- fire_event({
884
- type: "data",
885
- time: new Date(),
886
- data: transform_files
887
- ? transform_output(
888
- data.data,
889
- api_info,
890
- config.root,
891
- config.root_url
892
- )
893
- : data.data,
894
- endpoint: _endpoint,
895
- fn_index
896
- });
786
+ post_data(
787
+ `${config.root}/queue/join?${url_params}`,
788
+ {
789
+ ...payload,
790
+ session_hash
791
+ },
792
+ hf_token
793
+ ).then(([response, status]) => {
794
+ if (status === 503) {
795
+ fire_event({
796
+ type: "status",
797
+ stage: "error",
798
+ message: QUEUE_FULL_MSG,
799
+ queue: true,
800
+ endpoint: _endpoint,
801
+ fn_index,
802
+ time: new Date()
803
+ });
804
+ } else if (status !== 200) {
805
+ fire_event({
806
+ type: "status",
807
+ stage: "error",
808
+ message: BROKEN_CONNECTION_MSG,
809
+ queue: true,
810
+ endpoint: _endpoint,
811
+ fn_index,
812
+ time: new Date()
813
+ });
814
+ } else {
815
+ event_id = response.event_id as string;
816
+ let callback = async function (_data: object): void {
817
+ try {
818
+ const { type, status, data } = handle_message(
819
+ _data,
820
+ last_status[fn_index]
821
+ );
822
+
823
+ // TODO: Find out how to print this information
824
+ // only during testing
825
+ // console.info("data", type, status, data);
826
+
827
+ if (type == "heartbeat") {
828
+ return;
829
+ }
897
830
 
898
- if (complete) {
831
+ if (type === "update" && status && !complete) {
832
+ // call 'status' listeners
899
833
  fire_event({
900
834
  type: "status",
835
+ endpoint: _endpoint,
836
+ fn_index,
901
837
  time: new Date(),
902
- ...complete,
838
+ ...status
839
+ });
840
+ } else if (type === "complete") {
841
+ complete = status;
842
+ } else if (type == "unexpected_error") {
843
+ console.error("Unexpected error", status?.message);
844
+ fire_event({
845
+ type: "status",
846
+ stage: "error",
847
+ message: "An Unexpected Error Occurred!",
848
+ queue: true,
849
+ endpoint: _endpoint,
850
+ fn_index,
851
+ time: new Date()
852
+ });
853
+ } else if (type === "log") {
854
+ fire_event({
855
+ type: "log",
856
+ log: data.log,
857
+ level: data.level,
858
+ endpoint: _endpoint,
859
+ fn_index
860
+ });
861
+ return;
862
+ } else if (type === "generating") {
863
+ fire_event({
864
+ type: "status",
865
+ time: new Date(),
866
+ ...status,
903
867
  stage: status?.stage!,
904
868
  queue: true,
905
869
  endpoint: _endpoint,
906
870
  fn_index
907
871
  });
908
872
  }
909
- }
873
+ if (data) {
874
+ fire_event({
875
+ type: "data",
876
+ time: new Date(),
877
+ data: transform_files
878
+ ? transform_output(
879
+ data.data,
880
+ api_info,
881
+ config.root,
882
+ config.root_url
883
+ )
884
+ : data.data,
885
+ endpoint: _endpoint,
886
+ fn_index
887
+ });
888
+
889
+ if (complete) {
890
+ fire_event({
891
+ type: "status",
892
+ time: new Date(),
893
+ ...complete,
894
+ stage: status?.stage!,
895
+ queue: true,
896
+ endpoint: _endpoint,
897
+ fn_index
898
+ });
899
+ }
900
+ }
910
901
 
911
- if (
912
- status?.stage === "complete" ||
913
- status?.stage === "error"
914
- ) {
915
- if (event_callbacks[event_id]) {
916
- delete event_callbacks[event_id];
917
- if (Object.keys(event_callbacks).length === 0) {
918
- close_stream();
902
+ if (
903
+ status?.stage === "complete" ||
904
+ status?.stage === "error"
905
+ ) {
906
+ if (event_callbacks[event_id]) {
907
+ delete event_callbacks[event_id];
908
+ if (Object.keys(event_callbacks).length === 0) {
909
+ close_stream();
910
+ }
919
911
  }
920
912
  }
913
+ } catch (e) {
914
+ console.error("Unexpected client exception", e);
915
+ fire_event({
916
+ type: "status",
917
+ stage: "error",
918
+ message: "An Unexpected Error Occurred!",
919
+ queue: true,
920
+ endpoint: _endpoint,
921
+ fn_index,
922
+ time: new Date()
923
+ });
924
+ close_stream();
921
925
  }
922
- } catch (e) {
923
- console.error("Unexpected client exception", e);
924
- fire_event({
925
- type: "status",
926
- stage: "error",
927
- message: "An Unexpected Error Occurred!",
928
- queue: true,
929
- endpoint: _endpoint,
930
- fn_index,
931
- time: new Date()
932
- });
933
- close_stream();
926
+ };
927
+ if (event_id in pending_stream_messages) {
928
+ pending_stream_messages[event_id].forEach((msg) =>
929
+ callback(msg)
930
+ );
931
+ delete pending_stream_messages[event_id];
932
+ }
933
+ event_callbacks[event_id] = callback;
934
+ if (!stream_open) {
935
+ open_stream();
934
936
  }
935
- };
936
- if (event_id in pending_stream_messages) {
937
- pending_stream_messages[event_id].forEach((msg) =>
938
- callback(msg)
939
- );
940
- delete pending_stream_messages[event_id];
941
- }
942
- event_callbacks[event_id] = callback;
943
- if (!stream_open) {
944
- open_stream();
945
937
  }
946
- }
947
- });
938
+ });
939
+ }
948
940
  }
949
- });
941
+ );
950
942
 
951
943
  function fire_event<K extends EventType>(event: Event<K>): void {
952
944
  const narrowed_listener_map: ListenerMap<K> = listener_map;
@@ -1008,18 +1000,11 @@ export function api_factory(
1008
1000
  }
1009
1001
 
1010
1002
  try {
1011
- await fetch_implementation(
1012
- `${http_protocol}//${resolve_root(
1013
- host,
1014
- config.path,
1015
- true
1016
- )}/reset`,
1017
- {
1018
- headers: { "Content-Type": "application/json" },
1019
- method: "POST",
1020
- body: JSON.stringify(cancel_request)
1021
- }
1022
- );
1003
+ await fetch_implementation(`${config.root}/reset`, {
1004
+ headers: { "Content-Type": "application/json" },
1005
+ method: "POST",
1006
+ body: JSON.stringify(cancel_request)
1007
+ });
1023
1008
  } catch (e) {
1024
1009
  console.warn(
1025
1010
  "The `/reset` endpoint could not be called. Subsequent endpoint results may be unreliable."
@@ -1048,13 +1033,7 @@ export function api_factory(
1048
1033
  let params = new URLSearchParams({
1049
1034
  session_hash: session_hash
1050
1035
  }).toString();
1051
- let url = new URL(
1052
- `${http_protocol}//${resolve_root(
1053
- host,
1054
- config.path,
1055
- true
1056
- )}/queue/data?${params}`
1057
- );
1036
+ let url = new URL(`${config.root}/queue/data?${params}`);
1058
1037
  event_stream = new EventSource(url);
1059
1038
  event_stream.onmessage = async function (event) {
1060
1039
  let _data = JSON.parse(event.data);
@@ -1100,14 +1079,10 @@ export function api_factory(
1100
1079
  if (component?.props?.root_url) {
1101
1080
  root_url = component.props.root_url;
1102
1081
  } else {
1103
- root_url = `${http_protocol}//${resolve_root(
1104
- host,
1105
- config.path,
1106
- true
1107
- )}/`;
1082
+ root_url = config.root;
1108
1083
  }
1109
1084
  const response = await fetch_implementation(
1110
- `${root_url}component_server/`,
1085
+ `${root_url}/component_server/`,
1111
1086
  {
1112
1087
  method: "POST",
1113
1088
  body: JSON.stringify({