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