@stubwise/widget 0.1.0
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/core/api.d.ts +93 -0
- package/dist/core/dsn.d.ts +23 -0
- package/dist/core/sse.d.ts +55 -0
- package/dist/core/storage.d.ts +14 -0
- package/dist/i18n.d.ts +46 -0
- package/dist/index.d.ts +31 -0
- package/dist/stubwise-widget.iife.js +199 -0
- package/dist/stubwise-widget.js +1093 -0
- package/dist/ui/chat.d.ts +30 -0
- package/dist/ui/styles.d.ts +12 -0
- package/dist/ui/ticket-card.d.ts +16 -0
- package/dist/ui/widget.d.ts +19 -0
- package/package.json +33 -0
|
@@ -0,0 +1,1093 @@
|
|
|
1
|
+
const je = /^(?<prefix>(?:\/[^/]+)*)\/p\/(?<slug>[^/]+)\/?$/;
|
|
2
|
+
function qe(t) {
|
|
3
|
+
let e;
|
|
4
|
+
try {
|
|
5
|
+
e = new URL(t);
|
|
6
|
+
} catch {
|
|
7
|
+
throw new Error(
|
|
8
|
+
"[stubwise] DSN malformato: la stringa fornita non è un URL valido (atteso https://KEY@host/p/slug)"
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
if (e.protocol !== "https:" && e.protocol !== "http:")
|
|
12
|
+
throw new Error(`[stubwise] DSN malformato: protocollo "${e.protocol}" non supportato`);
|
|
13
|
+
const n = decodeURIComponent(e.username);
|
|
14
|
+
if (!n)
|
|
15
|
+
throw new Error(
|
|
16
|
+
"[stubwise] DSN malformato: chiave mancante (atteso https://KEY@host/p/slug)"
|
|
17
|
+
);
|
|
18
|
+
const r = je.exec(e.pathname), s = r?.groups?.slug;
|
|
19
|
+
if (!s)
|
|
20
|
+
throw new Error(`[stubwise] DSN malformato: path "${e.pathname}" non corrisponde a /p/<slug>`);
|
|
21
|
+
const o = r?.groups?.prefix ?? "";
|
|
22
|
+
return { origin: `${e.protocol}//${e.host}${o}`, slug: s, key: n };
|
|
23
|
+
}
|
|
24
|
+
class re extends Error {
|
|
25
|
+
status;
|
|
26
|
+
code;
|
|
27
|
+
constructor(e, n, r) {
|
|
28
|
+
super(r ?? n ?? `HTTP ${e}`), this.name = "WidgetApiError", this.status = e, this.code = n;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function U(t, e) {
|
|
32
|
+
return `${t.origin}/widget/${t.slug}${e}`;
|
|
33
|
+
}
|
|
34
|
+
function M(t, e) {
|
|
35
|
+
const n = { "X-Stubwise-Key": t.key };
|
|
36
|
+
return e && (n["content-type"] = "application/json"), n;
|
|
37
|
+
}
|
|
38
|
+
async function W(t) {
|
|
39
|
+
let e, n;
|
|
40
|
+
try {
|
|
41
|
+
const r = await t.json();
|
|
42
|
+
e = r.code, n = r.message;
|
|
43
|
+
} catch {
|
|
44
|
+
}
|
|
45
|
+
throw new re(t.status, e, n);
|
|
46
|
+
}
|
|
47
|
+
async function Ge(t) {
|
|
48
|
+
const e = await fetch(U(t, "/config"), {
|
|
49
|
+
method: "GET",
|
|
50
|
+
headers: M(t, !1)
|
|
51
|
+
});
|
|
52
|
+
return e.ok || await W(e), await e.json();
|
|
53
|
+
}
|
|
54
|
+
async function Ke(t, e) {
|
|
55
|
+
const n = await fetch(U(t, "/conversations"), {
|
|
56
|
+
method: "POST",
|
|
57
|
+
headers: M(t, !0),
|
|
58
|
+
body: JSON.stringify({ user: e })
|
|
59
|
+
});
|
|
60
|
+
return n.ok || await W(n), await n.json();
|
|
61
|
+
}
|
|
62
|
+
async function Je(t, e, n) {
|
|
63
|
+
const r = new URLSearchParams({ userId: n }), s = await fetch(
|
|
64
|
+
U(t, `/conversations/${e}/messages?${r.toString()}`),
|
|
65
|
+
{ method: "GET", headers: M(t, !1) }
|
|
66
|
+
);
|
|
67
|
+
return s.ok || await W(s), await s.json();
|
|
68
|
+
}
|
|
69
|
+
async function Ye(t, e, n, r) {
|
|
70
|
+
const s = await fetch(U(t, `/conversations/${e}/messages`), {
|
|
71
|
+
method: "POST",
|
|
72
|
+
headers: M(t, !0),
|
|
73
|
+
body: JSON.stringify(n),
|
|
74
|
+
signal: r
|
|
75
|
+
});
|
|
76
|
+
return s.ok || await W(s), s;
|
|
77
|
+
}
|
|
78
|
+
async function Ve(t, e, n) {
|
|
79
|
+
const r = await fetch(U(t, `/conversations/${e}/tickets`), {
|
|
80
|
+
method: "POST",
|
|
81
|
+
headers: M(t, !0),
|
|
82
|
+
body: JSON.stringify(n)
|
|
83
|
+
});
|
|
84
|
+
return r.ok || await W(r), await r.json();
|
|
85
|
+
}
|
|
86
|
+
var X, v, Ie, H, pe, Ee, Ne, Z, j, z, Ae, ce, oe, ie, K = {}, J = [], Xe = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i, Q = Array.isArray;
|
|
87
|
+
function D(t, e) {
|
|
88
|
+
for (var n in e) t[n] = e[n];
|
|
89
|
+
return t;
|
|
90
|
+
}
|
|
91
|
+
function le(t) {
|
|
92
|
+
t && t.parentNode && t.parentNode.removeChild(t);
|
|
93
|
+
}
|
|
94
|
+
function Qe(t, e, n) {
|
|
95
|
+
var r, s, o, a = {};
|
|
96
|
+
for (o in e) o == "key" ? r = e[o] : o == "ref" ? s = e[o] : a[o] = e[o];
|
|
97
|
+
if (arguments.length > 2 && (a.children = arguments.length > 3 ? X.call(arguments, 2) : n), typeof t == "function" && t.defaultProps != null) for (o in t.defaultProps) a[o] === void 0 && (a[o] = t.defaultProps[o]);
|
|
98
|
+
return q(t, a, r, s, null);
|
|
99
|
+
}
|
|
100
|
+
function q(t, e, n, r, s) {
|
|
101
|
+
var o = { type: t, props: e, key: n, ref: r, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: s ?? ++Ie, __i: -1, __u: 0 };
|
|
102
|
+
return s == null && v.vnode != null && v.vnode(o), o;
|
|
103
|
+
}
|
|
104
|
+
function B(t) {
|
|
105
|
+
return t.children;
|
|
106
|
+
}
|
|
107
|
+
function G(t, e) {
|
|
108
|
+
this.props = t, this.context = e;
|
|
109
|
+
}
|
|
110
|
+
function F(t, e) {
|
|
111
|
+
if (e == null) return t.__ ? F(t.__, t.__i + 1) : null;
|
|
112
|
+
for (var n; e < t.__k.length; e++) if ((n = t.__k[e]) != null && n.__e != null) return n.__e;
|
|
113
|
+
return typeof t.type == "function" ? F(t) : null;
|
|
114
|
+
}
|
|
115
|
+
function Ze(t) {
|
|
116
|
+
if (t.__P && t.__d) {
|
|
117
|
+
var e = t.__v, n = e.__e, r = [], s = [], o = D({}, e);
|
|
118
|
+
o.__v = e.__v + 1, v.vnode && v.vnode(o), _e(t.__P, o, e, t.__n, t.__P.namespaceURI, 32 & e.__u ? [n] : null, r, n ?? F(e), !!(32 & e.__u), s), o.__v = e.__v, o.__.__k[o.__i] = o, ze(r, o, s), e.__e = e.__ = null, o.__e != n && De(o);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function De(t) {
|
|
122
|
+
if ((t = t.__) != null && t.__c != null) return t.__e = t.__c.base = null, t.__k.some(function(e) {
|
|
123
|
+
if (e != null && e.__e != null) return t.__e = t.__c.base = e.__e;
|
|
124
|
+
}), De(t);
|
|
125
|
+
}
|
|
126
|
+
function he(t) {
|
|
127
|
+
(!t.__d && (t.__d = !0) && H.push(t) && !Y.__r++ || pe != v.debounceRendering) && ((pe = v.debounceRendering) || Ee)(Y);
|
|
128
|
+
}
|
|
129
|
+
function Y() {
|
|
130
|
+
try {
|
|
131
|
+
for (var t, e = 1; H.length; ) H.length > e && H.sort(Ne), t = H.shift(), e = H.length, Ze(t);
|
|
132
|
+
} finally {
|
|
133
|
+
H.length = Y.__r = 0;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function He(t, e, n, r, s, o, a, l, d, c, f) {
|
|
137
|
+
var g, i, _, p, P, w, y, h = r && r.__k || J, u = e.length;
|
|
138
|
+
for (d = et(n, e, h, d, u), g = 0; g < u; g++) (_ = n.__k[g]) != null && (i = _.__i != -1 && h[_.__i] || K, _.__i = g, w = _e(t, _, i, s, o, a, l, d, c, f), p = _.__e, _.ref && i.ref != _.ref && (i.ref && de(i.ref, null, _), f.push(_.ref, _.__c || p, _)), P == null && p != null && (P = p), (y = !!(4 & _.__u)) || i.__k === _.__k ? (d = Re(_, d, t, y), y && i.__e && (i.__e = null)) : typeof _.type == "function" && w !== void 0 ? d = w : p && (d = p.nextSibling), _.__u &= -7);
|
|
139
|
+
return n.__e = P, d;
|
|
140
|
+
}
|
|
141
|
+
function et(t, e, n, r, s) {
|
|
142
|
+
var o, a, l, d, c, f = n.length, g = f, i = 0;
|
|
143
|
+
for (t.__k = new Array(s), o = 0; o < s; o++) (a = e[o]) != null && typeof a != "boolean" && typeof a != "function" ? (typeof a == "string" || typeof a == "number" || typeof a == "bigint" || a.constructor == String ? a = t.__k[o] = q(null, a, null, null, null) : Q(a) ? a = t.__k[o] = q(B, { children: a }, null, null, null) : a.constructor === void 0 && a.__b > 0 ? a = t.__k[o] = q(a.type, a.props, a.key, a.ref ? a.ref : null, a.__v) : t.__k[o] = a, d = o + i, a.__ = t, a.__b = t.__b + 1, l = null, (c = a.__i = tt(a, n, d, g)) != -1 && (g--, (l = n[c]) && (l.__u |= 2)), l == null || l.__v == null ? (c == -1 && (s > f ? i-- : s < f && i++), typeof a.type != "function" && (a.__u |= 4)) : c != d && (c == d - 1 ? i-- : c == d + 1 ? i++ : (c > d ? i-- : i++, a.__u |= 4))) : t.__k[o] = null;
|
|
144
|
+
if (g) for (o = 0; o < f; o++) (l = n[o]) != null && (2 & l.__u) == 0 && (l.__e == r && (r = F(l)), Ue(l, l));
|
|
145
|
+
return r;
|
|
146
|
+
}
|
|
147
|
+
function Re(t, e, n, r) {
|
|
148
|
+
var s, o;
|
|
149
|
+
if (typeof t.type == "function") {
|
|
150
|
+
for (s = t.__k, o = 0; s && o < s.length; o++) s[o] && (s[o].__ = t, e = Re(s[o], e, n, r));
|
|
151
|
+
return e;
|
|
152
|
+
}
|
|
153
|
+
t.__e != e && (r && (e && t.type && !e.parentNode && (e = F(t)), n.insertBefore(t.__e, e || null)), e = t.__e);
|
|
154
|
+
do
|
|
155
|
+
e = e && e.nextSibling;
|
|
156
|
+
while (e != null && e.nodeType == 8);
|
|
157
|
+
return e;
|
|
158
|
+
}
|
|
159
|
+
function tt(t, e, n, r) {
|
|
160
|
+
var s, o, a, l = t.key, d = t.type, c = e[n], f = c != null && (2 & c.__u) == 0;
|
|
161
|
+
if (c === null && l == null || f && l == c.key && d == c.type) return n;
|
|
162
|
+
if (r > (f ? 1 : 0)) {
|
|
163
|
+
for (s = n - 1, o = n + 1; s >= 0 || o < e.length; ) if ((c = e[a = s >= 0 ? s-- : o++]) != null && (2 & c.__u) == 0 && l == c.key && d == c.type) return a;
|
|
164
|
+
}
|
|
165
|
+
return -1;
|
|
166
|
+
}
|
|
167
|
+
function me(t, e, n) {
|
|
168
|
+
e[0] == "-" ? t.setProperty(e, n ?? "") : t[e] = n == null ? "" : typeof n != "number" || Xe.test(e) ? n : n + "px";
|
|
169
|
+
}
|
|
170
|
+
function O(t, e, n, r, s) {
|
|
171
|
+
var o, a;
|
|
172
|
+
e: if (e == "style") if (typeof n == "string") t.style.cssText = n;
|
|
173
|
+
else {
|
|
174
|
+
if (typeof r == "string" && (t.style.cssText = r = ""), r) for (e in r) n && e in n || me(t.style, e, "");
|
|
175
|
+
if (n) for (e in n) r && n[e] == r[e] || me(t.style, e, n[e]);
|
|
176
|
+
}
|
|
177
|
+
else if (e[0] == "o" && e[1] == "n") o = e != (e = e.replace(Ae, "$1")), a = e.toLowerCase(), e = a in t || e == "onFocusOut" || e == "onFocusIn" ? a.slice(2) : e.slice(2), t.l || (t.l = {}), t.l[e + o] = n, n ? r ? n[z] = r[z] : (n[z] = ce, t.addEventListener(e, o ? ie : oe, o)) : t.removeEventListener(e, o ? ie : oe, o);
|
|
178
|
+
else {
|
|
179
|
+
if (s == "http://www.w3.org/2000/svg") e = e.replace(/xlink(H|:h)/, "h").replace(/sName$/, "s");
|
|
180
|
+
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 {
|
|
181
|
+
t[e] = n ?? "";
|
|
182
|
+
break e;
|
|
183
|
+
} catch {
|
|
184
|
+
}
|
|
185
|
+
typeof n == "function" || (n == null || n === !1 && e[4] != "-" ? t.removeAttribute(e) : t.setAttribute(e, e == "popover" && n == 1 ? "" : n));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function ge(t) {
|
|
189
|
+
return function(e) {
|
|
190
|
+
if (this.l) {
|
|
191
|
+
var n = this.l[e.type + t];
|
|
192
|
+
if (e[j] == null) e[j] = ce++;
|
|
193
|
+
else if (e[j] < n[z]) return;
|
|
194
|
+
return n(v.event ? v.event(e) : e);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function _e(t, e, n, r, s, o, a, l, d, c) {
|
|
199
|
+
var f, g, i, _, p, P, w, y, h, u, $, C, x, E, T, N, b = e.type;
|
|
200
|
+
if (e.constructor !== void 0) return null;
|
|
201
|
+
128 & n.__u && (d = !!(32 & n.__u), o = [l = e.__e = n.__e]), (f = v.__b) && f(e);
|
|
202
|
+
e: if (typeof b == "function") {
|
|
203
|
+
g = a.length;
|
|
204
|
+
try {
|
|
205
|
+
if (h = e.props, u = b.prototype && b.prototype.render, $ = (f = b.contextType) && r[f.__c], C = f ? $ ? $.props.value : f.__ : r, n.__c ? y = (i = e.__c = n.__c).__ = i.__E : (u ? e.__c = i = new b(h, C) : (e.__c = i = new G(h, C), i.constructor = b, i.render = rt), $ && $.sub(i), i.state || (i.state = {}), i.__n = r, _ = i.__d = !0, i.__h = [], i._sb = []), u && i.__s == null && (i.__s = i.state), u && b.getDerivedStateFromProps != null && (i.__s == i.state && (i.__s = D({}, i.__s)), D(i.__s, b.getDerivedStateFromProps(h, i.__s))), p = i.props, P = i.state, i.__v = e, _) u && b.getDerivedStateFromProps == null && i.componentWillMount != null && i.componentWillMount(), u && i.componentDidMount != null && i.__h.push(i.componentDidMount);
|
|
206
|
+
else {
|
|
207
|
+
if (u && b.getDerivedStateFromProps == null && h !== p && i.componentWillReceiveProps != null && i.componentWillReceiveProps(h, C), e.__v == n.__v || !i.__e && i.shouldComponentUpdate != null && i.shouldComponentUpdate(h, i.__s, C) === !1) {
|
|
208
|
+
e.__v != n.__v && (i.props = h, i.state = i.__s, i.__d = !1), e.__e = n.__e, e.__k = n.__k, e.__k.some(function(I) {
|
|
209
|
+
I && (I.__ = e);
|
|
210
|
+
}), J.push.apply(i.__h, i._sb), i._sb = [], i.__h.length && a.push(i);
|
|
211
|
+
break e;
|
|
212
|
+
}
|
|
213
|
+
i.componentWillUpdate != null && i.componentWillUpdate(h, i.__s, C), u && i.componentDidUpdate != null && i.__h.push(function() {
|
|
214
|
+
i.componentDidUpdate(p, P, w);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
if (i.context = C, i.props = h, i.__P = t, i.__e = !1, x = v.__r, E = 0, u) i.state = i.__s, i.__d = !1, x && x(e), f = i.render(i.props, i.state, i.context), J.push.apply(i.__h, i._sb), i._sb = [];
|
|
218
|
+
else do
|
|
219
|
+
i.__d = !1, x && x(e), f = i.render(i.props, i.state, i.context), i.state = i.__s;
|
|
220
|
+
while (i.__d && ++E < 25);
|
|
221
|
+
i.state = i.__s, i.getChildContext != null && (r = D(D({}, r), i.getChildContext())), u && !_ && i.getSnapshotBeforeUpdate != null && (w = i.getSnapshotBeforeUpdate(p, P)), T = f != null && f.type === B && f.key == null ? Le(f.props.children) : f, l = He(t, Q(T) ? T : [T], e, n, r, s, o, a, l, d, c), i.base = e.__e, e.__u &= -161, i.__h.length && a.push(i), y && (i.__E = i.__ = null);
|
|
222
|
+
} catch (I) {
|
|
223
|
+
if (a.length = g, e.__v = null, d || o != null) {
|
|
224
|
+
if (I.then) {
|
|
225
|
+
for (e.__u |= d ? 160 : 128; l && l.nodeType == 8 && l.nextSibling; ) l = l.nextSibling;
|
|
226
|
+
o != null && (o[o.indexOf(l)] = null), e.__e = l;
|
|
227
|
+
} else if (o != null) for (N = o.length; N--; ) le(o[N]);
|
|
228
|
+
} else e.__e = n.__e;
|
|
229
|
+
e.__k == null && (e.__k = n.__k || []), I.then || Fe(e), v.__e(I, e, n);
|
|
230
|
+
}
|
|
231
|
+
} else o == null && e.__v == n.__v ? (e.__k = n.__k, e.__e = n.__e) : l = e.__e = nt(n.__e, e, n, r, s, o, a, d, c);
|
|
232
|
+
return (f = v.diffed) && f(e), 128 & e.__u ? void 0 : l;
|
|
233
|
+
}
|
|
234
|
+
function Fe(t) {
|
|
235
|
+
t && (t.__c && (t.__c.__e = !0), t.__k && t.__k.some(Fe));
|
|
236
|
+
}
|
|
237
|
+
function ze(t, e, n) {
|
|
238
|
+
for (var r = 0; r < n.length; r++) de(n[r], n[++r], n[++r]);
|
|
239
|
+
v.__c && v.__c(e, t), t.some(function(s) {
|
|
240
|
+
try {
|
|
241
|
+
t = s.__h, s.__h = [], t.some(function(o) {
|
|
242
|
+
o.call(s);
|
|
243
|
+
});
|
|
244
|
+
} catch (o) {
|
|
245
|
+
v.__e(o, s.__v);
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
function Le(t) {
|
|
250
|
+
return typeof t != "object" || t == null || t.__b > 0 ? t : Q(t) ? t.map(Le) : t.constructor !== void 0 ? null : D({}, t);
|
|
251
|
+
}
|
|
252
|
+
function nt(t, e, n, r, s, o, a, l, d) {
|
|
253
|
+
var c, f, g, i, _, p, P, w = n.props || K, y = e.props, h = e.type;
|
|
254
|
+
if (h == "svg" ? s = "http://www.w3.org/2000/svg" : h == "math" ? s = "http://www.w3.org/1998/Math/MathML" : s || (s = "http://www.w3.org/1999/xhtml"), o != null) {
|
|
255
|
+
for (c = 0; c < o.length; c++) if ((_ = o[c]) && "setAttribute" in _ == !!h && (h ? _.localName == h : _.nodeType == 3)) {
|
|
256
|
+
t = _, o[c] = null;
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
if (t == null) {
|
|
261
|
+
if (h == null) return document.createTextNode(y);
|
|
262
|
+
t = document.createElementNS(s, h, y.is && y), l && (v.__m && v.__m(e, o), l = !1), o = null;
|
|
263
|
+
}
|
|
264
|
+
if (h == null) w === y || l && t.data == y || (t.data = y);
|
|
265
|
+
else {
|
|
266
|
+
if (o = h == "textarea" && y.defaultValue != null ? null : o && X.call(t.childNodes), !l && o != null) for (w = {}, c = 0; c < t.attributes.length; c++) w[(_ = t.attributes[c]).name] = _.value;
|
|
267
|
+
for (c in w) _ = w[c], c == "dangerouslySetInnerHTML" ? g = _ : c == "children" || c in y || c == "value" && "defaultValue" in y || c == "checked" && "defaultChecked" in y || O(t, c, null, _, s);
|
|
268
|
+
for (c in y) _ = y[c], c == "children" ? i = _ : c == "dangerouslySetInnerHTML" ? f = _ : c == "value" ? p = _ : c == "checked" ? P = _ : l && typeof _ != "function" || w[c] === _ || O(t, c, _, w[c], s);
|
|
269
|
+
if (f) l || g && (f.__html == g.__html || f.__html == t.innerHTML) || (t.innerHTML = f.__html), e.__k = [];
|
|
270
|
+
else if (g && (t.innerHTML = ""), He(e.type == "template" ? t.content : t, Q(i) ? i : [i], e, n, r, h == "foreignObject" ? "http://www.w3.org/1999/xhtml" : s, o, a, o ? o[0] : n.__k && F(n, 0), l, d), o != null) for (c = o.length; c--; ) le(o[c]);
|
|
271
|
+
l && h != "textarea" || (c = "value", h == "progress" && p == null ? t.removeAttribute("value") : p != null && (p !== t[c] || h == "progress" && !p || h == "option" && p != w[c]) && O(t, c, p, w[c], s), c = "checked", P != null && P != t[c] && O(t, c, P, w[c], s));
|
|
272
|
+
}
|
|
273
|
+
return t;
|
|
274
|
+
}
|
|
275
|
+
function de(t, e, n) {
|
|
276
|
+
try {
|
|
277
|
+
if (typeof t == "function") {
|
|
278
|
+
var r = typeof t.__u == "function";
|
|
279
|
+
r && t.__u(), r && e == null || (t.__u = t(e));
|
|
280
|
+
} else t.current = e;
|
|
281
|
+
} catch (s) {
|
|
282
|
+
v.__e(s, n);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
function Ue(t, e, n) {
|
|
286
|
+
var r, s;
|
|
287
|
+
if (v.unmount && v.unmount(t), (r = t.ref) && (r.current && r.current != t.__e || de(r, null, e)), (r = t.__c) != null) {
|
|
288
|
+
if (r.componentWillUnmount) try {
|
|
289
|
+
r.componentWillUnmount();
|
|
290
|
+
} catch (o) {
|
|
291
|
+
v.__e(o, e);
|
|
292
|
+
}
|
|
293
|
+
r.base = r.__P = r.__n = null;
|
|
294
|
+
}
|
|
295
|
+
if (r = t.__k) for (s = 0; s < r.length; s++) r[s] && Ue(r[s], e, n || typeof t.type != "function");
|
|
296
|
+
n || le(t.__e), t.__c = t.__ = t.__e = void 0;
|
|
297
|
+
}
|
|
298
|
+
function rt(t, e, n) {
|
|
299
|
+
return this.constructor(t, n);
|
|
300
|
+
}
|
|
301
|
+
function ot(t, e, n) {
|
|
302
|
+
var r, s, o, a;
|
|
303
|
+
e == document && (e = document.documentElement), v.__ && v.__(t, e), s = (r = !1) ? null : e.__k, o = [], a = [], _e(e, t = e.__k = Qe(B, null, [t]), s || K, K, e.namespaceURI, s ? null : e.firstChild ? X.call(e.childNodes) : null, o, s ? s.__e : e.firstChild, r, a), ze(o, t, a), t.props.children = null;
|
|
304
|
+
}
|
|
305
|
+
X = J.slice, v = { __e: function(t, e, n, r) {
|
|
306
|
+
for (var s, o, a; e = e.__; ) if ((s = e.__c) && !s.__) try {
|
|
307
|
+
if ((o = s.constructor) && o.getDerivedStateFromError != null && (s.setState(o.getDerivedStateFromError(t)), a = s.__d), s.componentDidCatch != null && (s.componentDidCatch(t, r || {}), a = s.__d), a) return s.__E = s;
|
|
308
|
+
} catch (l) {
|
|
309
|
+
t = l;
|
|
310
|
+
}
|
|
311
|
+
throw t;
|
|
312
|
+
} }, Ie = 0, G.prototype.setState = function(t, e) {
|
|
313
|
+
var n;
|
|
314
|
+
n = this.__s != null && this.__s != this.state ? this.__s : this.__s = D({}, this.state), typeof t == "function" && (t = t(D({}, n), this.props)), t && D(n, t), t != null && this.__v && (e && this._sb.push(e), he(this));
|
|
315
|
+
}, G.prototype.forceUpdate = function(t) {
|
|
316
|
+
this.__v && (this.__e = !0, t && this.__h.push(t), he(this));
|
|
317
|
+
}, G.prototype.render = B, H = [], Ee = typeof Promise == "function" ? Promise.prototype.then.bind(Promise.resolve()) : setTimeout, Ne = function(t, e) {
|
|
318
|
+
return t.__v.__b - e.__v.__b;
|
|
319
|
+
}, Y.__r = 0, Z = Math.random().toString(8), j = "__d" + Z, z = "__a" + Z, Ae = /(PointerCapture)$|Capture$/i, ce = 0, oe = ge(!1), ie = ge(!0);
|
|
320
|
+
var it = 0;
|
|
321
|
+
function m(t, e, n, r, s, o) {
|
|
322
|
+
e || (e = {});
|
|
323
|
+
var a, l, d = e;
|
|
324
|
+
if ("ref" in d) for (l in d = {}, e) l == "ref" ? a = e[l] : d[l] = e[l];
|
|
325
|
+
var c = { type: t, props: d, key: n, ref: a, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: --it, __i: -1, __u: 0, __source: s, __self: o };
|
|
326
|
+
if (typeof t == "function" && (a = t.defaultProps)) for (l in a) d[l] === void 0 && (d[l] = a[l]);
|
|
327
|
+
return v.vnode && v.vnode(c), c;
|
|
328
|
+
}
|
|
329
|
+
var L, k, ee, ve, V = 0, Me = [], S = v, we = S.__b, be = S.__r, ye = S.diffed, xe = S.__c, ke = S.unmount, Se = S.__;
|
|
330
|
+
function ue(t, e) {
|
|
331
|
+
S.__h && S.__h(k, t, V || e), V = 0;
|
|
332
|
+
var n = k.__H || (k.__H = { __: [], __h: [] });
|
|
333
|
+
return t >= n.__.length && n.__.push({}), n.__[t];
|
|
334
|
+
}
|
|
335
|
+
function A(t) {
|
|
336
|
+
return V = 1, st(Oe, t);
|
|
337
|
+
}
|
|
338
|
+
function st(t, e, n) {
|
|
339
|
+
var r = ue(L++, 2);
|
|
340
|
+
if (r.t = t, !r.__c && (r.__ = [Oe(void 0, e), function(l) {
|
|
341
|
+
var d = r.__N ? r.__N[0] : r.__[0], c = r.t(d, l);
|
|
342
|
+
d !== c && (r.__N = [c, r.__[1]], r.__c.setState({}));
|
|
343
|
+
}], r.__c = k, !k.__f)) {
|
|
344
|
+
var s = function(l, d, c) {
|
|
345
|
+
if (!r.__c.__H) return !0;
|
|
346
|
+
var f = !1, g = r.__c.props !== l;
|
|
347
|
+
if (r.__c.__H.__.some(function(_) {
|
|
348
|
+
if (_.__N) {
|
|
349
|
+
f = !0;
|
|
350
|
+
var p = _.__[0];
|
|
351
|
+
_.__ = _.__N, _.__N = void 0, p !== _.__[0] && (g = !0);
|
|
352
|
+
}
|
|
353
|
+
}), o) {
|
|
354
|
+
var i = o.call(this, l, d, c);
|
|
355
|
+
return f ? i || g : i;
|
|
356
|
+
}
|
|
357
|
+
return !f || g;
|
|
358
|
+
};
|
|
359
|
+
k.__f = !0;
|
|
360
|
+
var o = k.shouldComponentUpdate, a = k.componentWillUpdate;
|
|
361
|
+
k.componentWillUpdate = function(l, d, c) {
|
|
362
|
+
if (this.__e) {
|
|
363
|
+
var f = o;
|
|
364
|
+
o = void 0, s(l, d, c), o = f;
|
|
365
|
+
}
|
|
366
|
+
a && a.call(this, l, d, c);
|
|
367
|
+
}, k.shouldComponentUpdate = s;
|
|
368
|
+
}
|
|
369
|
+
return r.__N || r.__;
|
|
370
|
+
}
|
|
371
|
+
function te(t, e) {
|
|
372
|
+
var n = ue(L++, 3);
|
|
373
|
+
!S.__s && Be(n.__H, e) && (n.__ = t, n.u = e, k.__H.__h.push(n));
|
|
374
|
+
}
|
|
375
|
+
function ne(t) {
|
|
376
|
+
return V = 5, at(function() {
|
|
377
|
+
return { current: t };
|
|
378
|
+
}, []);
|
|
379
|
+
}
|
|
380
|
+
function at(t, e) {
|
|
381
|
+
var n = ue(L++, 7);
|
|
382
|
+
return Be(n.__H, e) && (n.__ = t(), n.__H = e, n.__h = t), n.__;
|
|
383
|
+
}
|
|
384
|
+
function Ce() {
|
|
385
|
+
for (var t; t = Me.shift(); ) {
|
|
386
|
+
var e = t.__H;
|
|
387
|
+
if (t.__P && e) try {
|
|
388
|
+
e.__h.some(se), e.__h.some(We), e.__h = [];
|
|
389
|
+
} catch (n) {
|
|
390
|
+
e.__h = [], S.__e(n, t.__v);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
S.__b = function(t) {
|
|
395
|
+
k = null, we && we(t);
|
|
396
|
+
}, S.__ = function(t, e) {
|
|
397
|
+
t && e.__k && e.__k.__m && (t.__m = e.__k.__m), Se && Se(t, e);
|
|
398
|
+
}, S.__r = function(t) {
|
|
399
|
+
be && be(t), L = 0;
|
|
400
|
+
var e = (k = t.__c).__H;
|
|
401
|
+
e && (ee === k ? (e.__h = [], k.__h = [], e.__.some(function(n) {
|
|
402
|
+
n.__N && (n.__ = n.__N), n.u = n.__N = void 0;
|
|
403
|
+
})) : (e.__h.length && Ce(), L = 0)), ee = k;
|
|
404
|
+
}, S.diffed = function(t) {
|
|
405
|
+
ye && ye(t);
|
|
406
|
+
var e = t.__c;
|
|
407
|
+
e && e.__H && (e.__H.__h.length && (Me.push(e) !== 1 && ve === S.requestAnimationFrame || ((ve = S.requestAnimationFrame) || ct)(Ce)), e.__H.__.some(function(n) {
|
|
408
|
+
n.u && (n.__H = n.u, n.u = void 0);
|
|
409
|
+
})), ee = k = null;
|
|
410
|
+
}, S.__c = function(t, e) {
|
|
411
|
+
e.some(function(n) {
|
|
412
|
+
try {
|
|
413
|
+
n.__h.some(se), n.__h = n.__h.filter(function(r) {
|
|
414
|
+
return !r.__ || We(r);
|
|
415
|
+
});
|
|
416
|
+
} catch (r) {
|
|
417
|
+
e.some(function(s) {
|
|
418
|
+
s.__h && (s.__h = []);
|
|
419
|
+
}), e = [], S.__e(r, n.__v);
|
|
420
|
+
}
|
|
421
|
+
}), xe && xe(t, e);
|
|
422
|
+
}, S.unmount = function(t) {
|
|
423
|
+
ke && ke(t);
|
|
424
|
+
var e, n = t.__c;
|
|
425
|
+
n && n.__H && (n.__H.__.some(function(r) {
|
|
426
|
+
try {
|
|
427
|
+
se(r);
|
|
428
|
+
} catch (s) {
|
|
429
|
+
e = s;
|
|
430
|
+
}
|
|
431
|
+
}), n.__H = void 0, e && S.__e(e, n.__v));
|
|
432
|
+
};
|
|
433
|
+
var $e = typeof requestAnimationFrame == "function";
|
|
434
|
+
function ct(t) {
|
|
435
|
+
var e, n = function() {
|
|
436
|
+
clearTimeout(r), $e && cancelAnimationFrame(e), setTimeout(t);
|
|
437
|
+
}, r = setTimeout(n, 35);
|
|
438
|
+
$e && (e = requestAnimationFrame(n));
|
|
439
|
+
}
|
|
440
|
+
function se(t) {
|
|
441
|
+
var e = k, n = t.__c;
|
|
442
|
+
typeof n == "function" && (t.__c = void 0, n()), k = e;
|
|
443
|
+
}
|
|
444
|
+
function We(t) {
|
|
445
|
+
var e = k;
|
|
446
|
+
t.__c = t.__(), k = e;
|
|
447
|
+
}
|
|
448
|
+
function Be(t, e) {
|
|
449
|
+
return !t || t.length !== e.length || e.some(function(n, r) {
|
|
450
|
+
return n !== t[r];
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
function Oe(t, e) {
|
|
454
|
+
return typeof e == "function" ? e(t) : e;
|
|
455
|
+
}
|
|
456
|
+
function fe(t) {
|
|
457
|
+
return `stubwise-widget:${t}:conversation`;
|
|
458
|
+
}
|
|
459
|
+
function lt(t) {
|
|
460
|
+
try {
|
|
461
|
+
return localStorage.getItem(fe(t));
|
|
462
|
+
} catch {
|
|
463
|
+
return null;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
function _t(t, e) {
|
|
467
|
+
try {
|
|
468
|
+
localStorage.setItem(fe(t), e);
|
|
469
|
+
} catch {
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
function dt(t) {
|
|
473
|
+
try {
|
|
474
|
+
localStorage.removeItem(fe(t));
|
|
475
|
+
} catch {
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
const ut = {
|
|
479
|
+
welcomeFallback: "Ciao! Come posso aiutarti?",
|
|
480
|
+
composerPlaceholder: "Scrivi un messaggio…",
|
|
481
|
+
send: "Invia",
|
|
482
|
+
openLabel: "Apri la chat di assistenza",
|
|
483
|
+
closeLabel: "Chiudi la chat",
|
|
484
|
+
assistantNote: "Risponde l'assistente AI",
|
|
485
|
+
errorGeneric: "Si è verificato un errore. Riprova tra poco.",
|
|
486
|
+
errorCapReached: "L'assistente non è disponibile oggi. Puoi comunque inviare una segnalazione descrivendo il problema.",
|
|
487
|
+
sourcePrefix: "fonte:",
|
|
488
|
+
chatDisabledNote: "La chat non è al momento disponibile.",
|
|
489
|
+
ticketBug: "bug",
|
|
490
|
+
ticketFeedback: "feedback",
|
|
491
|
+
ticketFeature: "richiesta",
|
|
492
|
+
ticketTitlePlaceholder: "Titolo",
|
|
493
|
+
ticketBodyPlaceholder: "Descrizione",
|
|
494
|
+
ticketSubmit: "Invia segnalazione",
|
|
495
|
+
ticketCancel: "Annulla",
|
|
496
|
+
ticketSent: "Segnalazione inviata",
|
|
497
|
+
ticketError: "Invio non riuscito.",
|
|
498
|
+
ticketRetry: "Riprova"
|
|
499
|
+
}, ft = {
|
|
500
|
+
welcomeFallback: "Hi! How can I help you?",
|
|
501
|
+
composerPlaceholder: "Type a message…",
|
|
502
|
+
send: "Send",
|
|
503
|
+
openLabel: "Open support chat",
|
|
504
|
+
closeLabel: "Close chat",
|
|
505
|
+
assistantNote: "You are chatting with the AI assistant",
|
|
506
|
+
errorGeneric: "Something went wrong. Please try again shortly.",
|
|
507
|
+
errorCapReached: "The assistant is unavailable today. You can still send a report describing the problem.",
|
|
508
|
+
sourcePrefix: "source:",
|
|
509
|
+
chatDisabledNote: "Chat is currently unavailable.",
|
|
510
|
+
ticketBug: "bug",
|
|
511
|
+
ticketFeedback: "feedback",
|
|
512
|
+
ticketFeature: "request",
|
|
513
|
+
ticketTitlePlaceholder: "Title",
|
|
514
|
+
ticketBodyPlaceholder: "Description",
|
|
515
|
+
ticketSubmit: "Send report",
|
|
516
|
+
ticketCancel: "Cancel",
|
|
517
|
+
ticketSent: "Report sent",
|
|
518
|
+
ticketError: "Sending failed.",
|
|
519
|
+
ticketRetry: "Retry"
|
|
520
|
+
}, Pe = { it: ut, en: ft };
|
|
521
|
+
function pt(t) {
|
|
522
|
+
return Pe[t] ?? Pe.it;
|
|
523
|
+
}
|
|
524
|
+
const ht = 1e6;
|
|
525
|
+
function mt(t) {
|
|
526
|
+
if (typeof t != "object" || t === null) return null;
|
|
527
|
+
const e = t;
|
|
528
|
+
switch (e.type) {
|
|
529
|
+
case "delta":
|
|
530
|
+
return typeof e.text == "string" ? { type: "delta", text: e.text } : null;
|
|
531
|
+
case "ticket_proposal": {
|
|
532
|
+
const n = e.proposal;
|
|
533
|
+
if (typeof n != "object" || n === null) return null;
|
|
534
|
+
const r = n;
|
|
535
|
+
return typeof r.title != "string" || typeof r.body != "string" || r.type !== "bug" && r.type !== "feedback" && r.type !== "feature" ? null : {
|
|
536
|
+
type: "ticket_proposal",
|
|
537
|
+
proposal: {
|
|
538
|
+
title: r.title,
|
|
539
|
+
body: r.body,
|
|
540
|
+
type: r.type
|
|
541
|
+
}
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
case "done":
|
|
545
|
+
return {
|
|
546
|
+
type: "done",
|
|
547
|
+
conversationId: typeof e.conversationId == "string" ? e.conversationId : "",
|
|
548
|
+
citations: Array.isArray(e.citations) ? e.citations : []
|
|
549
|
+
};
|
|
550
|
+
case "error":
|
|
551
|
+
return {
|
|
552
|
+
type: "error",
|
|
553
|
+
...typeof e.message == "string" ? { message: e.message } : {}
|
|
554
|
+
};
|
|
555
|
+
default:
|
|
556
|
+
return null;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
async function gt(t, e) {
|
|
560
|
+
const n = t.body;
|
|
561
|
+
if (!n) return;
|
|
562
|
+
const r = n.getReader(), s = new TextDecoder();
|
|
563
|
+
let o = "";
|
|
564
|
+
try {
|
|
565
|
+
for (; ; ) {
|
|
566
|
+
const { done: a, value: l } = await r.read();
|
|
567
|
+
if (a) break;
|
|
568
|
+
if (o += s.decode(l, { stream: !0 }), o.length > ht) {
|
|
569
|
+
e({ type: "error", message: "stream buffer overflow" });
|
|
570
|
+
break;
|
|
571
|
+
}
|
|
572
|
+
let d;
|
|
573
|
+
for (; (d = o.indexOf(`
|
|
574
|
+
|
|
575
|
+
`)) !== -1; ) {
|
|
576
|
+
const c = o.slice(0, d);
|
|
577
|
+
o = o.slice(d + 2);
|
|
578
|
+
const f = c.trim();
|
|
579
|
+
if (!f.startsWith("data:")) continue;
|
|
580
|
+
const g = f.slice(5).trim();
|
|
581
|
+
if (!g) continue;
|
|
582
|
+
let i;
|
|
583
|
+
try {
|
|
584
|
+
i = JSON.parse(g);
|
|
585
|
+
} catch {
|
|
586
|
+
continue;
|
|
587
|
+
}
|
|
588
|
+
const _ = mt(i);
|
|
589
|
+
_ && e(_);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
} finally {
|
|
593
|
+
await r.cancel().catch(() => {
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
function vt(t, e) {
|
|
598
|
+
return t === "bug" ? e.ticketBug : t === "feedback" ? e.ticketFeedback : e.ticketFeature;
|
|
599
|
+
}
|
|
600
|
+
function wt({ proposal: t, strings: e, onConfirm: n, onCancel: r }) {
|
|
601
|
+
const [s, o] = A(t.title), [a, l] = A(t.body), [d, c] = A("form"), [f, g] = A(null), [i, _] = A(!1);
|
|
602
|
+
if (d === "confirmed")
|
|
603
|
+
return /* @__PURE__ */ m("div", { class: "sw-card", children: /* @__PURE__ */ m("div", { class: "sw-card-confirmed", children: [
|
|
604
|
+
"✓ ",
|
|
605
|
+
e.ticketSent,
|
|
606
|
+
f !== null ? ` #${f}` : ""
|
|
607
|
+
] }) });
|
|
608
|
+
const p = d === "sending";
|
|
609
|
+
async function P() {
|
|
610
|
+
c("sending"), _(!1);
|
|
611
|
+
try {
|
|
612
|
+
const { number: w } = await n({ title: s, body: a });
|
|
613
|
+
g(w), c("confirmed");
|
|
614
|
+
} catch {
|
|
615
|
+
_(!0), c("form");
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
return /* @__PURE__ */ m("div", { class: "sw-card", children: [
|
|
619
|
+
/* @__PURE__ */ m("span", { class: "sw-badge", children: vt(t.type, e) }),
|
|
620
|
+
/* @__PURE__ */ m(
|
|
621
|
+
"input",
|
|
622
|
+
{
|
|
623
|
+
class: "sw-input",
|
|
624
|
+
value: s,
|
|
625
|
+
placeholder: e.ticketTitlePlaceholder,
|
|
626
|
+
disabled: p,
|
|
627
|
+
onInput: (w) => o(w.target.value)
|
|
628
|
+
}
|
|
629
|
+
),
|
|
630
|
+
/* @__PURE__ */ m(
|
|
631
|
+
"textarea",
|
|
632
|
+
{
|
|
633
|
+
class: "sw-textarea",
|
|
634
|
+
value: a,
|
|
635
|
+
placeholder: e.ticketBodyPlaceholder,
|
|
636
|
+
disabled: p,
|
|
637
|
+
onInput: (w) => l(w.target.value)
|
|
638
|
+
}
|
|
639
|
+
),
|
|
640
|
+
i ? /* @__PURE__ */ m("div", { class: "sw-card-msg", children: e.ticketError }) : null,
|
|
641
|
+
/* @__PURE__ */ m("div", { class: "sw-card-actions", children: [
|
|
642
|
+
/* @__PURE__ */ m("button", { class: "sw-btn", disabled: p, onClick: P, children: i ? e.ticketRetry : e.ticketSubmit }),
|
|
643
|
+
/* @__PURE__ */ m("button", { class: "sw-btn sw-btn-secondary", disabled: p, onClick: r, children: e.ticketCancel })
|
|
644
|
+
] })
|
|
645
|
+
] });
|
|
646
|
+
}
|
|
647
|
+
function bt(t) {
|
|
648
|
+
const e = t.title;
|
|
649
|
+
return typeof e == "string" ? e : null;
|
|
650
|
+
}
|
|
651
|
+
let Te = 0;
|
|
652
|
+
function R() {
|
|
653
|
+
return Te += 1, `m${Te}`;
|
|
654
|
+
}
|
|
655
|
+
function yt({
|
|
656
|
+
base: t,
|
|
657
|
+
user: e,
|
|
658
|
+
strings: n,
|
|
659
|
+
welcomeMessage: r,
|
|
660
|
+
chatEnabled: s,
|
|
661
|
+
initialConversationId: o
|
|
662
|
+
}) {
|
|
663
|
+
const [a, l] = A([]), [d, c] = A(""), [f, g] = A(!1), i = ne(o), _ = ne(null), p = ne(null);
|
|
664
|
+
te(() => () => {
|
|
665
|
+
p.current?.abort();
|
|
666
|
+
}, []), te(() => {
|
|
667
|
+
let u = !1;
|
|
668
|
+
async function $() {
|
|
669
|
+
const C = i.current;
|
|
670
|
+
if (!C) {
|
|
671
|
+
l([{ kind: "assistant", id: R(), text: r, citations: [] }]);
|
|
672
|
+
return;
|
|
673
|
+
}
|
|
674
|
+
try {
|
|
675
|
+
const { messages: x } = await Je(t, C, e.id);
|
|
676
|
+
if (u) return;
|
|
677
|
+
if (x.length === 0) {
|
|
678
|
+
l([{ kind: "assistant", id: R(), text: r, citations: [] }]);
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
l(
|
|
682
|
+
x.map(
|
|
683
|
+
(E) => E.role === "user" ? { kind: "user", id: E.id, text: E.content } : {
|
|
684
|
+
kind: "assistant",
|
|
685
|
+
id: E.id,
|
|
686
|
+
text: E.content,
|
|
687
|
+
citations: Array.isArray(E.citations) ? E.citations : []
|
|
688
|
+
}
|
|
689
|
+
)
|
|
690
|
+
);
|
|
691
|
+
} catch (x) {
|
|
692
|
+
if (u) return;
|
|
693
|
+
x instanceof re && x.status === 404 ? (i.current = null, dt(t.slug), l([{ kind: "assistant", id: R(), text: r, citations: [] }])) : l([{ kind: "assistant", id: R(), text: r, citations: [] }]);
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
return $(), () => {
|
|
697
|
+
u = !0;
|
|
698
|
+
};
|
|
699
|
+
}, []), te(() => {
|
|
700
|
+
const u = _.current;
|
|
701
|
+
u && (u.scrollTop = u.scrollHeight);
|
|
702
|
+
}, [a]);
|
|
703
|
+
async function P() {
|
|
704
|
+
if (i.current) return i.current;
|
|
705
|
+
const { conversationId: u } = await Ke(t, e);
|
|
706
|
+
return i.current = u, _t(t.slug, u), u;
|
|
707
|
+
}
|
|
708
|
+
async function w() {
|
|
709
|
+
const u = d.trim();
|
|
710
|
+
if (!u || f) return;
|
|
711
|
+
c(""), g(!0);
|
|
712
|
+
const $ = { kind: "user", id: R(), text: u }, C = R();
|
|
713
|
+
l((T) => [
|
|
714
|
+
...T,
|
|
715
|
+
$,
|
|
716
|
+
{ kind: "assistant", id: C, text: "", citations: [] }
|
|
717
|
+
]);
|
|
718
|
+
function x(T) {
|
|
719
|
+
l(
|
|
720
|
+
(N) => N.map((b) => b.kind === "assistant" && b.id === C ? T(b) : b)
|
|
721
|
+
);
|
|
722
|
+
}
|
|
723
|
+
const E = new AbortController();
|
|
724
|
+
p.current = E;
|
|
725
|
+
try {
|
|
726
|
+
const T = await P(), N = await Ye(
|
|
727
|
+
t,
|
|
728
|
+
T,
|
|
729
|
+
{ content: u, userId: e.id },
|
|
730
|
+
E.signal
|
|
731
|
+
);
|
|
732
|
+
await gt(N, (b) => {
|
|
733
|
+
b.type === "delta" ? x((I) => ({ ...I, text: I.text + b.text })) : b.type === "ticket_proposal" ? l((I) => [
|
|
734
|
+
...I,
|
|
735
|
+
{ kind: "ticket", id: R(), proposal: b.proposal }
|
|
736
|
+
]) : b.type === "done" ? x((I) => ({ ...I, citations: b.citations })) : b.type === "error" && x((I) => ({ ...I, text: I.text || n.errorGeneric }));
|
|
737
|
+
});
|
|
738
|
+
} catch (T) {
|
|
739
|
+
if (T instanceof DOMException && T.name === "AbortError") return;
|
|
740
|
+
const N = T instanceof re && (T.status === 429 || T.code === "widget_chat_cap_reached");
|
|
741
|
+
x((b) => ({
|
|
742
|
+
...b,
|
|
743
|
+
text: N ? n.errorCapReached : n.errorGeneric
|
|
744
|
+
}));
|
|
745
|
+
} finally {
|
|
746
|
+
p.current === E && (p.current = null), g(!1);
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
async function y(u, $) {
|
|
750
|
+
const C = await P(), { number: x } = await Ve(t, C, {
|
|
751
|
+
title: $.title,
|
|
752
|
+
body: $.body,
|
|
753
|
+
type: u.type,
|
|
754
|
+
userId: e.id
|
|
755
|
+
});
|
|
756
|
+
return { number: x };
|
|
757
|
+
}
|
|
758
|
+
function h(u) {
|
|
759
|
+
l(($) => $.filter((C) => C.id !== u));
|
|
760
|
+
}
|
|
761
|
+
return /* @__PURE__ */ m(B, { children: [
|
|
762
|
+
/* @__PURE__ */ m("div", { class: "sw-messages", ref: _, children: a.map((u) => u.kind === "ticket" ? /* @__PURE__ */ m(
|
|
763
|
+
wt,
|
|
764
|
+
{
|
|
765
|
+
proposal: u.proposal,
|
|
766
|
+
strings: n,
|
|
767
|
+
onConfirm: ($) => y(u.proposal, $),
|
|
768
|
+
onCancel: () => h(u.id)
|
|
769
|
+
},
|
|
770
|
+
u.id
|
|
771
|
+
) : u.kind === "user" ? /* @__PURE__ */ m("div", { class: "sw-msg sw-msg-user", children: u.text }, u.id) : /* @__PURE__ */ m("div", { children: [
|
|
772
|
+
/* @__PURE__ */ m("div", { class: "sw-msg sw-msg-assistant", children: u.text }),
|
|
773
|
+
u.citations.map(($, C) => {
|
|
774
|
+
const x = bt($);
|
|
775
|
+
return x ? /* @__PURE__ */ m("div", { class: "sw-citation", children: [
|
|
776
|
+
n.sourcePrefix,
|
|
777
|
+
" ",
|
|
778
|
+
x
|
|
779
|
+
] }, C) : null;
|
|
780
|
+
})
|
|
781
|
+
] }, u.id)) }),
|
|
782
|
+
s ? /* @__PURE__ */ m("div", { class: "sw-composer", children: [
|
|
783
|
+
/* @__PURE__ */ m(
|
|
784
|
+
"textarea",
|
|
785
|
+
{
|
|
786
|
+
class: "sw-composer-input",
|
|
787
|
+
rows: 1,
|
|
788
|
+
value: d,
|
|
789
|
+
placeholder: n.composerPlaceholder,
|
|
790
|
+
"aria-label": n.composerPlaceholder,
|
|
791
|
+
disabled: f,
|
|
792
|
+
onInput: (u) => c(u.target.value),
|
|
793
|
+
onKeyDown: (u) => {
|
|
794
|
+
u.key === "Enter" && !u.shiftKey && (u.preventDefault(), w());
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
),
|
|
798
|
+
/* @__PURE__ */ m(
|
|
799
|
+
"button",
|
|
800
|
+
{
|
|
801
|
+
class: "sw-btn",
|
|
802
|
+
disabled: f || d.trim().length === 0,
|
|
803
|
+
"aria-label": n.send,
|
|
804
|
+
onClick: () => {
|
|
805
|
+
w();
|
|
806
|
+
},
|
|
807
|
+
children: n.send
|
|
808
|
+
}
|
|
809
|
+
)
|
|
810
|
+
] }) : /* @__PURE__ */ m("div", { class: "sw-composer", children: /* @__PURE__ */ m("div", { class: "sw-composer-note", children: n.chatDisabledNote }) })
|
|
811
|
+
] });
|
|
812
|
+
}
|
|
813
|
+
function xt(t) {
|
|
814
|
+
return `
|
|
815
|
+
:host {
|
|
816
|
+
--sw-accent: ${/^#[0-9a-fA-F]{3,8}$/.test(t) ? t : "#3b82f6"};
|
|
817
|
+
--sw-bg: #ffffff;
|
|
818
|
+
--sw-fg: #1a1a1a;
|
|
819
|
+
--sw-muted: #6b7280;
|
|
820
|
+
--sw-border: #e5e7eb;
|
|
821
|
+
--sw-panel-bg: #f9fafb;
|
|
822
|
+
all: initial;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
.sw-root, .sw-root * {
|
|
826
|
+
box-sizing: border-box;
|
|
827
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
/* Bolla lanciatrice, fissa in basso a destra. */
|
|
831
|
+
.sw-bubble {
|
|
832
|
+
position: fixed;
|
|
833
|
+
bottom: 20px;
|
|
834
|
+
right: 20px;
|
|
835
|
+
width: 56px;
|
|
836
|
+
height: 56px;
|
|
837
|
+
border-radius: 50%;
|
|
838
|
+
border: none;
|
|
839
|
+
background: var(--sw-accent);
|
|
840
|
+
color: #fff;
|
|
841
|
+
cursor: pointer;
|
|
842
|
+
z-index: 2147483000;
|
|
843
|
+
display: flex;
|
|
844
|
+
align-items: center;
|
|
845
|
+
justify-content: center;
|
|
846
|
+
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.24);
|
|
847
|
+
font-size: 24px;
|
|
848
|
+
line-height: 1;
|
|
849
|
+
padding: 0;
|
|
850
|
+
}
|
|
851
|
+
.sw-bubble:hover { filter: brightness(1.05); }
|
|
852
|
+
|
|
853
|
+
/* Pannello chat. */
|
|
854
|
+
.sw-panel {
|
|
855
|
+
position: fixed;
|
|
856
|
+
bottom: 88px;
|
|
857
|
+
right: 20px;
|
|
858
|
+
width: 380px;
|
|
859
|
+
height: 600px;
|
|
860
|
+
max-height: calc(100vh - 108px);
|
|
861
|
+
background: var(--sw-bg);
|
|
862
|
+
color: var(--sw-fg);
|
|
863
|
+
border: 1px solid var(--sw-border);
|
|
864
|
+
border-radius: 12px;
|
|
865
|
+
box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
|
|
866
|
+
z-index: 2147483000;
|
|
867
|
+
display: flex;
|
|
868
|
+
flex-direction: column;
|
|
869
|
+
overflow: hidden;
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
.sw-header {
|
|
873
|
+
background: var(--sw-accent);
|
|
874
|
+
color: #fff;
|
|
875
|
+
padding: 14px 16px;
|
|
876
|
+
flex: 0 0 auto;
|
|
877
|
+
}
|
|
878
|
+
.sw-header-title { font-size: 15px; font-weight: 600; }
|
|
879
|
+
.sw-header-note { font-size: 12px; opacity: 0.85; margin-top: 2px; }
|
|
880
|
+
|
|
881
|
+
.sw-messages {
|
|
882
|
+
flex: 1 1 auto;
|
|
883
|
+
overflow-y: auto;
|
|
884
|
+
padding: 14px;
|
|
885
|
+
display: flex;
|
|
886
|
+
flex-direction: column;
|
|
887
|
+
gap: 10px;
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
.sw-msg {
|
|
891
|
+
max-width: 85%;
|
|
892
|
+
padding: 8px 12px;
|
|
893
|
+
border-radius: 12px;
|
|
894
|
+
font-size: 14px;
|
|
895
|
+
line-height: 1.4;
|
|
896
|
+
white-space: pre-wrap;
|
|
897
|
+
word-break: break-word;
|
|
898
|
+
}
|
|
899
|
+
.sw-msg-user {
|
|
900
|
+
align-self: flex-end;
|
|
901
|
+
background: var(--sw-accent);
|
|
902
|
+
color: #fff;
|
|
903
|
+
border-bottom-right-radius: 4px;
|
|
904
|
+
}
|
|
905
|
+
.sw-msg-assistant {
|
|
906
|
+
align-self: flex-start;
|
|
907
|
+
background: var(--sw-panel-bg);
|
|
908
|
+
color: var(--sw-fg);
|
|
909
|
+
border: 1px solid var(--sw-border);
|
|
910
|
+
border-bottom-left-radius: 4px;
|
|
911
|
+
}
|
|
912
|
+
.sw-citation {
|
|
913
|
+
font-size: 11px;
|
|
914
|
+
color: var(--sw-muted);
|
|
915
|
+
margin-top: 2px;
|
|
916
|
+
align-self: flex-start;
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
/* Card ticket. */
|
|
920
|
+
.sw-card {
|
|
921
|
+
align-self: stretch;
|
|
922
|
+
border: 1px solid var(--sw-border);
|
|
923
|
+
border-radius: 10px;
|
|
924
|
+
padding: 12px;
|
|
925
|
+
background: var(--sw-panel-bg);
|
|
926
|
+
display: flex;
|
|
927
|
+
flex-direction: column;
|
|
928
|
+
gap: 8px;
|
|
929
|
+
}
|
|
930
|
+
.sw-badge {
|
|
931
|
+
align-self: flex-start;
|
|
932
|
+
font-size: 11px;
|
|
933
|
+
font-weight: 600;
|
|
934
|
+
text-transform: uppercase;
|
|
935
|
+
letter-spacing: 0.04em;
|
|
936
|
+
padding: 2px 8px;
|
|
937
|
+
border-radius: 999px;
|
|
938
|
+
background: var(--sw-accent);
|
|
939
|
+
color: #fff;
|
|
940
|
+
}
|
|
941
|
+
.sw-input, .sw-textarea {
|
|
942
|
+
width: 100%;
|
|
943
|
+
border: 1px solid var(--sw-border);
|
|
944
|
+
border-radius: 8px;
|
|
945
|
+
padding: 8px 10px;
|
|
946
|
+
font-size: 14px;
|
|
947
|
+
color: var(--sw-fg);
|
|
948
|
+
background: #fff;
|
|
949
|
+
}
|
|
950
|
+
.sw-textarea { resize: vertical; min-height: 72px; }
|
|
951
|
+
.sw-card-actions { display: flex; gap: 8px; }
|
|
952
|
+
.sw-card-msg { font-size: 12px; color: #b91c1c; }
|
|
953
|
+
.sw-card-confirmed { font-size: 14px; font-weight: 600; color: #15803d; }
|
|
954
|
+
|
|
955
|
+
/* Composer. */
|
|
956
|
+
.sw-composer {
|
|
957
|
+
flex: 0 0 auto;
|
|
958
|
+
border-top: 1px solid var(--sw-border);
|
|
959
|
+
padding: 10px;
|
|
960
|
+
display: flex;
|
|
961
|
+
gap: 8px;
|
|
962
|
+
align-items: flex-end;
|
|
963
|
+
}
|
|
964
|
+
.sw-composer-input {
|
|
965
|
+
flex: 1 1 auto;
|
|
966
|
+
border: 1px solid var(--sw-border);
|
|
967
|
+
border-radius: 8px;
|
|
968
|
+
padding: 8px 10px;
|
|
969
|
+
font-size: 14px;
|
|
970
|
+
resize: none;
|
|
971
|
+
max-height: 96px;
|
|
972
|
+
color: var(--sw-fg);
|
|
973
|
+
background: #fff;
|
|
974
|
+
}
|
|
975
|
+
.sw-composer-note {
|
|
976
|
+
flex: 1 1 auto;
|
|
977
|
+
font-size: 12px;
|
|
978
|
+
color: var(--sw-muted);
|
|
979
|
+
padding: 8px 4px;
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
.sw-btn {
|
|
983
|
+
border: none;
|
|
984
|
+
border-radius: 8px;
|
|
985
|
+
padding: 8px 14px;
|
|
986
|
+
font-size: 13px;
|
|
987
|
+
font-weight: 600;
|
|
988
|
+
cursor: pointer;
|
|
989
|
+
background: var(--sw-accent);
|
|
990
|
+
color: #fff;
|
|
991
|
+
}
|
|
992
|
+
.sw-btn:disabled { opacity: 0.5; cursor: default; }
|
|
993
|
+
.sw-btn-secondary {
|
|
994
|
+
background: transparent;
|
|
995
|
+
color: var(--sw-fg);
|
|
996
|
+
border: 1px solid var(--sw-border);
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
/* Full-screen sotto 480px. */
|
|
1000
|
+
@media (max-width: 480px) {
|
|
1001
|
+
.sw-panel {
|
|
1002
|
+
inset: 0;
|
|
1003
|
+
width: 100%;
|
|
1004
|
+
height: 100%;
|
|
1005
|
+
max-height: 100%;
|
|
1006
|
+
border-radius: 0;
|
|
1007
|
+
border: none;
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
`;
|
|
1011
|
+
}
|
|
1012
|
+
function kt({ base: t, config: e, user: n }) {
|
|
1013
|
+
const [r, s] = A(!1), o = pt(e.language);
|
|
1014
|
+
return /* @__PURE__ */ m("div", { class: "sw-root", children: [
|
|
1015
|
+
r ? /* @__PURE__ */ m("div", { class: "sw-panel", role: "dialog", "aria-label": e.title, children: [
|
|
1016
|
+
/* @__PURE__ */ m("div", { class: "sw-header", children: [
|
|
1017
|
+
/* @__PURE__ */ m("div", { class: "sw-header-title", children: e.title }),
|
|
1018
|
+
/* @__PURE__ */ m("div", { class: "sw-header-note", children: o.assistantNote })
|
|
1019
|
+
] }),
|
|
1020
|
+
/* @__PURE__ */ m(
|
|
1021
|
+
yt,
|
|
1022
|
+
{
|
|
1023
|
+
base: t,
|
|
1024
|
+
user: n,
|
|
1025
|
+
strings: o,
|
|
1026
|
+
welcomeMessage: e.welcomeMessage || o.welcomeFallback,
|
|
1027
|
+
chatEnabled: e.chatEnabled,
|
|
1028
|
+
initialConversationId: lt(t.slug)
|
|
1029
|
+
}
|
|
1030
|
+
)
|
|
1031
|
+
] }) : null,
|
|
1032
|
+
/* @__PURE__ */ m(
|
|
1033
|
+
"button",
|
|
1034
|
+
{
|
|
1035
|
+
class: "sw-bubble",
|
|
1036
|
+
"aria-label": r ? o.closeLabel : o.openLabel,
|
|
1037
|
+
onClick: () => s((a) => !a),
|
|
1038
|
+
children: r ? "✕" : "💬"
|
|
1039
|
+
}
|
|
1040
|
+
)
|
|
1041
|
+
] });
|
|
1042
|
+
}
|
|
1043
|
+
function St(t, e, n) {
|
|
1044
|
+
const r = document.createElement("div");
|
|
1045
|
+
r.setAttribute("data-stubwise-widget", ""), document.body.appendChild(r);
|
|
1046
|
+
const s = r.attachShadow({ mode: "open" }), o = document.createElement("style");
|
|
1047
|
+
o.textContent = xt(e.accentColor), s.appendChild(o);
|
|
1048
|
+
const a = document.createElement("div");
|
|
1049
|
+
return s.appendChild(a), ot(/* @__PURE__ */ m(kt, { base: t, config: e, user: n }), a), r;
|
|
1050
|
+
}
|
|
1051
|
+
let ae = !1;
|
|
1052
|
+
function Pt() {
|
|
1053
|
+
ae = !1;
|
|
1054
|
+
}
|
|
1055
|
+
function Ct(t) {
|
|
1056
|
+
if (!(typeof document > "u")) {
|
|
1057
|
+
if (document.body) {
|
|
1058
|
+
t();
|
|
1059
|
+
return;
|
|
1060
|
+
}
|
|
1061
|
+
document.addEventListener("DOMContentLoaded", t, { once: !0 });
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
async function $t(t) {
|
|
1065
|
+
try {
|
|
1066
|
+
if (typeof document > "u" || ae) return;
|
|
1067
|
+
ae = !0;
|
|
1068
|
+
const e = qe(t.dsn), n = await Ge(e);
|
|
1069
|
+
if (!n.enabled) return;
|
|
1070
|
+
Ct(() => St(e, n, t.user));
|
|
1071
|
+
} catch (e) {
|
|
1072
|
+
console.warn("[stubwise] widget init non riuscito:", e);
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
typeof window < "u" && (window.Stubwise = {
|
|
1076
|
+
initWidget: $t
|
|
1077
|
+
}, window.dispatchEvent(new Event("stubwise:ready")));
|
|
1078
|
+
export {
|
|
1079
|
+
re as WidgetApiError,
|
|
1080
|
+
Pt as __resetWidgetForTests,
|
|
1081
|
+
dt as clearConversationId,
|
|
1082
|
+
Ve as confirmTicket,
|
|
1083
|
+
Ke as createConversation,
|
|
1084
|
+
Ge as fetchConfig,
|
|
1085
|
+
Je as fetchMessages,
|
|
1086
|
+
lt as getConversationId,
|
|
1087
|
+
$t as initWidget,
|
|
1088
|
+
gt as parseSseStream,
|
|
1089
|
+
qe as parseWidgetDsn,
|
|
1090
|
+
Ye as sendMessage,
|
|
1091
|
+
_t as setConversationId,
|
|
1092
|
+
Ct as whenBodyReady
|
|
1093
|
+
};
|