UNPKG

mongodb-chatbot-ui

Version:

UI React components for the MongoDB Assistant

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