@useago/sdk 0.3.2 → 0.3.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/AgoClient-DF7M2WAz.js +575 -0
- package/dist/AgoClient-bjN-z2ZQ.cjs +6 -0
- package/dist/angular.cjs +1 -143
- package/dist/angular.d.cts +530 -0
- package/dist/angular.d.ts +530 -2
- package/dist/angular.js +71 -139
- package/dist/createFormCollector-ClzHfaBd.js +185 -0
- package/dist/createFormCollector-H4Me_2uj.cjs +1 -0
- package/dist/createMockClient-C50gjV0b.js +71 -0
- package/dist/createMockClient-DQvFFWnc.cjs +1 -0
- package/dist/devtools.cjs +26 -100
- package/dist/devtools.d.cts +443 -0
- package/dist/devtools.d.ts +443 -2
- package/dist/devtools.js +68 -93
- package/dist/functions-BH1X5kas.cjs +1 -0
- package/dist/functions-CWSRi3xv.js +312 -0
- package/dist/helpers.cjs +1 -15
- package/dist/{helpers/functions.d.ts → helpers.d.cts} +121 -62
- package/dist/helpers.d.ts +121 -2
- package/dist/helpers.js +16 -2
- package/dist/index.cjs +1 -347
- package/dist/index.d.cts +1150 -0
- package/dist/index.d.ts +1150 -20
- package/dist/index.js +129 -298
- package/dist/react.cjs +31 -22438
- package/dist/react.d.cts +999 -0
- package/dist/react.d.ts +999 -2
- package/dist/react.js +8416 -22376
- package/dist/rolldown-runtime-CaekUdDJ.cjs +1 -0
- package/dist/rolldown-runtime-DxmricAu.js +25 -0
- package/dist/vue.cjs +1 -336
- package/dist/vue.d.cts +1063 -0
- package/dist/vue.d.ts +1063 -2
- package/dist/vue.js +174 -316
- package/dist/widget.cjs +1 -0
- package/dist/widget.d.cts +577 -0
- package/dist/widget.d.ts +577 -2
- package/dist/widget.js +398 -0
- package/package.json +35 -24
- package/dist/AgoClient-DPZdN5n2.js +0 -905
- package/dist/AgoClient-DPZdN5n2.js.map +0 -1
- package/dist/AgoClient-wMVUQqCD.cjs +0 -976
- package/dist/AgoClient-wMVUQqCD.cjs.map +0 -1
- package/dist/angular/ago.service.d.ts +0 -98
- package/dist/angular/index.d.ts +0 -4
- package/dist/angular/provide.d.ts +0 -27
- package/dist/angular.cjs.map +0 -1
- package/dist/angular.js.map +0 -1
- package/dist/api/HttpClient.d.ts +0 -31
- package/dist/api/index.d.ts +0 -1
- package/dist/auto/createAgo.d.ts +0 -39
- package/dist/auto/index.d.ts +0 -1
- package/dist/client/AgoClient.d.ts +0 -169
- package/dist/client/errors.d.ts +0 -48
- package/dist/client/index.d.ts +0 -3
- package/dist/client/types.d.ts +0 -205
- package/dist/createMockClient-Ci_N2tH8.cjs +0 -104
- package/dist/createMockClient-Ci_N2tH8.cjs.map +0 -1
- package/dist/createMockClient-U0ae_AYy.js +0 -99
- package/dist/createMockClient-U0ae_AYy.js.map +0 -1
- package/dist/devtools/index.d.ts +0 -2
- package/dist/devtools/initDevPanel.d.ts +0 -15
- package/dist/devtools.cjs.map +0 -1
- package/dist/devtools.js.map +0 -1
- package/dist/functions/FunctionRegistry.d.ts +0 -41
- package/dist/functions/defineFunction.d.ts +0 -22
- package/dist/functions/index.d.ts +0 -2
- package/dist/functions/types.d.ts +0 -50
- package/dist/functions--c6lx3ic.cjs +0 -480
- package/dist/functions--c6lx3ic.cjs.map +0 -1
- package/dist/functions-C9F1dnmh.js +0 -398
- package/dist/functions-C9F1dnmh.js.map +0 -1
- package/dist/helpers/factory.d.ts +0 -20
- package/dist/helpers/index.d.ts +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/react/components/ChatInput.d.ts +0 -12
- package/dist/react/components/ChatWidget.d.ts +0 -35
- package/dist/react/components/Markdown.d.ts +0 -12
- package/dist/react/components/Message.d.ts +0 -9
- package/dist/react/components/index.d.ts +0 -8
- package/dist/react/context/AgoContext.d.ts +0 -62
- package/dist/react/context/index.d.ts +0 -2
- package/dist/react/hooks/index.d.ts +0 -7
- package/dist/react/hooks/useAgo.d.ts +0 -14
- package/dist/react/hooks/useAgoContext.d.ts +0 -40
- package/dist/react/hooks/useAgoFunction.d.ts +0 -58
- package/dist/react/hooks/useAgoStore.d.ts +0 -17
- package/dist/react/hooks/useChat.d.ts +0 -45
- package/dist/react/hooks/useConversation.d.ts +0 -28
- package/dist/react/hooks/useMessages.d.ts +0 -26
- package/dist/react/index.d.ts +0 -24
- package/dist/react/testing.d.ts +0 -2
- package/dist/react.cjs.map +0 -1
- package/dist/react.js.map +0 -1
- package/dist/rolldown-runtime-BqCkTl7Q.cjs +0 -50
- package/dist/rolldown-runtime-CNZpIYwj.js +0 -33
- package/dist/state/ClientContextRegistry.d.ts +0 -64
- package/dist/state/createStore.d.ts +0 -30
- package/dist/streaming/SSEHandler.d.ts +0 -46
- package/dist/streaming/helpers.d.ts +0 -67
- package/dist/streaming/index.d.ts +0 -2
- package/dist/testing/createMockClient.d.ts +0 -42
- package/dist/testing/index.d.ts +0 -2
- package/dist/utils/eventEmitter.d.ts +0 -23
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/logger.d.ts +0 -14
- package/dist/vue/composables/useAgo.d.ts +0 -17
- package/dist/vue/composables/useAgoEvents.d.ts +0 -11
- package/dist/vue/composables/useAgoFunction.d.ts +0 -34
- package/dist/vue/composables/useAgoStore.d.ts +0 -18
- package/dist/vue/composables/useChat.d.ts +0 -251
- package/dist/vue/composables/useConversation.d.ts +0 -178
- package/dist/vue/composables/useMessages.d.ts +0 -89
- package/dist/vue/index.d.ts +0 -11
- package/dist/vue/plugin.d.ts +0 -16
- package/dist/vue/symbols.d.ts +0 -3
- package/dist/vue.cjs.map +0 -1
- package/dist/vue.js.map +0 -1
- package/dist/widget/index.d.ts +0 -1
- package/dist/widget/types.d.ts +0 -43
package/dist/widget.js
CHANGED
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
import { t as X } from "./AgoClient-DF7M2WAz.js";
|
|
2
|
+
import { t as Z } from "./createFormCollector-ClzHfaBd.js";
|
|
3
|
+
var G = '"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';
|
|
4
|
+
function m(l, o) {
|
|
5
|
+
Object.assign(l.style, o);
|
|
6
|
+
}
|
|
7
|
+
function c(l = {}) {
|
|
8
|
+
const o = document.createElement("div");
|
|
9
|
+
return m(o, l), o;
|
|
10
|
+
}
|
|
11
|
+
var P = "ago-chat-widget-keyframes";
|
|
12
|
+
function ee() {
|
|
13
|
+
if (typeof document > "u" || document.getElementById(P)) return;
|
|
14
|
+
const l = document.createElement("style");
|
|
15
|
+
l.id = P, l.textContent = "@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }", document.head.appendChild(l);
|
|
16
|
+
}
|
|
17
|
+
function te(l) {
|
|
18
|
+
const o = typeof l == "string" ? document.querySelector(l) : l;
|
|
19
|
+
if (!o) throw new Error(`mountChatWidget: target "${String(l)}" not found.`);
|
|
20
|
+
return o;
|
|
21
|
+
}
|
|
22
|
+
function ae(l, o) {
|
|
23
|
+
const { title: w = "Chat", welcomeMessage: I = "Hello! How can I help you today?", placeholder: R = "Type a message...", allowFiles: u = !1, height: x = 500, logoUrl: f, showAgentName: b = !1, forms: _, onFollowUpClick: k, onMessageSent: D, onMessageReceived: s } = o;
|
|
24
|
+
if (!o.client && !o.config?.baseUrl) throw new Error("mountChatWidget requires either `client` or `config` (with a baseUrl).");
|
|
25
|
+
const i = o.client ?? new X(o.config), z = te(l);
|
|
26
|
+
let g = o.conversationId, n = [], y = !1, v = null;
|
|
27
|
+
const N = c({
|
|
28
|
+
display: "flex",
|
|
29
|
+
flexDirection: "column",
|
|
30
|
+
height: typeof x == "number" ? `${x}px` : x,
|
|
31
|
+
border: "1px solid #dee3e8",
|
|
32
|
+
borderRadius: "16px",
|
|
33
|
+
overflow: "hidden",
|
|
34
|
+
backgroundColor: "#fff",
|
|
35
|
+
fontFamily: G,
|
|
36
|
+
boxShadow: "rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"
|
|
37
|
+
});
|
|
38
|
+
N.className = "ago-chat-widget";
|
|
39
|
+
const W = c({
|
|
40
|
+
padding: "14px 16px",
|
|
41
|
+
borderBottom: "1px solid #dee3e8",
|
|
42
|
+
backgroundColor: "#03182f",
|
|
43
|
+
color: "#e8f0fe",
|
|
44
|
+
display: "flex",
|
|
45
|
+
alignItems: "center",
|
|
46
|
+
gap: "10px"
|
|
47
|
+
});
|
|
48
|
+
if (W.className = "ago-chat-widget__header", f) {
|
|
49
|
+
const e = document.createElement("img");
|
|
50
|
+
e.src = f, e.alt = "Logo", m(e, {
|
|
51
|
+
height: "24px",
|
|
52
|
+
width: "auto"
|
|
53
|
+
}), W.appendChild(e);
|
|
54
|
+
}
|
|
55
|
+
const F = document.createElement("h3");
|
|
56
|
+
F.textContent = w, m(F, {
|
|
57
|
+
margin: "0",
|
|
58
|
+
fontSize: "15px",
|
|
59
|
+
fontWeight: "600"
|
|
60
|
+
}), W.appendChild(F);
|
|
61
|
+
const E = c({
|
|
62
|
+
flex: "1",
|
|
63
|
+
overflow: "auto",
|
|
64
|
+
padding: "16px",
|
|
65
|
+
backgroundColor: "#fbfbfb"
|
|
66
|
+
});
|
|
67
|
+
E.className = "ago-chat-widget__messages";
|
|
68
|
+
const { inputRow: K, setDisabled: j, focus: q } = ne({
|
|
69
|
+
placeholder: R,
|
|
70
|
+
allowFiles: u,
|
|
71
|
+
onSend: (e, t) => {
|
|
72
|
+
L(e, t);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
ee(), N.append(W, E, K), z.appendChild(N);
|
|
76
|
+
const U = k !== !1, A = k === !1 ? void 0 : k ?? ((e) => {
|
|
77
|
+
L(e);
|
|
78
|
+
});
|
|
79
|
+
function V(e) {
|
|
80
|
+
const t = e.role === "user", d = c({
|
|
81
|
+
display: "flex",
|
|
82
|
+
flexDirection: "column",
|
|
83
|
+
alignItems: t ? "flex-end" : "flex-start",
|
|
84
|
+
marginBottom: "16px"
|
|
85
|
+
});
|
|
86
|
+
if (d.className = `ago-message ago-message--${e.role}`, !t && b && e.agent) {
|
|
87
|
+
const a = c({
|
|
88
|
+
fontSize: "13px",
|
|
89
|
+
fontWeight: "500",
|
|
90
|
+
color: "#30373e",
|
|
91
|
+
marginBottom: "6px",
|
|
92
|
+
padding: "0 4px"
|
|
93
|
+
});
|
|
94
|
+
a.className = "ago-message__agent", a.textContent = e.agent.displayName || e.agent.name, d.appendChild(a);
|
|
95
|
+
}
|
|
96
|
+
if (!t && e.sources && e.sources.length > 0) {
|
|
97
|
+
const a = c({
|
|
98
|
+
display: "grid",
|
|
99
|
+
gridTemplateColumns: "1fr 1fr",
|
|
100
|
+
gap: "6px",
|
|
101
|
+
marginBottom: "10px",
|
|
102
|
+
width: "100%",
|
|
103
|
+
maxWidth: "85%"
|
|
104
|
+
});
|
|
105
|
+
a.className = "ago-message__sources", e.sources.forEach((p, r) => {
|
|
106
|
+
const C = p.url ? document.createElement("a") : document.createElement("div");
|
|
107
|
+
p.url && C instanceof HTMLAnchorElement && (C.href = p.url, C.target = "_blank", C.rel = "noopener noreferrer"), m(C, {
|
|
108
|
+
display: "flex",
|
|
109
|
+
alignItems: "center",
|
|
110
|
+
gap: "8px",
|
|
111
|
+
padding: "8px 10px",
|
|
112
|
+
border: "1px solid #dee3e8",
|
|
113
|
+
borderRadius: "8px",
|
|
114
|
+
backgroundColor: "#fff",
|
|
115
|
+
textDecoration: "none",
|
|
116
|
+
color: "#30373e",
|
|
117
|
+
fontSize: "12px",
|
|
118
|
+
overflow: "hidden"
|
|
119
|
+
});
|
|
120
|
+
const $ = c({
|
|
121
|
+
flexShrink: "0",
|
|
122
|
+
width: "18px",
|
|
123
|
+
height: "18px",
|
|
124
|
+
borderRadius: "3px",
|
|
125
|
+
border: "1px solid #1b5fc4",
|
|
126
|
+
color: "#1b5fc4",
|
|
127
|
+
fontSize: "11px",
|
|
128
|
+
fontWeight: "500",
|
|
129
|
+
display: "flex",
|
|
130
|
+
alignItems: "center",
|
|
131
|
+
justifyContent: "center",
|
|
132
|
+
backgroundColor: "#f0f4ff"
|
|
133
|
+
});
|
|
134
|
+
$.textContent = String(r + 1);
|
|
135
|
+
const M = c({
|
|
136
|
+
overflow: "hidden",
|
|
137
|
+
textOverflow: "ellipsis",
|
|
138
|
+
whiteSpace: "nowrap"
|
|
139
|
+
});
|
|
140
|
+
M.textContent = p.title, M.title = p.title, C.append($, M), a.appendChild(C);
|
|
141
|
+
}), d.appendChild(a);
|
|
142
|
+
}
|
|
143
|
+
const h = c({
|
|
144
|
+
maxWidth: t ? "75%" : "100%",
|
|
145
|
+
padding: t ? "10px 14px" : "2px 8px",
|
|
146
|
+
borderRadius: t ? "16px" : "0",
|
|
147
|
+
backgroundColor: t ? "#03182f" : "transparent",
|
|
148
|
+
color: t ? "#fff" : "#30373e",
|
|
149
|
+
wordBreak: "break-word",
|
|
150
|
+
fontSize: "14px",
|
|
151
|
+
lineHeight: "1.6",
|
|
152
|
+
whiteSpace: "pre-wrap"
|
|
153
|
+
});
|
|
154
|
+
if (h.className = "ago-message__content", e.content ? h.textContent = e.content : e.status === "IN_PROGRESS" && h.appendChild(Q()), d.appendChild(h), e.followUpReplies && e.followUpReplies.length > 0) {
|
|
155
|
+
const a = c({
|
|
156
|
+
display: "flex",
|
|
157
|
+
flexWrap: "wrap",
|
|
158
|
+
gap: "8px",
|
|
159
|
+
marginTop: "10px"
|
|
160
|
+
});
|
|
161
|
+
a.className = "ago-message__followups";
|
|
162
|
+
for (const p of e.followUpReplies) {
|
|
163
|
+
const r = document.createElement("button");
|
|
164
|
+
r.type = "button", r.className = "ago-message__followup-btn", r.textContent = p, r.disabled = !U, m(r, {
|
|
165
|
+
padding: "6px 14px",
|
|
166
|
+
fontSize: "13px",
|
|
167
|
+
borderRadius: "16px",
|
|
168
|
+
border: "1px solid #dee3e8",
|
|
169
|
+
backgroundColor: "#fff",
|
|
170
|
+
color: "#30373e",
|
|
171
|
+
cursor: U ? "pointer" : "default",
|
|
172
|
+
transition: "border-color 0.15s"
|
|
173
|
+
}), A && r.addEventListener("click", () => A(p)), r.addEventListener("mouseenter", () => {
|
|
174
|
+
r.style.borderColor = "#1b5fc4";
|
|
175
|
+
}), r.addEventListener("mouseleave", () => {
|
|
176
|
+
r.style.borderColor = "#dee3e8";
|
|
177
|
+
}), a.appendChild(r);
|
|
178
|
+
}
|
|
179
|
+
d.appendChild(a);
|
|
180
|
+
}
|
|
181
|
+
return d;
|
|
182
|
+
}
|
|
183
|
+
function S() {
|
|
184
|
+
if (E.replaceChildren(), n.length === 0) {
|
|
185
|
+
const e = c({
|
|
186
|
+
textAlign: "center",
|
|
187
|
+
color: "#6b6d6f",
|
|
188
|
+
padding: "24px 16px",
|
|
189
|
+
fontSize: "14px",
|
|
190
|
+
lineHeight: "1.5"
|
|
191
|
+
});
|
|
192
|
+
e.textContent = I, E.appendChild(e);
|
|
193
|
+
} else for (const e of n) E.appendChild(V(e));
|
|
194
|
+
if (v) {
|
|
195
|
+
const e = c({
|
|
196
|
+
padding: "10px 14px",
|
|
197
|
+
backgroundColor: "#fef2f2",
|
|
198
|
+
color: "#dc2626",
|
|
199
|
+
borderRadius: "12px",
|
|
200
|
+
marginTop: "8px",
|
|
201
|
+
fontSize: "13px",
|
|
202
|
+
border: "1px solid #fecaca"
|
|
203
|
+
});
|
|
204
|
+
e.textContent = v, E.appendChild(e);
|
|
205
|
+
}
|
|
206
|
+
E.scrollTop = E.scrollHeight, j(y);
|
|
207
|
+
}
|
|
208
|
+
function Y() {
|
|
209
|
+
for (let e = n.length - 1; e >= 0; e--) {
|
|
210
|
+
const t = n[e];
|
|
211
|
+
if (t.role === "assistant" && t.status === "IN_PROGRESS") return t;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
const B = (e) => {
|
|
215
|
+
g || (g = e.conversationId);
|
|
216
|
+
}, H = (e) => {
|
|
217
|
+
const t = Y();
|
|
218
|
+
t && (t.content += e.content, S());
|
|
219
|
+
}, O = (e) => {
|
|
220
|
+
const t = n.findIndex((d) => d.id === e.id || d.role === "assistant" && d.status === "IN_PROGRESS");
|
|
221
|
+
t >= 0 ? n[t] = e : n.push(e), y = !1, S(), e.status === "DONE" && s?.({
|
|
222
|
+
id: e.id,
|
|
223
|
+
content: e.content
|
|
224
|
+
});
|
|
225
|
+
}, T = (e) => {
|
|
226
|
+
v = e.error, y = !1, n = n.filter((t) => !t.id.startsWith("temp-")), S();
|
|
227
|
+
};
|
|
228
|
+
i.on("message:start", B), i.on("message:chunk", H), i.on("message:complete", O), i.on("message:error", T);
|
|
229
|
+
const J = (_ ?? []).map((e) => Z(e).install(i));
|
|
230
|
+
async function L(e, t) {
|
|
231
|
+
const d = e.trim();
|
|
232
|
+
if (!d && !t?.length || y) return;
|
|
233
|
+
D?.(d), y = !0, v = null;
|
|
234
|
+
const h = Date.now();
|
|
235
|
+
n.push({
|
|
236
|
+
id: `temp-user-${h}`,
|
|
237
|
+
conversationId: g || "",
|
|
238
|
+
content: d,
|
|
239
|
+
role: "user",
|
|
240
|
+
status: "DONE",
|
|
241
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
242
|
+
}), n.push({
|
|
243
|
+
id: `temp-assistant-${h}`,
|
|
244
|
+
conversationId: g || "",
|
|
245
|
+
content: "",
|
|
246
|
+
role: "assistant",
|
|
247
|
+
status: "IN_PROGRESS",
|
|
248
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
249
|
+
}), S();
|
|
250
|
+
try {
|
|
251
|
+
const a = await i.sendMessage(d, {
|
|
252
|
+
conversationId: g,
|
|
253
|
+
files: t
|
|
254
|
+
});
|
|
255
|
+
a.conversationId && !g && (g = a.conversationId);
|
|
256
|
+
const p = n.find((r) => r.id === `temp-user-${h}`);
|
|
257
|
+
if (p && (p.id = `user-${h}`, p.conversationId = a.conversationId), !n.some((r) => r.id === a.id)) {
|
|
258
|
+
const r = n.findIndex((C) => C.id === `temp-assistant-${h}`);
|
|
259
|
+
r >= 0 ? n[r] = a : n.push(a);
|
|
260
|
+
}
|
|
261
|
+
n = n.filter((r) => !r.id.startsWith("temp-")), y = !1, S();
|
|
262
|
+
} catch (a) {
|
|
263
|
+
v = a instanceof Error ? a.message : "Failed to send message", y = !1, n = n.filter((p) => !p.id.startsWith("temp-")), S();
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return S(), q(), {
|
|
267
|
+
client: i,
|
|
268
|
+
element: N,
|
|
269
|
+
sendMessage: L,
|
|
270
|
+
destroy() {
|
|
271
|
+
i.off("message:start", B), i.off("message:chunk", H), i.off("message:complete", O), i.off("message:error", T), J.forEach((e) => e()), N.remove(), o.client || i.destroy();
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
function Q() {
|
|
275
|
+
const e = c({
|
|
276
|
+
display: "flex",
|
|
277
|
+
gap: "4px",
|
|
278
|
+
padding: "4px 0"
|
|
279
|
+
});
|
|
280
|
+
for (let t = 0; t < 3; t++) {
|
|
281
|
+
const d = c({
|
|
282
|
+
width: "6px",
|
|
283
|
+
height: "6px",
|
|
284
|
+
borderRadius: "50%",
|
|
285
|
+
backgroundColor: "#b5bfc8",
|
|
286
|
+
animation: "ago-pulse 1.2s ease-in-out infinite",
|
|
287
|
+
animationDelay: `${t * 0.2}s`
|
|
288
|
+
});
|
|
289
|
+
e.appendChild(d);
|
|
290
|
+
}
|
|
291
|
+
return e;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
function ne(l) {
|
|
295
|
+
let o = [];
|
|
296
|
+
const w = document.createElement("form");
|
|
297
|
+
m(w, {
|
|
298
|
+
display: "flex",
|
|
299
|
+
flexDirection: "column",
|
|
300
|
+
gap: "8px",
|
|
301
|
+
padding: "12px",
|
|
302
|
+
borderTop: "1px solid #dee3e8",
|
|
303
|
+
backgroundColor: "#fff"
|
|
304
|
+
}), w.className = "ago-chat-input";
|
|
305
|
+
const I = c({
|
|
306
|
+
display: "flex",
|
|
307
|
+
flexWrap: "wrap",
|
|
308
|
+
gap: "6px"
|
|
309
|
+
}), R = c({
|
|
310
|
+
display: "flex",
|
|
311
|
+
gap: "8px",
|
|
312
|
+
alignItems: "flex-end"
|
|
313
|
+
}), u = document.createElement("textarea");
|
|
314
|
+
u.placeholder = l.placeholder, u.rows = 1, m(u, {
|
|
315
|
+
flex: "1",
|
|
316
|
+
resize: "none",
|
|
317
|
+
padding: "10px 12px",
|
|
318
|
+
border: "1px solid #dee3e8",
|
|
319
|
+
borderRadius: "12px",
|
|
320
|
+
fontSize: "14px",
|
|
321
|
+
fontFamily: G,
|
|
322
|
+
lineHeight: "1.4",
|
|
323
|
+
maxHeight: "120px",
|
|
324
|
+
outline: "none"
|
|
325
|
+
});
|
|
326
|
+
const x = document.createElement("button");
|
|
327
|
+
x.type = "submit", x.textContent = "Send", m(x, {
|
|
328
|
+
padding: "10px 16px",
|
|
329
|
+
border: "none",
|
|
330
|
+
borderRadius: "12px",
|
|
331
|
+
backgroundColor: "#03182f",
|
|
332
|
+
color: "#fff",
|
|
333
|
+
fontSize: "14px",
|
|
334
|
+
fontWeight: "500",
|
|
335
|
+
cursor: "pointer"
|
|
336
|
+
});
|
|
337
|
+
let f = null, b = null;
|
|
338
|
+
l.allowFiles && (f = document.createElement("input"), f.type = "file", f.multiple = !0, m(f, { display: "none" }), b = document.createElement("button"), b.type = "button", b.textContent = "📎", m(b, {
|
|
339
|
+
padding: "10px 12px",
|
|
340
|
+
border: "1px solid #dee3e8",
|
|
341
|
+
borderRadius: "12px",
|
|
342
|
+
backgroundColor: "#fff",
|
|
343
|
+
cursor: "pointer",
|
|
344
|
+
fontSize: "14px"
|
|
345
|
+
}), b.addEventListener("click", () => f?.click()), f.addEventListener("change", () => {
|
|
346
|
+
o = [...o, ...Array.from(f?.files ?? [])], _();
|
|
347
|
+
}));
|
|
348
|
+
function _() {
|
|
349
|
+
I.replaceChildren(), o.forEach((s, i) => {
|
|
350
|
+
const z = c({
|
|
351
|
+
display: "flex",
|
|
352
|
+
alignItems: "center",
|
|
353
|
+
gap: "4px",
|
|
354
|
+
padding: "4px 8px",
|
|
355
|
+
backgroundColor: "#f0f4ff",
|
|
356
|
+
border: "1px solid #dee3e8",
|
|
357
|
+
borderRadius: "8px",
|
|
358
|
+
fontSize: "12px"
|
|
359
|
+
}), g = document.createElement("span");
|
|
360
|
+
g.textContent = s.name;
|
|
361
|
+
const n = document.createElement("button");
|
|
362
|
+
n.type = "button", n.textContent = "×", m(n, {
|
|
363
|
+
border: "none",
|
|
364
|
+
background: "transparent",
|
|
365
|
+
cursor: "pointer",
|
|
366
|
+
fontSize: "14px",
|
|
367
|
+
lineHeight: "1"
|
|
368
|
+
}), n.addEventListener("click", () => {
|
|
369
|
+
o = o.filter((y, v) => v !== i), _();
|
|
370
|
+
}), z.append(g, n), I.appendChild(z);
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
const k = () => {
|
|
374
|
+
const s = u.value, i = o;
|
|
375
|
+
return u.value = "", o = [], _(), {
|
|
376
|
+
content: s,
|
|
377
|
+
files: i
|
|
378
|
+
};
|
|
379
|
+
}, D = () => {
|
|
380
|
+
const { content: s, files: i } = k();
|
|
381
|
+
(s.trim() || i.length > 0) && l.onSend(s.trim(), i.length > 0 ? i : void 0);
|
|
382
|
+
};
|
|
383
|
+
return w.addEventListener("submit", (s) => {
|
|
384
|
+
s.preventDefault(), D();
|
|
385
|
+
}), u.addEventListener("keydown", (s) => {
|
|
386
|
+
s.key === "Enter" && !s.shiftKey && (s.preventDefault(), D());
|
|
387
|
+
}), b && R.appendChild(b), R.append(u, x), f && w.appendChild(f), w.append(I, R), {
|
|
388
|
+
inputRow: w,
|
|
389
|
+
getValueAndClear: k,
|
|
390
|
+
setDisabled: (s) => {
|
|
391
|
+
u.disabled = s, x.disabled = s, x.style.opacity = s ? "0.6" : "1", x.style.cursor = s ? "not-allowed" : "pointer";
|
|
392
|
+
},
|
|
393
|
+
focus: () => u.focus()
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
export {
|
|
397
|
+
ae as mountChatWidget
|
|
398
|
+
};
|
package/package.json
CHANGED
|
@@ -1,57 +1,66 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@useago/sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "JavaScript SDK for AGO Chat integration",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
6
7
|
"main": "dist/index.cjs",
|
|
7
8
|
"module": "dist/index.js",
|
|
8
9
|
"types": "dist/index.d.ts",
|
|
9
10
|
"exports": {
|
|
10
11
|
".": {
|
|
11
|
-
"import": "./dist/index.js",
|
|
12
|
-
"require": "./dist/index.cjs"
|
|
13
|
-
"types": "./dist/index.d.ts"
|
|
12
|
+
"import": { "types": "./dist/index.d.ts", "default": "./dist/index.js" },
|
|
13
|
+
"require": { "types": "./dist/index.d.cts", "default": "./dist/index.cjs" }
|
|
14
14
|
},
|
|
15
15
|
"./react": {
|
|
16
|
-
"import": "./dist/react.js",
|
|
17
|
-
"require": "./dist/react.cjs"
|
|
18
|
-
"types": "./dist/react.d.ts"
|
|
16
|
+
"import": { "types": "./dist/react.d.ts", "default": "./dist/react.js" },
|
|
17
|
+
"require": { "types": "./dist/react.d.cts", "default": "./dist/react.cjs" }
|
|
19
18
|
},
|
|
20
19
|
"./vue": {
|
|
21
|
-
"import": "./dist/vue.js",
|
|
22
|
-
"require": "./dist/vue.cjs"
|
|
23
|
-
"types": "./dist/vue.d.ts"
|
|
20
|
+
"import": { "types": "./dist/vue.d.ts", "default": "./dist/vue.js" },
|
|
21
|
+
"require": { "types": "./dist/vue.d.cts", "default": "./dist/vue.cjs" }
|
|
24
22
|
},
|
|
25
23
|
"./angular": {
|
|
26
|
-
"import": "./dist/angular.js",
|
|
27
|
-
"require": "./dist/angular.cjs"
|
|
28
|
-
"types": "./dist/angular.d.ts"
|
|
24
|
+
"import": { "types": "./dist/angular.d.ts", "default": "./dist/angular.js" },
|
|
25
|
+
"require": { "types": "./dist/angular.d.cts", "default": "./dist/angular.cjs" }
|
|
29
26
|
},
|
|
30
27
|
"./helpers": {
|
|
31
|
-
"import": "./dist/helpers.js",
|
|
32
|
-
"require": "./dist/helpers.cjs"
|
|
33
|
-
"types": "./dist/helpers.d.ts"
|
|
28
|
+
"import": { "types": "./dist/helpers.d.ts", "default": "./dist/helpers.js" },
|
|
29
|
+
"require": { "types": "./dist/helpers.d.cts", "default": "./dist/helpers.cjs" }
|
|
34
30
|
},
|
|
35
31
|
"./widget": {
|
|
36
|
-
"import": "./dist/widget.js",
|
|
37
|
-
"require": "./dist/widget.cjs"
|
|
38
|
-
"types": "./dist/widget.d.ts"
|
|
32
|
+
"import": { "types": "./dist/widget.d.ts", "default": "./dist/widget.js" },
|
|
33
|
+
"require": { "types": "./dist/widget.d.cts", "default": "./dist/widget.cjs" }
|
|
39
34
|
},
|
|
40
35
|
"./devtools": {
|
|
41
|
-
"import": "./dist/devtools.js",
|
|
42
|
-
"require": "./dist/devtools.cjs"
|
|
43
|
-
"types": "./dist/devtools.d.ts"
|
|
36
|
+
"import": { "types": "./dist/devtools.d.ts", "default": "./dist/devtools.js" },
|
|
37
|
+
"require": { "types": "./dist/devtools.d.cts", "default": "./dist/devtools.cjs" }
|
|
44
38
|
}
|
|
45
39
|
},
|
|
46
40
|
"publishConfig": {
|
|
47
41
|
"access": "public"
|
|
48
42
|
},
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "git+https://github.com/useago/ago-chat.git",
|
|
46
|
+
"directory": "sdk"
|
|
47
|
+
},
|
|
48
|
+
"bugs": {
|
|
49
|
+
"url": "https://github.com/useago/ago-chat/issues"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=18"
|
|
53
|
+
},
|
|
49
54
|
"files": [
|
|
50
55
|
"dist",
|
|
51
56
|
"README.md"
|
|
52
57
|
],
|
|
53
58
|
"scripts": {
|
|
54
|
-
"
|
|
59
|
+
"clean": "rm -rf dist",
|
|
60
|
+
"build": "npm run clean && vite build && npm run build:cts-types",
|
|
61
|
+
"build:cts-types": "for f in $(find dist -name '*.d.ts'); do cp \"$f\" \"${f%.d.ts}.d.cts\"; done",
|
|
62
|
+
"prepublishOnly": "npm run lint && npm run typecheck && npm test && npm run build && npm run check:package",
|
|
63
|
+
"check:package": "publint --strict && attw --pack . --profile node16",
|
|
55
64
|
"dev": "vite build --watch",
|
|
56
65
|
"test": "vitest run",
|
|
57
66
|
"test:watch": "vitest",
|
|
@@ -79,6 +88,7 @@
|
|
|
79
88
|
}
|
|
80
89
|
},
|
|
81
90
|
"devDependencies": {
|
|
91
|
+
"@arethetypeswrong/cli": "^0.18.0",
|
|
82
92
|
"@types/node": "^20.0.0",
|
|
83
93
|
"@types/react": "^18.0.0",
|
|
84
94
|
"@types/react-dom": "^18.0.0",
|
|
@@ -87,6 +97,7 @@
|
|
|
87
97
|
"eslint": "^8.0.0",
|
|
88
98
|
"eslint-plugin-react-hooks": "^4.6.2",
|
|
89
99
|
"jsdom": "^28.0.0",
|
|
100
|
+
"publint": "^0.3.0",
|
|
90
101
|
"react": "^18.0.0",
|
|
91
102
|
"react-dom": "^18.0.0",
|
|
92
103
|
"typescript": "^5.0.0",
|
|
@@ -102,6 +113,6 @@
|
|
|
102
113
|
"ai",
|
|
103
114
|
"chatbot"
|
|
104
115
|
],
|
|
105
|
-
"license": "
|
|
116
|
+
"license": "UNLICENSED",
|
|
106
117
|
"homepage": "https://docs.useago.com"
|
|
107
118
|
}
|