@gradio/client 1.19.1 → 2.0.0-dev.0

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