ondemand-react-chat-bot
Version:
OnDemandChatBot is a React library that provides an easy-to-use AI-powered chatbot component for your application. Built on top of the OnDemand platform, it allows full customization and seamless AI integration.
3 lines (2 loc) • 30.3 kB
JavaScript
;var e=require("react/jsx-runtime"),n=require("react");function t(e){var n=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})}})),n.default=e,Object.freeze(n)}var r=t(n),o=function(){return o=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var o in n=arguments[t])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e},o.apply(this,arguments)};function i(e,n,t,r){return new(t||(t=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(s,a)}c((r=r.apply(e,n||[])).next())}))}function s(e,n){var t,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(t)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(t=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=n.call(e,i)}catch(e){a=[6,e],r=0}finally{t=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function a(e,n,t){if(t||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return e.concat(r||Array.prototype.slice.call(n))}"function"==typeof SuppressedError&&SuppressedError;var c=function(n){var t=n.color;return e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:t,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-send-horizontal",children:[e.jsx("path",{d:"M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z"}),e.jsx("path",{d:"M6 12h16"})]})},l=function(n){var t=n.color;return e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:t,"stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round",className:"lucide lucide-circle-x",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"m15 9-6 6"}),e.jsx("path",{d:"m9 9 6 6"})]})},u=function(n){var t=n.color;return e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:t,"stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",className:"lucide lucide-bot",children:[e.jsx("path",{d:"M12 8V4H8"}),e.jsx("rect",{width:"16",height:"12",x:"4",y:"8",rx:"2"}),e.jsx("path",{d:"M2 14h2"}),e.jsx("path",{d:"M20 14h2"}),e.jsx("path",{d:"M15 13v2"}),e.jsx("path",{d:"M9 13v2"})]})},d={"Analyzing the prompt...":"We're carefully reviewing your request.","Re-analyzing the prompt...":"Checking again to ensure everything is accurate!","Analysis failed":"We couldn't process your request. Please try again with more details.","Execution plan created":"We've mapped out the next steps for you.","Retrieved the agents":"We've found the right tools to assist you.","Executing the agents...":"Processing your request now...","Agents execution completed":"All done! Here's what we found for you.","Agents execution failed":"We ran into an issue while working on your request. Please try again.","Execution log created":"Your request details have been recorded for reference.","Fulfilling the prompt...":"Almost there! We're putting everything together.","Fulfillment completed":"Success! Your request has been completed.","Fulfillment failed":"We hit a snag while finishing up. Please try again or reach out for help."},p=function(e,n){e((function(e){return a(a([],e,!0),[o({message:"",isFetching:!1,id:Date.now().toString(),author:"bot",status:"loading"},n)],!1)}))},f=function(e,n){e((function(e){return a(a([],e.slice(0,-1),!0),[o(o({},e[e.length-1]),"function"==typeof n?n(e[e.length-1]):n)],!1)}))},h=function(e){return"dev"===e?"https://gateway-dev.on-demand.io":"https://api.on-demand.io"};function m(e,n,t,r){return i(this,void 0,void 0,(function(){var o,i,a,c,l,u;return s(this,(function(s){switch(s.label){case 0:return s.trys.push([0,3,,4]),o={pluginIds:[],externalUserId:"1",contextMetadata:r},i=h(n),[4,fetch("".concat(i,"/chat/v1/sessions"),{method:"POST",headers:{"Content-Type":"application/json","x-bot-id":t,apikey:e},body:JSON.stringify(o)})];case 1:if(!(a=s.sent()).ok)throw new Error("HTTP error! status: ".concat(a.status));return[4,a.json()];case 2:return c=s.sent(),[2,null===(u=null==c?void 0:c.data)||void 0===u?void 0:u.id];case 3:throw l=s.sent(),console.error("Failed to generate session:",l),l;case 4:return[2]}}))}))}function g(e,n,t){return i(this,void 0,void 0,(function(){var r,o,i;return s(this,(function(s){switch(s.label){case 0:return s.trys.push([0,3,,4]),r=h(t),[4,fetch("".concat(r,"/config/v1/public/embedded/chatbot/").concat(n),{method:"GET",headers:{"Content-Type":"application/json","x-bot-id":n,apikey:e}})];case 1:if(!(o=s.sent()).ok)throw new Error("HTTP error! status: ".concat(o.status));return[4,o.json()];case 2:return[2,s.sent().data];case 3:throw i=s.sent(),console.error("Failed to get bot configuration:",i),i;case 4:return[2]}}))}))}var y=function(n){var t=n.input,r=n.setInput,o=n.isInputDisabled,i=n.botConfig,s=n.onSubmit;return e.jsx("div",{className:"chat-input-container",children:e.jsxs("form",{onSubmit:s,className:"chat-form",children:[e.jsx("input",{type:"text",value:t,disabled:o,onChange:function(e){return r(e.target.value)},placeholder:i.inputPlaceholder,className:"chat-input"}),e.jsx("button",{type:"submit",disabled:o||!t.trim(),className:"send-button",style:{background:i.primaryColor},children:e.jsx(c,{color:i.secondaryColor})})]})})};function b(){return b=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},b.apply(this,arguments)}const v=["children","options"],x="0",k="1",w="2",j="3",C="4",E="5",S="6",I="7",O="8",N="9",T="10",z="11",A="12",M="13",$="14",P="15",L="16",F="17",R="18",D="19",q="20",W="21",B="22",H="23",U="24",_="25",V="27",G="28",Z="29",J="30",X="31",Y="32",K="33";var Q;!function(e){e[e.MAX=0]="MAX",e[e.HIGH=1]="HIGH",e[e.MED=2]="MED",e[e.LOW=3]="LOW",e[e.MIN=4]="MIN"}(Q||(Q={}));const ee=["allowFullScreen","allowTransparency","autoComplete","autoFocus","autoPlay","cellPadding","cellSpacing","charSet","classId","colSpan","contentEditable","contextMenu","crossOrigin","encType","formAction","formEncType","formMethod","formNoValidate","formTarget","frameBorder","hrefLang","inputMode","keyParams","keyType","marginHeight","marginWidth","maxLength","mediaGroup","minLength","noValidate","radioGroup","readOnly","rowSpan","spellCheck","srcDoc","srcLang","srcSet","tabIndex","useMap"].reduce(((e,n)=>(e[n.toLowerCase()]=n,e)),{class:"className",for:"htmlFor"}),ne={amp:"&",apos:"'",gt:">",lt:"<",nbsp:" ",quot:"“"},te=["style","script"],re=/([-A-Z0-9_:]+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|(?:\{((?:\\.|{[^}]*?}|[^}])*)\})))?/gi,oe=/mailto:/i,ie=/\n{2,}$/,se=/^(\s*>[\s\S]*?)(?=\n\n|$)/,ae=/^ *> ?/gm,ce=/^(?:\[!([^\]]*)\]\n)?([\s\S]*)/,le=/^ {2,}\n/,ue=/^(?:( *[-*_])){3,} *(?:\n *)+\n/,de=/^(?: {1,3})?(`{3,}|~{3,}) *(\S+)? *([^\n]*?)?\n([\s\S]*?)(?:\1\n?|$)/,pe=/^(?: {4}[^\n]+\n*)+(?:\n *)+\n?/,fe=/^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,he=/^(?:\n *)*\n/,me=/\r\n?/g,ge=/^\[\^([^\]]+)](:(.*)((\n+ {4,}.*)|(\n(?!\[\^).+))*)/,ye=/^\[\^([^\]]+)]/,be=/\f/g,ve=/^---[ \t]*\n(.|\n)*\n---[ \t]*\n/,xe=/^\s*?\[(x|\s)\]/,ke=/^ *(#{1,6}) *([^\n]+?)(?: +#*)?(?:\n *)*(?:\n|$)/,we=/^ *(#{1,6}) +([^\n]+?)(?: +#*)?(?:\n *)*(?:\n|$)/,je=/^([^\n]+)\n *(=|-){3,} *(?:\n *)+\n/,Ce=/^ *(?!<[a-z][^ >/]* ?\/>)<([a-z][^ >/]*) ?((?:[^>]*[^/])?)>\n?(\s*(?:<\1[^>]*?>[\s\S]*?<\/\1>|(?!<\1\b)[\s\S])*?)<\/\1>(?!<\/\1>)\n*/i,Ee=/&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});/gi,Se=/^<!--[\s\S]*?(?:-->)/,Ie=/^(data|aria|x)-[a-z_][a-z\d_.-]*$/,Oe=/^ *<([a-z][a-z0-9:]*)(?:\s+((?:<.*?>|[^>])*))?\/?>(?!<\/\1>)(\s*\n)?/i,Ne=/^\{.*\}$/,Te=/^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,ze=/^<([^ >]+@[^ >]+)>/,Ae=/^<([^ >]+:\/[^ >]+)>/,Me=/-([a-z])?/gi,$e=/^(\|.*)\n(?: *(\|? *[-:]+ *\|[-| :]*)\n((?:.*\|.*\n)*))?\n?/,Pe=/^\[([^\]]*)\]:\s+<?([^\s>]+)>?\s*("([^"]*)")?/,Le=/^!\[([^\]]*)\] ?\[([^\]]*)\]/,Fe=/^\[([^\]]*)\] ?\[([^\]]*)\]/,Re=/(\n|^[-*]\s|^#|^ {2,}|^-{2,}|^>\s)/,De=/\t/g,qe=/(^ *\||\| *$)/g,We=/^ *:-+: *$/,Be=/^ *:-+ *$/,He=/^ *-+: *$/,Ue="((?:\\[.*?\\][([].*?[)\\]]|<.*?>(?:.*?<.*?>)?|`.*?`|~~.*?~~|==.*?==|.|\\n)*?)",_e=new RegExp(`^([*_])\\1${Ue}\\1\\1(?!\\1)`),Ve=new RegExp(`^([*_])${Ue}\\1(?!\\1|\\w)`),Ge=new RegExp(`^==${Ue}==`),Ze=new RegExp(`^~~${Ue}~~`),Je=/^\\([^0-9A-Za-z\s])/,Xe=/^[\s\S]+?(?=[^0-9A-Z\s\u00c0-\uffff&#;.()'"]|\d+\.|\n\n| {2,}\n|\w+:\S|$)/i,Ye=/^\n+/,Ke=/^([ \t]*)/,Qe=/\\([^\\])/g,en=/ *\n+$/,nn=/(?:^|\n)( *)$/,tn="(?:\\d+\\.)",rn="(?:[*+-])";function on(e){return"( *)("+(1===e?tn:rn)+") +"}const sn=on(1),an=on(2);function cn(e){return new RegExp("^"+(1===e?sn:an))}const ln=cn(1),un=cn(2);function dn(e){return new RegExp("^"+(1===e?sn:an)+"[^\\n]*(?:\\n(?!\\1"+(1===e?tn:rn)+" )[^\\n]*)*(\\n|$)","gm")}const pn=dn(1),fn=dn(2);function hn(e){const n=1===e?tn:rn;return new RegExp("^( *)("+n+") [\\s\\S]+?(?:\\n{2,}(?! )(?!\\1"+n+" (?!"+n+" ))\\n*|\\s*\\n*$)")}const mn=hn(1),gn=hn(2);function yn(e,n){const t=1===n,r=t?mn:gn,o=t?pn:fn,i=t?ln:un;return{match(e,n){const t=nn.exec(n.prevCapture);return t&&(n.list||!n.inline&&!n.simple)?r.exec(e=t[1]+e):null},order:1,parse(e,n,r){const s=t?+e[2]:void 0,a=e[0].replace(ie,"\n").match(o);let c=!1;return{items:a.map((function(e,t){const o=i.exec(e)[0].length,s=new RegExp("^ {1,"+o+"}","gm"),l=e.replace(s,"").replace(i,""),u=t===a.length-1,d=-1!==l.indexOf("\n\n")||u&&c;c=d;const p=r.inline,f=r.list;let h;r.list=!0,d?(r.inline=!1,h=l.replace(en,"\n\n")):(r.inline=!0,h=l.replace(en,""));const m=n(h,r);return r.inline=p,r.list=f,m})),ordered:t,start:s}},render:(n,t,r)=>e(n.ordered?"ol":"ul",{key:r.key,start:n.type===q?n.start:void 0},n.items.map((function(n,o){return e("li",{key:o},t(n,r))})))}}const bn=new RegExp("^\\[((?:\\[[^\\]]*\\]|[^\\[\\]]|\\](?=[^\\[]*\\]))*)\\]\\(\\s*<?((?:\\([^)]*\\)|[^\\s\\\\]|\\\\.)*?)>?(?:\\s+['\"]([\\s\\S]*?)['\"])?\\s*\\)"),vn=/^!\[(.*?)\]\( *((?:\([^)]*\)|[^() ])*) *"?([^)"]*)?"?\)/,xn=[se,de,pe,ke,je,we,Se,$e,pn,mn,fn,gn],kn=[...xn,/^[^\n]+(?: \n|\n{2,})/,Ce,Oe];function wn(e){return e.replace(/[ÀÁÂÃÄÅàáâãä忯]/g,"a").replace(/[çÇ]/g,"c").replace(/[ðÐ]/g,"d").replace(/[ÈÉÊËéèêë]/g,"e").replace(/[ÏïÎîÍíÌì]/g,"i").replace(/[Ññ]/g,"n").replace(/[øØœŒÕõÔôÓóÒò]/g,"o").replace(/[ÜüÛûÚúÙù]/g,"u").replace(/[ŸÿÝý]/g,"y").replace(/[^a-z0-9- ]/gi,"").replace(/ /gi,"-").toLowerCase()}function jn(e){return He.test(e)?"right":We.test(e)?"center":Be.test(e)?"left":null}function Cn(e,n,t,r){const o=t.inTable;t.inTable=!0;let i=[[]],s="";function a(){if(!s)return;const e=i[i.length-1];e.push.apply(e,n(s,t)),s=""}return e.trim().split(/(`[^`]*`|\\\||\|)/).filter(Boolean).forEach(((e,n,t)=>{"|"===e.trim()&&(a(),r)?0!==n&&n!==t.length-1&&i.push([]):s+=e})),a(),t.inTable=o,i}function En(e,n,t){t.inline=!0;const r=e[2]?e[2].replace(qe,"").split("|").map(jn):[],o=e[3]?function(e,n,t){return e.trim().split("\n").map((function(e){return Cn(e,n,t,!0)}))}(e[3],n,t):[],i=Cn(e[1],n,t,!!o.length);return t.inline=!1,o.length?{align:r,cells:o,header:i,type:_}:{children:i,type:W}}function Sn(e,n){return null==e.align[n]?{}:{textAlign:e.align[n]}}function In(e){return function(n,t){return t.inline?e.exec(n):null}}function On(e){return function(n,t){return t.inline||t.simple?e.exec(n):null}}function Nn(e){return function(n,t){return t.inline||t.simple?null:e.exec(n)}}function Tn(e){return function(n){return e.exec(n)}}function zn(e,n){if(n.inline||n.simple)return null;let t="";e.split("\n").every((e=>(e+="\n",!xn.some((n=>n.test(e)))&&(t+=e,!!e.trim()))));const r=t.trimEnd();return""==r?null:[t,r]}function An(e){try{if(decodeURIComponent(e).replace(/[^A-Za-z0-9/:]/g,"").match(/^\s*(javascript|vbscript|data(?!:image)):/i))return null}catch(e){return null}return e}function Mn(e){return e.replace(Qe,"$1")}function $n(e,n,t){const r=t.inline||!1,o=t.simple||!1;t.inline=!0,t.simple=!0;const i=e(n,t);return t.inline=r,t.simple=o,i}function Pn(e,n,t){const r=t.inline||!1,o=t.simple||!1;t.inline=!1,t.simple=!0;const i=e(n,t);return t.inline=r,t.simple=o,i}function Ln(e,n,t){const r=t.inline||!1;t.inline=!1;const o=e(n,t);return t.inline=r,o}const Fn=(e,n,t)=>({children:$n(n,e[1],t)});function Rn(){return{}}function Dn(){return null}function qn(...e){return e.filter(Boolean).join(" ")}function Wn(e,n,t){let r=e;const o=n.split(".");for(;o.length&&(r=r[o[0]],void 0!==r);)o.shift();return r||t}function Bn(e="",n={}){function t(e,t,...r){const o=Wn(n.overrides,`${e}.props`,{});return n.createElement(function(e,n){const t=Wn(n,e);return t?"function"==typeof t||"object"==typeof t&&"render"in t?t:Wn(n,`${e}.component`,e):e}(e,n.overrides),b({},t,o,{className:qn(null==t?void 0:t.className,o.className)||void 0}),...r)}function o(e){e=e.replace(ve,"");let r=!1;n.forceInline?r=!0:n.forceBlock||(r=!1===Re.test(e));const o=u(l(r?e:`${e.trimEnd().replace(Ye,"")}\n\n`,{inline:r}));for(;"string"==typeof o[o.length-1]&&!o[o.length-1].trim();)o.pop();if(null===n.wrapper)return o;const i=n.wrapper||(r?"span":"div");let s;if(o.length>1||n.forceWrapper)s=o;else{if(1===o.length)return s=o[0],"string"==typeof s?t("span",{key:"outer"},s):s;s=null}return n.createElement(i,{key:"outer"},s)}function i(e,t){const r=t.match(re);return r?r.reduce((function(t,r){const i=r.indexOf("=");if(-1!==i){const s=function(e){return-1!==e.indexOf("-")&&null===e.match(Ie)&&(e=e.replace(Me,(function(e,n){return n.toUpperCase()}))),e}(r.slice(0,i)).trim(),a=function(e){const n=e[0];return('"'===n||"'"===n)&&e.length>=2&&e[e.length-1]===n?e.slice(1,-1):e}(r.slice(i+1).trim()),c=ee[s]||s;if("ref"===c)return t;const l=t[c]=function(e,n,t,r){return"style"===n?t.split(/;\s?/).reduce((function(e,n){const t=n.slice(0,n.indexOf(":"));return e[t.trim().replace(/(-[a-z])/g,(e=>e[1].toUpperCase()))]=n.slice(t.length+1).trim(),e}),{}):"href"===n||"src"===n?r(t,e,n):(t.match(Ne)&&(t=t.slice(1,t.length-1)),"true"===t||"false"!==t&&t)}(e,s,a,n.sanitizer);"string"==typeof l&&(Ce.test(l)||Oe.test(l))&&(t[c]=o(l.trim()))}else"style"!==r&&(t[ee[r]||r]=!0);return t}),{}):null}n.overrides=n.overrides||{},n.sanitizer=n.sanitizer||An,n.slugify=n.slugify||wn,n.namedCodesToUnicode=n.namedCodesToUnicode?b({},ne,n.namedCodesToUnicode):ne,n.createElement=n.createElement||r.createElement;const s=[],a={},c={[x]:{match:Nn(se),order:1,parse(e,n,t){const[,r,o]=e[0].replace(ae,"").match(ce);return{alert:r,children:n(o,t)}},render(e,r,o){const i={key:o.key};return e.alert&&(i.className="markdown-alert-"+n.slugify(e.alert.toLowerCase(),wn),e.children.unshift({attrs:{},children:[{type:V,text:e.alert}],noInnerParse:!0,type:z,tag:"header"})),t("blockquote",i,r(e.children,o))}},[k]:{match:Tn(le),order:1,parse:Rn,render:(e,n,r)=>t("br",{key:r.key})},[w]:{match:Nn(ue),order:1,parse:Rn,render:(e,n,r)=>t("hr",{key:r.key})},[j]:{match:Nn(pe),order:0,parse:e=>({lang:void 0,text:e[0].replace(/^ {4}/gm,"").replace(/\n+$/,"")}),render:(e,n,r)=>t("pre",{key:r.key},t("code",b({},e.attrs,{className:e.lang?`lang-${e.lang}`:""}),e.text))},[C]:{match:Nn(de),order:0,parse:e=>({attrs:i("code",e[3]||""),lang:e[2]||void 0,text:e[4],type:j})},[E]:{match:On(fe),order:3,parse:e=>({text:e[2]}),render:(e,n,r)=>t("code",{key:r.key},e.text)},[S]:{match:Nn(ge),order:0,parse:e=>(s.push({footnote:e[2],identifier:e[1]}),{}),render:Dn},[I]:{match:In(ye),order:1,parse:e=>({target:`#${n.slugify(e[1],wn)}`,text:e[1]}),render:(e,r,o)=>t("a",{key:o.key,href:n.sanitizer(e.target,"a","href")},t("sup",{key:o.key},e.text))},[O]:{match:In(xe),order:1,parse:e=>({completed:"x"===e[1].toLowerCase()}),render:(e,n,r)=>t("input",{checked:e.completed,key:r.key,readOnly:!0,type:"checkbox"})},[N]:{match:Nn(n.enforceAtxHeadings?we:ke),order:1,parse:(e,t,r)=>({children:$n(t,e[2],r),id:n.slugify(e[2],wn),level:e[1].length}),render:(e,n,r)=>t(`h${e.level}`,{id:e.id,key:r.key},n(e.children,r))},[T]:{match:Nn(je),order:0,parse:(e,n,t)=>({children:$n(n,e[1],t),level:"="===e[2]?1:2,type:N})},[z]:{match:Tn(Ce),order:1,parse(e,n,t){const[,r]=e[3].match(Ke),o=new RegExp(`^${r}`,"gm"),s=e[3].replace(o,""),a=(c=s,kn.some((e=>e.test(c)))?Ln:$n);var c;const l=e[1].toLowerCase(),u=-1!==te.indexOf(l),d=(u?l:e[1]).trim(),p={attrs:i(d,e[2]),noInnerParse:u,tag:d};return t.inAnchor=t.inAnchor||"a"===l,u?p.text=e[3]:p.children=a(n,s,t),t.inAnchor=!1,p},render:(e,n,r)=>t(e.tag,b({key:r.key},e.attrs),e.text||(e.children?n(e.children,r):""))},[M]:{match:Tn(Oe),order:1,parse(e){const n=e[1].trim();return{attrs:i(n,e[2]||""),tag:n}},render:(e,n,r)=>t(e.tag,b({},e.attrs,{key:r.key}))},[A]:{match:Tn(Se),order:1,parse:()=>({}),render:Dn},[$]:{match:On(vn),order:1,parse:e=>({alt:e[1],target:Mn(e[2]),title:e[3]}),render:(e,r,o)=>t("img",{key:o.key,alt:e.alt||void 0,title:e.title||void 0,src:n.sanitizer(e.target,"img","src")})},[P]:{match:In(bn),order:3,parse:(e,n,t)=>({children:Pn(n,e[1],t),target:Mn(e[2]),title:e[3]}),render:(e,r,o)=>t("a",{key:o.key,href:n.sanitizer(e.target,"a","href"),title:e.title},r(e.children,o))},[L]:{match:In(Ae),order:0,parse:e=>({children:[{text:e[1],type:V}],target:e[1],type:P})},[F]:{match:(e,t)=>t.inAnchor||n.disableAutoLink?null:In(Te)(e,t),order:0,parse:e=>({children:[{text:e[1],type:V}],target:e[1],title:void 0,type:P})},[R]:{match:In(ze),order:0,parse(e){let n=e[1],t=e[1];return oe.test(t)||(t="mailto:"+t),{children:[{text:n.replace("mailto:",""),type:V}],target:t,type:P}}},[q]:yn(t,1),[K]:yn(t,2),[D]:{match:Nn(he),order:3,parse:Rn,render:()=>"\n"},[W]:{match:zn,order:3,parse:Fn,render:(e,n,r)=>t("p",{key:r.key},n(e.children,r))},[B]:{match:In(Pe),order:0,parse:e=>(a[e[1]]={target:e[2],title:e[4]},{}),render:Dn},[H]:{match:On(Le),order:0,parse:e=>({alt:e[1]||void 0,ref:e[2]}),render:(e,r,o)=>a[e.ref]?t("img",{key:o.key,alt:e.alt,src:n.sanitizer(a[e.ref].target,"img","src"),title:a[e.ref].title}):null},[U]:{match:In(Fe),order:0,parse:(e,n,t)=>({children:n(e[1],t),fallbackChildren:e[0],ref:e[2]}),render:(e,r,o)=>a[e.ref]?t("a",{key:o.key,href:n.sanitizer(a[e.ref].target,"a","href"),title:a[e.ref].title},r(e.children,o)):t("span",{key:o.key},e.fallbackChildren)},[_]:{match:Nn($e),order:1,parse:En,render(e,n,r){const o=e;return t("table",{key:r.key},t("thead",null,t("tr",null,o.header.map((function(e,i){return t("th",{key:i,style:Sn(o,i)},n(e,r))})))),t("tbody",null,o.cells.map((function(e,i){return t("tr",{key:i},e.map((function(e,i){return t("td",{key:i,style:Sn(o,i)},n(e,r))})))}))))}},[V]:{match:Tn(Xe),order:4,parse:e=>({text:e[0].replace(Ee,((e,t)=>n.namedCodesToUnicode[t]?n.namedCodesToUnicode[t]:e))}),render:e=>e.text},[G]:{match:On(_e),order:2,parse:(e,n,t)=>({children:n(e[2],t)}),render:(e,n,r)=>t("strong",{key:r.key},n(e.children,r))},[Z]:{match:On(Ve),order:3,parse:(e,n,t)=>({children:n(e[2],t)}),render:(e,n,r)=>t("em",{key:r.key},n(e.children,r))},[J]:{match:On(Je),order:1,parse:e=>({text:e[1],type:V})},[X]:{match:On(Ge),order:3,parse:Fn,render:(e,n,r)=>t("mark",{key:r.key},n(e.children,r))},[Y]:{match:On(Ze),order:3,parse:Fn,render:(e,n,r)=>t("del",{key:r.key},n(e.children,r))}};!0===n.disableParsingRawHTML&&(delete c[z],delete c[M]);const l=function(e){let n=Object.keys(e);function t(r,o){let i=[];for(o.prevCapture=o.prevCapture||"";r;){let s=0;for(;s<n.length;){const a=n[s],c=e[a],l=c.match(r,o);if(l){const e=l[0];o.prevCapture+=e,r=r.substring(e.length);const n=c.parse(l,t,o);null==n.type&&(n.type=a),i.push(n);break}s++}}return o.prevCapture="",i}return n.sort((function(n,t){let r=e[n].order,o=e[t].order;return r!==o?r-o:n<t?-1:1})),function(e,n){return t(function(e){return e.replace(me,"\n").replace(be,"").replace(De," ")}(e),n)}}(c),u=(d=function(e,n){return function(t,r,o){const i=e[t.type].render;return n?n((()=>i(t,r,o)),t,r,o):i(t,r,o)}}(c,n.renderRule),function e(n,t={}){if(Array.isArray(n)){const r=t.key,o=[];let i=!1;for(let r=0;r<n.length;r++){t.key=r;const s=e(n[r],t),a="string"==typeof s;a&&i?o[o.length-1]+=s:null!==s&&o.push(s),i=a}return t.key=r,o}return d(n,e,t)});var d;const p=o(e);return s.length?t("div",null,p,t("footer",{key:"footer"},s.map((function(e){return t("div",{id:n.slugify(e.identifier,wn),key:e.identifier},e.identifier,u(l(e.footnote,{inline:!0})))})))):p}var Hn=e=>{let{children:n="",options:t}=e,o=function(e,n){if(null==e)return{};var t,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)n.indexOf(t=i[r])>=0||(o[t]=e[t]);return o}(e,v);return r.cloneElement(Bn(n,t),o)},Un=function(t){var r=t.message,o=t.botConfig,i=n.useRef(null);return n.useEffect((function(){i.current&&i.current.scrollIntoView({behavior:"smooth"})}),[r]),e.jsx("div",{ref:i,className:"message-wrapper ".concat("user"===r.author?"user":"ai"),children:e.jsxs("div",{className:"message ".concat("user"===r.author?"user":"ai"," "),style:{background:"user"===r.author?o.primaryColor:"primaryColor",color:"user"===r.author?o.secondaryColor:""},children:[r.isFetching&&e.jsx("div",{className:"loader"}),e.jsx(Hn,{className:"loading"===r.status?"shine":"",children:r.message})]})})};!function(e,n){void 0===n&&(n={});var t=n.insertAt;if("undefined"!=typeof document){var r=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===t&&r.firstChild?r.insertBefore(o,r.firstChild):r.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}("* {\n font-family: sans-serif;\n}\n.ai-chat-container {\n position: fixed;\n bottom: 1rem;\n right: 1rem;\n z-index: 50;\n}\n\n.help-button {\n cursor: pointer;\n background-color: black;\n color: #000000;\n border-width: 0;\n padding: 0.8rem 0.8rem;\n color: white;\n border-radius: 9999px;\n transition: background-color 0.3s;\n}\n\n.chat-window {\n display: flex;\n flex-direction: column;\n height: 35rem;\n width: 25rem;\n background-color: white;\n border-radius: 0.5rem;\n box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);\n}\n\n.chat-header {\n display: flex;\n align-items: center;\n justify-content: space-between;\n background-color: black;\n height: 3.5rem;\n padding: 0 0.5rem;\n border-top-left-radius: 0.5rem;\n border-top-right-radius: 0.5rem;\n color: white;\n}\n\n.cancel {\n cursor: pointer;\n color: white;\n border-width: 0;\n background: transparent;\n}\n\n.messages-container {\n flex: 1;\n overflow-y: auto;\n padding: 1rem;\n scroll-behavior: smooth;\n}\n\n.messages-container::-webkit-scrollbar {\n width: 6px;\n}\n\n.messages-container::-webkit-scrollbar-track {\n background: transparent;\n}\n\n.messages-container::-webkit-scrollbar-thumb {\n background-color: rgba(0, 0, 0, 0.2);\n border-radius: 3px;\n}\n\n.message-wrapper {\n display: flex;\n margin-bottom: 1rem;\n}\n\n.message-wrapper.user {\n justify-content: flex-end;\n}\n\n.message-wrapper.ai {\n justify-content: flex-start;\n}\n\n.message {\n max-width: 80%;\n padding: 0.75rem;\n border-radius: 0.5rem;\n font-size: 1rem;\n line-height: 1.4;\n letter-spacing: 0ch;\n}\n\n.message.user {\n background-color: #000000;\n color: white;\n}\n\n.message.ai {\n background-color: #f3f4f6;\n color: #1f2937;\n}\n\n.welcome-message {\n padding: 0.2rem 1rem;\n font-size: 1rem;\n font-weight: 500;\n color: #0d0d0d52;\n}\n\n.welcome-message span {\n font-weight: 600;\n color: #adedd5;\n}\n\n.chat-input-container {\n border-top: 1px solid #e5e7eb;\n padding: 1rem;\n}\n\n.chat-form {\n display: flex;\n gap: 0.5rem;\n}\n\n.chat-input {\n flex: 1;\n padding: 0.75rem;\n border: 1px solid #1e1e1e18;\n border-radius: 0.5rem;\n font-size: 0.875rem;\n transition: border-color 0.3s;\n}\n\n.chat-input:focus {\n outline: none;\n box-shadow: 0 0 0 2px rgba(173, 237, 213, 0.2);\n}\n\n.chat-input:disabled {\n background-color: #f3f4f6;\n cursor: not-allowed;\n}\n\n.send-button {\n border-width: 0;\n color: white;\n padding: 0.5rem 0.75rem;\n border-radius: 0.5rem;\n transition: background-color 0.3s;\n cursor: pointer;\n}\n\n.send-button:disabled {\n opacity: 0.7;\n cursor: not-allowed;\n}\n\n.loader {\n width: 20px;\n aspect-ratio: 2;\n --_g: no-repeat radial-gradient(circle closest-side, #000 90%, #0000);\n background: var(--_g) 0% 50%, var(--_g) 50% 50%, var(--_g) 100% 50%;\n background-size: calc(100% / 3) 50%;\n animation: l3 1s infinite linear;\n}\n@keyframes l3 {\n 20% {\n background-position: 0% 0%, 50% 50%, 100% 50%;\n }\n 40% {\n background-position: 0% 100%, 50% 0%, 100% 50%;\n }\n 60% {\n background-position: 0% 50%, 50% 100%, 100% 0%;\n }\n 80% {\n background-position: 0% 50%, 50% 50%, 100% 100%;\n }\n}\n\n.shine {\n font-size: 0.8rem;\n animation: blink 2s linear infinite;\n}\n\n@keyframes blink {\n 0% {\n opacity: 0.4;\n }\n 50% {\n opacity: 0.8;\n }\n 100% {\n opacity: 0.4;\n }\n}\n");exports.OnDemandChatBot=function(t){var r=t.environment,o=void 0===r?"prod":r,a=t.apiKey,c=t.botId,b=t.contextVariables,v=n.useState(!1),x=v[0],k=v[1],w=n.useState([]),j=w[0],C=w[1],E=n.useState(!1),S=E[0],I=E[1],O=n.useState(""),N=O[0],T=O[1],z=n.useState(""),A=z[0],M=z[1],$=n.useState(),P=$[0],L=$[1],F=function(e){return{sendMessage:function(n){return i(void 0,[n],void 0,(function(n){var t,r,o,i,a,c,l,u,g,y,b,v,x,k,w,j,C,E,S=n.environment,I=n.modelEndpointId,O=n.input,N=n.setMessages,T=n.sessionId,z=n.setInput,A=n.setIsInputDisabled,M=n.setSessionId,$=n.moreAddedAgents,P=n.fulfillmentPrompt,L=n.contextVariables,F=n.botId;return s(this,(function(n){switch(n.label){case 0:if(!O)return[2];p(N,{message:O,author:"user",isFetching:!1,id:Date.now().toString(),status:"complete"}),p(N,{author:"bot",isFetching:!0,status:"loading"}),A(!0),z(""),n.label=1;case 1:return n.trys.push([1,8,9,10]),(t=T)?[3,3]:[4,m(e,S,F,L)];case 2:r=n.sent(),M(t=r),n.label=3;case 3:return o={endpointId:I,query:O,pluginIds:$,responseMode:"stream",debugMode:"on",reasoningMode:"low",modelConfigs:{frequencyPenalty:0,fulfillmentPrompt:P,presencePenalty:0,stopTokens:[],temperature:.3,topP:.9}},i=h(S),[4,fetch("".concat(i,"/chat/v1/sessions/").concat(t,"/query"),{method:"POST",headers:{"Content-Type":"application/json","x-bot-id":F,apikey:e},body:JSON.stringify(o)})];case 4:a=n.sent(),c=null===(E=a.body)||void 0===E?void 0:E.getReader(),l=new TextDecoder("utf-8"),n.label=5;case 5:return[4,c.read()];case 6:if(u=n.sent(),g=u.done,y=u.value,g)return[3,7];for(b=l.decode(y),v=b.split("\n").map((function(e){return e.replace(/^data:/,"").trim()})).filter((function(e){return"event:message"!==e&&"[DONE]"!==e&&""!==e})).map((function(e){return JSON.parse(e)})),x=function(e){"statusLog"===e.eventType&&"Fulfillment completed"!==e.currentStatusLog.statusMessage?f(N,{message:d[e.currentStatusLog.statusMessage],isFetching:!1,status:"loading"}):"fulfillment"===e.eventType&&f(N,(function(n){return{message:"loading"===(null==n?void 0:n.status)?e.answer:n.message+e.answer,status:"streaming",isFetching:!1}}))},k=0,w=v;k<w.length;k++)j=w[k],x(j);return[3,5];case 7:return[3,10];case 8:return C=n.sent(),console.error("Error sending message:",C),f(N,{message:"An error occurred while processing your request.",status:"error",isFetching:!1}),[3,10];case 9:return A(!1),[7];case 10:return[2]}}))}))}}}(a).sendMessage,R=n.useRef(null),D=function(e){R.current&&!R.current.contains(e.target)&&k(!1)};return n.useEffect((function(){i(void 0,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return[4,g(a,c,o)];case 1:return e=n.sent(),L(e),0===j.length&&C([{message:e.introductoryMessage,author:"bot",isFetching:!1,id:Date.now().toString(),status:"complete"}]),[2]}}))}))}),[]),n.useEffect((function(){return x?(document.body.style.overflow="hidden",document.addEventListener("mousedown",D),function(){document.body.style.overflow="",document.removeEventListener("mousedown",D)}):(document.body.style.overflow="",void document.removeEventListener("mousedown",D))}),[x]),P?e.jsx("div",{className:"ai-chat-container",children:x?e.jsxs("div",{ref:R,className:"chat-window",children:[e.jsxs("div",{className:"chat-header",style:{background:P.primaryColor},children:[e.jsx("img",{src:P.logoUrl,style:{height:"2rem",paddingLeft:"0.5rem"},alt:"Bot Logo"}),e.jsx("button",{onClick:function(){return k(!1)},className:"cancel",children:e.jsx(l,{color:P.secondaryColor})})]}),e.jsx("div",{className:"messages-container",children:j.map((function(n){return e.jsx(Un,{message:n,botConfig:P},n.id)}))}),e.jsx(y,{input:N,setInput:T,isInputDisabled:S,botConfig:P,onSubmit:function(e){return i(void 0,void 0,void 0,(function(){return s(this,(function(n){switch(n.label){case 0:return e.preventDefault(),N.trim()?[4,F({reasoningMode:null==P?void 0:P.reasoningMode,input:N,sessionId:A,setMessages:C,messages:j,setInput:T,setIsInputDisabled:I,setSessionId:M,moreAddedAgents:null==P?void 0:P.chatPluginIds,fulfillmentPrompt:null==P?void 0:P.fulfillmentPrompt,modelEndpointId:null==P?void 0:P.modelEndpointId,environment:o,botId:c,contextVariables:b})]:[2];case 1:return n.sent(),T(""),[2]}}))}))}})]}):e.jsx("button",{onClick:function(){return k(!0)},className:"help-button",style:{background:P.primaryColor,color:P.secondaryColor},children:e.jsx(u,{color:P.secondaryColor})})}):null};
//# sourceMappingURL=index.js.map