@ariaflowagents/widget 0.6.4 → 0.6.6
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 +277 -269
- package/dist/widget.umd.cjs +3 -3
- package/package.json +1 -1
package/dist/widget.js
CHANGED
|
@@ -7,14 +7,14 @@ function ue(t) {
|
|
|
7
7
|
t && t.parentNode && t.parentNode.removeChild(t);
|
|
8
8
|
}
|
|
9
9
|
function D(t, e, n) {
|
|
10
|
-
var
|
|
11
|
-
for (
|
|
12
|
-
if (arguments.length > 2 && (a.children = arguments.length > 3 ? B.call(arguments, 2) : n), typeof t == "function" && t.defaultProps != null) for (
|
|
13
|
-
return Q(t, a,
|
|
10
|
+
var s, i, o, a = {};
|
|
11
|
+
for (o in e) o == "key" ? s = e[o] : o == "ref" ? i = e[o] : a[o] = e[o];
|
|
12
|
+
if (arguments.length > 2 && (a.children = arguments.length > 3 ? B.call(arguments, 2) : n), typeof t == "function" && t.defaultProps != null) for (o in t.defaultProps) a[o] === void 0 && (a[o] = t.defaultProps[o]);
|
|
13
|
+
return Q(t, a, s, i, null);
|
|
14
14
|
}
|
|
15
|
-
function Q(t, e, n,
|
|
16
|
-
var
|
|
17
|
-
return
|
|
15
|
+
function Q(t, e, n, s, i) {
|
|
16
|
+
var o = { type: t, props: e, key: n, ref: s, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: i ?? ++Ee, __i: -1, __u: 0 };
|
|
17
|
+
return i == null && m.vnode != null && m.vnode(o), o;
|
|
18
18
|
}
|
|
19
19
|
function U(t) {
|
|
20
20
|
return t.children;
|
|
@@ -37,57 +37,57 @@ function Ue(t) {
|
|
|
37
37
|
return Ue(t);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
function
|
|
40
|
+
function ye(t) {
|
|
41
41
|
(!t.__d && (t.__d = !0) && R.push(t) && !Y.__r++ || me != m.debounceRendering) && ((me = m.debounceRendering) || Te)(Y);
|
|
42
42
|
}
|
|
43
43
|
function Y() {
|
|
44
|
-
for (var t, e, n,
|
|
44
|
+
for (var t, e, n, s, i, o, a, l = 1; R.length; ) R.length > l && R.sort(He), t = R.shift(), l = R.length, t.__d && (n = void 0, s = void 0, i = (s = (e = t).__v).__e, o = [], a = [], e.__P && ((n = P({}, s)).__v = s.__v + 1, m.vnode && m.vnode(n), ge(e.__P, n, s, e.__n, e.__P.namespaceURI, 32 & s.__u ? [i] : null, o, i ?? O(s), !!(32 & s.__u), a), n.__v = s.__v, n.__.__k[n.__i] = n, Le(o, n, a), s.__e = s.__ = null, n.__e != i && Ue(n)));
|
|
45
45
|
Y.__r = 0;
|
|
46
46
|
}
|
|
47
|
-
function De(t, e, n,
|
|
48
|
-
var r, f, d, b, S,
|
|
49
|
-
for (c = lt(n, e, h, c, M), r = 0; r < M; r++) (d = n.__k[r]) != null && (f = d.__i == -1 ? q : h[d.__i] || q, d.__i = r,
|
|
47
|
+
function De(t, e, n, s, i, o, a, l, c, _, g) {
|
|
48
|
+
var r, f, d, b, S, w, p, h = s && s.__k || Re, M = e.length;
|
|
49
|
+
for (c = lt(n, e, h, c, M), r = 0; r < M; r++) (d = n.__k[r]) != null && (f = d.__i == -1 ? q : h[d.__i] || q, d.__i = r, w = ge(t, d, f, i, o, a, l, c, _, g), b = d.__e, d.ref && f.ref != d.ref && (f.ref && de(f.ref, null, d), g.push(d.ref, d.__c || b, d)), S == null && b != null && (S = b), (p = !!(4 & d.__u)) || f.__k === d.__k ? c = Oe(d, c, t, p) : typeof d.type == "function" && w !== void 0 ? c = w : b && (c = b.nextSibling), d.__u &= -7);
|
|
50
50
|
return n.__e = S, c;
|
|
51
51
|
}
|
|
52
|
-
function lt(t, e, n,
|
|
53
|
-
var
|
|
54
|
-
for (t.__k = new Array(
|
|
55
|
-
if (r) for (
|
|
56
|
-
return
|
|
52
|
+
function lt(t, e, n, s, i) {
|
|
53
|
+
var o, a, l, c, _, g = n.length, r = g, f = 0;
|
|
54
|
+
for (t.__k = new Array(i), o = 0; o < i; o++) (a = e[o]) != null && typeof a != "boolean" && typeof a != "function" ? (typeof a == "string" || typeof a == "number" || typeof a == "bigint" || a.constructor == String ? a = t.__k[o] = Q(null, a, null, null, null) : te(a) ? a = t.__k[o] = Q(U, { children: a }, null, null, null) : a.constructor === void 0 && a.__b > 0 ? a = t.__k[o] = Q(a.type, a.props, a.key, a.ref ? a.ref : null, a.__v) : t.__k[o] = a, c = o + f, a.__ = t, a.__b = t.__b + 1, l = null, (_ = a.__i = _t(a, n, c, r)) != -1 && (r--, (l = n[_]) && (l.__u |= 2)), l == null || l.__v == null ? (_ == -1 && (i > g ? f-- : i < g && f++), typeof a.type != "function" && (a.__u |= 4)) : _ != c && (_ == c - 1 ? f-- : _ == c + 1 ? f++ : (_ > c ? f-- : f++, a.__u |= 4))) : t.__k[o] = null;
|
|
55
|
+
if (r) for (o = 0; o < g; o++) (l = n[o]) != null && !(2 & l.__u) && (l.__e == s && (s = O(l)), qe(l, l));
|
|
56
|
+
return s;
|
|
57
57
|
}
|
|
58
|
-
function Oe(t, e, n,
|
|
59
|
-
var
|
|
58
|
+
function Oe(t, e, n, s) {
|
|
59
|
+
var i, o;
|
|
60
60
|
if (typeof t.type == "function") {
|
|
61
|
-
for (
|
|
61
|
+
for (i = t.__k, o = 0; i && o < i.length; o++) i[o] && (i[o].__ = t, e = Oe(i[o], e, n, s));
|
|
62
62
|
return e;
|
|
63
63
|
}
|
|
64
|
-
t.__e != e && (
|
|
64
|
+
t.__e != e && (s && (e && t.type && !e.parentNode && (e = O(t)), n.insertBefore(t.__e, e || null)), e = t.__e);
|
|
65
65
|
do
|
|
66
66
|
e = e && e.nextSibling;
|
|
67
67
|
while (e != null && e.nodeType == 8);
|
|
68
68
|
return e;
|
|
69
69
|
}
|
|
70
|
-
function _t(t, e, n,
|
|
71
|
-
var
|
|
72
|
-
if (
|
|
73
|
-
if (
|
|
74
|
-
for (
|
|
70
|
+
function _t(t, e, n, s) {
|
|
71
|
+
var i, o, a, l = t.key, c = t.type, _ = e[n], g = _ != null && (2 & _.__u) == 0;
|
|
72
|
+
if (_ === null && l == null || g && l == _.key && c == _.type) return n;
|
|
73
|
+
if (s > (g ? 1 : 0)) {
|
|
74
|
+
for (i = n - 1, o = n + 1; i >= 0 || o < e.length; ) if ((_ = e[a = i >= 0 ? i-- : o++]) != null && !(2 & _.__u) && l == _.key && c == _.type) return a;
|
|
75
75
|
}
|
|
76
76
|
return -1;
|
|
77
77
|
}
|
|
78
|
-
function
|
|
78
|
+
function we(t, e, n) {
|
|
79
79
|
e[0] == "-" ? t.setProperty(e, n ?? "") : t[e] = n == null ? "" : typeof n != "number" || at.test(e) ? n : n + "px";
|
|
80
80
|
}
|
|
81
|
-
function J(t, e, n,
|
|
82
|
-
var
|
|
81
|
+
function J(t, e, n, s, i) {
|
|
82
|
+
var o, a;
|
|
83
83
|
e: if (e == "style") if (typeof n == "string") t.style.cssText = n;
|
|
84
84
|
else {
|
|
85
|
-
if (typeof
|
|
86
|
-
if (n) for (e in n)
|
|
85
|
+
if (typeof s == "string" && (t.style.cssText = s = ""), s) for (e in s) n && e in n || we(t.style, e, "");
|
|
86
|
+
if (n) for (e in n) s && n[e] == s[e] || we(t.style, e, n[e]);
|
|
87
87
|
}
|
|
88
|
-
else if (e[0] == "o" && e[1] == "n")
|
|
88
|
+
else if (e[0] == "o" && e[1] == "n") o = e != (e = e.replace(Ie, "$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 + o] = n, n ? s ? n.u = s.u : (n.u = ce, t.addEventListener(e, o ? ae : re, o)) : t.removeEventListener(e, o ? ae : re, o);
|
|
89
89
|
else {
|
|
90
|
-
if (
|
|
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 {
|
|
92
92
|
t[e] = n ?? "";
|
|
93
93
|
break e;
|
|
@@ -106,142 +106,142 @@ function ve(t) {
|
|
|
106
106
|
}
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
|
-
function ge(t, e, n,
|
|
110
|
-
var g, r, f, d, b, S,
|
|
109
|
+
function ge(t, e, n, s, i, o, a, l, c, _) {
|
|
110
|
+
var g, r, f, d, b, S, w, p, h, M, N, T, $, z, A, H, I, W = e.type;
|
|
111
111
|
if (e.constructor !== void 0) return null;
|
|
112
|
-
128 & n.__u && (c = !!(32 & n.__u),
|
|
113
|
-
e: if (typeof
|
|
114
|
-
if (p = e.props, h = "prototype" in
|
|
112
|
+
128 & n.__u && (c = !!(32 & n.__u), o = [l = e.__e = n.__e]), (g = m.__b) && g(e);
|
|
113
|
+
e: if (typeof W == "function") try {
|
|
114
|
+
if (p = e.props, h = "prototype" in W && W.prototype.render, M = (g = W.contextType) && s[g.__c], N = g ? M ? M.props.value : g.__ : s, n.__c ? w = (r = e.__c = n.__c).__ = r.__E : (h ? e.__c = r = new W(p, N) : (e.__c = r = new G(p, N), r.constructor = W, r.render = ut), M && M.sub(r), r.state || (r.state = {}), r.__n = s, f = r.__d = !0, r.__h = [], r._sb = []), h && r.__s == null && (r.__s = r.state), h && W.getDerivedStateFromProps != null && (r.__s == r.state && (r.__s = P({}, r.__s)), P(r.__s, W.getDerivedStateFromProps(p, r.__s))), d = r.props, b = r.state, r.__v = e, f) h && W.getDerivedStateFromProps == null && r.componentWillMount != null && r.componentWillMount(), h && r.componentDidMount != null && r.__h.push(r.componentDidMount);
|
|
115
115
|
else {
|
|
116
|
-
if (h &&
|
|
116
|
+
if (h && W.getDerivedStateFromProps == null && p !== d && 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(x) {
|
|
118
118
|
x && (x.__ = e);
|
|
119
119
|
}), T = 0; T < r._sb.length; T++) r.__h.push(r._sb[T]);
|
|
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,
|
|
123
|
+
r.componentWillUpdate != null && r.componentWillUpdate(p, r.__s, N), h && r.componentDidUpdate != null && r.__h.push(function() {
|
|
124
124
|
r.componentDidUpdate(d, b, S);
|
|
125
125
|
});
|
|
126
126
|
}
|
|
127
|
-
if (r.context =
|
|
127
|
+
if (r.context = N, r.props = p, r.__P = t, r.__e = !1, $ = m.__r, z = 0, h) {
|
|
128
128
|
for (r.state = r.__s, r.__d = !1, $ && $(e), g = 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, $ && $(e), g = r.render(r.props, r.state, r.context), r.state = r.__s;
|
|
132
132
|
while (r.__d && ++z < 25);
|
|
133
|
-
r.state = r.__s, r.getChildContext != null && (
|
|
133
|
+
r.state = r.__s, r.getChildContext != null && (s = P(P({}, s), r.getChildContext())), h && !f && r.getSnapshotBeforeUpdate != null && (S = r.getSnapshotBeforeUpdate(d, b)), H = g, g != null && g.type === U && g.key == null && (H = Qe(g.props.children)), l = De(t, te(H) ? H : [H], e, n, s, i, o, a, l, c, _), r.base = e.__e, e.__u &= -161, r.__h.length && a.push(r), w && (r.__E = r.__ = null);
|
|
134
134
|
} catch (x) {
|
|
135
|
-
if (e.__v = null, c ||
|
|
136
|
-
for (e.__u |= c ? 160 : 128;
|
|
137
|
-
|
|
135
|
+
if (e.__v = null, c || o != null) if (x.then) {
|
|
136
|
+
for (e.__u |= c ? 160 : 128; l && l.nodeType == 8 && l.nextSibling; ) l = l.nextSibling;
|
|
137
|
+
o[o.indexOf(l)] = null, e.__e = l;
|
|
138
138
|
} else {
|
|
139
|
-
for (I =
|
|
139
|
+
for (I = o.length; I--; ) ue(o[I]);
|
|
140
140
|
le(e);
|
|
141
141
|
}
|
|
142
142
|
else e.__e = n.__e, e.__k = n.__k, x.then || le(e);
|
|
143
143
|
m.__e(x, e, n);
|
|
144
144
|
}
|
|
145
|
-
else
|
|
146
|
-
return (g = m.diffed) && g(e), 128 & e.__u ? void 0 :
|
|
145
|
+
else o == null && e.__v == n.__v ? (e.__k = n.__k, e.__e = n.__e) : l = e.__e = ct(n.__e, e, n, s, i, o, a, c, _);
|
|
146
|
+
return (g = m.diffed) && g(e), 128 & e.__u ? void 0 : l;
|
|
147
147
|
}
|
|
148
148
|
function le(t) {
|
|
149
149
|
t && t.__c && (t.__c.__e = !0), t && t.__k && t.__k.forEach(le);
|
|
150
150
|
}
|
|
151
151
|
function Le(t, e, n) {
|
|
152
|
-
for (var
|
|
153
|
-
m.__c && m.__c(e, t), t.some(function(
|
|
152
|
+
for (var s = 0; s < n.length; s++) de(n[s], n[++s], n[++s]);
|
|
153
|
+
m.__c && m.__c(e, t), t.some(function(i) {
|
|
154
154
|
try {
|
|
155
|
-
t =
|
|
156
|
-
|
|
155
|
+
t = i.__h, i.__h = [], t.some(function(o) {
|
|
156
|
+
o.call(i);
|
|
157
157
|
});
|
|
158
|
-
} catch (
|
|
159
|
-
m.__e(
|
|
158
|
+
} catch (o) {
|
|
159
|
+
m.__e(o, i.__v);
|
|
160
160
|
}
|
|
161
161
|
});
|
|
162
162
|
}
|
|
163
163
|
function Qe(t) {
|
|
164
164
|
return typeof t != "object" || t == null || t.__b && t.__b > 0 ? t : te(t) ? t.map(Qe) : P({}, t);
|
|
165
165
|
}
|
|
166
|
-
function ct(t, e, n,
|
|
167
|
-
var
|
|
168
|
-
if (h == "svg" ?
|
|
169
|
-
for (
|
|
170
|
-
t = d,
|
|
166
|
+
function ct(t, e, n, s, i, o, a, l, c) {
|
|
167
|
+
var _, g, r, f, d, b, S, w = n.props || q, p = e.props, h = e.type;
|
|
168
|
+
if (h == "svg" ? i = "http://www.w3.org/2000/svg" : h == "math" ? i = "http://www.w3.org/1998/Math/MathML" : i || (i = "http://www.w3.org/1999/xhtml"), o != null) {
|
|
169
|
+
for (_ = 0; _ < o.length; _++) if ((d = o[_]) && "setAttribute" in d == !!h && (h ? d.localName == h : d.nodeType == 3)) {
|
|
170
|
+
t = d, o[_] = null;
|
|
171
171
|
break;
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
if (t == null) {
|
|
175
175
|
if (h == null) return document.createTextNode(p);
|
|
176
|
-
t = document.createElementNS(
|
|
176
|
+
t = document.createElementNS(i, h, p.is && p), l && (m.__m && m.__m(e, o), l = !1), o = null;
|
|
177
177
|
}
|
|
178
|
-
if (h == null)
|
|
178
|
+
if (h == null) w === p || l && t.data == p || (t.data = p);
|
|
179
179
|
else {
|
|
180
|
-
if (
|
|
181
|
-
for (
|
|
182
|
-
if (
|
|
183
|
-
else if (!(
|
|
184
|
-
if (
|
|
185
|
-
J(t,
|
|
180
|
+
if (o = o && B.call(t.childNodes), !l && o != null) for (w = {}, _ = 0; _ < t.attributes.length; _++) w[(d = t.attributes[_]).name] = d.value;
|
|
181
|
+
for (_ in w) if (d = w[_], _ != "children") {
|
|
182
|
+
if (_ == "dangerouslySetInnerHTML") r = d;
|
|
183
|
+
else if (!(_ in p)) {
|
|
184
|
+
if (_ == "value" && "defaultValue" in p || _ == "checked" && "defaultChecked" in p) continue;
|
|
185
|
+
J(t, _, null, d, i);
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
|
-
for (
|
|
189
|
-
if (g)
|
|
190
|
-
else if (r && (t.innerHTML = ""), De(e.type == "template" ? t.content : t, te(f) ? f : [f], e, n,
|
|
191
|
-
|
|
188
|
+
for (_ in p) d = p[_], _ == "children" ? f = d : _ == "dangerouslySetInnerHTML" ? g = d : _ == "value" ? b = d : _ == "checked" ? S = d : l && typeof d != "function" || w[_] === d || J(t, _, d, w[_], i);
|
|
189
|
+
if (g) l || r && (g.__html == r.__html || g.__html == t.innerHTML) || (t.innerHTML = g.__html), e.__k = [];
|
|
190
|
+
else if (r && (t.innerHTML = ""), De(e.type == "template" ? t.content : t, te(f) ? f : [f], e, n, s, h == "foreignObject" ? "http://www.w3.org/1999/xhtml" : i, o, a, o ? o[0] : n.__k && O(n, 0), l, c), o != null) for (_ = o.length; _--; ) ue(o[_]);
|
|
191
|
+
l || (_ = "value", h == "progress" && b == null ? t.removeAttribute("value") : b != null && (b !== t[_] || h == "progress" && !b || h == "option" && b != w[_]) && J(t, _, b, w[_], i), _ = "checked", S != null && S != t[_] && J(t, _, S, w[_], i));
|
|
192
192
|
}
|
|
193
193
|
return t;
|
|
194
194
|
}
|
|
195
195
|
function de(t, e, n) {
|
|
196
196
|
try {
|
|
197
197
|
if (typeof t == "function") {
|
|
198
|
-
var
|
|
199
|
-
|
|
198
|
+
var s = typeof t.__u == "function";
|
|
199
|
+
s && t.__u(), s && e == null || (t.__u = t(e));
|
|
200
200
|
} else t.current = e;
|
|
201
|
-
} catch (
|
|
202
|
-
m.__e(
|
|
201
|
+
} catch (i) {
|
|
202
|
+
m.__e(i, n);
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
205
|
function qe(t, e, n) {
|
|
206
|
-
var
|
|
207
|
-
if (m.unmount && m.unmount(t), (
|
|
208
|
-
if (
|
|
209
|
-
|
|
210
|
-
} catch (
|
|
211
|
-
m.__e(
|
|
206
|
+
var s, i;
|
|
207
|
+
if (m.unmount && m.unmount(t), (s = t.ref) && (s.current && s.current != t.__e || de(s, null, e)), (s = t.__c) != null) {
|
|
208
|
+
if (s.componentWillUnmount) try {
|
|
209
|
+
s.componentWillUnmount();
|
|
210
|
+
} catch (o) {
|
|
211
|
+
m.__e(o, e);
|
|
212
212
|
}
|
|
213
|
-
|
|
213
|
+
s.base = s.__P = null;
|
|
214
214
|
}
|
|
215
|
-
if (
|
|
215
|
+
if (s = t.__k) for (i = 0; i < s.length; i++) s[i] && qe(s[i], e, n || typeof t.type != "function");
|
|
216
216
|
n || ue(t.__e), t.__c = t.__ = t.__e = void 0;
|
|
217
217
|
}
|
|
218
218
|
function ut(t, e, n) {
|
|
219
219
|
return this.constructor(t, n);
|
|
220
220
|
}
|
|
221
221
|
function ne(t, e, n) {
|
|
222
|
-
var
|
|
223
|
-
e == document && (e = document.documentElement), m.__ && m.__(t, e),
|
|
222
|
+
var s, i, o, a;
|
|
223
|
+
e == document && (e = document.documentElement), m.__ && m.__(t, e), i = (s = typeof n == "function") ? null : n && n.__k || e.__k, o = [], a = [], ge(e, t = (!s && n || e).__k = D(U, null, [t]), i || q, q, e.namespaceURI, !s && n ? [n] : i ? null : e.firstChild ? B.call(e.childNodes) : null, o, !s && n ? n : i ? i.__e : e.firstChild, s, a), Le(o, t, a);
|
|
224
224
|
}
|
|
225
225
|
function je(t, e) {
|
|
226
226
|
ne(t, e, je);
|
|
227
227
|
}
|
|
228
228
|
function Be(t, e, n) {
|
|
229
|
-
var
|
|
230
|
-
for (
|
|
231
|
-
return arguments.length > 2 && (
|
|
229
|
+
var s, i, o, a, l = P({}, t.props);
|
|
230
|
+
for (o in t.type && t.type.defaultProps && (a = t.type.defaultProps), e) o == "key" ? s = e[o] : o == "ref" ? i = e[o] : l[o] = e[o] === void 0 && a != null ? a[o] : e[o];
|
|
231
|
+
return arguments.length > 2 && (l.children = arguments.length > 3 ? B.call(arguments, 2) : n), Q(t.type, l, s || t.key, i || t.ref, null);
|
|
232
232
|
}
|
|
233
|
-
B = Re.slice, m = { __e: function(t, e, n,
|
|
234
|
-
for (var
|
|
235
|
-
if ((
|
|
236
|
-
} catch (
|
|
237
|
-
t =
|
|
233
|
+
B = Re.slice, m = { __e: function(t, e, n, s) {
|
|
234
|
+
for (var i, o, a; e = e.__; ) if ((i = e.__c) && !i.__) try {
|
|
235
|
+
if ((o = i.constructor) && o.getDerivedStateFromError != null && (i.setState(o.getDerivedStateFromError(t)), a = i.__d), i.componentDidCatch != null && (i.componentDidCatch(t, s || {}), a = i.__d), a) return i.__E = i;
|
|
236
|
+
} catch (l) {
|
|
237
|
+
t = l;
|
|
238
238
|
}
|
|
239
239
|
throw t;
|
|
240
240
|
} }, Ee = 0, G.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),
|
|
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), ye(this));
|
|
243
243
|
}, G.prototype.forceUpdate = function(t) {
|
|
244
|
-
this.__v && (this.__e = !0, t && this.__h.push(t),
|
|
244
|
+
this.__v && (this.__e = !0, t && this.__h.push(t), ye(this));
|
|
245
245
|
}, G.prototype.render = U, R = [], Te = typeof Promise == "function" ? Promise.prototype.then.bind(Promise.resolve()) : setTimeout, He = function(t, e) {
|
|
246
246
|
return t.__v.__b - e.__v.__b;
|
|
247
247
|
}, Y.__r = 0, Ie = /(PointerCapture)$|Capture$/i, ce = 0, re = ve(!1), ae = ve(!0);
|
|
@@ -249,34 +249,34 @@ function Z() {
|
|
|
249
249
|
return Z = Object.assign ? Object.assign.bind() : function(t) {
|
|
250
250
|
for (var e = 1; e < arguments.length; e++) {
|
|
251
251
|
var n = arguments[e];
|
|
252
|
-
for (var
|
|
252
|
+
for (var s in n) Object.prototype.hasOwnProperty.call(n, s) && (t[s] = n[s]);
|
|
253
253
|
}
|
|
254
254
|
return t;
|
|
255
255
|
}, Z.apply(this, arguments);
|
|
256
256
|
}
|
|
257
257
|
function ze(t, e) {
|
|
258
258
|
if (t == null) return {};
|
|
259
|
-
var n,
|
|
260
|
-
for (
|
|
261
|
-
return
|
|
259
|
+
var n, s, i = {}, o = Object.keys(t);
|
|
260
|
+
for (s = 0; s < o.length; s++) e.indexOf(n = o[s]) >= 0 || (i[n] = t[n]);
|
|
261
|
+
return i;
|
|
262
262
|
}
|
|
263
263
|
var gt = ["context", "children"], dt = ["useFragment"];
|
|
264
|
-
function ht(t, e, n,
|
|
265
|
-
function
|
|
266
|
-
var
|
|
267
|
-
return
|
|
264
|
+
function ht(t, e, n, s) {
|
|
265
|
+
function i() {
|
|
266
|
+
var o = Reflect.construct(HTMLElement, [], i);
|
|
267
|
+
return o._vdomComponent = t, o._root = o, o;
|
|
268
268
|
}
|
|
269
|
-
return (
|
|
270
|
-
pt.call(this,
|
|
271
|
-
},
|
|
272
|
-
Object.defineProperty(
|
|
273
|
-
return this._vdom ? this._vdom.props[
|
|
269
|
+
return (i.prototype = Object.create(HTMLElement.prototype)).constructor = i, i.prototype.connectedCallback = function() {
|
|
270
|
+
pt.call(this, s);
|
|
271
|
+
}, i.prototype.attributeChangedCallback = mt, i.prototype.disconnectedCallback = yt, n = n || t.observedAttributes || Object.keys(t.propTypes || {}), i.observedAttributes = n, t.formAssociated && (i.formAssociated = !0), n.forEach(function(o) {
|
|
272
|
+
Object.defineProperty(i.prototype, o, { get: function() {
|
|
273
|
+
return this._vdom ? this._vdom.props[o] : this._props[o];
|
|
274
274
|
}, set: function(a) {
|
|
275
|
-
this._vdom ? this.attributeChangedCallback(
|
|
276
|
-
var
|
|
277
|
-
a != null &&
|
|
275
|
+
this._vdom ? this.attributeChangedCallback(o, null, a) : (this._props || (this._props = {}), this._props[o] = a);
|
|
276
|
+
var l = typeof a;
|
|
277
|
+
a != null && l !== "string" && l !== "boolean" && l !== "number" || this.setAttribute(o, a);
|
|
278
278
|
} });
|
|
279
|
-
}), customElements.define(e,
|
|
279
|
+
}), customElements.define(e, i), i;
|
|
280
280
|
}
|
|
281
281
|
function ft(t) {
|
|
282
282
|
this.getChildContext = function() {
|
|
@@ -296,43 +296,43 @@ function Ve(t) {
|
|
|
296
296
|
}
|
|
297
297
|
function mt(t, e, n) {
|
|
298
298
|
if (this._vdom) {
|
|
299
|
-
var
|
|
300
|
-
|
|
299
|
+
var s = {};
|
|
300
|
+
s[t] = n = n ?? void 0, s[Ve(t)] = n, this._vdom = Be(this._vdom, s), ne(this._vdom, this._root);
|
|
301
301
|
}
|
|
302
302
|
}
|
|
303
|
-
function
|
|
303
|
+
function yt() {
|
|
304
304
|
ne(this._vdom = null, this._root);
|
|
305
305
|
}
|
|
306
306
|
function be(t, e) {
|
|
307
|
-
var n = this,
|
|
308
|
-
return D(
|
|
309
|
-
|
|
307
|
+
var n = this, s = t.useFragment, i = ze(t, dt);
|
|
308
|
+
return D(s ? U : "slot", Z({}, i, { ref: function(o) {
|
|
309
|
+
o ? (n.ref = o, n._listener || (n._listener = function(a) {
|
|
310
310
|
a.stopPropagation(), a.detail.context = e;
|
|
311
|
-
},
|
|
311
|
+
}, o.addEventListener("_preact", n._listener))) : n.ref.removeEventListener("_preact", n._listener);
|
|
312
312
|
} }));
|
|
313
313
|
}
|
|
314
314
|
function Je(t, e, n) {
|
|
315
315
|
if (t.nodeType === 3) return t.data;
|
|
316
316
|
if (t.nodeType !== 1) return null;
|
|
317
|
-
var
|
|
318
|
-
for (
|
|
319
|
-
for (
|
|
320
|
-
var c = Je(
|
|
321
|
-
|
|
317
|
+
var s = [], i = {}, o = 0, a = t.attributes, l = t.childNodes;
|
|
318
|
+
for (o = a.length; o--; ) a[o].name !== "slot" && (i[a[o].name] = a[o].value, i[Ve(a[o].name)] = a[o].value);
|
|
319
|
+
for (o = l.length; o--; ) {
|
|
320
|
+
var c = Je(l[o], null, n), _ = l[o].slot;
|
|
321
|
+
_ ? i[_] = D(be, { name: _ }, c) : s[o] = c;
|
|
322
322
|
}
|
|
323
|
-
var g = !(!n || !n.shadow), r = e ? D(be, { useFragment: !g },
|
|
324
|
-
return !g && e && (t.innerHTML = ""), D(e || t.nodeName.toLowerCase(),
|
|
323
|
+
var g = !(!n || !n.shadow), r = e ? D(be, { useFragment: !g }, s) : s;
|
|
324
|
+
return !g && e && (t.innerHTML = ""), D(e || t.nodeName.toLowerCase(), i, r);
|
|
325
325
|
}
|
|
326
|
-
var
|
|
327
|
-
function u(t, e, n,
|
|
326
|
+
var wt = 0;
|
|
327
|
+
function u(t, e, n, s, i, o) {
|
|
328
328
|
e || (e = {});
|
|
329
|
-
var a,
|
|
330
|
-
if ("ref" in c) for (
|
|
331
|
-
var
|
|
332
|
-
if (typeof t == "function" && (a = t.defaultProps)) for (
|
|
333
|
-
return m.vnode && m.vnode(
|
|
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: --wt, __i: -1, __u: 0, __source: i, __self: o };
|
|
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 j, v,
|
|
335
|
+
var j, v, se, Ce, ee = 0, Ke = [], C = m, ke = C.__b, Ae = C.__r, Se = C.diffed, $e = C.__c, Ne = C.unmount, We = C.__;
|
|
336
336
|
function he(t, e) {
|
|
337
337
|
C.__h && C.__h(v, t, ee || e), ee = 0;
|
|
338
338
|
var n = v.__H || (v.__H = { __: [], __h: [] });
|
|
@@ -342,38 +342,38 @@ function E(t) {
|
|
|
342
342
|
return ee = 1, vt(Xe, t);
|
|
343
343
|
}
|
|
344
344
|
function vt(t, e, n) {
|
|
345
|
-
var
|
|
346
|
-
if (
|
|
347
|
-
var c =
|
|
348
|
-
c !==
|
|
349
|
-
}],
|
|
350
|
-
var
|
|
351
|
-
if (!
|
|
352
|
-
var g =
|
|
345
|
+
var s = he(j++, 2);
|
|
346
|
+
if (s.t = t, !s.__c && (s.__ = [Xe(void 0, e), function(l) {
|
|
347
|
+
var c = s.__N ? s.__N[0] : s.__[0], _ = s.t(c, l);
|
|
348
|
+
c !== _ && (s.__N = [_, s.__[1]], s.__c.setState({}));
|
|
349
|
+
}], s.__c = v, !v.__f)) {
|
|
350
|
+
var i = function(l, c, _) {
|
|
351
|
+
if (!s.__c.__H) return !0;
|
|
352
|
+
var g = s.__c.__H.__.filter(function(f) {
|
|
353
353
|
return !!f.__c;
|
|
354
354
|
});
|
|
355
355
|
if (g.every(function(f) {
|
|
356
356
|
return !f.__N;
|
|
357
|
-
})) return !
|
|
358
|
-
var r =
|
|
357
|
+
})) return !o || o.call(this, l, c, _);
|
|
358
|
+
var r = s.__c.props !== l;
|
|
359
359
|
return g.forEach(function(f) {
|
|
360
360
|
if (f.__N) {
|
|
361
361
|
var d = f.__[0];
|
|
362
362
|
f.__ = f.__N, f.__N = void 0, d !== f.__[0] && (r = !0);
|
|
363
363
|
}
|
|
364
|
-
}),
|
|
364
|
+
}), o && o.call(this, l, c, _) || r;
|
|
365
365
|
};
|
|
366
366
|
v.__f = !0;
|
|
367
|
-
var
|
|
368
|
-
v.componentWillUpdate = function(
|
|
367
|
+
var o = v.shouldComponentUpdate, a = v.componentWillUpdate;
|
|
368
|
+
v.componentWillUpdate = function(l, c, _) {
|
|
369
369
|
if (this.__e) {
|
|
370
|
-
var g =
|
|
371
|
-
|
|
370
|
+
var g = o;
|
|
371
|
+
o = void 0, i(l, c, _), o = g;
|
|
372
372
|
}
|
|
373
|
-
a && a.call(this,
|
|
374
|
-
}, v.shouldComponentUpdate =
|
|
373
|
+
a && a.call(this, l, c, _);
|
|
374
|
+
}, v.shouldComponentUpdate = i;
|
|
375
375
|
}
|
|
376
|
-
return
|
|
376
|
+
return s.__N || s.__;
|
|
377
377
|
}
|
|
378
378
|
function xe(t, e) {
|
|
379
379
|
var n = he(j++, 3);
|
|
@@ -398,47 +398,47 @@ function Ct() {
|
|
|
398
398
|
C.__b = function(t) {
|
|
399
399
|
v = null, ke && ke(t);
|
|
400
400
|
}, C.__ = function(t, e) {
|
|
401
|
-
t && e.__k && e.__k.__m && (t.__m = e.__k.__m),
|
|
401
|
+
t && e.__k && e.__k.__m && (t.__m = e.__k.__m), We && We(t, e);
|
|
402
402
|
}, C.__r = function(t) {
|
|
403
403
|
Ae && Ae(t), j = 0;
|
|
404
404
|
var e = (v = t.__c).__H;
|
|
405
|
-
e && (
|
|
405
|
+
e && (se === v ? (e.__h = [], v.__h = [], e.__.forEach(function(n) {
|
|
406
406
|
n.__N && (n.__ = n.__N), n.u = n.__N = void 0;
|
|
407
|
-
})) : (e.__h.forEach(X), e.__h.forEach(_e), e.__h = [], j = 0)),
|
|
407
|
+
})) : (e.__h.forEach(X), e.__h.forEach(_e), e.__h = [], j = 0)), se = v;
|
|
408
408
|
}, C.diffed = function(t) {
|
|
409
409
|
Se && Se(t);
|
|
410
410
|
var e = t.__c;
|
|
411
411
|
e && e.__H && (e.__H.__h.length && (Ke.push(e) !== 1 && Ce === C.requestAnimationFrame || ((Ce = C.requestAnimationFrame) || kt)(Ct)), e.__H.__.forEach(function(n) {
|
|
412
412
|
n.u && (n.__H = n.u), n.u = void 0;
|
|
413
|
-
})),
|
|
413
|
+
})), se = v = null;
|
|
414
414
|
}, C.__c = function(t, e) {
|
|
415
415
|
e.some(function(n) {
|
|
416
416
|
try {
|
|
417
|
-
n.__h.forEach(X), n.__h = n.__h.filter(function(
|
|
418
|
-
return !
|
|
417
|
+
n.__h.forEach(X), n.__h = n.__h.filter(function(s) {
|
|
418
|
+
return !s.__ || _e(s);
|
|
419
419
|
});
|
|
420
|
-
} catch (
|
|
421
|
-
e.some(function(
|
|
422
|
-
|
|
423
|
-
}), e = [], C.__e(
|
|
420
|
+
} catch (s) {
|
|
421
|
+
e.some(function(i) {
|
|
422
|
+
i.__h && (i.__h = []);
|
|
423
|
+
}), e = [], C.__e(s, n.__v);
|
|
424
424
|
}
|
|
425
425
|
}), $e && $e(t, e);
|
|
426
426
|
}, C.unmount = function(t) {
|
|
427
|
-
|
|
427
|
+
Ne && Ne(t);
|
|
428
428
|
var e, n = t.__c;
|
|
429
|
-
n && n.__H && (n.__H.__.forEach(function(
|
|
429
|
+
n && n.__H && (n.__H.__.forEach(function(s) {
|
|
430
430
|
try {
|
|
431
|
-
X(
|
|
432
|
-
} catch (
|
|
433
|
-
e =
|
|
431
|
+
X(s);
|
|
432
|
+
} catch (i) {
|
|
433
|
+
e = i;
|
|
434
434
|
}
|
|
435
435
|
}), n.__H = void 0, e && C.__e(e, n.__v));
|
|
436
436
|
};
|
|
437
437
|
var Me = typeof requestAnimationFrame == "function";
|
|
438
438
|
function kt(t) {
|
|
439
439
|
var e, n = function() {
|
|
440
|
-
clearTimeout(
|
|
441
|
-
},
|
|
440
|
+
clearTimeout(s), Me && cancelAnimationFrame(e), setTimeout(t);
|
|
441
|
+
}, s = setTimeout(n, 35);
|
|
442
442
|
Me && (e = requestAnimationFrame(n));
|
|
443
443
|
}
|
|
444
444
|
function X(t) {
|
|
@@ -450,8 +450,8 @@ function _e(t) {
|
|
|
450
450
|
t.__c = t.__(), v = e;
|
|
451
451
|
}
|
|
452
452
|
function Ge(t, e) {
|
|
453
|
-
return !t || t.length !== e.length || e.some(function(n,
|
|
454
|
-
return n !== t[
|
|
453
|
+
return !t || t.length !== e.length || e.some(function(n, s) {
|
|
454
|
+
return n !== t[s];
|
|
455
455
|
});
|
|
456
456
|
}
|
|
457
457
|
function Xe(t, e) {
|
|
@@ -477,8 +477,8 @@ class St {
|
|
|
477
477
|
try {
|
|
478
478
|
const n = await fetch(`${this.agentUrl}/api/agent/${this.agentId}`);
|
|
479
479
|
if (n.ok) {
|
|
480
|
-
const
|
|
481
|
-
return console.log("[AriaFlow Widget] Agent config received:",
|
|
480
|
+
const s = await n.json();
|
|
481
|
+
return console.log("[AriaFlow Widget] Agent config received:", s), !s || s.status !== "active" ? (console.error("Agent not found or inactive"), null) : (this.agentConfig = s, this.maxReconnectAttempts = s.config.maxRetries || 5, this.reconnectDelay = s.config.reconnectDelay || 1e3, await this.connectToAgent(), s);
|
|
482
482
|
}
|
|
483
483
|
} catch {
|
|
484
484
|
console.warn("[AriaFlow Widget] Agent config endpoint not available, trying fallback");
|
|
@@ -512,23 +512,23 @@ class St {
|
|
|
512
512
|
if (!this.agentConfig?.wsUrl)
|
|
513
513
|
throw new Error("No agent WebSocket URL configured");
|
|
514
514
|
const e = this.getSessionId(), n = `${this.agentConfig.wsUrl}/${e}`;
|
|
515
|
-
return console.log("[AriaFlow Widget] Connecting to WebSocket:", n), new Promise((
|
|
515
|
+
return console.log("[AriaFlow Widget] Connecting to WebSocket:", n), new Promise((s, i) => {
|
|
516
516
|
try {
|
|
517
517
|
this.ws = new WebSocket(n), this.ws.onopen = () => {
|
|
518
|
-
console.log("[Widget] Connected to agent"), this.reconnectAttempts = 0, this.notifyConnectionChange(!0),
|
|
519
|
-
}, this.ws.onmessage = (
|
|
520
|
-
this.handleMessage(
|
|
518
|
+
console.log("[Widget] Connected to agent"), this.reconnectAttempts = 0, this.notifyConnectionChange(!0), s();
|
|
519
|
+
}, this.ws.onmessage = (o) => {
|
|
520
|
+
this.handleMessage(o);
|
|
521
521
|
}, this.ws.onclose = () => {
|
|
522
522
|
if (console.log("[Widget] Disconnected from agent"), this.notifyConnectionChange(!1), this.reconnectAttempts < this.maxReconnectAttempts) {
|
|
523
523
|
this.reconnectAttempts++;
|
|
524
|
-
const
|
|
525
|
-
console.log(`[Widget] Reconnecting in ${
|
|
524
|
+
const o = this.reconnectDelay * Math.pow(2, this.reconnectAttempts - 1);
|
|
525
|
+
console.log(`[Widget] Reconnecting in ${o}ms... (attempt ${this.reconnectAttempts})`), setTimeout(() => this.connectToAgent(), o);
|
|
526
526
|
}
|
|
527
|
-
}, this.ws.onerror = (
|
|
528
|
-
console.error("[Widget] WebSocket error:",
|
|
527
|
+
}, this.ws.onerror = (o) => {
|
|
528
|
+
console.error("[Widget] WebSocket error:", o), i(o);
|
|
529
529
|
};
|
|
530
|
-
} catch (
|
|
531
|
-
|
|
530
|
+
} catch (o) {
|
|
531
|
+
i(o);
|
|
532
532
|
}
|
|
533
533
|
});
|
|
534
534
|
}
|
|
@@ -550,13 +550,13 @@ class St {
|
|
|
550
550
|
try {
|
|
551
551
|
const n = JSON.parse(e.data);
|
|
552
552
|
if (n.type === "text-delta")
|
|
553
|
-
this.isAgentProcessing && this.notifyProcessingChange(!1), this.setMessages((
|
|
554
|
-
const
|
|
555
|
-
return
|
|
556
|
-
...
|
|
557
|
-
{ ...
|
|
553
|
+
this.isAgentProcessing && this.notifyProcessingChange(!1), this.setMessages((s) => {
|
|
554
|
+
const i = s[s.length - 1];
|
|
555
|
+
return i && i.role === "assistant" && i.isStreaming ? [
|
|
556
|
+
...s.slice(0, -1),
|
|
557
|
+
{ ...i, content: i.content + n.text }
|
|
558
558
|
] : [
|
|
559
|
-
...
|
|
559
|
+
...s,
|
|
560
560
|
{
|
|
561
561
|
id: K(),
|
|
562
562
|
role: "assistant",
|
|
@@ -567,45 +567,53 @@ class St {
|
|
|
567
567
|
];
|
|
568
568
|
});
|
|
569
569
|
else if (n.type === "done")
|
|
570
|
-
console.log("[Widget] Response complete"), this.notifyProcessingChange(!1), this.setMessages((
|
|
571
|
-
const
|
|
572
|
-
return
|
|
573
|
-
...
|
|
574
|
-
{ ...
|
|
575
|
-
] :
|
|
570
|
+
console.log("[Widget] Response complete"), this.notifyProcessingChange(!1), this.setMessages((s) => {
|
|
571
|
+
const i = s[s.length - 1];
|
|
572
|
+
return i && i.role === "assistant" && i.isStreaming ? [
|
|
573
|
+
...s.slice(0, -1),
|
|
574
|
+
{ ...i, isStreaming: !1 }
|
|
575
|
+
] : s;
|
|
576
576
|
}), this.isAgentStreaming = !1, this.notifyStreamingChange(!1), this.processMessageQueue();
|
|
577
577
|
else if (n.type === "step-start" || n.type === "agent-start")
|
|
578
578
|
console.log(`[Widget] ${n.type} received:`, n.agentId || ""), this.isAgentStreaming = !0, this.notifyStreamingChange(!0), this.notifyProcessingChange(!0);
|
|
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
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
(
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
582
|
+
const s = n.toolName || n.tool?.name, i = n.args || n.tool?.arguments;
|
|
583
|
+
if (console.log("[Widget] Tool call:", s), this.notifyProcessingChange(!0), s === "suggest_options" && (i?.options || i)) {
|
|
584
|
+
const o = i?.options || i;
|
|
585
|
+
Array.isArray(o) && this.setMessages((a) => {
|
|
586
|
+
const l = [...a].reverse().find((c) => c.role === "assistant");
|
|
587
|
+
return l ? a.map(
|
|
588
|
+
(c) => c.id === l.id ? { ...c, suggestions: o } : c
|
|
589
|
+
) : a;
|
|
590
|
+
});
|
|
591
|
+
} else {
|
|
592
|
+
const o = {
|
|
593
|
+
id: K(),
|
|
594
|
+
role: "tool",
|
|
595
|
+
content: `Calling tool: ${s}`,
|
|
596
|
+
timestamp: Date.now(),
|
|
597
|
+
toolCall: {
|
|
598
|
+
name: s,
|
|
599
|
+
arguments: i
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
this.setMessages((a) => [...a, o]);
|
|
603
|
+
}
|
|
604
|
+
} else if (n.type === "tool-result") {
|
|
605
|
+
const s = n.toolName || n.tool?.name;
|
|
606
|
+
console.log("[Widget] Tool result:", s), s === "suggest_options" || this.setMessages((i) => {
|
|
607
|
+
const o = i[i.length - 1];
|
|
608
|
+
return o && o.role === "tool" && !o.toolResult ? [
|
|
609
|
+
...i.slice(0, -1),
|
|
610
|
+
{ ...o, content: o.content + `
|
|
604
611
|
Result: ${JSON.stringify(n.result)}`, toolResult: n.result }
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
612
|
+
] : i;
|
|
613
|
+
});
|
|
614
|
+
} else 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((s) => {
|
|
615
|
+
const i = [...s].reverse().find((o) => o.role === "assistant");
|
|
616
|
+
return i ? s.map((o) => o.id === i.id ? { ...o, suggestions: n.suggestions } : o) : s;
|
|
609
617
|
})) : console.log("[Widget] Unknown message type:", n.type);
|
|
610
618
|
} catch (n) {
|
|
611
619
|
console.error("[Widget] Error parsing message:", e.data, n);
|
|
@@ -623,7 +631,7 @@ Result: ${JSON.stringify(n.result)}`, toolResult: n.result }
|
|
|
623
631
|
content: e,
|
|
624
632
|
timestamp: Date.now()
|
|
625
633
|
};
|
|
626
|
-
if (this.setMessages((
|
|
634
|
+
if (this.setMessages((s) => [...s, n]), this.isAgentStreaming) {
|
|
627
635
|
console.log("[Widget] Agent is streaming, queuing message"), this.messageQueue.push(e), this.notifyQueueChange(this.messageQueue.length);
|
|
628
636
|
return;
|
|
629
637
|
}
|
|
@@ -741,7 +749,7 @@ Result: ${JSON.stringify(n.result)}`, toolResult: n.result }
|
|
|
741
749
|
this.ws && (this.ws.close(), this.ws = null), this.messageCallbacks.clear(), this.connectionCallbacks.clear();
|
|
742
750
|
}
|
|
743
751
|
}
|
|
744
|
-
const
|
|
752
|
+
const ie = {
|
|
745
753
|
none: "0",
|
|
746
754
|
small: "0.375rem",
|
|
747
755
|
medium: "0.75rem",
|
|
@@ -752,13 +760,13 @@ function $t({
|
|
|
752
760
|
agentId: e,
|
|
753
761
|
// Legacy props for backward compatibility
|
|
754
762
|
widgetId: n,
|
|
755
|
-
apiUrl:
|
|
756
|
-
mode:
|
|
757
|
-
theme:
|
|
763
|
+
apiUrl: s,
|
|
764
|
+
mode: i = "chat",
|
|
765
|
+
theme: o = "light",
|
|
758
766
|
position: a = "bottom-right",
|
|
759
|
-
size:
|
|
767
|
+
size: l = "full",
|
|
760
768
|
radius: c = "medium",
|
|
761
|
-
baseColor:
|
|
769
|
+
baseColor: _,
|
|
762
770
|
accentColor: g = "#14B8A6",
|
|
763
771
|
buttonBaseColor: r = "#000000",
|
|
764
772
|
buttonAccentColor: f = "#FFFFFF",
|
|
@@ -766,7 +774,7 @@ function $t({
|
|
|
766
774
|
subtitle: b,
|
|
767
775
|
emptyChatMessage: S
|
|
768
776
|
}) {
|
|
769
|
-
const [
|
|
777
|
+
const [w, p] = E(!1), [h, M] = E([]), [N, T] = E(""), [$, z] = E(!1), [A, H] = E(!1), [I, W] = E(null), [x, Ye] = E(!1), [Ze, et] = E(!1), [oe, tt] = E(0), V = Fe(null), fe = Fe(null);
|
|
770
778
|
xe(() => ((async () => {
|
|
771
779
|
if (t && e) {
|
|
772
780
|
console.log("[AriaFlow Widget] Using new agent resolution:", { agentUrl: t, agentId: e });
|
|
@@ -785,41 +793,41 @@ function $t({
|
|
|
785
793
|
console.log("[AriaFlow Widget] Processing state:", k), et(k);
|
|
786
794
|
});
|
|
787
795
|
const L = await F.initWidget();
|
|
788
|
-
console.log("[AriaFlow Widget] Agent config received:", L), L ? (
|
|
796
|
+
console.log("[AriaFlow Widget] Agent config received:", L), L ? (W(L), console.log("[AriaFlow Widget] Widget initialized successfully")) : console.error("[AriaFlow Widget] Agent config fetch failed");
|
|
789
797
|
} catch (L) {
|
|
790
798
|
console.error("[AriaFlow Widget] Initialization error:", L);
|
|
791
799
|
}
|
|
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")) :
|
|
800
|
+
} 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")) : s && 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
801
|
})(), () => {
|
|
794
802
|
V.current?.dispose();
|
|
795
|
-
}), [t, e, n,
|
|
803
|
+
}), [t, e, n, s]), xe(() => {
|
|
796
804
|
fe.current?.scrollIntoView({ behavior: "smooth" });
|
|
797
805
|
}, [h]);
|
|
798
806
|
const pe = async () => {
|
|
799
|
-
if (!
|
|
800
|
-
const
|
|
807
|
+
if (!N.trim() || !$) return;
|
|
808
|
+
const y = N.trim();
|
|
801
809
|
T("");
|
|
802
810
|
try {
|
|
803
|
-
await V.current?.sendMessage(
|
|
811
|
+
await V.current?.sendMessage(y);
|
|
804
812
|
} catch (F) {
|
|
805
813
|
console.error("Failed to send message:", F);
|
|
806
814
|
}
|
|
807
|
-
}, nt = (
|
|
808
|
-
|
|
809
|
-
}, ot = (
|
|
810
|
-
!$ || x || V.current?.sendMessage(
|
|
811
|
-
},
|
|
812
|
-
return console.log("[AriaFlow Widget] Rendering widget component", { isInitialized: A, isOpen:
|
|
815
|
+
}, nt = (y) => {
|
|
816
|
+
y.key === "Enter" && !y.shiftKey && (y.preventDefault(), pe());
|
|
817
|
+
}, ot = (y) => {
|
|
818
|
+
!$ || x || V.current?.sendMessage(y);
|
|
819
|
+
}, st = d || I?.config.title || "Ninewells Hospital", it = b || I?.config.subtitle || "How can we help you today?", rt = S || I?.config.emptyChatMessage || "Start a conversation with Ninewells...";
|
|
820
|
+
return console.log("[AriaFlow Widget] Rendering widget component", { isInitialized: A, isOpen: w, position: a }), /* @__PURE__ */ u(
|
|
813
821
|
"div",
|
|
814
822
|
{
|
|
815
|
-
className: `ariaflow-widget-container ariaflow-widget-${a} ariaflow-widget-${
|
|
816
|
-
"data-theme":
|
|
823
|
+
className: `ariaflow-widget-container ariaflow-widget-${a} ariaflow-widget-${l} ariaflow-widget-radius-${c}`,
|
|
824
|
+
"data-theme": o,
|
|
817
825
|
style: {
|
|
818
826
|
"--ariaflow-accent-color": g,
|
|
819
|
-
"--ariaflow-base-color":
|
|
827
|
+
"--ariaflow-base-color": _
|
|
820
828
|
},
|
|
821
829
|
children: [
|
|
822
|
-
!
|
|
830
|
+
!w && /* @__PURE__ */ u(
|
|
823
831
|
"button",
|
|
824
832
|
{
|
|
825
833
|
className: "ariaflow-widget-launcher",
|
|
@@ -868,13 +876,13 @@ function $t({
|
|
|
868
876
|
]
|
|
869
877
|
}
|
|
870
878
|
),
|
|
871
|
-
|
|
879
|
+
w && A && /* @__PURE__ */ u(
|
|
872
880
|
"div",
|
|
873
881
|
{
|
|
874
882
|
className: "ariaflow-widget-window",
|
|
875
883
|
style: {
|
|
876
|
-
backgroundColor:
|
|
877
|
-
borderRadius:
|
|
884
|
+
backgroundColor: o === "dark" && _ ? _ : void 0,
|
|
885
|
+
borderRadius: ie[c]
|
|
878
886
|
},
|
|
879
887
|
children: [
|
|
880
888
|
/* @__PURE__ */ u(
|
|
@@ -883,12 +891,12 @@ function $t({
|
|
|
883
891
|
className: "ariaflow-widget-header",
|
|
884
892
|
style: {
|
|
885
893
|
backgroundColor: g,
|
|
886
|
-
borderRadius: c === "none" ? "0" : `${
|
|
894
|
+
borderRadius: c === "none" ? "0" : `${ie[c]} ${ie[c]} 0 0`
|
|
887
895
|
},
|
|
888
896
|
children: [
|
|
889
897
|
/* @__PURE__ */ u("div", { className: "ariaflow-widget-header-content", children: /* @__PURE__ */ u("div", { className: "ariaflow-widget-title-group", children: [
|
|
890
|
-
/* @__PURE__ */ u("h3", { className: "ariaflow-widget-title", children:
|
|
891
|
-
/* @__PURE__ */ u("p", { className: "ariaflow-widget-subtitle", children:
|
|
898
|
+
/* @__PURE__ */ u("h3", { className: "ariaflow-widget-title", children: st }),
|
|
899
|
+
/* @__PURE__ */ u("p", { className: "ariaflow-widget-subtitle", children: it })
|
|
892
900
|
] }) }),
|
|
893
901
|
/* @__PURE__ */ u(
|
|
894
902
|
"button",
|
|
@@ -921,37 +929,37 @@ function $t({
|
|
|
921
929
|
"Connecting..."
|
|
922
930
|
] }),
|
|
923
931
|
/* @__PURE__ */ u("div", { className: "ariaflow-widget-messages", children: h.length === 0 ? /* @__PURE__ */ u("div", { className: "ariaflow-widget-empty", children: /* @__PURE__ */ u("p", { children: $ ? rt : "Connecting to agent..." }) }) : /* @__PURE__ */ u(U, { children: [
|
|
924
|
-
h.map((
|
|
932
|
+
h.map((y, F) => (h.length - 1, /* @__PURE__ */ u(
|
|
925
933
|
"div",
|
|
926
934
|
{
|
|
927
|
-
className: `ariaflow-widget-message ariaflow-widget-message-${
|
|
928
|
-
children: /* @__PURE__ */ u("div", { className: "ariaflow-widget-message-bubble", children:
|
|
935
|
+
className: `ariaflow-widget-message ariaflow-widget-message-${y.role}`,
|
|
936
|
+
children: /* @__PURE__ */ u("div", { className: "ariaflow-widget-message-bubble", children: y.role === "tool" ? /* @__PURE__ */ u("div", { className: "ariaflow-widget-tool-message", children: [
|
|
929
937
|
/* @__PURE__ */ u("div", { className: "ariaflow-widget-tool-header", children: [
|
|
930
938
|
"🔧 ",
|
|
931
|
-
|
|
939
|
+
y.toolCall?.name
|
|
932
940
|
] }),
|
|
933
941
|
/* @__PURE__ */ u("div", { className: "ariaflow-widget-tool-content", children: [
|
|
934
|
-
|
|
942
|
+
y.toolCall && /* @__PURE__ */ u("div", { className: "ariaflow-widget-tool-args", children: [
|
|
935
943
|
/* @__PURE__ */ u("strong", { children: "Arguments:" }),
|
|
936
944
|
" ",
|
|
937
|
-
JSON.stringify(
|
|
945
|
+
JSON.stringify(y.toolCall.arguments, null, 2)
|
|
938
946
|
] }),
|
|
939
|
-
|
|
947
|
+
y.toolResult && /* @__PURE__ */ u("div", { className: "ariaflow-widget-tool-result", children: [
|
|
940
948
|
/* @__PURE__ */ u("strong", { children: "Result:" }),
|
|
941
949
|
" ",
|
|
942
|
-
JSON.stringify(
|
|
950
|
+
JSON.stringify(y.toolResult, null, 2)
|
|
943
951
|
] })
|
|
944
952
|
] })
|
|
945
953
|
] }) : /* @__PURE__ */ u(U, { children: [
|
|
946
|
-
|
|
947
|
-
|
|
954
|
+
y.content,
|
|
955
|
+
y.isStreaming && /* @__PURE__ */ u("span", { className: "ariaflow-widget-typing-indicator", children: [
|
|
948
956
|
/* @__PURE__ */ u("span", { children: "•" }),
|
|
949
957
|
/* @__PURE__ */ u("span", { children: "•" }),
|
|
950
958
|
/* @__PURE__ */ u("span", { children: "•" })
|
|
951
959
|
] })
|
|
952
960
|
] }) })
|
|
953
961
|
},
|
|
954
|
-
|
|
962
|
+
y.id
|
|
955
963
|
))),
|
|
956
964
|
/* @__PURE__ */ u("div", { ref: fe }),
|
|
957
965
|
Ze && !x && /* @__PURE__ */ u("div", { className: "ariaflow-widget-message ariaflow-widget-message-assistant", children: /* @__PURE__ */ u("div", { className: "ariaflow-widget-message-bubble", children: /* @__PURE__ */ u("span", { className: "ariaflow-widget-typing-indicator", children: [
|
|
@@ -960,27 +968,27 @@ function $t({
|
|
|
960
968
|
/* @__PURE__ */ u("span", { children: "•" })
|
|
961
969
|
] }) }) })
|
|
962
970
|
] }) }),
|
|
963
|
-
!x && h.length > 0 && h[h.length - 1].role === "assistant" && h[h.length - 1].suggestions && h[h.length - 1].suggestions.length > 0 && /* @__PURE__ */ u("div", { className: "ariaflow-widget-suggestions", children: h[h.length - 1].suggestions.map((
|
|
971
|
+
!x && h.length > 0 && h[h.length - 1].role === "assistant" && h[h.length - 1].suggestions && h[h.length - 1].suggestions.length > 0 && /* @__PURE__ */ u("div", { className: "ariaflow-widget-suggestions", children: h[h.length - 1].suggestions.map((y) => /* @__PURE__ */ u(
|
|
964
972
|
"button",
|
|
965
973
|
{
|
|
966
974
|
className: "ariaflow-widget-chip",
|
|
967
|
-
onClick: () => ot(
|
|
975
|
+
onClick: () => ot(y),
|
|
968
976
|
style: {
|
|
969
977
|
borderColor: g,
|
|
970
978
|
color: g,
|
|
971
979
|
backgroundColor: "rgba(255, 255, 255, 0.95)",
|
|
972
980
|
backdropFilter: "blur(4px)"
|
|
973
981
|
},
|
|
974
|
-
children:
|
|
982
|
+
children: y
|
|
975
983
|
},
|
|
976
|
-
|
|
984
|
+
y
|
|
977
985
|
)) }),
|
|
978
986
|
/* @__PURE__ */ u("div", { className: "ariaflow-widget-input", children: [
|
|
979
987
|
/* @__PURE__ */ u(
|
|
980
988
|
"textarea",
|
|
981
989
|
{
|
|
982
|
-
value:
|
|
983
|
-
onInput: (
|
|
990
|
+
value: N,
|
|
991
|
+
onInput: (y) => T(y.target.value),
|
|
984
992
|
onKeyDown: nt,
|
|
985
993
|
placeholder: $ ? x ? oe > 0 ? `Agent is responding... (${oe} message${oe > 1 ? "s" : ""} queued)` : "Agent is responding..." : "Type your message..." : "Connecting...",
|
|
986
994
|
rows: 1,
|
|
@@ -992,7 +1000,7 @@ function $t({
|
|
|
992
1000
|
{
|
|
993
1001
|
className: "ariaflow-widget-send",
|
|
994
1002
|
onClick: pe,
|
|
995
|
-
disabled: !
|
|
1003
|
+
disabled: !N.trim() || !$,
|
|
996
1004
|
style: { backgroundColor: g },
|
|
997
1005
|
"aria-label": "Send message",
|
|
998
1006
|
children: /* @__PURE__ */ u(
|
package/dist/widget.umd.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(H,E){typeof exports=="object"&&typeof module<"u"?E(exports):typeof define=="function"&&define.amd?define(["exports"],E):(H=typeof globalThis<"u"?globalThis:H||self,E(H.AriaFlowWidget={}))})(this,function(H){"use strict";var E,m,pe,I,me,ye,we,ve,ie,se,re,q={},be=[],tt=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,V=Array.isArray;function M(t,e){for(var n in e)t[n]=e[n];return t}function ae(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function L(t,e,n){var o,s,i,a={};for(i in e)i=="key"?o=e[i]:i=="ref"?s=e[i]:a[i]=e[i];if(arguments.length>2&&(a.children=arguments.length>3?E.call(arguments,2):n),typeof t=="function"&&t.defaultProps!=null)for(i in t.defaultProps)a[i]===void 0&&(a[i]=t.defaultProps[i]);return j(t,a,o,s,null)}function j(t,e,n,o,s){var i={type:t,props:e,key:n,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:s??++pe,__i:-1,__u:0};return s==null&&m.vnode!=null&&m.vnode(i),i}function R(t){return t.children}function J(t,e){this.props=t,this.context=e}function Q(t,e){if(e==null)return t.__?Q(t.__,t.__i+1):null;for(var n;e<t.__k.length;e++)if((n=t.__k[e])!=null&&n.__e!=null)return n.__e;return typeof t.type=="function"?Q(t):null}function Ce(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 Ce(t)}}function ke(t){(!t.__d&&(t.__d=!0)&&I.push(t)&&!K.__r++||me!=m.debounceRendering)&&((me=m.debounceRendering)||ye)(K)}function K(){for(var t,e,n,o,s,i,a,_=1;I.length;)I.length>_&&I.sort(we),t=I.shift(),_=I.length,t.__d&&(n=void 0,o=void 0,s=(o=(e=t).__v).__e,i=[],a=[],e.__P&&((n=M({},o)).__v=o.__v+1,m.vnode&&m.vnode(n),le(e.__P,n,o,e.__n,e.__P.namespaceURI,32&o.__u?[s]:null,i,s??Q(o),!!(32&o.__u),a),n.__v=o.__v,n.__.__k[n.__i]=n,Ne(i,n,a),o.__e=o.__=null,n.__e!=s&&Ce(n)));K.__r=0}function Ae(t,e,n,o,s,i,a,_,c,l,g){var r,f,d,C,S,v,p,h=o&&o.__k||be,P=e.length;for(c=nt(n,e,h,c,P),r=0;r<P;r++)(d=n.__k[r])!=null&&(f=d.__i==-1?q:h[d.__i]||q,d.__i=r,v=le(t,d,f,s,i,a,_,c,l,g),C=d.__e,d.ref&&f.ref!=d.ref&&(f.ref&&ce(f.ref,null,d),g.push(d.ref,d.__c||C,d)),S==null&&C!=null&&(S=C),(p=!!(4&d.__u))||f.__k===d.__k?c=Se(d,c,t,p):typeof d.type=="function"&&v!==void 0?c=v:C&&(c=C.nextSibling),d.__u&=-7);return n.__e=S,c}function nt(t,e,n,o,s){var i,a,_,c,l,g=n.length,r=g,f=0;for(t.__k=new Array(s),i=0;i<s;i++)(a=e[i])!=null&&typeof a!="boolean"&&typeof a!="function"?(typeof a=="string"||typeof a=="number"||typeof a=="bigint"||a.constructor==String?a=t.__k[i]=j(null,a,null,null,null):V(a)?a=t.__k[i]=j(R,{children:a},null,null,null):a.constructor===void 0&&a.__b>0?a=t.__k[i]=j(a.type,a.props,a.key,a.ref?a.ref:null,a.__v):t.__k[i]=a,c=i+f,a.__=t,a.__b=t.__b+1,_=null,(l=a.__i=ot(a,n,c,r))!=-1&&(r--,(_=n[l])&&(_.__u|=2)),_==null||_.__v==null?(l==-1&&(s>g?f--:s<g&&f++),typeof a.type!="function"&&(a.__u|=4)):l!=c&&(l==c-1?f--:l==c+1?f++:(l>c?f--:f++,a.__u|=4))):t.__k[i]=null;if(r)for(i=0;i<g;i++)(_=n[i])!=null&&!(2&_.__u)&&(_.__e==o&&(o=Q(_)),Fe(_,_));return o}function Se(t,e,n,o){var s,i;if(typeof t.type=="function"){for(s=t.__k,i=0;s&&i<s.length;i++)s[i]&&(s[i].__=t,e=Se(s[i],e,n,o));return e}t.__e!=e&&(o&&(e&&t.type&&!e.parentNode&&(e=Q(t)),n.insertBefore(t.__e,e||null)),e=t.__e);do e=e&&e.nextSibling;while(e!=null&&e.nodeType==8);return e}function ot(t,e,n,o){var s,i,a,_=t.key,c=t.type,l=e[n],g=l!=null&&(2&l.__u)==0;if(l===null&&_==null||g&&_==l.key&&c==l.type)return n;if(o>(g?1:0)){for(s=n-1,i=n+1;s>=0||i<e.length;)if((l=e[a=s>=0?s--:i++])!=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"||tt.test(e)?n:n+"px"}function G(t,e,n,o,s){var i,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")i=e!=(e=e.replace(ve,"$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+i]=n,n?o?n.u=o.u:(n.u=ie,t.addEventListener(e,i?re:se,i)):t.removeEventListener(e,i?re:se,i);else{if(s=="http://www.w3.org/2000/svg")e=e.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(e!="width"&&e!="height"&&e!="href"&&e!="list"&&e!="form"&&e!="tabIndex"&&e!="download"&&e!="rowSpan"&&e!="colSpan"&&e!="role"&&e!="popover"&&e in t)try{t[e]=n??"";break e}catch{}typeof n=="function"||(n==null||n===!1&&e[4]!="-"?t.removeAttribute(e):t.setAttribute(e,e=="popover"&&n==1?"":n))}}function We(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 le(t,e,n,o,s,i,a,_,c,l){var g,r,f,d,C,S,v,p,h,P,W,U,$,ne,A,D,O,N=e.type;if(e.constructor!==void 0)return null;128&n.__u&&(c=!!(32&n.__u),i=[_=e.__e=n.__e]),(g=m.__b)&&g(e);e:if(typeof N=="function")try{if(p=e.props,h="prototype"in N&&N.prototype.render,P=(g=N.contextType)&&o[g.__c],W=g?P?P.props.value:g.__:o,n.__c?v=(r=e.__c=n.__c).__=r.__E:(h?e.__c=r=new N(p,W):(e.__c=r=new J(p,W),r.constructor=N,r.render=st),P&&P.sub(r),r.state||(r.state={}),r.__n=o,f=r.__d=!0,r.__h=[],r._sb=[]),h&&r.__s==null&&(r.__s=r.state),h&&N.getDerivedStateFromProps!=null&&(r.__s==r.state&&(r.__s=M({},r.__s)),M(r.__s,N.getDerivedStateFromProps(p,r.__s))),d=r.props,C=r.state,r.__v=e,f)h&&N.getDerivedStateFromProps==null&&r.componentWillMount!=null&&r.componentWillMount(),h&&r.componentDidMount!=null&&r.__h.push(r.componentDidMount);else{if(h&&N.getDerivedStateFromProps==null&&p!==d&&r.componentWillReceiveProps!=null&&r.componentWillReceiveProps(p,W),e.__v==n.__v||!r.__e&&r.shouldComponentUpdate!=null&&r.shouldComponentUpdate(p,r.__s,W)===!1){for(e.__v!=n.__v&&(r.props=p,r.state=r.__s,r.__d=!1),e.__e=n.__e,e.__k=n.__k,e.__k.some(function(x){x&&(x.__=e)}),U=0;U<r._sb.length;U++)r.__h.push(r._sb[U]);r._sb=[],r.__h.length&&a.push(r);break e}r.componentWillUpdate!=null&&r.componentWillUpdate(p,r.__s,W),h&&r.componentDidUpdate!=null&&r.__h.push(function(){r.componentDidUpdate(d,C,S)})}if(r.context=W,r.props=p,r.__P=t,r.__e=!1,$=m.__r,ne=0,h){for(r.state=r.__s,r.__d=!1,$&&$(e),g=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),g=r.render(r.props,r.state,r.context),r.state=r.__s;while(r.__d&&++ne<25);r.state=r.__s,r.getChildContext!=null&&(o=M(M({},o),r.getChildContext())),h&&!f&&r.getSnapshotBeforeUpdate!=null&&(S=r.getSnapshotBeforeUpdate(d,C)),D=g,g!=null&&g.type===R&&g.key==null&&(D=xe(g.props.children)),_=Ae(t,V(D)?D:[D],e,n,o,s,i,a,_,c,l),r.base=e.__e,e.__u&=-161,r.__h.length&&a.push(r),v&&(r.__E=r.__=null)}catch(x){if(e.__v=null,c||i!=null)if(x.then){for(e.__u|=c?160:128;_&&_.nodeType==8&&_.nextSibling;)_=_.nextSibling;i[i.indexOf(_)]=null,e.__e=_}else{for(O=i.length;O--;)ae(i[O]);_e(e)}else e.__e=n.__e,e.__k=n.__k,x.then||_e(e);m.__e(x,e,n)}else i==null&&e.__v==n.__v?(e.__k=n.__k,e.__e=n.__e):_=e.__e=it(n.__e,e,n,o,s,i,a,c,l);return(g=m.diffed)&&g(e),128&e.__u?void 0:_}function _e(t){t&&t.__c&&(t.__c.__e=!0),t&&t.__k&&t.__k.forEach(_e)}function Ne(t,e,n){for(var o=0;o<n.length;o++)ce(n[o],n[++o],n[++o]);m.__c&&m.__c(e,t),t.some(function(s){try{t=s.__h,s.__h=[],t.some(function(i){i.call(s)})}catch(i){m.__e(i,s.__v)}})}function xe(t){return typeof t!="object"||t==null||t.__b&&t.__b>0?t:V(t)?t.map(xe):M({},t)}function it(t,e,n,o,s,i,a,_,c){var l,g,r,f,d,C,S,v=n.props||q,p=e.props,h=e.type;if(h=="svg"?s="http://www.w3.org/2000/svg":h=="math"?s="http://www.w3.org/1998/Math/MathML":s||(s="http://www.w3.org/1999/xhtml"),i!=null){for(l=0;l<i.length;l++)if((d=i[l])&&"setAttribute"in d==!!h&&(h?d.localName==h:d.nodeType==3)){t=d,i[l]=null;break}}if(t==null){if(h==null)return document.createTextNode(p);t=document.createElementNS(s,h,p.is&&p),_&&(m.__m&&m.__m(e,i),_=!1),i=null}if(h==null)v===p||_&&t.data==p||(t.data=p);else{if(i=i&&E.call(t.childNodes),!_&&i!=null)for(v={},l=0;l<t.attributes.length;l++)v[(d=t.attributes[l]).name]=d.value;for(l in v)if(d=v[l],l!="children"){if(l=="dangerouslySetInnerHTML")r=d;else if(!(l in p)){if(l=="value"&&"defaultValue"in p||l=="checked"&&"defaultChecked"in p)continue;G(t,l,null,d,s)}}for(l in p)d=p[l],l=="children"?f=d:l=="dangerouslySetInnerHTML"?g=d:l=="value"?C=d:l=="checked"?S=d:_&&typeof d!="function"||v[l]===d||G(t,l,d,v[l],s);if(g)_||r&&(g.__html==r.__html||g.__html==t.innerHTML)||(t.innerHTML=g.__html),e.__k=[];else if(r&&(t.innerHTML=""),Ae(e.type=="template"?t.content:t,V(f)?f:[f],e,n,o,h=="foreignObject"?"http://www.w3.org/1999/xhtml":s,i,a,i?i[0]:n.__k&&Q(n,0),_,c),i!=null)for(l=i.length;l--;)ae(i[l]);_||(l="value",h=="progress"&&C==null?t.removeAttribute("value"):C!=null&&(C!==t[l]||h=="progress"&&!C||h=="option"&&C!=v[l])&&G(t,l,C,v[l],s),l="checked",S!=null&&S!=t[l]&&G(t,l,S,v[l],s))}return t}function ce(t,e,n){try{if(typeof t=="function"){var o=typeof t.__u=="function";o&&t.__u(),o&&e==null||(t.__u=t(e))}else t.current=e}catch(s){m.__e(s,n)}}function Fe(t,e,n){var o,s;if(m.unmount&&m.unmount(t),(o=t.ref)&&(o.current&&o.current!=t.__e||ce(o,null,e)),(o=t.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(i){m.__e(i,e)}o.base=o.__P=null}if(o=t.__k)for(s=0;s<o.length;s++)o[s]&&Fe(o[s],e,n||typeof t.type!="function");n||ae(t.__e),t.__c=t.__=t.__e=void 0}function st(t,e,n){return this.constructor(t,n)}function X(t,e,n){var o,s,i,a;e==document&&(e=document.documentElement),m.__&&m.__(t,e),s=(o=typeof n=="function")?null:n&&n.__k||e.__k,i=[],a=[],le(e,t=(!o&&n||e).__k=L(R,null,[t]),s||q,q,e.namespaceURI,!o&&n?[n]:s?null:e.firstChild?E.call(e.childNodes):null,i,!o&&n?n:s?s.__e:e.firstChild,o,a),Ne(i,t,a)}function Me(t,e){X(t,e,Me)}function Pe(t,e,n){var o,s,i,a,_=M({},t.props);for(i in t.type&&t.type.defaultProps&&(a=t.type.defaultProps),e)i=="key"?o=e[i]:i=="ref"?s=e[i]:_[i]=e[i]===void 0&&a!=null?a[i]:e[i];return arguments.length>2&&(_.children=arguments.length>3?E.call(arguments,2):n),j(t.type,_,o||t.key,s||t.ref,null)}E=be.slice,m={__e:function(t,e,n,o){for(var s,i,a;e=e.__;)if((s=e.__c)&&!s.__)try{if((i=s.constructor)&&i.getDerivedStateFromError!=null&&(s.setState(i.getDerivedStateFromError(t)),a=s.__d),s.componentDidCatch!=null&&(s.componentDidCatch(t,o||{}),a=s.__d),a)return s.__E=s}catch(_){t=_}throw t}},pe=0,J.prototype.setState=function(t,e){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=M({},this.state),typeof t=="function"&&(t=t(M({},n),this.props)),t&&M(n,t),t!=null&&this.__v&&(e&&this._sb.push(e),ke(this))},J.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),ke(this))},J.prototype.render=R,I=[],ye=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,we=function(t,e){return t.__v.__b-e.__v.__b},K.__r=0,ve=/(PointerCapture)$|Capture$/i,ie=0,se=We(!1),re=We(!0);function Y(){return Y=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t},Y.apply(this,arguments)}function Ee(t,e){if(t==null)return{};var n,o,s={},i=Object.keys(t);for(o=0;o<i.length;o++)e.indexOf(n=i[o])>=0||(s[n]=t[n]);return s}var rt=["context","children"],at=["useFragment"];function lt(t,e,n,o){function s(){var i=Reflect.construct(HTMLElement,[],s);return i._vdomComponent=t,i._root=i,i}return(s.prototype=Object.create(HTMLElement.prototype)).constructor=s,s.prototype.connectedCallback=function(){ct.call(this,o)},s.prototype.attributeChangedCallback=ut,s.prototype.disconnectedCallback=gt,n=n||t.observedAttributes||Object.keys(t.propTypes||{}),s.observedAttributes=n,t.formAssociated&&(s.formAssociated=!0),n.forEach(function(i){Object.defineProperty(s.prototype,i,{get:function(){return this._vdom?this._vdom.props[i]:this._props[i]},set:function(a){this._vdom?this.attributeChangedCallback(i,null,a):(this._props||(this._props={}),this._props[i]=a);var _=typeof a;a!=null&&_!=="string"&&_!=="boolean"&&_!=="number"||this.setAttribute(i,a)}})}),customElements.define(e,s),s}function _t(t){this.getChildContext=function(){return t.context};var e=t.children,n=Ee(t,rt);return Pe(e,n)}function ct(t){var e=new CustomEvent("_preact",{detail:{},bubbles:!0,cancelable:!0});this.dispatchEvent(e),this._vdom=L(_t,Y({},this._props,{context:e.detail.context}),Ie(this,this._vdomComponent,t)),(this.hasAttribute("hydrate")?Me:X)(this._vdom,this._root)}function Te(t){return t.replace(/-(\w)/g,function(e,n){return n?n.toUpperCase():""})}function ut(t,e,n){if(this._vdom){var o={};o[t]=n=n??void 0,o[Te(t)]=n,this._vdom=Pe(this._vdom,o),X(this._vdom,this._root)}}function gt(){X(this._vdom=null,this._root)}function He(t,e){var n=this,o=t.useFragment,s=Ee(t,at);return L(o?R:"slot",Y({},s,{ref:function(i){i?(n.ref=i,n._listener||(n._listener=function(a){a.stopPropagation(),a.detail.context=e},i.addEventListener("_preact",n._listener))):n.ref.removeEventListener("_preact",n._listener)}}))}function Ie(t,e,n){if(t.nodeType===3)return t.data;if(t.nodeType!==1)return null;var o=[],s={},i=0,a=t.attributes,_=t.childNodes;for(i=a.length;i--;)a[i].name!=="slot"&&(s[a[i].name]=a[i].value,s[Te(a[i].name)]=a[i].value);for(i=_.length;i--;){var c=Ie(_[i],null,n),l=_[i].slot;l?s[l]=L(He,{name:l},c):o[i]=c}var g=!(!n||!n.shadow),r=e?L(He,{useFragment:!g},o):o;return!g&&e&&(t.innerHTML=""),L(e||t.nodeName.toLowerCase(),s,r)}var dt=0;function u(t,e,n,o,s,i){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:--dt,__i:-1,__u:0,__source:s,__self:i};if(typeof t=="function"&&(a=t.defaultProps))for(_ in a)c[_]===void 0&&(c[_]=a[_]);return m.vnode&&m.vnode(l),l}var B,w,ue,Re,Z=0,Ue=[],b=m,De=b.__b,Oe=b.__r,Le=b.diffed,Qe=b.__c,qe=b.unmount,je=b.__;function ge(t,e){b.__h&&b.__h(w,t,Z||e),Z=0;var n=w.__H||(w.__H={__:[],__h:[]});return t>=n.__.length&&n.__.push({}),n.__[t]}function T(t){return Z=1,ht(Ke,t)}function ht(t,e,n){var o=ge(B++,2);if(o.t=t,!o.__c&&(o.__=[Ke(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=w,!w.__f)){var s=function(_,c,l){if(!o.__c.__H)return!0;var g=o.__c.__H.__.filter(function(f){return!!f.__c});if(g.every(function(f){return!f.__N}))return!i||i.call(this,_,c,l);var r=o.__c.props!==_;return g.forEach(function(f){if(f.__N){var d=f.__[0];f.__=f.__N,f.__N=void 0,d!==f.__[0]&&(r=!0)}}),i&&i.call(this,_,c,l)||r};w.__f=!0;var i=w.shouldComponentUpdate,a=w.componentWillUpdate;w.componentWillUpdate=function(_,c,l){if(this.__e){var g=i;i=void 0,s(_,c,l),i=g}a&&a.call(this,_,c,l)},w.shouldComponentUpdate=s}return o.__N||o.__}function Be(t,e){var n=ge(B++,3);!b.__s&&Je(n.__H,e)&&(n.__=t,n.u=e,w.__H.__h.push(n))}function ze(t){return Z=5,ft(function(){return{current:t}},[])}function ft(t,e){var n=ge(B++,7);return Je(n.__H,e)&&(n.__=t(),n.__H=e,n.__h=t),n.__}function pt(){for(var t;t=Ue.shift();)if(t.__P&&t.__H)try{t.__H.__h.forEach(ee),t.__H.__h.forEach(de),t.__H.__h=[]}catch(e){t.__H.__h=[],b.__e(e,t.__v)}}b.__b=function(t){w=null,De&&De(t)},b.__=function(t,e){t&&e.__k&&e.__k.__m&&(t.__m=e.__k.__m),je&&je(t,e)},b.__r=function(t){Oe&&Oe(t),B=0;var e=(w=t.__c).__H;e&&(ue===w?(e.__h=[],w.__h=[],e.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(e.__h.forEach(ee),e.__h.forEach(de),e.__h=[],B=0)),ue=w},b.diffed=function(t){Le&&Le(t);var e=t.__c;e&&e.__H&&(e.__H.__h.length&&(Ue.push(e)!==1&&Re===b.requestAnimationFrame||((Re=b.requestAnimationFrame)||mt)(pt)),e.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),ue=w=null},b.__c=function(t,e){e.some(function(n){try{n.__h.forEach(ee),n.__h=n.__h.filter(function(o){return!o.__||de(o)})}catch(o){e.some(function(s){s.__h&&(s.__h=[])}),e=[],b.__e(o,n.__v)}}),Qe&&Qe(t,e)},b.unmount=function(t){qe&&qe(t);var e,n=t.__c;n&&n.__H&&(n.__H.__.forEach(function(o){try{ee(o)}catch(s){e=s}}),n.__H=void 0,e&&b.__e(e,n.__v))};var Ve=typeof requestAnimationFrame=="function";function mt(t){var e,n=function(){clearTimeout(o),Ve&&cancelAnimationFrame(e),setTimeout(t)},o=setTimeout(n,35);Ve&&(e=requestAnimationFrame(n))}function ee(t){var e=w,n=t.__c;typeof n=="function"&&(t.__c=void 0,n()),w=e}function de(t){var e=w;t.__c=t.__(),w=e}function Je(t,e){return!t||t.length!==e.length||e.some(function(n,o){return n!==t[o]})}function Ke(t,e){return typeof e=="function"?e(t):e}const yt="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let te=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t|=0));for(;t--;)e+=yt[n[t]&63];return e};class Ge{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,s)=>{try{this.ws=new WebSocket(n),this.ws.onopen=()=>{console.log("[Widget] Connected to agent"),this.reconnectAttempts=0,this.notifyConnectionChange(!0),o()},this.ws.onmessage=i=>{this.handleMessage(i)},this.ws.onclose=()=>{if(console.log("[Widget] Disconnected from agent"),this.notifyConnectionChange(!1),this.reconnectAttempts<this.maxReconnectAttempts){this.reconnectAttempts++;const i=this.reconnectDelay*Math.pow(2,this.reconnectAttempts-1);console.log(`[Widget] Reconnecting in ${i}ms... (attempt ${this.reconnectAttempts})`),setTimeout(()=>this.connectToAgent(),i)}},this.ws.onerror=i=>{console.error("[Widget] WebSocket error:",i),s(i)}}catch(i){s(i)}})}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 s=o[o.length-1];return s&&s.role==="assistant"&&s.isStreaming?[...o.slice(0,-1),{...s,content:s.content+n.text}]:[...o,{id:te(),role:"assistant",content:n.text,timestamp:Date.now(),isStreaming:!0}]});else if(n.type==="done")console.log("[Widget] Response complete"),this.notifyProcessingChange(!1),this.setMessages(o=>{const s=o[o.length-1];return s&&s.role==="assistant"&&s.isStreaming?[...o.slice(0,-1),{...s,isStreaming:!1}]:o}),this.isAgentStreaming=!1,this.notifyStreamingChange(!1),this.processMessageQueue();else if(n.type==="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:te(),role:"tool",content:`Calling tool: ${n.tool.name}`,timestamp:Date.now(),toolCall:{name:n.tool.name,arguments:n.tool.arguments}};this.setMessages(s=>[...s,o]),n.tool.name==="suggest_options"&&n.tool.arguments?.options&&this.setMessages(s=>{const i=[...s].reverse().find(a=>a.role==="assistant");return i?s.map(a=>a.id===i.id?{...a,suggestions:n.tool.arguments.options}:a):s})}else n.type==="tool-result"?(console.log("[Widget] Tool result:",n.result),this.setMessages(o=>{const s=o[o.length-1];return s&&s.role==="tool"&&!s.toolResult?[...o.slice(0,-1),{...s,content:s.content+`
|
|
2
|
-
Result: ${JSON.stringify(n.result)}`,toolResult:n.result}]:
|
|
1
|
+
(function(H,E){typeof exports=="object"&&typeof module<"u"?E(exports):typeof define=="function"&&define.amd?define(["exports"],E):(H=typeof globalThis<"u"?globalThis:H||self,E(H.AriaFlowWidget={}))})(this,function(H){"use strict";var E,m,pe,I,me,ye,we,ve,ie,se,re,q={},be=[],tt=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,V=Array.isArray;function M(t,e){for(var n in e)t[n]=e[n];return t}function ae(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function L(t,e,n){var i,s,o,a={};for(o in e)o=="key"?i=e[o]:o=="ref"?s=e[o]:a[o]=e[o];if(arguments.length>2&&(a.children=arguments.length>3?E.call(arguments,2):n),typeof t=="function"&&t.defaultProps!=null)for(o in t.defaultProps)a[o]===void 0&&(a[o]=t.defaultProps[o]);return j(t,a,i,s,null)}function j(t,e,n,i,s){var o={type:t,props:e,key:n,ref:i,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:s??++pe,__i:-1,__u:0};return s==null&&m.vnode!=null&&m.vnode(o),o}function R(t){return t.children}function J(t,e){this.props=t,this.context=e}function Q(t,e){if(e==null)return t.__?Q(t.__,t.__i+1):null;for(var n;e<t.__k.length;e++)if((n=t.__k[e])!=null&&n.__e!=null)return n.__e;return typeof t.type=="function"?Q(t):null}function Ce(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 Ce(t)}}function ke(t){(!t.__d&&(t.__d=!0)&&I.push(t)&&!K.__r++||me!=m.debounceRendering)&&((me=m.debounceRendering)||ye)(K)}function K(){for(var t,e,n,i,s,o,a,l=1;I.length;)I.length>l&&I.sort(we),t=I.shift(),l=I.length,t.__d&&(n=void 0,i=void 0,s=(i=(e=t).__v).__e,o=[],a=[],e.__P&&((n=M({},i)).__v=i.__v+1,m.vnode&&m.vnode(n),le(e.__P,n,i,e.__n,e.__P.namespaceURI,32&i.__u?[s]:null,o,s??Q(i),!!(32&i.__u),a),n.__v=i.__v,n.__.__k[n.__i]=n,Ne(o,n,a),i.__e=i.__=null,n.__e!=s&&Ce(n)));K.__r=0}function Ae(t,e,n,i,s,o,a,l,c,_,g){var r,f,d,C,S,v,p,h=i&&i.__k||be,P=e.length;for(c=nt(n,e,h,c,P),r=0;r<P;r++)(d=n.__k[r])!=null&&(f=d.__i==-1?q:h[d.__i]||q,d.__i=r,v=le(t,d,f,s,o,a,l,c,_,g),C=d.__e,d.ref&&f.ref!=d.ref&&(f.ref&&ce(f.ref,null,d),g.push(d.ref,d.__c||C,d)),S==null&&C!=null&&(S=C),(p=!!(4&d.__u))||f.__k===d.__k?c=Se(d,c,t,p):typeof d.type=="function"&&v!==void 0?c=v:C&&(c=C.nextSibling),d.__u&=-7);return n.__e=S,c}function nt(t,e,n,i,s){var o,a,l,c,_,g=n.length,r=g,f=0;for(t.__k=new Array(s),o=0;o<s;o++)(a=e[o])!=null&&typeof a!="boolean"&&typeof a!="function"?(typeof a=="string"||typeof a=="number"||typeof a=="bigint"||a.constructor==String?a=t.__k[o]=j(null,a,null,null,null):V(a)?a=t.__k[o]=j(R,{children:a},null,null,null):a.constructor===void 0&&a.__b>0?a=t.__k[o]=j(a.type,a.props,a.key,a.ref?a.ref:null,a.__v):t.__k[o]=a,c=o+f,a.__=t,a.__b=t.__b+1,l=null,(_=a.__i=ot(a,n,c,r))!=-1&&(r--,(l=n[_])&&(l.__u|=2)),l==null||l.__v==null?(_==-1&&(s>g?f--:s<g&&f++),typeof a.type!="function"&&(a.__u|=4)):_!=c&&(_==c-1?f--:_==c+1?f++:(_>c?f--:f++,a.__u|=4))):t.__k[o]=null;if(r)for(o=0;o<g;o++)(l=n[o])!=null&&!(2&l.__u)&&(l.__e==i&&(i=Q(l)),Fe(l,l));return i}function Se(t,e,n,i){var s,o;if(typeof t.type=="function"){for(s=t.__k,o=0;s&&o<s.length;o++)s[o]&&(s[o].__=t,e=Se(s[o],e,n,i));return e}t.__e!=e&&(i&&(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 ot(t,e,n,i){var s,o,a,l=t.key,c=t.type,_=e[n],g=_!=null&&(2&_.__u)==0;if(_===null&&l==null||g&&l==_.key&&c==_.type)return n;if(i>(g?1:0)){for(s=n-1,o=n+1;s>=0||o<e.length;)if((_=e[a=s>=0?s--:o++])!=null&&!(2&_.__u)&&l==_.key&&c==_.type)return a}return-1}function $e(t,e,n){e[0]=="-"?t.setProperty(e,n??""):t[e]=n==null?"":typeof n!="number"||tt.test(e)?n:n+"px"}function G(t,e,n,i,s){var o,a;e:if(e=="style")if(typeof n=="string")t.style.cssText=n;else{if(typeof i=="string"&&(t.style.cssText=i=""),i)for(e in i)n&&e in n||$e(t.style,e,"");if(n)for(e in n)i&&n[e]==i[e]||$e(t.style,e,n[e])}else if(e[0]=="o"&&e[1]=="n")o=e!=(e=e.replace(ve,"$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+o]=n,n?i?n.u=i.u:(n.u=ie,t.addEventListener(e,o?re:se,o)):t.removeEventListener(e,o?re:se,o);else{if(s=="http://www.w3.org/2000/svg")e=e.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(e!="width"&&e!="height"&&e!="href"&&e!="list"&&e!="form"&&e!="tabIndex"&&e!="download"&&e!="rowSpan"&&e!="colSpan"&&e!="role"&&e!="popover"&&e in t)try{t[e]=n??"";break e}catch{}typeof n=="function"||(n==null||n===!1&&e[4]!="-"?t.removeAttribute(e):t.setAttribute(e,e=="popover"&&n==1?"":n))}}function We(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 le(t,e,n,i,s,o,a,l,c,_){var g,r,f,d,C,S,v,p,h,P,W,U,$,ne,A,D,O,N=e.type;if(e.constructor!==void 0)return null;128&n.__u&&(c=!!(32&n.__u),o=[l=e.__e=n.__e]),(g=m.__b)&&g(e);e:if(typeof N=="function")try{if(p=e.props,h="prototype"in N&&N.prototype.render,P=(g=N.contextType)&&i[g.__c],W=g?P?P.props.value:g.__:i,n.__c?v=(r=e.__c=n.__c).__=r.__E:(h?e.__c=r=new N(p,W):(e.__c=r=new J(p,W),r.constructor=N,r.render=st),P&&P.sub(r),r.state||(r.state={}),r.__n=i,f=r.__d=!0,r.__h=[],r._sb=[]),h&&r.__s==null&&(r.__s=r.state),h&&N.getDerivedStateFromProps!=null&&(r.__s==r.state&&(r.__s=M({},r.__s)),M(r.__s,N.getDerivedStateFromProps(p,r.__s))),d=r.props,C=r.state,r.__v=e,f)h&&N.getDerivedStateFromProps==null&&r.componentWillMount!=null&&r.componentWillMount(),h&&r.componentDidMount!=null&&r.__h.push(r.componentDidMount);else{if(h&&N.getDerivedStateFromProps==null&&p!==d&&r.componentWillReceiveProps!=null&&r.componentWillReceiveProps(p,W),e.__v==n.__v||!r.__e&&r.shouldComponentUpdate!=null&&r.shouldComponentUpdate(p,r.__s,W)===!1){for(e.__v!=n.__v&&(r.props=p,r.state=r.__s,r.__d=!1),e.__e=n.__e,e.__k=n.__k,e.__k.some(function(x){x&&(x.__=e)}),U=0;U<r._sb.length;U++)r.__h.push(r._sb[U]);r._sb=[],r.__h.length&&a.push(r);break e}r.componentWillUpdate!=null&&r.componentWillUpdate(p,r.__s,W),h&&r.componentDidUpdate!=null&&r.__h.push(function(){r.componentDidUpdate(d,C,S)})}if(r.context=W,r.props=p,r.__P=t,r.__e=!1,$=m.__r,ne=0,h){for(r.state=r.__s,r.__d=!1,$&&$(e),g=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),g=r.render(r.props,r.state,r.context),r.state=r.__s;while(r.__d&&++ne<25);r.state=r.__s,r.getChildContext!=null&&(i=M(M({},i),r.getChildContext())),h&&!f&&r.getSnapshotBeforeUpdate!=null&&(S=r.getSnapshotBeforeUpdate(d,C)),D=g,g!=null&&g.type===R&&g.key==null&&(D=xe(g.props.children)),l=Ae(t,V(D)?D:[D],e,n,i,s,o,a,l,c,_),r.base=e.__e,e.__u&=-161,r.__h.length&&a.push(r),v&&(r.__E=r.__=null)}catch(x){if(e.__v=null,c||o!=null)if(x.then){for(e.__u|=c?160:128;l&&l.nodeType==8&&l.nextSibling;)l=l.nextSibling;o[o.indexOf(l)]=null,e.__e=l}else{for(O=o.length;O--;)ae(o[O]);_e(e)}else e.__e=n.__e,e.__k=n.__k,x.then||_e(e);m.__e(x,e,n)}else o==null&&e.__v==n.__v?(e.__k=n.__k,e.__e=n.__e):l=e.__e=it(n.__e,e,n,i,s,o,a,c,_);return(g=m.diffed)&&g(e),128&e.__u?void 0:l}function _e(t){t&&t.__c&&(t.__c.__e=!0),t&&t.__k&&t.__k.forEach(_e)}function Ne(t,e,n){for(var i=0;i<n.length;i++)ce(n[i],n[++i],n[++i]);m.__c&&m.__c(e,t),t.some(function(s){try{t=s.__h,s.__h=[],t.some(function(o){o.call(s)})}catch(o){m.__e(o,s.__v)}})}function xe(t){return typeof t!="object"||t==null||t.__b&&t.__b>0?t:V(t)?t.map(xe):M({},t)}function it(t,e,n,i,s,o,a,l,c){var _,g,r,f,d,C,S,v=n.props||q,p=e.props,h=e.type;if(h=="svg"?s="http://www.w3.org/2000/svg":h=="math"?s="http://www.w3.org/1998/Math/MathML":s||(s="http://www.w3.org/1999/xhtml"),o!=null){for(_=0;_<o.length;_++)if((d=o[_])&&"setAttribute"in d==!!h&&(h?d.localName==h:d.nodeType==3)){t=d,o[_]=null;break}}if(t==null){if(h==null)return document.createTextNode(p);t=document.createElementNS(s,h,p.is&&p),l&&(m.__m&&m.__m(e,o),l=!1),o=null}if(h==null)v===p||l&&t.data==p||(t.data=p);else{if(o=o&&E.call(t.childNodes),!l&&o!=null)for(v={},_=0;_<t.attributes.length;_++)v[(d=t.attributes[_]).name]=d.value;for(_ in v)if(d=v[_],_!="children"){if(_=="dangerouslySetInnerHTML")r=d;else if(!(_ in p)){if(_=="value"&&"defaultValue"in p||_=="checked"&&"defaultChecked"in p)continue;G(t,_,null,d,s)}}for(_ in p)d=p[_],_=="children"?f=d:_=="dangerouslySetInnerHTML"?g=d:_=="value"?C=d:_=="checked"?S=d:l&&typeof d!="function"||v[_]===d||G(t,_,d,v[_],s);if(g)l||r&&(g.__html==r.__html||g.__html==t.innerHTML)||(t.innerHTML=g.__html),e.__k=[];else if(r&&(t.innerHTML=""),Ae(e.type=="template"?t.content:t,V(f)?f:[f],e,n,i,h=="foreignObject"?"http://www.w3.org/1999/xhtml":s,o,a,o?o[0]:n.__k&&Q(n,0),l,c),o!=null)for(_=o.length;_--;)ae(o[_]);l||(_="value",h=="progress"&&C==null?t.removeAttribute("value"):C!=null&&(C!==t[_]||h=="progress"&&!C||h=="option"&&C!=v[_])&&G(t,_,C,v[_],s),_="checked",S!=null&&S!=t[_]&&G(t,_,S,v[_],s))}return t}function ce(t,e,n){try{if(typeof t=="function"){var i=typeof t.__u=="function";i&&t.__u(),i&&e==null||(t.__u=t(e))}else t.current=e}catch(s){m.__e(s,n)}}function Fe(t,e,n){var i,s;if(m.unmount&&m.unmount(t),(i=t.ref)&&(i.current&&i.current!=t.__e||ce(i,null,e)),(i=t.__c)!=null){if(i.componentWillUnmount)try{i.componentWillUnmount()}catch(o){m.__e(o,e)}i.base=i.__P=null}if(i=t.__k)for(s=0;s<i.length;s++)i[s]&&Fe(i[s],e,n||typeof t.type!="function");n||ae(t.__e),t.__c=t.__=t.__e=void 0}function st(t,e,n){return this.constructor(t,n)}function X(t,e,n){var i,s,o,a;e==document&&(e=document.documentElement),m.__&&m.__(t,e),s=(i=typeof n=="function")?null:n&&n.__k||e.__k,o=[],a=[],le(e,t=(!i&&n||e).__k=L(R,null,[t]),s||q,q,e.namespaceURI,!i&&n?[n]:s?null:e.firstChild?E.call(e.childNodes):null,o,!i&&n?n:s?s.__e:e.firstChild,i,a),Ne(o,t,a)}function Me(t,e){X(t,e,Me)}function Pe(t,e,n){var i,s,o,a,l=M({},t.props);for(o in t.type&&t.type.defaultProps&&(a=t.type.defaultProps),e)o=="key"?i=e[o]:o=="ref"?s=e[o]:l[o]=e[o]===void 0&&a!=null?a[o]:e[o];return arguments.length>2&&(l.children=arguments.length>3?E.call(arguments,2):n),j(t.type,l,i||t.key,s||t.ref,null)}E=be.slice,m={__e:function(t,e,n,i){for(var s,o,a;e=e.__;)if((s=e.__c)&&!s.__)try{if((o=s.constructor)&&o.getDerivedStateFromError!=null&&(s.setState(o.getDerivedStateFromError(t)),a=s.__d),s.componentDidCatch!=null&&(s.componentDidCatch(t,i||{}),a=s.__d),a)return s.__E=s}catch(l){t=l}throw t}},pe=0,J.prototype.setState=function(t,e){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=M({},this.state),typeof t=="function"&&(t=t(M({},n),this.props)),t&&M(n,t),t!=null&&this.__v&&(e&&this._sb.push(e),ke(this))},J.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),ke(this))},J.prototype.render=R,I=[],ye=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,we=function(t,e){return t.__v.__b-e.__v.__b},K.__r=0,ve=/(PointerCapture)$|Capture$/i,ie=0,se=We(!1),re=We(!0);function Y(){return Y=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},Y.apply(this,arguments)}function Ee(t,e){if(t==null)return{};var n,i,s={},o=Object.keys(t);for(i=0;i<o.length;i++)e.indexOf(n=o[i])>=0||(s[n]=t[n]);return s}var rt=["context","children"],at=["useFragment"];function lt(t,e,n,i){function s(){var o=Reflect.construct(HTMLElement,[],s);return o._vdomComponent=t,o._root=o,o}return(s.prototype=Object.create(HTMLElement.prototype)).constructor=s,s.prototype.connectedCallback=function(){ct.call(this,i)},s.prototype.attributeChangedCallback=ut,s.prototype.disconnectedCallback=gt,n=n||t.observedAttributes||Object.keys(t.propTypes||{}),s.observedAttributes=n,t.formAssociated&&(s.formAssociated=!0),n.forEach(function(o){Object.defineProperty(s.prototype,o,{get:function(){return this._vdom?this._vdom.props[o]:this._props[o]},set:function(a){this._vdom?this.attributeChangedCallback(o,null,a):(this._props||(this._props={}),this._props[o]=a);var l=typeof a;a!=null&&l!=="string"&&l!=="boolean"&&l!=="number"||this.setAttribute(o,a)}})}),customElements.define(e,s),s}function _t(t){this.getChildContext=function(){return t.context};var e=t.children,n=Ee(t,rt);return Pe(e,n)}function ct(t){var e=new CustomEvent("_preact",{detail:{},bubbles:!0,cancelable:!0});this.dispatchEvent(e),this._vdom=L(_t,Y({},this._props,{context:e.detail.context}),Ie(this,this._vdomComponent,t)),(this.hasAttribute("hydrate")?Me:X)(this._vdom,this._root)}function Te(t){return t.replace(/-(\w)/g,function(e,n){return n?n.toUpperCase():""})}function ut(t,e,n){if(this._vdom){var i={};i[t]=n=n??void 0,i[Te(t)]=n,this._vdom=Pe(this._vdom,i),X(this._vdom,this._root)}}function gt(){X(this._vdom=null,this._root)}function He(t,e){var n=this,i=t.useFragment,s=Ee(t,at);return L(i?R:"slot",Y({},s,{ref:function(o){o?(n.ref=o,n._listener||(n._listener=function(a){a.stopPropagation(),a.detail.context=e},o.addEventListener("_preact",n._listener))):n.ref.removeEventListener("_preact",n._listener)}}))}function Ie(t,e,n){if(t.nodeType===3)return t.data;if(t.nodeType!==1)return null;var i=[],s={},o=0,a=t.attributes,l=t.childNodes;for(o=a.length;o--;)a[o].name!=="slot"&&(s[a[o].name]=a[o].value,s[Te(a[o].name)]=a[o].value);for(o=l.length;o--;){var c=Ie(l[o],null,n),_=l[o].slot;_?s[_]=L(He,{name:_},c):i[o]=c}var g=!(!n||!n.shadow),r=e?L(He,{useFragment:!g},i):i;return!g&&e&&(t.innerHTML=""),L(e||t.nodeName.toLowerCase(),s,r)}var dt=0;function u(t,e,n,i,s,o){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:--dt,__i:-1,__u:0,__source:s,__self:o};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 B,w,ue,Re,Z=0,Ue=[],b=m,De=b.__b,Oe=b.__r,Le=b.diffed,Qe=b.__c,qe=b.unmount,je=b.__;function ge(t,e){b.__h&&b.__h(w,t,Z||e),Z=0;var n=w.__H||(w.__H={__:[],__h:[]});return t>=n.__.length&&n.__.push({}),n.__[t]}function T(t){return Z=1,ht(Ke,t)}function ht(t,e,n){var i=ge(B++,2);if(i.t=t,!i.__c&&(i.__=[Ke(void 0,e),function(l){var c=i.__N?i.__N[0]:i.__[0],_=i.t(c,l);c!==_&&(i.__N=[_,i.__[1]],i.__c.setState({}))}],i.__c=w,!w.__f)){var s=function(l,c,_){if(!i.__c.__H)return!0;var g=i.__c.__H.__.filter(function(f){return!!f.__c});if(g.every(function(f){return!f.__N}))return!o||o.call(this,l,c,_);var r=i.__c.props!==l;return g.forEach(function(f){if(f.__N){var d=f.__[0];f.__=f.__N,f.__N=void 0,d!==f.__[0]&&(r=!0)}}),o&&o.call(this,l,c,_)||r};w.__f=!0;var o=w.shouldComponentUpdate,a=w.componentWillUpdate;w.componentWillUpdate=function(l,c,_){if(this.__e){var g=o;o=void 0,s(l,c,_),o=g}a&&a.call(this,l,c,_)},w.shouldComponentUpdate=s}return i.__N||i.__}function Be(t,e){var n=ge(B++,3);!b.__s&&Je(n.__H,e)&&(n.__=t,n.u=e,w.__H.__h.push(n))}function ze(t){return Z=5,ft(function(){return{current:t}},[])}function ft(t,e){var n=ge(B++,7);return Je(n.__H,e)&&(n.__=t(),n.__H=e,n.__h=t),n.__}function pt(){for(var t;t=Ue.shift();)if(t.__P&&t.__H)try{t.__H.__h.forEach(ee),t.__H.__h.forEach(de),t.__H.__h=[]}catch(e){t.__H.__h=[],b.__e(e,t.__v)}}b.__b=function(t){w=null,De&&De(t)},b.__=function(t,e){t&&e.__k&&e.__k.__m&&(t.__m=e.__k.__m),je&&je(t,e)},b.__r=function(t){Oe&&Oe(t),B=0;var e=(w=t.__c).__H;e&&(ue===w?(e.__h=[],w.__h=[],e.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(e.__h.forEach(ee),e.__h.forEach(de),e.__h=[],B=0)),ue=w},b.diffed=function(t){Le&&Le(t);var e=t.__c;e&&e.__H&&(e.__H.__h.length&&(Ue.push(e)!==1&&Re===b.requestAnimationFrame||((Re=b.requestAnimationFrame)||mt)(pt)),e.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),ue=w=null},b.__c=function(t,e){e.some(function(n){try{n.__h.forEach(ee),n.__h=n.__h.filter(function(i){return!i.__||de(i)})}catch(i){e.some(function(s){s.__h&&(s.__h=[])}),e=[],b.__e(i,n.__v)}}),Qe&&Qe(t,e)},b.unmount=function(t){qe&&qe(t);var e,n=t.__c;n&&n.__H&&(n.__H.__.forEach(function(i){try{ee(i)}catch(s){e=s}}),n.__H=void 0,e&&b.__e(e,n.__v))};var Ve=typeof requestAnimationFrame=="function";function mt(t){var e,n=function(){clearTimeout(i),Ve&&cancelAnimationFrame(e),setTimeout(t)},i=setTimeout(n,35);Ve&&(e=requestAnimationFrame(n))}function ee(t){var e=w,n=t.__c;typeof n=="function"&&(t.__c=void 0,n()),w=e}function de(t){var e=w;t.__c=t.__(),w=e}function Je(t,e){return!t||t.length!==e.length||e.some(function(n,i){return n!==t[i]})}function Ke(t,e){return typeof e=="function"?e(t):e}const yt="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let te=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t|=0));for(;t--;)e+=yt[n[t]&63];return e};class Ge{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 i=await n.json();return console.log("[AriaFlow Widget] Agent config received:",i),!i||i.status!=="active"?(console.error("Agent not found or inactive"),null):(this.agentConfig=i,this.maxReconnectAttempts=i.config.maxRetries||5,this.reconnectDelay=i.config.reconnectDelay||1e3,await this.connectToAgent(),i)}}catch{console.warn("[AriaFlow Widget] Agent config endpoint not available, trying fallback")}console.log("[AriaFlow Widget] Using fallback config for Railway deployment");const e={id:this.agentId,name:this.agentId==="hospital"?"Hospital Support":"Support Agent",wsUrl:`${this.agentUrl.replace(/^https/,"wss")}/ws`,status:"active",capabilities:["chat","streaming"],config:{primaryColor:"#14B8A6",position:"bottom-right",theme:"light",title:this.agentId==="hospital"?"Hospital Support":"Chat Support",subtitle:"We're here to help!",maxRetries:3,reconnectDelay:1e3}};return this.agentConfig=e,await this.connectToAgent(),e}catch(e){return console.error("Failed to initialize widget:",e),null}}async connectToAgent(){if(!this.agentConfig?.wsUrl)throw new Error("No agent WebSocket URL configured");const e=this.getSessionId(),n=`${this.agentConfig.wsUrl}/${e}`;return console.log("[AriaFlow Widget] Connecting to WebSocket:",n),new Promise((i,s)=>{try{this.ws=new WebSocket(n),this.ws.onopen=()=>{console.log("[Widget] Connected to agent"),this.reconnectAttempts=0,this.notifyConnectionChange(!0),i()},this.ws.onmessage=o=>{this.handleMessage(o)},this.ws.onclose=()=>{if(console.log("[Widget] Disconnected from agent"),this.notifyConnectionChange(!1),this.reconnectAttempts<this.maxReconnectAttempts){this.reconnectAttempts++;const o=this.reconnectDelay*Math.pow(2,this.reconnectAttempts-1);console.log(`[Widget] Reconnecting in ${o}ms... (attempt ${this.reconnectAttempts})`),setTimeout(()=>this.connectToAgent(),o)}},this.ws.onerror=o=>{console.error("[Widget] WebSocket error:",o),s(o)}}catch(o){s(o)}})}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(i=>{const s=i[i.length-1];return s&&s.role==="assistant"&&s.isStreaming?[...i.slice(0,-1),{...s,content:s.content+n.text}]:[...i,{id:te(),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(i=>{const s=i[i.length-1];return s&&s.role==="assistant"&&s.isStreaming?[...i.slice(0,-1),{...s,isStreaming:!1}]:i}),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 i=n.toolName||n.tool?.name,s=n.args||n.tool?.arguments;if(console.log("[Widget] Tool call:",i),this.notifyProcessingChange(!0),i==="suggest_options"&&(s?.options||s)){const o=s?.options||s;Array.isArray(o)&&this.setMessages(a=>{const l=[...a].reverse().find(c=>c.role==="assistant");return l?a.map(c=>c.id===l.id?{...c,suggestions:o}:c):a})}else{const o={id:te(),role:"tool",content:`Calling tool: ${i}`,timestamp:Date.now(),toolCall:{name:i,arguments:s}};this.setMessages(a=>[...a,o])}}else if(n.type==="tool-result"){const i=n.toolName||n.tool?.name;console.log("[Widget] Tool result:",i),i==="suggest_options"||this.setMessages(s=>{const o=s[s.length-1];return o&&o.role==="tool"&&!o.toolResult?[...s.slice(0,-1),{...o,content:o.content+`
|
|
2
|
+
Result: ${JSON.stringify(n.result)}`,toolResult:n.result}]:s})}else 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(i=>{const s=[...i].reverse().find(o=>o.role==="assistant");return s?i.map(o=>o.id===s.id?{...o,suggestions:n.suggestions}:o):i})):console.log("[Widget] Unknown message type:",n.type)}catch(n){console.error("[Widget] Error parsing message:",e.data,n)}}async sendMessage(e){if(!this.ws||this.ws.readyState!==WebSocket.OPEN)throw new Error("Not connected to agent");const n={id:te(),role:"user",content:e,timestamp:Date.now()};if(this.setMessages(i=>[...i,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=te(),sessionStorage.setItem("ariaflow_session_id",e)),e}setMessages(e){this.messages=e(this.messages),this.messageCallbacks.forEach(n=>n(this.messages))}onMessages(e){return this.messageCallbacks.add(e),e(this.messages),()=>{this.messageCallbacks.delete(e)}}onConnectionChange(e){return this.connectionCallbacks.add(e),()=>{this.connectionCallbacks.delete(e)}}onStreamingChange(e){return this.streamingCallbacks.add(e),()=>{this.streamingCallbacks.delete(e)}}onQueueChange(e){return this.queueCallbacks.add(e),()=>{this.queueCallbacks.delete(e)}}notifyConnectionChange(e){this.connectionCallbacks.forEach(n=>n(e))}notifyStreamingChange(e){this.streamingCallbacks.forEach(n=>n(e))}notifyQueueChange(e){this.queueCallbacks.forEach(n=>n(e))}getMessages(){return this.messages}getConfig(){return this.agentConfig}isConnected(){return this.ws?.readyState===WebSocket.OPEN}dispose(){this.ws&&(this.ws.close(),this.ws=null),this.messageCallbacks.clear(),this.connectionCallbacks.clear()}}const he={none:"0",small:"0.375rem",medium:"0.75rem",large:"1rem"};function Xe({agentUrl:t,agentId:e,widgetId:n,apiUrl:
|
|
4
|
+
`);this.messageQueue.length=0,console.log("[Widget] Sending combined queued messages:",e),this.sendToAgent(e)}this.notifyQueueChange(this.messageQueue.length)}}getSessionId(){let e=sessionStorage.getItem("ariaflow_session_id");return e||(e=te(),sessionStorage.setItem("ariaflow_session_id",e)),e}setMessages(e){this.messages=e(this.messages),this.messageCallbacks.forEach(n=>n(this.messages))}onMessages(e){return this.messageCallbacks.add(e),e(this.messages),()=>{this.messageCallbacks.delete(e)}}onConnectionChange(e){return this.connectionCallbacks.add(e),()=>{this.connectionCallbacks.delete(e)}}onStreamingChange(e){return this.streamingCallbacks.add(e),()=>{this.streamingCallbacks.delete(e)}}onQueueChange(e){return this.queueCallbacks.add(e),()=>{this.queueCallbacks.delete(e)}}notifyConnectionChange(e){this.connectionCallbacks.forEach(n=>n(e))}notifyStreamingChange(e){this.streamingCallbacks.forEach(n=>n(e))}notifyQueueChange(e){this.queueCallbacks.forEach(n=>n(e))}getMessages(){return this.messages}getConfig(){return this.agentConfig}isConnected(){return this.ws?.readyState===WebSocket.OPEN}dispose(){this.ws&&(this.ws.close(),this.ws=null),this.messageCallbacks.clear(),this.connectionCallbacks.clear()}}const he={none:"0",small:"0.375rem",medium:"0.75rem",large:"1rem"};function Xe({agentUrl:t,agentId:e,widgetId:n,apiUrl:i,mode:s="chat",theme:o="light",position:a="bottom-right",size:l="full",radius:c="medium",baseColor:_,accentColor:g="#14B8A6",buttonBaseColor:r="#000000",buttonAccentColor:f="#FFFFFF",title:d,subtitle:C,emptyChatMessage:S}){const[v,p]=T(!1),[h,P]=T([]),[W,U]=T(""),[$,ne]=T(!1),[A,D]=T(!1),[O,N]=T(null),[x,wt]=T(!1),[vt,bt]=T(!1),[fe,Ct]=T(0),oe=ze(null),Ze=ze(null);Be(()=>((async()=>{if(t&&e){console.log("[AriaFlow Widget] Using new agent resolution:",{agentUrl:t,agentId:e});const F=new Ge(t,e);oe.current=F;try{F.onMessages(k=>{console.log("[AriaFlow Widget] Messages updated:",k.length),P(k)}),F.onConnectionChange(k=>{console.log("[AriaFlow Widget] Connection state:",k),ne(k),k&&D(!0)}),F.onStreamingChange(k=>{console.log("[AriaFlow Widget] Streaming state:",k),wt(k)}),F.onQueueChange(k=>{console.log("[AriaFlow Widget] Queue count:",k),Ct(k)}),F.onProcessingChange(k=>{console.log("[AriaFlow Widget] Processing state:",k),bt(k)});const z=await F.initWidget();console.log("[AriaFlow Widget] Agent config received:",z),z?(N(z),console.log("[AriaFlow Widget] Widget initialized successfully")):console.error("[AriaFlow Widget] Agent config fetch failed")}catch(z){console.error("[AriaFlow Widget] Initialization error:",z)}}else t&&!e?(console.warn("[AriaFlow Widget] Direct WebSocket URLs are deprecated. Use agent-url + agent-id instead."),console.error("[AriaFlow Widget] Configuration error: agent-id is required")):i&&n?(console.warn("[AriaFlow Widget] Legacy widget config is deprecated. Use agent-url + agent-id instead."),console.error("[AriaFlow Widget] Configuration error: use agent-url + agent-id instead")):console.error("[AriaFlow Widget] Invalid configuration. Provide agent-url and agent-id.")})(),()=>{oe.current?.dispose()}),[t,e,n,i]),Be(()=>{Ze.current?.scrollIntoView({behavior:"smooth"})},[h]);const et=async()=>{if(!W.trim()||!$)return;const y=W.trim();U("");try{await oe.current?.sendMessage(y)}catch(F){console.error("Failed to send message:",F)}},kt=y=>{y.key==="Enter"&&!y.shiftKey&&(y.preventDefault(),et())},At=y=>{!$||x||oe.current?.sendMessage(y)},St=d||O?.config.title||"Ninewells Hospital",$t=C||O?.config.subtitle||"How can we help you today?",Wt=S||O?.config.emptyChatMessage||"Start a conversation with Ninewells...";return console.log("[AriaFlow Widget] Rendering widget component",{isInitialized:A,isOpen:v,position:a}),u("div",{className:`ariaflow-widget-container ariaflow-widget-${a} ariaflow-widget-${l} ariaflow-widget-radius-${c}`,"data-theme":o,style:{"--ariaflow-accent-color":g,"--ariaflow-base-color":_},children:[!v&&u("button",{className:"ariaflow-widget-launcher",onClick:()=>p(!0),style:{backgroundColor:r,color:f,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&&u("div",{className:"ariaflow-widget-launcher-loading",style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"20px",height:"20px",border:`2px solid ${f}`,borderTop:"2px solid transparent",borderRadius:"50%",animation:"spin 1s linear infinite"}}),A&&u("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:u("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})]}),v&&A&&u("div",{className:"ariaflow-widget-window",style:{backgroundColor:o==="dark"&&_?_:void 0,borderRadius:he[c]},children:[u("div",{className:"ariaflow-widget-header",style:{backgroundColor:g,borderRadius:c==="none"?"0":`${he[c]} ${he[c]} 0 0`},children:[u("div",{className:"ariaflow-widget-header-content",children:u("div",{className:"ariaflow-widget-title-group",children:[u("h3",{className:"ariaflow-widget-title",children:St}),u("p",{className:"ariaflow-widget-subtitle",children:$t})]})}),u("button",{className:"ariaflow-widget-close",onClick:()=>p(!1),"aria-label":"Close chat",children:u("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[u("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),u("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),!$&&u("div",{className:"ariaflow-widget-status",children:[u("span",{className:"ariaflow-widget-status-dot"}),"Connecting..."]}),u("div",{className:"ariaflow-widget-messages",children:h.length===0?u("div",{className:"ariaflow-widget-empty",children:u("p",{children:$?Wt:"Connecting to agent..."})}):u(R,{children:[h.map((y,F)=>(h.length-1,u("div",{className:`ariaflow-widget-message ariaflow-widget-message-${y.role}`,children:u("div",{className:"ariaflow-widget-message-bubble",children:y.role==="tool"?u("div",{className:"ariaflow-widget-tool-message",children:[u("div",{className:"ariaflow-widget-tool-header",children:["🔧 ",y.toolCall?.name]}),u("div",{className:"ariaflow-widget-tool-content",children:[y.toolCall&&u("div",{className:"ariaflow-widget-tool-args",children:[u("strong",{children:"Arguments:"})," ",JSON.stringify(y.toolCall.arguments,null,2)]}),y.toolResult&&u("div",{className:"ariaflow-widget-tool-result",children:[u("strong",{children:"Result:"})," ",JSON.stringify(y.toolResult,null,2)]})]})]}):u(R,{children:[y.content,y.isStreaming&&u("span",{className:"ariaflow-widget-typing-indicator",children:[u("span",{children:"•"}),u("span",{children:"•"}),u("span",{children:"•"})]})]})})},y.id))),u("div",{ref:Ze}),vt&&!x&&u("div",{className:"ariaflow-widget-message ariaflow-widget-message-assistant",children:u("div",{className:"ariaflow-widget-message-bubble",children:u("span",{className:"ariaflow-widget-typing-indicator",children:[u("span",{children:"•"}),u("span",{children:"•"}),u("span",{children:"•"})]})})})]})}),!x&&h.length>0&&h[h.length-1].role==="assistant"&&h[h.length-1].suggestions&&h[h.length-1].suggestions.length>0&&u("div",{className:"ariaflow-widget-suggestions",children:h[h.length-1].suggestions.map(y=>u("button",{className:"ariaflow-widget-chip",onClick:()=>At(y),style:{borderColor:g,color:g,backgroundColor:"rgba(255, 255, 255, 0.95)",backdropFilter:"blur(4px)"},children:y},y))}),u("div",{className:"ariaflow-widget-input",children:[u("textarea",{value:W,onInput:y=>U(y.target.value),onKeyDown:kt,placeholder:$?x?fe>0?`Agent is responding... (${fe} message${fe>1?"s":""} queued)`:"Agent is responding...":"Type your message...":"Connecting...",rows:1,disabled:!$}),u("button",{className:"ariaflow-widget-send",onClick:et,disabled:!W.trim()||!$,style:{backgroundColor:g},"aria-label":"Send message",children:u("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[u("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),u("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})})]})]})]})}lt(Xe,"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",Ye):Ye());function Ye(){const t=document.querySelectorAll("ariaflow-widget");console.log(`[AriaFlow] Initializing ${t.length} widget(s)`)}H.Widget=Xe,H.WidgetClient=Ge,Object.defineProperty(H,Symbol.toStringTag,{value:"Module"})});
|