@ariaflowagents/widget 0.6.13 → 0.6.14

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
@@ -41,18 +41,18 @@ function ve(t) {
41
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(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)));
44
+ for (var t, e, n, o, i, s, a, l = 1; D.length; ) D.length > l && D.sort(Ue), t = D.shift(), l = 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 Oe(t, e, n, o, i, s, a, _, c, l, u) {
47
+ function Oe(t, e, n, o, i, s, a, l, c, _, u) {
48
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);
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, l, c, _, 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
52
  function ct(t, e, n, o, i) {
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 = 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(_, _));
53
+ var s, a, l, c, _, 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, l = null, (_ = a.__i = ut(a, n, c, r)) != -1 && (r--, (l = n[_]) && (l.__u |= 2)), l == null || l.__v == null ? (_ == -1 && (i > u ? h-- : i < u && h++), typeof a.type != "function" && (a.__u |= 4)) : _ != c && (_ == c - 1 ? h-- : _ == c + 1 ? h++ : (_ > c ? h-- : h++, a.__u |= 4))) : t.__k[s] = null;
55
+ if (r) for (s = 0; s < u; s++) (l = n[s]) != null && !(2 & l.__u) && (l.__e == o && (o = Q(l)), Be(l, l));
56
56
  return o;
57
57
  }
58
58
  function Qe(t, e, n, o) {
@@ -68,10 +68,10 @@ function Qe(t, e, n, o) {
68
68
  return e;
69
69
  }
70
70
  function ut(t, e, n, o) {
71
- var i, s, a, _ = t.key, c = t.type, l = e[n], u = l != null && (2 & l.__u) == 0;
72
- if (l === null && _ == null || u && _ == l.key && c == l.type) return n;
71
+ var i, s, a, l = t.key, c = t.type, _ = e[n], u = _ != null && (2 & _.__u) == 0;
72
+ if (_ === null && l == null || u && l == _.key && c == _.type) return n;
73
73
  if (o > (u ? 1 : 0)) {
74
- 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;
74
+ for (i = n - 1, s = n + 1; i >= 0 || s < e.length; ) if ((_ = e[a = i >= 0 ? i-- : s++]) != null && !(2 & _.__u) && l == _.key && c == _.type) return a;
75
75
  }
76
76
  return -1;
77
77
  }
@@ -106,35 +106,35 @@ function Ce(t) {
106
106
  }
107
107
  };
108
108
  }
109
- function he(t, e, n, o, i, s, a, _, c, l) {
110
- var u, r, h, g, v, $, y, p, f, F, x, H, W, V, A, I, U, N = e.type;
109
+ function he(t, e, n, o, i, s, a, l, c, _) {
110
+ var u, r, h, g, v, $, y, p, f, F, N, H, W, V, A, I, U, x = e.type;
111
111
  if (e.constructor !== void 0) return null;
112
- 128 & n.__u && (c = !!(32 & n.__u), s = [_ = e.__e = n.__e]), (u = m.__b) && u(e);
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 = 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);
112
+ 128 & n.__u && (c = !!(32 & n.__u), s = [l = e.__e = n.__e]), (u = m.__b) && u(e);
113
+ e: if (typeof x == "function") try {
114
+ if (p = e.props, f = "prototype" in x && x.prototype.render, F = (u = x.contextType) && o[u.__c], N = u ? F ? F.props.value : u.__ : o, n.__c ? y = (r = e.__c = n.__c).__ = r.__E : (f ? e.__c = r = new x(p, N) : (e.__c = r = new X(p, N), r.constructor = x, 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 && x.getDerivedStateFromProps != null && (r.__s == r.state && (r.__s = E({}, r.__s)), E(r.__s, x.getDerivedStateFromProps(p, r.__s))), g = r.props, v = r.state, r.__v = e, h) f && x.getDerivedStateFromProps == null && r.componentWillMount != null && r.componentWillMount(), f && r.componentDidMount != null && r.__h.push(r.componentDidMount);
115
115
  else {
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) {
116
+ if (f && x.getDerivedStateFromProps == null && p !== g && r.componentWillReceiveProps != null && r.componentWillReceiveProps(p, N), e.__v == n.__v || !r.__e && r.shouldComponentUpdate != null && r.shouldComponentUpdate(p, r.__s, N) === !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) {
118
118
  M && (M.__ = e);
119
119
  }), H = 0; H < r._sb.length; H++) r.__h.push(r._sb[H]);
120
120
  r._sb = [], r.__h.length && a.push(r);
121
121
  break e;
122
122
  }
123
- r.componentWillUpdate != null && r.componentWillUpdate(p, r.__s, x), f && r.componentDidUpdate != null && r.__h.push(function() {
123
+ r.componentWillUpdate != null && r.componentWillUpdate(p, r.__s, N), f && r.componentDidUpdate != null && r.__h.push(function() {
124
124
  r.componentDidUpdate(g, v, $);
125
125
  });
126
126
  }
127
- if (r.context = x, r.props = p, r.__P = t, r.__e = !1, W = m.__r, V = 0, f) {
127
+ if (r.context = N, r.props = p, r.__P = t, r.__e = !1, W = m.__r, V = 0, f) {
128
128
  for (r.state = r.__s, r.__d = !1, W && W(e), u = r.render(r.props, r.state, r.context), A = 0; A < r._sb.length; A++) r.__h.push(r._sb[A]);
129
129
  r._sb = [];
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 = 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);
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)), l = Oe(t, ne(I) ? I : [I], e, n, o, i, s, a, l, c, _), 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
- for (e.__u |= c ? 160 : 128; _ && _.nodeType == 8 && _.nextSibling; ) _ = _.nextSibling;
137
- s[s.indexOf(_)] = null, e.__e = _;
136
+ for (e.__u |= c ? 160 : 128; l && l.nodeType == 8 && l.nextSibling; ) l = l.nextSibling;
137
+ s[s.indexOf(l)] = null, e.__e = l;
138
138
  } else {
139
139
  for (U = s.length; U--; ) de(s[U]);
140
140
  ce(e);
@@ -142,8 +142,8 @@ function he(t, e, n, o, i, s, a, _, c, l) {
142
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 = gt(n.__e, e, n, o, i, s, a, c, l);
146
- return (u = m.diffed) && u(e), 128 & e.__u ? void 0 : _;
145
+ else s == null && e.__v == n.__v ? (e.__k = n.__k, e.__e = n.__e) : l = e.__e = gt(n.__e, e, n, o, i, s, a, c, _);
146
+ return (u = m.diffed) && u(e), 128 & e.__u ? void 0 : l;
147
147
  }
148
148
  function ce(t) {
149
149
  t && t.__c && (t.__c.__e = !0), t && t.__k && t.__k.forEach(ce);
@@ -163,32 +163,32 @@ function qe(t, e, n) {
163
163
  function je(t) {
164
164
  return typeof t != "object" || t == null || t.__b && t.__b > 0 ? t : ne(t) ? t.map(je) : E({}, t);
165
165
  }
166
- function gt(t, e, n, o, i, s, a, _, c) {
167
- var l, u, r, h, g, v, $, y = n.props || j, p = e.props, f = e.type;
166
+ function gt(t, e, n, o, i, s, a, l, c) {
167
+ var _, 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
- for (l = 0; l < s.length; l++) if ((g = s[l]) && "setAttribute" in g == !!f && (f ? g.localName == f : g.nodeType == 3)) {
170
- t = g, s[l] = null;
169
+ for (_ = 0; _ < s.length; _++) if ((g = s[_]) && "setAttribute" in g == !!f && (f ? g.localName == f : g.nodeType == 3)) {
170
+ t = g, s[_] = null;
171
171
  break;
172
172
  }
173
173
  }
174
174
  if (t == null) {
175
175
  if (f == null) return document.createTextNode(p);
176
- t = document.createElementNS(i, f, p.is && p), _ && (m.__m && m.__m(e, s), _ = !1), s = null;
176
+ t = document.createElementNS(i, f, p.is && p), l && (m.__m && m.__m(e, s), l = !1), s = null;
177
177
  }
178
- if (f == null) y === p || _ && t.data == p || (t.data = p);
178
+ if (f == null) y === p || l && t.data == p || (t.data = p);
179
179
  else {
180
- if (s = s && z.call(t.childNodes), !_ && s != null) for (y = {}, l = 0; l < t.attributes.length; l++) y[(g = t.attributes[l]).name] = g.value;
181
- for (l in y) if (g = y[l], l != "children") {
182
- if (l == "dangerouslySetInnerHTML") r = g;
183
- else if (!(l in p)) {
184
- if (l == "value" && "defaultValue" in p || l == "checked" && "defaultChecked" in p) continue;
185
- K(t, l, null, g, i);
180
+ if (s = s && z.call(t.childNodes), !l && s != null) for (y = {}, _ = 0; _ < t.attributes.length; _++) y[(g = t.attributes[_]).name] = g.value;
181
+ for (_ in y) if (g = y[_], _ != "children") {
182
+ if (_ == "dangerouslySetInnerHTML") r = g;
183
+ else if (!(_ in p)) {
184
+ if (_ == "value" && "defaultValue" in p || _ == "checked" && "defaultChecked" in p) continue;
185
+ K(t, _, null, g, i);
186
186
  }
187
187
  }
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
- if (u) _ || r && (u.__html == r.__html || u.__html == t.innerHTML) || (t.innerHTML = u.__html), e.__k = [];
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
- _ || (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));
188
+ for (_ in p) g = p[_], _ == "children" ? h = g : _ == "dangerouslySetInnerHTML" ? u = g : _ == "value" ? v = g : _ == "checked" ? $ = g : l && typeof g != "function" || y[_] === g || K(t, _, g, y[_], i);
189
+ if (u) l || r && (u.__html == r.__html || u.__html == t.innerHTML) || (t.innerHTML = u.__html), e.__k = [];
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), l, c), s != null) for (_ = s.length; _--; ) de(s[_]);
191
+ l || (_ = "value", f == "progress" && v == null ? t.removeAttribute("value") : v != null && (v !== t[_] || f == "progress" && !v || f == "option" && v != y[_]) && K(t, _, v, y[_], i), _ = "checked", $ != null && $ != t[_] && K(t, _, $, y[_], i));
192
192
  }
193
193
  return t;
194
194
  }
@@ -226,15 +226,15 @@ function ze(t, e) {
226
226
  oe(t, e, ze);
227
227
  }
228
228
  function Ve(t, e, n) {
229
- var o, i, s, a, _ = E({}, t.props);
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
- return arguments.length > 2 && (_.children = arguments.length > 3 ? z.call(arguments, 2) : n), q(t.type, _, o || t.key, i || t.ref, null);
229
+ var o, i, s, a, l = E({}, t.props);
230
+ for (s in t.type && t.type.defaultProps && (a = t.type.defaultProps), e) s == "key" ? o = e[s] : s == "ref" ? i = e[s] : l[s] = e[s] === void 0 && a != null ? a[s] : e[s];
231
+ return arguments.length > 2 && (l.children = arguments.length > 3 ? z.call(arguments, 2) : n), q(t.type, l, o || t.key, i || t.ref, null);
232
232
  }
233
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
- } catch (_) {
237
- t = _;
236
+ } catch (l) {
237
+ t = l;
238
238
  }
239
239
  throw t;
240
240
  } }, He = 0, X.prototype.setState = function(t, e) {
@@ -273,8 +273,8 @@ function pt(t, e, n, o) {
273
273
  return this._vdom ? this._vdom.props[s] : this._props[s];
274
274
  }, set: function(a) {
275
275
  this._vdom ? this.attributeChangedCallback(s, null, a) : (this._props || (this._props = {}), this._props[s] = a);
276
- var _ = typeof a;
277
- a != null && _ !== "string" && _ !== "boolean" && _ !== "number" || this.setAttribute(s, a);
276
+ var l = typeof a;
277
+ a != null && l !== "string" && l !== "boolean" && l !== "number" || this.setAttribute(s, a);
278
278
  } });
279
279
  }), customElements.define(e, i), i;
280
280
  }
@@ -314,11 +314,11 @@ function ke(t, e) {
314
314
  function Ge(t, e, n) {
315
315
  if (t.nodeType === 3) return t.data;
316
316
  if (t.nodeType !== 1) return null;
317
- var o = [], i = {}, s = 0, a = t.attributes, _ = t.childNodes;
317
+ var o = [], i = {}, s = 0, a = t.attributes, l = t.childNodes;
318
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
- for (s = _.length; s--; ) {
320
- var c = Ge(_[s], null, n), l = _[s].slot;
321
- l ? i[l] = O(ke, { name: l }, c) : o[s] = c;
319
+ for (s = l.length; s--; ) {
320
+ var c = Ge(l[s], null, n), _ = l[s].slot;
321
+ _ ? i[_] = O(ke, { name: _ }, c) : o[s] = c;
322
322
  }
323
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);
@@ -326,13 +326,13 @@ function Ge(t, e, n) {
326
326
  var bt = 0;
327
327
  function d(t, e, n, o, i, s) {
328
328
  e || (e = {});
329
- var a, _, c = e;
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: --bt, __i: -1, __u: 0, __source: i, __self: s };
332
- if (typeof t == "function" && (a = t.defaultProps)) for (_ in a) c[_] === void 0 && (c[_] = a[_]);
333
- return m.vnode && m.vnode(l), l;
329
+ var a, l, c = e;
330
+ if ("ref" in c) for (l in c = {}, e) l == "ref" ? a = e[l] : c[l] = e[l];
331
+ var _ = { 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
+ if (typeof t == "function" && (a = t.defaultProps)) for (l in a) c[l] === void 0 && (c[l] = a[l]);
333
+ return m.vnode && m.vnode(_), _;
334
334
  }
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.__;
335
+ var B, w, re, Ae, te = 0, Xe = [], C = m, Se = C.__b, $e = C.__r, We = C.diffed, Ne = C.__c, xe = C.unmount, Me = C.__;
336
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: [] });
@@ -343,34 +343,34 @@ function T(t) {
343
343
  }
344
344
  function Ct(t, e, n) {
345
345
  var o = pe(B++, 2);
346
- if (o.t = t, !o.__c && (o.__ = [Ze(void 0, e), function(_) {
347
- var c = o.__N ? o.__N[0] : o.__[0], l = o.t(c, _);
348
- c !== l && (o.__N = [l, o.__[1]], o.__c.setState({}));
346
+ if (o.t = t, !o.__c && (o.__ = [Ze(void 0, e), function(l) {
347
+ var c = o.__N ? o.__N[0] : o.__[0], _ = o.t(c, l);
348
+ c !== _ && (o.__N = [_, o.__[1]], o.__c.setState({}));
349
349
  }], o.__c = w, !w.__f)) {
350
- var i = function(_, c, l) {
350
+ var i = function(l, c, _) {
351
351
  if (!o.__c.__H) return !0;
352
352
  var u = o.__c.__H.__.filter(function(h) {
353
353
  return !!h.__c;
354
354
  });
355
355
  if (u.every(function(h) {
356
356
  return !h.__N;
357
- })) return !s || s.call(this, _, c, l);
358
- var r = o.__c.props !== _;
357
+ })) return !s || s.call(this, l, c, _);
358
+ var r = o.__c.props !== l;
359
359
  return u.forEach(function(h) {
360
360
  if (h.__N) {
361
361
  var g = h.__[0];
362
362
  h.__ = h.__N, h.__N = void 0, g !== h.__[0] && (r = !0);
363
363
  }
364
- }), s && s.call(this, _, c, l) || r;
364
+ }), s && s.call(this, l, c, _) || r;
365
365
  };
366
366
  w.__f = !0;
367
367
  var s = w.shouldComponentUpdate, a = w.componentWillUpdate;
368
- w.componentWillUpdate = function(_, c, l) {
368
+ w.componentWillUpdate = function(l, c, _) {
369
369
  if (this.__e) {
370
370
  var u = s;
371
- s = void 0, i(_, c, l), s = u;
371
+ s = void 0, i(l, c, _), s = u;
372
372
  }
373
- a && a.call(this, _, c, l);
373
+ a && a.call(this, l, c, _);
374
374
  }, w.shouldComponentUpdate = i;
375
375
  }
376
376
  return o.__N || o.__;
@@ -422,9 +422,9 @@ C.__b = function(t) {
422
422
  i.__h && (i.__h = []);
423
423
  }), e = [], C.__e(o, n.__v);
424
424
  }
425
- }), xe && xe(t, e);
425
+ }), Ne && Ne(t, e);
426
426
  }, C.unmount = function(t) {
427
- Ne && Ne(t);
427
+ xe && xe(t);
428
428
  var e, n = t.__c;
429
429
  n && n.__H && (n.__H.__.forEach(function(o) {
430
430
  try {
@@ -579,22 +579,23 @@ class Wt {
579
579
  else if (n.type === "step-end" || n.type === "agent-end")
580
580
  console.log(`[Widget] ${n.type} received`), n.type === "agent-end" && this.notifyProcessingChange(!1);
581
581
  else if (n.type === "tool-call") {
582
- console.log("[Widget] Tool call:", n.tool), this.notifyProcessingChange(!0);
583
- const o = {
582
+ const o = n.tool?.name || n.toolName, i = n.tool?.arguments || n.args;
583
+ console.log("[Widget] Tool call:", { name: o, args: i }), this.notifyProcessingChange(!0);
584
+ const s = {
584
585
  id: G(),
585
586
  role: "tool",
586
- content: `Calling tool: ${n.tool.name}`,
587
+ content: `Calling tool: ${o}`,
587
588
  timestamp: Date.now(),
588
589
  toolCall: {
589
- name: n.tool.name,
590
- arguments: n.tool.arguments
590
+ name: o,
591
+ arguments: i
591
592
  }
592
593
  };
593
- this.setMessages((i) => [...i, o]), n.tool.name === "suggest_options" && n.tool.arguments?.options && this.setMessages((i) => {
594
- const s = [...i].reverse().find((a) => a.role === "assistant");
595
- return s ? i.map(
596
- (a) => a.id === s.id ? { ...a, suggestions: n.tool.arguments.options } : a
597
- ) : i;
594
+ this.setMessages((a) => [...a, s]), o === "suggest_options" && i?.options && this.setMessages((a) => {
595
+ const l = [...a].reverse().find((c) => c.role === "assistant");
596
+ return l ? a.map(
597
+ (c) => c.id === l.id ? { ...c, suggestions: i.options } : c
598
+ ) : a;
598
599
  });
599
600
  } else n.type === "tool-result" ? (console.log("[Widget] Tool result:", n.result), this.setMessages((o) => {
600
601
  const i = o[o.length - 1];
@@ -747,7 +748,7 @@ const ae = {
747
748
  medium: "0.75rem",
748
749
  large: "1rem"
749
750
  };
750
- function xt({
751
+ function Nt({
751
752
  agentUrl: t,
752
753
  agentId: e,
753
754
  // Legacy props for backward compatibility
@@ -756,9 +757,9 @@ function xt({
756
757
  mode: i = "chat",
757
758
  theme: s = "light",
758
759
  position: a = "bottom-right",
759
- size: _ = "full",
760
+ size: l = "full",
760
761
  radius: c = "medium",
761
- baseColor: l,
762
+ baseColor: _,
762
763
  accentColor: u = "#14B8A6",
763
764
  buttonBaseColor: r = "#000000",
764
765
  buttonAccentColor: h = "#FFFFFF",
@@ -766,7 +767,7 @@ function xt({
766
767
  subtitle: v,
767
768
  emptyChatMessage: $
768
769
  }) {
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
+ const [y, p] = T(!1), [f, F] = T([]), [N, H] = T(""), [W, V] = T(!1), [A, I] = T(!1), [U, x] = T(null), [M, et] = T(!1), [tt, nt] = T(!1), [se, ot] = T(0), J = Pe(null), me = Pe(null);
770
771
  Fe(() => ((async () => {
771
772
  if (t && e) {
772
773
  console.log("[AriaFlow Widget] Using new agent resolution:", { agentUrl: t, agentId: e });
@@ -785,7 +786,7 @@ function xt({
785
786
  console.log("[AriaFlow Widget] Processing state:", k), nt(k);
786
787
  });
787
788
  const L = await S.initWidget();
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");
789
+ console.log("[AriaFlow Widget] Agent config received:", L), L ? (x(L), console.log("[AriaFlow Widget] Widget initialized successfully (v0.6.11)")) : console.error("[AriaFlow Widget] Agent config fetch failed");
789
790
  } catch (L) {
790
791
  console.error("[AriaFlow Widget] Initialization error:", L);
791
792
  }
@@ -796,8 +797,8 @@ function xt({
796
797
  me.current?.scrollIntoView({ behavior: "smooth" });
797
798
  }, [f]);
798
799
  const ye = async () => {
799
- if (!x.trim() || !W) return;
800
- const b = x.trim();
800
+ if (!N.trim() || !W) return;
801
+ const b = N.trim();
801
802
  H("");
802
803
  try {
803
804
  await J.current?.sendMessage(b);
@@ -812,11 +813,11 @@ function xt({
812
813
  return console.log("[AriaFlow Widget] Rendering widget component", { isInitialized: A, isOpen: y, position: a }), /* @__PURE__ */ d(
813
814
  "div",
814
815
  {
815
- className: `ariaflow-widget-container ariaflow-widget-${a} ariaflow-widget-${_} ariaflow-widget-radius-${c}`,
816
+ className: `ariaflow-widget-container ariaflow-widget-${a} ariaflow-widget-${l} ariaflow-widget-radius-${c}`,
816
817
  "data-theme": s,
817
818
  style: {
818
819
  "--ariaflow-accent-color": u,
819
- "--ariaflow-base-color": l
820
+ "--ariaflow-base-color": _
820
821
  },
821
822
  children: [
822
823
  !y && /* @__PURE__ */ d(
@@ -873,7 +874,7 @@ function xt({
873
874
  {
874
875
  className: "ariaflow-widget-window",
875
876
  style: {
876
- backgroundColor: s === "dark" && l ? l : void 0,
877
+ backgroundColor: s === "dark" && _ ? _ : void 0,
877
878
  borderRadius: ae[c]
878
879
  },
879
880
  children: [
@@ -972,7 +973,7 @@ function xt({
972
973
  /* @__PURE__ */ d(
973
974
  "textarea",
974
975
  {
975
- value: x,
976
+ value: N,
976
977
  onInput: (b) => H(b.target.value),
977
978
  onKeyDown: st,
978
979
  placeholder: W ? M ? se > 0 ? `Agent is responding... (${se} message${se > 1 ? "s" : ""} queued)` : "Agent is responding..." : "Type your message..." : "Connecting...",
@@ -985,7 +986,7 @@ function xt({
985
986
  {
986
987
  className: "ariaflow-widget-send",
987
988
  onClick: ye,
988
- disabled: !x.trim() || !W,
989
+ disabled: !N.trim() || !W,
989
990
  style: { backgroundColor: u },
990
991
  "aria-label": "Send message",
991
992
  children: /* @__PURE__ */ d(
@@ -1014,7 +1015,7 @@ function xt({
1014
1015
  );
1015
1016
  }
1016
1017
  pt(
1017
- xt,
1018
+ Nt,
1018
1019
  "ariaflow-widget",
1019
1020
  // Properties to observe from HTML attributes (mirror Vapi's naming convention)
1020
1021
  [
@@ -1046,6 +1047,6 @@ function Te() {
1046
1047
  console.log(`[AriaFlow] Initializing ${t.length} widget(s)`);
1047
1048
  }
1048
1049
  export {
1049
- xt as Widget,
1050
+ Nt as Widget,
1050
1051
  Wt as WidgetClient
1051
1052
  };
@@ -1,4 +1,4 @@
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+`
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,l=1;U.length;)U.length>l&&U.sort(be),t=U.shift(),l=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,l,c,_,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,l,c,_,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,l,c,_,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,l=null,(_=a.__i=it(a,n,c,r))!=-1&&(r--,(l=n[_])&&(l.__u|=2)),l==null||l.__v==null?(_==-1&&(i>u?h--:i<u&&h++),typeof a.type!="function"&&(a.__u|=4)):_!=c&&(_==c-1?h--:_==c+1?h++:(_>c?h--:h++,a.__u|=4))):t.__k[s]=null;if(r)for(s=0;s<u;s++)(l=n[s])!=null&&!(2&l.__u)&&(l.__e==o&&(o=q(l)),Pe(l,l));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,l=t.key,c=t.type,_=e[n],u=_!=null&&(2&_.__u)==0;if(_===null&&l==null||u&&l==_.key&&c==_.type)return n;if(o>(u?1:0)){for(i=n-1,s=n+1;i>=0||s<e.length;)if((_=e[a=i>=0?i--:s++])!=null&&!(2&_.__u)&&l==_.key&&c==_.type)return a}return-1}function Ne(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||Ne(t.style,e,"");if(n)for(e in n)o&&n[e]==o[e]||Ne(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 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,l,c,_){var u,r,h,g,b,W,w,p,f,P,N,R,$,oe,A,O,L,x=e.type;if(e.constructor!==void 0)return null;128&n.__u&&(c=!!(32&n.__u),s=[l=e.__e=n.__e]),(u=m.__b)&&u(e);e:if(typeof x=="function")try{if(p=e.props,f="prototype"in x&&x.prototype.render,P=(u=x.contextType)&&o[u.__c],N=u?P?P.props.value:u.__:o,n.__c?w=(r=e.__c=n.__c).__=r.__E:(f?e.__c=r=new x(p,N):(e.__c=r=new K(p,N),r.constructor=x,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&&x.getDerivedStateFromProps!=null&&(r.__s==r.state&&(r.__s=F({},r.__s)),F(r.__s,x.getDerivedStateFromProps(p,r.__s))),g=r.props,b=r.state,r.__v=e,h)f&&x.getDerivedStateFromProps==null&&r.componentWillMount!=null&&r.componentWillMount(),f&&r.componentDidMount!=null&&r.__h.push(r.componentDidMount);else{if(f&&x.getDerivedStateFromProps==null&&p!==g&&r.componentWillReceiveProps!=null&&r.componentWillReceiveProps(p,N),e.__v==n.__v||!r.__e&&r.shouldComponentUpdate!=null&&r.shouldComponentUpdate(p,r.__s,N)===!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,N),f&&r.componentDidUpdate!=null&&r.__h.push(function(){r.componentDidUpdate(g,b,W)})}if(r.context=N,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)),l=We(t,J(O)?O:[O],e,n,o,i,s,a,l,c,_),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;l&&l.nodeType==8&&l.nextSibling;)l=l.nextSibling;s[s.indexOf(l)]=null,e.__e=l}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):l=e.__e=rt(n.__e,e,n,o,i,s,a,c,_);return(u=m.diffed)&&u(e),128&e.__u?void 0:l}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,l,c){var _,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(_=0;_<s.length;_++)if((g=s[_])&&"setAttribute"in g==!!f&&(f?g.localName==f:g.nodeType==3)){t=g,s[_]=null;break}}if(t==null){if(f==null)return document.createTextNode(p);t=document.createElementNS(i,f,p.is&&p),l&&(m.__m&&m.__m(e,s),l=!1),s=null}if(f==null)w===p||l&&t.data==p||(t.data=p);else{if(s=s&&E.call(t.childNodes),!l&&s!=null)for(w={},_=0;_<t.attributes.length;_++)w[(g=t.attributes[_]).name]=g.value;for(_ in w)if(g=w[_],_!="children"){if(_=="dangerouslySetInnerHTML")r=g;else if(!(_ in p)){if(_=="value"&&"defaultValue"in p||_=="checked"&&"defaultChecked"in p)continue;X(t,_,null,g,i)}}for(_ in p)g=p[_],_=="children"?h=g:_=="dangerouslySetInnerHTML"?u=g:_=="value"?b=g:_=="checked"?W=g:l&&typeof g!="function"||w[_]===g||X(t,_,g,w[_],i);if(u)l||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),l,c),s!=null)for(_=s.length;_--;)le(s[_]);l||(_="value",f=="progress"&&b==null?t.removeAttribute("value"):b!=null&&(b!==t[_]||f=="progress"&&!b||f=="option"&&b!=w[_])&&X(t,_,b,w[_],i),_="checked",W!=null&&W!=t[_]&&X(t,_,W,w[_],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,l=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]:l[s]=e[s]===void 0&&a!=null?a[s]:e[s];return arguments.length>2&&(l.children=arguments.length>3?E.call(arguments,2):n),z(t.type,l,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(l){t=l}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=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 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 l=typeof a;a!=null&&l!=="string"&&l!=="boolean"&&l!=="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,l=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=l.length;s--;){var c=De(l[s],null,n),_=l[s].slot;_?i[_]=Q(Ue,{name:_},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,l,c=e;if("ref"in c)for(l in c={},e)l=="ref"?a=e[l]:c[l]=e[l];var _={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(l in a)c[l]===void 0&&(c[l]=a[l]);return m.vnode&&m.vnode(_),_}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(l){var c=o.__N?o.__N[0]:o.__[0],_=o.t(c,l);c!==_&&(o.__N=[_,o.__[1]],o.__c.setState({}))}],o.__c=y,!y.__f)){var i=function(l,c,_){if(!o.__c.__H)return!0;var u=o.__c.__H.__.filter(function(h){return!!h.__c});if(u.every(function(h){return!h.__N}))return!s||s.call(this,l,c,_);var r=o.__c.props!==l;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,l,c,_)||r};y.__f=!0;var s=y.shouldComponentUpdate,a=y.componentWillUpdate;y.componentWillUpdate=function(l,c,_){if(this.__e){var u=s;s=void 0,i(l,c,_),s=u}a&&a.call(this,l,c,_)},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"){const o=n.tool?.name||n.toolName,i=n.tool?.arguments||n.args;console.log("[Widget] Tool call:",{name:o,args:i}),this.notifyProcessingChange(!0);const s={id:ne(),role:"tool",content:`Calling tool: ${o}`,timestamp:Date.now(),toolCall:{name:o,arguments:i}};this.setMessages(a=>[...a,s]),o==="suggest_options"&&i?.options&&this.setMessages(a=>{const l=[...a].reverse().find(c=>c.role==="assistant");return l?a.map(c=>c.id===l.id?{...c,suggestions:i.options}:c):a})}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 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"})});
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:l="full",radius:c="medium",baseColor:_,accentColor:u="#14B8A6",buttonBaseColor:r="#000000",buttonAccentColor:h="#FFFFFF",title:g,subtitle:b,emptyChatMessage:W}){const[w,p]=H(!1),[f,P]=H([]),[N,R]=H(""),[$,oe]=H(!1),[A,O]=H(!1),[L,x]=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?(x(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(!N.trim()||!$)return;const C=N.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",Nt=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-${l} ariaflow-widget-radius-${c}`,"data-theme":s,style:{"--ariaflow-accent-color":u,"--ariaflow-base-color":_},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"&&_?_: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:Nt})]})}),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: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:N,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:!N.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.13",
3
+ "version": "0.6.14",
4
4
  "type": "module",
5
5
  "description": "Embeddable chat widget for AriaFlow Universal Inbox",
6
6
  "main": "./dist/widget.js",