@gradio/client 2.4.0 → 2.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -8,10 +8,10 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
8
8
  }, c = (n, r, a) => (a = n == null ? {} : e(i(n)), s(r || !n || !n.__esModule ? t(a, "default", {
9
9
  value: n,
10
10
  enumerable: !0
11
- }) : a, n)), l = "host", u = "queue/data", d = "queue/join", f = "upload", p = "login", m = "config", h = "info", g = "runtime", _ = "sleeptime", v = "heartbeat", ee = "component_server", te = "reset", ne = "cancel", y = "app_id", re = "This application is currently busy. Please try again. ", b = "Connection errored out. ", x = "Could not resolve app config. ", S = "Could not get space status. ", C = "Could not get API info. ", w = "Space metadata could not be loaded. ", T = "Invalid URL. A full URL path is required.", E = "Not authorized to access this space. ", D = "Invalid credentials. Could not login. ", ie = "Login credentials are required to access this space.", O = "Could not access this app (received a 401 response). If it is a private Hugging Face Space, pass a valid Hugging Face token to the `token` option of `Client.connect`. You can generate a token at https://huggingface.co/settings/tokens.", k = (e, t) => `Space "${e}" could not be accessed (received a ${t} response from the Hugging Face API). Check that the Space name is spelled correctly and that the Space exists. If the Space is private, pass a valid Hugging Face token to the \`token\` option of \`Client.connect\`. You can generate a token at https://huggingface.co/settings/tokens.`, ae = "No API information is available for this app. This can happen when the app's `/info` endpoint cannot be reached, or when the app is running a legacy version of Gradio that is not supported by this client. ", oe = "This app appears to be running a legacy version of Gradio (3.x or earlier) that communicates over WebSockets, which is not supported by this version of @gradio/client. Please upgrade the app to a newer version of Gradio, or connect to it with @gradio/client version 0.x.", A = "File system access is only available in Node.js environments", j = "Root URL not found in client config", M = "Error uploading file";
11
+ }) : a, n)), l = "host", u = "queue/data", d = "queue/join", f = "upload", p = "login", m = "config", h = "info", g = "runtime", ee = "sleeptime", _ = "heartbeat", te = "component_server", ne = "reset", re = "cancel", v = "app_id", ie = "This application is currently busy. Please try again. ", y = "Connection errored out. ", b = "Could not resolve app config. ", x = "Could not get space status. ", S = "Could not get API info. ", C = "Space metadata could not be loaded. ", w = "Invalid URL. A full URL path is required.", T = "Not authorized to access this space. ", E = "Invalid credentials. Could not login. ", ae = "Login credentials are required to access this space.", D = "Could not access this app (received a 401 response). If it is a private Hugging Face Space, pass a valid Hugging Face token to the `token` option of `Client.connect`. You can generate a token at https://huggingface.co/settings/tokens.", oe = (e, t) => `Space "${e}" could not be accessed (received a ${t} response from the Hugging Face API). Check that the Space name is spelled correctly and that the Space exists. If the Space is private, pass a valid Hugging Face token to the \`token\` option of \`Client.connect\`. You can generate a token at https://huggingface.co/settings/tokens.`, se = "No API information is available for this app. This can happen when the app's `/info` endpoint cannot be reached, or when the app is running a legacy version of Gradio that is not supported by this client. ", ce = "This app appears to be running a legacy version of Gradio (3.x or earlier) that communicates over WebSockets, which is not supported by this version of @gradio/client. Please upgrade the app to a newer version of Gradio, or connect to it with @gradio/client version 0.x.", le = "File system access is only available in Node.js environments", O = "Root URL not found in client config", ue = "Error uploading file";
12
12
  //#endregion
13
13
  //#region src/helpers/init_helpers.ts
14
- async function N(e, t, n) {
14
+ async function de(e, t, n) {
15
15
  try {
16
16
  return (await (await fetch(`https://huggingface.co/api/spaces/${e}/jwt`, { headers: {
17
17
  Authorization: `Bearer ${t}`,
@@ -21,24 +21,24 @@ async function N(e, t, n) {
21
21
  return !1;
22
22
  }
23
23
  }
24
- function P(e) {
24
+ function k(e) {
25
25
  e.hf_token && !e.token && (e.token = e.hf_token, console.warn("The `hf_token` option has been renamed to `token`. Support for `hf_token` will be removed in a future version of @gradio/client."));
26
26
  }
27
- function F(e) {
27
+ function fe(e) {
28
28
  let t = {};
29
29
  return e.forEach(({ api_name: e, id: n }) => {
30
30
  e && (t[e] = n);
31
31
  }), t;
32
32
  }
33
- function I(e, t) {
33
+ function A(e, t) {
34
34
  let n = new URL(e, t), r = new URL(t);
35
35
  return n.hostname === r.hostname ? (n.protocol = r.protocol, n.host = r.host, n.toString().replace(/\/$/, "")) : e;
36
36
  }
37
- async function se(e, t = !0) {
37
+ async function j(e, t = !0) {
38
38
  let n = this.options.token ? { Authorization: `Bearer ${this.options.token}` } : {};
39
39
  if (typeof window < "u" && window.gradio_config && location.origin !== "http://localhost:9876") {
40
40
  if (t && window.gradio_config.current_page && (e = e.substring(0, e.lastIndexOf("/"))), window.gradio_config.dev_mode || typeof window < "u" && window?.BUILD_MODE === "dev") {
41
- let t = W(e, this.deep_link ? m + "?deep_link=" + this.deep_link : m), r = await L(await this.fetch(t, {
41
+ let t = me(e, this.deep_link ? m + "?deep_link=" + this.deep_link : m), r = await M(await this.fetch(t, {
42
42
  headers: n,
43
43
  credentials: this.options.credentials ?? "same-origin"
44
44
  }), !!this.options.auth);
@@ -48,47 +48,47 @@ async function se(e, t = !0) {
48
48
  };
49
49
  }
50
50
  let r = { ...window.gradio_config };
51
- return r.root = I(r.root, location.href), r;
51
+ return r.root = A(r.root, location.href), r;
52
52
  } else if (e) {
53
- let t = W(e, this.deep_link ? m + "?deep_link=" + this.deep_link : m), r = await L(await this.fetch(t, {
53
+ let t = me(e, this.deep_link ? m + "?deep_link=" + this.deep_link : m), r = await M(await this.fetch(t, {
54
54
  headers: n,
55
55
  credentials: this.options.credentials ?? "same-origin"
56
56
  }), !!this.options.auth);
57
57
  return r.root ||= e, r;
58
58
  }
59
- throw Error(x);
59
+ throw Error(b);
60
60
  }
61
- async function L(e, t) {
61
+ async function M(e, t) {
62
62
  if (e?.status === 401 && !t) {
63
63
  let t = null;
64
64
  try {
65
65
  t = await e.json();
66
66
  } catch {
67
- throw Error(O);
67
+ throw Error(D);
68
68
  }
69
69
  let n = t?.detail?.auth_message;
70
70
  throw Error(n || "Login credentials are required to access this space.");
71
- } else if (e?.status === 401 && t) throw Error(D);
71
+ } else if (e?.status === 401 && t) throw Error(E);
72
72
  if (e?.status === 200) {
73
73
  let t = await e.json();
74
74
  return t.dependencies?.forEach((e, t) => {
75
75
  e.id === void 0 && (e.id = t);
76
76
  }), t;
77
- } else if (e?.status === 401) throw Error(E);
78
- throw Error(`${x}(received status ${e?.status} when fetching the app config)`);
77
+ } else if (e?.status === 401) throw Error(T);
78
+ throw Error(`${b}(received status ${e?.status} when fetching the app config)`);
79
79
  }
80
- async function ce() {
81
- let { http_protocol: e, host: t } = await U(this.app_reference, this.options.token);
80
+ async function N() {
81
+ let { http_protocol: e, host: t } = await R(this.app_reference, this.options.token);
82
82
  try {
83
83
  if (this.options.auth) {
84
- let n = await R(e, t, this.options.auth, this.fetch, this.options.token, this.options.credentials);
84
+ let n = await P(e, t, this.options.auth, this.fetch, this.options.token, this.options.credentials);
85
85
  n && this.set_cookies(n);
86
86
  }
87
87
  } catch (e) {
88
88
  throw Error(e.message);
89
89
  }
90
90
  }
91
- async function R(e, t, n, r, i, a) {
91
+ async function P(e, t, n, r, i, a) {
92
92
  let o = new FormData();
93
93
  o.append("username", n?.[0]), o.append("password", n?.[1]);
94
94
  let s = {};
@@ -100,9 +100,9 @@ async function R(e, t, n, r, i, a) {
100
100
  credentials: a ?? "same-origin"
101
101
  });
102
102
  if (c.status === 200) return c.headers.get("set-cookie");
103
- throw c.status === 401 ? Error(D) : Error(w);
103
+ throw c.status === 401 ? Error(E) : Error(C);
104
104
  }
105
- function z(e) {
105
+ function F(e) {
106
106
  if (e.startsWith("http")) {
107
107
  let { protocol: t, host: n, pathname: r } = new URL(e);
108
108
  return {
@@ -117,39 +117,39 @@ function z(e) {
117
117
  host: new URL(e).host
118
118
  };
119
119
  }
120
- var B = (e) => {
120
+ var I = (e) => {
121
121
  let t = [];
122
122
  return e.split(/,(?=\s*[^\s=;]+=[^\s=;]+)/).forEach((e) => {
123
123
  let [n, r] = e.split(";")[0].split("=");
124
124
  n && r && t.push(`${n.trim()}=${r.trim()}`);
125
125
  }), t;
126
- }, V = /^[a-zA-Z0-9_\-\.]+\/[a-zA-Z0-9_\-\.]+$/, H = /.*hf\.space\/{0,1}.*$/;
127
- async function U(e, t) {
126
+ }, L = /^[a-zA-Z0-9_\-\.]+\/[a-zA-Z0-9_\-\.]+$/, pe = /.*hf\.space\/{0,1}.*$/;
127
+ async function R(e, t) {
128
128
  let n = {};
129
129
  t && (n.Authorization = `Bearer ${t}`);
130
130
  let r = e.trim().replace(/\/$/, "");
131
- if (V.test(r)) {
131
+ if (L.test(r)) {
132
132
  let e;
133
133
  try {
134
134
  e = await fetch(`https://huggingface.co/api/spaces/${r}/${l}`, { headers: n });
135
135
  } catch {
136
- throw Error(w);
136
+ throw Error(C);
137
137
  }
138
- if (e.status === 401 || e.status === 404) throw Error(k(r, e.status));
138
+ if (e.status === 401 || e.status === 404) throw Error(oe(r, e.status));
139
139
  let t;
140
140
  try {
141
141
  t = (await e.json()).host;
142
142
  } catch {
143
- throw Error(w);
143
+ throw Error(C);
144
144
  }
145
- if (!t) throw Error(w);
145
+ if (!t) throw Error(C);
146
146
  return {
147
147
  space_id: r,
148
- ...z(t)
148
+ ...F(t)
149
149
  };
150
150
  }
151
- if (H.test(r)) {
152
- let { ws_protocol: e, http_protocol: t, host: n } = z(r);
151
+ if (pe.test(r)) {
152
+ let { ws_protocol: e, http_protocol: t, host: n } = F(r);
153
153
  return {
154
154
  space_id: n.split("/")[0].replace(".hf.space", ""),
155
155
  ws_protocol: e,
@@ -159,17 +159,17 @@ async function U(e, t) {
159
159
  }
160
160
  return {
161
161
  space_id: !1,
162
- ...z(r)
162
+ ...F(r)
163
163
  };
164
164
  }
165
- var W = (...e) => {
165
+ var me = (...e) => {
166
166
  try {
167
167
  return e.reduce((e, t) => (e = e.replace(/\/+$/, ""), t = t.replace(/^\/+/, ""), new URL(t, e + "/").toString()));
168
168
  } catch {
169
- throw Error(T);
169
+ throw Error(w);
170
170
  }
171
171
  };
172
- function G(e, t, n) {
172
+ function he(e, t, n) {
173
173
  let r = {
174
174
  named_endpoints: {},
175
175
  unnamed_endpoints: {}
@@ -199,8 +199,8 @@ function G(e, t, n) {
199
199
  }
200
200
  let d = (e, t, n, r) => ({
201
201
  ...e,
202
- description: ue(e?.type, n),
203
- type: le(e?.type, t, n, r) || ""
202
+ description: _e(e?.type, n),
203
+ type: ge(e?.type, t, n, r) || ""
204
204
  });
205
205
  r[i][e] = {
206
206
  parameters: o.map((e) => d(e, e?.component, e?.serializer, "parameter")),
@@ -211,7 +211,7 @@ function G(e, t, n) {
211
211
  }));
212
212
  }), r;
213
213
  }
214
- function le(e, t, n, r) {
214
+ function ge(e, t, n, r) {
215
215
  if (t === "Api") return e.type;
216
216
  switch (e?.type) {
217
217
  case "string": return "string";
@@ -224,10 +224,10 @@ function le(e, t, n, r) {
224
224
  if (n === "FileSerializable") return e?.type === "array" ? r === "parameter" ? "(Blob | File | Buffer)[]" : "{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}[]" : r === "parameter" ? "Blob | File | Buffer" : "{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}";
225
225
  if (n === "GallerySerializable") return r === "parameter" ? "[(Blob | File | Buffer), (string | null)][]" : "[{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}, (string | null))][]";
226
226
  }
227
- function ue(e, t) {
227
+ function _e(e, t) {
228
228
  return t === "GallerySerializable" ? "array of [file, label] tuples" : t === "ListStringSerializable" ? "array of strings" : t === "FileSerializable" ? "array of files or single file" : e?.description;
229
229
  }
230
- function de(e, t) {
230
+ function ve(e, t) {
231
231
  switch (e.msg) {
232
232
  case "send_data": return { type: "data" };
233
233
  case "send_hash": return { type: "hash" };
@@ -235,7 +235,7 @@ function de(e, t) {
235
235
  type: "update",
236
236
  status: {
237
237
  queue: !0,
238
- message: re,
238
+ message: ie,
239
239
  stage: "error",
240
240
  code: e.code,
241
241
  success: e.success
@@ -363,7 +363,7 @@ function de(e, t) {
363
363
  }
364
364
  };
365
365
  }
366
- var fe = (e = [], t) => {
366
+ var ye = (e = [], t) => {
367
367
  let n = t ? t.parameters : [];
368
368
  if (Array.isArray(e)) return t && n.length > 0 && e.length > n.length && console.warn("Too many arguments provided for the endpoint."), e;
369
369
  let r = [], i = Object.keys(e);
@@ -379,28 +379,28 @@ var fe = (e = [], t) => {
379
379
  };
380
380
  //#endregion
381
381
  //#region src/utils/view_api.ts
382
- async function K() {
382
+ async function be() {
383
383
  if (this.api_info) return this.api_info;
384
384
  let { token: e } = this.options, { config: t } = this, n = {};
385
385
  if (e && (n.Authorization = `Bearer ${e}`), t) try {
386
386
  let e, r;
387
387
  if (typeof window < "u" && window.gradio_api_info) r = window.gradio_api_info;
388
388
  else {
389
- let i = W(t.root, this.api_prefix, h);
389
+ let i = me(t.root, this.api_prefix, h);
390
390
  if (e = await this.fetch(i, {
391
391
  headers: n,
392
392
  credentials: this.options.credentials ?? "same-origin"
393
- }), !e.ok) throw Error(b);
393
+ }), !e.ok) throw Error(y);
394
394
  r = await e.json();
395
395
  }
396
- return "api" in r && (r = r.api), r.named_endpoints["/predict"] && !r.unnamed_endpoints[0] && (r.unnamed_endpoints[0] = r.named_endpoints["/predict"]), G(r, t, this.api_map);
396
+ return "api" in r && (r = r.api), r.named_endpoints["/predict"] && !r.unnamed_endpoints[0] && (r.unnamed_endpoints[0] = r.named_endpoints["/predict"]), he(r, t, this.api_map);
397
397
  } catch (e) {
398
398
  throw Error("Could not get API info. " + e.message);
399
399
  }
400
400
  }
401
401
  //#endregion
402
402
  //#region src/utils/upload_files.ts
403
- async function q(e, t, n) {
403
+ async function z(e, t, n) {
404
404
  let r = {};
405
405
  this?.options?.token && (r.Authorization = `Bearer ${this.options.token}`);
406
406
  let i = 1e3, a = [], o;
@@ -418,7 +418,7 @@ async function q(e, t, n) {
418
418
  credentials: this.options.credentials ?? "same-origin"
419
419
  });
420
420
  } catch (e) {
421
- throw Error(b + e.message);
421
+ throw Error(y + e.message);
422
422
  }
423
423
  if (!o.ok) {
424
424
  let e = await o.text();
@@ -429,7 +429,7 @@ async function q(e, t, n) {
429
429
  }
430
430
  return { files: a };
431
431
  }
432
- var pe = {
432
+ var B = {
433
433
  si: {
434
434
  radix: 1e3,
435
435
  unit: [
@@ -473,28 +473,28 @@ var pe = {
473
473
  ]
474
474
  }
475
475
  };
476
- function me(e, t = 1, n = "jedec") {
476
+ function V(e, t = 1, n = "jedec") {
477
477
  e = Math.abs(e);
478
- let { radix: r, unit: i } = pe[n] || pe.jedec, a = 0;
478
+ let { radix: r, unit: i } = B[n] || B.jedec, a = 0;
479
479
  for (; e >= r;) e /= r, ++a;
480
480
  return `${e.toFixed(t)} ${i[a]}`;
481
481
  }
482
482
  //#endregion
483
483
  //#region src/upload.ts
484
- async function he(e, t, n, r) {
484
+ async function H(e, t, n, r) {
485
485
  let i = (Array.isArray(e) ? e : [e]).map((e) => e.blob), a = i.filter((e) => e.size > (r ?? Infinity));
486
- if (a.length) throw Error(`File(s) exceed the maximum allowed size of ${me(r || Infinity)}: ${a.map((e) => `"${e.name}"`).join(", ")}`);
486
+ if (a.length) throw Error(`File(s) exceed the maximum allowed size of ${V(r || Infinity)}: ${a.map((e) => `"${e.name}"`).join(", ")}`);
487
487
  return await Promise.all(await this.upload_files(t, i, n).then(async (n) => {
488
488
  if (n.error) throw Error(n.error);
489
- return n.files ? n.files.map((n, r) => new J({
489
+ return n.files ? n.files.map((n, r) => new U({
490
490
  ...e[r],
491
491
  path: n,
492
492
  url: `${t}${this.api_prefix}/file=${n}`
493
493
  })) : [];
494
494
  }));
495
495
  }
496
- async function ge(e, t) {
497
- return e.map((e) => new J({
496
+ async function xe(e, t) {
497
+ return e.map((e) => new U({
498
498
  path: e.name,
499
499
  orig_name: e.name,
500
500
  blob: e,
@@ -503,7 +503,7 @@ async function ge(e, t) {
503
503
  is_stream: t
504
504
  }));
505
505
  }
506
- var J = class {
506
+ var U = class {
507
507
  path;
508
508
  url;
509
509
  orig_name;
@@ -517,7 +517,7 @@ var J = class {
517
517
  constructor({ path: e, url: t, orig_name: n, size: r, blob: i, is_stream: a, mime_type: o, alt_text: s, b64: c }) {
518
518
  this.path = e, this.url = t, this.orig_name = n, this.size = r, this.blob = t ? void 0 : i, this.is_stream = a, this.mime_type = o, this.alt_text = s, this.b64 = c;
519
519
  }
520
- }, _e = class {
520
+ }, W = class {
521
521
  type;
522
522
  command;
523
523
  meta;
@@ -525,8 +525,8 @@ var J = class {
525
525
  constructor(e, t) {
526
526
  this.type = "command", this.command = e, this.meta = t;
527
527
  }
528
- }, ve = typeof process < "u" && process.versions && process.versions.node;
529
- function ye(e, t, n) {
528
+ }, Se = typeof process < "u" && process.versions && process.versions.node;
529
+ function Ce(e, t, n) {
530
530
  for (; n.length > 1;) {
531
531
  let t = n.shift();
532
532
  if (typeof t == "string" || typeof t == "number") e = e[t];
@@ -536,13 +536,13 @@ function ye(e, t, n) {
536
536
  if (typeof r == "string" || typeof r == "number") e[r] = t;
537
537
  else throw Error("Invalid key type");
538
538
  }
539
- async function Y(e, t = void 0, n = [], r = !1, i = void 0) {
539
+ async function we(e, t = void 0, n = [], r = !1, i = void 0) {
540
540
  if (Array.isArray(e)) {
541
541
  let a = [];
542
542
  return await Promise.all(e.map(async (o, s) => {
543
543
  let c = n.slice();
544
544
  c.push(String(s));
545
- let l = await Y(e[s], r ? i?.parameters[s]?.component || void 0 : t, c, !1, i);
545
+ let l = await we(e[s], r ? i?.parameters[s]?.component || void 0 : t, c, !1, i);
546
546
  a = a.concat(l);
547
547
  })), a;
548
548
  } else if (globalThis.Buffer && e instanceof globalThis.Buffer || e instanceof Blob) return [{
@@ -554,17 +554,17 @@ async function Y(e, t = void 0, n = [], r = !1, i = void 0) {
554
554
  let t = [];
555
555
  for (let r of Object.keys(e)) {
556
556
  let a = [...n, r], o = e[r];
557
- t = t.concat(await Y(o, void 0, a, !1, i));
557
+ t = t.concat(await we(o, void 0, a, !1, i));
558
558
  }
559
559
  return t;
560
560
  }
561
561
  return [];
562
562
  }
563
- function be(e, t) {
563
+ function Te(e, t) {
564
564
  let n = t?.dependencies?.find((t) => t.id == e)?.queue;
565
565
  return n == null ? !t.enable_queue : !n;
566
566
  }
567
- function xe(e, t) {
567
+ function Ee(e, t) {
568
568
  return new Promise((n, r) => {
569
569
  let i = new MessageChannel();
570
570
  i.port1.onmessage = (({ data: e }) => {
@@ -572,7 +572,7 @@ function xe(e, t) {
572
572
  }), window.parent.postMessage(e, t, [i.port2]);
573
573
  });
574
574
  }
575
- function Se(e) {
575
+ function De(e) {
576
576
  if (typeof e == "string") {
577
577
  if (e.startsWith("http://") || e.startsWith("https://")) return {
578
578
  path: e,
@@ -580,7 +580,7 @@ function Se(e) {
580
580
  orig_name: e.split("/").pop() ?? "unknown",
581
581
  meta: { _type: "gradio.FileData" }
582
582
  };
583
- if (ve) return new _e("upload_file", {
583
+ if (Se) return new W("upload_file", {
584
584
  path: e,
585
585
  name: e,
586
586
  orig_path: e
@@ -590,7 +590,7 @@ function Se(e) {
590
590
  else if (e instanceof Blob) return e;
591
591
  throw Error("Invalid input: must be a URL, File, Blob, or Buffer object.");
592
592
  }
593
- function X(e, t, n, r, i = !1) {
593
+ function G(e, t, n, r, i = !1) {
594
594
  if (r === "input" && !i) throw Error("Invalid code path. Cannot skip state inputs for input.");
595
595
  if (r === "output" && i) return e;
596
596
  let a = [], o = 0, s = r === "input" ? t.inputs : t.outputs;
@@ -615,15 +615,15 @@ function X(e, t, n, r, i = !1) {
615
615
  }
616
616
  //#endregion
617
617
  //#region __vite-browser-external
618
- var Ce = /* @__PURE__ */ o(((e, t) => {
618
+ var Oe = /* @__PURE__ */ o(((e, t) => {
619
619
  t.exports = {};
620
620
  }));
621
621
  //#endregion
622
622
  //#region src/utils/handle_blob.ts
623
- async function we(e, t, n) {
623
+ async function ke(e, t, n) {
624
624
  let r = this;
625
- await Te(r, t);
626
- let i = await Y(t, void 0, [], !0, n);
625
+ await Ae(r, t);
626
+ let i = await we(t, void 0, [], !0, n);
627
627
  return (await Promise.all(i.map(async ({ path: t, blob: n, type: i }) => {
628
628
  if (!n) return {
629
629
  path: t,
@@ -637,40 +637,40 @@ async function we(e, t, n) {
637
637
  name: typeof File < "u" && n instanceof File ? n?.name : void 0
638
638
  };
639
639
  }))).forEach(({ path: e, file_url: n, type: r, name: i }) => {
640
- r === "Gallery" ? ye(t, n, e) : n && ye(t, new J({
640
+ r === "Gallery" ? Ce(t, n, e) : n && Ce(t, new U({
641
641
  path: n,
642
642
  orig_name: i
643
643
  }), e);
644
644
  }), t;
645
645
  }
646
- async function Te(e, t) {
647
- if (!(e.config?.root || e.config?.root_url)) throw Error(j);
648
- await Ee(e, t);
646
+ async function Ae(e, t) {
647
+ if (!(e.config?.root || e.config?.root_url)) throw Error(O);
648
+ await je(e, t);
649
649
  }
650
- async function Ee(e, t, n = []) {
651
- for (let r in t) t[r] instanceof _e ? await De(e, t, r) : typeof t[r] == "object" && t[r] !== null && await Ee(e, t[r], [...n, r]);
650
+ async function je(e, t, n = []) {
651
+ for (let r in t) t[r] instanceof W ? await Me(e, t, r) : typeof t[r] == "object" && t[r] !== null && await je(e, t[r], [...n, r]);
652
652
  }
653
- async function De(e, t, n) {
653
+ async function Me(e, t, n) {
654
654
  let r = t[n], i = e.config?.root || e.config?.root_url;
655
- if (!i) throw Error(j);
655
+ if (!i) throw Error(O);
656
656
  try {
657
657
  let a, o;
658
658
  if (typeof process < "u" && process.versions && process.versions.node) {
659
- let e = await Promise.resolve().then(() => /* @__PURE__ */ c(Ce(), 1));
660
- o = (await Promise.resolve().then(() => /* @__PURE__ */ c(Ce(), 1))).resolve(process.cwd(), r.meta.path), a = await e.readFile(o);
661
- } else throw Error(A);
659
+ let e = await Promise.resolve().then(() => /* @__PURE__ */ c(Oe(), 1));
660
+ o = (await Promise.resolve().then(() => /* @__PURE__ */ c(Oe(), 1))).resolve(process.cwd(), r.meta.path), a = await e.readFile(o);
661
+ } else throw Error(le);
662
662
  let s = new Blob([a], { type: "application/octet-stream" }), l = await e.upload_files(i, [s]), u = l.files && l.files[0];
663
- u && (t[n] = new J({
663
+ u && (t[n] = new U({
664
664
  path: u,
665
665
  orig_name: r.meta.name || ""
666
666
  }));
667
667
  } catch (e) {
668
- console.error(M, e);
668
+ console.error(ue, e);
669
669
  }
670
670
  }
671
671
  //#endregion
672
672
  //#region src/utils/post_data.ts
673
- async function Oe(e, t, n) {
673
+ async function Ne(e, t, n) {
674
674
  let r = { "Content-Type": "application/json" };
675
675
  this.options.token && (r.Authorization = `Bearer ${this.options.token}`);
676
676
  try {
@@ -684,7 +684,7 @@ async function Oe(e, t, n) {
684
684
  credentials: this.options.credentials ?? "same-origin"
685
685
  });
686
686
  } catch {
687
- return [{ error: b }, 500];
687
+ return [{ error: y }, 500];
688
688
  }
689
689
  let a, o;
690
690
  try {
@@ -696,7 +696,7 @@ async function Oe(e, t, n) {
696
696
  }
697
697
  //#endregion
698
698
  //#region src/utils/predict.ts
699
- async function ke(e, t = {}) {
699
+ async function Pe(e, t = {}) {
700
700
  let n = !1, r = !1;
701
701
  if (!this.config) throw Error("Could not resolve app config");
702
702
  if (typeof e == "number") this.config.dependencies.find((t) => t.id == e);
@@ -719,7 +719,7 @@ async function ke(e, t = {}) {
719
719
  }
720
720
  //#endregion
721
721
  //#region src/helpers/spaces.ts
722
- async function Z(e, t, n) {
722
+ async function K(e, t, n) {
723
723
  let r = t === "subdomain" ? `https://huggingface.co/api/spaces/by-subdomain/${e}` : `https://huggingface.co/api/spaces/${e}`, i, a;
724
724
  try {
725
725
  if (i = await fetch(r), a = i.status, a !== 200) throw Error();
@@ -728,7 +728,7 @@ async function Z(e, t, n) {
728
728
  n({
729
729
  status: "error",
730
730
  load_status: "error",
731
- message: S,
731
+ message: x,
732
732
  detail: "NOT_FOUND"
733
733
  });
734
734
  return;
@@ -744,7 +744,7 @@ async function Z(e, t, n) {
744
744
  message: "Space is asleep. Waking it up...",
745
745
  detail: o
746
746
  }), setTimeout(() => {
747
- Z(e, t, n);
747
+ K(e, t, n);
748
748
  }, 1e3);
749
749
  break;
750
750
  case "PAUSED":
@@ -753,7 +753,7 @@ async function Z(e, t, n) {
753
753
  load_status: "error",
754
754
  message: "This space has been paused by the author. If you would like to try this demo, consider duplicating the space.",
755
755
  detail: o,
756
- discussions_enabled: await Me(s)
756
+ discussions_enabled: await Le(s)
757
757
  });
758
758
  break;
759
759
  case "RUNNING":
@@ -772,7 +772,7 @@ async function Z(e, t, n) {
772
772
  message: "Space is building...",
773
773
  detail: o
774
774
  }), setTimeout(() => {
775
- Z(e, t, n);
775
+ K(e, t, n);
776
776
  }, 1e3);
777
777
  break;
778
778
  case "APP_STARTING":
@@ -782,7 +782,7 @@ async function Z(e, t, n) {
782
782
  message: "Space is starting...",
783
783
  detail: o
784
784
  }), setTimeout(() => {
785
- Z(e, t, n);
785
+ K(e, t, n);
786
786
  }, 1e3);
787
787
  break;
788
788
  default:
@@ -791,30 +791,30 @@ async function Z(e, t, n) {
791
791
  load_status: "error",
792
792
  message: "This space is experiencing an issue.",
793
793
  detail: o,
794
- discussions_enabled: await Me(s)
794
+ discussions_enabled: await Le(s)
795
795
  });
796
796
  break;
797
797
  }
798
798
  }
799
- var Ae = async (e, t) => {
799
+ var Fe = async (e, t) => {
800
800
  let n = 0;
801
801
  return new Promise((r) => {
802
- Z(e, V.test(e) ? "space_name" : "subdomain", (i) => {
802
+ K(e, L.test(e) ? "space_name" : "subdomain", (i) => {
803
803
  t(i), i.status === "running" || i.status === "error" || i.status === "paused" || i.status === "space_error" ? r() : (i.status === "sleeping" || i.status === "building") && (n < 12 ? (n++, setTimeout(() => {
804
- Ae(e, t).then(r);
804
+ Fe(e, t).then(r);
805
805
  }, 5e3)) : r());
806
806
  });
807
807
  });
808
- }, je = /^(?=[^]*\b[dD]iscussions{0,1}\b)(?=[^]*\b[dD]isabled\b)[^]*$/;
809
- async function Me(e) {
808
+ }, Ie = /^(?=[^]*\b[dD]iscussions{0,1}\b)(?=[^]*\b[dD]isabled\b)[^]*$/;
809
+ async function Le(e) {
810
810
  try {
811
811
  let t = await fetch(`https://huggingface.co/api/spaces/${e}/discussions`, { method: "HEAD" }), n = t.headers.get("x-error-message");
812
- return !(!t.ok || n && je.test(n));
812
+ return !(!t.ok || n && Ie.test(n));
813
813
  } catch {
814
814
  return !1;
815
815
  }
816
816
  }
817
- async function Ne(e, t) {
817
+ async function Re(e, t) {
818
818
  let n = {};
819
819
  t && (n.Authorization = `Bearer ${t}`);
820
820
  try {
@@ -826,12 +826,12 @@ async function Ne(e, t) {
826
826
  throw Error(e.message);
827
827
  }
828
828
  }
829
- async function Pe(e, t, n) {
829
+ async function ze(e, t, n) {
830
830
  let r = {};
831
831
  n && (r.Authorization = `Bearer ${n}`);
832
832
  let i = { seconds: t };
833
833
  try {
834
- let t = await fetch(`https://huggingface.co/api/spaces/${e}/${_}`, {
834
+ let t = await fetch(`https://huggingface.co/api/spaces/${e}/${ee}`, {
835
835
  method: "POST",
836
836
  headers: {
837
837
  "Content-Type": "application/json",
@@ -845,7 +845,7 @@ async function Pe(e, t, n) {
845
845
  throw Error(e.message);
846
846
  }
847
847
  }
848
- var Fe = [
848
+ var Be = [
849
849
  "cpu-basic",
850
850
  "cpu-upgrade",
851
851
  "cpu-xl",
@@ -862,14 +862,14 @@ var Fe = [
862
862
  ];
863
863
  //#endregion
864
864
  //#region src/utils/duplicate.ts
865
- async function Ie(e, t) {
866
- P(t);
865
+ async function Ve(e, t) {
866
+ k(t);
867
867
  let { token: n, private: r, hardware: i, timeout: a, auth: o } = t;
868
- if (i && !Fe.includes(i)) throw Error(`Invalid hardware type provided. Valid types are: ${Fe.map((e) => `"${e}"`).join(",")}.`);
869
- let { http_protocol: s, host: c } = await U(e, n), l = null;
868
+ if (i && !Be.includes(i)) throw Error(`Invalid hardware type provided. Valid types are: ${Be.map((e) => `"${e}"`).join(",")}.`);
869
+ let { http_protocol: s, host: c } = await R(e, n), l = null;
870
870
  if (o) {
871
- let e = await R(s, c, o, fetch, void 0, t.credentials);
872
- e && (l = B(e));
871
+ let e = await P(s, c, o, fetch, void 0, t.credentials);
872
+ e && (l = I(e));
873
873
  }
874
874
  let u = {
875
875
  Authorization: `Bearer ${n}`,
@@ -879,9 +879,9 @@ async function Ie(e, t) {
879
879
  r && (p.private = !0);
880
880
  let m;
881
881
  try {
882
- i || (m = await Ne(e, n));
882
+ i || (m = await Re(e, n));
883
883
  } catch (e) {
884
- throw Error(w + e.message);
884
+ throw Error(C + e.message);
885
885
  }
886
886
  p.hardware = i || m || "cpu-basic";
887
887
  try {
@@ -897,35 +897,35 @@ async function Ie(e, t) {
897
897
  }
898
898
  else if (r.status !== 200) throw Error(r.statusText);
899
899
  let i = await r.json();
900
- return await Pe(`${d}/${f}`, a || 300, n), await $.connect(Le(i.url), t);
900
+ return await ze(`${d}/${f}`, a || 300, n), await $.connect(He(i.url), t);
901
901
  } catch (e) {
902
902
  throw Error(e);
903
903
  }
904
904
  }
905
- function Le(e) {
905
+ function He(e) {
906
906
  let t = e.match(/https:\/\/huggingface.co\/spaces\/([^/]+\/[^/]+)/);
907
907
  if (t) return t[1];
908
908
  }
909
909
  //#endregion
910
910
  //#region src/helpers/zerogpu.ts
911
- var Re = "supports-zerogpu-headers", ze = !1;
912
- function Be() {
911
+ var Ue = "supports-zerogpu-headers", We = !1;
912
+ function Ge() {
913
913
  return typeof window < "u" && typeof document < "u" && typeof window.addEventListener == "function";
914
914
  }
915
- function Ve(e) {
915
+ function Ke(e) {
916
916
  return e.includes(".dev.") ? `https://moon-${e.split(".")[1]}.dev.spaces.huggingface.tech` : e.endsWith(".hf.space") ? "https://huggingface.co" : null;
917
917
  }
918
- function He() {
919
- if (!Be() || ze) return;
918
+ function qe() {
919
+ if (!Ge() || We) return;
920
920
  window.addEventListener("message", (e) => {
921
- e.data === Re && (window.supports_zerogpu_headers = !0);
922
- }), ze = !0;
923
- let e = Ve(window.location.hostname);
924
- e && window.parent !== window && window.parent.postMessage(Re, e);
921
+ e.data === Ue && (window.supports_zerogpu_headers = !0);
922
+ }), We = !0;
923
+ let e = Ke(window.location.hostname);
924
+ e && window.parent !== window && window.parent.postMessage(Ue, e);
925
925
  }
926
926
  //#endregion
927
927
  //#region ../../node_modules/.pnpm/fetch-event-stream@0.1.6/node_modules/fetch-event-stream/esm/deps/jsr.io/@std/streams/0.221.0/text_line_stream.js
928
- var Ue = class extends TransformStream {
928
+ var Je = class extends TransformStream {
929
929
  #e = "";
930
930
  constructor(e = { allowCR: !1 }) {
931
931
  super({
@@ -952,22 +952,22 @@ var Ue = class extends TransformStream {
952
952
  };
953
953
  //#endregion
954
954
  //#region ../../node_modules/.pnpm/fetch-event-stream@0.1.6/node_modules/fetch-event-stream/esm/utils.js
955
- function We(e) {
956
- let t = new TextDecoderStream(), n = new Ue({ allowCR: !0 });
955
+ function Ye(e) {
956
+ let t = new TextDecoderStream(), n = new Je({ allowCR: !0 });
957
957
  return e.pipeThrough(t).pipeThrough(n);
958
958
  }
959
- function Ge(e) {
959
+ function Xe(e) {
960
960
  let t = /[:]\s*/.exec(e), n = t && t.index;
961
961
  if (n) return [e.substring(0, n), e.substring(n + t[0].length)];
962
962
  }
963
- function Ke(e, t, n) {
963
+ function Ze(e, t, n) {
964
964
  e.get(t) || e.set(t, n);
965
965
  }
966
966
  //#endregion
967
967
  //#region ../../node_modules/.pnpm/fetch-event-stream@0.1.6/node_modules/fetch-event-stream/esm/mod.js
968
- async function* qe(e, t) {
968
+ async function* Qe(e, t) {
969
969
  if (!e.body) return;
970
- let n = We(e.body), r, i = n.getReader(), a;
970
+ let n = Ye(e.body), r, i = n.getReader(), a;
971
971
  for (;;) {
972
972
  if (t && t.aborted) return i.cancel();
973
973
  if (r = await i.read(), r.done) return;
@@ -975,20 +975,20 @@ async function* qe(e, t) {
975
975
  a && (yield a), a = void 0;
976
976
  continue;
977
977
  }
978
- let [e, n] = Ge(r.value) || [];
978
+ let [e, n] = Xe(r.value) || [];
979
979
  e === "data" ? (a ||= {}, a[e] = a[e] ? a[e] + "\n" + n : n) : e === "event" ? (a ||= {}, a[e] = n) : e === "id" ? (a ||= {}, a[e] = String(+n) === n ? +n : n) : e === "retry" && (a ||= {}, a[e] = +n || void 0);
980
980
  }
981
981
  }
982
- async function Je(e, t) {
982
+ async function $e(e, t) {
983
983
  let n = new Request(e, t);
984
- Ke(n.headers, "Accept", "text/event-stream"), Ke(n.headers, "Content-Type", "application/json");
984
+ Ze(n.headers, "Accept", "text/event-stream"), Ze(n.headers, "Content-Type", "application/json");
985
985
  let r = await fetch(n);
986
986
  if (!r.ok) throw r;
987
- return qe(r, n.signal);
987
+ return Qe(r, n.signal);
988
988
  }
989
989
  //#endregion
990
990
  //#region src/utils/stream.ts
991
- async function Ye() {
991
+ async function et() {
992
992
  let { event_callbacks: e, unclosed_events: t, pending_stream_messages: n, stream_status: r, config: i, jwt: a } = this, o = this;
993
993
  if (!i) throw Error("Could not resolve app config");
994
994
  r.open = !0;
@@ -1000,7 +1000,7 @@ async function Ye() {
1000
1000
  s.onmessage = async function(a) {
1001
1001
  let s = JSON.parse(a.data);
1002
1002
  if (s.msg === "close_stream") {
1003
- Q(r, o.abort_controller);
1003
+ tt(r, o.abort_controller);
1004
1004
  return;
1005
1005
  }
1006
1006
  let c = s.event_id;
@@ -1019,27 +1019,27 @@ async function Ye() {
1019
1019
  }, s.onerror = async function(t) {
1020
1020
  console.error(t), await Promise.all(Object.keys(e).map((t) => e[t]({
1021
1021
  msg: "broken_connection",
1022
- message: b
1022
+ message: y
1023
1023
  })));
1024
1024
  };
1025
1025
  }
1026
- function Q(e, t) {
1026
+ function tt(e, t) {
1027
1027
  e && (e.open = !1, t?.abort());
1028
1028
  }
1029
- function Xe(e, t, n) {
1029
+ function nt(e, t, n) {
1030
1030
  e[t] ? n.data.forEach((r, i) => {
1031
- let a = Ze(i < e[t].length ? e[t][i] : null, r);
1031
+ let a = rt(i < e[t].length ? e[t][i] : null, r);
1032
1032
  e[t][i] = a, n.data[i] = a;
1033
1033
  }) : (e[t] = [], n.data.forEach((n, r) => {
1034
1034
  e[t][r] = n;
1035
1035
  }));
1036
1036
  }
1037
- function Ze(e, t) {
1037
+ function rt(e, t) {
1038
1038
  return t.forEach(([t, n, r]) => {
1039
- e = Qe(e, n, t, r);
1039
+ e = it(e, n, t, r);
1040
1040
  }), e;
1041
1041
  }
1042
- function Qe(e, t, n, r) {
1042
+ function it(e, t, n, r) {
1043
1043
  if (t.length === 0) {
1044
1044
  if (n === "replace") return r;
1045
1045
  if (n === "append") return e + r;
@@ -1065,7 +1065,7 @@ function Qe(e, t, n, r) {
1065
1065
  }
1066
1066
  return e;
1067
1067
  }
1068
- function $e(e, t = {}) {
1068
+ function at(e, t = {}) {
1069
1069
  let n = {
1070
1070
  close: () => {
1071
1071
  console.warn("Method not implemented.");
@@ -1089,7 +1089,7 @@ function $e(e, t = {}) {
1089
1089
  throw Error("Method not implemented.");
1090
1090
  }
1091
1091
  };
1092
- return Je(e, t).then(async (e) => {
1092
+ return $e(e, t).then(async (e) => {
1093
1093
  n.readyState = n.OPEN;
1094
1094
  try {
1095
1095
  for await (let t of e) n.onmessage && n.onmessage(t);
@@ -1102,32 +1102,273 @@ function $e(e, t = {}) {
1102
1102
  }), n;
1103
1103
  }
1104
1104
  //#endregion
1105
+ //#region src/utils/run_history.ts
1106
+ var ot = "gradio:run-history:", q = `${ot}v2:`, st = `${ot}replay:v2:`, ct = 100, lt = 8;
1107
+ function J(e, t) {
1108
+ try {
1109
+ return e();
1110
+ } catch (e) {
1111
+ return console.warn("Could not update the run history.", e), t;
1112
+ }
1113
+ }
1114
+ function ut(e, t = "/gradio_api") {
1115
+ return `${e.replace(/\/+$/, "")}${t}/runs`;
1116
+ }
1117
+ function Y(e) {
1118
+ if (typeof window > "u") return null;
1119
+ let t = e?.app_id;
1120
+ if (t == null || t === "") return null;
1121
+ try {
1122
+ return window.localStorage ? `${q}${t}${e?.username ? `:user:${encodeURIComponent(e.username)}` : ""}` : null;
1123
+ } catch {
1124
+ return null;
1125
+ }
1126
+ }
1127
+ function dt(e) {
1128
+ let t = Y(e);
1129
+ return t ? t.replace(q, st) : null;
1130
+ }
1131
+ function ft(e) {
1132
+ try {
1133
+ let t = JSON.parse(window.localStorage.getItem(e) || "[]");
1134
+ return Array.isArray(t) && t.length && Date.parse(t[0]?.started_at) || 0;
1135
+ } catch {
1136
+ return 0;
1137
+ }
1138
+ }
1139
+ function pt(e) {
1140
+ let t = Object.keys(window.localStorage).filter((e) => e.startsWith(ot)), n = [...t.filter((e) => !e.startsWith(q) && !e.startsWith(st)), ...t.filter((t) => t.startsWith(q) && t !== e).sort((e, t) => ft(t) - ft(e)).slice(lt - 1)];
1141
+ for (let e of n) try {
1142
+ window.localStorage.removeItem(e), window.sessionStorage.removeItem(e.replace(q, st));
1143
+ } catch {}
1144
+ }
1145
+ function mt() {
1146
+ return typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(36).slice(2)}`;
1147
+ }
1148
+ function X(e) {
1149
+ let t = /* @__PURE__ */ new WeakSet();
1150
+ try {
1151
+ return JSON.parse(JSON.stringify(e, (e, n) => {
1152
+ if (typeof n == "bigint") return n.toString();
1153
+ if (typeof n == "object" && n) {
1154
+ if (t.has(n)) return "[Circular]";
1155
+ t.add(n);
1156
+ }
1157
+ return n;
1158
+ }));
1159
+ } catch {
1160
+ return "[Unserializable value]";
1161
+ }
1162
+ }
1163
+ function Z(e) {
1164
+ let t = Y(e);
1165
+ if (!t) return [];
1166
+ try {
1167
+ let e = JSON.parse(window.localStorage.getItem(t) || "[]");
1168
+ return Array.isArray(e) ? e : [];
1169
+ } catch {
1170
+ return [];
1171
+ }
1172
+ }
1173
+ function ht(e, t) {
1174
+ let n = Y(e);
1175
+ if (!n) return;
1176
+ let r = t.slice(0, ct), i = !1;
1177
+ for (; r.length > 0;) try {
1178
+ window.localStorage.setItem(n, JSON.stringify(r));
1179
+ return;
1180
+ } catch {
1181
+ if (!i) {
1182
+ i = !0, pt(n);
1183
+ continue;
1184
+ }
1185
+ r = r.slice(0, -1);
1186
+ }
1187
+ try {
1188
+ window.localStorage.removeItem(n);
1189
+ } catch {}
1190
+ }
1191
+ function gt(e) {
1192
+ let t = Y(e);
1193
+ if (t) {
1194
+ try {
1195
+ window.localStorage.removeItem(t);
1196
+ } catch {}
1197
+ yt();
1198
+ }
1199
+ }
1200
+ function _t(e, t) {
1201
+ ht(e, Z(e).filter((e) => e.id !== t)), yt();
1202
+ }
1203
+ var vt = "gradio:run-history-change";
1204
+ function yt() {
1205
+ if (!(typeof window > "u")) try {
1206
+ window.dispatchEvent(new Event(vt));
1207
+ } catch {}
1208
+ }
1209
+ function bt(e) {
1210
+ return typeof window > "u" ? () => {} : (window.addEventListener(vt, e), window.addEventListener("storage", e), () => {
1211
+ window.removeEventListener(vt, e), window.removeEventListener("storage", e);
1212
+ });
1213
+ }
1214
+ function xt(e, t) {
1215
+ let n = dt(e);
1216
+ if (n) try {
1217
+ window.sessionStorage.setItem(n, JSON.stringify(t));
1218
+ } catch {}
1219
+ }
1220
+ function St(e) {
1221
+ let t = dt(e);
1222
+ if (!t) return null;
1223
+ try {
1224
+ let e = window.sessionStorage.getItem(t);
1225
+ return window.sessionStorage.removeItem(t), e ? JSON.parse(e) : null;
1226
+ } catch {
1227
+ return null;
1228
+ }
1229
+ }
1230
+ function Ct(e, t) {
1231
+ let n = e.dependencies.find((e) => e.id === t.fn_index || typeof e.api_name == "string" && `/${e.api_name.replace(/^\//, "")}` === t.api_name);
1232
+ if (!n) return !1;
1233
+ let r = Array.isArray(t.inputs) ? t.inputs : Object.values(t.inputs ?? {}), i = Array.isArray(t.outputs) ? t.outputs : t.outputs === null || t.outputs === void 0 ? [] : [t.outputs], a = (t, n) => {
1234
+ for (let [r, i] of t.entries()) {
1235
+ let t = e.components.find((e) => e.id === i);
1236
+ !t || r >= n.length || t.type !== "state" && (t.props.value = n[r]);
1237
+ }
1238
+ };
1239
+ return a(n.inputs, r), a(n.outputs, i), !0;
1240
+ }
1241
+ function wt(e) {
1242
+ let t = St(e);
1243
+ return t ? Ct(e, t) : !1;
1244
+ }
1245
+ function Tt(e) {
1246
+ let t = Y(e);
1247
+ if (!t) return null;
1248
+ pt(t);
1249
+ let n = {
1250
+ id: mt(),
1251
+ endpoint: e.endpoint,
1252
+ api_name: e.api_name,
1253
+ fn_index: e.fn_index,
1254
+ page: `${window.location.pathname}${window.location.search}`,
1255
+ inputs: X(e.inputs),
1256
+ outputs: null,
1257
+ ...e.input_components ? { input_components: X(e.input_components) } : {},
1258
+ ...e.output_components ? { output_components: X(e.output_components) } : {},
1259
+ status: "running",
1260
+ started_at: (/* @__PURE__ */ new Date()).toISOString()
1261
+ };
1262
+ return ht(e, [n, ...Z(e)]), yt(), n.id;
1263
+ }
1264
+ function Et(e, t, n) {
1265
+ if (!t) return;
1266
+ let r = Z(e), i = r.find((e) => e.id === t);
1267
+ i && (i.inputs = X(n), ht(e, r));
1268
+ }
1269
+ function Dt(e, t, n) {
1270
+ if (!t) return;
1271
+ let r = Z(e), i = r.find((e) => e.id === t);
1272
+ if (!i) return;
1273
+ let a = !1;
1274
+ if (n.type === "data") i.outputs = X(n.data), Q.set(t, i.outputs);
1275
+ else if (n.type === "status" && n.original_msg === "process_starts") At(i, n.time);
1276
+ else if (n.type === "status" && (n.stage === "generating" || n.stage === "streaming")) i.streamed = !0;
1277
+ else if (n.type === "status" && n.stage === "complete") i.status = "completed", jt(i, n), a = !0;
1278
+ else if (n.type === "status" && n.stage === "error") i.status = "failed", i.error = typeof n.message == "string" ? n.message : JSON.stringify(n.message || "Unknown error"), jt(i, n), a = !0;
1279
+ else return;
1280
+ if (a) Q.has(t) && (i.outputs = Q.get(t)), Q.delete(t), kt.delete(t);
1281
+ else if (i.streamed) {
1282
+ if (Date.now() - (kt.get(t) ?? 0) < Ot) return;
1283
+ kt.set(t, Date.now()), Q.delete(t);
1284
+ }
1285
+ ht(e, r);
1286
+ }
1287
+ var Ot = 500, kt = /* @__PURE__ */ new Map(), Q = /* @__PURE__ */ new Map();
1288
+ function At(e, t) {
1289
+ if (e.process_started_at) return;
1290
+ let n = t || /* @__PURE__ */ new Date();
1291
+ e.process_started_at = n.toISOString(), e.queued_ms = Math.max(0, n.getTime() - Date.parse(e.started_at));
1292
+ }
1293
+ function jt(e, t) {
1294
+ let n = t.time || /* @__PURE__ */ new Date();
1295
+ e.completed_at = n.toISOString(), e.duration_ms = (!e.streamed && typeof t.cache_duration == "number" && t.cache_duration >= 0 ? t.cache_duration * 1e3 : null) ?? Math.max(0, n.getTime() - Date.parse(e.process_started_at || e.started_at));
1296
+ }
1297
+ function Mt(e) {
1298
+ return J(() => Z(e), []);
1299
+ }
1300
+ function Nt(e) {
1301
+ J(() => gt(e), void 0);
1302
+ }
1303
+ function Pt(e, t) {
1304
+ J(() => _t(e, t), void 0);
1305
+ }
1306
+ function Ft(e, t) {
1307
+ J(() => xt(e, t), void 0);
1308
+ }
1309
+ function It(e) {
1310
+ return J(() => St(e), null);
1311
+ }
1312
+ function Lt(e) {
1313
+ return J(() => wt(e), !1);
1314
+ }
1315
+ function Rt(e) {
1316
+ return J(() => Tt(e), null);
1317
+ }
1318
+ function zt(e, t, n) {
1319
+ J(() => Et(e, t, n), void 0);
1320
+ }
1321
+ function Bt(e, t, n) {
1322
+ J(() => Dt(e, t, n), void 0);
1323
+ }
1324
+ function Vt(e) {
1325
+ return J(() => bt(() => J(e, void 0)), () => {});
1326
+ }
1327
+ //#endregion
1105
1328
  //#region src/utils/submit.ts
1106
- function et(e, t = {}, n, r, i, a) {
1329
+ function Ht(e, t = {}, n, r, i, a) {
1107
1330
  try {
1108
- let { token: o } = this.options, { fetch: s, app_reference: c, config: l, session_hash: f, api_info: p, api_map: m, stream_status: h, pending_stream_messages: g, pending_diff_streams: _, event_callbacks: v, unclosed_events: ee, post_data: y, options: x, api_prefix: S } = this, C = a || { "x-gradio-user": "api" }, w = this;
1109
- if (!p) throw Error(ae);
1331
+ let { token: o } = this.options, { fetch: s, app_reference: c, config: l, session_hash: f, api_info: p, api_map: m, stream_status: h, pending_stream_messages: g, pending_diff_streams: ee, event_callbacks: _, unclosed_events: te, post_data: v, options: b, api_prefix: x } = this, S = a || { "x-gradio-user": "api" }, C = this;
1332
+ if (!p) throw Error(se);
1110
1333
  if (!l) throw Error("Could not resolve app config");
1111
- let { fn_index: T, endpoint_info: E, dependency: D } = nt(p, e, m, l), ie = fe(t, E), O, k = l.protocol ?? "ws";
1112
- if (k === "ws") throw Error(oe);
1113
- let A = "", j = typeof e == "number" ? "/predict" : e, M, N = null, P = !1, F = {}, I = typeof window < "u" && typeof document < "u" ? new URLSearchParams(window.location.search).toString() : "", se = x?.events?.reduce((e, t) => (e[t] = !0, e), {}) || {};
1114
- function L(e) {
1115
- (i || se[e.type]) && ue(e);
1334
+ let { fn_index: w, endpoint_info: T, dependency: E } = Wt(p, e, m, l), ae = ye(t, T), D = l.protocol ?? "ws";
1335
+ if (D === "ws") throw Error(ce);
1336
+ let oe = typeof E.api_name == "string" ? `/${E.api_name}` : e, le = typeof E.api_name == "string" ? `/${E.api_name}` : `Function ${w}`, O = (e) => {
1337
+ let t = l.components.find((t) => t.id === e);
1338
+ return t ? {
1339
+ type: t.type,
1340
+ component_class_id: t.component_class_id,
1341
+ props: t.props
1342
+ } : null;
1343
+ }, ue = E.api_visibility === "public", de = l.run_history !== !1 && this.options.record_history !== !1, k = {
1344
+ app_id: l.app_id,
1345
+ username: l.username
1346
+ }, fe = !de || !ue ? null : Rt({
1347
+ ...k,
1348
+ endpoint: oe,
1349
+ api_name: le,
1350
+ fn_index: w,
1351
+ inputs: G(ae, E, l.components, "input", !0),
1352
+ input_components: E.inputs.map(O),
1353
+ output_components: E.outputs.map(O)
1354
+ }), A, j = "", M = typeof e == "number" ? "/predict" : e, N, P = null, F = !1, I = {}, L = typeof window < "u" && typeof document < "u" ? new URLSearchParams(window.location.search).toString() : "", pe = b?.events?.reduce((e, t) => (e[t] = !0, e), {}) || {};
1355
+ function R(e) {
1356
+ Bt(k, fe, e), (i || pe[e.type]) && U(e);
1116
1357
  }
1117
- async function ce() {
1358
+ async function me() {
1118
1359
  let e = {}, t = {};
1119
- e = { event_id: N }, t = {
1120
- event_id: N,
1360
+ e = { event_id: P }, t = {
1361
+ event_id: P,
1121
1362
  session_hash: f,
1122
- fn_index: T
1363
+ fn_index: w
1123
1364
  };
1124
1365
  try {
1125
1366
  if (!l) throw Error("Could not resolve app config");
1126
- "event_id" in t && await s(`${l.root}${S}/${ne}`, {
1367
+ "event_id" in t && await s(`${l.root}${x}/${re}`, {
1127
1368
  headers: { "Content-Type": "application/json" },
1128
1369
  method: "POST",
1129
1370
  body: JSON.stringify(t)
1130
- }), await s(`${l.root}${S}/${te}`, {
1371
+ }), await s(`${l.root}${x}/${ne}`, {
1131
1372
  headers: { "Content-Type": "application/json" },
1132
1373
  method: "POST",
1133
1374
  body: JSON.stringify(e)
@@ -1136,64 +1377,65 @@ function et(e, t = {}, n, r, i, a) {
1136
1377
  console.warn("The `/reset` endpoint could not be called. Subsequent endpoint results may be unreliable.");
1137
1378
  }
1138
1379
  }
1139
- let R = async (e) => {
1380
+ let he = async (e) => {
1140
1381
  await this._resolve_heartbeat(e);
1141
1382
  };
1142
- async function z(e) {
1383
+ async function ge(e) {
1143
1384
  if (!l) return;
1144
1385
  let t = e.render_id;
1145
1386
  l.components = [...l.components.filter((e) => e.props.rendered_in !== t), ...e.components], l.dependencies = [...l.dependencies.filter((e) => e.rendered_in !== t), ...e.dependencies];
1146
1387
  let n = l.components.some((e) => e.type === "state"), r = l.dependencies.some((e) => e.targets.some((e) => e[1] === "unload"));
1147
- l.connect_heartbeat = n || r, await R(l), L({
1388
+ l.connect_heartbeat = n || r, await he(l), R({
1148
1389
  type: "render",
1149
1390
  data: e,
1150
- endpoint: j,
1151
- fn_index: T
1391
+ endpoint: M,
1392
+ fn_index: w
1152
1393
  });
1153
1394
  }
1154
- let B = this.handle_blob(l.root, ie, E).then(async (e) => {
1155
- if (M = {
1156
- data: X(e, D, l.components, "input", !0) || [],
1395
+ let _e = this.handle_blob(l.root, ae, T).then(async (e) => {
1396
+ let t = G(e, E, l.components, "input", !0);
1397
+ if (zt(k, fe, t || []), N = {
1398
+ data: t || [],
1157
1399
  event_data: n,
1158
- fn_index: T,
1400
+ fn_index: w,
1159
1401
  trigger_id: r,
1160
- ...x.oauth_token && E?.oauth_token ? { oauth_token: x.oauth_token } : {}
1161
- }, be(T, l)) L({
1402
+ ...b.oauth_token && T?.oauth_token ? { oauth_token: b.oauth_token } : {}
1403
+ }, Te(w, l)) R({
1162
1404
  type: "status",
1163
- endpoint: j,
1405
+ endpoint: M,
1164
1406
  stage: "pending",
1165
1407
  queue: !1,
1166
- fn_index: T,
1408
+ fn_index: w,
1167
1409
  time: /* @__PURE__ */ new Date()
1168
- }), y(`${l.root}${S}/run${j.startsWith("/") ? j : `/${j}`}${I ? "?" + I : ""}`, {
1169
- ...M,
1410
+ }), v(`${l.root}${x}/run${M.startsWith("/") ? M : `/${M}`}${L ? "?" + L : ""}`, {
1411
+ ...N,
1170
1412
  session_hash: f
1171
- }, C).then(async ([e, t]) => {
1413
+ }, S).then(async ([e, t]) => {
1172
1414
  let i = e.data;
1173
- if (t == 200) L({
1415
+ if (t == 200) R({
1174
1416
  type: "data",
1175
- endpoint: j,
1176
- fn_index: T,
1177
- data: X(i, D, l.components, "output", x.with_null_state),
1417
+ endpoint: M,
1418
+ fn_index: w,
1419
+ data: G(i, E, l.components, "output", b.with_null_state),
1178
1420
  time: /* @__PURE__ */ new Date(),
1179
1421
  event_data: n,
1180
1422
  trigger_id: r
1181
- }), e.render_config && await z(e.render_config), L({
1423
+ }), e.render_config && await ge(e.render_config), R({
1182
1424
  type: "status",
1183
- endpoint: j,
1184
- fn_index: T,
1425
+ endpoint: M,
1426
+ fn_index: w,
1185
1427
  stage: "complete",
1186
1428
  eta: e.average_duration,
1187
1429
  queue: !1,
1188
1430
  time: /* @__PURE__ */ new Date()
1189
1431
  });
1190
1432
  else {
1191
- let t = e?.error === b;
1192
- L({
1433
+ let t = e?.error === y;
1434
+ R({
1193
1435
  type: "status",
1194
1436
  stage: "error",
1195
- endpoint: j,
1196
- fn_index: T,
1437
+ endpoint: M,
1438
+ fn_index: w,
1197
1439
  message: e.error,
1198
1440
  broken: t,
1199
1441
  queue: !1,
@@ -1201,303 +1443,303 @@ function et(e, t = {}, n, r, i, a) {
1201
1443
  });
1202
1444
  }
1203
1445
  }).catch((e) => {
1204
- L({
1446
+ R({
1205
1447
  type: "status",
1206
1448
  stage: "error",
1207
1449
  message: e.message,
1208
- endpoint: j,
1209
- fn_index: T,
1450
+ endpoint: M,
1451
+ fn_index: w,
1210
1452
  queue: !1,
1211
1453
  time: /* @__PURE__ */ new Date()
1212
1454
  });
1213
1455
  });
1214
- else if (k == "sse") {
1215
- L({
1456
+ else if (D == "sse") {
1457
+ R({
1216
1458
  type: "status",
1217
1459
  stage: "pending",
1218
1460
  queue: !0,
1219
- endpoint: j,
1220
- fn_index: T,
1461
+ endpoint: M,
1462
+ fn_index: w,
1221
1463
  time: /* @__PURE__ */ new Date()
1222
1464
  });
1223
- var t = new URLSearchParams({
1224
- fn_index: T.toString(),
1465
+ var i = new URLSearchParams({
1466
+ fn_index: w.toString(),
1225
1467
  session_hash: f
1226
1468
  }).toString();
1227
- let e = new URL(`${l.root}${S}/${u}?${I ? I + "&" : ""}${t}`);
1228
- if (this.jwt && e.searchParams.set("__sign", this.jwt), O = this.stream(e), !O) return Promise.reject(/* @__PURE__ */ Error("Cannot connect to SSE endpoint: " + e.toString()));
1229
- O.onmessage = async function(e) {
1230
- let { type: t, status: i, data: a } = de(JSON.parse(e.data), F[T]);
1231
- if (t === "update" && i && !P) L({
1469
+ let e = new URL(`${l.root}${x}/${u}?${L ? L + "&" : ""}${i}`);
1470
+ if (this.jwt && e.searchParams.set("__sign", this.jwt), A = this.stream(e), !A) return Promise.reject(/* @__PURE__ */ Error("Cannot connect to SSE endpoint: " + e.toString()));
1471
+ A.onmessage = async function(e) {
1472
+ let { type: t, status: i, data: a } = ve(JSON.parse(e.data), I[w]);
1473
+ if (t === "update" && i && !F) R({
1232
1474
  type: "status",
1233
- endpoint: j,
1234
- fn_index: T,
1475
+ endpoint: M,
1476
+ fn_index: w,
1235
1477
  time: /* @__PURE__ */ new Date(),
1236
1478
  ...i
1237
- }), i.stage === "error" && (O?.close(), W());
1479
+ }), i.stage === "error" && (A?.close(), V());
1238
1480
  else if (t === "data") {
1239
- let [e, t] = await y(`${l.root}${S}/queue/data`, {
1240
- ...M,
1481
+ let [e, t] = await v(`${l.root}${x}/queue/data`, {
1482
+ ...N,
1241
1483
  session_hash: f,
1242
- event_id: N
1484
+ event_id: P
1243
1485
  });
1244
- t !== 200 && (L({
1486
+ t !== 200 && (R({
1245
1487
  type: "status",
1246
1488
  stage: "error",
1247
- message: b,
1489
+ message: y,
1248
1490
  queue: !0,
1249
- endpoint: j,
1250
- fn_index: T,
1491
+ endpoint: M,
1492
+ fn_index: w,
1251
1493
  time: /* @__PURE__ */ new Date()
1252
- }), O?.close(), W());
1253
- } else t === "complete" ? P = i : t === "log" ? L({
1494
+ }), A?.close(), V());
1495
+ } else t === "complete" ? F = i : t === "log" ? R({
1254
1496
  type: "log",
1255
1497
  title: a.title,
1256
1498
  log: a.log,
1257
1499
  level: a.level,
1258
- endpoint: j,
1500
+ endpoint: M,
1259
1501
  duration: a.duration,
1260
1502
  visible: a.visible,
1261
- fn_index: T
1262
- }) : (t === "generating" || t === "streaming") && L({
1503
+ fn_index: w
1504
+ }) : (t === "generating" || t === "streaming") && R({
1263
1505
  type: "status",
1264
1506
  time: /* @__PURE__ */ new Date(),
1265
1507
  ...i,
1266
1508
  stage: i?.stage,
1267
1509
  queue: !0,
1268
- endpoint: j,
1269
- fn_index: T
1510
+ endpoint: M,
1511
+ fn_index: w
1270
1512
  });
1271
- a && (L({
1513
+ a && (R({
1272
1514
  type: "data",
1273
1515
  time: /* @__PURE__ */ new Date(),
1274
- data: X(a.data, D, l.components, "output", x.with_null_state),
1275
- endpoint: j,
1276
- fn_index: T,
1516
+ data: G(a.data, E, l.components, "output", b.with_null_state),
1517
+ endpoint: M,
1518
+ fn_index: w,
1277
1519
  event_data: n,
1278
1520
  trigger_id: r
1279
- }), P && (L({
1521
+ }), F && (R({
1280
1522
  type: "status",
1281
1523
  time: /* @__PURE__ */ new Date(),
1282
- ...P,
1524
+ ...F,
1283
1525
  stage: i?.stage,
1284
1526
  queue: !0,
1285
- endpoint: j,
1286
- fn_index: T
1287
- }), O?.close(), W()));
1527
+ endpoint: M,
1528
+ fn_index: w
1529
+ }), A?.close(), V()));
1288
1530
  };
1289
- } else if (k == "sse_v1" || k == "sse_v2" || k == "sse_v2.1" || k == "sse_v3") {
1290
- L({
1531
+ } else if (D == "sse_v1" || D == "sse_v2" || D == "sse_v2.1" || D == "sse_v3") {
1532
+ R({
1291
1533
  type: "status",
1292
1534
  stage: "pending",
1293
1535
  queue: !0,
1294
- endpoint: j,
1295
- fn_index: T,
1536
+ endpoint: M,
1537
+ fn_index: w,
1296
1538
  time: /* @__PURE__ */ new Date()
1297
1539
  });
1298
1540
  let e = "";
1299
1541
  typeof window < "u" && typeof document < "u" && (e = window?.location?.hostname);
1300
- let t = Ve(e);
1301
- return (typeof window < "u" && typeof document < "u" && window.parent != window && t && window.supports_zerogpu_headers ? xe("zerogpu-headers", t) : Promise.resolve(null)).then((e) => {
1542
+ let t = Ke(e);
1543
+ return (typeof window < "u" && typeof document < "u" && window.parent != window && t && window.supports_zerogpu_headers ? Ee("zerogpu-headers", t) : Promise.resolve(null)).then((e) => {
1302
1544
  let t = {
1303
- ...C,
1545
+ ...S,
1304
1546
  ...e || {}
1305
1547
  };
1306
- return y(`${l.root}${S}/${d}?${I}`, {
1307
- ...M,
1548
+ return v(`${l.root}${x}/${d}?${L}`, {
1549
+ ...N,
1308
1550
  session_hash: f
1309
1551
  }, t);
1310
1552
  }).then(async ([e, t]) => {
1311
- if (e.event_id && (A = e.event_id), t === 503) L({
1553
+ if (e.event_id && (j = e.event_id), t === 503) R({
1312
1554
  type: "status",
1313
1555
  stage: "error",
1314
- message: re,
1556
+ message: ie,
1315
1557
  queue: !0,
1316
- endpoint: j,
1317
- fn_index: T,
1558
+ endpoint: M,
1559
+ fn_index: w,
1318
1560
  time: /* @__PURE__ */ new Date(),
1319
1561
  visible: !0
1320
- }), W();
1321
- else if (t === 422) L({
1562
+ }), V();
1563
+ else if (t === 422) R({
1322
1564
  type: "status",
1323
1565
  stage: "error",
1324
1566
  message: e.detail,
1325
1567
  queue: !0,
1326
- endpoint: j,
1327
- fn_index: T,
1568
+ endpoint: M,
1569
+ fn_index: w,
1328
1570
  code: "validation_error",
1329
1571
  time: /* @__PURE__ */ new Date(),
1330
1572
  visible: !0
1331
- }), W();
1573
+ }), V();
1332
1574
  else if (t !== 200) {
1333
- let t = e?.error === b;
1334
- L({
1575
+ let t = e?.error === y;
1576
+ R({
1335
1577
  type: "status",
1336
1578
  stage: "error",
1337
1579
  broken: t,
1338
- message: t ? b : e.detail || e.error,
1580
+ message: t ? y : e.detail || e.error,
1339
1581
  queue: !0,
1340
- endpoint: j,
1341
- fn_index: T,
1582
+ endpoint: M,
1583
+ fn_index: w,
1342
1584
  time: /* @__PURE__ */ new Date(),
1343
1585
  visible: !0
1344
- }), W();
1586
+ }), V();
1345
1587
  } else {
1346
- N = e.event_id, A = N;
1588
+ P = e.event_id, j = P;
1347
1589
  let t = async function(e) {
1348
1590
  try {
1349
- let { type: t, status: n, data: r, original_msg: i } = de(e, F[T]);
1591
+ let { type: t, status: n, data: r, original_msg: i } = ve(e, I[w]);
1350
1592
  if (t == "heartbeat") return;
1351
- if (t === "update" && n && !P) L({
1593
+ if (t === "update" && n && !F) R({
1352
1594
  type: "status",
1353
- endpoint: j,
1354
- fn_index: T,
1595
+ endpoint: M,
1596
+ fn_index: w,
1355
1597
  time: /* @__PURE__ */ new Date(),
1356
1598
  original_msg: i,
1357
1599
  ...n
1358
1600
  });
1359
- else if (t === "complete") P = n;
1601
+ else if (t === "complete") F = n;
1360
1602
  else if (t == "unexpected_error" || t == "broken_connection") {
1361
1603
  console.error("Unexpected error", n?.message);
1362
1604
  let e = t === "broken_connection";
1363
- L({
1605
+ R({
1364
1606
  type: "status",
1365
1607
  stage: "error",
1366
1608
  message: n?.message || "An Unexpected Error Occurred!",
1367
1609
  queue: !0,
1368
- endpoint: j,
1610
+ endpoint: M,
1369
1611
  broken: e,
1370
1612
  session_not_found: n?.session_not_found,
1371
- fn_index: T,
1613
+ fn_index: w,
1372
1614
  time: /* @__PURE__ */ new Date()
1373
1615
  });
1374
1616
  } else if (t === "log") {
1375
- L({
1617
+ R({
1376
1618
  type: "log",
1377
1619
  title: r.title,
1378
1620
  log: r.log,
1379
1621
  level: r.level,
1380
- endpoint: j,
1622
+ endpoint: M,
1381
1623
  duration: r.duration,
1382
1624
  visible: r.visible,
1383
- fn_index: T
1625
+ fn_index: w
1384
1626
  });
1385
1627
  return;
1386
- } else (t === "generating" || t === "streaming") && (L({
1628
+ } else (t === "generating" || t === "streaming") && (R({
1387
1629
  type: "status",
1388
1630
  time: /* @__PURE__ */ new Date(),
1389
1631
  ...n,
1390
1632
  stage: n?.stage,
1391
1633
  queue: !0,
1392
- endpoint: j,
1393
- fn_index: T
1394
- }), r && D.connection !== "stream" && [
1634
+ endpoint: M,
1635
+ fn_index: w
1636
+ }), r && E.connection !== "stream" && [
1395
1637
  "sse_v2",
1396
1638
  "sse_v2.1",
1397
1639
  "sse_v3"
1398
- ].includes(k) && Xe(_, N, r));
1399
- r && (L({
1640
+ ].includes(D) && nt(ee, P, r));
1641
+ r && (R({
1400
1642
  type: "data",
1401
1643
  time: /* @__PURE__ */ new Date(),
1402
- data: X(r.data, D, l.components, "output", x.with_null_state),
1403
- endpoint: j,
1404
- fn_index: T
1405
- }), r.render_config && await z(r.render_config), P && (L({
1644
+ data: G(r.data, E, l.components, "output", b.with_null_state),
1645
+ endpoint: M,
1646
+ fn_index: w
1647
+ }), r.render_config && await ge(r.render_config), F && (R({
1406
1648
  type: "status",
1407
1649
  time: /* @__PURE__ */ new Date(),
1408
- ...P,
1650
+ ...F,
1409
1651
  stage: n?.stage,
1410
1652
  queue: !0,
1411
- endpoint: j,
1412
- fn_index: T
1413
- }), W())), (n?.stage === "complete" || n?.stage === "error") && (v[N] && delete v[N], N in _ && delete _[N], W());
1653
+ endpoint: M,
1654
+ fn_index: w
1655
+ }), V())), (n?.stage === "complete" || n?.stage === "error") && (_[P] && delete _[P], P in ee && delete ee[P], V());
1414
1656
  } catch (e) {
1415
- console.error("Unexpected client exception", e), L({
1657
+ console.error("Unexpected client exception", e), R({
1416
1658
  type: "status",
1417
1659
  stage: "error",
1418
1660
  message: "An Unexpected Error Occurred!",
1419
1661
  queue: !0,
1420
- endpoint: j,
1421
- fn_index: T,
1662
+ endpoint: M,
1663
+ fn_index: w,
1422
1664
  time: /* @__PURE__ */ new Date()
1423
1665
  }), [
1424
1666
  "sse_v2",
1425
1667
  "sse_v2.1",
1426
1668
  "sse_v3"
1427
- ].includes(k) && (Q(h, w.abort_controller), h.open = !1, W());
1669
+ ].includes(D) && (tt(h, C.abort_controller), h.open = !1, V());
1428
1670
  }
1429
1671
  };
1430
- N in g && (g[N].forEach((e) => t(e)), delete g[N]), v[N] = t, ee.add(N), h.open || await this.open_stream();
1672
+ P in g && (g[P].forEach((e) => t(e)), delete g[P]), _[P] = t, te.add(P), h.open || await this.open_stream();
1431
1673
  }
1432
1674
  });
1433
1675
  }
1434
1676
  });
1435
- B.catch((e) => {
1436
- L({
1677
+ _e.catch((e) => {
1678
+ R({
1437
1679
  type: "status",
1438
1680
  stage: "error",
1439
1681
  message: e instanceof Error ? e.message : String(e),
1440
- queue: !be(T, l),
1441
- endpoint: j,
1442
- fn_index: T,
1682
+ queue: !Te(w, l),
1683
+ endpoint: M,
1684
+ fn_index: w,
1443
1685
  time: /* @__PURE__ */ new Date()
1444
- }), W();
1686
+ }), V();
1445
1687
  });
1446
- let V = !1, H = [], U = [];
1447
- function W() {
1448
- for (V = !0; U.length > 0;) U.shift()({
1688
+ let be = !1, z = [], B = [];
1689
+ function V() {
1690
+ for (be = !0; B.length > 0;) B.shift()({
1449
1691
  value: void 0,
1450
1692
  done: !0
1451
1693
  });
1452
1694
  }
1453
- function G(e) {
1454
- U.length > 0 ? U.shift()(e) : H.push(e);
1695
+ function H(e) {
1696
+ B.length > 0 ? B.shift()(e) : z.push(e);
1455
1697
  }
1456
- function le(e) {
1457
- G(tt(e)), W();
1698
+ function xe(e) {
1699
+ H(Ut(e)), V();
1458
1700
  }
1459
- function ue(e) {
1460
- G({
1701
+ function U(e) {
1702
+ H({
1461
1703
  value: e,
1462
1704
  done: !1
1463
1705
  });
1464
1706
  }
1465
- function K() {
1466
- return H.length > 0 ? Promise.resolve(H.shift()) : V ? Promise.resolve({
1707
+ function W() {
1708
+ return z.length > 0 ? Promise.resolve(z.shift()) : be ? Promise.resolve({
1467
1709
  value: void 0,
1468
1710
  done: !0
1469
- }) : new Promise((e) => U.push(e));
1711
+ }) : new Promise((e) => B.push(e));
1470
1712
  }
1471
- let q = {
1472
- [Symbol.asyncIterator]: () => q,
1473
- next: K,
1474
- throw: async (e) => (le(e), K()),
1475
- return: async () => (W(), {
1713
+ let Se = {
1714
+ [Symbol.asyncIterator]: () => Se,
1715
+ next: W,
1716
+ throw: async (e) => (xe(e), W()),
1717
+ return: async () => (V(), {
1476
1718
  value: void 0,
1477
1719
  done: !0
1478
1720
  }),
1479
- cancel: ce,
1721
+ cancel: me,
1480
1722
  send_chunk: (e) => {
1481
- this.post_data(`${l.root}${S}/stream/${A}`, {
1723
+ this.post_data(`${l.root}${x}/stream/${j}`, {
1482
1724
  ...e,
1483
1725
  session_hash: this.session_hash
1484
1726
  });
1485
1727
  },
1486
1728
  close_stream: () => {
1487
- this.post_data(`${l.root}${S}/stream/${A}/close`, {}), W();
1729
+ this.post_data(`${l.root}${x}/stream/${j}/close`, {}), V();
1488
1730
  },
1489
- event_id: () => A,
1490
- wait_for_id: async () => (await B, N)
1731
+ event_id: () => j,
1732
+ wait_for_id: async () => (await _e, P)
1491
1733
  };
1492
- return q;
1734
+ return Se;
1493
1735
  } catch (e) {
1494
1736
  throw console.error("Submit function encountered an error:", e), e;
1495
1737
  }
1496
1738
  }
1497
- function tt(e) {
1739
+ function Ut(e) {
1498
1740
  return { then: (t, n) => n(e) };
1499
1741
  }
1500
- function nt(e, t, n, r) {
1742
+ function Wt(e, t, n, r) {
1501
1743
  let i, a, o;
1502
1744
  if (typeof t == "number") i = t, a = e.unnamed_endpoints[i], o = r.dependencies.find((e) => e.id == t);
1503
1745
  else {
@@ -1539,13 +1781,13 @@ var $ = class {
1539
1781
  stream_instance = null;
1540
1782
  current_payload;
1541
1783
  get_url_config(e = null) {
1542
- if (!this.config) throw Error(x);
1784
+ if (!this.config) throw Error(b);
1543
1785
  e === null && (e = window.location.href);
1544
1786
  let t = (e) => e.replace(/^\/+|\/+$/g, ""), n = t(new URL(this.config.root).pathname), r = t(new URL(e).pathname), i;
1545
1787
  return i = r.startsWith(n) ? t(r.substring(n.length)) : "", this.get_page_config(i);
1546
1788
  }
1547
1789
  get_page_config(e) {
1548
- if (!this.config) throw Error(x);
1790
+ if (!this.config) throw Error(b);
1549
1791
  let t = this.config;
1550
1792
  return e in t.page || (e = ""), {
1551
1793
  ...t,
@@ -1568,7 +1810,7 @@ var $ = class {
1568
1810
  let t = new Headers();
1569
1811
  return this && this.cookies && t.append("Cookie", this.cookies), this && this.options.headers && new Headers(this.options.headers).forEach((e, n) => {
1570
1812
  t.append(n, e);
1571
- }), this && this.options.token && t.append("Authorization", `Bearer ${this.options.token}`), this.abort_controller = new AbortController(), this.stream_instance = $e(e.toString(), {
1813
+ }), this && this.options.token && t.append("Authorization", `Bearer ${this.options.token}`), this.abort_controller = new AbortController(), this.stream_instance = at(e.toString(), {
1572
1814
  credentials: this.options.credentials ?? "same-origin",
1573
1815
  headers: t,
1574
1816
  signal: this.abort_controller.signal
@@ -1585,20 +1827,20 @@ var $ = class {
1585
1827
  resolve_config;
1586
1828
  resolve_cookies;
1587
1829
  constructor(e, t = { events: ["data"] }) {
1588
- this.app_reference = e, this.deep_link = t.query_params?.deep_link || null, t.events ||= ["data"], P(t), this.options = t, this.current_payload = {}, t.cookies && (this.cookies = t.cookies), this.view_api = K.bind(this), this.upload_files = q.bind(this), this.handle_blob = we.bind(this), this.post_data = Oe.bind(this), this.submit = et.bind(this), this.predict = ke.bind(this), this.open_stream = Ye.bind(this), this.resolve_config = se.bind(this), this.resolve_cookies = ce.bind(this), this.upload = he.bind(this), this.fetch = this.fetch.bind(this), this.handle_space_success = this.handle_space_success.bind(this), this.stream = this.stream.bind(this);
1830
+ this.app_reference = e, this.deep_link = t.query_params?.deep_link || null, t.events ||= ["data"], k(t), this.options = t, this.current_payload = {}, t.cookies && (this.cookies = t.cookies), this.view_api = be.bind(this), this.upload_files = z.bind(this), this.handle_blob = ke.bind(this), this.post_data = Ne.bind(this), this.submit = Ht.bind(this), this.predict = Pe.bind(this), this.open_stream = et.bind(this), this.resolve_config = j.bind(this), this.resolve_cookies = N.bind(this), this.upload = H.bind(this), this.fetch = this.fetch.bind(this), this.handle_space_success = this.handle_space_success.bind(this), this.stream = this.stream.bind(this);
1589
1831
  }
1590
1832
  async init() {
1591
- He(), this.options.auth && await this.resolve_cookies(), await this._resolve_config().then((e) => e?.config && this._resolve_heartbeat(e.config));
1833
+ qe(), this.options.auth && await this.resolve_cookies(), await this._resolve_config().then((e) => e?.config && this._resolve_heartbeat(e.config));
1592
1834
  try {
1593
1835
  this.api_info = await this.view_api();
1594
1836
  } catch (e) {
1595
1837
  console.error(e.message);
1596
1838
  }
1597
- this.api_map = F(this.config?.dependencies || []);
1839
+ this.api_map = fe(this.config?.dependencies || []);
1598
1840
  }
1599
1841
  async _resolve_heartbeat(e) {
1600
- if (e && (this.config = e, this.api_prefix = e.api_prefix || "", this.config && this.config.connect_heartbeat && this.config.space_id && this.options.token && (this.jwt = await N(this.config.space_id, this.options.token, this.cookies))), e.space_id && this.options.token && (this.jwt = await N(e.space_id, this.options.token)), this.config && this.config.connect_heartbeat) {
1601
- let e = new URL(`${this.config.root}${this.api_prefix}/${v}/${this.session_hash}`);
1842
+ if (e && (this.config = e, this.api_prefix = e.api_prefix || "", this.config && this.config.connect_heartbeat && this.config.space_id && this.options.token && (this.jwt = await de(this.config.space_id, this.options.token, this.cookies))), e.space_id && this.options.token && (this.jwt = await de(e.space_id, this.options.token)), this.config && this.config.connect_heartbeat) {
1843
+ let e = new URL(`${this.config.root}${this.api_prefix}/${_}/${this.session_hash}`);
1602
1844
  this.jwt && e.searchParams.set("__sign", this.jwt), this.heartbeat_event ||= this.stream(e);
1603
1845
  }
1604
1846
  }
@@ -1607,7 +1849,7 @@ var $ = class {
1607
1849
  return t.session_hash && (n.session_hash = t.session_hash), await n.init(), n;
1608
1850
  }
1609
1851
  async reconnect() {
1610
- let e = new URL(`${this.config.root}${this.api_prefix}/${y}`), t;
1852
+ let e = new URL(`${this.config.root}${this.api_prefix}/${v}`), t;
1611
1853
  try {
1612
1854
  let n = await this.fetch(e);
1613
1855
  if (!n.ok) throw Error();
@@ -1618,17 +1860,17 @@ var $ = class {
1618
1860
  return t === this.config.app_id ? "connected" : "changed";
1619
1861
  }
1620
1862
  close() {
1621
- this.closed = !0, Q(this.stream_status, this.abort_controller);
1863
+ this.closed = !0, tt(this.stream_status, this.abort_controller);
1622
1864
  }
1623
1865
  async refresh() {
1624
- if (!this.config) throw Error(x);
1866
+ if (!this.config) throw Error(b);
1625
1867
  let e = await this.resolve_config(this.config.root, !1);
1626
- if (!e) throw Error(x);
1627
- this.config = e, this.api_prefix = e.api_prefix || "", this.api_map = F(e.dependencies || []);
1868
+ if (!e) throw Error(b);
1869
+ this.config = e, this.api_prefix = e.api_prefix || "", this.api_map = fe(e.dependencies || []);
1628
1870
  try {
1629
1871
  this.api_info = await this.view_api();
1630
1872
  } catch (e) {
1631
- console.error(C + e.message);
1873
+ console.error(S + e.message);
1632
1874
  }
1633
1875
  return this.get_url_config();
1634
1876
  }
@@ -1636,18 +1878,18 @@ var $ = class {
1636
1878
  this.current_payload = e;
1637
1879
  }
1638
1880
  static async duplicate(e, t = { events: ["data"] }) {
1639
- return Ie(e, t);
1881
+ return Ve(e, t);
1640
1882
  }
1641
1883
  async _resolve_config() {
1642
- let { http_protocol: e, host: t, space_id: n } = await U(this.app_reference, this.options.token), { status_callback: r } = this.options;
1643
- n && r && await Ae(n, r);
1884
+ let { http_protocol: e, host: t, space_id: n } = await R(this.app_reference, this.options.token), { status_callback: r } = this.options;
1885
+ n && r && await Fe(n, r);
1644
1886
  let i;
1645
1887
  try {
1646
1888
  let n = `${e}//${t}`;
1647
- if (i = await this.resolve_config(n), !i) throw Error(x);
1889
+ if (i = await this.resolve_config(n), !i) throw Error(b);
1648
1890
  return this.config_success(i);
1649
1891
  } catch (e) {
1650
- if (n && r) Z(n, V.test(n) ? "space_name" : "subdomain", this.handle_space_success);
1892
+ if (n && r) K(n, L.test(n) ? "space_name" : "subdomain", this.handle_space_success);
1651
1893
  else throw r && r({
1652
1894
  status: "error",
1653
1895
  message: "Could not load this space.",
@@ -1657,19 +1899,22 @@ var $ = class {
1657
1899
  }
1658
1900
  }
1659
1901
  async config_success(e) {
1660
- if (this.config = e, this.api_prefix = e.api_prefix || "", this.config.auth_required) return this.prepare_return_obj();
1902
+ if (this.config = e, this.api_prefix = e.api_prefix || "", e.run_history === !1 && Nt({
1903
+ app_id: e.app_id,
1904
+ username: e.username
1905
+ }), this.config.auth_required) return this.prepare_return_obj();
1661
1906
  try {
1662
1907
  this.api_info = await this.view_api();
1663
1908
  } catch (e) {
1664
- console.error(C + e.message);
1909
+ console.error(S + e.message);
1665
1910
  }
1666
1911
  return this.prepare_return_obj();
1667
1912
  }
1668
1913
  async handle_space_success(e) {
1669
- if (!this) throw Error(x);
1914
+ if (!this) throw Error(b);
1670
1915
  let { status_callback: t } = this.options;
1671
1916
  if (t && t(e), e.status === "running") try {
1672
- if (this.config = await this._resolve_config(), this.api_prefix = this?.config?.api_prefix || "", !this.config) throw Error(x);
1917
+ if (this.config = await this._resolve_config(), this.api_prefix = this?.config?.api_prefix || "", !this.config) throw Error(b);
1673
1918
  return await this.config_success(this.config);
1674
1919
  } catch (e) {
1675
1920
  throw t && t({
@@ -1681,7 +1926,7 @@ var $ = class {
1681
1926
  }
1682
1927
  }
1683
1928
  async component_server(e, t, n) {
1684
- if (!this.config) throw Error(x);
1929
+ if (!this.config) throw Error(b);
1685
1930
  let r = {}, { token: i } = this.options, { session_hash: a } = this;
1686
1931
  i && (r.Authorization = `Bearer ${this.options.token}`);
1687
1932
  let o, s = this.config.components.find((t) => t.id === e);
@@ -1700,7 +1945,7 @@ var $ = class {
1700
1945
  }), r["Content-Type"] = "application/json";
1701
1946
  i && (r.Authorization = `Bearer ${i}`);
1702
1947
  try {
1703
- let e = await this.fetch(`${o}${this.api_prefix}/${ee}/`, {
1948
+ let e = await this.fetch(`${o}${this.api_prefix}/${te}/`, {
1704
1949
  method: "POST",
1705
1950
  body: c,
1706
1951
  headers: r,
@@ -1713,7 +1958,7 @@ var $ = class {
1713
1958
  }
1714
1959
  }
1715
1960
  set_cookies(e) {
1716
- this.cookies = B(e).join("; ");
1961
+ this.cookies = I(e).join("; ");
1717
1962
  }
1718
1963
  prepare_return_obj() {
1719
1964
  return {
@@ -1725,11 +1970,11 @@ var $ = class {
1725
1970
  };
1726
1971
  }
1727
1972
  };
1728
- async function rt(e, t = { events: ["data"] }) {
1973
+ async function Gt(e, t = { events: ["data"] }) {
1729
1974
  return await $.connect(e, t);
1730
1975
  }
1731
- async function it(e, t) {
1976
+ async function Kt(e, t) {
1732
1977
  return await $.duplicate(e, t);
1733
1978
  }
1734
1979
  //#endregion
1735
- export { $ as Client, J as FileData, ie as MISSING_CREDENTIALS_MSG, rt as client, it as duplicate, Se as handle_file, ke as predict, ge as prepare_files, et as submit, he as upload, q as upload_files };
1980
+ export { $ as Client, U as FileData, ae as MISSING_CREDENTIALS_MSG, Lt as apply_run_history_replay, Nt as clear_run_history, Gt as client, It as consume_run_history_replay, Pt as delete_run_history, Kt as duplicate, De as handle_file, Vt as on_run_history_change, Pe as predict, xe as prepare_files, Mt as read_run_history, ut as run_history_url, Ft as stage_run_history_replay, Ht as submit, H as upload, z as upload_files };