@gradio/client 2.0.2 → 2.0.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 +15 -0
- package/dist/browser.js +324 -330
- package/dist/client.d.ts.map +1 -1
- package/dist/helpers/init_helpers.d.ts.map +1 -1
- package/dist/index.js +20 -16
- package/dist/types.d.ts +2 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +15 -6
- package/src/globals.d.ts +1 -0
- package/src/helpers/init_helpers.ts +13 -10
- package/src/types.ts +2 -1
package/dist/browser.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const We = "host", Te = "queue/data", Ze = "queue/join", ye = "upload", Ke = "login", K = "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. ", M = "Connection errored out. ",
|
|
1
|
+
const We = "host", Te = "queue/data", Ze = "queue/join", ye = "upload", Ke = "login", K = "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. ", M = "Connection errored out. ", D = "Could not resolve app config. ", it = "Could not get space status. ", ot = "Could not get API info. ", ue = "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
2
|
async function be(e, s, t) {
|
|
3
3
|
try {
|
|
4
4
|
return (await (await fetch(`https://huggingface.co/api/spaces/${e}/jwt`, {
|
|
@@ -20,7 +20,7 @@ function pt(e) {
|
|
|
20
20
|
async function dt(e) {
|
|
21
21
|
const s = this.options.token ? { Authorization: `Bearer ${this.options.token}` } : {};
|
|
22
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) {
|
|
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
24
|
let t = ae(
|
|
25
25
|
e,
|
|
26
26
|
this.deep_link ? K + "?deep_link=" + this.deep_link : K
|
|
@@ -28,17 +28,13 @@ async function dt(e) {
|
|
|
28
28
|
const n = await this.fetch(t, {
|
|
29
29
|
headers: s,
|
|
30
30
|
credentials: "include"
|
|
31
|
-
}),
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
!!this.options.auth
|
|
35
|
-
);
|
|
36
|
-
window.gradio_config = {
|
|
37
|
-
...o,
|
|
31
|
+
}), i = await ve(n, !!this.options.auth);
|
|
32
|
+
i.root = e || i.root, window.gradio_config = {
|
|
33
|
+
...i,
|
|
38
34
|
current_page: window.gradio_config.current_page
|
|
39
35
|
};
|
|
40
36
|
}
|
|
41
|
-
return
|
|
37
|
+
return { ...window.gradio_config };
|
|
42
38
|
} else if (e) {
|
|
43
39
|
let t = ae(
|
|
44
40
|
e,
|
|
@@ -47,25 +43,25 @@ async function dt(e) {
|
|
|
47
43
|
const n = await this.fetch(t, {
|
|
48
44
|
headers: s,
|
|
49
45
|
credentials: "include"
|
|
50
|
-
});
|
|
51
|
-
return
|
|
46
|
+
}), i = await ve(n, !!this.options.auth);
|
|
47
|
+
return i.root || (i.root = e), i;
|
|
52
48
|
}
|
|
53
|
-
throw new Error(
|
|
49
|
+
throw new Error(D);
|
|
54
50
|
}
|
|
55
|
-
async function ve(e, s
|
|
56
|
-
if (e?.status === 401 && !
|
|
57
|
-
const
|
|
58
|
-
throw new Error(
|
|
59
|
-
} else if (e?.status === 401 &&
|
|
51
|
+
async function ve(e, s) {
|
|
52
|
+
if (e?.status === 401 && !s) {
|
|
53
|
+
const n = (await e.json())?.detail?.auth_message;
|
|
54
|
+
throw new Error(n || ct);
|
|
55
|
+
} else if (e?.status === 401 && s)
|
|
60
56
|
throw new Error(xe);
|
|
61
57
|
if (e?.status === 200) {
|
|
62
|
-
let
|
|
63
|
-
return
|
|
64
|
-
|
|
65
|
-
}),
|
|
58
|
+
let t = await e.json();
|
|
59
|
+
return t.dependencies?.forEach((n, i) => {
|
|
60
|
+
n.id === void 0 && (n.id = i);
|
|
61
|
+
}), t;
|
|
66
62
|
} else if (e?.status === 401)
|
|
67
63
|
throw new Error(at);
|
|
68
|
-
throw new Error(
|
|
64
|
+
throw new Error(D);
|
|
69
65
|
}
|
|
70
66
|
async function ht() {
|
|
71
67
|
const { http_protocol: e, host: s } = await pe(
|
|
@@ -74,7 +70,7 @@ async function ht() {
|
|
|
74
70
|
);
|
|
75
71
|
try {
|
|
76
72
|
if (this.options.auth) {
|
|
77
|
-
const t = await
|
|
73
|
+
const t = await De(
|
|
78
74
|
e,
|
|
79
75
|
s,
|
|
80
76
|
this.options.auth,
|
|
@@ -87,13 +83,13 @@ async function ht() {
|
|
|
87
83
|
throw Error(t.message);
|
|
88
84
|
}
|
|
89
85
|
}
|
|
90
|
-
async function
|
|
86
|
+
async function De(e, s, t, n, i) {
|
|
91
87
|
const r = new FormData();
|
|
92
88
|
r.append("username", t?.[0]), r.append("password", t?.[1]);
|
|
93
|
-
let
|
|
94
|
-
|
|
89
|
+
let o = {};
|
|
90
|
+
i && (o.Authorization = `Bearer ${i}`);
|
|
95
91
|
const a = await n(`${e}//${s}/${Ke}`, {
|
|
96
|
-
headers:
|
|
92
|
+
headers: o,
|
|
97
93
|
method: "POST",
|
|
98
94
|
body: r,
|
|
99
95
|
credentials: "include"
|
|
@@ -117,11 +113,11 @@ function re(e) {
|
|
|
117
113
|
host: new URL(e).host
|
|
118
114
|
};
|
|
119
115
|
}
|
|
120
|
-
const
|
|
116
|
+
const Ne = (e) => {
|
|
121
117
|
let s = [];
|
|
122
118
|
return e.split(/,(?=\s*[^\s=;]+=[^\s=;]+)/).forEach((n) => {
|
|
123
|
-
const [
|
|
124
|
-
|
|
119
|
+
const [i, r] = n.split(";")[0].split("=");
|
|
120
|
+
i && r && s.push(`${i.trim()}=${r.trim()}`);
|
|
125
121
|
}), s;
|
|
126
122
|
}, le = /^[a-zA-Z0-9_\-\.]+\/[a-zA-Z0-9_\-\.]+$/, ft = /.*hf\.space\/{0,1}.*$/;
|
|
127
123
|
async function pe(e, s) {
|
|
@@ -142,12 +138,12 @@ async function pe(e, s) {
|
|
|
142
138
|
throw new Error(ue);
|
|
143
139
|
}
|
|
144
140
|
if (ft.test(n)) {
|
|
145
|
-
const { ws_protocol:
|
|
141
|
+
const { ws_protocol: i, http_protocol: r, host: o } = re(n);
|
|
146
142
|
return {
|
|
147
|
-
space_id:
|
|
148
|
-
ws_protocol:
|
|
143
|
+
space_id: o.split("/")[0].replace(".hf.space", ""),
|
|
144
|
+
ws_protocol: i,
|
|
149
145
|
http_protocol: r,
|
|
150
|
-
host:
|
|
146
|
+
host: o
|
|
151
147
|
};
|
|
152
148
|
}
|
|
153
149
|
return {
|
|
@@ -167,20 +163,20 @@ function _t(e, s, t) {
|
|
|
167
163
|
named_endpoints: {},
|
|
168
164
|
unnamed_endpoints: {}
|
|
169
165
|
};
|
|
170
|
-
return Object.keys(e).forEach((
|
|
171
|
-
(
|
|
172
|
-
([r, { parameters:
|
|
166
|
+
return Object.keys(e).forEach((i) => {
|
|
167
|
+
(i === "named_endpoints" || i === "unnamed_endpoints") && (n[i] = {}, Object.entries(e[i]).forEach(
|
|
168
|
+
([r, { parameters: o, returns: a }]) => {
|
|
173
169
|
const u = s.dependencies.find(
|
|
174
170
|
(c) => c.api_name === r || c.api_name === r.replace("/", "")
|
|
175
171
|
)?.id || t[r.replace("/", "")] || -1, l = u !== -1 ? s.dependencies.find((c) => c.id == u)?.types : { generator: !1, cancel: !1 };
|
|
176
|
-
if (u !== -1 && s.dependencies.find((c) => c.id == u)?.inputs?.length !==
|
|
172
|
+
if (u !== -1 && s.dependencies.find((c) => c.id == u)?.inputs?.length !== o.length) {
|
|
177
173
|
const c = s.dependencies.find((m) => m.id == u).inputs.map(
|
|
178
174
|
(m) => s.components.find((w) => w.id === m)?.type
|
|
179
175
|
);
|
|
180
176
|
try {
|
|
181
177
|
c.forEach((m, w) => {
|
|
182
178
|
if (m === "state") {
|
|
183
|
-
const
|
|
179
|
+
const N = {
|
|
184
180
|
component: "state",
|
|
185
181
|
example: null,
|
|
186
182
|
parameter_default: null,
|
|
@@ -188,20 +184,20 @@ function _t(e, s, t) {
|
|
|
188
184
|
parameter_name: null,
|
|
189
185
|
hidden: !0
|
|
190
186
|
};
|
|
191
|
-
|
|
187
|
+
o.splice(w, 0, N);
|
|
192
188
|
}
|
|
193
189
|
});
|
|
194
190
|
} catch (m) {
|
|
195
191
|
console.error(m);
|
|
196
192
|
}
|
|
197
193
|
}
|
|
198
|
-
const p = (c, m, w,
|
|
194
|
+
const p = (c, m, w, N) => ({
|
|
199
195
|
...c,
|
|
200
196
|
description: gt(c?.type, w),
|
|
201
|
-
type: mt(c?.type, m, w,
|
|
197
|
+
type: mt(c?.type, m, w, N) || ""
|
|
202
198
|
});
|
|
203
|
-
n[
|
|
204
|
-
parameters:
|
|
199
|
+
n[i][r] = {
|
|
200
|
+
parameters: o.map(
|
|
205
201
|
(c) => p(c, c?.component, c?.serializer, "parameter")
|
|
206
202
|
),
|
|
207
203
|
returns: a.map(
|
|
@@ -379,25 +375,25 @@ const wt = (e = [], s) => {
|
|
|
379
375
|
const t = s ? s.parameters : [];
|
|
380
376
|
if (Array.isArray(e))
|
|
381
377
|
return s && t.length > 0 && e.length > t.length && console.warn("Too many arguments provided for the endpoint."), e;
|
|
382
|
-
const n = [],
|
|
383
|
-
return t.forEach((r,
|
|
378
|
+
const n = [], i = Object.keys(e);
|
|
379
|
+
return t.forEach((r, o) => {
|
|
384
380
|
if (e.hasOwnProperty(r.parameter_name))
|
|
385
|
-
n[
|
|
381
|
+
n[o] = e[r.parameter_name];
|
|
386
382
|
else if (r.parameter_has_default)
|
|
387
|
-
n[
|
|
383
|
+
n[o] = r.parameter_default;
|
|
388
384
|
else
|
|
389
385
|
throw new Error(
|
|
390
386
|
`No value provided for required parameter: ${r.parameter_name}`
|
|
391
387
|
);
|
|
392
|
-
}),
|
|
393
|
-
if (!t.some((
|
|
388
|
+
}), i.forEach((r) => {
|
|
389
|
+
if (!t.some((o) => o.parameter_name === r))
|
|
394
390
|
throw new Error(
|
|
395
391
|
`Parameter \`${r}\` is not a valid keyword argument. Please refer to the API for usage.`
|
|
396
392
|
);
|
|
397
|
-
}), n.forEach((r,
|
|
398
|
-
if (r === void 0 && !t[
|
|
393
|
+
}), n.forEach((r, o) => {
|
|
394
|
+
if (r === void 0 && !t[o].parameter_has_default)
|
|
399
395
|
throw new Error(
|
|
400
|
-
`No value provided for required parameter: ${t[
|
|
396
|
+
`No value provided for required parameter: ${t[o].parameter_name}`
|
|
401
397
|
);
|
|
402
398
|
}), n;
|
|
403
399
|
};
|
|
@@ -406,9 +402,9 @@ async function yt() {
|
|
|
406
402
|
const { token: e } = this.options, { config: s } = this, t = { "Content-Type": "application/json" };
|
|
407
403
|
if (e && (t.Authorization = `Bearer ${e}`), !!s)
|
|
408
404
|
try {
|
|
409
|
-
let n,
|
|
405
|
+
let n, i;
|
|
410
406
|
if (typeof window < "u" && window.gradio_api_info)
|
|
411
|
-
|
|
407
|
+
i = window.gradio_api_info;
|
|
412
408
|
else {
|
|
413
409
|
const r = ae(s.root, this.api_prefix, Ve);
|
|
414
410
|
if (n = await this.fetch(r, {
|
|
@@ -416,9 +412,9 @@ async function yt() {
|
|
|
416
412
|
credentials: "include"
|
|
417
413
|
}), !n.ok)
|
|
418
414
|
throw new Error(M);
|
|
419
|
-
|
|
415
|
+
i = await n.json();
|
|
420
416
|
}
|
|
421
|
-
return "api" in
|
|
417
|
+
return "api" in i && (i = i.api), i.named_endpoints["/predict"] && !i.unnamed_endpoints[0] && (i.unnamed_endpoints[0] = i.named_endpoints["/predict"]), _t(i, s, this.api_map);
|
|
422
418
|
} catch (n) {
|
|
423
419
|
throw new Error("Could not get API info. " + n.message);
|
|
424
420
|
}
|
|
@@ -426,16 +422,16 @@ async function yt() {
|
|
|
426
422
|
async function bt(e, s, t) {
|
|
427
423
|
const n = {};
|
|
428
424
|
this?.options?.token && (n.Authorization = `Bearer ${this.options.token}`);
|
|
429
|
-
const
|
|
430
|
-
let
|
|
431
|
-
for (let a = 0; a < s.length; a +=
|
|
432
|
-
const u = s.slice(a, a +
|
|
425
|
+
const i = 1e3, r = [];
|
|
426
|
+
let o;
|
|
427
|
+
for (let a = 0; a < s.length; a += i) {
|
|
428
|
+
const u = s.slice(a, a + i), l = new FormData();
|
|
433
429
|
u.forEach((c) => {
|
|
434
430
|
l.append("files", c);
|
|
435
431
|
});
|
|
436
432
|
try {
|
|
437
433
|
const c = t ? `${e}${this.api_prefix}/${ye}?upload_id=${t}` : `${e}${this.api_prefix}/${ye}`;
|
|
438
|
-
|
|
434
|
+
o = await this.fetch(c, {
|
|
439
435
|
method: "POST",
|
|
440
436
|
body: l,
|
|
441
437
|
headers: n,
|
|
@@ -444,11 +440,11 @@ async function bt(e, s, t) {
|
|
|
444
440
|
} catch (c) {
|
|
445
441
|
throw new Error(M + c.message);
|
|
446
442
|
}
|
|
447
|
-
if (!
|
|
448
|
-
const c = await
|
|
449
|
-
return { error: `HTTP ${
|
|
443
|
+
if (!o.ok) {
|
|
444
|
+
const c = await o.text();
|
|
445
|
+
return { error: `HTTP ${o.status}: ${c}` };
|
|
450
446
|
}
|
|
451
|
-
const p = await
|
|
447
|
+
const p = await o.json();
|
|
452
448
|
p && r.push(...p);
|
|
453
449
|
}
|
|
454
450
|
return { files: r };
|
|
@@ -469,29 +465,29 @@ const vt = {
|
|
|
469
465
|
};
|
|
470
466
|
function $t(e, s = 1, t = "jedec") {
|
|
471
467
|
e = Math.abs(e);
|
|
472
|
-
const { radix: n, unit:
|
|
468
|
+
const { radix: n, unit: i } = Se[t] || Se.jedec;
|
|
473
469
|
let r = 0;
|
|
474
470
|
for (; e >= n; )
|
|
475
471
|
e /= n, ++r;
|
|
476
|
-
return `${e.toFixed(s)} ${
|
|
472
|
+
return `${e.toFixed(s)} ${i[r]}`;
|
|
477
473
|
}
|
|
478
474
|
async function kt(e, s, t, n) {
|
|
479
|
-
let
|
|
480
|
-
(
|
|
475
|
+
let i = (Array.isArray(e) ? e : [e]).map(
|
|
476
|
+
(o) => o.blob
|
|
481
477
|
);
|
|
482
|
-
const r =
|
|
483
|
-
(
|
|
478
|
+
const r = i.filter(
|
|
479
|
+
(o) => o.size > (n ?? 1 / 0)
|
|
484
480
|
);
|
|
485
481
|
if (r.length)
|
|
486
482
|
throw new Error(
|
|
487
|
-
`File(s) exceed the maximum allowed size of ${$t(n || 1 / 0)}: ${r.map((
|
|
483
|
+
`File(s) exceed the maximum allowed size of ${$t(n || 1 / 0)}: ${r.map((o) => `"${o.name}"`).join(", ")}`
|
|
488
484
|
);
|
|
489
485
|
return await Promise.all(
|
|
490
|
-
await this.upload_files(s,
|
|
491
|
-
async (
|
|
492
|
-
if (
|
|
493
|
-
throw new Error(
|
|
494
|
-
return
|
|
486
|
+
await this.upload_files(s, i, t).then(
|
|
487
|
+
async (o) => {
|
|
488
|
+
if (o.error)
|
|
489
|
+
throw new Error(o.error);
|
|
490
|
+
return o.files ? o.files.map((a, u) => new Q({
|
|
495
491
|
...e[u],
|
|
496
492
|
path: a,
|
|
497
493
|
url: `${s}${this.api_prefix}/file=${a}`
|
|
@@ -527,17 +523,17 @@ class Q {
|
|
|
527
523
|
path: s,
|
|
528
524
|
url: t,
|
|
529
525
|
orig_name: n,
|
|
530
|
-
size:
|
|
526
|
+
size: i,
|
|
531
527
|
blob: r,
|
|
532
|
-
is_stream:
|
|
528
|
+
is_stream: o,
|
|
533
529
|
mime_type: a,
|
|
534
530
|
alt_text: u,
|
|
535
531
|
b64: l
|
|
536
532
|
}) {
|
|
537
|
-
this.path = s, this.url = t, this.orig_name = n, this.size =
|
|
533
|
+
this.path = s, this.url = t, this.orig_name = n, this.size = i, this.blob = t ? void 0 : r, this.is_stream = o, this.mime_type = a, this.alt_text = u, this.b64 = l;
|
|
538
534
|
}
|
|
539
535
|
}
|
|
540
|
-
class
|
|
536
|
+
class Le {
|
|
541
537
|
type;
|
|
542
538
|
command;
|
|
543
539
|
meta;
|
|
@@ -549,9 +545,9 @@ class Pe {
|
|
|
549
545
|
const Rt = typeof process < "u" && process.versions && process.versions.node;
|
|
550
546
|
function $e(e, s, t) {
|
|
551
547
|
for (; t.length > 1; ) {
|
|
552
|
-
const
|
|
553
|
-
if (typeof
|
|
554
|
-
e = e[
|
|
548
|
+
const i = t.shift();
|
|
549
|
+
if (typeof i == "string" || typeof i == "number")
|
|
550
|
+
e = e[i];
|
|
555
551
|
else
|
|
556
552
|
throw new Error("Invalid key type");
|
|
557
553
|
}
|
|
@@ -561,19 +557,19 @@ function $e(e, s, t) {
|
|
|
561
557
|
else
|
|
562
558
|
throw new Error("Invalid key type");
|
|
563
559
|
}
|
|
564
|
-
async function ce(e, s = void 0, t = [], n = !1,
|
|
560
|
+
async function ce(e, s = void 0, t = [], n = !1, i = void 0) {
|
|
565
561
|
if (Array.isArray(e)) {
|
|
566
562
|
let r = [];
|
|
567
563
|
return await Promise.all(
|
|
568
|
-
e.map(async (
|
|
564
|
+
e.map(async (o, a) => {
|
|
569
565
|
let u = t.slice();
|
|
570
566
|
u.push(String(a));
|
|
571
567
|
const l = await ce(
|
|
572
568
|
e[a],
|
|
573
|
-
n ?
|
|
569
|
+
n ? i?.parameters[a]?.component || void 0 : s,
|
|
574
570
|
u,
|
|
575
571
|
!1,
|
|
576
|
-
|
|
572
|
+
i
|
|
577
573
|
);
|
|
578
574
|
r = r.concat(l);
|
|
579
575
|
})
|
|
@@ -589,15 +585,15 @@ async function ce(e, s = void 0, t = [], n = !1, o = void 0) {
|
|
|
589
585
|
];
|
|
590
586
|
if (typeof e == "object" && e !== null) {
|
|
591
587
|
let r = [];
|
|
592
|
-
for (const
|
|
593
|
-
const a = [...t,
|
|
588
|
+
for (const o of Object.keys(e)) {
|
|
589
|
+
const a = [...t, o], u = e[o];
|
|
594
590
|
r = r.concat(
|
|
595
591
|
await ce(
|
|
596
592
|
u,
|
|
597
593
|
void 0,
|
|
598
594
|
a,
|
|
599
595
|
!1,
|
|
600
|
-
|
|
596
|
+
i
|
|
601
597
|
)
|
|
602
598
|
);
|
|
603
599
|
}
|
|
@@ -612,10 +608,10 @@ function Ot(e, s) {
|
|
|
612
608
|
}
|
|
613
609
|
function Tt(e, s) {
|
|
614
610
|
return new Promise((t, n) => {
|
|
615
|
-
const
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
}), window.parent.postMessage(e, s, [
|
|
611
|
+
const i = new MessageChannel();
|
|
612
|
+
i.port1.onmessage = (({ data: r }) => {
|
|
613
|
+
i.port1.close(), t(r);
|
|
614
|
+
}), window.parent.postMessage(e, s, [i.port2]);
|
|
619
615
|
});
|
|
620
616
|
}
|
|
621
617
|
function es(e) {
|
|
@@ -628,7 +624,7 @@ function es(e) {
|
|
|
628
624
|
meta: { _type: "gradio.FileData" }
|
|
629
625
|
};
|
|
630
626
|
if (Rt)
|
|
631
|
-
return new
|
|
627
|
+
return new Le("upload_file", {
|
|
632
628
|
path: e,
|
|
633
629
|
name: e,
|
|
634
630
|
orig_path: e
|
|
@@ -645,30 +641,30 @@ function es(e) {
|
|
|
645
641
|
"Invalid input: must be a URL, File, Blob, or Buffer object."
|
|
646
642
|
);
|
|
647
643
|
}
|
|
648
|
-
function V(e, s, t, n,
|
|
649
|
-
if (n === "input" && !
|
|
644
|
+
function V(e, s, t, n, i = !1) {
|
|
645
|
+
if (n === "input" && !i)
|
|
650
646
|
throw new Error("Invalid code path. Cannot skip state inputs for input.");
|
|
651
|
-
if (n === "output" &&
|
|
647
|
+
if (n === "output" && i)
|
|
652
648
|
return e;
|
|
653
|
-
let r = [],
|
|
649
|
+
let r = [], o = 0;
|
|
654
650
|
const a = n === "input" ? s.inputs : s.outputs;
|
|
655
651
|
for (let u = 0; u < a.length; u++) {
|
|
656
652
|
const l = a[u];
|
|
657
653
|
if (t.find((c) => c.id === l)?.type === "state") {
|
|
658
|
-
if (
|
|
654
|
+
if (i)
|
|
659
655
|
if (e.length === a.length) {
|
|
660
|
-
const c = e[
|
|
661
|
-
r.push(c),
|
|
656
|
+
const c = e[o];
|
|
657
|
+
r.push(c), o++;
|
|
662
658
|
} else
|
|
663
659
|
r.push(null);
|
|
664
660
|
else {
|
|
665
|
-
|
|
661
|
+
o++;
|
|
666
662
|
continue;
|
|
667
663
|
}
|
|
668
664
|
continue;
|
|
669
665
|
} else {
|
|
670
|
-
const c = e[
|
|
671
|
-
r.push(c),
|
|
666
|
+
const c = e[o];
|
|
667
|
+
r.push(c), o++;
|
|
672
668
|
}
|
|
673
669
|
}
|
|
674
670
|
return r;
|
|
@@ -676,7 +672,7 @@ function V(e, s, t, n, o = !1) {
|
|
|
676
672
|
async function At(e, s, t) {
|
|
677
673
|
const n = this;
|
|
678
674
|
await xt(n, s);
|
|
679
|
-
const
|
|
675
|
+
const i = await ce(
|
|
680
676
|
s,
|
|
681
677
|
void 0,
|
|
682
678
|
[],
|
|
@@ -684,49 +680,49 @@ async function At(e, s, t) {
|
|
|
684
680
|
t
|
|
685
681
|
);
|
|
686
682
|
return (await Promise.all(
|
|
687
|
-
|
|
688
|
-
if (!a) return { path:
|
|
683
|
+
i.map(async ({ path: o, blob: a, type: u }) => {
|
|
684
|
+
if (!a) return { path: o, type: u };
|
|
689
685
|
const l = await n.upload_files(e, [a]), p = l.files && l.files[0];
|
|
690
686
|
return {
|
|
691
|
-
path:
|
|
687
|
+
path: o,
|
|
692
688
|
file_url: p,
|
|
693
689
|
type: u,
|
|
694
690
|
name: typeof File < "u" && a instanceof File ? a?.name : void 0
|
|
695
691
|
};
|
|
696
692
|
})
|
|
697
|
-
)).forEach(({ path:
|
|
693
|
+
)).forEach(({ path: o, file_url: a, type: u, name: l }) => {
|
|
698
694
|
if (u === "Gallery")
|
|
699
|
-
$e(s, a,
|
|
695
|
+
$e(s, a, o);
|
|
700
696
|
else if (a) {
|
|
701
697
|
const p = new Q({ path: a, orig_name: l });
|
|
702
|
-
$e(s, p,
|
|
698
|
+
$e(s, p, o);
|
|
703
699
|
}
|
|
704
700
|
}), s;
|
|
705
701
|
}
|
|
706
702
|
async function xt(e, s) {
|
|
707
703
|
if (!(e.config?.root || e.config?.root_url))
|
|
708
704
|
throw new Error(Ce);
|
|
709
|
-
await
|
|
705
|
+
await Pe(e, s);
|
|
710
706
|
}
|
|
711
|
-
async function
|
|
707
|
+
async function Pe(e, s, t = []) {
|
|
712
708
|
for (const n in s)
|
|
713
|
-
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]);
|
|
714
710
|
}
|
|
715
711
|
async function Ct(e, s, t) {
|
|
716
712
|
let n = s[t];
|
|
717
|
-
const
|
|
718
|
-
if (!
|
|
713
|
+
const i = e.config?.root || e.config?.root_url;
|
|
714
|
+
if (!i)
|
|
719
715
|
throw new Error(Ce);
|
|
720
716
|
try {
|
|
721
|
-
let r,
|
|
717
|
+
let r, o;
|
|
722
718
|
if (typeof process < "u" && process.versions && process.versions.node) {
|
|
723
719
|
const p = await import("./__vite-browser-external-DYxpcVy9.js");
|
|
724
|
-
|
|
720
|
+
o = (await import("./__vite-browser-external-DYxpcVy9.js")).resolve(process.cwd(), n.meta.path), r = await p.readFile(o);
|
|
725
721
|
} else
|
|
726
722
|
throw new Error(ut);
|
|
727
723
|
const a = new Blob([r], {
|
|
728
724
|
type: "application/octet-stream"
|
|
729
|
-
}), u = await e.upload_files(
|
|
725
|
+
}), u = await e.upload_files(i, [a]), l = u.files && u.files[0];
|
|
730
726
|
if (l) {
|
|
731
727
|
const p = new Q({
|
|
732
728
|
path: l,
|
|
@@ -738,11 +734,11 @@ async function Ct(e, s, t) {
|
|
|
738
734
|
console.error(lt, r);
|
|
739
735
|
}
|
|
740
736
|
}
|
|
741
|
-
async function
|
|
737
|
+
async function Dt(e, s, t) {
|
|
742
738
|
const n = { "Content-Type": "application/json" };
|
|
743
739
|
this.options.token && (n.Authorization = `Bearer ${this.options.token}`);
|
|
744
740
|
try {
|
|
745
|
-
var
|
|
741
|
+
var i = await this.fetch(e, {
|
|
746
742
|
method: "POST",
|
|
747
743
|
body: JSON.stringify(s),
|
|
748
744
|
headers: { ...n, ...t },
|
|
@@ -751,61 +747,61 @@ async function Nt(e, s, t) {
|
|
|
751
747
|
} catch {
|
|
752
748
|
return [{ error: M }, 500];
|
|
753
749
|
}
|
|
754
|
-
let r,
|
|
750
|
+
let r, o;
|
|
755
751
|
try {
|
|
756
|
-
r = await
|
|
752
|
+
r = await i.json(), o = i.status;
|
|
757
753
|
} catch (a) {
|
|
758
|
-
r = { error: `Could not parse server response: ${a}` },
|
|
754
|
+
r = { error: `Could not parse server response: ${a}` }, o = 500;
|
|
759
755
|
}
|
|
760
|
-
return [r,
|
|
756
|
+
return [r, o];
|
|
761
757
|
}
|
|
762
|
-
async function
|
|
758
|
+
async function Nt(e, s = {}) {
|
|
763
759
|
let t = !1, n = !1;
|
|
764
760
|
if (!this.config)
|
|
765
761
|
throw new Error("Could not resolve app config");
|
|
766
762
|
if (typeof e == "number")
|
|
767
|
-
this.config.dependencies.find((
|
|
763
|
+
this.config.dependencies.find((i) => i.id == e);
|
|
768
764
|
else {
|
|
769
|
-
const
|
|
765
|
+
const i = e.replace(/^\//, "");
|
|
770
766
|
this.config.dependencies.find(
|
|
771
|
-
(r) => r.id == this.api_map[
|
|
767
|
+
(r) => r.id == this.api_map[i]
|
|
772
768
|
);
|
|
773
769
|
}
|
|
774
|
-
return new Promise(async (
|
|
775
|
-
const
|
|
770
|
+
return new Promise(async (i, r) => {
|
|
771
|
+
const o = this.submit(e, s, null, null, !0);
|
|
776
772
|
let a;
|
|
777
|
-
for await (const u of
|
|
778
|
-
u.type === "data" && (n &&
|
|
773
|
+
for await (const u of o)
|
|
774
|
+
u.type === "data" && (n && i(a), t = !0, a = u), u.type === "status" && (u.stage === "error" && r(u), u.stage === "complete" && (n = !0, t && i(a)));
|
|
779
775
|
});
|
|
780
776
|
}
|
|
781
777
|
async function G(e, s, t) {
|
|
782
|
-
let n = s === "subdomain" ? `https://huggingface.co/api/spaces/by-subdomain/${e}` : `https://huggingface.co/api/spaces/${e}`,
|
|
778
|
+
let n = s === "subdomain" ? `https://huggingface.co/api/spaces/by-subdomain/${e}` : `https://huggingface.co/api/spaces/${e}`, i, r;
|
|
783
779
|
try {
|
|
784
|
-
if (
|
|
780
|
+
if (i = await fetch(n), r = i.status, r !== 200)
|
|
785
781
|
throw new Error();
|
|
786
|
-
|
|
782
|
+
i = await i.json();
|
|
787
783
|
} catch {
|
|
788
784
|
t({
|
|
789
785
|
status: "error",
|
|
790
786
|
load_status: "error",
|
|
791
|
-
message:
|
|
787
|
+
message: it,
|
|
792
788
|
detail: "NOT_FOUND"
|
|
793
789
|
});
|
|
794
790
|
return;
|
|
795
791
|
}
|
|
796
|
-
if (!
|
|
792
|
+
if (!i || r !== 200) return;
|
|
797
793
|
const {
|
|
798
|
-
runtime: { stage:
|
|
794
|
+
runtime: { stage: o },
|
|
799
795
|
id: a
|
|
800
|
-
} =
|
|
801
|
-
switch (
|
|
796
|
+
} = i;
|
|
797
|
+
switch (o) {
|
|
802
798
|
case "STOPPED":
|
|
803
799
|
case "SLEEPING":
|
|
804
800
|
t({
|
|
805
801
|
status: "sleeping",
|
|
806
802
|
load_status: "pending",
|
|
807
803
|
message: "Space is asleep. Waking it up...",
|
|
808
|
-
detail:
|
|
804
|
+
detail: o
|
|
809
805
|
}), setTimeout(() => {
|
|
810
806
|
G(e, s, t);
|
|
811
807
|
}, 1e3);
|
|
@@ -815,7 +811,7 @@ async function G(e, s, t) {
|
|
|
815
811
|
status: "paused",
|
|
816
812
|
load_status: "error",
|
|
817
813
|
message: "This space has been paused by the author. If you would like to try this demo, consider duplicating the space.",
|
|
818
|
-
detail:
|
|
814
|
+
detail: o,
|
|
819
815
|
discussions_enabled: await ke(a)
|
|
820
816
|
});
|
|
821
817
|
break;
|
|
@@ -825,7 +821,7 @@ async function G(e, s, t) {
|
|
|
825
821
|
status: "running",
|
|
826
822
|
load_status: "complete",
|
|
827
823
|
message: "Space is running.",
|
|
828
|
-
detail:
|
|
824
|
+
detail: o
|
|
829
825
|
});
|
|
830
826
|
break;
|
|
831
827
|
case "BUILDING":
|
|
@@ -833,7 +829,7 @@ async function G(e, s, t) {
|
|
|
833
829
|
status: "building",
|
|
834
830
|
load_status: "pending",
|
|
835
831
|
message: "Space is building...",
|
|
836
|
-
detail:
|
|
832
|
+
detail: o
|
|
837
833
|
}), setTimeout(() => {
|
|
838
834
|
G(e, s, t);
|
|
839
835
|
}, 1e3);
|
|
@@ -843,7 +839,7 @@ async function G(e, s, t) {
|
|
|
843
839
|
status: "starting",
|
|
844
840
|
load_status: "pending",
|
|
845
841
|
message: "Space is starting...",
|
|
846
|
-
detail:
|
|
842
|
+
detail: o
|
|
847
843
|
}), setTimeout(() => {
|
|
848
844
|
G(e, s, t);
|
|
849
845
|
}, 1e3);
|
|
@@ -853,27 +849,27 @@ async function G(e, s, t) {
|
|
|
853
849
|
status: "space_error",
|
|
854
850
|
load_status: "error",
|
|
855
851
|
message: "This space is experiencing an issue.",
|
|
856
|
-
detail:
|
|
852
|
+
detail: o,
|
|
857
853
|
discussions_enabled: await ke(a)
|
|
858
854
|
});
|
|
859
855
|
break;
|
|
860
856
|
}
|
|
861
857
|
}
|
|
862
|
-
const
|
|
858
|
+
const Ie = async (e, s) => {
|
|
863
859
|
let t = 0;
|
|
864
|
-
const n = 12,
|
|
860
|
+
const n = 12, i = 5e3;
|
|
865
861
|
return new Promise((r) => {
|
|
866
862
|
G(
|
|
867
863
|
e,
|
|
868
864
|
le.test(e) ? "space_name" : "subdomain",
|
|
869
|
-
(
|
|
870
|
-
s(
|
|
871
|
-
|
|
872
|
-
},
|
|
865
|
+
(o) => {
|
|
866
|
+
s(o), o.status === "running" || o.status === "error" || o.status === "paused" || o.status === "space_error" ? r() : (o.status === "sleeping" || o.status === "building") && (t < n ? (t++, setTimeout(() => {
|
|
867
|
+
Ie(e, s).then(r);
|
|
868
|
+
}, i)) : r());
|
|
873
869
|
}
|
|
874
870
|
);
|
|
875
871
|
});
|
|
876
|
-
},
|
|
872
|
+
}, Lt = /^(?=[^]*\b[dD]iscussions{0,1}\b)(?=[^]*\b[dD]isabled\b)[^]*$/;
|
|
877
873
|
async function ke(e) {
|
|
878
874
|
try {
|
|
879
875
|
const s = await fetch(
|
|
@@ -882,12 +878,12 @@ async function ke(e) {
|
|
|
882
878
|
method: "HEAD"
|
|
883
879
|
}
|
|
884
880
|
), t = s.headers.get("x-error-message");
|
|
885
|
-
return !(!s.ok || t &&
|
|
881
|
+
return !(!s.ok || t && Lt.test(t));
|
|
886
882
|
} catch {
|
|
887
883
|
return !1;
|
|
888
884
|
}
|
|
889
885
|
}
|
|
890
|
-
async function
|
|
886
|
+
async function Pt(e, s) {
|
|
891
887
|
const t = {};
|
|
892
888
|
s && (t.Authorization = `Bearer ${s}`);
|
|
893
889
|
try {
|
|
@@ -897,16 +893,16 @@ async function Lt(e, s) {
|
|
|
897
893
|
);
|
|
898
894
|
if (n.status !== 200)
|
|
899
895
|
throw new Error("Space hardware could not be obtained.");
|
|
900
|
-
const { hardware:
|
|
901
|
-
return
|
|
896
|
+
const { hardware: i } = await n.json();
|
|
897
|
+
return i.current;
|
|
902
898
|
} catch (n) {
|
|
903
899
|
throw new Error(n.message);
|
|
904
900
|
}
|
|
905
901
|
}
|
|
906
|
-
async function
|
|
902
|
+
async function It(e, s, t) {
|
|
907
903
|
const n = {};
|
|
908
904
|
t && (n.Authorization = `Bearer ${t}`);
|
|
909
|
-
const
|
|
905
|
+
const i = {
|
|
910
906
|
seconds: s
|
|
911
907
|
};
|
|
912
908
|
try {
|
|
@@ -915,7 +911,7 @@ async function jt(e, s, t) {
|
|
|
915
911
|
{
|
|
916
912
|
method: "POST",
|
|
917
913
|
headers: { "Content-Type": "application/json", ...n },
|
|
918
|
-
body: JSON.stringify(
|
|
914
|
+
body: JSON.stringify(i)
|
|
919
915
|
}
|
|
920
916
|
);
|
|
921
917
|
if (r.status !== 200)
|
|
@@ -942,22 +938,22 @@ const Re = [
|
|
|
942
938
|
"h100",
|
|
943
939
|
"h100x8"
|
|
944
940
|
];
|
|
945
|
-
async function
|
|
946
|
-
const { token: t, private: n, hardware:
|
|
947
|
-
if (
|
|
941
|
+
async function jt(e, s) {
|
|
942
|
+
const { token: t, private: n, hardware: i, timeout: r, auth: o } = s;
|
|
943
|
+
if (i && !Re.includes(i))
|
|
948
944
|
throw new Error(
|
|
949
945
|
`Invalid hardware type provided. Valid types are: ${Re.map((g) => `"${g}"`).join(",")}.`
|
|
950
946
|
);
|
|
951
947
|
const { http_protocol: a, host: u } = await pe(e, t);
|
|
952
948
|
let l = null;
|
|
953
|
-
if (
|
|
954
|
-
const g = await
|
|
949
|
+
if (o) {
|
|
950
|
+
const g = await De(
|
|
955
951
|
a,
|
|
956
952
|
u,
|
|
957
|
-
|
|
953
|
+
o,
|
|
958
954
|
fetch
|
|
959
955
|
);
|
|
960
|
-
g && (l =
|
|
956
|
+
g && (l = Ne(g));
|
|
961
957
|
}
|
|
962
958
|
const p = {
|
|
963
959
|
Authorization: `Bearer ${t}`,
|
|
@@ -969,13 +965,13 @@ async function It(e, s) {
|
|
|
969
965
|
repository: `${c}/${m}`
|
|
970
966
|
};
|
|
971
967
|
n && (w.private = !0);
|
|
972
|
-
let
|
|
968
|
+
let N;
|
|
973
969
|
try {
|
|
974
|
-
|
|
970
|
+
i || (N = await Pt(e, t));
|
|
975
971
|
} catch (g) {
|
|
976
972
|
throw Error(ue + g.message);
|
|
977
973
|
}
|
|
978
|
-
const f =
|
|
974
|
+
const f = i || N || "cpu-basic";
|
|
979
975
|
w.hardware = f;
|
|
980
976
|
try {
|
|
981
977
|
const g = await fetch(
|
|
@@ -994,9 +990,9 @@ async function It(e, s) {
|
|
|
994
990
|
}
|
|
995
991
|
else if (g.status !== 200)
|
|
996
992
|
throw new Error(g.statusText);
|
|
997
|
-
const
|
|
998
|
-
return await
|
|
999
|
-
Ut(
|
|
993
|
+
const H = await g.json();
|
|
994
|
+
return await It(`${c}/${m}`, r || 300, t), await Y.connect(
|
|
995
|
+
Ut(H.url),
|
|
1000
996
|
s
|
|
1001
997
|
);
|
|
1002
998
|
} catch (g) {
|
|
@@ -1015,16 +1011,16 @@ class qt extends TransformStream {
|
|
|
1015
1011
|
super({
|
|
1016
1012
|
transform: (t, n) => {
|
|
1017
1013
|
for (t = this.#e + t; ; ) {
|
|
1018
|
-
const
|
|
1014
|
+
const i = t.indexOf(`
|
|
1019
1015
|
`), r = s.allowCR ? t.indexOf("\r") : -1;
|
|
1020
|
-
if (r !== -1 && r !== t.length - 1 && (
|
|
1016
|
+
if (r !== -1 && r !== t.length - 1 && (i === -1 || i - 1 > r)) {
|
|
1021
1017
|
n.enqueue(t.slice(0, r)), t = t.slice(r + 1);
|
|
1022
1018
|
continue;
|
|
1023
1019
|
}
|
|
1024
|
-
if (
|
|
1020
|
+
if (i === -1)
|
|
1025
1021
|
break;
|
|
1026
|
-
const
|
|
1027
|
-
n.enqueue(t.slice(0,
|
|
1022
|
+
const o = t[i - 1] === "\r" ? i - 1 : i;
|
|
1023
|
+
n.enqueue(t.slice(0, o)), t = t.slice(i + 1);
|
|
1028
1024
|
}
|
|
1029
1025
|
this.#e = t;
|
|
1030
1026
|
},
|
|
@@ -1055,19 +1051,19 @@ function Oe(e, s, t) {
|
|
|
1055
1051
|
async function* Ft(e, s) {
|
|
1056
1052
|
if (!e.body)
|
|
1057
1053
|
return;
|
|
1058
|
-
let t = zt(e.body), n,
|
|
1054
|
+
let t = zt(e.body), n, i = t.getReader(), r;
|
|
1059
1055
|
for (; ; ) {
|
|
1060
1056
|
if (s && s.aborted)
|
|
1061
|
-
return
|
|
1062
|
-
if (n = await
|
|
1057
|
+
return i.cancel();
|
|
1058
|
+
if (n = await i.read(), n.done)
|
|
1063
1059
|
return;
|
|
1064
1060
|
if (!n.value) {
|
|
1065
1061
|
r && (yield r), r = void 0;
|
|
1066
1062
|
continue;
|
|
1067
1063
|
}
|
|
1068
|
-
let [
|
|
1069
|
-
|
|
1070
|
-
` + a : a) :
|
|
1064
|
+
let [o, a] = Bt(n.value) || [];
|
|
1065
|
+
o === "data" ? (r ||= {}, r[o] = r[o] ? r[o] + `
|
|
1066
|
+
` + a : a) : o === "event" ? (r ||= {}, r[o] = a) : o === "id" ? (r ||= {}, r[o] = String(+a) === a ? +a : a) : o === "retry" && (r ||= {}, r[o] = +a || void 0);
|
|
1071
1067
|
}
|
|
1072
1068
|
}
|
|
1073
1069
|
async function Gt(e, s) {
|
|
@@ -1084,16 +1080,16 @@ async function Mt() {
|
|
|
1084
1080
|
unclosed_events: s,
|
|
1085
1081
|
pending_stream_messages: t,
|
|
1086
1082
|
stream_status: n,
|
|
1087
|
-
config:
|
|
1083
|
+
config: i,
|
|
1088
1084
|
jwt: r
|
|
1089
1085
|
} = this;
|
|
1090
|
-
const
|
|
1091
|
-
if (!
|
|
1086
|
+
const o = this;
|
|
1087
|
+
if (!i)
|
|
1092
1088
|
throw new Error("Could not resolve app config");
|
|
1093
1089
|
n.open = !0;
|
|
1094
1090
|
let a = null, u = new URLSearchParams({
|
|
1095
1091
|
session_hash: this.session_hash
|
|
1096
|
-
}).toString(), l = new URL(`${
|
|
1092
|
+
}).toString(), l = new URL(`${i.root}${this.api_prefix}/${Te}?${u}`);
|
|
1097
1093
|
if (r && l.searchParams.set("__sign", r), a = this.stream(l), !a) {
|
|
1098
1094
|
console.warn("Cannot connect to SSE endpoint: " + l.toString());
|
|
1099
1095
|
return;
|
|
@@ -1101,7 +1097,7 @@ async function Mt() {
|
|
|
1101
1097
|
a.onmessage = async function(p) {
|
|
1102
1098
|
let c = JSON.parse(p.data);
|
|
1103
1099
|
if (c.msg === "close_stream") {
|
|
1104
|
-
de(n,
|
|
1100
|
+
de(n, o.abort_controller);
|
|
1105
1101
|
return;
|
|
1106
1102
|
}
|
|
1107
1103
|
const m = c.event_id;
|
|
@@ -1111,9 +1107,9 @@ async function Mt() {
|
|
|
1111
1107
|
(w) => e[w](c)
|
|
1112
1108
|
)
|
|
1113
1109
|
);
|
|
1114
|
-
else if (e[m] &&
|
|
1110
|
+
else if (e[m] && i) {
|
|
1115
1111
|
c.msg === "process_completed" && ["sse", "sse_v1", "sse_v2", "sse_v2.1", "sse_v3"].includes(
|
|
1116
|
-
|
|
1112
|
+
i.protocol
|
|
1117
1113
|
) && s.delete(m);
|
|
1118
1114
|
let w = e[m];
|
|
1119
1115
|
typeof window < "u" && typeof document < "u" ? setTimeout(w, 0, c) : w(c);
|
|
@@ -1133,17 +1129,17 @@ async function Mt() {
|
|
|
1133
1129
|
function de(e, s) {
|
|
1134
1130
|
e && (e.open = !1, s?.abort());
|
|
1135
1131
|
}
|
|
1136
|
-
function
|
|
1137
|
-
!e[s] ? (e[s] = [], t.data.forEach((
|
|
1138
|
-
e[s][r] =
|
|
1139
|
-
})) : t.data.forEach((
|
|
1140
|
-
let
|
|
1141
|
-
e[s][r] =
|
|
1132
|
+
function Ht(e, s, t) {
|
|
1133
|
+
!e[s] ? (e[s] = [], t.data.forEach((i, r) => {
|
|
1134
|
+
e[s][r] = i;
|
|
1135
|
+
})) : t.data.forEach((i, r) => {
|
|
1136
|
+
let o = Jt(e[s][r], i);
|
|
1137
|
+
e[s][r] = o, t.data[r] = o;
|
|
1142
1138
|
});
|
|
1143
1139
|
}
|
|
1144
|
-
function
|
|
1145
|
-
return s.forEach(([t, n,
|
|
1146
|
-
e = Wt(e, n, t,
|
|
1140
|
+
function Jt(e, s) {
|
|
1141
|
+
return s.forEach(([t, n, i]) => {
|
|
1142
|
+
e = Wt(e, n, t, i);
|
|
1147
1143
|
}), e;
|
|
1148
1144
|
}
|
|
1149
1145
|
function Wt(e, s, t, n) {
|
|
@@ -1154,22 +1150,22 @@ function Wt(e, s, t, n) {
|
|
|
1154
1150
|
return e + n;
|
|
1155
1151
|
throw new Error(`Unsupported action: ${t}`);
|
|
1156
1152
|
}
|
|
1157
|
-
let
|
|
1158
|
-
for (let
|
|
1159
|
-
|
|
1153
|
+
let i = e;
|
|
1154
|
+
for (let o = 0; o < s.length - 1; o++)
|
|
1155
|
+
i = i[s[o]];
|
|
1160
1156
|
const r = s[s.length - 1];
|
|
1161
1157
|
switch (t) {
|
|
1162
1158
|
case "replace":
|
|
1163
|
-
|
|
1159
|
+
i[r] = n;
|
|
1164
1160
|
break;
|
|
1165
1161
|
case "append":
|
|
1166
|
-
|
|
1162
|
+
i[r] += n;
|
|
1167
1163
|
break;
|
|
1168
1164
|
case "add":
|
|
1169
|
-
Array.isArray(
|
|
1165
|
+
Array.isArray(i) ? i.splice(Number(r), 0, n) : i[r] = n;
|
|
1170
1166
|
break;
|
|
1171
1167
|
case "delete":
|
|
1172
|
-
Array.isArray(
|
|
1168
|
+
Array.isArray(i) ? i.splice(Number(r), 1) : delete i[r];
|
|
1173
1169
|
break;
|
|
1174
1170
|
default:
|
|
1175
1171
|
throw new Error(`Unknown action: ${t}`);
|
|
@@ -1203,20 +1199,20 @@ function Zt(e, s = {}) {
|
|
|
1203
1199
|
return Gt(e, s).then(async (n) => {
|
|
1204
1200
|
t.readyState = t.OPEN;
|
|
1205
1201
|
try {
|
|
1206
|
-
for await (const
|
|
1207
|
-
t.onmessage && t.onmessage(
|
|
1202
|
+
for await (const i of n)
|
|
1203
|
+
t.onmessage && t.onmessage(i);
|
|
1208
1204
|
t.readyState = t.CLOSED;
|
|
1209
|
-
} catch (
|
|
1210
|
-
t.onerror && t.onerror(
|
|
1205
|
+
} catch (i) {
|
|
1206
|
+
t.onerror && t.onerror(i), t.readyState = t.CLOSED;
|
|
1211
1207
|
}
|
|
1212
1208
|
}).catch((n) => {
|
|
1213
1209
|
console.error(n), t.onerror && t.onerror(n), t.readyState = t.CLOSED;
|
|
1214
1210
|
}), t;
|
|
1215
1211
|
}
|
|
1216
|
-
function Kt(e, s = {}, t, n,
|
|
1212
|
+
function Kt(e, s = {}, t, n, i, r) {
|
|
1217
1213
|
try {
|
|
1218
|
-
let
|
|
1219
|
-
(
|
|
1214
|
+
let o = function(h) {
|
|
1215
|
+
(i || ze[h.type]) && p(h);
|
|
1220
1216
|
}, a = function() {
|
|
1221
1217
|
for (Me = !0; F.length > 0; )
|
|
1222
1218
|
F.shift()({
|
|
@@ -1224,44 +1220,44 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1224
1220
|
done: !0
|
|
1225
1221
|
});
|
|
1226
1222
|
}, u = function(h) {
|
|
1227
|
-
F.length > 0 ? F.shift()(h) :
|
|
1223
|
+
F.length > 0 ? F.shift()(h) : ie.push(h);
|
|
1228
1224
|
}, l = function(h) {
|
|
1229
1225
|
u(Vt(h)), a();
|
|
1230
1226
|
}, p = function(h) {
|
|
1231
1227
|
u({ value: h, done: !1 });
|
|
1232
1228
|
}, c = function() {
|
|
1233
|
-
return
|
|
1229
|
+
return ie.length > 0 ? Promise.resolve(ie.shift()) : new Promise((h) => F.push(h));
|
|
1234
1230
|
};
|
|
1235
1231
|
const { token: m } = this.options, {
|
|
1236
1232
|
fetch: w,
|
|
1237
|
-
app_reference:
|
|
1233
|
+
app_reference: N,
|
|
1238
1234
|
config: f,
|
|
1239
1235
|
session_hash: g,
|
|
1240
|
-
api_info:
|
|
1236
|
+
api_info: H,
|
|
1241
1237
|
api_map: q,
|
|
1242
1238
|
stream_status: X,
|
|
1243
1239
|
pending_stream_messages: ee,
|
|
1244
1240
|
pending_diff_streams: te,
|
|
1245
1241
|
event_callbacks: se,
|
|
1246
|
-
unclosed_events:
|
|
1242
|
+
unclosed_events: je,
|
|
1247
1243
|
post_data: ne,
|
|
1248
|
-
options:
|
|
1244
|
+
options: J,
|
|
1249
1245
|
api_prefix: R
|
|
1250
1246
|
} = this, he = r || { "x-gradio-user": "api" }, Ue = this;
|
|
1251
|
-
if (!
|
|
1247
|
+
if (!H) throw new Error("No API found");
|
|
1252
1248
|
if (!f) throw new Error("Could not resolve app config");
|
|
1253
1249
|
let { fn_index: d, endpoint_info: fe, dependency: z } = Yt(
|
|
1254
|
-
|
|
1250
|
+
H,
|
|
1255
1251
|
e,
|
|
1256
1252
|
q,
|
|
1257
1253
|
f
|
|
1258
|
-
), qe = wt(s, fe),
|
|
1254
|
+
), qe = wt(s, fe), j, O = f.protocol ?? "ws";
|
|
1259
1255
|
if (O === "ws")
|
|
1260
1256
|
throw new Error("WebSocket protocol is not supported in this version");
|
|
1261
1257
|
let U = "", Qt = () => U;
|
|
1262
1258
|
const _ = typeof e == "number" ? "/predict" : e;
|
|
1263
1259
|
let W, b = null, T = !1, _e = {}, B = typeof window < "u" && typeof document < "u" ? new URLSearchParams(window.location.search).toString() : "";
|
|
1264
|
-
const ze =
|
|
1260
|
+
const ze = J?.events?.reduce(
|
|
1265
1261
|
(h, k) => (h[k] = !0, h),
|
|
1266
1262
|
{}
|
|
1267
1263
|
) || {};
|
|
@@ -1300,9 +1296,9 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1300
1296
|
...h.dependencies
|
|
1301
1297
|
];
|
|
1302
1298
|
const Z = f.components.some((v) => v.type === "state"), y = f.dependencies.some(
|
|
1303
|
-
(v) => v.targets.some((
|
|
1299
|
+
(v) => v.targets.some((L) => L[1] === "unload")
|
|
1304
1300
|
);
|
|
1305
|
-
f.connect_heartbeat = Z || y, await Fe(f),
|
|
1301
|
+
f.connect_heartbeat = Z || y, await Fe(f), o({
|
|
1306
1302
|
type: "render",
|
|
1307
1303
|
data: h,
|
|
1308
1304
|
endpoint: _,
|
|
@@ -1326,7 +1322,7 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1326
1322
|
fn_index: d,
|
|
1327
1323
|
trigger_id: n
|
|
1328
1324
|
}, Ot(d, f))
|
|
1329
|
-
|
|
1325
|
+
o({
|
|
1330
1326
|
type: "status",
|
|
1331
1327
|
endpoint: _,
|
|
1332
1328
|
stage: "pending",
|
|
@@ -1341,22 +1337,22 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1341
1337
|
},
|
|
1342
1338
|
he
|
|
1343
1339
|
).then(async ([y, v]) => {
|
|
1344
|
-
const
|
|
1345
|
-
v == 200 ? (
|
|
1340
|
+
const L = y.data;
|
|
1341
|
+
v == 200 ? (o({
|
|
1346
1342
|
type: "data",
|
|
1347
1343
|
endpoint: _,
|
|
1348
1344
|
fn_index: d,
|
|
1349
1345
|
data: V(
|
|
1350
|
-
|
|
1346
|
+
L,
|
|
1351
1347
|
z,
|
|
1352
1348
|
f.components,
|
|
1353
1349
|
"output",
|
|
1354
|
-
|
|
1350
|
+
J.with_null_state
|
|
1355
1351
|
),
|
|
1356
1352
|
time: /* @__PURE__ */ new Date(),
|
|
1357
1353
|
event_data: t,
|
|
1358
1354
|
trigger_id: n
|
|
1359
|
-
}), y.render_config && await me(y.render_config),
|
|
1355
|
+
}), y.render_config && await me(y.render_config), o({
|
|
1360
1356
|
type: "status",
|
|
1361
1357
|
endpoint: _,
|
|
1362
1358
|
fn_index: d,
|
|
@@ -1364,7 +1360,7 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1364
1360
|
eta: y.average_duration,
|
|
1365
1361
|
queue: !1,
|
|
1366
1362
|
time: /* @__PURE__ */ new Date()
|
|
1367
|
-
})) :
|
|
1363
|
+
})) : o({
|
|
1368
1364
|
type: "status",
|
|
1369
1365
|
stage: "error",
|
|
1370
1366
|
endpoint: _,
|
|
@@ -1374,7 +1370,7 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1374
1370
|
time: /* @__PURE__ */ new Date()
|
|
1375
1371
|
});
|
|
1376
1372
|
}).catch((y) => {
|
|
1377
|
-
|
|
1373
|
+
o({
|
|
1378
1374
|
type: "status",
|
|
1379
1375
|
stage: "error",
|
|
1380
1376
|
message: y.message,
|
|
@@ -1385,7 +1381,7 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1385
1381
|
});
|
|
1386
1382
|
});
|
|
1387
1383
|
else if (O == "sse") {
|
|
1388
|
-
|
|
1384
|
+
o({
|
|
1389
1385
|
type: "status",
|
|
1390
1386
|
stage: "pending",
|
|
1391
1387
|
queue: !0,
|
|
@@ -1400,25 +1396,25 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1400
1396
|
let y = new URL(
|
|
1401
1397
|
`${f.root}${R}/${Te}?${B ? B + "&" : ""}${Z}`
|
|
1402
1398
|
);
|
|
1403
|
-
if (this.jwt && y.searchParams.set("__sign", this.jwt),
|
|
1399
|
+
if (this.jwt && y.searchParams.set("__sign", this.jwt), j = this.stream(y), !j)
|
|
1404
1400
|
return Promise.reject(
|
|
1405
1401
|
new Error("Cannot connect to SSE endpoint: " + y.toString())
|
|
1406
1402
|
);
|
|
1407
|
-
|
|
1408
|
-
const
|
|
1409
|
-
|
|
1403
|
+
j.onmessage = async function(v) {
|
|
1404
|
+
const L = JSON.parse(v.data), { type: P, status: A, data: x } = Ee(
|
|
1405
|
+
L,
|
|
1410
1406
|
_e[d]
|
|
1411
1407
|
);
|
|
1412
|
-
if (
|
|
1413
|
-
|
|
1408
|
+
if (P === "update" && A && !T)
|
|
1409
|
+
o({
|
|
1414
1410
|
type: "status",
|
|
1415
1411
|
endpoint: _,
|
|
1416
1412
|
fn_index: d,
|
|
1417
1413
|
time: /* @__PURE__ */ new Date(),
|
|
1418
1414
|
...A
|
|
1419
|
-
}), A.stage === "error" && (
|
|
1420
|
-
else if (
|
|
1421
|
-
let [C,
|
|
1415
|
+
}), A.stage === "error" && (j?.close(), a());
|
|
1416
|
+
else if (P === "data") {
|
|
1417
|
+
let [C, I] = await ne(
|
|
1422
1418
|
`${f.root}${R}/queue/data`,
|
|
1423
1419
|
{
|
|
1424
1420
|
...W,
|
|
@@ -1426,7 +1422,7 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1426
1422
|
event_id: b
|
|
1427
1423
|
}
|
|
1428
1424
|
);
|
|
1429
|
-
|
|
1425
|
+
I !== 200 && (o({
|
|
1430
1426
|
type: "status",
|
|
1431
1427
|
stage: "error",
|
|
1432
1428
|
message: M,
|
|
@@ -1434,8 +1430,8 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1434
1430
|
endpoint: _,
|
|
1435
1431
|
fn_index: d,
|
|
1436
1432
|
time: /* @__PURE__ */ new Date()
|
|
1437
|
-
}),
|
|
1438
|
-
} else
|
|
1433
|
+
}), j?.close(), a());
|
|
1434
|
+
} else P === "complete" ? T = A : P === "log" ? o({
|
|
1439
1435
|
type: "log",
|
|
1440
1436
|
title: x.title,
|
|
1441
1437
|
log: x.log,
|
|
@@ -1444,7 +1440,7 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1444
1440
|
duration: x.duration,
|
|
1445
1441
|
visible: x.visible,
|
|
1446
1442
|
fn_index: d
|
|
1447
|
-
}) : (
|
|
1443
|
+
}) : (P === "generating" || P === "streaming") && o({
|
|
1448
1444
|
type: "status",
|
|
1449
1445
|
time: /* @__PURE__ */ new Date(),
|
|
1450
1446
|
...A,
|
|
@@ -1453,7 +1449,7 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1453
1449
|
endpoint: _,
|
|
1454
1450
|
fn_index: d
|
|
1455
1451
|
});
|
|
1456
|
-
x && (
|
|
1452
|
+
x && (o({
|
|
1457
1453
|
type: "data",
|
|
1458
1454
|
time: /* @__PURE__ */ new Date(),
|
|
1459
1455
|
data: V(
|
|
@@ -1461,13 +1457,13 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1461
1457
|
z,
|
|
1462
1458
|
f.components,
|
|
1463
1459
|
"output",
|
|
1464
|
-
|
|
1460
|
+
J.with_null_state
|
|
1465
1461
|
),
|
|
1466
1462
|
endpoint: _,
|
|
1467
1463
|
fn_index: d,
|
|
1468
1464
|
event_data: t,
|
|
1469
1465
|
trigger_id: n
|
|
1470
|
-
}), T && (
|
|
1466
|
+
}), T && (o({
|
|
1471
1467
|
type: "status",
|
|
1472
1468
|
time: /* @__PURE__ */ new Date(),
|
|
1473
1469
|
...T,
|
|
@@ -1475,10 +1471,10 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1475
1471
|
queue: !0,
|
|
1476
1472
|
endpoint: _,
|
|
1477
1473
|
fn_index: d
|
|
1478
|
-
}),
|
|
1474
|
+
}), j?.close(), a()));
|
|
1479
1475
|
};
|
|
1480
1476
|
} else if (O == "sse_v1" || O == "sse_v2" || O == "sse_v2.1" || O == "sse_v3") {
|
|
1481
|
-
|
|
1477
|
+
o({
|
|
1482
1478
|
type: "status",
|
|
1483
1479
|
stage: "pending",
|
|
1484
1480
|
queue: !0,
|
|
@@ -1488,20 +1484,20 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1488
1484
|
});
|
|
1489
1485
|
let y = "";
|
|
1490
1486
|
typeof window < "u" && typeof document < "u" && (y = window?.location?.hostname);
|
|
1491
|
-
const
|
|
1492
|
-
return (typeof window < "u" && typeof document < "u" && window.parent != window && window.supports_zerogpu_headers ? Tt("zerogpu-headers",
|
|
1493
|
-
const
|
|
1487
|
+
const L = y.includes(".dev.") ? `https://moon-${y.split(".")[1]}.dev.spaces.huggingface.tech` : "https://huggingface.co";
|
|
1488
|
+
return (typeof window < "u" && typeof document < "u" && window.parent != window && window.supports_zerogpu_headers ? Tt("zerogpu-headers", L) : Promise.resolve(null)).then((C) => {
|
|
1489
|
+
const I = { ...he, ...C || {} };
|
|
1494
1490
|
return ne(
|
|
1495
1491
|
`${f.root}${R}/${Ze}?${B}`,
|
|
1496
1492
|
{
|
|
1497
1493
|
...W,
|
|
1498
1494
|
session_hash: g
|
|
1499
1495
|
},
|
|
1500
|
-
|
|
1496
|
+
I
|
|
1501
1497
|
);
|
|
1502
|
-
}).then(async ([C,
|
|
1503
|
-
if (C.event_id && (U = C.event_id),
|
|
1504
|
-
|
|
1498
|
+
}).then(async ([C, I]) => {
|
|
1499
|
+
if (C.event_id && (U = C.event_id), I === 503)
|
|
1500
|
+
o({
|
|
1505
1501
|
type: "status",
|
|
1506
1502
|
stage: "error",
|
|
1507
1503
|
message: Ae,
|
|
@@ -1511,8 +1507,8 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1511
1507
|
time: /* @__PURE__ */ new Date(),
|
|
1512
1508
|
visible: !0
|
|
1513
1509
|
});
|
|
1514
|
-
else if (
|
|
1515
|
-
|
|
1510
|
+
else if (I === 422)
|
|
1511
|
+
o({
|
|
1516
1512
|
type: "status",
|
|
1517
1513
|
stage: "error",
|
|
1518
1514
|
message: C.detail,
|
|
@@ -1523,8 +1519,8 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1523
1519
|
time: /* @__PURE__ */ new Date(),
|
|
1524
1520
|
visible: !0
|
|
1525
1521
|
}), a();
|
|
1526
|
-
else if (
|
|
1527
|
-
|
|
1522
|
+
else if (I !== 200)
|
|
1523
|
+
o({
|
|
1528
1524
|
type: "status",
|
|
1529
1525
|
stage: "error",
|
|
1530
1526
|
broken: !1,
|
|
@@ -1537,41 +1533,41 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1537
1533
|
});
|
|
1538
1534
|
else {
|
|
1539
1535
|
b = C.event_id, U = b;
|
|
1540
|
-
let we = async function(
|
|
1536
|
+
let we = async function(oe) {
|
|
1541
1537
|
try {
|
|
1542
|
-
const { type: E, status: S, data: $, original_msg:
|
|
1543
|
-
|
|
1538
|
+
const { type: E, status: S, data: $, original_msg: He } = Ee(
|
|
1539
|
+
oe,
|
|
1544
1540
|
_e[d]
|
|
1545
1541
|
);
|
|
1546
1542
|
if (E == "heartbeat")
|
|
1547
1543
|
return;
|
|
1548
1544
|
if (E === "update" && S && !T)
|
|
1549
|
-
|
|
1545
|
+
o({
|
|
1550
1546
|
type: "status",
|
|
1551
1547
|
endpoint: _,
|
|
1552
1548
|
fn_index: d,
|
|
1553
1549
|
time: /* @__PURE__ */ new Date(),
|
|
1554
|
-
original_msg:
|
|
1550
|
+
original_msg: He,
|
|
1555
1551
|
...S
|
|
1556
1552
|
});
|
|
1557
1553
|
else if (E === "complete")
|
|
1558
1554
|
T = S;
|
|
1559
1555
|
else if (E == "unexpected_error" || E == "broken_connection") {
|
|
1560
1556
|
console.error("Unexpected error", S?.message);
|
|
1561
|
-
const
|
|
1562
|
-
|
|
1557
|
+
const Je = E === "broken_connection";
|
|
1558
|
+
o({
|
|
1563
1559
|
type: "status",
|
|
1564
1560
|
stage: "error",
|
|
1565
1561
|
message: S?.message || "An Unexpected Error Occurred!",
|
|
1566
1562
|
queue: !0,
|
|
1567
1563
|
endpoint: _,
|
|
1568
|
-
broken:
|
|
1564
|
+
broken: Je,
|
|
1569
1565
|
session_not_found: S?.session_not_found,
|
|
1570
1566
|
fn_index: d,
|
|
1571
1567
|
time: /* @__PURE__ */ new Date()
|
|
1572
1568
|
});
|
|
1573
1569
|
} else if (E === "log") {
|
|
1574
|
-
|
|
1570
|
+
o({
|
|
1575
1571
|
type: "log",
|
|
1576
1572
|
title: $.title,
|
|
1577
1573
|
log: $.log,
|
|
@@ -1582,7 +1578,7 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1582
1578
|
fn_index: d
|
|
1583
1579
|
});
|
|
1584
1580
|
return;
|
|
1585
|
-
} else (E === "generating" || E === "streaming") && (
|
|
1581
|
+
} else (E === "generating" || E === "streaming") && (o({
|
|
1586
1582
|
type: "status",
|
|
1587
1583
|
time: /* @__PURE__ */ new Date(),
|
|
1588
1584
|
...S,
|
|
@@ -1590,8 +1586,8 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1590
1586
|
queue: !0,
|
|
1591
1587
|
endpoint: _,
|
|
1592
1588
|
fn_index: d
|
|
1593
|
-
}), $ && z.connection !== "stream" && ["sse_v2", "sse_v2.1", "sse_v3"].includes(O) &&
|
|
1594
|
-
$ && (
|
|
1589
|
+
}), $ && z.connection !== "stream" && ["sse_v2", "sse_v2.1", "sse_v3"].includes(O) && Ht(te, b, $));
|
|
1590
|
+
$ && (o({
|
|
1595
1591
|
type: "data",
|
|
1596
1592
|
time: /* @__PURE__ */ new Date(),
|
|
1597
1593
|
data: V(
|
|
@@ -1599,11 +1595,11 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1599
1595
|
z,
|
|
1600
1596
|
f.components,
|
|
1601
1597
|
"output",
|
|
1602
|
-
|
|
1598
|
+
J.with_null_state
|
|
1603
1599
|
),
|
|
1604
1600
|
endpoint: _,
|
|
1605
1601
|
fn_index: d
|
|
1606
|
-
}), $.render_config && await me($.render_config), T && (
|
|
1602
|
+
}), $.render_config && await me($.render_config), T && (o({
|
|
1607
1603
|
type: "status",
|
|
1608
1604
|
time: /* @__PURE__ */ new Date(),
|
|
1609
1605
|
...T,
|
|
@@ -1613,7 +1609,7 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1613
1609
|
fn_index: d
|
|
1614
1610
|
}), a())), (S?.stage === "complete" || S?.stage === "error") && (se[b] && delete se[b], b in te && delete te[b]);
|
|
1615
1611
|
} catch (E) {
|
|
1616
|
-
console.error("Unexpected client exception", E),
|
|
1612
|
+
console.error("Unexpected client exception", E), o({
|
|
1617
1613
|
type: "status",
|
|
1618
1614
|
stage: "error",
|
|
1619
1615
|
message: "An Unexpected Error Occurred!",
|
|
@@ -1624,13 +1620,13 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1624
1620
|
}), ["sse_v2", "sse_v2.1", "sse_v3"].includes(O) && (de(X, Ue.abort_controller), X.open = !1, a());
|
|
1625
1621
|
}
|
|
1626
1622
|
};
|
|
1627
|
-
b in ee && (ee[b].forEach((
|
|
1623
|
+
b in ee && (ee[b].forEach((oe) => we(oe)), delete ee[b]), se[b] = we, je.add(b), X.open || await this.open_stream();
|
|
1628
1624
|
}
|
|
1629
1625
|
});
|
|
1630
1626
|
}
|
|
1631
1627
|
});
|
|
1632
1628
|
let Me = !1;
|
|
1633
|
-
const
|
|
1629
|
+
const ie = [], F = [], ge = {
|
|
1634
1630
|
[Symbol.asyncIterator]: () => ge,
|
|
1635
1631
|
next: c,
|
|
1636
1632
|
throw: async (h) => (l(h), c()),
|
|
@@ -1652,8 +1648,8 @@ function Kt(e, s = {}, t, n, o, r) {
|
|
|
1652
1648
|
wait_for_id: async () => (await Ge, b)
|
|
1653
1649
|
};
|
|
1654
1650
|
return ge;
|
|
1655
|
-
} catch (
|
|
1656
|
-
throw console.error("Submit function encountered an error:",
|
|
1651
|
+
} catch (o) {
|
|
1652
|
+
throw console.error("Submit function encountered an error:", o), o;
|
|
1657
1653
|
}
|
|
1658
1654
|
}
|
|
1659
1655
|
function Vt(e) {
|
|
@@ -1662,20 +1658,20 @@ function Vt(e) {
|
|
|
1662
1658
|
};
|
|
1663
1659
|
}
|
|
1664
1660
|
function Yt(e, s, t, n) {
|
|
1665
|
-
let
|
|
1661
|
+
let i, r, o;
|
|
1666
1662
|
if (typeof s == "number")
|
|
1667
|
-
|
|
1663
|
+
i = s, r = e.unnamed_endpoints[i], o = n.dependencies.find((a) => a.id == s);
|
|
1668
1664
|
else {
|
|
1669
1665
|
const a = s.replace(/^\//, "");
|
|
1670
|
-
|
|
1666
|
+
i = t[a], r = e.named_endpoints[s.trim()], o = n.dependencies.find(
|
|
1671
1667
|
(u) => u.id == t[a]
|
|
1672
1668
|
);
|
|
1673
1669
|
}
|
|
1674
|
-
if (typeof
|
|
1670
|
+
if (typeof i != "number")
|
|
1675
1671
|
throw new Error(
|
|
1676
1672
|
"There is no endpoint matching that name of fn_index matching that number."
|
|
1677
1673
|
);
|
|
1678
|
-
return { fn_index:
|
|
1674
|
+
return { fn_index: i, endpoint_info: r, dependency: o };
|
|
1679
1675
|
}
|
|
1680
1676
|
class Y {
|
|
1681
1677
|
app_reference;
|
|
@@ -1702,15 +1698,15 @@ class Y {
|
|
|
1702
1698
|
current_payload;
|
|
1703
1699
|
get_url_config(s = null) {
|
|
1704
1700
|
if (!this.config)
|
|
1705
|
-
throw new Error(
|
|
1701
|
+
throw new Error(D);
|
|
1706
1702
|
s === null && (s = window.location.href);
|
|
1707
|
-
const t = (
|
|
1708
|
-
let n = t(new URL(this.config.root).pathname),
|
|
1709
|
-
return
|
|
1703
|
+
const t = (o) => o.replace(/^\/+|\/+$/g, "");
|
|
1704
|
+
let n = t(new URL(this.config.root).pathname), i = t(new URL(s).pathname), r;
|
|
1705
|
+
return i.startsWith(n) ? r = t(i.substring(n.length)) : r = "", this.get_page_config(r);
|
|
1710
1706
|
}
|
|
1711
1707
|
get_page_config(s) {
|
|
1712
1708
|
if (!this.config)
|
|
1713
|
-
throw new Error(
|
|
1709
|
+
throw new Error(D);
|
|
1714
1710
|
let t = this.config;
|
|
1715
1711
|
return s in t.page || (s = ""), {
|
|
1716
1712
|
...t,
|
|
@@ -1726,17 +1722,15 @@ class Y {
|
|
|
1726
1722
|
}
|
|
1727
1723
|
fetch(s, t) {
|
|
1728
1724
|
const n = new Headers(t?.headers || {});
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
return fetch(s, { ...t, headers: n });
|
|
1725
|
+
return this && this.cookies && n.append("Cookie", this.cookies), this && this.options.headers && new Headers(this.options.headers).forEach((r, o) => {
|
|
1726
|
+
n.append(o, r);
|
|
1727
|
+
}), fetch(s, { ...t, headers: n });
|
|
1733
1728
|
}
|
|
1734
1729
|
stream(s) {
|
|
1735
1730
|
const t = new Headers();
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
return this && this.options.token && t.append("Authorization", `Bearer ${this.options.token}`), this.abort_controller = new AbortController(), this.stream_instance = Zt(s.toString(), {
|
|
1731
|
+
return this && this.cookies && t.append("Cookie", this.cookies), this && this.options.headers && new Headers(this.options.headers).forEach((i, r) => {
|
|
1732
|
+
t.append(r, i);
|
|
1733
|
+
}), this && this.options.token && t.append("Authorization", `Bearer ${this.options.token}`), this.abort_controller = new AbortController(), this.stream_instance = Zt(s.toString(), {
|
|
1740
1734
|
credentials: "include",
|
|
1741
1735
|
headers: t,
|
|
1742
1736
|
signal: this.abort_controller.signal
|
|
@@ -1753,7 +1747,7 @@ class Y {
|
|
|
1753
1747
|
resolve_config;
|
|
1754
1748
|
resolve_cookies;
|
|
1755
1749
|
constructor(s, t = { events: ["data"] }) {
|
|
1756
|
-
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 =
|
|
1750
|
+
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);
|
|
1757
1751
|
}
|
|
1758
1752
|
async init() {
|
|
1759
1753
|
this.options.auth && await this.resolve_cookies(), await this._resolve_config().then(
|
|
@@ -1802,34 +1796,34 @@ class Y {
|
|
|
1802
1796
|
static async duplicate(s, t = {
|
|
1803
1797
|
events: ["data"]
|
|
1804
1798
|
}) {
|
|
1805
|
-
return
|
|
1799
|
+
return jt(s, t);
|
|
1806
1800
|
}
|
|
1807
1801
|
async _resolve_config() {
|
|
1808
1802
|
const { http_protocol: s, host: t, space_id: n } = await pe(
|
|
1809
1803
|
this.app_reference,
|
|
1810
1804
|
this.options.token
|
|
1811
|
-
), { status_callback:
|
|
1812
|
-
n &&
|
|
1805
|
+
), { status_callback: i } = this.options;
|
|
1806
|
+
n && i && await Ie(n, i);
|
|
1813
1807
|
let r;
|
|
1814
1808
|
try {
|
|
1815
|
-
let
|
|
1816
|
-
if (r = await this.resolve_config(
|
|
1817
|
-
throw new Error(
|
|
1809
|
+
let o = `${s}//${t}`;
|
|
1810
|
+
if (r = await this.resolve_config(o), !r)
|
|
1811
|
+
throw new Error(D);
|
|
1818
1812
|
return this.config_success(r);
|
|
1819
|
-
} catch (
|
|
1820
|
-
if (n &&
|
|
1813
|
+
} catch (o) {
|
|
1814
|
+
if (n && i)
|
|
1821
1815
|
G(
|
|
1822
1816
|
n,
|
|
1823
1817
|
le.test(n) ? "space_name" : "subdomain",
|
|
1824
1818
|
this.handle_space_success
|
|
1825
1819
|
);
|
|
1826
1820
|
else
|
|
1827
|
-
throw
|
|
1821
|
+
throw i && i({
|
|
1828
1822
|
status: "error",
|
|
1829
1823
|
message: "Could not load this space.",
|
|
1830
1824
|
load_status: "error",
|
|
1831
1825
|
detail: "NOT_FOUND"
|
|
1832
|
-
}), Error(
|
|
1826
|
+
}), Error(o);
|
|
1833
1827
|
}
|
|
1834
1828
|
}
|
|
1835
1829
|
async config_success(s) {
|
|
@@ -1838,18 +1832,18 @@ class Y {
|
|
|
1838
1832
|
try {
|
|
1839
1833
|
this.api_info = await this.view_api();
|
|
1840
1834
|
} catch (t) {
|
|
1841
|
-
console.error(
|
|
1835
|
+
console.error(ot + t.message);
|
|
1842
1836
|
}
|
|
1843
1837
|
return this.prepare_return_obj();
|
|
1844
1838
|
}
|
|
1845
1839
|
async handle_space_success(s) {
|
|
1846
1840
|
if (!this)
|
|
1847
|
-
throw new Error(
|
|
1841
|
+
throw new Error(D);
|
|
1848
1842
|
const { status_callback: t } = this.options;
|
|
1849
1843
|
if (t && t(s), s.status === "running")
|
|
1850
1844
|
try {
|
|
1851
1845
|
if (this.config = await this._resolve_config(), this.api_prefix = this?.config?.api_prefix || "", !this.config)
|
|
1852
|
-
throw new Error(
|
|
1846
|
+
throw new Error(D);
|
|
1853
1847
|
return await this.config_success(this.config);
|
|
1854
1848
|
} catch (n) {
|
|
1855
1849
|
throw t && t({
|
|
@@ -1862,9 +1856,9 @@ class Y {
|
|
|
1862
1856
|
}
|
|
1863
1857
|
async component_server(s, t, n) {
|
|
1864
1858
|
if (!this.config)
|
|
1865
|
-
throw new Error(
|
|
1866
|
-
const
|
|
1867
|
-
r && (
|
|
1859
|
+
throw new Error(D);
|
|
1860
|
+
const i = {}, { token: r } = this.options, { session_hash: o } = this;
|
|
1861
|
+
r && (i.Authorization = `Bearer ${this.options.token}`);
|
|
1868
1862
|
let a, u = this.config.components.find(
|
|
1869
1863
|
(p) => p.id === s
|
|
1870
1864
|
);
|
|
@@ -1874,22 +1868,22 @@ class Y {
|
|
|
1874
1868
|
l = new FormData();
|
|
1875
1869
|
for (const p in n.data)
|
|
1876
1870
|
p !== "binary" && l.append(p, n.data[p]);
|
|
1877
|
-
l.set("component_id", s.toString()), l.set("fn_name", t), l.set("session_hash",
|
|
1871
|
+
l.set("component_id", s.toString()), l.set("fn_name", t), l.set("session_hash", o);
|
|
1878
1872
|
} else
|
|
1879
1873
|
l = JSON.stringify({
|
|
1880
1874
|
data: n,
|
|
1881
1875
|
component_id: s,
|
|
1882
1876
|
fn_name: t,
|
|
1883
|
-
session_hash:
|
|
1884
|
-
}),
|
|
1885
|
-
r && (
|
|
1877
|
+
session_hash: o
|
|
1878
|
+
}), i["Content-Type"] = "application/json";
|
|
1879
|
+
r && (i.Authorization = `Bearer ${r}`);
|
|
1886
1880
|
try {
|
|
1887
1881
|
const p = await this.fetch(
|
|
1888
1882
|
`${a}${this.api_prefix}/${et}/`,
|
|
1889
1883
|
{
|
|
1890
1884
|
method: "POST",
|
|
1891
1885
|
body: l,
|
|
1892
|
-
headers:
|
|
1886
|
+
headers: i,
|
|
1893
1887
|
credentials: "include"
|
|
1894
1888
|
}
|
|
1895
1889
|
);
|
|
@@ -1903,7 +1897,7 @@ class Y {
|
|
|
1903
1897
|
}
|
|
1904
1898
|
}
|
|
1905
1899
|
set_cookies(s) {
|
|
1906
|
-
this.cookies =
|
|
1900
|
+
this.cookies = Ne(s).join("; ");
|
|
1907
1901
|
}
|
|
1908
1902
|
prepare_return_obj() {
|
|
1909
1903
|
return {
|
|
@@ -1930,7 +1924,7 @@ export {
|
|
|
1930
1924
|
ts as client,
|
|
1931
1925
|
ss as duplicate,
|
|
1932
1926
|
es as handle_file,
|
|
1933
|
-
|
|
1927
|
+
Nt as predict,
|
|
1934
1928
|
Xt as prepare_files,
|
|
1935
1929
|
Kt as submit,
|
|
1936
1930
|
kt as upload,
|