@gradio/client 0.9.2 → 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/CHANGELOG.md +12 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/index.js +398 -412
- package/package.json +1 -1
- package/src/client.ts +432 -444
package/dist/index.js
CHANGED
@@ -400,6 +400,7 @@ function api_factory(fetch_implementation, EventSource_factory) {
|
|
400
400
|
const session_hash = Math.random().toString(36).substring(2);
|
401
401
|
const last_status = {};
|
402
402
|
let stream_open = false;
|
403
|
+
let pending_stream_messages = {};
|
403
404
|
let event_stream = null;
|
404
405
|
const event_callbacks = {};
|
405
406
|
let config;
|
@@ -544,445 +545,441 @@ function api_factory(fetch_implementation, EventSource_factory) {
|
|
544
545
|
if (typeof window !== "undefined") {
|
545
546
|
url_params = new URLSearchParams(window.location.search).toString();
|
546
547
|
}
|
547
|
-
handle_blob2(
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
).then((_payload) => {
|
553
|
-
payload = { data: _payload || [], event_data, fn_index, trigger_id };
|
554
|
-
if (skip_queue(fn_index, config)) {
|
555
|
-
fire_event({
|
556
|
-
type: "status",
|
557
|
-
endpoint: _endpoint,
|
558
|
-
stage: "pending",
|
559
|
-
queue: false,
|
548
|
+
handle_blob2(`${config.root}`, data, api_info, hf_token).then(
|
549
|
+
(_payload) => {
|
550
|
+
payload = {
|
551
|
+
data: _payload || [],
|
552
|
+
event_data,
|
560
553
|
fn_index,
|
561
|
-
|
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
|
-
|
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) => {
|
595
608
|
fire_event({
|
596
609
|
type: "status",
|
597
610
|
stage: "error",
|
611
|
+
message: e.message,
|
598
612
|
endpoint: _endpoint,
|
599
613
|
fn_index,
|
600
|
-
message: output.error,
|
601
614
|
queue: false,
|
602
615
|
time: /* @__PURE__ */ new Date()
|
603
616
|
});
|
604
|
-
}
|
605
|
-
}
|
617
|
+
});
|
618
|
+
} else if (protocol == "ws") {
|
606
619
|
fire_event({
|
607
620
|
type: "status",
|
608
|
-
stage: "
|
609
|
-
|
621
|
+
stage: "pending",
|
622
|
+
queue: true,
|
610
623
|
endpoint: _endpoint,
|
611
624
|
fn_index,
|
612
|
-
queue: false,
|
613
625
|
time: /* @__PURE__ */ new Date()
|
614
626
|
});
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
queue: true,
|
621
|
-
endpoint: _endpoint,
|
622
|
-
fn_index,
|
623
|
-
time: /* @__PURE__ */ new Date()
|
624
|
-
});
|
625
|
-
let url = new URL(`${ws_protocol}://${resolve_root(
|
626
|
-
host,
|
627
|
-
config.path,
|
628
|
-
true
|
629
|
-
)}
|
627
|
+
let url = new URL(`${ws_protocol}://${resolve_root(
|
628
|
+
host,
|
629
|
+
config.path,
|
630
|
+
true
|
631
|
+
)}
|
630
632
|
/queue/join${url_params ? "?" + url_params : ""}`);
|
631
|
-
|
632
|
-
|
633
|
-
}
|
634
|
-
websocket = new WebSocket(url);
|
635
|
-
websocket.onclose = (evt) => {
|
636
|
-
if (!evt.wasClean) {
|
637
|
-
fire_event({
|
638
|
-
type: "status",
|
639
|
-
stage: "error",
|
640
|
-
broken: true,
|
641
|
-
message: BROKEN_CONNECTION_MSG,
|
642
|
-
queue: true,
|
643
|
-
endpoint: _endpoint,
|
644
|
-
fn_index,
|
645
|
-
time: /* @__PURE__ */ new Date()
|
646
|
-
});
|
633
|
+
if (jwt) {
|
634
|
+
url.searchParams.set("__sign", jwt);
|
647
635
|
}
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
...status
|
662
|
-
});
|
663
|
-
if (status.stage === "error") {
|
664
|
-
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
|
+
});
|
665
649
|
}
|
666
|
-
}
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
fire_event({
|
675
|
-
type: "log",
|
676
|
-
log: data2.log,
|
677
|
-
level: data2.level,
|
678
|
-
endpoint: _endpoint,
|
679
|
-
fn_index
|
680
|
-
});
|
681
|
-
} else if (type === "generating") {
|
682
|
-
fire_event({
|
683
|
-
type: "status",
|
684
|
-
time: /* @__PURE__ */ new Date(),
|
685
|
-
...status,
|
686
|
-
stage: status == null ? void 0 : status.stage,
|
687
|
-
queue: true,
|
688
|
-
endpoint: _endpoint,
|
689
|
-
fn_index
|
690
|
-
});
|
691
|
-
}
|
692
|
-
if (data2) {
|
693
|
-
fire_event({
|
694
|
-
type: "data",
|
695
|
-
time: /* @__PURE__ */ new Date(),
|
696
|
-
data: transform_files ? transform_output(
|
697
|
-
data2.data,
|
698
|
-
api_info,
|
699
|
-
config.root,
|
700
|
-
config.root_url
|
701
|
-
) : data2.data,
|
702
|
-
endpoint: _endpoint,
|
703
|
-
fn_index
|
704
|
-
});
|
705
|
-
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) {
|
706
658
|
fire_event({
|
707
659
|
type: "status",
|
660
|
+
endpoint: _endpoint,
|
661
|
+
fn_index,
|
708
662
|
time: /* @__PURE__ */ new Date(),
|
709
|
-
...
|
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,
|
710
688
|
stage: status == null ? void 0 : status.stage,
|
711
689
|
queue: true,
|
712
690
|
endpoint: _endpoint,
|
713
691
|
fn_index
|
714
692
|
});
|
715
|
-
websocket.close();
|
716
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
|
+
);
|
717
726
|
}
|
718
|
-
}
|
719
|
-
|
720
|
-
|
721
|
-
"
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
});
|
734
|
-
var params = new URLSearchParams({
|
735
|
-
fn_index: fn_index.toString(),
|
736
|
-
session_hash
|
737
|
-
}).toString();
|
738
|
-
let url = new URL(
|
739
|
-
`${http_protocol}//${resolve_root(
|
740
|
-
host,
|
741
|
-
config.path,
|
742
|
-
true
|
743
|
-
)}/queue/join?${url_params ? url_params + "&" : ""}${params}`
|
744
|
-
);
|
745
|
-
eventSource = EventSource_factory(url);
|
746
|
-
eventSource.onmessage = async function(event) {
|
747
|
-
const _data = JSON.parse(event.data);
|
748
|
-
const { type, status, data: data2 } = handle_message(
|
749
|
-
_data,
|
750
|
-
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}`
|
751
742
|
);
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
...status
|
759
|
-
});
|
760
|
-
if (status.stage === "error") {
|
761
|
-
eventSource.close();
|
762
|
-
}
|
763
|
-
} else if (type === "data") {
|
764
|
-
event_id = _data.event_id;
|
765
|
-
let [_, status2] = await post_data2(
|
766
|
-
`${http_protocol}//${resolve_root(
|
767
|
-
host,
|
768
|
-
config.path,
|
769
|
-
true
|
770
|
-
)}/queue/data`,
|
771
|
-
{
|
772
|
-
...payload,
|
773
|
-
session_hash,
|
774
|
-
event_id
|
775
|
-
},
|
776
|
-
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]
|
777
749
|
);
|
778
|
-
if (
|
750
|
+
if (type === "update" && status && !complete) {
|
779
751
|
fire_event({
|
780
752
|
type: "status",
|
781
|
-
stage: "error",
|
782
|
-
message: BROKEN_CONNECTION_MSG,
|
783
|
-
queue: true,
|
784
753
|
endpoint: _endpoint,
|
785
754
|
fn_index,
|
786
|
-
time: /* @__PURE__ */ new Date()
|
755
|
+
time: /* @__PURE__ */ new Date(),
|
756
|
+
...status
|
787
757
|
});
|
788
|
-
|
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
|
-
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") {
|
825
795
|
fire_event({
|
826
796
|
type: "status",
|
827
797
|
time: /* @__PURE__ */ new Date(),
|
828
|
-
...
|
798
|
+
...status,
|
829
799
|
stage: status == null ? void 0 : status.stage,
|
830
800
|
queue: true,
|
831
801
|
endpoint: _endpoint,
|
832
802
|
fn_index
|
833
803
|
});
|
834
|
-
eventSource.close();
|
835
804
|
}
|
836
|
-
|
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
|
-
fire_event({
|
913
|
-
type: "log",
|
914
|
-
log: data2.log,
|
915
|
-
level: data2.level,
|
916
|
-
endpoint: _endpoint,
|
917
|
-
fn_index
|
918
|
-
});
|
919
|
-
return;
|
920
|
-
} else if (type === "generating") {
|
921
|
-
fire_event({
|
922
|
-
type: "status",
|
923
|
-
time: /* @__PURE__ */ new Date(),
|
924
|
-
...status2,
|
925
|
-
stage: status2 == null ? void 0 : status2.stage,
|
926
|
-
queue: true,
|
927
|
-
endpoint: _endpoint,
|
928
|
-
fn_index
|
929
|
-
});
|
930
|
-
}
|
931
|
-
if (data2) {
|
932
|
-
fire_event({
|
933
|
-
type: "data",
|
934
|
-
time: /* @__PURE__ */ new Date(),
|
935
|
-
data: transform_files ? transform_output(
|
936
|
-
data2.data,
|
937
|
-
api_info,
|
938
|
-
config.root,
|
939
|
-
config.root_url
|
940
|
-
) : data2.data,
|
941
|
-
endpoint: _endpoint,
|
942
|
-
fn_index
|
943
|
-
});
|
944
|
-
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) {
|
945
881
|
fire_event({
|
946
882
|
type: "status",
|
883
|
+
endpoint: _endpoint,
|
884
|
+
fn_index,
|
947
885
|
time: /* @__PURE__ */ new Date(),
|
948
|
-
...
|
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,
|
949
915
|
stage: status2 == null ? void 0 : status2.stage,
|
950
916
|
queue: true,
|
951
917
|
endpoint: _endpoint,
|
952
918
|
fn_index
|
953
919
|
});
|
954
920
|
}
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
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
|
+
});
|
961
944
|
}
|
962
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();
|
963
966
|
}
|
964
|
-
}
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
});
|
975
|
-
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();
|
976
977
|
}
|
977
|
-
};
|
978
|
-
event_callbacks[event_id] = callback;
|
979
|
-
if (!stream_open) {
|
980
|
-
open_stream();
|
981
978
|
}
|
982
|
-
}
|
983
|
-
}
|
979
|
+
});
|
980
|
+
}
|
984
981
|
}
|
985
|
-
|
982
|
+
);
|
986
983
|
function fire_event(event) {
|
987
984
|
const narrowed_listener_map = listener_map;
|
988
985
|
const listeners = narrowed_listener_map[event.type] || [];
|
@@ -1030,18 +1027,11 @@ function api_factory(fetch_implementation, EventSource_factory) {
|
|
1030
1027
|
cancel_request = { event_id };
|
1031
1028
|
}
|
1032
1029
|
try {
|
1033
|
-
await fetch_implementation(
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
)}/reset`,
|
1039
|
-
{
|
1040
|
-
headers: { "Content-Type": "application/json" },
|
1041
|
-
method: "POST",
|
1042
|
-
body: JSON.stringify(cancel_request)
|
1043
|
-
}
|
1044
|
-
);
|
1030
|
+
await fetch_implementation(`${config.root}/reset`, {
|
1031
|
+
headers: { "Content-Type": "application/json" },
|
1032
|
+
method: "POST",
|
1033
|
+
body: JSON.stringify(cancel_request)
|
1034
|
+
});
|
1045
1035
|
} catch (e) {
|
1046
1036
|
console.warn(
|
1047
1037
|
"The `/reset` endpoint could not be called. Subsequent endpoint results may be unreliable."
|
@@ -1067,25 +1057,25 @@ function api_factory(fetch_implementation, EventSource_factory) {
|
|
1067
1057
|
let params = new URLSearchParams({
|
1068
1058
|
session_hash
|
1069
1059
|
}).toString();
|
1070
|
-
let url = new URL(
|
1071
|
-
`${http_protocol}//${resolve_root(
|
1072
|
-
host,
|
1073
|
-
config.path,
|
1074
|
-
true
|
1075
|
-
)}/queue/data?${params}`
|
1076
|
-
);
|
1060
|
+
let url = new URL(`${config.root}/queue/data?${params}`);
|
1077
1061
|
event_stream = new EventSource(url);
|
1078
1062
|
event_stream.onmessage = async function(event) {
|
1079
1063
|
let _data = JSON.parse(event.data);
|
1080
|
-
|
1064
|
+
const event_id = _data.event_id;
|
1065
|
+
if (!event_id) {
|
1081
1066
|
await Promise.all(
|
1082
1067
|
Object.keys(event_callbacks).map(
|
1083
|
-
(
|
1068
|
+
(event_id2) => event_callbacks[event_id2](_data)
|
1084
1069
|
)
|
1085
1070
|
);
|
1086
|
-
|
1071
|
+
} else if (event_callbacks[event_id]) {
|
1072
|
+
await event_callbacks[event_id](_data);
|
1073
|
+
} else {
|
1074
|
+
if (!pending_stream_messages[event_id]) {
|
1075
|
+
pending_stream_messages[event_id] = [];
|
1076
|
+
}
|
1077
|
+
pending_stream_messages[event_id].push(_data);
|
1087
1078
|
}
|
1088
|
-
await event_callbacks[_data.event_id](_data);
|
1089
1079
|
};
|
1090
1080
|
}
|
1091
1081
|
function close_stream() {
|
@@ -1105,14 +1095,10 @@ function api_factory(fetch_implementation, EventSource_factory) {
|
|
1105
1095
|
if ((_a = component == null ? void 0 : component.props) == null ? void 0 : _a.root_url) {
|
1106
1096
|
root_url = component.props.root_url;
|
1107
1097
|
} else {
|
1108
|
-
root_url =
|
1109
|
-
host,
|
1110
|
-
config.path,
|
1111
|
-
true
|
1112
|
-
)}/`;
|
1098
|
+
root_url = config.root;
|
1113
1099
|
}
|
1114
1100
|
const response = await fetch_implementation(
|
1115
|
-
`${root_url}component_server/`,
|
1101
|
+
`${root_url}/component_server/`,
|
1116
1102
|
{
|
1117
1103
|
method: "POST",
|
1118
1104
|
body: JSON.stringify({
|
@@ -1555,8 +1541,7 @@ function handle_message(data, last_status) {
|
|
1555
1541
|
message: !data.success ? data.output.error : void 0,
|
1556
1542
|
stage: data.success ? "complete" : "error",
|
1557
1543
|
code: data.code,
|
1558
|
-
progress_data: data.progress_data
|
1559
|
-
eta: data.output.average_duration
|
1544
|
+
progress_data: data.progress_data
|
1560
1545
|
},
|
1561
1546
|
data: data.success ? data.output : null
|
1562
1547
|
};
|
@@ -1569,7 +1554,8 @@ function handle_message(data, last_status) {
|
|
1569
1554
|
code: data.code,
|
1570
1555
|
size: data.rank,
|
1571
1556
|
position: 0,
|
1572
|
-
success: data.success
|
1557
|
+
success: data.success,
|
1558
|
+
eta: data.eta
|
1573
1559
|
}
|
1574
1560
|
};
|
1575
1561
|
}
|