ciro-chatbot-widget 0.1.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 -0
- package/package.json +41 -0
- package/src/types.ts +67 -0
package/dist/chatbot.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var __CiroChatbot=function(){"use strict";var e,t,n,r,o,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,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=f({},n);l.__v=n.__v+1,t.vnode&&t.vnode(l),M(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,P(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,_){var p,f,g,m,b,w,k,C=r&&r.__k||d,S=t.length;for(s=function(e,t,n,r,o){var i,l,a,s,c,_=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+d,l.__=e,l.__b=e.__b+1,a=null,-1!=(c=l.__i=H(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?d--:c==s+1?d++:(c>s?d--:d++,l.__u|=4))):e.__k[i]=null;if(u)for(i=0;i<_;i++)null!=(a=n[i])&&!(2&a.__u)&&(a.__e==r&&(r=v(a)),A(a,a));return r}(n,t,C,s,S),p=0;p<S;p++)null!=(g=n.__k[p])&&(f=-1!=g.__i&&C[g.__i]||u,g.__i=p,w=M(e,g,f,o,i,l,a,s,c,_),m=g.__e,g.ref&&f.ref!=g.ref&&(f.ref&&N(f.ref,null,g),_.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,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=E(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 H(e,t,n,r){var o,i,l,a=e.key,s=e.type,c=t[n],_=null!=c&&!(2&c.__u);if(null===c&&null==a||_&&a==c.key&&s==c.type)return n;if(r>(_?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,t,n){"-"==t[0]?e.setProperty(t,null==n?"":n):e[t]=null==n?"":"number"!=typeof n||p.test(t)?n:n+"px"}function I(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.style,t,"");if(n)for(t in n)r&&n[t]==r[t]||$(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?_:c,i)):e.removeEventListener(t,i?_: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 M(n,r,o,i,l,a,s,c,_,p){var m,y,w,k,C,S,E,H,$,R,M,P,N,A,F,L=r.type;if(void 0!==r.constructor)return null;128&o.__u&&(_=!!(32&o.__u),a=[c=r.__e=o.__e]),(m=t.__b)&&m(r);e:if("function"==typeof L)try{if(H=r.props,$=L.prototype&&L.prototype.render,R=(m=L.contextType)&&i[m.__c],M=m?R?R.props.value:m.__:i,o.__c?E=(y=r.__c=o.__c).__=y.__E:($?r.__c=y=new L(H,M):(r.__c=y=new b(H,M),y.constructor=L,y.render=W),R&&R.sub(y),y.state||(y.state={}),y.__n=i,w=y.__d=!0,y.__h=[],y._sb=[]),$&&null==y.__s&&(y.__s=y.state),$&&null!=L.getDerivedStateFromProps&&(y.__s==y.state&&(y.__s=f({},y.__s)),f(y.__s,L.getDerivedStateFromProps(H,y.__s))),k=y.props,C=y.state,y.__v=r,w)$&&null==L.getDerivedStateFromProps&&null!=y.componentWillMount&&y.componentWillMount(),$&&null!=y.componentDidMount&&y.__h.push(y.componentDidMount);else{if($&&null==L.getDerivedStateFromProps&&H!==k&&null!=y.componentWillReceiveProps&&y.componentWillReceiveProps(H,M),r.__v==o.__v||!y.__e&&null!=y.shouldComponentUpdate&&!1===y.shouldComponentUpdate(H,y.__s,M)){r.__v!=o.__v&&(y.props=H,y.state=y.__s,y.__d=!1),r.__e=o.__e,r.__k=o.__k,r.__k.some(function(e){e&&(e.__=r)}),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,M),$&&null!=y.componentDidUpdate&&y.__h.push(function(){y.componentDidUpdate(k,C,S)})}if(y.context=M,y.props=H,y.__P=n,y.__e=!1,P=t.__r,N=0,$)y.state=y.__s,y.__d=!1,P&&P(r),m=y.render(y.props,y.state,y.context),d.push.apply(y.__h,y._sb),y._sb=[];else do{y.__d=!1,P&&P(r),m=y.render(y.props,y.state,y.context),y.state=y.__s}while(y.__d&&++N<25);y.state=y.__s,null!=y.getChildContext&&(i=f(f({},i),y.getChildContext())),$&&!w&&null!=y.getSnapshotBeforeUpdate&&(S=y.getSnapshotBeforeUpdate(k,C)),A=null!=m&&m.type===x&&null==m.key?U(m.props.children):m,c=T(n,h(A)?A:[A],r,o,i,l,a,s,c,_,p),y.base=r.__e,r.__u&=-161,y.__h.length&&s.push(y),E&&(y.__E=y.__=null)}catch(D){if(r.__v=null,_||null!=a)if(D.then){for(r.__u|=_?160:128;c&&8==c.nodeType&&c.nextSibling;)c=c.nextSibling;a[a.indexOf(c)]=null,r.__e=c}else{for(F=a.length;F--;)g(a[F]);z(r)}else r.__e=o.__e,r.__k=o.__k,D.then||z(r);t.__e(D,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,_){var d,p,f,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(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(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={},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||I(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||I(n,d,y,w[d],l);if(p)c||f&&(p.__html==f.__html||p.__html==n.innerHTML)||(n.innerHTML=p.__html),r.__k=[];else if(f&&(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,_),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])&&I(n,d,x,w[d],l),d="checked",null!=b&&b!=n[d]&&I(n,d,b,w[d],l))}return n}(o.__e,r,o,i,l,a,s,_,p);return(m=t.diffed)&&m(r),128&r.__u?void 0:c}function z(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some(z))}function P(e,n,r){for(var o=0;o<r.length;o++)N(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 U(e){return"object"!=typeof e||null==e||e.__b>0?e:h(e)?e.map(U):f({},e)}function N(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||N(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||g(e.__e),e.__c=e.__=e.__e=void 0}function W(e,t,n){return this.constructor(e,n)}function F(n,r,o){var i,l,a;r==document&&(r=document.documentElement),t.__&&t.__(n,r),i=!1?null:r.__k,l=[],a=[],M(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),P(l,n,a)}e=d.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=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,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),_=R(!0);var L=0;function D(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 _={type:e,props:c,key:r,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--L,__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(_),_}var q,O,j,B,K=0,J=[],Y=t,V=Y.__b,G=Y.__r,X=Y.diffed,Q=Y.__c,Z=Y.unmount,ee=Y.__;function te(e,t){Y.__h&&Y.__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],r=n.t(t,e);t!==r&&(n.__N=[r,n.__[1]],n.__c.setState({}))}],n.__c=O,!O.__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};O.__f=!0;var o=O.shouldComponentUpdate,i=O.componentWillUpdate;O.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)},O.shouldComponentUpdate=r}return n.__N||n.__}(pe,e)}function re(e,t){var n=te(q++,3);!Y.__s&&de(n.__H,t)&&(n.__=e,n.u=t,O.__H.__h.push(n))}function oe(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=J.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(_e),t.__h.some(ue),t.__h=[]}catch(n){t.__h=[],Y.__e(n,e.__v)}}}Y.__b=function(e){O=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),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(_e),t.__h.some(ue),t.__h=[],q=0)),j=O},Y.diffed=function(e){X&&X(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=O=null},Y.__c=function(e,t){t.some(function(e){try{e.__h.some(_e),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)}}),Q&&Q(e,t)},Y.unmount=function(e){Z&&Z(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(e){try{_e(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 _e(e){var t=O,n=e.__c;"function"==typeof n&&(e.__c=void 0,n()),O=t}function ue(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 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()})}}function fe({onClick:e,primaryColor:t,position:n,isOpen:r}){return D("button",{onClick:e,"aria-label":r?"Close chat":"Open chat",style:{position:"fixed",bottom:"20px",..."bottom-left"===n?{left:"20px",right:"auto"}:{right:"20px",left:"auto"},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:D("svg",r?{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"white","stroke-width":"2","stroke-linecap":"round",children:[D("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),D("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:D("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:r}){const[o,i]=ne(null),l=(e,t)=>{i(e),n(t)};return D(x,{children:e.map(e=>{if("system"===e.role)return D("div",{style:{textAlign:"center",fontSize:"12px",opacity:.6,padding:"8px 0"},children:e.content},e.id);const n="user"===e.role,i=e.id===r&&!e.isStreaming&&e.content,a=o===e.id;return D("div",{style:{display:"flex",flexDirection:"column",alignItems:n?"flex-end":"flex-start",maxWidth:"85%",alignSelf:n?"flex-end":"flex-start"},children:[D("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&&D("span",{style:{display:"inline-flex",gap:"3px",padding:"2px 0"},children:[0,1,2].map(e=>D("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&&D("span",{style:{display:"inline-block",animation:"ciro-blink 1s infinite",marginLeft:"1px"},children:"|"})]}),!n&&e.sources&&e.sources.length>0&&t.include_citations&&D("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginTop:"6px"},children:e.sources.map((e,n)=>D("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))}),i&&D("div",{style:{display:"flex",gap:"6px",marginTop:"6px"},children:a?D("span",{style:{fontSize:"12px",opacity:.5},children:"Thanks for your feedback"}):D(x,{children:[D("button",{onClick:()=>l(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:"👍"}),D("button",{onClick:()=>l(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:r}){const[o,i]=ne(""),l=oe(null),a=le(()=>{const n=o.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)))},[o,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]),_=o.trim().length>0&&!t;return D("div",{style:{padding:"10px 12px",borderTop:"1px solid rgba(0,0,0,0.08)",display:"flex",alignItems:"flex-end",gap:"8px",flexShrink:0},children:[D("textarea",{ref:l,value:o,onInput:s,onKeyDown:c,placeholder:r,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)"}}),D("button",{onClick:a,disabled:!_,"aria-label":"Send message",style:{width:"40px",height:"40px",borderRadius:"50%",backgroundColor:_?n:"#e5e7eb",border:"none",cursor:_?"pointer":"default",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,transition:"background-color 0.15s",minHeight:"44px",minWidth:"44px"},children:D("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"white","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[D("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),D("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})})]})}function xe({questions:e,onClick:t,primaryColor:n}){return e.length?D("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},role:"list","aria-label":"Suggested questions",children:e.map((e,r)=>D("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},r))}):null}function be({config:e,messages:t,isStreaming:n,onSend:r,onSuggestionClick:o,onClose:i,onRate:l,onEscalate:a,position:s}){const c=oe(null),_=oe(0),u=Ce();re(()=>{if(t.length>_.current){const e=c.current;e&&requestAnimationFrame(()=>{e.scrollTop=e.scrollHeight})}_.current=t.length},[t.length]),re(()=>{if(!n)return;const e=c.current;if(!e)return;e.scrollHeight-e.scrollTop-e.clientHeight<100&&(e.scrollTop=e.scrollHeight)},[t,n]);const d=[...t].reverse().find(e=>"assistant"===e.role&&!e.isStreaming),p=null==d?void 0:d.id,h=(null==d?void 0:d.suggestions)||[],f=0===t.length&&e.suggested_questions.length>0,g="bottom-left"===s?{left:"20px",right:"auto"}:{right:"20px",left:"auto"};return D("div",{role:"dialog","aria-label":`Chat with ${e.name}`,style:{position:"fixed",bottom:u?"0":"90px",...u?{left:0,right:0}:g,width:u?"100%":`${e.widget_width}px`,height:u?"100%":`${e.widget_height}px`,maxHeight:u?"100vh":"calc(100vh - 110px)",backgroundColor:e.background_color,borderRadius:u?"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:u?"none":"1px solid rgba(0,0,0,0.08)",animation:"ciro-window-open 0.25s cubic-bezier(0.16, 1, 0.3, 1)"},children:[D("div",{style:{padding:"14px 16px",backgroundColor:e.primary_color,color:"white",display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[D("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[e.avatar_url&&D("img",{src:e.avatar_url,alt:"",style:{width:"32px",height:"32px",borderRadius:"50%",objectFit:"cover"},onError:e=>{e.target.style.display="none"}}),D("div",{children:[D("div",{style:{fontWeight:600,fontSize:"15px"},children:e.name}),D("div",{style:{fontSize:"12px",opacity:.85,display:"flex",alignItems:"center",gap:"4px"},children:n?D("span",{style:{display:"inline-flex",gap:"2px",alignItems:"center"},children:[D("span",{children:"Typing"}),[0,1,2].map(e=>D("span",{style:{width:"3px",height:"3px",borderRadius:"50%",backgroundColor:"white",animation:`ciro-thinking-dot 1.4s ease-in-out ${.16*e}s infinite`}},e))]}):D(x,{children:[D("span",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#4ade80",display:"inline-block",boxShadow:"0 0 4px #4ade80"}}),"Online"]})})]})]}),D("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:D("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:[D("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),D("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),D("div",{ref:c,style:{flex:1,overflowY:"auto",padding:"16px",display:"flex",flexDirection:"column",gap:"12px",WebkitOverflowScrolling:"touch"},children:[0===t.length&&D("div",{style:{textAlign:"center",padding:"20px 0"},children:[e.logo_url&&D("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"}}),D("p",{style:{color:e.text_color,opacity:.8,margin:0,lineHeight:1.5},children:e.welcome_message})]}),f&&D(xe,{questions:e.suggested_questions,onClick:o,primaryColor:e.primary_color}),D(ge,{messages:t,config:e,onRate:l,lastAssistantId:p}),h.length>0&&!n&&D(xe,{questions:h,onClick:o,primaryColor:e.primary_color})]}),e.escalation_enabled&&t.length>4&&D("div",{style:{padding:"0 16px 6px",textAlign:"center"},children:D("button",{onClick:a,style:{background:"none",border:"none",color:e.primary_color,cursor:"pointer",fontSize:"12px",textDecoration:"underline",opacity:.7,minHeight:"32px"},children:"Talk to a human"})}),D(ye,{onSend:r,isStreaming:n,primaryColor:e.primary_color,placeholder:"Type your message..."}),D("div",{style:{textAlign:"center",padding:"4px 0 6px",fontSize:"10px",opacity:.3,letterSpacing:"0.5px",textTransform:"uppercase"},children:["Powered by ",D("span",{style:{fontWeight:600},children:"CIRO"})]})]})}function ve({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 D("div",{style:{padding:"24px 20px",textAlign:"center"},children:[D("p",{style:{margin:"0 0 16px",fontSize:"14px",lineHeight:1.5,opacity:.8},children:e.lead_capture_message||"Please introduce yourself to start chatting."}),D("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&&D("input",{type:"text",placeholder:"Your name",value:i,maxLength:100,onInput:e=>l(e.target.value),style:c}),e.require_email&&D("input",{type:"email",placeholder:"Your email",value:r,maxLength:255,onInput:e=>o(e.target.value),style:c}),a&&D("p",{style:{color:"#ef4444",fontSize:"12px",margin:0},children:a}),D("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),[r,o]=ne(!1),[i,l]=ne({}),{widgetConfig:a,loading:s,error:c}=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),_=function(e,t){const[n,r]=ne([]),[o,i]=ne("idle"),[l,a]=ne(null),[s,c]=ne(null),_=oe(null),u=oe(null),d=oe(0),p=oe(null),h=oe("");_.current||(_.current=new he(e.apiUrl||window.location.origin,e.botId,e.apiKey));const f=_.current;re(()=>()=>{var e;null==(e=u.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"===o)return;c(null),h.current="";const a="user_"+ ++d.current;r(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;r(e=>[...e,{id:s,role:"assistant",content:"",sources:[],suggestions:[],isStreaming:!0}]),i("streaming");try{const n=await g();u.current=f.streamMessage(n,t.trim(),{onTextDelta:e=>{h.current+=e,r(t=>t.map(t=>t.id===s?{...t,content:t.content+e}:t))},onSource:e=>{r(t=>t.map(t=>t.id===s?{...t,sources:[...t.sources||[],{name:e.label,type:e.detail}]}:t))},onSuggestions:e=>{r(t=>t.map(t=>t.id===s?{...t,suggestions:e}:t))},onConfidence:e=>{r(t=>t.map(t=>t.id===s?{...t,confidence:e.overall}:t))},onEnd:()=>{var t;r(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;r(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(_){r(e=>e.map(e=>e.id===s?{...e,content:"Failed to connect. Please try again.",isStreaming:!1}:e)),i("error"),c(_.message),null==(l=e.onError)||l.call(e,_)}},[o,e,f,g]),y=le(()=>{var e;null==(e=u.current)||e.abort(),u.current=null,r(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),r(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:o,error:s,conversationId:l,sendMessage:m,cancelStream:y,rateConversation:x,escalate:b}}({...e,userEmail:e.userEmail||i.email,userName:e.userName||i.name},a);re(()=>(window.__ciroWidgetControl={open:()=>n(!0),close:()=>n(!1)},()=>{delete window.__ciroWidgetControl}),[]),re(()=>{var n,r;t?null==(n=e.onOpen)||n.call(e):null==(r=e.onClose)||r.call(e)},[t]);const u=le(()=>{n(e=>!e)},[]),d=le(e=>{_.sendMessage(e)},[_]),p=le(e=>{_.sendMessage(e)},[_]),h=le(t=>{var n;l(t),o(!0),null==(n=e.onLeadCapture)||n.call(e,t)},[e]);re(()=>{const e=e=>{"Escape"===e.key&&t&&n(!1)};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t]);const f=(null==a?void 0:a.primary_color)||"#2563EB",g=e.position||(null==a?void 0:a.position)||"bottom-right";if(s||c||!a)return D(fe,{onClick:u,primaryColor:f,position:g,isOpen:t});const m=(a.require_email||a.require_name)&&!r&&!e.userEmail;return D(x,{children:[D(fe,{onClick:u,primaryColor:a.primary_color,position:g,isOpen:t}),t&&(m?D(ke,{config:a,position:g,onClose:u,onSubmit:h}):D(be,{config:a,messages:_.messages,isStreaming:"streaming"===_.state,onSend:d,onSuggestionClick:p,onClose:u,onRate:_.rateConversation,onEscalate:_.escalate,position:g}))]})}function ke({config:e,position:t,onClose:n,onSubmit:r}){const o=Ce();return D("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:[D("div",{style:{padding:"16px",backgroundColor:e.primary_color,color:"white",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[D("span",{style:{fontWeight:600},children:e.name}),D("button",{onClick:n,style:{background:"none",border:"none",color:"white",cursor:"pointer",display:"flex"},children:D("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:[D("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),D("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),D(ve,{config:e,onSubmit:r,primaryColor:e.primary_color})]})}function Ce(){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 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(r){}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{F(m(we,{config:e}),Te)}catch(o){console.error("[CiroChatbot] Failed to render:",o)}},open(){var e;null==(e=Ee())||e.open()},close(){var e;null==(e=Ee())||e.close()},destroy(){Te&&F(null,Te),Se&&Se.remove(),Se=null,Te=null,delete window.__ciroWidgetControl}};window.CiroChatbot=He;const $e=document.currentScript;if($e){const e=$e.getAttribute("data-ciro-bot-id"),t=$e.getAttribute("data-ciro-api-key"),n=$e.getAttribute("data-ciro-api-url");if(e&&t){const r=()=>He.init({botId:e,apiKey:t,apiUrl:n||void 0});"loading"===document.readyState?document.addEventListener("DOMContentLoaded",r):r()}}return He}();
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ciro-chatbot-widget",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Embeddable AI chatbot widget for customer websites",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/chatbot.js",
|
|
7
|
+
"types": "src/types.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist/chatbot.js",
|
|
10
|
+
"src/types.ts"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"dev": "vite",
|
|
14
|
+
"build": "vite build",
|
|
15
|
+
"preview": "vite preview",
|
|
16
|
+
"typecheck": "tsc --noEmit",
|
|
17
|
+
"prepublishOnly": "npm run build"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"chatbot",
|
|
21
|
+
"widget",
|
|
22
|
+
"ai",
|
|
23
|
+
"customer-support",
|
|
24
|
+
"embeddable",
|
|
25
|
+
"ciro"
|
|
26
|
+
],
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/cirolabs/ciro"
|
|
30
|
+
},
|
|
31
|
+
"license": "UNLICENSED",
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"preact": "^10.19.3"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@preact/preset-vite": "^2.9.1",
|
|
37
|
+
"terser": "^5.46.0",
|
|
38
|
+
"typescript": "^5.3.3",
|
|
39
|
+
"vite": "^5.4.0"
|
|
40
|
+
}
|
|
41
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/** Configuration passed to CiroChatbot.init() */
|
|
2
|
+
export interface CiroChatbotConfig {
|
|
3
|
+
botId: string;
|
|
4
|
+
apiKey: string;
|
|
5
|
+
apiUrl?: string;
|
|
6
|
+
// Layout
|
|
7
|
+
position?: 'bottom-right' | 'bottom-left';
|
|
8
|
+
// External user identity
|
|
9
|
+
externalUserId?: string;
|
|
10
|
+
userEmail?: string;
|
|
11
|
+
userName?: string;
|
|
12
|
+
// Callbacks
|
|
13
|
+
onOpen?: () => void;
|
|
14
|
+
onClose?: () => void;
|
|
15
|
+
onMessage?: (msg: { role: string; content: string }) => void;
|
|
16
|
+
onError?: (err: Error) => void;
|
|
17
|
+
onLeadCapture?: (data: { email?: string; name?: string }) => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Widget config returned from POST /init */
|
|
21
|
+
export interface WidgetConfig {
|
|
22
|
+
name: string;
|
|
23
|
+
welcome_message: string;
|
|
24
|
+
suggested_questions: string[];
|
|
25
|
+
fallback_message: string;
|
|
26
|
+
primary_color: string;
|
|
27
|
+
background_color: string;
|
|
28
|
+
text_color: string;
|
|
29
|
+
logo_url: string | null;
|
|
30
|
+
avatar_url: string | null;
|
|
31
|
+
chat_bubble_icon: string;
|
|
32
|
+
position: string;
|
|
33
|
+
border_radius: number;
|
|
34
|
+
theme: string;
|
|
35
|
+
custom_css: string | null;
|
|
36
|
+
widget_width: number;
|
|
37
|
+
widget_height: number;
|
|
38
|
+
require_email: boolean;
|
|
39
|
+
require_name: boolean;
|
|
40
|
+
lead_capture_message: string | null;
|
|
41
|
+
escalation_enabled: boolean;
|
|
42
|
+
escalation_message: string;
|
|
43
|
+
include_citations: boolean;
|
|
44
|
+
show_confidence: boolean;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** A message in the conversation */
|
|
48
|
+
export interface ChatMessage {
|
|
49
|
+
id: string;
|
|
50
|
+
role: 'user' | 'assistant' | 'system';
|
|
51
|
+
content: string;
|
|
52
|
+
sources?: Array<{ name: string; type: string }>;
|
|
53
|
+
suggestions?: string[];
|
|
54
|
+
confidence?: number;
|
|
55
|
+
isStreaming?: boolean;
|
|
56
|
+
created_at?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** SSE event types from the widget API */
|
|
60
|
+
export type SSEEventType =
|
|
61
|
+
| 'stream:start'
|
|
62
|
+
| 'stream:end'
|
|
63
|
+
| 'stream:error'
|
|
64
|
+
| 'text:delta'
|
|
65
|
+
| 'source:add'
|
|
66
|
+
| 'suggestions'
|
|
67
|
+
| 'confidence';
|