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