@ariaflowagents/widget 0.5.8 → 0.5.9
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/README.md +19 -14
- package/dist/widget.js +4 -3
- package/dist/widget.umd.cjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,32 +12,36 @@ Include the widget script on your website:
|
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
15
|
-
### Method 1:
|
|
15
|
+
### Method 1: Agent Resolution (Recommended)
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
Use `agent-url` (HTTP base URL) and `agent-id` to dynamically resolve agent configuration:
|
|
18
18
|
|
|
19
19
|
```html
|
|
20
20
|
<ariaflow-widget
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
agent-url="https://your-api-endpoint.com"
|
|
22
|
+
agent-id="support"
|
|
23
23
|
position="bottom-right"
|
|
24
24
|
theme="light"
|
|
25
25
|
title="Chat with us"
|
|
26
|
-
subtitle="We
|
|
26
|
+
subtitle="We're here to help!">
|
|
27
27
|
</ariaflow-widget>
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
The widget will:
|
|
31
|
+
1. Call `GET https://your-api-endpoint.com/api/agent/support`
|
|
32
|
+
2. Receive WebSocket URL and agent configuration
|
|
33
|
+
3. Connect to the resolved WebSocket endpoint
|
|
31
34
|
|
|
32
|
-
|
|
35
|
+
### Method 2: Legacy Direct Connection
|
|
36
|
+
|
|
37
|
+
For backward compatibility with fallback logic:
|
|
33
38
|
|
|
34
39
|
```html
|
|
35
40
|
<ariaflow-widget
|
|
36
|
-
agent-url="
|
|
41
|
+
agent-url="wss://your-server.com"
|
|
42
|
+
agent-id="support"
|
|
37
43
|
position="bottom-right"
|
|
38
|
-
theme="light"
|
|
39
|
-
title="Chat with us"
|
|
40
|
-
subtitle="Direct agent connection">
|
|
44
|
+
theme="light">
|
|
41
45
|
</ariaflow-widget>
|
|
42
46
|
```
|
|
43
47
|
|
|
@@ -45,9 +49,10 @@ Connect directly to an agent WebSocket endpoint:
|
|
|
45
49
|
|
|
46
50
|
| Attribute | Type | Default | Description |
|
|
47
51
|
|-----------|------|---------|-------------|
|
|
48
|
-
| `
|
|
49
|
-
| `
|
|
50
|
-
| `
|
|
52
|
+
| `agent-url` | string | **required** | HTTP base URL for API calls |
|
|
53
|
+
| `agent-id` | string | **required** | Agent identifier to resolve configuration |
|
|
54
|
+
| `widget-id` | string | - | Legacy: Widget config ID |
|
|
55
|
+
| `api-url` | string | - | Legacy: API endpoint for widget config |
|
|
51
56
|
| `position` | string | `"bottom-right"` | Widget position: `bottom-right`, `bottom-left`, `top-right`, `top-left` |
|
|
52
57
|
| `theme` | string | `"light"` | Theme: `light` or `dark` |
|
|
53
58
|
| `title` | string | `"Chat with us"` | Header title |
|
package/dist/widget.js
CHANGED
|
@@ -660,12 +660,13 @@ function yt({
|
|
|
660
660
|
const P = new vt(t, e);
|
|
661
661
|
N.current = P;
|
|
662
662
|
try {
|
|
663
|
-
|
|
664
|
-
console.log("[AriaFlow Widget] Agent config received:", L), L ? (W(L), M(!0), console.log("[AriaFlow Widget] Widget initialized successfully"), P.onMessages((O) => {
|
|
663
|
+
P.onMessages((O) => {
|
|
665
664
|
console.log("[AriaFlow Widget] Messages updated:", O.length), S(O);
|
|
666
665
|
}), P.onConnectionChange((O) => {
|
|
667
666
|
console.log("[AriaFlow Widget] Connection state:", O), q(O);
|
|
668
|
-
})
|
|
667
|
+
});
|
|
668
|
+
const L = await P.initWidget();
|
|
669
|
+
console.log("[AriaFlow Widget] Agent config received:", L), L ? (W(L), M(!0), console.log("[AriaFlow Widget] Widget initialized successfully")) : console.error("[AriaFlow Widget] Agent config fetch failed");
|
|
669
670
|
} catch (L) {
|
|
670
671
|
console.error("[AriaFlow Widget] Initialization error:", L);
|
|
671
672
|
}
|
package/dist/widget.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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,j={},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 B(t,_,i,r,null)}function B(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?j:g[u.__i]||j,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]=B(null,_,null,null,null):K(_)?_=t.__k[o]=B(D,{children:_},null,null,null):_.constructor===void 0&&_.__b>0?_=t.__k[o]=B(_.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||j,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||j,j,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),B(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 z,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(z++,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(z++,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(z++,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),z=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=[],z=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{const V=await O.initWidget();console.log("[AriaFlow Widget] Agent config received:",V),V?(W(V),P(!0),console.log("[AriaFlow Widget] Widget initialized successfully"),O.onMessages(q=>{console.log("[AriaFlow Widget] Messages updated:",q.length),N(q)}),O.onConnectionChange(q=>{console.log("[AriaFlow Widget] Connection state:",q),te(q)})):console.error("[AriaFlow Widget] Agent config fetch failed")}catch(V){console.error("[AriaFlow Widget] Initialization error:",V)}}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(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,j={},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 B(t,_,i,r,null)}function B(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?j:g[u.__i]||j,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]=B(null,_,null,null,null):K(_)?_=t.__k[o]=B(D,{children:_},null,null,null):_.constructor===void 0&&_.__b>0?_=t.__k[o]=B(_.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||j,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||j,j,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),B(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 z,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(z++,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(z++,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(z++,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),z=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=[],z=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(q=>{console.log("[AriaFlow Widget] Messages updated:",q.length),N(q)}),O.onConnectionChange(q=>{console.log("[AriaFlow Widget] Connection state:",q),te(q)});const V=await O.initWidget();console.log("[AriaFlow Widget] Agent config received:",V),V?(W(V),P(!0),console.log("[AriaFlow Widget] Widget initialized successfully")):console.error("[AriaFlow Widget] Agent config fetch failed")}catch(V){console.error("[AriaFlow Widget] Initialization error:",V)}}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"})});
|