ciro-chatbot-widget 0.2.0 → 0.4.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 CHANGED
@@ -1 +1 @@
1
- var __CiroChatbot=function(){"use strict";var e,t,n,o,r,i,l,a,s,c,u,_={},d=[],p=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,h=Array.isArray;function f(e,t){for(var n in t)e[n]=t[n];return e}function g(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function m(t,n,o){var r,i,l,a={};for(l in n)"key"==l?r=n[l]:"ref"==l?i=n[l]:a[l]=n[l];if(arguments.length>2&&(a.children=arguments.length>3?e.call(arguments,2):o),"function"==typeof t&&null!=t.defaultProps)for(l in t.defaultProps)void 0===a[l]&&(a[l]=t.defaultProps[l]);return y(t,a,r,i,null)}function y(e,o,r,i,l){var a={type:e,props:o,key:r,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,o=n.__e,r=[],i=[],l=f({},n);l.__v=n.__v+1,t.vnode&&t.vnode(l),z(e.__P,l,n,e.__n,e.__P.namespaceURI,32&n.__u?[o]:null,r,null==o?v(n):o,!!(32&n.__u),i),l.__v=n.__v,l.__.__k[l.__i]=l,M(r,l,i),n.__e=n.__=null,l.__e!=o&&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)&&o.push(e)&&!S.__r++||r!=t.debounceRendering)&&((r=t.debounceRendering)||i)(S)}function S(){try{for(var e,t=1;o.length;)o.length>t&&o.sort(l),e=o.shift(),t=o.length,w(e)}finally{o.length=S.__r=0}}function T(e,t,n,o,r,i,l,a,s,c,u){var p,f,g,m,b,w,k,C=o&&o.__k||d,S=t.length;for(s=function(e,t,n,o,r){var i,l,a,s,c,u=n.length,_=u,d=0;for(e.__k=new Array(r),i=0;i<r;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+d,l.__=e,l.__b=e.__b+1,a=null,-1!=(c=l.__i=H(l,n,s,_))&&(_--,(a=n[c])&&(a.__u|=2)),null==a||null==a.__v?(-1==c&&(r>u?d--:r<u&&d++),"function"!=typeof l.type&&(l.__u|=4)):c!=s&&(c==s-1?d--:c==s+1?d++:(c>s?d--:d++,l.__u|=4))):e.__k[i]=null;if(_)for(i=0;i<u;i++)null!=(a=n[i])&&!(2&a.__u)&&(a.__e==o&&(o=v(a)),N(a,a));return o}(n,t,C,s,S),p=0;p<S;p++)null!=(g=n.__k[p])&&(f=-1!=g.__i&&C[g.__i]||_,g.__i=p,w=z(e,g,f,r,i,l,a,s,c,u),m=g.__e,g.ref&&f.ref!=g.ref&&(f.ref&&L(f.ref,null,g),u.push(g.ref,g.__c||m,g)),null==b&&null!=m&&(b=m),(k=!!(4&g.__u))||f.__k===g.__k?s=E(g,s,e,k):"function"==typeof g.type&&void 0!==w?s=w:m&&(s=m.nextSibling),g.__u&=-7);return n.__e=b,s}function E(e,t,n,o){var r,i;if("function"==typeof e.type){for(r=e.__k,i=0;r&&i<r.length;i++)r[i]&&(r[i].__=e,t=E(r[i],t,n,o));return t}e.__e!=t&&(o&&(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 H(e,t,n,o){var r,i,l,a=e.key,s=e.type,c=t[n],u=null!=c&&!(2&c.__u);if(null===c&&null==a||u&&a==c.key&&s==c.type)return n;if(o>(u?1:0))for(r=n-1,i=n+1;r>=0||i<t.length;)if(null!=(c=t[l=r>=0?r--:i++])&&!(2&c.__u)&&a==c.key&&s==c.type)return l;return-1}function I(e,t,n){"-"==t[0]?e.setProperty(t,null==n?"":n):e[t]=null==n?"":"number"!=typeof n||p.test(t)?n:n+"px"}function $(e,t,n,o,r){var i,l;e:if("style"==t)if("string"==typeof n)e.style.cssText=n;else{if("string"==typeof o&&(e.style.cssText=o=""),o)for(t in o)n&&t in n||I(e.style,t,"");if(n)for(t in n)o&&n[t]==o[t]||I(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?o?n.u=o.u:(n.u=s,e.addEventListener(t,i?u:c,i)):e.removeEventListener(t,i?u:c,i);else{if("http://www.w3.org/2000/svg"==r)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(_){}"function"==typeof n||(null==n||!1===n&&"-"!=t[4]?e.removeAttribute(t):e.setAttribute(t,"popover"==t&&1==n?"":n))}}function R(e){return function(n){if(this.l){var o=this.l[n.type+e];if(null==n.t)n.t=s++;else if(n.t<o.u)return;return o(t.event?t.event(n):n)}}}function z(n,o,r,i,l,a,s,c,u,p){var m,y,w,k,C,S,E,H,I,R,z,M,L,N,A,D=o.type;if(void 0!==o.constructor)return null;128&r.__u&&(u=!!(32&r.__u),a=[c=o.__e=r.__e]),(m=t.__b)&&m(o);e:if("function"==typeof D)try{if(H=o.props,I=D.prototype&&D.prototype.render,R=(m=D.contextType)&&i[m.__c],z=m?R?R.props.value:m.__:i,r.__c?E=(y=o.__c=r.__c).__=y.__E:(I?o.__c=y=new D(H,z):(o.__c=y=new b(H,z),y.constructor=D,y.render=W),R&&R.sub(y),y.state||(y.state={}),y.__n=i,w=y.__d=!0,y.__h=[],y._sb=[]),I&&null==y.__s&&(y.__s=y.state),I&&null!=D.getDerivedStateFromProps&&(y.__s==y.state&&(y.__s=f({},y.__s)),f(y.__s,D.getDerivedStateFromProps(H,y.__s))),k=y.props,C=y.state,y.__v=o,w)I&&null==D.getDerivedStateFromProps&&null!=y.componentWillMount&&y.componentWillMount(),I&&null!=y.componentDidMount&&y.__h.push(y.componentDidMount);else{if(I&&null==D.getDerivedStateFromProps&&H!==k&&null!=y.componentWillReceiveProps&&y.componentWillReceiveProps(H,z),o.__v==r.__v||!y.__e&&null!=y.shouldComponentUpdate&&!1===y.shouldComponentUpdate(H,y.__s,z)){o.__v!=r.__v&&(y.props=H,y.state=y.__s,y.__d=!1),o.__e=r.__e,o.__k=r.__k,o.__k.some(function(e){e&&(e.__=o)}),d.push.apply(y.__h,y._sb),y._sb=[],y.__h.length&&s.push(y);break e}null!=y.componentWillUpdate&&y.componentWillUpdate(H,y.__s,z),I&&null!=y.componentDidUpdate&&y.__h.push(function(){y.componentDidUpdate(k,C,S)})}if(y.context=z,y.props=H,y.__P=n,y.__e=!1,M=t.__r,L=0,I)y.state=y.__s,y.__d=!1,M&&M(o),m=y.render(y.props,y.state,y.context),d.push.apply(y.__h,y._sb),y._sb=[];else do{y.__d=!1,M&&M(o),m=y.render(y.props,y.state,y.context),y.state=y.__s}while(y.__d&&++L<25);y.state=y.__s,null!=y.getChildContext&&(i=f(f({},i),y.getChildContext())),I&&!w&&null!=y.getSnapshotBeforeUpdate&&(S=y.getSnapshotBeforeUpdate(k,C)),N=null!=m&&m.type===x&&null==m.key?U(m.props.children):m,c=T(n,h(N)?N:[N],o,r,i,l,a,s,c,u,p),y.base=o.__e,o.__u&=-161,y.__h.length&&s.push(y),E&&(y.__E=y.__=null)}catch(F){if(o.__v=null,u||null!=a)if(F.then){for(o.__u|=u?160:128;c&&8==c.nodeType&&c.nextSibling;)c=c.nextSibling;a[a.indexOf(c)]=null,o.__e=c}else{for(A=a.length;A--;)g(a[A]);P(o)}else o.__e=r.__e,o.__k=r.__k,F.then||P(o);t.__e(F,o,r)}else null==a&&o.__v==r.__v?(o.__k=r.__k,o.__e=r.__e):c=o.__e=function(n,o,r,i,l,a,s,c,u){var d,p,f,m,y,x,b,w=r.props||_,k=o.props,C=o.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(d=0;d<a.length;d++)if((y=a[d])&&"setAttribute"in y==!!C&&(C?y.localName==C:3==y.nodeType)){n=y,a[d]=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(o,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={},d=0;d<n.attributes.length;d++)w[(y=n.attributes[d]).name]=y.value;for(d in w)y=w[d],"dangerouslySetInnerHTML"==d?f=y:"children"==d||d in k||"value"==d&&"defaultValue"in k||"checked"==d&&"defaultChecked"in k||$(n,d,null,y,l);for(d in k)y=k[d],"children"==d?m=y:"dangerouslySetInnerHTML"==d?p=y:"value"==d?x=y:"checked"==d?b=y:c&&"function"!=typeof y||w[d]===y||$(n,d,y,w[d],l);if(p)c||f&&(p.__html==f.__html||p.__html==n.innerHTML)||(n.innerHTML=p.__html),o.__k=[];else if(f&&(n.innerHTML=""),T("template"==o.type?n.content:n,h(m)?m:[m],o,r,i,"foreignObject"==C?"http://www.w3.org/1999/xhtml":l,a,s,a?a[0]:r.__k&&v(r,0),c,u),null!=a)for(d=a.length;d--;)g(a[d]);c||(d="value","progress"==C&&null==x?n.removeAttribute("value"):null!=x&&(x!==n[d]||"progress"==C&&!x||"option"==C&&x!=w[d])&&$(n,d,x,w[d],l),d="checked",null!=b&&b!=n[d]&&$(n,d,b,w[d],l))}return n}(r.__e,o,r,i,l,a,s,u,p);return(m=t.diffed)&&m(o),128&o.__u?void 0:c}function P(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some(P))}function M(e,n,o){for(var r=0;r<o.length;r++)L(o[r],o[++r],o[++r]);t.__c&&t.__c(n,e),e.some(function(n){try{e=n.__h,n.__h=[],e.some(function(e){e.call(n)})}catch(o){t.__e(o,n.__v)}})}function U(e){return"object"!=typeof e||null==e||e.__b>0?e:h(e)?e.map(U):f({},e)}function L(e,n,o){try{if("function"==typeof e){var r="function"==typeof e.__u;r&&e.__u(),r&&null==n||(e.__u=e(n))}else e.current=n}catch(i){t.__e(i,o)}}function N(e,n,o){var r,i;if(t.unmount&&t.unmount(e),(r=e.ref)&&(r.current&&r.current!=e.__e||L(r,null,n)),null!=(r=e.__c)){if(r.componentWillUnmount)try{r.componentWillUnmount()}catch(l){t.__e(l,n)}r.base=r.__P=null}if(r=e.__k)for(i=0;i<r.length;i++)r[i]&&N(r[i],n,o||"function"!=typeof e.type);o||g(e.__e),e.__c=e.__=e.__e=void 0}function W(e,t,n){return this.constructor(e,n)}function A(n,o,r){var i,l,a;o==document&&(o=document.documentElement),t.__&&t.__(n,o),i=!1?null:o.__k,l=[],a=[],z(o,n=o.__k=m(x,null,[n]),i||_,_,o.namespaceURI,i?null:o.firstChild?e.call(o.childNodes):null,l,i?i.__e:o.firstChild,false,a),M(l,n,a)}e=d.slice,t={__e:function(e,t,n,o){for(var r,i,l;t=t.__;)if((r=t.__c)&&!r.__)try{if((i=r.constructor)&&null!=i.getDerivedStateFromError&&(r.setState(i.getDerivedStateFromError(e)),l=r.__d),null!=r.componentDidCatch&&(r.componentDidCatch(e,o||{}),l=r.__d),l)return r.__E=r}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=f({},this.state),"function"==typeof e&&(e=e(f({},n),this.props)),e&&f(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,o=[],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=R(!1),u=R(!0);var D=0;function F(e,n,o,r,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 u={type:e,props:c,key:o,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--D,__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(u),u}var q,O,j,B,K=0,Y=[],J=t,G=J.__b,V=J.__r,X=J.diffed,Q=J.__c,Z=J.unmount,ee=J.__;function te(e,t){J.__h&&J.__h(O,e,K||t),K=0;var n=O.__H||(O.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function ne(e){return K=1,function(e,t){var n=te(q++,2);if(n.t=e,!n.__c&&(n.__=[pe(void 0,t),function(e){var t=n.__N?n.__N[0]:n.__[0],o=n.t(t,e);t!==o&&(n.__N=[o,n.__[1]],n.__c.setState({}))}],n.__c=O,!O.__f)){var o=function(e,t,o){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!r||r.call(this,e,t,o);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)}}),r&&r.call(this,e,t,o)||l};O.__f=!0;var r=O.shouldComponentUpdate,i=O.componentWillUpdate;O.componentWillUpdate=function(e,t,n){if(this.__e){var l=r;r=void 0,o(e,t,n),r=l}i&&i.call(this,e,t,n)},O.shouldComponentUpdate=o}return n.__N||n.__}(pe,e)}function oe(e,t){var n=te(q++,3);!J.__s&&de(n.__H,t)&&(n.__=e,n.u=t,O.__H.__h.push(n))}function re(e){return K=5,ie(function(){return{current:e}},[])}function ie(e,t){var n=te(q++,7);return de(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=Y.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(ue),t.__h.some(_e),t.__h=[]}catch(n){t.__h=[],J.__e(n,e.__v)}}}J.__b=function(e){O=null,G&&G(e)},J.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),ee&&ee(e,t)},J.__r=function(e){V&&V(e),q=0;var t=(O=e.__c).__H;t&&(j===O?(t.__h=[],O.__h=[],t.__.some(function(e){e.__N&&(e.__=e.__N),e.u=e.__N=void 0})):(t.__h.some(ue),t.__h.some(_e),t.__h=[],q=0)),j=O},J.diffed=function(e){X&&X(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(1!==Y.push(t)&&B===J.requestAnimationFrame||((B=J.requestAnimationFrame)||ce)(ae)),t.__H.__.some(function(e){e.u&&(e.__H=e.u),e.u=void 0})),j=O=null},J.__c=function(e,t){t.some(function(e){try{e.__h.some(ue),e.__h=e.__h.filter(function(e){return!e.__||_e(e)})}catch(n){t.some(function(e){e.__h&&(e.__h=[])}),t=[],J.__e(n,e.__v)}}),Q&&Q(e,t)},J.unmount=function(e){Z&&Z(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(e){try{ue(e)}catch(n){t=n}}),n.__H=void 0,t&&J.__e(t,n.__v))};var se="function"==typeof requestAnimationFrame;function ce(e){var t,n=function(){clearTimeout(o),se&&cancelAnimationFrame(t),setTimeout(e)},o=setTimeout(n,35);se&&(t=requestAnimationFrame(n))}function ue(e){var t=O,n=e.__c;"function"==typeof n&&(e.__c=void 0,n()),O=t}function _e(e){var t=O;e.__c=e.__(),O=t}function de(e,t){return!e||e.length!==t.length||t.some(function(t,n){return t!==e[n]})}function pe(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 o=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:o.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(r){}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 o;for(s+=a.decode(t,{stream:!0});-1!==(o=s.indexOf("\n\n"));){const e=s.slice(0,o);s=s.slice(o+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(r){}}}n.onEnd()}catch(i){if("AbortError"===i.name)return;n.onError(i.message||"Connection failed")}})(),o}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()})}}function fe({onClick:e,primaryColor:t,position:n,isOpen:o,greeting:r,onDismissGreeting:i}){const l="bottom-left"===n?{left:"20px",right:"auto"}:{right:"20px",left:"auto"};return F(x,{children:[r&&!o&&F("div",{style:{position:"fixed",bottom:"88px",...l,maxWidth:"260px",padding:"10px 14px",backgroundColor:"white",borderRadius:"12px",boxShadow:"0 4px 20px rgba(0,0,0,0.12)",fontSize:"13px",lineHeight:1.4,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:[r,F("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"})]}),F("button",{onClick:e,"aria-label":o?"Close chat":"Open chat",style:{position:"fixed",bottom:"20px",...l,width:"60px",height:"60px",borderRadius:"50%",backgroundColor:t,border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:`0 4px 14px ${t}40, 0 2px 6px rgba(0,0,0,0.1)`,transition:"transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease",zIndex:2147483646,WebkitTapHighlightColor:"transparent",animation:"ciro-bubble-entrance 0.4s cubic-bezier(0.34, 1.56, 0.64, 1)"},onMouseEnter:e=>{const t=e.currentTarget;t.style.transform="scale(1.08)",t.style.boxShadow="0 6px 20px rgba(0,0,0,0.2)"},onMouseLeave:e=>{const t=e.currentTarget;t.style.transform="scale(1)",t.style.boxShadow="0 4px 12px rgba(0,0,0,0.15)"},children:F("svg",o?{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"white","stroke-width":"2","stroke-linecap":"round",children:[F("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),F("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}:{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"white","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:F("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})})]})}function ge({messages:e,config:t,onRate:n,lastAssistantId:o,feedbackThanks:r}){const[i,l]=ne(null),a=(e,t)=>{l(e),n(t)};return F(x,{children:e.map(e=>{if("system"===e.role)return F("div",{style:{textAlign:"center",fontSize:"12px",opacity:.6,padding:"8px 0"},children:e.content},e.id);const n="user"===e.role,l=e.id===o&&!e.isStreaming&&e.content,s=i===e.id;return F("div",{style:{display:"flex",flexDirection:"column",alignItems:n?"flex-end":"flex-start",maxWidth:"85%",alignSelf:n?"flex-end":"flex-start"},children:[F("div",{style:{padding:"10px 14px",borderRadius:n?`${t.border_radius}px ${t.border_radius}px 4px ${t.border_radius}px`:`${t.border_radius}px ${t.border_radius}px ${t.border_radius}px 4px`,backgroundColor:n?t.primary_color:`${t.primary_color}0A`,color:n?"white":t.text_color,lineHeight:1.5,wordBreak:"break-word",whiteSpace:"pre-wrap",fontSize:"14px"},children:[e.content||(e.isStreaming,""),e.isStreaming&&!e.content&&F("span",{style:{display:"inline-flex",gap:"3px",padding:"2px 0"},children:[0,1,2].map(e=>F("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))}),e.isStreaming&&e.content&&F("span",{style:{display:"inline-block",animation:"ciro-blink 1s infinite",marginLeft:"1px"},children:"|"})]}),!n&&e.sources&&e.sources.length>0&&t.include_citations&&F("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginTop:"6px"},children:e.sources.map((e,n)=>F("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"10px",backgroundColor:`${t.primary_color}15`,color:t.primary_color,border:`1px solid ${t.primary_color}30`},children:e.name},n))}),l&&F("div",{style:{display:"flex",gap:"6px",marginTop:"6px"},children:s?F("span",{style:{fontSize:"12px",opacity:.5},children:r||"Thanks for your feedback"}):F(x,{children:[F("button",{onClick:()=>a(e.id,"positive"),"aria-label":"Helpful",style:{background:"none",border:"1px solid rgba(0,0,0,0.1)",borderRadius:"6px",cursor:"pointer",fontSize:"13px",opacity:.5,padding:"2px 8px",minHeight:"28px",transition:"opacity 0.15s"},onMouseEnter:e=>{e.currentTarget.style.opacity="1"},onMouseLeave:e=>{e.currentTarget.style.opacity="0.5"},children:"👍"}),F("button",{onClick:()=>a(e.id,"negative"),"aria-label":"Not helpful",style:{background:"none",border:"1px solid rgba(0,0,0,0.1)",borderRadius:"6px",cursor:"pointer",fontSize:"13px",opacity:.5,padding:"2px 8px",minHeight:"28px",transition:"opacity 0.15s"},onMouseEnter:e=>{e.currentTarget.style.opacity="1"},onMouseLeave:e=>{e.currentTarget.style.opacity="0.5"},children:"👎"})]})})]},e.id)})})}const me=5e3;function ye({onSend:e,isStreaming:t,primaryColor:n,placeholder:o}){const[r,i]=ne(""),l=re(null),a=le(()=>{const n=r.trim();n&&!t&&(n.length>me||(e(n),i(""),l.current&&(l.current.style.height="auto"),setTimeout(()=>{var e;return null==(e=l.current)?void 0:e.focus()},50)))},[r,t,e]),s=le(e=>{const t=e.target,n=t.value.slice(0,me);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]),u=r.trim().length>0&&!t;return F("div",{style:{padding:"10px 12px",borderTop:"1px solid rgba(0,0,0,0.08)",display:"flex",alignItems:"flex-end",gap:"8px",flexShrink:0},children:[F("textarea",{ref:l,value:r,onInput:s,onKeyDown:c,placeholder:o,disabled:t,rows:1,maxLength:me,"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)"}}),F("button",{onClick:a,disabled:!u,"aria-label":"Send message",style:{width:"40px",height:"40px",borderRadius:"50%",backgroundColor:u?n:"#e5e7eb",border:"none",cursor:u?"pointer":"default",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,transition:"background-color 0.15s",minHeight:"44px",minWidth:"44px"},children:F("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"white","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[F("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),F("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})})]})}function xe({questions:e,onClick:t,primaryColor:n}){return e.length?F("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},role:"list","aria-label":"Suggested questions",children:e.map((e,o)=>F("button",{role:"listitem",onClick:()=>t(e),style:{padding:"10px 14px",border:`1px solid ${n}30`,borderRadius:"12px",backgroundColor:`${n}08`,color:n,cursor:"pointer",textAlign:"left",fontSize:"13px",lineHeight:1.4,fontFamily:"inherit",transition:"background-color 0.15s, border-color 0.15s",minHeight:"44px",display:"flex",alignItems:"center"},onMouseEnter:e=>{const t=e.currentTarget;t.style.backgroundColor=`${n}15`,t.style.borderColor=`${n}50`},onMouseLeave:e=>{const t=e.currentTarget;t.style.backgroundColor=`${n}08`,t.style.borderColor=`${n}30`},children:e},o))}):null}function be({config:e,messages:t,isStreaming:n,onSend:o,onSuggestionClick:r,onClose:i,onRate:l,onEscalate:a,position:s,locale:c}){const u=re(null),_=re(0),d=Ce();oe(()=>{if(t.length>_.current){const e=u.current;e&&requestAnimationFrame(()=>{e.scrollTop=e.scrollHeight})}_.current=t.length},[t.length]),oe(()=>{if(!n)return;const e=u.current;if(!e)return;e.scrollHeight-e.scrollTop-e.clientHeight<100&&(e.scrollTop=e.scrollHeight)},[t,n]);const p=[...t].reverse().find(e=>"assistant"===e.role&&!e.isStreaming),h=null==p?void 0:p.id,f=(null==p?void 0:p.suggestions)||[],g=0===t.length&&e.suggested_questions.length>0,m="bottom-left"===s?{left:"20px",right:"auto"}:{right:"20px",left:"auto"};return F("div",{role:"dialog","aria-label":`Chat with ${e.name}`,style:{position:"fixed",bottom:d?"0":"90px",...d?{left:0,right:0}:m,width:d?"100%":`${e.widget_width}px`,height:d?"100%":`${e.widget_height}px`,maxHeight:d?"100vh":"calc(100vh - 110px)",backgroundColor:e.background_color,borderRadius:d?"0":`${e.border_radius}px`,boxShadow:"0 8px 30px rgba(0,0,0,0.12)",display:"flex",flexDirection:"column",overflow:"hidden",zIndex:2147483647,fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',fontSize:"14px",color:e.text_color,border:d?"none":"1px solid rgba(0,0,0,0.08)",animation:"ciro-window-open 0.25s cubic-bezier(0.16, 1, 0.3, 1)"},children:[F("div",{style:{padding:"14px 16px",backgroundColor:e.primary_color,color:"white",display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[F("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[e.avatar_url&&F("img",{src:e.avatar_url,alt:"",style:{width:"32px",height:"32px",borderRadius:"50%",objectFit:"cover"},onError:e=>{e.target.style.display="none"}}),F("div",{children:[F("div",{style:{fontWeight:600,fontSize:"15px"},children:e.name}),F("div",{style:{fontSize:"12px",opacity:.85,display:"flex",alignItems:"center",gap:"4px"},children:n?F("span",{style:{display:"inline-flex",gap:"2px",alignItems:"center"},children:[F("span",{children:(null==c?void 0:c.typing)||"Typing"}),[0,1,2].map(e=>F("span",{style:{width:"3px",height:"3px",borderRadius:"50%",backgroundColor:"white",animation:`ciro-thinking-dot 1.4s ease-in-out ${.16*e}s infinite`}},e))]}):F(x,{children:[F("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"]})})]})]}),F("button",{onClick:i,"aria-label":"Close chat",style:{background:"none",border:"none",color:"white",cursor:"pointer",padding:"6px",display:"flex",borderRadius:"4px",minHeight:"44px",minWidth:"44px",alignItems:"center",justifyContent:"center"},children:F("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:[F("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),F("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),F("div",{ref:u,style:{flex:1,overflowY:"auto",padding:"16px",display:"flex",flexDirection:"column",gap:"12px",WebkitOverflowScrolling:"touch"},children:[0===t.length&&F("div",{style:{textAlign:"center",padding:"20px 0"},children:[e.logo_url&&F("img",{src:e.logo_url,alt:"",style:{width:"48px",height:"48px",borderRadius:"12px",margin:"0 auto 12px",display:"block",objectFit:"contain"},onError:e=>{e.target.style.display="none"}}),F("p",{style:{color:e.text_color,opacity:.8,margin:0,lineHeight:1.5},children:e.welcome_message})]}),g&&F(xe,{questions:e.suggested_questions,onClick:r,primaryColor:e.primary_color}),F(ge,{messages:t,config:e,onRate:l,lastAssistantId:h,feedbackThanks:null==c?void 0:c.feedbackThanks}),f.length>0&&!n&&F(xe,{questions:f,onClick:r,primaryColor:e.primary_color})]}),e.escalation_enabled&&t.length>4&&F("div",{style:{padding:"0 16px 6px",textAlign:"center"},children:F("button",{onClick:a,style:{background:"none",border:"none",color:e.primary_color,cursor:"pointer",fontSize:"12px",textDecoration:"underline",opacity:.7,minHeight:"32px"},children:(null==c?void 0:c.talkToHuman)||"Talk to a human"})}),F(ye,{onSend:o,isStreaming:n,primaryColor:e.primary_color,placeholder:(null==c?void 0:c.placeholder)||"Type your message..."}),F("div",{style:{textAlign:"center",padding:"4px 0 6px",fontSize:"10px",opacity:.3,letterSpacing:"0.5px",textTransform:"uppercase"},children:(null==c?void 0:c.poweredBy)||F(x,{children:["Powered by ",F("span",{style:{fontWeight:600},children:"CIRO"})]})})]})}function ve({config:e,onSubmit:t,primaryColor:n}){const[o,r]=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 F("div",{style:{padding:"24px 20px",textAlign:"center"},children:[F("p",{style:{margin:"0 0 16px",fontSize:"14px",lineHeight:1.5,opacity:.8},children:e.lead_capture_message||"Please introduce yourself to start chatting."}),F("form",{onSubmit:n=>{n.preventDefault(),s(""),!e.require_email||o.trim()?!e.require_email||/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(o)?!e.require_name||i.trim()?t({email:o.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&&F("input",{type:"text",placeholder:"Your name",value:i,maxLength:100,onInput:e=>l(e.target.value),style:c}),e.require_email&&F("input",{type:"email",placeholder:"Your email",value:o,maxLength:255,onInput:e=>r(e.target.value),style:c}),a&&F("p",{style:{color:"#ef4444",fontSize:"12px",margin:0},children:a}),F("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 we({config:e}){const[t,n]=ne(!1),[o,r]=ne(!1),[i,l]=ne({}),[a,s]=ne(!1),{widgetConfig:c,loading:u,error:_}=function(e){const[t,n]=ne(null),[o,r]=ne(!0),[i,l]=ne(null),a=re(0);return oe(()=>{const t=new he(e.apiUrl||window.location.origin,e.botId,e.apiKey);let o=!1;const i=()=>{t.init().then(e=>{o||(n(e),r(!1),l(null))}).catch(t=>{var n;o||(a.current++,a.current<=2?setTimeout(()=>{o||i()},3e3):(l(t.message||"Failed to load chatbot"),r(!1),null==(n=e.onError)||n.call(e,t)))})};return i(),()=>{o=!0}},[e.botId,e.apiKey,e.apiUrl]),{widgetConfig:t,loading:o,error:i}}(e),d=function(e,t){const[n,o]=ne([]),[r,i]=ne("idle"),[l,a]=ne(null),[s,c]=ne(null),u=re(null),_=re(null),d=re(0),p=re(null),h=re("");u.current||(u.current=new he(e.apiUrl||window.location.origin,e.botId,e.apiKey));const f=u.current;oe(()=>()=>{var e;null==(e=_.current)||e.abort()},[]);const g=le(async()=>{if(l)return l;if(p.current)return p.current;const t=f.createConversation({external_user_id:e.externalUserId,user_email:e.userEmail,user_name:e.userName}).then(e=>(a(e.conversation_id),p.current=null,e.conversation_id)).catch(e=>{throw p.current=null,e});return p.current=t,t},[l,e,f]),m=le(async t=>{var n,l;if(!t.trim()||"streaming"===r)return;c(null),h.current="";const a="user_"+ ++d.current;o(e=>[...e,{id:a,role:"user",content:t.trim()}]),null==(n=e.onMessage)||n.call(e,{role:"user",content:t.trim()});const s="assistant_"+ ++d.current;o(e=>[...e,{id:s,role:"assistant",content:"",sources:[],suggestions:[],isStreaming:!0}]),i("streaming");try{const n=await g();_.current=f.streamMessage(n,t.trim(),{onTextDelta:e=>{h.current+=e,o(t=>t.map(t=>t.id===s?{...t,content:t.content+e}:t))},onSource:e=>{o(t=>t.map(t=>t.id===s?{...t,sources:[...t.sources||[],{name:e.label,type:e.detail}]}:t))},onSuggestions:e=>{o(t=>t.map(t=>t.id===s?{...t,suggestions:e}:t))},onConfidence:e=>{o(t=>t.map(t=>t.id===s?{...t,confidence:e.overall}:t))},onEnd:()=>{var t;o(e=>e.map(e=>e.id===s?{...e,isStreaming:!1}:e)),i("idle"),h.current&&(null==(t=e.onMessage)||t.call(e,{role:"assistant",content:h.current}))},onError:t=>{var n;o(e=>e.map(e=>e.id===s?{...e,content:t||"Something went wrong.",isStreaming:!1}:e)),i("error"),c(t),null==(n=e.onError)||n.call(e,new Error(t))}})}catch(u){o(e=>e.map(e=>e.id===s?{...e,content:"Failed to connect. Please try again.",isStreaming:!1}:e)),i("error"),c(u.message),null==(l=e.onError)||l.call(e,u)}},[r,e,f,g]),y=le(()=>{var e;null==(e=_.current)||e.abort(),_.current=null,o(e=>e.map(e=>e.isStreaming?{...e,isStreaming:!1}:e)),i("idle")},[]),x=le(async e=>{if(l)try{await f.rateConversation(l,e)}catch(t){}},[l,f]),b=le(async()=>{if(l)try{await f.escalateConversation(l),o(e=>[...e,{id:"system_"+ ++d.current,role:"system",content:(null==t?void 0:t.escalation_message)||"Connecting you with a human agent..."}])}catch(e){}},[l,f,t]);return{messages:n,state:r,error:s,conversationId:l,sendMessage:m,cancelStream:y,rateConversation:x,escalate:b}}({...e,userEmail:e.userEmail||i.email,userName:e.userName||i.name},c);oe(()=>(window.__ciroWidgetControl={open:()=>n(!0),close:()=>n(!1)},()=>{delete window.__ciroWidgetControl}),[]),oe(()=>{var n,o;t?null==(n=e.onOpen)||n.call(e):null==(o=e.onClose)||o.call(e)},[t]);const p=le(()=>{n(e=>!e)},[]),h=le(e=>{d.sendMessage(e)},[d]),f=le(e=>{d.sendMessage(e)},[d]),g=le(t=>{var n;l(t),r(!0),null==(n=e.onLeadCapture)||n.call(e,t)},[e]);oe(()=>{if(!e.triggers||t)return;const{delaySeconds:n,scrollPercent:o,pageViewCount:r,oncePerSession:i}=e.triggers,l=`ciro_triggered_${e.botId}`;if(!1!==i&&sessionStorage.getItem(l))return;const a=()=>{sessionStorage.setItem(l,"1"),s(!0)};let c,u;if(n&&n>0&&(c=setTimeout(a,1e3*n)),o&&o>0&&(u=()=>{window.scrollY/(document.documentElement.scrollHeight-window.innerHeight)*100>=o&&(a(),window.removeEventListener("scroll",u))},window.addEventListener("scroll",u,{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&&a()}return()=>{c&&clearTimeout(c),u&&window.removeEventListener("scroll",u)}},[e.triggers,e.botId]),oe(()=>{const e=e=>{"Escape"===e.key&&t&&n(!1)};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t]);const m=(null==c?void 0:c.primary_color)||"#2563EB",y=e.position||(null==c?void 0:c.position)||"bottom-right",b=le(()=>{s(!1),n(e=>!e)},[]);if(u||_||!c)return F(fe,{onClick:b,primaryColor:m,position:y,isOpen:t});const v=(c.require_email||c.require_name)&&!o&&!e.userEmail;return F(x,{children:[F(fe,{onClick:b,primaryColor:c.primary_color,position:y,isOpen:t,greeting:a?c.welcome_message:null,onDismissGreeting:()=>s(!1)}),t&&(v?F(ke,{config:c,position:y,onClose:p,onSubmit:g}):F(be,{config:c,messages:d.messages,isStreaming:"streaming"===d.state,onSend:h,onSuggestionClick:f,onClose:p,onRate:d.rateConversation,onEscalate:d.escalate,position:y,locale:e.locale}))]})}function ke({config:e,position:t,onClose:n,onSubmit:o}){const r=Ce();return F("div",{style:{position:"fixed",bottom:r?"0":"90px",...r?{left:0,right:0}:"bottom-left"===t?{left:"20px"}:{right:"20px"},width:r?"100%":`${e.widget_width}px`,backgroundColor:e.background_color,borderRadius:r?"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:[F("div",{style:{padding:"16px",backgroundColor:e.primary_color,color:"white",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[F("span",{style:{fontWeight:600},children:e.name}),F("button",{onClick:n,style:{background:"none",border:"none",color:"white",cursor:"pointer",display:"flex"},children:F("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:[F("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),F("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),F(ve,{config:e,onSubmit:o,primaryColor:e.primary_color})]})}function Ce(){const[e,t]=ne("undefined"!=typeof window&&window.innerWidth<640);return oe(()=>{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 Se=null,Te=null;const Ee=()=>window.__ciroWidgetControl,He={init(e){if(Se)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(o){}e.apiUrl||(e.apiUrl="https://api.ciroai.us")}Se=document.createElement("div"),Se.id="ciro-chatbot-widget",document.body.appendChild(Se);const t=Se.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-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),Te=document.createElement("div"),t.appendChild(Te);try{A(m(we,{config:e}),Te)}catch(r){console.error("[CiroChatbot] Failed to render:",r)}},open(){var e;null==(e=Ee())||e.open()},close(){var e;null==(e=Ee())||e.close()},destroy(){Te&&A(null,Te),Se&&Se.remove(),Se=null,Te=null,delete window.__ciroWidgetControl}};window.CiroChatbot=He;const Ie=document.currentScript;if(Ie){const e=Ie.getAttribute("data-ciro-bot-id"),t=Ie.getAttribute("data-ciro-api-key"),n=Ie.getAttribute("data-ciro-api-url");if(e&&t){const o=()=>He.init({botId:e,apiKey:t,apiUrl:n||void 0});"loading"===document.readyState?document.addEventListener("DOMContentLoaded",o):o()}}return He}();
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),z(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,D(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 p,g,f,m,b,w,k,C=r&&r.__k||_,S=t.length;for(s=function(e,t,n,r,o){var i,l,a,s,c,d=n.length,u=d,_=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+_,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?_--:o<d&&_++),"function"!=typeof l.type&&(l.__u|=4)):c!=s&&(c==s-1?_--:c==s+1?_++:(c>s?_--:_++,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),p=0;p<S;p++)null!=(f=n.__k[p])&&(g=-1!=f.__i&&C[f.__i]||u,f.__i=p,w=z(e,f,g,o,i,l,a,s,c,d),m=f.__e,f.ref&&g.ref!=f.ref&&(g.ref&&A(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||p.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 R(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 z(n,r,o,i,l,a,s,c,d,p){var m,y,w,k,C,S,I,$,E,R,z,D,A,L,N,U=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 U)try{if($=r.props,E=U.prototype&&U.prototype.render,R=(m=U.contextType)&&i[m.__c],z=m?R?R.props.value:m.__:i,o.__c?I=(y=r.__c=o.__c).__=y.__E:(E?r.__c=y=new U($,z):(r.__c=y=new b($,z),y.constructor=U,y.render=P),R&&R.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!=U.getDerivedStateFromProps&&(y.__s==y.state&&(y.__s=g({},y.__s)),g(y.__s,U.getDerivedStateFromProps($,y.__s))),k=y.props,C=y.state,y.__v=r,w)E&&null==U.getDerivedStateFromProps&&null!=y.componentWillMount&&y.componentWillMount(),E&&null!=y.componentDidMount&&y.__h.push(y.componentDidMount);else{if(E&&null==U.getDerivedStateFromProps&&$!==k&&null!=y.componentWillReceiveProps&&y.componentWillReceiveProps($,z),r.__v==o.__v||!y.__e&&null!=y.shouldComponentUpdate&&!1===y.shouldComponentUpdate($,y.__s,z)){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)}),_.push.apply(y.__h,y._sb),y._sb=[],y.__h.length&&s.push(y);break e}null!=y.componentWillUpdate&&y.componentWillUpdate($,y.__s,z),E&&null!=y.componentDidUpdate&&y.__h.push(function(){y.componentDidUpdate(k,C,S)})}if(y.context=z,y.props=$,y.__P=n,y.__e=!1,D=t.__r,A=0,E)y.state=y.__s,y.__d=!1,D&&D(r),m=y.render(y.props,y.state,y.context),_.push.apply(y.__h,y._sb),y._sb=[];else do{y.__d=!1,D&&D(r),m=y.render(y.props,y.state,y.context),y.state=y.__s}while(y.__d&&++A<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?W(m.props.children):m,c=T(n,h(L)?L:[L],r,o,i,l,a,s,c,d,p),y.base=r.__e,r.__u&=-161,y.__h.length&&s.push(y),I&&(y.__E=y.__=null)}catch(F){if(r.__v=null,d||null!=a)if(F.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,F.then||M(r);t.__e(F,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(_=0;_<a.length;_++)if((y=a[_])&&"setAttribute"in y==!!C&&(C?y.localName==C:3==y.nodeType)){n=y,a[_]=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={},_=0;_<n.attributes.length;_++)w[(y=n.attributes[_]).name]=y.value;for(_ in w)y=w[_],"dangerouslySetInnerHTML"==_?g=y:"children"==_||_ in k||"value"==_&&"defaultValue"in k||"checked"==_&&"defaultChecked"in k||H(n,_,null,y,l);for(_ in k)y=k[_],"children"==_?m=y:"dangerouslySetInnerHTML"==_?p=y:"value"==_?x=y:"checked"==_?b=y:c&&"function"!=typeof y||w[_]===y||H(n,_,y,w[_],l);if(p)c||g&&(p.__html==g.__html||p.__html==n.innerHTML)||(n.innerHTML=p.__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(_=a.length;_--;)f(a[_]);c||(_="value","progress"==C&&null==x?n.removeAttribute("value"):null!=x&&(x!==n[_]||"progress"==C&&!x||"option"==C&&x!=w[_])&&H(n,_,x,w[_],l),_="checked",null!=b&&b!=n[_]&&H(n,_,b,w[_],l))}return n}(o.__e,r,o,i,l,a,s,d,p);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 D(e,n,r){for(var o=0;o<r.length;o++)A(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 A(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||A(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=[],z(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),D(l,n,a)}e=_.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=R(!1),d=R(!0);var U=0;function F(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:--U,__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 O,j,q,B,K=0,V=[],J=t,Y=J.__b,G=J.__r,X=J.diffed,Q=J.__c,Z=J.unmount,ee=J.__;function te(e,t){J.__h&&J.__h(j,e,K||t),K=0;var n=j.__H||(j.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function ne(e){return K=1,function(e,t){var n=te(O++,2);if(n.t=e,!n.__c&&(n.__=[pe(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=j,!j.__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};j.__f=!0;var o=j.shouldComponentUpdate,i=j.componentWillUpdate;j.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)},j.shouldComponentUpdate=r}return n.__N||n.__}(pe,e)}function re(e,t){var n=te(O++,3);!J.__s&&_e(n.__H,t)&&(n.__=e,n.u=t,j.__H.__h.push(n))}function oe(e){return K=5,ie(function(){return{current:e}},[])}function ie(e,t){var n=te(O++,7);return _e(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=V.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(de),t.__h.some(ue),t.__h=[]}catch(n){t.__h=[],J.__e(n,e.__v)}}}J.__b=function(e){j=null,Y&&Y(e)},J.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),ee&&ee(e,t)},J.__r=function(e){G&&G(e),O=0;var t=(j=e.__c).__H;t&&(q===j?(t.__h=[],j.__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=[],O=0)),q=j},J.diffed=function(e){X&&X(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(1!==V.push(t)&&B===J.requestAnimationFrame||((B=J.requestAnimationFrame)||ce)(ae)),t.__H.__.some(function(e){e.u&&(e.__H=e.u),e.u=void 0})),q=j=null},J.__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=[],J.__e(n,e.__v)}}),Q&&Q(e,t)},J.unmount=function(e){Z&&Z(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&&J.__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=j,n=e.__c;"function"==typeof n&&(e.__c=void 0,n()),j=t}function ue(e){var t=j;e.__c=e.__(),j=t}function _e(e,t){return!e||e.length!==t.length||t.some(function(t,n){return t!==e[n]})}function pe(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,_]=ne(null),[p,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;_(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"),_(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"),_(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:p,sendMessage:C,cancelStream:S,rateConversation:T,escalate:I,clearConversation:$,setIsOpen:w}}function me({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 F(x,{children:[o&&!r&&F("div",{style:{position:"fixed",bottom:"88px",...a,maxWidth:"260px",padding:"10px 14px",backgroundColor:"white",borderRadius:"12px",boxShadow:"0 4px 20px rgba(0,0,0,0.12)",fontSize:"13px",lineHeight:1.4,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:[o,F("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"})]}),F("button",{onClick:e,"aria-label":r?"Close chat":"Open chat",style:{position:"fixed",bottom:"20px",...a,width:"60px",height:"60px",borderRadius:"50%",backgroundColor:t,border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:`0 4px 14px ${t}40, 0 2px 6px rgba(0,0,0,0.1)`,transition:"transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease",zIndex:2147483646,WebkitTapHighlightColor:"transparent",animation:"ciro-bubble-entrance 0.4s cubic-bezier(0.34, 1.56, 0.64, 1)"},onMouseEnter:e=>{const t=e.currentTarget;t.style.transform="scale(1.08)",t.style.boxShadow="0 6px 20px rgba(0,0,0,0.2)"},onMouseLeave:e=>{const t=e.currentTarget;t.style.transform="scale(1)",t.style.boxShadow="0 4px 12px rgba(0,0,0,0.15)"},children:[F("svg",r?{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"white","stroke-width":"2","stroke-linecap":"round",children:[F("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),F("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}:{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"white","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:F("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})}),!r&&l>0&&F("span",{style:{position:"absolute",top:"-4px",right:"-4px",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"},children:l>9?"9+":l})]})]})}function ye(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(F("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(F("strong",{children:i[5]},r++)):i[6]?n.push(F("em",{children:i[7]},r++)):i[8]?n.push(F("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(F("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 xe(e){if(!e)return"";try{return new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch(t){return""}}function be({color:e,size:t=28}){return F("div",{style:{width:`${t}px`,height:`${t}px`,borderRadius:"50%",backgroundColor:`${e}15`,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:F("svg",{width:.55*t,height:.55*t,viewBox:"0 0 24 24",fill:"none",stroke:e,"stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[F("path",{d:"M12 8V4H8"}),F("rect",{x:"4",y:"8",width:"16",height:"12",rx:"2"}),F("circle",{cx:"9",cy:"14",r:"1",fill:e}),F("circle",{cx:"15",cy:"14",r:"1",fill:e})]})})}function ve({messages:e,config:t,onRate:n,lastAssistantId:r,feedbackThanks:o}){const[i,l]=ne(null),a=(e,t)=>{l(e),n(t)};return F(x,{children:e.map((n,l)=>{if("system"===n.role)return F("div",{style:{textAlign:"center",fontSize:"11px",opacity:.5,padding:"12px 0",display:"flex",alignItems:"center",gap:"8px"},children:[F("div",{style:{flex:1,height:"1px",backgroundColor:"rgba(0,0,0,0.08)"}}),F("span",{children:n.content}),F("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,_=!(s||u&&"assistant"===u.role);return F("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&&F("div",{style:{width:"28px",flexShrink:0},children:_&&(t.avatar_url?F("img",{src:t.avatar_url,alt:"",style:{width:"28px",height:"28px",borderRadius:"50%",objectFit:"cover"},onError:e=>{e.target.style.display="none"}}):F(be,{color:t.primary_color}))}),F("div",{style:{maxWidth:"78%",display:"flex",flexDirection:"column",alignItems:s?"flex-end":"flex-start"},children:[!s&&_&&F("div",{style:{fontSize:"11px",fontWeight:500,opacity:.5,marginBottom:"3px",paddingLeft:"2px"},children:t.name}),F("div",{style:{padding:"10px 14px",borderRadius:s?`${t.border_radius}px ${t.border_radius}px 4px ${t.border_radius}px`:_?`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?ye(n.content,t.text_color):null,n.isStreaming&&!n.content&&F("span",{style:{display:"inline-flex",gap:"3px",padding:"2px 0"},children:[0,1,2].map(e=>F("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&&F("span",{style:{display:"inline-block",animation:"ciro-blink 1s infinite",marginLeft:"1px"},children:"|"})]}),n.created_at&&!n.isStreaming&&F("div",{style:{fontSize:"10px",opacity:.35,marginTop:"3px",paddingLeft:s?"0":"2px",paddingRight:s?"2px":"0"},children:xe(n.created_at)}),!s&&n.sources&&n.sources.length>0&&t.include_citations&&F("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginTop:"4px"},children:n.sources.map((e,n)=>F("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&&F("div",{style:{display:"flex",gap:"4px",marginTop:"6px"},children:d?F("span",{style:{fontSize:"11px",opacity:.4},children:o||"Thanks for your feedback"}):F(x,{children:[F("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"}),F("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 we=5e3;function ke({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>we||(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,we);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 F("div",{style:{padding:"10px 12px",borderTop:"1px solid rgba(0,0,0,0.08)",display:"flex",alignItems:"flex-end",gap:"8px",flexShrink:0},children:[F("textarea",{ref:l,value:o,onInput:s,onKeyDown:c,placeholder:r,disabled:t,rows:1,maxLength:we,"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)"}}),F("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:F("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"white","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[F("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),F("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})})]})}function Ce({questions:e,onClick:t,primaryColor:n}){if(!e.length)return null;const r=e.length>=4;return F("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)=>F("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 Se({size:e=14}){return F("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"currentColor",style:{opacity:.6},children:[F("circle",{cx:"12",cy:"12",r:"10",fill:"none",stroke:"currentColor","stroke-width":"2"}),F("circle",{cx:"12",cy:"12",r:"4"})]})}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),_=He();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 p=[...t].reverse().find(e=>"assistant"===e.role&&!e.isStreaming),h=(null==p?void 0:p.suggestions)||[],g=0===t.length,f="bottom-left"===s?{left:"20px",right:"auto"}:{right:"20px",left:"auto"};return F("div",{role:"dialog","aria-label":`Chat with ${e.name}`,style:{position:"fixed",bottom:_?"0":"90px",..._?{left:0,right:0}:f,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:[F("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:F("div",{style:{padding:"14px 16px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[F("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[e.avatar_url?F("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"}}):F("div",{style:{width:"36px",height:"36px",borderRadius:"50%",backgroundColor:"rgba(255,255,255,0.15)",display:"flex",alignItems:"center",justifyContent:"center"},children:F("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"white","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[F("path",{d:"M12 8V4H8"}),F("rect",{x:"4",y:"8",width:"16",height:"12",rx:"2"}),F("circle",{cx:"9",cy:"14",r:"1",fill:"white"}),F("circle",{cx:"15",cy:"14",r:"1",fill:"white"})]})}),F("div",{children:[F("div",{style:{fontWeight:600,fontSize:"15px",letterSpacing:"-0.01em"},children:e.name}),F("div",{style:{fontSize:"12px",opacity:.9,display:"flex",alignItems:"center",gap:"4px"},children:n?F("span",{style:{display:"inline-flex",gap:"2px",alignItems:"center"},children:[F("span",{children:(null==c?void 0:c.typing)||"Typing"}),[0,1,2].map(e=>F("span",{style:{width:"3px",height:"3px",borderRadius:"50%",backgroundColor:"white",animation:`ciro-thinking-dot 1.4s ease-in-out ${.16*e}s infinite`}},e))]}):F(x,{children:[F("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"]})})]})]}),F("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:F("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:[F("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),F("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})}),F("div",{ref:d,style:{flex:1,overflowY:"auto",padding:"16px",display:"flex",flexDirection:"column",gap:"4px",WebkitOverflowScrolling:"touch"},children:[g&&F("div",{style:{padding:"16px 0 8px",display:"flex",flexDirection:"column",alignItems:"center"},children:F("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?F("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"}}):F("div",{style:{width:"48px",height:"48px",borderRadius:"12px",backgroundColor:`${e.primary_color}15`,margin:"0 auto 10px",display:"flex",alignItems:"center",justifyContent:"center"},children:F("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:e.primary_color,"stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[F("path",{d:"M12 8V4H8"}),F("rect",{x:"4",y:"8",width:"16",height:"12",rx:"2"}),F("circle",{cx:"9",cy:"14",r:"1",fill:e.primary_color}),F("circle",{cx:"15",cy:"14",r:"1",fill:e.primary_color})]})}),F("div",{style:{fontWeight:600,fontSize:"15px",marginBottom:"4px"},children:e.name}),F("p",{style:{opacity:.7,margin:0,lineHeight:1.5,fontSize:"13px"},children:e.welcome_message})]})}),g&&e.suggested_questions.length>0&&F(Ce,{questions:e.suggested_questions,onClick:o,primaryColor:e.primary_color}),F(ve,{messages:t,config:e,onRate:l,lastAssistantId:null==p?void 0:p.id,feedbackThanks:null==c?void 0:c.feedbackThanks}),h.length>0&&!n&&F(Ce,{questions:h,onClick:o,primaryColor:e.primary_color})]}),n&&F("div",{style:{padding:"6px 16px",display:"flex",alignItems:"center",gap:"8px",borderTop:"1px solid rgba(0,0,0,0.04)",flexShrink:0},children:[F("div",{style:{width:"20px",height:"20px",borderRadius:"50%",backgroundColor:`${e.primary_color}15`,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:F("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:e.primary_color,"stroke-width":"2.5",children:[F("path",{d:"M12 8V4H8"}),F("rect",{x:"4",y:"8",width:"16",height:"12",rx:"2"})]})}),F("span",{style:{fontSize:"12px",opacity:.5,display:"flex",alignItems:"center",gap:"3px"},children:[e.name," is typing",[0,1,2].map(t=>F("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&&F("div",{style:{padding:"0 16px 4px",textAlign:"center"},children:F("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"})}),F(ke,{onSend:r,isStreaming:n,primaryColor:e.primary_color,placeholder:(null==c?void 0:c.placeholder)||"Type your message..."}),F("div",{style:{textAlign:"center",padding:"3px 0 6px",fontSize:"10px",opacity:.3,display:"flex",alignItems:"center",justifyContent:"center",gap:"4px"},children:[F(Se,{size:10}),F("span",{style:{letterSpacing:"0.3px"},children:(null==c?void 0:c.poweredBy)||F(x,{children:["Powered by ",F("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 F("div",{style:{padding:"24px 20px",textAlign:"center"},children:[F("p",{style:{margin:"0 0 16px",fontSize:"14px",lineHeight:1.5,opacity:.8},children:e.lead_capture_message||"Please introduce yourself to start chatting."}),F("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&&F("input",{type:"text",placeholder:"Your name",value:i,maxLength:100,onInput:e=>l(e.target.value),style:c}),e.require_email&&F("input",{type:"email",placeholder:"Your email",value:r,maxLength:255,onInput:e=>o(e.target.value),style:c}),a&&F("p",{style:{color:"#ef4444",fontSize:"12px",margin:0},children:a}),F("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,_]=ne(!1),[p,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||p.email,userName:e.userName||p.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),_(!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 F(me,{onClick:H,primaryColor:I,position:$,isOpen:c});const R=(E.require_email||E.require_name)&&!u&&!e.userEmail;return F(x,{children:[F(me,{onClick:H,primaryColor:E.primary_color,position:$,isOpen:c,greeting:g?E.welcome_message:null,onDismissGreeting:()=>f(!1),unreadCount:v.unreadCount}),c&&(R?F(Ee,{config:E,position:$,onClose:k,onSubmit:T}):F(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=He();return F("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:[F("div",{style:{padding:"16px",backgroundColor:e.primary_color,color:"white",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[F("span",{style:{fontWeight:600},children:e.name}),F("button",{onClick:n,style:{background:"none",border:"none",color:"white",cursor:"pointer",display:"flex"},children:F("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:[F("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),F("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),F(Ie,{config:e,onSubmit:r,primaryColor:e.primary_color})]})}function He(){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,ze=null;const Me=()=>window.__ciroWidgetControl,De={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-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),ze=document.createElement("div"),t.appendChild(ze);try{N(m($e,{config:e}),ze)}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(){ze&&N(null,ze),Re&&Re.remove(),Re=null,ze=null,delete window.__ciroWidgetControl}};window.CiroChatbot=De;const We=document.currentScript;if(We){const e=We.getAttribute("data-ciro-bot-id"),t=We.getAttribute("data-ciro-api-key"),n=We.getAttribute("data-ciro-api-url");if(e&&t){const r=()=>De.init({botId:e,apiKey:t,apiUrl:n||void 0});"loading"===document.readyState?document.addEventListener("DOMContentLoaded",r):r()}}return De}();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ciro-chatbot-widget",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Embeddable AI chatbot widget for customer websites",
5
5
  "type": "module",
6
6
  "main": "dist/chatbot.js",
package/src/types.ts CHANGED
@@ -20,6 +20,16 @@ export interface CiroChatbotConfig {
20
20
  /** Only trigger once per session */
21
21
  oncePerSession?: boolean;
22
22
  };
23
+ // Theme overrides (override server config locally)
24
+ theme?: {
25
+ primaryColor?: string; // Override header + button color
26
+ backgroundColor?: string; // Override chat background
27
+ textColor?: string; // Override text color
28
+ borderRadius?: number; // Override corner radius
29
+ widgetWidth?: number; // Override width
30
+ widgetHeight?: number; // Override height
31
+ fontFamily?: string; // Override font
32
+ };
23
33
  // Localization
24
34
  locale?: {
25
35
  placeholder?: string; // Default: "Type your message..."
@@ -31,6 +41,8 @@ export interface CiroChatbotConfig {
31
41
  sendButton?: string; // Default: "Send message"
32
42
  feedbackThanks?: string; // Default: "Thanks for your feedback"
33
43
  };
44
+ // Sound
45
+ sound?: boolean; // Play notification sound on bot response (default: false)
34
46
  // Callbacks
35
47
  onOpen?: () => void;
36
48
  onClose?: () => void;