@gradio/client 0.9.3 → 0.10.0
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/CHANGELOG.md +13 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/index.js +396 -412
- package/package.json +1 -1
- package/src/client.ts +428 -445
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
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
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
|
-
|
563
|
-
}
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
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
|
-
}
|
617
|
+
});
|
618
|
+
} else if (protocol == "ws") {
|
607
619
|
fire_event({
|
608
620
|
type: "status",
|
609
|
-
stage: "
|
610
|
-
|
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
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
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
|
-
|
633
|
-
|
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
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
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
|
-
}
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
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) {
|
658
|
+
fire_event({
|
659
|
+
type: "status",
|
660
|
+
endpoint: _endpoint,
|
661
|
+
fn_index,
|
662
|
+
time: /* @__PURE__ */ new Date(),
|
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") {
|
707
684
|
fire_event({
|
708
685
|
type: "status",
|
709
686
|
time: /* @__PURE__ */ new Date(),
|
710
|
-
...
|
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
|
-
|
721
|
-
|
722
|
-
"
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
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
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
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 (
|
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
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
if (
|
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
|
-
...
|
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
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
}
|
912
|
-
|
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
|
-
...
|
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: (status2 == null ? void 0 : status2.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
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
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
|
+
});
|
962
944
|
}
|
963
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
|
+
}
|
952
|
+
}
|
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
|
-
}
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
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
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
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,14 +1057,8 @@ 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
|
-
|
1079
|
-
host,
|
1080
|
-
config.path,
|
1081
|
-
true
|
1082
|
-
)}/queue/data?${params}`
|
1083
|
-
);
|
1084
|
-
event_stream = new EventSource(url);
|
1060
|
+
let url = new URL(`${config.root}/queue/data?${params}`);
|
1061
|
+
event_stream = EventSource_factory(url);
|
1085
1062
|
event_stream.onmessage = async function(event) {
|
1086
1063
|
let _data = JSON.parse(event.data);
|
1087
1064
|
const event_id = _data.event_id;
|
@@ -1100,6 +1077,17 @@ function api_factory(fetch_implementation, EventSource_factory) {
|
|
1100
1077
|
pending_stream_messages[event_id].push(_data);
|
1101
1078
|
}
|
1102
1079
|
};
|
1080
|
+
event_stream.onerror = async function(event) {
|
1081
|
+
await Promise.all(
|
1082
|
+
Object.keys(event_callbacks).map(
|
1083
|
+
(event_id) => event_callbacks[event_id]({
|
1084
|
+
msg: "unexpected_error",
|
1085
|
+
message: BROKEN_CONNECTION_MSG
|
1086
|
+
})
|
1087
|
+
)
|
1088
|
+
);
|
1089
|
+
close_stream();
|
1090
|
+
};
|
1103
1091
|
}
|
1104
1092
|
function close_stream() {
|
1105
1093
|
stream_open = false;
|
@@ -1118,14 +1106,10 @@ function api_factory(fetch_implementation, EventSource_factory) {
|
|
1118
1106
|
if ((_a = component == null ? void 0 : component.props) == null ? void 0 : _a.root_url) {
|
1119
1107
|
root_url = component.props.root_url;
|
1120
1108
|
} else {
|
1121
|
-
root_url =
|
1122
|
-
host,
|
1123
|
-
config.path,
|
1124
|
-
true
|
1125
|
-
)}/`;
|
1109
|
+
root_url = config.root;
|
1126
1110
|
}
|
1127
1111
|
const response = await fetch_implementation(
|
1128
|
-
`${root_url}component_server/`,
|
1112
|
+
`${root_url}/component_server/`,
|
1129
1113
|
{
|
1130
1114
|
method: "POST",
|
1131
1115
|
body: JSON.stringify({
|