@useago/sdk 1.2.0 → 1.3.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/widget.cjs +4 -4
- package/dist/widget.d.cts +9 -0
- package/dist/widget.d.ts +9 -0
- package/dist/widget.js +526 -513
- package/package.json +1 -1
package/dist/widget.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import { r as
|
|
3
|
-
import { t as
|
|
4
|
-
var
|
|
1
|
+
import { a as Ut, i as Wt, m as Gt, o as Vt, s as jt, t as qt } from "./AgoClient-Cwx_eYSu.js";
|
|
2
|
+
import { r as Kt, t as Xt } from "./createFormCollector-CyWisAkI.js";
|
|
3
|
+
import { t as Qt } from "./createConversationSession-B3h567tt.js";
|
|
4
|
+
var Yt = '"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif', Ee = `var(--ago-font, ${Yt})`, lt = {
|
|
5
5
|
font: "--ago-font",
|
|
6
6
|
radius: "--ago-radius",
|
|
7
7
|
messageRadius: "--ago-message-radius",
|
|
@@ -16,240 +16,240 @@ var jt = '"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto
|
|
|
16
16
|
border: "--ago-border-color",
|
|
17
17
|
accent: "--ago-accent-color",
|
|
18
18
|
agentBubbleBg: "--ago-agent-bubble-background"
|
|
19
|
-
},
|
|
20
|
-
function
|
|
19
|
+
}, Re = "var(--ago-brand-color, #03182f)", ke = "var(--ago-brand-text-color, #fff)", Zt = "var(--ago-header-background, var(--ago-brand-color, #03182f))", dt = "var(--ago-header-text-color, #e8f0fe)", ee = "var(--ago-panel-background, #fff)", mt = "var(--ago-messages-background, #fbfbfb)", J = "var(--ago-text-color, #30373e)", gt = "var(--ago-muted-text-color, #6b6d6f)", L = "var(--ago-border-color, #dee3e8)", Be = "var(--ago-accent-color, #1b5fc4)", ct = "var(--ago-agent-bubble-background, #f1f3f5)", Jt = "var(--ago-radius, 16px)", Me = "var(--ago-message-radius, 16px)", en = "var(--ago-message-radius, 20px)";
|
|
20
|
+
function tn(n, o) {
|
|
21
21
|
if (o)
|
|
22
|
-
for (const i of Object.keys(
|
|
22
|
+
for (const i of Object.keys(lt)) {
|
|
23
23
|
const r = o[i];
|
|
24
|
-
r != null &&
|
|
24
|
+
r != null && n.style.setProperty(lt[i], r);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
function
|
|
28
|
-
Object.assign(
|
|
27
|
+
function v(n, o) {
|
|
28
|
+
Object.assign(n.style, o);
|
|
29
29
|
}
|
|
30
|
-
function
|
|
30
|
+
function h(n = {}) {
|
|
31
31
|
const o = document.createElement("div");
|
|
32
|
-
return
|
|
32
|
+
return v(o, n), o;
|
|
33
33
|
}
|
|
34
|
-
var
|
|
35
|
-
function
|
|
36
|
-
if (typeof document > "u" || document.getElementById(
|
|
37
|
-
const
|
|
38
|
-
|
|
34
|
+
var pt = "ago-chat-widget-keyframes";
|
|
35
|
+
function nn() {
|
|
36
|
+
if (typeof document > "u" || document.getElementById(pt)) return;
|
|
37
|
+
const n = document.createElement("style");
|
|
38
|
+
n.id = pt, n.textContent = "@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }@keyframes ago-spin { to { transform: rotate(360deg); } }", document.head.appendChild(n);
|
|
39
39
|
}
|
|
40
|
-
function
|
|
40
|
+
function on(n) {
|
|
41
41
|
let o = [];
|
|
42
42
|
const i = document.createElement("form");
|
|
43
|
-
|
|
43
|
+
v(i, {
|
|
44
44
|
display: "flex",
|
|
45
45
|
flexDirection: "column",
|
|
46
46
|
gap: "8px",
|
|
47
47
|
padding: "12px",
|
|
48
|
-
borderTop: `1px solid ${
|
|
49
|
-
backgroundColor:
|
|
48
|
+
borderTop: `1px solid ${L}`,
|
|
49
|
+
backgroundColor: ee
|
|
50
50
|
}), i.className = "ago-chat-input";
|
|
51
|
-
const r =
|
|
51
|
+
const r = h({
|
|
52
52
|
display: "flex",
|
|
53
53
|
flexWrap: "wrap",
|
|
54
54
|
gap: "6px"
|
|
55
|
-
}),
|
|
55
|
+
}), b = h({
|
|
56
56
|
display: "flex",
|
|
57
57
|
gap: "8px",
|
|
58
58
|
alignItems: "flex-end"
|
|
59
59
|
}), a = document.createElement("textarea");
|
|
60
|
-
a.placeholder =
|
|
60
|
+
a.placeholder = n.placeholder, a.setAttribute("aria-label", n.placeholder), a.rows = 1, v(a, {
|
|
61
61
|
flex: "1",
|
|
62
62
|
resize: "none",
|
|
63
63
|
boxSizing: "border-box",
|
|
64
64
|
padding: "10px 12px",
|
|
65
|
-
border: `1px solid ${
|
|
65
|
+
border: `1px solid ${L}`,
|
|
66
66
|
borderRadius: "12px",
|
|
67
67
|
fontSize: "16px",
|
|
68
|
-
fontFamily:
|
|
68
|
+
fontFamily: Ee,
|
|
69
69
|
lineHeight: "1.4",
|
|
70
70
|
maxHeight: "110px",
|
|
71
71
|
overflowY: "hidden"
|
|
72
72
|
});
|
|
73
73
|
const C = () => {
|
|
74
74
|
a.style.height = "auto";
|
|
75
|
-
const
|
|
76
|
-
a.style.height = `${
|
|
75
|
+
const c = Math.min(a.scrollHeight + 2, 110);
|
|
76
|
+
a.style.height = `${c}px`, a.style.overflowY = a.scrollHeight + 2 > 110 ? "auto" : "hidden";
|
|
77
77
|
};
|
|
78
78
|
a.addEventListener("input", () => {
|
|
79
|
-
C(),
|
|
79
|
+
C(), A();
|
|
80
80
|
});
|
|
81
|
-
const
|
|
82
|
-
|
|
81
|
+
const m = '<svg width="18" height="18" viewBox="0 -960 960 960" fill="currentColor" aria-hidden="true"><path d="M440-160v-487L216-423l-56-57 320-320 320 320-56 57-224-224v487h-80Z"/></svg>', x = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true" style="animation: ago-spin 0.8s linear infinite"><path d="M21 12a9 9 0 1 1-6.219-8.56"/></svg>', p = document.createElement("button");
|
|
82
|
+
p.type = "submit", p.setAttribute("aria-label", "Send"), p.innerHTML = m, v(p, {
|
|
83
83
|
flexShrink: "0",
|
|
84
84
|
width: "40px",
|
|
85
85
|
height: "40px",
|
|
86
86
|
padding: "0",
|
|
87
87
|
border: "none",
|
|
88
88
|
borderRadius: "50%",
|
|
89
|
-
backgroundColor:
|
|
90
|
-
color:
|
|
89
|
+
backgroundColor: Re,
|
|
90
|
+
color: ke,
|
|
91
91
|
display: "flex",
|
|
92
92
|
alignItems: "center",
|
|
93
93
|
justifyContent: "center",
|
|
94
94
|
cursor: "pointer"
|
|
95
95
|
});
|
|
96
|
-
let
|
|
97
|
-
const
|
|
98
|
-
const
|
|
99
|
-
|
|
96
|
+
let f = !1;
|
|
97
|
+
const A = () => {
|
|
98
|
+
const s = a.value.trim() !== "" || o.length > 0, c = f || !s;
|
|
99
|
+
p.disabled = c, p.innerHTML = f ? x : m, p.style.opacity = c && !f ? "0.5" : "1", p.style.cursor = c ? "default" : "pointer";
|
|
100
100
|
};
|
|
101
|
-
let
|
|
102
|
-
|
|
101
|
+
let R = null, _ = null;
|
|
102
|
+
n.allowFiles && (R = document.createElement("input"), R.type = "file", R.multiple = !0, v(R, { display: "none" }), _ = document.createElement("button"), _.type = "button", _.setAttribute("aria-label", "Attach file"), _.textContent = "📎", v(_, {
|
|
103
103
|
padding: "10px 12px",
|
|
104
|
-
border: `1px solid ${
|
|
104
|
+
border: `1px solid ${L}`,
|
|
105
105
|
borderRadius: "12px",
|
|
106
|
-
backgroundColor:
|
|
106
|
+
backgroundColor: ee,
|
|
107
107
|
cursor: "pointer",
|
|
108
108
|
fontSize: "14px"
|
|
109
|
-
}),
|
|
110
|
-
o = [...o, ...Array.from(
|
|
109
|
+
}), _.addEventListener("click", () => R?.click()), R.addEventListener("change", () => {
|
|
110
|
+
o = [...o, ...Array.from(R?.files ?? [])], Y();
|
|
111
111
|
}));
|
|
112
|
-
function
|
|
113
|
-
r.replaceChildren(), o.forEach((
|
|
114
|
-
const
|
|
112
|
+
function Y() {
|
|
113
|
+
r.replaceChildren(), o.forEach((s, c) => {
|
|
114
|
+
const y = h({
|
|
115
115
|
display: "flex",
|
|
116
116
|
alignItems: "center",
|
|
117
117
|
gap: "4px",
|
|
118
118
|
padding: "4px 8px",
|
|
119
119
|
backgroundColor: "#f0f4ff",
|
|
120
|
-
border: `1px solid ${
|
|
120
|
+
border: `1px solid ${L}`,
|
|
121
121
|
borderRadius: "8px",
|
|
122
122
|
fontSize: "12px"
|
|
123
|
-
}),
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
|
|
123
|
+
}), T = document.createElement("span");
|
|
124
|
+
T.textContent = s.name;
|
|
125
|
+
const k = document.createElement("button");
|
|
126
|
+
k.type = "button", k.setAttribute("aria-label", `Remove ${s.name}`), k.textContent = "×", v(k, {
|
|
127
127
|
border: "none",
|
|
128
128
|
background: "transparent",
|
|
129
129
|
cursor: "pointer",
|
|
130
130
|
fontSize: "14px",
|
|
131
131
|
lineHeight: "1"
|
|
132
|
-
}),
|
|
133
|
-
o = o.filter((
|
|
134
|
-
}),
|
|
135
|
-
}),
|
|
132
|
+
}), k.addEventListener("click", () => {
|
|
133
|
+
o = o.filter((G, V) => V !== c), Y();
|
|
134
|
+
}), y.append(T, k), r.appendChild(y);
|
|
135
|
+
}), A();
|
|
136
136
|
}
|
|
137
|
-
const
|
|
138
|
-
const
|
|
139
|
-
return a.value = "", C(), o = [],
|
|
140
|
-
content:
|
|
141
|
-
files:
|
|
137
|
+
const O = () => {
|
|
138
|
+
const s = a.value, c = o;
|
|
139
|
+
return a.value = "", C(), o = [], Y(), {
|
|
140
|
+
content: s,
|
|
141
|
+
files: c
|
|
142
142
|
};
|
|
143
|
-
},
|
|
144
|
-
const { content:
|
|
145
|
-
(
|
|
143
|
+
}, g = () => {
|
|
144
|
+
const { content: s, files: c } = O();
|
|
145
|
+
(s.trim() || c.length > 0) && n.onSend(s.trim(), c.length > 0 ? c : void 0);
|
|
146
146
|
};
|
|
147
|
-
return i.addEventListener("submit", (
|
|
148
|
-
|
|
149
|
-
}), a.addEventListener("keydown", (
|
|
150
|
-
|
|
151
|
-
}),
|
|
147
|
+
return i.addEventListener("submit", (s) => {
|
|
148
|
+
s.preventDefault(), g();
|
|
149
|
+
}), a.addEventListener("keydown", (s) => {
|
|
150
|
+
s.key === "Enter" && !s.shiftKey && (s.preventDefault(), g());
|
|
151
|
+
}), _ && b.appendChild(_), b.append(a, p), R && i.appendChild(R), i.append(r, b), A(), {
|
|
152
152
|
inputRow: i,
|
|
153
|
-
getValueAndClear:
|
|
154
|
-
setDisabled: (
|
|
155
|
-
a.disabled =
|
|
153
|
+
getValueAndClear: O,
|
|
154
|
+
setDisabled: (s) => {
|
|
155
|
+
a.disabled = s, f = s, A();
|
|
156
156
|
},
|
|
157
157
|
focus: () => a.focus()
|
|
158
158
|
};
|
|
159
159
|
}
|
|
160
|
-
var
|
|
160
|
+
var rn = {
|
|
161
161
|
"&": "&",
|
|
162
162
|
"<": "<",
|
|
163
163
|
">": ">",
|
|
164
164
|
'"': """,
|
|
165
165
|
"'": "'"
|
|
166
166
|
};
|
|
167
|
-
function
|
|
168
|
-
return
|
|
167
|
+
function ie(n) {
|
|
168
|
+
return n.replace(/[&<>"']/g, (o) => rn[o]);
|
|
169
169
|
}
|
|
170
|
-
function
|
|
171
|
-
const o =
|
|
170
|
+
function ft(n) {
|
|
171
|
+
const o = n.trim();
|
|
172
172
|
return /^(https?:|mailto:|tel:|#|\/|\.\/|\.\.\/)/i.test(o) || !/^[a-z][a-z0-9+.-]*:/i.test(o) ? o : null;
|
|
173
173
|
}
|
|
174
|
-
var
|
|
175
|
-
function
|
|
176
|
-
const o = [], i = (
|
|
177
|
-
let r =
|
|
178
|
-
return r = r.replace(/`([^`]+)`/g, (
|
|
179
|
-
const
|
|
180
|
-
return
|
|
181
|
-
}), r = r.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (
|
|
182
|
-
const
|
|
183
|
-
return
|
|
184
|
-
}), r =
|
|
174
|
+
var ht = '"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace', Ce = "";
|
|
175
|
+
function te(n) {
|
|
176
|
+
const o = [], i = (b) => (o.push(b), `${Ce}${o.length - 1}${Ce}`);
|
|
177
|
+
let r = n;
|
|
178
|
+
return r = r.replace(/`([^`]+)`/g, (b, a) => i(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${ht}">${ie(a)}</code>`)), r = r.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g, (b, a, C) => {
|
|
179
|
+
const m = ft(C);
|
|
180
|
+
return m ? i(`<img alt="${ie(a)}" src="${ie(m)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`) : b;
|
|
181
|
+
}), r = r.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (b, a, C) => {
|
|
182
|
+
const m = ft(C);
|
|
183
|
+
return m ? i(`<a href="${ie(m)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${te(a)}</a>`) : b;
|
|
184
|
+
}), r = ie(r), r = r.replace(/\*\*([^*]+?)\*\*/g, "<strong>$1</strong>").replace(/__([^_]+?)__/g, "<strong>$1</strong>").replace(/~~([^~]+?)~~/g, "<del>$1</del>").replace(/(^|[^*])\*(?!\s)([^*]+?)\*/g, "$1<em>$2</em>").replace(/(^|[^\w_])_(?!\s)([^_]+?)_/g, "$1<em>$2</em>"), r = r.replace(new RegExp(`${Ce}(\\d+)${Ce}`, "g"), (b, a) => o[Number(a)]), r;
|
|
185
185
|
}
|
|
186
|
-
function
|
|
187
|
-
const r = document.createElement(
|
|
186
|
+
function M(n, o, i) {
|
|
187
|
+
const r = document.createElement(n);
|
|
188
188
|
return Object.assign(r.style, o), i !== void 0 && (r.innerHTML = i), r;
|
|
189
189
|
}
|
|
190
|
-
var
|
|
190
|
+
var xt = /^ {0,3}([-*_])( *\1){2,} *$/, bt = /^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/, vt = /^ {0,3}(```+|~~~+)/, Se = /^ {0,3}>\s?/, ae = /^(\s*)([-*+]|\d+[.)])\s+(.*)$/, an = [
|
|
191
191
|
"20px",
|
|
192
192
|
"18px",
|
|
193
193
|
"16px",
|
|
194
194
|
"15px",
|
|
195
195
|
"14px",
|
|
196
196
|
"13px"
|
|
197
|
-
],
|
|
198
|
-
function
|
|
199
|
-
return
|
|
197
|
+
], Oe = (n) => n.match(/^\s*/)?.[0].length ?? 0;
|
|
198
|
+
function sn(n) {
|
|
199
|
+
return n.trim() === "" || xt.test(n) || bt.test(n) || vt.test(n) || Se.test(n) || ae.test(n);
|
|
200
200
|
}
|
|
201
|
-
function
|
|
202
|
-
const o =
|
|
201
|
+
function yt(n) {
|
|
202
|
+
const o = n[0].match(ae), i = o[1].length, r = /\d/.test(o[2]), b = M(r ? "ol" : "ul", {
|
|
203
203
|
margin: "0 0 8px 0",
|
|
204
204
|
paddingLeft: "20px",
|
|
205
205
|
listStyleType: r ? "decimal" : "disc",
|
|
206
206
|
listStylePosition: "outside"
|
|
207
207
|
});
|
|
208
208
|
let a = 0;
|
|
209
|
-
for (; a <
|
|
210
|
-
const C =
|
|
211
|
-
for (a++; a <
|
|
212
|
-
|
|
213
|
-
const
|
|
209
|
+
for (; a < n.length; ) {
|
|
210
|
+
const C = n[a].match(ae), m = [];
|
|
211
|
+
for (a++; a < n.length && Oe(n[a]) > i; )
|
|
212
|
+
m.push(n[a]), a++;
|
|
213
|
+
const x = M("li", {
|
|
214
214
|
display: "list-item",
|
|
215
215
|
margin: "2px 0",
|
|
216
216
|
lineHeight: "1.6"
|
|
217
|
-
}),
|
|
218
|
-
|
|
217
|
+
}), p = C[3].match(/^\[([ xX])\]\s+(.*)$/);
|
|
218
|
+
p ? (x.style.listStyleType = "none", x.style.marginLeft = "-20px", x.innerHTML = `<span style="margin-right:6px">${p[1].toLowerCase() === "x" ? "☑" : "☐"}</span>${te(p[2])}`) : x.innerHTML = te(C[3]), m.filter((f) => ae.test(f)).length > 0 && x.appendChild(yt(m.filter((f) => f.trim() !== ""))), b.appendChild(x);
|
|
219
219
|
}
|
|
220
|
-
return
|
|
220
|
+
return b;
|
|
221
221
|
}
|
|
222
|
-
function
|
|
223
|
-
const o = (
|
|
222
|
+
function ln(n) {
|
|
223
|
+
const o = (m) => m.replace(/^\s*\|?/, "").replace(/\|?\s*$/, "").split("|").map((x) => x.trim()), i = M("div", {
|
|
224
224
|
overflowX: "auto",
|
|
225
225
|
margin: "0 0 8px 0"
|
|
226
|
-
}), r =
|
|
226
|
+
}), r = M("table", {
|
|
227
227
|
borderCollapse: "collapse",
|
|
228
228
|
width: "100%",
|
|
229
229
|
fontSize: "13px"
|
|
230
|
-
}),
|
|
231
|
-
for (const
|
|
230
|
+
}), b = document.createElement("thead"), a = document.createElement("tr");
|
|
231
|
+
for (const m of o(n[0])) a.appendChild(M("th", {
|
|
232
232
|
border: "1px solid #dee3e8",
|
|
233
233
|
padding: "6px 10px",
|
|
234
234
|
textAlign: "left",
|
|
235
235
|
backgroundColor: "#f5f7fa",
|
|
236
236
|
fontWeight: "600"
|
|
237
|
-
},
|
|
238
|
-
|
|
237
|
+
}, te(m)));
|
|
238
|
+
b.appendChild(a), r.appendChild(b);
|
|
239
239
|
const C = document.createElement("tbody");
|
|
240
|
-
for (const
|
|
241
|
-
const
|
|
242
|
-
for (const
|
|
240
|
+
for (const m of n.slice(2)) {
|
|
241
|
+
const x = document.createElement("tr");
|
|
242
|
+
for (const p of o(m)) x.appendChild(M("td", {
|
|
243
243
|
border: "1px solid #dee3e8",
|
|
244
244
|
padding: "6px 10px"
|
|
245
|
-
},
|
|
246
|
-
C.appendChild(
|
|
245
|
+
}, te(p)));
|
|
246
|
+
C.appendChild(x);
|
|
247
247
|
}
|
|
248
248
|
return r.appendChild(C), i.appendChild(r), i;
|
|
249
249
|
}
|
|
250
|
-
var
|
|
251
|
-
function
|
|
252
|
-
const o = document.createDocumentFragment(), i =
|
|
250
|
+
var dn = (n) => !!n && /^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(n);
|
|
251
|
+
function De(n) {
|
|
252
|
+
const o = document.createDocumentFragment(), i = n.replace(/\r\n?/g, `
|
|
253
253
|
`).split(`
|
|
254
254
|
`);
|
|
255
255
|
let r = 0;
|
|
@@ -259,106 +259,106 @@ function Te(t) {
|
|
|
259
259
|
r++;
|
|
260
260
|
continue;
|
|
261
261
|
}
|
|
262
|
-
const C = a.match(
|
|
262
|
+
const C = a.match(vt);
|
|
263
263
|
if (C) {
|
|
264
|
-
const
|
|
265
|
-
for (r++; r < i.length && !new RegExp(`^ {0,3}${
|
|
266
|
-
|
|
264
|
+
const p = C[1][0], f = [];
|
|
265
|
+
for (r++; r < i.length && !new RegExp(`^ {0,3}${p === "`" ? "`{3,}" : "~{3,}"}\\s*$`).test(i[r]); )
|
|
266
|
+
f.push(i[r]), r++;
|
|
267
267
|
r++;
|
|
268
|
-
const
|
|
269
|
-
|
|
268
|
+
const A = M("pre", { margin: "0 0 8px 0" });
|
|
269
|
+
A.appendChild(M("code", {
|
|
270
270
|
display: "block",
|
|
271
271
|
background: "#f5f5f5",
|
|
272
272
|
padding: "8px 12px",
|
|
273
273
|
borderRadius: "6px",
|
|
274
274
|
fontSize: "13px",
|
|
275
275
|
overflowX: "auto",
|
|
276
|
-
fontFamily:
|
|
276
|
+
fontFamily: ht,
|
|
277
277
|
whiteSpace: "pre"
|
|
278
|
-
},
|
|
279
|
-
`)))), o.appendChild(
|
|
278
|
+
}, ie(f.join(`
|
|
279
|
+
`)))), o.appendChild(A);
|
|
280
280
|
continue;
|
|
281
281
|
}
|
|
282
|
-
if (
|
|
283
|
-
o.appendChild(
|
|
282
|
+
if (xt.test(a)) {
|
|
283
|
+
o.appendChild(M("hr", {
|
|
284
284
|
border: "none",
|
|
285
285
|
borderTop: "1px solid #dee3e8",
|
|
286
286
|
margin: "12px 0"
|
|
287
287
|
})), r++;
|
|
288
288
|
continue;
|
|
289
289
|
}
|
|
290
|
-
const
|
|
291
|
-
if (
|
|
292
|
-
const
|
|
293
|
-
o.appendChild(
|
|
290
|
+
const m = a.match(bt);
|
|
291
|
+
if (m) {
|
|
292
|
+
const p = m[1].length;
|
|
293
|
+
o.appendChild(M(`h${p}`, {
|
|
294
294
|
margin: "16px 0 8px 0",
|
|
295
|
-
fontSize:
|
|
295
|
+
fontSize: an[p - 1],
|
|
296
296
|
fontWeight: "600",
|
|
297
297
|
lineHeight: "1.3"
|
|
298
|
-
},
|
|
298
|
+
}, te(m[2]))), r++;
|
|
299
299
|
continue;
|
|
300
300
|
}
|
|
301
|
-
if (
|
|
302
|
-
const
|
|
303
|
-
for (; r < i.length &&
|
|
304
|
-
|
|
305
|
-
const
|
|
301
|
+
if (Se.test(a)) {
|
|
302
|
+
const p = [];
|
|
303
|
+
for (; r < i.length && Se.test(i[r]); )
|
|
304
|
+
p.push(i[r].replace(Se, "")), r++;
|
|
305
|
+
const f = M("blockquote", {
|
|
306
306
|
borderLeft: "4px solid #dee3e8",
|
|
307
307
|
paddingLeft: "12px",
|
|
308
308
|
margin: "0 0 8px 0",
|
|
309
309
|
fontStyle: "italic",
|
|
310
310
|
color: "#6b6d6f"
|
|
311
311
|
});
|
|
312
|
-
|
|
313
|
-
`))), o.appendChild(
|
|
312
|
+
f.appendChild(De(p.join(`
|
|
313
|
+
`))), o.appendChild(f);
|
|
314
314
|
continue;
|
|
315
315
|
}
|
|
316
|
-
if (a.includes("|") &&
|
|
317
|
-
const
|
|
316
|
+
if (a.includes("|") && dn(i[r + 1])) {
|
|
317
|
+
const p = [a, i[r + 1]];
|
|
318
318
|
for (r += 2; r < i.length && i[r].includes("|") && i[r].trim(); )
|
|
319
|
-
|
|
320
|
-
o.appendChild(
|
|
319
|
+
p.push(i[r]), r++;
|
|
320
|
+
o.appendChild(ln(p));
|
|
321
321
|
continue;
|
|
322
322
|
}
|
|
323
|
-
if (
|
|
324
|
-
const
|
|
323
|
+
if (ae.test(a)) {
|
|
324
|
+
const p = [], f = Oe(a);
|
|
325
325
|
for (; r < i.length && i[r].trim() !== ""; )
|
|
326
|
-
if (
|
|
327
|
-
|
|
326
|
+
if (ae.test(i[r]) || Oe(i[r]) > f)
|
|
327
|
+
p.push(i[r]), r++;
|
|
328
328
|
else break;
|
|
329
|
-
o.appendChild(
|
|
329
|
+
o.appendChild(yt(p));
|
|
330
330
|
continue;
|
|
331
331
|
}
|
|
332
|
-
const
|
|
333
|
-
for (r++; r < i.length && !
|
|
334
|
-
|
|
335
|
-
o.appendChild(
|
|
332
|
+
const x = [a];
|
|
333
|
+
for (r++; r < i.length && !sn(i[r]); )
|
|
334
|
+
x.push(i[r]), r++;
|
|
335
|
+
o.appendChild(M("p", {
|
|
336
336
|
margin: "0 0 8px 0",
|
|
337
337
|
lineHeight: "1.6"
|
|
338
|
-
},
|
|
338
|
+
}, x.map((p) => te(p)).join("<br>")));
|
|
339
339
|
}
|
|
340
|
-
const
|
|
341
|
-
return
|
|
340
|
+
const b = o.lastElementChild;
|
|
341
|
+
return b && (b.style.marginBottom = "0"), o;
|
|
342
342
|
}
|
|
343
|
-
function
|
|
344
|
-
const { isLast: i, isLastOfBlock: r, bubbleStyle:
|
|
343
|
+
function cn(n, o) {
|
|
344
|
+
const { isLast: i, isLastOfBlock: r, bubbleStyle: b, showAgentName: a, agentBubble: C, followUpEnabled: m, followUpHandler: x, isMobile: p } = o, f = n.role === "user", A = b === "imessage", R = h({
|
|
345
345
|
display: "flex",
|
|
346
346
|
flexDirection: "column",
|
|
347
|
-
alignItems:
|
|
348
|
-
marginBottom:
|
|
347
|
+
alignItems: f ? "flex-end" : "flex-start",
|
|
348
|
+
marginBottom: A && !r ? "2px" : "16px"
|
|
349
349
|
});
|
|
350
|
-
if (R.className = `ago-message ago-message--${
|
|
351
|
-
const g =
|
|
350
|
+
if (R.className = `ago-message ago-message--${n.role}`, !f && a && n.agent) {
|
|
351
|
+
const g = h({
|
|
352
352
|
fontSize: "13px",
|
|
353
353
|
fontWeight: "500",
|
|
354
|
-
color:
|
|
354
|
+
color: J,
|
|
355
355
|
marginBottom: "6px",
|
|
356
356
|
padding: "0 4px"
|
|
357
357
|
});
|
|
358
|
-
g.className = "ago-message__agent", g.textContent =
|
|
358
|
+
g.className = "ago-message__agent", g.textContent = n.agent.displayName || n.agent.name, R.appendChild(g);
|
|
359
359
|
}
|
|
360
|
-
if (!
|
|
361
|
-
const g =
|
|
360
|
+
if (!f && n.sources && n.sources.length > 0) {
|
|
361
|
+
const g = h({
|
|
362
362
|
display: "grid",
|
|
363
363
|
gridTemplateColumns: "1fr 1fr",
|
|
364
364
|
gap: "6px",
|
|
@@ -366,28 +366,28 @@ function on(t, o) {
|
|
|
366
366
|
width: "100%",
|
|
367
367
|
maxWidth: "85%"
|
|
368
368
|
});
|
|
369
|
-
g.className = "ago-message__sources",
|
|
370
|
-
const
|
|
371
|
-
|
|
369
|
+
g.className = "ago-message__sources", n.sources.forEach((s, c) => {
|
|
370
|
+
const y = s.url ? document.createElement("a") : document.createElement("div");
|
|
371
|
+
s.url && y instanceof HTMLAnchorElement && (y.href = s.url, y.target = "_blank", y.rel = "noopener noreferrer"), v(y, {
|
|
372
372
|
display: "flex",
|
|
373
373
|
alignItems: "center",
|
|
374
374
|
gap: "8px",
|
|
375
375
|
padding: "8px 10px",
|
|
376
|
-
border: `1px solid ${
|
|
376
|
+
border: `1px solid ${L}`,
|
|
377
377
|
borderRadius: "8px",
|
|
378
|
-
backgroundColor:
|
|
378
|
+
backgroundColor: ee,
|
|
379
379
|
textDecoration: "none",
|
|
380
|
-
color:
|
|
380
|
+
color: J,
|
|
381
381
|
fontSize: "12px",
|
|
382
382
|
overflow: "hidden"
|
|
383
383
|
});
|
|
384
|
-
const
|
|
384
|
+
const T = h({
|
|
385
385
|
flexShrink: "0",
|
|
386
386
|
width: "18px",
|
|
387
387
|
height: "18px",
|
|
388
388
|
borderRadius: "3px",
|
|
389
|
-
border: `1px solid ${
|
|
390
|
-
color:
|
|
389
|
+
border: `1px solid ${Be}`,
|
|
390
|
+
color: Be,
|
|
391
391
|
fontSize: "11px",
|
|
392
392
|
fontWeight: "500",
|
|
393
393
|
display: "flex",
|
|
@@ -395,176 +395,176 @@ function on(t, o) {
|
|
|
395
395
|
justifyContent: "center",
|
|
396
396
|
backgroundColor: "#f0f4ff"
|
|
397
397
|
});
|
|
398
|
-
|
|
399
|
-
const
|
|
398
|
+
T.textContent = String(c + 1);
|
|
399
|
+
const k = h({
|
|
400
400
|
overflow: "hidden",
|
|
401
401
|
textOverflow: "ellipsis",
|
|
402
402
|
whiteSpace: "nowrap"
|
|
403
403
|
});
|
|
404
|
-
|
|
404
|
+
k.textContent = s.title, k.title = s.title, y.append(T, k), g.appendChild(y);
|
|
405
405
|
}), R.appendChild(g);
|
|
406
406
|
}
|
|
407
|
-
if (
|
|
408
|
-
const g =
|
|
407
|
+
if (n.attachments && n.attachments.length > 0) {
|
|
408
|
+
const g = h({
|
|
409
409
|
display: "flex",
|
|
410
410
|
flexWrap: "wrap",
|
|
411
411
|
gap: "6px",
|
|
412
412
|
marginBottom: "6px",
|
|
413
|
-
justifyContent:
|
|
413
|
+
justifyContent: f ? "flex-end" : "flex-start",
|
|
414
414
|
maxWidth: "75%"
|
|
415
415
|
});
|
|
416
416
|
g.className = "ago-message__attachments";
|
|
417
|
-
for (const
|
|
418
|
-
const
|
|
419
|
-
if (
|
|
420
|
-
const
|
|
421
|
-
|
|
417
|
+
for (const s of n.attachments) {
|
|
418
|
+
const c = jt(s.url);
|
|
419
|
+
if (Ut(s) && c) {
|
|
420
|
+
const B = document.createElement("a");
|
|
421
|
+
B.href = c, B.target = "_blank", B.rel = "noopener noreferrer", v(B, {
|
|
422
422
|
display: "inline-block",
|
|
423
423
|
textDecoration: "none"
|
|
424
424
|
});
|
|
425
425
|
const j = document.createElement("img");
|
|
426
|
-
j.src =
|
|
426
|
+
j.src = c, j.alt = s.name, j.loading = "lazy", v(j, {
|
|
427
427
|
maxWidth: "180px",
|
|
428
428
|
maxHeight: "160px",
|
|
429
429
|
objectFit: "cover",
|
|
430
430
|
borderRadius: "10px",
|
|
431
|
-
border: `1px solid ${
|
|
431
|
+
border: `1px solid ${L}`,
|
|
432
432
|
display: "block"
|
|
433
|
-
}),
|
|
433
|
+
}), B.appendChild(j), g.appendChild(B);
|
|
434
434
|
continue;
|
|
435
435
|
}
|
|
436
|
-
const
|
|
437
|
-
|
|
436
|
+
const y = c ? document.createElement("a") : document.createElement("div");
|
|
437
|
+
c && y instanceof HTMLAnchorElement && (y.href = c, y.target = "_blank", y.rel = "noopener noreferrer"), v(y, {
|
|
438
438
|
display: "inline-flex",
|
|
439
439
|
alignItems: "center",
|
|
440
440
|
gap: "8px",
|
|
441
441
|
padding: "8px 12px",
|
|
442
442
|
borderRadius: "10px",
|
|
443
|
-
border: `1px solid ${
|
|
444
|
-
backgroundColor:
|
|
445
|
-
color:
|
|
443
|
+
border: `1px solid ${L}`,
|
|
444
|
+
backgroundColor: f ? "rgba(255,255,255,0.12)" : ee,
|
|
445
|
+
color: f ? ke : J,
|
|
446
446
|
fontSize: "13px",
|
|
447
447
|
textDecoration: "none",
|
|
448
448
|
maxWidth: "220px"
|
|
449
449
|
});
|
|
450
|
-
const
|
|
451
|
-
|
|
450
|
+
const T = document.createElement("span");
|
|
451
|
+
T.textContent = "📄", T.setAttribute("aria-hidden", "true"), v(T, {
|
|
452
452
|
fontSize: "16px",
|
|
453
453
|
lineHeight: "1",
|
|
454
454
|
flexShrink: "0"
|
|
455
455
|
});
|
|
456
|
-
const
|
|
456
|
+
const k = h({
|
|
457
457
|
display: "flex",
|
|
458
458
|
flexDirection: "column",
|
|
459
459
|
minWidth: "0"
|
|
460
|
-
}),
|
|
460
|
+
}), G = h({
|
|
461
461
|
overflow: "hidden",
|
|
462
462
|
textOverflow: "ellipsis",
|
|
463
463
|
whiteSpace: "nowrap",
|
|
464
464
|
maxWidth: "160px"
|
|
465
465
|
});
|
|
466
|
-
|
|
467
|
-
const
|
|
468
|
-
if (
|
|
469
|
-
const
|
|
466
|
+
G.textContent = s.name, G.title = s.name, k.appendChild(G);
|
|
467
|
+
const V = Vt(s.fileSize);
|
|
468
|
+
if (V) {
|
|
469
|
+
const B = h({
|
|
470
470
|
fontSize: "11px",
|
|
471
|
-
color:
|
|
471
|
+
color: gt
|
|
472
472
|
});
|
|
473
|
-
|
|
473
|
+
B.textContent = V, k.appendChild(B);
|
|
474
474
|
}
|
|
475
|
-
|
|
475
|
+
y.append(T, k), g.appendChild(y);
|
|
476
476
|
}
|
|
477
477
|
R.appendChild(g);
|
|
478
478
|
}
|
|
479
|
-
const
|
|
480
|
-
maxWidth:
|
|
481
|
-
padding:
|
|
482
|
-
borderRadius:
|
|
483
|
-
backgroundColor:
|
|
484
|
-
color:
|
|
479
|
+
const _ = f || C || A, Y = !!n.content || n.status === "IN_PROGRESS", O = h({
|
|
480
|
+
maxWidth: _ ? A || f ? p ? "88%" : "75%" : p ? "92%" : "85%" : "100%",
|
|
481
|
+
padding: _ ? "10px 14px" : "2px 8px",
|
|
482
|
+
borderRadius: A ? en : _ ? Me : "0",
|
|
483
|
+
backgroundColor: f ? Re : _ ? ct : "transparent",
|
|
484
|
+
color: f ? ke : J,
|
|
485
485
|
overflowWrap: "break-word",
|
|
486
486
|
textWrap: "pretty",
|
|
487
487
|
fontSize: "16px",
|
|
488
488
|
lineHeight: "1.6"
|
|
489
489
|
});
|
|
490
|
-
if (
|
|
491
|
-
|
|
492
|
-
const g =
|
|
490
|
+
if (O.className = "ago-message__content", A && r) {
|
|
491
|
+
O.style.position = "relative";
|
|
492
|
+
const g = h({
|
|
493
493
|
position: "absolute",
|
|
494
494
|
zIndex: "0",
|
|
495
495
|
bottom: "-2px",
|
|
496
496
|
width: "20px",
|
|
497
497
|
height: "20px",
|
|
498
|
-
background:
|
|
498
|
+
background: f ? Re : ct
|
|
499
499
|
});
|
|
500
500
|
g.className = "ago-message__tail";
|
|
501
|
-
const
|
|
501
|
+
const s = h({
|
|
502
502
|
position: "absolute",
|
|
503
503
|
zIndex: "1",
|
|
504
504
|
bottom: "-2px",
|
|
505
505
|
width: "10px",
|
|
506
506
|
height: "20px",
|
|
507
|
-
background:
|
|
507
|
+
background: mt
|
|
508
508
|
});
|
|
509
|
-
|
|
509
|
+
s.className = "ago-message__tail-mask", f ? (g.style.right = "-8px", g.style.borderBottomLeftRadius = "16px 14px", s.style.right = "-10px", s.style.borderBottomLeftRadius = "10px") : (g.style.left = "-7px", g.style.borderBottomRightRadius = "16px 14px", s.style.left = "-10px", s.style.borderBottomRightRadius = "10px"), O.append(g, s);
|
|
510
510
|
}
|
|
511
|
-
if (
|
|
512
|
-
const g =
|
|
511
|
+
if (n.content ? O.appendChild(De(n.content)) : n.status === "IN_PROGRESS" && O.appendChild(fn()), Y && R.appendChild(O), i && n.followUpReplies && n.followUpReplies.length > 0) {
|
|
512
|
+
const g = h({
|
|
513
513
|
display: "flex",
|
|
514
514
|
flexWrap: "wrap",
|
|
515
515
|
gap: "8px",
|
|
516
516
|
marginTop: "10px"
|
|
517
517
|
});
|
|
518
518
|
g.className = "ago-message__followups";
|
|
519
|
-
for (const
|
|
520
|
-
const
|
|
521
|
-
|
|
519
|
+
for (const s of n.followUpReplies) {
|
|
520
|
+
const c = document.createElement("button");
|
|
521
|
+
c.type = "button", c.className = "ago-message__followup-btn", c.textContent = s, c.disabled = !m, v(c, {
|
|
522
522
|
minHeight: "36px",
|
|
523
523
|
padding: "6px 14px",
|
|
524
524
|
fontSize: "14px",
|
|
525
|
-
borderRadius:
|
|
526
|
-
border: `1px solid ${
|
|
527
|
-
backgroundColor:
|
|
528
|
-
color:
|
|
529
|
-
cursor:
|
|
525
|
+
borderRadius: Me,
|
|
526
|
+
border: `1px solid ${L}`,
|
|
527
|
+
backgroundColor: ee,
|
|
528
|
+
color: J,
|
|
529
|
+
cursor: m ? "pointer" : "default",
|
|
530
530
|
transition: "border-color 0.15s"
|
|
531
|
-
}),
|
|
532
|
-
|
|
533
|
-
}),
|
|
534
|
-
|
|
535
|
-
}), g.appendChild(
|
|
531
|
+
}), x && c.addEventListener("click", () => x(s)), c.addEventListener("mouseenter", () => {
|
|
532
|
+
c.style.borderColor = Be;
|
|
533
|
+
}), c.addEventListener("mouseleave", () => {
|
|
534
|
+
c.style.borderColor = L;
|
|
535
|
+
}), g.appendChild(c);
|
|
536
536
|
}
|
|
537
537
|
R.appendChild(g);
|
|
538
538
|
}
|
|
539
539
|
return R;
|
|
540
540
|
}
|
|
541
|
-
function
|
|
542
|
-
const o =
|
|
541
|
+
function pn(n) {
|
|
542
|
+
const o = h({
|
|
543
543
|
display: "flex",
|
|
544
544
|
alignItems: "center",
|
|
545
545
|
gap: "8px",
|
|
546
546
|
padding: "10px 14px",
|
|
547
547
|
backgroundColor: "#f0fdf4",
|
|
548
548
|
color: "#15803d",
|
|
549
|
-
borderRadius:
|
|
549
|
+
borderRadius: Me,
|
|
550
550
|
marginTop: "8px",
|
|
551
551
|
fontSize: "13px",
|
|
552
552
|
border: "1px solid #bbf7d0"
|
|
553
553
|
});
|
|
554
554
|
o.className = "ago-form-notice", o.setAttribute("role", "status");
|
|
555
555
|
const i = document.createElement("span");
|
|
556
|
-
i.textContent = "✓", i.setAttribute("aria-hidden", "true"),
|
|
556
|
+
i.textContent = "✓", i.setAttribute("aria-hidden", "true"), v(i, { fontWeight: "700" });
|
|
557
557
|
const r = document.createElement("span");
|
|
558
|
-
return r.textContent =
|
|
558
|
+
return r.textContent = n, o.append(i, r), o;
|
|
559
559
|
}
|
|
560
|
-
function
|
|
561
|
-
const
|
|
560
|
+
function fn() {
|
|
561
|
+
const n = h({
|
|
562
562
|
display: "flex",
|
|
563
563
|
gap: "4px",
|
|
564
564
|
padding: "4px 0"
|
|
565
565
|
});
|
|
566
566
|
for (let o = 0; o < 3; o++) {
|
|
567
|
-
const i =
|
|
567
|
+
const i = h({
|
|
568
568
|
width: "6px",
|
|
569
569
|
height: "6px",
|
|
570
570
|
borderRadius: "50%",
|
|
@@ -572,21 +572,21 @@ function an() {
|
|
|
572
572
|
animation: "ago-pulse 1.2s ease-in-out infinite",
|
|
573
573
|
animationDelay: `${o * 0.2}s`
|
|
574
574
|
});
|
|
575
|
-
|
|
575
|
+
n.appendChild(i);
|
|
576
576
|
}
|
|
577
|
-
return
|
|
577
|
+
return n;
|
|
578
578
|
}
|
|
579
|
-
function
|
|
580
|
-
const
|
|
579
|
+
function un() {
|
|
580
|
+
const n = "http://www.w3.org/2000/svg", o = document.createElementNS(n, "svg");
|
|
581
581
|
o.setAttribute("width", "26"), o.setAttribute("height", "26"), o.setAttribute("viewBox", "0 0 24 24"), o.setAttribute("fill", "none");
|
|
582
|
-
const i = document.createElementNS(
|
|
582
|
+
const i = document.createElementNS(n, "path");
|
|
583
583
|
return i.setAttribute("d", "M21 11.5a8.38 8.38 0 0 1-8.5 8.5 8.5 8.5 0 0 1-3.8-.9L3 21l1.9-5.7a8.5 8.5 0 0 1-.9-3.8 8.38 8.38 0 0 1 8.5-8.5 8.38 8.38 0 0 1 8.5 8.5z"), i.setAttribute("stroke", "currentColor"), i.setAttribute("stroke-width", "2"), i.setAttribute("stroke-linecap", "round"), i.setAttribute("stroke-linejoin", "round"), o.appendChild(i), o;
|
|
584
584
|
}
|
|
585
|
-
var
|
|
586
|
-
function
|
|
587
|
-
if (typeof
|
|
588
|
-
if (!
|
|
589
|
-
const o =
|
|
585
|
+
var ut = "Form submitted.";
|
|
586
|
+
function mn(n) {
|
|
587
|
+
if (typeof n == "string") return n || null;
|
|
588
|
+
if (!n || typeof n != "object") return null;
|
|
589
|
+
const o = n;
|
|
590
590
|
if (typeof o.message == "string" && o.message) return o.message;
|
|
591
591
|
const i = o.result;
|
|
592
592
|
if (typeof i == "string" && i) return i;
|
|
@@ -596,186 +596,187 @@ function ln(t) {
|
|
|
596
596
|
}
|
|
597
597
|
return null;
|
|
598
598
|
}
|
|
599
|
-
var
|
|
600
|
-
function
|
|
601
|
-
const o = typeof
|
|
602
|
-
if (!o) throw new Error(`mountChatWidget: target "${String(
|
|
599
|
+
var gn = 0;
|
|
600
|
+
function hn(n) {
|
|
601
|
+
const o = typeof n == "string" ? document.querySelector(n) : n;
|
|
602
|
+
if (!o) throw new Error(`mountChatWidget: target "${String(n)}" not found.`);
|
|
603
603
|
return o;
|
|
604
604
|
}
|
|
605
|
-
function
|
|
606
|
-
const { title: i = "Chat", welcomeMessage: r = "Hello! How can I help you today?", placeholder:
|
|
605
|
+
function yn(n, o) {
|
|
606
|
+
const { title: i = "Chat", welcomeMessage: r = "Hello! How can I help you today?", placeholder: b = "Type a message...", allowFiles: a = !1, height: C = 500, placement: m = "inline", width: x = 400, defaultOpen: p = !1, logoUrl: f, showAgentName: A = !1, agentBubble: R = !1, bubbleStyle: _ = "default", showHeader: Y = !0, theme: O, loadThreads: g = !1, forms: s, formSubmittedMessage: c = ut, onFollowUpClick: y, onMessageSent: T, onMessageReceived: k, onFormSubmitted: G, onFormError: V, onOpen: B, onClose: j } = o, ne = typeof r == "string" ? {
|
|
607
607
|
message: r,
|
|
608
608
|
mode: "static"
|
|
609
|
-
} : r,
|
|
610
|
-
if (!o.client && !o.config?.baseUrl) throw new
|
|
611
|
-
const E = o.client ?? new
|
|
612
|
-
let
|
|
613
|
-
const
|
|
614
|
-
let P = o.conversationId ??
|
|
615
|
-
const
|
|
616
|
-
function
|
|
617
|
-
if (typeof
|
|
618
|
-
const
|
|
619
|
-
if (typeof
|
|
609
|
+
} : r, ze = ne.message, Fe = ne.mode ?? "static", wt = "speed" in ne && ne.speed || 45, He = "followUpReplies" in ne && ne.followUpReplies || void 0;
|
|
610
|
+
if (!o.client && !o.config?.baseUrl) throw new Gt("mountChatWidget requires either `client` or `config` (with a baseUrl).", "config_missing_base_url");
|
|
611
|
+
const E = o.client ?? new qt(o.config), Pe = hn(n), D = m === "left" || m === "right", Ct = D && (o.launcher ?? !0);
|
|
612
|
+
let oe = D ? p : !0;
|
|
613
|
+
const Et = o.mobile?.breakpoint ?? 768, St = o.mobile?.trigger ?? "focus", Ue = typeof window < "u" && !!window.matchMedia, z = Ue ? window.matchMedia(`(max-width: ${Et}px)`) : void 0, Rt = Ue ? window.matchMedia("(prefers-reduced-motion: reduce)") : void 0, se = !D && !!z, Ae = o.persistConversation, ue = Ae ? Qt(Ae === !0 ? {} : Ae) : void 0;
|
|
614
|
+
let P = o.conversationId ?? ue?.getLastActiveThread() ?? void 0, u = [], Z = !1, le = null, q;
|
|
615
|
+
const We = [];
|
|
616
|
+
function kt(e) {
|
|
617
|
+
if (typeof c == "function") {
|
|
618
|
+
const l = c(e);
|
|
619
|
+
if (typeof l == "string" && l) return l;
|
|
620
620
|
}
|
|
621
|
-
const
|
|
622
|
-
return
|
|
621
|
+
const t = mn(e);
|
|
622
|
+
return t || (typeof c == "string" ? c : ut);
|
|
623
623
|
}
|
|
624
|
-
const
|
|
624
|
+
const me = [], d = h({
|
|
625
625
|
display: "flex",
|
|
626
626
|
flexDirection: "column",
|
|
627
|
-
height:
|
|
628
|
-
border: `1px solid ${
|
|
629
|
-
borderRadius:
|
|
627
|
+
height: D ? "100%" : typeof C == "number" ? `${C}px` : C,
|
|
628
|
+
border: `1px solid ${L}`,
|
|
629
|
+
borderRadius: Jt,
|
|
630
630
|
overflow: "hidden",
|
|
631
|
-
backgroundColor:
|
|
632
|
-
fontFamily:
|
|
631
|
+
backgroundColor: ee,
|
|
632
|
+
fontFamily: Ee,
|
|
633
633
|
textAlign: "left",
|
|
634
634
|
boxShadow: "rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"
|
|
635
635
|
});
|
|
636
|
-
d.className = "ago-chat-widget",
|
|
637
|
-
let
|
|
638
|
-
if (
|
|
639
|
-
if (
|
|
636
|
+
d.className = "ago-chat-widget", tn(d, O);
|
|
637
|
+
let F;
|
|
638
|
+
if (Y) {
|
|
639
|
+
if (F = h({
|
|
640
640
|
padding: "14px 16px",
|
|
641
|
-
borderBottom: `1px solid ${
|
|
642
|
-
backgroundColor:
|
|
643
|
-
color:
|
|
641
|
+
borderBottom: `1px solid ${L}`,
|
|
642
|
+
backgroundColor: Zt,
|
|
643
|
+
color: dt,
|
|
644
644
|
display: "flex",
|
|
645
645
|
alignItems: "center",
|
|
646
646
|
gap: "10px"
|
|
647
|
-
}),
|
|
648
|
-
const
|
|
649
|
-
|
|
647
|
+
}), F.className = "ago-chat-widget__header", f) {
|
|
648
|
+
const t = document.createElement("img");
|
|
649
|
+
t.src = f, t.alt = "Logo", v(t, {
|
|
650
650
|
height: "24px",
|
|
651
651
|
width: "auto"
|
|
652
|
-
}),
|
|
652
|
+
}), F.appendChild(t);
|
|
653
653
|
}
|
|
654
654
|
const e = document.createElement("h3");
|
|
655
|
-
if (e.textContent = i,
|
|
655
|
+
if (e.textContent = i, v(e, {
|
|
656
656
|
margin: "0",
|
|
657
657
|
fontSize: "15px",
|
|
658
658
|
fontWeight: "600"
|
|
659
|
-
}),
|
|
660
|
-
const
|
|
661
|
-
|
|
659
|
+
}), F.appendChild(e), D) {
|
|
660
|
+
const t = document.createElement("button");
|
|
661
|
+
t.type = "button", t.className = "ago-chat-widget__close", t.setAttribute("aria-label", "Close"), t.textContent = "×", v(t, {
|
|
662
662
|
marginLeft: "auto",
|
|
663
663
|
background: "transparent",
|
|
664
664
|
border: "none",
|
|
665
|
-
color:
|
|
665
|
+
color: dt,
|
|
666
666
|
fontSize: "22px",
|
|
667
667
|
lineHeight: "1",
|
|
668
668
|
cursor: "pointer",
|
|
669
669
|
padding: "0 2px"
|
|
670
|
-
}),
|
|
670
|
+
}), t.addEventListener("click", () => Te()), F.appendChild(t);
|
|
671
671
|
}
|
|
672
672
|
}
|
|
673
|
-
const
|
|
673
|
+
const I = h({
|
|
674
674
|
flex: "1",
|
|
675
675
|
overflow: "auto",
|
|
676
676
|
padding: "16px",
|
|
677
|
-
backgroundColor:
|
|
677
|
+
backgroundColor: mt
|
|
678
678
|
});
|
|
679
|
-
|
|
680
|
-
const { inputRow:
|
|
681
|
-
placeholder:
|
|
679
|
+
I.className = "ago-chat-widget__messages", I.setAttribute("role", "log"), I.setAttribute("aria-live", "polite"), I.setAttribute("aria-relevant", "additions text"), I.setAttribute("aria-atomic", "false");
|
|
680
|
+
const { inputRow: _e, setDisabled: At, focus: ge } = on({
|
|
681
|
+
placeholder: b,
|
|
682
682
|
allowFiles: a,
|
|
683
|
-
onSend: (e,
|
|
684
|
-
|
|
683
|
+
onSend: (e, t) => {
|
|
684
|
+
$e(e, t);
|
|
685
685
|
}
|
|
686
686
|
});
|
|
687
|
-
|
|
688
|
-
let
|
|
689
|
-
const
|
|
690
|
-
if (
|
|
687
|
+
nn(), d.append(...F ? [F] : [], I, _e);
|
|
688
|
+
let he = d, U, N;
|
|
689
|
+
const xe = m === "left" ? "left" : "right";
|
|
690
|
+
if (D && (U = h({
|
|
691
691
|
position: "fixed",
|
|
692
692
|
top: "0",
|
|
693
693
|
bottom: "0",
|
|
694
|
-
[
|
|
695
|
-
width: typeof
|
|
694
|
+
[xe]: "0",
|
|
695
|
+
width: typeof x == "number" ? `${x}px` : x,
|
|
696
696
|
maxWidth: "100vw",
|
|
697
697
|
display: "flex",
|
|
698
698
|
zIndex: "2147483000",
|
|
699
699
|
transition: "transform 0.3s ease",
|
|
700
700
|
boxShadow: "rgba(15, 15, 15, 0.18) 0px 0px 24px 0px"
|
|
701
|
-
}),
|
|
701
|
+
}), U.className = "ago-chat-widget-panel", v(d, {
|
|
702
702
|
height: "100%",
|
|
703
703
|
width: "100%",
|
|
704
704
|
borderRadius: "0",
|
|
705
705
|
border: "none",
|
|
706
706
|
boxShadow: "none",
|
|
707
|
-
[
|
|
708
|
-
}),
|
|
709
|
-
if (
|
|
707
|
+
[xe === "left" ? "borderRight" : "borderLeft"]: `1px solid ${L}`
|
|
708
|
+
}), U.appendChild(d), he = U), Ct) {
|
|
709
|
+
if (N = document.createElement("button"), N.type = "button", N.className = "ago-chat-widget-launcher", N.setAttribute("aria-label", `Open ${i}`), v(N, {
|
|
710
710
|
position: "fixed",
|
|
711
711
|
bottom: "20px",
|
|
712
|
-
[
|
|
712
|
+
[xe]: "20px",
|
|
713
713
|
width: "56px",
|
|
714
714
|
height: "56px",
|
|
715
715
|
borderRadius: "50%",
|
|
716
716
|
border: "none",
|
|
717
|
-
backgroundColor:
|
|
718
|
-
color:
|
|
717
|
+
backgroundColor: Re,
|
|
718
|
+
color: ke,
|
|
719
719
|
cursor: "pointer",
|
|
720
720
|
display: "flex",
|
|
721
721
|
alignItems: "center",
|
|
722
722
|
justifyContent: "center",
|
|
723
723
|
zIndex: "2147483000",
|
|
724
724
|
boxShadow: "rgba(15, 15, 15, 0.2) 0px 4px 14px 0px",
|
|
725
|
-
fontFamily:
|
|
726
|
-
}),
|
|
725
|
+
fontFamily: Ee
|
|
726
|
+
}), f) {
|
|
727
727
|
const e = document.createElement("img");
|
|
728
|
-
e.src =
|
|
728
|
+
e.src = f, e.alt = "", v(e, {
|
|
729
729
|
width: "26px",
|
|
730
730
|
height: "26px",
|
|
731
731
|
objectFit: "contain"
|
|
732
|
-
}),
|
|
733
|
-
} else
|
|
734
|
-
|
|
732
|
+
}), N.appendChild(e);
|
|
733
|
+
} else N.appendChild(un());
|
|
734
|
+
N.addEventListener("click", () => Ne());
|
|
735
735
|
}
|
|
736
|
-
const
|
|
737
|
-
let K = !1,
|
|
738
|
-
const
|
|
736
|
+
const de = se ? `ago-vt-${++gn}` : "", Ge = 52;
|
|
737
|
+
let K = !1, ce = 0, re = 0, H, pe, X;
|
|
738
|
+
const be = {
|
|
739
739
|
height: d.style.height,
|
|
740
740
|
border: d.style.border,
|
|
741
741
|
borderRadius: d.style.borderRadius,
|
|
742
742
|
boxShadow: d.style.boxShadow
|
|
743
743
|
};
|
|
744
|
-
|
|
745
|
-
K || !
|
|
746
|
-
}, !0), d.addEventListener("focusin", () => {
|
|
747
|
-
|
|
748
|
-
})), document.addEventListener("keydown",
|
|
749
|
-
const
|
|
750
|
-
|
|
744
|
+
Pe.appendChild(he), N && Pe.appendChild(N), ve(), se && (H = Ft(), d.insertBefore(H, d.firstChild), pe = document.createElement("style"), pe.id = de, pe.textContent = `::view-transition-group(${de}),::view-transition-group(${de}-bar){animation-duration:0.3s;animation-timing-function:cubic-bezier(0.4,0,0.2,1)}`, document.head.appendChild(pe), St === "focus" && (d.addEventListener("pointerdown", (e) => {
|
|
745
|
+
K || !z?.matches || _e.contains(e.target) && (e.preventDefault(), we());
|
|
746
|
+
}, !0), d.addEventListener("focusin", (e) => {
|
|
747
|
+
z?.matches && _e.contains(e.target) && we();
|
|
748
|
+
})), document.addEventListener("keydown", et)), z && z.addEventListener("change", tt);
|
|
749
|
+
const _t = y !== !1, It = y === !1 ? void 0 : y ?? ((e) => {
|
|
750
|
+
$e(e);
|
|
751
751
|
});
|
|
752
|
-
function
|
|
753
|
-
if (
|
|
754
|
-
if (
|
|
755
|
-
const
|
|
752
|
+
function $() {
|
|
753
|
+
if (I.replaceChildren(), u.length === 0) {
|
|
754
|
+
if (Fe === "static") {
|
|
755
|
+
const t = h({
|
|
756
756
|
textAlign: "center",
|
|
757
|
-
color:
|
|
757
|
+
color: gt,
|
|
758
758
|
padding: "24px 16px",
|
|
759
759
|
fontSize: "16px",
|
|
760
760
|
lineHeight: "1.5"
|
|
761
761
|
});
|
|
762
|
-
|
|
762
|
+
t.appendChild(De(ze)), I.appendChild(t);
|
|
763
763
|
}
|
|
764
|
-
} else
|
|
765
|
-
const S =
|
|
766
|
-
|
|
767
|
-
isLast:
|
|
764
|
+
} else u.forEach((t, l) => {
|
|
765
|
+
const S = l === u.length - 1 || u[l + 1].role !== t.role;
|
|
766
|
+
I.appendChild(cn(t, {
|
|
767
|
+
isLast: l === u.length - 1,
|
|
768
768
|
isLastOfBlock: S,
|
|
769
|
-
bubbleStyle:
|
|
770
|
-
showAgentName:
|
|
771
|
-
agentBubble:
|
|
772
|
-
followUpEnabled:
|
|
773
|
-
followUpHandler:
|
|
769
|
+
bubbleStyle: _,
|
|
770
|
+
showAgentName: A,
|
|
771
|
+
agentBubble: R,
|
|
772
|
+
followUpEnabled: _t,
|
|
773
|
+
followUpHandler: It,
|
|
774
|
+
isMobile: !!z?.matches
|
|
774
775
|
}));
|
|
775
776
|
});
|
|
776
|
-
for (const
|
|
777
|
-
if (
|
|
778
|
-
const
|
|
777
|
+
for (const t of We) I.appendChild(pn(t));
|
|
778
|
+
if (le) {
|
|
779
|
+
const t = h({
|
|
779
780
|
padding: "10px 14px",
|
|
780
781
|
backgroundColor: "#fef2f2",
|
|
781
782
|
color: "#dc2626",
|
|
@@ -784,37 +785,37 @@ function mn(t, o) {
|
|
|
784
785
|
fontSize: "13px",
|
|
785
786
|
border: "1px solid #fecaca"
|
|
786
787
|
});
|
|
787
|
-
|
|
788
|
+
t.setAttribute("role", "alert"), t.textContent = le, I.appendChild(t);
|
|
788
789
|
}
|
|
789
|
-
|
|
790
|
-
const e =
|
|
791
|
-
|
|
790
|
+
I.scrollTop = I.scrollHeight;
|
|
791
|
+
const e = u[u.length - 1];
|
|
792
|
+
At(Z && e?.role === "assistant" && e.status === "IN_PROGRESS");
|
|
792
793
|
}
|
|
793
|
-
function
|
|
794
|
-
for (let e =
|
|
795
|
-
const
|
|
796
|
-
if (
|
|
794
|
+
function $t() {
|
|
795
|
+
for (let e = u.length - 1; e >= 0; e--) {
|
|
796
|
+
const t = u[e];
|
|
797
|
+
if (t.role === "assistant" && t.status === "IN_PROGRESS") return t;
|
|
797
798
|
}
|
|
798
799
|
}
|
|
799
|
-
const
|
|
800
|
+
const Ve = (e) => {
|
|
800
801
|
P || (P = e.conversationId);
|
|
801
|
-
}, Ue = (e) => {
|
|
802
|
-
const n = Rt();
|
|
803
|
-
n && (n.content += e.content, N());
|
|
804
|
-
}, Ge = (e) => {
|
|
805
|
-
const n = p.findIndex((c) => c.id === e.id || c.role === "assistant" && c.status === "IN_PROGRESS");
|
|
806
|
-
n >= 0 ? p[n] = e : p.push(e), N(), fe();
|
|
807
802
|
}, je = (e) => {
|
|
808
|
-
const
|
|
809
|
-
|
|
803
|
+
const t = $t();
|
|
804
|
+
t && (t.content += e.content, $());
|
|
805
|
+
}, qe = (e) => {
|
|
806
|
+
const t = u.findIndex((l) => l.id === e.id || l.role === "assistant" && l.status === "IN_PROGRESS");
|
|
807
|
+
t >= 0 ? u[t] = e : u.push(e), $(), ge();
|
|
808
|
+
}, Ke = (e) => {
|
|
809
|
+
const t = u.findIndex((l) => l.id === e.id || l.role === "assistant" && l.status === "IN_PROGRESS");
|
|
810
|
+
t >= 0 ? u[t] = e : u.push(e), Z = !1, $(), e.status === "DONE" && k?.({
|
|
810
811
|
id: e.id,
|
|
811
812
|
content: e.content
|
|
812
813
|
});
|
|
813
|
-
},
|
|
814
|
-
|
|
814
|
+
}, Xe = (e) => {
|
|
815
|
+
le = e.error, Z = !1, u = u.filter((t) => !t.id.startsWith("temp-")), $();
|
|
815
816
|
};
|
|
816
|
-
function
|
|
817
|
-
const
|
|
817
|
+
function Lt(e) {
|
|
818
|
+
const t = {
|
|
818
819
|
id: `ago-intro-${Date.now()}`,
|
|
819
820
|
conversationId: "",
|
|
820
821
|
content: "",
|
|
@@ -822,226 +823,238 @@ function mn(t, o) {
|
|
|
822
823
|
status: "IN_PROGRESS",
|
|
823
824
|
createdAt: /* @__PURE__ */ new Date()
|
|
824
825
|
};
|
|
825
|
-
|
|
826
|
-
const
|
|
826
|
+
u.push(t), $();
|
|
827
|
+
const l = e.match(/\S+\s*/g) ?? [e];
|
|
827
828
|
let S = 0;
|
|
828
|
-
|
|
829
|
-
if (S >=
|
|
830
|
-
clearInterval(
|
|
829
|
+
q = setInterval(() => {
|
|
830
|
+
if (S >= l.length) {
|
|
831
|
+
clearInterval(q), q = void 0, t.status = "DONE", He && (t.followUpReplies = He), $();
|
|
831
832
|
return;
|
|
832
833
|
}
|
|
833
|
-
|
|
834
|
-
},
|
|
834
|
+
t.content += l[S], S++, $();
|
|
835
|
+
}, wt);
|
|
835
836
|
}
|
|
836
|
-
E.on("message:start",
|
|
837
|
-
const
|
|
838
|
-
|
|
839
|
-
const
|
|
840
|
-
let
|
|
841
|
-
const
|
|
842
|
-
if (
|
|
843
|
-
|
|
844
|
-
let
|
|
845
|
-
const
|
|
846
|
-
S.submitted && !
|
|
837
|
+
E.on("message:start", Ve), E.on("message:chunk", je), E.on("message:answer-complete", qe), E.on("message:complete", Ke), E.on("message:error", Xe);
|
|
838
|
+
const Qe = (e) => G?.(e), Ye = (e) => V?.(e);
|
|
839
|
+
G && E.on("form:submitted", Qe), V && E.on("form:error", Ye);
|
|
840
|
+
const Ie = [];
|
|
841
|
+
let Ze = !1;
|
|
842
|
+
const Je = (e) => {
|
|
843
|
+
if (Ze) return;
|
|
844
|
+
Ie.push(e.install(E));
|
|
845
|
+
let t = e.store.get().submitted;
|
|
846
|
+
const l = e.store.subscribe((S) => {
|
|
847
|
+
S.submitted && !t && (We.push(kt(S.submitResult)), $()), t = S.submitted;
|
|
847
848
|
});
|
|
848
|
-
|
|
849
|
+
Ie.push(l);
|
|
849
850
|
};
|
|
850
|
-
for (const e of
|
|
851
|
+
for (const e of s ?? []) e.schema != null ? Je(Xt(e)) : Kt(E, e).then((t) => Je(t)).catch(() => {
|
|
851
852
|
});
|
|
852
|
-
async function
|
|
853
|
-
const
|
|
854
|
-
if (!
|
|
855
|
-
if (
|
|
856
|
-
clearInterval(
|
|
857
|
-
const w =
|
|
858
|
-
w && !w.content ?
|
|
853
|
+
async function $e(e, t) {
|
|
854
|
+
const l = e.trim();
|
|
855
|
+
if (!l && !t?.length || Z) return;
|
|
856
|
+
if (T?.(l), Z = !0, le = null, q) {
|
|
857
|
+
clearInterval(q), q = void 0;
|
|
858
|
+
const w = u.find((W) => W.id.startsWith("ago-intro-"));
|
|
859
|
+
w && !w.content ? u = u.filter((W) => W !== w) : w && (w.status = "DONE");
|
|
859
860
|
}
|
|
860
861
|
const S = Date.now();
|
|
861
|
-
|
|
862
|
+
u.push({
|
|
862
863
|
id: `temp-user-${S}`,
|
|
863
864
|
conversationId: P || "",
|
|
864
|
-
content:
|
|
865
|
+
content: l,
|
|
865
866
|
role: "user",
|
|
866
867
|
status: "DONE",
|
|
867
|
-
attachments:
|
|
868
|
+
attachments: t && t.length > 0 ? Wt(t) : void 0,
|
|
868
869
|
createdAt: /* @__PURE__ */ new Date()
|
|
869
|
-
}),
|
|
870
|
+
}), u.push({
|
|
870
871
|
id: `temp-assistant-${S}`,
|
|
871
872
|
conversationId: P || "",
|
|
872
873
|
content: "",
|
|
873
874
|
role: "assistant",
|
|
874
875
|
status: "IN_PROGRESS",
|
|
875
876
|
createdAt: /* @__PURE__ */ new Date()
|
|
876
|
-
}),
|
|
877
|
+
}), $();
|
|
877
878
|
try {
|
|
878
|
-
const w = await E.sendMessage(
|
|
879
|
+
const w = await E.sendMessage(l, {
|
|
879
880
|
conversationId: P,
|
|
880
|
-
files:
|
|
881
|
+
files: t
|
|
881
882
|
});
|
|
882
|
-
w.conversationId && (P || (P = w.conversationId),
|
|
883
|
-
const
|
|
884
|
-
if (
|
|
885
|
-
const
|
|
886
|
-
|
|
883
|
+
w.conversationId && (P || (P = w.conversationId), ue?.setActiveThread(w.conversationId, w.createdAt));
|
|
884
|
+
const W = u.find((Q) => Q.id === `temp-user-${S}`);
|
|
885
|
+
if (W && (W.id = `user-${S}`, W.conversationId = w.conversationId), !u.some((Q) => Q.id === w.id)) {
|
|
886
|
+
const Q = u.findIndex((Pt) => Pt.id === `temp-assistant-${S}`);
|
|
887
|
+
Q >= 0 ? u[Q] = w : u.push(w);
|
|
887
888
|
}
|
|
888
|
-
|
|
889
|
+
u = u.filter((Q) => !Q.id.startsWith("temp-")), Z = !1, $(), g && Le();
|
|
889
890
|
} catch (w) {
|
|
890
|
-
|
|
891
|
+
le = w instanceof Error ? w.message : "Failed to send message", Z = !1, u = u.filter((W) => !W.id.startsWith("temp-")), $();
|
|
891
892
|
}
|
|
892
893
|
}
|
|
893
|
-
async function
|
|
894
|
+
async function Le() {
|
|
894
895
|
try {
|
|
895
896
|
const e = await E.getConversations();
|
|
896
|
-
|
|
897
|
+
me.splice(0, me.length, ...e);
|
|
897
898
|
} catch {
|
|
898
899
|
}
|
|
899
|
-
return
|
|
900
|
+
return me;
|
|
900
901
|
}
|
|
901
|
-
async function
|
|
902
|
+
async function Nt(e) {
|
|
902
903
|
try {
|
|
903
|
-
const
|
|
904
|
-
|
|
904
|
+
const t = (await E.getConversation(e))?.messages ?? [];
|
|
905
|
+
t.length > 0 && u.length === 0 && (u = t, $());
|
|
905
906
|
} catch {
|
|
906
|
-
|
|
907
|
+
u.length === 0 && (ue?.clear(), P = void 0);
|
|
907
908
|
}
|
|
908
909
|
}
|
|
909
|
-
return
|
|
910
|
+
return $(), se && z?.matches || ge(), P ? Nt(P) : Fe === "streaming" && Lt(ze), g && Le(), {
|
|
910
911
|
client: E,
|
|
911
|
-
element:
|
|
912
|
-
sendMessage:
|
|
913
|
-
...
|
|
914
|
-
open:
|
|
915
|
-
close:
|
|
916
|
-
toggle:
|
|
912
|
+
element: he,
|
|
913
|
+
sendMessage: $e,
|
|
914
|
+
...D || se ? {
|
|
915
|
+
open: Bt,
|
|
916
|
+
close: Mt,
|
|
917
|
+
toggle: Ot
|
|
917
918
|
} : {},
|
|
918
|
-
session:
|
|
919
|
-
threads:
|
|
920
|
-
refreshThreads:
|
|
919
|
+
session: ue,
|
|
920
|
+
threads: me,
|
|
921
|
+
refreshThreads: Le,
|
|
921
922
|
destroy() {
|
|
922
|
-
|
|
923
|
+
q && clearInterval(q), E.off("message:start", Ve), E.off("message:chunk", je), E.off("message:answer-complete", qe), E.off("message:complete", Ke), E.off("message:error", Xe), G && E.off("form:submitted", Qe), V && E.off("form:error", Ye), Ze = !0, Ie.forEach((e) => e()), he.remove(), N?.remove(), H?.remove(), pe?.remove(), X?.remove(), z?.removeEventListener("change", tt), se && (document.removeEventListener("keydown", et), rt(), document.documentElement.style.removeProperty("overflow")), o.client || E.destroy();
|
|
923
924
|
}
|
|
924
925
|
};
|
|
925
|
-
function
|
|
926
|
-
if (!
|
|
926
|
+
function ve() {
|
|
927
|
+
if (!U) return;
|
|
927
928
|
{
|
|
928
|
-
const
|
|
929
|
-
|
|
929
|
+
const t = xe === "left" ? "border-right" : "border-left";
|
|
930
|
+
z?.matches ? (U.style.width = "100%", d.style.borderRadius = "0", d.style.removeProperty(t)) : (U.style.width = typeof x == "number" ? `${x}px` : x, d.style.setProperty(t, `1px solid ${L}`));
|
|
930
931
|
}
|
|
931
|
-
const e =
|
|
932
|
-
|
|
932
|
+
const e = m === "left" ? "translateX(-100%)" : "translateX(100%)";
|
|
933
|
+
U.style.transform = oe ? "translateX(0)" : e, U.setAttribute("aria-hidden", oe ? "false" : "true"), N && (N.style.display = oe ? "none" : "flex");
|
|
933
934
|
}
|
|
934
|
-
function
|
|
935
|
-
|
|
935
|
+
function Ne() {
|
|
936
|
+
oe = !0, ve(), ge(), B?.();
|
|
936
937
|
}
|
|
937
|
-
function
|
|
938
|
-
|
|
938
|
+
function Te() {
|
|
939
|
+
oe = !1, ve(), j?.();
|
|
939
940
|
}
|
|
940
|
-
function
|
|
941
|
-
|
|
941
|
+
function Tt() {
|
|
942
|
+
oe ? Te() : Ne();
|
|
942
943
|
}
|
|
943
|
-
function
|
|
944
|
-
|
|
944
|
+
function Bt() {
|
|
945
|
+
D ? Ne() : we();
|
|
945
946
|
}
|
|
946
|
-
function
|
|
947
|
-
|
|
947
|
+
function Mt() {
|
|
948
|
+
D ? Te() : fe();
|
|
948
949
|
}
|
|
949
|
-
function
|
|
950
|
-
|
|
950
|
+
function Ot() {
|
|
951
|
+
D ? Tt() : K ? fe() : we();
|
|
951
952
|
}
|
|
952
|
-
function
|
|
953
|
+
function Dt() {
|
|
953
954
|
return Array.from(d.querySelectorAll('a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])')).filter((e) => e.getClientRects().length > 0);
|
|
954
955
|
}
|
|
955
|
-
function
|
|
956
|
+
function et(e) {
|
|
956
957
|
if (!K) return;
|
|
957
958
|
if (e.key === "Escape") {
|
|
958
|
-
|
|
959
|
+
fe();
|
|
959
960
|
return;
|
|
960
961
|
}
|
|
961
962
|
if (e.key !== "Tab") return;
|
|
962
|
-
const
|
|
963
|
-
if (
|
|
963
|
+
const t = Dt();
|
|
964
|
+
if (t.length === 0) {
|
|
964
965
|
e.preventDefault();
|
|
965
966
|
return;
|
|
966
967
|
}
|
|
967
|
-
const
|
|
968
|
-
e.shiftKey && (w ===
|
|
968
|
+
const l = t[0], S = t[t.length - 1], w = document.activeElement;
|
|
969
|
+
e.shiftKey && (w === l || !d.contains(w)) ? (e.preventDefault(), S.focus()) : !e.shiftKey && (w === S || !d.contains(w)) && (e.preventDefault(), l.focus());
|
|
969
970
|
}
|
|
970
|
-
function
|
|
971
|
-
|
|
971
|
+
function tt(e) {
|
|
972
|
+
D ? ve() : !e.matches && K && fe(), $();
|
|
972
973
|
}
|
|
973
|
-
function
|
|
974
|
+
function nt() {
|
|
974
975
|
return window.visualViewport?.height ?? window.innerHeight;
|
|
975
976
|
}
|
|
976
|
-
function
|
|
977
|
-
|
|
977
|
+
function ot() {
|
|
978
|
+
const e = window.visualViewport, t = e?.offsetTop ?? 0, l = e?.height ?? ce, S = Math.min(0, t + l - ce);
|
|
979
|
+
d.style.top = `${S}px`, H && (H.style.top = `${t}px`);
|
|
978
980
|
}
|
|
979
|
-
function
|
|
980
|
-
|
|
981
|
+
function ye() {
|
|
982
|
+
re || (re = requestAnimationFrame(() => {
|
|
983
|
+
re = 0, ot();
|
|
984
|
+
}));
|
|
981
985
|
}
|
|
982
|
-
function
|
|
983
|
-
|
|
986
|
+
function zt() {
|
|
987
|
+
window.visualViewport?.addEventListener("resize", ye), window.visualViewport?.addEventListener("scroll", ye);
|
|
988
|
+
}
|
|
989
|
+
function rt() {
|
|
990
|
+
window.visualViewport?.removeEventListener("resize", ye), window.visualViewport?.removeEventListener("scroll", ye), re && (cancelAnimationFrame(re), re = 0);
|
|
991
|
+
}
|
|
992
|
+
function it() {
|
|
993
|
+
I.scrollTop = I.scrollHeight;
|
|
994
|
+
}
|
|
995
|
+
function Ft() {
|
|
996
|
+
const e = h({
|
|
984
997
|
position: "fixed",
|
|
985
998
|
top: "0",
|
|
986
999
|
left: "0",
|
|
987
1000
|
right: "0",
|
|
988
|
-
height: `calc(${
|
|
1001
|
+
height: `calc(${Ge}px + env(safe-area-inset-top))`,
|
|
989
1002
|
display: "none",
|
|
990
1003
|
alignItems: "center",
|
|
991
1004
|
justifyContent: "space-between",
|
|
992
1005
|
padding: "env(safe-area-inset-top) 14px 0",
|
|
993
|
-
backgroundColor:
|
|
994
|
-
borderBottom: `1px solid ${
|
|
1006
|
+
backgroundColor: ee,
|
|
1007
|
+
borderBottom: `1px solid ${L}`,
|
|
995
1008
|
zIndex: "2147483001",
|
|
996
|
-
fontFamily:
|
|
1009
|
+
fontFamily: Ee
|
|
997
1010
|
});
|
|
998
|
-
if (e.className = "ago-chat-widget-mobile-bar",
|
|
999
|
-
const
|
|
1000
|
-
|
|
1011
|
+
if (e.className = "ago-chat-widget-mobile-bar", f) {
|
|
1012
|
+
const l = document.createElement("img");
|
|
1013
|
+
l.src = f, l.alt = "", v(l, {
|
|
1001
1014
|
height: "28px",
|
|
1002
1015
|
width: "auto"
|
|
1003
|
-
}), e.appendChild(
|
|
1016
|
+
}), e.appendChild(l);
|
|
1004
1017
|
} else if (i) {
|
|
1005
|
-
const
|
|
1006
|
-
|
|
1018
|
+
const l = document.createElement("span");
|
|
1019
|
+
l.textContent = i, v(l, {
|
|
1007
1020
|
fontSize: "15px",
|
|
1008
1021
|
fontWeight: "600",
|
|
1009
|
-
color:
|
|
1022
|
+
color: J,
|
|
1010
1023
|
overflow: "hidden",
|
|
1011
1024
|
whiteSpace: "nowrap",
|
|
1012
1025
|
textOverflow: "ellipsis"
|
|
1013
|
-
}), e.appendChild(
|
|
1014
|
-
} else e.appendChild(
|
|
1015
|
-
const
|
|
1016
|
-
return
|
|
1026
|
+
}), e.appendChild(l);
|
|
1027
|
+
} else e.appendChild(h({}));
|
|
1028
|
+
const t = document.createElement("button");
|
|
1029
|
+
return t.type = "button", t.setAttribute("aria-label", "Close"), t.textContent = "×", v(t, {
|
|
1017
1030
|
border: "none",
|
|
1018
1031
|
background: "transparent",
|
|
1019
1032
|
fontSize: "26px",
|
|
1020
1033
|
lineHeight: "1",
|
|
1021
|
-
color:
|
|
1034
|
+
color: J,
|
|
1022
1035
|
cursor: "pointer",
|
|
1023
1036
|
padding: "4px 8px"
|
|
1024
|
-
}),
|
|
1025
|
-
|
|
1026
|
-
}), e.appendChild(
|
|
1037
|
+
}), t.addEventListener("click", () => {
|
|
1038
|
+
fe();
|
|
1039
|
+
}), e.appendChild(t), e;
|
|
1027
1040
|
}
|
|
1028
|
-
function
|
|
1029
|
-
return typeof document.startViewTransition == "function" && !
|
|
1041
|
+
function Ht() {
|
|
1042
|
+
return typeof document.startViewTransition == "function" && !Rt?.matches && !!z?.matches;
|
|
1030
1043
|
}
|
|
1031
|
-
function
|
|
1032
|
-
const
|
|
1033
|
-
if (
|
|
1034
|
-
d.style.setProperty("view-transition-name",
|
|
1035
|
-
const
|
|
1036
|
-
d.style.removeProperty("view-transition-name"),
|
|
1044
|
+
function at(e) {
|
|
1045
|
+
const t = document;
|
|
1046
|
+
if (Ht() && t.startViewTransition) {
|
|
1047
|
+
d.style.setProperty("view-transition-name", de), H?.style.setProperty("view-transition-name", `${de}-bar`);
|
|
1048
|
+
const l = () => {
|
|
1049
|
+
d.style.removeProperty("view-transition-name"), H?.style.removeProperty("view-transition-name");
|
|
1037
1050
|
};
|
|
1038
|
-
return
|
|
1051
|
+
return t.startViewTransition(e).finished.then(l, l);
|
|
1039
1052
|
}
|
|
1040
1053
|
return e(), Promise.resolve();
|
|
1041
1054
|
}
|
|
1042
|
-
function
|
|
1055
|
+
function st(e) {
|
|
1043
1056
|
if (e)
|
|
1044
|
-
X && d.parentElement?.insertBefore(X, d),
|
|
1057
|
+
X && d.parentElement?.insertBefore(X, d), v(d, {
|
|
1045
1058
|
position: "fixed",
|
|
1046
1059
|
top: "0",
|
|
1047
1060
|
left: "0",
|
|
@@ -1052,12 +1065,12 @@ function mn(t, o) {
|
|
|
1052
1065
|
border: "none",
|
|
1053
1066
|
borderRadius: "0",
|
|
1054
1067
|
boxShadow: "none",
|
|
1055
|
-
paddingTop: `calc(${
|
|
1068
|
+
paddingTop: `calc(${Ge}px + env(safe-area-inset-top))`,
|
|
1056
1069
|
paddingBottom: "env(safe-area-inset-bottom)"
|
|
1057
|
-
}), d.setAttribute("role", "dialog"), d.setAttribute("aria-modal", "true"), d.setAttribute("aria-label", i), document.documentElement.style.overflow = "hidden",
|
|
1070
|
+
}), d.setAttribute("role", "dialog"), d.setAttribute("aria-modal", "true"), d.setAttribute("aria-label", i), document.documentElement.style.overflow = "hidden", F && (F.style.display = "none"), H && (H.style.display = "flex");
|
|
1058
1071
|
else {
|
|
1059
1072
|
X?.remove(), X = void 0;
|
|
1060
|
-
for (const
|
|
1073
|
+
for (const t of [
|
|
1061
1074
|
"position",
|
|
1062
1075
|
"top",
|
|
1063
1076
|
"left",
|
|
@@ -1066,31 +1079,31 @@ function mn(t, o) {
|
|
|
1066
1079
|
"z-index",
|
|
1067
1080
|
"padding-top",
|
|
1068
1081
|
"padding-bottom"
|
|
1069
|
-
]) d.style.removeProperty(
|
|
1070
|
-
d.style.height =
|
|
1082
|
+
]) d.style.removeProperty(t);
|
|
1083
|
+
d.style.height = be.height, d.style.border = be.border, d.style.borderRadius = be.borderRadius, d.style.boxShadow = be.boxShadow, d.removeAttribute("role"), d.removeAttribute("aria-modal"), d.removeAttribute("aria-label"), document.documentElement.style.removeProperty("overflow"), F && (F.style.display = "flex"), H && (H.style.display = "none");
|
|
1071
1084
|
}
|
|
1072
1085
|
}
|
|
1073
|
-
function
|
|
1074
|
-
if (K || !
|
|
1086
|
+
function we() {
|
|
1087
|
+
if (K || !z?.matches) return Promise.resolve();
|
|
1075
1088
|
const e = d.getBoundingClientRect();
|
|
1076
|
-
if (e.height >=
|
|
1077
|
-
K = !0, X =
|
|
1089
|
+
if (e.height >= nt() * 0.8) return Promise.resolve();
|
|
1090
|
+
K = !0, X = h({
|
|
1078
1091
|
width: `${e.width}px`,
|
|
1079
1092
|
height: `${e.height}px`
|
|
1080
|
-
}), X.className = "ago-chat-widget-spacer", X.setAttribute("aria-hidden", "true"),
|
|
1081
|
-
const
|
|
1082
|
-
return
|
|
1083
|
-
|
|
1084
|
-
}),
|
|
1093
|
+
}), X.className = "ago-chat-widget-spacer", X.setAttribute("aria-hidden", "true"), ce = nt(), d.style.setProperty("--ago-vh", `${ce}px`), ot(), zt();
|
|
1094
|
+
const t = at(() => st(!0));
|
|
1095
|
+
return t.then(() => {
|
|
1096
|
+
it(), ge();
|
|
1097
|
+
}), it(), B?.(), t;
|
|
1085
1098
|
}
|
|
1086
|
-
function
|
|
1099
|
+
function fe() {
|
|
1087
1100
|
if (!K) return Promise.resolve();
|
|
1088
|
-
K = !1,
|
|
1089
|
-
const e =
|
|
1090
|
-
return e.then(() => d.style.removeProperty("--ago-vh")),
|
|
1101
|
+
K = !1, rt(), d.querySelector("textarea")?.blur();
|
|
1102
|
+
const e = at(() => st(!1));
|
|
1103
|
+
return e.then(() => d.style.removeProperty("--ago-vh")), ce = 0, j?.(), e;
|
|
1091
1104
|
}
|
|
1092
1105
|
}
|
|
1093
1106
|
export {
|
|
1094
|
-
|
|
1095
|
-
|
|
1107
|
+
yn as mountChatWidget,
|
|
1108
|
+
De as renderMarkdown
|
|
1096
1109
|
};
|