@leadbot/components 2.24.0 → 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 +1 -0
- package/dist/{agentChat-0mQZrzM9.js → agentChat-8s9g6Np1.js} +118 -105
- package/dist/agentChat-DWRE_Le4.cjs +1 -0
- package/dist/agentChat.d.ts.map +1 -1
- package/dist/chat.cjs +1 -1
- package/dist/chat.js +1 -1
- package/dist/{flow-BY5oslmc.js → flow-BZED8XTR.js} +1133 -1092
- package/dist/flow-BpPqOZAo.cjs +82 -0
- package/dist/flow.cjs +1 -1
- package/dist/flow.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +2 -2
- package/dist/styles.css +14 -3
- package/package.json +2 -2
- package/dist/agentChat-C1wUvNcg.cjs +0 -1
- package/dist/flow-CNUyZA89.cjs +0 -82
package/README.md
CHANGED
|
@@ -171,6 +171,7 @@ own overrides keep winning either way.
|
|
|
171
171
|
|---|---|---|
|
|
172
172
|
| `--leadbot-primary` | `#2563eb` | Buttons, accents, user chat bubbles, focus rings |
|
|
173
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 |
|
|
174
175
|
| `--leadbot-form-max-width` | `360px` | Form card width cap; set `none` for full width |
|
|
175
176
|
| `--leadbot-form-max-height` | *available height* | Form card height cap; set `none` to never scroll |
|
|
176
177
|
| `--leadbot-font-family` | *page default* | Type stack; undeclared so your page's font shows through |
|
|
@@ -1,15 +1,15 @@
|
|
|
1
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
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
|
|
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
4
|
//#region src/agentChat.tsx
|
|
5
|
-
var
|
|
6
|
-
function
|
|
7
|
-
return e.replace(
|
|
5
|
+
var _ = f("en"), v = /\[\[C(\d+)\]\]/g;
|
|
6
|
+
function ae(e) {
|
|
7
|
+
return e.replace(v, "");
|
|
8
8
|
}
|
|
9
|
-
function
|
|
9
|
+
function y(e, t) {
|
|
10
10
|
if (!t?.length) return [];
|
|
11
11
|
let n = new Map(t.map((e) => [e.chunk_id, e])), r = /* @__PURE__ */ new Set(), i = [];
|
|
12
|
-
for (let t of e.matchAll(
|
|
12
|
+
for (let t of e.matchAll(v)) {
|
|
13
13
|
let e = parseInt(t[1], 10), a = n.get(e);
|
|
14
14
|
!a || r.has(e) || (r.add(e), /^https?:\/\//i.test(a.filename) && i.push({
|
|
15
15
|
index: i.length + 1,
|
|
@@ -18,7 +18,7 @@ function x(e, t) {
|
|
|
18
18
|
}
|
|
19
19
|
return i;
|
|
20
20
|
}
|
|
21
|
-
function
|
|
21
|
+
function b(e, t) {
|
|
22
22
|
let n = e[e.length - 1];
|
|
23
23
|
return n?.role === "assistant" ? [...e.slice(0, -1), {
|
|
24
24
|
...n,
|
|
@@ -28,94 +28,94 @@ function S(e, t) {
|
|
|
28
28
|
content: t
|
|
29
29
|
}];
|
|
30
30
|
}
|
|
31
|
-
function
|
|
32
|
-
let
|
|
33
|
-
...f(
|
|
31
|
+
function x(n) {
|
|
32
|
+
let _ = d(n), v = {
|
|
33
|
+
...f(_),
|
|
34
34
|
...n.labels
|
|
35
|
-
}, { step:
|
|
36
|
-
|
|
37
|
-
let
|
|
38
|
-
|
|
39
|
-
let
|
|
40
|
-
|
|
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
41
|
let n = typeof e == "function" ? e(t) : e;
|
|
42
|
-
return
|
|
42
|
+
return R.current = n, n;
|
|
43
43
|
});
|
|
44
44
|
};
|
|
45
45
|
t(() => {
|
|
46
46
|
setTimeout(() => {
|
|
47
|
-
|
|
47
|
+
L.current && (L.current.scrollTop = L.current.scrollHeight);
|
|
48
48
|
}, 0);
|
|
49
49
|
}, [
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
D,
|
|
51
|
+
O,
|
|
52
|
+
A
|
|
53
53
|
]), t(() => {
|
|
54
|
-
|
|
54
|
+
T && R.current.length === 0 && W([{
|
|
55
55
|
role: "assistant",
|
|
56
|
-
content:
|
|
56
|
+
content: T
|
|
57
57
|
}]);
|
|
58
|
-
}, [
|
|
59
|
-
|
|
58
|
+
}, [T]), t(() => () => {
|
|
59
|
+
z.current?.abort(), B.current && clearTimeout(B.current);
|
|
60
60
|
}, []);
|
|
61
|
-
let
|
|
62
|
-
let t =
|
|
63
|
-
r?.role === "assistant" && r.content === "" ?
|
|
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
64
|
role: "assistant",
|
|
65
65
|
content: t
|
|
66
|
-
}]) :
|
|
66
|
+
}]) : W([...n, {
|
|
67
67
|
role: "assistant",
|
|
68
68
|
content: t
|
|
69
69
|
}]);
|
|
70
|
-
},
|
|
71
|
-
let t =
|
|
70
|
+
}, q = (e) => {
|
|
71
|
+
let t = R.current, n = t[t.length - 1];
|
|
72
72
|
if (n?.role !== "assistant") return;
|
|
73
73
|
if (n.content === "") {
|
|
74
|
-
|
|
74
|
+
W(t.slice(0, -1));
|
|
75
75
|
return;
|
|
76
76
|
}
|
|
77
77
|
let r = e.length > 0 ? {
|
|
78
78
|
...n,
|
|
79
79
|
citations: e
|
|
80
80
|
} : n;
|
|
81
|
-
|
|
82
|
-
},
|
|
83
|
-
if (
|
|
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
84
|
let n = {
|
|
85
85
|
role: "user",
|
|
86
86
|
content: t
|
|
87
|
-
}, i = [...
|
|
88
|
-
|
|
87
|
+
}, i = [...R.current, n];
|
|
88
|
+
H.current.onMessage?.(n), W([...i, {
|
|
89
89
|
role: "assistant",
|
|
90
90
|
content: ""
|
|
91
|
-
}]),
|
|
91
|
+
}]), k(!0), j("thinking");
|
|
92
92
|
let a = new AbortController();
|
|
93
|
-
|
|
93
|
+
z.current = a;
|
|
94
94
|
let o = [], s = !1;
|
|
95
95
|
try {
|
|
96
|
-
let t = u(
|
|
96
|
+
let t = u(H.current), n = i.map((e) => ({
|
|
97
97
|
role: e.role,
|
|
98
98
|
content: e.content
|
|
99
|
-
}))
|
|
99
|
+
})), c = ie({
|
|
100
100
|
url: t.buildUrl("/client/chat/stream"),
|
|
101
101
|
domainKey: t.domainKey ?? "",
|
|
102
|
-
leadbotId:
|
|
103
|
-
stepUuid:
|
|
104
|
-
visitorId:
|
|
105
|
-
chatSessionId:
|
|
102
|
+
leadbotId: H.current.leadbotId,
|
|
103
|
+
stepUuid: H.current.id,
|
|
104
|
+
visitorId: m(),
|
|
105
|
+
chatSessionId: J(),
|
|
106
106
|
messages: n,
|
|
107
|
-
eventLabel:
|
|
107
|
+
eventLabel: U.current,
|
|
108
108
|
analytics: r(),
|
|
109
|
-
...e(
|
|
109
|
+
...e(H.current),
|
|
110
110
|
signal: a.signal
|
|
111
111
|
});
|
|
112
112
|
for await (let e of c) {
|
|
113
113
|
if (e.type === "reasoning") {
|
|
114
|
-
s = !0,
|
|
114
|
+
s = !0, j("thinking");
|
|
115
115
|
continue;
|
|
116
116
|
}
|
|
117
|
-
if (s && (s = !1,
|
|
118
|
-
else if (e.type === "correction" && typeof e.content == "string")
|
|
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
119
|
let n = t[t.length - 1];
|
|
120
120
|
return n?.role === "assistant" ? [...t.slice(0, -1), {
|
|
121
121
|
...n,
|
|
@@ -126,47 +126,60 @@ function C(n) {
|
|
|
126
126
|
}];
|
|
127
127
|
}), await new Promise((e) => setTimeout(e, 0));
|
|
128
128
|
else if (e.type === "citations" && Array.isArray(e.citations)) o = e.citations;
|
|
129
|
-
else if (e.type === "tool_call")
|
|
129
|
+
else if (e.type === "tool_call") j("tool"), await new Promise((e) => setTimeout(e, 0));
|
|
130
130
|
else if (e.type === "done") {
|
|
131
|
-
|
|
131
|
+
q(o);
|
|
132
132
|
break;
|
|
133
133
|
} else if (e.type === "error") {
|
|
134
|
-
|
|
134
|
+
q([]), K(ee[e.error_code ?? ""] || "chatbot_error_default"), H.current.onError?.(Error(e.error_code || "chatbot_error_default"));
|
|
135
135
|
break;
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
} catch (e) {
|
|
139
|
-
e instanceof DOMException && e.name === "AbortError" || (
|
|
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
140
|
} finally {
|
|
141
|
-
|
|
141
|
+
k(!1), j(null), z.current = null;
|
|
142
142
|
}
|
|
143
|
-
},
|
|
144
|
-
if (
|
|
145
|
-
if (!
|
|
146
|
-
let
|
|
143
|
+
}, ce = (t) => {
|
|
144
|
+
if (O) return;
|
|
145
|
+
if (!t.answer) return void Y(t.question);
|
|
146
|
+
let n = {
|
|
147
147
|
role: "user",
|
|
148
|
-
content:
|
|
149
|
-
},
|
|
148
|
+
content: t.question
|
|
149
|
+
}, i = {
|
|
150
150
|
role: "assistant",
|
|
151
|
-
content:
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
H.current
|
|
155
|
-
|
|
156
|
-
|
|
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) => {
|
|
157
170
|
e.preventDefault();
|
|
158
|
-
let t =
|
|
159
|
-
!t ||
|
|
160
|
-
},
|
|
161
|
-
|
|
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 ? [{
|
|
162
175
|
role: "assistant",
|
|
163
|
-
content:
|
|
176
|
+
content: T
|
|
164
177
|
}] : []);
|
|
165
|
-
}, Z =
|
|
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) => ({
|
|
166
179
|
question: e,
|
|
167
180
|
answer: null
|
|
168
|
-
})) : g(
|
|
169
|
-
return
|
|
181
|
+
})) : g(w.conversation_starters), fe = $.length > 0 && !de && !O;
|
|
182
|
+
return oe ? /* @__PURE__ */ l("div", {
|
|
170
183
|
className: "leadbot-chatbot-interface",
|
|
171
184
|
children: [
|
|
172
185
|
/* @__PURE__ */ l("div", {
|
|
@@ -176,17 +189,17 @@ function C(n) {
|
|
|
176
189
|
className: "leadbot-chatbot-header-info",
|
|
177
190
|
children: [/* @__PURE__ */ l("div", {
|
|
178
191
|
className: "leadbot-chatbot-title",
|
|
179
|
-
children:
|
|
192
|
+
children: v.title
|
|
180
193
|
}), /* @__PURE__ */ l("div", {
|
|
181
194
|
className: "leadbot-chatbot-status",
|
|
182
|
-
children: [/* @__PURE__ */ l("span", { className: "leadbot-chatbot-online-dot" }), /* @__PURE__ */ l("span", { children:
|
|
195
|
+
children: [/* @__PURE__ */ l("span", { className: "leadbot-chatbot-online-dot" }), /* @__PURE__ */ l("span", { children: v.status })]
|
|
183
196
|
})]
|
|
184
197
|
}),
|
|
185
198
|
/* @__PURE__ */ l("button", {
|
|
186
199
|
type: "button",
|
|
187
200
|
className: "leadbot-chatbot-menu-btn",
|
|
188
|
-
"aria-label":
|
|
189
|
-
onClick: () =>
|
|
201
|
+
"aria-label": v.menu,
|
|
202
|
+
onClick: () => N(!M),
|
|
190
203
|
children: /* @__PURE__ */ l("svg", {
|
|
191
204
|
width: "18",
|
|
192
205
|
height: "18",
|
|
@@ -214,12 +227,12 @@ function C(n) {
|
|
|
214
227
|
]
|
|
215
228
|
})
|
|
216
229
|
}),
|
|
217
|
-
|
|
230
|
+
M && /* @__PURE__ */ l("div", {
|
|
218
231
|
className: "leadbot-chatbot-menu",
|
|
219
232
|
children: /* @__PURE__ */ l("button", {
|
|
220
233
|
type: "button",
|
|
221
234
|
className: "leadbot-chatbot-menu-item",
|
|
222
|
-
onClick:
|
|
235
|
+
onClick: X,
|
|
223
236
|
children: [/* @__PURE__ */ l("span", {
|
|
224
237
|
className: "leadbot-chatbot-menu-item-icon",
|
|
225
238
|
children: /* @__PURE__ */ l("svg", {
|
|
@@ -235,15 +248,15 @@ function C(n) {
|
|
|
235
248
|
strokeLinejoin: "round"
|
|
236
249
|
})
|
|
237
250
|
})
|
|
238
|
-
}), /* @__PURE__ */ l("span", { children:
|
|
251
|
+
}), /* @__PURE__ */ l("span", { children: v.reset })]
|
|
239
252
|
})
|
|
240
253
|
})
|
|
241
254
|
]
|
|
242
255
|
}),
|
|
243
256
|
/* @__PURE__ */ l("div", {
|
|
244
257
|
className: "leadbot-chatbot-messages",
|
|
245
|
-
ref:
|
|
246
|
-
children: [
|
|
258
|
+
ref: L,
|
|
259
|
+
children: [D.map((e, t) => {
|
|
247
260
|
if (e.role === "user") return /* @__PURE__ */ l("div", {
|
|
248
261
|
className: "leadbot-chatbot-message leadbot-chatbot-message-user",
|
|
249
262
|
children: /* @__PURE__ */ l("div", {
|
|
@@ -251,7 +264,7 @@ function C(n) {
|
|
|
251
264
|
children: e.content
|
|
252
265
|
})
|
|
253
266
|
}, t);
|
|
254
|
-
if (
|
|
267
|
+
if (O && e.content === "" && t === D.length - 1) return /* @__PURE__ */ l("div", {
|
|
255
268
|
className: "leadbot-chatbot-message leadbot-chatbot-message-bot leadbot-chatbot-message-typing",
|
|
256
269
|
children: /* @__PURE__ */ l("div", {
|
|
257
270
|
className: "leadbot-chatbot-thinking",
|
|
@@ -268,12 +281,12 @@ function C(n) {
|
|
|
268
281
|
})]
|
|
269
282
|
})
|
|
270
283
|
}, t);
|
|
271
|
-
let n =
|
|
284
|
+
let n = y(e.content, e.citations);
|
|
272
285
|
return /* @__PURE__ */ l("div", {
|
|
273
286
|
className: "leadbot-chatbot-message leadbot-chatbot-message-bot",
|
|
274
287
|
children: [/* @__PURE__ */ l("div", {
|
|
275
288
|
className: "leadbot-chatbot-message-content",
|
|
276
|
-
children:
|
|
289
|
+
children: ae(e.content)
|
|
277
290
|
}), n.length > 0 && /* @__PURE__ */ l("div", {
|
|
278
291
|
className: "leadbot-chatbot-citations",
|
|
279
292
|
children: n.map((e) => /* @__PURE__ */ l("a", {
|
|
@@ -291,7 +304,7 @@ function C(n) {
|
|
|
291
304
|
}, e.index))
|
|
292
305
|
})]
|
|
293
306
|
}, t);
|
|
294
|
-
}),
|
|
307
|
+
}), ue && /* @__PURE__ */ l("div", {
|
|
295
308
|
className: "leadbot-chatbot-message leadbot-chatbot-message-bot leadbot-chatbot-message-typing",
|
|
296
309
|
children: /* @__PURE__ */ l("div", {
|
|
297
310
|
className: "leadbot-chatbot-thinking",
|
|
@@ -309,13 +322,13 @@ function C(n) {
|
|
|
309
322
|
})
|
|
310
323
|
})]
|
|
311
324
|
}),
|
|
312
|
-
|
|
325
|
+
fe && /* @__PURE__ */ l("div", {
|
|
313
326
|
className: "leadbot-chatbot-starters",
|
|
314
327
|
children: $.map((e) => /* @__PURE__ */ l("button", {
|
|
315
328
|
type: "button",
|
|
316
329
|
className: "leadbot-chatbot-starter-btn",
|
|
317
|
-
disabled:
|
|
318
|
-
onClick: () =>
|
|
330
|
+
disabled: O,
|
|
331
|
+
onClick: () => ce(e),
|
|
319
332
|
children: e.question
|
|
320
333
|
}, e.question))
|
|
321
334
|
}),
|
|
@@ -323,19 +336,19 @@ function C(n) {
|
|
|
323
336
|
className: "leadbot-chatbot-input",
|
|
324
337
|
children: /* @__PURE__ */ l("form", {
|
|
325
338
|
className: "leadbot-chatbot-input-field",
|
|
326
|
-
onSubmit:
|
|
339
|
+
onSubmit: le,
|
|
327
340
|
children: [/* @__PURE__ */ l("input", {
|
|
328
|
-
ref:
|
|
341
|
+
ref: I,
|
|
329
342
|
type: "text",
|
|
330
|
-
placeholder: n.placeholder ?? h("chatbot_placeholder",
|
|
343
|
+
placeholder: n.placeholder ?? h("chatbot_placeholder", _),
|
|
331
344
|
className: "leadbot-chatbot-message-input",
|
|
332
|
-
disabled:
|
|
333
|
-
onInput: () =>
|
|
345
|
+
disabled: O,
|
|
346
|
+
onInput: () => F(!!I.current?.value?.trim())
|
|
334
347
|
}), /* @__PURE__ */ l("button", {
|
|
335
348
|
type: "submit",
|
|
336
|
-
"aria-label":
|
|
337
|
-
className: `leadbot-chatbot-send-btn${
|
|
338
|
-
disabled:
|
|
349
|
+
"aria-label": v.send,
|
|
350
|
+
className: `leadbot-chatbot-send-btn${P && !O ? " leadbot-chatbot-send-btn--active" : ""}`,
|
|
351
|
+
disabled: O || !P,
|
|
339
352
|
children: /* @__PURE__ */ l("svg", {
|
|
340
353
|
width: "20",
|
|
341
354
|
height: "20",
|
|
@@ -353,14 +366,14 @@ function C(n) {
|
|
|
353
366
|
})
|
|
354
367
|
})
|
|
355
368
|
]
|
|
356
|
-
}) :
|
|
369
|
+
}) : S ? /* @__PURE__ */ l(o, {
|
|
357
370
|
...c(n),
|
|
358
|
-
forbidden:
|
|
359
|
-
lang:
|
|
371
|
+
forbidden: C,
|
|
372
|
+
lang: _
|
|
360
373
|
}) : null;
|
|
361
374
|
}
|
|
362
|
-
function
|
|
363
|
-
return n(
|
|
375
|
+
function S(e, t) {
|
|
376
|
+
return n(x, e, t);
|
|
364
377
|
}
|
|
365
378
|
//#endregion
|
|
366
|
-
export {
|
|
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.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"}
|
package/dist/chat.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./jsxRuntime.module-CT7yzySL.cjs"),t=require("./agentChat-
|
|
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
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
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-
|
|
2
|
+
import { n as a, r as o, t as s } from "./agentChat-8s9g6Np1.js";
|
|
3
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 };
|