@gradio/client 2.5.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/CHANGELOG.md +6 -0
- package/dist/browser.js +174 -156
- package/dist/index.cjs +32 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -1
- package/dist/index.min.js +55 -37
- package/dist/utils/run_history.d.ts +26 -0
- package/dist/utils/run_history.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/test/run_history.test.ts +67 -0
- package/src/utils/run_history.ts +69 -0
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",
|
|
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
|
|
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,10 +21,10 @@ async function de(e, t, n) {
|
|
|
21
21
|
return !1;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
function
|
|
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
|
|
27
|
+
function k(e) {
|
|
28
28
|
let t = {};
|
|
29
29
|
return e.forEach(({ api_name: e, id: n }) => {
|
|
30
30
|
e && (t[e] = n);
|
|
@@ -56,7 +56,7 @@ async function j(e, t = !0) {
|
|
|
56
56
|
}), !!this.options.auth);
|
|
57
57
|
return r.root ||= e, r;
|
|
58
58
|
}
|
|
59
|
-
throw Error(
|
|
59
|
+
throw Error(y);
|
|
60
60
|
}
|
|
61
61
|
async function M(e, t) {
|
|
62
62
|
if (e?.status === 401 && !t) {
|
|
@@ -64,18 +64,18 @@ async function M(e, t) {
|
|
|
64
64
|
try {
|
|
65
65
|
t = await e.json();
|
|
66
66
|
} catch {
|
|
67
|
-
throw Error(
|
|
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(
|
|
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(
|
|
78
|
-
throw Error(`${
|
|
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
80
|
async function N() {
|
|
81
81
|
let { http_protocol: e, host: t } = await R(this.app_reference, this.options.token);
|
|
@@ -100,7 +100,7 @@ async function P(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(
|
|
103
|
+
throw c.status === 401 ? Error(T) : Error(S);
|
|
104
104
|
}
|
|
105
105
|
function F(e) {
|
|
106
106
|
if (e.startsWith("http")) {
|
|
@@ -133,16 +133,16 @@ async function R(e, t) {
|
|
|
133
133
|
try {
|
|
134
134
|
e = await fetch(`https://huggingface.co/api/spaces/${r}/${l}`, { headers: n });
|
|
135
135
|
} catch {
|
|
136
|
-
throw Error(
|
|
136
|
+
throw Error(S);
|
|
137
137
|
}
|
|
138
|
-
if (e.status === 401 || e.status === 404) throw Error(
|
|
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(
|
|
143
|
+
throw Error(S);
|
|
144
144
|
}
|
|
145
|
-
if (!t) throw Error(
|
|
145
|
+
if (!t) throw Error(S);
|
|
146
146
|
return {
|
|
147
147
|
space_id: r,
|
|
148
148
|
...F(t)
|
|
@@ -166,7 +166,7 @@ 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(
|
|
169
|
+
throw Error(C);
|
|
170
170
|
}
|
|
171
171
|
};
|
|
172
172
|
function he(e, t, n) {
|
|
@@ -235,7 +235,7 @@ function ve(e, t) {
|
|
|
235
235
|
type: "update",
|
|
236
236
|
status: {
|
|
237
237
|
queue: !0,
|
|
238
|
-
message:
|
|
238
|
+
message: ae,
|
|
239
239
|
stage: "error",
|
|
240
240
|
code: e.code,
|
|
241
241
|
success: e.success
|
|
@@ -386,11 +386,11 @@ async function be() {
|
|
|
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 = me(t.root, this.api_prefix,
|
|
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(
|
|
393
|
+
}), !e.ok) throw Error(v);
|
|
394
394
|
r = await e.json();
|
|
395
395
|
}
|
|
396
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);
|
|
@@ -418,7 +418,7 @@ async function z(e, t, n) {
|
|
|
418
418
|
credentials: this.options.credentials ?? "same-origin"
|
|
419
419
|
});
|
|
420
420
|
} catch (e) {
|
|
421
|
-
throw Error(
|
|
421
|
+
throw Error(v + e.message);
|
|
422
422
|
}
|
|
423
423
|
if (!o.ok) {
|
|
424
424
|
let e = await o.text();
|
|
@@ -639,7 +639,7 @@ async function Oe(e, t, n) {
|
|
|
639
639
|
}), t;
|
|
640
640
|
}
|
|
641
641
|
async function ke(e, t) {
|
|
642
|
-
if (!(e.config?.root || e.config?.root_url)) throw Error(
|
|
642
|
+
if (!(e.config?.root || e.config?.root_url)) throw Error(D);
|
|
643
643
|
await Ae(e, t);
|
|
644
644
|
}
|
|
645
645
|
async function Ae(e, t, n = []) {
|
|
@@ -647,20 +647,20 @@ async function Ae(e, t, n = []) {
|
|
|
647
647
|
}
|
|
648
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(
|
|
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(
|
|
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
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(
|
|
663
|
+
console.error(de, e);
|
|
664
664
|
}
|
|
665
665
|
}
|
|
666
666
|
//#endregion
|
|
@@ -679,7 +679,7 @@ async function Me(e, t, n) {
|
|
|
679
679
|
credentials: this.options.credentials ?? "same-origin"
|
|
680
680
|
});
|
|
681
681
|
} catch {
|
|
682
|
-
return [{ error:
|
|
682
|
+
return [{ error: v }, 500];
|
|
683
683
|
}
|
|
684
684
|
let a, o;
|
|
685
685
|
try {
|
|
@@ -723,7 +723,7 @@ async function K(e, t, n) {
|
|
|
723
723
|
n({
|
|
724
724
|
status: "error",
|
|
725
725
|
load_status: "error",
|
|
726
|
-
message:
|
|
726
|
+
message: b,
|
|
727
727
|
detail: "NOT_FOUND"
|
|
728
728
|
});
|
|
729
729
|
return;
|
|
@@ -813,7 +813,7 @@ 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}/${
|
|
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;
|
|
@@ -826,7 +826,7 @@ async function Re(e, t, n) {
|
|
|
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",
|
|
@@ -858,7 +858,7 @@ var ze = [
|
|
|
858
858
|
//#endregion
|
|
859
859
|
//#region src/utils/duplicate.ts
|
|
860
860
|
async function Be(e, t) {
|
|
861
|
-
|
|
861
|
+
O(t);
|
|
862
862
|
let { token: n, private: r, hardware: i, timeout: a, auth: o } = t;
|
|
863
863
|
if (i && !ze.includes(i)) throw Error(`Invalid hardware type provided. Valid types are: ${ze.map((e) => `"${e}"`).join(",")}.`);
|
|
864
864
|
let { http_protocol: s, host: c } = await R(e, n), l = null;
|
|
@@ -876,7 +876,7 @@ async function Be(e, t) {
|
|
|
876
876
|
try {
|
|
877
877
|
i || (m = await Le(e, n));
|
|
878
878
|
} catch (e) {
|
|
879
|
-
throw Error(
|
|
879
|
+
throw Error(S + e.message);
|
|
880
880
|
}
|
|
881
881
|
p.hardware = i || m || "cpu-basic";
|
|
882
882
|
try {
|
|
@@ -1014,7 +1014,7 @@ async function $e() {
|
|
|
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:
|
|
1017
|
+
message: v
|
|
1018
1018
|
})));
|
|
1019
1019
|
};
|
|
1020
1020
|
}
|
|
@@ -1222,7 +1222,22 @@ function xt(e) {
|
|
|
1222
1222
|
return null;
|
|
1223
1223
|
}
|
|
1224
1224
|
}
|
|
1225
|
-
function St(e) {
|
|
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) {
|
|
1226
1241
|
let t = Y(e);
|
|
1227
1242
|
if (!t) return null;
|
|
1228
1243
|
ft(t);
|
|
@@ -1241,111 +1256,114 @@ function St(e) {
|
|
|
1241
1256
|
};
|
|
1242
1257
|
return mt(e, [n, ...Z(e)]), vt(), n.id;
|
|
1243
1258
|
}
|
|
1244
|
-
function
|
|
1259
|
+
function Tt(e, t, n) {
|
|
1245
1260
|
if (!t) return;
|
|
1246
1261
|
let r = Z(e), i = r.find((e) => e.id === t);
|
|
1247
1262
|
i && (i.inputs = X(n), mt(e, r));
|
|
1248
1263
|
}
|
|
1249
|
-
function
|
|
1264
|
+
function Et(e, t, n) {
|
|
1250
1265
|
if (!t) return;
|
|
1251
1266
|
let r = Z(e), i = r.find((e) => e.id === t);
|
|
1252
1267
|
if (!i) return;
|
|
1253
1268
|
let a = !1;
|
|
1254
1269
|
if (n.type === "data") i.outputs = X(n.data), Q.set(t, i.outputs);
|
|
1255
|
-
else if (n.type === "status" && n.original_msg === "process_starts")
|
|
1270
|
+
else if (n.type === "status" && n.original_msg === "process_starts") kt(i, n.time);
|
|
1256
1271
|
else if (n.type === "status" && (n.stage === "generating" || n.stage === "streaming")) i.streamed = !0;
|
|
1257
|
-
else if (n.type === "status" && n.stage === "complete") i.status = "completed",
|
|
1258
|
-
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"),
|
|
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;
|
|
1259
1274
|
else return;
|
|
1260
|
-
if (a) Q.has(t) && (i.outputs = Q.get(t)), Q.delete(t),
|
|
1275
|
+
if (a) Q.has(t) && (i.outputs = Q.get(t)), Q.delete(t), Ot.delete(t);
|
|
1261
1276
|
else if (i.streamed) {
|
|
1262
|
-
if (Date.now() - (
|
|
1263
|
-
|
|
1277
|
+
if (Date.now() - (Ot.get(t) ?? 0) < Dt) return;
|
|
1278
|
+
Ot.set(t, Date.now()), Q.delete(t);
|
|
1264
1279
|
}
|
|
1265
1280
|
mt(e, r);
|
|
1266
1281
|
}
|
|
1267
|
-
var
|
|
1268
|
-
function
|
|
1282
|
+
var Dt = 500, Ot = /* @__PURE__ */ new Map(), Q = /* @__PURE__ */ new Map();
|
|
1283
|
+
function kt(e, t) {
|
|
1269
1284
|
if (e.process_started_at) return;
|
|
1270
1285
|
let n = t || /* @__PURE__ */ new Date();
|
|
1271
1286
|
e.process_started_at = n.toISOString(), e.queued_ms = Math.max(0, n.getTime() - Date.parse(e.started_at));
|
|
1272
1287
|
}
|
|
1273
|
-
function
|
|
1288
|
+
function At(e, t) {
|
|
1274
1289
|
let n = t.time || /* @__PURE__ */ new Date();
|
|
1275
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));
|
|
1276
1291
|
}
|
|
1277
|
-
function
|
|
1292
|
+
function jt(e) {
|
|
1278
1293
|
return J(() => Z(e), []);
|
|
1279
1294
|
}
|
|
1280
|
-
function
|
|
1295
|
+
function Mt(e) {
|
|
1281
1296
|
J(() => ht(e), void 0);
|
|
1282
1297
|
}
|
|
1283
|
-
function
|
|
1298
|
+
function Nt(e, t) {
|
|
1284
1299
|
J(() => gt(e, t), void 0);
|
|
1285
1300
|
}
|
|
1286
|
-
function
|
|
1301
|
+
function Pt(e, t) {
|
|
1287
1302
|
J(() => bt(e, t), void 0);
|
|
1288
1303
|
}
|
|
1289
|
-
function
|
|
1304
|
+
function Ft(e) {
|
|
1290
1305
|
return J(() => xt(e), null);
|
|
1291
1306
|
}
|
|
1292
|
-
function
|
|
1293
|
-
return J(() =>
|
|
1307
|
+
function It(e) {
|
|
1308
|
+
return J(() => Ct(e), !1);
|
|
1309
|
+
}
|
|
1310
|
+
function Lt(e) {
|
|
1311
|
+
return J(() => wt(e), null);
|
|
1294
1312
|
}
|
|
1295
|
-
function
|
|
1296
|
-
J(() =>
|
|
1313
|
+
function Rt(e, t, n) {
|
|
1314
|
+
J(() => Tt(e, t, n), void 0);
|
|
1297
1315
|
}
|
|
1298
|
-
function
|
|
1299
|
-
J(() =>
|
|
1316
|
+
function zt(e, t, n) {
|
|
1317
|
+
J(() => Et(e, t, n), void 0);
|
|
1300
1318
|
}
|
|
1301
|
-
function
|
|
1319
|
+
function Bt(e) {
|
|
1302
1320
|
return J(() => yt(() => J(e, void 0)), () => {});
|
|
1303
1321
|
}
|
|
1304
1322
|
//#endregion
|
|
1305
1323
|
//#region src/utils/submit.ts
|
|
1306
|
-
function
|
|
1324
|
+
function Vt(e, t = {}, n, r, i, a) {
|
|
1307
1325
|
try {
|
|
1308
|
-
let { token: o } = this.options, { fetch: s, app_reference: c, config: l, session_hash: f, api_info: p, api_map: m, stream_status:
|
|
1309
|
-
if (!p) throw Error(
|
|
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);
|
|
1310
1328
|
if (!l) throw Error("Could not resolve app config");
|
|
1311
|
-
let { fn_index:
|
|
1312
|
-
if (
|
|
1313
|
-
let
|
|
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) => {
|
|
1314
1332
|
let t = l.components.find((t) => t.id === e);
|
|
1315
1333
|
return t ? {
|
|
1316
1334
|
type: t.type,
|
|
1317
1335
|
component_class_id: t.component_class_id,
|
|
1318
1336
|
props: t.props
|
|
1319
1337
|
} : null;
|
|
1320
|
-
},
|
|
1338
|
+
}, de = T.api_visibility === "public", fe = l.run_history !== !1 && this.options.record_history !== !1, O = {
|
|
1321
1339
|
app_id: l.app_id,
|
|
1322
1340
|
username: l.username
|
|
1323
|
-
},
|
|
1324
|
-
...
|
|
1325
|
-
endpoint:
|
|
1326
|
-
api_name:
|
|
1327
|
-
fn_index:
|
|
1328
|
-
inputs: G(
|
|
1329
|
-
input_components:
|
|
1330
|
-
output_components:
|
|
1331
|
-
}), 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 =
|
|
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), {}) || {};
|
|
1332
1350
|
function R(e) {
|
|
1333
|
-
|
|
1351
|
+
zt(O, k, e), (i || pe[e.type]) && U(e);
|
|
1334
1352
|
}
|
|
1335
1353
|
async function me() {
|
|
1336
1354
|
let e = {}, t = {};
|
|
1337
1355
|
e = { event_id: P }, t = {
|
|
1338
1356
|
event_id: P,
|
|
1339
1357
|
session_hash: f,
|
|
1340
|
-
fn_index:
|
|
1358
|
+
fn_index: C
|
|
1341
1359
|
};
|
|
1342
1360
|
try {
|
|
1343
1361
|
if (!l) throw Error("Could not resolve app config");
|
|
1344
|
-
"event_id" in t && await s(`${l.root}${
|
|
1362
|
+
"event_id" in t && await s(`${l.root}${b}/${ie}`, {
|
|
1345
1363
|
headers: { "Content-Type": "application/json" },
|
|
1346
1364
|
method: "POST",
|
|
1347
1365
|
body: JSON.stringify(t)
|
|
1348
|
-
}), await s(`${l.root}${
|
|
1366
|
+
}), await s(`${l.root}${b}/${re}`, {
|
|
1349
1367
|
headers: { "Content-Type": "application/json" },
|
|
1350
1368
|
method: "POST",
|
|
1351
1369
|
body: JSON.stringify(e)
|
|
@@ -1366,53 +1384,53 @@ function Rt(e, t = {}, n, r, i, a) {
|
|
|
1366
1384
|
type: "render",
|
|
1367
1385
|
data: e,
|
|
1368
1386
|
endpoint: M,
|
|
1369
|
-
fn_index:
|
|
1387
|
+
fn_index: C
|
|
1370
1388
|
});
|
|
1371
1389
|
}
|
|
1372
|
-
let _e = this.handle_blob(l.root,
|
|
1373
|
-
let t = G(e,
|
|
1374
|
-
if (
|
|
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 = {
|
|
1375
1393
|
data: t || [],
|
|
1376
1394
|
event_data: n,
|
|
1377
|
-
fn_index:
|
|
1395
|
+
fn_index: C,
|
|
1378
1396
|
trigger_id: r,
|
|
1379
|
-
...
|
|
1380
|
-
}, Te(
|
|
1397
|
+
...y.oauth_token && w?.oauth_token ? { oauth_token: y.oauth_token } : {}
|
|
1398
|
+
}, Te(C, l)) R({
|
|
1381
1399
|
type: "status",
|
|
1382
1400
|
endpoint: M,
|
|
1383
1401
|
stage: "pending",
|
|
1384
1402
|
queue: !1,
|
|
1385
|
-
fn_index:
|
|
1403
|
+
fn_index: C,
|
|
1386
1404
|
time: /* @__PURE__ */ new Date()
|
|
1387
|
-
}),
|
|
1405
|
+
}), _(`${l.root}${b}/run${M.startsWith("/") ? M : `/${M}`}${L ? "?" + L : ""}`, {
|
|
1388
1406
|
...N,
|
|
1389
1407
|
session_hash: f
|
|
1390
|
-
},
|
|
1408
|
+
}, x).then(async ([e, t]) => {
|
|
1391
1409
|
let i = e.data;
|
|
1392
1410
|
if (t == 200) R({
|
|
1393
1411
|
type: "data",
|
|
1394
1412
|
endpoint: M,
|
|
1395
|
-
fn_index:
|
|
1396
|
-
data: G(i,
|
|
1413
|
+
fn_index: C,
|
|
1414
|
+
data: G(i, T, l.components, "output", y.with_null_state),
|
|
1397
1415
|
time: /* @__PURE__ */ new Date(),
|
|
1398
1416
|
event_data: n,
|
|
1399
1417
|
trigger_id: r
|
|
1400
1418
|
}), e.render_config && await ge(e.render_config), R({
|
|
1401
1419
|
type: "status",
|
|
1402
1420
|
endpoint: M,
|
|
1403
|
-
fn_index:
|
|
1421
|
+
fn_index: C,
|
|
1404
1422
|
stage: "complete",
|
|
1405
1423
|
eta: e.average_duration,
|
|
1406
1424
|
queue: !1,
|
|
1407
1425
|
time: /* @__PURE__ */ new Date()
|
|
1408
1426
|
});
|
|
1409
1427
|
else {
|
|
1410
|
-
let t = e?.error ===
|
|
1428
|
+
let t = e?.error === v;
|
|
1411
1429
|
R({
|
|
1412
1430
|
type: "status",
|
|
1413
1431
|
stage: "error",
|
|
1414
1432
|
endpoint: M,
|
|
1415
|
-
fn_index:
|
|
1433
|
+
fn_index: C,
|
|
1416
1434
|
message: e.error,
|
|
1417
1435
|
broken: t,
|
|
1418
1436
|
queue: !1,
|
|
@@ -1425,37 +1443,37 @@ function Rt(e, t = {}, n, r, i, a) {
|
|
|
1425
1443
|
stage: "error",
|
|
1426
1444
|
message: e.message,
|
|
1427
1445
|
endpoint: M,
|
|
1428
|
-
fn_index:
|
|
1446
|
+
fn_index: C,
|
|
1429
1447
|
queue: !1,
|
|
1430
1448
|
time: /* @__PURE__ */ new Date()
|
|
1431
1449
|
});
|
|
1432
1450
|
});
|
|
1433
|
-
else if (
|
|
1451
|
+
else if (E == "sse") {
|
|
1434
1452
|
R({
|
|
1435
1453
|
type: "status",
|
|
1436
1454
|
stage: "pending",
|
|
1437
1455
|
queue: !0,
|
|
1438
1456
|
endpoint: M,
|
|
1439
|
-
fn_index:
|
|
1457
|
+
fn_index: C,
|
|
1440
1458
|
time: /* @__PURE__ */ new Date()
|
|
1441
1459
|
});
|
|
1442
1460
|
var i = new URLSearchParams({
|
|
1443
|
-
fn_index:
|
|
1461
|
+
fn_index: C.toString(),
|
|
1444
1462
|
session_hash: f
|
|
1445
1463
|
}).toString();
|
|
1446
|
-
let e = new URL(`${l.root}${
|
|
1464
|
+
let e = new URL(`${l.root}${b}/${u}?${L ? L + "&" : ""}${i}`);
|
|
1447
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()));
|
|
1448
1466
|
A.onmessage = async function(e) {
|
|
1449
|
-
let { type: t, status: i, data: a } = ve(JSON.parse(e.data), I[
|
|
1467
|
+
let { type: t, status: i, data: a } = ve(JSON.parse(e.data), I[C]);
|
|
1450
1468
|
if (t === "update" && i && !F) R({
|
|
1451
1469
|
type: "status",
|
|
1452
1470
|
endpoint: M,
|
|
1453
|
-
fn_index:
|
|
1471
|
+
fn_index: C,
|
|
1454
1472
|
time: /* @__PURE__ */ new Date(),
|
|
1455
1473
|
...i
|
|
1456
1474
|
}), i.stage === "error" && (A?.close(), V());
|
|
1457
1475
|
else if (t === "data") {
|
|
1458
|
-
let [e, t] = await
|
|
1476
|
+
let [e, t] = await _(`${l.root}${b}/queue/data`, {
|
|
1459
1477
|
...N,
|
|
1460
1478
|
session_hash: f,
|
|
1461
1479
|
event_id: P
|
|
@@ -1463,10 +1481,10 @@ function Rt(e, t = {}, n, r, i, a) {
|
|
|
1463
1481
|
t !== 200 && (R({
|
|
1464
1482
|
type: "status",
|
|
1465
1483
|
stage: "error",
|
|
1466
|
-
message:
|
|
1484
|
+
message: v,
|
|
1467
1485
|
queue: !0,
|
|
1468
1486
|
endpoint: M,
|
|
1469
|
-
fn_index:
|
|
1487
|
+
fn_index: C,
|
|
1470
1488
|
time: /* @__PURE__ */ new Date()
|
|
1471
1489
|
}), A?.close(), V());
|
|
1472
1490
|
} else t === "complete" ? F = i : t === "log" ? R({
|
|
@@ -1477,7 +1495,7 @@ function Rt(e, t = {}, n, r, i, a) {
|
|
|
1477
1495
|
endpoint: M,
|
|
1478
1496
|
duration: a.duration,
|
|
1479
1497
|
visible: a.visible,
|
|
1480
|
-
fn_index:
|
|
1498
|
+
fn_index: C
|
|
1481
1499
|
}) : (t === "generating" || t === "streaming") && R({
|
|
1482
1500
|
type: "status",
|
|
1483
1501
|
time: /* @__PURE__ */ new Date(),
|
|
@@ -1485,14 +1503,14 @@ function Rt(e, t = {}, n, r, i, a) {
|
|
|
1485
1503
|
stage: i?.stage,
|
|
1486
1504
|
queue: !0,
|
|
1487
1505
|
endpoint: M,
|
|
1488
|
-
fn_index:
|
|
1506
|
+
fn_index: C
|
|
1489
1507
|
});
|
|
1490
1508
|
a && (R({
|
|
1491
1509
|
type: "data",
|
|
1492
1510
|
time: /* @__PURE__ */ new Date(),
|
|
1493
|
-
data: G(a.data,
|
|
1511
|
+
data: G(a.data, T, l.components, "output", y.with_null_state),
|
|
1494
1512
|
endpoint: M,
|
|
1495
|
-
fn_index:
|
|
1513
|
+
fn_index: C,
|
|
1496
1514
|
event_data: n,
|
|
1497
1515
|
trigger_id: r
|
|
1498
1516
|
}), F && (R({
|
|
@@ -1502,16 +1520,16 @@ function Rt(e, t = {}, n, r, i, a) {
|
|
|
1502
1520
|
stage: i?.stage,
|
|
1503
1521
|
queue: !0,
|
|
1504
1522
|
endpoint: M,
|
|
1505
|
-
fn_index:
|
|
1523
|
+
fn_index: C
|
|
1506
1524
|
}), A?.close(), V()));
|
|
1507
1525
|
};
|
|
1508
|
-
} else if (
|
|
1526
|
+
} else if (E == "sse_v1" || E == "sse_v2" || E == "sse_v2.1" || E == "sse_v3") {
|
|
1509
1527
|
R({
|
|
1510
1528
|
type: "status",
|
|
1511
1529
|
stage: "pending",
|
|
1512
1530
|
queue: !0,
|
|
1513
1531
|
endpoint: M,
|
|
1514
|
-
fn_index:
|
|
1532
|
+
fn_index: C,
|
|
1515
1533
|
time: /* @__PURE__ */ new Date()
|
|
1516
1534
|
});
|
|
1517
1535
|
let e = "";
|
|
@@ -1519,10 +1537,10 @@ function Rt(e, t = {}, n, r, i, a) {
|
|
|
1519
1537
|
let t = Ge(e);
|
|
1520
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) => {
|
|
1521
1539
|
let t = {
|
|
1522
|
-
...
|
|
1540
|
+
...x,
|
|
1523
1541
|
...e || {}
|
|
1524
1542
|
};
|
|
1525
|
-
return
|
|
1543
|
+
return _(`${l.root}${b}/${d}?${L}`, {
|
|
1526
1544
|
...N,
|
|
1527
1545
|
session_hash: f
|
|
1528
1546
|
}, t);
|
|
@@ -1530,10 +1548,10 @@ function Rt(e, t = {}, n, r, i, a) {
|
|
|
1530
1548
|
if (e.event_id && (j = e.event_id), t === 503) R({
|
|
1531
1549
|
type: "status",
|
|
1532
1550
|
stage: "error",
|
|
1533
|
-
message:
|
|
1551
|
+
message: ae,
|
|
1534
1552
|
queue: !0,
|
|
1535
1553
|
endpoint: M,
|
|
1536
|
-
fn_index:
|
|
1554
|
+
fn_index: C,
|
|
1537
1555
|
time: /* @__PURE__ */ new Date(),
|
|
1538
1556
|
visible: !0
|
|
1539
1557
|
}), V();
|
|
@@ -1543,21 +1561,21 @@ function Rt(e, t = {}, n, r, i, a) {
|
|
|
1543
1561
|
message: e.detail,
|
|
1544
1562
|
queue: !0,
|
|
1545
1563
|
endpoint: M,
|
|
1546
|
-
fn_index:
|
|
1564
|
+
fn_index: C,
|
|
1547
1565
|
code: "validation_error",
|
|
1548
1566
|
time: /* @__PURE__ */ new Date(),
|
|
1549
1567
|
visible: !0
|
|
1550
1568
|
}), V();
|
|
1551
1569
|
else if (t !== 200) {
|
|
1552
|
-
let t = e?.error ===
|
|
1570
|
+
let t = e?.error === v;
|
|
1553
1571
|
R({
|
|
1554
1572
|
type: "status",
|
|
1555
1573
|
stage: "error",
|
|
1556
1574
|
broken: t,
|
|
1557
|
-
message: t ?
|
|
1575
|
+
message: t ? v : e.detail || e.error,
|
|
1558
1576
|
queue: !0,
|
|
1559
1577
|
endpoint: M,
|
|
1560
|
-
fn_index:
|
|
1578
|
+
fn_index: C,
|
|
1561
1579
|
time: /* @__PURE__ */ new Date(),
|
|
1562
1580
|
visible: !0
|
|
1563
1581
|
}), V();
|
|
@@ -1565,12 +1583,12 @@ function Rt(e, t = {}, n, r, i, a) {
|
|
|
1565
1583
|
P = e.event_id, j = P;
|
|
1566
1584
|
let t = async function(e) {
|
|
1567
1585
|
try {
|
|
1568
|
-
let { type: t, status: n, data: r, original_msg: i } = ve(e, I[
|
|
1586
|
+
let { type: t, status: n, data: r, original_msg: i } = ve(e, I[C]);
|
|
1569
1587
|
if (t == "heartbeat") return;
|
|
1570
1588
|
if (t === "update" && n && !F) R({
|
|
1571
1589
|
type: "status",
|
|
1572
1590
|
endpoint: M,
|
|
1573
|
-
fn_index:
|
|
1591
|
+
fn_index: C,
|
|
1574
1592
|
time: /* @__PURE__ */ new Date(),
|
|
1575
1593
|
original_msg: i,
|
|
1576
1594
|
...n
|
|
@@ -1587,7 +1605,7 @@ function Rt(e, t = {}, n, r, i, a) {
|
|
|
1587
1605
|
endpoint: M,
|
|
1588
1606
|
broken: e,
|
|
1589
1607
|
session_not_found: n?.session_not_found,
|
|
1590
|
-
fn_index:
|
|
1608
|
+
fn_index: C,
|
|
1591
1609
|
time: /* @__PURE__ */ new Date()
|
|
1592
1610
|
});
|
|
1593
1611
|
} else if (t === "log") {
|
|
@@ -1599,7 +1617,7 @@ function Rt(e, t = {}, n, r, i, a) {
|
|
|
1599
1617
|
endpoint: M,
|
|
1600
1618
|
duration: r.duration,
|
|
1601
1619
|
visible: r.visible,
|
|
1602
|
-
fn_index:
|
|
1620
|
+
fn_index: C
|
|
1603
1621
|
});
|
|
1604
1622
|
return;
|
|
1605
1623
|
} else (t === "generating" || t === "streaming") && (R({
|
|
@@ -1609,18 +1627,18 @@ function Rt(e, t = {}, n, r, i, a) {
|
|
|
1609
1627
|
stage: n?.stage,
|
|
1610
1628
|
queue: !0,
|
|
1611
1629
|
endpoint: M,
|
|
1612
|
-
fn_index:
|
|
1613
|
-
}), r &&
|
|
1630
|
+
fn_index: C
|
|
1631
|
+
}), r && T.connection !== "stream" && [
|
|
1614
1632
|
"sse_v2",
|
|
1615
1633
|
"sse_v2.1",
|
|
1616
1634
|
"sse_v3"
|
|
1617
|
-
].includes(
|
|
1635
|
+
].includes(E) && tt(te, P, r));
|
|
1618
1636
|
r && (R({
|
|
1619
1637
|
type: "data",
|
|
1620
1638
|
time: /* @__PURE__ */ new Date(),
|
|
1621
|
-
data: G(r.data,
|
|
1639
|
+
data: G(r.data, T, l.components, "output", y.with_null_state),
|
|
1622
1640
|
endpoint: M,
|
|
1623
|
-
fn_index:
|
|
1641
|
+
fn_index: C
|
|
1624
1642
|
}), r.render_config && await ge(r.render_config), F && (R({
|
|
1625
1643
|
type: "status",
|
|
1626
1644
|
time: /* @__PURE__ */ new Date(),
|
|
@@ -1628,8 +1646,8 @@ function Rt(e, t = {}, n, r, i, a) {
|
|
|
1628
1646
|
stage: n?.stage,
|
|
1629
1647
|
queue: !0,
|
|
1630
1648
|
endpoint: M,
|
|
1631
|
-
fn_index:
|
|
1632
|
-
}), V())), (n?.stage === "complete" || n?.stage === "error") && (
|
|
1649
|
+
fn_index: C
|
|
1650
|
+
}), V())), (n?.stage === "complete" || n?.stage === "error") && (g[P] && delete g[P], P in te && delete te[P], V());
|
|
1633
1651
|
} catch (e) {
|
|
1634
1652
|
console.error("Unexpected client exception", e), R({
|
|
1635
1653
|
type: "status",
|
|
@@ -1637,16 +1655,16 @@ function Rt(e, t = {}, n, r, i, a) {
|
|
|
1637
1655
|
message: "An Unexpected Error Occurred!",
|
|
1638
1656
|
queue: !0,
|
|
1639
1657
|
endpoint: M,
|
|
1640
|
-
fn_index:
|
|
1658
|
+
fn_index: C,
|
|
1641
1659
|
time: /* @__PURE__ */ new Date()
|
|
1642
1660
|
}), [
|
|
1643
1661
|
"sse_v2",
|
|
1644
1662
|
"sse_v2.1",
|
|
1645
1663
|
"sse_v3"
|
|
1646
|
-
].includes(
|
|
1664
|
+
].includes(E) && (et(ee, S.abort_controller), ee.open = !1, V());
|
|
1647
1665
|
}
|
|
1648
1666
|
};
|
|
1649
|
-
P in
|
|
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();
|
|
1650
1668
|
}
|
|
1651
1669
|
});
|
|
1652
1670
|
}
|
|
@@ -1656,9 +1674,9 @@ function Rt(e, t = {}, n, r, i, a) {
|
|
|
1656
1674
|
type: "status",
|
|
1657
1675
|
stage: "error",
|
|
1658
1676
|
message: e instanceof Error ? e.message : String(e),
|
|
1659
|
-
queue: !Te(
|
|
1677
|
+
queue: !Te(C, l),
|
|
1660
1678
|
endpoint: M,
|
|
1661
|
-
fn_index:
|
|
1679
|
+
fn_index: C,
|
|
1662
1680
|
time: /* @__PURE__ */ new Date()
|
|
1663
1681
|
}), V();
|
|
1664
1682
|
});
|
|
@@ -1673,7 +1691,7 @@ function Rt(e, t = {}, n, r, i, a) {
|
|
|
1673
1691
|
B.length > 0 ? B.shift()(e) : z.push(e);
|
|
1674
1692
|
}
|
|
1675
1693
|
function xe(e) {
|
|
1676
|
-
H(
|
|
1694
|
+
H(Ht(e)), V();
|
|
1677
1695
|
}
|
|
1678
1696
|
function U(e) {
|
|
1679
1697
|
H({
|
|
@@ -1697,13 +1715,13 @@ function Rt(e, t = {}, n, r, i, a) {
|
|
|
1697
1715
|
}),
|
|
1698
1716
|
cancel: me,
|
|
1699
1717
|
send_chunk: (e) => {
|
|
1700
|
-
this.post_data(`${l.root}${
|
|
1718
|
+
this.post_data(`${l.root}${b}/stream/${j}`, {
|
|
1701
1719
|
...e,
|
|
1702
1720
|
session_hash: this.session_hash
|
|
1703
1721
|
});
|
|
1704
1722
|
},
|
|
1705
1723
|
close_stream: () => {
|
|
1706
|
-
this.post_data(`${l.root}${
|
|
1724
|
+
this.post_data(`${l.root}${b}/stream/${j}/close`, {}), V();
|
|
1707
1725
|
},
|
|
1708
1726
|
event_id: () => j,
|
|
1709
1727
|
wait_for_id: async () => (await _e, P)
|
|
@@ -1713,10 +1731,10 @@ function Rt(e, t = {}, n, r, i, a) {
|
|
|
1713
1731
|
throw console.error("Submit function encountered an error:", e), e;
|
|
1714
1732
|
}
|
|
1715
1733
|
}
|
|
1716
|
-
function
|
|
1734
|
+
function Ht(e) {
|
|
1717
1735
|
return { then: (t, n) => n(e) };
|
|
1718
1736
|
}
|
|
1719
|
-
function
|
|
1737
|
+
function Ut(e, t, n, r) {
|
|
1720
1738
|
let i, a, o;
|
|
1721
1739
|
if (typeof t == "number") i = t, a = e.unnamed_endpoints[i], o = r.dependencies.find((e) => e.id == t);
|
|
1722
1740
|
else {
|
|
@@ -1758,13 +1776,13 @@ var $ = class {
|
|
|
1758
1776
|
stream_instance = null;
|
|
1759
1777
|
current_payload;
|
|
1760
1778
|
get_url_config(e = null) {
|
|
1761
|
-
if (!this.config) throw Error(
|
|
1779
|
+
if (!this.config) throw Error(y);
|
|
1762
1780
|
e === null && (e = window.location.href);
|
|
1763
1781
|
let t = (e) => e.replace(/^\/+|\/+$/g, ""), n = t(new URL(this.config.root).pathname), r = t(new URL(e).pathname), i;
|
|
1764
1782
|
return i = r.startsWith(n) ? t(r.substring(n.length)) : "", this.get_page_config(i);
|
|
1765
1783
|
}
|
|
1766
1784
|
get_page_config(e) {
|
|
1767
|
-
if (!this.config) throw Error(
|
|
1785
|
+
if (!this.config) throw Error(y);
|
|
1768
1786
|
let t = this.config;
|
|
1769
1787
|
return e in t.page || (e = ""), {
|
|
1770
1788
|
...t,
|
|
@@ -1804,7 +1822,7 @@ var $ = class {
|
|
|
1804
1822
|
resolve_config;
|
|
1805
1823
|
resolve_cookies;
|
|
1806
1824
|
constructor(e, t = { events: ["data"] }) {
|
|
1807
|
-
this.app_reference = e, this.deep_link = t.query_params?.deep_link || null, t.events ||= ["data"],
|
|
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);
|
|
1808
1826
|
}
|
|
1809
1827
|
async init() {
|
|
1810
1828
|
Ke(), this.options.auth && await this.resolve_cookies(), await this._resolve_config().then((e) => e?.config && this._resolve_heartbeat(e.config));
|
|
@@ -1813,11 +1831,11 @@ var $ = class {
|
|
|
1813
1831
|
} catch (e) {
|
|
1814
1832
|
console.error(e.message);
|
|
1815
1833
|
}
|
|
1816
|
-
this.api_map =
|
|
1834
|
+
this.api_map = k(this.config?.dependencies || []);
|
|
1817
1835
|
}
|
|
1818
1836
|
async _resolve_heartbeat(e) {
|
|
1819
|
-
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
|
|
1820
|
-
let e = new URL(`${this.config.root}${this.api_prefix}/${
|
|
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}`);
|
|
1821
1839
|
this.jwt && e.searchParams.set("__sign", this.jwt), this.heartbeat_event ||= this.stream(e);
|
|
1822
1840
|
}
|
|
1823
1841
|
}
|
|
@@ -1826,7 +1844,7 @@ var $ = class {
|
|
|
1826
1844
|
return t.session_hash && (n.session_hash = t.session_hash), await n.init(), n;
|
|
1827
1845
|
}
|
|
1828
1846
|
async reconnect() {
|
|
1829
|
-
let e = new URL(`${this.config.root}${this.api_prefix}/${
|
|
1847
|
+
let e = new URL(`${this.config.root}${this.api_prefix}/${_}`), t;
|
|
1830
1848
|
try {
|
|
1831
1849
|
let n = await this.fetch(e);
|
|
1832
1850
|
if (!n.ok) throw Error();
|
|
@@ -1840,14 +1858,14 @@ var $ = class {
|
|
|
1840
1858
|
this.closed = !0, et(this.stream_status, this.abort_controller);
|
|
1841
1859
|
}
|
|
1842
1860
|
async refresh() {
|
|
1843
|
-
if (!this.config) throw Error(
|
|
1861
|
+
if (!this.config) throw Error(y);
|
|
1844
1862
|
let e = await this.resolve_config(this.config.root, !1);
|
|
1845
|
-
if (!e) throw Error(
|
|
1846
|
-
this.config = e, this.api_prefix = e.api_prefix || "", this.api_map =
|
|
1863
|
+
if (!e) throw Error(y);
|
|
1864
|
+
this.config = e, this.api_prefix = e.api_prefix || "", this.api_map = k(e.dependencies || []);
|
|
1847
1865
|
try {
|
|
1848
1866
|
this.api_info = await this.view_api();
|
|
1849
1867
|
} catch (e) {
|
|
1850
|
-
console.error(
|
|
1868
|
+
console.error(x + e.message);
|
|
1851
1869
|
}
|
|
1852
1870
|
return this.get_url_config();
|
|
1853
1871
|
}
|
|
@@ -1863,7 +1881,7 @@ var $ = class {
|
|
|
1863
1881
|
let i;
|
|
1864
1882
|
try {
|
|
1865
1883
|
let n = `${e}//${t}`;
|
|
1866
|
-
if (i = await this.resolve_config(n), !i) throw Error(
|
|
1884
|
+
if (i = await this.resolve_config(n), !i) throw Error(y);
|
|
1867
1885
|
return this.config_success(i);
|
|
1868
1886
|
} catch (e) {
|
|
1869
1887
|
if (n && r) K(n, L.test(n) ? "space_name" : "subdomain", this.handle_space_success);
|
|
@@ -1876,22 +1894,22 @@ var $ = class {
|
|
|
1876
1894
|
}
|
|
1877
1895
|
}
|
|
1878
1896
|
async config_success(e) {
|
|
1879
|
-
if (this.config = e, this.api_prefix = e.api_prefix || "", e.run_history === !1 &&
|
|
1897
|
+
if (this.config = e, this.api_prefix = e.api_prefix || "", e.run_history === !1 && Mt({
|
|
1880
1898
|
app_id: e.app_id,
|
|
1881
1899
|
username: e.username
|
|
1882
1900
|
}), this.config.auth_required) return this.prepare_return_obj();
|
|
1883
1901
|
try {
|
|
1884
1902
|
this.api_info = await this.view_api();
|
|
1885
1903
|
} catch (e) {
|
|
1886
|
-
console.error(
|
|
1904
|
+
console.error(x + e.message);
|
|
1887
1905
|
}
|
|
1888
1906
|
return this.prepare_return_obj();
|
|
1889
1907
|
}
|
|
1890
1908
|
async handle_space_success(e) {
|
|
1891
|
-
if (!this) throw Error(
|
|
1909
|
+
if (!this) throw Error(y);
|
|
1892
1910
|
let { status_callback: t } = this.options;
|
|
1893
1911
|
if (t && t(e), e.status === "running") try {
|
|
1894
|
-
if (this.config = await this._resolve_config(), this.api_prefix = this?.config?.api_prefix || "", !this.config) throw Error(
|
|
1912
|
+
if (this.config = await this._resolve_config(), this.api_prefix = this?.config?.api_prefix || "", !this.config) throw Error(y);
|
|
1895
1913
|
return await this.config_success(this.config);
|
|
1896
1914
|
} catch (e) {
|
|
1897
1915
|
throw t && t({
|
|
@@ -1903,7 +1921,7 @@ var $ = class {
|
|
|
1903
1921
|
}
|
|
1904
1922
|
}
|
|
1905
1923
|
async component_server(e, t, n) {
|
|
1906
|
-
if (!this.config) throw Error(
|
|
1924
|
+
if (!this.config) throw Error(y);
|
|
1907
1925
|
let r = {}, { token: i } = this.options, { session_hash: a } = this;
|
|
1908
1926
|
i && (r.Authorization = `Bearer ${this.options.token}`);
|
|
1909
1927
|
let o, s = this.config.components.find((t) => t.id === e);
|
|
@@ -1922,7 +1940,7 @@ var $ = class {
|
|
|
1922
1940
|
}), r["Content-Type"] = "application/json";
|
|
1923
1941
|
i && (r.Authorization = `Bearer ${i}`);
|
|
1924
1942
|
try {
|
|
1925
|
-
let e = await this.fetch(`${o}${this.api_prefix}/${
|
|
1943
|
+
let e = await this.fetch(`${o}${this.api_prefix}/${ne}/`, {
|
|
1926
1944
|
method: "POST",
|
|
1927
1945
|
body: c,
|
|
1928
1946
|
headers: r,
|
|
@@ -1947,11 +1965,11 @@ var $ = class {
|
|
|
1947
1965
|
};
|
|
1948
1966
|
}
|
|
1949
1967
|
};
|
|
1950
|
-
async function
|
|
1968
|
+
async function Wt(e, t = { events: ["data"] }) {
|
|
1951
1969
|
return await $.connect(e, t);
|
|
1952
1970
|
}
|
|
1953
|
-
async function
|
|
1971
|
+
async function Gt(e, t) {
|
|
1954
1972
|
return await $.duplicate(e, t);
|
|
1955
1973
|
}
|
|
1956
1974
|
//#endregion
|
|
1957
|
-
export { $ as Client, U as FileData,
|
|
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 };
|