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