@ariaflowagents/widget 0.6.12 → 0.6.13

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
@@ -1,9 +1,9 @@
1
- var z, m, Te, D, ye, He, Ie, Ue, ue, ae, le, j = {}, De = [], lt = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i, ne = Array.isArray;
2
- function P(t, e) {
1
+ var z, m, He, D, we, Ie, Ue, De, ge, le, _e, j = {}, Re = [], _t = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i, ne = Array.isArray;
2
+ function E(t, e) {
3
3
  for (var n in e) t[n] = e[n];
4
4
  return t;
5
5
  }
6
- function ge(t) {
6
+ function de(t) {
7
7
  t && t.parentNode && t.parentNode.removeChild(t);
8
8
  }
9
9
  function O(t, e, n) {
@@ -13,7 +13,7 @@ function O(t, e, n) {
13
13
  return q(t, a, o, i, null);
14
14
  }
15
15
  function q(t, e, n, o, i) {
16
- var s = { type: t, props: e, key: n, ref: o, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: i ?? ++Te, __i: -1, __u: 0 };
16
+ var s = { type: t, props: e, key: n, ref: o, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: i ?? ++He, __i: -1, __u: 0 };
17
17
  return i == null && m.vnode != null && m.vnode(s), s;
18
18
  }
19
19
  function R(t) {
@@ -27,38 +27,38 @@ function Q(t, e) {
27
27
  for (var n; e < t.__k.length; e++) if ((n = t.__k[e]) != null && n.__e != null) return n.__e;
28
28
  return typeof t.type == "function" ? Q(t) : null;
29
29
  }
30
- function Re(t) {
30
+ function Le(t) {
31
31
  var e, n;
32
32
  if ((t = t.__) != null && t.__c != null) {
33
33
  for (t.__e = t.__c.base = null, e = 0; e < t.__k.length; e++) if ((n = t.__k[e]) != null && n.__e != null) {
34
34
  t.__e = t.__c.base = n.__e;
35
35
  break;
36
36
  }
37
- return Re(t);
37
+ return Le(t);
38
38
  }
39
39
  }
40
- function we(t) {
41
- (!t.__d && (t.__d = !0) && D.push(t) && !Z.__r++ || ye != m.debounceRendering) && ((ye = m.debounceRendering) || He)(Z);
40
+ function ve(t) {
41
+ (!t.__d && (t.__d = !0) && D.push(t) && !Z.__r++ || we != m.debounceRendering) && ((we = m.debounceRendering) || Ie)(Z);
42
42
  }
43
43
  function Z() {
44
- for (var t, e, n, o, i, s, a, _ = 1; D.length; ) D.length > _ && D.sort(Ie), t = D.shift(), _ = D.length, t.__d && (n = void 0, o = void 0, i = (o = (e = t).__v).__e, s = [], a = [], e.__P && ((n = P({}, o)).__v = o.__v + 1, m.vnode && m.vnode(n), de(e.__P, n, o, e.__n, e.__P.namespaceURI, 32 & o.__u ? [i] : null, s, i ?? Q(o), !!(32 & o.__u), a), n.__v = o.__v, n.__.__k[n.__i] = n, Qe(s, n, a), o.__e = o.__ = null, n.__e != i && Re(n)));
44
+ for (var t, e, n, o, i, s, a, _ = 1; D.length; ) D.length > _ && D.sort(Ue), t = D.shift(), _ = D.length, t.__d && (n = void 0, o = void 0, i = (o = (e = t).__v).__e, s = [], a = [], e.__P && ((n = E({}, o)).__v = o.__v + 1, m.vnode && m.vnode(n), he(e.__P, n, o, e.__n, e.__P.namespaceURI, 32 & o.__u ? [i] : null, s, i ?? Q(o), !!(32 & o.__u), a), n.__v = o.__v, n.__.__k[n.__i] = n, qe(s, n, a), o.__e = o.__ = null, n.__e != i && Le(n)));
45
45
  Z.__r = 0;
46
46
  }
47
- function Le(t, e, n, o, i, s, a, _, c, l, u) {
48
- var r, h, g, v, $, y, p, f = o && o.__k || De, F = e.length;
49
- for (c = _t(n, e, f, c, F), r = 0; r < F; r++) (g = n.__k[r]) != null && (h = g.__i == -1 ? j : f[g.__i] || j, g.__i = r, y = de(t, g, h, i, s, a, _, c, l, u), v = g.__e, g.ref && h.ref != g.ref && (h.ref && he(h.ref, null, g), u.push(g.ref, g.__c || v, g)), $ == null && v != null && ($ = v), (p = !!(4 & g.__u)) || h.__k === g.__k ? c = Oe(g, c, t, p) : typeof g.type == "function" && y !== void 0 ? c = y : v && (c = v.nextSibling), g.__u &= -7);
47
+ function Oe(t, e, n, o, i, s, a, _, c, l, u) {
48
+ var r, h, g, v, $, y, p, f = o && o.__k || Re, F = e.length;
49
+ for (c = ct(n, e, f, c, F), r = 0; r < F; r++) (g = n.__k[r]) != null && (h = g.__i == -1 ? j : f[g.__i] || j, g.__i = r, y = he(t, g, h, i, s, a, _, c, l, u), v = g.__e, g.ref && h.ref != g.ref && (h.ref && fe(h.ref, null, g), u.push(g.ref, g.__c || v, g)), $ == null && v != null && ($ = v), (p = !!(4 & g.__u)) || h.__k === g.__k ? c = Qe(g, c, t, p) : typeof g.type == "function" && y !== void 0 ? c = y : v && (c = v.nextSibling), g.__u &= -7);
50
50
  return n.__e = $, c;
51
51
  }
52
- function _t(t, e, n, o, i) {
52
+ function ct(t, e, n, o, i) {
53
53
  var s, a, _, c, l, u = n.length, r = u, h = 0;
54
- for (t.__k = new Array(i), s = 0; s < i; s++) (a = e[s]) != null && typeof a != "boolean" && typeof a != "function" ? (typeof a == "string" || typeof a == "number" || typeof a == "bigint" || a.constructor == String ? a = t.__k[s] = q(null, a, null, null, null) : ne(a) ? a = t.__k[s] = q(R, { children: a }, null, null, null) : a.constructor === void 0 && a.__b > 0 ? a = t.__k[s] = q(a.type, a.props, a.key, a.ref ? a.ref : null, a.__v) : t.__k[s] = a, c = s + h, a.__ = t, a.__b = t.__b + 1, _ = null, (l = a.__i = ct(a, n, c, r)) != -1 && (r--, (_ = n[l]) && (_.__u |= 2)), _ == null || _.__v == null ? (l == -1 && (i > u ? h-- : i < u && h++), typeof a.type != "function" && (a.__u |= 4)) : l != c && (l == c - 1 ? h-- : l == c + 1 ? h++ : (l > c ? h-- : h++, a.__u |= 4))) : t.__k[s] = null;
55
- if (r) for (s = 0; s < u; s++) (_ = n[s]) != null && !(2 & _.__u) && (_.__e == o && (o = Q(_)), je(_, _));
54
+ for (t.__k = new Array(i), s = 0; s < i; s++) (a = e[s]) != null && typeof a != "boolean" && typeof a != "function" ? (typeof a == "string" || typeof a == "number" || typeof a == "bigint" || a.constructor == String ? a = t.__k[s] = q(null, a, null, null, null) : ne(a) ? a = t.__k[s] = q(R, { children: a }, null, null, null) : a.constructor === void 0 && a.__b > 0 ? a = t.__k[s] = q(a.type, a.props, a.key, a.ref ? a.ref : null, a.__v) : t.__k[s] = a, c = s + h, a.__ = t, a.__b = t.__b + 1, _ = null, (l = a.__i = ut(a, n, c, r)) != -1 && (r--, (_ = n[l]) && (_.__u |= 2)), _ == null || _.__v == null ? (l == -1 && (i > u ? h-- : i < u && h++), typeof a.type != "function" && (a.__u |= 4)) : l != c && (l == c - 1 ? h-- : l == c + 1 ? h++ : (l > c ? h-- : h++, a.__u |= 4))) : t.__k[s] = null;
55
+ if (r) for (s = 0; s < u; s++) (_ = n[s]) != null && !(2 & _.__u) && (_.__e == o && (o = Q(_)), Be(_, _));
56
56
  return o;
57
57
  }
58
- function Oe(t, e, n, o) {
58
+ function Qe(t, e, n, o) {
59
59
  var i, s;
60
60
  if (typeof t.type == "function") {
61
- for (i = t.__k, s = 0; i && s < i.length; s++) i[s] && (i[s].__ = t, e = Oe(i[s], e, n, o));
61
+ for (i = t.__k, s = 0; i && s < i.length; s++) i[s] && (i[s].__ = t, e = Qe(i[s], e, n, o));
62
62
  return e;
63
63
  }
64
64
  t.__e != e && (o && (e && t.type && !e.parentNode && (e = Q(t)), n.insertBefore(t.__e, e || null)), e = t.__e);
@@ -67,7 +67,7 @@ function Oe(t, e, n, o) {
67
67
  while (e != null && e.nodeType == 8);
68
68
  return e;
69
69
  }
70
- function ct(t, e, n, o) {
70
+ function ut(t, e, n, o) {
71
71
  var i, s, a, _ = t.key, c = t.type, l = e[n], u = l != null && (2 & l.__u) == 0;
72
72
  if (l === null && _ == null || u && _ == l.key && c == l.type) return n;
73
73
  if (o > (u ? 1 : 0)) {
@@ -75,17 +75,17 @@ function ct(t, e, n, o) {
75
75
  }
76
76
  return -1;
77
77
  }
78
- function ve(t, e, n) {
79
- e[0] == "-" ? t.setProperty(e, n ?? "") : t[e] = n == null ? "" : typeof n != "number" || lt.test(e) ? n : n + "px";
78
+ function be(t, e, n) {
79
+ e[0] == "-" ? t.setProperty(e, n ?? "") : t[e] = n == null ? "" : typeof n != "number" || _t.test(e) ? n : n + "px";
80
80
  }
81
81
  function K(t, e, n, o, i) {
82
82
  var s, a;
83
83
  e: if (e == "style") if (typeof n == "string") t.style.cssText = n;
84
84
  else {
85
- if (typeof o == "string" && (t.style.cssText = o = ""), o) for (e in o) n && e in n || ve(t.style, e, "");
86
- if (n) for (e in n) o && n[e] == o[e] || ve(t.style, e, n[e]);
85
+ if (typeof o == "string" && (t.style.cssText = o = ""), o) for (e in o) n && e in n || be(t.style, e, "");
86
+ if (n) for (e in n) o && n[e] == o[e] || be(t.style, e, n[e]);
87
87
  }
88
- else if (e[0] == "o" && e[1] == "n") s = e != (e = e.replace(Ue, "$1")), a = e.toLowerCase(), e = a in t || e == "onFocusOut" || e == "onFocusIn" ? a.slice(2) : e.slice(2), t.l || (t.l = {}), t.l[e + s] = n, n ? o ? n.u = o.u : (n.u = ue, t.addEventListener(e, s ? le : ae, s)) : t.removeEventListener(e, s ? le : ae, s);
88
+ else if (e[0] == "o" && e[1] == "n") s = e != (e = e.replace(De, "$1")), a = e.toLowerCase(), e = a in t || e == "onFocusOut" || e == "onFocusIn" ? a.slice(2) : e.slice(2), t.l || (t.l = {}), t.l[e + s] = n, n ? o ? n.u = o.u : (n.u = ge, t.addEventListener(e, s ? _e : le, s)) : t.removeEventListener(e, s ? _e : le, s);
89
89
  else {
90
90
  if (i == "http://www.w3.org/2000/svg") e = e.replace(/xlink(H|:h)/, "h").replace(/sName$/, "s");
91
91
  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 {
@@ -96,22 +96,22 @@ function K(t, e, n, o, i) {
96
96
  typeof n == "function" || (n == null || n === !1 && e[4] != "-" ? t.removeAttribute(e) : t.setAttribute(e, e == "popover" && n == 1 ? "" : n));
97
97
  }
98
98
  }
99
- function be(t) {
99
+ function Ce(t) {
100
100
  return function(e) {
101
101
  if (this.l) {
102
102
  var n = this.l[e.type + t];
103
- if (e.t == null) e.t = ue++;
103
+ if (e.t == null) e.t = ge++;
104
104
  else if (e.t < n.u) return;
105
105
  return n(m.event ? m.event(e) : e);
106
106
  }
107
107
  };
108
108
  }
109
- function de(t, e, n, o, i, s, a, _, c, l) {
109
+ function he(t, e, n, o, i, s, a, _, c, l) {
110
110
  var u, r, h, g, v, $, y, p, f, F, x, H, W, V, A, I, U, N = e.type;
111
111
  if (e.constructor !== void 0) return null;
112
112
  128 & n.__u && (c = !!(32 & n.__u), s = [_ = e.__e = n.__e]), (u = m.__b) && u(e);
113
113
  e: if (typeof N == "function") try {
114
- if (p = e.props, f = "prototype" in N && N.prototype.render, F = (u = N.contextType) && o[u.__c], x = u ? F ? F.props.value : u.__ : o, n.__c ? y = (r = e.__c = n.__c).__ = r.__E : (f ? e.__c = r = new N(p, x) : (e.__c = r = new X(p, x), r.constructor = N, r.render = gt), F && F.sub(r), r.state || (r.state = {}), r.__n = o, h = r.__d = !0, r.__h = [], r._sb = []), f && r.__s == null && (r.__s = r.state), f && N.getDerivedStateFromProps != null && (r.__s == r.state && (r.__s = P({}, r.__s)), P(r.__s, N.getDerivedStateFromProps(p, r.__s))), g = r.props, v = r.state, r.__v = e, h) f && N.getDerivedStateFromProps == null && r.componentWillMount != null && r.componentWillMount(), f && r.componentDidMount != null && r.__h.push(r.componentDidMount);
114
+ if (p = e.props, f = "prototype" in N && N.prototype.render, F = (u = N.contextType) && o[u.__c], x = u ? F ? F.props.value : u.__ : o, n.__c ? y = (r = e.__c = n.__c).__ = r.__E : (f ? e.__c = r = new N(p, x) : (e.__c = r = new X(p, x), r.constructor = N, r.render = dt), F && F.sub(r), r.state || (r.state = {}), r.__n = o, h = r.__d = !0, r.__h = [], r._sb = []), f && r.__s == null && (r.__s = r.state), f && N.getDerivedStateFromProps != null && (r.__s == r.state && (r.__s = E({}, r.__s)), E(r.__s, N.getDerivedStateFromProps(p, r.__s))), g = r.props, v = r.state, r.__v = e, h) f && N.getDerivedStateFromProps == null && r.componentWillMount != null && r.componentWillMount(), f && r.componentDidMount != null && r.__h.push(r.componentDidMount);
115
115
  else {
116
116
  if (f && N.getDerivedStateFromProps == null && p !== g && r.componentWillReceiveProps != null && r.componentWillReceiveProps(p, x), e.__v == n.__v || !r.__e && r.shouldComponentUpdate != null && r.shouldComponentUpdate(p, r.__s, x) === !1) {
117
117
  for (e.__v != n.__v && (r.props = p, r.state = r.__s, r.__d = !1), e.__e = n.__e, e.__k = n.__k, e.__k.some(function(M) {
@@ -130,26 +130,26 @@ function de(t, e, n, o, i, s, a, _, c, l) {
130
130
  } else do
131
131
  r.__d = !1, W && W(e), u = r.render(r.props, r.state, r.context), r.state = r.__s;
132
132
  while (r.__d && ++V < 25);
133
- r.state = r.__s, r.getChildContext != null && (o = P(P({}, o), r.getChildContext())), f && !h && r.getSnapshotBeforeUpdate != null && ($ = r.getSnapshotBeforeUpdate(g, v)), I = u, u != null && u.type === R && u.key == null && (I = qe(u.props.children)), _ = Le(t, ne(I) ? I : [I], e, n, o, i, s, a, _, c, l), r.base = e.__e, e.__u &= -161, r.__h.length && a.push(r), y && (r.__E = r.__ = null);
133
+ r.state = r.__s, r.getChildContext != null && (o = E(E({}, o), r.getChildContext())), f && !h && r.getSnapshotBeforeUpdate != null && ($ = r.getSnapshotBeforeUpdate(g, v)), I = u, u != null && u.type === R && u.key == null && (I = je(u.props.children)), _ = Oe(t, ne(I) ? I : [I], e, n, o, i, s, a, _, c, l), r.base = e.__e, e.__u &= -161, r.__h.length && a.push(r), y && (r.__E = r.__ = null);
134
134
  } catch (M) {
135
135
  if (e.__v = null, c || s != null) if (M.then) {
136
136
  for (e.__u |= c ? 160 : 128; _ && _.nodeType == 8 && _.nextSibling; ) _ = _.nextSibling;
137
137
  s[s.indexOf(_)] = null, e.__e = _;
138
138
  } else {
139
- for (U = s.length; U--; ) ge(s[U]);
140
- _e(e);
139
+ for (U = s.length; U--; ) de(s[U]);
140
+ ce(e);
141
141
  }
142
- else e.__e = n.__e, e.__k = n.__k, M.then || _e(e);
142
+ else e.__e = n.__e, e.__k = n.__k, M.then || ce(e);
143
143
  m.__e(M, e, n);
144
144
  }
145
- else s == null && e.__v == n.__v ? (e.__k = n.__k, e.__e = n.__e) : _ = e.__e = ut(n.__e, e, n, o, i, s, a, c, l);
145
+ else s == null && e.__v == n.__v ? (e.__k = n.__k, e.__e = n.__e) : _ = e.__e = gt(n.__e, e, n, o, i, s, a, c, l);
146
146
  return (u = m.diffed) && u(e), 128 & e.__u ? void 0 : _;
147
147
  }
148
- function _e(t) {
149
- t && t.__c && (t.__c.__e = !0), t && t.__k && t.__k.forEach(_e);
148
+ function ce(t) {
149
+ t && t.__c && (t.__c.__e = !0), t && t.__k && t.__k.forEach(ce);
150
150
  }
151
- function Qe(t, e, n) {
152
- for (var o = 0; o < n.length; o++) he(n[o], n[++o], n[++o]);
151
+ function qe(t, e, n) {
152
+ for (var o = 0; o < n.length; o++) fe(n[o], n[++o], n[++o]);
153
153
  m.__c && m.__c(e, t), t.some(function(i) {
154
154
  try {
155
155
  t = i.__h, i.__h = [], t.some(function(s) {
@@ -160,10 +160,10 @@ function Qe(t, e, n) {
160
160
  }
161
161
  });
162
162
  }
163
- function qe(t) {
164
- return typeof t != "object" || t == null || t.__b && t.__b > 0 ? t : ne(t) ? t.map(qe) : P({}, t);
163
+ function je(t) {
164
+ return typeof t != "object" || t == null || t.__b && t.__b > 0 ? t : ne(t) ? t.map(je) : E({}, t);
165
165
  }
166
- function ut(t, e, n, o, i, s, a, _, c) {
166
+ function gt(t, e, n, o, i, s, a, _, c) {
167
167
  var l, u, r, h, g, v, $, y = n.props || j, p = e.props, f = e.type;
168
168
  if (f == "svg" ? i = "http://www.w3.org/2000/svg" : f == "math" ? i = "http://www.w3.org/1998/Math/MathML" : i || (i = "http://www.w3.org/1999/xhtml"), s != null) {
169
169
  for (l = 0; l < s.length; l++) if ((g = s[l]) && "setAttribute" in g == !!f && (f ? g.localName == f : g.nodeType == 3)) {
@@ -187,12 +187,12 @@ function ut(t, e, n, o, i, s, a, _, c) {
187
187
  }
188
188
  for (l in p) g = p[l], l == "children" ? h = g : l == "dangerouslySetInnerHTML" ? u = g : l == "value" ? v = g : l == "checked" ? $ = g : _ && typeof g != "function" || y[l] === g || K(t, l, g, y[l], i);
189
189
  if (u) _ || r && (u.__html == r.__html || u.__html == t.innerHTML) || (t.innerHTML = u.__html), e.__k = [];
190
- else if (r && (t.innerHTML = ""), Le(e.type == "template" ? t.content : t, ne(h) ? h : [h], e, n, o, f == "foreignObject" ? "http://www.w3.org/1999/xhtml" : i, s, a, s ? s[0] : n.__k && Q(n, 0), _, c), s != null) for (l = s.length; l--; ) ge(s[l]);
190
+ else if (r && (t.innerHTML = ""), Oe(e.type == "template" ? t.content : t, ne(h) ? h : [h], e, n, o, f == "foreignObject" ? "http://www.w3.org/1999/xhtml" : i, s, a, s ? s[0] : n.__k && Q(n, 0), _, c), s != null) for (l = s.length; l--; ) de(s[l]);
191
191
  _ || (l = "value", f == "progress" && v == null ? t.removeAttribute("value") : v != null && (v !== t[l] || f == "progress" && !v || f == "option" && v != y[l]) && K(t, l, v, y[l], i), l = "checked", $ != null && $ != t[l] && K(t, l, $, y[l], i));
192
192
  }
193
193
  return t;
194
194
  }
195
- function he(t, e, n) {
195
+ function fe(t, e, n) {
196
196
  try {
197
197
  if (typeof t == "function") {
198
198
  var o = typeof t.__u == "function";
@@ -202,9 +202,9 @@ function he(t, e, n) {
202
202
  m.__e(i, n);
203
203
  }
204
204
  }
205
- function je(t, e, n) {
205
+ function Be(t, e, n) {
206
206
  var o, i;
207
- if (m.unmount && m.unmount(t), (o = t.ref) && (o.current && o.current != t.__e || he(o, null, e)), (o = t.__c) != null) {
207
+ if (m.unmount && m.unmount(t), (o = t.ref) && (o.current && o.current != t.__e || fe(o, null, e)), (o = t.__c) != null) {
208
208
  if (o.componentWillUnmount) try {
209
209
  o.componentWillUnmount();
210
210
  } catch (s) {
@@ -212,39 +212,39 @@ function je(t, e, n) {
212
212
  }
213
213
  o.base = o.__P = null;
214
214
  }
215
- if (o = t.__k) for (i = 0; i < o.length; i++) o[i] && je(o[i], e, n || typeof t.type != "function");
216
- n || ge(t.__e), t.__c = t.__ = t.__e = void 0;
215
+ if (o = t.__k) for (i = 0; i < o.length; i++) o[i] && Be(o[i], e, n || typeof t.type != "function");
216
+ n || de(t.__e), t.__c = t.__ = t.__e = void 0;
217
217
  }
218
- function gt(t, e, n) {
218
+ function dt(t, e, n) {
219
219
  return this.constructor(t, n);
220
220
  }
221
221
  function oe(t, e, n) {
222
222
  var o, i, s, a;
223
- e == document && (e = document.documentElement), m.__ && m.__(t, e), i = (o = typeof n == "function") ? null : n && n.__k || e.__k, s = [], a = [], de(e, t = (!o && n || e).__k = O(R, null, [t]), i || j, j, e.namespaceURI, !o && n ? [n] : i ? null : e.firstChild ? z.call(e.childNodes) : null, s, !o && n ? n : i ? i.__e : e.firstChild, o, a), Qe(s, t, a);
223
+ e == document && (e = document.documentElement), m.__ && m.__(t, e), i = (o = typeof n == "function") ? null : n && n.__k || e.__k, s = [], a = [], he(e, t = (!o && n || e).__k = O(R, null, [t]), i || j, j, e.namespaceURI, !o && n ? [n] : i ? null : e.firstChild ? z.call(e.childNodes) : null, s, !o && n ? n : i ? i.__e : e.firstChild, o, a), qe(s, t, a);
224
224
  }
225
- function Be(t, e) {
226
- oe(t, e, Be);
225
+ function ze(t, e) {
226
+ oe(t, e, ze);
227
227
  }
228
- function ze(t, e, n) {
229
- var o, i, s, a, _ = P({}, t.props);
228
+ function Ve(t, e, n) {
229
+ var o, i, s, a, _ = E({}, t.props);
230
230
  for (s in t.type && t.type.defaultProps && (a = t.type.defaultProps), e) s == "key" ? o = e[s] : s == "ref" ? i = e[s] : _[s] = e[s] === void 0 && a != null ? a[s] : e[s];
231
231
  return arguments.length > 2 && (_.children = arguments.length > 3 ? z.call(arguments, 2) : n), q(t.type, _, o || t.key, i || t.ref, null);
232
232
  }
233
- z = De.slice, m = { __e: function(t, e, n, o) {
233
+ z = Re.slice, m = { __e: function(t, e, n, o) {
234
234
  for (var i, s, a; e = e.__; ) if ((i = e.__c) && !i.__) try {
235
235
  if ((s = i.constructor) && s.getDerivedStateFromError != null && (i.setState(s.getDerivedStateFromError(t)), a = i.__d), i.componentDidCatch != null && (i.componentDidCatch(t, o || {}), a = i.__d), a) return i.__E = i;
236
236
  } catch (_) {
237
237
  t = _;
238
238
  }
239
239
  throw t;
240
- } }, Te = 0, X.prototype.setState = function(t, e) {
240
+ } }, He = 0, X.prototype.setState = function(t, e) {
241
241
  var n;
242
- n = this.__s != null && this.__s != this.state ? this.__s : this.__s = P({}, this.state), typeof t == "function" && (t = t(P({}, n), this.props)), t && P(n, t), t != null && this.__v && (e && this._sb.push(e), we(this));
242
+ n = this.__s != null && this.__s != this.state ? this.__s : this.__s = E({}, this.state), typeof t == "function" && (t = t(E({}, n), this.props)), t && E(n, t), t != null && this.__v && (e && this._sb.push(e), ve(this));
243
243
  }, X.prototype.forceUpdate = function(t) {
244
- this.__v && (this.__e = !0, t && this.__h.push(t), we(this));
245
- }, X.prototype.render = R, D = [], He = typeof Promise == "function" ? Promise.prototype.then.bind(Promise.resolve()) : setTimeout, Ie = function(t, e) {
244
+ this.__v && (this.__e = !0, t && this.__h.push(t), ve(this));
245
+ }, X.prototype.render = R, D = [], Ie = typeof Promise == "function" ? Promise.prototype.then.bind(Promise.resolve()) : setTimeout, Ue = function(t, e) {
246
246
  return t.__v.__b - e.__v.__b;
247
- }, Z.__r = 0, Ue = /(PointerCapture)$|Capture$/i, ue = 0, ae = be(!1), le = be(!0);
247
+ }, Z.__r = 0, De = /(PointerCapture)$|Capture$/i, ge = 0, le = Ce(!1), _e = Ce(!0);
248
248
  function ee() {
249
249
  return ee = Object.assign ? Object.assign.bind() : function(t) {
250
250
  for (var e = 1; e < arguments.length; e++) {
@@ -254,21 +254,21 @@ function ee() {
254
254
  return t;
255
255
  }, ee.apply(this, arguments);
256
256
  }
257
- function Ve(t, e) {
257
+ function Je(t, e) {
258
258
  if (t == null) return {};
259
259
  var n, o, i = {}, s = Object.keys(t);
260
260
  for (o = 0; o < s.length; o++) e.indexOf(n = s[o]) >= 0 || (i[n] = t[n]);
261
261
  return i;
262
262
  }
263
- var dt = ["context", "children"], ht = ["useFragment"];
264
- function ft(t, e, n, o) {
263
+ var ht = ["context", "children"], ft = ["useFragment"];
264
+ function pt(t, e, n, o) {
265
265
  function i() {
266
266
  var s = Reflect.construct(HTMLElement, [], i);
267
267
  return s._vdomComponent = t, s._root = s, s;
268
268
  }
269
269
  return (i.prototype = Object.create(HTMLElement.prototype)).constructor = i, i.prototype.connectedCallback = function() {
270
- mt.call(this, o);
271
- }, i.prototype.attributeChangedCallback = yt, i.prototype.disconnectedCallback = wt, n = n || t.observedAttributes || Object.keys(t.propTypes || {}), i.observedAttributes = n, t.formAssociated && (i.formAssociated = !0), n.forEach(function(s) {
270
+ yt.call(this, o);
271
+ }, i.prototype.attributeChangedCallback = wt, i.prototype.disconnectedCallback = vt, n = n || t.observedAttributes || Object.keys(t.propTypes || {}), i.observedAttributes = n, t.formAssociated && (i.formAssociated = !0), n.forEach(function(s) {
272
272
  Object.defineProperty(i.prototype, s, { get: function() {
273
273
  return this._vdom ? this._vdom.props[s] : this._props[s];
274
274
  }, set: function(a) {
@@ -278,72 +278,72 @@ function ft(t, e, n, o) {
278
278
  } });
279
279
  }), customElements.define(e, i), i;
280
280
  }
281
- function pt(t) {
281
+ function mt(t) {
282
282
  this.getChildContext = function() {
283
283
  return t.context;
284
284
  };
285
- var e = t.children, n = Ve(t, dt);
286
- return ze(e, n);
285
+ var e = t.children, n = Je(t, ht);
286
+ return Ve(e, n);
287
287
  }
288
- function mt(t) {
288
+ function yt(t) {
289
289
  var e = new CustomEvent("_preact", { detail: {}, bubbles: !0, cancelable: !0 });
290
- this.dispatchEvent(e), this._vdom = O(pt, ee({}, this._props, { context: e.detail.context }), Ke(this, this._vdomComponent, t)), (this.hasAttribute("hydrate") ? Be : oe)(this._vdom, this._root);
290
+ this.dispatchEvent(e), this._vdom = O(mt, ee({}, this._props, { context: e.detail.context }), Ge(this, this._vdomComponent, t)), (this.hasAttribute("hydrate") ? ze : oe)(this._vdom, this._root);
291
291
  }
292
- function Je(t) {
292
+ function Ke(t) {
293
293
  return t.replace(/-(\w)/g, function(e, n) {
294
294
  return n ? n.toUpperCase() : "";
295
295
  });
296
296
  }
297
- function yt(t, e, n) {
297
+ function wt(t, e, n) {
298
298
  if (this._vdom) {
299
299
  var o = {};
300
- o[t] = n = n ?? void 0, o[Je(t)] = n, this._vdom = ze(this._vdom, o), oe(this._vdom, this._root);
300
+ o[t] = n = n ?? void 0, o[Ke(t)] = n, this._vdom = Ve(this._vdom, o), oe(this._vdom, this._root);
301
301
  }
302
302
  }
303
- function wt() {
303
+ function vt() {
304
304
  oe(this._vdom = null, this._root);
305
305
  }
306
- function Ce(t, e) {
307
- var n = this, o = t.useFragment, i = Ve(t, ht);
306
+ function ke(t, e) {
307
+ var n = this, o = t.useFragment, i = Je(t, ft);
308
308
  return O(o ? R : "slot", ee({}, i, { ref: function(s) {
309
309
  s ? (n.ref = s, n._listener || (n._listener = function(a) {
310
310
  a.stopPropagation(), a.detail.context = e;
311
311
  }, s.addEventListener("_preact", n._listener))) : n.ref.removeEventListener("_preact", n._listener);
312
312
  } }));
313
313
  }
314
- function Ke(t, e, n) {
314
+ function Ge(t, e, n) {
315
315
  if (t.nodeType === 3) return t.data;
316
316
  if (t.nodeType !== 1) return null;
317
317
  var o = [], i = {}, s = 0, a = t.attributes, _ = t.childNodes;
318
- for (s = a.length; s--; ) a[s].name !== "slot" && (i[a[s].name] = a[s].value, i[Je(a[s].name)] = a[s].value);
318
+ for (s = a.length; s--; ) a[s].name !== "slot" && (i[a[s].name] = a[s].value, i[Ke(a[s].name)] = a[s].value);
319
319
  for (s = _.length; s--; ) {
320
- var c = Ke(_[s], null, n), l = _[s].slot;
321
- l ? i[l] = O(Ce, { name: l }, c) : o[s] = c;
320
+ var c = Ge(_[s], null, n), l = _[s].slot;
321
+ l ? i[l] = O(ke, { name: l }, c) : o[s] = c;
322
322
  }
323
- var u = !(!n || !n.shadow), r = e ? O(Ce, { useFragment: !u }, o) : o;
323
+ var u = !(!n || !n.shadow), r = e ? O(ke, { useFragment: !u }, o) : o;
324
324
  return !u && e && (t.innerHTML = ""), O(e || t.nodeName.toLowerCase(), i, r);
325
325
  }
326
- var vt = 0;
326
+ var bt = 0;
327
327
  function d(t, e, n, o, i, s) {
328
328
  e || (e = {});
329
329
  var a, _, c = e;
330
330
  if ("ref" in c) for (_ in c = {}, e) _ == "ref" ? a = e[_] : c[_] = e[_];
331
- var l = { type: t, props: c, key: n, ref: a, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: --vt, __i: -1, __u: 0, __source: i, __self: s };
331
+ var l = { type: t, props: c, key: n, ref: a, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: --bt, __i: -1, __u: 0, __source: i, __self: s };
332
332
  if (typeof t == "function" && (a = t.defaultProps)) for (_ in a) c[_] === void 0 && (c[_] = a[_]);
333
333
  return m.vnode && m.vnode(l), l;
334
334
  }
335
- var B, w, ie, ke, te = 0, Ge = [], C = m, Ae = C.__b, Se = C.__r, $e = C.diffed, We = C.__c, xe = C.unmount, Ne = C.__;
336
- function fe(t, e) {
335
+ var B, w, re, Ae, te = 0, Xe = [], C = m, Se = C.__b, $e = C.__r, We = C.diffed, xe = C.__c, Ne = C.unmount, Me = C.__;
336
+ function pe(t, e) {
337
337
  C.__h && C.__h(w, t, te || e), te = 0;
338
338
  var n = w.__H || (w.__H = { __: [], __h: [] });
339
339
  return t >= n.__.length && n.__.push({}), n.__[t];
340
340
  }
341
- function E(t) {
342
- return te = 1, bt(Ye, t);
341
+ function T(t) {
342
+ return te = 1, Ct(Ze, t);
343
343
  }
344
- function bt(t, e, n) {
345
- var o = fe(B++, 2);
346
- if (o.t = t, !o.__c && (o.__ = [Ye(void 0, e), function(_) {
344
+ function Ct(t, e, n) {
345
+ var o = pe(B++, 2);
346
+ if (o.t = t, !o.__c && (o.__ = [Ze(void 0, e), function(_) {
347
347
  var c = o.__N ? o.__N[0] : o.__[0], l = o.t(c, _);
348
348
  c !== l && (o.__N = [l, o.__[1]], o.__c.setState({}));
349
349
  }], o.__c = w, !w.__f)) {
@@ -375,56 +375,56 @@ function bt(t, e, n) {
375
375
  }
376
376
  return o.__N || o.__;
377
377
  }
378
- function Me(t, e) {
379
- var n = fe(B++, 3);
380
- !C.__s && Xe(n.__H, e) && (n.__ = t, n.u = e, w.__H.__h.push(n));
378
+ function Fe(t, e) {
379
+ var n = pe(B++, 3);
380
+ !C.__s && Ye(n.__H, e) && (n.__ = t, n.u = e, w.__H.__h.push(n));
381
381
  }
382
- function Fe(t) {
383
- return te = 5, Ct(function() {
382
+ function Pe(t) {
383
+ return te = 5, kt(function() {
384
384
  return { current: t };
385
385
  }, []);
386
386
  }
387
- function Ct(t, e) {
388
- var n = fe(B++, 7);
389
- return Xe(n.__H, e) && (n.__ = t(), n.__H = e, n.__h = t), n.__;
387
+ function kt(t, e) {
388
+ var n = pe(B++, 7);
389
+ return Ye(n.__H, e) && (n.__ = t(), n.__H = e, n.__h = t), n.__;
390
390
  }
391
- function kt() {
392
- for (var t; t = Ge.shift(); ) if (t.__P && t.__H) try {
393
- t.__H.__h.forEach(Y), t.__H.__h.forEach(ce), t.__H.__h = [];
391
+ function At() {
392
+ for (var t; t = Xe.shift(); ) if (t.__P && t.__H) try {
393
+ t.__H.__h.forEach(Y), t.__H.__h.forEach(ue), t.__H.__h = [];
394
394
  } catch (e) {
395
395
  t.__H.__h = [], C.__e(e, t.__v);
396
396
  }
397
397
  }
398
398
  C.__b = function(t) {
399
- w = null, Ae && Ae(t);
399
+ w = null, Se && Se(t);
400
400
  }, C.__ = function(t, e) {
401
- t && e.__k && e.__k.__m && (t.__m = e.__k.__m), Ne && Ne(t, e);
401
+ t && e.__k && e.__k.__m && (t.__m = e.__k.__m), Me && Me(t, e);
402
402
  }, C.__r = function(t) {
403
- Se && Se(t), B = 0;
403
+ $e && $e(t), B = 0;
404
404
  var e = (w = t.__c).__H;
405
- e && (ie === w ? (e.__h = [], w.__h = [], e.__.forEach(function(n) {
405
+ e && (re === w ? (e.__h = [], w.__h = [], e.__.forEach(function(n) {
406
406
  n.__N && (n.__ = n.__N), n.u = n.__N = void 0;
407
- })) : (e.__h.forEach(Y), e.__h.forEach(ce), e.__h = [], B = 0)), ie = w;
407
+ })) : (e.__h.forEach(Y), e.__h.forEach(ue), e.__h = [], B = 0)), re = w;
408
408
  }, C.diffed = function(t) {
409
- $e && $e(t);
409
+ We && We(t);
410
410
  var e = t.__c;
411
- e && e.__H && (e.__H.__h.length && (Ge.push(e) !== 1 && ke === C.requestAnimationFrame || ((ke = C.requestAnimationFrame) || At)(kt)), e.__H.__.forEach(function(n) {
411
+ e && e.__H && (e.__H.__h.length && (Xe.push(e) !== 1 && Ae === C.requestAnimationFrame || ((Ae = C.requestAnimationFrame) || St)(At)), e.__H.__.forEach(function(n) {
412
412
  n.u && (n.__H = n.u), n.u = void 0;
413
- })), ie = w = null;
413
+ })), re = w = null;
414
414
  }, C.__c = function(t, e) {
415
415
  e.some(function(n) {
416
416
  try {
417
417
  n.__h.forEach(Y), n.__h = n.__h.filter(function(o) {
418
- return !o.__ || ce(o);
418
+ return !o.__ || ue(o);
419
419
  });
420
420
  } catch (o) {
421
421
  e.some(function(i) {
422
422
  i.__h && (i.__h = []);
423
423
  }), e = [], C.__e(o, n.__v);
424
424
  }
425
- }), We && We(t, e);
425
+ }), xe && xe(t, e);
426
426
  }, C.unmount = function(t) {
427
- xe && xe(t);
427
+ Ne && Ne(t);
428
428
  var e, n = t.__c;
429
429
  n && n.__H && (n.__H.__.forEach(function(o) {
430
430
  try {
@@ -434,37 +434,37 @@ C.__b = function(t) {
434
434
  }
435
435
  }), n.__H = void 0, e && C.__e(e, n.__v));
436
436
  };
437
- var Pe = typeof requestAnimationFrame == "function";
438
- function At(t) {
437
+ var Ee = typeof requestAnimationFrame == "function";
438
+ function St(t) {
439
439
  var e, n = function() {
440
- clearTimeout(o), Pe && cancelAnimationFrame(e), setTimeout(t);
440
+ clearTimeout(o), Ee && cancelAnimationFrame(e), setTimeout(t);
441
441
  }, o = setTimeout(n, 35);
442
- Pe && (e = requestAnimationFrame(n));
442
+ Ee && (e = requestAnimationFrame(n));
443
443
  }
444
444
  function Y(t) {
445
445
  var e = w, n = t.__c;
446
446
  typeof n == "function" && (t.__c = void 0, n()), w = e;
447
447
  }
448
- function ce(t) {
448
+ function ue(t) {
449
449
  var e = w;
450
450
  t.__c = t.__(), w = e;
451
451
  }
452
- function Xe(t, e) {
452
+ function Ye(t, e) {
453
453
  return !t || t.length !== e.length || e.some(function(n, o) {
454
454
  return n !== t[o];
455
455
  });
456
456
  }
457
- function Ye(t, e) {
457
+ function Ze(t, e) {
458
458
  return typeof e == "function" ? e(t) : e;
459
459
  }
460
- const St = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
460
+ const $t = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
461
461
  let G = (t = 21) => {
462
462
  let e = "", n = crypto.getRandomValues(new Uint8Array(t |= 0));
463
463
  for (; t--; )
464
- e += St[n[t] & 63];
464
+ e += $t[n[t] & 63];
465
465
  return e;
466
466
  };
467
- class $t {
467
+ class Wt {
468
468
  constructor(e, n) {
469
469
  this.agentUrl = e, this.agentId = n, this.agentConfig = null, this.ws = null, this.messageCallbacks = /* @__PURE__ */ new Set(), this.connectionCallbacks = /* @__PURE__ */ new Set(), this.streamingCallbacks = /* @__PURE__ */ new Set(), this.processingCallbacks = /* @__PURE__ */ new Set(), this.queueCallbacks = /* @__PURE__ */ new Set(), this.messages = [], this.reconnectAttempts = 0, this.maxReconnectAttempts = 5, this.reconnectDelay = 1e3, this.isAgentStreaming = !1, this.isAgentProcessing = !1, this.messageQueue = [];
470
470
  }
@@ -741,13 +741,13 @@ Result: ${JSON.stringify(n.result)}`, toolResult: n.result }
741
741
  this.ws && (this.ws.close(), this.ws = null), this.messageCallbacks.clear(), this.connectionCallbacks.clear();
742
742
  }
743
743
  }
744
- const re = {
744
+ const ae = {
745
745
  none: "0",
746
746
  small: "0.375rem",
747
747
  medium: "0.75rem",
748
748
  large: "1rem"
749
749
  };
750
- function Wt({
750
+ function xt({
751
751
  agentUrl: t,
752
752
  agentId: e,
753
753
  // Legacy props for backward compatibility
@@ -766,11 +766,11 @@ function Wt({
766
766
  subtitle: v,
767
767
  emptyChatMessage: $
768
768
  }) {
769
- const [y, p] = E(!1), [f, F] = E([]), [x, H] = E(""), [W, V] = E(!1), [A, I] = E(!1), [U, N] = E(null), [M, Ze] = E(!1), [et, tt] = E(!1), [se, nt] = E(0), J = Fe(null), pe = Fe(null);
770
- Me(() => ((async () => {
769
+ const [y, p] = T(!1), [f, F] = T([]), [x, H] = T(""), [W, V] = T(!1), [A, I] = T(!1), [U, N] = T(null), [M, et] = T(!1), [tt, nt] = T(!1), [se, ot] = T(0), J = Pe(null), me = Pe(null);
770
+ Fe(() => ((async () => {
771
771
  if (t && e) {
772
772
  console.log("[AriaFlow Widget] Using new agent resolution:", { agentUrl: t, agentId: e });
773
- const S = new $t(t, e);
773
+ const S = new Wt(t, e);
774
774
  J.current = S;
775
775
  try {
776
776
  S.onMessages((k) => {
@@ -778,11 +778,11 @@ function Wt({
778
778
  }), S.onConnectionChange((k) => {
779
779
  console.log("[AriaFlow Widget] Connection state:", k), V(k), k && I(!0);
780
780
  }), S.onStreamingChange((k) => {
781
- console.log("[AriaFlow Widget] Streaming state:", k), Ze(k);
781
+ console.log("[AriaFlow Widget] Streaming state:", k), et(k);
782
782
  }), S.onQueueChange((k) => {
783
- console.log("[AriaFlow Widget] Queue count:", k), nt(k);
783
+ console.log("[AriaFlow Widget] Queue count:", k), ot(k);
784
784
  }), S.onProcessingChange((k) => {
785
- console.log("[AriaFlow Widget] Processing state:", k), tt(k);
785
+ console.log("[AriaFlow Widget] Processing state:", k), nt(k);
786
786
  });
787
787
  const L = await S.initWidget();
788
788
  console.log("[AriaFlow Widget] Agent config received:", L), L ? (N(L), console.log("[AriaFlow Widget] Widget initialized successfully (v0.6.11)")) : console.error("[AriaFlow Widget] Agent config fetch failed");
@@ -792,10 +792,10 @@ function Wt({
792
792
  } else t && !e ? (console.warn("[AriaFlow Widget] Direct WebSocket URLs are deprecated. Use agent-url + agent-id instead."), console.error("[AriaFlow Widget] Configuration error: agent-id is required")) : o && n ? (console.warn("[AriaFlow Widget] Legacy widget config is deprecated. Use agent-url + agent-id instead."), console.error("[AriaFlow Widget] Configuration error: use agent-url + agent-id instead")) : console.error("[AriaFlow Widget] Invalid configuration. Provide agent-url and agent-id.");
793
793
  })(), () => {
794
794
  J.current?.dispose();
795
- }), [t, e, n, o]), Me(() => {
796
- pe.current?.scrollIntoView({ behavior: "smooth" });
795
+ }), [t, e, n, o]), Fe(() => {
796
+ me.current?.scrollIntoView({ behavior: "smooth" });
797
797
  }, [f]);
798
- const me = async () => {
798
+ const ye = async () => {
799
799
  if (!x.trim() || !W) return;
800
800
  const b = x.trim();
801
801
  H("");
@@ -804,11 +804,11 @@ function Wt({
804
804
  } catch (S) {
805
805
  console.error("Failed to send message:", S);
806
806
  }
807
- }, ot = (b) => {
808
- b.key === "Enter" && !b.shiftKey && (b.preventDefault(), me());
809
807
  }, st = (b) => {
808
+ b.key === "Enter" && !b.shiftKey && (b.preventDefault(), ye());
809
+ }, it = (b) => {
810
810
  !W || M || J.current?.sendMessage(b);
811
- }, it = g || U?.config.title || "Ninewells Hospital", rt = v || U?.config.subtitle || "How can we help you today?", at = $ || U?.config.emptyChatMessage || "Start a conversation with Ninewells...";
811
+ }, rt = g || U?.config.title || "Ninewells Hospital", at = v || U?.config.subtitle || "How can we help you today?", lt = $ || U?.config.emptyChatMessage || "Start a conversation with Ninewells...";
812
812
  return console.log("[AriaFlow Widget] Rendering widget component", { isInitialized: A, isOpen: y, position: a }), /* @__PURE__ */ d(
813
813
  "div",
814
814
  {
@@ -874,7 +874,7 @@ function Wt({
874
874
  className: "ariaflow-widget-window",
875
875
  style: {
876
876
  backgroundColor: s === "dark" && l ? l : void 0,
877
- borderRadius: re[c]
877
+ borderRadius: ae[c]
878
878
  },
879
879
  children: [
880
880
  /* @__PURE__ */ d(
@@ -883,12 +883,12 @@ function Wt({
883
883
  className: "ariaflow-widget-header",
884
884
  style: {
885
885
  backgroundColor: u,
886
- borderRadius: c === "none" ? "0" : `${re[c]} ${re[c]} 0 0`
886
+ borderRadius: c === "none" ? "0" : `${ae[c]} ${ae[c]} 0 0`
887
887
  },
888
888
  children: [
889
889
  /* @__PURE__ */ d("div", { className: "ariaflow-widget-header-content", children: /* @__PURE__ */ d("div", { className: "ariaflow-widget-title-group", children: [
890
- /* @__PURE__ */ d("h3", { className: "ariaflow-widget-title", children: it }),
891
- /* @__PURE__ */ d("p", { className: "ariaflow-widget-subtitle", children: rt })
890
+ /* @__PURE__ */ d("h3", { className: "ariaflow-widget-title", children: rt }),
891
+ /* @__PURE__ */ d("p", { className: "ariaflow-widget-subtitle", children: at })
892
892
  ] }) }),
893
893
  /* @__PURE__ */ d(
894
894
  "button",
@@ -920,7 +920,7 @@ function Wt({
920
920
  /* @__PURE__ */ d("span", { className: "ariaflow-widget-status-dot" }),
921
921
  "Connecting..."
922
922
  ] }),
923
- /* @__PURE__ */ d("div", { className: "ariaflow-widget-messages", children: f.length === 0 ? /* @__PURE__ */ d("div", { className: "ariaflow-widget-empty", children: /* @__PURE__ */ d("p", { children: W ? at : "Connecting to agent..." }) }) : /* @__PURE__ */ d(R, { children: [
923
+ /* @__PURE__ */ d("div", { className: "ariaflow-widget-messages", children: f.length === 0 ? /* @__PURE__ */ d("div", { className: "ariaflow-widget-empty", children: /* @__PURE__ */ d("p", { children: W ? lt : "Connecting to agent..." }) }) : /* @__PURE__ */ d(R, { children: [
924
924
  f.map((b, S) => (f.length - 1, b.role === "tool" ? null : /* @__PURE__ */ d(
925
925
  "div",
926
926
  {
@@ -936,30 +936,37 @@ function Wt({
936
936
  },
937
937
  b.id
938
938
  ))),
939
- /* @__PURE__ */ d("div", { ref: pe }),
940
- et && !M && /* @__PURE__ */ d("div", { className: "ariaflow-widget-message ariaflow-widget-message-assistant", children: /* @__PURE__ */ d("div", { className: "ariaflow-widget-message-bubble", children: /* @__PURE__ */ d("span", { className: "ariaflow-widget-typing-indicator", children: [
939
+ /* @__PURE__ */ d("div", { ref: me }),
940
+ tt && !M && /* @__PURE__ */ d("div", { className: "ariaflow-widget-message ariaflow-widget-message-assistant", children: /* @__PURE__ */ d("div", { className: "ariaflow-widget-message-bubble", children: /* @__PURE__ */ d("span", { className: "ariaflow-widget-typing-indicator", children: [
941
941
  /* @__PURE__ */ d("span", { children: "•" }),
942
942
  /* @__PURE__ */ d("span", { children: "•" }),
943
943
  /* @__PURE__ */ d("span", { children: "•" })
944
944
  ] }) }) })
945
945
  ] }) }),
946
946
  !M && (() => {
947
- const b = [...f].reverse(), S = b.findIndex((T) => T.role === "user"), k = (S === -1 ? b : b.slice(0, S)).find((T) => T.suggestions && T.suggestions.length > 0);
948
- return k && k.suggestions ? /* @__PURE__ */ d("div", { className: "ariaflow-widget-suggestions", children: k.suggestions.map((T) => /* @__PURE__ */ d(
949
- "button",
950
- {
951
- className: "ariaflow-widget-chip",
952
- onClick: () => st(T),
953
- style: {
954
- borderColor: u,
955
- color: u,
956
- backgroundColor: "rgba(255, 255, 255, 0.95)",
957
- backdropFilter: "blur(4px)"
958
- },
959
- children: T
960
- },
961
- T
962
- )) }) : null;
947
+ const b = [...f].reverse(), S = b.findIndex((P) => P.role === "user"), k = (S === -1 ? b : b.slice(0, S)).find(
948
+ (P) => P.suggestions && P.suggestions.length > 0 || P.role === "tool" && P.toolCall?.name === "suggest_options" && P.toolCall.arguments?.options?.length > 0
949
+ );
950
+ if (k) {
951
+ const P = k.suggestions || k.toolCall?.arguments?.options || [];
952
+ if (P.length > 0)
953
+ return /* @__PURE__ */ d("div", { className: "ariaflow-widget-suggestions", children: P.map((ie) => /* @__PURE__ */ d(
954
+ "button",
955
+ {
956
+ className: "ariaflow-widget-chip",
957
+ onClick: () => it(ie),
958
+ style: {
959
+ borderColor: u,
960
+ color: u,
961
+ backgroundColor: "rgba(255, 255, 255, 0.95)",
962
+ backdropFilter: "blur(4px)"
963
+ },
964
+ children: ie
965
+ },
966
+ ie
967
+ )) });
968
+ }
969
+ return null;
963
970
  })(),
964
971
  /* @__PURE__ */ d("div", { className: "ariaflow-widget-input", children: [
965
972
  /* @__PURE__ */ d(
@@ -967,7 +974,7 @@ function Wt({
967
974
  {
968
975
  value: x,
969
976
  onInput: (b) => H(b.target.value),
970
- onKeyDown: ot,
977
+ onKeyDown: st,
971
978
  placeholder: W ? M ? se > 0 ? `Agent is responding... (${se} message${se > 1 ? "s" : ""} queued)` : "Agent is responding..." : "Type your message..." : "Connecting...",
972
979
  rows: 1,
973
980
  disabled: !W
@@ -977,7 +984,7 @@ function Wt({
977
984
  "button",
978
985
  {
979
986
  className: "ariaflow-widget-send",
980
- onClick: me,
987
+ onClick: ye,
981
988
  disabled: !x.trim() || !W,
982
989
  style: { backgroundColor: u },
983
990
  "aria-label": "Send message",
@@ -1006,8 +1013,8 @@ function Wt({
1006
1013
  }
1007
1014
  );
1008
1015
  }
1009
- ft(
1010
- Wt,
1016
+ pt(
1017
+ xt,
1011
1018
  "ariaflow-widget",
1012
1019
  // Properties to observe from HTML attributes (mirror Vapi's naming convention)
1013
1020
  [
@@ -1033,12 +1040,12 @@ ft(
1033
1040
  // Shadow DOM (optional, set to false for light DOM)
1034
1041
  !1
1035
1042
  );
1036
- typeof document < "u" && (document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", Ee) : Ee());
1037
- function Ee() {
1043
+ typeof document < "u" && (document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", Te) : Te());
1044
+ function Te() {
1038
1045
  const t = document.querySelectorAll("ariaflow-widget");
1039
1046
  console.log(`[AriaFlow] Initializing ${t.length} widget(s)`);
1040
1047
  }
1041
1048
  export {
1042
- Wt as Widget,
1043
- $t as WidgetClient
1049
+ xt as Widget,
1050
+ Wt as WidgetClient
1044
1051
  };
@@ -1,4 +1,4 @@
1
- (function(I,T){typeof exports=="object"&&typeof module<"u"?T(exports):typeof define=="function"&&define.amd?define(["exports"],T):(I=typeof globalThis<"u"?globalThis:I||self,T(I.AriaFlowWidget={}))})(this,function(I){"use strict";var T,m,me,U,ye,we,ve,be,ie,re,ae,B={},Ce=[],nt=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,J=Array.isArray;function F(t,e){for(var n in e)t[n]=e[n];return t}function le(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function Q(t,e,n){var o,i,s,a={};for(s in e)s=="key"?o=e[s]:s=="ref"?i=e[s]:a[s]=e[s];if(arguments.length>2&&(a.children=arguments.length>3?T.call(arguments,2):n),typeof t=="function"&&t.defaultProps!=null)for(s in t.defaultProps)a[s]===void 0&&(a[s]=t.defaultProps[s]);return z(t,a,o,i,null)}function z(t,e,n,o,i){var s={type:t,props:e,key:n,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:i??++me,__i:-1,__u:0};return i==null&&m.vnode!=null&&m.vnode(s),s}function D(t){return t.children}function K(t,e){this.props=t,this.context=e}function q(t,e){if(e==null)return t.__?q(t.__,t.__i+1):null;for(var n;e<t.__k.length;e++)if((n=t.__k[e])!=null&&n.__e!=null)return n.__e;return typeof t.type=="function"?q(t):null}function ke(t){var e,n;if((t=t.__)!=null&&t.__c!=null){for(t.__e=t.__c.base=null,e=0;e<t.__k.length;e++)if((n=t.__k[e])!=null&&n.__e!=null){t.__e=t.__c.base=n.__e;break}return ke(t)}}function Ae(t){(!t.__d&&(t.__d=!0)&&U.push(t)&&!G.__r++||ye!=m.debounceRendering)&&((ye=m.debounceRendering)||we)(G)}function G(){for(var t,e,n,o,i,s,a,_=1;U.length;)U.length>_&&U.sort(ve),t=U.shift(),_=U.length,t.__d&&(n=void 0,o=void 0,i=(o=(e=t).__v).__e,s=[],a=[],e.__P&&((n=F({},o)).__v=o.__v+1,m.vnode&&m.vnode(n),_e(e.__P,n,o,e.__n,e.__P.namespaceURI,32&o.__u?[i]:null,s,i??q(o),!!(32&o.__u),a),n.__v=o.__v,n.__.__k[n.__i]=n,Ne(s,n,a),o.__e=o.__=null,n.__e!=i&&ke(n)));G.__r=0}function Se(t,e,n,o,i,s,a,_,c,l,u){var r,h,g,b,W,w,p,f=o&&o.__k||Ce,P=e.length;for(c=ot(n,e,f,c,P),r=0;r<P;r++)(g=n.__k[r])!=null&&(h=g.__i==-1?B:f[g.__i]||B,g.__i=r,w=_e(t,g,h,i,s,a,_,c,l,u),b=g.__e,g.ref&&h.ref!=g.ref&&(h.ref&&ue(h.ref,null,g),u.push(g.ref,g.__c||b,g)),W==null&&b!=null&&(W=b),(p=!!(4&g.__u))||h.__k===g.__k?c=We(g,c,t,p):typeof g.type=="function"&&w!==void 0?c=w:b&&(c=b.nextSibling),g.__u&=-7);return n.__e=W,c}function ot(t,e,n,o,i){var s,a,_,c,l,u=n.length,r=u,h=0;for(t.__k=new Array(i),s=0;s<i;s++)(a=e[s])!=null&&typeof a!="boolean"&&typeof a!="function"?(typeof a=="string"||typeof a=="number"||typeof a=="bigint"||a.constructor==String?a=t.__k[s]=z(null,a,null,null,null):J(a)?a=t.__k[s]=z(D,{children:a},null,null,null):a.constructor===void 0&&a.__b>0?a=t.__k[s]=z(a.type,a.props,a.key,a.ref?a.ref:null,a.__v):t.__k[s]=a,c=s+h,a.__=t,a.__b=t.__b+1,_=null,(l=a.__i=st(a,n,c,r))!=-1&&(r--,(_=n[l])&&(_.__u|=2)),_==null||_.__v==null?(l==-1&&(i>u?h--:i<u&&h++),typeof a.type!="function"&&(a.__u|=4)):l!=c&&(l==c-1?h--:l==c+1?h++:(l>c?h--:h++,a.__u|=4))):t.__k[s]=null;if(r)for(s=0;s<u;s++)(_=n[s])!=null&&!(2&_.__u)&&(_.__e==o&&(o=q(_)),Fe(_,_));return o}function We(t,e,n,o){var i,s;if(typeof t.type=="function"){for(i=t.__k,s=0;i&&s<i.length;s++)i[s]&&(i[s].__=t,e=We(i[s],e,n,o));return e}t.__e!=e&&(o&&(e&&t.type&&!e.parentNode&&(e=q(t)),n.insertBefore(t.__e,e||null)),e=t.__e);do e=e&&e.nextSibling;while(e!=null&&e.nodeType==8);return e}function st(t,e,n,o){var i,s,a,_=t.key,c=t.type,l=e[n],u=l!=null&&(2&l.__u)==0;if(l===null&&_==null||u&&_==l.key&&c==l.type)return n;if(o>(u?1:0)){for(i=n-1,s=n+1;i>=0||s<e.length;)if((l=e[a=i>=0?i--:s++])!=null&&!(2&l.__u)&&_==l.key&&c==l.type)return a}return-1}function $e(t,e,n){e[0]=="-"?t.setProperty(e,n??""):t[e]=n==null?"":typeof n!="number"||nt.test(e)?n:n+"px"}function X(t,e,n,o,i){var s,a;e:if(e=="style")if(typeof n=="string")t.style.cssText=n;else{if(typeof o=="string"&&(t.style.cssText=o=""),o)for(e in o)n&&e in n||$e(t.style,e,"");if(n)for(e in n)o&&n[e]==o[e]||$e(t.style,e,n[e])}else if(e[0]=="o"&&e[1]=="n")s=e!=(e=e.replace(be,"$1")),a=e.toLowerCase(),e=a in t||e=="onFocusOut"||e=="onFocusIn"?a.slice(2):e.slice(2),t.l||(t.l={}),t.l[e+s]=n,n?o?n.u=o.u:(n.u=ie,t.addEventListener(e,s?ae:re,s)):t.removeEventListener(e,s?ae:re,s);else{if(i=="http://www.w3.org/2000/svg")e=e.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(e!="width"&&e!="height"&&e!="href"&&e!="list"&&e!="form"&&e!="tabIndex"&&e!="download"&&e!="rowSpan"&&e!="colSpan"&&e!="role"&&e!="popover"&&e in t)try{t[e]=n??"";break e}catch{}typeof n=="function"||(n==null||n===!1&&e[4]!="-"?t.removeAttribute(e):t.setAttribute(e,e=="popover"&&n==1?"":n))}}function xe(t){return function(e){if(this.l){var n=this.l[e.type+t];if(e.t==null)e.t=ie++;else if(e.t<n.u)return;return n(m.event?m.event(e):e)}}}function _e(t,e,n,o,i,s,a,_,c,l){var u,r,h,g,b,W,w,p,f,P,x,R,$,oe,A,O,L,N=e.type;if(e.constructor!==void 0)return null;128&n.__u&&(c=!!(32&n.__u),s=[_=e.__e=n.__e]),(u=m.__b)&&u(e);e:if(typeof N=="function")try{if(p=e.props,f="prototype"in N&&N.prototype.render,P=(u=N.contextType)&&o[u.__c],x=u?P?P.props.value:u.__:o,n.__c?w=(r=e.__c=n.__c).__=r.__E:(f?e.__c=r=new N(p,x):(e.__c=r=new K(p,x),r.constructor=N,r.render=rt),P&&P.sub(r),r.state||(r.state={}),r.__n=o,h=r.__d=!0,r.__h=[],r._sb=[]),f&&r.__s==null&&(r.__s=r.state),f&&N.getDerivedStateFromProps!=null&&(r.__s==r.state&&(r.__s=F({},r.__s)),F(r.__s,N.getDerivedStateFromProps(p,r.__s))),g=r.props,b=r.state,r.__v=e,h)f&&N.getDerivedStateFromProps==null&&r.componentWillMount!=null&&r.componentWillMount(),f&&r.componentDidMount!=null&&r.__h.push(r.componentDidMount);else{if(f&&N.getDerivedStateFromProps==null&&p!==g&&r.componentWillReceiveProps!=null&&r.componentWillReceiveProps(p,x),e.__v==n.__v||!r.__e&&r.shouldComponentUpdate!=null&&r.shouldComponentUpdate(p,r.__s,x)===!1){for(e.__v!=n.__v&&(r.props=p,r.state=r.__s,r.__d=!1),e.__e=n.__e,e.__k=n.__k,e.__k.some(function(M){M&&(M.__=e)}),R=0;R<r._sb.length;R++)r.__h.push(r._sb[R]);r._sb=[],r.__h.length&&a.push(r);break e}r.componentWillUpdate!=null&&r.componentWillUpdate(p,r.__s,x),f&&r.componentDidUpdate!=null&&r.__h.push(function(){r.componentDidUpdate(g,b,W)})}if(r.context=x,r.props=p,r.__P=t,r.__e=!1,$=m.__r,oe=0,f){for(r.state=r.__s,r.__d=!1,$&&$(e),u=r.render(r.props,r.state,r.context),A=0;A<r._sb.length;A++)r.__h.push(r._sb[A]);r._sb=[]}else do r.__d=!1,$&&$(e),u=r.render(r.props,r.state,r.context),r.state=r.__s;while(r.__d&&++oe<25);r.state=r.__s,r.getChildContext!=null&&(o=F(F({},o),r.getChildContext())),f&&!h&&r.getSnapshotBeforeUpdate!=null&&(W=r.getSnapshotBeforeUpdate(g,b)),O=u,u!=null&&u.type===D&&u.key==null&&(O=Me(u.props.children)),_=Se(t,J(O)?O:[O],e,n,o,i,s,a,_,c,l),r.base=e.__e,e.__u&=-161,r.__h.length&&a.push(r),w&&(r.__E=r.__=null)}catch(M){if(e.__v=null,c||s!=null)if(M.then){for(e.__u|=c?160:128;_&&_.nodeType==8&&_.nextSibling;)_=_.nextSibling;s[s.indexOf(_)]=null,e.__e=_}else{for(L=s.length;L--;)le(s[L]);ce(e)}else e.__e=n.__e,e.__k=n.__k,M.then||ce(e);m.__e(M,e,n)}else s==null&&e.__v==n.__v?(e.__k=n.__k,e.__e=n.__e):_=e.__e=it(n.__e,e,n,o,i,s,a,c,l);return(u=m.diffed)&&u(e),128&e.__u?void 0:_}function ce(t){t&&t.__c&&(t.__c.__e=!0),t&&t.__k&&t.__k.forEach(ce)}function Ne(t,e,n){for(var o=0;o<n.length;o++)ue(n[o],n[++o],n[++o]);m.__c&&m.__c(e,t),t.some(function(i){try{t=i.__h,i.__h=[],t.some(function(s){s.call(i)})}catch(s){m.__e(s,i.__v)}})}function Me(t){return typeof t!="object"||t==null||t.__b&&t.__b>0?t:J(t)?t.map(Me):F({},t)}function it(t,e,n,o,i,s,a,_,c){var l,u,r,h,g,b,W,w=n.props||B,p=e.props,f=e.type;if(f=="svg"?i="http://www.w3.org/2000/svg":f=="math"?i="http://www.w3.org/1998/Math/MathML":i||(i="http://www.w3.org/1999/xhtml"),s!=null){for(l=0;l<s.length;l++)if((g=s[l])&&"setAttribute"in g==!!f&&(f?g.localName==f:g.nodeType==3)){t=g,s[l]=null;break}}if(t==null){if(f==null)return document.createTextNode(p);t=document.createElementNS(i,f,p.is&&p),_&&(m.__m&&m.__m(e,s),_=!1),s=null}if(f==null)w===p||_&&t.data==p||(t.data=p);else{if(s=s&&T.call(t.childNodes),!_&&s!=null)for(w={},l=0;l<t.attributes.length;l++)w[(g=t.attributes[l]).name]=g.value;for(l in w)if(g=w[l],l!="children"){if(l=="dangerouslySetInnerHTML")r=g;else if(!(l in p)){if(l=="value"&&"defaultValue"in p||l=="checked"&&"defaultChecked"in p)continue;X(t,l,null,g,i)}}for(l in p)g=p[l],l=="children"?h=g:l=="dangerouslySetInnerHTML"?u=g:l=="value"?b=g:l=="checked"?W=g:_&&typeof g!="function"||w[l]===g||X(t,l,g,w[l],i);if(u)_||r&&(u.__html==r.__html||u.__html==t.innerHTML)||(t.innerHTML=u.__html),e.__k=[];else if(r&&(t.innerHTML=""),Se(e.type=="template"?t.content:t,J(h)?h:[h],e,n,o,f=="foreignObject"?"http://www.w3.org/1999/xhtml":i,s,a,s?s[0]:n.__k&&q(n,0),_,c),s!=null)for(l=s.length;l--;)le(s[l]);_||(l="value",f=="progress"&&b==null?t.removeAttribute("value"):b!=null&&(b!==t[l]||f=="progress"&&!b||f=="option"&&b!=w[l])&&X(t,l,b,w[l],i),l="checked",W!=null&&W!=t[l]&&X(t,l,W,w[l],i))}return t}function ue(t,e,n){try{if(typeof t=="function"){var o=typeof t.__u=="function";o&&t.__u(),o&&e==null||(t.__u=t(e))}else t.current=e}catch(i){m.__e(i,n)}}function Fe(t,e,n){var o,i;if(m.unmount&&m.unmount(t),(o=t.ref)&&(o.current&&o.current!=t.__e||ue(o,null,e)),(o=t.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(s){m.__e(s,e)}o.base=o.__P=null}if(o=t.__k)for(i=0;i<o.length;i++)o[i]&&Fe(o[i],e,n||typeof t.type!="function");n||le(t.__e),t.__c=t.__=t.__e=void 0}function rt(t,e,n){return this.constructor(t,n)}function Y(t,e,n){var o,i,s,a;e==document&&(e=document.documentElement),m.__&&m.__(t,e),i=(o=typeof n=="function")?null:n&&n.__k||e.__k,s=[],a=[],_e(e,t=(!o&&n||e).__k=Q(D,null,[t]),i||B,B,e.namespaceURI,!o&&n?[n]:i?null:e.firstChild?T.call(e.childNodes):null,s,!o&&n?n:i?i.__e:e.firstChild,o,a),Ne(s,t,a)}function Pe(t,e){Y(t,e,Pe)}function Te(t,e,n){var o,i,s,a,_=F({},t.props);for(s in t.type&&t.type.defaultProps&&(a=t.type.defaultProps),e)s=="key"?o=e[s]:s=="ref"?i=e[s]:_[s]=e[s]===void 0&&a!=null?a[s]:e[s];return arguments.length>2&&(_.children=arguments.length>3?T.call(arguments,2):n),z(t.type,_,o||t.key,i||t.ref,null)}T=Ce.slice,m={__e:function(t,e,n,o){for(var i,s,a;e=e.__;)if((i=e.__c)&&!i.__)try{if((s=i.constructor)&&s.getDerivedStateFromError!=null&&(i.setState(s.getDerivedStateFromError(t)),a=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(t,o||{}),a=i.__d),a)return i.__E=i}catch(_){t=_}throw t}},me=0,K.prototype.setState=function(t,e){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=F({},this.state),typeof t=="function"&&(t=t(F({},n),this.props)),t&&F(n,t),t!=null&&this.__v&&(e&&this._sb.push(e),Ae(this))},K.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),Ae(this))},K.prototype.render=D,U=[],we=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,ve=function(t,e){return t.__v.__b-e.__v.__b},G.__r=0,be=/(PointerCapture)$|Capture$/i,ie=0,re=xe(!1),ae=xe(!0);function Z(){return Z=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t},Z.apply(this,arguments)}function Ee(t,e){if(t==null)return{};var n,o,i={},s=Object.keys(t);for(o=0;o<s.length;o++)e.indexOf(n=s[o])>=0||(i[n]=t[n]);return i}var at=["context","children"],lt=["useFragment"];function _t(t,e,n,o){function i(){var s=Reflect.construct(HTMLElement,[],i);return s._vdomComponent=t,s._root=s,s}return(i.prototype=Object.create(HTMLElement.prototype)).constructor=i,i.prototype.connectedCallback=function(){ut.call(this,o)},i.prototype.attributeChangedCallback=gt,i.prototype.disconnectedCallback=dt,n=n||t.observedAttributes||Object.keys(t.propTypes||{}),i.observedAttributes=n,t.formAssociated&&(i.formAssociated=!0),n.forEach(function(s){Object.defineProperty(i.prototype,s,{get:function(){return this._vdom?this._vdom.props[s]:this._props[s]},set:function(a){this._vdom?this.attributeChangedCallback(s,null,a):(this._props||(this._props={}),this._props[s]=a);var _=typeof a;a!=null&&_!=="string"&&_!=="boolean"&&_!=="number"||this.setAttribute(s,a)}})}),customElements.define(e,i),i}function ct(t){this.getChildContext=function(){return t.context};var e=t.children,n=Ee(t,at);return Te(e,n)}function ut(t){var e=new CustomEvent("_preact",{detail:{},bubbles:!0,cancelable:!0});this.dispatchEvent(e),this._vdom=Q(ct,Z({},this._props,{context:e.detail.context}),Ue(this,this._vdomComponent,t)),(this.hasAttribute("hydrate")?Pe:Y)(this._vdom,this._root)}function He(t){return t.replace(/-(\w)/g,function(e,n){return n?n.toUpperCase():""})}function gt(t,e,n){if(this._vdom){var o={};o[t]=n=n??void 0,o[He(t)]=n,this._vdom=Te(this._vdom,o),Y(this._vdom,this._root)}}function dt(){Y(this._vdom=null,this._root)}function Ie(t,e){var n=this,o=t.useFragment,i=Ee(t,lt);return Q(o?D:"slot",Z({},i,{ref:function(s){s?(n.ref=s,n._listener||(n._listener=function(a){a.stopPropagation(),a.detail.context=e},s.addEventListener("_preact",n._listener))):n.ref.removeEventListener("_preact",n._listener)}}))}function Ue(t,e,n){if(t.nodeType===3)return t.data;if(t.nodeType!==1)return null;var o=[],i={},s=0,a=t.attributes,_=t.childNodes;for(s=a.length;s--;)a[s].name!=="slot"&&(i[a[s].name]=a[s].value,i[He(a[s].name)]=a[s].value);for(s=_.length;s--;){var c=Ue(_[s],null,n),l=_[s].slot;l?i[l]=Q(Ie,{name:l},c):o[s]=c}var u=!(!n||!n.shadow),r=e?Q(Ie,{useFragment:!u},o):o;return!u&&e&&(t.innerHTML=""),Q(e||t.nodeName.toLowerCase(),i,r)}var ht=0;function d(t,e,n,o,i,s){e||(e={});var a,_,c=e;if("ref"in c)for(_ in c={},e)_=="ref"?a=e[_]:c[_]=e[_];var l={type:t,props:c,key:n,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--ht,__i:-1,__u:0,__source:i,__self:s};if(typeof t=="function"&&(a=t.defaultProps))for(_ in a)c[_]===void 0&&(c[_]=a[_]);return m.vnode&&m.vnode(l),l}var V,y,ge,De,ee=0,Re=[],v=m,Oe=v.__b,Le=v.__r,Qe=v.diffed,qe=v.__c,je=v.unmount,Be=v.__;function de(t,e){v.__h&&v.__h(y,t,ee||e),ee=0;var n=y.__H||(y.__H={__:[],__h:[]});return t>=n.__.length&&n.__.push({}),n.__[t]}function E(t){return ee=1,ft(Ge,t)}function ft(t,e,n){var o=de(V++,2);if(o.t=t,!o.__c&&(o.__=[Ge(void 0,e),function(_){var c=o.__N?o.__N[0]:o.__[0],l=o.t(c,_);c!==l&&(o.__N=[l,o.__[1]],o.__c.setState({}))}],o.__c=y,!y.__f)){var i=function(_,c,l){if(!o.__c.__H)return!0;var u=o.__c.__H.__.filter(function(h){return!!h.__c});if(u.every(function(h){return!h.__N}))return!s||s.call(this,_,c,l);var r=o.__c.props!==_;return u.forEach(function(h){if(h.__N){var g=h.__[0];h.__=h.__N,h.__N=void 0,g!==h.__[0]&&(r=!0)}}),s&&s.call(this,_,c,l)||r};y.__f=!0;var s=y.shouldComponentUpdate,a=y.componentWillUpdate;y.componentWillUpdate=function(_,c,l){if(this.__e){var u=s;s=void 0,i(_,c,l),s=u}a&&a.call(this,_,c,l)},y.shouldComponentUpdate=i}return o.__N||o.__}function ze(t,e){var n=de(V++,3);!v.__s&&Ke(n.__H,e)&&(n.__=t,n.u=e,y.__H.__h.push(n))}function Ve(t){return ee=5,pt(function(){return{current:t}},[])}function pt(t,e){var n=de(V++,7);return Ke(n.__H,e)&&(n.__=t(),n.__H=e,n.__h=t),n.__}function mt(){for(var t;t=Re.shift();)if(t.__P&&t.__H)try{t.__H.__h.forEach(te),t.__H.__h.forEach(he),t.__H.__h=[]}catch(e){t.__H.__h=[],v.__e(e,t.__v)}}v.__b=function(t){y=null,Oe&&Oe(t)},v.__=function(t,e){t&&e.__k&&e.__k.__m&&(t.__m=e.__k.__m),Be&&Be(t,e)},v.__r=function(t){Le&&Le(t),V=0;var e=(y=t.__c).__H;e&&(ge===y?(e.__h=[],y.__h=[],e.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(e.__h.forEach(te),e.__h.forEach(he),e.__h=[],V=0)),ge=y},v.diffed=function(t){Qe&&Qe(t);var e=t.__c;e&&e.__H&&(e.__H.__h.length&&(Re.push(e)!==1&&De===v.requestAnimationFrame||((De=v.requestAnimationFrame)||yt)(mt)),e.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),ge=y=null},v.__c=function(t,e){e.some(function(n){try{n.__h.forEach(te),n.__h=n.__h.filter(function(o){return!o.__||he(o)})}catch(o){e.some(function(i){i.__h&&(i.__h=[])}),e=[],v.__e(o,n.__v)}}),qe&&qe(t,e)},v.unmount=function(t){je&&je(t);var e,n=t.__c;n&&n.__H&&(n.__H.__.forEach(function(o){try{te(o)}catch(i){e=i}}),n.__H=void 0,e&&v.__e(e,n.__v))};var Je=typeof requestAnimationFrame=="function";function yt(t){var e,n=function(){clearTimeout(o),Je&&cancelAnimationFrame(e),setTimeout(t)},o=setTimeout(n,35);Je&&(e=requestAnimationFrame(n))}function te(t){var e=y,n=t.__c;typeof n=="function"&&(t.__c=void 0,n()),y=e}function he(t){var e=y;t.__c=t.__(),y=e}function Ke(t,e){return!t||t.length!==e.length||e.some(function(n,o){return n!==t[o]})}function Ge(t,e){return typeof e=="function"?e(t):e}const wt="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let ne=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t|=0));for(;t--;)e+=wt[n[t]&63];return e};class Xe{constructor(e,n){this.agentUrl=e,this.agentId=n,this.agentConfig=null,this.ws=null,this.messageCallbacks=new Set,this.connectionCallbacks=new Set,this.streamingCallbacks=new Set,this.processingCallbacks=new Set,this.queueCallbacks=new Set,this.messages=[],this.reconnectAttempts=0,this.maxReconnectAttempts=5,this.reconnectDelay=1e3,this.isAgentStreaming=!1,this.isAgentProcessing=!1,this.messageQueue=[]}async initWidget(){try{console.log("[AriaFlow Widget] Fetching agent config...",{agentUrl:this.agentUrl,agentId:this.agentId});try{const n=await fetch(`${this.agentUrl}/api/agent/${this.agentId}`);if(n.ok){const o=await n.json();return console.log("[AriaFlow Widget] Agent config received:",o),!o||o.status!=="active"?(console.error("Agent not found or inactive"),null):(this.agentConfig=o,this.maxReconnectAttempts=o.config.maxRetries||5,this.reconnectDelay=o.config.reconnectDelay||1e3,await this.connectToAgent(),o)}}catch{console.warn("[AriaFlow Widget] Agent config endpoint not available, trying fallback")}console.log("[AriaFlow Widget] Using fallback config for Railway deployment");const e={id:this.agentId,name:this.agentId==="hospital"?"Hospital Support":"Support Agent",wsUrl:`${this.agentUrl.replace(/^https/,"wss")}/ws`,status:"active",capabilities:["chat","streaming"],config:{primaryColor:"#14B8A6",position:"bottom-right",theme:"light",title:this.agentId==="hospital"?"Hospital Support":"Chat Support",subtitle:"We're here to help!",maxRetries:3,reconnectDelay:1e3}};return this.agentConfig=e,await this.connectToAgent(),e}catch(e){return console.error("Failed to initialize widget:",e),null}}async connectToAgent(){if(!this.agentConfig?.wsUrl)throw new Error("No agent WebSocket URL configured");const e=this.getSessionId(),n=`${this.agentConfig.wsUrl}/${e}`;return console.log("[AriaFlow Widget] Connecting to WebSocket:",n),new Promise((o,i)=>{try{this.ws=new WebSocket(n),this.ws.onopen=()=>{console.log("[Widget] Connected to agent"),this.reconnectAttempts=0,this.notifyConnectionChange(!0),o()},this.ws.onmessage=s=>{this.handleMessage(s)},this.ws.onclose=()=>{if(console.log("[Widget] Disconnected from agent"),this.notifyConnectionChange(!1),this.reconnectAttempts<this.maxReconnectAttempts){this.reconnectAttempts++;const s=this.reconnectDelay*Math.pow(2,this.reconnectAttempts-1);console.log(`[Widget] Reconnecting in ${s}ms... (attempt ${this.reconnectAttempts})`),setTimeout(()=>this.connectToAgent(),s)}},this.ws.onerror=s=>{console.error("[Widget] WebSocket error:",s),i(s)}}catch(s){i(s)}})}onProcessingChange(e){return this.processingCallbacks.add(e),()=>{this.processingCallbacks.delete(e)}}notifyProcessingChange(e){this.isAgentProcessing=e,this.processingCallbacks.forEach(n=>n(e))}handleMessage(e){try{const n=JSON.parse(e.data);if(n.type==="text-delta")this.isAgentProcessing&&this.notifyProcessingChange(!1),this.setMessages(o=>{const i=o[o.length-1];return i&&i.role==="assistant"&&i.isStreaming?[...o.slice(0,-1),{...i,content:i.content+n.text}]:[...o,{id:ne(),role:"assistant",content:n.text,timestamp:Date.now(),isStreaming:!0}]});else if(n.type==="done")console.log("[Widget] Response complete"),this.notifyProcessingChange(!1),this.setMessages(o=>{const i=o[o.length-1];return i&&i.role==="assistant"&&i.isStreaming?[...o.slice(0,-1),{...i,isStreaming:!1}]:o}),this.isAgentStreaming=!1,this.notifyStreamingChange(!1),this.processMessageQueue();else if(n.type==="step-start"||n.type==="agent-start")console.log(`[Widget] ${n.type} received:`,n.agentId||""),this.isAgentStreaming=!0,this.notifyStreamingChange(!0),this.notifyProcessingChange(!0);else if(n.type==="step-end"||n.type==="agent-end")console.log(`[Widget] ${n.type} received`),n.type==="agent-end"&&this.notifyProcessingChange(!1);else if(n.type==="tool-call"){console.log("[Widget] Tool call:",n.tool),this.notifyProcessingChange(!0);const o={id:ne(),role:"tool",content:`Calling tool: ${n.tool.name}`,timestamp:Date.now(),toolCall:{name:n.tool.name,arguments:n.tool.arguments}};this.setMessages(i=>[...i,o]),n.tool.name==="suggest_options"&&n.tool.arguments?.options&&this.setMessages(i=>{const s=[...i].reverse().find(a=>a.role==="assistant");return s?i.map(a=>a.id===s.id?{...a,suggestions:n.tool.arguments.options}:a):i})}else n.type==="tool-result"?(console.log("[Widget] Tool result:",n.result),this.setMessages(o=>{const i=o[o.length-1];return i&&i.role==="tool"&&!i.toolResult?[...o.slice(0,-1),{...i,content:i.content+`
1
+ (function(I,E){typeof exports=="object"&&typeof module<"u"?E(exports):typeof define=="function"&&define.amd?define(["exports"],E):(I=typeof globalThis<"u"?globalThis:I||self,E(I.AriaFlowWidget={}))})(this,function(I){"use strict";var E,m,ye,U,we,ve,be,Ce,ie,re,ae,B={},ke=[],ot=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,J=Array.isArray;function F(t,e){for(var n in e)t[n]=e[n];return t}function le(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function Q(t,e,n){var o,i,s,a={};for(s in e)s=="key"?o=e[s]:s=="ref"?i=e[s]:a[s]=e[s];if(arguments.length>2&&(a.children=arguments.length>3?E.call(arguments,2):n),typeof t=="function"&&t.defaultProps!=null)for(s in t.defaultProps)a[s]===void 0&&(a[s]=t.defaultProps[s]);return z(t,a,o,i,null)}function z(t,e,n,o,i){var s={type:t,props:e,key:n,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:i??++ye,__i:-1,__u:0};return i==null&&m.vnode!=null&&m.vnode(s),s}function D(t){return t.children}function K(t,e){this.props=t,this.context=e}function q(t,e){if(e==null)return t.__?q(t.__,t.__i+1):null;for(var n;e<t.__k.length;e++)if((n=t.__k[e])!=null&&n.__e!=null)return n.__e;return typeof t.type=="function"?q(t):null}function Ae(t){var e,n;if((t=t.__)!=null&&t.__c!=null){for(t.__e=t.__c.base=null,e=0;e<t.__k.length;e++)if((n=t.__k[e])!=null&&n.__e!=null){t.__e=t.__c.base=n.__e;break}return Ae(t)}}function Se(t){(!t.__d&&(t.__d=!0)&&U.push(t)&&!G.__r++||we!=m.debounceRendering)&&((we=m.debounceRendering)||ve)(G)}function G(){for(var t,e,n,o,i,s,a,_=1;U.length;)U.length>_&&U.sort(be),t=U.shift(),_=U.length,t.__d&&(n=void 0,o=void 0,i=(o=(e=t).__v).__e,s=[],a=[],e.__P&&((n=F({},o)).__v=o.__v+1,m.vnode&&m.vnode(n),_e(e.__P,n,o,e.__n,e.__P.namespaceURI,32&o.__u?[i]:null,s,i??q(o),!!(32&o.__u),a),n.__v=o.__v,n.__.__k[n.__i]=n,Me(s,n,a),o.__e=o.__=null,n.__e!=i&&Ae(n)));G.__r=0}function We(t,e,n,o,i,s,a,_,c,l,u){var r,h,g,b,W,w,p,f=o&&o.__k||ke,P=e.length;for(c=st(n,e,f,c,P),r=0;r<P;r++)(g=n.__k[r])!=null&&(h=g.__i==-1?B:f[g.__i]||B,g.__i=r,w=_e(t,g,h,i,s,a,_,c,l,u),b=g.__e,g.ref&&h.ref!=g.ref&&(h.ref&&ue(h.ref,null,g),u.push(g.ref,g.__c||b,g)),W==null&&b!=null&&(W=b),(p=!!(4&g.__u))||h.__k===g.__k?c=$e(g,c,t,p):typeof g.type=="function"&&w!==void 0?c=w:b&&(c=b.nextSibling),g.__u&=-7);return n.__e=W,c}function st(t,e,n,o,i){var s,a,_,c,l,u=n.length,r=u,h=0;for(t.__k=new Array(i),s=0;s<i;s++)(a=e[s])!=null&&typeof a!="boolean"&&typeof a!="function"?(typeof a=="string"||typeof a=="number"||typeof a=="bigint"||a.constructor==String?a=t.__k[s]=z(null,a,null,null,null):J(a)?a=t.__k[s]=z(D,{children:a},null,null,null):a.constructor===void 0&&a.__b>0?a=t.__k[s]=z(a.type,a.props,a.key,a.ref?a.ref:null,a.__v):t.__k[s]=a,c=s+h,a.__=t,a.__b=t.__b+1,_=null,(l=a.__i=it(a,n,c,r))!=-1&&(r--,(_=n[l])&&(_.__u|=2)),_==null||_.__v==null?(l==-1&&(i>u?h--:i<u&&h++),typeof a.type!="function"&&(a.__u|=4)):l!=c&&(l==c-1?h--:l==c+1?h++:(l>c?h--:h++,a.__u|=4))):t.__k[s]=null;if(r)for(s=0;s<u;s++)(_=n[s])!=null&&!(2&_.__u)&&(_.__e==o&&(o=q(_)),Pe(_,_));return o}function $e(t,e,n,o){var i,s;if(typeof t.type=="function"){for(i=t.__k,s=0;i&&s<i.length;s++)i[s]&&(i[s].__=t,e=$e(i[s],e,n,o));return e}t.__e!=e&&(o&&(e&&t.type&&!e.parentNode&&(e=q(t)),n.insertBefore(t.__e,e||null)),e=t.__e);do e=e&&e.nextSibling;while(e!=null&&e.nodeType==8);return e}function it(t,e,n,o){var i,s,a,_=t.key,c=t.type,l=e[n],u=l!=null&&(2&l.__u)==0;if(l===null&&_==null||u&&_==l.key&&c==l.type)return n;if(o>(u?1:0)){for(i=n-1,s=n+1;i>=0||s<e.length;)if((l=e[a=i>=0?i--:s++])!=null&&!(2&l.__u)&&_==l.key&&c==l.type)return a}return-1}function xe(t,e,n){e[0]=="-"?t.setProperty(e,n??""):t[e]=n==null?"":typeof n!="number"||ot.test(e)?n:n+"px"}function X(t,e,n,o,i){var s,a;e:if(e=="style")if(typeof n=="string")t.style.cssText=n;else{if(typeof o=="string"&&(t.style.cssText=o=""),o)for(e in o)n&&e in n||xe(t.style,e,"");if(n)for(e in n)o&&n[e]==o[e]||xe(t.style,e,n[e])}else if(e[0]=="o"&&e[1]=="n")s=e!=(e=e.replace(Ce,"$1")),a=e.toLowerCase(),e=a in t||e=="onFocusOut"||e=="onFocusIn"?a.slice(2):e.slice(2),t.l||(t.l={}),t.l[e+s]=n,n?o?n.u=o.u:(n.u=ie,t.addEventListener(e,s?ae:re,s)):t.removeEventListener(e,s?ae:re,s);else{if(i=="http://www.w3.org/2000/svg")e=e.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(e!="width"&&e!="height"&&e!="href"&&e!="list"&&e!="form"&&e!="tabIndex"&&e!="download"&&e!="rowSpan"&&e!="colSpan"&&e!="role"&&e!="popover"&&e in t)try{t[e]=n??"";break e}catch{}typeof n=="function"||(n==null||n===!1&&e[4]!="-"?t.removeAttribute(e):t.setAttribute(e,e=="popover"&&n==1?"":n))}}function Ne(t){return function(e){if(this.l){var n=this.l[e.type+t];if(e.t==null)e.t=ie++;else if(e.t<n.u)return;return n(m.event?m.event(e):e)}}}function _e(t,e,n,o,i,s,a,_,c,l){var u,r,h,g,b,W,w,p,f,P,x,R,$,oe,A,O,L,N=e.type;if(e.constructor!==void 0)return null;128&n.__u&&(c=!!(32&n.__u),s=[_=e.__e=n.__e]),(u=m.__b)&&u(e);e:if(typeof N=="function")try{if(p=e.props,f="prototype"in N&&N.prototype.render,P=(u=N.contextType)&&o[u.__c],x=u?P?P.props.value:u.__:o,n.__c?w=(r=e.__c=n.__c).__=r.__E:(f?e.__c=r=new N(p,x):(e.__c=r=new K(p,x),r.constructor=N,r.render=at),P&&P.sub(r),r.state||(r.state={}),r.__n=o,h=r.__d=!0,r.__h=[],r._sb=[]),f&&r.__s==null&&(r.__s=r.state),f&&N.getDerivedStateFromProps!=null&&(r.__s==r.state&&(r.__s=F({},r.__s)),F(r.__s,N.getDerivedStateFromProps(p,r.__s))),g=r.props,b=r.state,r.__v=e,h)f&&N.getDerivedStateFromProps==null&&r.componentWillMount!=null&&r.componentWillMount(),f&&r.componentDidMount!=null&&r.__h.push(r.componentDidMount);else{if(f&&N.getDerivedStateFromProps==null&&p!==g&&r.componentWillReceiveProps!=null&&r.componentWillReceiveProps(p,x),e.__v==n.__v||!r.__e&&r.shouldComponentUpdate!=null&&r.shouldComponentUpdate(p,r.__s,x)===!1){for(e.__v!=n.__v&&(r.props=p,r.state=r.__s,r.__d=!1),e.__e=n.__e,e.__k=n.__k,e.__k.some(function(M){M&&(M.__=e)}),R=0;R<r._sb.length;R++)r.__h.push(r._sb[R]);r._sb=[],r.__h.length&&a.push(r);break e}r.componentWillUpdate!=null&&r.componentWillUpdate(p,r.__s,x),f&&r.componentDidUpdate!=null&&r.__h.push(function(){r.componentDidUpdate(g,b,W)})}if(r.context=x,r.props=p,r.__P=t,r.__e=!1,$=m.__r,oe=0,f){for(r.state=r.__s,r.__d=!1,$&&$(e),u=r.render(r.props,r.state,r.context),A=0;A<r._sb.length;A++)r.__h.push(r._sb[A]);r._sb=[]}else do r.__d=!1,$&&$(e),u=r.render(r.props,r.state,r.context),r.state=r.__s;while(r.__d&&++oe<25);r.state=r.__s,r.getChildContext!=null&&(o=F(F({},o),r.getChildContext())),f&&!h&&r.getSnapshotBeforeUpdate!=null&&(W=r.getSnapshotBeforeUpdate(g,b)),O=u,u!=null&&u.type===D&&u.key==null&&(O=Fe(u.props.children)),_=We(t,J(O)?O:[O],e,n,o,i,s,a,_,c,l),r.base=e.__e,e.__u&=-161,r.__h.length&&a.push(r),w&&(r.__E=r.__=null)}catch(M){if(e.__v=null,c||s!=null)if(M.then){for(e.__u|=c?160:128;_&&_.nodeType==8&&_.nextSibling;)_=_.nextSibling;s[s.indexOf(_)]=null,e.__e=_}else{for(L=s.length;L--;)le(s[L]);ce(e)}else e.__e=n.__e,e.__k=n.__k,M.then||ce(e);m.__e(M,e,n)}else s==null&&e.__v==n.__v?(e.__k=n.__k,e.__e=n.__e):_=e.__e=rt(n.__e,e,n,o,i,s,a,c,l);return(u=m.diffed)&&u(e),128&e.__u?void 0:_}function ce(t){t&&t.__c&&(t.__c.__e=!0),t&&t.__k&&t.__k.forEach(ce)}function Me(t,e,n){for(var o=0;o<n.length;o++)ue(n[o],n[++o],n[++o]);m.__c&&m.__c(e,t),t.some(function(i){try{t=i.__h,i.__h=[],t.some(function(s){s.call(i)})}catch(s){m.__e(s,i.__v)}})}function Fe(t){return typeof t!="object"||t==null||t.__b&&t.__b>0?t:J(t)?t.map(Fe):F({},t)}function rt(t,e,n,o,i,s,a,_,c){var l,u,r,h,g,b,W,w=n.props||B,p=e.props,f=e.type;if(f=="svg"?i="http://www.w3.org/2000/svg":f=="math"?i="http://www.w3.org/1998/Math/MathML":i||(i="http://www.w3.org/1999/xhtml"),s!=null){for(l=0;l<s.length;l++)if((g=s[l])&&"setAttribute"in g==!!f&&(f?g.localName==f:g.nodeType==3)){t=g,s[l]=null;break}}if(t==null){if(f==null)return document.createTextNode(p);t=document.createElementNS(i,f,p.is&&p),_&&(m.__m&&m.__m(e,s),_=!1),s=null}if(f==null)w===p||_&&t.data==p||(t.data=p);else{if(s=s&&E.call(t.childNodes),!_&&s!=null)for(w={},l=0;l<t.attributes.length;l++)w[(g=t.attributes[l]).name]=g.value;for(l in w)if(g=w[l],l!="children"){if(l=="dangerouslySetInnerHTML")r=g;else if(!(l in p)){if(l=="value"&&"defaultValue"in p||l=="checked"&&"defaultChecked"in p)continue;X(t,l,null,g,i)}}for(l in p)g=p[l],l=="children"?h=g:l=="dangerouslySetInnerHTML"?u=g:l=="value"?b=g:l=="checked"?W=g:_&&typeof g!="function"||w[l]===g||X(t,l,g,w[l],i);if(u)_||r&&(u.__html==r.__html||u.__html==t.innerHTML)||(t.innerHTML=u.__html),e.__k=[];else if(r&&(t.innerHTML=""),We(e.type=="template"?t.content:t,J(h)?h:[h],e,n,o,f=="foreignObject"?"http://www.w3.org/1999/xhtml":i,s,a,s?s[0]:n.__k&&q(n,0),_,c),s!=null)for(l=s.length;l--;)le(s[l]);_||(l="value",f=="progress"&&b==null?t.removeAttribute("value"):b!=null&&(b!==t[l]||f=="progress"&&!b||f=="option"&&b!=w[l])&&X(t,l,b,w[l],i),l="checked",W!=null&&W!=t[l]&&X(t,l,W,w[l],i))}return t}function ue(t,e,n){try{if(typeof t=="function"){var o=typeof t.__u=="function";o&&t.__u(),o&&e==null||(t.__u=t(e))}else t.current=e}catch(i){m.__e(i,n)}}function Pe(t,e,n){var o,i;if(m.unmount&&m.unmount(t),(o=t.ref)&&(o.current&&o.current!=t.__e||ue(o,null,e)),(o=t.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(s){m.__e(s,e)}o.base=o.__P=null}if(o=t.__k)for(i=0;i<o.length;i++)o[i]&&Pe(o[i],e,n||typeof t.type!="function");n||le(t.__e),t.__c=t.__=t.__e=void 0}function at(t,e,n){return this.constructor(t,n)}function Y(t,e,n){var o,i,s,a;e==document&&(e=document.documentElement),m.__&&m.__(t,e),i=(o=typeof n=="function")?null:n&&n.__k||e.__k,s=[],a=[],_e(e,t=(!o&&n||e).__k=Q(D,null,[t]),i||B,B,e.namespaceURI,!o&&n?[n]:i?null:e.firstChild?E.call(e.childNodes):null,s,!o&&n?n:i?i.__e:e.firstChild,o,a),Me(s,t,a)}function Te(t,e){Y(t,e,Te)}function Ee(t,e,n){var o,i,s,a,_=F({},t.props);for(s in t.type&&t.type.defaultProps&&(a=t.type.defaultProps),e)s=="key"?o=e[s]:s=="ref"?i=e[s]:_[s]=e[s]===void 0&&a!=null?a[s]:e[s];return arguments.length>2&&(_.children=arguments.length>3?E.call(arguments,2):n),z(t.type,_,o||t.key,i||t.ref,null)}E=ke.slice,m={__e:function(t,e,n,o){for(var i,s,a;e=e.__;)if((i=e.__c)&&!i.__)try{if((s=i.constructor)&&s.getDerivedStateFromError!=null&&(i.setState(s.getDerivedStateFromError(t)),a=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(t,o||{}),a=i.__d),a)return i.__E=i}catch(_){t=_}throw t}},ye=0,K.prototype.setState=function(t,e){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=F({},this.state),typeof t=="function"&&(t=t(F({},n),this.props)),t&&F(n,t),t!=null&&this.__v&&(e&&this._sb.push(e),Se(this))},K.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),Se(this))},K.prototype.render=D,U=[],ve=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,be=function(t,e){return t.__v.__b-e.__v.__b},G.__r=0,Ce=/(PointerCapture)$|Capture$/i,ie=0,re=Ne(!1),ae=Ne(!0);function Z(){return Z=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t},Z.apply(this,arguments)}function He(t,e){if(t==null)return{};var n,o,i={},s=Object.keys(t);for(o=0;o<s.length;o++)e.indexOf(n=s[o])>=0||(i[n]=t[n]);return i}var lt=["context","children"],_t=["useFragment"];function ct(t,e,n,o){function i(){var s=Reflect.construct(HTMLElement,[],i);return s._vdomComponent=t,s._root=s,s}return(i.prototype=Object.create(HTMLElement.prototype)).constructor=i,i.prototype.connectedCallback=function(){gt.call(this,o)},i.prototype.attributeChangedCallback=dt,i.prototype.disconnectedCallback=ht,n=n||t.observedAttributes||Object.keys(t.propTypes||{}),i.observedAttributes=n,t.formAssociated&&(i.formAssociated=!0),n.forEach(function(s){Object.defineProperty(i.prototype,s,{get:function(){return this._vdom?this._vdom.props[s]:this._props[s]},set:function(a){this._vdom?this.attributeChangedCallback(s,null,a):(this._props||(this._props={}),this._props[s]=a);var _=typeof a;a!=null&&_!=="string"&&_!=="boolean"&&_!=="number"||this.setAttribute(s,a)}})}),customElements.define(e,i),i}function ut(t){this.getChildContext=function(){return t.context};var e=t.children,n=He(t,lt);return Ee(e,n)}function gt(t){var e=new CustomEvent("_preact",{detail:{},bubbles:!0,cancelable:!0});this.dispatchEvent(e),this._vdom=Q(ut,Z({},this._props,{context:e.detail.context}),De(this,this._vdomComponent,t)),(this.hasAttribute("hydrate")?Te:Y)(this._vdom,this._root)}function Ie(t){return t.replace(/-(\w)/g,function(e,n){return n?n.toUpperCase():""})}function dt(t,e,n){if(this._vdom){var o={};o[t]=n=n??void 0,o[Ie(t)]=n,this._vdom=Ee(this._vdom,o),Y(this._vdom,this._root)}}function ht(){Y(this._vdom=null,this._root)}function Ue(t,e){var n=this,o=t.useFragment,i=He(t,_t);return Q(o?D:"slot",Z({},i,{ref:function(s){s?(n.ref=s,n._listener||(n._listener=function(a){a.stopPropagation(),a.detail.context=e},s.addEventListener("_preact",n._listener))):n.ref.removeEventListener("_preact",n._listener)}}))}function De(t,e,n){if(t.nodeType===3)return t.data;if(t.nodeType!==1)return null;var o=[],i={},s=0,a=t.attributes,_=t.childNodes;for(s=a.length;s--;)a[s].name!=="slot"&&(i[a[s].name]=a[s].value,i[Ie(a[s].name)]=a[s].value);for(s=_.length;s--;){var c=De(_[s],null,n),l=_[s].slot;l?i[l]=Q(Ue,{name:l},c):o[s]=c}var u=!(!n||!n.shadow),r=e?Q(Ue,{useFragment:!u},o):o;return!u&&e&&(t.innerHTML=""),Q(e||t.nodeName.toLowerCase(),i,r)}var ft=0;function d(t,e,n,o,i,s){e||(e={});var a,_,c=e;if("ref"in c)for(_ in c={},e)_=="ref"?a=e[_]:c[_]=e[_];var l={type:t,props:c,key:n,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--ft,__i:-1,__u:0,__source:i,__self:s};if(typeof t=="function"&&(a=t.defaultProps))for(_ in a)c[_]===void 0&&(c[_]=a[_]);return m.vnode&&m.vnode(l),l}var V,y,ge,Re,ee=0,Oe=[],v=m,Le=v.__b,Qe=v.__r,qe=v.diffed,je=v.__c,Be=v.unmount,ze=v.__;function de(t,e){v.__h&&v.__h(y,t,ee||e),ee=0;var n=y.__H||(y.__H={__:[],__h:[]});return t>=n.__.length&&n.__.push({}),n.__[t]}function H(t){return ee=1,pt(Xe,t)}function pt(t,e,n){var o=de(V++,2);if(o.t=t,!o.__c&&(o.__=[Xe(void 0,e),function(_){var c=o.__N?o.__N[0]:o.__[0],l=o.t(c,_);c!==l&&(o.__N=[l,o.__[1]],o.__c.setState({}))}],o.__c=y,!y.__f)){var i=function(_,c,l){if(!o.__c.__H)return!0;var u=o.__c.__H.__.filter(function(h){return!!h.__c});if(u.every(function(h){return!h.__N}))return!s||s.call(this,_,c,l);var r=o.__c.props!==_;return u.forEach(function(h){if(h.__N){var g=h.__[0];h.__=h.__N,h.__N=void 0,g!==h.__[0]&&(r=!0)}}),s&&s.call(this,_,c,l)||r};y.__f=!0;var s=y.shouldComponentUpdate,a=y.componentWillUpdate;y.componentWillUpdate=function(_,c,l){if(this.__e){var u=s;s=void 0,i(_,c,l),s=u}a&&a.call(this,_,c,l)},y.shouldComponentUpdate=i}return o.__N||o.__}function Ve(t,e){var n=de(V++,3);!v.__s&&Ge(n.__H,e)&&(n.__=t,n.u=e,y.__H.__h.push(n))}function Je(t){return ee=5,mt(function(){return{current:t}},[])}function mt(t,e){var n=de(V++,7);return Ge(n.__H,e)&&(n.__=t(),n.__H=e,n.__h=t),n.__}function yt(){for(var t;t=Oe.shift();)if(t.__P&&t.__H)try{t.__H.__h.forEach(te),t.__H.__h.forEach(he),t.__H.__h=[]}catch(e){t.__H.__h=[],v.__e(e,t.__v)}}v.__b=function(t){y=null,Le&&Le(t)},v.__=function(t,e){t&&e.__k&&e.__k.__m&&(t.__m=e.__k.__m),ze&&ze(t,e)},v.__r=function(t){Qe&&Qe(t),V=0;var e=(y=t.__c).__H;e&&(ge===y?(e.__h=[],y.__h=[],e.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(e.__h.forEach(te),e.__h.forEach(he),e.__h=[],V=0)),ge=y},v.diffed=function(t){qe&&qe(t);var e=t.__c;e&&e.__H&&(e.__H.__h.length&&(Oe.push(e)!==1&&Re===v.requestAnimationFrame||((Re=v.requestAnimationFrame)||wt)(yt)),e.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),ge=y=null},v.__c=function(t,e){e.some(function(n){try{n.__h.forEach(te),n.__h=n.__h.filter(function(o){return!o.__||he(o)})}catch(o){e.some(function(i){i.__h&&(i.__h=[])}),e=[],v.__e(o,n.__v)}}),je&&je(t,e)},v.unmount=function(t){Be&&Be(t);var e,n=t.__c;n&&n.__H&&(n.__H.__.forEach(function(o){try{te(o)}catch(i){e=i}}),n.__H=void 0,e&&v.__e(e,n.__v))};var Ke=typeof requestAnimationFrame=="function";function wt(t){var e,n=function(){clearTimeout(o),Ke&&cancelAnimationFrame(e),setTimeout(t)},o=setTimeout(n,35);Ke&&(e=requestAnimationFrame(n))}function te(t){var e=y,n=t.__c;typeof n=="function"&&(t.__c=void 0,n()),y=e}function he(t){var e=y;t.__c=t.__(),y=e}function Ge(t,e){return!t||t.length!==e.length||e.some(function(n,o){return n!==t[o]})}function Xe(t,e){return typeof e=="function"?e(t):e}const vt="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let ne=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t|=0));for(;t--;)e+=vt[n[t]&63];return e};class Ye{constructor(e,n){this.agentUrl=e,this.agentId=n,this.agentConfig=null,this.ws=null,this.messageCallbacks=new Set,this.connectionCallbacks=new Set,this.streamingCallbacks=new Set,this.processingCallbacks=new Set,this.queueCallbacks=new Set,this.messages=[],this.reconnectAttempts=0,this.maxReconnectAttempts=5,this.reconnectDelay=1e3,this.isAgentStreaming=!1,this.isAgentProcessing=!1,this.messageQueue=[]}async initWidget(){try{console.log("[AriaFlow Widget] Fetching agent config...",{agentUrl:this.agentUrl,agentId:this.agentId});try{const n=await fetch(`${this.agentUrl}/api/agent/${this.agentId}`);if(n.ok){const o=await n.json();return console.log("[AriaFlow Widget] Agent config received:",o),!o||o.status!=="active"?(console.error("Agent not found or inactive"),null):(this.agentConfig=o,this.maxReconnectAttempts=o.config.maxRetries||5,this.reconnectDelay=o.config.reconnectDelay||1e3,await this.connectToAgent(),o)}}catch{console.warn("[AriaFlow Widget] Agent config endpoint not available, trying fallback")}console.log("[AriaFlow Widget] Using fallback config for Railway deployment");const e={id:this.agentId,name:this.agentId==="hospital"?"Hospital Support":"Support Agent",wsUrl:`${this.agentUrl.replace(/^https/,"wss")}/ws`,status:"active",capabilities:["chat","streaming"],config:{primaryColor:"#14B8A6",position:"bottom-right",theme:"light",title:this.agentId==="hospital"?"Hospital Support":"Chat Support",subtitle:"We're here to help!",maxRetries:3,reconnectDelay:1e3}};return this.agentConfig=e,await this.connectToAgent(),e}catch(e){return console.error("Failed to initialize widget:",e),null}}async connectToAgent(){if(!this.agentConfig?.wsUrl)throw new Error("No agent WebSocket URL configured");const e=this.getSessionId(),n=`${this.agentConfig.wsUrl}/${e}`;return console.log("[AriaFlow Widget] Connecting to WebSocket:",n),new Promise((o,i)=>{try{this.ws=new WebSocket(n),this.ws.onopen=()=>{console.log("[Widget] Connected to agent"),this.reconnectAttempts=0,this.notifyConnectionChange(!0),o()},this.ws.onmessage=s=>{this.handleMessage(s)},this.ws.onclose=()=>{if(console.log("[Widget] Disconnected from agent"),this.notifyConnectionChange(!1),this.reconnectAttempts<this.maxReconnectAttempts){this.reconnectAttempts++;const s=this.reconnectDelay*Math.pow(2,this.reconnectAttempts-1);console.log(`[Widget] Reconnecting in ${s}ms... (attempt ${this.reconnectAttempts})`),setTimeout(()=>this.connectToAgent(),s)}},this.ws.onerror=s=>{console.error("[Widget] WebSocket error:",s),i(s)}}catch(s){i(s)}})}onProcessingChange(e){return this.processingCallbacks.add(e),()=>{this.processingCallbacks.delete(e)}}notifyProcessingChange(e){this.isAgentProcessing=e,this.processingCallbacks.forEach(n=>n(e))}handleMessage(e){try{const n=JSON.parse(e.data);if(n.type==="text-delta")this.isAgentProcessing&&this.notifyProcessingChange(!1),this.setMessages(o=>{const i=o[o.length-1];return i&&i.role==="assistant"&&i.isStreaming?[...o.slice(0,-1),{...i,content:i.content+n.text}]:[...o,{id:ne(),role:"assistant",content:n.text,timestamp:Date.now(),isStreaming:!0}]});else if(n.type==="done")console.log("[Widget] Response complete"),this.notifyProcessingChange(!1),this.setMessages(o=>{const i=o[o.length-1];return i&&i.role==="assistant"&&i.isStreaming?[...o.slice(0,-1),{...i,isStreaming:!1}]:o}),this.isAgentStreaming=!1,this.notifyStreamingChange(!1),this.processMessageQueue();else if(n.type==="step-start"||n.type==="agent-start")console.log(`[Widget] ${n.type} received:`,n.agentId||""),this.isAgentStreaming=!0,this.notifyStreamingChange(!0),this.notifyProcessingChange(!0);else if(n.type==="step-end"||n.type==="agent-end")console.log(`[Widget] ${n.type} received`),n.type==="agent-end"&&this.notifyProcessingChange(!1);else if(n.type==="tool-call"){console.log("[Widget] Tool call:",n.tool),this.notifyProcessingChange(!0);const o={id:ne(),role:"tool",content:`Calling tool: ${n.tool.name}`,timestamp:Date.now(),toolCall:{name:n.tool.name,arguments:n.tool.arguments}};this.setMessages(i=>[...i,o]),n.tool.name==="suggest_options"&&n.tool.arguments?.options&&this.setMessages(i=>{const s=[...i].reverse().find(a=>a.role==="assistant");return s?i.map(a=>a.id===s.id?{...a,suggestions:n.tool.arguments.options}:a):i})}else n.type==="tool-result"?(console.log("[Widget] Tool result:",n.result),this.setMessages(o=>{const i=o[o.length-1];return i&&i.role==="tool"&&!i.toolResult?[...o.slice(0,-1),{...i,content:i.content+`
2
2
  Result: ${JSON.stringify(n.result)}`,toolResult:n.result}]:o})):n.type==="agent-start"?(console.log(`[Widget] Agent started: ${n.agentId}`),this.isAgentStreaming=!0,this.notifyStreamingChange(!0)):n.type==="handoff"?console.log(`[Widget] Handoff: ${n.from} -> ${n.to}: ${n.reason}`):n.type==="suggested-questions"?(console.log("[Widget] Suggestions received:",n.suggestions),this.setMessages(o=>{const i=[...o].reverse().find(s=>s.role==="assistant");return i?o.map(s=>s.id===i.id?{...s,suggestions:n.suggestions}:s):o})):console.log("[Widget] Unknown message type:",n.type)}catch(n){console.error("[Widget] Error parsing message:",e.data,n)}}async sendMessage(e){if(!this.ws||this.ws.readyState!==WebSocket.OPEN)throw new Error("Not connected to agent");const n={id:ne(),role:"user",content:e,timestamp:Date.now()};if(this.setMessages(o=>[...o,n]),this.isAgentStreaming){console.log("[Widget] Agent is streaming, queuing message"),this.messageQueue.push(e),this.notifyQueueChange(this.messageQueue.length);return}this.sendToAgent(e)}async sendToAgent(e){const n=this.getSessionId();this.ws.send(JSON.stringify({message:e,sessionId:n}))}async processMessageQueue(){if(this.messageQueue.length!==0){if(this.messageQueue.length===1){const e=this.messageQueue.shift();console.log("[Widget] Sending queued message:",e),this.sendToAgent(e)}else{const e=this.messageQueue.join(`
3
3
 
4
- `);this.messageQueue.length=0,console.log("[Widget] Sending combined queued messages:",e),this.sendToAgent(e)}this.notifyQueueChange(this.messageQueue.length)}}getSessionId(){let e=sessionStorage.getItem("ariaflow_session_id");return e||(e=ne(),sessionStorage.setItem("ariaflow_session_id",e)),e}setMessages(e){this.messages=e(this.messages),this.messageCallbacks.forEach(n=>n(this.messages))}onMessages(e){return this.messageCallbacks.add(e),e(this.messages),()=>{this.messageCallbacks.delete(e)}}onConnectionChange(e){return this.connectionCallbacks.add(e),()=>{this.connectionCallbacks.delete(e)}}onStreamingChange(e){return this.streamingCallbacks.add(e),()=>{this.streamingCallbacks.delete(e)}}onQueueChange(e){return this.queueCallbacks.add(e),()=>{this.queueCallbacks.delete(e)}}notifyConnectionChange(e){this.connectionCallbacks.forEach(n=>n(e))}notifyStreamingChange(e){this.streamingCallbacks.forEach(n=>n(e))}notifyQueueChange(e){this.queueCallbacks.forEach(n=>n(e))}getMessages(){return this.messages}getConfig(){return this.agentConfig}isConnected(){return this.ws?.readyState===WebSocket.OPEN}dispose(){this.ws&&(this.ws.close(),this.ws=null),this.messageCallbacks.clear(),this.connectionCallbacks.clear()}}const fe={none:"0",small:"0.375rem",medium:"0.75rem",large:"1rem"};function Ye({agentUrl:t,agentId:e,widgetId:n,apiUrl:o,mode:i="chat",theme:s="light",position:a="bottom-right",size:_="full",radius:c="medium",baseColor:l,accentColor:u="#14B8A6",buttonBaseColor:r="#000000",buttonAccentColor:h="#FFFFFF",title:g,subtitle:b,emptyChatMessage:W}){const[w,p]=E(!1),[f,P]=E([]),[x,R]=E(""),[$,oe]=E(!1),[A,O]=E(!1),[L,N]=E(null),[M,vt]=E(!1),[bt,Ct]=E(!1),[pe,kt]=E(0),se=Ve(null),et=Ve(null);ze(()=>((async()=>{if(t&&e){console.log("[AriaFlow Widget] Using new agent resolution:",{agentUrl:t,agentId:e});const S=new Xe(t,e);se.current=S;try{S.onMessages(k=>{console.log("[AriaFlow Widget] Messages updated:",k.length),P(k)}),S.onConnectionChange(k=>{console.log("[AriaFlow Widget] Connection state:",k),oe(k),k&&O(!0)}),S.onStreamingChange(k=>{console.log("[AriaFlow Widget] Streaming state:",k),vt(k)}),S.onQueueChange(k=>{console.log("[AriaFlow Widget] Queue count:",k),kt(k)}),S.onProcessingChange(k=>{console.log("[AriaFlow Widget] Processing state:",k),Ct(k)});const j=await S.initWidget();console.log("[AriaFlow Widget] Agent config received:",j),j?(N(j),console.log("[AriaFlow Widget] Widget initialized successfully (v0.6.11)")):console.error("[AriaFlow Widget] Agent config fetch failed")}catch(j){console.error("[AriaFlow Widget] Initialization error:",j)}}else t&&!e?(console.warn("[AriaFlow Widget] Direct WebSocket URLs are deprecated. Use agent-url + agent-id instead."),console.error("[AriaFlow Widget] Configuration error: agent-id is required")):o&&n?(console.warn("[AriaFlow Widget] Legacy widget config is deprecated. Use agent-url + agent-id instead."),console.error("[AriaFlow Widget] Configuration error: use agent-url + agent-id instead")):console.error("[AriaFlow Widget] Invalid configuration. Provide agent-url and agent-id.")})(),()=>{se.current?.dispose()}),[t,e,n,o]),ze(()=>{et.current?.scrollIntoView({behavior:"smooth"})},[f]);const tt=async()=>{if(!x.trim()||!$)return;const C=x.trim();R("");try{await se.current?.sendMessage(C)}catch(S){console.error("Failed to send message:",S)}},At=C=>{C.key==="Enter"&&!C.shiftKey&&(C.preventDefault(),tt())},St=C=>{!$||M||se.current?.sendMessage(C)},Wt=g||L?.config.title||"Ninewells Hospital",$t=b||L?.config.subtitle||"How can we help you today?",xt=W||L?.config.emptyChatMessage||"Start a conversation with Ninewells...";return console.log("[AriaFlow Widget] Rendering widget component",{isInitialized:A,isOpen:w,position:a}),d("div",{className:`ariaflow-widget-container ariaflow-widget-${a} ariaflow-widget-${_} ariaflow-widget-radius-${c}`,"data-theme":s,style:{"--ariaflow-accent-color":u,"--ariaflow-base-color":l},children:[!w&&d("button",{className:"ariaflow-widget-launcher",onClick:()=>p(!0),style:{backgroundColor:r,color:h,opacity:A?1:.8,cursor:A?"pointer":"wait",position:"relative"},"aria-label":A?"Open chat":"Connecting to agent...",disabled:!A,title:A?"Click to start chat":"Connecting to agent...",children:[!A&&d("div",{className:"ariaflow-widget-launcher-loading",style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"20px",height:"20px",border:`2px solid ${h}`,borderTop:"2px solid transparent",borderRadius:"50%",animation:"spin 1s linear infinite"}}),A&&d("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:d("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})]}),w&&A&&d("div",{className:"ariaflow-widget-window",style:{backgroundColor:s==="dark"&&l?l:void 0,borderRadius:fe[c]},children:[d("div",{className:"ariaflow-widget-header",style:{backgroundColor:u,borderRadius:c==="none"?"0":`${fe[c]} ${fe[c]} 0 0`},children:[d("div",{className:"ariaflow-widget-header-content",children:d("div",{className:"ariaflow-widget-title-group",children:[d("h3",{className:"ariaflow-widget-title",children:Wt}),d("p",{className:"ariaflow-widget-subtitle",children:$t})]})}),d("button",{className:"ariaflow-widget-close",onClick:()=>p(!1),"aria-label":"Close chat",children:d("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[d("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),d("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),!$&&d("div",{className:"ariaflow-widget-status",children:[d("span",{className:"ariaflow-widget-status-dot"}),"Connecting..."]}),d("div",{className:"ariaflow-widget-messages",children:f.length===0?d("div",{className:"ariaflow-widget-empty",children:d("p",{children:$?xt:"Connecting to agent..."})}):d(D,{children:[f.map((C,S)=>(f.length-1,C.role==="tool"?null:d("div",{className:`ariaflow-widget-message ariaflow-widget-message-${C.role}`,children:d("div",{className:"ariaflow-widget-message-bubble",children:d(D,{children:[C.content,C.isStreaming&&d("span",{className:"ariaflow-widget-typing-indicator",children:[d("span",{children:"•"}),d("span",{children:"•"}),d("span",{children:"•"})]})]})})},C.id))),d("div",{ref:et}),bt&&!M&&d("div",{className:"ariaflow-widget-message ariaflow-widget-message-assistant",children:d("div",{className:"ariaflow-widget-message-bubble",children:d("span",{className:"ariaflow-widget-typing-indicator",children:[d("span",{children:"•"}),d("span",{children:"•"}),d("span",{children:"•"})]})})})]})}),!M&&(()=>{const C=[...f].reverse(),S=C.findIndex(H=>H.role==="user"),k=(S===-1?C:C.slice(0,S)).find(H=>H.suggestions&&H.suggestions.length>0);return k&&k.suggestions?d("div",{className:"ariaflow-widget-suggestions",children:k.suggestions.map(H=>d("button",{className:"ariaflow-widget-chip",onClick:()=>St(H),style:{borderColor:u,color:u,backgroundColor:"rgba(255, 255, 255, 0.95)",backdropFilter:"blur(4px)"},children:H},H))}):null})(),d("div",{className:"ariaflow-widget-input",children:[d("textarea",{value:x,onInput:C=>R(C.target.value),onKeyDown:At,placeholder:$?M?pe>0?`Agent is responding... (${pe} message${pe>1?"s":""} queued)`:"Agent is responding...":"Type your message...":"Connecting...",rows:1,disabled:!$}),d("button",{className:"ariaflow-widget-send",onClick:tt,disabled:!x.trim()||!$,style:{backgroundColor:u},"aria-label":"Send message",children:d("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[d("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),d("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})})]})]})]})}_t(Ye,"ariaflow-widget",["agent-url","agent-id","widget-id","api-url","mode","theme","position","size","radius","base-color","accent-color","button-base-color","button-accent-color","title","subtitle","empty-chat-message"],!1),typeof document<"u"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Ze):Ze());function Ze(){const t=document.querySelectorAll("ariaflow-widget");console.log(`[AriaFlow] Initializing ${t.length} widget(s)`)}I.Widget=Ye,I.WidgetClient=Xe,Object.defineProperty(I,Symbol.toStringTag,{value:"Module"})});
4
+ `);this.messageQueue.length=0,console.log("[Widget] Sending combined queued messages:",e),this.sendToAgent(e)}this.notifyQueueChange(this.messageQueue.length)}}getSessionId(){let e=sessionStorage.getItem("ariaflow_session_id");return e||(e=ne(),sessionStorage.setItem("ariaflow_session_id",e)),e}setMessages(e){this.messages=e(this.messages),this.messageCallbacks.forEach(n=>n(this.messages))}onMessages(e){return this.messageCallbacks.add(e),e(this.messages),()=>{this.messageCallbacks.delete(e)}}onConnectionChange(e){return this.connectionCallbacks.add(e),()=>{this.connectionCallbacks.delete(e)}}onStreamingChange(e){return this.streamingCallbacks.add(e),()=>{this.streamingCallbacks.delete(e)}}onQueueChange(e){return this.queueCallbacks.add(e),()=>{this.queueCallbacks.delete(e)}}notifyConnectionChange(e){this.connectionCallbacks.forEach(n=>n(e))}notifyStreamingChange(e){this.streamingCallbacks.forEach(n=>n(e))}notifyQueueChange(e){this.queueCallbacks.forEach(n=>n(e))}getMessages(){return this.messages}getConfig(){return this.agentConfig}isConnected(){return this.ws?.readyState===WebSocket.OPEN}dispose(){this.ws&&(this.ws.close(),this.ws=null),this.messageCallbacks.clear(),this.connectionCallbacks.clear()}}const fe={none:"0",small:"0.375rem",medium:"0.75rem",large:"1rem"};function Ze({agentUrl:t,agentId:e,widgetId:n,apiUrl:o,mode:i="chat",theme:s="light",position:a="bottom-right",size:_="full",radius:c="medium",baseColor:l,accentColor:u="#14B8A6",buttonBaseColor:r="#000000",buttonAccentColor:h="#FFFFFF",title:g,subtitle:b,emptyChatMessage:W}){const[w,p]=H(!1),[f,P]=H([]),[x,R]=H(""),[$,oe]=H(!1),[A,O]=H(!1),[L,N]=H(null),[M,bt]=H(!1),[Ct,kt]=H(!1),[pe,At]=H(0),se=Je(null),tt=Je(null);Ve(()=>((async()=>{if(t&&e){console.log("[AriaFlow Widget] Using new agent resolution:",{agentUrl:t,agentId:e});const S=new Ye(t,e);se.current=S;try{S.onMessages(k=>{console.log("[AriaFlow Widget] Messages updated:",k.length),P(k)}),S.onConnectionChange(k=>{console.log("[AriaFlow Widget] Connection state:",k),oe(k),k&&O(!0)}),S.onStreamingChange(k=>{console.log("[AriaFlow Widget] Streaming state:",k),bt(k)}),S.onQueueChange(k=>{console.log("[AriaFlow Widget] Queue count:",k),At(k)}),S.onProcessingChange(k=>{console.log("[AriaFlow Widget] Processing state:",k),kt(k)});const j=await S.initWidget();console.log("[AriaFlow Widget] Agent config received:",j),j?(N(j),console.log("[AriaFlow Widget] Widget initialized successfully (v0.6.11)")):console.error("[AriaFlow Widget] Agent config fetch failed")}catch(j){console.error("[AriaFlow Widget] Initialization error:",j)}}else t&&!e?(console.warn("[AriaFlow Widget] Direct WebSocket URLs are deprecated. Use agent-url + agent-id instead."),console.error("[AriaFlow Widget] Configuration error: agent-id is required")):o&&n?(console.warn("[AriaFlow Widget] Legacy widget config is deprecated. Use agent-url + agent-id instead."),console.error("[AriaFlow Widget] Configuration error: use agent-url + agent-id instead")):console.error("[AriaFlow Widget] Invalid configuration. Provide agent-url and agent-id.")})(),()=>{se.current?.dispose()}),[t,e,n,o]),Ve(()=>{tt.current?.scrollIntoView({behavior:"smooth"})},[f]);const nt=async()=>{if(!x.trim()||!$)return;const C=x.trim();R("");try{await se.current?.sendMessage(C)}catch(S){console.error("Failed to send message:",S)}},St=C=>{C.key==="Enter"&&!C.shiftKey&&(C.preventDefault(),nt())},Wt=C=>{!$||M||se.current?.sendMessage(C)},$t=g||L?.config.title||"Ninewells Hospital",xt=b||L?.config.subtitle||"How can we help you today?",Nt=W||L?.config.emptyChatMessage||"Start a conversation with Ninewells...";return console.log("[AriaFlow Widget] Rendering widget component",{isInitialized:A,isOpen:w,position:a}),d("div",{className:`ariaflow-widget-container ariaflow-widget-${a} ariaflow-widget-${_} ariaflow-widget-radius-${c}`,"data-theme":s,style:{"--ariaflow-accent-color":u,"--ariaflow-base-color":l},children:[!w&&d("button",{className:"ariaflow-widget-launcher",onClick:()=>p(!0),style:{backgroundColor:r,color:h,opacity:A?1:.8,cursor:A?"pointer":"wait",position:"relative"},"aria-label":A?"Open chat":"Connecting to agent...",disabled:!A,title:A?"Click to start chat":"Connecting to agent...",children:[!A&&d("div",{className:"ariaflow-widget-launcher-loading",style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"20px",height:"20px",border:`2px solid ${h}`,borderTop:"2px solid transparent",borderRadius:"50%",animation:"spin 1s linear infinite"}}),A&&d("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:d("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})]}),w&&A&&d("div",{className:"ariaflow-widget-window",style:{backgroundColor:s==="dark"&&l?l:void 0,borderRadius:fe[c]},children:[d("div",{className:"ariaflow-widget-header",style:{backgroundColor:u,borderRadius:c==="none"?"0":`${fe[c]} ${fe[c]} 0 0`},children:[d("div",{className:"ariaflow-widget-header-content",children:d("div",{className:"ariaflow-widget-title-group",children:[d("h3",{className:"ariaflow-widget-title",children:$t}),d("p",{className:"ariaflow-widget-subtitle",children:xt})]})}),d("button",{className:"ariaflow-widget-close",onClick:()=>p(!1),"aria-label":"Close chat",children:d("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[d("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),d("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),!$&&d("div",{className:"ariaflow-widget-status",children:[d("span",{className:"ariaflow-widget-status-dot"}),"Connecting..."]}),d("div",{className:"ariaflow-widget-messages",children:f.length===0?d("div",{className:"ariaflow-widget-empty",children:d("p",{children:$?Nt:"Connecting to agent..."})}):d(D,{children:[f.map((C,S)=>(f.length-1,C.role==="tool"?null:d("div",{className:`ariaflow-widget-message ariaflow-widget-message-${C.role}`,children:d("div",{className:"ariaflow-widget-message-bubble",children:d(D,{children:[C.content,C.isStreaming&&d("span",{className:"ariaflow-widget-typing-indicator",children:[d("span",{children:"•"}),d("span",{children:"•"}),d("span",{children:"•"})]})]})})},C.id))),d("div",{ref:tt}),Ct&&!M&&d("div",{className:"ariaflow-widget-message ariaflow-widget-message-assistant",children:d("div",{className:"ariaflow-widget-message-bubble",children:d("span",{className:"ariaflow-widget-typing-indicator",children:[d("span",{children:"•"}),d("span",{children:"•"}),d("span",{children:"•"})]})})})]})}),!M&&(()=>{const C=[...f].reverse(),S=C.findIndex(T=>T.role==="user"),k=(S===-1?C:C.slice(0,S)).find(T=>T.suggestions&&T.suggestions.length>0||T.role==="tool"&&T.toolCall?.name==="suggest_options"&&T.toolCall.arguments?.options?.length>0);if(k){const T=k.suggestions||k.toolCall?.arguments?.options||[];if(T.length>0)return d("div",{className:"ariaflow-widget-suggestions",children:T.map(me=>d("button",{className:"ariaflow-widget-chip",onClick:()=>Wt(me),style:{borderColor:u,color:u,backgroundColor:"rgba(255, 255, 255, 0.95)",backdropFilter:"blur(4px)"},children:me},me))})}return null})(),d("div",{className:"ariaflow-widget-input",children:[d("textarea",{value:x,onInput:C=>R(C.target.value),onKeyDown:St,placeholder:$?M?pe>0?`Agent is responding... (${pe} message${pe>1?"s":""} queued)`:"Agent is responding...":"Type your message...":"Connecting...",rows:1,disabled:!$}),d("button",{className:"ariaflow-widget-send",onClick:nt,disabled:!x.trim()||!$,style:{backgroundColor:u},"aria-label":"Send message",children:d("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[d("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),d("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})})]})]})]})}ct(Ze,"ariaflow-widget",["agent-url","agent-id","widget-id","api-url","mode","theme","position","size","radius","base-color","accent-color","button-base-color","button-accent-color","title","subtitle","empty-chat-message"],!1),typeof document<"u"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",et):et());function et(){const t=document.querySelectorAll("ariaflow-widget");console.log(`[AriaFlow] Initializing ${t.length} widget(s)`)}I.Widget=Ze,I.WidgetClient=Ye,Object.defineProperty(I,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ariaflowagents/widget",
3
- "version": "0.6.12",
3
+ "version": "0.6.13",
4
4
  "type": "module",
5
5
  "description": "Embeddable chat widget for AriaFlow Universal Inbox",
6
6
  "main": "./dist/widget.js",