@gradio/client 1.15.5 → 1.15.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/browser.es.js +217 -186
- package/dist/client.d.ts +2 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/helpers/api_info.d.ts +1 -1
- package/dist/helpers/api_info.d.ts.map +1 -1
- package/dist/index.js +42 -6
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/stream.d.ts.map +1 -1
- package/dist/utils/submit.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +23 -2
- package/src/constants.ts +1 -0
- package/src/helpers/api_info.ts +12 -0
- package/src/types.ts +2 -0
- package/src/utils/stream.ts +3 -2
- package/src/utils/submit.ts +9 -2
package/dist/browser.es.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
var
|
2
|
-
var
|
3
|
-
var u = (e, t, s) => (
|
1
|
+
var et = Object.defineProperty;
|
2
|
+
var tt = (e, t, s) => t in e ? et(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
|
3
|
+
var u = (e, t, s) => (tt(e, typeof t != "symbol" ? t + "" : t, s), s), $e = (e, t, s) => {
|
4
4
|
if (!t.has(e))
|
5
5
|
throw TypeError("Cannot " + s);
|
6
6
|
};
|
@@ -13,8 +13,8 @@ var fe = new Intl.Collator(0, { numeric: 1 }).compare;
|
|
13
13
|
function Pe(e, t, s) {
|
14
14
|
return e = e.split("."), t = t.split("."), fe(e[0], t[0]) || fe(e[1], t[1]) || (t[2] = t.slice(2).join("."), s = /[.-]/.test(e[2] = e.slice(2).join(".")), s == /[.-]/.test(t[2]) ? fe(e[2], t[2]) : s ? -1 : 1);
|
15
15
|
}
|
16
|
-
const
|
17
|
-
function
|
16
|
+
const st = "host", je = "queue/data", nt = "queue/join", Oe = "upload", it = "login", Ne = "config", ot = "info", rt = "runtime", at = "sleeptime", ct = "heartbeat", lt = "component_server", ut = "reset", pt = "cancel", ft = "app_id", ht = "https://gradio-space-api-fetcher-v2.hf.space/api", xe = "This application is currently busy. Please try again. ", J = "Connection errored out. ", z = "Could not resolve app config. ", dt = "Could not get space status. ", _t = "Could not get API info. ", me = "Space metadata could not be loaded. ", mt = "Invalid URL. A full URL path is required.", gt = "Not authorized to access this space. ", Ie = "Invalid credentials. Could not login. ", wt = "Login credentials are required to access this space.", yt = "File system access is only available in Node.js environments", Ue = "Root URL not found in client config", bt = "Error uploading file";
|
17
|
+
function vt(e, t, s) {
|
18
18
|
return t.startsWith("http://") || t.startsWith("https://") ? s ? e : t : e + t;
|
19
19
|
}
|
20
20
|
async function Te(e, t, s) {
|
@@ -29,13 +29,13 @@ async function Te(e, t, s) {
|
|
29
29
|
return !1;
|
30
30
|
}
|
31
31
|
}
|
32
|
-
function
|
32
|
+
function Et(e) {
|
33
33
|
let t = {};
|
34
34
|
return e.forEach(({ api_name: s, id: n }) => {
|
35
35
|
s && (t[s] = n);
|
36
36
|
}), t;
|
37
37
|
}
|
38
|
-
async function
|
38
|
+
async function St(e) {
|
39
39
|
const t = this.options.hf_token ? { Authorization: `Bearer ${this.options.hf_token}` } : {};
|
40
40
|
if (t["Content-Type"] = "application/json", typeof window < "u" && window.gradio_config && location.origin !== "http://localhost:9876" && !window.gradio_config.dev_mode)
|
41
41
|
return window.gradio_config.current_page && (e = e.substring(0, e.lastIndexOf("/"))), window.gradio_config.root = e, { ...window.gradio_config };
|
@@ -48,15 +48,15 @@ async function vt(e) {
|
|
48
48
|
headers: t,
|
49
49
|
credentials: "include"
|
50
50
|
});
|
51
|
-
return
|
51
|
+
return $t(n, e, !!this.options.auth);
|
52
52
|
}
|
53
53
|
throw new Error(z);
|
54
54
|
}
|
55
|
-
async function
|
55
|
+
async function $t(e, t, s) {
|
56
56
|
var n, i;
|
57
57
|
if ((e == null ? void 0 : e.status) === 401 && !s) {
|
58
58
|
const r = await e.json(), o = (n = r == null ? void 0 : r.detail) == null ? void 0 : n.auth_message;
|
59
|
-
throw new Error(o ||
|
59
|
+
throw new Error(o || wt);
|
60
60
|
} else if ((e == null ? void 0 : e.status) === 401 && s)
|
61
61
|
throw new Error(Ie);
|
62
62
|
if ((e == null ? void 0 : e.status) === 200) {
|
@@ -65,17 +65,17 @@ async function Et(e, t, s) {
|
|
65
65
|
o.id === void 0 && (o.id = a);
|
66
66
|
}), r;
|
67
67
|
} else if ((e == null ? void 0 : e.status) === 401)
|
68
|
-
throw new Error(
|
68
|
+
throw new Error(gt);
|
69
69
|
throw new Error(z);
|
70
70
|
}
|
71
|
-
async function
|
71
|
+
async function kt() {
|
72
72
|
const { http_protocol: e, host: t } = await te(
|
73
73
|
this.app_reference,
|
74
74
|
this.options.hf_token
|
75
75
|
);
|
76
76
|
try {
|
77
77
|
if (this.options.auth) {
|
78
|
-
const s = await
|
78
|
+
const s = await qe(
|
79
79
|
e,
|
80
80
|
t,
|
81
81
|
this.options.auth,
|
@@ -88,12 +88,12 @@ async function St() {
|
|
88
88
|
throw Error(s.message);
|
89
89
|
}
|
90
90
|
}
|
91
|
-
async function
|
91
|
+
async function qe(e, t, s, n, i) {
|
92
92
|
const r = new FormData();
|
93
93
|
r.append("username", s == null ? void 0 : s[0]), r.append("password", s == null ? void 0 : s[1]);
|
94
94
|
let o = {};
|
95
95
|
i && (o.Authorization = `Bearer ${i}`);
|
96
|
-
const a = await n(`${e}//${t}/${
|
96
|
+
const a = await n(`${e}//${t}/${it}`, {
|
97
97
|
headers: o,
|
98
98
|
method: "POST",
|
99
99
|
body: r,
|
@@ -130,7 +130,7 @@ const ze = (e) => {
|
|
130
130
|
const [i, r] = n.split(";")[0].split("=");
|
131
131
|
i && r && t.push(`${i.trim()}=${r.trim()}`);
|
132
132
|
}), t;
|
133
|
-
}, ge = /^[a-zA-Z0-9_\-\.]+\/[a-zA-Z0-9_\-\.]+$/,
|
133
|
+
}, ge = /^[a-zA-Z0-9_\-\.]+\/[a-zA-Z0-9_\-\.]+$/, Rt = /.*hf\.space\/{0,1}.*$/;
|
134
134
|
async function te(e, t) {
|
135
135
|
const s = {};
|
136
136
|
t && (s.Authorization = `Bearer ${t}`);
|
@@ -138,7 +138,7 @@ async function te(e, t) {
|
|
138
138
|
if (ge.test(n))
|
139
139
|
try {
|
140
140
|
const r = (await (await fetch(
|
141
|
-
`https://huggingface.co/api/spaces/${n}/${
|
141
|
+
`https://huggingface.co/api/spaces/${n}/${st}`,
|
142
142
|
{ headers: s }
|
143
143
|
)).json()).host;
|
144
144
|
return {
|
@@ -148,7 +148,7 @@ async function te(e, t) {
|
|
148
148
|
} catch {
|
149
149
|
throw new Error(me);
|
150
150
|
}
|
151
|
-
if (
|
151
|
+
if (Rt.test(n)) {
|
152
152
|
const { ws_protocol: i, http_protocol: r, host: o } = he(n);
|
153
153
|
return {
|
154
154
|
space_id: o.split("/")[0].replace(".hf.space", ""),
|
@@ -166,10 +166,10 @@ const Be = (...e) => {
|
|
166
166
|
try {
|
167
167
|
return e.reduce((t, s) => (t = t.replace(/\/+$/, ""), s = s.replace(/^\/+/, ""), new URL(s, t + "/").toString()));
|
168
168
|
} catch {
|
169
|
-
throw new Error(
|
169
|
+
throw new Error(mt);
|
170
170
|
}
|
171
171
|
};
|
172
|
-
function
|
172
|
+
function Ot(e, t, s) {
|
173
173
|
const n = {
|
174
174
|
named_endpoints: {},
|
175
175
|
unnamed_endpoints: {}
|
@@ -185,13 +185,13 @@ function kt(e, t, s) {
|
|
185
185
|
const c = t.dependencies.find((_) => _.id == l).inputs.map(
|
186
186
|
(_) => {
|
187
187
|
var N;
|
188
|
-
return (N = t.components.find((
|
188
|
+
return (N = t.components.find((C) => C.id === _)) == null ? void 0 : N.type;
|
189
189
|
}
|
190
190
|
);
|
191
191
|
try {
|
192
192
|
c.forEach((_, N) => {
|
193
193
|
if (_ === "state") {
|
194
|
-
const
|
194
|
+
const C = {
|
195
195
|
component: "state",
|
196
196
|
example: null,
|
197
197
|
parameter_default: null,
|
@@ -199,17 +199,17 @@ function kt(e, t, s) {
|
|
199
199
|
parameter_name: null,
|
200
200
|
hidden: !0
|
201
201
|
};
|
202
|
-
o.splice(N, 0,
|
202
|
+
o.splice(N, 0, C);
|
203
203
|
}
|
204
204
|
});
|
205
205
|
} catch (_) {
|
206
206
|
console.error(_);
|
207
207
|
}
|
208
208
|
}
|
209
|
-
const m = (c, _, N,
|
209
|
+
const m = (c, _, N, C) => ({
|
210
210
|
...c,
|
211
|
-
description:
|
212
|
-
type:
|
211
|
+
description: Tt(c == null ? void 0 : c.type, N),
|
212
|
+
type: Nt(c == null ? void 0 : c.type, _, N, C) || ""
|
213
213
|
});
|
214
214
|
n[i][r] = {
|
215
215
|
parameters: o.map(
|
@@ -224,7 +224,7 @@ function kt(e, t, s) {
|
|
224
224
|
));
|
225
225
|
}), n;
|
226
226
|
}
|
227
|
-
function
|
227
|
+
function Nt(e, t, s, n) {
|
228
228
|
if (t === "Api")
|
229
229
|
return e.type;
|
230
230
|
switch (e == null ? void 0 : e.type) {
|
@@ -246,7 +246,7 @@ function Rt(e, t, s, n) {
|
|
246
246
|
if (s === "GallerySerializable")
|
247
247
|
return n === "parameter" ? "[(Blob | File | Buffer), (string | null)][]" : "[{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}, (string | null))][]";
|
248
248
|
}
|
249
|
-
function
|
249
|
+
function Tt(e, t) {
|
250
250
|
return t === "GallerySerializable" ? "array of [file, label] tuples" : t === "ListStringSerializable" ? "array of strings" : t === "FileSerializable" ? "array of files or single file" : e == null ? void 0 : e.description;
|
251
251
|
}
|
252
252
|
function de(e, t) {
|
@@ -273,6 +273,17 @@ function de(e, t) {
|
|
273
273
|
case "unexpected_error":
|
274
274
|
return {
|
275
275
|
type: "unexpected_error",
|
276
|
+
status: {
|
277
|
+
queue: !0,
|
278
|
+
message: e.message,
|
279
|
+
session_not_found: e.session_not_found,
|
280
|
+
stage: "error",
|
281
|
+
success: !1
|
282
|
+
}
|
283
|
+
};
|
284
|
+
case "broken_connection":
|
285
|
+
return {
|
286
|
+
type: "broken_connection",
|
276
287
|
status: {
|
277
288
|
queue: !0,
|
278
289
|
message: e.message,
|
@@ -376,7 +387,7 @@ function de(e, t) {
|
|
376
387
|
}
|
377
388
|
return { type: "none", status: { stage: "error", queue: !0 } };
|
378
389
|
}
|
379
|
-
const
|
390
|
+
const Dt = (e = [], t) => {
|
380
391
|
const s = t ? t.parameters : [];
|
381
392
|
if (Array.isArray(e))
|
382
393
|
return t && s.length > 0 && e.length > s.length && console.warn("Too many arguments provided for the endpoint."), e;
|
@@ -402,7 +413,7 @@ const Nt = (e = [], t) => {
|
|
402
413
|
);
|
403
414
|
}), n;
|
404
415
|
};
|
405
|
-
async function
|
416
|
+
async function Ct() {
|
406
417
|
if (this.api_info)
|
407
418
|
return this.api_info;
|
408
419
|
const { hf_token: e } = this.options, { config: t } = this, s = { "Content-Type": "application/json" };
|
@@ -413,7 +424,7 @@ async function Tt() {
|
|
413
424
|
i = window.gradio_api_info;
|
414
425
|
else {
|
415
426
|
if (Pe((t == null ? void 0 : t.version) || "2.0.0", "3.30") < 0)
|
416
|
-
n = await this.fetch(
|
427
|
+
n = await this.fetch(ht, {
|
417
428
|
method: "POST",
|
418
429
|
body: JSON.stringify({
|
419
430
|
serialize: !1,
|
@@ -423,7 +434,7 @@ async function Tt() {
|
|
423
434
|
credentials: "include"
|
424
435
|
});
|
425
436
|
else {
|
426
|
-
const r = Be(t.root, this.api_prefix,
|
437
|
+
const r = Be(t.root, this.api_prefix, ot);
|
427
438
|
n = await this.fetch(r, {
|
428
439
|
headers: s,
|
429
440
|
credentials: "include"
|
@@ -433,12 +444,12 @@ async function Tt() {
|
|
433
444
|
throw new Error(J);
|
434
445
|
i = await n.json();
|
435
446
|
}
|
436
|
-
return "api" in i && (i = i.api), i.named_endpoints["/predict"] && !i.unnamed_endpoints[0] && (i.unnamed_endpoints[0] = i.named_endpoints["/predict"]),
|
447
|
+
return "api" in i && (i = i.api), i.named_endpoints["/predict"] && !i.unnamed_endpoints[0] && (i.unnamed_endpoints[0] = i.named_endpoints["/predict"]), Ot(i, t, this.api_map);
|
437
448
|
} catch (n) {
|
438
449
|
throw new Error("Could not get API info. " + n.message);
|
439
450
|
}
|
440
451
|
}
|
441
|
-
async function
|
452
|
+
async function At(e, t, s) {
|
442
453
|
var a;
|
443
454
|
const n = {};
|
444
455
|
(a = this == null ? void 0 : this.options) != null && a.hf_token && (n.Authorization = `Bearer ${this.options.hf_token}`);
|
@@ -469,7 +480,7 @@ async function Ct(e, t, s) {
|
|
469
480
|
}
|
470
481
|
return { files: r };
|
471
482
|
}
|
472
|
-
async function
|
483
|
+
async function Lt(e, t, s, n) {
|
473
484
|
let i = (Array.isArray(e) ? e : [e]).map(
|
474
485
|
(o) => o.blob
|
475
486
|
);
|
@@ -494,7 +505,7 @@ async function Dt(e, t, s, n) {
|
|
494
505
|
)
|
495
506
|
);
|
496
507
|
}
|
497
|
-
async function
|
508
|
+
async function as(e, t) {
|
498
509
|
return e.map(
|
499
510
|
(s) => new se({
|
500
511
|
path: s.name,
|
@@ -540,8 +551,8 @@ class Fe {
|
|
540
551
|
this.type = "command", this.command = t, this.meta = s;
|
541
552
|
}
|
542
553
|
}
|
543
|
-
const
|
544
|
-
function
|
554
|
+
const Pt = typeof process < "u" && process.versions && process.versions.node;
|
555
|
+
function De(e, t, s) {
|
545
556
|
for (; s.length > 1; ) {
|
546
557
|
const i = s.shift();
|
547
558
|
if (typeof i == "string" || typeof i == "number")
|
@@ -601,12 +612,12 @@ async function _e(e, t = void 0, s = [], n = !1, i = void 0) {
|
|
601
612
|
}
|
602
613
|
return [];
|
603
614
|
}
|
604
|
-
function
|
615
|
+
function jt(e, t) {
|
605
616
|
var n, i;
|
606
617
|
let s = (i = (n = t == null ? void 0 : t.dependencies) == null ? void 0 : n.find((r) => r.id == e)) == null ? void 0 : i.queue;
|
607
618
|
return s != null ? !s : !t.enable_queue;
|
608
619
|
}
|
609
|
-
function
|
620
|
+
function xt(e, t) {
|
610
621
|
return new Promise((s, n) => {
|
611
622
|
const i = new MessageChannel();
|
612
623
|
i.port1.onmessage = ({ data: r }) => {
|
@@ -614,7 +625,7 @@ function Pt(e, t) {
|
|
614
625
|
}, window.parent.postMessage(e, t, [i.port2]);
|
615
626
|
});
|
616
627
|
}
|
617
|
-
function
|
628
|
+
function cs(e) {
|
618
629
|
if (typeof e == "string") {
|
619
630
|
if (e.startsWith("http://") || e.startsWith("https://"))
|
620
631
|
return {
|
@@ -623,7 +634,7 @@ function rs(e) {
|
|
623
634
|
orig_name: e.split("/").pop() ?? "unknown",
|
624
635
|
meta: { _type: "gradio.FileData" }
|
625
636
|
};
|
626
|
-
if (
|
637
|
+
if (Pt)
|
627
638
|
return new Fe("upload_file", {
|
628
639
|
path: e,
|
629
640
|
name: e,
|
@@ -669,9 +680,9 @@ function X(e, t, s, n, i = !1) {
|
|
669
680
|
}
|
670
681
|
return r;
|
671
682
|
}
|
672
|
-
async function
|
683
|
+
async function It(e, t, s) {
|
673
684
|
const n = this;
|
674
|
-
await
|
685
|
+
await Ut(n, t);
|
675
686
|
const i = await _e(
|
676
687
|
t,
|
677
688
|
void 0,
|
@@ -693,36 +704,36 @@ async function jt(e, t, s) {
|
|
693
704
|
})
|
694
705
|
)).forEach(({ path: o, file_url: a, type: l, name: h }) => {
|
695
706
|
if (l === "Gallery")
|
696
|
-
|
707
|
+
De(t, a, o);
|
697
708
|
else if (a) {
|
698
709
|
const m = new se({ path: a, orig_name: h });
|
699
|
-
|
710
|
+
De(t, m, o);
|
700
711
|
}
|
701
712
|
}), t;
|
702
713
|
}
|
703
|
-
async function
|
714
|
+
async function Ut(e, t) {
|
704
715
|
var n, i;
|
705
716
|
if (!(((n = e.config) == null ? void 0 : n.root) || ((i = e.config) == null ? void 0 : i.root_url)))
|
706
|
-
throw new Error(
|
717
|
+
throw new Error(Ue);
|
707
718
|
await Ge(e, t);
|
708
719
|
}
|
709
720
|
async function Ge(e, t, s = []) {
|
710
721
|
for (const n in t)
|
711
|
-
t[n] instanceof Fe ? await
|
722
|
+
t[n] instanceof Fe ? await qt(e, t, n) : typeof t[n] == "object" && t[n] !== null && await Ge(e, t[n], [...s, n]);
|
712
723
|
}
|
713
|
-
async function
|
724
|
+
async function qt(e, t, s) {
|
714
725
|
var r, o;
|
715
726
|
let n = t[s];
|
716
727
|
const i = ((r = e.config) == null ? void 0 : r.root) || ((o = e.config) == null ? void 0 : o.root_url);
|
717
728
|
if (!i)
|
718
|
-
throw new Error(
|
729
|
+
throw new Error(Ue);
|
719
730
|
try {
|
720
731
|
let a, l;
|
721
732
|
if (typeof process < "u" && process.versions && process.versions.node) {
|
722
733
|
const g = await import("./__vite-browser-external-DYxpcVy9.js");
|
723
734
|
l = (await import("./__vite-browser-external-DYxpcVy9.js")).resolve(process.cwd(), n.meta.path), a = await g.readFile(l);
|
724
735
|
} else
|
725
|
-
throw new Error(
|
736
|
+
throw new Error(yt);
|
726
737
|
const h = new Blob([a], { type: "application/octet-stream" }), m = await e.upload_files(i, [h]), p = m.files && m.files[0];
|
727
738
|
if (p) {
|
728
739
|
const g = new se({
|
@@ -732,10 +743,10 @@ async function It(e, t, s) {
|
|
732
743
|
t[s] = g;
|
733
744
|
}
|
734
745
|
} catch (a) {
|
735
|
-
console.error(
|
746
|
+
console.error(bt, a);
|
736
747
|
}
|
737
748
|
}
|
738
|
-
async function
|
749
|
+
async function zt(e, t, s) {
|
739
750
|
const n = { "Content-Type": "application/json" };
|
740
751
|
this.options.hf_token && (n.Authorization = `Bearer ${this.options.hf_token}`);
|
741
752
|
try {
|
@@ -756,7 +767,7 @@ async function qt(e, t, s) {
|
|
756
767
|
}
|
757
768
|
return [r, o];
|
758
769
|
}
|
759
|
-
async function
|
770
|
+
async function Bt(e, t = {}) {
|
760
771
|
let s = !1, n = !1;
|
761
772
|
if (!this.config)
|
762
773
|
throw new Error("Could not resolve app config");
|
@@ -785,7 +796,7 @@ async function Y(e, t, s) {
|
|
785
796
|
s({
|
786
797
|
status: "error",
|
787
798
|
load_status: "error",
|
788
|
-
message:
|
799
|
+
message: dt,
|
789
800
|
detail: "NOT_FOUND"
|
790
801
|
});
|
791
802
|
return;
|
@@ -814,7 +825,7 @@ async function Y(e, t, s) {
|
|
814
825
|
load_status: "error",
|
815
826
|
message: "This space has been paused by the author. If you would like to try this demo, consider duplicating the space.",
|
816
827
|
detail: o,
|
817
|
-
discussions_enabled: await
|
828
|
+
discussions_enabled: await Ce(a)
|
818
829
|
});
|
819
830
|
break;
|
820
831
|
case "RUNNING":
|
@@ -852,7 +863,7 @@ async function Y(e, t, s) {
|
|
852
863
|
load_status: "error",
|
853
864
|
message: "This space is experiencing an issue.",
|
854
865
|
detail: o,
|
855
|
-
discussions_enabled: await
|
866
|
+
discussions_enabled: await Ce(a)
|
856
867
|
});
|
857
868
|
break;
|
858
869
|
}
|
@@ -871,8 +882,8 @@ const Me = async (e, t) => {
|
|
871
882
|
}
|
872
883
|
);
|
873
884
|
});
|
874
|
-
},
|
875
|
-
async function
|
885
|
+
}, Ft = /^(?=[^]*\b[dD]iscussions{0,1}\b)(?=[^]*\b[dD]isabled\b)[^]*$/;
|
886
|
+
async function Ce(e) {
|
876
887
|
try {
|
877
888
|
const t = await fetch(
|
878
889
|
`https://huggingface.co/api/spaces/${e}/discussions`,
|
@@ -880,17 +891,17 @@ async function De(e) {
|
|
880
891
|
method: "HEAD"
|
881
892
|
}
|
882
893
|
), s = t.headers.get("x-error-message");
|
883
|
-
return !(!t.ok || s &&
|
894
|
+
return !(!t.ok || s && Ft.test(s));
|
884
895
|
} catch {
|
885
896
|
return !1;
|
886
897
|
}
|
887
898
|
}
|
888
|
-
async function
|
899
|
+
async function Gt(e, t) {
|
889
900
|
const s = {};
|
890
901
|
t && (s.Authorization = `Bearer ${t}`);
|
891
902
|
try {
|
892
903
|
const n = await fetch(
|
893
|
-
`https://huggingface.co/api/spaces/${e}/${
|
904
|
+
`https://huggingface.co/api/spaces/${e}/${rt}`,
|
894
905
|
{ headers: s }
|
895
906
|
);
|
896
907
|
if (n.status !== 200)
|
@@ -901,7 +912,7 @@ async function Bt(e, t) {
|
|
901
912
|
throw new Error(n.message);
|
902
913
|
}
|
903
914
|
}
|
904
|
-
async function
|
915
|
+
async function Mt(e, t, s) {
|
905
916
|
const n = {};
|
906
917
|
s && (n.Authorization = `Bearer ${s}`);
|
907
918
|
const i = {
|
@@ -909,7 +920,7 @@ async function Ft(e, t, s) {
|
|
909
920
|
};
|
910
921
|
try {
|
911
922
|
const r = await fetch(
|
912
|
-
`https://huggingface.co/api/spaces/${e}/${
|
923
|
+
`https://huggingface.co/api/spaces/${e}/${at}`,
|
913
924
|
{
|
914
925
|
method: "POST",
|
915
926
|
headers: { "Content-Type": "application/json", ...n },
|
@@ -940,7 +951,7 @@ const Ae = [
|
|
940
951
|
"h100",
|
941
952
|
"h100x8"
|
942
953
|
];
|
943
|
-
async function
|
954
|
+
async function Jt(e, t) {
|
944
955
|
const { hf_token: s, private: n, hardware: i, timeout: r, auth: o } = t;
|
945
956
|
if (i && !Ae.includes(i))
|
946
957
|
throw new Error(
|
@@ -952,7 +963,7 @@ async function Gt(e, t) {
|
|
952
963
|
);
|
953
964
|
let h = null;
|
954
965
|
if (o) {
|
955
|
-
const _ = await
|
966
|
+
const _ = await qe(
|
956
967
|
a,
|
957
968
|
l,
|
958
969
|
o,
|
@@ -972,7 +983,7 @@ async function Gt(e, t) {
|
|
972
983
|
n && (E.private = !0);
|
973
984
|
let B;
|
974
985
|
try {
|
975
|
-
i || (B = await
|
986
|
+
i || (B = await Gt(e, s));
|
976
987
|
} catch (_) {
|
977
988
|
throw Error(me + _.message);
|
978
989
|
}
|
@@ -990,27 +1001,27 @@ async function Gt(e, t) {
|
|
990
1001
|
if (_.status === 409)
|
991
1002
|
try {
|
992
1003
|
return await ee.connect(`${p}/${g}`, t);
|
993
|
-
} catch (
|
994
|
-
throw console.error("Failed to connect Client instance:",
|
1004
|
+
} catch (C) {
|
1005
|
+
throw console.error("Failed to connect Client instance:", C), C;
|
995
1006
|
}
|
996
1007
|
else if (_.status !== 200)
|
997
1008
|
throw new Error(_.statusText);
|
998
1009
|
const N = await _.json();
|
999
|
-
return await
|
1000
|
-
|
1010
|
+
return await Mt(`${p}/${g}`, r || 300, s), await ee.connect(
|
1011
|
+
Wt(N.url),
|
1001
1012
|
t
|
1002
1013
|
);
|
1003
1014
|
} catch (_) {
|
1004
1015
|
throw new Error(_);
|
1005
1016
|
}
|
1006
1017
|
}
|
1007
|
-
function
|
1018
|
+
function Wt(e) {
|
1008
1019
|
const t = /https:\/\/huggingface.co\/spaces\/([^/]+\/[^/]+)/, s = e.match(t);
|
1009
1020
|
if (s)
|
1010
1021
|
return s[1];
|
1011
1022
|
}
|
1012
1023
|
var I;
|
1013
|
-
class
|
1024
|
+
class Ht extends TransformStream {
|
1014
1025
|
/** Constructs a new instance. */
|
1015
1026
|
constructor(s = { allowCR: !1 }) {
|
1016
1027
|
super({
|
@@ -1040,11 +1051,11 @@ class Jt extends TransformStream {
|
|
1040
1051
|
}
|
1041
1052
|
}
|
1042
1053
|
I = new WeakMap();
|
1043
|
-
function
|
1044
|
-
let t = new TextDecoderStream(), s = new
|
1054
|
+
function Vt(e) {
|
1055
|
+
let t = new TextDecoderStream(), s = new Ht({ allowCR: !0 });
|
1045
1056
|
return e.pipeThrough(t).pipeThrough(s);
|
1046
1057
|
}
|
1047
|
-
function
|
1058
|
+
function Zt(e) {
|
1048
1059
|
let s = /[:]\s*/.exec(e), n = s && s.index;
|
1049
1060
|
if (n)
|
1050
1061
|
return [
|
@@ -1055,10 +1066,10 @@ function Ht(e) {
|
|
1055
1066
|
function Le(e, t, s) {
|
1056
1067
|
e.get(t) || e.set(t, s);
|
1057
1068
|
}
|
1058
|
-
async function*
|
1069
|
+
async function* Kt(e, t) {
|
1059
1070
|
if (!e.body)
|
1060
1071
|
return;
|
1061
|
-
let s =
|
1072
|
+
let s = Vt(e.body), n, i = s.getReader(), r;
|
1062
1073
|
for (; ; ) {
|
1063
1074
|
if (t && t.aborted)
|
1064
1075
|
return i.cancel();
|
@@ -1068,20 +1079,20 @@ async function* Vt(e, t) {
|
|
1068
1079
|
r && (yield r), r = void 0;
|
1069
1080
|
continue;
|
1070
1081
|
}
|
1071
|
-
let [o, a] =
|
1082
|
+
let [o, a] = Zt(n.value) || [];
|
1072
1083
|
o && (o === "data" ? (r || (r = {}), r[o] = r[o] ? r[o] + `
|
1073
1084
|
` + a : a) : o === "event" ? (r || (r = {}), r[o] = a) : o === "id" ? (r || (r = {}), r[o] = +a || a) : o === "retry" && (r || (r = {}), r[o] = +a || void 0));
|
1074
1085
|
}
|
1075
1086
|
}
|
1076
|
-
async function
|
1087
|
+
async function Qt(e, t) {
|
1077
1088
|
let s = new Request(e, t);
|
1078
1089
|
Le(s.headers, "Accept", "text/event-stream"), Le(s.headers, "Content-Type", "application/json");
|
1079
1090
|
let n = await fetch(s);
|
1080
1091
|
if (!n.ok)
|
1081
1092
|
throw n;
|
1082
|
-
return
|
1093
|
+
return Kt(n, s.signal);
|
1083
1094
|
}
|
1084
|
-
async function
|
1095
|
+
async function Xt() {
|
1085
1096
|
let {
|
1086
1097
|
event_callbacks: e,
|
1087
1098
|
unclosed_events: t,
|
@@ -1122,11 +1133,11 @@ async function Kt() {
|
|
1122
1133
|
typeof window < "u" && typeof document < "u" ? setTimeout(E, 0, p) : E(p);
|
1123
1134
|
} else
|
1124
1135
|
s[g] || (s[g] = []), s[g].push(p);
|
1125
|
-
}, a.onerror = async function() {
|
1126
|
-
await Promise.all(
|
1136
|
+
}, a.onerror = async function(m) {
|
1137
|
+
console.error(m), await Promise.all(
|
1127
1138
|
Object.keys(e).map(
|
1128
|
-
(
|
1129
|
-
msg: "
|
1139
|
+
(p) => e[p]({
|
1140
|
+
msg: "broken_connection",
|
1130
1141
|
message: J
|
1131
1142
|
})
|
1132
1143
|
)
|
@@ -1136,20 +1147,20 @@ async function Kt() {
|
|
1136
1147
|
function we(e, t) {
|
1137
1148
|
e && (e.open = !1, t == null || t.abort());
|
1138
1149
|
}
|
1139
|
-
function
|
1150
|
+
function Yt(e, t, s) {
|
1140
1151
|
!e[t] ? (e[t] = [], s.data.forEach((i, r) => {
|
1141
1152
|
e[t][r] = i;
|
1142
1153
|
})) : s.data.forEach((i, r) => {
|
1143
|
-
let o =
|
1154
|
+
let o = es(e[t][r], i);
|
1144
1155
|
e[t][r] = o, s.data[r] = o;
|
1145
1156
|
});
|
1146
1157
|
}
|
1147
|
-
function
|
1158
|
+
function es(e, t) {
|
1148
1159
|
return t.forEach(([s, n, i]) => {
|
1149
|
-
e =
|
1160
|
+
e = ts(e, n, s, i);
|
1150
1161
|
}), e;
|
1151
1162
|
}
|
1152
|
-
function
|
1163
|
+
function ts(e, t, s, n) {
|
1153
1164
|
if (t.length === 0) {
|
1154
1165
|
if (s === "replace")
|
1155
1166
|
return n;
|
@@ -1179,7 +1190,7 @@ function Yt(e, t, s, n) {
|
|
1179
1190
|
}
|
1180
1191
|
return e;
|
1181
1192
|
}
|
1182
|
-
function
|
1193
|
+
function ss(e, t = {}) {
|
1183
1194
|
const s = {
|
1184
1195
|
close: () => {
|
1185
1196
|
console.warn("Method not implemented.");
|
@@ -1203,7 +1214,7 @@ function es(e, t = {}) {
|
|
1203
1214
|
throw new Error("Method not implemented.");
|
1204
1215
|
}
|
1205
1216
|
};
|
1206
|
-
return
|
1217
|
+
return Qt(e, t).then(async (n) => {
|
1207
1218
|
s.readyState = s.OPEN;
|
1208
1219
|
try {
|
1209
1220
|
for await (const i of n)
|
@@ -1216,7 +1227,7 @@ function es(e, t = {}) {
|
|
1216
1227
|
console.error(n), s.onerror && s.onerror(n), s.readyState = s.CLOSED;
|
1217
1228
|
}), s;
|
1218
1229
|
}
|
1219
|
-
function
|
1230
|
+
function ns(e, t = {}, s, n, i) {
|
1220
1231
|
var r;
|
1221
1232
|
try {
|
1222
1233
|
let o = function(w) {
|
@@ -1230,7 +1241,7 @@ function ts(e, t = {}, s, n, i) {
|
|
1230
1241
|
}, l = function(w) {
|
1231
1242
|
le || (K.length > 0 ? K.shift()(w) : ue.push(w));
|
1232
1243
|
}, h = function(w) {
|
1233
|
-
l(
|
1244
|
+
l(is(w)), a();
|
1234
1245
|
}, m = function(w) {
|
1235
1246
|
l({ value: w, done: !1 });
|
1236
1247
|
}, p = function() {
|
@@ -1242,7 +1253,7 @@ function ts(e, t = {}, s, n, i) {
|
|
1242
1253
|
config: c,
|
1243
1254
|
session_hash: _,
|
1244
1255
|
api_info: N,
|
1245
|
-
api_map:
|
1256
|
+
api_map: C,
|
1246
1257
|
stream_status: ne,
|
1247
1258
|
pending_stream_messages: ie,
|
1248
1259
|
pending_diff_streams: oe,
|
@@ -1256,16 +1267,16 @@ function ts(e, t = {}, s, n, i) {
|
|
1256
1267
|
throw new Error("No API found");
|
1257
1268
|
if (!c)
|
1258
1269
|
throw new Error("Could not resolve app config");
|
1259
|
-
let { fn_index: f, endpoint_info: ye, dependency: H } =
|
1270
|
+
let { fn_index: f, endpoint_info: ye, dependency: H } = os(
|
1260
1271
|
N,
|
1261
1272
|
e,
|
1262
|
-
|
1273
|
+
C,
|
1263
1274
|
c
|
1264
|
-
), He =
|
1275
|
+
), He = Dt(t, ye), R, T, j = c.protocol ?? "ws", be = "", Ve = () => be;
|
1265
1276
|
const d = typeof e == "number" ? "/predict" : e;
|
1266
1277
|
let Z, S = null, O = !1, ce = {}, G = typeof window < "u" && typeof document < "u" ? new URLSearchParams(window.location.search).toString() : "";
|
1267
1278
|
const Ze = ((r = F == null ? void 0 : F.events) == null ? void 0 : r.reduce(
|
1268
|
-
(w,
|
1279
|
+
(w, x) => (w[x] = !0, w),
|
1269
1280
|
{}
|
1270
1281
|
)) || {};
|
1271
1282
|
async function Ke() {
|
@@ -1280,21 +1291,21 @@ function ts(e, t = {}, s, n, i) {
|
|
1280
1291
|
endpoint: d,
|
1281
1292
|
fn_index: f
|
1282
1293
|
});
|
1283
|
-
let
|
1284
|
-
|
1294
|
+
let x = {}, M = {};
|
1295
|
+
j === "ws" ? (R && R.readyState === 0 ? R.addEventListener("open", () => {
|
1285
1296
|
R.close();
|
1286
|
-
}) : R.close(),
|
1297
|
+
}) : R.close(), x = { fn_index: f, session_hash: _ }) : (x = { event_id: S }, M = { event_id: S, session_hash: _, fn_index: f });
|
1287
1298
|
try {
|
1288
1299
|
if (!c)
|
1289
1300
|
throw new Error("Could not resolve app config");
|
1290
|
-
"event_id" in M && await E(`${c.root}${W}/${
|
1301
|
+
"event_id" in M && await E(`${c.root}${W}/${pt}`, {
|
1291
1302
|
headers: { "Content-Type": "application/json" },
|
1292
1303
|
method: "POST",
|
1293
1304
|
body: JSON.stringify(M)
|
1294
|
-
}), await E(`${c.root}${W}/${
|
1305
|
+
}), await E(`${c.root}${W}/${ut}`, {
|
1295
1306
|
headers: { "Content-Type": "application/json" },
|
1296
1307
|
method: "POST",
|
1297
|
-
body: JSON.stringify(
|
1308
|
+
body: JSON.stringify(x)
|
1298
1309
|
});
|
1299
1310
|
} catch {
|
1300
1311
|
console.warn(
|
@@ -1303,21 +1314,21 @@ function ts(e, t = {}, s, n, i) {
|
|
1303
1314
|
}
|
1304
1315
|
}
|
1305
1316
|
const Qe = async (w) => {
|
1306
|
-
await this.
|
1317
|
+
await this._resolve_heartbeat(w);
|
1307
1318
|
};
|
1308
1319
|
async function ve(w) {
|
1309
1320
|
if (!c)
|
1310
1321
|
return;
|
1311
|
-
let
|
1322
|
+
let x = w.render_id;
|
1312
1323
|
c.components = [
|
1313
|
-
...c.components.filter((y) => y.props.rendered_in !==
|
1324
|
+
...c.components.filter((y) => y.props.rendered_in !== x),
|
1314
1325
|
...w.components
|
1315
1326
|
], c.dependencies = [
|
1316
|
-
...c.dependencies.filter((y) => y.rendered_in !==
|
1327
|
+
...c.dependencies.filter((y) => y.rendered_in !== x),
|
1317
1328
|
...w.dependencies
|
1318
1329
|
];
|
1319
1330
|
const M = c.components.some((y) => y.type === "state"), Q = c.dependencies.some(
|
1320
|
-
(y) => y.targets.some((
|
1331
|
+
(y) => y.targets.some((U) => U[1] === "unload")
|
1321
1332
|
);
|
1322
1333
|
c.connect_heartbeat = M || Q, await Qe(c), o({
|
1323
1334
|
type: "render",
|
@@ -1340,7 +1351,7 @@ function ts(e, t = {}, s, n, i) {
|
|
1340
1351
|
event_data: s,
|
1341
1352
|
fn_index: f,
|
1342
1353
|
trigger_id: n
|
1343
|
-
},
|
1354
|
+
}, jt(f, c))
|
1344
1355
|
o({
|
1345
1356
|
type: "status",
|
1346
1357
|
endpoint: d,
|
@@ -1354,14 +1365,14 @@ function ts(e, t = {}, s, n, i) {
|
|
1354
1365
|
...Z,
|
1355
1366
|
session_hash: _
|
1356
1367
|
}
|
1357
|
-
).then(([y,
|
1358
|
-
const
|
1359
|
-
|
1368
|
+
).then(([y, U]) => {
|
1369
|
+
const q = y.data;
|
1370
|
+
U == 200 ? (o({
|
1360
1371
|
type: "data",
|
1361
1372
|
endpoint: d,
|
1362
1373
|
fn_index: f,
|
1363
1374
|
data: X(
|
1364
|
-
|
1375
|
+
q,
|
1365
1376
|
H,
|
1366
1377
|
c.components,
|
1367
1378
|
"output",
|
@@ -1398,8 +1409,8 @@ function ts(e, t = {}, s, n, i) {
|
|
1398
1409
|
time: /* @__PURE__ */ new Date()
|
1399
1410
|
});
|
1400
1411
|
});
|
1401
|
-
else if (
|
1402
|
-
const { ws_protocol: y, host:
|
1412
|
+
else if (j == "ws") {
|
1413
|
+
const { ws_protocol: y, host: U } = await te(
|
1403
1414
|
B,
|
1404
1415
|
g
|
1405
1416
|
);
|
@@ -1411,14 +1422,14 @@ function ts(e, t = {}, s, n, i) {
|
|
1411
1422
|
fn_index: f,
|
1412
1423
|
time: /* @__PURE__ */ new Date()
|
1413
1424
|
});
|
1414
|
-
let
|
1415
|
-
`${y}://${
|
1416
|
-
|
1425
|
+
let q = new URL(
|
1426
|
+
`${y}://${vt(
|
1427
|
+
U,
|
1417
1428
|
c.root,
|
1418
1429
|
!0
|
1419
1430
|
)}/queue/join${G ? "?" + G : ""}`
|
1420
1431
|
);
|
1421
|
-
this.jwt &&
|
1432
|
+
this.jwt && q.searchParams.set("__sign", this.jwt), R = new WebSocket(q), R.onclose = (A) => {
|
1422
1433
|
A.wasClean || o({
|
1423
1434
|
type: "status",
|
1424
1435
|
stage: "error",
|
@@ -1430,7 +1441,7 @@ function ts(e, t = {}, s, n, i) {
|
|
1430
1441
|
time: /* @__PURE__ */ new Date()
|
1431
1442
|
});
|
1432
1443
|
}, R.onmessage = function(A) {
|
1433
|
-
const k = JSON.parse(A.data), { type: $, status: v, data:
|
1444
|
+
const k = JSON.parse(A.data), { type: $, status: v, data: D } = de(
|
1434
1445
|
k,
|
1435
1446
|
ce[f]
|
1436
1447
|
);
|
@@ -1448,12 +1459,12 @@ function ts(e, t = {}, s, n, i) {
|
|
1448
1459
|
} else
|
1449
1460
|
$ === "data" ? R.send(JSON.stringify({ ...Z, session_hash: _ })) : $ === "complete" ? O = v : $ === "log" ? o({
|
1450
1461
|
type: "log",
|
1451
|
-
title:
|
1452
|
-
log:
|
1453
|
-
level:
|
1462
|
+
title: D.title,
|
1463
|
+
log: D.log,
|
1464
|
+
level: D.level,
|
1454
1465
|
endpoint: d,
|
1455
|
-
duration:
|
1456
|
-
visible:
|
1466
|
+
duration: D.duration,
|
1467
|
+
visible: D.visible,
|
1457
1468
|
fn_index: f
|
1458
1469
|
}) : $ === "generating" && o({
|
1459
1470
|
type: "status",
|
@@ -1464,11 +1475,11 @@ function ts(e, t = {}, s, n, i) {
|
|
1464
1475
|
endpoint: d,
|
1465
1476
|
fn_index: f
|
1466
1477
|
});
|
1467
|
-
|
1478
|
+
D && (o({
|
1468
1479
|
type: "data",
|
1469
1480
|
time: /* @__PURE__ */ new Date(),
|
1470
1481
|
data: X(
|
1471
|
-
|
1482
|
+
D.data,
|
1472
1483
|
H,
|
1473
1484
|
c.components,
|
1474
1485
|
"output",
|
@@ -1491,7 +1502,7 @@ function ts(e, t = {}, s, n, i) {
|
|
1491
1502
|
"open",
|
1492
1503
|
() => R.send(JSON.stringify({ hash: _ }))
|
1493
1504
|
);
|
1494
|
-
} else if (
|
1505
|
+
} else if (j == "sse") {
|
1495
1506
|
o({
|
1496
1507
|
type: "status",
|
1497
1508
|
stage: "pending",
|
@@ -1511,9 +1522,9 @@ function ts(e, t = {}, s, n, i) {
|
|
1511
1522
|
return Promise.reject(
|
1512
1523
|
new Error("Cannot connect to SSE endpoint: " + y.toString())
|
1513
1524
|
);
|
1514
|
-
T.onmessage = async function(
|
1515
|
-
const
|
1516
|
-
|
1525
|
+
T.onmessage = async function(U) {
|
1526
|
+
const q = JSON.parse(U.data), { type: A, status: k, data: $ } = de(
|
1527
|
+
q,
|
1517
1528
|
ce[f]
|
1518
1529
|
);
|
1519
1530
|
if (A === "update" && k && !O)
|
@@ -1525,7 +1536,7 @@ function ts(e, t = {}, s, n, i) {
|
|
1525
1536
|
...k
|
1526
1537
|
}), k.stage === "error" && (T == null || T.close(), a());
|
1527
1538
|
else if (A === "data") {
|
1528
|
-
let [v,
|
1539
|
+
let [v, D] = await ae(
|
1529
1540
|
`${c.root}${W}/queue/data`,
|
1530
1541
|
{
|
1531
1542
|
...Z,
|
@@ -1533,7 +1544,7 @@ function ts(e, t = {}, s, n, i) {
|
|
1533
1544
|
event_id: S
|
1534
1545
|
}
|
1535
1546
|
);
|
1536
|
-
|
1547
|
+
D !== 200 && (o({
|
1537
1548
|
type: "status",
|
1538
1549
|
stage: "error",
|
1539
1550
|
message: J,
|
@@ -1585,7 +1596,7 @@ function ts(e, t = {}, s, n, i) {
|
|
1585
1596
|
fn_index: f
|
1586
1597
|
}), T == null || T.close(), a()));
|
1587
1598
|
};
|
1588
|
-
} else if (
|
1599
|
+
} else if (j == "sse_v1" || j == "sse_v2" || j == "sse_v2.1" || j == "sse_v3") {
|
1589
1600
|
o({
|
1590
1601
|
type: "status",
|
1591
1602
|
stage: "pending",
|
@@ -1596,16 +1607,16 @@ function ts(e, t = {}, s, n, i) {
|
|
1596
1607
|
});
|
1597
1608
|
let y = "";
|
1598
1609
|
typeof window < "u" && typeof document < "u" && (y = (Q = window == null ? void 0 : window.location) == null ? void 0 : Q.hostname);
|
1599
|
-
const
|
1600
|
-
(typeof window < "u" && typeof document < "u" && window.parent != window && window.supports_zerogpu_headers ?
|
1601
|
-
`${c.root}${W}/${
|
1610
|
+
const q = y.includes(".dev.") ? `https://moon-${y.split(".")[1]}.dev.spaces.huggingface.tech` : "https://huggingface.co";
|
1611
|
+
(typeof window < "u" && typeof document < "u" && window.parent != window && window.supports_zerogpu_headers ? xt("zerogpu-headers", q) : Promise.resolve(null)).then((v) => ae(
|
1612
|
+
`${c.root}${W}/${nt}?${G}`,
|
1602
1613
|
{
|
1603
1614
|
...Z,
|
1604
1615
|
session_hash: _
|
1605
1616
|
},
|
1606
1617
|
v
|
1607
|
-
)).then(async ([v,
|
1608
|
-
if (
|
1618
|
+
)).then(async ([v, D]) => {
|
1619
|
+
if (D === 503)
|
1609
1620
|
o({
|
1610
1621
|
type: "status",
|
1611
1622
|
stage: "error",
|
@@ -1615,10 +1626,11 @@ function ts(e, t = {}, s, n, i) {
|
|
1615
1626
|
fn_index: f,
|
1616
1627
|
time: /* @__PURE__ */ new Date()
|
1617
1628
|
});
|
1618
|
-
else if (
|
1629
|
+
else if (D !== 200)
|
1619
1630
|
o({
|
1620
1631
|
type: "status",
|
1621
1632
|
stage: "error",
|
1633
|
+
broken: !0,
|
1622
1634
|
message: J,
|
1623
1635
|
queue: !0,
|
1624
1636
|
endpoint: d,
|
@@ -1629,13 +1641,13 @@ function ts(e, t = {}, s, n, i) {
|
|
1629
1641
|
S = v.event_id, be = S;
|
1630
1642
|
let Se = async function(pe) {
|
1631
1643
|
try {
|
1632
|
-
const { type:
|
1644
|
+
const { type: L, status: b, data: P, original_msg: Xe } = de(
|
1633
1645
|
pe,
|
1634
1646
|
ce[f]
|
1635
1647
|
);
|
1636
|
-
if (
|
1648
|
+
if (L == "heartbeat")
|
1637
1649
|
return;
|
1638
|
-
if (
|
1650
|
+
if (L === "update" && b && !O)
|
1639
1651
|
o({
|
1640
1652
|
type: "status",
|
1641
1653
|
endpoint: d,
|
@@ -1644,32 +1656,36 @@ function ts(e, t = {}, s, n, i) {
|
|
1644
1656
|
original_msg: Xe,
|
1645
1657
|
...b
|
1646
1658
|
});
|
1647
|
-
else if (
|
1659
|
+
else if (L === "complete")
|
1648
1660
|
O = b;
|
1649
|
-
else if (
|
1650
|
-
console.error("Unexpected error", b == null ? void 0 : b.message)
|
1661
|
+
else if (L == "unexpected_error" || L == "broken_connection") {
|
1662
|
+
console.error("Unexpected error", b == null ? void 0 : b.message);
|
1663
|
+
const Ye = L === "broken_connection";
|
1664
|
+
o({
|
1651
1665
|
type: "status",
|
1652
1666
|
stage: "error",
|
1653
1667
|
message: (b == null ? void 0 : b.message) || "An Unexpected Error Occurred!",
|
1654
1668
|
queue: !0,
|
1655
1669
|
endpoint: d,
|
1670
|
+
broken: Ye,
|
1671
|
+
session_not_found: b == null ? void 0 : b.session_not_found,
|
1656
1672
|
fn_index: f,
|
1657
1673
|
time: /* @__PURE__ */ new Date()
|
1658
1674
|
});
|
1659
|
-
else if (
|
1675
|
+
} else if (L === "log") {
|
1660
1676
|
o({
|
1661
1677
|
type: "log",
|
1662
|
-
title:
|
1663
|
-
log:
|
1664
|
-
level:
|
1678
|
+
title: P.title,
|
1679
|
+
log: P.log,
|
1680
|
+
level: P.level,
|
1665
1681
|
endpoint: d,
|
1666
|
-
duration:
|
1667
|
-
visible:
|
1682
|
+
duration: P.duration,
|
1683
|
+
visible: P.visible,
|
1668
1684
|
fn_index: f
|
1669
1685
|
});
|
1670
1686
|
return;
|
1671
1687
|
} else
|
1672
|
-
(
|
1688
|
+
(L === "generating" || L === "streaming") && (o({
|
1673
1689
|
type: "status",
|
1674
1690
|
time: /* @__PURE__ */ new Date(),
|
1675
1691
|
...b,
|
@@ -1677,12 +1693,12 @@ function ts(e, t = {}, s, n, i) {
|
|
1677
1693
|
queue: !0,
|
1678
1694
|
endpoint: d,
|
1679
1695
|
fn_index: f
|
1680
|
-
}),
|
1681
|
-
|
1696
|
+
}), P && H.connection !== "stream" && ["sse_v2", "sse_v2.1", "sse_v3"].includes(j) && Yt(oe, S, P));
|
1697
|
+
P && (o({
|
1682
1698
|
type: "data",
|
1683
1699
|
time: /* @__PURE__ */ new Date(),
|
1684
1700
|
data: X(
|
1685
|
-
|
1701
|
+
P.data,
|
1686
1702
|
H,
|
1687
1703
|
c.components,
|
1688
1704
|
"output",
|
@@ -1690,7 +1706,7 @@ function ts(e, t = {}, s, n, i) {
|
|
1690
1706
|
),
|
1691
1707
|
endpoint: d,
|
1692
1708
|
fn_index: f
|
1693
|
-
}),
|
1709
|
+
}), P.render_config && await ve(P.render_config), O && (o({
|
1694
1710
|
type: "status",
|
1695
1711
|
time: /* @__PURE__ */ new Date(),
|
1696
1712
|
...O,
|
@@ -1699,8 +1715,8 @@ function ts(e, t = {}, s, n, i) {
|
|
1699
1715
|
endpoint: d,
|
1700
1716
|
fn_index: f
|
1701
1717
|
}), a())), ((b == null ? void 0 : b.stage) === "complete" || (b == null ? void 0 : b.stage) === "error") && (re[S] && delete re[S], S in oe && delete oe[S]);
|
1702
|
-
} catch (
|
1703
|
-
console.error("Unexpected client exception",
|
1718
|
+
} catch (L) {
|
1719
|
+
console.error("Unexpected client exception", L), o({
|
1704
1720
|
type: "status",
|
1705
1721
|
stage: "error",
|
1706
1722
|
message: "An Unexpected Error Occurred!",
|
@@ -1708,7 +1724,7 @@ function ts(e, t = {}, s, n, i) {
|
|
1708
1724
|
endpoint: d,
|
1709
1725
|
fn_index: f,
|
1710
1726
|
time: /* @__PURE__ */ new Date()
|
1711
|
-
}), ["sse_v2", "sse_v2.1", "sse_v3"].includes(
|
1727
|
+
}), ["sse_v2", "sse_v2.1", "sse_v3"].includes(j) && (we(ne, We.abort_controller), ne.open = !1, a());
|
1712
1728
|
}
|
1713
1729
|
};
|
1714
1730
|
S in ie && (ie[S].forEach(
|
@@ -1733,12 +1749,12 @@ function ts(e, t = {}, s, n, i) {
|
|
1733
1749
|
throw console.error("Submit function encountered an error:", o), o;
|
1734
1750
|
}
|
1735
1751
|
}
|
1736
|
-
function
|
1752
|
+
function is(e) {
|
1737
1753
|
return {
|
1738
1754
|
then: (t, s) => s(e)
|
1739
1755
|
};
|
1740
1756
|
}
|
1741
|
-
function
|
1757
|
+
function os(e, t, s, n) {
|
1742
1758
|
let i, r, o;
|
1743
1759
|
if (typeof t == "number")
|
1744
1760
|
i = t, r = e.unnamed_endpoints[i], o = n.dependencies.find((a) => a.id == t);
|
@@ -1790,7 +1806,7 @@ class ee {
|
|
1790
1806
|
u(this, "resolve_config");
|
1791
1807
|
u(this, "resolve_cookies");
|
1792
1808
|
var n;
|
1793
|
-
this.app_reference = t, this.deep_link = ((n = s.query_params) == null ? void 0 : n.deep_link) || null, s.events || (s.events = ["data"]), this.options = s, this.current_payload = {}, this.view_api =
|
1809
|
+
this.app_reference = t, this.deep_link = ((n = s.query_params) == null ? void 0 : n.deep_link) || null, s.events || (s.events = ["data"]), this.options = s, this.current_payload = {}, this.view_api = Ct.bind(this), this.upload_files = At.bind(this), this.handle_blob = It.bind(this), this.post_data = zt.bind(this), this.submit = ns.bind(this), this.predict = Bt.bind(this), this.open_stream = Xt.bind(this), this.resolve_config = St.bind(this), this.resolve_cookies = kt.bind(this), this.upload = Lt.bind(this), this.fetch = this.fetch.bind(this), this.handle_space_success = this.handle_space_success.bind(this), this.stream = this.stream.bind(this);
|
1794
1810
|
}
|
1795
1811
|
get_url_config(t = null) {
|
1796
1812
|
if (!this.config)
|
@@ -1828,7 +1844,7 @@ class ee {
|
|
1828
1844
|
if (this && this.cookies && s.append("Cookie", this.cookies), this && this.options.headers)
|
1829
1845
|
for (const n in this.options.headers)
|
1830
1846
|
s.append(n, this.options.headers[n]);
|
1831
|
-
return this && this.options.hf_token && s.append("Authorization", `Bearer ${this.options.hf_token}`), this.abort_controller = new AbortController(), this.stream_instance =
|
1847
|
+
return this && this.options.hf_token && s.append("Authorization", `Bearer ${this.options.hf_token}`), this.abort_controller = new AbortController(), this.stream_instance = ss(t.toString(), {
|
1832
1848
|
credentials: "include",
|
1833
1849
|
headers: s,
|
1834
1850
|
signal: this.abort_controller.signal
|
@@ -1837,17 +1853,17 @@ class ee {
|
|
1837
1853
|
async init() {
|
1838
1854
|
var t;
|
1839
1855
|
this.options.auth && await this.resolve_cookies(), await this._resolve_config().then(
|
1840
|
-
({ config: s }) => this.
|
1841
|
-
), this.api_info = await this.view_api(), this.api_map =
|
1856
|
+
({ config: s }) => this._resolve_heartbeat(s)
|
1857
|
+
), this.api_info = await this.view_api(), this.api_map = Et(((t = this.config) == null ? void 0 : t.dependencies) || []);
|
1842
1858
|
}
|
1843
|
-
async
|
1859
|
+
async _resolve_heartbeat(t) {
|
1844
1860
|
if (t && (this.config = t, this.api_prefix = t.api_prefix || "", this.config && this.config.connect_heartbeat && this.config.space_id && this.options.hf_token && (this.jwt = await Te(
|
1845
1861
|
this.config.space_id,
|
1846
1862
|
this.options.hf_token,
|
1847
1863
|
this.cookies
|
1848
1864
|
))), t.space_id && this.options.hf_token && (this.jwt = await Te(t.space_id, this.options.hf_token)), this.config && this.config.connect_heartbeat) {
|
1849
1865
|
const s = new URL(
|
1850
|
-
`${this.config.root}${this.api_prefix}/${
|
1866
|
+
`${this.config.root}${this.api_prefix}/${ct}/${this.session_hash}`
|
1851
1867
|
);
|
1852
1868
|
this.jwt && s.searchParams.set("__sign", this.jwt), this.heartbeat_event || (this.heartbeat_event = this.stream(s));
|
1853
1869
|
}
|
@@ -1858,6 +1874,21 @@ class ee {
|
|
1858
1874
|
const n = new this(t, s);
|
1859
1875
|
return s.session_hash && (n.session_hash = s.session_hash), await n.init(), n;
|
1860
1876
|
}
|
1877
|
+
async reconnect() {
|
1878
|
+
const t = new URL(
|
1879
|
+
`${this.config.root}${this.api_prefix}/${ft}`
|
1880
|
+
);
|
1881
|
+
let s;
|
1882
|
+
try {
|
1883
|
+
const n = await this.fetch(t);
|
1884
|
+
if (!n.ok)
|
1885
|
+
throw new Error();
|
1886
|
+
s = (await n.json()).app_id;
|
1887
|
+
} catch {
|
1888
|
+
return "broken";
|
1889
|
+
}
|
1890
|
+
return s !== this.config.app_id ? "changed" : "connected";
|
1891
|
+
}
|
1861
1892
|
close() {
|
1862
1893
|
this.closed = !0, we(this.stream_status, this.abort_controller);
|
1863
1894
|
}
|
@@ -1867,7 +1898,7 @@ class ee {
|
|
1867
1898
|
static async duplicate(t, s = {
|
1868
1899
|
events: ["data"]
|
1869
1900
|
}) {
|
1870
|
-
return
|
1901
|
+
return Jt(t, s);
|
1871
1902
|
}
|
1872
1903
|
async _resolve_config() {
|
1873
1904
|
const { http_protocol: t, host: s, space_id: n } = await te(
|
@@ -1903,7 +1934,7 @@ class ee {
|
|
1903
1934
|
try {
|
1904
1935
|
this.api_info = await this.view_api();
|
1905
1936
|
} catch (s) {
|
1906
|
-
console.error(
|
1937
|
+
console.error(_t + s.message);
|
1907
1938
|
}
|
1908
1939
|
return this.prepare_return_obj();
|
1909
1940
|
}
|
@@ -1952,7 +1983,7 @@ class ee {
|
|
1952
1983
|
r && (i.Authorization = `Bearer ${r}`);
|
1953
1984
|
try {
|
1954
1985
|
const p = await this.fetch(
|
1955
|
-
`${a}${this.api_prefix}/${
|
1986
|
+
`${a}${this.api_prefix}/${lt}/`,
|
1956
1987
|
{
|
1957
1988
|
method: "POST",
|
1958
1989
|
body: h,
|
@@ -2015,24 +2046,24 @@ class ee {
|
|
2015
2046
|
}
|
2016
2047
|
}
|
2017
2048
|
}
|
2018
|
-
async function
|
2049
|
+
async function ls(e, t = {
|
2019
2050
|
events: ["data"]
|
2020
2051
|
}) {
|
2021
2052
|
return await ee.connect(e, t);
|
2022
2053
|
}
|
2023
|
-
async function
|
2054
|
+
async function us(e, t) {
|
2024
2055
|
return await ee.duplicate(e, t);
|
2025
2056
|
}
|
2026
2057
|
export {
|
2027
2058
|
ee as Client,
|
2028
2059
|
se as FileData,
|
2029
|
-
|
2030
|
-
|
2031
|
-
|
2032
|
-
|
2033
|
-
|
2034
|
-
|
2035
|
-
|
2036
|
-
|
2037
|
-
|
2060
|
+
wt as MISSING_CREDENTIALS_MSG,
|
2061
|
+
ls as client,
|
2062
|
+
us as duplicate,
|
2063
|
+
cs as handle_file,
|
2064
|
+
Bt as predict,
|
2065
|
+
as as prepare_files,
|
2066
|
+
ns as submit,
|
2067
|
+
Lt as upload,
|
2068
|
+
At as upload_files
|
2038
2069
|
};
|