ciro-chatbot-widget 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chatbot.js +1 -1
- package/package.json +1 -1
- package/src/types.ts +3 -0
package/dist/chatbot.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var __CiroChatbot=function(){"use strict";var e,t,n,r,o,i,l,a,s,c,d,u={},p=[],_=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,h=Array.isArray;function g(e,t){for(var n in t)e[n]=t[n];return e}function f(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function m(t,n,r){var o,i,l,a={};for(l in n)"key"==l?o=n[l]:"ref"==l?i=n[l]:a[l]=n[l];if(arguments.length>2&&(a.children=arguments.length>3?e.call(arguments,2):r),"function"==typeof t&&null!=t.defaultProps)for(l in t.defaultProps)void 0===a[l]&&(a[l]=t.defaultProps[l]);return y(t,a,o,i,null)}function y(e,r,o,i,l){var a={type:e,props:r,key:o,ref:i,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:null==l?++n:l,__i:-1,__u:0};return null==l&&null!=t.vnode&&t.vnode(a),a}function x(e){return e.children}function b(e,t){this.props=e,this.context=t}function v(e,t){if(null==t)return e.__?v(e.__,e.__i+1):null;for(var n;t<e.__k.length;t++)if(null!=(n=e.__k[t])&&null!=n.__e)return n.__e;return"function"==typeof e.type?v(e):null}function w(e){if(e.__P&&e.__d){var n=e.__v,r=n.__e,o=[],i=[],l=g({},n);l.__v=n.__v+1,t.vnode&&t.vnode(l),H(e.__P,l,n,e.__n,e.__P.namespaceURI,32&n.__u?[r]:null,o,null==r?v(n):r,!!(32&n.__u),i),l.__v=n.__v,l.__.__k[l.__i]=l,W(o,l,i),n.__e=n.__=null,l.__e!=r&&k(l)}}function k(e){if(null!=(e=e.__)&&null!=e.__c)return e.__e=e.__c.base=null,e.__k.some(function(t){if(null!=t&&null!=t.__e)return e.__e=e.__c.base=t.__e}),k(e)}function C(e){(!e.__d&&(e.__d=!0)&&r.push(e)&&!S.__r++||o!=t.debounceRendering)&&((o=t.debounceRendering)||i)(S)}function S(){try{for(var e,t=1;r.length;)r.length>t&&r.sort(l),e=r.shift(),t=r.length,w(e)}finally{r.length=S.__r=0}}function T(e,t,n,r,o,i,l,a,s,c,d){var _,g,f,m,b,w,k,C=r&&r.__k||p,S=t.length;for(s=function(e,t,n,r,o){var i,l,a,s,c,d=n.length,u=d,p=0;for(e.__k=new Array(o),i=0;i<o;i++)null!=(l=t[i])&&"boolean"!=typeof l&&"function"!=typeof l?("string"==typeof l||"number"==typeof l||"bigint"==typeof l||l.constructor==String?l=e.__k[i]=y(null,l,null,null,null):h(l)?l=e.__k[i]=y(x,{children:l},null,null,null):void 0===l.constructor&&l.__b>0?l=e.__k[i]=y(l.type,l.props,l.key,l.ref?l.ref:null,l.__v):e.__k[i]=l,s=i+p,l.__=e,l.__b=e.__b+1,a=null,-1!=(c=l.__i=$(l,n,s,u))&&(u--,(a=n[c])&&(a.__u|=2)),null==a||null==a.__v?(-1==c&&(o>d?p--:o<d&&p++),"function"!=typeof l.type&&(l.__u|=4)):c!=s&&(c==s-1?p--:c==s+1?p++:(c>s?p--:p++,l.__u|=4))):e.__k[i]=null;if(u)for(i=0;i<d;i++)null!=(a=n[i])&&!(2&a.__u)&&(a.__e==r&&(r=v(a)),L(a,a));return r}(n,t,C,s,S),_=0;_<S;_++)null!=(f=n.__k[_])&&(g=-1!=f.__i&&C[f.__i]||u,f.__i=_,w=H(e,f,g,o,i,l,a,s,c,d),m=f.__e,f.ref&&g.ref!=f.ref&&(g.ref&&D(g.ref,null,f),d.push(f.ref,f.__c||m,f)),null==b&&null!=m&&(b=m),(k=!!(4&f.__u))||g.__k===f.__k?s=I(f,s,e,k):"function"==typeof f.type&&void 0!==w?s=w:m&&(s=m.nextSibling),f.__u&=-7);return n.__e=b,s}function I(e,t,n,r){var o,i;if("function"==typeof e.type){for(o=e.__k,i=0;o&&i<o.length;i++)o[i]&&(o[i].__=e,t=I(o[i],t,n,r));return t}e.__e!=t&&(r&&(t&&e.type&&!t.parentNode&&(t=v(e)),n.insertBefore(e.__e,t||null)),t=e.__e);do{t=t&&t.nextSibling}while(null!=t&&8==t.nodeType);return t}function $(e,t,n,r){var o,i,l,a=e.key,s=e.type,c=t[n],d=null!=c&&!(2&c.__u);if(null===c&&null==a||d&&a==c.key&&s==c.type)return n;if(r>(d?1:0))for(o=n-1,i=n+1;o>=0||i<t.length;)if(null!=(c=t[l=o>=0?o--:i++])&&!(2&c.__u)&&a==c.key&&s==c.type)return l;return-1}function E(e,t,n){"-"==t[0]?e.setProperty(t,null==n?"":n):e[t]=null==n?"":"number"!=typeof n||_.test(t)?n:n+"px"}function R(e,t,n,r,o){var i,l;e:if("style"==t)if("string"==typeof n)e.style.cssText=n;else{if("string"==typeof r&&(e.style.cssText=r=""),r)for(t in r)n&&t in n||E(e.style,t,"");if(n)for(t in n)r&&n[t]==r[t]||E(e.style,t,n[t])}else if("o"==t[0]&&"n"==t[1])i=t!=(t=t.replace(a,"$1")),l=t.toLowerCase(),t=l in e||"onFocusOut"==t||"onFocusIn"==t?l.slice(2):t.slice(2),e.l||(e.l={}),e.l[t+i]=n,n?r?n.u=r.u:(n.u=s,e.addEventListener(t,i?d:c,i)):e.removeEventListener(t,i?d:c,i);else{if("http://www.w3.org/2000/svg"==o)t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if("width"!=t&&"height"!=t&&"href"!=t&&"list"!=t&&"form"!=t&&"tabIndex"!=t&&"download"!=t&&"rowSpan"!=t&&"colSpan"!=t&&"role"!=t&&"popover"!=t&&t in e)try{e[t]=null==n?"":n;break e}catch(u){}"function"==typeof n||(null==n||!1===n&&"-"!=t[4]?e.removeAttribute(t):e.setAttribute(t,"popover"==t&&1==n?"":n))}}function z(e){return function(n){if(this.l){var r=this.l[n.type+e];if(null==n.t)n.t=s++;else if(n.t<r.u)return;return r(t.event?t.event(n):n)}}}function H(n,r,o,i,l,a,s,c,d,_){var m,y,w,k,C,S,I,$,E,z,H,W,D,L,N,O=r.type;if(void 0!==r.constructor)return null;128&o.__u&&(d=!!(32&o.__u),a=[c=r.__e=o.__e]),(m=t.__b)&&m(r);e:if("function"==typeof O)try{if($=r.props,E=O.prototype&&O.prototype.render,z=(m=O.contextType)&&i[m.__c],H=m?z?z.props.value:m.__:i,o.__c?I=(y=r.__c=o.__c).__=y.__E:(E?r.__c=y=new O($,H):(r.__c=y=new b($,H),y.constructor=O,y.render=P),z&&z.sub(y),y.state||(y.state={}),y.__n=i,w=y.__d=!0,y.__h=[],y._sb=[]),E&&null==y.__s&&(y.__s=y.state),E&&null!=O.getDerivedStateFromProps&&(y.__s==y.state&&(y.__s=g({},y.__s)),g(y.__s,O.getDerivedStateFromProps($,y.__s))),k=y.props,C=y.state,y.__v=r,w)E&&null==O.getDerivedStateFromProps&&null!=y.componentWillMount&&y.componentWillMount(),E&&null!=y.componentDidMount&&y.__h.push(y.componentDidMount);else{if(E&&null==O.getDerivedStateFromProps&&$!==k&&null!=y.componentWillReceiveProps&&y.componentWillReceiveProps($,H),r.__v==o.__v||!y.__e&&null!=y.shouldComponentUpdate&&!1===y.shouldComponentUpdate($,y.__s,H)){r.__v!=o.__v&&(y.props=$,y.state=y.__s,y.__d=!1),r.__e=o.__e,r.__k=o.__k,r.__k.some(function(e){e&&(e.__=r)}),p.push.apply(y.__h,y._sb),y._sb=[],y.__h.length&&s.push(y);break e}null!=y.componentWillUpdate&&y.componentWillUpdate($,y.__s,H),E&&null!=y.componentDidUpdate&&y.__h.push(function(){y.componentDidUpdate(k,C,S)})}if(y.context=H,y.props=$,y.__P=n,y.__e=!1,W=t.__r,D=0,E)y.state=y.__s,y.__d=!1,W&&W(r),m=y.render(y.props,y.state,y.context),p.push.apply(y.__h,y._sb),y._sb=[];else do{y.__d=!1,W&&W(r),m=y.render(y.props,y.state,y.context),y.state=y.__s}while(y.__d&&++D<25);y.state=y.__s,null!=y.getChildContext&&(i=g(g({},i),y.getChildContext())),E&&!w&&null!=y.getSnapshotBeforeUpdate&&(S=y.getSnapshotBeforeUpdate(k,C)),L=null!=m&&m.type===x&&null==m.key?A(m.props.children):m,c=T(n,h(L)?L:[L],r,o,i,l,a,s,c,d,_),y.base=r.__e,r.__u&=-161,y.__h.length&&s.push(y),I&&(y.__E=y.__=null)}catch(U){if(r.__v=null,d||null!=a)if(U.then){for(r.__u|=d?160:128;c&&8==c.nodeType&&c.nextSibling;)c=c.nextSibling;a[a.indexOf(c)]=null,r.__e=c}else{for(N=a.length;N--;)f(a[N]);M(r)}else r.__e=o.__e,r.__k=o.__k,U.then||M(r);t.__e(U,r,o)}else null==a&&r.__v==o.__v?(r.__k=o.__k,r.__e=o.__e):c=r.__e=function(n,r,o,i,l,a,s,c,d){var p,_,g,m,y,x,b,w=o.props||u,k=r.props,C=r.type;if("svg"==C?l="http://www.w3.org/2000/svg":"math"==C?l="http://www.w3.org/1998/Math/MathML":l||(l="http://www.w3.org/1999/xhtml"),null!=a)for(p=0;p<a.length;p++)if((y=a[p])&&"setAttribute"in y==!!C&&(C?y.localName==C:3==y.nodeType)){n=y,a[p]=null;break}if(null==n){if(null==C)return document.createTextNode(k);n=document.createElementNS(l,C,k.is&&k),c&&(t.__m&&t.__m(r,a),c=!1),a=null}if(null==C)w===k||c&&n.data==k||(n.data=k);else{if(a=a&&e.call(n.childNodes),!c&&null!=a)for(w={},p=0;p<n.attributes.length;p++)w[(y=n.attributes[p]).name]=y.value;for(p in w)y=w[p],"dangerouslySetInnerHTML"==p?g=y:"children"==p||p in k||"value"==p&&"defaultValue"in k||"checked"==p&&"defaultChecked"in k||R(n,p,null,y,l);for(p in k)y=k[p],"children"==p?m=y:"dangerouslySetInnerHTML"==p?_=y:"value"==p?x=y:"checked"==p?b=y:c&&"function"!=typeof y||w[p]===y||R(n,p,y,w[p],l);if(_)c||g&&(_.__html==g.__html||_.__html==n.innerHTML)||(n.innerHTML=_.__html),r.__k=[];else if(g&&(n.innerHTML=""),T("template"==r.type?n.content:n,h(m)?m:[m],r,o,i,"foreignObject"==C?"http://www.w3.org/1999/xhtml":l,a,s,a?a[0]:o.__k&&v(o,0),c,d),null!=a)for(p=a.length;p--;)f(a[p]);c||(p="value","progress"==C&&null==x?n.removeAttribute("value"):null!=x&&(x!==n[p]||"progress"==C&&!x||"option"==C&&x!=w[p])&&R(n,p,x,w[p],l),p="checked",null!=b&&b!=n[p]&&R(n,p,b,w[p],l))}return n}(o.__e,r,o,i,l,a,s,d,_);return(m=t.diffed)&&m(r),128&r.__u?void 0:c}function M(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some(M))}function W(e,n,r){for(var o=0;o<r.length;o++)D(r[o],r[++o],r[++o]);t.__c&&t.__c(n,e),e.some(function(n){try{e=n.__h,n.__h=[],e.some(function(e){e.call(n)})}catch(r){t.__e(r,n.__v)}})}function A(e){return"object"!=typeof e||null==e||e.__b>0?e:h(e)?e.map(A):g({},e)}function D(e,n,r){try{if("function"==typeof e){var o="function"==typeof e.__u;o&&e.__u(),o&&null==n||(e.__u=e(n))}else e.current=n}catch(i){t.__e(i,r)}}function L(e,n,r){var o,i;if(t.unmount&&t.unmount(e),(o=e.ref)&&(o.current&&o.current!=e.__e||D(o,null,n)),null!=(o=e.__c)){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(l){t.__e(l,n)}o.base=o.__P=null}if(o=e.__k)for(i=0;i<o.length;i++)o[i]&&L(o[i],n,r||"function"!=typeof e.type);r||f(e.__e),e.__c=e.__=e.__e=void 0}function P(e,t,n){return this.constructor(e,n)}function N(n,r,o){var i,l,a;r==document&&(r=document.documentElement),t.__&&t.__(n,r),i=!1?null:r.__k,l=[],a=[],H(r,n=r.__k=m(x,null,[n]),i||u,u,r.namespaceURI,i?null:r.firstChild?e.call(r.childNodes):null,l,i?i.__e:r.firstChild,false,a),W(l,n,a)}e=p.slice,t={__e:function(e,t,n,r){for(var o,i,l;t=t.__;)if((o=t.__c)&&!o.__)try{if((i=o.constructor)&&null!=i.getDerivedStateFromError&&(o.setState(i.getDerivedStateFromError(e)),l=o.__d),null!=o.componentDidCatch&&(o.componentDidCatch(e,r||{}),l=o.__d),l)return o.__E=o}catch(a){e=a}throw e}},n=0,b.prototype.setState=function(e,t){var n;n=null!=this.__s&&this.__s!=this.state?this.__s:this.__s=g({},this.state),"function"==typeof e&&(e=e(g({},n),this.props)),e&&g(n,e),null!=e&&this.__v&&(t&&this._sb.push(t),C(this))},b.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),C(this))},b.prototype.render=x,r=[],i="function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout,l=function(e,t){return e.__v.__b-t.__v.__b},S.__r=0,a=/(PointerCapture)$|Capture$/i,s=0,c=z(!1),d=z(!0);var O=0;function U(e,n,r,o,i,l){n||(n={});var a,s,c=n;if("ref"in c)for(s in c={},n)"ref"==s?a=n[s]:c[s]=n[s];var d={type:e,props:c,key:r,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--O,__i:-1,__u:0,__source:i,__self:l};if("function"==typeof e&&(a=e.defaultProps))for(s in a)void 0===c[s]&&(c[s]=a[s]);return t.vnode&&t.vnode(d),d}var F,q,j,B,K=0,J=[],Y=t,V=Y.__b,G=Y.__r,Z=Y.diffed,X=Y.__c,Q=Y.unmount,ee=Y.__;function te(e,t){Y.__h&&Y.__h(q,e,K||t),K=0;var n=q.__H||(q.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function ne(e){return K=1,function(e,t){var n=te(F++,2);if(n.t=e,!n.__c&&(n.__=[_e(void 0,t),function(e){var t=n.__N?n.__N[0]:n.__[0],r=n.t(t,e);t!==r&&(n.__N=[r,n.__[1]],n.__c.setState({}))}],n.__c=q,!q.__f)){var r=function(e,t,r){if(!n.__c.__H)return!0;var i=n.__c.__H.__.filter(function(e){return e.__c});if(i.every(function(e){return!e.__N}))return!o||o.call(this,e,t,r);var l=n.__c.props!==e;return i.some(function(e){if(e.__N){var t=e.__[0];e.__=e.__N,e.__N=void 0,t!==e.__[0]&&(l=!0)}}),o&&o.call(this,e,t,r)||l};q.__f=!0;var o=q.shouldComponentUpdate,i=q.componentWillUpdate;q.componentWillUpdate=function(e,t,n){if(this.__e){var l=o;o=void 0,r(e,t,n),o=l}i&&i.call(this,e,t,n)},q.shouldComponentUpdate=r}return n.__N||n.__}(_e,e)}function re(e,t){var n=te(F++,3);!Y.__s&&pe(n.__H,t)&&(n.__=e,n.u=t,q.__H.__h.push(n))}function oe(e){return K=5,ie(function(){return{current:e}},[])}function ie(e,t){var n=te(F++,7);return pe(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function le(e,t){return K=8,ie(function(){return e},t)}function ae(){for(var e;e=J.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(de),t.__h.some(ue),t.__h=[]}catch(n){t.__h=[],Y.__e(n,e.__v)}}}Y.__b=function(e){q=null,V&&V(e)},Y.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),ee&&ee(e,t)},Y.__r=function(e){G&&G(e),F=0;var t=(q=e.__c).__H;t&&(j===q?(t.__h=[],q.__h=[],t.__.some(function(e){e.__N&&(e.__=e.__N),e.u=e.__N=void 0})):(t.__h.some(de),t.__h.some(ue),t.__h=[],F=0)),j=q},Y.diffed=function(e){Z&&Z(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(1!==J.push(t)&&B===Y.requestAnimationFrame||((B=Y.requestAnimationFrame)||ce)(ae)),t.__H.__.some(function(e){e.u&&(e.__H=e.u),e.u=void 0})),j=q=null},Y.__c=function(e,t){t.some(function(e){try{e.__h.some(de),e.__h=e.__h.filter(function(e){return!e.__||ue(e)})}catch(n){t.some(function(e){e.__h&&(e.__h=[])}),t=[],Y.__e(n,e.__v)}}),X&&X(e,t)},Y.unmount=function(e){Q&&Q(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(e){try{de(e)}catch(n){t=n}}),n.__H=void 0,t&&Y.__e(t,n.__v))};var se="function"==typeof requestAnimationFrame;function ce(e){var t,n=function(){clearTimeout(r),se&&cancelAnimationFrame(t),setTimeout(e)},r=setTimeout(n,35);se&&(t=requestAnimationFrame(n))}function de(e){var t=q,n=e.__c;"function"==typeof n&&(e.__c=void 0,n()),q=t}function ue(e){var t=q;e.__c=e.__(),q=t}function pe(e,t){return!e||e.length!==t.length||t.some(function(t,n){return t!==e[n]})}function _e(e,t){return"function"==typeof t?t(e):t}class he{constructor(e,t,n){this.apiUrl=e,this.botId=t,this.apiKey=n}headers(){return{"Content-Type":"application/json","X-Chatbot-Key":this.apiKey}}url(e){return`${this.apiUrl}/api/chatbot-widget/${this.botId}${e}`}async init(){const e=await fetch(this.url("/init"),{method:"POST",headers:this.headers()});if(!e.ok)throw new Error(`Init failed: ${e.status}`);return e.json()}async createConversation(e){const t=await fetch(this.url("/conversations"),{method:"POST",headers:this.headers(),body:JSON.stringify(e||{})});if(!t.ok){const e=await t.json().catch(()=>({message:`HTTP ${t.status}`}));throw new Error(e.message||`Create conversation failed: ${t.status}`)}return t.json()}async getMessages(e){const t=await fetch(this.url(`/conversations/${e}/messages`),{headers:this.headers()});if(!t.ok)throw new Error(`Get messages failed: ${t.status}`);return t.json()}streamMessage(e,t,n){const r=new AbortController;return(async()=>{try{const i=await fetch(this.url(`/conversations/${e}/messages`),{method:"POST",headers:this.headers(),body:JSON.stringify({content:t}),signal:r.signal});if(!i.ok){const e=await i.json().catch(()=>({message:`HTTP ${i.status}`}));return void n.onError(e.message||"Request failed")}if(!i.body||"function"!=typeof i.body.getReader){const e=(await i.text()).split("\n").filter(e=>e.startsWith("data: ")).pop();if(e)try{const t=JSON.parse(e.slice(6));t.text&&n.onTextDelta(t.text)}catch(o){}return void n.onEnd()}const l=i.body.getReader(),a=new TextDecoder;let s="";for(;;){const{done:e,value:t}=await l.read();if(e)break;let r;for(s+=a.decode(t,{stream:!0});-1!==(r=s.indexOf("\n\n"));){const e=s.slice(0,r);s=s.slice(r+2);let t="",i="";for(const n of e.split("\n"))n.startsWith("event: ")?t=n.slice(7).trim():n.startsWith("data: ")&&(i+=(i?"\n":"")+n.slice(6));if(t&&i)try{const e=JSON.parse(i);switch(t){case"text:delta":n.onTextDelta(e.text||"");break;case"source:add":n.onSource({label:e.label||"",detail:e.detail||""});break;case"suggestions":n.onSuggestions(e.questions||[]);break;case"confidence":n.onConfidence(e);break;case"stream:end":return void n.onEnd();case"stream:error":return void n.onError(e.message||"Stream error")}}catch(o){}}}n.onEnd()}catch(i){if("AbortError"===i.name)return;n.onError(i.message||"Connection failed")}})(),r}async rateConversation(e,t){await fetch(this.url(`/conversations/${e}/rate`),{method:"POST",headers:this.headers(),body:JSON.stringify({satisfaction:t})})}async escalateConversation(e){await fetch(this.url(`/conversations/${e}/escalate`),{method:"POST",headers:this.headers()})}}const ge="ciro_chat_";function fe(e,t){var n,r;const o=oe(function(e){try{const t=localStorage.getItem(`${ge}${e}`);if(!t)return null;const n=JSON.parse(t);return Date.now()-(n.timestamp||0)>864e5?(localStorage.removeItem(`${ge}${e}`),null):{conversationId:n.conversationId,messages:n.messages||[]}}catch(t){return null}}(e.botId)),[i,l]=ne((null==(n=o.current)?void 0:n.messages)||[]),[a,s]=ne("idle"),[c,d]=ne((null==(r=o.current)?void 0:r.conversationId)||null),[u,p]=ne(null),[_,h]=ne(0),g=oe(null),f=oe(null),m=oe(0),y=oe(null),x=oe(""),b=oe(!1);g.current||(g.current=new he(e.apiUrl||window.location.origin,e.botId,e.apiKey));const v=g.current;re(()=>()=>{var e;null==(e=f.current)||e.abort()},[]),re(()=>{c&&i.length>0&&function(e,t,n){try{const r=n.slice(-50).map(({isStreaming:e,...t})=>t);localStorage.setItem(`${ge}${e}`,JSON.stringify({conversationId:t,messages:r,timestamp:Date.now()}))}catch(r){}}(e.botId,c,i)},[i,c,e.botId]);const w=le(e=>{b.current=e,e&&h(0)},[]),k=le(async()=>{if(c)return c;if(y.current)return y.current;const t=v.createConversation({external_user_id:e.externalUserId,user_email:e.userEmail,user_name:e.userName}).then(e=>(d(e.conversation_id),y.current=null,e.conversation_id)).catch(e=>{throw y.current=null,e});return y.current=t,t},[c,e,v]),C=le(async t=>{var n,r;if(!t.trim()||"streaming"===a)return;p(null),x.current="";const o="user_"+ ++m.current;l(e=>[...e,{id:o,role:"user",content:t.trim(),created_at:(new Date).toISOString()}]),null==(n=e.onMessage)||n.call(e,{role:"user",content:t.trim()});const i="assistant_"+ ++m.current;l(e=>[...e,{id:i,role:"assistant",content:"",sources:[],suggestions:[],isStreaming:!0}]),s("streaming");try{const n=await k();f.current=v.streamMessage(n,t.trim(),{onTextDelta:e=>{x.current+=e,l(t=>t.map(t=>t.id===i?{...t,content:t.content+e}:t))},onSource:e=>{l(t=>t.map(t=>t.id===i?{...t,sources:[...t.sources||[],{name:e.label,type:e.detail}]}:t))},onSuggestions:e=>{l(t=>t.map(t=>t.id===i?{...t,suggestions:e}:t))},onConfidence:e=>{l(t=>t.map(t=>t.id===i?{...t,confidence:e.overall}:t))},onEnd:()=>{var t;l(e=>e.map(e=>e.id===i?{...e,isStreaming:!1,created_at:(new Date).toISOString()}:e)),s("idle"),x.current&&(null==(t=e.onMessage)||t.call(e,{role:"assistant",content:x.current})),b.current||h(e=>e+1)},onError:t=>{var n;l(e=>e.map(e=>e.id===i?{...e,content:t||"Something went wrong.",isStreaming:!1}:e)),s("error"),p(t),null==(n=e.onError)||n.call(e,new Error(t))}})}catch(c){l(e=>e.map(e=>e.id===i?{...e,content:"Failed to connect. Please try again.",isStreaming:!1}:e)),s("error"),p(c.message),null==(r=e.onError)||r.call(e,c)}},[a,e,v,k]),S=le(()=>{var e;null==(e=f.current)||e.abort(),f.current=null,l(e=>e.map(e=>e.isStreaming?{...e,isStreaming:!1}:e)),s("idle")},[]),T=le(async e=>{if(c)try{await v.rateConversation(c,e)}catch(t){}},[c,v]),I=le(async()=>{if(c)try{await v.escalateConversation(c),l(e=>[...e,{id:"system_"+ ++m.current,role:"system",content:(null==t?void 0:t.escalation_message)||"Connecting you with a human agent..."}])}catch(e){}},[c,v,t]),$=le(()=>{var t;null==(t=f.current)||t.abort(),l([]),d(null),s("idle"),h(0),localStorage.removeItem(`${ge}${e.botId}`)},[e.botId]);return{messages:i,state:a,error:u,conversationId:c,unreadCount:_,sendMessage:C,cancelStream:S,rateConversation:T,escalate:I,clearConversation:$,setIsOpen:w}}function me({color:e="white",size:t=22}){return U("svg",{width:t,height:.574*t,viewBox:"0 0 515 296",fill:e,children:[U("path",{d:"M294.79,207.08l.97-1.03.11-.11,28.71-30.02,5.85-6.13h-.02l.05-.06c1.64-1.65,3.04-3.54,4.15-5.62l.03-.06c.36-.67.7-1.36,1-2.08l.09-.28c.27-.64.52-1.3.72-1.97.06-.2.11-.41.16-.61.17-.58.33-1.15.45-1.75.08-.38.11-.77.17-1.16.06-.39.15-.78.19-1.17.09-.86.14-1.74.14-2.62,0-8.77-4.6-16.48-11.5-20.89-3.84-2.44-8.38-3.87-13.25-3.87-6.28,0-11.99,2.37-16.36,6.23-.5.44-.98.89-1.45,1.37v-.05l-6.21,6.51-13.17,13.77-1.44,1.51-12.66,13.24-1.08,1.12-27.88,29.17-1.2,1.25-7.63,7.99-1.09,1.12-4.06,4.26c-1.16.91-2.31,1.83-3.5,2.72-1.76,1.53-3.59,3-5.48,4.4-7.82,5.87-16.58,10.6-26.02,13.94-3.25,1.14-6.59,2.11-9.99,2.92-.91.22-1.83.42-2.75.61-3.18.67-6.42,1.17-9.71,1.53-3.47.36-6.99.56-10.55.56-.25,0-.5-.02-.73-.02-.72,0-1.41-.03-2.11-.05-20.09-.58-38.67-7.1-53.9-17.84-.44-.3-.87-.59-1.3-.89-4.61-3.36-8.87-7.1-12.78-11.18-.36-.37-.72-.75-1.08-1.12-15.52-16.69-24.98-38.79-24.98-62.99,0-21.24,7.29-40.87,19.57-56.63,5.15-6.62,11.21-12.55,17.97-17.65.42-.31.83-.64,1.25-.95,9.1-6.65,19.45-11.75,30.63-14.97,7.91-2.28,16.25-3.59,24.87-3.81.7-.02,1.4-.05,2.11-.05.17,0,.33-.02.48-.02,21.22,0,40.86,6.68,56.84,17.97,1.46,1.03,3.47.8,4.71-.49l28.09-29.37,2.21-2.32c1.46-1.53,1.32-3.99-.31-5.35-1.23-1.02-2.47-2.03-3.73-3.01C213.34,11.63,181.88,0,147.78,0c-14.92,0-29.35,2.23-42.93,6.37-.56.17-1.12.34-1.67.52-17.84,5.65-34.23,14.63-48.44,26.16-.41.33-.81.66-1.22,1C20.86,61.16,0,102.07,0,147.76c0,39.62,15.69,75.64,41.16,102.21.36.37.73.75,1.09,1.12,3.95,4.03,8.13,7.85,12.53,11.41.41.33.81.66,1.22.98,2.96,2.36,6.02,4.62,9.18,6.74,11.53,7.8,24.24,14.02,37.79,18.34l.06-.08c.55.19,1.09.39,1.64.56,1.48.47,2.97.91,4.46,1.33,3.58.97,7.2,1.81,10.88,2.51.61.12,1.22.23,1.83.34,5.87,1.05,11.85,1.73,17.94,2.06.69.05,1.37.06,2.08.09,1.95.08,3.93.12,5.91.12,37.84,0,72.41-14.31,98.59-37.79l10.51-11.01,1.08-1.12.16-.17,1.09-1.12,2.92-3.06,8.99-9.41,23.57-24.65.11-.11Z"}),U("path",{d:"M473.9,45.55c-.36-.37-.73-.75-1.09-1.12-3.95-4.03-8.13-7.85-12.53-11.41-.41-.33-.81-.66-1.22-.98-2.96-2.36-6.02-4.62-9.18-6.74-11.53-7.8-24.24-14.02-37.79-18.34l-.06.08c-.55-.19-1.09-.39-1.64-.56-1.48-.47-2.97-.91-4.46-1.33-3.58-.97-7.2-1.81-10.88-2.51-.61-.12-1.22-.23-1.83-.34-5.87-1.05-11.85-1.73-17.94-2.06-.69-.05-1.37-.06-2.08-.09-1.95-.08-3.93-.12-5.91-.12-37.84,0-72.41,14.31-98.59,37.79l-10.51,11.01-1.08,1.12-.16.17-1.09,1.12-2.92,3.06-8.99,9.41-23.57,24.65-.11.11-.97,1.03-.11.11-28.71,30.02-9.61,10.17h.02l-.05.06c-1.64,1.65-3.04,3.54-4.15,5.62l-.03.06c-.36.67-.7,1.36-1,2.08l-.09.28c-.27.64-.52,1.3-.72,1.97-.06.2-.11.41-.16.61-.17.58-.33,1.15-.45,1.75-.08.37-.11.77-.17,1.16-.08.42-.16.84-.2,1.28-.08.83-.12,1.67-.12,2.51,0,6.05,2.19,11.59,5.81,15.9h0s.03.03.03.03c.66.78,1.36,1.52,2.11,2.21l29.06,30.43,34.34-35.89-12.31-12.8,6.67-6.98,1.44-1.51,12.66-13.24,1.08-1.12,27.88-29.17,1.2-1.25,7.63-7.99,1.09-1.12,4.06-4.26c1.16-.91,2.31-1.83,3.5-2.72,1.76-1.53,3.59-3,5.48-4.4,7.82-5.87,16.58-10.6,26.02-13.94,3.25-1.14,6.59-2.11,9.99-2.92.91-.22,1.83-.42,2.75-.61,3.18-.67,6.42-1.17,9.71-1.53,3.47-.36,6.99-.56,10.55-.56.25,0,.5.02.73.02.72,0,1.41.03,2.11.05,20.09.58,38.67,7.1,53.9,17.84.44.3.87.59,1.3.89,4.61,3.36,8.87,7.1,12.78,11.18.36.37.72.75,1.08,1.12,15.52,16.69,24.98,38.79,24.98,62.99,0,21.24-7.29,40.87-19.57,56.63-5.15,6.62-11.21,12.55-17.97,17.65-.42.31-.83.64-1.25.95-9.1,6.65-19.45,11.75-30.63,14.97-7.91,2.28-16.25,3.59-24.87,3.81-.7.02-1.4.05-2.11.05-.17,0-.33.02-.48.02-22.34,0-42.93-7.4-59.33-19.79l-30.3,31.69-4.89,5.12c2.19,1.9,4.42,3.76,6.71,5.56,25.04,19.48,56.49,31.11,90.6,31.11,14.92,0,29.35-2.23,42.93-6.37.56-.17,1.12-.34,1.67-.52,17.84-5.65,34.23-14.63,48.44-26.16.41-.33.81-.66,1.22-1,32.67-27.11,53.53-68.03,53.53-113.72,0-39.62-15.69-75.64-41.16-102.21Z"})]})}function ye({onClick:e,primaryColor:t,position:n,isOpen:r,greeting:o,onDismissGreeting:i,unreadCount:l=0}){const a="bottom-left"===n?{left:"20px",right:"auto"}:{right:"20px",left:"auto"};return U(x,{children:[o&&!r&&U("div",{style:{position:"fixed",bottom:"88px",...a,maxWidth:"260px",padding:"12px 16px",backgroundColor:"white",borderRadius:"14px",boxShadow:"0 4px 24px rgba(0,0,0,0.12)",fontSize:"13px",lineHeight:1.5,color:"#374151",zIndex:2147483646,cursor:"pointer",animation:"ciro-window-open 0.3s cubic-bezier(0.16, 1, 0.3, 1)",border:"1px solid rgba(0,0,0,0.06)"},onClick:e,children:[U("div",{style:{display:"flex",alignItems:"center",gap:"6px",marginBottom:"6px",opacity:.5,fontSize:"11px",fontWeight:600,letterSpacing:"0.3px"},children:[U(me,{color:"#5e6a98",size:14}),"CIRO AI"]}),o,U("button",{onClick:e=>{e.stopPropagation(),null==i||i()},"aria-label":"Dismiss",style:{position:"absolute",top:"-6px",right:"-6px",width:"20px",height:"20px",borderRadius:"50%",backgroundColor:"#e5e7eb",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"10px",color:"#6b7280"},children:"x"})]}),U("div",{style:{position:"fixed",bottom:"20px",...a,zIndex:2147483646,animation:"ciro-bubble-entrance 0.4s cubic-bezier(0.34, 1.56, 0.64, 1)"},children:[U("div",{style:{position:"absolute",inset:"-3px",borderRadius:"50%",background:r?"none":`conic-gradient(from 0deg, ${t}, #f59e0b, #ec4899, #8b5cf6, #06b6d4, ${t})`,opacity:r?0:.6,animation:r?"none":"ciro-glow-spin 4s linear infinite",transition:"opacity 0.3s",filter:"blur(2px)"}}),U("button",{onClick:e,"aria-label":r?"Close chat":"Open chat",style:{position:"relative",width:"58px",height:"58px",borderRadius:"50%",backgroundColor:"#1a1a2e",border:"2px solid rgba(255,255,255,0.1)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 4px 20px rgba(0,0,0,0.3)",transition:"transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease",WebkitTapHighlightColor:"transparent"},onMouseEnter:e=>{const t=e.currentTarget;t.style.transform="scale(1.08)",t.style.boxShadow="0 6px 28px rgba(0,0,0,0.4)"},onMouseLeave:e=>{const t=e.currentTarget;t.style.transform="scale(1)",t.style.boxShadow="0 4px 20px rgba(0,0,0,0.3)"},children:r?U("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"white","stroke-width":"2.5","stroke-linecap":"round",children:[U("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),U("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}):U(me,{color:"white",size:28})}),!r&&l>0&&U("span",{style:{position:"absolute",top:"-5px",right:"-5px",minWidth:"20px",height:"20px",borderRadius:"10px",backgroundColor:"#ef4444",color:"white",fontSize:"11px",fontWeight:700,display:"flex",alignItems:"center",justifyContent:"center",padding:"0 5px",border:"2px solid white",animation:"ciro-bubble-entrance 0.3s ease",zIndex:1},children:l>9?"9+":l})]})]})}function xe(e,t){if(!e)return e;const n=[];let r=0;const o=/(!\[([^\]]*)\]\(([^)]+)\))|(\*\*(.+?)\*\*)|(\*(.+?)\*)|(`(.+?)`)|(\[(.+?)\]\((.+?)\))/g;let i,l=0;for(;null!==(i=o.exec(e));)i.index>l&&n.push(e.slice(l,i.index)),i[1]?n.push(U("img",{src:i[3],alt:i[2]||"",style:{maxWidth:"100%",borderRadius:"8px",marginTop:"4px",marginBottom:"4px",display:"block"},onError:e=>{e.target.style.display="none"}},r++)):i[4]?n.push(U("strong",{children:i[5]},r++)):i[6]?n.push(U("em",{children:i[7]},r++)):i[8]?n.push(U("code",{style:{backgroundColor:"rgba(0,0,0,0.06)",padding:"1px 4px",borderRadius:"3px",fontSize:"12px",fontFamily:"monospace"},children:i[9]},r++)):i[10]&&n.push(U("a",{href:i[12],target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"underline"},children:i[11]},r++)),l=i.index+i[0].length;return l<e.length&&n.push(e.slice(l)),n.length>0?n:e}function be(e){if(!e)return"";try{return new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch(t){return""}}function ve({color:e,size:t=28}){return U("div",{style:{width:`${t}px`,height:`${t}px`,borderRadius:"8px",backgroundColor:`${e}12`,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:U(me,{color:e,size:.55*t})})}function we({messages:e,config:t,onRate:n,lastAssistantId:r,feedbackThanks:o}){const[i,l]=ne(null),a=(e,t)=>{l(e),n(t)};return U(x,{children:e.map((n,l)=>{if("system"===n.role)return U("div",{style:{textAlign:"center",fontSize:"11px",opacity:.5,padding:"12px 0",display:"flex",alignItems:"center",gap:"8px"},children:[U("div",{style:{flex:1,height:"1px",backgroundColor:"rgba(0,0,0,0.08)"}}),U("span",{children:n.content}),U("div",{style:{flex:1,height:"1px",backgroundColor:"rgba(0,0,0,0.08)"}})]},n.id);const s="user"===n.role,c=n.id===r&&!n.isStreaming&&n.content,d=i===n.id,u=l>0?e[l-1]:null,p=!(s||u&&"assistant"===u.role);return U("div",{style:{display:"flex",gap:"8px",alignItems:"flex-start",flexDirection:s?"row-reverse":"row",marginTop:(null==u?void 0:u.role)===n.role?"2px":"8px"},children:[!s&&U("div",{style:{width:"28px",flexShrink:0},children:p&&(t.avatar_url?U("img",{src:t.avatar_url,alt:"",style:{width:"28px",height:"28px",borderRadius:"50%",objectFit:"cover"},onError:e=>{e.target.style.display="none"}}):U(ve,{color:t.primary_color}))}),U("div",{style:{maxWidth:"78%",display:"flex",flexDirection:"column",alignItems:s?"flex-end":"flex-start"},children:[!s&&p&&U("div",{style:{fontSize:"11px",fontWeight:500,opacity:.5,marginBottom:"3px",paddingLeft:"2px"},children:t.name}),U("div",{style:{padding:"10px 14px",borderRadius:s?`${t.border_radius}px ${t.border_radius}px 4px ${t.border_radius}px`:p?`4px ${t.border_radius}px ${t.border_radius}px ${t.border_radius}px`:`${t.border_radius}px`,backgroundColor:s?t.primary_color:`${t.primary_color}0A`,color:s?"white":t.text_color,lineHeight:1.5,wordBreak:"break-word",fontSize:"14px",border:s?"none":`1px solid ${t.primary_color}10`},children:[n.content?xe(n.content,t.text_color):null,n.isStreaming&&!n.content&&U("span",{style:{display:"inline-flex",gap:"3px",padding:"2px 0"},children:[0,1,2].map(e=>U("span",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:t.text_color||"#6b7280",opacity:.4,display:"inline-block",animation:`ciro-thinking-dot 1.4s ease-in-out ${.16*e}s infinite`}},e))}),n.isStreaming&&n.content&&U("span",{style:{display:"inline-block",animation:"ciro-blink 1s infinite",marginLeft:"1px"},children:"|"})]}),n.created_at&&!n.isStreaming&&U("div",{style:{fontSize:"10px",opacity:.35,marginTop:"3px",paddingLeft:s?"0":"2px",paddingRight:s?"2px":"0"},children:be(n.created_at)}),!s&&n.sources&&n.sources.length>0&&t.include_citations&&U("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginTop:"4px"},children:n.sources.map((e,n)=>U("span",{style:{fontSize:"10px",padding:"2px 7px",borderRadius:"10px",backgroundColor:`${t.primary_color}10`,color:t.primary_color,border:`1px solid ${t.primary_color}20`},children:e.name},n))}),c&&U("div",{style:{display:"flex",gap:"4px",marginTop:"6px"},children:d?U("span",{style:{fontSize:"11px",opacity:.4},children:o||"Thanks for your feedback"}):U(x,{children:[U("button",{onClick:()=>a(n.id,"positive"),"aria-label":"Helpful",style:{background:"none",border:"1px solid rgba(0,0,0,0.08)",borderRadius:"14px",cursor:"pointer",fontSize:"12px",opacity:.5,padding:"3px 10px",minHeight:"26px",transition:"all 0.15s"},onMouseEnter:e=>{e.currentTarget.style.opacity="1",e.currentTarget.style.backgroundColor="rgba(0,0,0,0.03)"},onMouseLeave:e=>{e.currentTarget.style.opacity="0.5",e.currentTarget.style.backgroundColor="transparent"},children:"👍 Helpful"}),U("button",{onClick:()=>a(n.id,"negative"),"aria-label":"Not helpful",style:{background:"none",border:"1px solid rgba(0,0,0,0.08)",borderRadius:"14px",cursor:"pointer",fontSize:"12px",opacity:.5,padding:"3px 10px",minHeight:"26px",transition:"all 0.15s"},onMouseEnter:e=>{e.currentTarget.style.opacity="1",e.currentTarget.style.backgroundColor="rgba(0,0,0,0.03)"},onMouseLeave:e=>{e.currentTarget.style.opacity="0.5",e.currentTarget.style.backgroundColor="transparent"},children:"👎"})]})})]})]},n.id)})})}const ke=5e3;function Ce({onSend:e,isStreaming:t,primaryColor:n,placeholder:r}){const[o,i]=ne(""),l=oe(null),a=le(()=>{const n=o.trim();n&&!t&&(n.length>ke||(e(n),i(""),l.current&&(l.current.style.height="auto"),setTimeout(()=>{var e;return null==(e=l.current)?void 0:e.focus()},50)))},[o,t,e]),s=le(e=>{const t=e.target,n=t.value.slice(0,ke);i(n),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,100)}px`},[]),c=le(e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),a())},[a]),d=o.trim().length>0&&!t;return U("div",{style:{padding:"10px 12px",borderTop:"1px solid rgba(0,0,0,0.08)",display:"flex",alignItems:"flex-end",gap:"8px",flexShrink:0},children:[U("textarea",{ref:l,value:o,onInput:s,onKeyDown:c,placeholder:r,disabled:t,rows:1,maxLength:ke,"aria-label":"Message input",style:{flex:1,border:"1px solid rgba(0,0,0,0.12)",borderRadius:"20px",padding:"10px 16px",fontSize:"14px",resize:"none",outline:"none",fontFamily:"inherit",lineHeight:1.4,maxHeight:"100px",minHeight:"40px",overflow:"auto",backgroundColor:"transparent",color:"inherit",transition:"border-color 0.15s"},onFocus:e=>{e.currentTarget.style.borderColor=n},onBlur:e=>{e.currentTarget.style.borderColor="rgba(0,0,0,0.12)"}}),U("button",{onClick:a,disabled:!d,"aria-label":"Send message",style:{width:"40px",height:"40px",borderRadius:"50%",backgroundColor:d?n:"#e5e7eb",border:"none",cursor:d?"pointer":"default",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,transition:"background-color 0.15s",minHeight:"44px",minWidth:"44px"},children:U("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"white","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[U("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),U("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})})]})}function Se({questions:e,onClick:t,primaryColor:n}){if(!e.length)return null;const r=e.length>=4;return U("div",{role:"list","aria-label":"Suggested questions",style:{display:r?"grid":"flex",gridTemplateColumns:r?"repeat(2, 1fr)":void 0,flexDirection:r?void 0:"column",gap:"6px",padding:"4px 0"},children:e.map((e,o)=>U("button",{role:"listitem",onClick:()=>t(e),style:{padding:r?"10px 12px":"10px 14px",border:`1px solid ${n}25`,borderRadius:"12px",backgroundColor:"transparent",color:n,cursor:"pointer",textAlign:"left",fontSize:"13px",lineHeight:1.4,fontFamily:"inherit",transition:"all 0.15s ease",minHeight:"40px",display:"flex",alignItems:"center",fontWeight:500},onMouseEnter:e=>{const t=e.currentTarget;t.style.backgroundColor=`${n}10`,t.style.borderColor=`${n}40`,t.style.transform="translateY(-1px)"},onMouseLeave:e=>{const t=e.currentTarget;t.style.backgroundColor="transparent",t.style.borderColor=`${n}25`,t.style.transform="none"},children:e},o))})}function Te({config:e,messages:t,isStreaming:n,onSend:r,onSuggestionClick:o,onClose:i,onRate:l,onEscalate:a,position:s,locale:c}){const d=oe(null),u=oe(0),p=Re();re(()=>{if(t.length>u.current){const e=d.current;e&&requestAnimationFrame(()=>{e.scrollTop=e.scrollHeight})}u.current=t.length},[t.length]),re(()=>{if(!n)return;const e=d.current;e&&e.scrollHeight-e.scrollTop-e.clientHeight<100&&(e.scrollTop=e.scrollHeight)},[t,n]);const _=[...t].reverse().find(e=>"assistant"===e.role&&!e.isStreaming),h=(null==_?void 0:_.suggestions)||[],g=0===t.length,f="bottom-left"===s?{left:"20px",right:"auto"}:{right:"20px",left:"auto"};return U("div",{role:"dialog","aria-label":`Chat with ${e.name}`,style:{position:"fixed",bottom:p?"0":"90px",...p?{left:0,right:0}:f,width:p?"100%":`${e.widget_width}px`,height:p?"100%":`${e.widget_height}px`,maxHeight:p?"100vh":"calc(100vh - 110px)",backgroundColor:e.background_color,borderRadius:p?"0":`${e.border_radius}px`,boxShadow:"0 8px 40px rgba(0,0,0,0.15), 0 2px 8px rgba(0,0,0,0.08)",display:"flex",flexDirection:"column",overflow:"hidden",zIndex:2147483647,fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',fontSize:"14px",color:e.text_color,border:p?"none":"1px solid rgba(0,0,0,0.06)",animation:"ciro-window-open 0.25s cubic-bezier(0.16, 1, 0.3, 1)"},children:[U("div",{style:{padding:"0",backgroundColor:e.primary_color,color:"white",flexShrink:0,borderRadius:p?"0":`${e.border_radius}px ${e.border_radius}px 0 0`,overflow:"hidden"},children:U("div",{style:{padding:"14px 16px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[U("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[e.avatar_url?U("img",{src:e.avatar_url,alt:"",style:{width:"36px",height:"36px",borderRadius:"50%",objectFit:"cover",border:"2px solid rgba(255,255,255,0.2)"},onError:e=>{e.target.style.display="none"}}):U("div",{style:{width:"36px",height:"36px",borderRadius:"10px",backgroundColor:"rgba(255,255,255,0.15)",display:"flex",alignItems:"center",justifyContent:"center"},children:U(me,{color:"white",size:20})}),U("div",{children:[U("div",{style:{fontWeight:600,fontSize:"15px",letterSpacing:"-0.01em"},children:e.name}),U("div",{style:{fontSize:"12px",opacity:.9,display:"flex",alignItems:"center",gap:"4px"},children:n?U("span",{style:{display:"inline-flex",gap:"2px",alignItems:"center"},children:[U("span",{children:(null==c?void 0:c.typing)||"Typing"}),[0,1,2].map(e=>U("span",{style:{width:"3px",height:"3px",borderRadius:"50%",backgroundColor:"white",animation:`ciro-thinking-dot 1.4s ease-in-out ${.16*e}s infinite`}},e))]}):U(x,{children:[U("span",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#4ade80",display:"inline-block",boxShadow:"0 0 4px #4ade80"}}),(null==c?void 0:c.online)||"Online"]})})]})]}),U("button",{onClick:i,"aria-label":"Close chat",style:{background:"rgba(255,255,255,0.1)",border:"none",color:"white",cursor:"pointer",padding:"8px",display:"flex",borderRadius:"8px",minHeight:"36px",minWidth:"36px",alignItems:"center",justifyContent:"center",transition:"background 0.15s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(255,255,255,0.2)"},onMouseLeave:e=>{e.currentTarget.style.background="rgba(255,255,255,0.1)"},children:U("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:[U("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),U("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})}),U("div",{ref:d,style:{flex:1,overflowY:"auto",padding:"16px",display:"flex",flexDirection:"column",gap:"4px",WebkitOverflowScrolling:"touch"},children:[g&&U("div",{style:{padding:"16px 0 8px",display:"flex",flexDirection:"column",alignItems:"center"},children:U("div",{style:{backgroundColor:`${e.primary_color}08`,border:`1px solid ${e.primary_color}15`,borderRadius:"16px",padding:"20px",textAlign:"center",width:"100%",marginBottom:"16px"},children:[e.logo_url?U("img",{src:e.logo_url,alt:"",style:{width:"48px",height:"48px",borderRadius:"12px",margin:"0 auto 10px",display:"block",objectFit:"contain"},onError:e=>{e.target.style.display="none"}}):U("div",{style:{width:"48px",height:"48px",borderRadius:"12px",backgroundColor:`${e.primary_color}15`,margin:"0 auto 10px",display:"flex",alignItems:"center",justifyContent:"center"},children:U(me,{color:e.primary_color,size:28})}),U("div",{style:{fontWeight:600,fontSize:"15px",marginBottom:"4px"},children:e.name}),U("p",{style:{opacity:.7,margin:0,lineHeight:1.5,fontSize:"13px"},children:e.welcome_message})]})}),g&&e.suggested_questions.length>0&&U(Se,{questions:e.suggested_questions,onClick:o,primaryColor:e.primary_color}),U(we,{messages:t,config:e,onRate:l,lastAssistantId:null==_?void 0:_.id,feedbackThanks:null==c?void 0:c.feedbackThanks}),h.length>0&&!n&&U(Se,{questions:h,onClick:o,primaryColor:e.primary_color})]}),n&&U("div",{style:{padding:"6px 16px",display:"flex",alignItems:"center",gap:"8px",borderTop:"1px solid rgba(0,0,0,0.04)",flexShrink:0},children:[U("div",{style:{width:"20px",height:"20px",borderRadius:"6px",backgroundColor:`${e.primary_color}15`,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:U(me,{color:e.primary_color,size:12})}),U("span",{style:{fontSize:"12px",opacity:.5,display:"flex",alignItems:"center",gap:"3px"},children:[e.name," is typing",[0,1,2].map(t=>U("span",{style:{width:"3px",height:"3px",borderRadius:"50%",backgroundColor:e.text_color,opacity:.4,animation:`ciro-thinking-dot 1.4s ease-in-out ${.16*t}s infinite`}},t))]})]}),e.escalation_enabled&&t.length>4&&U("div",{style:{padding:"0 16px 4px",textAlign:"center"},children:U("button",{onClick:a,style:{background:"none",border:`1px solid ${e.primary_color}25`,color:e.primary_color,cursor:"pointer",fontSize:"12px",borderRadius:"16px",padding:"4px 14px",opacity:.7,minHeight:"28px",transition:"all 0.15s"},onMouseEnter:t=>{t.currentTarget.style.opacity="1",t.currentTarget.style.backgroundColor=`${e.primary_color}08`},onMouseLeave:e=>{e.currentTarget.style.opacity="0.7",e.currentTarget.style.backgroundColor="transparent"},children:(null==c?void 0:c.talkToHuman)||"Talk to a human"})}),U(Ce,{onSend:r,isStreaming:n,primaryColor:e.primary_color,placeholder:(null==c?void 0:c.placeholder)||"Type your message..."}),U("div",{style:{textAlign:"center",padding:"3px 0 6px",fontSize:"10px",opacity:.3,display:"flex",alignItems:"center",justifyContent:"center",gap:"4px"},children:[U(me,{color:"#5e6a98",size:12}),U("span",{style:{letterSpacing:"0.3px"},children:(null==c?void 0:c.poweredBy)||U(x,{children:["Powered by ",U("strong",{children:"CIRO"})]})})]})]})}function Ie({config:e,onSubmit:t,primaryColor:n}){const[r,o]=ne(""),[i,l]=ne(""),[a,s]=ne(""),c={width:"100%",padding:"10px 14px",border:"1px solid rgba(0,0,0,0.15)",borderRadius:"8px",fontSize:"14px",fontFamily:"inherit",outline:"none",boxSizing:"border-box"};return U("div",{style:{padding:"24px 20px",textAlign:"center"},children:[U("p",{style:{margin:"0 0 16px",fontSize:"14px",lineHeight:1.5,opacity:.8},children:e.lead_capture_message||"Please introduce yourself to start chatting."}),U("form",{onSubmit:n=>{n.preventDefault(),s(""),!e.require_email||r.trim()?!e.require_email||/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(r)?!e.require_name||i.trim()?t({email:r.trim()||void 0,name:i.trim()||void 0}):s("Name is required"):s("Please enter a valid email"):s("Email is required")},style:{display:"flex",flexDirection:"column",gap:"10px"},children:[e.require_name&&U("input",{type:"text",placeholder:"Your name",value:i,maxLength:100,onInput:e=>l(e.target.value),style:c}),e.require_email&&U("input",{type:"email",placeholder:"Your email",value:r,maxLength:255,onInput:e=>o(e.target.value),style:c}),a&&U("p",{style:{color:"#ef4444",fontSize:"12px",margin:0},children:a}),U("button",{type:"submit",style:{padding:"10px 20px",backgroundColor:n,color:"white",border:"none",borderRadius:"8px",fontSize:"14px",fontWeight:600,cursor:"pointer",fontFamily:"inherit"},children:"Start chatting"})]})]})}function $e({config:e}){var t,n,r,o,i,l,a,s;const[c,d]=ne(!1),[u,p]=ne(!1),[_,h]=ne({}),[g,f]=ne(!1),{widgetConfig:m,loading:y,error:b}=function(e){const[t,n]=ne(null),[r,o]=ne(!0),[i,l]=ne(null),a=oe(0);return re(()=>{const t=new he(e.apiUrl||window.location.origin,e.botId,e.apiKey);let r=!1;const i=()=>{t.init().then(e=>{r||(n(e),o(!1),l(null))}).catch(t=>{var n;r||(a.current++,a.current<=2?setTimeout(()=>{r||i()},3e3):(l(t.message||"Failed to load chatbot"),o(!1),null==(n=e.onError)||n.call(e,t)))})};return i(),()=>{r=!0}},[e.botId,e.apiKey,e.apiUrl]),{widgetConfig:t,loading:r,error:i}}(e),v=fe({...e,userEmail:e.userEmail||_.email,userName:e.userName||_.name},m);re(()=>(window.__ciroWidgetControl={open:()=>d(!0),close:()=>d(!1)},()=>{delete window.__ciroWidgetControl}),[]),re(()=>{var t,n;v.setIsOpen(c),c?null==(t=e.onOpen)||t.call(e):null==(n=e.onClose)||n.call(e)},[c]);const w=oe(v.messages.length);re(()=>{if(e.sound&&v.messages.length>w.current){const e=v.messages[v.messages.length-1];"assistant"===(null==e?void 0:e.role)&&!e.isStreaming&&e.content&&function(){try{const e=new(window.AudioContext||window.webkitAudioContext),t=e.createOscillator(),n=e.createGain();t.connect(n),n.connect(e.destination),t.type="sine",t.frequency.setValueAtTime(880,e.currentTime),t.frequency.setValueAtTime(1100,e.currentTime+.08),n.gain.setValueAtTime(.08,e.currentTime),n.gain.exponentialRampToValueAtTime(.001,e.currentTime+.25),t.start(e.currentTime),t.stop(e.currentTime+.25)}catch(e){}}()}w.current=v.messages.length},[v.messages,e.sound]);const k=le(()=>{d(e=>!e)},[]),C=le(e=>{v.sendMessage(e)},[v]),S=le(e=>{v.sendMessage(e)},[v]),T=le(t=>{var n;h(t),p(!0),null==(n=e.onLeadCapture)||n.call(e,t)},[e]);re(()=>{if(!e.triggers||c)return;const{delaySeconds:t,scrollPercent:n,pageViewCount:r,oncePerSession:o}=e.triggers,i=`ciro_triggered_${e.botId}`;if(!1!==o&&sessionStorage.getItem(i))return;const l=()=>{sessionStorage.setItem(i,"1"),f(!0)};let a,s;if(t&&t>0&&(a=setTimeout(l,1e3*t)),n&&n>0&&(s=()=>{window.scrollY/(document.documentElement.scrollHeight-window.innerHeight)*100>=n&&(l(),window.removeEventListener("scroll",s))},window.addEventListener("scroll",s,{passive:!0})),r&&r>0){const t=`ciro_views_${e.botId}`,n=parseInt(localStorage.getItem(t)||"0",10)+1;localStorage.setItem(t,String(n)),n>=r&&l()}return()=>{a&&clearTimeout(a),s&&window.removeEventListener("scroll",s)}},[e.triggers,e.botId]),re(()=>{const e=e=>{"Escape"===e.key&&c&&d(!1)};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[c]);const I=(null==(t=e.theme)?void 0:t.primaryColor)||(null==m?void 0:m.primary_color)||"#2563EB",$=e.position||(null==m?void 0:m.position)||"bottom-right",E=m?{...m,primary_color:(null==(n=e.theme)?void 0:n.primaryColor)||m.primary_color,background_color:(null==(r=e.theme)?void 0:r.backgroundColor)||m.background_color,text_color:(null==(o=e.theme)?void 0:o.textColor)||m.text_color,border_radius:null!=(l=null==(i=e.theme)?void 0:i.borderRadius)?l:m.border_radius,widget_width:(null==(a=e.theme)?void 0:a.widgetWidth)||m.widget_width,widget_height:(null==(s=e.theme)?void 0:s.widgetHeight)||m.widget_height}:null,R=le(()=>{f(!1),d(e=>!e)},[]);if(y||b||!m)return U(ye,{onClick:R,primaryColor:I,position:$,isOpen:c});const z=(E.require_email||E.require_name)&&!u&&!e.userEmail;return U(x,{children:[U(ye,{onClick:R,primaryColor:E.primary_color,position:$,isOpen:c,greeting:g?E.welcome_message:null,onDismissGreeting:()=>f(!1),unreadCount:v.unreadCount}),c&&(z?U(Ee,{config:E,position:$,onClose:k,onSubmit:T}):U(Te,{config:E,messages:v.messages,isStreaming:"streaming"===v.state,onSend:C,onSuggestionClick:S,onClose:k,onRate:v.rateConversation,onEscalate:v.escalate,position:$,locale:e.locale}))]})}function Ee({config:e,position:t,onClose:n,onSubmit:r}){const o=Re();return U("div",{style:{position:"fixed",bottom:o?"0":"90px",...o?{left:0,right:0}:"bottom-left"===t?{left:"20px"}:{right:"20px"},width:o?"100%":`${e.widget_width}px`,backgroundColor:e.background_color,borderRadius:o?"0":`${e.border_radius}px`,boxShadow:"0 8px 30px rgba(0,0,0,0.12)",zIndex:2147483647,fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',border:"1px solid rgba(0,0,0,0.08)",overflow:"hidden"},children:[U("div",{style:{padding:"16px",backgroundColor:e.primary_color,color:"white",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[U("span",{style:{fontWeight:600},children:e.name}),U("button",{onClick:n,style:{background:"none",border:"none",color:"white",cursor:"pointer",display:"flex"},children:U("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:[U("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),U("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),U(Ie,{config:e,onSubmit:r,primaryColor:e.primary_color})]})}function Re(){const[e,t]=ne("undefined"!=typeof window&&window.innerWidth<640);return re(()=>{const e=()=>t(window.innerWidth<640);return window.addEventListener("resize",e),window.addEventListener("orientationchange",e),()=>{window.removeEventListener("resize",e),window.removeEventListener("orientationchange",e)}},[]),e}let ze=null,He=null;const Me=()=>window.__ciroWidgetControl,We={init(e){if(ze)return void console.warn("[CiroChatbot] Already initialized. Call destroy() first.");if(!e.botId||!e.apiKey)return void console.error("[CiroChatbot] botId and apiKey are required.");if(!e.apiUrl){try{const t=document.querySelectorAll('script[src*="chatbot"]');if(t.length>0){const n=t[t.length-1].src;e.apiUrl=new URL(n).origin}}catch(r){}e.apiUrl||(e.apiUrl="https://api.ciroai.us")}ze=document.createElement("div"),ze.id="ciro-chatbot-widget",document.body.appendChild(ze);const t=ze.attachShadow({mode:"open"}),n=document.createElement("style");n.textContent="\n :host {\n all: initial;\n position: fixed;\n z-index: 2147483645;\n pointer-events: none;\n }\n :host > * { pointer-events: auto; }\n *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }\n button, textarea, input { font-family: inherit; }\n @keyframes ciro-blink {\n 0%, 50% { opacity: 1; }\n 51%, 100% { opacity: 0; }\n }\n @keyframes ciro-bubble-entrance {\n 0% { transform: scale(0); opacity: 0; }\n 100% { transform: scale(1); opacity: 1; }\n }\n @keyframes ciro-window-open {\n 0% { opacity: 0; transform: translateY(16px) scale(0.95); }\n 100% { opacity: 1; transform: translateY(0) scale(1); }\n }\n @keyframes ciro-glow-spin {\n from { transform: rotate(0deg); }\n to { transform: rotate(360deg); }\n }\n @keyframes ciro-thinking-dot {\n 0%, 80%, 100% { transform: scale(0.4); opacity: 0.3; }\n 40% { transform: scale(1); opacity: 1; }\n }\n ",t.appendChild(n),He=document.createElement("div"),t.appendChild(He);try{N(m($e,{config:e}),He)}catch(o){console.error("[CiroChatbot] Failed to render:",o)}},open(){var e;null==(e=Me())||e.open()},close(){var e;null==(e=Me())||e.close()},destroy(){He&&N(null,He),ze&&ze.remove(),ze=null,He=null,delete window.__ciroWidgetControl}};window.CiroChatbot=We;const Ae=document.currentScript;if(Ae){const e=Ae.getAttribute("data-ciro-bot-id"),t=Ae.getAttribute("data-ciro-api-key"),n=Ae.getAttribute("data-ciro-api-url");if(e&&t){const r=()=>We.init({botId:e,apiKey:t,apiUrl:n||void 0});"loading"===document.readyState?document.addEventListener("DOMContentLoaded",r):r()}}return We}();
|
|
1
|
+
var __CiroChatbot=function(){"use strict";var e,t,n,r,o,i,l,a,s,c,d,u={},p=[],_=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,h=Array.isArray;function g(e,t){for(var n in t)e[n]=t[n];return e}function f(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function m(t,n,r){var o,i,l,a={};for(l in n)"key"==l?o=n[l]:"ref"==l?i=n[l]:a[l]=n[l];if(arguments.length>2&&(a.children=arguments.length>3?e.call(arguments,2):r),"function"==typeof t&&null!=t.defaultProps)for(l in t.defaultProps)void 0===a[l]&&(a[l]=t.defaultProps[l]);return y(t,a,o,i,null)}function y(e,r,o,i,l){var a={type:e,props:r,key:o,ref:i,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:null==l?++n:l,__i:-1,__u:0};return null==l&&null!=t.vnode&&t.vnode(a),a}function x(e){return e.children}function b(e,t){this.props=e,this.context=t}function v(e,t){if(null==t)return e.__?v(e.__,e.__i+1):null;for(var n;t<e.__k.length;t++)if(null!=(n=e.__k[t])&&null!=n.__e)return n.__e;return"function"==typeof e.type?v(e):null}function w(e){if(e.__P&&e.__d){var n=e.__v,r=n.__e,o=[],i=[],l=g({},n);l.__v=n.__v+1,t.vnode&&t.vnode(l),R(e.__P,l,n,e.__n,e.__P.namespaceURI,32&n.__u?[r]:null,o,null==r?v(n):r,!!(32&n.__u),i),l.__v=n.__v,l.__.__k[l.__i]=l,L(o,l,i),n.__e=n.__=null,l.__e!=r&&k(l)}}function k(e){if(null!=(e=e.__)&&null!=e.__c)return e.__e=e.__c.base=null,e.__k.some(function(t){if(null!=t&&null!=t.__e)return e.__e=e.__c.base=t.__e}),k(e)}function C(e){(!e.__d&&(e.__d=!0)&&r.push(e)&&!S.__r++||o!=t.debounceRendering)&&((o=t.debounceRendering)||i)(S)}function S(){try{for(var e,t=1;r.length;)r.length>t&&r.sort(l),e=r.shift(),t=r.length,w(e)}finally{r.length=S.__r=0}}function T(e,t,n,r,o,i,l,a,s,c,d){var _,g,f,m,b,w,k,C=r&&r.__k||p,S=t.length;for(s=function(e,t,n,r,o){var i,l,a,s,c,d=n.length,u=d,p=0;for(e.__k=new Array(o),i=0;i<o;i++)null!=(l=t[i])&&"boolean"!=typeof l&&"function"!=typeof l?("string"==typeof l||"number"==typeof l||"bigint"==typeof l||l.constructor==String?l=e.__k[i]=y(null,l,null,null,null):h(l)?l=e.__k[i]=y(x,{children:l},null,null,null):void 0===l.constructor&&l.__b>0?l=e.__k[i]=y(l.type,l.props,l.key,l.ref?l.ref:null,l.__v):e.__k[i]=l,s=i+p,l.__=e,l.__b=e.__b+1,a=null,-1!=(c=l.__i=$(l,n,s,u))&&(u--,(a=n[c])&&(a.__u|=2)),null==a||null==a.__v?(-1==c&&(o>d?p--:o<d&&p++),"function"!=typeof l.type&&(l.__u|=4)):c!=s&&(c==s-1?p--:c==s+1?p++:(c>s?p--:p++,l.__u|=4))):e.__k[i]=null;if(u)for(i=0;i<d;i++)null!=(a=n[i])&&!(2&a.__u)&&(a.__e==r&&(r=v(a)),A(a,a));return r}(n,t,C,s,S),_=0;_<S;_++)null!=(f=n.__k[_])&&(g=-1!=f.__i&&C[f.__i]||u,f.__i=_,w=R(e,f,g,o,i,l,a,s,c,d),m=f.__e,f.ref&&g.ref!=f.ref&&(g.ref&&D(g.ref,null,f),d.push(f.ref,f.__c||m,f)),null==b&&null!=m&&(b=m),(k=!!(4&f.__u))||g.__k===f.__k?s=I(f,s,e,k):"function"==typeof f.type&&void 0!==w?s=w:m&&(s=m.nextSibling),f.__u&=-7);return n.__e=b,s}function I(e,t,n,r){var o,i;if("function"==typeof e.type){for(o=e.__k,i=0;o&&i<o.length;i++)o[i]&&(o[i].__=e,t=I(o[i],t,n,r));return t}e.__e!=t&&(r&&(t&&e.type&&!t.parentNode&&(t=v(e)),n.insertBefore(e.__e,t||null)),t=e.__e);do{t=t&&t.nextSibling}while(null!=t&&8==t.nodeType);return t}function $(e,t,n,r){var o,i,l,a=e.key,s=e.type,c=t[n],d=null!=c&&!(2&c.__u);if(null===c&&null==a||d&&a==c.key&&s==c.type)return n;if(r>(d?1:0))for(o=n-1,i=n+1;o>=0||i<t.length;)if(null!=(c=t[l=o>=0?o--:i++])&&!(2&c.__u)&&a==c.key&&s==c.type)return l;return-1}function E(e,t,n){"-"==t[0]?e.setProperty(t,null==n?"":n):e[t]=null==n?"":"number"!=typeof n||_.test(t)?n:n+"px"}function H(e,t,n,r,o){var i,l;e:if("style"==t)if("string"==typeof n)e.style.cssText=n;else{if("string"==typeof r&&(e.style.cssText=r=""),r)for(t in r)n&&t in n||E(e.style,t,"");if(n)for(t in n)r&&n[t]==r[t]||E(e.style,t,n[t])}else if("o"==t[0]&&"n"==t[1])i=t!=(t=t.replace(a,"$1")),l=t.toLowerCase(),t=l in e||"onFocusOut"==t||"onFocusIn"==t?l.slice(2):t.slice(2),e.l||(e.l={}),e.l[t+i]=n,n?r?n.u=r.u:(n.u=s,e.addEventListener(t,i?d:c,i)):e.removeEventListener(t,i?d:c,i);else{if("http://www.w3.org/2000/svg"==o)t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if("width"!=t&&"height"!=t&&"href"!=t&&"list"!=t&&"form"!=t&&"tabIndex"!=t&&"download"!=t&&"rowSpan"!=t&&"colSpan"!=t&&"role"!=t&&"popover"!=t&&t in e)try{e[t]=null==n?"":n;break e}catch(u){}"function"==typeof n||(null==n||!1===n&&"-"!=t[4]?e.removeAttribute(t):e.setAttribute(t,"popover"==t&&1==n?"":n))}}function z(e){return function(n){if(this.l){var r=this.l[n.type+e];if(null==n.t)n.t=s++;else if(n.t<r.u)return;return r(t.event?t.event(n):n)}}}function R(n,r,o,i,l,a,s,c,d,_){var m,y,w,k,C,S,I,$,E,z,R,L,D,A,P,O=r.type;if(void 0!==r.constructor)return null;128&o.__u&&(d=!!(32&o.__u),a=[c=r.__e=o.__e]),(m=t.__b)&&m(r);e:if("function"==typeof O)try{if($=r.props,E=O.prototype&&O.prototype.render,z=(m=O.contextType)&&i[m.__c],R=m?z?z.props.value:m.__:i,o.__c?I=(y=r.__c=o.__c).__=y.__E:(E?r.__c=y=new O($,R):(r.__c=y=new b($,R),y.constructor=O,y.render=N),z&&z.sub(y),y.state||(y.state={}),y.__n=i,w=y.__d=!0,y.__h=[],y._sb=[]),E&&null==y.__s&&(y.__s=y.state),E&&null!=O.getDerivedStateFromProps&&(y.__s==y.state&&(y.__s=g({},y.__s)),g(y.__s,O.getDerivedStateFromProps($,y.__s))),k=y.props,C=y.state,y.__v=r,w)E&&null==O.getDerivedStateFromProps&&null!=y.componentWillMount&&y.componentWillMount(),E&&null!=y.componentDidMount&&y.__h.push(y.componentDidMount);else{if(E&&null==O.getDerivedStateFromProps&&$!==k&&null!=y.componentWillReceiveProps&&y.componentWillReceiveProps($,R),r.__v==o.__v||!y.__e&&null!=y.shouldComponentUpdate&&!1===y.shouldComponentUpdate($,y.__s,R)){r.__v!=o.__v&&(y.props=$,y.state=y.__s,y.__d=!1),r.__e=o.__e,r.__k=o.__k,r.__k.some(function(e){e&&(e.__=r)}),p.push.apply(y.__h,y._sb),y._sb=[],y.__h.length&&s.push(y);break e}null!=y.componentWillUpdate&&y.componentWillUpdate($,y.__s,R),E&&null!=y.componentDidUpdate&&y.__h.push(function(){y.componentDidUpdate(k,C,S)})}if(y.context=R,y.props=$,y.__P=n,y.__e=!1,L=t.__r,D=0,E)y.state=y.__s,y.__d=!1,L&&L(r),m=y.render(y.props,y.state,y.context),p.push.apply(y.__h,y._sb),y._sb=[];else do{y.__d=!1,L&&L(r),m=y.render(y.props,y.state,y.context),y.state=y.__s}while(y.__d&&++D<25);y.state=y.__s,null!=y.getChildContext&&(i=g(g({},i),y.getChildContext())),E&&!w&&null!=y.getSnapshotBeforeUpdate&&(S=y.getSnapshotBeforeUpdate(k,C)),A=null!=m&&m.type===x&&null==m.key?W(m.props.children):m,c=T(n,h(A)?A:[A],r,o,i,l,a,s,c,d,_),y.base=r.__e,r.__u&=-161,y.__h.length&&s.push(y),I&&(y.__E=y.__=null)}catch(U){if(r.__v=null,d||null!=a)if(U.then){for(r.__u|=d?160:128;c&&8==c.nodeType&&c.nextSibling;)c=c.nextSibling;a[a.indexOf(c)]=null,r.__e=c}else{for(P=a.length;P--;)f(a[P]);M(r)}else r.__e=o.__e,r.__k=o.__k,U.then||M(r);t.__e(U,r,o)}else null==a&&r.__v==o.__v?(r.__k=o.__k,r.__e=o.__e):c=r.__e=function(n,r,o,i,l,a,s,c,d){var p,_,g,m,y,x,b,w=o.props||u,k=r.props,C=r.type;if("svg"==C?l="http://www.w3.org/2000/svg":"math"==C?l="http://www.w3.org/1998/Math/MathML":l||(l="http://www.w3.org/1999/xhtml"),null!=a)for(p=0;p<a.length;p++)if((y=a[p])&&"setAttribute"in y==!!C&&(C?y.localName==C:3==y.nodeType)){n=y,a[p]=null;break}if(null==n){if(null==C)return document.createTextNode(k);n=document.createElementNS(l,C,k.is&&k),c&&(t.__m&&t.__m(r,a),c=!1),a=null}if(null==C)w===k||c&&n.data==k||(n.data=k);else{if(a=a&&e.call(n.childNodes),!c&&null!=a)for(w={},p=0;p<n.attributes.length;p++)w[(y=n.attributes[p]).name]=y.value;for(p in w)y=w[p],"dangerouslySetInnerHTML"==p?g=y:"children"==p||p in k||"value"==p&&"defaultValue"in k||"checked"==p&&"defaultChecked"in k||H(n,p,null,y,l);for(p in k)y=k[p],"children"==p?m=y:"dangerouslySetInnerHTML"==p?_=y:"value"==p?x=y:"checked"==p?b=y:c&&"function"!=typeof y||w[p]===y||H(n,p,y,w[p],l);if(_)c||g&&(_.__html==g.__html||_.__html==n.innerHTML)||(n.innerHTML=_.__html),r.__k=[];else if(g&&(n.innerHTML=""),T("template"==r.type?n.content:n,h(m)?m:[m],r,o,i,"foreignObject"==C?"http://www.w3.org/1999/xhtml":l,a,s,a?a[0]:o.__k&&v(o,0),c,d),null!=a)for(p=a.length;p--;)f(a[p]);c||(p="value","progress"==C&&null==x?n.removeAttribute("value"):null!=x&&(x!==n[p]||"progress"==C&&!x||"option"==C&&x!=w[p])&&H(n,p,x,w[p],l),p="checked",null!=b&&b!=n[p]&&H(n,p,b,w[p],l))}return n}(o.__e,r,o,i,l,a,s,d,_);return(m=t.diffed)&&m(r),128&r.__u?void 0:c}function M(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some(M))}function L(e,n,r){for(var o=0;o<r.length;o++)D(r[o],r[++o],r[++o]);t.__c&&t.__c(n,e),e.some(function(n){try{e=n.__h,n.__h=[],e.some(function(e){e.call(n)})}catch(r){t.__e(r,n.__v)}})}function W(e){return"object"!=typeof e||null==e||e.__b>0?e:h(e)?e.map(W):g({},e)}function D(e,n,r){try{if("function"==typeof e){var o="function"==typeof e.__u;o&&e.__u(),o&&null==n||(e.__u=e(n))}else e.current=n}catch(i){t.__e(i,r)}}function A(e,n,r){var o,i;if(t.unmount&&t.unmount(e),(o=e.ref)&&(o.current&&o.current!=e.__e||D(o,null,n)),null!=(o=e.__c)){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(l){t.__e(l,n)}o.base=o.__P=null}if(o=e.__k)for(i=0;i<o.length;i++)o[i]&&A(o[i],n,r||"function"!=typeof e.type);r||f(e.__e),e.__c=e.__=e.__e=void 0}function N(e,t,n){return this.constructor(e,n)}function P(n,r,o){var i,l,a;r==document&&(r=document.documentElement),t.__&&t.__(n,r),i=!1?null:r.__k,l=[],a=[],R(r,n=r.__k=m(x,null,[n]),i||u,u,r.namespaceURI,i?null:r.firstChild?e.call(r.childNodes):null,l,i?i.__e:r.firstChild,false,a),L(l,n,a)}e=p.slice,t={__e:function(e,t,n,r){for(var o,i,l;t=t.__;)if((o=t.__c)&&!o.__)try{if((i=o.constructor)&&null!=i.getDerivedStateFromError&&(o.setState(i.getDerivedStateFromError(e)),l=o.__d),null!=o.componentDidCatch&&(o.componentDidCatch(e,r||{}),l=o.__d),l)return o.__E=o}catch(a){e=a}throw e}},n=0,b.prototype.setState=function(e,t){var n;n=null!=this.__s&&this.__s!=this.state?this.__s:this.__s=g({},this.state),"function"==typeof e&&(e=e(g({},n),this.props)),e&&g(n,e),null!=e&&this.__v&&(t&&this._sb.push(t),C(this))},b.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),C(this))},b.prototype.render=x,r=[],i="function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout,l=function(e,t){return e.__v.__b-t.__v.__b},S.__r=0,a=/(PointerCapture)$|Capture$/i,s=0,c=z(!1),d=z(!0);var O=0;function U(e,n,r,o,i,l){n||(n={});var a,s,c=n;if("ref"in c)for(s in c={},n)"ref"==s?a=n[s]:c[s]=n[s];var d={type:e,props:c,key:r,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--O,__i:-1,__u:0,__source:i,__self:l};if("function"==typeof e&&(a=e.defaultProps))for(s in a)void 0===c[s]&&(c[s]=a[s]);return t.vnode&&t.vnode(d),d}var F,q,j,B,K=0,J=[],Y=t,V=Y.__b,G=Y.__r,Z=Y.diffed,X=Y.__c,Q=Y.unmount,ee=Y.__;function te(e,t){Y.__h&&Y.__h(q,e,K||t),K=0;var n=q.__H||(q.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function ne(e){return K=1,function(e,t){var n=te(F++,2);if(n.t=e,!n.__c&&(n.__=[_e(void 0,t),function(e){var t=n.__N?n.__N[0]:n.__[0],r=n.t(t,e);t!==r&&(n.__N=[r,n.__[1]],n.__c.setState({}))}],n.__c=q,!q.__f)){var r=function(e,t,r){if(!n.__c.__H)return!0;var i=n.__c.__H.__.filter(function(e){return e.__c});if(i.every(function(e){return!e.__N}))return!o||o.call(this,e,t,r);var l=n.__c.props!==e;return i.some(function(e){if(e.__N){var t=e.__[0];e.__=e.__N,e.__N=void 0,t!==e.__[0]&&(l=!0)}}),o&&o.call(this,e,t,r)||l};q.__f=!0;var o=q.shouldComponentUpdate,i=q.componentWillUpdate;q.componentWillUpdate=function(e,t,n){if(this.__e){var l=o;o=void 0,r(e,t,n),o=l}i&&i.call(this,e,t,n)},q.shouldComponentUpdate=r}return n.__N||n.__}(_e,e)}function re(e,t){var n=te(F++,3);!Y.__s&&pe(n.__H,t)&&(n.__=e,n.u=t,q.__H.__h.push(n))}function oe(e){return K=5,ie(function(){return{current:e}},[])}function ie(e,t){var n=te(F++,7);return pe(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function le(e,t){return K=8,ie(function(){return e},t)}function ae(){for(var e;e=J.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(de),t.__h.some(ue),t.__h=[]}catch(n){t.__h=[],Y.__e(n,e.__v)}}}Y.__b=function(e){q=null,V&&V(e)},Y.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),ee&&ee(e,t)},Y.__r=function(e){G&&G(e),F=0;var t=(q=e.__c).__H;t&&(j===q?(t.__h=[],q.__h=[],t.__.some(function(e){e.__N&&(e.__=e.__N),e.u=e.__N=void 0})):(t.__h.some(de),t.__h.some(ue),t.__h=[],F=0)),j=q},Y.diffed=function(e){Z&&Z(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(1!==J.push(t)&&B===Y.requestAnimationFrame||((B=Y.requestAnimationFrame)||ce)(ae)),t.__H.__.some(function(e){e.u&&(e.__H=e.u),e.u=void 0})),j=q=null},Y.__c=function(e,t){t.some(function(e){try{e.__h.some(de),e.__h=e.__h.filter(function(e){return!e.__||ue(e)})}catch(n){t.some(function(e){e.__h&&(e.__h=[])}),t=[],Y.__e(n,e.__v)}}),X&&X(e,t)},Y.unmount=function(e){Q&&Q(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(e){try{de(e)}catch(n){t=n}}),n.__H=void 0,t&&Y.__e(t,n.__v))};var se="function"==typeof requestAnimationFrame;function ce(e){var t,n=function(){clearTimeout(r),se&&cancelAnimationFrame(t),setTimeout(e)},r=setTimeout(n,35);se&&(t=requestAnimationFrame(n))}function de(e){var t=q,n=e.__c;"function"==typeof n&&(e.__c=void 0,n()),q=t}function ue(e){var t=q;e.__c=e.__(),q=t}function pe(e,t){return!e||e.length!==t.length||t.some(function(t,n){return t!==e[n]})}function _e(e,t){return"function"==typeof t?t(e):t}class he{constructor(e,t,n){this.apiUrl=e,this.botId=t,this.apiKey=n}headers(){return{"Content-Type":"application/json","X-Chatbot-Key":this.apiKey}}url(e){return`${this.apiUrl}/api/chatbot-widget/${this.botId}${e}`}async init(){const e=await fetch(this.url("/init"),{method:"POST",headers:this.headers()});if(!e.ok)throw new Error(`Init failed: ${e.status}`);return e.json()}async createConversation(e){const t=await fetch(this.url("/conversations"),{method:"POST",headers:this.headers(),body:JSON.stringify(e||{})});if(!t.ok){const e=await t.json().catch(()=>({message:`HTTP ${t.status}`}));throw new Error(e.message||`Create conversation failed: ${t.status}`)}return t.json()}async getMessages(e){const t=await fetch(this.url(`/conversations/${e}/messages`),{headers:this.headers()});if(!t.ok)throw new Error(`Get messages failed: ${t.status}`);return t.json()}streamMessage(e,t,n){const r=new AbortController;return(async()=>{try{const i=await fetch(this.url(`/conversations/${e}/messages`),{method:"POST",headers:this.headers(),body:JSON.stringify({content:t}),signal:r.signal});if(!i.ok){const e=await i.json().catch(()=>({message:`HTTP ${i.status}`}));return void n.onError(e.message||"Request failed")}if(!i.body||"function"!=typeof i.body.getReader){const e=(await i.text()).split("\n").filter(e=>e.startsWith("data: ")).pop();if(e)try{const t=JSON.parse(e.slice(6));t.text&&n.onTextDelta(t.text)}catch(o){}return void n.onEnd()}const l=i.body.getReader(),a=new TextDecoder;let s="";for(;;){const{done:e,value:t}=await l.read();if(e)break;let r;for(s+=a.decode(t,{stream:!0});-1!==(r=s.indexOf("\n\n"));){const e=s.slice(0,r);s=s.slice(r+2);let t="",i="";for(const n of e.split("\n"))n.startsWith("event: ")?t=n.slice(7).trim():n.startsWith("data: ")&&(i+=(i?"\n":"")+n.slice(6));if(t&&i)try{const e=JSON.parse(i);switch(t){case"text:delta":n.onTextDelta(e.text||"");break;case"source:add":n.onSource({label:e.label||"",detail:e.detail||""});break;case"suggestions":n.onSuggestions(e.questions||[]);break;case"confidence":n.onConfidence(e);break;case"stream:end":return void n.onEnd();case"stream:error":return void n.onError(e.message||"Stream error")}}catch(o){}}}n.onEnd()}catch(i){if("AbortError"===i.name)return;n.onError(i.message||"Connection failed")}})(),r}async rateConversation(e,t){await fetch(this.url(`/conversations/${e}/rate`),{method:"POST",headers:this.headers(),body:JSON.stringify({satisfaction:t})})}async escalateConversation(e){await fetch(this.url(`/conversations/${e}/escalate`),{method:"POST",headers:this.headers()})}}const ge="ciro_chat_";function fe(e,t){var n,r;const o=oe(function(e){try{const t=localStorage.getItem(`${ge}${e}`);if(!t)return null;const n=JSON.parse(t);return Date.now()-(n.timestamp||0)>864e5?(localStorage.removeItem(`${ge}${e}`),null):{conversationId:n.conversationId,messages:n.messages||[]}}catch(t){return null}}(e.botId)),[i,l]=ne((null==(n=o.current)?void 0:n.messages)||[]),[a,s]=ne("idle"),[c,d]=ne((null==(r=o.current)?void 0:r.conversationId)||null),[u,p]=ne(null),[_,h]=ne(0),g=oe(null),f=oe(null),m=oe(0),y=oe(null),x=oe(""),b=oe(!1);g.current||(g.current=new he(e.apiUrl||window.location.origin,e.botId,e.apiKey));const v=g.current;re(()=>()=>{var e;null==(e=f.current)||e.abort()},[]),re(()=>{c&&i.length>0&&function(e,t,n){try{const r=n.slice(-50).map(({isStreaming:e,...t})=>t);localStorage.setItem(`${ge}${e}`,JSON.stringify({conversationId:t,messages:r,timestamp:Date.now()}))}catch(r){}}(e.botId,c,i)},[i,c,e.botId]);const w=le(e=>{b.current=e,e&&h(0)},[]),k=le(async()=>{if(c)return c;if(y.current)return y.current;const t=v.createConversation({external_user_id:e.externalUserId,user_email:e.userEmail,user_name:e.userName}).then(e=>(d(e.conversation_id),y.current=null,e.conversation_id)).catch(e=>{throw y.current=null,e});return y.current=t,t},[c,e,v]),C=le(async t=>{var n,r;if(!t.trim()||"streaming"===a)return;p(null),x.current="";const o="user_"+ ++m.current;l(e=>[...e,{id:o,role:"user",content:t.trim(),created_at:(new Date).toISOString()}]),null==(n=e.onMessage)||n.call(e,{role:"user",content:t.trim()});const i="assistant_"+ ++m.current;l(e=>[...e,{id:i,role:"assistant",content:"",sources:[],suggestions:[],isStreaming:!0}]),s("streaming");try{const n=await k();f.current=v.streamMessage(n,t.trim(),{onTextDelta:e=>{x.current+=e,l(t=>t.map(t=>t.id===i?{...t,content:t.content+e}:t))},onSource:e=>{l(t=>t.map(t=>t.id===i?{...t,sources:[...t.sources||[],{name:e.label,type:e.detail}]}:t))},onSuggestions:e=>{l(t=>t.map(t=>t.id===i?{...t,suggestions:e}:t))},onConfidence:e=>{l(t=>t.map(t=>t.id===i?{...t,confidence:e.overall}:t))},onEnd:()=>{var t;l(e=>e.map(e=>e.id===i?{...e,isStreaming:!1,created_at:(new Date).toISOString()}:e)),s("idle"),x.current&&(null==(t=e.onMessage)||t.call(e,{role:"assistant",content:x.current})),b.current||h(e=>e+1)},onError:t=>{var n;l(e=>e.map(e=>e.id===i?{...e,content:t||"Something went wrong.",isStreaming:!1}:e)),s("error"),p(t),null==(n=e.onError)||n.call(e,new Error(t))}})}catch(c){l(e=>e.map(e=>e.id===i?{...e,content:"Failed to connect. Please try again.",isStreaming:!1}:e)),s("error"),p(c.message),null==(r=e.onError)||r.call(e,c)}},[a,e,v,k]),S=le(()=>{var e;null==(e=f.current)||e.abort(),f.current=null,l(e=>e.map(e=>e.isStreaming?{...e,isStreaming:!1}:e)),s("idle")},[]),T=le(async e=>{if(c)try{await v.rateConversation(c,e)}catch(t){}},[c,v]),I=le(async()=>{if(c)try{await v.escalateConversation(c),l(e=>[...e,{id:"system_"+ ++m.current,role:"system",content:(null==t?void 0:t.escalation_message)||"Connecting you with a human agent..."}])}catch(e){}},[c,v,t]),$=le(()=>{var t;null==(t=f.current)||t.abort(),l([]),d(null),s("idle"),h(0),localStorage.removeItem(`${ge}${e.botId}`)},[e.botId]);return{messages:i,state:a,error:u,conversationId:c,unreadCount:_,sendMessage:C,cancelStream:S,rateConversation:T,escalate:I,clearConversation:$,setIsOpen:w}}function me({color:e="white",size:t=22}){return U("svg",{width:t,height:.574*t,viewBox:"0 0 515 296",fill:e,children:[U("path",{d:"M294.79,207.08l.97-1.03.11-.11,28.71-30.02,5.85-6.13h-.02l.05-.06c1.64-1.65,3.04-3.54,4.15-5.62l.03-.06c.36-.67.7-1.36,1-2.08l.09-.28c.27-.64.52-1.3.72-1.97.06-.2.11-.41.16-.61.17-.58.33-1.15.45-1.75.08-.38.11-.77.17-1.16.06-.39.15-.78.19-1.17.09-.86.14-1.74.14-2.62,0-8.77-4.6-16.48-11.5-20.89-3.84-2.44-8.38-3.87-13.25-3.87-6.28,0-11.99,2.37-16.36,6.23-.5.44-.98.89-1.45,1.37v-.05l-6.21,6.51-13.17,13.77-1.44,1.51-12.66,13.24-1.08,1.12-27.88,29.17-1.2,1.25-7.63,7.99-1.09,1.12-4.06,4.26c-1.16.91-2.31,1.83-3.5,2.72-1.76,1.53-3.59,3-5.48,4.4-7.82,5.87-16.58,10.6-26.02,13.94-3.25,1.14-6.59,2.11-9.99,2.92-.91.22-1.83.42-2.75.61-3.18.67-6.42,1.17-9.71,1.53-3.47.36-6.99.56-10.55.56-.25,0-.5-.02-.73-.02-.72,0-1.41-.03-2.11-.05-20.09-.58-38.67-7.1-53.9-17.84-.44-.3-.87-.59-1.3-.89-4.61-3.36-8.87-7.1-12.78-11.18-.36-.37-.72-.75-1.08-1.12-15.52-16.69-24.98-38.79-24.98-62.99,0-21.24,7.29-40.87,19.57-56.63,5.15-6.62,11.21-12.55,17.97-17.65.42-.31.83-.64,1.25-.95,9.1-6.65,19.45-11.75,30.63-14.97,7.91-2.28,16.25-3.59,24.87-3.81.7-.02,1.4-.05,2.11-.05.17,0,.33-.02.48-.02,21.22,0,40.86,6.68,56.84,17.97,1.46,1.03,3.47.8,4.71-.49l28.09-29.37,2.21-2.32c1.46-1.53,1.32-3.99-.31-5.35-1.23-1.02-2.47-2.03-3.73-3.01C213.34,11.63,181.88,0,147.78,0c-14.92,0-29.35,2.23-42.93,6.37-.56.17-1.12.34-1.67.52-17.84,5.65-34.23,14.63-48.44,26.16-.41.33-.81.66-1.22,1C20.86,61.16,0,102.07,0,147.76c0,39.62,15.69,75.64,41.16,102.21.36.37.73.75,1.09,1.12,3.95,4.03,8.13,7.85,12.53,11.41.41.33.81.66,1.22.98,2.96,2.36,6.02,4.62,9.18,6.74,11.53,7.8,24.24,14.02,37.79,18.34l.06-.08c.55.19,1.09.39,1.64.56,1.48.47,2.97.91,4.46,1.33,3.58.97,7.2,1.81,10.88,2.51.61.12,1.22.23,1.83.34,5.87,1.05,11.85,1.73,17.94,2.06.69.05,1.37.06,2.08.09,1.95.08,3.93.12,5.91.12,37.84,0,72.41-14.31,98.59-37.79l10.51-11.01,1.08-1.12.16-.17,1.09-1.12,2.92-3.06,8.99-9.41,23.57-24.65.11-.11Z"}),U("path",{d:"M473.9,45.55c-.36-.37-.73-.75-1.09-1.12-3.95-4.03-8.13-7.85-12.53-11.41-.41-.33-.81-.66-1.22-.98-2.96-2.36-6.02-4.62-9.18-6.74-11.53-7.8-24.24-14.02-37.79-18.34l-.06.08c-.55-.19-1.09-.39-1.64-.56-1.48-.47-2.97-.91-4.46-1.33-3.58-.97-7.2-1.81-10.88-2.51-.61-.12-1.22-.23-1.83-.34-5.87-1.05-11.85-1.73-17.94-2.06-.69-.05-1.37-.06-2.08-.09-1.95-.08-3.93-.12-5.91-.12-37.84,0-72.41,14.31-98.59,37.79l-10.51,11.01-1.08,1.12-.16.17-1.09,1.12-2.92,3.06-8.99,9.41-23.57,24.65-.11.11-.97,1.03-.11.11-28.71,30.02-9.61,10.17h.02l-.05.06c-1.64,1.65-3.04,3.54-4.15,5.62l-.03.06c-.36.67-.7,1.36-1,2.08l-.09.28c-.27.64-.52,1.3-.72,1.97-.06.2-.11.41-.16.61-.17.58-.33,1.15-.45,1.75-.08.37-.11.77-.17,1.16-.08.42-.16.84-.2,1.28-.08.83-.12,1.67-.12,2.51,0,6.05,2.19,11.59,5.81,15.9h0s.03.03.03.03c.66.78,1.36,1.52,2.11,2.21l29.06,30.43,34.34-35.89-12.31-12.8,6.67-6.98,1.44-1.51,12.66-13.24,1.08-1.12,27.88-29.17,1.2-1.25,7.63-7.99,1.09-1.12,4.06-4.26c1.16-.91,2.31-1.83,3.5-2.72,1.76-1.53,3.59-3,5.48-4.4,7.82-5.87,16.58-10.6,26.02-13.94,3.25-1.14,6.59-2.11,9.99-2.92.91-.22,1.83-.42,2.75-.61,3.18-.67,6.42-1.17,9.71-1.53,3.47-.36,6.99-.56,10.55-.56.25,0,.5.02.73.02.72,0,1.41.03,2.11.05,20.09.58,38.67,7.1,53.9,17.84.44.3.87.59,1.3.89,4.61,3.36,8.87,7.1,12.78,11.18.36.37.72.75,1.08,1.12,15.52,16.69,24.98,38.79,24.98,62.99,0,21.24-7.29,40.87-19.57,56.63-5.15,6.62-11.21,12.55-17.97,17.65-.42.31-.83.64-1.25.95-9.1,6.65-19.45,11.75-30.63,14.97-7.91,2.28-16.25,3.59-24.87,3.81-.7.02-1.4.05-2.11.05-.17,0-.33.02-.48.02-22.34,0-42.93-7.4-59.33-19.79l-30.3,31.69-4.89,5.12c2.19,1.9,4.42,3.76,6.71,5.56,25.04,19.48,56.49,31.11,90.6,31.11,14.92,0,29.35-2.23,42.93-6.37.56-.17,1.12-.34,1.67-.52,17.84-5.65,34.23-14.63,48.44-26.16.41-.33.81-.66,1.22-1,32.67-27.11,53.53-68.03,53.53-113.72,0-39.62-15.69-75.64-41.16-102.21Z"})]})}function ye({onClick:e,primaryColor:t,position:n,isOpen:r,greeting:o,onDismissGreeting:i,unreadCount:l=0}){const a="bottom-left"===n?{left:"20px",right:"auto"}:{right:"20px",left:"auto"};return U(x,{children:[o&&!r&&U("div",{style:{position:"fixed",bottom:"88px",...a,maxWidth:"260px",padding:"12px 16px",backgroundColor:"white",borderRadius:"14px",boxShadow:"0 4px 24px rgba(0,0,0,0.12)",fontSize:"13px",lineHeight:1.5,color:"#374151",zIndex:2147483646,cursor:"pointer",animation:"ciro-window-open 0.3s cubic-bezier(0.16, 1, 0.3, 1)",border:"1px solid rgba(0,0,0,0.06)"},onClick:e,children:[U("div",{style:{display:"flex",alignItems:"center",gap:"6px",marginBottom:"6px",opacity:.5,fontSize:"11px",fontWeight:600,letterSpacing:"0.3px"},children:[U(me,{color:"#5e6a98",size:14}),"CIRO AI"]}),o,U("button",{onClick:e=>{e.stopPropagation(),null==i||i()},"aria-label":"Dismiss",style:{position:"absolute",top:"-6px",right:"-6px",width:"20px",height:"20px",borderRadius:"50%",backgroundColor:"#e5e7eb",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"10px",color:"#6b7280"},children:"x"})]}),U("div",{style:{position:"fixed",bottom:"20px",...a,zIndex:2147483646,animation:"ciro-bubble-entrance 0.4s cubic-bezier(0.34, 1.56, 0.64, 1)"},children:[U("div",{style:{position:"absolute",inset:"-3px",borderRadius:"50%",background:r?"none":`conic-gradient(from 0deg, ${t}, #f59e0b, #ec4899, #8b5cf6, #06b6d4, ${t})`,opacity:r?0:.6,animation:r?"none":"ciro-glow-spin 4s linear infinite",transition:"opacity 0.3s",filter:"blur(2px)"}}),U("button",{onClick:e,"aria-label":r?"Close chat":"Open chat",style:{position:"relative",width:"58px",height:"58px",borderRadius:"50%",backgroundColor:"#1a1a2e",border:"2px solid rgba(255,255,255,0.1)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 4px 20px rgba(0,0,0,0.3)",transition:"transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease",WebkitTapHighlightColor:"transparent"},onMouseEnter:e=>{const t=e.currentTarget;t.style.transform="scale(1.08)",t.style.boxShadow="0 6px 28px rgba(0,0,0,0.4)"},onMouseLeave:e=>{const t=e.currentTarget;t.style.transform="scale(1)",t.style.boxShadow="0 4px 20px rgba(0,0,0,0.3)"},children:r?U("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"white","stroke-width":"2.5","stroke-linecap":"round",children:[U("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),U("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}):U(me,{color:"white",size:28})}),!r&&l>0&&U("span",{style:{position:"absolute",top:"-5px",right:"-5px",minWidth:"20px",height:"20px",borderRadius:"10px",backgroundColor:"#ef4444",color:"white",fontSize:"11px",fontWeight:700,display:"flex",alignItems:"center",justifyContent:"center",padding:"0 5px",border:"2px solid white",animation:"ciro-bubble-entrance 0.3s ease",zIndex:1},children:l>9?"9+":l})]})]})}function xe(e,t){var n;if(!e)return e;const r=e.split(/\n{2,}/),o=[];let i=0;for(const l of r){const e=l.trim();if(!e)continue;if(/^#{1,3}\s/.test(e)){const r=(null==(n=e.match(/^(#{1,3})/))?void 0:n[1].length)||2,l=e.replace(/^#{1,3}\s+/,"");o.push(U("div",{style:{fontWeight:700,fontSize:1===r?"16px":2===r?"15px":"14px",marginTop:o.length>0?"12px":"0",marginBottom:"4px",color:t},children:be(l,t,i)},i++));continue}const r=e.split("\n").filter(e=>/^\d+[\.\)]\s/.test(e.trim()));if(r.length>1){o.push(U("ol",{style:{margin:"6px 0",paddingLeft:"20px",listStyleType:"decimal"},children:r.map((e,n)=>U("li",{style:{marginBottom:"4px",lineHeight:1.5},children:be(e.replace(/^\d+[\.\)]\s+/,""),t,i+n)},n))},i++)),i+=r.length;continue}const a=e.split("\n").filter(e=>/^[\-\*]\s/.test(e.trim()));if(a.length>1){o.push(U("ul",{style:{margin:"6px 0",paddingLeft:"18px",listStyleType:"disc"},children:a.map((e,n)=>U("li",{style:{marginBottom:"3px",lineHeight:1.5},children:be(e.replace(/^[\-\*]\s+/,""),t,i+n)},n))},i++)),i+=a.length;continue}const s=e.split("\n");o.push(U("div",{style:{marginBottom:"6px",lineHeight:1.6},children:s.map((e,n)=>U("span",{children:[n>0&&U("br",{}),be(e,t,i+n)]},n))},i++)),i+=s.length}return o.length>0?o:e}function be(e,t,n){const r=[];let o=100*n;const i=/(!\[([^\]]*)\]\(([^)]+)\))|(\*\*(.+?)\*\*)|(\*(.+?)\*)|(`(.+?)`)|(\[(.+?)\]\((.+?)\))/g;let l,a=0;for(;null!==(l=i.exec(e));)l.index>a&&r.push(e.slice(a,l.index)),l[1]?r.push(U("img",{src:l[3],alt:l[2]||"",style:{maxWidth:"100%",borderRadius:"8px",margin:"4px 0",display:"block"},onError:e=>{e.target.style.display="none"}},o++)):l[4]?r.push(U("strong",{children:l[5]},o++)):l[6]?r.push(U("em",{children:l[7]},o++)):l[8]?r.push(U("code",{style:{backgroundColor:"rgba(0,0,0,0.06)",padding:"1px 4px",borderRadius:"3px",fontSize:"12px",fontFamily:"monospace"},children:l[9]},o++)):l[10]&&r.push(U("a",{href:l[12],target:"_blank",rel:"noopener noreferrer",style:{color:t,textDecoration:"underline"},children:l[11]},o++)),a=l.index+l[0].length;return a<e.length&&r.push(e.slice(a)),r.length>0?r:e}function ve(e){if(!e)return"";try{return new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch(t){return""}}function we({color:e,size:t=28}){return U("div",{style:{width:`${t}px`,height:`${t}px`,borderRadius:"8px",backgroundColor:`${e}12`,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:U(me,{color:e,size:.55*t})})}function ke({messages:e,config:t,onRate:n,lastAssistantId:r,feedbackThanks:o}){const[i,l]=ne(null),a=(e,t)=>{l(e),n(t)};return U(x,{children:e.map((n,l)=>{if("system"===n.role)return U("div",{style:{textAlign:"center",fontSize:"11px",opacity:.5,padding:"12px 0",display:"flex",alignItems:"center",gap:"8px"},children:[U("div",{style:{flex:1,height:"1px",backgroundColor:"rgba(0,0,0,0.08)"}}),U("span",{children:n.content}),U("div",{style:{flex:1,height:"1px",backgroundColor:"rgba(0,0,0,0.08)"}})]},n.id);const s="user"===n.role,c=n.id===r&&!n.isStreaming&&n.content,d=i===n.id,u=l>0?e[l-1]:null,p=!(s||u&&"assistant"===u.role);return U("div",{style:{display:"flex",gap:"8px",alignItems:"flex-start",flexDirection:s?"row-reverse":"row",marginTop:(null==u?void 0:u.role)===n.role?"2px":"8px"},children:[!s&&U("div",{style:{width:"28px",flexShrink:0},children:p&&(t.avatar_url?U("img",{src:t.avatar_url,alt:"",style:{width:"28px",height:"28px",borderRadius:"50%",objectFit:"cover"},onError:e=>{e.target.style.display="none"}}):U(we,{color:t.primary_color}))}),U("div",{style:{maxWidth:"78%",display:"flex",flexDirection:"column",alignItems:s?"flex-end":"flex-start"},children:[!s&&p&&U("div",{style:{fontSize:"11px",fontWeight:500,opacity:.5,marginBottom:"3px",paddingLeft:"2px"},children:t.name}),U("div",{style:{padding:"10px 14px",borderRadius:s?`${t.border_radius}px ${t.border_radius}px 4px ${t.border_radius}px`:p?`4px ${t.border_radius}px ${t.border_radius}px ${t.border_radius}px`:`${t.border_radius}px`,backgroundColor:s?t.primary_color:`${t.primary_color}0A`,color:s?"white":t.text_color,lineHeight:1.5,wordBreak:"break-word",fontSize:"14px",border:s?"none":`1px solid ${t.primary_color}10`},children:[n.content?xe(n.content,t.primary_color):null,n.isStreaming&&!n.content&&U("span",{style:{display:"inline-flex",gap:"3px",padding:"2px 0"},children:[0,1,2].map(e=>U("span",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:t.text_color||"#6b7280",opacity:.4,display:"inline-block",animation:`ciro-thinking-dot 1.4s ease-in-out ${.16*e}s infinite`}},e))}),n.isStreaming&&n.content&&U("span",{style:{display:"inline-block",animation:"ciro-blink 1s infinite",marginLeft:"1px"},children:"|"})]}),n.created_at&&!n.isStreaming&&U("div",{style:{fontSize:"10px",opacity:.35,marginTop:"3px",paddingLeft:s?"0":"2px",paddingRight:s?"2px":"0"},children:ve(n.created_at)}),!s&&n.sources&&n.sources.length>0&&t.include_citations&&U("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginTop:"4px"},children:n.sources.map((e,n)=>U("span",{style:{fontSize:"10px",padding:"2px 7px",borderRadius:"10px",backgroundColor:`${t.primary_color}10`,color:t.primary_color,border:`1px solid ${t.primary_color}20`},children:e.name},n))}),c&&U("div",{style:{display:"flex",gap:"4px",marginTop:"6px"},children:d?U("span",{style:{fontSize:"11px",opacity:.4},children:o||"Thanks for your feedback"}):U(x,{children:[U("button",{onClick:()=>a(n.id,"positive"),"aria-label":"Helpful",style:{background:"none",border:"1px solid rgba(0,0,0,0.08)",borderRadius:"14px",cursor:"pointer",fontSize:"12px",opacity:.5,padding:"3px 10px",minHeight:"26px",transition:"all 0.15s"},onMouseEnter:e=>{e.currentTarget.style.opacity="1",e.currentTarget.style.backgroundColor="rgba(0,0,0,0.03)"},onMouseLeave:e=>{e.currentTarget.style.opacity="0.5",e.currentTarget.style.backgroundColor="transparent"},children:"👍 Helpful"}),U("button",{onClick:()=>a(n.id,"negative"),"aria-label":"Not helpful",style:{background:"none",border:"1px solid rgba(0,0,0,0.08)",borderRadius:"14px",cursor:"pointer",fontSize:"12px",opacity:.5,padding:"3px 10px",minHeight:"26px",transition:"all 0.15s"},onMouseEnter:e=>{e.currentTarget.style.opacity="1",e.currentTarget.style.backgroundColor="rgba(0,0,0,0.03)"},onMouseLeave:e=>{e.currentTarget.style.opacity="0.5",e.currentTarget.style.backgroundColor="transparent"},children:"👎"})]})})]})]},n.id)})})}const Ce=5e3;function Se({onSend:e,isStreaming:t,primaryColor:n,placeholder:r}){const[o,i]=ne(""),l=oe(null),a=le(()=>{const n=o.trim();n&&!t&&(n.length>Ce||(e(n),i(""),l.current&&(l.current.style.height="auto"),setTimeout(()=>{var e;return null==(e=l.current)?void 0:e.focus()},50)))},[o,t,e]),s=le(e=>{const t=e.target,n=t.value.slice(0,Ce);i(n),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,100)}px`},[]),c=le(e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),a())},[a]),d=o.trim().length>0&&!t;return U("div",{style:{padding:"10px 12px",borderTop:"1px solid rgba(0,0,0,0.08)",display:"flex",alignItems:"flex-end",gap:"8px",flexShrink:0},children:[U("textarea",{ref:l,value:o,onInput:s,onKeyDown:c,placeholder:r,disabled:t,rows:1,maxLength:Ce,"aria-label":"Message input",style:{flex:1,border:"1px solid rgba(0,0,0,0.12)",borderRadius:"20px",padding:"10px 16px",fontSize:"14px",resize:"none",outline:"none",fontFamily:"inherit",lineHeight:1.4,maxHeight:"100px",minHeight:"40px",overflow:"auto",backgroundColor:"transparent",color:"inherit",transition:"border-color 0.15s"},onFocus:e=>{e.currentTarget.style.borderColor=n},onBlur:e=>{e.currentTarget.style.borderColor="rgba(0,0,0,0.12)"}}),U("button",{onClick:a,disabled:!d,"aria-label":"Send message",style:{width:"40px",height:"40px",borderRadius:"50%",backgroundColor:d?n:"#e5e7eb",border:"none",cursor:d?"pointer":"default",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,transition:"background-color 0.15s",minHeight:"44px",minWidth:"44px"},children:U("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"white","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[U("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),U("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})})]})}function Te({questions:e,onClick:t,primaryColor:n}){if(!e.length)return null;const r=e.length>=4;return U("div",{role:"list","aria-label":"Suggested questions",style:{display:r?"grid":"flex",gridTemplateColumns:r?"repeat(2, 1fr)":void 0,flexDirection:r?void 0:"column",gap:"6px",padding:"4px 0"},children:e.map((e,o)=>U("button",{role:"listitem",onClick:()=>t(e),style:{padding:r?"10px 12px":"10px 14px",border:`1px solid ${n}25`,borderRadius:"12px",backgroundColor:"transparent",color:n,cursor:"pointer",textAlign:"left",fontSize:"13px",lineHeight:1.4,fontFamily:"inherit",transition:"all 0.15s ease",minHeight:"40px",display:"flex",alignItems:"center",fontWeight:500},onMouseEnter:e=>{const t=e.currentTarget;t.style.backgroundColor=`${n}10`,t.style.borderColor=`${n}40`,t.style.transform="translateY(-1px)"},onMouseLeave:e=>{const t=e.currentTarget;t.style.backgroundColor="transparent",t.style.borderColor=`${n}25`,t.style.transform="none"},children:e},o))})}function Ie({config:e,messages:t,isStreaming:n,onSend:r,onSuggestionClick:o,onClose:i,onRate:l,onEscalate:a,onNewChat:s,position:c,locale:d}){const u=oe(null),p=oe(0),_=ze();re(()=>{if(t.length>p.current){const e=u.current;e&&requestAnimationFrame(()=>{e.scrollTop=e.scrollHeight})}p.current=t.length},[t.length]),re(()=>{if(!n)return;const e=u.current;e&&e.scrollHeight-e.scrollTop-e.clientHeight<100&&(e.scrollTop=e.scrollHeight)},[t,n]);const h=[...t].reverse().find(e=>"assistant"===e.role&&!e.isStreaming),g=(null==h?void 0:h.suggestions)||[],f=0===t.length,m="bottom-left"===c?{left:"20px",right:"auto"}:{right:"20px",left:"auto"};return U("div",{role:"dialog","aria-label":`Chat with ${e.name}`,style:{position:"fixed",bottom:_?"0":"90px",..._?{left:0,right:0}:m,width:_?"100%":`${e.widget_width}px`,height:_?"100%":`${e.widget_height}px`,maxHeight:_?"100vh":"calc(100vh - 110px)",backgroundColor:e.background_color,borderRadius:_?"0":`${e.border_radius}px`,boxShadow:"0 8px 40px rgba(0,0,0,0.15), 0 2px 8px rgba(0,0,0,0.08)",display:"flex",flexDirection:"column",overflow:"hidden",zIndex:2147483647,fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',fontSize:"14px",color:e.text_color,border:_?"none":"1px solid rgba(0,0,0,0.06)",animation:"ciro-window-open 0.25s cubic-bezier(0.16, 1, 0.3, 1)"},children:[U("div",{style:{padding:"0",backgroundColor:e.primary_color,color:"white",flexShrink:0,borderRadius:_?"0":`${e.border_radius}px ${e.border_radius}px 0 0`,overflow:"hidden"},children:U("div",{style:{padding:"14px 16px",display:"flex",alignItems:"center",justifyContent:"space-between",background:`linear-gradient(135deg, ${e.primary_color}, ${e.primary_color}dd)`},children:[U("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[e.avatar_url?U("img",{src:e.avatar_url,alt:"",style:{width:"36px",height:"36px",borderRadius:"50%",objectFit:"cover",border:"2px solid rgba(255,255,255,0.2)"},onError:e=>{e.target.style.display="none"}}):U("div",{style:{width:"36px",height:"36px",borderRadius:"10px",backgroundColor:"rgba(255,255,255,0.15)",display:"flex",alignItems:"center",justifyContent:"center"},children:U(me,{color:"white",size:20})}),U("div",{children:[U("div",{style:{fontWeight:600,fontSize:"15px",letterSpacing:"-0.01em"},children:e.name}),U("div",{style:{fontSize:"12px",opacity:.9,display:"flex",alignItems:"center",gap:"4px"},children:n?U("span",{style:{display:"inline-flex",gap:"2px",alignItems:"center"},children:[U("span",{children:(null==d?void 0:d.typing)||"Typing"}),[0,1,2].map(e=>U("span",{style:{width:"3px",height:"3px",borderRadius:"50%",backgroundColor:"white",animation:`ciro-thinking-dot 1.4s ease-in-out ${.16*e}s infinite`}},e))]}):U(x,{children:[U("span",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#4ade80",display:"inline-block",boxShadow:"0 0 4px #4ade80"}}),(null==d?void 0:d.online)||"Online"]})})]})]}),U("div",{style:{display:"flex",gap:"4px"},children:[s&&t.length>0&&U("button",{onClick:s,"aria-label":"New chat",title:"New conversation",style:{background:"rgba(255,255,255,0.1)",border:"none",color:"white",cursor:"pointer",padding:"8px",display:"flex",borderRadius:"8px",minHeight:"36px",minWidth:"36px",alignItems:"center",justifyContent:"center",transition:"background 0.15s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(255,255,255,0.2)"},onMouseLeave:e=>{e.currentTarget.style.background="rgba(255,255,255,0.1)"},children:U("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round",children:[U("path",{d:"M12 20h9"}),U("path",{d:"M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"})]})}),U("button",{onClick:i,"aria-label":"Close chat",style:{background:"rgba(255,255,255,0.1)",border:"none",color:"white",cursor:"pointer",padding:"8px",display:"flex",borderRadius:"8px",minHeight:"36px",minWidth:"36px",alignItems:"center",justifyContent:"center",transition:"background 0.15s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(255,255,255,0.2)"},onMouseLeave:e=>{e.currentTarget.style.background="rgba(255,255,255,0.1)"},children:U("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:[U("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),U("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]})}),U("div",{ref:u,style:{flex:1,overflowY:"auto",padding:"16px",display:"flex",flexDirection:"column",gap:"4px",WebkitOverflowScrolling:"touch"},children:[f&&U("div",{style:{padding:"16px 0 8px",display:"flex",flexDirection:"column",alignItems:"center"},children:U("div",{style:{backgroundColor:`${e.primary_color}08`,border:`1px solid ${e.primary_color}15`,borderRadius:"16px",padding:"20px",textAlign:"center",width:"100%",marginBottom:"16px"},children:[e.logo_url?U("img",{src:e.logo_url,alt:"",style:{width:"48px",height:"48px",borderRadius:"12px",margin:"0 auto 10px",display:"block",objectFit:"contain"},onError:e=>{e.target.style.display="none"}}):U("div",{style:{width:"48px",height:"48px",borderRadius:"12px",backgroundColor:`${e.primary_color}15`,margin:"0 auto 10px",display:"flex",alignItems:"center",justifyContent:"center"},children:U(me,{color:e.primary_color,size:28})}),U("div",{style:{fontWeight:600,fontSize:"15px",marginBottom:"4px"},children:e.name}),U("p",{style:{opacity:.7,margin:0,lineHeight:1.5,fontSize:"13px"},children:e.welcome_message})]})}),f&&e.suggested_questions.length>0&&U(Te,{questions:e.suggested_questions,onClick:o,primaryColor:e.primary_color}),U(ke,{messages:t,config:e,onRate:l,lastAssistantId:null==h?void 0:h.id,feedbackThanks:null==d?void 0:d.feedbackThanks}),g.length>0&&!n&&U(Te,{questions:g,onClick:o,primaryColor:e.primary_color})]}),n&&U("div",{style:{padding:"6px 16px",display:"flex",alignItems:"center",gap:"8px",borderTop:"1px solid rgba(0,0,0,0.04)",flexShrink:0},children:[U("div",{style:{width:"20px",height:"20px",borderRadius:"6px",backgroundColor:`${e.primary_color}15`,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:U(me,{color:e.primary_color,size:12})}),U("span",{style:{fontSize:"12px",opacity:.5,display:"flex",alignItems:"center",gap:"3px"},children:[e.name," is typing",[0,1,2].map(t=>U("span",{style:{width:"3px",height:"3px",borderRadius:"50%",backgroundColor:e.text_color,opacity:.4,animation:`ciro-thinking-dot 1.4s ease-in-out ${.16*t}s infinite`}},t))]})]}),e.escalation_enabled&&t.length>4&&U("div",{style:{padding:"0 16px 4px",textAlign:"center"},children:U("button",{onClick:a,style:{background:"none",border:`1px solid ${e.primary_color}25`,color:e.primary_color,cursor:"pointer",fontSize:"12px",borderRadius:"16px",padding:"4px 14px",opacity:.7,minHeight:"28px",transition:"all 0.15s"},onMouseEnter:t=>{t.currentTarget.style.opacity="1",t.currentTarget.style.backgroundColor=`${e.primary_color}08`},onMouseLeave:e=>{e.currentTarget.style.opacity="0.7",e.currentTarget.style.backgroundColor="transparent"},children:(null==d?void 0:d.talkToHuman)||"Talk to a human"})}),U(Se,{onSend:r,isStreaming:n,primaryColor:e.primary_color,placeholder:(null==d?void 0:d.placeholder)||"Type your message..."}),U("a",{href:"https://ciroai.us",target:"_blank",rel:"noopener noreferrer",style:{textAlign:"center",padding:"3px 0 6px",fontSize:"10px",opacity:.3,display:"flex",alignItems:"center",justifyContent:"center",gap:"4px",textDecoration:"none",color:"inherit",transition:"opacity 0.15s"},onMouseEnter:e=>{e.currentTarget.style.opacity="0.6"},onMouseLeave:e=>{e.currentTarget.style.opacity="0.3"},children:[U(me,{color:"#5e6a98",size:12}),U("span",{style:{letterSpacing:"0.3px"},children:(null==d?void 0:d.poweredBy)||U(x,{children:["Powered by ",U("strong",{children:"CIRO"})]})})]})]})}function $e({config:e,onSubmit:t,primaryColor:n}){const[r,o]=ne(""),[i,l]=ne(""),[a,s]=ne(""),c={width:"100%",padding:"10px 14px",border:"1px solid rgba(0,0,0,0.15)",borderRadius:"8px",fontSize:"14px",fontFamily:"inherit",outline:"none",boxSizing:"border-box"};return U("div",{style:{padding:"24px 20px",textAlign:"center"},children:[U("p",{style:{margin:"0 0 16px",fontSize:"14px",lineHeight:1.5,opacity:.8},children:e.lead_capture_message||"Please introduce yourself to start chatting."}),U("form",{onSubmit:n=>{n.preventDefault(),s(""),!e.require_email||r.trim()?!e.require_email||/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(r)?!e.require_name||i.trim()?t({email:r.trim()||void 0,name:i.trim()||void 0}):s("Name is required"):s("Please enter a valid email"):s("Email is required")},style:{display:"flex",flexDirection:"column",gap:"10px"},children:[e.require_name&&U("input",{type:"text",placeholder:"Your name",value:i,maxLength:100,onInput:e=>l(e.target.value),style:c}),e.require_email&&U("input",{type:"email",placeholder:"Your email",value:r,maxLength:255,onInput:e=>o(e.target.value),style:c}),a&&U("p",{style:{color:"#ef4444",fontSize:"12px",margin:0},children:a}),U("button",{type:"submit",style:{padding:"10px 20px",backgroundColor:n,color:"white",border:"none",borderRadius:"8px",fontSize:"14px",fontWeight:600,cursor:"pointer",fontFamily:"inherit"},children:"Start chatting"})]})]})}function Ee({config:e}){var t,n,r,o,i,l,a,s;const[c,d]=ne(!1),[u,p]=ne(!1),[_,h]=ne({}),[g,f]=ne(!1),{widgetConfig:m,loading:y,error:b}=function(e){const[t,n]=ne(null),[r,o]=ne(!0),[i,l]=ne(null),a=oe(0);return re(()=>{const t=new he(e.apiUrl||window.location.origin,e.botId,e.apiKey);let r=!1;const i=()=>{t.init().then(e=>{r||(n(e),o(!1),l(null))}).catch(t=>{var n;r||(a.current++,a.current<=2?setTimeout(()=>{r||i()},3e3):(l(t.message||"Failed to load chatbot"),o(!1),null==(n=e.onError)||n.call(e,t)))})};return i(),()=>{r=!0}},[e.botId,e.apiKey,e.apiUrl]),{widgetConfig:t,loading:r,error:i}}(e),v=fe({...e,userEmail:e.userEmail||_.email,userName:e.userName||_.name},m);re(()=>(window.__ciroWidgetControl={open:()=>d(!0),close:()=>d(!1)},()=>{delete window.__ciroWidgetControl}),[]),re(()=>{var t,n;v.setIsOpen(c),c?null==(t=e.onOpen)||t.call(e):null==(n=e.onClose)||n.call(e)},[c]);const w=oe(v.messages.length);re(()=>{if(e.sound&&v.messages.length>w.current){const e=v.messages[v.messages.length-1];"assistant"===(null==e?void 0:e.role)&&!e.isStreaming&&e.content&&function(){try{const e=new(window.AudioContext||window.webkitAudioContext),t=e.createOscillator(),n=e.createGain();t.connect(n),n.connect(e.destination),t.type="sine",t.frequency.setValueAtTime(880,e.currentTime),t.frequency.setValueAtTime(1100,e.currentTime+.08),n.gain.setValueAtTime(.08,e.currentTime),n.gain.exponentialRampToValueAtTime(.001,e.currentTime+.25),t.start(e.currentTime),t.stop(e.currentTime+.25)}catch(e){}}()}w.current=v.messages.length},[v.messages,e.sound]);const k=le(()=>{d(e=>!e)},[]),C=le(e=>{v.sendMessage(e)},[v]),S=le(e=>{v.sendMessage(e)},[v]),T=le(t=>{var n;h(t),p(!0),null==(n=e.onLeadCapture)||n.call(e,t)},[e]);re(()=>{if(!e.triggers||c)return;const{delaySeconds:t,scrollPercent:n,pageViewCount:r,oncePerSession:o}=e.triggers,i=`ciro_triggered_${e.botId}`;if(!1!==o&&sessionStorage.getItem(i))return;const l=()=>{sessionStorage.setItem(i,"1"),f(!0)};let a,s;if(t&&t>0&&(a=setTimeout(l,1e3*t)),n&&n>0&&(s=()=>{window.scrollY/(document.documentElement.scrollHeight-window.innerHeight)*100>=n&&(l(),window.removeEventListener("scroll",s))},window.addEventListener("scroll",s,{passive:!0})),r&&r>0){const t=`ciro_views_${e.botId}`,n=parseInt(localStorage.getItem(t)||"0",10)+1;localStorage.setItem(t,String(n)),n>=r&&l()}return()=>{a&&clearTimeout(a),s&&window.removeEventListener("scroll",s)}},[e.triggers,e.botId]),re(()=>{const e=e=>{"Escape"===e.key&&c&&d(!1)};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[c]);const I=(null==(t=e.theme)?void 0:t.primaryColor)||(null==m?void 0:m.primary_color)||"#2563EB",$=e.position||(null==m?void 0:m.position)||"bottom-right",E=m?{...m,primary_color:(null==(n=e.theme)?void 0:n.primaryColor)||m.primary_color,background_color:(null==(r=e.theme)?void 0:r.backgroundColor)||m.background_color,text_color:(null==(o=e.theme)?void 0:o.textColor)||m.text_color,border_radius:null!=(l=null==(i=e.theme)?void 0:i.borderRadius)?l:m.border_radius,widget_width:(null==(a=e.theme)?void 0:a.widgetWidth)||m.widget_width,widget_height:(null==(s=e.theme)?void 0:s.widgetHeight)||m.widget_height}:null,H=le(()=>{f(!1),d(e=>!e)},[]);if(y||b||!m)return U(ye,{onClick:H,primaryColor:I,position:$,isOpen:c});const z=(E.require_email||E.require_name)&&!u&&!e.userEmail;return U(x,{children:[U(ye,{onClick:H,primaryColor:E.primary_color,position:$,isOpen:c,greeting:g?E.welcome_message:null,onDismissGreeting:()=>f(!1),unreadCount:v.unreadCount}),c&&(z?U(He,{config:E,position:$,onClose:k,onSubmit:T}):U(Ie,{config:E,messages:v.messages,isStreaming:"streaming"===v.state,onSend:C,onSuggestionClick:S,onClose:k,onRate:v.rateConversation,onEscalate:v.escalate,onNewChat:v.clearConversation,position:$,locale:e.locale}))]})}function He({config:e,position:t,onClose:n,onSubmit:r}){const o=ze();return U("div",{style:{position:"fixed",bottom:o?"0":"90px",...o?{left:0,right:0}:"bottom-left"===t?{left:"20px"}:{right:"20px"},width:o?"100%":`${e.widget_width}px`,backgroundColor:e.background_color,borderRadius:o?"0":`${e.border_radius}px`,boxShadow:"0 8px 30px rgba(0,0,0,0.12)",zIndex:2147483647,fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',border:"1px solid rgba(0,0,0,0.08)",overflow:"hidden"},children:[U("div",{style:{padding:"16px",backgroundColor:e.primary_color,color:"white",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[U("span",{style:{fontWeight:600},children:e.name}),U("button",{onClick:n,style:{background:"none",border:"none",color:"white",cursor:"pointer",display:"flex"},children:U("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:[U("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),U("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),U($e,{config:e,onSubmit:r,primaryColor:e.primary_color})]})}function ze(){const[e,t]=ne("undefined"!=typeof window&&window.innerWidth<640);return re(()=>{const e=()=>t(window.innerWidth<640);return window.addEventListener("resize",e),window.addEventListener("orientationchange",e),()=>{window.removeEventListener("resize",e),window.removeEventListener("orientationchange",e)}},[]),e}let Re=null,Me=null;const Le=()=>window.__ciroWidgetControl,We={init(e){if(Re)return void console.warn("[CiroChatbot] Already initialized. Call destroy() first.");if(!e.botId||!e.apiKey)return void console.error("[CiroChatbot] botId and apiKey are required.");if(!e.apiUrl){try{const t=document.querySelectorAll('script[src*="chatbot"]');if(t.length>0){const n=t[t.length-1].src;e.apiUrl=new URL(n).origin}}catch(r){}e.apiUrl||(e.apiUrl="https://api.ciroai.us")}Re=document.createElement("div"),Re.id="ciro-chatbot-widget",document.body.appendChild(Re);const t=Re.attachShadow({mode:"open"}),n=document.createElement("style");n.textContent="\n :host {\n all: initial;\n position: fixed;\n z-index: 2147483645;\n pointer-events: none;\n }\n :host > * { pointer-events: auto; }\n *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }\n button, textarea, input { font-family: inherit; }\n @keyframes ciro-blink {\n 0%, 50% { opacity: 1; }\n 51%, 100% { opacity: 0; }\n }\n @keyframes ciro-bubble-entrance {\n 0% { transform: scale(0); opacity: 0; }\n 100% { transform: scale(1); opacity: 1; }\n }\n @keyframes ciro-window-open {\n 0% { opacity: 0; transform: translateY(16px) scale(0.95); }\n 100% { opacity: 1; transform: translateY(0) scale(1); }\n }\n @keyframes ciro-glow-spin {\n from { transform: rotate(0deg); }\n to { transform: rotate(360deg); }\n }\n @keyframes ciro-thinking-dot {\n 0%, 80%, 100% { transform: scale(0.4); opacity: 0.3; }\n 40% { transform: scale(1); opacity: 1; }\n }\n ",t.appendChild(n),Me=document.createElement("div"),t.appendChild(Me);try{P(m(Ee,{config:e}),Me)}catch(o){console.error("[CiroChatbot] Failed to render:",o)}},open(){var e;null==(e=Le())||e.open()},close(){var e;null==(e=Le())||e.close()},destroy(){Me&&P(null,Me),Re&&Re.remove(),Re=null,Me=null,delete window.__ciroWidgetControl}};window.CiroChatbot=We;const De=document.currentScript;if(De){const e=De.getAttribute("data-ciro-bot-id"),t=De.getAttribute("data-ciro-api-key"),n=De.getAttribute("data-ciro-api-url");if(e&&t){const r=()=>We.init({botId:e,apiKey:t,apiUrl:n||void 0});"loading"===document.readyState?document.addEventListener("DOMContentLoaded",r):r()}}return We}();
|
package/package.json
CHANGED
package/src/types.ts
CHANGED
|
@@ -41,6 +41,9 @@ export interface CiroChatbotConfig {
|
|
|
41
41
|
sendButton?: string; // Default: "Send message"
|
|
42
42
|
feedbackThanks?: string; // Default: "Thanks for your feedback"
|
|
43
43
|
};
|
|
44
|
+
// Agent persona
|
|
45
|
+
agentName?: string; // Display name for the bot (e.g., "Sofia" instead of "Support Bot")
|
|
46
|
+
agentAvatar?: string; // URL to a human-looking avatar photo
|
|
44
47
|
// Sound
|
|
45
48
|
sound?: boolean; // Play notification sound on bot response (default: false)
|
|
46
49
|
// Callbacks
|