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