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