@gradio/client 1.17.1 → 1.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/browser.js +331 -334
- package/dist/index.js +37 -53
- package/dist/types.d.ts +5 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/submit.d.ts.map +1 -1
- package/dist/{wrapper-CviSselG.js → wrapper-CpGUsf_3.js} +172 -795
- package/package.json +1 -1
- package/src/types.ts +6 -1
- package/src/utils/submit.ts +14 -2
package/dist/browser.js
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
if (!t.has(e))
|
|
5
|
-
throw TypeError("Cannot " + s);
|
|
1
|
+
var tt = Object.defineProperty;
|
|
2
|
+
var Se = (e) => {
|
|
3
|
+
throw TypeError(e);
|
|
6
4
|
};
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
t instanceof WeakSet ? t.add(e) : t.set(e, s);
|
|
11
|
-
}, ke = (e, t, s, n) => (Se(e, t, "write to private field"), n ? n.call(e, s) : t.set(e, s), s);
|
|
5
|
+
var st = (e, t, s) => t in e ? tt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
|
|
6
|
+
var u = (e, t, s) => st(e, typeof t != "symbol" ? t + "" : t, s), $e = (e, t, s) => t.has(e) || Se("Cannot " + s);
|
|
7
|
+
var W = (e, t, s) => ($e(e, t, "read from private field"), s ? s.call(e) : t.get(e)), ke = (e, t, s) => t.has(e) ? Se("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, s), Re = (e, t, s, n) => ($e(e, t, "write to private field"), n ? n.call(e, s) : t.set(e, s), s);
|
|
12
8
|
var pe = new Intl.Collator(0, { numeric: 1 }).compare;
|
|
13
|
-
function
|
|
9
|
+
function Pe(e, t, s) {
|
|
14
10
|
return e = e.split("."), t = t.split("."), pe(e[0], t[0]) || pe(e[1], t[1]) || (t[2] = t.slice(2).join("."), s = /[.-]/.test(e[2] = e.slice(2).join(".")), s == /[.-]/.test(t[2]) ? pe(e[2], t[2]) : s ? -1 : 1);
|
|
15
11
|
}
|
|
16
|
-
const
|
|
17
|
-
function
|
|
12
|
+
const nt = "host", je = "queue/data", it = "queue/join", Oe = "upload", ot = "login", Ne = "config", rt = "info", at = "runtime", ct = "sleeptime", lt = "heartbeat", ut = "component_server", pt = "reset", ft = "cancel", ht = "app_id", dt = "https://gradio-space-api-fetcher-v2.hf.space/api", xe = "This application is currently busy. Please try again. ", H = "Connection errored out. ", z = "Could not resolve app config. ", _t = "Could not get space status. ", mt = "Could not get API info. ", _e = "Space metadata could not be loaded. ", gt = "Invalid URL. A full URL path is required.", wt = "Not authorized to access this space. ", Ie = "Invalid credentials. Could not login. ", yt = "Login credentials are required to access this space.", bt = "File system access is only available in Node.js environments", Ue = "Root URL not found in client config", vt = "Error uploading file";
|
|
13
|
+
function Et(e, t, s) {
|
|
18
14
|
return t.startsWith("http://") || t.startsWith("https://") ? s ? e : t : e + t;
|
|
19
15
|
}
|
|
20
|
-
async function
|
|
16
|
+
async function Te(e, t, s) {
|
|
21
17
|
try {
|
|
22
18
|
return (await (await fetch(`https://huggingface.co/api/spaces/${e}/jwt`, {
|
|
23
19
|
headers: {
|
|
@@ -29,53 +25,53 @@ async function Ne(e, t, s) {
|
|
|
29
25
|
return !1;
|
|
30
26
|
}
|
|
31
27
|
}
|
|
32
|
-
function
|
|
28
|
+
function St(e) {
|
|
33
29
|
let t = {};
|
|
34
30
|
return e.forEach(({ api_name: s, id: n }) => {
|
|
35
31
|
s && (t[s] = n);
|
|
36
32
|
}), t;
|
|
37
33
|
}
|
|
38
|
-
async function
|
|
34
|
+
async function $t(e) {
|
|
39
35
|
const t = this.options.hf_token ? { Authorization: `Bearer ${this.options.hf_token}` } : {};
|
|
40
36
|
if (t["Content-Type"] = "application/json", typeof window < "u" && window.gradio_config && location.origin !== "http://localhost:9876" && !window.gradio_config.dev_mode)
|
|
41
37
|
return window.gradio_config.current_page && (e = e.substring(0, e.lastIndexOf("/"))), window.gradio_config.root = e, { ...window.gradio_config };
|
|
42
38
|
if (e) {
|
|
43
|
-
let s =
|
|
39
|
+
let s = Be(
|
|
44
40
|
e,
|
|
45
|
-
this.deep_link ?
|
|
41
|
+
this.deep_link ? Ne + "?deep_link=" + this.deep_link : Ne
|
|
46
42
|
);
|
|
47
43
|
const n = await this.fetch(s, {
|
|
48
44
|
headers: t,
|
|
49
45
|
credentials: "include"
|
|
50
46
|
});
|
|
51
|
-
return
|
|
47
|
+
return kt(n, e, !!this.options.auth);
|
|
52
48
|
}
|
|
53
49
|
throw new Error(z);
|
|
54
50
|
}
|
|
55
|
-
async function
|
|
51
|
+
async function kt(e, t, s) {
|
|
56
52
|
var n, i;
|
|
57
53
|
if ((e == null ? void 0 : e.status) === 401 && !s) {
|
|
58
54
|
const r = await e.json(), o = (n = r == null ? void 0 : r.detail) == null ? void 0 : n.auth_message;
|
|
59
|
-
throw new Error(o ||
|
|
55
|
+
throw new Error(o || yt);
|
|
60
56
|
} else if ((e == null ? void 0 : e.status) === 401 && s)
|
|
61
|
-
throw new Error(
|
|
57
|
+
throw new Error(Ie);
|
|
62
58
|
if ((e == null ? void 0 : e.status) === 200) {
|
|
63
59
|
let r = await e.json();
|
|
64
60
|
return r.root = t, (i = r.dependencies) == null || i.forEach((o, a) => {
|
|
65
61
|
o.id === void 0 && (o.id = a);
|
|
66
62
|
}), r;
|
|
67
63
|
} else if ((e == null ? void 0 : e.status) === 401)
|
|
68
|
-
throw new Error(
|
|
64
|
+
throw new Error(wt);
|
|
69
65
|
throw new Error(z);
|
|
70
66
|
}
|
|
71
|
-
async function
|
|
67
|
+
async function Rt() {
|
|
72
68
|
const { http_protocol: e, host: t } = await te(
|
|
73
69
|
this.app_reference,
|
|
74
70
|
this.options.hf_token
|
|
75
71
|
);
|
|
76
72
|
try {
|
|
77
73
|
if (this.options.auth) {
|
|
78
|
-
const s = await
|
|
74
|
+
const s = await qe(
|
|
79
75
|
e,
|
|
80
76
|
t,
|
|
81
77
|
this.options.auth,
|
|
@@ -88,12 +84,12 @@ async function kt() {
|
|
|
88
84
|
throw Error(s.message);
|
|
89
85
|
}
|
|
90
86
|
}
|
|
91
|
-
async function
|
|
87
|
+
async function qe(e, t, s, n, i) {
|
|
92
88
|
const r = new FormData();
|
|
93
89
|
r.append("username", s == null ? void 0 : s[0]), r.append("password", s == null ? void 0 : s[1]);
|
|
94
90
|
let o = {};
|
|
95
91
|
i && (o.Authorization = `Bearer ${i}`);
|
|
96
|
-
const a = await n(`${e}//${t}/${
|
|
92
|
+
const a = await n(`${e}//${t}/${ot}`, {
|
|
97
93
|
headers: o,
|
|
98
94
|
method: "POST",
|
|
99
95
|
body: r,
|
|
@@ -101,7 +97,7 @@ async function Ue(e, t, s, n, i) {
|
|
|
101
97
|
});
|
|
102
98
|
if (a.status === 200)
|
|
103
99
|
return a.headers.get("set-cookie");
|
|
104
|
-
throw a.status === 401 ? new Error(
|
|
100
|
+
throw a.status === 401 ? new Error(Ie) : new Error(_e);
|
|
105
101
|
}
|
|
106
102
|
function fe(e) {
|
|
107
103
|
if (e.startsWith("http")) {
|
|
@@ -124,13 +120,13 @@ function fe(e) {
|
|
|
124
120
|
host: new URL(e).host
|
|
125
121
|
};
|
|
126
122
|
}
|
|
127
|
-
const
|
|
123
|
+
const ze = (e) => {
|
|
128
124
|
let t = [];
|
|
129
125
|
return e.split(/,(?=\s*[^\s=;]+=[^\s=;]+)/).forEach((n) => {
|
|
130
126
|
const [i, r] = n.split(";")[0].split("=");
|
|
131
127
|
i && r && t.push(`${i.trim()}=${r.trim()}`);
|
|
132
128
|
}), t;
|
|
133
|
-
}, me = /^[a-zA-Z0-9_\-\.]+\/[a-zA-Z0-9_\-\.]+$/,
|
|
129
|
+
}, me = /^[a-zA-Z0-9_\-\.]+\/[a-zA-Z0-9_\-\.]+$/, Ot = /.*hf\.space\/{0,1}.*$/;
|
|
134
130
|
async function te(e, t) {
|
|
135
131
|
const s = {};
|
|
136
132
|
t && (s.Authorization = `Bearer ${t}`);
|
|
@@ -138,7 +134,7 @@ async function te(e, t) {
|
|
|
138
134
|
if (me.test(n))
|
|
139
135
|
try {
|
|
140
136
|
const r = (await (await fetch(
|
|
141
|
-
`https://huggingface.co/api/spaces/${n}/${
|
|
137
|
+
`https://huggingface.co/api/spaces/${n}/${nt}`,
|
|
142
138
|
{ headers: s }
|
|
143
139
|
)).json()).host;
|
|
144
140
|
return {
|
|
@@ -148,7 +144,7 @@ async function te(e, t) {
|
|
|
148
144
|
} catch {
|
|
149
145
|
throw new Error(_e);
|
|
150
146
|
}
|
|
151
|
-
if (
|
|
147
|
+
if (Ot.test(n)) {
|
|
152
148
|
const { ws_protocol: i, http_protocol: r, host: o } = fe(n);
|
|
153
149
|
return {
|
|
154
150
|
space_id: o.split("/")[0].replace(".hf.space", ""),
|
|
@@ -162,14 +158,14 @@ async function te(e, t) {
|
|
|
162
158
|
...fe(n)
|
|
163
159
|
};
|
|
164
160
|
}
|
|
165
|
-
const
|
|
161
|
+
const Be = (...e) => {
|
|
166
162
|
try {
|
|
167
163
|
return e.reduce((t, s) => (t = t.replace(/\/+$/, ""), s = s.replace(/^\/+/, ""), new URL(s, t + "/").toString()));
|
|
168
164
|
} catch {
|
|
169
|
-
throw new Error(
|
|
165
|
+
throw new Error(gt);
|
|
170
166
|
}
|
|
171
167
|
};
|
|
172
|
-
function
|
|
168
|
+
function Nt(e, t, s) {
|
|
173
169
|
const n = {
|
|
174
170
|
named_endpoints: {},
|
|
175
171
|
unnamed_endpoints: {}
|
|
@@ -182,16 +178,16 @@ function Ot(e, t, s) {
|
|
|
182
178
|
(c) => c.api_name === r || c.api_name === r.replace("/", "")
|
|
183
179
|
)) == null ? void 0 : p.id) || s[r.replace("/", "")] || -1, h = l !== -1 ? (g = t.dependencies.find((c) => c.id == l)) == null ? void 0 : g.types : { generator: !1, cancel: !1 };
|
|
184
180
|
if (l !== -1 && ((B = (E = t.dependencies.find((c) => c.id == l)) == null ? void 0 : E.inputs) == null ? void 0 : B.length) !== o.length) {
|
|
185
|
-
const c = t.dependencies.find((
|
|
186
|
-
(
|
|
187
|
-
var
|
|
188
|
-
return (
|
|
181
|
+
const c = t.dependencies.find((_) => _.id == l).inputs.map(
|
|
182
|
+
(_) => {
|
|
183
|
+
var N;
|
|
184
|
+
return (N = t.components.find((C) => C.id === _)) == null ? void 0 : N.type;
|
|
189
185
|
}
|
|
190
186
|
);
|
|
191
187
|
try {
|
|
192
|
-
c.forEach((
|
|
193
|
-
if (
|
|
194
|
-
const
|
|
188
|
+
c.forEach((_, N) => {
|
|
189
|
+
if (_ === "state") {
|
|
190
|
+
const C = {
|
|
195
191
|
component: "state",
|
|
196
192
|
example: null,
|
|
197
193
|
parameter_default: null,
|
|
@@ -199,17 +195,17 @@ function Ot(e, t, s) {
|
|
|
199
195
|
parameter_name: null,
|
|
200
196
|
hidden: !0
|
|
201
197
|
};
|
|
202
|
-
o.splice(
|
|
198
|
+
o.splice(N, 0, C);
|
|
203
199
|
}
|
|
204
200
|
});
|
|
205
|
-
} catch (
|
|
206
|
-
console.error(
|
|
201
|
+
} catch (_) {
|
|
202
|
+
console.error(_);
|
|
207
203
|
}
|
|
208
204
|
}
|
|
209
|
-
const m = (c,
|
|
205
|
+
const m = (c, _, N, C) => ({
|
|
210
206
|
...c,
|
|
211
|
-
description:
|
|
212
|
-
type:
|
|
207
|
+
description: Dt(c == null ? void 0 : c.type, N),
|
|
208
|
+
type: Tt(c == null ? void 0 : c.type, _, N, C) || ""
|
|
213
209
|
});
|
|
214
210
|
n[i][r] = {
|
|
215
211
|
parameters: o.map(
|
|
@@ -224,9 +220,8 @@ function Ot(e, t, s) {
|
|
|
224
220
|
));
|
|
225
221
|
}), n;
|
|
226
222
|
}
|
|
227
|
-
function
|
|
228
|
-
if (t === "Api")
|
|
229
|
-
return e.type;
|
|
223
|
+
function Tt(e, t, s, n) {
|
|
224
|
+
if (t === "Api") return e.type;
|
|
230
225
|
switch (e == null ? void 0 : e.type) {
|
|
231
226
|
case "string":
|
|
232
227
|
return "string";
|
|
@@ -246,7 +241,7 @@ function Nt(e, t, s, n) {
|
|
|
246
241
|
if (s === "GallerySerializable")
|
|
247
242
|
return n === "parameter" ? "[(Blob | File | Buffer), (string | null)][]" : "[{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}, (string | null))][]";
|
|
248
243
|
}
|
|
249
|
-
function
|
|
244
|
+
function Dt(e, t) {
|
|
250
245
|
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
246
|
}
|
|
252
247
|
function he(e, t) {
|
|
@@ -260,7 +255,7 @@ function he(e, t) {
|
|
|
260
255
|
type: "update",
|
|
261
256
|
status: {
|
|
262
257
|
queue: !0,
|
|
263
|
-
message:
|
|
258
|
+
message: xe,
|
|
264
259
|
stage: "error",
|
|
265
260
|
code: e.code,
|
|
266
261
|
success: e.success
|
|
@@ -413,9 +408,8 @@ const Ct = (e = [], t) => {
|
|
|
413
408
|
);
|
|
414
409
|
}), n;
|
|
415
410
|
};
|
|
416
|
-
async function
|
|
417
|
-
if (this.api_info)
|
|
418
|
-
return this.api_info;
|
|
411
|
+
async function At() {
|
|
412
|
+
if (this.api_info) return this.api_info;
|
|
419
413
|
const { hf_token: e } = this.options, { config: t } = this, s = { "Content-Type": "application/json" };
|
|
420
414
|
if (e && (s.Authorization = `Bearer ${e}`), !!t)
|
|
421
415
|
try {
|
|
@@ -423,8 +417,8 @@ async function Dt() {
|
|
|
423
417
|
if (typeof window < "u" && window.gradio_api_info)
|
|
424
418
|
i = window.gradio_api_info;
|
|
425
419
|
else {
|
|
426
|
-
if (
|
|
427
|
-
n = await this.fetch(
|
|
420
|
+
if (Pe((t == null ? void 0 : t.version) || "2.0.0", "3.30") < 0)
|
|
421
|
+
n = await this.fetch(dt, {
|
|
428
422
|
method: "POST",
|
|
429
423
|
body: JSON.stringify({
|
|
430
424
|
serialize: !1,
|
|
@@ -434,22 +428,22 @@ async function Dt() {
|
|
|
434
428
|
credentials: "include"
|
|
435
429
|
});
|
|
436
430
|
else {
|
|
437
|
-
const r =
|
|
431
|
+
const r = Be(t.root, this.api_prefix, rt);
|
|
438
432
|
n = await this.fetch(r, {
|
|
439
433
|
headers: s,
|
|
440
434
|
credentials: "include"
|
|
441
435
|
});
|
|
442
436
|
}
|
|
443
437
|
if (!n.ok)
|
|
444
|
-
throw new Error(
|
|
438
|
+
throw new Error(H);
|
|
445
439
|
i = await n.json();
|
|
446
440
|
}
|
|
447
|
-
return "api" in i && (i = i.api), i.named_endpoints["/predict"] && !i.unnamed_endpoints[0] && (i.unnamed_endpoints[0] = i.named_endpoints["/predict"]),
|
|
441
|
+
return "api" in i && (i = i.api), i.named_endpoints["/predict"] && !i.unnamed_endpoints[0] && (i.unnamed_endpoints[0] = i.named_endpoints["/predict"]), Nt(i, t, this.api_map);
|
|
448
442
|
} catch (n) {
|
|
449
443
|
throw new Error("Could not get API info. " + n.message);
|
|
450
444
|
}
|
|
451
445
|
}
|
|
452
|
-
async function
|
|
446
|
+
async function Lt(e, t, s) {
|
|
453
447
|
var a;
|
|
454
448
|
const n = {};
|
|
455
449
|
(a = this == null ? void 0 : this.options) != null && a.hf_token && (n.Authorization = `Bearer ${this.options.hf_token}`);
|
|
@@ -461,7 +455,7 @@ async function At(e, t, s) {
|
|
|
461
455
|
m.append("files", g);
|
|
462
456
|
});
|
|
463
457
|
try {
|
|
464
|
-
const g = s ? `${e}${this.api_prefix}/${
|
|
458
|
+
const g = s ? `${e}${this.api_prefix}/${Oe}?upload_id=${s}` : `${e}${this.api_prefix}/${Oe}`;
|
|
465
459
|
o = await this.fetch(g, {
|
|
466
460
|
method: "POST",
|
|
467
461
|
body: m,
|
|
@@ -469,7 +463,7 @@ async function At(e, t, s) {
|
|
|
469
463
|
credentials: "include"
|
|
470
464
|
});
|
|
471
465
|
} catch (g) {
|
|
472
|
-
throw new Error(
|
|
466
|
+
throw new Error(H + g.message);
|
|
473
467
|
}
|
|
474
468
|
if (!o.ok) {
|
|
475
469
|
const g = await o.text();
|
|
@@ -480,7 +474,7 @@ async function At(e, t, s) {
|
|
|
480
474
|
}
|
|
481
475
|
return { files: r };
|
|
482
476
|
}
|
|
483
|
-
async function
|
|
477
|
+
async function Pt(e, t, s, n) {
|
|
484
478
|
let i = (Array.isArray(e) ? e : [e]).map(
|
|
485
479
|
(o) => o.blob
|
|
486
480
|
);
|
|
@@ -505,7 +499,7 @@ async function Lt(e, t, s, n) {
|
|
|
505
499
|
)
|
|
506
500
|
);
|
|
507
501
|
}
|
|
508
|
-
async function
|
|
502
|
+
async function cs(e, t) {
|
|
509
503
|
return e.map(
|
|
510
504
|
(s) => new se({
|
|
511
505
|
path: s.name,
|
|
@@ -542,7 +536,7 @@ class se {
|
|
|
542
536
|
this.path = t, this.url = s, this.orig_name = n, this.size = i, this.blob = s ? void 0 : r, this.is_stream = o, this.mime_type = a, this.alt_text = l, this.b64 = h;
|
|
543
537
|
}
|
|
544
538
|
}
|
|
545
|
-
class
|
|
539
|
+
class Fe {
|
|
546
540
|
constructor(t, s) {
|
|
547
541
|
u(this, "type");
|
|
548
542
|
u(this, "command");
|
|
@@ -551,8 +545,8 @@ class Be {
|
|
|
551
545
|
this.type = "command", this.command = t, this.meta = s;
|
|
552
546
|
}
|
|
553
547
|
}
|
|
554
|
-
const
|
|
555
|
-
function
|
|
548
|
+
const jt = typeof process < "u" && process.versions && process.versions.node;
|
|
549
|
+
function De(e, t, s) {
|
|
556
550
|
for (; s.length > 1; ) {
|
|
557
551
|
const i = s.shift();
|
|
558
552
|
if (typeof i == "string" || typeof i == "number")
|
|
@@ -612,12 +606,12 @@ async function de(e, t = void 0, s = [], n = !1, i = void 0) {
|
|
|
612
606
|
}
|
|
613
607
|
return [];
|
|
614
608
|
}
|
|
615
|
-
function
|
|
609
|
+
function xt(e, t) {
|
|
616
610
|
var n, i;
|
|
617
611
|
let s = (i = (n = t == null ? void 0 : t.dependencies) == null ? void 0 : n.find((r) => r.id == e)) == null ? void 0 : i.queue;
|
|
618
612
|
return s != null ? !s : !t.enable_queue;
|
|
619
613
|
}
|
|
620
|
-
function
|
|
614
|
+
function It(e, t) {
|
|
621
615
|
return new Promise((s, n) => {
|
|
622
616
|
const i = new MessageChannel();
|
|
623
617
|
i.port1.onmessage = ({ data: r }) => {
|
|
@@ -625,7 +619,7 @@ function xt(e, t) {
|
|
|
625
619
|
}, window.parent.postMessage(e, t, [i.port2]);
|
|
626
620
|
});
|
|
627
621
|
}
|
|
628
|
-
function
|
|
622
|
+
function ls(e) {
|
|
629
623
|
if (typeof e == "string") {
|
|
630
624
|
if (e.startsWith("http://") || e.startsWith("https://"))
|
|
631
625
|
return {
|
|
@@ -634,8 +628,8 @@ function cs(e) {
|
|
|
634
628
|
orig_name: e.split("/").pop() ?? "unknown",
|
|
635
629
|
meta: { _type: "gradio.FileData" }
|
|
636
630
|
};
|
|
637
|
-
if (
|
|
638
|
-
return new
|
|
631
|
+
if (jt)
|
|
632
|
+
return new Fe("upload_file", {
|
|
639
633
|
path: e,
|
|
640
634
|
name: e,
|
|
641
635
|
orig_path: e
|
|
@@ -680,9 +674,9 @@ function K(e, t, s, n, i = !1) {
|
|
|
680
674
|
}
|
|
681
675
|
return r;
|
|
682
676
|
}
|
|
683
|
-
async function
|
|
677
|
+
async function Ut(e, t, s) {
|
|
684
678
|
const n = this;
|
|
685
|
-
await
|
|
679
|
+
await qt(n, t);
|
|
686
680
|
const i = await de(
|
|
687
681
|
t,
|
|
688
682
|
void 0,
|
|
@@ -692,8 +686,7 @@ async function It(e, t, s) {
|
|
|
692
686
|
);
|
|
693
687
|
return (await Promise.all(
|
|
694
688
|
i.map(async ({ path: o, blob: a, type: l }) => {
|
|
695
|
-
if (!a)
|
|
696
|
-
return { path: o, type: l };
|
|
689
|
+
if (!a) return { path: o, type: l };
|
|
697
690
|
const h = await n.upload_files(e, [a]), m = h.files && h.files[0];
|
|
698
691
|
return {
|
|
699
692
|
path: o,
|
|
@@ -704,36 +697,36 @@ async function It(e, t, s) {
|
|
|
704
697
|
})
|
|
705
698
|
)).forEach(({ path: o, file_url: a, type: l, name: h }) => {
|
|
706
699
|
if (l === "Gallery")
|
|
707
|
-
|
|
700
|
+
De(t, a, o);
|
|
708
701
|
else if (a) {
|
|
709
702
|
const m = new se({ path: a, orig_name: h });
|
|
710
|
-
|
|
703
|
+
De(t, m, o);
|
|
711
704
|
}
|
|
712
705
|
}), t;
|
|
713
706
|
}
|
|
714
|
-
async function
|
|
707
|
+
async function qt(e, t) {
|
|
715
708
|
var n, i;
|
|
716
709
|
if (!(((n = e.config) == null ? void 0 : n.root) || ((i = e.config) == null ? void 0 : i.root_url)))
|
|
717
|
-
throw new Error(
|
|
718
|
-
await
|
|
710
|
+
throw new Error(Ue);
|
|
711
|
+
await Ge(e, t);
|
|
719
712
|
}
|
|
720
|
-
async function
|
|
713
|
+
async function Ge(e, t, s = []) {
|
|
721
714
|
for (const n in t)
|
|
722
|
-
t[n] instanceof
|
|
715
|
+
t[n] instanceof Fe ? await zt(e, t, n) : typeof t[n] == "object" && t[n] !== null && await Ge(e, t[n], [...s, n]);
|
|
723
716
|
}
|
|
724
|
-
async function
|
|
717
|
+
async function zt(e, t, s) {
|
|
725
718
|
var r, o;
|
|
726
719
|
let n = t[s];
|
|
727
720
|
const i = ((r = e.config) == null ? void 0 : r.root) || ((o = e.config) == null ? void 0 : o.root_url);
|
|
728
721
|
if (!i)
|
|
729
|
-
throw new Error(
|
|
722
|
+
throw new Error(Ue);
|
|
730
723
|
try {
|
|
731
724
|
let a, l;
|
|
732
725
|
if (typeof process < "u" && process.versions && process.versions.node) {
|
|
733
726
|
const g = await import("./__vite-browser-external-DYxpcVy9.js");
|
|
734
727
|
l = (await import("./__vite-browser-external-DYxpcVy9.js")).resolve(process.cwd(), n.meta.path), a = await g.readFile(l);
|
|
735
728
|
} else
|
|
736
|
-
throw new Error(
|
|
729
|
+
throw new Error(bt);
|
|
737
730
|
const h = new Blob([a], { type: "application/octet-stream" }), m = await e.upload_files(i, [h]), p = m.files && m.files[0];
|
|
738
731
|
if (p) {
|
|
739
732
|
const g = new se({
|
|
@@ -743,10 +736,10 @@ async function qt(e, t, s) {
|
|
|
743
736
|
t[s] = g;
|
|
744
737
|
}
|
|
745
738
|
} catch (a) {
|
|
746
|
-
console.error(
|
|
739
|
+
console.error(vt, a);
|
|
747
740
|
}
|
|
748
741
|
}
|
|
749
|
-
async function
|
|
742
|
+
async function Bt(e, t, s) {
|
|
750
743
|
const n = { "Content-Type": "application/json" };
|
|
751
744
|
this.options.hf_token && (n.Authorization = `Bearer ${this.options.hf_token}`);
|
|
752
745
|
try {
|
|
@@ -757,7 +750,7 @@ async function zt(e, t, s) {
|
|
|
757
750
|
credentials: "include"
|
|
758
751
|
});
|
|
759
752
|
} catch {
|
|
760
|
-
return [{ error:
|
|
753
|
+
return [{ error: H }, 500];
|
|
761
754
|
}
|
|
762
755
|
let r, o;
|
|
763
756
|
try {
|
|
@@ -767,7 +760,7 @@ async function zt(e, t, s) {
|
|
|
767
760
|
}
|
|
768
761
|
return [r, o];
|
|
769
762
|
}
|
|
770
|
-
async function
|
|
763
|
+
async function Ft(e, t = {}) {
|
|
771
764
|
let s = !1, n = !1;
|
|
772
765
|
if (!this.config)
|
|
773
766
|
throw new Error("Could not resolve app config");
|
|
@@ -796,13 +789,12 @@ async function Q(e, t, s) {
|
|
|
796
789
|
s({
|
|
797
790
|
status: "error",
|
|
798
791
|
load_status: "error",
|
|
799
|
-
message:
|
|
792
|
+
message: _t,
|
|
800
793
|
detail: "NOT_FOUND"
|
|
801
794
|
});
|
|
802
795
|
return;
|
|
803
796
|
}
|
|
804
|
-
if (!i || r !== 200)
|
|
805
|
-
return;
|
|
797
|
+
if (!i || r !== 200) return;
|
|
806
798
|
const {
|
|
807
799
|
runtime: { stage: o },
|
|
808
800
|
id: a
|
|
@@ -868,7 +860,7 @@ async function Q(e, t, s) {
|
|
|
868
860
|
break;
|
|
869
861
|
}
|
|
870
862
|
}
|
|
871
|
-
const
|
|
863
|
+
const Me = async (e, t) => {
|
|
872
864
|
let s = 0;
|
|
873
865
|
const n = 12, i = 5e3;
|
|
874
866
|
return new Promise((r) => {
|
|
@@ -877,12 +869,12 @@ const Ge = async (e, t) => {
|
|
|
877
869
|
me.test(e) ? "space_name" : "subdomain",
|
|
878
870
|
(o) => {
|
|
879
871
|
t(o), o.status === "running" || o.status === "error" || o.status === "paused" || o.status === "space_error" ? r() : (o.status === "sleeping" || o.status === "building") && (s < n ? (s++, setTimeout(() => {
|
|
880
|
-
|
|
872
|
+
Me(e, t).then(r);
|
|
881
873
|
}, i)) : r());
|
|
882
874
|
}
|
|
883
875
|
);
|
|
884
876
|
});
|
|
885
|
-
},
|
|
877
|
+
}, Gt = /^(?=[^]*\b[dD]iscussions{0,1}\b)(?=[^]*\b[dD]isabled\b)[^]*$/;
|
|
886
878
|
async function Ce(e) {
|
|
887
879
|
try {
|
|
888
880
|
const t = await fetch(
|
|
@@ -891,17 +883,17 @@ async function Ce(e) {
|
|
|
891
883
|
method: "HEAD"
|
|
892
884
|
}
|
|
893
885
|
), s = t.headers.get("x-error-message");
|
|
894
|
-
return !(!t.ok || s &&
|
|
886
|
+
return !(!t.ok || s && Gt.test(s));
|
|
895
887
|
} catch {
|
|
896
888
|
return !1;
|
|
897
889
|
}
|
|
898
890
|
}
|
|
899
|
-
async function
|
|
891
|
+
async function Mt(e, t) {
|
|
900
892
|
const s = {};
|
|
901
893
|
t && (s.Authorization = `Bearer ${t}`);
|
|
902
894
|
try {
|
|
903
895
|
const n = await fetch(
|
|
904
|
-
`https://huggingface.co/api/spaces/${e}/${
|
|
896
|
+
`https://huggingface.co/api/spaces/${e}/${at}`,
|
|
905
897
|
{ headers: s }
|
|
906
898
|
);
|
|
907
899
|
if (n.status !== 200)
|
|
@@ -912,7 +904,7 @@ async function Gt(e, t) {
|
|
|
912
904
|
throw new Error(n.message);
|
|
913
905
|
}
|
|
914
906
|
}
|
|
915
|
-
async function
|
|
907
|
+
async function Jt(e, t, s) {
|
|
916
908
|
const n = {};
|
|
917
909
|
s && (n.Authorization = `Bearer ${s}`);
|
|
918
910
|
const i = {
|
|
@@ -920,7 +912,7 @@ async function Mt(e, t, s) {
|
|
|
920
912
|
};
|
|
921
913
|
try {
|
|
922
914
|
const r = await fetch(
|
|
923
|
-
`https://huggingface.co/api/spaces/${e}/${
|
|
915
|
+
`https://huggingface.co/api/spaces/${e}/${ct}`,
|
|
924
916
|
{
|
|
925
917
|
method: "POST",
|
|
926
918
|
headers: { "Content-Type": "application/json", ...n },
|
|
@@ -936,7 +928,7 @@ async function Mt(e, t, s) {
|
|
|
936
928
|
throw new Error(r.message);
|
|
937
929
|
}
|
|
938
930
|
}
|
|
939
|
-
const
|
|
931
|
+
const Ae = [
|
|
940
932
|
"cpu-basic",
|
|
941
933
|
"cpu-upgrade",
|
|
942
934
|
"cpu-xl",
|
|
@@ -951,11 +943,11 @@ const De = [
|
|
|
951
943
|
"h100",
|
|
952
944
|
"h100x8"
|
|
953
945
|
];
|
|
954
|
-
async function
|
|
946
|
+
async function Wt(e, t) {
|
|
955
947
|
const { hf_token: s, private: n, hardware: i, timeout: r, auth: o } = t;
|
|
956
|
-
if (i && !
|
|
948
|
+
if (i && !Ae.includes(i))
|
|
957
949
|
throw new Error(
|
|
958
|
-
`Invalid hardware type provided. Valid types are: ${
|
|
950
|
+
`Invalid hardware type provided. Valid types are: ${Ae.map((_) => `"${_}"`).join(",")}.`
|
|
959
951
|
);
|
|
960
952
|
const { http_protocol: a, host: l } = await te(
|
|
961
953
|
e,
|
|
@@ -963,13 +955,13 @@ async function Jt(e, t) {
|
|
|
963
955
|
);
|
|
964
956
|
let h = null;
|
|
965
957
|
if (o) {
|
|
966
|
-
const
|
|
958
|
+
const _ = await qe(
|
|
967
959
|
a,
|
|
968
960
|
l,
|
|
969
961
|
o,
|
|
970
962
|
fetch
|
|
971
963
|
);
|
|
972
|
-
|
|
964
|
+
_ && (h = ze(_));
|
|
973
965
|
}
|
|
974
966
|
const m = {
|
|
975
967
|
Authorization: `Bearer ${s}`,
|
|
@@ -983,14 +975,14 @@ async function Jt(e, t) {
|
|
|
983
975
|
n && (E.private = !0);
|
|
984
976
|
let B;
|
|
985
977
|
try {
|
|
986
|
-
i || (B = await
|
|
987
|
-
} catch (
|
|
988
|
-
throw Error(_e +
|
|
978
|
+
i || (B = await Mt(e, s));
|
|
979
|
+
} catch (_) {
|
|
980
|
+
throw Error(_e + _.message);
|
|
989
981
|
}
|
|
990
982
|
const c = i || B || "cpu-basic";
|
|
991
983
|
E.hardware = c;
|
|
992
984
|
try {
|
|
993
|
-
const
|
|
985
|
+
const _ = await fetch(
|
|
994
986
|
`https://huggingface.co/api/spaces/${e}/duplicate`,
|
|
995
987
|
{
|
|
996
988
|
method: "POST",
|
|
@@ -998,35 +990,35 @@ async function Jt(e, t) {
|
|
|
998
990
|
body: JSON.stringify(E)
|
|
999
991
|
}
|
|
1000
992
|
);
|
|
1001
|
-
if (
|
|
993
|
+
if (_.status === 409)
|
|
1002
994
|
try {
|
|
1003
995
|
return await ee.connect(`${p}/${g}`, t);
|
|
1004
|
-
} catch (
|
|
1005
|
-
throw console.error("Failed to connect Client instance:",
|
|
996
|
+
} catch (C) {
|
|
997
|
+
throw console.error("Failed to connect Client instance:", C), C;
|
|
1006
998
|
}
|
|
1007
|
-
else if (
|
|
1008
|
-
throw new Error(
|
|
1009
|
-
const
|
|
1010
|
-
return await
|
|
1011
|
-
|
|
999
|
+
else if (_.status !== 200)
|
|
1000
|
+
throw new Error(_.statusText);
|
|
1001
|
+
const N = await _.json();
|
|
1002
|
+
return await Jt(`${p}/${g}`, r || 300, s), await ee.connect(
|
|
1003
|
+
Ht(N.url),
|
|
1012
1004
|
t
|
|
1013
1005
|
);
|
|
1014
|
-
} catch (
|
|
1015
|
-
throw new Error(
|
|
1006
|
+
} catch (_) {
|
|
1007
|
+
throw new Error(_);
|
|
1016
1008
|
}
|
|
1017
1009
|
}
|
|
1018
|
-
function
|
|
1010
|
+
function Ht(e) {
|
|
1019
1011
|
const t = /https:\/\/huggingface.co\/spaces\/([^/]+\/[^/]+)/, s = e.match(t);
|
|
1020
1012
|
if (s)
|
|
1021
1013
|
return s[1];
|
|
1022
1014
|
}
|
|
1023
1015
|
var I;
|
|
1024
|
-
class
|
|
1016
|
+
class Vt extends TransformStream {
|
|
1025
1017
|
/** Constructs a new instance. */
|
|
1026
1018
|
constructor(s = { allowCR: !1 }) {
|
|
1027
1019
|
super({
|
|
1028
1020
|
transform: (n, i) => {
|
|
1029
|
-
for (n =
|
|
1021
|
+
for (n = W(this, I) + n; ; ) {
|
|
1030
1022
|
const r = n.indexOf(`
|
|
1031
1023
|
`), o = s.allowCR ? n.indexOf("\r") : -1;
|
|
1032
1024
|
if (o !== -1 && o !== n.length - 1 && (r === -1 || r - 1 > o)) {
|
|
@@ -1038,24 +1030,24 @@ class Ht extends TransformStream {
|
|
|
1038
1030
|
const a = n[r - 1] === "\r" ? r - 1 : r;
|
|
1039
1031
|
i.enqueue(n.slice(0, a)), n = n.slice(r + 1);
|
|
1040
1032
|
}
|
|
1041
|
-
|
|
1033
|
+
Re(this, I, n);
|
|
1042
1034
|
},
|
|
1043
1035
|
flush: (n) => {
|
|
1044
|
-
if (
|
|
1036
|
+
if (W(this, I) === "")
|
|
1045
1037
|
return;
|
|
1046
|
-
const i = s.allowCR &&
|
|
1038
|
+
const i = s.allowCR && W(this, I).endsWith("\r") ? W(this, I).slice(0, -1) : W(this, I);
|
|
1047
1039
|
n.enqueue(i);
|
|
1048
1040
|
}
|
|
1049
1041
|
});
|
|
1050
|
-
|
|
1042
|
+
ke(this, I, "");
|
|
1051
1043
|
}
|
|
1052
1044
|
}
|
|
1053
1045
|
I = new WeakMap();
|
|
1054
|
-
function
|
|
1055
|
-
let t = new TextDecoderStream(), s = new
|
|
1046
|
+
function Zt(e) {
|
|
1047
|
+
let t = new TextDecoderStream(), s = new Vt({ allowCR: !0 });
|
|
1056
1048
|
return e.pipeThrough(t).pipeThrough(s);
|
|
1057
1049
|
}
|
|
1058
|
-
function
|
|
1050
|
+
function Kt(e) {
|
|
1059
1051
|
let s = /[:]\s*/.exec(e), n = s && s.index;
|
|
1060
1052
|
if (n)
|
|
1061
1053
|
return [
|
|
@@ -1063,13 +1055,13 @@ function Zt(e) {
|
|
|
1063
1055
|
e.substring(n + s[0].length)
|
|
1064
1056
|
];
|
|
1065
1057
|
}
|
|
1066
|
-
function
|
|
1058
|
+
function Le(e, t, s) {
|
|
1067
1059
|
e.get(t) || e.set(t, s);
|
|
1068
1060
|
}
|
|
1069
|
-
async function*
|
|
1061
|
+
async function* Qt(e, t) {
|
|
1070
1062
|
if (!e.body)
|
|
1071
1063
|
return;
|
|
1072
|
-
let s =
|
|
1064
|
+
let s = Zt(e.body), n, i = s.getReader(), r;
|
|
1073
1065
|
for (; ; ) {
|
|
1074
1066
|
if (t && t.aborted)
|
|
1075
1067
|
return i.cancel();
|
|
@@ -1079,20 +1071,20 @@ async function* Kt(e, t) {
|
|
|
1079
1071
|
r && (yield r), r = void 0;
|
|
1080
1072
|
continue;
|
|
1081
1073
|
}
|
|
1082
|
-
let [o, a] =
|
|
1074
|
+
let [o, a] = Kt(n.value) || [];
|
|
1083
1075
|
o && (o === "data" ? (r || (r = {}), r[o] = r[o] ? r[o] + `
|
|
1084
1076
|
` + 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));
|
|
1085
1077
|
}
|
|
1086
1078
|
}
|
|
1087
|
-
async function
|
|
1079
|
+
async function Xt(e, t) {
|
|
1088
1080
|
let s = new Request(e, t);
|
|
1089
|
-
|
|
1081
|
+
Le(s.headers, "Accept", "text/event-stream"), Le(s.headers, "Content-Type", "application/json");
|
|
1090
1082
|
let n = await fetch(s);
|
|
1091
1083
|
if (!n.ok)
|
|
1092
1084
|
throw n;
|
|
1093
|
-
return
|
|
1085
|
+
return Qt(n, s.signal);
|
|
1094
1086
|
}
|
|
1095
|
-
async function
|
|
1087
|
+
async function Yt() {
|
|
1096
1088
|
let {
|
|
1097
1089
|
event_callbacks: e,
|
|
1098
1090
|
unclosed_events: t,
|
|
@@ -1107,7 +1099,7 @@ async function Xt() {
|
|
|
1107
1099
|
n.open = !0;
|
|
1108
1100
|
let a = null, l = new URLSearchParams({
|
|
1109
1101
|
session_hash: this.session_hash
|
|
1110
|
-
}).toString(), h = new URL(`${i.root}${this.api_prefix}/${
|
|
1102
|
+
}).toString(), h = new URL(`${i.root}${this.api_prefix}/${je}?${l}`);
|
|
1111
1103
|
if (r && h.searchParams.set("__sign", r), a = this.stream(h), !a) {
|
|
1112
1104
|
console.warn("Cannot connect to SSE endpoint: " + h.toString());
|
|
1113
1105
|
return;
|
|
@@ -1138,7 +1130,7 @@ async function Xt() {
|
|
|
1138
1130
|
Object.keys(e).map(
|
|
1139
1131
|
(p) => e[p]({
|
|
1140
1132
|
msg: "broken_connection",
|
|
1141
|
-
message:
|
|
1133
|
+
message: H
|
|
1142
1134
|
})
|
|
1143
1135
|
)
|
|
1144
1136
|
);
|
|
@@ -1147,20 +1139,20 @@ async function Xt() {
|
|
|
1147
1139
|
function ge(e, t) {
|
|
1148
1140
|
e && (e.open = !1, t == null || t.abort());
|
|
1149
1141
|
}
|
|
1150
|
-
function
|
|
1142
|
+
function es(e, t, s) {
|
|
1151
1143
|
!e[t] ? (e[t] = [], s.data.forEach((i, r) => {
|
|
1152
1144
|
e[t][r] = i;
|
|
1153
1145
|
})) : s.data.forEach((i, r) => {
|
|
1154
|
-
let o =
|
|
1146
|
+
let o = ts(e[t][r], i);
|
|
1155
1147
|
e[t][r] = o, s.data[r] = o;
|
|
1156
1148
|
});
|
|
1157
1149
|
}
|
|
1158
|
-
function
|
|
1150
|
+
function ts(e, t) {
|
|
1159
1151
|
return t.forEach(([s, n, i]) => {
|
|
1160
|
-
e =
|
|
1152
|
+
e = ss(e, n, s, i);
|
|
1161
1153
|
}), e;
|
|
1162
1154
|
}
|
|
1163
|
-
function
|
|
1155
|
+
function ss(e, t, s, n) {
|
|
1164
1156
|
if (t.length === 0) {
|
|
1165
1157
|
if (s === "replace")
|
|
1166
1158
|
return n;
|
|
@@ -1190,7 +1182,7 @@ function ts(e, t, s, n) {
|
|
|
1190
1182
|
}
|
|
1191
1183
|
return e;
|
|
1192
1184
|
}
|
|
1193
|
-
function
|
|
1185
|
+
function ns(e, t = {}) {
|
|
1194
1186
|
const s = {
|
|
1195
1187
|
close: () => {
|
|
1196
1188
|
console.warn("Method not implemented.");
|
|
@@ -1214,7 +1206,7 @@ function ss(e, t = {}) {
|
|
|
1214
1206
|
throw new Error("Method not implemented.");
|
|
1215
1207
|
}
|
|
1216
1208
|
};
|
|
1217
|
-
return
|
|
1209
|
+
return Xt(e, t).then(async (n) => {
|
|
1218
1210
|
s.readyState = s.OPEN;
|
|
1219
1211
|
try {
|
|
1220
1212
|
for await (const i of n)
|
|
@@ -1227,13 +1219,13 @@ function ss(e, t = {}) {
|
|
|
1227
1219
|
console.error(n), s.onerror && s.onerror(n), s.readyState = s.CLOSED;
|
|
1228
1220
|
}), s;
|
|
1229
1221
|
}
|
|
1230
|
-
function
|
|
1222
|
+
function is(e, t = {}, s, n, i) {
|
|
1231
1223
|
var r;
|
|
1232
1224
|
try {
|
|
1233
1225
|
let o = function(w) {
|
|
1234
|
-
(i ||
|
|
1226
|
+
(i || Ze[w.type]) && m(w);
|
|
1235
1227
|
}, a = function() {
|
|
1236
|
-
for (
|
|
1228
|
+
for (Xe = !0; Z.length > 0; )
|
|
1237
1229
|
Z.shift()({
|
|
1238
1230
|
value: void 0,
|
|
1239
1231
|
done: !0
|
|
@@ -1241,7 +1233,7 @@ function ns(e, t = {}, s, n, i) {
|
|
|
1241
1233
|
}, l = function(w) {
|
|
1242
1234
|
Z.length > 0 ? Z.shift()(w) : le.push(w);
|
|
1243
1235
|
}, h = function(w) {
|
|
1244
|
-
l(
|
|
1236
|
+
l(os(w)), a();
|
|
1245
1237
|
}, m = function(w) {
|
|
1246
1238
|
l({ value: w, done: !1 });
|
|
1247
1239
|
}, p = function() {
|
|
@@ -1251,47 +1243,45 @@ function ns(e, t = {}, s, n, i) {
|
|
|
1251
1243
|
fetch: E,
|
|
1252
1244
|
app_reference: B,
|
|
1253
1245
|
config: c,
|
|
1254
|
-
session_hash:
|
|
1255
|
-
api_info:
|
|
1256
|
-
api_map:
|
|
1246
|
+
session_hash: _,
|
|
1247
|
+
api_info: N,
|
|
1248
|
+
api_map: C,
|
|
1257
1249
|
stream_status: ne,
|
|
1258
1250
|
pending_stream_messages: ie,
|
|
1259
1251
|
pending_diff_streams: oe,
|
|
1260
1252
|
event_callbacks: re,
|
|
1261
|
-
unclosed_events:
|
|
1253
|
+
unclosed_events: Je,
|
|
1262
1254
|
post_data: ae,
|
|
1263
1255
|
options: F,
|
|
1264
|
-
api_prefix:
|
|
1265
|
-
} = this,
|
|
1266
|
-
if (!
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
let { fn_index: f, endpoint_info: we, dependency: W } = os(
|
|
1271
|
-
O,
|
|
1256
|
+
api_prefix: M
|
|
1257
|
+
} = this, We = this;
|
|
1258
|
+
if (!N) throw new Error("No API found");
|
|
1259
|
+
if (!c) throw new Error("Could not resolve app config");
|
|
1260
|
+
let { fn_index: f, endpoint_info: we, dependency: J } = rs(
|
|
1261
|
+
N,
|
|
1272
1262
|
e,
|
|
1273
|
-
|
|
1263
|
+
C,
|
|
1274
1264
|
c
|
|
1275
|
-
),
|
|
1276
|
-
const
|
|
1277
|
-
let V, S = null,
|
|
1278
|
-
const
|
|
1265
|
+
), He = Ct(t, we), R, T, j = c.protocol ?? "ws", ye = "", Ve = () => ye;
|
|
1266
|
+
const d = typeof e == "number" ? "/predict" : e;
|
|
1267
|
+
let V, S = null, D = !1, ce = {}, G = typeof window < "u" && typeof document < "u" ? new URLSearchParams(window.location.search).toString() : "";
|
|
1268
|
+
const Ze = ((r = F == null ? void 0 : F.events) == null ? void 0 : r.reduce(
|
|
1279
1269
|
(w, x) => (w[x] = !0, w),
|
|
1280
1270
|
{}
|
|
1281
1271
|
)) || {};
|
|
1282
|
-
async function
|
|
1272
|
+
async function Ke() {
|
|
1283
1273
|
let w = {}, x = {};
|
|
1284
1274
|
j === "ws" ? (R && R.readyState === 0 ? R.addEventListener("open", () => {
|
|
1285
1275
|
R.close();
|
|
1286
|
-
}) : R.close(), w = { fn_index: f, session_hash:
|
|
1276
|
+
}) : R.close(), w = { fn_index: f, session_hash: _ }) : (w = { event_id: S }, x = { event_id: S, session_hash: _, fn_index: f });
|
|
1287
1277
|
try {
|
|
1288
1278
|
if (!c)
|
|
1289
1279
|
throw new Error("Could not resolve app config");
|
|
1290
|
-
"event_id" in x && await E(`${c.root}${
|
|
1280
|
+
"event_id" in x && await E(`${c.root}${M}/${ft}`, {
|
|
1291
1281
|
headers: { "Content-Type": "application/json" },
|
|
1292
1282
|
method: "POST",
|
|
1293
1283
|
body: JSON.stringify(x)
|
|
1294
|
-
}), await E(`${c.root}${
|
|
1284
|
+
}), await E(`${c.root}${M}/${pt}`, {
|
|
1295
1285
|
headers: { "Content-Type": "application/json" },
|
|
1296
1286
|
method: "POST",
|
|
1297
1287
|
body: JSON.stringify(w)
|
|
@@ -1302,12 +1292,11 @@ function ns(e, t = {}, s, n, i) {
|
|
|
1302
1292
|
);
|
|
1303
1293
|
}
|
|
1304
1294
|
}
|
|
1305
|
-
const
|
|
1295
|
+
const Qe = async (w) => {
|
|
1306
1296
|
await this._resolve_heartbeat(w);
|
|
1307
1297
|
};
|
|
1308
1298
|
async function be(w) {
|
|
1309
|
-
if (!c)
|
|
1310
|
-
return;
|
|
1299
|
+
if (!c) return;
|
|
1311
1300
|
let x = w.render_id;
|
|
1312
1301
|
c.components = [
|
|
1313
1302
|
...c.components.filter((y) => y.props.rendered_in !== x),
|
|
@@ -1319,20 +1308,20 @@ function ns(e, t = {}, s, n, i) {
|
|
|
1319
1308
|
const X = c.components.some((y) => y.type === "state"), Y = c.dependencies.some(
|
|
1320
1309
|
(y) => y.targets.some((U) => U[1] === "unload")
|
|
1321
1310
|
);
|
|
1322
|
-
c.connect_heartbeat = X || Y, await
|
|
1311
|
+
c.connect_heartbeat = X || Y, await Qe(c), o({
|
|
1323
1312
|
type: "render",
|
|
1324
1313
|
data: w,
|
|
1325
|
-
endpoint:
|
|
1314
|
+
endpoint: d,
|
|
1326
1315
|
fn_index: f
|
|
1327
1316
|
});
|
|
1328
1317
|
}
|
|
1329
|
-
this.handle_blob(c.root,
|
|
1318
|
+
this.handle_blob(c.root, He, we).then(
|
|
1330
1319
|
async (w) => {
|
|
1331
1320
|
var Y;
|
|
1332
1321
|
if (V = {
|
|
1333
1322
|
data: K(
|
|
1334
1323
|
w,
|
|
1335
|
-
|
|
1324
|
+
J,
|
|
1336
1325
|
c.components,
|
|
1337
1326
|
"input",
|
|
1338
1327
|
!0
|
|
@@ -1340,29 +1329,29 @@ function ns(e, t = {}, s, n, i) {
|
|
|
1340
1329
|
event_data: s,
|
|
1341
1330
|
fn_index: f,
|
|
1342
1331
|
trigger_id: n
|
|
1343
|
-
},
|
|
1332
|
+
}, xt(f, c))
|
|
1344
1333
|
o({
|
|
1345
1334
|
type: "status",
|
|
1346
|
-
endpoint:
|
|
1335
|
+
endpoint: d,
|
|
1347
1336
|
stage: "pending",
|
|
1348
1337
|
queue: !1,
|
|
1349
1338
|
fn_index: f,
|
|
1350
1339
|
time: /* @__PURE__ */ new Date()
|
|
1351
1340
|
}), ae(
|
|
1352
|
-
`${c.root}${
|
|
1341
|
+
`${c.root}${M}/run${d.startsWith("/") ? d : `/${d}`}${G ? "?" + G : ""}`,
|
|
1353
1342
|
{
|
|
1354
1343
|
...V,
|
|
1355
|
-
session_hash:
|
|
1344
|
+
session_hash: _
|
|
1356
1345
|
}
|
|
1357
1346
|
).then(([y, U]) => {
|
|
1358
1347
|
const q = y.data;
|
|
1359
1348
|
U == 200 ? (o({
|
|
1360
1349
|
type: "data",
|
|
1361
|
-
endpoint:
|
|
1350
|
+
endpoint: d,
|
|
1362
1351
|
fn_index: f,
|
|
1363
1352
|
data: K(
|
|
1364
1353
|
q,
|
|
1365
|
-
|
|
1354
|
+
J,
|
|
1366
1355
|
c.components,
|
|
1367
1356
|
"output",
|
|
1368
1357
|
F.with_null_state
|
|
@@ -1372,7 +1361,7 @@ function ns(e, t = {}, s, n, i) {
|
|
|
1372
1361
|
trigger_id: n
|
|
1373
1362
|
}), y.render_config && be(y.render_config), o({
|
|
1374
1363
|
type: "status",
|
|
1375
|
-
endpoint:
|
|
1364
|
+
endpoint: d,
|
|
1376
1365
|
fn_index: f,
|
|
1377
1366
|
stage: "complete",
|
|
1378
1367
|
eta: y.average_duration,
|
|
@@ -1381,7 +1370,7 @@ function ns(e, t = {}, s, n, i) {
|
|
|
1381
1370
|
})) : o({
|
|
1382
1371
|
type: "status",
|
|
1383
1372
|
stage: "error",
|
|
1384
|
-
endpoint:
|
|
1373
|
+
endpoint: d,
|
|
1385
1374
|
fn_index: f,
|
|
1386
1375
|
message: y.error,
|
|
1387
1376
|
queue: !1,
|
|
@@ -1392,7 +1381,7 @@ function ns(e, t = {}, s, n, i) {
|
|
|
1392
1381
|
type: "status",
|
|
1393
1382
|
stage: "error",
|
|
1394
1383
|
message: y.message,
|
|
1395
|
-
endpoint:
|
|
1384
|
+
endpoint: d,
|
|
1396
1385
|
fn_index: f,
|
|
1397
1386
|
queue: !1,
|
|
1398
1387
|
time: /* @__PURE__ */ new Date()
|
|
@@ -1407,12 +1396,12 @@ function ns(e, t = {}, s, n, i) {
|
|
|
1407
1396
|
type: "status",
|
|
1408
1397
|
stage: "pending",
|
|
1409
1398
|
queue: !0,
|
|
1410
|
-
endpoint:
|
|
1399
|
+
endpoint: d,
|
|
1411
1400
|
fn_index: f,
|
|
1412
1401
|
time: /* @__PURE__ */ new Date()
|
|
1413
1402
|
});
|
|
1414
1403
|
let q = new URL(
|
|
1415
|
-
`${y}://${
|
|
1404
|
+
`${y}://${Et(
|
|
1416
1405
|
U,
|
|
1417
1406
|
c.root,
|
|
1418
1407
|
!0
|
|
@@ -1423,206 +1412,215 @@ function ns(e, t = {}, s, n, i) {
|
|
|
1423
1412
|
type: "status",
|
|
1424
1413
|
stage: "error",
|
|
1425
1414
|
broken: !0,
|
|
1426
|
-
message:
|
|
1415
|
+
message: H,
|
|
1427
1416
|
queue: !0,
|
|
1428
|
-
endpoint:
|
|
1417
|
+
endpoint: d,
|
|
1429
1418
|
fn_index: f,
|
|
1430
1419
|
time: /* @__PURE__ */ new Date()
|
|
1431
1420
|
});
|
|
1432
1421
|
}, R.onmessage = function(A) {
|
|
1433
|
-
const k = JSON.parse(A.data), { type: $, status: v, data:
|
|
1422
|
+
const k = JSON.parse(A.data), { type: $, status: v, data: O } = he(
|
|
1434
1423
|
k,
|
|
1435
1424
|
ce[f]
|
|
1436
1425
|
);
|
|
1437
|
-
if ($ === "update" && v && !
|
|
1426
|
+
if ($ === "update" && v && !D)
|
|
1438
1427
|
o({
|
|
1439
1428
|
type: "status",
|
|
1440
|
-
endpoint:
|
|
1429
|
+
endpoint: d,
|
|
1441
1430
|
fn_index: f,
|
|
1442
1431
|
time: /* @__PURE__ */ new Date(),
|
|
1443
1432
|
...v
|
|
1444
1433
|
}), v.stage === "error" && R.close();
|
|
1445
1434
|
else if ($ === "hash") {
|
|
1446
|
-
R.send(JSON.stringify({ fn_index: f, session_hash:
|
|
1435
|
+
R.send(JSON.stringify({ fn_index: f, session_hash: _ }));
|
|
1447
1436
|
return;
|
|
1448
|
-
} else
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
C && (o({
|
|
1437
|
+
} else $ === "data" ? R.send(JSON.stringify({ ...V, session_hash: _ })) : $ === "complete" ? D = v : $ === "log" ? o({
|
|
1438
|
+
type: "log",
|
|
1439
|
+
title: O.title,
|
|
1440
|
+
log: O.log,
|
|
1441
|
+
level: O.level,
|
|
1442
|
+
endpoint: d,
|
|
1443
|
+
duration: O.duration,
|
|
1444
|
+
visible: O.visible,
|
|
1445
|
+
fn_index: f
|
|
1446
|
+
}) : $ === "generating" && o({
|
|
1447
|
+
type: "status",
|
|
1448
|
+
time: /* @__PURE__ */ new Date(),
|
|
1449
|
+
...v,
|
|
1450
|
+
stage: v == null ? void 0 : v.stage,
|
|
1451
|
+
queue: !0,
|
|
1452
|
+
endpoint: d,
|
|
1453
|
+
fn_index: f
|
|
1454
|
+
});
|
|
1455
|
+
O && (o({
|
|
1468
1456
|
type: "data",
|
|
1469
1457
|
time: /* @__PURE__ */ new Date(),
|
|
1470
1458
|
data: K(
|
|
1471
|
-
|
|
1472
|
-
|
|
1459
|
+
O.data,
|
|
1460
|
+
J,
|
|
1473
1461
|
c.components,
|
|
1474
1462
|
"output",
|
|
1475
1463
|
F.with_null_state
|
|
1476
1464
|
),
|
|
1477
|
-
endpoint:
|
|
1465
|
+
endpoint: d,
|
|
1478
1466
|
fn_index: f,
|
|
1479
1467
|
event_data: s,
|
|
1480
1468
|
trigger_id: n
|
|
1481
|
-
}),
|
|
1469
|
+
}), D && (o({
|
|
1482
1470
|
type: "status",
|
|
1483
1471
|
time: /* @__PURE__ */ new Date(),
|
|
1484
|
-
...
|
|
1472
|
+
...D,
|
|
1485
1473
|
stage: v == null ? void 0 : v.stage,
|
|
1486
1474
|
queue: !0,
|
|
1487
|
-
endpoint:
|
|
1475
|
+
endpoint: d,
|
|
1488
1476
|
fn_index: f
|
|
1489
1477
|
}), R.close()));
|
|
1490
|
-
},
|
|
1478
|
+
}, Pe(c.version || "2.0.0", "3.6") < 0 && addEventListener(
|
|
1491
1479
|
"open",
|
|
1492
|
-
() => R.send(JSON.stringify({ hash:
|
|
1480
|
+
() => R.send(JSON.stringify({ hash: _ }))
|
|
1493
1481
|
);
|
|
1494
1482
|
} else if (j == "sse") {
|
|
1495
1483
|
o({
|
|
1496
1484
|
type: "status",
|
|
1497
1485
|
stage: "pending",
|
|
1498
1486
|
queue: !0,
|
|
1499
|
-
endpoint:
|
|
1487
|
+
endpoint: d,
|
|
1500
1488
|
fn_index: f,
|
|
1501
1489
|
time: /* @__PURE__ */ new Date()
|
|
1502
1490
|
});
|
|
1503
1491
|
var X = new URLSearchParams({
|
|
1504
1492
|
fn_index: f.toString(),
|
|
1505
|
-
session_hash:
|
|
1493
|
+
session_hash: _
|
|
1506
1494
|
}).toString();
|
|
1507
1495
|
let y = new URL(
|
|
1508
|
-
`${c.root}${
|
|
1496
|
+
`${c.root}${M}/${je}?${G ? G + "&" : ""}${X}`
|
|
1509
1497
|
);
|
|
1510
|
-
if (this.jwt && y.searchParams.set("__sign", this.jwt),
|
|
1498
|
+
if (this.jwt && y.searchParams.set("__sign", this.jwt), T = this.stream(y), !T)
|
|
1511
1499
|
return Promise.reject(
|
|
1512
1500
|
new Error("Cannot connect to SSE endpoint: " + y.toString())
|
|
1513
1501
|
);
|
|
1514
|
-
|
|
1502
|
+
T.onmessage = async function(U) {
|
|
1515
1503
|
const q = JSON.parse(U.data), { type: A, status: k, data: $ } = he(
|
|
1516
1504
|
q,
|
|
1517
1505
|
ce[f]
|
|
1518
1506
|
);
|
|
1519
|
-
if (A === "update" && k && !
|
|
1507
|
+
if (A === "update" && k && !D)
|
|
1520
1508
|
o({
|
|
1521
1509
|
type: "status",
|
|
1522
|
-
endpoint:
|
|
1510
|
+
endpoint: d,
|
|
1523
1511
|
fn_index: f,
|
|
1524
1512
|
time: /* @__PURE__ */ new Date(),
|
|
1525
1513
|
...k
|
|
1526
|
-
}), k.stage === "error" && (
|
|
1514
|
+
}), k.stage === "error" && (T == null || T.close(), a());
|
|
1527
1515
|
else if (A === "data") {
|
|
1528
|
-
let [v,
|
|
1529
|
-
`${c.root}${
|
|
1516
|
+
let [v, O] = await ae(
|
|
1517
|
+
`${c.root}${M}/queue/data`,
|
|
1530
1518
|
{
|
|
1531
1519
|
...V,
|
|
1532
|
-
session_hash:
|
|
1520
|
+
session_hash: _,
|
|
1533
1521
|
event_id: S
|
|
1534
1522
|
}
|
|
1535
1523
|
);
|
|
1536
|
-
|
|
1524
|
+
O !== 200 && (o({
|
|
1537
1525
|
type: "status",
|
|
1538
1526
|
stage: "error",
|
|
1539
|
-
message:
|
|
1527
|
+
message: H,
|
|
1540
1528
|
queue: !0,
|
|
1541
|
-
endpoint:
|
|
1529
|
+
endpoint: d,
|
|
1542
1530
|
fn_index: f,
|
|
1543
1531
|
time: /* @__PURE__ */ new Date()
|
|
1544
|
-
}),
|
|
1545
|
-
} else
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
});
|
|
1532
|
+
}), T == null || T.close(), a());
|
|
1533
|
+
} else A === "complete" ? D = k : A === "log" ? o({
|
|
1534
|
+
type: "log",
|
|
1535
|
+
title: $.title,
|
|
1536
|
+
log: $.log,
|
|
1537
|
+
level: $.level,
|
|
1538
|
+
endpoint: d,
|
|
1539
|
+
duration: $.duration,
|
|
1540
|
+
visible: $.visible,
|
|
1541
|
+
fn_index: f
|
|
1542
|
+
}) : (A === "generating" || A === "streaming") && o({
|
|
1543
|
+
type: "status",
|
|
1544
|
+
time: /* @__PURE__ */ new Date(),
|
|
1545
|
+
...k,
|
|
1546
|
+
stage: k == null ? void 0 : k.stage,
|
|
1547
|
+
queue: !0,
|
|
1548
|
+
endpoint: d,
|
|
1549
|
+
fn_index: f
|
|
1550
|
+
});
|
|
1564
1551
|
$ && (o({
|
|
1565
1552
|
type: "data",
|
|
1566
1553
|
time: /* @__PURE__ */ new Date(),
|
|
1567
1554
|
data: K(
|
|
1568
1555
|
$.data,
|
|
1569
|
-
|
|
1556
|
+
J,
|
|
1570
1557
|
c.components,
|
|
1571
1558
|
"output",
|
|
1572
1559
|
F.with_null_state
|
|
1573
1560
|
),
|
|
1574
|
-
endpoint:
|
|
1561
|
+
endpoint: d,
|
|
1575
1562
|
fn_index: f,
|
|
1576
1563
|
event_data: s,
|
|
1577
1564
|
trigger_id: n
|
|
1578
|
-
}),
|
|
1565
|
+
}), D && (o({
|
|
1579
1566
|
type: "status",
|
|
1580
1567
|
time: /* @__PURE__ */ new Date(),
|
|
1581
|
-
...
|
|
1568
|
+
...D,
|
|
1582
1569
|
stage: k == null ? void 0 : k.stage,
|
|
1583
1570
|
queue: !0,
|
|
1584
|
-
endpoint:
|
|
1571
|
+
endpoint: d,
|
|
1585
1572
|
fn_index: f
|
|
1586
|
-
}),
|
|
1573
|
+
}), T == null || T.close(), a()));
|
|
1587
1574
|
};
|
|
1588
1575
|
} else if (j == "sse_v1" || j == "sse_v2" || j == "sse_v2.1" || j == "sse_v3") {
|
|
1589
1576
|
o({
|
|
1590
1577
|
type: "status",
|
|
1591
1578
|
stage: "pending",
|
|
1592
1579
|
queue: !0,
|
|
1593
|
-
endpoint:
|
|
1580
|
+
endpoint: d,
|
|
1594
1581
|
fn_index: f,
|
|
1595
1582
|
time: /* @__PURE__ */ new Date()
|
|
1596
1583
|
});
|
|
1597
1584
|
let y = "";
|
|
1598
1585
|
typeof window < "u" && typeof document < "u" && (y = (Y = window == null ? void 0 : window.location) == null ? void 0 : Y.hostname);
|
|
1599
1586
|
const q = y.includes(".dev.") ? `https://moon-${y.split(".")[1]}.dev.spaces.huggingface.tech` : "https://huggingface.co";
|
|
1600
|
-
(typeof window < "u" && typeof document < "u" && window.parent != window && window.supports_zerogpu_headers ?
|
|
1601
|
-
`${c.root}${
|
|
1587
|
+
(typeof window < "u" && typeof document < "u" && window.parent != window && window.supports_zerogpu_headers ? It("zerogpu-headers", q) : Promise.resolve(null)).then((v) => ae(
|
|
1588
|
+
`${c.root}${M}/${it}?${G}`,
|
|
1602
1589
|
{
|
|
1603
1590
|
...V,
|
|
1604
|
-
session_hash:
|
|
1591
|
+
session_hash: _
|
|
1605
1592
|
},
|
|
1606
1593
|
v
|
|
1607
|
-
)).then(async ([v,
|
|
1608
|
-
if (
|
|
1594
|
+
)).then(async ([v, O]) => {
|
|
1595
|
+
if (O === 503)
|
|
1609
1596
|
o({
|
|
1610
1597
|
type: "status",
|
|
1611
1598
|
stage: "error",
|
|
1612
|
-
message:
|
|
1599
|
+
message: xe,
|
|
1613
1600
|
queue: !0,
|
|
1614
|
-
endpoint:
|
|
1601
|
+
endpoint: d,
|
|
1615
1602
|
fn_index: f,
|
|
1616
1603
|
time: /* @__PURE__ */ new Date()
|
|
1617
1604
|
});
|
|
1618
|
-
else if (
|
|
1605
|
+
else if (O === 422)
|
|
1619
1606
|
o({
|
|
1620
1607
|
type: "status",
|
|
1621
1608
|
stage: "error",
|
|
1622
|
-
|
|
1623
|
-
message: M,
|
|
1609
|
+
message: v.detail,
|
|
1624
1610
|
queue: !0,
|
|
1625
|
-
endpoint:
|
|
1611
|
+
endpoint: d,
|
|
1612
|
+
fn_index: f,
|
|
1613
|
+
code: "validation_error",
|
|
1614
|
+
time: /* @__PURE__ */ new Date()
|
|
1615
|
+
}), a();
|
|
1616
|
+
else if (O !== 200)
|
|
1617
|
+
o({
|
|
1618
|
+
type: "status",
|
|
1619
|
+
stage: "error",
|
|
1620
|
+
broken: !1,
|
|
1621
|
+
message: v.detail,
|
|
1622
|
+
queue: !0,
|
|
1623
|
+
endpoint: d,
|
|
1626
1624
|
fn_index: f,
|
|
1627
1625
|
time: /* @__PURE__ */ new Date()
|
|
1628
1626
|
});
|
|
@@ -1630,33 +1628,33 @@ function ns(e, t = {}, s, n, i) {
|
|
|
1630
1628
|
S = v.event_id, ye = S;
|
|
1631
1629
|
let Ee = async function(ue) {
|
|
1632
1630
|
try {
|
|
1633
|
-
const { type: L, status: b, data: P, original_msg:
|
|
1631
|
+
const { type: L, status: b, data: P, original_msg: Ye } = he(
|
|
1634
1632
|
ue,
|
|
1635
1633
|
ce[f]
|
|
1636
1634
|
);
|
|
1637
1635
|
if (L == "heartbeat")
|
|
1638
1636
|
return;
|
|
1639
|
-
if (L === "update" && b && !
|
|
1637
|
+
if (L === "update" && b && !D)
|
|
1640
1638
|
o({
|
|
1641
1639
|
type: "status",
|
|
1642
|
-
endpoint:
|
|
1640
|
+
endpoint: d,
|
|
1643
1641
|
fn_index: f,
|
|
1644
1642
|
time: /* @__PURE__ */ new Date(),
|
|
1645
|
-
original_msg:
|
|
1643
|
+
original_msg: Ye,
|
|
1646
1644
|
...b
|
|
1647
1645
|
});
|
|
1648
1646
|
else if (L === "complete")
|
|
1649
|
-
|
|
1647
|
+
D = b;
|
|
1650
1648
|
else if (L == "unexpected_error" || L == "broken_connection") {
|
|
1651
1649
|
console.error("Unexpected error", b == null ? void 0 : b.message);
|
|
1652
|
-
const
|
|
1650
|
+
const et = L === "broken_connection";
|
|
1653
1651
|
o({
|
|
1654
1652
|
type: "status",
|
|
1655
1653
|
stage: "error",
|
|
1656
1654
|
message: (b == null ? void 0 : b.message) || "An Unexpected Error Occurred!",
|
|
1657
1655
|
queue: !0,
|
|
1658
|
-
endpoint:
|
|
1659
|
-
broken:
|
|
1656
|
+
endpoint: d,
|
|
1657
|
+
broken: et,
|
|
1660
1658
|
session_not_found: b == null ? void 0 : b.session_not_found,
|
|
1661
1659
|
fn_index: f,
|
|
1662
1660
|
time: /* @__PURE__ */ new Date()
|
|
@@ -1667,41 +1665,40 @@ function ns(e, t = {}, s, n, i) {
|
|
|
1667
1665
|
title: P.title,
|
|
1668
1666
|
log: P.log,
|
|
1669
1667
|
level: P.level,
|
|
1670
|
-
endpoint:
|
|
1668
|
+
endpoint: d,
|
|
1671
1669
|
duration: P.duration,
|
|
1672
1670
|
visible: P.visible,
|
|
1673
1671
|
fn_index: f
|
|
1674
1672
|
});
|
|
1675
1673
|
return;
|
|
1676
|
-
} else
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
}), P && W.connection !== "stream" && ["sse_v2", "sse_v2.1", "sse_v3"].includes(j) && Yt(oe, S, P));
|
|
1674
|
+
} else (L === "generating" || L === "streaming") && (o({
|
|
1675
|
+
type: "status",
|
|
1676
|
+
time: /* @__PURE__ */ new Date(),
|
|
1677
|
+
...b,
|
|
1678
|
+
stage: b == null ? void 0 : b.stage,
|
|
1679
|
+
queue: !0,
|
|
1680
|
+
endpoint: d,
|
|
1681
|
+
fn_index: f
|
|
1682
|
+
}), P && J.connection !== "stream" && ["sse_v2", "sse_v2.1", "sse_v3"].includes(j) && es(oe, S, P));
|
|
1686
1683
|
P && (o({
|
|
1687
1684
|
type: "data",
|
|
1688
1685
|
time: /* @__PURE__ */ new Date(),
|
|
1689
1686
|
data: K(
|
|
1690
1687
|
P.data,
|
|
1691
|
-
|
|
1688
|
+
J,
|
|
1692
1689
|
c.components,
|
|
1693
1690
|
"output",
|
|
1694
1691
|
F.with_null_state
|
|
1695
1692
|
),
|
|
1696
|
-
endpoint:
|
|
1693
|
+
endpoint: d,
|
|
1697
1694
|
fn_index: f
|
|
1698
|
-
}), P.render_config && await be(P.render_config),
|
|
1695
|
+
}), P.render_config && await be(P.render_config), D && (o({
|
|
1699
1696
|
type: "status",
|
|
1700
1697
|
time: /* @__PURE__ */ new Date(),
|
|
1701
|
-
...
|
|
1698
|
+
...D,
|
|
1702
1699
|
stage: b == null ? void 0 : b.stage,
|
|
1703
1700
|
queue: !0,
|
|
1704
|
-
endpoint:
|
|
1701
|
+
endpoint: d,
|
|
1705
1702
|
fn_index: f
|
|
1706
1703
|
}), 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]);
|
|
1707
1704
|
} catch (L) {
|
|
@@ -1710,40 +1707,40 @@ function ns(e, t = {}, s, n, i) {
|
|
|
1710
1707
|
stage: "error",
|
|
1711
1708
|
message: "An Unexpected Error Occurred!",
|
|
1712
1709
|
queue: !0,
|
|
1713
|
-
endpoint:
|
|
1710
|
+
endpoint: d,
|
|
1714
1711
|
fn_index: f,
|
|
1715
1712
|
time: /* @__PURE__ */ new Date()
|
|
1716
|
-
}), ["sse_v2", "sse_v2.1", "sse_v3"].includes(j) && (ge(ne,
|
|
1713
|
+
}), ["sse_v2", "sse_v2.1", "sse_v3"].includes(j) && (ge(ne, We.abort_controller), ne.open = !1, a());
|
|
1717
1714
|
}
|
|
1718
1715
|
};
|
|
1719
1716
|
S in ie && (ie[S].forEach(
|
|
1720
1717
|
(ue) => Ee(ue)
|
|
1721
|
-
), delete ie[S]), re[S] = Ee,
|
|
1718
|
+
), delete ie[S]), re[S] = Ee, Je.add(S), ne.open || await this.open_stream();
|
|
1722
1719
|
}
|
|
1723
1720
|
});
|
|
1724
1721
|
}
|
|
1725
1722
|
}
|
|
1726
1723
|
);
|
|
1727
|
-
let
|
|
1724
|
+
let Xe = !1;
|
|
1728
1725
|
const le = [], Z = [], ve = {
|
|
1729
1726
|
[Symbol.asyncIterator]: () => ve,
|
|
1730
1727
|
next: p,
|
|
1731
1728
|
throw: async (w) => (h(w), p()),
|
|
1732
1729
|
return: async () => (a(), p()),
|
|
1733
|
-
cancel:
|
|
1734
|
-
event_id:
|
|
1730
|
+
cancel: Ke,
|
|
1731
|
+
event_id: Ve
|
|
1735
1732
|
};
|
|
1736
1733
|
return ve;
|
|
1737
1734
|
} catch (o) {
|
|
1738
1735
|
throw console.error("Submit function encountered an error:", o), o;
|
|
1739
1736
|
}
|
|
1740
1737
|
}
|
|
1741
|
-
function
|
|
1738
|
+
function os(e) {
|
|
1742
1739
|
return {
|
|
1743
1740
|
then: (t, s) => s(e)
|
|
1744
1741
|
};
|
|
1745
1742
|
}
|
|
1746
|
-
function
|
|
1743
|
+
function rs(e, t, s, n) {
|
|
1747
1744
|
let i, r, o;
|
|
1748
1745
|
if (typeof t == "number")
|
|
1749
1746
|
i = t, r = e.unnamed_endpoints[i], o = n.dependencies.find((a) => a.id == t);
|
|
@@ -1795,7 +1792,7 @@ class ee {
|
|
|
1795
1792
|
u(this, "resolve_config");
|
|
1796
1793
|
u(this, "resolve_cookies");
|
|
1797
1794
|
var n;
|
|
1798
|
-
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 =
|
|
1795
|
+
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 = At.bind(this), this.upload_files = Lt.bind(this), this.handle_blob = Ut.bind(this), this.post_data = Bt.bind(this), this.submit = is.bind(this), this.predict = Ft.bind(this), this.open_stream = Yt.bind(this), this.resolve_config = $t.bind(this), this.resolve_cookies = Rt.bind(this), this.upload = Pt.bind(this), this.fetch = this.fetch.bind(this), this.handle_space_success = this.handle_space_success.bind(this), this.stream = this.stream.bind(this);
|
|
1799
1796
|
}
|
|
1800
1797
|
get_url_config(t = null) {
|
|
1801
1798
|
if (!this.config)
|
|
@@ -1833,7 +1830,7 @@ class ee {
|
|
|
1833
1830
|
if (this && this.cookies && s.append("Cookie", this.cookies), this && this.options.headers)
|
|
1834
1831
|
for (const n in this.options.headers)
|
|
1835
1832
|
s.append(n, this.options.headers[n]);
|
|
1836
|
-
return this && this.options.hf_token && s.append("Authorization", `Bearer ${this.options.hf_token}`), this.abort_controller = new AbortController(), this.stream_instance =
|
|
1833
|
+
return this && this.options.hf_token && s.append("Authorization", `Bearer ${this.options.hf_token}`), this.abort_controller = new AbortController(), this.stream_instance = ns(t.toString(), {
|
|
1837
1834
|
credentials: "include",
|
|
1838
1835
|
headers: s,
|
|
1839
1836
|
signal: this.abort_controller.signal
|
|
@@ -1843,16 +1840,16 @@ class ee {
|
|
|
1843
1840
|
var t;
|
|
1844
1841
|
this.options.auth && await this.resolve_cookies(), await this._resolve_config().then(
|
|
1845
1842
|
({ config: s }) => this._resolve_heartbeat(s)
|
|
1846
|
-
), this.api_info = await this.view_api(), this.api_map =
|
|
1843
|
+
), this.api_info = await this.view_api(), this.api_map = St(((t = this.config) == null ? void 0 : t.dependencies) || []);
|
|
1847
1844
|
}
|
|
1848
1845
|
async _resolve_heartbeat(t) {
|
|
1849
|
-
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
|
|
1846
|
+
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(
|
|
1850
1847
|
this.config.space_id,
|
|
1851
1848
|
this.options.hf_token,
|
|
1852
1849
|
this.cookies
|
|
1853
|
-
))), t.space_id && this.options.hf_token && (this.jwt = await
|
|
1850
|
+
))), t.space_id && this.options.hf_token && (this.jwt = await Te(t.space_id, this.options.hf_token)), this.config && this.config.connect_heartbeat) {
|
|
1854
1851
|
const s = new URL(
|
|
1855
|
-
`${this.config.root}${this.api_prefix}/${
|
|
1852
|
+
`${this.config.root}${this.api_prefix}/${lt}/${this.session_hash}`
|
|
1856
1853
|
);
|
|
1857
1854
|
this.jwt && s.searchParams.set("__sign", this.jwt), this.heartbeat_event || (this.heartbeat_event = this.stream(s));
|
|
1858
1855
|
}
|
|
@@ -1865,7 +1862,7 @@ class ee {
|
|
|
1865
1862
|
}
|
|
1866
1863
|
async reconnect() {
|
|
1867
1864
|
const t = new URL(
|
|
1868
|
-
`${this.config.root}${this.api_prefix}/${
|
|
1865
|
+
`${this.config.root}${this.api_prefix}/${ht}`
|
|
1869
1866
|
);
|
|
1870
1867
|
let s;
|
|
1871
1868
|
try {
|
|
@@ -1887,14 +1884,14 @@ class ee {
|
|
|
1887
1884
|
static async duplicate(t, s = {
|
|
1888
1885
|
events: ["data"]
|
|
1889
1886
|
}) {
|
|
1890
|
-
return
|
|
1887
|
+
return Wt(t, s);
|
|
1891
1888
|
}
|
|
1892
1889
|
async _resolve_config() {
|
|
1893
1890
|
const { http_protocol: t, host: s, space_id: n } = await te(
|
|
1894
1891
|
this.app_reference,
|
|
1895
1892
|
this.options.hf_token
|
|
1896
1893
|
), { status_callback: i } = this.options;
|
|
1897
|
-
n && i && await
|
|
1894
|
+
n && i && await Me(n, i);
|
|
1898
1895
|
let r;
|
|
1899
1896
|
try {
|
|
1900
1897
|
let o = `${t}//${s}`;
|
|
@@ -1923,7 +1920,7 @@ class ee {
|
|
|
1923
1920
|
try {
|
|
1924
1921
|
this.api_info = await this.view_api();
|
|
1925
1922
|
} catch (s) {
|
|
1926
|
-
console.error(
|
|
1923
|
+
console.error(mt + s.message);
|
|
1927
1924
|
}
|
|
1928
1925
|
return this.prepare_return_obj();
|
|
1929
1926
|
}
|
|
@@ -1972,7 +1969,7 @@ class ee {
|
|
|
1972
1969
|
r && (i.Authorization = `Bearer ${r}`);
|
|
1973
1970
|
try {
|
|
1974
1971
|
const p = await this.fetch(
|
|
1975
|
-
`${a}${this.api_prefix}/${
|
|
1972
|
+
`${a}${this.api_prefix}/${ut}/`,
|
|
1976
1973
|
{
|
|
1977
1974
|
method: "POST",
|
|
1978
1975
|
body: h,
|
|
@@ -1990,7 +1987,7 @@ class ee {
|
|
|
1990
1987
|
}
|
|
1991
1988
|
}
|
|
1992
1989
|
set_cookies(t) {
|
|
1993
|
-
this.cookies =
|
|
1990
|
+
this.cookies = ze(t).join("; ");
|
|
1994
1991
|
}
|
|
1995
1992
|
prepare_return_obj() {
|
|
1996
1993
|
return {
|
|
@@ -2035,24 +2032,24 @@ class ee {
|
|
|
2035
2032
|
}
|
|
2036
2033
|
}
|
|
2037
2034
|
}
|
|
2038
|
-
async function
|
|
2035
|
+
async function us(e, t = {
|
|
2039
2036
|
events: ["data"]
|
|
2040
2037
|
}) {
|
|
2041
2038
|
return await ee.connect(e, t);
|
|
2042
2039
|
}
|
|
2043
|
-
async function
|
|
2040
|
+
async function ps(e, t) {
|
|
2044
2041
|
return await ee.duplicate(e, t);
|
|
2045
2042
|
}
|
|
2046
2043
|
export {
|
|
2047
2044
|
ee as Client,
|
|
2048
2045
|
se as FileData,
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2046
|
+
yt as MISSING_CREDENTIALS_MSG,
|
|
2047
|
+
us as client,
|
|
2048
|
+
ps as duplicate,
|
|
2049
|
+
ls as handle_file,
|
|
2050
|
+
Ft as predict,
|
|
2051
|
+
cs as prepare_files,
|
|
2052
|
+
is as submit,
|
|
2053
|
+
Pt as upload,
|
|
2054
|
+
Lt as upload_files
|
|
2058
2055
|
};
|