@ariaflowagents/widget 0.6.0 → 0.6.2

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/style.css CHANGED
@@ -1 +1 @@
1
- .ariaflow-widget-container{position:fixed;z-index:9999;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,sans-serif;--ariaflow-accent-color: #14B8A6;--ariaflow-base-color: #ffffff;--ariaflow-window-bg: #ffffff;--ariaflow-messages-bg: #f8fafc;--ariaflow-text-primary: #1e293b;--ariaflow-text-secondary: #64748b;--ariaflow-border-color: #e2e8f0;--ariaflow-input-bg: #ffffff;--ariaflow-assistant-bubble-bg: #ffffff;--ariaflow-assistant-bubble-text: #1e293b;--ariaflow-input-focus-border: var(--ariaflow-accent-color)}@keyframes spin{0%{transform:translate(-50%,-50%) rotate(0)}to{transform:translate(-50%,-50%) rotate(360deg)}}.ariaflow-widget-bottom-right{bottom:20px;right:20px}.ariaflow-widget-bottom-left{bottom:20px;left:20px}.ariaflow-widget-top-right{top:20px;right:20px}.ariaflow-widget-top-left{top:20px;left:20px}.ariaflow-widget-launcher{width:60px;height:60px;border-radius:30px;border:none;cursor:pointer;display:flex;align-items:center;justify-content:center;color:#fff;box-shadow:0 4px 12px #00000026;transition:transform .2s,box-shadow .2s}.ariaflow-widget-launcher:hover{transform:scale(1.05);box-shadow:0 6px 16px #0003}.ariaflow-widget-window{max-height:calc(100vh - 40px);background:#fff;border-radius:16px;box-shadow:0 8px 32px #00000026;display:flex;flex-direction:column;overflow:hidden;animation:ariaflow-slide-up .3s ease-out}.ariaflow-widget-tiny .ariaflow-widget-window{width:320px;height:400px}.ariaflow-widget-compact .ariaflow-widget-window{width:360px;height:500px}.ariaflow-widget-full .ariaflow-widget-window{width:380px;height:600px}@keyframes ariaflow-slide-up{0%{opacity:0;transform:translateY(20px)}to{opacity:1;transform:translateY(0)}}.ariaflow-widget-header{padding:16px 20px;color:#fff;display:flex;align-items:center;justify-content:space-between}.ariaflow-widget-header-content{display:flex;align-items:center;gap:12px}.ariaflow-widget-avatar{width:40px;height:40px;border-radius:20px;object-fit:cover}.ariaflow-widget-title-group{display:flex;flex-direction:column;gap:2px}.ariaflow-widget-title{margin:0;font-size:16px;font-weight:600}.ariaflow-widget-subtitle{margin:0;font-size:13px;opacity:.9}.ariaflow-widget-close{background:#fff3;border:none;border-radius:20px;width:32px;height:32px;display:flex;align-items:center;justify-content:center;color:#fff;cursor:pointer;transition:background .2s}.ariaflow-widget-close:hover{background:#ffffff4d}.ariaflow-widget-status{padding:8px 16px;display:flex;align-items:center;gap:8px;font-size:13px;color:#64748b;background:#f1f5f9}.ariaflow-widget-status-dot{width:8px;height:8px;border-radius:50%;background:#fbbf24;animation:ariaflow-pulse 1.5s infinite}@keyframes ariaflow-pulse{0%,to{opacity:1}50%{opacity:.5}}.ariaflow-widget-messages{flex:1;padding:16px;overflow-y:auto;display:flex;flex-direction:column;gap:12px;background:#f8fafc}.ariaflow-widget-empty{display:flex;align-items:center;justify-content:center;height:100%;color:#64748b;font-size:14px}.ariaflow-widget-message{display:flex}.ariaflow-widget-message-user{justify-content:flex-end}.ariaflow-widget-message-assistant{justify-content:flex-start}.ariaflow-widget-message-bubble{max-width:80%;padding:12px 16px;border-radius:16px;font-size:14px;line-height:1.5;word-wrap:break-word;white-space:pre-wrap}.ariaflow-widget-message-user .ariaflow-widget-message-bubble{background:var(--ariaflow-accent-color, #14B8A6);color:#fff;border-bottom-right-radius:4px}.ariaflow-widget-message-assistant .ariaflow-widget-message-bubble{background:var(--ariaflow-assistant-bubble-bg, #ffffff);color:var(--ariaflow-assistant-bubble-text, #1e293b);border:1px solid var(--ariaflow-border-color, #e2e8f0);border-bottom-left-radius:4px}.ariaflow-widget-message-tool{justify-content:flex-start}.ariaflow-widget-message-tool .ariaflow-widget-message-bubble{background:var(--ariaflow-tool-bubble-bg, #f1f5f9);color:var(--ariaflow-tool-bubble-text, #334155);border:1px solid var(--ariaflow-tool-border, #cbd5e1);font-family:Monaco,Menlo,Ubuntu Mono,monospace;font-size:13px;max-width:90%}.ariaflow-widget-chips-container{display:flex;flex-wrap:wrap;gap:8px;margin-top:12px}.ariaflow-widget-chip{background:#fff;border:1px solid var(--ariaflow-accent-color);color:var(--ariaflow-accent-color);padding:6px 14px;border-radius:18px;font-size:13px;font-weight:500;cursor:pointer;transition:background .2s,color .2s,transform .1s;white-space:nowrap}.ariaflow-widget-chip:hover{background:var(--ariaflow-accent-color);color:#fff;transform:translateY(-1px)}.ariaflow-widget-chip:active{transform:translateY(0)}.ariaflow-widget-container[data-theme=dark] .ariaflow-widget-chip{background:var(--ariaflow-messages-bg)}.ariaflow-widget-tool-message{display:flex;flex-direction:column;gap:8px}.ariaflow-widget-tool-header{font-weight:600;color:#059669;font-size:12px;text-transform:uppercase;letter-spacing:.5px}.ariaflow-widget-tool-args,.ariaflow-widget-tool-result{margin-top:4px}.ariaflow-widget-tool-args strong,.ariaflow-widget-tool-result strong{color:#475569;font-weight:600}.ariaflow-widget-typing-indicator{display:inline-flex;gap:2px;margin-left:8px;align-items:center}.ariaflow-widget-typing-indicator span{animation:typing 1.4s infinite ease-in-out}.ariaflow-widget-typing-indicator span:nth-child(1){animation-delay:0s}.ariaflow-widget-typing-indicator span:nth-child(2){animation-delay:.2s}.ariaflow-widget-typing-indicator span:nth-child(3){animation-delay:.4s}@keyframes typing{0%,60%,to{opacity:.3;transform:translateY(0)}30%{opacity:1;transform:translateY(-2px)}}.ariaflow-widget-input{padding:12px 16px;background:#fff;border-top:1px solid #e2e8f0;display:flex;gap:8px;align-items:flex-end}.ariaflow-widget-input textarea{flex:1;border:1px solid #e2e8f0;border-radius:20px;padding:10px 14px;font-size:14px;font-family:inherit;resize:none;max-height:100px;outline:none;transition:border-color .2s}.ariaflow-widget-input textarea:focus{border-color:var(--ariaflow-input-focus-border, #2563eb)}.ariaflow-widget-input textarea::placeholder{color:#94a3b8}.ariaflow-widget-send{width:40px;height:40px;border-radius:20px;border:none;color:#fff;display:flex;align-items:center;justify-content:center;cursor:pointer;transition:opacity .2s,transform .2s;flex-shrink:0}.ariaflow-widget-send:hover:not(:disabled){transform:scale(1.05)}.ariaflow-widget-send:disabled{opacity:.5;cursor:not-allowed}.ariaflow-widget-container[data-theme=dark]{--ariaflow-window-bg: var(--ariaflow-base-color, #1e293b);--ariaflow-messages-bg: #0f172a;--ariaflow-text-primary: #f1f5f9;--ariaflow-text-secondary: #94a3b8;--ariaflow-border-color: #334155;--ariaflow-input-bg: #1e293b;--ariaflow-assistant-bubble-bg: #334155;--ariaflow-assistant-bubble-text: #f1f5f9;--ariaflow-input-focus-border: #3b82f6}.ariaflow-widget-container[data-theme=dark] .ariaflow-widget-window{background:var(--ariaflow-window-bg)}.ariaflow-widget-container[data-theme=dark] .ariaflow-widget-messages{background:var(--ariaflow-messages-bg)}.ariaflow-widget-container[data-theme=dark] .ariaflow-widget-message-assistant .ariaflow-widget-message-bubble{background:var(--ariaflow-assistant-bubble-bg);color:var(--ariaflow-assistant-bubble-text);border-color:var(--ariaflow-border-color)}.ariaflow-widget-container[data-theme=dark] .ariaflow-widget-input{background:var(--ariaflow-input-bg);border-top-color:var(--ariaflow-border-color)}.ariaflow-widget-container[data-theme=dark] .ariaflow-widget-input textarea{background:var(--ariaflow-messages-bg);border-color:var(--ariaflow-border-color);color:var(--ariaflow-text-primary)}.ariaflow-widget-container[data-theme=dark] .ariaflow-widget-input textarea:focus{border-color:var(--ariaflow-input-focus-border)}.ariaflow-widget-container[data-theme=dark] .ariaflow-widget-input textarea::placeholder{color:var(--ariaflow-text-secondary)}.ariaflow-widget-messages::-webkit-scrollbar{width:6px}.ariaflow-widget-messages::-webkit-scrollbar-track{background:transparent}.ariaflow-widget-messages::-webkit-scrollbar-thumb{background:#cbd5e1;border-radius:3px}.ariaflow-widget-container[data-theme=dark] .ariaflow-widget-messages::-webkit-scrollbar-thumb{background:#475569}.ariaflow-widget-messages::-webkit-scrollbar-thumb:hover{background:#94a3b8}
1
+ .ariaflow-widget-container{position:fixed;z-index:9999;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,sans-serif;--ariaflow-accent-color: #14B8A6;--ariaflow-base-color: #ffffff;--ariaflow-window-bg: #ffffff;--ariaflow-messages-bg: #f8fafc;--ariaflow-text-primary: #1e293b;--ariaflow-text-secondary: #64748b;--ariaflow-border-color: #e2e8f0;--ariaflow-input-bg: #ffffff;--ariaflow-assistant-bubble-bg: #ffffff;--ariaflow-assistant-bubble-text: #1e293b;--ariaflow-input-focus-border: var(--ariaflow-accent-color)}@keyframes spin{0%{transform:translate(-50%,-50%) rotate(0)}to{transform:translate(-50%,-50%) rotate(360deg)}}.ariaflow-widget-bottom-right{bottom:20px;right:20px}.ariaflow-widget-bottom-left{bottom:20px;left:20px}.ariaflow-widget-top-right{top:20px;right:20px}.ariaflow-widget-top-left{top:20px;left:20px}.ariaflow-widget-launcher{width:60px;height:60px;border-radius:30px;border:none;cursor:pointer;display:flex;align-items:center;justify-content:center;color:#fff;box-shadow:0 4px 12px #00000026;transition:transform .2s,box-shadow .2s}.ariaflow-widget-launcher:hover{transform:scale(1.05);box-shadow:0 6px 16px #0003}.ariaflow-widget-window{max-height:calc(100vh - 40px);background:#fff;border-radius:16px;box-shadow:0 8px 32px #00000026;display:flex;flex-direction:column;overflow:hidden;animation:ariaflow-slide-up .3s ease-out}.ariaflow-widget-tiny .ariaflow-widget-window{width:320px;height:400px}.ariaflow-widget-compact .ariaflow-widget-window{width:360px;height:500px}.ariaflow-widget-full .ariaflow-widget-window{width:380px;height:600px}@keyframes ariaflow-slide-up{0%{opacity:0;transform:translateY(20px)}to{opacity:1;transform:translateY(0)}}.ariaflow-widget-header{padding:16px 20px;color:#fff;display:flex;align-items:center;justify-content:space-between}.ariaflow-widget-header-content{display:flex;align-items:center;gap:12px}.ariaflow-widget-avatar{width:40px;height:40px;border-radius:20px;object-fit:cover}.ariaflow-widget-title-group{display:flex;flex-direction:column;gap:2px}.ariaflow-widget-title{margin:0;font-size:16px;font-weight:600}.ariaflow-widget-subtitle{margin:0;font-size:13px;opacity:.9}.ariaflow-widget-close{background:#fff3;border:none;border-radius:20px;width:32px;height:32px;display:flex;align-items:center;justify-content:center;color:#fff;cursor:pointer;transition:background .2s}.ariaflow-widget-close:hover{background:#ffffff4d}.ariaflow-widget-status{padding:8px 16px;display:flex;align-items:center;gap:8px;font-size:13px;color:#64748b;background:#f1f5f9}.ariaflow-widget-status-dot{width:8px;height:8px;border-radius:50%;background:#fbbf24;animation:ariaflow-pulse 1.5s infinite}@keyframes ariaflow-pulse{0%,to{opacity:1}50%{opacity:.5}}.ariaflow-widget-messages{flex:1;padding:16px;overflow-y:auto;display:flex;flex-direction:column;gap:12px;background:#f8fafc}.ariaflow-widget-empty{display:flex;align-items:center;justify-content:center;height:100%;color:#64748b;font-size:14px}.ariaflow-widget-message{display:flex}.ariaflow-widget-message-user{justify-content:flex-end}.ariaflow-widget-message-assistant{justify-content:flex-start}.ariaflow-widget-message-bubble{max-width:80%;padding:12px 16px;border-radius:16px;font-size:14px;line-height:1.5;word-wrap:break-word;white-space:pre-wrap}.ariaflow-widget-message-user .ariaflow-widget-message-bubble{background:var(--ariaflow-accent-color, #14B8A6);color:#fff;border-bottom-right-radius:4px}.ariaflow-widget-message-assistant .ariaflow-widget-message-bubble{background:var(--ariaflow-assistant-bubble-bg, #ffffff);color:var(--ariaflow-assistant-bubble-text, #1e293b);border:1px solid var(--ariaflow-border-color, #e2e8f0);border-bottom-left-radius:4px}.ariaflow-widget-message-tool{justify-content:flex-start}.ariaflow-widget-message-tool .ariaflow-widget-message-bubble{background:var(--ariaflow-tool-bubble-bg, #f1f5f9);color:var(--ariaflow-tool-bubble-text, #334155);border:1px solid var(--ariaflow-tool-border, #cbd5e1);font-family:Monaco,Menlo,Ubuntu Mono,monospace;font-size:13px;max-width:90%}.ariaflow-widget-chips-container{display:flex;flex-wrap:wrap;gap:8px;margin-top:12px}.ariaflow-widget-chip{background:#fff;border:1px solid var(--ariaflow-accent-color);color:var(--ariaflow-accent-color);padding:8px 16px;border-radius:20px;font-size:13px;font-weight:500;cursor:pointer;transition:all .2s cubic-bezier(.4,0,.2,1);white-space:nowrap;box-shadow:0 2px 4px #0000000d;animation:ariaflow-chip-entrance .4s ease-out backwards}.ariaflow-widget-chip:hover{background:var(--ariaflow-accent-color);color:#fff;transform:translateY(-2px);box-shadow:0 4px 8px #0000001a}.ariaflow-widget-chip:active{transform:translateY(0)}@keyframes ariaflow-chip-entrance{0%{opacity:0;transform:translateY(10px) scale(.95);filter:blur(4px)}to{opacity:1;transform:translateY(0) scale(1);filter:blur(0)}}.ariaflow-widget-container[data-theme=dark] .ariaflow-widget-chip{background:var(--ariaflow-messages-bg)}.ariaflow-widget-tool-message{display:flex;flex-direction:column;gap:8px}.ariaflow-widget-tool-header{font-weight:600;color:#059669;font-size:12px;text-transform:uppercase;letter-spacing:.5px}.ariaflow-widget-tool-args,.ariaflow-widget-tool-result{margin-top:4px}.ariaflow-widget-tool-args strong,.ariaflow-widget-tool-result strong{color:#475569;font-weight:600}.ariaflow-widget-typing-indicator{display:inline-flex;gap:2px;margin-left:8px;align-items:center}.ariaflow-widget-typing-indicator span{animation:typing 1.4s infinite ease-in-out}.ariaflow-widget-typing-indicator span:nth-child(1){animation-delay:0s}.ariaflow-widget-typing-indicator span:nth-child(2){animation-delay:.2s}.ariaflow-widget-typing-indicator span:nth-child(3){animation-delay:.4s}@keyframes typing{0%,60%,to{opacity:.3;transform:translateY(0)}30%{opacity:1;transform:translateY(-2px)}}.ariaflow-widget-input{padding:12px 16px;background:#fff;border-top:1px solid #e2e8f0;display:flex;gap:8px;align-items:flex-end}.ariaflow-widget-input textarea{flex:1;border:1px solid #e2e8f0;border-radius:20px;padding:10px 14px;font-size:14px;font-family:inherit;resize:none;max-height:100px;outline:none;transition:border-color .2s}.ariaflow-widget-input textarea:focus{border-color:var(--ariaflow-input-focus-border, #2563eb)}.ariaflow-widget-input textarea::placeholder{color:#94a3b8}.ariaflow-widget-send{width:40px;height:40px;border-radius:20px;border:none;color:#fff;display:flex;align-items:center;justify-content:center;cursor:pointer;transition:opacity .2s,transform .2s;flex-shrink:0}.ariaflow-widget-send:hover:not(:disabled){transform:scale(1.05)}.ariaflow-widget-send:disabled{opacity:.5;cursor:not-allowed}.ariaflow-widget-container[data-theme=dark]{--ariaflow-window-bg: var(--ariaflow-base-color, #1e293b);--ariaflow-messages-bg: #0f172a;--ariaflow-text-primary: #f1f5f9;--ariaflow-text-secondary: #94a3b8;--ariaflow-border-color: #334155;--ariaflow-input-bg: #1e293b;--ariaflow-assistant-bubble-bg: #334155;--ariaflow-assistant-bubble-text: #f1f5f9;--ariaflow-input-focus-border: #3b82f6}.ariaflow-widget-container[data-theme=dark] .ariaflow-widget-window{background:var(--ariaflow-window-bg)}.ariaflow-widget-container[data-theme=dark] .ariaflow-widget-messages{background:var(--ariaflow-messages-bg)}.ariaflow-widget-container[data-theme=dark] .ariaflow-widget-message-assistant .ariaflow-widget-message-bubble{background:var(--ariaflow-assistant-bubble-bg);color:var(--ariaflow-assistant-bubble-text);border-color:var(--ariaflow-border-color)}.ariaflow-widget-container[data-theme=dark] .ariaflow-widget-input{background:var(--ariaflow-input-bg);border-top-color:var(--ariaflow-border-color)}.ariaflow-widget-container[data-theme=dark] .ariaflow-widget-input textarea{background:var(--ariaflow-messages-bg);border-color:var(--ariaflow-border-color);color:var(--ariaflow-text-primary)}.ariaflow-widget-container[data-theme=dark] .ariaflow-widget-input textarea:focus{border-color:var(--ariaflow-input-focus-border)}.ariaflow-widget-container[data-theme=dark] .ariaflow-widget-input textarea::placeholder{color:var(--ariaflow-text-secondary)}.ariaflow-widget-messages::-webkit-scrollbar{width:6px}.ariaflow-widget-messages::-webkit-scrollbar-track{background:transparent}.ariaflow-widget-messages::-webkit-scrollbar-thumb{background:#cbd5e1;border-radius:3px}.ariaflow-widget-container[data-theme=dark] .ariaflow-widget-messages::-webkit-scrollbar-thumb{background:#475569}.ariaflow-widget-messages::-webkit-scrollbar-thumb:hover{background:#94a3b8}
package/dist/widget.js CHANGED
@@ -1,5 +1,5 @@
1
- var B, m, He, R, we, Pe, Ie, Re, ue, le, ae, q = {}, Ue = [], rt = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i, te = Array.isArray;
2
- function M(t, e) {
1
+ var B, m, He, R, ye, Pe, Ie, Re, ue, le, ae, q = {}, Ue = [], rt = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i, te = Array.isArray;
2
+ function E(t, e) {
3
3
  for (var n in e) t[n] = e[n];
4
4
  return t;
5
5
  }
@@ -37,22 +37,22 @@ function De(t) {
37
37
  return De(t);
38
38
  }
39
39
  }
40
- function ye(t) {
41
- (!t.__d && (t.__d = !0) && R.push(t) && !Y.__r++ || we != m.debounceRendering) && ((we = m.debounceRendering) || Pe)(Y);
40
+ function we(t) {
41
+ (!t.__d && (t.__d = !0) && R.push(t) && !Y.__r++ || ye != m.debounceRendering) && ((ye = m.debounceRendering) || Pe)(Y);
42
42
  }
43
43
  function Y() {
44
- for (var t, e, n, o, s, i, l, a = 1; R.length; ) R.length > a && R.sort(Ie), t = R.shift(), a = R.length, t.__d && (n = void 0, o = void 0, s = (o = (e = t).__v).__e, i = [], l = [], e.__P && ((n = M({}, o)).__v = o.__v + 1, m.vnode && m.vnode(n), ge(e.__P, n, o, e.__n, e.__P.namespaceURI, 32 & o.__u ? [s] : null, i, s ?? O(o), !!(32 & o.__u), l), n.__v = o.__v, n.__.__k[n.__i] = n, Qe(i, n, l), o.__e = o.__ = null, n.__e != s && De(n)));
44
+ for (var t, e, n, o, s, i, l, _ = 1; R.length; ) R.length > _ && R.sort(Ie), t = R.shift(), _ = R.length, t.__d && (n = void 0, o = void 0, s = (o = (e = t).__v).__e, i = [], l = [], e.__P && ((n = E({}, o)).__v = o.__v + 1, m.vnode && m.vnode(n), ge(e.__P, n, o, e.__n, e.__P.namespaceURI, 32 & o.__u ? [s] : null, i, s ?? O(o), !!(32 & o.__u), l), n.__v = o.__v, n.__.__k[n.__i] = n, Qe(i, n, l), o.__e = o.__ = null, n.__e != s && De(n)));
45
45
  Y.__r = 0;
46
46
  }
47
- function Le(t, e, n, o, s, i, l, a, c, _, u) {
48
- var r, h, d, b, S, y, p, f = o && o.__k || Ue, x = e.length;
49
- for (c = lt(n, e, f, c, x), r = 0; r < x; r++) (d = n.__k[r]) != null && (h = d.__i == -1 ? q : f[d.__i] || q, d.__i = r, y = ge(t, d, h, s, i, l, a, c, _, u), b = d.__e, d.ref && h.ref != d.ref && (h.ref && he(h.ref, null, d), u.push(d.ref, d.__c || b, d)), S == null && b != null && (S = b), (p = !!(4 & d.__u)) || h.__k === d.__k ? c = Oe(d, c, t, p) : typeof d.type == "function" && y !== void 0 ? c = y : b && (c = b.nextSibling), d.__u &= -7);
47
+ function Le(t, e, n, o, s, i, l, _, c, a, u) {
48
+ var r, h, d, b, S, w, p, f = o && o.__k || Ue, x = e.length;
49
+ for (c = lt(n, e, f, c, x), r = 0; r < x; r++) (d = n.__k[r]) != null && (h = d.__i == -1 ? q : f[d.__i] || q, d.__i = r, w = ge(t, d, h, s, i, l, _, c, a, u), b = d.__e, d.ref && h.ref != d.ref && (h.ref && he(h.ref, null, d), u.push(d.ref, d.__c || b, d)), S == null && b != null && (S = b), (p = !!(4 & d.__u)) || h.__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
52
  function lt(t, e, n, o, s) {
53
- var i, l, a, c, _, u = n.length, r = u, h = 0;
54
- for (t.__k = new Array(s), i = 0; i < s; i++) (l = e[i]) != null && typeof l != "boolean" && typeof l != "function" ? (typeof l == "string" || typeof l == "number" || typeof l == "bigint" || l.constructor == String ? l = t.__k[i] = Q(null, l, null, null, null) : te(l) ? l = t.__k[i] = Q(U, { children: l }, null, null, null) : l.constructor === void 0 && l.__b > 0 ? l = t.__k[i] = Q(l.type, l.props, l.key, l.ref ? l.ref : null, l.__v) : t.__k[i] = l, c = i + h, l.__ = t, l.__b = t.__b + 1, a = null, (_ = l.__i = at(l, n, c, r)) != -1 && (r--, (a = n[_]) && (a.__u |= 2)), a == null || a.__v == null ? (_ == -1 && (s > u ? h-- : s < u && h++), typeof l.type != "function" && (l.__u |= 4)) : _ != c && (_ == c - 1 ? h-- : _ == c + 1 ? h++ : (_ > c ? h-- : h++, l.__u |= 4))) : t.__k[i] = null;
55
- if (r) for (i = 0; i < u; i++) (a = n[i]) != null && !(2 & a.__u) && (a.__e == o && (o = O(a)), je(a, a));
53
+ var i, l, _, c, a, u = n.length, r = u, h = 0;
54
+ for (t.__k = new Array(s), i = 0; i < s; i++) (l = e[i]) != null && typeof l != "boolean" && typeof l != "function" ? (typeof l == "string" || typeof l == "number" || typeof l == "bigint" || l.constructor == String ? l = t.__k[i] = Q(null, l, null, null, null) : te(l) ? l = t.__k[i] = Q(U, { children: l }, null, null, null) : l.constructor === void 0 && l.__b > 0 ? l = t.__k[i] = Q(l.type, l.props, l.key, l.ref ? l.ref : null, l.__v) : t.__k[i] = l, c = i + h, l.__ = t, l.__b = t.__b + 1, _ = null, (a = l.__i = at(l, n, c, r)) != -1 && (r--, (_ = n[a]) && (_.__u |= 2)), _ == null || _.__v == null ? (a == -1 && (s > u ? h-- : s < u && h++), typeof l.type != "function" && (l.__u |= 4)) : a != c && (a == c - 1 ? h-- : a == c + 1 ? h++ : (a > c ? h-- : h++, l.__u |= 4))) : t.__k[i] = null;
55
+ if (r) for (i = 0; i < u; i++) (_ = n[i]) != null && !(2 & _.__u) && (_.__e == o && (o = O(_)), je(_, _));
56
56
  return o;
57
57
  }
58
58
  function Oe(t, e, n, o) {
@@ -68,10 +68,10 @@ function Oe(t, e, n, o) {
68
68
  return e;
69
69
  }
70
70
  function at(t, e, n, o) {
71
- var s, i, l, a = t.key, c = t.type, _ = e[n], u = _ != null && (2 & _.__u) == 0;
72
- if (_ === null && a == null || u && a == _.key && c == _.type) return n;
71
+ var s, i, l, _ = t.key, c = t.type, a = e[n], u = a != null && (2 & a.__u) == 0;
72
+ if (a === null && _ == null || u && _ == a.key && c == a.type) return n;
73
73
  if (o > (u ? 1 : 0)) {
74
- for (s = n - 1, i = n + 1; s >= 0 || i < e.length; ) if ((_ = e[l = s >= 0 ? s-- : i++]) != null && !(2 & _.__u) && a == _.key && c == _.type) return l;
74
+ for (s = n - 1, i = n + 1; s >= 0 || i < e.length; ) if ((a = e[l = s >= 0 ? s-- : i++]) != null && !(2 & a.__u) && _ == a.key && c == a.type) return l;
75
75
  }
76
76
  return -1;
77
77
  }
@@ -106,16 +106,16 @@ function be(t) {
106
106
  }
107
107
  };
108
108
  }
109
- function ge(t, e, n, o, s, i, l, a, c, _) {
110
- var u, r, h, d, b, S, y, p, f, x, W, H, $, z, k, P, I, N = e.type;
109
+ function ge(t, e, n, o, s, i, l, _, c, a) {
110
+ var u, r, h, d, b, S, w, p, f, x, W, H, $, z, k, P, I, N = e.type;
111
111
  if (e.constructor !== void 0) return null;
112
- 128 & n.__u && (c = !!(32 & n.__u), i = [a = e.__e = n.__e]), (u = m.__b) && u(e);
112
+ 128 & n.__u && (c = !!(32 & n.__u), i = [_ = e.__e = n.__e]), (u = m.__b) && u(e);
113
113
  e: if (typeof N == "function") try {
114
- if (p = e.props, f = "prototype" in N && N.prototype.render, x = (u = N.contextType) && o[u.__c], W = u ? x ? x.props.value : u.__ : o, n.__c ? y = (r = e.__c = n.__c).__ = r.__E : (f ? e.__c = r = new N(p, W) : (e.__c = r = new G(p, W), r.constructor = N, r.render = ct), x && x.sub(r), r.state || (r.state = {}), r.__n = o, h = r.__d = !0, r.__h = [], r._sb = []), f && r.__s == null && (r.__s = r.state), f && N.getDerivedStateFromProps != null && (r.__s == r.state && (r.__s = M({}, r.__s)), M(r.__s, N.getDerivedStateFromProps(p, r.__s))), d = r.props, b = r.state, r.__v = e, h) f && N.getDerivedStateFromProps == null && r.componentWillMount != null && r.componentWillMount(), f && r.componentDidMount != null && r.__h.push(r.componentDidMount);
114
+ if (p = e.props, f = "prototype" in N && N.prototype.render, x = (u = N.contextType) && o[u.__c], W = u ? x ? x.props.value : u.__ : o, n.__c ? w = (r = e.__c = n.__c).__ = r.__E : (f ? e.__c = r = new N(p, W) : (e.__c = r = new G(p, W), r.constructor = N, r.render = ct), x && x.sub(r), r.state || (r.state = {}), r.__n = o, h = r.__d = !0, r.__h = [], r._sb = []), f && r.__s == null && (r.__s = r.state), f && N.getDerivedStateFromProps != null && (r.__s == r.state && (r.__s = E({}, r.__s)), E(r.__s, N.getDerivedStateFromProps(p, r.__s))), d = r.props, b = r.state, r.__v = e, h) f && N.getDerivedStateFromProps == null && r.componentWillMount != null && r.componentWillMount(), f && r.componentDidMount != null && r.__h.push(r.componentDidMount);
115
115
  else {
116
116
  if (f && 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) {
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(E) {
118
- E && (E.__ = e);
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(F) {
118
+ F && (F.__ = e);
119
119
  }), H = 0; H < r._sb.length; H++) r.__h.push(r._sb[H]);
120
120
  r._sb = [], r.__h.length && l.push(r);
121
121
  break e;
@@ -130,20 +130,20 @@ function ge(t, e, n, o, s, i, l, a, c, _) {
130
130
  } else do
131
131
  r.__d = !1, $ && $(e), u = 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 && (o = M(M({}, o), r.getChildContext())), f && !h && r.getSnapshotBeforeUpdate != null && (S = r.getSnapshotBeforeUpdate(d, b)), P = u, u != null && u.type === U && u.key == null && (P = qe(u.props.children)), a = Le(t, te(P) ? P : [P], e, n, o, s, i, l, a, c, _), r.base = e.__e, e.__u &= -161, r.__h.length && l.push(r), y && (r.__E = r.__ = null);
134
- } catch (E) {
135
- if (e.__v = null, c || i != null) if (E.then) {
136
- for (e.__u |= c ? 160 : 128; a && a.nodeType == 8 && a.nextSibling; ) a = a.nextSibling;
137
- i[i.indexOf(a)] = null, e.__e = a;
133
+ r.state = r.__s, r.getChildContext != null && (o = E(E({}, o), r.getChildContext())), f && !h && r.getSnapshotBeforeUpdate != null && (S = r.getSnapshotBeforeUpdate(d, b)), P = u, u != null && u.type === U && u.key == null && (P = qe(u.props.children)), _ = Le(t, te(P) ? P : [P], e, n, o, s, i, l, _, c, a), r.base = e.__e, e.__u &= -161, r.__h.length && l.push(r), w && (r.__E = r.__ = null);
134
+ } catch (F) {
135
+ if (e.__v = null, c || i != null) if (F.then) {
136
+ for (e.__u |= c ? 160 : 128; _ && _.nodeType == 8 && _.nextSibling; ) _ = _.nextSibling;
137
+ i[i.indexOf(_)] = null, e.__e = _;
138
138
  } else {
139
139
  for (I = i.length; I--; ) de(i[I]);
140
140
  _e(e);
141
141
  }
142
- else e.__e = n.__e, e.__k = n.__k, E.then || _e(e);
143
- m.__e(E, e, n);
142
+ else e.__e = n.__e, e.__k = n.__k, F.then || _e(e);
143
+ m.__e(F, e, n);
144
144
  }
145
- else i == null && e.__v == n.__v ? (e.__k = n.__k, e.__e = n.__e) : a = e.__e = _t(n.__e, e, n, o, s, i, l, c, _);
146
- return (u = m.diffed) && u(e), 128 & e.__u ? void 0 : a;
145
+ else i == null && e.__v == n.__v ? (e.__k = n.__k, e.__e = n.__e) : _ = e.__e = _t(n.__e, e, n, o, s, i, l, c, a);
146
+ return (u = m.diffed) && u(e), 128 & e.__u ? void 0 : _;
147
147
  }
148
148
  function _e(t) {
149
149
  t && t.__c && (t.__c.__e = !0), t && t.__k && t.__k.forEach(_e);
@@ -161,34 +161,34 @@ function Qe(t, e, n) {
161
161
  });
162
162
  }
163
163
  function qe(t) {
164
- return typeof t != "object" || t == null || t.__b && t.__b > 0 ? t : te(t) ? t.map(qe) : M({}, t);
164
+ return typeof t != "object" || t == null || t.__b && t.__b > 0 ? t : te(t) ? t.map(qe) : E({}, t);
165
165
  }
166
- function _t(t, e, n, o, s, i, l, a, c) {
167
- var _, u, r, h, d, b, S, y = n.props || q, p = e.props, f = e.type;
166
+ function _t(t, e, n, o, s, i, l, _, c) {
167
+ var a, u, r, h, d, b, S, w = n.props || q, p = e.props, f = e.type;
168
168
  if (f == "svg" ? s = "http://www.w3.org/2000/svg" : f == "math" ? s = "http://www.w3.org/1998/Math/MathML" : s || (s = "http://www.w3.org/1999/xhtml"), i != null) {
169
- for (_ = 0; _ < i.length; _++) if ((d = i[_]) && "setAttribute" in d == !!f && (f ? d.localName == f : d.nodeType == 3)) {
170
- t = d, i[_] = null;
169
+ for (a = 0; a < i.length; a++) if ((d = i[a]) && "setAttribute" in d == !!f && (f ? d.localName == f : d.nodeType == 3)) {
170
+ t = d, i[a] = null;
171
171
  break;
172
172
  }
173
173
  }
174
174
  if (t == null) {
175
175
  if (f == null) return document.createTextNode(p);
176
- t = document.createElementNS(s, f, p.is && p), a && (m.__m && m.__m(e, i), a = !1), i = null;
176
+ t = document.createElementNS(s, f, p.is && p), _ && (m.__m && m.__m(e, i), _ = !1), i = null;
177
177
  }
178
- if (f == null) y === p || a && t.data == p || (t.data = p);
178
+ if (f == null) w === p || _ && t.data == p || (t.data = p);
179
179
  else {
180
- if (i = i && B.call(t.childNodes), !a && i != null) for (y = {}, _ = 0; _ < t.attributes.length; _++) y[(d = t.attributes[_]).name] = d.value;
181
- for (_ in y) if (d = y[_], _ != "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, s);
180
+ if (i = i && B.call(t.childNodes), !_ && i != null) for (w = {}, a = 0; a < t.attributes.length; a++) w[(d = t.attributes[a]).name] = d.value;
181
+ for (a in w) if (d = w[a], a != "children") {
182
+ if (a == "dangerouslySetInnerHTML") r = d;
183
+ else if (!(a in p)) {
184
+ if (a == "value" && "defaultValue" in p || a == "checked" && "defaultChecked" in p) continue;
185
+ J(t, a, null, d, s);
186
186
  }
187
187
  }
188
- for (_ in p) d = p[_], _ == "children" ? h = d : _ == "dangerouslySetInnerHTML" ? u = d : _ == "value" ? b = d : _ == "checked" ? S = d : a && typeof d != "function" || y[_] === d || J(t, _, d, y[_], s);
189
- if (u) a || r && (u.__html == r.__html || u.__html == t.innerHTML) || (t.innerHTML = u.__html), e.__k = [];
190
- else if (r && (t.innerHTML = ""), Le(e.type == "template" ? t.content : t, te(h) ? h : [h], e, n, o, f == "foreignObject" ? "http://www.w3.org/1999/xhtml" : s, i, l, i ? i[0] : n.__k && O(n, 0), a, c), i != null) for (_ = i.length; _--; ) de(i[_]);
191
- a || (_ = "value", f == "progress" && b == null ? t.removeAttribute("value") : b != null && (b !== t[_] || f == "progress" && !b || f == "option" && b != y[_]) && J(t, _, b, y[_], s), _ = "checked", S != null && S != t[_] && J(t, _, S, y[_], s));
188
+ for (a in p) d = p[a], a == "children" ? h = d : a == "dangerouslySetInnerHTML" ? u = d : a == "value" ? b = d : a == "checked" ? S = d : _ && typeof d != "function" || w[a] === d || J(t, a, d, w[a], s);
189
+ if (u) _ || r && (u.__html == r.__html || u.__html == t.innerHTML) || (t.innerHTML = u.__html), e.__k = [];
190
+ else if (r && (t.innerHTML = ""), Le(e.type == "template" ? t.content : t, te(h) ? h : [h], e, n, o, f == "foreignObject" ? "http://www.w3.org/1999/xhtml" : s, i, l, i ? i[0] : n.__k && O(n, 0), _, c), i != null) for (a = i.length; a--; ) de(i[a]);
191
+ _ || (a = "value", f == "progress" && b == null ? t.removeAttribute("value") : b != null && (b !== t[a] || f == "progress" && !b || f == "option" && b != w[a]) && J(t, a, b, w[a], s), a = "checked", S != null && S != t[a] && J(t, a, S, w[a], s));
192
192
  }
193
193
  return t;
194
194
  }
@@ -226,22 +226,22 @@ function Be(t, e) {
226
226
  ne(t, e, Be);
227
227
  }
228
228
  function ze(t, e, n) {
229
- var o, s, i, l, a = M({}, t.props);
230
- for (i in t.type && t.type.defaultProps && (l = t.type.defaultProps), e) i == "key" ? o = e[i] : i == "ref" ? s = e[i] : a[i] = e[i] === void 0 && l != null ? l[i] : e[i];
231
- return arguments.length > 2 && (a.children = arguments.length > 3 ? B.call(arguments, 2) : n), Q(t.type, a, o || t.key, s || t.ref, null);
229
+ var o, s, i, l, _ = E({}, t.props);
230
+ for (i in t.type && t.type.defaultProps && (l = t.type.defaultProps), e) i == "key" ? o = e[i] : i == "ref" ? s = e[i] : _[i] = e[i] === void 0 && l != null ? l[i] : e[i];
231
+ return arguments.length > 2 && (_.children = arguments.length > 3 ? B.call(arguments, 2) : n), Q(t.type, _, o || t.key, s || t.ref, null);
232
232
  }
233
233
  B = Ue.slice, m = { __e: function(t, e, n, o) {
234
234
  for (var s, i, l; e = e.__; ) if ((s = e.__c) && !s.__) try {
235
235
  if ((i = s.constructor) && i.getDerivedStateFromError != null && (s.setState(i.getDerivedStateFromError(t)), l = s.__d), s.componentDidCatch != null && (s.componentDidCatch(t, o || {}), l = s.__d), l) return s.__E = s;
236
- } catch (a) {
237
- t = a;
236
+ } catch (_) {
237
+ t = _;
238
238
  }
239
239
  throw t;
240
240
  } }, He = 0, G.prototype.setState = function(t, e) {
241
241
  var n;
242
- 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), ye(this));
242
+ n = this.__s != null && this.__s != this.state ? this.__s : this.__s = E({}, this.state), typeof t == "function" && (t = t(E({}, n), this.props)), t && E(n, t), t != null && this.__v && (e && this._sb.push(e), we(this));
243
243
  }, G.prototype.forceUpdate = function(t) {
244
- this.__v && (this.__e = !0, t && this.__h.push(t), ye(this));
244
+ this.__v && (this.__e = !0, t && this.__h.push(t), we(this));
245
245
  }, G.prototype.render = U, R = [], Pe = typeof Promise == "function" ? Promise.prototype.then.bind(Promise.resolve()) : setTimeout, Ie = function(t, e) {
246
246
  return t.__v.__b - e.__v.__b;
247
247
  }, Y.__r = 0, Re = /(PointerCapture)$|Capture$/i, ue = 0, le = be(!1), ae = be(!0);
@@ -273,8 +273,8 @@ function gt(t, e, n, o) {
273
273
  return this._vdom ? this._vdom.props[i] : this._props[i];
274
274
  }, set: function(l) {
275
275
  this._vdom ? this.attributeChangedCallback(i, null, l) : (this._props || (this._props = {}), this._props[i] = l);
276
- var a = typeof l;
277
- l != null && a !== "string" && a !== "boolean" && a !== "number" || this.setAttribute(i, l);
276
+ var _ = typeof l;
277
+ l != null && _ !== "string" && _ !== "boolean" && _ !== "number" || this.setAttribute(i, l);
278
278
  } });
279
279
  }), customElements.define(e, s), s;
280
280
  }
@@ -314,23 +314,23 @@ function Ce(t, e) {
314
314
  function Ke(t, e, n) {
315
315
  if (t.nodeType === 3) return t.data;
316
316
  if (t.nodeType !== 1) return null;
317
- var o = [], s = {}, i = 0, l = t.attributes, a = t.childNodes;
317
+ var o = [], s = {}, i = 0, l = t.attributes, _ = t.childNodes;
318
318
  for (i = l.length; i--; ) l[i].name !== "slot" && (s[l[i].name] = l[i].value, s[Je(l[i].name)] = l[i].value);
319
- for (i = a.length; i--; ) {
320
- var c = Ke(a[i], null, n), _ = a[i].slot;
321
- _ ? s[_] = L(Ce, { name: _ }, c) : o[i] = c;
319
+ for (i = _.length; i--; ) {
320
+ var c = Ke(_[i], null, n), a = _[i].slot;
321
+ a ? s[a] = L(Ce, { name: a }, c) : o[i] = c;
322
322
  }
323
323
  var u = !(!n || !n.shadow), r = e ? L(Ce, { useFragment: !u }, o) : o;
324
324
  return !u && e && (t.innerHTML = ""), L(e || t.nodeName.toLowerCase(), s, r);
325
325
  }
326
- var wt = 0;
326
+ var yt = 0;
327
327
  function g(t, e, n, o, s, i) {
328
328
  e || (e = {});
329
- var l, a, c = e;
330
- if ("ref" in c) for (a in c = {}, e) a == "ref" ? l = e[a] : c[a] = e[a];
331
- var _ = { type: t, props: c, key: n, ref: l, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: --wt, __i: -1, __u: 0, __source: s, __self: i };
332
- if (typeof t == "function" && (l = t.defaultProps)) for (a in l) c[a] === void 0 && (c[a] = l[a]);
333
- return m.vnode && m.vnode(_), _;
329
+ var l, _, c = e;
330
+ if ("ref" in c) for (_ in c = {}, e) _ == "ref" ? l = e[_] : c[_] = e[_];
331
+ var a = { type: t, props: c, key: n, ref: l, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: --yt, __i: -1, __u: 0, __source: s, __self: i };
332
+ if (typeof t == "function" && (l = t.defaultProps)) for (_ in l) c[_] === void 0 && (c[_] = l[_]);
333
+ return m.vnode && m.vnode(a), a;
334
334
  }
335
335
  var j, v, se, ke, ee = 0, Ge = [], C = m, Ae = C.__b, Se = C.__r, $e = C.diffed, We = C.__c, Ne = C.unmount, xe = C.__;
336
336
  function fe(t, e) {
@@ -339,38 +339,38 @@ function fe(t, e) {
339
339
  return t >= n.__.length && n.__.push({}), n.__[t];
340
340
  }
341
341
  function T(t) {
342
- return ee = 1, yt(Ye, t);
342
+ return ee = 1, wt(Ye, t);
343
343
  }
344
- function yt(t, e, n) {
344
+ function wt(t, e, n) {
345
345
  var o = fe(j++, 2);
346
- if (o.t = t, !o.__c && (o.__ = [Ye(void 0, e), function(a) {
347
- var c = o.__N ? o.__N[0] : o.__[0], _ = o.t(c, a);
348
- c !== _ && (o.__N = [_, o.__[1]], o.__c.setState({}));
346
+ if (o.t = t, !o.__c && (o.__ = [Ye(void 0, e), function(_) {
347
+ var c = o.__N ? o.__N[0] : o.__[0], a = o.t(c, _);
348
+ c !== a && (o.__N = [a, o.__[1]], o.__c.setState({}));
349
349
  }], o.__c = v, !v.__f)) {
350
- var s = function(a, c, _) {
350
+ var s = function(_, c, a) {
351
351
  if (!o.__c.__H) return !0;
352
352
  var u = o.__c.__H.__.filter(function(h) {
353
353
  return !!h.__c;
354
354
  });
355
355
  if (u.every(function(h) {
356
356
  return !h.__N;
357
- })) return !i || i.call(this, a, c, _);
358
- var r = o.__c.props !== a;
357
+ })) return !i || i.call(this, _, c, a);
358
+ var r = o.__c.props !== _;
359
359
  return u.forEach(function(h) {
360
360
  if (h.__N) {
361
361
  var d = h.__[0];
362
362
  h.__ = h.__N, h.__N = void 0, d !== h.__[0] && (r = !0);
363
363
  }
364
- }), i && i.call(this, a, c, _) || r;
364
+ }), i && i.call(this, _, c, a) || r;
365
365
  };
366
366
  v.__f = !0;
367
367
  var i = v.shouldComponentUpdate, l = v.componentWillUpdate;
368
- v.componentWillUpdate = function(a, c, _) {
368
+ v.componentWillUpdate = function(_, c, a) {
369
369
  if (this.__e) {
370
370
  var u = i;
371
- i = void 0, s(a, c, _), i = u;
371
+ i = void 0, s(_, c, a), i = u;
372
372
  }
373
- l && l.call(this, a, c, _);
373
+ l && l.call(this, _, c, a);
374
374
  }, v.shouldComponentUpdate = s;
375
375
  }
376
376
  return o.__N || o.__;
@@ -563,6 +563,10 @@ class At {
563
563
  { ...s, isStreaming: !1 }
564
564
  ] : o;
565
565
  }), this.isAgentStreaming = !1, this.notifyStreamingChange(!1), this.processMessageQueue();
566
+ else if (n.type === "step-start" || n.type === "agent-start")
567
+ console.log(`[Widget] ${n.type} received:`, n.agentId || ""), this.isAgentStreaming = !0, this.notifyStreamingChange(!0);
568
+ else if (n.type === "step-end" || n.type === "agent-end")
569
+ console.log(`[Widget] ${n.type} received`);
566
570
  else if (n.type === "tool-call") {
567
571
  console.log("[Widget] Tool call:", n.tool);
568
572
  const o = {
@@ -578,7 +582,7 @@ class At {
578
582
  this.setMessages((s) => [...s, o]), n.tool.name === "suggest_options" && n.tool.arguments?.options && this.setMessages((s) => {
579
583
  const i = [...s].reverse().find((l) => l.role === "assistant");
580
584
  return i ? s.map(
581
- (l) => l.id === i.id ? { ...l, suggestions: [...l.suggestions || [], ...n.tool.arguments.options] } : l
585
+ (l) => l.id === i.id ? { ...l, suggestions: n.tool.arguments.options } : l
582
586
  ) : s;
583
587
  });
584
588
  } else n.type === "tool-result" ? (console.log("[Widget] Tool result:", n.result), this.setMessages((o) => {
@@ -590,11 +594,7 @@ Result: ${JSON.stringify(n.result)}`, toolResult: n.result }
590
594
  ] : o;
591
595
  })) : n.type === "agent-start" ? (console.log(`[Widget] Agent started: ${n.agentId}`), this.isAgentStreaming = !0, this.notifyStreamingChange(!0)) : n.type === "handoff" ? console.log(`[Widget] Handoff: ${n.from} -> ${n.to}: ${n.reason}`) : n.type === "suggested-questions" ? (console.log("[Widget] Suggestions received:", n.suggestions), this.setMessages((o) => {
592
596
  const s = [...o].reverse().find((i) => i.role === "assistant");
593
- if (s) {
594
- const i = s.suggestions || [], l = Array.from(/* @__PURE__ */ new Set([...i, ...n.suggestions]));
595
- return o.map((a) => a.id === s.id ? { ...a, suggestions: l } : a);
596
- }
597
- return o;
597
+ return s ? o.map((i) => i.id === s.id ? { ...i, suggestions: n.suggestions } : i) : o;
598
598
  })) : console.log("[Widget] Unknown message type:", n.type);
599
599
  } catch (n) {
600
600
  console.error("[Widget] Error parsing message:", e.data, n);
@@ -745,9 +745,9 @@ function St({
745
745
  mode: s = "chat",
746
746
  theme: i = "light",
747
747
  position: l = "bottom-right",
748
- size: a = "full",
748
+ size: _ = "full",
749
749
  radius: c = "medium",
750
- baseColor: _,
750
+ baseColor: a,
751
751
  accentColor: u = "#14B8A6",
752
752
  buttonBaseColor: r = "#000000",
753
753
  buttonAccentColor: h = "#FFFFFF",
@@ -755,23 +755,23 @@ function St({
755
755
  subtitle: b,
756
756
  emptyChatMessage: S
757
757
  }) {
758
- const [y, p] = T(!1), [f, x] = T([]), [W, H] = T(""), [$, z] = T(!1), [k, P] = T(!1), [I, N] = T(null), [E, Ze] = T(!1), [oe, et] = T(0), V = Me(null), pe = Me(null);
758
+ const [w, p] = T(!1), [f, x] = T([]), [W, H] = T(""), [$, z] = T(!1), [k, P] = T(!1), [I, N] = T(null), [F, Ze] = T(!1), [oe, et] = T(0), V = Me(null), pe = Me(null);
759
759
  Fe(() => ((async () => {
760
760
  if (t && e) {
761
761
  console.log("[AriaFlow Widget] Using new agent resolution:", { agentUrl: t, agentId: e });
762
- const F = new At(t, e);
763
- V.current = F;
762
+ const M = new At(t, e);
763
+ V.current = M;
764
764
  try {
765
- F.onMessages((A) => {
765
+ M.onMessages((A) => {
766
766
  console.log("[AriaFlow Widget] Messages updated:", A.length), x(A);
767
- }), F.onConnectionChange((A) => {
767
+ }), M.onConnectionChange((A) => {
768
768
  console.log("[AriaFlow Widget] Connection state:", A), z(A), A && P(!0);
769
- }), F.onStreamingChange((A) => {
769
+ }), M.onStreamingChange((A) => {
770
770
  console.log("[AriaFlow Widget] Streaming state:", A), Ze(A);
771
- }), F.onQueueChange((A) => {
771
+ }), M.onQueueChange((A) => {
772
772
  console.log("[AriaFlow Widget] Queue count:", A), et(A);
773
773
  });
774
- const D = await F.initWidget();
774
+ const D = await M.initWidget();
775
775
  console.log("[AriaFlow Widget] Agent config received:", D), D ? (N(D), console.log("[AriaFlow Widget] Widget initialized successfully")) : console.error("[AriaFlow Widget] Agent config fetch failed");
776
776
  } catch (D) {
777
777
  console.error("[AriaFlow Widget] Initialization error:", D);
@@ -784,29 +784,29 @@ function St({
784
784
  }, [f]);
785
785
  const me = async () => {
786
786
  if (!W.trim() || !$) return;
787
- const w = W.trim();
787
+ const y = W.trim();
788
788
  H("");
789
789
  try {
790
- await V.current?.sendMessage(w);
791
- } catch (F) {
792
- console.error("Failed to send message:", F);
790
+ await V.current?.sendMessage(y);
791
+ } catch (M) {
792
+ console.error("Failed to send message:", M);
793
793
  }
794
- }, tt = (w) => {
795
- w.key === "Enter" && !w.shiftKey && (w.preventDefault(), me());
796
- }, nt = (w) => {
797
- !$ || E || V.current?.sendMessage(w);
798
- }, ot = d || I?.config.title || "Chat with us", it = b || I?.config.subtitle || "We typically reply within minutes", st = S || I?.config.emptyChatMessage || "Start a conversation...";
799
- return console.log("[AriaFlow Widget] Rendering widget component", { isInitialized: k, isOpen: y, position: l }), /* @__PURE__ */ g(
794
+ }, tt = (y) => {
795
+ y.key === "Enter" && !y.shiftKey && (y.preventDefault(), me());
796
+ }, nt = (y) => {
797
+ !$ || F || V.current?.sendMessage(y);
798
+ }, ot = d || I?.config.title || "Ninewells Hospital", it = b || I?.config.subtitle || "How can we help you today?", st = S || I?.config.emptyChatMessage || "Start a conversation with Ninewells...";
799
+ return console.log("[AriaFlow Widget] Rendering widget component", { isInitialized: k, isOpen: w, position: l }), /* @__PURE__ */ g(
800
800
  "div",
801
801
  {
802
- className: `ariaflow-widget-container ariaflow-widget-${l} ariaflow-widget-${a} ariaflow-widget-radius-${c}`,
802
+ className: `ariaflow-widget-container ariaflow-widget-${l} ariaflow-widget-${_} ariaflow-widget-radius-${c}`,
803
803
  "data-theme": i,
804
804
  style: {
805
805
  "--ariaflow-accent-color": u,
806
- "--ariaflow-base-color": _
806
+ "--ariaflow-base-color": a
807
807
  },
808
808
  children: [
809
- !y && /* @__PURE__ */ g(
809
+ !w && /* @__PURE__ */ g(
810
810
  "button",
811
811
  {
812
812
  className: "ariaflow-widget-launcher",
@@ -855,12 +855,12 @@ function St({
855
855
  ]
856
856
  }
857
857
  ),
858
- y && k && /* @__PURE__ */ g(
858
+ w && k && /* @__PURE__ */ g(
859
859
  "div",
860
860
  {
861
861
  className: "ariaflow-widget-window",
862
862
  style: {
863
- backgroundColor: i === "dark" && _ ? _ : void 0,
863
+ backgroundColor: i === "dark" && a ? a : void 0,
864
864
  borderRadius: re[c]
865
865
  },
866
866
  children: [
@@ -908,39 +908,39 @@ function St({
908
908
  "Connecting..."
909
909
  ] }),
910
910
  /* @__PURE__ */ g("div", { className: "ariaflow-widget-messages", children: f.length === 0 ? /* @__PURE__ */ g("div", { className: "ariaflow-widget-empty", children: /* @__PURE__ */ g("p", { children: $ ? st : "Connecting to agent..." }) }) : /* @__PURE__ */ g(U, { children: [
911
- f.map((w, F) => {
912
- const A = F === f.length - 1 && w.role === "assistant" && !w.isStreaming && w.suggestions && w.suggestions.length > 0;
911
+ f.map((y, M) => {
912
+ const A = M === f.length - 1 && y.role === "assistant" && !F && y.suggestions && y.suggestions.length > 0;
913
913
  return /* @__PURE__ */ g(
914
914
  "div",
915
915
  {
916
- className: `ariaflow-widget-message ariaflow-widget-message-${w.role}`,
916
+ className: `ariaflow-widget-message ariaflow-widget-message-${y.role}`,
917
917
  children: [
918
- /* @__PURE__ */ g("div", { className: "ariaflow-widget-message-bubble", children: w.role === "tool" ? /* @__PURE__ */ g("div", { className: "ariaflow-widget-tool-message", children: [
918
+ /* @__PURE__ */ g("div", { className: "ariaflow-widget-message-bubble", children: y.role === "tool" ? /* @__PURE__ */ g("div", { className: "ariaflow-widget-tool-message", children: [
919
919
  /* @__PURE__ */ g("div", { className: "ariaflow-widget-tool-header", children: [
920
920
  "🔧 ",
921
- w.toolCall?.name
921
+ y.toolCall?.name
922
922
  ] }),
923
923
  /* @__PURE__ */ g("div", { className: "ariaflow-widget-tool-content", children: [
924
- w.toolCall && /* @__PURE__ */ g("div", { className: "ariaflow-widget-tool-args", children: [
924
+ y.toolCall && /* @__PURE__ */ g("div", { className: "ariaflow-widget-tool-args", children: [
925
925
  /* @__PURE__ */ g("strong", { children: "Arguments:" }),
926
926
  " ",
927
- JSON.stringify(w.toolCall.arguments, null, 2)
927
+ JSON.stringify(y.toolCall.arguments, null, 2)
928
928
  ] }),
929
- w.toolResult && /* @__PURE__ */ g("div", { className: "ariaflow-widget-tool-result", children: [
929
+ y.toolResult && /* @__PURE__ */ g("div", { className: "ariaflow-widget-tool-result", children: [
930
930
  /* @__PURE__ */ g("strong", { children: "Result:" }),
931
931
  " ",
932
- JSON.stringify(w.toolResult, null, 2)
932
+ JSON.stringify(y.toolResult, null, 2)
933
933
  ] })
934
934
  ] })
935
935
  ] }) : /* @__PURE__ */ g(U, { children: [
936
- w.content,
937
- w.isStreaming && /* @__PURE__ */ g("span", { className: "ariaflow-widget-typing-indicator", children: [
936
+ y.content,
937
+ y.isStreaming && /* @__PURE__ */ g("span", { className: "ariaflow-widget-typing-indicator", children: [
938
938
  /* @__PURE__ */ g("span", { children: "•" }),
939
939
  /* @__PURE__ */ g("span", { children: "•" }),
940
940
  /* @__PURE__ */ g("span", { children: "•" })
941
941
  ] })
942
942
  ] }) }),
943
- A && /* @__PURE__ */ g("div", { className: "ariaflow-widget-chips-container", children: w.suggestions?.map((ie) => /* @__PURE__ */ g(
943
+ A && /* @__PURE__ */ g("div", { className: "ariaflow-widget-chips-container", children: y.suggestions?.map((ie) => /* @__PURE__ */ g(
944
944
  "button",
945
945
  {
946
946
  className: "ariaflow-widget-chip",
@@ -955,7 +955,7 @@ function St({
955
955
  )) })
956
956
  ]
957
957
  },
958
- w.id
958
+ y.id
959
959
  );
960
960
  }),
961
961
  /* @__PURE__ */ g("div", { ref: pe })
@@ -965,9 +965,9 @@ function St({
965
965
  "textarea",
966
966
  {
967
967
  value: W,
968
- onInput: (w) => H(w.target.value),
968
+ onInput: (y) => H(y.target.value),
969
969
  onKeyDown: tt,
970
- placeholder: $ ? E ? oe > 0 ? `Agent is responding... (${oe} message${oe > 1 ? "s" : ""} queued)` : "Agent is responding..." : "Type your message..." : "Connecting...",
970
+ placeholder: $ ? F ? oe > 0 ? `Agent is responding... (${oe} message${oe > 1 ? "s" : ""} queued)` : "Agent is responding..." : "Type your message..." : "Connecting...",
971
971
  rows: 1,
972
972
  disabled: !$
973
973
  }
@@ -1,4 +1,4 @@
1
- (function(P,E){typeof exports=="object"&&typeof module<"u"?E(exports):typeof define=="function"&&define.amd?define(["exports"],E):(P=typeof globalThis<"u"?globalThis:P||self,E(P.AriaFlowWidget={}))})(this,function(P){"use strict";var E,m,me,I,ye,we,ve,be,ie,se,re,j={},Ce=[],nt=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,V=Array.isArray;function x(t,e){for(var n in e)t[n]=e[n];return t}function le(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function L(t,e,n){var o,s,i,l={};for(i in e)i=="key"?o=e[i]:i=="ref"?s=e[i]:l[i]=e[i];if(arguments.length>2&&(l.children=arguments.length>3?E.call(arguments,2):n),typeof t=="function"&&t.defaultProps!=null)for(i in t.defaultProps)l[i]===void 0&&(l[i]=t.defaultProps[i]);return B(t,l,o,s,null)}function B(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??++me,__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 ke(t){var e,n;if((t=t.__)!=null&&t.__c!=null){for(t.__e=t.__c.base=null,e=0;e<t.__k.length;e++)if((n=t.__k[e])!=null&&n.__e!=null){t.__e=t.__c.base=n.__e;break}return ke(t)}}function Ae(t){(!t.__d&&(t.__d=!0)&&I.push(t)&&!K.__r++||ye!=m.debounceRendering)&&((ye=m.debounceRendering)||we)(K)}function K(){for(var t,e,n,o,s,i,l,a=1;I.length;)I.length>a&&I.sort(ve),t=I.shift(),a=I.length,t.__d&&(n=void 0,o=void 0,s=(o=(e=t).__v).__e,i=[],l=[],e.__P&&((n=x({},o)).__v=o.__v+1,m.vnode&&m.vnode(n),ae(e.__P,n,o,e.__n,e.__P.namespaceURI,32&o.__u?[s]:null,i,s??Q(o),!!(32&o.__u),l),n.__v=o.__v,n.__.__k[n.__i]=n,xe(i,n,l),o.__e=o.__=null,n.__e!=s&&ke(n)));K.__r=0}function Se(t,e,n,o,s,i,l,a,c,_,u){var r,h,d,C,S,v,p,f=o&&o.__k||Ce,F=e.length;for(c=ot(n,e,f,c,F),r=0;r<F;r++)(d=n.__k[r])!=null&&(h=d.__i==-1?j:f[d.__i]||j,d.__i=r,v=ae(t,d,h,s,i,l,a,c,_,u),C=d.__e,d.ref&&h.ref!=d.ref&&(h.ref&&ce(h.ref,null,d),u.push(d.ref,d.__c||C,d)),S==null&&C!=null&&(S=C),(p=!!(4&d.__u))||h.__k===d.__k?c=$e(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 ot(t,e,n,o,s){var i,l,a,c,_,u=n.length,r=u,h=0;for(t.__k=new Array(s),i=0;i<s;i++)(l=e[i])!=null&&typeof l!="boolean"&&typeof l!="function"?(typeof l=="string"||typeof l=="number"||typeof l=="bigint"||l.constructor==String?l=t.__k[i]=B(null,l,null,null,null):V(l)?l=t.__k[i]=B(R,{children:l},null,null,null):l.constructor===void 0&&l.__b>0?l=t.__k[i]=B(l.type,l.props,l.key,l.ref?l.ref:null,l.__v):t.__k[i]=l,c=i+h,l.__=t,l.__b=t.__b+1,a=null,(_=l.__i=it(l,n,c,r))!=-1&&(r--,(a=n[_])&&(a.__u|=2)),a==null||a.__v==null?(_==-1&&(s>u?h--:s<u&&h++),typeof l.type!="function"&&(l.__u|=4)):_!=c&&(_==c-1?h--:_==c+1?h++:(_>c?h--:h++,l.__u|=4))):t.__k[i]=null;if(r)for(i=0;i<u;i++)(a=n[i])!=null&&!(2&a.__u)&&(a.__e==o&&(o=Q(a)),Me(a,a));return o}function $e(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=$e(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 it(t,e,n,o){var s,i,l,a=t.key,c=t.type,_=e[n],u=_!=null&&(2&_.__u)==0;if(_===null&&a==null||u&&a==_.key&&c==_.type)return n;if(o>(u?1:0)){for(s=n-1,i=n+1;s>=0||i<e.length;)if((_=e[l=s>=0?s--:i++])!=null&&!(2&_.__u)&&a==_.key&&c==_.type)return l}return-1}function We(t,e,n){e[0]=="-"?t.setProperty(e,n??""):t[e]=n==null?"":typeof n!="number"||nt.test(e)?n:n+"px"}function G(t,e,n,o,s){var i,l;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||We(t.style,e,"");if(n)for(e in n)o&&n[e]==o[e]||We(t.style,e,n[e])}else if(e[0]=="o"&&e[1]=="n")i=e!=(e=e.replace(be,"$1")),l=e.toLowerCase(),e=l in t||e=="onFocusOut"||e=="onFocusIn"?l.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 Ne(t){return function(e){if(this.l){var n=this.l[e.type+t];if(e.t==null)e.t=ie++;else if(e.t<n.u)return;return n(m.event?m.event(e):e)}}}function ae(t,e,n,o,s,i,l,a,c,_){var u,r,h,d,C,S,v,p,f,F,W,U,$,ne,k,D,O,N=e.type;if(e.constructor!==void 0)return null;128&n.__u&&(c=!!(32&n.__u),i=[a=e.__e=n.__e]),(u=m.__b)&&u(e);e:if(typeof N=="function")try{if(p=e.props,f="prototype"in N&&N.prototype.render,F=(u=N.contextType)&&o[u.__c],W=u?F?F.props.value:u.__:o,n.__c?v=(r=e.__c=n.__c).__=r.__E:(f?e.__c=r=new N(p,W):(e.__c=r=new J(p,W),r.constructor=N,r.render=rt),F&&F.sub(r),r.state||(r.state={}),r.__n=o,h=r.__d=!0,r.__h=[],r._sb=[]),f&&r.__s==null&&(r.__s=r.state),f&&N.getDerivedStateFromProps!=null&&(r.__s==r.state&&(r.__s=x({},r.__s)),x(r.__s,N.getDerivedStateFromProps(p,r.__s))),d=r.props,C=r.state,r.__v=e,h)f&&N.getDerivedStateFromProps==null&&r.componentWillMount!=null&&r.componentWillMount(),f&&r.componentDidMount!=null&&r.__h.push(r.componentDidMount);else{if(f&&N.getDerivedStateFromProps==null&&p!==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(T){T&&(T.__=e)}),U=0;U<r._sb.length;U++)r.__h.push(r._sb[U]);r._sb=[],r.__h.length&&l.push(r);break e}r.componentWillUpdate!=null&&r.componentWillUpdate(p,r.__s,W),f&&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,f){for(r.state=r.__s,r.__d=!1,$&&$(e),u=r.render(r.props,r.state,r.context),k=0;k<r._sb.length;k++)r.__h.push(r._sb[k]);r._sb=[]}else do r.__d=!1,$&&$(e),u=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=x(x({},o),r.getChildContext())),f&&!h&&r.getSnapshotBeforeUpdate!=null&&(S=r.getSnapshotBeforeUpdate(d,C)),D=u,u!=null&&u.type===R&&u.key==null&&(D=Fe(u.props.children)),a=Se(t,V(D)?D:[D],e,n,o,s,i,l,a,c,_),r.base=e.__e,e.__u&=-161,r.__h.length&&l.push(r),v&&(r.__E=r.__=null)}catch(T){if(e.__v=null,c||i!=null)if(T.then){for(e.__u|=c?160:128;a&&a.nodeType==8&&a.nextSibling;)a=a.nextSibling;i[i.indexOf(a)]=null,e.__e=a}else{for(O=i.length;O--;)le(i[O]);_e(e)}else e.__e=n.__e,e.__k=n.__k,T.then||_e(e);m.__e(T,e,n)}else i==null&&e.__v==n.__v?(e.__k=n.__k,e.__e=n.__e):a=e.__e=st(n.__e,e,n,o,s,i,l,c,_);return(u=m.diffed)&&u(e),128&e.__u?void 0:a}function _e(t){t&&t.__c&&(t.__c.__e=!0),t&&t.__k&&t.__k.forEach(_e)}function xe(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 Fe(t){return typeof t!="object"||t==null||t.__b&&t.__b>0?t:V(t)?t.map(Fe):x({},t)}function st(t,e,n,o,s,i,l,a,c){var _,u,r,h,d,C,S,v=n.props||j,p=e.props,f=e.type;if(f=="svg"?s="http://www.w3.org/2000/svg":f=="math"?s="http://www.w3.org/1998/Math/MathML":s||(s="http://www.w3.org/1999/xhtml"),i!=null){for(_=0;_<i.length;_++)if((d=i[_])&&"setAttribute"in d==!!f&&(f?d.localName==f:d.nodeType==3)){t=d,i[_]=null;break}}if(t==null){if(f==null)return document.createTextNode(p);t=document.createElementNS(s,f,p.is&&p),a&&(m.__m&&m.__m(e,i),a=!1),i=null}if(f==null)v===p||a&&t.data==p||(t.data=p);else{if(i=i&&E.call(t.childNodes),!a&&i!=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"?h=d:_=="dangerouslySetInnerHTML"?u=d:_=="value"?C=d:_=="checked"?S=d:a&&typeof d!="function"||v[_]===d||G(t,_,d,v[_],s);if(u)a||r&&(u.__html==r.__html||u.__html==t.innerHTML)||(t.innerHTML=u.__html),e.__k=[];else if(r&&(t.innerHTML=""),Se(e.type=="template"?t.content:t,V(h)?h:[h],e,n,o,f=="foreignObject"?"http://www.w3.org/1999/xhtml":s,i,l,i?i[0]:n.__k&&Q(n,0),a,c),i!=null)for(_=i.length;_--;)le(i[_]);a||(_="value",f=="progress"&&C==null?t.removeAttribute("value"):C!=null&&(C!==t[_]||f=="progress"&&!C||f=="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 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 Me(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]&&Me(o[s],e,n||typeof t.type!="function");n||le(t.__e),t.__c=t.__=t.__e=void 0}function rt(t,e,n){return this.constructor(t,n)}function X(t,e,n){var o,s,i,l;e==document&&(e=document.documentElement),m.__&&m.__(t,e),s=(o=typeof n=="function")?null:n&&n.__k||e.__k,i=[],l=[],ae(e,t=(!o&&n||e).__k=L(R,null,[t]),s||j,j,e.namespaceURI,!o&&n?[n]:s?null:e.firstChild?E.call(e.childNodes):null,i,!o&&n?n:s?s.__e:e.firstChild,o,l),xe(i,t,l)}function Ee(t,e){X(t,e,Ee)}function Te(t,e,n){var o,s,i,l,a=x({},t.props);for(i in t.type&&t.type.defaultProps&&(l=t.type.defaultProps),e)i=="key"?o=e[i]:i=="ref"?s=e[i]:a[i]=e[i]===void 0&&l!=null?l[i]:e[i];return arguments.length>2&&(a.children=arguments.length>3?E.call(arguments,2):n),B(t.type,a,o||t.key,s||t.ref,null)}E=Ce.slice,m={__e:function(t,e,n,o){for(var s,i,l;e=e.__;)if((s=e.__c)&&!s.__)try{if((i=s.constructor)&&i.getDerivedStateFromError!=null&&(s.setState(i.getDerivedStateFromError(t)),l=s.__d),s.componentDidCatch!=null&&(s.componentDidCatch(t,o||{}),l=s.__d),l)return s.__E=s}catch(a){t=a}throw t}},me=0,J.prototype.setState=function(t,e){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=x({},this.state),typeof t=="function"&&(t=t(x({},n),this.props)),t&&x(n,t),t!=null&&this.__v&&(e&&this._sb.push(e),Ae(this))},J.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),Ae(this))},J.prototype.render=R,I=[],we=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,ve=function(t,e){return t.__v.__b-e.__v.__b},K.__r=0,be=/(PointerCapture)$|Capture$/i,ie=0,se=Ne(!1),re=Ne(!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 He(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 lt=["context","children"],at=["useFragment"];function _t(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(){ut.call(this,o)},s.prototype.attributeChangedCallback=dt,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(l){this._vdom?this.attributeChangedCallback(i,null,l):(this._props||(this._props={}),this._props[i]=l);var a=typeof l;l!=null&&a!=="string"&&a!=="boolean"&&a!=="number"||this.setAttribute(i,l)}})}),customElements.define(e,s),s}function ct(t){this.getChildContext=function(){return t.context};var e=t.children,n=He(t,lt);return Te(e,n)}function ut(t){var e=new CustomEvent("_preact",{detail:{},bubbles:!0,cancelable:!0});this.dispatchEvent(e),this._vdom=L(ct,Y({},this._props,{context:e.detail.context}),Re(this,this._vdomComponent,t)),(this.hasAttribute("hydrate")?Ee:X)(this._vdom,this._root)}function Pe(t){return t.replace(/-(\w)/g,function(e,n){return n?n.toUpperCase():""})}function dt(t,e,n){if(this._vdom){var o={};o[t]=n=n??void 0,o[Pe(t)]=n,this._vdom=Te(this._vdom,o),X(this._vdom,this._root)}}function gt(){X(this._vdom=null,this._root)}function Ie(t,e){var n=this,o=t.useFragment,s=He(t,at);return L(o?R:"slot",Y({},s,{ref:function(i){i?(n.ref=i,n._listener||(n._listener=function(l){l.stopPropagation(),l.detail.context=e},i.addEventListener("_preact",n._listener))):n.ref.removeEventListener("_preact",n._listener)}}))}function Re(t,e,n){if(t.nodeType===3)return t.data;if(t.nodeType!==1)return null;var o=[],s={},i=0,l=t.attributes,a=t.childNodes;for(i=l.length;i--;)l[i].name!=="slot"&&(s[l[i].name]=l[i].value,s[Pe(l[i].name)]=l[i].value);for(i=a.length;i--;){var c=Re(a[i],null,n),_=a[i].slot;_?s[_]=L(Ie,{name:_},c):o[i]=c}var u=!(!n||!n.shadow),r=e?L(Ie,{useFragment:!u},o):o;return!u&&e&&(t.innerHTML=""),L(e||t.nodeName.toLowerCase(),s,r)}var ht=0;function g(t,e,n,o,s,i){e||(e={});var l,a,c=e;if("ref"in c)for(a in c={},e)a=="ref"?l=e[a]:c[a]=e[a];var _={type:t,props:c,key:n,ref:l,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--ht,__i:-1,__u:0,__source:s,__self:i};if(typeof t=="function"&&(l=t.defaultProps))for(a in l)c[a]===void 0&&(c[a]=l[a]);return m.vnode&&m.vnode(_),_}var z,w,ue,Ue,Z=0,De=[],b=m,Oe=b.__b,Le=b.__r,Qe=b.diffed,qe=b.__c,je=b.unmount,Be=b.__;function de(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 H(t){return Z=1,ft(Ge,t)}function ft(t,e,n){var o=de(z++,2);if(o.t=t,!o.__c&&(o.__=[Ge(void 0,e),function(a){var c=o.__N?o.__N[0]:o.__[0],_=o.t(c,a);c!==_&&(o.__N=[_,o.__[1]],o.__c.setState({}))}],o.__c=w,!w.__f)){var s=function(a,c,_){if(!o.__c.__H)return!0;var u=o.__c.__H.__.filter(function(h){return!!h.__c});if(u.every(function(h){return!h.__N}))return!i||i.call(this,a,c,_);var r=o.__c.props!==a;return u.forEach(function(h){if(h.__N){var d=h.__[0];h.__=h.__N,h.__N=void 0,d!==h.__[0]&&(r=!0)}}),i&&i.call(this,a,c,_)||r};w.__f=!0;var i=w.shouldComponentUpdate,l=w.componentWillUpdate;w.componentWillUpdate=function(a,c,_){if(this.__e){var u=i;i=void 0,s(a,c,_),i=u}l&&l.call(this,a,c,_)},w.shouldComponentUpdate=s}return o.__N||o.__}function ze(t,e){var n=de(z++,3);!b.__s&&Ke(n.__H,e)&&(n.__=t,n.u=e,w.__H.__h.push(n))}function Ve(t){return Z=5,pt(function(){return{current:t}},[])}function pt(t,e){var n=de(z++,7);return Ke(n.__H,e)&&(n.__=t(),n.__H=e,n.__h=t),n.__}function mt(){for(var t;t=De.shift();)if(t.__P&&t.__H)try{t.__H.__h.forEach(ee),t.__H.__h.forEach(ge),t.__H.__h=[]}catch(e){t.__H.__h=[],b.__e(e,t.__v)}}b.__b=function(t){w=null,Oe&&Oe(t)},b.__=function(t,e){t&&e.__k&&e.__k.__m&&(t.__m=e.__k.__m),Be&&Be(t,e)},b.__r=function(t){Le&&Le(t),z=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(ge),e.__h=[],z=0)),ue=w},b.diffed=function(t){Qe&&Qe(t);var e=t.__c;e&&e.__H&&(e.__H.__h.length&&(De.push(e)!==1&&Ue===b.requestAnimationFrame||((Ue=b.requestAnimationFrame)||yt)(mt)),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.__||ge(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){je&&je(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 Je=typeof requestAnimationFrame=="function";function yt(t){var e,n=function(){clearTimeout(o),Je&&cancelAnimationFrame(e),setTimeout(t)},o=setTimeout(n,35);Je&&(e=requestAnimationFrame(n))}function ee(t){var e=w,n=t.__c;typeof n=="function"&&(t.__c=void 0,n()),w=e}function ge(t){var e=w;t.__c=t.__(),w=e}function Ke(t,e){return!t||t.length!==e.length||e.some(function(n,o){return n!==t[o]})}function Ge(t,e){return typeof e=="function"?e(t):e}const wt="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let te=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t|=0));for(;t--;)e+=wt[n[t]&63];return e};class Xe{constructor(e,n){this.agentUrl=e,this.agentId=n,this.agentConfig=null,this.ws=null,this.messageCallbacks=new Set,this.connectionCallbacks=new Set,this.streamingCallbacks=new Set,this.queueCallbacks=new Set,this.messages=[],this.reconnectAttempts=0,this.maxReconnectAttempts=5,this.reconnectDelay=1e3,this.isAgentStreaming=!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)}})}handleMessage(e){try{const n=JSON.parse(e.data);if(n.type==="text-delta")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.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==="tool-call"){console.log("[Widget] Tool call:",n.tool);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(l=>l.role==="assistant");return i?s.map(l=>l.id===i.id?{...l,suggestions:[...l.suggestions||[],...n.tool.arguments.options]}:l):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}]:o})):n.type==="agent-start"?(console.log(`[Widget] Agent started: ${n.agentId}`),this.isAgentStreaming=!0,this.notifyStreamingChange(!0)):n.type==="handoff"?console.log(`[Widget] Handoff: ${n.from} -> ${n.to}: ${n.reason}`):n.type==="suggested-questions"?(console.log("[Widget] Suggestions received:",n.suggestions),this.setMessages(o=>{const s=[...o].reverse().find(i=>i.role==="assistant");if(s){const i=s.suggestions||[],l=Array.from(new Set([...i,...n.suggestions]));return o.map(a=>a.id===s.id?{...a,suggestions:l}:a)}return o})):console.log("[Widget] Unknown message type:",n.type)}catch(n){console.error("[Widget] Error parsing message:",e.data,n)}}async sendMessage(e){if(!this.ws||this.ws.readyState!==WebSocket.OPEN)throw new Error("Not connected to agent");const n={id:te(),role:"user",content:e,timestamp:Date.now()};if(this.setMessages(o=>[...o,n]),this.isAgentStreaming){console.log("[Widget] Agent is streaming, queuing message"),this.messageQueue.push(e),this.notifyQueueChange(this.messageQueue.length);return}this.sendToAgent(e)}async sendToAgent(e){const n=this.getSessionId();this.ws.send(JSON.stringify({message:e,sessionId:n}))}async processMessageQueue(){if(this.messageQueue.length!==0){if(this.messageQueue.length===1){const e=this.messageQueue.shift();console.log("[Widget] Sending queued message:",e),this.sendToAgent(e)}else{const e=this.messageQueue.join(`
1
+ (function(P,T){typeof exports=="object"&&typeof module<"u"?T(exports):typeof define=="function"&&define.amd?define(["exports"],T):(P=typeof globalThis<"u"?globalThis:P||self,T(P.AriaFlowWidget={}))})(this,function(P){"use strict";var T,m,me,I,ye,we,ve,be,ie,se,re,j={},Ce=[],nt=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,V=Array.isArray;function x(t,e){for(var n in e)t[n]=e[n];return t}function le(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function L(t,e,n){var o,s,i,l={};for(i in e)i=="key"?o=e[i]:i=="ref"?s=e[i]:l[i]=e[i];if(arguments.length>2&&(l.children=arguments.length>3?T.call(arguments,2):n),typeof t=="function"&&t.defaultProps!=null)for(i in t.defaultProps)l[i]===void 0&&(l[i]=t.defaultProps[i]);return B(t,l,o,s,null)}function B(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??++me,__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 ke(t){var e,n;if((t=t.__)!=null&&t.__c!=null){for(t.__e=t.__c.base=null,e=0;e<t.__k.length;e++)if((n=t.__k[e])!=null&&n.__e!=null){t.__e=t.__c.base=n.__e;break}return ke(t)}}function Ae(t){(!t.__d&&(t.__d=!0)&&I.push(t)&&!K.__r++||ye!=m.debounceRendering)&&((ye=m.debounceRendering)||we)(K)}function K(){for(var t,e,n,o,s,i,l,_=1;I.length;)I.length>_&&I.sort(ve),t=I.shift(),_=I.length,t.__d&&(n=void 0,o=void 0,s=(o=(e=t).__v).__e,i=[],l=[],e.__P&&((n=x({},o)).__v=o.__v+1,m.vnode&&m.vnode(n),ae(e.__P,n,o,e.__n,e.__P.namespaceURI,32&o.__u?[s]:null,i,s??Q(o),!!(32&o.__u),l),n.__v=o.__v,n.__.__k[n.__i]=n,xe(i,n,l),o.__e=o.__=null,n.__e!=s&&ke(n)));K.__r=0}function Se(t,e,n,o,s,i,l,_,c,a,u){var r,h,d,C,S,v,p,f=o&&o.__k||Ce,F=e.length;for(c=ot(n,e,f,c,F),r=0;r<F;r++)(d=n.__k[r])!=null&&(h=d.__i==-1?j:f[d.__i]||j,d.__i=r,v=ae(t,d,h,s,i,l,_,c,a,u),C=d.__e,d.ref&&h.ref!=d.ref&&(h.ref&&ce(h.ref,null,d),u.push(d.ref,d.__c||C,d)),S==null&&C!=null&&(S=C),(p=!!(4&d.__u))||h.__k===d.__k?c=$e(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 ot(t,e,n,o,s){var i,l,_,c,a,u=n.length,r=u,h=0;for(t.__k=new Array(s),i=0;i<s;i++)(l=e[i])!=null&&typeof l!="boolean"&&typeof l!="function"?(typeof l=="string"||typeof l=="number"||typeof l=="bigint"||l.constructor==String?l=t.__k[i]=B(null,l,null,null,null):V(l)?l=t.__k[i]=B(R,{children:l},null,null,null):l.constructor===void 0&&l.__b>0?l=t.__k[i]=B(l.type,l.props,l.key,l.ref?l.ref:null,l.__v):t.__k[i]=l,c=i+h,l.__=t,l.__b=t.__b+1,_=null,(a=l.__i=it(l,n,c,r))!=-1&&(r--,(_=n[a])&&(_.__u|=2)),_==null||_.__v==null?(a==-1&&(s>u?h--:s<u&&h++),typeof l.type!="function"&&(l.__u|=4)):a!=c&&(a==c-1?h--:a==c+1?h++:(a>c?h--:h++,l.__u|=4))):t.__k[i]=null;if(r)for(i=0;i<u;i++)(_=n[i])!=null&&!(2&_.__u)&&(_.__e==o&&(o=Q(_)),Me(_,_));return o}function $e(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=$e(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 it(t,e,n,o){var s,i,l,_=t.key,c=t.type,a=e[n],u=a!=null&&(2&a.__u)==0;if(a===null&&_==null||u&&_==a.key&&c==a.type)return n;if(o>(u?1:0)){for(s=n-1,i=n+1;s>=0||i<e.length;)if((a=e[l=s>=0?s--:i++])!=null&&!(2&a.__u)&&_==a.key&&c==a.type)return l}return-1}function We(t,e,n){e[0]=="-"?t.setProperty(e,n??""):t[e]=n==null?"":typeof n!="number"||nt.test(e)?n:n+"px"}function G(t,e,n,o,s){var i,l;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||We(t.style,e,"");if(n)for(e in n)o&&n[e]==o[e]||We(t.style,e,n[e])}else if(e[0]=="o"&&e[1]=="n")i=e!=(e=e.replace(be,"$1")),l=e.toLowerCase(),e=l in t||e=="onFocusOut"||e=="onFocusIn"?l.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 Ne(t){return function(e){if(this.l){var n=this.l[e.type+t];if(e.t==null)e.t=ie++;else if(e.t<n.u)return;return n(m.event?m.event(e):e)}}}function ae(t,e,n,o,s,i,l,_,c,a){var u,r,h,d,C,S,v,p,f,F,W,U,$,ne,k,D,O,N=e.type;if(e.constructor!==void 0)return null;128&n.__u&&(c=!!(32&n.__u),i=[_=e.__e=n.__e]),(u=m.__b)&&u(e);e:if(typeof N=="function")try{if(p=e.props,f="prototype"in N&&N.prototype.render,F=(u=N.contextType)&&o[u.__c],W=u?F?F.props.value:u.__:o,n.__c?v=(r=e.__c=n.__c).__=r.__E:(f?e.__c=r=new N(p,W):(e.__c=r=new J(p,W),r.constructor=N,r.render=rt),F&&F.sub(r),r.state||(r.state={}),r.__n=o,h=r.__d=!0,r.__h=[],r._sb=[]),f&&r.__s==null&&(r.__s=r.state),f&&N.getDerivedStateFromProps!=null&&(r.__s==r.state&&(r.__s=x({},r.__s)),x(r.__s,N.getDerivedStateFromProps(p,r.__s))),d=r.props,C=r.state,r.__v=e,h)f&&N.getDerivedStateFromProps==null&&r.componentWillMount!=null&&r.componentWillMount(),f&&r.componentDidMount!=null&&r.__h.push(r.componentDidMount);else{if(f&&N.getDerivedStateFromProps==null&&p!==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(M){M&&(M.__=e)}),U=0;U<r._sb.length;U++)r.__h.push(r._sb[U]);r._sb=[],r.__h.length&&l.push(r);break e}r.componentWillUpdate!=null&&r.componentWillUpdate(p,r.__s,W),f&&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,f){for(r.state=r.__s,r.__d=!1,$&&$(e),u=r.render(r.props,r.state,r.context),k=0;k<r._sb.length;k++)r.__h.push(r._sb[k]);r._sb=[]}else do r.__d=!1,$&&$(e),u=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=x(x({},o),r.getChildContext())),f&&!h&&r.getSnapshotBeforeUpdate!=null&&(S=r.getSnapshotBeforeUpdate(d,C)),D=u,u!=null&&u.type===R&&u.key==null&&(D=Fe(u.props.children)),_=Se(t,V(D)?D:[D],e,n,o,s,i,l,_,c,a),r.base=e.__e,e.__u&=-161,r.__h.length&&l.push(r),v&&(r.__E=r.__=null)}catch(M){if(e.__v=null,c||i!=null)if(M.then){for(e.__u|=c?160:128;_&&_.nodeType==8&&_.nextSibling;)_=_.nextSibling;i[i.indexOf(_)]=null,e.__e=_}else{for(O=i.length;O--;)le(i[O]);_e(e)}else e.__e=n.__e,e.__k=n.__k,M.then||_e(e);m.__e(M,e,n)}else i==null&&e.__v==n.__v?(e.__k=n.__k,e.__e=n.__e):_=e.__e=st(n.__e,e,n,o,s,i,l,c,a);return(u=m.diffed)&&u(e),128&e.__u?void 0:_}function _e(t){t&&t.__c&&(t.__c.__e=!0),t&&t.__k&&t.__k.forEach(_e)}function xe(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 Fe(t){return typeof t!="object"||t==null||t.__b&&t.__b>0?t:V(t)?t.map(Fe):x({},t)}function st(t,e,n,o,s,i,l,_,c){var a,u,r,h,d,C,S,v=n.props||j,p=e.props,f=e.type;if(f=="svg"?s="http://www.w3.org/2000/svg":f=="math"?s="http://www.w3.org/1998/Math/MathML":s||(s="http://www.w3.org/1999/xhtml"),i!=null){for(a=0;a<i.length;a++)if((d=i[a])&&"setAttribute"in d==!!f&&(f?d.localName==f:d.nodeType==3)){t=d,i[a]=null;break}}if(t==null){if(f==null)return document.createTextNode(p);t=document.createElementNS(s,f,p.is&&p),_&&(m.__m&&m.__m(e,i),_=!1),i=null}if(f==null)v===p||_&&t.data==p||(t.data=p);else{if(i=i&&T.call(t.childNodes),!_&&i!=null)for(v={},a=0;a<t.attributes.length;a++)v[(d=t.attributes[a]).name]=d.value;for(a in v)if(d=v[a],a!="children"){if(a=="dangerouslySetInnerHTML")r=d;else if(!(a in p)){if(a=="value"&&"defaultValue"in p||a=="checked"&&"defaultChecked"in p)continue;G(t,a,null,d,s)}}for(a in p)d=p[a],a=="children"?h=d:a=="dangerouslySetInnerHTML"?u=d:a=="value"?C=d:a=="checked"?S=d:_&&typeof d!="function"||v[a]===d||G(t,a,d,v[a],s);if(u)_||r&&(u.__html==r.__html||u.__html==t.innerHTML)||(t.innerHTML=u.__html),e.__k=[];else if(r&&(t.innerHTML=""),Se(e.type=="template"?t.content:t,V(h)?h:[h],e,n,o,f=="foreignObject"?"http://www.w3.org/1999/xhtml":s,i,l,i?i[0]:n.__k&&Q(n,0),_,c),i!=null)for(a=i.length;a--;)le(i[a]);_||(a="value",f=="progress"&&C==null?t.removeAttribute("value"):C!=null&&(C!==t[a]||f=="progress"&&!C||f=="option"&&C!=v[a])&&G(t,a,C,v[a],s),a="checked",S!=null&&S!=t[a]&&G(t,a,S,v[a],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 Me(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]&&Me(o[s],e,n||typeof t.type!="function");n||le(t.__e),t.__c=t.__=t.__e=void 0}function rt(t,e,n){return this.constructor(t,n)}function X(t,e,n){var o,s,i,l;e==document&&(e=document.documentElement),m.__&&m.__(t,e),s=(o=typeof n=="function")?null:n&&n.__k||e.__k,i=[],l=[],ae(e,t=(!o&&n||e).__k=L(R,null,[t]),s||j,j,e.namespaceURI,!o&&n?[n]:s?null:e.firstChild?T.call(e.childNodes):null,i,!o&&n?n:s?s.__e:e.firstChild,o,l),xe(i,t,l)}function Ee(t,e){X(t,e,Ee)}function Te(t,e,n){var o,s,i,l,_=x({},t.props);for(i in t.type&&t.type.defaultProps&&(l=t.type.defaultProps),e)i=="key"?o=e[i]:i=="ref"?s=e[i]:_[i]=e[i]===void 0&&l!=null?l[i]:e[i];return arguments.length>2&&(_.children=arguments.length>3?T.call(arguments,2):n),B(t.type,_,o||t.key,s||t.ref,null)}T=Ce.slice,m={__e:function(t,e,n,o){for(var s,i,l;e=e.__;)if((s=e.__c)&&!s.__)try{if((i=s.constructor)&&i.getDerivedStateFromError!=null&&(s.setState(i.getDerivedStateFromError(t)),l=s.__d),s.componentDidCatch!=null&&(s.componentDidCatch(t,o||{}),l=s.__d),l)return s.__E=s}catch(_){t=_}throw t}},me=0,J.prototype.setState=function(t,e){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=x({},this.state),typeof t=="function"&&(t=t(x({},n),this.props)),t&&x(n,t),t!=null&&this.__v&&(e&&this._sb.push(e),Ae(this))},J.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),Ae(this))},J.prototype.render=R,I=[],we=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,ve=function(t,e){return t.__v.__b-e.__v.__b},K.__r=0,be=/(PointerCapture)$|Capture$/i,ie=0,se=Ne(!1),re=Ne(!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 He(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 lt=["context","children"],at=["useFragment"];function _t(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(){ut.call(this,o)},s.prototype.attributeChangedCallback=dt,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(l){this._vdom?this.attributeChangedCallback(i,null,l):(this._props||(this._props={}),this._props[i]=l);var _=typeof l;l!=null&&_!=="string"&&_!=="boolean"&&_!=="number"||this.setAttribute(i,l)}})}),customElements.define(e,s),s}function ct(t){this.getChildContext=function(){return t.context};var e=t.children,n=He(t,lt);return Te(e,n)}function ut(t){var e=new CustomEvent("_preact",{detail:{},bubbles:!0,cancelable:!0});this.dispatchEvent(e),this._vdom=L(ct,Y({},this._props,{context:e.detail.context}),Re(this,this._vdomComponent,t)),(this.hasAttribute("hydrate")?Ee:X)(this._vdom,this._root)}function Pe(t){return t.replace(/-(\w)/g,function(e,n){return n?n.toUpperCase():""})}function dt(t,e,n){if(this._vdom){var o={};o[t]=n=n??void 0,o[Pe(t)]=n,this._vdom=Te(this._vdom,o),X(this._vdom,this._root)}}function gt(){X(this._vdom=null,this._root)}function Ie(t,e){var n=this,o=t.useFragment,s=He(t,at);return L(o?R:"slot",Y({},s,{ref:function(i){i?(n.ref=i,n._listener||(n._listener=function(l){l.stopPropagation(),l.detail.context=e},i.addEventListener("_preact",n._listener))):n.ref.removeEventListener("_preact",n._listener)}}))}function Re(t,e,n){if(t.nodeType===3)return t.data;if(t.nodeType!==1)return null;var o=[],s={},i=0,l=t.attributes,_=t.childNodes;for(i=l.length;i--;)l[i].name!=="slot"&&(s[l[i].name]=l[i].value,s[Pe(l[i].name)]=l[i].value);for(i=_.length;i--;){var c=Re(_[i],null,n),a=_[i].slot;a?s[a]=L(Ie,{name:a},c):o[i]=c}var u=!(!n||!n.shadow),r=e?L(Ie,{useFragment:!u},o):o;return!u&&e&&(t.innerHTML=""),L(e||t.nodeName.toLowerCase(),s,r)}var ht=0;function g(t,e,n,o,s,i){e||(e={});var l,_,c=e;if("ref"in c)for(_ in c={},e)_=="ref"?l=e[_]:c[_]=e[_];var a={type:t,props:c,key:n,ref:l,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--ht,__i:-1,__u:0,__source:s,__self:i};if(typeof t=="function"&&(l=t.defaultProps))for(_ in l)c[_]===void 0&&(c[_]=l[_]);return m.vnode&&m.vnode(a),a}var z,w,ue,Ue,Z=0,De=[],b=m,Oe=b.__b,Le=b.__r,Qe=b.diffed,qe=b.__c,je=b.unmount,Be=b.__;function de(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 H(t){return Z=1,ft(Ge,t)}function ft(t,e,n){var o=de(z++,2);if(o.t=t,!o.__c&&(o.__=[Ge(void 0,e),function(_){var c=o.__N?o.__N[0]:o.__[0],a=o.t(c,_);c!==a&&(o.__N=[a,o.__[1]],o.__c.setState({}))}],o.__c=w,!w.__f)){var s=function(_,c,a){if(!o.__c.__H)return!0;var u=o.__c.__H.__.filter(function(h){return!!h.__c});if(u.every(function(h){return!h.__N}))return!i||i.call(this,_,c,a);var r=o.__c.props!==_;return u.forEach(function(h){if(h.__N){var d=h.__[0];h.__=h.__N,h.__N=void 0,d!==h.__[0]&&(r=!0)}}),i&&i.call(this,_,c,a)||r};w.__f=!0;var i=w.shouldComponentUpdate,l=w.componentWillUpdate;w.componentWillUpdate=function(_,c,a){if(this.__e){var u=i;i=void 0,s(_,c,a),i=u}l&&l.call(this,_,c,a)},w.shouldComponentUpdate=s}return o.__N||o.__}function ze(t,e){var n=de(z++,3);!b.__s&&Ke(n.__H,e)&&(n.__=t,n.u=e,w.__H.__h.push(n))}function Ve(t){return Z=5,pt(function(){return{current:t}},[])}function pt(t,e){var n=de(z++,7);return Ke(n.__H,e)&&(n.__=t(),n.__H=e,n.__h=t),n.__}function mt(){for(var t;t=De.shift();)if(t.__P&&t.__H)try{t.__H.__h.forEach(ee),t.__H.__h.forEach(ge),t.__H.__h=[]}catch(e){t.__H.__h=[],b.__e(e,t.__v)}}b.__b=function(t){w=null,Oe&&Oe(t)},b.__=function(t,e){t&&e.__k&&e.__k.__m&&(t.__m=e.__k.__m),Be&&Be(t,e)},b.__r=function(t){Le&&Le(t),z=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(ge),e.__h=[],z=0)),ue=w},b.diffed=function(t){Qe&&Qe(t);var e=t.__c;e&&e.__H&&(e.__H.__h.length&&(De.push(e)!==1&&Ue===b.requestAnimationFrame||((Ue=b.requestAnimationFrame)||yt)(mt)),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.__||ge(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){je&&je(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 Je=typeof requestAnimationFrame=="function";function yt(t){var e,n=function(){clearTimeout(o),Je&&cancelAnimationFrame(e),setTimeout(t)},o=setTimeout(n,35);Je&&(e=requestAnimationFrame(n))}function ee(t){var e=w,n=t.__c;typeof n=="function"&&(t.__c=void 0,n()),w=e}function ge(t){var e=w;t.__c=t.__(),w=e}function Ke(t,e){return!t||t.length!==e.length||e.some(function(n,o){return n!==t[o]})}function Ge(t,e){return typeof e=="function"?e(t):e}const wt="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let te=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t|=0));for(;t--;)e+=wt[n[t]&63];return e};class Xe{constructor(e,n){this.agentUrl=e,this.agentId=n,this.agentConfig=null,this.ws=null,this.messageCallbacks=new Set,this.connectionCallbacks=new Set,this.streamingCallbacks=new Set,this.queueCallbacks=new Set,this.messages=[],this.reconnectAttempts=0,this.maxReconnectAttempts=5,this.reconnectDelay=1e3,this.isAgentStreaming=!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)}})}handleMessage(e){try{const n=JSON.parse(e.data);if(n.type==="text-delta")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.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);else if(n.type==="step-end"||n.type==="agent-end")console.log(`[Widget] ${n.type} received`);else if(n.type==="tool-call"){console.log("[Widget] Tool call:",n.tool);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(l=>l.role==="assistant");return i?s.map(l=>l.id===i.id?{...l,suggestions:n.tool.arguments.options}:l):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}]:o})):n.type==="agent-start"?(console.log(`[Widget] Agent started: ${n.agentId}`),this.isAgentStreaming=!0,this.notifyStreamingChange(!0)):n.type==="handoff"?console.log(`[Widget] Handoff: ${n.from} -> ${n.to}: ${n.reason}`):n.type==="suggested-questions"?(console.log("[Widget] Suggestions received:",n.suggestions),this.setMessages(o=>{const s=[...o].reverse().find(i=>i.role==="assistant");return s?o.map(i=>i.id===s.id?{...i,suggestions:n.suggestions}:i):o})):console.log("[Widget] Unknown message type:",n.type)}catch(n){console.error("[Widget] Error parsing message:",e.data,n)}}async sendMessage(e){if(!this.ws||this.ws.readyState!==WebSocket.OPEN)throw new Error("Not connected to agent");const n={id:te(),role:"user",content:e,timestamp:Date.now()};if(this.setMessages(o=>[...o,n]),this.isAgentStreaming){console.log("[Widget] Agent is streaming, queuing message"),this.messageQueue.push(e),this.notifyQueueChange(this.messageQueue.length);return}this.sendToAgent(e)}async sendToAgent(e){const n=this.getSessionId();this.ws.send(JSON.stringify({message:e,sessionId:n}))}async processMessageQueue(){if(this.messageQueue.length!==0){if(this.messageQueue.length===1){const e=this.messageQueue.shift();console.log("[Widget] Sending queued message:",e),this.sendToAgent(e)}else{const e=this.messageQueue.join(`
3
3
 
4
- `);this.messageQueue.length=0,console.log("[Widget] Sending combined queued messages:",e),this.sendToAgent(e)}this.notifyQueueChange(this.messageQueue.length)}}getSessionId(){let e=sessionStorage.getItem("ariaflow_session_id");return e||(e=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 Ye({agentUrl:t,agentId:e,widgetId:n,apiUrl:o,mode:s="chat",theme:i="light",position:l="bottom-right",size:a="full",radius:c="medium",baseColor:_,accentColor:u="#14B8A6",buttonBaseColor:r="#000000",buttonAccentColor:h="#FFFFFF",title:d,subtitle:C,emptyChatMessage:S}){const[v,p]=H(!1),[f,F]=H([]),[W,U]=H(""),[$,ne]=H(!1),[k,D]=H(!1),[O,N]=H(null),[T,vt]=H(!1),[fe,bt]=H(0),oe=Ve(null),et=Ve(null);ze(()=>((async()=>{if(t&&e){console.log("[AriaFlow Widget] Using new agent resolution:",{agentUrl:t,agentId:e});const M=new Xe(t,e);oe.current=M;try{M.onMessages(A=>{console.log("[AriaFlow Widget] Messages updated:",A.length),F(A)}),M.onConnectionChange(A=>{console.log("[AriaFlow Widget] Connection state:",A),ne(A),A&&D(!0)}),M.onStreamingChange(A=>{console.log("[AriaFlow Widget] Streaming state:",A),vt(A)}),M.onQueueChange(A=>{console.log("[AriaFlow Widget] Queue count:",A),bt(A)});const q=await M.initWidget();console.log("[AriaFlow Widget] Agent config received:",q),q?(N(q),console.log("[AriaFlow Widget] Widget initialized successfully")):console.error("[AriaFlow Widget] Agent config fetch failed")}catch(q){console.error("[AriaFlow Widget] Initialization error:",q)}}else t&&!e?(console.warn("[AriaFlow Widget] Direct WebSocket URLs are deprecated. Use agent-url + agent-id instead."),console.error("[AriaFlow Widget] Configuration error: agent-id is required")):o&&n?(console.warn("[AriaFlow Widget] Legacy widget config is deprecated. Use agent-url + agent-id instead."),console.error("[AriaFlow Widget] Configuration error: use agent-url + agent-id instead")):console.error("[AriaFlow Widget] Invalid configuration. Provide agent-url and agent-id.")})(),()=>{oe.current?.dispose()}),[t,e,n,o]),ze(()=>{et.current?.scrollIntoView({behavior:"smooth"})},[f]);const tt=async()=>{if(!W.trim()||!$)return;const y=W.trim();U("");try{await oe.current?.sendMessage(y)}catch(M){console.error("Failed to send message:",M)}},Ct=y=>{y.key==="Enter"&&!y.shiftKey&&(y.preventDefault(),tt())},kt=y=>{!$||T||oe.current?.sendMessage(y)},At=d||O?.config.title||"Chat with us",St=C||O?.config.subtitle||"We typically reply within minutes",$t=S||O?.config.emptyChatMessage||"Start a conversation...";return console.log("[AriaFlow Widget] Rendering widget component",{isInitialized:k,isOpen:v,position:l}),g("div",{className:`ariaflow-widget-container ariaflow-widget-${l} ariaflow-widget-${a} ariaflow-widget-radius-${c}`,"data-theme":i,style:{"--ariaflow-accent-color":u,"--ariaflow-base-color":_},children:[!v&&g("button",{className:"ariaflow-widget-launcher",onClick:()=>p(!0),style:{backgroundColor:r,color:h,opacity:k?1:.8,cursor:k?"pointer":"wait",position:"relative"},"aria-label":k?"Open chat":"Connecting to agent...",disabled:!k,title:k?"Click to start chat":"Connecting to agent...",children:[!k&&g("div",{className:"ariaflow-widget-launcher-loading",style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"20px",height:"20px",border:`2px solid ${h}`,borderTop:"2px solid transparent",borderRadius:"50%",animation:"spin 1s linear infinite"}}),k&&g("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:g("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&&k&&g("div",{className:"ariaflow-widget-window",style:{backgroundColor:i==="dark"&&_?_:void 0,borderRadius:he[c]},children:[g("div",{className:"ariaflow-widget-header",style:{backgroundColor:u,borderRadius:c==="none"?"0":`${he[c]} ${he[c]} 0 0`},children:[g("div",{className:"ariaflow-widget-header-content",children:g("div",{className:"ariaflow-widget-title-group",children:[g("h3",{className:"ariaflow-widget-title",children:At}),g("p",{className:"ariaflow-widget-subtitle",children:St})]})}),g("button",{className:"ariaflow-widget-close",onClick:()=>p(!1),"aria-label":"Close chat",children:g("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[g("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),g("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),!$&&g("div",{className:"ariaflow-widget-status",children:[g("span",{className:"ariaflow-widget-status-dot"}),"Connecting..."]}),g("div",{className:"ariaflow-widget-messages",children:f.length===0?g("div",{className:"ariaflow-widget-empty",children:g("p",{children:$?$t:"Connecting to agent..."})}):g(R,{children:[f.map((y,M)=>{const A=M===f.length-1&&y.role==="assistant"&&!y.isStreaming&&y.suggestions&&y.suggestions.length>0;return g("div",{className:`ariaflow-widget-message ariaflow-widget-message-${y.role}`,children:[g("div",{className:"ariaflow-widget-message-bubble",children:y.role==="tool"?g("div",{className:"ariaflow-widget-tool-message",children:[g("div",{className:"ariaflow-widget-tool-header",children:["🔧 ",y.toolCall?.name]}),g("div",{className:"ariaflow-widget-tool-content",children:[y.toolCall&&g("div",{className:"ariaflow-widget-tool-args",children:[g("strong",{children:"Arguments:"})," ",JSON.stringify(y.toolCall.arguments,null,2)]}),y.toolResult&&g("div",{className:"ariaflow-widget-tool-result",children:[g("strong",{children:"Result:"})," ",JSON.stringify(y.toolResult,null,2)]})]})]}):g(R,{children:[y.content,y.isStreaming&&g("span",{className:"ariaflow-widget-typing-indicator",children:[g("span",{children:"•"}),g("span",{children:"•"}),g("span",{children:"•"})]})]})}),A&&g("div",{className:"ariaflow-widget-chips-container",children:y.suggestions?.map(pe=>g("button",{className:"ariaflow-widget-chip",onClick:()=>kt(pe),style:{borderColor:u,color:u},children:pe},pe))})]},y.id)}),g("div",{ref:et})]})}),g("div",{className:"ariaflow-widget-input",children:[g("textarea",{value:W,onInput:y=>U(y.target.value),onKeyDown:Ct,placeholder:$?T?fe>0?`Agent is responding... (${fe} message${fe>1?"s":""} queued)`:"Agent is responding...":"Type your message...":"Connecting...",rows:1,disabled:!$}),g("button",{className:"ariaflow-widget-send",onClick:tt,disabled:!W.trim()||!$,style:{backgroundColor:u},"aria-label":"Send message",children:g("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[g("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),g("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})})]})]})]})}_t(Ye,"ariaflow-widget",["agent-url","agent-id","widget-id","api-url","mode","theme","position","size","radius","base-color","accent-color","button-base-color","button-accent-color","title","subtitle","empty-chat-message"],!1),typeof document<"u"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Ze):Ze());function Ze(){const t=document.querySelectorAll("ariaflow-widget");console.log(`[AriaFlow] Initializing ${t.length} widget(s)`)}P.Widget=Ye,P.WidgetClient=Xe,Object.defineProperty(P,Symbol.toStringTag,{value:"Module"})});
4
+ `);this.messageQueue.length=0,console.log("[Widget] Sending combined queued messages:",e),this.sendToAgent(e)}this.notifyQueueChange(this.messageQueue.length)}}getSessionId(){let e=sessionStorage.getItem("ariaflow_session_id");return e||(e=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 Ye({agentUrl:t,agentId:e,widgetId:n,apiUrl:o,mode:s="chat",theme:i="light",position:l="bottom-right",size:_="full",radius:c="medium",baseColor:a,accentColor:u="#14B8A6",buttonBaseColor:r="#000000",buttonAccentColor:h="#FFFFFF",title:d,subtitle:C,emptyChatMessage:S}){const[v,p]=H(!1),[f,F]=H([]),[W,U]=H(""),[$,ne]=H(!1),[k,D]=H(!1),[O,N]=H(null),[M,vt]=H(!1),[fe,bt]=H(0),oe=Ve(null),et=Ve(null);ze(()=>((async()=>{if(t&&e){console.log("[AriaFlow Widget] Using new agent resolution:",{agentUrl:t,agentId:e});const E=new Xe(t,e);oe.current=E;try{E.onMessages(A=>{console.log("[AriaFlow Widget] Messages updated:",A.length),F(A)}),E.onConnectionChange(A=>{console.log("[AriaFlow Widget] Connection state:",A),ne(A),A&&D(!0)}),E.onStreamingChange(A=>{console.log("[AriaFlow Widget] Streaming state:",A),vt(A)}),E.onQueueChange(A=>{console.log("[AriaFlow Widget] Queue count:",A),bt(A)});const q=await E.initWidget();console.log("[AriaFlow Widget] Agent config received:",q),q?(N(q),console.log("[AriaFlow Widget] Widget initialized successfully")):console.error("[AriaFlow Widget] Agent config fetch failed")}catch(q){console.error("[AriaFlow Widget] Initialization error:",q)}}else t&&!e?(console.warn("[AriaFlow Widget] Direct WebSocket URLs are deprecated. Use agent-url + agent-id instead."),console.error("[AriaFlow Widget] Configuration error: agent-id is required")):o&&n?(console.warn("[AriaFlow Widget] Legacy widget config is deprecated. Use agent-url + agent-id instead."),console.error("[AriaFlow Widget] Configuration error: use agent-url + agent-id instead")):console.error("[AriaFlow Widget] Invalid configuration. Provide agent-url and agent-id.")})(),()=>{oe.current?.dispose()}),[t,e,n,o]),ze(()=>{et.current?.scrollIntoView({behavior:"smooth"})},[f]);const tt=async()=>{if(!W.trim()||!$)return;const y=W.trim();U("");try{await oe.current?.sendMessage(y)}catch(E){console.error("Failed to send message:",E)}},Ct=y=>{y.key==="Enter"&&!y.shiftKey&&(y.preventDefault(),tt())},kt=y=>{!$||M||oe.current?.sendMessage(y)},At=d||O?.config.title||"Ninewells Hospital",St=C||O?.config.subtitle||"How can we help you today?",$t=S||O?.config.emptyChatMessage||"Start a conversation with Ninewells...";return console.log("[AriaFlow Widget] Rendering widget component",{isInitialized:k,isOpen:v,position:l}),g("div",{className:`ariaflow-widget-container ariaflow-widget-${l} ariaflow-widget-${_} ariaflow-widget-radius-${c}`,"data-theme":i,style:{"--ariaflow-accent-color":u,"--ariaflow-base-color":a},children:[!v&&g("button",{className:"ariaflow-widget-launcher",onClick:()=>p(!0),style:{backgroundColor:r,color:h,opacity:k?1:.8,cursor:k?"pointer":"wait",position:"relative"},"aria-label":k?"Open chat":"Connecting to agent...",disabled:!k,title:k?"Click to start chat":"Connecting to agent...",children:[!k&&g("div",{className:"ariaflow-widget-launcher-loading",style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"20px",height:"20px",border:`2px solid ${h}`,borderTop:"2px solid transparent",borderRadius:"50%",animation:"spin 1s linear infinite"}}),k&&g("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:g("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&&k&&g("div",{className:"ariaflow-widget-window",style:{backgroundColor:i==="dark"&&a?a:void 0,borderRadius:he[c]},children:[g("div",{className:"ariaflow-widget-header",style:{backgroundColor:u,borderRadius:c==="none"?"0":`${he[c]} ${he[c]} 0 0`},children:[g("div",{className:"ariaflow-widget-header-content",children:g("div",{className:"ariaflow-widget-title-group",children:[g("h3",{className:"ariaflow-widget-title",children:At}),g("p",{className:"ariaflow-widget-subtitle",children:St})]})}),g("button",{className:"ariaflow-widget-close",onClick:()=>p(!1),"aria-label":"Close chat",children:g("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[g("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),g("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),!$&&g("div",{className:"ariaflow-widget-status",children:[g("span",{className:"ariaflow-widget-status-dot"}),"Connecting..."]}),g("div",{className:"ariaflow-widget-messages",children:f.length===0?g("div",{className:"ariaflow-widget-empty",children:g("p",{children:$?$t:"Connecting to agent..."})}):g(R,{children:[f.map((y,E)=>{const A=E===f.length-1&&y.role==="assistant"&&!M&&y.suggestions&&y.suggestions.length>0;return g("div",{className:`ariaflow-widget-message ariaflow-widget-message-${y.role}`,children:[g("div",{className:"ariaflow-widget-message-bubble",children:y.role==="tool"?g("div",{className:"ariaflow-widget-tool-message",children:[g("div",{className:"ariaflow-widget-tool-header",children:["🔧 ",y.toolCall?.name]}),g("div",{className:"ariaflow-widget-tool-content",children:[y.toolCall&&g("div",{className:"ariaflow-widget-tool-args",children:[g("strong",{children:"Arguments:"})," ",JSON.stringify(y.toolCall.arguments,null,2)]}),y.toolResult&&g("div",{className:"ariaflow-widget-tool-result",children:[g("strong",{children:"Result:"})," ",JSON.stringify(y.toolResult,null,2)]})]})]}):g(R,{children:[y.content,y.isStreaming&&g("span",{className:"ariaflow-widget-typing-indicator",children:[g("span",{children:"•"}),g("span",{children:"•"}),g("span",{children:"•"})]})]})}),A&&g("div",{className:"ariaflow-widget-chips-container",children:y.suggestions?.map(pe=>g("button",{className:"ariaflow-widget-chip",onClick:()=>kt(pe),style:{borderColor:u,color:u},children:pe},pe))})]},y.id)}),g("div",{ref:et})]})}),g("div",{className:"ariaflow-widget-input",children:[g("textarea",{value:W,onInput:y=>U(y.target.value),onKeyDown:Ct,placeholder:$?M?fe>0?`Agent is responding... (${fe} message${fe>1?"s":""} queued)`:"Agent is responding...":"Type your message...":"Connecting...",rows:1,disabled:!$}),g("button",{className:"ariaflow-widget-send",onClick:tt,disabled:!W.trim()||!$,style:{backgroundColor:u},"aria-label":"Send message",children:g("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[g("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),g("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})})]})]})]})}_t(Ye,"ariaflow-widget",["agent-url","agent-id","widget-id","api-url","mode","theme","position","size","radius","base-color","accent-color","button-base-color","button-accent-color","title","subtitle","empty-chat-message"],!1),typeof document<"u"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Ze):Ze());function Ze(){const t=document.querySelectorAll("ariaflow-widget");console.log(`[AriaFlow] Initializing ${t.length} widget(s)`)}P.Widget=Ye,P.WidgetClient=Xe,Object.defineProperty(P,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ariaflowagents/widget",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "type": "module",
5
5
  "description": "Embeddable chat widget for AriaFlow Universal Inbox",
6
6
  "main": "./dist/widget.js",