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