@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/CHANGELOG.md +6 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/index.js +384 -411
- package/package.json +1 -1
- package/src/client.ts +419 -444
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
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
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
|
-
|
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
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
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
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
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
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
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
|
-
|
558
|
-
|
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
|
-
|
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
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
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
|
-
}
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
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
|
-
...
|
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
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
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
|
-
|
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
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
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
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
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
|
-
|
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
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
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
|
-
...
|
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
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
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
|
-
|
837
|
-
|
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
|
-
|
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
|
-
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
|
-
...
|
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
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
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
|
-
}
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
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
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
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 =
|
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({
|