@ariaflowagents/widget 0.5.10 → 0.6.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/style.css +1 -1
- package/dist/widget.js +549 -399
- package/dist/widget.umd.cjs +4 -1
- package/package.json +1 -1
package/dist/widget.umd.cjs
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
(function(M,E){typeof exports=="object"&&typeof module<"u"?E(exports):typeof define=="function"&&define.amd?define(["exports"],E):(M=typeof globalThis<"u"?globalThis:M||self,E(M.AriaFlowWidget={}))})(this,function(M){"use strict";var E,m,he,T,ge,pe,me,ve,ne,oe,ie,B={},ye=[],Ze=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,K=Array.isArray;function S(t,e){for(var n in e)t[n]=e[n];return t}function re(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function I(t,e,n){var i,r,o,_={};for(o in e)o=="key"?i=e[o]:o=="ref"?r=e[o]:_[o]=e[o];if(arguments.length>2&&(_.children=arguments.length>3?E.call(arguments,2):n),typeof t=="function"&&t.defaultProps!=null)for(o in t.defaultProps)_[o]===void 0&&(_[o]=t.defaultProps[o]);return z(t,_,i,r,null)}function z(t,e,n,i,r){var o={type:t,props:e,key:n,ref:i,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:r??++he,__i:-1,__u:0};return r==null&&m.vnode!=null&&m.vnode(o),o}function D(t){return t.children}function J(t,e){this.props=t,this.context=e}function R(t,e){if(e==null)return t.__?R(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"?R(t):null}function we(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 we(t)}}function be(t){(!t.__d&&(t.__d=!0)&&T.push(t)&&!G.__r++||ge!=m.debounceRendering)&&((ge=m.debounceRendering)||pe)(G)}function G(){for(var t,e,n,i,r,o,_,a=1;T.length;)T.length>a&&T.sort(me),t=T.shift(),a=T.length,t.__d&&(n=void 0,i=void 0,r=(i=(e=t).__v).__e,o=[],_=[],e.__P&&((n=S({},i)).__v=i.__v+1,m.vnode&&m.vnode(n),se(e.__P,n,i,e.__n,e.__P.namespaceURI,32&i.__u?[r]:null,o,r??R(i),!!(32&i.__u),_),n.__v=i.__v,n.__.__k[n.__i]=n,We(o,n,_),i.__e=i.__=null,n.__e!=r&&we(n)));G.__r=0}function ke(t,e,n,i,r,o,_,a,c,l,d){var s,f,u,b,C,y,p,g=i&&i.__k||ye,N=e.length;for(c=et(n,e,g,c,N),s=0;s<N;s++)(u=n.__k[s])!=null&&(f=u.__i==-1?B:g[u.__i]||B,u.__i=s,y=se(t,u,f,r,o,_,a,c,l,d),b=u.__e,u.ref&&f.ref!=u.ref&&(f.ref&&le(f.ref,null,u),d.push(u.ref,u.__c||b,u)),C==null&&b!=null&&(C=b),(p=!!(4&u.__u))||f.__k===u.__k?c=Ce(u,c,t,p):typeof u.type=="function"&&y!==void 0?c=y:b&&(c=b.nextSibling),u.__u&=-7);return n.__e=C,c}function et(t,e,n,i,r){var o,_,a,c,l,d=n.length,s=d,f=0;for(t.__k=new Array(r),o=0;o<r;o++)(_=e[o])!=null&&typeof _!="boolean"&&typeof _!="function"?(typeof _=="string"||typeof _=="number"||typeof _=="bigint"||_.constructor==String?_=t.__k[o]=z(null,_,null,null,null):K(_)?_=t.__k[o]=z(D,{children:_},null,null,null):_.constructor===void 0&&_.__b>0?_=t.__k[o]=z(_.type,_.props,_.key,_.ref?_.ref:null,_.__v):t.__k[o]=_,c=o+f,_.__=t,_.__b=t.__b+1,a=null,(l=_.__i=tt(_,n,c,s))!=-1&&(s--,(a=n[l])&&(a.__u|=2)),a==null||a.__v==null?(l==-1&&(r>d?f--:r<d&&f++),typeof _.type!="function"&&(_.__u|=4)):l!=c&&(l==c-1?f--:l==c+1?f++:(l>c?f--:f++,_.__u|=4))):t.__k[o]=null;if(s)for(o=0;o<d;o++)(a=n[o])!=null&&!(2&a.__u)&&(a.__e==i&&(i=R(a)),Se(a,a));return i}function Ce(t,e,n,i){var r,o;if(typeof t.type=="function"){for(r=t.__k,o=0;r&&o<r.length;o++)r[o]&&(r[o].__=t,e=Ce(r[o],e,n,i));return e}t.__e!=e&&(i&&(e&&t.type&&!e.parentNode&&(e=R(t)),n.insertBefore(t.__e,e||null)),e=t.__e);do e=e&&e.nextSibling;while(e!=null&&e.nodeType==8);return e}function tt(t,e,n,i){var r,o,_,a=t.key,c=t.type,l=e[n],d=l!=null&&(2&l.__u)==0;if(l===null&&a==null||d&&a==l.key&&c==l.type)return n;if(i>(d?1:0)){for(r=n-1,o=n+1;r>=0||o<e.length;)if((l=e[_=r>=0?r--:o++])!=null&&!(2&l.__u)&&a==l.key&&c==l.type)return _}return-1}function Ae(t,e,n){e[0]=="-"?t.setProperty(e,n??""):t[e]=n==null?"":typeof n!="number"||Ze.test(e)?n:n+"px"}function Q(t,e,n,i,r){var o,_;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||Ae(t.style,e,"");if(n)for(e in n)i&&n[e]==i[e]||Ae(t.style,e,n[e])}else if(e[0]=="o"&&e[1]=="n")o=e!=(e=e.replace(ve,"$1")),_=e.toLowerCase(),e=_ in t||e=="onFocusOut"||e=="onFocusIn"?_.slice(2):e.slice(2),t.l||(t.l={}),t.l[e+o]=n,n?i?n.u=i.u:(n.u=ne,t.addEventListener(e,o?ie:oe,o)):t.removeEventListener(e,o?ie:oe,o);else{if(r=="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 $e(t){return function(e){if(this.l){var n=this.l[e.type+t];if(e.t==null)e.t=ne++;else if(e.t<n.u)return;return n(m.event?m.event(e):e)}}}function se(t,e,n,i,r,o,_,a,c,l){var d,s,f,u,b,C,y,p,g,N,A,H,$,te,k,P,U,W=e.type;if(e.constructor!==void 0)return null;128&n.__u&&(c=!!(32&n.__u),o=[a=e.__e=n.__e]),(d=m.__b)&&d(e);e:if(typeof W=="function")try{if(p=e.props,g="prototype"in W&&W.prototype.render,N=(d=W.contextType)&&i[d.__c],A=d?N?N.props.value:d.__:i,n.__c?y=(s=e.__c=n.__c).__=s.__E:(g?e.__c=s=new W(p,A):(e.__c=s=new J(p,A),s.constructor=W,s.render=ot),N&&N.sub(s),s.state||(s.state={}),s.__n=i,f=s.__d=!0,s.__h=[],s._sb=[]),g&&s.__s==null&&(s.__s=s.state),g&&W.getDerivedStateFromProps!=null&&(s.__s==s.state&&(s.__s=S({},s.__s)),S(s.__s,W.getDerivedStateFromProps(p,s.__s))),u=s.props,b=s.state,s.__v=e,f)g&&W.getDerivedStateFromProps==null&&s.componentWillMount!=null&&s.componentWillMount(),g&&s.componentDidMount!=null&&s.__h.push(s.componentDidMount);else{if(g&&W.getDerivedStateFromProps==null&&p!==u&&s.componentWillReceiveProps!=null&&s.componentWillReceiveProps(p,A),e.__v==n.__v||!s.__e&&s.shouldComponentUpdate!=null&&s.shouldComponentUpdate(p,s.__s,A)===!1){for(e.__v!=n.__v&&(s.props=p,s.state=s.__s,s.__d=!1),e.__e=n.__e,e.__k=n.__k,e.__k.some(function(F){F&&(F.__=e)}),H=0;H<s._sb.length;H++)s.__h.push(s._sb[H]);s._sb=[],s.__h.length&&_.push(s);break e}s.componentWillUpdate!=null&&s.componentWillUpdate(p,s.__s,A),g&&s.componentDidUpdate!=null&&s.__h.push(function(){s.componentDidUpdate(u,b,C)})}if(s.context=A,s.props=p,s.__P=t,s.__e=!1,$=m.__r,te=0,g){for(s.state=s.__s,s.__d=!1,$&&$(e),d=s.render(s.props,s.state,s.context),k=0;k<s._sb.length;k++)s.__h.push(s._sb[k]);s._sb=[]}else do s.__d=!1,$&&$(e),d=s.render(s.props,s.state,s.context),s.state=s.__s;while(s.__d&&++te<25);s.state=s.__s,s.getChildContext!=null&&(i=S(S({},i),s.getChildContext())),g&&!f&&s.getSnapshotBeforeUpdate!=null&&(C=s.getSnapshotBeforeUpdate(u,b)),P=d,d!=null&&d.type===D&&d.key==null&&(P=xe(d.props.children)),a=ke(t,K(P)?P:[P],e,n,i,r,o,_,a,c,l),s.base=e.__e,e.__u&=-161,s.__h.length&&_.push(s),y&&(s.__E=s.__=null)}catch(F){if(e.__v=null,c||o!=null)if(F.then){for(e.__u|=c?160:128;a&&a.nodeType==8&&a.nextSibling;)a=a.nextSibling;o[o.indexOf(a)]=null,e.__e=a}else{for(U=o.length;U--;)re(o[U]);_e(e)}else e.__e=n.__e,e.__k=n.__k,F.then||_e(e);m.__e(F,e,n)}else o==null&&e.__v==n.__v?(e.__k=n.__k,e.__e=n.__e):a=e.__e=nt(n.__e,e,n,i,r,o,_,c,l);return(d=m.diffed)&&d(e),128&e.__u?void 0:a}function _e(t){t&&t.__c&&(t.__c.__e=!0),t&&t.__k&&t.__k.forEach(_e)}function We(t,e,n){for(var i=0;i<n.length;i++)le(n[i],n[++i],n[++i]);m.__c&&m.__c(e,t),t.some(function(r){try{t=r.__h,r.__h=[],t.some(function(o){o.call(r)})}catch(o){m.__e(o,r.__v)}})}function xe(t){return typeof t!="object"||t==null||t.__b&&t.__b>0?t:K(t)?t.map(xe):S({},t)}function nt(t,e,n,i,r,o,_,a,c){var l,d,s,f,u,b,C,y=n.props||B,p=e.props,g=e.type;if(g=="svg"?r="http://www.w3.org/2000/svg":g=="math"?r="http://www.w3.org/1998/Math/MathML":r||(r="http://www.w3.org/1999/xhtml"),o!=null){for(l=0;l<o.length;l++)if((u=o[l])&&"setAttribute"in u==!!g&&(g?u.localName==g:u.nodeType==3)){t=u,o[l]=null;break}}if(t==null){if(g==null)return document.createTextNode(p);t=document.createElementNS(r,g,p.is&&p),a&&(m.__m&&m.__m(e,o),a=!1),o=null}if(g==null)y===p||a&&t.data==p||(t.data=p);else{if(o=o&&E.call(t.childNodes),!a&&o!=null)for(y={},l=0;l<t.attributes.length;l++)y[(u=t.attributes[l]).name]=u.value;for(l in y)if(u=y[l],l!="children"){if(l=="dangerouslySetInnerHTML")s=u;else if(!(l in p)){if(l=="value"&&"defaultValue"in p||l=="checked"&&"defaultChecked"in p)continue;Q(t,l,null,u,r)}}for(l in p)u=p[l],l=="children"?f=u:l=="dangerouslySetInnerHTML"?d=u:l=="value"?b=u:l=="checked"?C=u:a&&typeof u!="function"||y[l]===u||Q(t,l,u,y[l],r);if(d)a||s&&(d.__html==s.__html||d.__html==t.innerHTML)||(t.innerHTML=d.__html),e.__k=[];else if(s&&(t.innerHTML=""),ke(e.type=="template"?t.content:t,K(f)?f:[f],e,n,i,g=="foreignObject"?"http://www.w3.org/1999/xhtml":r,o,_,o?o[0]:n.__k&&R(n,0),a,c),o!=null)for(l=o.length;l--;)re(o[l]);a||(l="value",g=="progress"&&b==null?t.removeAttribute("value"):b!=null&&(b!==t[l]||g=="progress"&&!b||g=="option"&&b!=y[l])&&Q(t,l,b,y[l],r),l="checked",C!=null&&C!=t[l]&&Q(t,l,C,y[l],r))}return t}function le(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(r){m.__e(r,n)}}function Se(t,e,n){var i,r;if(m.unmount&&m.unmount(t),(i=t.ref)&&(i.current&&i.current!=t.__e||le(i,null,e)),(i=t.__c)!=null){if(i.componentWillUnmount)try{i.componentWillUnmount()}catch(o){m.__e(o,e)}i.base=i.__P=null}if(i=t.__k)for(r=0;r<i.length;r++)i[r]&&Se(i[r],e,n||typeof t.type!="function");n||re(t.__e),t.__c=t.__=t.__e=void 0}function ot(t,e,n){return this.constructor(t,n)}function X(t,e,n){var i,r,o,_;e==document&&(e=document.documentElement),m.__&&m.__(t,e),r=(i=typeof n=="function")?null:n&&n.__k||e.__k,o=[],_=[],se(e,t=(!i&&n||e).__k=I(D,null,[t]),r||B,B,e.namespaceURI,!i&&n?[n]:r?null:e.firstChild?E.call(e.childNodes):null,o,!i&&n?n:r?r.__e:e.firstChild,i,_),We(o,t,_)}function Ne(t,e){X(t,e,Ne)}function Fe(t,e,n){var i,r,o,_,a=S({},t.props);for(o in t.type&&t.type.defaultProps&&(_=t.type.defaultProps),e)o=="key"?i=e[o]:o=="ref"?r=e[o]:a[o]=e[o]===void 0&&_!=null?_[o]:e[o];return arguments.length>2&&(a.children=arguments.length>3?E.call(arguments,2):n),z(t.type,a,i||t.key,r||t.ref,null)}E=ye.slice,m={__e:function(t,e,n,i){for(var r,o,_;e=e.__;)if((r=e.__c)&&!r.__)try{if((o=r.constructor)&&o.getDerivedStateFromError!=null&&(r.setState(o.getDerivedStateFromError(t)),_=r.__d),r.componentDidCatch!=null&&(r.componentDidCatch(t,i||{}),_=r.__d),_)return r.__E=r}catch(a){t=a}throw t}},he=0,J.prototype.setState=function(t,e){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=S({},this.state),typeof t=="function"&&(t=t(S({},n),this.props)),t&&S(n,t),t!=null&&this.__v&&(e&&this._sb.push(e),be(this))},J.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),be(this))},J.prototype.render=D,T=[],pe=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,me=function(t,e){return t.__v.__b-e.__v.__b},G.__r=0,ve=/(PointerCapture)$|Capture$/i,ne=0,oe=$e(!1),ie=$e(!0);function Y(){return Y=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},Y.apply(this,arguments)}function Ee(t,e){if(t==null)return{};var n,i,r={},o=Object.keys(t);for(i=0;i<o.length;i++)e.indexOf(n=o[i])>=0||(r[n]=t[n]);return r}var it=["context","children"],rt=["useFragment"];function st(t,e,n,i){function r(){var o=Reflect.construct(HTMLElement,[],r);return o._vdomComponent=t,o._root=o,o}return(r.prototype=Object.create(HTMLElement.prototype)).constructor=r,r.prototype.connectedCallback=function(){lt.call(this,i)},r.prototype.attributeChangedCallback=at,r.prototype.disconnectedCallback=ct,n=n||t.observedAttributes||Object.keys(t.propTypes||{}),r.observedAttributes=n,t.formAssociated&&(r.formAssociated=!0),n.forEach(function(o){Object.defineProperty(r.prototype,o,{get:function(){return this._vdom?this._vdom.props[o]:this._props[o]},set:function(_){this._vdom?this.attributeChangedCallback(o,null,_):(this._props||(this._props={}),this._props[o]=_);var a=typeof _;_!=null&&a!=="string"&&a!=="boolean"&&a!=="number"||this.setAttribute(o,_)}})}),customElements.define(e,r),r}function _t(t){this.getChildContext=function(){return t.context};var e=t.children,n=Ee(t,it);return Fe(e,n)}function lt(t){var e=new CustomEvent("_preact",{detail:{},bubbles:!0,cancelable:!0});this.dispatchEvent(e),this._vdom=I(_t,Y({},this._props,{context:e.detail.context}),He(this,this._vdomComponent,t)),(this.hasAttribute("hydrate")?Ne:X)(this._vdom,this._root)}function Me(t){return t.replace(/-(\w)/g,function(e,n){return n?n.toUpperCase():""})}function at(t,e,n){if(this._vdom){var i={};i[t]=n=n??void 0,i[Me(t)]=n,this._vdom=Fe(this._vdom,i),X(this._vdom,this._root)}}function ct(){X(this._vdom=null,this._root)}function Te(t,e){var n=this,i=t.useFragment,r=Ee(t,rt);return I(i?D:"slot",Y({},r,{ref:function(o){o?(n.ref=o,n._listener||(n._listener=function(_){_.stopPropagation(),_.detail.context=e},o.addEventListener("_preact",n._listener))):n.ref.removeEventListener("_preact",n._listener)}}))}function He(t,e,n){if(t.nodeType===3)return t.data;if(t.nodeType!==1)return null;var i=[],r={},o=0,_=t.attributes,a=t.childNodes;for(o=_.length;o--;)_[o].name!=="slot"&&(r[_[o].name]=_[o].value,r[Me(_[o].name)]=_[o].value);for(o=a.length;o--;){var c=He(a[o],null,n),l=a[o].slot;l?r[l]=I(Te,{name:l},c):i[o]=c}var d=!(!n||!n.shadow),s=e?I(Te,{useFragment:!d},i):i;return!d&&e&&(t.innerHTML=""),I(e||t.nodeName.toLowerCase(),r,s)}var ut=0;function h(t,e,n,i,r,o){e||(e={});var _,a,c=e;if("ref"in c)for(a in c={},e)a=="ref"?_=e[a]:c[a]=e[a];var l={type:t,props:c,key:n,ref:_,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--ut,__i:-1,__u:0,__source:r,__self:o};if(typeof t=="function"&&(_=t.defaultProps))for(a in _)c[a]===void 0&&(c[a]=_[a]);return m.vnode&&m.vnode(l),l}var V,v,ae,Pe,Z=0,Ue=[],w=m,Ie=w.__b,De=w.__r,Re=w.diffed,Le=w.__c,Oe=w.unmount,je=w.__;function ce(t,e){w.__h&&w.__h(v,t,Z||e),Z=0;var n=v.__H||(v.__H={__:[],__h:[]});return t>=n.__.length&&n.__.push({}),n.__[t]}function L(t){return Z=1,dt(Ke,t)}function dt(t,e,n){var i=ce(V++,2);if(i.t=t,!i.__c&&(i.__=[Ke(void 0,e),function(a){var c=i.__N?i.__N[0]:i.__[0],l=i.t(c,a);c!==l&&(i.__N=[l,i.__[1]],i.__c.setState({}))}],i.__c=v,!v.__f)){var r=function(a,c,l){if(!i.__c.__H)return!0;var d=i.__c.__H.__.filter(function(f){return!!f.__c});if(d.every(function(f){return!f.__N}))return!o||o.call(this,a,c,l);var s=i.__c.props!==a;return d.forEach(function(f){if(f.__N){var u=f.__[0];f.__=f.__N,f.__N=void 0,u!==f.__[0]&&(s=!0)}}),o&&o.call(this,a,c,l)||s};v.__f=!0;var o=v.shouldComponentUpdate,_=v.componentWillUpdate;v.componentWillUpdate=function(a,c,l){if(this.__e){var d=o;o=void 0,r(a,c,l),o=d}_&&_.call(this,a,c,l)},v.shouldComponentUpdate=r}return i.__N||i.__}function Be(t,e){var n=ce(V++,3);!w.__s&&qe(n.__H,e)&&(n.__=t,n.u=e,v.__H.__h.push(n))}function ze(t){return Z=5,ft(function(){return{current:t}},[])}function ft(t,e){var n=ce(V++,7);return qe(n.__H,e)&&(n.__=t(),n.__H=e,n.__h=t),n.__}function ht(){for(var t;t=Ue.shift();)if(t.__P&&t.__H)try{t.__H.__h.forEach(ee),t.__H.__h.forEach(ue),t.__H.__h=[]}catch(e){t.__H.__h=[],w.__e(e,t.__v)}}w.__b=function(t){v=null,Ie&&Ie(t)},w.__=function(t,e){t&&e.__k&&e.__k.__m&&(t.__m=e.__k.__m),je&&je(t,e)},w.__r=function(t){De&&De(t),V=0;var e=(v=t.__c).__H;e&&(ae===v?(e.__h=[],v.__h=[],e.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(e.__h.forEach(ee),e.__h.forEach(ue),e.__h=[],V=0)),ae=v},w.diffed=function(t){Re&&Re(t);var e=t.__c;e&&e.__H&&(e.__H.__h.length&&(Ue.push(e)!==1&&Pe===w.requestAnimationFrame||((Pe=w.requestAnimationFrame)||gt)(ht)),e.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),ae=v=null},w.__c=function(t,e){e.some(function(n){try{n.__h.forEach(ee),n.__h=n.__h.filter(function(i){return!i.__||ue(i)})}catch(i){e.some(function(r){r.__h&&(r.__h=[])}),e=[],w.__e(i,n.__v)}}),Le&&Le(t,e)},w.unmount=function(t){Oe&&Oe(t);var e,n=t.__c;n&&n.__H&&(n.__H.__.forEach(function(i){try{ee(i)}catch(r){e=r}}),n.__H=void 0,e&&w.__e(e,n.__v))};var Ve=typeof requestAnimationFrame=="function";function gt(t){var e,n=function(){clearTimeout(i),Ve&&cancelAnimationFrame(e),setTimeout(t)},i=setTimeout(n,35);Ve&&(e=requestAnimationFrame(n))}function ee(t){var e=v,n=t.__c;typeof n=="function"&&(t.__c=void 0,n()),v=e}function ue(t){var e=v;t.__c=t.__(),v=e}function qe(t,e){return!t||t.length!==e.length||e.some(function(n,i){return n!==t[i]})}function Ke(t,e){return typeof e=="function"?e(t):e}const pt="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let de=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t|=0));for(;t--;)e+=pt[n[t]&63];return e};class Je{constructor(e,n){this.agentUrl=e,this.agentId=n,this.agentConfig=null,this.ws=null,this.messageCallbacks=new Set,this.connectionCallbacks=new Set,this.messages=[],this.reconnectAttempts=0,this.maxReconnectAttempts=5,this.reconnectDelay=1e3}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 i=await n.json();return console.log("[AriaFlow Widget] Agent config received:",i),!i||i.status!=="active"?(console.error("Agent not found or inactive"),null):(this.agentConfig=i,this.maxReconnectAttempts=i.config.maxRetries||5,this.reconnectDelay=i.config.reconnectDelay||1e3,await this.connectToAgent(),i)}}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((i,r)=>{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=o=>{this.handleMessage(o)},this.ws.onclose=()=>{if(console.log("[Widget] Disconnected from agent"),this.notifyConnectionChange(!1),this.reconnectAttempts<this.maxReconnectAttempts){this.reconnectAttempts++;const o=this.reconnectDelay*Math.pow(2,this.reconnectAttempts-1);console.log(`[Widget] Reconnecting in ${o}ms... (attempt ${this.reconnectAttempts})`),setTimeout(()=>this.connectToAgent(),o)}},this.ws.onerror=o=>{console.error("[Widget] WebSocket error:",o),r(o)}}catch(o){r(o)}})}handleMessage(e){try{const n=JSON.parse(e.data);n.type==="text-delta"?this.setMessages(i=>{const r=i[i.length-1];return r&&r.role==="assistant"?[...i.slice(0,-1),{...r,content:r.content+n.text}]:[...i,{id:de(),role:"assistant",content:n.text,timestamp:Date.now()}]}):n.type==="done"?console.log("[Widget] Response complete"):n.type==="handoff"?console.log(`[Widget] Handoff: ${n.from} -> ${n.to}: ${n.reason}`):n.type==="tool-call"?console.log("[Widget] Tool call:",n.tool):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:de(),role:"user",content:e,timestamp:Date.now()};this.setMessages(r=>[...r,n]);const i=this.getSessionId();this.ws.send(JSON.stringify({message:e,sessionId:i}))}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)}}notifyConnectionChange(e){this.connectionCallbacks.forEach(n=>n(e))}getMessages(){return this.messages}getConfig(){return this.agentConfig}isConnected(){return this.ws?.readyState===WebSocket.OPEN}dispose(){this.ws&&(this.ws.close(),this.ws=null),this.messageCallbacks.clear(),this.connectionCallbacks.clear()}}const fe={none:"0",small:"0.375rem",medium:"0.75rem",large:"1rem"};function Ge({agentUrl:t,agentId:e,widgetId:n,apiUrl:i,mode:r="chat",theme:o="light",position:_="bottom-right",size:a="full",radius:c="medium",baseColor:l,accentColor:d="#14B8A6",buttonBaseColor:s="#000000",buttonAccentColor:f="#FFFFFF",title:u,subtitle:b,emptyChatMessage:C}){const[y,p]=L(!1),[g,N]=L([]),[A,H]=L(""),[$,te]=L(!1),[k,P]=L(!1),[U,W]=L(null),F=ze(null),Xe=ze(null);Be(()=>((async()=>{if(t&&e){console.log("[AriaFlow Widget] Using new agent resolution:",{agentUrl:t,agentId:e});const O=new Je(t,e);F.current=O;try{O.onMessages(j=>{console.log("[AriaFlow Widget] Messages updated:",j.length),N(j)}),O.onConnectionChange(j=>{console.log("[AriaFlow Widget] Connection state:",j),te(j),j&&P(!0)});const q=await O.initWidget();console.log("[AriaFlow Widget] Agent config received:",q),q?(W(q),console.log("[AriaFlow Widget] Widget initialized successfully")):console.error("[AriaFlow Widget] Agent config fetch failed")}catch(q){console.error("[AriaFlow Widget] Initialization error:",q)}}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.")})(),()=>{F.current?.dispose()}),[t,e,n,i]),Be(()=>{Xe.current?.scrollIntoView({behavior:"smooth"})},[g]);const Ye=async()=>{if(!A.trim()||!$)return;const x=A.trim();H("");try{await F.current?.sendMessage(x)}catch(O){console.error("Failed to send message:",O)}},mt=x=>{x.key==="Enter"&&!x.shiftKey&&(x.preventDefault(),Ye())},vt=u||U?.title||"Chat with us",yt=b||U?.subtitle||"We typically reply within minutes",wt=C||U?.config?.emptyChatMessage||"Start a conversation...";return console.log("[AriaFlow Widget] Rendering widget component",{isInitialized:k,isOpen:y,position:_}),h("div",{className:`ariaflow-widget-container ariaflow-widget-${_} ariaflow-widget-${a} ariaflow-widget-radius-${c}`,"data-theme":o,style:{"--ariaflow-accent-color":d,"--ariaflow-base-color":l},children:[!y&&h("button",{className:"ariaflow-widget-launcher",onClick:()=>p(!0),style:{backgroundColor:s,color:f,opacity:k?1:.8,cursor:k?"pointer":"wait",position:"relative"},"aria-label":k?"Open chat":"Connecting to agent...",disabled:!k,title:k?"Click to start chat":"Connecting to agent...",children:[!k&&h("div",{className:"ariaflow-widget-launcher-loading",style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"20px",height:"20px",border:`2px solid ${f}`,borderTop:"2px solid transparent",borderRadius:"50%",animation:"spin 1s linear infinite"}}),k&&h("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:h("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})]}),y&&k&&h("div",{className:"ariaflow-widget-window",style:{backgroundColor:o==="dark"&&l?l:void 0,borderRadius:fe[c]},children:[h("div",{className:"ariaflow-widget-header",style:{backgroundColor:d,borderRadius:c==="none"?"0":`${fe[c]} ${fe[c]} 0 0`},children:[h("div",{className:"ariaflow-widget-header-content",children:h("div",{className:"ariaflow-widget-title-group",children:[h("h3",{className:"ariaflow-widget-title",children:vt}),h("p",{className:"ariaflow-widget-subtitle",children:yt})]})}),h("button",{className:"ariaflow-widget-close",onClick:()=>p(!1),"aria-label":"Close chat",children:h("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[h("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),h("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),!$&&h("div",{className:"ariaflow-widget-status",children:[h("span",{className:"ariaflow-widget-status-dot"}),"Connecting..."]}),h("div",{className:"ariaflow-widget-messages",children:g.length===0?h("div",{className:"ariaflow-widget-empty",children:h("p",{children:$?wt:"Connecting to agent..."})}):h(D,{children:[g.map(x=>h("div",{className:`ariaflow-widget-message ariaflow-widget-message-${x.role}`,children:h("div",{className:"ariaflow-widget-message-bubble",children:x.content})},x.id)),h("div",{ref:Xe})]})}),h("div",{className:"ariaflow-widget-input",children:[h("textarea",{value:A,onInput:x=>H(x.target.value),onKeyDown:mt,placeholder:$?"Type your message...":"Connecting...",rows:1,disabled:!$}),h("button",{className:"ariaflow-widget-send",onClick:Ye,disabled:!A.trim()||!$,style:{backgroundColor:d},"aria-label":"Send message",children:h("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[h("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),h("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})})]})]})]})}st(Ge,"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"],!1),typeof document<"u"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Qe):Qe());function Qe(){const t=document.querySelectorAll("ariaflow-widget");console.log(`[AriaFlow] Initializing ${t.length} widget(s)`)}M.Widget=Ge,M.WidgetClient=Je,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(P,E){typeof exports=="object"&&typeof module<"u"?E(exports):typeof define=="function"&&define.amd?define(["exports"],E):(P=typeof globalThis<"u"?globalThis:P||self,E(P.AriaFlowWidget={}))})(this,function(P){"use strict";var E,m,me,I,ye,we,ve,be,ie,se,re,j={},Ce=[],nt=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,V=Array.isArray;function x(t,e){for(var n in e)t[n]=e[n];return t}function le(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function L(t,e,n){var o,s,i,l={};for(i in e)i=="key"?o=e[i]:i=="ref"?s=e[i]:l[i]=e[i];if(arguments.length>2&&(l.children=arguments.length>3?E.call(arguments,2):n),typeof t=="function"&&t.defaultProps!=null)for(i in t.defaultProps)l[i]===void 0&&(l[i]=t.defaultProps[i]);return B(t,l,o,s,null)}function B(t,e,n,o,s){var i={type:t,props:e,key:n,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:s??++me,__i:-1,__u:0};return s==null&&m.vnode!=null&&m.vnode(i),i}function R(t){return t.children}function J(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 ke(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 ke(t)}}function Ae(t){(!t.__d&&(t.__d=!0)&&I.push(t)&&!K.__r++||ye!=m.debounceRendering)&&((ye=m.debounceRendering)||we)(K)}function K(){for(var t,e,n,o,s,i,l,a=1;I.length;)I.length>a&&I.sort(ve),t=I.shift(),a=I.length,t.__d&&(n=void 0,o=void 0,s=(o=(e=t).__v).__e,i=[],l=[],e.__P&&((n=x({},o)).__v=o.__v+1,m.vnode&&m.vnode(n),ae(e.__P,n,o,e.__n,e.__P.namespaceURI,32&o.__u?[s]:null,i,s??Q(o),!!(32&o.__u),l),n.__v=o.__v,n.__.__k[n.__i]=n,xe(i,n,l),o.__e=o.__=null,n.__e!=s&&ke(n)));K.__r=0}function Se(t,e,n,o,s,i,l,a,c,_,u){var r,h,d,C,S,v,p,f=o&&o.__k||Ce,F=e.length;for(c=ot(n,e,f,c,F),r=0;r<F;r++)(d=n.__k[r])!=null&&(h=d.__i==-1?j:f[d.__i]||j,d.__i=r,v=ae(t,d,h,s,i,l,a,c,_,u),C=d.__e,d.ref&&h.ref!=d.ref&&(h.ref&&ce(h.ref,null,d),u.push(d.ref,d.__c||C,d)),S==null&&C!=null&&(S=C),(p=!!(4&d.__u))||h.__k===d.__k?c=$e(d,c,t,p):typeof d.type=="function"&&v!==void 0?c=v:C&&(c=C.nextSibling),d.__u&=-7);return n.__e=S,c}function ot(t,e,n,o,s){var i,l,a,c,_,u=n.length,r=u,h=0;for(t.__k=new Array(s),i=0;i<s;i++)(l=e[i])!=null&&typeof l!="boolean"&&typeof l!="function"?(typeof l=="string"||typeof l=="number"||typeof l=="bigint"||l.constructor==String?l=t.__k[i]=B(null,l,null,null,null):V(l)?l=t.__k[i]=B(R,{children:l},null,null,null):l.constructor===void 0&&l.__b>0?l=t.__k[i]=B(l.type,l.props,l.key,l.ref?l.ref:null,l.__v):t.__k[i]=l,c=i+h,l.__=t,l.__b=t.__b+1,a=null,(_=l.__i=it(l,n,c,r))!=-1&&(r--,(a=n[_])&&(a.__u|=2)),a==null||a.__v==null?(_==-1&&(s>u?h--:s<u&&h++),typeof l.type!="function"&&(l.__u|=4)):_!=c&&(_==c-1?h--:_==c+1?h++:(_>c?h--:h++,l.__u|=4))):t.__k[i]=null;if(r)for(i=0;i<u;i++)(a=n[i])!=null&&!(2&a.__u)&&(a.__e==o&&(o=Q(a)),Me(a,a));return o}function $e(t,e,n,o){var s,i;if(typeof t.type=="function"){for(s=t.__k,i=0;s&&i<s.length;i++)s[i]&&(s[i].__=t,e=$e(s[i],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 s,i,l,a=t.key,c=t.type,_=e[n],u=_!=null&&(2&_.__u)==0;if(_===null&&a==null||u&&a==_.key&&c==_.type)return n;if(o>(u?1:0)){for(s=n-1,i=n+1;s>=0||i<e.length;)if((_=e[l=s>=0?s--:i++])!=null&&!(2&_.__u)&&a==_.key&&c==_.type)return l}return-1}function We(t,e,n){e[0]=="-"?t.setProperty(e,n??""):t[e]=n==null?"":typeof n!="number"||nt.test(e)?n:n+"px"}function G(t,e,n,o,s){var i,l;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||We(t.style,e,"");if(n)for(e in n)o&&n[e]==o[e]||We(t.style,e,n[e])}else if(e[0]=="o"&&e[1]=="n")i=e!=(e=e.replace(be,"$1")),l=e.toLowerCase(),e=l in t||e=="onFocusOut"||e=="onFocusIn"?l.slice(2):e.slice(2),t.l||(t.l={}),t.l[e+i]=n,n?o?n.u=o.u:(n.u=ie,t.addEventListener(e,i?re:se,i)):t.removeEventListener(e,i?re:se,i);else{if(s=="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 ae(t,e,n,o,s,i,l,a,c,_){var u,r,h,d,C,S,v,p,f,F,W,U,$,ne,k,D,O,N=e.type;if(e.constructor!==void 0)return null;128&n.__u&&(c=!!(32&n.__u),i=[a=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,F=(u=N.contextType)&&o[u.__c],W=u?F?F.props.value:u.__:o,n.__c?v=(r=e.__c=n.__c).__=r.__E:(f?e.__c=r=new N(p,W):(e.__c=r=new J(p,W),r.constructor=N,r.render=rt),F&&F.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=x({},r.__s)),x(r.__s,N.getDerivedStateFromProps(p,r.__s))),d=r.props,C=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!==d&&r.componentWillReceiveProps!=null&&r.componentWillReceiveProps(p,W),e.__v==n.__v||!r.__e&&r.shouldComponentUpdate!=null&&r.shouldComponentUpdate(p,r.__s,W)===!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(T){T&&(T.__=e)}),U=0;U<r._sb.length;U++)r.__h.push(r._sb[U]);r._sb=[],r.__h.length&&l.push(r);break e}r.componentWillUpdate!=null&&r.componentWillUpdate(p,r.__s,W),f&&r.componentDidUpdate!=null&&r.__h.push(function(){r.componentDidUpdate(d,C,S)})}if(r.context=W,r.props=p,r.__P=t,r.__e=!1,$=m.__r,ne=0,f){for(r.state=r.__s,r.__d=!1,$&&$(e),u=r.render(r.props,r.state,r.context),k=0;k<r._sb.length;k++)r.__h.push(r._sb[k]);r._sb=[]}else do r.__d=!1,$&&$(e),u=r.render(r.props,r.state,r.context),r.state=r.__s;while(r.__d&&++ne<25);r.state=r.__s,r.getChildContext!=null&&(o=x(x({},o),r.getChildContext())),f&&!h&&r.getSnapshotBeforeUpdate!=null&&(S=r.getSnapshotBeforeUpdate(d,C)),D=u,u!=null&&u.type===R&&u.key==null&&(D=Fe(u.props.children)),a=Se(t,V(D)?D:[D],e,n,o,s,i,l,a,c,_),r.base=e.__e,e.__u&=-161,r.__h.length&&l.push(r),v&&(r.__E=r.__=null)}catch(T){if(e.__v=null,c||i!=null)if(T.then){for(e.__u|=c?160:128;a&&a.nodeType==8&&a.nextSibling;)a=a.nextSibling;i[i.indexOf(a)]=null,e.__e=a}else{for(O=i.length;O--;)le(i[O]);_e(e)}else e.__e=n.__e,e.__k=n.__k,T.then||_e(e);m.__e(T,e,n)}else i==null&&e.__v==n.__v?(e.__k=n.__k,e.__e=n.__e):a=e.__e=st(n.__e,e,n,o,s,i,l,c,_);return(u=m.diffed)&&u(e),128&e.__u?void 0:a}function _e(t){t&&t.__c&&(t.__c.__e=!0),t&&t.__k&&t.__k.forEach(_e)}function xe(t,e,n){for(var o=0;o<n.length;o++)ce(n[o],n[++o],n[++o]);m.__c&&m.__c(e,t),t.some(function(s){try{t=s.__h,s.__h=[],t.some(function(i){i.call(s)})}catch(i){m.__e(i,s.__v)}})}function Fe(t){return typeof t!="object"||t==null||t.__b&&t.__b>0?t:V(t)?t.map(Fe):x({},t)}function st(t,e,n,o,s,i,l,a,c){var _,u,r,h,d,C,S,v=n.props||j,p=e.props,f=e.type;if(f=="svg"?s="http://www.w3.org/2000/svg":f=="math"?s="http://www.w3.org/1998/Math/MathML":s||(s="http://www.w3.org/1999/xhtml"),i!=null){for(_=0;_<i.length;_++)if((d=i[_])&&"setAttribute"in d==!!f&&(f?d.localName==f:d.nodeType==3)){t=d,i[_]=null;break}}if(t==null){if(f==null)return document.createTextNode(p);t=document.createElementNS(s,f,p.is&&p),a&&(m.__m&&m.__m(e,i),a=!1),i=null}if(f==null)v===p||a&&t.data==p||(t.data=p);else{if(i=i&&E.call(t.childNodes),!a&&i!=null)for(v={},_=0;_<t.attributes.length;_++)v[(d=t.attributes[_]).name]=d.value;for(_ in v)if(d=v[_],_!="children"){if(_=="dangerouslySetInnerHTML")r=d;else if(!(_ in p)){if(_=="value"&&"defaultValue"in p||_=="checked"&&"defaultChecked"in p)continue;G(t,_,null,d,s)}}for(_ in p)d=p[_],_=="children"?h=d:_=="dangerouslySetInnerHTML"?u=d:_=="value"?C=d:_=="checked"?S=d:a&&typeof d!="function"||v[_]===d||G(t,_,d,v[_],s);if(u)a||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,V(h)?h:[h],e,n,o,f=="foreignObject"?"http://www.w3.org/1999/xhtml":s,i,l,i?i[0]:n.__k&&Q(n,0),a,c),i!=null)for(_=i.length;_--;)le(i[_]);a||(_="value",f=="progress"&&C==null?t.removeAttribute("value"):C!=null&&(C!==t[_]||f=="progress"&&!C||f=="option"&&C!=v[_])&&G(t,_,C,v[_],s),_="checked",S!=null&&S!=t[_]&&G(t,_,S,v[_],s))}return t}function ce(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(s){m.__e(s,n)}}function Me(t,e,n){var o,s;if(m.unmount&&m.unmount(t),(o=t.ref)&&(o.current&&o.current!=t.__e||ce(o,null,e)),(o=t.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(i){m.__e(i,e)}o.base=o.__P=null}if(o=t.__k)for(s=0;s<o.length;s++)o[s]&&Me(o[s],e,n||typeof t.type!="function");n||le(t.__e),t.__c=t.__=t.__e=void 0}function rt(t,e,n){return this.constructor(t,n)}function X(t,e,n){var o,s,i,l;e==document&&(e=document.documentElement),m.__&&m.__(t,e),s=(o=typeof n=="function")?null:n&&n.__k||e.__k,i=[],l=[],ae(e,t=(!o&&n||e).__k=L(R,null,[t]),s||j,j,e.namespaceURI,!o&&n?[n]:s?null:e.firstChild?E.call(e.childNodes):null,i,!o&&n?n:s?s.__e:e.firstChild,o,l),xe(i,t,l)}function Ee(t,e){X(t,e,Ee)}function Te(t,e,n){var o,s,i,l,a=x({},t.props);for(i in t.type&&t.type.defaultProps&&(l=t.type.defaultProps),e)i=="key"?o=e[i]:i=="ref"?s=e[i]:a[i]=e[i]===void 0&&l!=null?l[i]:e[i];return arguments.length>2&&(a.children=arguments.length>3?E.call(arguments,2):n),B(t.type,a,o||t.key,s||t.ref,null)}E=Ce.slice,m={__e:function(t,e,n,o){for(var s,i,l;e=e.__;)if((s=e.__c)&&!s.__)try{if((i=s.constructor)&&i.getDerivedStateFromError!=null&&(s.setState(i.getDerivedStateFromError(t)),l=s.__d),s.componentDidCatch!=null&&(s.componentDidCatch(t,o||{}),l=s.__d),l)return s.__E=s}catch(a){t=a}throw t}},me=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=R,I=[],we=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,ve=function(t,e){return t.__v.__b-e.__v.__b},K.__r=0,be=/(PointerCapture)$|Capture$/i,ie=0,se=Ne(!1),re=Ne(!0);function Y(){return Y=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},Y.apply(this,arguments)}function He(t,e){if(t==null)return{};var n,o,s={},i=Object.keys(t);for(o=0;o<i.length;o++)e.indexOf(n=i[o])>=0||(s[n]=t[n]);return s}var lt=["context","children"],at=["useFragment"];function _t(t,e,n,o){function s(){var i=Reflect.construct(HTMLElement,[],s);return i._vdomComponent=t,i._root=i,i}return(s.prototype=Object.create(HTMLElement.prototype)).constructor=s,s.prototype.connectedCallback=function(){ut.call(this,o)},s.prototype.attributeChangedCallback=dt,s.prototype.disconnectedCallback=gt,n=n||t.observedAttributes||Object.keys(t.propTypes||{}),s.observedAttributes=n,t.formAssociated&&(s.formAssociated=!0),n.forEach(function(i){Object.defineProperty(s.prototype,i,{get:function(){return this._vdom?this._vdom.props[i]:this._props[i]},set:function(l){this._vdom?this.attributeChangedCallback(i,null,l):(this._props||(this._props={}),this._props[i]=l);var a=typeof l;l!=null&&a!=="string"&&a!=="boolean"&&a!=="number"||this.setAttribute(i,l)}})}),customElements.define(e,s),s}function ct(t){this.getChildContext=function(){return t.context};var e=t.children,n=He(t,lt);return Te(e,n)}function ut(t){var e=new CustomEvent("_preact",{detail:{},bubbles:!0,cancelable:!0});this.dispatchEvent(e),this._vdom=L(ct,Y({},this._props,{context:e.detail.context}),Re(this,this._vdomComponent,t)),(this.hasAttribute("hydrate")?Ee:X)(this._vdom,this._root)}function Pe(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[Pe(t)]=n,this._vdom=Te(this._vdom,o),X(this._vdom,this._root)}}function gt(){X(this._vdom=null,this._root)}function Ie(t,e){var n=this,o=t.useFragment,s=He(t,at);return L(o?R:"slot",Y({},s,{ref:function(i){i?(n.ref=i,n._listener||(n._listener=function(l){l.stopPropagation(),l.detail.context=e},i.addEventListener("_preact",n._listener))):n.ref.removeEventListener("_preact",n._listener)}}))}function Re(t,e,n){if(t.nodeType===3)return t.data;if(t.nodeType!==1)return null;var o=[],s={},i=0,l=t.attributes,a=t.childNodes;for(i=l.length;i--;)l[i].name!=="slot"&&(s[l[i].name]=l[i].value,s[Pe(l[i].name)]=l[i].value);for(i=a.length;i--;){var c=Re(a[i],null,n),_=a[i].slot;_?s[_]=L(Ie,{name:_},c):o[i]=c}var u=!(!n||!n.shadow),r=e?L(Ie,{useFragment:!u},o):o;return!u&&e&&(t.innerHTML=""),L(e||t.nodeName.toLowerCase(),s,r)}var ht=0;function g(t,e,n,o,s,i){e||(e={});var l,a,c=e;if("ref"in c)for(a in c={},e)a=="ref"?l=e[a]:c[a]=e[a];var _={type:t,props:c,key:n,ref:l,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--ht,__i:-1,__u:0,__source:s,__self:i};if(typeof t=="function"&&(l=t.defaultProps))for(a in l)c[a]===void 0&&(c[a]=l[a]);return m.vnode&&m.vnode(_),_}var z,w,ue,Ue,Z=0,De=[],b=m,Oe=b.__b,Le=b.__r,Qe=b.diffed,qe=b.__c,je=b.unmount,Be=b.__;function de(t,e){b.__h&&b.__h(w,t,Z||e),Z=0;var n=w.__H||(w.__H={__:[],__h:[]});return t>=n.__.length&&n.__.push({}),n.__[t]}function H(t){return Z=1,ft(Ge,t)}function ft(t,e,n){var o=de(z++,2);if(o.t=t,!o.__c&&(o.__=[Ge(void 0,e),function(a){var c=o.__N?o.__N[0]:o.__[0],_=o.t(c,a);c!==_&&(o.__N=[_,o.__[1]],o.__c.setState({}))}],o.__c=w,!w.__f)){var s=function(a,c,_){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!i||i.call(this,a,c,_);var r=o.__c.props!==a;return u.forEach(function(h){if(h.__N){var d=h.__[0];h.__=h.__N,h.__N=void 0,d!==h.__[0]&&(r=!0)}}),i&&i.call(this,a,c,_)||r};w.__f=!0;var i=w.shouldComponentUpdate,l=w.componentWillUpdate;w.componentWillUpdate=function(a,c,_){if(this.__e){var u=i;i=void 0,s(a,c,_),i=u}l&&l.call(this,a,c,_)},w.shouldComponentUpdate=s}return o.__N||o.__}function ze(t,e){var n=de(z++,3);!b.__s&&Ke(n.__H,e)&&(n.__=t,n.u=e,w.__H.__h.push(n))}function Ve(t){return Z=5,pt(function(){return{current:t}},[])}function pt(t,e){var n=de(z++,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(ee),t.__H.__h.forEach(ge),t.__H.__h=[]}catch(e){t.__H.__h=[],b.__e(e,t.__v)}}b.__b=function(t){w=null,Oe&&Oe(t)},b.__=function(t,e){t&&e.__k&&e.__k.__m&&(t.__m=e.__k.__m),Be&&Be(t,e)},b.__r=function(t){Le&&Le(t),z=0;var e=(w=t.__c).__H;e&&(ue===w?(e.__h=[],w.__h=[],e.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(e.__h.forEach(ee),e.__h.forEach(ge),e.__h=[],z=0)),ue=w},b.diffed=function(t){Qe&&Qe(t);var e=t.__c;e&&e.__H&&(e.__H.__h.length&&(De.push(e)!==1&&Ue===b.requestAnimationFrame||((Ue=b.requestAnimationFrame)||yt)(mt)),e.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),ue=w=null},b.__c=function(t,e){e.some(function(n){try{n.__h.forEach(ee),n.__h=n.__h.filter(function(o){return!o.__||ge(o)})}catch(o){e.some(function(s){s.__h&&(s.__h=[])}),e=[],b.__e(o,n.__v)}}),qe&&qe(t,e)},b.unmount=function(t){je&&je(t);var e,n=t.__c;n&&n.__H&&(n.__H.__.forEach(function(o){try{ee(o)}catch(s){e=s}}),n.__H=void 0,e&&b.__e(e,n.__v))};var Je=typeof requestAnimationFrame=="function";function yt(t){var e,n=function(){clearTimeout(o),Je&&cancelAnimationFrame(e),setTimeout(t)},o=setTimeout(n,35);Je&&(e=requestAnimationFrame(n))}function ee(t){var e=w,n=t.__c;typeof n=="function"&&(t.__c=void 0,n()),w=e}function ge(t){var e=w;t.__c=t.__(),w=e}function Ke(t,e){return!t||t.length!==e.length||e.some(function(n,o){return n!==t[o]})}function Ge(t,e){return typeof e=="function"?e(t):e}const wt="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let te=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t|=0));for(;t--;)e+=wt[n[t]&63];return e};class Xe{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.queueCallbacks=new Set,this.messages=[],this.reconnectAttempts=0,this.maxReconnectAttempts=5,this.reconnectDelay=1e3,this.isAgentStreaming=!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,s)=>{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=i=>{this.handleMessage(i)},this.ws.onclose=()=>{if(console.log("[Widget] Disconnected from agent"),this.notifyConnectionChange(!1),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),s(i)}}catch(i){s(i)}})}handleMessage(e){try{const n=JSON.parse(e.data);if(n.type==="text-delta")this.setMessages(o=>{const s=o[o.length-1];return s&&s.role==="assistant"&&s.isStreaming?[...o.slice(0,-1),{...s,content:s.content+n.text}]:[...o,{id:te(),role:"assistant",content:n.text,timestamp:Date.now(),isStreaming:!0}]});else if(n.type==="done")console.log("[Widget] Response complete"),this.setMessages(o=>{const s=o[o.length-1];return s&&s.role==="assistant"&&s.isStreaming?[...o.slice(0,-1),{...s,isStreaming:!1}]:o}),this.isAgentStreaming=!1,this.notifyStreamingChange(!1),this.processMessageQueue();else if(n.type==="tool-call"){console.log("[Widget] Tool call:",n.tool);const o={id:te(),role:"tool",content:`Calling tool: ${n.tool.name}`,timestamp:Date.now(),toolCall:{name:n.tool.name,arguments:n.tool.arguments}};this.setMessages(s=>[...s,o]),n.tool.name==="suggest_options"&&n.tool.arguments?.options&&this.setMessages(s=>{const i=[...s].reverse().find(l=>l.role==="assistant");return i?s.map(l=>l.id===i.id?{...l,suggestions:[...l.suggestions||[],...n.tool.arguments.options]}:l):s})}else n.type==="tool-result"?(console.log("[Widget] Tool result:",n.result),this.setMessages(o=>{const s=o[o.length-1];return s&&s.role==="tool"&&!s.toolResult?[...o.slice(0,-1),{...s,content:s.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 s=[...o].reverse().find(i=>i.role==="assistant");if(s){const i=s.suggestions||[],l=Array.from(new Set([...i,...n.suggestions]));return o.map(a=>a.id===s.id?{...a,suggestions:l}:a)}return 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:te(),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(`
|
|
3
|
+
|
|
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=te(),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))}getMessages(){return this.messages}getConfig(){return this.agentConfig}isConnected(){return this.ws?.readyState===WebSocket.OPEN}dispose(){this.ws&&(this.ws.close(),this.ws=null),this.messageCallbacks.clear(),this.connectionCallbacks.clear()}}const he={none:"0",small:"0.375rem",medium:"0.75rem",large:"1rem"};function Ye({agentUrl:t,agentId:e,widgetId:n,apiUrl:o,mode:s="chat",theme:i="light",position:l="bottom-right",size:a="full",radius:c="medium",baseColor:_,accentColor:u="#14B8A6",buttonBaseColor:r="#000000",buttonAccentColor:h="#FFFFFF",title:d,subtitle:C,emptyChatMessage:S}){const[v,p]=H(!1),[f,F]=H([]),[W,U]=H(""),[$,ne]=H(!1),[k,D]=H(!1),[O,N]=H(null),[T,vt]=H(!1),[fe,bt]=H(0),oe=Ve(null),et=Ve(null);ze(()=>((async()=>{if(t&&e){console.log("[AriaFlow Widget] Using new agent resolution:",{agentUrl:t,agentId:e});const M=new Xe(t,e);oe.current=M;try{M.onMessages(A=>{console.log("[AriaFlow Widget] Messages updated:",A.length),F(A)}),M.onConnectionChange(A=>{console.log("[AriaFlow Widget] Connection state:",A),ne(A),A&&D(!0)}),M.onStreamingChange(A=>{console.log("[AriaFlow Widget] Streaming state:",A),vt(A)}),M.onQueueChange(A=>{console.log("[AriaFlow Widget] Queue count:",A),bt(A)});const q=await M.initWidget();console.log("[AriaFlow Widget] Agent config received:",q),q?(N(q),console.log("[AriaFlow Widget] Widget initialized successfully")):console.error("[AriaFlow Widget] Agent config fetch failed")}catch(q){console.error("[AriaFlow Widget] Initialization error:",q)}}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")):o&&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.")})(),()=>{oe.current?.dispose()}),[t,e,n,o]),ze(()=>{et.current?.scrollIntoView({behavior:"smooth"})},[f]);const tt=async()=>{if(!W.trim()||!$)return;const y=W.trim();U("");try{await oe.current?.sendMessage(y)}catch(M){console.error("Failed to send message:",M)}},Ct=y=>{y.key==="Enter"&&!y.shiftKey&&(y.preventDefault(),tt())},kt=y=>{!$||T||oe.current?.sendMessage(y)},At=d||O?.config.title||"Chat with us",St=C||O?.config.subtitle||"We typically reply within minutes",$t=S||O?.config.emptyChatMessage||"Start a conversation...";return console.log("[AriaFlow Widget] Rendering widget component",{isInitialized:k,isOpen:v,position:l}),g("div",{className:`ariaflow-widget-container ariaflow-widget-${l} ariaflow-widget-${a} ariaflow-widget-radius-${c}`,"data-theme":i,style:{"--ariaflow-accent-color":u,"--ariaflow-base-color":_},children:[!v&&g("button",{className:"ariaflow-widget-launcher",onClick:()=>p(!0),style:{backgroundColor:r,color:h,opacity:k?1:.8,cursor:k?"pointer":"wait",position:"relative"},"aria-label":k?"Open chat":"Connecting to agent...",disabled:!k,title:k?"Click to start chat":"Connecting to agent...",children:[!k&&g("div",{className:"ariaflow-widget-launcher-loading",style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"20px",height:"20px",border:`2px solid ${h}`,borderTop:"2px solid transparent",borderRadius:"50%",animation:"spin 1s linear infinite"}}),k&&g("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:g("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})]}),v&&k&&g("div",{className:"ariaflow-widget-window",style:{backgroundColor:i==="dark"&&_?_:void 0,borderRadius:he[c]},children:[g("div",{className:"ariaflow-widget-header",style:{backgroundColor:u,borderRadius:c==="none"?"0":`${he[c]} ${he[c]} 0 0`},children:[g("div",{className:"ariaflow-widget-header-content",children:g("div",{className:"ariaflow-widget-title-group",children:[g("h3",{className:"ariaflow-widget-title",children:At}),g("p",{className:"ariaflow-widget-subtitle",children:St})]})}),g("button",{className:"ariaflow-widget-close",onClick:()=>p(!1),"aria-label":"Close chat",children:g("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[g("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),g("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),!$&&g("div",{className:"ariaflow-widget-status",children:[g("span",{className:"ariaflow-widget-status-dot"}),"Connecting..."]}),g("div",{className:"ariaflow-widget-messages",children:f.length===0?g("div",{className:"ariaflow-widget-empty",children:g("p",{children:$?$t:"Connecting to agent..."})}):g(R,{children:[f.map((y,M)=>{const A=M===f.length-1&&y.role==="assistant"&&!y.isStreaming&&y.suggestions&&y.suggestions.length>0;return g("div",{className:`ariaflow-widget-message ariaflow-widget-message-${y.role}`,children:[g("div",{className:"ariaflow-widget-message-bubble",children:y.role==="tool"?g("div",{className:"ariaflow-widget-tool-message",children:[g("div",{className:"ariaflow-widget-tool-header",children:["🔧 ",y.toolCall?.name]}),g("div",{className:"ariaflow-widget-tool-content",children:[y.toolCall&&g("div",{className:"ariaflow-widget-tool-args",children:[g("strong",{children:"Arguments:"})," ",JSON.stringify(y.toolCall.arguments,null,2)]}),y.toolResult&&g("div",{className:"ariaflow-widget-tool-result",children:[g("strong",{children:"Result:"})," ",JSON.stringify(y.toolResult,null,2)]})]})]}):g(R,{children:[y.content,y.isStreaming&&g("span",{className:"ariaflow-widget-typing-indicator",children:[g("span",{children:"•"}),g("span",{children:"•"}),g("span",{children:"•"})]})]})}),A&&g("div",{className:"ariaflow-widget-chips-container",children:y.suggestions?.map(pe=>g("button",{className:"ariaflow-widget-chip",onClick:()=>kt(pe),style:{borderColor:u,color:u},children:pe},pe))})]},y.id)}),g("div",{ref:et})]})}),g("div",{className:"ariaflow-widget-input",children:[g("textarea",{value:W,onInput:y=>U(y.target.value),onKeyDown:Ct,placeholder:$?T?fe>0?`Agent is responding... (${fe} message${fe>1?"s":""} queued)`:"Agent is responding...":"Type your message...":"Connecting...",rows:1,disabled:!$}),g("button",{className:"ariaflow-widget-send",onClick:tt,disabled:!W.trim()||!$,style:{backgroundColor:u},"aria-label":"Send message",children:g("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[g("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),g("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})})]})]})]})}_t(Ye,"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"],!1),typeof document<"u"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Ze):Ze());function Ze(){const t=document.querySelectorAll("ariaflow-widget");console.log(`[AriaFlow] Initializing ${t.length} widget(s)`)}P.Widget=Ye,P.WidgetClient=Xe,Object.defineProperty(P,Symbol.toStringTag,{value:"Module"})});
|