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