@gradio/client 2.7.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 +6 -0
- package/dist/browser.js +360 -356
- package/dist/index.cjs +8 -2
- package/dist/index.js +8 -2
- package/dist/index.min.js +161 -157
- package/dist/utils/submit.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/test/submit.test.ts +40 -1
- package/src/utils/submit.ts +16 -9
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", ee = "info",
|
|
11
|
+
}) : a, n)), l = "host", u = "queue/data", d = "queue/join", f = "upload", p = "login", m = "config", ee = "info", te = "runtime", ne = "sleeptime", h = "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. ", ce = "Invalid URL. A full URL path is required.", x = "Not authorized to access this space. ", S = "Invalid credentials. Could not login. ", C = "Login credentials are required to access this space.", le = "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.", w = (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.`, ue = "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. ", de = "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.", fe = "File system access is only available in Node.js environments", pe = "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 he(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,26 +21,26 @@ async function me(e, t, n) {
|
|
|
21
21
|
return !1;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
function
|
|
24
|
+
function T(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 = new URL(
|
|
41
|
+
let t = new URL(F(e, m));
|
|
42
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
|
|
43
|
+
let r = await _e(await this.fetch(t, {
|
|
44
44
|
headers: n,
|
|
45
45
|
credentials: this.options.credentials ?? "same-origin"
|
|
46
46
|
}), !!this.options.auth);
|
|
@@ -50,49 +50,49 @@ async function O(e, t = !0) {
|
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
52
|
let r = { ...window.gradio_config };
|
|
53
|
-
return r.root =
|
|
53
|
+
return r.root = ge(r.root, location.href, r.is_colab), r;
|
|
54
54
|
} else if (e) {
|
|
55
|
-
let t = new URL(
|
|
55
|
+
let t = new URL(F(e, m));
|
|
56
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
|
|
57
|
+
let r = await _e(await this.fetch(t, {
|
|
58
58
|
headers: n,
|
|
59
59
|
credentials: this.options.credentials ?? "same-origin"
|
|
60
60
|
}), !!this.options.auth);
|
|
61
61
|
return r.root ||= e, r;
|
|
62
62
|
}
|
|
63
|
-
throw Error(
|
|
63
|
+
throw Error(v);
|
|
64
64
|
}
|
|
65
|
-
async function
|
|
65
|
+
async function _e(e, t) {
|
|
66
66
|
if (e?.status === 401 && !t) {
|
|
67
67
|
let t = null;
|
|
68
68
|
try {
|
|
69
69
|
t = await e.json();
|
|
70
70
|
} catch {
|
|
71
|
-
throw Error(
|
|
71
|
+
throw Error(le);
|
|
72
72
|
}
|
|
73
73
|
let n = t?.detail?.auth_message;
|
|
74
74
|
throw Error(n || "Login credentials are required to access this space.");
|
|
75
|
-
} else if (e?.status === 401 && t) throw Error(
|
|
75
|
+
} else if (e?.status === 401 && t) throw Error(S);
|
|
76
76
|
if (e?.status === 200) {
|
|
77
77
|
let t = await e.json();
|
|
78
78
|
return t.dependencies?.forEach((e, t) => {
|
|
79
79
|
e.id === void 0 && (e.id = t);
|
|
80
80
|
}), t;
|
|
81
|
-
} else if (e?.status === 401) throw Error(
|
|
82
|
-
throw Error(`${
|
|
81
|
+
} else if (e?.status === 401) throw Error(x);
|
|
82
|
+
throw Error(`${v}(received status ${e?.status} when fetching the app config)`);
|
|
83
83
|
}
|
|
84
|
-
async function
|
|
85
|
-
let { http_protocol: e, host: t } = await
|
|
84
|
+
async function O() {
|
|
85
|
+
let { http_protocol: e, host: t } = await P(this.app_reference, this.options.token);
|
|
86
86
|
try {
|
|
87
87
|
if (this.options.auth) {
|
|
88
|
-
let n = await
|
|
88
|
+
let n = await k(e, t, this.options.auth, this.fetch, this.options.token, this.options.credentials);
|
|
89
89
|
n && this.set_cookies(n);
|
|
90
90
|
}
|
|
91
91
|
} catch (e) {
|
|
92
92
|
throw Error(e.message);
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
|
-
async function
|
|
95
|
+
async function k(e, t, n, r, i, a) {
|
|
96
96
|
let o = new FormData();
|
|
97
97
|
o.append("username", n?.[0]), o.append("password", n?.[1]);
|
|
98
98
|
let s = {};
|
|
@@ -104,9 +104,9 @@ async function j(e, t, n, r, i, a) {
|
|
|
104
104
|
credentials: a ?? "same-origin"
|
|
105
105
|
});
|
|
106
106
|
if (c.status === 200) return c.headers.get("set-cookie");
|
|
107
|
-
throw c.status === 401 ? Error(
|
|
107
|
+
throw c.status === 401 ? Error(S) : Error(b);
|
|
108
108
|
}
|
|
109
|
-
function
|
|
109
|
+
function A(e) {
|
|
110
110
|
if (e.startsWith("http")) {
|
|
111
111
|
let { protocol: t, host: n, pathname: r } = new URL(e);
|
|
112
112
|
return {
|
|
@@ -121,39 +121,39 @@ function M(e) {
|
|
|
121
121
|
host: new URL(e).host
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
|
-
var
|
|
124
|
+
var j = (e) => {
|
|
125
125
|
let t = [];
|
|
126
126
|
return e.split(/,(?=\s*[^\s=;]+=[^\s=;]+)/).forEach((e) => {
|
|
127
127
|
let [n, r] = e.split(";")[0].split("=");
|
|
128
128
|
n && r && t.push(`${n.trim()}=${r.trim()}`);
|
|
129
129
|
}), t;
|
|
130
|
-
},
|
|
131
|
-
async function
|
|
130
|
+
}, M = /^[a-zA-Z0-9_\-\.]+\/[a-zA-Z0-9_\-\.]+$/, N = /.*hf\.space\/{0,1}.*$/;
|
|
131
|
+
async function P(e, t) {
|
|
132
132
|
let n = {};
|
|
133
133
|
t && (n.Authorization = `Bearer ${t}`);
|
|
134
134
|
let r = e.trim().replace(/\/$/, "");
|
|
135
|
-
if (
|
|
135
|
+
if (M.test(r)) {
|
|
136
136
|
let e;
|
|
137
137
|
try {
|
|
138
138
|
e = await fetch(`https://huggingface.co/api/spaces/${r}/${l}`, { headers: n });
|
|
139
139
|
} catch {
|
|
140
|
-
throw Error(
|
|
140
|
+
throw Error(b);
|
|
141
141
|
}
|
|
142
|
-
if (e.status === 401 || e.status === 404) throw Error(
|
|
142
|
+
if (e.status === 401 || e.status === 404) throw Error(w(r, e.status));
|
|
143
143
|
let t;
|
|
144
144
|
try {
|
|
145
145
|
t = (await e.json()).host;
|
|
146
146
|
} catch {
|
|
147
|
-
throw Error(
|
|
147
|
+
throw Error(b);
|
|
148
148
|
}
|
|
149
|
-
if (!t) throw Error(
|
|
149
|
+
if (!t) throw Error(b);
|
|
150
150
|
return {
|
|
151
151
|
space_id: r,
|
|
152
|
-
...
|
|
152
|
+
...A(t)
|
|
153
153
|
};
|
|
154
154
|
}
|
|
155
|
-
if (
|
|
156
|
-
let { ws_protocol: e, http_protocol: t, host: n } =
|
|
155
|
+
if (N.test(r)) {
|
|
156
|
+
let { ws_protocol: e, http_protocol: t, host: n } = A(r);
|
|
157
157
|
return {
|
|
158
158
|
space_id: n.split("/")[0].replace(".hf.space", ""),
|
|
159
159
|
ws_protocol: e,
|
|
@@ -163,17 +163,17 @@ async function I(e, t) {
|
|
|
163
163
|
}
|
|
164
164
|
return {
|
|
165
165
|
space_id: !1,
|
|
166
|
-
...
|
|
166
|
+
...A(r)
|
|
167
167
|
};
|
|
168
168
|
}
|
|
169
|
-
var
|
|
169
|
+
var F = (...e) => {
|
|
170
170
|
try {
|
|
171
171
|
return e.reduce((e, t) => (e = e.replace(/\/+$/, ""), t = t.replace(/^\/+/, ""), new URL(t, e + "/").toString()));
|
|
172
172
|
} catch {
|
|
173
|
-
throw Error(
|
|
173
|
+
throw Error(ce);
|
|
174
174
|
}
|
|
175
175
|
};
|
|
176
|
-
function
|
|
176
|
+
function ve(e, t, n) {
|
|
177
177
|
let r = {
|
|
178
178
|
named_endpoints: {},
|
|
179
179
|
unnamed_endpoints: {}
|
|
@@ -203,8 +203,8 @@ function ge(e, t, n) {
|
|
|
203
203
|
}
|
|
204
204
|
let d = (e, t, n, r) => ({
|
|
205
205
|
...e,
|
|
206
|
-
description:
|
|
207
|
-
type:
|
|
206
|
+
description: ye(e?.type, n),
|
|
207
|
+
type: I(e?.type, t, n, r) || ""
|
|
208
208
|
});
|
|
209
209
|
r[i][e] = {
|
|
210
210
|
parameters: o.map((e) => d(e, e?.component, e?.serializer, "parameter")),
|
|
@@ -215,7 +215,7 @@ function ge(e, t, n) {
|
|
|
215
215
|
}));
|
|
216
216
|
}), r;
|
|
217
217
|
}
|
|
218
|
-
function
|
|
218
|
+
function I(e, t, n, r) {
|
|
219
219
|
if (t === "Api") return e.type;
|
|
220
220
|
switch (e?.type) {
|
|
221
221
|
case "string": return "string";
|
|
@@ -228,10 +228,10 @@ function R(e, t, n, r) {
|
|
|
228
228
|
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}";
|
|
229
229
|
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))][]";
|
|
230
230
|
}
|
|
231
|
-
function
|
|
231
|
+
function ye(e, t) {
|
|
232
232
|
return t === "GallerySerializable" ? "array of [file, label] tuples" : t === "ListStringSerializable" ? "array of strings" : t === "FileSerializable" ? "array of files or single file" : e?.description;
|
|
233
233
|
}
|
|
234
|
-
function
|
|
234
|
+
function be(e, t) {
|
|
235
235
|
switch (e.msg) {
|
|
236
236
|
case "send_data": return { type: "data" };
|
|
237
237
|
case "send_hash": return { type: "hash" };
|
|
@@ -239,7 +239,7 @@ function ve(e, t) {
|
|
|
239
239
|
type: "update",
|
|
240
240
|
status: {
|
|
241
241
|
queue: !0,
|
|
242
|
-
message:
|
|
242
|
+
message: oe,
|
|
243
243
|
stage: "error",
|
|
244
244
|
code: e.code,
|
|
245
245
|
success: e.success
|
|
@@ -367,7 +367,7 @@ function ve(e, t) {
|
|
|
367
367
|
}
|
|
368
368
|
};
|
|
369
369
|
}
|
|
370
|
-
var
|
|
370
|
+
var xe = (e = [], t) => {
|
|
371
371
|
let n = t ? t.parameters : [];
|
|
372
372
|
if (Array.isArray(e)) return t && n.length > 0 && e.length > n.length && console.warn("Too many arguments provided for the endpoint."), e;
|
|
373
373
|
let r = [], i = Object.keys(e);
|
|
@@ -383,28 +383,28 @@ var ye = (e = [], t) => {
|
|
|
383
383
|
};
|
|
384
384
|
//#endregion
|
|
385
385
|
//#region src/utils/view_api.ts
|
|
386
|
-
async function
|
|
386
|
+
async function Se() {
|
|
387
387
|
if (this.api_info) return this.api_info;
|
|
388
388
|
let { token: e } = this.options, { config: t } = this, n = {};
|
|
389
389
|
if (e && (n.Authorization = `Bearer ${e}`), t) try {
|
|
390
390
|
let e, r;
|
|
391
391
|
if (typeof window < "u" && window.gradio_api_info) r = window.gradio_api_info;
|
|
392
392
|
else {
|
|
393
|
-
let i = new URL(
|
|
393
|
+
let i = new URL(F(t.root, this.api_prefix, ee));
|
|
394
394
|
if (this.page !== null && i.searchParams.set("page", this.page), e = await this.fetch(i, {
|
|
395
395
|
headers: n,
|
|
396
396
|
credentials: this.options.credentials ?? "same-origin"
|
|
397
|
-
}), !e.ok) throw Error(
|
|
397
|
+
}), !e.ok) throw Error(_);
|
|
398
398
|
r = await e.json();
|
|
399
399
|
}
|
|
400
|
-
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"]), ve(r, t, this.api_map);
|
|
401
401
|
} catch (e) {
|
|
402
402
|
throw Error("Could not get API info. " + e.message);
|
|
403
403
|
}
|
|
404
404
|
}
|
|
405
405
|
//#endregion
|
|
406
406
|
//#region src/utils/upload_files.ts
|
|
407
|
-
async function
|
|
407
|
+
async function L(e, t, n) {
|
|
408
408
|
let r = {};
|
|
409
409
|
this?.options?.token && (r.Authorization = `Bearer ${this.options.token}`);
|
|
410
410
|
let i = 1e3, a = [], o;
|
|
@@ -422,7 +422,7 @@ async function xe(e, t, n) {
|
|
|
422
422
|
credentials: this.options.credentials ?? "same-origin"
|
|
423
423
|
});
|
|
424
424
|
} catch (e) {
|
|
425
|
-
throw Error(
|
|
425
|
+
throw Error(_ + e.message);
|
|
426
426
|
}
|
|
427
427
|
if (!o.ok) {
|
|
428
428
|
let e = await o.text();
|
|
@@ -433,7 +433,7 @@ async function xe(e, t, n) {
|
|
|
433
433
|
}
|
|
434
434
|
return { files: a };
|
|
435
435
|
}
|
|
436
|
-
var
|
|
436
|
+
var R = {
|
|
437
437
|
si: {
|
|
438
438
|
radix: 1e3,
|
|
439
439
|
unit: [
|
|
@@ -479,7 +479,7 @@ var Se = {
|
|
|
479
479
|
};
|
|
480
480
|
function Ce(e, t = 1, n = "jedec") {
|
|
481
481
|
e = Math.abs(e);
|
|
482
|
-
let { radix: r, unit: i } =
|
|
482
|
+
let { radix: r, unit: i } = R[n] || R.jedec, a = 0;
|
|
483
483
|
for (; e >= r;) e /= r, ++a;
|
|
484
484
|
return `${e.toFixed(t)} ${i[a]}`;
|
|
485
485
|
}
|
|
@@ -670,7 +670,7 @@ async function Me(e, t, n) {
|
|
|
670
670
|
}), t;
|
|
671
671
|
}
|
|
672
672
|
async function Ne(e, t) {
|
|
673
|
-
if (!(e.config?.root || e.config?.root_url)) throw Error(
|
|
673
|
+
if (!(e.config?.root || e.config?.root_url)) throw Error(pe);
|
|
674
674
|
await Pe(e, t);
|
|
675
675
|
}
|
|
676
676
|
async function Pe(e, t, n = []) {
|
|
@@ -678,20 +678,20 @@ async function Pe(e, t, n = []) {
|
|
|
678
678
|
}
|
|
679
679
|
async function Fe(e, t, n) {
|
|
680
680
|
let r = t[n], i = e.config?.root || e.config?.root_url;
|
|
681
|
-
if (!i) throw Error(
|
|
681
|
+
if (!i) throw Error(pe);
|
|
682
682
|
try {
|
|
683
683
|
let a, o;
|
|
684
684
|
if (typeof process < "u" && process.versions && process.versions.node) {
|
|
685
685
|
let e = await import("./__vite-browser-external-Cgmn0awE.js").then((e) => /* @__PURE__ */ c(e.default, 1));
|
|
686
686
|
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);
|
|
687
|
-
} else throw Error(
|
|
687
|
+
} else throw Error(fe);
|
|
688
688
|
let s = new Blob([a], { type: "application/octet-stream" }), l = await e.upload_files(i, [s]), u = l.files && l.files[0];
|
|
689
689
|
u && (t[n] = new V({
|
|
690
690
|
path: u,
|
|
691
691
|
orig_name: r.meta.name || ""
|
|
692
692
|
}));
|
|
693
693
|
} catch (e) {
|
|
694
|
-
console.error(
|
|
694
|
+
console.error(me, e);
|
|
695
695
|
}
|
|
696
696
|
}
|
|
697
697
|
//#endregion
|
|
@@ -710,7 +710,7 @@ async function Ie(e, t, n) {
|
|
|
710
710
|
credentials: this.options.credentials ?? "same-origin"
|
|
711
711
|
});
|
|
712
712
|
} catch {
|
|
713
|
-
return [{ error:
|
|
713
|
+
return [{ error: _ }, 500];
|
|
714
714
|
}
|
|
715
715
|
let a, o;
|
|
716
716
|
try {
|
|
@@ -754,7 +754,7 @@ async function G(e, t, n) {
|
|
|
754
754
|
n({
|
|
755
755
|
status: "error",
|
|
756
756
|
load_status: "error",
|
|
757
|
-
message:
|
|
757
|
+
message: y,
|
|
758
758
|
detail: "NOT_FOUND"
|
|
759
759
|
});
|
|
760
760
|
return;
|
|
@@ -825,7 +825,7 @@ async function G(e, t, n) {
|
|
|
825
825
|
var Re = async (e, t) => {
|
|
826
826
|
let n = 0;
|
|
827
827
|
return new Promise((r) => {
|
|
828
|
-
G(e,
|
|
828
|
+
G(e, M.test(e) ? "space_name" : "subdomain", (i) => {
|
|
829
829
|
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(() => {
|
|
830
830
|
Re(e, t).then(r);
|
|
831
831
|
}, 5e3)) : r());
|
|
@@ -844,7 +844,7 @@ async function Ve(e, t) {
|
|
|
844
844
|
let n = {};
|
|
845
845
|
t && (n.Authorization = `Bearer ${t}`);
|
|
846
846
|
try {
|
|
847
|
-
let t = await fetch(`https://huggingface.co/api/spaces/${e}/${
|
|
847
|
+
let t = await fetch(`https://huggingface.co/api/spaces/${e}/${te}`, { headers: n });
|
|
848
848
|
if (t.status !== 200) throw Error("Space hardware could not be obtained.");
|
|
849
849
|
let { hardware: r } = await t.json();
|
|
850
850
|
return r.current;
|
|
@@ -857,7 +857,7 @@ async function He(e, t, n) {
|
|
|
857
857
|
n && (r.Authorization = `Bearer ${n}`);
|
|
858
858
|
let i = { seconds: t };
|
|
859
859
|
try {
|
|
860
|
-
let t = await fetch(`https://huggingface.co/api/spaces/${e}/${
|
|
860
|
+
let t = await fetch(`https://huggingface.co/api/spaces/${e}/${ne}`, {
|
|
861
861
|
method: "POST",
|
|
862
862
|
headers: {
|
|
863
863
|
"Content-Type": "application/json",
|
|
@@ -889,13 +889,13 @@ var Ue = [
|
|
|
889
889
|
//#endregion
|
|
890
890
|
//#region src/utils/duplicate.ts
|
|
891
891
|
async function We(e, t) {
|
|
892
|
-
|
|
892
|
+
T(t);
|
|
893
893
|
let { token: n, private: r, hardware: i, timeout: a, auth: o } = t;
|
|
894
894
|
if (i && !Ue.includes(i)) throw Error(`Invalid hardware type provided. Valid types are: ${Ue.map((e) => `"${e}"`).join(",")}.`);
|
|
895
|
-
let { http_protocol: s, host: c } = await
|
|
895
|
+
let { http_protocol: s, host: c } = await P(e, n), l = null;
|
|
896
896
|
if (o) {
|
|
897
|
-
let e = await
|
|
898
|
-
e && (l =
|
|
897
|
+
let e = await k(s, c, o, fetch, void 0, t.credentials);
|
|
898
|
+
e && (l = j(e));
|
|
899
899
|
}
|
|
900
900
|
let u = {
|
|
901
901
|
Authorization: `Bearer ${n}`,
|
|
@@ -907,7 +907,7 @@ async function We(e, t) {
|
|
|
907
907
|
try {
|
|
908
908
|
i || (m = await Ve(e, n));
|
|
909
909
|
} catch (e) {
|
|
910
|
-
throw Error(
|
|
910
|
+
throw Error(b + e.message);
|
|
911
911
|
}
|
|
912
912
|
p.hardware = i || m || "cpu-basic";
|
|
913
913
|
try {
|
|
@@ -917,13 +917,13 @@ async function We(e, t) {
|
|
|
917
917
|
body: JSON.stringify(p)
|
|
918
918
|
});
|
|
919
919
|
if (r.status === 409) try {
|
|
920
|
-
return await
|
|
920
|
+
return await Q.connect(`${d}/${f}`, t);
|
|
921
921
|
} catch (e) {
|
|
922
922
|
throw console.error("Failed to connect Client instance:", e), e;
|
|
923
923
|
}
|
|
924
924
|
else if (r.status !== 200) throw Error(r.statusText);
|
|
925
925
|
let i = await r.json();
|
|
926
|
-
return await He(`${d}/${f}`, a || 300, n), await
|
|
926
|
+
return await He(`${d}/${f}`, a || 300, n), await Q.connect(Ge(i.url), t);
|
|
927
927
|
} catch (e) {
|
|
928
928
|
throw Error(e);
|
|
929
929
|
}
|
|
@@ -1045,7 +1045,7 @@ async function rt() {
|
|
|
1045
1045
|
}, s.onerror = async function(t) {
|
|
1046
1046
|
console.error(t), await Promise.all(Object.keys(e).map((t) => e[t]({
|
|
1047
1047
|
msg: "broken_connection",
|
|
1048
|
-
message:
|
|
1048
|
+
message: _
|
|
1049
1049
|
})));
|
|
1050
1050
|
};
|
|
1051
1051
|
}
|
|
@@ -1129,37 +1129,37 @@ function ct(e, t = {}) {
|
|
|
1129
1129
|
}
|
|
1130
1130
|
//#endregion
|
|
1131
1131
|
//#region src/utils/run_history.ts
|
|
1132
|
-
var
|
|
1133
|
-
function
|
|
1132
|
+
var lt = "gradio:run-history:", K = `${lt}v2:`, ut = `${lt}replay:v2:`, dt = `${lt}destination:v1:`, ft = 100, pt = 8;
|
|
1133
|
+
function q(e, t) {
|
|
1134
1134
|
try {
|
|
1135
1135
|
return e();
|
|
1136
1136
|
} catch (e) {
|
|
1137
1137
|
return console.warn("Could not update the run history.", e), t;
|
|
1138
1138
|
}
|
|
1139
1139
|
}
|
|
1140
|
-
function
|
|
1140
|
+
function mt(e, t = "/gradio_api") {
|
|
1141
1141
|
return `${e.replace(/\/+$/, "")}${t}/runs`;
|
|
1142
1142
|
}
|
|
1143
|
-
function
|
|
1143
|
+
function J(e) {
|
|
1144
1144
|
if (typeof window > "u") return null;
|
|
1145
1145
|
let t = e?.app_id;
|
|
1146
1146
|
if (t == null || t === "") return null;
|
|
1147
1147
|
try {
|
|
1148
|
-
return window.localStorage ? `${
|
|
1148
|
+
return window.localStorage ? `${K}${t}${e?.username ? `:user:${encodeURIComponent(e.username)}` : ""}` : null;
|
|
1149
1149
|
} catch {
|
|
1150
1150
|
return null;
|
|
1151
1151
|
}
|
|
1152
1152
|
}
|
|
1153
|
-
function mt(e) {
|
|
1154
|
-
let t = Y(e);
|
|
1155
|
-
return t ? t.replace(q, lt) : null;
|
|
1156
|
-
}
|
|
1157
1153
|
function ht(e) {
|
|
1158
|
-
let t =
|
|
1159
|
-
return t ? t.replace(
|
|
1154
|
+
let t = J(e);
|
|
1155
|
+
return t ? t.replace(K, ut) : null;
|
|
1160
1156
|
}
|
|
1161
1157
|
function gt(e) {
|
|
1162
|
-
let t =
|
|
1158
|
+
let t = J(e);
|
|
1159
|
+
return t ? t.replace(K, dt) : null;
|
|
1160
|
+
}
|
|
1161
|
+
function _t(e) {
|
|
1162
|
+
let t = gt(e);
|
|
1163
1163
|
if (!t) return { type: "browser" };
|
|
1164
1164
|
try {
|
|
1165
1165
|
let e = JSON.parse(window.localStorage.getItem(t) || "null");
|
|
@@ -1174,11 +1174,11 @@ function gt(e) {
|
|
|
1174
1174
|
return { type: "browser" };
|
|
1175
1175
|
}
|
|
1176
1176
|
}
|
|
1177
|
-
function
|
|
1178
|
-
let n =
|
|
1179
|
-
n && (t.type === "browser" && !t.bucket_id ? window.localStorage.removeItem(n) : window.localStorage.setItem(n, JSON.stringify(t)),
|
|
1177
|
+
function vt(e, t) {
|
|
1178
|
+
let n = gt(e);
|
|
1179
|
+
n && (t.type === "browser" && !t.bucket_id ? window.localStorage.removeItem(n) : window.localStorage.setItem(n, JSON.stringify(t)), Et());
|
|
1180
1180
|
}
|
|
1181
|
-
function
|
|
1181
|
+
function yt(e) {
|
|
1182
1182
|
try {
|
|
1183
1183
|
let t = JSON.parse(window.localStorage.getItem(e) || "[]");
|
|
1184
1184
|
return Array.isArray(t) && t.length && Date.parse(t[0]?.started_at) || 0;
|
|
@@ -1186,16 +1186,16 @@ function vt(e) {
|
|
|
1186
1186
|
return 0;
|
|
1187
1187
|
}
|
|
1188
1188
|
}
|
|
1189
|
-
function
|
|
1190
|
-
let t = Object.keys(window.localStorage).filter((e) => e.startsWith(
|
|
1189
|
+
function bt(e) {
|
|
1190
|
+
let t = Object.keys(window.localStorage).filter((e) => e.startsWith(lt)), n = [...t.filter((e) => !e.startsWith(K) && !e.startsWith(ut) && !e.startsWith(dt)), ...t.filter((t) => t.startsWith(K) && t !== e).sort((e, t) => yt(t) - yt(e)).slice(pt - 1)];
|
|
1191
1191
|
for (let e of n) try {
|
|
1192
|
-
window.localStorage.removeItem(e), window.sessionStorage.removeItem(e.replace(
|
|
1192
|
+
window.localStorage.removeItem(e), window.sessionStorage.removeItem(e.replace(K, ut));
|
|
1193
1193
|
} catch {}
|
|
1194
1194
|
}
|
|
1195
|
-
function
|
|
1195
|
+
function xt() {
|
|
1196
1196
|
return typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
1197
1197
|
}
|
|
1198
|
-
function
|
|
1198
|
+
function Y(e) {
|
|
1199
1199
|
let t = /* @__PURE__ */ new WeakSet();
|
|
1200
1200
|
try {
|
|
1201
1201
|
return JSON.parse(JSON.stringify(e, (e, n) => {
|
|
@@ -1210,8 +1210,8 @@ function X(e) {
|
|
|
1210
1210
|
return "[Unserializable value]";
|
|
1211
1211
|
}
|
|
1212
1212
|
}
|
|
1213
|
-
function
|
|
1214
|
-
let t =
|
|
1213
|
+
function X(e) {
|
|
1214
|
+
let t = J(e);
|
|
1215
1215
|
if (!t) return [];
|
|
1216
1216
|
try {
|
|
1217
1217
|
let e = JSON.parse(window.localStorage.getItem(t) || "[]");
|
|
@@ -1220,16 +1220,16 @@ function Z(e) {
|
|
|
1220
1220
|
return [];
|
|
1221
1221
|
}
|
|
1222
1222
|
}
|
|
1223
|
-
function
|
|
1224
|
-
let n =
|
|
1223
|
+
function St(e, t) {
|
|
1224
|
+
let n = J(e);
|
|
1225
1225
|
if (!n) return;
|
|
1226
|
-
let r = t.slice(0,
|
|
1226
|
+
let r = t.slice(0, ft), i = !1;
|
|
1227
1227
|
for (; r.length > 0;) try {
|
|
1228
1228
|
window.localStorage.setItem(n, JSON.stringify(r));
|
|
1229
1229
|
return;
|
|
1230
1230
|
} catch {
|
|
1231
1231
|
if (!i) {
|
|
1232
|
-
i = !0,
|
|
1232
|
+
i = !0, bt(n);
|
|
1233
1233
|
continue;
|
|
1234
1234
|
}
|
|
1235
1235
|
r = r.slice(0, -1);
|
|
@@ -1238,37 +1238,37 @@ function xt(e, t) {
|
|
|
1238
1238
|
window.localStorage.removeItem(n);
|
|
1239
1239
|
} catch {}
|
|
1240
1240
|
}
|
|
1241
|
-
function
|
|
1242
|
-
let t =
|
|
1241
|
+
function Ct(e) {
|
|
1242
|
+
let t = J(e);
|
|
1243
1243
|
if (t) {
|
|
1244
1244
|
try {
|
|
1245
1245
|
window.localStorage.removeItem(t);
|
|
1246
1246
|
} catch {}
|
|
1247
|
-
|
|
1247
|
+
Et();
|
|
1248
1248
|
}
|
|
1249
1249
|
}
|
|
1250
|
-
function
|
|
1251
|
-
|
|
1250
|
+
function wt(e, t) {
|
|
1251
|
+
St(e, X(e).filter((e) => e.id !== t)), Et();
|
|
1252
1252
|
}
|
|
1253
|
-
var
|
|
1254
|
-
function
|
|
1253
|
+
var Tt = "gradio:run-history-change";
|
|
1254
|
+
function Et() {
|
|
1255
1255
|
if (!(typeof window > "u")) try {
|
|
1256
|
-
window.dispatchEvent(new Event(
|
|
1256
|
+
window.dispatchEvent(new Event(Tt));
|
|
1257
1257
|
} catch {}
|
|
1258
1258
|
}
|
|
1259
|
-
function
|
|
1260
|
-
return typeof window > "u" ? () => {} : (window.addEventListener(
|
|
1261
|
-
window.removeEventListener(
|
|
1259
|
+
function Dt(e) {
|
|
1260
|
+
return typeof window > "u" ? () => {} : (window.addEventListener(Tt, e), window.addEventListener("storage", e), () => {
|
|
1261
|
+
window.removeEventListener(Tt, e), window.removeEventListener("storage", e);
|
|
1262
1262
|
});
|
|
1263
1263
|
}
|
|
1264
|
-
function
|
|
1265
|
-
let n =
|
|
1264
|
+
function Ot(e, t) {
|
|
1265
|
+
let n = ht(e);
|
|
1266
1266
|
if (n) try {
|
|
1267
1267
|
window.sessionStorage.setItem(n, JSON.stringify(t));
|
|
1268
1268
|
} catch {}
|
|
1269
1269
|
}
|
|
1270
|
-
function
|
|
1271
|
-
let t =
|
|
1270
|
+
function kt(e) {
|
|
1271
|
+
let t = ht(e);
|
|
1272
1272
|
if (!t) return null;
|
|
1273
1273
|
try {
|
|
1274
1274
|
let e = window.sessionStorage.getItem(t);
|
|
@@ -1277,7 +1277,7 @@ function Ot(e) {
|
|
|
1277
1277
|
return null;
|
|
1278
1278
|
}
|
|
1279
1279
|
}
|
|
1280
|
-
function
|
|
1280
|
+
function At(e, t) {
|
|
1281
1281
|
let n = e.dependencies.find((e) => e.id === t.fn_index || typeof e.api_name == "string" && `/${e.api_name.replace(/^\//, "")}` === t.api_name);
|
|
1282
1282
|
if (!n) return !1;
|
|
1283
1283
|
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) => {
|
|
@@ -1288,147 +1288,147 @@ function kt(e, t) {
|
|
|
1288
1288
|
};
|
|
1289
1289
|
return a(n.inputs, r), a(n.outputs, i), !0;
|
|
1290
1290
|
}
|
|
1291
|
-
function At(e) {
|
|
1292
|
-
let t = Ot(e);
|
|
1293
|
-
return t ? kt(e, t) : !1;
|
|
1294
|
-
}
|
|
1295
1291
|
function jt(e) {
|
|
1296
|
-
|
|
1297
|
-
|
|
1292
|
+
let t = kt(e);
|
|
1293
|
+
return t ? At(e, t) : !1;
|
|
1294
|
+
}
|
|
1295
|
+
function Mt(e) {
|
|
1296
|
+
if (_t(e).type === "bucket") return null;
|
|
1297
|
+
let t = J(e);
|
|
1298
1298
|
if (!t) return null;
|
|
1299
|
-
|
|
1299
|
+
bt(t);
|
|
1300
1300
|
let n = {
|
|
1301
|
-
id:
|
|
1301
|
+
id: xt(),
|
|
1302
1302
|
endpoint: e.endpoint,
|
|
1303
1303
|
api_name: e.api_name,
|
|
1304
1304
|
fn_index: e.fn_index,
|
|
1305
1305
|
page: `${window.location.pathname}${window.location.search}`,
|
|
1306
|
-
inputs:
|
|
1306
|
+
inputs: Y(e.inputs),
|
|
1307
1307
|
outputs: null,
|
|
1308
|
-
...e.input_components ? { input_components:
|
|
1309
|
-
...e.output_components ? { output_components:
|
|
1308
|
+
...e.input_components ? { input_components: Y(e.input_components) } : {},
|
|
1309
|
+
...e.output_components ? { output_components: Y(e.output_components) } : {},
|
|
1310
1310
|
status: "running",
|
|
1311
1311
|
started_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1312
1312
|
};
|
|
1313
|
-
return
|
|
1313
|
+
return St(e, [n, ...X(e)]), Et(), n.id;
|
|
1314
1314
|
}
|
|
1315
|
-
function
|
|
1315
|
+
function Nt(e, t, n) {
|
|
1316
1316
|
if (!t) return;
|
|
1317
|
-
let r =
|
|
1318
|
-
i && (i.inputs =
|
|
1317
|
+
let r = X(e), i = r.find((e) => e.id === t);
|
|
1318
|
+
i && (i.inputs = Y(n), St(e, r));
|
|
1319
1319
|
}
|
|
1320
|
-
function
|
|
1320
|
+
function Pt(e, t, n) {
|
|
1321
1321
|
if (!t) return;
|
|
1322
|
-
let r =
|
|
1322
|
+
let r = X(e), i = r.find((e) => e.id === t);
|
|
1323
1323
|
if (!i) return;
|
|
1324
1324
|
let a = !1;
|
|
1325
|
-
if (n.type === "data") i.outputs =
|
|
1326
|
-
else if (n.type === "status" && n.original_msg === "process_starts")
|
|
1325
|
+
if (n.type === "data") i.outputs = Y(n.data), Z.set(t, i.outputs);
|
|
1326
|
+
else if (n.type === "status" && n.original_msg === "process_starts") Lt(i, n.time);
|
|
1327
1327
|
else if (n.type === "status" && (n.stage === "generating" || n.stage === "streaming")) i.streamed = !0;
|
|
1328
|
-
else if (n.type === "status" && n.stage === "complete") i.status = "completed",
|
|
1329
|
-
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"),
|
|
1328
|
+
else if (n.type === "status" && n.stage === "complete") i.status = "completed", Rt(i, n), a = !0;
|
|
1329
|
+
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;
|
|
1330
1330
|
else return;
|
|
1331
|
-
if (a)
|
|
1331
|
+
if (a) Z.has(t) && (i.outputs = Z.get(t)), Z.delete(t), It.delete(t);
|
|
1332
1332
|
else if (i.streamed) {
|
|
1333
|
-
if (Date.now() - (
|
|
1334
|
-
|
|
1333
|
+
if (Date.now() - (It.get(t) ?? 0) < Ft) return;
|
|
1334
|
+
It.set(t, Date.now()), Z.delete(t);
|
|
1335
1335
|
}
|
|
1336
|
-
|
|
1336
|
+
St(e, r);
|
|
1337
1337
|
}
|
|
1338
|
-
var
|
|
1339
|
-
function
|
|
1338
|
+
var Ft = 500, It = /* @__PURE__ */ new Map(), Z = /* @__PURE__ */ new Map();
|
|
1339
|
+
function Lt(e, t) {
|
|
1340
1340
|
if (e.process_started_at) return;
|
|
1341
1341
|
let n = t || /* @__PURE__ */ new Date();
|
|
1342
1342
|
e.process_started_at = n.toISOString(), e.queued_ms = Math.max(0, n.getTime() - Date.parse(e.started_at));
|
|
1343
1343
|
}
|
|
1344
|
-
function
|
|
1344
|
+
function Rt(e, t) {
|
|
1345
1345
|
let n = t.time || /* @__PURE__ */ new Date();
|
|
1346
1346
|
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));
|
|
1347
1347
|
}
|
|
1348
|
-
function Rt(e) {
|
|
1349
|
-
return J(() => Z(e), []);
|
|
1350
|
-
}
|
|
1351
1348
|
function zt(e) {
|
|
1352
|
-
return
|
|
1349
|
+
return q(() => X(e), []);
|
|
1353
1350
|
}
|
|
1354
|
-
function Bt(e
|
|
1355
|
-
|
|
1351
|
+
function Bt(e) {
|
|
1352
|
+
return q(() => _t(e), { type: "browser" });
|
|
1356
1353
|
}
|
|
1357
|
-
function Vt(e) {
|
|
1358
|
-
|
|
1354
|
+
function Vt(e, t) {
|
|
1355
|
+
q(() => vt(e, t), void 0);
|
|
1359
1356
|
}
|
|
1360
|
-
function Ht(e
|
|
1361
|
-
|
|
1357
|
+
function Ht(e) {
|
|
1358
|
+
q(() => Ct(e), void 0);
|
|
1362
1359
|
}
|
|
1363
1360
|
function Ut(e, t) {
|
|
1364
|
-
|
|
1361
|
+
q(() => wt(e, t), void 0);
|
|
1365
1362
|
}
|
|
1366
|
-
function Wt(e) {
|
|
1367
|
-
|
|
1363
|
+
function Wt(e, t) {
|
|
1364
|
+
q(() => Ot(e, t), void 0);
|
|
1368
1365
|
}
|
|
1369
1366
|
function Gt(e) {
|
|
1370
|
-
return
|
|
1367
|
+
return q(() => kt(e), null);
|
|
1371
1368
|
}
|
|
1372
1369
|
function Kt(e) {
|
|
1373
|
-
return
|
|
1370
|
+
return q(() => jt(e), !1);
|
|
1374
1371
|
}
|
|
1375
|
-
function qt(e
|
|
1376
|
-
|
|
1372
|
+
function qt(e) {
|
|
1373
|
+
return q(() => Mt(e), null);
|
|
1377
1374
|
}
|
|
1378
1375
|
function Jt(e, t, n) {
|
|
1379
|
-
|
|
1376
|
+
q(() => Nt(e, t, n), void 0);
|
|
1380
1377
|
}
|
|
1381
|
-
function Yt(e) {
|
|
1382
|
-
|
|
1378
|
+
function Yt(e, t, n) {
|
|
1379
|
+
q(() => Pt(e, t, n), void 0);
|
|
1380
|
+
}
|
|
1381
|
+
function Xt(e) {
|
|
1382
|
+
return q(() => Dt(() => q(e, void 0)), () => {});
|
|
1383
1383
|
}
|
|
1384
1384
|
//#endregion
|
|
1385
1385
|
//#region src/utils/submit.ts
|
|
1386
|
-
function
|
|
1386
|
+
function Zt(e, t = {}, n, r, i, a) {
|
|
1387
1387
|
try {
|
|
1388
|
-
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:
|
|
1389
|
-
if (!p) throw Error(
|
|
1388
|
+
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: te, pending_diff_streams: ne, event_callbacks: h, unclosed_events: re, post_data: g, options: v, api_prefix: y } = this, se = a || { "x-gradio-user": "api" }, b = this;
|
|
1389
|
+
if (!p) throw Error(ue);
|
|
1390
1390
|
if (!l) throw Error("Could not resolve app config");
|
|
1391
|
-
let
|
|
1392
|
-
if (
|
|
1393
|
-
let
|
|
1391
|
+
let ce = l.root, { fn_index: x, endpoint_info: S, dependency: C } = $t(p, e, m, l), le = xe(t, S), w = l.protocol ?? "ws";
|
|
1392
|
+
if (w === "ws") throw Error(de);
|
|
1393
|
+
let fe = typeof C.api_name == "string" ? `/${C.api_name}` : e, pe = typeof C.api_name == "string" ? `/${C.api_name}` : `Function ${x}`, me = (e) => {
|
|
1394
1394
|
let t = l.components.find((t) => t.id === e);
|
|
1395
1395
|
return t ? {
|
|
1396
1396
|
type: t.type,
|
|
1397
1397
|
component_class_id: t.component_class_id,
|
|
1398
1398
|
props: t.props
|
|
1399
1399
|
} : null;
|
|
1400
|
-
},
|
|
1400
|
+
}, he = C.api_visibility === "public", T = l.run_history !== !1 && this.options.record_history !== !1, E = {
|
|
1401
1401
|
app_id: l.app_id,
|
|
1402
1402
|
username: l.username
|
|
1403
|
-
},
|
|
1404
|
-
...
|
|
1405
|
-
...
|
|
1406
|
-
},
|
|
1407
|
-
...
|
|
1408
|
-
endpoint:
|
|
1409
|
-
api_name:
|
|
1410
|
-
fn_index:
|
|
1411
|
-
inputs: W(
|
|
1412
|
-
input_components:
|
|
1413
|
-
output_components:
|
|
1414
|
-
}),
|
|
1415
|
-
function
|
|
1416
|
-
|
|
1403
|
+
}, ge = Bt(E), D = {
|
|
1404
|
+
...se,
|
|
1405
|
+
...T && ge.type === "bucket" ? { "x-gradio-history-bucket": ge.bucket_id } : {}
|
|
1406
|
+
}, _e = !T || !he ? null : qt({
|
|
1407
|
+
...E,
|
|
1408
|
+
endpoint: fe,
|
|
1409
|
+
api_name: pe,
|
|
1410
|
+
fn_index: x,
|
|
1411
|
+
inputs: W(le, C, l.components, "input", !0),
|
|
1412
|
+
input_components: C.inputs.map(me),
|
|
1413
|
+
output_components: C.outputs.map(me)
|
|
1414
|
+
}), O, k = "", A = typeof e == "number" ? "/predict" : e, j, M = null, N = !1, P = {}, F = typeof window < "u" && typeof document < "u" ? new URLSearchParams(window.location.search).toString() : "", ve = v?.events?.reduce((e, t) => (e[t] = !0, e), {}) || {};
|
|
1415
|
+
function I(e) {
|
|
1416
|
+
Yt(E, _e, e), (e.type === "data" || e.type === "render") && Ae(e.data, ce, y, b.jwt), (i || ve[e.type]) && Te(e);
|
|
1417
1417
|
}
|
|
1418
|
-
async function
|
|
1418
|
+
async function ye() {
|
|
1419
1419
|
let e = {}, t = {};
|
|
1420
|
-
e = { event_id:
|
|
1421
|
-
event_id:
|
|
1420
|
+
e = { event_id: M }, t = {
|
|
1421
|
+
event_id: M,
|
|
1422
1422
|
session_hash: f,
|
|
1423
|
-
fn_index:
|
|
1423
|
+
fn_index: x
|
|
1424
1424
|
};
|
|
1425
1425
|
try {
|
|
1426
1426
|
if (!l) throw Error("Could not resolve app config");
|
|
1427
|
-
"event_id" in t && await s(`${l.root}${
|
|
1427
|
+
"event_id" in t && await s(`${l.root}${y}/${ae}`, {
|
|
1428
1428
|
headers: { "Content-Type": "application/json" },
|
|
1429
1429
|
method: "POST",
|
|
1430
1430
|
body: JSON.stringify(t)
|
|
1431
|
-
}), await s(`${l.root}${
|
|
1431
|
+
}), await s(`${l.root}${y}/${ie}`, {
|
|
1432
1432
|
headers: { "Content-Type": "application/json" },
|
|
1433
1433
|
method: "POST",
|
|
1434
1434
|
body: JSON.stringify(e)
|
|
@@ -1437,65 +1437,65 @@ function Xt(e, t = {}, n, r, i, a) {
|
|
|
1437
1437
|
console.warn("The `/reset` endpoint could not be called. Subsequent endpoint results may be unreliable.");
|
|
1438
1438
|
}
|
|
1439
1439
|
}
|
|
1440
|
-
let
|
|
1440
|
+
let Se = async (e) => {
|
|
1441
1441
|
await this._resolve_heartbeat(e);
|
|
1442
1442
|
};
|
|
1443
|
-
async function
|
|
1443
|
+
async function L(e) {
|
|
1444
1444
|
if (!l) return;
|
|
1445
1445
|
let t = e.render_id;
|
|
1446
1446
|
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];
|
|
1447
1447
|
let n = l.components.some((e) => e.type === "state"), r = l.dependencies.some((e) => e.targets.some((e) => e[1] === "unload"));
|
|
1448
|
-
l.connect_heartbeat = n || r, await
|
|
1448
|
+
l.connect_heartbeat = n || r, await Se(l), I({
|
|
1449
1449
|
type: "render",
|
|
1450
1450
|
data: e,
|
|
1451
|
-
endpoint:
|
|
1452
|
-
fn_index:
|
|
1451
|
+
endpoint: A,
|
|
1452
|
+
fn_index: x
|
|
1453
1453
|
});
|
|
1454
1454
|
}
|
|
1455
|
-
let
|
|
1456
|
-
let t = W(e,
|
|
1457
|
-
if (
|
|
1455
|
+
let R = this.handle_blob(l.root, le, S).then(async (e) => {
|
|
1456
|
+
let t = W(e, C, l.components, "input", !0);
|
|
1457
|
+
if (Jt(E, _e, t || []), j = {
|
|
1458
1458
|
data: t || [],
|
|
1459
1459
|
event_data: n,
|
|
1460
|
-
fn_index:
|
|
1460
|
+
fn_index: x,
|
|
1461
1461
|
trigger_id: r,
|
|
1462
|
-
...
|
|
1463
|
-
}, Ee(
|
|
1462
|
+
...v.oauth_token && S?.oauth_token ? { oauth_token: v.oauth_token } : {}
|
|
1463
|
+
}, Ee(x, l)) I({
|
|
1464
1464
|
type: "status",
|
|
1465
|
-
endpoint:
|
|
1465
|
+
endpoint: A,
|
|
1466
1466
|
stage: "pending",
|
|
1467
1467
|
queue: !1,
|
|
1468
|
-
fn_index:
|
|
1468
|
+
fn_index: x,
|
|
1469
1469
|
time: /* @__PURE__ */ new Date()
|
|
1470
|
-
}),
|
|
1471
|
-
...
|
|
1470
|
+
}), g(`${l.root}${y}/run${A.startsWith("/") ? A : `/${A}`}${F ? "?" + F : ""}`, {
|
|
1471
|
+
...j,
|
|
1472
1472
|
session_hash: f
|
|
1473
|
-
},
|
|
1473
|
+
}, D).then(async ([e, t]) => {
|
|
1474
1474
|
let i = e.data;
|
|
1475
|
-
if (t == 200)
|
|
1475
|
+
if (t == 200) I({
|
|
1476
1476
|
type: "data",
|
|
1477
|
-
endpoint:
|
|
1478
|
-
fn_index:
|
|
1479
|
-
data: W(i,
|
|
1477
|
+
endpoint: A,
|
|
1478
|
+
fn_index: x,
|
|
1479
|
+
data: W(i, C, l.components, "output", v.with_null_state),
|
|
1480
1480
|
time: /* @__PURE__ */ new Date(),
|
|
1481
1481
|
event_data: n,
|
|
1482
1482
|
trigger_id: r
|
|
1483
|
-
}), e.render_config && await
|
|
1483
|
+
}), e.render_config && await L(e.render_config), I({
|
|
1484
1484
|
type: "status",
|
|
1485
|
-
endpoint:
|
|
1486
|
-
fn_index:
|
|
1485
|
+
endpoint: A,
|
|
1486
|
+
fn_index: x,
|
|
1487
1487
|
stage: "complete",
|
|
1488
1488
|
eta: e.average_duration,
|
|
1489
1489
|
queue: !1,
|
|
1490
1490
|
time: /* @__PURE__ */ new Date()
|
|
1491
1491
|
});
|
|
1492
1492
|
else {
|
|
1493
|
-
let t = e?.error ===
|
|
1494
|
-
|
|
1493
|
+
let t = e?.error === _;
|
|
1494
|
+
I({
|
|
1495
1495
|
type: "status",
|
|
1496
1496
|
stage: "error",
|
|
1497
|
-
endpoint:
|
|
1498
|
-
fn_index:
|
|
1497
|
+
endpoint: A,
|
|
1498
|
+
fn_index: x,
|
|
1499
1499
|
message: e.error,
|
|
1500
1500
|
broken: t,
|
|
1501
1501
|
queue: !1,
|
|
@@ -1503,98 +1503,98 @@ function Xt(e, t = {}, n, r, i, a) {
|
|
|
1503
1503
|
});
|
|
1504
1504
|
}
|
|
1505
1505
|
}).catch((e) => {
|
|
1506
|
-
|
|
1506
|
+
I({
|
|
1507
1507
|
type: "status",
|
|
1508
1508
|
stage: "error",
|
|
1509
1509
|
message: e.message,
|
|
1510
|
-
endpoint:
|
|
1511
|
-
fn_index:
|
|
1510
|
+
endpoint: A,
|
|
1511
|
+
fn_index: x,
|
|
1512
1512
|
queue: !1,
|
|
1513
1513
|
time: /* @__PURE__ */ new Date()
|
|
1514
1514
|
});
|
|
1515
1515
|
});
|
|
1516
|
-
else if (
|
|
1517
|
-
|
|
1516
|
+
else if (w == "sse") {
|
|
1517
|
+
I({
|
|
1518
1518
|
type: "status",
|
|
1519
1519
|
stage: "pending",
|
|
1520
1520
|
queue: !0,
|
|
1521
|
-
endpoint:
|
|
1522
|
-
fn_index:
|
|
1521
|
+
endpoint: A,
|
|
1522
|
+
fn_index: x,
|
|
1523
1523
|
time: /* @__PURE__ */ new Date()
|
|
1524
1524
|
});
|
|
1525
1525
|
var i = new URLSearchParams({
|
|
1526
|
-
fn_index:
|
|
1526
|
+
fn_index: x.toString(),
|
|
1527
1527
|
session_hash: f
|
|
1528
1528
|
}).toString();
|
|
1529
|
-
let e = new URL(`${l.root}${
|
|
1530
|
-
if (this.jwt && e.searchParams.set("__sign", this.jwt),
|
|
1531
|
-
|
|
1532
|
-
let { type: t, status: i, data: a } =
|
|
1533
|
-
if (t === "update" && i && !
|
|
1529
|
+
let e = new URL(`${l.root}${y}/${u}?${F ? F + "&" : ""}${i}`);
|
|
1530
|
+
if (this.jwt && e.searchParams.set("__sign", this.jwt), O = this.stream(e), !O) return Promise.reject(/* @__PURE__ */ Error("Cannot connect to SSE endpoint: " + e.toString()));
|
|
1531
|
+
O.onmessage = async function(e) {
|
|
1532
|
+
let { type: t, status: i, data: a } = be(JSON.parse(e.data), P[x]);
|
|
1533
|
+
if (t === "update" && i && !N) I({
|
|
1534
1534
|
type: "status",
|
|
1535
|
-
endpoint:
|
|
1536
|
-
fn_index:
|
|
1535
|
+
endpoint: A,
|
|
1536
|
+
fn_index: x,
|
|
1537
1537
|
time: /* @__PURE__ */ new Date(),
|
|
1538
1538
|
...i
|
|
1539
|
-
}), i.stage === "error" && (
|
|
1539
|
+
}), i.stage === "error" && (O?.close(), V());
|
|
1540
1540
|
else if (t === "data") {
|
|
1541
|
-
let [e, t] = await
|
|
1542
|
-
...
|
|
1541
|
+
let [e, t] = await g(`${l.root}${y}/queue/data`, {
|
|
1542
|
+
...j,
|
|
1543
1543
|
session_hash: f,
|
|
1544
|
-
event_id:
|
|
1545
|
-
},
|
|
1546
|
-
t !== 200 && (
|
|
1544
|
+
event_id: M
|
|
1545
|
+
}, D);
|
|
1546
|
+
t !== 200 && (I({
|
|
1547
1547
|
type: "status",
|
|
1548
1548
|
stage: "error",
|
|
1549
|
-
message:
|
|
1549
|
+
message: _,
|
|
1550
1550
|
queue: !0,
|
|
1551
|
-
endpoint:
|
|
1552
|
-
fn_index:
|
|
1551
|
+
endpoint: A,
|
|
1552
|
+
fn_index: x,
|
|
1553
1553
|
time: /* @__PURE__ */ new Date()
|
|
1554
|
-
}),
|
|
1555
|
-
} else t === "complete" ?
|
|
1554
|
+
}), O?.close(), V());
|
|
1555
|
+
} else t === "complete" ? N = i : t === "log" ? I({
|
|
1556
1556
|
type: "log",
|
|
1557
1557
|
title: a.title,
|
|
1558
1558
|
log: a.log,
|
|
1559
1559
|
level: a.level,
|
|
1560
|
-
endpoint:
|
|
1560
|
+
endpoint: A,
|
|
1561
1561
|
duration: a.duration,
|
|
1562
1562
|
visible: a.visible,
|
|
1563
|
-
fn_index:
|
|
1564
|
-
}) : (t === "generating" || t === "streaming") &&
|
|
1563
|
+
fn_index: x
|
|
1564
|
+
}) : (t === "generating" || t === "streaming") && I({
|
|
1565
1565
|
type: "status",
|
|
1566
1566
|
time: /* @__PURE__ */ new Date(),
|
|
1567
1567
|
...i,
|
|
1568
1568
|
stage: i?.stage,
|
|
1569
1569
|
queue: !0,
|
|
1570
|
-
endpoint:
|
|
1571
|
-
fn_index:
|
|
1570
|
+
endpoint: A,
|
|
1571
|
+
fn_index: x
|
|
1572
1572
|
});
|
|
1573
|
-
a && (
|
|
1573
|
+
a && (I({
|
|
1574
1574
|
type: "data",
|
|
1575
1575
|
time: /* @__PURE__ */ new Date(),
|
|
1576
|
-
data: W(a.data,
|
|
1577
|
-
endpoint:
|
|
1578
|
-
fn_index:
|
|
1576
|
+
data: W(a.data, C, l.components, "output", v.with_null_state),
|
|
1577
|
+
endpoint: A,
|
|
1578
|
+
fn_index: x,
|
|
1579
1579
|
event_data: n,
|
|
1580
1580
|
trigger_id: r
|
|
1581
|
-
}),
|
|
1581
|
+
}), N && (I({
|
|
1582
1582
|
type: "status",
|
|
1583
1583
|
time: /* @__PURE__ */ new Date(),
|
|
1584
|
-
...
|
|
1584
|
+
...N,
|
|
1585
1585
|
stage: i?.stage,
|
|
1586
1586
|
queue: !0,
|
|
1587
|
-
endpoint:
|
|
1588
|
-
fn_index:
|
|
1589
|
-
}),
|
|
1587
|
+
endpoint: A,
|
|
1588
|
+
fn_index: x
|
|
1589
|
+
}), O?.close(), V()));
|
|
1590
1590
|
};
|
|
1591
|
-
} else if (
|
|
1592
|
-
|
|
1591
|
+
} else if (w == "sse_v1" || w == "sse_v2" || w == "sse_v2.1" || w == "sse_v3") {
|
|
1592
|
+
I({
|
|
1593
1593
|
type: "status",
|
|
1594
1594
|
stage: "pending",
|
|
1595
1595
|
queue: !0,
|
|
1596
|
-
endpoint:
|
|
1597
|
-
fn_index:
|
|
1596
|
+
endpoint: A,
|
|
1597
|
+
fn_index: x,
|
|
1598
1598
|
time: /* @__PURE__ */ new Date()
|
|
1599
1599
|
});
|
|
1600
1600
|
let e = "";
|
|
@@ -1602,146 +1602,146 @@ function Xt(e, t = {}, n, r, i, a) {
|
|
|
1602
1602
|
let t = Ye(e);
|
|
1603
1603
|
return (typeof window < "u" && typeof document < "u" && window.parent != window && t && window.supports_zerogpu_headers ? De("zerogpu-headers", t) : Promise.resolve(null)).then((e) => {
|
|
1604
1604
|
let t = {
|
|
1605
|
-
...
|
|
1605
|
+
...D,
|
|
1606
1606
|
...e || {}
|
|
1607
1607
|
};
|
|
1608
|
-
return
|
|
1609
|
-
...
|
|
1608
|
+
return g(`${l.root}${y}/${d}?${F}`, {
|
|
1609
|
+
...j,
|
|
1610
1610
|
session_hash: f
|
|
1611
1611
|
}, t);
|
|
1612
1612
|
}).then(async ([e, t]) => {
|
|
1613
|
-
if (e.event_id && (
|
|
1613
|
+
if (e.event_id && (k = e.event_id), t === 503) I({
|
|
1614
1614
|
type: "status",
|
|
1615
1615
|
stage: "error",
|
|
1616
|
-
message:
|
|
1616
|
+
message: oe,
|
|
1617
1617
|
queue: !0,
|
|
1618
|
-
endpoint:
|
|
1619
|
-
fn_index:
|
|
1618
|
+
endpoint: A,
|
|
1619
|
+
fn_index: x,
|
|
1620
1620
|
time: /* @__PURE__ */ new Date(),
|
|
1621
1621
|
visible: !0
|
|
1622
1622
|
}), V();
|
|
1623
|
-
else if (t === 422)
|
|
1623
|
+
else if (t === 422) I({
|
|
1624
1624
|
type: "status",
|
|
1625
1625
|
stage: "error",
|
|
1626
1626
|
message: e.detail,
|
|
1627
1627
|
queue: !0,
|
|
1628
|
-
endpoint:
|
|
1629
|
-
fn_index:
|
|
1628
|
+
endpoint: A,
|
|
1629
|
+
fn_index: x,
|
|
1630
1630
|
code: "validation_error",
|
|
1631
1631
|
time: /* @__PURE__ */ new Date(),
|
|
1632
1632
|
visible: !0
|
|
1633
1633
|
}), V();
|
|
1634
1634
|
else if (t !== 200) {
|
|
1635
|
-
let t = e?.error ===
|
|
1636
|
-
|
|
1635
|
+
let t = e?.error === _;
|
|
1636
|
+
I({
|
|
1637
1637
|
type: "status",
|
|
1638
1638
|
stage: "error",
|
|
1639
1639
|
broken: t,
|
|
1640
|
-
message: t ?
|
|
1640
|
+
message: t ? _ : e.detail || e.error,
|
|
1641
1641
|
queue: !0,
|
|
1642
|
-
endpoint:
|
|
1643
|
-
fn_index:
|
|
1642
|
+
endpoint: A,
|
|
1643
|
+
fn_index: x,
|
|
1644
1644
|
time: /* @__PURE__ */ new Date(),
|
|
1645
1645
|
visible: !0
|
|
1646
1646
|
}), V();
|
|
1647
1647
|
} else {
|
|
1648
|
-
|
|
1648
|
+
M = e.event_id, k = M;
|
|
1649
1649
|
let t = async function(e) {
|
|
1650
1650
|
try {
|
|
1651
|
-
let { type: t, status: n, data: r, original_msg: i } =
|
|
1651
|
+
let { type: t, status: n, data: r, original_msg: i } = be(e, P[x]);
|
|
1652
1652
|
if (t == "heartbeat") return;
|
|
1653
|
-
if (t === "update" && n && !
|
|
1653
|
+
if (t === "update" && n && !N) I({
|
|
1654
1654
|
type: "status",
|
|
1655
|
-
endpoint:
|
|
1656
|
-
fn_index:
|
|
1655
|
+
endpoint: A,
|
|
1656
|
+
fn_index: x,
|
|
1657
1657
|
time: /* @__PURE__ */ new Date(),
|
|
1658
1658
|
original_msg: i,
|
|
1659
1659
|
...n
|
|
1660
1660
|
});
|
|
1661
|
-
else if (t === "complete")
|
|
1661
|
+
else if (t === "complete") N = n;
|
|
1662
1662
|
else if (t == "unexpected_error" || t == "broken_connection") {
|
|
1663
1663
|
console.error("Unexpected error", n?.message);
|
|
1664
1664
|
let e = t === "broken_connection";
|
|
1665
|
-
|
|
1665
|
+
I({
|
|
1666
1666
|
type: "status",
|
|
1667
1667
|
stage: "error",
|
|
1668
1668
|
message: n?.message || "An Unexpected Error Occurred!",
|
|
1669
1669
|
queue: !0,
|
|
1670
|
-
endpoint:
|
|
1670
|
+
endpoint: A,
|
|
1671
1671
|
broken: e,
|
|
1672
1672
|
session_not_found: n?.session_not_found,
|
|
1673
|
-
fn_index:
|
|
1673
|
+
fn_index: x,
|
|
1674
1674
|
time: /* @__PURE__ */ new Date()
|
|
1675
1675
|
});
|
|
1676
1676
|
} else if (t === "log") {
|
|
1677
|
-
|
|
1677
|
+
I({
|
|
1678
1678
|
type: "log",
|
|
1679
1679
|
title: r.title,
|
|
1680
1680
|
log: r.log,
|
|
1681
1681
|
level: r.level,
|
|
1682
|
-
endpoint:
|
|
1682
|
+
endpoint: A,
|
|
1683
1683
|
duration: r.duration,
|
|
1684
1684
|
visible: r.visible,
|
|
1685
|
-
fn_index:
|
|
1685
|
+
fn_index: x
|
|
1686
1686
|
});
|
|
1687
1687
|
return;
|
|
1688
|
-
} else (t === "generating" || t === "streaming") && (
|
|
1688
|
+
} else (t === "generating" || t === "streaming") && (I({
|
|
1689
1689
|
type: "status",
|
|
1690
1690
|
time: /* @__PURE__ */ new Date(),
|
|
1691
1691
|
...n,
|
|
1692
1692
|
stage: n?.stage,
|
|
1693
1693
|
queue: !0,
|
|
1694
|
-
endpoint:
|
|
1695
|
-
fn_index:
|
|
1696
|
-
}), r &&
|
|
1694
|
+
endpoint: A,
|
|
1695
|
+
fn_index: x
|
|
1696
|
+
}), r && C.connection !== "stream" && [
|
|
1697
1697
|
"sse_v2",
|
|
1698
1698
|
"sse_v2.1",
|
|
1699
1699
|
"sse_v3"
|
|
1700
|
-
].includes(
|
|
1701
|
-
r && (
|
|
1700
|
+
].includes(w) && at(ne, M, r));
|
|
1701
|
+
r && (I({
|
|
1702
1702
|
type: "data",
|
|
1703
1703
|
time: /* @__PURE__ */ new Date(),
|
|
1704
|
-
data: W(r.data,
|
|
1705
|
-
endpoint:
|
|
1706
|
-
fn_index:
|
|
1707
|
-
}), r.render_config && await
|
|
1704
|
+
data: W(r.data, C, l.components, "output", v.with_null_state),
|
|
1705
|
+
endpoint: A,
|
|
1706
|
+
fn_index: x
|
|
1707
|
+
}), r.render_config && await L(r.render_config), N && (I({
|
|
1708
1708
|
type: "status",
|
|
1709
1709
|
time: /* @__PURE__ */ new Date(),
|
|
1710
|
-
...
|
|
1710
|
+
...N,
|
|
1711
1711
|
stage: n?.stage,
|
|
1712
1712
|
queue: !0,
|
|
1713
|
-
endpoint:
|
|
1714
|
-
fn_index:
|
|
1715
|
-
}), V())), (n?.stage === "complete" || n?.stage === "error") && (
|
|
1713
|
+
endpoint: A,
|
|
1714
|
+
fn_index: x
|
|
1715
|
+
}), V())), (n?.stage === "complete" || n?.stage === "error") && (h[M] && delete h[M], M in ne && delete ne[M], V());
|
|
1716
1716
|
} catch (e) {
|
|
1717
|
-
console.error("Unexpected client exception", e),
|
|
1717
|
+
console.error("Unexpected client exception", e), I({
|
|
1718
1718
|
type: "status",
|
|
1719
1719
|
stage: "error",
|
|
1720
1720
|
message: "An Unexpected Error Occurred!",
|
|
1721
1721
|
queue: !0,
|
|
1722
|
-
endpoint:
|
|
1723
|
-
fn_index:
|
|
1722
|
+
endpoint: A,
|
|
1723
|
+
fn_index: x,
|
|
1724
1724
|
time: /* @__PURE__ */ new Date()
|
|
1725
1725
|
}), [
|
|
1726
1726
|
"sse_v2",
|
|
1727
1727
|
"sse_v2.1",
|
|
1728
1728
|
"sse_v3"
|
|
1729
|
-
].includes(
|
|
1729
|
+
].includes(w) && (it(ee, b.abort_controller), ee.open = !1, V());
|
|
1730
1730
|
}
|
|
1731
1731
|
};
|
|
1732
|
-
|
|
1732
|
+
M in te && (te[M].forEach((e) => t(e)), delete te[M]), h[M] = t, re.add(M), ee.open || await this.open_stream();
|
|
1733
1733
|
}
|
|
1734
1734
|
});
|
|
1735
1735
|
}
|
|
1736
1736
|
});
|
|
1737
|
-
|
|
1738
|
-
|
|
1737
|
+
R.catch((e) => {
|
|
1738
|
+
I({
|
|
1739
1739
|
type: "status",
|
|
1740
1740
|
stage: "error",
|
|
1741
1741
|
message: e instanceof Error ? e.message : String(e),
|
|
1742
|
-
queue: !Ee(
|
|
1743
|
-
endpoint:
|
|
1744
|
-
fn_index:
|
|
1742
|
+
queue: !Ee(x, l),
|
|
1743
|
+
endpoint: A,
|
|
1744
|
+
fn_index: x,
|
|
1745
1745
|
time: /* @__PURE__ */ new Date()
|
|
1746
1746
|
}), V();
|
|
1747
1747
|
});
|
|
@@ -1756,7 +1756,7 @@ function Xt(e, t = {}, n, r, i, a) {
|
|
|
1756
1756
|
B.length > 0 ? B.shift()(e) : z.push(e);
|
|
1757
1757
|
}
|
|
1758
1758
|
function we(e) {
|
|
1759
|
-
H(
|
|
1759
|
+
H(Qt(e)), V();
|
|
1760
1760
|
}
|
|
1761
1761
|
function Te(e) {
|
|
1762
1762
|
H({
|
|
@@ -1770,36 +1770,40 @@ function Xt(e, t = {}, n, r, i, a) {
|
|
|
1770
1770
|
done: !0
|
|
1771
1771
|
}) : new Promise((e) => B.push(e));
|
|
1772
1772
|
}
|
|
1773
|
-
let Oe = {
|
|
1774
|
-
|
|
1773
|
+
let Oe = (e, t) => {
|
|
1774
|
+
R.then(() => {
|
|
1775
|
+
k && this.post_data(`${l.root}${y}/stream/${k}${e}`, t);
|
|
1776
|
+
}, () => {});
|
|
1777
|
+
}, ke = {
|
|
1778
|
+
[Symbol.asyncIterator]: () => ke,
|
|
1775
1779
|
next: U,
|
|
1776
1780
|
throw: async (e) => (we(e), U()),
|
|
1777
1781
|
return: async () => (V(), {
|
|
1778
1782
|
value: void 0,
|
|
1779
1783
|
done: !0
|
|
1780
1784
|
}),
|
|
1781
|
-
cancel:
|
|
1785
|
+
cancel: ye,
|
|
1782
1786
|
send_chunk: (e) => {
|
|
1783
|
-
|
|
1787
|
+
Oe("", {
|
|
1784
1788
|
...e,
|
|
1785
1789
|
session_hash: this.session_hash
|
|
1786
1790
|
});
|
|
1787
1791
|
},
|
|
1788
1792
|
close_stream: () => {
|
|
1789
|
-
|
|
1793
|
+
V(), Oe("/close", {});
|
|
1790
1794
|
},
|
|
1791
|
-
event_id: () =>
|
|
1792
|
-
wait_for_id: async () => (await
|
|
1795
|
+
event_id: () => k,
|
|
1796
|
+
wait_for_id: async () => (await R, M)
|
|
1793
1797
|
};
|
|
1794
|
-
return
|
|
1798
|
+
return ke;
|
|
1795
1799
|
} catch (e) {
|
|
1796
1800
|
throw console.error("Submit function encountered an error:", e), e;
|
|
1797
1801
|
}
|
|
1798
1802
|
}
|
|
1799
|
-
function
|
|
1803
|
+
function Qt(e) {
|
|
1800
1804
|
return { then: (t, n) => n(e) };
|
|
1801
1805
|
}
|
|
1802
|
-
function
|
|
1806
|
+
function $t(e, t, n, r) {
|
|
1803
1807
|
let i, a, o;
|
|
1804
1808
|
if (typeof t == "number") i = t, a = e.unnamed_endpoints[i], o = r.dependencies.find((e) => e.id == t);
|
|
1805
1809
|
else {
|
|
@@ -1818,7 +1822,7 @@ function Qt(e, t, n, r) {
|
|
|
1818
1822
|
}
|
|
1819
1823
|
//#endregion
|
|
1820
1824
|
//#region src/client.ts
|
|
1821
|
-
var
|
|
1825
|
+
var Q = class {
|
|
1822
1826
|
app_reference;
|
|
1823
1827
|
options;
|
|
1824
1828
|
deep_link = null;
|
|
@@ -1842,13 +1846,13 @@ var $ = class {
|
|
|
1842
1846
|
stream_instance = null;
|
|
1843
1847
|
current_payload;
|
|
1844
1848
|
get_url_config(e = null) {
|
|
1845
|
-
if (!this.config) throw Error(
|
|
1849
|
+
if (!this.config) throw Error(v);
|
|
1846
1850
|
e === null && (e = window.location.href);
|
|
1847
1851
|
let t = (e) => e.replace(/^\/+|\/+$/g, ""), n = t(new URL(this.config.root).pathname), r = t(new URL(e).pathname), i;
|
|
1848
1852
|
return i = r.startsWith(n) ? t(r.substring(n.length)) : "", this.get_page_config(i);
|
|
1849
1853
|
}
|
|
1850
1854
|
get_page_config(e) {
|
|
1851
|
-
if (!this.config) throw Error(
|
|
1855
|
+
if (!this.config) throw Error(v);
|
|
1852
1856
|
let t = this.config;
|
|
1853
1857
|
return e in t.page || (e = ""), {
|
|
1854
1858
|
...t,
|
|
@@ -1888,7 +1892,7 @@ var $ = class {
|
|
|
1888
1892
|
resolve_config;
|
|
1889
1893
|
resolve_cookies;
|
|
1890
1894
|
constructor(e, t = { events: ["data"] }) {
|
|
1891
|
-
this.app_reference = e, this.deep_link = t.query_params?.deep_link || null, this.page = t.query_params?.page ?? null, t.events ||= ["data"],
|
|
1895
|
+
this.app_reference = e, this.deep_link = t.query_params?.deep_link || null, this.page = t.query_params?.page ?? null, t.events ||= ["data"], T(t), this.options = t, this.current_payload = {}, t.cookies && (this.cookies = t.cookies), this.view_api = Se.bind(this), this.upload_files = L.bind(this), this.handle_blob = Me.bind(this), this.post_data = Ie.bind(this), this.submit = Zt.bind(this), this.predict = Le.bind(this), this.open_stream = rt.bind(this), this.resolve_config = D.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);
|
|
1892
1896
|
}
|
|
1893
1897
|
async init() {
|
|
1894
1898
|
Xe(), this.options.auth && await this.resolve_cookies(), await this._resolve_config().then((e) => e?.config && this._resolve_heartbeat(e.config));
|
|
@@ -1897,11 +1901,11 @@ var $ = class {
|
|
|
1897
1901
|
} catch (e) {
|
|
1898
1902
|
console.error(e.message);
|
|
1899
1903
|
}
|
|
1900
|
-
this.api_map =
|
|
1904
|
+
this.api_map = E(this.config?.dependencies || []);
|
|
1901
1905
|
}
|
|
1902
1906
|
async _resolve_heartbeat(e) {
|
|
1903
|
-
if (this.config = e, this.api_prefix = e.api_prefix || "", e.space_id && this.options.token && (this.jwt = await
|
|
1904
|
-
let e = new URL(`${this.config.root}${this.api_prefix}/${
|
|
1907
|
+
if (this.config = e, this.api_prefix = e.api_prefix || "", e.space_id && this.options.token && (this.jwt = await he(e.space_id, this.options.token, this.cookies)), je(this.config, this.jwt), this.config && this.config.connect_heartbeat) {
|
|
1908
|
+
let e = new URL(`${this.config.root}${this.api_prefix}/${h}/${this.session_hash}`);
|
|
1905
1909
|
this.jwt && e.searchParams.set("__sign", this.jwt), this.heartbeat_event ||= this.stream(e);
|
|
1906
1910
|
}
|
|
1907
1911
|
}
|
|
@@ -1910,7 +1914,7 @@ var $ = class {
|
|
|
1910
1914
|
return t.session_hash && (n.session_hash = t.session_hash), await n.init(), n;
|
|
1911
1915
|
}
|
|
1912
1916
|
async reconnect() {
|
|
1913
|
-
let e = new URL(`${this.config.root}${this.api_prefix}/${
|
|
1917
|
+
let e = new URL(`${this.config.root}${this.api_prefix}/${g}`), t;
|
|
1914
1918
|
try {
|
|
1915
1919
|
let n = await this.fetch(e);
|
|
1916
1920
|
if (!n.ok) throw Error();
|
|
@@ -1924,14 +1928,14 @@ var $ = class {
|
|
|
1924
1928
|
this.closed = !0, it(this.stream_status, this.abort_controller);
|
|
1925
1929
|
}
|
|
1926
1930
|
async refresh() {
|
|
1927
|
-
if (!this.config) throw Error(
|
|
1931
|
+
if (!this.config) throw Error(v);
|
|
1928
1932
|
let e = await this.resolve_config(this.config.root, !1);
|
|
1929
|
-
if (!e) throw Error(
|
|
1930
|
-
this.config = e, this.api_prefix = e.api_prefix || "", this.api_map =
|
|
1933
|
+
if (!e) throw Error(v);
|
|
1934
|
+
this.config = e, this.api_prefix = e.api_prefix || "", this.api_map = E(e.dependencies || []), je(this.config, this.jwt);
|
|
1931
1935
|
try {
|
|
1932
1936
|
this.api_info = await this.view_api();
|
|
1933
1937
|
} catch (e) {
|
|
1934
|
-
console.error(
|
|
1938
|
+
console.error(se + e.message);
|
|
1935
1939
|
}
|
|
1936
1940
|
return this.get_url_config();
|
|
1937
1941
|
}
|
|
@@ -1942,15 +1946,15 @@ var $ = class {
|
|
|
1942
1946
|
return We(e, t);
|
|
1943
1947
|
}
|
|
1944
1948
|
async _resolve_config() {
|
|
1945
|
-
let { http_protocol: e, host: t, space_id: n } = await
|
|
1949
|
+
let { http_protocol: e, host: t, space_id: n } = await P(this.app_reference, this.options.token), { status_callback: r } = this.options;
|
|
1946
1950
|
n && r && await Re(n, r);
|
|
1947
1951
|
let i;
|
|
1948
1952
|
try {
|
|
1949
1953
|
let n = `${e}//${t}`;
|
|
1950
|
-
if (i = await this.resolve_config(n), !i) throw Error(
|
|
1954
|
+
if (i = await this.resolve_config(n), !i) throw Error(v);
|
|
1951
1955
|
return this.config_success(i);
|
|
1952
1956
|
} catch (e) {
|
|
1953
|
-
if (n && r) G(n,
|
|
1957
|
+
if (n && r) G(n, M.test(n) ? "space_name" : "subdomain", this.handle_space_success);
|
|
1954
1958
|
else throw r && r({
|
|
1955
1959
|
status: "error",
|
|
1956
1960
|
message: "Could not load this space.",
|
|
@@ -1960,22 +1964,22 @@ var $ = class {
|
|
|
1960
1964
|
}
|
|
1961
1965
|
}
|
|
1962
1966
|
async config_success(e) {
|
|
1963
|
-
if (this.config = e, this.api_prefix = e.api_prefix || "", e.run_history === !1 &&
|
|
1967
|
+
if (this.config = e, this.api_prefix = e.api_prefix || "", e.run_history === !1 && Ht({
|
|
1964
1968
|
app_id: e.app_id,
|
|
1965
1969
|
username: e.username
|
|
1966
1970
|
}), this.config.auth_required) return this.prepare_return_obj();
|
|
1967
1971
|
try {
|
|
1968
1972
|
this.api_info = await this.view_api();
|
|
1969
1973
|
} catch (e) {
|
|
1970
|
-
console.error(
|
|
1974
|
+
console.error(se + e.message);
|
|
1971
1975
|
}
|
|
1972
1976
|
return this.prepare_return_obj();
|
|
1973
1977
|
}
|
|
1974
1978
|
async handle_space_success(e) {
|
|
1975
|
-
if (!this) throw Error(
|
|
1979
|
+
if (!this) throw Error(v);
|
|
1976
1980
|
let { status_callback: t } = this.options;
|
|
1977
1981
|
if (t && t(e), e.status === "running") try {
|
|
1978
|
-
if (this.config = await this._resolve_config(), this.api_prefix = this?.config?.api_prefix || "", !this.config) throw Error(
|
|
1982
|
+
if (this.config = await this._resolve_config(), this.api_prefix = this?.config?.api_prefix || "", !this.config) throw Error(v);
|
|
1979
1983
|
return await this.config_success(this.config);
|
|
1980
1984
|
} catch (e) {
|
|
1981
1985
|
throw t && t({
|
|
@@ -1987,7 +1991,7 @@ var $ = class {
|
|
|
1987
1991
|
}
|
|
1988
1992
|
}
|
|
1989
1993
|
async component_server(e, t, n) {
|
|
1990
|
-
if (!this.config) throw Error(
|
|
1994
|
+
if (!this.config) throw Error(v);
|
|
1991
1995
|
let r = {}, { token: i } = this.options, { session_hash: a } = this;
|
|
1992
1996
|
i && (r.Authorization = `Bearer ${this.options.token}`);
|
|
1993
1997
|
let o, s = this.config.components.find((t) => t.id === e);
|
|
@@ -2006,7 +2010,7 @@ var $ = class {
|
|
|
2006
2010
|
}), r["Content-Type"] = "application/json";
|
|
2007
2011
|
i && (r.Authorization = `Bearer ${i}`);
|
|
2008
2012
|
try {
|
|
2009
|
-
let e = await this.fetch(`${o}${this.api_prefix}/${
|
|
2013
|
+
let e = await this.fetch(`${o}${this.api_prefix}/${re}/`, {
|
|
2010
2014
|
method: "POST",
|
|
2011
2015
|
body: c,
|
|
2012
2016
|
headers: r,
|
|
@@ -2020,7 +2024,7 @@ var $ = class {
|
|
|
2020
2024
|
}
|
|
2021
2025
|
}
|
|
2022
2026
|
set_cookies(e) {
|
|
2023
|
-
this.cookies =
|
|
2027
|
+
this.cookies = j(e).join("; ");
|
|
2024
2028
|
}
|
|
2025
2029
|
prepare_return_obj() {
|
|
2026
2030
|
return {
|
|
@@ -2032,19 +2036,19 @@ var $ = class {
|
|
|
2032
2036
|
};
|
|
2033
2037
|
}
|
|
2034
2038
|
};
|
|
2035
|
-
async function
|
|
2036
|
-
return await
|
|
2039
|
+
async function en(e, t = { events: ["data"] }) {
|
|
2040
|
+
return await Q.connect(e, t);
|
|
2037
2041
|
}
|
|
2038
|
-
async function
|
|
2039
|
-
return await
|
|
2042
|
+
async function tn(e, t) {
|
|
2043
|
+
return await Q.duplicate(e, t);
|
|
2040
2044
|
}
|
|
2041
2045
|
//#endregion
|
|
2042
2046
|
//#region src/utils/bucket_sync.ts
|
|
2043
|
-
var
|
|
2044
|
-
function
|
|
2045
|
-
return
|
|
2047
|
+
var nn = /^[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-][a-zA-Z0-9_./-]*$/;
|
|
2048
|
+
function rn(e) {
|
|
2049
|
+
return nn.test(e) ? !e.split("/").some((e) => e === "" || e === "." || e === "..") : !1;
|
|
2046
2050
|
}
|
|
2047
|
-
function
|
|
2051
|
+
function $(e, t, n) {
|
|
2048
2052
|
let r = n ? `?${new URLSearchParams(n)}` : "", i = e.replace(/\/+$/, "");
|
|
2049
2053
|
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}`;
|
|
2050
2054
|
}
|
|
@@ -2082,7 +2086,7 @@ async function on(e, t, n, r) {
|
|
|
2082
2086
|
}
|
|
2083
2087
|
}
|
|
2084
2088
|
async function sn(e, t) {
|
|
2085
|
-
return
|
|
2089
|
+
return rn(t) ? on($(e, "connect"), {
|
|
2086
2090
|
method: "POST",
|
|
2087
2091
|
headers: { "Content-Type": "application/json" },
|
|
2088
2092
|
body: JSON.stringify({ bucket_id: t })
|
|
@@ -2094,13 +2098,13 @@ async function sn(e, t) {
|
|
|
2094
2098
|
};
|
|
2095
2099
|
}
|
|
2096
2100
|
async function cn(e) {
|
|
2097
|
-
return on(
|
|
2101
|
+
return on($(e, "buckets"), {}, [], (e) => Array.isArray(e?.buckets) ? e.buckets : []);
|
|
2098
2102
|
}
|
|
2099
2103
|
async function ln(e, t) {
|
|
2100
|
-
return on(
|
|
2104
|
+
return on($(e, "records", { bucket: t }), {}, [], (e) => Array.isArray(e?.records) ? e.records : []);
|
|
2101
2105
|
}
|
|
2102
2106
|
function un(e, t, n, r, i) {
|
|
2103
|
-
return
|
|
2107
|
+
return $(e, `records/${encodeURIComponent(n)}/${encodeURIComponent(r)}/assets/${encodeURIComponent(i)}`, { bucket: t });
|
|
2104
2108
|
}
|
|
2105
2109
|
//#endregion
|
|
2106
|
-
export {
|
|
2110
|
+
export { Q as Client, V as FileData, C as MISSING_CREDENTIALS_MSG, Kt as apply_run_history_replay, un as asset_url, Ht as clear_run_history, en as client, sn 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, ln as list_bucket_records, cn as list_user_buckets, Xt as on_run_history_change, Le 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, o as t, z as upload, L as upload_files };
|