@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/index.min.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,15 +615,15 @@ function X(e, t, n, r, i = !1) {
|
|
|
615
615
|
}
|
|
616
616
|
//#endregion
|
|
617
617
|
//#region __vite-browser-external
|
|
618
|
-
var
|
|
618
|
+
var Oe = /* @__PURE__ */ o(((e, t) => {
|
|
619
619
|
t.exports = {};
|
|
620
620
|
}));
|
|
621
621
|
//#endregion
|
|
622
622
|
//#region src/utils/handle_blob.ts
|
|
623
|
-
async function
|
|
623
|
+
async function ke(e, t, n) {
|
|
624
624
|
let r = this;
|
|
625
|
-
await
|
|
626
|
-
let i = await
|
|
625
|
+
await Ae(r, t);
|
|
626
|
+
let i = await we(t, void 0, [], !0, n);
|
|
627
627
|
return (await Promise.all(i.map(async ({ path: t, blob: n, type: i }) => {
|
|
628
628
|
if (!n) return {
|
|
629
629
|
path: t,
|
|
@@ -637,40 +637,40 @@ async function we(e, t, n) {
|
|
|
637
637
|
name: typeof File < "u" && n instanceof File ? n?.name : void 0
|
|
638
638
|
};
|
|
639
639
|
}))).forEach(({ path: e, file_url: n, type: r, name: i }) => {
|
|
640
|
-
r === "Gallery" ?
|
|
640
|
+
r === "Gallery" ? Ce(t, n, e) : n && Ce(t, new U({
|
|
641
641
|
path: n,
|
|
642
642
|
orig_name: i
|
|
643
643
|
}), e);
|
|
644
644
|
}), t;
|
|
645
645
|
}
|
|
646
|
-
async function
|
|
647
|
-
if (!(e.config?.root || e.config?.root_url)) throw Error(
|
|
648
|
-
await
|
|
646
|
+
async function Ae(e, t) {
|
|
647
|
+
if (!(e.config?.root || e.config?.root_url)) throw Error(O);
|
|
648
|
+
await je(e, t);
|
|
649
649
|
}
|
|
650
|
-
async function
|
|
651
|
-
for (let r in t) t[r] instanceof
|
|
650
|
+
async function je(e, t, n = []) {
|
|
651
|
+
for (let r in t) t[r] instanceof W ? await Me(e, t, r) : typeof t[r] == "object" && t[r] !== null && await je(e, t[r], [...n, r]);
|
|
652
652
|
}
|
|
653
|
-
async function
|
|
653
|
+
async function Me(e, t, n) {
|
|
654
654
|
let r = t[n], i = e.config?.root || e.config?.root_url;
|
|
655
|
-
if (!i) throw Error(
|
|
655
|
+
if (!i) throw Error(O);
|
|
656
656
|
try {
|
|
657
657
|
let a, o;
|
|
658
658
|
if (typeof process < "u" && process.versions && process.versions.node) {
|
|
659
|
-
let e = await Promise.resolve().then(() => /* @__PURE__ */ c(
|
|
660
|
-
o = (await Promise.resolve().then(() => /* @__PURE__ */ c(
|
|
661
|
-
} else throw Error(
|
|
659
|
+
let e = await Promise.resolve().then(() => /* @__PURE__ */ c(Oe(), 1));
|
|
660
|
+
o = (await Promise.resolve().then(() => /* @__PURE__ */ c(Oe(), 1))).resolve(process.cwd(), r.meta.path), a = await e.readFile(o);
|
|
661
|
+
} else throw Error(le);
|
|
662
662
|
let s = new Blob([a], { type: "application/octet-stream" }), l = await e.upload_files(i, [s]), u = l.files && l.files[0];
|
|
663
|
-
u && (t[n] = new
|
|
663
|
+
u && (t[n] = new U({
|
|
664
664
|
path: u,
|
|
665
665
|
orig_name: r.meta.name || ""
|
|
666
666
|
}));
|
|
667
667
|
} catch (e) {
|
|
668
|
-
console.error(
|
|
668
|
+
console.error(ue, e);
|
|
669
669
|
}
|
|
670
670
|
}
|
|
671
671
|
//#endregion
|
|
672
672
|
//#region src/utils/post_data.ts
|
|
673
|
-
async function
|
|
673
|
+
async function Ne(e, t, n) {
|
|
674
674
|
let r = { "Content-Type": "application/json" };
|
|
675
675
|
this.options.token && (r.Authorization = `Bearer ${this.options.token}`);
|
|
676
676
|
try {
|
|
@@ -684,7 +684,7 @@ async function Oe(e, t, n) {
|
|
|
684
684
|
credentials: this.options.credentials ?? "same-origin"
|
|
685
685
|
});
|
|
686
686
|
} catch {
|
|
687
|
-
return [{ error:
|
|
687
|
+
return [{ error: y }, 500];
|
|
688
688
|
}
|
|
689
689
|
let a, o;
|
|
690
690
|
try {
|
|
@@ -696,7 +696,7 @@ async function Oe(e, t, n) {
|
|
|
696
696
|
}
|
|
697
697
|
//#endregion
|
|
698
698
|
//#region src/utils/predict.ts
|
|
699
|
-
async function
|
|
699
|
+
async function Pe(e, t = {}) {
|
|
700
700
|
let n = !1, r = !1;
|
|
701
701
|
if (!this.config) throw Error("Could not resolve app config");
|
|
702
702
|
if (typeof e == "number") this.config.dependencies.find((t) => t.id == e);
|
|
@@ -719,7 +719,7 @@ async function ke(e, t = {}) {
|
|
|
719
719
|
}
|
|
720
720
|
//#endregion
|
|
721
721
|
//#region src/helpers/spaces.ts
|
|
722
|
-
async function
|
|
722
|
+
async function K(e, t, n) {
|
|
723
723
|
let r = t === "subdomain" ? `https://huggingface.co/api/spaces/by-subdomain/${e}` : `https://huggingface.co/api/spaces/${e}`, i, a;
|
|
724
724
|
try {
|
|
725
725
|
if (i = await fetch(r), a = i.status, a !== 200) throw Error();
|
|
@@ -728,7 +728,7 @@ async function Z(e, t, n) {
|
|
|
728
728
|
n({
|
|
729
729
|
status: "error",
|
|
730
730
|
load_status: "error",
|
|
731
|
-
message:
|
|
731
|
+
message: x,
|
|
732
732
|
detail: "NOT_FOUND"
|
|
733
733
|
});
|
|
734
734
|
return;
|
|
@@ -744,7 +744,7 @@ async function Z(e, t, n) {
|
|
|
744
744
|
message: "Space is asleep. Waking it up...",
|
|
745
745
|
detail: o
|
|
746
746
|
}), setTimeout(() => {
|
|
747
|
-
|
|
747
|
+
K(e, t, n);
|
|
748
748
|
}, 1e3);
|
|
749
749
|
break;
|
|
750
750
|
case "PAUSED":
|
|
@@ -753,7 +753,7 @@ async function Z(e, t, n) {
|
|
|
753
753
|
load_status: "error",
|
|
754
754
|
message: "This space has been paused by the author. If you would like to try this demo, consider duplicating the space.",
|
|
755
755
|
detail: o,
|
|
756
|
-
discussions_enabled: await
|
|
756
|
+
discussions_enabled: await Le(s)
|
|
757
757
|
});
|
|
758
758
|
break;
|
|
759
759
|
case "RUNNING":
|
|
@@ -772,7 +772,7 @@ async function Z(e, t, n) {
|
|
|
772
772
|
message: "Space is building...",
|
|
773
773
|
detail: o
|
|
774
774
|
}), setTimeout(() => {
|
|
775
|
-
|
|
775
|
+
K(e, t, n);
|
|
776
776
|
}, 1e3);
|
|
777
777
|
break;
|
|
778
778
|
case "APP_STARTING":
|
|
@@ -782,7 +782,7 @@ async function Z(e, t, n) {
|
|
|
782
782
|
message: "Space is starting...",
|
|
783
783
|
detail: o
|
|
784
784
|
}), setTimeout(() => {
|
|
785
|
-
|
|
785
|
+
K(e, t, n);
|
|
786
786
|
}, 1e3);
|
|
787
787
|
break;
|
|
788
788
|
default:
|
|
@@ -791,30 +791,30 @@ async function Z(e, t, n) {
|
|
|
791
791
|
load_status: "error",
|
|
792
792
|
message: "This space is experiencing an issue.",
|
|
793
793
|
detail: o,
|
|
794
|
-
discussions_enabled: await
|
|
794
|
+
discussions_enabled: await Le(s)
|
|
795
795
|
});
|
|
796
796
|
break;
|
|
797
797
|
}
|
|
798
798
|
}
|
|
799
|
-
var
|
|
799
|
+
var Fe = async (e, t) => {
|
|
800
800
|
let n = 0;
|
|
801
801
|
return new Promise((r) => {
|
|
802
|
-
|
|
802
|
+
K(e, L.test(e) ? "space_name" : "subdomain", (i) => {
|
|
803
803
|
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(() => {
|
|
804
|
-
|
|
804
|
+
Fe(e, t).then(r);
|
|
805
805
|
}, 5e3)) : r());
|
|
806
806
|
});
|
|
807
807
|
});
|
|
808
|
-
},
|
|
809
|
-
async function
|
|
808
|
+
}, Ie = /^(?=[^]*\b[dD]iscussions{0,1}\b)(?=[^]*\b[dD]isabled\b)[^]*$/;
|
|
809
|
+
async function Le(e) {
|
|
810
810
|
try {
|
|
811
811
|
let t = await fetch(`https://huggingface.co/api/spaces/${e}/discussions`, { method: "HEAD" }), n = t.headers.get("x-error-message");
|
|
812
|
-
return !(!t.ok || n &&
|
|
812
|
+
return !(!t.ok || n && Ie.test(n));
|
|
813
813
|
} catch {
|
|
814
814
|
return !1;
|
|
815
815
|
}
|
|
816
816
|
}
|
|
817
|
-
async function
|
|
817
|
+
async function Re(e, t) {
|
|
818
818
|
let n = {};
|
|
819
819
|
t && (n.Authorization = `Bearer ${t}`);
|
|
820
820
|
try {
|
|
@@ -826,12 +826,12 @@ async function Ne(e, t) {
|
|
|
826
826
|
throw Error(e.message);
|
|
827
827
|
}
|
|
828
828
|
}
|
|
829
|
-
async function
|
|
829
|
+
async function ze(e, t, n) {
|
|
830
830
|
let r = {};
|
|
831
831
|
n && (r.Authorization = `Bearer ${n}`);
|
|
832
832
|
let i = { seconds: t };
|
|
833
833
|
try {
|
|
834
|
-
let t = await fetch(`https://huggingface.co/api/spaces/${e}/${
|
|
834
|
+
let t = await fetch(`https://huggingface.co/api/spaces/${e}/${ee}`, {
|
|
835
835
|
method: "POST",
|
|
836
836
|
headers: {
|
|
837
837
|
"Content-Type": "application/json",
|
|
@@ -845,7 +845,7 @@ async function Pe(e, t, n) {
|
|
|
845
845
|
throw Error(e.message);
|
|
846
846
|
}
|
|
847
847
|
}
|
|
848
|
-
var
|
|
848
|
+
var Be = [
|
|
849
849
|
"cpu-basic",
|
|
850
850
|
"cpu-upgrade",
|
|
851
851
|
"cpu-xl",
|
|
@@ -862,14 +862,14 @@ var Fe = [
|
|
|
862
862
|
];
|
|
863
863
|
//#endregion
|
|
864
864
|
//#region src/utils/duplicate.ts
|
|
865
|
-
async function
|
|
866
|
-
|
|
865
|
+
async function Ve(e, t) {
|
|
866
|
+
k(t);
|
|
867
867
|
let { token: n, private: r, hardware: i, timeout: a, auth: o } = t;
|
|
868
|
-
if (i && !
|
|
869
|
-
let { http_protocol: s, host: c } = await
|
|
868
|
+
if (i && !Be.includes(i)) throw Error(`Invalid hardware type provided. Valid types are: ${Be.map((e) => `"${e}"`).join(",")}.`);
|
|
869
|
+
let { http_protocol: s, host: c } = await R(e, n), l = null;
|
|
870
870
|
if (o) {
|
|
871
|
-
let e = await
|
|
872
|
-
e && (l =
|
|
871
|
+
let e = await P(s, c, o, fetch, void 0, t.credentials);
|
|
872
|
+
e && (l = I(e));
|
|
873
873
|
}
|
|
874
874
|
let u = {
|
|
875
875
|
Authorization: `Bearer ${n}`,
|
|
@@ -879,9 +879,9 @@ async function Ie(e, t) {
|
|
|
879
879
|
r && (p.private = !0);
|
|
880
880
|
let m;
|
|
881
881
|
try {
|
|
882
|
-
i || (m = await
|
|
882
|
+
i || (m = await Re(e, n));
|
|
883
883
|
} catch (e) {
|
|
884
|
-
throw Error(
|
|
884
|
+
throw Error(C + e.message);
|
|
885
885
|
}
|
|
886
886
|
p.hardware = i || m || "cpu-basic";
|
|
887
887
|
try {
|
|
@@ -897,35 +897,35 @@ async function Ie(e, t) {
|
|
|
897
897
|
}
|
|
898
898
|
else if (r.status !== 200) throw Error(r.statusText);
|
|
899
899
|
let i = await r.json();
|
|
900
|
-
return await
|
|
900
|
+
return await ze(`${d}/${f}`, a || 300, n), await $.connect(He(i.url), t);
|
|
901
901
|
} catch (e) {
|
|
902
902
|
throw Error(e);
|
|
903
903
|
}
|
|
904
904
|
}
|
|
905
|
-
function
|
|
905
|
+
function He(e) {
|
|
906
906
|
let t = e.match(/https:\/\/huggingface.co\/spaces\/([^/]+\/[^/]+)/);
|
|
907
907
|
if (t) return t[1];
|
|
908
908
|
}
|
|
909
909
|
//#endregion
|
|
910
910
|
//#region src/helpers/zerogpu.ts
|
|
911
|
-
var
|
|
912
|
-
function
|
|
911
|
+
var Ue = "supports-zerogpu-headers", We = !1;
|
|
912
|
+
function Ge() {
|
|
913
913
|
return typeof window < "u" && typeof document < "u" && typeof window.addEventListener == "function";
|
|
914
914
|
}
|
|
915
|
-
function
|
|
915
|
+
function Ke(e) {
|
|
916
916
|
return e.includes(".dev.") ? `https://moon-${e.split(".")[1]}.dev.spaces.huggingface.tech` : e.endsWith(".hf.space") ? "https://huggingface.co" : null;
|
|
917
917
|
}
|
|
918
|
-
function
|
|
919
|
-
if (!
|
|
918
|
+
function qe() {
|
|
919
|
+
if (!Ge() || We) return;
|
|
920
920
|
window.addEventListener("message", (e) => {
|
|
921
|
-
e.data ===
|
|
922
|
-
}),
|
|
923
|
-
let e =
|
|
924
|
-
e && window.parent !== window && window.parent.postMessage(
|
|
921
|
+
e.data === Ue && (window.supports_zerogpu_headers = !0);
|
|
922
|
+
}), We = !0;
|
|
923
|
+
let e = Ke(window.location.hostname);
|
|
924
|
+
e && window.parent !== window && window.parent.postMessage(Ue, e);
|
|
925
925
|
}
|
|
926
926
|
//#endregion
|
|
927
927
|
//#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
|
|
928
|
-
var
|
|
928
|
+
var Je = class extends TransformStream {
|
|
929
929
|
#e = "";
|
|
930
930
|
constructor(e = { allowCR: !1 }) {
|
|
931
931
|
super({
|
|
@@ -952,22 +952,22 @@ var Ue = class extends TransformStream {
|
|
|
952
952
|
};
|
|
953
953
|
//#endregion
|
|
954
954
|
//#region ../../node_modules/.pnpm/fetch-event-stream@0.1.6/node_modules/fetch-event-stream/esm/utils.js
|
|
955
|
-
function
|
|
956
|
-
let t = new TextDecoderStream(), n = new
|
|
955
|
+
function Ye(e) {
|
|
956
|
+
let t = new TextDecoderStream(), n = new Je({ allowCR: !0 });
|
|
957
957
|
return e.pipeThrough(t).pipeThrough(n);
|
|
958
958
|
}
|
|
959
|
-
function
|
|
959
|
+
function Xe(e) {
|
|
960
960
|
let t = /[:]\s*/.exec(e), n = t && t.index;
|
|
961
961
|
if (n) return [e.substring(0, n), e.substring(n + t[0].length)];
|
|
962
962
|
}
|
|
963
|
-
function
|
|
963
|
+
function Ze(e, t, n) {
|
|
964
964
|
e.get(t) || e.set(t, n);
|
|
965
965
|
}
|
|
966
966
|
//#endregion
|
|
967
967
|
//#region ../../node_modules/.pnpm/fetch-event-stream@0.1.6/node_modules/fetch-event-stream/esm/mod.js
|
|
968
|
-
async function*
|
|
968
|
+
async function* Qe(e, t) {
|
|
969
969
|
if (!e.body) return;
|
|
970
|
-
let n =
|
|
970
|
+
let n = Ye(e.body), r, i = n.getReader(), a;
|
|
971
971
|
for (;;) {
|
|
972
972
|
if (t && t.aborted) return i.cancel();
|
|
973
973
|
if (r = await i.read(), r.done) return;
|
|
@@ -975,20 +975,20 @@ async function* qe(e, t) {
|
|
|
975
975
|
a && (yield a), a = void 0;
|
|
976
976
|
continue;
|
|
977
977
|
}
|
|
978
|
-
let [e, n] =
|
|
978
|
+
let [e, n] = Xe(r.value) || [];
|
|
979
979
|
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);
|
|
980
980
|
}
|
|
981
981
|
}
|
|
982
|
-
async function
|
|
982
|
+
async function $e(e, t) {
|
|
983
983
|
let n = new Request(e, t);
|
|
984
|
-
|
|
984
|
+
Ze(n.headers, "Accept", "text/event-stream"), Ze(n.headers, "Content-Type", "application/json");
|
|
985
985
|
let r = await fetch(n);
|
|
986
986
|
if (!r.ok) throw r;
|
|
987
|
-
return
|
|
987
|
+
return Qe(r, n.signal);
|
|
988
988
|
}
|
|
989
989
|
//#endregion
|
|
990
990
|
//#region src/utils/stream.ts
|
|
991
|
-
async function
|
|
991
|
+
async function et() {
|
|
992
992
|
let { event_callbacks: e, unclosed_events: t, pending_stream_messages: n, stream_status: r, config: i, jwt: a } = this, o = this;
|
|
993
993
|
if (!i) throw Error("Could not resolve app config");
|
|
994
994
|
r.open = !0;
|
|
@@ -1000,7 +1000,7 @@ async function Ye() {
|
|
|
1000
1000
|
s.onmessage = async function(a) {
|
|
1001
1001
|
let s = JSON.parse(a.data);
|
|
1002
1002
|
if (s.msg === "close_stream") {
|
|
1003
|
-
|
|
1003
|
+
tt(r, o.abort_controller);
|
|
1004
1004
|
return;
|
|
1005
1005
|
}
|
|
1006
1006
|
let c = s.event_id;
|
|
@@ -1019,27 +1019,27 @@ async function Ye() {
|
|
|
1019
1019
|
}, s.onerror = async function(t) {
|
|
1020
1020
|
console.error(t), await Promise.all(Object.keys(e).map((t) => e[t]({
|
|
1021
1021
|
msg: "broken_connection",
|
|
1022
|
-
message:
|
|
1022
|
+
message: y
|
|
1023
1023
|
})));
|
|
1024
1024
|
};
|
|
1025
1025
|
}
|
|
1026
|
-
function
|
|
1026
|
+
function tt(e, t) {
|
|
1027
1027
|
e && (e.open = !1, t?.abort());
|
|
1028
1028
|
}
|
|
1029
|
-
function
|
|
1029
|
+
function nt(e, t, n) {
|
|
1030
1030
|
e[t] ? n.data.forEach((r, i) => {
|
|
1031
|
-
let a =
|
|
1031
|
+
let a = rt(i < e[t].length ? e[t][i] : null, r);
|
|
1032
1032
|
e[t][i] = a, n.data[i] = a;
|
|
1033
1033
|
}) : (e[t] = [], n.data.forEach((n, r) => {
|
|
1034
1034
|
e[t][r] = n;
|
|
1035
1035
|
}));
|
|
1036
1036
|
}
|
|
1037
|
-
function
|
|
1037
|
+
function rt(e, t) {
|
|
1038
1038
|
return t.forEach(([t, n, r]) => {
|
|
1039
|
-
e =
|
|
1039
|
+
e = it(e, n, t, r);
|
|
1040
1040
|
}), e;
|
|
1041
1041
|
}
|
|
1042
|
-
function
|
|
1042
|
+
function it(e, t, n, r) {
|
|
1043
1043
|
if (t.length === 0) {
|
|
1044
1044
|
if (n === "replace") return r;
|
|
1045
1045
|
if (n === "append") return e + r;
|
|
@@ -1065,7 +1065,7 @@ function Qe(e, t, n, r) {
|
|
|
1065
1065
|
}
|
|
1066
1066
|
return e;
|
|
1067
1067
|
}
|
|
1068
|
-
function
|
|
1068
|
+
function at(e, t = {}) {
|
|
1069
1069
|
let n = {
|
|
1070
1070
|
close: () => {
|
|
1071
1071
|
console.warn("Method not implemented.");
|
|
@@ -1089,7 +1089,7 @@ function $e(e, t = {}) {
|
|
|
1089
1089
|
throw Error("Method not implemented.");
|
|
1090
1090
|
}
|
|
1091
1091
|
};
|
|
1092
|
-
return
|
|
1092
|
+
return $e(e, t).then(async (e) => {
|
|
1093
1093
|
n.readyState = n.OPEN;
|
|
1094
1094
|
try {
|
|
1095
1095
|
for await (let t of e) n.onmessage && n.onmessage(t);
|
|
@@ -1102,32 +1102,255 @@ function $e(e, t = {}) {
|
|
|
1102
1102
|
}), n;
|
|
1103
1103
|
}
|
|
1104
1104
|
//#endregion
|
|
1105
|
+
//#region src/utils/run_history.ts
|
|
1106
|
+
var ot = "gradio:run-history:", q = `${ot}v2:`, st = `${ot}replay:v2:`, ct = 100, lt = 8;
|
|
1107
|
+
function J(e, t) {
|
|
1108
|
+
try {
|
|
1109
|
+
return e();
|
|
1110
|
+
} catch (e) {
|
|
1111
|
+
return console.warn("Could not update the run history.", e), t;
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
function ut(e, t = "/gradio_api") {
|
|
1115
|
+
return `${e.replace(/\/+$/, "")}${t}/runs`;
|
|
1116
|
+
}
|
|
1117
|
+
function Y(e) {
|
|
1118
|
+
if (typeof window > "u") return null;
|
|
1119
|
+
let t = e?.app_id;
|
|
1120
|
+
if (t == null || t === "") return null;
|
|
1121
|
+
try {
|
|
1122
|
+
return window.localStorage ? `${q}${t}${e?.username ? `:user:${encodeURIComponent(e.username)}` : ""}` : null;
|
|
1123
|
+
} catch {
|
|
1124
|
+
return null;
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
function dt(e) {
|
|
1128
|
+
let t = Y(e);
|
|
1129
|
+
return t ? t.replace(q, st) : null;
|
|
1130
|
+
}
|
|
1131
|
+
function ft(e) {
|
|
1132
|
+
try {
|
|
1133
|
+
let t = JSON.parse(window.localStorage.getItem(e) || "[]");
|
|
1134
|
+
return Array.isArray(t) && t.length && Date.parse(t[0]?.started_at) || 0;
|
|
1135
|
+
} catch {
|
|
1136
|
+
return 0;
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
function pt(e) {
|
|
1140
|
+
let t = Object.keys(window.localStorage).filter((e) => e.startsWith(ot)), n = [...t.filter((e) => !e.startsWith(q) && !e.startsWith(st)), ...t.filter((t) => t.startsWith(q) && t !== e).sort((e, t) => ft(t) - ft(e)).slice(lt - 1)];
|
|
1141
|
+
for (let e of n) try {
|
|
1142
|
+
window.localStorage.removeItem(e), window.sessionStorage.removeItem(e.replace(q, st));
|
|
1143
|
+
} catch {}
|
|
1144
|
+
}
|
|
1145
|
+
function mt() {
|
|
1146
|
+
return typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
1147
|
+
}
|
|
1148
|
+
function X(e) {
|
|
1149
|
+
let t = /* @__PURE__ */ new WeakSet();
|
|
1150
|
+
try {
|
|
1151
|
+
return JSON.parse(JSON.stringify(e, (e, n) => {
|
|
1152
|
+
if (typeof n == "bigint") return n.toString();
|
|
1153
|
+
if (typeof n == "object" && n) {
|
|
1154
|
+
if (t.has(n)) return "[Circular]";
|
|
1155
|
+
t.add(n);
|
|
1156
|
+
}
|
|
1157
|
+
return n;
|
|
1158
|
+
}));
|
|
1159
|
+
} catch {
|
|
1160
|
+
return "[Unserializable value]";
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
function Z(e) {
|
|
1164
|
+
let t = Y(e);
|
|
1165
|
+
if (!t) return [];
|
|
1166
|
+
try {
|
|
1167
|
+
let e = JSON.parse(window.localStorage.getItem(t) || "[]");
|
|
1168
|
+
return Array.isArray(e) ? e : [];
|
|
1169
|
+
} catch {
|
|
1170
|
+
return [];
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
function ht(e, t) {
|
|
1174
|
+
let n = Y(e);
|
|
1175
|
+
if (!n) return;
|
|
1176
|
+
let r = t.slice(0, ct), i = !1;
|
|
1177
|
+
for (; r.length > 0;) try {
|
|
1178
|
+
window.localStorage.setItem(n, JSON.stringify(r));
|
|
1179
|
+
return;
|
|
1180
|
+
} catch {
|
|
1181
|
+
if (!i) {
|
|
1182
|
+
i = !0, pt(n);
|
|
1183
|
+
continue;
|
|
1184
|
+
}
|
|
1185
|
+
r = r.slice(0, -1);
|
|
1186
|
+
}
|
|
1187
|
+
try {
|
|
1188
|
+
window.localStorage.removeItem(n);
|
|
1189
|
+
} catch {}
|
|
1190
|
+
}
|
|
1191
|
+
function gt(e) {
|
|
1192
|
+
let t = Y(e);
|
|
1193
|
+
if (t) {
|
|
1194
|
+
try {
|
|
1195
|
+
window.localStorage.removeItem(t);
|
|
1196
|
+
} catch {}
|
|
1197
|
+
yt();
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
function _t(e, t) {
|
|
1201
|
+
ht(e, Z(e).filter((e) => e.id !== t)), yt();
|
|
1202
|
+
}
|
|
1203
|
+
var vt = "gradio:run-history-change";
|
|
1204
|
+
function yt() {
|
|
1205
|
+
if (!(typeof window > "u")) try {
|
|
1206
|
+
window.dispatchEvent(new Event(vt));
|
|
1207
|
+
} catch {}
|
|
1208
|
+
}
|
|
1209
|
+
function bt(e) {
|
|
1210
|
+
return typeof window > "u" ? () => {} : (window.addEventListener(vt, e), window.addEventListener("storage", e), () => {
|
|
1211
|
+
window.removeEventListener(vt, e), window.removeEventListener("storage", e);
|
|
1212
|
+
});
|
|
1213
|
+
}
|
|
1214
|
+
function xt(e, t) {
|
|
1215
|
+
let n = dt(e);
|
|
1216
|
+
if (n) try {
|
|
1217
|
+
window.sessionStorage.setItem(n, JSON.stringify(t));
|
|
1218
|
+
} catch {}
|
|
1219
|
+
}
|
|
1220
|
+
function St(e) {
|
|
1221
|
+
let t = dt(e);
|
|
1222
|
+
if (!t) return null;
|
|
1223
|
+
try {
|
|
1224
|
+
let e = window.sessionStorage.getItem(t);
|
|
1225
|
+
return window.sessionStorage.removeItem(t), e ? JSON.parse(e) : null;
|
|
1226
|
+
} catch {
|
|
1227
|
+
return null;
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
function Ct(e) {
|
|
1231
|
+
let t = Y(e);
|
|
1232
|
+
if (!t) return null;
|
|
1233
|
+
pt(t);
|
|
1234
|
+
let n = {
|
|
1235
|
+
id: mt(),
|
|
1236
|
+
endpoint: e.endpoint,
|
|
1237
|
+
api_name: e.api_name,
|
|
1238
|
+
fn_index: e.fn_index,
|
|
1239
|
+
page: `${window.location.pathname}${window.location.search}`,
|
|
1240
|
+
inputs: X(e.inputs),
|
|
1241
|
+
outputs: null,
|
|
1242
|
+
...e.input_components ? { input_components: X(e.input_components) } : {},
|
|
1243
|
+
...e.output_components ? { output_components: X(e.output_components) } : {},
|
|
1244
|
+
status: "running",
|
|
1245
|
+
started_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1246
|
+
};
|
|
1247
|
+
return ht(e, [n, ...Z(e)]), yt(), n.id;
|
|
1248
|
+
}
|
|
1249
|
+
function wt(e, t, n) {
|
|
1250
|
+
if (!t) return;
|
|
1251
|
+
let r = Z(e), i = r.find((e) => e.id === t);
|
|
1252
|
+
i && (i.inputs = X(n), ht(e, r));
|
|
1253
|
+
}
|
|
1254
|
+
function Tt(e, t, n) {
|
|
1255
|
+
if (!t) return;
|
|
1256
|
+
let r = Z(e), i = r.find((e) => e.id === t);
|
|
1257
|
+
if (!i) return;
|
|
1258
|
+
let a = !1;
|
|
1259
|
+
if (n.type === "data") i.outputs = X(n.data), Q.set(t, i.outputs);
|
|
1260
|
+
else if (n.type === "status" && n.original_msg === "process_starts") Ot(i, n.time);
|
|
1261
|
+
else if (n.type === "status" && (n.stage === "generating" || n.stage === "streaming")) i.streamed = !0;
|
|
1262
|
+
else if (n.type === "status" && n.stage === "complete") i.status = "completed", kt(i, n), a = !0;
|
|
1263
|
+
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"), kt(i, n), a = !0;
|
|
1264
|
+
else return;
|
|
1265
|
+
if (a) Q.has(t) && (i.outputs = Q.get(t)), Q.delete(t), Dt.delete(t);
|
|
1266
|
+
else if (i.streamed) {
|
|
1267
|
+
if (Date.now() - (Dt.get(t) ?? 0) < Et) return;
|
|
1268
|
+
Dt.set(t, Date.now()), Q.delete(t);
|
|
1269
|
+
}
|
|
1270
|
+
ht(e, r);
|
|
1271
|
+
}
|
|
1272
|
+
var Et = 500, Dt = /* @__PURE__ */ new Map(), Q = /* @__PURE__ */ new Map();
|
|
1273
|
+
function Ot(e, t) {
|
|
1274
|
+
if (e.process_started_at) return;
|
|
1275
|
+
let n = t || /* @__PURE__ */ new Date();
|
|
1276
|
+
e.process_started_at = n.toISOString(), e.queued_ms = Math.max(0, n.getTime() - Date.parse(e.started_at));
|
|
1277
|
+
}
|
|
1278
|
+
function kt(e, t) {
|
|
1279
|
+
let n = t.time || /* @__PURE__ */ new Date();
|
|
1280
|
+
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));
|
|
1281
|
+
}
|
|
1282
|
+
function At(e) {
|
|
1283
|
+
return J(() => Z(e), []);
|
|
1284
|
+
}
|
|
1285
|
+
function jt(e) {
|
|
1286
|
+
J(() => gt(e), void 0);
|
|
1287
|
+
}
|
|
1288
|
+
function Mt(e, t) {
|
|
1289
|
+
J(() => _t(e, t), void 0);
|
|
1290
|
+
}
|
|
1291
|
+
function Nt(e, t) {
|
|
1292
|
+
J(() => xt(e, t), void 0);
|
|
1293
|
+
}
|
|
1294
|
+
function Pt(e) {
|
|
1295
|
+
return J(() => St(e), null);
|
|
1296
|
+
}
|
|
1297
|
+
function Ft(e) {
|
|
1298
|
+
return J(() => Ct(e), null);
|
|
1299
|
+
}
|
|
1300
|
+
function It(e, t, n) {
|
|
1301
|
+
J(() => wt(e, t, n), void 0);
|
|
1302
|
+
}
|
|
1303
|
+
function Lt(e, t, n) {
|
|
1304
|
+
J(() => Tt(e, t, n), void 0);
|
|
1305
|
+
}
|
|
1306
|
+
function Rt(e) {
|
|
1307
|
+
return J(() => bt(() => J(e, void 0)), () => {});
|
|
1308
|
+
}
|
|
1309
|
+
//#endregion
|
|
1105
1310
|
//#region src/utils/submit.ts
|
|
1106
|
-
function
|
|
1311
|
+
function zt(e, t = {}, n, r, i, a) {
|
|
1107
1312
|
try {
|
|
1108
|
-
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:
|
|
1109
|
-
if (!p) throw Error(
|
|
1313
|
+
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;
|
|
1314
|
+
if (!p) throw Error(se);
|
|
1110
1315
|
if (!l) throw Error("Could not resolve app config");
|
|
1111
|
-
let { fn_index:
|
|
1112
|
-
if (
|
|
1113
|
-
let
|
|
1114
|
-
|
|
1115
|
-
|
|
1316
|
+
let { fn_index: w, endpoint_info: T, dependency: E } = Vt(p, e, m, l), ae = ye(t, T), D = l.protocol ?? "ws";
|
|
1317
|
+
if (D === "ws") throw Error(ce);
|
|
1318
|
+
let oe = typeof E.api_name == "string" ? `/${E.api_name}` : e, le = typeof E.api_name == "string" ? `/${E.api_name}` : `Function ${w}`, O = (e) => {
|
|
1319
|
+
let t = l.components.find((t) => t.id === e);
|
|
1320
|
+
return t ? {
|
|
1321
|
+
type: t.type,
|
|
1322
|
+
component_class_id: t.component_class_id,
|
|
1323
|
+
props: t.props
|
|
1324
|
+
} : null;
|
|
1325
|
+
}, ue = E.api_visibility === "public", de = l.run_history !== !1 && this.options.record_history !== !1, k = {
|
|
1326
|
+
app_id: l.app_id,
|
|
1327
|
+
username: l.username
|
|
1328
|
+
}, fe = !de || !ue ? null : Ft({
|
|
1329
|
+
...k,
|
|
1330
|
+
endpoint: oe,
|
|
1331
|
+
api_name: le,
|
|
1332
|
+
fn_index: w,
|
|
1333
|
+
inputs: G(ae, E, l.components, "input", !0),
|
|
1334
|
+
input_components: E.inputs.map(O),
|
|
1335
|
+
output_components: E.outputs.map(O)
|
|
1336
|
+
}), 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), {}) || {};
|
|
1337
|
+
function R(e) {
|
|
1338
|
+
Lt(k, fe, e), (i || pe[e.type]) && U(e);
|
|
1116
1339
|
}
|
|
1117
|
-
async function
|
|
1340
|
+
async function me() {
|
|
1118
1341
|
let e = {}, t = {};
|
|
1119
|
-
e = { event_id:
|
|
1120
|
-
event_id:
|
|
1342
|
+
e = { event_id: P }, t = {
|
|
1343
|
+
event_id: P,
|
|
1121
1344
|
session_hash: f,
|
|
1122
|
-
fn_index:
|
|
1345
|
+
fn_index: w
|
|
1123
1346
|
};
|
|
1124
1347
|
try {
|
|
1125
1348
|
if (!l) throw Error("Could not resolve app config");
|
|
1126
|
-
"event_id" in t && await s(`${l.root}${
|
|
1349
|
+
"event_id" in t && await s(`${l.root}${x}/${re}`, {
|
|
1127
1350
|
headers: { "Content-Type": "application/json" },
|
|
1128
1351
|
method: "POST",
|
|
1129
1352
|
body: JSON.stringify(t)
|
|
1130
|
-
}), await s(`${l.root}${
|
|
1353
|
+
}), await s(`${l.root}${x}/${ne}`, {
|
|
1131
1354
|
headers: { "Content-Type": "application/json" },
|
|
1132
1355
|
method: "POST",
|
|
1133
1356
|
body: JSON.stringify(e)
|
|
@@ -1136,64 +1359,65 @@ function et(e, t = {}, n, r, i, a) {
|
|
|
1136
1359
|
console.warn("The `/reset` endpoint could not be called. Subsequent endpoint results may be unreliable.");
|
|
1137
1360
|
}
|
|
1138
1361
|
}
|
|
1139
|
-
let
|
|
1362
|
+
let he = async (e) => {
|
|
1140
1363
|
await this._resolve_heartbeat(e);
|
|
1141
1364
|
};
|
|
1142
|
-
async function
|
|
1365
|
+
async function ge(e) {
|
|
1143
1366
|
if (!l) return;
|
|
1144
1367
|
let t = e.render_id;
|
|
1145
1368
|
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];
|
|
1146
1369
|
let n = l.components.some((e) => e.type === "state"), r = l.dependencies.some((e) => e.targets.some((e) => e[1] === "unload"));
|
|
1147
|
-
l.connect_heartbeat = n || r, await
|
|
1370
|
+
l.connect_heartbeat = n || r, await he(l), R({
|
|
1148
1371
|
type: "render",
|
|
1149
1372
|
data: e,
|
|
1150
|
-
endpoint:
|
|
1151
|
-
fn_index:
|
|
1373
|
+
endpoint: M,
|
|
1374
|
+
fn_index: w
|
|
1152
1375
|
});
|
|
1153
1376
|
}
|
|
1154
|
-
let
|
|
1155
|
-
|
|
1156
|
-
|
|
1377
|
+
let _e = this.handle_blob(l.root, ae, T).then(async (e) => {
|
|
1378
|
+
let t = G(e, E, l.components, "input", !0);
|
|
1379
|
+
if (It(k, fe, t || []), N = {
|
|
1380
|
+
data: t || [],
|
|
1157
1381
|
event_data: n,
|
|
1158
|
-
fn_index:
|
|
1382
|
+
fn_index: w,
|
|
1159
1383
|
trigger_id: r,
|
|
1160
|
-
...
|
|
1161
|
-
},
|
|
1384
|
+
...b.oauth_token && T?.oauth_token ? { oauth_token: b.oauth_token } : {}
|
|
1385
|
+
}, Te(w, l)) R({
|
|
1162
1386
|
type: "status",
|
|
1163
|
-
endpoint:
|
|
1387
|
+
endpoint: M,
|
|
1164
1388
|
stage: "pending",
|
|
1165
1389
|
queue: !1,
|
|
1166
|
-
fn_index:
|
|
1390
|
+
fn_index: w,
|
|
1167
1391
|
time: /* @__PURE__ */ new Date()
|
|
1168
|
-
}),
|
|
1169
|
-
...
|
|
1392
|
+
}), v(`${l.root}${x}/run${M.startsWith("/") ? M : `/${M}`}${L ? "?" + L : ""}`, {
|
|
1393
|
+
...N,
|
|
1170
1394
|
session_hash: f
|
|
1171
|
-
},
|
|
1395
|
+
}, S).then(async ([e, t]) => {
|
|
1172
1396
|
let i = e.data;
|
|
1173
|
-
if (t == 200)
|
|
1397
|
+
if (t == 200) R({
|
|
1174
1398
|
type: "data",
|
|
1175
|
-
endpoint:
|
|
1176
|
-
fn_index:
|
|
1177
|
-
data:
|
|
1399
|
+
endpoint: M,
|
|
1400
|
+
fn_index: w,
|
|
1401
|
+
data: G(i, E, l.components, "output", b.with_null_state),
|
|
1178
1402
|
time: /* @__PURE__ */ new Date(),
|
|
1179
1403
|
event_data: n,
|
|
1180
1404
|
trigger_id: r
|
|
1181
|
-
}), e.render_config && await
|
|
1405
|
+
}), e.render_config && await ge(e.render_config), R({
|
|
1182
1406
|
type: "status",
|
|
1183
|
-
endpoint:
|
|
1184
|
-
fn_index:
|
|
1407
|
+
endpoint: M,
|
|
1408
|
+
fn_index: w,
|
|
1185
1409
|
stage: "complete",
|
|
1186
1410
|
eta: e.average_duration,
|
|
1187
1411
|
queue: !1,
|
|
1188
1412
|
time: /* @__PURE__ */ new Date()
|
|
1189
1413
|
});
|
|
1190
1414
|
else {
|
|
1191
|
-
let t = e?.error ===
|
|
1192
|
-
|
|
1415
|
+
let t = e?.error === y;
|
|
1416
|
+
R({
|
|
1193
1417
|
type: "status",
|
|
1194
1418
|
stage: "error",
|
|
1195
|
-
endpoint:
|
|
1196
|
-
fn_index:
|
|
1419
|
+
endpoint: M,
|
|
1420
|
+
fn_index: w,
|
|
1197
1421
|
message: e.error,
|
|
1198
1422
|
broken: t,
|
|
1199
1423
|
queue: !1,
|
|
@@ -1201,303 +1425,303 @@ function et(e, t = {}, n, r, i, a) {
|
|
|
1201
1425
|
});
|
|
1202
1426
|
}
|
|
1203
1427
|
}).catch((e) => {
|
|
1204
|
-
|
|
1428
|
+
R({
|
|
1205
1429
|
type: "status",
|
|
1206
1430
|
stage: "error",
|
|
1207
1431
|
message: e.message,
|
|
1208
|
-
endpoint:
|
|
1209
|
-
fn_index:
|
|
1432
|
+
endpoint: M,
|
|
1433
|
+
fn_index: w,
|
|
1210
1434
|
queue: !1,
|
|
1211
1435
|
time: /* @__PURE__ */ new Date()
|
|
1212
1436
|
});
|
|
1213
1437
|
});
|
|
1214
|
-
else if (
|
|
1215
|
-
|
|
1438
|
+
else if (D == "sse") {
|
|
1439
|
+
R({
|
|
1216
1440
|
type: "status",
|
|
1217
1441
|
stage: "pending",
|
|
1218
1442
|
queue: !0,
|
|
1219
|
-
endpoint:
|
|
1220
|
-
fn_index:
|
|
1443
|
+
endpoint: M,
|
|
1444
|
+
fn_index: w,
|
|
1221
1445
|
time: /* @__PURE__ */ new Date()
|
|
1222
1446
|
});
|
|
1223
|
-
var
|
|
1224
|
-
fn_index:
|
|
1447
|
+
var i = new URLSearchParams({
|
|
1448
|
+
fn_index: w.toString(),
|
|
1225
1449
|
session_hash: f
|
|
1226
1450
|
}).toString();
|
|
1227
|
-
let e = new URL(`${l.root}${
|
|
1228
|
-
if (this.jwt && e.searchParams.set("__sign", this.jwt),
|
|
1229
|
-
|
|
1230
|
-
let { type: t, status: i, data: a } =
|
|
1231
|
-
if (t === "update" && i && !
|
|
1451
|
+
let e = new URL(`${l.root}${x}/${u}?${L ? L + "&" : ""}${i}`);
|
|
1452
|
+
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()));
|
|
1453
|
+
A.onmessage = async function(e) {
|
|
1454
|
+
let { type: t, status: i, data: a } = ve(JSON.parse(e.data), I[w]);
|
|
1455
|
+
if (t === "update" && i && !F) R({
|
|
1232
1456
|
type: "status",
|
|
1233
|
-
endpoint:
|
|
1234
|
-
fn_index:
|
|
1457
|
+
endpoint: M,
|
|
1458
|
+
fn_index: w,
|
|
1235
1459
|
time: /* @__PURE__ */ new Date(),
|
|
1236
1460
|
...i
|
|
1237
|
-
}), i.stage === "error" && (
|
|
1461
|
+
}), i.stage === "error" && (A?.close(), V());
|
|
1238
1462
|
else if (t === "data") {
|
|
1239
|
-
let [e, t] = await
|
|
1240
|
-
...
|
|
1463
|
+
let [e, t] = await v(`${l.root}${x}/queue/data`, {
|
|
1464
|
+
...N,
|
|
1241
1465
|
session_hash: f,
|
|
1242
|
-
event_id:
|
|
1466
|
+
event_id: P
|
|
1243
1467
|
});
|
|
1244
|
-
t !== 200 && (
|
|
1468
|
+
t !== 200 && (R({
|
|
1245
1469
|
type: "status",
|
|
1246
1470
|
stage: "error",
|
|
1247
|
-
message:
|
|
1471
|
+
message: y,
|
|
1248
1472
|
queue: !0,
|
|
1249
|
-
endpoint:
|
|
1250
|
-
fn_index:
|
|
1473
|
+
endpoint: M,
|
|
1474
|
+
fn_index: w,
|
|
1251
1475
|
time: /* @__PURE__ */ new Date()
|
|
1252
|
-
}),
|
|
1253
|
-
} else t === "complete" ?
|
|
1476
|
+
}), A?.close(), V());
|
|
1477
|
+
} else t === "complete" ? F = i : t === "log" ? R({
|
|
1254
1478
|
type: "log",
|
|
1255
1479
|
title: a.title,
|
|
1256
1480
|
log: a.log,
|
|
1257
1481
|
level: a.level,
|
|
1258
|
-
endpoint:
|
|
1482
|
+
endpoint: M,
|
|
1259
1483
|
duration: a.duration,
|
|
1260
1484
|
visible: a.visible,
|
|
1261
|
-
fn_index:
|
|
1262
|
-
}) : (t === "generating" || t === "streaming") &&
|
|
1485
|
+
fn_index: w
|
|
1486
|
+
}) : (t === "generating" || t === "streaming") && R({
|
|
1263
1487
|
type: "status",
|
|
1264
1488
|
time: /* @__PURE__ */ new Date(),
|
|
1265
1489
|
...i,
|
|
1266
1490
|
stage: i?.stage,
|
|
1267
1491
|
queue: !0,
|
|
1268
|
-
endpoint:
|
|
1269
|
-
fn_index:
|
|
1492
|
+
endpoint: M,
|
|
1493
|
+
fn_index: w
|
|
1270
1494
|
});
|
|
1271
|
-
a && (
|
|
1495
|
+
a && (R({
|
|
1272
1496
|
type: "data",
|
|
1273
1497
|
time: /* @__PURE__ */ new Date(),
|
|
1274
|
-
data:
|
|
1275
|
-
endpoint:
|
|
1276
|
-
fn_index:
|
|
1498
|
+
data: G(a.data, E, l.components, "output", b.with_null_state),
|
|
1499
|
+
endpoint: M,
|
|
1500
|
+
fn_index: w,
|
|
1277
1501
|
event_data: n,
|
|
1278
1502
|
trigger_id: r
|
|
1279
|
-
}),
|
|
1503
|
+
}), F && (R({
|
|
1280
1504
|
type: "status",
|
|
1281
1505
|
time: /* @__PURE__ */ new Date(),
|
|
1282
|
-
...
|
|
1506
|
+
...F,
|
|
1283
1507
|
stage: i?.stage,
|
|
1284
1508
|
queue: !0,
|
|
1285
|
-
endpoint:
|
|
1286
|
-
fn_index:
|
|
1287
|
-
}),
|
|
1509
|
+
endpoint: M,
|
|
1510
|
+
fn_index: w
|
|
1511
|
+
}), A?.close(), V()));
|
|
1288
1512
|
};
|
|
1289
|
-
} else if (
|
|
1290
|
-
|
|
1513
|
+
} else if (D == "sse_v1" || D == "sse_v2" || D == "sse_v2.1" || D == "sse_v3") {
|
|
1514
|
+
R({
|
|
1291
1515
|
type: "status",
|
|
1292
1516
|
stage: "pending",
|
|
1293
1517
|
queue: !0,
|
|
1294
|
-
endpoint:
|
|
1295
|
-
fn_index:
|
|
1518
|
+
endpoint: M,
|
|
1519
|
+
fn_index: w,
|
|
1296
1520
|
time: /* @__PURE__ */ new Date()
|
|
1297
1521
|
});
|
|
1298
1522
|
let e = "";
|
|
1299
1523
|
typeof window < "u" && typeof document < "u" && (e = window?.location?.hostname);
|
|
1300
|
-
let t =
|
|
1301
|
-
return (typeof window < "u" && typeof document < "u" && window.parent != window && t && window.supports_zerogpu_headers ?
|
|
1524
|
+
let t = Ke(e);
|
|
1525
|
+
return (typeof window < "u" && typeof document < "u" && window.parent != window && t && window.supports_zerogpu_headers ? Ee("zerogpu-headers", t) : Promise.resolve(null)).then((e) => {
|
|
1302
1526
|
let t = {
|
|
1303
|
-
...
|
|
1527
|
+
...S,
|
|
1304
1528
|
...e || {}
|
|
1305
1529
|
};
|
|
1306
|
-
return
|
|
1307
|
-
...
|
|
1530
|
+
return v(`${l.root}${x}/${d}?${L}`, {
|
|
1531
|
+
...N,
|
|
1308
1532
|
session_hash: f
|
|
1309
1533
|
}, t);
|
|
1310
1534
|
}).then(async ([e, t]) => {
|
|
1311
|
-
if (e.event_id && (
|
|
1535
|
+
if (e.event_id && (j = e.event_id), t === 503) R({
|
|
1312
1536
|
type: "status",
|
|
1313
1537
|
stage: "error",
|
|
1314
|
-
message:
|
|
1538
|
+
message: ie,
|
|
1315
1539
|
queue: !0,
|
|
1316
|
-
endpoint:
|
|
1317
|
-
fn_index:
|
|
1540
|
+
endpoint: M,
|
|
1541
|
+
fn_index: w,
|
|
1318
1542
|
time: /* @__PURE__ */ new Date(),
|
|
1319
1543
|
visible: !0
|
|
1320
|
-
}),
|
|
1321
|
-
else if (t === 422)
|
|
1544
|
+
}), V();
|
|
1545
|
+
else if (t === 422) R({
|
|
1322
1546
|
type: "status",
|
|
1323
1547
|
stage: "error",
|
|
1324
1548
|
message: e.detail,
|
|
1325
1549
|
queue: !0,
|
|
1326
|
-
endpoint:
|
|
1327
|
-
fn_index:
|
|
1550
|
+
endpoint: M,
|
|
1551
|
+
fn_index: w,
|
|
1328
1552
|
code: "validation_error",
|
|
1329
1553
|
time: /* @__PURE__ */ new Date(),
|
|
1330
1554
|
visible: !0
|
|
1331
|
-
}),
|
|
1555
|
+
}), V();
|
|
1332
1556
|
else if (t !== 200) {
|
|
1333
|
-
let t = e?.error ===
|
|
1334
|
-
|
|
1557
|
+
let t = e?.error === y;
|
|
1558
|
+
R({
|
|
1335
1559
|
type: "status",
|
|
1336
1560
|
stage: "error",
|
|
1337
1561
|
broken: t,
|
|
1338
|
-
message: t ?
|
|
1562
|
+
message: t ? y : e.detail || e.error,
|
|
1339
1563
|
queue: !0,
|
|
1340
|
-
endpoint:
|
|
1341
|
-
fn_index:
|
|
1564
|
+
endpoint: M,
|
|
1565
|
+
fn_index: w,
|
|
1342
1566
|
time: /* @__PURE__ */ new Date(),
|
|
1343
1567
|
visible: !0
|
|
1344
|
-
}),
|
|
1568
|
+
}), V();
|
|
1345
1569
|
} else {
|
|
1346
|
-
|
|
1570
|
+
P = e.event_id, j = P;
|
|
1347
1571
|
let t = async function(e) {
|
|
1348
1572
|
try {
|
|
1349
|
-
let { type: t, status: n, data: r, original_msg: i } =
|
|
1573
|
+
let { type: t, status: n, data: r, original_msg: i } = ve(e, I[w]);
|
|
1350
1574
|
if (t == "heartbeat") return;
|
|
1351
|
-
if (t === "update" && n && !
|
|
1575
|
+
if (t === "update" && n && !F) R({
|
|
1352
1576
|
type: "status",
|
|
1353
|
-
endpoint:
|
|
1354
|
-
fn_index:
|
|
1577
|
+
endpoint: M,
|
|
1578
|
+
fn_index: w,
|
|
1355
1579
|
time: /* @__PURE__ */ new Date(),
|
|
1356
1580
|
original_msg: i,
|
|
1357
1581
|
...n
|
|
1358
1582
|
});
|
|
1359
|
-
else if (t === "complete")
|
|
1583
|
+
else if (t === "complete") F = n;
|
|
1360
1584
|
else if (t == "unexpected_error" || t == "broken_connection") {
|
|
1361
1585
|
console.error("Unexpected error", n?.message);
|
|
1362
1586
|
let e = t === "broken_connection";
|
|
1363
|
-
|
|
1587
|
+
R({
|
|
1364
1588
|
type: "status",
|
|
1365
1589
|
stage: "error",
|
|
1366
1590
|
message: n?.message || "An Unexpected Error Occurred!",
|
|
1367
1591
|
queue: !0,
|
|
1368
|
-
endpoint:
|
|
1592
|
+
endpoint: M,
|
|
1369
1593
|
broken: e,
|
|
1370
1594
|
session_not_found: n?.session_not_found,
|
|
1371
|
-
fn_index:
|
|
1595
|
+
fn_index: w,
|
|
1372
1596
|
time: /* @__PURE__ */ new Date()
|
|
1373
1597
|
});
|
|
1374
1598
|
} else if (t === "log") {
|
|
1375
|
-
|
|
1599
|
+
R({
|
|
1376
1600
|
type: "log",
|
|
1377
1601
|
title: r.title,
|
|
1378
1602
|
log: r.log,
|
|
1379
1603
|
level: r.level,
|
|
1380
|
-
endpoint:
|
|
1604
|
+
endpoint: M,
|
|
1381
1605
|
duration: r.duration,
|
|
1382
1606
|
visible: r.visible,
|
|
1383
|
-
fn_index:
|
|
1607
|
+
fn_index: w
|
|
1384
1608
|
});
|
|
1385
1609
|
return;
|
|
1386
|
-
} else (t === "generating" || t === "streaming") && (
|
|
1610
|
+
} else (t === "generating" || t === "streaming") && (R({
|
|
1387
1611
|
type: "status",
|
|
1388
1612
|
time: /* @__PURE__ */ new Date(),
|
|
1389
1613
|
...n,
|
|
1390
1614
|
stage: n?.stage,
|
|
1391
1615
|
queue: !0,
|
|
1392
|
-
endpoint:
|
|
1393
|
-
fn_index:
|
|
1394
|
-
}), r &&
|
|
1616
|
+
endpoint: M,
|
|
1617
|
+
fn_index: w
|
|
1618
|
+
}), r && E.connection !== "stream" && [
|
|
1395
1619
|
"sse_v2",
|
|
1396
1620
|
"sse_v2.1",
|
|
1397
1621
|
"sse_v3"
|
|
1398
|
-
].includes(
|
|
1399
|
-
r && (
|
|
1622
|
+
].includes(D) && nt(ee, P, r));
|
|
1623
|
+
r && (R({
|
|
1400
1624
|
type: "data",
|
|
1401
1625
|
time: /* @__PURE__ */ new Date(),
|
|
1402
|
-
data:
|
|
1403
|
-
endpoint:
|
|
1404
|
-
fn_index:
|
|
1405
|
-
}), r.render_config && await
|
|
1626
|
+
data: G(r.data, E, l.components, "output", b.with_null_state),
|
|
1627
|
+
endpoint: M,
|
|
1628
|
+
fn_index: w
|
|
1629
|
+
}), r.render_config && await ge(r.render_config), F && (R({
|
|
1406
1630
|
type: "status",
|
|
1407
1631
|
time: /* @__PURE__ */ new Date(),
|
|
1408
|
-
...
|
|
1632
|
+
...F,
|
|
1409
1633
|
stage: n?.stage,
|
|
1410
1634
|
queue: !0,
|
|
1411
|
-
endpoint:
|
|
1412
|
-
fn_index:
|
|
1413
|
-
}),
|
|
1635
|
+
endpoint: M,
|
|
1636
|
+
fn_index: w
|
|
1637
|
+
}), V())), (n?.stage === "complete" || n?.stage === "error") && (_[P] && delete _[P], P in ee && delete ee[P], V());
|
|
1414
1638
|
} catch (e) {
|
|
1415
|
-
console.error("Unexpected client exception", e),
|
|
1639
|
+
console.error("Unexpected client exception", e), R({
|
|
1416
1640
|
type: "status",
|
|
1417
1641
|
stage: "error",
|
|
1418
1642
|
message: "An Unexpected Error Occurred!",
|
|
1419
1643
|
queue: !0,
|
|
1420
|
-
endpoint:
|
|
1421
|
-
fn_index:
|
|
1644
|
+
endpoint: M,
|
|
1645
|
+
fn_index: w,
|
|
1422
1646
|
time: /* @__PURE__ */ new Date()
|
|
1423
1647
|
}), [
|
|
1424
1648
|
"sse_v2",
|
|
1425
1649
|
"sse_v2.1",
|
|
1426
1650
|
"sse_v3"
|
|
1427
|
-
].includes(
|
|
1651
|
+
].includes(D) && (tt(h, C.abort_controller), h.open = !1, V());
|
|
1428
1652
|
}
|
|
1429
1653
|
};
|
|
1430
|
-
|
|
1654
|
+
P in g && (g[P].forEach((e) => t(e)), delete g[P]), _[P] = t, te.add(P), h.open || await this.open_stream();
|
|
1431
1655
|
}
|
|
1432
1656
|
});
|
|
1433
1657
|
}
|
|
1434
1658
|
});
|
|
1435
|
-
|
|
1436
|
-
|
|
1659
|
+
_e.catch((e) => {
|
|
1660
|
+
R({
|
|
1437
1661
|
type: "status",
|
|
1438
1662
|
stage: "error",
|
|
1439
1663
|
message: e instanceof Error ? e.message : String(e),
|
|
1440
|
-
queue: !
|
|
1441
|
-
endpoint:
|
|
1442
|
-
fn_index:
|
|
1664
|
+
queue: !Te(w, l),
|
|
1665
|
+
endpoint: M,
|
|
1666
|
+
fn_index: w,
|
|
1443
1667
|
time: /* @__PURE__ */ new Date()
|
|
1444
|
-
}),
|
|
1668
|
+
}), V();
|
|
1445
1669
|
});
|
|
1446
|
-
let
|
|
1447
|
-
function
|
|
1448
|
-
for (
|
|
1670
|
+
let be = !1, z = [], B = [];
|
|
1671
|
+
function V() {
|
|
1672
|
+
for (be = !0; B.length > 0;) B.shift()({
|
|
1449
1673
|
value: void 0,
|
|
1450
1674
|
done: !0
|
|
1451
1675
|
});
|
|
1452
1676
|
}
|
|
1453
|
-
function
|
|
1454
|
-
|
|
1677
|
+
function H(e) {
|
|
1678
|
+
B.length > 0 ? B.shift()(e) : z.push(e);
|
|
1455
1679
|
}
|
|
1456
|
-
function
|
|
1457
|
-
|
|
1680
|
+
function xe(e) {
|
|
1681
|
+
H(Bt(e)), V();
|
|
1458
1682
|
}
|
|
1459
|
-
function
|
|
1460
|
-
|
|
1683
|
+
function U(e) {
|
|
1684
|
+
H({
|
|
1461
1685
|
value: e,
|
|
1462
1686
|
done: !1
|
|
1463
1687
|
});
|
|
1464
1688
|
}
|
|
1465
|
-
function
|
|
1466
|
-
return
|
|
1689
|
+
function W() {
|
|
1690
|
+
return z.length > 0 ? Promise.resolve(z.shift()) : be ? Promise.resolve({
|
|
1467
1691
|
value: void 0,
|
|
1468
1692
|
done: !0
|
|
1469
|
-
}) : new Promise((e) =>
|
|
1693
|
+
}) : new Promise((e) => B.push(e));
|
|
1470
1694
|
}
|
|
1471
|
-
let
|
|
1472
|
-
[Symbol.asyncIterator]: () =>
|
|
1473
|
-
next:
|
|
1474
|
-
throw: async (e) => (
|
|
1475
|
-
return: async () => (
|
|
1695
|
+
let Se = {
|
|
1696
|
+
[Symbol.asyncIterator]: () => Se,
|
|
1697
|
+
next: W,
|
|
1698
|
+
throw: async (e) => (xe(e), W()),
|
|
1699
|
+
return: async () => (V(), {
|
|
1476
1700
|
value: void 0,
|
|
1477
1701
|
done: !0
|
|
1478
1702
|
}),
|
|
1479
|
-
cancel:
|
|
1703
|
+
cancel: me,
|
|
1480
1704
|
send_chunk: (e) => {
|
|
1481
|
-
this.post_data(`${l.root}${
|
|
1705
|
+
this.post_data(`${l.root}${x}/stream/${j}`, {
|
|
1482
1706
|
...e,
|
|
1483
1707
|
session_hash: this.session_hash
|
|
1484
1708
|
});
|
|
1485
1709
|
},
|
|
1486
1710
|
close_stream: () => {
|
|
1487
|
-
this.post_data(`${l.root}${
|
|
1711
|
+
this.post_data(`${l.root}${x}/stream/${j}/close`, {}), V();
|
|
1488
1712
|
},
|
|
1489
|
-
event_id: () =>
|
|
1490
|
-
wait_for_id: async () => (await
|
|
1713
|
+
event_id: () => j,
|
|
1714
|
+
wait_for_id: async () => (await _e, P)
|
|
1491
1715
|
};
|
|
1492
|
-
return
|
|
1716
|
+
return Se;
|
|
1493
1717
|
} catch (e) {
|
|
1494
1718
|
throw console.error("Submit function encountered an error:", e), e;
|
|
1495
1719
|
}
|
|
1496
1720
|
}
|
|
1497
|
-
function
|
|
1721
|
+
function Bt(e) {
|
|
1498
1722
|
return { then: (t, n) => n(e) };
|
|
1499
1723
|
}
|
|
1500
|
-
function
|
|
1724
|
+
function Vt(e, t, n, r) {
|
|
1501
1725
|
let i, a, o;
|
|
1502
1726
|
if (typeof t == "number") i = t, a = e.unnamed_endpoints[i], o = r.dependencies.find((e) => e.id == t);
|
|
1503
1727
|
else {
|
|
@@ -1539,13 +1763,13 @@ var $ = class {
|
|
|
1539
1763
|
stream_instance = null;
|
|
1540
1764
|
current_payload;
|
|
1541
1765
|
get_url_config(e = null) {
|
|
1542
|
-
if (!this.config) throw Error(
|
|
1766
|
+
if (!this.config) throw Error(b);
|
|
1543
1767
|
e === null && (e = window.location.href);
|
|
1544
1768
|
let t = (e) => e.replace(/^\/+|\/+$/g, ""), n = t(new URL(this.config.root).pathname), r = t(new URL(e).pathname), i;
|
|
1545
1769
|
return i = r.startsWith(n) ? t(r.substring(n.length)) : "", this.get_page_config(i);
|
|
1546
1770
|
}
|
|
1547
1771
|
get_page_config(e) {
|
|
1548
|
-
if (!this.config) throw Error(
|
|
1772
|
+
if (!this.config) throw Error(b);
|
|
1549
1773
|
let t = this.config;
|
|
1550
1774
|
return e in t.page || (e = ""), {
|
|
1551
1775
|
...t,
|
|
@@ -1568,7 +1792,7 @@ var $ = class {
|
|
|
1568
1792
|
let t = new Headers();
|
|
1569
1793
|
return this && this.cookies && t.append("Cookie", this.cookies), this && this.options.headers && new Headers(this.options.headers).forEach((e, n) => {
|
|
1570
1794
|
t.append(n, e);
|
|
1571
|
-
}), this && this.options.token && t.append("Authorization", `Bearer ${this.options.token}`), this.abort_controller = new AbortController(), this.stream_instance =
|
|
1795
|
+
}), this && this.options.token && t.append("Authorization", `Bearer ${this.options.token}`), this.abort_controller = new AbortController(), this.stream_instance = at(e.toString(), {
|
|
1572
1796
|
credentials: this.options.credentials ?? "same-origin",
|
|
1573
1797
|
headers: t,
|
|
1574
1798
|
signal: this.abort_controller.signal
|
|
@@ -1585,20 +1809,20 @@ var $ = class {
|
|
|
1585
1809
|
resolve_config;
|
|
1586
1810
|
resolve_cookies;
|
|
1587
1811
|
constructor(e, t = { events: ["data"] }) {
|
|
1588
|
-
this.app_reference = e, this.deep_link = t.query_params?.deep_link || null, t.events ||= ["data"],
|
|
1812
|
+
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 = ke.bind(this), this.post_data = Ne.bind(this), this.submit = zt.bind(this), this.predict = Pe.bind(this), this.open_stream = et.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);
|
|
1589
1813
|
}
|
|
1590
1814
|
async init() {
|
|
1591
|
-
|
|
1815
|
+
qe(), this.options.auth && await this.resolve_cookies(), await this._resolve_config().then((e) => e?.config && this._resolve_heartbeat(e.config));
|
|
1592
1816
|
try {
|
|
1593
1817
|
this.api_info = await this.view_api();
|
|
1594
1818
|
} catch (e) {
|
|
1595
1819
|
console.error(e.message);
|
|
1596
1820
|
}
|
|
1597
|
-
this.api_map =
|
|
1821
|
+
this.api_map = fe(this.config?.dependencies || []);
|
|
1598
1822
|
}
|
|
1599
1823
|
async _resolve_heartbeat(e) {
|
|
1600
|
-
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
|
|
1601
|
-
let e = new URL(`${this.config.root}${this.api_prefix}/${
|
|
1824
|
+
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) {
|
|
1825
|
+
let e = new URL(`${this.config.root}${this.api_prefix}/${_}/${this.session_hash}`);
|
|
1602
1826
|
this.jwt && e.searchParams.set("__sign", this.jwt), this.heartbeat_event ||= this.stream(e);
|
|
1603
1827
|
}
|
|
1604
1828
|
}
|
|
@@ -1607,7 +1831,7 @@ var $ = class {
|
|
|
1607
1831
|
return t.session_hash && (n.session_hash = t.session_hash), await n.init(), n;
|
|
1608
1832
|
}
|
|
1609
1833
|
async reconnect() {
|
|
1610
|
-
let e = new URL(`${this.config.root}${this.api_prefix}/${
|
|
1834
|
+
let e = new URL(`${this.config.root}${this.api_prefix}/${v}`), t;
|
|
1611
1835
|
try {
|
|
1612
1836
|
let n = await this.fetch(e);
|
|
1613
1837
|
if (!n.ok) throw Error();
|
|
@@ -1618,17 +1842,17 @@ var $ = class {
|
|
|
1618
1842
|
return t === this.config.app_id ? "connected" : "changed";
|
|
1619
1843
|
}
|
|
1620
1844
|
close() {
|
|
1621
|
-
this.closed = !0,
|
|
1845
|
+
this.closed = !0, tt(this.stream_status, this.abort_controller);
|
|
1622
1846
|
}
|
|
1623
1847
|
async refresh() {
|
|
1624
|
-
if (!this.config) throw Error(
|
|
1848
|
+
if (!this.config) throw Error(b);
|
|
1625
1849
|
let e = await this.resolve_config(this.config.root, !1);
|
|
1626
|
-
if (!e) throw Error(
|
|
1627
|
-
this.config = e, this.api_prefix = e.api_prefix || "", this.api_map =
|
|
1850
|
+
if (!e) throw Error(b);
|
|
1851
|
+
this.config = e, this.api_prefix = e.api_prefix || "", this.api_map = fe(e.dependencies || []);
|
|
1628
1852
|
try {
|
|
1629
1853
|
this.api_info = await this.view_api();
|
|
1630
1854
|
} catch (e) {
|
|
1631
|
-
console.error(
|
|
1855
|
+
console.error(S + e.message);
|
|
1632
1856
|
}
|
|
1633
1857
|
return this.get_url_config();
|
|
1634
1858
|
}
|
|
@@ -1636,18 +1860,18 @@ var $ = class {
|
|
|
1636
1860
|
this.current_payload = e;
|
|
1637
1861
|
}
|
|
1638
1862
|
static async duplicate(e, t = { events: ["data"] }) {
|
|
1639
|
-
return
|
|
1863
|
+
return Ve(e, t);
|
|
1640
1864
|
}
|
|
1641
1865
|
async _resolve_config() {
|
|
1642
|
-
let { http_protocol: e, host: t, space_id: n } = await
|
|
1643
|
-
n && r && await
|
|
1866
|
+
let { http_protocol: e, host: t, space_id: n } = await R(this.app_reference, this.options.token), { status_callback: r } = this.options;
|
|
1867
|
+
n && r && await Fe(n, r);
|
|
1644
1868
|
let i;
|
|
1645
1869
|
try {
|
|
1646
1870
|
let n = `${e}//${t}`;
|
|
1647
|
-
if (i = await this.resolve_config(n), !i) throw Error(
|
|
1871
|
+
if (i = await this.resolve_config(n), !i) throw Error(b);
|
|
1648
1872
|
return this.config_success(i);
|
|
1649
1873
|
} catch (e) {
|
|
1650
|
-
if (n && r)
|
|
1874
|
+
if (n && r) K(n, L.test(n) ? "space_name" : "subdomain", this.handle_space_success);
|
|
1651
1875
|
else throw r && r({
|
|
1652
1876
|
status: "error",
|
|
1653
1877
|
message: "Could not load this space.",
|
|
@@ -1657,19 +1881,22 @@ var $ = class {
|
|
|
1657
1881
|
}
|
|
1658
1882
|
}
|
|
1659
1883
|
async config_success(e) {
|
|
1660
|
-
if (this.config = e, this.api_prefix = e.api_prefix || "",
|
|
1884
|
+
if (this.config = e, this.api_prefix = e.api_prefix || "", e.run_history === !1 && jt({
|
|
1885
|
+
app_id: e.app_id,
|
|
1886
|
+
username: e.username
|
|
1887
|
+
}), this.config.auth_required) return this.prepare_return_obj();
|
|
1661
1888
|
try {
|
|
1662
1889
|
this.api_info = await this.view_api();
|
|
1663
1890
|
} catch (e) {
|
|
1664
|
-
console.error(
|
|
1891
|
+
console.error(S + e.message);
|
|
1665
1892
|
}
|
|
1666
1893
|
return this.prepare_return_obj();
|
|
1667
1894
|
}
|
|
1668
1895
|
async handle_space_success(e) {
|
|
1669
|
-
if (!this) throw Error(
|
|
1896
|
+
if (!this) throw Error(b);
|
|
1670
1897
|
let { status_callback: t } = this.options;
|
|
1671
1898
|
if (t && t(e), e.status === "running") try {
|
|
1672
|
-
if (this.config = await this._resolve_config(), this.api_prefix = this?.config?.api_prefix || "", !this.config) throw Error(
|
|
1899
|
+
if (this.config = await this._resolve_config(), this.api_prefix = this?.config?.api_prefix || "", !this.config) throw Error(b);
|
|
1673
1900
|
return await this.config_success(this.config);
|
|
1674
1901
|
} catch (e) {
|
|
1675
1902
|
throw t && t({
|
|
@@ -1681,7 +1908,7 @@ var $ = class {
|
|
|
1681
1908
|
}
|
|
1682
1909
|
}
|
|
1683
1910
|
async component_server(e, t, n) {
|
|
1684
|
-
if (!this.config) throw Error(
|
|
1911
|
+
if (!this.config) throw Error(b);
|
|
1685
1912
|
let r = {}, { token: i } = this.options, { session_hash: a } = this;
|
|
1686
1913
|
i && (r.Authorization = `Bearer ${this.options.token}`);
|
|
1687
1914
|
let o, s = this.config.components.find((t) => t.id === e);
|
|
@@ -1700,7 +1927,7 @@ var $ = class {
|
|
|
1700
1927
|
}), r["Content-Type"] = "application/json";
|
|
1701
1928
|
i && (r.Authorization = `Bearer ${i}`);
|
|
1702
1929
|
try {
|
|
1703
|
-
let e = await this.fetch(`${o}${this.api_prefix}/${
|
|
1930
|
+
let e = await this.fetch(`${o}${this.api_prefix}/${te}/`, {
|
|
1704
1931
|
method: "POST",
|
|
1705
1932
|
body: c,
|
|
1706
1933
|
headers: r,
|
|
@@ -1713,7 +1940,7 @@ var $ = class {
|
|
|
1713
1940
|
}
|
|
1714
1941
|
}
|
|
1715
1942
|
set_cookies(e) {
|
|
1716
|
-
this.cookies =
|
|
1943
|
+
this.cookies = I(e).join("; ");
|
|
1717
1944
|
}
|
|
1718
1945
|
prepare_return_obj() {
|
|
1719
1946
|
return {
|
|
@@ -1725,11 +1952,11 @@ var $ = class {
|
|
|
1725
1952
|
};
|
|
1726
1953
|
}
|
|
1727
1954
|
};
|
|
1728
|
-
async function
|
|
1955
|
+
async function Ht(e, t = { events: ["data"] }) {
|
|
1729
1956
|
return await $.connect(e, t);
|
|
1730
1957
|
}
|
|
1731
|
-
async function
|
|
1958
|
+
async function Ut(e, t) {
|
|
1732
1959
|
return await $.duplicate(e, t);
|
|
1733
1960
|
}
|
|
1734
1961
|
//#endregion
|
|
1735
|
-
export { $ as Client,
|
|
1962
|
+
export { $ as Client, U as FileData, ae as MISSING_CREDENTIALS_MSG, jt as clear_run_history, Ht as client, Pt as consume_run_history_replay, Mt as delete_run_history, Ut as duplicate, De as handle_file, Rt as on_run_history_change, Pe as predict, xe as prepare_files, At as read_run_history, ut as run_history_url, Nt as stage_run_history_replay, zt as submit, H as upload, z as upload_files };
|