@brainbase-labs/chat-widget 0.1.8 → 0.1.10
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/embed/index.js +1 -1
- package/dist/index.cjs +4 -4
- package/dist/index.d.ts +2 -0
- package/dist/index.js +311 -302
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { useState as
|
|
1
|
+
import { useState as N, useRef as U, useEffect as Z, useCallback as x, useMemo as te } from "react";
|
|
2
2
|
import { jsxs as i, jsx as e } from "react/jsx-runtime";
|
|
3
|
-
const
|
|
3
|
+
const oe = "bb-chat-";
|
|
4
4
|
function ie(o) {
|
|
5
5
|
try {
|
|
6
|
-
const t = sessionStorage.getItem(`${
|
|
6
|
+
const t = sessionStorage.getItem(`${oe}${o}`);
|
|
7
7
|
return t ? JSON.parse(t) : null;
|
|
8
8
|
} catch {
|
|
9
9
|
return null;
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
function
|
|
12
|
+
function se(o, t) {
|
|
13
13
|
try {
|
|
14
14
|
sessionStorage.setItem(
|
|
15
|
-
`${
|
|
15
|
+
`${oe}${o}`,
|
|
16
16
|
JSON.stringify(t)
|
|
17
17
|
);
|
|
18
18
|
} catch {
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
function
|
|
21
|
+
function re(o) {
|
|
22
22
|
try {
|
|
23
|
-
sessionStorage.removeItem(`${
|
|
23
|
+
sessionStorage.removeItem(`${oe}${o}`);
|
|
24
24
|
} catch {
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -29,66 +29,66 @@ function le(o) {
|
|
|
29
29
|
config: t,
|
|
30
30
|
apiClient: s,
|
|
31
31
|
mockMode: r,
|
|
32
|
-
onSessionStart:
|
|
33
|
-
onSessionEnd:
|
|
32
|
+
onSessionStart: u,
|
|
33
|
+
onSessionEnd: m,
|
|
34
34
|
onMessage: c,
|
|
35
|
-
onError:
|
|
36
|
-
} = o, [l, n] =
|
|
37
|
-
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
}, [t.embedId]),
|
|
43
|
-
|
|
44
|
-
sessionId:
|
|
35
|
+
onError: g
|
|
36
|
+
} = o, [l, n] = N([]), [b, M] = N([]), [A, H] = N(!1), [P, z] = N(null), [y, _] = N(null), S = U(0), K = U(!1);
|
|
37
|
+
Z(() => {
|
|
38
|
+
if (K.current) return;
|
|
39
|
+
K.current = !0;
|
|
40
|
+
const p = ie(t.embedId);
|
|
41
|
+
p && p.status === "active" && (_(p.sessionId), n(p.messages), M(p.toolCalls), S.current = p.startTime);
|
|
42
|
+
}, [t.embedId]), Z(() => {
|
|
43
|
+
y && l.length > 0 && se(t.embedId, {
|
|
44
|
+
sessionId: y,
|
|
45
45
|
deploymentId: t.deploymentId,
|
|
46
46
|
workerId: t.workerId,
|
|
47
47
|
flowId: t.flowId,
|
|
48
|
-
startTime:
|
|
48
|
+
startTime: S.current,
|
|
49
49
|
messages: l,
|
|
50
|
-
toolCalls:
|
|
50
|
+
toolCalls: b,
|
|
51
51
|
status: "active"
|
|
52
52
|
});
|
|
53
|
-
}, [
|
|
54
|
-
const
|
|
55
|
-
(
|
|
56
|
-
switch (
|
|
53
|
+
}, [y, l, b, t]);
|
|
54
|
+
const G = x(async () => (S.current = Date.now(), _(null), n([]), M([]), re(t.embedId), ""), [t.embedId]), E = x(
|
|
55
|
+
(p, I, w) => {
|
|
56
|
+
switch (p.type) {
|
|
57
57
|
case "session": {
|
|
58
|
-
const
|
|
59
|
-
|
|
58
|
+
const d = p.data;
|
|
59
|
+
d.session_id && (w(d.session_id), d.is_new && (S.current = Date.now(), u == null || u(d.session_id)));
|
|
60
60
|
break;
|
|
61
61
|
}
|
|
62
62
|
case "message": {
|
|
63
|
-
const
|
|
64
|
-
|
|
63
|
+
const d = p.data;
|
|
64
|
+
d.content && n(
|
|
65
65
|
(h) => h.map(
|
|
66
|
-
(a) => a.id ===
|
|
66
|
+
(a) => a.id === I ? { ...a, content: d.content, status: "streaming" } : a
|
|
67
67
|
)
|
|
68
68
|
);
|
|
69
69
|
break;
|
|
70
70
|
}
|
|
71
71
|
case "tool_call": {
|
|
72
|
-
const
|
|
73
|
-
|
|
72
|
+
const d = p.data;
|
|
73
|
+
M((h) => {
|
|
74
74
|
const a = h.findIndex(
|
|
75
|
-
(f) => f.name ===
|
|
75
|
+
(f) => f.name === d.function && f.status === "pending"
|
|
76
76
|
);
|
|
77
|
-
return a !== -1 &&
|
|
78
|
-
(f,
|
|
77
|
+
return a !== -1 && d.result !== void 0 ? h.map(
|
|
78
|
+
(f, B) => B === a ? { ...f, result: d.result, status: "completed" } : f
|
|
79
79
|
) : a === -1 ? [
|
|
80
80
|
...h,
|
|
81
81
|
{
|
|
82
82
|
id: `tc-${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
83
|
-
name:
|
|
84
|
-
arguments:
|
|
83
|
+
name: d.function,
|
|
84
|
+
arguments: d.args ?? {},
|
|
85
85
|
status: "pending",
|
|
86
86
|
timestamp: Date.now()
|
|
87
87
|
}
|
|
88
88
|
] : h;
|
|
89
|
-
}),
|
|
89
|
+
}), d.content && n(
|
|
90
90
|
(h) => h.map(
|
|
91
|
-
(a) => a.id ===
|
|
91
|
+
(a) => a.id === I ? { ...a, content: d.content, status: "streaming" } : a
|
|
92
92
|
)
|
|
93
93
|
);
|
|
94
94
|
break;
|
|
@@ -97,33 +97,33 @@ function le(o) {
|
|
|
97
97
|
break;
|
|
98
98
|
case "done": {
|
|
99
99
|
n(
|
|
100
|
-
(
|
|
100
|
+
(d) => d.map((h) => h.id === I ? { ...h, status: "sent" } : h)
|
|
101
101
|
);
|
|
102
102
|
break;
|
|
103
103
|
}
|
|
104
104
|
case "completed": {
|
|
105
105
|
n(
|
|
106
|
-
(
|
|
107
|
-
),
|
|
108
|
-
sessionId:
|
|
106
|
+
(d) => d.map((h) => h.id === I ? { ...h, status: "sent" } : h)
|
|
107
|
+
), y && se(t.embedId, {
|
|
108
|
+
sessionId: y,
|
|
109
109
|
deploymentId: t.deploymentId,
|
|
110
110
|
workerId: t.workerId,
|
|
111
111
|
flowId: t.flowId,
|
|
112
|
-
startTime:
|
|
112
|
+
startTime: S.current,
|
|
113
113
|
messages: l,
|
|
114
|
-
toolCalls:
|
|
114
|
+
toolCalls: b,
|
|
115
115
|
status: "completed"
|
|
116
116
|
});
|
|
117
117
|
break;
|
|
118
118
|
}
|
|
119
119
|
case "error": {
|
|
120
|
-
const
|
|
120
|
+
const d = p.data;
|
|
121
121
|
n(
|
|
122
122
|
(h) => h.map(
|
|
123
|
-
(a) => a.id ===
|
|
123
|
+
(a) => a.id === I ? {
|
|
124
124
|
...a,
|
|
125
125
|
status: "error",
|
|
126
|
-
content:
|
|
126
|
+
content: d.error ?? "An error occurred"
|
|
127
127
|
} : a
|
|
128
128
|
)
|
|
129
129
|
);
|
|
@@ -131,130 +131,130 @@ function le(o) {
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
},
|
|
134
|
-
[t,
|
|
135
|
-
),
|
|
136
|
-
async (
|
|
137
|
-
const
|
|
134
|
+
[t, y, l, b, u]
|
|
135
|
+
), T = x(
|
|
136
|
+
async (p, I, w) => {
|
|
137
|
+
const d = p.getReader(), h = new TextDecoder();
|
|
138
138
|
let a = "";
|
|
139
139
|
try {
|
|
140
140
|
for (; ; ) {
|
|
141
|
-
const { done: f, value:
|
|
141
|
+
const { done: f, value: B } = await d.read();
|
|
142
142
|
if (f) break;
|
|
143
|
-
for (a += h.decode(
|
|
143
|
+
for (a += h.decode(B, { stream: !0 }); a.includes(`
|
|
144
144
|
|
|
145
145
|
`); ) {
|
|
146
|
-
const [
|
|
146
|
+
const [v, j] = a.split(`
|
|
147
147
|
|
|
148
148
|
`, 2);
|
|
149
|
-
a =
|
|
150
|
-
for (const
|
|
149
|
+
a = j;
|
|
150
|
+
for (const ne of v.split(`
|
|
151
151
|
`))
|
|
152
|
-
if (
|
|
152
|
+
if (ne.startsWith("data: "))
|
|
153
153
|
try {
|
|
154
|
-
const ce = JSON.parse(
|
|
155
|
-
|
|
154
|
+
const ce = JSON.parse(ne.slice(6));
|
|
155
|
+
E(ce, I, w);
|
|
156
156
|
} catch {
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
} finally {
|
|
161
|
-
|
|
161
|
+
d.releaseLock();
|
|
162
162
|
}
|
|
163
163
|
},
|
|
164
|
-
[
|
|
165
|
-
),
|
|
166
|
-
async (
|
|
167
|
-
if (!
|
|
168
|
-
const
|
|
164
|
+
[E]
|
|
165
|
+
), ee = x(
|
|
166
|
+
async (p) => {
|
|
167
|
+
if (!p.trim()) return;
|
|
168
|
+
const I = {
|
|
169
169
|
id: `user-${Date.now()}`,
|
|
170
170
|
role: "user",
|
|
171
|
-
content:
|
|
171
|
+
content: p,
|
|
172
172
|
timestamp: Date.now(),
|
|
173
173
|
status: "sent"
|
|
174
174
|
};
|
|
175
|
-
n((a) => [...a,
|
|
176
|
-
const
|
|
177
|
-
id:
|
|
175
|
+
n((a) => [...a, I]), c == null || c(I);
|
|
176
|
+
const w = `assistant-${Date.now()}`, d = {
|
|
177
|
+
id: w,
|
|
178
178
|
role: "assistant",
|
|
179
179
|
content: "",
|
|
180
180
|
timestamp: Date.now(),
|
|
181
181
|
status: "streaming"
|
|
182
182
|
};
|
|
183
|
-
n((a) => [...a,
|
|
183
|
+
n((a) => [...a, d]), H(!0), z(null);
|
|
184
184
|
const h = (a) => {
|
|
185
|
-
|
|
185
|
+
_(a);
|
|
186
186
|
};
|
|
187
187
|
try {
|
|
188
188
|
if (r) {
|
|
189
|
-
const a = s.sendMessage(
|
|
189
|
+
const a = s.sendMessage(p);
|
|
190
190
|
for await (const f of a)
|
|
191
|
-
|
|
191
|
+
E(f, w, h);
|
|
192
192
|
} else {
|
|
193
193
|
const a = await s.sendMessage({
|
|
194
194
|
embedId: t.embedId,
|
|
195
|
-
message:
|
|
196
|
-
sessionId:
|
|
195
|
+
message: p,
|
|
196
|
+
sessionId: y ?? void 0
|
|
197
197
|
});
|
|
198
|
-
await
|
|
198
|
+
await T(a, w, h);
|
|
199
199
|
}
|
|
200
200
|
n(
|
|
201
201
|
(a) => a.map(
|
|
202
|
-
(f) => f.id ===
|
|
202
|
+
(f) => f.id === w && f.status === "streaming" ? { ...f, status: "sent" } : f
|
|
203
203
|
)
|
|
204
204
|
);
|
|
205
205
|
} catch (a) {
|
|
206
206
|
const f = a instanceof Error ? a : new Error("Failed to send message");
|
|
207
|
-
|
|
208
|
-
(
|
|
209
|
-
(
|
|
207
|
+
z(f), g == null || g(f), n(
|
|
208
|
+
(B) => B.map(
|
|
209
|
+
(v) => v.id === w ? { ...v, status: "error", content: "Failed to get response" } : v
|
|
210
210
|
)
|
|
211
211
|
);
|
|
212
212
|
} finally {
|
|
213
|
-
|
|
213
|
+
H(!1);
|
|
214
214
|
}
|
|
215
215
|
},
|
|
216
216
|
[
|
|
217
|
-
|
|
217
|
+
y,
|
|
218
218
|
s,
|
|
219
219
|
r,
|
|
220
220
|
t.embedId,
|
|
221
|
-
|
|
222
|
-
|
|
221
|
+
E,
|
|
222
|
+
T,
|
|
223
223
|
c,
|
|
224
|
-
|
|
224
|
+
g
|
|
225
225
|
]
|
|
226
|
-
),
|
|
227
|
-
if (!
|
|
228
|
-
const
|
|
229
|
-
sessionId:
|
|
226
|
+
), J = x(async () => {
|
|
227
|
+
if (!y) return;
|
|
228
|
+
const p = {
|
|
229
|
+
sessionId: y,
|
|
230
230
|
deploymentId: t.deploymentId,
|
|
231
231
|
workerId: t.workerId,
|
|
232
232
|
flowId: t.flowId,
|
|
233
|
-
startTime:
|
|
233
|
+
startTime: S.current,
|
|
234
234
|
messages: l,
|
|
235
|
-
toolCalls:
|
|
235
|
+
toolCalls: b,
|
|
236
236
|
status: "completed"
|
|
237
237
|
};
|
|
238
|
-
|
|
238
|
+
m == null || m(p), re(t.embedId), _(null), n([]), M([]);
|
|
239
239
|
}, [
|
|
240
|
-
|
|
240
|
+
y,
|
|
241
241
|
t,
|
|
242
242
|
l,
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
]),
|
|
246
|
-
n([]),
|
|
243
|
+
b,
|
|
244
|
+
m
|
|
245
|
+
]), F = x(() => {
|
|
246
|
+
n([]), M([]);
|
|
247
247
|
}, []);
|
|
248
248
|
return {
|
|
249
249
|
messages: l,
|
|
250
|
-
toolCalls:
|
|
251
|
-
isLoading:
|
|
252
|
-
error:
|
|
253
|
-
sessionId:
|
|
254
|
-
sendMessage:
|
|
255
|
-
endSession:
|
|
256
|
-
clearMessages:
|
|
257
|
-
startNewSession:
|
|
250
|
+
toolCalls: b,
|
|
251
|
+
isLoading: A,
|
|
252
|
+
error: P,
|
|
253
|
+
sessionId: y,
|
|
254
|
+
sendMessage: ee,
|
|
255
|
+
endSession: J,
|
|
256
|
+
clearMessages: F,
|
|
257
|
+
startNewSession: G
|
|
258
258
|
};
|
|
259
259
|
}
|
|
260
260
|
const de = "https://whatsapp-based-server.onrender.com";
|
|
@@ -356,25 +356,25 @@ const me = {
|
|
|
356
356
|
delay: 1e3
|
|
357
357
|
}
|
|
358
358
|
];
|
|
359
|
-
function
|
|
359
|
+
function O(o) {
|
|
360
360
|
return new Promise((t) => setTimeout(t, o));
|
|
361
361
|
}
|
|
362
362
|
function pe(o, t) {
|
|
363
|
-
const s = { ...me, ...o }, r = t ?? ge,
|
|
363
|
+
const s = { ...me, ...o }, r = t ?? ge, u = `mock-session-${Date.now()}`;
|
|
364
364
|
return {
|
|
365
|
-
async getDeploymentConfig(
|
|
366
|
-
return await
|
|
365
|
+
async getDeploymentConfig(m) {
|
|
366
|
+
return await O(300), s;
|
|
367
367
|
},
|
|
368
|
-
async *sendMessage(
|
|
368
|
+
async *sendMessage(m) {
|
|
369
369
|
yield {
|
|
370
370
|
type: "session",
|
|
371
|
-
data: { session_id:
|
|
371
|
+
data: { session_id: u, is_new: !0 },
|
|
372
372
|
timestamp: Date.now()
|
|
373
373
|
};
|
|
374
374
|
const c = r.find(
|
|
375
|
-
(n) => typeof n.trigger == "string" ?
|
|
375
|
+
(n) => typeof n.trigger == "string" ? m.toLowerCase().includes(n.trigger.toLowerCase()) : n.trigger.test(m)
|
|
376
376
|
) ?? r[r.length - 1];
|
|
377
|
-
if (await
|
|
377
|
+
if (await O(c.delay ?? 500), c.toolCalls)
|
|
378
378
|
for (const n of c.toolCalls)
|
|
379
379
|
yield {
|
|
380
380
|
type: "tool_call",
|
|
@@ -383,31 +383,31 @@ function pe(o, t) {
|
|
|
383
383
|
args: n.arguments
|
|
384
384
|
},
|
|
385
385
|
timestamp: Date.now()
|
|
386
|
-
}, await
|
|
386
|
+
}, await O(300), yield {
|
|
387
387
|
type: "tool_call",
|
|
388
388
|
data: {
|
|
389
389
|
function: n.name,
|
|
390
390
|
result: n.result
|
|
391
391
|
},
|
|
392
392
|
timestamp: Date.now()
|
|
393
|
-
}, await
|
|
394
|
-
const
|
|
393
|
+
}, await O(200);
|
|
394
|
+
const g = c.response.split(" ");
|
|
395
395
|
let l = "";
|
|
396
|
-
for (const n of
|
|
396
|
+
for (const n of g)
|
|
397
397
|
l += (l ? " " : "") + n, yield {
|
|
398
398
|
type: "message",
|
|
399
399
|
data: { content: l, role: "assistant" },
|
|
400
400
|
timestamp: Date.now()
|
|
401
|
-
}, await
|
|
401
|
+
}, await O(30 + Math.random() * 40);
|
|
402
402
|
yield {
|
|
403
403
|
type: "done",
|
|
404
|
-
data: { session_id:
|
|
404
|
+
data: { session_id: u },
|
|
405
405
|
timestamp: Date.now()
|
|
406
406
|
};
|
|
407
407
|
}
|
|
408
408
|
};
|
|
409
409
|
}
|
|
410
|
-
const
|
|
410
|
+
const q = ({
|
|
411
411
|
className: o,
|
|
412
412
|
color: t = "currentColor",
|
|
413
413
|
cutoutColor: s = "var(--bb-primary-color)"
|
|
@@ -463,61 +463,61 @@ const Z = ({
|
|
|
463
463
|
)
|
|
464
464
|
]
|
|
465
465
|
}
|
|
466
|
-
), he = "_header_1p6z5_1", _e = "_compact_1p6z5_9", fe = "_headerBackground_1p6z5_20",
|
|
466
|
+
), he = "_header_1p6z5_1", _e = "_compact_1p6z5_9", fe = "_headerBackground_1p6z5_20", be = "_headerContent_1p6z5_59", ye = "_topRow_1p6z5_64", we = "_agentInfo_1p6z5_79", Ce = "_agentLogo_1p6z5_85", ke = "_agentLogoPlaceholder_1p6z5_102", ve = "_brainbaseLogo_1p6z5_123", Ie = "_agentName_1p6z5_137", Ne = "_actions_1p6z5_144", Le = "_actionButton_1p6z5_149", $e = "_welcomeText_1p6z5_183", Be = "_title_1p6z5_202", xe = "_subtitle_1p6z5_210", C = {
|
|
467
467
|
header: he,
|
|
468
468
|
compact: _e,
|
|
469
469
|
headerBackground: fe,
|
|
470
|
-
headerContent:
|
|
471
|
-
topRow:
|
|
472
|
-
agentInfo:
|
|
470
|
+
headerContent: be,
|
|
471
|
+
topRow: ye,
|
|
472
|
+
agentInfo: we,
|
|
473
473
|
agentLogo: Ce,
|
|
474
474
|
agentLogoPlaceholder: ke,
|
|
475
475
|
brainbaseLogo: ve,
|
|
476
476
|
agentName: Ie,
|
|
477
477
|
actions: Ne,
|
|
478
478
|
actionButton: Le,
|
|
479
|
-
welcomeText:
|
|
480
|
-
title:
|
|
479
|
+
welcomeText: $e,
|
|
480
|
+
title: Be,
|
|
481
481
|
subtitle: xe
|
|
482
482
|
}, Me = ({
|
|
483
483
|
agentName: o = "AI Assistant",
|
|
484
484
|
agentLogoUrl: t,
|
|
485
485
|
welcomeTitle: s,
|
|
486
486
|
welcomeSubtitle: r,
|
|
487
|
-
onClose:
|
|
488
|
-
onNewChatRequest:
|
|
487
|
+
onClose: u,
|
|
488
|
+
onNewChatRequest: m,
|
|
489
489
|
showNewChatButton: c = !1,
|
|
490
|
-
compact:
|
|
490
|
+
compact: g = !1
|
|
491
491
|
}) => {
|
|
492
492
|
const l = s || "Hello there.", n = r !== void 0 ? r : s ? void 0 : "How can we help?";
|
|
493
|
-
return /* @__PURE__ */ i("div", { className: `${
|
|
494
|
-
/* @__PURE__ */ e("div", { className:
|
|
495
|
-
/* @__PURE__ */ i("div", { className:
|
|
496
|
-
/* @__PURE__ */ i("div", { className:
|
|
497
|
-
/* @__PURE__ */ i("div", { className:
|
|
493
|
+
return /* @__PURE__ */ i("div", { className: `${C.header} ${g ? C.compact : ""}`, children: [
|
|
494
|
+
/* @__PURE__ */ e("div", { className: C.headerBackground }),
|
|
495
|
+
/* @__PURE__ */ i("div", { className: C.headerContent, children: [
|
|
496
|
+
/* @__PURE__ */ i("div", { className: C.topRow, children: [
|
|
497
|
+
/* @__PURE__ */ i("div", { className: C.agentInfo, children: [
|
|
498
498
|
t ? /* @__PURE__ */ e(
|
|
499
499
|
"img",
|
|
500
500
|
{
|
|
501
501
|
src: t,
|
|
502
502
|
alt: o,
|
|
503
|
-
className:
|
|
503
|
+
className: C.agentLogo
|
|
504
504
|
}
|
|
505
|
-
) : /* @__PURE__ */ e("div", { className:
|
|
506
|
-
|
|
505
|
+
) : /* @__PURE__ */ e("div", { className: C.agentLogoPlaceholder, children: /* @__PURE__ */ e(
|
|
506
|
+
q,
|
|
507
507
|
{
|
|
508
|
-
className:
|
|
508
|
+
className: C.brainbaseLogo,
|
|
509
509
|
color: "white",
|
|
510
510
|
cutoutColor: "var(--bb-primary-color)"
|
|
511
511
|
}
|
|
512
512
|
) }),
|
|
513
|
-
/* @__PURE__ */ e("span", { className:
|
|
513
|
+
/* @__PURE__ */ e("span", { className: C.agentName, children: o })
|
|
514
514
|
] }),
|
|
515
|
-
/* @__PURE__ */ i("div", { className:
|
|
516
|
-
c &&
|
|
515
|
+
/* @__PURE__ */ i("div", { className: C.actions, children: [
|
|
516
|
+
c && m && /* @__PURE__ */ e(
|
|
517
517
|
"button",
|
|
518
518
|
{
|
|
519
|
-
className:
|
|
520
|
-
onClick:
|
|
519
|
+
className: C.actionButton,
|
|
520
|
+
onClick: m,
|
|
521
521
|
"aria-label": "Start new chat",
|
|
522
522
|
type: "button",
|
|
523
523
|
children: /* @__PURE__ */ e("svg", { viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ e(
|
|
@@ -532,11 +532,11 @@ const Z = ({
|
|
|
532
532
|
) })
|
|
533
533
|
}
|
|
534
534
|
),
|
|
535
|
-
|
|
535
|
+
u && /* @__PURE__ */ e(
|
|
536
536
|
"button",
|
|
537
537
|
{
|
|
538
|
-
className:
|
|
539
|
-
onClick:
|
|
538
|
+
className: C.actionButton,
|
|
539
|
+
onClick: u,
|
|
540
540
|
"aria-label": "Close chat",
|
|
541
541
|
type: "button",
|
|
542
542
|
children: /* @__PURE__ */ e("svg", { viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ e(
|
|
@@ -553,9 +553,9 @@ const Z = ({
|
|
|
553
553
|
)
|
|
554
554
|
] })
|
|
555
555
|
] }),
|
|
556
|
-
!
|
|
557
|
-
/* @__PURE__ */ e("h1", { className:
|
|
558
|
-
n && /* @__PURE__ */ e("p", { className:
|
|
556
|
+
!g && /* @__PURE__ */ i("div", { className: C.welcomeText, children: [
|
|
557
|
+
/* @__PURE__ */ e("h1", { className: C.title, children: l }),
|
|
558
|
+
n && /* @__PURE__ */ e("p", { className: C.subtitle, children: n })
|
|
559
559
|
] })
|
|
560
560
|
] })
|
|
561
561
|
] });
|
|
@@ -576,14 +576,14 @@ const Z = ({
|
|
|
576
576
|
agentName: t,
|
|
577
577
|
agentLogoUrl: s
|
|
578
578
|
}) => {
|
|
579
|
-
const r = o.role === "user",
|
|
579
|
+
const r = o.role === "user", u = o.status === "streaming", m = o.status === "error";
|
|
580
580
|
return /* @__PURE__ */ i(
|
|
581
581
|
"div",
|
|
582
582
|
{
|
|
583
583
|
className: `${L.messageWrapper} ${r ? L.user : L.assistant}`,
|
|
584
584
|
children: [
|
|
585
585
|
!r && /* @__PURE__ */ e("div", { className: L.avatar, children: s ? /* @__PURE__ */ e("img", { src: s, alt: t || "AI" }) : /* @__PURE__ */ e("div", { className: L.avatarPlaceholder, children: /* @__PURE__ */ e(
|
|
586
|
-
|
|
586
|
+
q,
|
|
587
587
|
{
|
|
588
588
|
className: L.brainbaseLogo,
|
|
589
589
|
color: "white",
|
|
@@ -593,15 +593,15 @@ const Z = ({
|
|
|
593
593
|
/* @__PURE__ */ i(
|
|
594
594
|
"div",
|
|
595
595
|
{
|
|
596
|
-
className: `${L.messageBubble} ${
|
|
596
|
+
className: `${L.messageBubble} ${m ? L.error : ""}`,
|
|
597
597
|
role: "article",
|
|
598
598
|
"aria-label": `${r ? "Your message" : `${t || "AI"} says`}`,
|
|
599
599
|
children: [
|
|
600
600
|
/* @__PURE__ */ i("div", { className: L.content, children: [
|
|
601
601
|
o.content,
|
|
602
|
-
|
|
602
|
+
u && /* @__PURE__ */ e("span", { className: L.cursor })
|
|
603
603
|
] }),
|
|
604
|
-
|
|
604
|
+
m && /* @__PURE__ */ i("div", { className: L.errorIndicator, children: [
|
|
605
605
|
/* @__PURE__ */ i("svg", { viewBox: "0 0 24 24", fill: "none", children: [
|
|
606
606
|
/* @__PURE__ */ e("circle", { cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "2" }),
|
|
607
607
|
/* @__PURE__ */ e("path", { d: "M12 8V12M12 16H12.01", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" })
|
|
@@ -614,7 +614,7 @@ const Z = ({
|
|
|
614
614
|
]
|
|
615
615
|
}
|
|
616
616
|
);
|
|
617
|
-
}, Oe = "_toolCall_1wby1_1", Re = "_iconWrapper_1wby1_24", Ue = "_spinner_1wby1_33", Ze = "_checkIcon_1wby1_48", qe = "_errorIcon_1wby1_54", Ke = "_content_1wby1_60", Ge = "_label_1wby1_66", Je = "_name_1wby1_73", Ye = "_pending_1wby1_78", Xe = "_completed_1wby1_82", Qe = "_error_1wby1_54",
|
|
617
|
+
}, Oe = "_toolCall_1wby1_1", Re = "_iconWrapper_1wby1_24", Ue = "_spinner_1wby1_33", Ze = "_checkIcon_1wby1_48", qe = "_errorIcon_1wby1_54", Ke = "_content_1wby1_60", Ge = "_label_1wby1_66", Je = "_name_1wby1_73", Ye = "_pending_1wby1_78", Xe = "_completed_1wby1_82", Qe = "_error_1wby1_54", $ = {
|
|
618
618
|
toolCall: Oe,
|
|
619
619
|
iconWrapper: Re,
|
|
620
620
|
spinner: Ue,
|
|
@@ -627,13 +627,13 @@ const Z = ({
|
|
|
627
627
|
completed: Xe,
|
|
628
628
|
error: Qe
|
|
629
629
|
}, et = ({ toolCall: o }) => {
|
|
630
|
-
const t = o.status === "pending" || o.status === "executing", s = o.status === "completed", r = o.status === "error",
|
|
630
|
+
const t = o.status === "pending" || o.status === "executing", s = o.status === "completed", r = o.status === "error", u = (m) => m.replace(/_/g, " ").replace(/([A-Z])/g, " $1").trim().toLowerCase().replace(/^./, (c) => c.toUpperCase());
|
|
631
631
|
return /* @__PURE__ */ i(
|
|
632
632
|
"div",
|
|
633
633
|
{
|
|
634
|
-
className: `${
|
|
634
|
+
className: `${$.toolCall} ${t ? $.pending : ""} ${s ? $.completed : ""} ${r ? $.error : ""}`,
|
|
635
635
|
children: [
|
|
636
|
-
/* @__PURE__ */ e("div", { className:
|
|
636
|
+
/* @__PURE__ */ e("div", { className: $.iconWrapper, children: t ? /* @__PURE__ */ e("div", { className: $.spinner }) : s ? /* @__PURE__ */ e("svg", { viewBox: "0 0 24 24", fill: "none", className: $.checkIcon, children: /* @__PURE__ */ e(
|
|
637
637
|
"path",
|
|
638
638
|
{
|
|
639
639
|
d: "M20 6L9 17L4 12",
|
|
@@ -642,7 +642,7 @@ const Z = ({
|
|
|
642
642
|
strokeLinecap: "round",
|
|
643
643
|
strokeLinejoin: "round"
|
|
644
644
|
}
|
|
645
|
-
) }) : /* @__PURE__ */ e("svg", { viewBox: "0 0 24 24", fill: "none", className:
|
|
645
|
+
) }) : /* @__PURE__ */ e("svg", { viewBox: "0 0 24 24", fill: "none", className: $.errorIcon, children: /* @__PURE__ */ e(
|
|
646
646
|
"path",
|
|
647
647
|
{
|
|
648
648
|
d: "M6 18L18 6M6 6L18 18",
|
|
@@ -652,9 +652,9 @@ const Z = ({
|
|
|
652
652
|
strokeLinejoin: "round"
|
|
653
653
|
}
|
|
654
654
|
) }) }),
|
|
655
|
-
/* @__PURE__ */ i("div", { className:
|
|
656
|
-
/* @__PURE__ */ e("span", { className:
|
|
657
|
-
/* @__PURE__ */ e("span", { className:
|
|
655
|
+
/* @__PURE__ */ i("div", { className: $.content, children: [
|
|
656
|
+
/* @__PURE__ */ e("span", { className: $.label, children: t ? "Running" : s ? "Completed" : "Failed" }),
|
|
657
|
+
/* @__PURE__ */ e("span", { className: $.name, children: u(o.name) })
|
|
658
658
|
] })
|
|
659
659
|
]
|
|
660
660
|
}
|
|
@@ -671,7 +671,7 @@ const Z = ({
|
|
|
671
671
|
agentLogoUrl: t
|
|
672
672
|
}) => /* @__PURE__ */ i("div", { className: W.wrapper, role: "status", "aria-label": `${o} is typing`, children: [
|
|
673
673
|
/* @__PURE__ */ e("div", { className: W.avatar, children: t ? /* @__PURE__ */ e("img", { src: t, alt: o }) : /* @__PURE__ */ e("div", { className: W.avatarPlaceholder, children: /* @__PURE__ */ e(
|
|
674
|
-
|
|
674
|
+
q,
|
|
675
675
|
{
|
|
676
676
|
className: W.brainbaseLogo,
|
|
677
677
|
color: "white",
|
|
@@ -693,18 +693,18 @@ const Z = ({
|
|
|
693
693
|
toolCalls: t,
|
|
694
694
|
isLoading: s,
|
|
695
695
|
agentName: r,
|
|
696
|
-
agentLogoUrl:
|
|
696
|
+
agentLogoUrl: u
|
|
697
697
|
}) => {
|
|
698
698
|
var l;
|
|
699
|
-
const
|
|
700
|
-
|
|
699
|
+
const m = U(null), c = U(null);
|
|
700
|
+
Z(() => {
|
|
701
701
|
var n;
|
|
702
702
|
(n = c.current) == null || n.scrollIntoView({ behavior: "smooth" });
|
|
703
703
|
}, [o, t, s]);
|
|
704
|
-
const
|
|
704
|
+
const g = t.filter(
|
|
705
705
|
(n) => n.status === "pending" || n.status === "executing"
|
|
706
706
|
);
|
|
707
|
-
return /* @__PURE__ */ i("div", { className: Y.messageList, ref:
|
|
707
|
+
return /* @__PURE__ */ i("div", { className: Y.messageList, ref: m, role: "log", "aria-live": "polite", children: [
|
|
708
708
|
o.length === 0 && !s && /* @__PURE__ */ i("div", { className: Y.emptyState, children: [
|
|
709
709
|
/* @__PURE__ */ e("div", { className: Y.emptyIcon, children: /* @__PURE__ */ e("svg", { viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ e(
|
|
710
710
|
"path",
|
|
@@ -723,54 +723,54 @@ const Z = ({
|
|
|
723
723
|
{
|
|
724
724
|
message: n,
|
|
725
725
|
agentName: r,
|
|
726
|
-
agentLogoUrl:
|
|
726
|
+
agentLogoUrl: u
|
|
727
727
|
},
|
|
728
728
|
n.id
|
|
729
729
|
)),
|
|
730
|
-
|
|
731
|
-
s && ((l = o[o.length - 1]) == null ? void 0 : l.role) === "user" && /* @__PURE__ */ e(ct, { agentName: r, agentLogoUrl:
|
|
730
|
+
g.map((n) => /* @__PURE__ */ e(et, { toolCall: n }, n.id)),
|
|
731
|
+
s && ((l = o[o.length - 1]) == null ? void 0 : l.role) === "user" && /* @__PURE__ */ e(ct, { agentName: r, agentLogoUrl: u }),
|
|
732
732
|
/* @__PURE__ */ e("div", { ref: c })
|
|
733
733
|
] });
|
|
734
|
-
}, gt = "_inputWrapper_5lgg7_1", pt = "_inputContainer_5lgg7_7", ht = "_textarea_5lgg7_23", _t = "_sendButton_5lgg7_50", ft = "_hint_5lgg7_89",
|
|
734
|
+
}, gt = "_inputWrapper_5lgg7_1", pt = "_inputContainer_5lgg7_7", ht = "_textarea_5lgg7_23", _t = "_sendButton_5lgg7_50", ft = "_hint_5lgg7_89", R = {
|
|
735
735
|
inputWrapper: gt,
|
|
736
736
|
inputContainer: pt,
|
|
737
737
|
textarea: ht,
|
|
738
738
|
sendButton: _t,
|
|
739
739
|
hint: ft
|
|
740
|
-
},
|
|
740
|
+
}, bt = ({
|
|
741
741
|
onSend: o,
|
|
742
742
|
disabled: t = !1,
|
|
743
743
|
placeholder: s = "Send a message..."
|
|
744
744
|
}) => {
|
|
745
|
-
const [r,
|
|
746
|
-
const n =
|
|
745
|
+
const [r, u] = N(""), m = U(null), c = x(() => {
|
|
746
|
+
const n = m.current;
|
|
747
747
|
n && (n.style.height = "auto", n.style.height = `${Math.min(n.scrollHeight, 150)}px`);
|
|
748
748
|
}, []);
|
|
749
|
-
|
|
749
|
+
Z(() => {
|
|
750
750
|
c();
|
|
751
751
|
}, [r, c]);
|
|
752
|
-
const
|
|
752
|
+
const g = x(
|
|
753
753
|
(n) => {
|
|
754
754
|
n == null || n.preventDefault();
|
|
755
|
-
const
|
|
756
|
-
|
|
755
|
+
const b = r.trim();
|
|
756
|
+
b && !t && (o(b), u(""), m.current && (m.current.style.height = "auto"));
|
|
757
757
|
},
|
|
758
758
|
[r, t, o]
|
|
759
|
-
), l =
|
|
759
|
+
), l = x(
|
|
760
760
|
(n) => {
|
|
761
|
-
n.key === "Enter" && !n.shiftKey && (n.preventDefault(),
|
|
761
|
+
n.key === "Enter" && !n.shiftKey && (n.preventDefault(), g());
|
|
762
762
|
},
|
|
763
|
-
[
|
|
763
|
+
[g]
|
|
764
764
|
);
|
|
765
|
-
return /* @__PURE__ */ i("form", { className:
|
|
766
|
-
/* @__PURE__ */ i("div", { className:
|
|
765
|
+
return /* @__PURE__ */ i("form", { className: R.inputWrapper, onSubmit: g, children: [
|
|
766
|
+
/* @__PURE__ */ i("div", { className: R.inputContainer, children: [
|
|
767
767
|
/* @__PURE__ */ e(
|
|
768
768
|
"textarea",
|
|
769
769
|
{
|
|
770
|
-
ref:
|
|
771
|
-
className:
|
|
770
|
+
ref: m,
|
|
771
|
+
className: R.textarea,
|
|
772
772
|
value: r,
|
|
773
|
-
onChange: (n) =>
|
|
773
|
+
onChange: (n) => u(n.target.value),
|
|
774
774
|
onKeyDown: l,
|
|
775
775
|
placeholder: s,
|
|
776
776
|
disabled: t,
|
|
@@ -782,7 +782,7 @@ const Z = ({
|
|
|
782
782
|
"button",
|
|
783
783
|
{
|
|
784
784
|
type: "submit",
|
|
785
|
-
className:
|
|
785
|
+
className: R.sendButton,
|
|
786
786
|
disabled: t || !r.trim(),
|
|
787
787
|
"aria-label": "Send message",
|
|
788
788
|
children: /* @__PURE__ */ e("svg", { viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ e(
|
|
@@ -798,7 +798,7 @@ const Z = ({
|
|
|
798
798
|
}
|
|
799
799
|
)
|
|
800
800
|
] }),
|
|
801
|
-
/* @__PURE__ */ i("div", { className:
|
|
801
|
+
/* @__PURE__ */ i("div", { className: R.hint, children: [
|
|
802
802
|
"Press ",
|
|
803
803
|
/* @__PURE__ */ e("kbd", { children: "Enter" }),
|
|
804
804
|
" to send, ",
|
|
@@ -806,9 +806,9 @@ const Z = ({
|
|
|
806
806
|
" for new line"
|
|
807
807
|
] })
|
|
808
808
|
] });
|
|
809
|
-
},
|
|
810
|
-
poweredBy:
|
|
811
|
-
logo:
|
|
809
|
+
}, yt = "_poweredBy_9jh5q_1", wt = "_logo_9jh5q_20", Ct = "_poweredText_9jh5q_24", kt = "_text_9jh5q_36", X = {
|
|
810
|
+
poweredBy: yt,
|
|
811
|
+
logo: wt,
|
|
812
812
|
poweredText: Ct,
|
|
813
813
|
text: kt
|
|
814
814
|
}, vt = ({ className: o }) => /* @__PURE__ */ i(
|
|
@@ -877,11 +877,11 @@ const Z = ({
|
|
|
877
877
|
/* @__PURE__ */ e("span", { className: X.text, children: "Brainbase Labs" })
|
|
878
878
|
]
|
|
879
879
|
}
|
|
880
|
-
) : null, Nt = "_container_m2o9l_1", Lt = "_body_m2o9l_26",
|
|
880
|
+
) : null, Nt = "_container_m2o9l_1", Lt = "_body_m2o9l_26", $t = "_confirmationOverlay_m2o9l_35", Bt = "_confirmationDialog_m2o9l_56", xt = "_confirmationText_m2o9l_78", Mt = "_confirmationButtons_m2o9l_86", St = "_cancelButton_m2o9l_91", Tt = "_confirmButton_m2o9l_92", D = {
|
|
881
881
|
container: Nt,
|
|
882
882
|
body: Lt,
|
|
883
|
-
confirmationOverlay:
|
|
884
|
-
confirmationDialog:
|
|
883
|
+
confirmationOverlay: $t,
|
|
884
|
+
confirmationDialog: Bt,
|
|
885
885
|
confirmationText: xt,
|
|
886
886
|
confirmationButtons: Mt,
|
|
887
887
|
cancelButton: St,
|
|
@@ -891,16 +891,16 @@ const Z = ({
|
|
|
891
891
|
messages: t,
|
|
892
892
|
toolCalls: s,
|
|
893
893
|
isLoading: r,
|
|
894
|
-
onSendMessage:
|
|
895
|
-
onClose:
|
|
894
|
+
onSendMessage: u,
|
|
895
|
+
onClose: m,
|
|
896
896
|
onNewChat: c
|
|
897
897
|
}) => {
|
|
898
|
-
var
|
|
899
|
-
const [
|
|
898
|
+
var H;
|
|
899
|
+
const [g, l] = N(!1), n = t.length > 0, b = () => {
|
|
900
900
|
l(!0);
|
|
901
|
-
},
|
|
901
|
+
}, M = () => {
|
|
902
902
|
l(!1), c == null || c();
|
|
903
|
-
},
|
|
903
|
+
}, A = () => {
|
|
904
904
|
l(!1);
|
|
905
905
|
};
|
|
906
906
|
return /* @__PURE__ */ i("div", { className: D.container, role: "dialog", "aria-label": "Chat window", children: [
|
|
@@ -911,8 +911,8 @@ const Z = ({
|
|
|
911
911
|
agentLogoUrl: o.agentLogoUrl,
|
|
912
912
|
welcomeTitle: o.welcomeMessage || "Hello there.",
|
|
913
913
|
welcomeSubtitle: o.welcomeMessage ? void 0 : "How can we help?",
|
|
914
|
-
onClose:
|
|
915
|
-
onNewChatRequest:
|
|
914
|
+
onClose: m,
|
|
915
|
+
onNewChatRequest: b,
|
|
916
916
|
showNewChatButton: n,
|
|
917
917
|
compact: n
|
|
918
918
|
}
|
|
@@ -929,23 +929,23 @@ const Z = ({
|
|
|
929
929
|
}
|
|
930
930
|
),
|
|
931
931
|
/* @__PURE__ */ e(
|
|
932
|
-
|
|
932
|
+
bt,
|
|
933
933
|
{
|
|
934
|
-
onSend:
|
|
934
|
+
onSend: u,
|
|
935
935
|
disabled: r,
|
|
936
936
|
placeholder: "Ask a question..."
|
|
937
937
|
}
|
|
938
938
|
)
|
|
939
939
|
] }),
|
|
940
|
-
/* @__PURE__ */ e(It, { showBranding: ((
|
|
941
|
-
|
|
940
|
+
/* @__PURE__ */ e(It, { showBranding: ((H = o.styling) == null ? void 0 : H.showBranding) ?? !0 }),
|
|
941
|
+
g && /* @__PURE__ */ e("div", { className: D.confirmationOverlay, children: /* @__PURE__ */ i("div", { className: D.confirmationDialog, children: [
|
|
942
942
|
/* @__PURE__ */ e("p", { className: D.confirmationText, children: "End current chat and start a new conversation?" }),
|
|
943
943
|
/* @__PURE__ */ i("div", { className: D.confirmationButtons, children: [
|
|
944
944
|
/* @__PURE__ */ e(
|
|
945
945
|
"button",
|
|
946
946
|
{
|
|
947
947
|
className: D.cancelButton,
|
|
948
|
-
onClick:
|
|
948
|
+
onClick: A,
|
|
949
949
|
type: "button",
|
|
950
950
|
children: "Cancel"
|
|
951
951
|
}
|
|
@@ -954,7 +954,7 @@ const Z = ({
|
|
|
954
954
|
"button",
|
|
955
955
|
{
|
|
956
956
|
className: D.confirmButton,
|
|
957
|
-
onClick:
|
|
957
|
+
onClick: M,
|
|
958
958
|
type: "button",
|
|
959
959
|
children: "End Chat"
|
|
960
960
|
}
|
|
@@ -967,7 +967,7 @@ const Z = ({
|
|
|
967
967
|
icon: Ht,
|
|
968
968
|
agentLogo: Pt,
|
|
969
969
|
unreadBadge: Et
|
|
970
|
-
},
|
|
970
|
+
}, ae = ({
|
|
971
971
|
onClick: o,
|
|
972
972
|
agentLogoUrl: t,
|
|
973
973
|
unreadCount: s = 0
|
|
@@ -1001,7 +1001,7 @@ const Z = ({
|
|
|
1001
1001
|
s > 0 && /* @__PURE__ */ e("span", { className: Q.unreadBadge, children: s > 9 ? "9+" : s })
|
|
1002
1002
|
]
|
|
1003
1003
|
}
|
|
1004
|
-
), jt = "_container_kgfgt_1", Vt = "_header_kgfgt_25", At = "_logoWrapper_kgfgt_38", zt = "_logo_kgfgt_38", Ft = "_closeButton_kgfgt_51", Ot = "_content_kgfgt_74", Rt = "_iconWrapper_kgfgt_84", Ut = "_errorIcon_kgfgt_95", Zt = "_title_kgfgt_101", qt = "_description_kgfgt_109", Kt = "_retryButton_kgfgt_117", Gt = "_footer_kgfgt_139", Jt = "_poweredBy_kgfgt_146", Yt = "_footerLogo_kgfgt_160",
|
|
1004
|
+
), jt = "_container_kgfgt_1", Vt = "_header_kgfgt_25", At = "_logoWrapper_kgfgt_38", zt = "_logo_kgfgt_38", Ft = "_closeButton_kgfgt_51", Ot = "_content_kgfgt_74", Rt = "_iconWrapper_kgfgt_84", Ut = "_errorIcon_kgfgt_95", Zt = "_title_kgfgt_101", qt = "_description_kgfgt_109", Kt = "_retryButton_kgfgt_117", Gt = "_footer_kgfgt_139", Jt = "_poweredBy_kgfgt_146", Yt = "_footerLogo_kgfgt_160", k = {
|
|
1005
1005
|
container: jt,
|
|
1006
1006
|
header: Vt,
|
|
1007
1007
|
logoWrapper: At,
|
|
@@ -1022,13 +1022,13 @@ const Z = ({
|
|
|
1022
1022
|
onRetry: s,
|
|
1023
1023
|
onClose: r
|
|
1024
1024
|
}) => {
|
|
1025
|
-
const
|
|
1025
|
+
const u = () => {
|
|
1026
1026
|
switch (o) {
|
|
1027
1027
|
case "not_found":
|
|
1028
1028
|
return {
|
|
1029
1029
|
title: "Chat Not Found",
|
|
1030
1030
|
description: t || "This chat widget is not configured correctly. Please check the embed ID.",
|
|
1031
|
-
icon: /* @__PURE__ */ i("svg", { viewBox: "0 0 24 24", fill: "none", className:
|
|
1031
|
+
icon: /* @__PURE__ */ i("svg", { viewBox: "0 0 24 24", fill: "none", className: k.errorIcon, children: [
|
|
1032
1032
|
/* @__PURE__ */ e(
|
|
1033
1033
|
"circle",
|
|
1034
1034
|
{
|
|
@@ -1054,7 +1054,7 @@ const Z = ({
|
|
|
1054
1054
|
return {
|
|
1055
1055
|
title: "Connection Error",
|
|
1056
1056
|
description: t || "Unable to connect to the chat service. Please check your internet connection.",
|
|
1057
|
-
icon: /* @__PURE__ */ i("svg", { viewBox: "0 0 24 24", fill: "none", className:
|
|
1057
|
+
icon: /* @__PURE__ */ i("svg", { viewBox: "0 0 24 24", fill: "none", className: k.errorIcon, children: [
|
|
1058
1058
|
/* @__PURE__ */ e(
|
|
1059
1059
|
"path",
|
|
1060
1060
|
{
|
|
@@ -1078,7 +1078,7 @@ const Z = ({
|
|
|
1078
1078
|
return {
|
|
1079
1079
|
title: "Something Went Wrong",
|
|
1080
1080
|
description: t || "An unexpected error occurred. Please try again later.",
|
|
1081
|
-
icon: /* @__PURE__ */ e("svg", { viewBox: "0 0 24 24", fill: "none", className:
|
|
1081
|
+
icon: /* @__PURE__ */ e("svg", { viewBox: "0 0 24 24", fill: "none", className: k.errorIcon, children: /* @__PURE__ */ e(
|
|
1082
1082
|
"path",
|
|
1083
1083
|
{
|
|
1084
1084
|
d: "M12 9V13M12 17H12.01M21 12C21 16.9706 16.9706 21 12 21C7.02944 21 3 16.9706 3 12C3 7.02944 7.02944 3 12 3C16.9706 3 21 7.02944 21 12Z",
|
|
@@ -1089,13 +1089,13 @@ const Z = ({
|
|
|
1089
1089
|
) })
|
|
1090
1090
|
};
|
|
1091
1091
|
}
|
|
1092
|
-
}, { title:
|
|
1093
|
-
return /* @__PURE__ */ i("div", { className:
|
|
1094
|
-
/* @__PURE__ */ i("div", { className:
|
|
1095
|
-
/* @__PURE__ */ e("div", { className:
|
|
1096
|
-
|
|
1092
|
+
}, { title: m, description: c, icon: g } = u();
|
|
1093
|
+
return /* @__PURE__ */ i("div", { className: k.container, children: [
|
|
1094
|
+
/* @__PURE__ */ i("div", { className: k.header, children: [
|
|
1095
|
+
/* @__PURE__ */ e("div", { className: k.logoWrapper, children: /* @__PURE__ */ e(
|
|
1096
|
+
q,
|
|
1097
1097
|
{
|
|
1098
|
-
className:
|
|
1098
|
+
className: k.logo,
|
|
1099
1099
|
color: "white",
|
|
1100
1100
|
cutoutColor: "var(--bb-primary-color)"
|
|
1101
1101
|
}
|
|
@@ -1103,7 +1103,7 @@ const Z = ({
|
|
|
1103
1103
|
r && /* @__PURE__ */ e(
|
|
1104
1104
|
"button",
|
|
1105
1105
|
{
|
|
1106
|
-
className:
|
|
1106
|
+
className: k.closeButton,
|
|
1107
1107
|
onClick: r,
|
|
1108
1108
|
"aria-label": "Close",
|
|
1109
1109
|
type: "button",
|
|
@@ -1119,26 +1119,26 @@ const Z = ({
|
|
|
1119
1119
|
}
|
|
1120
1120
|
)
|
|
1121
1121
|
] }),
|
|
1122
|
-
/* @__PURE__ */ i("div", { className:
|
|
1123
|
-
/* @__PURE__ */ e("div", { className:
|
|
1124
|
-
/* @__PURE__ */ e("h2", { className:
|
|
1125
|
-
/* @__PURE__ */ e("p", { className:
|
|
1126
|
-
s && /* @__PURE__ */ e("button", { className:
|
|
1122
|
+
/* @__PURE__ */ i("div", { className: k.content, children: [
|
|
1123
|
+
/* @__PURE__ */ e("div", { className: k.iconWrapper, children: g }),
|
|
1124
|
+
/* @__PURE__ */ e("h2", { className: k.title, children: m }),
|
|
1125
|
+
/* @__PURE__ */ e("p", { className: k.description, children: c }),
|
|
1126
|
+
s && /* @__PURE__ */ e("button", { className: k.retryButton, onClick: s, type: "button", children: "Try Again" })
|
|
1127
1127
|
] }),
|
|
1128
|
-
/* @__PURE__ */ e("div", { className:
|
|
1128
|
+
/* @__PURE__ */ e("div", { className: k.footer, children: /* @__PURE__ */ i(
|
|
1129
1129
|
"a",
|
|
1130
1130
|
{
|
|
1131
1131
|
href: "https://brainbaselabs.com",
|
|
1132
1132
|
target: "_blank",
|
|
1133
1133
|
rel: "noopener noreferrer",
|
|
1134
|
-
className:
|
|
1134
|
+
className: k.poweredBy,
|
|
1135
1135
|
children: [
|
|
1136
1136
|
"Powered by",
|
|
1137
1137
|
" ",
|
|
1138
1138
|
/* @__PURE__ */ e(
|
|
1139
|
-
|
|
1139
|
+
q,
|
|
1140
1140
|
{
|
|
1141
|
-
className:
|
|
1141
|
+
className: k.footerLogo,
|
|
1142
1142
|
color: "var(--bb-text-tertiary)",
|
|
1143
1143
|
cutoutColor: "var(--bb-surface-bg)"
|
|
1144
1144
|
}
|
|
@@ -1148,7 +1148,7 @@ const Z = ({
|
|
|
1148
1148
|
}
|
|
1149
1149
|
) })
|
|
1150
1150
|
] });
|
|
1151
|
-
}, Qt = "_widget_1ehud_1", eo = "_inline_1ehud_25",
|
|
1151
|
+
}, Qt = "_widget_1ehud_1", eo = "_inline_1ehud_25", V = {
|
|
1152
1152
|
widget: Qt,
|
|
1153
1153
|
"bottom-right": "_bottom-right_1ehud_10",
|
|
1154
1154
|
"bottom-left": "_bottom-left_1ehud_17",
|
|
@@ -1158,126 +1158,135 @@ const Z = ({
|
|
|
1158
1158
|
apiBaseUrl: t = to,
|
|
1159
1159
|
mockMode: s = !1,
|
|
1160
1160
|
mockResponses: r,
|
|
1161
|
-
position:
|
|
1162
|
-
defaultOpen:
|
|
1161
|
+
position: u = "bottom-right",
|
|
1162
|
+
defaultOpen: m = !1,
|
|
1163
1163
|
primaryColor: c,
|
|
1164
|
-
agentName:
|
|
1164
|
+
agentName: g,
|
|
1165
1165
|
welcomeMessage: l,
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1166
|
+
showBranding: n,
|
|
1167
|
+
className: b,
|
|
1168
|
+
onSessionStart: M,
|
|
1169
|
+
onSessionEnd: A,
|
|
1170
|
+
onMessage: H,
|
|
1171
|
+
onError: P
|
|
1171
1172
|
}) => {
|
|
1172
|
-
const [
|
|
1173
|
-
{ primaryColor: c, agentName:
|
|
1173
|
+
const [z, y] = N(m), [_, S] = N(null), [K, G] = N(!0), [E, T] = N(null), [ee, J] = N(), F = te(() => s ? pe(
|
|
1174
|
+
{ primaryColor: c, agentName: g, welcomeMessage: l },
|
|
1174
1175
|
r
|
|
1175
|
-
) : ue(t), [s, c,
|
|
1176
|
-
|
|
1176
|
+
) : ue(t), [s, c, g, l, r, t]), p = x(async () => {
|
|
1177
|
+
G(!0), T(null), J(void 0);
|
|
1177
1178
|
try {
|
|
1178
|
-
const v = await
|
|
1179
|
-
|
|
1179
|
+
const v = await F.getDeploymentConfig(o);
|
|
1180
|
+
S({
|
|
1180
1181
|
...v,
|
|
1181
1182
|
// Allow prop overrides
|
|
1182
1183
|
primaryColor: c ?? v.primaryColor,
|
|
1183
|
-
agentName:
|
|
1184
|
-
welcomeMessage: l ?? v.welcomeMessage
|
|
1184
|
+
agentName: g ?? v.agentName,
|
|
1185
|
+
welcomeMessage: l ?? v.welcomeMessage,
|
|
1186
|
+
styling: {
|
|
1187
|
+
...v.styling ?? {},
|
|
1188
|
+
...n !== void 0 ? { showBranding: n } : {}
|
|
1189
|
+
}
|
|
1185
1190
|
});
|
|
1186
1191
|
} catch (v) {
|
|
1187
|
-
const
|
|
1188
|
-
|
|
1192
|
+
const j = v instanceof Error ? v : new Error("Failed to load config");
|
|
1193
|
+
j.message.includes("404") ? (T("not_found"), J("The chat widget with this embed ID was not found.")) : j.message.includes("Failed to fetch") || j.message.includes("network") ? T("network") : T("unknown"), s && (S({
|
|
1189
1194
|
embedId: o,
|
|
1190
1195
|
deploymentId: "mock-deployment",
|
|
1191
1196
|
workerId: "mock-worker",
|
|
1192
1197
|
flowId: "mock-flow",
|
|
1193
1198
|
primaryColor: c ?? "#1a1a2e",
|
|
1194
|
-
agentName:
|
|
1195
|
-
|
|
1199
|
+
agentName: g ?? "AI Assistant",
|
|
1200
|
+
styling: n !== void 0 ? { showBranding: n } : void 0
|
|
1201
|
+
}), T(null)), P == null || P(j);
|
|
1196
1202
|
} finally {
|
|
1197
|
-
|
|
1203
|
+
G(!1);
|
|
1198
1204
|
}
|
|
1199
|
-
}, [o, s,
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
}, [
|
|
1203
|
-
const
|
|
1205
|
+
}, [o, s, F, c, g, l, P]);
|
|
1206
|
+
Z(() => {
|
|
1207
|
+
p();
|
|
1208
|
+
}, [p]);
|
|
1209
|
+
const I = te(() => _ || {
|
|
1204
1210
|
embedId: o,
|
|
1205
1211
|
deploymentId: "",
|
|
1206
1212
|
workerId: "",
|
|
1207
1213
|
flowId: "",
|
|
1208
1214
|
primaryColor: c,
|
|
1209
|
-
agentName:
|
|
1210
|
-
welcomeMessage: l
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1215
|
+
agentName: g,
|
|
1216
|
+
welcomeMessage: l,
|
|
1217
|
+
styling: n !== void 0 ? {
|
|
1218
|
+
showBranding: n
|
|
1219
|
+
} : void 0
|
|
1220
|
+
}, [_, o, c, g, l, n]), w = le({
|
|
1221
|
+
config: I,
|
|
1222
|
+
apiClient: F,
|
|
1214
1223
|
mockMode: s,
|
|
1215
|
-
onSessionStart:
|
|
1216
|
-
onSessionEnd:
|
|
1217
|
-
onMessage:
|
|
1218
|
-
onError:
|
|
1219
|
-
}),
|
|
1224
|
+
onSessionStart: M,
|
|
1225
|
+
onSessionEnd: A,
|
|
1226
|
+
onMessage: H,
|
|
1227
|
+
onError: P
|
|
1228
|
+
}), d = te(
|
|
1220
1229
|
() => ({
|
|
1221
|
-
"--bb-primary-color": (
|
|
1230
|
+
"--bb-primary-color": (_ == null ? void 0 : _.primaryColor) ?? c ?? "#1a1a2e"
|
|
1222
1231
|
}),
|
|
1223
|
-
[
|
|
1224
|
-
),
|
|
1232
|
+
[_ == null ? void 0 : _.primaryColor, c]
|
|
1233
|
+
), h = () => {
|
|
1225
1234
|
w.endSession(), w.startNewSession();
|
|
1226
|
-
}, h = () => {
|
|
1227
|
-
P(!1);
|
|
1228
1235
|
}, a = () => {
|
|
1229
|
-
|
|
1230
|
-
}, f =
|
|
1231
|
-
|
|
1236
|
+
y(!1);
|
|
1237
|
+
}, f = () => {
|
|
1238
|
+
p();
|
|
1239
|
+
}, B = u === "inline";
|
|
1240
|
+
return K ? null : E && !s ? !B && !z ? /* @__PURE__ */ e(
|
|
1232
1241
|
"div",
|
|
1233
1242
|
{
|
|
1234
|
-
className: `${
|
|
1235
|
-
style:
|
|
1243
|
+
className: `${V.widget} ${V[u]} ${b ?? ""}`,
|
|
1244
|
+
style: d,
|
|
1236
1245
|
children: /* @__PURE__ */ e(
|
|
1237
|
-
|
|
1246
|
+
ae,
|
|
1238
1247
|
{
|
|
1239
|
-
onClick: () =>
|
|
1240
|
-
agentName:
|
|
1248
|
+
onClick: () => y(!0),
|
|
1249
|
+
agentName: g
|
|
1241
1250
|
}
|
|
1242
1251
|
)
|
|
1243
1252
|
}
|
|
1244
1253
|
) : /* @__PURE__ */ e(
|
|
1245
1254
|
"div",
|
|
1246
1255
|
{
|
|
1247
|
-
className: `${
|
|
1248
|
-
style:
|
|
1256
|
+
className: `${V.widget} ${V[u]} ${b ?? ""}`,
|
|
1257
|
+
style: d,
|
|
1249
1258
|
children: /* @__PURE__ */ e(
|
|
1250
1259
|
Xt,
|
|
1251
1260
|
{
|
|
1252
|
-
errorType:
|
|
1253
|
-
message:
|
|
1254
|
-
onRetry:
|
|
1255
|
-
onClose:
|
|
1261
|
+
errorType: E,
|
|
1262
|
+
message: ee,
|
|
1263
|
+
onRetry: f,
|
|
1264
|
+
onClose: B ? void 0 : a
|
|
1256
1265
|
}
|
|
1257
1266
|
)
|
|
1258
1267
|
}
|
|
1259
1268
|
) : /* @__PURE__ */ e(
|
|
1260
1269
|
"div",
|
|
1261
1270
|
{
|
|
1262
|
-
className: `${
|
|
1263
|
-
style:
|
|
1264
|
-
children:
|
|
1271
|
+
className: `${V.widget} ${V[u]} ${b ?? ""}`,
|
|
1272
|
+
style: d,
|
|
1273
|
+
children: z || B ? /* @__PURE__ */ e(
|
|
1265
1274
|
Wt,
|
|
1266
1275
|
{
|
|
1267
|
-
config:
|
|
1276
|
+
config: I,
|
|
1268
1277
|
messages: w.messages,
|
|
1269
1278
|
toolCalls: w.toolCalls,
|
|
1270
1279
|
isLoading: w.isLoading,
|
|
1271
1280
|
onSendMessage: w.sendMessage,
|
|
1272
|
-
onClose:
|
|
1273
|
-
onNewChat:
|
|
1281
|
+
onClose: B ? void 0 : a,
|
|
1282
|
+
onNewChat: h
|
|
1274
1283
|
}
|
|
1275
1284
|
) : /* @__PURE__ */ e(
|
|
1276
|
-
|
|
1285
|
+
ae,
|
|
1277
1286
|
{
|
|
1278
|
-
onClick: () =>
|
|
1279
|
-
agentName:
|
|
1280
|
-
agentLogoUrl:
|
|
1287
|
+
onClick: () => y(!0),
|
|
1288
|
+
agentName: _ == null ? void 0 : _.agentName,
|
|
1289
|
+
agentLogoUrl: _ == null ? void 0 : _.agentLogoUrl
|
|
1281
1290
|
}
|
|
1282
1291
|
)
|
|
1283
1292
|
}
|
|
@@ -1292,18 +1301,18 @@ function ro() {
|
|
|
1292
1301
|
export {
|
|
1293
1302
|
Wt as ChatContainer,
|
|
1294
1303
|
Me as ChatHeader,
|
|
1295
|
-
|
|
1304
|
+
ae as ChatToggleButton,
|
|
1296
1305
|
so as ChatWidget,
|
|
1297
1306
|
Fe as Message,
|
|
1298
|
-
|
|
1307
|
+
bt as MessageInput,
|
|
1299
1308
|
mt as MessageList,
|
|
1300
1309
|
et as ToolCallDisplay,
|
|
1301
1310
|
ct as TypingIndicator,
|
|
1302
|
-
|
|
1311
|
+
re as clearSession,
|
|
1303
1312
|
ue as createAPIClient,
|
|
1304
1313
|
pe as createMockAPIClient,
|
|
1305
1314
|
ro as generateSessionId,
|
|
1306
1315
|
ie as getStoredSession,
|
|
1307
|
-
|
|
1316
|
+
se as storeSession,
|
|
1308
1317
|
le as useChat
|
|
1309
1318
|
};
|