@gradio/client 2.0.0-dev.2 → 2.0.1

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