@ariaflowagents/widget 0.6.13 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/widget.js +413 -427
- package/dist/widget.umd.cjs +2 -3
- package/package.json +1 -1
package/dist/widget.umd.cjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
(function(I,E){typeof exports=="object"&&typeof module<"u"?E(exports):typeof define=="function"&&define.amd?define(["exports"],E):(I=typeof globalThis<"u"?globalThis:I||self,E(I.AriaFlowWidget={}))})(this,function(I){"use strict";var E,m,ye,U,we,ve,be,Ce,ie,re,ae,B={},ke=[],ot=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,J=Array.isArray;function F(t,e){for(var n in e)t[n]=e[n];return t}function le(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function Q(t,e,n){var o,i,s,a={};for(s in e)s=="key"?o=e[s]:s=="ref"?i=e[s]:a[s]=e[s];if(arguments.length>2&&(a.children=arguments.length>3?E.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 z(t,a,o,i,null)}function z(t,e,n,o,i){var s={type:t,props:e,key:n,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:i??++ye,__i:-1,__u:0};return i==null&&m.vnode!=null&&m.vnode(s),s}function D(t){return t.children}function K(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 Ae(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 Ae(t)}}function Se(t){(!t.__d&&(t.__d=!0)&&U.push(t)&&!G.__r++||we!=m.debounceRendering)&&((we=m.debounceRendering)||ve)(G)}function G(){for(var t,e,n,o,i,s,a,_=1;U.length;)U.length>_&&U.sort(be),t=U.shift(),_=U.length,t.__d&&(n=void 0,o=void 0,i=(o=(e=t).__v).__e,s=[],a=[],e.__P&&((n=F({},o)).__v=o.__v+1,m.vnode&&m.vnode(n),_e(e.__P,n,o,e.__n,e.__P.namespaceURI,32&o.__u?[i]:null,s,i??q(o),!!(32&o.__u),a),n.__v=o.__v,n.__.__k[n.__i]=n,Me(s,n,a),o.__e=o.__=null,n.__e!=i&&Ae(n)));G.__r=0}function We(t,e,n,o,i,s,a,_,c,l,u){var r,h,g,b,W,w,p,f=o&&o.__k||ke,P=e.length;for(c=st(n,e,f,c,P),r=0;r<P;r++)(g=n.__k[r])!=null&&(h=g.__i==-1?B:f[g.__i]||B,g.__i=r,w=_e(t,g,h,i,s,a,_,c,l,u),b=g.__e,g.ref&&h.ref!=g.ref&&(h.ref&&ue(h.ref,null,g),u.push(g.ref,g.__c||b,g)),W==null&&b!=null&&(W=b),(p=!!(4&g.__u))||h.__k===g.__k?c=$e(g,c,t,p):typeof g.type=="function"&&w!==void 0?c=w:b&&(c=b.nextSibling),g.__u&=-7);return n.__e=W,c}function st(t,e,n,o,i){var s,a,_,c,l,u=n.length,r=u,h=0;for(t.__k=new Array(i),s=0;s<i;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]=z(null,a,null,null,null):J(a)?a=t.__k[s]=z(D,{children:a},null,null,null):a.constructor===void 0&&a.__b>0?a=t.__k[s]=z(a.type,a.props,a.key,a.ref?a.ref:null,a.__v):t.__k[s]=a,c=s+h,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&&(i>u?h--:i<u&&h++),typeof a.type!="function"&&(a.__u|=4)):l!=c&&(l==c-1?h--:l==c+1?h++:(l>c?h--:h++,a.__u|=4))):t.__k[s]=null;if(r)for(s=0;s<u;s++)(_=n[s])!=null&&!(2&_.__u)&&(_.__e==o&&(o=q(_)),Pe(_,_));return o}function $e(t,e,n,o){var i,s;if(typeof t.type=="function"){for(i=t.__k,s=0;i&&s<i.length;s++)i[s]&&(i[s].__=t,e=$e(i[s],e,n,o));return e}t.__e!=e&&(o&&(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,o){var i,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(o>(u?1:0)){for(i=n-1,s=n+1;i>=0||s<e.length;)if((l=e[a=i>=0?i--: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"||ot.test(e)?n:n+"px"}function X(t,e,n,o,i){var s,a;e:if(e=="style")if(typeof n=="string")t.style.cssText=n;else{if(typeof o=="string"&&(t.style.cssText=o=""),o)for(e in o)n&&e in n||xe(t.style,e,"");if(n)for(e in n)o&&n[e]==o[e]||xe(t.style,e,n[e])}else if(e[0]=="o"&&e[1]=="n")s=e!=(e=e.replace(Ce,"$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?o?n.u=o.u:(n.u=ie,t.addEventListener(e,s?ae:re,s)):t.removeEventListener(e,s?ae:re,s);else{if(i=="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=ie++;else if(e.t<n.u)return;return n(m.event?m.event(e):e)}}}function _e(t,e,n,o,i,s,a,_,c,l){var u,r,h,g,b,W,w,p,f,P,x,R,$,oe,A,O,L,N=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 N=="function")try{if(p=e.props,f="prototype"in N&&N.prototype.render,P=(u=N.contextType)&&o[u.__c],x=u?P?P.props.value:u.__:o,n.__c?w=(r=e.__c=n.__c).__=r.__E:(f?e.__c=r=new N(p,x):(e.__c=r=new K(p,x),r.constructor=N,r.render=at),P&&P.sub(r),r.state||(r.state={}),r.__n=o,h=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=F({},r.__s)),F(r.__s,N.getDerivedStateFromProps(p,r.__s))),g=r.props,b=r.state,r.__v=e,h)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!==g&&r.componentWillReceiveProps!=null&&r.componentWillReceiveProps(p,x),e.__v==n.__v||!r.__e&&r.shouldComponentUpdate!=null&&r.shouldComponentUpdate(p,r.__s,x)===!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(M){M&&(M.__=e)}),R=0;R<r._sb.length;R++)r.__h.push(r._sb[R]);r._sb=[],r.__h.length&&a.push(r);break e}r.componentWillUpdate!=null&&r.componentWillUpdate(p,r.__s,x),f&&r.componentDidUpdate!=null&&r.__h.push(function(){r.componentDidUpdate(g,b,W)})}if(r.context=x,r.props=p,r.__P=t,r.__e=!1,$=m.__r,oe=0,f){for(r.state=r.__s,r.__d=!1,$&&$(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,$&&$(e),u=r.render(r.props,r.state,r.context),r.state=r.__s;while(r.__d&&++oe<25);r.state=r.__s,r.getChildContext!=null&&(o=F(F({},o),r.getChildContext())),f&&!h&&r.getSnapshotBeforeUpdate!=null&&(W=r.getSnapshotBeforeUpdate(g,b)),O=u,u!=null&&u.type===D&&u.key==null&&(O=Fe(u.props.children)),_=We(t,J(O)?O:[O],e,n,o,i,s,a,_,c,l),r.base=e.__e,e.__u&=-161,r.__h.length&&a.push(r),w&&(r.__E=r.__=null)}catch(M){if(e.__v=null,c||s!=null)if(M.then){for(e.__u|=c?160:128;_&&_.nodeType==8&&_.nextSibling;)_=_.nextSibling;s[s.indexOf(_)]=null,e.__e=_}else{for(L=s.length;L--;)le(s[L]);ce(e)}else e.__e=n.__e,e.__k=n.__k,M.then||ce(e);m.__e(M,e,n)}else s==null&&e.__v==n.__v?(e.__k=n.__k,e.__e=n.__e):_=e.__e=rt(n.__e,e,n,o,i,s,a,c,l);return(u=m.diffed)&&u(e),128&e.__u?void 0:_}function ce(t){t&&t.__c&&(t.__c.__e=!0),t&&t.__k&&t.__k.forEach(ce)}function Me(t,e,n){for(var o=0;o<n.length;o++)ue(n[o],n[++o],n[++o]);m.__c&&m.__c(e,t),t.some(function(i){try{t=i.__h,i.__h=[],t.some(function(s){s.call(i)})}catch(s){m.__e(s,i.__v)}})}function Fe(t){return typeof t!="object"||t==null||t.__b&&t.__b>0?t:J(t)?t.map(Fe):F({},t)}function rt(t,e,n,o,i,s,a,_,c){var l,u,r,h,g,b,W,w=n.props||B,p=e.props,f=e.type;if(f=="svg"?i="http://www.w3.org/2000/svg":f=="math"?i="http://www.w3.org/1998/Math/MathML":i||(i="http://www.w3.org/1999/xhtml"),s!=null){for(l=0;l<s.length;l++)if((g=s[l])&&"setAttribute"in g==!!f&&(f?g.localName==f:g.nodeType==3)){t=g,s[l]=null;break}}if(t==null){if(f==null)return document.createTextNode(p);t=document.createElementNS(i,f,p.is&&p),_&&(m.__m&&m.__m(e,s),_=!1),s=null}if(f==null)w===p||_&&t.data==p||(t.data=p);else{if(s=s&&E.call(t.childNodes),!_&&s!=null)for(w={},l=0;l<t.attributes.length;l++)w[(g=t.attributes[l]).name]=g.value;for(l in w)if(g=w[l],l!="children"){if(l=="dangerouslySetInnerHTML")r=g;else if(!(l in p)){if(l=="value"&&"defaultValue"in p||l=="checked"&&"defaultChecked"in p)continue;X(t,l,null,g,i)}}for(l in p)g=p[l],l=="children"?h=g:l=="dangerouslySetInnerHTML"?u=g:l=="value"?b=g:l=="checked"?W=g:_&&typeof g!="function"||w[l]===g||X(t,l,g,w[l],i);if(u)_||r&&(u.__html==r.__html||u.__html==t.innerHTML)||(t.innerHTML=u.__html),e.__k=[];else if(r&&(t.innerHTML=""),We(e.type=="template"?t.content:t,J(h)?h:[h],e,n,o,f=="foreignObject"?"http://www.w3.org/1999/xhtml":i,s,a,s?s[0]:n.__k&&q(n,0),_,c),s!=null)for(l=s.length;l--;)le(s[l]);_||(l="value",f=="progress"&&b==null?t.removeAttribute("value"):b!=null&&(b!==t[l]||f=="progress"&&!b||f=="option"&&b!=w[l])&&X(t,l,b,w[l],i),l="checked",W!=null&&W!=t[l]&&X(t,l,W,w[l],i))}return t}function ue(t,e,n){try{if(typeof t=="function"){var o=typeof t.__u=="function";o&&t.__u(),o&&e==null||(t.__u=t(e))}else t.current=e}catch(i){m.__e(i,n)}}function Pe(t,e,n){var o,i;if(m.unmount&&m.unmount(t),(o=t.ref)&&(o.current&&o.current!=t.__e||ue(o,null,e)),(o=t.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(s){m.__e(s,e)}o.base=o.__P=null}if(o=t.__k)for(i=0;i<o.length;i++)o[i]&&Pe(o[i],e,n||typeof t.type!="function");n||le(t.__e),t.__c=t.__=t.__e=void 0}function at(t,e,n){return this.constructor(t,n)}function Y(t,e,n){var o,i,s,a;e==document&&(e=document.documentElement),m.__&&m.__(t,e),i=(o=typeof n=="function")?null:n&&n.__k||e.__k,s=[],a=[],_e(e,t=(!o&&n||e).__k=Q(D,null,[t]),i||B,B,e.namespaceURI,!o&&n?[n]:i?null:e.firstChild?E.call(e.childNodes):null,s,!o&&n?n:i?i.__e:e.firstChild,o,a),Me(s,t,a)}function Te(t,e){Y(t,e,Te)}function Ee(t,e,n){var o,i,s,a,_=F({},t.props);for(s in t.type&&t.type.defaultProps&&(a=t.type.defaultProps),e)s=="key"?o=e[s]:s=="ref"?i=e[s]:_[s]=e[s]===void 0&&a!=null?a[s]:e[s];return arguments.length>2&&(_.children=arguments.length>3?E.call(arguments,2):n),z(t.type,_,o||t.key,i||t.ref,null)}E=ke.slice,m={__e:function(t,e,n,o){for(var i,s,a;e=e.__;)if((i=e.__c)&&!i.__)try{if((s=i.constructor)&&s.getDerivedStateFromError!=null&&(i.setState(s.getDerivedStateFromError(t)),a=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(t,o||{}),a=i.__d),a)return i.__E=i}catch(_){t=_}throw t}},ye=0,K.prototype.setState=function(t,e){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=F({},this.state),typeof t=="function"&&(t=t(F({},n),this.props)),t&&F(n,t),t!=null&&this.__v&&(e&&this._sb.push(e),Se(this))},K.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),Se(this))},K.prototype.render=D,U=[],ve=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,be=function(t,e){return t.__v.__b-e.__v.__b},G.__r=0,Ce=/(PointerCapture)$|Capture$/i,ie=0,re=Ne(!1),ae=Ne(!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 o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t},Z.apply(this,arguments)}function He(t,e){if(t==null)return{};var n,o,i={},s=Object.keys(t);for(o=0;o<s.length;o++)e.indexOf(n=s[o])>=0||(i[n]=t[n]);return i}var lt=["context","children"],_t=["useFragment"];function ct(t,e,n,o){function i(){var s=Reflect.construct(HTMLElement,[],i);return s._vdomComponent=t,s._root=s,s}return(i.prototype=Object.create(HTMLElement.prototype)).constructor=i,i.prototype.connectedCallback=function(){gt.call(this,o)},i.prototype.attributeChangedCallback=dt,i.prototype.disconnectedCallback=ht,n=n||t.observedAttributes||Object.keys(t.propTypes||{}),i.observedAttributes=n,t.formAssociated&&(i.formAssociated=!0),n.forEach(function(s){Object.defineProperty(i.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,i),i}function ut(t){this.getChildContext=function(){return t.context};var e=t.children,n=He(t,lt);return Ee(e,n)}function gt(t){var e=new CustomEvent("_preact",{detail:{},bubbles:!0,cancelable:!0});this.dispatchEvent(e),this._vdom=Q(ut,Z({},this._props,{context:e.detail.context}),De(this,this._vdomComponent,t)),(this.hasAttribute("hydrate")?Te:Y)(this._vdom,this._root)}function Ie(t){return t.replace(/-(\w)/g,function(e,n){return n?n.toUpperCase():""})}function dt(t,e,n){if(this._vdom){var o={};o[t]=n=n??void 0,o[Ie(t)]=n,this._vdom=Ee(this._vdom,o),Y(this._vdom,this._root)}}function ht(){Y(this._vdom=null,this._root)}function Ue(t,e){var n=this,o=t.useFragment,i=He(t,_t);return Q(o?D:"slot",Z({},i,{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 o=[],i={},s=0,a=t.attributes,_=t.childNodes;for(s=a.length;s--;)a[s].name!=="slot"&&(i[a[s].name]=a[s].value,i[Ie(a[s].name)]=a[s].value);for(s=_.length;s--;){var c=De(_[s],null,n),l=_[s].slot;l?i[l]=Q(Ue,{name:l},c):o[s]=c}var u=!(!n||!n.shadow),r=e?Q(Ue,{useFragment:!u},o):o;return!u&&e&&(t.innerHTML=""),Q(e||t.nodeName.toLowerCase(),i,r)}var ft=0;function d(t,e,n,o,i,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:--ft,__i:-1,__u:0,__source:i,__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 V,y,ge,Re,ee=0,Oe=[],v=m,Le=v.__b,Qe=v.__r,qe=v.diffed,je=v.__c,Be=v.unmount,ze=v.__;function de(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 H(t){return ee=1,pt(Xe,t)}function pt(t,e,n){var o=de(V++,2);if(o.t=t,!o.__c&&(o.__=[Xe(void 0,e),function(_){var c=o.__N?o.__N[0]:o.__[0],l=o.t(c,_);c!==l&&(o.__N=[l,o.__[1]],o.__c.setState({}))}],o.__c=y,!y.__f)){var i=function(_,c,l){if(!o.__c.__H)return!0;var u=o.__c.__H.__.filter(function(h){return!!h.__c});if(u.every(function(h){return!h.__N}))return!s||s.call(this,_,c,l);var r=o.__c.props!==_;return u.forEach(function(h){if(h.__N){var g=h.__[0];h.__=h.__N,h.__N=void 0,g!==h.__[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,i(_,c,l),s=u}a&&a.call(this,_,c,l)},y.shouldComponentUpdate=i}return o.__N||o.__}function Ve(t,e){var n=de(V++,3);!v.__s&&Ge(n.__H,e)&&(n.__=t,n.u=e,y.__H.__h.push(n))}function Je(t){return ee=5,mt(function(){return{current:t}},[])}function mt(t,e){var n=de(V++,7);return Ge(n.__H,e)&&(n.__=t(),n.__H=e,n.__h=t),n.__}function yt(){for(var t;t=Oe.shift();)if(t.__P&&t.__H)try{t.__H.__h.forEach(te),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),ze&&ze(t,e)},v.__r=function(t){Qe&&Qe(t),V=0;var e=(y=t.__c).__H;e&&(ge===y?(e.__h=[],y.__h=[],e.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(e.__h.forEach(te),e.__h.forEach(he),e.__h=[],V=0)),ge=y},v.diffed=function(t){qe&&qe(t);var e=t.__c;e&&e.__H&&(e.__H.__h.length&&(Oe.push(e)!==1&&Re===v.requestAnimationFrame||((Re=v.requestAnimationFrame)||wt)(yt)),e.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),ge=y=null},v.__c=function(t,e){e.some(function(n){try{n.__h.forEach(te),n.__h=n.__h.filter(function(o){return!o.__||he(o)})}catch(o){e.some(function(i){i.__h&&(i.__h=[])}),e=[],v.__e(o,n.__v)}}),je&&je(t,e)},v.unmount=function(t){Be&&Be(t);var e,n=t.__c;n&&n.__H&&(n.__H.__.forEach(function(o){try{te(o)}catch(i){e=i}}),n.__H=void 0,e&&v.__e(e,n.__v))};var Ke=typeof requestAnimationFrame=="function";function wt(t){var e,n=function(){clearTimeout(o),Ke&&cancelAnimationFrame(e),setTimeout(t)},o=setTimeout(n,35);Ke&&(e=requestAnimationFrame(n))}function te(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 Ge(t,e){return!t||t.length!==e.length||e.some(function(n,o){return n!==t[o]})}function Xe(t,e){return typeof e=="function"?e(t):e}const vt="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let ne=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t|=0));for(;t--;)e+=vt[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.connectionCallbacks=new Set,this.streamingCallbacks=new Set,this.processingCallbacks=new Set,this.queueCallbacks=new Set,this.messages=[],this.reconnectAttempts=0,this.maxReconnectAttempts=5,this.reconnectDelay=1e3,this.isAgentStreaming=!1,this.isAgentProcessing=!1,this.messageQueue=[]}async initWidget(){try{console.log("[AriaFlow Widget] Fetching agent config...",{agentUrl:this.agentUrl,agentId:this.agentId});try{const n=await fetch(`${this.agentUrl}/api/agent/${this.agentId}`);if(n.ok){const o=await n.json();return console.log("[AriaFlow Widget] Agent config received:",o),!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")}console.log("[AriaFlow Widget] Using fallback config for Railway deployment");const e={id:this.agentId,name:this.agentId==="hospital"?"Hospital Support":"Support Agent",wsUrl:`${this.agentUrl.replace(/^https/,"wss")}/ws`,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=e,await this.connectToAgent(),e}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");const e=this.getSessionId(),n=`${this.agentConfig.wsUrl}/${e}`;return console.log("[AriaFlow Widget] Connecting to WebSocket:",n),new Promise((o,i)=>{try{this.ws=new WebSocket(n),this.ws.onopen=()=>{console.log("[Widget] Connected to agent"),this.reconnectAttempts=0,this.notifyConnectionChange(!0),o()},this.ws.onmessage=s=>{this.handleMessage(s)},this.ws.onclose=()=>{if(console.log("[Widget] Disconnected from agent"),this.notifyConnectionChange(!1),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),i(s)}}catch(s){i(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==="text-delta")this.isAgentProcessing&&this.notifyProcessingChange(!1),this.setMessages(o=>{const i=o[o.length-1];return i&&i.role==="assistant"&&i.isStreaming?[...o.slice(0,-1),{...i,content:i.content+n.text}]:[...o,{id:ne(),role:"assistant",content:n.text,timestamp:Date.now(),isStreaming:!0}]});else if(n.type==="done")console.log("[Widget] Response complete"),this.notifyProcessingChange(!1),this.setMessages(o=>{const i=o[o.length-1];return i&&i.role==="assistant"&&i.isStreaming?[...o.slice(0,-1),{...i,isStreaming:!1}]:o}),this.isAgentStreaming=!1,this.notifyStreamingChange(!1),this.processMessageQueue();else if(n.type==="step-start"||n.type==="agent-start")console.log(`[Widget] ${n.type} received:`,n.agentId||""),this.isAgentStreaming=!0,this.notifyStreamingChange(!0),this.notifyProcessingChange(!0);else if(n.type==="step-end"||n.type==="agent-end")console.log(`[Widget] ${n.type} received`),n.type==="agent-end"&&this.notifyProcessingChange(!1);else if(n.type==="tool-call"){console.log("[Widget] Tool call:",n.tool),this.notifyProcessingChange(!0);const o={id:ne(),role:"tool",content:`Calling tool: ${n.tool.name}`,timestamp:Date.now(),toolCall:{name:n.tool.name,arguments:n.tool.arguments}};this.setMessages(i=>[...i,o]),n.tool.name==="suggest_options"&&n.tool.arguments?.options&&this.setMessages(i=>{const s=[...i].reverse().find(a=>a.role==="assistant");return s?i.map(a=>a.id===s.id?{...a,suggestions:n.tool.arguments.options}:a):i})}else n.type==="tool-result"?(console.log("[Widget] Tool result:",n.result),this.setMessages(o=>{const i=o[o.length-1];return i&&i.role==="tool"&&!i.toolResult?[...o.slice(0,-1),{...i,content:i.content+`
|
|
2
|
-
Result: ${JSON.stringify(n.result)}`,toolResult:n.result}]:o})):n.type==="agent-start"?(console.log(`[Widget] Agent started: ${n.agentId}`),this.isAgentStreaming=!0,this.notifyStreamingChange(!0)):n.type==="handoff"?console.log(`[Widget] Handoff: ${n.from} -> ${n.to}: ${n.reason}`):n.type==="suggested-questions"?(console.log("[Widget] Suggestions received:",n.suggestions),this.setMessages(o=>{const i=[...o].reverse().find(s=>s.role==="assistant");return i?o.map(s=>s.id===i.id?{...s,suggestions:n.suggestions}:s):o})):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");const n={id:ne(),role:"user",content:e,timestamp:Date.now()};if(this.setMessages(o=>[...o,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(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(`
|
|
3
2
|
|
|
4
|
-
`);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=de(),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):[],s=[...new Set(n)];this.activeSuggestions=s,this.suggestionsCallbacks.forEach(o=>o(s))}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 ge={none:"0",small:"0.375rem",medium:"0.75rem",large:"1rem"};function Xe({agentUrl:t,agentId:e,widgetId:n,apiUrl:s,mode:o="chat",theme:i="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]=E(!1),[f,M]=E([]),[$,D]=E(""),[S,ee]=E(!1),[A,L]=E(!1),[O,N]=E(null),[P,wt]=E(!1),[bt,Ct]=E(!1),[fe,kt]=E(0),[Ze,St]=E([]),te=ze(null),et=ze(null);je(()=>((async()=>{if(t&&e){const T=new Ge(t,e);te.current=T;try{T.onMessages(x=>M(x)),T.onConnectionChange(x=>{ee(x),x&&L(!0)}),T.onStreamingChange(x=>wt(x)),T.onQueueChange(x=>kt(x)),T.onProcessingChange(x=>Ct(x)),T.onSuggestionsChange(x=>St(x));const ne=await T.initWidget();ne?N(ne):console.error("[AriaFlow Widget] Agent config fetch failed")}catch(ne){console.error("[AriaFlow Widget] Initialization error:",ne)}}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")):s&&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.")})(),()=>{te.current?.dispose()}),[t,e,n,s]),je(()=>{et.current?.scrollIntoView({behavior:"smooth"})},[f]);const tt=async()=>{if(!$.trim()||!S)return;const C=$.trim();D("");try{await te.current?.sendMessage(C)}catch(T){console.error("Failed to send message:",T)}},At=C=>{C.key==="Enter"&&!C.shiftKey&&(C.preventDefault(),tt())},$t=C=>{!S||P||te.current?.sendMessage(C)},Nt=h||O?.config.title||"Ninewells Hospital",xt=w||O?.config.subtitle||"How can we help you today?",Pt=k||O?.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":i,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:i==="dark"&&l?l:void 0,borderRadius:ge[c]},children:[d("div",{className:"ariaflow-widget-header",style:{backgroundColor:u,borderRadius:c==="none"?"0":`${ge[c]} ${ge[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:Nt}),d("p",{className:"ariaflow-widget-subtitle",children:xt})]})}),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"})]})})]}),!S&&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:S?Pt:"Connecting to agent..."})}):d(I,{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(I,{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:et}),bt&&!P&&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:"•"})]})})})]})}),!P&&Ze.length>0&&d("div",{className:"ariaflow-widget-suggestions",children:Ze.map(C=>d("button",{className:"ariaflow-widget-chip",onClick:()=>$t(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:$,onInput:C=>D(C.target.value),onKeyDown:At,placeholder:S?P?fe>0?`Agent is responding... (${fe} message${fe>1?"s":""} queued)`:"Agent is responding...":"Type your message...":"Connecting...",rows:1,disabled:!S}),d("button",{className:"ariaflow-widget-send",onClick:tt,disabled:!$.trim()||!S,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"})]})})]})]})]})}_t(Xe,"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",Ye):Ye());function Ye(){const t=document.querySelectorAll("ariaflow-widget");console.log(`[AriaFlow] Initializing ${t.length} widget(s)`)}H.Widget=Xe,H.WidgetClient=Ge,Object.defineProperty(H,Symbol.toStringTag,{value:"Module"})});
|