@locdo.tech/botiq-chat-sdk 0.3.3 → 0.4.0
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/sdk/index.js +1 -1
- package/dist/sdk/{npm-DfSKhYCq.js → npm-DV43YS-n.js} +339 -184
- package/dist/sdk/react.js +1 -1
- package/dist/sdk/vue.js +1 -1
- package/package.json +1 -1
package/dist/sdk/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as e } from "./npm-
|
|
1
|
+
import { t as e } from "./npm-DV43YS-n.js";
|
|
2
2
|
export { e as init };
|
|
@@ -1,30 +1,31 @@
|
|
|
1
1
|
//#region src/core/config.ts
|
|
2
2
|
var e = "https://bot-q-backend.vercel.app", t = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
placeholder: ""
|
|
23
|
-
},
|
|
24
|
-
font: "inter"
|
|
3
|
+
colors: {
|
|
4
|
+
primary: "#F97316",
|
|
5
|
+
header: "#F97316",
|
|
6
|
+
userBubble: "#F97316",
|
|
7
|
+
botBubble: "#1A1A1A",
|
|
8
|
+
background: "#000000",
|
|
9
|
+
text: "#FFFFFF",
|
|
10
|
+
inputBackground: "#1A1A1A"
|
|
11
|
+
},
|
|
12
|
+
layout: {
|
|
13
|
+
position: "bottom-right",
|
|
14
|
+
buttonShape: "circle",
|
|
15
|
+
width: 360,
|
|
16
|
+
height: 520
|
|
17
|
+
},
|
|
18
|
+
content: {
|
|
19
|
+
greeting: "",
|
|
20
|
+
suggestionChips: [],
|
|
21
|
+
placeholder: ""
|
|
25
22
|
},
|
|
23
|
+
font: "inter"
|
|
24
|
+
}, n = {
|
|
25
|
+
name: "BotIQ",
|
|
26
|
+
design: t,
|
|
26
27
|
widgetLanguage: "vi"
|
|
27
|
-
},
|
|
28
|
+
}, r = /^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/, i = new Set(["bottom-right", "bottom-left"]), a = new Set(["circle", "square"]), o = new Set([
|
|
28
29
|
"inter",
|
|
29
30
|
"plus-jakarta",
|
|
30
31
|
"poppins",
|
|
@@ -33,56 +34,74 @@ var e = "https://bot-q-backend.vercel.app", t = {
|
|
|
33
34
|
"raleway",
|
|
34
35
|
"lato",
|
|
35
36
|
"playfair"
|
|
36
|
-
]),
|
|
37
|
+
]), s = new Set([
|
|
37
38
|
"none",
|
|
38
39
|
"fade",
|
|
39
40
|
"slide-up",
|
|
40
41
|
"bounce"
|
|
41
|
-
]),
|
|
42
|
+
]), c = new Set([
|
|
42
43
|
"dots-bounce",
|
|
43
44
|
"dots-pulse",
|
|
44
45
|
"bar"
|
|
45
46
|
]);
|
|
46
|
-
function
|
|
47
|
+
function l(e) {
|
|
47
48
|
let t = e.colors;
|
|
48
|
-
if (![
|
|
49
|
+
if (t.inputBackground ||= "#1A1A1A", ![
|
|
49
50
|
t.primary,
|
|
50
51
|
t.header,
|
|
51
52
|
t.userBubble,
|
|
52
53
|
t.botBubble,
|
|
53
54
|
t.background,
|
|
54
|
-
t.text
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
t.text,
|
|
56
|
+
t.inputBackground
|
|
57
|
+
].every((e) => typeof e == "string" && r.test(e)) || !i.has(e.layout.position) || !a.has(e.layout.buttonShape) || !o.has(e.font)) return !1;
|
|
58
|
+
let { width: n, height: l } = e.layout;
|
|
59
|
+
if (!Number.isFinite(n) || n < 280 || n > 800 || !Number.isFinite(l) || l < 200 || l > 900) return !1;
|
|
58
60
|
if (e.gradient) {
|
|
59
61
|
let t = e.gradient;
|
|
60
|
-
if (t.type !== "linear" && t.type !== "radial" || !
|
|
62
|
+
if (t.type !== "linear" && t.type !== "radial" || !r.test(t.from) || !r.test(t.to) || t.angle !== void 0 && (!Number.isFinite(t.angle) || t.angle < 0 || t.angle > 360)) return !1;
|
|
61
63
|
}
|
|
62
|
-
return !(e.animation && (!
|
|
64
|
+
return !(e.animation && (!s.has(e.animation.bubbleOpen) || !c.has(e.animation.typingIndicator)) || e.customCSS !== void 0 && (typeof e.customCSS != "string" || e.customCSS.length > 8e3));
|
|
65
|
+
}
|
|
66
|
+
var u = 8e3;
|
|
67
|
+
function d(e, t) {
|
|
68
|
+
return fetch(`${t}/widget/meta`, {
|
|
69
|
+
headers: { "X-Api-Key": e },
|
|
70
|
+
referrerPolicy: "no-referrer-when-downgrade",
|
|
71
|
+
signal: AbortSignal.timeout(u)
|
|
72
|
+
});
|
|
63
73
|
}
|
|
64
|
-
async function
|
|
74
|
+
async function f(e, r) {
|
|
75
|
+
let i;
|
|
65
76
|
try {
|
|
66
|
-
|
|
67
|
-
headers: { "X-Api-Key": e },
|
|
68
|
-
referrerPolicy: "no-referrer-when-downgrade",
|
|
69
|
-
signal: AbortSignal.timeout(5e3)
|
|
70
|
-
});
|
|
71
|
-
if (r.status === 401 || r.status === 403) return null;
|
|
72
|
-
if (!r.ok) return t;
|
|
73
|
-
let i = await r.json();
|
|
74
|
-
if (!i?.design?.colors || !i?.design?.layout || !i?.design?.content || !c(i.design)) return t;
|
|
75
|
-
let a = typeof i.name == "string" && i.name.length > 0 ? i.name : "BotIQ", o = i.widgetLanguage === "en" ? "en" : "vi";
|
|
76
|
-
return {
|
|
77
|
-
name: a,
|
|
78
|
-
design: i.design,
|
|
79
|
-
widgetLanguage: o
|
|
80
|
-
};
|
|
77
|
+
i = await d(e, r);
|
|
81
78
|
} catch {
|
|
82
|
-
|
|
79
|
+
try {
|
|
80
|
+
i = await d(e, r);
|
|
81
|
+
} catch {
|
|
82
|
+
return n;
|
|
83
|
+
}
|
|
83
84
|
}
|
|
85
|
+
if (i.status === 401 || i.status === 403) return null;
|
|
86
|
+
if (!i.ok) return n;
|
|
87
|
+
let a;
|
|
88
|
+
try {
|
|
89
|
+
a = await i.json();
|
|
90
|
+
} catch {
|
|
91
|
+
return n;
|
|
92
|
+
}
|
|
93
|
+
let o = typeof a.name == "string" && a.name.length > 0 ? a.name : n.name, s = a.widgetLanguage === "en" ? "en" : "vi";
|
|
94
|
+
return !a.design?.colors || !a.design?.layout || !a.design?.content || !l(a.design) ? {
|
|
95
|
+
name: o,
|
|
96
|
+
design: t,
|
|
97
|
+
widgetLanguage: s
|
|
98
|
+
} : {
|
|
99
|
+
name: o,
|
|
100
|
+
design: a.design,
|
|
101
|
+
widgetLanguage: s
|
|
102
|
+
};
|
|
84
103
|
}
|
|
85
|
-
function
|
|
104
|
+
function p(t) {
|
|
86
105
|
return {
|
|
87
106
|
apiKey: t.apiKey,
|
|
88
107
|
apiUrl: e
|
|
@@ -90,32 +109,38 @@ function u(t) {
|
|
|
90
109
|
}
|
|
91
110
|
//#endregion
|
|
92
111
|
//#region src/core/session.ts
|
|
93
|
-
var
|
|
94
|
-
function
|
|
112
|
+
var m = "botiq:sessionId", h = "botiq:sessionId:", g = "botiq:history:", _ = 10;
|
|
113
|
+
function v() {
|
|
114
|
+
try {
|
|
115
|
+
let e = localStorage.getItem(m);
|
|
116
|
+
localStorage.removeItem(m), e && localStorage.removeItem(g + e);
|
|
117
|
+
} catch {}
|
|
118
|
+
}
|
|
119
|
+
function y(e) {
|
|
95
120
|
try {
|
|
96
|
-
let e = localStorage.getItem(
|
|
97
|
-
return
|
|
121
|
+
let t = h + e, n = localStorage.getItem(t);
|
|
122
|
+
return n || (n = crypto.randomUUID(), localStorage.setItem(t, n)), n;
|
|
98
123
|
} catch {
|
|
99
124
|
return crypto.randomUUID();
|
|
100
125
|
}
|
|
101
126
|
}
|
|
102
|
-
function
|
|
127
|
+
function b(e, t) {
|
|
103
128
|
try {
|
|
104
|
-
let
|
|
105
|
-
return
|
|
129
|
+
let n = localStorage.getItem(`${g}${e}:${t}`);
|
|
130
|
+
return n ? JSON.parse(n) : [];
|
|
106
131
|
} catch {
|
|
107
132
|
return [];
|
|
108
133
|
}
|
|
109
134
|
}
|
|
110
|
-
function
|
|
135
|
+
function x(e, t, n) {
|
|
111
136
|
try {
|
|
112
|
-
let
|
|
113
|
-
localStorage.setItem(
|
|
137
|
+
let r = [...b(e, t), ...n].slice(-_);
|
|
138
|
+
localStorage.setItem(`${g}${e}:${t}`, JSON.stringify(r));
|
|
114
139
|
} catch {}
|
|
115
140
|
}
|
|
116
141
|
//#endregion
|
|
117
142
|
//#region src/core/api.ts
|
|
118
|
-
async function
|
|
143
|
+
async function S(e, t, n, r, i, a) {
|
|
119
144
|
try {
|
|
120
145
|
let o = await fetch(`${e}/widget/chat`, {
|
|
121
146
|
method: "POST",
|
|
@@ -135,30 +160,68 @@ async function _(e, t, n, r, i, a) {
|
|
|
135
160
|
return a.errorMessage;
|
|
136
161
|
}
|
|
137
162
|
}
|
|
163
|
+
var C = {
|
|
164
|
+
messages: [],
|
|
165
|
+
hasMore: !1
|
|
166
|
+
};
|
|
167
|
+
function w(e) {
|
|
168
|
+
if (!e || typeof e != "object") return !1;
|
|
169
|
+
let t = e;
|
|
170
|
+
return typeof t.id == "string" && (t.role === "user" || t.role === "assistant") && typeof t.content == "string";
|
|
171
|
+
}
|
|
172
|
+
async function T(e, t, n, r, i) {
|
|
173
|
+
try {
|
|
174
|
+
let a = new URLSearchParams({
|
|
175
|
+
sessionId: n,
|
|
176
|
+
limit: String(i)
|
|
177
|
+
});
|
|
178
|
+
r && a.set("before", r);
|
|
179
|
+
let o = await fetch(`${e}/widget/messages?${a.toString()}`, {
|
|
180
|
+
method: "GET",
|
|
181
|
+
headers: { "X-Api-Key": t },
|
|
182
|
+
referrerPolicy: "no-referrer-when-downgrade"
|
|
183
|
+
});
|
|
184
|
+
if (!o.ok) return C;
|
|
185
|
+
let s = await o.json();
|
|
186
|
+
return {
|
|
187
|
+
messages: Array.isArray(s.messages) ? s.messages.filter(w) : [],
|
|
188
|
+
hasMore: s.hasMore === !0
|
|
189
|
+
};
|
|
190
|
+
} catch {
|
|
191
|
+
return C;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function ee(e, t, n, r) {
|
|
195
|
+
return T(e, t, n, void 0, r);
|
|
196
|
+
}
|
|
197
|
+
function te(e, t, n, r, i) {
|
|
198
|
+
return T(e, t, n, r, i);
|
|
199
|
+
}
|
|
138
200
|
//#endregion
|
|
139
201
|
//#region src/core/state.ts
|
|
140
|
-
var
|
|
202
|
+
var E = {
|
|
141
203
|
messages: [],
|
|
142
204
|
isLoading: !1,
|
|
143
|
-
isOpen: !1
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
205
|
+
isOpen: !1,
|
|
206
|
+
loadingOlder: !1
|
|
207
|
+
}, D = /* @__PURE__ */ new Set();
|
|
208
|
+
function O() {
|
|
209
|
+
return E;
|
|
210
|
+
}
|
|
211
|
+
function k(e) {
|
|
212
|
+
Object.assign(E, e);
|
|
150
213
|
let t = {
|
|
151
|
-
...
|
|
152
|
-
messages: [...
|
|
214
|
+
...E,
|
|
215
|
+
messages: [...E.messages]
|
|
153
216
|
};
|
|
154
|
-
|
|
217
|
+
D.forEach((e) => e(t));
|
|
155
218
|
}
|
|
156
|
-
function
|
|
157
|
-
return
|
|
219
|
+
function A(e) {
|
|
220
|
+
return D.add(e), () => D.delete(e);
|
|
158
221
|
}
|
|
159
222
|
//#endregion
|
|
160
223
|
//#region src/core/styles.ts
|
|
161
|
-
var
|
|
224
|
+
var j = {
|
|
162
225
|
inter: {
|
|
163
226
|
url: "https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap",
|
|
164
227
|
family: "'Inter', system-ui, -apple-system, sans-serif"
|
|
@@ -167,45 +230,33 @@ var C = {
|
|
|
167
230
|
url: "https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600&display=swap",
|
|
168
231
|
family: "'Plus Jakarta Sans', system-ui, -apple-system, sans-serif"
|
|
169
232
|
},
|
|
170
|
-
poppins: {
|
|
171
|
-
url: "https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap",
|
|
172
|
-
family: "'Poppins', system-ui, -apple-system, sans-serif"
|
|
173
|
-
},
|
|
174
233
|
nunito: {
|
|
175
234
|
url: "https://fonts.googleapis.com/css2?family=Nunito:wght@400;500;600&display=swap",
|
|
176
235
|
family: "'Nunito', system-ui, -apple-system, sans-serif"
|
|
177
236
|
},
|
|
178
|
-
"dm-sans": {
|
|
179
|
-
url: "https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600&display=swap",
|
|
180
|
-
family: "'DM Sans', system-ui, -apple-system, sans-serif"
|
|
181
|
-
},
|
|
182
237
|
raleway: {
|
|
183
238
|
url: "https://fonts.googleapis.com/css2?family=Raleway:wght@400;500;600&display=swap",
|
|
184
239
|
family: "'Raleway', system-ui, -apple-system, sans-serif"
|
|
185
240
|
},
|
|
186
|
-
lato: {
|
|
187
|
-
url: "https://fonts.googleapis.com/css2?family=Lato:wght@400;700&display=swap",
|
|
188
|
-
family: "'Lato', system-ui, -apple-system, sans-serif"
|
|
189
|
-
},
|
|
190
241
|
playfair: {
|
|
191
242
|
url: "https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;500;600&display=swap",
|
|
192
243
|
family: "'Playfair Display', Georgia, serif"
|
|
193
244
|
}
|
|
194
245
|
};
|
|
195
|
-
function
|
|
246
|
+
function M(e, t) {
|
|
196
247
|
if (!t) return e;
|
|
197
248
|
let n = t.angle ?? 135;
|
|
198
249
|
return t.type === "linear" ? `linear-gradient(${n}deg, ${t.from}, ${t.to})` : `radial-gradient(circle, ${t.from}, ${t.to})`;
|
|
199
250
|
}
|
|
200
|
-
function
|
|
251
|
+
function ne(e) {
|
|
201
252
|
return e.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\\[0-9a-fA-F]{1,6}\s?/g, "x").replace(/@import\b[^;]*;?/gi, "").replace(/url\s*\(\s*["']?\s*(?!data:)[^)]*["']?\s*\)/gi, "url(\"\")").replace(/expression\s*\(/gi, "expression_(").replace(/javascript\s*:/gi, "blocked:").replace(/-moz-binding\s*:/gi, "").replace(/\bbehavior\s*:/gi, "");
|
|
202
253
|
}
|
|
203
|
-
function
|
|
254
|
+
function N(e) {
|
|
204
255
|
let t = e?.bubbleOpen ?? "none", n = e?.typingIndicator ?? "dots-bounce";
|
|
205
256
|
return [t === "fade" ? "@keyframes biq-open-fade { from { opacity: 0; } to { opacity: 1; } }\n.chat-window.open { animation: biq-open-fade .22s ease forwards; }" : t === "slide-up" ? "@keyframes biq-open-slide { from { opacity: 0; transform: scale(1) translateY(20px); } to { opacity: 1; transform: scale(1) translateY(0); } }\n.chat-window.open { animation: biq-open-slide .25s cubic-bezier(.22,1,.36,1) forwards; }" : t === "bounce" ? "@keyframes biq-open-bounce { 0% { opacity: 0; transform: scale(.85) translateY(8px); } 60% { transform: scale(1.03) translateY(-3px); } 100% { opacity: 1; transform: scale(1) translateY(0); } }\n.chat-window.open { animation: biq-open-bounce .35s cubic-bezier(.34,1.56,.64,1) forwards; }" : "", n === "dots-pulse" ? "@keyframes biq-pulse { 0%, 100% { opacity: 0.3; transform: scale(1); } 50% { opacity: 1; transform: scale(1.3); } }\n.typing span { animation: biq-pulse 1.2s infinite ease-in-out; }" : n === "bar" ? ".typing { gap: 3px; align-items: flex-end; }\n.typing span { width: 3px; height: 14px; border-radius: 2px; animation: biq-bar 1s infinite ease-in-out; }\n.typing span:nth-child(1) { animation-delay: 0s; }\n.typing span:nth-child(2) { animation-delay: .15s; height: 20px; }\n.typing span:nth-child(3) { animation-delay: .3s; }\n@keyframes biq-bar { 0%, 100% { transform: scaleY(.4); opacity: .5; } 50% { transform: scaleY(1); opacity: 1; } }" : ""].filter(Boolean).join("\n");
|
|
206
257
|
}
|
|
207
|
-
function
|
|
208
|
-
let { colors: t, layout: n, font: r, gradient: i, animation: a, customCSS: o, whiteLabel: s } = e, c =
|
|
258
|
+
function P(e) {
|
|
259
|
+
let { colors: t, layout: n, font: r, gradient: i, animation: a, customCSS: o, whiteLabel: s } = e, c = j[r] ?? j.inter, l = n.buttonShape === "square" ? "14px" : "50%", u = n.position === "bottom-left" ? "right: auto; left: 24px;" : "right: 24px;", d = n.position === "bottom-left" ? "bottom left" : "bottom right", f = n.position === "bottom-left" ? "right: auto; left: 0;" : "right: 0;", p = M(t.primary, i), m = M(t.header, i), h = M(t.userBubble, i), g = s ? ".botiq-badge { display: none !important; }" : "";
|
|
209
260
|
return `
|
|
210
261
|
@import url('${c.url}');
|
|
211
262
|
|
|
@@ -222,6 +273,7 @@ function D(e) {
|
|
|
222
273
|
--color-bot: ${t.botBubble};
|
|
223
274
|
--color-bg: ${t.background};
|
|
224
275
|
--color-text: ${t.text};
|
|
276
|
+
--color-input-bg: ${t.inputBackground};
|
|
225
277
|
--gray-50: #1A1A1A;
|
|
226
278
|
--gray-100: #222222;
|
|
227
279
|
--gray-200: #2D2D2D;
|
|
@@ -381,6 +433,37 @@ function D(e) {
|
|
|
381
433
|
background: rgba(255,255,255,.1);
|
|
382
434
|
white-space: pre-wrap;
|
|
383
435
|
}
|
|
436
|
+
.message-bubble del { text-decoration: line-through; opacity: .7; }
|
|
437
|
+
|
|
438
|
+
/* ── Markdown headings ───────────────────────────────── */
|
|
439
|
+
/* Kept modest — the chat bubble is small, so headings are only slightly
|
|
440
|
+
larger than body text, never document-sized. */
|
|
441
|
+
.message-bubble h1,
|
|
442
|
+
.message-bubble h2,
|
|
443
|
+
.message-bubble h3,
|
|
444
|
+
.message-bubble h4,
|
|
445
|
+
.message-bubble h5,
|
|
446
|
+
.message-bubble h6 {
|
|
447
|
+
margin: 8px 0 4px;
|
|
448
|
+
font-weight: 600;
|
|
449
|
+
line-height: 1.3;
|
|
450
|
+
color: #fff;
|
|
451
|
+
}
|
|
452
|
+
.message-bubble h1 { font-size: 16px; }
|
|
453
|
+
.message-bubble h2 { font-size: 15px; }
|
|
454
|
+
.message-bubble h3 { font-size: 14px; }
|
|
455
|
+
.message-bubble h4,
|
|
456
|
+
.message-bubble h5,
|
|
457
|
+
.message-bubble h6 { font-size: 13px; }
|
|
458
|
+
.message-bubble :first-child { margin-top: 0; }
|
|
459
|
+
|
|
460
|
+
/* ── Markdown horizontal rule ────────────────────────── */
|
|
461
|
+
.message-bubble hr {
|
|
462
|
+
border: 0;
|
|
463
|
+
height: 1px;
|
|
464
|
+
background: rgba(255,255,255,.15);
|
|
465
|
+
margin: 8px 0;
|
|
466
|
+
}
|
|
384
467
|
|
|
385
468
|
/* ── Markdown tables ─────────────────────────────────── */
|
|
386
469
|
.message-bubble table {
|
|
@@ -531,13 +614,13 @@ function D(e) {
|
|
|
531
614
|
color: var(--color-text);
|
|
532
615
|
resize: none;
|
|
533
616
|
outline: none;
|
|
534
|
-
background: var(--
|
|
617
|
+
background: var(--color-input-bg);
|
|
535
618
|
line-height: 1.4;
|
|
536
619
|
overflow-y: auto;
|
|
537
620
|
transition: border-color .15s;
|
|
538
621
|
}
|
|
539
622
|
|
|
540
|
-
.input:focus { border-color: var(--color-primary); background: var(--
|
|
623
|
+
.input:focus { border-color: var(--color-primary); background: var(--color-input-bg); }
|
|
541
624
|
.input::placeholder { color: var(--gray-400); }
|
|
542
625
|
|
|
543
626
|
.send-btn {
|
|
@@ -560,144 +643,192 @@ function D(e) {
|
|
|
560
643
|
.send-btn svg { width: 18px; height: 18px; fill: #fff; }
|
|
561
644
|
|
|
562
645
|
${g}
|
|
563
|
-
${
|
|
564
|
-
${o ?
|
|
646
|
+
${N(a)}
|
|
647
|
+
${o ? ne(o) : ""}
|
|
565
648
|
`;
|
|
566
649
|
}
|
|
567
650
|
//#endregion
|
|
651
|
+
//#region src/core/assets.ts
|
|
652
|
+
var F = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAYAAACOEfKtAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7D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Wc1qVrNfXvsfj+EYlqVWv8UAAAAASUVORK5CYII=";
|
|
653
|
+
//#endregion
|
|
654
|
+
//#region src/core/history-pager.ts
|
|
655
|
+
function I() {
|
|
656
|
+
return {
|
|
657
|
+
oldestCursor: null,
|
|
658
|
+
hasMore: !1,
|
|
659
|
+
cursorReady: !1
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
function L(e) {
|
|
663
|
+
return {
|
|
664
|
+
oldestCursor: e.messages[0]?.id ?? null,
|
|
665
|
+
hasMore: e.hasMore,
|
|
666
|
+
cursorReady: e.messages.length > 0
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
function R(e, t) {
|
|
670
|
+
return {
|
|
671
|
+
oldestCursor: t.messages[0]?.id ?? e.oldestCursor,
|
|
672
|
+
hasMore: t.hasMore,
|
|
673
|
+
cursorReady: e.cursorReady
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
function z(e, t) {
|
|
677
|
+
return e.cursorReady && e.hasMore && !t && e.oldestCursor !== null;
|
|
678
|
+
}
|
|
679
|
+
function B(e, t, n) {
|
|
680
|
+
return e + (n - t);
|
|
681
|
+
}
|
|
682
|
+
//#endregion
|
|
568
683
|
//#region src/core/ui.ts
|
|
569
|
-
var
|
|
570
|
-
function
|
|
571
|
-
if (!e || e.type === "icon") return
|
|
572
|
-
if (e.type === "emoji") return `<span style="font-size:22px;line-height:1;display:flex;align-items:center;justify-content:center;width:100%;height:100%">${
|
|
684
|
+
var V = "https://bot-q-frontend.vercel.app/", H = "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M20 2H4a2 2 0 00-2 2v18l4-4h14a2 2 0 002-2V4a2 2 0 00-2-2z\"/>\n</svg>", U = "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z\"/>\n</svg>", W = `<img src="${F}" alt="" style="width:100%;height:100%;object-fit:cover;border-radius:50%" />`, G = "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M2.01 21L23 12 2.01 3 2 10l15 2-15 2z\"/>\n</svg>", K = "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M20 2H4a2 2 0 00-2 2v18l4-4h14a2 2 0 002-2V4a2 2 0 00-2-2zm-2 10H6v-2h12v2zm0-3H6V7h12v2z\"/>\n</svg>";
|
|
685
|
+
function q(e) {
|
|
686
|
+
if (!e || e.type === "icon") return W;
|
|
687
|
+
if (e.type === "emoji") return `<span style="font-size:22px;line-height:1;display:flex;align-items:center;justify-content:center;width:100%;height:100%">${J(e.value)}</span>`;
|
|
573
688
|
if (e.type === "initials") {
|
|
574
689
|
let t = e.bgColor ?? "#F97316";
|
|
575
|
-
return `<div style="width:100%;height:100%;border-radius:50%;background:${/^#[0-9A-Fa-f]{3,6}$/.test(t) ? t : "#F97316"};display:flex;align-items:center;justify-content:center;font-size:14px;font-weight:700;color:#fff">${
|
|
690
|
+
return `<div style="width:100%;height:100%;border-radius:50%;background:${/^#[0-9A-Fa-f]{3,6}$/.test(t) ? t : "#F97316"};display:flex;align-items:center;justify-content:center;font-size:14px;font-weight:700;color:#fff">${J(e.value.slice(0, 2).toUpperCase())}</div>`;
|
|
576
691
|
}
|
|
577
|
-
return e.type === "image" ? `<img src="${
|
|
692
|
+
return e.type === "image" ? `<img src="${J(e.value)}" style="width:100%;height:100%;object-fit:cover;border-radius:50%" alt="" />` : W;
|
|
578
693
|
}
|
|
579
|
-
function
|
|
694
|
+
function J(e) {
|
|
580
695
|
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
581
696
|
}
|
|
582
|
-
function
|
|
697
|
+
function Y(e) {
|
|
583
698
|
let t = [];
|
|
584
|
-
return e = e.replace(/`([^`]+)`/g, (e, n) => (t.push(`<code>${n}</code>`), `\x00CODE${t.length - 1}\x00`)), e = e.replace(/\*\*\*(.+?)\*\*\*/g, "<strong><em>$1</em></strong>"), e = e.replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>"), e = e.replace(/(?<!\*)\*(?!\*)(.+?)(?<!\*)\*(?!\*)/g, "<em>$1</em>"), e = e.replace(/\[([^\]]+)\]\(([^()]*(?:\([^()]*\))*[^()]*)\)/g, (e, t, n) => /^https?:\/\//.test(n) ? `<a href="${n}" target="_blank" rel="noopener noreferrer">${t}</a>` : t), e = e.replace(/\x00CODE(\d+)\x00/g, (e, n) => t[Number(n)]), e;
|
|
699
|
+
return e = e.replace(/`([^`]+)`/g, (e, n) => (t.push(`<code>${n}</code>`), `\x00CODE${t.length - 1}\x00`)), e = e.replace(/\*\*\*(.+?)\*\*\*/g, "<strong><em>$1</em></strong>"), e = e.replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>"), e = e.replace(/(?<!\*)\*(?!\*)(.+?)(?<!\*)\*(?!\*)/g, "<em>$1</em>"), e = e.replace(/~~(.+?)~~/g, "<del>$1</del>"), e = e.replace(/__(.+?)__/g, "<strong>$1</strong>"), e = e.replace(/(^|\s)_(?!_)(.+?)_(?!_)(?=\s|$)/g, "$1<em>$2</em>"), e = e.replace(/\[([^\]]+)\]\(([^()]*(?:\([^()]*\))*[^()]*)\)/g, (e, t, n) => /^https?:\/\//.test(n) ? `<a href="${n}" target="_blank" rel="noopener noreferrer">${t}</a>` : t), e = e.replace(/\x00CODE(\d+)\x00/g, (e, n) => t[Number(n)]), e;
|
|
585
700
|
}
|
|
586
|
-
function
|
|
701
|
+
function X(e) {
|
|
587
702
|
return /^\|[\s\-:|]+\|$/.test(e);
|
|
588
703
|
}
|
|
589
|
-
function
|
|
704
|
+
function Z(e) {
|
|
590
705
|
return e.replace(/^\|/, "").replace(/\|$/, "").split("|").map((e) => e.trim());
|
|
591
706
|
}
|
|
592
|
-
function
|
|
593
|
-
let t =
|
|
707
|
+
function re(e) {
|
|
708
|
+
let t = J(e).replace(/\x00/g, "").split("\n"), n = [], r = 0;
|
|
594
709
|
for (; r < t.length;) {
|
|
595
710
|
let e = t[r].trim();
|
|
596
711
|
if (e.startsWith("|") && e.endsWith("|")) {
|
|
597
712
|
let e = [];
|
|
598
713
|
for (; r < t.length && t[r].trim().startsWith("|") && t[r].trim().endsWith("|");) e.push(t[r].trim()), r++;
|
|
599
|
-
let i = e.findIndex(
|
|
600
|
-
a.length > 0 && (s += "<thead>" + a.map((e) => "<tr>" +
|
|
714
|
+
let i = e.findIndex(X), a = i > 0 ? e.slice(0, i) : [], o = i >= 0 ? e.slice(i + 1) : e, s = "<table>";
|
|
715
|
+
a.length > 0 && (s += "<thead>" + a.map((e) => "<tr>" + Z(e).map((e) => `<th>${Y(e)}</th>`).join("") + "</tr>").join("") + "</thead>"), o.length > 0 && (s += "<tbody>" + o.map((e) => "<tr>" + Z(e).map((e) => `<td>${Y(e)}</td>`).join("") + "</tr>").join("") + "</tbody>"), s += "</table>", n.push(s);
|
|
716
|
+
continue;
|
|
717
|
+
}
|
|
718
|
+
if (/^-{3,}$/.test(e)) {
|
|
719
|
+
n.push("<hr>"), r++;
|
|
720
|
+
continue;
|
|
721
|
+
}
|
|
722
|
+
let i = e.match(/^(#{1,6})\s+(.*)$/);
|
|
723
|
+
if (i) {
|
|
724
|
+
let e = i[1].length;
|
|
725
|
+
n.push(`<h${e}>${Y(i[2])}</h${e}>`), r++;
|
|
601
726
|
continue;
|
|
602
727
|
}
|
|
603
728
|
if (/^[-*]\s/.test(e)) {
|
|
604
729
|
let e = [];
|
|
605
730
|
for (; r < t.length && /^\s*[-*]\s/.test(t[r]);) e.push(t[r].trim().replace(/^[-*]\s+/, "")), r++;
|
|
606
|
-
n.push("<ul>" + e.map((e) => `<li>${
|
|
731
|
+
n.push("<ul>" + e.map((e) => `<li>${Y(e)}</li>`).join("") + "</ul>");
|
|
607
732
|
continue;
|
|
608
733
|
}
|
|
609
734
|
if (/^\d+\.\s/.test(e)) {
|
|
610
735
|
let e = [];
|
|
611
736
|
for (; r < t.length && /^\s*\d+\.\s/.test(t[r]);) e.push(t[r].trim().replace(/^\d+\.\s+/, "")), r++;
|
|
612
|
-
n.push("<ol>" + e.map((e) => `<li>${
|
|
737
|
+
n.push("<ol>" + e.map((e) => `<li>${Y(e)}</li>`).join("") + "</ol>");
|
|
613
738
|
continue;
|
|
614
739
|
}
|
|
615
740
|
if (e === "") {
|
|
616
741
|
n.push("<br>"), r++;
|
|
617
742
|
continue;
|
|
618
743
|
}
|
|
619
|
-
n.push(
|
|
744
|
+
n.push(Y(e)), n.push("<br>"), r++;
|
|
620
745
|
}
|
|
621
746
|
for (; n.length > 0 && n[n.length - 1] === "<br>";) n.pop();
|
|
622
747
|
return n.join("");
|
|
623
748
|
}
|
|
624
|
-
function
|
|
625
|
-
let { name:
|
|
626
|
-
function
|
|
627
|
-
e.setAttribute("data-position",
|
|
749
|
+
function ie(e, t, n, r, i, a) {
|
|
750
|
+
let { name: o, design: s } = t, c, l, u, d, f, p, { content: m } = s;
|
|
751
|
+
function h(e) {
|
|
752
|
+
e.setAttribute("data-position", s.layout.position), c = e.attachShadow({ mode: "closed" });
|
|
628
753
|
let t = document.createElement("style");
|
|
629
|
-
t.textContent =
|
|
630
|
-
<span class="icon-chat">${
|
|
631
|
-
<span class="icon-close">${
|
|
632
|
-
`,
|
|
754
|
+
t.textContent = P(s), c.appendChild(t), l = document.createElement("button"), l.className = "bubble", l.setAttribute("aria-label", n.ariaOpenChat), l.innerHTML = `
|
|
755
|
+
<span class="icon-chat">${H}</span>
|
|
756
|
+
<span class="icon-close">${U}</span>
|
|
757
|
+
`, l.addEventListener("click", i), c.appendChild(l), u = document.createElement("div"), u.className = "chat-window", u.setAttribute("role", "dialog"), u.setAttribute("aria-label", `${o} chat`), u.innerHTML = `
|
|
633
758
|
<div class="chat-header">
|
|
634
|
-
<div class="avatar">${
|
|
759
|
+
<div class="avatar">${q(s.avatar)}</div>
|
|
635
760
|
<div class="header-text">
|
|
636
|
-
<span class="bot-name">${
|
|
637
|
-
<span class="bot-status">${
|
|
761
|
+
<span class="bot-name">${J(o)}</span>
|
|
762
|
+
<span class="bot-status">${J(n.statusOnline)}</span>
|
|
638
763
|
</div>
|
|
639
|
-
<button class="close-btn" aria-label="${
|
|
764
|
+
<button class="close-btn" aria-label="${J(n.ariaCloseChat)}">×</button>
|
|
640
765
|
</div>
|
|
641
766
|
<div class="messages" id="messages-container" role="log" aria-live="polite" aria-atomic="false"></div>
|
|
642
767
|
<div class="chat-footer">
|
|
643
768
|
<div class="input-row">
|
|
644
769
|
<textarea
|
|
645
770
|
class="input"
|
|
646
|
-
placeholder="${
|
|
771
|
+
placeholder="${J(m.placeholder || n.inputPlaceholder)}"
|
|
647
772
|
rows="1"
|
|
648
773
|
maxlength="2000"
|
|
649
774
|
aria-label="Message input"
|
|
650
775
|
></textarea>
|
|
651
|
-
<button class="send-btn" aria-label="${
|
|
652
|
-
${
|
|
776
|
+
<button class="send-btn" aria-label="${J(n.ariaSendMessage)}">
|
|
777
|
+
${G}
|
|
653
778
|
</button>
|
|
654
779
|
</div>
|
|
655
|
-
<a class="botiq-badge" href="${
|
|
656
|
-
${
|
|
780
|
+
<a class="botiq-badge" href="${V}" target="_blank" rel="noopener noreferrer">
|
|
781
|
+
${J(n.poweredBy)} <span class="botiq-badge-name">BotIQ</span>
|
|
657
782
|
</a>
|
|
658
783
|
</div>
|
|
659
|
-
`,
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
784
|
+
`, u.querySelector(".close-btn").addEventListener("click", i), d = u.querySelector("#messages-container");
|
|
785
|
+
let r = null;
|
|
786
|
+
d.addEventListener("scroll", () => {
|
|
787
|
+
d.scrollTop <= 48 && !r && (r = setTimeout(() => {
|
|
788
|
+
r = null;
|
|
789
|
+
}, 150), a());
|
|
790
|
+
}), f = u.querySelector(".input"), p = u.querySelector(".send-btn"), f.addEventListener("input", () => {
|
|
791
|
+
f.style.height = "auto", f.style.height = Math.min(f.scrollHeight, 100) + "px";
|
|
792
|
+
}), f.addEventListener("keydown", (e) => {
|
|
793
|
+
e.key === "Enter" && !e.shiftKey && (e.preventDefault(), g());
|
|
794
|
+
}), p.addEventListener("click", g), c.appendChild(u);
|
|
664
795
|
}
|
|
665
|
-
function
|
|
666
|
-
let e =
|
|
667
|
-
!e ||
|
|
796
|
+
function g() {
|
|
797
|
+
let e = f.value.trim();
|
|
798
|
+
!e || p.disabled || (f.value = "", f.style.height = "auto", r(e));
|
|
668
799
|
}
|
|
669
|
-
function
|
|
800
|
+
function _(e) {
|
|
670
801
|
if (e.messages.length === 0 && !e.isLoading) {
|
|
671
|
-
let e =
|
|
672
|
-
|
|
802
|
+
let e = m.suggestionChips.length > 0 ? `<div class="chips">${m.suggestionChips.map((e) => `<button class="chip">${J(e)}</button>`).join("")}</div>` : "";
|
|
803
|
+
d.innerHTML = `
|
|
673
804
|
<div class="empty-state">
|
|
674
|
-
${
|
|
675
|
-
<span class="greeting">${
|
|
805
|
+
${K}
|
|
806
|
+
<span class="greeting">${J(m.greeting || n.defaultGreeting)}</span>
|
|
676
807
|
${e}
|
|
677
808
|
</div>
|
|
678
|
-
`,
|
|
809
|
+
`, d.querySelectorAll(".chip").forEach((e) => {
|
|
679
810
|
e.addEventListener("click", () => r(e.textContent ?? ""));
|
|
680
811
|
});
|
|
681
812
|
return;
|
|
682
813
|
}
|
|
683
814
|
let t = e.messages.map((e) => `
|
|
684
815
|
<div class="message ${e.role}">
|
|
685
|
-
<div class="message-bubble">${e.role === "assistant" ?
|
|
816
|
+
<div class="message-bubble">${e.role === "assistant" ? re(e.content) : J(e.content)}</div>
|
|
686
817
|
</div>
|
|
687
|
-
`).join(""), i = e.isLoading ? "<div class=\"typing\"><span></span><span></span><span></span></div>" : "";
|
|
688
|
-
|
|
818
|
+
`).join(""), i = e.loadingOlder ? "<div class=\"typing\"><span></span><span></span><span></span></div>" : "", a = e.isLoading ? "<div class=\"typing\"><span></span><span></span><span></span></div>" : "", o = d.scrollHeight - d.scrollTop - d.clientHeight < 80, s = d.scrollTop, c = d.scrollHeight;
|
|
819
|
+
d.innerHTML = i + t + a, o ? d.scrollTop = d.scrollHeight : d.scrollTop = B(s, c, d.scrollHeight);
|
|
689
820
|
}
|
|
690
|
-
function
|
|
691
|
-
e.isOpen ? (
|
|
821
|
+
function v(e) {
|
|
822
|
+
e.isOpen ? (u.classList.add("open"), l.classList.add("open"), l.setAttribute("aria-label", n.ariaCloseChat), requestAnimationFrame(() => f.focus())) : (u.classList.remove("open"), l.classList.remove("open"), l.setAttribute("aria-label", n.ariaOpenChat)), p.disabled = e.isLoading, _(e);
|
|
692
823
|
}
|
|
693
824
|
return {
|
|
694
|
-
mount:
|
|
695
|
-
update:
|
|
825
|
+
mount: h,
|
|
826
|
+
update: v
|
|
696
827
|
};
|
|
697
828
|
}
|
|
698
829
|
//#endregion
|
|
699
830
|
//#region src/i18n/vi.ts
|
|
700
|
-
var
|
|
831
|
+
var ae = {
|
|
701
832
|
statusOnline: "Trực tuyến",
|
|
702
833
|
inputPlaceholder: "Nhắn tin...",
|
|
703
834
|
defaultGreeting: "Xin chào! Tôi có thể giúp gì cho bạn?",
|
|
@@ -713,7 +844,7 @@ var V = {
|
|
|
713
844
|
ariaOpenChat: "Mở khung chat",
|
|
714
845
|
ariaCloseChat: "Đóng khung chat",
|
|
715
846
|
ariaSendMessage: "Gửi tin nhắn"
|
|
716
|
-
},
|
|
847
|
+
}, oe = {
|
|
717
848
|
statusOnline: "Online",
|
|
718
849
|
inputPlaceholder: "Type a message...",
|
|
719
850
|
defaultGreeting: "Hello! How can I help you?",
|
|
@@ -732,57 +863,81 @@ var V = {
|
|
|
732
863
|
};
|
|
733
864
|
//#endregion
|
|
734
865
|
//#region src/i18n/index.ts
|
|
735
|
-
function
|
|
736
|
-
return e === "en" ?
|
|
866
|
+
function Q(e) {
|
|
867
|
+
return e === "en" ? oe : ae;
|
|
737
868
|
}
|
|
738
869
|
//#endregion
|
|
739
870
|
//#region src/builds/npm/index.ts
|
|
740
|
-
|
|
871
|
+
var $ = 10;
|
|
872
|
+
function se(e) {
|
|
741
873
|
if (!e.apiKey) return console.warn("[BotIQ] apiKey is required"), () => void 0;
|
|
742
|
-
let t =
|
|
743
|
-
|
|
744
|
-
let
|
|
745
|
-
|
|
746
|
-
let
|
|
747
|
-
|
|
748
|
-
|
|
874
|
+
let t = p(e);
|
|
875
|
+
v();
|
|
876
|
+
let n = t.apiKey.slice(-16), r = y(n), i = b(n, r);
|
|
877
|
+
k({ messages: i });
|
|
878
|
+
let a = I(), o = document.createElement("div");
|
|
879
|
+
document.body.appendChild(o);
|
|
880
|
+
let s = () => void 0, c = !1, l = Q(void 0);
|
|
881
|
+
f(t.apiKey, t.apiUrl).then((e) => {
|
|
882
|
+
if (c) return;
|
|
749
883
|
if (e === null) {
|
|
750
|
-
console.warn("[BotIQ] Widget not authorised on this origin — skipped mount"),
|
|
884
|
+
console.warn("[BotIQ] Widget not authorised on this origin — skipped mount"), o.remove();
|
|
751
885
|
return;
|
|
752
886
|
}
|
|
753
|
-
|
|
754
|
-
let n =
|
|
755
|
-
n.mount(
|
|
887
|
+
l = Q(e.widgetLanguage);
|
|
888
|
+
let n = ie(t, e, l, h, g, m);
|
|
889
|
+
n.mount(o), s = A((e) => n.update(e)), n.update(O()), i.length > 0 && d();
|
|
756
890
|
});
|
|
757
|
-
function
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
891
|
+
function u(e) {
|
|
892
|
+
return {
|
|
893
|
+
role: e.role,
|
|
894
|
+
content: e.content
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
async function d() {
|
|
898
|
+
let e = await ee(t.apiUrl, t.apiKey, r, $);
|
|
899
|
+
e.messages.length > 0 && (a = L(e), k({ messages: e.messages.map(u) }));
|
|
900
|
+
}
|
|
901
|
+
async function m() {
|
|
902
|
+
if (z(a, O().loadingOlder)) {
|
|
903
|
+
k({ loadingOlder: !0 });
|
|
904
|
+
try {
|
|
905
|
+
let e = await te(t.apiUrl, t.apiKey, r, a.oldestCursor, $);
|
|
906
|
+
e.messages.length > 0 && k({ messages: [...e.messages.map(u), ...O().messages] }), a = R(a, e);
|
|
907
|
+
} finally {
|
|
908
|
+
k({ loadingOlder: !1 });
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
function h(e) {
|
|
913
|
+
let i = O();
|
|
914
|
+
if (i.isLoading) return;
|
|
915
|
+
let a = {
|
|
761
916
|
role: "user",
|
|
762
917
|
content: e
|
|
763
918
|
};
|
|
764
|
-
|
|
765
|
-
messages: [...
|
|
919
|
+
k({
|
|
920
|
+
messages: [...i.messages, a],
|
|
766
921
|
isLoading: !0
|
|
767
|
-
}),
|
|
922
|
+
}), S(t.apiUrl, t.apiKey, r, e, i.messages, l).then((e) => {
|
|
768
923
|
let t = {
|
|
769
924
|
role: "assistant",
|
|
770
925
|
content: e
|
|
771
926
|
};
|
|
772
|
-
|
|
773
|
-
messages: [...
|
|
927
|
+
k({
|
|
928
|
+
messages: [...O().messages, t],
|
|
774
929
|
isLoading: !1
|
|
775
|
-
}),
|
|
930
|
+
}), x(n, r, [a, t]);
|
|
776
931
|
}).catch(() => {
|
|
777
|
-
|
|
932
|
+
k({ isLoading: !1 });
|
|
778
933
|
});
|
|
779
934
|
}
|
|
780
|
-
function
|
|
781
|
-
|
|
935
|
+
function g() {
|
|
936
|
+
k({ isOpen: !O().isOpen });
|
|
782
937
|
}
|
|
783
938
|
return () => {
|
|
784
|
-
|
|
939
|
+
c = !0, s(), o.remove();
|
|
785
940
|
};
|
|
786
941
|
}
|
|
787
942
|
//#endregion
|
|
788
|
-
export {
|
|
943
|
+
export { se as t };
|
package/dist/sdk/react.js
CHANGED
package/dist/sdk/vue.js
CHANGED