UNPKG

widget-chatbot

Version:

- [![React][react.js]][react-url] - [![Socket-io][socket-io-img]][socket-io-url] - [![Chart.js][chart.js-img]][chart.js-url]

1,562 lines (1,558 loc) 224 kB
import ot, { version as Lr, createContext as He, useContext as Ue, useState as H, useRef as se, useMemo as z, useEffect as ge, memo as Y, Fragment as pt, Children as Mr, isValidElement as Nr, cloneElement as Fr, createElement as Ht, useCallback as Ir } from "react"; import Je from "axios"; import Se from "dayjs"; import { version as $r, Modal as un, Collapse as dn, Typography as ce, Button as le, Form as Ce, notification as Te, Radio as Hr, Divider as Ur, Input as st, Image as Wr, Skeleton as _e, Avatar as Un, Upload as Wn, Spin as Br, Tooltip as Ke, Tag as Yr, Badge as Vr, Grid as Re, Empty as Bn, Popover as Ut, Mentions as fn, Select as gn, DatePicker as zr, Result as Gr, Tabs as wt } from "antd"; import { io as qr } from "socket.io-client"; import Kr from "react-markdown"; import Pr from "remark-gfm"; import { Prism as Xr } from "react-syntax-highlighter"; import Jr from "@ant-design/icons"; import { Pie as Zr } from "@ant-design/charts"; import Ve from "crypto-js"; import { Picker as Qr } from "emoji-mart"; import Yn from "react-dom"; function eo(e) { return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e; } var lt = { exports: {} }, ze = {}; /* object-assign (c) Sindre Sorhus @license MIT */ var _t, pn; function Wt() { if (pn) return _t; pn = 1; var e = Object.getOwnPropertySymbols, n = Object.prototype.hasOwnProperty, o = Object.prototype.propertyIsEnumerable; function r(s) { if (s == null) throw new TypeError("Object.assign cannot be called with null or undefined"); return Object(s); } function a() { try { if (!Object.assign) return !1; var s = new String("abc"); if (s[5] = "de", Object.getOwnPropertyNames(s)[0] === "5") return !1; for (var i = {}, c = 0; c < 10; c++) i["_" + String.fromCharCode(c)] = c; var l = Object.getOwnPropertyNames(i).map(function(h) { return i[h]; }); if (l.join("") !== "0123456789") return !1; var x = {}; return "abcdefghijklmnopqrst".split("").forEach(function(h) { x[h] = h; }), Object.keys(Object.assign({}, x)).join("") === "abcdefghijklmnopqrst"; } catch { return !1; } } return _t = a() ? Object.assign : function(s, i) { for (var c, l = r(s), x, h = 1; h < arguments.length; h++) { c = Object(arguments[h]); for (var p in c) n.call(c, p) && (l[p] = c[p]); if (e) { x = e(c); for (var f = 0; f < x.length; f++) o.call(c, x[f]) && (l[x[f]] = c[x[f]]); } } return l; }, _t; } /** @license React v17.0.2 * 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 xn; function to() { if (xn) return ze; xn = 1, Wt(); var e = ot, n = 60103; if (ze.Fragment = 60107, typeof Symbol == "function" && Symbol.for) { var o = Symbol.for; n = o("react.element"), ze.Fragment = o("react.fragment"); } var r = e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, a = Object.prototype.hasOwnProperty, s = { key: !0, ref: !0, __self: !0, __source: !0 }; function i(c, l, x) { var h, p = {}, f = null, m = null; x !== void 0 && (f = "" + x), l.key !== void 0 && (f = "" + l.key), l.ref !== void 0 && (m = l.ref); for (h in l) a.call(l, h) && !s.hasOwnProperty(h) && (p[h] = l[h]); if (c && c.defaultProps) for (h in l = c.defaultProps, l) p[h] === void 0 && (p[h] = l[h]); return { $$typeof: n, type: c, key: f, ref: m, props: p, _owner: r.current }; } return ze.jsx = i, ze.jsxs = i, ze; } var jt = {}; /** @license React v17.0.2 * 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 hn; function no() { return hn || (hn = 1, function(e) { process.env.NODE_ENV !== "production" && function() { var n = ot, o = Wt(), r = 60103, a = 60106; e.Fragment = 60107; var s = 60108, i = 60114, c = 60109, l = 60110, x = 60112, h = 60113, p = 60120, f = 60115, m = 60116, j = 60121, T = 60122, S = 60117, C = 60129, E = 60131; if (typeof Symbol == "function" && Symbol.for) { var y = Symbol.for; r = y("react.element"), a = y("react.portal"), e.Fragment = y("react.fragment"), s = y("react.strict_mode"), i = y("react.profiler"), c = y("react.provider"), l = y("react.context"), x = y("react.forward_ref"), h = y("react.suspense"), p = y("react.suspense_list"), f = y("react.memo"), m = y("react.lazy"), j = y("react.block"), T = y("react.server.block"), S = y("react.fundamental"), y("react.scope"), y("react.opaque.id"), C = y("react.debug_trace_mode"), y("react.offscreen"), E = y("react.legacy_hidden"); } var w = typeof Symbol == "function" && Symbol.iterator, d = "@@iterator"; function v(g) { if (g === null || typeof g != "object") return null; var A = w && g[w] || g[d]; return typeof A == "function" ? A : null; } var u = n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; function b(g) { { for (var A = arguments.length, N = new Array(A > 1 ? A - 1 : 0), q = 1; q < A; q++) N[q - 1] = arguments[q]; k("error", g, N); } } function k(g, A, N) { { var q = u.ReactDebugCurrentFrame, fe = q.getStackAddendum(); fe !== "" && (A += "%s", N = N.concat([fe])); var de = N.map(function(oe) { return "" + oe; }); de.unshift("Warning: " + A), Function.prototype.apply.call(console[g], console, de); } } var D = !1; function R(g) { return !!(typeof g == "string" || typeof g == "function" || g === e.Fragment || g === i || g === C || g === s || g === h || g === p || g === E || D || typeof g == "object" && g !== null && (g.$$typeof === m || g.$$typeof === f || g.$$typeof === c || g.$$typeof === l || g.$$typeof === x || g.$$typeof === S || g.$$typeof === j || g[0] === T)); } function U(g, A, N) { var q = A.displayName || A.name || ""; return g.displayName || (q !== "" ? N + "(" + q + ")" : N); } function $(g) { return g.displayName || "Context"; } function V(g) { if (g == null) return null; if (typeof g.tag == "number" && b("Received an unexpected object in getComponentName(). This is likely a bug in React. Please file an issue."), typeof g == "function") return g.displayName || g.name || null; if (typeof g == "string") return g; switch (g) { case e.Fragment: return "Fragment"; case a: return "Portal"; case i: return "Profiler"; case s: return "StrictMode"; case h: return "Suspense"; case p: return "SuspenseList"; } if (typeof g == "object") switch (g.$$typeof) { case l: var A = g; return $(A) + ".Consumer"; case c: var N = g; return $(N._context) + ".Provider"; case x: return U(g, g.render, "ForwardRef"); case f: return V(g.type); case j: return V(g._render); case m: { var q = g, fe = q._payload, de = q._init; try { return V(de(fe)); } catch { return null; } } } return null; } var G = 0, P, F, Z, K, _, O, W; function I() { } I.__reactDisabledLog = !0; function B() { { if (G === 0) { P = console.log, F = console.info, Z = console.warn, K = console.error, _ = console.group, O = console.groupCollapsed, W = console.groupEnd; var g = { configurable: !0, enumerable: !0, value: I, writable: !0 }; Object.defineProperties(console, { info: g, log: g, warn: g, error: g, group: g, groupCollapsed: g, groupEnd: g }); } G++; } } function Q() { { if (G--, G === 0) { var g = { configurable: !0, enumerable: !0, writable: !0 }; Object.defineProperties(console, { log: o({}, g, { value: P }), info: o({}, g, { value: F }), warn: o({}, g, { value: Z }), error: o({}, g, { value: K }), group: o({}, g, { value: _ }), groupCollapsed: o({}, g, { value: O }), groupEnd: o({}, g, { value: W }) }); } G < 0 && b("disabledDepth fell below zero. This is a bug in React. Please file an issue."); } } var X = u.ReactCurrentDispatcher, J; function ee(g, A, N) { { if (J === void 0) try { throw Error(); } catch (fe) { var q = fe.stack.trim().match(/\n( *(at )?)/); J = q && q[1] || ""; } return ` ` + J + g; } } var re = !1, te; { var ye = typeof WeakMap == "function" ? WeakMap : Map; te = new ye(); } function L(g, A) { if (!g || re) return ""; { var N = te.get(g); if (N !== void 0) return N; } var q; re = !0; var fe = Error.prepareStackTrace; Error.prepareStackTrace = void 0; var de; de = X.current, X.current = null, B(); try { if (A) { var oe = function() { throw Error(); }; if (Object.defineProperty(oe.prototype, "props", { set: function() { throw Error(); } }), typeof Reflect == "object" && Reflect.construct) { try { Reflect.construct(oe, []); } catch (Ae) { q = Ae; } Reflect.construct(g, [], oe); } else { try { oe.call(); } catch (Ae) { q = Ae; } g.call(oe.prototype); } } else { try { throw Error(); } catch (Ae) { q = Ae; } g(); } } catch (Ae) { if (Ae && q && typeof Ae.stack == "string") { for (var ne = Ae.stack.split(` `), ve = q.stack.split(` `), xe = ne.length - 1, me = ve.length - 1; xe >= 1 && me >= 0 && ne[xe] !== ve[me]; ) me--; for (; xe >= 1 && me >= 0; xe--, me--) if (ne[xe] !== ve[me]) { if (xe !== 1 || me !== 1) do if (xe--, me--, me < 0 || ne[xe] !== ve[me]) { var ke = ` ` + ne[xe].replace(" at new ", " at "); return typeof g == "function" && te.set(g, ke), ke; } while (xe >= 1 && me >= 0); break; } } } finally { re = !1, X.current = de, Q(), Error.prepareStackTrace = fe; } var Ye = g ? g.displayName || g.name : "", ln = Ye ? ee(Ye) : ""; return typeof g == "function" && te.set(g, ln), ln; } function be(g, A, N) { return L(g, !1); } function We(g) { var A = g.prototype; return !!(A && A.isReactComponent); } function Ie(g, A, N) { if (g == null) return ""; if (typeof g == "function") return L(g, We(g)); if (typeof g == "string") return ee(g); switch (g) { case h: return ee("Suspense"); case p: return ee("SuspenseList"); } if (typeof g == "object") switch (g.$$typeof) { case x: return be(g.render); case f: return Ie(g.type, A, N); case j: return be(g._render); case m: { var q = g, fe = q._payload, de = q._init; try { return Ie(de(fe), A, N); } catch { } } } return ""; } var Jt = {}, Zt = u.ReactDebugCurrentFrame; function ct(g) { if (g) { var A = g._owner, N = Ie(g.type, g._source, A ? A.type : null); Zt.setExtraStackFrame(N); } else Zt.setExtraStackFrame(null); } function hr(g, A, N, q, fe) { { var de = Function.call.bind(Object.prototype.hasOwnProperty); for (var oe in g) if (de(g, oe)) { var ne = void 0; try { if (typeof g[oe] != "function") { var ve = Error((q || "React class") + ": " + N + " type `" + oe + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof g[oe] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`."); throw ve.name = "Invariant Violation", ve; } ne = g[oe](A, oe, q, N, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"); } catch (xe) { ne = xe; } ne && !(ne instanceof Error) && (ct(fe), b("%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).", q || "React class", N, oe, typeof ne), ct(null)), ne instanceof Error && !(ne.message in Jt) && (Jt[ne.message] = !0, ct(fe), b("Failed %s type: %s", N, ne.message), ct(null)); } } } var Qt = u.ReactCurrentOwner, Ct = Object.prototype.hasOwnProperty, mr = { key: !0, ref: !0, __self: !0, __source: !0 }, en, tn; function yr(g) { if (Ct.call(g, "ref")) { var A = Object.getOwnPropertyDescriptor(g, "ref").get; if (A && A.isReactWarning) return !1; } return g.ref !== void 0; } function vr(g) { if (Ct.call(g, "key")) { var A = Object.getOwnPropertyDescriptor(g, "key").get; if (A && A.isReactWarning) return !1; } return g.key !== void 0; } function br(g, A) { typeof g.ref == "string" && Qt.current; } function Cr(g, A) { { var N = function() { en || (en = !0, b("%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)", A)); }; N.isReactWarning = !0, Object.defineProperty(g, "key", { get: N, configurable: !0 }); } } function Tr(g, A) { { var N = function() { tn || (tn = !0, b("%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)", A)); }; N.isReactWarning = !0, Object.defineProperty(g, "ref", { get: N, configurable: !0 }); } } var Er = function(g, A, N, q, fe, de, oe) { var ne = { // This tag allows us to uniquely identify this as a React Element $$typeof: r, // Built-in properties that belong on the element type: g, key: A, ref: N, props: oe, // Record the component responsible for creating this element. _owner: de }; return ne._store = {}, Object.defineProperty(ne._store, "validated", { configurable: !1, enumerable: !1, writable: !0, value: !1 }), Object.defineProperty(ne, "_self", { configurable: !1, enumerable: !1, writable: !1, value: q }), Object.defineProperty(ne, "_source", { configurable: !1, enumerable: !1, writable: !1, value: fe }), Object.freeze && (Object.freeze(ne.props), Object.freeze(ne)), ne; }; function Sr(g, A, N, q, fe) { { var de, oe = {}, ne = null, ve = null; N !== void 0 && (ne = "" + N), vr(A) && (ne = "" + A.key), yr(A) && (ve = A.ref, br(A, fe)); for (de in A) Ct.call(A, de) && !mr.hasOwnProperty(de) && (oe[de] = A[de]); if (g && g.defaultProps) { var xe = g.defaultProps; for (de in xe) oe[de] === void 0 && (oe[de] = xe[de]); } if (ne || ve) { var me = typeof g == "function" ? g.displayName || g.name || "Unknown" : g; ne && Cr(oe, me), ve && Tr(oe, me); } return Er(g, ne, ve, fe, q, Qt.current, oe); } } var Tt = u.ReactCurrentOwner, nn = u.ReactDebugCurrentFrame; function Be(g) { if (g) { var A = g._owner, N = Ie(g.type, g._source, A ? A.type : null); nn.setExtraStackFrame(N); } else nn.setExtraStackFrame(null); } var Et; Et = !1; function St(g) { return typeof g == "object" && g !== null && g.$$typeof === r; } function rn() { { if (Tt.current) { var g = V(Tt.current.type); if (g) return ` Check the render method of \`` + g + "`."; } return ""; } } function wr(g) { return ""; } var on = {}; function _r(g) { { var A = rn(); if (!A) { var N = typeof g == "string" ? g : g.displayName || g.name; N && (A = ` Check the top-level render call using <` + N + ">."); } return A; } } function sn(g, A) { { if (!g._store || g._store.validated || g.key != null) return; g._store.validated = !0; var N = _r(A); if (on[N]) return; on[N] = !0; var q = ""; g && g._owner && g._owner !== Tt.current && (q = " It was passed a child from " + V(g._owner.type) + "."), Be(g), b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', N, q), Be(null); } } function an(g, A) { { if (typeof g != "object") return; if (Array.isArray(g)) for (var N = 0; N < g.length; N++) { var q = g[N]; St(q) && sn(q, A); } else if (St(g)) g._store && (g._store.validated = !0); else if (g) { var fe = v(g); if (typeof fe == "function" && fe !== g.entries) for (var de = fe.call(g), oe; !(oe = de.next()).done; ) St(oe.value) && sn(oe.value, A); } } } function jr(g) { { var A = g.type; if (A == null || typeof A == "string") return; var N; if (typeof A == "function") N = A.propTypes; else if (typeof A == "object" && (A.$$typeof === x || // Note: Memo only checks outer props here. // Inner props are checked in the reconciler. A.$$typeof === f)) N = A.propTypes; else return; if (N) { var q = V(A); hr(N, g.props, "prop", q, g); } else if (A.PropTypes !== void 0 && !Et) { Et = !0; var fe = V(A); b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", fe || "Unknown"); } typeof A.getDefaultProps == "function" && !A.getDefaultProps.isReactClassApproved && b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead."); } } function kr(g) { { for (var A = Object.keys(g.props), N = 0; N < A.length; N++) { var q = A[N]; if (q !== "children" && q !== "key") { Be(g), b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", q), Be(null); break; } } g.ref !== null && (Be(g), b("Invalid attribute `ref` supplied to `React.Fragment`."), Be(null)); } } function cn(g, A, N, q, fe, de) { { var oe = R(g); if (!oe) { var ne = ""; (g === void 0 || typeof g == "object" && g !== null && Object.keys(g).length === 0) && (ne += " 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 ve = wr(); ve ? ne += ve : ne += rn(); var xe; g === null ? xe = "null" : Array.isArray(g) ? xe = "array" : g !== void 0 && g.$$typeof === r ? (xe = "<" + (V(g.type) || "Unknown") + " />", ne = " Did you accidentally export a JSX literal instead of a component?") : xe = typeof g, b("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", xe, ne); } var me = Sr(g, A, N, fe, de); if (me == null) return me; if (oe) { var ke = A.children; if (ke !== void 0) if (q) if (Array.isArray(ke)) { for (var Ye = 0; Ye < ke.length; Ye++) an(ke[Ye], g); Object.freeze && Object.freeze(ke); } else b("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 an(ke, g); } return g === e.Fragment ? kr(me) : jr(me), me; } } function Ar(g, A, N) { return cn(g, A, N, !0); } function Rr(g, A, N) { return cn(g, A, N, !1); } var Or = Rr, Dr = Ar; e.jsx = Or, e.jsxs = Dr; }(); }(jt)), jt; } var mn; function ro() { return mn || (mn = 1, process.env.NODE_ENV === "production" ? lt.exports = to() : lt.exports = no()), lt.exports; } var t = ro(); const oo = "2.0.6", Vn = "chat_session", so = "user_uttered", io = "bot_uttered", ao = "ehelp_bot_uttered"; JSON.stringify({ enabled_agents: ["Alice", "Maria", "Jani"], default_active_agent: "Alice" }); JSON.stringify({ enabled_agents: ["Alice", "Maria", "Jani"], default_active_agent: "Alice" }); const co = "https://sfchatbot.dataon.com", lo = [ { label: "Didn’t address my question", value: "Didn’t address my question" }, { label: "Inaccurate Answer", value: "Inaccurate Answer" }, { label: "The response unclear", value: "The response unclear" }, { label: "The information is incomplete", value: "The information is incomplete" }, { label: "I’d like to explain further", value: "another" } ], Pe = $r, Xe = Lr, uo = oo, fo = "https://sfchatbot.dataon.com/openai-service-dev/", ht = "https://res.cloudinary.com/dcvolkyfb/image/upload/v1740135794/svg/bot_profile_hlnyop.png", Bt = "YYYY-MM-DD", mt = "HH:mm", yn = "N/A", kt = [ // Raster (bitmap) ".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tiff", ".tif", ".webp", ".heif", ".heic", ".jp2", ".ico", ".dds", ".raw", ".cr2", ".nef", ".arw", ".orf", ".psd", ".xcf" ], At = "w-widget-content-container", Rt = "w-ticket-detail-content-container", go = "w-wrapper-body", po = "w-wrapper-body-helpdesk", Qe = "w-header", Ot = { FADE_IN: "w-fade-in-animate" }, xo = "https://placehold.co/600x400?text=No+Image", nt = 3, ho = "GoHRDev2025WorkPlazeDataOnDotCom", Ge = "(Helpdesk Widget Chatbot)", mo = (e) => JSON.parse((e == null ? void 0 : e.replaceAll("/get_started", "")) || "{}"), zn = (e) => { var n; try { return (n = new URL(e)) == null ? void 0 : n.host; } catch { return zn(co); } }, Ee = (e, n) => { var o, r, a; return ((o = Object.keys(e || {})) == null ? void 0 : o.length) > 0 ? (a = (r = Object == null ? void 0 : Object.prototype) == null ? void 0 : r.hasOwnProperty) == null ? void 0 : a.call(e, n) : !1; }, qe = (e) => { var o; const n = e == null ? void 0 : e.attachment; return { text: ((o = Object.keys(e || {})) == null ? void 0 : o.length) > 0 && (e == null ? void 0 : e.type) === "text", upload: Ee(e, "attachment") && Ee(n, "type") && (n == null ? void 0 : n.type) === "fileuploader", password: (n == null ? void 0 : n.type) === "show_password_wp", filedownload: Ee(n, "type") && (n == null ? void 0 : n.type) === "filedownloader", chart: (n == null ? void 0 : n.type) === "charts" && Ee(n, "chartType") }; }, Gn = (e) => { var n, o, r, a; if (e) { const s = e == null ? void 0 : e.split(".")[1], i = (n = s == null ? void 0 : s.replace(/-/g, "+")) == null ? void 0 : n.replace(/_/g, "/"), c = decodeURIComponent( (a = (r = (o = window == null ? void 0 : window.atob(i)) == null ? void 0 : o.split("")) == null ? void 0 : r.map((l) => "%" + ("00" + l.charCodeAt(0).toString(16)).slice(-2))) == null ? void 0 : a.join("") ); return JSON == null ? void 0 : JSON.parse(c || "{}"); } return {}; }, Yt = ({ downloadURL: e = "", fileName: n = "", isOpenNewTab: o = !1 }) => { var a; const r = document == null ? void 0 : document.createElement("a"); r.href = e, r.download = n || e, o && (r.target = "_blank"), (a = document == null ? void 0 : document.body) == null || a.appendChild(r), r.click(), document.body.removeChild(r); }, yo = () => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(e) { const n = crypto.getRandomValues(new Uint8Array(1))[0] % 16; return (e === "x" ? n : n & 3 | 8).toString(16); }), Vt = ({ ArrObj: e, key: n, ignoreCaseSensitive: o = !1 }) => (e == null ? void 0 : e.length) > 0 ? [ ...new Map( e.map((r) => { var a; return [ o ? (a = String(r[n])) == null ? void 0 : a.toLowerCase() : r[n], r ]; }) ).values() ] : [], vo = (e = []) => { const n = {}, o = [], r = []; e == null || e.forEach((s) => { var i; Ee(s, "chats") ? (i = s == null ? void 0 : s.chats) == null || i.forEach((c) => { r == null || r.push(c); }) : r == null || r.push(s); }), r == null || r.forEach((s, i) => { var l, x, h; const c = s == null ? void 0 : s.generated_id; c ? (n[c] || (n[c] = []), (x = n[c]) == null || x.push({ ...s, indexChat: i, ...!(s != null && s.timestamp) && { timestamp: (l = Se()) == null ? void 0 : l.format("hh:mm A") } }), o == null || o.push({ keyItem: c ?? i, type: "text", sender: "response", id: s == null ? void 0 : s.id, ...c && { generated_id: c }, chats: n == null ? void 0 : n[c] })) : o == null || o.push({ ...s, keyItem: i, ...!(s != null && s.timestamp) && { timestamp: (h = Se()) == null ? void 0 : h.format("hh:mm A") } }); }); const a = Vt({ ArrObj: o, key: "keyItem" }); return a == null || a.forEach((s) => { s == null || delete s.keyItem; }), a; }, yt = (e = {}) => { const o = { ...qn(), ...e }; localStorage == null || localStorage.setItem(Vn, JSON.stringify(o || {})); }, qn = () => { const e = localStorage == null ? void 0 : localStorage.getItem(Vn); return JSON.parse(e || "{}"); }, bo = (e = "") => { var n; try { const o = new URL(e); return (n = o == null ? void 0 : o.protocol) != null && n.includes("https") ? "wss" : "ws"; } catch { return "wss"; } }; let vn = null; const Le = (e = ".w-wrapper-body") => { const n = document.querySelector(e); clearTimeout(vn), vn = setTimeout(() => { n && n.scrollTo({ top: n.scrollHeight, behavior: "smooth" }); }, 0); }, Co = (e) => { const n = new Uint8Array(e); let o = ""; for (let r = 0; r < n.byteLength; r++) o += String.fromCharCode(n[r]); return btoa(o); }, To = async (e, n) => { var l; const o = typeof e == "object" ? JSON == null ? void 0 : JSON.stringify(e || {}) : e, r = new TextEncoder(), a = r == null ? void 0 : r.encode(o), s = r == null ? void 0 : r.encode(n); if (s.length !== 32) throw new Error("Key length must be 32 bytes for AES-256"); const i = await ((l = crypto == null ? void 0 : crypto.subtle) == null ? void 0 : l.importKey( "raw", s, { name: "AES-CBC" }, !1, ["encrypt"] )), c = await crypto.subtle.encrypt( { name: "AES-CBC", iv: new Uint8Array(16) }, i, a ); return Co(c); }, xt = (e) => { const n = {}, o = Kn(e), r = o == null ? void 0 : o.map((a) => { var i; const s = a == null ? void 0 : a.CREATED_DATE; return { ...a, DATE_KEY: (i = Se(s)) == null ? void 0 : i.format("YYYY-MM-DD") }; }); return r == null || r.forEach((a) => { var s; n[a == null ? void 0 : a.DATE_KEY] || (n[a == null ? void 0 : a.DATE_KEY] = []), (s = n[a == null ? void 0 : a.DATE_KEY]) == null || s.push(a); }), n; }, zt = (e) => { var n; return (n = Object.values(e || {})) == null ? void 0 : n.flat(); }, Kn = (e) => e == null ? void 0 : e.sort((n, o) => Se(n == null ? void 0 : n.CREATED_DATE) - Se(o == null ? void 0 : o.CREATED_DATE)), Pn = (e) => { if (e && typeof e == "string") { const n = e == null ? void 0 : e.split("."), o = n[(n == null ? void 0 : n.length) - 1]; return e == null ? void 0 : e.replaceAll(`.${o}`, `_avatar.${o}`); } return e; }, Gt = (e) => `https://ui-avatars.com/api/?background=e5e5e5&color=000${e && typeof e == "string" ? `&name=${e.replaceAll(" ", "+")}` : ""}`, bn = (e) => URL.parse(e) && new URL(e), Eo = (e) => { try { return new URL(e); } catch { return {}; } }, Xn = He({}), ue = () => Ue(Xn), So = ({ children: e, getStartedPayload: n, socketURL: o, socketPath: r, onPayslipFn: a, title: s, subTitle: i, keyEncrypt: c, history: l, modelName: x, isSF: h }) => { const [p, f] = H(!1), [m, j] = H("va"), [T, S] = H(!1), [C, E] = H({}), [y, w] = H(!1), [d, v] = H(!1), [u, b] = H(!1), k = se(!1), D = z(() => ({ getStartedPayload: n, socketURL: o, socketPath: r, onPayslipFn: a, title: s, subTitle: i, keyEncrypt: c, history: l, modelName: x, isSF: h }), [ n, o, r, a, s, i, c, l, x, h ]), R = z(() => Gn(C == null ? void 0 : C.access_token), [C == null ? void 0 : C.access_token]); return ge(() => { E(mo(n)); }, [n]), ge(() => { yt({ chatbot_version: uo }); }, []), /* @__PURE__ */ t.jsx( Xn.Provider, { value: { objInitPayload: C, setOpenWidget: f, isOpenWidget: p, activeTab: m, setActiveTab: j, isExpand: T, setExpand: S, setObjInitPayload: E, parsedJWT: R, widgetProps: D, isFirstOpenWidget: y, setFirstOpenWidget: w, isFirstRenderHelpdesk: k, showReadyWSHD: d, setShowReadyWSHD: v, isUserInputHide: u, setUserInputHide: b }, children: e } ); }, Jn = He({}), wo = () => Ue(Jn), _o = ({ children: e }) => { const { objInitPayload: n } = ue(), [o, r] = H({}), a = () => { var i; (i = Je( `${(n == null ? void 0 : n.uriService) || fo}optional/translations` )) == null || i.then(({ data: c }) => { var l; if (c) { const x = Object.keys((l = Object.values(c)) == null ? void 0 : l[0]), h = {}; x == null || x.forEach((p) => { var f; (f = Object.keys(c)) == null || f.forEach((m) => { var j; h[p == null ? void 0 : p.toLowerCase()] = (j = c == null ? void 0 : c[m]) == null ? void 0 : j[p]; }); }), r(h); } }); }, s = () => { const i = window.indexedDB.open("language"); i.onsuccess = (c) => { var x; const l = c.target.result; try { const p = l.transaction("keyvaluepairs", "readonly").objectStore("keyvaluepairs"), f = p == null ? void 0 : p.get((x = n == null ? void 0 : n.lang) == null ? void 0 : x.toLowerCase()); f.onsuccess = () => { r(f == null ? void 0 : f.result); }, f.onerror = () => { a(); }; } catch { a(); } }, i.onerror = () => { a(); }; }; return ge(() => { s(); }, [n == null ? void 0 : n.uriService, n == null ? void 0 : n.lang]), /* @__PURE__ */ t.jsx(Jn.Provider, { value: { langDatas: o }, children: e }); }, Zn = He({}), je = () => Ue(Zn), jo = ({ children: e }) => { var P; const [n, o] = H([]), [r, a] = H(!1), [s, i] = H(!1), [c, l] = H({}), [x, h] = H(!1), [p, f] = H(!1), [m, j] = H(""), [T, S] = H(!1), { objInitPayload: C, widgetProps: E, setOpenWidget: y, setFirstOpenWidget: w, isFirstRenderHelpdesk: d, setUserInputHide: v } = ue(), u = se(null), b = se(""), k = se(""), D = (F) => { var K, _; const Z = (K = F == null ? void 0 : F.metadata) == null ? void 0 : K.stopped; if (v(((_ = F == null ? void 0 : F.metadata) == null ? void 0 : _.userInput) === "hide"), !Z) { const O = Ee(F, "text_feedback_link") && Ee(F, "text"); o((W) => { const I = [...W], B = I == null ? void 0 : I[(I == null ? void 0 : I.length) - 1]; return (B == null ? void 0 : B.id) === (F == null ? void 0 : F.id) ? (B.text += F == null ? void 0 : F.text, F != null && F.tag && (B.tag = F.tag)) : I.push({ ...F, ...O && { type: "text" }, sender: "response" }), vo(I); }); } a(!1), i(!1), Le(); }, R = (F) => { var Z, K, _, O; F && U({ msg: E == null ? void 0 : E.getStartedPayload }), (Z = u == null ? void 0 : u.current) == null || Z.emit("session_request", { session_id: null }), (K = u == null ? void 0 : u.current) == null || K.on("session_confirm", (W) => { b.current = W, yt({ session_id: W == null ? void 0 : W.session_id }); }), (_ = u == null ? void 0 : u.current) == null || _.on(io, D), (O = u == null ? void 0 : u.current) == null || O.on(ao, (W) => { const I = JSON.parse(W || "{}"); Ee(I, "iswidget") && f(I == null ? void 0 : I.iswidget); }), x || h(!0), w(!1); }, U = ({ msg: F, additionalConfig: Z = {}, isShowLoadingResponse: K = !0 }) => { var _; (_ = u == null ? void 0 : u.current) == null || _.emit(so, { customData: { language: C == null ? void 0 : C.lang }, message: F, session_id: b == null ? void 0 : b.current, ...Z }), K ? a(!0) : i(!0); }, $ = (F = !1) => { var K, _; u.current && ((K = u == null ? void 0 : u.current) == null || K.off(), (_ = u == null ? void 0 : u.current) == null || _.disconnect(), u.current = null), d.current = !1; const Z = qr( `${bo(E == null ? void 0 : E.socketURL)}://${zn( E == null ? void 0 : E.socketURL )}`, { path: E == null ? void 0 : E.socketPath, transports: ["websocket"], reconnection: !0, reconnectionAttempts: 1 } ); Z.on("connect", () => { R(F); }), Z.on("connect_error", (O) => { console.error("connect_error widget-chatbot : ", { err: O, socketURL: E == null ? void 0 : E.socketURL, socketPath: E == null ? void 0 : E.widgetProps }), h(!1); }), Z.io.on("reconnect", () => { console.error("reconnect widget-chatbot : ", { socketURL: E == null ? void 0 : E.socketURL, socketPath: E == null ? void 0 : E.widgetProps }), h(!1); }), u.current = Z; }, V = () => { var F; (!((F = u == null ? void 0 : u.current) != null && F.connected) || !x) && ($(), y(!1)); }, G = () => { h(!1); }; return ge(() => (y(!1), $(), window.addEventListener("online", V), window.addEventListener("offline", G), () => { var F, Z; u.current && ((F = u.current) == null || F.off("connect", R), (Z = u.current) == null || Z.disconnect(), u.current = null), window.removeEventListener("online", V), window.removeEventListener("offline", G); }), [ JSON.stringify(C || {}), E == null ? void 0 : E.socketURL, E == null ? void 0 : E.socketPath ]), /* @__PURE__ */ t.jsx( Zn.Provider, { value: { setChats: o, chats: n, onSendMsg: U, isWaitResponse: r, socket: u == null ? void 0 : u.current, sessionId: (P = b == null ? void 0 : b.current) == null ? void 0 : P.session_id, loadingRegenerate: s, file: c, setFile: l, connected: x, isHandshakeWidget: p, createSocket: $, currRegenerateId: k, thinkingText: m, setThinkingText: j, isThinkingCompleted: T, setIsThinkingCompleted: S }, children: e } ); }, ko = { 'pre[class*="language-"]': { color: "#d4d4d4", fontSize: "13px", textShadow: "none", fontFamily: 'Menlo, Monaco, Consolas, "Andale Mono", "Ubuntu Mono", "Courier New", monospace', direction: "ltr", textAlign: "left", whiteSpace: "pre", wordSpacing: "normal", wordBreak: "normal", lineHeight: "1.5", MozTabSize: "4", OTabSize: "4", tabSize: "4", WebkitHyphens: "none", MozHyphens: "none", msHyphens: "none", hyphens: "none", padding: "1em", margin: ".5em 0", overflow: "auto", background: "#1e1e1e" }, 'code[class*="language-"]': { color: "#d4d4d4", fontSize: "13px", textShadow: "none", fontFamily: 'Menlo, Monaco, Consolas, "Andale Mono", "Ubuntu Mono", "Courier New", monospace', direction: "ltr", textAlign: "left", whiteSpace: "pre", wordSpacing: "normal", wordBreak: "normal", lineHeight: "1.5", MozTabSize: "4", OTabSize: "4", tabSize: "4", WebkitHyphens: "none", MozHyphens: "none", msHyphens: "none", hyphens: "none" }, 'pre[class*="language-"]::selection': { textShadow: "none", background: "#264F78" }, 'code[class*="language-"]::selection': { textShadow: "none", background: "#264F78" }, 'pre[class*="language-"] *::selection': { textShadow: "none", background: "#264F78" }, 'code[class*="language-"] *::selection': { textShadow: "none", background: "#264F78" }, ':not(pre) > code[class*="language-"]': { padding: ".1em .3em", borderRadius: ".3em", color: "#db4c69", background: "#1e1e1e" }, ".namespace": { Opacity: ".7" }, "doctype.doctype-tag": { color: "#569CD6" }, "doctype.name": { color: "#9cdcfe" }, comment: { color: "#6a9955" }, prolog: { color: "#6a9955" }, punctuation: { color: "#d4d4d4" }, ".language-html .language-css .token.punctuation": { color: "#d4d4d4" }, ".language-html .language-javascript .token.punctuation": { color: "#d4d4d4" }, property: { color: "#9cdcfe" }, tag: { color: "#569cd6" }, boolean: { color: "#569cd6" }, number: { color: "#b5cea8" }, constant: { color: "#9cdcfe" }, symbol: { color: "#b5cea8" }, inserted: { color: "#b5cea8" }, unit: { color: "#b5cea8" }, selector: { color: "#d7ba7d" }, "attr-name": { color: "#9cdcfe" }, string: { color: "#ce9178" }, char: { color: "#ce9178" }, builtin: { color: "#ce9178" }, deleted: { color: "#ce9178" }, ".language-css .token.string.url": { textDecoration: "underline" }, operator: { color: "#d4d4d4" }, entity: { color: "#569cd6" }, "operator.arrow": { color: "#569CD6" }, atrule: { color: "#ce9178" }, "atrule.rule": { color: "#c586c0" }, "atrule.url": { color: "#9cdcfe" }, "atrule.url.function": { color: "#dcdcaa" }, "atrule.url.punctuation": { color: "#d4d4d4" }, keyword: { color: "#569CD6" }, "keyword.module": { color: "#c586c0" }, "keyword.control-flow": { color: "#c586c0" }, function: { color: "#dcdcaa" }, "function.maybe-class-name": { color: "#dcdcaa" }, regex: { color: "#d16969" }, important: { color: "#569cd6" }, italic: { fontStyle: "italic" }, "class-name": { color: "#4ec9b0" }, "maybe-class-name": { color: "#4ec9b0" }, console: { color: "#9cdcfe" }, parameter: { color: "#9cdcfe" }, interpolation: { color: "#9cdcfe" }, "punctuation.interpolation-punctuation": { color: "#569cd6" }, variable: { color: "#9cdcfe" }, "imports.maybe-class-name": { color: "#9cdcfe" }, "exports.maybe-class-name": { color: "#9cdcfe" }, escape: { color: "#d7ba7d" }, "tag.punctuation": { color: "#808080" }, cdata: { color: "#808080" }, "attr-value": { color: "#ce9178" }, "attr-value.punctuation": { color: "#ce9178" }, "attr-value.punctuation.attr-equals": { color: "#d4d4d4" }, namespace: { color: "#4ec9b0" }, 'pre[class*="language-javascript"]': { color: "#9cdcfe" }, 'code[class*="language-javascript"]': { color: "#9cdcfe" }, 'pre[class*="language-jsx"]': { color: "#9cdcfe" }, 'code[class*="language-jsx"]': { color: "#9cdcfe" }, 'pre[class*="language-typescript"]': { color: "#9cdcfe" }, 'code[class*="language-typescript"]': { color: "#9cdcfe" }, 'pre[class*="language-tsx"]': { color: "#9cdcfe" }, 'code[class*="language-tsx"]': { color: "#9cdcfe" }, 'pre[class*="language-css"]': { color: "#ce9178" }, 'code[class*="language-css"]': { color: "#ce9178" }, 'pre[class*="language-html"]': { color: "#d4d4d4" }, 'code[class*="language-html"]': { color: "#d4d4d4" }, ".language-regex .token.anchor": { color: "#dcdcaa" }, ".language-html .token.punctuation": { color: "#808080" }, 'pre[class*="language-"] > code[class*="language-"]': { position: "relative", zIndex: "1" }, ".line-highlight.line-highlight": { background: "#f7ebc6", boxShadow: "inset 5px 0 0 #f7d87c", zIndex: "0" } }, Ao = (e) => e.replace(/[^a-zA-Z0-9_]/g, "").trim(), M = (e = "", n) => { var i; const { langDatas: o } = wo(), r = localStorage == null ? void 0 : localStorage.getItem("show_text_id"), a = Ao(String(e)), s = (o == null ? void 0 : o[a == null ? void 0 : a.toUpperCase()]) || n; return ((i = Object.keys(o || {})) == null ? void 0 : i.length) > 0 ? r ? `WPUI_${a}` : s : n; }, Ro = ({ isFeedback: e = !1, open: n, ...o }) => { var a; const r = z(() => e ? "w-modal-container-feedback" : "", [e]); return Pe != null && Pe.startsWith("5") ? /* @__PURE__ */ t.jsx( un, { rootClassName: r, ...o, open: n, getContainer: "#w-widget-content", maskProps: { style: { backdropFilter: "blur(4px)" } }, width: 300, style: { ...Object.keys((o == null ? void 0 : o.style) || {}).length > 0 && { ...o == null ? void 0 : o.style }, top: 20 } } ) : ( // <div className={rootClassName}> /* @__PURE__ */ t.jsx( un, { getContainer: "#w-widget-content", width: 300, ...o, ...Xe != null && Xe.startsWith("18") ? { open: n } : { visible: n }, maskStyle: { backdropFilter: "blur(4x)", ...((a = Object.keys((o == null ? void 0 : o.maskStyle) || {})) == null ? void 0 : a.length) > 0 && { ...o == null ? void 0 : o.maskStyle } }, style: { ...Object.keys((o == null ? void 0 : o.style) || {}).length > 0 && { ...o == null ? void 0 : o.style }, top: 20 } } ) ); }, Qn = Y(Ro), Oo = ({ childrenData: e, children: n, tag: o }) => { const r = M("ThinkProcess", "Think Process"), s = (() => { const i = [], c = []; let l = 0; const x = "<think>", h = "</think>"; for (; l < (e == null ? void 0 : e.length); ) { const f = e == null ? void 0 : e.indexOf(x, l), m = e == null ? void 0 : e.indexOf(h, l); if (f !== -1 && m !== -1 && f < m) f > l && i.push({ type: "text", value: e == null ? void 0 : e.slice(l, f) }), c.push( e == null ? void 0 : e.slice(f + x.length, m) // ini buat ambil text dri stlah <think> sampai sblm </think> ), l = m + h.length; else if (f !== -1 && m === -1) { f > l && i.push({ type: "text", value: e == null ? void 0 : e.slice(l, f) }), c.push( e == null ? void 0 : e.slice(f + x.length) // ini buat ambil smua text stlah <think> aja, karna </think> blm ada ); break; } else { i.push({ type: "text", value: e == null ? void 0 : e.slice(l) }); break; } } const p = []; return c.length > 0 && p.push({ type: "think", value: c.join(` `) // gabungkan semua isi <think> dengan pemisah newline }), p.push(...i), p; })(); return /* @__PURE__ */ t.jsx("div", { children: s == null ? void 0 : s.map((i, c) => (i == null ? void 0 : i.type) === "think" ? /* @__PURE__ */ t.jsx( dn, { className: "w-think-collapse", ghost: !0, style: { marginBottom: 12 }, children: /* @__PURE__ */ t.jsx( dn.Panel, { header: o || r, children: /* @__PURE__ */ t.jsx(ce.Paragraph, { children: /* @__PURE__ */ t.jsx("blockquote", { children: n(i == null ? void 0 : i.value, "think") }) }) }, "think" ) }, c ) : /* @__PURE__ */ t.jsx(pt, { children: n(i == null ? void 0 : i.value, "text") }, c)) }); }, Do = Y(Oo), Cn = ({ props: e, isModal: n = !1 }) => { const o = (r, a) => { var s; return (s = Mr) == null ? void 0 : s.map(r, (i) => { var c, l, x; return !Nr(i) || ((c = Object.keys((i == null ? void 0 : i.props) || {})) == null ? void 0 : c.length) === 0 ? i : Fr(i, { ...i == null ? void 0 : i.props, ...(i == null ? void 0 : i.type) === "thead" && { className: "ant-table-thead" }, ...((i == null ? void 0 : i.type) === "th" || (i == null ? void 0 : i.type) === "td") && { className: "ant-table-cell", ...(i == null ? void 0 : i.type) === "th" && { style: { background: "var(--primary-color, #395ebc)", color: "#ffffff", minWidth: 180 } } }, ...i.type === "tr" && a === "tbody" && { className: "ant-table-row" }, ...(i == null ? void 0 : i.type) === "tbody" && { className: "ant-table-tbody" }, children: (l = i == null ? void 0 : i.props) != null && l.children ? o((x = i == null ? void 0 : i.props) == null ? void 0 : x.children, i == null ? void 0 : i.type) : i == null ? void 0 : i.props }); }); }; return /* @__PURE__ */ t.jsx(t.Fragment, { children: /* @__PURE__ */ t.jsx("div", { className: "ant-table", children: /* @__PURE__ */ t.jsx("div", { className: "ant-table-container", children: /* @__PURE__ */ t.jsx( "div", { className: "ant-table-content", style: { overflow: "scroll", maxWidth: n ? "100%" : 330, maxHeight: n ? "100%" : 360 }, children: /* @__PURE__ */ t.jsx("table", { className: "wp-md-table", ...e, children: o(e == null ? void 0 : e.children, "") }) } ) }) }) }); }, Lo = ({ children: e, tag: n }) => { const o = M( "OpenDetailTable", "Open Detail Table" ), r = M("TableDetail", "Tabel Detail"), { widgetProps: a, objInitPayload: s } = ue(), [i, c] = H(!1); return /* @__PURE__ */ t.jsx("div", { children: /* @__PURE__ */ t.jsx(Do, { childrenData: e, tag: n, children: (l, x) => /* @__PURE__ */ t.jsx( Kr, { remarkPlugins: [Pr], components: { table: ({ ...h }) => /* @__PURE__ */ t.jsxs(t.Fragment, { children: [ /* @__PURE__ */ t.jsx(Cn, { props: h }), /* @__PURE__ */ t.jsx( "div", { style: { display: "flex",