@livelayer/react 0.1.0 → 0.2.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/dist/index.mjs CHANGED
@@ -1,33 +1,1763 @@
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,
9
- onAgentEvent: l,
10
- className: m,
11
- style: b
1
+ "use client";
2
+ import { jsxs as w, jsx as e, Fragment as Qe } from "react/jsx-runtime";
3
+ import { Component as Ze, useState as x, useRef as S, useEffect as L, useCallback as f, useMemo as Se } from "react";
4
+ import { LiveKitSession as et } from "@livelayer/sdk";
5
+ import { createLocalAudioTrack as tt, Track as Oe, createLocalVideoTrack as nt } from "livekit-client";
6
+ class rt 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(n) {
13
+ return { hasError: !0, error: n };
14
+ }
15
+ componentDidCatch(n, i) {
16
+ var o, r;
17
+ (r = (o = this.props).onError) == null || r.call(o, n, i);
18
+ }
19
+ render() {
20
+ var n;
21
+ return this.state.hasError ? this.props.fallback ? this.props.fallback : /* @__PURE__ */ w("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: ((n = this.state.error) == null ? void 0 : n.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 it(t) {
37
+ const [n, i] = x("idle"), [o, r] = x("idle"), [a, c] = x([]), [m, d] = x(null), [g, u] = x(null), [s, l] = x(null), [b, _] = x(!1), [N, D] = x(null), E = S(null), R = S(t.onDataMessage);
38
+ R.current = t.onDataMessage, L(() => {
39
+ const k = {
40
+ onConnectionStateChange: (y) => {
41
+ i(y), y === "connected" && D(null);
42
+ },
43
+ onAgentStateChange: r,
44
+ onTranscript: (y) => c([...y]),
45
+ onAgentConfig: d,
46
+ onAudioTrack: (y) => l(y),
47
+ onVideoTrack: (y) => u(y),
48
+ onVideoTrackRemoved: () => u(null),
49
+ onError: (y) => D(y),
50
+ onDataMessage: (y) => {
51
+ var A;
52
+ (A = R.current) == null || A.call(R, y);
53
+ },
54
+ onResumabilityChange: _
55
+ }, C = new et(
56
+ {
57
+ agentId: t.agentId,
58
+ baseUrl: t.baseUrl,
59
+ apiKey: t.apiKey,
60
+ sessionEndpoint: t.sessionEndpoint,
61
+ sessionBody: t.sessionBody
62
+ },
63
+ k
64
+ );
65
+ return E.current = C, i("idle"), r("idle"), c([]), d(null), u(null), l(null), _(!1), D(null), () => {
66
+ var y;
67
+ (y = C.destroy) == null || y.call(C), E.current = null;
68
+ };
69
+ }, [
70
+ t.agentId,
71
+ t.baseUrl,
72
+ t.apiKey,
73
+ t.sessionEndpoint,
74
+ JSON.stringify(t.sessionBody ?? {})
75
+ ]);
76
+ const T = f(async () => {
77
+ const k = E.current;
78
+ if (k)
79
+ try {
80
+ await k.connect();
81
+ } catch (C) {
82
+ throw D(C instanceof Error ? C.message : String(C)), C;
83
+ }
84
+ }, []), z = f(() => {
85
+ const k = E.current;
86
+ k && k.disconnect();
87
+ }, []), I = f(() => {
88
+ var k;
89
+ return ((k = E.current) == null ? void 0 : k.getRoom()) ?? null;
90
+ }, []);
91
+ return {
92
+ connectionState: n,
93
+ agentState: o,
94
+ transcript: a,
95
+ agentConfig: m,
96
+ videoElement: g,
97
+ audioElement: s,
98
+ canResume: b,
99
+ error: N,
100
+ connect: T,
101
+ disconnect: z,
102
+ getRoom: I,
103
+ session: E.current
104
+ };
105
+ }
106
+ function ot() {
107
+ const t = S(null), n = S(null), i = S(null), o = S(null), r = S(/* @__PURE__ */ new Set()), a = S(null), c = f(() => {
108
+ const s = n.current;
109
+ if (!s) {
110
+ o.current = null;
111
+ return;
112
+ }
113
+ (!a.current || a.current.length !== s.frequencyBinCount) && (a.current = new Uint8Array(
114
+ new ArrayBuffer(s.frequencyBinCount)
115
+ ));
116
+ const l = a.current;
117
+ s.getByteFrequencyData(l);
118
+ let b = 0;
119
+ for (let N = 0; N < l.length; N++) b += l[N];
120
+ const _ = b / l.length / 255;
121
+ for (const N of r.current)
122
+ try {
123
+ N(_);
124
+ } catch (D) {
125
+ console.error("[useAudioLevel] subscriber threw:", D);
126
+ }
127
+ o.current = requestAnimationFrame(c);
128
+ }, []), m = f(() => {
129
+ if (t.current || typeof window > "u" || typeof AudioContext > "u") return;
130
+ const s = new AudioContext(), l = s.createAnalyser();
131
+ l.fftSize = 64, l.connect(s.destination), t.current = s, n.current = l;
132
+ }, []), d = f(
133
+ (s) => {
134
+ if (m(), !(!t.current || !n.current)) {
135
+ if (i.current) {
136
+ try {
137
+ i.current.disconnect();
138
+ } catch {
139
+ }
140
+ i.current = null;
141
+ }
142
+ try {
143
+ const l = t.current.createMediaElementSource(s);
144
+ l.connect(n.current), i.current = l;
145
+ } catch (l) {
146
+ console.warn("[useAudioLevel] createMediaElementSource failed:", l);
147
+ return;
148
+ }
149
+ o.current === null && (o.current = requestAnimationFrame(c));
150
+ }
151
+ },
152
+ [m, c]
153
+ ), g = f(() => {
154
+ if (o.current !== null && (cancelAnimationFrame(o.current), o.current = null), i.current) {
155
+ try {
156
+ i.current.disconnect();
157
+ } catch {
158
+ }
159
+ i.current = null;
160
+ }
161
+ }, []), u = f((s) => (r.current.add(s), () => {
162
+ r.current.delete(s);
163
+ }), []);
164
+ return L(() => () => {
165
+ if (g(), n.current) {
166
+ try {
167
+ n.current.disconnect();
168
+ } catch {
169
+ }
170
+ n.current = null;
171
+ }
172
+ if (t.current) {
173
+ try {
174
+ t.current.close();
175
+ } catch {
176
+ }
177
+ t.current = null;
178
+ }
179
+ r.current.clear(), a.current = null;
180
+ }, [g]), { attach: d, detach: g, subscribe: u };
181
+ }
182
+ function lt() {
183
+ const [t, n] = x(!1), [i, o] = x(null), r = S(null), a = S(null), c = f(async (u) => {
184
+ if (r.current && a.current) {
185
+ try {
186
+ await a.current.localParticipant.unpublishTrack(r.current);
187
+ } catch {
188
+ }
189
+ r.current.stop(), r.current = null;
190
+ }
191
+ a.current = u, o(null);
192
+ try {
193
+ const s = await tt({
194
+ echoCancellation: !0,
195
+ noiseSuppression: !0
196
+ });
197
+ await u.localParticipant.publishTrack(s), r.current = s, n(s.isMuted);
198
+ } catch (s) {
199
+ const l = s instanceof Error && s.name === "NotAllowedError" ? "Enable your microphone to talk with the agent." : "Microphone unavailable. Check browser permissions and try again.";
200
+ throw o(l), s;
201
+ }
202
+ }, []), m = f(() => {
203
+ const u = r.current;
204
+ u && (u.isMuted ? (u.unmute(), n(!1)) : (u.mute(), n(!0)));
205
+ }, []), d = f(() => {
206
+ const u = r.current, s = a.current;
207
+ if (u && s) {
208
+ try {
209
+ s.localParticipant.unpublishTrack(u);
210
+ } catch {
211
+ }
212
+ u.stop();
213
+ }
214
+ r.current = null, a.current = null, n(!1);
215
+ }, []), g = f(() => o(null), []);
216
+ return {
217
+ isMuted: t,
218
+ micError: i,
219
+ toggleMute: m,
220
+ setupMic: c,
221
+ teardownMic: d,
222
+ clearError: g
223
+ };
224
+ }
225
+ const at = { resolution: { width: 640, height: 480, frameRate: 24 } };
226
+ function st() {
227
+ const [t, n] = x(!1), [i, o] = x(null), [r, a] = x(null), [c, m] = x(""), d = S(null), g = S(null), u = f((E) => {
228
+ d.current = E;
229
+ }, []), s = f(() => {
230
+ const E = d.current, R = g.current;
231
+ if (R && E) {
232
+ const T = E.localParticipant.getTrackPublication(Oe.Source.Camera);
233
+ if (T != null && T.track) {
234
+ try {
235
+ E.localParticipant.unpublishTrack(T.track);
236
+ } catch {
237
+ }
238
+ T.track.stop();
239
+ } else
240
+ R.stop();
241
+ }
242
+ g.current = null, a(null), n(!1);
243
+ }, []), l = f(async (E) => {
244
+ const R = d.current;
245
+ if (R) {
246
+ o(null);
247
+ try {
248
+ const T = { ...at };
249
+ E && (T.deviceId = E);
250
+ const z = await nt(T);
251
+ await R.localParticipant.publishTrack(z), g.current = z;
252
+ const I = z.attach();
253
+ a(I), n(!0), E && m(E);
254
+ try {
255
+ R.localParticipant.publishData(
256
+ new TextEncoder().encode(JSON.stringify({ type: "user_camera_on" })),
257
+ { reliable: !0 }
258
+ );
259
+ } catch {
260
+ }
261
+ } catch (T) {
262
+ const z = T instanceof Error && T.name === "NotAllowedError" ? "Enable your camera in the browser to share video." : "Camera unavailable. Check permissions and try again.";
263
+ o(z);
264
+ }
265
+ }
266
+ }, []), b = f(async () => {
267
+ t ? s() : await l(c || void 0);
268
+ }, [t, c, s, l]), _ = f(async (E) => {
269
+ s(), await l(E);
270
+ }, [s, l]), N = f(() => {
271
+ s(), d.current = null, o(null), m("");
272
+ }, [s]), D = f(() => o(null), []);
273
+ return L(() => () => {
274
+ g.current && g.current.stop();
275
+ }, []), {
276
+ isEnabled: t,
277
+ error: i,
278
+ previewEl: r,
279
+ activeDeviceId: c,
280
+ toggle: b,
281
+ switchDevice: _,
282
+ attachRoom: u,
283
+ teardown: N,
284
+ clearError: D
285
+ };
286
+ }
287
+ function ct() {
288
+ const [t, n] = x(!1), [i, o] = x(null), [r, a] = x(null), c = S(null), m = f((l) => {
289
+ c.current = l;
290
+ }, []), d = f(() => a(null), []), g = f(async () => {
291
+ const l = c.current;
292
+ if (l) {
293
+ if (t) {
294
+ try {
295
+ await l.localParticipant.setScreenShareEnabled(!1);
296
+ } catch {
297
+ }
298
+ d(), n(!1);
299
+ return;
300
+ }
301
+ o(null);
302
+ try {
303
+ await l.localParticipant.setScreenShareEnabled(!0);
304
+ let b = 0;
305
+ const _ = () => {
306
+ const N = l.localParticipant.getTrackPublication(Oe.Source.ScreenShare);
307
+ if (N != null && N.track) {
308
+ const D = N.track.attach();
309
+ a(D), n(!0);
310
+ try {
311
+ l.localParticipant.publishData(
312
+ new TextEncoder().encode(JSON.stringify({ type: "user_screen_share_on" })),
313
+ { reliable: !0 }
314
+ );
315
+ } catch {
316
+ }
317
+ return;
318
+ }
319
+ b++ < 10 ? setTimeout(_, 100) : n(!0);
320
+ };
321
+ _();
322
+ } catch (b) {
323
+ const _ = b instanceof Error ? b.name : "";
324
+ _ !== "NotAllowedError" && _ !== "AbortError" && o("Screen share unavailable. Try again."), n(!1);
325
+ }
326
+ }
327
+ }, [t, d]), u = f(() => {
328
+ const l = c.current;
329
+ if (l && t)
330
+ try {
331
+ l.localParticipant.setScreenShareEnabled(!1);
332
+ } catch {
333
+ }
334
+ d(), n(!1), o(null), c.current = null;
335
+ }, [t, d]), s = f(() => o(null), []);
336
+ return { isEnabled: t, error: i, previewEl: r, toggle: g, attachRoom: m, teardown: u, clearError: s };
337
+ }
338
+ function dt() {
339
+ const [t, n] = x([]), [i, o] = x([]), r = f(async () => {
340
+ if (!(typeof navigator > "u" || !navigator.mediaDevices))
341
+ try {
342
+ const a = await navigator.mediaDevices.enumerateDevices();
343
+ n(a.filter((c) => c.kind === "audioinput")), o(a.filter((c) => c.kind === "videoinput"));
344
+ } catch {
345
+ }
346
+ }, []);
347
+ return L(() => {
348
+ if (r(), typeof navigator > "u" || !navigator.mediaDevices) return;
349
+ const a = () => void r();
350
+ return navigator.mediaDevices.addEventListener("devicechange", a), () => navigator.mediaDevices.removeEventListener("devicechange", a);
351
+ }, [r]), { mics: t, cameras: i, refresh: r };
352
+ }
353
+ function ut(t, n, i = !1) {
354
+ const [o, r] = x(null), [a, c] = x(null), [m, d] = x(!i && !!t), g = S("");
355
+ return L(() => {
356
+ if (i || !t) {
357
+ d(!1);
358
+ return;
359
+ }
360
+ const u = `${n || ""}::${t}`;
361
+ if (g.current === u) return;
362
+ g.current = u;
363
+ const s = new AbortController(), l = n || "https://app.livelayer.studio";
364
+ return d(!0), c(null), fetch(`${l}/api/widget/agent/${encodeURIComponent(t)}`, {
365
+ signal: s.signal
366
+ }).then(async (b) => {
367
+ if (!b.ok) {
368
+ const _ = await b.json().catch(() => ({}));
369
+ throw new Error(_.error || `HTTP ${b.status}`);
370
+ }
371
+ return b.json();
372
+ }).then((b) => {
373
+ r(b), d(!1);
374
+ }).catch((b) => {
375
+ s.signal.aborted || (c(b instanceof Error ? b.message : "Agent lookup failed"), d(!1));
376
+ }), () => s.abort();
377
+ }, [t, n, i]), { info: o, error: a, loading: m };
378
+ }
379
+ function ht(t) {
380
+ if (typeof window > "u") return null;
381
+ try {
382
+ return window.localStorage.getItem(t);
383
+ } catch {
384
+ return null;
385
+ }
386
+ }
387
+ function pt(t, n) {
388
+ if (!(typeof window > "u"))
389
+ try {
390
+ window.localStorage.setItem(t, n);
391
+ } catch {
392
+ }
393
+ }
394
+ function mt({
395
+ value: t,
396
+ defaultValue: n = "expanded",
397
+ onChange: i
398
+ } = {}) {
399
+ const o = t !== void 0, [r, a] = x(n), c = o ? t : r, m = f(
400
+ (d) => {
401
+ d !== c && (o || a(d), i == null || i(d));
402
+ },
403
+ [c, o, i]
404
+ );
405
+ return [c, m];
406
+ }
407
+ const ft = ["hidden", "minimized", "expanded"];
408
+ function gt(t) {
409
+ return t && ft.includes(t) ? t : null;
410
+ }
411
+ function vt({
412
+ value: t,
413
+ defaultValue: n = "expanded",
414
+ onChange: i,
415
+ persistKey: o = "ll-widget",
416
+ disablePersistence: r = !1
417
+ } = {}) {
418
+ const a = `${o}:display-mode`, c = S(!1), [m, d] = mt({
419
+ value: t,
420
+ defaultValue: n,
421
+ onChange: (g) => {
422
+ t === void 0 && !r && pt(a, g), i == null || i(g);
423
+ }
424
+ });
425
+ return L(() => {
426
+ if (c.current || (c.current = !0, r || t !== void 0)) return;
427
+ const g = gt(ht(a));
428
+ g && g !== m && d(g);
429
+ }, []), [m, d];
430
+ }
431
+ const yt = 640;
432
+ function _t(t = yt) {
433
+ const [n, i] = x(!1);
434
+ return L(() => {
435
+ if (t === !1) {
436
+ i(!1);
437
+ return;
438
+ }
439
+ if (typeof window > "u" || typeof window.matchMedia > "u")
440
+ return;
441
+ const o = `(max-width: ${t - 1}px)`, r = window.matchMedia(o), a = () => i(r.matches);
442
+ return a(), typeof r.addEventListener == "function" ? (r.addEventListener("change", a), () => r.removeEventListener("change", a)) : (r.addListener(a), () => {
443
+ r.removeListener(a);
444
+ });
445
+ }, [t]), n;
446
+ }
447
+ const Pe = ({ muted: t = !1, className: n }) => t ? /* @__PURE__ */ w(
448
+ "svg",
449
+ {
450
+ className: n,
451
+ fill: "none",
452
+ viewBox: "0 0 24 24",
453
+ stroke: "currentColor",
454
+ strokeWidth: 2,
455
+ "aria-hidden": "true",
456
+ children: [
457
+ /* @__PURE__ */ e(
458
+ "path",
459
+ {
460
+ strokeLinecap: "round",
461
+ strokeLinejoin: "round",
462
+ 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"
463
+ }
464
+ ),
465
+ /* @__PURE__ */ e(
466
+ "path",
467
+ {
468
+ strokeLinecap: "round",
469
+ strokeLinejoin: "round",
470
+ d: "M17 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2"
471
+ }
472
+ )
473
+ ]
474
+ }
475
+ ) : /* @__PURE__ */ e(
476
+ "svg",
477
+ {
478
+ className: n,
479
+ fill: "none",
480
+ viewBox: "0 0 24 24",
481
+ stroke: "currentColor",
482
+ strokeWidth: 2,
483
+ "aria-hidden": "true",
484
+ children: /* @__PURE__ */ e(
485
+ "path",
486
+ {
487
+ strokeLinecap: "round",
488
+ strokeLinejoin: "round",
489
+ 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"
490
+ }
491
+ )
492
+ }
493
+ ), $e = ({ className: t }) => /* @__PURE__ */ e(
494
+ "svg",
495
+ {
496
+ className: t,
497
+ fill: "none",
498
+ viewBox: "0 0 24 24",
499
+ stroke: "currentColor",
500
+ strokeWidth: 2,
501
+ "aria-hidden": "true",
502
+ children: /* @__PURE__ */ e(
503
+ "path",
504
+ {
505
+ strokeLinecap: "round",
506
+ strokeLinejoin: "round",
507
+ d: "M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"
508
+ }
509
+ )
510
+ }
511
+ ), bt = ({ className: t }) => /* @__PURE__ */ e(
512
+ "svg",
513
+ {
514
+ className: t,
515
+ fill: "none",
516
+ viewBox: "0 0 24 24",
517
+ stroke: "currentColor",
518
+ strokeWidth: 2,
519
+ "aria-hidden": "true",
520
+ children: /* @__PURE__ */ e("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M6 18L18 6M6 6l12 12" })
521
+ }
522
+ ), wt = {
523
+ left: 180,
524
+ right: 0,
525
+ up: -90,
526
+ down: 90
527
+ }, kt = ({ direction: t = "right", className: n }) => /* @__PURE__ */ e(
528
+ "svg",
529
+ {
530
+ className: n,
531
+ fill: "none",
532
+ viewBox: "0 0 24 24",
533
+ stroke: "currentColor",
534
+ strokeWidth: 2,
535
+ style: { transform: `rotate(${wt[t]}deg)` },
536
+ "aria-hidden": "true",
537
+ children: /* @__PURE__ */ e("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M9 6l6 6-6 6" })
538
+ }
539
+ );
540
+ function xt(t) {
541
+ return t === "top-left" || t === "bottom-left" ? "left" : "right";
542
+ }
543
+ const We = "ll-hidden-tab-center-y", Ct = 5, Be = 16;
544
+ function Nt() {
545
+ if (typeof window > "u") return null;
546
+ try {
547
+ const t = window.localStorage.getItem(We);
548
+ if (!t) return null;
549
+ const n = Number.parseFloat(t);
550
+ return Number.isFinite(n) ? n : null;
551
+ } catch {
552
+ return null;
553
+ }
554
+ }
555
+ function Ue(t) {
556
+ if (!(typeof window > "u"))
557
+ try {
558
+ window.localStorage.setItem(We, String(t));
559
+ } catch {
560
+ }
561
+ }
562
+ const Et = ({
563
+ position: t,
564
+ isMobile: n,
565
+ isSpeaking: i,
566
+ onExpand: o,
567
+ label: r = "Open widget"
568
+ }) => {
569
+ const a = xt(t), c = a === "right" ? "left" : "right", m = n ? 80 : 72, [d, g] = x(null), [u, s] = x(!1), l = S(null), b = S(!1), _ = f(
570
+ (k) => {
571
+ if (typeof window > "u") return k;
572
+ const C = m / 2, y = Be + C, A = window.innerHeight - Be - C;
573
+ return A < y ? Math.max(y, k) : Math.max(y, Math.min(A, k));
574
+ },
575
+ [m]
576
+ );
577
+ L(() => {
578
+ const k = Nt();
579
+ g(_(k ?? window.innerHeight / 2));
580
+ const C = () => {
581
+ g((y) => y === null ? null : _(y));
582
+ };
583
+ return window.addEventListener("resize", C), () => window.removeEventListener("resize", C);
584
+ }, [_]);
585
+ const N = f(
586
+ (k) => {
587
+ if (!(k.pointerType === "mouse" && k.button !== 0) && d !== null) {
588
+ try {
589
+ k.currentTarget.setPointerCapture(k.pointerId);
590
+ } catch {
591
+ }
592
+ l.current = {
593
+ startClientY: k.clientY,
594
+ startCenterY: d,
595
+ moved: !1
596
+ };
597
+ }
598
+ },
599
+ [d]
600
+ ), D = f(
601
+ (k) => {
602
+ const C = l.current;
603
+ if (!C) return;
604
+ const y = k.clientY - C.startClientY;
605
+ !C.moved && Math.abs(y) > Ct && (C.moved = !0, s(!0)), C.moved && g(_(C.startCenterY + y));
606
+ },
607
+ [_]
608
+ ), E = f(
609
+ (k) => {
610
+ const C = l.current;
611
+ if (C) {
612
+ try {
613
+ k.currentTarget.releasePointerCapture(k.pointerId);
614
+ } catch {
615
+ }
616
+ l.current = null, C.moved && (s(!1), b.current = !0, g((y) => (y !== null && Ue(y), y)));
617
+ }
618
+ },
619
+ []
620
+ ), R = f(() => {
621
+ if (b.current) {
622
+ b.current = !1;
623
+ return;
624
+ }
625
+ o();
626
+ }, [o]), T = f(
627
+ (k) => {
628
+ if (k.key === "ArrowUp" || k.key === "ArrowDown") {
629
+ k.preventDefault();
630
+ const C = k.key === "ArrowUp" ? -8 : 8;
631
+ g((y) => {
632
+ if (y === null) return y;
633
+ const A = _(y + C);
634
+ return Ue(A), A;
635
+ });
636
+ }
637
+ },
638
+ [_]
639
+ ), z = [
640
+ "ll-hidden",
641
+ `ll-hidden--${a}`,
642
+ n ? "ll-hidden--mobile" : "ll-hidden--desktop",
643
+ i ? "ll-hidden--speaking" : null,
644
+ u ? "is-dragging" : null
645
+ ].filter(Boolean).join(" "), I = d === null ? void 0 : { top: `${d - m / 2}px`, transform: "none" };
646
+ return /* @__PURE__ */ e(
647
+ "button",
648
+ {
649
+ type: "button",
650
+ className: z,
651
+ onPointerDown: N,
652
+ onPointerMove: D,
653
+ onPointerUp: E,
654
+ onPointerCancel: E,
655
+ onClick: R,
656
+ onKeyDown: T,
657
+ "aria-label": r,
658
+ "data-position": t,
659
+ style: I,
660
+ children: /* @__PURE__ */ e(kt, { direction: c, className: "ll-hidden__chevron" })
661
+ }
662
+ );
663
+ }, St = ({
664
+ audioLevel: t,
665
+ bars: n = 20,
666
+ maxHeight: i = 20,
667
+ minHeight: o = 4,
668
+ className: r,
669
+ barClassName: a
670
+ }) => {
671
+ const c = S(null), m = S([]), d = Se(() => {
672
+ const u = (Math.sqrt(5) - 1) / 2;
673
+ return Array.from({ length: n }, (s, l) => 0.5 + l * u % 1 * 0.5);
674
+ }, [n]);
675
+ L(() => t.subscribe((s) => {
676
+ for (let l = 0; l < n; l++) {
677
+ const b = m.current[l];
678
+ if (!b) continue;
679
+ const _ = Math.max(o, s * i * d[l]);
680
+ b.style.height = `${_}px`;
681
+ }
682
+ }), [t, n, i, o, d]);
683
+ const g = ["ll-waveform", r].filter(Boolean).join(" ");
684
+ return /* @__PURE__ */ e("div", { ref: c, className: g, "aria-hidden": "true", children: Array.from({ length: n }, (u, s) => /* @__PURE__ */ e(
685
+ "div",
686
+ {
687
+ ref: (l) => {
688
+ m.current[s] = l;
689
+ },
690
+ className: ["ll-waveform__bar", a].filter(Boolean).join(" "),
691
+ style: { height: `${o}px` }
692
+ },
693
+ s
694
+ )) });
695
+ }, Lt = ({
696
+ position: t,
697
+ isMobile: n,
698
+ agentName: i,
699
+ avatarImageUrl: o,
700
+ agentState: r,
701
+ isMuted: a,
702
+ audioLevel: c,
703
+ onExpand: m,
704
+ onToggleMute: d,
705
+ onClose: g
706
+ }) => n ? /* @__PURE__ */ e(
707
+ "div",
708
+ {
709
+ className: "ll-minimized ll-minimized--mobile",
710
+ role: "region",
711
+ "aria-label": `${i} widget`,
712
+ children: /* @__PURE__ */ w(
713
+ "button",
714
+ {
715
+ type: "button",
716
+ className: "ll-minimized__surface",
717
+ onClick: m,
718
+ "aria-label": `Expand ${i} widget`,
719
+ children: [
720
+ o ? (
721
+ // eslint-disable-next-line @next/next/no-img-element
722
+ /* @__PURE__ */ e(
723
+ "img",
724
+ {
725
+ src: o,
726
+ alt: i,
727
+ className: "ll-minimized__avatar"
728
+ }
729
+ )
730
+ ) : /* @__PURE__ */ e("div", { className: "ll-minimized__avatar ll-minimized__avatar--placeholder" }),
731
+ /* @__PURE__ */ e(
732
+ St,
733
+ {
734
+ audioLevel: c,
735
+ bars: 16,
736
+ maxHeight: 18,
737
+ className: "ll-minimized__waveform"
738
+ }
739
+ ),
740
+ /* @__PURE__ */ e("span", { className: "ll-minimized__name", children: i }),
741
+ /* @__PURE__ */ w("div", { className: "ll-minimized__controls", children: [
742
+ /* @__PURE__ */ e(
743
+ "span",
744
+ {
745
+ className: "ll-minimized__btn",
746
+ role: "button",
747
+ tabIndex: 0,
748
+ onClick: (u) => {
749
+ u.stopPropagation(), d();
750
+ },
751
+ onKeyDown: (u) => {
752
+ (u.key === "Enter" || u.key === " ") && (u.stopPropagation(), u.preventDefault(), d());
753
+ },
754
+ "aria-label": a ? "Unmute microphone" : "Mute microphone",
755
+ children: /* @__PURE__ */ e(Pe, { muted: a, className: "ll-minimized__icon" })
756
+ }
757
+ ),
758
+ /* @__PURE__ */ e($e, { className: "ll-minimized__icon ll-minimized__icon--expand" })
759
+ ] })
760
+ ]
761
+ }
762
+ )
763
+ }
764
+ ) : /* @__PURE__ */ e(
765
+ "div",
766
+ {
767
+ className: "ll-minimized ll-minimized--desktop",
768
+ "data-position": t,
769
+ role: "region",
770
+ "aria-label": `${i} widget`,
771
+ children: /* @__PURE__ */ w("div", { className: "ll-minimized__surface", children: [
772
+ o ? (
773
+ // eslint-disable-next-line @next/next/no-img-element
774
+ /* @__PURE__ */ e(
775
+ "img",
776
+ {
777
+ src: o,
778
+ alt: i,
779
+ className: "ll-minimized__avatar"
780
+ }
781
+ )
782
+ ) : /* @__PURE__ */ e("div", { className: "ll-minimized__avatar ll-minimized__avatar--placeholder" }),
783
+ /* @__PURE__ */ w("div", { className: "ll-minimized__meta", children: [
784
+ /* @__PURE__ */ e("span", { className: "ll-minimized__name", children: i }),
785
+ /* @__PURE__ */ e("span", { className: "ll-minimized__state", children: r === "speaking" ? "Speaking" : r === "thinking" ? "Thinking" : "Listening" })
786
+ ] }),
787
+ /* @__PURE__ */ w("div", { className: "ll-minimized__controls", children: [
788
+ /* @__PURE__ */ e(
789
+ "button",
790
+ {
791
+ type: "button",
792
+ className: "ll-minimized__btn",
793
+ onClick: d,
794
+ "aria-label": a ? "Unmute microphone" : "Mute microphone",
795
+ children: /* @__PURE__ */ e(Pe, { muted: a, className: "ll-minimized__icon" })
796
+ }
797
+ ),
798
+ /* @__PURE__ */ e(
799
+ "button",
800
+ {
801
+ type: "button",
802
+ className: "ll-minimized__btn",
803
+ onClick: m,
804
+ "aria-label": `Expand ${i} widget`,
805
+ children: /* @__PURE__ */ e($e, { className: "ll-minimized__icon" })
806
+ }
807
+ ),
808
+ /* @__PURE__ */ e(
809
+ "button",
810
+ {
811
+ type: "button",
812
+ className: "ll-minimized__btn ll-minimized__btn--close",
813
+ onClick: g,
814
+ "aria-label": "Close widget",
815
+ children: /* @__PURE__ */ e(bt, { className: "ll-minimized__icon" })
816
+ }
817
+ )
818
+ ] })
819
+ ] })
820
+ }
821
+ ), Mt = ({
822
+ src: t,
823
+ alt: n,
824
+ preCannedPlaying: i = !1,
825
+ className: o,
826
+ style: r
827
+ }) => {
828
+ const [a, c] = x(!1), m = S(t);
829
+ if (L(() => {
830
+ m.current !== t && (m.current = t, c(!1));
831
+ }, [t]), !t) return null;
832
+ const d = {
833
+ position: "absolute",
834
+ inset: 0,
835
+ width: "100%",
836
+ height: "100%",
837
+ objectFit: "cover",
838
+ objectPosition: "top",
839
+ transition: "opacity 500ms ease, transform 500ms ease",
840
+ transform: i ? "scale(1.02)" : "scale(1)",
841
+ opacity: a ? 1 : 0,
842
+ ...r
843
+ };
844
+ return (
845
+ // eslint-disable-next-line @next/next/no-img-element
846
+ /* @__PURE__ */ e(
847
+ "img",
848
+ {
849
+ src: t,
850
+ alt: n,
851
+ className: o,
852
+ style: d,
853
+ loading: "eager",
854
+ fetchpriority: "high",
855
+ onLoad: () => c(!0)
856
+ }
857
+ )
858
+ );
859
+ }, It = ({
860
+ position: t,
861
+ isMobile: n,
862
+ agentName: i,
863
+ avatarImageUrl: o,
864
+ idleLoopUrl: r,
865
+ greeting: a,
866
+ branding: c,
867
+ teamMembers: m,
868
+ currentTeamMemberId: d,
869
+ isSwitchingTeamMember: g,
870
+ teamSwitcherOpen: u,
871
+ onToggleTeamSwitcher: s,
872
+ onSelectTeamMember: l,
873
+ languageMenuOpen: b,
874
+ onToggleLanguageMenu: _,
875
+ connectionState: N,
876
+ agentState: D,
877
+ transcript: E,
878
+ canResume: R,
879
+ needsUserGesture: T,
880
+ error: z,
881
+ isMuted: I,
882
+ micError: k,
883
+ micDevices: C,
884
+ isCameraEnabled: y,
885
+ cameraPreviewEl: A,
886
+ cameraDevices: X,
887
+ activeCameraId: ne,
888
+ isScreenShareEnabled: U,
889
+ screenPreviewEl: j,
890
+ isSpeakerMuted: F,
891
+ allowCamera: re,
892
+ allowScreenShare: P,
893
+ allowTyping: be,
894
+ avatarVideoContainerRef: we,
895
+ onConnect: ge,
896
+ onDisconnect: de,
897
+ onRetry: ke,
898
+ onResumeAudio: xe,
899
+ onToggleMute: Q,
900
+ onToggleCamera: B,
901
+ onSwitchCameraDevice: ve,
902
+ onToggleScreenShare: Z,
903
+ onToggleSpeaker: G,
904
+ onSendMessage: ee,
905
+ onMinimize: ue,
906
+ onClose: V,
907
+ onClearMicError: K
908
+ }) => {
909
+ var ye;
910
+ const O = E.length > 0 ? E[E.length - 1] : null, Y = ((m == null ? void 0 : m.length) ?? 0) > 1, ie = N === "connecting" || N === "connected", H = N === "connected", he = N === "idle" || N === "disconnected" || N === "error", pe = S(null), oe = S(null);
911
+ L(() => {
912
+ const h = pe.current;
913
+ h && (h.innerHTML = "", A && (A.style.width = "100%", A.style.height = "100%", A.style.objectFit = "cover", A.style.transform = "scaleX(-1)", h.appendChild(A)));
914
+ }, [A]), L(() => {
915
+ const h = oe.current;
916
+ h && (h.innerHTML = "", j && (j.style.width = "100%", j.style.height = "100%", j.style.objectFit = "contain", h.appendChild(j)));
917
+ }, [j]);
918
+ const [q, le] = x(!1), [ae, J] = x(!1);
919
+ L(() => {
920
+ if (!q && !ae && !b && !u) return;
921
+ const h = () => {
922
+ le(!1), J(!1), b && _(), u && s();
923
+ };
924
+ return document.addEventListener("click", h), () => document.removeEventListener("click", h);
925
+ }, [
926
+ q,
927
+ ae,
928
+ b,
929
+ u,
930
+ _,
931
+ s
932
+ ]);
933
+ const [se, ce] = x(""), $ = f(
934
+ (h) => {
935
+ h.preventDefault();
936
+ const W = se.trim();
937
+ W && (ee(W), ce(""));
938
+ },
939
+ [se, ee]
940
+ ), p = c.productName || "Live Layer", me = H && (O != null && O.text) ? O.text : a || "", Ce = [
941
+ "ll-expanded",
942
+ n ? "ll-expanded--mobile" : "ll-expanded--desktop"
943
+ ].join(" ");
944
+ return /* @__PURE__ */ w(
945
+ "div",
946
+ {
947
+ className: Ce,
948
+ "data-position": t,
949
+ "data-state": H ? "connected" : ie ? "connecting" : "idle",
950
+ role: "dialog",
951
+ "aria-label": `${i} widget`,
952
+ children: [
953
+ /* @__PURE__ */ w("div", { className: "ll-expanded__bg", children: [
954
+ o ? /* @__PURE__ */ e(
955
+ Mt,
956
+ {
957
+ src: o,
958
+ alt: i,
959
+ className: "ll-expanded__bg-img"
960
+ }
961
+ ) : /* @__PURE__ */ e("div", { className: "ll-expanded__bg-fallback", children: /* @__PURE__ */ e("span", { className: "ll-expanded__bg-initial", children: ((ye = i == null ? void 0 : i.charAt(0)) == null ? void 0 : ye.toUpperCase()) || "A" }) }),
962
+ r && !H && /* @__PURE__ */ e(
963
+ "video",
964
+ {
965
+ className: "ll-expanded__bg-idle",
966
+ src: r,
967
+ autoPlay: !0,
968
+ loop: !0,
969
+ muted: !0,
970
+ playsInline: !0
971
+ }
972
+ )
973
+ ] }),
974
+ /* @__PURE__ */ e("div", { ref: we, className: "ll-expanded__video" }),
975
+ N === "connecting" && /* @__PURE__ */ w("div", { className: "ll-expanded__overlay ll-expanded__overlay--connecting", children: [
976
+ /* @__PURE__ */ e("div", { className: "ll-expanded__spinner" }),
977
+ /* @__PURE__ */ e("p", { className: "ll-expanded__overlay-text", children: g ? "Switching..." : "Connecting..." })
978
+ ] }),
979
+ T && H && /* @__PURE__ */ w(
980
+ "button",
981
+ {
982
+ type: "button",
983
+ className: "ll-expanded__overlay ll-expanded__overlay--gesture",
984
+ onClick: xe,
985
+ children: [
986
+ /* @__PURE__ */ e("svg", { width: "32", height: "32", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": !0, children: /* @__PURE__ */ e("path", { d: "M3 9v6h4l5 5V4L7 9H3zm13.54.12a5 5 0 0 1 0 5.76l-1.41-1.41a3 3 0 0 0 0-2.94L16.54 9.12z" }) }),
987
+ /* @__PURE__ */ e("p", { className: "ll-expanded__overlay-text", children: "Tap to enable audio" })
988
+ ]
989
+ }
990
+ ),
991
+ ie ? /* @__PURE__ */ w("div", { className: "ll-expanded__topbar", children: [
992
+ /* @__PURE__ */ w("div", { className: "ll-expanded__topbar-left", children: [
993
+ /* @__PURE__ */ w("div", { className: "ll-expanded__pill-wrap", children: [
994
+ /* @__PURE__ */ w(
995
+ "button",
996
+ {
997
+ type: "button",
998
+ className: "ll-hpill",
999
+ onClick: (h) => {
1000
+ Y && (h.stopPropagation(), s());
1001
+ },
1002
+ "aria-haspopup": Y ? "listbox" : void 0,
1003
+ "aria-expanded": Y ? u : void 0,
1004
+ children: [
1005
+ /* @__PURE__ */ e("span", { className: "ll-hpill__label", children: i }),
1006
+ Y && /* @__PURE__ */ e(_e, {})
1007
+ ]
1008
+ }
1009
+ ),
1010
+ Y && u && /* @__PURE__ */ e(
1011
+ "div",
1012
+ {
1013
+ className: "ll-hmenu",
1014
+ onClick: (h) => h.stopPropagation(),
1015
+ role: "listbox",
1016
+ children: m == null ? void 0 : m.map((h) => /* @__PURE__ */ w(
1017
+ "button",
1018
+ {
1019
+ type: "button",
1020
+ className: `ll-hmenu__item ${h.id === d ? "is-active" : ""}`,
1021
+ onClick: () => l(h.id),
1022
+ role: "option",
1023
+ "aria-selected": h.id === d,
1024
+ children: [
1025
+ h.avatarImageUrl && /* @__PURE__ */ e(
1026
+ "img",
1027
+ {
1028
+ src: h.avatarImageUrl,
1029
+ alt: "",
1030
+ className: "ll-hmenu__avatar"
1031
+ }
1032
+ ),
1033
+ /* @__PURE__ */ e("span", { className: "ll-hmenu__name", children: h.name }),
1034
+ h.role && /* @__PURE__ */ e("span", { className: "ll-hmenu__role", children: h.role })
1035
+ ]
1036
+ },
1037
+ h.id
1038
+ ))
1039
+ }
1040
+ )
1041
+ ] }),
1042
+ /* @__PURE__ */ w("div", { className: "ll-expanded__pill-wrap", children: [
1043
+ /* @__PURE__ */ w(
1044
+ "button",
1045
+ {
1046
+ type: "button",
1047
+ className: "ll-hpill",
1048
+ onClick: (h) => {
1049
+ h.stopPropagation(), _();
1050
+ },
1051
+ "aria-haspopup": "listbox",
1052
+ "aria-expanded": b,
1053
+ children: [
1054
+ /* @__PURE__ */ e("span", { className: "ll-hpill__label", children: "English" }),
1055
+ /* @__PURE__ */ e(_e, {})
1056
+ ]
1057
+ }
1058
+ ),
1059
+ b && /* @__PURE__ */ e(
1060
+ "div",
1061
+ {
1062
+ className: "ll-hmenu",
1063
+ onClick: (h) => h.stopPropagation(),
1064
+ role: "listbox",
1065
+ children: /* @__PURE__ */ e(
1066
+ "button",
1067
+ {
1068
+ type: "button",
1069
+ className: "ll-hmenu__item is-active",
1070
+ role: "option",
1071
+ "aria-selected": !0,
1072
+ children: /* @__PURE__ */ e("span", { className: "ll-hmenu__name", children: "English" })
1073
+ }
1074
+ )
1075
+ }
1076
+ )
1077
+ ] }),
1078
+ /* @__PURE__ */ e(
1079
+ "span",
1080
+ {
1081
+ className: `ll-expanded__state ll-expanded__state--${D}`,
1082
+ children: D
1083
+ }
1084
+ )
1085
+ ] }),
1086
+ /* @__PURE__ */ e(
1087
+ "button",
1088
+ {
1089
+ type: "button",
1090
+ className: "ll-hbtn",
1091
+ onClick: V,
1092
+ "aria-label": "Close widget",
1093
+ title: "Close",
1094
+ children: /* @__PURE__ */ e(je, {})
1095
+ }
1096
+ )
1097
+ ] }) : (
1098
+ // Idle-state header with Live Layer product name + minimize/close
1099
+ /* @__PURE__ */ w("div", { className: "ll-expanded__header ll-expanded__header--idle", children: [
1100
+ /* @__PURE__ */ e("span", { className: "ll-expanded__brand", children: p }),
1101
+ /* @__PURE__ */ w("div", { className: "ll-expanded__header-actions", children: [
1102
+ /* @__PURE__ */ e(
1103
+ "button",
1104
+ {
1105
+ type: "button",
1106
+ className: "ll-hbtn ll-hbtn--ghost",
1107
+ onClick: ue,
1108
+ "aria-label": "Minimize widget",
1109
+ children: /* @__PURE__ */ e(At, {})
1110
+ }
1111
+ ),
1112
+ /* @__PURE__ */ e(
1113
+ "button",
1114
+ {
1115
+ type: "button",
1116
+ className: "ll-hbtn ll-hbtn--ghost",
1117
+ onClick: V,
1118
+ "aria-label": "Close widget",
1119
+ children: /* @__PURE__ */ e(je, {})
1120
+ }
1121
+ )
1122
+ ] })
1123
+ ] })
1124
+ ),
1125
+ he && /* @__PURE__ */ w(
1126
+ "button",
1127
+ {
1128
+ type: "button",
1129
+ className: "ll-expanded__play",
1130
+ onClick: ge,
1131
+ "aria-label": R ? "Resume session" : "Start video call",
1132
+ children: [
1133
+ /* @__PURE__ */ e("div", { className: "ll-expanded__play-circle", children: /* @__PURE__ */ e("svg", { width: "22", height: "22", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": !0, children: /* @__PURE__ */ e("polygon", { points: "6 3 20 12 6 21 6 3" }) }) }),
1134
+ /* @__PURE__ */ e("span", { className: "ll-expanded__play-label", children: R ? "Restart session" : "Start video call" }),
1135
+ R && /* @__PURE__ */ e("span", { className: "ll-expanded__play-sublabel", children: "Pick up where you left off" })
1136
+ ]
1137
+ }
1138
+ ),
1139
+ /* @__PURE__ */ w(
1140
+ "div",
1141
+ {
1142
+ className: `ll-expanded__pip ${ie && (y || U) ? "is-visible" : ""}`,
1143
+ children: [
1144
+ /* @__PURE__ */ e(
1145
+ "div",
1146
+ {
1147
+ ref: oe,
1148
+ className: U ? "ll-expanded__pip-host" : "ll-expanded__pip-host is-hidden"
1149
+ }
1150
+ ),
1151
+ /* @__PURE__ */ e(
1152
+ "div",
1153
+ {
1154
+ ref: pe,
1155
+ className: !U && y ? "ll-expanded__pip-host" : "ll-expanded__pip-host is-hidden"
1156
+ }
1157
+ )
1158
+ ]
1159
+ }
1160
+ ),
1161
+ ie ? /* @__PURE__ */ w("div", { className: "ll-expanded__bottom", children: [
1162
+ me && /* @__PURE__ */ e("div", { className: "ll-expanded__transcript", children: /* @__PURE__ */ e("p", { className: "ll-expanded__transcript-text", children: me }) }),
1163
+ /* @__PURE__ */ w("div", { className: "ll-toolbar", onClick: (h) => h.stopPropagation(), children: [
1164
+ P && /* @__PURE__ */ e(
1165
+ "button",
1166
+ {
1167
+ type: "button",
1168
+ className: `ll-tool ${U ? "is-on" : ""}`,
1169
+ onClick: Z,
1170
+ "aria-label": U ? "Stop sharing screen" : "Share screen",
1171
+ title: U ? "Stop sharing" : "Share screen",
1172
+ children: /* @__PURE__ */ e(Dt, {})
1173
+ }
1174
+ ),
1175
+ re && /* @__PURE__ */ w("div", { className: "ll-tool-split", children: [
1176
+ /* @__PURE__ */ e(
1177
+ "button",
1178
+ {
1179
+ type: "button",
1180
+ className: `ll-tool ll-tool--left ${y ? "is-on" : ""}`,
1181
+ onClick: B,
1182
+ "aria-label": y ? "Turn off camera" : "Turn on camera",
1183
+ title: y ? "Stop camera" : "Start camera",
1184
+ children: /* @__PURE__ */ e(Rt, {})
1185
+ }
1186
+ ),
1187
+ /* @__PURE__ */ e(
1188
+ "button",
1189
+ {
1190
+ type: "button",
1191
+ className: `ll-tool ll-tool--right ${y ? "is-on" : ""}`,
1192
+ onClick: (h) => {
1193
+ h.stopPropagation(), J((W) => !W), le(!1);
1194
+ },
1195
+ "aria-label": "Camera devices",
1196
+ "aria-haspopup": "listbox",
1197
+ "aria-expanded": ae,
1198
+ children: /* @__PURE__ */ e(_e, {})
1199
+ }
1200
+ ),
1201
+ ae && X.length > 0 && /* @__PURE__ */ e(
1202
+ Ve,
1203
+ {
1204
+ label: "Camera",
1205
+ devices: X,
1206
+ activeId: ne,
1207
+ onPick: (h) => {
1208
+ J(!1), ve(h);
1209
+ }
1210
+ }
1211
+ )
1212
+ ] }),
1213
+ /* @__PURE__ */ w("div", { className: "ll-tool-split", children: [
1214
+ /* @__PURE__ */ e(
1215
+ "button",
1216
+ {
1217
+ type: "button",
1218
+ className: `ll-tool ll-tool--left ${I ? "is-muted" : ""}`,
1219
+ onClick: Q,
1220
+ "aria-label": I ? "Unmute microphone" : "Mute microphone",
1221
+ title: I ? "Unmute" : "Mute",
1222
+ children: /* @__PURE__ */ e(Tt, { muted: I })
1223
+ }
1224
+ ),
1225
+ /* @__PURE__ */ e(
1226
+ "button",
1227
+ {
1228
+ type: "button",
1229
+ className: `ll-tool ll-tool--right ${I ? "is-muted" : ""}`,
1230
+ onClick: (h) => {
1231
+ h.stopPropagation(), le((W) => !W), J(!1);
1232
+ },
1233
+ "aria-label": "Microphone devices",
1234
+ "aria-haspopup": "listbox",
1235
+ "aria-expanded": q,
1236
+ children: /* @__PURE__ */ e(_e, {})
1237
+ }
1238
+ ),
1239
+ q && C.length > 0 && /* @__PURE__ */ e(
1240
+ Ve,
1241
+ {
1242
+ label: "Microphone",
1243
+ devices: C,
1244
+ activeId: "",
1245
+ onPick: () => le(!1)
1246
+ }
1247
+ )
1248
+ ] }),
1249
+ /* @__PURE__ */ e(
1250
+ "button",
1251
+ {
1252
+ type: "button",
1253
+ className: `ll-tool ${F ? "is-muted" : ""}`,
1254
+ onClick: G,
1255
+ "aria-label": F ? "Unmute speaker" : "Mute speaker",
1256
+ title: F ? "Unmute speaker" : "Mute speaker",
1257
+ children: /* @__PURE__ */ e(zt, { muted: F })
1258
+ }
1259
+ )
1260
+ ] }),
1261
+ be && /* @__PURE__ */ w("form", { className: "ll-message-input", onSubmit: $, children: [
1262
+ /* @__PURE__ */ e(
1263
+ "input",
1264
+ {
1265
+ type: "text",
1266
+ className: "ll-message-input__field",
1267
+ placeholder: "Message...",
1268
+ value: se,
1269
+ onChange: (h) => ce(h.target.value),
1270
+ "aria-label": "Message the agent"
1271
+ }
1272
+ ),
1273
+ se.trim() && /* @__PURE__ */ e(
1274
+ "button",
1275
+ {
1276
+ type: "submit",
1277
+ className: "ll-message-input__send",
1278
+ "aria-label": "Send message",
1279
+ children: /* @__PURE__ */ e(Pt, {})
1280
+ }
1281
+ )
1282
+ ] }),
1283
+ /* @__PURE__ */ e(
1284
+ "button",
1285
+ {
1286
+ type: "button",
1287
+ className: "ll-expanded__end",
1288
+ onClick: de,
1289
+ children: "End conversation"
1290
+ }
1291
+ )
1292
+ ] }) : (
1293
+ // Idle-state footer: start button + greeting
1294
+ a && /* @__PURE__ */ e("div", { className: "ll-expanded__bottom ll-expanded__bottom--idle", children: /* @__PURE__ */ e("div", { className: "ll-expanded__transcript", children: /* @__PURE__ */ e("p", { className: "ll-expanded__transcript-text", children: a }) }) })
1295
+ ),
1296
+ (() => {
1297
+ if (k && N !== "error")
1298
+ return /* @__PURE__ */ w("div", { className: "ll-expanded__banner", role: "alert", children: [
1299
+ /* @__PURE__ */ e("span", { children: k }),
1300
+ /* @__PURE__ */ e(
1301
+ "button",
1302
+ {
1303
+ type: "button",
1304
+ className: "ll-expanded__banner-x",
1305
+ onClick: K,
1306
+ "aria-label": "Dismiss",
1307
+ children: "×"
1308
+ }
1309
+ )
1310
+ ] });
1311
+ if (!z || N !== "error") return null;
1312
+ let h = "Failed to connect", W = "Try again";
1313
+ return z === "MIC_PERMISSION_DENIED" ? h = "Microphone blocked. Allow access to talk." : z === "MIC_NOT_FOUND" ? h = "No microphone found. Plug one in + retry." : z === "MIC_UNAVAILABLE" ? h = "Mic unavailable. Check other apps using it." : z === "AGENT_TIMEOUT" ? h = "Agent didn't pick up. Try again." : z === "CONNECT_FAILED" ? h = "Connection failed. Check your network." : z.length < 80 && (h = z), /* @__PURE__ */ w("div", { className: "ll-expanded__banner ll-expanded__banner--error", role: "alert", children: [
1314
+ /* @__PURE__ */ e("span", { children: h }),
1315
+ /* @__PURE__ */ e(
1316
+ "button",
1317
+ {
1318
+ type: "button",
1319
+ className: "ll-expanded__banner-retry",
1320
+ onClick: ke,
1321
+ children: W
1322
+ }
1323
+ )
1324
+ ] });
1325
+ })()
1326
+ ]
1327
+ }
1328
+ );
1329
+ };
1330
+ function _e() {
1331
+ return /* @__PURE__ */ e("svg", { width: "12", height: "12", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", "aria-hidden": !0, children: /* @__PURE__ */ e("polyline", { points: "6 9 12 15 18 9" }) });
1332
+ }
1333
+ function je() {
1334
+ return /* @__PURE__ */ w("svg", { width: "12", height: "12", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.5", strokeLinecap: "round", "aria-hidden": !0, children: [
1335
+ /* @__PURE__ */ e("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
1336
+ /* @__PURE__ */ e("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
1337
+ ] });
1338
+ }
1339
+ function At() {
1340
+ return /* @__PURE__ */ e("svg", { width: "12", height: "12", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.5", strokeLinecap: "round", "aria-hidden": !0, children: /* @__PURE__ */ e("line", { x1: "5", y1: "12", x2: "19", y2: "12" }) });
1341
+ }
1342
+ function Dt() {
1343
+ return /* @__PURE__ */ w("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": !0, children: [
1344
+ /* @__PURE__ */ e("rect", { x: "2", y: "3", width: "20", height: "14", rx: "2" }),
1345
+ /* @__PURE__ */ e("line", { x1: "8", y1: "21", x2: "16", y2: "21" }),
1346
+ /* @__PURE__ */ e("line", { x1: "12", y1: "17", x2: "12", y2: "21" })
1347
+ ] });
1348
+ }
1349
+ function Rt() {
1350
+ return /* @__PURE__ */ w("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": !0, children: [
1351
+ /* @__PURE__ */ e("path", { d: "M23 7l-7 5 7 5V7z" }),
1352
+ /* @__PURE__ */ e("rect", { x: "1", y: "5", width: "15", height: "14", rx: "2" })
1353
+ ] });
1354
+ }
1355
+ function Tt({ muted: t }) {
1356
+ return /* @__PURE__ */ w("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": !0, children: [
1357
+ /* @__PURE__ */ e("path", { d: "M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z" }),
1358
+ /* @__PURE__ */ e("path", { d: "M19 10v2a7 7 0 0 1-14 0v-2" }),
1359
+ /* @__PURE__ */ e("line", { x1: "12", y1: "19", x2: "12", y2: "23" }),
1360
+ t && /* @__PURE__ */ e("line", { x1: "1", y1: "1", x2: "23", y2: "23" })
1361
+ ] });
1362
+ }
1363
+ function zt({ muted: t }) {
1364
+ return /* @__PURE__ */ w("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": !0, children: [
1365
+ /* @__PURE__ */ e("polygon", { points: "11 5 6 9 2 9 2 15 6 15 11 19 11 5" }),
1366
+ t ? /* @__PURE__ */ e("line", { x1: "23", y1: "9", x2: "17", y2: "15" }) : /* @__PURE__ */ w(Qe, { children: [
1367
+ /* @__PURE__ */ e("path", { d: "M19.07 4.93a10 10 0 0 1 0 14.14" }),
1368
+ /* @__PURE__ */ e("path", { d: "M15.54 8.46a5 5 0 0 1 0 7.07" })
1369
+ ] })
1370
+ ] });
1371
+ }
1372
+ function Pt() {
1373
+ return /* @__PURE__ */ w("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": !0, children: [
1374
+ /* @__PURE__ */ e("line", { x1: "5", y1: "12", x2: "19", y2: "12" }),
1375
+ /* @__PURE__ */ e("polyline", { points: "12 5 19 12 12 19" })
1376
+ ] });
1377
+ }
1378
+ const Ve = ({ label: t, devices: n, activeId: i, onPick: o }) => /* @__PURE__ */ w(
1379
+ "div",
1380
+ {
1381
+ className: "ll-device-menu",
1382
+ onClick: (r) => r.stopPropagation(),
1383
+ role: "listbox",
1384
+ children: [
1385
+ /* @__PURE__ */ e("p", { className: "ll-device-menu__label", children: t }),
1386
+ n.map((r, a) => {
1387
+ const c = i === r.deviceId;
1388
+ return /* @__PURE__ */ w(
1389
+ "button",
1390
+ {
1391
+ type: "button",
1392
+ className: `ll-device-menu__item ${c ? "is-active" : ""}`,
1393
+ onClick: () => o(r.deviceId),
1394
+ role: "option",
1395
+ "aria-selected": c,
1396
+ children: [
1397
+ c && /* @__PURE__ */ e("span", { className: "ll-device-menu__dot", children: "●" }),
1398
+ /* @__PURE__ */ e("span", { className: "ll-device-menu__name", children: r.label || `${t} ${a + 1}` })
1399
+ ]
1400
+ },
1401
+ r.deviceId || a
1402
+ );
1403
+ })
1404
+ ]
1405
+ }
1406
+ ), $t = /* @__PURE__ */ new Set([
1407
+ "agent_state",
1408
+ "avatar_stream_ready",
1409
+ "avatar_active",
1410
+ "avatar_idle",
1411
+ "bot_ready",
1412
+ "agent_error",
1413
+ "idle_warning",
1414
+ "idle_timeout"
1415
+ ]);
1416
+ function Bt(t) {
1417
+ var Ie, Ae, De, Re, Te, ze;
1418
+ const {
1419
+ agentId: n,
1420
+ apiKey: i,
1421
+ baseUrl: o = "https://app.livelayer.studio",
1422
+ sessionEndpoint: r,
1423
+ sessionBody: a,
1424
+ autoConnect: c = !1,
1425
+ displayMode: m,
1426
+ defaultDisplayMode: d = "expanded",
1427
+ onDisplayModeChange: g,
1428
+ position: u = "bottom-right",
1429
+ mobileBreakpoint: s = 640,
1430
+ persistKey: l = "ll-widget",
1431
+ disablePersistence: b = !1,
1432
+ teamMembers: _,
1433
+ currentTeamMemberId: N,
1434
+ onTeamMemberChange: D,
1435
+ idleLoopUrl: E,
1436
+ greeting: R,
1437
+ avatarImageUrl: T,
1438
+ agentName: z,
1439
+ branding: I = {},
1440
+ allowCamera: k = !0,
1441
+ allowScreenShare: C = !0,
1442
+ allowTyping: y = !0,
1443
+ onConnect: A,
1444
+ onDisconnect: X,
1445
+ onTranscript: ne,
1446
+ onAgentState: U,
1447
+ onConnectionStateChange: j,
1448
+ onAgentEvent: F,
1449
+ onAgentCommand: re,
1450
+ controlledSession: P,
1451
+ className: be,
1452
+ style: we,
1453
+ zIndex: ge = 2147483647
1454
+ } = t, de = N !== void 0, [ke, xe] = x(() => {
1455
+ var v;
1456
+ return N ?? ((v = _ == null ? void 0 : _[0]) == null ? void 0 : v.id);
1457
+ }), Q = de ? N : ke, B = Se(
1458
+ () => (_ == null ? void 0 : _.find((v) => v.id === Q)) ?? null,
1459
+ [_, Q]
1460
+ ), ve = (B == null ? void 0 : B.agentId) ?? n, [Z, G] = vt({
1461
+ value: m,
1462
+ defaultValue: d,
1463
+ onChange: g,
1464
+ persistKey: l,
1465
+ disablePersistence: b
1466
+ }), ee = _t(s), ue = ot(), V = lt(), K = st(), O = ct(), Y = dt(), [ie, H] = x(!1), [he, pe] = x(!1), [oe, q] = x(!1), [le, ae] = x(!1), [J, se] = x(!1), ce = f(
1467
+ (v) => {
1468
+ const M = v;
1469
+ !M.type || typeof M.type != "string" || (F == null || F({ eventName: M.type, data: v }), $t.has(M.type) || re == null || re(M));
1470
+ },
1471
+ [re, F]
1472
+ ), $ = it({
1473
+ agentId: P ? "__controlled__" : ve,
1474
+ baseUrl: o,
1475
+ apiKey: i,
1476
+ sessionEndpoint: r,
1477
+ sessionBody: a,
1478
+ onDataMessage: P ? void 0 : ce
1479
+ });
1480
+ L(() => {
1481
+ if (P != null && P.subscribeToDataMessages)
1482
+ return P.subscribeToDataMessages(ce);
1483
+ }, [P, ce]);
1484
+ const p = Se(() => P ? {
1485
+ connectionState: P.connectionState,
1486
+ agentState: P.agentState,
1487
+ transcript: P.transcript,
1488
+ videoElement: P.videoElement,
1489
+ audioElement: P.audioElement,
1490
+ canResume: P.canResume,
1491
+ error: P.error,
1492
+ agentConfig: null,
1493
+ connect: async () => {
1494
+ await P.onConnect();
1495
+ },
1496
+ disconnect: () => P.onDisconnect(),
1497
+ // Dummy getRoom for shape compatibility — controlled consumers own the Room.
1498
+ // Internal session's getRoom returns null when no real connect has happened,
1499
+ // so we reuse its reference for type consistency.
1500
+ getRoom: $.getRoom,
1501
+ isControlled: !0
1502
+ } : {
1503
+ connectionState: $.connectionState,
1504
+ agentState: $.agentState,
1505
+ transcript: $.transcript,
1506
+ videoElement: $.videoElement,
1507
+ audioElement: $.audioElement,
1508
+ canResume: $.canResume,
1509
+ error: $.error,
1510
+ agentConfig: $.agentConfig,
1511
+ connect: $.connect,
1512
+ disconnect: $.disconnect,
1513
+ getRoom: $.getRoom,
1514
+ isControlled: !1
1515
+ }, [P, $]), me = S(null);
1516
+ L(() => {
1517
+ const v = p.videoElement, M = me.current;
1518
+ if (!(!v || !M))
1519
+ return M.appendChild(v), () => {
1520
+ v.parentNode === M && M.removeChild(v);
1521
+ };
1522
+ }, [p.videoElement]), L(() => {
1523
+ const v = p.audioElement;
1524
+ if (!v) return;
1525
+ ue.attach(v);
1526
+ const M = v.play();
1527
+ return M && typeof M.catch == "function" && M.catch((te) => {
1528
+ (te == null ? void 0 : te.name) === "NotAllowedError" && H(!0);
1529
+ }), () => {
1530
+ ue.detach();
1531
+ };
1532
+ }, [p.audioElement]), L(() => {
1533
+ if (p.isControlled || p.connectionState !== "connected") return;
1534
+ const v = p.getRoom();
1535
+ if (v)
1536
+ return V.setupMic(v).catch(() => {
1537
+ }), K.attachRoom(v), O.attachRoom(v), Y.refresh(), () => {
1538
+ V.teardownMic(), K.teardown(), O.teardown();
1539
+ };
1540
+ }, [p.isControlled, p.connectionState]), L(() => {
1541
+ const v = p.audioElement;
1542
+ v && (v.muted = J);
1543
+ }, [p.audioElement, J]);
1544
+ const Ce = f((v) => {
1545
+ const M = p.getRoom();
1546
+ if (M)
1547
+ try {
1548
+ const te = new TextEncoder().encode(
1549
+ JSON.stringify({ type: "user_message", text: v })
1550
+ );
1551
+ M.localParticipant.publishData(te, { reliable: !0 });
1552
+ } catch {
1553
+ }
1554
+ }, [p]), ye = f(() => {
1555
+ se((v) => !v);
1556
+ }, []);
1557
+ L(() => {
1558
+ j == null || j(p.connectionState), p.connectionState === "connected" ? A == null || A() : p.connectionState === "disconnected" && (X == null || X());
1559
+ }, [p.connectionState, A, X, j]), L(() => {
1560
+ ne == null || ne(p.transcript);
1561
+ }, [p.transcript, ne]), L(() => {
1562
+ U == null || U(p.agentState);
1563
+ }, [p.agentState, U]);
1564
+ const h = S(!1);
1565
+ L(() => {
1566
+ p.isControlled || !c || h.current || p.connectionState === "idle" && (h.current = !0, p.connect());
1567
+ }, [c, p.connectionState, p]);
1568
+ const W = f(
1569
+ (v) => {
1570
+ const M = _ == null ? void 0 : _.find((te) => te.id === v);
1571
+ M && (q(!1), v !== Q && (pe(!0), p.disconnect(), de || xe(v), D == null || D(M)));
1572
+ },
1573
+ [
1574
+ _,
1575
+ Q,
1576
+ p,
1577
+ de,
1578
+ D
1579
+ ]
1580
+ );
1581
+ L(() => {
1582
+ he && p.connectionState === "connected" && pe(!1);
1583
+ }, [p.connectionState, he]), L(() => {
1584
+ if (!oe) return;
1585
+ const v = (M) => {
1586
+ M.key === "Escape" && q(!1);
1587
+ };
1588
+ return window.addEventListener("keydown", v), () => window.removeEventListener("keydown", v);
1589
+ }, [oe]);
1590
+ const Fe = !!T || !!(B != null && B.avatarImageUrl) || p.isControlled, Ne = ut(ve, o, Fe), Ee = (B == null ? void 0 : B.name) ?? z ?? ((Ie = p.agentConfig) == null ? void 0 : Ie.name) ?? ((Ae = Ne.info) == null ? void 0 : Ae.name) ?? "Live Layer", Le = (B == null ? void 0 : B.avatarImageUrl) ?? T ?? ((De = p.agentConfig) == null ? void 0 : De.avatarImageUrl) ?? ((Re = Ne.info) == null ? void 0 : Re.avatarImageUrl) ?? null, Ge = E ?? ((Te = p.agentConfig) == null ? void 0 : Te.idleLoopUrl) ?? ((ze = Ne.info) == null ? void 0 : ze.idleLoopUrl) ?? null, Ke = R ?? null, Ye = f(() => G("expanded"), [G]), He = f(
1591
+ () => G("minimized"),
1592
+ [G]
1593
+ ), Me = f(() => G("hidden"), [G]), qe = f(() => {
1594
+ const v = p.audioElement;
1595
+ v && v.play().then(() => H(!1)).catch(() => {
1596
+ });
1597
+ }, [p.audioElement]), Je = f(() => {
1598
+ H(!1), p.connect();
1599
+ }, [p]), fe = {
1600
+ ...we,
1601
+ zIndex: ge
1602
+ };
1603
+ I.primaryColor && (fe["--ll-color-primary"] = I.primaryColor), I.accentColor && (fe["--ll-color-accent"] = I.accentColor), I.backgroundColor && (fe["--ll-color-bg"] = I.backgroundColor), I.textColor && (fe["--ll-color-fg"] = I.textColor);
1604
+ const Xe = [
1605
+ "ll-widget",
1606
+ `ll-widget--${Z}`,
1607
+ `ll-widget--${ee ? "mobile" : "desktop"}`,
1608
+ be
1609
+ ].filter(Boolean).join(" ");
1610
+ return /* @__PURE__ */ w(
1611
+ "div",
1612
+ {
1613
+ className: Xe,
1614
+ style: fe,
1615
+ "data-display-mode": Z,
1616
+ "data-position": u,
1617
+ children: [
1618
+ Z === "hidden" && /* @__PURE__ */ e(
1619
+ Et,
1620
+ {
1621
+ position: u,
1622
+ isMobile: ee,
1623
+ isSpeaking: p.agentState === "speaking",
1624
+ onExpand: () => G("expanded"),
1625
+ label: `Open ${Ee} widget`
1626
+ }
1627
+ ),
1628
+ Z === "minimized" && /* @__PURE__ */ e(
1629
+ Lt,
1630
+ {
1631
+ position: u,
1632
+ isMobile: ee,
1633
+ agentName: Ee,
1634
+ avatarImageUrl: Le,
1635
+ agentState: p.agentState,
1636
+ isMuted: V.isMuted,
1637
+ audioLevel: ue,
1638
+ onExpand: Ye,
1639
+ onToggleMute: V.toggleMute,
1640
+ onClose: Me
1641
+ }
1642
+ ),
1643
+ Z === "expanded" && /* @__PURE__ */ e(
1644
+ It,
1645
+ {
1646
+ position: u,
1647
+ isMobile: ee,
1648
+ agentName: Ee,
1649
+ avatarImageUrl: Le,
1650
+ idleLoopUrl: Ge,
1651
+ greeting: Ke,
1652
+ branding: I,
1653
+ teamMembers: _,
1654
+ currentTeamMemberId: Q,
1655
+ isSwitchingTeamMember: he,
1656
+ teamSwitcherOpen: oe,
1657
+ onToggleTeamSwitcher: () => q((v) => !v),
1658
+ onSelectTeamMember: W,
1659
+ connectionState: p.connectionState,
1660
+ agentState: p.agentState,
1661
+ transcript: p.transcript,
1662
+ isMuted: V.isMuted,
1663
+ micDevices: Y.mics,
1664
+ isCameraEnabled: K.isEnabled,
1665
+ cameraPreviewEl: K.previewEl,
1666
+ cameraDevices: Y.cameras,
1667
+ activeCameraId: K.activeDeviceId,
1668
+ isScreenShareEnabled: O.isEnabled,
1669
+ screenPreviewEl: O.previewEl,
1670
+ isSpeakerMuted: J,
1671
+ allowCamera: k,
1672
+ allowScreenShare: C,
1673
+ allowTyping: y,
1674
+ languageMenuOpen: le,
1675
+ onToggleLanguageMenu: () => ae((v) => !v),
1676
+ needsUserGesture: ie,
1677
+ canResume: p.canResume,
1678
+ micError: V.micError,
1679
+ error: p.error,
1680
+ avatarVideoContainerRef: me,
1681
+ onConnect: () => void p.connect(),
1682
+ onDisconnect: () => p.disconnect(),
1683
+ onRetry: Je,
1684
+ onResumeAudio: qe,
1685
+ onToggleMute: V.toggleMute,
1686
+ onToggleCamera: () => void K.toggle(),
1687
+ onSwitchCameraDevice: (v) => void K.switchDevice(v),
1688
+ onToggleScreenShare: () => void O.toggle(),
1689
+ onToggleSpeaker: ye,
1690
+ onSendMessage: Ce,
1691
+ onMinimize: He,
1692
+ onClose: Me,
1693
+ onClearMicError: V.clearError
1694
+ }
1695
+ )
1696
+ ]
1697
+ }
1698
+ );
1699
+ }
1700
+ function Ft(t) {
1701
+ return /* @__PURE__ */ e(rt, { children: /* @__PURE__ */ e(Bt, { ...t }) });
1702
+ }
1703
+ const Gt = ({
1704
+ agentId: t,
1705
+ baseUrl: n,
1706
+ apiKey: i,
1707
+ mode: o,
1708
+ onAgentEvent: r,
1709
+ className: a,
1710
+ style: c
12
1711
  }) => {
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);
1712
+ const m = S(null), d = S(null), g = S(r);
1713
+ g.current = r;
1714
+ const u = f((s) => {
1715
+ var b;
1716
+ const l = s.detail;
1717
+ (b = g.current) == null || b.call(g, l);
19
1718
  }, []);
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;
1719
+ return L(() => {
1720
+ const s = m.current;
1721
+ if (!s) return;
1722
+ const l = document.createElement("livelayer-widget");
1723
+ return l.setAttribute("agent-id", t), n && l.setAttribute("base-url", n), i && l.setAttribute("api-key", i), o && l.setAttribute("mode", o), l.addEventListener("agent-event", u), s.appendChild(l), d.current = l, () => {
1724
+ l.removeEventListener("agent-event", u), s.removeChild(l), d.current = null;
26
1725
  };
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 });
1726
+ }, [t]), L(() => {
1727
+ d.current && (o ? d.current.setAttribute("mode", o) : d.current.removeAttribute("mode"));
1728
+ }, [o]), /* @__PURE__ */ e("div", { ref: m, className: a, style: c });
30
1729
  };
1730
+ function Kt() {
1731
+ const [t, n] = x([]), i = f((r) => {
1732
+ n((a) => {
1733
+ const c = a.findIndex((m) => m.id === r.id);
1734
+ if (c >= 0) {
1735
+ const m = a.slice();
1736
+ return m[c] = r, m;
1737
+ }
1738
+ return [...a, r];
1739
+ });
1740
+ }, []), o = f(() => n([]), []);
1741
+ return {
1742
+ entries: t,
1743
+ pushSegment: i,
1744
+ clear: o,
1745
+ latest: t.length > 0 ? t[t.length - 1] : null
1746
+ };
1747
+ }
31
1748
  export {
32
- h as LiveLayerWidget
1749
+ Ft as AvatarWidget,
1750
+ rt as ErrorBoundary,
1751
+ Gt as LiveLayerWidget,
1752
+ ut as useAgentInfo,
1753
+ ot as useAudioLevel,
1754
+ st as useCameraState,
1755
+ mt as useDisplayMode,
1756
+ vt as useDisplayModePersistence,
1757
+ _t as useIsMobile,
1758
+ it as useLiveKitSession,
1759
+ dt as useMediaDevices,
1760
+ lt as useMicrophoneState,
1761
+ ct as useScreenShareState,
1762
+ Kt as useTranscript
33
1763
  };