@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/index.min.js CHANGED
@@ -8,10 +8,10 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
8
8
  }, c = (n, r, a) => (a = n == null ? {} : e(i(n)), s(r || !n || !n.__esModule ? t(a, "default", {
9
9
  value: n,
10
10
  enumerable: !0
11
- }) : a, n)), l = "host", u = "queue/data", d = "queue/join", f = "upload", p = "login", m = "config", h = "info", g = "runtime", ee = "sleeptime", _ = "heartbeat", te = "component_server", ne = "reset", re = "cancel", v = "app_id", ie = "This application is currently busy. Please try again. ", y = "Connection errored out. ", b = "Could not resolve app config. ", x = "Could not get space status. ", S = "Could not get API info. ", C = "Space metadata could not be loaded. ", w = "Invalid URL. A full URL path is required.", T = "Not authorized to access this space. ", E = "Invalid credentials. Could not login. ", ae = "Login credentials are required to access this space.", D = "Could not access this app (received a 401 response). If it is a private Hugging Face Space, pass a valid Hugging Face token to the `token` option of `Client.connect`. You can generate a token at https://huggingface.co/settings/tokens.", oe = (e, t) => `Space "${e}" could not be accessed (received a ${t} response from the Hugging Face API). Check that the Space name is spelled correctly and that the Space exists. If the Space is private, pass a valid Hugging Face token to the \`token\` option of \`Client.connect\`. You can generate a token at https://huggingface.co/settings/tokens.`, se = "No API information is available for this app. This can happen when the app's `/info` endpoint cannot be reached, or when the app is running a legacy version of Gradio that is not supported by this client. ", ce = "This app appears to be running a legacy version of Gradio (3.x or earlier) that communicates over WebSockets, which is not supported by this version of @gradio/client. Please upgrade the app to a newer version of Gradio, or connect to it with @gradio/client version 0.x.", le = "File system access is only available in Node.js environments", O = "Root URL not found in client config", ue = "Error uploading file";
11
+ }) : a, n)), l = "host", u = "queue/data", d = "queue/join", f = "upload", p = "login", m = "config", h = "info", g = "runtime", _ = "sleeptime", v = "heartbeat", ee = "component_server", te = "reset", ne = "cancel", re = "app_id", ie = "This application is currently busy. Please try again. ", y = "Connection errored out. ", b = "Could not resolve app config. ", x = "Could not get space status. ", ae = "Could not get API info. ", S = "Space metadata could not be loaded. ", C = "Invalid URL. A full URL path is required.", w = "Not authorized to access this space. ", T = "Invalid credentials. Could not login. ", oe = "Login credentials are required to access this space.", E = "Could not access this app (received a 401 response). If it is a private Hugging Face Space, pass a valid Hugging Face token to the `token` option of `Client.connect`. You can generate a token at https://huggingface.co/settings/tokens.", se = (e, t) => `Space "${e}" could not be accessed (received a ${t} response from the Hugging Face API). Check that the Space name is spelled correctly and that the Space exists. If the Space is private, pass a valid Hugging Face token to the \`token\` option of \`Client.connect\`. You can generate a token at https://huggingface.co/settings/tokens.`, ce = "No API information is available for this app. This can happen when the app's `/info` endpoint cannot be reached, or when the app is running a legacy version of Gradio that is not supported by this client. ", le = "This app appears to be running a legacy version of Gradio (3.x or earlier) that communicates over WebSockets, which is not supported by this version of @gradio/client. Please upgrade the app to a newer version of Gradio, or connect to it with @gradio/client version 0.x.", ue = "File system access is only available in Node.js environments", de = "Root URL not found in client config", fe = "Error uploading file";
12
12
  //#endregion
13
13
  //#region src/helpers/init_helpers.ts
14
- async function de(e, t, n) {
14
+ async function pe(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 de(e, t, n) {
21
21
  return !1;
22
22
  }
23
23
  }
24
- function k(e) {
24
+ function D(e) {
25
25
  e.hf_token && !e.token && (e.token = e.hf_token, console.warn("The `hf_token` option has been renamed to `token`. Support for `hf_token` will be removed in a future version of @gradio/client."));
26
26
  }
27
- function fe(e) {
27
+ function me(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 O(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 he(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 = I(e, this.deep_link ? m + "?deep_link=" + this.deep_link : m), r = await k(await this.fetch(t, {
42
42
  headers: n,
43
43
  credentials: this.options.credentials ?? "same-origin"
44
44
  }), !!this.options.auth);
@@ -48,9 +48,9 @@ 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 = O(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 = I(e, this.deep_link ? m + "?deep_link=" + this.deep_link : m), r = await k(await this.fetch(t, {
54
54
  headers: n,
55
55
  credentials: this.options.credentials ?? "same-origin"
56
56
  }), !!this.options.auth);
@@ -58,37 +58,37 @@ async function j(e, t = !0) {
58
58
  }
59
59
  throw Error(b);
60
60
  }
61
- async function M(e, t) {
61
+ async function k(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(D);
67
+ throw Error(E);
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(E);
71
+ } else if (e?.status === 401 && t) throw Error(T);
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(T);
77
+ } else if (e?.status === 401) throw Error(w);
78
78
  throw Error(`${b}(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 A() {
81
+ let { http_protocol: e, host: t } = await F(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 j(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 j(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(E) : Error(C);
103
+ throw c.status === 401 ? Error(T) : Error(S);
104
104
  }
105
- function F(e) {
105
+ function M(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 N = (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
+ }, P = /^[a-zA-Z0-9_\-\.]+\/[a-zA-Z0-9_\-\.]+$/, ge = /.*hf\.space\/{0,1}.*$/;
127
+ async function F(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 (P.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(C);
136
+ throw Error(S);
137
137
  }
138
- if (e.status === 401 || e.status === 404) throw Error(oe(r, e.status));
138
+ if (e.status === 401 || e.status === 404) throw Error(se(r, e.status));
139
139
  let t;
140
140
  try {
141
141
  t = (await e.json()).host;
142
142
  } catch {
143
- throw Error(C);
143
+ throw Error(S);
144
144
  }
145
- if (!t) throw Error(C);
145
+ if (!t) throw Error(S);
146
146
  return {
147
147
  space_id: r,
148
- ...F(t)
148
+ ...M(t)
149
149
  };
150
150
  }
151
- if (pe.test(r)) {
152
- let { ws_protocol: e, http_protocol: t, host: n } = F(r);
151
+ if (ge.test(r)) {
152
+ let { ws_protocol: e, http_protocol: t, host: n } = M(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
+ ...M(r)
163
163
  };
164
164
  }
165
- var me = (...e) => {
165
+ var I = (...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(w);
169
+ throw Error(C);
170
170
  }
171
171
  };
172
- function he(e, t, n) {
172
+ function L(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: ve(e?.type, n),
203
+ type: _e(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 _e(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 ve(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 ye(e, t) {
231
231
  switch (e.msg) {
232
232
  case "send_data": return { type: "data" };
233
233
  case "send_hash": return { type: "hash" };
@@ -363,7 +363,7 @@ function ve(e, t) {
363
363
  }
364
364
  };
365
365
  }
366
- var ye = (e = [], t) => {
366
+ var be = (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 xe() {
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, h);
389
+ let i = I(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
393
  }), !e.ok) throw Error(y);
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"]), L(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 R(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;
@@ -429,7 +429,7 @@ async function z(e, t, n) {
429
429
  }
430
430
  return { files: a };
431
431
  }
432
- var B = {
432
+ var z = {
433
433
  si: {
434
434
  radix: 1e3,
435
435
  unit: [
@@ -473,27 +473,30 @@ var B = {
473
473
  ]
474
474
  }
475
475
  };
476
- function V(e, t = 1, n = "jedec") {
476
+ function B(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 } = z[n] || z.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 V(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 ${B(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 U({
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) {
499
+ async function H(e, t) {
497
500
  return e.map((e) => new U({
498
501
  path: e.name,
499
502
  orig_name: e.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
+ }, Se = 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
+ }, Ce = typeof process < "u" && process.versions && process.versions.node;
532
+ function we(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 W(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 W(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,7 +557,7 @@ 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 W(o, void 0, a, !1, i));
558
561
  }
559
562
  return t;
560
563
  }
@@ -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 (Ce) return new Se("upload_file", {
584
587
  path: e,
585
588
  name: e,
586
589
  orig_path: e
@@ -623,7 +626,7 @@ var Oe = /* @__PURE__ */ o(((e, t) => {
623
626
  async function ke(e, t, n) {
624
627
  let r = this;
625
628
  await Ae(r, t);
626
- let i = await we(t, void 0, [], !0, n);
629
+ let i = await W(t, void 0, [], !0, n);
627
630
  return (await Promise.all(i.map(async ({ path: t, blob: n, type: i }) => {
628
631
  if (!n) return {
629
632
  path: t,
@@ -637,35 +640,35 @@ async function ke(e, t, n) {
637
640
  name: typeof File < "u" && n instanceof File ? n?.name : void 0
638
641
  };
639
642
  }))).forEach(({ path: e, file_url: n, type: r, name: i }) => {
640
- r === "Gallery" ? Ce(t, n, e) : n && Ce(t, new U({
643
+ r === "Gallery" ? we(t, n, e) : n && we(t, new U({
641
644
  path: n,
642
645
  orig_name: i
643
646
  }), e);
644
647
  }), t;
645
648
  }
646
649
  async function Ae(e, t) {
647
- if (!(e.config?.root || e.config?.root_url)) throw Error(O);
650
+ if (!(e.config?.root || e.config?.root_url)) throw Error(de);
648
651
  await je(e, t);
649
652
  }
650
653
  async function je(e, t, n = []) {
651
- for (let r in t) t[r] instanceof W ? await Me(e, t, r) : typeof t[r] == "object" && t[r] !== null && await je(e, t[r], [...n, r]);
654
+ for (let r in t) t[r] instanceof Se ? await Me(e, t, r) : typeof t[r] == "object" && t[r] !== null && await je(e, t[r], [...n, r]);
652
655
  }
653
656
  async function Me(e, t, n) {
654
657
  let r = t[n], i = e.config?.root || e.config?.root_url;
655
- if (!i) throw Error(O);
658
+ if (!i) throw Error(de);
656
659
  try {
657
660
  let a, o;
658
661
  if (typeof process < "u" && process.versions && process.versions.node) {
659
662
  let e = await Promise.resolve().then(() => /* @__PURE__ */ c(Oe(), 1));
660
663
  o = (await Promise.resolve().then(() => /* @__PURE__ */ c(Oe(), 1))).resolve(process.cwd(), r.meta.path), a = await e.readFile(o);
661
- } else throw Error(le);
664
+ } else throw Error(ue);
662
665
  let s = new Blob([a], { type: "application/octet-stream" }), l = await e.upload_files(i, [s]), u = l.files && l.files[0];
663
666
  u && (t[n] = new U({
664
667
  path: u,
665
668
  orig_name: r.meta.name || ""
666
669
  }));
667
670
  } catch (e) {
668
- console.error(ue, e);
671
+ console.error(fe, e);
669
672
  }
670
673
  }
671
674
  //#endregion
@@ -799,7 +802,7 @@ async function K(e, t, n) {
799
802
  var Fe = async (e, t) => {
800
803
  let n = 0;
801
804
  return new Promise((r) => {
802
- K(e, L.test(e) ? "space_name" : "subdomain", (i) => {
805
+ K(e, P.test(e) ? "space_name" : "subdomain", (i) => {
803
806
  t(i), i.status === "running" || i.status === "error" || i.status === "paused" || i.status === "space_error" ? r() : (i.status === "sleeping" || i.status === "building") && (n < 12 ? (n++, setTimeout(() => {
804
807
  Fe(e, t).then(r);
805
808
  }, 5e3)) : r());
@@ -831,7 +834,7 @@ async function ze(e, t, n) {
831
834
  n && (r.Authorization = `Bearer ${n}`);
832
835
  let i = { seconds: t };
833
836
  try {
834
- let t = await fetch(`https://huggingface.co/api/spaces/${e}/${ee}`, {
837
+ let t = await fetch(`https://huggingface.co/api/spaces/${e}/${_}`, {
835
838
  method: "POST",
836
839
  headers: {
837
840
  "Content-Type": "application/json",
@@ -863,13 +866,13 @@ var Be = [
863
866
  //#endregion
864
867
  //#region src/utils/duplicate.ts
865
868
  async function Ve(e, t) {
866
- k(t);
869
+ D(t);
867
870
  let { token: n, private: r, hardware: i, timeout: a, auth: o } = t;
868
871
  if (i && !Be.includes(i)) throw Error(`Invalid hardware type provided. Valid types are: ${Be.map((e) => `"${e}"`).join(",")}.`);
869
- let { http_protocol: s, host: c } = await R(e, n), l = null;
872
+ let { http_protocol: s, host: c } = await F(e, n), l = null;
870
873
  if (o) {
871
- let e = await P(s, c, o, fetch, void 0, t.credentials);
872
- e && (l = I(e));
874
+ let e = await j(s, c, o, fetch, void 0, t.credentials);
875
+ e && (l = N(e));
873
876
  }
874
877
  let u = {
875
878
  Authorization: `Bearer ${n}`,
@@ -881,7 +884,7 @@ async function Ve(e, t) {
881
884
  try {
882
885
  i || (m = await Re(e, n));
883
886
  } catch (e) {
884
- throw Error(C + e.message);
887
+ throw Error(S + e.message);
885
888
  }
886
889
  p.hardware = i || m || "cpu-basic";
887
890
  try {
@@ -1103,7 +1106,7 @@ function at(e, t = {}) {
1103
1106
  }
1104
1107
  //#endregion
1105
1108
  //#region src/utils/run_history.ts
1106
- var ot = "gradio:run-history:", q = `${ot}v2:`, st = `${ot}replay:v2:`, ct = 100, lt = 8;
1109
+ var ot = "gradio:run-history:", q = `${ot}v2:`, st = `${ot}replay:v2:`, ct = `${ot}destination:v1:`, lt = 100, ut = 8;
1107
1110
  function J(e, t) {
1108
1111
  try {
1109
1112
  return e();
@@ -1111,7 +1114,7 @@ function J(e, t) {
1111
1114
  return console.warn("Could not update the run history.", e), t;
1112
1115
  }
1113
1116
  }
1114
- function ut(e, t = "/gradio_api") {
1117
+ function dt(e, t = "/gradio_api") {
1115
1118
  return `${e.replace(/\/+$/, "")}${t}/runs`;
1116
1119
  }
1117
1120
  function Y(e) {
@@ -1124,11 +1127,35 @@ function Y(e) {
1124
1127
  return null;
1125
1128
  }
1126
1129
  }
1127
- function dt(e) {
1130
+ function ft(e) {
1128
1131
  let t = Y(e);
1129
1132
  return t ? t.replace(q, st) : null;
1130
1133
  }
1131
- function ft(e) {
1134
+ function pt(e) {
1135
+ let t = Y(e);
1136
+ return t ? t.replace(q, ct) : null;
1137
+ }
1138
+ function mt(e) {
1139
+ let t = pt(e);
1140
+ if (!t) return { type: "browser" };
1141
+ try {
1142
+ let e = JSON.parse(window.localStorage.getItem(t) || "null");
1143
+ return typeof e?.bucket_id == "string" ? e.type === "bucket" ? {
1144
+ type: "bucket",
1145
+ bucket_id: e.bucket_id
1146
+ } : {
1147
+ type: "browser",
1148
+ bucket_id: e.bucket_id
1149
+ } : { type: "browser" };
1150
+ } catch {
1151
+ return { type: "browser" };
1152
+ }
1153
+ }
1154
+ function ht(e, t) {
1155
+ let n = pt(e);
1156
+ n && (t.type === "browser" && !t.bucket_id ? window.localStorage.removeItem(n) : window.localStorage.setItem(n, JSON.stringify(t)), Ct());
1157
+ }
1158
+ function gt(e) {
1132
1159
  try {
1133
1160
  let t = JSON.parse(window.localStorage.getItem(e) || "[]");
1134
1161
  return Array.isArray(t) && t.length && Date.parse(t[0]?.started_at) || 0;
@@ -1136,13 +1163,13 @@ function ft(e) {
1136
1163
  return 0;
1137
1164
  }
1138
1165
  }
1139
- function pt(e) {
1140
- let t = Object.keys(window.localStorage).filter((e) => e.startsWith(ot)), n = [...t.filter((e) => !e.startsWith(q) && !e.startsWith(st)), ...t.filter((t) => t.startsWith(q) && t !== e).sort((e, t) => ft(t) - ft(e)).slice(lt - 1)];
1166
+ function _t(e) {
1167
+ let t = Object.keys(window.localStorage).filter((e) => e.startsWith(ot)), n = [...t.filter((e) => !e.startsWith(q) && !e.startsWith(st) && !e.startsWith(ct)), ...t.filter((t) => t.startsWith(q) && t !== e).sort((e, t) => gt(t) - gt(e)).slice(ut - 1)];
1141
1168
  for (let e of n) try {
1142
1169
  window.localStorage.removeItem(e), window.sessionStorage.removeItem(e.replace(q, st));
1143
1170
  } catch {}
1144
1171
  }
1145
- function mt() {
1172
+ function vt() {
1146
1173
  return typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(36).slice(2)}`;
1147
1174
  }
1148
1175
  function X(e) {
@@ -1170,16 +1197,16 @@ function Z(e) {
1170
1197
  return [];
1171
1198
  }
1172
1199
  }
1173
- function ht(e, t) {
1200
+ function yt(e, t) {
1174
1201
  let n = Y(e);
1175
1202
  if (!n) return;
1176
- let r = t.slice(0, ct), i = !1;
1203
+ let r = t.slice(0, lt), i = !1;
1177
1204
  for (; r.length > 0;) try {
1178
1205
  window.localStorage.setItem(n, JSON.stringify(r));
1179
1206
  return;
1180
1207
  } catch {
1181
1208
  if (!i) {
1182
- i = !0, pt(n);
1209
+ i = !0, _t(n);
1183
1210
  continue;
1184
1211
  }
1185
1212
  r = r.slice(0, -1);
@@ -1188,37 +1215,37 @@ function ht(e, t) {
1188
1215
  window.localStorage.removeItem(n);
1189
1216
  } catch {}
1190
1217
  }
1191
- function gt(e) {
1218
+ function bt(e) {
1192
1219
  let t = Y(e);
1193
1220
  if (t) {
1194
1221
  try {
1195
1222
  window.localStorage.removeItem(t);
1196
1223
  } catch {}
1197
- yt();
1224
+ Ct();
1198
1225
  }
1199
1226
  }
1200
- function _t(e, t) {
1201
- ht(e, Z(e).filter((e) => e.id !== t)), yt();
1227
+ function xt(e, t) {
1228
+ yt(e, Z(e).filter((e) => e.id !== t)), Ct();
1202
1229
  }
1203
- var vt = "gradio:run-history-change";
1204
- function yt() {
1230
+ var St = "gradio:run-history-change";
1231
+ function Ct() {
1205
1232
  if (!(typeof window > "u")) try {
1206
- window.dispatchEvent(new Event(vt));
1233
+ window.dispatchEvent(new Event(St));
1207
1234
  } catch {}
1208
1235
  }
1209
- function bt(e) {
1210
- return typeof window > "u" ? () => {} : (window.addEventListener(vt, e), window.addEventListener("storage", e), () => {
1211
- window.removeEventListener(vt, e), window.removeEventListener("storage", e);
1236
+ function wt(e) {
1237
+ return typeof window > "u" ? () => {} : (window.addEventListener(St, e), window.addEventListener("storage", e), () => {
1238
+ window.removeEventListener(St, e), window.removeEventListener("storage", e);
1212
1239
  });
1213
1240
  }
1214
- function xt(e, t) {
1215
- let n = dt(e);
1241
+ function Tt(e, t) {
1242
+ let n = ft(e);
1216
1243
  if (n) try {
1217
1244
  window.sessionStorage.setItem(n, JSON.stringify(t));
1218
1245
  } catch {}
1219
1246
  }
1220
- function St(e) {
1221
- let t = dt(e);
1247
+ function Et(e) {
1248
+ let t = ft(e);
1222
1249
  if (!t) return null;
1223
1250
  try {
1224
1251
  let e = window.sessionStorage.getItem(t);
@@ -1227,7 +1254,7 @@ function St(e) {
1227
1254
  return null;
1228
1255
  }
1229
1256
  }
1230
- function Ct(e, t) {
1257
+ function Dt(e, t) {
1231
1258
  let n = e.dependencies.find((e) => e.id === t.fn_index || typeof e.api_name == "string" && `/${e.api_name.replace(/^\//, "")}` === t.api_name);
1232
1259
  if (!n) return !1;
1233
1260
  let r = Array.isArray(t.inputs) ? t.inputs : Object.values(t.inputs ?? {}), i = Array.isArray(t.outputs) ? t.outputs : t.outputs === null || t.outputs === void 0 ? [] : [t.outputs], a = (t, n) => {
@@ -1238,16 +1265,17 @@ function Ct(e, t) {
1238
1265
  };
1239
1266
  return a(n.inputs, r), a(n.outputs, i), !0;
1240
1267
  }
1241
- function wt(e) {
1242
- let t = St(e);
1243
- return t ? Ct(e, t) : !1;
1268
+ function Ot(e) {
1269
+ let t = Et(e);
1270
+ return t ? Dt(e, t) : !1;
1244
1271
  }
1245
- function Tt(e) {
1272
+ function kt(e) {
1273
+ if (mt(e).type === "bucket") return null;
1246
1274
  let t = Y(e);
1247
1275
  if (!t) return null;
1248
- pt(t);
1276
+ _t(t);
1249
1277
  let n = {
1250
- id: mt(),
1278
+ id: vt(),
1251
1279
  endpoint: e.endpoint,
1252
1280
  api_name: e.api_name,
1253
1281
  fn_index: e.fn_index,
@@ -1259,116 +1287,125 @@ function Tt(e) {
1259
1287
  status: "running",
1260
1288
  started_at: (/* @__PURE__ */ new Date()).toISOString()
1261
1289
  };
1262
- return ht(e, [n, ...Z(e)]), yt(), n.id;
1290
+ return yt(e, [n, ...Z(e)]), Ct(), n.id;
1263
1291
  }
1264
- function Et(e, t, n) {
1292
+ function At(e, t, n) {
1265
1293
  if (!t) return;
1266
1294
  let r = Z(e), i = r.find((e) => e.id === t);
1267
- i && (i.inputs = X(n), ht(e, r));
1295
+ i && (i.inputs = X(n), yt(e, r));
1268
1296
  }
1269
- function Dt(e, t, n) {
1297
+ function jt(e, t, n) {
1270
1298
  if (!t) return;
1271
1299
  let r = Z(e), i = r.find((e) => e.id === t);
1272
1300
  if (!i) return;
1273
1301
  let a = !1;
1274
1302
  if (n.type === "data") i.outputs = X(n.data), Q.set(t, i.outputs);
1275
- else if (n.type === "status" && n.original_msg === "process_starts") At(i, n.time);
1303
+ else if (n.type === "status" && n.original_msg === "process_starts") Pt(i, n.time);
1276
1304
  else if (n.type === "status" && (n.stage === "generating" || n.stage === "streaming")) i.streamed = !0;
1277
- else if (n.type === "status" && n.stage === "complete") i.status = "completed", jt(i, n), a = !0;
1278
- else if (n.type === "status" && n.stage === "error") i.status = "failed", i.error = typeof n.message == "string" ? n.message : JSON.stringify(n.message || "Unknown error"), jt(i, n), a = !0;
1305
+ else if (n.type === "status" && n.stage === "complete") i.status = "completed", Ft(i, n), a = !0;
1306
+ else if (n.type === "status" && n.stage === "error") i.status = "failed", i.error = typeof n.message == "string" ? n.message : JSON.stringify(n.message || "Unknown error"), Ft(i, n), a = !0;
1279
1307
  else return;
1280
- if (a) Q.has(t) && (i.outputs = Q.get(t)), Q.delete(t), kt.delete(t);
1308
+ if (a) Q.has(t) && (i.outputs = Q.get(t)), Q.delete(t), Nt.delete(t);
1281
1309
  else if (i.streamed) {
1282
- if (Date.now() - (kt.get(t) ?? 0) < Ot) return;
1283
- kt.set(t, Date.now()), Q.delete(t);
1310
+ if (Date.now() - (Nt.get(t) ?? 0) < Mt) return;
1311
+ Nt.set(t, Date.now()), Q.delete(t);
1284
1312
  }
1285
- ht(e, r);
1313
+ yt(e, r);
1286
1314
  }
1287
- var Ot = 500, kt = /* @__PURE__ */ new Map(), Q = /* @__PURE__ */ new Map();
1288
- function At(e, t) {
1315
+ var Mt = 500, Nt = /* @__PURE__ */ new Map(), Q = /* @__PURE__ */ new Map();
1316
+ function Pt(e, t) {
1289
1317
  if (e.process_started_at) return;
1290
1318
  let n = t || /* @__PURE__ */ new Date();
1291
1319
  e.process_started_at = n.toISOString(), e.queued_ms = Math.max(0, n.getTime() - Date.parse(e.started_at));
1292
1320
  }
1293
- function jt(e, t) {
1321
+ function Ft(e, t) {
1294
1322
  let n = t.time || /* @__PURE__ */ new Date();
1295
1323
  e.completed_at = n.toISOString(), e.duration_ms = (!e.streamed && typeof t.cache_duration == "number" && t.cache_duration >= 0 ? t.cache_duration * 1e3 : null) ?? Math.max(0, n.getTime() - Date.parse(e.process_started_at || e.started_at));
1296
1324
  }
1297
- function Mt(e) {
1325
+ function It(e) {
1298
1326
  return J(() => Z(e), []);
1299
1327
  }
1300
- function Nt(e) {
1301
- J(() => gt(e), void 0);
1328
+ function Lt(e) {
1329
+ return J(() => mt(e), { type: "browser" });
1302
1330
  }
1303
- function Pt(e, t) {
1304
- J(() => _t(e, t), void 0);
1331
+ function Rt(e, t) {
1332
+ J(() => ht(e, t), void 0);
1305
1333
  }
1306
- function Ft(e, t) {
1334
+ function zt(e) {
1335
+ J(() => bt(e), void 0);
1336
+ }
1337
+ function Bt(e, t) {
1307
1338
  J(() => xt(e, t), void 0);
1308
1339
  }
1309
- function It(e) {
1310
- return J(() => St(e), null);
1340
+ function Vt(e, t) {
1341
+ J(() => Tt(e, t), void 0);
1311
1342
  }
1312
- function Lt(e) {
1313
- return J(() => wt(e), !1);
1343
+ function Ht(e) {
1344
+ return J(() => Et(e), null);
1314
1345
  }
1315
- function Rt(e) {
1316
- return J(() => Tt(e), null);
1346
+ function Ut(e) {
1347
+ return J(() => Ot(e), !1);
1317
1348
  }
1318
- function zt(e, t, n) {
1319
- J(() => Et(e, t, n), void 0);
1349
+ function Wt(e) {
1350
+ return J(() => kt(e), null);
1320
1351
  }
1321
- function Bt(e, t, n) {
1322
- J(() => Dt(e, t, n), void 0);
1352
+ function Gt(e, t, n) {
1353
+ J(() => At(e, t, n), void 0);
1323
1354
  }
1324
- function Vt(e) {
1325
- return J(() => bt(() => J(e, void 0)), () => {});
1355
+ function Kt(e, t, n) {
1356
+ J(() => jt(e, t, n), void 0);
1357
+ }
1358
+ function qt(e) {
1359
+ return J(() => wt(() => J(e, void 0)), () => {});
1326
1360
  }
1327
1361
  //#endregion
1328
1362
  //#region src/utils/submit.ts
1329
- function Ht(e, t = {}, n, r, i, a) {
1363
+ function Jt(e, t = {}, n, r, i, a) {
1330
1364
  try {
1331
- let { token: o } = this.options, { fetch: s, app_reference: c, config: l, session_hash: f, api_info: p, api_map: m, stream_status: h, pending_stream_messages: g, pending_diff_streams: ee, event_callbacks: _, unclosed_events: te, post_data: v, options: b, api_prefix: x } = this, S = a || { "x-gradio-user": "api" }, C = this;
1332
- if (!p) throw Error(se);
1365
+ let { token: o } = this.options, { fetch: s, app_reference: c, config: l, session_hash: f, api_info: p, api_map: m, stream_status: h, pending_stream_messages: g, pending_diff_streams: _, event_callbacks: v, unclosed_events: ee, post_data: re, options: b, api_prefix: x } = this, ae = a || { "x-gradio-user": "api" }, S = this;
1366
+ if (!p) throw Error(ce);
1333
1367
  if (!l) throw Error("Could not resolve app config");
1334
- let { fn_index: w, endpoint_info: T, dependency: E } = Wt(p, e, m, l), ae = ye(t, T), D = l.protocol ?? "ws";
1335
- if (D === "ws") throw Error(ce);
1336
- let oe = typeof E.api_name == "string" ? `/${E.api_name}` : e, le = typeof E.api_name == "string" ? `/${E.api_name}` : `Function ${w}`, O = (e) => {
1368
+ let { fn_index: C, endpoint_info: w, dependency: T } = Xt(p, e, m, l), oe = be(t, w), E = l.protocol ?? "ws";
1369
+ if (E === "ws") throw Error(le);
1370
+ let se = typeof T.api_name == "string" ? `/${T.api_name}` : e, ue = typeof T.api_name == "string" ? `/${T.api_name}` : `Function ${C}`, de = (e) => {
1337
1371
  let t = l.components.find((t) => t.id === e);
1338
1372
  return t ? {
1339
1373
  type: t.type,
1340
1374
  component_class_id: t.component_class_id,
1341
1375
  props: t.props
1342
1376
  } : null;
1343
- }, ue = E.api_visibility === "public", de = l.run_history !== !1 && this.options.record_history !== !1, k = {
1377
+ }, fe = T.api_visibility === "public", pe = l.run_history !== !1 && this.options.record_history !== !1, D = {
1344
1378
  app_id: l.app_id,
1345
1379
  username: l.username
1346
- }, fe = !de || !ue ? null : Rt({
1347
- ...k,
1348
- endpoint: oe,
1349
- api_name: le,
1350
- fn_index: w,
1351
- inputs: G(ae, E, l.components, "input", !0),
1352
- input_components: E.inputs.map(O),
1353
- output_components: E.outputs.map(O)
1354
- }), A, j = "", M = typeof e == "number" ? "/predict" : e, N, P = null, F = !1, I = {}, L = typeof window < "u" && typeof document < "u" ? new URLSearchParams(window.location.search).toString() : "", pe = b?.events?.reduce((e, t) => (e[t] = !0, e), {}) || {};
1355
- function R(e) {
1356
- Bt(k, fe, e), (i || pe[e.type]) && U(e);
1380
+ }, me = Lt(D), O = {
1381
+ ...ae,
1382
+ ...pe && me.type === "bucket" ? { "x-gradio-history-bucket": me.bucket_id } : {}
1383
+ }, he = !pe || !fe ? null : Wt({
1384
+ ...D,
1385
+ endpoint: se,
1386
+ api_name: ue,
1387
+ fn_index: C,
1388
+ inputs: G(oe, T, l.components, "input", !0),
1389
+ input_components: T.inputs.map(de),
1390
+ output_components: T.outputs.map(de)
1391
+ }), k, A = "", j = typeof e == "number" ? "/predict" : e, M, N = null, P = !1, ge = {}, F = typeof window < "u" && typeof document < "u" ? new URLSearchParams(window.location.search).toString() : "", I = b?.events?.reduce((e, t) => (e[t] = !0, e), {}) || {};
1392
+ function L(e) {
1393
+ Kt(D, he, e), (i || I[e.type]) && Ce(e);
1357
1394
  }
1358
- async function me() {
1395
+ async function _e() {
1359
1396
  let e = {}, t = {};
1360
- e = { event_id: P }, t = {
1361
- event_id: P,
1397
+ e = { event_id: N }, t = {
1398
+ event_id: N,
1362
1399
  session_hash: f,
1363
- fn_index: w
1400
+ fn_index: C
1364
1401
  };
1365
1402
  try {
1366
1403
  if (!l) throw Error("Could not resolve app config");
1367
- "event_id" in t && await s(`${l.root}${x}/${re}`, {
1404
+ "event_id" in t && await s(`${l.root}${x}/${ne}`, {
1368
1405
  headers: { "Content-Type": "application/json" },
1369
1406
  method: "POST",
1370
1407
  body: JSON.stringify(t)
1371
- }), await s(`${l.root}${x}/${ne}`, {
1408
+ }), await s(`${l.root}${x}/${te}`, {
1372
1409
  headers: { "Content-Type": "application/json" },
1373
1410
  method: "POST",
1374
1411
  body: JSON.stringify(e)
@@ -1377,53 +1414,53 @@ function Ht(e, t = {}, n, r, i, a) {
1377
1414
  console.warn("The `/reset` endpoint could not be called. Subsequent endpoint results may be unreliable.");
1378
1415
  }
1379
1416
  }
1380
- let he = async (e) => {
1417
+ let ve = async (e) => {
1381
1418
  await this._resolve_heartbeat(e);
1382
1419
  };
1383
- async function ge(e) {
1420
+ async function xe(e) {
1384
1421
  if (!l) return;
1385
1422
  let t = e.render_id;
1386
1423
  l.components = [...l.components.filter((e) => e.props.rendered_in !== t), ...e.components], l.dependencies = [...l.dependencies.filter((e) => e.rendered_in !== t), ...e.dependencies];
1387
1424
  let n = l.components.some((e) => e.type === "state"), r = l.dependencies.some((e) => e.targets.some((e) => e[1] === "unload"));
1388
- l.connect_heartbeat = n || r, await he(l), R({
1425
+ l.connect_heartbeat = n || r, await ve(l), L({
1389
1426
  type: "render",
1390
1427
  data: e,
1391
- endpoint: M,
1392
- fn_index: w
1428
+ endpoint: j,
1429
+ fn_index: C
1393
1430
  });
1394
1431
  }
1395
- let _e = this.handle_blob(l.root, ae, T).then(async (e) => {
1396
- let t = G(e, E, l.components, "input", !0);
1397
- if (zt(k, fe, t || []), N = {
1432
+ let R = this.handle_blob(l.root, oe, w).then(async (e) => {
1433
+ let t = G(e, T, l.components, "input", !0);
1434
+ if (Gt(D, he, t || []), M = {
1398
1435
  data: t || [],
1399
1436
  event_data: n,
1400
- fn_index: w,
1437
+ fn_index: C,
1401
1438
  trigger_id: r,
1402
- ...b.oauth_token && T?.oauth_token ? { oauth_token: b.oauth_token } : {}
1403
- }, Te(w, l)) R({
1439
+ ...b.oauth_token && w?.oauth_token ? { oauth_token: b.oauth_token } : {}
1440
+ }, Te(C, l)) L({
1404
1441
  type: "status",
1405
- endpoint: M,
1442
+ endpoint: j,
1406
1443
  stage: "pending",
1407
1444
  queue: !1,
1408
- fn_index: w,
1445
+ fn_index: C,
1409
1446
  time: /* @__PURE__ */ new Date()
1410
- }), v(`${l.root}${x}/run${M.startsWith("/") ? M : `/${M}`}${L ? "?" + L : ""}`, {
1411
- ...N,
1447
+ }), re(`${l.root}${x}/run${j.startsWith("/") ? j : `/${j}`}${F ? "?" + F : ""}`, {
1448
+ ...M,
1412
1449
  session_hash: f
1413
- }, S).then(async ([e, t]) => {
1450
+ }, O).then(async ([e, t]) => {
1414
1451
  let i = e.data;
1415
- if (t == 200) R({
1452
+ if (t == 200) L({
1416
1453
  type: "data",
1417
- endpoint: M,
1418
- fn_index: w,
1419
- data: G(i, E, l.components, "output", b.with_null_state),
1454
+ endpoint: j,
1455
+ fn_index: C,
1456
+ data: G(i, T, l.components, "output", b.with_null_state),
1420
1457
  time: /* @__PURE__ */ new Date(),
1421
1458
  event_data: n,
1422
1459
  trigger_id: r
1423
- }), e.render_config && await ge(e.render_config), R({
1460
+ }), e.render_config && await xe(e.render_config), L({
1424
1461
  type: "status",
1425
- endpoint: M,
1426
- fn_index: w,
1462
+ endpoint: j,
1463
+ fn_index: C,
1427
1464
  stage: "complete",
1428
1465
  eta: e.average_duration,
1429
1466
  queue: !1,
@@ -1431,11 +1468,11 @@ function Ht(e, t = {}, n, r, i, a) {
1431
1468
  });
1432
1469
  else {
1433
1470
  let t = e?.error === y;
1434
- R({
1471
+ L({
1435
1472
  type: "status",
1436
1473
  stage: "error",
1437
- endpoint: M,
1438
- fn_index: w,
1474
+ endpoint: j,
1475
+ fn_index: C,
1439
1476
  message: e.error,
1440
1477
  broken: t,
1441
1478
  queue: !1,
@@ -1443,98 +1480,98 @@ function Ht(e, t = {}, n, r, i, a) {
1443
1480
  });
1444
1481
  }
1445
1482
  }).catch((e) => {
1446
- R({
1483
+ L({
1447
1484
  type: "status",
1448
1485
  stage: "error",
1449
1486
  message: e.message,
1450
- endpoint: M,
1451
- fn_index: w,
1487
+ endpoint: j,
1488
+ fn_index: C,
1452
1489
  queue: !1,
1453
1490
  time: /* @__PURE__ */ new Date()
1454
1491
  });
1455
1492
  });
1456
- else if (D == "sse") {
1457
- R({
1493
+ else if (E == "sse") {
1494
+ L({
1458
1495
  type: "status",
1459
1496
  stage: "pending",
1460
1497
  queue: !0,
1461
- endpoint: M,
1462
- fn_index: w,
1498
+ endpoint: j,
1499
+ fn_index: C,
1463
1500
  time: /* @__PURE__ */ new Date()
1464
1501
  });
1465
1502
  var i = new URLSearchParams({
1466
- fn_index: w.toString(),
1503
+ fn_index: C.toString(),
1467
1504
  session_hash: f
1468
1505
  }).toString();
1469
- let e = new URL(`${l.root}${x}/${u}?${L ? L + "&" : ""}${i}`);
1470
- if (this.jwt && e.searchParams.set("__sign", this.jwt), A = this.stream(e), !A) return Promise.reject(/* @__PURE__ */ Error("Cannot connect to SSE endpoint: " + e.toString()));
1471
- A.onmessage = async function(e) {
1472
- let { type: t, status: i, data: a } = ve(JSON.parse(e.data), I[w]);
1473
- if (t === "update" && i && !F) R({
1506
+ let e = new URL(`${l.root}${x}/${u}?${F ? F + "&" : ""}${i}`);
1507
+ if (this.jwt && e.searchParams.set("__sign", this.jwt), k = this.stream(e), !k) return Promise.reject(/* @__PURE__ */ Error("Cannot connect to SSE endpoint: " + e.toString()));
1508
+ k.onmessage = async function(e) {
1509
+ let { type: t, status: i, data: a } = ye(JSON.parse(e.data), ge[C]);
1510
+ if (t === "update" && i && !P) L({
1474
1511
  type: "status",
1475
- endpoint: M,
1476
- fn_index: w,
1512
+ endpoint: j,
1513
+ fn_index: C,
1477
1514
  time: /* @__PURE__ */ new Date(),
1478
1515
  ...i
1479
- }), i.stage === "error" && (A?.close(), V());
1516
+ }), i.stage === "error" && (k?.close(), H());
1480
1517
  else if (t === "data") {
1481
- let [e, t] = await v(`${l.root}${x}/queue/data`, {
1482
- ...N,
1518
+ let [e, t] = await re(`${l.root}${x}/queue/data`, {
1519
+ ...M,
1483
1520
  session_hash: f,
1484
- event_id: P
1485
- });
1486
- t !== 200 && (R({
1521
+ event_id: N
1522
+ }, O);
1523
+ t !== 200 && (L({
1487
1524
  type: "status",
1488
1525
  stage: "error",
1489
1526
  message: y,
1490
1527
  queue: !0,
1491
- endpoint: M,
1492
- fn_index: w,
1528
+ endpoint: j,
1529
+ fn_index: C,
1493
1530
  time: /* @__PURE__ */ new Date()
1494
- }), A?.close(), V());
1495
- } else t === "complete" ? F = i : t === "log" ? R({
1531
+ }), k?.close(), H());
1532
+ } else t === "complete" ? P = i : t === "log" ? L({
1496
1533
  type: "log",
1497
1534
  title: a.title,
1498
1535
  log: a.log,
1499
1536
  level: a.level,
1500
- endpoint: M,
1537
+ endpoint: j,
1501
1538
  duration: a.duration,
1502
1539
  visible: a.visible,
1503
- fn_index: w
1504
- }) : (t === "generating" || t === "streaming") && R({
1540
+ fn_index: C
1541
+ }) : (t === "generating" || t === "streaming") && L({
1505
1542
  type: "status",
1506
1543
  time: /* @__PURE__ */ new Date(),
1507
1544
  ...i,
1508
1545
  stage: i?.stage,
1509
1546
  queue: !0,
1510
- endpoint: M,
1511
- fn_index: w
1547
+ endpoint: j,
1548
+ fn_index: C
1512
1549
  });
1513
- a && (R({
1550
+ a && (L({
1514
1551
  type: "data",
1515
1552
  time: /* @__PURE__ */ new Date(),
1516
- data: G(a.data, E, l.components, "output", b.with_null_state),
1517
- endpoint: M,
1518
- fn_index: w,
1553
+ data: G(a.data, T, l.components, "output", b.with_null_state),
1554
+ endpoint: j,
1555
+ fn_index: C,
1519
1556
  event_data: n,
1520
1557
  trigger_id: r
1521
- }), F && (R({
1558
+ }), P && (L({
1522
1559
  type: "status",
1523
1560
  time: /* @__PURE__ */ new Date(),
1524
- ...F,
1561
+ ...P,
1525
1562
  stage: i?.stage,
1526
1563
  queue: !0,
1527
- endpoint: M,
1528
- fn_index: w
1529
- }), A?.close(), V()));
1564
+ endpoint: j,
1565
+ fn_index: C
1566
+ }), k?.close(), H()));
1530
1567
  };
1531
- } else if (D == "sse_v1" || D == "sse_v2" || D == "sse_v2.1" || D == "sse_v3") {
1532
- R({
1568
+ } else if (E == "sse_v1" || E == "sse_v2" || E == "sse_v2.1" || E == "sse_v3") {
1569
+ L({
1533
1570
  type: "status",
1534
1571
  stage: "pending",
1535
1572
  queue: !0,
1536
- endpoint: M,
1537
- fn_index: w,
1573
+ endpoint: j,
1574
+ fn_index: C,
1538
1575
  time: /* @__PURE__ */ new Date()
1539
1576
  });
1540
1577
  let e = "";
@@ -1542,204 +1579,204 @@ function Ht(e, t = {}, n, r, i, a) {
1542
1579
  let t = Ke(e);
1543
1580
  return (typeof window < "u" && typeof document < "u" && window.parent != window && t && window.supports_zerogpu_headers ? Ee("zerogpu-headers", t) : Promise.resolve(null)).then((e) => {
1544
1581
  let t = {
1545
- ...S,
1582
+ ...O,
1546
1583
  ...e || {}
1547
1584
  };
1548
- return v(`${l.root}${x}/${d}?${L}`, {
1549
- ...N,
1585
+ return re(`${l.root}${x}/${d}?${F}`, {
1586
+ ...M,
1550
1587
  session_hash: f
1551
1588
  }, t);
1552
1589
  }).then(async ([e, t]) => {
1553
- if (e.event_id && (j = e.event_id), t === 503) R({
1590
+ if (e.event_id && (A = e.event_id), t === 503) L({
1554
1591
  type: "status",
1555
1592
  stage: "error",
1556
1593
  message: ie,
1557
1594
  queue: !0,
1558
- endpoint: M,
1559
- fn_index: w,
1595
+ endpoint: j,
1596
+ fn_index: C,
1560
1597
  time: /* @__PURE__ */ new Date(),
1561
1598
  visible: !0
1562
- }), V();
1563
- else if (t === 422) R({
1599
+ }), H();
1600
+ else if (t === 422) L({
1564
1601
  type: "status",
1565
1602
  stage: "error",
1566
1603
  message: e.detail,
1567
1604
  queue: !0,
1568
- endpoint: M,
1569
- fn_index: w,
1605
+ endpoint: j,
1606
+ fn_index: C,
1570
1607
  code: "validation_error",
1571
1608
  time: /* @__PURE__ */ new Date(),
1572
1609
  visible: !0
1573
- }), V();
1610
+ }), H();
1574
1611
  else if (t !== 200) {
1575
1612
  let t = e?.error === y;
1576
- R({
1613
+ L({
1577
1614
  type: "status",
1578
1615
  stage: "error",
1579
1616
  broken: t,
1580
1617
  message: t ? y : e.detail || e.error,
1581
1618
  queue: !0,
1582
- endpoint: M,
1583
- fn_index: w,
1619
+ endpoint: j,
1620
+ fn_index: C,
1584
1621
  time: /* @__PURE__ */ new Date(),
1585
1622
  visible: !0
1586
- }), V();
1623
+ }), H();
1587
1624
  } else {
1588
- P = e.event_id, j = P;
1625
+ N = e.event_id, A = N;
1589
1626
  let t = async function(e) {
1590
1627
  try {
1591
- let { type: t, status: n, data: r, original_msg: i } = ve(e, I[w]);
1628
+ let { type: t, status: n, data: r, original_msg: i } = ye(e, ge[C]);
1592
1629
  if (t == "heartbeat") return;
1593
- if (t === "update" && n && !F) R({
1630
+ if (t === "update" && n && !P) L({
1594
1631
  type: "status",
1595
- endpoint: M,
1596
- fn_index: w,
1632
+ endpoint: j,
1633
+ fn_index: C,
1597
1634
  time: /* @__PURE__ */ new Date(),
1598
1635
  original_msg: i,
1599
1636
  ...n
1600
1637
  });
1601
- else if (t === "complete") F = n;
1638
+ else if (t === "complete") P = n;
1602
1639
  else if (t == "unexpected_error" || t == "broken_connection") {
1603
1640
  console.error("Unexpected error", n?.message);
1604
1641
  let e = t === "broken_connection";
1605
- R({
1642
+ L({
1606
1643
  type: "status",
1607
1644
  stage: "error",
1608
1645
  message: n?.message || "An Unexpected Error Occurred!",
1609
1646
  queue: !0,
1610
- endpoint: M,
1647
+ endpoint: j,
1611
1648
  broken: e,
1612
1649
  session_not_found: n?.session_not_found,
1613
- fn_index: w,
1650
+ fn_index: C,
1614
1651
  time: /* @__PURE__ */ new Date()
1615
1652
  });
1616
1653
  } else if (t === "log") {
1617
- R({
1654
+ L({
1618
1655
  type: "log",
1619
1656
  title: r.title,
1620
1657
  log: r.log,
1621
1658
  level: r.level,
1622
- endpoint: M,
1659
+ endpoint: j,
1623
1660
  duration: r.duration,
1624
1661
  visible: r.visible,
1625
- fn_index: w
1662
+ fn_index: C
1626
1663
  });
1627
1664
  return;
1628
- } else (t === "generating" || t === "streaming") && (R({
1665
+ } else (t === "generating" || t === "streaming") && (L({
1629
1666
  type: "status",
1630
1667
  time: /* @__PURE__ */ new Date(),
1631
1668
  ...n,
1632
1669
  stage: n?.stage,
1633
1670
  queue: !0,
1634
- endpoint: M,
1635
- fn_index: w
1636
- }), r && E.connection !== "stream" && [
1671
+ endpoint: j,
1672
+ fn_index: C
1673
+ }), r && T.connection !== "stream" && [
1637
1674
  "sse_v2",
1638
1675
  "sse_v2.1",
1639
1676
  "sse_v3"
1640
- ].includes(D) && nt(ee, P, r));
1641
- r && (R({
1677
+ ].includes(E) && nt(_, N, r));
1678
+ r && (L({
1642
1679
  type: "data",
1643
1680
  time: /* @__PURE__ */ new Date(),
1644
- data: G(r.data, E, l.components, "output", b.with_null_state),
1645
- endpoint: M,
1646
- fn_index: w
1647
- }), r.render_config && await ge(r.render_config), F && (R({
1681
+ data: G(r.data, T, l.components, "output", b.with_null_state),
1682
+ endpoint: j,
1683
+ fn_index: C
1684
+ }), r.render_config && await xe(r.render_config), P && (L({
1648
1685
  type: "status",
1649
1686
  time: /* @__PURE__ */ new Date(),
1650
- ...F,
1687
+ ...P,
1651
1688
  stage: n?.stage,
1652
1689
  queue: !0,
1653
- endpoint: M,
1654
- fn_index: w
1655
- }), V())), (n?.stage === "complete" || n?.stage === "error") && (_[P] && delete _[P], P in ee && delete ee[P], V());
1690
+ endpoint: j,
1691
+ fn_index: C
1692
+ }), H())), (n?.stage === "complete" || n?.stage === "error") && (v[N] && delete v[N], N in _ && delete _[N], H());
1656
1693
  } catch (e) {
1657
- console.error("Unexpected client exception", e), R({
1694
+ console.error("Unexpected client exception", e), L({
1658
1695
  type: "status",
1659
1696
  stage: "error",
1660
1697
  message: "An Unexpected Error Occurred!",
1661
1698
  queue: !0,
1662
- endpoint: M,
1663
- fn_index: w,
1699
+ endpoint: j,
1700
+ fn_index: C,
1664
1701
  time: /* @__PURE__ */ new Date()
1665
1702
  }), [
1666
1703
  "sse_v2",
1667
1704
  "sse_v2.1",
1668
1705
  "sse_v3"
1669
- ].includes(D) && (tt(h, C.abort_controller), h.open = !1, V());
1706
+ ].includes(E) && (tt(h, S.abort_controller), h.open = !1, H());
1670
1707
  }
1671
1708
  };
1672
- P in g && (g[P].forEach((e) => t(e)), delete g[P]), _[P] = t, te.add(P), h.open || await this.open_stream();
1709
+ N in g && (g[N].forEach((e) => t(e)), delete g[N]), v[N] = t, ee.add(N), h.open || await this.open_stream();
1673
1710
  }
1674
1711
  });
1675
1712
  }
1676
1713
  });
1677
- _e.catch((e) => {
1678
- R({
1714
+ R.catch((e) => {
1715
+ L({
1679
1716
  type: "status",
1680
1717
  stage: "error",
1681
1718
  message: e instanceof Error ? e.message : String(e),
1682
- queue: !Te(w, l),
1683
- endpoint: M,
1684
- fn_index: w,
1719
+ queue: !Te(C, l),
1720
+ endpoint: j,
1721
+ fn_index: C,
1685
1722
  time: /* @__PURE__ */ new Date()
1686
- }), V();
1723
+ }), H();
1687
1724
  });
1688
- let be = !1, z = [], B = [];
1689
- function V() {
1690
- for (be = !0; B.length > 0;) B.shift()({
1725
+ let z = !1, B = [], V = [];
1726
+ function H() {
1727
+ for (z = !0; V.length > 0;) V.shift()({
1691
1728
  value: void 0,
1692
1729
  done: !0
1693
1730
  });
1694
1731
  }
1695
- function H(e) {
1696
- B.length > 0 ? B.shift()(e) : z.push(e);
1732
+ function U(e) {
1733
+ V.length > 0 ? V.shift()(e) : B.push(e);
1697
1734
  }
1698
- function xe(e) {
1699
- H(Ut(e)), V();
1735
+ function Se(e) {
1736
+ U(Yt(e)), H();
1700
1737
  }
1701
- function U(e) {
1702
- H({
1738
+ function Ce(e) {
1739
+ U({
1703
1740
  value: e,
1704
1741
  done: !1
1705
1742
  });
1706
1743
  }
1707
- function W() {
1708
- return z.length > 0 ? Promise.resolve(z.shift()) : be ? Promise.resolve({
1744
+ function we() {
1745
+ return B.length > 0 ? Promise.resolve(B.shift()) : z ? Promise.resolve({
1709
1746
  value: void 0,
1710
1747
  done: !0
1711
- }) : new Promise((e) => B.push(e));
1748
+ }) : new Promise((e) => V.push(e));
1712
1749
  }
1713
- let Se = {
1714
- [Symbol.asyncIterator]: () => Se,
1715
- next: W,
1716
- throw: async (e) => (xe(e), W()),
1717
- return: async () => (V(), {
1750
+ let W = {
1751
+ [Symbol.asyncIterator]: () => W,
1752
+ next: we,
1753
+ throw: async (e) => (Se(e), we()),
1754
+ return: async () => (H(), {
1718
1755
  value: void 0,
1719
1756
  done: !0
1720
1757
  }),
1721
- cancel: me,
1758
+ cancel: _e,
1722
1759
  send_chunk: (e) => {
1723
- this.post_data(`${l.root}${x}/stream/${j}`, {
1760
+ this.post_data(`${l.root}${x}/stream/${A}`, {
1724
1761
  ...e,
1725
1762
  session_hash: this.session_hash
1726
1763
  });
1727
1764
  },
1728
1765
  close_stream: () => {
1729
- this.post_data(`${l.root}${x}/stream/${j}/close`, {}), V();
1766
+ this.post_data(`${l.root}${x}/stream/${A}/close`, {}), H();
1730
1767
  },
1731
- event_id: () => j,
1732
- wait_for_id: async () => (await _e, P)
1768
+ event_id: () => A,
1769
+ wait_for_id: async () => (await R, N)
1733
1770
  };
1734
- return Se;
1771
+ return W;
1735
1772
  } catch (e) {
1736
1773
  throw console.error("Submit function encountered an error:", e), e;
1737
1774
  }
1738
1775
  }
1739
- function Ut(e) {
1776
+ function Yt(e) {
1740
1777
  return { then: (t, n) => n(e) };
1741
1778
  }
1742
- function Wt(e, t, n, r) {
1779
+ function Xt(e, t, n, r) {
1743
1780
  let i, a, o;
1744
1781
  if (typeof t == "number") i = t, a = e.unnamed_endpoints[i], o = r.dependencies.find((e) => e.id == t);
1745
1782
  else {
@@ -1827,7 +1864,7 @@ var $ = class {
1827
1864
  resolve_config;
1828
1865
  resolve_cookies;
1829
1866
  constructor(e, t = { events: ["data"] }) {
1830
- this.app_reference = e, this.deep_link = t.query_params?.deep_link || null, t.events ||= ["data"], k(t), this.options = t, this.current_payload = {}, t.cookies && (this.cookies = t.cookies), this.view_api = be.bind(this), this.upload_files = z.bind(this), this.handle_blob = ke.bind(this), this.post_data = Ne.bind(this), this.submit = Ht.bind(this), this.predict = Pe.bind(this), this.open_stream = et.bind(this), this.resolve_config = j.bind(this), this.resolve_cookies = N.bind(this), this.upload = H.bind(this), this.fetch = this.fetch.bind(this), this.handle_space_success = this.handle_space_success.bind(this), this.stream = this.stream.bind(this);
1867
+ this.app_reference = e, this.deep_link = t.query_params?.deep_link || null, t.events ||= ["data"], D(t), this.options = t, this.current_payload = {}, t.cookies && (this.cookies = t.cookies), this.view_api = xe.bind(this), this.upload_files = R.bind(this), this.handle_blob = ke.bind(this), this.post_data = Ne.bind(this), this.submit = Jt.bind(this), this.predict = Pe.bind(this), this.open_stream = et.bind(this), this.resolve_config = he.bind(this), this.resolve_cookies = A.bind(this), this.upload = V.bind(this), this.fetch = this.fetch.bind(this), this.handle_space_success = this.handle_space_success.bind(this), this.stream = this.stream.bind(this);
1831
1868
  }
1832
1869
  async init() {
1833
1870
  qe(), this.options.auth && await this.resolve_cookies(), await this._resolve_config().then((e) => e?.config && this._resolve_heartbeat(e.config));
@@ -1836,11 +1873,11 @@ var $ = class {
1836
1873
  } catch (e) {
1837
1874
  console.error(e.message);
1838
1875
  }
1839
- this.api_map = fe(this.config?.dependencies || []);
1876
+ this.api_map = me(this.config?.dependencies || []);
1840
1877
  }
1841
1878
  async _resolve_heartbeat(e) {
1842
- if (e && (this.config = e, this.api_prefix = e.api_prefix || "", this.config && this.config.connect_heartbeat && this.config.space_id && this.options.token && (this.jwt = await de(this.config.space_id, this.options.token, this.cookies))), e.space_id && this.options.token && (this.jwt = await de(e.space_id, this.options.token)), this.config && this.config.connect_heartbeat) {
1843
- let e = new URL(`${this.config.root}${this.api_prefix}/${_}/${this.session_hash}`);
1879
+ if (e && (this.config = e, this.api_prefix = e.api_prefix || "", this.config && this.config.connect_heartbeat && this.config.space_id && this.options.token && (this.jwt = await pe(this.config.space_id, this.options.token, this.cookies))), e.space_id && this.options.token && (this.jwt = await pe(e.space_id, this.options.token)), this.config && this.config.connect_heartbeat) {
1880
+ let e = new URL(`${this.config.root}${this.api_prefix}/${v}/${this.session_hash}`);
1844
1881
  this.jwt && e.searchParams.set("__sign", this.jwt), this.heartbeat_event ||= this.stream(e);
1845
1882
  }
1846
1883
  }
@@ -1849,7 +1886,7 @@ var $ = class {
1849
1886
  return t.session_hash && (n.session_hash = t.session_hash), await n.init(), n;
1850
1887
  }
1851
1888
  async reconnect() {
1852
- let e = new URL(`${this.config.root}${this.api_prefix}/${v}`), t;
1889
+ let e = new URL(`${this.config.root}${this.api_prefix}/${re}`), t;
1853
1890
  try {
1854
1891
  let n = await this.fetch(e);
1855
1892
  if (!n.ok) throw Error();
@@ -1866,11 +1903,11 @@ var $ = class {
1866
1903
  if (!this.config) throw Error(b);
1867
1904
  let e = await this.resolve_config(this.config.root, !1);
1868
1905
  if (!e) throw Error(b);
1869
- this.config = e, this.api_prefix = e.api_prefix || "", this.api_map = fe(e.dependencies || []);
1906
+ this.config = e, this.api_prefix = e.api_prefix || "", this.api_map = me(e.dependencies || []);
1870
1907
  try {
1871
1908
  this.api_info = await this.view_api();
1872
1909
  } catch (e) {
1873
- console.error(S + e.message);
1910
+ console.error(ae + e.message);
1874
1911
  }
1875
1912
  return this.get_url_config();
1876
1913
  }
@@ -1881,7 +1918,7 @@ var $ = class {
1881
1918
  return Ve(e, t);
1882
1919
  }
1883
1920
  async _resolve_config() {
1884
- let { http_protocol: e, host: t, space_id: n } = await R(this.app_reference, this.options.token), { status_callback: r } = this.options;
1921
+ let { http_protocol: e, host: t, space_id: n } = await F(this.app_reference, this.options.token), { status_callback: r } = this.options;
1885
1922
  n && r && await Fe(n, r);
1886
1923
  let i;
1887
1924
  try {
@@ -1889,7 +1926,7 @@ var $ = class {
1889
1926
  if (i = await this.resolve_config(n), !i) throw Error(b);
1890
1927
  return this.config_success(i);
1891
1928
  } catch (e) {
1892
- if (n && r) K(n, L.test(n) ? "space_name" : "subdomain", this.handle_space_success);
1929
+ if (n && r) K(n, P.test(n) ? "space_name" : "subdomain", this.handle_space_success);
1893
1930
  else throw r && r({
1894
1931
  status: "error",
1895
1932
  message: "Could not load this space.",
@@ -1899,14 +1936,14 @@ var $ = class {
1899
1936
  }
1900
1937
  }
1901
1938
  async config_success(e) {
1902
- if (this.config = e, this.api_prefix = e.api_prefix || "", e.run_history === !1 && Nt({
1939
+ if (this.config = e, this.api_prefix = e.api_prefix || "", e.run_history === !1 && zt({
1903
1940
  app_id: e.app_id,
1904
1941
  username: e.username
1905
1942
  }), this.config.auth_required) return this.prepare_return_obj();
1906
1943
  try {
1907
1944
  this.api_info = await this.view_api();
1908
1945
  } catch (e) {
1909
- console.error(S + e.message);
1946
+ console.error(ae + e.message);
1910
1947
  }
1911
1948
  return this.prepare_return_obj();
1912
1949
  }
@@ -1945,7 +1982,7 @@ var $ = class {
1945
1982
  }), r["Content-Type"] = "application/json";
1946
1983
  i && (r.Authorization = `Bearer ${i}`);
1947
1984
  try {
1948
- let e = await this.fetch(`${o}${this.api_prefix}/${te}/`, {
1985
+ let e = await this.fetch(`${o}${this.api_prefix}/${ee}/`, {
1949
1986
  method: "POST",
1950
1987
  body: c,
1951
1988
  headers: r,
@@ -1958,7 +1995,7 @@ var $ = class {
1958
1995
  }
1959
1996
  }
1960
1997
  set_cookies(e) {
1961
- this.cookies = I(e).join("; ");
1998
+ this.cookies = N(e).join("; ");
1962
1999
  }
1963
2000
  prepare_return_obj() {
1964
2001
  return {
@@ -1970,11 +2007,75 @@ var $ = class {
1970
2007
  };
1971
2008
  }
1972
2009
  };
1973
- async function Gt(e, t = { events: ["data"] }) {
2010
+ async function Zt(e, t = { events: ["data"] }) {
1974
2011
  return await $.connect(e, t);
1975
2012
  }
1976
- async function Kt(e, t) {
2013
+ async function Qt(e, t) {
1977
2014
  return await $.duplicate(e, t);
1978
2015
  }
1979
2016
  //#endregion
1980
- export { $ as Client, U as FileData, ae as MISSING_CREDENTIALS_MSG, Lt as apply_run_history_replay, Nt as clear_run_history, Gt as client, It as consume_run_history_replay, Pt as delete_run_history, Kt as duplicate, De as handle_file, Vt as on_run_history_change, Pe as predict, xe as prepare_files, Mt as read_run_history, ut as run_history_url, Ft as stage_run_history_replay, Ht as submit, H as upload, z as upload_files };
2017
+ //#region src/utils/bucket_sync.ts
2018
+ var $t = /^[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-][a-zA-Z0-9_./-]*$/;
2019
+ function en(e) {
2020
+ return $t.test(e) ? !e.split("/").some((e) => e === "" || e === "." || e === "..") : !1;
2021
+ }
2022
+ function tn(e, t, n) {
2023
+ let r = n ? `?${new URLSearchParams(n)}` : "", i = e.replace(/\/+$/, "");
2024
+ return i ? `${i}/gradio_api/run-history/${t}${r}` : typeof document < "u" && document.baseURI ? new URL(`gradio_api/run-history/${t}${r}`, document.baseURI).toString() : `gradio_api/run-history/${t}${r}`;
2025
+ }
2026
+ async function nn(e) {
2027
+ try {
2028
+ let t = await e.json();
2029
+ return typeof t?.detail == "string" ? t.detail : `${e.status}`;
2030
+ } catch {
2031
+ return `${e.status}`;
2032
+ }
2033
+ }
2034
+ async function rn(e, t, n, r) {
2035
+ try {
2036
+ let i = await fetch(e, {
2037
+ credentials: "include",
2038
+ ...t
2039
+ });
2040
+ return i.ok ? {
2041
+ ok: !0,
2042
+ status: i.status,
2043
+ data: r(await i.json())
2044
+ } : {
2045
+ ok: !1,
2046
+ status: i.status,
2047
+ data: n,
2048
+ detail: await nn(i)
2049
+ };
2050
+ } catch (e) {
2051
+ return {
2052
+ ok: !1,
2053
+ status: 0,
2054
+ data: n,
2055
+ detail: String(e)
2056
+ };
2057
+ }
2058
+ }
2059
+ async function an(e, t) {
2060
+ return en(t) ? rn(tn(e, "connect"), {
2061
+ method: "POST",
2062
+ headers: { "Content-Type": "application/json" },
2063
+ body: JSON.stringify({ bucket_id: t })
2064
+ }, null, () => null) : {
2065
+ ok: !1,
2066
+ status: 422,
2067
+ data: null,
2068
+ detail: "invalid bucket id"
2069
+ };
2070
+ }
2071
+ async function on(e) {
2072
+ return rn(tn(e, "buckets"), {}, [], (e) => Array.isArray(e?.buckets) ? e.buckets : []);
2073
+ }
2074
+ async function sn(e, t) {
2075
+ return rn(tn(e, "records", { bucket: t }), {}, [], (e) => Array.isArray(e?.records) ? e.records : []);
2076
+ }
2077
+ function cn(e, t, n, r, i) {
2078
+ return tn(e, `records/${encodeURIComponent(n)}/${encodeURIComponent(r)}/assets/${encodeURIComponent(i)}`, { bucket: t });
2079
+ }
2080
+ //#endregion
2081
+ export { $ as Client, U as FileData, oe as MISSING_CREDENTIALS_MSG, Ut as apply_run_history_replay, cn as asset_url, zt as clear_run_history, Zt as client, an as connect_bucket, Ht as consume_run_history_replay, Bt as delete_run_history, Qt as duplicate, De as handle_file, en as is_valid_bucket_id, sn as list_bucket_records, on as list_user_buckets, qt as on_run_history_change, Pe as predict, H as prepare_files, It as read_run_history, Lt as read_run_history_storage, dt as run_history_url, Rt as set_run_history_storage, Vt as stage_run_history_replay, Jt as submit, V as upload, R as upload_files };