@selleo/chatbot-client
Version:
Client that can be integrated with a backend created with openai
1,570 lines (1,566 loc) • 264 kB
JavaScript
import "./styles.css";
import * as Fe from "react";
import Qe, {
createContext as Ri,
memo as Ii,
useContext as _i,
useEffect as ht,
useRef as _t,
useState as gn,
} from "react";
function an(e) {
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default")
? e.default
: e;
}
var nt = { exports: {} },
hn = {};
/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var It;
function Fi() {
if (It) return hn;
It = 1;
var e = Qe,
n = Symbol.for("react.element"),
t = Symbol.for("react.fragment"),
r = Object.prototype.hasOwnProperty,
i = e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,
l = { key: !0, ref: !0, __self: !0, __source: !0 };
function o(a, s, c) {
var f,
p = {},
g = null,
d = null;
c !== void 0 && (g = "" + c),
s.key !== void 0 && (g = "" + s.key),
s.ref !== void 0 && (d = s.ref);
for (f in s) r.call(s, f) && !l.hasOwnProperty(f) && (p[f] = s[f]);
if (a && a.defaultProps)
for (f in ((s = a.defaultProps), s)) p[f] === void 0 && (p[f] = s[f]);
return {
$$typeof: n,
type: a,
key: g,
ref: d,
props: p,
_owner: i.current,
};
}
return (hn.Fragment = t), (hn.jsx = o), (hn.jsxs = o), hn;
}
var dn = {};
/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var Ft;
function Di() {
return (
Ft ||
((Ft = 1),
process.env.NODE_ENV !== "production" &&
(function () {
var e = Qe,
n = Symbol.for("react.element"),
t = Symbol.for("react.portal"),
r = Symbol.for("react.fragment"),
i = Symbol.for("react.strict_mode"),
l = Symbol.for("react.profiler"),
o = Symbol.for("react.provider"),
a = Symbol.for("react.context"),
s = Symbol.for("react.forward_ref"),
c = Symbol.for("react.suspense"),
f = Symbol.for("react.suspense_list"),
p = Symbol.for("react.memo"),
g = Symbol.for("react.lazy"),
d = Symbol.for("react.offscreen"),
E = Symbol.iterator,
y = "@@iterator";
function x(m) {
if (m === null || typeof m != "object") return null;
var S = (E && m[E]) || m[y];
return typeof S == "function" ? S : null;
}
var v = e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
function F(m) {
{
for (
var S = arguments.length,
R = new Array(S > 1 ? S - 1 : 0),
Y = 1;
Y < S;
Y++
)
R[Y - 1] = arguments[Y];
C("error", m, R);
}
}
function C(m, S, R) {
{
var Y = v.ReactDebugCurrentFrame,
se = Y.getStackAddendum();
se !== "" && ((S += "%s"), (R = R.concat([se])));
var me = R.map(function (ie) {
return String(ie);
});
me.unshift("Warning: " + S),
Function.prototype.apply.call(console[m], console, me);
}
}
var z = !1,
k = !1,
b = !1,
M = !1,
q = !1,
Z;
Z = Symbol.for("react.module.reference");
function de(m) {
return !!(
typeof m == "string" ||
typeof m == "function" ||
m === r ||
m === l ||
q ||
m === i ||
m === c ||
m === f ||
M ||
m === d ||
z ||
k ||
b ||
(typeof m == "object" &&
m !== null &&
(m.$$typeof === g ||
m.$$typeof === p ||
m.$$typeof === o ||
m.$$typeof === a ||
m.$$typeof === s || // This needs to include all possible module reference object
// types supported by any Flight configuration anywhere since
// we don't know which Flight build this will end up being used
// with.
m.$$typeof === Z ||
m.getModuleId !== void 0))
);
}
function _(m, S, R) {
var Y = m.displayName;
if (Y) return Y;
var se = S.displayName || S.name || "";
return se !== "" ? R + "(" + se + ")" : R;
}
function I(m) {
return m.displayName || "Context";
}
function G(m) {
if (m == null) return null;
if (
(typeof m.tag == "number" &&
F(
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue.",
),
typeof m == "function")
)
return m.displayName || m.name || null;
if (typeof m == "string") return m;
switch (m) {
case r:
return "Fragment";
case t:
return "Portal";
case l:
return "Profiler";
case i:
return "StrictMode";
case c:
return "Suspense";
case f:
return "SuspenseList";
}
if (typeof m == "object")
switch (m.$$typeof) {
case a:
var S = m;
return I(S) + ".Consumer";
case o:
var R = m;
return I(R._context) + ".Provider";
case s:
return _(m, m.render, "ForwardRef");
case p:
var Y = m.displayName || null;
return Y !== null ? Y : G(m.type) || "Memo";
case g: {
var se = m,
me = se._payload,
ie = se._init;
try {
return G(ie(me));
} catch {
return null;
}
}
}
return null;
}
var ne = Object.assign,
D = 0,
ee,
ue,
be,
Se,
u,
A,
N;
function h() {}
h.__reactDisabledLog = !0;
function B() {
{
if (D === 0) {
(ee = console.log),
(ue = console.info),
(be = console.warn),
(Se = console.error),
(u = console.group),
(A = console.groupCollapsed),
(N = console.groupEnd);
var m = {
configurable: !0,
enumerable: !0,
value: h,
writable: !0,
};
Object.defineProperties(console, {
info: m,
log: m,
warn: m,
error: m,
group: m,
groupCollapsed: m,
groupEnd: m,
});
}
D++;
}
}
function Q() {
{
if ((D--, D === 0)) {
var m = {
configurable: !0,
enumerable: !0,
writable: !0,
};
Object.defineProperties(console, {
log: ne({}, m, {
value: ee,
}),
info: ne({}, m, {
value: ue,
}),
warn: ne({}, m, {
value: be,
}),
error: ne({}, m, {
value: Se,
}),
group: ne({}, m, {
value: u,
}),
groupCollapsed: ne({}, m, {
value: A,
}),
groupEnd: ne({}, m, {
value: N,
}),
});
}
D < 0 &&
F(
"disabledDepth fell below zero. This is a bug in React. Please file an issue.",
);
}
}
var L = v.ReactCurrentDispatcher,
U;
function H(m, S, R) {
{
if (U === void 0)
try {
throw Error();
} catch (se) {
var Y = se.stack.trim().match(/\n( *(at )?)/);
U = (Y && Y[1]) || "";
}
return (
`
` +
U +
m
);
}
}
var K = !1,
W;
{
var ve = typeof WeakMap == "function" ? WeakMap : Map;
W = new ve();
}
function O(m, S) {
if (!m || K) return "";
{
var R = W.get(m);
if (R !== void 0) return R;
}
var Y;
K = !0;
var se = Error.prepareStackTrace;
Error.prepareStackTrace = void 0;
var me;
(me = L.current), (L.current = null), B();
try {
if (S) {
var ie = function () {
throw Error();
};
if (
(Object.defineProperty(ie.prototype, "props", {
set: function () {
throw Error();
},
}),
typeof Reflect == "object" && Reflect.construct)
) {
try {
Reflect.construct(ie, []);
} catch (We) {
Y = We;
}
Reflect.construct(m, [], ie);
} else {
try {
ie.call();
} catch (We) {
Y = We;
}
m.call(ie.prototype);
}
} else {
try {
throw Error();
} catch (We) {
Y = We;
}
m();
}
} catch (We) {
if (We && Y && typeof We.stack == "string") {
for (
var re = We.stack.split(`
`),
Te = Y.stack.split(`
`),
we = re.length - 1,
ke = Te.length - 1;
we >= 1 && ke >= 0 && re[we] !== Te[ke];
)
ke--;
for (; we >= 1 && ke >= 0; we--, ke--)
if (re[we] !== Te[ke]) {
if (we !== 1 || ke !== 1)
do
if ((we--, ke--, ke < 0 || re[we] !== Te[ke])) {
var Me =
`
` + re[we].replace(" at new ", " at ");
return (
m.displayName &&
Me.includes("<anonymous>") &&
(Me = Me.replace("<anonymous>", m.displayName)),
typeof m == "function" && W.set(m, Me),
Me
);
}
while (we >= 1 && ke >= 0);
break;
}
}
} finally {
(K = !1), (L.current = me), Q(), (Error.prepareStackTrace = se);
}
var rn = m ? m.displayName || m.name : "",
Rt = rn ? H(rn) : "";
return typeof m == "function" && W.set(m, Rt), Rt;
}
function Ce(m, S, R) {
return O(m, !1);
}
function j(m) {
var S = m.prototype;
return !!(S && S.isReactComponent);
}
function Oe(m, S, R) {
if (m == null) return "";
if (typeof m == "function") return O(m, j(m));
if (typeof m == "string") return H(m);
switch (m) {
case c:
return H("Suspense");
case f:
return H("SuspenseList");
}
if (typeof m == "object")
switch (m.$$typeof) {
case s:
return Ce(m.render);
case p:
return Oe(m.type, S, R);
case g: {
var Y = m,
se = Y._payload,
me = Y._init;
try {
return Oe(me(se), S, R);
} catch {}
}
}
return "";
}
var Le = Object.prototype.hasOwnProperty,
Ye = {},
cn = v.ReactDebugCurrentFrame;
function nn(m) {
if (m) {
var S = m._owner,
R = Oe(m.type, m._source, S ? S.type : null);
cn.setExtraStackFrame(R);
} else cn.setExtraStackFrame(null);
}
function kn(m, S, R, Y, se) {
{
var me = Function.call.bind(Le);
for (var ie in m)
if (me(m, ie)) {
var re = void 0;
try {
if (typeof m[ie] != "function") {
var Te = Error(
(Y || "React class") +
": " +
R +
" type `" +
ie +
"` is invalid; it must be a function, usually from the `prop-types` package, but received `" +
typeof m[ie] +
"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.",
);
throw ((Te.name = "Invariant Violation"), Te);
}
re = m[ie](
S,
ie,
Y,
R,
null,
"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED",
);
} catch (we) {
re = we;
}
re &&
!(re instanceof Error) &&
(nn(se),
F(
"%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",
Y || "React class",
R,
ie,
typeof re,
),
nn(null)),
re instanceof Error &&
!(re.message in Ye) &&
((Ye[re.message] = !0),
nn(se),
F("Failed %s type: %s", R, re.message),
nn(null));
}
}
}
var En = Array.isArray;
function fn(m) {
return En(m);
}
function Ln(m) {
{
var S = typeof Symbol == "function" && Symbol.toStringTag,
R =
(S && m[Symbol.toStringTag]) ||
m.constructor.name ||
"Object";
return R;
}
}
function Mn(m) {
try {
return Sn(m), !1;
} catch {
return !0;
}
}
function Sn(m) {
return "" + m;
}
function Cn(m) {
if (Mn(m))
return (
F(
"The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",
Ln(m),
),
Sn(m)
);
}
var w = v.ReactCurrentOwner,
P = {
key: !0,
ref: !0,
__self: !0,
__source: !0,
},
$,
le,
oe;
oe = {};
function Re(m) {
if (Le.call(m, "ref")) {
var S = Object.getOwnPropertyDescriptor(m, "ref").get;
if (S && S.isReactWarning) return !1;
}
return m.ref !== void 0;
}
function Ue(m) {
if (Le.call(m, "key")) {
var S = Object.getOwnPropertyDescriptor(m, "key").get;
if (S && S.isReactWarning) return !1;
}
return m.key !== void 0;
}
function Ne(m, S) {
if (
typeof m.ref == "string" &&
w.current &&
S &&
w.current.stateNode !== S
) {
var R = G(w.current.type);
oe[R] ||
(F(
'Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',
G(w.current.type),
m.ref,
),
(oe[R] = !0));
}
}
function Ke(m, S) {
{
var R = function () {
$ ||
(($ = !0),
F(
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",
S,
));
};
(R.isReactWarning = !0),
Object.defineProperty(m, "key", {
get: R,
configurable: !0,
});
}
}
function Je(m, S) {
{
var R = function () {
le ||
((le = !0),
F(
"%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",
S,
));
};
(R.isReactWarning = !0),
Object.defineProperty(m, "ref", {
get: R,
configurable: !0,
});
}
}
var xe = function (m, S, R, Y, se, me, ie) {
var re = {
// This tag allows us to uniquely identify this as a React Element
$$typeof: n,
// Built-in properties that belong on the element
type: m,
key: S,
ref: R,
props: ie,
// Record the component responsible for creating this element.
_owner: me,
};
return (
(re._store = {}),
Object.defineProperty(re._store, "validated", {
configurable: !1,
enumerable: !1,
writable: !0,
value: !1,
}),
Object.defineProperty(re, "_self", {
configurable: !1,
enumerable: !1,
writable: !1,
value: Y,
}),
Object.defineProperty(re, "_source", {
configurable: !1,
enumerable: !1,
writable: !1,
value: se,
}),
Object.freeze && (Object.freeze(re.props), Object.freeze(re)),
re
);
};
function pn(m, S, R, Y, se) {
{
var me,
ie = {},
re = null,
Te = null;
R !== void 0 && (Cn(R), (re = "" + R)),
Ue(S) && (Cn(S.key), (re = "" + S.key)),
Re(S) && ((Te = S.ref), Ne(S, se));
for (me in S)
Le.call(S, me) && !P.hasOwnProperty(me) && (ie[me] = S[me]);
if (m && m.defaultProps) {
var we = m.defaultProps;
for (me in we) ie[me] === void 0 && (ie[me] = we[me]);
}
if (re || Te) {
var ke =
typeof m == "function"
? m.displayName || m.name || "Unknown"
: m;
re && Ke(ie, ke), Te && Je(ie, ke);
}
return xe(m, re, Te, se, Y, w.current, ie);
}
}
var _e = v.ReactCurrentOwner,
St = v.ReactDebugCurrentFrame;
function tn(m) {
if (m) {
var S = m._owner,
R = Oe(m.type, m._source, S ? S.type : null);
St.setExtraStackFrame(R);
} else St.setExtraStackFrame(null);
}
var zn;
zn = !1;
function jn(m) {
return typeof m == "object" && m !== null && m.$$typeof === n;
}
function Ct() {
{
if (_e.current) {
var m = G(_e.current.type);
if (m)
return (
`
Check the render method of \`` +
m +
"`."
);
}
return "";
}
}
function ki(m) {
return "";
}
var Tt = {};
function Ei(m) {
{
var S = Ct();
if (!S) {
var R = typeof m == "string" ? m : m.displayName || m.name;
R &&
(S =
`
Check the top-level render call using <` +
R +
">.");
}
return S;
}
}
function Pt(m, S) {
{
if (!m._store || m._store.validated || m.key != null) return;
m._store.validated = !0;
var R = Ei(S);
if (Tt[R]) return;
Tt[R] = !0;
var Y = "";
m &&
m._owner &&
m._owner !== _e.current &&
(Y = " It was passed a child from " + G(m._owner.type) + "."),
tn(m),
F(
'Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',
R,
Y,
),
tn(null);
}
}
function At(m, S) {
{
if (typeof m != "object") return;
if (fn(m))
for (var R = 0; R < m.length; R++) {
var Y = m[R];
jn(Y) && Pt(Y, S);
}
else if (jn(m)) m._store && (m._store.validated = !0);
else if (m) {
var se = x(m);
if (typeof se == "function" && se !== m.entries)
for (var me = se.call(m), ie; !(ie = me.next()).done; )
jn(ie.value) && Pt(ie.value, S);
}
}
}
function Si(m) {
{
var S = m.type;
if (S == null || typeof S == "string") return;
var R;
if (typeof S == "function") R = S.propTypes;
else if (
typeof S == "object" &&
(S.$$typeof === s || // Note: Memo only checks outer props here.
// Inner props are checked in the reconciler.
S.$$typeof === p)
)
R = S.propTypes;
else return;
if (R) {
var Y = G(S);
kn(R, m.props, "prop", Y, m);
} else if (S.PropTypes !== void 0 && !zn) {
zn = !0;
var se = G(S);
F(
"Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",
se || "Unknown",
);
}
typeof S.getDefaultProps == "function" &&
!S.getDefaultProps.isReactClassApproved &&
F(
"getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.",
);
}
}
function Ci(m) {
{
for (var S = Object.keys(m.props), R = 0; R < S.length; R++) {
var Y = S[R];
if (Y !== "children" && Y !== "key") {
tn(m),
F(
"Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",
Y,
),
tn(null);
break;
}
}
m.ref !== null &&
(tn(m),
F("Invalid attribute `ref` supplied to `React.Fragment`."),
tn(null));
}
}
function Ot(m, S, R, Y, se, me) {
{
var ie = de(m);
if (!ie) {
var re = "";
(m === void 0 ||
(typeof m == "object" &&
m !== null &&
Object.keys(m).length === 0)) &&
(re +=
" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");
var Te = ki();
Te ? (re += Te) : (re += Ct());
var we;
m === null
? (we = "null")
: fn(m)
? (we = "array")
: m !== void 0 && m.$$typeof === n
? ((we = "<" + (G(m.type) || "Unknown") + " />"),
(re =
" Did you accidentally export a JSX literal instead of a component?"))
: (we = typeof m),
F(
"React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",
we,
re,
);
}
var ke = pn(m, S, R, se, me);
if (ke == null) return ke;
if (ie) {
var Me = S.children;
if (Me !== void 0)
if (Y)
if (fn(Me)) {
for (var rn = 0; rn < Me.length; rn++) At(Me[rn], m);
Object.freeze && Object.freeze(Me);
} else
F(
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.",
);
else At(Me, m);
}
return m === r ? Ci(ke) : Si(ke), ke;
}
}
function Ti(m, S, R) {
return Ot(m, S, R, !0);
}
function Pi(m, S, R) {
return Ot(m, S, R, !1);
}
var Ai = Pi,
Oi = Ti;
(dn.Fragment = r), (dn.jsx = Ai), (dn.jsxs = Oi);
})()),
dn
);
}
process.env.NODE_ENV === "production"
? (nt.exports = Fi())
: (nt.exports = Di());
var te = nt.exports;
const Li = (e) =>
/* @__PURE__ */ Fe.createElement(
"svg",
{ xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", ...e },
/* @__PURE__ */ Fe.createElement("path", {
d: "M16.293 9.293 12 13.586 7.707 9.293l-1.414 1.414L12 16.414l5.707-5.707z",
}),
/* @__PURE__ */ Fe.createElement("path", {
d: "M16.293 9.293 12 13.586 7.707 9.293l-1.414 1.414L12 16.414l5.707-5.707z",
}),
),
Ir = (e) =>
/* @__PURE__ */ Fe.createElement(
"svg",
{
viewBox: "0 0 24 24",
xmlns: "http://www.w3.org/2000/svg",
fill: "none",
...e,
},
/* @__PURE__ */ Fe.createElement("path", {
d: "M12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2C6.47715 2 2 6.47715 2 12C2 13.5997 2.37562 15.1116 3.04346 16.4525C3.22094 16.8088 3.28001 17.2161 3.17712 17.6006L2.58151 19.8267C2.32295 20.793 3.20701 21.677 4.17335 21.4185L6.39939 20.8229C6.78393 20.72 7.19121 20.7791 7.54753 20.9565C8.88837 21.6244 10.4003 22 12 22Z",
fill: "#ff6d2a",
}),
/* @__PURE__ */ Fe.createElement("path", {
d: "M15 12C15 12.5523 15.4477 13 16 13C16.5523 13 17 12.5523 17 12C17 11.4477 16.5523 11 16 11C15.4477 11 15 11.4477 15 12Z",
fill: "#5c99d2",
}),
/* @__PURE__ */ Fe.createElement("path", {
d: "M11 12C11 12.5523 11.4477 13 12 13C12.5523 13 13 12.5523 13 12C13 11.4477 12.5523 11 12 11C11.4477 11 11 11.4477 11 12Z",
fill: "#5c99d2",
}),
/* @__PURE__ */ Fe.createElement("path", {
d: "M7 12C7 12.5523 7.44772 13 8 13C8.55228 13 9 12.5523 9 12C9 11.4477 8.55228 11 8 11C7.44772 11 7 11.4477 7 12Z",
fill: "#5c99d2",
}),
),
Fr = (e) =>
/* @__PURE__ */ Fe.createElement(
"svg",
{
xmlns: "http://www.w3.org/2000/svg",
viewBox: "0 0 24 24",
fill: "#474747",
...e,
},
/* @__PURE__ */ Fe.createElement("path", {
d: "M16 14h.5c.827 0 1.5-.673 1.5-1.5v-9c0-.827-.673-1.5-1.5-1.5h-13C2.673 2 2 2.673 2 3.5V18l5.333-4H16zm-9.333-2L4 14V4h12v8H6.667z",
}),
/* @__PURE__ */ Fe.createElement("path", {
d: "M20.5 8H20v6.001c0 1.1-.893 1.993-1.99 1.999H8v.5c0 .827.673 1.5 1.5 1.5h7.167L22 22V9.5c0-.827-.673-1.5-1.5-1.5z",
}),
),
Mi = (e) =>
/* @__PURE__ */ Fe.createElement(
"svg",
{ xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", ...e },
/* @__PURE__ */ Fe.createElement("path", {
d: "M11 8.414V18h2V8.414l4.293 4.293 1.414-1.414L12 4.586l-6.707 6.707 1.414 1.414z",
}),
);
var Dr = { exports: {} };
/*!
Copyright (c) 2018 Jed Watson.
Licensed under the MIT License (MIT), see
http://jedwatson.github.io/classnames
*/
(function (e) {
(function () {
var n = {}.hasOwnProperty;
function t() {
for (var l = "", o = 0; o < arguments.length; o++) {
var a = arguments[o];
a && (l = i(l, r(a)));
}
return l;
}
function r(l) {
if (typeof l == "string" || typeof l == "number") return l;
if (typeof l != "object") return "";
if (Array.isArray(l)) return t.apply(null, l);
if (
l.toString !== Object.prototype.toString &&
!l.toString.toString().includes("[native code]")
)
return l.toString();
var o = "";
for (var a in l) n.call(l, a) && l[a] && (o = i(o, a));
return o;
}
function i(l, o) {
return o ? (l ? l + " " + o : l + o) : l;
}
e.exports ? ((t.default = t), (e.exports = t)) : (window.classNames = t);
})();
})(Dr);
var zi = Dr.exports;
const $e = /* @__PURE__ */ an(zi),
On = (e) => ({
Authorization: e ?? "",
"Content-Type": "application/json",
}),
ji = {
getMessages: async (e, n, t) => {
const r = await fetch(`${t}/api/threads/${e}/messages`, {
headers: On(n),
});
if (!r.ok) throw new Error("Failed to fetch messages");
return (await r.json()).messages;
},
},
Lr = {
createThread: async (e, n) => {
const t = await fetch(`${n}/api/threads`, {
method: "POST",
headers: On(e),
});
if (!t.ok) throw new Error("Failed to create thread");
return await t.json();
},
deleteThread: async (e, n, t) => {
if (
!(
await fetch(`${t}/api/threads/${e}`, {
method: "DELETE",
headers: On(n),
})
).ok
)
throw new Error("Failed to delete thread");
},
createMessage: async (e, n, t, r) => {
const i = await fetch(`${r}/api/threads/${e}/messages`, {
method: "POST",
headers: On(t),
body: JSON.stringify({ content: n }),
});
if (!i.ok) throw new Error("Failed to create message");
return await i.json();
},
},
Bi = {
content: "",
role: "assistant",
isWaiting: !0,
},
Mr = {
content: "How can I help you?",
role: "assistant",
},
Ni = (e, n) => {
const [t, r] = gn(""),
[i, l] = gn([]),
[o, a] = gn(!1),
{ apiUrl: s, welcomeMessage: c } = bn(),
f = async () => {
a(!0);
try {
const g = await ji.getMessages(e, n, s);
l([...g, c]);
} catch (g) {
console.error("Failed to fetch messages:", g),
l([{ content: "Server error", role: "system" }, ...i]);
} finally {
a(!1);
}
},
p = async (g) => {
a(!0);
try {
l([Bi, { content: g, role: "user" }, ...i]),
r(""),
await Lr.createMessage(e, g, n, s),
await f();
} catch (d) {
console.error("Failed to create message:", d),
l([{ content: "Server error", role: "system" }, ...i]);
} finally {
a(!1);
}
};
return (
ht(() => {
f();
}, [e]),
{
messages: i,
createMessage: p,
message: t,
setMessage: r,
isLoading: o,
}
);
},
zr = Ri({
logo: Ir,
toggleButtonIcon: Fr,
placeholder: "Let's talk",
welcomeMessage: Mr,
}),
$i = (e) => {
const { children: n } = e;
return /* @__PURE__ */ te.jsx(zr.Provider, { value: e, children: n });
},
bn = () => _i(zr),
Ui = ({ threadId: e, token: n }) => {
const [t, r] = gn(!1),
i = _t(null),
l = _t(null),
{
messages: o,
createMessage: a,
message: s,
setMessage: c,
isLoading: f,
} = Ni(e, n),
{
chatToggleButtonClassName: p,
chatMainClassName: g,
topBarClassName: d,
chatName: E,
conversationClassName: y,
inputSectionClassName: x,
placeholder: v,
toggleButtonIcon: F,
logo: C,
} = bn(),
z = (D) => {
c(D.target.value);
},
k = async (D) => {
var ee;
D.preventDefault(),
!(s.trim() === "" || f) &&
(await a(s), (ee = i.current) == null || ee.focus());
},
b = (D) => {
D.code === "Escape" && r((ee) => !ee), D.code === "Enter" && k(D);
},
M = () => {
var D;
r((ee) => !ee), (D = i.current) == null || D.focus();
},
q = () =>
o
? o
.slice()
.reverse()
.map((D, ee) => /* @__PURE__ */ te.jsx(ls, { ...D }, D.role + ee))
: null,
Z = () => {
const D = l.current;
D && D.scrollIntoView({ behavior: "smooth" });
};
ht(() => {
Z();
}, [o]);
const de = $e(
"chat-transition-toggle-menu chat-shadow-gray-950 chat-fixed chat-flex chat-cursor-pointer chat-items-center chat-justify-center chat-rounded-full chat-bg-white chat-p-0 chat-shadow-2xl chat-z-[101]",
p,
{
"chat-bottom-[-50px] chat-right-[-50px] chat-h-2 chat-w-2 chat-opacity-0":
t,
"chat-bottom-5 chat-right-4 chat-h-[60px] chat-w-[60px] chat-opacity-100":
!t,
},
),
_ = $e(
`chat-chatbox-scroll chat-max-h-[500px] chat-shadow-gray-950 chat-transition-chatbox chat-fixed chat-w-full chat-overflow-hidden chat-rounded-t-xl chat-right-0 chat-bg-white chat-max-w-[350px] chat-shadow-xl chat-z-[101] lg:chat-max-w-[50vw] lg:chat-max-h-[60vh] ${g}`,
{
"chat-bottom-0 chat-h-full chat-w-full chat-opacity-100": t,
"chat-bottom-[-60px] chat-h-10 chat-opacity-0": !t,
},
),
I = $e(
"chat-flex chat-h-[70px] chat-items-center chat-justify-between chat-pl-1 chat-shadow-md",
d,
),
G = $e(
"chat-m-0 chat-flex chat-h-[calc(100%-130px)] chat-min-h-0 chat-flex-col chat-overflow-y-auto chat-p-0",
y,
),
ne = $e("chat-absolute chat-bottom-3 chat-w-full", x);
return /* @__PURE__ */ te.jsxs(te.Fragment, {
children: [
/* @__PURE__ */ te.jsx("div", {
className: de,
onClick: M,
role: "button",
tabIndex: 0,
"aria-label": "Toggle chatbox",
children: /* @__PURE__ */ te.jsx(F, { width: 35 }),
}),
/* @__PURE__ */ te.jsxs("div", {
className: _,
children: [
/* @__PURE__ */ te.jsxs("div", {
className: I,
children: [
/* @__PURE__ */ te.jsxs("div", {
className: "chat-flex chat-items-center chat-p-2",
children: [
/* @__PURE__ */ te.jsx(C, { width: 35 }),
/* @__PURE__ */ te.jsx("div", {
className: "chat-ml-2",
children: /* @__PURE__ */ te.jsx("h3", {
className:
"chat-m-0 chat-p-0 chat-text-2xl chat-font-medium chat-text-gray",
children: E,
}),
}),
],
}),
/* @__PURE__ */ te.jsx("button", {
className:
"chat-absolute chat-right-2 chat-top-4 chat-flex chat-h-10 chat-w-10 chat-cursor-pointer chat-items-center chat-justify-center chat-rounded-full chat-bg-transparent chat-p-0",
onClick: () => r((D) => !D),
children: /* @__PURE__ */ te.jsx(Li, {
fill: "black",
width: 30,
}),
}),
],
}),
/* @__PURE__ */ te.jsxs("div", {
className: G,
children: [q(), /* @__PURE__ */ te.jsx("div", { ref: l })],
}),
/* @__PURE__ */ te.jsx("div", {
className: ne,
children: /* @__PURE__ */ te.jsxs("form", {
autoComplete: "off",
className:
"chat-mx-4 chat-my-0 chat-flex chat-h-11 chat-items-center chat-overflow-hidden chat-rounded-full chat-bg-gray chat-bg-opacity-10",
onSubmit: k,
children: [
/* @__PURE__ */ te.jsx("input", {
className:
"chat-h-full chat-w-full chat-resize-none chat-border-none chat-bg-transparent chat-pl-4 chat-text-base chat-font-normal chat-text-black chat-outline-none chat-ring-0 focus:chat-border-none focus:chat-outline-none focus:chat-ring-0",
type: "text",
name: "message",
id: "message",
ref: i,
placeholder: v,
value: s,
onChange: z,
onKeyUp: b,
"aria-label": "Chat message input",
}),
/* @__PURE__ */ te.jsx("button", {
className:
"chat-mr-1 chat-flex chat-h-9 chat-w-11 chat-items-center chat-justify-center chat-rounded-full chat-border-none chat-bg-gray chat-bg-opacity-20 chat-p-0 chat-font-body hover:chat-bg-opacity-30",
disabled: f,
type: "submit",
"aria-label": "Send message",
children: /* @__PURE__ */ te.jsx(Mi, {
fill: "black",
width: 30,
}),
}),
],
}),
}),
],
}),
],
});
},
Hi = () => {
const [e, n] = gn(localStorage.getItem("threadId")),
{ apiUrl: t, token: r } = bn(),
i = (l) => {
if (l) {
n(l), localStorage.setItem("threadId", l);
return;
}
n(null), localStorage.removeItem("threadId");
};
return (
ht(() => {
e ||
(async () => {
try {
const o = await Lr.createThread(r, t);
i(o.threadId);
} catch (o) {
console.error("Failed to create thread:", o);
}
})();
}, [t, e, r]),
e ? /* @__PURE__ */ te.jsx(Ui, { threadId: e, token: r }) : null
);
},
Dt = ["http", "https", "mailto", "tel"];
function Vi(e) {
const n = (e || "").trim(),
t = n.charAt(0);
if (t === "#" || t === "/") return n;
const r = n.indexOf(":");
if (r === -1) return n;
let i = -1;
for (; ++i < Dt.length; ) {
const l = Dt[i];
if (r === l.length && n.slice(0, l.length).toLowerCase() === l) return n;
}
return (
(i = n.indexOf("?")),
(i !== -1 && r > i) || ((i = n.indexOf("#")), i !== -1 && r > i)
? n
: "javascript:void(0)"
);
}
/*!
* Determine if an object is a Buffer
*
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/
var qi = function (n) {
return (
n != null &&
n.constructor != null &&
typeof n.constructor.isBuffer == "function" &&
n.constructor.isBuffer(n)
);
};
const jr = /* @__PURE__ */ an(qi);
function yn(e) {
return !e || typeof e != "object"
? ""
: "position" in e || "type" in e
? Lt(e.position)
: "start" in e || "end" in e
? Lt(e)
: "line" in e || "column" in e
? tt(e)
: "";
}
function tt(e) {
return Mt(e && e.line) + ":" + Mt(e && e.column);
}
function Lt(e) {
return tt(e && e.start) + "-" + tt(e && e.end);
}
function Mt(e) {
return e && typeof e == "number" ? e : 1;
}
class je extends Error {
/**
* Create a message for `reason` at `place` from `origin`.
*
* When an error is passed in as `reason`, the `stack` is copied.
*
* @param {string | Error | VFileMessage} reason
* Reason for message, uses the stack and message of the error if given.
*
* > 👉 **Note**: you should use markdown.
* @param {Node | NodeLike | Position | Point | null | undefined} [place]
* Place in file where the message occurred.
* @param {string | null | undefined} [origin]
* Place in code where the message originates (example:
* `'my-package:my-rule'` or `'my-rule'`).
* @returns
* Instance of `VFileMessage`.
*/
// To do: next major: expose `undefined` everywhere instead of `null`.
constructor(n, t, r) {
const i = [null, null];
let l = {
// @ts-expect-error: we always follows the structure of `position`.
start: { line: null, column: null },
// @ts-expect-error: "
end: { line: null, column: null },
};
if (
(super(),
typeof t == "string" && ((r = t), (t = void 0)),
typeof r == "string")
) {
const o = r.indexOf(":");
o === -1 ? (i[1] = r) : ((i[0] = r.slice(0, o)), (i[1] = r.slice(o + 1)));
}
t &&
("type" in t || "position" in t
? t.position && (l = t.position)
: "start" in t || "end" in t
? (l = t)
: ("line" in t || "column" in t) && (l.start = t)),
(this.name = yn(t) || "1:1"),
(this.message = typeof n == "object" ? n.message : n),
(this.stack = ""),
typeof n == "object" && n.stack && (this.stack = n.stack),
(this.reason = this.message),
this.fatal,
(this.line = l.start.line),
(this.column = l.start.column),
(this.position = l),
(this.source = i[0]),
(this.ruleId = i[1]),
this.file,
this.actual,
this.expected,
this.url,
this.note;
}
}
je.prototype.file = "";
je.prototype.name = "";
je.prototype.reason = "";
je.prototype.message = "";
je.prototype.stack = "";
je.prototype.fatal = null;
je.prototype.column = null;
je.prototype.line = null;
je.prototype.source = null;
je.prototype.ruleId = null;
je.prototype.position = null;
const He = { basename: Wi, dirname: Yi, extname: Xi, join: Qi, sep: "/" };
function Wi(e, n) {
if (n !== void 0 && typeof n != "string")
throw new TypeError('"ext" argument must be a string');
vn(e);
let t = 0,
r = -1,
i = e.length,
l;
if (n === void 0 || n.length === 0 || n.length > e.length) {
for (; i--; )
if (e.charCodeAt(i) === 47) {
if (l) {
t = i + 1;
break;
}
} else r < 0 && ((l = !0), (r = i + 1));
return r < 0 ? "" : e.slice(t, r);
}
if (n === e) return "";
let o = -1,
a = n.length - 1;
for (; i--; )
if (e.charCodeAt(i) === 47) {
if (l) {
t = i + 1;
break;
}
} else
o < 0 && ((l = !0), (o = i + 1)),
a > -1 &&
(e.charCodeAt(i) === n.charCodeAt(a--)
? a < 0 && (r = i)
: ((a = -1), (r = o)));
return t === r ? (r = o) : r < 0 && (r = e.length), e.slice(t, r);
}
function Yi(e) {
if ((vn(e), e.length === 0)) return ".";
let n = -1,
t = e.length,
r;
for (; --t; )
if (e.charCodeAt(t) === 47) {
if (r) {
n = t;
break;
}
} else r || (r = !0);
return n < 0
? e.charCodeAt(0) === 47
? "/"
: "."
: n === 1 && e.charCodeAt(0) === 47
? "//"
: e.slice(0, n);
}
function Xi(e) {
vn(e);
let n = e.length,
t = -1,
r = 0,
i = -1,
l = 0,
o;
for (; n--; ) {
const a = e.charCodeAt(n);
if (a === 47) {
if (o) {
r = n + 1;
break;
}
continue;
}
t < 0 && ((o = !0), (t = n + 1)),
a === 46 ? (i < 0 ? (i = n) : l !== 1 && (l = 1)) : i > -1 && (l = -1);
}
return i < 0 ||
t < 0 || // We saw a non-dot character immediately before the dot.
l === 0 || // The (right-most) trimmed path component is exactly `..`.
(l === 1 && i === t - 1 && i === r + 1)
? ""
: e.slice(i, t);
}
function Qi(...e) {
let n = -1,
t;
for (; ++n < e.length; )
vn(e[n]), e[n] && (t = t === void 0 ? e[n] : t + "/" + e[n]);
return t === void 0 ? "." : Gi(t);
}
function Gi(e) {
vn(e);
const n = e.charCodeAt(0) === 47;
let t = Ki(e, !n);
return (
t.length === 0 && !n && (t = "."),
t.length > 0 && e.charCodeAt(e.length - 1) === 47 && (t += "/"),
n ? "/" + t : t
);
}
function Ki(e, n) {
let t = "",
r = 0,
i = -1,
l = 0,
o = -1,
a,
s;
for (; ++o <= e.length; ) {
if (o < e.length) a = e.charCodeAt(o);
else {
if (a === 47) break;
a = 47;
}
if (a === 47) {
if (!(i === o - 1 || l === 1))
if (i !== o - 1 && l === 2) {
if (
t.length < 2 ||
r !== 2 ||
t.charCodeAt(t.length - 1) !== 46 ||
t.charCodeAt(t.length - 2) !== 46
) {
if (t.length > 2) {
if (((s = t.lastIndexOf("/")), s !== t.length - 1)) {
s < 0
? ((t = ""), (r = 0))
: ((t = t.slice(0, s)),
(r = t.length - 1 - t.lastIndexOf("/"))),
(i = o),
(l = 0);
continue;
}
} else if (t.length > 0) {
(t = ""), (r = 0), (i = o), (l = 0);
continue;
}
}
n && ((t = t.length > 0 ? t + "/.." : ".."), (r = 2));
} else
t.length > 0
? (t += "/" + e.slice(i + 1, o))
: (t = e.slice(i + 1, o)),
(r = o - i - 1);
(i = o), (l = 0);
} else a === 46 && l > -1 ? l++ : (l = -1);
}
return t;
}
function vn(e) {
if (typeof e != "string")
throw new TypeError("Path must be a string. Received " + JSON.stringify(e));
}
const Ji = { cwd: Zi };
function Zi() {
return "/";
}
function rt(e) {
return (
e !== null &&
typeof e == "object" && // @ts-expect-error: indexable.
e.href && // @ts-expect-error: indexable.
e.origin
);
}
function el(e) {
if (typeof e == "string") e = new URL(e);
else if (!rt(e)) {
const n = new TypeError(
'The "path" argument must be of type string or an instance of URL. Received `' +
e +
"`",
);
throw ((n.code = "ERR_INVALI