@selleo/chatbot-client
Version:
Client that can be integrated with a backend created with openai
34 lines (32 loc) • 156 kB
JavaScript
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const we=require("react");function Pi(e){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:()=>e[t]})}}return n.default=e,Object.freeze(n)}const De=Pi(we);function an(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var et={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 At;function Oi(){if(At)return hn;At=1;var e=we,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 Rt;function Ai(){return Rt||(Rt=1,process.env.NODE_ENV!=="production"&&function(){var e=we,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 j=!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||j||k||b||typeof m=="object"&&m!==null&&(m.$$typeof===g||m.$$typeof===p||m.$$typeof===o||m.$$typeof===a||m.$$typeof===s||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,Ce,u,O,N;function h(){}h.__reactDisabledLog=!0;function B(){{if(D===0){ee=console.log,ue=console.info,be=console.warn,Ce=console.error,u=console.group,O=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:Ce}),group:ne({},m,{value:u}),groupCollapsed:ne({},m,{value:O}),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 A(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(Ye){Y=Ye}Reflect.construct(m,[],ie)}else{try{ie.call()}catch(Ye){Y=Ye}m.call(ie.prototype)}}else{try{throw Error()}catch(Ye){Y=Ye}m()}}catch(Ye){if(Ye&&Y&&typeof Ye.stack=="string"){for(var re=Ye.stack.split(`
`),Pe=Y.stack.split(`
`),ke=re.length-1,Ee=Pe.length-1;ke>=1&&Ee>=0&&re[ke]!==Pe[Ee];)Ee--;for(;ke>=1&&Ee>=0;ke--,Ee--)if(re[ke]!==Pe[Ee]){if(ke!==1||Ee!==1)do if(ke--,Ee--,Ee<0||re[ke]!==Pe[Ee]){var je=`
`+re[ke].replace(" at new "," at ");return m.displayName&&je.includes("<anonymous>")&&(je=je.replace("<anonymous>",m.displayName)),typeof m=="function"&&W.set(m,je),je}while(ke>=1&&Ee>=0);break}}}finally{K=!1,L.current=me,Q(),Error.prepareStackTrace=se}var rn=m?m.displayName||m.name:"",Ot=rn?H(rn):"";return typeof m=="function"&&W.set(m,Ot),Ot}function Te(m,S,R){return A(m,!1)}function z(m){var S=m.prototype;return!!(S&&S.isReactComponent)}function Re(m,S,R){if(m==null)return"";if(typeof m=="function")return A(m,z(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 Te(m.render);case p:return Re(m.type,S,R);case g:{var Y=m,se=Y._payload,me=Y._init;try{return Re(me(se),S,R)}catch{}}}return""}var Me=Object.prototype.hasOwnProperty,Xe={},cn=v.ReactDebugCurrentFrame;function nn(m){if(m){var S=m._owner,R=Re(m.type,m._source,S?S.type:null);cn.setExtraStackFrame(R)}else cn.setExtraStackFrame(null)}function wn(m,S,R,Y,se){{var me=Function.call.bind(Me);for(var ie in m)if(me(m,ie)){var re=void 0;try{if(typeof m[ie]!="function"){var Pe=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 Pe.name="Invariant Violation",Pe}re=m[ie](S,ie,Y,R,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(ke){re=ke}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 Xe)&&(Xe[re.message]=!0,nn(se),F("Failed %s type: %s",R,re.message),nn(null))}}}var kn=Array.isArray;function fn(m){return kn(m)}function Dn(m){{var S=typeof Symbol=="function"&&Symbol.toStringTag,R=S&&m[Symbol.toStringTag]||m.constructor.name||"Object";return R}}function Ln(m){try{return En(m),!1}catch{return!0}}function En(m){return""+m}function Sn(m){if(Ln(m))return F("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Dn(m)),En(m)}var w=v.ReactCurrentOwner,P={key:!0,ref:!0,__self:!0,__source:!0},$,le,oe;oe={};function _e(m){if(Me.call(m,"ref")){var S=Object.getOwnPropertyDescriptor(m,"ref").get;if(S&&S.isReactWarning)return!1}return m.ref!==void 0}function He(m){if(Me.call(m,"key")){var S=Object.getOwnPropertyDescriptor(m,"key").get;if(S&&S.isReactWarning)return!1}return m.key!==void 0}function $e(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={$$typeof:n,type:m,key:S,ref:R,props:ie,_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,Pe=null;R!==void 0&&(Sn(R),re=""+R),He(S)&&(Sn(S.key),re=""+S.key),_e(S)&&(Pe=S.ref,$e(S,se));for(me in S)Me.call(S,me)&&!P.hasOwnProperty(me)&&(ie[me]=S[me]);if(m&&m.defaultProps){var ke=m.defaultProps;for(me in ke)ie[me]===void 0&&(ie[me]=ke[me])}if(re||Pe){var Ee=typeof m=="function"?m.displayName||m.name||"Unknown":m;re&&Ke(ie,Ee),Pe&&Je(ie,Ee)}return xe(m,re,Pe,se,Y,w.current,ie)}}var Ie=v.ReactCurrentOwner,kt=v.ReactDebugCurrentFrame;function tn(m){if(m){var S=m._owner,R=Re(m.type,m._source,S?S.type:null);kt.setExtraStackFrame(R)}else kt.setExtraStackFrame(null)}var Mn;Mn=!1;function jn(m){return typeof m=="object"&&m!==null&&m.$$typeof===n}function Et(){{if(Ie.current){var m=G(Ie.current.type);if(m)return`
Check the render method of \``+m+"`."}return""}}function bi(m){return""}var St={};function vi(m){{var S=Et();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 Ct(m,S){{if(!m._store||m._store.validated||m.key!=null)return;m._store.validated=!0;var R=vi(S);if(St[R])return;St[R]=!0;var Y="";m&&m._owner&&m._owner!==Ie.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 Tt(m,S){{if(typeof m!="object")return;if(fn(m))for(var R=0;R<m.length;R++){var Y=m[R];jn(Y)&&Ct(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)&&Ct(ie.value,S)}}}function wi(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||S.$$typeof===p))R=S.propTypes;else return;if(R){var Y=G(S);wn(R,m.props,"prop",Y,m)}else if(S.PropTypes!==void 0&&!Mn){Mn=!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 ki(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 Pt(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 Pe=bi();Pe?re+=Pe:re+=Et();var ke;m===null?ke="null":fn(m)?ke="array":m!==void 0&&m.$$typeof===n?(ke="<"+(G(m.type)||"Unknown")+" />",re=" Did you accidentally export a JSX literal instead of a component?"):ke=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",ke,re)}var Ee=pn(m,S,R,se,me);if(Ee==null)return Ee;if(ie){var je=S.children;if(je!==void 0)if(Y)if(fn(je)){for(var rn=0;rn<je.length;rn++)Tt(je[rn],m);Object.freeze&&Object.freeze(je)}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 Tt(je,m)}return m===r?ki(Ee):wi(Ee),Ee}}function Ei(m,S,R){return Pt(m,S,R,!0)}function Si(m,S,R){return Pt(m,S,R,!1)}var Ci=Si,Ti=Ei;dn.Fragment=r,dn.jsx=Ci,dn.jsxs=Ti}()),dn}process.env.NODE_ENV==="production"?et.exports=Oi():et.exports=Ai();var te=et.exports;const Ri=e=>De.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",...e},De.createElement("path",{d:"M16.293 9.293 12 13.586 7.707 9.293l-1.414 1.414L12 16.414l5.707-5.707z"}),De.createElement("path",{d:"M16.293 9.293 12 13.586 7.707 9.293l-1.414 1.414L12 16.414l5.707-5.707z"})),Ar=e=>De.createElement("svg",{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",fill:"none",...e},De.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"}),De.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"}),De.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"}),De.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"})),Rr=e=>De.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"#474747",...e},De.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"}),De.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"})),_i=e=>De.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",...e},De.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 _r={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})()})(_r);var Ii=_r.exports;const Ue=an(Ii),On=e=>({Authorization:e??"","Content-Type":"application/json"}),Fi={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}},Ir={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()}},Di={content:"",role:"assistant",isWaiting:!0},Fr={content:"How can I help you?",role:"assistant"},Li=(e,n)=>{const[t,r]=we.useState(""),[i,l]=we.useState([]),[o,a]=we.useState(!1),{apiUrl:s,welcomeMessage:c}=xn(),f=async()=>{a(!0);try{const g=await Fi.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([Di,{content:g,role:"user"},...i]),r(""),await Ir.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 we.useEffect(()=>{f()},[e]),{messages:i,createMessage:p,message:t,setMessage:r,isLoading:o}},Dr=we.createContext({logo:Ar,toggleButtonIcon:Rr,placeholder:"Let's talk",welcomeMessage:Fr}),Mi=e=>{const{children:n}=e;return te.jsx(Dr.Provider,{value:e,children:n})},xn=()=>we.useContext(Dr),ji=({threadId:e,token:n})=>{const[t,r]=we.useState(!1),i=we.useRef(null),l=we.useRef(null),{messages:o,createMessage:a,message:s,setMessage:c,isLoading:f}=Li(e,n),{chatToggleButtonClassName:p,chatMainClassName:g,topBarClassName:d,chatName:E,conversationClassName:y,inputSectionClassName:x,placeholder:v,toggleButtonIcon:F,logo:C}=xn(),j=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)=>te.jsx(es,{...D},D.role+ee)):null,Z=()=>{const D=l.current;D&&D.scrollIntoView({behavior:"smooth"})};we.useEffect(()=>{Z()},[o]);const de=Ue("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}),_=Ue(`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=Ue("chat-flex chat-h-[70px] chat-items-center chat-justify-between chat-pl-1 chat-shadow-md",d),G=Ue("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=Ue("chat-absolute chat-bottom-3 chat-w-full",x);return te.jsxs(te.Fragment,{children:[te.jsx("div",{className:de,onClick:M,role:"button",tabIndex:0,"aria-label":"Toggle chatbox",children:te.jsx(F,{width:35})}),te.jsxs("div",{className:_,children:[te.jsxs("div",{className:I,children:[te.jsxs("div",{className:"chat-flex chat-items-center chat-p-2",children:[te.jsx(C,{width:35}),te.jsx("div",{className:"chat-ml-2",children:te.jsx("h3",{className:"chat-m-0 chat-p-0 chat-text-2xl chat-font-medium chat-text-gray",children:E})})]}),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:te.jsx(Ri,{fill:"black",width:30})})]}),te.jsxs("div",{className:G,children:[q(),te.jsx("div",{ref:l})]}),te.jsx("div",{className:ne,children: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:[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:j,onKeyUp:b,"aria-label":"Chat message input"}),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:te.jsx(_i,{fill:"black",width:30})})]})})]})]})},zi=()=>{const[e,n]=we.useState(localStorage.getItem("threadId")),{apiUrl:t,token:r}=xn(),i=l=>{if(l){n(l),localStorage.setItem("threadId",l);return}n(null),localStorage.removeItem("threadId")};return we.useEffect(()=>{e||(async()=>{try{const o=await Ir.createThread(r,t);i(o.threadId)}catch(o){console.error("Failed to create thread:",o)}})()},[t,e,r]),e?te.jsx(ji,{threadId:e,token:r}):null},_t=["http","https","mailto","tel"];function Bi(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<_t.length;){const l=_t[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 Ni=function(n){return n!=null&&n.constructor!=null&&typeof n.constructor.isBuffer=="function"&&n.constructor.isBuffer(n)};const Lr=an(Ni);function gn(e){return!e||typeof e!="object"?"":"position"in e||"type"in e?It(e.position):"start"in e||"end"in e?It(e):"line"in e||"column"in e?nt(e):""}function nt(e){return Ft(e&&e.line)+":"+Ft(e&&e.column)}function It(e){return nt(e&&e.start)+"-"+nt(e&&e.end)}function Ft(e){return e&&typeof e=="number"?e:1}class Be extends Error{constructor(n,t,r){const i=[null,null];let l={start:{line:null,column:null},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=gn(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}}Be.prototype.file="";Be.prototype.name="";Be.prototype.reason="";Be.prototype.message="";Be.prototype.stack="";Be.prototype.fatal=null;Be.prototype.column=null;Be.prototype.line=null;Be.prototype.source=null;Be.prototype.ruleId=null;Be.prototype.position=null;const Ve={basename:$i,dirname:Ui,extname:Hi,join:Vi,sep:"/"};function $i(e,n){if(n!==void 0&&typeof n!="string")throw new TypeError('"ext" argument must be a string');bn(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 Ui(e){if(bn(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 Hi(e){bn(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||l===0||l===1&&i===t-1&&i===r+1?"":e.slice(i,t)}function Vi(...e){let n=-1,t;for(;++n<e.length;)bn(e[n]),e[n]&&(t=t===void 0?e[n]:t+"/"+e[n]);return t===void 0?".":qi(t)}function qi(e){bn(e);const n=e.charCodeAt(0)===47;let t=Wi(e,!n);return t.length===0&&!n&&(t="."),t.length>0&&e.charCodeAt(e.length-1)===47&&(t+="/"),n?"/"+t:t}function Wi(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 bn(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}const Yi={cwd:Xi};function Xi(){return"/"}function tt(e){return e!==null&&typeof e=="object"&&e.href&&e.origin}function Qi(e){if(typeof e=="string")e=new URL(e);else if(!tt(e)){const n=new TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw n.code="ERR_INVALID_ARG_TYPE",n}if(e.protocol!=="file:"){const n=new TypeError("The URL must be of scheme file");throw n.code="ERR_INVALID_URL_SCHEME",n}return Gi(e)}function Gi(e){if(e.hostname!==""){const r=new TypeError('File URL host must be "localhost" or empty on darwin');throw r.code="ERR_INVALID_FILE_URL_HOST",r}const n=e.pathname;let t=-1;for(;++t<n.length;)if(n.charCodeAt(t)===37&&n.charCodeAt(t+1)===50){const r=n.charCodeAt(t+2);if(r===70||r===102){const i=new TypeError("File URL path must not include encoded / characters");throw i.code="ERR_INVALID_FILE_URL_PATH",i}}return decodeURIComponent(n)}const zn=["history","path","basename","stem","extname","dirname"];class Mr{constructor(n){let t;n?typeof n=="string"||Ki(n)?t={value:n}:tt(n)?t={path:n}:t=n:t={},this.data={},this.messages=[],this.history=[],this.cwd=Yi.cwd(),this.value,this.stored,this.result,this.map;let r=-1;for(;++r<zn.length;){const l=zn[r];l in t&&t[l]!==void 0&&t[l]!==null&&(this[l]=l==="history"?[...t[l]]:t[l])}let i;for(i in t)zn.includes(i)||(this[i]=t[i])}get path(){return this.history[this.history.length-1]}set path(n){tt(n)&&(n=Qi(n)),Nn(n,"path"),this.path!==n&&this.history.push(n)}get dirname(){return typeof this.path=="string"?Ve.dirname(this.path):void 0}set dirname(n){Dt(this.basename,"dirname"),this.path=Ve.join(n||"",this.basename)}get basename(){return typeof this.path=="string"?Ve.basename(this.path):void 0}set basename(n){Nn(n,"basename"),Bn(n,"basename"),this.path=Ve.join(this.dirname||"",n)}get extname(){return typeof this.path=="string"?Ve.extname(this.path):void 0}set extname(n){if(Bn(n,"extname"),Dt(this.dirname,"extname"),n){if(n.charCodeAt(0)!==46)throw new Error("`extname` must start with `.`");if(n.includes(".",1))throw new Error("`extname` cannot contain multiple dots")}this.path=Ve.join(this.dirname,this.stem+(n||""))}get stem(){return typeof this.path=="string"?Ve.basename(this.path,this.extname):void 0}set stem(n){Nn(n,"stem"),Bn(n,"stem"),this.path=Ve.join(this.dirname||"",n+(this.extname||""))}toString(n){return(this.value||"").toString(n||void 0)}message(n,t,r){const i=new Be(n,t,r);return this.path&&(i.name=this.path+":"+i.name,i.file=this.path),i.fatal=!1,this.messages.push(i),i}info(n,t,r){const i=this.message(n,t,r);return i.fatal=null,i}fail(n,t,r){const i=this.message(n,t,r);throw i.fatal=!0,i}}function Bn(e,n){if(e&&e.includes(Ve.sep))throw new Error("`"+n+"` cannot be a path: did not expect `"+Ve.sep+"`")}function Nn(e,n){if(!e)throw new Error("`"+n+"` cannot be empty")}function Dt(e,n){if(!e)throw new Error("Setting `"+n+"` requires `path` to be set too")}function Ki(e){return Lr(e)}function Lt(e){if(e)throw e}var An=Object.prototype.hasOwnProperty,jr=Object.prototype.toString,Mt=Object.defineProperty,jt=Object.getOwnPropertyDescriptor,zt=function(n){return typeof Array.isArray=="function"?Array.isArray(n):jr.call(n)==="[object Array]"},Bt=function(n){if(!n||jr.call(n)!=="[object Object]")return!1;var t=An.call(n,"constructor"),r=n.constructor&&n.constructor.prototype&&An.call(n.constructor.prototype,"isPrototypeOf");if(n.constructor&&!t&&!r)return!1;var i;for(i in n);return typeof i>"u"||An.call(n,i)},Nt=function(n,t){Mt&&t.name==="__proto__"?Mt(n,t.name,{enumerable:!0,configurable:!0,value:t.newValue,writable:!0}):n[t.name]=t.newValue},$t=function(n,t){if(t==="__proto__")if(An.call(n,t)){if(jt)return jt(n,t).value}else return;return n[t]},Ji=function e(){var n,t,r,i,l,o,a=arguments[0],s=1,c=arguments.length,f=!1;for(typeof a=="boolean"&&(f=a,a=arguments[1]||{},s=2),(a==null||typeof a!="object"&&typeof a!="function")&&(a={});s<c;++s)if(n=arguments[s],n!=null)for(t in n)r=$t(a,t),i=$t(n,t),a!==i&&(f&&i&&(Bt(i)||(l=zt(i)))?(l?(l=!1,o=r&&zt(r)?r:[]):o=r&&Bt(r)?r:{},Nt(a,{name:t,newValue:e(f,o,i)})):typeof i<"u"&&Nt(a,{name:t,newValue:i}));return a};const Ut=an(Ji);function rt(e){if(typeof e!="object"||e===null)return!1;const n=Object.getPrototypeOf(e);return(n===null||n===Object.prototype||Object.getPrototypeOf(n)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}function Zi(){const e=[],n={run:t,use:r};return n;function t(...i){let l=-1;const o=i.pop();if(typeof o!="function")throw new TypeError("Expected function as last argument, not "+o);a(null,...i);function a(s,...c){const f=e[++l];let p=-1;if(s){o(s);return}for(;++p<i.length;)(c[p]===null||c[p]===void 0)&&(c[p]=i[p]);i=c,f?el(f,a)(...c):o(null,...c)}}function r(i){if(typeof i!="function")throw new TypeError("Expected `middelware` to be a function, not "+i);return e.push(i),n}}function el(e,n){let t;return r;function r(...o){const a=e.length>o.length;let s;a&&o.push(i);try{s=e.apply(this,o)}catch(c){const f=c;if(a&&t)throw f;return i(f)}a||(s&&s.then&&typeof s.then=="function"?s.then(l,i):s instanceof Error?i(s):l(s))}function i(o,...a){t||(t=!0,n(o,...a))}function l(o){i(null,o)}}const nl=Br().freeze(),zr={}.hasOwnProperty;function Br(){const e=Zi(),n=[];let t={},r,i=-1;return l.data=o,l.Parser=void 0,l.Compiler=void 0,l.freeze=a,l.attachers=n,l.use=s,l.parse=c,l.stringify=f,l.run=p,l.runSync=g,l.process=d,l.processSync=E,l;function l(){const y=Br();let x=-1;for(;++x<n.length;)y.use(...n[x]);return y.data(Ut(!0,{},t)),y}function o(y,x){return typeof y=="string"?arguments.length===2?(Hn("data",r),t[y]=x,l):zr.call(t,y)&&t[y]||null:y?(Hn("data",r),t=y,l):t}function a(){if(r)return l;for(;++i<n.length;){const[y,...x]=n[i];if(x[0]===!1)continue;x[0]===!0&&(x[0]=void 0);const v=y.call(l,...x);typeof v=="function"&&e.use(v)}return r=!0,i=Number.POSITIVE_INFINITY,l}function s(y,...x){let v;if(Hn("use",r),y!=null)if(typeof y=="function")k(y,...x);else if(typeof y=="object")Array.isArray(y)?j(y):C(y);else throw new TypeError("Expected usable value, not `"+y+"`");return v&&(t.settings=Object.assign(t.settings||{},v)),l;function F(b){if(typeof b=="function")k(b);else if(typeof b=="object")if(Array.isArray(b)){const[M,...q]=b;k(M,...q)}else C(b);else throw new TypeError("Expected usable value, not `"+b+"`")}function C(b){j(b.plugins),b.settings&&(v=Object.assign(v||{},b.settings))}function j(b){let M=-1;if(b!=null)if(Array.isArray(b))for(;++M<b.length;){const q=b[M];F(q)}else throw new TypeError("Expected a list of plugins, not `"+b+"`")}function k(b,M){let q=-1,Z;for(;++q<n.length;)if(n[q][0]===b){Z=n[q];break}Z?(rt(Z[1])&&rt(M)&&(M=Ut(!0,Z[1],M)),Z[1]=M):n.push([...arguments])}}function c(y){l.freeze();const x=mn(y),v=l.Parser;return $n("parse",v),Ht(v,"parse")?new v(String(x),x).parse():v(String(x),x)}function f(y,x){l.freeze();const v=mn(x),F=l.Compiler;return Un("stringify",F),Vt(y),Ht(F,"compile")?new F(y,v).compile():F(y,v)}function p(y,x,v){if(Vt(y),l.freeze(),!v&&typeof x=="function"&&(v=x,x=void 0),!v)return new Promise(F);F(null,v);function F(C,j){e.run(y,mn(x),k);function k(b,M,q){M=M||y,b?j(b):C?C(M):v(null,M,q)}}}function g(y,x){let v,F;return l.run(y,x,C),qt("runSync","run",F),v;function C(j,k){Lt(j),v=k,F=!0}}function d(y,x){if(l.freeze(),$n("process",l.Parser),Un("process",l.Compiler),!x)return new Promise(v);v(null,x);function v(F,C){const j=mn(y);l.run(l.parse(j),j,(b,M,q)=>{if(b||!M||!q)k(b);else{const Z=l.stringify(M,q);Z==null||(il(Z)?q.value=Z:q.result=Z),k(b,q)}});function k(b,M){b||!M?C(b):F?F(M):x(null,M)}}}function E(y){let x;l.freeze(),$n("processSync",l.Parser),Un("processSync",l.Compiler);const v=mn(y);return l.process(v,F),qt("processSync","process",x),v;function F(C){x=!0,Lt(C)}}}function Ht(e,n){return typeof e=="function"&&e.prototype&&(tl(e.prototype)||n in e.prototype)}function tl(e){let n;for(n in e)if(zr.call(e,n))return!0;return!1}function $n(e,n){if(typeof n!="function")throw new TypeError("Cannot `"+e+"` without `Parser`")}function Un(e,n){if(typeof n!="function")throw new TypeError("Cannot `"+e+"` without `Compiler`")}function Hn(e,n){if(n)throw new Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function Vt(e){if(!rt(e)||typeof e.type!="string")throw new TypeError("Expected node, got `"+e+"`")}function qt(e,n,t){if(!t)throw new Error("`"+e+"` finished async. Use `"+n+"` instead")}function mn(e){return rl(e)?e:new Mr(e)}function rl(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function il(e){return typeof e=="string"||Lr(e)}const ll={};function ol(e,n){const t=ll,r=typeof t.includeImageAlt=="boolean"?t.includeImageAlt:!0,i=typeof t.includeHtml=="boolean"?t.includeHtml:!0;return Nr(e,r,i)}function Nr(e,n,t){if(al(e)){if("value"in e)return e.type==="html"&&!t?"":e.value;if(n&&"alt"in e&&e.alt)return e.alt;if("children"in e)return Wt(e.children,n,t)}return Array.isArray(e)?Wt(e,n,t):""}function Wt(e,n,t){const r=[];let i=-1;for(;++i<e.length;)r[i]=Nr(e[i],n,t);return r.join("")}function al(e){return!!(e&&typeof e=="object")}function We(e,n,t,r){const i=e.length;let l=0,o;if(n<0?n=-n>i?0:i+n:n=n>i?i:n,t=t>0?t:0,r.length<1e4)o=Array.from(r),o.unshift(n,t),e.splice(...o);else for(t&&e.splice(n,t);l<r.length;)o=r.slice(l,l+1e4),o.unshift(n,0),e.splice(...o),l+=1e4,n+=1e4}function ze(e,n){return e.length>0?(We(e,e.length,0,n),e):n}const Yt={}.hasOwnProperty;function ul(e){const n={};let t=-1;for(;++t<e.length;)sl(n,e[t]);return n}function sl(e,n){let t;for(t in n){const i=(Yt.call(e,t)?e[t]:void 0)||(e[t]={}),l=n[t];let o;if(l)for(o in l){Yt.call(i,o)||(i[o]=[]);const a=l[o];cl(i[o],Array.isArray(a)?a:a?[a]:[])}}}function cl(e,n){let t=-1;const r=[];for(;++t<n.length;)(n[t].add==="after"?e:r).push(n[t]);We(e,0,0,r)}const fl=/[!-\/:-@\[-`\{-~\xA1\xA7\xAB\xB6\xB7\xBB\xBF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061D-\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u09FD\u0A76\u0AF0\u0C77\u0C84\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1B7D\u1B7E\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2308-\u230B\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E4F\u2E52-\u2E5D\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]/,qe=Ge(/[A-Za-z]/),Le=Ge(/[\dA-Za-z]/),pl=Ge(/[#-'*+\--9=?A-Z^-~]/);function it(e){return e!==null&&(e<32||e===127)}const lt=Ge(/\d/),hl=Ge(/[\dA-Fa-f]/),dl=Ge(/[!-/:-@[-`{-~]/);function V(e){return e!==null&&e<-2}function Ae(e){return e!==null&&(e<0||e===32)}function ae(e){return e===-2||e===-1||e===32}const ml=Ge(fl),gl=Ge(/\s/);function Ge(e){return n;function n(t){return t!==null&&e.test(String.fromCharCode(t))}}function ye(e,n,t,r){const i=r?r-1:Number.POSITIVE_INFINITY;let l=0;return o;function o(s){return ae(s)?(e.enter(t),a(s)):n(s)}function a(s){return ae(s)&&l++<i?(e.consume(s),a):(e.exit(t),n(s))}}const yl={tokenize:xl};function xl(e){const n=e.attempt(this.parser.constructs.contentInitial,r,i);let t;return n;function r(a){if(a===null){e.consume(a);return}return e.enter("lineEnding"),e.consume(a),e.exit("lineEnding"),ye(e,n,"linePrefix")}function i(a){return e.enter("paragraph"),l(a)}function l(a){const s=e.enter("chunkText",{contentType:"text",previous:t});return t&&(t.next=s),t=s,o(a)}function o(a){if(a===null){e.exit("chunkText"),e.exit("paragraph"),e.consume(a);return}return V(a)?(e.consume(a),e.exit("chunkText"),l):(e.consume(a),o)}}const bl={tokenize:vl},Xt={tokenize:wl};function vl(e){const n=this,t=[];let r=0,i,l,o;return a;function a(C){if(r<t.length){const j=t[r];return n.containerState=j[1],e.attempt(j[0].continuation,s,c)(C)}return c(C)}function s(C){if(r++,n.containerState._closeFlow){n.containerState._closeFlow=void 0,i&&F();const j=n.events.length;let k=j,b;for(;k--;)if(n.events[k][0]==="exit"&&n.events[k][1].type==="chunkFlow"){b=n.events[k][1].end;break}v(r);let M=j;for(;M<n.events.length;)n.events[M][1].end=Object.assign({},b),M++;return We(n.events,k+1,0,n.events.slice(j)),n.events.length=M,c(C)}return a(C)}function c(C){if(r===t.length){if(!i)return g(C);if(i.currentConstruct&&i.currentConstruct.concrete)return E(C);n.interrupt=!!(i.currentConstruct&&!i._gfmTableDynamicInterruptHack)}return n.containerState={},e.check(Xt,f,p)(C)}function f(C){return i&&F(),v(r),g(C)}function p(C){return n.parser.lazy[n.now().line]=r!==t.length,o=n.now().offset,E(C)}function g(C){return n.containerState={},e.attempt(Xt,d,E)(C)}function d(C){return r++,t.push([n.currentConstruct,n.containerState]),g(C)}function E(C){if(C===null){i&&F(),v(0),e.consume(C);return}return i=i||n.parser.flow(n.now()),e.enter("chunkFlow",{contentType:"flow",previous:l,_tokenizer:i}),y(C)}function y(C){if(C===null){x(e.exit("chunkFlow"),!0),v(0),e.consume(C);return}return V(C)?(e.consume(C),x(e.exit("chunkFlow")),r=0,n.interrupt=void 0,a):(e.consume(C),y)}function x(C,j){const k=n.sliceStream(C);if(j&&k.push(null),C.previous=l,l&&(l.next=C),l=C,i.defineSkip(C.start),i.write(k),n.parser.lazy[C.start.line]){let b=i.events.length;for(;b--;)if(i.events[b][1].start.offset<o&&(!i.events[b][1].end||i.events[b][1].end.offset>o))return;const M=n.events.length;let q=M,Z,de;for(;q--;)if(n.events[q][0]==="exit"&&n.events[q][1].type==="chunkFlow"){if(Z){de=n.events[q][1].end;break}Z=!0}for(v(r),b=M;b<n.events.length;)n.events[b][1].end=Object.assign({},de),b++;We(n.events,q+1,0,n.events.slice(M)),n.events.length=b}}function v(C){let j=t.length;for(;j-- >C;){const k=t[j];n.containerState=k[1],k[0].exit.call(n,e)}t.length=C}function F(){i.write([null]),l=void 0,i=void 0,n.containerState._closeFlow=void 0}}function wl(e,n,t){return ye(e,e.attempt(this.parser.constructs.document,n,t),"linePrefix",this.parser.constructs.disable.null.includes("codeIndented")?void 0:4)}function Qt(e){if(e===null||Ae(e)||gl(e))return 1;if(ml(e))return 2}function pt(e,n,t){const r=[];let i=-1;for(;++i<e.length;){const l=e[i].resolveAll;l&&!r.includes(l)&&(n=l(n,t),r.push(l))}return n}const ot={name:"attention",tokenize:El,resolveAll:kl};function kl(e,n){let t=-1,r,i,l,o,a,s,c,f;for(;++t<e.length;)if(e[t][0]==="enter"&&e[t][1].type==="attentionSequence"&&e[t][1]._close){for(r=t;r--;)if(e[r][0]==="exit"&&e[r][1].type==="attentionSequence"&&e[r][1]._open&&n.sliceSerialize(e[r][1]).charCodeAt(0)===n.sliceSerialize(e[t][1]).charCodeAt(0)){if((e[r][1]._close||e[t][1]._open)&&(e[t][1].end.offset-e[t][1].start.offset)%3&&!((e[r][1].end.offset-e[r][1].start.offset+e[t][1].end.offset-e[t][1].start.offset)%3))continue;s=e[r][1].end.offset-e[r][1].start.offset>1&&e[t][1].end.offset-e[t][1].start.offset>1?2:1;const p=Object.assign({},e[r][1].end),g=Object.assign({},e[t][1].start);Gt(p,-s),Gt(g,s),o={type:s>1?"strongSequence":"emphasisSequence",start:p,end:Object.assign({},e[r][1].end)},a={type:s>1?"strongSequence":"emphasisSequence",start:Object.assign({},e[t][1].start),end:g},l={type:s>1?"strongText":"emphasisText",start:Object.assign({},e[r][1].end),end:Object.assign({},e[t][1].start)},i={type:s>1?"strong":"emphasis",start:Object.assign({},o.start),end:Object.assign({},a.end)},e[r][1].end=Object.assign({},o.start),e[t][1].start=Object.assign({},a.end),c=[],e[r][1].end.offset-e[r][1].start.offset&&(c=ze(c,[["enter",e[r][1],n],["exit",e[r][1],n]])),c=ze(c,[["enter",i,n],["enter",o,n],["exit",o,n],["enter",l,n]]),c=ze(c,pt(n.parser.constructs.insideSpan.null,e.slice(r+1,t),n)),c=ze(c,[["exit",l,n],["enter",a,n],["exit",a,n],["exit",i,n]]),e[t][1].end.offset-e[t][1].start.offset?(f=2,c=ze(c,[["enter",e[t][1],n],["exit",e[t][1],n]])):f=0,We(e,r-1,t-r+3,c),t=r+c.length-f-2;break}}for(t=-1;++t<e.length;)e[t][1].type==="attentionSequence"&&(e[t][1].type="data");return e}function El(e,n){const t=this.parser.constructs.attentionMarkers.null,r=this.previous,i=Qt(r);let l;return o;function o(s){return l=s,e.enter("attentionSequence"),a(s)}function a(s){if(s===l)return e.consume(s),a;const c=e.exit("attentionSequence"),f=Qt(s),p=!f||f===2&&i||t.includes(s),g=!i||i===2&&f||t.includes(r);return c._open=!!(l===42?p:p&&(i||!g)),c._close=!!(l===42?g:g&&(f||!p)),n(s)}}function Gt(e,n){e.column+=n,e.offset+=n,e._bufferIndex+=n}const Sl={name:"autolink",tokenize:Cl};function Cl(e,n,t){let r=0;return i;function i(d){return e.enter("autolink"),e.enter("autolinkMarker"),e.consume(d),e.exit("autolinkMarker"),e.enter("autolinkProtocol"),l}function l(d){return qe(d)?(e.consume(d),o):c(d)}function o(d){return d===43||d===45||d===46||Le(d)?(r=1,a(d)):c(d)}function a(d){return d===58?(e.consume(d),r=0,s):(d===43||d===45||d===46||Le(d))&&r++<32?(e.consume(d),a):(r=0,c(d))}function s(d){return d===62?(e.exit("autolinkProtocol"),e.enter("autolinkMarker"),e.consume(d),e.exit("autolinkMarker"),e.exit("autolink"),n):d===null||d===32||d===60||it(d)?t(d):(e.consume(d),s)}function c(d){return d===64?(e.consume(d),f):pl(d)?(e.consume(d),c):t(d)}function f(d){return Le(d)?p(d):t(d)}function p(d){return d===46?(e.consume(d),r=0,f):d===62?(e.exit("autolinkProtocol").type="autolinkEmail",e.enter("autolinkMarker"),e.consume(d),e.exit("autolinkMarker"),e.exit("autolink"),n):g(d)}function g(d){if((d===45||Le(d))&&r++<63){const E=d===45?g:p;return e.consume(d),E}return t(d)}}const In={tokenize:Tl,partial:!0};function Tl(e,n,t){return r;function r(l){return ae(l)?ye(e,i,"linePrefix")(l):i(l)}function i(l){return l===null||V(l)?n(l):t(l)}}const $r={name:"blockQuote",tokenize:Pl,continuation:{tokenize:Ol},exit:Al};function Pl(e,n,t){const r=this;return i;function i(o){if(o===62){const a=r.containerState;return a.open||(e.enter("blockQuote",{_container:!0}),a.open=!0),e.enter("blockQuotePrefix"),e.enter("blockQuoteMarker"),e.consume(o),e.exit("blockQuoteMarker"),l}return t(o)}function l(o){return ae(o)?(e.enter("blockQuotePrefixWhitespace"),e.consume(o),e.exit("blockQuotePrefixWhitespace"),e.exit("blockQuotePrefix"),n):(e.exit("blockQuotePrefix"),n(o))}}function Ol(e,n,t){const r=this;return i;function i(o){return ae(o)?ye(e,l,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(o):l(o)}function l(o){return e.attempt($r,n,t)(o)}}function Al(e){e.exit("blockQuote")}const Ur={name:"characterEscape",tokenize:Rl};function Rl(e,n,t){return r;function r(l){return e.enter("characterEscape"),e.enter("escapeMarker"),e.consume(l),e.exit("escapeMarker"),i}function i(l){return dl(l)?(e.enter("characterEscapeValue"),e.consume(l),e.exit("characterEscapeValue"),e.exit("characterEscape"),n):t(l)}}const Kt=document.createElement("i");function ht(e){const n="&"+e+";";Kt.innerHTML=n;const t=Kt.textContent;return t.charCodeAt(t.length-1)===59&&e!=="semi"||t===n?!1:t}const Hr={name:"characterReference",tokenize:_l};function _l(e,n,t){const r=this;let i=0,l,o;return a;function a(p){return e.enter("characterReference"),e.enter("characterReferenceMarker"),e.consume(p),e.exit("characterReferenceMarker"),s}function s(p){return p===35?(e.enter("characterReferenceMarkerNumeric"),e.consume(p),e.exit("characterReferenceMarkerNumeric"),c):(e.enter("characterReferenceValue"),l=31,o=Le,f(p))}function c(p){return p===88||p===120?(e.enter("characterReferenceMarkerHexadecimal"),e.consume(p),e.exit("characterReferenceMarkerHexadecimal"),e.enter("characterReferenceValue"),l=6,o=hl,f):(e.enter("characterReferenceValue"),l=7,o=lt,f(p))}function f(p){if(p===59&&i){const g=e.exit("characterReferenceValue");return o===Le&&!ht(r.sliceSerialize(g))?t(p):(e.enter("characterReferenceMarker"),e.consume(p),e.exit("characterReferenceMarker"),e.exit("characterReference"),n)}return o(p)&&i++<l?(e.consume(p),f):t(p)}}const Jt={tokenize:Fl,partial:!0},Zt={name:"codeFenced",tokenize:Il,concrete:!0};function Il(e,n,t){const r=this,i={tokenize:k,partial:!0};let l=0,o=0,a;return s;function s(b){return c(b)}function c(b){const M=r.events[r.events.length-1];return l=M&&M[1].type==="linePrefix"?M[2].sliceSerialize(M[1],!0).length:0,a=b,e.enter("codeFenced"),e.enter("codeFencedFence"),e.enter("codeFencedFenceSequence"),f(b)}function f(b){return b===a?(o++,e.consume(b),f):o<3?t(b):(e.exit("codeFencedFenceSequence"),ae(b)?ye(e,p,"whitespace")(b):p(b))}function p(b){return b===null||V(b)?(e.exit("codeFencedFence"),r.interrupt?n(b):e.check(Jt,y,j)(b)):(e.enter("codeFencedFenceInfo"),e.enter("chunkString",{contentType:"string"}),g(b))}function g(b){return b===null||V(b)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),p(b)):ae(b)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),ye(e,d,"whitespace")(b)):b===96&&b===a?t(b):(e.consume(b),g)}function d(b){return b===null||V(b)?p(b):(e.enter("codeFencedFenceMeta"),e.enter("chunkString",{contentType:"string"}),E(b))}function E(b){return b===null||V(b)?(e.exit("chunkString"),e.exit("codeFencedFenceMeta"),p(b)):b===96&&b===a?t(b):(e.consume(b),E)}function y(b){return e.attempt(i,j,x)(b)}function x(b){return e.enter("lineEnding"),e.consume(b),e.exit("lineEnding"),v}function v(b){return l>0&&ae(b)?ye(e,F,"linePrefix",l+1)(b):F(b)}function F(b){return b===null||V(b)?e.check(Jt,y,j)(b):(e.enter("codeFlowValue"),C(b))}function C(b){return b===null||V(b)?(e.exit("codeFlowValue"),F(b)):(e.consume(b),C)}function j(b){return e.exit("codeFenced"),n(b)}function k(b,M,q){let Z=0;return de;function de(D){return b.enter("lineEnding"),b.consume(D),b.exit("lineEnding"),_}function _(D){return b.enter("codeFencedFence"),ae(D)?ye(b,I,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(D):I(D)}function I(D){return D===a?(b.enter("codeFencedFenceSequence"),G(D)):q(D)}function G(D){return D===a?(Z++,b.consume(D),G):Z>=o?(b.exit("codeFencedFenceSequence"),ae(D)?ye(b,ne,"whitespace")(D):ne(D)):q(D)}function ne(D){return D===null||V(D)?(b.exit("codeFencedFence"),M(D)):q(D)}}}function Fl(e,n,t){const r=this;return i;function i(o){return o===null?t(o):(e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),l)}function l(o){return r.parser.lazy[r.now().line]?t(o):n(o)}}const Vn={name:"codeIndented",tokenize:Ll},Dl={tokenize:Ml,partial:!0};function Ll(e,n,t){const r=this;return i;function i(c){return e.enter("codeIndented"),ye(e,l,"linePrefix",5)(c)}function l(c){const f=r.events[r.events.length-1];return f&&f[1].type==="linePrefix"&&f[2].sliceSerialize(f[1],!0).length>=4?o(c):t(c)}function o(c){return c===null?s(c):V(c)?e.attempt(Dl,o,s)(c):(e.enter("codeFlowValue"),a(c))}function a(c){return c===null||V(c)?(e.exit("codeFlowValue"),o(c)):(e.consume(c),a)}function s(c){return e.exit("codeIndented"),n(c)}}function Ml(e,n,t){const r=this;return i;function i(o){return r.parser.lazy[r.now().line]?t(o):V(o)?(e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),i):ye(e,l,"linePrefix",5)(o)}function l(o){const a=r.events[r.events.length-1];return a&&a[1].type==="linePrefix"&&a[2].sliceSerialize(a[1],!0).length>=4?n(o):V(o)?i(o):t(o)}}const jl={name:"codeText",tokenize:Nl,resolve:zl,previous:Bl};function zl(e){l