@ariaflowagents/widget 0.9.1 → 0.9.2
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/widget.js +329 -332
- package/dist/widget.umd.cjs +2 -2
- package/package.json +1 -1
package/dist/widget.umd.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(function(H,F){typeof exports=="object"&&typeof module<"u"?F(exports):typeof define=="function"&&define.amd?define(["exports"],F):(H=typeof globalThis<"u"?globalThis:H||self,F(H.AriaFlowWidget={}))})(this,function(H){"use strict";var F,m,pe,U,me,ye,ve,we,se,ie,oe,B={},be=[],nt=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,z=Array.isArray;function W(t,e){for(var n in e)t[n]=e[n];return t}function re(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function R(t,e,n){var s,o,i,a={};for(i in e)i=="key"?s=e[i]:i=="ref"?o=e[i]:a[i]=e[i];if(arguments.length>2&&(a.children=arguments.length>3?F.call(arguments,2):n),typeof t=="function"&&t.defaultProps!=null)for(i in t.defaultProps)a[i]===void 0&&(a[i]=t.defaultProps[i]);return Q(t,a,s,o,null)}function Q(t,e,n,s,o){var i={type:t,props:e,key:n,ref:s,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:o??++pe,__i:-1,__u:0};return o==null&&m.vnode!=null&&m.vnode(i),i}function I(t){return t.children}function V(t,e){this.props=t,this.context=e}function q(t,e){if(e==null)return t.__?q(t.__,t.__i+1):null;for(var n;e<t.__k.length;e++)if((n=t.__k[e])!=null&&n.__e!=null)return n.__e;return typeof t.type=="function"?q(t):null}function Ce(t){var e,n;if((t=t.__)!=null&&t.__c!=null){for(t.__e=t.__c.base=null,e=0;e<t.__k.length;e++)if((n=t.__k[e])!=null&&n.__e!=null){t.__e=t.__c.base=n.__e;break}return Ce(t)}}function ke(t){(!t.__d&&(t.__d=!0)&&U.push(t)&&!K.__r++||me!=m.debounceRendering)&&((me=m.debounceRendering)||ye)(K)}function K(){for(var t,e,n,s,o,i,a,_=1;U.length;)U.length>_&&U.sort(ve),t=U.shift(),_=U.length,t.__d&&(n=void 0,s=void 0,o=(s=(e=t).__v).__e,i=[],a=[],e.__P&&((n=W({},s)).__v=s.__v+1,m.vnode&&m.vnode(n),ae(e.__P,n,s,e.__n,e.__P.namespaceURI,32&s.__u?[o]:null,i,o??q(s),!!(32&s.__u),a),n.__v=s.__v,n.__.__k[n.__i]=n,xe(i,n,a),s.__e=s.__=null,n.__e!=o&&Ce(n)));K.__r=0}function Se(t,e,n,s,o,i,a,_,c,l,u){var r,g,h,w,k,b,p,f=s&&s.__k||be,M=e.length;for(c=st(n,e,f,c,M),r=0;r<M;r++)(h=n.__k[r])!=null&&(g=h.__i==-1?B:f[h.__i]||B,h.__i=r,b=ae(t,h,g,o,i,a,_,c,l,u),w=h.__e,h.ref&&g.ref!=h.ref&&(g.ref&&_e(g.ref,null,h),u.push(h.ref,h.__c||w,h)),k==null&&w!=null&&(k=w),(p=!!(4&h.__u))||g.__k===h.__k?c=Ae(h,c,t,p):typeof h.type=="function"&&b!==void 0?c=b:w&&(c=w.nextSibling),h.__u&=-7);return n.__e=k,c}function st(t,e,n,s,o){var i,a,_,c,l,u=n.length,r=u,g=0;for(t.__k=new Array(o),i=0;i<o;i++)(a=e[i])!=null&&typeof a!="boolean"&&typeof a!="function"?(typeof a=="string"||typeof a=="number"||typeof a=="bigint"||a.constructor==String?a=t.__k[i]=Q(null,a,null,null,null):z(a)?a=t.__k[i]=Q(I,{children:a},null,null,null):a.constructor===void 0&&a.__b>0?a=t.__k[i]=Q(a.type,a.props,a.key,a.ref?a.ref:null,a.__v):t.__k[i]=a,c=i+g,a.__=t,a.__b=t.__b+1,_=null,(l=a.__i=it(a,n,c,r))!=-1&&(r--,(_=n[l])&&(_.__u|=2)),_==null||_.__v==null?(l==-1&&(o>u?g--:o<u&&g++),typeof a.type!="function"&&(a.__u|=4)):l!=c&&(l==c-1?g--:l==c+1?g++:(l>c?g--:g++,a.__u|=4))):t.__k[i]=null;if(r)for(i=0;i<u;i++)(_=n[i])!=null&&!(2&_.__u)&&(_.__e==s&&(s=q(_)),We(_,_));return s}function Ae(t,e,n,s){var o,i;if(typeof t.type=="function"){for(o=t.__k,i=0;o&&i<o.length;i++)o[i]&&(o[i].__=t,e=Ae(o[i],e,n,s));return e}t.__e!=e&&(s&&(e&&t.type&&!e.parentNode&&(e=q(t)),n.insertBefore(t.__e,e||null)),e=t.__e);do e=e&&e.nextSibling;while(e!=null&&e.nodeType==8);return e}function it(t,e,n,s){var o,i,a,_=t.key,c=t.type,l=e[n],u=l!=null&&(2&l.__u)==0;if(l===null&&_==null||u&&_==l.key&&c==l.type)return n;if(s>(u?1:0)){for(o=n-1,i=n+1;o>=0||i<e.length;)if((l=e[a=o>=0?o--:i++])!=null&&!(2&l.__u)&&_==l.key&&c==l.type)return a}return-1}function $e(t,e,n){e[0]=="-"?t.setProperty(e,n??""):t[e]=n==null?"":typeof n!="number"||nt.test(e)?n:n+"px"}function J(t,e,n,s,o){var i,a;e:if(e=="style")if(typeof n=="string")t.style.cssText=n;else{if(typeof s=="string"&&(t.style.cssText=s=""),s)for(e in s)n&&e in n||$e(t.style,e,"");if(n)for(e in n)s&&n[e]==s[e]||$e(t.style,e,n[e])}else if(e[0]=="o"&&e[1]=="n")i=e!=(e=e.replace(we,"$1")),a=e.toLowerCase(),e=a in t||e=="onFocusOut"||e=="onFocusIn"?a.slice(2):e.slice(2),t.l||(t.l={}),t.l[e+i]=n,n?s?n.u=s.u:(n.u=se,t.addEventListener(e,i?oe:ie,i)):t.removeEventListener(e,i?oe:ie,i);else{if(o=="http://www.w3.org/2000/svg")e=e.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(e!="width"&&e!="height"&&e!="href"&&e!="list"&&e!="form"&&e!="tabIndex"&&e!="download"&&e!="rowSpan"&&e!="colSpan"&&e!="role"&&e!="popover"&&e in t)try{t[e]=n??"";break e}catch{}typeof n=="function"||(n==null||n===!1&&e[4]!="-"?t.removeAttribute(e):t.setAttribute(e,e=="popover"&&n==1?"":n))}}function Ne(t){return function(e){if(this.l){var n=this.l[e.type+t];if(e.t==null)e.t=se++;else if(e.t<n.u)return;return n(m.event?m.event(e):e)}}}function ae(t,e,n,s,o,i,a,_,c,l){var u,r,g,h,w,k,b,p,f,M,$,D,S,ee,A,L,O,N=e.type;if(e.constructor!==void 0)return null;128&n.__u&&(c=!!(32&n.__u),i=[_=e.__e=n.__e]),(u=m.__b)&&u(e);e:if(typeof N=="function")try{if(p=e.props,f="prototype"in N&&N.prototype.render,M=(u=N.contextType)&&s[u.__c],$=u?M?M.props.value:u.__:s,n.__c?b=(r=e.__c=n.__c).__=r.__E:(f?e.__c=r=new N(p,$):(e.__c=r=new V(p,$),r.constructor=N,r.render=rt),M&&M.sub(r),r.state||(r.state={}),r.__n=s,g=r.__d=!0,r.__h=[],r._sb=[]),f&&r.__s==null&&(r.__s=r.state),f&&N.getDerivedStateFromProps!=null&&(r.__s==r.state&&(r.__s=W({},r.__s)),W(r.__s,N.getDerivedStateFromProps(p,r.__s))),h=r.props,w=r.state,r.__v=e,g)f&&N.getDerivedStateFromProps==null&&r.componentWillMount!=null&&r.componentWillMount(),f&&r.componentDidMount!=null&&r.__h.push(r.componentDidMount);else{if(f&&N.getDerivedStateFromProps==null&&p!==h&&r.componentWillReceiveProps!=null&&r.componentWillReceiveProps(p,$),e.__v==n.__v||!r.__e&&r.shouldComponentUpdate!=null&&r.shouldComponentUpdate(p,r.__s,$)===!1){for(e.__v!=n.__v&&(r.props=p,r.state=r.__s,r.__d=!1),e.__e=n.__e,e.__k=n.__k,e.__k.some(function(P){P&&(P.__=e)}),D=0;D<r._sb.length;D++)r.__h.push(r._sb[D]);r._sb=[],r.__h.length&&a.push(r);break e}r.componentWillUpdate!=null&&r.componentWillUpdate(p,r.__s,$),f&&r.componentDidUpdate!=null&&r.__h.push(function(){r.componentDidUpdate(h,w,k)})}if(r.context=$,r.props=p,r.__P=t,r.__e=!1,S=m.__r,ee=0,f){for(r.state=r.__s,r.__d=!1,S&&S(e),u=r.render(r.props,r.state,r.context),A=0;A<r._sb.length;A++)r.__h.push(r._sb[A]);r._sb=[]}else do r.__d=!1,S&&S(e),u=r.render(r.props,r.state,r.context),r.state=r.__s;while(r.__d&&++ee<25);r.state=r.__s,r.getChildContext!=null&&(s=W(W({},s),r.getChildContext())),f&&!g&&r.getSnapshotBeforeUpdate!=null&&(k=r.getSnapshotBeforeUpdate(h,w)),L=u,u!=null&&u.type===I&&u.key==null&&(L=Pe(u.props.children)),_=Se(t,z(L)?L:[L],e,n,s,o,i,a,_,c,l),r.base=e.__e,e.__u&=-161,r.__h.length&&a.push(r),b&&(r.__E=r.__=null)}catch(P){if(e.__v=null,c||i!=null)if(P.then){for(e.__u|=c?160:128;_&&_.nodeType==8&&_.nextSibling;)_=_.nextSibling;i[i.indexOf(_)]=null,e.__e=_}else{for(O=i.length;O--;)re(i[O]);le(e)}else e.__e=n.__e,e.__k=n.__k,P.then||le(e);m.__e(P,e,n)}else i==null&&e.__v==n.__v?(e.__k=n.__k,e.__e=n.__e):_=e.__e=ot(n.__e,e,n,s,o,i,a,c,l);return(u=m.diffed)&&u(e),128&e.__u?void 0:_}function le(t){t&&t.__c&&(t.__c.__e=!0),t&&t.__k&&t.__k.forEach(le)}function xe(t,e,n){for(var s=0;s<n.length;s++)_e(n[s],n[++s],n[++s]);m.__c&&m.__c(e,t),t.some(function(o){try{t=o.__h,o.__h=[],t.some(function(i){i.call(o)})}catch(i){m.__e(i,o.__v)}})}function Pe(t){return typeof t!="object"||t==null||t.__b&&t.__b>0?t:z(t)?t.map(Pe):W({},t)}function ot(t,e,n,s,o,i,a,_,c){var l,u,r,g,h,w,k,b=n.props||B,p=e.props,f=e.type;if(f=="svg"?o="http://www.w3.org/2000/svg":f=="math"?o="http://www.w3.org/1998/Math/MathML":o||(o="http://www.w3.org/1999/xhtml"),i!=null){for(l=0;l<i.length;l++)if((h=i[l])&&"setAttribute"in h==!!f&&(f?h.localName==f:h.nodeType==3)){t=h,i[l]=null;break}}if(t==null){if(f==null)return document.createTextNode(p);t=document.createElementNS(o,f,p.is&&p),_&&(m.__m&&m.__m(e,i),_=!1),i=null}if(f==null)b===p||_&&t.data==p||(t.data=p);else{if(i=i&&F.call(t.childNodes),!_&&i!=null)for(b={},l=0;l<t.attributes.length;l++)b[(h=t.attributes[l]).name]=h.value;for(l in b)if(h=b[l],l!="children"){if(l=="dangerouslySetInnerHTML")r=h;else if(!(l in p)){if(l=="value"&&"defaultValue"in p||l=="checked"&&"defaultChecked"in p)continue;J(t,l,null,h,o)}}for(l in p)h=p[l],l=="children"?g=h:l=="dangerouslySetInnerHTML"?u=h:l=="value"?w=h:l=="checked"?k=h:_&&typeof h!="function"||b[l]===h||J(t,l,h,b[l],o);if(u)_||r&&(u.__html==r.__html||u.__html==t.innerHTML)||(t.innerHTML=u.__html),e.__k=[];else if(r&&(t.innerHTML=""),Se(e.type=="template"?t.content:t,z(g)?g:[g],e,n,s,f=="foreignObject"?"http://www.w3.org/1999/xhtml":o,i,a,i?i[0]:n.__k&&q(n,0),_,c),i!=null)for(l=i.length;l--;)re(i[l]);_||(l="value",f=="progress"&&w==null?t.removeAttribute("value"):w!=null&&(w!==t[l]||f=="progress"&&!w||f=="option"&&w!=b[l])&&J(t,l,w,b[l],o),l="checked",k!=null&&k!=t[l]&&J(t,l,k,b[l],o))}return t}function _e(t,e,n){try{if(typeof t=="function"){var s=typeof t.__u=="function";s&&t.__u(),s&&e==null||(t.__u=t(e))}else t.current=e}catch(o){m.__e(o,n)}}function We(t,e,n){var s,o;if(m.unmount&&m.unmount(t),(s=t.ref)&&(s.current&&s.current!=t.__e||_e(s,null,e)),(s=t.__c)!=null){if(s.componentWillUnmount)try{s.componentWillUnmount()}catch(i){m.__e(i,e)}s.base=s.__P=null}if(s=t.__k)for(o=0;o<s.length;o++)s[o]&&We(s[o],e,n||typeof t.type!="function");n||re(t.__e),t.__c=t.__=t.__e=void 0}function rt(t,e,n){return this.constructor(t,n)}function G(t,e,n){var s,o,i,a;e==document&&(e=document.documentElement),m.__&&m.__(t,e),o=(s=typeof n=="function")?null:n&&n.__k||e.__k,i=[],a=[],ae(e,t=(!s&&n||e).__k=R(I,null,[t]),o||B,B,e.namespaceURI,!s&&n?[n]:o?null:e.firstChild?F.call(e.childNodes):null,i,!s&&n?n:o?o.__e:e.firstChild,s,a),xe(i,t,a)}function Ee(t,e){G(t,e,Ee)}function Me(t,e,n){var s,o,i,a,_=W({},t.props);for(i in t.type&&t.type.defaultProps&&(a=t.type.defaultProps),e)i=="key"?s=e[i]:i=="ref"?o=e[i]:_[i]=e[i]===void 0&&a!=null?a[i]:e[i];return arguments.length>2&&(_.children=arguments.length>3?F.call(arguments,2):n),Q(t.type,_,s||t.key,o||t.ref,null)}F=be.slice,m={__e:function(t,e,n,s){for(var o,i,a;e=e.__;)if((o=e.__c)&&!o.__)try{if((i=o.constructor)&&i.getDerivedStateFromError!=null&&(o.setState(i.getDerivedStateFromError(t)),a=o.__d),o.componentDidCatch!=null&&(o.componentDidCatch(t,s||{}),a=o.__d),a)return o.__E=o}catch(_){t=_}throw t}},pe=0,V.prototype.setState=function(t,e){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=W({},this.state),typeof t=="function"&&(t=t(W({},n),this.props)),t&&W(n,t),t!=null&&this.__v&&(e&&this._sb.push(e),ke(this))},V.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),ke(this))},V.prototype.render=I,U=[],ye=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,ve=function(t,e){return t.__v.__b-e.__v.__b},K.__r=0,we=/(PointerCapture)$|Capture$/i,se=0,ie=Ne(!1),oe=Ne(!0);function X(){return X=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},X.apply(this,arguments)}function Te(t,e){if(t==null)return{};var n,s,o={},i=Object.keys(t);for(s=0;s<i.length;s++)e.indexOf(n=i[s])>=0||(o[n]=t[n]);return o}var at=["context","children"],lt=["useFragment"];function _t(t,e,n,s){function o(){var i,a=Reflect.construct(HTMLElement,[],o);return a._vdomComponent=t,s&&s.shadow?(a._root=a.attachShadow({mode:s.mode||"open",serializable:(i=s.serializable)!=null&&i}),s.adoptedStyleSheets&&(a._root.adoptedStyleSheets=s.adoptedStyleSheets)):a._root=a,a}return(o.prototype=Object.create(HTMLElement.prototype)).constructor=o,o.prototype.connectedCallback=function(){ut.call(this,s)},o.prototype.attributeChangedCallback=ht,o.prototype.disconnectedCallback=dt,n=n||t.observedAttributes||Object.keys(t.propTypes||{}),o.observedAttributes=n,t.formAssociated&&(o.formAssociated=!0),n.forEach(function(i){Object.defineProperty(o.prototype,i,{get:function(){return this._vdom?this._vdom.props[i]:this._props[i]},set:function(a){this._vdom?this.attributeChangedCallback(i,null,a):(this._props||(this._props={}),this._props[i]=a);var _=typeof a;a!=null&&_!=="string"&&_!=="boolean"&&_!=="number"||this.setAttribute(i,a)}})}),customElements.define(e,o),o}function ct(t){this.getChildContext=function(){return t.context};var e=t.children,n=Te(t,at);return Me(e,n)}function ut(t){var e=new CustomEvent("_preact",{detail:{},bubbles:!0,cancelable:!0});this.dispatchEvent(e),this._vdom=R(ct,X({},this._props,{context:e.detail.context}),Ue(this,this._vdomComponent,t)),(this.hasAttribute("hydrate")?Ee:G)(this._vdom,this._root)}function Fe(t){return t.replace(/-(\w)/g,function(e,n){return n?n.toUpperCase():""})}function ht(t,e,n){if(this._vdom){var s={};s[t]=n=n??void 0,s[Fe(t)]=n,this._vdom=Me(this._vdom,s),G(this._vdom,this._root)}}function dt(){G(this._vdom=null,this._root)}function He(t,e){var n=this,s=t.useFragment,o=Te(t,lt);return R(s?I:"slot",X({},o,{ref:function(i){i?(n.ref=i,n._listener||(n._listener=function(a){a.stopPropagation(),a.detail.context=e},i.addEventListener("_preact",n._listener))):n.ref.removeEventListener("_preact",n._listener)}}))}function Ue(t,e,n){if(t.nodeType===3)return t.data;if(t.nodeType!==1)return null;var s=[],o={},i=0,a=t.attributes,_=t.childNodes;for(i=a.length;i--;)a[i].name!=="slot"&&(o[a[i].name]=a[i].value,o[Fe(a[i].name)]=a[i].value);for(i=_.length;i--;){var c=Ue(_[i],null,n),l=_[i].slot;l?o[l]=R(He,{name:l},c):s[i]=c}var u=!(!n||!n.shadow),r=e?R(He,{useFragment:!u},s):s;return!u&&e&&(t.innerHTML=""),R(e||t.nodeName.toLowerCase(),o,r)}var gt=0;function d(t,e,n,s,o,i){e||(e={});var a,_,c=e;if("ref"in c)for(_ in c={},e)_=="ref"?a=e[_]:c[_]=e[_];var l={type:t,props:c,key:n,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--gt,__i:-1,__u:0,__source:o,__self:i};if(typeof t=="function"&&(a=t.defaultProps))for(_ in a)c[_]===void 0&&(c[_]=a[_]);return m.vnode&&m.vnode(l),l}var j,y,ce,Ie,Y=0,De=[],v=m,Le=v.__b,Oe=v.__r,Re=v.diffed,qe=v.__c,Be=v.unmount,Qe=v.__;function ue(t,e){v.__h&&v.__h(y,t,Y||e),Y=0;var n=y.__H||(y.__H={__:[],__h:[]});return t>=n.__.length&&n.__.push({}),n.__[t]}function E(t){return Y=1,ft(Je,t)}function ft(t,e,n){var s=ue(j++,2);if(s.t=t,!s.__c&&(s.__=[Je(void 0,e),function(_){var c=s.__N?s.__N[0]:s.__[0],l=s.t(c,_);c!==l&&(s.__N=[l,s.__[1]],s.__c.setState({}))}],s.__c=y,!y.__f)){var o=function(_,c,l){if(!s.__c.__H)return!0;var u=s.__c.__H.__.filter(function(g){return!!g.__c});if(u.every(function(g){return!g.__N}))return!i||i.call(this,_,c,l);var r=s.__c.props!==_;return u.forEach(function(g){if(g.__N){var h=g.__[0];g.__=g.__N,g.__N=void 0,h!==g.__[0]&&(r=!0)}}),i&&i.call(this,_,c,l)||r};y.__f=!0;var i=y.shouldComponentUpdate,a=y.componentWillUpdate;y.componentWillUpdate=function(_,c,l){if(this.__e){var u=i;i=void 0,o(_,c,l),i=u}a&&a.call(this,_,c,l)},y.shouldComponentUpdate=o}return s.__N||s.__}function je(t,e){var n=ue(j++,3);!v.__s&&Ke(n.__H,e)&&(n.__=t,n.u=e,y.__H.__h.push(n))}function ze(t){return Y=5,pt(function(){return{current:t}},[])}function pt(t,e){var n=ue(j++,7);return Ke(n.__H,e)&&(n.__=t(),n.__H=e,n.__h=t),n.__}function mt(){for(var t;t=De.shift();)if(t.__P&&t.__H)try{t.__H.__h.forEach(Z),t.__H.__h.forEach(he),t.__H.__h=[]}catch(e){t.__H.__h=[],v.__e(e,t.__v)}}v.__b=function(t){y=null,Le&&Le(t)},v.__=function(t,e){t&&e.__k&&e.__k.__m&&(t.__m=e.__k.__m),Qe&&Qe(t,e)},v.__r=function(t){Oe&&Oe(t),j=0;var e=(y=t.__c).__H;e&&(ce===y?(e.__h=[],y.__h=[],e.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(e.__h.forEach(Z),e.__h.forEach(he),e.__h=[],j=0)),ce=y},v.diffed=function(t){Re&&Re(t);var e=t.__c;e&&e.__H&&(e.__H.__h.length&&(De.push(e)!==1&&Ie===v.requestAnimationFrame||((Ie=v.requestAnimationFrame)||yt)(mt)),e.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),ce=y=null},v.__c=function(t,e){e.some(function(n){try{n.__h.forEach(Z),n.__h=n.__h.filter(function(s){return!s.__||he(s)})}catch(s){e.some(function(o){o.__h&&(o.__h=[])}),e=[],v.__e(s,n.__v)}}),qe&&qe(t,e)},v.unmount=function(t){Be&&Be(t);var e,n=t.__c;n&&n.__H&&(n.__H.__.forEach(function(s){try{Z(s)}catch(o){e=o}}),n.__H=void 0,e&&v.__e(e,n.__v))};var Ve=typeof requestAnimationFrame=="function";function yt(t){var e,n=function(){clearTimeout(s),Ve&&cancelAnimationFrame(e),setTimeout(t)},s=setTimeout(n,35);Ve&&(e=requestAnimationFrame(n))}function Z(t){var e=y,n=t.__c;typeof n=="function"&&(t.__c=void 0,n()),y=e}function he(t){var e=y;t.__c=t.__(),y=e}function Ke(t,e){return!t||t.length!==e.length||e.some(function(n,s){return n!==t[s]})}function Je(t,e){return typeof e=="function"?e(t):e}const vt="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let de=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t|=0));for(;t--;)e+=vt[n[t]&63];return e};class Ge{constructor(e,n){this.agentUrl=e,this.agentId=n,this.agentConfig=null,this.ws=null,this.messageCallbacks=new Set,this.suggestionsCallbacks=new Set,this.connectionCallbacks=new Set,this.streamingCallbacks=new Set,this.processingCallbacks=new Set,this.queueCallbacks=new Set,this.messages=[],this.activeSuggestions=[],this.reconnectAttempts=0,this.maxReconnectAttempts=5,this.reconnectDelay=1e3,this.isAgentStreaming=!1,this.isAgentProcessing=!1,this.messageQueue=[],this.disposed=!1}async initWidget(){try{try{const s=await fetch(`${this.normalizeBaseUrl(this.agentUrl)}/api/agent/${this.agentId}`);if(s.ok){const o=await s.json();return!o||o.status!=="active"?(console.error("Agent not found or inactive"),null):(this.agentConfig=o,this.maxReconnectAttempts=o.config.maxRetries||5,this.reconnectDelay=o.config.reconnectDelay||1e3,await this.connectToAgent(),o)}}catch{console.warn("[AriaFlow Widget] Agent config endpoint not available, trying fallback")}const e=this.toWebSocketBaseUrl(this.normalizeBaseUrl(this.agentUrl)),n={id:this.agentId,name:this.agentId==="hospital"?"Hospital Support":"Support Agent",wsUrl:`${e}/agents/chat`,status:"active",capabilities:["chat","streaming"],config:{primaryColor:"#14B8A6",position:"bottom-right",theme:"light",title:this.agentId==="hospital"?"Hospital Support":"Chat Support",subtitle:"We're here to help!",maxRetries:3,reconnectDelay:1e3}};return this.agentConfig=n,await this.connectToAgent(),n}catch(e){return console.error("Failed to initialize widget:",e),null}}async connectToAgent(){if(!this.agentConfig?.wsUrl)throw new Error("No agent WebSocket URL configured");if(this.disposed)return;const e=this.getSessionId(),n=`${this.normalizeBaseUrl(this.agentConfig.wsUrl)}/${e}`;return new Promise((s,o)=>{try{this.ws=new WebSocket(n),this.ws.onopen=()=>{console.log("[Widget] Connected to agent"),this.reconnectAttempts=0,this.notifyConnectionChange(!0),s()},this.ws.onmessage=i=>{this.handleMessage(i)},this.ws.onclose=()=>{if(this.ws=null,this.notifyConnectionChange(!1),!this.disposed&&this.reconnectAttempts<this.maxReconnectAttempts){this.reconnectAttempts++;const i=this.reconnectDelay*Math.pow(2,this.reconnectAttempts-1);console.log(`[Widget] Reconnecting in ${i}ms... (attempt ${this.reconnectAttempts})`),setTimeout(()=>this.connectToAgent(),i)}},this.ws.onerror=i=>{console.error("[Widget] WebSocket error:",i),o(i)}}catch(i){o(i)}})}onProcessingChange(e){return this.processingCallbacks.add(e),()=>{this.processingCallbacks.delete(e)}}notifyProcessingChange(e){this.isAgentProcessing=e,this.processingCallbacks.forEach(n=>n(e))}handleMessage(e){try{const n=JSON.parse(e.data);if(n.type==="connected")this.notifyConnectionChange(!0);else if(n.type==="text-delta")this.isAgentProcessing&&this.notifyProcessingChange(!1),this.setMessages(s=>{const o=s[s.length-1];return o&&o.role==="assistant"&&o.isStreaming?[...s.slice(0,-1),{...o,content:o.content+n.text}]:[...s,{id:de(),role:"assistant",content:n.text,timestamp:Date.now(),isStreaming:!0}]});else if(n.type==="done")this.notifyProcessingChange(!1),this.setMessages(s=>{const o=s[s.length-1];return o&&o.role==="assistant"&&o.isStreaming?[...s.slice(0,-1),{...o,isStreaming:!1}]:s}),this.isAgentStreaming=!1,this.notifyStreamingChange(!1),this.processMessageQueue();else if(n.type==="step-start"||n.type==="agent-start")this.isAgentStreaming=!0,this.notifyStreamingChange(!0),this.notifyProcessingChange(!0);else if(n.type==="step-end"||n.type==="agent-end")n.type==="agent-end"&&this.notifyProcessingChange(!1);else if(n.type==="tool-call"){const s=n.tool?.name||n.toolName,o=n.tool?.arguments||n.args;this.notifyProcessingChange(!0),s==="suggest_options"&&o?.options&&this.setActiveSuggestions(o.options)}else n.type==="tool-result"||n.type==="handoff"||(n.type==="suggested-questions"?this.setActiveSuggestions(n.suggestions):n.type==="error"||n.type==="interrupted"?(this.notifyProcessingChange(!1),this.isAgentStreaming=!1,this.notifyStreamingChange(!1)):n.type==="cancelled"?this.notifyProcessingChange(!1):console.log("[Widget] Unknown message type:",n.type))}catch(n){console.error("[Widget] Error parsing message:",e.data,n)}}async sendMessage(e){if(!this.ws||this.ws.readyState!==WebSocket.OPEN)throw new Error("Not connected to agent");this.setActiveSuggestions([]);const n={id:de(),role:"user",content:e,timestamp:Date.now()};if(this.setMessages(s=>[...s,n]),this.isAgentStreaming){console.log("[Widget] Agent is streaming, queuing message"),this.messageQueue.push(e),this.notifyQueueChange(this.messageQueue.length);return}this.sendToAgent(e)}async sendToAgent(e){const n=this.getSessionId();this.ws.send(JSON.stringify({message:e,sessionId:n}))}async processMessageQueue(){if(this.messageQueue.length!==0){if(this.messageQueue.length===1){const e=this.messageQueue.shift();console.log("[Widget] Sending queued message:",e),this.sendToAgent(e)}else{const e=this.messageQueue.join(`
|
|
1
|
+
(function(I,F){typeof exports=="object"&&typeof module<"u"?F(exports):typeof define=="function"&&define.amd?define(["exports"],F):(I=typeof globalThis<"u"?globalThis:I||self,F(I.AriaFlowWidget={}))})(this,function(I){"use strict";var F,m,ve,E,we,be,Ce,oe,z,q,ke,re,ae,le,j={},V=[],it=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,K=Array.isArray;function x(t,e){for(var n in e)t[n]=e[n];return t}function _e(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function R(t,e,n){var i,o,s,a={};for(s in e)s=="key"?i=e[s]:s=="ref"?o=e[s]:a[s]=e[s];if(arguments.length>2&&(a.children=arguments.length>3?F.call(arguments,2):n),typeof t=="function"&&t.defaultProps!=null)for(s in t.defaultProps)a[s]===void 0&&(a[s]=t.defaultProps[s]);return B(t,a,i,o,null)}function B(t,e,n,i,o){var s={type:t,props:e,key:n,ref:i,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:o??++ve,__i:-1,__u:0};return o==null&&m.vnode!=null&&m.vnode(s),s}function D(t){return t.children}function J(t,e){this.props=t,this.context=e}function L(t,e){if(e==null)return t.__?L(t.__,t.__i+1):null;for(var n;e<t.__k.length;e++)if((n=t.__k[e])!=null&&n.__e!=null)return n.__e;return typeof t.type=="function"?L(t):null}function ot(t){if(t.__P&&t.__d){var e=t.__v,n=e.__e,i=[],o=[],s=x({},e);s.__v=e.__v+1,m.vnode&&m.vnode(s),ce(t.__P,s,e,t.__n,t.__P.namespaceURI,32&e.__u?[n]:null,i,n??L(e),!!(32&e.__u),o),s.__v=e.__v,s.__.__k[s.__i]=s,We(i,s,o),e.__e=e.__=null,s.__e!=n&&Se(s)}}function Se(t){if((t=t.__)!=null&&t.__c!=null)return t.__e=t.__c.base=null,t.__k.some(function(e){if(e!=null&&e.__e!=null)return t.__e=t.__c.base=e.__e}),Se(t)}function Ae(t){(!t.__d&&(t.__d=!0)&&E.push(t)&&!G.__r++||we!=m.debounceRendering)&&((we=m.debounceRendering)||be)(G)}function G(){try{for(var t,e=1;E.length;)E.length>e&&E.sort(Ce),t=E.shift(),e=E.length,ot(t)}finally{E.length=G.__r=0}}function $e(t,e,n,i,o,s,a,_,c,l,u){var r,g,h,w,k,b,p,f=i&&i.__k||V,W=e.length;for(c=rt(n,e,f,c,W),r=0;r<W;r++)(h=n.__k[r])!=null&&(g=h.__i!=-1&&f[h.__i]||j,h.__i=r,b=ce(t,h,g,o,s,a,_,c,l,u),w=h.__e,h.ref&&g.ref!=h.ref&&(g.ref&&he(g.ref,null,h),u.push(h.ref,h.__c||w,h)),k==null&&w!=null&&(k=w),(p=!!(4&h.__u))||g.__k===h.__k?(c=Ne(h,c,t,p),p&&g.__e&&(g.__e=null)):typeof h.type=="function"&&b!==void 0?c=b:w&&(c=w.nextSibling),h.__u&=-7);return n.__e=k,c}function rt(t,e,n,i,o){var s,a,_,c,l,u=n.length,r=u,g=0;for(t.__k=new Array(o),s=0;s<o;s++)(a=e[s])!=null&&typeof a!="boolean"&&typeof a!="function"?(typeof a=="string"||typeof a=="number"||typeof a=="bigint"||a.constructor==String?a=t.__k[s]=B(null,a,null,null,null):K(a)?a=t.__k[s]=B(D,{children:a},null,null,null):a.constructor===void 0&&a.__b>0?a=t.__k[s]=B(a.type,a.props,a.key,a.ref?a.ref:null,a.__v):t.__k[s]=a,c=s+g,a.__=t,a.__b=t.__b+1,_=null,(l=a.__i=at(a,n,c,r))!=-1&&(r--,(_=n[l])&&(_.__u|=2)),_==null||_.__v==null?(l==-1&&(o>u?g--:o<u&&g++),typeof a.type!="function"&&(a.__u|=4)):l!=c&&(l==c-1?g--:l==c+1?g++:(l>c?g--:g++,a.__u|=4))):t.__k[s]=null;if(r)for(s=0;s<u;s++)(_=n[s])!=null&&!(2&_.__u)&&(_.__e==i&&(i=L(_)),Te(_,_));return i}function Ne(t,e,n,i){var o,s;if(typeof t.type=="function"){for(o=t.__k,s=0;o&&s<o.length;s++)o[s]&&(o[s].__=t,e=Ne(o[s],e,n,i));return e}t.__e!=e&&(i&&(e&&t.type&&!e.parentNode&&(e=L(t)),n.insertBefore(t.__e,e||null)),e=t.__e);do e=e&&e.nextSibling;while(e!=null&&e.nodeType==8);return e}function at(t,e,n,i){var o,s,a,_=t.key,c=t.type,l=e[n],u=l!=null&&(2&l.__u)==0;if(l===null&&_==null||u&&_==l.key&&c==l.type)return n;if(i>(u?1:0)){for(o=n-1,s=n+1;o>=0||s<e.length;)if((l=e[a=o>=0?o--:s++])!=null&&!(2&l.__u)&&_==l.key&&c==l.type)return a}return-1}function xe(t,e,n){e[0]=="-"?t.setProperty(e,n??""):t[e]=n==null?"":typeof n!="number"||it.test(e)?n:n+"px"}function X(t,e,n,i,o){var s,a;e:if(e=="style")if(typeof n=="string")t.style.cssText=n;else{if(typeof i=="string"&&(t.style.cssText=i=""),i)for(e in i)n&&e in n||xe(t.style,e,"");if(n)for(e in n)i&&n[e]==i[e]||xe(t.style,e,n[e])}else if(e[0]=="o"&&e[1]=="n")s=e!=(e=e.replace(ke,"$1")),a=e.toLowerCase(),e=a in t||e=="onFocusOut"||e=="onFocusIn"?a.slice(2):e.slice(2),t.l||(t.l={}),t.l[e+s]=n,n?i?n[q]=i[q]:(n[q]=re,t.addEventListener(e,s?le:ae,s)):t.removeEventListener(e,s?le:ae,s);else{if(o=="http://www.w3.org/2000/svg")e=e.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(e!="width"&&e!="height"&&e!="href"&&e!="list"&&e!="form"&&e!="tabIndex"&&e!="download"&&e!="rowSpan"&&e!="colSpan"&&e!="role"&&e!="popover"&&e in t)try{t[e]=n??"";break e}catch{}typeof n=="function"||(n==null||n===!1&&e[4]!="-"?t.removeAttribute(e):t.setAttribute(e,e=="popover"&&n==1?"":n))}}function Pe(t){return function(e){if(this.l){var n=this.l[e.type+t];if(e[z]==null)e[z]=re++;else if(e[z]<n[q])return;return n(m.event?m.event(e):e)}}}function ce(t,e,n,i,o,s,a,_,c,l){var u,r,g,h,w,k,b,p,f,W,S,H,M,O,A,$=e.type;if(e.constructor!==void 0)return null;128&n.__u&&(c=!!(32&n.__u),s=[_=e.__e=n.__e]),(u=m.__b)&&u(e);e:if(typeof $=="function")try{if(p=e.props,f=$.prototype&&$.prototype.render,W=(u=$.contextType)&&i[u.__c],S=u?W?W.props.value:u.__:i,n.__c?b=(r=e.__c=n.__c).__=r.__E:(f?e.__c=r=new $(p,S):(e.__c=r=new J(p,S),r.constructor=$,r.render=_t),W&&W.sub(r),r.state||(r.state={}),r.__n=i,g=r.__d=!0,r.__h=[],r._sb=[]),f&&r.__s==null&&(r.__s=r.state),f&&$.getDerivedStateFromProps!=null&&(r.__s==r.state&&(r.__s=x({},r.__s)),x(r.__s,$.getDerivedStateFromProps(p,r.__s))),h=r.props,w=r.state,r.__v=e,g)f&&$.getDerivedStateFromProps==null&&r.componentWillMount!=null&&r.componentWillMount(),f&&r.componentDidMount!=null&&r.__h.push(r.componentDidMount);else{if(f&&$.getDerivedStateFromProps==null&&p!==h&&r.componentWillReceiveProps!=null&&r.componentWillReceiveProps(p,S),e.__v==n.__v||!r.__e&&r.shouldComponentUpdate!=null&&r.shouldComponentUpdate(p,r.__s,S)===!1){e.__v!=n.__v&&(r.props=p,r.state=r.__s,r.__d=!1),e.__e=n.__e,e.__k=n.__k,e.__k.some(function(T){T&&(T.__=e)}),V.push.apply(r.__h,r._sb),r._sb=[],r.__h.length&&a.push(r);break e}r.componentWillUpdate!=null&&r.componentWillUpdate(p,r.__s,S),f&&r.componentDidUpdate!=null&&r.__h.push(function(){r.componentDidUpdate(h,w,k)})}if(r.context=S,r.props=p,r.__P=t,r.__e=!1,H=m.__r,M=0,f)r.state=r.__s,r.__d=!1,H&&H(e),u=r.render(r.props,r.state,r.context),V.push.apply(r.__h,r._sb),r._sb=[];else do r.__d=!1,H&&H(e),u=r.render(r.props,r.state,r.context),r.state=r.__s;while(r.__d&&++M<25);r.state=r.__s,r.getChildContext!=null&&(i=x(x({},i),r.getChildContext())),f&&!g&&r.getSnapshotBeforeUpdate!=null&&(k=r.getSnapshotBeforeUpdate(h,w)),O=u!=null&&u.type===D&&u.key==null?Me(u.props.children):u,_=$e(t,K(O)?O:[O],e,n,i,o,s,a,_,c,l),r.base=e.__e,e.__u&=-161,r.__h.length&&a.push(r),b&&(r.__E=r.__=null)}catch(T){if(e.__v=null,c||s!=null)if(T.then){for(e.__u|=c?160:128;_&&_.nodeType==8&&_.nextSibling;)_=_.nextSibling;s[s.indexOf(_)]=null,e.__e=_}else{for(A=s.length;A--;)_e(s[A]);ue(e)}else e.__e=n.__e,e.__k=n.__k,T.then||ue(e);m.__e(T,e,n)}else s==null&&e.__v==n.__v?(e.__k=n.__k,e.__e=n.__e):_=e.__e=lt(n.__e,e,n,i,o,s,a,c,l);return(u=m.diffed)&&u(e),128&e.__u?void 0:_}function ue(t){t&&(t.__c&&(t.__c.__e=!0),t.__k&&t.__k.some(ue))}function We(t,e,n){for(var i=0;i<n.length;i++)he(n[i],n[++i],n[++i]);m.__c&&m.__c(e,t),t.some(function(o){try{t=o.__h,o.__h=[],t.some(function(s){s.call(o)})}catch(s){m.__e(s,o.__v)}})}function Me(t){return typeof t!="object"||t==null||t.__b>0?t:K(t)?t.map(Me):x({},t)}function lt(t,e,n,i,o,s,a,_,c){var l,u,r,g,h,w,k,b=n.props||j,p=e.props,f=e.type;if(f=="svg"?o="http://www.w3.org/2000/svg":f=="math"?o="http://www.w3.org/1998/Math/MathML":o||(o="http://www.w3.org/1999/xhtml"),s!=null){for(l=0;l<s.length;l++)if((h=s[l])&&"setAttribute"in h==!!f&&(f?h.localName==f:h.nodeType==3)){t=h,s[l]=null;break}}if(t==null){if(f==null)return document.createTextNode(p);t=document.createElementNS(o,f,p.is&&p),_&&(m.__m&&m.__m(e,s),_=!1),s=null}if(f==null)b===p||_&&t.data==p||(t.data=p);else{if(s=s&&F.call(t.childNodes),!_&&s!=null)for(b={},l=0;l<t.attributes.length;l++)b[(h=t.attributes[l]).name]=h.value;for(l in b)h=b[l],l=="dangerouslySetInnerHTML"?r=h:l=="children"||l in p||l=="value"&&"defaultValue"in p||l=="checked"&&"defaultChecked"in p||X(t,l,null,h,o);for(l in p)h=p[l],l=="children"?g=h:l=="dangerouslySetInnerHTML"?u=h:l=="value"?w=h:l=="checked"?k=h:_&&typeof h!="function"||b[l]===h||X(t,l,h,b[l],o);if(u)_||r&&(u.__html==r.__html||u.__html==t.innerHTML)||(t.innerHTML=u.__html),e.__k=[];else if(r&&(t.innerHTML=""),$e(e.type=="template"?t.content:t,K(g)?g:[g],e,n,i,f=="foreignObject"?"http://www.w3.org/1999/xhtml":o,s,a,s?s[0]:n.__k&&L(n,0),_,c),s!=null)for(l=s.length;l--;)_e(s[l]);_||(l="value",f=="progress"&&w==null?t.removeAttribute("value"):w!=null&&(w!==t[l]||f=="progress"&&!w||f=="option"&&w!=b[l])&&X(t,l,w,b[l],o),l="checked",k!=null&&k!=t[l]&&X(t,l,k,b[l],o))}return t}function he(t,e,n){try{if(typeof t=="function"){var i=typeof t.__u=="function";i&&t.__u(),i&&e==null||(t.__u=t(e))}else t.current=e}catch(o){m.__e(o,n)}}function Te(t,e,n){var i,o;if(m.unmount&&m.unmount(t),(i=t.ref)&&(i.current&&i.current!=t.__e||he(i,null,e)),(i=t.__c)!=null){if(i.componentWillUnmount)try{i.componentWillUnmount()}catch(s){m.__e(s,e)}i.base=i.__P=null}if(i=t.__k)for(o=0;o<i.length;o++)i[o]&&Te(i[o],e,n||typeof t.type!="function");n||_e(t.__e),t.__c=t.__=t.__e=void 0}function _t(t,e,n){return this.constructor(t,n)}function Y(t,e,n){var i,o,s,a;e==document&&(e=document.documentElement),m.__&&m.__(t,e),o=(i=typeof n=="function")?null:n&&n.__k||e.__k,s=[],a=[],ce(e,t=(!i&&n||e).__k=R(D,null,[t]),o||j,j,e.namespaceURI,!i&&n?[n]:o?null:e.firstChild?F.call(e.childNodes):null,s,!i&&n?n:o?o.__e:e.firstChild,i,a),We(s,t,a)}function Ue(t,e){Y(t,e,Ue)}function Fe(t,e,n){var i,o,s,a,_=x({},t.props);for(s in t.type&&t.type.defaultProps&&(a=t.type.defaultProps),e)s=="key"?i=e[s]:s=="ref"?o=e[s]:_[s]=e[s]===void 0&&a!=null?a[s]:e[s];return arguments.length>2&&(_.children=arguments.length>3?F.call(arguments,2):n),B(t.type,_,i||t.key,o||t.ref,null)}F=V.slice,m={__e:function(t,e,n,i){for(var o,s,a;e=e.__;)if((o=e.__c)&&!o.__)try{if((s=o.constructor)&&s.getDerivedStateFromError!=null&&(o.setState(s.getDerivedStateFromError(t)),a=o.__d),o.componentDidCatch!=null&&(o.componentDidCatch(t,i||{}),a=o.__d),a)return o.__E=o}catch(_){t=_}throw t}},ve=0,J.prototype.setState=function(t,e){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=x({},this.state),typeof t=="function"&&(t=t(x({},n),this.props)),t&&x(n,t),t!=null&&this.__v&&(e&&this._sb.push(e),Ae(this))},J.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),Ae(this))},J.prototype.render=D,E=[],be=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,Ce=function(t,e){return t.__v.__b-e.__v.__b},G.__r=0,oe=Math.random().toString(8),z="__d"+oe,q="__a"+oe,ke=/(PointerCapture)$|Capture$/i,re=0,ae=Pe(!1),le=Pe(!0);function Z(){return Z=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},Z.apply(this,arguments)}function Ee(t,e){if(t==null)return{};var n,i,o={},s=Object.keys(t);for(i=0;i<s.length;i++)e.indexOf(n=s[i])>=0||(o[n]=t[n]);return o}var ct=["context","children"],ut=["useFragment"];function ht(t,e,n,i){function o(){var s,a=Reflect.construct(HTMLElement,[],o);return a._vdomComponent=t,i&&i.shadow?(a._root=a.attachShadow({mode:i.mode||"open",serializable:(s=i.serializable)!=null&&s}),i.adoptedStyleSheets&&(a._root.adoptedStyleSheets=i.adoptedStyleSheets)):a._root=a,a}return(o.prototype=Object.create(HTMLElement.prototype)).constructor=o,o.prototype.connectedCallback=function(){gt.call(this,i)},o.prototype.attributeChangedCallback=ft,o.prototype.disconnectedCallback=pt,n=n||t.observedAttributes||Object.keys(t.propTypes||{}),o.observedAttributes=n,t.formAssociated&&(o.formAssociated=!0),n.forEach(function(s){Object.defineProperty(o.prototype,s,{get:function(){return this._vdom?this._vdom.props[s]:this._props[s]},set:function(a){this._vdom?this.attributeChangedCallback(s,null,a):(this._props||(this._props={}),this._props[s]=a);var _=typeof a;a!=null&&_!=="string"&&_!=="boolean"&&_!=="number"||this.setAttribute(s,a)}})}),customElements.define(e,o),o}function dt(t){this.getChildContext=function(){return t.context};var e=t.children,n=Ee(t,ct);return Fe(e,n)}function gt(t){var e=new CustomEvent("_preact",{detail:{},bubbles:!0,cancelable:!0});this.dispatchEvent(e),this._vdom=R(dt,Z({},this._props,{context:e.detail.context}),De(this,this._vdomComponent,t)),(this.hasAttribute("hydrate")?Ue:Y)(this._vdom,this._root)}function He(t){return t.replace(/-(\w)/g,function(e,n){return n?n.toUpperCase():""})}function ft(t,e,n){if(this._vdom){var i={};i[t]=n=n??void 0,i[He(t)]=n,this._vdom=Fe(this._vdom,i),Y(this._vdom,this._root)}}function pt(){Y(this._vdom=null,this._root)}function Ie(t,e){var n=this,i=t.useFragment,o=Ee(t,ut);return R(i?D:"slot",Z({},o,{ref:function(s){s?(n.ref=s,n._listener||(n._listener=function(a){a.stopPropagation(),a.detail.context=e},s.addEventListener("_preact",n._listener))):n.ref.removeEventListener("_preact",n._listener)}}))}function De(t,e,n){if(t.nodeType===3)return t.data;if(t.nodeType!==1)return null;var i=[],o={},s=0,a=t.attributes,_=t.childNodes;for(s=a.length;s--;)a[s].name!=="slot"&&(o[a[s].name]=a[s].value,o[He(a[s].name)]=a[s].value);for(s=_.length;s--;){var c=De(_[s],null,n),l=_[s].slot;l?o[l]=R(Ie,{name:l},c):i[s]=c}var u=!(!n||!n.shadow),r=e?R(Ie,{useFragment:!u},i):i;return!u&&e&&(t.innerHTML=""),R(e||t.nodeName.toLowerCase(),o,r)}var mt=0;function d(t,e,n,i,o,s){e||(e={});var a,_,c=e;if("ref"in c)for(_ in c={},e)_=="ref"?a=e[_]:c[_]=e[_];var l={type:t,props:c,key:n,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--mt,__i:-1,__u:0,__source:o,__self:s};if(typeof t=="function"&&(a=t.defaultProps))for(_ in a)c[_]===void 0&&(c[_]=a[_]);return m.vnode&&m.vnode(l),l}var Q,y,de,Re,ee=0,Le=[],v=m,Oe=v.__b,qe=v.__r,Be=v.diffed,Qe=v.__c,ze=v.unmount,je=v.__;function ge(t,e){v.__h&&v.__h(y,t,ee||e),ee=0;var n=y.__H||(y.__H={__:[],__h:[]});return t>=n.__.length&&n.__.push({}),n.__[t]}function P(t){return ee=1,yt(Xe,t)}function yt(t,e,n){var i=ge(Q++,2);if(i.t=t,!i.__c&&(i.__=[Xe(void 0,e),function(_){var c=i.__N?i.__N[0]:i.__[0],l=i.t(c,_);c!==l&&(i.__N=[l,i.__[1]],i.__c.setState({}))}],i.__c=y,!y.__f)){var o=function(_,c,l){if(!i.__c.__H)return!0;var u=i.__c.__H.__.filter(function(g){return g.__c});if(u.every(function(g){return!g.__N}))return!s||s.call(this,_,c,l);var r=i.__c.props!==_;return u.some(function(g){if(g.__N){var h=g.__[0];g.__=g.__N,g.__N=void 0,h!==g.__[0]&&(r=!0)}}),s&&s.call(this,_,c,l)||r};y.__f=!0;var s=y.shouldComponentUpdate,a=y.componentWillUpdate;y.componentWillUpdate=function(_,c,l){if(this.__e){var u=s;s=void 0,o(_,c,l),s=u}a&&a.call(this,_,c,l)},y.shouldComponentUpdate=o}return i.__N||i.__}function Ve(t,e){var n=ge(Q++,3);!v.__s&&Ge(n.__H,e)&&(n.__=t,n.u=e,y.__H.__h.push(n))}function Ke(t){return ee=5,vt(function(){return{current:t}},[])}function vt(t,e){var n=ge(Q++,7);return Ge(n.__H,e)&&(n.__=t(),n.__H=e,n.__h=t),n.__}function wt(){for(var t;t=Le.shift();){var e=t.__H;if(t.__P&&e)try{e.__h.some(te),e.__h.some(fe),e.__h=[]}catch(n){e.__h=[],v.__e(n,t.__v)}}}v.__b=function(t){y=null,Oe&&Oe(t)},v.__=function(t,e){t&&e.__k&&e.__k.__m&&(t.__m=e.__k.__m),je&&je(t,e)},v.__r=function(t){qe&&qe(t),Q=0;var e=(y=t.__c).__H;e&&(de===y?(e.__h=[],y.__h=[],e.__.some(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(e.__h.some(te),e.__h.some(fe),e.__h=[],Q=0)),de=y},v.diffed=function(t){Be&&Be(t);var e=t.__c;e&&e.__H&&(e.__H.__h.length&&(Le.push(e)!==1&&Re===v.requestAnimationFrame||((Re=v.requestAnimationFrame)||bt)(wt)),e.__H.__.some(function(n){n.u&&(n.__H=n.u),n.u=void 0})),de=y=null},v.__c=function(t,e){e.some(function(n){try{n.__h.some(te),n.__h=n.__h.filter(function(i){return!i.__||fe(i)})}catch(i){e.some(function(o){o.__h&&(o.__h=[])}),e=[],v.__e(i,n.__v)}}),Qe&&Qe(t,e)},v.unmount=function(t){ze&&ze(t);var e,n=t.__c;n&&n.__H&&(n.__H.__.some(function(i){try{te(i)}catch(o){e=o}}),n.__H=void 0,e&&v.__e(e,n.__v))};var Je=typeof requestAnimationFrame=="function";function bt(t){var e,n=function(){clearTimeout(i),Je&&cancelAnimationFrame(e),setTimeout(t)},i=setTimeout(n,35);Je&&(e=requestAnimationFrame(n))}function te(t){var e=y,n=t.__c;typeof n=="function"&&(t.__c=void 0,n()),y=e}function fe(t){var e=y;t.__c=t.__(),y=e}function Ge(t,e){return!t||t.length!==e.length||e.some(function(n,i){return n!==t[i]})}function Xe(t,e){return typeof e=="function"?e(t):e}let Ct="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",pe=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t|=0));for(;t--;)e+=Ct[n[t]&63];return e};class Ye{constructor(e,n){this.agentUrl=e,this.agentId=n,this.agentConfig=null,this.ws=null,this.messageCallbacks=new Set,this.suggestionsCallbacks=new Set,this.connectionCallbacks=new Set,this.streamingCallbacks=new Set,this.processingCallbacks=new Set,this.queueCallbacks=new Set,this.messages=[],this.activeSuggestions=[],this.reconnectAttempts=0,this.maxReconnectAttempts=5,this.reconnectDelay=1e3,this.isAgentStreaming=!1,this.isAgentProcessing=!1,this.messageQueue=[],this.disposed=!1}async initWidget(){try{try{const i=await fetch(`${this.normalizeBaseUrl(this.agentUrl)}/api/agent/${this.agentId}`);if(i.ok){const o=await i.json();return!o||o.status!=="active"?(console.error("Agent not found or inactive"),null):(this.agentConfig=o,this.maxReconnectAttempts=o.config.maxRetries||5,this.reconnectDelay=o.config.reconnectDelay||1e3,await this.connectToAgent(),o)}}catch{console.warn("[AriaFlow Widget] Agent config endpoint not available, trying fallback")}const e=this.toWebSocketBaseUrl(this.normalizeBaseUrl(this.agentUrl)),n={id:this.agentId,name:this.agentId==="hospital"?"Hospital Support":"Support Agent",wsUrl:`${e}/agents/chat`,status:"active",capabilities:["chat","streaming"],config:{primaryColor:"#14B8A6",position:"bottom-right",theme:"light",title:this.agentId==="hospital"?"Hospital Support":"Chat Support",subtitle:"We're here to help!",maxRetries:3,reconnectDelay:1e3}};return this.agentConfig=n,await this.connectToAgent(),n}catch(e){return console.error("Failed to initialize widget:",e),null}}async connectToAgent(){if(!this.agentConfig?.wsUrl)throw new Error("No agent WebSocket URL configured");if(this.disposed)return;const e=this.getSessionId(),n=`${this.normalizeBaseUrl(this.agentConfig.wsUrl)}/${e}`;return new Promise((i,o)=>{try{this.ws=new WebSocket(n),this.ws.onopen=()=>{console.log("[Widget] Connected to agent"),this.reconnectAttempts=0,this.notifyConnectionChange(!0),i()},this.ws.onmessage=s=>{this.handleMessage(s)},this.ws.onclose=()=>{if(this.ws=null,this.notifyConnectionChange(!1),!this.disposed&&this.reconnectAttempts<this.maxReconnectAttempts){this.reconnectAttempts++;const s=this.reconnectDelay*Math.pow(2,this.reconnectAttempts-1);console.log(`[Widget] Reconnecting in ${s}ms... (attempt ${this.reconnectAttempts})`),setTimeout(()=>this.connectToAgent(),s)}},this.ws.onerror=s=>{console.error("[Widget] WebSocket error:",s),o(s)}}catch(s){o(s)}})}onProcessingChange(e){return this.processingCallbacks.add(e),()=>{this.processingCallbacks.delete(e)}}notifyProcessingChange(e){this.isAgentProcessing=e,this.processingCallbacks.forEach(n=>n(e))}handleMessage(e){try{const n=JSON.parse(e.data);if(n.type==="connected")this.notifyConnectionChange(!0);else if(n.type==="text-delta")this.isAgentProcessing&&this.notifyProcessingChange(!1),this.setMessages(i=>{const o=i[i.length-1];return o&&o.role==="assistant"&&o.isStreaming?[...i.slice(0,-1),{...o,content:o.content+n.text}]:[...i,{id:pe(),role:"assistant",content:n.text,timestamp:Date.now(),isStreaming:!0}]});else if(n.type==="done")this.notifyProcessingChange(!1),this.setMessages(i=>{const o=i[i.length-1];return o&&o.role==="assistant"&&o.isStreaming?[...i.slice(0,-1),{...o,isStreaming:!1}]:i}),this.isAgentStreaming=!1,this.notifyStreamingChange(!1),this.processMessageQueue();else if(n.type==="step-start"||n.type==="agent-start")this.isAgentStreaming=!0,this.notifyStreamingChange(!0),this.notifyProcessingChange(!0);else if(n.type==="step-end"||n.type==="agent-end")n.type==="agent-end"&&this.notifyProcessingChange(!1);else if(n.type==="tool-call"){const i=n.tool?.name||n.toolName,o=n.tool?.arguments||n.args;this.notifyProcessingChange(!0),i==="suggest_options"&&o?.options&&this.setActiveSuggestions(o.options)}else n.type==="tool-result"||n.type==="handoff"||(n.type==="suggested-questions"?this.setActiveSuggestions(n.suggestions):n.type==="error"||n.type==="interrupted"?(this.notifyProcessingChange(!1),this.isAgentStreaming=!1,this.notifyStreamingChange(!1)):n.type==="cancelled"?this.notifyProcessingChange(!1):console.log("[Widget] Unknown message type:",n.type))}catch(n){console.error("[Widget] Error parsing message:",e.data,n)}}async sendMessage(e){if(!this.ws||this.ws.readyState!==WebSocket.OPEN)throw new Error("Not connected to agent");this.setActiveSuggestions([]);const n={id:pe(),role:"user",content:e,timestamp:Date.now()};if(this.setMessages(i=>[...i,n]),this.isAgentStreaming){console.log("[Widget] Agent is streaming, queuing message"),this.messageQueue.push(e),this.notifyQueueChange(this.messageQueue.length);return}this.sendToAgent(e)}async sendToAgent(e){const n=this.getSessionId();this.ws.send(JSON.stringify({message:e,sessionId:n}))}async processMessageQueue(){if(this.messageQueue.length!==0){if(this.messageQueue.length===1){const e=this.messageQueue.shift();console.log("[Widget] Sending queued message:",e),this.sendToAgent(e)}else{const e=this.messageQueue.join(`
|
|
2
2
|
|
|
3
|
-
`);this.messageQueue.length=0,console.log("[Widget] Sending combined queued messages:",e),this.sendToAgent(e)}this.notifyQueueChange(this.messageQueue.length)}}getSessionId(){let e=sessionStorage.getItem("ariaflow_session_id");return e||(e=
|
|
3
|
+
`);this.messageQueue.length=0,console.log("[Widget] Sending combined queued messages:",e),this.sendToAgent(e)}this.notifyQueueChange(this.messageQueue.length)}}getSessionId(){let e=sessionStorage.getItem("ariaflow_session_id");return e||(e=pe(),sessionStorage.setItem("ariaflow_session_id",e)),e}setMessages(e){this.messages=e(this.messages),this.messageCallbacks.forEach(n=>n(this.messages))}onMessages(e){return this.messageCallbacks.add(e),e(this.messages),()=>{this.messageCallbacks.delete(e)}}onConnectionChange(e){return this.connectionCallbacks.add(e),()=>{this.connectionCallbacks.delete(e)}}onStreamingChange(e){return this.streamingCallbacks.add(e),()=>{this.streamingCallbacks.delete(e)}}onQueueChange(e){return this.queueCallbacks.add(e),()=>{this.queueCallbacks.delete(e)}}notifyConnectionChange(e){this.connectionCallbacks.forEach(n=>n(e))}notifyStreamingChange(e){this.streamingCallbacks.forEach(n=>n(e))}notifyQueueChange(e){this.queueCallbacks.forEach(n=>n(e))}onSuggestionsChange(e){return this.suggestionsCallbacks.add(e),e(this.activeSuggestions),()=>{this.suggestionsCallbacks.delete(e)}}setActiveSuggestions(e){const n=Array.isArray(e)?e.filter(o=>typeof o=="string").map(o=>o.trim()).filter(Boolean):[],i=[...new Set(n)];this.activeSuggestions=i,this.suggestionsCallbacks.forEach(o=>o(i))}normalizeBaseUrl(e){return e.replace(/\/+$/,"")}toWebSocketBaseUrl(e){try{const n=new URL(e);return n.protocol==="https:"?n.protocol="wss:":n.protocol==="http:"&&(n.protocol="ws:"),n.toString().replace(/\/+$/,"")}catch{return e.replace(/^https:\/\//,"wss://").replace(/^http:\/\//,"ws://").replace(/\/+$/,"")}}getMessages(){return this.messages}getConfig(){return this.agentConfig}isConnected(){return this.ws?.readyState===WebSocket.OPEN}dispose(){this.disposed=!0,this.ws&&(this.ws.close(),this.ws=null),this.messageCallbacks.clear(),this.suggestionsCallbacks.clear(),this.connectionCallbacks.clear(),this.streamingCallbacks.clear(),this.processingCallbacks.clear(),this.queueCallbacks.clear()}}const me={none:"0",small:"0.375rem",medium:"0.75rem",large:"1rem"};function Ze({agentUrl:t,agentId:e,widgetId:n,apiUrl:i,mode:o="chat",theme:s="light",position:a="bottom-right",size:_="full",radius:c="medium",baseColor:l,accentColor:u="#14B8A6",buttonBaseColor:r="#000000",buttonAccentColor:g="#FFFFFF",title:h,subtitle:w,emptyChatMessage:k}){const[b,p]=P(!1),[f,W]=P([]),[S,H]=P(""),[M,O]=P(!1),[A,$]=P(!1),[T,kt]=P(null),[ne,St]=P(!1),[At,$t]=P(!1),[ye,Nt]=P(0),[tt,xt]=P([]),se=Ke(null),nt=Ke(null);Ve(()=>((async()=>{if(t&&e){const U=new Ye(t,e);se.current=U;try{U.onMessages(N=>W(N)),U.onConnectionChange(N=>{O(N),N&&$(!0)}),U.onStreamingChange(N=>St(N)),U.onQueueChange(N=>Nt(N)),U.onProcessingChange(N=>$t(N)),U.onSuggestionsChange(N=>xt(N));const ie=await U.initWidget();ie?kt(ie):console.error("[AriaFlow Widget] Agent config fetch failed")}catch(ie){console.error("[AriaFlow Widget] Initialization error:",ie)}}else t&&!e?(console.warn("[AriaFlow Widget] Direct WebSocket URLs are deprecated. Use agent-url + agent-id instead."),console.error("[AriaFlow Widget] Configuration error: agent-id is required")):i&&n?(console.warn("[AriaFlow Widget] Legacy widget config is deprecated. Use agent-url + agent-id instead."),console.error("[AriaFlow Widget] Configuration error: use agent-url + agent-id instead")):console.error("[AriaFlow Widget] Invalid configuration. Provide agent-url and agent-id.")})(),()=>{se.current?.dispose()}),[t,e,n,i]),Ve(()=>{nt.current?.scrollIntoView({behavior:"smooth"})},[f]);const st=async()=>{if(!S.trim()||!M)return;const C=S.trim();H("");try{await se.current?.sendMessage(C)}catch(U){console.error("Failed to send message:",U)}},Pt=C=>{C.key==="Enter"&&!C.shiftKey&&(C.preventDefault(),st())},Wt=C=>{!M||ne||se.current?.sendMessage(C)},Mt=h||T?.config.title||"Ninewells Hospital",Tt=w||T?.config.subtitle||"How can we help you today?",Ut=k||T?.config.emptyChatMessage||"Start a conversation with Ninewells...";return d("div",{className:`ariaflow-widget-container ariaflow-widget-${a} ariaflow-widget-${_} ariaflow-widget-radius-${c}`,"data-theme":s,style:{"--ariaflow-accent-color":u,"--ariaflow-base-color":l},children:[!b&&d("button",{className:"ariaflow-widget-launcher",onClick:()=>p(!0),style:{backgroundColor:r,color:g,opacity:A?1:.8,cursor:A?"pointer":"wait",position:"relative"},"aria-label":A?"Open chat":"Connecting to agent...",disabled:!A,title:A?"Click to start chat":"Connecting to agent...",children:[!A&&d("div",{className:"ariaflow-widget-launcher-loading",style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"20px",height:"20px",border:`2px solid ${g}`,borderTop:"2px solid transparent",borderRadius:"50%",animation:"spin 1s linear infinite"}}),A&&d("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",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"})})]}),b&&A&&d("div",{className:"ariaflow-widget-window",style:{backgroundColor:s==="dark"&&l?l:void 0,borderRadius:me[c]},children:[d("div",{className:"ariaflow-widget-header",style:{backgroundColor:u,borderRadius:c==="none"?"0":`${me[c]} ${me[c]} 0 0`},children:[d("div",{className:"ariaflow-widget-header-content",children:d("div",{className:"ariaflow-widget-title-group",children:[d("h3",{className:"ariaflow-widget-title",children:Mt}),d("p",{className:"ariaflow-widget-subtitle",children:Tt})]})}),d("button",{className:"ariaflow-widget-close",onClick:()=>p(!1),"aria-label":"Close chat",children:d("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[d("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),d("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),!M&&d("div",{className:"ariaflow-widget-status",children:[d("span",{className:"ariaflow-widget-status-dot"}),"Connecting..."]}),d("div",{className:"ariaflow-widget-messages",children:f.length===0?d("div",{className:"ariaflow-widget-empty",children:d("p",{children:M?Ut:"Connecting to agent..."})}):d(D,{children:[f.map(C=>C.role==="tool"?null:d("div",{className:`ariaflow-widget-message ariaflow-widget-message-${C.role}`,children:d("div",{className:"ariaflow-widget-message-bubble",children:d(D,{children:[C.content,C.isStreaming&&d("span",{className:"ariaflow-widget-typing-indicator",children:[d("span",{children:"•"}),d("span",{children:"•"}),d("span",{children:"•"})]})]})})},C.id)),d("div",{ref:nt}),At&&!ne&&d("div",{className:"ariaflow-widget-message ariaflow-widget-message-assistant",children:d("div",{className:"ariaflow-widget-message-bubble",children:d("span",{className:"ariaflow-widget-typing-indicator",children:[d("span",{children:"•"}),d("span",{children:"•"}),d("span",{children:"•"})]})})})]})}),!ne&&tt.length>0&&d("div",{className:"ariaflow-widget-suggestions",children:tt.map(C=>d("button",{className:"ariaflow-widget-chip",onClick:()=>Wt(C),style:{borderColor:u,color:u,backgroundColor:"rgba(255, 255, 255, 0.95)",backdropFilter:"blur(4px)"},children:C},C))}),d("div",{className:"ariaflow-widget-input",children:[d("textarea",{value:S,onInput:C=>H(C.target.value),onKeyDown:Pt,placeholder:M?ne?ye>0?`Agent is responding... (${ye} message${ye>1?"s":""} queued)`:"Agent is responding...":"Type your message...":"Connecting...",rows:1,disabled:!M}),d("button",{className:"ariaflow-widget-send",onClick:st,disabled:!S.trim()||!M,style:{backgroundColor:u},"aria-label":"Send message",children:d("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[d("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),d("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})})]})]})]})}ht(Ze,"ariaflow-widget",["agent-url","agent-id","widget-id","api-url","mode","theme","position","size","radius","base-color","accent-color","button-base-color","button-accent-color","title","subtitle","empty-chat-message"],{shadow:!1}),typeof document<"u"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",et):et());function et(){const t=document.querySelectorAll("ariaflow-widget");console.log(`[AriaFlow] Initializing ${t.length} widget(s)`)}I.Widget=Ze,I.WidgetClient=Ye,Object.defineProperty(I,Symbol.toStringTag,{value:"Module"})});
|