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