@livelayer/react 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,33 +1,1250 @@
1
- import { jsx as g } from "react/jsx-runtime";
2
- import { useRef as u, useCallback as p, useEffect as v } from "react";
3
- import "@livelayer/sdk";
4
- const h = ({
5
- agentId: c,
6
- baseUrl: s,
7
- apiKey: o,
8
- mode: t,
1
+ "use client";
2
+ import { jsxs as f, jsx as e } from "react/jsx-runtime";
3
+ import { Component as ze, useState as E, useRef as N, useEffect as C, useCallback as y, useMemo as ae } from "react";
4
+ import { LiveKitSession as Re } from "@livelayer/sdk";
5
+ import { createLocalAudioTrack as Ie } from "livekit-client";
6
+ class Ae extends ze {
7
+ constructor() {
8
+ super(...arguments), this.state = { hasError: !1, error: null }, this.reset = () => {
9
+ this.setState({ hasError: !1, error: null });
10
+ };
11
+ }
12
+ static getDerivedStateFromError(t) {
13
+ return { hasError: !0, error: t };
14
+ }
15
+ componentDidCatch(t, r) {
16
+ var i, l;
17
+ (l = (i = this.props).onError) == null || l.call(i, t, r);
18
+ }
19
+ render() {
20
+ var t;
21
+ return this.state.hasError ? this.props.fallback ? this.props.fallback : /* @__PURE__ */ f("div", { className: "ll-error-boundary", role: "alert", children: [
22
+ /* @__PURE__ */ e("p", { className: "ll-error-boundary__title", children: "Widget crashed" }),
23
+ /* @__PURE__ */ e("p", { className: "ll-error-boundary__message", children: ((t = this.state.error) == null ? void 0 : t.message) || "Something went wrong." }),
24
+ /* @__PURE__ */ e(
25
+ "button",
26
+ {
27
+ type: "button",
28
+ className: "ll-error-boundary__retry",
29
+ onClick: this.reset,
30
+ children: "Reload widget"
31
+ }
32
+ )
33
+ ] }) : this.props.children;
34
+ }
35
+ }
36
+ function Te(n) {
37
+ const [t, r] = E("idle"), [i, l] = E("idle"), [a, m] = E([]), [u, p] = E(null), [g, d] = E(null), [c, o] = E(null), [_, b] = E(!1), [M, S] = E(null), I = N(null), A = N(n.onDataMessage);
38
+ A.current = n.onDataMessage, C(() => {
39
+ const w = {
40
+ onConnectionStateChange: (v) => {
41
+ r(v), v === "connected" && S(null);
42
+ },
43
+ onAgentStateChange: l,
44
+ onTranscript: (v) => m([...v]),
45
+ onAgentConfig: p,
46
+ onAudioTrack: (v) => o(v),
47
+ onVideoTrack: (v) => d(v),
48
+ onVideoTrackRemoved: () => d(null),
49
+ onError: (v) => S(v),
50
+ onDataMessage: (v) => {
51
+ var B;
52
+ (B = A.current) == null || B.call(A, v);
53
+ },
54
+ onResumabilityChange: b
55
+ }, L = new Re(
56
+ {
57
+ agentId: n.agentId,
58
+ baseUrl: n.baseUrl,
59
+ apiKey: n.apiKey,
60
+ sessionEndpoint: n.sessionEndpoint,
61
+ sessionBody: n.sessionBody
62
+ },
63
+ w
64
+ );
65
+ return I.current = L, r("idle"), l("idle"), m([]), p(null), d(null), o(null), b(!1), S(null), () => {
66
+ var v;
67
+ (v = L.destroy) == null || v.call(L), I.current = null;
68
+ };
69
+ }, [
70
+ n.agentId,
71
+ n.baseUrl,
72
+ n.apiKey,
73
+ n.sessionEndpoint,
74
+ JSON.stringify(n.sessionBody ?? {})
75
+ ]);
76
+ const P = y(async () => {
77
+ const w = I.current;
78
+ if (w)
79
+ try {
80
+ await w.connect();
81
+ } catch (L) {
82
+ throw S(L instanceof Error ? L.message : String(L)), L;
83
+ }
84
+ }, []), $ = y(() => {
85
+ const w = I.current;
86
+ w && w.disconnect();
87
+ }, []), z = y(() => {
88
+ var w;
89
+ return ((w = I.current) == null ? void 0 : w.getRoom()) ?? null;
90
+ }, []);
91
+ return {
92
+ connectionState: t,
93
+ agentState: i,
94
+ transcript: a,
95
+ agentConfig: u,
96
+ videoElement: g,
97
+ audioElement: c,
98
+ canResume: _,
99
+ error: M,
100
+ connect: P,
101
+ disconnect: $,
102
+ getRoom: z,
103
+ session: I.current
104
+ };
105
+ }
106
+ function Be() {
107
+ const n = N(null), t = N(null), r = N(null), i = N(null), l = N(/* @__PURE__ */ new Set()), a = N(null), m = y(() => {
108
+ const c = t.current;
109
+ if (!c) {
110
+ i.current = null;
111
+ return;
112
+ }
113
+ (!a.current || a.current.length !== c.frequencyBinCount) && (a.current = new Uint8Array(
114
+ new ArrayBuffer(c.frequencyBinCount)
115
+ ));
116
+ const o = a.current;
117
+ c.getByteFrequencyData(o);
118
+ let _ = 0;
119
+ for (let M = 0; M < o.length; M++) _ += o[M];
120
+ const b = _ / o.length / 255;
121
+ for (const M of l.current)
122
+ try {
123
+ M(b);
124
+ } catch (S) {
125
+ console.error("[useAudioLevel] subscriber threw:", S);
126
+ }
127
+ i.current = requestAnimationFrame(m);
128
+ }, []), u = y(() => {
129
+ if (n.current || typeof window > "u" || typeof AudioContext > "u") return;
130
+ const c = new AudioContext(), o = c.createAnalyser();
131
+ o.fftSize = 64, o.connect(c.destination), n.current = c, t.current = o;
132
+ }, []), p = y(
133
+ (c) => {
134
+ if (u(), !(!n.current || !t.current)) {
135
+ if (r.current) {
136
+ try {
137
+ r.current.disconnect();
138
+ } catch {
139
+ }
140
+ r.current = null;
141
+ }
142
+ try {
143
+ const o = n.current.createMediaElementSource(c);
144
+ o.connect(t.current), r.current = o;
145
+ } catch (o) {
146
+ console.warn("[useAudioLevel] createMediaElementSource failed:", o);
147
+ return;
148
+ }
149
+ i.current === null && (i.current = requestAnimationFrame(m));
150
+ }
151
+ },
152
+ [u, m]
153
+ ), g = y(() => {
154
+ if (i.current !== null && (cancelAnimationFrame(i.current), i.current = null), r.current) {
155
+ try {
156
+ r.current.disconnect();
157
+ } catch {
158
+ }
159
+ r.current = null;
160
+ }
161
+ }, []), d = y((c) => (l.current.add(c), () => {
162
+ l.current.delete(c);
163
+ }), []);
164
+ return C(() => () => {
165
+ if (g(), t.current) {
166
+ try {
167
+ t.current.disconnect();
168
+ } catch {
169
+ }
170
+ t.current = null;
171
+ }
172
+ if (n.current) {
173
+ try {
174
+ n.current.close();
175
+ } catch {
176
+ }
177
+ n.current = null;
178
+ }
179
+ l.current.clear(), a.current = null;
180
+ }, [g]), { attach: p, detach: g, subscribe: d };
181
+ }
182
+ function De() {
183
+ const [n, t] = E(!1), [r, i] = E(null), l = N(null), a = N(null), m = y(async (d) => {
184
+ if (l.current && a.current) {
185
+ try {
186
+ await a.current.localParticipant.unpublishTrack(l.current);
187
+ } catch {
188
+ }
189
+ l.current.stop(), l.current = null;
190
+ }
191
+ a.current = d, i(null);
192
+ try {
193
+ const c = await Ie({
194
+ echoCancellation: !0,
195
+ noiseSuppression: !0
196
+ });
197
+ await d.localParticipant.publishTrack(c), l.current = c, t(c.isMuted);
198
+ } catch (c) {
199
+ const o = c instanceof Error && c.name === "NotAllowedError" ? "Enable your microphone to talk with the agent." : "Microphone unavailable. Check browser permissions and try again.";
200
+ throw i(o), c;
201
+ }
202
+ }, []), u = y(() => {
203
+ const d = l.current;
204
+ d && (d.isMuted ? (d.unmute(), t(!1)) : (d.mute(), t(!0)));
205
+ }, []), p = y(() => {
206
+ const d = l.current, c = a.current;
207
+ if (d && c) {
208
+ try {
209
+ c.localParticipant.unpublishTrack(d);
210
+ } catch {
211
+ }
212
+ d.stop();
213
+ }
214
+ l.current = null, a.current = null, t(!1);
215
+ }, []), g = y(() => i(null), []);
216
+ return {
217
+ isMuted: n,
218
+ micError: r,
219
+ toggleMute: u,
220
+ setupMic: m,
221
+ teardownMic: p,
222
+ clearError: g
223
+ };
224
+ }
225
+ function je(n) {
226
+ if (typeof window > "u") return null;
227
+ try {
228
+ return window.localStorage.getItem(n);
229
+ } catch {
230
+ return null;
231
+ }
232
+ }
233
+ function Ue(n, t) {
234
+ if (!(typeof window > "u"))
235
+ try {
236
+ window.localStorage.setItem(n, t);
237
+ } catch {
238
+ }
239
+ }
240
+ function Pe({
241
+ value: n,
242
+ defaultValue: t = "expanded",
243
+ onChange: r
244
+ } = {}) {
245
+ const i = n !== void 0, [l, a] = E(t), m = i ? n : l, u = y(
246
+ (p) => {
247
+ p !== m && (i || a(p), r == null || r(p));
248
+ },
249
+ [m, i, r]
250
+ );
251
+ return [m, u];
252
+ }
253
+ const $e = ["hidden", "minimized", "expanded"];
254
+ function Ve(n) {
255
+ return n && $e.includes(n) ? n : null;
256
+ }
257
+ function We({
258
+ value: n,
259
+ defaultValue: t = "expanded",
260
+ onChange: r,
261
+ persistKey: i = "ll-widget",
262
+ disablePersistence: l = !1
263
+ } = {}) {
264
+ const a = `${i}:display-mode`, m = N(!1), [u, p] = Pe({
265
+ value: n,
266
+ defaultValue: t,
267
+ onChange: (g) => {
268
+ n === void 0 && !l && Ue(a, g), r == null || r(g);
269
+ }
270
+ });
271
+ return C(() => {
272
+ if (m.current || (m.current = !0, l || n !== void 0)) return;
273
+ const g = Ve(je(a));
274
+ g && g !== u && p(g);
275
+ }, []), [u, p];
276
+ }
277
+ const Ke = 640;
278
+ function qe(n = Ke) {
279
+ const [t, r] = E(!1);
280
+ return C(() => {
281
+ if (n === !1) {
282
+ r(!1);
283
+ return;
284
+ }
285
+ if (typeof window > "u" || typeof window.matchMedia > "u")
286
+ return;
287
+ const i = `(max-width: ${n - 1}px)`, l = window.matchMedia(i), a = () => r(l.matches);
288
+ return a(), typeof l.addEventListener == "function" ? (l.addEventListener("change", a), () => l.removeEventListener("change", a)) : (l.addListener(a), () => {
289
+ l.removeListener(a);
290
+ });
291
+ }, [n]), t;
292
+ }
293
+ const oe = ({ muted: n = !1, className: t }) => n ? /* @__PURE__ */ f(
294
+ "svg",
295
+ {
296
+ className: t,
297
+ fill: "none",
298
+ viewBox: "0 0 24 24",
299
+ stroke: "currentColor",
300
+ strokeWidth: 2,
301
+ "aria-hidden": "true",
302
+ children: [
303
+ /* @__PURE__ */ e(
304
+ "path",
305
+ {
306
+ strokeLinecap: "round",
307
+ strokeLinejoin: "round",
308
+ d: "M5.586 15H4a1 1 0 01-1-1v-4a1 1 0 011-1h1.586l4.707-4.707C10.923 3.663 12 4.109 12 5v14c0 .891-1.077 1.337-1.707.707L5.586 15z"
309
+ }
310
+ ),
311
+ /* @__PURE__ */ e(
312
+ "path",
313
+ {
314
+ strokeLinecap: "round",
315
+ strokeLinejoin: "round",
316
+ d: "M17 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2"
317
+ }
318
+ )
319
+ ]
320
+ }
321
+ ) : /* @__PURE__ */ e(
322
+ "svg",
323
+ {
324
+ className: t,
325
+ fill: "none",
326
+ viewBox: "0 0 24 24",
327
+ stroke: "currentColor",
328
+ strokeWidth: 2,
329
+ "aria-hidden": "true",
330
+ children: /* @__PURE__ */ e(
331
+ "path",
332
+ {
333
+ strokeLinecap: "round",
334
+ strokeLinejoin: "round",
335
+ d: "M19 11a7 7 0 01-7 7m0 0a7 7 0 01-7-7m7 7v4m0 0H8m4 0h4M12 1a3 3 0 00-3 3v4a3 3 0 006 0V4a3 3 0 00-3-3z"
336
+ }
337
+ )
338
+ }
339
+ ), _e = ({ className: n }) => /* @__PURE__ */ e(
340
+ "svg",
341
+ {
342
+ className: n,
343
+ fill: "none",
344
+ viewBox: "0 0 24 24",
345
+ stroke: "currentColor",
346
+ strokeWidth: 2,
347
+ "aria-hidden": "true",
348
+ children: /* @__PURE__ */ e(
349
+ "path",
350
+ {
351
+ strokeLinecap: "round",
352
+ strokeLinejoin: "round",
353
+ d: "M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"
354
+ }
355
+ )
356
+ }
357
+ ), ge = ({ className: n }) => /* @__PURE__ */ e(
358
+ "svg",
359
+ {
360
+ className: n,
361
+ fill: "none",
362
+ viewBox: "0 0 24 24",
363
+ stroke: "currentColor",
364
+ strokeWidth: 2,
365
+ "aria-hidden": "true",
366
+ children: /* @__PURE__ */ e("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M19 9l-7 7-7-7" })
367
+ }
368
+ ), ve = ({ className: n }) => /* @__PURE__ */ e(
369
+ "svg",
370
+ {
371
+ className: n,
372
+ fill: "none",
373
+ viewBox: "0 0 24 24",
374
+ stroke: "currentColor",
375
+ strokeWidth: 2,
376
+ "aria-hidden": "true",
377
+ children: /* @__PURE__ */ e("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M6 18L18 6M6 6l12 12" })
378
+ }
379
+ ), Fe = {
380
+ left: 180,
381
+ right: 0,
382
+ up: -90,
383
+ down: 90
384
+ }, Oe = ({ direction: n = "right", className: t }) => /* @__PURE__ */ e(
385
+ "svg",
386
+ {
387
+ className: t,
388
+ fill: "none",
389
+ viewBox: "0 0 24 24",
390
+ stroke: "currentColor",
391
+ strokeWidth: 2,
392
+ style: { transform: `rotate(${Fe[n]}deg)` },
393
+ "aria-hidden": "true",
394
+ children: /* @__PURE__ */ e("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M9 5l7 7-7 7" })
395
+ }
396
+ ), He = ({ muted: n = !1, className: t }) => /* @__PURE__ */ f(
397
+ "svg",
398
+ {
399
+ className: t,
400
+ fill: "none",
401
+ viewBox: "0 0 24 24",
402
+ stroke: "currentColor",
403
+ strokeWidth: 2,
404
+ "aria-hidden": "true",
405
+ children: [
406
+ /* @__PURE__ */ e(
407
+ "path",
408
+ {
409
+ strokeLinecap: "round",
410
+ strokeLinejoin: "round",
411
+ d: "M15 9v6m3-9v12M9 5l-3 4H3v6h3l3 4V5z"
412
+ }
413
+ ),
414
+ n && /* @__PURE__ */ e("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M4 20L20 4" })
415
+ ]
416
+ }
417
+ ), Ye = ({ className: n }) => /* @__PURE__ */ e(
418
+ "svg",
419
+ {
420
+ className: n,
421
+ fill: "none",
422
+ viewBox: "0 0 24 24",
423
+ stroke: "currentColor",
424
+ strokeWidth: 2,
425
+ "aria-hidden": "true",
426
+ children: /* @__PURE__ */ e(
427
+ "path",
428
+ {
429
+ strokeLinecap: "round",
430
+ strokeLinejoin: "round",
431
+ d: "M15 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z"
432
+ }
433
+ )
434
+ }
435
+ );
436
+ function Ge(n) {
437
+ return n === "top-left" || n === "bottom-left" ? "left" : "right";
438
+ }
439
+ const Je = ({
440
+ position: n,
441
+ isMobile: t,
442
+ isSpeaking: r,
443
+ onExpand: i,
444
+ label: l = "Open widget"
445
+ }) => {
446
+ const a = Ge(n), m = a === "right" ? "left" : "right", u = [
447
+ "ll-hidden",
448
+ `ll-hidden--${a}`,
449
+ t ? "ll-hidden--mobile" : "ll-hidden--desktop",
450
+ r ? "ll-hidden--speaking" : null
451
+ ].filter(Boolean).join(" ");
452
+ return /* @__PURE__ */ e(
453
+ "button",
454
+ {
455
+ type: "button",
456
+ className: u,
457
+ onClick: i,
458
+ "aria-label": l,
459
+ "data-position": n,
460
+ children: /* @__PURE__ */ e(Oe, { direction: m, className: "ll-hidden__chevron" })
461
+ }
462
+ );
463
+ }, Qe = ({
464
+ audioLevel: n,
465
+ bars: t = 20,
466
+ maxHeight: r = 20,
467
+ minHeight: i = 4,
468
+ className: l,
469
+ barClassName: a
470
+ }) => {
471
+ const m = N(null), u = N([]), p = ae(() => {
472
+ const d = (Math.sqrt(5) - 1) / 2;
473
+ return Array.from({ length: t }, (c, o) => 0.5 + o * d % 1 * 0.5);
474
+ }, [t]);
475
+ C(() => n.subscribe((c) => {
476
+ for (let o = 0; o < t; o++) {
477
+ const _ = u.current[o];
478
+ if (!_) continue;
479
+ const b = Math.max(i, c * r * p[o]);
480
+ _.style.height = `${b}px`;
481
+ }
482
+ }), [n, t, r, i, p]);
483
+ const g = ["ll-waveform", l].filter(Boolean).join(" ");
484
+ return /* @__PURE__ */ e("div", { ref: m, className: g, "aria-hidden": "true", children: Array.from({ length: t }, (d, c) => /* @__PURE__ */ e(
485
+ "div",
486
+ {
487
+ ref: (o) => {
488
+ u.current[c] = o;
489
+ },
490
+ className: ["ll-waveform__bar", a].filter(Boolean).join(" "),
491
+ style: { height: `${i}px` }
492
+ },
493
+ c
494
+ )) });
495
+ }, Xe = ({
496
+ position: n,
497
+ isMobile: t,
498
+ agentName: r,
499
+ avatarImageUrl: i,
500
+ agentState: l,
501
+ isMuted: a,
502
+ audioLevel: m,
503
+ onExpand: u,
504
+ onToggleMute: p,
505
+ onClose: g
506
+ }) => t ? /* @__PURE__ */ e(
507
+ "div",
508
+ {
509
+ className: "ll-minimized ll-minimized--mobile",
510
+ role: "region",
511
+ "aria-label": `${r} widget`,
512
+ children: /* @__PURE__ */ f(
513
+ "button",
514
+ {
515
+ type: "button",
516
+ className: "ll-minimized__surface",
517
+ onClick: u,
518
+ "aria-label": `Expand ${r} widget`,
519
+ children: [
520
+ i ? (
521
+ // eslint-disable-next-line @next/next/no-img-element
522
+ /* @__PURE__ */ e(
523
+ "img",
524
+ {
525
+ src: i,
526
+ alt: r,
527
+ className: "ll-minimized__avatar"
528
+ }
529
+ )
530
+ ) : /* @__PURE__ */ e("div", { className: "ll-minimized__avatar ll-minimized__avatar--placeholder" }),
531
+ /* @__PURE__ */ e(
532
+ Qe,
533
+ {
534
+ audioLevel: m,
535
+ bars: 16,
536
+ maxHeight: 18,
537
+ className: "ll-minimized__waveform"
538
+ }
539
+ ),
540
+ /* @__PURE__ */ e("span", { className: "ll-minimized__name", children: r }),
541
+ /* @__PURE__ */ f("div", { className: "ll-minimized__controls", children: [
542
+ /* @__PURE__ */ e(
543
+ "span",
544
+ {
545
+ className: "ll-minimized__btn",
546
+ role: "button",
547
+ tabIndex: 0,
548
+ onClick: (d) => {
549
+ d.stopPropagation(), p();
550
+ },
551
+ onKeyDown: (d) => {
552
+ (d.key === "Enter" || d.key === " ") && (d.stopPropagation(), d.preventDefault(), p());
553
+ },
554
+ "aria-label": a ? "Unmute microphone" : "Mute microphone",
555
+ children: /* @__PURE__ */ e(oe, { muted: a, className: "ll-minimized__icon" })
556
+ }
557
+ ),
558
+ /* @__PURE__ */ e(_e, { className: "ll-minimized__icon ll-minimized__icon--expand" })
559
+ ] })
560
+ ]
561
+ }
562
+ )
563
+ }
564
+ ) : /* @__PURE__ */ e(
565
+ "div",
566
+ {
567
+ className: "ll-minimized ll-minimized--desktop",
568
+ "data-position": n,
569
+ role: "region",
570
+ "aria-label": `${r} widget`,
571
+ children: /* @__PURE__ */ f("div", { className: "ll-minimized__surface", children: [
572
+ i ? (
573
+ // eslint-disable-next-line @next/next/no-img-element
574
+ /* @__PURE__ */ e(
575
+ "img",
576
+ {
577
+ src: i,
578
+ alt: r,
579
+ className: "ll-minimized__avatar"
580
+ }
581
+ )
582
+ ) : /* @__PURE__ */ e("div", { className: "ll-minimized__avatar ll-minimized__avatar--placeholder" }),
583
+ /* @__PURE__ */ f("div", { className: "ll-minimized__meta", children: [
584
+ /* @__PURE__ */ e("span", { className: "ll-minimized__name", children: r }),
585
+ /* @__PURE__ */ e("span", { className: "ll-minimized__state", children: l === "speaking" ? "Speaking" : l === "thinking" ? "Thinking" : "Listening" })
586
+ ] }),
587
+ /* @__PURE__ */ f("div", { className: "ll-minimized__controls", children: [
588
+ /* @__PURE__ */ e(
589
+ "button",
590
+ {
591
+ type: "button",
592
+ className: "ll-minimized__btn",
593
+ onClick: p,
594
+ "aria-label": a ? "Unmute microphone" : "Mute microphone",
595
+ children: /* @__PURE__ */ e(oe, { muted: a, className: "ll-minimized__icon" })
596
+ }
597
+ ),
598
+ /* @__PURE__ */ e(
599
+ "button",
600
+ {
601
+ type: "button",
602
+ className: "ll-minimized__btn",
603
+ onClick: u,
604
+ "aria-label": `Expand ${r} widget`,
605
+ children: /* @__PURE__ */ e(_e, { className: "ll-minimized__icon" })
606
+ }
607
+ ),
608
+ /* @__PURE__ */ e(
609
+ "button",
610
+ {
611
+ type: "button",
612
+ className: "ll-minimized__btn ll-minimized__btn--close",
613
+ onClick: g,
614
+ "aria-label": "Close widget",
615
+ children: /* @__PURE__ */ e(ve, { className: "ll-minimized__icon" })
616
+ }
617
+ )
618
+ ] })
619
+ ] })
620
+ }
621
+ ), Ze = ({
622
+ src: n,
623
+ alt: t,
624
+ preCannedPlaying: r = !1,
625
+ className: i,
626
+ style: l
627
+ }) => {
628
+ const [a, m] = E(!1), u = N(n);
629
+ if (C(() => {
630
+ u.current !== n && (u.current = n, m(!1));
631
+ }, [n]), !n) return null;
632
+ const p = {
633
+ position: "absolute",
634
+ inset: 0,
635
+ width: "100%",
636
+ height: "100%",
637
+ objectFit: "cover",
638
+ objectPosition: "top",
639
+ transition: "opacity 500ms ease, transform 500ms ease",
640
+ transform: r ? "scale(1.02)" : "scale(1)",
641
+ opacity: a ? 1 : 0,
642
+ ...l
643
+ };
644
+ return (
645
+ // eslint-disable-next-line @next/next/no-img-element
646
+ /* @__PURE__ */ e(
647
+ "img",
648
+ {
649
+ src: n,
650
+ alt: t,
651
+ className: i,
652
+ style: p,
653
+ loading: "eager",
654
+ fetchpriority: "high",
655
+ onLoad: () => m(!0)
656
+ }
657
+ )
658
+ );
659
+ }, en = {
660
+ idle: "Idle",
661
+ listening: "Listening",
662
+ thinking: "Thinking",
663
+ speaking: "Speaking"
664
+ }, nn = ({ state: n, className: t }) => {
665
+ const r = ["ll-pill", `ll-pill--${n}`, t].filter(Boolean).join(" ");
666
+ return /* @__PURE__ */ f("div", { className: r, "data-agent-state": n, children: [
667
+ /* @__PURE__ */ e("span", { className: "ll-pill__dot" }),
668
+ /* @__PURE__ */ e("span", { className: "ll-pill__label", children: en[n] })
669
+ ] });
670
+ }, tn = ({
671
+ position: n,
672
+ isMobile: t,
673
+ agentName: r,
674
+ avatarImageUrl: i,
675
+ idleLoopUrl: l,
676
+ greeting: a,
677
+ branding: m,
678
+ teamMembers: u,
679
+ currentTeamMemberId: p,
680
+ isSwitchingTeamMember: g,
681
+ teamSwitcherOpen: d,
682
+ onToggleTeamSwitcher: c,
683
+ onSelectTeamMember: o,
684
+ connectionState: _,
685
+ agentState: b,
686
+ transcript: M,
687
+ isMuted: S,
688
+ needsUserGesture: I,
689
+ canResume: A,
690
+ micError: P,
691
+ error: $,
692
+ avatarVideoContainerRef: z,
693
+ onConnect: w,
694
+ onDisconnect: L,
695
+ onRetry: v,
696
+ onResumeAudio: B,
697
+ onToggleMute: V,
698
+ onMinimize: W,
699
+ onClose: K,
700
+ onClearMicError: x
701
+ }) => {
702
+ const G = M.length > 0 ? M[M.length - 1] : null, J = ((u == null ? void 0 : u.length) ?? 0) > 1, X = m.productName || "Live Layer", q = [
703
+ "ll-expanded",
704
+ t ? "ll-expanded--mobile" : "ll-expanded--desktop"
705
+ ].join(" ");
706
+ return /* @__PURE__ */ f(
707
+ "div",
708
+ {
709
+ className: q,
710
+ "data-position": n,
711
+ role: "dialog",
712
+ "aria-label": `${r} widget`,
713
+ children: [
714
+ /* @__PURE__ */ f("div", { className: "ll-expanded__header", children: [
715
+ /* @__PURE__ */ f("div", { className: "ll-expanded__header-left", children: [
716
+ m.logoUrl && // eslint-disable-next-line @next/next/no-img-element
717
+ /* @__PURE__ */ e(
718
+ "img",
719
+ {
720
+ src: m.logoUrl,
721
+ alt: X,
722
+ className: "ll-expanded__logo"
723
+ }
724
+ ),
725
+ J ? /* @__PURE__ */ f(
726
+ "button",
727
+ {
728
+ type: "button",
729
+ className: "ll-expanded__team-trigger",
730
+ onClick: c,
731
+ "aria-expanded": d,
732
+ "aria-label": "Change team member",
733
+ children: [
734
+ /* @__PURE__ */ e("span", { children: r }),
735
+ /* @__PURE__ */ e(
736
+ ge,
737
+ {
738
+ className: `ll-expanded__team-chevron ${d ? "ll-expanded__team-chevron--open" : ""}`
739
+ }
740
+ )
741
+ ]
742
+ }
743
+ ) : /* @__PURE__ */ e("span", { className: "ll-expanded__name", children: r })
744
+ ] }),
745
+ /* @__PURE__ */ f("div", { className: "ll-expanded__header-right", children: [
746
+ /* @__PURE__ */ e(
747
+ "button",
748
+ {
749
+ type: "button",
750
+ className: "ll-expanded__icon-btn",
751
+ onClick: V,
752
+ "aria-label": S ? "Unmute microphone" : "Mute microphone",
753
+ title: S ? "Unmute" : "Mute",
754
+ children: /* @__PURE__ */ e(He, { muted: S, className: "ll-expanded__icon" })
755
+ }
756
+ ),
757
+ t ? null : /* @__PURE__ */ e(
758
+ "button",
759
+ {
760
+ type: "button",
761
+ className: "ll-expanded__icon-btn",
762
+ onClick: W,
763
+ "aria-label": "Minimize widget",
764
+ title: "Minimize",
765
+ children: /* @__PURE__ */ e(ge, { className: "ll-expanded__icon" })
766
+ }
767
+ ),
768
+ /* @__PURE__ */ e(
769
+ "button",
770
+ {
771
+ type: "button",
772
+ className: "ll-expanded__icon-btn",
773
+ onClick: K,
774
+ "aria-label": "Close widget",
775
+ title: "Close",
776
+ children: /* @__PURE__ */ e(ve, { className: "ll-expanded__icon" })
777
+ }
778
+ )
779
+ ] })
780
+ ] }),
781
+ J && d && /* @__PURE__ */ e("div", { className: "ll-expanded__team-menu", role: "menu", children: u.map((T) => /* @__PURE__ */ f(
782
+ "button",
783
+ {
784
+ type: "button",
785
+ role: "menuitem",
786
+ className: `ll-expanded__team-item ${T.id === p ? "ll-expanded__team-item--active" : ""}`,
787
+ onClick: () => o(T.id),
788
+ children: [
789
+ T.avatarImageUrl && // eslint-disable-next-line @next/next/no-img-element
790
+ /* @__PURE__ */ e(
791
+ "img",
792
+ {
793
+ src: T.avatarImageUrl,
794
+ alt: "",
795
+ className: "ll-expanded__team-item-avatar"
796
+ }
797
+ ),
798
+ /* @__PURE__ */ f("div", { className: "ll-expanded__team-item-meta", children: [
799
+ /* @__PURE__ */ e("span", { className: "ll-expanded__team-item-name", children: T.name }),
800
+ T.role && /* @__PURE__ */ e("span", { className: "ll-expanded__team-item-role", children: T.role })
801
+ ] })
802
+ ]
803
+ },
804
+ T.id
805
+ )) }),
806
+ /* @__PURE__ */ f("div", { className: "ll-expanded__avatar-surface", children: [
807
+ i && /* @__PURE__ */ e(
808
+ Ze,
809
+ {
810
+ src: i,
811
+ alt: r,
812
+ className: "ll-expanded__avatar-image"
813
+ }
814
+ ),
815
+ l && /* @__PURE__ */ e(
816
+ "video",
817
+ {
818
+ className: "ll-expanded__avatar-idle-loop",
819
+ src: l,
820
+ loop: !0,
821
+ muted: !0,
822
+ playsInline: !0,
823
+ autoPlay: !0
824
+ }
825
+ ),
826
+ /* @__PURE__ */ e("div", { ref: z, className: "ll-expanded__avatar-live" }),
827
+ _ === "connecting" && /* @__PURE__ */ f("div", { className: "ll-expanded__overlay ll-expanded__overlay--connecting", children: [
828
+ /* @__PURE__ */ e("div", { className: "ll-expanded__spinner" }),
829
+ /* @__PURE__ */ e("p", { className: "ll-expanded__overlay-text", children: "Connecting..." })
830
+ ] }),
831
+ I && /* @__PURE__ */ f(
832
+ "button",
833
+ {
834
+ type: "button",
835
+ className: "ll-expanded__overlay ll-expanded__overlay--gesture",
836
+ onClick: B,
837
+ children: [
838
+ /* @__PURE__ */ e("div", { className: "ll-expanded__play-circle", children: /* @__PURE__ */ e("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ e("path", { d: "M8 5v14l11-7L8 5z" }) }) }),
839
+ /* @__PURE__ */ e("p", { className: "ll-expanded__overlay-text", children: "Tap to enable audio" }),
840
+ /* @__PURE__ */ e("p", { className: "ll-expanded__overlay-subtext", children: "Your agent is ready" })
841
+ ]
842
+ }
843
+ ),
844
+ !I && (_ === "idle" || _ === "disconnected" || _ === "error") && /* @__PURE__ */ f(
845
+ "button",
846
+ {
847
+ type: "button",
848
+ className: "ll-expanded__overlay ll-expanded__overlay--play",
849
+ onClick: w,
850
+ "aria-label": A ? "Restart paused session" : _ === "disconnected" ? "Reconnect to agent" : "Start video call",
851
+ children: [
852
+ /* @__PURE__ */ e("div", { className: "ll-expanded__play-circle", children: /* @__PURE__ */ e("svg", { width: "26", height: "26", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ e("polygon", { points: "6 3 20 12 6 21 6 3" }) }) }),
853
+ /* @__PURE__ */ e("p", { className: "ll-expanded__overlay-text", children: A ? "Restart session" : _ === "disconnected" ? "Click to reconnect" : a || "Start video call" }),
854
+ A && /* @__PURE__ */ e("p", { className: "ll-expanded__overlay-subtext", children: "Pick up where you left off" })
855
+ ]
856
+ }
857
+ ),
858
+ g && /* @__PURE__ */ f("div", { className: "ll-expanded__overlay ll-expanded__overlay--switching", children: [
859
+ /* @__PURE__ */ e("div", { className: "ll-expanded__spinner" }),
860
+ /* @__PURE__ */ f("p", { className: "ll-expanded__overlay-text", children: [
861
+ "Connecting to ",
862
+ r,
863
+ "..."
864
+ ] })
865
+ ] }),
866
+ _ === "connected" && /* @__PURE__ */ e("div", { className: "ll-expanded__state-pill-wrap", children: /* @__PURE__ */ e(nn, { state: b }) }),
867
+ P && _ === "connected" && /* @__PURE__ */ f("div", { className: "ll-expanded__mic-error", role: "alert", children: [
868
+ /* @__PURE__ */ e("p", { children: P }),
869
+ /* @__PURE__ */ e(
870
+ "button",
871
+ {
872
+ type: "button",
873
+ onClick: () => {
874
+ x(), v();
875
+ },
876
+ children: "Retry"
877
+ }
878
+ )
879
+ ] }),
880
+ _ === "connected" && G && /* @__PURE__ */ e("div", { className: "ll-expanded__transcript", "aria-live": "polite", children: /* @__PURE__ */ e("p", { children: G.text }) })
881
+ ] }),
882
+ /* @__PURE__ */ f("div", { className: "ll-expanded__footer", children: [
883
+ _ === "idle" && /* @__PURE__ */ f(
884
+ "button",
885
+ {
886
+ type: "button",
887
+ className: "ll-expanded__cta ll-expanded__cta--primary",
888
+ onClick: w,
889
+ children: [
890
+ /* @__PURE__ */ e(Ye, { className: "ll-expanded__cta-icon" }),
891
+ /* @__PURE__ */ e("span", { children: "Start Video Call" })
892
+ ]
893
+ }
894
+ ),
895
+ _ === "connecting" && /* @__PURE__ */ f(
896
+ "button",
897
+ {
898
+ type: "button",
899
+ className: "ll-expanded__cta ll-expanded__cta--loading",
900
+ disabled: !0,
901
+ children: [
902
+ /* @__PURE__ */ e("div", { className: "ll-expanded__spinner ll-expanded__spinner--small" }),
903
+ /* @__PURE__ */ e("span", { children: "Connecting..." })
904
+ ]
905
+ }
906
+ ),
907
+ _ === "connected" && /* @__PURE__ */ e(
908
+ "button",
909
+ {
910
+ type: "button",
911
+ className: "ll-expanded__cta ll-expanded__cta--danger",
912
+ onClick: L,
913
+ children: "End conversation"
914
+ }
915
+ ),
916
+ (_ === "error" || _ === "disconnected") && /* @__PURE__ */ f("div", { className: "ll-expanded__retry", children: [
917
+ $ && /* @__PURE__ */ e("p", { className: "ll-expanded__error-text", children: $ }),
918
+ /* @__PURE__ */ f(
919
+ "button",
920
+ {
921
+ type: "button",
922
+ className: "ll-expanded__cta ll-expanded__cta--primary",
923
+ onClick: v,
924
+ children: [
925
+ /* @__PURE__ */ e(oe, { muted: !1, className: "ll-expanded__cta-icon" }),
926
+ /* @__PURE__ */ e("span", { children: "Try again" })
927
+ ]
928
+ }
929
+ )
930
+ ] })
931
+ ] })
932
+ ]
933
+ }
934
+ );
935
+ }, rn = /* @__PURE__ */ new Set([
936
+ "agent_state",
937
+ "avatar_stream_ready",
938
+ "avatar_active",
939
+ "avatar_idle",
940
+ "bot_ready",
941
+ "agent_error",
942
+ "idle_warning",
943
+ "idle_timeout"
944
+ ]);
945
+ function ln(n) {
946
+ var pe, he, fe;
947
+ const {
948
+ agentId: t,
949
+ apiKey: r,
950
+ baseUrl: i = "https://app.livelayer.studio",
951
+ sessionEndpoint: l,
952
+ sessionBody: a,
953
+ autoConnect: m = !1,
954
+ displayMode: u,
955
+ defaultDisplayMode: p = "expanded",
956
+ onDisplayModeChange: g,
957
+ position: d = "bottom-right",
958
+ mobileBreakpoint: c = 640,
959
+ persistKey: o = "ll-widget",
960
+ disablePersistence: _ = !1,
961
+ teamMembers: b,
962
+ currentTeamMemberId: M,
963
+ onTeamMemberChange: S,
964
+ idleLoopUrl: I,
965
+ greeting: A,
966
+ avatarImageUrl: P,
967
+ agentName: $,
968
+ branding: z = {},
969
+ onConnect: w,
970
+ onDisconnect: L,
971
+ onTranscript: v,
972
+ onAgentState: B,
973
+ onConnectionStateChange: V,
974
+ onAgentEvent: W,
975
+ onAgentCommand: K,
976
+ controlledSession: x,
977
+ className: G,
978
+ style: J,
979
+ zIndex: X = 2147483647
980
+ } = n, q = M !== void 0, [T, ye] = E(() => {
981
+ var h;
982
+ return M ?? ((h = b == null ? void 0 : b[0]) == null ? void 0 : h.id);
983
+ }), F = q ? M : T, D = ae(
984
+ () => (b == null ? void 0 : b.find((h) => h.id === F)) ?? null,
985
+ [b, F]
986
+ ), be = (D == null ? void 0 : D.agentId) ?? t, [O, U] = We({
987
+ value: u,
988
+ defaultValue: p,
989
+ onChange: g,
990
+ persistKey: o,
991
+ disablePersistence: _
992
+ }), Q = qe(c), Z = Be(), j = De(), [xe, ee] = E(!1), [ne, ce] = E(!1), [te, re] = E(!1), le = y(
993
+ (h) => {
994
+ const k = h;
995
+ !k.type || typeof k.type != "string" || (W == null || W({ eventName: k.type, data: h }), rn.has(k.type) || K == null || K(k));
996
+ },
997
+ [K, W]
998
+ ), R = Te({
999
+ agentId: x ? "__controlled__" : be,
1000
+ baseUrl: i,
1001
+ apiKey: r,
1002
+ sessionEndpoint: l,
1003
+ sessionBody: a,
1004
+ onDataMessage: x ? void 0 : le
1005
+ });
1006
+ C(() => {
1007
+ if (x != null && x.subscribeToDataMessages)
1008
+ return x.subscribeToDataMessages(le);
1009
+ }, [x, le]);
1010
+ const s = ae(() => x ? {
1011
+ connectionState: x.connectionState,
1012
+ agentState: x.agentState,
1013
+ transcript: x.transcript,
1014
+ videoElement: x.videoElement,
1015
+ audioElement: x.audioElement,
1016
+ canResume: x.canResume,
1017
+ error: x.error,
1018
+ agentConfig: null,
1019
+ connect: async () => {
1020
+ await x.onConnect();
1021
+ },
1022
+ disconnect: () => x.onDisconnect(),
1023
+ // Dummy getRoom for shape compatibility — controlled consumers own the Room.
1024
+ // Internal session's getRoom returns null when no real connect has happened,
1025
+ // so we reuse its reference for type consistency.
1026
+ getRoom: R.getRoom,
1027
+ isControlled: !0
1028
+ } : {
1029
+ connectionState: R.connectionState,
1030
+ agentState: R.agentState,
1031
+ transcript: R.transcript,
1032
+ videoElement: R.videoElement,
1033
+ audioElement: R.audioElement,
1034
+ canResume: R.canResume,
1035
+ error: R.error,
1036
+ agentConfig: R.agentConfig,
1037
+ connect: R.connect,
1038
+ disconnect: R.disconnect,
1039
+ getRoom: R.getRoom,
1040
+ isControlled: !1
1041
+ }, [x, R]), se = N(null);
1042
+ C(() => {
1043
+ const h = s.videoElement, k = se.current;
1044
+ if (!(!h || !k))
1045
+ return k.appendChild(h), () => {
1046
+ h.parentNode === k && k.removeChild(h);
1047
+ };
1048
+ }, [s.videoElement]), C(() => {
1049
+ const h = s.audioElement;
1050
+ if (!h) return;
1051
+ Z.attach(h);
1052
+ const k = h.play();
1053
+ return k && typeof k.catch == "function" && k.catch((Y) => {
1054
+ (Y == null ? void 0 : Y.name) === "NotAllowedError" && ee(!0);
1055
+ }), () => {
1056
+ Z.detach();
1057
+ };
1058
+ }, [s.audioElement]), C(() => {
1059
+ if (s.isControlled || s.connectionState !== "connected") return;
1060
+ const h = s.getRoom();
1061
+ if (h)
1062
+ return j.setupMic(h).catch(() => {
1063
+ }), () => {
1064
+ j.teardownMic();
1065
+ };
1066
+ }, [s.isControlled, s.connectionState]), C(() => {
1067
+ V == null || V(s.connectionState), s.connectionState === "connected" ? w == null || w() : s.connectionState === "disconnected" && (L == null || L());
1068
+ }, [s.connectionState, w, L, V]), C(() => {
1069
+ v == null || v(s.transcript);
1070
+ }, [s.transcript, v]), C(() => {
1071
+ B == null || B(s.agentState);
1072
+ }, [s.agentState, B]);
1073
+ const de = N(!1);
1074
+ C(() => {
1075
+ s.isControlled || !m || de.current || s.connectionState === "idle" && (de.current = !0, s.connect());
1076
+ }, [m, s.connectionState, s]);
1077
+ const ke = y(
1078
+ (h) => {
1079
+ const k = b == null ? void 0 : b.find((Y) => Y.id === h);
1080
+ k && (re(!1), h !== F && (ce(!0), s.disconnect(), q || ye(h), S == null || S(k)));
1081
+ },
1082
+ [
1083
+ b,
1084
+ F,
1085
+ s,
1086
+ q,
1087
+ S
1088
+ ]
1089
+ );
1090
+ C(() => {
1091
+ ne && s.connectionState === "connected" && ce(!1);
1092
+ }, [s.connectionState, ne]), C(() => {
1093
+ if (!te) return;
1094
+ const h = (k) => {
1095
+ k.key === "Escape" && re(!1);
1096
+ };
1097
+ return window.addEventListener("keydown", h), () => window.removeEventListener("keydown", h);
1098
+ }, [te]);
1099
+ const ie = (D == null ? void 0 : D.name) ?? $ ?? ((pe = s.agentConfig) == null ? void 0 : pe.name) ?? "Live Layer", ue = (D == null ? void 0 : D.avatarImageUrl) ?? P ?? ((he = s.agentConfig) == null ? void 0 : he.avatarImageUrl) ?? null, Ne = I ?? ((fe = s.agentConfig) == null ? void 0 : fe.idleLoopUrl) ?? null, we = A ?? null, Ce = y(() => U("expanded"), [U]), Ee = y(
1100
+ () => U("minimized"),
1101
+ [U]
1102
+ ), me = y(() => U("hidden"), [U]), Le = y(() => {
1103
+ const h = s.audioElement;
1104
+ h && h.play().then(() => ee(!1)).catch(() => {
1105
+ });
1106
+ }, [s.audioElement]), Me = y(() => {
1107
+ ee(!1), s.connect();
1108
+ }, [s]), H = {
1109
+ ...J,
1110
+ zIndex: X
1111
+ };
1112
+ z.primaryColor && (H["--ll-color-primary"] = z.primaryColor), z.accentColor && (H["--ll-color-accent"] = z.accentColor), z.backgroundColor && (H["--ll-color-bg"] = z.backgroundColor), z.textColor && (H["--ll-color-fg"] = z.textColor);
1113
+ const Se = [
1114
+ "ll-widget",
1115
+ `ll-widget--${O}`,
1116
+ `ll-widget--${Q ? "mobile" : "desktop"}`,
1117
+ G
1118
+ ].filter(Boolean).join(" ");
1119
+ return /* @__PURE__ */ f(
1120
+ "div",
1121
+ {
1122
+ className: Se,
1123
+ style: H,
1124
+ "data-display-mode": O,
1125
+ "data-position": d,
1126
+ children: [
1127
+ O === "hidden" && /* @__PURE__ */ e(
1128
+ Je,
1129
+ {
1130
+ position: d,
1131
+ isMobile: Q,
1132
+ isSpeaking: s.agentState === "speaking",
1133
+ onExpand: () => U("minimized"),
1134
+ label: `Open ${ie} widget`
1135
+ }
1136
+ ),
1137
+ O === "minimized" && /* @__PURE__ */ e(
1138
+ Xe,
1139
+ {
1140
+ position: d,
1141
+ isMobile: Q,
1142
+ agentName: ie,
1143
+ avatarImageUrl: ue,
1144
+ agentState: s.agentState,
1145
+ isMuted: j.isMuted,
1146
+ audioLevel: Z,
1147
+ onExpand: Ce,
1148
+ onToggleMute: j.toggleMute,
1149
+ onClose: me
1150
+ }
1151
+ ),
1152
+ O === "expanded" && /* @__PURE__ */ e(
1153
+ tn,
1154
+ {
1155
+ position: d,
1156
+ isMobile: Q,
1157
+ agentName: ie,
1158
+ avatarImageUrl: ue,
1159
+ idleLoopUrl: Ne,
1160
+ greeting: we,
1161
+ branding: z,
1162
+ teamMembers: b,
1163
+ currentTeamMemberId: F,
1164
+ isSwitchingTeamMember: ne,
1165
+ teamSwitcherOpen: te,
1166
+ onToggleTeamSwitcher: () => re((h) => !h),
1167
+ onSelectTeamMember: ke,
1168
+ connectionState: s.connectionState,
1169
+ agentState: s.agentState,
1170
+ transcript: s.transcript,
1171
+ isMuted: j.isMuted,
1172
+ needsUserGesture: xe,
1173
+ canResume: s.canResume,
1174
+ micError: j.micError,
1175
+ error: s.error,
1176
+ avatarVideoContainerRef: se,
1177
+ onConnect: () => void s.connect(),
1178
+ onDisconnect: () => s.disconnect(),
1179
+ onRetry: Me,
1180
+ onResumeAudio: Le,
1181
+ onToggleMute: j.toggleMute,
1182
+ onMinimize: Ee,
1183
+ onClose: me,
1184
+ onClearMicError: j.clearError
1185
+ }
1186
+ )
1187
+ ]
1188
+ }
1189
+ );
1190
+ }
1191
+ function un(n) {
1192
+ return /* @__PURE__ */ e(Ae, { children: /* @__PURE__ */ e(ln, { ...n }) });
1193
+ }
1194
+ const mn = ({
1195
+ agentId: n,
1196
+ baseUrl: t,
1197
+ apiKey: r,
1198
+ mode: i,
9
1199
  onAgentEvent: l,
10
- className: m,
11
- style: b
1200
+ className: a,
1201
+ style: m
12
1202
  }) => {
13
- const d = u(null), r = u(null), i = u(l);
14
- i.current = l;
15
- const f = p((n) => {
16
- var a;
17
- const e = n.detail;
18
- (a = i.current) == null || a.call(i, e);
1203
+ const u = N(null), p = N(null), g = N(l);
1204
+ g.current = l;
1205
+ const d = y((c) => {
1206
+ var _;
1207
+ const o = c.detail;
1208
+ (_ = g.current) == null || _.call(g, o);
19
1209
  }, []);
20
- return v(() => {
21
- const n = d.current;
22
- if (!n) return;
23
- const e = document.createElement("livelayer-widget");
24
- return e.setAttribute("agent-id", c), s && e.setAttribute("base-url", s), o && e.setAttribute("api-key", o), t && e.setAttribute("mode", t), e.addEventListener("agent-event", f), n.appendChild(e), r.current = e, () => {
25
- e.removeEventListener("agent-event", f), n.removeChild(e), r.current = null;
1210
+ return C(() => {
1211
+ const c = u.current;
1212
+ if (!c) return;
1213
+ const o = document.createElement("livelayer-widget");
1214
+ return o.setAttribute("agent-id", n), t && o.setAttribute("base-url", t), r && o.setAttribute("api-key", r), i && o.setAttribute("mode", i), o.addEventListener("agent-event", d), c.appendChild(o), p.current = o, () => {
1215
+ o.removeEventListener("agent-event", d), c.removeChild(o), p.current = null;
26
1216
  };
27
- }, [c]), v(() => {
28
- r.current && (t ? r.current.setAttribute("mode", t) : r.current.removeAttribute("mode"));
29
- }, [t]), /* @__PURE__ */ g("div", { ref: d, className: m, style: b });
1217
+ }, [n]), C(() => {
1218
+ p.current && (i ? p.current.setAttribute("mode", i) : p.current.removeAttribute("mode"));
1219
+ }, [i]), /* @__PURE__ */ e("div", { ref: u, className: a, style: m });
30
1220
  };
1221
+ function pn() {
1222
+ const [n, t] = E([]), r = y((l) => {
1223
+ t((a) => {
1224
+ const m = a.findIndex((u) => u.id === l.id);
1225
+ if (m >= 0) {
1226
+ const u = a.slice();
1227
+ return u[m] = l, u;
1228
+ }
1229
+ return [...a, l];
1230
+ });
1231
+ }, []), i = y(() => t([]), []);
1232
+ return {
1233
+ entries: n,
1234
+ pushSegment: r,
1235
+ clear: i,
1236
+ latest: n.length > 0 ? n[n.length - 1] : null
1237
+ };
1238
+ }
31
1239
  export {
32
- h as LiveLayerWidget
1240
+ un as AvatarWidget,
1241
+ Ae as ErrorBoundary,
1242
+ mn as LiveLayerWidget,
1243
+ Be as useAudioLevel,
1244
+ Pe as useDisplayMode,
1245
+ We as useDisplayModePersistence,
1246
+ qe as useIsMobile,
1247
+ Te as useLiveKitSession,
1248
+ De as useMicrophoneState,
1249
+ pn as useTranscript
33
1250
  };