@useago/sdk 0.4.2 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{createConversationSession-DtaeA418.cjs → createConversationSession-DibXdxoC.cjs} +1 -1
- package/dist/{createConversationSession-D9FesBQS.js → createConversationSession-XkiOGAUT.js} +1 -1
- package/dist/createFormCollector-D4-yZh1i.js +207 -0
- package/dist/createFormCollector-DLwgDX24.cjs +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +15 -3
- package/dist/index.d.ts +15 -3
- package/dist/index.js +59 -58
- package/dist/react.cjs +13 -13
- package/dist/react.d.cts +20 -5
- package/dist/react.d.ts +20 -5
- package/dist/react.js +1031 -1025
- package/dist/widget.cjs +1 -1
- package/dist/widget.d.cts +37 -0
- package/dist/widget.d.ts +37 -0
- package/dist/widget.js +205 -183
- package/package.json +1 -1
- package/dist/createFormCollector-BwvkKi48.js +0 -211
- package/dist/createFormCollector-Wb8Rr-U2.cjs +0 -1
package/dist/widget.js
CHANGED
|
@@ -1,94 +1,116 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import { t as
|
|
3
|
-
import { t as
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { t as ge } from "./AgoClient-rvTz2thR.js";
|
|
2
|
+
import { t as ue } from "./createFormCollector-D4-yZh1i.js";
|
|
3
|
+
import { t as xe } from "./createConversationSession-XkiOGAUT.js";
|
|
4
|
+
var oe = 'var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif)', Z = {
|
|
5
|
+
font: "--ago-font",
|
|
6
|
+
radius: "--ago-radius",
|
|
7
|
+
messageRadius: "--ago-message-radius",
|
|
8
|
+
brand: "--ago-brand-color",
|
|
9
|
+
brandText: "--ago-brand-text-color",
|
|
10
|
+
headerBg: "--ago-header-background",
|
|
11
|
+
headerText: "--ago-header-text-color",
|
|
12
|
+
panelBg: "--ago-panel-background",
|
|
13
|
+
messagesBg: "--ago-messages-background",
|
|
14
|
+
text: "--ago-text-color",
|
|
15
|
+
mutedText: "--ago-muted-text-color",
|
|
16
|
+
border: "--ago-border-color",
|
|
17
|
+
accent: "--ago-accent-color"
|
|
18
|
+
}, ne = "var(--ago-brand-color, #03182f)", re = "var(--ago-brand-text-color, #fff)", me = "var(--ago-header-background, var(--ago-brand-color, #03182f))", he = "var(--ago-header-text-color, #e8f0fe)", L = "var(--ago-panel-background, #fff)", be = "var(--ago-messages-background, #fbfbfb)", H = "var(--ago-text-color, #30373e)", ve = "var(--ago-muted-text-color, #6b6d6f)", E = "var(--ago-border-color, #dee3e8)", K = "var(--ago-accent-color, #1b5fc4)", Ce = "var(--ago-radius, 16px)", ee = "var(--ago-message-radius, 16px)";
|
|
19
|
+
function ye(i, o) {
|
|
20
|
+
if (o)
|
|
21
|
+
for (const g of Object.keys(Z)) {
|
|
22
|
+
const w = o[g];
|
|
23
|
+
w != null && i.style.setProperty(Z[g], w);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function m(i, o) {
|
|
27
|
+
Object.assign(i.style, o);
|
|
7
28
|
}
|
|
8
|
-
function c(
|
|
9
|
-
const
|
|
10
|
-
return
|
|
29
|
+
function c(i = {}) {
|
|
30
|
+
const o = document.createElement("div");
|
|
31
|
+
return m(o, i), o;
|
|
11
32
|
}
|
|
12
|
-
var
|
|
13
|
-
function
|
|
14
|
-
if (typeof document > "u" || document.getElementById(
|
|
15
|
-
const
|
|
16
|
-
|
|
33
|
+
var te = "ago-chat-widget-keyframes";
|
|
34
|
+
function Ee() {
|
|
35
|
+
if (typeof document > "u" || document.getElementById(te)) return;
|
|
36
|
+
const i = document.createElement("style");
|
|
37
|
+
i.id = te, i.textContent = "@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }", document.head.appendChild(i);
|
|
17
38
|
}
|
|
18
|
-
function
|
|
19
|
-
const
|
|
20
|
-
if (!
|
|
21
|
-
return
|
|
39
|
+
function we(i) {
|
|
40
|
+
const o = typeof i == "string" ? document.querySelector(i) : i;
|
|
41
|
+
if (!o) throw new Error(`mountChatWidget: target "${String(i)}" not found.`);
|
|
42
|
+
return o;
|
|
22
43
|
}
|
|
23
|
-
function
|
|
24
|
-
const { title:
|
|
25
|
-
if (!
|
|
26
|
-
const l =
|
|
27
|
-
let
|
|
28
|
-
const
|
|
44
|
+
function Ie(i, o) {
|
|
45
|
+
const { title: g = "Chat", welcomeMessage: w = "Hello! How can I help you today?", placeholder: O = "Type a message...", allowFiles: u = !1, height: x = 500, logoUrl: f, showAgentName: v = !1, theme: T, loadThreads: D = !1, forms: B, onFollowUpClick: s, onMessageSent: C, onMessageReceived: $ } = o;
|
|
46
|
+
if (!o.client && !o.config?.baseUrl) throw new Error("mountChatWidget requires either `client` or `config` (with a baseUrl).");
|
|
47
|
+
const l = o.client ?? new ge(o.config), k = we(i), U = o.persistConversation, I = U ? xe(U === !0 ? {} : U) : void 0;
|
|
48
|
+
let h = o.conversationId ?? I?.getLastActiveThread() ?? void 0, n = [], _ = !1, N = null;
|
|
49
|
+
const M = [], A = c({
|
|
29
50
|
display: "flex",
|
|
30
51
|
flexDirection: "column",
|
|
31
|
-
height: typeof
|
|
32
|
-
border:
|
|
33
|
-
borderRadius:
|
|
52
|
+
height: typeof x == "number" ? `${x}px` : x,
|
|
53
|
+
border: `1px solid ${E}`,
|
|
54
|
+
borderRadius: Ce,
|
|
34
55
|
overflow: "hidden",
|
|
35
|
-
backgroundColor:
|
|
36
|
-
fontFamily:
|
|
56
|
+
backgroundColor: L,
|
|
57
|
+
fontFamily: oe,
|
|
58
|
+
textAlign: "left",
|
|
37
59
|
boxShadow: "rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"
|
|
38
60
|
});
|
|
39
|
-
|
|
40
|
-
const
|
|
61
|
+
A.className = "ago-chat-widget", ye(A, T);
|
|
62
|
+
const z = c({
|
|
41
63
|
padding: "14px 16px",
|
|
42
|
-
borderBottom:
|
|
43
|
-
backgroundColor:
|
|
44
|
-
color:
|
|
64
|
+
borderBottom: `1px solid ${E}`,
|
|
65
|
+
backgroundColor: me,
|
|
66
|
+
color: he,
|
|
45
67
|
display: "flex",
|
|
46
68
|
alignItems: "center",
|
|
47
69
|
gap: "10px"
|
|
48
70
|
});
|
|
49
|
-
if (
|
|
71
|
+
if (z.className = "ago-chat-widget__header", f) {
|
|
50
72
|
const e = document.createElement("img");
|
|
51
|
-
e.src = f, e.alt = "Logo",
|
|
73
|
+
e.src = f, e.alt = "Logo", m(e, {
|
|
52
74
|
height: "24px",
|
|
53
75
|
width: "auto"
|
|
54
|
-
}),
|
|
76
|
+
}), z.appendChild(e);
|
|
55
77
|
}
|
|
56
|
-
const
|
|
57
|
-
|
|
78
|
+
const W = document.createElement("h3");
|
|
79
|
+
W.textContent = g, m(W, {
|
|
58
80
|
margin: "0",
|
|
59
81
|
fontSize: "15px",
|
|
60
82
|
fontWeight: "600"
|
|
61
|
-
}),
|
|
62
|
-
const
|
|
83
|
+
}), z.appendChild(W);
|
|
84
|
+
const R = c({
|
|
63
85
|
flex: "1",
|
|
64
86
|
overflow: "auto",
|
|
65
87
|
padding: "16px",
|
|
66
|
-
backgroundColor:
|
|
88
|
+
backgroundColor: be
|
|
67
89
|
});
|
|
68
|
-
|
|
69
|
-
const { inputRow:
|
|
70
|
-
placeholder:
|
|
71
|
-
allowFiles:
|
|
90
|
+
R.className = "ago-chat-widget__messages";
|
|
91
|
+
const { inputRow: ae, setDisabled: se, focus: ie } = Re({
|
|
92
|
+
placeholder: O,
|
|
93
|
+
allowFiles: u,
|
|
72
94
|
onSend: (e, t) => {
|
|
73
|
-
|
|
95
|
+
F(e, t);
|
|
74
96
|
}
|
|
75
97
|
});
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
98
|
+
Ee(), A.append(z, R, ae), k.appendChild(A);
|
|
99
|
+
const X = s !== !1, j = s === !1 ? void 0 : s ?? ((e) => {
|
|
100
|
+
F(e);
|
|
79
101
|
});
|
|
80
|
-
function
|
|
102
|
+
function le(e) {
|
|
81
103
|
const t = e.role === "user", d = c({
|
|
82
104
|
display: "flex",
|
|
83
105
|
flexDirection: "column",
|
|
84
106
|
alignItems: t ? "flex-end" : "flex-start",
|
|
85
107
|
marginBottom: "16px"
|
|
86
108
|
});
|
|
87
|
-
if (d.className = `ago-message ago-message--${e.role}`, !t &&
|
|
109
|
+
if (d.className = `ago-message ago-message--${e.role}`, !t && v && e.agent) {
|
|
88
110
|
const r = c({
|
|
89
111
|
fontSize: "13px",
|
|
90
112
|
fontWeight: "500",
|
|
91
|
-
color:
|
|
113
|
+
color: H,
|
|
92
114
|
marginBottom: "6px",
|
|
93
115
|
padding: "0 4px"
|
|
94
116
|
});
|
|
@@ -104,27 +126,27 @@ function ue(s, n) {
|
|
|
104
126
|
maxWidth: "85%"
|
|
105
127
|
});
|
|
106
128
|
r.className = "ago-message__sources", e.sources.forEach((p, a) => {
|
|
107
|
-
const
|
|
108
|
-
p.url &&
|
|
129
|
+
const y = p.url ? document.createElement("a") : document.createElement("div");
|
|
130
|
+
p.url && y instanceof HTMLAnchorElement && (y.href = p.url, y.target = "_blank", y.rel = "noopener noreferrer"), m(y, {
|
|
109
131
|
display: "flex",
|
|
110
132
|
alignItems: "center",
|
|
111
133
|
gap: "8px",
|
|
112
134
|
padding: "8px 10px",
|
|
113
|
-
border:
|
|
135
|
+
border: `1px solid ${E}`,
|
|
114
136
|
borderRadius: "8px",
|
|
115
|
-
backgroundColor:
|
|
137
|
+
backgroundColor: L,
|
|
116
138
|
textDecoration: "none",
|
|
117
|
-
color:
|
|
139
|
+
color: H,
|
|
118
140
|
fontSize: "12px",
|
|
119
141
|
overflow: "hidden"
|
|
120
142
|
});
|
|
121
|
-
const
|
|
143
|
+
const Q = c({
|
|
122
144
|
flexShrink: "0",
|
|
123
145
|
width: "18px",
|
|
124
146
|
height: "18px",
|
|
125
147
|
borderRadius: "3px",
|
|
126
|
-
border:
|
|
127
|
-
color:
|
|
148
|
+
border: `1px solid ${K}`,
|
|
149
|
+
color: K,
|
|
128
150
|
fontSize: "11px",
|
|
129
151
|
fontWeight: "500",
|
|
130
152
|
display: "flex",
|
|
@@ -132,27 +154,27 @@ function ue(s, n) {
|
|
|
132
154
|
justifyContent: "center",
|
|
133
155
|
backgroundColor: "#f0f4ff"
|
|
134
156
|
});
|
|
135
|
-
|
|
136
|
-
const
|
|
157
|
+
Q.textContent = String(a + 1);
|
|
158
|
+
const P = c({
|
|
137
159
|
overflow: "hidden",
|
|
138
160
|
textOverflow: "ellipsis",
|
|
139
161
|
whiteSpace: "nowrap"
|
|
140
162
|
});
|
|
141
|
-
|
|
163
|
+
P.textContent = p.title, P.title = p.title, y.append(Q, P), r.appendChild(y);
|
|
142
164
|
}), d.appendChild(r);
|
|
143
165
|
}
|
|
144
|
-
const
|
|
166
|
+
const b = c({
|
|
145
167
|
maxWidth: t ? "75%" : "100%",
|
|
146
168
|
padding: t ? "10px 14px" : "2px 8px",
|
|
147
|
-
borderRadius: t ?
|
|
148
|
-
backgroundColor: t ?
|
|
149
|
-
color: t ?
|
|
169
|
+
borderRadius: t ? ee : "0",
|
|
170
|
+
backgroundColor: t ? ne : "transparent",
|
|
171
|
+
color: t ? re : H,
|
|
150
172
|
wordBreak: "break-word",
|
|
151
173
|
fontSize: "14px",
|
|
152
174
|
lineHeight: "1.6",
|
|
153
175
|
whiteSpace: "pre-wrap"
|
|
154
176
|
});
|
|
155
|
-
if (
|
|
177
|
+
if (b.className = "ago-message__content", e.content ? b.textContent = e.content : e.status === "IN_PROGRESS" && b.appendChild(fe()), d.appendChild(b), e.followUpReplies && e.followUpReplies.length > 0) {
|
|
156
178
|
const r = c({
|
|
157
179
|
display: "flex",
|
|
158
180
|
flexWrap: "wrap",
|
|
@@ -162,19 +184,19 @@ function ue(s, n) {
|
|
|
162
184
|
r.className = "ago-message__followups";
|
|
163
185
|
for (const p of e.followUpReplies) {
|
|
164
186
|
const a = document.createElement("button");
|
|
165
|
-
a.type = "button", a.className = "ago-message__followup-btn", a.textContent = p, a.disabled = !
|
|
187
|
+
a.type = "button", a.className = "ago-message__followup-btn", a.textContent = p, a.disabled = !X, m(a, {
|
|
166
188
|
padding: "6px 14px",
|
|
167
189
|
fontSize: "13px",
|
|
168
|
-
borderRadius:
|
|
169
|
-
border:
|
|
170
|
-
backgroundColor:
|
|
171
|
-
color:
|
|
172
|
-
cursor:
|
|
190
|
+
borderRadius: ee,
|
|
191
|
+
border: `1px solid ${E}`,
|
|
192
|
+
backgroundColor: L,
|
|
193
|
+
color: H,
|
|
194
|
+
cursor: X ? "pointer" : "default",
|
|
173
195
|
transition: "border-color 0.15s"
|
|
174
|
-
}),
|
|
175
|
-
a.style.borderColor =
|
|
196
|
+
}), j && a.addEventListener("click", () => j(p)), a.addEventListener("mouseenter", () => {
|
|
197
|
+
a.style.borderColor = K;
|
|
176
198
|
}), a.addEventListener("mouseleave", () => {
|
|
177
|
-
a.style.borderColor =
|
|
199
|
+
a.style.borderColor = E;
|
|
178
200
|
}), r.appendChild(a);
|
|
179
201
|
}
|
|
180
202
|
d.appendChild(r);
|
|
@@ -182,17 +204,17 @@ function ue(s, n) {
|
|
|
182
204
|
return d;
|
|
183
205
|
}
|
|
184
206
|
function S() {
|
|
185
|
-
if (
|
|
207
|
+
if (R.replaceChildren(), n.length === 0) {
|
|
186
208
|
const e = c({
|
|
187
209
|
textAlign: "center",
|
|
188
|
-
color:
|
|
210
|
+
color: ve,
|
|
189
211
|
padding: "24px 16px",
|
|
190
212
|
fontSize: "14px",
|
|
191
213
|
lineHeight: "1.5"
|
|
192
214
|
});
|
|
193
|
-
e.textContent =
|
|
194
|
-
} else for (const e of
|
|
195
|
-
if (
|
|
215
|
+
e.textContent = w, R.appendChild(e);
|
|
216
|
+
} else for (const e of n) R.appendChild(le(e));
|
|
217
|
+
if (N) {
|
|
196
218
|
const e = c({
|
|
197
219
|
padding: "10px 14px",
|
|
198
220
|
backgroundColor: "#fef2f2",
|
|
@@ -202,47 +224,47 @@ function ue(s, n) {
|
|
|
202
224
|
fontSize: "13px",
|
|
203
225
|
border: "1px solid #fecaca"
|
|
204
226
|
});
|
|
205
|
-
e.textContent =
|
|
227
|
+
e.textContent = N, R.appendChild(e);
|
|
206
228
|
}
|
|
207
|
-
|
|
229
|
+
R.scrollTop = R.scrollHeight, se(_);
|
|
208
230
|
}
|
|
209
|
-
function
|
|
210
|
-
for (let e =
|
|
211
|
-
const t =
|
|
231
|
+
function de() {
|
|
232
|
+
for (let e = n.length - 1; e >= 0; e--) {
|
|
233
|
+
const t = n[e];
|
|
212
234
|
if (t.role === "assistant" && t.status === "IN_PROGRESS") return t;
|
|
213
235
|
}
|
|
214
236
|
}
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
},
|
|
218
|
-
const t =
|
|
237
|
+
const V = (e) => {
|
|
238
|
+
h || (h = e.conversationId);
|
|
239
|
+
}, q = (e) => {
|
|
240
|
+
const t = de();
|
|
219
241
|
t && (t.content += e.content, S());
|
|
220
|
-
},
|
|
221
|
-
const t =
|
|
222
|
-
t >= 0 ?
|
|
242
|
+
}, Y = (e) => {
|
|
243
|
+
const t = n.findIndex((d) => d.id === e.id || d.role === "assistant" && d.status === "IN_PROGRESS");
|
|
244
|
+
t >= 0 ? n[t] = e : n.push(e), _ = !1, S(), e.status === "DONE" && $?.({
|
|
223
245
|
id: e.id,
|
|
224
246
|
content: e.content
|
|
225
247
|
});
|
|
226
|
-
},
|
|
227
|
-
|
|
248
|
+
}, J = (e) => {
|
|
249
|
+
N = e.error, _ = !1, n = n.filter((t) => !t.id.startsWith("temp-")), S();
|
|
228
250
|
};
|
|
229
|
-
l.on("message:start",
|
|
230
|
-
const
|
|
231
|
-
async function
|
|
251
|
+
l.on("message:start", V), l.on("message:chunk", q), l.on("message:complete", Y), l.on("message:error", J);
|
|
252
|
+
const ce = (B ?? []).map((e) => ue(e).install(l));
|
|
253
|
+
async function F(e, t) {
|
|
232
254
|
const d = e.trim();
|
|
233
|
-
if (!d && !t?.length ||
|
|
234
|
-
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
id: `temp-user-${
|
|
238
|
-
conversationId:
|
|
255
|
+
if (!d && !t?.length || _) return;
|
|
256
|
+
C?.(d), _ = !0, N = null;
|
|
257
|
+
const b = Date.now();
|
|
258
|
+
n.push({
|
|
259
|
+
id: `temp-user-${b}`,
|
|
260
|
+
conversationId: h || "",
|
|
239
261
|
content: d,
|
|
240
262
|
role: "user",
|
|
241
263
|
status: "DONE",
|
|
242
264
|
createdAt: /* @__PURE__ */ new Date()
|
|
243
|
-
}),
|
|
244
|
-
id: `temp-assistant-${
|
|
245
|
-
conversationId:
|
|
265
|
+
}), n.push({
|
|
266
|
+
id: `temp-assistant-${b}`,
|
|
267
|
+
conversationId: h || "",
|
|
246
268
|
content: "",
|
|
247
269
|
role: "assistant",
|
|
248
270
|
status: "IN_PROGRESS",
|
|
@@ -250,48 +272,48 @@ function ue(s, n) {
|
|
|
250
272
|
}), S();
|
|
251
273
|
try {
|
|
252
274
|
const r = await l.sendMessage(d, {
|
|
253
|
-
conversationId:
|
|
275
|
+
conversationId: h,
|
|
254
276
|
files: t
|
|
255
277
|
});
|
|
256
|
-
r.conversationId && (
|
|
257
|
-
const p =
|
|
258
|
-
if (p && (p.id = `user-${
|
|
259
|
-
const a =
|
|
260
|
-
a >= 0 ?
|
|
278
|
+
r.conversationId && (h || (h = r.conversationId), I?.setActiveThread(r.conversationId, r.createdAt));
|
|
279
|
+
const p = n.find((a) => a.id === `temp-user-${b}`);
|
|
280
|
+
if (p && (p.id = `user-${b}`, p.conversationId = r.conversationId), !n.some((a) => a.id === r.id)) {
|
|
281
|
+
const a = n.findIndex((y) => y.id === `temp-assistant-${b}`);
|
|
282
|
+
a >= 0 ? n[a] = r : n.push(r);
|
|
261
283
|
}
|
|
262
|
-
|
|
284
|
+
n = n.filter((a) => !a.id.startsWith("temp-")), _ = !1, S(), D && G();
|
|
263
285
|
} catch (r) {
|
|
264
|
-
|
|
286
|
+
N = r instanceof Error ? r.message : "Failed to send message", _ = !1, n = n.filter((p) => !p.id.startsWith("temp-")), S();
|
|
265
287
|
}
|
|
266
288
|
}
|
|
267
|
-
async function
|
|
289
|
+
async function G() {
|
|
268
290
|
try {
|
|
269
291
|
const e = await l.getConversations();
|
|
270
|
-
|
|
292
|
+
M.splice(0, M.length, ...e);
|
|
271
293
|
} catch {
|
|
272
294
|
}
|
|
273
|
-
return
|
|
295
|
+
return M;
|
|
274
296
|
}
|
|
275
|
-
async function
|
|
297
|
+
async function pe(e) {
|
|
276
298
|
try {
|
|
277
299
|
const t = (await l.getConversation(e))?.messages ?? [];
|
|
278
|
-
t.length > 0 &&
|
|
300
|
+
t.length > 0 && n.length === 0 && (n = t, S());
|
|
279
301
|
} catch {
|
|
280
|
-
|
|
302
|
+
n.length === 0 && (I?.clear(), h = void 0);
|
|
281
303
|
}
|
|
282
304
|
}
|
|
283
|
-
return S(),
|
|
305
|
+
return S(), ie(), h && pe(h), D && G(), {
|
|
284
306
|
client: l,
|
|
285
|
-
element:
|
|
286
|
-
sendMessage:
|
|
287
|
-
session:
|
|
288
|
-
threads:
|
|
289
|
-
refreshThreads:
|
|
307
|
+
element: A,
|
|
308
|
+
sendMessage: F,
|
|
309
|
+
session: I,
|
|
310
|
+
threads: M,
|
|
311
|
+
refreshThreads: G,
|
|
290
312
|
destroy() {
|
|
291
|
-
l.off("message:start",
|
|
313
|
+
l.off("message:start", V), l.off("message:chunk", q), l.off("message:complete", Y), l.off("message:error", J), ce.forEach((e) => e()), A.remove(), o.client || l.destroy();
|
|
292
314
|
}
|
|
293
315
|
};
|
|
294
|
-
function
|
|
316
|
+
function fe() {
|
|
295
317
|
const e = c({
|
|
296
318
|
display: "flex",
|
|
297
319
|
gap: "4px",
|
|
@@ -311,108 +333,108 @@ function ue(s, n) {
|
|
|
311
333
|
return e;
|
|
312
334
|
}
|
|
313
335
|
}
|
|
314
|
-
function
|
|
315
|
-
let
|
|
316
|
-
const
|
|
317
|
-
|
|
336
|
+
function Re(i) {
|
|
337
|
+
let o = [];
|
|
338
|
+
const g = document.createElement("form");
|
|
339
|
+
m(g, {
|
|
318
340
|
display: "flex",
|
|
319
341
|
flexDirection: "column",
|
|
320
342
|
gap: "8px",
|
|
321
343
|
padding: "12px",
|
|
322
|
-
borderTop:
|
|
323
|
-
backgroundColor:
|
|
324
|
-
}),
|
|
325
|
-
const
|
|
344
|
+
borderTop: `1px solid ${E}`,
|
|
345
|
+
backgroundColor: L
|
|
346
|
+
}), g.className = "ago-chat-input";
|
|
347
|
+
const w = c({
|
|
326
348
|
display: "flex",
|
|
327
349
|
flexWrap: "wrap",
|
|
328
350
|
gap: "6px"
|
|
329
|
-
}),
|
|
351
|
+
}), O = c({
|
|
330
352
|
display: "flex",
|
|
331
353
|
gap: "8px",
|
|
332
354
|
alignItems: "flex-end"
|
|
333
|
-
}),
|
|
334
|
-
|
|
355
|
+
}), u = document.createElement("textarea");
|
|
356
|
+
u.placeholder = i.placeholder, u.rows = 1, m(u, {
|
|
335
357
|
flex: "1",
|
|
336
358
|
resize: "none",
|
|
337
359
|
padding: "10px 12px",
|
|
338
|
-
border:
|
|
360
|
+
border: `1px solid ${E}`,
|
|
339
361
|
borderRadius: "12px",
|
|
340
362
|
fontSize: "14px",
|
|
341
|
-
fontFamily:
|
|
363
|
+
fontFamily: oe,
|
|
342
364
|
lineHeight: "1.4",
|
|
343
365
|
maxHeight: "120px",
|
|
344
366
|
outline: "none"
|
|
345
367
|
});
|
|
346
|
-
const
|
|
347
|
-
|
|
368
|
+
const x = document.createElement("button");
|
|
369
|
+
x.type = "submit", x.textContent = "Send", m(x, {
|
|
348
370
|
padding: "10px 16px",
|
|
349
371
|
border: "none",
|
|
350
372
|
borderRadius: "12px",
|
|
351
|
-
backgroundColor:
|
|
352
|
-
color:
|
|
373
|
+
backgroundColor: ne,
|
|
374
|
+
color: re,
|
|
353
375
|
fontSize: "14px",
|
|
354
376
|
fontWeight: "500",
|
|
355
377
|
cursor: "pointer"
|
|
356
378
|
});
|
|
357
|
-
let f = null,
|
|
358
|
-
|
|
379
|
+
let f = null, v = null;
|
|
380
|
+
i.allowFiles && (f = document.createElement("input"), f.type = "file", f.multiple = !0, m(f, { display: "none" }), v = document.createElement("button"), v.type = "button", v.textContent = "📎", m(v, {
|
|
359
381
|
padding: "10px 12px",
|
|
360
|
-
border:
|
|
382
|
+
border: `1px solid ${E}`,
|
|
361
383
|
borderRadius: "12px",
|
|
362
|
-
backgroundColor:
|
|
384
|
+
backgroundColor: L,
|
|
363
385
|
cursor: "pointer",
|
|
364
386
|
fontSize: "14px"
|
|
365
|
-
}),
|
|
366
|
-
|
|
387
|
+
}), v.addEventListener("click", () => f?.click()), f.addEventListener("change", () => {
|
|
388
|
+
o = [...o, ...Array.from(f?.files ?? [])], T();
|
|
367
389
|
}));
|
|
368
|
-
function
|
|
369
|
-
|
|
370
|
-
const
|
|
390
|
+
function T() {
|
|
391
|
+
w.replaceChildren(), o.forEach((s, C) => {
|
|
392
|
+
const $ = c({
|
|
371
393
|
display: "flex",
|
|
372
394
|
alignItems: "center",
|
|
373
395
|
gap: "4px",
|
|
374
396
|
padding: "4px 8px",
|
|
375
397
|
backgroundColor: "#f0f4ff",
|
|
376
|
-
border:
|
|
398
|
+
border: `1px solid ${E}`,
|
|
377
399
|
borderRadius: "8px",
|
|
378
400
|
fontSize: "12px"
|
|
379
|
-
}),
|
|
380
|
-
|
|
381
|
-
const
|
|
382
|
-
|
|
401
|
+
}), l = document.createElement("span");
|
|
402
|
+
l.textContent = s.name;
|
|
403
|
+
const k = document.createElement("button");
|
|
404
|
+
k.type = "button", k.textContent = "×", m(k, {
|
|
383
405
|
border: "none",
|
|
384
406
|
background: "transparent",
|
|
385
407
|
cursor: "pointer",
|
|
386
408
|
fontSize: "14px",
|
|
387
409
|
lineHeight: "1"
|
|
388
|
-
}),
|
|
389
|
-
|
|
390
|
-
}),
|
|
410
|
+
}), k.addEventListener("click", () => {
|
|
411
|
+
o = o.filter((U, I) => I !== C), T();
|
|
412
|
+
}), $.append(l, k), w.appendChild($);
|
|
391
413
|
});
|
|
392
414
|
}
|
|
393
|
-
const
|
|
394
|
-
const
|
|
395
|
-
return
|
|
396
|
-
content:
|
|
415
|
+
const D = () => {
|
|
416
|
+
const s = u.value, C = o;
|
|
417
|
+
return u.value = "", o = [], T(), {
|
|
418
|
+
content: s,
|
|
397
419
|
files: C
|
|
398
420
|
};
|
|
399
|
-
},
|
|
400
|
-
const { content:
|
|
401
|
-
(
|
|
421
|
+
}, B = () => {
|
|
422
|
+
const { content: s, files: C } = D();
|
|
423
|
+
(s.trim() || C.length > 0) && i.onSend(s.trim(), C.length > 0 ? C : void 0);
|
|
402
424
|
};
|
|
403
|
-
return
|
|
404
|
-
|
|
405
|
-
}),
|
|
406
|
-
|
|
407
|
-
}),
|
|
408
|
-
inputRow:
|
|
409
|
-
getValueAndClear:
|
|
410
|
-
setDisabled: (
|
|
411
|
-
|
|
425
|
+
return g.addEventListener("submit", (s) => {
|
|
426
|
+
s.preventDefault(), B();
|
|
427
|
+
}), u.addEventListener("keydown", (s) => {
|
|
428
|
+
s.key === "Enter" && !s.shiftKey && (s.preventDefault(), B());
|
|
429
|
+
}), v && O.appendChild(v), O.append(u, x), f && g.appendChild(f), g.append(w, O), {
|
|
430
|
+
inputRow: g,
|
|
431
|
+
getValueAndClear: D,
|
|
432
|
+
setDisabled: (s) => {
|
|
433
|
+
u.disabled = s, x.disabled = s, x.style.opacity = s ? "0.6" : "1", x.style.cursor = s ? "not-allowed" : "pointer";
|
|
412
434
|
},
|
|
413
|
-
focus: () =>
|
|
435
|
+
focus: () => u.focus()
|
|
414
436
|
};
|
|
415
437
|
}
|
|
416
438
|
export {
|
|
417
|
-
|
|
439
|
+
Ie as mountChatWidget
|
|
418
440
|
};
|