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