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