@useago/sdk 0.4.4 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{createConversationSession-XkiOGAUT.js → createConversationSession-D-eq8VIo.js} +1 -1
- package/dist/{createConversationSession-DibXdxoC.cjs → createConversationSession-DGcM_Z3f.cjs} +1 -1
- package/dist/createFormCollector-DON4vdJV.js +244 -0
- package/dist/createFormCollector-IO6bfPQx.cjs +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +49 -4
- package/dist/index.d.ts +49 -4
- package/dist/index.js +2 -2
- package/dist/react.cjs +1 -1
- package/dist/react.d.cts +49 -4
- package/dist/react.d.ts +49 -4
- package/dist/react.js +1 -1
- package/dist/widget.cjs +5 -1
- package/dist/widget.d.cts +75 -6
- package/dist/widget.d.ts +75 -6
- package/dist/widget.js +417 -234
- package/package.json +1 -1
- package/dist/createFormCollector-D4-yZh1i.js +0 -207
- package/dist/createFormCollector-DLwgDX24.cjs +0 -1
package/dist/widget.js
CHANGED
|
@@ -1,7 +1,190 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import { t as
|
|
3
|
-
import { t as
|
|
4
|
-
var
|
|
1
|
+
import { t as ke } from "./AgoClient-rvTz2thR.js";
|
|
2
|
+
import { t as $e } from "./createFormCollector-DON4vdJV.js";
|
|
3
|
+
import { t as Ie } from "./createConversationSession-D-eq8VIo.js";
|
|
4
|
+
var Te = {
|
|
5
|
+
"&": "&",
|
|
6
|
+
"<": "<",
|
|
7
|
+
">": ">",
|
|
8
|
+
'"': """,
|
|
9
|
+
"'": "'"
|
|
10
|
+
};
|
|
11
|
+
function M(o) {
|
|
12
|
+
return o.replace(/[&<>"']/g, (n) => Te[n]);
|
|
13
|
+
}
|
|
14
|
+
function se(o) {
|
|
15
|
+
const n = o.trim();
|
|
16
|
+
return /^(https?:|mailto:|tel:|#|\/|\.\/|\.\.\/)/i.test(n) || !/^[a-z][a-z0-9+.-]*:/i.test(n) ? n : null;
|
|
17
|
+
}
|
|
18
|
+
var ce = '"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace', G = "";
|
|
19
|
+
function N(o) {
|
|
20
|
+
const n = [], r = (g) => (n.push(g), `${G}${n.length - 1}${G}`);
|
|
21
|
+
let e = o;
|
|
22
|
+
return e = e.replace(/`([^`]+)`/g, (g, a) => r(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${ce}">${M(a)}</code>`)), e = e.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g, (g, a, d) => {
|
|
23
|
+
const s = se(d);
|
|
24
|
+
return s ? r(`<img alt="${M(a)}" src="${M(s)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`) : g;
|
|
25
|
+
}), e = e.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (g, a, d) => {
|
|
26
|
+
const s = se(d);
|
|
27
|
+
return s ? r(`<a href="${M(s)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${N(a)}</a>`) : g;
|
|
28
|
+
}), e = M(e), e = e.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>"), e = e.replace(new RegExp(`${G}(\\d+)${G}`, "g"), (g, a) => n[Number(a)]), e;
|
|
29
|
+
}
|
|
30
|
+
function y(o, n, r) {
|
|
31
|
+
const e = document.createElement(o);
|
|
32
|
+
return Object.assign(e.style, n), r !== void 0 && (e.innerHTML = r), e;
|
|
33
|
+
}
|
|
34
|
+
var pe = /^ {0,3}([-*_])( *\1){2,} *$/, fe = /^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/, ge = /^ {0,3}(```+|~~~+)/, X = /^ {0,3}>\s?/, H = /^(\s*)([-*+]|\d+[.)])\s+(.*)$/, Le = [
|
|
35
|
+
"20px",
|
|
36
|
+
"18px",
|
|
37
|
+
"16px",
|
|
38
|
+
"15px",
|
|
39
|
+
"14px",
|
|
40
|
+
"13px"
|
|
41
|
+
], Z = (o) => o.match(/^\s*/)?.[0].length ?? 0;
|
|
42
|
+
function Ae(o) {
|
|
43
|
+
return o.trim() === "" || pe.test(o) || fe.test(o) || ge.test(o) || X.test(o) || H.test(o);
|
|
44
|
+
}
|
|
45
|
+
function ue(o) {
|
|
46
|
+
const n = o[0].match(H), r = n[1].length, e = /\d/.test(n[2]), g = y(e ? "ol" : "ul", {
|
|
47
|
+
margin: "0 0 8px 0",
|
|
48
|
+
paddingLeft: "20px",
|
|
49
|
+
listStyleType: e ? "decimal" : "disc",
|
|
50
|
+
listStylePosition: "outside"
|
|
51
|
+
});
|
|
52
|
+
let a = 0;
|
|
53
|
+
for (; a < o.length; ) {
|
|
54
|
+
const d = o[a].match(H), s = [];
|
|
55
|
+
for (a++; a < o.length && Z(o[a]) > r; )
|
|
56
|
+
s.push(o[a]), a++;
|
|
57
|
+
const c = y("li", {
|
|
58
|
+
display: "list-item",
|
|
59
|
+
margin: "2px 0",
|
|
60
|
+
lineHeight: "1.6"
|
|
61
|
+
}), l = d[3].match(/^\[([ xX])\]\s+(.*)$/);
|
|
62
|
+
l ? (c.style.listStyleType = "none", c.style.marginLeft = "-20px", c.innerHTML = `<span style="margin-right:6px">${l[1].toLowerCase() === "x" ? "☑" : "☐"}</span>${N(l[2])}`) : c.innerHTML = N(d[3]), s.filter((h) => H.test(h)).length > 0 && c.appendChild(ue(s.filter((h) => h.trim() !== ""))), g.appendChild(c);
|
|
63
|
+
}
|
|
64
|
+
return g;
|
|
65
|
+
}
|
|
66
|
+
function Ne(o) {
|
|
67
|
+
const n = (s) => s.replace(/^\s*\|?/, "").replace(/\|?\s*$/, "").split("|").map((c) => c.trim()), r = y("div", {
|
|
68
|
+
overflowX: "auto",
|
|
69
|
+
margin: "0 0 8px 0"
|
|
70
|
+
}), e = y("table", {
|
|
71
|
+
borderCollapse: "collapse",
|
|
72
|
+
width: "100%",
|
|
73
|
+
fontSize: "13px"
|
|
74
|
+
}), g = document.createElement("thead"), a = document.createElement("tr");
|
|
75
|
+
for (const s of n(o[0])) a.appendChild(y("th", {
|
|
76
|
+
border: "1px solid #dee3e8",
|
|
77
|
+
padding: "6px 10px",
|
|
78
|
+
textAlign: "left",
|
|
79
|
+
backgroundColor: "#f5f7fa",
|
|
80
|
+
fontWeight: "600"
|
|
81
|
+
}, N(s)));
|
|
82
|
+
g.appendChild(a), e.appendChild(g);
|
|
83
|
+
const d = document.createElement("tbody");
|
|
84
|
+
for (const s of o.slice(2)) {
|
|
85
|
+
const c = document.createElement("tr");
|
|
86
|
+
for (const l of n(s)) c.appendChild(y("td", {
|
|
87
|
+
border: "1px solid #dee3e8",
|
|
88
|
+
padding: "6px 10px"
|
|
89
|
+
}, N(l)));
|
|
90
|
+
d.appendChild(c);
|
|
91
|
+
}
|
|
92
|
+
return e.appendChild(d), r.appendChild(e), r;
|
|
93
|
+
}
|
|
94
|
+
var Oe = (o) => !!o && /^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(o);
|
|
95
|
+
function me(o) {
|
|
96
|
+
const n = document.createDocumentFragment(), r = o.replace(/\r\n?/g, `
|
|
97
|
+
`).split(`
|
|
98
|
+
`);
|
|
99
|
+
let e = 0;
|
|
100
|
+
for (; e < r.length; ) {
|
|
101
|
+
const a = r[e];
|
|
102
|
+
if (a.trim() === "") {
|
|
103
|
+
e++;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const d = a.match(ge);
|
|
107
|
+
if (d) {
|
|
108
|
+
const l = d[1][0], h = [];
|
|
109
|
+
for (e++; e < r.length && !new RegExp(`^ {0,3}${l === "`" ? "`{3,}" : "~{3,}"}\\s*$`).test(r[e]); )
|
|
110
|
+
h.push(r[e]), e++;
|
|
111
|
+
e++;
|
|
112
|
+
const T = y("pre", { margin: "0 0 8px 0" });
|
|
113
|
+
T.appendChild(y("code", {
|
|
114
|
+
display: "block",
|
|
115
|
+
background: "#f5f5f5",
|
|
116
|
+
padding: "8px 12px",
|
|
117
|
+
borderRadius: "6px",
|
|
118
|
+
fontSize: "13px",
|
|
119
|
+
overflowX: "auto",
|
|
120
|
+
fontFamily: ce,
|
|
121
|
+
whiteSpace: "pre"
|
|
122
|
+
}, M(h.join(`
|
|
123
|
+
`)))), n.appendChild(T);
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (pe.test(a)) {
|
|
127
|
+
n.appendChild(y("hr", {
|
|
128
|
+
border: "none",
|
|
129
|
+
borderTop: "1px solid #dee3e8",
|
|
130
|
+
margin: "12px 0"
|
|
131
|
+
})), e++;
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
const s = a.match(fe);
|
|
135
|
+
if (s) {
|
|
136
|
+
const l = s[1].length;
|
|
137
|
+
n.appendChild(y(`h${l}`, {
|
|
138
|
+
margin: "16px 0 8px 0",
|
|
139
|
+
fontSize: Le[l - 1],
|
|
140
|
+
fontWeight: "600",
|
|
141
|
+
lineHeight: "1.3"
|
|
142
|
+
}, N(s[2]))), e++;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (X.test(a)) {
|
|
146
|
+
const l = [];
|
|
147
|
+
for (; e < r.length && X.test(r[e]); )
|
|
148
|
+
l.push(r[e].replace(X, "")), e++;
|
|
149
|
+
const h = y("blockquote", {
|
|
150
|
+
borderLeft: "4px solid #dee3e8",
|
|
151
|
+
paddingLeft: "12px",
|
|
152
|
+
margin: "0 0 8px 0",
|
|
153
|
+
fontStyle: "italic",
|
|
154
|
+
color: "#6b6d6f"
|
|
155
|
+
});
|
|
156
|
+
h.appendChild(me(l.join(`
|
|
157
|
+
`))), n.appendChild(h);
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (a.includes("|") && Oe(r[e + 1])) {
|
|
161
|
+
const l = [a, r[e + 1]];
|
|
162
|
+
for (e += 2; e < r.length && r[e].includes("|") && r[e].trim(); )
|
|
163
|
+
l.push(r[e]), e++;
|
|
164
|
+
n.appendChild(Ne(l));
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
if (H.test(a)) {
|
|
168
|
+
const l = [], h = Z(a);
|
|
169
|
+
for (; e < r.length && r[e].trim() !== ""; )
|
|
170
|
+
if (H.test(r[e]) || Z(r[e]) > h)
|
|
171
|
+
l.push(r[e]), e++;
|
|
172
|
+
else break;
|
|
173
|
+
n.appendChild(ue(l));
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
const c = [a];
|
|
177
|
+
for (e++; e < r.length && !Ae(r[e]); )
|
|
178
|
+
c.push(r[e]), e++;
|
|
179
|
+
n.appendChild(y("p", {
|
|
180
|
+
margin: "0 0 8px 0",
|
|
181
|
+
lineHeight: "1.6"
|
|
182
|
+
}, c.map((l) => N(l)).join("<br>")));
|
|
183
|
+
}
|
|
184
|
+
const g = n.lastElementChild;
|
|
185
|
+
return g && (g.style.marginBottom = "0"), n;
|
|
186
|
+
}
|
|
187
|
+
var he = 'var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif)', ie = {
|
|
5
188
|
font: "--ago-font",
|
|
6
189
|
radius: "--ago-radius",
|
|
7
190
|
messageRadius: "--ago-message-radius",
|
|
@@ -15,109 +198,109 @@ var oe = 'var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "S
|
|
|
15
198
|
mutedText: "--ago-muted-text-color",
|
|
16
199
|
border: "--ago-border-color",
|
|
17
200
|
accent: "--ago-accent-color"
|
|
18
|
-
},
|
|
19
|
-
function
|
|
20
|
-
if (
|
|
21
|
-
for (const
|
|
22
|
-
const
|
|
23
|
-
|
|
201
|
+
}, xe = "var(--ago-brand-color, #03182f)", be = "var(--ago-brand-text-color, #fff)", De = "var(--ago-header-background, var(--ago-brand-color, #03182f))", Me = "var(--ago-header-text-color, #e8f0fe)", z = "var(--ago-panel-background, #fff)", He = "var(--ago-messages-background, #fbfbfb)", j = "var(--ago-text-color, #30373e)", Be = "var(--ago-muted-text-color, #6b6d6f)", k = "var(--ago-border-color, #dee3e8)", Y = "var(--ago-accent-color, #1b5fc4)", ze = "var(--ago-radius, 16px)", le = "var(--ago-message-radius, 16px)";
|
|
202
|
+
function Ue(o, n) {
|
|
203
|
+
if (n)
|
|
204
|
+
for (const r of Object.keys(ie)) {
|
|
205
|
+
const e = n[r];
|
|
206
|
+
e != null && o.style.setProperty(ie[r], e);
|
|
24
207
|
}
|
|
25
208
|
}
|
|
26
|
-
function
|
|
27
|
-
Object.assign(
|
|
209
|
+
function E(o, n) {
|
|
210
|
+
Object.assign(o.style, n);
|
|
28
211
|
}
|
|
29
|
-
function
|
|
30
|
-
const
|
|
31
|
-
return
|
|
212
|
+
function C(o = {}) {
|
|
213
|
+
const n = document.createElement("div");
|
|
214
|
+
return E(n, o), n;
|
|
32
215
|
}
|
|
33
|
-
var
|
|
34
|
-
function
|
|
35
|
-
if (typeof document > "u" || document.getElementById(
|
|
36
|
-
const
|
|
37
|
-
|
|
216
|
+
var de = "ago-chat-widget-keyframes";
|
|
217
|
+
function Fe() {
|
|
218
|
+
if (typeof document > "u" || document.getElementById(de)) return;
|
|
219
|
+
const o = document.createElement("style");
|
|
220
|
+
o.id = de, o.textContent = "@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }", document.head.appendChild(o);
|
|
38
221
|
}
|
|
39
|
-
function
|
|
40
|
-
const
|
|
41
|
-
if (!
|
|
42
|
-
return
|
|
222
|
+
function We(o) {
|
|
223
|
+
const n = typeof o == "string" ? document.querySelector(o) : o;
|
|
224
|
+
if (!n) throw new Error(`mountChatWidget: target "${String(o)}" not found.`);
|
|
225
|
+
return n;
|
|
43
226
|
}
|
|
44
|
-
function
|
|
45
|
-
const { title:
|
|
46
|
-
if (!
|
|
47
|
-
const
|
|
48
|
-
let
|
|
49
|
-
const
|
|
227
|
+
function Ke(o, n) {
|
|
228
|
+
const { title: r = "Chat", welcomeMessage: e = "Hello! How can I help you today?", placeholder: g = "Type a message...", allowFiles: a = !1, height: d = 500, logoUrl: s, showAgentName: c = !1, theme: l, loadThreads: h = !1, forms: T, onFollowUpClick: m, onMessageSent: R, onMessageReceived: U } = n;
|
|
229
|
+
if (!n.client && !n.config?.baseUrl) throw new Error("mountChatWidget requires either `client` or `config` (with a baseUrl).");
|
|
230
|
+
const x = n.client ?? new ke(n.config), L = We(o), F = n.persistConversation, O = F ? Ie(F === !0 ? {} : F) : void 0;
|
|
231
|
+
let w = n.conversationId ?? O?.getLastActiveThread() ?? void 0, p = [], A = !1, B = null;
|
|
232
|
+
const W = [], D = C({
|
|
50
233
|
display: "flex",
|
|
51
234
|
flexDirection: "column",
|
|
52
|
-
height: typeof
|
|
53
|
-
border: `1px solid ${
|
|
54
|
-
borderRadius:
|
|
235
|
+
height: typeof d == "number" ? `${d}px` : d,
|
|
236
|
+
border: `1px solid ${k}`,
|
|
237
|
+
borderRadius: ze,
|
|
55
238
|
overflow: "hidden",
|
|
56
|
-
backgroundColor:
|
|
57
|
-
fontFamily:
|
|
239
|
+
backgroundColor: z,
|
|
240
|
+
fontFamily: he,
|
|
58
241
|
textAlign: "left",
|
|
59
242
|
boxShadow: "rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"
|
|
60
243
|
});
|
|
61
|
-
|
|
62
|
-
const
|
|
244
|
+
D.className = "ago-chat-widget", Ue(D, l);
|
|
245
|
+
const P = C({
|
|
63
246
|
padding: "14px 16px",
|
|
64
|
-
borderBottom: `1px solid ${
|
|
65
|
-
backgroundColor:
|
|
66
|
-
color:
|
|
247
|
+
borderBottom: `1px solid ${k}`,
|
|
248
|
+
backgroundColor: De,
|
|
249
|
+
color: Me,
|
|
67
250
|
display: "flex",
|
|
68
251
|
alignItems: "center",
|
|
69
252
|
gap: "10px"
|
|
70
253
|
});
|
|
71
|
-
if (
|
|
72
|
-
const
|
|
73
|
-
|
|
254
|
+
if (P.className = "ago-chat-widget__header", s) {
|
|
255
|
+
const t = document.createElement("img");
|
|
256
|
+
t.src = s, t.alt = "Logo", E(t, {
|
|
74
257
|
height: "24px",
|
|
75
258
|
width: "auto"
|
|
76
|
-
}),
|
|
259
|
+
}), P.appendChild(t);
|
|
77
260
|
}
|
|
78
|
-
const
|
|
79
|
-
|
|
261
|
+
const K = document.createElement("h3");
|
|
262
|
+
K.textContent = r, E(K, {
|
|
80
263
|
margin: "0",
|
|
81
264
|
fontSize: "15px",
|
|
82
265
|
fontWeight: "600"
|
|
83
|
-
}),
|
|
84
|
-
const
|
|
266
|
+
}), P.appendChild(K);
|
|
267
|
+
const $ = C({
|
|
85
268
|
flex: "1",
|
|
86
269
|
overflow: "auto",
|
|
87
270
|
padding: "16px",
|
|
88
|
-
backgroundColor:
|
|
271
|
+
backgroundColor: He
|
|
89
272
|
});
|
|
90
|
-
|
|
91
|
-
const { inputRow:
|
|
92
|
-
placeholder:
|
|
93
|
-
allowFiles:
|
|
94
|
-
onSend: (
|
|
95
|
-
|
|
273
|
+
$.className = "ago-chat-widget__messages";
|
|
274
|
+
const { inputRow: Ce, setDisabled: ve, focus: ye } = Pe({
|
|
275
|
+
placeholder: g,
|
|
276
|
+
allowFiles: a,
|
|
277
|
+
onSend: (t, i) => {
|
|
278
|
+
q(t, i);
|
|
96
279
|
}
|
|
97
280
|
});
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
281
|
+
Fe(), D.append(P, $, Ce), L.appendChild(D);
|
|
282
|
+
const J = m !== !1, ee = m === !1 ? void 0 : m ?? ((t) => {
|
|
283
|
+
q(t);
|
|
101
284
|
});
|
|
102
|
-
function
|
|
103
|
-
const
|
|
285
|
+
function Ee(t) {
|
|
286
|
+
const i = t.role === "user", b = C({
|
|
104
287
|
display: "flex",
|
|
105
288
|
flexDirection: "column",
|
|
106
|
-
alignItems:
|
|
289
|
+
alignItems: i ? "flex-end" : "flex-start",
|
|
107
290
|
marginBottom: "16px"
|
|
108
291
|
});
|
|
109
|
-
if (
|
|
110
|
-
const
|
|
292
|
+
if (b.className = `ago-message ago-message--${t.role}`, !i && c && t.agent) {
|
|
293
|
+
const f = C({
|
|
111
294
|
fontSize: "13px",
|
|
112
295
|
fontWeight: "500",
|
|
113
|
-
color:
|
|
296
|
+
color: j,
|
|
114
297
|
marginBottom: "6px",
|
|
115
298
|
padding: "0 4px"
|
|
116
299
|
});
|
|
117
|
-
|
|
300
|
+
f.className = "ago-message__agent", f.textContent = t.agent.displayName || t.agent.name, b.appendChild(f);
|
|
118
301
|
}
|
|
119
|
-
if (!
|
|
120
|
-
const
|
|
302
|
+
if (!i && t.sources && t.sources.length > 0) {
|
|
303
|
+
const f = C({
|
|
121
304
|
display: "grid",
|
|
122
305
|
gridTemplateColumns: "1fr 1fr",
|
|
123
306
|
gap: "6px",
|
|
@@ -125,28 +308,28 @@ function Ie(i, o) {
|
|
|
125
308
|
width: "100%",
|
|
126
309
|
maxWidth: "85%"
|
|
127
310
|
});
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
|
|
311
|
+
f.className = "ago-message__sources", t.sources.forEach((v, u) => {
|
|
312
|
+
const _ = v.url ? document.createElement("a") : document.createElement("div");
|
|
313
|
+
v.url && _ instanceof HTMLAnchorElement && (_.href = v.url, _.target = "_blank", _.rel = "noopener noreferrer"), E(_, {
|
|
131
314
|
display: "flex",
|
|
132
315
|
alignItems: "center",
|
|
133
316
|
gap: "8px",
|
|
134
317
|
padding: "8px 10px",
|
|
135
|
-
border: `1px solid ${
|
|
318
|
+
border: `1px solid ${k}`,
|
|
136
319
|
borderRadius: "8px",
|
|
137
|
-
backgroundColor:
|
|
320
|
+
backgroundColor: z,
|
|
138
321
|
textDecoration: "none",
|
|
139
|
-
color:
|
|
322
|
+
color: j,
|
|
140
323
|
fontSize: "12px",
|
|
141
324
|
overflow: "hidden"
|
|
142
325
|
});
|
|
143
|
-
const
|
|
326
|
+
const ae = C({
|
|
144
327
|
flexShrink: "0",
|
|
145
328
|
width: "18px",
|
|
146
329
|
height: "18px",
|
|
147
330
|
borderRadius: "3px",
|
|
148
|
-
border: `1px solid ${
|
|
149
|
-
color:
|
|
331
|
+
border: `1px solid ${Y}`,
|
|
332
|
+
color: Y,
|
|
150
333
|
fontSize: "11px",
|
|
151
334
|
fontWeight: "500",
|
|
152
335
|
display: "flex",
|
|
@@ -154,68 +337,67 @@ function Ie(i, o) {
|
|
|
154
337
|
justifyContent: "center",
|
|
155
338
|
backgroundColor: "#f0f4ff"
|
|
156
339
|
});
|
|
157
|
-
|
|
158
|
-
const
|
|
340
|
+
ae.textContent = String(u + 1);
|
|
341
|
+
const Q = C({
|
|
159
342
|
overflow: "hidden",
|
|
160
343
|
textOverflow: "ellipsis",
|
|
161
344
|
whiteSpace: "nowrap"
|
|
162
345
|
});
|
|
163
|
-
|
|
164
|
-
}),
|
|
346
|
+
Q.textContent = v.title, Q.title = v.title, _.append(ae, Q), f.appendChild(_);
|
|
347
|
+
}), b.appendChild(f);
|
|
165
348
|
}
|
|
166
|
-
const
|
|
167
|
-
maxWidth:
|
|
168
|
-
padding:
|
|
169
|
-
borderRadius:
|
|
170
|
-
backgroundColor:
|
|
171
|
-
color:
|
|
349
|
+
const S = C({
|
|
350
|
+
maxWidth: i ? "75%" : "100%",
|
|
351
|
+
padding: i ? "10px 14px" : "2px 8px",
|
|
352
|
+
borderRadius: i ? le : "0",
|
|
353
|
+
backgroundColor: i ? xe : "transparent",
|
|
354
|
+
color: i ? be : j,
|
|
172
355
|
wordBreak: "break-word",
|
|
173
356
|
fontSize: "14px",
|
|
174
|
-
lineHeight: "1.6"
|
|
175
|
-
whiteSpace: "pre-wrap"
|
|
357
|
+
lineHeight: "1.6"
|
|
176
358
|
});
|
|
177
|
-
if (
|
|
178
|
-
const
|
|
359
|
+
if (S.className = "ago-message__content", t.content ? S.appendChild(me(t.content)) : t.status === "IN_PROGRESS" && S.appendChild(_e()), b.appendChild(S), t.followUpReplies && t.followUpReplies.length > 0) {
|
|
360
|
+
const f = C({
|
|
179
361
|
display: "flex",
|
|
180
362
|
flexWrap: "wrap",
|
|
181
363
|
gap: "8px",
|
|
182
364
|
marginTop: "10px"
|
|
183
365
|
});
|
|
184
|
-
|
|
185
|
-
for (const
|
|
186
|
-
const
|
|
187
|
-
|
|
366
|
+
f.className = "ago-message__followups";
|
|
367
|
+
for (const v of t.followUpReplies) {
|
|
368
|
+
const u = document.createElement("button");
|
|
369
|
+
u.type = "button", u.className = "ago-message__followup-btn", u.textContent = v, u.disabled = !J, E(u, {
|
|
188
370
|
padding: "6px 14px",
|
|
189
371
|
fontSize: "13px",
|
|
190
|
-
borderRadius:
|
|
191
|
-
border: `1px solid ${
|
|
192
|
-
backgroundColor:
|
|
193
|
-
color:
|
|
194
|
-
cursor:
|
|
372
|
+
borderRadius: le,
|
|
373
|
+
border: `1px solid ${k}`,
|
|
374
|
+
backgroundColor: z,
|
|
375
|
+
color: j,
|
|
376
|
+
cursor: J ? "pointer" : "default",
|
|
195
377
|
transition: "border-color 0.15s"
|
|
196
|
-
}),
|
|
197
|
-
|
|
198
|
-
}),
|
|
199
|
-
|
|
200
|
-
}),
|
|
378
|
+
}), ee && u.addEventListener("click", () => ee(v)), u.addEventListener("mouseenter", () => {
|
|
379
|
+
u.style.borderColor = Y;
|
|
380
|
+
}), u.addEventListener("mouseleave", () => {
|
|
381
|
+
u.style.borderColor = k;
|
|
382
|
+
}), f.appendChild(u);
|
|
201
383
|
}
|
|
202
|
-
|
|
384
|
+
b.appendChild(f);
|
|
203
385
|
}
|
|
204
|
-
return
|
|
386
|
+
return b;
|
|
205
387
|
}
|
|
206
|
-
function
|
|
207
|
-
if (
|
|
208
|
-
const
|
|
388
|
+
function I() {
|
|
389
|
+
if ($.replaceChildren(), p.length === 0) {
|
|
390
|
+
const t = C({
|
|
209
391
|
textAlign: "center",
|
|
210
|
-
color:
|
|
392
|
+
color: Be,
|
|
211
393
|
padding: "24px 16px",
|
|
212
394
|
fontSize: "14px",
|
|
213
395
|
lineHeight: "1.5"
|
|
214
396
|
});
|
|
215
|
-
|
|
216
|
-
} else for (const
|
|
217
|
-
if (
|
|
218
|
-
const
|
|
397
|
+
t.textContent = e, $.appendChild(t);
|
|
398
|
+
} else for (const t of p) $.appendChild(Ee(t));
|
|
399
|
+
if (B) {
|
|
400
|
+
const t = C({
|
|
219
401
|
padding: "10px 14px",
|
|
220
402
|
backgroundColor: "#fef2f2",
|
|
221
403
|
color: "#dc2626",
|
|
@@ -224,217 +406,218 @@ function Ie(i, o) {
|
|
|
224
406
|
fontSize: "13px",
|
|
225
407
|
border: "1px solid #fecaca"
|
|
226
408
|
});
|
|
227
|
-
|
|
409
|
+
t.textContent = B, $.appendChild(t);
|
|
228
410
|
}
|
|
229
|
-
|
|
411
|
+
$.scrollTop = $.scrollHeight, ve(A);
|
|
230
412
|
}
|
|
231
|
-
function
|
|
232
|
-
for (let
|
|
233
|
-
const
|
|
234
|
-
if (
|
|
413
|
+
function we() {
|
|
414
|
+
for (let t = p.length - 1; t >= 0; t--) {
|
|
415
|
+
const i = p[t];
|
|
416
|
+
if (i.role === "assistant" && i.status === "IN_PROGRESS") return i;
|
|
235
417
|
}
|
|
236
418
|
}
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
},
|
|
240
|
-
const
|
|
241
|
-
|
|
242
|
-
},
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
id:
|
|
246
|
-
content:
|
|
419
|
+
const te = (t) => {
|
|
420
|
+
w || (w = t.conversationId);
|
|
421
|
+
}, ne = (t) => {
|
|
422
|
+
const i = we();
|
|
423
|
+
i && (i.content += t.content, I());
|
|
424
|
+
}, oe = (t) => {
|
|
425
|
+
const i = p.findIndex((b) => b.id === t.id || b.role === "assistant" && b.status === "IN_PROGRESS");
|
|
426
|
+
i >= 0 ? p[i] = t : p.push(t), A = !1, I(), t.status === "DONE" && U?.({
|
|
427
|
+
id: t.id,
|
|
428
|
+
content: t.content
|
|
247
429
|
});
|
|
248
|
-
},
|
|
249
|
-
|
|
430
|
+
}, re = (t) => {
|
|
431
|
+
B = t.error, A = !1, p = p.filter((i) => !i.id.startsWith("temp-")), I();
|
|
250
432
|
};
|
|
251
|
-
|
|
252
|
-
const
|
|
253
|
-
async function
|
|
254
|
-
const
|
|
255
|
-
if (!
|
|
256
|
-
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
id: `temp-user-${
|
|
260
|
-
conversationId:
|
|
261
|
-
content:
|
|
433
|
+
x.on("message:start", te), x.on("message:chunk", ne), x.on("message:complete", oe), x.on("message:error", re);
|
|
434
|
+
const Se = (T ?? []).map((t) => $e(t).install(x));
|
|
435
|
+
async function q(t, i) {
|
|
436
|
+
const b = t.trim();
|
|
437
|
+
if (!b && !i?.length || A) return;
|
|
438
|
+
R?.(b), A = !0, B = null;
|
|
439
|
+
const S = Date.now();
|
|
440
|
+
p.push({
|
|
441
|
+
id: `temp-user-${S}`,
|
|
442
|
+
conversationId: w || "",
|
|
443
|
+
content: b,
|
|
262
444
|
role: "user",
|
|
263
445
|
status: "DONE",
|
|
264
446
|
createdAt: /* @__PURE__ */ new Date()
|
|
265
|
-
}),
|
|
266
|
-
id: `temp-assistant-${
|
|
267
|
-
conversationId:
|
|
447
|
+
}), p.push({
|
|
448
|
+
id: `temp-assistant-${S}`,
|
|
449
|
+
conversationId: w || "",
|
|
268
450
|
content: "",
|
|
269
451
|
role: "assistant",
|
|
270
452
|
status: "IN_PROGRESS",
|
|
271
453
|
createdAt: /* @__PURE__ */ new Date()
|
|
272
|
-
}),
|
|
454
|
+
}), I();
|
|
273
455
|
try {
|
|
274
|
-
const
|
|
275
|
-
conversationId:
|
|
276
|
-
files:
|
|
456
|
+
const f = await x.sendMessage(b, {
|
|
457
|
+
conversationId: w,
|
|
458
|
+
files: i
|
|
277
459
|
});
|
|
278
|
-
|
|
279
|
-
const
|
|
280
|
-
if (
|
|
281
|
-
const
|
|
282
|
-
|
|
460
|
+
f.conversationId && (w || (w = f.conversationId), O?.setActiveThread(f.conversationId, f.createdAt));
|
|
461
|
+
const v = p.find((u) => u.id === `temp-user-${S}`);
|
|
462
|
+
if (v && (v.id = `user-${S}`, v.conversationId = f.conversationId), !p.some((u) => u.id === f.id)) {
|
|
463
|
+
const u = p.findIndex((_) => _.id === `temp-assistant-${S}`);
|
|
464
|
+
u >= 0 ? p[u] = f : p.push(f);
|
|
283
465
|
}
|
|
284
|
-
|
|
285
|
-
} catch (
|
|
286
|
-
|
|
466
|
+
p = p.filter((u) => !u.id.startsWith("temp-")), A = !1, I(), h && V();
|
|
467
|
+
} catch (f) {
|
|
468
|
+
B = f instanceof Error ? f.message : "Failed to send message", A = !1, p = p.filter((v) => !v.id.startsWith("temp-")), I();
|
|
287
469
|
}
|
|
288
470
|
}
|
|
289
|
-
async function
|
|
471
|
+
async function V() {
|
|
290
472
|
try {
|
|
291
|
-
const
|
|
292
|
-
|
|
473
|
+
const t = await x.getConversations();
|
|
474
|
+
W.splice(0, W.length, ...t);
|
|
293
475
|
} catch {
|
|
294
476
|
}
|
|
295
|
-
return
|
|
477
|
+
return W;
|
|
296
478
|
}
|
|
297
|
-
async function
|
|
479
|
+
async function Re(t) {
|
|
298
480
|
try {
|
|
299
|
-
const
|
|
300
|
-
|
|
481
|
+
const i = (await x.getConversation(t))?.messages ?? [];
|
|
482
|
+
i.length > 0 && p.length === 0 && (p = i, I());
|
|
301
483
|
} catch {
|
|
302
|
-
|
|
484
|
+
p.length === 0 && (O?.clear(), w = void 0);
|
|
303
485
|
}
|
|
304
486
|
}
|
|
305
|
-
return
|
|
306
|
-
client:
|
|
307
|
-
element:
|
|
308
|
-
sendMessage:
|
|
309
|
-
session:
|
|
310
|
-
threads:
|
|
311
|
-
refreshThreads:
|
|
487
|
+
return I(), ye(), w && Re(w), h && V(), {
|
|
488
|
+
client: x,
|
|
489
|
+
element: D,
|
|
490
|
+
sendMessage: q,
|
|
491
|
+
session: O,
|
|
492
|
+
threads: W,
|
|
493
|
+
refreshThreads: V,
|
|
312
494
|
destroy() {
|
|
313
|
-
|
|
495
|
+
x.off("message:start", te), x.off("message:chunk", ne), x.off("message:complete", oe), x.off("message:error", re), Se.forEach((t) => t()), D.remove(), n.client || x.destroy();
|
|
314
496
|
}
|
|
315
497
|
};
|
|
316
|
-
function
|
|
317
|
-
const
|
|
498
|
+
function _e() {
|
|
499
|
+
const t = C({
|
|
318
500
|
display: "flex",
|
|
319
501
|
gap: "4px",
|
|
320
502
|
padding: "4px 0"
|
|
321
503
|
});
|
|
322
|
-
for (let
|
|
323
|
-
const
|
|
504
|
+
for (let i = 0; i < 3; i++) {
|
|
505
|
+
const b = C({
|
|
324
506
|
width: "6px",
|
|
325
507
|
height: "6px",
|
|
326
508
|
borderRadius: "50%",
|
|
327
509
|
backgroundColor: "#b5bfc8",
|
|
328
510
|
animation: "ago-pulse 1.2s ease-in-out infinite",
|
|
329
|
-
animationDelay: `${
|
|
511
|
+
animationDelay: `${i * 0.2}s`
|
|
330
512
|
});
|
|
331
|
-
|
|
513
|
+
t.appendChild(b);
|
|
332
514
|
}
|
|
333
|
-
return
|
|
515
|
+
return t;
|
|
334
516
|
}
|
|
335
517
|
}
|
|
336
|
-
function
|
|
337
|
-
let
|
|
338
|
-
const
|
|
339
|
-
|
|
518
|
+
function Pe(o) {
|
|
519
|
+
let n = [];
|
|
520
|
+
const r = document.createElement("form");
|
|
521
|
+
E(r, {
|
|
340
522
|
display: "flex",
|
|
341
523
|
flexDirection: "column",
|
|
342
524
|
gap: "8px",
|
|
343
525
|
padding: "12px",
|
|
344
|
-
borderTop: `1px solid ${
|
|
345
|
-
backgroundColor:
|
|
346
|
-
}),
|
|
347
|
-
const
|
|
526
|
+
borderTop: `1px solid ${k}`,
|
|
527
|
+
backgroundColor: z
|
|
528
|
+
}), r.className = "ago-chat-input";
|
|
529
|
+
const e = C({
|
|
348
530
|
display: "flex",
|
|
349
531
|
flexWrap: "wrap",
|
|
350
532
|
gap: "6px"
|
|
351
|
-
}),
|
|
533
|
+
}), g = C({
|
|
352
534
|
display: "flex",
|
|
353
535
|
gap: "8px",
|
|
354
536
|
alignItems: "flex-end"
|
|
355
|
-
}),
|
|
356
|
-
|
|
537
|
+
}), a = document.createElement("textarea");
|
|
538
|
+
a.placeholder = o.placeholder, a.rows = 1, E(a, {
|
|
357
539
|
flex: "1",
|
|
358
540
|
resize: "none",
|
|
359
541
|
padding: "10px 12px",
|
|
360
|
-
border: `1px solid ${
|
|
542
|
+
border: `1px solid ${k}`,
|
|
361
543
|
borderRadius: "12px",
|
|
362
544
|
fontSize: "14px",
|
|
363
|
-
fontFamily:
|
|
545
|
+
fontFamily: he,
|
|
364
546
|
lineHeight: "1.4",
|
|
365
547
|
maxHeight: "120px",
|
|
366
548
|
outline: "none"
|
|
367
549
|
});
|
|
368
|
-
const
|
|
369
|
-
|
|
550
|
+
const d = document.createElement("button");
|
|
551
|
+
d.type = "submit", d.textContent = "Send", E(d, {
|
|
370
552
|
padding: "10px 16px",
|
|
371
553
|
border: "none",
|
|
372
554
|
borderRadius: "12px",
|
|
373
|
-
backgroundColor:
|
|
374
|
-
color:
|
|
555
|
+
backgroundColor: xe,
|
|
556
|
+
color: be,
|
|
375
557
|
fontSize: "14px",
|
|
376
558
|
fontWeight: "500",
|
|
377
559
|
cursor: "pointer"
|
|
378
560
|
});
|
|
379
|
-
let
|
|
380
|
-
|
|
561
|
+
let s = null, c = null;
|
|
562
|
+
o.allowFiles && (s = document.createElement("input"), s.type = "file", s.multiple = !0, E(s, { display: "none" }), c = document.createElement("button"), c.type = "button", c.textContent = "📎", E(c, {
|
|
381
563
|
padding: "10px 12px",
|
|
382
|
-
border: `1px solid ${
|
|
564
|
+
border: `1px solid ${k}`,
|
|
383
565
|
borderRadius: "12px",
|
|
384
|
-
backgroundColor:
|
|
566
|
+
backgroundColor: z,
|
|
385
567
|
cursor: "pointer",
|
|
386
568
|
fontSize: "14px"
|
|
387
|
-
}),
|
|
388
|
-
|
|
569
|
+
}), c.addEventListener("click", () => s?.click()), s.addEventListener("change", () => {
|
|
570
|
+
n = [...n, ...Array.from(s?.files ?? [])], l();
|
|
389
571
|
}));
|
|
390
|
-
function
|
|
391
|
-
|
|
392
|
-
const
|
|
572
|
+
function l() {
|
|
573
|
+
e.replaceChildren(), n.forEach((m, R) => {
|
|
574
|
+
const U = C({
|
|
393
575
|
display: "flex",
|
|
394
576
|
alignItems: "center",
|
|
395
577
|
gap: "4px",
|
|
396
578
|
padding: "4px 8px",
|
|
397
579
|
backgroundColor: "#f0f4ff",
|
|
398
|
-
border: `1px solid ${
|
|
580
|
+
border: `1px solid ${k}`,
|
|
399
581
|
borderRadius: "8px",
|
|
400
582
|
fontSize: "12px"
|
|
401
|
-
}),
|
|
402
|
-
|
|
403
|
-
const
|
|
404
|
-
|
|
583
|
+
}), x = document.createElement("span");
|
|
584
|
+
x.textContent = m.name;
|
|
585
|
+
const L = document.createElement("button");
|
|
586
|
+
L.type = "button", L.textContent = "×", E(L, {
|
|
405
587
|
border: "none",
|
|
406
588
|
background: "transparent",
|
|
407
589
|
cursor: "pointer",
|
|
408
590
|
fontSize: "14px",
|
|
409
591
|
lineHeight: "1"
|
|
410
|
-
}),
|
|
411
|
-
|
|
412
|
-
}),
|
|
592
|
+
}), L.addEventListener("click", () => {
|
|
593
|
+
n = n.filter((F, O) => O !== R), l();
|
|
594
|
+
}), U.append(x, L), e.appendChild(U);
|
|
413
595
|
});
|
|
414
596
|
}
|
|
415
|
-
const
|
|
416
|
-
const
|
|
417
|
-
return
|
|
418
|
-
content:
|
|
419
|
-
files:
|
|
597
|
+
const h = () => {
|
|
598
|
+
const m = a.value, R = n;
|
|
599
|
+
return a.value = "", n = [], l(), {
|
|
600
|
+
content: m,
|
|
601
|
+
files: R
|
|
420
602
|
};
|
|
421
|
-
},
|
|
422
|
-
const { content:
|
|
423
|
-
(
|
|
603
|
+
}, T = () => {
|
|
604
|
+
const { content: m, files: R } = h();
|
|
605
|
+
(m.trim() || R.length > 0) && o.onSend(m.trim(), R.length > 0 ? R : void 0);
|
|
424
606
|
};
|
|
425
|
-
return
|
|
426
|
-
|
|
427
|
-
}),
|
|
428
|
-
|
|
429
|
-
}),
|
|
430
|
-
inputRow:
|
|
431
|
-
getValueAndClear:
|
|
432
|
-
setDisabled: (
|
|
433
|
-
|
|
607
|
+
return r.addEventListener("submit", (m) => {
|
|
608
|
+
m.preventDefault(), T();
|
|
609
|
+
}), a.addEventListener("keydown", (m) => {
|
|
610
|
+
m.key === "Enter" && !m.shiftKey && (m.preventDefault(), T());
|
|
611
|
+
}), c && g.appendChild(c), g.append(a, d), s && r.appendChild(s), r.append(e, g), {
|
|
612
|
+
inputRow: r,
|
|
613
|
+
getValueAndClear: h,
|
|
614
|
+
setDisabled: (m) => {
|
|
615
|
+
a.disabled = m, d.disabled = m, d.style.opacity = m ? "0.6" : "1", d.style.cursor = m ? "not-allowed" : "pointer";
|
|
434
616
|
},
|
|
435
|
-
focus: () =>
|
|
617
|
+
focus: () => a.focus()
|
|
436
618
|
};
|
|
437
619
|
}
|
|
438
620
|
export {
|
|
439
|
-
|
|
621
|
+
Ke as mountChatWidget,
|
|
622
|
+
me as renderMarkdown
|
|
440
623
|
};
|