@gradio/client 2.0.4 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.js CHANGED
@@ -1,5 +1,5 @@
1
- const We = "host", Te = "queue/data", Ze = "queue/join", ye = "upload", Ke = "login", K = "config", Ve = "info", Ye = "runtime", Qe = "sleeptime", Xe = "heartbeat", et = "component_server", tt = "reset", st = "cancel", nt = "app_id", Ae = "This application is currently busy. Please try again. ", M = "Connection errored out. ", D = "Could not resolve app config. ", it = "Could not get space status. ", ot = "Could not get API info. ", ue = "Space metadata could not be loaded. ", rt = "Invalid URL. A full URL path is required.", at = "Not authorized to access this space. ", xe = "Invalid credentials. Could not login. ", ct = "Login credentials are required to access this space.", ut = "File system access is only available in Node.js environments", Ce = "Root URL not found in client config", lt = "Error uploading file";
2
- async function be(e, s, t) {
1
+ const Ke = "host", Ae = "queue/data", Ve = "queue/join", we = "upload", Ye = "login", K = "config", Qe = "info", Xe = "runtime", et = "sleeptime", tt = "heartbeat", st = "component_server", nt = "reset", ot = "cancel", it = "app_id", xe = "This application is currently busy. Please try again. ", L = "Connection errored out. ", C = "Could not resolve app config. ", rt = "Could not get space status. ", at = "Could not get API info. ", ue = "Space metadata could not be loaded. ", ct = "Invalid URL. A full URL path is required.", ut = "Not authorized to access this space. ", De = "Invalid credentials. Could not login. ", lt = "Login credentials are required to access this space.", pt = "File system access is only available in Node.js environments", Ce = "Root URL not found in client config", dt = "Error uploading file";
2
+ async function ye(e, s, t) {
3
3
  try {
4
4
  return (await (await fetch(`https://huggingface.co/api/spaces/${e}/jwt`, {
5
5
  headers: {
@@ -11,13 +11,13 @@ async function be(e, s, t) {
11
11
  return !1;
12
12
  }
13
13
  }
14
- function pt(e) {
14
+ function ht(e) {
15
15
  let s = {};
16
16
  return e.forEach(({ api_name: t, id: n }) => {
17
17
  t && (s[t] = n);
18
18
  }), s;
19
19
  }
20
- async function dt(e) {
20
+ async function ft(e) {
21
21
  const s = this.options.token ? { Authorization: `Bearer ${this.options.token}` } : {};
22
22
  if (s["Content-Type"] = "application/json", typeof window < "u" && window.gradio_config && location.origin !== "http://localhost:9876") {
23
23
  if (window.gradio_config.current_page && (e = e.substring(0, e.lastIndexOf("/"))), window.gradio_config.dev_mode || typeof window < "u" && window?.BUILD_MODE === "dev") {
@@ -28,9 +28,9 @@ async function dt(e) {
28
28
  const n = await this.fetch(t, {
29
29
  headers: s,
30
30
  credentials: "include"
31
- }), i = await ve(n, !!this.options.auth);
32
- i.root = e || i.root, window.gradio_config = {
33
- ...i,
31
+ }), o = await be(n, !!this.options.auth);
32
+ o.root = e || o.root, window.gradio_config = {
33
+ ...o,
34
34
  current_page: window.gradio_config.current_page
35
35
  };
36
36
  }
@@ -43,34 +43,34 @@ async function dt(e) {
43
43
  const n = await this.fetch(t, {
44
44
  headers: s,
45
45
  credentials: "include"
46
- }), i = await ve(n, !!this.options.auth);
47
- return i.root || (i.root = e), i;
46
+ }), o = await be(n, !!this.options.auth);
47
+ return o.root || (o.root = e), o;
48
48
  }
49
- throw new Error(D);
49
+ throw new Error(C);
50
50
  }
51
- async function ve(e, s) {
51
+ async function be(e, s) {
52
52
  if (e?.status === 401 && !s) {
53
53
  const n = (await e.json())?.detail?.auth_message;
54
- throw new Error(n || ct);
54
+ throw new Error(n || lt);
55
55
  } else if (e?.status === 401 && s)
56
- throw new Error(xe);
56
+ throw new Error(De);
57
57
  if (e?.status === 200) {
58
58
  let t = await e.json();
59
- return t.dependencies?.forEach((n, i) => {
60
- n.id === void 0 && (n.id = i);
59
+ return t.dependencies?.forEach((n, o) => {
60
+ n.id === void 0 && (n.id = o);
61
61
  }), t;
62
62
  } else if (e?.status === 401)
63
- throw new Error(at);
64
- throw new Error(D);
63
+ throw new Error(ut);
64
+ throw new Error(C);
65
65
  }
66
- async function ht() {
66
+ async function _t() {
67
67
  const { http_protocol: e, host: s } = await pe(
68
68
  this.app_reference,
69
69
  this.options.token
70
70
  );
71
71
  try {
72
72
  if (this.options.auth) {
73
- const t = await De(
73
+ const t = await Le(
74
74
  e,
75
75
  s,
76
76
  this.options.auth,
@@ -83,20 +83,20 @@ async function ht() {
83
83
  throw Error(t.message);
84
84
  }
85
85
  }
86
- async function De(e, s, t, n, i) {
86
+ async function Le(e, s, t, n, o) {
87
87
  const r = new FormData();
88
88
  r.append("username", t?.[0]), r.append("password", t?.[1]);
89
- let o = {};
90
- i && (o.Authorization = `Bearer ${i}`);
91
- const a = await n(`${e}//${s}/${Ke}`, {
92
- headers: o,
89
+ let i = {};
90
+ o && (i.Authorization = `Bearer ${o}`);
91
+ const a = await n(`${e}//${s}/${Ye}`, {
92
+ headers: i,
93
93
  method: "POST",
94
94
  body: r,
95
95
  credentials: "include"
96
96
  });
97
97
  if (a.status === 200)
98
98
  return a.headers.get("set-cookie");
99
- throw a.status === 401 ? new Error(xe) : new Error(ue);
99
+ throw a.status === 401 ? new Error(De) : new Error(ue);
100
100
  }
101
101
  function re(e) {
102
102
  if (e.startsWith("http")) {
@@ -116,10 +116,10 @@ function re(e) {
116
116
  const Ne = (e) => {
117
117
  let s = [];
118
118
  return e.split(/,(?=\s*[^\s=;]+=[^\s=;]+)/).forEach((n) => {
119
- const [i, r] = n.split(";")[0].split("=");
120
- i && r && s.push(`${i.trim()}=${r.trim()}`);
119
+ const [o, r] = n.split(";")[0].split("=");
120
+ o && r && s.push(`${o.trim()}=${r.trim()}`);
121
121
  }), s;
122
- }, le = /^[a-zA-Z0-9_\-\.]+\/[a-zA-Z0-9_\-\.]+$/, ft = /.*hf\.space\/{0,1}.*$/;
122
+ }, le = /^[a-zA-Z0-9_\-\.]+\/[a-zA-Z0-9_\-\.]+$/, gt = /.*hf\.space\/{0,1}.*$/;
123
123
  async function pe(e, s) {
124
124
  const t = {};
125
125
  s && (t.Authorization = `Bearer ${s}`);
@@ -127,7 +127,7 @@ async function pe(e, s) {
127
127
  if (le.test(n))
128
128
  try {
129
129
  const r = (await (await fetch(
130
- `https://huggingface.co/api/spaces/${n}/${We}`,
130
+ `https://huggingface.co/api/spaces/${n}/${Ke}`,
131
131
  { headers: t }
132
132
  )).json()).host;
133
133
  return {
@@ -137,13 +137,13 @@ async function pe(e, s) {
137
137
  } catch {
138
138
  throw new Error(ue);
139
139
  }
140
- if (ft.test(n)) {
141
- const { ws_protocol: i, http_protocol: r, host: o } = re(n);
140
+ if (gt.test(n)) {
141
+ const { ws_protocol: o, http_protocol: r, host: i } = re(n);
142
142
  return {
143
- space_id: o.split("/")[0].replace(".hf.space", ""),
144
- ws_protocol: i,
143
+ space_id: i.split("/")[0].replace(".hf.space", ""),
144
+ ws_protocol: o,
145
145
  http_protocol: r,
146
- host: o
146
+ host: i
147
147
  };
148
148
  }
149
149
  return {
@@ -155,27 +155,27 @@ const ae = (...e) => {
155
155
  try {
156
156
  return e.reduce((s, t) => (s = s.replace(/\/+$/, ""), t = t.replace(/^\/+/, ""), new URL(t, s + "/").toString()));
157
157
  } catch {
158
- throw new Error(rt);
158
+ throw new Error(ct);
159
159
  }
160
160
  };
161
- function _t(e, s, t) {
161
+ function mt(e, s, t) {
162
162
  const n = {
163
163
  named_endpoints: {},
164
164
  unnamed_endpoints: {}
165
165
  };
166
- return Object.keys(e).forEach((i) => {
167
- (i === "named_endpoints" || i === "unnamed_endpoints") && (n[i] = {}, Object.entries(e[i]).forEach(
168
- ([r, { parameters: o, returns: a }]) => {
166
+ return Object.keys(e).forEach((o) => {
167
+ (o === "named_endpoints" || o === "unnamed_endpoints") && (n[o] = {}, Object.entries(e[o]).forEach(
168
+ ([r, { parameters: i, returns: a }]) => {
169
169
  const u = s.dependencies.find(
170
170
  (c) => c.api_name === r || c.api_name === r.replace("/", "")
171
171
  )?.id || t[r.replace("/", "")] || -1, l = u !== -1 ? s.dependencies.find((c) => c.id == u)?.types : { generator: !1, cancel: !1 };
172
- if (u !== -1 && s.dependencies.find((c) => c.id == u)?.inputs?.length !== o.length) {
173
- const c = s.dependencies.find((m) => m.id == u).inputs.map(
174
- (m) => s.components.find((w) => w.id === m)?.type
172
+ if (u !== -1 && s.dependencies.find((c) => c.id == u)?.inputs?.length !== i.length) {
173
+ const c = s.dependencies.find((g) => g.id == u).inputs.map(
174
+ (g) => s.components.find((w) => w.id === g)?.type
175
175
  );
176
176
  try {
177
- c.forEach((m, w) => {
178
- if (m === "state") {
177
+ c.forEach((g, w) => {
178
+ if (g === "state") {
179
179
  const N = {
180
180
  component: "state",
181
181
  example: null,
@@ -184,20 +184,20 @@ function _t(e, s, t) {
184
184
  parameter_name: null,
185
185
  hidden: !0
186
186
  };
187
- o.splice(w, 0, N);
187
+ i.splice(w, 0, N);
188
188
  }
189
189
  });
190
- } catch (m) {
191
- console.error(m);
190
+ } catch (g) {
191
+ console.error(g);
192
192
  }
193
193
  }
194
- const p = (c, m, w, N) => ({
194
+ const p = (c, g, w, N) => ({
195
195
  ...c,
196
- description: gt(c?.type, w),
197
- type: mt(c?.type, m, w, N) || ""
196
+ description: yt(c?.type, w),
197
+ type: wt(c?.type, g, w, N) || ""
198
198
  });
199
- n[i][r] = {
200
- parameters: o.map(
199
+ n[o][r] = {
200
+ parameters: i.map(
201
201
  (c) => p(c, c?.component, c?.serializer, "parameter")
202
202
  ),
203
203
  returns: a.map(
@@ -209,7 +209,7 @@ function _t(e, s, t) {
209
209
  ));
210
210
  }), n;
211
211
  }
212
- function mt(e, s, t, n) {
212
+ function wt(e, s, t, n) {
213
213
  if (s === "Api") return e.type;
214
214
  switch (e?.type) {
215
215
  case "string":
@@ -230,10 +230,10 @@ function mt(e, s, t, n) {
230
230
  if (t === "GallerySerializable")
231
231
  return n === "parameter" ? "[(Blob | File | Buffer), (string | null)][]" : "[{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}, (string | null))][]";
232
232
  }
233
- function gt(e, s) {
233
+ function yt(e, s) {
234
234
  return s === "GallerySerializable" ? "array of [file, label] tuples" : s === "ListStringSerializable" ? "array of strings" : s === "FileSerializable" ? "array of files or single file" : e?.description;
235
235
  }
236
- function Ee(e, s) {
236
+ function ve(e, s) {
237
237
  switch (e.msg) {
238
238
  case "send_data":
239
239
  return { type: "data" };
@@ -244,7 +244,7 @@ function Ee(e, s) {
244
244
  type: "update",
245
245
  status: {
246
246
  queue: !0,
247
- message: Ae,
247
+ message: xe,
248
248
  stage: "error",
249
249
  code: e.code,
250
250
  success: e.success
@@ -350,7 +350,10 @@ function Ee(e, s) {
350
350
  stage: e.success ? "complete" : "error",
351
351
  code: e.code,
352
352
  progress_data: e.progress_data,
353
- changed_state_ids: e.success ? e.output.changed_state_ids : void 0
353
+ changed_state_ids: e.success ? e.output.changed_state_ids : void 0,
354
+ used_cache: e.used_cache,
355
+ cache_duration: e.cache_duration,
356
+ avg_time: e.avg_time
354
357
  },
355
358
  data: e.success ? e.output : null
356
359
  };
@@ -371,123 +374,123 @@ function Ee(e, s) {
371
374
  }
372
375
  return { type: "none", status: { stage: "error", queue: !0 } };
373
376
  }
374
- const wt = (e = [], s) => {
377
+ const bt = (e = [], s) => {
375
378
  const t = s ? s.parameters : [];
376
379
  if (Array.isArray(e))
377
380
  return s && t.length > 0 && e.length > t.length && console.warn("Too many arguments provided for the endpoint."), e;
378
- const n = [], i = Object.keys(e);
379
- return t.forEach((r, o) => {
381
+ const n = [], o = Object.keys(e);
382
+ return t.forEach((r, i) => {
380
383
  if (e.hasOwnProperty(r.parameter_name))
381
- n[o] = e[r.parameter_name];
384
+ n[i] = e[r.parameter_name];
382
385
  else if (r.parameter_has_default)
383
- n[o] = r.parameter_default;
386
+ n[i] = r.parameter_default;
384
387
  else
385
388
  throw new Error(
386
389
  `No value provided for required parameter: ${r.parameter_name}`
387
390
  );
388
- }), i.forEach((r) => {
389
- if (!t.some((o) => o.parameter_name === r))
391
+ }), o.forEach((r) => {
392
+ if (!t.some((i) => i.parameter_name === r))
390
393
  throw new Error(
391
394
  `Parameter \`${r}\` is not a valid keyword argument. Please refer to the API for usage.`
392
395
  );
393
- }), n.forEach((r, o) => {
394
- if (r === void 0 && !t[o].parameter_has_default)
396
+ }), n.forEach((r, i) => {
397
+ if (r === void 0 && !t[i].parameter_has_default)
395
398
  throw new Error(
396
- `No value provided for required parameter: ${t[o].parameter_name}`
399
+ `No value provided for required parameter: ${t[i].parameter_name}`
397
400
  );
398
401
  }), n;
399
402
  };
400
- async function yt() {
403
+ async function vt() {
401
404
  if (this.api_info) return this.api_info;
402
405
  const { token: e } = this.options, { config: s } = this, t = { "Content-Type": "application/json" };
403
406
  if (e && (t.Authorization = `Bearer ${e}`), !!s)
404
407
  try {
405
- let n, i;
408
+ let n, o;
406
409
  if (typeof window < "u" && window.gradio_api_info)
407
- i = window.gradio_api_info;
410
+ o = window.gradio_api_info;
408
411
  else {
409
- const r = ae(s.root, this.api_prefix, Ve);
412
+ const r = ae(s.root, this.api_prefix, Qe);
410
413
  if (n = await this.fetch(r, {
411
414
  headers: t,
412
415
  credentials: "include"
413
416
  }), !n.ok)
414
- throw new Error(M);
415
- i = await n.json();
417
+ throw new Error(L);
418
+ o = await n.json();
416
419
  }
417
- return "api" in i && (i = i.api), i.named_endpoints["/predict"] && !i.unnamed_endpoints[0] && (i.unnamed_endpoints[0] = i.named_endpoints["/predict"]), _t(i, s, this.api_map);
420
+ return "api" in o && (o = o.api), o.named_endpoints["/predict"] && !o.unnamed_endpoints[0] && (o.unnamed_endpoints[0] = o.named_endpoints["/predict"]), mt(o, s, this.api_map);
418
421
  } catch (n) {
419
422
  throw new Error("Could not get API info. " + n.message);
420
423
  }
421
424
  }
422
- async function bt(e, s, t) {
425
+ async function Et(e, s, t) {
423
426
  const n = {};
424
427
  this?.options?.token && (n.Authorization = `Bearer ${this.options.token}`);
425
- const i = 1e3, r = [];
426
- let o;
427
- for (let a = 0; a < s.length; a += i) {
428
- const u = s.slice(a, a + i), l = new FormData();
428
+ const o = 1e3, r = [];
429
+ let i;
430
+ for (let a = 0; a < s.length; a += o) {
431
+ const u = s.slice(a, a + o), l = new FormData();
429
432
  u.forEach((c) => {
430
433
  l.append("files", c);
431
434
  });
432
435
  try {
433
- const c = t ? `${e}${this.api_prefix}/${ye}?upload_id=${t}` : `${e}${this.api_prefix}/${ye}`;
434
- o = await this.fetch(c, {
436
+ const c = t ? `${e}${this.api_prefix}/${we}?upload_id=${t}` : `${e}${this.api_prefix}/${we}`;
437
+ i = await this.fetch(c, {
435
438
  method: "POST",
436
439
  body: l,
437
440
  headers: n,
438
441
  credentials: "include"
439
442
  });
440
443
  } catch (c) {
441
- throw new Error(M + c.message);
444
+ throw new Error(L + c.message);
442
445
  }
443
- if (!o.ok) {
444
- const c = await o.text();
445
- return { error: `HTTP ${o.status}: ${c}` };
446
+ if (!i.ok) {
447
+ const c = await i.text();
448
+ return { error: `HTTP ${i.status}: ${c}` };
446
449
  }
447
- const p = await o.json();
450
+ const p = await i.json();
448
451
  p && r.push(...p);
449
452
  }
450
453
  return { files: r };
451
454
  }
452
- const vt = {
455
+ const St = {
453
456
  radix: 1e3,
454
457
  unit: ["b", "kb", "Mb", "Gb", "Tb", "Pb", "Eb", "Zb", "Yb"]
455
- }, Et = {
458
+ }, $t = {
456
459
  radix: 1024,
457
460
  unit: ["b", "Kib", "Mib", "Gib", "Tib", "Pib", "Eib", "Zib", "Yib"]
458
- }, St = {
461
+ }, kt = {
459
462
  radix: 1024,
460
463
  unit: ["b", "Kb", "Mb", "Gb", "Tb", "Pb", "Eb", "Zb", "Yb"]
461
- }, Se = {
462
- si: vt,
463
- iec: Et,
464
- jedec: St
464
+ }, Ee = {
465
+ si: St,
466
+ iec: $t,
467
+ jedec: kt
465
468
  };
466
- function $t(e, s = 1, t = "jedec") {
469
+ function Rt(e, s = 1, t = "jedec") {
467
470
  e = Math.abs(e);
468
- const { radix: n, unit: i } = Se[t] || Se.jedec;
471
+ const { radix: n, unit: o } = Ee[t] || Ee.jedec;
469
472
  let r = 0;
470
473
  for (; e >= n; )
471
474
  e /= n, ++r;
472
- return `${e.toFixed(s)} ${i[r]}`;
475
+ return `${e.toFixed(s)} ${o[r]}`;
473
476
  }
474
- async function kt(e, s, t, n) {
475
- let i = (Array.isArray(e) ? e : [e]).map(
476
- (o) => o.blob
477
+ async function Ot(e, s, t, n) {
478
+ let o = (Array.isArray(e) ? e : [e]).map(
479
+ (i) => i.blob
477
480
  );
478
- const r = i.filter(
479
- (o) => o.size > (n ?? 1 / 0)
481
+ const r = o.filter(
482
+ (i) => i.size > (n ?? 1 / 0)
480
483
  );
481
484
  if (r.length)
482
485
  throw new Error(
483
- `File(s) exceed the maximum allowed size of ${$t(n || 1 / 0)}: ${r.map((o) => `"${o.name}"`).join(", ")}`
486
+ `File(s) exceed the maximum allowed size of ${Rt(n || 1 / 0)}: ${r.map((i) => `"${i.name}"`).join(", ")}`
484
487
  );
485
488
  return await Promise.all(
486
- await this.upload_files(s, i, t).then(
487
- async (o) => {
488
- if (o.error)
489
- throw new Error(o.error);
490
- return o.files ? o.files.map((a, u) => new Q({
489
+ await this.upload_files(s, o, t).then(
490
+ async (i) => {
491
+ if (i.error)
492
+ throw new Error(i.error);
493
+ return i.files ? i.files.map((a, u) => new Q({
491
494
  ...e[u],
492
495
  path: a,
493
496
  url: `${s}${this.api_prefix}/file=${a}`
@@ -496,7 +499,7 @@ async function kt(e, s, t, n) {
496
499
  )
497
500
  );
498
501
  }
499
- async function Xt(e, s) {
502
+ async function ns(e, s) {
500
503
  return e.map(
501
504
  (t) => new Q({
502
505
  path: t.name,
@@ -523,17 +526,17 @@ class Q {
523
526
  path: s,
524
527
  url: t,
525
528
  orig_name: n,
526
- size: i,
529
+ size: o,
527
530
  blob: r,
528
- is_stream: o,
531
+ is_stream: i,
529
532
  mime_type: a,
530
533
  alt_text: u,
531
534
  b64: l
532
535
  }) {
533
- this.path = s, this.url = t, this.orig_name = n, this.size = i, this.blob = t ? void 0 : r, this.is_stream = o, this.mime_type = a, this.alt_text = u, this.b64 = l;
536
+ this.path = s, this.url = t, this.orig_name = n, this.size = o, this.blob = t ? void 0 : r, this.is_stream = i, this.mime_type = a, this.alt_text = u, this.b64 = l;
534
537
  }
535
538
  }
536
- class Le {
539
+ class Pe {
537
540
  type;
538
541
  command;
539
542
  meta;
@@ -542,12 +545,12 @@ class Le {
542
545
  this.type = "command", this.command = s, this.meta = t;
543
546
  }
544
547
  }
545
- const Rt = typeof process < "u" && process.versions && process.versions.node;
546
- function $e(e, s, t) {
548
+ const Tt = typeof process < "u" && process.versions && process.versions.node;
549
+ function Se(e, s, t) {
547
550
  for (; t.length > 1; ) {
548
- const i = t.shift();
549
- if (typeof i == "string" || typeof i == "number")
550
- e = e[i];
551
+ const o = t.shift();
552
+ if (typeof o == "string" || typeof o == "number")
553
+ e = e[o];
551
554
  else
552
555
  throw new Error("Invalid key type");
553
556
  }
@@ -557,19 +560,19 @@ function $e(e, s, t) {
557
560
  else
558
561
  throw new Error("Invalid key type");
559
562
  }
560
- async function ce(e, s = void 0, t = [], n = !1, i = void 0) {
563
+ async function ce(e, s = void 0, t = [], n = !1, o = void 0) {
561
564
  if (Array.isArray(e)) {
562
565
  let r = [];
563
566
  return await Promise.all(
564
- e.map(async (o, a) => {
567
+ e.map(async (i, a) => {
565
568
  let u = t.slice();
566
569
  u.push(String(a));
567
570
  const l = await ce(
568
571
  e[a],
569
- n ? i?.parameters[a]?.component || void 0 : s,
572
+ n ? o?.parameters[a]?.component || void 0 : s,
570
573
  u,
571
574
  !1,
572
- i
575
+ o
573
576
  );
574
577
  r = r.concat(l);
575
578
  })
@@ -585,15 +588,15 @@ async function ce(e, s = void 0, t = [], n = !1, i = void 0) {
585
588
  ];
586
589
  if (typeof e == "object" && e !== null) {
587
590
  let r = [];
588
- for (const o of Object.keys(e)) {
589
- const a = [...t, o], u = e[o];
591
+ for (const i of Object.keys(e)) {
592
+ const a = [...t, i], u = e[i];
590
593
  r = r.concat(
591
594
  await ce(
592
595
  u,
593
596
  void 0,
594
597
  a,
595
598
  !1,
596
- i
599
+ o
597
600
  )
598
601
  );
599
602
  }
@@ -602,19 +605,19 @@ async function ce(e, s = void 0, t = [], n = !1, i = void 0) {
602
605
  }
603
606
  return [];
604
607
  }
605
- function Ot(e, s) {
608
+ function At(e, s) {
606
609
  let t = s?.dependencies?.find((n) => n.id == e)?.queue;
607
610
  return t != null ? !t : !s.enable_queue;
608
611
  }
609
- function Tt(e, s) {
612
+ function xt(e, s) {
610
613
  return new Promise((t, n) => {
611
- const i = new MessageChannel();
612
- i.port1.onmessage = (({ data: r }) => {
613
- i.port1.close(), t(r);
614
- }), window.parent.postMessage(e, s, [i.port2]);
614
+ const o = new MessageChannel();
615
+ o.port1.onmessage = (({ data: r }) => {
616
+ o.port1.close(), t(r);
617
+ }), window.parent.postMessage(e, s, [o.port2]);
615
618
  });
616
619
  }
617
- function es(e) {
620
+ function os(e) {
618
621
  if (typeof e == "string") {
619
622
  if (e.startsWith("http://") || e.startsWith("https://"))
620
623
  return {
@@ -623,8 +626,8 @@ function es(e) {
623
626
  orig_name: e.split("/").pop() ?? "unknown",
624
627
  meta: { _type: "gradio.FileData" }
625
628
  };
626
- if (Rt)
627
- return new Le("upload_file", {
629
+ if (Tt)
630
+ return new Pe("upload_file", {
628
631
  path: e,
629
632
  name: e,
630
633
  orig_path: e
@@ -641,38 +644,38 @@ function es(e) {
641
644
  "Invalid input: must be a URL, File, Blob, or Buffer object."
642
645
  );
643
646
  }
644
- function V(e, s, t, n, i = !1) {
645
- if (n === "input" && !i)
647
+ function V(e, s, t, n, o = !1) {
648
+ if (n === "input" && !o)
646
649
  throw new Error("Invalid code path. Cannot skip state inputs for input.");
647
- if (n === "output" && i)
650
+ if (n === "output" && o)
648
651
  return e;
649
- let r = [], o = 0;
652
+ let r = [], i = 0;
650
653
  const a = n === "input" ? s.inputs : s.outputs;
651
654
  for (let u = 0; u < a.length; u++) {
652
655
  const l = a[u];
653
656
  if (t.find((c) => c.id === l)?.type === "state") {
654
- if (i)
657
+ if (o)
655
658
  if (e.length === a.length) {
656
- const c = e[o];
657
- r.push(c), o++;
659
+ const c = e[i];
660
+ r.push(c), i++;
658
661
  } else
659
662
  r.push(null);
660
663
  else {
661
- o++;
664
+ i++;
662
665
  continue;
663
666
  }
664
667
  continue;
665
668
  } else {
666
- const c = e[o];
667
- r.push(c), o++;
669
+ const c = e[i];
670
+ r.push(c), i++;
668
671
  }
669
672
  }
670
673
  return r;
671
674
  }
672
- async function At(e, s, t) {
675
+ async function Dt(e, s, t) {
673
676
  const n = this;
674
- await xt(n, s);
675
- const i = await ce(
677
+ await Ct(n, s);
678
+ const o = await ce(
676
679
  s,
677
680
  void 0,
678
681
  [],
@@ -680,49 +683,49 @@ async function At(e, s, t) {
680
683
  t
681
684
  );
682
685
  return (await Promise.all(
683
- i.map(async ({ path: o, blob: a, type: u }) => {
684
- if (!a) return { path: o, type: u };
686
+ o.map(async ({ path: i, blob: a, type: u }) => {
687
+ if (!a) return { path: i, type: u };
685
688
  const l = await n.upload_files(e, [a]), p = l.files && l.files[0];
686
689
  return {
687
- path: o,
690
+ path: i,
688
691
  file_url: p,
689
692
  type: u,
690
693
  name: typeof File < "u" && a instanceof File ? a?.name : void 0
691
694
  };
692
695
  })
693
- )).forEach(({ path: o, file_url: a, type: u, name: l }) => {
696
+ )).forEach(({ path: i, file_url: a, type: u, name: l }) => {
694
697
  if (u === "Gallery")
695
- $e(s, a, o);
698
+ Se(s, a, i);
696
699
  else if (a) {
697
700
  const p = new Q({ path: a, orig_name: l });
698
- $e(s, p, o);
701
+ Se(s, p, i);
699
702
  }
700
703
  }), s;
701
704
  }
702
- async function xt(e, s) {
705
+ async function Ct(e, s) {
703
706
  if (!(e.config?.root || e.config?.root_url))
704
707
  throw new Error(Ce);
705
- await Pe(e, s);
708
+ await je(e, s);
706
709
  }
707
- async function Pe(e, s, t = []) {
710
+ async function je(e, s, t = []) {
708
711
  for (const n in s)
709
- s[n] instanceof Le ? await Ct(e, s, n) : typeof s[n] == "object" && s[n] !== null && await Pe(e, s[n], [...t, n]);
712
+ s[n] instanceof Pe ? await Lt(e, s, n) : typeof s[n] == "object" && s[n] !== null && await je(e, s[n], [...t, n]);
710
713
  }
711
- async function Ct(e, s, t) {
714
+ async function Lt(e, s, t) {
712
715
  let n = s[t];
713
- const i = e.config?.root || e.config?.root_url;
714
- if (!i)
716
+ const o = e.config?.root || e.config?.root_url;
717
+ if (!o)
715
718
  throw new Error(Ce);
716
719
  try {
717
- let r, o;
720
+ let r, i;
718
721
  if (typeof process < "u" && process.versions && process.versions.node) {
719
722
  const p = await import("./__vite-browser-external-DYxpcVy9.js");
720
- o = (await import("./__vite-browser-external-DYxpcVy9.js")).resolve(process.cwd(), n.meta.path), r = await p.readFile(o);
723
+ i = (await import("./__vite-browser-external-DYxpcVy9.js")).resolve(process.cwd(), n.meta.path), r = await p.readFile(i);
721
724
  } else
722
- throw new Error(ut);
725
+ throw new Error(pt);
723
726
  const a = new Blob([r], {
724
727
  type: "application/octet-stream"
725
- }), u = await e.upload_files(i, [a]), l = u.files && u.files[0];
728
+ }), u = await e.upload_files(o, [a]), l = u.files && u.files[0];
726
729
  if (l) {
727
730
  const p = new Q({
728
731
  path: l,
@@ -731,79 +734,79 @@ async function Ct(e, s, t) {
731
734
  s[t] = p;
732
735
  }
733
736
  } catch (r) {
734
- console.error(lt, r);
737
+ console.error(dt, r);
735
738
  }
736
739
  }
737
- async function Dt(e, s, t) {
740
+ async function Nt(e, s, t) {
738
741
  const n = { "Content-Type": "application/json" };
739
742
  this.options.token && (n.Authorization = `Bearer ${this.options.token}`);
740
743
  try {
741
- var i = await this.fetch(e, {
744
+ var o = await this.fetch(e, {
742
745
  method: "POST",
743
746
  body: JSON.stringify(s),
744
747
  headers: { ...n, ...t },
745
748
  credentials: "include"
746
749
  });
747
750
  } catch {
748
- return [{ error: M }, 500];
751
+ return [{ error: L }, 500];
749
752
  }
750
- let r, o;
753
+ let r, i;
751
754
  try {
752
- r = await i.json(), o = i.status;
755
+ r = await o.json(), i = o.status;
753
756
  } catch (a) {
754
- r = { error: `Could not parse server response: ${a}` }, o = 500;
757
+ r = { error: `Could not parse server response: ${a}` }, i = 500;
755
758
  }
756
- return [r, o];
759
+ return [r, i];
757
760
  }
758
- async function Nt(e, s = {}) {
761
+ async function Pt(e, s = {}) {
759
762
  let t = !1, n = !1;
760
763
  if (!this.config)
761
764
  throw new Error("Could not resolve app config");
762
765
  if (typeof e == "number")
763
- this.config.dependencies.find((i) => i.id == e);
766
+ this.config.dependencies.find((o) => o.id == e);
764
767
  else {
765
- const i = e.replace(/^\//, "");
768
+ const o = e.replace(/^\//, "");
766
769
  this.config.dependencies.find(
767
- (r) => r.id == this.api_map[i]
770
+ (r) => r.id == this.api_map[o]
768
771
  );
769
772
  }
770
- return new Promise(async (i, r) => {
771
- const o = this.submit(e, s, null, null, !0);
773
+ return new Promise(async (o, r) => {
774
+ const i = this.submit(e, s, null, null, !0);
772
775
  let a;
773
- for await (const u of o)
774
- u.type === "data" && (n && i(a), t = !0, a = u), u.type === "status" && (u.stage === "error" && r(u), u.stage === "complete" && (n = !0, t && i(a)));
776
+ for await (const u of i)
777
+ u.type === "data" && (n && o(a), t = !0, a = u), u.type === "status" && (u.stage === "error" && r(u), u.stage === "complete" && (n = !0, t && o(a)));
775
778
  });
776
779
  }
777
- async function G(e, s, t) {
778
- let n = s === "subdomain" ? `https://huggingface.co/api/spaces/by-subdomain/${e}` : `https://huggingface.co/api/spaces/${e}`, i, r;
780
+ async function F(e, s, t) {
781
+ let n = s === "subdomain" ? `https://huggingface.co/api/spaces/by-subdomain/${e}` : `https://huggingface.co/api/spaces/${e}`, o, r;
779
782
  try {
780
- if (i = await fetch(n), r = i.status, r !== 200)
783
+ if (o = await fetch(n), r = o.status, r !== 200)
781
784
  throw new Error();
782
- i = await i.json();
785
+ o = await o.json();
783
786
  } catch {
784
787
  t({
785
788
  status: "error",
786
789
  load_status: "error",
787
- message: it,
790
+ message: rt,
788
791
  detail: "NOT_FOUND"
789
792
  });
790
793
  return;
791
794
  }
792
- if (!i || r !== 200) return;
795
+ if (!o || r !== 200) return;
793
796
  const {
794
- runtime: { stage: o },
797
+ runtime: { stage: i },
795
798
  id: a
796
- } = i;
797
- switch (o) {
799
+ } = o;
800
+ switch (i) {
798
801
  case "STOPPED":
799
802
  case "SLEEPING":
800
803
  t({
801
804
  status: "sleeping",
802
805
  load_status: "pending",
803
806
  message: "Space is asleep. Waking it up...",
804
- detail: o
807
+ detail: i
805
808
  }), setTimeout(() => {
806
- G(e, s, t);
809
+ F(e, s, t);
807
810
  }, 1e3);
808
811
  break;
809
812
  case "PAUSED":
@@ -811,8 +814,8 @@ async function G(e, s, t) {
811
814
  status: "paused",
812
815
  load_status: "error",
813
816
  message: "This space has been paused by the author. If you would like to try this demo, consider duplicating the space.",
814
- detail: o,
815
- discussions_enabled: await ke(a)
817
+ detail: i,
818
+ discussions_enabled: await $e(a)
816
819
  });
817
820
  break;
818
821
  case "RUNNING":
@@ -821,7 +824,7 @@ async function G(e, s, t) {
821
824
  status: "running",
822
825
  load_status: "complete",
823
826
  message: "Space is running.",
824
- detail: o
827
+ detail: i
825
828
  });
826
829
  break;
827
830
  case "BUILDING":
@@ -829,9 +832,9 @@ async function G(e, s, t) {
829
832
  status: "building",
830
833
  load_status: "pending",
831
834
  message: "Space is building...",
832
- detail: o
835
+ detail: i
833
836
  }), setTimeout(() => {
834
- G(e, s, t);
837
+ F(e, s, t);
835
838
  }, 1e3);
836
839
  break;
837
840
  case "APP_STARTING":
@@ -839,9 +842,9 @@ async function G(e, s, t) {
839
842
  status: "starting",
840
843
  load_status: "pending",
841
844
  message: "Space is starting...",
842
- detail: o
845
+ detail: i
843
846
  }), setTimeout(() => {
844
- G(e, s, t);
847
+ F(e, s, t);
845
848
  }, 1e3);
846
849
  break;
847
850
  default:
@@ -849,28 +852,28 @@ async function G(e, s, t) {
849
852
  status: "space_error",
850
853
  load_status: "error",
851
854
  message: "This space is experiencing an issue.",
852
- detail: o,
853
- discussions_enabled: await ke(a)
855
+ detail: i,
856
+ discussions_enabled: await $e(a)
854
857
  });
855
858
  break;
856
859
  }
857
860
  }
858
861
  const Ie = async (e, s) => {
859
862
  let t = 0;
860
- const n = 12, i = 5e3;
863
+ const n = 12, o = 5e3;
861
864
  return new Promise((r) => {
862
- G(
865
+ F(
863
866
  e,
864
867
  le.test(e) ? "space_name" : "subdomain",
865
- (o) => {
866
- s(o), o.status === "running" || o.status === "error" || o.status === "paused" || o.status === "space_error" ? r() : (o.status === "sleeping" || o.status === "building") && (t < n ? (t++, setTimeout(() => {
868
+ (i) => {
869
+ s(i), i.status === "running" || i.status === "error" || i.status === "paused" || i.status === "space_error" ? r() : (i.status === "sleeping" || i.status === "building") && (t < n ? (t++, setTimeout(() => {
867
870
  Ie(e, s).then(r);
868
- }, i)) : r());
871
+ }, o)) : r());
869
872
  }
870
873
  );
871
874
  });
872
- }, Lt = /^(?=[^]*\b[dD]iscussions{0,1}\b)(?=[^]*\b[dD]isabled\b)[^]*$/;
873
- async function ke(e) {
875
+ }, jt = /^(?=[^]*\b[dD]iscussions{0,1}\b)(?=[^]*\b[dD]isabled\b)[^]*$/;
876
+ async function $e(e) {
874
877
  try {
875
878
  const s = await fetch(
876
879
  `https://huggingface.co/api/spaces/${e}/discussions`,
@@ -878,40 +881,40 @@ async function ke(e) {
878
881
  method: "HEAD"
879
882
  }
880
883
  ), t = s.headers.get("x-error-message");
881
- return !(!s.ok || t && Lt.test(t));
884
+ return !(!s.ok || t && jt.test(t));
882
885
  } catch {
883
886
  return !1;
884
887
  }
885
888
  }
886
- async function Pt(e, s) {
889
+ async function It(e, s) {
887
890
  const t = {};
888
891
  s && (t.Authorization = `Bearer ${s}`);
889
892
  try {
890
893
  const n = await fetch(
891
- `https://huggingface.co/api/spaces/${e}/${Ye}`,
894
+ `https://huggingface.co/api/spaces/${e}/${Xe}`,
892
895
  { headers: t }
893
896
  );
894
897
  if (n.status !== 200)
895
898
  throw new Error("Space hardware could not be obtained.");
896
- const { hardware: i } = await n.json();
897
- return i.current;
899
+ const { hardware: o } = await n.json();
900
+ return o.current;
898
901
  } catch (n) {
899
902
  throw new Error(n.message);
900
903
  }
901
904
  }
902
- async function It(e, s, t) {
905
+ async function Ut(e, s, t) {
903
906
  const n = {};
904
907
  t && (n.Authorization = `Bearer ${t}`);
905
- const i = {
908
+ const o = {
906
909
  seconds: s
907
910
  };
908
911
  try {
909
912
  const r = await fetch(
910
- `https://huggingface.co/api/spaces/${e}/${Qe}`,
913
+ `https://huggingface.co/api/spaces/${e}/${et}`,
911
914
  {
912
915
  method: "POST",
913
916
  headers: { "Content-Type": "application/json", ...n },
914
- body: JSON.stringify(i)
917
+ body: JSON.stringify(o)
915
918
  }
916
919
  );
917
920
  if (r.status !== 200)
@@ -923,7 +926,7 @@ async function It(e, s, t) {
923
926
  throw new Error(r.message);
924
927
  }
925
928
  }
926
- const Re = [
929
+ const ke = [
927
930
  "cpu-basic",
928
931
  "cpu-upgrade",
929
932
  "cpu-xl",
@@ -938,22 +941,22 @@ const Re = [
938
941
  "h100",
939
942
  "h100x8"
940
943
  ];
941
- async function jt(e, s) {
942
- const { token: t, private: n, hardware: i, timeout: r, auth: o } = s;
943
- if (i && !Re.includes(i))
944
+ async function qt(e, s) {
945
+ const { token: t, private: n, hardware: o, timeout: r, auth: i } = s;
946
+ if (o && !ke.includes(o))
944
947
  throw new Error(
945
- `Invalid hardware type provided. Valid types are: ${Re.map((g) => `"${g}"`).join(",")}.`
948
+ `Invalid hardware type provided. Valid types are: ${ke.map((m) => `"${m}"`).join(",")}.`
946
949
  );
947
950
  const { http_protocol: a, host: u } = await pe(e, t);
948
951
  let l = null;
949
- if (o) {
950
- const g = await De(
952
+ if (i) {
953
+ const m = await Le(
951
954
  a,
952
955
  u,
953
- o,
956
+ i,
954
957
  fetch
955
958
  );
956
- g && (l = Ne(g));
959
+ m && (l = Ne(m));
957
960
  }
958
961
  const p = {
959
962
  Authorization: `Bearer ${t}`,
@@ -961,20 +964,20 @@ async function jt(e, s) {
961
964
  ...l ? { Cookie: l.join("; ") } : {}
962
965
  }, c = (await (await fetch("https://huggingface.co/api/whoami-v2", {
963
966
  headers: p
964
- })).json()).name, m = e.split("/")[1], w = {
965
- repository: `${c}/${m}`
967
+ })).json()).name, g = e.split("/")[1], w = {
968
+ repository: `${c}/${g}`
966
969
  };
967
970
  n && (w.private = !0);
968
971
  let N;
969
972
  try {
970
- i || (N = await Pt(e, t));
971
- } catch (g) {
972
- throw Error(ue + g.message);
973
+ o || (N = await It(e, t));
974
+ } catch (m) {
975
+ throw Error(ue + m.message);
973
976
  }
974
- const f = i || N || "cpu-basic";
977
+ const f = o || N || "cpu-basic";
975
978
  w.hardware = f;
976
979
  try {
977
- const g = await fetch(
980
+ const m = await fetch(
978
981
  `https://huggingface.co/api/spaces/${e}/duplicate`,
979
982
  {
980
983
  method: "POST",
@@ -982,45 +985,62 @@ async function jt(e, s) {
982
985
  body: JSON.stringify(w)
983
986
  }
984
987
  );
985
- if (g.status === 409)
988
+ if (m.status === 409)
986
989
  try {
987
- return await Y.connect(`${c}/${m}`, s);
988
- } catch (q) {
989
- throw console.error("Failed to connect Client instance:", q), q;
990
+ return await Y.connect(`${c}/${g}`, s);
991
+ } catch (z) {
992
+ throw console.error("Failed to connect Client instance:", z), z;
990
993
  }
991
- else if (g.status !== 200)
992
- throw new Error(g.statusText);
993
- const H = await g.json();
994
- return await It(`${c}/${m}`, r || 300, t), await Y.connect(
995
- Ut(H.url),
994
+ else if (m.status !== 200)
995
+ throw new Error(m.statusText);
996
+ const H = await m.json();
997
+ return await Ut(`${c}/${g}`, r || 300, t), await Y.connect(
998
+ zt(H.url),
996
999
  s
997
1000
  );
998
- } catch (g) {
999
- throw new Error(g);
1001
+ } catch (m) {
1002
+ throw new Error(m);
1000
1003
  }
1001
1004
  }
1002
- function Ut(e) {
1005
+ function zt(e) {
1003
1006
  const s = /https:\/\/huggingface.co\/spaces\/([^/]+\/[^/]+)/, t = e.match(s);
1004
1007
  if (t)
1005
1008
  return t[1];
1006
1009
  }
1007
- class qt extends TransformStream {
1010
+ const Re = "supports-zerogpu-headers";
1011
+ let Oe = !1;
1012
+ function Bt() {
1013
+ return typeof window < "u" && typeof document < "u" && typeof window.addEventListener == "function";
1014
+ }
1015
+ function Ue(e) {
1016
+ return e.includes(".dev.") ? `https://moon-${e.split(".")[1]}.dev.spaces.huggingface.tech` : e.endsWith(".hf.space") ? "https://huggingface.co" : null;
1017
+ }
1018
+ function Gt() {
1019
+ if (!Bt() || Oe)
1020
+ return;
1021
+ window.addEventListener("message", (s) => {
1022
+ s.data === Re && (window.supports_zerogpu_headers = !0);
1023
+ }), Oe = !0;
1024
+ const e = Ue(window.location.hostname);
1025
+ e && window.parent !== window && window.parent.postMessage(Re, e);
1026
+ }
1027
+ class Mt extends TransformStream {
1008
1028
  #e = "";
1009
1029
  /** Constructs a new instance. */
1010
1030
  constructor(s = { allowCR: !1 }) {
1011
1031
  super({
1012
1032
  transform: (t, n) => {
1013
1033
  for (t = this.#e + t; ; ) {
1014
- const i = t.indexOf(`
1034
+ const o = t.indexOf(`
1015
1035
  `), r = s.allowCR ? t.indexOf("\r") : -1;
1016
- if (r !== -1 && r !== t.length - 1 && (i === -1 || i - 1 > r)) {
1036
+ if (r !== -1 && r !== t.length - 1 && (o === -1 || o - 1 > r)) {
1017
1037
  n.enqueue(t.slice(0, r)), t = t.slice(r + 1);
1018
1038
  continue;
1019
1039
  }
1020
- if (i === -1)
1040
+ if (o === -1)
1021
1041
  break;
1022
- const o = t[i - 1] === "\r" ? i - 1 : i;
1023
- n.enqueue(t.slice(0, o)), t = t.slice(i + 1);
1042
+ const i = t[o - 1] === "\r" ? o - 1 : o;
1043
+ n.enqueue(t.slice(0, i)), t = t.slice(o + 1);
1024
1044
  }
1025
1045
  this.#e = t;
1026
1046
  },
@@ -1033,11 +1053,11 @@ class qt extends TransformStream {
1033
1053
  });
1034
1054
  }
1035
1055
  }
1036
- function zt(e) {
1037
- let s = new TextDecoderStream(), t = new qt({ allowCR: !0 });
1056
+ function Ft(e) {
1057
+ let s = new TextDecoderStream(), t = new Mt({ allowCR: !0 });
1038
1058
  return e.pipeThrough(s).pipeThrough(t);
1039
1059
  }
1040
- function Bt(e) {
1060
+ function Ht(e) {
1041
1061
  let t = /[:]\s*/.exec(e), n = t && t.index;
1042
1062
  if (n)
1043
1063
  return [
@@ -1045,51 +1065,51 @@ function Bt(e) {
1045
1065
  e.substring(n + t[0].length)
1046
1066
  ];
1047
1067
  }
1048
- function Oe(e, s, t) {
1068
+ function Te(e, s, t) {
1049
1069
  e.get(s) || e.set(s, t);
1050
1070
  }
1051
- async function* Ft(e, s) {
1071
+ async function* Jt(e, s) {
1052
1072
  if (!e.body)
1053
1073
  return;
1054
- let t = zt(e.body), n, i = t.getReader(), r;
1074
+ let t = Ft(e.body), n, o = t.getReader(), r;
1055
1075
  for (; ; ) {
1056
1076
  if (s && s.aborted)
1057
- return i.cancel();
1058
- if (n = await i.read(), n.done)
1077
+ return o.cancel();
1078
+ if (n = await o.read(), n.done)
1059
1079
  return;
1060
1080
  if (!n.value) {
1061
1081
  r && (yield r), r = void 0;
1062
1082
  continue;
1063
1083
  }
1064
- let [o, a] = Bt(n.value) || [];
1065
- o === "data" ? (r ||= {}, r[o] = r[o] ? r[o] + `
1066
- ` + a : a) : o === "event" ? (r ||= {}, r[o] = a) : o === "id" ? (r ||= {}, r[o] = String(+a) === a ? +a : a) : o === "retry" && (r ||= {}, r[o] = +a || void 0);
1084
+ let [i, a] = Ht(n.value) || [];
1085
+ i === "data" ? (r ||= {}, r[i] = r[i] ? r[i] + `
1086
+ ` + a : a) : i === "event" ? (r ||= {}, r[i] = a) : i === "id" ? (r ||= {}, r[i] = String(+a) === a ? +a : a) : i === "retry" && (r ||= {}, r[i] = +a || void 0);
1067
1087
  }
1068
1088
  }
1069
- async function Gt(e, s) {
1089
+ async function Wt(e, s) {
1070
1090
  let t = new Request(e, s);
1071
- Oe(t.headers, "Accept", "text/event-stream"), Oe(t.headers, "Content-Type", "application/json");
1091
+ Te(t.headers, "Accept", "text/event-stream"), Te(t.headers, "Content-Type", "application/json");
1072
1092
  let n = await fetch(t);
1073
1093
  if (!n.ok)
1074
1094
  throw n;
1075
- return Ft(n, t.signal);
1095
+ return Jt(n, t.signal);
1076
1096
  }
1077
- async function Mt() {
1097
+ async function Zt() {
1078
1098
  let {
1079
1099
  event_callbacks: e,
1080
1100
  unclosed_events: s,
1081
1101
  pending_stream_messages: t,
1082
1102
  stream_status: n,
1083
- config: i,
1103
+ config: o,
1084
1104
  jwt: r
1085
1105
  } = this;
1086
- const o = this;
1087
- if (!i)
1106
+ const i = this;
1107
+ if (!o)
1088
1108
  throw new Error("Could not resolve app config");
1089
1109
  n.open = !0;
1090
1110
  let a = null, u = new URLSearchParams({
1091
1111
  session_hash: this.session_hash
1092
- }).toString(), l = new URL(`${i.root}${this.api_prefix}/${Te}?${u}`);
1112
+ }).toString(), l = new URL(`${o.root}${this.api_prefix}/${Ae}?${u}`);
1093
1113
  if (r && l.searchParams.set("__sign", r), a = this.stream(l), !a) {
1094
1114
  console.warn("Cannot connect to SSE endpoint: " + l.toString());
1095
1115
  return;
@@ -1097,30 +1117,30 @@ async function Mt() {
1097
1117
  a.onmessage = async function(p) {
1098
1118
  let c = JSON.parse(p.data);
1099
1119
  if (c.msg === "close_stream") {
1100
- de(n, o.abort_controller);
1120
+ de(n, i.abort_controller);
1101
1121
  return;
1102
1122
  }
1103
- const m = c.event_id;
1104
- if (!m)
1123
+ const g = c.event_id;
1124
+ if (!g)
1105
1125
  await Promise.all(
1106
1126
  Object.keys(e).map(
1107
1127
  (w) => e[w](c)
1108
1128
  )
1109
1129
  );
1110
- else if (e[m] && i) {
1130
+ else if (e[g] && o) {
1111
1131
  c.msg === "process_completed" && ["sse", "sse_v1", "sse_v2", "sse_v2.1", "sse_v3"].includes(
1112
- i.protocol
1113
- ) && s.delete(m);
1114
- let w = e[m];
1132
+ o.protocol
1133
+ ) && s.delete(g);
1134
+ let w = e[g];
1115
1135
  typeof window < "u" && typeof document < "u" ? setTimeout(w, 0, c) : w(c);
1116
1136
  } else
1117
- t[m] || (t[m] = []), t[m].push(c);
1137
+ t[g] || (t[g] = []), t[g].push(c);
1118
1138
  }, a.onerror = async function(p) {
1119
1139
  console.error(p), await Promise.all(
1120
1140
  Object.keys(e).map(
1121
1141
  (c) => e[c]({
1122
1142
  msg: "broken_connection",
1123
- message: M
1143
+ message: L
1124
1144
  })
1125
1145
  )
1126
1146
  );
@@ -1129,20 +1149,20 @@ async function Mt() {
1129
1149
  function de(e, s) {
1130
1150
  e && (e.open = !1, s?.abort());
1131
1151
  }
1132
- function Ht(e, s, t) {
1133
- !e[s] ? (e[s] = [], t.data.forEach((i, r) => {
1134
- e[s][r] = i;
1135
- })) : t.data.forEach((i, r) => {
1136
- let o = Jt(e[s][r], i);
1137
- e[s][r] = o, t.data[r] = o;
1152
+ function Kt(e, s, t) {
1153
+ !e[s] ? (e[s] = [], t.data.forEach((o, r) => {
1154
+ e[s][r] = o;
1155
+ })) : t.data.forEach((o, r) => {
1156
+ let i = Vt(e[s][r], o);
1157
+ e[s][r] = i, t.data[r] = i;
1138
1158
  });
1139
1159
  }
1140
- function Jt(e, s) {
1141
- return s.forEach(([t, n, i]) => {
1142
- e = Wt(e, n, t, i);
1160
+ function Vt(e, s) {
1161
+ return s.forEach(([t, n, o]) => {
1162
+ e = Yt(e, n, t, o);
1143
1163
  }), e;
1144
1164
  }
1145
- function Wt(e, s, t, n) {
1165
+ function Yt(e, s, t, n) {
1146
1166
  if (s.length === 0) {
1147
1167
  if (t === "replace")
1148
1168
  return n;
@@ -1150,29 +1170,29 @@ function Wt(e, s, t, n) {
1150
1170
  return e + n;
1151
1171
  throw new Error(`Unsupported action: ${t}`);
1152
1172
  }
1153
- let i = e;
1154
- for (let o = 0; o < s.length - 1; o++)
1155
- i = i[s[o]];
1173
+ let o = e;
1174
+ for (let i = 0; i < s.length - 1; i++)
1175
+ o = o[s[i]];
1156
1176
  const r = s[s.length - 1];
1157
1177
  switch (t) {
1158
1178
  case "replace":
1159
- i[r] = n;
1179
+ o[r] = n;
1160
1180
  break;
1161
1181
  case "append":
1162
- i[r] += n;
1182
+ o[r] += n;
1163
1183
  break;
1164
1184
  case "add":
1165
- Array.isArray(i) ? i.splice(Number(r), 0, n) : i[r] = n;
1185
+ Array.isArray(o) ? o.splice(Number(r), 0, n) : o[r] = n;
1166
1186
  break;
1167
1187
  case "delete":
1168
- Array.isArray(i) ? i.splice(Number(r), 1) : delete i[r];
1188
+ Array.isArray(o) ? o.splice(Number(r), 1) : delete o[r];
1169
1189
  break;
1170
1190
  default:
1171
1191
  throw new Error(`Unknown action: ${t}`);
1172
1192
  }
1173
1193
  return e;
1174
1194
  }
1175
- function Zt(e, s = {}) {
1195
+ function Qt(e, s = {}) {
1176
1196
  const t = {
1177
1197
  close: () => {
1178
1198
  console.warn("Method not implemented.");
@@ -1196,82 +1216,82 @@ function Zt(e, s = {}) {
1196
1216
  throw new Error("Method not implemented.");
1197
1217
  }
1198
1218
  };
1199
- return Gt(e, s).then(async (n) => {
1219
+ return Wt(e, s).then(async (n) => {
1200
1220
  t.readyState = t.OPEN;
1201
1221
  try {
1202
- for await (const i of n)
1203
- t.onmessage && t.onmessage(i);
1222
+ for await (const o of n)
1223
+ t.onmessage && t.onmessage(o);
1204
1224
  t.readyState = t.CLOSED;
1205
- } catch (i) {
1206
- t.onerror && t.onerror(i), t.readyState = t.CLOSED;
1225
+ } catch (o) {
1226
+ t.onerror && t.onerror(o), t.readyState = t.CLOSED;
1207
1227
  }
1208
1228
  }).catch((n) => {
1209
1229
  console.error(n), t.onerror && t.onerror(n), t.readyState = t.CLOSED;
1210
1230
  }), t;
1211
1231
  }
1212
- function Kt(e, s = {}, t, n, i, r) {
1232
+ function Xt(e, s = {}, t, n, o, r) {
1213
1233
  try {
1214
- let o = function(h) {
1215
- (i || ze[h.type]) && p(h);
1234
+ let i = function(h) {
1235
+ (o || Ge[h.type]) && p(h);
1216
1236
  }, a = function() {
1217
- for (Me = !0; F.length > 0; )
1218
- F.shift()({
1237
+ for (Je = !0; M.length > 0; )
1238
+ M.shift()({
1219
1239
  value: void 0,
1220
1240
  done: !0
1221
1241
  });
1222
1242
  }, u = function(h) {
1223
- F.length > 0 ? F.shift()(h) : ie.push(h);
1243
+ M.length > 0 ? M.shift()(h) : oe.push(h);
1224
1244
  }, l = function(h) {
1225
- u(Vt(h)), a();
1245
+ u(es(h)), a();
1226
1246
  }, p = function(h) {
1227
1247
  u({ value: h, done: !1 });
1228
1248
  }, c = function() {
1229
- return ie.length > 0 ? Promise.resolve(ie.shift()) : new Promise((h) => F.push(h));
1249
+ return oe.length > 0 ? Promise.resolve(oe.shift()) : new Promise((h) => M.push(h));
1230
1250
  };
1231
- const { token: m } = this.options, {
1251
+ const { token: g } = this.options, {
1232
1252
  fetch: w,
1233
1253
  app_reference: N,
1234
1254
  config: f,
1235
- session_hash: g,
1255
+ session_hash: m,
1236
1256
  api_info: H,
1237
- api_map: q,
1257
+ api_map: z,
1238
1258
  stream_status: X,
1239
1259
  pending_stream_messages: ee,
1240
1260
  pending_diff_streams: te,
1241
1261
  event_callbacks: se,
1242
- unclosed_events: je,
1262
+ unclosed_events: qe,
1243
1263
  post_data: ne,
1244
1264
  options: J,
1245
- api_prefix: R
1246
- } = this, he = r || { "x-gradio-user": "api" }, Ue = this;
1265
+ api_prefix: T
1266
+ } = this, he = r || { "x-gradio-user": "api" }, ze = this;
1247
1267
  if (!H) throw new Error("No API found");
1248
1268
  if (!f) throw new Error("Could not resolve app config");
1249
- let { fn_index: d, endpoint_info: fe, dependency: z } = Yt(
1269
+ let { fn_index: d, endpoint_info: fe, dependency: B } = ts(
1250
1270
  H,
1251
1271
  e,
1252
- q,
1272
+ z,
1253
1273
  f
1254
- ), qe = wt(s, fe), j, O = f.protocol ?? "ws";
1255
- if (O === "ws")
1274
+ ), Be = bt(s, fe), j, A = f.protocol ?? "ws";
1275
+ if (A === "ws")
1256
1276
  throw new Error("WebSocket protocol is not supported in this version");
1257
- let U = "", Qt = () => U;
1277
+ let I = "", ss = () => I;
1258
1278
  const _ = typeof e == "number" ? "/predict" : e;
1259
- let W, b = null, T = !1, _e = {}, B = typeof window < "u" && typeof document < "u" ? new URLSearchParams(window.location.search).toString() : "";
1260
- const ze = J?.events?.reduce(
1261
- (h, k) => (h[k] = !0, h),
1279
+ let W, v = null, x = !1, _e = {}, G = typeof window < "u" && typeof document < "u" ? new URLSearchParams(window.location.search).toString() : "";
1280
+ const Ge = J?.events?.reduce(
1281
+ (h, R) => (h[R] = !0, h),
1262
1282
  {}
1263
1283
  ) || {};
1264
- async function Be() {
1265
- let h = {}, k = {};
1266
- h = { event_id: b }, k = { event_id: b, session_hash: g, fn_index: d };
1284
+ async function Me() {
1285
+ let h = {}, R = {};
1286
+ h = { event_id: v }, R = { event_id: v, session_hash: m, fn_index: d };
1267
1287
  try {
1268
1288
  if (!f)
1269
1289
  throw new Error("Could not resolve app config");
1270
- "event_id" in k && await w(`${f.root}${R}/${st}`, {
1290
+ "event_id" in R && await w(`${f.root}${T}/${ot}`, {
1271
1291
  headers: { "Content-Type": "application/json" },
1272
1292
  method: "POST",
1273
- body: JSON.stringify(k)
1274
- }), await w(`${f.root}${R}/${tt}`, {
1293
+ body: JSON.stringify(R)
1294
+ }), await w(`${f.root}${T}/${nt}`, {
1275
1295
  headers: { "Content-Type": "application/json" },
1276
1296
  method: "POST",
1277
1297
  body: JSON.stringify(h)
@@ -1285,35 +1305,35 @@ function Kt(e, s = {}, t, n, i, r) {
1285
1305
  const Fe = async (h) => {
1286
1306
  await this._resolve_heartbeat(h);
1287
1307
  };
1288
- async function me(h) {
1308
+ async function ge(h) {
1289
1309
  if (!f) return;
1290
- let k = h.render_id;
1310
+ let R = h.render_id;
1291
1311
  f.components = [
1292
- ...f.components.filter((v) => v.props.rendered_in !== k),
1312
+ ...f.components.filter((E) => E.props.rendered_in !== R),
1293
1313
  ...h.components
1294
1314
  ], f.dependencies = [
1295
- ...f.dependencies.filter((v) => v.rendered_in !== k),
1315
+ ...f.dependencies.filter((E) => E.rendered_in !== R),
1296
1316
  ...h.dependencies
1297
1317
  ];
1298
- const Z = f.components.some((v) => v.type === "state"), y = f.dependencies.some(
1299
- (v) => v.targets.some((L) => L[1] === "unload")
1318
+ const Z = f.components.some((E) => E.type === "state"), y = f.dependencies.some(
1319
+ (E) => E.targets.some((U) => U[1] === "unload")
1300
1320
  );
1301
- f.connect_heartbeat = Z || y, await Fe(f), o({
1321
+ f.connect_heartbeat = Z || y, await Fe(f), i({
1302
1322
  type: "render",
1303
1323
  data: h,
1304
1324
  endpoint: _,
1305
1325
  fn_index: d
1306
1326
  });
1307
1327
  }
1308
- const Ge = this.handle_blob(
1328
+ const He = this.handle_blob(
1309
1329
  f.root,
1310
- qe,
1330
+ Be,
1311
1331
  fe
1312
1332
  ).then(async (h) => {
1313
1333
  if (W = {
1314
1334
  data: V(
1315
1335
  h,
1316
- z,
1336
+ B,
1317
1337
  f.components,
1318
1338
  "input",
1319
1339
  !0
@@ -1321,8 +1341,8 @@ function Kt(e, s = {}, t, n, i, r) {
1321
1341
  event_data: t,
1322
1342
  fn_index: d,
1323
1343
  trigger_id: n
1324
- }, Ot(d, f))
1325
- o({
1344
+ }, At(d, f))
1345
+ i({
1326
1346
  type: "status",
1327
1347
  endpoint: _,
1328
1348
  stage: "pending",
@@ -1330,47 +1350,53 @@ function Kt(e, s = {}, t, n, i, r) {
1330
1350
  fn_index: d,
1331
1351
  time: /* @__PURE__ */ new Date()
1332
1352
  }), ne(
1333
- `${f.root}${R}/run${_.startsWith("/") ? _ : `/${_}`}${B ? "?" + B : ""}`,
1353
+ `${f.root}${T}/run${_.startsWith("/") ? _ : `/${_}`}${G ? "?" + G : ""}`,
1334
1354
  {
1335
1355
  ...W,
1336
- session_hash: g
1356
+ session_hash: m
1337
1357
  },
1338
1358
  he
1339
- ).then(async ([y, v]) => {
1340
- const L = y.data;
1341
- v == 200 ? (o({
1342
- type: "data",
1343
- endpoint: _,
1344
- fn_index: d,
1345
- data: V(
1346
- L,
1347
- z,
1348
- f.components,
1349
- "output",
1350
- J.with_null_state
1351
- ),
1352
- time: /* @__PURE__ */ new Date(),
1353
- event_data: t,
1354
- trigger_id: n
1355
- }), y.render_config && await me(y.render_config), o({
1356
- type: "status",
1357
- endpoint: _,
1358
- fn_index: d,
1359
- stage: "complete",
1360
- eta: y.average_duration,
1361
- queue: !1,
1362
- time: /* @__PURE__ */ new Date()
1363
- })) : o({
1364
- type: "status",
1365
- stage: "error",
1366
- endpoint: _,
1367
- fn_index: d,
1368
- message: y.error,
1369
- queue: !1,
1370
- time: /* @__PURE__ */ new Date()
1371
- });
1359
+ ).then(async ([y, E]) => {
1360
+ const U = y.data;
1361
+ if (E == 200)
1362
+ i({
1363
+ type: "data",
1364
+ endpoint: _,
1365
+ fn_index: d,
1366
+ data: V(
1367
+ U,
1368
+ B,
1369
+ f.components,
1370
+ "output",
1371
+ J.with_null_state
1372
+ ),
1373
+ time: /* @__PURE__ */ new Date(),
1374
+ event_data: t,
1375
+ trigger_id: n
1376
+ }), y.render_config && await ge(y.render_config), i({
1377
+ type: "status",
1378
+ endpoint: _,
1379
+ fn_index: d,
1380
+ stage: "complete",
1381
+ eta: y.average_duration,
1382
+ queue: !1,
1383
+ time: /* @__PURE__ */ new Date()
1384
+ });
1385
+ else {
1386
+ const O = y?.error === L;
1387
+ i({
1388
+ type: "status",
1389
+ stage: "error",
1390
+ endpoint: _,
1391
+ fn_index: d,
1392
+ message: y.error,
1393
+ broken: O,
1394
+ queue: !1,
1395
+ time: /* @__PURE__ */ new Date()
1396
+ });
1397
+ }
1372
1398
  }).catch((y) => {
1373
- o({
1399
+ i({
1374
1400
  type: "status",
1375
1401
  stage: "error",
1376
1402
  message: y.message,
@@ -1380,8 +1406,8 @@ function Kt(e, s = {}, t, n, i, r) {
1380
1406
  time: /* @__PURE__ */ new Date()
1381
1407
  });
1382
1408
  });
1383
- else if (O == "sse") {
1384
- o({
1409
+ else if (A == "sse") {
1410
+ i({
1385
1411
  type: "status",
1386
1412
  stage: "pending",
1387
1413
  queue: !0,
@@ -1391,70 +1417,70 @@ function Kt(e, s = {}, t, n, i, r) {
1391
1417
  });
1392
1418
  var Z = new URLSearchParams({
1393
1419
  fn_index: d.toString(),
1394
- session_hash: g
1420
+ session_hash: m
1395
1421
  }).toString();
1396
1422
  let y = new URL(
1397
- `${f.root}${R}/${Te}?${B ? B + "&" : ""}${Z}`
1423
+ `${f.root}${T}/${Ae}?${G ? G + "&" : ""}${Z}`
1398
1424
  );
1399
1425
  if (this.jwt && y.searchParams.set("__sign", this.jwt), j = this.stream(y), !j)
1400
1426
  return Promise.reject(
1401
1427
  new Error("Cannot connect to SSE endpoint: " + y.toString())
1402
1428
  );
1403
- j.onmessage = async function(v) {
1404
- const L = JSON.parse(v.data), { type: P, status: A, data: x } = Ee(
1405
- L,
1429
+ j.onmessage = async function(E) {
1430
+ const U = JSON.parse(E.data), { type: O, status: D, data: b } = ve(
1431
+ U,
1406
1432
  _e[d]
1407
1433
  );
1408
- if (P === "update" && A && !T)
1409
- o({
1434
+ if (O === "update" && D && !x)
1435
+ i({
1410
1436
  type: "status",
1411
1437
  endpoint: _,
1412
1438
  fn_index: d,
1413
1439
  time: /* @__PURE__ */ new Date(),
1414
- ...A
1415
- }), A.stage === "error" && (j?.close(), a());
1416
- else if (P === "data") {
1417
- let [C, I] = await ne(
1418
- `${f.root}${R}/queue/data`,
1440
+ ...D
1441
+ }), D.stage === "error" && (j?.close(), a());
1442
+ else if (O === "data") {
1443
+ let [q, P] = await ne(
1444
+ `${f.root}${T}/queue/data`,
1419
1445
  {
1420
1446
  ...W,
1421
- session_hash: g,
1422
- event_id: b
1447
+ session_hash: m,
1448
+ event_id: v
1423
1449
  }
1424
1450
  );
1425
- I !== 200 && (o({
1451
+ P !== 200 && (i({
1426
1452
  type: "status",
1427
1453
  stage: "error",
1428
- message: M,
1454
+ message: L,
1429
1455
  queue: !0,
1430
1456
  endpoint: _,
1431
1457
  fn_index: d,
1432
1458
  time: /* @__PURE__ */ new Date()
1433
1459
  }), j?.close(), a());
1434
- } else P === "complete" ? T = A : P === "log" ? o({
1460
+ } else O === "complete" ? x = D : O === "log" ? i({
1435
1461
  type: "log",
1436
- title: x.title,
1437
- log: x.log,
1438
- level: x.level,
1462
+ title: b.title,
1463
+ log: b.log,
1464
+ level: b.level,
1439
1465
  endpoint: _,
1440
- duration: x.duration,
1441
- visible: x.visible,
1466
+ duration: b.duration,
1467
+ visible: b.visible,
1442
1468
  fn_index: d
1443
- }) : (P === "generating" || P === "streaming") && o({
1469
+ }) : (O === "generating" || O === "streaming") && i({
1444
1470
  type: "status",
1445
1471
  time: /* @__PURE__ */ new Date(),
1446
- ...A,
1447
- stage: A?.stage,
1472
+ ...D,
1473
+ stage: D?.stage,
1448
1474
  queue: !0,
1449
1475
  endpoint: _,
1450
1476
  fn_index: d
1451
1477
  });
1452
- x && (o({
1478
+ b && (i({
1453
1479
  type: "data",
1454
1480
  time: /* @__PURE__ */ new Date(),
1455
1481
  data: V(
1456
- x.data,
1457
- z,
1482
+ b.data,
1483
+ B,
1458
1484
  f.components,
1459
1485
  "output",
1460
1486
  J.with_null_state
@@ -1463,18 +1489,18 @@ function Kt(e, s = {}, t, n, i, r) {
1463
1489
  fn_index: d,
1464
1490
  event_data: t,
1465
1491
  trigger_id: n
1466
- }), T && (o({
1492
+ }), x && (i({
1467
1493
  type: "status",
1468
1494
  time: /* @__PURE__ */ new Date(),
1469
- ...T,
1470
- stage: A?.stage,
1495
+ ...x,
1496
+ stage: D?.stage,
1471
1497
  queue: !0,
1472
1498
  endpoint: _,
1473
1499
  fn_index: d
1474
1500
  }), j?.close(), a()));
1475
1501
  };
1476
- } else if (O == "sse_v1" || O == "sse_v2" || O == "sse_v2.1" || O == "sse_v3") {
1477
- o({
1502
+ } else if (A == "sse_v1" || A == "sse_v2" || A == "sse_v2.1" || A == "sse_v3") {
1503
+ i({
1478
1504
  type: "status",
1479
1505
  stage: "pending",
1480
1506
  queue: !0,
@@ -1484,34 +1510,34 @@ function Kt(e, s = {}, t, n, i, r) {
1484
1510
  });
1485
1511
  let y = "";
1486
1512
  typeof window < "u" && typeof document < "u" && (y = window?.location?.hostname);
1487
- const L = y.includes(".dev.") ? `https://moon-${y.split(".")[1]}.dev.spaces.huggingface.tech` : "https://huggingface.co";
1488
- return (typeof window < "u" && typeof document < "u" && window.parent != window && window.supports_zerogpu_headers ? Tt("zerogpu-headers", L) : Promise.resolve(null)).then((C) => {
1489
- const I = { ...he, ...C || {} };
1513
+ const E = Ue(y);
1514
+ return (typeof window < "u" && typeof document < "u" && window.parent != window && !!E && window.supports_zerogpu_headers ? xt("zerogpu-headers", E) : Promise.resolve(null)).then((b) => {
1515
+ const q = { ...he, ...b || {} };
1490
1516
  return ne(
1491
- `${f.root}${R}/${Ze}?${B}`,
1517
+ `${f.root}${T}/${Ve}?${G}`,
1492
1518
  {
1493
1519
  ...W,
1494
- session_hash: g
1520
+ session_hash: m
1495
1521
  },
1496
- I
1522
+ q
1497
1523
  );
1498
- }).then(async ([C, I]) => {
1499
- if (C.event_id && (U = C.event_id), I === 503)
1500
- o({
1524
+ }).then(async ([b, q]) => {
1525
+ if (b.event_id && (I = b.event_id), q === 503)
1526
+ i({
1501
1527
  type: "status",
1502
1528
  stage: "error",
1503
- message: Ae,
1529
+ message: xe,
1504
1530
  queue: !0,
1505
1531
  endpoint: _,
1506
1532
  fn_index: d,
1507
1533
  time: /* @__PURE__ */ new Date(),
1508
1534
  visible: !0
1509
1535
  });
1510
- else if (I === 422)
1511
- o({
1536
+ else if (q === 422)
1537
+ i({
1512
1538
  type: "status",
1513
1539
  stage: "error",
1514
- message: C.detail,
1540
+ message: b.detail,
1515
1541
  queue: !0,
1516
1542
  endpoint: _,
1517
1543
  fn_index: d,
@@ -1519,97 +1545,98 @@ function Kt(e, s = {}, t, n, i, r) {
1519
1545
  time: /* @__PURE__ */ new Date(),
1520
1546
  visible: !0
1521
1547
  }), a();
1522
- else if (I !== 200)
1523
- o({
1548
+ else if (q !== 200) {
1549
+ const P = b?.error === L;
1550
+ i({
1524
1551
  type: "status",
1525
1552
  stage: "error",
1526
- broken: !1,
1527
- message: C.detail,
1553
+ broken: P,
1554
+ message: P ? L : b.detail || b.error,
1528
1555
  queue: !0,
1529
1556
  endpoint: _,
1530
1557
  fn_index: d,
1531
1558
  time: /* @__PURE__ */ new Date(),
1532
1559
  visible: !0
1533
1560
  });
1534
- else {
1535
- b = C.event_id, U = b;
1536
- let we = async function(oe) {
1561
+ } else {
1562
+ v = b.event_id, I = v;
1563
+ let P = async function(ie) {
1537
1564
  try {
1538
- const { type: E, status: S, data: $, original_msg: He } = Ee(
1539
- oe,
1565
+ const { type: S, status: $, data: k, original_msg: We } = ve(
1566
+ ie,
1540
1567
  _e[d]
1541
1568
  );
1542
- if (E == "heartbeat")
1569
+ if (S == "heartbeat")
1543
1570
  return;
1544
- if (E === "update" && S && !T)
1545
- o({
1571
+ if (S === "update" && $ && !x)
1572
+ i({
1546
1573
  type: "status",
1547
1574
  endpoint: _,
1548
1575
  fn_index: d,
1549
1576
  time: /* @__PURE__ */ new Date(),
1550
- original_msg: He,
1551
- ...S
1577
+ original_msg: We,
1578
+ ...$
1552
1579
  });
1553
- else if (E === "complete")
1554
- T = S;
1555
- else if (E == "unexpected_error" || E == "broken_connection") {
1556
- console.error("Unexpected error", S?.message);
1557
- const Je = E === "broken_connection";
1558
- o({
1580
+ else if (S === "complete")
1581
+ x = $;
1582
+ else if (S == "unexpected_error" || S == "broken_connection") {
1583
+ console.error("Unexpected error", $?.message);
1584
+ const Ze = S === "broken_connection";
1585
+ i({
1559
1586
  type: "status",
1560
1587
  stage: "error",
1561
- message: S?.message || "An Unexpected Error Occurred!",
1588
+ message: $?.message || "An Unexpected Error Occurred!",
1562
1589
  queue: !0,
1563
1590
  endpoint: _,
1564
- broken: Je,
1565
- session_not_found: S?.session_not_found,
1591
+ broken: Ze,
1592
+ session_not_found: $?.session_not_found,
1566
1593
  fn_index: d,
1567
1594
  time: /* @__PURE__ */ new Date()
1568
1595
  });
1569
- } else if (E === "log") {
1570
- o({
1596
+ } else if (S === "log") {
1597
+ i({
1571
1598
  type: "log",
1572
- title: $.title,
1573
- log: $.log,
1574
- level: $.level,
1599
+ title: k.title,
1600
+ log: k.log,
1601
+ level: k.level,
1575
1602
  endpoint: _,
1576
- duration: $.duration,
1577
- visible: $.visible,
1603
+ duration: k.duration,
1604
+ visible: k.visible,
1578
1605
  fn_index: d
1579
1606
  });
1580
1607
  return;
1581
- } else (E === "generating" || E === "streaming") && (o({
1608
+ } else (S === "generating" || S === "streaming") && (i({
1582
1609
  type: "status",
1583
1610
  time: /* @__PURE__ */ new Date(),
1584
- ...S,
1585
- stage: S?.stage,
1611
+ ...$,
1612
+ stage: $?.stage,
1586
1613
  queue: !0,
1587
1614
  endpoint: _,
1588
1615
  fn_index: d
1589
- }), $ && z.connection !== "stream" && ["sse_v2", "sse_v2.1", "sse_v3"].includes(O) && Ht(te, b, $));
1590
- $ && (o({
1616
+ }), k && B.connection !== "stream" && ["sse_v2", "sse_v2.1", "sse_v3"].includes(A) && Kt(te, v, k));
1617
+ k && (i({
1591
1618
  type: "data",
1592
1619
  time: /* @__PURE__ */ new Date(),
1593
1620
  data: V(
1594
- $.data,
1595
- z,
1621
+ k.data,
1622
+ B,
1596
1623
  f.components,
1597
1624
  "output",
1598
1625
  J.with_null_state
1599
1626
  ),
1600
1627
  endpoint: _,
1601
1628
  fn_index: d
1602
- }), $.render_config && await me($.render_config), T && (o({
1629
+ }), k.render_config && await ge(k.render_config), x && (i({
1603
1630
  type: "status",
1604
1631
  time: /* @__PURE__ */ new Date(),
1605
- ...T,
1606
- stage: S?.stage,
1632
+ ...x,
1633
+ stage: $?.stage,
1607
1634
  queue: !0,
1608
1635
  endpoint: _,
1609
1636
  fn_index: d
1610
- }), a())), (S?.stage === "complete" || S?.stage === "error") && (se[b] && delete se[b], b in te && delete te[b]);
1611
- } catch (E) {
1612
- console.error("Unexpected client exception", E), o({
1637
+ }), a())), ($?.stage === "complete" || $?.stage === "error") && (se[v] && delete se[v], v in te && delete te[v]);
1638
+ } catch (S) {
1639
+ console.error("Unexpected client exception", S), i({
1613
1640
  type: "status",
1614
1641
  stage: "error",
1615
1642
  message: "An Unexpected Error Occurred!",
@@ -1617,61 +1644,61 @@ function Kt(e, s = {}, t, n, i, r) {
1617
1644
  endpoint: _,
1618
1645
  fn_index: d,
1619
1646
  time: /* @__PURE__ */ new Date()
1620
- }), ["sse_v2", "sse_v2.1", "sse_v3"].includes(O) && (de(X, Ue.abort_controller), X.open = !1, a());
1647
+ }), ["sse_v2", "sse_v2.1", "sse_v3"].includes(A) && (de(X, ze.abort_controller), X.open = !1, a());
1621
1648
  }
1622
1649
  };
1623
- b in ee && (ee[b].forEach((oe) => we(oe)), delete ee[b]), se[b] = we, je.add(b), X.open || await this.open_stream();
1650
+ v in ee && (ee[v].forEach((ie) => P(ie)), delete ee[v]), se[v] = P, qe.add(v), X.open || await this.open_stream();
1624
1651
  }
1625
1652
  });
1626
1653
  }
1627
1654
  });
1628
- let Me = !1;
1629
- const ie = [], F = [], ge = {
1630
- [Symbol.asyncIterator]: () => ge,
1655
+ let Je = !1;
1656
+ const oe = [], M = [], me = {
1657
+ [Symbol.asyncIterator]: () => me,
1631
1658
  next: c,
1632
1659
  throw: async (h) => (l(h), c()),
1633
1660
  return: async () => (a(), { value: void 0, done: !0 }),
1634
- cancel: Be,
1661
+ cancel: Me,
1635
1662
  send_chunk: (h) => {
1636
- this.post_data(`${f.root}${R}/stream/${U}`, {
1663
+ this.post_data(`${f.root}${T}/stream/${I}`, {
1637
1664
  ...h,
1638
1665
  session_hash: this.session_hash
1639
1666
  });
1640
1667
  },
1641
1668
  close_stream: () => {
1642
1669
  this.post_data(
1643
- `${f.root}${R}/stream/${U}/close`,
1670
+ `${f.root}${T}/stream/${I}/close`,
1644
1671
  {}
1645
1672
  ), a();
1646
1673
  },
1647
- event_id: () => U,
1648
- wait_for_id: async () => (await Ge, b)
1674
+ event_id: () => I,
1675
+ wait_for_id: async () => (await He, v)
1649
1676
  };
1650
- return ge;
1651
- } catch (o) {
1652
- throw console.error("Submit function encountered an error:", o), o;
1677
+ return me;
1678
+ } catch (i) {
1679
+ throw console.error("Submit function encountered an error:", i), i;
1653
1680
  }
1654
1681
  }
1655
- function Vt(e) {
1682
+ function es(e) {
1656
1683
  return {
1657
1684
  then: (s, t) => t(e)
1658
1685
  };
1659
1686
  }
1660
- function Yt(e, s, t, n) {
1661
- let i, r, o;
1687
+ function ts(e, s, t, n) {
1688
+ let o, r, i;
1662
1689
  if (typeof s == "number")
1663
- i = s, r = e.unnamed_endpoints[i], o = n.dependencies.find((a) => a.id == s);
1690
+ o = s, r = e.unnamed_endpoints[o], i = n.dependencies.find((a) => a.id == s);
1664
1691
  else {
1665
1692
  const a = s.replace(/^\//, "");
1666
- i = t[a], r = e.named_endpoints[s.trim()], o = n.dependencies.find(
1693
+ o = t[a], r = e.named_endpoints[s.trim()], i = n.dependencies.find(
1667
1694
  (u) => u.id == t[a]
1668
1695
  );
1669
1696
  }
1670
- if (typeof i != "number")
1697
+ if (typeof o != "number")
1671
1698
  throw new Error(
1672
1699
  "There is no endpoint matching that name of fn_index matching that number."
1673
1700
  );
1674
- return { fn_index: i, endpoint_info: r, dependency: o };
1701
+ return { fn_index: o, endpoint_info: r, dependency: i };
1675
1702
  }
1676
1703
  class Y {
1677
1704
  app_reference;
@@ -1698,15 +1725,15 @@ class Y {
1698
1725
  current_payload;
1699
1726
  get_url_config(s = null) {
1700
1727
  if (!this.config)
1701
- throw new Error(D);
1728
+ throw new Error(C);
1702
1729
  s === null && (s = window.location.href);
1703
- const t = (o) => o.replace(/^\/+|\/+$/g, "");
1704
- let n = t(new URL(this.config.root).pathname), i = t(new URL(s).pathname), r;
1705
- return i.startsWith(n) ? r = t(i.substring(n.length)) : r = "", this.get_page_config(r);
1730
+ const t = (i) => i.replace(/^\/+|\/+$/g, "");
1731
+ let n = t(new URL(this.config.root).pathname), o = t(new URL(s).pathname), r;
1732
+ return o.startsWith(n) ? r = t(o.substring(n.length)) : r = "", this.get_page_config(r);
1706
1733
  }
1707
1734
  get_page_config(s) {
1708
1735
  if (!this.config)
1709
- throw new Error(D);
1736
+ throw new Error(C);
1710
1737
  let t = this.config;
1711
1738
  return s in t.page || (s = ""), {
1712
1739
  ...t,
@@ -1722,15 +1749,15 @@ class Y {
1722
1749
  }
1723
1750
  fetch(s, t) {
1724
1751
  const n = new Headers(t?.headers || {});
1725
- return this && this.cookies && n.append("Cookie", this.cookies), this && this.options.headers && new Headers(this.options.headers).forEach((r, o) => {
1726
- n.append(o, r);
1752
+ return this && this.cookies && n.append("Cookie", this.cookies), this && this.options.headers && new Headers(this.options.headers).forEach((r, i) => {
1753
+ n.append(i, r);
1727
1754
  }), fetch(s, { ...t, headers: n });
1728
1755
  }
1729
1756
  stream(s) {
1730
1757
  const t = new Headers();
1731
- return this && this.cookies && t.append("Cookie", this.cookies), this && this.options.headers && new Headers(this.options.headers).forEach((i, r) => {
1732
- t.append(r, i);
1733
- }), this && this.options.token && t.append("Authorization", `Bearer ${this.options.token}`), this.abort_controller = new AbortController(), this.stream_instance = Zt(s.toString(), {
1758
+ return this && this.cookies && t.append("Cookie", this.cookies), this && this.options.headers && new Headers(this.options.headers).forEach((o, r) => {
1759
+ t.append(r, o);
1760
+ }), this && this.options.token && t.append("Authorization", `Bearer ${this.options.token}`), this.abort_controller = new AbortController(), this.stream_instance = Qt(s.toString(), {
1734
1761
  credentials: "include",
1735
1762
  headers: t,
1736
1763
  signal: this.abort_controller.signal
@@ -1747,21 +1774,21 @@ class Y {
1747
1774
  resolve_config;
1748
1775
  resolve_cookies;
1749
1776
  constructor(s, t = { events: ["data"] }) {
1750
- this.app_reference = s, this.deep_link = t.query_params?.deep_link || null, t.events || (t.events = ["data"]), this.options = t, this.current_payload = {}, t.cookies && (this.cookies = t.cookies), this.view_api = yt.bind(this), this.upload_files = bt.bind(this), this.handle_blob = At.bind(this), this.post_data = Dt.bind(this), this.submit = Kt.bind(this), this.predict = Nt.bind(this), this.open_stream = Mt.bind(this), this.resolve_config = dt.bind(this), this.resolve_cookies = ht.bind(this), this.upload = kt.bind(this), this.fetch = this.fetch.bind(this), this.handle_space_success = this.handle_space_success.bind(this), this.stream = this.stream.bind(this);
1777
+ this.app_reference = s, this.deep_link = t.query_params?.deep_link || null, t.events || (t.events = ["data"]), this.options = t, this.current_payload = {}, t.cookies && (this.cookies = t.cookies), this.view_api = vt.bind(this), this.upload_files = Et.bind(this), this.handle_blob = Dt.bind(this), this.post_data = Nt.bind(this), this.submit = Xt.bind(this), this.predict = Pt.bind(this), this.open_stream = Zt.bind(this), this.resolve_config = ft.bind(this), this.resolve_cookies = _t.bind(this), this.upload = Ot.bind(this), this.fetch = this.fetch.bind(this), this.handle_space_success = this.handle_space_success.bind(this), this.stream = this.stream.bind(this);
1751
1778
  }
1752
1779
  async init() {
1753
- this.options.auth && await this.resolve_cookies(), await this._resolve_config().then(
1780
+ Gt(), this.options.auth && await this.resolve_cookies(), await this._resolve_config().then(
1754
1781
  ({ config: s }) => this._resolve_heartbeat(s)
1755
- ), this.api_info = await this.view_api(), this.api_map = pt(this.config?.dependencies || []);
1782
+ ), this.api_info = await this.view_api(), this.api_map = ht(this.config?.dependencies || []);
1756
1783
  }
1757
1784
  async _resolve_heartbeat(s) {
1758
- if (s && (this.config = s, this.api_prefix = s.api_prefix || "", this.config && this.config.connect_heartbeat && this.config.space_id && this.options.token && (this.jwt = await be(
1785
+ if (s && (this.config = s, this.api_prefix = s.api_prefix || "", this.config && this.config.connect_heartbeat && this.config.space_id && this.options.token && (this.jwt = await ye(
1759
1786
  this.config.space_id,
1760
1787
  this.options.token,
1761
1788
  this.cookies
1762
- ))), s.space_id && this.options.token && (this.jwt = await be(s.space_id, this.options.token)), this.config && this.config.connect_heartbeat) {
1789
+ ))), s.space_id && this.options.token && (this.jwt = await ye(s.space_id, this.options.token)), this.config && this.config.connect_heartbeat) {
1763
1790
  const t = new URL(
1764
- `${this.config.root}${this.api_prefix}/${Xe}/${this.session_hash}`
1791
+ `${this.config.root}${this.api_prefix}/${tt}/${this.session_hash}`
1765
1792
  );
1766
1793
  this.jwt && t.searchParams.set("__sign", this.jwt), this.heartbeat_event || (this.heartbeat_event = this.stream(t));
1767
1794
  }
@@ -1774,7 +1801,7 @@ class Y {
1774
1801
  }
1775
1802
  async reconnect() {
1776
1803
  const s = new URL(
1777
- `${this.config.root}${this.api_prefix}/${nt}`
1804
+ `${this.config.root}${this.api_prefix}/${it}`
1778
1805
  );
1779
1806
  let t;
1780
1807
  try {
@@ -1796,34 +1823,34 @@ class Y {
1796
1823
  static async duplicate(s, t = {
1797
1824
  events: ["data"]
1798
1825
  }) {
1799
- return jt(s, t);
1826
+ return qt(s, t);
1800
1827
  }
1801
1828
  async _resolve_config() {
1802
1829
  const { http_protocol: s, host: t, space_id: n } = await pe(
1803
1830
  this.app_reference,
1804
1831
  this.options.token
1805
- ), { status_callback: i } = this.options;
1806
- n && i && await Ie(n, i);
1832
+ ), { status_callback: o } = this.options;
1833
+ n && o && await Ie(n, o);
1807
1834
  let r;
1808
1835
  try {
1809
- let o = `${s}//${t}`;
1810
- if (r = await this.resolve_config(o), !r)
1811
- throw new Error(D);
1836
+ let i = `${s}//${t}`;
1837
+ if (r = await this.resolve_config(i), !r)
1838
+ throw new Error(C);
1812
1839
  return this.config_success(r);
1813
- } catch (o) {
1814
- if (n && i)
1815
- G(
1840
+ } catch (i) {
1841
+ if (n && o)
1842
+ F(
1816
1843
  n,
1817
1844
  le.test(n) ? "space_name" : "subdomain",
1818
1845
  this.handle_space_success
1819
1846
  );
1820
1847
  else
1821
- throw i && i({
1848
+ throw o && o({
1822
1849
  status: "error",
1823
1850
  message: "Could not load this space.",
1824
1851
  load_status: "error",
1825
1852
  detail: "NOT_FOUND"
1826
- }), Error(o);
1853
+ }), Error(i);
1827
1854
  }
1828
1855
  }
1829
1856
  async config_success(s) {
@@ -1832,18 +1859,18 @@ class Y {
1832
1859
  try {
1833
1860
  this.api_info = await this.view_api();
1834
1861
  } catch (t) {
1835
- console.error(ot + t.message);
1862
+ console.error(at + t.message);
1836
1863
  }
1837
1864
  return this.prepare_return_obj();
1838
1865
  }
1839
1866
  async handle_space_success(s) {
1840
1867
  if (!this)
1841
- throw new Error(D);
1868
+ throw new Error(C);
1842
1869
  const { status_callback: t } = this.options;
1843
1870
  if (t && t(s), s.status === "running")
1844
1871
  try {
1845
1872
  if (this.config = await this._resolve_config(), this.api_prefix = this?.config?.api_prefix || "", !this.config)
1846
- throw new Error(D);
1873
+ throw new Error(C);
1847
1874
  return await this.config_success(this.config);
1848
1875
  } catch (n) {
1849
1876
  throw t && t({
@@ -1856,34 +1883,35 @@ class Y {
1856
1883
  }
1857
1884
  async component_server(s, t, n) {
1858
1885
  if (!this.config)
1859
- throw new Error(D);
1860
- const i = {}, { token: r } = this.options, { session_hash: o } = this;
1861
- r && (i.Authorization = `Bearer ${this.options.token}`);
1886
+ throw new Error(C);
1887
+ const o = {}, { token: r } = this.options, { session_hash: i } = this;
1888
+ r && (o.Authorization = `Bearer ${this.options.token}`);
1862
1889
  let a, u = this.config.components.find(
1863
1890
  (p) => p.id === s
1864
1891
  );
1865
1892
  u?.props?.root_url ? a = u.props.root_url : a = this.config.root;
1866
1893
  let l;
1867
- if ("binary" in n) {
1894
+ if (typeof n == "object" && n !== null && "binary" in n) {
1895
+ const p = n;
1868
1896
  l = new FormData();
1869
- for (const p in n.data)
1870
- p !== "binary" && l.append(p, n.data[p]);
1871
- l.set("component_id", s.toString()), l.set("fn_name", t), l.set("session_hash", o);
1897
+ for (const c in p.data)
1898
+ c !== "binary" && l.append(c, p.data[c]);
1899
+ l.set("component_id", s.toString()), l.set("fn_name", t), l.set("session_hash", i);
1872
1900
  } else
1873
1901
  l = JSON.stringify({
1874
1902
  data: n,
1875
1903
  component_id: s,
1876
1904
  fn_name: t,
1877
- session_hash: o
1878
- }), i["Content-Type"] = "application/json";
1879
- r && (i.Authorization = `Bearer ${r}`);
1905
+ session_hash: i
1906
+ }), o["Content-Type"] = "application/json";
1907
+ r && (o.Authorization = `Bearer ${r}`);
1880
1908
  try {
1881
1909
  const p = await this.fetch(
1882
- `${a}${this.api_prefix}/${et}/`,
1910
+ `${a}${this.api_prefix}/${st}/`,
1883
1911
  {
1884
1912
  method: "POST",
1885
1913
  body: l,
1886
- headers: i,
1914
+ headers: o,
1887
1915
  credentials: "include"
1888
1916
  }
1889
1917
  );
@@ -1909,24 +1937,24 @@ class Y {
1909
1937
  };
1910
1938
  }
1911
1939
  }
1912
- async function ts(e, s = {
1940
+ async function is(e, s = {
1913
1941
  events: ["data"]
1914
1942
  }) {
1915
1943
  return await Y.connect(e, s);
1916
1944
  }
1917
- async function ss(e, s) {
1945
+ async function rs(e, s) {
1918
1946
  return await Y.duplicate(e, s);
1919
1947
  }
1920
1948
  export {
1921
1949
  Y as Client,
1922
1950
  Q as FileData,
1923
- ct as MISSING_CREDENTIALS_MSG,
1924
- ts as client,
1925
- ss as duplicate,
1926
- es as handle_file,
1927
- Nt as predict,
1928
- Xt as prepare_files,
1929
- Kt as submit,
1930
- kt as upload,
1931
- bt as upload_files
1951
+ lt as MISSING_CREDENTIALS_MSG,
1952
+ is as client,
1953
+ rs as duplicate,
1954
+ os as handle_file,
1955
+ Pt as predict,
1956
+ ns as prepare_files,
1957
+ Xt as submit,
1958
+ Ot as upload,
1959
+ Et as upload_files
1932
1960
  };