@gradio/client 2.4.0 → 2.5.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/dist/browser.js +567 -340
- package/dist/client.d.ts.map +1 -1
- package/dist/index.cjs +312 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +306 -3
- package/dist/index.min.js +570 -343
- package/dist/types.d.ts +14 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/run_history.d.ts +64 -0
- package/dist/utils/run_history.d.ts.map +1 -0
- package/dist/utils/submit.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +10 -0
- package/src/index.ts +12 -0
- package/src/test/run_history.test.ts +345 -0
- package/src/types.ts +14 -0
- package/src/utils/run_history.ts +520 -0
- package/src/utils/submit.ts +62 -2
package/dist/browser.js
CHANGED
|
@@ -8,10 +8,10 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
|
|
|
8
8
|
}, c = (n, r, a) => (a = n == null ? {} : e(i(n)), s(r || !n || !n.__esModule ? t(a, "default", {
|
|
9
9
|
value: n,
|
|
10
10
|
enumerable: !0
|
|
11
|
-
}) : a, n)), l = "host", u = "queue/data", d = "queue/join", f = "upload", p = "login", m = "config", h = "info", g = "runtime",
|
|
11
|
+
}) : a, n)), l = "host", u = "queue/data", d = "queue/join", f = "upload", p = "login", m = "config", h = "info", g = "runtime", ee = "sleeptime", _ = "heartbeat", te = "component_server", ne = "reset", re = "cancel", v = "app_id", ie = "This application is currently busy. Please try again. ", y = "Connection errored out. ", b = "Could not resolve app config. ", x = "Could not get space status. ", S = "Could not get API info. ", C = "Space metadata could not be loaded. ", w = "Invalid URL. A full URL path is required.", T = "Not authorized to access this space. ", E = "Invalid credentials. Could not login. ", ae = "Login credentials are required to access this space.", D = "Could not access this app (received a 401 response). If it is a private Hugging Face Space, pass a valid Hugging Face token to the `token` option of `Client.connect`. You can generate a token at https://huggingface.co/settings/tokens.", oe = (e, t) => `Space "${e}" could not be accessed (received a ${t} response from the Hugging Face API). Check that the Space name is spelled correctly and that the Space exists. If the Space is private, pass a valid Hugging Face token to the \`token\` option of \`Client.connect\`. You can generate a token at https://huggingface.co/settings/tokens.`, se = "No API information is available for this app. This can happen when the app's `/info` endpoint cannot be reached, or when the app is running a legacy version of Gradio that is not supported by this client. ", ce = "This app appears to be running a legacy version of Gradio (3.x or earlier) that communicates over WebSockets, which is not supported by this version of @gradio/client. Please upgrade the app to a newer version of Gradio, or connect to it with @gradio/client version 0.x.", le = "File system access is only available in Node.js environments", O = "Root URL not found in client config", ue = "Error uploading file";
|
|
12
12
|
//#endregion
|
|
13
13
|
//#region src/helpers/init_helpers.ts
|
|
14
|
-
async function
|
|
14
|
+
async function de(e, t, n) {
|
|
15
15
|
try {
|
|
16
16
|
return (await (await fetch(`https://huggingface.co/api/spaces/${e}/jwt`, { headers: {
|
|
17
17
|
Authorization: `Bearer ${t}`,
|
|
@@ -21,24 +21,24 @@ async function N(e, t, n) {
|
|
|
21
21
|
return !1;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
function
|
|
24
|
+
function k(e) {
|
|
25
25
|
e.hf_token && !e.token && (e.token = e.hf_token, console.warn("The `hf_token` option has been renamed to `token`. Support for `hf_token` will be removed in a future version of @gradio/client."));
|
|
26
26
|
}
|
|
27
|
-
function
|
|
27
|
+
function fe(e) {
|
|
28
28
|
let t = {};
|
|
29
29
|
return e.forEach(({ api_name: e, id: n }) => {
|
|
30
30
|
e && (t[e] = n);
|
|
31
31
|
}), t;
|
|
32
32
|
}
|
|
33
|
-
function
|
|
33
|
+
function A(e, t) {
|
|
34
34
|
let n = new URL(e, t), r = new URL(t);
|
|
35
35
|
return n.hostname === r.hostname ? (n.protocol = r.protocol, n.host = r.host, n.toString().replace(/\/$/, "")) : e;
|
|
36
36
|
}
|
|
37
|
-
async function
|
|
37
|
+
async function j(e, t = !0) {
|
|
38
38
|
let n = this.options.token ? { Authorization: `Bearer ${this.options.token}` } : {};
|
|
39
39
|
if (typeof window < "u" && window.gradio_config && location.origin !== "http://localhost:9876") {
|
|
40
40
|
if (t && window.gradio_config.current_page && (e = e.substring(0, e.lastIndexOf("/"))), window.gradio_config.dev_mode || typeof window < "u" && window?.BUILD_MODE === "dev") {
|
|
41
|
-
let t =
|
|
41
|
+
let t = me(e, this.deep_link ? m + "?deep_link=" + this.deep_link : m), r = await M(await this.fetch(t, {
|
|
42
42
|
headers: n,
|
|
43
43
|
credentials: this.options.credentials ?? "same-origin"
|
|
44
44
|
}), !!this.options.auth);
|
|
@@ -48,47 +48,47 @@ async function se(e, t = !0) {
|
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
let r = { ...window.gradio_config };
|
|
51
|
-
return r.root =
|
|
51
|
+
return r.root = A(r.root, location.href), r;
|
|
52
52
|
} else if (e) {
|
|
53
|
-
let t =
|
|
53
|
+
let t = me(e, this.deep_link ? m + "?deep_link=" + this.deep_link : m), r = await M(await this.fetch(t, {
|
|
54
54
|
headers: n,
|
|
55
55
|
credentials: this.options.credentials ?? "same-origin"
|
|
56
56
|
}), !!this.options.auth);
|
|
57
57
|
return r.root ||= e, r;
|
|
58
58
|
}
|
|
59
|
-
throw Error(
|
|
59
|
+
throw Error(b);
|
|
60
60
|
}
|
|
61
|
-
async function
|
|
61
|
+
async function M(e, t) {
|
|
62
62
|
if (e?.status === 401 && !t) {
|
|
63
63
|
let t = null;
|
|
64
64
|
try {
|
|
65
65
|
t = await e.json();
|
|
66
66
|
} catch {
|
|
67
|
-
throw Error(
|
|
67
|
+
throw Error(D);
|
|
68
68
|
}
|
|
69
69
|
let n = t?.detail?.auth_message;
|
|
70
70
|
throw Error(n || "Login credentials are required to access this space.");
|
|
71
|
-
} else if (e?.status === 401 && t) throw Error(
|
|
71
|
+
} else if (e?.status === 401 && t) throw Error(E);
|
|
72
72
|
if (e?.status === 200) {
|
|
73
73
|
let t = await e.json();
|
|
74
74
|
return t.dependencies?.forEach((e, t) => {
|
|
75
75
|
e.id === void 0 && (e.id = t);
|
|
76
76
|
}), t;
|
|
77
|
-
} else if (e?.status === 401) throw Error(
|
|
78
|
-
throw Error(`${
|
|
77
|
+
} else if (e?.status === 401) throw Error(T);
|
|
78
|
+
throw Error(`${b}(received status ${e?.status} when fetching the app config)`);
|
|
79
79
|
}
|
|
80
|
-
async function
|
|
81
|
-
let { http_protocol: e, host: t } = await
|
|
80
|
+
async function N() {
|
|
81
|
+
let { http_protocol: e, host: t } = await R(this.app_reference, this.options.token);
|
|
82
82
|
try {
|
|
83
83
|
if (this.options.auth) {
|
|
84
|
-
let n = await
|
|
84
|
+
let n = await P(e, t, this.options.auth, this.fetch, this.options.token, this.options.credentials);
|
|
85
85
|
n && this.set_cookies(n);
|
|
86
86
|
}
|
|
87
87
|
} catch (e) {
|
|
88
88
|
throw Error(e.message);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
|
-
async function
|
|
91
|
+
async function P(e, t, n, r, i, a) {
|
|
92
92
|
let o = new FormData();
|
|
93
93
|
o.append("username", n?.[0]), o.append("password", n?.[1]);
|
|
94
94
|
let s = {};
|
|
@@ -100,9 +100,9 @@ async function R(e, t, n, r, i, a) {
|
|
|
100
100
|
credentials: a ?? "same-origin"
|
|
101
101
|
});
|
|
102
102
|
if (c.status === 200) return c.headers.get("set-cookie");
|
|
103
|
-
throw c.status === 401 ? Error(
|
|
103
|
+
throw c.status === 401 ? Error(E) : Error(C);
|
|
104
104
|
}
|
|
105
|
-
function
|
|
105
|
+
function F(e) {
|
|
106
106
|
if (e.startsWith("http")) {
|
|
107
107
|
let { protocol: t, host: n, pathname: r } = new URL(e);
|
|
108
108
|
return {
|
|
@@ -117,39 +117,39 @@ function z(e) {
|
|
|
117
117
|
host: new URL(e).host
|
|
118
118
|
};
|
|
119
119
|
}
|
|
120
|
-
var
|
|
120
|
+
var I = (e) => {
|
|
121
121
|
let t = [];
|
|
122
122
|
return e.split(/,(?=\s*[^\s=;]+=[^\s=;]+)/).forEach((e) => {
|
|
123
123
|
let [n, r] = e.split(";")[0].split("=");
|
|
124
124
|
n && r && t.push(`${n.trim()}=${r.trim()}`);
|
|
125
125
|
}), t;
|
|
126
|
-
},
|
|
127
|
-
async function
|
|
126
|
+
}, L = /^[a-zA-Z0-9_\-\.]+\/[a-zA-Z0-9_\-\.]+$/, pe = /.*hf\.space\/{0,1}.*$/;
|
|
127
|
+
async function R(e, t) {
|
|
128
128
|
let n = {};
|
|
129
129
|
t && (n.Authorization = `Bearer ${t}`);
|
|
130
130
|
let r = e.trim().replace(/\/$/, "");
|
|
131
|
-
if (
|
|
131
|
+
if (L.test(r)) {
|
|
132
132
|
let e;
|
|
133
133
|
try {
|
|
134
134
|
e = await fetch(`https://huggingface.co/api/spaces/${r}/${l}`, { headers: n });
|
|
135
135
|
} catch {
|
|
136
|
-
throw Error(
|
|
136
|
+
throw Error(C);
|
|
137
137
|
}
|
|
138
|
-
if (e.status === 401 || e.status === 404) throw Error(
|
|
138
|
+
if (e.status === 401 || e.status === 404) throw Error(oe(r, e.status));
|
|
139
139
|
let t;
|
|
140
140
|
try {
|
|
141
141
|
t = (await e.json()).host;
|
|
142
142
|
} catch {
|
|
143
|
-
throw Error(
|
|
143
|
+
throw Error(C);
|
|
144
144
|
}
|
|
145
|
-
if (!t) throw Error(
|
|
145
|
+
if (!t) throw Error(C);
|
|
146
146
|
return {
|
|
147
147
|
space_id: r,
|
|
148
|
-
...
|
|
148
|
+
...F(t)
|
|
149
149
|
};
|
|
150
150
|
}
|
|
151
|
-
if (
|
|
152
|
-
let { ws_protocol: e, http_protocol: t, host: n } =
|
|
151
|
+
if (pe.test(r)) {
|
|
152
|
+
let { ws_protocol: e, http_protocol: t, host: n } = F(r);
|
|
153
153
|
return {
|
|
154
154
|
space_id: n.split("/")[0].replace(".hf.space", ""),
|
|
155
155
|
ws_protocol: e,
|
|
@@ -159,17 +159,17 @@ async function U(e, t) {
|
|
|
159
159
|
}
|
|
160
160
|
return {
|
|
161
161
|
space_id: !1,
|
|
162
|
-
...
|
|
162
|
+
...F(r)
|
|
163
163
|
};
|
|
164
164
|
}
|
|
165
|
-
var
|
|
165
|
+
var me = (...e) => {
|
|
166
166
|
try {
|
|
167
167
|
return e.reduce((e, t) => (e = e.replace(/\/+$/, ""), t = t.replace(/^\/+/, ""), new URL(t, e + "/").toString()));
|
|
168
168
|
} catch {
|
|
169
|
-
throw Error(
|
|
169
|
+
throw Error(w);
|
|
170
170
|
}
|
|
171
171
|
};
|
|
172
|
-
function
|
|
172
|
+
function he(e, t, n) {
|
|
173
173
|
let r = {
|
|
174
174
|
named_endpoints: {},
|
|
175
175
|
unnamed_endpoints: {}
|
|
@@ -199,8 +199,8 @@ function G(e, t, n) {
|
|
|
199
199
|
}
|
|
200
200
|
let d = (e, t, n, r) => ({
|
|
201
201
|
...e,
|
|
202
|
-
description:
|
|
203
|
-
type:
|
|
202
|
+
description: _e(e?.type, n),
|
|
203
|
+
type: ge(e?.type, t, n, r) || ""
|
|
204
204
|
});
|
|
205
205
|
r[i][e] = {
|
|
206
206
|
parameters: o.map((e) => d(e, e?.component, e?.serializer, "parameter")),
|
|
@@ -211,7 +211,7 @@ function G(e, t, n) {
|
|
|
211
211
|
}));
|
|
212
212
|
}), r;
|
|
213
213
|
}
|
|
214
|
-
function
|
|
214
|
+
function ge(e, t, n, r) {
|
|
215
215
|
if (t === "Api") return e.type;
|
|
216
216
|
switch (e?.type) {
|
|
217
217
|
case "string": return "string";
|
|
@@ -224,10 +224,10 @@ function le(e, t, n, r) {
|
|
|
224
224
|
if (n === "FileSerializable") return e?.type === "array" ? r === "parameter" ? "(Blob | File | Buffer)[]" : "{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}[]" : r === "parameter" ? "Blob | File | Buffer" : "{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}";
|
|
225
225
|
if (n === "GallerySerializable") return r === "parameter" ? "[(Blob | File | Buffer), (string | null)][]" : "[{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}, (string | null))][]";
|
|
226
226
|
}
|
|
227
|
-
function
|
|
227
|
+
function _e(e, t) {
|
|
228
228
|
return t === "GallerySerializable" ? "array of [file, label] tuples" : t === "ListStringSerializable" ? "array of strings" : t === "FileSerializable" ? "array of files or single file" : e?.description;
|
|
229
229
|
}
|
|
230
|
-
function
|
|
230
|
+
function ve(e, t) {
|
|
231
231
|
switch (e.msg) {
|
|
232
232
|
case "send_data": return { type: "data" };
|
|
233
233
|
case "send_hash": return { type: "hash" };
|
|
@@ -235,7 +235,7 @@ function de(e, t) {
|
|
|
235
235
|
type: "update",
|
|
236
236
|
status: {
|
|
237
237
|
queue: !0,
|
|
238
|
-
message:
|
|
238
|
+
message: ie,
|
|
239
239
|
stage: "error",
|
|
240
240
|
code: e.code,
|
|
241
241
|
success: e.success
|
|
@@ -363,7 +363,7 @@ function de(e, t) {
|
|
|
363
363
|
}
|
|
364
364
|
};
|
|
365
365
|
}
|
|
366
|
-
var
|
|
366
|
+
var ye = (e = [], t) => {
|
|
367
367
|
let n = t ? t.parameters : [];
|
|
368
368
|
if (Array.isArray(e)) return t && n.length > 0 && e.length > n.length && console.warn("Too many arguments provided for the endpoint."), e;
|
|
369
369
|
let r = [], i = Object.keys(e);
|
|
@@ -379,28 +379,28 @@ var fe = (e = [], t) => {
|
|
|
379
379
|
};
|
|
380
380
|
//#endregion
|
|
381
381
|
//#region src/utils/view_api.ts
|
|
382
|
-
async function
|
|
382
|
+
async function be() {
|
|
383
383
|
if (this.api_info) return this.api_info;
|
|
384
384
|
let { token: e } = this.options, { config: t } = this, n = {};
|
|
385
385
|
if (e && (n.Authorization = `Bearer ${e}`), t) try {
|
|
386
386
|
let e, r;
|
|
387
387
|
if (typeof window < "u" && window.gradio_api_info) r = window.gradio_api_info;
|
|
388
388
|
else {
|
|
389
|
-
let i =
|
|
389
|
+
let i = me(t.root, this.api_prefix, h);
|
|
390
390
|
if (e = await this.fetch(i, {
|
|
391
391
|
headers: n,
|
|
392
392
|
credentials: this.options.credentials ?? "same-origin"
|
|
393
|
-
}), !e.ok) throw Error(
|
|
393
|
+
}), !e.ok) throw Error(y);
|
|
394
394
|
r = await e.json();
|
|
395
395
|
}
|
|
396
|
-
return "api" in r && (r = r.api), r.named_endpoints["/predict"] && !r.unnamed_endpoints[0] && (r.unnamed_endpoints[0] = r.named_endpoints["/predict"]),
|
|
396
|
+
return "api" in r && (r = r.api), r.named_endpoints["/predict"] && !r.unnamed_endpoints[0] && (r.unnamed_endpoints[0] = r.named_endpoints["/predict"]), he(r, t, this.api_map);
|
|
397
397
|
} catch (e) {
|
|
398
398
|
throw Error("Could not get API info. " + e.message);
|
|
399
399
|
}
|
|
400
400
|
}
|
|
401
401
|
//#endregion
|
|
402
402
|
//#region src/utils/upload_files.ts
|
|
403
|
-
async function
|
|
403
|
+
async function z(e, t, n) {
|
|
404
404
|
let r = {};
|
|
405
405
|
this?.options?.token && (r.Authorization = `Bearer ${this.options.token}`);
|
|
406
406
|
let i = 1e3, a = [], o;
|
|
@@ -418,7 +418,7 @@ async function q(e, t, n) {
|
|
|
418
418
|
credentials: this.options.credentials ?? "same-origin"
|
|
419
419
|
});
|
|
420
420
|
} catch (e) {
|
|
421
|
-
throw Error(
|
|
421
|
+
throw Error(y + e.message);
|
|
422
422
|
}
|
|
423
423
|
if (!o.ok) {
|
|
424
424
|
let e = await o.text();
|
|
@@ -429,7 +429,7 @@ async function q(e, t, n) {
|
|
|
429
429
|
}
|
|
430
430
|
return { files: a };
|
|
431
431
|
}
|
|
432
|
-
var
|
|
432
|
+
var B = {
|
|
433
433
|
si: {
|
|
434
434
|
radix: 1e3,
|
|
435
435
|
unit: [
|
|
@@ -473,28 +473,28 @@ var pe = {
|
|
|
473
473
|
]
|
|
474
474
|
}
|
|
475
475
|
};
|
|
476
|
-
function
|
|
476
|
+
function V(e, t = 1, n = "jedec") {
|
|
477
477
|
e = Math.abs(e);
|
|
478
|
-
let { radix: r, unit: i } =
|
|
478
|
+
let { radix: r, unit: i } = B[n] || B.jedec, a = 0;
|
|
479
479
|
for (; e >= r;) e /= r, ++a;
|
|
480
480
|
return `${e.toFixed(t)} ${i[a]}`;
|
|
481
481
|
}
|
|
482
482
|
//#endregion
|
|
483
483
|
//#region src/upload.ts
|
|
484
|
-
async function
|
|
484
|
+
async function H(e, t, n, r) {
|
|
485
485
|
let i = (Array.isArray(e) ? e : [e]).map((e) => e.blob), a = i.filter((e) => e.size > (r ?? Infinity));
|
|
486
|
-
if (a.length) throw Error(`File(s) exceed the maximum allowed size of ${
|
|
486
|
+
if (a.length) throw Error(`File(s) exceed the maximum allowed size of ${V(r || Infinity)}: ${a.map((e) => `"${e.name}"`).join(", ")}`);
|
|
487
487
|
return await Promise.all(await this.upload_files(t, i, n).then(async (n) => {
|
|
488
488
|
if (n.error) throw Error(n.error);
|
|
489
|
-
return n.files ? n.files.map((n, r) => new
|
|
489
|
+
return n.files ? n.files.map((n, r) => new U({
|
|
490
490
|
...e[r],
|
|
491
491
|
path: n,
|
|
492
492
|
url: `${t}${this.api_prefix}/file=${n}`
|
|
493
493
|
})) : [];
|
|
494
494
|
}));
|
|
495
495
|
}
|
|
496
|
-
async function
|
|
497
|
-
return e.map((e) => new
|
|
496
|
+
async function xe(e, t) {
|
|
497
|
+
return e.map((e) => new U({
|
|
498
498
|
path: e.name,
|
|
499
499
|
orig_name: e.name,
|
|
500
500
|
blob: e,
|
|
@@ -503,7 +503,7 @@ async function ge(e, t) {
|
|
|
503
503
|
is_stream: t
|
|
504
504
|
}));
|
|
505
505
|
}
|
|
506
|
-
var
|
|
506
|
+
var U = class {
|
|
507
507
|
path;
|
|
508
508
|
url;
|
|
509
509
|
orig_name;
|
|
@@ -517,7 +517,7 @@ var J = class {
|
|
|
517
517
|
constructor({ path: e, url: t, orig_name: n, size: r, blob: i, is_stream: a, mime_type: o, alt_text: s, b64: c }) {
|
|
518
518
|
this.path = e, this.url = t, this.orig_name = n, this.size = r, this.blob = t ? void 0 : i, this.is_stream = a, this.mime_type = o, this.alt_text = s, this.b64 = c;
|
|
519
519
|
}
|
|
520
|
-
},
|
|
520
|
+
}, W = class {
|
|
521
521
|
type;
|
|
522
522
|
command;
|
|
523
523
|
meta;
|
|
@@ -525,8 +525,8 @@ var J = class {
|
|
|
525
525
|
constructor(e, t) {
|
|
526
526
|
this.type = "command", this.command = e, this.meta = t;
|
|
527
527
|
}
|
|
528
|
-
},
|
|
529
|
-
function
|
|
528
|
+
}, Se = typeof process < "u" && process.versions && process.versions.node;
|
|
529
|
+
function Ce(e, t, n) {
|
|
530
530
|
for (; n.length > 1;) {
|
|
531
531
|
let t = n.shift();
|
|
532
532
|
if (typeof t == "string" || typeof t == "number") e = e[t];
|
|
@@ -536,13 +536,13 @@ function ye(e, t, n) {
|
|
|
536
536
|
if (typeof r == "string" || typeof r == "number") e[r] = t;
|
|
537
537
|
else throw Error("Invalid key type");
|
|
538
538
|
}
|
|
539
|
-
async function
|
|
539
|
+
async function we(e, t = void 0, n = [], r = !1, i = void 0) {
|
|
540
540
|
if (Array.isArray(e)) {
|
|
541
541
|
let a = [];
|
|
542
542
|
return await Promise.all(e.map(async (o, s) => {
|
|
543
543
|
let c = n.slice();
|
|
544
544
|
c.push(String(s));
|
|
545
|
-
let l = await
|
|
545
|
+
let l = await we(e[s], r ? i?.parameters[s]?.component || void 0 : t, c, !1, i);
|
|
546
546
|
a = a.concat(l);
|
|
547
547
|
})), a;
|
|
548
548
|
} else if (globalThis.Buffer && e instanceof globalThis.Buffer || e instanceof Blob) return [{
|
|
@@ -554,17 +554,17 @@ async function Y(e, t = void 0, n = [], r = !1, i = void 0) {
|
|
|
554
554
|
let t = [];
|
|
555
555
|
for (let r of Object.keys(e)) {
|
|
556
556
|
let a = [...n, r], o = e[r];
|
|
557
|
-
t = t.concat(await
|
|
557
|
+
t = t.concat(await we(o, void 0, a, !1, i));
|
|
558
558
|
}
|
|
559
559
|
return t;
|
|
560
560
|
}
|
|
561
561
|
return [];
|
|
562
562
|
}
|
|
563
|
-
function
|
|
563
|
+
function Te(e, t) {
|
|
564
564
|
let n = t?.dependencies?.find((t) => t.id == e)?.queue;
|
|
565
565
|
return n == null ? !t.enable_queue : !n;
|
|
566
566
|
}
|
|
567
|
-
function
|
|
567
|
+
function Ee(e, t) {
|
|
568
568
|
return new Promise((n, r) => {
|
|
569
569
|
let i = new MessageChannel();
|
|
570
570
|
i.port1.onmessage = (({ data: e }) => {
|
|
@@ -572,7 +572,7 @@ function xe(e, t) {
|
|
|
572
572
|
}), window.parent.postMessage(e, t, [i.port2]);
|
|
573
573
|
});
|
|
574
574
|
}
|
|
575
|
-
function
|
|
575
|
+
function De(e) {
|
|
576
576
|
if (typeof e == "string") {
|
|
577
577
|
if (e.startsWith("http://") || e.startsWith("https://")) return {
|
|
578
578
|
path: e,
|
|
@@ -580,7 +580,7 @@ function Se(e) {
|
|
|
580
580
|
orig_name: e.split("/").pop() ?? "unknown",
|
|
581
581
|
meta: { _type: "gradio.FileData" }
|
|
582
582
|
};
|
|
583
|
-
if (
|
|
583
|
+
if (Se) return new W("upload_file", {
|
|
584
584
|
path: e,
|
|
585
585
|
name: e,
|
|
586
586
|
orig_path: e
|
|
@@ -590,7 +590,7 @@ function Se(e) {
|
|
|
590
590
|
else if (e instanceof Blob) return e;
|
|
591
591
|
throw Error("Invalid input: must be a URL, File, Blob, or Buffer object.");
|
|
592
592
|
}
|
|
593
|
-
function
|
|
593
|
+
function G(e, t, n, r, i = !1) {
|
|
594
594
|
if (r === "input" && !i) throw Error("Invalid code path. Cannot skip state inputs for input.");
|
|
595
595
|
if (r === "output" && i) return e;
|
|
596
596
|
let a = [], o = 0, s = r === "input" ? t.inputs : t.outputs;
|
|
@@ -615,10 +615,10 @@ function X(e, t, n, r, i = !1) {
|
|
|
615
615
|
}
|
|
616
616
|
//#endregion
|
|
617
617
|
//#region src/utils/handle_blob.ts
|
|
618
|
-
async function
|
|
618
|
+
async function Oe(e, t, n) {
|
|
619
619
|
let r = this;
|
|
620
|
-
await
|
|
621
|
-
let i = await
|
|
620
|
+
await ke(r, t);
|
|
621
|
+
let i = await we(t, void 0, [], !0, n);
|
|
622
622
|
return (await Promise.all(i.map(async ({ path: t, blob: n, type: i }) => {
|
|
623
623
|
if (!n) return {
|
|
624
624
|
path: t,
|
|
@@ -632,40 +632,40 @@ async function Ce(e, t, n) {
|
|
|
632
632
|
name: typeof File < "u" && n instanceof File ? n?.name : void 0
|
|
633
633
|
};
|
|
634
634
|
}))).forEach(({ path: e, file_url: n, type: r, name: i }) => {
|
|
635
|
-
r === "Gallery" ?
|
|
635
|
+
r === "Gallery" ? Ce(t, n, e) : n && Ce(t, new U({
|
|
636
636
|
path: n,
|
|
637
637
|
orig_name: i
|
|
638
638
|
}), e);
|
|
639
639
|
}), t;
|
|
640
640
|
}
|
|
641
|
-
async function
|
|
642
|
-
if (!(e.config?.root || e.config?.root_url)) throw Error(
|
|
643
|
-
await
|
|
641
|
+
async function ke(e, t) {
|
|
642
|
+
if (!(e.config?.root || e.config?.root_url)) throw Error(O);
|
|
643
|
+
await Ae(e, t);
|
|
644
644
|
}
|
|
645
|
-
async function
|
|
646
|
-
for (let r in t) t[r] instanceof
|
|
645
|
+
async function Ae(e, t, n = []) {
|
|
646
|
+
for (let r in t) t[r] instanceof W ? await je(e, t, r) : typeof t[r] == "object" && t[r] !== null && await Ae(e, t[r], [...n, r]);
|
|
647
647
|
}
|
|
648
|
-
async function
|
|
648
|
+
async function je(e, t, n) {
|
|
649
649
|
let r = t[n], i = e.config?.root || e.config?.root_url;
|
|
650
|
-
if (!i) throw Error(
|
|
650
|
+
if (!i) throw Error(O);
|
|
651
651
|
try {
|
|
652
652
|
let a, o;
|
|
653
653
|
if (typeof process < "u" && process.versions && process.versions.node) {
|
|
654
654
|
let e = await import("./__vite-browser-external-Cgmn0awE.js").then((e) => /* @__PURE__ */ c(e.default, 1));
|
|
655
655
|
o = (await import("./__vite-browser-external-Cgmn0awE.js").then((e) => /* @__PURE__ */ c(e.default, 1))).resolve(process.cwd(), r.meta.path), a = await e.readFile(o);
|
|
656
|
-
} else throw Error(
|
|
656
|
+
} else throw Error(le);
|
|
657
657
|
let s = new Blob([a], { type: "application/octet-stream" }), l = await e.upload_files(i, [s]), u = l.files && l.files[0];
|
|
658
|
-
u && (t[n] = new
|
|
658
|
+
u && (t[n] = new U({
|
|
659
659
|
path: u,
|
|
660
660
|
orig_name: r.meta.name || ""
|
|
661
661
|
}));
|
|
662
662
|
} catch (e) {
|
|
663
|
-
console.error(
|
|
663
|
+
console.error(ue, e);
|
|
664
664
|
}
|
|
665
665
|
}
|
|
666
666
|
//#endregion
|
|
667
667
|
//#region src/utils/post_data.ts
|
|
668
|
-
async function
|
|
668
|
+
async function Me(e, t, n) {
|
|
669
669
|
let r = { "Content-Type": "application/json" };
|
|
670
670
|
this.options.token && (r.Authorization = `Bearer ${this.options.token}`);
|
|
671
671
|
try {
|
|
@@ -679,7 +679,7 @@ async function De(e, t, n) {
|
|
|
679
679
|
credentials: this.options.credentials ?? "same-origin"
|
|
680
680
|
});
|
|
681
681
|
} catch {
|
|
682
|
-
return [{ error:
|
|
682
|
+
return [{ error: y }, 500];
|
|
683
683
|
}
|
|
684
684
|
let a, o;
|
|
685
685
|
try {
|
|
@@ -691,7 +691,7 @@ async function De(e, t, n) {
|
|
|
691
691
|
}
|
|
692
692
|
//#endregion
|
|
693
693
|
//#region src/utils/predict.ts
|
|
694
|
-
async function
|
|
694
|
+
async function Ne(e, t = {}) {
|
|
695
695
|
let n = !1, r = !1;
|
|
696
696
|
if (!this.config) throw Error("Could not resolve app config");
|
|
697
697
|
if (typeof e == "number") this.config.dependencies.find((t) => t.id == e);
|
|
@@ -714,7 +714,7 @@ async function Oe(e, t = {}) {
|
|
|
714
714
|
}
|
|
715
715
|
//#endregion
|
|
716
716
|
//#region src/helpers/spaces.ts
|
|
717
|
-
async function
|
|
717
|
+
async function K(e, t, n) {
|
|
718
718
|
let r = t === "subdomain" ? `https://huggingface.co/api/spaces/by-subdomain/${e}` : `https://huggingface.co/api/spaces/${e}`, i, a;
|
|
719
719
|
try {
|
|
720
720
|
if (i = await fetch(r), a = i.status, a !== 200) throw Error();
|
|
@@ -723,7 +723,7 @@ async function Z(e, t, n) {
|
|
|
723
723
|
n({
|
|
724
724
|
status: "error",
|
|
725
725
|
load_status: "error",
|
|
726
|
-
message:
|
|
726
|
+
message: x,
|
|
727
727
|
detail: "NOT_FOUND"
|
|
728
728
|
});
|
|
729
729
|
return;
|
|
@@ -739,7 +739,7 @@ async function Z(e, t, n) {
|
|
|
739
739
|
message: "Space is asleep. Waking it up...",
|
|
740
740
|
detail: o
|
|
741
741
|
}), setTimeout(() => {
|
|
742
|
-
|
|
742
|
+
K(e, t, n);
|
|
743
743
|
}, 1e3);
|
|
744
744
|
break;
|
|
745
745
|
case "PAUSED":
|
|
@@ -748,7 +748,7 @@ async function Z(e, t, n) {
|
|
|
748
748
|
load_status: "error",
|
|
749
749
|
message: "This space has been paused by the author. If you would like to try this demo, consider duplicating the space.",
|
|
750
750
|
detail: o,
|
|
751
|
-
discussions_enabled: await
|
|
751
|
+
discussions_enabled: await Ie(s)
|
|
752
752
|
});
|
|
753
753
|
break;
|
|
754
754
|
case "RUNNING":
|
|
@@ -767,7 +767,7 @@ async function Z(e, t, n) {
|
|
|
767
767
|
message: "Space is building...",
|
|
768
768
|
detail: o
|
|
769
769
|
}), setTimeout(() => {
|
|
770
|
-
|
|
770
|
+
K(e, t, n);
|
|
771
771
|
}, 1e3);
|
|
772
772
|
break;
|
|
773
773
|
case "APP_STARTING":
|
|
@@ -777,7 +777,7 @@ async function Z(e, t, n) {
|
|
|
777
777
|
message: "Space is starting...",
|
|
778
778
|
detail: o
|
|
779
779
|
}), setTimeout(() => {
|
|
780
|
-
|
|
780
|
+
K(e, t, n);
|
|
781
781
|
}, 1e3);
|
|
782
782
|
break;
|
|
783
783
|
default:
|
|
@@ -786,30 +786,30 @@ async function Z(e, t, n) {
|
|
|
786
786
|
load_status: "error",
|
|
787
787
|
message: "This space is experiencing an issue.",
|
|
788
788
|
detail: o,
|
|
789
|
-
discussions_enabled: await
|
|
789
|
+
discussions_enabled: await Ie(s)
|
|
790
790
|
});
|
|
791
791
|
break;
|
|
792
792
|
}
|
|
793
793
|
}
|
|
794
|
-
var
|
|
794
|
+
var Pe = async (e, t) => {
|
|
795
795
|
let n = 0;
|
|
796
796
|
return new Promise((r) => {
|
|
797
|
-
|
|
797
|
+
K(e, L.test(e) ? "space_name" : "subdomain", (i) => {
|
|
798
798
|
t(i), i.status === "running" || i.status === "error" || i.status === "paused" || i.status === "space_error" ? r() : (i.status === "sleeping" || i.status === "building") && (n < 12 ? (n++, setTimeout(() => {
|
|
799
|
-
|
|
799
|
+
Pe(e, t).then(r);
|
|
800
800
|
}, 5e3)) : r());
|
|
801
801
|
});
|
|
802
802
|
});
|
|
803
|
-
},
|
|
804
|
-
async function
|
|
803
|
+
}, Fe = /^(?=[^]*\b[dD]iscussions{0,1}\b)(?=[^]*\b[dD]isabled\b)[^]*$/;
|
|
804
|
+
async function Ie(e) {
|
|
805
805
|
try {
|
|
806
806
|
let t = await fetch(`https://huggingface.co/api/spaces/${e}/discussions`, { method: "HEAD" }), n = t.headers.get("x-error-message");
|
|
807
|
-
return !(!t.ok || n &&
|
|
807
|
+
return !(!t.ok || n && Fe.test(n));
|
|
808
808
|
} catch {
|
|
809
809
|
return !1;
|
|
810
810
|
}
|
|
811
811
|
}
|
|
812
|
-
async function
|
|
812
|
+
async function Le(e, t) {
|
|
813
813
|
let n = {};
|
|
814
814
|
t && (n.Authorization = `Bearer ${t}`);
|
|
815
815
|
try {
|
|
@@ -821,12 +821,12 @@ async function Me(e, t) {
|
|
|
821
821
|
throw Error(e.message);
|
|
822
822
|
}
|
|
823
823
|
}
|
|
824
|
-
async function
|
|
824
|
+
async function Re(e, t, n) {
|
|
825
825
|
let r = {};
|
|
826
826
|
n && (r.Authorization = `Bearer ${n}`);
|
|
827
827
|
let i = { seconds: t };
|
|
828
828
|
try {
|
|
829
|
-
let t = await fetch(`https://huggingface.co/api/spaces/${e}/${
|
|
829
|
+
let t = await fetch(`https://huggingface.co/api/spaces/${e}/${ee}`, {
|
|
830
830
|
method: "POST",
|
|
831
831
|
headers: {
|
|
832
832
|
"Content-Type": "application/json",
|
|
@@ -840,7 +840,7 @@ async function Ne(e, t, n) {
|
|
|
840
840
|
throw Error(e.message);
|
|
841
841
|
}
|
|
842
842
|
}
|
|
843
|
-
var
|
|
843
|
+
var ze = [
|
|
844
844
|
"cpu-basic",
|
|
845
845
|
"cpu-upgrade",
|
|
846
846
|
"cpu-xl",
|
|
@@ -857,14 +857,14 @@ var Pe = [
|
|
|
857
857
|
];
|
|
858
858
|
//#endregion
|
|
859
859
|
//#region src/utils/duplicate.ts
|
|
860
|
-
async function
|
|
861
|
-
|
|
860
|
+
async function Be(e, t) {
|
|
861
|
+
k(t);
|
|
862
862
|
let { token: n, private: r, hardware: i, timeout: a, auth: o } = t;
|
|
863
|
-
if (i && !
|
|
864
|
-
let { http_protocol: s, host: c } = await
|
|
863
|
+
if (i && !ze.includes(i)) throw Error(`Invalid hardware type provided. Valid types are: ${ze.map((e) => `"${e}"`).join(",")}.`);
|
|
864
|
+
let { http_protocol: s, host: c } = await R(e, n), l = null;
|
|
865
865
|
if (o) {
|
|
866
|
-
let e = await
|
|
867
|
-
e && (l =
|
|
866
|
+
let e = await P(s, c, o, fetch, void 0, t.credentials);
|
|
867
|
+
e && (l = I(e));
|
|
868
868
|
}
|
|
869
869
|
let u = {
|
|
870
870
|
Authorization: `Bearer ${n}`,
|
|
@@ -874,9 +874,9 @@ async function Fe(e, t) {
|
|
|
874
874
|
r && (p.private = !0);
|
|
875
875
|
let m;
|
|
876
876
|
try {
|
|
877
|
-
i || (m = await
|
|
877
|
+
i || (m = await Le(e, n));
|
|
878
878
|
} catch (e) {
|
|
879
|
-
throw Error(
|
|
879
|
+
throw Error(C + e.message);
|
|
880
880
|
}
|
|
881
881
|
p.hardware = i || m || "cpu-basic";
|
|
882
882
|
try {
|
|
@@ -892,35 +892,35 @@ async function Fe(e, t) {
|
|
|
892
892
|
}
|
|
893
893
|
else if (r.status !== 200) throw Error(r.statusText);
|
|
894
894
|
let i = await r.json();
|
|
895
|
-
return await
|
|
895
|
+
return await Re(`${d}/${f}`, a || 300, n), await $.connect(Ve(i.url), t);
|
|
896
896
|
} catch (e) {
|
|
897
897
|
throw Error(e);
|
|
898
898
|
}
|
|
899
899
|
}
|
|
900
|
-
function
|
|
900
|
+
function Ve(e) {
|
|
901
901
|
let t = e.match(/https:\/\/huggingface.co\/spaces\/([^/]+\/[^/]+)/);
|
|
902
902
|
if (t) return t[1];
|
|
903
903
|
}
|
|
904
904
|
//#endregion
|
|
905
905
|
//#region src/helpers/zerogpu.ts
|
|
906
|
-
var
|
|
907
|
-
function
|
|
906
|
+
var He = "supports-zerogpu-headers", Ue = !1;
|
|
907
|
+
function We() {
|
|
908
908
|
return typeof window < "u" && typeof document < "u" && typeof window.addEventListener == "function";
|
|
909
909
|
}
|
|
910
|
-
function
|
|
910
|
+
function Ge(e) {
|
|
911
911
|
return e.includes(".dev.") ? `https://moon-${e.split(".")[1]}.dev.spaces.huggingface.tech` : e.endsWith(".hf.space") ? "https://huggingface.co" : null;
|
|
912
912
|
}
|
|
913
|
-
function
|
|
914
|
-
if (!
|
|
913
|
+
function Ke() {
|
|
914
|
+
if (!We() || Ue) return;
|
|
915
915
|
window.addEventListener("message", (e) => {
|
|
916
|
-
e.data ===
|
|
917
|
-
}),
|
|
918
|
-
let e =
|
|
919
|
-
e && window.parent !== window && window.parent.postMessage(
|
|
916
|
+
e.data === He && (window.supports_zerogpu_headers = !0);
|
|
917
|
+
}), Ue = !0;
|
|
918
|
+
let e = Ge(window.location.hostname);
|
|
919
|
+
e && window.parent !== window && window.parent.postMessage(He, e);
|
|
920
920
|
}
|
|
921
921
|
//#endregion
|
|
922
922
|
//#region ../../node_modules/.pnpm/fetch-event-stream@0.1.6/node_modules/fetch-event-stream/esm/deps/jsr.io/@std/streams/0.221.0/text_line_stream.js
|
|
923
|
-
var
|
|
923
|
+
var qe = class extends TransformStream {
|
|
924
924
|
#e = "";
|
|
925
925
|
constructor(e = { allowCR: !1 }) {
|
|
926
926
|
super({
|
|
@@ -947,22 +947,22 @@ var He = class extends TransformStream {
|
|
|
947
947
|
};
|
|
948
948
|
//#endregion
|
|
949
949
|
//#region ../../node_modules/.pnpm/fetch-event-stream@0.1.6/node_modules/fetch-event-stream/esm/utils.js
|
|
950
|
-
function
|
|
951
|
-
let t = new TextDecoderStream(), n = new
|
|
950
|
+
function Je(e) {
|
|
951
|
+
let t = new TextDecoderStream(), n = new qe({ allowCR: !0 });
|
|
952
952
|
return e.pipeThrough(t).pipeThrough(n);
|
|
953
953
|
}
|
|
954
|
-
function
|
|
954
|
+
function Ye(e) {
|
|
955
955
|
let t = /[:]\s*/.exec(e), n = t && t.index;
|
|
956
956
|
if (n) return [e.substring(0, n), e.substring(n + t[0].length)];
|
|
957
957
|
}
|
|
958
|
-
function
|
|
958
|
+
function Xe(e, t, n) {
|
|
959
959
|
e.get(t) || e.set(t, n);
|
|
960
960
|
}
|
|
961
961
|
//#endregion
|
|
962
962
|
//#region ../../node_modules/.pnpm/fetch-event-stream@0.1.6/node_modules/fetch-event-stream/esm/mod.js
|
|
963
|
-
async function*
|
|
963
|
+
async function* Ze(e, t) {
|
|
964
964
|
if (!e.body) return;
|
|
965
|
-
let n =
|
|
965
|
+
let n = Je(e.body), r, i = n.getReader(), a;
|
|
966
966
|
for (;;) {
|
|
967
967
|
if (t && t.aborted) return i.cancel();
|
|
968
968
|
if (r = await i.read(), r.done) return;
|
|
@@ -970,20 +970,20 @@ async function* Ke(e, t) {
|
|
|
970
970
|
a && (yield a), a = void 0;
|
|
971
971
|
continue;
|
|
972
972
|
}
|
|
973
|
-
let [e, n] =
|
|
973
|
+
let [e, n] = Ye(r.value) || [];
|
|
974
974
|
e === "data" ? (a ||= {}, a[e] = a[e] ? a[e] + "\n" + n : n) : e === "event" ? (a ||= {}, a[e] = n) : e === "id" ? (a ||= {}, a[e] = String(+n) === n ? +n : n) : e === "retry" && (a ||= {}, a[e] = +n || void 0);
|
|
975
975
|
}
|
|
976
976
|
}
|
|
977
|
-
async function
|
|
977
|
+
async function Qe(e, t) {
|
|
978
978
|
let n = new Request(e, t);
|
|
979
|
-
|
|
979
|
+
Xe(n.headers, "Accept", "text/event-stream"), Xe(n.headers, "Content-Type", "application/json");
|
|
980
980
|
let r = await fetch(n);
|
|
981
981
|
if (!r.ok) throw r;
|
|
982
|
-
return
|
|
982
|
+
return Ze(r, n.signal);
|
|
983
983
|
}
|
|
984
984
|
//#endregion
|
|
985
985
|
//#region src/utils/stream.ts
|
|
986
|
-
async function
|
|
986
|
+
async function $e() {
|
|
987
987
|
let { event_callbacks: e, unclosed_events: t, pending_stream_messages: n, stream_status: r, config: i, jwt: a } = this, o = this;
|
|
988
988
|
if (!i) throw Error("Could not resolve app config");
|
|
989
989
|
r.open = !0;
|
|
@@ -995,7 +995,7 @@ async function Je() {
|
|
|
995
995
|
s.onmessage = async function(a) {
|
|
996
996
|
let s = JSON.parse(a.data);
|
|
997
997
|
if (s.msg === "close_stream") {
|
|
998
|
-
|
|
998
|
+
et(r, o.abort_controller);
|
|
999
999
|
return;
|
|
1000
1000
|
}
|
|
1001
1001
|
let c = s.event_id;
|
|
@@ -1014,27 +1014,27 @@ async function Je() {
|
|
|
1014
1014
|
}, s.onerror = async function(t) {
|
|
1015
1015
|
console.error(t), await Promise.all(Object.keys(e).map((t) => e[t]({
|
|
1016
1016
|
msg: "broken_connection",
|
|
1017
|
-
message:
|
|
1017
|
+
message: y
|
|
1018
1018
|
})));
|
|
1019
1019
|
};
|
|
1020
1020
|
}
|
|
1021
|
-
function
|
|
1021
|
+
function et(e, t) {
|
|
1022
1022
|
e && (e.open = !1, t?.abort());
|
|
1023
1023
|
}
|
|
1024
|
-
function
|
|
1024
|
+
function tt(e, t, n) {
|
|
1025
1025
|
e[t] ? n.data.forEach((r, i) => {
|
|
1026
|
-
let a =
|
|
1026
|
+
let a = nt(i < e[t].length ? e[t][i] : null, r);
|
|
1027
1027
|
e[t][i] = a, n.data[i] = a;
|
|
1028
1028
|
}) : (e[t] = [], n.data.forEach((n, r) => {
|
|
1029
1029
|
e[t][r] = n;
|
|
1030
1030
|
}));
|
|
1031
1031
|
}
|
|
1032
|
-
function
|
|
1032
|
+
function nt(e, t) {
|
|
1033
1033
|
return t.forEach(([t, n, r]) => {
|
|
1034
|
-
e =
|
|
1034
|
+
e = rt(e, n, t, r);
|
|
1035
1035
|
}), e;
|
|
1036
1036
|
}
|
|
1037
|
-
function
|
|
1037
|
+
function rt(e, t, n, r) {
|
|
1038
1038
|
if (t.length === 0) {
|
|
1039
1039
|
if (n === "replace") return r;
|
|
1040
1040
|
if (n === "append") return e + r;
|
|
@@ -1060,7 +1060,7 @@ function Ze(e, t, n, r) {
|
|
|
1060
1060
|
}
|
|
1061
1061
|
return e;
|
|
1062
1062
|
}
|
|
1063
|
-
function
|
|
1063
|
+
function it(e, t = {}) {
|
|
1064
1064
|
let n = {
|
|
1065
1065
|
close: () => {
|
|
1066
1066
|
console.warn("Method not implemented.");
|
|
@@ -1084,7 +1084,7 @@ function Qe(e, t = {}) {
|
|
|
1084
1084
|
throw Error("Method not implemented.");
|
|
1085
1085
|
}
|
|
1086
1086
|
};
|
|
1087
|
-
return
|
|
1087
|
+
return Qe(e, t).then(async (e) => {
|
|
1088
1088
|
n.readyState = n.OPEN;
|
|
1089
1089
|
try {
|
|
1090
1090
|
for await (let t of e) n.onmessage && n.onmessage(t);
|
|
@@ -1097,32 +1097,255 @@ function Qe(e, t = {}) {
|
|
|
1097
1097
|
}), n;
|
|
1098
1098
|
}
|
|
1099
1099
|
//#endregion
|
|
1100
|
+
//#region src/utils/run_history.ts
|
|
1101
|
+
var at = "gradio:run-history:", q = `${at}v2:`, ot = `${at}replay:v2:`, st = 100, ct = 8;
|
|
1102
|
+
function J(e, t) {
|
|
1103
|
+
try {
|
|
1104
|
+
return e();
|
|
1105
|
+
} catch (e) {
|
|
1106
|
+
return console.warn("Could not update the run history.", e), t;
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
function lt(e, t = "/gradio_api") {
|
|
1110
|
+
return `${e.replace(/\/+$/, "")}${t}/runs`;
|
|
1111
|
+
}
|
|
1112
|
+
function Y(e) {
|
|
1113
|
+
if (typeof window > "u") return null;
|
|
1114
|
+
let t = e?.app_id;
|
|
1115
|
+
if (t == null || t === "") return null;
|
|
1116
|
+
try {
|
|
1117
|
+
return window.localStorage ? `${q}${t}${e?.username ? `:user:${encodeURIComponent(e.username)}` : ""}` : null;
|
|
1118
|
+
} catch {
|
|
1119
|
+
return null;
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
function ut(e) {
|
|
1123
|
+
let t = Y(e);
|
|
1124
|
+
return t ? t.replace(q, ot) : null;
|
|
1125
|
+
}
|
|
1126
|
+
function dt(e) {
|
|
1127
|
+
try {
|
|
1128
|
+
let t = JSON.parse(window.localStorage.getItem(e) || "[]");
|
|
1129
|
+
return Array.isArray(t) && t.length && Date.parse(t[0]?.started_at) || 0;
|
|
1130
|
+
} catch {
|
|
1131
|
+
return 0;
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
function ft(e) {
|
|
1135
|
+
let t = Object.keys(window.localStorage).filter((e) => e.startsWith(at)), n = [...t.filter((e) => !e.startsWith(q) && !e.startsWith(ot)), ...t.filter((t) => t.startsWith(q) && t !== e).sort((e, t) => dt(t) - dt(e)).slice(ct - 1)];
|
|
1136
|
+
for (let e of n) try {
|
|
1137
|
+
window.localStorage.removeItem(e), window.sessionStorage.removeItem(e.replace(q, ot));
|
|
1138
|
+
} catch {}
|
|
1139
|
+
}
|
|
1140
|
+
function pt() {
|
|
1141
|
+
return typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
1142
|
+
}
|
|
1143
|
+
function X(e) {
|
|
1144
|
+
let t = /* @__PURE__ */ new WeakSet();
|
|
1145
|
+
try {
|
|
1146
|
+
return JSON.parse(JSON.stringify(e, (e, n) => {
|
|
1147
|
+
if (typeof n == "bigint") return n.toString();
|
|
1148
|
+
if (typeof n == "object" && n) {
|
|
1149
|
+
if (t.has(n)) return "[Circular]";
|
|
1150
|
+
t.add(n);
|
|
1151
|
+
}
|
|
1152
|
+
return n;
|
|
1153
|
+
}));
|
|
1154
|
+
} catch {
|
|
1155
|
+
return "[Unserializable value]";
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
function Z(e) {
|
|
1159
|
+
let t = Y(e);
|
|
1160
|
+
if (!t) return [];
|
|
1161
|
+
try {
|
|
1162
|
+
let e = JSON.parse(window.localStorage.getItem(t) || "[]");
|
|
1163
|
+
return Array.isArray(e) ? e : [];
|
|
1164
|
+
} catch {
|
|
1165
|
+
return [];
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
function mt(e, t) {
|
|
1169
|
+
let n = Y(e);
|
|
1170
|
+
if (!n) return;
|
|
1171
|
+
let r = t.slice(0, st), i = !1;
|
|
1172
|
+
for (; r.length > 0;) try {
|
|
1173
|
+
window.localStorage.setItem(n, JSON.stringify(r));
|
|
1174
|
+
return;
|
|
1175
|
+
} catch {
|
|
1176
|
+
if (!i) {
|
|
1177
|
+
i = !0, ft(n);
|
|
1178
|
+
continue;
|
|
1179
|
+
}
|
|
1180
|
+
r = r.slice(0, -1);
|
|
1181
|
+
}
|
|
1182
|
+
try {
|
|
1183
|
+
window.localStorage.removeItem(n);
|
|
1184
|
+
} catch {}
|
|
1185
|
+
}
|
|
1186
|
+
function ht(e) {
|
|
1187
|
+
let t = Y(e);
|
|
1188
|
+
if (t) {
|
|
1189
|
+
try {
|
|
1190
|
+
window.localStorage.removeItem(t);
|
|
1191
|
+
} catch {}
|
|
1192
|
+
vt();
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
function gt(e, t) {
|
|
1196
|
+
mt(e, Z(e).filter((e) => e.id !== t)), vt();
|
|
1197
|
+
}
|
|
1198
|
+
var _t = "gradio:run-history-change";
|
|
1199
|
+
function vt() {
|
|
1200
|
+
if (!(typeof window > "u")) try {
|
|
1201
|
+
window.dispatchEvent(new Event(_t));
|
|
1202
|
+
} catch {}
|
|
1203
|
+
}
|
|
1204
|
+
function yt(e) {
|
|
1205
|
+
return typeof window > "u" ? () => {} : (window.addEventListener(_t, e), window.addEventListener("storage", e), () => {
|
|
1206
|
+
window.removeEventListener(_t, e), window.removeEventListener("storage", e);
|
|
1207
|
+
});
|
|
1208
|
+
}
|
|
1209
|
+
function bt(e, t) {
|
|
1210
|
+
let n = ut(e);
|
|
1211
|
+
if (n) try {
|
|
1212
|
+
window.sessionStorage.setItem(n, JSON.stringify(t));
|
|
1213
|
+
} catch {}
|
|
1214
|
+
}
|
|
1215
|
+
function xt(e) {
|
|
1216
|
+
let t = ut(e);
|
|
1217
|
+
if (!t) return null;
|
|
1218
|
+
try {
|
|
1219
|
+
let e = window.sessionStorage.getItem(t);
|
|
1220
|
+
return window.sessionStorage.removeItem(t), e ? JSON.parse(e) : null;
|
|
1221
|
+
} catch {
|
|
1222
|
+
return null;
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
function St(e) {
|
|
1226
|
+
let t = Y(e);
|
|
1227
|
+
if (!t) return null;
|
|
1228
|
+
ft(t);
|
|
1229
|
+
let n = {
|
|
1230
|
+
id: pt(),
|
|
1231
|
+
endpoint: e.endpoint,
|
|
1232
|
+
api_name: e.api_name,
|
|
1233
|
+
fn_index: e.fn_index,
|
|
1234
|
+
page: `${window.location.pathname}${window.location.search}`,
|
|
1235
|
+
inputs: X(e.inputs),
|
|
1236
|
+
outputs: null,
|
|
1237
|
+
...e.input_components ? { input_components: X(e.input_components) } : {},
|
|
1238
|
+
...e.output_components ? { output_components: X(e.output_components) } : {},
|
|
1239
|
+
status: "running",
|
|
1240
|
+
started_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1241
|
+
};
|
|
1242
|
+
return mt(e, [n, ...Z(e)]), vt(), n.id;
|
|
1243
|
+
}
|
|
1244
|
+
function Ct(e, t, n) {
|
|
1245
|
+
if (!t) return;
|
|
1246
|
+
let r = Z(e), i = r.find((e) => e.id === t);
|
|
1247
|
+
i && (i.inputs = X(n), mt(e, r));
|
|
1248
|
+
}
|
|
1249
|
+
function wt(e, t, n) {
|
|
1250
|
+
if (!t) return;
|
|
1251
|
+
let r = Z(e), i = r.find((e) => e.id === t);
|
|
1252
|
+
if (!i) return;
|
|
1253
|
+
let a = !1;
|
|
1254
|
+
if (n.type === "data") i.outputs = X(n.data), Q.set(t, i.outputs);
|
|
1255
|
+
else if (n.type === "status" && n.original_msg === "process_starts") Dt(i, n.time);
|
|
1256
|
+
else if (n.type === "status" && (n.stage === "generating" || n.stage === "streaming")) i.streamed = !0;
|
|
1257
|
+
else if (n.type === "status" && n.stage === "complete") i.status = "completed", Ot(i, n), a = !0;
|
|
1258
|
+
else if (n.type === "status" && n.stage === "error") i.status = "failed", i.error = typeof n.message == "string" ? n.message : JSON.stringify(n.message || "Unknown error"), Ot(i, n), a = !0;
|
|
1259
|
+
else return;
|
|
1260
|
+
if (a) Q.has(t) && (i.outputs = Q.get(t)), Q.delete(t), Et.delete(t);
|
|
1261
|
+
else if (i.streamed) {
|
|
1262
|
+
if (Date.now() - (Et.get(t) ?? 0) < Tt) return;
|
|
1263
|
+
Et.set(t, Date.now()), Q.delete(t);
|
|
1264
|
+
}
|
|
1265
|
+
mt(e, r);
|
|
1266
|
+
}
|
|
1267
|
+
var Tt = 500, Et = /* @__PURE__ */ new Map(), Q = /* @__PURE__ */ new Map();
|
|
1268
|
+
function Dt(e, t) {
|
|
1269
|
+
if (e.process_started_at) return;
|
|
1270
|
+
let n = t || /* @__PURE__ */ new Date();
|
|
1271
|
+
e.process_started_at = n.toISOString(), e.queued_ms = Math.max(0, n.getTime() - Date.parse(e.started_at));
|
|
1272
|
+
}
|
|
1273
|
+
function Ot(e, t) {
|
|
1274
|
+
let n = t.time || /* @__PURE__ */ new Date();
|
|
1275
|
+
e.completed_at = n.toISOString(), e.duration_ms = (!e.streamed && typeof t.cache_duration == "number" && t.cache_duration >= 0 ? t.cache_duration * 1e3 : null) ?? Math.max(0, n.getTime() - Date.parse(e.process_started_at || e.started_at));
|
|
1276
|
+
}
|
|
1277
|
+
function kt(e) {
|
|
1278
|
+
return J(() => Z(e), []);
|
|
1279
|
+
}
|
|
1280
|
+
function At(e) {
|
|
1281
|
+
J(() => ht(e), void 0);
|
|
1282
|
+
}
|
|
1283
|
+
function jt(e, t) {
|
|
1284
|
+
J(() => gt(e, t), void 0);
|
|
1285
|
+
}
|
|
1286
|
+
function Mt(e, t) {
|
|
1287
|
+
J(() => bt(e, t), void 0);
|
|
1288
|
+
}
|
|
1289
|
+
function Nt(e) {
|
|
1290
|
+
return J(() => xt(e), null);
|
|
1291
|
+
}
|
|
1292
|
+
function Pt(e) {
|
|
1293
|
+
return J(() => St(e), null);
|
|
1294
|
+
}
|
|
1295
|
+
function Ft(e, t, n) {
|
|
1296
|
+
J(() => Ct(e, t, n), void 0);
|
|
1297
|
+
}
|
|
1298
|
+
function It(e, t, n) {
|
|
1299
|
+
J(() => wt(e, t, n), void 0);
|
|
1300
|
+
}
|
|
1301
|
+
function Lt(e) {
|
|
1302
|
+
return J(() => yt(() => J(e, void 0)), () => {});
|
|
1303
|
+
}
|
|
1304
|
+
//#endregion
|
|
1100
1305
|
//#region src/utils/submit.ts
|
|
1101
|
-
function
|
|
1306
|
+
function Rt(e, t = {}, n, r, i, a) {
|
|
1102
1307
|
try {
|
|
1103
|
-
let { token: o } = this.options, { fetch: s, app_reference: c, config: l, session_hash: f, api_info: p, api_map: m, stream_status: h, pending_stream_messages: g, pending_diff_streams:
|
|
1104
|
-
if (!p) throw Error(
|
|
1308
|
+
let { token: o } = this.options, { fetch: s, app_reference: c, config: l, session_hash: f, api_info: p, api_map: m, stream_status: h, pending_stream_messages: g, pending_diff_streams: ee, event_callbacks: _, unclosed_events: te, post_data: v, options: b, api_prefix: x } = this, S = a || { "x-gradio-user": "api" }, C = this;
|
|
1309
|
+
if (!p) throw Error(se);
|
|
1105
1310
|
if (!l) throw Error("Could not resolve app config");
|
|
1106
|
-
let { fn_index:
|
|
1107
|
-
if (
|
|
1108
|
-
let
|
|
1109
|
-
|
|
1110
|
-
|
|
1311
|
+
let { fn_index: w, endpoint_info: T, dependency: E } = Bt(p, e, m, l), ae = ye(t, T), D = l.protocol ?? "ws";
|
|
1312
|
+
if (D === "ws") throw Error(ce);
|
|
1313
|
+
let oe = typeof E.api_name == "string" ? `/${E.api_name}` : e, le = typeof E.api_name == "string" ? `/${E.api_name}` : `Function ${w}`, O = (e) => {
|
|
1314
|
+
let t = l.components.find((t) => t.id === e);
|
|
1315
|
+
return t ? {
|
|
1316
|
+
type: t.type,
|
|
1317
|
+
component_class_id: t.component_class_id,
|
|
1318
|
+
props: t.props
|
|
1319
|
+
} : null;
|
|
1320
|
+
}, ue = E.api_visibility === "public", de = l.run_history !== !1 && this.options.record_history !== !1, k = {
|
|
1321
|
+
app_id: l.app_id,
|
|
1322
|
+
username: l.username
|
|
1323
|
+
}, fe = !de || !ue ? null : Pt({
|
|
1324
|
+
...k,
|
|
1325
|
+
endpoint: oe,
|
|
1326
|
+
api_name: le,
|
|
1327
|
+
fn_index: w,
|
|
1328
|
+
inputs: G(ae, E, l.components, "input", !0),
|
|
1329
|
+
input_components: E.inputs.map(O),
|
|
1330
|
+
output_components: E.outputs.map(O)
|
|
1331
|
+
}), A, j = "", M = typeof e == "number" ? "/predict" : e, N, P = null, F = !1, I = {}, L = typeof window < "u" && typeof document < "u" ? new URLSearchParams(window.location.search).toString() : "", pe = b?.events?.reduce((e, t) => (e[t] = !0, e), {}) || {};
|
|
1332
|
+
function R(e) {
|
|
1333
|
+
It(k, fe, e), (i || pe[e.type]) && U(e);
|
|
1111
1334
|
}
|
|
1112
|
-
async function
|
|
1335
|
+
async function me() {
|
|
1113
1336
|
let e = {}, t = {};
|
|
1114
|
-
e = { event_id:
|
|
1115
|
-
event_id:
|
|
1337
|
+
e = { event_id: P }, t = {
|
|
1338
|
+
event_id: P,
|
|
1116
1339
|
session_hash: f,
|
|
1117
|
-
fn_index:
|
|
1340
|
+
fn_index: w
|
|
1118
1341
|
};
|
|
1119
1342
|
try {
|
|
1120
1343
|
if (!l) throw Error("Could not resolve app config");
|
|
1121
|
-
"event_id" in t && await s(`${l.root}${
|
|
1344
|
+
"event_id" in t && await s(`${l.root}${x}/${re}`, {
|
|
1122
1345
|
headers: { "Content-Type": "application/json" },
|
|
1123
1346
|
method: "POST",
|
|
1124
1347
|
body: JSON.stringify(t)
|
|
1125
|
-
}), await s(`${l.root}${
|
|
1348
|
+
}), await s(`${l.root}${x}/${ne}`, {
|
|
1126
1349
|
headers: { "Content-Type": "application/json" },
|
|
1127
1350
|
method: "POST",
|
|
1128
1351
|
body: JSON.stringify(e)
|
|
@@ -1131,64 +1354,65 @@ function $e(e, t = {}, n, r, i, a) {
|
|
|
1131
1354
|
console.warn("The `/reset` endpoint could not be called. Subsequent endpoint results may be unreliable.");
|
|
1132
1355
|
}
|
|
1133
1356
|
}
|
|
1134
|
-
let
|
|
1357
|
+
let he = async (e) => {
|
|
1135
1358
|
await this._resolve_heartbeat(e);
|
|
1136
1359
|
};
|
|
1137
|
-
async function
|
|
1360
|
+
async function ge(e) {
|
|
1138
1361
|
if (!l) return;
|
|
1139
1362
|
let t = e.render_id;
|
|
1140
1363
|
l.components = [...l.components.filter((e) => e.props.rendered_in !== t), ...e.components], l.dependencies = [...l.dependencies.filter((e) => e.rendered_in !== t), ...e.dependencies];
|
|
1141
1364
|
let n = l.components.some((e) => e.type === "state"), r = l.dependencies.some((e) => e.targets.some((e) => e[1] === "unload"));
|
|
1142
|
-
l.connect_heartbeat = n || r, await
|
|
1365
|
+
l.connect_heartbeat = n || r, await he(l), R({
|
|
1143
1366
|
type: "render",
|
|
1144
1367
|
data: e,
|
|
1145
|
-
endpoint:
|
|
1146
|
-
fn_index:
|
|
1368
|
+
endpoint: M,
|
|
1369
|
+
fn_index: w
|
|
1147
1370
|
});
|
|
1148
1371
|
}
|
|
1149
|
-
let
|
|
1150
|
-
|
|
1151
|
-
|
|
1372
|
+
let _e = this.handle_blob(l.root, ae, T).then(async (e) => {
|
|
1373
|
+
let t = G(e, E, l.components, "input", !0);
|
|
1374
|
+
if (Ft(k, fe, t || []), N = {
|
|
1375
|
+
data: t || [],
|
|
1152
1376
|
event_data: n,
|
|
1153
|
-
fn_index:
|
|
1377
|
+
fn_index: w,
|
|
1154
1378
|
trigger_id: r,
|
|
1155
|
-
...
|
|
1156
|
-
},
|
|
1379
|
+
...b.oauth_token && T?.oauth_token ? { oauth_token: b.oauth_token } : {}
|
|
1380
|
+
}, Te(w, l)) R({
|
|
1157
1381
|
type: "status",
|
|
1158
|
-
endpoint:
|
|
1382
|
+
endpoint: M,
|
|
1159
1383
|
stage: "pending",
|
|
1160
1384
|
queue: !1,
|
|
1161
|
-
fn_index:
|
|
1385
|
+
fn_index: w,
|
|
1162
1386
|
time: /* @__PURE__ */ new Date()
|
|
1163
|
-
}),
|
|
1164
|
-
...
|
|
1387
|
+
}), v(`${l.root}${x}/run${M.startsWith("/") ? M : `/${M}`}${L ? "?" + L : ""}`, {
|
|
1388
|
+
...N,
|
|
1165
1389
|
session_hash: f
|
|
1166
|
-
},
|
|
1390
|
+
}, S).then(async ([e, t]) => {
|
|
1167
1391
|
let i = e.data;
|
|
1168
|
-
if (t == 200)
|
|
1392
|
+
if (t == 200) R({
|
|
1169
1393
|
type: "data",
|
|
1170
|
-
endpoint:
|
|
1171
|
-
fn_index:
|
|
1172
|
-
data:
|
|
1394
|
+
endpoint: M,
|
|
1395
|
+
fn_index: w,
|
|
1396
|
+
data: G(i, E, l.components, "output", b.with_null_state),
|
|
1173
1397
|
time: /* @__PURE__ */ new Date(),
|
|
1174
1398
|
event_data: n,
|
|
1175
1399
|
trigger_id: r
|
|
1176
|
-
}), e.render_config && await
|
|
1400
|
+
}), e.render_config && await ge(e.render_config), R({
|
|
1177
1401
|
type: "status",
|
|
1178
|
-
endpoint:
|
|
1179
|
-
fn_index:
|
|
1402
|
+
endpoint: M,
|
|
1403
|
+
fn_index: w,
|
|
1180
1404
|
stage: "complete",
|
|
1181
1405
|
eta: e.average_duration,
|
|
1182
1406
|
queue: !1,
|
|
1183
1407
|
time: /* @__PURE__ */ new Date()
|
|
1184
1408
|
});
|
|
1185
1409
|
else {
|
|
1186
|
-
let t = e?.error ===
|
|
1187
|
-
|
|
1410
|
+
let t = e?.error === y;
|
|
1411
|
+
R({
|
|
1188
1412
|
type: "status",
|
|
1189
1413
|
stage: "error",
|
|
1190
|
-
endpoint:
|
|
1191
|
-
fn_index:
|
|
1414
|
+
endpoint: M,
|
|
1415
|
+
fn_index: w,
|
|
1192
1416
|
message: e.error,
|
|
1193
1417
|
broken: t,
|
|
1194
1418
|
queue: !1,
|
|
@@ -1196,303 +1420,303 @@ function $e(e, t = {}, n, r, i, a) {
|
|
|
1196
1420
|
});
|
|
1197
1421
|
}
|
|
1198
1422
|
}).catch((e) => {
|
|
1199
|
-
|
|
1423
|
+
R({
|
|
1200
1424
|
type: "status",
|
|
1201
1425
|
stage: "error",
|
|
1202
1426
|
message: e.message,
|
|
1203
|
-
endpoint:
|
|
1204
|
-
fn_index:
|
|
1427
|
+
endpoint: M,
|
|
1428
|
+
fn_index: w,
|
|
1205
1429
|
queue: !1,
|
|
1206
1430
|
time: /* @__PURE__ */ new Date()
|
|
1207
1431
|
});
|
|
1208
1432
|
});
|
|
1209
|
-
else if (
|
|
1210
|
-
|
|
1433
|
+
else if (D == "sse") {
|
|
1434
|
+
R({
|
|
1211
1435
|
type: "status",
|
|
1212
1436
|
stage: "pending",
|
|
1213
1437
|
queue: !0,
|
|
1214
|
-
endpoint:
|
|
1215
|
-
fn_index:
|
|
1438
|
+
endpoint: M,
|
|
1439
|
+
fn_index: w,
|
|
1216
1440
|
time: /* @__PURE__ */ new Date()
|
|
1217
1441
|
});
|
|
1218
|
-
var
|
|
1219
|
-
fn_index:
|
|
1442
|
+
var i = new URLSearchParams({
|
|
1443
|
+
fn_index: w.toString(),
|
|
1220
1444
|
session_hash: f
|
|
1221
1445
|
}).toString();
|
|
1222
|
-
let e = new URL(`${l.root}${
|
|
1223
|
-
if (this.jwt && e.searchParams.set("__sign", this.jwt),
|
|
1224
|
-
|
|
1225
|
-
let { type: t, status: i, data: a } =
|
|
1226
|
-
if (t === "update" && i && !
|
|
1446
|
+
let e = new URL(`${l.root}${x}/${u}?${L ? L + "&" : ""}${i}`);
|
|
1447
|
+
if (this.jwt && e.searchParams.set("__sign", this.jwt), A = this.stream(e), !A) return Promise.reject(/* @__PURE__ */ Error("Cannot connect to SSE endpoint: " + e.toString()));
|
|
1448
|
+
A.onmessage = async function(e) {
|
|
1449
|
+
let { type: t, status: i, data: a } = ve(JSON.parse(e.data), I[w]);
|
|
1450
|
+
if (t === "update" && i && !F) R({
|
|
1227
1451
|
type: "status",
|
|
1228
|
-
endpoint:
|
|
1229
|
-
fn_index:
|
|
1452
|
+
endpoint: M,
|
|
1453
|
+
fn_index: w,
|
|
1230
1454
|
time: /* @__PURE__ */ new Date(),
|
|
1231
1455
|
...i
|
|
1232
|
-
}), i.stage === "error" && (
|
|
1456
|
+
}), i.stage === "error" && (A?.close(), V());
|
|
1233
1457
|
else if (t === "data") {
|
|
1234
|
-
let [e, t] = await
|
|
1235
|
-
...
|
|
1458
|
+
let [e, t] = await v(`${l.root}${x}/queue/data`, {
|
|
1459
|
+
...N,
|
|
1236
1460
|
session_hash: f,
|
|
1237
|
-
event_id:
|
|
1461
|
+
event_id: P
|
|
1238
1462
|
});
|
|
1239
|
-
t !== 200 && (
|
|
1463
|
+
t !== 200 && (R({
|
|
1240
1464
|
type: "status",
|
|
1241
1465
|
stage: "error",
|
|
1242
|
-
message:
|
|
1466
|
+
message: y,
|
|
1243
1467
|
queue: !0,
|
|
1244
|
-
endpoint:
|
|
1245
|
-
fn_index:
|
|
1468
|
+
endpoint: M,
|
|
1469
|
+
fn_index: w,
|
|
1246
1470
|
time: /* @__PURE__ */ new Date()
|
|
1247
|
-
}),
|
|
1248
|
-
} else t === "complete" ?
|
|
1471
|
+
}), A?.close(), V());
|
|
1472
|
+
} else t === "complete" ? F = i : t === "log" ? R({
|
|
1249
1473
|
type: "log",
|
|
1250
1474
|
title: a.title,
|
|
1251
1475
|
log: a.log,
|
|
1252
1476
|
level: a.level,
|
|
1253
|
-
endpoint:
|
|
1477
|
+
endpoint: M,
|
|
1254
1478
|
duration: a.duration,
|
|
1255
1479
|
visible: a.visible,
|
|
1256
|
-
fn_index:
|
|
1257
|
-
}) : (t === "generating" || t === "streaming") &&
|
|
1480
|
+
fn_index: w
|
|
1481
|
+
}) : (t === "generating" || t === "streaming") && R({
|
|
1258
1482
|
type: "status",
|
|
1259
1483
|
time: /* @__PURE__ */ new Date(),
|
|
1260
1484
|
...i,
|
|
1261
1485
|
stage: i?.stage,
|
|
1262
1486
|
queue: !0,
|
|
1263
|
-
endpoint:
|
|
1264
|
-
fn_index:
|
|
1487
|
+
endpoint: M,
|
|
1488
|
+
fn_index: w
|
|
1265
1489
|
});
|
|
1266
|
-
a && (
|
|
1490
|
+
a && (R({
|
|
1267
1491
|
type: "data",
|
|
1268
1492
|
time: /* @__PURE__ */ new Date(),
|
|
1269
|
-
data:
|
|
1270
|
-
endpoint:
|
|
1271
|
-
fn_index:
|
|
1493
|
+
data: G(a.data, E, l.components, "output", b.with_null_state),
|
|
1494
|
+
endpoint: M,
|
|
1495
|
+
fn_index: w,
|
|
1272
1496
|
event_data: n,
|
|
1273
1497
|
trigger_id: r
|
|
1274
|
-
}),
|
|
1498
|
+
}), F && (R({
|
|
1275
1499
|
type: "status",
|
|
1276
1500
|
time: /* @__PURE__ */ new Date(),
|
|
1277
|
-
...
|
|
1501
|
+
...F,
|
|
1278
1502
|
stage: i?.stage,
|
|
1279
1503
|
queue: !0,
|
|
1280
|
-
endpoint:
|
|
1281
|
-
fn_index:
|
|
1282
|
-
}),
|
|
1504
|
+
endpoint: M,
|
|
1505
|
+
fn_index: w
|
|
1506
|
+
}), A?.close(), V()));
|
|
1283
1507
|
};
|
|
1284
|
-
} else if (
|
|
1285
|
-
|
|
1508
|
+
} else if (D == "sse_v1" || D == "sse_v2" || D == "sse_v2.1" || D == "sse_v3") {
|
|
1509
|
+
R({
|
|
1286
1510
|
type: "status",
|
|
1287
1511
|
stage: "pending",
|
|
1288
1512
|
queue: !0,
|
|
1289
|
-
endpoint:
|
|
1290
|
-
fn_index:
|
|
1513
|
+
endpoint: M,
|
|
1514
|
+
fn_index: w,
|
|
1291
1515
|
time: /* @__PURE__ */ new Date()
|
|
1292
1516
|
});
|
|
1293
1517
|
let e = "";
|
|
1294
1518
|
typeof window < "u" && typeof document < "u" && (e = window?.location?.hostname);
|
|
1295
|
-
let t =
|
|
1296
|
-
return (typeof window < "u" && typeof document < "u" && window.parent != window && t && window.supports_zerogpu_headers ?
|
|
1519
|
+
let t = Ge(e);
|
|
1520
|
+
return (typeof window < "u" && typeof document < "u" && window.parent != window && t && window.supports_zerogpu_headers ? Ee("zerogpu-headers", t) : Promise.resolve(null)).then((e) => {
|
|
1297
1521
|
let t = {
|
|
1298
|
-
...
|
|
1522
|
+
...S,
|
|
1299
1523
|
...e || {}
|
|
1300
1524
|
};
|
|
1301
|
-
return
|
|
1302
|
-
...
|
|
1525
|
+
return v(`${l.root}${x}/${d}?${L}`, {
|
|
1526
|
+
...N,
|
|
1303
1527
|
session_hash: f
|
|
1304
1528
|
}, t);
|
|
1305
1529
|
}).then(async ([e, t]) => {
|
|
1306
|
-
if (e.event_id && (
|
|
1530
|
+
if (e.event_id && (j = e.event_id), t === 503) R({
|
|
1307
1531
|
type: "status",
|
|
1308
1532
|
stage: "error",
|
|
1309
|
-
message:
|
|
1533
|
+
message: ie,
|
|
1310
1534
|
queue: !0,
|
|
1311
|
-
endpoint:
|
|
1312
|
-
fn_index:
|
|
1535
|
+
endpoint: M,
|
|
1536
|
+
fn_index: w,
|
|
1313
1537
|
time: /* @__PURE__ */ new Date(),
|
|
1314
1538
|
visible: !0
|
|
1315
|
-
}),
|
|
1316
|
-
else if (t === 422)
|
|
1539
|
+
}), V();
|
|
1540
|
+
else if (t === 422) R({
|
|
1317
1541
|
type: "status",
|
|
1318
1542
|
stage: "error",
|
|
1319
1543
|
message: e.detail,
|
|
1320
1544
|
queue: !0,
|
|
1321
|
-
endpoint:
|
|
1322
|
-
fn_index:
|
|
1545
|
+
endpoint: M,
|
|
1546
|
+
fn_index: w,
|
|
1323
1547
|
code: "validation_error",
|
|
1324
1548
|
time: /* @__PURE__ */ new Date(),
|
|
1325
1549
|
visible: !0
|
|
1326
|
-
}),
|
|
1550
|
+
}), V();
|
|
1327
1551
|
else if (t !== 200) {
|
|
1328
|
-
let t = e?.error ===
|
|
1329
|
-
|
|
1552
|
+
let t = e?.error === y;
|
|
1553
|
+
R({
|
|
1330
1554
|
type: "status",
|
|
1331
1555
|
stage: "error",
|
|
1332
1556
|
broken: t,
|
|
1333
|
-
message: t ?
|
|
1557
|
+
message: t ? y : e.detail || e.error,
|
|
1334
1558
|
queue: !0,
|
|
1335
|
-
endpoint:
|
|
1336
|
-
fn_index:
|
|
1559
|
+
endpoint: M,
|
|
1560
|
+
fn_index: w,
|
|
1337
1561
|
time: /* @__PURE__ */ new Date(),
|
|
1338
1562
|
visible: !0
|
|
1339
|
-
}),
|
|
1563
|
+
}), V();
|
|
1340
1564
|
} else {
|
|
1341
|
-
|
|
1565
|
+
P = e.event_id, j = P;
|
|
1342
1566
|
let t = async function(e) {
|
|
1343
1567
|
try {
|
|
1344
|
-
let { type: t, status: n, data: r, original_msg: i } =
|
|
1568
|
+
let { type: t, status: n, data: r, original_msg: i } = ve(e, I[w]);
|
|
1345
1569
|
if (t == "heartbeat") return;
|
|
1346
|
-
if (t === "update" && n && !
|
|
1570
|
+
if (t === "update" && n && !F) R({
|
|
1347
1571
|
type: "status",
|
|
1348
|
-
endpoint:
|
|
1349
|
-
fn_index:
|
|
1572
|
+
endpoint: M,
|
|
1573
|
+
fn_index: w,
|
|
1350
1574
|
time: /* @__PURE__ */ new Date(),
|
|
1351
1575
|
original_msg: i,
|
|
1352
1576
|
...n
|
|
1353
1577
|
});
|
|
1354
|
-
else if (t === "complete")
|
|
1578
|
+
else if (t === "complete") F = n;
|
|
1355
1579
|
else if (t == "unexpected_error" || t == "broken_connection") {
|
|
1356
1580
|
console.error("Unexpected error", n?.message);
|
|
1357
1581
|
let e = t === "broken_connection";
|
|
1358
|
-
|
|
1582
|
+
R({
|
|
1359
1583
|
type: "status",
|
|
1360
1584
|
stage: "error",
|
|
1361
1585
|
message: n?.message || "An Unexpected Error Occurred!",
|
|
1362
1586
|
queue: !0,
|
|
1363
|
-
endpoint:
|
|
1587
|
+
endpoint: M,
|
|
1364
1588
|
broken: e,
|
|
1365
1589
|
session_not_found: n?.session_not_found,
|
|
1366
|
-
fn_index:
|
|
1590
|
+
fn_index: w,
|
|
1367
1591
|
time: /* @__PURE__ */ new Date()
|
|
1368
1592
|
});
|
|
1369
1593
|
} else if (t === "log") {
|
|
1370
|
-
|
|
1594
|
+
R({
|
|
1371
1595
|
type: "log",
|
|
1372
1596
|
title: r.title,
|
|
1373
1597
|
log: r.log,
|
|
1374
1598
|
level: r.level,
|
|
1375
|
-
endpoint:
|
|
1599
|
+
endpoint: M,
|
|
1376
1600
|
duration: r.duration,
|
|
1377
1601
|
visible: r.visible,
|
|
1378
|
-
fn_index:
|
|
1602
|
+
fn_index: w
|
|
1379
1603
|
});
|
|
1380
1604
|
return;
|
|
1381
|
-
} else (t === "generating" || t === "streaming") && (
|
|
1605
|
+
} else (t === "generating" || t === "streaming") && (R({
|
|
1382
1606
|
type: "status",
|
|
1383
1607
|
time: /* @__PURE__ */ new Date(),
|
|
1384
1608
|
...n,
|
|
1385
1609
|
stage: n?.stage,
|
|
1386
1610
|
queue: !0,
|
|
1387
|
-
endpoint:
|
|
1388
|
-
fn_index:
|
|
1389
|
-
}), r &&
|
|
1611
|
+
endpoint: M,
|
|
1612
|
+
fn_index: w
|
|
1613
|
+
}), r && E.connection !== "stream" && [
|
|
1390
1614
|
"sse_v2",
|
|
1391
1615
|
"sse_v2.1",
|
|
1392
1616
|
"sse_v3"
|
|
1393
|
-
].includes(
|
|
1394
|
-
r && (
|
|
1617
|
+
].includes(D) && tt(ee, P, r));
|
|
1618
|
+
r && (R({
|
|
1395
1619
|
type: "data",
|
|
1396
1620
|
time: /* @__PURE__ */ new Date(),
|
|
1397
|
-
data:
|
|
1398
|
-
endpoint:
|
|
1399
|
-
fn_index:
|
|
1400
|
-
}), r.render_config && await
|
|
1621
|
+
data: G(r.data, E, l.components, "output", b.with_null_state),
|
|
1622
|
+
endpoint: M,
|
|
1623
|
+
fn_index: w
|
|
1624
|
+
}), r.render_config && await ge(r.render_config), F && (R({
|
|
1401
1625
|
type: "status",
|
|
1402
1626
|
time: /* @__PURE__ */ new Date(),
|
|
1403
|
-
...
|
|
1627
|
+
...F,
|
|
1404
1628
|
stage: n?.stage,
|
|
1405
1629
|
queue: !0,
|
|
1406
|
-
endpoint:
|
|
1407
|
-
fn_index:
|
|
1408
|
-
}),
|
|
1630
|
+
endpoint: M,
|
|
1631
|
+
fn_index: w
|
|
1632
|
+
}), V())), (n?.stage === "complete" || n?.stage === "error") && (_[P] && delete _[P], P in ee && delete ee[P], V());
|
|
1409
1633
|
} catch (e) {
|
|
1410
|
-
console.error("Unexpected client exception", e),
|
|
1634
|
+
console.error("Unexpected client exception", e), R({
|
|
1411
1635
|
type: "status",
|
|
1412
1636
|
stage: "error",
|
|
1413
1637
|
message: "An Unexpected Error Occurred!",
|
|
1414
1638
|
queue: !0,
|
|
1415
|
-
endpoint:
|
|
1416
|
-
fn_index:
|
|
1639
|
+
endpoint: M,
|
|
1640
|
+
fn_index: w,
|
|
1417
1641
|
time: /* @__PURE__ */ new Date()
|
|
1418
1642
|
}), [
|
|
1419
1643
|
"sse_v2",
|
|
1420
1644
|
"sse_v2.1",
|
|
1421
1645
|
"sse_v3"
|
|
1422
|
-
].includes(
|
|
1646
|
+
].includes(D) && (et(h, C.abort_controller), h.open = !1, V());
|
|
1423
1647
|
}
|
|
1424
1648
|
};
|
|
1425
|
-
|
|
1649
|
+
P in g && (g[P].forEach((e) => t(e)), delete g[P]), _[P] = t, te.add(P), h.open || await this.open_stream();
|
|
1426
1650
|
}
|
|
1427
1651
|
});
|
|
1428
1652
|
}
|
|
1429
1653
|
});
|
|
1430
|
-
|
|
1431
|
-
|
|
1654
|
+
_e.catch((e) => {
|
|
1655
|
+
R({
|
|
1432
1656
|
type: "status",
|
|
1433
1657
|
stage: "error",
|
|
1434
1658
|
message: e instanceof Error ? e.message : String(e),
|
|
1435
|
-
queue: !
|
|
1436
|
-
endpoint:
|
|
1437
|
-
fn_index:
|
|
1659
|
+
queue: !Te(w, l),
|
|
1660
|
+
endpoint: M,
|
|
1661
|
+
fn_index: w,
|
|
1438
1662
|
time: /* @__PURE__ */ new Date()
|
|
1439
|
-
}),
|
|
1663
|
+
}), V();
|
|
1440
1664
|
});
|
|
1441
|
-
let
|
|
1442
|
-
function
|
|
1443
|
-
for (
|
|
1665
|
+
let be = !1, z = [], B = [];
|
|
1666
|
+
function V() {
|
|
1667
|
+
for (be = !0; B.length > 0;) B.shift()({
|
|
1444
1668
|
value: void 0,
|
|
1445
1669
|
done: !0
|
|
1446
1670
|
});
|
|
1447
1671
|
}
|
|
1448
|
-
function
|
|
1449
|
-
|
|
1672
|
+
function H(e) {
|
|
1673
|
+
B.length > 0 ? B.shift()(e) : z.push(e);
|
|
1450
1674
|
}
|
|
1451
|
-
function
|
|
1452
|
-
|
|
1675
|
+
function xe(e) {
|
|
1676
|
+
H(zt(e)), V();
|
|
1453
1677
|
}
|
|
1454
|
-
function
|
|
1455
|
-
|
|
1678
|
+
function U(e) {
|
|
1679
|
+
H({
|
|
1456
1680
|
value: e,
|
|
1457
1681
|
done: !1
|
|
1458
1682
|
});
|
|
1459
1683
|
}
|
|
1460
|
-
function
|
|
1461
|
-
return
|
|
1684
|
+
function W() {
|
|
1685
|
+
return z.length > 0 ? Promise.resolve(z.shift()) : be ? Promise.resolve({
|
|
1462
1686
|
value: void 0,
|
|
1463
1687
|
done: !0
|
|
1464
|
-
}) : new Promise((e) =>
|
|
1688
|
+
}) : new Promise((e) => B.push(e));
|
|
1465
1689
|
}
|
|
1466
|
-
let
|
|
1467
|
-
[Symbol.asyncIterator]: () =>
|
|
1468
|
-
next:
|
|
1469
|
-
throw: async (e) => (
|
|
1470
|
-
return: async () => (
|
|
1690
|
+
let Se = {
|
|
1691
|
+
[Symbol.asyncIterator]: () => Se,
|
|
1692
|
+
next: W,
|
|
1693
|
+
throw: async (e) => (xe(e), W()),
|
|
1694
|
+
return: async () => (V(), {
|
|
1471
1695
|
value: void 0,
|
|
1472
1696
|
done: !0
|
|
1473
1697
|
}),
|
|
1474
|
-
cancel:
|
|
1698
|
+
cancel: me,
|
|
1475
1699
|
send_chunk: (e) => {
|
|
1476
|
-
this.post_data(`${l.root}${
|
|
1700
|
+
this.post_data(`${l.root}${x}/stream/${j}`, {
|
|
1477
1701
|
...e,
|
|
1478
1702
|
session_hash: this.session_hash
|
|
1479
1703
|
});
|
|
1480
1704
|
},
|
|
1481
1705
|
close_stream: () => {
|
|
1482
|
-
this.post_data(`${l.root}${
|
|
1706
|
+
this.post_data(`${l.root}${x}/stream/${j}/close`, {}), V();
|
|
1483
1707
|
},
|
|
1484
|
-
event_id: () =>
|
|
1485
|
-
wait_for_id: async () => (await
|
|
1708
|
+
event_id: () => j,
|
|
1709
|
+
wait_for_id: async () => (await _e, P)
|
|
1486
1710
|
};
|
|
1487
|
-
return
|
|
1711
|
+
return Se;
|
|
1488
1712
|
} catch (e) {
|
|
1489
1713
|
throw console.error("Submit function encountered an error:", e), e;
|
|
1490
1714
|
}
|
|
1491
1715
|
}
|
|
1492
|
-
function
|
|
1716
|
+
function zt(e) {
|
|
1493
1717
|
return { then: (t, n) => n(e) };
|
|
1494
1718
|
}
|
|
1495
|
-
function
|
|
1719
|
+
function Bt(e, t, n, r) {
|
|
1496
1720
|
let i, a, o;
|
|
1497
1721
|
if (typeof t == "number") i = t, a = e.unnamed_endpoints[i], o = r.dependencies.find((e) => e.id == t);
|
|
1498
1722
|
else {
|
|
@@ -1534,13 +1758,13 @@ var $ = class {
|
|
|
1534
1758
|
stream_instance = null;
|
|
1535
1759
|
current_payload;
|
|
1536
1760
|
get_url_config(e = null) {
|
|
1537
|
-
if (!this.config) throw Error(
|
|
1761
|
+
if (!this.config) throw Error(b);
|
|
1538
1762
|
e === null && (e = window.location.href);
|
|
1539
1763
|
let t = (e) => e.replace(/^\/+|\/+$/g, ""), n = t(new URL(this.config.root).pathname), r = t(new URL(e).pathname), i;
|
|
1540
1764
|
return i = r.startsWith(n) ? t(r.substring(n.length)) : "", this.get_page_config(i);
|
|
1541
1765
|
}
|
|
1542
1766
|
get_page_config(e) {
|
|
1543
|
-
if (!this.config) throw Error(
|
|
1767
|
+
if (!this.config) throw Error(b);
|
|
1544
1768
|
let t = this.config;
|
|
1545
1769
|
return e in t.page || (e = ""), {
|
|
1546
1770
|
...t,
|
|
@@ -1563,7 +1787,7 @@ var $ = class {
|
|
|
1563
1787
|
let t = new Headers();
|
|
1564
1788
|
return this && this.cookies && t.append("Cookie", this.cookies), this && this.options.headers && new Headers(this.options.headers).forEach((e, n) => {
|
|
1565
1789
|
t.append(n, e);
|
|
1566
|
-
}), this && this.options.token && t.append("Authorization", `Bearer ${this.options.token}`), this.abort_controller = new AbortController(), this.stream_instance =
|
|
1790
|
+
}), this && this.options.token && t.append("Authorization", `Bearer ${this.options.token}`), this.abort_controller = new AbortController(), this.stream_instance = it(e.toString(), {
|
|
1567
1791
|
credentials: this.options.credentials ?? "same-origin",
|
|
1568
1792
|
headers: t,
|
|
1569
1793
|
signal: this.abort_controller.signal
|
|
@@ -1580,20 +1804,20 @@ var $ = class {
|
|
|
1580
1804
|
resolve_config;
|
|
1581
1805
|
resolve_cookies;
|
|
1582
1806
|
constructor(e, t = { events: ["data"] }) {
|
|
1583
|
-
this.app_reference = e, this.deep_link = t.query_params?.deep_link || null, t.events ||= ["data"],
|
|
1807
|
+
this.app_reference = e, this.deep_link = t.query_params?.deep_link || null, t.events ||= ["data"], k(t), this.options = t, this.current_payload = {}, t.cookies && (this.cookies = t.cookies), this.view_api = be.bind(this), this.upload_files = z.bind(this), this.handle_blob = Oe.bind(this), this.post_data = Me.bind(this), this.submit = Rt.bind(this), this.predict = Ne.bind(this), this.open_stream = $e.bind(this), this.resolve_config = j.bind(this), this.resolve_cookies = N.bind(this), this.upload = H.bind(this), this.fetch = this.fetch.bind(this), this.handle_space_success = this.handle_space_success.bind(this), this.stream = this.stream.bind(this);
|
|
1584
1808
|
}
|
|
1585
1809
|
async init() {
|
|
1586
|
-
|
|
1810
|
+
Ke(), this.options.auth && await this.resolve_cookies(), await this._resolve_config().then((e) => e?.config && this._resolve_heartbeat(e.config));
|
|
1587
1811
|
try {
|
|
1588
1812
|
this.api_info = await this.view_api();
|
|
1589
1813
|
} catch (e) {
|
|
1590
1814
|
console.error(e.message);
|
|
1591
1815
|
}
|
|
1592
|
-
this.api_map =
|
|
1816
|
+
this.api_map = fe(this.config?.dependencies || []);
|
|
1593
1817
|
}
|
|
1594
1818
|
async _resolve_heartbeat(e) {
|
|
1595
|
-
if (e && (this.config = e, this.api_prefix = e.api_prefix || "", this.config && this.config.connect_heartbeat && this.config.space_id && this.options.token && (this.jwt = await
|
|
1596
|
-
let e = new URL(`${this.config.root}${this.api_prefix}/${
|
|
1819
|
+
if (e && (this.config = e, this.api_prefix = e.api_prefix || "", this.config && this.config.connect_heartbeat && this.config.space_id && this.options.token && (this.jwt = await de(this.config.space_id, this.options.token, this.cookies))), e.space_id && this.options.token && (this.jwt = await de(e.space_id, this.options.token)), this.config && this.config.connect_heartbeat) {
|
|
1820
|
+
let e = new URL(`${this.config.root}${this.api_prefix}/${_}/${this.session_hash}`);
|
|
1597
1821
|
this.jwt && e.searchParams.set("__sign", this.jwt), this.heartbeat_event ||= this.stream(e);
|
|
1598
1822
|
}
|
|
1599
1823
|
}
|
|
@@ -1602,7 +1826,7 @@ var $ = class {
|
|
|
1602
1826
|
return t.session_hash && (n.session_hash = t.session_hash), await n.init(), n;
|
|
1603
1827
|
}
|
|
1604
1828
|
async reconnect() {
|
|
1605
|
-
let e = new URL(`${this.config.root}${this.api_prefix}/${
|
|
1829
|
+
let e = new URL(`${this.config.root}${this.api_prefix}/${v}`), t;
|
|
1606
1830
|
try {
|
|
1607
1831
|
let n = await this.fetch(e);
|
|
1608
1832
|
if (!n.ok) throw Error();
|
|
@@ -1613,17 +1837,17 @@ var $ = class {
|
|
|
1613
1837
|
return t === this.config.app_id ? "connected" : "changed";
|
|
1614
1838
|
}
|
|
1615
1839
|
close() {
|
|
1616
|
-
this.closed = !0,
|
|
1840
|
+
this.closed = !0, et(this.stream_status, this.abort_controller);
|
|
1617
1841
|
}
|
|
1618
1842
|
async refresh() {
|
|
1619
|
-
if (!this.config) throw Error(
|
|
1843
|
+
if (!this.config) throw Error(b);
|
|
1620
1844
|
let e = await this.resolve_config(this.config.root, !1);
|
|
1621
|
-
if (!e) throw Error(
|
|
1622
|
-
this.config = e, this.api_prefix = e.api_prefix || "", this.api_map =
|
|
1845
|
+
if (!e) throw Error(b);
|
|
1846
|
+
this.config = e, this.api_prefix = e.api_prefix || "", this.api_map = fe(e.dependencies || []);
|
|
1623
1847
|
try {
|
|
1624
1848
|
this.api_info = await this.view_api();
|
|
1625
1849
|
} catch (e) {
|
|
1626
|
-
console.error(
|
|
1850
|
+
console.error(S + e.message);
|
|
1627
1851
|
}
|
|
1628
1852
|
return this.get_url_config();
|
|
1629
1853
|
}
|
|
@@ -1631,18 +1855,18 @@ var $ = class {
|
|
|
1631
1855
|
this.current_payload = e;
|
|
1632
1856
|
}
|
|
1633
1857
|
static async duplicate(e, t = { events: ["data"] }) {
|
|
1634
|
-
return
|
|
1858
|
+
return Be(e, t);
|
|
1635
1859
|
}
|
|
1636
1860
|
async _resolve_config() {
|
|
1637
|
-
let { http_protocol: e, host: t, space_id: n } = await
|
|
1638
|
-
n && r && await
|
|
1861
|
+
let { http_protocol: e, host: t, space_id: n } = await R(this.app_reference, this.options.token), { status_callback: r } = this.options;
|
|
1862
|
+
n && r && await Pe(n, r);
|
|
1639
1863
|
let i;
|
|
1640
1864
|
try {
|
|
1641
1865
|
let n = `${e}//${t}`;
|
|
1642
|
-
if (i = await this.resolve_config(n), !i) throw Error(
|
|
1866
|
+
if (i = await this.resolve_config(n), !i) throw Error(b);
|
|
1643
1867
|
return this.config_success(i);
|
|
1644
1868
|
} catch (e) {
|
|
1645
|
-
if (n && r)
|
|
1869
|
+
if (n && r) K(n, L.test(n) ? "space_name" : "subdomain", this.handle_space_success);
|
|
1646
1870
|
else throw r && r({
|
|
1647
1871
|
status: "error",
|
|
1648
1872
|
message: "Could not load this space.",
|
|
@@ -1652,19 +1876,22 @@ var $ = class {
|
|
|
1652
1876
|
}
|
|
1653
1877
|
}
|
|
1654
1878
|
async config_success(e) {
|
|
1655
|
-
if (this.config = e, this.api_prefix = e.api_prefix || "",
|
|
1879
|
+
if (this.config = e, this.api_prefix = e.api_prefix || "", e.run_history === !1 && At({
|
|
1880
|
+
app_id: e.app_id,
|
|
1881
|
+
username: e.username
|
|
1882
|
+
}), this.config.auth_required) return this.prepare_return_obj();
|
|
1656
1883
|
try {
|
|
1657
1884
|
this.api_info = await this.view_api();
|
|
1658
1885
|
} catch (e) {
|
|
1659
|
-
console.error(
|
|
1886
|
+
console.error(S + e.message);
|
|
1660
1887
|
}
|
|
1661
1888
|
return this.prepare_return_obj();
|
|
1662
1889
|
}
|
|
1663
1890
|
async handle_space_success(e) {
|
|
1664
|
-
if (!this) throw Error(
|
|
1891
|
+
if (!this) throw Error(b);
|
|
1665
1892
|
let { status_callback: t } = this.options;
|
|
1666
1893
|
if (t && t(e), e.status === "running") try {
|
|
1667
|
-
if (this.config = await this._resolve_config(), this.api_prefix = this?.config?.api_prefix || "", !this.config) throw Error(
|
|
1894
|
+
if (this.config = await this._resolve_config(), this.api_prefix = this?.config?.api_prefix || "", !this.config) throw Error(b);
|
|
1668
1895
|
return await this.config_success(this.config);
|
|
1669
1896
|
} catch (e) {
|
|
1670
1897
|
throw t && t({
|
|
@@ -1676,7 +1903,7 @@ var $ = class {
|
|
|
1676
1903
|
}
|
|
1677
1904
|
}
|
|
1678
1905
|
async component_server(e, t, n) {
|
|
1679
|
-
if (!this.config) throw Error(
|
|
1906
|
+
if (!this.config) throw Error(b);
|
|
1680
1907
|
let r = {}, { token: i } = this.options, { session_hash: a } = this;
|
|
1681
1908
|
i && (r.Authorization = `Bearer ${this.options.token}`);
|
|
1682
1909
|
let o, s = this.config.components.find((t) => t.id === e);
|
|
@@ -1695,7 +1922,7 @@ var $ = class {
|
|
|
1695
1922
|
}), r["Content-Type"] = "application/json";
|
|
1696
1923
|
i && (r.Authorization = `Bearer ${i}`);
|
|
1697
1924
|
try {
|
|
1698
|
-
let e = await this.fetch(`${o}${this.api_prefix}/${
|
|
1925
|
+
let e = await this.fetch(`${o}${this.api_prefix}/${te}/`, {
|
|
1699
1926
|
method: "POST",
|
|
1700
1927
|
body: c,
|
|
1701
1928
|
headers: r,
|
|
@@ -1708,7 +1935,7 @@ var $ = class {
|
|
|
1708
1935
|
}
|
|
1709
1936
|
}
|
|
1710
1937
|
set_cookies(e) {
|
|
1711
|
-
this.cookies =
|
|
1938
|
+
this.cookies = I(e).join("; ");
|
|
1712
1939
|
}
|
|
1713
1940
|
prepare_return_obj() {
|
|
1714
1941
|
return {
|
|
@@ -1720,11 +1947,11 @@ var $ = class {
|
|
|
1720
1947
|
};
|
|
1721
1948
|
}
|
|
1722
1949
|
};
|
|
1723
|
-
async function
|
|
1950
|
+
async function Vt(e, t = { events: ["data"] }) {
|
|
1724
1951
|
return await $.connect(e, t);
|
|
1725
1952
|
}
|
|
1726
|
-
async function
|
|
1953
|
+
async function Ht(e, t) {
|
|
1727
1954
|
return await $.duplicate(e, t);
|
|
1728
1955
|
}
|
|
1729
1956
|
//#endregion
|
|
1730
|
-
export { $ as Client,
|
|
1957
|
+
export { $ as Client, U as FileData, ae as MISSING_CREDENTIALS_MSG, At as clear_run_history, Vt as client, Nt as consume_run_history_replay, jt as delete_run_history, Ht as duplicate, De as handle_file, Lt as on_run_history_change, Ne as predict, xe as prepare_files, kt as read_run_history, lt as run_history_url, Mt as stage_run_history_replay, Rt as submit, o as t, H as upload, z as upload_files };
|