@gradio/client 1.15.5 → 1.15.7

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.
@@ -1,23 +1,23 @@
1
- var Ye = Object.defineProperty;
2
- var et = (e, t, s) => t in e ? Ye(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
3
- var u = (e, t, s) => (et(e, typeof t != "symbol" ? t + "" : t, s), s), $e = (e, t, s) => {
1
+ var et = Object.defineProperty;
2
+ var tt = (e, t, s) => t in e ? et(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
3
+ var u = (e, t, s) => (tt(e, typeof t != "symbol" ? t + "" : t, s), s), Se = (e, t, s) => {
4
4
  if (!t.has(e))
5
5
  throw TypeError("Cannot " + s);
6
6
  };
7
- var V = (e, t, s) => ($e(e, t, "read from private field"), s ? s.call(e) : t.get(e)), ke = (e, t, s) => {
7
+ var H = (e, t, s) => (Se(e, t, "read from private field"), s ? s.call(e) : t.get(e)), $e = (e, t, s) => {
8
8
  if (t.has(e))
9
9
  throw TypeError("Cannot add the same private member more than once");
10
10
  t instanceof WeakSet ? t.add(e) : t.set(e, s);
11
- }, Re = (e, t, s, n) => ($e(e, t, "write to private field"), n ? n.call(e, s) : t.set(e, s), s);
12
- var fe = new Intl.Collator(0, { numeric: 1 }).compare;
13
- function Pe(e, t, s) {
14
- return e = e.split("."), t = t.split("."), fe(e[0], t[0]) || fe(e[1], t[1]) || (t[2] = t.slice(2).join("."), s = /[.-]/.test(e[2] = e.slice(2).join(".")), s == /[.-]/.test(t[2]) ? fe(e[2], t[2]) : s ? -1 : 1);
11
+ }, ke = (e, t, s, n) => (Se(e, t, "write to private field"), n ? n.call(e, s) : t.set(e, s), s);
12
+ var pe = new Intl.Collator(0, { numeric: 1 }).compare;
13
+ function Le(e, t, s) {
14
+ return e = e.split("."), t = t.split("."), pe(e[0], t[0]) || pe(e[1], t[1]) || (t[2] = t.slice(2).join("."), s = /[.-]/.test(e[2] = e.slice(2).join(".")), s == /[.-]/.test(t[2]) ? pe(e[2], t[2]) : s ? -1 : 1);
15
15
  }
16
- const tt = "host", je = "queue/data", st = "queue/join", Oe = "upload", nt = "login", Ne = "config", it = "info", ot = "runtime", rt = "sleeptime", at = "heartbeat", ct = "component_server", lt = "reset", ut = "cancel", pt = "https://gradio-space-api-fetcher-v2.hf.space/api", xe = "This application is currently busy. Please try again. ", J = "Connection errored out. ", z = "Could not resolve app config. ", ft = "Could not get space status. ", ht = "Could not get API info. ", me = "Space metadata could not be loaded. ", dt = "Invalid URL. A full URL path is required.", _t = "Not authorized to access this space. ", Ie = "Invalid credentials. Could not login. ", mt = "Login credentials are required to access this space.", gt = "File system access is only available in Node.js environments", qe = "Root URL not found in client config", wt = "Error uploading file";
17
- function yt(e, t, s) {
16
+ const st = "host", Pe = "queue/data", nt = "queue/join", Re = "upload", it = "login", Oe = "config", ot = "info", rt = "runtime", at = "sleeptime", ct = "heartbeat", lt = "component_server", ut = "reset", pt = "cancel", ft = "app_id", ht = "https://gradio-space-api-fetcher-v2.hf.space/api", je = "This application is currently busy. Please try again. ", M = "Connection errored out. ", z = "Could not resolve app config. ", dt = "Could not get space status. ", _t = "Could not get API info. ", _e = "Space metadata could not be loaded. ", mt = "Invalid URL. A full URL path is required.", gt = "Not authorized to access this space. ", xe = "Invalid credentials. Could not login. ", wt = "Login credentials are required to access this space.", yt = "File system access is only available in Node.js environments", Ie = "Root URL not found in client config", bt = "Error uploading file";
17
+ function vt(e, t, s) {
18
18
  return t.startsWith("http://") || t.startsWith("https://") ? s ? e : t : e + t;
19
19
  }
20
- async function Te(e, t, s) {
20
+ async function Ne(e, t, s) {
21
21
  try {
22
22
  return (await (await fetch(`https://huggingface.co/api/spaces/${e}/jwt`, {
23
23
  headers: {
@@ -29,46 +29,46 @@ async function Te(e, t, s) {
29
29
  return !1;
30
30
  }
31
31
  }
32
- function bt(e) {
32
+ function Et(e) {
33
33
  let t = {};
34
34
  return e.forEach(({ api_name: s, id: n }) => {
35
35
  s && (t[s] = n);
36
36
  }), t;
37
37
  }
38
- async function vt(e) {
38
+ async function St(e) {
39
39
  const t = this.options.hf_token ? { Authorization: `Bearer ${this.options.hf_token}` } : {};
40
40
  if (t["Content-Type"] = "application/json", typeof window < "u" && window.gradio_config && location.origin !== "http://localhost:9876" && !window.gradio_config.dev_mode)
41
41
  return window.gradio_config.current_page && (e = e.substring(0, e.lastIndexOf("/"))), window.gradio_config.root = e, { ...window.gradio_config };
42
42
  if (e) {
43
- let s = Be(
43
+ let s = ze(
44
44
  e,
45
- this.deep_link ? Ne + "?deep_link=" + this.deep_link : Ne
45
+ this.deep_link ? Oe + "?deep_link=" + this.deep_link : Oe
46
46
  );
47
47
  const n = await this.fetch(s, {
48
48
  headers: t,
49
49
  credentials: "include"
50
50
  });
51
- return Et(n, e, !!this.options.auth);
51
+ return $t(n, e, !!this.options.auth);
52
52
  }
53
53
  throw new Error(z);
54
54
  }
55
- async function Et(e, t, s) {
55
+ async function $t(e, t, s) {
56
56
  var n, i;
57
57
  if ((e == null ? void 0 : e.status) === 401 && !s) {
58
58
  const r = await e.json(), o = (n = r == null ? void 0 : r.detail) == null ? void 0 : n.auth_message;
59
- throw new Error(o || mt);
59
+ throw new Error(o || wt);
60
60
  } else if ((e == null ? void 0 : e.status) === 401 && s)
61
- throw new Error(Ie);
61
+ throw new Error(xe);
62
62
  if ((e == null ? void 0 : e.status) === 200) {
63
63
  let r = await e.json();
64
64
  return r.root = t, (i = r.dependencies) == null || i.forEach((o, a) => {
65
65
  o.id === void 0 && (o.id = a);
66
66
  }), r;
67
67
  } else if ((e == null ? void 0 : e.status) === 401)
68
- throw new Error(_t);
68
+ throw new Error(gt);
69
69
  throw new Error(z);
70
70
  }
71
- async function St() {
71
+ async function kt() {
72
72
  const { http_protocol: e, host: t } = await te(
73
73
  this.app_reference,
74
74
  this.options.hf_token
@@ -93,7 +93,7 @@ async function Ue(e, t, s, n, i) {
93
93
  r.append("username", s == null ? void 0 : s[0]), r.append("password", s == null ? void 0 : s[1]);
94
94
  let o = {};
95
95
  i && (o.Authorization = `Bearer ${i}`);
96
- const a = await n(`${e}//${t}/${nt}`, {
96
+ const a = await n(`${e}//${t}/${it}`, {
97
97
  headers: o,
98
98
  method: "POST",
99
99
  body: r,
@@ -101,9 +101,9 @@ async function Ue(e, t, s, n, i) {
101
101
  });
102
102
  if (a.status === 200)
103
103
  return a.headers.get("set-cookie");
104
- throw a.status === 401 ? new Error(Ie) : new Error(me);
104
+ throw a.status === 401 ? new Error(xe) : new Error(_e);
105
105
  }
106
- function he(e) {
106
+ function fe(e) {
107
107
  if (e.startsWith("http")) {
108
108
  const { protocol: t, host: s, pathname: n } = new URL(e);
109
109
  return {
@@ -124,32 +124,32 @@ function he(e) {
124
124
  host: new URL(e).host
125
125
  };
126
126
  }
127
- const ze = (e) => {
127
+ const qe = (e) => {
128
128
  let t = [];
129
129
  return e.split(/,(?=\s*[^\s=;]+=[^\s=;]+)/).forEach((n) => {
130
130
  const [i, r] = n.split(";")[0].split("=");
131
131
  i && r && t.push(`${i.trim()}=${r.trim()}`);
132
132
  }), t;
133
- }, ge = /^[a-zA-Z0-9_\-\.]+\/[a-zA-Z0-9_\-\.]+$/, $t = /.*hf\.space\/{0,1}.*$/;
133
+ }, me = /^[a-zA-Z0-9_\-\.]+\/[a-zA-Z0-9_\-\.]+$/, Rt = /.*hf\.space\/{0,1}.*$/;
134
134
  async function te(e, t) {
135
135
  const s = {};
136
136
  t && (s.Authorization = `Bearer ${t}`);
137
137
  const n = e.trim().replace(/\/$/, "");
138
- if (ge.test(n))
138
+ if (me.test(n))
139
139
  try {
140
140
  const r = (await (await fetch(
141
- `https://huggingface.co/api/spaces/${n}/${tt}`,
141
+ `https://huggingface.co/api/spaces/${n}/${st}`,
142
142
  { headers: s }
143
143
  )).json()).host;
144
144
  return {
145
145
  space_id: e,
146
- ...he(r)
146
+ ...fe(r)
147
147
  };
148
148
  } catch {
149
- throw new Error(me);
149
+ throw new Error(_e);
150
150
  }
151
- if ($t.test(n)) {
152
- const { ws_protocol: i, http_protocol: r, host: o } = he(n);
151
+ if (Rt.test(n)) {
152
+ const { ws_protocol: i, http_protocol: r, host: o } = fe(n);
153
153
  return {
154
154
  space_id: o.split("/")[0].replace(".hf.space", ""),
155
155
  ws_protocol: i,
@@ -159,17 +159,17 @@ async function te(e, t) {
159
159
  }
160
160
  return {
161
161
  space_id: !1,
162
- ...he(n)
162
+ ...fe(n)
163
163
  };
164
164
  }
165
- const Be = (...e) => {
165
+ const ze = (...e) => {
166
166
  try {
167
167
  return e.reduce((t, s) => (t = t.replace(/\/+$/, ""), s = s.replace(/^\/+/, ""), new URL(s, t + "/").toString()));
168
168
  } catch {
169
- throw new Error(dt);
169
+ throw new Error(mt);
170
170
  }
171
171
  };
172
- function kt(e, t, s) {
172
+ function Ot(e, t, s) {
173
173
  const n = {
174
174
  named_endpoints: {},
175
175
  unnamed_endpoints: {}
@@ -182,15 +182,15 @@ function kt(e, t, s) {
182
182
  (c) => c.api_name === r || c.api_name === r.replace("/", "")
183
183
  )) == null ? void 0 : p.id) || s[r.replace("/", "")] || -1, h = l !== -1 ? (g = t.dependencies.find((c) => c.id == l)) == null ? void 0 : g.types : { generator: !1, cancel: !1 };
184
184
  if (l !== -1 && ((B = (E = t.dependencies.find((c) => c.id == l)) == null ? void 0 : E.inputs) == null ? void 0 : B.length) !== o.length) {
185
- const c = t.dependencies.find((_) => _.id == l).inputs.map(
186
- (_) => {
187
- var N;
188
- return (N = t.components.find((D) => D.id === _)) == null ? void 0 : N.type;
185
+ const c = t.dependencies.find((d) => d.id == l).inputs.map(
186
+ (d) => {
187
+ var O;
188
+ return (O = t.components.find((D) => D.id === d)) == null ? void 0 : O.type;
189
189
  }
190
190
  );
191
191
  try {
192
- c.forEach((_, N) => {
193
- if (_ === "state") {
192
+ c.forEach((d, O) => {
193
+ if (d === "state") {
194
194
  const D = {
195
195
  component: "state",
196
196
  example: null,
@@ -199,17 +199,17 @@ function kt(e, t, s) {
199
199
  parameter_name: null,
200
200
  hidden: !0
201
201
  };
202
- o.splice(N, 0, D);
202
+ o.splice(O, 0, D);
203
203
  }
204
204
  });
205
- } catch (_) {
206
- console.error(_);
205
+ } catch (d) {
206
+ console.error(d);
207
207
  }
208
208
  }
209
- const m = (c, _, N, D) => ({
209
+ const m = (c, d, O, D) => ({
210
210
  ...c,
211
- description: Ot(c == null ? void 0 : c.type, N),
212
- type: Rt(c == null ? void 0 : c.type, _, N, D) || ""
211
+ description: Tt(c == null ? void 0 : c.type, O),
212
+ type: Nt(c == null ? void 0 : c.type, d, O, D) || ""
213
213
  });
214
214
  n[i][r] = {
215
215
  parameters: o.map(
@@ -224,7 +224,7 @@ function kt(e, t, s) {
224
224
  ));
225
225
  }), n;
226
226
  }
227
- function Rt(e, t, s, n) {
227
+ function Nt(e, t, s, n) {
228
228
  if (t === "Api")
229
229
  return e.type;
230
230
  switch (e == null ? void 0 : e.type) {
@@ -246,10 +246,10 @@ function Rt(e, t, s, n) {
246
246
  if (s === "GallerySerializable")
247
247
  return n === "parameter" ? "[(Blob | File | Buffer), (string | null)][]" : "[{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}, (string | null))][]";
248
248
  }
249
- function Ot(e, t) {
249
+ function Tt(e, t) {
250
250
  return t === "GallerySerializable" ? "array of [file, label] tuples" : t === "ListStringSerializable" ? "array of strings" : t === "FileSerializable" ? "array of files or single file" : e == null ? void 0 : e.description;
251
251
  }
252
- function de(e, t) {
252
+ function he(e, t) {
253
253
  switch (e.msg) {
254
254
  case "send_data":
255
255
  return { type: "data" };
@@ -260,7 +260,7 @@ function de(e, t) {
260
260
  type: "update",
261
261
  status: {
262
262
  queue: !0,
263
- message: xe,
263
+ message: je,
264
264
  stage: "error",
265
265
  code: e.code,
266
266
  success: e.success
@@ -273,6 +273,17 @@ function de(e, t) {
273
273
  case "unexpected_error":
274
274
  return {
275
275
  type: "unexpected_error",
276
+ status: {
277
+ queue: !0,
278
+ message: e.message,
279
+ session_not_found: e.session_not_found,
280
+ stage: "error",
281
+ success: !1
282
+ }
283
+ };
284
+ case "broken_connection":
285
+ return {
286
+ type: "broken_connection",
276
287
  status: {
277
288
  queue: !0,
278
289
  message: e.message,
@@ -376,7 +387,7 @@ function de(e, t) {
376
387
  }
377
388
  return { type: "none", status: { stage: "error", queue: !0 } };
378
389
  }
379
- const Nt = (e = [], t) => {
390
+ const Ct = (e = [], t) => {
380
391
  const s = t ? t.parameters : [];
381
392
  if (Array.isArray(e))
382
393
  return t && s.length > 0 && e.length > s.length && console.warn("Too many arguments provided for the endpoint."), e;
@@ -402,7 +413,7 @@ const Nt = (e = [], t) => {
402
413
  );
403
414
  }), n;
404
415
  };
405
- async function Tt() {
416
+ async function Dt() {
406
417
  if (this.api_info)
407
418
  return this.api_info;
408
419
  const { hf_token: e } = this.options, { config: t } = this, s = { "Content-Type": "application/json" };
@@ -412,8 +423,8 @@ async function Tt() {
412
423
  if (typeof window < "u" && window.gradio_api_info)
413
424
  i = window.gradio_api_info;
414
425
  else {
415
- if (Pe((t == null ? void 0 : t.version) || "2.0.0", "3.30") < 0)
416
- n = await this.fetch(pt, {
426
+ if (Le((t == null ? void 0 : t.version) || "2.0.0", "3.30") < 0)
427
+ n = await this.fetch(ht, {
417
428
  method: "POST",
418
429
  body: JSON.stringify({
419
430
  serialize: !1,
@@ -423,22 +434,22 @@ async function Tt() {
423
434
  credentials: "include"
424
435
  });
425
436
  else {
426
- const r = Be(t.root, this.api_prefix, it);
437
+ const r = ze(t.root, this.api_prefix, ot);
427
438
  n = await this.fetch(r, {
428
439
  headers: s,
429
440
  credentials: "include"
430
441
  });
431
442
  }
432
443
  if (!n.ok)
433
- throw new Error(J);
444
+ throw new Error(M);
434
445
  i = await n.json();
435
446
  }
436
- return "api" in i && (i = i.api), i.named_endpoints["/predict"] && !i.unnamed_endpoints[0] && (i.unnamed_endpoints[0] = i.named_endpoints["/predict"]), kt(i, t, this.api_map);
447
+ return "api" in i && (i = i.api), i.named_endpoints["/predict"] && !i.unnamed_endpoints[0] && (i.unnamed_endpoints[0] = i.named_endpoints["/predict"]), Ot(i, t, this.api_map);
437
448
  } catch (n) {
438
449
  throw new Error("Could not get API info. " + n.message);
439
450
  }
440
451
  }
441
- async function Ct(e, t, s) {
452
+ async function At(e, t, s) {
442
453
  var a;
443
454
  const n = {};
444
455
  (a = this == null ? void 0 : this.options) != null && a.hf_token && (n.Authorization = `Bearer ${this.options.hf_token}`);
@@ -450,7 +461,7 @@ async function Ct(e, t, s) {
450
461
  m.append("files", g);
451
462
  });
452
463
  try {
453
- const g = s ? `${e}${this.api_prefix}/${Oe}?upload_id=${s}` : `${e}${this.api_prefix}/${Oe}`;
464
+ const g = s ? `${e}${this.api_prefix}/${Re}?upload_id=${s}` : `${e}${this.api_prefix}/${Re}`;
454
465
  o = await this.fetch(g, {
455
466
  method: "POST",
456
467
  body: m,
@@ -458,7 +469,7 @@ async function Ct(e, t, s) {
458
469
  credentials: "include"
459
470
  });
460
471
  } catch (g) {
461
- throw new Error(J + g.message);
472
+ throw new Error(M + g.message);
462
473
  }
463
474
  if (!o.ok) {
464
475
  const g = await o.text();
@@ -469,7 +480,7 @@ async function Ct(e, t, s) {
469
480
  }
470
481
  return { files: r };
471
482
  }
472
- async function Dt(e, t, s, n) {
483
+ async function Lt(e, t, s, n) {
473
484
  let i = (Array.isArray(e) ? e : [e]).map(
474
485
  (o) => o.blob
475
486
  );
@@ -494,7 +505,7 @@ async function Dt(e, t, s, n) {
494
505
  )
495
506
  );
496
507
  }
497
- async function os(e, t) {
508
+ async function as(e, t) {
498
509
  return e.map(
499
510
  (s) => new se({
500
511
  path: s.name,
@@ -531,7 +542,7 @@ class se {
531
542
  this.path = t, this.url = s, this.orig_name = n, this.size = i, this.blob = s ? void 0 : r, this.is_stream = o, this.mime_type = a, this.alt_text = l, this.b64 = h;
532
543
  }
533
544
  }
534
- class Fe {
545
+ class Be {
535
546
  constructor(t, s) {
536
547
  u(this, "type");
537
548
  u(this, "command");
@@ -540,8 +551,8 @@ class Fe {
540
551
  this.type = "command", this.command = t, this.meta = s;
541
552
  }
542
553
  }
543
- const At = typeof process < "u" && process.versions && process.versions.node;
544
- function Ce(e, t, s) {
554
+ const Pt = typeof process < "u" && process.versions && process.versions.node;
555
+ function Te(e, t, s) {
545
556
  for (; s.length > 1; ) {
546
557
  const i = s.shift();
547
558
  if (typeof i == "string" || typeof i == "number")
@@ -555,7 +566,7 @@ function Ce(e, t, s) {
555
566
  else
556
567
  throw new Error("Invalid key type");
557
568
  }
558
- async function _e(e, t = void 0, s = [], n = !1, i = void 0) {
569
+ async function de(e, t = void 0, s = [], n = !1, i = void 0) {
559
570
  if (Array.isArray(e)) {
560
571
  let r = [];
561
572
  return await Promise.all(
@@ -563,7 +574,7 @@ async function _e(e, t = void 0, s = [], n = !1, i = void 0) {
563
574
  var m;
564
575
  let l = s.slice();
565
576
  l.push(String(a));
566
- const h = await _e(
577
+ const h = await de(
567
578
  e[a],
568
579
  n ? ((m = i == null ? void 0 : i.parameters[a]) == null ? void 0 : m.component) || void 0 : t,
569
580
  l,
@@ -587,7 +598,7 @@ async function _e(e, t = void 0, s = [], n = !1, i = void 0) {
587
598
  for (const o of Object.keys(e)) {
588
599
  const a = [...s, o], l = e[o];
589
600
  r = r.concat(
590
- await _e(
601
+ await de(
591
602
  l,
592
603
  void 0,
593
604
  a,
@@ -601,12 +612,12 @@ async function _e(e, t = void 0, s = [], n = !1, i = void 0) {
601
612
  }
602
613
  return [];
603
614
  }
604
- function Lt(e, t) {
615
+ function jt(e, t) {
605
616
  var n, i;
606
617
  let s = (i = (n = t == null ? void 0 : t.dependencies) == null ? void 0 : n.find((r) => r.id == e)) == null ? void 0 : i.queue;
607
618
  return s != null ? !s : !t.enable_queue;
608
619
  }
609
- function Pt(e, t) {
620
+ function xt(e, t) {
610
621
  return new Promise((s, n) => {
611
622
  const i = new MessageChannel();
612
623
  i.port1.onmessage = ({ data: r }) => {
@@ -614,7 +625,7 @@ function Pt(e, t) {
614
625
  }, window.parent.postMessage(e, t, [i.port2]);
615
626
  });
616
627
  }
617
- function rs(e) {
628
+ function cs(e) {
618
629
  if (typeof e == "string") {
619
630
  if (e.startsWith("http://") || e.startsWith("https://"))
620
631
  return {
@@ -623,8 +634,8 @@ function rs(e) {
623
634
  orig_name: e.split("/").pop() ?? "unknown",
624
635
  meta: { _type: "gradio.FileData" }
625
636
  };
626
- if (At)
627
- return new Fe("upload_file", {
637
+ if (Pt)
638
+ return new Be("upload_file", {
628
639
  path: e,
629
640
  name: e,
630
641
  orig_path: e
@@ -641,7 +652,7 @@ function rs(e) {
641
652
  "Invalid input: must be a URL, File, Blob, or Buffer object."
642
653
  );
643
654
  }
644
- function X(e, t, s, n, i = !1) {
655
+ function K(e, t, s, n, i = !1) {
645
656
  if (n === "input" && !i)
646
657
  throw new Error("Invalid code path. Cannot skip state inputs for input.");
647
658
  if (n === "output" && i)
@@ -669,10 +680,10 @@ function X(e, t, s, n, i = !1) {
669
680
  }
670
681
  return r;
671
682
  }
672
- async function jt(e, t, s) {
683
+ async function It(e, t, s) {
673
684
  const n = this;
674
- await xt(n, t);
675
- const i = await _e(
685
+ await Ut(n, t);
686
+ const i = await de(
676
687
  t,
677
688
  void 0,
678
689
  [],
@@ -693,36 +704,36 @@ async function jt(e, t, s) {
693
704
  })
694
705
  )).forEach(({ path: o, file_url: a, type: l, name: h }) => {
695
706
  if (l === "Gallery")
696
- Ce(t, a, o);
707
+ Te(t, a, o);
697
708
  else if (a) {
698
709
  const m = new se({ path: a, orig_name: h });
699
- Ce(t, m, o);
710
+ Te(t, m, o);
700
711
  }
701
712
  }), t;
702
713
  }
703
- async function xt(e, t) {
714
+ async function Ut(e, t) {
704
715
  var n, i;
705
716
  if (!(((n = e.config) == null ? void 0 : n.root) || ((i = e.config) == null ? void 0 : i.root_url)))
706
- throw new Error(qe);
707
- await Ge(e, t);
717
+ throw new Error(Ie);
718
+ await Fe(e, t);
708
719
  }
709
- async function Ge(e, t, s = []) {
720
+ async function Fe(e, t, s = []) {
710
721
  for (const n in t)
711
- t[n] instanceof Fe ? await It(e, t, n) : typeof t[n] == "object" && t[n] !== null && await Ge(e, t[n], [...s, n]);
722
+ t[n] instanceof Be ? await qt(e, t, n) : typeof t[n] == "object" && t[n] !== null && await Fe(e, t[n], [...s, n]);
712
723
  }
713
- async function It(e, t, s) {
724
+ async function qt(e, t, s) {
714
725
  var r, o;
715
726
  let n = t[s];
716
727
  const i = ((r = e.config) == null ? void 0 : r.root) || ((o = e.config) == null ? void 0 : o.root_url);
717
728
  if (!i)
718
- throw new Error(qe);
729
+ throw new Error(Ie);
719
730
  try {
720
731
  let a, l;
721
732
  if (typeof process < "u" && process.versions && process.versions.node) {
722
733
  const g = await import("./__vite-browser-external-DYxpcVy9.js");
723
734
  l = (await import("./__vite-browser-external-DYxpcVy9.js")).resolve(process.cwd(), n.meta.path), a = await g.readFile(l);
724
735
  } else
725
- throw new Error(gt);
736
+ throw new Error(yt);
726
737
  const h = new Blob([a], { type: "application/octet-stream" }), m = await e.upload_files(i, [h]), p = m.files && m.files[0];
727
738
  if (p) {
728
739
  const g = new se({
@@ -732,10 +743,10 @@ async function It(e, t, s) {
732
743
  t[s] = g;
733
744
  }
734
745
  } catch (a) {
735
- console.error(wt, a);
746
+ console.error(bt, a);
736
747
  }
737
748
  }
738
- async function qt(e, t, s) {
749
+ async function zt(e, t, s) {
739
750
  const n = { "Content-Type": "application/json" };
740
751
  this.options.hf_token && (n.Authorization = `Bearer ${this.options.hf_token}`);
741
752
  try {
@@ -746,7 +757,7 @@ async function qt(e, t, s) {
746
757
  credentials: "include"
747
758
  });
748
759
  } catch {
749
- return [{ error: J }, 500];
760
+ return [{ error: M }, 500];
750
761
  }
751
762
  let r, o;
752
763
  try {
@@ -756,7 +767,7 @@ async function qt(e, t, s) {
756
767
  }
757
768
  return [r, o];
758
769
  }
759
- async function Ut(e, t = {}) {
770
+ async function Bt(e, t = {}) {
760
771
  let s = !1, n = !1;
761
772
  if (!this.config)
762
773
  throw new Error("Could not resolve app config");
@@ -775,7 +786,7 @@ async function Ut(e, t = {}) {
775
786
  l.type === "data" && (n && i(a), s = !0, a = l), l.type === "status" && (l.stage === "error" && r(l), l.stage === "complete" && (n = !0, s && i(a)));
776
787
  });
777
788
  }
778
- async function Y(e, t, s) {
789
+ async function Q(e, t, s) {
779
790
  let n = t === "subdomain" ? `https://huggingface.co/api/spaces/by-subdomain/${e}` : `https://huggingface.co/api/spaces/${e}`, i, r;
780
791
  try {
781
792
  if (i = await fetch(n), r = i.status, r !== 200)
@@ -785,7 +796,7 @@ async function Y(e, t, s) {
785
796
  s({
786
797
  status: "error",
787
798
  load_status: "error",
788
- message: ft,
799
+ message: dt,
789
800
  detail: "NOT_FOUND"
790
801
  });
791
802
  return;
@@ -805,7 +816,7 @@ async function Y(e, t, s) {
805
816
  message: "Space is asleep. Waking it up...",
806
817
  detail: o
807
818
  }), setTimeout(() => {
808
- Y(e, t, s);
819
+ Q(e, t, s);
809
820
  }, 1e3);
810
821
  break;
811
822
  case "PAUSED":
@@ -814,7 +825,7 @@ async function Y(e, t, s) {
814
825
  load_status: "error",
815
826
  message: "This space has been paused by the author. If you would like to try this demo, consider duplicating the space.",
816
827
  detail: o,
817
- discussions_enabled: await De(a)
828
+ discussions_enabled: await Ce(a)
818
829
  });
819
830
  break;
820
831
  case "RUNNING":
@@ -833,7 +844,7 @@ async function Y(e, t, s) {
833
844
  message: "Space is building...",
834
845
  detail: o
835
846
  }), setTimeout(() => {
836
- Y(e, t, s);
847
+ Q(e, t, s);
837
848
  }, 1e3);
838
849
  break;
839
850
  case "APP_STARTING":
@@ -843,7 +854,7 @@ async function Y(e, t, s) {
843
854
  message: "Space is starting...",
844
855
  detail: o
845
856
  }), setTimeout(() => {
846
- Y(e, t, s);
857
+ Q(e, t, s);
847
858
  }, 1e3);
848
859
  break;
849
860
  default:
@@ -852,27 +863,27 @@ async function Y(e, t, s) {
852
863
  load_status: "error",
853
864
  message: "This space is experiencing an issue.",
854
865
  detail: o,
855
- discussions_enabled: await De(a)
866
+ discussions_enabled: await Ce(a)
856
867
  });
857
868
  break;
858
869
  }
859
870
  }
860
- const Me = async (e, t) => {
871
+ const Ge = async (e, t) => {
861
872
  let s = 0;
862
873
  const n = 12, i = 5e3;
863
874
  return new Promise((r) => {
864
- Y(
875
+ Q(
865
876
  e,
866
- ge.test(e) ? "space_name" : "subdomain",
877
+ me.test(e) ? "space_name" : "subdomain",
867
878
  (o) => {
868
879
  t(o), o.status === "running" || o.status === "error" || o.status === "paused" || o.status === "space_error" ? r() : (o.status === "sleeping" || o.status === "building") && (s < n ? (s++, setTimeout(() => {
869
- Me(e, t).then(r);
880
+ Ge(e, t).then(r);
870
881
  }, i)) : r());
871
882
  }
872
883
  );
873
884
  });
874
- }, zt = /^(?=[^]*\b[dD]iscussions{0,1}\b)(?=[^]*\b[dD]isabled\b)[^]*$/;
875
- async function De(e) {
885
+ }, Ft = /^(?=[^]*\b[dD]iscussions{0,1}\b)(?=[^]*\b[dD]isabled\b)[^]*$/;
886
+ async function Ce(e) {
876
887
  try {
877
888
  const t = await fetch(
878
889
  `https://huggingface.co/api/spaces/${e}/discussions`,
@@ -880,17 +891,17 @@ async function De(e) {
880
891
  method: "HEAD"
881
892
  }
882
893
  ), s = t.headers.get("x-error-message");
883
- return !(!t.ok || s && zt.test(s));
894
+ return !(!t.ok || s && Ft.test(s));
884
895
  } catch {
885
896
  return !1;
886
897
  }
887
898
  }
888
- async function Bt(e, t) {
899
+ async function Gt(e, t) {
889
900
  const s = {};
890
901
  t && (s.Authorization = `Bearer ${t}`);
891
902
  try {
892
903
  const n = await fetch(
893
- `https://huggingface.co/api/spaces/${e}/${ot}`,
904
+ `https://huggingface.co/api/spaces/${e}/${rt}`,
894
905
  { headers: s }
895
906
  );
896
907
  if (n.status !== 200)
@@ -901,7 +912,7 @@ async function Bt(e, t) {
901
912
  throw new Error(n.message);
902
913
  }
903
914
  }
904
- async function Ft(e, t, s) {
915
+ async function Mt(e, t, s) {
905
916
  const n = {};
906
917
  s && (n.Authorization = `Bearer ${s}`);
907
918
  const i = {
@@ -909,7 +920,7 @@ async function Ft(e, t, s) {
909
920
  };
910
921
  try {
911
922
  const r = await fetch(
912
- `https://huggingface.co/api/spaces/${e}/${rt}`,
923
+ `https://huggingface.co/api/spaces/${e}/${at}`,
913
924
  {
914
925
  method: "POST",
915
926
  headers: { "Content-Type": "application/json", ...n },
@@ -925,7 +936,7 @@ async function Ft(e, t, s) {
925
936
  throw new Error(r.message);
926
937
  }
927
938
  }
928
- const Ae = [
939
+ const De = [
929
940
  "cpu-basic",
930
941
  "cpu-upgrade",
931
942
  "cpu-xl",
@@ -940,11 +951,11 @@ const Ae = [
940
951
  "h100",
941
952
  "h100x8"
942
953
  ];
943
- async function Gt(e, t) {
954
+ async function Jt(e, t) {
944
955
  const { hf_token: s, private: n, hardware: i, timeout: r, auth: o } = t;
945
- if (i && !Ae.includes(i))
956
+ if (i && !De.includes(i))
946
957
  throw new Error(
947
- `Invalid hardware type provided. Valid types are: ${Ae.map((_) => `"${_}"`).join(",")}.`
958
+ `Invalid hardware type provided. Valid types are: ${De.map((d) => `"${d}"`).join(",")}.`
948
959
  );
949
960
  const { http_protocol: a, host: l } = await te(
950
961
  e,
@@ -952,13 +963,13 @@ async function Gt(e, t) {
952
963
  );
953
964
  let h = null;
954
965
  if (o) {
955
- const _ = await Ue(
966
+ const d = await Ue(
956
967
  a,
957
968
  l,
958
969
  o,
959
970
  fetch
960
971
  );
961
- _ && (h = ze(_));
972
+ d && (h = qe(d));
962
973
  }
963
974
  const m = {
964
975
  Authorization: `Bearer ${s}`,
@@ -972,14 +983,14 @@ async function Gt(e, t) {
972
983
  n && (E.private = !0);
973
984
  let B;
974
985
  try {
975
- i || (B = await Bt(e, s));
976
- } catch (_) {
977
- throw Error(me + _.message);
986
+ i || (B = await Gt(e, s));
987
+ } catch (d) {
988
+ throw Error(_e + d.message);
978
989
  }
979
990
  const c = i || B || "cpu-basic";
980
991
  E.hardware = c;
981
992
  try {
982
- const _ = await fetch(
993
+ const d = await fetch(
983
994
  `https://huggingface.co/api/spaces/${e}/duplicate`,
984
995
  {
985
996
  method: "POST",
@@ -987,35 +998,35 @@ async function Gt(e, t) {
987
998
  body: JSON.stringify(E)
988
999
  }
989
1000
  );
990
- if (_.status === 409)
1001
+ if (d.status === 409)
991
1002
  try {
992
1003
  return await ee.connect(`${p}/${g}`, t);
993
1004
  } catch (D) {
994
1005
  throw console.error("Failed to connect Client instance:", D), D;
995
1006
  }
996
- else if (_.status !== 200)
997
- throw new Error(_.statusText);
998
- const N = await _.json();
999
- return await Ft(`${p}/${g}`, r || 300, s), await ee.connect(
1000
- Mt(N.url),
1007
+ else if (d.status !== 200)
1008
+ throw new Error(d.statusText);
1009
+ const O = await d.json();
1010
+ return await Mt(`${p}/${g}`, r || 300, s), await ee.connect(
1011
+ Wt(O.url),
1001
1012
  t
1002
1013
  );
1003
- } catch (_) {
1004
- throw new Error(_);
1014
+ } catch (d) {
1015
+ throw new Error(d);
1005
1016
  }
1006
1017
  }
1007
- function Mt(e) {
1018
+ function Wt(e) {
1008
1019
  const t = /https:\/\/huggingface.co\/spaces\/([^/]+\/[^/]+)/, s = e.match(t);
1009
1020
  if (s)
1010
1021
  return s[1];
1011
1022
  }
1012
1023
  var I;
1013
- class Jt extends TransformStream {
1024
+ class Ht extends TransformStream {
1014
1025
  /** Constructs a new instance. */
1015
1026
  constructor(s = { allowCR: !1 }) {
1016
1027
  super({
1017
1028
  transform: (n, i) => {
1018
- for (n = V(this, I) + n; ; ) {
1029
+ for (n = H(this, I) + n; ; ) {
1019
1030
  const r = n.indexOf(`
1020
1031
  `), o = s.allowCR ? n.indexOf("\r") : -1;
1021
1032
  if (o !== -1 && o !== n.length - 1 && (r === -1 || r - 1 > o)) {
@@ -1027,24 +1038,24 @@ class Jt extends TransformStream {
1027
1038
  const a = n[r - 1] === "\r" ? r - 1 : r;
1028
1039
  i.enqueue(n.slice(0, a)), n = n.slice(r + 1);
1029
1040
  }
1030
- Re(this, I, n);
1041
+ ke(this, I, n);
1031
1042
  },
1032
1043
  flush: (n) => {
1033
- if (V(this, I) === "")
1044
+ if (H(this, I) === "")
1034
1045
  return;
1035
- const i = s.allowCR && V(this, I).endsWith("\r") ? V(this, I).slice(0, -1) : V(this, I);
1046
+ const i = s.allowCR && H(this, I).endsWith("\r") ? H(this, I).slice(0, -1) : H(this, I);
1036
1047
  n.enqueue(i);
1037
1048
  }
1038
1049
  });
1039
- ke(this, I, "");
1050
+ $e(this, I, "");
1040
1051
  }
1041
1052
  }
1042
1053
  I = new WeakMap();
1043
- function Wt(e) {
1044
- let t = new TextDecoderStream(), s = new Jt({ allowCR: !0 });
1054
+ function Vt(e) {
1055
+ let t = new TextDecoderStream(), s = new Ht({ allowCR: !0 });
1045
1056
  return e.pipeThrough(t).pipeThrough(s);
1046
1057
  }
1047
- function Ht(e) {
1058
+ function Zt(e) {
1048
1059
  let s = /[:]\s*/.exec(e), n = s && s.index;
1049
1060
  if (n)
1050
1061
  return [
@@ -1052,13 +1063,13 @@ function Ht(e) {
1052
1063
  e.substring(n + s[0].length)
1053
1064
  ];
1054
1065
  }
1055
- function Le(e, t, s) {
1066
+ function Ae(e, t, s) {
1056
1067
  e.get(t) || e.set(t, s);
1057
1068
  }
1058
- async function* Vt(e, t) {
1069
+ async function* Kt(e, t) {
1059
1070
  if (!e.body)
1060
1071
  return;
1061
- let s = Wt(e.body), n, i = s.getReader(), r;
1072
+ let s = Vt(e.body), n, i = s.getReader(), r;
1062
1073
  for (; ; ) {
1063
1074
  if (t && t.aborted)
1064
1075
  return i.cancel();
@@ -1068,20 +1079,20 @@ async function* Vt(e, t) {
1068
1079
  r && (yield r), r = void 0;
1069
1080
  continue;
1070
1081
  }
1071
- let [o, a] = Ht(n.value) || [];
1082
+ let [o, a] = Zt(n.value) || [];
1072
1083
  o && (o === "data" ? (r || (r = {}), r[o] = r[o] ? r[o] + `
1073
1084
  ` + a : a) : o === "event" ? (r || (r = {}), r[o] = a) : o === "id" ? (r || (r = {}), r[o] = +a || a) : o === "retry" && (r || (r = {}), r[o] = +a || void 0));
1074
1085
  }
1075
1086
  }
1076
- async function Zt(e, t) {
1087
+ async function Qt(e, t) {
1077
1088
  let s = new Request(e, t);
1078
- Le(s.headers, "Accept", "text/event-stream"), Le(s.headers, "Content-Type", "application/json");
1089
+ Ae(s.headers, "Accept", "text/event-stream"), Ae(s.headers, "Content-Type", "application/json");
1079
1090
  let n = await fetch(s);
1080
1091
  if (!n.ok)
1081
1092
  throw n;
1082
- return Vt(n, s.signal);
1093
+ return Kt(n, s.signal);
1083
1094
  }
1084
- async function Kt() {
1095
+ async function Xt() {
1085
1096
  let {
1086
1097
  event_callbacks: e,
1087
1098
  unclosed_events: t,
@@ -1096,7 +1107,7 @@ async function Kt() {
1096
1107
  n.open = !0;
1097
1108
  let a = null, l = new URLSearchParams({
1098
1109
  session_hash: this.session_hash
1099
- }).toString(), h = new URL(`${i.root}${this.api_prefix}/${je}?${l}`);
1110
+ }).toString(), h = new URL(`${i.root}${this.api_prefix}/${Pe}?${l}`);
1100
1111
  if (r && h.searchParams.set("__sign", r), a = this.stream(h), !a) {
1101
1112
  console.warn("Cannot connect to SSE endpoint: " + h.toString());
1102
1113
  return;
@@ -1104,7 +1115,7 @@ async function Kt() {
1104
1115
  a.onmessage = async function(m) {
1105
1116
  let p = JSON.parse(m.data);
1106
1117
  if (p.msg === "close_stream") {
1107
- we(n, o.abort_controller);
1118
+ ge(n, o.abort_controller);
1108
1119
  return;
1109
1120
  }
1110
1121
  const g = p.event_id;
@@ -1122,34 +1133,34 @@ async function Kt() {
1122
1133
  typeof window < "u" && typeof document < "u" ? setTimeout(E, 0, p) : E(p);
1123
1134
  } else
1124
1135
  s[g] || (s[g] = []), s[g].push(p);
1125
- }, a.onerror = async function() {
1126
- await Promise.all(
1136
+ }, a.onerror = async function(m) {
1137
+ console.error(m), await Promise.all(
1127
1138
  Object.keys(e).map(
1128
- (m) => e[m]({
1129
- msg: "unexpected_error",
1130
- message: J
1139
+ (p) => e[p]({
1140
+ msg: "broken_connection",
1141
+ message: M
1131
1142
  })
1132
1143
  )
1133
1144
  );
1134
1145
  };
1135
1146
  }
1136
- function we(e, t) {
1147
+ function ge(e, t) {
1137
1148
  e && (e.open = !1, t == null || t.abort());
1138
1149
  }
1139
- function Qt(e, t, s) {
1150
+ function Yt(e, t, s) {
1140
1151
  !e[t] ? (e[t] = [], s.data.forEach((i, r) => {
1141
1152
  e[t][r] = i;
1142
1153
  })) : s.data.forEach((i, r) => {
1143
- let o = Xt(e[t][r], i);
1154
+ let o = es(e[t][r], i);
1144
1155
  e[t][r] = o, s.data[r] = o;
1145
1156
  });
1146
1157
  }
1147
- function Xt(e, t) {
1158
+ function es(e, t) {
1148
1159
  return t.forEach(([s, n, i]) => {
1149
- e = Yt(e, n, s, i);
1160
+ e = ts(e, n, s, i);
1150
1161
  }), e;
1151
1162
  }
1152
- function Yt(e, t, s, n) {
1163
+ function ts(e, t, s, n) {
1153
1164
  if (t.length === 0) {
1154
1165
  if (s === "replace")
1155
1166
  return n;
@@ -1179,7 +1190,7 @@ function Yt(e, t, s, n) {
1179
1190
  }
1180
1191
  return e;
1181
1192
  }
1182
- function es(e, t = {}) {
1193
+ function ss(e, t = {}) {
1183
1194
  const s = {
1184
1195
  close: () => {
1185
1196
  console.warn("Method not implemented.");
@@ -1203,7 +1214,7 @@ function es(e, t = {}) {
1203
1214
  throw new Error("Method not implemented.");
1204
1215
  }
1205
1216
  };
1206
- return Zt(e, t).then(async (n) => {
1217
+ return Qt(e, t).then(async (n) => {
1207
1218
  s.readyState = s.OPEN;
1208
1219
  try {
1209
1220
  for await (const i of n)
@@ -1216,85 +1227,74 @@ function es(e, t = {}) {
1216
1227
  console.error(n), s.onerror && s.onerror(n), s.readyState = s.CLOSED;
1217
1228
  }), s;
1218
1229
  }
1219
- function ts(e, t = {}, s, n, i) {
1230
+ function ns(e, t = {}, s, n, i) {
1220
1231
  var r;
1221
1232
  try {
1222
1233
  let o = function(w) {
1223
- (i || Ze[w.type]) && m(w);
1234
+ (i || Ve[w.type]) && m(w);
1224
1235
  }, a = function() {
1225
- for (le = !0; K.length > 0; )
1226
- K.shift()({
1236
+ for (Qe = !0; Z.length > 0; )
1237
+ Z.shift()({
1227
1238
  value: void 0,
1228
1239
  done: !0
1229
1240
  });
1230
1241
  }, l = function(w) {
1231
- le || (K.length > 0 ? K.shift()(w) : ue.push(w));
1242
+ Z.length > 0 ? Z.shift()(w) : le.push(w);
1232
1243
  }, h = function(w) {
1233
- l(ss(w)), a();
1244
+ l(is(w)), a();
1234
1245
  }, m = function(w) {
1235
1246
  l({ value: w, done: !1 });
1236
1247
  }, p = function() {
1237
- return ue.length > 0 ? Promise.resolve(ue.shift()) : le ? Promise.resolve({ value: void 0, done: !0 }) : new Promise((w) => K.push(w));
1248
+ return le.length > 0 ? Promise.resolve(le.shift()) : new Promise((w) => Z.push(w));
1238
1249
  };
1239
1250
  const { hf_token: g } = this.options, {
1240
1251
  fetch: E,
1241
1252
  app_reference: B,
1242
1253
  config: c,
1243
- session_hash: _,
1244
- api_info: N,
1254
+ session_hash: d,
1255
+ api_info: O,
1245
1256
  api_map: D,
1246
1257
  stream_status: ne,
1247
1258
  pending_stream_messages: ie,
1248
1259
  pending_diff_streams: oe,
1249
1260
  event_callbacks: re,
1250
- unclosed_events: Je,
1261
+ unclosed_events: Me,
1251
1262
  post_data: ae,
1252
1263
  options: F,
1253
- api_prefix: W
1254
- } = this, We = this;
1255
- if (!N)
1264
+ api_prefix: J
1265
+ } = this, Je = this;
1266
+ if (!O)
1256
1267
  throw new Error("No API found");
1257
1268
  if (!c)
1258
1269
  throw new Error("Could not resolve app config");
1259
- let { fn_index: f, endpoint_info: ye, dependency: H } = ns(
1260
- N,
1270
+ let { fn_index: f, endpoint_info: we, dependency: W } = os(
1271
+ O,
1261
1272
  e,
1262
1273
  D,
1263
1274
  c
1264
- ), He = Nt(t, ye), R, T, P = c.protocol ?? "ws", be = "", Ve = () => be;
1265
- const d = typeof e == "number" ? "/predict" : e;
1266
- let Z, S = null, O = !1, ce = {}, G = typeof window < "u" && typeof document < "u" ? new URLSearchParams(window.location.search).toString() : "";
1267
- const Ze = ((r = F == null ? void 0 : F.events) == null ? void 0 : r.reduce(
1268
- (w, j) => (w[j] = !0, w),
1275
+ ), We = Ct(t, we), R, N, j = c.protocol ?? "ws", ye = "", He = () => ye;
1276
+ const _ = typeof e == "number" ? "/predict" : e;
1277
+ let V, S = null, T = !1, ce = {}, G = typeof window < "u" && typeof document < "u" ? new URLSearchParams(window.location.search).toString() : "";
1278
+ const Ve = ((r = F == null ? void 0 : F.events) == null ? void 0 : r.reduce(
1279
+ (w, x) => (w[x] = !0, w),
1269
1280
  {}
1270
1281
  )) || {};
1271
- async function Ke() {
1272
- const w = {
1273
- stage: "complete",
1274
- queue: !1,
1275
- time: /* @__PURE__ */ new Date()
1276
- };
1277
- O = w, o({
1278
- ...w,
1279
- type: "status",
1280
- endpoint: d,
1281
- fn_index: f
1282
- });
1283
- let j = {}, M = {};
1284
- P === "ws" ? (R && R.readyState === 0 ? R.addEventListener("open", () => {
1282
+ async function Ze() {
1283
+ let w = {}, x = {};
1284
+ j === "ws" ? (R && R.readyState === 0 ? R.addEventListener("open", () => {
1285
1285
  R.close();
1286
- }) : R.close(), j = { fn_index: f, session_hash: _ }) : (j = { event_id: S }, M = { event_id: S, session_hash: _, fn_index: f });
1286
+ }) : R.close(), w = { fn_index: f, session_hash: d }) : (w = { event_id: S }, x = { event_id: S, session_hash: d, fn_index: f });
1287
1287
  try {
1288
1288
  if (!c)
1289
1289
  throw new Error("Could not resolve app config");
1290
- "event_id" in M && await E(`${c.root}${W}/${ut}`, {
1290
+ "event_id" in x && await E(`${c.root}${J}/${pt}`, {
1291
1291
  headers: { "Content-Type": "application/json" },
1292
1292
  method: "POST",
1293
- body: JSON.stringify(M)
1294
- }), await E(`${c.root}${W}/${lt}`, {
1293
+ body: JSON.stringify(x)
1294
+ }), await E(`${c.root}${J}/${ut}`, {
1295
1295
  headers: { "Content-Type": "application/json" },
1296
1296
  method: "POST",
1297
- body: JSON.stringify(j)
1297
+ body: JSON.stringify(w)
1298
1298
  });
1299
1299
  } catch {
1300
1300
  console.warn(
@@ -1302,37 +1302,37 @@ function ts(e, t = {}, s, n, i) {
1302
1302
  );
1303
1303
  }
1304
1304
  }
1305
- const Qe = async (w) => {
1306
- await this._resolve_hearbeat(w);
1305
+ const Ke = async (w) => {
1306
+ await this._resolve_heartbeat(w);
1307
1307
  };
1308
- async function ve(w) {
1308
+ async function be(w) {
1309
1309
  if (!c)
1310
1310
  return;
1311
- let j = w.render_id;
1311
+ let x = w.render_id;
1312
1312
  c.components = [
1313
- ...c.components.filter((y) => y.props.rendered_in !== j),
1313
+ ...c.components.filter((y) => y.props.rendered_in !== x),
1314
1314
  ...w.components
1315
1315
  ], c.dependencies = [
1316
- ...c.dependencies.filter((y) => y.rendered_in !== j),
1316
+ ...c.dependencies.filter((y) => y.rendered_in !== x),
1317
1317
  ...w.dependencies
1318
1318
  ];
1319
- const M = c.components.some((y) => y.type === "state"), Q = c.dependencies.some(
1320
- (y) => y.targets.some((q) => q[1] === "unload")
1319
+ const X = c.components.some((y) => y.type === "state"), Y = c.dependencies.some(
1320
+ (y) => y.targets.some((U) => U[1] === "unload")
1321
1321
  );
1322
- c.connect_heartbeat = M || Q, await Qe(c), o({
1322
+ c.connect_heartbeat = X || Y, await Ke(c), o({
1323
1323
  type: "render",
1324
1324
  data: w,
1325
- endpoint: d,
1325
+ endpoint: _,
1326
1326
  fn_index: f
1327
1327
  });
1328
1328
  }
1329
- this.handle_blob(c.root, He, ye).then(
1329
+ this.handle_blob(c.root, We, we).then(
1330
1330
  async (w) => {
1331
- var Q;
1332
- if (Z = {
1333
- data: X(
1331
+ var Y;
1332
+ if (V = {
1333
+ data: K(
1334
1334
  w,
1335
- H,
1335
+ W,
1336
1336
  c.components,
1337
1337
  "input",
1338
1338
  !0
@@ -1340,29 +1340,29 @@ function ts(e, t = {}, s, n, i) {
1340
1340
  event_data: s,
1341
1341
  fn_index: f,
1342
1342
  trigger_id: n
1343
- }, Lt(f, c))
1343
+ }, jt(f, c))
1344
1344
  o({
1345
1345
  type: "status",
1346
- endpoint: d,
1346
+ endpoint: _,
1347
1347
  stage: "pending",
1348
1348
  queue: !1,
1349
1349
  fn_index: f,
1350
1350
  time: /* @__PURE__ */ new Date()
1351
1351
  }), ae(
1352
- `${c.root}${W}/run${d.startsWith("/") ? d : `/${d}`}${G ? "?" + G : ""}`,
1352
+ `${c.root}${J}/run${_.startsWith("/") ? _ : `/${_}`}${G ? "?" + G : ""}`,
1353
1353
  {
1354
- ...Z,
1355
- session_hash: _
1354
+ ...V,
1355
+ session_hash: d
1356
1356
  }
1357
- ).then(([y, q]) => {
1358
- const U = y.data;
1359
- q == 200 ? (o({
1357
+ ).then(([y, U]) => {
1358
+ const q = y.data;
1359
+ U == 200 ? (o({
1360
1360
  type: "data",
1361
- endpoint: d,
1361
+ endpoint: _,
1362
1362
  fn_index: f,
1363
- data: X(
1364
- U,
1365
- H,
1363
+ data: K(
1364
+ q,
1365
+ W,
1366
1366
  c.components,
1367
1367
  "output",
1368
1368
  F.with_null_state
@@ -1370,9 +1370,9 @@ function ts(e, t = {}, s, n, i) {
1370
1370
  time: /* @__PURE__ */ new Date(),
1371
1371
  event_data: s,
1372
1372
  trigger_id: n
1373
- }), y.render_config && ve(y.render_config), o({
1373
+ }), y.render_config && be(y.render_config), o({
1374
1374
  type: "status",
1375
- endpoint: d,
1375
+ endpoint: _,
1376
1376
  fn_index: f,
1377
1377
  stage: "complete",
1378
1378
  eta: y.average_duration,
@@ -1381,7 +1381,7 @@ function ts(e, t = {}, s, n, i) {
1381
1381
  })) : o({
1382
1382
  type: "status",
1383
1383
  stage: "error",
1384
- endpoint: d,
1384
+ endpoint: _,
1385
1385
  fn_index: f,
1386
1386
  message: y.error,
1387
1387
  queue: !1,
@@ -1392,14 +1392,14 @@ function ts(e, t = {}, s, n, i) {
1392
1392
  type: "status",
1393
1393
  stage: "error",
1394
1394
  message: y.message,
1395
- endpoint: d,
1395
+ endpoint: _,
1396
1396
  fn_index: f,
1397
1397
  queue: !1,
1398
1398
  time: /* @__PURE__ */ new Date()
1399
1399
  });
1400
1400
  });
1401
- else if (P == "ws") {
1402
- const { ws_protocol: y, host: q } = await te(
1401
+ else if (j == "ws") {
1402
+ const { ws_protocol: y, host: U } = await te(
1403
1403
  B,
1404
1404
  g
1405
1405
  );
@@ -1407,51 +1407,51 @@ function ts(e, t = {}, s, n, i) {
1407
1407
  type: "status",
1408
1408
  stage: "pending",
1409
1409
  queue: !0,
1410
- endpoint: d,
1410
+ endpoint: _,
1411
1411
  fn_index: f,
1412
1412
  time: /* @__PURE__ */ new Date()
1413
1413
  });
1414
- let U = new URL(
1415
- `${y}://${yt(
1416
- q,
1414
+ let q = new URL(
1415
+ `${y}://${vt(
1416
+ U,
1417
1417
  c.root,
1418
1418
  !0
1419
1419
  )}/queue/join${G ? "?" + G : ""}`
1420
1420
  );
1421
- this.jwt && U.searchParams.set("__sign", this.jwt), R = new WebSocket(U), R.onclose = (A) => {
1421
+ this.jwt && q.searchParams.set("__sign", this.jwt), R = new WebSocket(q), R.onclose = (A) => {
1422
1422
  A.wasClean || o({
1423
1423
  type: "status",
1424
1424
  stage: "error",
1425
1425
  broken: !0,
1426
- message: J,
1426
+ message: M,
1427
1427
  queue: !0,
1428
- endpoint: d,
1428
+ endpoint: _,
1429
1429
  fn_index: f,
1430
1430
  time: /* @__PURE__ */ new Date()
1431
1431
  });
1432
1432
  }, R.onmessage = function(A) {
1433
- const k = JSON.parse(A.data), { type: $, status: v, data: C } = de(
1433
+ const k = JSON.parse(A.data), { type: $, status: v, data: C } = he(
1434
1434
  k,
1435
1435
  ce[f]
1436
1436
  );
1437
- if ($ === "update" && v && !O)
1437
+ if ($ === "update" && v && !T)
1438
1438
  o({
1439
1439
  type: "status",
1440
- endpoint: d,
1440
+ endpoint: _,
1441
1441
  fn_index: f,
1442
1442
  time: /* @__PURE__ */ new Date(),
1443
1443
  ...v
1444
1444
  }), v.stage === "error" && R.close();
1445
1445
  else if ($ === "hash") {
1446
- R.send(JSON.stringify({ fn_index: f, session_hash: _ }));
1446
+ R.send(JSON.stringify({ fn_index: f, session_hash: d }));
1447
1447
  return;
1448
1448
  } else
1449
- $ === "data" ? R.send(JSON.stringify({ ...Z, session_hash: _ })) : $ === "complete" ? O = v : $ === "log" ? o({
1449
+ $ === "data" ? R.send(JSON.stringify({ ...V, session_hash: d })) : $ === "complete" ? T = v : $ === "log" ? o({
1450
1450
  type: "log",
1451
1451
  title: C.title,
1452
1452
  log: C.log,
1453
1453
  level: C.level,
1454
- endpoint: d,
1454
+ endpoint: _,
1455
1455
  duration: C.duration,
1456
1456
  visible: C.visible,
1457
1457
  fn_index: f
@@ -1461,94 +1461,94 @@ function ts(e, t = {}, s, n, i) {
1461
1461
  ...v,
1462
1462
  stage: v == null ? void 0 : v.stage,
1463
1463
  queue: !0,
1464
- endpoint: d,
1464
+ endpoint: _,
1465
1465
  fn_index: f
1466
1466
  });
1467
1467
  C && (o({
1468
1468
  type: "data",
1469
1469
  time: /* @__PURE__ */ new Date(),
1470
- data: X(
1470
+ data: K(
1471
1471
  C.data,
1472
- H,
1472
+ W,
1473
1473
  c.components,
1474
1474
  "output",
1475
1475
  F.with_null_state
1476
1476
  ),
1477
- endpoint: d,
1477
+ endpoint: _,
1478
1478
  fn_index: f,
1479
1479
  event_data: s,
1480
1480
  trigger_id: n
1481
- }), O && (o({
1481
+ }), T && (o({
1482
1482
  type: "status",
1483
1483
  time: /* @__PURE__ */ new Date(),
1484
- ...O,
1484
+ ...T,
1485
1485
  stage: v == null ? void 0 : v.stage,
1486
1486
  queue: !0,
1487
- endpoint: d,
1487
+ endpoint: _,
1488
1488
  fn_index: f
1489
1489
  }), R.close()));
1490
- }, Pe(c.version || "2.0.0", "3.6") < 0 && addEventListener(
1490
+ }, Le(c.version || "2.0.0", "3.6") < 0 && addEventListener(
1491
1491
  "open",
1492
- () => R.send(JSON.stringify({ hash: _ }))
1492
+ () => R.send(JSON.stringify({ hash: d }))
1493
1493
  );
1494
- } else if (P == "sse") {
1494
+ } else if (j == "sse") {
1495
1495
  o({
1496
1496
  type: "status",
1497
1497
  stage: "pending",
1498
1498
  queue: !0,
1499
- endpoint: d,
1499
+ endpoint: _,
1500
1500
  fn_index: f,
1501
1501
  time: /* @__PURE__ */ new Date()
1502
1502
  });
1503
- var M = new URLSearchParams({
1503
+ var X = new URLSearchParams({
1504
1504
  fn_index: f.toString(),
1505
- session_hash: _
1505
+ session_hash: d
1506
1506
  }).toString();
1507
1507
  let y = new URL(
1508
- `${c.root}${W}/${je}?${G ? G + "&" : ""}${M}`
1508
+ `${c.root}${J}/${Pe}?${G ? G + "&" : ""}${X}`
1509
1509
  );
1510
- if (this.jwt && y.searchParams.set("__sign", this.jwt), T = this.stream(y), !T)
1510
+ if (this.jwt && y.searchParams.set("__sign", this.jwt), N = this.stream(y), !N)
1511
1511
  return Promise.reject(
1512
1512
  new Error("Cannot connect to SSE endpoint: " + y.toString())
1513
1513
  );
1514
- T.onmessage = async function(q) {
1515
- const U = JSON.parse(q.data), { type: A, status: k, data: $ } = de(
1516
- U,
1514
+ N.onmessage = async function(U) {
1515
+ const q = JSON.parse(U.data), { type: A, status: k, data: $ } = he(
1516
+ q,
1517
1517
  ce[f]
1518
1518
  );
1519
- if (A === "update" && k && !O)
1519
+ if (A === "update" && k && !T)
1520
1520
  o({
1521
1521
  type: "status",
1522
- endpoint: d,
1522
+ endpoint: _,
1523
1523
  fn_index: f,
1524
1524
  time: /* @__PURE__ */ new Date(),
1525
1525
  ...k
1526
- }), k.stage === "error" && (T == null || T.close(), a());
1526
+ }), k.stage === "error" && (N == null || N.close(), a());
1527
1527
  else if (A === "data") {
1528
1528
  let [v, C] = await ae(
1529
- `${c.root}${W}/queue/data`,
1529
+ `${c.root}${J}/queue/data`,
1530
1530
  {
1531
- ...Z,
1532
- session_hash: _,
1531
+ ...V,
1532
+ session_hash: d,
1533
1533
  event_id: S
1534
1534
  }
1535
1535
  );
1536
1536
  C !== 200 && (o({
1537
1537
  type: "status",
1538
1538
  stage: "error",
1539
- message: J,
1539
+ message: M,
1540
1540
  queue: !0,
1541
- endpoint: d,
1541
+ endpoint: _,
1542
1542
  fn_index: f,
1543
1543
  time: /* @__PURE__ */ new Date()
1544
- }), T == null || T.close(), a());
1544
+ }), N == null || N.close(), a());
1545
1545
  } else
1546
- A === "complete" ? O = k : A === "log" ? o({
1546
+ A === "complete" ? T = k : A === "log" ? o({
1547
1547
  type: "log",
1548
1548
  title: $.title,
1549
1549
  log: $.log,
1550
1550
  level: $.level,
1551
- endpoint: d,
1551
+ endpoint: _,
1552
1552
  duration: $.duration,
1553
1553
  visible: $.visible,
1554
1554
  fn_index: f
@@ -1558,50 +1558,50 @@ function ts(e, t = {}, s, n, i) {
1558
1558
  ...k,
1559
1559
  stage: k == null ? void 0 : k.stage,
1560
1560
  queue: !0,
1561
- endpoint: d,
1561
+ endpoint: _,
1562
1562
  fn_index: f
1563
1563
  });
1564
1564
  $ && (o({
1565
1565
  type: "data",
1566
1566
  time: /* @__PURE__ */ new Date(),
1567
- data: X(
1567
+ data: K(
1568
1568
  $.data,
1569
- H,
1569
+ W,
1570
1570
  c.components,
1571
1571
  "output",
1572
1572
  F.with_null_state
1573
1573
  ),
1574
- endpoint: d,
1574
+ endpoint: _,
1575
1575
  fn_index: f,
1576
1576
  event_data: s,
1577
1577
  trigger_id: n
1578
- }), O && (o({
1578
+ }), T && (o({
1579
1579
  type: "status",
1580
1580
  time: /* @__PURE__ */ new Date(),
1581
- ...O,
1581
+ ...T,
1582
1582
  stage: k == null ? void 0 : k.stage,
1583
1583
  queue: !0,
1584
- endpoint: d,
1584
+ endpoint: _,
1585
1585
  fn_index: f
1586
- }), T == null || T.close(), a()));
1586
+ }), N == null || N.close(), a()));
1587
1587
  };
1588
- } else if (P == "sse_v1" || P == "sse_v2" || P == "sse_v2.1" || P == "sse_v3") {
1588
+ } else if (j == "sse_v1" || j == "sse_v2" || j == "sse_v2.1" || j == "sse_v3") {
1589
1589
  o({
1590
1590
  type: "status",
1591
1591
  stage: "pending",
1592
1592
  queue: !0,
1593
- endpoint: d,
1593
+ endpoint: _,
1594
1594
  fn_index: f,
1595
1595
  time: /* @__PURE__ */ new Date()
1596
1596
  });
1597
1597
  let y = "";
1598
- typeof window < "u" && typeof document < "u" && (y = (Q = window == null ? void 0 : window.location) == null ? void 0 : Q.hostname);
1599
- const U = y.includes(".dev.") ? `https://moon-${y.split(".")[1]}.dev.spaces.huggingface.tech` : "https://huggingface.co";
1600
- (typeof window < "u" && typeof document < "u" && window.parent != window && window.supports_zerogpu_headers ? Pt("zerogpu-headers", U) : Promise.resolve(null)).then((v) => ae(
1601
- `${c.root}${W}/${st}?${G}`,
1598
+ typeof window < "u" && typeof document < "u" && (y = (Y = window == null ? void 0 : window.location) == null ? void 0 : Y.hostname);
1599
+ const q = y.includes(".dev.") ? `https://moon-${y.split(".")[1]}.dev.spaces.huggingface.tech` : "https://huggingface.co";
1600
+ (typeof window < "u" && typeof document < "u" && window.parent != window && window.supports_zerogpu_headers ? xt("zerogpu-headers", q) : Promise.resolve(null)).then((v) => ae(
1601
+ `${c.root}${J}/${nt}?${G}`,
1602
1602
  {
1603
- ...Z,
1604
- session_hash: _
1603
+ ...V,
1604
+ session_hash: d
1605
1605
  },
1606
1606
  v
1607
1607
  )).then(async ([v, C]) => {
@@ -1609,9 +1609,9 @@ function ts(e, t = {}, s, n, i) {
1609
1609
  o({
1610
1610
  type: "status",
1611
1611
  stage: "error",
1612
- message: xe,
1612
+ message: je,
1613
1613
  queue: !0,
1614
- endpoint: d,
1614
+ endpoint: _,
1615
1615
  fn_index: f,
1616
1616
  time: /* @__PURE__ */ new Date()
1617
1617
  });
@@ -1619,126 +1619,131 @@ function ts(e, t = {}, s, n, i) {
1619
1619
  o({
1620
1620
  type: "status",
1621
1621
  stage: "error",
1622
- message: J,
1622
+ broken: !0,
1623
+ message: M,
1623
1624
  queue: !0,
1624
- endpoint: d,
1625
+ endpoint: _,
1625
1626
  fn_index: f,
1626
1627
  time: /* @__PURE__ */ new Date()
1627
1628
  });
1628
1629
  else {
1629
- S = v.event_id, be = S;
1630
- let Se = async function(pe) {
1630
+ S = v.event_id, ye = S;
1631
+ let Ee = async function(ue) {
1631
1632
  try {
1632
- const { type: x, status: b, data: L, original_msg: Xe } = de(
1633
- pe,
1633
+ const { type: L, status: b, data: P, original_msg: Xe } = he(
1634
+ ue,
1634
1635
  ce[f]
1635
1636
  );
1636
- if (x == "heartbeat")
1637
+ if (L == "heartbeat")
1637
1638
  return;
1638
- if (x === "update" && b && !O)
1639
+ if (L === "update" && b && !T)
1639
1640
  o({
1640
1641
  type: "status",
1641
- endpoint: d,
1642
+ endpoint: _,
1642
1643
  fn_index: f,
1643
1644
  time: /* @__PURE__ */ new Date(),
1644
1645
  original_msg: Xe,
1645
1646
  ...b
1646
1647
  });
1647
- else if (x === "complete")
1648
- O = b;
1649
- else if (x == "unexpected_error")
1650
- console.error("Unexpected error", b == null ? void 0 : b.message), o({
1648
+ else if (L === "complete")
1649
+ T = b;
1650
+ else if (L == "unexpected_error" || L == "broken_connection") {
1651
+ console.error("Unexpected error", b == null ? void 0 : b.message);
1652
+ const Ye = L === "broken_connection";
1653
+ o({
1651
1654
  type: "status",
1652
1655
  stage: "error",
1653
1656
  message: (b == null ? void 0 : b.message) || "An Unexpected Error Occurred!",
1654
1657
  queue: !0,
1655
- endpoint: d,
1658
+ endpoint: _,
1659
+ broken: Ye,
1660
+ session_not_found: b == null ? void 0 : b.session_not_found,
1656
1661
  fn_index: f,
1657
1662
  time: /* @__PURE__ */ new Date()
1658
1663
  });
1659
- else if (x === "log") {
1664
+ } else if (L === "log") {
1660
1665
  o({
1661
1666
  type: "log",
1662
- title: L.title,
1663
- log: L.log,
1664
- level: L.level,
1665
- endpoint: d,
1666
- duration: L.duration,
1667
- visible: L.visible,
1667
+ title: P.title,
1668
+ log: P.log,
1669
+ level: P.level,
1670
+ endpoint: _,
1671
+ duration: P.duration,
1672
+ visible: P.visible,
1668
1673
  fn_index: f
1669
1674
  });
1670
1675
  return;
1671
1676
  } else
1672
- (x === "generating" || x === "streaming") && (o({
1677
+ (L === "generating" || L === "streaming") && (o({
1673
1678
  type: "status",
1674
1679
  time: /* @__PURE__ */ new Date(),
1675
1680
  ...b,
1676
1681
  stage: b == null ? void 0 : b.stage,
1677
1682
  queue: !0,
1678
- endpoint: d,
1683
+ endpoint: _,
1679
1684
  fn_index: f
1680
- }), L && H.connection !== "stream" && ["sse_v2", "sse_v2.1", "sse_v3"].includes(P) && Qt(oe, S, L));
1681
- L && (o({
1685
+ }), P && W.connection !== "stream" && ["sse_v2", "sse_v2.1", "sse_v3"].includes(j) && Yt(oe, S, P));
1686
+ P && (o({
1682
1687
  type: "data",
1683
1688
  time: /* @__PURE__ */ new Date(),
1684
- data: X(
1685
- L.data,
1686
- H,
1689
+ data: K(
1690
+ P.data,
1691
+ W,
1687
1692
  c.components,
1688
1693
  "output",
1689
1694
  F.with_null_state
1690
1695
  ),
1691
- endpoint: d,
1696
+ endpoint: _,
1692
1697
  fn_index: f
1693
- }), L.render_config && await ve(L.render_config), O && (o({
1698
+ }), P.render_config && await be(P.render_config), T && (o({
1694
1699
  type: "status",
1695
1700
  time: /* @__PURE__ */ new Date(),
1696
- ...O,
1701
+ ...T,
1697
1702
  stage: b == null ? void 0 : b.stage,
1698
1703
  queue: !0,
1699
- endpoint: d,
1704
+ endpoint: _,
1700
1705
  fn_index: f
1701
1706
  }), a())), ((b == null ? void 0 : b.stage) === "complete" || (b == null ? void 0 : b.stage) === "error") && (re[S] && delete re[S], S in oe && delete oe[S]);
1702
- } catch (x) {
1703
- console.error("Unexpected client exception", x), o({
1707
+ } catch (L) {
1708
+ console.error("Unexpected client exception", L), o({
1704
1709
  type: "status",
1705
1710
  stage: "error",
1706
1711
  message: "An Unexpected Error Occurred!",
1707
1712
  queue: !0,
1708
- endpoint: d,
1713
+ endpoint: _,
1709
1714
  fn_index: f,
1710
1715
  time: /* @__PURE__ */ new Date()
1711
- }), ["sse_v2", "sse_v2.1", "sse_v3"].includes(P) && (we(ne, We.abort_controller), ne.open = !1, a());
1716
+ }), ["sse_v2", "sse_v2.1", "sse_v3"].includes(j) && (ge(ne, Je.abort_controller), ne.open = !1, a());
1712
1717
  }
1713
1718
  };
1714
1719
  S in ie && (ie[S].forEach(
1715
- (pe) => Se(pe)
1716
- ), delete ie[S]), re[S] = Se, Je.add(S), ne.open || await this.open_stream();
1720
+ (ue) => Ee(ue)
1721
+ ), delete ie[S]), re[S] = Ee, Me.add(S), ne.open || await this.open_stream();
1717
1722
  }
1718
1723
  });
1719
1724
  }
1720
1725
  }
1721
1726
  );
1722
- let le = !1;
1723
- const ue = [], K = [], Ee = {
1724
- [Symbol.asyncIterator]: () => Ee,
1727
+ let Qe = !1;
1728
+ const le = [], Z = [], ve = {
1729
+ [Symbol.asyncIterator]: () => ve,
1725
1730
  next: p,
1726
1731
  throw: async (w) => (h(w), p()),
1727
1732
  return: async () => (a(), p()),
1728
- cancel: Ke,
1729
- event_id: Ve
1733
+ cancel: Ze,
1734
+ event_id: He
1730
1735
  };
1731
- return Ee;
1736
+ return ve;
1732
1737
  } catch (o) {
1733
1738
  throw console.error("Submit function encountered an error:", o), o;
1734
1739
  }
1735
1740
  }
1736
- function ss(e) {
1741
+ function is(e) {
1737
1742
  return {
1738
1743
  then: (t, s) => s(e)
1739
1744
  };
1740
1745
  }
1741
- function ns(e, t, s, n) {
1746
+ function os(e, t, s, n) {
1742
1747
  let i, r, o;
1743
1748
  if (typeof t == "number")
1744
1749
  i = t, r = e.unnamed_endpoints[i], o = n.dependencies.find((a) => a.id == t);
@@ -1790,7 +1795,7 @@ class ee {
1790
1795
  u(this, "resolve_config");
1791
1796
  u(this, "resolve_cookies");
1792
1797
  var n;
1793
- this.app_reference = t, this.deep_link = ((n = s.query_params) == null ? void 0 : n.deep_link) || null, s.events || (s.events = ["data"]), this.options = s, this.current_payload = {}, this.view_api = Tt.bind(this), this.upload_files = Ct.bind(this), this.handle_blob = jt.bind(this), this.post_data = qt.bind(this), this.submit = ts.bind(this), this.predict = Ut.bind(this), this.open_stream = Kt.bind(this), this.resolve_config = vt.bind(this), this.resolve_cookies = St.bind(this), this.upload = Dt.bind(this), this.fetch = this.fetch.bind(this), this.handle_space_success = this.handle_space_success.bind(this), this.stream = this.stream.bind(this);
1798
+ this.app_reference = t, this.deep_link = ((n = s.query_params) == null ? void 0 : n.deep_link) || null, s.events || (s.events = ["data"]), this.options = s, this.current_payload = {}, this.view_api = Dt.bind(this), this.upload_files = At.bind(this), this.handle_blob = It.bind(this), this.post_data = zt.bind(this), this.submit = ns.bind(this), this.predict = Bt.bind(this), this.open_stream = Xt.bind(this), this.resolve_config = St.bind(this), this.resolve_cookies = kt.bind(this), this.upload = Lt.bind(this), this.fetch = this.fetch.bind(this), this.handle_space_success = this.handle_space_success.bind(this), this.stream = this.stream.bind(this);
1794
1799
  }
1795
1800
  get_url_config(t = null) {
1796
1801
  if (!this.config)
@@ -1828,7 +1833,7 @@ class ee {
1828
1833
  if (this && this.cookies && s.append("Cookie", this.cookies), this && this.options.headers)
1829
1834
  for (const n in this.options.headers)
1830
1835
  s.append(n, this.options.headers[n]);
1831
- return this && this.options.hf_token && s.append("Authorization", `Bearer ${this.options.hf_token}`), this.abort_controller = new AbortController(), this.stream_instance = es(t.toString(), {
1836
+ return this && this.options.hf_token && s.append("Authorization", `Bearer ${this.options.hf_token}`), this.abort_controller = new AbortController(), this.stream_instance = ss(t.toString(), {
1832
1837
  credentials: "include",
1833
1838
  headers: s,
1834
1839
  signal: this.abort_controller.signal
@@ -1837,17 +1842,17 @@ class ee {
1837
1842
  async init() {
1838
1843
  var t;
1839
1844
  this.options.auth && await this.resolve_cookies(), await this._resolve_config().then(
1840
- ({ config: s }) => this._resolve_hearbeat(s)
1841
- ), this.api_info = await this.view_api(), this.api_map = bt(((t = this.config) == null ? void 0 : t.dependencies) || []);
1845
+ ({ config: s }) => this._resolve_heartbeat(s)
1846
+ ), this.api_info = await this.view_api(), this.api_map = Et(((t = this.config) == null ? void 0 : t.dependencies) || []);
1842
1847
  }
1843
- async _resolve_hearbeat(t) {
1844
- if (t && (this.config = t, this.api_prefix = t.api_prefix || "", this.config && this.config.connect_heartbeat && this.config.space_id && this.options.hf_token && (this.jwt = await Te(
1848
+ async _resolve_heartbeat(t) {
1849
+ if (t && (this.config = t, this.api_prefix = t.api_prefix || "", this.config && this.config.connect_heartbeat && this.config.space_id && this.options.hf_token && (this.jwt = await Ne(
1845
1850
  this.config.space_id,
1846
1851
  this.options.hf_token,
1847
1852
  this.cookies
1848
- ))), t.space_id && this.options.hf_token && (this.jwt = await Te(t.space_id, this.options.hf_token)), this.config && this.config.connect_heartbeat) {
1853
+ ))), t.space_id && this.options.hf_token && (this.jwt = await Ne(t.space_id, this.options.hf_token)), this.config && this.config.connect_heartbeat) {
1849
1854
  const s = new URL(
1850
- `${this.config.root}${this.api_prefix}/${at}/${this.session_hash}`
1855
+ `${this.config.root}${this.api_prefix}/${ct}/${this.session_hash}`
1851
1856
  );
1852
1857
  this.jwt && s.searchParams.set("__sign", this.jwt), this.heartbeat_event || (this.heartbeat_event = this.stream(s));
1853
1858
  }
@@ -1858,8 +1863,23 @@ class ee {
1858
1863
  const n = new this(t, s);
1859
1864
  return s.session_hash && (n.session_hash = s.session_hash), await n.init(), n;
1860
1865
  }
1866
+ async reconnect() {
1867
+ const t = new URL(
1868
+ `${this.config.root}${this.api_prefix}/${ft}`
1869
+ );
1870
+ let s;
1871
+ try {
1872
+ const n = await this.fetch(t);
1873
+ if (!n.ok)
1874
+ throw new Error();
1875
+ s = (await n.json()).app_id;
1876
+ } catch {
1877
+ return "broken";
1878
+ }
1879
+ return s !== this.config.app_id ? "changed" : "connected";
1880
+ }
1861
1881
  close() {
1862
- this.closed = !0, we(this.stream_status, this.abort_controller);
1882
+ this.closed = !0, ge(this.stream_status, this.abort_controller);
1863
1883
  }
1864
1884
  set_current_payload(t) {
1865
1885
  this.current_payload = t;
@@ -1867,14 +1887,14 @@ class ee {
1867
1887
  static async duplicate(t, s = {
1868
1888
  events: ["data"]
1869
1889
  }) {
1870
- return Gt(t, s);
1890
+ return Jt(t, s);
1871
1891
  }
1872
1892
  async _resolve_config() {
1873
1893
  const { http_protocol: t, host: s, space_id: n } = await te(
1874
1894
  this.app_reference,
1875
1895
  this.options.hf_token
1876
1896
  ), { status_callback: i } = this.options;
1877
- n && i && await Me(n, i);
1897
+ n && i && await Ge(n, i);
1878
1898
  let r;
1879
1899
  try {
1880
1900
  let o = `${t}//${s}`;
@@ -1883,9 +1903,9 @@ class ee {
1883
1903
  return this.config_success(r);
1884
1904
  } catch (o) {
1885
1905
  if (n && i)
1886
- Y(
1906
+ Q(
1887
1907
  n,
1888
- ge.test(n) ? "space_name" : "subdomain",
1908
+ me.test(n) ? "space_name" : "subdomain",
1889
1909
  this.handle_space_success
1890
1910
  );
1891
1911
  else
@@ -1903,7 +1923,7 @@ class ee {
1903
1923
  try {
1904
1924
  this.api_info = await this.view_api();
1905
1925
  } catch (s) {
1906
- console.error(ht + s.message);
1926
+ console.error(_t + s.message);
1907
1927
  }
1908
1928
  return this.prepare_return_obj();
1909
1929
  }
@@ -1952,7 +1972,7 @@ class ee {
1952
1972
  r && (i.Authorization = `Bearer ${r}`);
1953
1973
  try {
1954
1974
  const p = await this.fetch(
1955
- `${a}${this.api_prefix}/${ct}/`,
1975
+ `${a}${this.api_prefix}/${lt}/`,
1956
1976
  {
1957
1977
  method: "POST",
1958
1978
  body: h,
@@ -1970,7 +1990,7 @@ class ee {
1970
1990
  }
1971
1991
  }
1972
1992
  set_cookies(t) {
1973
- this.cookies = ze(t).join("; ");
1993
+ this.cookies = qe(t).join("; ");
1974
1994
  }
1975
1995
  prepare_return_obj() {
1976
1996
  return {
@@ -2015,24 +2035,24 @@ class ee {
2015
2035
  }
2016
2036
  }
2017
2037
  }
2018
- async function as(e, t = {
2038
+ async function ls(e, t = {
2019
2039
  events: ["data"]
2020
2040
  }) {
2021
2041
  return await ee.connect(e, t);
2022
2042
  }
2023
- async function cs(e, t) {
2043
+ async function us(e, t) {
2024
2044
  return await ee.duplicate(e, t);
2025
2045
  }
2026
2046
  export {
2027
2047
  ee as Client,
2028
2048
  se as FileData,
2029
- mt as MISSING_CREDENTIALS_MSG,
2030
- as as client,
2031
- cs as duplicate,
2032
- rs as handle_file,
2033
- Ut as predict,
2034
- os as prepare_files,
2035
- ts as submit,
2036
- Dt as upload,
2037
- Ct as upload_files
2049
+ wt as MISSING_CREDENTIALS_MSG,
2050
+ ls as client,
2051
+ us as duplicate,
2052
+ cs as handle_file,
2053
+ Bt as predict,
2054
+ as as prepare_files,
2055
+ ns as submit,
2056
+ Lt as upload,
2057
+ At as upload_files
2038
2058
  };