@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/browser.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", ee = "info", h = "runtime", te = "sleeptime", g = "heartbeat", ne = "component_server", re = "reset", ie = "cancel", _ = "app_id", ae = "This application is currently busy. Please try again. ", v = "Connection errored out. ", y = "Could not resolve app config. ", b = "Could not get space status. ", x = "Could not get API info. ", S = "Space metadata could not be loaded. ", C = "Invalid URL. A full URL path is required.", w = "Not authorized to access this space. ", T = "Invalid credentials. Could not login. ", oe = "Login credentials are required to access this space.", E = "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.", se = (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.`, ce = "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. ", le = "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.", ue = "File system access is only available in Node.js environments", D = "Root URL not found in client config", de = "Error uploading file";
12
12
  //#endregion
13
13
  //#region src/helpers/init_helpers.ts
14
- async function N(e, t, n) {
14
+ async function fe(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 O(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 k(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(y);
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(E);
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(T);
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(w);
78
+ throw Error(`${y}(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(T) : Error(S);
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(S);
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(se(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(S);
144
144
  }
145
- if (!t) throw Error(w);
145
+ if (!t) throw Error(S);
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(C);
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: ae,
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, ee);
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(v);
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(v + 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,10 +615,10 @@ function X(e, t, n, r, i = !1) {
615
615
  }
616
616
  //#endregion
617
617
  //#region src/utils/handle_blob.ts
618
- async function Ce(e, t, n) {
618
+ async function Oe(e, t, n) {
619
619
  let r = this;
620
- await we(r, t);
621
- let i = await Y(t, void 0, [], !0, n);
620
+ await ke(r, t);
621
+ let i = await we(t, void 0, [], !0, n);
622
622
  return (await Promise.all(i.map(async ({ path: t, blob: n, type: i }) => {
623
623
  if (!n) return {
624
624
  path: t,
@@ -632,40 +632,40 @@ async function Ce(e, t, n) {
632
632
  name: typeof File < "u" && n instanceof File ? n?.name : void 0
633
633
  };
634
634
  }))).forEach(({ path: e, file_url: n, type: r, name: i }) => {
635
- r === "Gallery" ? ye(t, n, e) : n && ye(t, new J({
635
+ r === "Gallery" ? Ce(t, n, e) : n && Ce(t, new U({
636
636
  path: n,
637
637
  orig_name: i
638
638
  }), e);
639
639
  }), t;
640
640
  }
641
- async function we(e, t) {
642
- if (!(e.config?.root || e.config?.root_url)) throw Error(j);
643
- await Te(e, t);
641
+ async function ke(e, t) {
642
+ if (!(e.config?.root || e.config?.root_url)) throw Error(D);
643
+ await Ae(e, t);
644
644
  }
645
- async function Te(e, t, n = []) {
646
- for (let r in t) t[r] instanceof _e ? await Ee(e, t, r) : typeof t[r] == "object" && t[r] !== null && await Te(e, t[r], [...n, r]);
645
+ async function Ae(e, t, n = []) {
646
+ for (let r in t) t[r] instanceof W ? await je(e, t, r) : typeof t[r] == "object" && t[r] !== null && await Ae(e, t[r], [...n, r]);
647
647
  }
648
- async function Ee(e, t, n) {
648
+ async function je(e, t, n) {
649
649
  let r = t[n], i = e.config?.root || e.config?.root_url;
650
- if (!i) throw Error(j);
650
+ if (!i) throw Error(D);
651
651
  try {
652
652
  let a, o;
653
653
  if (typeof process < "u" && process.versions && process.versions.node) {
654
654
  let e = await import("./__vite-browser-external-Cgmn0awE.js").then((e) => /* @__PURE__ */ c(e.default, 1));
655
655
  o = (await import("./__vite-browser-external-Cgmn0awE.js").then((e) => /* @__PURE__ */ c(e.default, 1))).resolve(process.cwd(), r.meta.path), a = await e.readFile(o);
656
- } else throw Error(A);
656
+ } else throw Error(ue);
657
657
  let s = new Blob([a], { type: "application/octet-stream" }), l = await e.upload_files(i, [s]), u = l.files && l.files[0];
658
- u && (t[n] = new J({
658
+ u && (t[n] = new U({
659
659
  path: u,
660
660
  orig_name: r.meta.name || ""
661
661
  }));
662
662
  } catch (e) {
663
- console.error(M, e);
663
+ console.error(de, e);
664
664
  }
665
665
  }
666
666
  //#endregion
667
667
  //#region src/utils/post_data.ts
668
- async function De(e, t, n) {
668
+ async function Me(e, t, n) {
669
669
  let r = { "Content-Type": "application/json" };
670
670
  this.options.token && (r.Authorization = `Bearer ${this.options.token}`);
671
671
  try {
@@ -679,7 +679,7 @@ async function De(e, t, n) {
679
679
  credentials: this.options.credentials ?? "same-origin"
680
680
  });
681
681
  } catch {
682
- return [{ error: b }, 500];
682
+ return [{ error: v }, 500];
683
683
  }
684
684
  let a, o;
685
685
  try {
@@ -691,7 +691,7 @@ async function De(e, t, n) {
691
691
  }
692
692
  //#endregion
693
693
  //#region src/utils/predict.ts
694
- async function Oe(e, t = {}) {
694
+ async function Ne(e, t = {}) {
695
695
  let n = !1, r = !1;
696
696
  if (!this.config) throw Error("Could not resolve app config");
697
697
  if (typeof e == "number") this.config.dependencies.find((t) => t.id == e);
@@ -714,7 +714,7 @@ async function Oe(e, t = {}) {
714
714
  }
715
715
  //#endregion
716
716
  //#region src/helpers/spaces.ts
717
- async function Z(e, t, n) {
717
+ async function K(e, t, n) {
718
718
  let r = t === "subdomain" ? `https://huggingface.co/api/spaces/by-subdomain/${e}` : `https://huggingface.co/api/spaces/${e}`, i, a;
719
719
  try {
720
720
  if (i = await fetch(r), a = i.status, a !== 200) throw Error();
@@ -723,7 +723,7 @@ async function Z(e, t, n) {
723
723
  n({
724
724
  status: "error",
725
725
  load_status: "error",
726
- message: S,
726
+ message: b,
727
727
  detail: "NOT_FOUND"
728
728
  });
729
729
  return;
@@ -739,7 +739,7 @@ async function Z(e, t, n) {
739
739
  message: "Space is asleep. Waking it up...",
740
740
  detail: o
741
741
  }), setTimeout(() => {
742
- Z(e, t, n);
742
+ K(e, t, n);
743
743
  }, 1e3);
744
744
  break;
745
745
  case "PAUSED":
@@ -748,7 +748,7 @@ async function Z(e, t, n) {
748
748
  load_status: "error",
749
749
  message: "This space has been paused by the author. If you would like to try this demo, consider duplicating the space.",
750
750
  detail: o,
751
- discussions_enabled: await je(s)
751
+ discussions_enabled: await Ie(s)
752
752
  });
753
753
  break;
754
754
  case "RUNNING":
@@ -767,7 +767,7 @@ async function Z(e, t, n) {
767
767
  message: "Space is building...",
768
768
  detail: o
769
769
  }), setTimeout(() => {
770
- Z(e, t, n);
770
+ K(e, t, n);
771
771
  }, 1e3);
772
772
  break;
773
773
  case "APP_STARTING":
@@ -777,7 +777,7 @@ async function Z(e, t, n) {
777
777
  message: "Space is starting...",
778
778
  detail: o
779
779
  }), setTimeout(() => {
780
- Z(e, t, n);
780
+ K(e, t, n);
781
781
  }, 1e3);
782
782
  break;
783
783
  default:
@@ -786,34 +786,34 @@ async function Z(e, t, n) {
786
786
  load_status: "error",
787
787
  message: "This space is experiencing an issue.",
788
788
  detail: o,
789
- discussions_enabled: await je(s)
789
+ discussions_enabled: await Ie(s)
790
790
  });
791
791
  break;
792
792
  }
793
793
  }
794
- var ke = async (e, t) => {
794
+ var Pe = async (e, t) => {
795
795
  let n = 0;
796
796
  return new Promise((r) => {
797
- Z(e, V.test(e) ? "space_name" : "subdomain", (i) => {
797
+ K(e, L.test(e) ? "space_name" : "subdomain", (i) => {
798
798
  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(() => {
799
- ke(e, t).then(r);
799
+ Pe(e, t).then(r);
800
800
  }, 5e3)) : r());
801
801
  });
802
802
  });
803
- }, Ae = /^(?=[^]*\b[dD]iscussions{0,1}\b)(?=[^]*\b[dD]isabled\b)[^]*$/;
804
- async function je(e) {
803
+ }, Fe = /^(?=[^]*\b[dD]iscussions{0,1}\b)(?=[^]*\b[dD]isabled\b)[^]*$/;
804
+ async function Ie(e) {
805
805
  try {
806
806
  let t = await fetch(`https://huggingface.co/api/spaces/${e}/discussions`, { method: "HEAD" }), n = t.headers.get("x-error-message");
807
- return !(!t.ok || n && Ae.test(n));
807
+ return !(!t.ok || n && Fe.test(n));
808
808
  } catch {
809
809
  return !1;
810
810
  }
811
811
  }
812
- async function Me(e, t) {
812
+ async function Le(e, t) {
813
813
  let n = {};
814
814
  t && (n.Authorization = `Bearer ${t}`);
815
815
  try {
816
- let t = await fetch(`https://huggingface.co/api/spaces/${e}/${g}`, { headers: n });
816
+ let t = await fetch(`https://huggingface.co/api/spaces/${e}/${h}`, { headers: n });
817
817
  if (t.status !== 200) throw Error("Space hardware could not be obtained.");
818
818
  let { hardware: r } = await t.json();
819
819
  return r.current;
@@ -821,12 +821,12 @@ async function Me(e, t) {
821
821
  throw Error(e.message);
822
822
  }
823
823
  }
824
- async function Ne(e, t, n) {
824
+ async function Re(e, t, n) {
825
825
  let r = {};
826
826
  n && (r.Authorization = `Bearer ${n}`);
827
827
  let i = { seconds: t };
828
828
  try {
829
- let t = await fetch(`https://huggingface.co/api/spaces/${e}/${_}`, {
829
+ let t = await fetch(`https://huggingface.co/api/spaces/${e}/${te}`, {
830
830
  method: "POST",
831
831
  headers: {
832
832
  "Content-Type": "application/json",
@@ -840,7 +840,7 @@ async function Ne(e, t, n) {
840
840
  throw Error(e.message);
841
841
  }
842
842
  }
843
- var Pe = [
843
+ var ze = [
844
844
  "cpu-basic",
845
845
  "cpu-upgrade",
846
846
  "cpu-xl",
@@ -857,14 +857,14 @@ var Pe = [
857
857
  ];
858
858
  //#endregion
859
859
  //#region src/utils/duplicate.ts
860
- async function Fe(e, t) {
861
- P(t);
860
+ async function Be(e, t) {
861
+ O(t);
862
862
  let { token: n, private: r, hardware: i, timeout: a, auth: o } = t;
863
- if (i && !Pe.includes(i)) throw Error(`Invalid hardware type provided. Valid types are: ${Pe.map((e) => `"${e}"`).join(",")}.`);
864
- let { http_protocol: s, host: c } = await U(e, n), l = null;
863
+ if (i && !ze.includes(i)) throw Error(`Invalid hardware type provided. Valid types are: ${ze.map((e) => `"${e}"`).join(",")}.`);
864
+ let { http_protocol: s, host: c } = await R(e, n), l = null;
865
865
  if (o) {
866
- let e = await R(s, c, o, fetch, void 0, t.credentials);
867
- e && (l = B(e));
866
+ let e = await P(s, c, o, fetch, void 0, t.credentials);
867
+ e && (l = I(e));
868
868
  }
869
869
  let u = {
870
870
  Authorization: `Bearer ${n}`,
@@ -874,9 +874,9 @@ async function Fe(e, t) {
874
874
  r && (p.private = !0);
875
875
  let m;
876
876
  try {
877
- i || (m = await Me(e, n));
877
+ i || (m = await Le(e, n));
878
878
  } catch (e) {
879
- throw Error(w + e.message);
879
+ throw Error(S + e.message);
880
880
  }
881
881
  p.hardware = i || m || "cpu-basic";
882
882
  try {
@@ -892,35 +892,35 @@ async function Fe(e, t) {
892
892
  }
893
893
  else if (r.status !== 200) throw Error(r.statusText);
894
894
  let i = await r.json();
895
- return await Ne(`${d}/${f}`, a || 300, n), await $.connect(Ie(i.url), t);
895
+ return await Re(`${d}/${f}`, a || 300, n), await $.connect(Ve(i.url), t);
896
896
  } catch (e) {
897
897
  throw Error(e);
898
898
  }
899
899
  }
900
- function Ie(e) {
900
+ function Ve(e) {
901
901
  let t = e.match(/https:\/\/huggingface.co\/spaces\/([^/]+\/[^/]+)/);
902
902
  if (t) return t[1];
903
903
  }
904
904
  //#endregion
905
905
  //#region src/helpers/zerogpu.ts
906
- var Le = "supports-zerogpu-headers", Re = !1;
907
- function ze() {
906
+ var He = "supports-zerogpu-headers", Ue = !1;
907
+ function We() {
908
908
  return typeof window < "u" && typeof document < "u" && typeof window.addEventListener == "function";
909
909
  }
910
- function Be(e) {
910
+ function Ge(e) {
911
911
  return e.includes(".dev.") ? `https://moon-${e.split(".")[1]}.dev.spaces.huggingface.tech` : e.endsWith(".hf.space") ? "https://huggingface.co" : null;
912
912
  }
913
- function Ve() {
914
- if (!ze() || Re) return;
913
+ function Ke() {
914
+ if (!We() || Ue) return;
915
915
  window.addEventListener("message", (e) => {
916
- e.data === Le && (window.supports_zerogpu_headers = !0);
917
- }), Re = !0;
918
- let e = Be(window.location.hostname);
919
- e && window.parent !== window && window.parent.postMessage(Le, e);
916
+ e.data === He && (window.supports_zerogpu_headers = !0);
917
+ }), Ue = !0;
918
+ let e = Ge(window.location.hostname);
919
+ e && window.parent !== window && window.parent.postMessage(He, e);
920
920
  }
921
921
  //#endregion
922
922
  //#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
923
- var He = class extends TransformStream {
923
+ var qe = class extends TransformStream {
924
924
  #e = "";
925
925
  constructor(e = { allowCR: !1 }) {
926
926
  super({
@@ -947,22 +947,22 @@ var He = class extends TransformStream {
947
947
  };
948
948
  //#endregion
949
949
  //#region ../../node_modules/.pnpm/fetch-event-stream@0.1.6/node_modules/fetch-event-stream/esm/utils.js
950
- function Ue(e) {
951
- let t = new TextDecoderStream(), n = new He({ allowCR: !0 });
950
+ function Je(e) {
951
+ let t = new TextDecoderStream(), n = new qe({ allowCR: !0 });
952
952
  return e.pipeThrough(t).pipeThrough(n);
953
953
  }
954
- function We(e) {
954
+ function Ye(e) {
955
955
  let t = /[:]\s*/.exec(e), n = t && t.index;
956
956
  if (n) return [e.substring(0, n), e.substring(n + t[0].length)];
957
957
  }
958
- function Ge(e, t, n) {
958
+ function Xe(e, t, n) {
959
959
  e.get(t) || e.set(t, n);
960
960
  }
961
961
  //#endregion
962
962
  //#region ../../node_modules/.pnpm/fetch-event-stream@0.1.6/node_modules/fetch-event-stream/esm/mod.js
963
- async function* Ke(e, t) {
963
+ async function* Ze(e, t) {
964
964
  if (!e.body) return;
965
- let n = Ue(e.body), r, i = n.getReader(), a;
965
+ let n = Je(e.body), r, i = n.getReader(), a;
966
966
  for (;;) {
967
967
  if (t && t.aborted) return i.cancel();
968
968
  if (r = await i.read(), r.done) return;
@@ -970,20 +970,20 @@ async function* Ke(e, t) {
970
970
  a && (yield a), a = void 0;
971
971
  continue;
972
972
  }
973
- let [e, n] = We(r.value) || [];
973
+ let [e, n] = Ye(r.value) || [];
974
974
  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);
975
975
  }
976
976
  }
977
- async function qe(e, t) {
977
+ async function Qe(e, t) {
978
978
  let n = new Request(e, t);
979
- Ge(n.headers, "Accept", "text/event-stream"), Ge(n.headers, "Content-Type", "application/json");
979
+ Xe(n.headers, "Accept", "text/event-stream"), Xe(n.headers, "Content-Type", "application/json");
980
980
  let r = await fetch(n);
981
981
  if (!r.ok) throw r;
982
- return Ke(r, n.signal);
982
+ return Ze(r, n.signal);
983
983
  }
984
984
  //#endregion
985
985
  //#region src/utils/stream.ts
986
- async function Je() {
986
+ async function $e() {
987
987
  let { event_callbacks: e, unclosed_events: t, pending_stream_messages: n, stream_status: r, config: i, jwt: a } = this, o = this;
988
988
  if (!i) throw Error("Could not resolve app config");
989
989
  r.open = !0;
@@ -995,7 +995,7 @@ async function Je() {
995
995
  s.onmessage = async function(a) {
996
996
  let s = JSON.parse(a.data);
997
997
  if (s.msg === "close_stream") {
998
- Q(r, o.abort_controller);
998
+ et(r, o.abort_controller);
999
999
  return;
1000
1000
  }
1001
1001
  let c = s.event_id;
@@ -1014,27 +1014,27 @@ async function Je() {
1014
1014
  }, s.onerror = async function(t) {
1015
1015
  console.error(t), await Promise.all(Object.keys(e).map((t) => e[t]({
1016
1016
  msg: "broken_connection",
1017
- message: b
1017
+ message: v
1018
1018
  })));
1019
1019
  };
1020
1020
  }
1021
- function Q(e, t) {
1021
+ function et(e, t) {
1022
1022
  e && (e.open = !1, t?.abort());
1023
1023
  }
1024
- function Ye(e, t, n) {
1024
+ function tt(e, t, n) {
1025
1025
  e[t] ? n.data.forEach((r, i) => {
1026
- let a = Xe(i < e[t].length ? e[t][i] : null, r);
1026
+ let a = nt(i < e[t].length ? e[t][i] : null, r);
1027
1027
  e[t][i] = a, n.data[i] = a;
1028
1028
  }) : (e[t] = [], n.data.forEach((n, r) => {
1029
1029
  e[t][r] = n;
1030
1030
  }));
1031
1031
  }
1032
- function Xe(e, t) {
1032
+ function nt(e, t) {
1033
1033
  return t.forEach(([t, n, r]) => {
1034
- e = Ze(e, n, t, r);
1034
+ e = rt(e, n, t, r);
1035
1035
  }), e;
1036
1036
  }
1037
- function Ze(e, t, n, r) {
1037
+ function rt(e, t, n, r) {
1038
1038
  if (t.length === 0) {
1039
1039
  if (n === "replace") return r;
1040
1040
  if (n === "append") return e + r;
@@ -1060,7 +1060,7 @@ function Ze(e, t, n, r) {
1060
1060
  }
1061
1061
  return e;
1062
1062
  }
1063
- function Qe(e, t = {}) {
1063
+ function it(e, t = {}) {
1064
1064
  let n = {
1065
1065
  close: () => {
1066
1066
  console.warn("Method not implemented.");
@@ -1084,7 +1084,7 @@ function Qe(e, t = {}) {
1084
1084
  throw Error("Method not implemented.");
1085
1085
  }
1086
1086
  };
1087
- return qe(e, t).then(async (e) => {
1087
+ return Qe(e, t).then(async (e) => {
1088
1088
  n.readyState = n.OPEN;
1089
1089
  try {
1090
1090
  for await (let t of e) n.onmessage && n.onmessage(t);
@@ -1097,32 +1097,273 @@ function Qe(e, t = {}) {
1097
1097
  }), n;
1098
1098
  }
1099
1099
  //#endregion
1100
+ //#region src/utils/run_history.ts
1101
+ var at = "gradio:run-history:", q = `${at}v2:`, ot = `${at}replay:v2:`, st = 100, ct = 8;
1102
+ function J(e, t) {
1103
+ try {
1104
+ return e();
1105
+ } catch (e) {
1106
+ return console.warn("Could not update the run history.", e), t;
1107
+ }
1108
+ }
1109
+ function lt(e, t = "/gradio_api") {
1110
+ return `${e.replace(/\/+$/, "")}${t}/runs`;
1111
+ }
1112
+ function Y(e) {
1113
+ if (typeof window > "u") return null;
1114
+ let t = e?.app_id;
1115
+ if (t == null || t === "") return null;
1116
+ try {
1117
+ return window.localStorage ? `${q}${t}${e?.username ? `:user:${encodeURIComponent(e.username)}` : ""}` : null;
1118
+ } catch {
1119
+ return null;
1120
+ }
1121
+ }
1122
+ function ut(e) {
1123
+ let t = Y(e);
1124
+ return t ? t.replace(q, ot) : null;
1125
+ }
1126
+ function dt(e) {
1127
+ try {
1128
+ let t = JSON.parse(window.localStorage.getItem(e) || "[]");
1129
+ return Array.isArray(t) && t.length && Date.parse(t[0]?.started_at) || 0;
1130
+ } catch {
1131
+ return 0;
1132
+ }
1133
+ }
1134
+ function ft(e) {
1135
+ let t = Object.keys(window.localStorage).filter((e) => e.startsWith(at)), n = [...t.filter((e) => !e.startsWith(q) && !e.startsWith(ot)), ...t.filter((t) => t.startsWith(q) && t !== e).sort((e, t) => dt(t) - dt(e)).slice(ct - 1)];
1136
+ for (let e of n) try {
1137
+ window.localStorage.removeItem(e), window.sessionStorage.removeItem(e.replace(q, ot));
1138
+ } catch {}
1139
+ }
1140
+ function pt() {
1141
+ return typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(36).slice(2)}`;
1142
+ }
1143
+ function X(e) {
1144
+ let t = /* @__PURE__ */ new WeakSet();
1145
+ try {
1146
+ return JSON.parse(JSON.stringify(e, (e, n) => {
1147
+ if (typeof n == "bigint") return n.toString();
1148
+ if (typeof n == "object" && n) {
1149
+ if (t.has(n)) return "[Circular]";
1150
+ t.add(n);
1151
+ }
1152
+ return n;
1153
+ }));
1154
+ } catch {
1155
+ return "[Unserializable value]";
1156
+ }
1157
+ }
1158
+ function Z(e) {
1159
+ let t = Y(e);
1160
+ if (!t) return [];
1161
+ try {
1162
+ let e = JSON.parse(window.localStorage.getItem(t) || "[]");
1163
+ return Array.isArray(e) ? e : [];
1164
+ } catch {
1165
+ return [];
1166
+ }
1167
+ }
1168
+ function mt(e, t) {
1169
+ let n = Y(e);
1170
+ if (!n) return;
1171
+ let r = t.slice(0, st), i = !1;
1172
+ for (; r.length > 0;) try {
1173
+ window.localStorage.setItem(n, JSON.stringify(r));
1174
+ return;
1175
+ } catch {
1176
+ if (!i) {
1177
+ i = !0, ft(n);
1178
+ continue;
1179
+ }
1180
+ r = r.slice(0, -1);
1181
+ }
1182
+ try {
1183
+ window.localStorage.removeItem(n);
1184
+ } catch {}
1185
+ }
1186
+ function ht(e) {
1187
+ let t = Y(e);
1188
+ if (t) {
1189
+ try {
1190
+ window.localStorage.removeItem(t);
1191
+ } catch {}
1192
+ vt();
1193
+ }
1194
+ }
1195
+ function gt(e, t) {
1196
+ mt(e, Z(e).filter((e) => e.id !== t)), vt();
1197
+ }
1198
+ var _t = "gradio:run-history-change";
1199
+ function vt() {
1200
+ if (!(typeof window > "u")) try {
1201
+ window.dispatchEvent(new Event(_t));
1202
+ } catch {}
1203
+ }
1204
+ function yt(e) {
1205
+ return typeof window > "u" ? () => {} : (window.addEventListener(_t, e), window.addEventListener("storage", e), () => {
1206
+ window.removeEventListener(_t, e), window.removeEventListener("storage", e);
1207
+ });
1208
+ }
1209
+ function bt(e, t) {
1210
+ let n = ut(e);
1211
+ if (n) try {
1212
+ window.sessionStorage.setItem(n, JSON.stringify(t));
1213
+ } catch {}
1214
+ }
1215
+ function xt(e) {
1216
+ let t = ut(e);
1217
+ if (!t) return null;
1218
+ try {
1219
+ let e = window.sessionStorage.getItem(t);
1220
+ return window.sessionStorage.removeItem(t), e ? JSON.parse(e) : null;
1221
+ } catch {
1222
+ return null;
1223
+ }
1224
+ }
1225
+ function St(e, t) {
1226
+ let n = e.dependencies.find((e) => e.id === t.fn_index || typeof e.api_name == "string" && `/${e.api_name.replace(/^\//, "")}` === t.api_name);
1227
+ if (!n) return !1;
1228
+ 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) => {
1229
+ for (let [r, i] of t.entries()) {
1230
+ let t = e.components.find((e) => e.id === i);
1231
+ !t || r >= n.length || t.type !== "state" && (t.props.value = n[r]);
1232
+ }
1233
+ };
1234
+ return a(n.inputs, r), a(n.outputs, i), !0;
1235
+ }
1236
+ function Ct(e) {
1237
+ let t = xt(e);
1238
+ return t ? St(e, t) : !1;
1239
+ }
1240
+ function wt(e) {
1241
+ let t = Y(e);
1242
+ if (!t) return null;
1243
+ ft(t);
1244
+ let n = {
1245
+ id: pt(),
1246
+ endpoint: e.endpoint,
1247
+ api_name: e.api_name,
1248
+ fn_index: e.fn_index,
1249
+ page: `${window.location.pathname}${window.location.search}`,
1250
+ inputs: X(e.inputs),
1251
+ outputs: null,
1252
+ ...e.input_components ? { input_components: X(e.input_components) } : {},
1253
+ ...e.output_components ? { output_components: X(e.output_components) } : {},
1254
+ status: "running",
1255
+ started_at: (/* @__PURE__ */ new Date()).toISOString()
1256
+ };
1257
+ return mt(e, [n, ...Z(e)]), vt(), n.id;
1258
+ }
1259
+ function Tt(e, t, n) {
1260
+ if (!t) return;
1261
+ let r = Z(e), i = r.find((e) => e.id === t);
1262
+ i && (i.inputs = X(n), mt(e, r));
1263
+ }
1264
+ function Et(e, t, n) {
1265
+ if (!t) return;
1266
+ let r = Z(e), i = r.find((e) => e.id === t);
1267
+ if (!i) return;
1268
+ let a = !1;
1269
+ if (n.type === "data") i.outputs = X(n.data), Q.set(t, i.outputs);
1270
+ else if (n.type === "status" && n.original_msg === "process_starts") kt(i, n.time);
1271
+ else if (n.type === "status" && (n.stage === "generating" || n.stage === "streaming")) i.streamed = !0;
1272
+ else if (n.type === "status" && n.stage === "complete") i.status = "completed", At(i, n), a = !0;
1273
+ 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"), At(i, n), a = !0;
1274
+ else return;
1275
+ if (a) Q.has(t) && (i.outputs = Q.get(t)), Q.delete(t), Ot.delete(t);
1276
+ else if (i.streamed) {
1277
+ if (Date.now() - (Ot.get(t) ?? 0) < Dt) return;
1278
+ Ot.set(t, Date.now()), Q.delete(t);
1279
+ }
1280
+ mt(e, r);
1281
+ }
1282
+ var Dt = 500, Ot = /* @__PURE__ */ new Map(), Q = /* @__PURE__ */ new Map();
1283
+ function kt(e, t) {
1284
+ if (e.process_started_at) return;
1285
+ let n = t || /* @__PURE__ */ new Date();
1286
+ e.process_started_at = n.toISOString(), e.queued_ms = Math.max(0, n.getTime() - Date.parse(e.started_at));
1287
+ }
1288
+ function At(e, t) {
1289
+ let n = t.time || /* @__PURE__ */ new Date();
1290
+ 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));
1291
+ }
1292
+ function jt(e) {
1293
+ return J(() => Z(e), []);
1294
+ }
1295
+ function Mt(e) {
1296
+ J(() => ht(e), void 0);
1297
+ }
1298
+ function Nt(e, t) {
1299
+ J(() => gt(e, t), void 0);
1300
+ }
1301
+ function Pt(e, t) {
1302
+ J(() => bt(e, t), void 0);
1303
+ }
1304
+ function Ft(e) {
1305
+ return J(() => xt(e), null);
1306
+ }
1307
+ function It(e) {
1308
+ return J(() => Ct(e), !1);
1309
+ }
1310
+ function Lt(e) {
1311
+ return J(() => wt(e), null);
1312
+ }
1313
+ function Rt(e, t, n) {
1314
+ J(() => Tt(e, t, n), void 0);
1315
+ }
1316
+ function zt(e, t, n) {
1317
+ J(() => Et(e, t, n), void 0);
1318
+ }
1319
+ function Bt(e) {
1320
+ return J(() => yt(() => J(e, void 0)), () => {});
1321
+ }
1322
+ //#endregion
1100
1323
  //#region src/utils/submit.ts
1101
- function $e(e, t = {}, n, r, i, a) {
1324
+ function Vt(e, t = {}, n, r, i, a) {
1102
1325
  try {
1103
- 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;
1104
- if (!p) throw Error(ae);
1326
+ let { token: o } = this.options, { fetch: s, app_reference: c, config: l, session_hash: f, api_info: p, api_map: m, stream_status: ee, pending_stream_messages: h, pending_diff_streams: te, event_callbacks: g, unclosed_events: ne, post_data: _, options: y, api_prefix: b } = this, x = a || { "x-gradio-user": "api" }, S = this;
1327
+ if (!p) throw Error(ce);
1105
1328
  if (!l) throw Error("Could not resolve app config");
1106
- let { fn_index: T, endpoint_info: E, dependency: D } = tt(p, e, m, l), ie = fe(t, E), O, k = l.protocol ?? "ws";
1107
- if (k === "ws") throw Error(oe);
1108
- 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), {}) || {};
1109
- function L(e) {
1110
- (i || se[e.type]) && ue(e);
1329
+ let { fn_index: C, endpoint_info: w, dependency: T } = Ut(p, e, m, l), oe = ye(t, w), E = l.protocol ?? "ws";
1330
+ if (E === "ws") throw Error(le);
1331
+ let se = typeof T.api_name == "string" ? `/${T.api_name}` : e, ue = typeof T.api_name == "string" ? `/${T.api_name}` : `Function ${C}`, D = (e) => {
1332
+ let t = l.components.find((t) => t.id === e);
1333
+ return t ? {
1334
+ type: t.type,
1335
+ component_class_id: t.component_class_id,
1336
+ props: t.props
1337
+ } : null;
1338
+ }, de = T.api_visibility === "public", fe = l.run_history !== !1 && this.options.record_history !== !1, O = {
1339
+ app_id: l.app_id,
1340
+ username: l.username
1341
+ }, k = !fe || !de ? null : Lt({
1342
+ ...O,
1343
+ endpoint: se,
1344
+ api_name: ue,
1345
+ fn_index: C,
1346
+ inputs: G(oe, T, l.components, "input", !0),
1347
+ input_components: T.inputs.map(D),
1348
+ output_components: T.outputs.map(D)
1349
+ }), 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 = y?.events?.reduce((e, t) => (e[t] = !0, e), {}) || {};
1350
+ function R(e) {
1351
+ zt(O, k, e), (i || pe[e.type]) && U(e);
1111
1352
  }
1112
- async function ce() {
1353
+ async function me() {
1113
1354
  let e = {}, t = {};
1114
- e = { event_id: N }, t = {
1115
- event_id: N,
1355
+ e = { event_id: P }, t = {
1356
+ event_id: P,
1116
1357
  session_hash: f,
1117
- fn_index: T
1358
+ fn_index: C
1118
1359
  };
1119
1360
  try {
1120
1361
  if (!l) throw Error("Could not resolve app config");
1121
- "event_id" in t && await s(`${l.root}${S}/${ne}`, {
1362
+ "event_id" in t && await s(`${l.root}${b}/${ie}`, {
1122
1363
  headers: { "Content-Type": "application/json" },
1123
1364
  method: "POST",
1124
1365
  body: JSON.stringify(t)
1125
- }), await s(`${l.root}${S}/${te}`, {
1366
+ }), await s(`${l.root}${b}/${re}`, {
1126
1367
  headers: { "Content-Type": "application/json" },
1127
1368
  method: "POST",
1128
1369
  body: JSON.stringify(e)
@@ -1131,64 +1372,65 @@ function $e(e, t = {}, n, r, i, a) {
1131
1372
  console.warn("The `/reset` endpoint could not be called. Subsequent endpoint results may be unreliable.");
1132
1373
  }
1133
1374
  }
1134
- let R = async (e) => {
1375
+ let he = async (e) => {
1135
1376
  await this._resolve_heartbeat(e);
1136
1377
  };
1137
- async function z(e) {
1378
+ async function ge(e) {
1138
1379
  if (!l) return;
1139
1380
  let t = e.render_id;
1140
1381
  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];
1141
1382
  let n = l.components.some((e) => e.type === "state"), r = l.dependencies.some((e) => e.targets.some((e) => e[1] === "unload"));
1142
- l.connect_heartbeat = n || r, await R(l), L({
1383
+ l.connect_heartbeat = n || r, await he(l), R({
1143
1384
  type: "render",
1144
1385
  data: e,
1145
- endpoint: j,
1146
- fn_index: T
1386
+ endpoint: M,
1387
+ fn_index: C
1147
1388
  });
1148
1389
  }
1149
- let B = this.handle_blob(l.root, ie, E).then(async (e) => {
1150
- if (M = {
1151
- data: X(e, D, l.components, "input", !0) || [],
1390
+ let _e = this.handle_blob(l.root, oe, w).then(async (e) => {
1391
+ let t = G(e, T, l.components, "input", !0);
1392
+ if (Rt(O, k, t || []), N = {
1393
+ data: t || [],
1152
1394
  event_data: n,
1153
- fn_index: T,
1395
+ fn_index: C,
1154
1396
  trigger_id: r,
1155
- ...x.oauth_token && E?.oauth_token ? { oauth_token: x.oauth_token } : {}
1156
- }, be(T, l)) L({
1397
+ ...y.oauth_token && w?.oauth_token ? { oauth_token: y.oauth_token } : {}
1398
+ }, Te(C, l)) R({
1157
1399
  type: "status",
1158
- endpoint: j,
1400
+ endpoint: M,
1159
1401
  stage: "pending",
1160
1402
  queue: !1,
1161
- fn_index: T,
1403
+ fn_index: C,
1162
1404
  time: /* @__PURE__ */ new Date()
1163
- }), y(`${l.root}${S}/run${j.startsWith("/") ? j : `/${j}`}${I ? "?" + I : ""}`, {
1164
- ...M,
1405
+ }), _(`${l.root}${b}/run${M.startsWith("/") ? M : `/${M}`}${L ? "?" + L : ""}`, {
1406
+ ...N,
1165
1407
  session_hash: f
1166
- }, C).then(async ([e, t]) => {
1408
+ }, x).then(async ([e, t]) => {
1167
1409
  let i = e.data;
1168
- if (t == 200) L({
1410
+ if (t == 200) R({
1169
1411
  type: "data",
1170
- endpoint: j,
1171
- fn_index: T,
1172
- data: X(i, D, l.components, "output", x.with_null_state),
1412
+ endpoint: M,
1413
+ fn_index: C,
1414
+ data: G(i, T, l.components, "output", y.with_null_state),
1173
1415
  time: /* @__PURE__ */ new Date(),
1174
1416
  event_data: n,
1175
1417
  trigger_id: r
1176
- }), e.render_config && await z(e.render_config), L({
1418
+ }), e.render_config && await ge(e.render_config), R({
1177
1419
  type: "status",
1178
- endpoint: j,
1179
- fn_index: T,
1420
+ endpoint: M,
1421
+ fn_index: C,
1180
1422
  stage: "complete",
1181
1423
  eta: e.average_duration,
1182
1424
  queue: !1,
1183
1425
  time: /* @__PURE__ */ new Date()
1184
1426
  });
1185
1427
  else {
1186
- let t = e?.error === b;
1187
- L({
1428
+ let t = e?.error === v;
1429
+ R({
1188
1430
  type: "status",
1189
1431
  stage: "error",
1190
- endpoint: j,
1191
- fn_index: T,
1432
+ endpoint: M,
1433
+ fn_index: C,
1192
1434
  message: e.error,
1193
1435
  broken: t,
1194
1436
  queue: !1,
@@ -1196,303 +1438,303 @@ function $e(e, t = {}, n, r, i, a) {
1196
1438
  });
1197
1439
  }
1198
1440
  }).catch((e) => {
1199
- L({
1441
+ R({
1200
1442
  type: "status",
1201
1443
  stage: "error",
1202
1444
  message: e.message,
1203
- endpoint: j,
1204
- fn_index: T,
1445
+ endpoint: M,
1446
+ fn_index: C,
1205
1447
  queue: !1,
1206
1448
  time: /* @__PURE__ */ new Date()
1207
1449
  });
1208
1450
  });
1209
- else if (k == "sse") {
1210
- L({
1451
+ else if (E == "sse") {
1452
+ R({
1211
1453
  type: "status",
1212
1454
  stage: "pending",
1213
1455
  queue: !0,
1214
- endpoint: j,
1215
- fn_index: T,
1456
+ endpoint: M,
1457
+ fn_index: C,
1216
1458
  time: /* @__PURE__ */ new Date()
1217
1459
  });
1218
- var t = new URLSearchParams({
1219
- fn_index: T.toString(),
1460
+ var i = new URLSearchParams({
1461
+ fn_index: C.toString(),
1220
1462
  session_hash: f
1221
1463
  }).toString();
1222
- let e = new URL(`${l.root}${S}/${u}?${I ? I + "&" : ""}${t}`);
1223
- 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()));
1224
- O.onmessage = async function(e) {
1225
- let { type: t, status: i, data: a } = de(JSON.parse(e.data), F[T]);
1226
- if (t === "update" && i && !P) L({
1464
+ let e = new URL(`${l.root}${b}/${u}?${L ? L + "&" : ""}${i}`);
1465
+ 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()));
1466
+ A.onmessage = async function(e) {
1467
+ let { type: t, status: i, data: a } = ve(JSON.parse(e.data), I[C]);
1468
+ if (t === "update" && i && !F) R({
1227
1469
  type: "status",
1228
- endpoint: j,
1229
- fn_index: T,
1470
+ endpoint: M,
1471
+ fn_index: C,
1230
1472
  time: /* @__PURE__ */ new Date(),
1231
1473
  ...i
1232
- }), i.stage === "error" && (O?.close(), W());
1474
+ }), i.stage === "error" && (A?.close(), V());
1233
1475
  else if (t === "data") {
1234
- let [e, t] = await y(`${l.root}${S}/queue/data`, {
1235
- ...M,
1476
+ let [e, t] = await _(`${l.root}${b}/queue/data`, {
1477
+ ...N,
1236
1478
  session_hash: f,
1237
- event_id: N
1479
+ event_id: P
1238
1480
  });
1239
- t !== 200 && (L({
1481
+ t !== 200 && (R({
1240
1482
  type: "status",
1241
1483
  stage: "error",
1242
- message: b,
1484
+ message: v,
1243
1485
  queue: !0,
1244
- endpoint: j,
1245
- fn_index: T,
1486
+ endpoint: M,
1487
+ fn_index: C,
1246
1488
  time: /* @__PURE__ */ new Date()
1247
- }), O?.close(), W());
1248
- } else t === "complete" ? P = i : t === "log" ? L({
1489
+ }), A?.close(), V());
1490
+ } else t === "complete" ? F = i : t === "log" ? R({
1249
1491
  type: "log",
1250
1492
  title: a.title,
1251
1493
  log: a.log,
1252
1494
  level: a.level,
1253
- endpoint: j,
1495
+ endpoint: M,
1254
1496
  duration: a.duration,
1255
1497
  visible: a.visible,
1256
- fn_index: T
1257
- }) : (t === "generating" || t === "streaming") && L({
1498
+ fn_index: C
1499
+ }) : (t === "generating" || t === "streaming") && R({
1258
1500
  type: "status",
1259
1501
  time: /* @__PURE__ */ new Date(),
1260
1502
  ...i,
1261
1503
  stage: i?.stage,
1262
1504
  queue: !0,
1263
- endpoint: j,
1264
- fn_index: T
1505
+ endpoint: M,
1506
+ fn_index: C
1265
1507
  });
1266
- a && (L({
1508
+ a && (R({
1267
1509
  type: "data",
1268
1510
  time: /* @__PURE__ */ new Date(),
1269
- data: X(a.data, D, l.components, "output", x.with_null_state),
1270
- endpoint: j,
1271
- fn_index: T,
1511
+ data: G(a.data, T, l.components, "output", y.with_null_state),
1512
+ endpoint: M,
1513
+ fn_index: C,
1272
1514
  event_data: n,
1273
1515
  trigger_id: r
1274
- }), P && (L({
1516
+ }), F && (R({
1275
1517
  type: "status",
1276
1518
  time: /* @__PURE__ */ new Date(),
1277
- ...P,
1519
+ ...F,
1278
1520
  stage: i?.stage,
1279
1521
  queue: !0,
1280
- endpoint: j,
1281
- fn_index: T
1282
- }), O?.close(), W()));
1522
+ endpoint: M,
1523
+ fn_index: C
1524
+ }), A?.close(), V()));
1283
1525
  };
1284
- } else if (k == "sse_v1" || k == "sse_v2" || k == "sse_v2.1" || k == "sse_v3") {
1285
- L({
1526
+ } else if (E == "sse_v1" || E == "sse_v2" || E == "sse_v2.1" || E == "sse_v3") {
1527
+ R({
1286
1528
  type: "status",
1287
1529
  stage: "pending",
1288
1530
  queue: !0,
1289
- endpoint: j,
1290
- fn_index: T,
1531
+ endpoint: M,
1532
+ fn_index: C,
1291
1533
  time: /* @__PURE__ */ new Date()
1292
1534
  });
1293
1535
  let e = "";
1294
1536
  typeof window < "u" && typeof document < "u" && (e = window?.location?.hostname);
1295
- let t = Be(e);
1296
- return (typeof window < "u" && typeof document < "u" && window.parent != window && t && window.supports_zerogpu_headers ? xe("zerogpu-headers", t) : Promise.resolve(null)).then((e) => {
1537
+ let t = Ge(e);
1538
+ return (typeof window < "u" && typeof document < "u" && window.parent != window && t && window.supports_zerogpu_headers ? Ee("zerogpu-headers", t) : Promise.resolve(null)).then((e) => {
1297
1539
  let t = {
1298
- ...C,
1540
+ ...x,
1299
1541
  ...e || {}
1300
1542
  };
1301
- return y(`${l.root}${S}/${d}?${I}`, {
1302
- ...M,
1543
+ return _(`${l.root}${b}/${d}?${L}`, {
1544
+ ...N,
1303
1545
  session_hash: f
1304
1546
  }, t);
1305
1547
  }).then(async ([e, t]) => {
1306
- if (e.event_id && (A = e.event_id), t === 503) L({
1548
+ if (e.event_id && (j = e.event_id), t === 503) R({
1307
1549
  type: "status",
1308
1550
  stage: "error",
1309
- message: re,
1551
+ message: ae,
1310
1552
  queue: !0,
1311
- endpoint: j,
1312
- fn_index: T,
1553
+ endpoint: M,
1554
+ fn_index: C,
1313
1555
  time: /* @__PURE__ */ new Date(),
1314
1556
  visible: !0
1315
- }), W();
1316
- else if (t === 422) L({
1557
+ }), V();
1558
+ else if (t === 422) R({
1317
1559
  type: "status",
1318
1560
  stage: "error",
1319
1561
  message: e.detail,
1320
1562
  queue: !0,
1321
- endpoint: j,
1322
- fn_index: T,
1563
+ endpoint: M,
1564
+ fn_index: C,
1323
1565
  code: "validation_error",
1324
1566
  time: /* @__PURE__ */ new Date(),
1325
1567
  visible: !0
1326
- }), W();
1568
+ }), V();
1327
1569
  else if (t !== 200) {
1328
- let t = e?.error === b;
1329
- L({
1570
+ let t = e?.error === v;
1571
+ R({
1330
1572
  type: "status",
1331
1573
  stage: "error",
1332
1574
  broken: t,
1333
- message: t ? b : e.detail || e.error,
1575
+ message: t ? v : e.detail || e.error,
1334
1576
  queue: !0,
1335
- endpoint: j,
1336
- fn_index: T,
1577
+ endpoint: M,
1578
+ fn_index: C,
1337
1579
  time: /* @__PURE__ */ new Date(),
1338
1580
  visible: !0
1339
- }), W();
1581
+ }), V();
1340
1582
  } else {
1341
- N = e.event_id, A = N;
1583
+ P = e.event_id, j = P;
1342
1584
  let t = async function(e) {
1343
1585
  try {
1344
- let { type: t, status: n, data: r, original_msg: i } = de(e, F[T]);
1586
+ let { type: t, status: n, data: r, original_msg: i } = ve(e, I[C]);
1345
1587
  if (t == "heartbeat") return;
1346
- if (t === "update" && n && !P) L({
1588
+ if (t === "update" && n && !F) R({
1347
1589
  type: "status",
1348
- endpoint: j,
1349
- fn_index: T,
1590
+ endpoint: M,
1591
+ fn_index: C,
1350
1592
  time: /* @__PURE__ */ new Date(),
1351
1593
  original_msg: i,
1352
1594
  ...n
1353
1595
  });
1354
- else if (t === "complete") P = n;
1596
+ else if (t === "complete") F = n;
1355
1597
  else if (t == "unexpected_error" || t == "broken_connection") {
1356
1598
  console.error("Unexpected error", n?.message);
1357
1599
  let e = t === "broken_connection";
1358
- L({
1600
+ R({
1359
1601
  type: "status",
1360
1602
  stage: "error",
1361
1603
  message: n?.message || "An Unexpected Error Occurred!",
1362
1604
  queue: !0,
1363
- endpoint: j,
1605
+ endpoint: M,
1364
1606
  broken: e,
1365
1607
  session_not_found: n?.session_not_found,
1366
- fn_index: T,
1608
+ fn_index: C,
1367
1609
  time: /* @__PURE__ */ new Date()
1368
1610
  });
1369
1611
  } else if (t === "log") {
1370
- L({
1612
+ R({
1371
1613
  type: "log",
1372
1614
  title: r.title,
1373
1615
  log: r.log,
1374
1616
  level: r.level,
1375
- endpoint: j,
1617
+ endpoint: M,
1376
1618
  duration: r.duration,
1377
1619
  visible: r.visible,
1378
- fn_index: T
1620
+ fn_index: C
1379
1621
  });
1380
1622
  return;
1381
- } else (t === "generating" || t === "streaming") && (L({
1623
+ } else (t === "generating" || t === "streaming") && (R({
1382
1624
  type: "status",
1383
1625
  time: /* @__PURE__ */ new Date(),
1384
1626
  ...n,
1385
1627
  stage: n?.stage,
1386
1628
  queue: !0,
1387
- endpoint: j,
1388
- fn_index: T
1389
- }), r && D.connection !== "stream" && [
1629
+ endpoint: M,
1630
+ fn_index: C
1631
+ }), r && T.connection !== "stream" && [
1390
1632
  "sse_v2",
1391
1633
  "sse_v2.1",
1392
1634
  "sse_v3"
1393
- ].includes(k) && Ye(_, N, r));
1394
- r && (L({
1635
+ ].includes(E) && tt(te, P, r));
1636
+ r && (R({
1395
1637
  type: "data",
1396
1638
  time: /* @__PURE__ */ new Date(),
1397
- data: X(r.data, D, l.components, "output", x.with_null_state),
1398
- endpoint: j,
1399
- fn_index: T
1400
- }), r.render_config && await z(r.render_config), P && (L({
1639
+ data: G(r.data, T, l.components, "output", y.with_null_state),
1640
+ endpoint: M,
1641
+ fn_index: C
1642
+ }), r.render_config && await ge(r.render_config), F && (R({
1401
1643
  type: "status",
1402
1644
  time: /* @__PURE__ */ new Date(),
1403
- ...P,
1645
+ ...F,
1404
1646
  stage: n?.stage,
1405
1647
  queue: !0,
1406
- endpoint: j,
1407
- fn_index: T
1408
- }), W())), (n?.stage === "complete" || n?.stage === "error") && (v[N] && delete v[N], N in _ && delete _[N], W());
1648
+ endpoint: M,
1649
+ fn_index: C
1650
+ }), V())), (n?.stage === "complete" || n?.stage === "error") && (g[P] && delete g[P], P in te && delete te[P], V());
1409
1651
  } catch (e) {
1410
- console.error("Unexpected client exception", e), L({
1652
+ console.error("Unexpected client exception", e), R({
1411
1653
  type: "status",
1412
1654
  stage: "error",
1413
1655
  message: "An Unexpected Error Occurred!",
1414
1656
  queue: !0,
1415
- endpoint: j,
1416
- fn_index: T,
1657
+ endpoint: M,
1658
+ fn_index: C,
1417
1659
  time: /* @__PURE__ */ new Date()
1418
1660
  }), [
1419
1661
  "sse_v2",
1420
1662
  "sse_v2.1",
1421
1663
  "sse_v3"
1422
- ].includes(k) && (Q(h, w.abort_controller), h.open = !1, W());
1664
+ ].includes(E) && (et(ee, S.abort_controller), ee.open = !1, V());
1423
1665
  }
1424
1666
  };
1425
- N in g && (g[N].forEach((e) => t(e)), delete g[N]), v[N] = t, ee.add(N), h.open || await this.open_stream();
1667
+ P in h && (h[P].forEach((e) => t(e)), delete h[P]), g[P] = t, ne.add(P), ee.open || await this.open_stream();
1426
1668
  }
1427
1669
  });
1428
1670
  }
1429
1671
  });
1430
- B.catch((e) => {
1431
- L({
1672
+ _e.catch((e) => {
1673
+ R({
1432
1674
  type: "status",
1433
1675
  stage: "error",
1434
1676
  message: e instanceof Error ? e.message : String(e),
1435
- queue: !be(T, l),
1436
- endpoint: j,
1437
- fn_index: T,
1677
+ queue: !Te(C, l),
1678
+ endpoint: M,
1679
+ fn_index: C,
1438
1680
  time: /* @__PURE__ */ new Date()
1439
- }), W();
1681
+ }), V();
1440
1682
  });
1441
- let V = !1, H = [], U = [];
1442
- function W() {
1443
- for (V = !0; U.length > 0;) U.shift()({
1683
+ let be = !1, z = [], B = [];
1684
+ function V() {
1685
+ for (be = !0; B.length > 0;) B.shift()({
1444
1686
  value: void 0,
1445
1687
  done: !0
1446
1688
  });
1447
1689
  }
1448
- function G(e) {
1449
- U.length > 0 ? U.shift()(e) : H.push(e);
1690
+ function H(e) {
1691
+ B.length > 0 ? B.shift()(e) : z.push(e);
1450
1692
  }
1451
- function le(e) {
1452
- G(et(e)), W();
1693
+ function xe(e) {
1694
+ H(Ht(e)), V();
1453
1695
  }
1454
- function ue(e) {
1455
- G({
1696
+ function U(e) {
1697
+ H({
1456
1698
  value: e,
1457
1699
  done: !1
1458
1700
  });
1459
1701
  }
1460
- function K() {
1461
- return H.length > 0 ? Promise.resolve(H.shift()) : V ? Promise.resolve({
1702
+ function W() {
1703
+ return z.length > 0 ? Promise.resolve(z.shift()) : be ? Promise.resolve({
1462
1704
  value: void 0,
1463
1705
  done: !0
1464
- }) : new Promise((e) => U.push(e));
1706
+ }) : new Promise((e) => B.push(e));
1465
1707
  }
1466
- let q = {
1467
- [Symbol.asyncIterator]: () => q,
1468
- next: K,
1469
- throw: async (e) => (le(e), K()),
1470
- return: async () => (W(), {
1708
+ let Se = {
1709
+ [Symbol.asyncIterator]: () => Se,
1710
+ next: W,
1711
+ throw: async (e) => (xe(e), W()),
1712
+ return: async () => (V(), {
1471
1713
  value: void 0,
1472
1714
  done: !0
1473
1715
  }),
1474
- cancel: ce,
1716
+ cancel: me,
1475
1717
  send_chunk: (e) => {
1476
- this.post_data(`${l.root}${S}/stream/${A}`, {
1718
+ this.post_data(`${l.root}${b}/stream/${j}`, {
1477
1719
  ...e,
1478
1720
  session_hash: this.session_hash
1479
1721
  });
1480
1722
  },
1481
1723
  close_stream: () => {
1482
- this.post_data(`${l.root}${S}/stream/${A}/close`, {}), W();
1724
+ this.post_data(`${l.root}${b}/stream/${j}/close`, {}), V();
1483
1725
  },
1484
- event_id: () => A,
1485
- wait_for_id: async () => (await B, N)
1726
+ event_id: () => j,
1727
+ wait_for_id: async () => (await _e, P)
1486
1728
  };
1487
- return q;
1729
+ return Se;
1488
1730
  } catch (e) {
1489
1731
  throw console.error("Submit function encountered an error:", e), e;
1490
1732
  }
1491
1733
  }
1492
- function et(e) {
1734
+ function Ht(e) {
1493
1735
  return { then: (t, n) => n(e) };
1494
1736
  }
1495
- function tt(e, t, n, r) {
1737
+ function Ut(e, t, n, r) {
1496
1738
  let i, a, o;
1497
1739
  if (typeof t == "number") i = t, a = e.unnamed_endpoints[i], o = r.dependencies.find((e) => e.id == t);
1498
1740
  else {
@@ -1534,13 +1776,13 @@ var $ = class {
1534
1776
  stream_instance = null;
1535
1777
  current_payload;
1536
1778
  get_url_config(e = null) {
1537
- if (!this.config) throw Error(x);
1779
+ if (!this.config) throw Error(y);
1538
1780
  e === null && (e = window.location.href);
1539
1781
  let t = (e) => e.replace(/^\/+|\/+$/g, ""), n = t(new URL(this.config.root).pathname), r = t(new URL(e).pathname), i;
1540
1782
  return i = r.startsWith(n) ? t(r.substring(n.length)) : "", this.get_page_config(i);
1541
1783
  }
1542
1784
  get_page_config(e) {
1543
- if (!this.config) throw Error(x);
1785
+ if (!this.config) throw Error(y);
1544
1786
  let t = this.config;
1545
1787
  return e in t.page || (e = ""), {
1546
1788
  ...t,
@@ -1563,7 +1805,7 @@ var $ = class {
1563
1805
  let t = new Headers();
1564
1806
  return this && this.cookies && t.append("Cookie", this.cookies), this && this.options.headers && new Headers(this.options.headers).forEach((e, n) => {
1565
1807
  t.append(n, e);
1566
- }), this && this.options.token && t.append("Authorization", `Bearer ${this.options.token}`), this.abort_controller = new AbortController(), this.stream_instance = Qe(e.toString(), {
1808
+ }), this && this.options.token && t.append("Authorization", `Bearer ${this.options.token}`), this.abort_controller = new AbortController(), this.stream_instance = it(e.toString(), {
1567
1809
  credentials: this.options.credentials ?? "same-origin",
1568
1810
  headers: t,
1569
1811
  signal: this.abort_controller.signal
@@ -1580,20 +1822,20 @@ var $ = class {
1580
1822
  resolve_config;
1581
1823
  resolve_cookies;
1582
1824
  constructor(e, t = { events: ["data"] }) {
1583
- 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 = Ce.bind(this), this.post_data = De.bind(this), this.submit = $e.bind(this), this.predict = Oe.bind(this), this.open_stream = Je.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);
1825
+ this.app_reference = e, this.deep_link = t.query_params?.deep_link || null, t.events ||= ["data"], O(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 = Oe.bind(this), this.post_data = Me.bind(this), this.submit = Vt.bind(this), this.predict = Ne.bind(this), this.open_stream = $e.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);
1584
1826
  }
1585
1827
  async init() {
1586
- Ve(), this.options.auth && await this.resolve_cookies(), await this._resolve_config().then((e) => e?.config && this._resolve_heartbeat(e.config));
1828
+ Ke(), this.options.auth && await this.resolve_cookies(), await this._resolve_config().then((e) => e?.config && this._resolve_heartbeat(e.config));
1587
1829
  try {
1588
1830
  this.api_info = await this.view_api();
1589
1831
  } catch (e) {
1590
1832
  console.error(e.message);
1591
1833
  }
1592
- this.api_map = F(this.config?.dependencies || []);
1834
+ this.api_map = k(this.config?.dependencies || []);
1593
1835
  }
1594
1836
  async _resolve_heartbeat(e) {
1595
- 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) {
1596
- let e = new URL(`${this.config.root}${this.api_prefix}/${v}/${this.session_hash}`);
1837
+ 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 fe(this.config.space_id, this.options.token, this.cookies))), e.space_id && this.options.token && (this.jwt = await fe(e.space_id, this.options.token)), this.config && this.config.connect_heartbeat) {
1838
+ let e = new URL(`${this.config.root}${this.api_prefix}/${g}/${this.session_hash}`);
1597
1839
  this.jwt && e.searchParams.set("__sign", this.jwt), this.heartbeat_event ||= this.stream(e);
1598
1840
  }
1599
1841
  }
@@ -1602,7 +1844,7 @@ var $ = class {
1602
1844
  return t.session_hash && (n.session_hash = t.session_hash), await n.init(), n;
1603
1845
  }
1604
1846
  async reconnect() {
1605
- let e = new URL(`${this.config.root}${this.api_prefix}/${y}`), t;
1847
+ let e = new URL(`${this.config.root}${this.api_prefix}/${_}`), t;
1606
1848
  try {
1607
1849
  let n = await this.fetch(e);
1608
1850
  if (!n.ok) throw Error();
@@ -1613,17 +1855,17 @@ var $ = class {
1613
1855
  return t === this.config.app_id ? "connected" : "changed";
1614
1856
  }
1615
1857
  close() {
1616
- this.closed = !0, Q(this.stream_status, this.abort_controller);
1858
+ this.closed = !0, et(this.stream_status, this.abort_controller);
1617
1859
  }
1618
1860
  async refresh() {
1619
- if (!this.config) throw Error(x);
1861
+ if (!this.config) throw Error(y);
1620
1862
  let e = await this.resolve_config(this.config.root, !1);
1621
- if (!e) throw Error(x);
1622
- this.config = e, this.api_prefix = e.api_prefix || "", this.api_map = F(e.dependencies || []);
1863
+ if (!e) throw Error(y);
1864
+ this.config = e, this.api_prefix = e.api_prefix || "", this.api_map = k(e.dependencies || []);
1623
1865
  try {
1624
1866
  this.api_info = await this.view_api();
1625
1867
  } catch (e) {
1626
- console.error(C + e.message);
1868
+ console.error(x + e.message);
1627
1869
  }
1628
1870
  return this.get_url_config();
1629
1871
  }
@@ -1631,18 +1873,18 @@ var $ = class {
1631
1873
  this.current_payload = e;
1632
1874
  }
1633
1875
  static async duplicate(e, t = { events: ["data"] }) {
1634
- return Fe(e, t);
1876
+ return Be(e, t);
1635
1877
  }
1636
1878
  async _resolve_config() {
1637
- let { http_protocol: e, host: t, space_id: n } = await U(this.app_reference, this.options.token), { status_callback: r } = this.options;
1638
- n && r && await ke(n, r);
1879
+ let { http_protocol: e, host: t, space_id: n } = await R(this.app_reference, this.options.token), { status_callback: r } = this.options;
1880
+ n && r && await Pe(n, r);
1639
1881
  let i;
1640
1882
  try {
1641
1883
  let n = `${e}//${t}`;
1642
- if (i = await this.resolve_config(n), !i) throw Error(x);
1884
+ if (i = await this.resolve_config(n), !i) throw Error(y);
1643
1885
  return this.config_success(i);
1644
1886
  } catch (e) {
1645
- if (n && r) Z(n, V.test(n) ? "space_name" : "subdomain", this.handle_space_success);
1887
+ if (n && r) K(n, L.test(n) ? "space_name" : "subdomain", this.handle_space_success);
1646
1888
  else throw r && r({
1647
1889
  status: "error",
1648
1890
  message: "Could not load this space.",
@@ -1652,19 +1894,22 @@ var $ = class {
1652
1894
  }
1653
1895
  }
1654
1896
  async config_success(e) {
1655
- if (this.config = e, this.api_prefix = e.api_prefix || "", this.config.auth_required) return this.prepare_return_obj();
1897
+ if (this.config = e, this.api_prefix = e.api_prefix || "", e.run_history === !1 && Mt({
1898
+ app_id: e.app_id,
1899
+ username: e.username
1900
+ }), this.config.auth_required) return this.prepare_return_obj();
1656
1901
  try {
1657
1902
  this.api_info = await this.view_api();
1658
1903
  } catch (e) {
1659
- console.error(C + e.message);
1904
+ console.error(x + e.message);
1660
1905
  }
1661
1906
  return this.prepare_return_obj();
1662
1907
  }
1663
1908
  async handle_space_success(e) {
1664
- if (!this) throw Error(x);
1909
+ if (!this) throw Error(y);
1665
1910
  let { status_callback: t } = this.options;
1666
1911
  if (t && t(e), e.status === "running") try {
1667
- if (this.config = await this._resolve_config(), this.api_prefix = this?.config?.api_prefix || "", !this.config) throw Error(x);
1912
+ if (this.config = await this._resolve_config(), this.api_prefix = this?.config?.api_prefix || "", !this.config) throw Error(y);
1668
1913
  return await this.config_success(this.config);
1669
1914
  } catch (e) {
1670
1915
  throw t && t({
@@ -1676,7 +1921,7 @@ var $ = class {
1676
1921
  }
1677
1922
  }
1678
1923
  async component_server(e, t, n) {
1679
- if (!this.config) throw Error(x);
1924
+ if (!this.config) throw Error(y);
1680
1925
  let r = {}, { token: i } = this.options, { session_hash: a } = this;
1681
1926
  i && (r.Authorization = `Bearer ${this.options.token}`);
1682
1927
  let o, s = this.config.components.find((t) => t.id === e);
@@ -1695,7 +1940,7 @@ var $ = class {
1695
1940
  }), r["Content-Type"] = "application/json";
1696
1941
  i && (r.Authorization = `Bearer ${i}`);
1697
1942
  try {
1698
- let e = await this.fetch(`${o}${this.api_prefix}/${ee}/`, {
1943
+ let e = await this.fetch(`${o}${this.api_prefix}/${ne}/`, {
1699
1944
  method: "POST",
1700
1945
  body: c,
1701
1946
  headers: r,
@@ -1708,7 +1953,7 @@ var $ = class {
1708
1953
  }
1709
1954
  }
1710
1955
  set_cookies(e) {
1711
- this.cookies = B(e).join("; ");
1956
+ this.cookies = I(e).join("; ");
1712
1957
  }
1713
1958
  prepare_return_obj() {
1714
1959
  return {
@@ -1720,11 +1965,11 @@ var $ = class {
1720
1965
  };
1721
1966
  }
1722
1967
  };
1723
- async function nt(e, t = { events: ["data"] }) {
1968
+ async function Wt(e, t = { events: ["data"] }) {
1724
1969
  return await $.connect(e, t);
1725
1970
  }
1726
- async function rt(e, t) {
1971
+ async function Gt(e, t) {
1727
1972
  return await $.duplicate(e, t);
1728
1973
  }
1729
1974
  //#endregion
1730
- export { $ as Client, J as FileData, ie as MISSING_CREDENTIALS_MSG, nt as client, rt as duplicate, Se as handle_file, Oe as predict, ge as prepare_files, $e as submit, o as t, he as upload, q as upload_files };
1975
+ export { $ as Client, U as FileData, oe as MISSING_CREDENTIALS_MSG, It as apply_run_history_replay, Mt as clear_run_history, Wt as client, Ft as consume_run_history_replay, Nt as delete_run_history, Gt as duplicate, De as handle_file, Bt as on_run_history_change, Ne as predict, xe as prepare_files, jt as read_run_history, lt as run_history_url, Pt as stage_run_history_replay, Vt as submit, o as t, H as upload, z as upload_files };