@leadbot/components 2.21.1 → 2.24.1
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/README.md +50 -3
- package/dist/agentChat-8s9g6Np1.js +379 -0
- package/dist/agentChat-DWRE_Le4.cjs +1 -0
- package/dist/agentChat.d.ts +2 -0
- package/dist/agentChat.d.ts.map +1 -1
- package/dist/buttons-ecViBEJ9.js +85 -0
- package/dist/buttons-rml8Kh8z.cjs +1 -0
- package/dist/buttons.cjs +1 -0
- package/dist/buttons.js +3 -0
- package/dist/chat.cjs +1 -0
- package/dist/chat.js +3 -0
- package/dist/entries/_shared.d.ts +5 -0
- package/dist/entries/_shared.d.ts.map +1 -0
- package/dist/entries/buttons.d.ts +3 -0
- package/dist/entries/buttons.d.ts.map +1 -0
- package/dist/entries/chat.d.ts +3 -0
- package/dist/entries/chat.d.ts.map +1 -0
- package/dist/entries/flow.d.ts +3 -0
- package/dist/entries/flow.d.ts.map +1 -0
- package/dist/entries/form.d.ts +3 -0
- package/dist/entries/form.d.ts.map +1 -0
- package/dist/entries/whatsapp.d.ts +3 -0
- package/dist/entries/whatsapp.d.ts.map +1 -0
- package/dist/flow-BZED8XTR.js +5047 -0
- package/dist/flow-BpPqOZAo.cjs +82 -0
- package/dist/flow.cjs +1 -0
- package/dist/flow.d.ts.map +1 -1
- package/dist/flow.js +3 -0
- package/dist/form-Dc8AaZBV.cjs +1 -0
- package/dist/form-Df53ALbk.js +290 -0
- package/dist/form.cjs +1 -0
- package/dist/form.d.ts +1 -0
- package/dist/form.d.ts.map +1 -1
- package/dist/form.js +3 -0
- package/dist/i18n-DyDsn-Fk.js +93 -0
- package/dist/i18n-gV6rxSod.cjs +1 -0
- package/dist/i18n.d.ts +25 -0
- package/dist/i18n.d.ts.map +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -6779
- package/dist/jsxRuntime.module-CT7yzySL.cjs +1 -0
- package/dist/jsxRuntime.module-DsRxbn3o.js +657 -0
- package/dist/mount.d.ts +38 -2
- package/dist/mount.d.ts.map +1 -1
- package/dist/styles.css +93 -4
- package/dist/useStep.d.ts +47 -1
- package/dist/useStep.d.ts.map +1 -1
- package/dist/whatsapp-B3GO1RDT.cjs +1 -0
- package/dist/whatsapp-DGnyaume.js +128 -0
- package/dist/whatsapp.cjs +1 -0
- package/dist/whatsapp.d.ts +1 -0
- package/dist/whatsapp.d.ts.map +1 -1
- package/dist/whatsapp.js +3 -0
- package/package.json +39 -11
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
} from "@leadbot/components";
|
|
22
22
|
import "@leadbot/components/styles.css";
|
|
23
23
|
|
|
24
|
-
init({ domainKey: "your-domain-key"
|
|
24
|
+
init({ domainKey: "your-domain-key" });
|
|
25
25
|
|
|
26
26
|
const chat = mountAgentChat(document.querySelector("#chat")!, {
|
|
27
27
|
leadbotId: 18,
|
|
@@ -54,8 +54,10 @@ Every mount requires a `leadbotId` — the id of the component leadbot the
|
|
|
54
54
|
component belongs to (each embed can target a different one) — and an `id`,
|
|
55
55
|
the uuid of the published step it renders. Mounts also
|
|
56
56
|
accept `domainKey` / `apiHost` to override the `init()` defaults, a
|
|
57
|
-
`className` for the container, and a `labels` object to
|
|
58
|
-
|
|
57
|
+
`className` for the container, and a `labels` object to override individual UI
|
|
58
|
+
strings. Defaults are not English: every component renders its own copy in the
|
|
59
|
+
language of the bot as published, which arrives with the boot fetch — the
|
|
60
|
+
page's `<html lang>` is only the fallback until it does.
|
|
59
61
|
|
|
60
62
|
`preview` / `previewToken` exist for the dashboard preview of unpublished draft
|
|
61
63
|
flows: `preview` keeps submissions out of the inbox, `previewToken` authorizes
|
|
@@ -63,6 +65,50 @@ the draft. The token is ignored unless `preview` is set, and it must never be
|
|
|
63
65
|
committed into a production build — anyone reading the shipped JS could then
|
|
64
66
|
read your unpublished flows.
|
|
65
67
|
|
|
68
|
+
## Without a bundler (script tag / CDN)
|
|
69
|
+
|
|
70
|
+
One script tag and one container div — no npm, no build step. The bundle boots
|
|
71
|
+
from its own script tag, injects the stylesheet, and mounts every
|
|
72
|
+
`[data-leadbot-step]` container; the component to render comes from the
|
|
73
|
+
published step's own type.
|
|
74
|
+
|
|
75
|
+
```html
|
|
76
|
+
<script
|
|
77
|
+
src="https://cdn.leadbot.com/components.js"
|
|
78
|
+
data-leadbot-domain-key="your-domain-key"
|
|
79
|
+
data-leadbot-api-host="https://collector.example.com"
|
|
80
|
+
data-leadbot-id="18"
|
|
81
|
+
></script>
|
|
82
|
+
|
|
83
|
+
<div data-leadbot-step="chat-step-uuid"></div>
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The full API is on `window.LeadBot` (`init`, every `mount*`, `mountAll`,
|
|
87
|
+
`openWidget`). Container attributes and the rest of the reference live in
|
|
88
|
+
[docs/SDK.md](../../docs/SDK.md).
|
|
89
|
+
|
|
90
|
+
## Module formats and subpath entries
|
|
91
|
+
|
|
92
|
+
The package ships ESM and CommonJS (`require` works, for older Next.js setups
|
|
93
|
+
and CJS toolchains), plus a subpath entry per component:
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
import { init, mountForm } from "@leadbot/components/form";
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
`form`, `chat`, `whatsapp`, `buttons` and `flow` each carry the shared
|
|
100
|
+
configuration surface (`init`, `loadFlow`, `useStep`) and nothing from the
|
|
101
|
+
other components — a form-only page is ~24 kB gzipped instead of ~81 kB. The
|
|
102
|
+
barrel import is tree-shakeable too; the subpath is the guarantee.
|
|
103
|
+
|
|
104
|
+
## Configuration precedence
|
|
105
|
+
|
|
106
|
+
**The value on the mount always wins.** Everything in `init()` is a default;
|
|
107
|
+
an option set on a `mount*()` call overrides it for that mount only, and an
|
|
108
|
+
option left `undefined` overrides nothing. `leadbotId` included — set it once
|
|
109
|
+
in `init()`, and pass it per mount only where an embed belongs to a different
|
|
110
|
+
component leadbot.
|
|
111
|
+
|
|
66
112
|
## Published steps
|
|
67
113
|
|
|
68
114
|
Every component is backed by a published step. Its `id` is the step uuid, and
|
|
@@ -125,6 +171,7 @@ own overrides keep winning either way.
|
|
|
125
171
|
|---|---|---|
|
|
126
172
|
| `--leadbot-primary` | `#2563eb` | Buttons, accents, user chat bubbles, focus rings |
|
|
127
173
|
| `--leadbot-available-height` | `600px` | Max height of chat / form panels |
|
|
174
|
+
| `--leadbot-chat-height` | `520px` | Fixed height of the chat panel — it never grows or shrinks with the conversation. Capped by the available height |
|
|
128
175
|
| `--leadbot-form-max-width` | `360px` | Form card width cap; set `none` for full width |
|
|
129
176
|
| `--leadbot-form-max-height` | *available height* | Form card height cap; set `none` to never scroll |
|
|
130
177
|
| `--leadbot-font-family` | *page default* | Type stack; undeclared so your page's font shows through |
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
import { b as e, d as t, g as n, h as r, i, l as a, n as o, o as s, r as c, t as l, x as u } from "./jsxRuntime.module-DsRxbn3o.js";
|
|
2
|
+
import { i as d, t as f } from "./i18n-DyDsn-Fk.js";
|
|
3
|
+
import { CHAT_ERROR_CODE_MAP as ee, FIXED_ANSWER_TYPING_MS as te, generateUUID as p, getOrCreateVisitorId as m, getVariableValue as h, sanitizeConversationStarters as g, sendChatExchange as ne, setActiveChatSession as re, streamChat as ie } from "@leadbot/core";
|
|
4
|
+
//#region src/agentChat.tsx
|
|
5
|
+
var _ = f("en"), v = /\[\[C(\d+)\]\]/g;
|
|
6
|
+
function ae(e) {
|
|
7
|
+
return e.replace(v, "");
|
|
8
|
+
}
|
|
9
|
+
function y(e, t) {
|
|
10
|
+
if (!t?.length) return [];
|
|
11
|
+
let n = new Map(t.map((e) => [e.chunk_id, e])), r = /* @__PURE__ */ new Set(), i = [];
|
|
12
|
+
for (let t of e.matchAll(v)) {
|
|
13
|
+
let e = parseInt(t[1], 10), a = n.get(e);
|
|
14
|
+
!a || r.has(e) || (r.add(e), /^https?:\/\//i.test(a.filename) && i.push({
|
|
15
|
+
index: i.length + 1,
|
|
16
|
+
url: a.filename
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
19
|
+
return i;
|
|
20
|
+
}
|
|
21
|
+
function b(e, t) {
|
|
22
|
+
let n = e[e.length - 1];
|
|
23
|
+
return n?.role === "assistant" ? [...e.slice(0, -1), {
|
|
24
|
+
...n,
|
|
25
|
+
content: n.content + t
|
|
26
|
+
}] : [...e, {
|
|
27
|
+
role: "assistant",
|
|
28
|
+
content: t
|
|
29
|
+
}];
|
|
30
|
+
}
|
|
31
|
+
function x(n) {
|
|
32
|
+
let _ = d(n), v = {
|
|
33
|
+
...f(_),
|
|
34
|
+
...n.labels
|
|
35
|
+
}, { step: x, missing: S, forbidden: C } = i(n), w = x?.attributes ?? {}, oe = w.agent_id ?? "", T = n.initialMessage ?? w.initial_message, E = n.eventLabel ?? x?.event_label ?? void 0, [D, se] = a([]), [O, k] = a(!1), [A, j] = a(null), [M, N] = a(!1), [P, F] = a(!1), I = s(null), L = s(null), R = s(D), z = s(null), B = s(null), V = s(n.chatSessionId ?? p()), H = s(n);
|
|
36
|
+
H.current = n;
|
|
37
|
+
let U = s(E);
|
|
38
|
+
U.current = E;
|
|
39
|
+
let W = (e) => {
|
|
40
|
+
se((t) => {
|
|
41
|
+
let n = typeof e == "function" ? e(t) : e;
|
|
42
|
+
return R.current = n, n;
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
t(() => {
|
|
46
|
+
setTimeout(() => {
|
|
47
|
+
L.current && (L.current.scrollTop = L.current.scrollHeight);
|
|
48
|
+
}, 0);
|
|
49
|
+
}, [
|
|
50
|
+
D,
|
|
51
|
+
O,
|
|
52
|
+
A
|
|
53
|
+
]), t(() => {
|
|
54
|
+
T && R.current.length === 0 && W([{
|
|
55
|
+
role: "assistant",
|
|
56
|
+
content: T
|
|
57
|
+
}]);
|
|
58
|
+
}, [T]), t(() => () => {
|
|
59
|
+
z.current?.abort(), B.current && clearTimeout(B.current);
|
|
60
|
+
}, []);
|
|
61
|
+
let G = (e) => v[e] ?? v.chatbot_error_default, K = (e) => {
|
|
62
|
+
let t = G(e), n = R.current, r = n[n.length - 1];
|
|
63
|
+
r?.role === "assistant" && r.content === "" ? W([...n.slice(0, -1), {
|
|
64
|
+
role: "assistant",
|
|
65
|
+
content: t
|
|
66
|
+
}]) : W([...n, {
|
|
67
|
+
role: "assistant",
|
|
68
|
+
content: t
|
|
69
|
+
}]);
|
|
70
|
+
}, q = (e) => {
|
|
71
|
+
let t = R.current, n = t[t.length - 1];
|
|
72
|
+
if (n?.role !== "assistant") return;
|
|
73
|
+
if (n.content === "") {
|
|
74
|
+
W(t.slice(0, -1));
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
let r = e.length > 0 ? {
|
|
78
|
+
...n,
|
|
79
|
+
citations: e
|
|
80
|
+
} : n;
|
|
81
|
+
W([...t.slice(0, -1), r]), H.current.onMessage?.(r);
|
|
82
|
+
}, J = () => (re(V.current), V.current), Y = async (t) => {
|
|
83
|
+
if (O) return;
|
|
84
|
+
let n = {
|
|
85
|
+
role: "user",
|
|
86
|
+
content: t
|
|
87
|
+
}, i = [...R.current, n];
|
|
88
|
+
H.current.onMessage?.(n), W([...i, {
|
|
89
|
+
role: "assistant",
|
|
90
|
+
content: ""
|
|
91
|
+
}]), k(!0), j("thinking");
|
|
92
|
+
let a = new AbortController();
|
|
93
|
+
z.current = a;
|
|
94
|
+
let o = [], s = !1;
|
|
95
|
+
try {
|
|
96
|
+
let t = u(H.current), n = i.map((e) => ({
|
|
97
|
+
role: e.role,
|
|
98
|
+
content: e.content
|
|
99
|
+
})), c = ie({
|
|
100
|
+
url: t.buildUrl("/client/chat/stream"),
|
|
101
|
+
domainKey: t.domainKey ?? "",
|
|
102
|
+
leadbotId: H.current.leadbotId,
|
|
103
|
+
stepUuid: H.current.id,
|
|
104
|
+
visitorId: m(),
|
|
105
|
+
chatSessionId: J(),
|
|
106
|
+
messages: n,
|
|
107
|
+
eventLabel: U.current,
|
|
108
|
+
analytics: r(),
|
|
109
|
+
...e(H.current),
|
|
110
|
+
signal: a.signal
|
|
111
|
+
});
|
|
112
|
+
for await (let e of c) {
|
|
113
|
+
if (e.type === "reasoning") {
|
|
114
|
+
s = !0, j("thinking");
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (s && (s = !1, j("searching"), await new Promise((e) => setTimeout(e, 0))), e.type === "token" && typeof e.content == "string") j(null), W((t) => b(t, e.content)), await new Promise((e) => setTimeout(e, 0));
|
|
118
|
+
else if (e.type === "correction" && typeof e.content == "string") W((t) => {
|
|
119
|
+
let n = t[t.length - 1];
|
|
120
|
+
return n?.role === "assistant" ? [...t.slice(0, -1), {
|
|
121
|
+
...n,
|
|
122
|
+
content: e.content
|
|
123
|
+
}] : [...t, {
|
|
124
|
+
role: "assistant",
|
|
125
|
+
content: e.content
|
|
126
|
+
}];
|
|
127
|
+
}), await new Promise((e) => setTimeout(e, 0));
|
|
128
|
+
else if (e.type === "citations" && Array.isArray(e.citations)) o = e.citations;
|
|
129
|
+
else if (e.type === "tool_call") j("tool"), await new Promise((e) => setTimeout(e, 0));
|
|
130
|
+
else if (e.type === "done") {
|
|
131
|
+
q(o);
|
|
132
|
+
break;
|
|
133
|
+
} else if (e.type === "error") {
|
|
134
|
+
q([]), K(ee[e.error_code ?? ""] || "chatbot_error_default"), H.current.onError?.(Error(e.error_code || "chatbot_error_default"));
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
} catch (e) {
|
|
139
|
+
e instanceof DOMException && e.name === "AbortError" || (q([]), K(e instanceof Error && e.message.startsWith("chatbot_error_") ? e.message : "chatbot_error_default"), H.current.onError?.(e));
|
|
140
|
+
} finally {
|
|
141
|
+
k(!1), j(null), z.current = null;
|
|
142
|
+
}
|
|
143
|
+
}, ce = (t) => {
|
|
144
|
+
if (O) return;
|
|
145
|
+
if (!t.answer) return void Y(t.question);
|
|
146
|
+
let n = {
|
|
147
|
+
role: "user",
|
|
148
|
+
content: t.question
|
|
149
|
+
}, i = {
|
|
150
|
+
role: "assistant",
|
|
151
|
+
content: t.answer
|
|
152
|
+
}, a = [...R.current, n];
|
|
153
|
+
ne(u(H.current), {
|
|
154
|
+
leadbotId: H.current.leadbotId,
|
|
155
|
+
stepUuid: H.current.id,
|
|
156
|
+
visitorId: m(),
|
|
157
|
+
chatSessionId: J(),
|
|
158
|
+
messages: a.map((e) => ({
|
|
159
|
+
role: e.role,
|
|
160
|
+
content: e.content
|
|
161
|
+
})),
|
|
162
|
+
answer: t.answer,
|
|
163
|
+
eventLabel: U.current,
|
|
164
|
+
analytics: r(),
|
|
165
|
+
...e(H.current)
|
|
166
|
+
}), H.current.onMessage?.(n), W(a), k(!0), B.current = setTimeout(() => {
|
|
167
|
+
B.current = null, k(!1), W([...R.current, i]), H.current.onMessage?.(i);
|
|
168
|
+
}, te);
|
|
169
|
+
}, le = (e) => {
|
|
170
|
+
e.preventDefault();
|
|
171
|
+
let t = I.current?.value?.trim();
|
|
172
|
+
!t || O || (I.current.value = "", F(!1), Y(t));
|
|
173
|
+
}, X = () => {
|
|
174
|
+
z.current?.abort(), z.current = null, V.current = H.current.chatSessionId ?? p(), k(!1), j(null), N(!1), W(T ? [{
|
|
175
|
+
role: "assistant",
|
|
176
|
+
content: T
|
|
177
|
+
}] : []);
|
|
178
|
+
}, Z = A === "searching" ? v.searching : A === "tool" ? v.usingTool : v.thinking, Q = D[D.length - 1], ue = O && A !== null && Q?.role === "assistant" && Q.content !== "", de = D.some((e) => e.role !== "assistant"), $ = n.conversationStarters ? n.conversationStarters.map((e) => ({
|
|
179
|
+
question: e,
|
|
180
|
+
answer: null
|
|
181
|
+
})) : g(w.conversation_starters), fe = $.length > 0 && !de && !O;
|
|
182
|
+
return oe ? /* @__PURE__ */ l("div", {
|
|
183
|
+
className: "leadbot-chatbot-interface",
|
|
184
|
+
children: [
|
|
185
|
+
/* @__PURE__ */ l("div", {
|
|
186
|
+
className: "leadbot-chatbot-header",
|
|
187
|
+
children: [
|
|
188
|
+
/* @__PURE__ */ l("div", {
|
|
189
|
+
className: "leadbot-chatbot-header-info",
|
|
190
|
+
children: [/* @__PURE__ */ l("div", {
|
|
191
|
+
className: "leadbot-chatbot-title",
|
|
192
|
+
children: v.title
|
|
193
|
+
}), /* @__PURE__ */ l("div", {
|
|
194
|
+
className: "leadbot-chatbot-status",
|
|
195
|
+
children: [/* @__PURE__ */ l("span", { className: "leadbot-chatbot-online-dot" }), /* @__PURE__ */ l("span", { children: v.status })]
|
|
196
|
+
})]
|
|
197
|
+
}),
|
|
198
|
+
/* @__PURE__ */ l("button", {
|
|
199
|
+
type: "button",
|
|
200
|
+
className: "leadbot-chatbot-menu-btn",
|
|
201
|
+
"aria-label": v.menu,
|
|
202
|
+
onClick: () => N(!M),
|
|
203
|
+
children: /* @__PURE__ */ l("svg", {
|
|
204
|
+
width: "18",
|
|
205
|
+
height: "18",
|
|
206
|
+
viewBox: "0 0 20 20",
|
|
207
|
+
fill: "none",
|
|
208
|
+
children: [
|
|
209
|
+
/* @__PURE__ */ l("circle", {
|
|
210
|
+
cx: "10",
|
|
211
|
+
cy: "4",
|
|
212
|
+
r: "1.5",
|
|
213
|
+
fill: "currentColor"
|
|
214
|
+
}),
|
|
215
|
+
/* @__PURE__ */ l("circle", {
|
|
216
|
+
cx: "10",
|
|
217
|
+
cy: "10",
|
|
218
|
+
r: "1.5",
|
|
219
|
+
fill: "currentColor"
|
|
220
|
+
}),
|
|
221
|
+
/* @__PURE__ */ l("circle", {
|
|
222
|
+
cx: "10",
|
|
223
|
+
cy: "16",
|
|
224
|
+
r: "1.5",
|
|
225
|
+
fill: "currentColor"
|
|
226
|
+
})
|
|
227
|
+
]
|
|
228
|
+
})
|
|
229
|
+
}),
|
|
230
|
+
M && /* @__PURE__ */ l("div", {
|
|
231
|
+
className: "leadbot-chatbot-menu",
|
|
232
|
+
children: /* @__PURE__ */ l("button", {
|
|
233
|
+
type: "button",
|
|
234
|
+
className: "leadbot-chatbot-menu-item",
|
|
235
|
+
onClick: X,
|
|
236
|
+
children: [/* @__PURE__ */ l("span", {
|
|
237
|
+
className: "leadbot-chatbot-menu-item-icon",
|
|
238
|
+
children: /* @__PURE__ */ l("svg", {
|
|
239
|
+
width: "14",
|
|
240
|
+
height: "14",
|
|
241
|
+
viewBox: "0 0 24 24",
|
|
242
|
+
fill: "none",
|
|
243
|
+
children: /* @__PURE__ */ l("path", {
|
|
244
|
+
d: "M3 12a9 9 0 1 0 3-6.7M3 4v5h5",
|
|
245
|
+
stroke: "currentColor",
|
|
246
|
+
strokeWidth: "2",
|
|
247
|
+
strokeLinecap: "round",
|
|
248
|
+
strokeLinejoin: "round"
|
|
249
|
+
})
|
|
250
|
+
})
|
|
251
|
+
}), /* @__PURE__ */ l("span", { children: v.reset })]
|
|
252
|
+
})
|
|
253
|
+
})
|
|
254
|
+
]
|
|
255
|
+
}),
|
|
256
|
+
/* @__PURE__ */ l("div", {
|
|
257
|
+
className: "leadbot-chatbot-messages",
|
|
258
|
+
ref: L,
|
|
259
|
+
children: [D.map((e, t) => {
|
|
260
|
+
if (e.role === "user") return /* @__PURE__ */ l("div", {
|
|
261
|
+
className: "leadbot-chatbot-message leadbot-chatbot-message-user",
|
|
262
|
+
children: /* @__PURE__ */ l("div", {
|
|
263
|
+
className: "leadbot-chatbot-message-content",
|
|
264
|
+
children: e.content
|
|
265
|
+
})
|
|
266
|
+
}, t);
|
|
267
|
+
if (O && e.content === "" && t === D.length - 1) return /* @__PURE__ */ l("div", {
|
|
268
|
+
className: "leadbot-chatbot-message leadbot-chatbot-message-bot leadbot-chatbot-message-typing",
|
|
269
|
+
children: /* @__PURE__ */ l("div", {
|
|
270
|
+
className: "leadbot-chatbot-thinking",
|
|
271
|
+
children: [/* @__PURE__ */ l("span", {
|
|
272
|
+
className: "leadbot-chatbot-typing-dots",
|
|
273
|
+
children: [
|
|
274
|
+
/* @__PURE__ */ l("span", {}),
|
|
275
|
+
/* @__PURE__ */ l("span", {}),
|
|
276
|
+
/* @__PURE__ */ l("span", {})
|
|
277
|
+
]
|
|
278
|
+
}), /* @__PURE__ */ l("span", {
|
|
279
|
+
className: "leadbot-chatbot-thinking-text",
|
|
280
|
+
children: [Z, "..."]
|
|
281
|
+
})]
|
|
282
|
+
})
|
|
283
|
+
}, t);
|
|
284
|
+
let n = y(e.content, e.citations);
|
|
285
|
+
return /* @__PURE__ */ l("div", {
|
|
286
|
+
className: "leadbot-chatbot-message leadbot-chatbot-message-bot",
|
|
287
|
+
children: [/* @__PURE__ */ l("div", {
|
|
288
|
+
className: "leadbot-chatbot-message-content",
|
|
289
|
+
children: ae(e.content)
|
|
290
|
+
}), n.length > 0 && /* @__PURE__ */ l("div", {
|
|
291
|
+
className: "leadbot-chatbot-citations",
|
|
292
|
+
children: n.map((e) => /* @__PURE__ */ l("a", {
|
|
293
|
+
href: e.url,
|
|
294
|
+
target: "_blank",
|
|
295
|
+
rel: "noopener noreferrer",
|
|
296
|
+
className: "leadbot-chatbot-citation-item",
|
|
297
|
+
children: [/* @__PURE__ */ l("span", {
|
|
298
|
+
className: "leadbot-chatbot-citation-number",
|
|
299
|
+
children: e.index
|
|
300
|
+
}), /* @__PURE__ */ l("span", {
|
|
301
|
+
className: "leadbot-chatbot-citation-url",
|
|
302
|
+
children: e.url.replace(/^https?:\/\//, "")
|
|
303
|
+
})]
|
|
304
|
+
}, e.index))
|
|
305
|
+
})]
|
|
306
|
+
}, t);
|
|
307
|
+
}), ue && /* @__PURE__ */ l("div", {
|
|
308
|
+
className: "leadbot-chatbot-message leadbot-chatbot-message-bot leadbot-chatbot-message-typing",
|
|
309
|
+
children: /* @__PURE__ */ l("div", {
|
|
310
|
+
className: "leadbot-chatbot-thinking",
|
|
311
|
+
children: [/* @__PURE__ */ l("span", {
|
|
312
|
+
className: "leadbot-chatbot-typing-dots",
|
|
313
|
+
children: [
|
|
314
|
+
/* @__PURE__ */ l("span", {}),
|
|
315
|
+
/* @__PURE__ */ l("span", {}),
|
|
316
|
+
/* @__PURE__ */ l("span", {})
|
|
317
|
+
]
|
|
318
|
+
}), /* @__PURE__ */ l("span", {
|
|
319
|
+
className: "leadbot-chatbot-thinking-text",
|
|
320
|
+
children: [Z, "..."]
|
|
321
|
+
})]
|
|
322
|
+
})
|
|
323
|
+
})]
|
|
324
|
+
}),
|
|
325
|
+
fe && /* @__PURE__ */ l("div", {
|
|
326
|
+
className: "leadbot-chatbot-starters",
|
|
327
|
+
children: $.map((e) => /* @__PURE__ */ l("button", {
|
|
328
|
+
type: "button",
|
|
329
|
+
className: "leadbot-chatbot-starter-btn",
|
|
330
|
+
disabled: O,
|
|
331
|
+
onClick: () => ce(e),
|
|
332
|
+
children: e.question
|
|
333
|
+
}, e.question))
|
|
334
|
+
}),
|
|
335
|
+
/* @__PURE__ */ l("div", {
|
|
336
|
+
className: "leadbot-chatbot-input",
|
|
337
|
+
children: /* @__PURE__ */ l("form", {
|
|
338
|
+
className: "leadbot-chatbot-input-field",
|
|
339
|
+
onSubmit: le,
|
|
340
|
+
children: [/* @__PURE__ */ l("input", {
|
|
341
|
+
ref: I,
|
|
342
|
+
type: "text",
|
|
343
|
+
placeholder: n.placeholder ?? h("chatbot_placeholder", _),
|
|
344
|
+
className: "leadbot-chatbot-message-input",
|
|
345
|
+
disabled: O,
|
|
346
|
+
onInput: () => F(!!I.current?.value?.trim())
|
|
347
|
+
}), /* @__PURE__ */ l("button", {
|
|
348
|
+
type: "submit",
|
|
349
|
+
"aria-label": v.send,
|
|
350
|
+
className: `leadbot-chatbot-send-btn${P && !O ? " leadbot-chatbot-send-btn--active" : ""}`,
|
|
351
|
+
disabled: O || !P,
|
|
352
|
+
children: /* @__PURE__ */ l("svg", {
|
|
353
|
+
width: "20",
|
|
354
|
+
height: "20",
|
|
355
|
+
viewBox: "0 0 20 20",
|
|
356
|
+
fill: "none",
|
|
357
|
+
children: /* @__PURE__ */ l("path", {
|
|
358
|
+
d: "M10 4L10 16M10 4L5 9M10 4L15 9",
|
|
359
|
+
stroke: "currentColor",
|
|
360
|
+
strokeWidth: "2",
|
|
361
|
+
strokeLinecap: "round",
|
|
362
|
+
strokeLinejoin: "round"
|
|
363
|
+
})
|
|
364
|
+
})
|
|
365
|
+
})]
|
|
366
|
+
})
|
|
367
|
+
})
|
|
368
|
+
]
|
|
369
|
+
}) : S ? /* @__PURE__ */ l(o, {
|
|
370
|
+
...c(n),
|
|
371
|
+
forbidden: C,
|
|
372
|
+
lang: _
|
|
373
|
+
}) : null;
|
|
374
|
+
}
|
|
375
|
+
function S(e, t) {
|
|
376
|
+
return n(x, e, t);
|
|
377
|
+
}
|
|
378
|
+
//#endregion
|
|
379
|
+
export { _ as n, S as r, x as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require("./jsxRuntime.module-CT7yzySL.cjs"),t=require("./i18n-gV6rxSod.cjs");let n=require("@leadbot/core");var r=t.t(`en`),i=/\[\[C(\d+)\]\]/g;function a(e){return e.replace(i,``)}function o(e,t){if(!t?.length)return[];let n=new Map(t.map(e=>[e.chunk_id,e])),r=new Set,a=[];for(let t of e.matchAll(i)){let e=parseInt(t[1],10),i=n.get(e);!i||r.has(e)||(r.add(e),/^https?:\/\//i.test(i.filename)&&a.push({index:a.length+1,url:i.filename}))}return a}function s(e,t){let n=e[e.length-1];return n?.role===`assistant`?[...e.slice(0,-1),{...n,content:n.content+t}]:[...e,{role:`assistant`,content:t}]}function c(r){let i=t.i(r),c={...t.t(i),...r.labels},{step:l,missing:u,forbidden:d}=e.i(r),f=l?.attributes??{},p=f.agent_id??``,m=r.initialMessage??f.initial_message,h=r.eventLabel??l?.event_label??void 0,[g,_]=e.l([]),[v,y]=e.l(!1),[b,x]=e.l(null),[S,C]=e.l(!1),[w,T]=e.l(!1),E=e.o(null),D=e.o(null),O=e.o(g),k=e.o(null),A=e.o(null),j=e.o(r.chatSessionId??(0,n.generateUUID)()),M=e.o(r);M.current=r;let N=e.o(h);N.current=h;let P=e=>{_(t=>{let n=typeof e==`function`?e(t):e;return O.current=n,n})};e.d(()=>{setTimeout(()=>{D.current&&(D.current.scrollTop=D.current.scrollHeight)},0)},[g,v,b]),e.d(()=>{m&&O.current.length===0&&P([{role:`assistant`,content:m}])},[m]),e.d(()=>()=>{k.current?.abort(),A.current&&clearTimeout(A.current)},[]);let F=e=>c[e]??c.chatbot_error_default,I=e=>{let t=F(e),n=O.current,r=n[n.length-1];r?.role===`assistant`&&r.content===``?P([...n.slice(0,-1),{role:`assistant`,content:t}]):P([...n,{role:`assistant`,content:t}])},L=e=>{let t=O.current,n=t[t.length-1];if(n?.role!==`assistant`)return;if(n.content===``){P(t.slice(0,-1));return}let r=e.length>0?{...n,citations:e}:n;P([...t.slice(0,-1),r]),M.current.onMessage?.(r)},R=()=>((0,n.setActiveChatSession)(j.current),j.current),z=async t=>{if(v)return;let r={role:`user`,content:t},i=[...O.current,r];M.current.onMessage?.(r),P([...i,{role:`assistant`,content:``}]),y(!0),x(`thinking`);let a=new AbortController;k.current=a;let o=[],c=!1;try{let t=e.b(M.current),r=i.map(e=>({role:e.role,content:e.content})),l=(0,n.streamChat)({url:t.buildUrl(`/client/chat/stream`),domainKey:t.domainKey??``,leadbotId:M.current.leadbotId,stepUuid:M.current.id,visitorId:(0,n.getOrCreateVisitorId)(),chatSessionId:R(),messages:r,eventLabel:N.current,analytics:(0,n.buildAnalytics)(),...e.y(M.current),signal:a.signal});for await(let e of l){if(e.type===`reasoning`){c=!0,x(`thinking`);continue}if(c&&(c=!1,x(`searching`),await new Promise(e=>setTimeout(e,0))),e.type===`token`&&typeof e.content==`string`)x(null),P(t=>s(t,e.content)),await new Promise(e=>setTimeout(e,0));else if(e.type===`correction`&&typeof e.content==`string`)P(t=>{let n=t[t.length-1];return n?.role===`assistant`?[...t.slice(0,-1),{...n,content:e.content}]:[...t,{role:`assistant`,content:e.content}]}),await new Promise(e=>setTimeout(e,0));else if(e.type===`citations`&&Array.isArray(e.citations))o=e.citations;else if(e.type===`tool_call`)x(`tool`),await new Promise(e=>setTimeout(e,0));else if(e.type===`done`){L(o);break}else if(e.type===`error`){L([]),I(n.CHAT_ERROR_CODE_MAP[e.error_code??``]||`chatbot_error_default`),M.current.onError?.(Error(e.error_code||`chatbot_error_default`));break}}}catch(e){e instanceof DOMException&&e.name===`AbortError`||(L([]),I(e instanceof Error&&e.message.startsWith(`chatbot_error_`)?e.message:`chatbot_error_default`),M.current.onError?.(e))}finally{y(!1),x(null),k.current=null}},B=t=>{if(v)return;if(!t.answer)return void z(t.question);let r={role:`user`,content:t.question},i={role:`assistant`,content:t.answer},a=[...O.current,r];(0,n.sendChatExchange)(e.b(M.current),{leadbotId:M.current.leadbotId,stepUuid:M.current.id,visitorId:(0,n.getOrCreateVisitorId)(),chatSessionId:R(),messages:a.map(e=>({role:e.role,content:e.content})),answer:t.answer,eventLabel:N.current,analytics:(0,n.buildAnalytics)(),...e.y(M.current)}),M.current.onMessage?.(r),P(a),y(!0),A.current=setTimeout(()=>{A.current=null,y(!1),P([...O.current,i]),M.current.onMessage?.(i)},n.FIXED_ANSWER_TYPING_MS)},V=e=>{e.preventDefault();let t=E.current?.value?.trim();!t||v||(E.current.value=``,T(!1),z(t))},H=()=>{k.current?.abort(),k.current=null,j.current=M.current.chatSessionId??(0,n.generateUUID)(),y(!1),x(null),C(!1),P(m?[{role:`assistant`,content:m}]:[])},U=b===`searching`?c.searching:b===`tool`?c.usingTool:c.thinking,W=g[g.length-1],G=v&&b!==null&&W?.role===`assistant`&&W.content!==``,K=g.some(e=>e.role!==`assistant`),q=r.conversationStarters?r.conversationStarters.map(e=>({question:e,answer:null})):(0,n.sanitizeConversationStarters)(f.conversation_starters),J=q.length>0&&!K&&!v;return p?e.t(`div`,{className:`leadbot-chatbot-interface`,children:[e.t(`div`,{className:`leadbot-chatbot-header`,children:[e.t(`div`,{className:`leadbot-chatbot-header-info`,children:[e.t(`div`,{className:`leadbot-chatbot-title`,children:c.title}),e.t(`div`,{className:`leadbot-chatbot-status`,children:[e.t(`span`,{className:`leadbot-chatbot-online-dot`}),e.t(`span`,{children:c.status})]})]}),e.t(`button`,{type:`button`,className:`leadbot-chatbot-menu-btn`,"aria-label":c.menu,onClick:()=>C(!S),children:e.t(`svg`,{width:`18`,height:`18`,viewBox:`0 0 20 20`,fill:`none`,children:[e.t(`circle`,{cx:`10`,cy:`4`,r:`1.5`,fill:`currentColor`}),e.t(`circle`,{cx:`10`,cy:`10`,r:`1.5`,fill:`currentColor`}),e.t(`circle`,{cx:`10`,cy:`16`,r:`1.5`,fill:`currentColor`})]})}),S&&e.t(`div`,{className:`leadbot-chatbot-menu`,children:e.t(`button`,{type:`button`,className:`leadbot-chatbot-menu-item`,onClick:H,children:[e.t(`span`,{className:`leadbot-chatbot-menu-item-icon`,children:e.t(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,children:e.t(`path`,{d:`M3 12a9 9 0 1 0 3-6.7M3 4v5h5`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})})}),e.t(`span`,{children:c.reset})]})})]}),e.t(`div`,{className:`leadbot-chatbot-messages`,ref:D,children:[g.map((t,n)=>{if(t.role===`user`)return e.t(`div`,{className:`leadbot-chatbot-message leadbot-chatbot-message-user`,children:e.t(`div`,{className:`leadbot-chatbot-message-content`,children:t.content})},n);if(v&&t.content===``&&n===g.length-1)return e.t(`div`,{className:`leadbot-chatbot-message leadbot-chatbot-message-bot leadbot-chatbot-message-typing`,children:e.t(`div`,{className:`leadbot-chatbot-thinking`,children:[e.t(`span`,{className:`leadbot-chatbot-typing-dots`,children:[e.t(`span`,{}),e.t(`span`,{}),e.t(`span`,{})]}),e.t(`span`,{className:`leadbot-chatbot-thinking-text`,children:[U,`...`]})]})},n);let r=o(t.content,t.citations);return e.t(`div`,{className:`leadbot-chatbot-message leadbot-chatbot-message-bot`,children:[e.t(`div`,{className:`leadbot-chatbot-message-content`,children:a(t.content)}),r.length>0&&e.t(`div`,{className:`leadbot-chatbot-citations`,children:r.map(t=>e.t(`a`,{href:t.url,target:`_blank`,rel:`noopener noreferrer`,className:`leadbot-chatbot-citation-item`,children:[e.t(`span`,{className:`leadbot-chatbot-citation-number`,children:t.index}),e.t(`span`,{className:`leadbot-chatbot-citation-url`,children:t.url.replace(/^https?:\/\//,``)})]},t.index))})]},n)}),G&&e.t(`div`,{className:`leadbot-chatbot-message leadbot-chatbot-message-bot leadbot-chatbot-message-typing`,children:e.t(`div`,{className:`leadbot-chatbot-thinking`,children:[e.t(`span`,{className:`leadbot-chatbot-typing-dots`,children:[e.t(`span`,{}),e.t(`span`,{}),e.t(`span`,{})]}),e.t(`span`,{className:`leadbot-chatbot-thinking-text`,children:[U,`...`]})]})})]}),J&&e.t(`div`,{className:`leadbot-chatbot-starters`,children:q.map(t=>e.t(`button`,{type:`button`,className:`leadbot-chatbot-starter-btn`,disabled:v,onClick:()=>B(t),children:t.question},t.question))}),e.t(`div`,{className:`leadbot-chatbot-input`,children:e.t(`form`,{className:`leadbot-chatbot-input-field`,onSubmit:V,children:[e.t(`input`,{ref:E,type:`text`,placeholder:r.placeholder??(0,n.getVariableValue)(`chatbot_placeholder`,i),className:`leadbot-chatbot-message-input`,disabled:v,onInput:()=>T(!!E.current?.value?.trim())}),e.t(`button`,{type:`submit`,"aria-label":c.send,className:`leadbot-chatbot-send-btn${w&&!v?` leadbot-chatbot-send-btn--active`:``}`,disabled:v||!w,children:e.t(`svg`,{width:`20`,height:`20`,viewBox:`0 0 20 20`,fill:`none`,children:e.t(`path`,{d:`M10 4L10 16M10 4L5 9M10 4L15 9`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})})})]})})]}):u?e.t(e.n,{...e.r(r),forbidden:d,lang:i}):null}function l(t,n){return e.h(c,t,n)}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return c}});
|
package/dist/agentChat.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export interface AgentChatLabels {
|
|
|
14
14
|
menu: string;
|
|
15
15
|
thinking: string;
|
|
16
16
|
searching: string;
|
|
17
|
+
usingTool: string;
|
|
17
18
|
chatbot_error_default: string;
|
|
18
19
|
chatbot_error_network: string;
|
|
19
20
|
chatbot_error_invalid_request: string;
|
|
@@ -24,6 +25,7 @@ export interface AgentChatLabels {
|
|
|
24
25
|
chatbot_error_agent_no_response: string;
|
|
25
26
|
chatbot_error_agent_response_failed: string;
|
|
26
27
|
}
|
|
28
|
+
/** English label set; every other language comes from the same table. */
|
|
27
29
|
export declare const DEFAULT_CHAT_LABELS: AgentChatLabels;
|
|
28
30
|
export interface AgentChatOptions extends BaseMountOptions, StepOptions {
|
|
29
31
|
/** Id of the component leadbot this chat belongs to (dashboard → Settings → Components). */
|
package/dist/agentChat.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentChat.d.ts","sourceRoot":"","sources":["../src/agentChat.tsx"],"names":[],"mappings":"AACA,OAAO,EAEN,KAAK,YAAY,
|
|
1
|
+
{"version":3,"file":"agentChat.d.ts","sourceRoot":"","sources":["../src/agentChat.tsx"],"names":[],"mappings":"AACA,OAAO,EAEN,KAAK,YAAY,EAWjB,MAAM,eAAe,CAAC;AACvB,OAAO,EACN,KAAK,gBAAgB,EAGrB,KAAK,WAAW,EAGhB,MAAM,SAAS,CAAC;AAEjB,OAAO,EACN,KAAK,WAAW,EAIhB,MAAM,WAAW,CAAC;AAEnB,MAAM,WAAW,gBAAgB;IAChC,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,YAAY,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,eAAe;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,6BAA6B,EAAE,MAAM,CAAC;IACtC,4BAA4B,EAAE,MAAM,CAAC;IACrC,6BAA6B,EAAE,MAAM,CAAC;IACtC,kCAAkC,EAAE,MAAM,CAAC;IAC3C,+BAA+B,EAAE,MAAM,CAAC;IACxC,+BAA+B,EAAE,MAAM,CAAC;IACxC,mCAAmC,EAAE,MAAM,CAAC;CAC5C;AAED,yEAAyE;AACzE,eAAO,MAAM,mBAAmB,EAAE,eAAkC,CAAC;AAErE,MAAM,WAAW,gBAAiB,SAAQ,gBAAgB,EAAE,WAAW;IACtE,4FAA4F;IAC5F,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;IAClC,6DAA6D;IAC7D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wEAAwE;IACxE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,6DAA6D;IAC7D,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAChD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CACnC;AAuCD,wBAAgB,SAAS,CAAC,KAAK,EAAE,gBAAgB,uCAyehD;AAED,wBAAgB,cAAc,CAC7B,EAAE,EAAE,WAAW,EACf,OAAO,EAAE,gBAAgB,GACvB,WAAW,CAAC,gBAAgB,CAAC,CAE/B"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { a as e, b as t, d as n, g as r, t as i, x as a } from "./jsxRuntime.module-DsRxbn3o.js";
|
|
2
|
+
import { getOrCreateVisitorId as o, getTracker as s, openWidget as c, trackClick as l } from "@leadbot/core";
|
|
3
|
+
//#region src/buttons.tsx
|
|
4
|
+
function u(e) {
|
|
5
|
+
return {
|
|
6
|
+
label: e.label,
|
|
7
|
+
action: e.next_step_uuid ? {
|
|
8
|
+
type: "open_widget",
|
|
9
|
+
stepUuid: e.next_step_uuid,
|
|
10
|
+
message: e.label
|
|
11
|
+
} : void 0
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function d(e) {
|
|
15
|
+
if (e.step_type !== "button") return (e.options ?? []).map(u);
|
|
16
|
+
let { text: t, url: n, target: r, open_widget_step_uuid: i, open_widget_message: a } = e.attributes, { open_widget: o } = e.attributes, s;
|
|
17
|
+
return i || o ? s = {
|
|
18
|
+
type: "open_widget",
|
|
19
|
+
stepUuid: i ?? void 0,
|
|
20
|
+
message: a ?? void 0
|
|
21
|
+
} : n && (s = {
|
|
22
|
+
type: "url",
|
|
23
|
+
href: n,
|
|
24
|
+
target: r === "_blank" ? "_blank" : void 0
|
|
25
|
+
}), [{
|
|
26
|
+
label: t ?? e.label ?? "",
|
|
27
|
+
action: s
|
|
28
|
+
}];
|
|
29
|
+
}
|
|
30
|
+
function f(e) {
|
|
31
|
+
try {
|
|
32
|
+
let { protocol: t } = new URL(e, window.location.href);
|
|
33
|
+
return [
|
|
34
|
+
"http:",
|
|
35
|
+
"https:",
|
|
36
|
+
"tel:",
|
|
37
|
+
"mailto:"
|
|
38
|
+
].includes(t);
|
|
39
|
+
} catch {
|
|
40
|
+
return !1;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function p(r) {
|
|
44
|
+
let u = e(r), p = r.eventLabel ?? u?.event_label ?? void 0, m = u ? d(u) : [], h = r.buttons ? r.buttons.map((e, t) => e.action ? e : {
|
|
45
|
+
...e,
|
|
46
|
+
action: m[t]?.action
|
|
47
|
+
}) : m, g = JSON.stringify(h.map((e) => e.label));
|
|
48
|
+
n(() => {
|
|
49
|
+
let e = JSON.parse(g), t = e.filter((t, n) => e.indexOf(t) !== n);
|
|
50
|
+
t.length > 0 && console.warn(`[leadbot] duplicate button label(s) ${[...new Set(t)].map((e) => `"${e}"`).join(", ")} — labels identify buttons, so duplicates collide`);
|
|
51
|
+
}, [g]);
|
|
52
|
+
let _ = (e) => {
|
|
53
|
+
r.onSelect?.(e), r.id && l(a(r), {
|
|
54
|
+
stepUuid: r.id,
|
|
55
|
+
visitorId: o(),
|
|
56
|
+
...t(r)
|
|
57
|
+
}), s().trackButtonClick({ event_label: p });
|
|
58
|
+
let n = e.action;
|
|
59
|
+
if (n) {
|
|
60
|
+
if (n.type === "open_widget") c({
|
|
61
|
+
stepUuid: n.stepUuid,
|
|
62
|
+
message: n.message
|
|
63
|
+
});
|
|
64
|
+
else if (n.type === "url") {
|
|
65
|
+
if (!f(n.href)) return;
|
|
66
|
+
n.target === "_blank" ? window.open(n.href, "_blank", "noopener,noreferrer") : window.location.href = n.href;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
return h.length === 0 ? null : /* @__PURE__ */ i("div", {
|
|
71
|
+
className: "leadbot-buttons",
|
|
72
|
+
children: h.map((e) => /* @__PURE__ */ i("button", {
|
|
73
|
+
type: "button",
|
|
74
|
+
className: "leadbot-buttons-btn",
|
|
75
|
+
ref: (t) => r.onButtonEl?.(e.label, t),
|
|
76
|
+
onClick: () => _(e),
|
|
77
|
+
children: "children" in e ? e.children : e.label
|
|
78
|
+
}, e.label))
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function m(e, t) {
|
|
82
|
+
return r(p, e, t);
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
export { m as n, p as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require("./jsxRuntime.module-CT7yzySL.cjs");let t=require("@leadbot/core");function n(e){return{label:e.label,action:e.next_step_uuid?{type:`open_widget`,stepUuid:e.next_step_uuid,message:e.label}:void 0}}function r(e){if(e.step_type!==`button`)return(e.options??[]).map(n);let{text:t,url:r,target:i,open_widget_step_uuid:a,open_widget_message:o}=e.attributes,{open_widget:s}=e.attributes,c;return a||s?c={type:`open_widget`,stepUuid:a??void 0,message:o??void 0}:r&&(c={type:`url`,href:r,target:i===`_blank`?`_blank`:void 0}),[{label:t??e.label??``,action:c}]}function i(e){try{let{protocol:t}=new URL(e,window.location.href);return[`http:`,`https:`,`tel:`,`mailto:`].includes(t)}catch{return!1}}function a(n){let a=e.a(n),o=n.eventLabel??a?.event_label??void 0,s=a?r(a):[],c=n.buttons?n.buttons.map((e,t)=>e.action?e:{...e,action:s[t]?.action}):s,l=JSON.stringify(c.map(e=>e.label));e.d(()=>{let e=JSON.parse(l),t=e.filter((t,n)=>e.indexOf(t)!==n);t.length>0&&console.warn(`[leadbot] duplicate button label(s) ${[...new Set(t)].map(e=>`"${e}"`).join(`, `)} — labels identify buttons, so duplicates collide`)},[l]);let u=r=>{n.onSelect?.(r),n.id&&(0,t.trackClick)(e.b(n),{stepUuid:n.id,visitorId:(0,t.getOrCreateVisitorId)(),...e.y(n)}),(0,t.getTracker)().trackButtonClick({event_label:o});let a=r.action;if(a){if(a.type===`open_widget`)(0,t.openWidget)({stepUuid:a.stepUuid,message:a.message});else if(a.type===`url`){if(!i(a.href))return;a.target===`_blank`?window.open(a.href,`_blank`,`noopener,noreferrer`):window.location.href=a.href}}};return c.length===0?null:e.t(`div`,{className:`leadbot-buttons`,children:c.map(t=>e.t(`button`,{type:`button`,className:`leadbot-buttons-btn`,ref:e=>n.onButtonEl?.(t.label,e),onClick:()=>u(t),children:`children`in t?t.children:t.label},t.label))})}function o(t,n){return e.h(a,t,n)}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return a}});
|
package/dist/buttons.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./jsxRuntime.module-CT7yzySL.cjs"),t=require("./buttons-rml8Kh8z.cjs");let n=require("@leadbot/core");exports.ComponentsButtons=t.t,exports.ROOT_CLASS=e.m,Object.defineProperty(exports,"buildAnalytics",{enumerable:!0,get:function(){return n.buildAnalytics}}),exports.init=e._,exports.loadFlow=e.v,exports.mountButtons=t.n,exports.useStep=e.a;
|
package/dist/buttons.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as e, h as t, m as n, v as r, y as i } from "./jsxRuntime.module-DsRxbn3o.js";
|
|
2
|
+
import { n as a, t as o } from "./buttons-ecViBEJ9.js";
|
|
3
|
+
export { o as ComponentsButtons, n as ROOT_CLASS, t as buildAnalytics, r as init, i as loadFlow, a as mountButtons, e as useStep };
|
package/dist/chat.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./jsxRuntime.module-CT7yzySL.cjs"),t=require("./agentChat-DWRE_Le4.cjs");let n=require("@leadbot/core");exports.AgentChat=t.t,exports.DEFAULT_CHAT_LABELS=t.n,exports.ROOT_CLASS=e.m,Object.defineProperty(exports,"buildAnalytics",{enumerable:!0,get:function(){return n.buildAnalytics}}),exports.init=e._,exports.loadFlow=e.v,exports.mountAgentChat=t.r,exports.useStep=e.a;
|
package/dist/chat.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as e, h as t, m as n, v as r, y as i } from "./jsxRuntime.module-DsRxbn3o.js";
|
|
2
|
+
import { n as a, r as o, t as s } from "./agentChat-8s9g6Np1.js";
|
|
3
|
+
export { s as AgentChat, a as DEFAULT_CHAT_LABELS, n as ROOT_CLASS, t as buildAnalytics, r as init, i as loadFlow, o as mountAgentChat, e as useStep };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { buildAnalytics, init, loadFlow, ROOT_CLASS } from "../mount";
|
|
2
|
+
export type { BaseMountOptions, LeadbotComponentsConfig, MountHandle, } from "../mount";
|
|
3
|
+
export { useStep } from "../useStep";
|
|
4
|
+
export type { PublishedStep, StepOptions } from "../useStep";
|
|
5
|
+
//# sourceMappingURL=_shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_shared.d.ts","sourceRoot":"","sources":["../../src/entries/_shared.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtE,YAAY,EACX,gBAAgB,EAChB,uBAAuB,EACvB,WAAW,GACX,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buttons.d.ts","sourceRoot":"","sources":["../../src/entries/buttons.ts"],"names":[],"mappings":"AAGA,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/entries/chat.ts"],"names":[],"mappings":"AAGA,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow.d.ts","sourceRoot":"","sources":["../../src/entries/flow.ts"],"names":[],"mappings":"AAGA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../src/entries/form.ts"],"names":[],"mappings":"AAGA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
|