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