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