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