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