@ariaflowagents/widget 0.5.9 → 0.5.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/widget.js CHANGED
@@ -6,7 +6,7 @@ function F(t, e) {
6
6
  function ae(t) {
7
7
  t && t.parentNode && t.parentNode.removeChild(t);
8
8
  }
9
- function I(t, e, n) {
9
+ function D(t, e, n) {
10
10
  var i, r, o, _ = {};
11
11
  for (o in e) o == "key" ? i = e[o] : o == "ref" ? r = e[o] : _[o] = e[o];
12
12
  if (arguments.length > 2 && (_.children = arguments.length > 3 ? V.call(arguments, 2) : n), typeof t == "function" && t.defaultProps != null) for (o in t.defaultProps) _[o] === void 0 && (_[o] = t.defaultProps[o]);
@@ -16,16 +16,16 @@ function j(t, e, n, i, r) {
16
16
  var o = { type: t, props: e, key: n, ref: i, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: r ?? ++Ee, __i: -1, __u: 0 };
17
17
  return r == null && m.vnode != null && m.vnode(o), o;
18
18
  }
19
- function R(t) {
19
+ function L(t) {
20
20
  return t.children;
21
21
  }
22
22
  function J(t, e) {
23
23
  this.props = t, this.context = e;
24
24
  }
25
- function D(t, e) {
26
- if (e == null) return t.__ ? D(t.__, t.__i + 1) : null;
25
+ function R(t, e) {
26
+ if (e == null) return t.__ ? R(t.__, t.__i + 1) : null;
27
27
  for (var n; e < t.__k.length; e++) if ((n = t.__k[e]) != null && n.__e != null) return n.__e;
28
- return typeof t.type == "function" ? D(t) : null;
28
+ return typeof t.type == "function" ? R(t) : null;
29
29
  }
30
30
  function Ue(t) {
31
31
  var e, n;
@@ -41,7 +41,7 @@ function pe(t) {
41
41
  (!t.__d && (t.__d = !0) && T.push(t) && !Q.__r++ || ge != m.debounceRendering) && ((ge = m.debounceRendering) || Me)(Q);
42
42
  }
43
43
  function Q() {
44
- for (var t, e, n, i, r, o, _, a = 1; T.length; ) T.length > a && T.sort(He), t = T.shift(), a = T.length, t.__d && (n = void 0, i = void 0, r = (i = (e = t).__v).__e, o = [], _ = [], e.__P && ((n = F({}, i)).__v = i.__v + 1, m.vnode && m.vnode(n), ce(e.__P, n, i, e.__n, e.__P.namespaceURI, 32 & i.__u ? [r] : null, o, r ?? D(i), !!(32 & i.__u), _), n.__v = i.__v, n.__.__k[n.__i] = n, Re(o, n, _), i.__e = i.__ = null, n.__e != r && Ue(n)));
44
+ for (var t, e, n, i, r, o, _, a = 1; T.length; ) T.length > a && T.sort(He), t = T.shift(), a = T.length, t.__d && (n = void 0, i = void 0, r = (i = (e = t).__v).__e, o = [], _ = [], e.__P && ((n = F({}, i)).__v = i.__v + 1, m.vnode && m.vnode(n), ce(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, Re(o, n, _), i.__e = i.__ = null, n.__e != r && Ue(n)));
45
45
  Q.__r = 0;
46
46
  }
47
47
  function Ie(t, e, n, i, r, o, _, a, c, l, d) {
@@ -51,8 +51,8 @@ function Ie(t, e, n, i, r, o, _, a, c, l, d) {
51
51
  }
52
52
  function tt(t, e, n, i, r) {
53
53
  var o, _, a, c, l, d = n.length, s = d, f = 0;
54
- 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] = j(null, _, null, null, null) : Z(_) ? _ = t.__k[o] = j(R, { children: _ }, null, null, null) : _.constructor === void 0 && _.__b > 0 ? _ = t.__k[o] = j(_.type, _.props, _.key, _.ref ? _.ref : null, _.__v) : t.__k[o] = _, c = o + f, _.__ = t, _.__b = t.__b + 1, a = null, (l = _.__i = nt(_, 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;
55
- if (s) for (o = 0; o < d; o++) (a = n[o]) != null && !(2 & a.__u) && (a.__e == i && (i = D(a)), Oe(a, a));
54
+ 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] = j(null, _, null, null, null) : Z(_) ? _ = t.__k[o] = j(L, { children: _ }, null, null, null) : _.constructor === void 0 && _.__b > 0 ? _ = t.__k[o] = j(_.type, _.props, _.key, _.ref ? _.ref : null, _.__v) : t.__k[o] = _, c = o + f, _.__ = t, _.__b = t.__b + 1, a = null, (l = _.__i = nt(_, 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;
55
+ if (s) for (o = 0; o < d; o++) (a = n[o]) != null && !(2 & a.__u) && (a.__e == i && (i = R(a)), Oe(a, a));
56
56
  return i;
57
57
  }
58
58
  function De(t, e, n, i) {
@@ -61,7 +61,7 @@ function De(t, e, n, i) {
61
61
  for (r = t.__k, o = 0; r && o < r.length; o++) r[o] && (r[o].__ = t, e = De(r[o], e, n, i));
62
62
  return e;
63
63
  }
64
- t.__e != e && (i && (e && t.type && !e.parentNode && (e = D(t)), n.insertBefore(t.__e, e || null)), e = t.__e);
64
+ t.__e != e && (i && (e && t.type && !e.parentNode && (e = R(t)), n.insertBefore(t.__e, e || null)), e = t.__e);
65
65
  do
66
66
  e = e && e.nextSibling;
67
67
  while (e != null && e.nodeType == 8);
@@ -130,7 +130,7 @@ function ce(t, e, n, i, r, o, _, a, c, l) {
130
130
  } else do
131
131
  s.__d = !1, $ && $(e), d = s.render(s.props, s.state, s.context), s.state = s.__s;
132
132
  while (s.__d && ++q < 25);
133
- s.state = s.__s, s.getChildContext != null && (i = F(F({}, i), s.getChildContext())), h && !f && s.getSnapshotBeforeUpdate != null && (C = s.getSnapshotBeforeUpdate(u, w)), M = d, d != null && d.type === R && d.key == null && (M = Le(d.props.children)), a = Ie(t, Z(M) ? M : [M], e, n, i, r, o, _, a, c, l), s.base = e.__e, e.__u &= -161, s.__h.length && _.push(s), v && (s.__E = s.__ = null);
133
+ s.state = s.__s, s.getChildContext != null && (i = F(F({}, i), s.getChildContext())), h && !f && s.getSnapshotBeforeUpdate != null && (C = s.getSnapshotBeforeUpdate(u, w)), M = d, d != null && d.type === L && d.key == null && (M = Le(d.props.children)), a = Ie(t, Z(M) ? M : [M], e, n, i, r, o, _, a, c, l), s.base = e.__e, e.__u &= -161, s.__h.length && _.push(s), v && (s.__E = s.__ = null);
134
134
  } catch (N) {
135
135
  if (e.__v = null, c || o != null) if (N.then) {
136
136
  for (e.__u |= c ? 160 : 128; a && a.nodeType == 8 && a.nextSibling; ) a = a.nextSibling;
@@ -187,7 +187,7 @@ function ot(t, e, n, i, r, o, _, a, c) {
187
187
  }
188
188
  for (l in p) u = p[l], l == "children" ? f = u : l == "dangerouslySetInnerHTML" ? d = u : l == "value" ? w = u : l == "checked" ? C = u : a && typeof u != "function" || v[l] === u || K(t, l, u, v[l], r);
189
189
  if (d) a || s && (d.__html == s.__html || d.__html == t.innerHTML) || (t.innerHTML = d.__html), e.__k = [];
190
- else if (s && (t.innerHTML = ""), Ie(e.type == "template" ? t.content : t, Z(f) ? f : [f], e, n, i, h == "foreignObject" ? "http://www.w3.org/1999/xhtml" : r, o, _, o ? o[0] : n.__k && D(n, 0), a, c), o != null) for (l = o.length; l--; ) ae(o[l]);
190
+ else if (s && (t.innerHTML = ""), Ie(e.type == "template" ? t.content : t, Z(f) ? f : [f], e, n, i, h == "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--; ) ae(o[l]);
191
191
  a || (l = "value", h == "progress" && w == null ? t.removeAttribute("value") : w != null && (w !== t[l] || h == "progress" && !w || h == "option" && w != v[l]) && K(t, l, w, v[l], r), l = "checked", C != null && C != t[l] && K(t, l, C, v[l], r));
192
192
  }
193
193
  return t;
@@ -220,7 +220,7 @@ function it(t, e, n) {
220
220
  }
221
221
  function ee(t, e, n) {
222
222
  var i, r, o, _;
223
- e == document && (e = document.documentElement), m.__ && m.__(t, e), r = (i = typeof n == "function") ? null : n && n.__k || e.__k, o = [], _ = [], ce(e, t = (!i && n || e).__k = I(R, null, [t]), r || B, B, e.namespaceURI, !i && n ? [n] : r ? null : e.firstChild ? V.call(e.childNodes) : null, o, !i && n ? n : r ? r.__e : e.firstChild, i, _), Re(o, t, _);
223
+ e == document && (e = document.documentElement), m.__ && m.__(t, e), r = (i = typeof n == "function") ? null : n && n.__k || e.__k, o = [], _ = [], ce(e, t = (!i && n || e).__k = D(L, null, [t]), r || B, B, e.namespaceURI, !i && n ? [n] : r ? null : e.firstChild ? V.call(e.childNodes) : null, o, !i && n ? n : r ? r.__e : e.firstChild, i, _), Re(o, t, _);
224
224
  }
225
225
  function je(t, e) {
226
226
  ee(t, e, je);
@@ -242,7 +242,7 @@ V = Pe.slice, m = { __e: function(t, e, n, i) {
242
242
  n = this.__s != null && this.__s != this.state ? this.__s : this.__s = F({}, this.state), typeof t == "function" && (t = t(F({}, n), this.props)), t && F(n, t), t != null && this.__v && (e && this._sb.push(e), pe(this));
243
243
  }, J.prototype.forceUpdate = function(t) {
244
244
  this.__v && (this.__e = !0, t && this.__h.push(t), pe(this));
245
- }, J.prototype.render = R, T = [], Me = typeof Promise == "function" ? Promise.prototype.then.bind(Promise.resolve()) : setTimeout, He = function(t, e) {
245
+ }, J.prototype.render = L, T = [], Me = typeof Promise == "function" ? Promise.prototype.then.bind(Promise.resolve()) : setTimeout, He = function(t, e) {
246
246
  return t.__v.__b - e.__v.__b;
247
247
  }, Q.__r = 0, Te = /(PointerCapture)$|Capture$/i, le = 0, ie = ve(!1), re = ve(!0);
248
248
  function X() {
@@ -287,7 +287,7 @@ function lt(t) {
287
287
  }
288
288
  function at(t) {
289
289
  var e = new CustomEvent("_preact", { detail: {}, bubbles: !0, cancelable: !0 });
290
- this.dispatchEvent(e), this._vdom = I(lt, X({}, this._props, { context: e.detail.context }), qe(this, this._vdomComponent, t)), (this.hasAttribute("hydrate") ? je : ee)(this._vdom, this._root);
290
+ this.dispatchEvent(e), this._vdom = D(lt, X({}, this._props, { context: e.detail.context }), qe(this, this._vdomComponent, t)), (this.hasAttribute("hydrate") ? je : ee)(this._vdom, this._root);
291
291
  }
292
292
  function Ve(t) {
293
293
  return t.replace(/-(\w)/g, function(e, n) {
@@ -305,7 +305,7 @@ function ut() {
305
305
  }
306
306
  function ye(t, e) {
307
307
  var n = this, i = t.useFragment, r = ze(t, st);
308
- return I(i ? R : "slot", X({}, r, { ref: function(o) {
308
+ return D(i ? L : "slot", X({}, r, { ref: function(o) {
309
309
  o ? (n.ref = o, n._listener || (n._listener = function(_) {
310
310
  _.stopPropagation(), _.detail.context = e;
311
311
  }, o.addEventListener("_preact", n._listener))) : n.ref.removeEventListener("_preact", n._listener);
@@ -318,10 +318,10 @@ function qe(t, e, n) {
318
318
  for (o = _.length; o--; ) _[o].name !== "slot" && (r[_[o].name] = _[o].value, r[Ve(_[o].name)] = _[o].value);
319
319
  for (o = a.length; o--; ) {
320
320
  var c = qe(a[o], null, n), l = a[o].slot;
321
- l ? r[l] = I(ye, { name: l }, c) : i[o] = c;
321
+ l ? r[l] = D(ye, { name: l }, c) : i[o] = c;
322
322
  }
323
- var d = !(!n || !n.shadow), s = e ? I(ye, { useFragment: !d }, i) : i;
324
- return !d && e && (t.innerHTML = ""), I(e || t.nodeName.toLowerCase(), r, s);
323
+ var d = !(!n || !n.shadow), s = e ? D(ye, { useFragment: !d }, i) : i;
324
+ return !d && e && (t.innerHTML = ""), D(e || t.nodeName.toLowerCase(), r, s);
325
325
  }
326
326
  var dt = 0;
327
327
  function g(t, e, n, i, r, o) {
@@ -338,7 +338,7 @@ function de(t, e) {
338
338
  var n = y.__H || (y.__H = { __: [], __h: [] });
339
339
  return t >= n.__.length && n.__.push({}), n.__[t];
340
340
  }
341
- function U(t) {
341
+ function I(t) {
342
342
  return Y = 1, ft(Ge, t);
343
343
  }
344
344
  function ft(t, e, n) {
@@ -653,22 +653,22 @@ function yt({
653
653
  subtitle: w,
654
654
  emptyChatMessage: C
655
655
  }) {
656
- const [v, p] = U(!1), [h, S] = U([]), [A, E] = U(""), [$, q] = U(!1), [k, M] = U(!1), [H, W] = U(null), N = Se(null), fe = Se(null);
656
+ const [v, p] = I(!1), [h, S] = I([]), [A, E] = I(""), [$, q] = I(!1), [k, M] = I(!1), [H, W] = I(null), N = Se(null), fe = Se(null);
657
657
  xe(() => ((async () => {
658
658
  if (t && e) {
659
659
  console.log("[AriaFlow Widget] Using new agent resolution:", { agentUrl: t, agentId: e });
660
660
  const P = new vt(t, e);
661
661
  N.current = P;
662
662
  try {
663
- P.onMessages((O) => {
664
- console.log("[AriaFlow Widget] Messages updated:", O.length), S(O);
665
- }), P.onConnectionChange((O) => {
666
- console.log("[AriaFlow Widget] Connection state:", O), q(O);
663
+ P.onMessages((U) => {
664
+ console.log("[AriaFlow Widget] Messages updated:", U.length), S(U);
665
+ }), P.onConnectionChange((U) => {
666
+ console.log("[AriaFlow Widget] Connection state:", U), q(U), U && M(!0);
667
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");
670
- } catch (L) {
671
- console.error("[AriaFlow Widget] Initialization error:", L);
668
+ const O = await P.initWidget();
669
+ console.log("[AriaFlow Widget] Agent config received:", O), O ? (W(O), console.log("[AriaFlow Widget] Widget initialized successfully")) : console.error("[AriaFlow Widget] Agent config fetch failed");
670
+ } catch (O) {
671
+ console.error("[AriaFlow Widget] Initialization error:", O);
672
672
  }
673
673
  } 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.");
674
674
  })(), () => {
@@ -799,7 +799,7 @@ function yt({
799
799
  /* @__PURE__ */ g("span", { className: "ariaflow-widget-status-dot" }),
800
800
  "Connecting..."
801
801
  ] }),
802
- /* @__PURE__ */ g("div", { className: "ariaflow-widget-messages", children: h.length === 0 ? /* @__PURE__ */ g("div", { className: "ariaflow-widget-empty", children: /* @__PURE__ */ g("p", { children: $ ? Ze : "Connecting to agent..." }) }) : /* @__PURE__ */ g(R, { children: [
802
+ /* @__PURE__ */ g("div", { className: "ariaflow-widget-messages", children: h.length === 0 ? /* @__PURE__ */ g("div", { className: "ariaflow-widget-empty", children: /* @__PURE__ */ g("p", { children: $ ? Ze : "Connecting to agent..." }) }) : /* @__PURE__ */ g(L, { children: [
803
803
  h.map((x) => /* @__PURE__ */ g(
804
804
  "div",
805
805
  {
@@ -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{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"})});
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"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ariaflowagents/widget",
3
- "version": "0.5.9",
3
+ "version": "0.5.10",
4
4
  "type": "module",
5
5
  "description": "Embeddable chat widget for AriaFlow Universal Inbox",
6
6
  "main": "./dist/widget.js",