UNPKG

mongodb-chatbot-ui

Version:

UI React components for the MongoDB Chatbot Framework

1,521 lines (1,513 loc) 62.3 kB
import { p as ce, j as ye } from "./jsx-runtime.js"; import { u as Oe, c as Ke, a as et, d as tt, j as rt } from "./index2.js"; import { m as nt, U as ot } from "./messageLinks.js"; import { useMemo as at, useState as Re, useRef as it, startTransition as st } from "react"; import { r as Je, a as ct, p as ut, b as ft } from "./index3.js"; import { c as Ue, S as lt, a as pt, C as dt } from "./ConversationStateProvider2.js"; import { c as ht, a as gt } from "./utils.js"; import { useConversationStateContext as yt } from "./useConversationStateContext.js"; import { L as mt } from "./LinkDataProvider.js"; import { C as vt } from "./ChatbotProvider.js"; import { H as bt } from "./HotkeyContext.js"; async function wt(u, o) { const y = u.getReader(); let d; for (; !(d = await y.read()).done; ) o(d.value); } function Et(u) { let o, y, d, v = !1; return function(N) { o === void 0 ? (o = N, y = 0, d = -1) : o = Ot(o, N); const F = o.length; let $ = 0; for (; y < F; ) { v && (o[y] === 10 && ($ = ++y), v = !1); let B = -1; for (; y < F && B === -1; ++y) switch (o[y]) { case 58: d === -1 && (d = y - $); break; case 13: v = !0; case 10: B = y; break; } if (B === -1) break; u(o.subarray($, B), d), $ = y, d = -1; } $ === F ? o = void 0 : $ !== 0 && (o = o.subarray($), y -= $); }; } function St(u, o, y) { let d = Fe(); const v = new TextDecoder(); return function(N, F) { if (N.length === 0) y == null || y(d), d = Fe(); else if (F > 0) { const $ = v.decode(N.subarray(0, F)), B = F + (N[F + 1] === 32 ? 2 : 1), W = v.decode(N.subarray(B)); switch ($) { case "data": d.data = d.data ? d.data + ` ` + W : W; break; case "event": d.event = W; break; case "id": u(d.id = W); break; case "retry": const R = parseInt(W, 10); isNaN(R) || o(d.retry = R); break; } } }; } function Ot(u, o) { const y = new Uint8Array(u.length + o.length); return y.set(u), y.set(o, u.length), y; } function Fe() { return { data: "", event: "", id: "", retry: void 0 }; } var jt = globalThis && globalThis.__rest || function(u, o) { var y = {}; for (var d in u) Object.prototype.hasOwnProperty.call(u, d) && o.indexOf(d) < 0 && (y[d] = u[d]); if (u != null && typeof Object.getOwnPropertySymbols == "function") for (var v = 0, d = Object.getOwnPropertySymbols(u); v < d.length; v++) o.indexOf(d[v]) < 0 && Object.prototype.propertyIsEnumerable.call(u, d[v]) && (y[d[v]] = u[d[v]]); return y; }; const De = "text/event-stream", Rt = 1e3, Le = "last-event-id"; function It(u, o) { var { signal: y, headers: d, onopen: v, onmessage: P, onclose: N, onerror: F, openWhenHidden: $, fetch: B } = o, W = jt(o, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]); return new Promise((R, m) => { const I = Object.assign({}, d); I.accept || (I.accept = De); let U; function Y() { U.abort(), document.hidden || c(); } $ || document.addEventListener("visibilitychange", Y); let z = Rt, x = 0; function L() { document.removeEventListener("visibilitychange", Y), window.clearTimeout(x), U.abort(); } y == null || y.addEventListener("abort", () => { L(), R(); }); const te = B ?? window.fetch, Q = v ?? At; async function c() { var s; U = new AbortController(); try { const h = await te(u, Object.assign(Object.assign({}, W), { headers: I, signal: U.signal })); await Q(h), await wt(h.body, Et(St((l) => { l ? I[Le] = l : delete I[Le]; }, (l) => { z = l; }, P))), N == null || N(), L(), R(); } catch (h) { if (!U.signal.aborted) try { const l = (s = F == null ? void 0 : F(h)) !== null && s !== void 0 ? s : z; window.clearTimeout(x), x = window.setTimeout(c, l); } catch (l) { L(), m(l); } } } c(); }); } function At(u) { const o = u.headers.get("content-type"); if (!(o != null && o.startsWith(De))) throw new Error(`Expected content-type to be ${De}, Actual: ${o}`); } var Ie = { exports: {} }, Ae = {}, $e; function Xe() { if ($e) return Ae; $e = 1; function u(c) { "@babel/helpers - typeof"; return u = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(s) { return typeof s; } : function(s) { return s && typeof Symbol == "function" && s.constructor === Symbol && s !== Symbol.prototype ? "symbol" : typeof s; }, u(c); } function o(c, s) { for (var h = 0; h < s.length; h++) { var l = s[h]; l.enumerable = l.enumerable || !1, l.configurable = !0, "value" in l && (l.writable = !0), Object.defineProperty(c, d(l.key), l); } } function y(c, s, h) { return s && o(c.prototype, s), h && o(c, h), Object.defineProperty(c, "prototype", { writable: !1 }), c; } function d(c) { var s = v(c, "string"); return u(s) === "symbol" ? s : String(s); } function v(c, s) { if (u(c) !== "object" || c === null) return c; var h = c[Symbol.toPrimitive]; if (h !== void 0) { var l = h.call(c, s || "default"); if (u(l) !== "object") return l; throw new TypeError("@@toPrimitive must return a primitive value."); } return (s === "string" ? String : Number)(c); } function P(c, s) { if (!(c instanceof s)) throw new TypeError("Cannot call a class as a function"); } function N(c, s) { if (typeof s != "function" && s !== null) throw new TypeError("Super expression must either be null or a function"); c.prototype = Object.create(s && s.prototype, { constructor: { value: c, writable: !0, configurable: !0 } }), Object.defineProperty(c, "prototype", { writable: !1 }), s && F(c, s); } function F(c, s) { return F = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(l, _) { return l.__proto__ = _, l; }, F(c, s); } function $(c) { var s = R(); return function() { var l = m(c), _; if (s) { var A = m(this).constructor; _ = Reflect.construct(l, arguments, A); } else _ = l.apply(this, arguments); return B(this, _); }; } function B(c, s) { if (s && (u(s) === "object" || typeof s == "function")) return s; if (s !== void 0) throw new TypeError("Derived constructors may only return object or undefined"); return W(c); } function W(c) { if (c === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return c; } function R() { if (typeof Reflect > "u" || !Reflect.construct || Reflect.construct.sham) return !1; if (typeof Proxy == "function") return !0; try { return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { })), !0; } catch { return !1; } } function m(c) { return m = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function(h) { return h.__proto__ || Object.getPrototypeOf(h); }, m(c); } var I = {}, U, Y; function z(c, s, h) { h || (h = Error); function l(A, Z, M) { return typeof s == "string" ? s : s(A, Z, M); } var _ = /* @__PURE__ */ function(A) { N(M, A); var Z = $(M); function M(re, pe, se) { var oe; return P(this, M), oe = Z.call(this, l(re, pe, se)), oe.code = c, oe; } return y(M); }(h); I[c] = _; } function x(c, s) { if (Array.isArray(c)) { var h = c.length; return c = c.map(function(l) { return String(l); }), h > 2 ? "one of ".concat(s, " ").concat(c.slice(0, h - 1).join(", "), ", or ") + c[h - 1] : h === 2 ? "one of ".concat(s, " ").concat(c[0], " or ").concat(c[1]) : "of ".concat(s, " ").concat(c[0]); } else return "of ".concat(s, " ").concat(String(c)); } function L(c, s, h) { return c.substr(!h || h < 0 ? 0 : +h, s.length) === s; } function te(c, s, h) { return (h === void 0 || h > c.length) && (h = c.length), c.substring(h - s.length, h) === s; } function Q(c, s, h) { return typeof h != "number" && (h = 0), h + s.length > c.length ? !1 : c.indexOf(s, h) !== -1; } return z("ERR_AMBIGUOUS_ARGUMENT", 'The "%s" argument is ambiguous. %s', TypeError), z("ERR_INVALID_ARG_TYPE", function(c, s, h) { U === void 0 && (U = Ce()), U(typeof c == "string", "'name' must be a string"); var l; typeof s == "string" && L(s, "not ") ? (l = "must not be", s = s.replace(/^not /, "")) : l = "must be"; var _; if (te(c, " argument")) _ = "The ".concat(c, " ").concat(l, " ").concat(x(s, "type")); else { var A = Q(c, ".") ? "property" : "argument"; _ = 'The "'.concat(c, '" ').concat(A, " ").concat(l, " ").concat(x(s, "type")); } return _ += ". Received type ".concat(u(h)), _; }, TypeError), z("ERR_INVALID_ARG_VALUE", function(c, s) { var h = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "is invalid"; Y === void 0 && (Y = Oe); var l = Y.inspect(s); return l.length > 128 && (l = "".concat(l.slice(0, 128), "...")), "The argument '".concat(c, "' ").concat(h, ". Received ").concat(l); }, TypeError), z("ERR_INVALID_RETURN_VALUE", function(c, s, h) { var l; return h && h.constructor && h.constructor.name ? l = "instance of ".concat(h.constructor.name) : l = "type ".concat(u(h)), "Expected ".concat(c, ' to be returned from the "').concat(s, '"') + " function but got ".concat(l, "."); }, TypeError), z("ERR_MISSING_ARGS", function() { for (var c = arguments.length, s = new Array(c), h = 0; h < c; h++) s[h] = arguments[h]; U === void 0 && (U = Ce()), U(s.length > 0, "At least one arg needs to be specified"); var l = "The ", _ = s.length; switch (s = s.map(function(A) { return '"'.concat(A, '"'); }), _) { case 1: l += "".concat(s[0], " argument"); break; case 2: l += "".concat(s[0], " and ").concat(s[1], " arguments"); break; default: l += s.slice(0, _ - 1).join(", "), l += ", and ".concat(s[_ - 1], " arguments"); break; } return "".concat(l, " must be specified"); }, TypeError), Ae.codes = I, Ae; } var qe, Be; function qt() { if (Be) return qe; Be = 1; function u(f, p) { var E = Object.keys(f); if (Object.getOwnPropertySymbols) { var b = Object.getOwnPropertySymbols(f); p && (b = b.filter(function(q) { return Object.getOwnPropertyDescriptor(f, q).enumerable; })), E.push.apply(E, b); } return E; } function o(f) { for (var p = 1; p < arguments.length; p++) { var E = arguments[p] != null ? arguments[p] : {}; p % 2 ? u(Object(E), !0).forEach(function(b) { y(f, b, E[b]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(f, Object.getOwnPropertyDescriptors(E)) : u(Object(E)).forEach(function(b) { Object.defineProperty(f, b, Object.getOwnPropertyDescriptor(E, b)); }); } return f; } function y(f, p, E) { return p = N(p), p in f ? Object.defineProperty(f, p, { value: E, enumerable: !0, configurable: !0, writable: !0 }) : f[p] = E, f; } function d(f, p) { if (!(f instanceof p)) throw new TypeError("Cannot call a class as a function"); } function v(f, p) { for (var E = 0; E < p.length; E++) { var b = p[E]; b.enumerable = b.enumerable || !1, b.configurable = !0, "value" in b && (b.writable = !0), Object.defineProperty(f, N(b.key), b); } } function P(f, p, E) { return p && v(f.prototype, p), E && v(f, E), Object.defineProperty(f, "prototype", { writable: !1 }), f; } function N(f) { var p = F(f, "string"); return L(p) === "symbol" ? p : String(p); } function F(f, p) { if (L(f) !== "object" || f === null) return f; var E = f[Symbol.toPrimitive]; if (E !== void 0) { var b = E.call(f, p || "default"); if (L(b) !== "object") return b; throw new TypeError("@@toPrimitive must return a primitive value."); } return (p === "string" ? String : Number)(f); } function $(f, p) { if (typeof p != "function" && p !== null) throw new TypeError("Super expression must either be null or a function"); f.prototype = Object.create(p && p.prototype, { constructor: { value: f, writable: !0, configurable: !0 } }), Object.defineProperty(f, "prototype", { writable: !1 }), p && z(f, p); } function B(f) { var p = U(); return function() { var b = x(f), q; if (p) { var V = x(this).constructor; q = Reflect.construct(b, arguments, V); } else q = b.apply(this, arguments); return W(this, q); }; } function W(f, p) { if (p && (L(p) === "object" || typeof p == "function")) return p; if (p !== void 0) throw new TypeError("Derived constructors may only return object or undefined"); return R(f); } function R(f) { if (f === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return f; } function m(f) { var p = typeof Map == "function" ? /* @__PURE__ */ new Map() : void 0; return m = function(b) { if (b === null || !Y(b)) return b; if (typeof b != "function") throw new TypeError("Super expression must either be null or a function"); if (typeof p < "u") { if (p.has(b)) return p.get(b); p.set(b, q); } function q() { return I(b, arguments, x(this).constructor); } return q.prototype = Object.create(b.prototype, { constructor: { value: q, enumerable: !1, writable: !0, configurable: !0 } }), z(q, b); }, m(f); } function I(f, p, E) { return U() ? I = Reflect.construct.bind() : I = function(q, V, X) { var H = [null]; H.push.apply(H, V); var a = Function.bind.apply(q, H), e = new a(); return X && z(e, X.prototype), e; }, I.apply(null, arguments); } function U() { if (typeof Reflect > "u" || !Reflect.construct || Reflect.construct.sham) return !1; if (typeof Proxy == "function") return !0; try { return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { })), !0; } catch { return !1; } } function Y(f) { return Function.toString.call(f).indexOf("[native code]") !== -1; } function z(f, p) { return z = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(b, q) { return b.__proto__ = q, b; }, z(f, p); } function x(f) { return x = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function(E) { return E.__proto__ || Object.getPrototypeOf(E); }, x(f); } function L(f) { "@babel/helpers - typeof"; return L = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(p) { return typeof p; } : function(p) { return p && typeof Symbol == "function" && p.constructor === Symbol && p !== Symbol.prototype ? "symbol" : typeof p; }, L(f); } var te = Oe, Q = te.inspect, c = Xe(), s = c.codes.ERR_INVALID_ARG_TYPE; function h(f, p, E) { return (E === void 0 || E > f.length) && (E = f.length), f.substring(E - p.length, E) === p; } function l(f, p) { if (p = Math.floor(p), f.length == 0 || p == 0) return ""; var E = f.length * p; for (p = Math.floor(Math.log(p) / Math.log(2)); p; ) f += f, p--; return f += f.substring(0, E - f.length), f; } var _ = "", A = "", Z = "", M = "", re = { deepStrictEqual: "Expected values to be strictly deep-equal:", strictEqual: "Expected values to be strictly equal:", strictEqualObject: 'Expected "actual" to be reference-equal to "expected":', deepEqual: "Expected values to be loosely deep-equal:", equal: "Expected values to be loosely equal:", notDeepStrictEqual: 'Expected "actual" not to be strictly deep-equal to:', notStrictEqual: 'Expected "actual" to be strictly unequal to:', notStrictEqualObject: 'Expected "actual" not to be reference-equal to "expected":', notDeepEqual: 'Expected "actual" not to be loosely deep-equal to:', notEqual: 'Expected "actual" to be loosely unequal to:', notIdentical: "Values identical but not reference-equal:" }, pe = 10; function se(f) { var p = Object.keys(f), E = Object.create(Object.getPrototypeOf(f)); return p.forEach(function(b) { E[b] = f[b]; }), Object.defineProperty(E, "message", { value: f.message }), E; } function oe(f) { return Q(f, { compact: !1, customInspect: !1, depth: 1e3, maxArrayLength: 1 / 0, // Assert compares only enumerable properties (with a few exceptions). showHidden: !1, // Having a long line as error is better than wrapping the line for // comparison for now. // TODO(BridgeAR): `breakLength` should be limited as soon as soon as we // have meta information about the inspected properties (i.e., know where // in what line the property starts and ends). breakLength: 1 / 0, // Assert does not detect proxies currently. showProxy: !1, sorted: !0, // Inspect getters as we also check them when comparing entries. getters: !0 }); } function me(f, p, E) { var b = "", q = "", V = 0, X = "", H = !1, a = oe(f), e = a.split(` `), r = oe(p).split(` `), i = 0, w = ""; if (E === "strictEqual" && L(f) === "object" && L(p) === "object" && f !== null && p !== null && (E = "strictEqualObject"), e.length === 1 && r.length === 1 && e[0] !== r[0]) { var O = e[0].length + r[0].length; if (O <= pe) { if ((L(f) !== "object" || f === null) && (L(p) !== "object" || p === null) && (f !== 0 || p !== 0)) return "".concat(re[E], ` `) + "".concat(e[0], " !== ").concat(r[0], ` `); } else if (E !== "strictEqualObject") { var D = ce.stderr && ce.stderr.isTTY ? ce.stderr.columns : 80; if (O < D) { for (; e[0][i] === r[0][i]; ) i++; i > 2 && (w = ` `.concat(l(" ", i), "^"), i = 0); } } } for (var J = e[e.length - 1], K = r[r.length - 1]; J === K && (i++ < 2 ? X = ` `.concat(J).concat(X) : b = J, e.pop(), r.pop(), !(e.length === 0 || r.length === 0)); ) J = e[e.length - 1], K = r[r.length - 1]; var ue = Math.max(e.length, r.length); if (ue === 0) { var he = a.split(` `); if (he.length > 30) for (he[26] = "".concat(_, "...").concat(M); he.length > 27; ) he.pop(); return "".concat(re.notIdentical, ` `).concat(he.join(` `), ` `); } i > 3 && (X = ` `.concat(_, "...").concat(M).concat(X), H = !0), b !== "" && (X = ` `.concat(b).concat(X), b = ""); var ae = 0, be = re[E] + ` `.concat(A, "+ actual").concat(M, " ").concat(Z, "- expected").concat(M), je = " ".concat(_, "...").concat(M, " Lines skipped"); for (i = 0; i < ue; i++) { var ie = i - V; if (e.length < i + 1) ie > 1 && i > 2 && (ie > 4 ? (q += ` `.concat(_, "...").concat(M), H = !0) : ie > 3 && (q += ` `.concat(r[i - 2]), ae++), q += ` `.concat(r[i - 1]), ae++), V = i, b += ` `.concat(Z, "-").concat(M, " ").concat(r[i]), ae++; else if (r.length < i + 1) ie > 1 && i > 2 && (ie > 4 ? (q += ` `.concat(_, "...").concat(M), H = !0) : ie > 3 && (q += ` `.concat(e[i - 2]), ae++), q += ` `.concat(e[i - 1]), ae++), V = i, q += ` `.concat(A, "+").concat(M, " ").concat(e[i]), ae++; else { var ge = r[i], fe = e[i], t = fe !== ge && (!h(fe, ",") || fe.slice(0, -1) !== ge); t && h(ge, ",") && ge.slice(0, -1) === fe && (t = !1, fe += ","), t ? (ie > 1 && i > 2 && (ie > 4 ? (q += ` `.concat(_, "...").concat(M), H = !0) : ie > 3 && (q += ` `.concat(e[i - 2]), ae++), q += ` `.concat(e[i - 1]), ae++), V = i, q += ` `.concat(A, "+").concat(M, " ").concat(fe), b += ` `.concat(Z, "-").concat(M, " ").concat(ge), ae += 2) : (q += b, b = "", (ie === 1 || i === 0) && (q += ` `.concat(fe), ae++)); } if (ae > 20 && i < ue - 2) return "".concat(be).concat(je, ` `).concat(q, ` `).concat(_, "...").concat(M).concat(b, ` `) + "".concat(_, "...").concat(M); } return "".concat(be).concat(H ? je : "", ` `).concat(q).concat(b).concat(X).concat(w); } var de = /* @__PURE__ */ function(f, p) { $(b, f); var E = B(b); function b(q) { var V; if (d(this, b), L(q) !== "object" || q === null) throw new s("options", "Object", q); var X = q.message, H = q.operator, a = q.stackStartFn, e = q.actual, r = q.expected, i = Error.stackTraceLimit; if (Error.stackTraceLimit = 0, X != null) V = E.call(this, String(X)); else if (ce.stderr && ce.stderr.isTTY && (ce.stderr && ce.stderr.getColorDepth && ce.stderr.getColorDepth() !== 1 ? (_ = "\x1B[34m", A = "\x1B[32m", M = "\x1B[39m", Z = "\x1B[31m") : (_ = "", A = "", M = "", Z = "")), L(e) === "object" && e !== null && L(r) === "object" && r !== null && "stack" in e && e instanceof Error && "stack" in r && r instanceof Error && (e = se(e), r = se(r)), H === "deepStrictEqual" || H === "strictEqual") V = E.call(this, me(e, r, H)); else if (H === "notDeepStrictEqual" || H === "notStrictEqual") { var w = re[H], O = oe(e).split(` `); if (H === "notStrictEqual" && L(e) === "object" && e !== null && (w = re.notStrictEqualObject), O.length > 30) for (O[26] = "".concat(_, "...").concat(M); O.length > 27; ) O.pop(); O.length === 1 ? V = E.call(this, "".concat(w, " ").concat(O[0])) : V = E.call(this, "".concat(w, ` `).concat(O.join(` `), ` `)); } else { var D = oe(e), J = "", K = re[H]; H === "notDeepEqual" || H === "notEqual" ? (D = "".concat(re[H], ` `).concat(D), D.length > 1024 && (D = "".concat(D.slice(0, 1021), "..."))) : (J = "".concat(oe(r)), D.length > 512 && (D = "".concat(D.slice(0, 509), "...")), J.length > 512 && (J = "".concat(J.slice(0, 509), "...")), H === "deepEqual" || H === "equal" ? D = "".concat(K, ` `).concat(D, ` should equal `) : J = " ".concat(H, " ").concat(J)), V = E.call(this, "".concat(D).concat(J)); } return Error.stackTraceLimit = i, V.generatedMessage = !X, Object.defineProperty(R(V), "name", { value: "AssertionError [ERR_ASSERTION]", enumerable: !1, writable: !0, configurable: !0 }), V.code = "ERR_ASSERTION", V.actual = e, V.expected = r, V.operator = H, Error.captureStackTrace && Error.captureStackTrace(R(V), a), V.stack, V.name = "AssertionError", W(V); } return P(b, [{ key: "toString", value: function() { return "".concat(this.name, " [").concat(this.code, "]: ").concat(this.message); } }, { key: p, value: function(V, X) { return Q(this, o(o({}, X), {}, { customInspect: !1, depth: 0 })); } }]), b; }(/* @__PURE__ */ m(Error), Q.custom); return qe = de, qe; } var Pe, Ve; function Qe() { return Ve || (Ve = 1, Pe = function(o) { return o !== o; }), Pe; } var Ne, Ge; function Ze() { if (Ge) return Ne; Ge = 1; var u = Qe(); return Ne = function() { return Number.isNaN && Number.isNaN(NaN) && !Number.isNaN("a") ? Number.isNaN : u; }, Ne; } var Te, ke; function Pt() { if (ke) return Te; ke = 1; var u = Je(), o = Ze(); return Te = function() { var d = o(); return u(Number, { isNaN: d }, { isNaN: function() { return Number.isNaN !== d; } }), d; }, Te; } var xe, He; function Nt() { if (He) return xe; He = 1; var u = Ke, o = Je(), y = Qe(), d = Ze(), v = Pt(), P = u(d(), Number); return o(P, { getPolyfill: d, implementation: y, shim: v }), xe = P, xe; } var _e, We; function Tt() { if (We) return _e; We = 1; function u(t, n) { return P(t) || v(t, n) || y(t, n) || o(); } function o() { throw new TypeError(`Invalid attempt to destructure non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`); } function y(t, n) { if (t) { if (typeof t == "string") return d(t, n); var g = Object.prototype.toString.call(t).slice(8, -1); if (g === "Object" && t.constructor && (g = t.constructor.name), g === "Map" || g === "Set") return Array.from(t); if (g === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(g)) return d(t, n); } } function d(t, n) { (n == null || n > t.length) && (n = t.length); for (var g = 0, S = new Array(n); g < n; g++) S[g] = t[g]; return S; } function v(t, n) { var g = t == null ? null : typeof Symbol < "u" && t[Symbol.iterator] || t["@@iterator"]; if (g != null) { var S, j, C, T, G = [], k = !0, ee = !1; try { if (C = (g = g.call(t)).next, n === 0) { if (Object(g) !== g) return; k = !1; } else for (; !(k = (S = C.call(g)).done) && (G.push(S.value), G.length !== n); k = !0) ; } catch (ne) { ee = !0, j = ne; } finally { try { if (!k && g.return != null && (T = g.return(), Object(T) !== T)) return; } finally { if (ee) throw j; } } return G; } } function P(t) { if (Array.isArray(t)) return t; } function N(t) { "@babel/helpers - typeof"; return N = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(n) { return typeof n; } : function(n) { return n && typeof Symbol == "function" && n.constructor === Symbol && n !== Symbol.prototype ? "symbol" : typeof n; }, N(t); } var F = /a/g.flags !== void 0, $ = function(n) { var g = []; return n.forEach(function(S) { return g.push(S); }), g; }, B = function(n) { var g = []; return n.forEach(function(S, j) { return g.push([j, S]); }), g; }, W = Object.is ? Object.is : ct(), R = Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols : function() { return []; }, m = Number.isNaN ? Number.isNaN : Nt(); function I(t) { return t.call.bind(t); } var U = I(Object.prototype.hasOwnProperty), Y = I(Object.prototype.propertyIsEnumerable), z = I(Object.prototype.toString), x = Oe.types, L = x.isAnyArrayBuffer, te = x.isArrayBufferView, Q = x.isDate, c = x.isMap, s = x.isRegExp, h = x.isSet, l = x.isNativeError, _ = x.isBoxedPrimitive, A = x.isNumberObject, Z = x.isStringObject, M = x.isBooleanObject, re = x.isBigIntObject, pe = x.isSymbolObject, se = x.isFloat32Array, oe = x.isFloat64Array; function me(t) { if (t.length === 0 || t.length > 10) return !0; for (var n = 0; n < t.length; n++) { var g = t.charCodeAt(n); if (g < 48 || g > 57) return !0; } return t.length === 10 && t >= Math.pow(2, 32); } function de(t) { return Object.keys(t).filter(me).concat(R(t).filter(Object.prototype.propertyIsEnumerable.bind(t))); } /*! * The buffer module from node.js, for the browser. * * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org> * @license MIT */ function f(t, n) { if (t === n) return 0; for (var g = t.length, S = n.length, j = 0, C = Math.min(g, S); j < C; ++j) if (t[j] !== n[j]) { g = t[j], S = n[j]; break; } return g < S ? -1 : S < g ? 1 : 0; } var p = !0, E = !1, b = 0, q = 1, V = 2, X = 3; function H(t, n) { return F ? t.source === n.source && t.flags === n.flags : RegExp.prototype.toString.call(t) === RegExp.prototype.toString.call(n); } function a(t, n) { if (t.byteLength !== n.byteLength) return !1; for (var g = 0; g < t.byteLength; g++) if (t[g] !== n[g]) return !1; return !0; } function e(t, n) { return t.byteLength !== n.byteLength ? !1 : f(new Uint8Array(t.buffer, t.byteOffset, t.byteLength), new Uint8Array(n.buffer, n.byteOffset, n.byteLength)) === 0; } function r(t, n) { return t.byteLength === n.byteLength && f(new Uint8Array(t), new Uint8Array(n)) === 0; } function i(t, n) { return A(t) ? A(n) && W(Number.prototype.valueOf.call(t), Number.prototype.valueOf.call(n)) : Z(t) ? Z(n) && String.prototype.valueOf.call(t) === String.prototype.valueOf.call(n) : M(t) ? M(n) && Boolean.prototype.valueOf.call(t) === Boolean.prototype.valueOf.call(n) : re(t) ? re(n) && BigInt.prototype.valueOf.call(t) === BigInt.prototype.valueOf.call(n) : pe(n) && Symbol.prototype.valueOf.call(t) === Symbol.prototype.valueOf.call(n); } function w(t, n, g, S) { if (t === n) return t !== 0 ? !0 : g ? W(t, n) : !0; if (g) { if (N(t) !== "object") return typeof t == "number" && m(t) && m(n); if (N(n) !== "object" || t === null || n === null || Object.getPrototypeOf(t) !== Object.getPrototypeOf(n)) return !1; } else { if (t === null || N(t) !== "object") return n === null || N(n) !== "object" ? t == n : !1; if (n === null || N(n) !== "object") return !1; } var j = z(t), C = z(n); if (j !== C) return !1; if (Array.isArray(t)) { if (t.length !== n.length) return !1; var T = de(t), G = de(n); return T.length !== G.length ? !1 : D(t, n, g, S, q, T); } if (j === "[object Object]" && (!c(t) && c(n) || !h(t) && h(n))) return !1; if (Q(t)) { if (!Q(n) || Date.prototype.getTime.call(t) !== Date.prototype.getTime.call(n)) return !1; } else if (s(t)) { if (!s(n) || !H(t, n)) return !1; } else if (l(t) || t instanceof Error) { if (t.message !== n.message || t.name !== n.name) return !1; } else if (te(t)) { if (!g && (se(t) || oe(t))) { if (!a(t, n)) return !1; } else if (!e(t, n)) return !1; var k = de(t), ee = de(n); return k.length !== ee.length ? !1 : D(t, n, g, S, b, k); } else { if (h(t)) return !h(n) || t.size !== n.size ? !1 : D(t, n, g, S, V); if (c(t)) return !c(n) || t.size !== n.size ? !1 : D(t, n, g, S, X); if (L(t)) { if (!r(t, n)) return !1; } else if (_(t) && !i(t, n)) return !1; } return D(t, n, g, S, b); } function O(t, n) { return n.filter(function(g) { return Y(t, g); }); } function D(t, n, g, S, j, C) { if (arguments.length === 5) { C = Object.keys(t); var T = Object.keys(n); if (C.length !== T.length) return !1; } for (var G = 0; G < C.length; G++) if (!U(n, C[G])) return !1; if (g && arguments.length === 5) { var k = R(t); if (k.length !== 0) { var ee = 0; for (G = 0; G < k.length; G++) { var ne = k[G]; if (Y(t, ne)) { if (!Y(n, ne)) return !1; C.push(ne), ee++; } else if (Y(n, ne)) return !1; } var we = R(n); if (k.length !== we.length && O(n, we).length !== ee) return !1; } else { var ve = R(n); if (ve.length !== 0 && O(n, ve).length !== 0) return !1; } } if (C.length === 0 && (j === b || j === q && t.length === 0 || t.size === 0)) return !0; if (S === void 0) S = { val1: /* @__PURE__ */ new Map(), val2: /* @__PURE__ */ new Map(), position: 0 }; else { var Ee = S.val1.get(t); if (Ee !== void 0) { var le = S.val2.get(n); if (le !== void 0) return Ee === le; } S.position++; } S.val1.set(t, S.position), S.val2.set(n, S.position); var Se = ie(t, n, g, C, S, j); return S.val1.delete(t), S.val2.delete(n), Se; } function J(t, n, g, S) { for (var j = $(t), C = 0; C < j.length; C++) { var T = j[C]; if (w(n, T, g, S)) return t.delete(T), !0; } return !1; } function K(t) { switch (N(t)) { case "undefined": return null; case "object": return; case "symbol": return !1; case "string": t = +t; case "number": if (m(t)) return !1; } return !0; } function ue(t, n, g) { var S = K(g); return S ?? (n.has(S) && !t.has(S)); } function he(t, n, g, S, j) { var C = K(g); if (C != null) return C; var T = n.get(C); return T === void 0 && !n.has(C) || !w(S, T, !1, j) ? !1 : !t.has(C) && w(S, T, !1, j); } function ae(t, n, g, S) { for (var j = null, C = $(t), T = 0; T < C.length; T++) { var G = C[T]; if (N(G) === "object" && G !== null) j === null && (j = /* @__PURE__ */ new Set()), j.add(G); else if (!n.has(G)) { if (g || !ue(t, n, G)) return !1; j === null && (j = /* @__PURE__ */ new Set()), j.add(G); } } if (j !== null) { for (var k = $(n), ee = 0; ee < k.length; ee++) { var ne = k[ee]; if (N(ne) === "object" && ne !== null) { if (!J(j, ne, g, S)) return !1; } else if (!g && !t.has(ne) && !J(j, ne, g, S)) return !1; } return j.size === 0; } return !0; } function be(t, n, g, S, j, C) { for (var T = $(t), G = 0; G < T.length; G++) { var k = T[G]; if (w(g, k, j, C) && w(S, n.get(k), j, C)) return t.delete(k), !0; } return !1; } function je(t, n, g, S) { for (var j = null, C = B(t), T = 0; T < C.length; T++) { var G = u(C[T], 2), k = G[0], ee = G[1]; if (N(k) === "object" && k !== null) j === null && (j = /* @__PURE__ */ new Set()), j.add(k); else { var ne = n.get(k); if (ne === void 0 && !n.has(k) || !w(ee, ne, g, S)) { if (g || !he(t, n, k, ee, S)) return !1; j === null && (j = /* @__PURE__ */ new Set()), j.add(k); } } } if (j !== null) { for (var we = B(n), ve = 0; ve < we.length; ve++) { var Ee = u(we[ve], 2), le = Ee[0], Se = Ee[1]; if (N(le) === "object" && le !== null) { if (!be(j, t, le, Se, g, S)) return !1; } else if (!g && (!t.has(le) || !w(t.get(le), Se, !1, S)) && !be(j, t, le, Se, !1, S)) return !1; } return j.size === 0; } return !0; } function ie(t, n, g, S, j, C) { var T = 0; if (C === V) { if (!ae(t, n, g, j)) return !1; } else if (C === X) { if (!je(t, n, g, j)) return !1; } else if (C === q) for (; T < t.length; T++) if (U(t, T)) { if (!U(n, T) || !w(t[T], n[T], g, j)) return !1; } else { if (U(n, T)) return !1; for (var G = Object.keys(t); T < G.length; T++) { var k = G[T]; if (!U(n, k) || !w(t[k], n[k], g, j)) return !1; } return G.length === Object.keys(n).length; } for (T = 0; T < S.length; T++) { var ee = S[T]; if (!w(t[ee], n[ee], g, j)) return !1; } return !0; } function ge(t, n) { return w(t, n, E); } function fe(t, n) { return w(t, n, p); } return _e = { isDeepEqual: ge, isDeepStrictEqual: fe }, _e; } var ze; function Ce() { if (ze) return Ie.exports; ze = 1; function u(a) { "@babel/helpers - typeof"; return u = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) { return typeof e; } : function(e) { return e && typeof Symbol == "function" && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e; }, u(a); } function o(a, e) { for (var r = 0; r < e.length; r++) { var i = e[r]; i.enumerable = i.enumerable || !1, i.configurable = !0, "value" in i && (i.writable = !0), Object.defineProperty(a, d(i.key), i); } } function y(a, e, r) { return e && o(a.prototype, e), r && o(a, r), Object.defineProperty(a, "prototype", { writable: !1 }), a; } function d(a) { var e = v(a, "string"); return u(e) === "symbol" ? e : String(e); } function v(a, e) { if (u(a) !== "object" || a === null) return a; var r = a[Symbol.toPrimitive]; if (r !== void 0) { var i = r.call(a, e || "default"); if (u(i) !== "object") return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return (e === "string" ? String : Number)(a); } function P(a, e) { if (!(a instanceof e)) throw new TypeError("Cannot call a class as a function"); } var N = Xe(), F = N.codes, $ = F.ERR_AMBIGUOUS_ARGUMENT, B = F.ERR_INVALID_ARG_TYPE, W = F.ERR_INVALID_ARG_VALUE, R = F.ERR_INVALID_RETURN_VALUE, m = F.ERR_MISSING_ARGS, I = qt(), U = Oe, Y = U.inspect, z = Oe.types, x = z.isPromise, L = z.isRegExp, te = ut(), Q = ft(), c = et("RegExp.prototype.test"), s, h; function l() { var a = Tt(); s = a.isDeepEqual, h = a.isDeepStrictEqual; } var _ = !1, A = Ie.exports = se, Z = {}; function M(a) { throw a.message instanceof Error ? a.message : new I(a); } function re(a, e, r, i, w) { var O = arguments.length, D; if (O === 0) D = "Failed"; else if (O === 1) r = a, a = void 0; else { if (_ === !1) { _ = !0; var J = ce.emitWarning ? ce.emitWarning : console.warn.bind(console); J("assert.fail() with more than one argument is deprecated. Please use assert.strictEqual() instead or only pass a message.", "DeprecationWarning", "DEP0094"); } O === 2 && (i = "!="); } if (r instanceof Error) throw r; var K = { actual: a, expected: e, operator: i === void 0 ? "fail" : i, stackStartFn: w || re }; r !== void 0 && (K.message = r); var ue = new I(K); throw D && (ue.message = D, ue.generatedMessage = !0), ue; } A.fail = re, A.AssertionError = I; function pe(a, e, r, i) { if (!r) { var w = !1; if (e === 0) w = !0, i = "No value argument passed to `assert.ok()`"; else if (i instanceof Error) throw i; var O = new I({ actual: r, expected: !0, message: i, operator: "==", stackStartFn: a }); throw O.generatedMessage = w, O; } } function se() { for (var a = arguments.length, e = new Array(a), r = 0; r < a; r++) e[r] = arguments[r]; pe.apply(void 0, [se, e.length].concat(e)); } A.ok = se, A.equal = function a(e, r, i) { if (arguments.length < 2) throw new m("actual", "expected"); e != r && M({ actual: e, expected: r, message: i, operator: "==", stackStartFn: a }); }, A.notEqual = function a(e, r, i) { if (arguments.length < 2) throw new m("actual", "expected"); e == r && M({ actual: e, expected: r, message: i, operator: "!=", stackStartFn: a }); }, A.deepEqual = function a(e, r, i) { if (arguments.length < 2) throw new m("actual", "expected"); s === void 0 && l(), s(e, r) || M({ actual: e, expected: r, message: i, operator: "deepEqual", stackStartFn: a }); }, A.notDeepEqual = function a(e, r, i) { if (arguments.length < 2) throw new m("actual", "expected"); s === void 0 && l(), s(e, r) && M({ actual: e, expected: r, message: i, operator: "notDeepEqual", stackStartFn: a }); }, A.deepStrictEqual = function a(e, r, i) { if (arguments.length < 2) throw new m("actual", "expected"); s === void 0 && l(), h(e, r) || M({ actual: e, expected: r, message: i, operator: "deepStrictEqual", stackStartFn: a }); }, A.notDeepStrictEqual = oe; function oe(a, e, r) { if (arguments.length < 2) throw new m("actual", "expected"); s === void 0 && l(), h(a, e) && M({ actual: a, expected: e, message: r, operator: "notDeepStrictEqual", stackStartFn: oe }); } A.strictEqual = function a(e, r, i) { if (arguments.length < 2) throw new m("actual", "expected"); Q(e, r) || M({ actual: e, expected: r, message: i, operator: "strictEqual", stackStartFn: a }); }, A.notStrictEqual = function a(e, r, i) { if (arguments.length < 2) throw new m("actual", "expected"); Q(e, r) && M({ actual: e, expected: r, message: i, operator: "notStrictEqual", stackStartFn: a }); }; var me = /* @__PURE__ */ y(function a(e, r, i) { var w = this; P(this, a), r.forEach(function(O) { O in e && (i !== void 0 && typeof i[O] == "string" && L(e[O]) && c(e[O], i[O]) ? w[O] = i[O] : w[O] = e[O]); }); }); function de(a, e, r, i, w, O) { if (!(r in a) || !h(a[r], e[r])) { if (!i) { var D = new me(a, w), J = new me(e, w, a), K = new I({ actual: D, expected: J, operator: "deepStrictEqual", stackStartFn: O }); throw K.actual = a, K.expected = e, K.operator = O.name, K; } M({ actual: a, expected: e, message: i, operator: O.name, stackStartFn: O }); } } function f(a, e, r, i) { if (typeof e != "function") { if (L(e)) return c(e, a); if (arguments.length === 2) throw new B("expected", ["Function", "RegExp"], e); if (u(a) !== "object" || a === null) { var w = new I({ actual: a, expected: e, message: r, operator: "deepStrictEqual", stackStartFn: i }); throw w.operator = i.name, w; } var O = Object.keys(e); if (e instanceof Error) O.push("name", "message"); else if (O.length === 0) throw new W("error", e, "may not be an empty object"); return s === void 0 && l(), O.forEach(function(D) { typeof a[D] == "string" && L(e[D]) && c(e[D], a[D]) || de(a, e, D, r, O, i); }), !0; } return e.prototype !== void 0 && a instanceof e ? !0 : Error.isPrototypeOf(e) ? !1 : e.call({}, a) === !0; } function p(a) { if (typeof a != "function") throw new B("fn", "Function", a); try { a(); } catch (e) { return e; } return Z; } function E(a) { return x(a) || a !== null && u(a) === "object" && typeof a.then == "function" && typeof a.catch == "function"; } function b(a) { return Promise.resolve().then(function() { var e; if (typeof a == "function") { if (e = a(), !E(e)) throw new R("instance of Promise", "promiseFn", e); } else if (E(a)) e = a; else throw new B("promiseFn", ["Function", "Promise"], a); return Promise.resolve().then(function() { return e; }).then(function() { return Z; }).catch(function(r) { return r; }); }); } function q(a, e, r, i) { if (typeof r == "string") { if (arguments.length === 4) throw new B("error", ["Object", "Error", "Function", "RegExp"], r); if (u(e) === "object" && e !== null) { if (e.message === r) throw new $("error/message", 'The error message "'.concat(e.message, '" is identical to the message.')); } else if (e === r) throw new $("error/message", 'The error "'.concat(e, '" is identical to the message.')); i = r, r = void 0; } else if (r != null && u(r) !== "object" && typeof r != "function") throw new B("error", ["Object", "Error", "Function", "RegExp"], r); if (e === Z) { var w = ""; r && r.name && (w += " (".concat(r.name, ")")), w += i ? ": ".concat(i) : "."; var O = a.name === "rejects" ? "rejection" : "exception"; M({ actual: void 0, expected: r, operator: a.name, message: "Missing expected ".concat(O).concat(w), stackStartFn: a }); } if (r && !f(e, r, i, a)) throw e; } function V(a, e, r, i) { if (e !== Z) { if (typeof r == "string" && (i = r, r = void 0), !r || f(e, r)) { var w = i ? ": ".concat(i) : ".", O = a.name === "doesNotReject" ? "rejection" : "exception"; M({ actual: e, expected: r, operator: a.name, message: "Got unwanted ".concat(O).concat(w, ` `) + 'Actual message: "'.concat(e && e.message, '"'), stackStartFn: a }); } throw e; } } A.throws = function a(e) { for (var r = arguments.length, i = new Array(r > 1 ? r - 1 : 0), w = 1; w < r; w++) i[w - 1] = arguments[w]; q.apply(void 0, [a, p(e)].concat(i)); }, A.rejects = function a(e) { for (var r = arguments.length, i = new Array(r > 1 ? r - 1 : 0), w = 1; w < r; w++) i[w - 1] = arguments[w]; return b(e).then(function(O) { return q.apply(void 0, [a, O].concat(i)); }); }, A.doesNotThrow = function a(e) { for (var r = arguments.length, i = new Array(r > 1 ? r - 1 : 0), w = 1; w < r; w++) i[w - 1] = arguments[w]; V.apply(void 0, [a, p(e)].concat(i)); }, A.doesNotReject = function a(e) { for (var r = arguments.length, i = new Array(r > 1 ? r - 1 : 0), w = 1; w < r; w++) i[w - 1] = arguments[w]; return b(e).then(function(O) { return V.apply(void 0, [a, O].concat(i)); }); }, A.ifError = function a(e) { if (e != null) { var r = "ifError got unwanted exception: "; u(e) === "object" && typeof e.message == "string" ? e.message.length === 0 && e.constructor ? r += e.constructor.name : r += e.message : r += Y(e); var i = new I({ actual: e, expected: null, operator: "ifError", message: r, stackStartFn: a }), w = e.stack; if (typeof w == "string") { var O = w.split(` `); O.shift(); for (var D = i.stack.split(` `), J = 0; J < O.length; J++) { var K = D.indexOf(O[J]); if (K !== -1) { D = D.slice(0, K); break; } } i.stack = "".concat(D.join(` `), ` `).concat(O.join(` `)); } throw i; } }; function X(a, e, r, i, w) { if (!L(e)) throw new B("regexp", "RegExp", e); var O = w === "match"; if (typeof a != "string" || c(e, a) !== O) { if (r instanceof Error) throw r; var D = !r; r = r || (typeof a != "string" ? 'The "string" argument must be of type string. Received type ' + "".concat(u(a), " (").concat(Y(a), ")") : (O ? "The input did not match the regular expression " : "The input was expected to not match the regular expression ") + "".concat(Y(e), `. Input: `).concat(Y(a), ` `)); var J = new I({ actual: a, expected: e, message: r, operator: w, stackStartFn: i }); throw J.generatedMessage = D, J; } } A.match = function a(e, r, i) { X(e, r, i, a, "match"); }, A.doesNotMatch = function a(e, r, i) { X(e, r, i, a, "doesNotMatch"); }; function H() { for (var a = arguments.length, e = new Array(a), r = 0; r < a; r++) e[r] = arguments[r]; pe.apply(void 0, [H, e.length].concat(e)); } return A.strict = te(H, A, { equal: A.strictEqual, deepEqual: A.deepStrictEqual, notEqual: A.notStrictEqual, notDeepEqual: A.notDeepStrictEqual }), A.strict.strict = A.strict, Ie.exports; } var xt = Ce(); function Ye(u) { if (typeof u._id != "string") throw new Error("Invalid conversation data: _id must be a string"); if (!Array.isArray(u.messages)) throw new Error("Invalid conversation data: messages must be an array"); if (typeof u.createdAt != "number" || new Date(u.createdAt).getTime() !== u.createdAt) throw new Error( `Invalid conversation data: createdAt must be a valid datetime number. Got ${u.createdAt}` ); return { _id: u._id, messages: u.messages, createdAt: u.createdAt }; } const _t = "X-Request-Origin"; function Mt() { if (typeof window < "u") return window.location.href; } class Me extends Error { constructor(o, y = {}) { const { retryAfter: d = 1e3, data: v } = y; super(o), this.name = "RetriableError", this.message = o, this.retryAfter = d, this.data = v; } } class Dt extends Error { constructor(o) { super(o), this.name = "TimeoutError", this.message = o; } } function Ct(u) { const o = u; return typeof o.type == "string" && typeof o.data < "u"; } const Ut = (u) => u === "delta" || u === "references" || u === "metadata" || u === "finished", Ft = (u) => { const o = u; return o.type === "delta" && typeof o.data == "string" || o.type === "references" && typeof o.data == "object" || o.type === "metadata" && typeof o.data == "object" || o.type === "finished" && typeof o.data == "string"; }; class Lt { constructor(o) { var d, v; xt.strict( o.serverUrl, "You must define a serverUrl for the ConversationService" ), this.serverUrl = o.serverUrl.startsWith("/") ? new URL( o.serverUrl, window.location.protocol + "//" + window.location.host ).href : o.serverUrl; const y = new Headers({ "Content-Type": "applica