@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/browser.js CHANGED
@@ -8,10 +8,10 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
8
8
  }, c = (n, r, a) => (a = n == null ? {} : e(i(n)), s(r || !n || !n.__esModule ? t(a, "default", {
9
9
  value: n,
10
10
  enumerable: !0
11
- }) : a, n)), l = "host", u = "queue/data", d = "queue/join", f = "upload", p = "login", m = "config", ee = "info", 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. ", x = "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", D = "Root URL not found in client config", de = "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 fe(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 fe(e, t, n) {
21
21
  return !1;
22
22
  }
23
23
  }
24
- function O(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 k(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,9 +50,11 @@ 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);
@@ -58,37 +62,37 @@ async function j(e, t = !0) {
58
62
  }
59
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(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);
81
+ } else if (e?.status === 401) throw Error(S);
78
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(T) : Error(S);
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(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
- ...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(C);
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";
@@ -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, ee);
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
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;
@@ -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,12 +620,36 @@ 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 src/utils/handle_blob.ts
618
- async function Oe(e, t, n) {
649
+ async function Me(e, t, n) {
619
650
  let r = this;
620
- await ke(r, t);
621
- let i = await we(t, void 0, [], !0, n);
651
+ await Ne(r, t);
652
+ let i = await U(t, void 0, [], !0, n);
622
653
  return (await Promise.all(i.map(async ({ path: t, blob: n, type: i }) => {
623
654
  if (!n) return {
624
655
  path: t,
@@ -632,40 +663,40 @@ async function Oe(e, t, n) {
632
663
  name: typeof File < "u" && n instanceof File ? n?.name : void 0
633
664
  };
634
665
  }))).forEach(({ path: e, file_url: n, type: r, name: i }) => {
635
- r === "Gallery" ? Ce(t, n, e) : n && Ce(t, new U({
666
+ r === "Gallery" ? Te(t, n, e) : n && Te(t, new V({
636
667
  path: n,
637
668
  orig_name: i
638
669
  }), e);
639
670
  }), t;
640
671
  }
641
- async function ke(e, t) {
642
- if (!(e.config?.root || e.config?.root_url)) throw Error(D);
643
- await Ae(e, t);
672
+ async function Ne(e, t) {
673
+ if (!(e.config?.root || e.config?.root_url)) throw Error(fe);
674
+ await Pe(e, t);
644
675
  }
645
- async function Ae(e, t, n = []) {
646
- for (let r in t) t[r] instanceof W ? await je(e, t, r) : typeof t[r] == "object" && t[r] !== null && await Ae(e, t[r], [...n, r]);
676
+ async function Pe(e, t, n = []) {
677
+ for (let r in t) t[r] instanceof H ? await Fe(e, t, r) : typeof t[r] == "object" && t[r] !== null && await Pe(e, t[r], [...n, r]);
647
678
  }
648
- async function je(e, t, n) {
679
+ async function Fe(e, t, n) {
649
680
  let r = t[n], i = e.config?.root || e.config?.root_url;
650
- if (!i) throw Error(D);
681
+ if (!i) throw Error(fe);
651
682
  try {
652
683
  let a, o;
653
684
  if (typeof process < "u" && process.versions && process.versions.node) {
654
685
  let e = await import("./__vite-browser-external-Cgmn0awE.js").then((e) => /* @__PURE__ */ c(e.default, 1));
655
686
  o = (await import("./__vite-browser-external-Cgmn0awE.js").then((e) => /* @__PURE__ */ c(e.default, 1))).resolve(process.cwd(), r.meta.path), a = await e.readFile(o);
656
- } else throw Error(ue);
687
+ } else throw Error(de);
657
688
  let s = new Blob([a], { type: "application/octet-stream" }), l = await e.upload_files(i, [s]), u = l.files && l.files[0];
658
- u && (t[n] = new U({
689
+ u && (t[n] = new V({
659
690
  path: u,
660
691
  orig_name: r.meta.name || ""
661
692
  }));
662
693
  } catch (e) {
663
- console.error(de, e);
694
+ console.error(pe, e);
664
695
  }
665
696
  }
666
697
  //#endregion
667
698
  //#region src/utils/post_data.ts
668
- async function Me(e, t, n) {
699
+ async function Ie(e, t, n) {
669
700
  let r = { "Content-Type": "application/json" };
670
701
  this.options.token && (r.Authorization = `Bearer ${this.options.token}`);
671
702
  try {
@@ -691,7 +722,7 @@ async function Me(e, t, n) {
691
722
  }
692
723
  //#endregion
693
724
  //#region src/utils/predict.ts
694
- async function Ne(e, t = {}) {
725
+ async function Le(e, t = {}) {
695
726
  let n = !1, r = !1;
696
727
  if (!this.config) throw Error("Could not resolve app config");
697
728
  if (typeof e == "number") this.config.dependencies.find((t) => t.id == e);
@@ -714,7 +745,7 @@ async function Ne(e, t = {}) {
714
745
  }
715
746
  //#endregion
716
747
  //#region src/helpers/spaces.ts
717
- async function K(e, t, n) {
748
+ async function G(e, t, n) {
718
749
  let r = t === "subdomain" ? `https://huggingface.co/api/spaces/by-subdomain/${e}` : `https://huggingface.co/api/spaces/${e}`, i, a;
719
750
  try {
720
751
  if (i = await fetch(r), a = i.status, a !== 200) throw Error();
@@ -739,7 +770,7 @@ async function K(e, t, n) {
739
770
  message: "Space is asleep. Waking it up...",
740
771
  detail: o
741
772
  }), setTimeout(() => {
742
- K(e, t, n);
773
+ G(e, t, n);
743
774
  }, 1e3);
744
775
  break;
745
776
  case "PAUSED":
@@ -748,7 +779,7 @@ async function K(e, t, n) {
748
779
  load_status: "error",
749
780
  message: "This space has been paused by the author. If you would like to try this demo, consider duplicating the space.",
750
781
  detail: o,
751
- discussions_enabled: await Ie(s)
782
+ discussions_enabled: await Be(s)
752
783
  });
753
784
  break;
754
785
  case "RUNNING":
@@ -767,7 +798,7 @@ async function K(e, t, n) {
767
798
  message: "Space is building...",
768
799
  detail: o
769
800
  }), setTimeout(() => {
770
- K(e, t, n);
801
+ G(e, t, n);
771
802
  }, 1e3);
772
803
  break;
773
804
  case "APP_STARTING":
@@ -777,7 +808,7 @@ async function K(e, t, n) {
777
808
  message: "Space is starting...",
778
809
  detail: o
779
810
  }), setTimeout(() => {
780
- K(e, t, n);
811
+ G(e, t, n);
781
812
  }, 1e3);
782
813
  break;
783
814
  default:
@@ -786,30 +817,30 @@ async function K(e, t, n) {
786
817
  load_status: "error",
787
818
  message: "This space is experiencing an issue.",
788
819
  detail: o,
789
- discussions_enabled: await Ie(s)
820
+ discussions_enabled: await Be(s)
790
821
  });
791
822
  break;
792
823
  }
793
824
  }
794
- var Pe = async (e, t) => {
825
+ var Re = async (e, t) => {
795
826
  let n = 0;
796
827
  return new Promise((r) => {
797
- K(e, L.test(e) ? "space_name" : "subdomain", (i) => {
828
+ G(e, P.test(e) ? "space_name" : "subdomain", (i) => {
798
829
  t(i), i.status === "running" || i.status === "error" || i.status === "paused" || i.status === "space_error" ? r() : (i.status === "sleeping" || i.status === "building") && (n < 12 ? (n++, setTimeout(() => {
799
- Pe(e, t).then(r);
830
+ Re(e, t).then(r);
800
831
  }, 5e3)) : r());
801
832
  });
802
833
  });
803
- }, Fe = /^(?=[^]*\b[dD]iscussions{0,1}\b)(?=[^]*\b[dD]isabled\b)[^]*$/;
804
- async function Ie(e) {
834
+ }, ze = /^(?=[^]*\b[dD]iscussions{0,1}\b)(?=[^]*\b[dD]isabled\b)[^]*$/;
835
+ async function Be(e) {
805
836
  try {
806
837
  let t = await fetch(`https://huggingface.co/api/spaces/${e}/discussions`, { method: "HEAD" }), n = t.headers.get("x-error-message");
807
- return !(!t.ok || n && Fe.test(n));
838
+ return !(!t.ok || n && ze.test(n));
808
839
  } catch {
809
840
  return !1;
810
841
  }
811
842
  }
812
- async function Le(e, t) {
843
+ async function Ve(e, t) {
813
844
  let n = {};
814
845
  t && (n.Authorization = `Bearer ${t}`);
815
846
  try {
@@ -821,7 +852,7 @@ async function Le(e, t) {
821
852
  throw Error(e.message);
822
853
  }
823
854
  }
824
- async function Re(e, t, n) {
855
+ async function He(e, t, n) {
825
856
  let r = {};
826
857
  n && (r.Authorization = `Bearer ${n}`);
827
858
  let i = { seconds: t };
@@ -840,7 +871,7 @@ async function Re(e, t, n) {
840
871
  throw Error(e.message);
841
872
  }
842
873
  }
843
- var ze = [
874
+ var Ue = [
844
875
  "cpu-basic",
845
876
  "cpu-upgrade",
846
877
  "cpu-xl",
@@ -857,14 +888,14 @@ var ze = [
857
888
  ];
858
889
  //#endregion
859
890
  //#region src/utils/duplicate.ts
860
- async function Be(e, t) {
861
- O(t);
891
+ async function We(e, t) {
892
+ E(t);
862
893
  let { token: n, private: r, hardware: i, timeout: a, auth: o } = t;
863
- if (i && !ze.includes(i)) throw Error(`Invalid hardware type provided. Valid types are: ${ze.map((e) => `"${e}"`).join(",")}.`);
864
- let { http_protocol: s, host: c } = await R(e, n), l = null;
894
+ if (i && !Ue.includes(i)) throw Error(`Invalid hardware type provided. Valid types are: ${Ue.map((e) => `"${e}"`).join(",")}.`);
895
+ let { http_protocol: s, host: c } = await I(e, n), l = null;
865
896
  if (o) {
866
- let e = await P(s, c, o, fetch, void 0, t.credentials);
867
- e && (l = I(e));
897
+ let e = await j(s, c, o, fetch, void 0, t.credentials);
898
+ e && (l = N(e));
868
899
  }
869
900
  let u = {
870
901
  Authorization: `Bearer ${n}`,
@@ -874,9 +905,9 @@ async function Be(e, t) {
874
905
  r && (p.private = !0);
875
906
  let m;
876
907
  try {
877
- i || (m = await Le(e, n));
908
+ i || (m = await Ve(e, n));
878
909
  } catch (e) {
879
- throw Error(S + e.message);
910
+ throw Error(x + e.message);
880
911
  }
881
912
  p.hardware = i || m || "cpu-basic";
882
913
  try {
@@ -892,35 +923,35 @@ async function Be(e, t) {
892
923
  }
893
924
  else if (r.status !== 200) throw Error(r.statusText);
894
925
  let i = await r.json();
895
- return await Re(`${d}/${f}`, a || 300, n), await $.connect(Ve(i.url), t);
926
+ return await He(`${d}/${f}`, a || 300, n), await $.connect(Ge(i.url), t);
896
927
  } catch (e) {
897
928
  throw Error(e);
898
929
  }
899
930
  }
900
- function Ve(e) {
931
+ function Ge(e) {
901
932
  let t = e.match(/https:\/\/huggingface.co\/spaces\/([^/]+\/[^/]+)/);
902
933
  if (t) return t[1];
903
934
  }
904
935
  //#endregion
905
936
  //#region src/helpers/zerogpu.ts
906
- var He = "supports-zerogpu-headers", Ue = !1;
907
- function We() {
937
+ var Ke = "supports-zerogpu-headers", qe = !1;
938
+ function Je() {
908
939
  return typeof window < "u" && typeof document < "u" && typeof window.addEventListener == "function";
909
940
  }
910
- function Ge(e) {
941
+ function Ye(e) {
911
942
  return e.includes(".dev.") ? `https://moon-${e.split(".")[1]}.dev.spaces.huggingface.tech` : e.endsWith(".hf.space") ? "https://huggingface.co" : null;
912
943
  }
913
- function Ke() {
914
- if (!We() || Ue) return;
944
+ function Xe() {
945
+ if (!Je() || qe) return;
915
946
  window.addEventListener("message", (e) => {
916
- e.data === He && (window.supports_zerogpu_headers = !0);
917
- }), Ue = !0;
918
- let e = Ge(window.location.hostname);
919
- e && window.parent !== window && window.parent.postMessage(He, e);
947
+ e.data === Ke && (window.supports_zerogpu_headers = !0);
948
+ }), qe = !0;
949
+ let e = Ye(window.location.hostname);
950
+ e && window.parent !== window && window.parent.postMessage(Ke, e);
920
951
  }
921
952
  //#endregion
922
953
  //#region ../../node_modules/.pnpm/fetch-event-stream@0.1.6/node_modules/fetch-event-stream/esm/deps/jsr.io/@std/streams/0.221.0/text_line_stream.js
923
- var qe = class extends TransformStream {
954
+ var Ze = class extends TransformStream {
924
955
  #e = "";
925
956
  constructor(e = { allowCR: !1 }) {
926
957
  super({
@@ -947,22 +978,22 @@ var qe = class extends TransformStream {
947
978
  };
948
979
  //#endregion
949
980
  //#region ../../node_modules/.pnpm/fetch-event-stream@0.1.6/node_modules/fetch-event-stream/esm/utils.js
950
- function Je(e) {
951
- let t = new TextDecoderStream(), n = new qe({ allowCR: !0 });
981
+ function Qe(e) {
982
+ let t = new TextDecoderStream(), n = new Ze({ allowCR: !0 });
952
983
  return e.pipeThrough(t).pipeThrough(n);
953
984
  }
954
- function Ye(e) {
985
+ function $e(e) {
955
986
  let t = /[:]\s*/.exec(e), n = t && t.index;
956
987
  if (n) return [e.substring(0, n), e.substring(n + t[0].length)];
957
988
  }
958
- function Xe(e, t, n) {
989
+ function et(e, t, n) {
959
990
  e.get(t) || e.set(t, n);
960
991
  }
961
992
  //#endregion
962
993
  //#region ../../node_modules/.pnpm/fetch-event-stream@0.1.6/node_modules/fetch-event-stream/esm/mod.js
963
- async function* Ze(e, t) {
994
+ async function* tt(e, t) {
964
995
  if (!e.body) return;
965
- let n = Je(e.body), r, i = n.getReader(), a;
996
+ let n = Qe(e.body), r, i = n.getReader(), a;
966
997
  for (;;) {
967
998
  if (t && t.aborted) return i.cancel();
968
999
  if (r = await i.read(), r.done) return;
@@ -970,20 +1001,20 @@ async function* Ze(e, t) {
970
1001
  a && (yield a), a = void 0;
971
1002
  continue;
972
1003
  }
973
- let [e, n] = Ye(r.value) || [];
1004
+ let [e, n] = $e(r.value) || [];
974
1005
  e === "data" ? (a ||= {}, a[e] = a[e] ? a[e] + "\n" + n : n) : e === "event" ? (a ||= {}, a[e] = n) : e === "id" ? (a ||= {}, a[e] = String(+n) === n ? +n : n) : e === "retry" && (a ||= {}, a[e] = +n || void 0);
975
1006
  }
976
1007
  }
977
- async function Qe(e, t) {
1008
+ async function nt(e, t) {
978
1009
  let n = new Request(e, t);
979
- Xe(n.headers, "Accept", "text/event-stream"), Xe(n.headers, "Content-Type", "application/json");
1010
+ et(n.headers, "Accept", "text/event-stream"), et(n.headers, "Content-Type", "application/json");
980
1011
  let r = await fetch(n);
981
1012
  if (!r.ok) throw r;
982
- return Ze(r, n.signal);
1013
+ return tt(r, n.signal);
983
1014
  }
984
1015
  //#endregion
985
1016
  //#region src/utils/stream.ts
986
- async function $e() {
1017
+ async function rt() {
987
1018
  let { event_callbacks: e, unclosed_events: t, pending_stream_messages: n, stream_status: r, config: i, jwt: a } = this, o = this;
988
1019
  if (!i) throw Error("Could not resolve app config");
989
1020
  r.open = !0;
@@ -995,7 +1026,7 @@ async function $e() {
995
1026
  s.onmessage = async function(a) {
996
1027
  let s = JSON.parse(a.data);
997
1028
  if (s.msg === "close_stream") {
998
- et(r, o.abort_controller);
1029
+ it(r, o.abort_controller);
999
1030
  return;
1000
1031
  }
1001
1032
  let c = s.event_id;
@@ -1018,23 +1049,23 @@ async function $e() {
1018
1049
  })));
1019
1050
  };
1020
1051
  }
1021
- function et(e, t) {
1052
+ function it(e, t) {
1022
1053
  e && (e.open = !1, t?.abort());
1023
1054
  }
1024
- function tt(e, t, n) {
1055
+ function at(e, t, n) {
1025
1056
  e[t] ? n.data.forEach((r, i) => {
1026
- let a = nt(i < e[t].length ? e[t][i] : null, r);
1057
+ let a = ot(i < e[t].length ? e[t][i] : null, r);
1027
1058
  e[t][i] = a, n.data[i] = a;
1028
1059
  }) : (e[t] = [], n.data.forEach((n, r) => {
1029
1060
  e[t][r] = n;
1030
1061
  }));
1031
1062
  }
1032
- function nt(e, t) {
1063
+ function ot(e, t) {
1033
1064
  return t.forEach(([t, n, r]) => {
1034
- e = rt(e, n, t, r);
1065
+ e = st(e, n, t, r);
1035
1066
  }), e;
1036
1067
  }
1037
- function rt(e, t, n, r) {
1068
+ function st(e, t, n, r) {
1038
1069
  if (t.length === 0) {
1039
1070
  if (n === "replace") return r;
1040
1071
  if (n === "append") return e + r;
@@ -1060,7 +1091,7 @@ function rt(e, t, n, r) {
1060
1091
  }
1061
1092
  return e;
1062
1093
  }
1063
- function it(e, t = {}) {
1094
+ function ct(e, t = {}) {
1064
1095
  let n = {
1065
1096
  close: () => {
1066
1097
  console.warn("Method not implemented.");
@@ -1084,7 +1115,7 @@ function it(e, t = {}) {
1084
1115
  throw Error("Method not implemented.");
1085
1116
  }
1086
1117
  };
1087
- return Qe(e, t).then(async (e) => {
1118
+ return nt(e, t).then(async (e) => {
1088
1119
  n.readyState = n.OPEN;
1089
1120
  try {
1090
1121
  for await (let t of e) n.onmessage && n.onmessage(t);
@@ -1098,7 +1129,7 @@ function it(e, t = {}) {
1098
1129
  }
1099
1130
  //#endregion
1100
1131
  //#region src/utils/run_history.ts
1101
- var at = "gradio:run-history:", q = `${at}v2:`, ot = `${at}replay:v2:`, st = 100, ct = 8;
1132
+ var K = "gradio:run-history:", q = `${K}v2:`, lt = `${K}replay:v2:`, ut = `${K}destination:v1:`, dt = 100, ft = 8;
1102
1133
  function J(e, t) {
1103
1134
  try {
1104
1135
  return e();
@@ -1106,7 +1137,7 @@ function J(e, t) {
1106
1137
  return console.warn("Could not update the run history.", e), t;
1107
1138
  }
1108
1139
  }
1109
- function lt(e, t = "/gradio_api") {
1140
+ function pt(e, t = "/gradio_api") {
1110
1141
  return `${e.replace(/\/+$/, "")}${t}/runs`;
1111
1142
  }
1112
1143
  function Y(e) {
@@ -1119,11 +1150,35 @@ function Y(e) {
1119
1150
  return null;
1120
1151
  }
1121
1152
  }
1122
- function ut(e) {
1153
+ function mt(e) {
1123
1154
  let t = Y(e);
1124
- return t ? t.replace(q, ot) : null;
1155
+ return t ? t.replace(q, lt) : null;
1125
1156
  }
1126
- function dt(e) {
1157
+ function ht(e) {
1158
+ let t = Y(e);
1159
+ return t ? t.replace(q, ut) : null;
1160
+ }
1161
+ function gt(e) {
1162
+ let t = ht(e);
1163
+ if (!t) return { type: "browser" };
1164
+ try {
1165
+ let e = JSON.parse(window.localStorage.getItem(t) || "null");
1166
+ return typeof e?.bucket_id == "string" ? e.type === "bucket" ? {
1167
+ type: "bucket",
1168
+ bucket_id: e.bucket_id
1169
+ } : {
1170
+ type: "browser",
1171
+ bucket_id: e.bucket_id
1172
+ } : { type: "browser" };
1173
+ } catch {
1174
+ return { type: "browser" };
1175
+ }
1176
+ }
1177
+ function _t(e, t) {
1178
+ let n = ht(e);
1179
+ n && (t.type === "browser" && !t.bucket_id ? window.localStorage.removeItem(n) : window.localStorage.setItem(n, JSON.stringify(t)), Tt());
1180
+ }
1181
+ function vt(e) {
1127
1182
  try {
1128
1183
  let t = JSON.parse(window.localStorage.getItem(e) || "[]");
1129
1184
  return Array.isArray(t) && t.length && Date.parse(t[0]?.started_at) || 0;
@@ -1131,13 +1186,13 @@ function dt(e) {
1131
1186
  return 0;
1132
1187
  }
1133
1188
  }
1134
- function ft(e) {
1135
- let t = Object.keys(window.localStorage).filter((e) => e.startsWith(at)), n = [...t.filter((e) => !e.startsWith(q) && !e.startsWith(ot)), ...t.filter((t) => t.startsWith(q) && t !== e).sort((e, t) => dt(t) - dt(e)).slice(ct - 1)];
1189
+ function yt(e) {
1190
+ let t = Object.keys(window.localStorage).filter((e) => e.startsWith(K)), n = [...t.filter((e) => !e.startsWith(q) && !e.startsWith(lt) && !e.startsWith(ut)), ...t.filter((t) => t.startsWith(q) && t !== e).sort((e, t) => vt(t) - vt(e)).slice(ft - 1)];
1136
1191
  for (let e of n) try {
1137
- window.localStorage.removeItem(e), window.sessionStorage.removeItem(e.replace(q, ot));
1192
+ window.localStorage.removeItem(e), window.sessionStorage.removeItem(e.replace(q, lt));
1138
1193
  } catch {}
1139
1194
  }
1140
- function pt() {
1195
+ function bt() {
1141
1196
  return typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(36).slice(2)}`;
1142
1197
  }
1143
1198
  function X(e) {
@@ -1165,16 +1220,16 @@ function Z(e) {
1165
1220
  return [];
1166
1221
  }
1167
1222
  }
1168
- function mt(e, t) {
1223
+ function xt(e, t) {
1169
1224
  let n = Y(e);
1170
1225
  if (!n) return;
1171
- let r = t.slice(0, st), i = !1;
1226
+ let r = t.slice(0, dt), i = !1;
1172
1227
  for (; r.length > 0;) try {
1173
1228
  window.localStorage.setItem(n, JSON.stringify(r));
1174
1229
  return;
1175
1230
  } catch {
1176
1231
  if (!i) {
1177
- i = !0, ft(n);
1232
+ i = !0, yt(n);
1178
1233
  continue;
1179
1234
  }
1180
1235
  r = r.slice(0, -1);
@@ -1183,37 +1238,37 @@ function mt(e, t) {
1183
1238
  window.localStorage.removeItem(n);
1184
1239
  } catch {}
1185
1240
  }
1186
- function ht(e) {
1241
+ function St(e) {
1187
1242
  let t = Y(e);
1188
1243
  if (t) {
1189
1244
  try {
1190
1245
  window.localStorage.removeItem(t);
1191
1246
  } catch {}
1192
- vt();
1247
+ Tt();
1193
1248
  }
1194
1249
  }
1195
- function gt(e, t) {
1196
- mt(e, Z(e).filter((e) => e.id !== t)), vt();
1250
+ function Ct(e, t) {
1251
+ xt(e, Z(e).filter((e) => e.id !== t)), Tt();
1197
1252
  }
1198
- var _t = "gradio:run-history-change";
1199
- function vt() {
1253
+ var wt = "gradio:run-history-change";
1254
+ function Tt() {
1200
1255
  if (!(typeof window > "u")) try {
1201
- window.dispatchEvent(new Event(_t));
1256
+ window.dispatchEvent(new Event(wt));
1202
1257
  } catch {}
1203
1258
  }
1204
- function yt(e) {
1205
- return typeof window > "u" ? () => {} : (window.addEventListener(_t, e), window.addEventListener("storage", e), () => {
1206
- window.removeEventListener(_t, e), window.removeEventListener("storage", e);
1259
+ function Et(e) {
1260
+ return typeof window > "u" ? () => {} : (window.addEventListener(wt, e), window.addEventListener("storage", e), () => {
1261
+ window.removeEventListener(wt, e), window.removeEventListener("storage", e);
1207
1262
  });
1208
1263
  }
1209
- function bt(e, t) {
1210
- let n = ut(e);
1264
+ function Dt(e, t) {
1265
+ let n = mt(e);
1211
1266
  if (n) try {
1212
1267
  window.sessionStorage.setItem(n, JSON.stringify(t));
1213
1268
  } catch {}
1214
1269
  }
1215
- function xt(e) {
1216
- let t = ut(e);
1270
+ function Ot(e) {
1271
+ let t = mt(e);
1217
1272
  if (!t) return null;
1218
1273
  try {
1219
1274
  let e = window.sessionStorage.getItem(t);
@@ -1222,7 +1277,7 @@ function xt(e) {
1222
1277
  return null;
1223
1278
  }
1224
1279
  }
1225
- function St(e, t) {
1280
+ function kt(e, t) {
1226
1281
  let n = e.dependencies.find((e) => e.id === t.fn_index || typeof e.api_name == "string" && `/${e.api_name.replace(/^\//, "")}` === t.api_name);
1227
1282
  if (!n) return !1;
1228
1283
  let r = Array.isArray(t.inputs) ? t.inputs : Object.values(t.inputs ?? {}), i = Array.isArray(t.outputs) ? t.outputs : t.outputs === null || t.outputs === void 0 ? [] : [t.outputs], a = (t, n) => {
@@ -1233,16 +1288,17 @@ function St(e, t) {
1233
1288
  };
1234
1289
  return a(n.inputs, r), a(n.outputs, i), !0;
1235
1290
  }
1236
- function Ct(e) {
1237
- let t = xt(e);
1238
- return t ? St(e, t) : !1;
1291
+ function At(e) {
1292
+ let t = Ot(e);
1293
+ return t ? kt(e, t) : !1;
1239
1294
  }
1240
- function wt(e) {
1295
+ function jt(e) {
1296
+ if (gt(e).type === "bucket") return null;
1241
1297
  let t = Y(e);
1242
1298
  if (!t) return null;
1243
- ft(t);
1299
+ yt(t);
1244
1300
  let n = {
1245
- id: pt(),
1301
+ id: bt(),
1246
1302
  endpoint: e.endpoint,
1247
1303
  api_name: e.api_name,
1248
1304
  fn_index: e.fn_index,
@@ -1254,108 +1310,117 @@ function wt(e) {
1254
1310
  status: "running",
1255
1311
  started_at: (/* @__PURE__ */ new Date()).toISOString()
1256
1312
  };
1257
- return mt(e, [n, ...Z(e)]), vt(), n.id;
1313
+ return xt(e, [n, ...Z(e)]), Tt(), n.id;
1258
1314
  }
1259
- function Tt(e, t, n) {
1315
+ function Mt(e, t, n) {
1260
1316
  if (!t) return;
1261
1317
  let r = Z(e), i = r.find((e) => e.id === t);
1262
- i && (i.inputs = X(n), mt(e, r));
1318
+ i && (i.inputs = X(n), xt(e, r));
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
1323
  if (!i) return;
1268
1324
  let a = !1;
1269
1325
  if (n.type === "data") i.outputs = X(n.data), Q.set(t, i.outputs);
1270
- else if (n.type === "status" && n.original_msg === "process_starts") kt(i, n.time);
1326
+ else if (n.type === "status" && n.original_msg === "process_starts") It(i, n.time);
1271
1327
  else if (n.type === "status" && (n.stage === "generating" || n.stage === "streaming")) i.streamed = !0;
1272
- else if (n.type === "status" && n.stage === "complete") i.status = "completed", At(i, n), a = !0;
1273
- 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"), At(i, n), a = !0;
1328
+ else if (n.type === "status" && n.stage === "complete") i.status = "completed", Lt(i, n), a = !0;
1329
+ else if (n.type === "status" && n.stage === "error") i.status = "failed", i.error = typeof n.message == "string" ? n.message : JSON.stringify(n.message || "Unknown error"), Lt(i, n), a = !0;
1274
1330
  else return;
1275
- if (a) Q.has(t) && (i.outputs = Q.get(t)), Q.delete(t), Ot.delete(t);
1331
+ if (a) Q.has(t) && (i.outputs = Q.get(t)), Q.delete(t), Ft.delete(t);
1276
1332
  else if (i.streamed) {
1277
- if (Date.now() - (Ot.get(t) ?? 0) < Dt) return;
1278
- Ot.set(t, Date.now()), Q.delete(t);
1333
+ if (Date.now() - (Ft.get(t) ?? 0) < Pt) return;
1334
+ Ft.set(t, Date.now()), Q.delete(t);
1279
1335
  }
1280
- mt(e, r);
1336
+ xt(e, r);
1281
1337
  }
1282
- var Dt = 500, Ot = /* @__PURE__ */ new Map(), Q = /* @__PURE__ */ new Map();
1283
- function kt(e, t) {
1338
+ var Pt = 500, Ft = /* @__PURE__ */ new Map(), Q = /* @__PURE__ */ new Map();
1339
+ function It(e, t) {
1284
1340
  if (e.process_started_at) return;
1285
1341
  let n = t || /* @__PURE__ */ new Date();
1286
1342
  e.process_started_at = n.toISOString(), e.queued_ms = Math.max(0, n.getTime() - Date.parse(e.started_at));
1287
1343
  }
1288
- function At(e, t) {
1344
+ function Lt(e, t) {
1289
1345
  let n = t.time || /* @__PURE__ */ new Date();
1290
1346
  e.completed_at = n.toISOString(), e.duration_ms = (!e.streamed && typeof t.cache_duration == "number" && t.cache_duration >= 0 ? t.cache_duration * 1e3 : null) ?? Math.max(0, n.getTime() - Date.parse(e.process_started_at || e.started_at));
1291
1347
  }
1292
- function jt(e) {
1348
+ function Rt(e) {
1293
1349
  return J(() => Z(e), []);
1294
1350
  }
1295
- function Mt(e) {
1296
- J(() => ht(e), void 0);
1351
+ function zt(e) {
1352
+ return J(() => gt(e), { type: "browser" });
1353
+ }
1354
+ function Bt(e, t) {
1355
+ J(() => _t(e, t), void 0);
1297
1356
  }
1298
- function Nt(e, t) {
1299
- J(() => gt(e, t), void 0);
1357
+ function Vt(e) {
1358
+ J(() => St(e), void 0);
1300
1359
  }
1301
- function Pt(e, t) {
1302
- J(() => bt(e, t), void 0);
1360
+ function Ht(e, t) {
1361
+ J(() => Ct(e, t), void 0);
1303
1362
  }
1304
- function Ft(e) {
1305
- return J(() => xt(e), null);
1363
+ function Ut(e, t) {
1364
+ J(() => Dt(e, t), void 0);
1306
1365
  }
1307
- function It(e) {
1308
- return J(() => Ct(e), !1);
1366
+ function Wt(e) {
1367
+ return J(() => Ot(e), null);
1309
1368
  }
1310
- function Lt(e) {
1311
- return J(() => wt(e), null);
1369
+ function Gt(e) {
1370
+ return J(() => At(e), !1);
1312
1371
  }
1313
- function Rt(e, t, n) {
1314
- J(() => Tt(e, t, n), void 0);
1372
+ function Kt(e) {
1373
+ return J(() => jt(e), null);
1315
1374
  }
1316
- function zt(e, t, n) {
1317
- J(() => Et(e, t, n), void 0);
1375
+ function qt(e, t, n) {
1376
+ J(() => Mt(e, t, n), void 0);
1318
1377
  }
1319
- function Bt(e) {
1320
- return J(() => yt(() => J(e, void 0)), () => {});
1378
+ function Jt(e, t, n) {
1379
+ J(() => Nt(e, t, n), void 0);
1380
+ }
1381
+ function Yt(e) {
1382
+ return J(() => Et(() => J(e, void 0)), () => {});
1321
1383
  }
1322
1384
  //#endregion
1323
1385
  //#region src/utils/submit.ts
1324
- function Vt(e, t = {}, n, r, i, a) {
1386
+ function Xt(e, t = {}, n, r, i, a) {
1325
1387
  try {
1326
- 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, x = a || { "x-gradio-user": "api" }, S = this;
1327
- if (!p) throw Error(ce);
1388
+ let { token: o } = this.options, { fetch: s, app_reference: c, config: l, session_hash: f, api_info: p, api_map: m, stream_status: ee, pending_stream_messages: h, pending_diff_streams: te, event_callbacks: g, unclosed_events: ne, post_data: _, options: y, api_prefix: b } = this, oe = a || { "x-gradio-user": "api" }, x = this;
1389
+ if (!p) throw Error(le);
1328
1390
  if (!l) throw Error("Could not resolve app config");
1329
- let { fn_index: C, endpoint_info: w, dependency: T } = Ut(p, e, m, l), oe = ye(t, w), E = l.protocol ?? "ws";
1330
- if (E === "ws") throw Error(le);
1331
- let se = typeof T.api_name == "string" ? `/${T.api_name}` : e, ue = typeof T.api_name == "string" ? `/${T.api_name}` : `Function ${C}`, D = (e) => {
1391
+ let se = l.root, { fn_index: S, endpoint_info: C, dependency: w } = Qt(p, e, m, l), ce = ye(t, C), T = l.protocol ?? "ws";
1392
+ if (T === "ws") throw Error(ue);
1393
+ let de = typeof w.api_name == "string" ? `/${w.api_name}` : e, fe = typeof w.api_name == "string" ? `/${w.api_name}` : `Function ${S}`, pe = (e) => {
1332
1394
  let t = l.components.find((t) => t.id === e);
1333
1395
  return t ? {
1334
1396
  type: t.type,
1335
1397
  component_class_id: t.component_class_id,
1336
1398
  props: t.props
1337
1399
  } : null;
1338
- }, de = T.api_visibility === "public", fe = l.run_history !== !1 && this.options.record_history !== !1, O = {
1400
+ }, me = w.api_visibility === "public", E = l.run_history !== !1 && this.options.record_history !== !1, D = {
1339
1401
  app_id: l.app_id,
1340
1402
  username: l.username
1341
- }, k = !fe || !de ? null : Lt({
1342
- ...O,
1343
- endpoint: se,
1344
- api_name: ue,
1345
- fn_index: C,
1346
- inputs: G(oe, T, l.components, "input", !0),
1347
- input_components: T.inputs.map(D),
1348
- output_components: T.outputs.map(D)
1349
- }), 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 = y?.events?.reduce((e, t) => (e[t] = !0, e), {}) || {};
1403
+ }, he = zt(D), O = {
1404
+ ...oe,
1405
+ ...E && he.type === "bucket" ? { "x-gradio-history-bucket": he.bucket_id } : {}
1406
+ }, k = !E || !me ? null : Kt({
1407
+ ...D,
1408
+ endpoint: de,
1409
+ api_name: fe,
1410
+ fn_index: S,
1411
+ inputs: W(ce, w, l.components, "input", !0),
1412
+ input_components: w.inputs.map(pe),
1413
+ output_components: w.outputs.map(pe)
1414
+ }), A, j = "", M = typeof e == "number" ? "/predict" : e, N, P = null, F = !1, I = {}, L = typeof window < "u" && typeof document < "u" ? new URLSearchParams(window.location.search).toString() : "", ge = y?.events?.reduce((e, t) => (e[t] = !0, e), {}) || {};
1350
1415
  function R(e) {
1351
- zt(O, k, e), (i || pe[e.type]) && U(e);
1416
+ Jt(D, k, e), (e.type === "data" || e.type === "render") && Ae(e.data, se, b, x.jwt), (i || ge[e.type]) && Te(e);
1352
1417
  }
1353
- async function me() {
1418
+ async function _e() {
1354
1419
  let e = {}, t = {};
1355
1420
  e = { event_id: P }, t = {
1356
1421
  event_id: P,
1357
1422
  session_hash: f,
1358
- fn_index: C
1423
+ fn_index: S
1359
1424
  };
1360
1425
  try {
1361
1426
  if (!l) throw Error("Could not resolve app config");
@@ -1372,53 +1437,53 @@ function Vt(e, t = {}, n, r, i, a) {
1372
1437
  console.warn("The `/reset` endpoint could not be called. Subsequent endpoint results may be unreliable.");
1373
1438
  }
1374
1439
  }
1375
- let he = async (e) => {
1440
+ let be = async (e) => {
1376
1441
  await this._resolve_heartbeat(e);
1377
1442
  };
1378
- async function ge(e) {
1443
+ async function xe(e) {
1379
1444
  if (!l) return;
1380
1445
  let t = e.render_id;
1381
1446
  l.components = [...l.components.filter((e) => e.props.rendered_in !== t), ...e.components], l.dependencies = [...l.dependencies.filter((e) => e.rendered_in !== t), ...e.dependencies];
1382
1447
  let n = l.components.some((e) => e.type === "state"), r = l.dependencies.some((e) => e.targets.some((e) => e[1] === "unload"));
1383
- l.connect_heartbeat = n || r, await he(l), R({
1448
+ l.connect_heartbeat = n || r, await be(l), R({
1384
1449
  type: "render",
1385
1450
  data: e,
1386
1451
  endpoint: M,
1387
- fn_index: C
1452
+ fn_index: S
1388
1453
  });
1389
1454
  }
1390
- let _e = this.handle_blob(l.root, oe, w).then(async (e) => {
1391
- let t = G(e, T, l.components, "input", !0);
1392
- if (Rt(O, k, t || []), N = {
1455
+ let Se = this.handle_blob(l.root, ce, C).then(async (e) => {
1456
+ let t = W(e, w, l.components, "input", !0);
1457
+ if (qt(D, k, t || []), N = {
1393
1458
  data: t || [],
1394
1459
  event_data: n,
1395
- fn_index: C,
1460
+ fn_index: S,
1396
1461
  trigger_id: r,
1397
- ...y.oauth_token && w?.oauth_token ? { oauth_token: y.oauth_token } : {}
1398
- }, Te(C, l)) R({
1462
+ ...y.oauth_token && C?.oauth_token ? { oauth_token: y.oauth_token } : {}
1463
+ }, Ee(S, l)) R({
1399
1464
  type: "status",
1400
1465
  endpoint: M,
1401
1466
  stage: "pending",
1402
1467
  queue: !1,
1403
- fn_index: C,
1468
+ fn_index: S,
1404
1469
  time: /* @__PURE__ */ new Date()
1405
1470
  }), _(`${l.root}${b}/run${M.startsWith("/") ? M : `/${M}`}${L ? "?" + L : ""}`, {
1406
1471
  ...N,
1407
1472
  session_hash: f
1408
- }, x).then(async ([e, t]) => {
1473
+ }, O).then(async ([e, t]) => {
1409
1474
  let i = e.data;
1410
1475
  if (t == 200) R({
1411
1476
  type: "data",
1412
1477
  endpoint: M,
1413
- fn_index: C,
1414
- data: G(i, T, l.components, "output", y.with_null_state),
1478
+ fn_index: S,
1479
+ data: W(i, w, l.components, "output", y.with_null_state),
1415
1480
  time: /* @__PURE__ */ new Date(),
1416
1481
  event_data: n,
1417
1482
  trigger_id: r
1418
- }), e.render_config && await ge(e.render_config), R({
1483
+ }), e.render_config && await xe(e.render_config), R({
1419
1484
  type: "status",
1420
1485
  endpoint: M,
1421
- fn_index: C,
1486
+ fn_index: S,
1422
1487
  stage: "complete",
1423
1488
  eta: e.average_duration,
1424
1489
  queue: !1,
@@ -1430,7 +1495,7 @@ function Vt(e, t = {}, n, r, i, a) {
1430
1495
  type: "status",
1431
1496
  stage: "error",
1432
1497
  endpoint: M,
1433
- fn_index: C,
1498
+ fn_index: S,
1434
1499
  message: e.error,
1435
1500
  broken: t,
1436
1501
  queue: !1,
@@ -1443,32 +1508,32 @@ function Vt(e, t = {}, n, r, i, a) {
1443
1508
  stage: "error",
1444
1509
  message: e.message,
1445
1510
  endpoint: M,
1446
- fn_index: C,
1511
+ fn_index: S,
1447
1512
  queue: !1,
1448
1513
  time: /* @__PURE__ */ new Date()
1449
1514
  });
1450
1515
  });
1451
- else if (E == "sse") {
1516
+ else if (T == "sse") {
1452
1517
  R({
1453
1518
  type: "status",
1454
1519
  stage: "pending",
1455
1520
  queue: !0,
1456
1521
  endpoint: M,
1457
- fn_index: C,
1522
+ fn_index: S,
1458
1523
  time: /* @__PURE__ */ new Date()
1459
1524
  });
1460
1525
  var i = new URLSearchParams({
1461
- fn_index: C.toString(),
1526
+ fn_index: S.toString(),
1462
1527
  session_hash: f
1463
1528
  }).toString();
1464
1529
  let e = new URL(`${l.root}${b}/${u}?${L ? L + "&" : ""}${i}`);
1465
1530
  if (this.jwt && e.searchParams.set("__sign", this.jwt), A = this.stream(e), !A) return Promise.reject(/* @__PURE__ */ Error("Cannot connect to SSE endpoint: " + e.toString()));
1466
1531
  A.onmessage = async function(e) {
1467
- let { type: t, status: i, data: a } = ve(JSON.parse(e.data), I[C]);
1532
+ let { type: t, status: i, data: a } = ve(JSON.parse(e.data), I[S]);
1468
1533
  if (t === "update" && i && !F) R({
1469
1534
  type: "status",
1470
1535
  endpoint: M,
1471
- fn_index: C,
1536
+ fn_index: S,
1472
1537
  time: /* @__PURE__ */ new Date(),
1473
1538
  ...i
1474
1539
  }), i.stage === "error" && (A?.close(), V());
@@ -1477,14 +1542,14 @@ function Vt(e, t = {}, n, r, i, a) {
1477
1542
  ...N,
1478
1543
  session_hash: f,
1479
1544
  event_id: P
1480
- });
1545
+ }, O);
1481
1546
  t !== 200 && (R({
1482
1547
  type: "status",
1483
1548
  stage: "error",
1484
1549
  message: v,
1485
1550
  queue: !0,
1486
1551
  endpoint: M,
1487
- fn_index: C,
1552
+ fn_index: S,
1488
1553
  time: /* @__PURE__ */ new Date()
1489
1554
  }), A?.close(), V());
1490
1555
  } else t === "complete" ? F = i : t === "log" ? R({
@@ -1495,7 +1560,7 @@ function Vt(e, t = {}, n, r, i, a) {
1495
1560
  endpoint: M,
1496
1561
  duration: a.duration,
1497
1562
  visible: a.visible,
1498
- fn_index: C
1563
+ fn_index: S
1499
1564
  }) : (t === "generating" || t === "streaming") && R({
1500
1565
  type: "status",
1501
1566
  time: /* @__PURE__ */ new Date(),
@@ -1503,14 +1568,14 @@ function Vt(e, t = {}, n, r, i, a) {
1503
1568
  stage: i?.stage,
1504
1569
  queue: !0,
1505
1570
  endpoint: M,
1506
- fn_index: C
1571
+ fn_index: S
1507
1572
  });
1508
1573
  a && (R({
1509
1574
  type: "data",
1510
1575
  time: /* @__PURE__ */ new Date(),
1511
- data: G(a.data, T, l.components, "output", y.with_null_state),
1576
+ data: W(a.data, w, l.components, "output", y.with_null_state),
1512
1577
  endpoint: M,
1513
- fn_index: C,
1578
+ fn_index: S,
1514
1579
  event_data: n,
1515
1580
  trigger_id: r
1516
1581
  }), F && (R({
@@ -1520,24 +1585,24 @@ function Vt(e, t = {}, n, r, i, a) {
1520
1585
  stage: i?.stage,
1521
1586
  queue: !0,
1522
1587
  endpoint: M,
1523
- fn_index: C
1588
+ fn_index: S
1524
1589
  }), A?.close(), V()));
1525
1590
  };
1526
- } else if (E == "sse_v1" || E == "sse_v2" || E == "sse_v2.1" || E == "sse_v3") {
1591
+ } else if (T == "sse_v1" || T == "sse_v2" || T == "sse_v2.1" || T == "sse_v3") {
1527
1592
  R({
1528
1593
  type: "status",
1529
1594
  stage: "pending",
1530
1595
  queue: !0,
1531
1596
  endpoint: M,
1532
- fn_index: C,
1597
+ fn_index: S,
1533
1598
  time: /* @__PURE__ */ new Date()
1534
1599
  });
1535
1600
  let e = "";
1536
1601
  typeof window < "u" && typeof document < "u" && (e = window?.location?.hostname);
1537
- let t = Ge(e);
1538
- return (typeof window < "u" && typeof document < "u" && window.parent != window && t && window.supports_zerogpu_headers ? Ee("zerogpu-headers", t) : Promise.resolve(null)).then((e) => {
1602
+ let t = Ye(e);
1603
+ return (typeof window < "u" && typeof document < "u" && window.parent != window && t && window.supports_zerogpu_headers ? De("zerogpu-headers", t) : Promise.resolve(null)).then((e) => {
1539
1604
  let t = {
1540
- ...x,
1605
+ ...O,
1541
1606
  ...e || {}
1542
1607
  };
1543
1608
  return _(`${l.root}${b}/${d}?${L}`, {
@@ -1551,7 +1616,7 @@ function Vt(e, t = {}, n, r, i, a) {
1551
1616
  message: ae,
1552
1617
  queue: !0,
1553
1618
  endpoint: M,
1554
- fn_index: C,
1619
+ fn_index: S,
1555
1620
  time: /* @__PURE__ */ new Date(),
1556
1621
  visible: !0
1557
1622
  }), V();
@@ -1561,7 +1626,7 @@ function Vt(e, t = {}, n, r, i, a) {
1561
1626
  message: e.detail,
1562
1627
  queue: !0,
1563
1628
  endpoint: M,
1564
- fn_index: C,
1629
+ fn_index: S,
1565
1630
  code: "validation_error",
1566
1631
  time: /* @__PURE__ */ new Date(),
1567
1632
  visible: !0
@@ -1575,7 +1640,7 @@ function Vt(e, t = {}, n, r, i, a) {
1575
1640
  message: t ? v : e.detail || e.error,
1576
1641
  queue: !0,
1577
1642
  endpoint: M,
1578
- fn_index: C,
1643
+ fn_index: S,
1579
1644
  time: /* @__PURE__ */ new Date(),
1580
1645
  visible: !0
1581
1646
  }), V();
@@ -1583,12 +1648,12 @@ function Vt(e, t = {}, n, r, i, a) {
1583
1648
  P = e.event_id, j = P;
1584
1649
  let t = async function(e) {
1585
1650
  try {
1586
- let { type: t, status: n, data: r, original_msg: i } = ve(e, I[C]);
1651
+ let { type: t, status: n, data: r, original_msg: i } = ve(e, I[S]);
1587
1652
  if (t == "heartbeat") return;
1588
1653
  if (t === "update" && n && !F) R({
1589
1654
  type: "status",
1590
1655
  endpoint: M,
1591
- fn_index: C,
1656
+ fn_index: S,
1592
1657
  time: /* @__PURE__ */ new Date(),
1593
1658
  original_msg: i,
1594
1659
  ...n
@@ -1605,7 +1670,7 @@ function Vt(e, t = {}, n, r, i, a) {
1605
1670
  endpoint: M,
1606
1671
  broken: e,
1607
1672
  session_not_found: n?.session_not_found,
1608
- fn_index: C,
1673
+ fn_index: S,
1609
1674
  time: /* @__PURE__ */ new Date()
1610
1675
  });
1611
1676
  } else if (t === "log") {
@@ -1617,7 +1682,7 @@ function Vt(e, t = {}, n, r, i, a) {
1617
1682
  endpoint: M,
1618
1683
  duration: r.duration,
1619
1684
  visible: r.visible,
1620
- fn_index: C
1685
+ fn_index: S
1621
1686
  });
1622
1687
  return;
1623
1688
  } else (t === "generating" || t === "streaming") && (R({
@@ -1627,26 +1692,26 @@ function Vt(e, t = {}, n, r, i, a) {
1627
1692
  stage: n?.stage,
1628
1693
  queue: !0,
1629
1694
  endpoint: M,
1630
- fn_index: C
1631
- }), r && T.connection !== "stream" && [
1695
+ fn_index: S
1696
+ }), r && w.connection !== "stream" && [
1632
1697
  "sse_v2",
1633
1698
  "sse_v2.1",
1634
1699
  "sse_v3"
1635
- ].includes(E) && tt(te, P, r));
1700
+ ].includes(T) && at(te, P, r));
1636
1701
  r && (R({
1637
1702
  type: "data",
1638
1703
  time: /* @__PURE__ */ new Date(),
1639
- data: G(r.data, T, l.components, "output", y.with_null_state),
1704
+ data: W(r.data, w, l.components, "output", y.with_null_state),
1640
1705
  endpoint: M,
1641
- fn_index: C
1642
- }), r.render_config && await ge(r.render_config), F && (R({
1706
+ fn_index: S
1707
+ }), r.render_config && await xe(r.render_config), F && (R({
1643
1708
  type: "status",
1644
1709
  time: /* @__PURE__ */ new Date(),
1645
1710
  ...F,
1646
1711
  stage: n?.stage,
1647
1712
  queue: !0,
1648
1713
  endpoint: M,
1649
- fn_index: C
1714
+ fn_index: S
1650
1715
  }), V())), (n?.stage === "complete" || n?.stage === "error") && (g[P] && delete g[P], P in te && delete te[P], V());
1651
1716
  } catch (e) {
1652
1717
  console.error("Unexpected client exception", e), R({
@@ -1655,13 +1720,13 @@ function Vt(e, t = {}, n, r, i, a) {
1655
1720
  message: "An Unexpected Error Occurred!",
1656
1721
  queue: !0,
1657
1722
  endpoint: M,
1658
- fn_index: C,
1723
+ fn_index: S,
1659
1724
  time: /* @__PURE__ */ new Date()
1660
1725
  }), [
1661
1726
  "sse_v2",
1662
1727
  "sse_v2.1",
1663
1728
  "sse_v3"
1664
- ].includes(E) && (et(ee, S.abort_controller), ee.open = !1, V());
1729
+ ].includes(T) && (it(ee, x.abort_controller), ee.open = !1, V());
1665
1730
  }
1666
1731
  };
1667
1732
  P in h && (h[P].forEach((e) => t(e)), delete h[P]), g[P] = t, ne.add(P), ee.open || await this.open_stream();
@@ -1669,20 +1734,20 @@ function Vt(e, t = {}, n, r, i, a) {
1669
1734
  });
1670
1735
  }
1671
1736
  });
1672
- _e.catch((e) => {
1737
+ Se.catch((e) => {
1673
1738
  R({
1674
1739
  type: "status",
1675
1740
  stage: "error",
1676
1741
  message: e instanceof Error ? e.message : String(e),
1677
- queue: !Te(C, l),
1742
+ queue: !Ee(S, l),
1678
1743
  endpoint: M,
1679
- fn_index: C,
1744
+ fn_index: S,
1680
1745
  time: /* @__PURE__ */ new Date()
1681
1746
  }), V();
1682
1747
  });
1683
- let be = !1, z = [], B = [];
1748
+ let Ce = !1, z = [], B = [];
1684
1749
  function V() {
1685
- for (be = !0; B.length > 0;) B.shift()({
1750
+ for (Ce = !0; B.length > 0;) B.shift()({
1686
1751
  value: void 0,
1687
1752
  done: !0
1688
1753
  });
@@ -1690,30 +1755,30 @@ function Vt(e, t = {}, n, r, i, a) {
1690
1755
  function H(e) {
1691
1756
  B.length > 0 ? B.shift()(e) : z.push(e);
1692
1757
  }
1693
- function xe(e) {
1694
- H(Ht(e)), V();
1758
+ function we(e) {
1759
+ H(Zt(e)), V();
1695
1760
  }
1696
- function U(e) {
1761
+ function Te(e) {
1697
1762
  H({
1698
1763
  value: e,
1699
1764
  done: !1
1700
1765
  });
1701
1766
  }
1702
- function W() {
1703
- return z.length > 0 ? Promise.resolve(z.shift()) : be ? Promise.resolve({
1767
+ function U() {
1768
+ return z.length > 0 ? Promise.resolve(z.shift()) : Ce ? Promise.resolve({
1704
1769
  value: void 0,
1705
1770
  done: !0
1706
1771
  }) : new Promise((e) => B.push(e));
1707
1772
  }
1708
- let Se = {
1709
- [Symbol.asyncIterator]: () => Se,
1710
- next: W,
1711
- throw: async (e) => (xe(e), W()),
1773
+ let Oe = {
1774
+ [Symbol.asyncIterator]: () => Oe,
1775
+ next: U,
1776
+ throw: async (e) => (we(e), U()),
1712
1777
  return: async () => (V(), {
1713
1778
  value: void 0,
1714
1779
  done: !0
1715
1780
  }),
1716
- cancel: me,
1781
+ cancel: _e,
1717
1782
  send_chunk: (e) => {
1718
1783
  this.post_data(`${l.root}${b}/stream/${j}`, {
1719
1784
  ...e,
@@ -1724,17 +1789,17 @@ function Vt(e, t = {}, n, r, i, a) {
1724
1789
  this.post_data(`${l.root}${b}/stream/${j}/close`, {}), V();
1725
1790
  },
1726
1791
  event_id: () => j,
1727
- wait_for_id: async () => (await _e, P)
1792
+ wait_for_id: async () => (await Se, P)
1728
1793
  };
1729
- return Se;
1794
+ return Oe;
1730
1795
  } catch (e) {
1731
1796
  throw console.error("Submit function encountered an error:", e), e;
1732
1797
  }
1733
1798
  }
1734
- function Ht(e) {
1799
+ function Zt(e) {
1735
1800
  return { then: (t, n) => n(e) };
1736
1801
  }
1737
- function Ut(e, t, n, r) {
1802
+ function Qt(e, t, n, r) {
1738
1803
  let i, a, o;
1739
1804
  if (typeof t == "number") i = t, a = e.unnamed_endpoints[i], o = r.dependencies.find((e) => e.id == t);
1740
1805
  else {
@@ -1757,6 +1822,7 @@ var $ = class {
1757
1822
  app_reference;
1758
1823
  options;
1759
1824
  deep_link = null;
1825
+ page = null;
1760
1826
  config;
1761
1827
  api_prefix = "";
1762
1828
  api_info;
@@ -1805,7 +1871,7 @@ var $ = class {
1805
1871
  let t = new Headers();
1806
1872
  return this && this.cookies && t.append("Cookie", this.cookies), this && this.options.headers && new Headers(this.options.headers).forEach((e, n) => {
1807
1873
  t.append(n, e);
1808
- }), this && this.options.token && t.append("Authorization", `Bearer ${this.options.token}`), this.abort_controller = new AbortController(), this.stream_instance = it(e.toString(), {
1874
+ }), this && this.options.token && t.append("Authorization", `Bearer ${this.options.token}`), this.abort_controller = new AbortController(), this.stream_instance = ct(e.toString(), {
1809
1875
  credentials: this.options.credentials ?? "same-origin",
1810
1876
  headers: t,
1811
1877
  signal: this.abort_controller.signal
@@ -1822,19 +1888,19 @@ var $ = class {
1822
1888
  resolve_config;
1823
1889
  resolve_cookies;
1824
1890
  constructor(e, t = { events: ["data"] }) {
1825
- this.app_reference = e, this.deep_link = t.query_params?.deep_link || null, t.events ||= ["data"], O(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 = Oe.bind(this), this.post_data = Me.bind(this), this.submit = Vt.bind(this), this.predict = Ne.bind(this), this.open_stream = $e.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);
1891
+ this.app_reference = e, this.deep_link = t.query_params?.deep_link || null, this.page = t.query_params?.page ?? null, t.events ||= ["data"], E(t), this.options = t, this.current_payload = {}, t.cookies && (this.cookies = t.cookies), this.view_api = be.bind(this), this.upload_files = xe.bind(this), this.handle_blob = Me.bind(this), this.post_data = Ie.bind(this), this.submit = Xt.bind(this), this.predict = Le.bind(this), this.open_stream = rt.bind(this), this.resolve_config = O.bind(this), this.resolve_cookies = A.bind(this), this.upload = z.bind(this), this.fetch = this.fetch.bind(this), this.handle_space_success = this.handle_space_success.bind(this), this.stream = this.stream.bind(this);
1826
1892
  }
1827
1893
  async init() {
1828
- Ke(), this.options.auth && await this.resolve_cookies(), await this._resolve_config().then((e) => e?.config && this._resolve_heartbeat(e.config));
1894
+ Xe(), this.options.auth && await this.resolve_cookies(), await this._resolve_config().then((e) => e?.config && this._resolve_heartbeat(e.config));
1829
1895
  try {
1830
1896
  this.api_info = await this.view_api();
1831
1897
  } catch (e) {
1832
1898
  console.error(e.message);
1833
1899
  }
1834
- this.api_map = k(this.config?.dependencies || []);
1900
+ this.api_map = D(this.config?.dependencies || []);
1835
1901
  }
1836
1902
  async _resolve_heartbeat(e) {
1837
- 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 fe(this.config.space_id, this.options.token, this.cookies))), e.space_id && this.options.token && (this.jwt = await fe(e.space_id, this.options.token)), this.config && this.config.connect_heartbeat) {
1903
+ if (this.config = e, this.api_prefix = e.api_prefix || "", e.space_id && this.options.token && (this.jwt = await me(e.space_id, this.options.token, this.cookies)), je(this.config, this.jwt), this.config && this.config.connect_heartbeat) {
1838
1904
  let e = new URL(`${this.config.root}${this.api_prefix}/${g}/${this.session_hash}`);
1839
1905
  this.jwt && e.searchParams.set("__sign", this.jwt), this.heartbeat_event ||= this.stream(e);
1840
1906
  }
@@ -1855,17 +1921,17 @@ var $ = class {
1855
1921
  return t === this.config.app_id ? "connected" : "changed";
1856
1922
  }
1857
1923
  close() {
1858
- this.closed = !0, et(this.stream_status, this.abort_controller);
1924
+ this.closed = !0, it(this.stream_status, this.abort_controller);
1859
1925
  }
1860
1926
  async refresh() {
1861
1927
  if (!this.config) throw Error(y);
1862
1928
  let e = await this.resolve_config(this.config.root, !1);
1863
1929
  if (!e) throw Error(y);
1864
- this.config = e, this.api_prefix = e.api_prefix || "", this.api_map = k(e.dependencies || []);
1930
+ this.config = e, this.api_prefix = e.api_prefix || "", this.api_map = D(e.dependencies || []), je(this.config, this.jwt);
1865
1931
  try {
1866
1932
  this.api_info = await this.view_api();
1867
1933
  } catch (e) {
1868
- console.error(x + e.message);
1934
+ console.error(oe + e.message);
1869
1935
  }
1870
1936
  return this.get_url_config();
1871
1937
  }
@@ -1873,18 +1939,18 @@ var $ = class {
1873
1939
  this.current_payload = e;
1874
1940
  }
1875
1941
  static async duplicate(e, t = { events: ["data"] }) {
1876
- return Be(e, t);
1942
+ return We(e, t);
1877
1943
  }
1878
1944
  async _resolve_config() {
1879
- let { http_protocol: e, host: t, space_id: n } = await R(this.app_reference, this.options.token), { status_callback: r } = this.options;
1880
- n && r && await Pe(n, r);
1945
+ let { http_protocol: e, host: t, space_id: n } = await I(this.app_reference, this.options.token), { status_callback: r } = this.options;
1946
+ n && r && await Re(n, r);
1881
1947
  let i;
1882
1948
  try {
1883
1949
  let n = `${e}//${t}`;
1884
1950
  if (i = await this.resolve_config(n), !i) throw Error(y);
1885
1951
  return this.config_success(i);
1886
1952
  } catch (e) {
1887
- if (n && r) K(n, L.test(n) ? "space_name" : "subdomain", this.handle_space_success);
1953
+ if (n && r) G(n, P.test(n) ? "space_name" : "subdomain", this.handle_space_success);
1888
1954
  else throw r && r({
1889
1955
  status: "error",
1890
1956
  message: "Could not load this space.",
@@ -1894,14 +1960,14 @@ var $ = class {
1894
1960
  }
1895
1961
  }
1896
1962
  async config_success(e) {
1897
- if (this.config = e, this.api_prefix = e.api_prefix || "", e.run_history === !1 && Mt({
1963
+ if (this.config = e, this.api_prefix = e.api_prefix || "", e.run_history === !1 && Vt({
1898
1964
  app_id: e.app_id,
1899
1965
  username: e.username
1900
1966
  }), this.config.auth_required) return this.prepare_return_obj();
1901
1967
  try {
1902
1968
  this.api_info = await this.view_api();
1903
1969
  } catch (e) {
1904
- console.error(x + e.message);
1970
+ console.error(oe + e.message);
1905
1971
  }
1906
1972
  return this.prepare_return_obj();
1907
1973
  }
@@ -1947,13 +2013,14 @@ var $ = class {
1947
2013
  credentials: this.options.credentials ?? "same-origin"
1948
2014
  });
1949
2015
  if (!e.ok) throw Error("Could not connect to component server: " + e.statusText);
1950
- return await e.json();
2016
+ let t = await e.json();
2017
+ return Ae(t, this.config.root, this.config.api_prefix || "", this.jwt), t;
1951
2018
  } catch (e) {
1952
2019
  console.warn(e);
1953
2020
  }
1954
2021
  }
1955
2022
  set_cookies(e) {
1956
- this.cookies = I(e).join("; ");
2023
+ this.cookies = N(e).join("; ");
1957
2024
  }
1958
2025
  prepare_return_obj() {
1959
2026
  return {
@@ -1965,11 +2032,75 @@ var $ = class {
1965
2032
  };
1966
2033
  }
1967
2034
  };
1968
- async function Wt(e, t = { events: ["data"] }) {
2035
+ async function $t(e, t = { events: ["data"] }) {
1969
2036
  return await $.connect(e, t);
1970
2037
  }
1971
- async function Gt(e, t) {
2038
+ async function en(e, t) {
1972
2039
  return await $.duplicate(e, t);
1973
2040
  }
1974
2041
  //#endregion
1975
- export { $ as Client, U as FileData, oe as MISSING_CREDENTIALS_MSG, It as apply_run_history_replay, Mt as clear_run_history, Wt as client, Ft as consume_run_history_replay, Nt as delete_run_history, Gt as duplicate, De as handle_file, Bt as on_run_history_change, Ne as predict, xe as prepare_files, jt as read_run_history, lt as run_history_url, Pt as stage_run_history_replay, Vt as submit, o as t, H as upload, z as upload_files };
2042
+ //#region src/utils/bucket_sync.ts
2043
+ var tn = /^[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-][a-zA-Z0-9_./-]*$/;
2044
+ function nn(e) {
2045
+ return tn.test(e) ? !e.split("/").some((e) => e === "" || e === "." || e === "..") : !1;
2046
+ }
2047
+ function rn(e, t, n) {
2048
+ let r = n ? `?${new URLSearchParams(n)}` : "", i = e.replace(/\/+$/, "");
2049
+ return i ? `${i}/gradio_api/run-history/${t}${r}` : typeof document < "u" && document.baseURI ? new URL(`gradio_api/run-history/${t}${r}`, document.baseURI).toString() : `gradio_api/run-history/${t}${r}`;
2050
+ }
2051
+ async function an(e) {
2052
+ try {
2053
+ let t = await e.json();
2054
+ return typeof t?.detail == "string" ? t.detail : `${e.status}`;
2055
+ } catch {
2056
+ return `${e.status}`;
2057
+ }
2058
+ }
2059
+ async function on(e, t, n, r) {
2060
+ try {
2061
+ let i = await fetch(e, {
2062
+ credentials: "include",
2063
+ ...t
2064
+ });
2065
+ return i.ok ? {
2066
+ ok: !0,
2067
+ status: i.status,
2068
+ data: r(await i.json())
2069
+ } : {
2070
+ ok: !1,
2071
+ status: i.status,
2072
+ data: n,
2073
+ detail: await an(i)
2074
+ };
2075
+ } catch (e) {
2076
+ return {
2077
+ ok: !1,
2078
+ status: 0,
2079
+ data: n,
2080
+ detail: String(e)
2081
+ };
2082
+ }
2083
+ }
2084
+ async function sn(e, t) {
2085
+ return nn(t) ? on(rn(e, "connect"), {
2086
+ method: "POST",
2087
+ headers: { "Content-Type": "application/json" },
2088
+ body: JSON.stringify({ bucket_id: t })
2089
+ }, null, () => null) : {
2090
+ ok: !1,
2091
+ status: 422,
2092
+ data: null,
2093
+ detail: "invalid bucket id"
2094
+ };
2095
+ }
2096
+ async function cn(e) {
2097
+ return on(rn(e, "buckets"), {}, [], (e) => Array.isArray(e?.buckets) ? e.buckets : []);
2098
+ }
2099
+ async function ln(e, t) {
2100
+ return on(rn(e, "records", { bucket: t }), {}, [], (e) => Array.isArray(e?.records) ? e.records : []);
2101
+ }
2102
+ function un(e, t, n, r, i) {
2103
+ return rn(e, `records/${encodeURIComponent(n)}/${encodeURIComponent(r)}/assets/${encodeURIComponent(i)}`, { bucket: t });
2104
+ }
2105
+ //#endregion
2106
+ export { $ as Client, V as FileData, w as MISSING_CREDENTIALS_MSG, Gt as apply_run_history_replay, un as asset_url, Vt as clear_run_history, $t as client, sn as connect_bucket, Wt as consume_run_history_replay, Ht as delete_run_history, en as duplicate, Oe as handle_file, nn as is_valid_bucket_id, ln as list_bucket_records, cn as list_user_buckets, Yt as on_run_history_change, Le as predict, B as prepare_files, Rt as read_run_history, zt as read_run_history_storage, pt as run_history_url, Bt as set_run_history_storage, Ut as stage_run_history_replay, Xt as submit, o as t, z as upload, xe as upload_files };