@ownhelp/widget 0.1.0 → 0.1.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/API_CONTRACT.md +14 -3
- package/README.md +17 -3
- package/dist/lib/index.js +436 -300
- package/dist/widget.js +62 -12
- package/package.json +1 -1
package/dist/lib/index.js
CHANGED
|
@@ -1,264 +1,279 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { useState as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { jsxs as g, jsx as s, Fragment as Pe } from "react/jsx-runtime";
|
|
2
|
+
import { useState as h, useRef as $, useCallback as Z, useLayoutEffect as Ae, useEffect as z } from "react";
|
|
3
|
+
import { createPortal as Re } from "react-dom";
|
|
4
|
+
function xe(t) {
|
|
5
|
+
if (typeof t != "string" || t.length > 50) return;
|
|
6
|
+
const e = t.trim(), r = /^(\+?[0-9 ().-]+?)(?:\s*[xX#]\s*(\d+))?$/.exec(e);
|
|
6
7
|
if (!r || !/\d/.test(r[1])) return;
|
|
7
8
|
const n = r[1].replace(/[^+0-9]/g, "");
|
|
8
|
-
return { display:
|
|
9
|
+
return { display: e, uri: `tel:${n}${r[2] ? `;ext=${r[2]}` : ""}` };
|
|
9
10
|
}
|
|
10
|
-
function
|
|
11
|
-
if (!
|
|
12
|
-
const
|
|
13
|
-
typeof
|
|
14
|
-
const r =
|
|
15
|
-
return r && (
|
|
11
|
+
function oe(t) {
|
|
12
|
+
if (!t || t.available !== !0 || typeof t.token != "string" || !t.token.trim()) return;
|
|
13
|
+
const e = { available: !0, token: t.token };
|
|
14
|
+
typeof t.contact_email == "string" && /^[A-Za-z0-9.!#$%&'*+/=?^_`{|}~-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/.test(t.contact_email) && (e.contactEmail = t.contact_email);
|
|
15
|
+
const r = xe(t.contact_phone);
|
|
16
|
+
return r && (e.contactPhone = r.display), e;
|
|
16
17
|
}
|
|
17
|
-
function
|
|
18
|
-
const
|
|
18
|
+
function Le(t) {
|
|
19
|
+
const e = oe({
|
|
19
20
|
available: !0,
|
|
20
|
-
token:
|
|
21
|
-
contact_email:
|
|
22
|
-
contact_phone:
|
|
21
|
+
token: t?.token,
|
|
22
|
+
contact_email: t?.contactEmail,
|
|
23
|
+
contact_phone: t?.contactPhone
|
|
23
24
|
});
|
|
24
25
|
return {
|
|
25
|
-
email:
|
|
26
|
-
phone:
|
|
26
|
+
email: e?.contactEmail ? `mailto:${encodeURIComponent(e.contactEmail)}` : void 0,
|
|
27
|
+
phone: xe(e?.contactPhone)?.uri
|
|
27
28
|
};
|
|
28
29
|
}
|
|
29
|
-
function
|
|
30
|
-
let
|
|
31
|
-
const
|
|
30
|
+
function Oe() {
|
|
31
|
+
let t = 0;
|
|
32
|
+
const e = /* @__PURE__ */ new Set();
|
|
32
33
|
return {
|
|
33
34
|
begin() {
|
|
34
|
-
const r =
|
|
35
|
-
return
|
|
35
|
+
const r = t, n = new AbortController();
|
|
36
|
+
return e.add(n), {
|
|
36
37
|
signal: n.signal,
|
|
37
38
|
abort: () => n.abort(),
|
|
38
|
-
isCurrent: () => r ===
|
|
39
|
-
finish: () =>
|
|
39
|
+
isCurrent: () => r === t,
|
|
40
|
+
finish: () => e.delete(n)
|
|
40
41
|
};
|
|
41
42
|
},
|
|
42
43
|
reset() {
|
|
43
|
-
|
|
44
|
-
for (const r of
|
|
45
|
-
|
|
44
|
+
t += 1;
|
|
45
|
+
for (const r of e) r.abort();
|
|
46
|
+
e.clear();
|
|
46
47
|
}
|
|
47
48
|
};
|
|
48
49
|
}
|
|
49
|
-
function
|
|
50
|
-
let
|
|
51
|
-
function
|
|
52
|
-
n.length > 0 &&
|
|
50
|
+
function ze(t) {
|
|
51
|
+
let e = "", r = "message", n = [];
|
|
52
|
+
function i() {
|
|
53
|
+
n.length > 0 && t({ event: r, data: n.join(`
|
|
53
54
|
`) }), r = "message", n = [];
|
|
54
55
|
}
|
|
55
|
-
function
|
|
56
|
-
if (
|
|
57
|
-
|
|
56
|
+
function f(u) {
|
|
57
|
+
if (u === "") {
|
|
58
|
+
i();
|
|
58
59
|
return;
|
|
59
60
|
}
|
|
60
|
-
if (
|
|
61
|
+
if (u.startsWith(":"))
|
|
61
62
|
return;
|
|
62
|
-
const
|
|
63
|
-
let d =
|
|
63
|
+
const l = u.indexOf(":"), a = l === -1 ? u : u.slice(0, l);
|
|
64
|
+
let d = l === -1 ? "" : u.slice(l + 1);
|
|
64
65
|
d.startsWith(" ") && (d = d.slice(1)), a === "event" ? r = d : a === "data" && n.push(d);
|
|
65
66
|
}
|
|
66
67
|
return {
|
|
67
|
-
push(
|
|
68
|
-
|
|
69
|
-
let
|
|
70
|
-
for (; (
|
|
71
|
-
const a =
|
|
72
|
-
`,
|
|
73
|
-
if (!a &&
|
|
68
|
+
push(u) {
|
|
69
|
+
e += u;
|
|
70
|
+
let l;
|
|
71
|
+
for (; (l = e.search(/\r\n|\n|\r/)) !== -1; ) {
|
|
72
|
+
const a = e.startsWith(`\r
|
|
73
|
+
`, l);
|
|
74
|
+
if (!a && e[l] === "\r" && l === e.length - 1)
|
|
74
75
|
return;
|
|
75
|
-
const d =
|
|
76
|
-
|
|
76
|
+
const d = e.slice(0, l);
|
|
77
|
+
e = e.slice(l + (a ? 2 : 1)), f(d);
|
|
77
78
|
}
|
|
78
79
|
},
|
|
79
80
|
/** Call when the stream ends; dispatches nothing that was not terminated by a blank line. */
|
|
80
81
|
flush() {
|
|
81
|
-
|
|
82
|
+
e = "", r = "message", n = [];
|
|
82
83
|
}
|
|
83
84
|
};
|
|
84
85
|
}
|
|
85
|
-
class
|
|
86
|
-
constructor(
|
|
87
|
-
super(r), this.name = "ChatError", this.code =
|
|
86
|
+
class b extends Error {
|
|
87
|
+
constructor(e, r, n, i) {
|
|
88
|
+
super(r), this.name = "ChatError", this.code = e, this.status = n, this.retryAfterSec = i;
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
|
-
const
|
|
91
|
-
function
|
|
92
|
-
return `${String(
|
|
91
|
+
const Me = 3e4;
|
|
92
|
+
function ae(t) {
|
|
93
|
+
return `${String(t).replace(/\/+$/, "")}/api/chat`;
|
|
93
94
|
}
|
|
94
|
-
async function
|
|
95
|
-
let
|
|
95
|
+
async function ye(t) {
|
|
96
|
+
let e = `http_${t.status}`, r = `Request failed (${t.status})`;
|
|
96
97
|
try {
|
|
97
|
-
const
|
|
98
|
-
|
|
98
|
+
const i = await t.json();
|
|
99
|
+
i && i.error && (e = i.error.code || e, r = i.error.message || r);
|
|
99
100
|
} catch {
|
|
100
101
|
}
|
|
101
|
-
const n = Number(
|
|
102
|
-
return new
|
|
102
|
+
const n = Number(t.headers && t.headers.get && t.headers.get("retry-after"));
|
|
103
|
+
return new b(e, r, t.status, Number.isFinite(n) && n > 0 ? n : void 0);
|
|
103
104
|
}
|
|
104
|
-
async function
|
|
105
|
-
apiUrl:
|
|
106
|
-
tenantId:
|
|
105
|
+
async function je({
|
|
106
|
+
apiUrl: t,
|
|
107
|
+
tenantId: e,
|
|
107
108
|
message: r,
|
|
108
109
|
sessionId: n,
|
|
109
|
-
|
|
110
|
-
|
|
110
|
+
recordingNotice: i = !1,
|
|
111
|
+
signal: f,
|
|
112
|
+
onToken: u = () => {
|
|
111
113
|
},
|
|
112
|
-
idleTimeoutMs: l =
|
|
113
|
-
fetchImpl:
|
|
114
|
+
idleTimeoutMs: l = Me,
|
|
115
|
+
fetchImpl: a = (...d) => fetch(...d)
|
|
114
116
|
}) {
|
|
115
|
-
const
|
|
116
|
-
let
|
|
117
|
-
const
|
|
118
|
-
l && (clearTimeout(
|
|
119
|
-
|
|
117
|
+
const d = new AbortController();
|
|
118
|
+
let A = !1, T = null;
|
|
119
|
+
const M = () => {
|
|
120
|
+
l && (clearTimeout(T), T = setTimeout(() => {
|
|
121
|
+
A = !0, d.abort();
|
|
120
122
|
}, l));
|
|
121
|
-
},
|
|
122
|
-
if (
|
|
123
|
-
if (
|
|
124
|
-
throw new
|
|
125
|
-
|
|
123
|
+
}, R = () => d.abort();
|
|
124
|
+
if (f) {
|
|
125
|
+
if (f.aborted)
|
|
126
|
+
throw new b("aborted", "Request cancelled");
|
|
127
|
+
f.addEventListener("abort", R, { once: !0 });
|
|
126
128
|
}
|
|
127
|
-
const
|
|
129
|
+
const Q = (p) => p instanceof b ? p : A ? new b("timeout", "The assistant took too long to respond") : d.signal.aborted ? new b("aborted", "Request cancelled") : new b("network_error", "Could not reach the support service");
|
|
128
130
|
try {
|
|
129
|
-
|
|
130
|
-
const
|
|
131
|
+
M();
|
|
132
|
+
const p = await a(ae(t), {
|
|
131
133
|
method: "POST",
|
|
132
134
|
headers: {
|
|
133
135
|
"Content-Type": "application/json",
|
|
134
136
|
Accept: "text/event-stream, application/json"
|
|
135
137
|
},
|
|
136
138
|
body: JSON.stringify({
|
|
137
|
-
tenant_id:
|
|
139
|
+
tenant_id: e,
|
|
138
140
|
message: r,
|
|
139
|
-
session_id: n
|
|
141
|
+
session_id: n,
|
|
142
|
+
...i === !0 ? { recording_notice: !0 } : {}
|
|
140
143
|
}),
|
|
141
|
-
signal:
|
|
144
|
+
signal: d.signal
|
|
142
145
|
});
|
|
143
|
-
if (!
|
|
144
|
-
throw await
|
|
145
|
-
if (!(
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
const
|
|
149
|
-
return { answer:
|
|
146
|
+
if (!p.ok)
|
|
147
|
+
throw await ye(p);
|
|
148
|
+
if (!(p.headers.get("content-type") || "").includes("text/event-stream") || !p.body) {
|
|
149
|
+
const m = await p.json(), x = String(m.answer ?? "");
|
|
150
|
+
x && u(x);
|
|
151
|
+
const y = oe(m.follow_up);
|
|
152
|
+
return { answer: x, sessionId: m.session_id ?? n, ...y ? { followUp: y } : {} };
|
|
150
153
|
}
|
|
151
|
-
let
|
|
152
|
-
const
|
|
153
|
-
let
|
|
154
|
+
let N = "", S = !1, _, C = null;
|
|
155
|
+
const j = ze(({ event: m, data: x }) => {
|
|
156
|
+
let y = {};
|
|
154
157
|
try {
|
|
155
|
-
|
|
158
|
+
y = x ? JSON.parse(x) : {};
|
|
156
159
|
} catch {
|
|
157
160
|
return;
|
|
158
161
|
}
|
|
159
|
-
if (
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
} else
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
) :
|
|
166
|
-
}),
|
|
162
|
+
if (m === "token") {
|
|
163
|
+
const L = String(y.text ?? "");
|
|
164
|
+
N += L, u(L);
|
|
165
|
+
} else m === "error" ? C = new b(
|
|
166
|
+
y.code || "stream_error",
|
|
167
|
+
y.message || "The assistant ran into a problem"
|
|
168
|
+
) : m === "done" && (S = !0, _ = oe(y.follow_up));
|
|
169
|
+
}), k = p.body.getReader(), I = new TextDecoder();
|
|
167
170
|
for (; ; ) {
|
|
168
|
-
const { done:
|
|
169
|
-
if (
|
|
171
|
+
const { done: m, value: x } = await k.read();
|
|
172
|
+
if (m)
|
|
170
173
|
break;
|
|
171
|
-
if (
|
|
172
|
-
throw await
|
|
173
|
-
}),
|
|
174
|
-
if (
|
|
175
|
-
await
|
|
174
|
+
if (M(), j.push(I.decode(x, { stream: !0 })), C)
|
|
175
|
+
throw await k.cancel().catch(() => {
|
|
176
|
+
}), C;
|
|
177
|
+
if (S) {
|
|
178
|
+
await k.cancel().catch(() => {
|
|
176
179
|
});
|
|
177
180
|
break;
|
|
178
181
|
}
|
|
179
182
|
}
|
|
180
|
-
if (
|
|
181
|
-
throw
|
|
182
|
-
if (!
|
|
183
|
-
throw new
|
|
184
|
-
return { answer:
|
|
185
|
-
} catch (
|
|
186
|
-
throw
|
|
183
|
+
if (j.push(I.decode()), j.flush(), C)
|
|
184
|
+
throw C;
|
|
185
|
+
if (!S)
|
|
186
|
+
throw new b("stream_interrupted", "The response ended unexpectedly");
|
|
187
|
+
return { answer: N, sessionId: n, ..._ ? { followUp: _ } : {} };
|
|
188
|
+
} catch (p) {
|
|
189
|
+
throw Q(p);
|
|
187
190
|
} finally {
|
|
188
|
-
clearTimeout(
|
|
191
|
+
clearTimeout(T), f && f.removeEventListener("abort", R);
|
|
189
192
|
}
|
|
190
193
|
}
|
|
191
|
-
async function
|
|
192
|
-
|
|
193
|
-
|
|
194
|
+
async function Ie({ apiUrl: t, tenantId: e, signal: r, fetchImpl: n = (...i) => fetch(...i) }) {
|
|
195
|
+
try {
|
|
196
|
+
const i = await n(`${ae(t)}?tenant_id=${encodeURIComponent(e)}`, {
|
|
197
|
+
method: "GET",
|
|
198
|
+
headers: { Accept: "application/json" },
|
|
199
|
+
signal: r
|
|
200
|
+
});
|
|
201
|
+
return i.ok ? (await i.json())?.record_conversations === !0 : !1;
|
|
202
|
+
} catch {
|
|
203
|
+
return !1;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
async function De({
|
|
207
|
+
apiUrl: t,
|
|
208
|
+
tenantId: e,
|
|
194
209
|
sessionId: r,
|
|
195
210
|
followUpToken: n,
|
|
196
|
-
name:
|
|
197
|
-
email:
|
|
198
|
-
signal:
|
|
199
|
-
fetchImpl:
|
|
211
|
+
name: i,
|
|
212
|
+
email: f,
|
|
213
|
+
signal: u,
|
|
214
|
+
fetchImpl: l = (...a) => fetch(...a)
|
|
200
215
|
}) {
|
|
201
216
|
try {
|
|
202
|
-
if (
|
|
203
|
-
const a = await
|
|
217
|
+
if (u?.aborted) throw new b("aborted", "Request cancelled");
|
|
218
|
+
const a = await l(`${ae(t)}/contact`, {
|
|
204
219
|
method: "POST",
|
|
205
220
|
headers: { "Content-Type": "application/json", Accept: "application/json" },
|
|
206
221
|
body: JSON.stringify({
|
|
207
|
-
tenant_id:
|
|
222
|
+
tenant_id: e,
|
|
208
223
|
session_id: r,
|
|
209
224
|
follow_up_token: n,
|
|
210
|
-
name:
|
|
211
|
-
email:
|
|
225
|
+
name: i.trim(),
|
|
226
|
+
email: f.trim()
|
|
212
227
|
}),
|
|
213
|
-
signal:
|
|
228
|
+
signal: u
|
|
214
229
|
});
|
|
215
|
-
if (!a.ok) throw await
|
|
216
|
-
if ((await a.json()).status !== "saved") throw new
|
|
230
|
+
if (!a.ok) throw await ye(a);
|
|
231
|
+
if ((await a.json()).status !== "saved") throw new b("invalid_response", "Could not confirm save");
|
|
217
232
|
return { status: "saved" };
|
|
218
233
|
} catch (a) {
|
|
219
|
-
throw
|
|
234
|
+
throw u?.aborted ? new b("aborted", "Request cancelled") : a instanceof b ? a : new b("network_error", "Could not save contact details");
|
|
220
235
|
}
|
|
221
236
|
}
|
|
222
|
-
const
|
|
223
|
-
function
|
|
237
|
+
const P = /* @__PURE__ */ new Map();
|
|
238
|
+
function ve() {
|
|
224
239
|
return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : `s_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 12)}`;
|
|
225
240
|
}
|
|
226
|
-
function
|
|
241
|
+
function _e() {
|
|
227
242
|
try {
|
|
228
243
|
return typeof localStorage < "u" ? localStorage : null;
|
|
229
244
|
} catch {
|
|
230
245
|
return null;
|
|
231
246
|
}
|
|
232
247
|
}
|
|
233
|
-
function
|
|
234
|
-
const r = `support_widget_session:${
|
|
235
|
-
if (
|
|
248
|
+
function fe(t, e = _e()) {
|
|
249
|
+
const r = `support_widget_session:${t}`;
|
|
250
|
+
if (P.has(r)) return P.get(r);
|
|
236
251
|
try {
|
|
237
|
-
const
|
|
238
|
-
if (
|
|
239
|
-
return
|
|
252
|
+
const i = e ? e.getItem(r) : null;
|
|
253
|
+
if (i)
|
|
254
|
+
return P.set(r, i), i;
|
|
240
255
|
} catch {
|
|
241
256
|
}
|
|
242
|
-
if (
|
|
243
|
-
return
|
|
244
|
-
const n =
|
|
245
|
-
|
|
257
|
+
if (P.has(r))
|
|
258
|
+
return P.get(r);
|
|
259
|
+
const n = ve();
|
|
260
|
+
P.set(r, n);
|
|
246
261
|
try {
|
|
247
|
-
|
|
262
|
+
e && e.setItem(r, n);
|
|
248
263
|
} catch {
|
|
249
264
|
}
|
|
250
265
|
return n;
|
|
251
266
|
}
|
|
252
|
-
function
|
|
253
|
-
const r = `support_widget_session:${
|
|
254
|
-
|
|
267
|
+
function qe(t, e = _e()) {
|
|
268
|
+
const r = `support_widget_session:${t}`, n = ve();
|
|
269
|
+
P.set(r, n);
|
|
255
270
|
try {
|
|
256
|
-
|
|
271
|
+
e?.setItem(r, n);
|
|
257
272
|
} catch {
|
|
258
273
|
}
|
|
259
274
|
return n;
|
|
260
275
|
}
|
|
261
|
-
const
|
|
276
|
+
const ke = "The support assistant is temporarily unavailable. Please try again shortly.", he = "Something went wrong. Please try again.", we = {
|
|
262
277
|
network_error: {
|
|
263
278
|
message: "We couldn't reach the support service. Please check your connection and try again.",
|
|
264
279
|
retryable: !0
|
|
@@ -270,7 +285,7 @@ const me = "The support assistant is temporarily unavailable. Please try again s
|
|
|
270
285
|
},
|
|
271
286
|
generation_failed: { message: "The assistant ran into a problem. Please try again.", retryable: !0 },
|
|
272
287
|
stream_error: { message: "The assistant ran into a problem. Please try again.", retryable: !0 },
|
|
273
|
-
service_unavailable: { message:
|
|
288
|
+
service_unavailable: { message: ke, retryable: !0 },
|
|
274
289
|
message_too_long: {
|
|
275
290
|
message: "That message is too long. Please shorten it (2000 characters at most) and send it again.",
|
|
276
291
|
retryable: !1
|
|
@@ -279,24 +294,52 @@ const me = "The support assistant is temporarily unavailable. Please try again s
|
|
|
279
294
|
unknown_tenant: { message: "The support chat isn't available on this site.", retryable: !1 },
|
|
280
295
|
origin_not_allowed: { message: "The support chat isn't available on this site.", retryable: !1 }
|
|
281
296
|
};
|
|
282
|
-
function
|
|
283
|
-
const
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
if (
|
|
289
|
-
return
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
297
|
+
function Ce(t) {
|
|
298
|
+
const e = Number(t && t.retryAfterSec);
|
|
299
|
+
return !Number.isFinite(e) || e <= 0 ? "a moment" : e > 90 ? `${Math.ceil(e / 60)} minutes` : `${Math.ceil(e)} seconds`;
|
|
300
|
+
}
|
|
301
|
+
function Se(t) {
|
|
302
|
+
const e = t && t.code;
|
|
303
|
+
if (e === "rate_limited")
|
|
304
|
+
return {
|
|
305
|
+
message: `You're sending messages too quickly. Please wait ${Ce(t)} and try again.`,
|
|
306
|
+
retryable: !0
|
|
307
|
+
};
|
|
308
|
+
if (e && we[e])
|
|
309
|
+
return we[e];
|
|
310
|
+
const r = Number(t && t.status);
|
|
311
|
+
return r >= 500 ? { message: ke, retryable: !0 } : r >= 400 ? { message: he, retryable: !1 } : { message: he, retryable: !0 };
|
|
312
|
+
}
|
|
313
|
+
const Ue = "Your details could not be saved. Please try again or contact the business directly.", J = "contact the business directly", ne = {
|
|
314
|
+
invalid_request: "Please check your name and email address and try again.",
|
|
315
|
+
origin_not_allowed: `Email follow-up isn't available on this site. Please ${J}.`,
|
|
316
|
+
unknown_tenant: `Email follow-up isn't available on this site. Please ${J}.`,
|
|
317
|
+
invalid_follow_up: `This follow-up form has expired. Please send your message again to get a new one, or ${J}.`,
|
|
318
|
+
contact_already_submitted: `Different contact details were already saved for this conversation. Please ${J} to change them.`,
|
|
319
|
+
service_unavailable: "We couldn't save your details right now. Please try again shortly or contact the business directly.",
|
|
320
|
+
network_error: "We couldn't reach the support service. Please check your connection and try again.",
|
|
321
|
+
timeout: "Saving your details took too long. Please try again."
|
|
322
|
+
};
|
|
323
|
+
function We(t) {
|
|
324
|
+
const e = t && t.code === "aborted" ? "timeout" : t && t.code;
|
|
325
|
+
return e === "rate_limited" ? `Too many attempts. Please wait ${Ce(t)} and try again.` : e && Object.hasOwn(ne, e) ? ne[e] : Number(t && t.status) >= 500 ? ne.service_unavailable : Ue;
|
|
326
|
+
}
|
|
327
|
+
function Fe(t) {
|
|
328
|
+
return Se(t).message;
|
|
329
|
+
}
|
|
330
|
+
function Be(t) {
|
|
331
|
+
return Se(t).retryable;
|
|
332
|
+
}
|
|
333
|
+
const Ye = 120, He = 1.01;
|
|
334
|
+
function Ge({ innerHeight: t, vvHeight: e, vvOffsetTop: r, vvScale: n }) {
|
|
335
|
+
return ![t, e, r, n].every((f) => Number.isFinite(f)) || e <= 0 || n > He ? null : {
|
|
336
|
+
top: Math.max(0, Math.round(r)),
|
|
337
|
+
height: Math.round(e),
|
|
338
|
+
keyboardOpen: t - e >= Ye
|
|
339
|
+
};
|
|
298
340
|
}
|
|
299
|
-
const
|
|
341
|
+
const Ve = `
|
|
342
|
+
:host { all: initial; }
|
|
300
343
|
.cw-root {
|
|
301
344
|
--cw-accent: #1f6feb;
|
|
302
345
|
--cw-accent-text: #ffffff;
|
|
@@ -440,6 +483,7 @@ const Pe = `
|
|
|
440
483
|
.cw-contact-form .cw-send { padding: 9px; }
|
|
441
484
|
.cw-contact-form [role="alert"] { color: var(--cw-error); }
|
|
442
485
|
.cw-new-chat:focus-visible, .cw-contact-form input:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
|
|
486
|
+
.cw-notice { padding: 6px 12px; border-top: 1px solid var(--cw-border); background: var(--cw-surface); font-size: 12px; color: var(--cw-muted); text-align: center; }
|
|
443
487
|
.cw-form {
|
|
444
488
|
display: flex;
|
|
445
489
|
gap: 8px;
|
|
@@ -469,127 +513,212 @@ const Pe = `
|
|
|
469
513
|
.cw-send:disabled { opacity: 0.5; cursor: not-allowed; }
|
|
470
514
|
.cw-footer { padding: 0 10px 8px; font-size: 11px; color: var(--cw-muted); text-align: center; }
|
|
471
515
|
|
|
516
|
+
/* Phones and short landscape screens: the open panel fills the screen. Its box follows the part of
|
|
517
|
+
the screen the keyboard leaves free (--cw-vv-top / --cw-vv-height, set from the visual viewport
|
|
518
|
+
by ChatWidget; 100dvh is the fallback), so the header and greeting stay visible and the input
|
|
519
|
+
sits just above the keyboard. Everything here lives inside the widget's own shadow root. */
|
|
520
|
+
@media (max-width: 640px), (max-height: 500px) {
|
|
521
|
+
.cw-root { bottom: max(16px, env(safe-area-inset-bottom)); }
|
|
522
|
+
.cw-root.cw-right { right: 16px; }
|
|
523
|
+
.cw-root.cw-left { left: 16px; }
|
|
524
|
+
|
|
525
|
+
.cw-root.cw-open,
|
|
526
|
+
.cw-root.cw-open.cw-right,
|
|
527
|
+
.cw-root.cw-open.cw-left {
|
|
528
|
+
top: var(--cw-vv-top, 0px);
|
|
529
|
+
left: 0;
|
|
530
|
+
right: 0;
|
|
531
|
+
bottom: auto;
|
|
532
|
+
height: var(--cw-vv-height, 100dvh);
|
|
533
|
+
}
|
|
534
|
+
.cw-panel {
|
|
535
|
+
width: 100%;
|
|
536
|
+
max-width: none;
|
|
537
|
+
height: 100%;
|
|
538
|
+
max-height: none;
|
|
539
|
+
border: none;
|
|
540
|
+
border-radius: 0;
|
|
541
|
+
box-shadow: none;
|
|
542
|
+
}
|
|
543
|
+
.cw-header {
|
|
544
|
+
padding: 8px 10px;
|
|
545
|
+
padding-top: max(8px, env(safe-area-inset-top));
|
|
546
|
+
gap: 6px;
|
|
547
|
+
touch-action: none;
|
|
548
|
+
}
|
|
549
|
+
.cw-header > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
550
|
+
.cw-new-chat { min-height: 40px; padding: 0 12px; font-size: 13px; }
|
|
551
|
+
.cw-close { min-width: 44px; min-height: 44px; font-size: 28px; }
|
|
552
|
+
.cw-messages { padding: 12px; font-size: 15px; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
|
|
553
|
+
.cw-msg { max-width: 90%; padding: 9px 13px; }
|
|
554
|
+
.cw-follow-up p, .cw-contact-form label { font-size: 13px; }
|
|
555
|
+
/* 16px stops iOS Safari from zooming the page when a field is focused. */
|
|
556
|
+
.cw-input { font-size: 16px; padding: 10px 12px; }
|
|
557
|
+
.cw-send { min-width: 64px; min-height: 44px; }
|
|
558
|
+
.cw-form { padding: 8px 10px; }
|
|
559
|
+
.cw-footer { padding-bottom: max(8px, env(safe-area-inset-bottom)); touch-action: none; }
|
|
560
|
+
/* With the keyboard up, drop the footer line and its safe-area padding to keep room for messages. */
|
|
561
|
+
.cw-root.cw-kb .cw-footer { display: none; }
|
|
562
|
+
}
|
|
563
|
+
|
|
472
564
|
@media (prefers-reduced-motion: reduce) {
|
|
473
565
|
.cw-typing::after { animation: none; }
|
|
474
566
|
}
|
|
475
|
-
`,
|
|
476
|
-
let
|
|
477
|
-
function
|
|
478
|
-
return
|
|
567
|
+
`, me = 2e3, Xe = 6e3;
|
|
568
|
+
let ge = 0;
|
|
569
|
+
function K() {
|
|
570
|
+
return ge += 1, `m${ge}`;
|
|
571
|
+
}
|
|
572
|
+
function be() {
|
|
573
|
+
try {
|
|
574
|
+
return !window.matchMedia("(pointer: coarse)").matches;
|
|
575
|
+
} catch {
|
|
576
|
+
return !0;
|
|
577
|
+
}
|
|
479
578
|
}
|
|
480
|
-
function
|
|
481
|
-
apiUrl:
|
|
482
|
-
tenantId:
|
|
579
|
+
function Ze({
|
|
580
|
+
apiUrl: t,
|
|
581
|
+
tenantId: e,
|
|
483
582
|
title: r = "Support",
|
|
484
583
|
greeting: n = "Hi! How can I help you today?",
|
|
485
|
-
position:
|
|
486
|
-
accentColor:
|
|
487
|
-
defaultOpen:
|
|
488
|
-
fetchImpl:
|
|
584
|
+
position: i = "right",
|
|
585
|
+
accentColor: f,
|
|
586
|
+
defaultOpen: u = !1,
|
|
587
|
+
fetchImpl: l
|
|
489
588
|
}) {
|
|
490
|
-
const [a, d] =
|
|
491
|
-
{ id:
|
|
492
|
-
]), S = $(null),
|
|
493
|
-
|
|
494
|
-
const [
|
|
495
|
-
|
|
496
|
-
}, [
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
}, [
|
|
500
|
-
|
|
589
|
+
const [a, d] = h(u), [A, T] = h(""), [M, R] = h(!1), [Q, p] = h(!1), [U, N] = h(() => [
|
|
590
|
+
{ id: K(), role: "assistant", text: n, status: "done" }
|
|
591
|
+
]), S = $(null), _ = $(null);
|
|
592
|
+
_.current || (_.current = Oe());
|
|
593
|
+
const [C, j] = h(() => fe(e)), [k, I] = h(null), [m, x] = h(""), [y, L] = h(""), [O, W] = h("idle"), [se, F] = h(""), B = $(!1), Y = $(!1), ie = $(null), H = $(null), ee = $(""), [G, ce] = h(null), [te, le] = h(!1), de = Z((o) => {
|
|
594
|
+
_.current.reset(), S.current = null, Y.current = !1, B.current = !1, ee.current = "", j(o ? qe(e) : fe(e)), N([{ id: K(), role: "assistant", text: n, status: "done" }]), T(""), R(!1), p(!1), I(null), x(""), L(""), W("idle"), F(""), be() && H.current?.focus();
|
|
595
|
+
}, [e, n]);
|
|
596
|
+
Ae(() => {
|
|
597
|
+
de(!1);
|
|
598
|
+
}, [e, t]);
|
|
599
|
+
const ue = !!G?.keyboardOpen;
|
|
600
|
+
z(() => {
|
|
601
|
+
const o = ie.current;
|
|
501
602
|
o && (o.scrollTop = o.scrollHeight);
|
|
502
|
-
}, [
|
|
503
|
-
a &&
|
|
504
|
-
}, [a]),
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
603
|
+
}, [U, a, ue]), z(() => {
|
|
604
|
+
a && H.current && be() && H.current.focus();
|
|
605
|
+
}, [a]), z(() => {
|
|
606
|
+
const o = typeof window < "u" ? window.visualViewport : null;
|
|
607
|
+
if (!a || !o) {
|
|
608
|
+
ce(null);
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
const c = () => ce(
|
|
612
|
+
Ge({
|
|
613
|
+
innerHeight: window.innerHeight,
|
|
614
|
+
vvHeight: o.height,
|
|
615
|
+
vvOffsetTop: o.offsetTop,
|
|
616
|
+
vvScale: o.scale
|
|
617
|
+
})
|
|
618
|
+
);
|
|
619
|
+
return c(), o.addEventListener("resize", c), o.addEventListener("scroll", c), () => {
|
|
620
|
+
o.removeEventListener("resize", c), o.removeEventListener("scroll", c);
|
|
621
|
+
};
|
|
622
|
+
}, [a]), z(() => () => _.current.reset(), []), z(() => {
|
|
623
|
+
if (le(!1), !a) return;
|
|
624
|
+
const o = new AbortController();
|
|
625
|
+
return Ie({ apiUrl: t, tenantId: e, signal: o.signal, fetchImpl: l }).then((c) => {
|
|
626
|
+
o.signal.aborted || le(c);
|
|
627
|
+
}), () => o.abort();
|
|
628
|
+
}, [a, t, e, l]);
|
|
629
|
+
const D = Z((o, c) => {
|
|
630
|
+
N((v) => v.map((w) => w.id === o ? { ...w, ...c } : w));
|
|
631
|
+
}, []), re = Z(
|
|
508
632
|
async (o) => {
|
|
509
|
-
const
|
|
510
|
-
if (!
|
|
633
|
+
const c = o.trim().slice(0, me);
|
|
634
|
+
if (!c || Y.current)
|
|
511
635
|
return;
|
|
512
|
-
|
|
513
|
-
const
|
|
514
|
-
|
|
636
|
+
Y.current = !0, ee.current = c;
|
|
637
|
+
const v = K();
|
|
638
|
+
N((E) => [
|
|
515
639
|
...E,
|
|
516
|
-
{ id:
|
|
517
|
-
{ id:
|
|
518
|
-
]),
|
|
519
|
-
const
|
|
520
|
-
S.current =
|
|
521
|
-
let
|
|
522
|
-
|
|
523
|
-
const
|
|
524
|
-
|
|
525
|
-
},
|
|
640
|
+
{ id: K(), role: "user", text: c, status: "done" },
|
|
641
|
+
{ id: v, role: "assistant", text: "", status: "streaming" }
|
|
642
|
+
]), T(""), R(!0);
|
|
643
|
+
const w = _.current.begin();
|
|
644
|
+
S.current = w;
|
|
645
|
+
let q = "";
|
|
646
|
+
p(!1);
|
|
647
|
+
const pe = setTimeout(() => {
|
|
648
|
+
w.isCurrent() && p(!0);
|
|
649
|
+
}, Xe);
|
|
526
650
|
try {
|
|
527
|
-
const E = await
|
|
528
|
-
apiUrl:
|
|
529
|
-
tenantId:
|
|
530
|
-
message:
|
|
531
|
-
sessionId:
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
651
|
+
const E = await je({
|
|
652
|
+
apiUrl: t,
|
|
653
|
+
tenantId: e,
|
|
654
|
+
message: c,
|
|
655
|
+
sessionId: C,
|
|
656
|
+
// Only true while the recording notice is on screen (see `recording`).
|
|
657
|
+
recordingNotice: te,
|
|
658
|
+
signal: w.signal,
|
|
659
|
+
fetchImpl: l,
|
|
660
|
+
onToken: (X) => {
|
|
661
|
+
w.isCurrent() && (clearTimeout(pe), p(!1), q += X, D(v, { text: q }));
|
|
536
662
|
}
|
|
537
663
|
});
|
|
538
|
-
if (!
|
|
539
|
-
|
|
664
|
+
if (!w.isCurrent()) return;
|
|
665
|
+
D(v, { status: "done" }), E.followUp && (I(E.followUp), F(""));
|
|
540
666
|
} catch (E) {
|
|
541
|
-
if (!
|
|
667
|
+
if (!w.isCurrent()) return;
|
|
542
668
|
if (E.code === "aborted")
|
|
543
|
-
|
|
669
|
+
D(v, { status: "done", text: q || "(stopped)" });
|
|
544
670
|
else {
|
|
545
|
-
const
|
|
546
|
-
|
|
671
|
+
const X = Fe(E);
|
|
672
|
+
D(v, {
|
|
547
673
|
status: "error",
|
|
548
|
-
retryable:
|
|
549
|
-
text:
|
|
674
|
+
retryable: Be(E),
|
|
675
|
+
text: q ? `${q}
|
|
550
676
|
|
|
551
|
-
${
|
|
677
|
+
${X}` : X
|
|
552
678
|
});
|
|
553
679
|
}
|
|
554
680
|
} finally {
|
|
555
|
-
clearTimeout(
|
|
681
|
+
clearTimeout(pe), w.finish(), w.isCurrent() && (S.current = null, Y.current = !1, p(!1), R(!1));
|
|
556
682
|
}
|
|
557
683
|
},
|
|
558
|
-
[e,
|
|
559
|
-
),
|
|
560
|
-
const o =
|
|
561
|
-
o && (
|
|
562
|
-
}, [
|
|
563
|
-
o.preventDefault(),
|
|
564
|
-
},
|
|
565
|
-
if (o.preventDefault(), !
|
|
566
|
-
|
|
567
|
-
const
|
|
568
|
-
|
|
569
|
-
const
|
|
684
|
+
[t, e, C, l, D, te]
|
|
685
|
+
), Ee = Z(() => {
|
|
686
|
+
const o = ee.current;
|
|
687
|
+
o && (N((c) => c.slice(0, -2)), re(o));
|
|
688
|
+
}, [re]), Te = (o) => {
|
|
689
|
+
o.preventDefault(), re(A);
|
|
690
|
+
}, Ne = async (o) => {
|
|
691
|
+
if (o.preventDefault(), !k || B.current || O === "saved") return;
|
|
692
|
+
B.current = !0;
|
|
693
|
+
const c = _.current.begin();
|
|
694
|
+
W("pending"), F("");
|
|
695
|
+
const v = setTimeout(() => c.abort(), 3e4);
|
|
570
696
|
try {
|
|
571
|
-
await
|
|
572
|
-
apiUrl:
|
|
573
|
-
tenantId:
|
|
574
|
-
sessionId:
|
|
575
|
-
followUpToken:
|
|
576
|
-
name:
|
|
577
|
-
email:
|
|
578
|
-
signal:
|
|
579
|
-
fetchImpl:
|
|
580
|
-
}),
|
|
581
|
-
} catch {
|
|
582
|
-
|
|
697
|
+
await De({
|
|
698
|
+
apiUrl: t,
|
|
699
|
+
tenantId: e,
|
|
700
|
+
sessionId: C,
|
|
701
|
+
followUpToken: k.token,
|
|
702
|
+
name: m,
|
|
703
|
+
email: y,
|
|
704
|
+
signal: c.signal,
|
|
705
|
+
fetchImpl: l
|
|
706
|
+
}), c.isCurrent() && (W("saved"), x(""), L(""));
|
|
707
|
+
} catch (w) {
|
|
708
|
+
c.isCurrent() && (W("error"), F(We(w)));
|
|
583
709
|
} finally {
|
|
584
|
-
clearTimeout(
|
|
710
|
+
clearTimeout(v), c.finish(), c.isCurrent() && (B.current = !1);
|
|
585
711
|
}
|
|
586
|
-
},
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
712
|
+
}, V = Le(k), $e = {
|
|
713
|
+
...f ? { "--cw-accent": f } : {},
|
|
714
|
+
...a && G ? { "--cw-vv-top": `${G.top}px`, "--cw-vv-height": `${G.height}px` } : {}
|
|
715
|
+
};
|
|
716
|
+
return /* @__PURE__ */ g("div", { className: `cw-root ${i === "left" ? "cw-left" : "cw-right"}${`${a ? " cw-open" : ""}${a && ue ? " cw-kb" : ""}`}`, style: $e, children: [
|
|
717
|
+
/* @__PURE__ */ s("style", { children: Ve }),
|
|
718
|
+
a ? /* @__PURE__ */ g("section", { className: "cw-panel", role: "dialog", "aria-label": r, children: [
|
|
719
|
+
/* @__PURE__ */ g("header", { className: "cw-header", children: [
|
|
591
720
|
/* @__PURE__ */ s("span", { children: r }),
|
|
592
|
-
/* @__PURE__ */ s("button", { type: "button", className: "cw-new-chat", onClick: () =>
|
|
721
|
+
/* @__PURE__ */ s("button", { type: "button", className: "cw-new-chat", onClick: () => de(!0), children: "New chat" }),
|
|
593
722
|
/* @__PURE__ */ s(
|
|
594
723
|
"button",
|
|
595
724
|
{
|
|
@@ -601,39 +730,39 @@ ${B}` : B
|
|
|
601
730
|
}
|
|
602
731
|
)
|
|
603
732
|
] }),
|
|
604
|
-
/* @__PURE__ */
|
|
605
|
-
|
|
606
|
-
const
|
|
607
|
-
return /* @__PURE__ */
|
|
733
|
+
/* @__PURE__ */ g("div", { className: "cw-messages", ref: ie, role: "log", "aria-live": "polite", children: [
|
|
734
|
+
U.map((o, c) => {
|
|
735
|
+
const v = c === U.length - 1;
|
|
736
|
+
return /* @__PURE__ */ g(
|
|
608
737
|
"div",
|
|
609
738
|
{
|
|
610
739
|
className: `cw-msg cw-${o.role}${o.status === "error" ? " cw-error" : ""}`,
|
|
611
740
|
children: [
|
|
612
741
|
o.text,
|
|
613
|
-
o.status === "streaming" && !o.text ? /* @__PURE__ */
|
|
742
|
+
o.status === "streaming" && !o.text ? /* @__PURE__ */ g(Pe, { children: [
|
|
614
743
|
/* @__PURE__ */ s("span", { className: "cw-typing", "aria-label": "Assistant is typing" }),
|
|
615
|
-
|
|
744
|
+
Q ? /* @__PURE__ */ s("span", { className: "cw-slow", children: "Still working on your answer…" }) : null
|
|
616
745
|
] }) : null,
|
|
617
|
-
o.status === "error" && o.retryable !== !1 &&
|
|
746
|
+
o.status === "error" && o.retryable !== !1 && v && !M ? /* @__PURE__ */ s("div", { children: /* @__PURE__ */ s("button", { type: "button", className: "cw-retry", onClick: Ee, children: "Retry" }) }) : null
|
|
618
747
|
]
|
|
619
748
|
},
|
|
620
749
|
o.id
|
|
621
750
|
);
|
|
622
751
|
}),
|
|
623
|
-
|
|
752
|
+
k ? /* @__PURE__ */ g("section", { className: "cw-follow-up", "aria-label": "Email follow-up", children: [
|
|
624
753
|
/* @__PURE__ */ s("strong", { children: "Email follow-up" }),
|
|
625
754
|
/* @__PURE__ */ s("p", { children: "Email follow-up is not immediate. For time-sensitive help, contact the business directly." }),
|
|
626
|
-
|
|
755
|
+
V.phone ? /* @__PURE__ */ g("p", { children: [
|
|
627
756
|
"Call ",
|
|
628
|
-
/* @__PURE__ */ s("a", { href:
|
|
757
|
+
/* @__PURE__ */ s("a", { href: V.phone, target: "_blank", rel: "noopener noreferrer", children: k.contactPhone })
|
|
629
758
|
] }) : null,
|
|
630
|
-
|
|
759
|
+
V.email ? /* @__PURE__ */ g("p", { children: [
|
|
631
760
|
"Email ",
|
|
632
|
-
/* @__PURE__ */ s("a", { href:
|
|
761
|
+
/* @__PURE__ */ s("a", { href: V.email, target: "_blank", rel: "noopener noreferrer", children: k.contactEmail })
|
|
633
762
|
] }) : null,
|
|
634
|
-
|
|
763
|
+
O === "saved" ? /* @__PURE__ */ s("p", { role: "status", children: "Your details were saved for the team to review and follow up by email." }) : /* @__PURE__ */ g("form", { className: "cw-contact-form", onSubmit: Ne, children: [
|
|
635
764
|
/* @__PURE__ */ s("p", { children: "Leave your name and email to request follow-up about this conversation." }),
|
|
636
|
-
/* @__PURE__ */
|
|
765
|
+
/* @__PURE__ */ g("label", { children: [
|
|
637
766
|
"Name",
|
|
638
767
|
/* @__PURE__ */ s(
|
|
639
768
|
"input",
|
|
@@ -643,13 +772,13 @@ ${B}` : B
|
|
|
643
772
|
autoComplete: "name",
|
|
644
773
|
required: !0,
|
|
645
774
|
maxLength: 100,
|
|
646
|
-
value:
|
|
647
|
-
disabled:
|
|
648
|
-
onChange: (o) =>
|
|
775
|
+
value: m,
|
|
776
|
+
disabled: O === "pending",
|
|
777
|
+
onChange: (o) => x(o.target.value)
|
|
649
778
|
}
|
|
650
779
|
)
|
|
651
780
|
] }),
|
|
652
|
-
/* @__PURE__ */
|
|
781
|
+
/* @__PURE__ */ g("label", { children: [
|
|
653
782
|
"Email",
|
|
654
783
|
/* @__PURE__ */ s(
|
|
655
784
|
"input",
|
|
@@ -660,31 +789,32 @@ ${B}` : B
|
|
|
660
789
|
autoComplete: "email",
|
|
661
790
|
required: !0,
|
|
662
791
|
maxLength: 254,
|
|
663
|
-
value:
|
|
664
|
-
disabled:
|
|
665
|
-
onChange: (o) =>
|
|
792
|
+
value: y,
|
|
793
|
+
disabled: O === "pending",
|
|
794
|
+
onChange: (o) => L(o.target.value)
|
|
666
795
|
}
|
|
667
796
|
)
|
|
668
797
|
] }),
|
|
669
|
-
|
|
670
|
-
/* @__PURE__ */ s("button", { className: "cw-send", type: "submit", disabled:
|
|
798
|
+
se ? /* @__PURE__ */ s("p", { role: "alert", children: se }) : null,
|
|
799
|
+
/* @__PURE__ */ s("button", { className: "cw-send", type: "submit", disabled: O === "pending" || !m.trim() || !y.trim(), children: O === "pending" ? "Saving…" : "Request email follow-up" })
|
|
671
800
|
] })
|
|
672
801
|
] }) : null
|
|
673
802
|
] }),
|
|
674
|
-
/* @__PURE__ */
|
|
803
|
+
te ? /* @__PURE__ */ s("div", { className: "cw-notice", role: "note", children: "This conversation is recorded to improve the assistant." }) : null,
|
|
804
|
+
/* @__PURE__ */ g("form", { className: "cw-form", onSubmit: Te, children: [
|
|
675
805
|
/* @__PURE__ */ s(
|
|
676
806
|
"input",
|
|
677
807
|
{
|
|
678
|
-
ref:
|
|
808
|
+
ref: H,
|
|
679
809
|
className: "cw-input",
|
|
680
|
-
value:
|
|
681
|
-
maxLength:
|
|
810
|
+
value: A,
|
|
811
|
+
maxLength: me,
|
|
682
812
|
placeholder: "Type your question…",
|
|
683
813
|
"aria-label": "Your message",
|
|
684
|
-
onChange: (o) =>
|
|
814
|
+
onChange: (o) => T(o.target.value)
|
|
685
815
|
}
|
|
686
816
|
),
|
|
687
|
-
|
|
817
|
+
M ? /* @__PURE__ */ s(
|
|
688
818
|
"button",
|
|
689
819
|
{
|
|
690
820
|
type: "button",
|
|
@@ -692,7 +822,7 @@ ${B}` : B
|
|
|
692
822
|
onClick: () => S.current?.abort(),
|
|
693
823
|
children: "Stop"
|
|
694
824
|
}
|
|
695
|
-
) : /* @__PURE__ */ s("button", { type: "submit", className: "cw-send", disabled: !
|
|
825
|
+
) : /* @__PURE__ */ s("button", { type: "submit", className: "cw-send", disabled: !A.trim(), children: "Send" })
|
|
696
826
|
] }),
|
|
697
827
|
/* @__PURE__ */ s("div", { className: "cw-footer", children: "AI assistant – answers may contain mistakes." })
|
|
698
828
|
] }) : /* @__PURE__ */ s(
|
|
@@ -707,11 +837,17 @@ ${B}` : B
|
|
|
707
837
|
)
|
|
708
838
|
] });
|
|
709
839
|
}
|
|
840
|
+
function rt(t) {
|
|
841
|
+
const [e, r] = h(null), [n, i] = h(null);
|
|
842
|
+
return z(() => {
|
|
843
|
+
e && i(e.shadowRoot || e.attachShadow({ mode: "open" }));
|
|
844
|
+
}, [e]), /* @__PURE__ */ s("div", { ref: r, "data-support-widget": t.tenantId, children: n ? Re(/* @__PURE__ */ s(Ze, { ...t }), n) : null });
|
|
845
|
+
}
|
|
710
846
|
export {
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
847
|
+
b as ChatError,
|
|
848
|
+
rt as ChatWidget,
|
|
849
|
+
fe as getSessionId,
|
|
850
|
+
qe as newSessionId,
|
|
851
|
+
je as streamChat,
|
|
852
|
+
De as submitContact
|
|
717
853
|
};
|