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