@useago/sdk 1.0.10 → 1.0.11
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/react.cjs +3 -3
- package/dist/react.js +363 -341
- package/dist/widget.cjs +4 -4
- package/dist/widget.d.cts +25 -2
- package/dist/widget.d.ts +25 -2
- package/dist/widget.js +460 -412
- package/package.json +1 -1
package/dist/widget.js
CHANGED
|
@@ -1,190 +1,190 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import { r as
|
|
3
|
-
import { t as
|
|
4
|
-
var
|
|
1
|
+
import { t as mt, u as ht } from "./AgoClient-QcTtrN7u.js";
|
|
2
|
+
import { r as xt, t as bt } from "./createFormCollector-CFt1_QSL.js";
|
|
3
|
+
import { t as vt } from "./createConversationSession-CR-71aLR.js";
|
|
4
|
+
var yt = {
|
|
5
5
|
"&": "&",
|
|
6
6
|
"<": "<",
|
|
7
7
|
">": ">",
|
|
8
8
|
'"': """,
|
|
9
9
|
"'": "'"
|
|
10
10
|
};
|
|
11
|
-
function
|
|
12
|
-
return r.replace(/[&<>"']/g, (o) =>
|
|
11
|
+
function q(r) {
|
|
12
|
+
return r.replace(/[&<>"']/g, (o) => yt[o]);
|
|
13
13
|
}
|
|
14
|
-
function
|
|
14
|
+
function Pe(r) {
|
|
15
15
|
const o = r.trim();
|
|
16
16
|
return /^(https?:|mailto:|tel:|#|\/|\.\/|\.\.\/)/i.test(o) || !/^[a-z][a-z0-9+.-]*:/i.test(o) ? o : null;
|
|
17
17
|
}
|
|
18
|
-
var
|
|
19
|
-
function
|
|
20
|
-
const o = [], a = (
|
|
21
|
-
let
|
|
22
|
-
return
|
|
23
|
-
const
|
|
24
|
-
return
|
|
25
|
-
}),
|
|
26
|
-
const
|
|
27
|
-
return
|
|
28
|
-
}),
|
|
18
|
+
var Ze = '"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace', le = "";
|
|
19
|
+
function G(r) {
|
|
20
|
+
const o = [], a = (u) => (o.push(u), `${le}${o.length - 1}${le}`);
|
|
21
|
+
let n = r;
|
|
22
|
+
return n = n.replace(/`([^`]+)`/g, (u, s) => a(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${Ze}">${q(s)}</code>`)), n = n.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g, (u, s, v) => {
|
|
23
|
+
const p = Pe(v);
|
|
24
|
+
return p ? a(`<img alt="${q(s)}" src="${q(p)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`) : u;
|
|
25
|
+
}), n = n.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (u, s, v) => {
|
|
26
|
+
const p = Pe(v);
|
|
27
|
+
return p ? a(`<a href="${q(p)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${G(s)}</a>`) : u;
|
|
28
|
+
}), n = q(n), n = n.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>"), n = n.replace(new RegExp(`${le}(\\d+)${le}`, "g"), (u, s) => o[Number(s)]), n;
|
|
29
29
|
}
|
|
30
|
-
function
|
|
31
|
-
const
|
|
32
|
-
return Object.assign(
|
|
30
|
+
function N(r, o, a) {
|
|
31
|
+
const n = document.createElement(r);
|
|
32
|
+
return Object.assign(n.style, o), a !== void 0 && (n.innerHTML = a), n;
|
|
33
33
|
}
|
|
34
|
-
var
|
|
34
|
+
var Qe = /^ {0,3}([-*_])( *\1){2,} *$/, Je = /^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/, et = /^ {0,3}(```+|~~~+)/, ce = /^ {0,3}>\s?/, V = /^(\s*)([-*+]|\d+[.)])\s+(.*)$/, Ct = [
|
|
35
35
|
"20px",
|
|
36
36
|
"18px",
|
|
37
37
|
"16px",
|
|
38
38
|
"15px",
|
|
39
39
|
"14px",
|
|
40
40
|
"13px"
|
|
41
|
-
],
|
|
42
|
-
function
|
|
43
|
-
return r.trim() === "" ||
|
|
41
|
+
], Se = (r) => r.match(/^\s*/)?.[0].length ?? 0;
|
|
42
|
+
function wt(r) {
|
|
43
|
+
return r.trim() === "" || Qe.test(r) || Je.test(r) || et.test(r) || ce.test(r) || V.test(r);
|
|
44
44
|
}
|
|
45
|
-
function
|
|
46
|
-
const o = r[0].match(
|
|
45
|
+
function tt(r) {
|
|
46
|
+
const o = r[0].match(V), a = o[1].length, n = /\d/.test(o[2]), u = N(n ? "ol" : "ul", {
|
|
47
47
|
margin: "0 0 8px 0",
|
|
48
48
|
paddingLeft: "20px",
|
|
49
|
-
listStyleType:
|
|
49
|
+
listStyleType: n ? "decimal" : "disc",
|
|
50
50
|
listStylePosition: "outside"
|
|
51
51
|
});
|
|
52
52
|
let s = 0;
|
|
53
53
|
for (; s < r.length; ) {
|
|
54
|
-
const
|
|
55
|
-
for (s++; s < r.length &&
|
|
56
|
-
|
|
57
|
-
const
|
|
54
|
+
const v = r[s].match(V), p = [];
|
|
55
|
+
for (s++; s < r.length && Se(r[s]) > a; )
|
|
56
|
+
p.push(r[s]), s++;
|
|
57
|
+
const b = N("li", {
|
|
58
58
|
display: "list-item",
|
|
59
59
|
margin: "2px 0",
|
|
60
60
|
lineHeight: "1.6"
|
|
61
|
-
}),
|
|
62
|
-
|
|
61
|
+
}), d = v[3].match(/^\[([ xX])\]\s+(.*)$/);
|
|
62
|
+
d ? (b.style.listStyleType = "none", b.style.marginLeft = "-20px", b.innerHTML = `<span style="margin-right:6px">${d[1].toLowerCase() === "x" ? "☑" : "☐"}</span>${G(d[2])}`) : b.innerHTML = G(v[3]), p.filter((g) => V.test(g)).length > 0 && b.appendChild(tt(p.filter((g) => g.trim() !== ""))), u.appendChild(b);
|
|
63
63
|
}
|
|
64
|
-
return
|
|
64
|
+
return u;
|
|
65
65
|
}
|
|
66
|
-
function
|
|
67
|
-
const o = (
|
|
66
|
+
function Et(r) {
|
|
67
|
+
const o = (p) => p.replace(/^\s*\|?/, "").replace(/\|?\s*$/, "").split("|").map((b) => b.trim()), a = N("div", {
|
|
68
68
|
overflowX: "auto",
|
|
69
69
|
margin: "0 0 8px 0"
|
|
70
|
-
}),
|
|
70
|
+
}), n = N("table", {
|
|
71
71
|
borderCollapse: "collapse",
|
|
72
72
|
width: "100%",
|
|
73
73
|
fontSize: "13px"
|
|
74
|
-
}),
|
|
75
|
-
for (const
|
|
74
|
+
}), u = document.createElement("thead"), s = document.createElement("tr");
|
|
75
|
+
for (const p of o(r[0])) s.appendChild(N("th", {
|
|
76
76
|
border: "1px solid #dee3e8",
|
|
77
77
|
padding: "6px 10px",
|
|
78
78
|
textAlign: "left",
|
|
79
79
|
backgroundColor: "#f5f7fa",
|
|
80
80
|
fontWeight: "600"
|
|
81
|
-
},
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
for (const
|
|
85
|
-
const
|
|
86
|
-
for (const
|
|
81
|
+
}, G(p)));
|
|
82
|
+
u.appendChild(s), n.appendChild(u);
|
|
83
|
+
const v = document.createElement("tbody");
|
|
84
|
+
for (const p of r.slice(2)) {
|
|
85
|
+
const b = document.createElement("tr");
|
|
86
|
+
for (const d of o(p)) b.appendChild(N("td", {
|
|
87
87
|
border: "1px solid #dee3e8",
|
|
88
88
|
padding: "6px 10px"
|
|
89
|
-
},
|
|
90
|
-
|
|
89
|
+
}, G(d)));
|
|
90
|
+
v.appendChild(b);
|
|
91
91
|
}
|
|
92
|
-
return
|
|
92
|
+
return n.appendChild(v), a.appendChild(n), a;
|
|
93
93
|
}
|
|
94
|
-
var
|
|
95
|
-
function
|
|
94
|
+
var St = (r) => !!r && /^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(r);
|
|
95
|
+
function Re(r) {
|
|
96
96
|
const o = document.createDocumentFragment(), a = r.replace(/\r\n?/g, `
|
|
97
97
|
`).split(`
|
|
98
98
|
`);
|
|
99
|
-
let
|
|
100
|
-
for (;
|
|
101
|
-
const s = a[
|
|
99
|
+
let n = 0;
|
|
100
|
+
for (; n < a.length; ) {
|
|
101
|
+
const s = a[n];
|
|
102
102
|
if (s.trim() === "") {
|
|
103
|
-
|
|
103
|
+
n++;
|
|
104
104
|
continue;
|
|
105
105
|
}
|
|
106
|
-
const
|
|
107
|
-
if (
|
|
108
|
-
const
|
|
109
|
-
for (
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const B =
|
|
113
|
-
B.appendChild(
|
|
106
|
+
const v = s.match(et);
|
|
107
|
+
if (v) {
|
|
108
|
+
const d = v[1][0], g = [];
|
|
109
|
+
for (n++; n < a.length && !new RegExp(`^ {0,3}${d === "`" ? "`{3,}" : "~{3,}"}\\s*$`).test(a[n]); )
|
|
110
|
+
g.push(a[n]), n++;
|
|
111
|
+
n++;
|
|
112
|
+
const B = N("pre", { margin: "0 0 8px 0" });
|
|
113
|
+
B.appendChild(N("code", {
|
|
114
114
|
display: "block",
|
|
115
115
|
background: "#f5f5f5",
|
|
116
116
|
padding: "8px 12px",
|
|
117
117
|
borderRadius: "6px",
|
|
118
118
|
fontSize: "13px",
|
|
119
119
|
overflowX: "auto",
|
|
120
|
-
fontFamily:
|
|
120
|
+
fontFamily: Ze,
|
|
121
121
|
whiteSpace: "pre"
|
|
122
|
-
},
|
|
122
|
+
}, q(g.join(`
|
|
123
123
|
`)))), o.appendChild(B);
|
|
124
124
|
continue;
|
|
125
125
|
}
|
|
126
|
-
if (
|
|
127
|
-
o.appendChild(
|
|
126
|
+
if (Qe.test(s)) {
|
|
127
|
+
o.appendChild(N("hr", {
|
|
128
128
|
border: "none",
|
|
129
129
|
borderTop: "1px solid #dee3e8",
|
|
130
130
|
margin: "12px 0"
|
|
131
|
-
})),
|
|
131
|
+
})), n++;
|
|
132
132
|
continue;
|
|
133
133
|
}
|
|
134
|
-
const
|
|
135
|
-
if (
|
|
136
|
-
const
|
|
137
|
-
o.appendChild(
|
|
134
|
+
const p = s.match(Je);
|
|
135
|
+
if (p) {
|
|
136
|
+
const d = p[1].length;
|
|
137
|
+
o.appendChild(N(`h${d}`, {
|
|
138
138
|
margin: "16px 0 8px 0",
|
|
139
|
-
fontSize:
|
|
139
|
+
fontSize: Ct[d - 1],
|
|
140
140
|
fontWeight: "600",
|
|
141
141
|
lineHeight: "1.3"
|
|
142
|
-
},
|
|
142
|
+
}, G(p[2]))), n++;
|
|
143
143
|
continue;
|
|
144
144
|
}
|
|
145
|
-
if (
|
|
146
|
-
const
|
|
147
|
-
for (;
|
|
148
|
-
|
|
149
|
-
const
|
|
145
|
+
if (ce.test(s)) {
|
|
146
|
+
const d = [];
|
|
147
|
+
for (; n < a.length && ce.test(a[n]); )
|
|
148
|
+
d.push(a[n].replace(ce, "")), n++;
|
|
149
|
+
const g = N("blockquote", {
|
|
150
150
|
borderLeft: "4px solid #dee3e8",
|
|
151
151
|
paddingLeft: "12px",
|
|
152
152
|
margin: "0 0 8px 0",
|
|
153
153
|
fontStyle: "italic",
|
|
154
154
|
color: "#6b6d6f"
|
|
155
155
|
});
|
|
156
|
-
|
|
157
|
-
`))), o.appendChild(
|
|
156
|
+
g.appendChild(Re(d.join(`
|
|
157
|
+
`))), o.appendChild(g);
|
|
158
158
|
continue;
|
|
159
159
|
}
|
|
160
|
-
if (s.includes("|") &&
|
|
161
|
-
const
|
|
162
|
-
for (
|
|
163
|
-
|
|
164
|
-
o.appendChild(
|
|
160
|
+
if (s.includes("|") && St(a[n + 1])) {
|
|
161
|
+
const d = [s, a[n + 1]];
|
|
162
|
+
for (n += 2; n < a.length && a[n].includes("|") && a[n].trim(); )
|
|
163
|
+
d.push(a[n]), n++;
|
|
164
|
+
o.appendChild(Et(d));
|
|
165
165
|
continue;
|
|
166
166
|
}
|
|
167
|
-
if (
|
|
168
|
-
const
|
|
169
|
-
for (;
|
|
170
|
-
if (
|
|
171
|
-
|
|
167
|
+
if (V.test(s)) {
|
|
168
|
+
const d = [], g = Se(s);
|
|
169
|
+
for (; n < a.length && a[n].trim() !== ""; )
|
|
170
|
+
if (V.test(a[n]) || Se(a[n]) > g)
|
|
171
|
+
d.push(a[n]), n++;
|
|
172
172
|
else break;
|
|
173
|
-
o.appendChild(
|
|
173
|
+
o.appendChild(tt(d));
|
|
174
174
|
continue;
|
|
175
175
|
}
|
|
176
|
-
const
|
|
177
|
-
for (
|
|
178
|
-
|
|
179
|
-
o.appendChild(
|
|
176
|
+
const b = [s];
|
|
177
|
+
for (n++; n < a.length && !wt(a[n]); )
|
|
178
|
+
b.push(a[n]), n++;
|
|
179
|
+
o.appendChild(N("p", {
|
|
180
180
|
margin: "0 0 8px 0",
|
|
181
181
|
lineHeight: "1.6"
|
|
182
|
-
},
|
|
182
|
+
}, b.map((d) => G(d)).join("<br>")));
|
|
183
183
|
}
|
|
184
|
-
const
|
|
185
|
-
return
|
|
184
|
+
const u = o.lastElementChild;
|
|
185
|
+
return u && (u.style.marginBottom = "0"), o;
|
|
186
186
|
}
|
|
187
|
-
var
|
|
187
|
+
var _e = 'var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif)', je = {
|
|
188
188
|
font: "--ago-font",
|
|
189
189
|
radius: "--ago-radius",
|
|
190
190
|
messageRadius: "--ago-message-radius",
|
|
@@ -199,23 +199,23 @@ var ve = 'var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "S
|
|
|
199
199
|
border: "--ago-border-color",
|
|
200
200
|
accent: "--ago-accent-color",
|
|
201
201
|
agentBubbleBg: "--ago-agent-bubble-background"
|
|
202
|
-
},
|
|
203
|
-
function
|
|
202
|
+
}, pe = "var(--ago-brand-color, #03182f)", ke = "var(--ago-brand-text-color, #fff)", Rt = "var(--ago-header-background, var(--ago-brand-color, #03182f))", Xe = "var(--ago-header-text-color, #e8f0fe)", ee = "var(--ago-panel-background, #fff)", Ke = "var(--ago-messages-background, #fbfbfb)", de = "var(--ago-text-color, #30373e)", _t = "var(--ago-muted-text-color, #6b6d6f)", O = "var(--ago-border-color, #dee3e8)", we = "var(--ago-accent-color, #1b5fc4)", qe = "var(--ago-agent-bubble-background, #f1f3f5)", kt = "var(--ago-radius, 16px)", Ee = "var(--ago-message-radius, 16px)", At = "var(--ago-message-radius, 20px)";
|
|
203
|
+
function It(r, o) {
|
|
204
204
|
if (o)
|
|
205
|
-
for (const a of Object.keys(
|
|
206
|
-
const
|
|
207
|
-
|
|
205
|
+
for (const a of Object.keys(je)) {
|
|
206
|
+
const n = o[a];
|
|
207
|
+
n != null && r.style.setProperty(je[a], n);
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
|
-
function
|
|
210
|
+
function E(r, o) {
|
|
211
211
|
Object.assign(r.style, o);
|
|
212
212
|
}
|
|
213
|
-
function
|
|
213
|
+
function x(r = {}) {
|
|
214
214
|
const o = document.createElement("div");
|
|
215
|
-
return
|
|
215
|
+
return E(o, r), o;
|
|
216
216
|
}
|
|
217
|
-
var
|
|
218
|
-
function
|
|
217
|
+
var Ve = "Form submitted.";
|
|
218
|
+
function Nt(r) {
|
|
219
219
|
if (typeof r == "string") return r || null;
|
|
220
220
|
if (!r || typeof r != "object") return null;
|
|
221
221
|
const o = r;
|
|
@@ -223,173 +223,176 @@ function wt(r) {
|
|
|
223
223
|
const a = o.result;
|
|
224
224
|
if (typeof a == "string" && a) return a;
|
|
225
225
|
if (a && typeof a == "object") {
|
|
226
|
-
const
|
|
227
|
-
if (typeof
|
|
226
|
+
const n = a.message;
|
|
227
|
+
if (typeof n == "string" && n) return n;
|
|
228
228
|
}
|
|
229
229
|
return null;
|
|
230
230
|
}
|
|
231
|
-
var
|
|
232
|
-
function
|
|
233
|
-
if (typeof document > "u" || document.getElementById(
|
|
231
|
+
var Ye = "ago-chat-widget-keyframes";
|
|
232
|
+
function $t() {
|
|
233
|
+
if (typeof document > "u" || document.getElementById(Ye)) return;
|
|
234
234
|
const r = document.createElement("style");
|
|
235
|
-
r.id =
|
|
235
|
+
r.id = Ye, r.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(r);
|
|
236
236
|
}
|
|
237
|
-
function
|
|
237
|
+
function Lt(r) {
|
|
238
238
|
const o = typeof r == "string" ? document.querySelector(r) : r;
|
|
239
239
|
if (!o) throw new Error(`mountChatWidget: target "${String(r)}" not found.`);
|
|
240
240
|
return o;
|
|
241
241
|
}
|
|
242
|
-
function
|
|
243
|
-
const { title: a = "Chat", welcomeMessage:
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
242
|
+
function Mt(r, o) {
|
|
243
|
+
const { title: a = "Chat", welcomeMessage: n = "Hello! How can I help you today?", placeholder: u = "Type a message...", allowFiles: s = !1, height: v = 500, placement: p = "inline", width: b = 400, defaultOpen: d = !1, logoUrl: g, showAgentName: B = !1, agentBubble: $ = !1, bubbleStyle: L = "default", showHeader: Y = !0, theme: te, loadThreads: Z = !1, forms: m, formSubmittedMessage: y = Ve, onFollowUpClick: P, onMessageSent: ne, onMessageReceived: D, onFormSubmitted: oe, onFormError: Q } = o, re = typeof n == "string" ? {
|
|
244
|
+
message: n,
|
|
245
|
+
mode: "static"
|
|
246
|
+
} : n, Ae = re.message, Ie = re.mode ?? "static", nt = "speed" in re && re.speed || 45;
|
|
247
|
+
if (!o.client && !o.config?.baseUrl) throw new ht("mountChatWidget requires either `client` or `config` (with a baseUrl).", "config_missing_base_url");
|
|
248
|
+
const h = o.client ?? new mt(o.config), Ne = Lt(r), j = p === "left" || p === "right", ot = j && (o.launcher ?? !0);
|
|
249
|
+
let X = j ? d : !0;
|
|
250
|
+
const fe = o.persistConversation, ae = fe ? vt(fe === !0 ? {} : fe) : void 0;
|
|
251
|
+
let T = o.conversationId ?? ae?.getLastActiveThread() ?? void 0, l = [], F = !1, J = null, M;
|
|
252
|
+
const $e = [];
|
|
253
|
+
function rt(e) {
|
|
254
|
+
if (typeof y == "function") {
|
|
255
|
+
const i = y(e);
|
|
253
256
|
if (typeof i == "string" && i) return i;
|
|
254
257
|
}
|
|
255
|
-
const
|
|
256
|
-
return
|
|
258
|
+
const t = Nt(e);
|
|
259
|
+
return t || (typeof y == "string" ? y : Ve);
|
|
257
260
|
}
|
|
258
|
-
const
|
|
261
|
+
const se = [], K = x({
|
|
259
262
|
display: "flex",
|
|
260
263
|
flexDirection: "column",
|
|
261
|
-
height:
|
|
262
|
-
border: `1px solid ${
|
|
263
|
-
borderRadius:
|
|
264
|
+
height: j ? "100%" : typeof v == "number" ? `${v}px` : v,
|
|
265
|
+
border: `1px solid ${O}`,
|
|
266
|
+
borderRadius: kt,
|
|
264
267
|
overflow: "hidden",
|
|
265
|
-
backgroundColor:
|
|
266
|
-
fontFamily:
|
|
268
|
+
backgroundColor: ee,
|
|
269
|
+
fontFamily: _e,
|
|
267
270
|
textAlign: "left",
|
|
268
271
|
boxShadow: "rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"
|
|
269
272
|
});
|
|
270
|
-
|
|
271
|
-
let
|
|
272
|
-
if (
|
|
273
|
-
if (
|
|
273
|
+
K.className = "ago-chat-widget", It(K, te);
|
|
274
|
+
let z;
|
|
275
|
+
if (Y) {
|
|
276
|
+
if (z = x({
|
|
274
277
|
padding: "14px 16px",
|
|
275
|
-
borderBottom: `1px solid ${
|
|
276
|
-
backgroundColor:
|
|
277
|
-
color:
|
|
278
|
+
borderBottom: `1px solid ${O}`,
|
|
279
|
+
backgroundColor: Rt,
|
|
280
|
+
color: Xe,
|
|
278
281
|
display: "flex",
|
|
279
282
|
alignItems: "center",
|
|
280
283
|
gap: "10px"
|
|
281
|
-
}),
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
+
}), z.className = "ago-chat-widget__header", g) {
|
|
285
|
+
const t = document.createElement("img");
|
|
286
|
+
t.src = g, t.alt = "Logo", E(t, {
|
|
284
287
|
height: "24px",
|
|
285
288
|
width: "auto"
|
|
286
|
-
}),
|
|
289
|
+
}), z.appendChild(t);
|
|
287
290
|
}
|
|
288
291
|
const e = document.createElement("h3");
|
|
289
|
-
if (e.textContent = a,
|
|
292
|
+
if (e.textContent = a, E(e, {
|
|
290
293
|
margin: "0",
|
|
291
294
|
fontSize: "15px",
|
|
292
295
|
fontWeight: "600"
|
|
293
|
-
}),
|
|
294
|
-
const
|
|
295
|
-
|
|
296
|
+
}), z.appendChild(e), j) {
|
|
297
|
+
const t = document.createElement("button");
|
|
298
|
+
t.type = "button", t.className = "ago-chat-widget__close", t.setAttribute("aria-label", "Close"), t.textContent = "×", E(t, {
|
|
296
299
|
marginLeft: "auto",
|
|
297
300
|
background: "transparent",
|
|
298
301
|
border: "none",
|
|
299
|
-
color:
|
|
302
|
+
color: Xe,
|
|
300
303
|
fontSize: "22px",
|
|
301
304
|
lineHeight: "1",
|
|
302
305
|
cursor: "pointer",
|
|
303
306
|
padding: "0 2px"
|
|
304
|
-
}),
|
|
307
|
+
}), t.addEventListener("click", () => ye()), z.appendChild(t);
|
|
305
308
|
}
|
|
306
309
|
}
|
|
307
|
-
const
|
|
310
|
+
const R = x({
|
|
308
311
|
flex: "1",
|
|
309
312
|
overflow: "auto",
|
|
310
313
|
padding: "16px",
|
|
311
|
-
backgroundColor:
|
|
314
|
+
backgroundColor: Ke
|
|
312
315
|
});
|
|
313
|
-
|
|
314
|
-
const { inputRow:
|
|
315
|
-
placeholder:
|
|
316
|
+
R.className = "ago-chat-widget__messages", R.setAttribute("role", "log"), R.setAttribute("aria-live", "polite"), R.setAttribute("aria-relevant", "additions text"), R.setAttribute("aria-atomic", "false");
|
|
317
|
+
const { inputRow: at, setDisabled: st, focus: ue } = Tt({
|
|
318
|
+
placeholder: u,
|
|
316
319
|
allowFiles: s,
|
|
317
|
-
onSend: (e,
|
|
318
|
-
|
|
320
|
+
onSend: (e, t) => {
|
|
321
|
+
he(e, t);
|
|
319
322
|
}
|
|
320
323
|
});
|
|
321
|
-
|
|
322
|
-
let
|
|
323
|
-
const
|
|
324
|
-
if (
|
|
324
|
+
$t(), K.append(...z ? [z] : [], R, at);
|
|
325
|
+
let ie = K, U, _;
|
|
326
|
+
const ge = p === "left" ? "left" : "right";
|
|
327
|
+
if (j && (U = x({
|
|
325
328
|
position: "fixed",
|
|
326
329
|
top: "0",
|
|
327
330
|
bottom: "0",
|
|
328
|
-
[
|
|
329
|
-
width: typeof
|
|
331
|
+
[ge]: "0",
|
|
332
|
+
width: typeof b == "number" ? `${b}px` : b,
|
|
330
333
|
maxWidth: "100vw",
|
|
331
334
|
display: "flex",
|
|
332
335
|
zIndex: "2147483000",
|
|
333
336
|
transition: "transform 0.3s ease",
|
|
334
337
|
boxShadow: "rgba(15, 15, 15, 0.18) 0px 0px 24px 0px"
|
|
335
|
-
}),
|
|
338
|
+
}), U.className = "ago-chat-widget-panel", E(K, {
|
|
336
339
|
height: "100%",
|
|
337
340
|
width: "100%",
|
|
338
341
|
borderRadius: "0",
|
|
339
342
|
border: "none",
|
|
340
343
|
boxShadow: "none",
|
|
341
|
-
[
|
|
342
|
-
}),
|
|
343
|
-
if (
|
|
344
|
+
[ge === "left" ? "borderRight" : "borderLeft"]: `1px solid ${O}`
|
|
345
|
+
}), U.appendChild(K), ie = U), ot) {
|
|
346
|
+
if (_ = document.createElement("button"), _.type = "button", _.className = "ago-chat-widget-launcher", _.setAttribute("aria-label", `Open ${a}`), E(_, {
|
|
344
347
|
position: "fixed",
|
|
345
348
|
bottom: "20px",
|
|
346
|
-
[
|
|
349
|
+
[ge]: "20px",
|
|
347
350
|
width: "56px",
|
|
348
351
|
height: "56px",
|
|
349
352
|
borderRadius: "50%",
|
|
350
353
|
border: "none",
|
|
351
|
-
backgroundColor:
|
|
352
|
-
color:
|
|
354
|
+
backgroundColor: pe,
|
|
355
|
+
color: ke,
|
|
353
356
|
cursor: "pointer",
|
|
354
357
|
display: "flex",
|
|
355
358
|
alignItems: "center",
|
|
356
359
|
justifyContent: "center",
|
|
357
360
|
zIndex: "2147483000",
|
|
358
361
|
boxShadow: "rgba(15, 15, 15, 0.2) 0px 4px 14px 0px",
|
|
359
|
-
fontFamily:
|
|
360
|
-
}),
|
|
362
|
+
fontFamily: _e
|
|
363
|
+
}), g) {
|
|
361
364
|
const e = document.createElement("img");
|
|
362
|
-
e.src =
|
|
365
|
+
e.src = g, e.alt = "", E(e, {
|
|
363
366
|
width: "26px",
|
|
364
367
|
height: "26px",
|
|
365
368
|
objectFit: "contain"
|
|
366
|
-
}),
|
|
367
|
-
} else
|
|
368
|
-
|
|
369
|
+
}), _.appendChild(e);
|
|
370
|
+
} else _.appendChild(ut());
|
|
371
|
+
_.addEventListener("click", () => ve());
|
|
369
372
|
}
|
|
370
|
-
|
|
371
|
-
const
|
|
372
|
-
|
|
373
|
+
Ne.appendChild(ie), _ && Ne.appendChild(_), be();
|
|
374
|
+
const Le = P !== !1, Te = P === !1 ? void 0 : P ?? ((e) => {
|
|
375
|
+
he(e);
|
|
373
376
|
});
|
|
374
|
-
function
|
|
375
|
-
const
|
|
377
|
+
function it(e, t, i = !0) {
|
|
378
|
+
const c = e.role === "user", f = L === "imessage", w = x({
|
|
376
379
|
display: "flex",
|
|
377
380
|
flexDirection: "column",
|
|
378
|
-
alignItems:
|
|
379
|
-
marginBottom:
|
|
381
|
+
alignItems: c ? "flex-end" : "flex-start",
|
|
382
|
+
marginBottom: f && !i ? "2px" : "16px"
|
|
380
383
|
});
|
|
381
|
-
if (
|
|
382
|
-
const
|
|
384
|
+
if (w.className = `ago-message ago-message--${e.role}`, !c && B && e.agent) {
|
|
385
|
+
const C = x({
|
|
383
386
|
fontSize: "13px",
|
|
384
387
|
fontWeight: "500",
|
|
385
|
-
color:
|
|
388
|
+
color: de,
|
|
386
389
|
marginBottom: "6px",
|
|
387
390
|
padding: "0 4px"
|
|
388
391
|
});
|
|
389
|
-
|
|
392
|
+
C.className = "ago-message__agent", C.textContent = e.agent.displayName || e.agent.name, w.appendChild(C);
|
|
390
393
|
}
|
|
391
|
-
if (!
|
|
392
|
-
const
|
|
394
|
+
if (!c && e.sources && e.sources.length > 0) {
|
|
395
|
+
const C = x({
|
|
393
396
|
display: "grid",
|
|
394
397
|
gridTemplateColumns: "1fr 1fr",
|
|
395
398
|
gap: "6px",
|
|
@@ -397,28 +400,28 @@ function $t(r, o) {
|
|
|
397
400
|
width: "100%",
|
|
398
401
|
maxWidth: "85%"
|
|
399
402
|
});
|
|
400
|
-
|
|
401
|
-
const
|
|
402
|
-
|
|
403
|
+
C.className = "ago-message__sources", e.sources.forEach((S, I) => {
|
|
404
|
+
const W = S.url ? document.createElement("a") : document.createElement("div");
|
|
405
|
+
S.url && W instanceof HTMLAnchorElement && (W.href = S.url, W.target = "_blank", W.rel = "noopener noreferrer"), E(W, {
|
|
403
406
|
display: "flex",
|
|
404
407
|
alignItems: "center",
|
|
405
408
|
gap: "8px",
|
|
406
409
|
padding: "8px 10px",
|
|
407
|
-
border: `1px solid ${
|
|
410
|
+
border: `1px solid ${O}`,
|
|
408
411
|
borderRadius: "8px",
|
|
409
|
-
backgroundColor:
|
|
412
|
+
backgroundColor: ee,
|
|
410
413
|
textDecoration: "none",
|
|
411
|
-
color:
|
|
414
|
+
color: de,
|
|
412
415
|
fontSize: "12px",
|
|
413
416
|
overflow: "hidden"
|
|
414
417
|
});
|
|
415
|
-
const
|
|
418
|
+
const Ge = x({
|
|
416
419
|
flexShrink: "0",
|
|
417
420
|
width: "18px",
|
|
418
421
|
height: "18px",
|
|
419
422
|
borderRadius: "3px",
|
|
420
|
-
border: `1px solid ${
|
|
421
|
-
color:
|
|
423
|
+
border: `1px solid ${we}`,
|
|
424
|
+
color: we,
|
|
422
425
|
fontSize: "11px",
|
|
423
426
|
fontWeight: "500",
|
|
424
427
|
display: "flex",
|
|
@@ -426,111 +429,114 @@ function $t(r, o) {
|
|
|
426
429
|
justifyContent: "center",
|
|
427
430
|
backgroundColor: "#f0f4ff"
|
|
428
431
|
});
|
|
429
|
-
|
|
430
|
-
const
|
|
432
|
+
Ge.textContent = String(I + 1);
|
|
433
|
+
const Ce = x({
|
|
431
434
|
overflow: "hidden",
|
|
432
435
|
textOverflow: "ellipsis",
|
|
433
436
|
whiteSpace: "nowrap"
|
|
434
437
|
});
|
|
435
|
-
|
|
436
|
-
}),
|
|
438
|
+
Ce.textContent = S.title, Ce.title = S.title, W.append(Ge, Ce), C.appendChild(W);
|
|
439
|
+
}), w.appendChild(C);
|
|
437
440
|
}
|
|
438
|
-
const
|
|
439
|
-
maxWidth:
|
|
440
|
-
padding:
|
|
441
|
-
borderRadius:
|
|
442
|
-
backgroundColor:
|
|
443
|
-
color:
|
|
441
|
+
const A = c || $ || f, H = x({
|
|
442
|
+
maxWidth: f || c ? "75%" : A ? "85%" : "100%",
|
|
443
|
+
padding: A ? "10px 14px" : "2px 8px",
|
|
444
|
+
borderRadius: f ? At : A ? Ee : "0",
|
|
445
|
+
backgroundColor: c ? pe : A ? qe : "transparent",
|
|
446
|
+
color: c ? ke : de,
|
|
444
447
|
wordBreak: "break-word",
|
|
445
448
|
fontSize: "16px",
|
|
446
449
|
lineHeight: "1.6"
|
|
447
450
|
});
|
|
448
|
-
if (
|
|
449
|
-
|
|
450
|
-
const
|
|
451
|
+
if (H.className = "ago-message__content", f && i) {
|
|
452
|
+
H.style.position = "relative";
|
|
453
|
+
const C = x({
|
|
451
454
|
position: "absolute",
|
|
452
455
|
zIndex: "0",
|
|
453
|
-
bottom: "
|
|
456
|
+
bottom: "-2px",
|
|
454
457
|
width: "20px",
|
|
455
458
|
height: "20px",
|
|
456
|
-
background:
|
|
459
|
+
background: c ? pe : qe
|
|
457
460
|
});
|
|
458
|
-
|
|
459
|
-
const
|
|
461
|
+
C.className = "ago-message__tail";
|
|
462
|
+
const S = x({
|
|
460
463
|
position: "absolute",
|
|
461
464
|
zIndex: "1",
|
|
462
|
-
bottom: "
|
|
465
|
+
bottom: "-2px",
|
|
463
466
|
width: "10px",
|
|
464
467
|
height: "20px",
|
|
465
|
-
background:
|
|
468
|
+
background: Ke
|
|
466
469
|
});
|
|
467
|
-
|
|
470
|
+
S.className = "ago-message__tail-mask", c ? (C.style.right = "-8px", C.style.borderBottomLeftRadius = "16px 14px", S.style.right = "-10px", S.style.borderBottomLeftRadius = "10px") : (C.style.left = "-7px", C.style.borderBottomRightRadius = "16px 14px", S.style.left = "-10px", S.style.borderBottomRightRadius = "10px"), H.append(C, S);
|
|
468
471
|
}
|
|
469
|
-
if (e.content ?
|
|
470
|
-
const
|
|
472
|
+
if (e.content ? H.appendChild(Re(e.content)) : e.status === "IN_PROGRESS" && H.appendChild(gt()), w.appendChild(H), t && e.followUpReplies && e.followUpReplies.length > 0) {
|
|
473
|
+
const C = x({
|
|
471
474
|
display: "flex",
|
|
472
475
|
flexWrap: "wrap",
|
|
473
476
|
gap: "8px",
|
|
474
477
|
marginTop: "10px"
|
|
475
478
|
});
|
|
476
|
-
|
|
477
|
-
for (const
|
|
478
|
-
const
|
|
479
|
-
|
|
479
|
+
C.className = "ago-message__followups";
|
|
480
|
+
for (const S of e.followUpReplies) {
|
|
481
|
+
const I = document.createElement("button");
|
|
482
|
+
I.type = "button", I.className = "ago-message__followup-btn", I.textContent = S, I.disabled = !Le, E(I, {
|
|
483
|
+
minHeight: "36px",
|
|
480
484
|
padding: "6px 14px",
|
|
481
485
|
fontSize: "14px",
|
|
482
|
-
borderRadius:
|
|
483
|
-
border: `1px solid ${
|
|
484
|
-
backgroundColor:
|
|
485
|
-
color:
|
|
486
|
-
cursor:
|
|
486
|
+
borderRadius: Ee,
|
|
487
|
+
border: `1px solid ${O}`,
|
|
488
|
+
backgroundColor: ee,
|
|
489
|
+
color: de,
|
|
490
|
+
cursor: Le ? "pointer" : "default",
|
|
487
491
|
transition: "border-color 0.15s"
|
|
488
|
-
}),
|
|
489
|
-
|
|
490
|
-
}),
|
|
491
|
-
|
|
492
|
-
}),
|
|
492
|
+
}), Te && I.addEventListener("click", () => Te(S)), I.addEventListener("mouseenter", () => {
|
|
493
|
+
I.style.borderColor = we;
|
|
494
|
+
}), I.addEventListener("mouseleave", () => {
|
|
495
|
+
I.style.borderColor = O;
|
|
496
|
+
}), C.appendChild(I);
|
|
493
497
|
}
|
|
494
|
-
|
|
498
|
+
w.appendChild(C);
|
|
495
499
|
}
|
|
496
|
-
return
|
|
500
|
+
return w;
|
|
497
501
|
}
|
|
498
|
-
function
|
|
499
|
-
const
|
|
502
|
+
function lt(e) {
|
|
503
|
+
const t = x({
|
|
500
504
|
display: "flex",
|
|
501
505
|
alignItems: "center",
|
|
502
506
|
gap: "8px",
|
|
503
507
|
padding: "10px 14px",
|
|
504
508
|
backgroundColor: "#f0fdf4",
|
|
505
509
|
color: "#15803d",
|
|
506
|
-
borderRadius:
|
|
510
|
+
borderRadius: Ee,
|
|
507
511
|
marginTop: "8px",
|
|
508
512
|
fontSize: "13px",
|
|
509
513
|
border: "1px solid #bbf7d0"
|
|
510
514
|
});
|
|
511
|
-
|
|
515
|
+
t.className = "ago-form-notice", t.setAttribute("role", "status");
|
|
512
516
|
const i = document.createElement("span");
|
|
513
|
-
i.textContent = "✓", i.setAttribute("aria-hidden", "true"),
|
|
514
|
-
const
|
|
515
|
-
return
|
|
517
|
+
i.textContent = "✓", i.setAttribute("aria-hidden", "true"), E(i, { fontWeight: "700" });
|
|
518
|
+
const c = document.createElement("span");
|
|
519
|
+
return c.textContent = e, t.append(i, c), t;
|
|
516
520
|
}
|
|
517
|
-
function
|
|
518
|
-
if (
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
521
|
+
function k() {
|
|
522
|
+
if (R.replaceChildren(), l.length === 0) {
|
|
523
|
+
if (Ie === "static") {
|
|
524
|
+
const t = x({
|
|
525
|
+
textAlign: "center",
|
|
526
|
+
color: _t,
|
|
527
|
+
padding: "24px 16px",
|
|
528
|
+
fontSize: "16px",
|
|
529
|
+
lineHeight: "1.5"
|
|
530
|
+
});
|
|
531
|
+
t.appendChild(Re(Ae)), R.appendChild(t);
|
|
532
|
+
}
|
|
533
|
+
} else l.forEach((t, i) => {
|
|
534
|
+
const c = i === l.length - 1 || l[i + 1].role !== t.role;
|
|
535
|
+
R.appendChild(it(t, i === l.length - 1, c));
|
|
530
536
|
});
|
|
531
|
-
for (const
|
|
532
|
-
if (
|
|
533
|
-
const
|
|
537
|
+
for (const t of $e) R.appendChild(lt(t));
|
|
538
|
+
if (J) {
|
|
539
|
+
const t = x({
|
|
534
540
|
padding: "10px 14px",
|
|
535
541
|
backgroundColor: "#fef2f2",
|
|
536
542
|
color: "#dc2626",
|
|
@@ -539,262 +545,304 @@ function $t(r, o) {
|
|
|
539
545
|
fontSize: "13px",
|
|
540
546
|
border: "1px solid #fecaca"
|
|
541
547
|
});
|
|
542
|
-
|
|
548
|
+
t.setAttribute("role", "alert"), t.textContent = J, R.appendChild(t);
|
|
543
549
|
}
|
|
544
|
-
|
|
545
|
-
const e =
|
|
546
|
-
|
|
550
|
+
R.scrollTop = R.scrollHeight;
|
|
551
|
+
const e = l[l.length - 1];
|
|
552
|
+
st(F && e?.role === "assistant" && e.status === "IN_PROGRESS");
|
|
547
553
|
}
|
|
548
|
-
function
|
|
549
|
-
for (let e =
|
|
550
|
-
const
|
|
551
|
-
if (
|
|
554
|
+
function dt() {
|
|
555
|
+
for (let e = l.length - 1; e >= 0; e--) {
|
|
556
|
+
const t = l[e];
|
|
557
|
+
if (t.role === "assistant" && t.status === "IN_PROGRESS") return t;
|
|
552
558
|
}
|
|
553
559
|
}
|
|
554
|
-
const
|
|
555
|
-
|
|
556
|
-
},
|
|
557
|
-
const
|
|
558
|
-
|
|
559
|
-
},
|
|
560
|
-
const
|
|
561
|
-
|
|
562
|
-
},
|
|
563
|
-
const
|
|
564
|
-
|
|
560
|
+
const Oe = (e) => {
|
|
561
|
+
T || (T = e.conversationId);
|
|
562
|
+
}, Be = (e) => {
|
|
563
|
+
const t = dt();
|
|
564
|
+
t && (t.content += e.content, k());
|
|
565
|
+
}, De = (e) => {
|
|
566
|
+
const t = l.findIndex((i) => i.id === e.id || i.role === "assistant" && i.status === "IN_PROGRESS");
|
|
567
|
+
t >= 0 ? l[t] = e : l.push(e), k(), ue();
|
|
568
|
+
}, Me = (e) => {
|
|
569
|
+
const t = l.findIndex((i) => i.id === e.id || i.role === "assistant" && i.status === "IN_PROGRESS");
|
|
570
|
+
t >= 0 ? l[t] = e : l.push(e), F = !1, k(), e.status === "DONE" && D?.({
|
|
565
571
|
id: e.id,
|
|
566
572
|
content: e.content
|
|
567
573
|
});
|
|
568
|
-
},
|
|
569
|
-
|
|
574
|
+
}, He = (e) => {
|
|
575
|
+
J = e.error, F = !1, l = l.filter((t) => !t.id.startsWith("temp-")), k();
|
|
570
576
|
};
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
577
|
+
function ct(e) {
|
|
578
|
+
const t = {
|
|
579
|
+
id: `ago-intro-${Date.now()}`,
|
|
580
|
+
conversationId: "",
|
|
581
|
+
content: "",
|
|
582
|
+
role: "assistant",
|
|
583
|
+
status: "IN_PROGRESS",
|
|
584
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
585
|
+
};
|
|
586
|
+
l.push(t), k();
|
|
587
|
+
const i = e.match(/\S+\s*/g) ?? [e];
|
|
588
|
+
let c = 0;
|
|
589
|
+
M = setInterval(() => {
|
|
590
|
+
if (c >= i.length) {
|
|
591
|
+
clearInterval(M), M = void 0, t.status = "DONE", k();
|
|
592
|
+
return;
|
|
593
|
+
}
|
|
594
|
+
t.content += i[c], c++, k();
|
|
595
|
+
}, nt);
|
|
596
|
+
}
|
|
597
|
+
h.on("message:start", Oe), h.on("message:chunk", Be), h.on("message:answer-complete", De), h.on("message:complete", Me), h.on("message:error", He);
|
|
598
|
+
const Fe = (e) => oe?.(e), ze = (e) => Q?.(e);
|
|
599
|
+
oe && h.on("form:submitted", Fe), Q && h.on("form:error", ze);
|
|
600
|
+
const me = [];
|
|
601
|
+
let Ue = !1;
|
|
602
|
+
const We = (e) => {
|
|
603
|
+
if (Ue) return;
|
|
604
|
+
me.push(e.install(h));
|
|
605
|
+
let t = e.store.get().submitted;
|
|
606
|
+
const i = e.store.subscribe((c) => {
|
|
607
|
+
c.submitted && !t && ($e.push(rt(c.submitResult)), k()), t = c.submitted;
|
|
582
608
|
});
|
|
583
|
-
|
|
609
|
+
me.push(i);
|
|
584
610
|
};
|
|
585
|
-
for (const e of
|
|
611
|
+
for (const e of m ?? []) e.schema != null ? We(bt(e)) : xt(h, e).then((t) => We(t)).catch(() => {
|
|
586
612
|
});
|
|
587
|
-
async function
|
|
613
|
+
async function he(e, t) {
|
|
588
614
|
const i = e.trim();
|
|
589
|
-
if (!i && !
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
615
|
+
if (!i && !t?.length || F) return;
|
|
616
|
+
if (ne?.(i), F = !0, J = null, M) {
|
|
617
|
+
clearInterval(M), M = void 0;
|
|
618
|
+
const f = l.find((w) => w.id.startsWith("ago-intro-"));
|
|
619
|
+
f && !f.content ? l = l.filter((w) => w !== f) : f && (f.status = "DONE");
|
|
620
|
+
}
|
|
621
|
+
const c = Date.now();
|
|
622
|
+
l.push({
|
|
623
|
+
id: `temp-user-${c}`,
|
|
624
|
+
conversationId: T || "",
|
|
595
625
|
content: i,
|
|
596
626
|
role: "user",
|
|
597
627
|
status: "DONE",
|
|
598
628
|
createdAt: /* @__PURE__ */ new Date()
|
|
599
|
-
}),
|
|
600
|
-
id: `temp-assistant-${
|
|
601
|
-
conversationId:
|
|
629
|
+
}), l.push({
|
|
630
|
+
id: `temp-assistant-${c}`,
|
|
631
|
+
conversationId: T || "",
|
|
602
632
|
content: "",
|
|
603
633
|
role: "assistant",
|
|
604
634
|
status: "IN_PROGRESS",
|
|
605
635
|
createdAt: /* @__PURE__ */ new Date()
|
|
606
|
-
}),
|
|
636
|
+
}), k();
|
|
607
637
|
try {
|
|
608
|
-
const
|
|
609
|
-
conversationId:
|
|
610
|
-
files:
|
|
638
|
+
const f = await h.sendMessage(i, {
|
|
639
|
+
conversationId: T,
|
|
640
|
+
files: t
|
|
611
641
|
});
|
|
612
|
-
|
|
613
|
-
const
|
|
614
|
-
if (
|
|
615
|
-
const
|
|
616
|
-
|
|
642
|
+
f.conversationId && (T || (T = f.conversationId), ae?.setActiveThread(f.conversationId, f.createdAt));
|
|
643
|
+
const w = l.find((A) => A.id === `temp-user-${c}`);
|
|
644
|
+
if (w && (w.id = `user-${c}`, w.conversationId = f.conversationId), !l.some((A) => A.id === f.id)) {
|
|
645
|
+
const A = l.findIndex((H) => H.id === `temp-assistant-${c}`);
|
|
646
|
+
A >= 0 ? l[A] = f : l.push(f);
|
|
617
647
|
}
|
|
618
|
-
|
|
619
|
-
} catch (
|
|
620
|
-
|
|
648
|
+
l = l.filter((A) => !A.id.startsWith("temp-")), F = !1, k(), Z && xe();
|
|
649
|
+
} catch (f) {
|
|
650
|
+
J = f instanceof Error ? f.message : "Failed to send message", F = !1, l = l.filter((w) => !w.id.startsWith("temp-")), k();
|
|
621
651
|
}
|
|
622
652
|
}
|
|
623
|
-
async function
|
|
653
|
+
async function xe() {
|
|
624
654
|
try {
|
|
625
|
-
const e = await
|
|
626
|
-
|
|
655
|
+
const e = await h.getConversations();
|
|
656
|
+
se.splice(0, se.length, ...e);
|
|
627
657
|
} catch {
|
|
628
658
|
}
|
|
629
|
-
return
|
|
659
|
+
return se;
|
|
630
660
|
}
|
|
631
|
-
async function
|
|
661
|
+
async function pt(e) {
|
|
632
662
|
try {
|
|
633
|
-
const
|
|
634
|
-
|
|
663
|
+
const t = (await h.getConversation(e))?.messages ?? [];
|
|
664
|
+
t.length > 0 && l.length === 0 && (l = t, k());
|
|
635
665
|
} catch {
|
|
636
|
-
|
|
666
|
+
l.length === 0 && (ae?.clear(), T = void 0);
|
|
637
667
|
}
|
|
638
668
|
}
|
|
639
|
-
return
|
|
640
|
-
client:
|
|
641
|
-
element:
|
|
642
|
-
sendMessage:
|
|
643
|
-
...
|
|
644
|
-
open:
|
|
645
|
-
close:
|
|
646
|
-
toggle:
|
|
669
|
+
return k(), ue(), T ? pt(T) : Ie === "streaming" && ct(Ae), Z && xe(), {
|
|
670
|
+
client: h,
|
|
671
|
+
element: ie,
|
|
672
|
+
sendMessage: he,
|
|
673
|
+
...j ? {
|
|
674
|
+
open: ve,
|
|
675
|
+
close: ye,
|
|
676
|
+
toggle: ft
|
|
647
677
|
} : {},
|
|
648
|
-
session:
|
|
649
|
-
threads:
|
|
650
|
-
refreshThreads:
|
|
678
|
+
session: ae,
|
|
679
|
+
threads: se,
|
|
680
|
+
refreshThreads: xe,
|
|
651
681
|
destroy() {
|
|
652
|
-
|
|
682
|
+
M && clearInterval(M), h.off("message:start", Oe), h.off("message:chunk", Be), h.off("message:answer-complete", De), h.off("message:complete", Me), h.off("message:error", He), oe && h.off("form:submitted", Fe), Q && h.off("form:error", ze), Ue = !0, me.forEach((e) => e()), ie.remove(), _?.remove(), o.client || h.destroy();
|
|
653
683
|
}
|
|
654
684
|
};
|
|
655
|
-
function
|
|
656
|
-
if (!
|
|
657
|
-
const e =
|
|
658
|
-
|
|
685
|
+
function be() {
|
|
686
|
+
if (!U) return;
|
|
687
|
+
const e = p === "left" ? "translateX(-100%)" : "translateX(100%)";
|
|
688
|
+
U.style.transform = X ? "translateX(0)" : e, U.setAttribute("aria-hidden", X ? "false" : "true"), _ && (_.style.display = X ? "none" : "flex");
|
|
659
689
|
}
|
|
660
|
-
function
|
|
661
|
-
|
|
690
|
+
function ve() {
|
|
691
|
+
X = !0, be(), ue();
|
|
662
692
|
}
|
|
663
|
-
function
|
|
664
|
-
|
|
693
|
+
function ye() {
|
|
694
|
+
X = !1, be();
|
|
665
695
|
}
|
|
666
|
-
function
|
|
667
|
-
|
|
696
|
+
function ft() {
|
|
697
|
+
X ? ye() : ve();
|
|
668
698
|
}
|
|
669
|
-
function
|
|
670
|
-
const e = "http://www.w3.org/2000/svg",
|
|
671
|
-
|
|
699
|
+
function ut() {
|
|
700
|
+
const e = "http://www.w3.org/2000/svg", t = document.createElementNS(e, "svg");
|
|
701
|
+
t.setAttribute("width", "26"), t.setAttribute("height", "26"), t.setAttribute("viewBox", "0 0 24 24"), t.setAttribute("fill", "none");
|
|
672
702
|
const i = document.createElementNS(e, "path");
|
|
673
|
-
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"),
|
|
703
|
+
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"), t.appendChild(i), t;
|
|
674
704
|
}
|
|
675
|
-
function
|
|
676
|
-
const e =
|
|
705
|
+
function gt() {
|
|
706
|
+
const e = x({
|
|
677
707
|
display: "flex",
|
|
678
708
|
gap: "4px",
|
|
679
709
|
padding: "4px 0"
|
|
680
710
|
});
|
|
681
|
-
for (let
|
|
682
|
-
const i =
|
|
711
|
+
for (let t = 0; t < 3; t++) {
|
|
712
|
+
const i = x({
|
|
683
713
|
width: "6px",
|
|
684
714
|
height: "6px",
|
|
685
715
|
borderRadius: "50%",
|
|
686
716
|
backgroundColor: "#b5bfc8",
|
|
687
717
|
animation: "ago-pulse 1.2s ease-in-out infinite",
|
|
688
|
-
animationDelay: `${
|
|
718
|
+
animationDelay: `${t * 0.2}s`
|
|
689
719
|
});
|
|
690
720
|
e.appendChild(i);
|
|
691
721
|
}
|
|
692
722
|
return e;
|
|
693
723
|
}
|
|
694
724
|
}
|
|
695
|
-
function
|
|
725
|
+
function Tt(r) {
|
|
696
726
|
let o = [];
|
|
697
727
|
const a = document.createElement("form");
|
|
698
|
-
|
|
728
|
+
E(a, {
|
|
699
729
|
display: "flex",
|
|
700
730
|
flexDirection: "column",
|
|
701
731
|
gap: "8px",
|
|
702
732
|
padding: "12px",
|
|
703
|
-
borderTop: `1px solid ${
|
|
704
|
-
backgroundColor:
|
|
733
|
+
borderTop: `1px solid ${O}`,
|
|
734
|
+
backgroundColor: ee
|
|
705
735
|
}), a.className = "ago-chat-input";
|
|
706
|
-
const
|
|
736
|
+
const n = x({
|
|
707
737
|
display: "flex",
|
|
708
738
|
flexWrap: "wrap",
|
|
709
739
|
gap: "6px"
|
|
710
|
-
}),
|
|
740
|
+
}), u = x({
|
|
711
741
|
display: "flex",
|
|
712
742
|
gap: "8px",
|
|
713
743
|
alignItems: "flex-end"
|
|
714
744
|
}), s = document.createElement("textarea");
|
|
715
|
-
s.placeholder = r.placeholder, s.rows = 1,
|
|
745
|
+
s.placeholder = r.placeholder, s.setAttribute("aria-label", r.placeholder), s.rows = 1, E(s, {
|
|
716
746
|
flex: "1",
|
|
717
747
|
resize: "none",
|
|
748
|
+
boxSizing: "border-box",
|
|
718
749
|
padding: "10px 12px",
|
|
719
|
-
border: `1px solid ${
|
|
750
|
+
border: `1px solid ${O}`,
|
|
720
751
|
borderRadius: "12px",
|
|
721
752
|
fontSize: "16px",
|
|
722
|
-
fontFamily:
|
|
753
|
+
fontFamily: _e,
|
|
723
754
|
lineHeight: "1.4",
|
|
724
|
-
maxHeight: "
|
|
725
|
-
|
|
755
|
+
maxHeight: "110px",
|
|
756
|
+
overflowY: "hidden"
|
|
757
|
+
});
|
|
758
|
+
const v = () => {
|
|
759
|
+
s.style.height = "auto";
|
|
760
|
+
const y = Math.min(s.scrollHeight + 2, 110);
|
|
761
|
+
s.style.height = `${y}px`, s.style.overflowY = s.scrollHeight + 2 > 110 ? "auto" : "hidden";
|
|
762
|
+
};
|
|
763
|
+
s.addEventListener("input", () => {
|
|
764
|
+
v(), B();
|
|
726
765
|
});
|
|
727
|
-
const
|
|
728
|
-
|
|
729
|
-
|
|
766
|
+
const p = '<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>', b = '<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>', d = document.createElement("button");
|
|
767
|
+
d.type = "submit", d.setAttribute("aria-label", "Send"), d.innerHTML = p, E(d, {
|
|
768
|
+
flexShrink: "0",
|
|
769
|
+
width: "40px",
|
|
770
|
+
height: "40px",
|
|
771
|
+
padding: "0",
|
|
730
772
|
border: "none",
|
|
731
|
-
borderRadius: "
|
|
732
|
-
backgroundColor:
|
|
733
|
-
color:
|
|
734
|
-
|
|
735
|
-
|
|
773
|
+
borderRadius: "50%",
|
|
774
|
+
backgroundColor: pe,
|
|
775
|
+
color: ke,
|
|
776
|
+
display: "flex",
|
|
777
|
+
alignItems: "center",
|
|
778
|
+
justifyContent: "center",
|
|
736
779
|
cursor: "pointer"
|
|
737
780
|
});
|
|
738
|
-
let
|
|
739
|
-
|
|
781
|
+
let g = !1;
|
|
782
|
+
const B = () => {
|
|
783
|
+
const m = s.value.trim() !== "" || o.length > 0, y = g || !m;
|
|
784
|
+
d.disabled = y, d.innerHTML = g ? b : p, d.style.opacity = y && !g ? "0.5" : "1", d.style.cursor = y ? "default" : "pointer";
|
|
785
|
+
};
|
|
786
|
+
let $ = null, L = null;
|
|
787
|
+
r.allowFiles && ($ = document.createElement("input"), $.type = "file", $.multiple = !0, E($, { display: "none" }), L = document.createElement("button"), L.type = "button", L.setAttribute("aria-label", "Attach file"), L.textContent = "📎", E(L, {
|
|
740
788
|
padding: "10px 12px",
|
|
741
|
-
border: `1px solid ${
|
|
789
|
+
border: `1px solid ${O}`,
|
|
742
790
|
borderRadius: "12px",
|
|
743
|
-
backgroundColor:
|
|
791
|
+
backgroundColor: ee,
|
|
744
792
|
cursor: "pointer",
|
|
745
793
|
fontSize: "14px"
|
|
746
|
-
}),
|
|
747
|
-
o = [...o, ...Array.from(
|
|
794
|
+
}), L.addEventListener("click", () => $?.click()), $.addEventListener("change", () => {
|
|
795
|
+
o = [...o, ...Array.from($?.files ?? [])], Y();
|
|
748
796
|
}));
|
|
749
|
-
function
|
|
750
|
-
|
|
751
|
-
const
|
|
797
|
+
function Y() {
|
|
798
|
+
n.replaceChildren(), o.forEach((m, y) => {
|
|
799
|
+
const P = x({
|
|
752
800
|
display: "flex",
|
|
753
801
|
alignItems: "center",
|
|
754
802
|
gap: "4px",
|
|
755
803
|
padding: "4px 8px",
|
|
756
804
|
backgroundColor: "#f0f4ff",
|
|
757
|
-
border: `1px solid ${
|
|
805
|
+
border: `1px solid ${O}`,
|
|
758
806
|
borderRadius: "8px",
|
|
759
807
|
fontSize: "12px"
|
|
760
|
-
}),
|
|
761
|
-
|
|
762
|
-
const
|
|
763
|
-
|
|
808
|
+
}), ne = document.createElement("span");
|
|
809
|
+
ne.textContent = m.name;
|
|
810
|
+
const D = document.createElement("button");
|
|
811
|
+
D.type = "button", D.setAttribute("aria-label", `Remove ${m.name}`), D.textContent = "×", E(D, {
|
|
764
812
|
border: "none",
|
|
765
813
|
background: "transparent",
|
|
766
814
|
cursor: "pointer",
|
|
767
815
|
fontSize: "14px",
|
|
768
816
|
lineHeight: "1"
|
|
769
|
-
}),
|
|
770
|
-
o = o.filter((
|
|
771
|
-
}),
|
|
772
|
-
});
|
|
817
|
+
}), D.addEventListener("click", () => {
|
|
818
|
+
o = o.filter((oe, Q) => Q !== y), Y();
|
|
819
|
+
}), P.append(ne, D), n.appendChild(P);
|
|
820
|
+
}), B();
|
|
773
821
|
}
|
|
774
|
-
const
|
|
775
|
-
const
|
|
776
|
-
return s.value = "", o = [],
|
|
777
|
-
content:
|
|
778
|
-
files:
|
|
822
|
+
const te = () => {
|
|
823
|
+
const m = s.value, y = o;
|
|
824
|
+
return s.value = "", v(), o = [], Y(), {
|
|
825
|
+
content: m,
|
|
826
|
+
files: y
|
|
779
827
|
};
|
|
780
|
-
},
|
|
781
|
-
const { content:
|
|
782
|
-
(
|
|
828
|
+
}, Z = () => {
|
|
829
|
+
const { content: m, files: y } = te();
|
|
830
|
+
(m.trim() || y.length > 0) && r.onSend(m.trim(), y.length > 0 ? y : void 0);
|
|
783
831
|
};
|
|
784
|
-
return a.addEventListener("submit", (
|
|
785
|
-
|
|
786
|
-
}), s.addEventListener("keydown", (
|
|
787
|
-
|
|
788
|
-
}),
|
|
832
|
+
return a.addEventListener("submit", (m) => {
|
|
833
|
+
m.preventDefault(), Z();
|
|
834
|
+
}), s.addEventListener("keydown", (m) => {
|
|
835
|
+
m.key === "Enter" && !m.shiftKey && (m.preventDefault(), Z());
|
|
836
|
+
}), L && u.appendChild(L), u.append(s, d), $ && a.appendChild($), a.append(n, u), B(), {
|
|
789
837
|
inputRow: a,
|
|
790
|
-
getValueAndClear:
|
|
791
|
-
setDisabled: (
|
|
792
|
-
s.disabled =
|
|
838
|
+
getValueAndClear: te,
|
|
839
|
+
setDisabled: (m) => {
|
|
840
|
+
s.disabled = m, g = m, B();
|
|
793
841
|
},
|
|
794
842
|
focus: () => s.focus()
|
|
795
843
|
};
|
|
796
844
|
}
|
|
797
845
|
export {
|
|
798
|
-
|
|
799
|
-
|
|
846
|
+
Mt as mountChatWidget,
|
|
847
|
+
Re as renderMarkdown
|
|
800
848
|
};
|