@gradio/client 2.0.0-dev.1 → 2.0.0-dev.2

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