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