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