@gradio/client 2.0.3 → 2.1.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 +15 -0
- package/dist/browser.js +328 -302
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/helpers/init_helpers.d.ts.map +1 -1
- package/dist/index.js +48 -20
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/submit.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +10 -4
- package/src/helpers/init_helpers.ts +50 -17
- package/src/types.ts +1 -0
- package/src/utils/submit.ts +9 -2
package/dist/browser.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const
|
|
2
|
-
async function
|
|
1
|
+
const We = "host", Te = "queue/data", Ze = "queue/join", ye = "upload", Ke = "login", V = "config", Ve = "info", Ye = "runtime", Qe = "sleeptime", Xe = "heartbeat", et = "component_server", tt = "reset", st = "cancel", nt = "app_id", Ae = "This application is currently busy. Please try again. ", L = "Connection errored out. ", N = "Could not resolve app config. ", ot = "Could not get space status. ", it = "Could not get API info. ", le = "Space metadata could not be loaded. ", rt = "Invalid URL. A full URL path is required.", at = "Not authorized to access this space. ", xe = "Invalid credentials. Could not login. ", ct = "Login credentials are required to access this space.", ut = "File system access is only available in Node.js environments", Ce = "Root URL not found in client config", lt = "Error uploading file";
|
|
2
|
+
async function be(e, s, t) {
|
|
3
3
|
try {
|
|
4
4
|
return (await (await fetch(`https://huggingface.co/api/spaces/${e}/jwt`, {
|
|
5
5
|
headers: {
|
|
@@ -11,48 +11,66 @@ async function ye(e, s, t) {
|
|
|
11
11
|
return !1;
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
function
|
|
14
|
+
function pt(e) {
|
|
15
15
|
let s = {};
|
|
16
16
|
return e.forEach(({ api_name: t, id: n }) => {
|
|
17
17
|
t && (s[t] = n);
|
|
18
18
|
}), s;
|
|
19
19
|
}
|
|
20
|
-
async function
|
|
20
|
+
async function dt(e) {
|
|
21
21
|
const s = this.options.token ? { Authorization: `Bearer ${this.options.token}` } : {};
|
|
22
|
-
s["Content-Type"] = "application/json", typeof window < "u" && window
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
if (s["Content-Type"] = "application/json", typeof window < "u" && window.gradio_config && location.origin !== "http://localhost:9876") {
|
|
23
|
+
if (window.gradio_config.current_page && (e = e.substring(0, e.lastIndexOf("/"))), window.gradio_config.dev_mode || typeof window < "u" && window?.BUILD_MODE === "dev") {
|
|
24
|
+
let t = ce(
|
|
25
|
+
e,
|
|
26
|
+
this.deep_link ? V + "?deep_link=" + this.deep_link : V
|
|
27
|
+
);
|
|
28
|
+
const n = await this.fetch(t, {
|
|
29
|
+
headers: s,
|
|
30
|
+
credentials: "include"
|
|
31
|
+
}), o = await ve(n, !!this.options.auth);
|
|
32
|
+
o.root = e || o.root, window.gradio_config = {
|
|
33
|
+
...o,
|
|
34
|
+
current_page: window.gradio_config.current_page
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return { ...window.gradio_config };
|
|
38
|
+
} else if (e) {
|
|
39
|
+
let t = ce(
|
|
40
|
+
e,
|
|
41
|
+
this.deep_link ? V + "?deep_link=" + this.deep_link : V
|
|
42
|
+
);
|
|
43
|
+
const n = await this.fetch(t, {
|
|
44
|
+
headers: s,
|
|
45
|
+
credentials: "include"
|
|
46
|
+
}), o = await ve(n, !!this.options.auth);
|
|
47
|
+
return o.root || (o.root = e), o;
|
|
48
|
+
}
|
|
49
|
+
throw new Error(N);
|
|
32
50
|
}
|
|
33
|
-
async function
|
|
51
|
+
async function ve(e, s) {
|
|
34
52
|
if (e?.status === 401 && !s) {
|
|
35
53
|
const n = (await e.json())?.detail?.auth_message;
|
|
36
|
-
throw new Error(n ||
|
|
54
|
+
throw new Error(n || ct);
|
|
37
55
|
} else if (e?.status === 401 && s)
|
|
38
|
-
throw new Error(
|
|
56
|
+
throw new Error(xe);
|
|
39
57
|
if (e?.status === 200) {
|
|
40
58
|
let t = await e.json();
|
|
41
59
|
return t.dependencies?.forEach((n, o) => {
|
|
42
60
|
n.id === void 0 && (n.id = o);
|
|
43
61
|
}), t;
|
|
44
62
|
} else if (e?.status === 401)
|
|
45
|
-
throw new Error(
|
|
46
|
-
throw new Error(
|
|
63
|
+
throw new Error(at);
|
|
64
|
+
throw new Error(N);
|
|
47
65
|
}
|
|
48
66
|
async function ht() {
|
|
49
|
-
const { http_protocol: e, host: s } = await
|
|
67
|
+
const { http_protocol: e, host: s } = await de(
|
|
50
68
|
this.app_reference,
|
|
51
69
|
this.options.token
|
|
52
70
|
);
|
|
53
71
|
try {
|
|
54
72
|
if (this.options.auth) {
|
|
55
|
-
const t = await
|
|
73
|
+
const t = await De(
|
|
56
74
|
e,
|
|
57
75
|
s,
|
|
58
76
|
this.options.auth,
|
|
@@ -65,12 +83,12 @@ async function ht() {
|
|
|
65
83
|
throw Error(t.message);
|
|
66
84
|
}
|
|
67
85
|
}
|
|
68
|
-
async function
|
|
86
|
+
async function De(e, s, t, n, o) {
|
|
69
87
|
const r = new FormData();
|
|
70
88
|
r.append("username", t?.[0]), r.append("password", t?.[1]);
|
|
71
89
|
let i = {};
|
|
72
90
|
o && (i.Authorization = `Bearer ${o}`);
|
|
73
|
-
const a = await n(`${e}//${s}/${
|
|
91
|
+
const a = await n(`${e}//${s}/${Ke}`, {
|
|
74
92
|
headers: i,
|
|
75
93
|
method: "POST",
|
|
76
94
|
body: r,
|
|
@@ -78,9 +96,9 @@ async function xe(e, s, t, n, o) {
|
|
|
78
96
|
});
|
|
79
97
|
if (a.status === 200)
|
|
80
98
|
return a.headers.get("set-cookie");
|
|
81
|
-
throw a.status === 401 ? new Error(
|
|
99
|
+
throw a.status === 401 ? new Error(xe) : new Error(le);
|
|
82
100
|
}
|
|
83
|
-
function
|
|
101
|
+
function ae(e) {
|
|
84
102
|
if (e.startsWith("http")) {
|
|
85
103
|
const { protocol: s, host: t, pathname: n } = new URL(e);
|
|
86
104
|
return {
|
|
@@ -95,32 +113,32 @@ function ie(e) {
|
|
|
95
113
|
host: new URL(e).host
|
|
96
114
|
};
|
|
97
115
|
}
|
|
98
|
-
const
|
|
116
|
+
const Ne = (e) => {
|
|
99
117
|
let s = [];
|
|
100
118
|
return e.split(/,(?=\s*[^\s=;]+=[^\s=;]+)/).forEach((n) => {
|
|
101
119
|
const [o, r] = n.split(";")[0].split("=");
|
|
102
120
|
o && r && s.push(`${o.trim()}=${r.trim()}`);
|
|
103
121
|
}), s;
|
|
104
|
-
},
|
|
105
|
-
async function
|
|
122
|
+
}, pe = /^[a-zA-Z0-9_\-\.]+\/[a-zA-Z0-9_\-\.]+$/, ft = /.*hf\.space\/{0,1}.*$/;
|
|
123
|
+
async function de(e, s) {
|
|
106
124
|
const t = {};
|
|
107
125
|
s && (t.Authorization = `Bearer ${s}`);
|
|
108
126
|
const n = e.trim().replace(/\/$/, "");
|
|
109
|
-
if (
|
|
127
|
+
if (pe.test(n))
|
|
110
128
|
try {
|
|
111
129
|
const r = (await (await fetch(
|
|
112
|
-
`https://huggingface.co/api/spaces/${n}/${
|
|
130
|
+
`https://huggingface.co/api/spaces/${n}/${We}`,
|
|
113
131
|
{ headers: t }
|
|
114
132
|
)).json()).host;
|
|
115
133
|
return {
|
|
116
134
|
space_id: e,
|
|
117
|
-
...
|
|
135
|
+
...ae(r)
|
|
118
136
|
};
|
|
119
137
|
} catch {
|
|
120
|
-
throw new Error(
|
|
138
|
+
throw new Error(le);
|
|
121
139
|
}
|
|
122
140
|
if (ft.test(n)) {
|
|
123
|
-
const { ws_protocol: o, http_protocol: r, host: i } =
|
|
141
|
+
const { ws_protocol: o, http_protocol: r, host: i } = ae(n);
|
|
124
142
|
return {
|
|
125
143
|
space_id: i.split("/")[0].replace(".hf.space", ""),
|
|
126
144
|
ws_protocol: o,
|
|
@@ -130,14 +148,14 @@ async function ue(e, s) {
|
|
|
130
148
|
}
|
|
131
149
|
return {
|
|
132
150
|
space_id: !1,
|
|
133
|
-
...
|
|
151
|
+
...ae(n)
|
|
134
152
|
};
|
|
135
153
|
}
|
|
136
|
-
const
|
|
154
|
+
const ce = (...e) => {
|
|
137
155
|
try {
|
|
138
156
|
return e.reduce((s, t) => (s = s.replace(/\/+$/, ""), t = t.replace(/^\/+/, ""), new URL(t, s + "/").toString()));
|
|
139
157
|
} catch {
|
|
140
|
-
throw new Error(
|
|
158
|
+
throw new Error(rt);
|
|
141
159
|
}
|
|
142
160
|
};
|
|
143
161
|
function _t(e, s, t) {
|
|
@@ -158,7 +176,7 @@ function _t(e, s, t) {
|
|
|
158
176
|
try {
|
|
159
177
|
c.forEach((m, w) => {
|
|
160
178
|
if (m === "state") {
|
|
161
|
-
const
|
|
179
|
+
const P = {
|
|
162
180
|
component: "state",
|
|
163
181
|
example: null,
|
|
164
182
|
parameter_default: null,
|
|
@@ -166,17 +184,17 @@ function _t(e, s, t) {
|
|
|
166
184
|
parameter_name: null,
|
|
167
185
|
hidden: !0
|
|
168
186
|
};
|
|
169
|
-
i.splice(w, 0,
|
|
187
|
+
i.splice(w, 0, P);
|
|
170
188
|
}
|
|
171
189
|
});
|
|
172
190
|
} catch (m) {
|
|
173
191
|
console.error(m);
|
|
174
192
|
}
|
|
175
193
|
}
|
|
176
|
-
const p = (c, m, w,
|
|
194
|
+
const p = (c, m, w, P) => ({
|
|
177
195
|
...c,
|
|
178
196
|
description: gt(c?.type, w),
|
|
179
|
-
type: mt(c?.type, m, w,
|
|
197
|
+
type: mt(c?.type, m, w, P) || ""
|
|
180
198
|
});
|
|
181
199
|
n[o][r] = {
|
|
182
200
|
parameters: i.map(
|
|
@@ -215,7 +233,7 @@ function mt(e, s, t, n) {
|
|
|
215
233
|
function gt(e, s) {
|
|
216
234
|
return s === "GallerySerializable" ? "array of [file, label] tuples" : s === "ListStringSerializable" ? "array of strings" : s === "FileSerializable" ? "array of files or single file" : e?.description;
|
|
217
235
|
}
|
|
218
|
-
function
|
|
236
|
+
function Ee(e, s) {
|
|
219
237
|
switch (e.msg) {
|
|
220
238
|
case "send_data":
|
|
221
239
|
return { type: "data" };
|
|
@@ -226,7 +244,7 @@ function be(e, s) {
|
|
|
226
244
|
type: "update",
|
|
227
245
|
status: {
|
|
228
246
|
queue: !0,
|
|
229
|
-
message:
|
|
247
|
+
message: Ae,
|
|
230
248
|
stage: "error",
|
|
231
249
|
code: e.code,
|
|
232
250
|
success: e.success
|
|
@@ -388,12 +406,12 @@ async function yt() {
|
|
|
388
406
|
if (typeof window < "u" && window.gradio_api_info)
|
|
389
407
|
o = window.gradio_api_info;
|
|
390
408
|
else {
|
|
391
|
-
const r =
|
|
409
|
+
const r = ce(s.root, this.api_prefix, Ve);
|
|
392
410
|
if (n = await this.fetch(r, {
|
|
393
411
|
headers: t,
|
|
394
412
|
credentials: "include"
|
|
395
413
|
}), !n.ok)
|
|
396
|
-
throw new Error(
|
|
414
|
+
throw new Error(L);
|
|
397
415
|
o = await n.json();
|
|
398
416
|
}
|
|
399
417
|
return "api" in o && (o = o.api), o.named_endpoints["/predict"] && !o.unnamed_endpoints[0] && (o.unnamed_endpoints[0] = o.named_endpoints["/predict"]), _t(o, s, this.api_map);
|
|
@@ -412,7 +430,7 @@ async function bt(e, s, t) {
|
|
|
412
430
|
l.append("files", c);
|
|
413
431
|
});
|
|
414
432
|
try {
|
|
415
|
-
const c = t ? `${e}${this.api_prefix}/${
|
|
433
|
+
const c = t ? `${e}${this.api_prefix}/${ye}?upload_id=${t}` : `${e}${this.api_prefix}/${ye}`;
|
|
416
434
|
i = await this.fetch(c, {
|
|
417
435
|
method: "POST",
|
|
418
436
|
body: l,
|
|
@@ -420,7 +438,7 @@ async function bt(e, s, t) {
|
|
|
420
438
|
credentials: "include"
|
|
421
439
|
});
|
|
422
440
|
} catch (c) {
|
|
423
|
-
throw new Error(
|
|
441
|
+
throw new Error(L + c.message);
|
|
424
442
|
}
|
|
425
443
|
if (!i.ok) {
|
|
426
444
|
const c = await i.text();
|
|
@@ -440,14 +458,14 @@ const vt = {
|
|
|
440
458
|
}, St = {
|
|
441
459
|
radix: 1024,
|
|
442
460
|
unit: ["b", "Kb", "Mb", "Gb", "Tb", "Pb", "Eb", "Zb", "Yb"]
|
|
443
|
-
},
|
|
461
|
+
}, Se = {
|
|
444
462
|
si: vt,
|
|
445
463
|
iec: Et,
|
|
446
464
|
jedec: St
|
|
447
465
|
};
|
|
448
466
|
function $t(e, s = 1, t = "jedec") {
|
|
449
467
|
e = Math.abs(e);
|
|
450
|
-
const { radix: n, unit: o } =
|
|
468
|
+
const { radix: n, unit: o } = Se[t] || Se.jedec;
|
|
451
469
|
let r = 0;
|
|
452
470
|
for (; e >= n; )
|
|
453
471
|
e /= n, ++r;
|
|
@@ -469,7 +487,7 @@ async function kt(e, s, t, n) {
|
|
|
469
487
|
async (i) => {
|
|
470
488
|
if (i.error)
|
|
471
489
|
throw new Error(i.error);
|
|
472
|
-
return i.files ? i.files.map((a, u) => new
|
|
490
|
+
return i.files ? i.files.map((a, u) => new X({
|
|
473
491
|
...e[u],
|
|
474
492
|
path: a,
|
|
475
493
|
url: `${s}${this.api_prefix}/file=${a}`
|
|
@@ -480,7 +498,7 @@ async function kt(e, s, t, n) {
|
|
|
480
498
|
}
|
|
481
499
|
async function Xt(e, s) {
|
|
482
500
|
return e.map(
|
|
483
|
-
(t) => new
|
|
501
|
+
(t) => new X({
|
|
484
502
|
path: t.name,
|
|
485
503
|
orig_name: t.name,
|
|
486
504
|
blob: t,
|
|
@@ -490,7 +508,7 @@ async function Xt(e, s) {
|
|
|
490
508
|
})
|
|
491
509
|
);
|
|
492
510
|
}
|
|
493
|
-
class
|
|
511
|
+
class X {
|
|
494
512
|
path;
|
|
495
513
|
url;
|
|
496
514
|
orig_name;
|
|
@@ -515,7 +533,7 @@ class Y {
|
|
|
515
533
|
this.path = s, this.url = t, this.orig_name = n, this.size = o, this.blob = t ? void 0 : r, this.is_stream = i, this.mime_type = a, this.alt_text = u, this.b64 = l;
|
|
516
534
|
}
|
|
517
535
|
}
|
|
518
|
-
class
|
|
536
|
+
class Le {
|
|
519
537
|
type;
|
|
520
538
|
command;
|
|
521
539
|
meta;
|
|
@@ -525,7 +543,7 @@ class Ne {
|
|
|
525
543
|
}
|
|
526
544
|
}
|
|
527
545
|
const Rt = typeof process < "u" && process.versions && process.versions.node;
|
|
528
|
-
function
|
|
546
|
+
function $e(e, s, t) {
|
|
529
547
|
for (; t.length > 1; ) {
|
|
530
548
|
const o = t.shift();
|
|
531
549
|
if (typeof o == "string" || typeof o == "number")
|
|
@@ -539,14 +557,14 @@ function Ee(e, s, t) {
|
|
|
539
557
|
else
|
|
540
558
|
throw new Error("Invalid key type");
|
|
541
559
|
}
|
|
542
|
-
async function
|
|
560
|
+
async function ue(e, s = void 0, t = [], n = !1, o = void 0) {
|
|
543
561
|
if (Array.isArray(e)) {
|
|
544
562
|
let r = [];
|
|
545
563
|
return await Promise.all(
|
|
546
564
|
e.map(async (i, a) => {
|
|
547
565
|
let u = t.slice();
|
|
548
566
|
u.push(String(a));
|
|
549
|
-
const l = await
|
|
567
|
+
const l = await ue(
|
|
550
568
|
e[a],
|
|
551
569
|
n ? o?.parameters[a]?.component || void 0 : s,
|
|
552
570
|
u,
|
|
@@ -570,7 +588,7 @@ async function re(e, s = void 0, t = [], n = !1, o = void 0) {
|
|
|
570
588
|
for (const i of Object.keys(e)) {
|
|
571
589
|
const a = [...t, i], u = e[i];
|
|
572
590
|
r = r.concat(
|
|
573
|
-
await
|
|
591
|
+
await ue(
|
|
574
592
|
u,
|
|
575
593
|
void 0,
|
|
576
594
|
a,
|
|
@@ -606,7 +624,7 @@ function es(e) {
|
|
|
606
624
|
meta: { _type: "gradio.FileData" }
|
|
607
625
|
};
|
|
608
626
|
if (Rt)
|
|
609
|
-
return new
|
|
627
|
+
return new Le("upload_file", {
|
|
610
628
|
path: e,
|
|
611
629
|
name: e,
|
|
612
630
|
orig_path: e
|
|
@@ -623,7 +641,7 @@ function es(e) {
|
|
|
623
641
|
"Invalid input: must be a URL, File, Blob, or Buffer object."
|
|
624
642
|
);
|
|
625
643
|
}
|
|
626
|
-
function
|
|
644
|
+
function Y(e, s, t, n, o = !1) {
|
|
627
645
|
if (n === "input" && !o)
|
|
628
646
|
throw new Error("Invalid code path. Cannot skip state inputs for input.");
|
|
629
647
|
if (n === "output" && o)
|
|
@@ -654,7 +672,7 @@ function K(e, s, t, n, o = !1) {
|
|
|
654
672
|
async function At(e, s, t) {
|
|
655
673
|
const n = this;
|
|
656
674
|
await xt(n, s);
|
|
657
|
-
const o = await
|
|
675
|
+
const o = await ue(
|
|
658
676
|
s,
|
|
659
677
|
void 0,
|
|
660
678
|
[],
|
|
@@ -674,46 +692,46 @@ async function At(e, s, t) {
|
|
|
674
692
|
})
|
|
675
693
|
)).forEach(({ path: i, file_url: a, type: u, name: l }) => {
|
|
676
694
|
if (u === "Gallery")
|
|
677
|
-
|
|
695
|
+
$e(s, a, i);
|
|
678
696
|
else if (a) {
|
|
679
|
-
const p = new
|
|
680
|
-
|
|
697
|
+
const p = new X({ path: a, orig_name: l });
|
|
698
|
+
$e(s, p, i);
|
|
681
699
|
}
|
|
682
700
|
}), s;
|
|
683
701
|
}
|
|
684
702
|
async function xt(e, s) {
|
|
685
703
|
if (!(e.config?.root || e.config?.root_url))
|
|
686
|
-
throw new Error(
|
|
687
|
-
await
|
|
704
|
+
throw new Error(Ce);
|
|
705
|
+
await Pe(e, s);
|
|
688
706
|
}
|
|
689
|
-
async function
|
|
707
|
+
async function Pe(e, s, t = []) {
|
|
690
708
|
for (const n in s)
|
|
691
|
-
s[n] instanceof
|
|
709
|
+
s[n] instanceof Le ? await Ct(e, s, n) : typeof s[n] == "object" && s[n] !== null && await Pe(e, s[n], [...t, n]);
|
|
692
710
|
}
|
|
693
711
|
async function Ct(e, s, t) {
|
|
694
712
|
let n = s[t];
|
|
695
713
|
const o = e.config?.root || e.config?.root_url;
|
|
696
714
|
if (!o)
|
|
697
|
-
throw new Error(
|
|
715
|
+
throw new Error(Ce);
|
|
698
716
|
try {
|
|
699
717
|
let r, i;
|
|
700
718
|
if (typeof process < "u" && process.versions && process.versions.node) {
|
|
701
719
|
const p = await import("./__vite-browser-external-DYxpcVy9.js");
|
|
702
720
|
i = (await import("./__vite-browser-external-DYxpcVy9.js")).resolve(process.cwd(), n.meta.path), r = await p.readFile(i);
|
|
703
721
|
} else
|
|
704
|
-
throw new Error(
|
|
722
|
+
throw new Error(ut);
|
|
705
723
|
const a = new Blob([r], {
|
|
706
724
|
type: "application/octet-stream"
|
|
707
725
|
}), u = await e.upload_files(o, [a]), l = u.files && u.files[0];
|
|
708
726
|
if (l) {
|
|
709
|
-
const p = new
|
|
727
|
+
const p = new X({
|
|
710
728
|
path: l,
|
|
711
729
|
orig_name: n.meta.name || ""
|
|
712
730
|
});
|
|
713
731
|
s[t] = p;
|
|
714
732
|
}
|
|
715
733
|
} catch (r) {
|
|
716
|
-
console.error(
|
|
734
|
+
console.error(lt, r);
|
|
717
735
|
}
|
|
718
736
|
}
|
|
719
737
|
async function Dt(e, s, t) {
|
|
@@ -727,7 +745,7 @@ async function Dt(e, s, t) {
|
|
|
727
745
|
credentials: "include"
|
|
728
746
|
});
|
|
729
747
|
} catch {
|
|
730
|
-
return [{ error:
|
|
748
|
+
return [{ error: L }, 500];
|
|
731
749
|
}
|
|
732
750
|
let r, i;
|
|
733
751
|
try {
|
|
@@ -756,7 +774,7 @@ async function Nt(e, s = {}) {
|
|
|
756
774
|
u.type === "data" && (n && o(a), t = !0, a = u), u.type === "status" && (u.stage === "error" && r(u), u.stage === "complete" && (n = !0, t && o(a)));
|
|
757
775
|
});
|
|
758
776
|
}
|
|
759
|
-
async function
|
|
777
|
+
async function H(e, s, t) {
|
|
760
778
|
let n = s === "subdomain" ? `https://huggingface.co/api/spaces/by-subdomain/${e}` : `https://huggingface.co/api/spaces/${e}`, o, r;
|
|
761
779
|
try {
|
|
762
780
|
if (o = await fetch(n), r = o.status, r !== 200)
|
|
@@ -766,7 +784,7 @@ async function G(e, s, t) {
|
|
|
766
784
|
t({
|
|
767
785
|
status: "error",
|
|
768
786
|
load_status: "error",
|
|
769
|
-
message:
|
|
787
|
+
message: ot,
|
|
770
788
|
detail: "NOT_FOUND"
|
|
771
789
|
});
|
|
772
790
|
return;
|
|
@@ -785,7 +803,7 @@ async function G(e, s, t) {
|
|
|
785
803
|
message: "Space is asleep. Waking it up...",
|
|
786
804
|
detail: i
|
|
787
805
|
}), setTimeout(() => {
|
|
788
|
-
|
|
806
|
+
H(e, s, t);
|
|
789
807
|
}, 1e3);
|
|
790
808
|
break;
|
|
791
809
|
case "PAUSED":
|
|
@@ -794,7 +812,7 @@ async function G(e, s, t) {
|
|
|
794
812
|
load_status: "error",
|
|
795
813
|
message: "This space has been paused by the author. If you would like to try this demo, consider duplicating the space.",
|
|
796
814
|
detail: i,
|
|
797
|
-
discussions_enabled: await
|
|
815
|
+
discussions_enabled: await ke(a)
|
|
798
816
|
});
|
|
799
817
|
break;
|
|
800
818
|
case "RUNNING":
|
|
@@ -813,7 +831,7 @@ async function G(e, s, t) {
|
|
|
813
831
|
message: "Space is building...",
|
|
814
832
|
detail: i
|
|
815
833
|
}), setTimeout(() => {
|
|
816
|
-
|
|
834
|
+
H(e, s, t);
|
|
817
835
|
}, 1e3);
|
|
818
836
|
break;
|
|
819
837
|
case "APP_STARTING":
|
|
@@ -823,7 +841,7 @@ async function G(e, s, t) {
|
|
|
823
841
|
message: "Space is starting...",
|
|
824
842
|
detail: i
|
|
825
843
|
}), setTimeout(() => {
|
|
826
|
-
|
|
844
|
+
H(e, s, t);
|
|
827
845
|
}, 1e3);
|
|
828
846
|
break;
|
|
829
847
|
default:
|
|
@@ -832,27 +850,27 @@ async function G(e, s, t) {
|
|
|
832
850
|
load_status: "error",
|
|
833
851
|
message: "This space is experiencing an issue.",
|
|
834
852
|
detail: i,
|
|
835
|
-
discussions_enabled: await
|
|
853
|
+
discussions_enabled: await ke(a)
|
|
836
854
|
});
|
|
837
855
|
break;
|
|
838
856
|
}
|
|
839
857
|
}
|
|
840
|
-
const
|
|
858
|
+
const je = async (e, s) => {
|
|
841
859
|
let t = 0;
|
|
842
860
|
const n = 12, o = 5e3;
|
|
843
861
|
return new Promise((r) => {
|
|
844
|
-
|
|
862
|
+
H(
|
|
845
863
|
e,
|
|
846
|
-
|
|
864
|
+
pe.test(e) ? "space_name" : "subdomain",
|
|
847
865
|
(i) => {
|
|
848
866
|
s(i), i.status === "running" || i.status === "error" || i.status === "paused" || i.status === "space_error" ? r() : (i.status === "sleeping" || i.status === "building") && (t < n ? (t++, setTimeout(() => {
|
|
849
|
-
|
|
867
|
+
je(e, s).then(r);
|
|
850
868
|
}, o)) : r());
|
|
851
869
|
}
|
|
852
870
|
);
|
|
853
871
|
});
|
|
854
872
|
}, Lt = /^(?=[^]*\b[dD]iscussions{0,1}\b)(?=[^]*\b[dD]isabled\b)[^]*$/;
|
|
855
|
-
async function
|
|
873
|
+
async function ke(e) {
|
|
856
874
|
try {
|
|
857
875
|
const s = await fetch(
|
|
858
876
|
`https://huggingface.co/api/spaces/${e}/discussions`,
|
|
@@ -870,7 +888,7 @@ async function Pt(e, s) {
|
|
|
870
888
|
s && (t.Authorization = `Bearer ${s}`);
|
|
871
889
|
try {
|
|
872
890
|
const n = await fetch(
|
|
873
|
-
`https://huggingface.co/api/spaces/${e}/${
|
|
891
|
+
`https://huggingface.co/api/spaces/${e}/${Ye}`,
|
|
874
892
|
{ headers: t }
|
|
875
893
|
);
|
|
876
894
|
if (n.status !== 200)
|
|
@@ -881,7 +899,7 @@ async function Pt(e, s) {
|
|
|
881
899
|
throw new Error(n.message);
|
|
882
900
|
}
|
|
883
901
|
}
|
|
884
|
-
async function
|
|
902
|
+
async function jt(e, s, t) {
|
|
885
903
|
const n = {};
|
|
886
904
|
t && (n.Authorization = `Bearer ${t}`);
|
|
887
905
|
const o = {
|
|
@@ -889,7 +907,7 @@ async function It(e, s, t) {
|
|
|
889
907
|
};
|
|
890
908
|
try {
|
|
891
909
|
const r = await fetch(
|
|
892
|
-
`https://huggingface.co/api/spaces/${e}/${
|
|
910
|
+
`https://huggingface.co/api/spaces/${e}/${Qe}`,
|
|
893
911
|
{
|
|
894
912
|
method: "POST",
|
|
895
913
|
headers: { "Content-Type": "application/json", ...n },
|
|
@@ -905,7 +923,7 @@ async function It(e, s, t) {
|
|
|
905
923
|
throw new Error(r.message);
|
|
906
924
|
}
|
|
907
925
|
}
|
|
908
|
-
const
|
|
926
|
+
const Re = [
|
|
909
927
|
"cpu-basic",
|
|
910
928
|
"cpu-upgrade",
|
|
911
929
|
"cpu-xl",
|
|
@@ -920,22 +938,22 @@ const $e = [
|
|
|
920
938
|
"h100",
|
|
921
939
|
"h100x8"
|
|
922
940
|
];
|
|
923
|
-
async function
|
|
941
|
+
async function It(e, s) {
|
|
924
942
|
const { token: t, private: n, hardware: o, timeout: r, auth: i } = s;
|
|
925
|
-
if (o &&
|
|
943
|
+
if (o && !Re.includes(o))
|
|
926
944
|
throw new Error(
|
|
927
|
-
`Invalid hardware type provided. Valid types are: ${
|
|
945
|
+
`Invalid hardware type provided. Valid types are: ${Re.map((g) => `"${g}"`).join(",")}.`
|
|
928
946
|
);
|
|
929
|
-
const { http_protocol: a, host: u } = await
|
|
947
|
+
const { http_protocol: a, host: u } = await de(e, t);
|
|
930
948
|
let l = null;
|
|
931
949
|
if (i) {
|
|
932
|
-
const g = await
|
|
950
|
+
const g = await De(
|
|
933
951
|
a,
|
|
934
952
|
u,
|
|
935
953
|
i,
|
|
936
954
|
fetch
|
|
937
955
|
);
|
|
938
|
-
g && (l =
|
|
956
|
+
g && (l = Ne(g));
|
|
939
957
|
}
|
|
940
958
|
const p = {
|
|
941
959
|
Authorization: `Bearer ${t}`,
|
|
@@ -947,13 +965,13 @@ async function jt(e, s) {
|
|
|
947
965
|
repository: `${c}/${m}`
|
|
948
966
|
};
|
|
949
967
|
n && (w.private = !0);
|
|
950
|
-
let
|
|
968
|
+
let P;
|
|
951
969
|
try {
|
|
952
|
-
o || (
|
|
970
|
+
o || (P = await Pt(e, t));
|
|
953
971
|
} catch (g) {
|
|
954
|
-
throw Error(
|
|
972
|
+
throw Error(le + g.message);
|
|
955
973
|
}
|
|
956
|
-
const f = o ||
|
|
974
|
+
const f = o || P || "cpu-basic";
|
|
957
975
|
w.hardware = f;
|
|
958
976
|
try {
|
|
959
977
|
const g = await fetch(
|
|
@@ -966,15 +984,15 @@ async function jt(e, s) {
|
|
|
966
984
|
);
|
|
967
985
|
if (g.status === 409)
|
|
968
986
|
try {
|
|
969
|
-
return await
|
|
970
|
-
} catch (
|
|
971
|
-
throw console.error("Failed to connect Client instance:",
|
|
987
|
+
return await Q.connect(`${c}/${m}`, s);
|
|
988
|
+
} catch (z) {
|
|
989
|
+
throw console.error("Failed to connect Client instance:", z), z;
|
|
972
990
|
}
|
|
973
991
|
else if (g.status !== 200)
|
|
974
992
|
throw new Error(g.statusText);
|
|
975
|
-
const
|
|
976
|
-
return await
|
|
977
|
-
Ut(
|
|
993
|
+
const J = await g.json();
|
|
994
|
+
return await jt(`${c}/${m}`, r || 300, t), await Q.connect(
|
|
995
|
+
Ut(J.url),
|
|
978
996
|
s
|
|
979
997
|
);
|
|
980
998
|
} catch (g) {
|
|
@@ -1027,7 +1045,7 @@ function Bt(e) {
|
|
|
1027
1045
|
e.substring(n + t[0].length)
|
|
1028
1046
|
];
|
|
1029
1047
|
}
|
|
1030
|
-
function
|
|
1048
|
+
function Oe(e, s, t) {
|
|
1031
1049
|
e.get(s) || e.set(s, t);
|
|
1032
1050
|
}
|
|
1033
1051
|
async function* Ft(e, s) {
|
|
@@ -1050,7 +1068,7 @@ async function* Ft(e, s) {
|
|
|
1050
1068
|
}
|
|
1051
1069
|
async function Gt(e, s) {
|
|
1052
1070
|
let t = new Request(e, s);
|
|
1053
|
-
|
|
1071
|
+
Oe(t.headers, "Accept", "text/event-stream"), Oe(t.headers, "Content-Type", "application/json");
|
|
1054
1072
|
let n = await fetch(t);
|
|
1055
1073
|
if (!n.ok)
|
|
1056
1074
|
throw n;
|
|
@@ -1071,7 +1089,7 @@ async function Mt() {
|
|
|
1071
1089
|
n.open = !0;
|
|
1072
1090
|
let a = null, u = new URLSearchParams({
|
|
1073
1091
|
session_hash: this.session_hash
|
|
1074
|
-
}).toString(), l = new URL(`${o.root}${this.api_prefix}/${
|
|
1092
|
+
}).toString(), l = new URL(`${o.root}${this.api_prefix}/${Te}?${u}`);
|
|
1075
1093
|
if (r && l.searchParams.set("__sign", r), a = this.stream(l), !a) {
|
|
1076
1094
|
console.warn("Cannot connect to SSE endpoint: " + l.toString());
|
|
1077
1095
|
return;
|
|
@@ -1079,7 +1097,7 @@ async function Mt() {
|
|
|
1079
1097
|
a.onmessage = async function(p) {
|
|
1080
1098
|
let c = JSON.parse(p.data);
|
|
1081
1099
|
if (c.msg === "close_stream") {
|
|
1082
|
-
|
|
1100
|
+
he(n, i.abort_controller);
|
|
1083
1101
|
return;
|
|
1084
1102
|
}
|
|
1085
1103
|
const m = c.event_id;
|
|
@@ -1102,13 +1120,13 @@ async function Mt() {
|
|
|
1102
1120
|
Object.keys(e).map(
|
|
1103
1121
|
(c) => e[c]({
|
|
1104
1122
|
msg: "broken_connection",
|
|
1105
|
-
message:
|
|
1123
|
+
message: L
|
|
1106
1124
|
})
|
|
1107
1125
|
)
|
|
1108
1126
|
);
|
|
1109
1127
|
};
|
|
1110
1128
|
}
|
|
1111
|
-
function
|
|
1129
|
+
function he(e, s) {
|
|
1112
1130
|
e && (e.open = !1, s?.abort());
|
|
1113
1131
|
}
|
|
1114
1132
|
function Ht(e, s, t) {
|
|
@@ -1194,66 +1212,66 @@ function Zt(e, s = {}) {
|
|
|
1194
1212
|
function Kt(e, s = {}, t, n, o, r) {
|
|
1195
1213
|
try {
|
|
1196
1214
|
let i = function(h) {
|
|
1197
|
-
(o ||
|
|
1215
|
+
(o || ze[h.type]) && p(h);
|
|
1198
1216
|
}, a = function() {
|
|
1199
|
-
for (
|
|
1200
|
-
|
|
1217
|
+
for (Me = !0; G.length > 0; )
|
|
1218
|
+
G.shift()({
|
|
1201
1219
|
value: void 0,
|
|
1202
1220
|
done: !0
|
|
1203
1221
|
});
|
|
1204
1222
|
}, u = function(h) {
|
|
1205
|
-
|
|
1223
|
+
G.length > 0 ? G.shift()(h) : ie.push(h);
|
|
1206
1224
|
}, l = function(h) {
|
|
1207
1225
|
u(Vt(h)), a();
|
|
1208
1226
|
}, p = function(h) {
|
|
1209
1227
|
u({ value: h, done: !1 });
|
|
1210
1228
|
}, c = function() {
|
|
1211
|
-
return
|
|
1229
|
+
return ie.length > 0 ? Promise.resolve(ie.shift()) : new Promise((h) => G.push(h));
|
|
1212
1230
|
};
|
|
1213
1231
|
const { token: m } = this.options, {
|
|
1214
1232
|
fetch: w,
|
|
1215
|
-
app_reference:
|
|
1233
|
+
app_reference: P,
|
|
1216
1234
|
config: f,
|
|
1217
1235
|
session_hash: g,
|
|
1218
|
-
api_info:
|
|
1219
|
-
api_map:
|
|
1220
|
-
stream_status:
|
|
1221
|
-
pending_stream_messages:
|
|
1222
|
-
pending_diff_streams:
|
|
1223
|
-
event_callbacks:
|
|
1236
|
+
api_info: J,
|
|
1237
|
+
api_map: z,
|
|
1238
|
+
stream_status: ee,
|
|
1239
|
+
pending_stream_messages: te,
|
|
1240
|
+
pending_diff_streams: se,
|
|
1241
|
+
event_callbacks: ne,
|
|
1224
1242
|
unclosed_events: Ie,
|
|
1225
|
-
post_data:
|
|
1226
|
-
options:
|
|
1227
|
-
api_prefix:
|
|
1228
|
-
} = this,
|
|
1229
|
-
if (!
|
|
1243
|
+
post_data: oe,
|
|
1244
|
+
options: W,
|
|
1245
|
+
api_prefix: T
|
|
1246
|
+
} = this, fe = r || { "x-gradio-user": "api" }, Ue = this;
|
|
1247
|
+
if (!J) throw new Error("No API found");
|
|
1230
1248
|
if (!f) throw new Error("Could not resolve app config");
|
|
1231
|
-
let { fn_index: d, endpoint_info:
|
|
1232
|
-
|
|
1249
|
+
let { fn_index: d, endpoint_info: _e, dependency: B } = Yt(
|
|
1250
|
+
J,
|
|
1233
1251
|
e,
|
|
1234
|
-
|
|
1252
|
+
z,
|
|
1235
1253
|
f
|
|
1236
|
-
),
|
|
1237
|
-
if (
|
|
1254
|
+
), qe = wt(s, _e), U, A = f.protocol ?? "ws";
|
|
1255
|
+
if (A === "ws")
|
|
1238
1256
|
throw new Error("WebSocket protocol is not supported in this version");
|
|
1239
|
-
let
|
|
1257
|
+
let q = "", Qt = () => q;
|
|
1240
1258
|
const _ = typeof e == "number" ? "/predict" : e;
|
|
1241
|
-
let
|
|
1242
|
-
const
|
|
1243
|
-
(h,
|
|
1259
|
+
let Z, b = null, x = !1, me = {}, F = typeof window < "u" && typeof document < "u" ? new URLSearchParams(window.location.search).toString() : "";
|
|
1260
|
+
const ze = W?.events?.reduce(
|
|
1261
|
+
(h, R) => (h[R] = !0, h),
|
|
1244
1262
|
{}
|
|
1245
1263
|
) || {};
|
|
1246
|
-
async function
|
|
1247
|
-
let h = {},
|
|
1248
|
-
h = { event_id: b },
|
|
1264
|
+
async function Be() {
|
|
1265
|
+
let h = {}, R = {};
|
|
1266
|
+
h = { event_id: b }, R = { event_id: b, session_hash: g, fn_index: d };
|
|
1249
1267
|
try {
|
|
1250
1268
|
if (!f)
|
|
1251
1269
|
throw new Error("Could not resolve app config");
|
|
1252
|
-
"event_id" in
|
|
1270
|
+
"event_id" in R && await w(`${f.root}${T}/${st}`, {
|
|
1253
1271
|
headers: { "Content-Type": "application/json" },
|
|
1254
1272
|
method: "POST",
|
|
1255
|
-
body: JSON.stringify(
|
|
1256
|
-
}), await w(`${f.root}${
|
|
1273
|
+
body: JSON.stringify(R)
|
|
1274
|
+
}), await w(`${f.root}${T}/${tt}`, {
|
|
1257
1275
|
headers: { "Content-Type": "application/json" },
|
|
1258
1276
|
method: "POST",
|
|
1259
1277
|
body: JSON.stringify(h)
|
|
@@ -1264,38 +1282,38 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1264
1282
|
);
|
|
1265
1283
|
}
|
|
1266
1284
|
}
|
|
1267
|
-
const
|
|
1285
|
+
const Fe = async (h) => {
|
|
1268
1286
|
await this._resolve_heartbeat(h);
|
|
1269
1287
|
};
|
|
1270
|
-
async function
|
|
1288
|
+
async function ge(h) {
|
|
1271
1289
|
if (!f) return;
|
|
1272
|
-
let
|
|
1290
|
+
let R = h.render_id;
|
|
1273
1291
|
f.components = [
|
|
1274
|
-
...f.components.filter((v) => v.props.rendered_in !==
|
|
1292
|
+
...f.components.filter((v) => v.props.rendered_in !== R),
|
|
1275
1293
|
...h.components
|
|
1276
1294
|
], f.dependencies = [
|
|
1277
|
-
...f.dependencies.filter((v) => v.rendered_in !==
|
|
1295
|
+
...f.dependencies.filter((v) => v.rendered_in !== R),
|
|
1278
1296
|
...h.dependencies
|
|
1279
1297
|
];
|
|
1280
|
-
const
|
|
1281
|
-
(v) => v.targets.some((
|
|
1298
|
+
const K = f.components.some((v) => v.type === "state"), y = f.dependencies.some(
|
|
1299
|
+
(v) => v.targets.some((j) => j[1] === "unload")
|
|
1282
1300
|
);
|
|
1283
|
-
f.connect_heartbeat =
|
|
1301
|
+
f.connect_heartbeat = K || y, await Fe(f), i({
|
|
1284
1302
|
type: "render",
|
|
1285
1303
|
data: h,
|
|
1286
1304
|
endpoint: _,
|
|
1287
1305
|
fn_index: d
|
|
1288
1306
|
});
|
|
1289
1307
|
}
|
|
1290
|
-
const
|
|
1308
|
+
const Ge = this.handle_blob(
|
|
1291
1309
|
f.root,
|
|
1292
|
-
|
|
1293
|
-
|
|
1310
|
+
qe,
|
|
1311
|
+
_e
|
|
1294
1312
|
).then(async (h) => {
|
|
1295
|
-
if (
|
|
1296
|
-
data:
|
|
1313
|
+
if (Z = {
|
|
1314
|
+
data: Y(
|
|
1297
1315
|
h,
|
|
1298
|
-
|
|
1316
|
+
B,
|
|
1299
1317
|
f.components,
|
|
1300
1318
|
"input",
|
|
1301
1319
|
!0
|
|
@@ -1311,46 +1329,52 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1311
1329
|
queue: !1,
|
|
1312
1330
|
fn_index: d,
|
|
1313
1331
|
time: /* @__PURE__ */ new Date()
|
|
1314
|
-
}),
|
|
1315
|
-
`${f.root}${
|
|
1332
|
+
}), oe(
|
|
1333
|
+
`${f.root}${T}/run${_.startsWith("/") ? _ : `/${_}`}${F ? "?" + F : ""}`,
|
|
1316
1334
|
{
|
|
1317
|
-
...
|
|
1335
|
+
...Z,
|
|
1318
1336
|
session_hash: g
|
|
1319
1337
|
},
|
|
1320
|
-
|
|
1338
|
+
fe
|
|
1321
1339
|
).then(async ([y, v]) => {
|
|
1322
|
-
const
|
|
1323
|
-
v == 200
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1340
|
+
const j = y.data;
|
|
1341
|
+
if (v == 200)
|
|
1342
|
+
i({
|
|
1343
|
+
type: "data",
|
|
1344
|
+
endpoint: _,
|
|
1345
|
+
fn_index: d,
|
|
1346
|
+
data: Y(
|
|
1347
|
+
j,
|
|
1348
|
+
B,
|
|
1349
|
+
f.components,
|
|
1350
|
+
"output",
|
|
1351
|
+
W.with_null_state
|
|
1352
|
+
),
|
|
1353
|
+
time: /* @__PURE__ */ new Date(),
|
|
1354
|
+
event_data: t,
|
|
1355
|
+
trigger_id: n
|
|
1356
|
+
}), y.render_config && await ge(y.render_config), i({
|
|
1357
|
+
type: "status",
|
|
1358
|
+
endpoint: _,
|
|
1359
|
+
fn_index: d,
|
|
1360
|
+
stage: "complete",
|
|
1361
|
+
eta: y.average_duration,
|
|
1362
|
+
queue: !1,
|
|
1363
|
+
time: /* @__PURE__ */ new Date()
|
|
1364
|
+
});
|
|
1365
|
+
else {
|
|
1366
|
+
const O = y?.error === L;
|
|
1367
|
+
i({
|
|
1368
|
+
type: "status",
|
|
1369
|
+
stage: "error",
|
|
1370
|
+
endpoint: _,
|
|
1371
|
+
fn_index: d,
|
|
1372
|
+
message: y.error,
|
|
1373
|
+
broken: O,
|
|
1374
|
+
queue: !1,
|
|
1375
|
+
time: /* @__PURE__ */ new Date()
|
|
1376
|
+
});
|
|
1377
|
+
}
|
|
1354
1378
|
}).catch((y) => {
|
|
1355
1379
|
i({
|
|
1356
1380
|
type: "status",
|
|
@@ -1362,7 +1386,7 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1362
1386
|
time: /* @__PURE__ */ new Date()
|
|
1363
1387
|
});
|
|
1364
1388
|
});
|
|
1365
|
-
else if (
|
|
1389
|
+
else if (A == "sse") {
|
|
1366
1390
|
i({
|
|
1367
1391
|
type: "status",
|
|
1368
1392
|
stage: "pending",
|
|
@@ -1371,91 +1395,91 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1371
1395
|
fn_index: d,
|
|
1372
1396
|
time: /* @__PURE__ */ new Date()
|
|
1373
1397
|
});
|
|
1374
|
-
var
|
|
1398
|
+
var K = new URLSearchParams({
|
|
1375
1399
|
fn_index: d.toString(),
|
|
1376
1400
|
session_hash: g
|
|
1377
1401
|
}).toString();
|
|
1378
1402
|
let y = new URL(
|
|
1379
|
-
`${f.root}${
|
|
1403
|
+
`${f.root}${T}/${Te}?${F ? F + "&" : ""}${K}`
|
|
1380
1404
|
);
|
|
1381
|
-
if (this.jwt && y.searchParams.set("__sign", this.jwt),
|
|
1405
|
+
if (this.jwt && y.searchParams.set("__sign", this.jwt), U = this.stream(y), !U)
|
|
1382
1406
|
return Promise.reject(
|
|
1383
1407
|
new Error("Cannot connect to SSE endpoint: " + y.toString())
|
|
1384
1408
|
);
|
|
1385
|
-
|
|
1386
|
-
const
|
|
1387
|
-
|
|
1388
|
-
|
|
1409
|
+
U.onmessage = async function(v) {
|
|
1410
|
+
const j = JSON.parse(v.data), { type: O, status: C, data: D } = Ee(
|
|
1411
|
+
j,
|
|
1412
|
+
me[d]
|
|
1389
1413
|
);
|
|
1390
|
-
if (
|
|
1414
|
+
if (O === "update" && C && !x)
|
|
1391
1415
|
i({
|
|
1392
1416
|
type: "status",
|
|
1393
1417
|
endpoint: _,
|
|
1394
1418
|
fn_index: d,
|
|
1395
1419
|
time: /* @__PURE__ */ new Date(),
|
|
1396
|
-
...
|
|
1397
|
-
}),
|
|
1398
|
-
else if (
|
|
1399
|
-
let [
|
|
1400
|
-
`${f.root}${
|
|
1420
|
+
...C
|
|
1421
|
+
}), C.stage === "error" && (U?.close(), a());
|
|
1422
|
+
else if (O === "data") {
|
|
1423
|
+
let [k, I] = await oe(
|
|
1424
|
+
`${f.root}${T}/queue/data`,
|
|
1401
1425
|
{
|
|
1402
|
-
...
|
|
1426
|
+
...Z,
|
|
1403
1427
|
session_hash: g,
|
|
1404
1428
|
event_id: b
|
|
1405
1429
|
}
|
|
1406
1430
|
);
|
|
1407
|
-
|
|
1431
|
+
I !== 200 && (i({
|
|
1408
1432
|
type: "status",
|
|
1409
1433
|
stage: "error",
|
|
1410
|
-
message:
|
|
1434
|
+
message: L,
|
|
1411
1435
|
queue: !0,
|
|
1412
1436
|
endpoint: _,
|
|
1413
1437
|
fn_index: d,
|
|
1414
1438
|
time: /* @__PURE__ */ new Date()
|
|
1415
|
-
}),
|
|
1416
|
-
} else
|
|
1439
|
+
}), U?.close(), a());
|
|
1440
|
+
} else O === "complete" ? x = C : O === "log" ? i({
|
|
1417
1441
|
type: "log",
|
|
1418
|
-
title:
|
|
1419
|
-
log:
|
|
1420
|
-
level:
|
|
1442
|
+
title: D.title,
|
|
1443
|
+
log: D.log,
|
|
1444
|
+
level: D.level,
|
|
1421
1445
|
endpoint: _,
|
|
1422
|
-
duration:
|
|
1423
|
-
visible:
|
|
1446
|
+
duration: D.duration,
|
|
1447
|
+
visible: D.visible,
|
|
1424
1448
|
fn_index: d
|
|
1425
|
-
}) : (
|
|
1449
|
+
}) : (O === "generating" || O === "streaming") && i({
|
|
1426
1450
|
type: "status",
|
|
1427
1451
|
time: /* @__PURE__ */ new Date(),
|
|
1428
|
-
...
|
|
1429
|
-
stage:
|
|
1452
|
+
...C,
|
|
1453
|
+
stage: C?.stage,
|
|
1430
1454
|
queue: !0,
|
|
1431
1455
|
endpoint: _,
|
|
1432
1456
|
fn_index: d
|
|
1433
1457
|
});
|
|
1434
|
-
|
|
1458
|
+
D && (i({
|
|
1435
1459
|
type: "data",
|
|
1436
1460
|
time: /* @__PURE__ */ new Date(),
|
|
1437
|
-
data:
|
|
1438
|
-
|
|
1439
|
-
|
|
1461
|
+
data: Y(
|
|
1462
|
+
D.data,
|
|
1463
|
+
B,
|
|
1440
1464
|
f.components,
|
|
1441
1465
|
"output",
|
|
1442
|
-
|
|
1466
|
+
W.with_null_state
|
|
1443
1467
|
),
|
|
1444
1468
|
endpoint: _,
|
|
1445
1469
|
fn_index: d,
|
|
1446
1470
|
event_data: t,
|
|
1447
1471
|
trigger_id: n
|
|
1448
|
-
}),
|
|
1472
|
+
}), x && (i({
|
|
1449
1473
|
type: "status",
|
|
1450
1474
|
time: /* @__PURE__ */ new Date(),
|
|
1451
|
-
...
|
|
1452
|
-
stage:
|
|
1475
|
+
...x,
|
|
1476
|
+
stage: C?.stage,
|
|
1453
1477
|
queue: !0,
|
|
1454
1478
|
endpoint: _,
|
|
1455
1479
|
fn_index: d
|
|
1456
|
-
}),
|
|
1480
|
+
}), U?.close(), a()));
|
|
1457
1481
|
};
|
|
1458
|
-
} else if (
|
|
1482
|
+
} else if (A == "sse_v1" || A == "sse_v2" || A == "sse_v2.1" || A == "sse_v3") {
|
|
1459
1483
|
i({
|
|
1460
1484
|
type: "status",
|
|
1461
1485
|
stage: "pending",
|
|
@@ -1466,34 +1490,34 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1466
1490
|
});
|
|
1467
1491
|
let y = "";
|
|
1468
1492
|
typeof window < "u" && typeof document < "u" && (y = window?.location?.hostname);
|
|
1469
|
-
const
|
|
1470
|
-
return (typeof window < "u" && typeof document < "u" && window.parent != window && window.supports_zerogpu_headers ? Tt("zerogpu-headers",
|
|
1471
|
-
const
|
|
1472
|
-
return
|
|
1473
|
-
`${f.root}${
|
|
1493
|
+
const j = y.includes(".dev.") ? `https://moon-${y.split(".")[1]}.dev.spaces.huggingface.tech` : "https://huggingface.co";
|
|
1494
|
+
return (typeof window < "u" && typeof document < "u" && window.parent != window && window.supports_zerogpu_headers ? Tt("zerogpu-headers", j) : Promise.resolve(null)).then((k) => {
|
|
1495
|
+
const I = { ...fe, ...k || {} };
|
|
1496
|
+
return oe(
|
|
1497
|
+
`${f.root}${T}/${Ze}?${F}`,
|
|
1474
1498
|
{
|
|
1475
|
-
...
|
|
1499
|
+
...Z,
|
|
1476
1500
|
session_hash: g
|
|
1477
1501
|
},
|
|
1478
|
-
|
|
1502
|
+
I
|
|
1479
1503
|
);
|
|
1480
|
-
}).then(async ([
|
|
1481
|
-
if (
|
|
1504
|
+
}).then(async ([k, I]) => {
|
|
1505
|
+
if (k.event_id && (q = k.event_id), I === 503)
|
|
1482
1506
|
i({
|
|
1483
1507
|
type: "status",
|
|
1484
1508
|
stage: "error",
|
|
1485
|
-
message:
|
|
1509
|
+
message: Ae,
|
|
1486
1510
|
queue: !0,
|
|
1487
1511
|
endpoint: _,
|
|
1488
1512
|
fn_index: d,
|
|
1489
1513
|
time: /* @__PURE__ */ new Date(),
|
|
1490
1514
|
visible: !0
|
|
1491
1515
|
});
|
|
1492
|
-
else if (
|
|
1516
|
+
else if (I === 422)
|
|
1493
1517
|
i({
|
|
1494
1518
|
type: "status",
|
|
1495
1519
|
stage: "error",
|
|
1496
|
-
message:
|
|
1520
|
+
message: k.detail,
|
|
1497
1521
|
queue: !0,
|
|
1498
1522
|
endpoint: _,
|
|
1499
1523
|
fn_index: d,
|
|
@@ -1501,49 +1525,50 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1501
1525
|
time: /* @__PURE__ */ new Date(),
|
|
1502
1526
|
visible: !0
|
|
1503
1527
|
}), a();
|
|
1504
|
-
else if (
|
|
1528
|
+
else if (I !== 200) {
|
|
1529
|
+
const M = k?.error === L;
|
|
1505
1530
|
i({
|
|
1506
1531
|
type: "status",
|
|
1507
1532
|
stage: "error",
|
|
1508
|
-
broken:
|
|
1509
|
-
message:
|
|
1533
|
+
broken: M,
|
|
1534
|
+
message: M ? L : k.detail || k.error,
|
|
1510
1535
|
queue: !0,
|
|
1511
1536
|
endpoint: _,
|
|
1512
1537
|
fn_index: d,
|
|
1513
1538
|
time: /* @__PURE__ */ new Date(),
|
|
1514
1539
|
visible: !0
|
|
1515
1540
|
});
|
|
1516
|
-
else {
|
|
1517
|
-
b =
|
|
1518
|
-
let
|
|
1541
|
+
} else {
|
|
1542
|
+
b = k.event_id, q = b;
|
|
1543
|
+
let M = async function(re) {
|
|
1519
1544
|
try {
|
|
1520
|
-
const { type: E, status: S, data: $, original_msg:
|
|
1521
|
-
|
|
1522
|
-
|
|
1545
|
+
const { type: E, status: S, data: $, original_msg: He } = Ee(
|
|
1546
|
+
re,
|
|
1547
|
+
me[d]
|
|
1523
1548
|
);
|
|
1524
1549
|
if (E == "heartbeat")
|
|
1525
1550
|
return;
|
|
1526
|
-
if (E === "update" && S && !
|
|
1551
|
+
if (E === "update" && S && !x)
|
|
1527
1552
|
i({
|
|
1528
1553
|
type: "status",
|
|
1529
1554
|
endpoint: _,
|
|
1530
1555
|
fn_index: d,
|
|
1531
1556
|
time: /* @__PURE__ */ new Date(),
|
|
1532
|
-
original_msg:
|
|
1557
|
+
original_msg: He,
|
|
1533
1558
|
...S
|
|
1534
1559
|
});
|
|
1535
1560
|
else if (E === "complete")
|
|
1536
|
-
|
|
1561
|
+
x = S;
|
|
1537
1562
|
else if (E == "unexpected_error" || E == "broken_connection") {
|
|
1538
1563
|
console.error("Unexpected error", S?.message);
|
|
1539
|
-
const
|
|
1564
|
+
const Je = E === "broken_connection";
|
|
1540
1565
|
i({
|
|
1541
1566
|
type: "status",
|
|
1542
1567
|
stage: "error",
|
|
1543
1568
|
message: S?.message || "An Unexpected Error Occurred!",
|
|
1544
1569
|
queue: !0,
|
|
1545
1570
|
endpoint: _,
|
|
1546
|
-
broken:
|
|
1571
|
+
broken: Je,
|
|
1547
1572
|
session_not_found: S?.session_not_found,
|
|
1548
1573
|
fn_index: d,
|
|
1549
1574
|
time: /* @__PURE__ */ new Date()
|
|
@@ -1568,28 +1593,28 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1568
1593
|
queue: !0,
|
|
1569
1594
|
endpoint: _,
|
|
1570
1595
|
fn_index: d
|
|
1571
|
-
}), $ &&
|
|
1596
|
+
}), $ && B.connection !== "stream" && ["sse_v2", "sse_v2.1", "sse_v3"].includes(A) && Ht(se, b, $));
|
|
1572
1597
|
$ && (i({
|
|
1573
1598
|
type: "data",
|
|
1574
1599
|
time: /* @__PURE__ */ new Date(),
|
|
1575
|
-
data:
|
|
1600
|
+
data: Y(
|
|
1576
1601
|
$.data,
|
|
1577
|
-
|
|
1602
|
+
B,
|
|
1578
1603
|
f.components,
|
|
1579
1604
|
"output",
|
|
1580
|
-
|
|
1605
|
+
W.with_null_state
|
|
1581
1606
|
),
|
|
1582
1607
|
endpoint: _,
|
|
1583
1608
|
fn_index: d
|
|
1584
|
-
}), $.render_config && await
|
|
1609
|
+
}), $.render_config && await ge($.render_config), x && (i({
|
|
1585
1610
|
type: "status",
|
|
1586
1611
|
time: /* @__PURE__ */ new Date(),
|
|
1587
|
-
...
|
|
1612
|
+
...x,
|
|
1588
1613
|
stage: S?.stage,
|
|
1589
1614
|
queue: !0,
|
|
1590
1615
|
endpoint: _,
|
|
1591
1616
|
fn_index: d
|
|
1592
|
-
}), a())), (S?.stage === "complete" || S?.stage === "error") && (
|
|
1617
|
+
}), a())), (S?.stage === "complete" || S?.stage === "error") && (ne[b] && delete ne[b], b in se && delete se[b]);
|
|
1593
1618
|
} catch (E) {
|
|
1594
1619
|
console.error("Unexpected client exception", E), i({
|
|
1595
1620
|
type: "status",
|
|
@@ -1599,37 +1624,37 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1599
1624
|
endpoint: _,
|
|
1600
1625
|
fn_index: d,
|
|
1601
1626
|
time: /* @__PURE__ */ new Date()
|
|
1602
|
-
}), ["sse_v2", "sse_v2.1", "sse_v3"].includes(
|
|
1627
|
+
}), ["sse_v2", "sse_v2.1", "sse_v3"].includes(A) && (he(ee, Ue.abort_controller), ee.open = !1, a());
|
|
1603
1628
|
}
|
|
1604
1629
|
};
|
|
1605
|
-
b in
|
|
1630
|
+
b in te && (te[b].forEach((re) => M(re)), delete te[b]), ne[b] = M, Ie.add(b), ee.open || await this.open_stream();
|
|
1606
1631
|
}
|
|
1607
1632
|
});
|
|
1608
1633
|
}
|
|
1609
1634
|
});
|
|
1610
|
-
let
|
|
1611
|
-
const
|
|
1612
|
-
[Symbol.asyncIterator]: () =>
|
|
1635
|
+
let Me = !1;
|
|
1636
|
+
const ie = [], G = [], we = {
|
|
1637
|
+
[Symbol.asyncIterator]: () => we,
|
|
1613
1638
|
next: c,
|
|
1614
1639
|
throw: async (h) => (l(h), c()),
|
|
1615
1640
|
return: async () => (a(), { value: void 0, done: !0 }),
|
|
1616
|
-
cancel:
|
|
1641
|
+
cancel: Be,
|
|
1617
1642
|
send_chunk: (h) => {
|
|
1618
|
-
this.post_data(`${f.root}${
|
|
1643
|
+
this.post_data(`${f.root}${T}/stream/${q}`, {
|
|
1619
1644
|
...h,
|
|
1620
1645
|
session_hash: this.session_hash
|
|
1621
1646
|
});
|
|
1622
1647
|
},
|
|
1623
1648
|
close_stream: () => {
|
|
1624
1649
|
this.post_data(
|
|
1625
|
-
`${f.root}${
|
|
1650
|
+
`${f.root}${T}/stream/${q}/close`,
|
|
1626
1651
|
{}
|
|
1627
1652
|
), a();
|
|
1628
1653
|
},
|
|
1629
|
-
event_id: () =>
|
|
1630
|
-
wait_for_id: async () => (await
|
|
1654
|
+
event_id: () => q,
|
|
1655
|
+
wait_for_id: async () => (await Ge, b)
|
|
1631
1656
|
};
|
|
1632
|
-
return
|
|
1657
|
+
return we;
|
|
1633
1658
|
} catch (i) {
|
|
1634
1659
|
throw console.error("Submit function encountered an error:", i), i;
|
|
1635
1660
|
}
|
|
@@ -1655,7 +1680,7 @@ function Yt(e, s, t, n) {
|
|
|
1655
1680
|
);
|
|
1656
1681
|
return { fn_index: o, endpoint_info: r, dependency: i };
|
|
1657
1682
|
}
|
|
1658
|
-
class
|
|
1683
|
+
class Q {
|
|
1659
1684
|
app_reference;
|
|
1660
1685
|
options;
|
|
1661
1686
|
deep_link = null;
|
|
@@ -1680,7 +1705,7 @@ class V {
|
|
|
1680
1705
|
current_payload;
|
|
1681
1706
|
get_url_config(s = null) {
|
|
1682
1707
|
if (!this.config)
|
|
1683
|
-
throw new Error(
|
|
1708
|
+
throw new Error(N);
|
|
1684
1709
|
s === null && (s = window.location.href);
|
|
1685
1710
|
const t = (i) => i.replace(/^\/+|\/+$/g, "");
|
|
1686
1711
|
let n = t(new URL(this.config.root).pathname), o = t(new URL(s).pathname), r;
|
|
@@ -1688,7 +1713,7 @@ class V {
|
|
|
1688
1713
|
}
|
|
1689
1714
|
get_page_config(s) {
|
|
1690
1715
|
if (!this.config)
|
|
1691
|
-
throw new Error(
|
|
1716
|
+
throw new Error(N);
|
|
1692
1717
|
let t = this.config;
|
|
1693
1718
|
return s in t.page || (s = ""), {
|
|
1694
1719
|
...t,
|
|
@@ -1729,21 +1754,21 @@ class V {
|
|
|
1729
1754
|
resolve_config;
|
|
1730
1755
|
resolve_cookies;
|
|
1731
1756
|
constructor(s, t = { events: ["data"] }) {
|
|
1732
|
-
this.app_reference = s, this.deep_link = t.query_params?.deep_link || null, t.events || (t.events = ["data"]), this.options = t, this.current_payload = {}, this.view_api = yt.bind(this), this.upload_files = bt.bind(this), this.handle_blob = At.bind(this), this.post_data = Dt.bind(this), this.submit = Kt.bind(this), this.predict = Nt.bind(this), this.open_stream = Mt.bind(this), this.resolve_config =
|
|
1757
|
+
this.app_reference = s, this.deep_link = t.query_params?.deep_link || null, t.events || (t.events = ["data"]), this.options = t, this.current_payload = {}, t.cookies && (this.cookies = t.cookies), this.view_api = yt.bind(this), this.upload_files = bt.bind(this), this.handle_blob = At.bind(this), this.post_data = Dt.bind(this), this.submit = Kt.bind(this), this.predict = Nt.bind(this), this.open_stream = Mt.bind(this), this.resolve_config = dt.bind(this), this.resolve_cookies = ht.bind(this), this.upload = kt.bind(this), this.fetch = this.fetch.bind(this), this.handle_space_success = this.handle_space_success.bind(this), this.stream = this.stream.bind(this);
|
|
1733
1758
|
}
|
|
1734
1759
|
async init() {
|
|
1735
1760
|
this.options.auth && await this.resolve_cookies(), await this._resolve_config().then(
|
|
1736
1761
|
({ config: s }) => this._resolve_heartbeat(s)
|
|
1737
|
-
), this.api_info = await this.view_api(), this.api_map =
|
|
1762
|
+
), this.api_info = await this.view_api(), this.api_map = pt(this.config?.dependencies || []);
|
|
1738
1763
|
}
|
|
1739
1764
|
async _resolve_heartbeat(s) {
|
|
1740
|
-
if (s && (this.config = s, this.api_prefix = s.api_prefix || "", this.config && this.config.connect_heartbeat && this.config.space_id && this.options.token && (this.jwt = await
|
|
1765
|
+
if (s && (this.config = s, this.api_prefix = s.api_prefix || "", this.config && this.config.connect_heartbeat && this.config.space_id && this.options.token && (this.jwt = await be(
|
|
1741
1766
|
this.config.space_id,
|
|
1742
1767
|
this.options.token,
|
|
1743
1768
|
this.cookies
|
|
1744
|
-
))), s.space_id && this.options.token && (this.jwt = await
|
|
1769
|
+
))), s.space_id && this.options.token && (this.jwt = await be(s.space_id, this.options.token)), this.config && this.config.connect_heartbeat) {
|
|
1745
1770
|
const t = new URL(
|
|
1746
|
-
`${this.config.root}${this.api_prefix}/${
|
|
1771
|
+
`${this.config.root}${this.api_prefix}/${Xe}/${this.session_hash}`
|
|
1747
1772
|
);
|
|
1748
1773
|
this.jwt && t.searchParams.set("__sign", this.jwt), this.heartbeat_event || (this.heartbeat_event = this.stream(t));
|
|
1749
1774
|
}
|
|
@@ -1756,7 +1781,7 @@ class V {
|
|
|
1756
1781
|
}
|
|
1757
1782
|
async reconnect() {
|
|
1758
1783
|
const s = new URL(
|
|
1759
|
-
`${this.config.root}${this.api_prefix}/${
|
|
1784
|
+
`${this.config.root}${this.api_prefix}/${nt}`
|
|
1760
1785
|
);
|
|
1761
1786
|
let t;
|
|
1762
1787
|
try {
|
|
@@ -1770,7 +1795,7 @@ class V {
|
|
|
1770
1795
|
return t !== this.config.app_id ? "changed" : "connected";
|
|
1771
1796
|
}
|
|
1772
1797
|
close() {
|
|
1773
|
-
this.closed = !0,
|
|
1798
|
+
this.closed = !0, he(this.stream_status, this.abort_controller);
|
|
1774
1799
|
}
|
|
1775
1800
|
set_current_payload(s) {
|
|
1776
1801
|
this.current_payload = s;
|
|
@@ -1778,25 +1803,25 @@ class V {
|
|
|
1778
1803
|
static async duplicate(s, t = {
|
|
1779
1804
|
events: ["data"]
|
|
1780
1805
|
}) {
|
|
1781
|
-
return
|
|
1806
|
+
return It(s, t);
|
|
1782
1807
|
}
|
|
1783
1808
|
async _resolve_config() {
|
|
1784
|
-
const { http_protocol: s, host: t, space_id: n } = await
|
|
1809
|
+
const { http_protocol: s, host: t, space_id: n } = await de(
|
|
1785
1810
|
this.app_reference,
|
|
1786
1811
|
this.options.token
|
|
1787
1812
|
), { status_callback: o } = this.options;
|
|
1788
|
-
n && o && await
|
|
1813
|
+
n && o && await je(n, o);
|
|
1789
1814
|
let r;
|
|
1790
1815
|
try {
|
|
1791
1816
|
let i = `${s}//${t}`;
|
|
1792
1817
|
if (r = await this.resolve_config(i), !r)
|
|
1793
|
-
throw new Error(
|
|
1818
|
+
throw new Error(N);
|
|
1794
1819
|
return this.config_success(r);
|
|
1795
1820
|
} catch (i) {
|
|
1796
1821
|
if (n && o)
|
|
1797
|
-
|
|
1822
|
+
H(
|
|
1798
1823
|
n,
|
|
1799
|
-
|
|
1824
|
+
pe.test(n) ? "space_name" : "subdomain",
|
|
1800
1825
|
this.handle_space_success
|
|
1801
1826
|
);
|
|
1802
1827
|
else
|
|
@@ -1814,18 +1839,18 @@ class V {
|
|
|
1814
1839
|
try {
|
|
1815
1840
|
this.api_info = await this.view_api();
|
|
1816
1841
|
} catch (t) {
|
|
1817
|
-
console.error(
|
|
1842
|
+
console.error(it + t.message);
|
|
1818
1843
|
}
|
|
1819
1844
|
return this.prepare_return_obj();
|
|
1820
1845
|
}
|
|
1821
1846
|
async handle_space_success(s) {
|
|
1822
1847
|
if (!this)
|
|
1823
|
-
throw new Error(
|
|
1848
|
+
throw new Error(N);
|
|
1824
1849
|
const { status_callback: t } = this.options;
|
|
1825
1850
|
if (t && t(s), s.status === "running")
|
|
1826
1851
|
try {
|
|
1827
1852
|
if (this.config = await this._resolve_config(), this.api_prefix = this?.config?.api_prefix || "", !this.config)
|
|
1828
|
-
throw new Error(
|
|
1853
|
+
throw new Error(N);
|
|
1829
1854
|
return await this.config_success(this.config);
|
|
1830
1855
|
} catch (n) {
|
|
1831
1856
|
throw t && t({
|
|
@@ -1838,7 +1863,7 @@ class V {
|
|
|
1838
1863
|
}
|
|
1839
1864
|
async component_server(s, t, n) {
|
|
1840
1865
|
if (!this.config)
|
|
1841
|
-
throw new Error(
|
|
1866
|
+
throw new Error(N);
|
|
1842
1867
|
const o = {}, { token: r } = this.options, { session_hash: i } = this;
|
|
1843
1868
|
r && (o.Authorization = `Bearer ${this.options.token}`);
|
|
1844
1869
|
let a, u = this.config.components.find(
|
|
@@ -1846,10 +1871,11 @@ class V {
|
|
|
1846
1871
|
);
|
|
1847
1872
|
u?.props?.root_url ? a = u.props.root_url : a = this.config.root;
|
|
1848
1873
|
let l;
|
|
1849
|
-
if ("binary" in n) {
|
|
1874
|
+
if (typeof n == "object" && n !== null && "binary" in n) {
|
|
1875
|
+
const p = n;
|
|
1850
1876
|
l = new FormData();
|
|
1851
|
-
for (const
|
|
1852
|
-
|
|
1877
|
+
for (const c in p.data)
|
|
1878
|
+
c !== "binary" && l.append(c, p.data[c]);
|
|
1853
1879
|
l.set("component_id", s.toString()), l.set("fn_name", t), l.set("session_hash", i);
|
|
1854
1880
|
} else
|
|
1855
1881
|
l = JSON.stringify({
|
|
@@ -1861,7 +1887,7 @@ class V {
|
|
|
1861
1887
|
r && (o.Authorization = `Bearer ${r}`);
|
|
1862
1888
|
try {
|
|
1863
1889
|
const p = await this.fetch(
|
|
1864
|
-
`${a}${this.api_prefix}/${
|
|
1890
|
+
`${a}${this.api_prefix}/${et}/`,
|
|
1865
1891
|
{
|
|
1866
1892
|
method: "POST",
|
|
1867
1893
|
body: l,
|
|
@@ -1879,7 +1905,7 @@ class V {
|
|
|
1879
1905
|
}
|
|
1880
1906
|
}
|
|
1881
1907
|
set_cookies(s) {
|
|
1882
|
-
this.cookies =
|
|
1908
|
+
this.cookies = Ne(s).join("; ");
|
|
1883
1909
|
}
|
|
1884
1910
|
prepare_return_obj() {
|
|
1885
1911
|
return {
|
|
@@ -1894,15 +1920,15 @@ class V {
|
|
|
1894
1920
|
async function ts(e, s = {
|
|
1895
1921
|
events: ["data"]
|
|
1896
1922
|
}) {
|
|
1897
|
-
return await
|
|
1923
|
+
return await Q.connect(e, s);
|
|
1898
1924
|
}
|
|
1899
1925
|
async function ss(e, s) {
|
|
1900
|
-
return await
|
|
1926
|
+
return await Q.duplicate(e, s);
|
|
1901
1927
|
}
|
|
1902
1928
|
export {
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1929
|
+
Q as Client,
|
|
1930
|
+
X as FileData,
|
|
1931
|
+
ct as MISSING_CREDENTIALS_MSG,
|
|
1906
1932
|
ts as client,
|
|
1907
1933
|
ss as duplicate,
|
|
1908
1934
|
es as handle_file,
|