@burdenoff/fe-libs 2026.1024.3 → 2026.1026.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.
Files changed (33) hide show
  1. package/dist/shared/assistant/avatar/live/LiveAvatarMinutes.d.ts +24 -0
  2. package/dist/shared/assistant/avatar/live/LiveAvatarMinutes.js +161 -0
  3. package/dist/shared/assistant/avatar/live/LiveAvatarStage.js +95 -74
  4. package/dist/shared/assistant/avatar/live/LiveAvatarTabView.d.ts +6 -0
  5. package/dist/shared/assistant/avatar/live/LiveAvatarTabView.js +195 -172
  6. package/dist/shared/assistant/avatar/live/avatarPorts.d.ts +9 -0
  7. package/dist/shared/assistant/avatar/live/avatarSessionClient.d.ts +77 -1
  8. package/dist/shared/assistant/avatar/live/avatarSessionClient.js +193 -72
  9. package/dist/shared/assistant/avatar/live/avatarTransport.d.ts +25 -3
  10. package/dist/shared/assistant/avatar/live/avatarTransport.js +29 -2
  11. package/dist/shared/assistant/avatar/live/createLiveAvatarSeam.d.ts +35 -4
  12. package/dist/shared/assistant/avatar/live/createLiveAvatarSeam.js +136 -79
  13. package/dist/shared/assistant/avatar/live/liveAvatarController.d.ts +79 -3
  14. package/dist/shared/assistant/avatar/live/liveAvatarController.js +424 -245
  15. package/dist/shared/assistant/avatar/live/liveAvatarMinutesView.d.ts +127 -0
  16. package/dist/shared/assistant/avatar/live/liveAvatarMinutesView.js +168 -0
  17. package/dist/shared/assistant/avatar/live/liveAvatarStatus.d.ts +3 -0
  18. package/dist/shared/assistant/avatar/live/liveAvatarStatus.js +11 -7
  19. package/dist/shared/assistant/avatar/live/liveKitAvatarRoom.js +6 -1
  20. package/dist/shared/assistant/avatar/useAvatarCopy.d.ts +127 -2
  21. package/dist/shared/assistant/avatar/useAvatarCopy.js +116 -7
  22. package/dist/shared/assistant/i18nManifest.d.ts +32 -1
  23. package/dist/shared/assistant/i18nManifest.js +55 -24
  24. package/dist/shared/assistant/index.d.ts +2 -0
  25. package/dist/shared/assistant/ui/AssistantChatArea.js +17 -17
  26. package/dist/shared/assistant/ui/AssistantMarkdownRenderer.d.ts +5 -2
  27. package/dist/shared/assistant/ui/assistantLiveAvatarSeam.d.ts +11 -3
  28. package/dist/shared/assistant/ui/avatar/AssistantAvatarTab.js +78 -76
  29. package/dist/shared/assistant/ui/avatar/avatarAskGate.d.ts +2 -0
  30. package/dist/shared/assistant/ui/avatar/avatarAskGate.js +1 -0
  31. package/dist/shared/events/index.d.ts +2 -1
  32. package/dist/shared-assistant.js +227 -225
  33. package/package.json +1 -1
@@ -1,9 +1,9 @@
1
1
  import { AvatarNotReadyError as e, LiveKitAvatarTransport as t } from "./avatarTransport.js";
2
2
  import { createAvatarTransportPort as n } from "./avatarTransportPort.js";
3
3
  import { createAvatarReplyOutputs as r } from "./avatarReplyOutputs.js";
4
- import { AvatarApiError as i, avatarAvailabilityRefusal as a, avatarRefusalFor as o } from "./avatarSessionClient.js";
4
+ import { AvatarApiError as i, avatarAvailabilityRefusal as a, avatarMinutesRefusal as o, avatarRefusalFor as s } from "./avatarSessionClient.js";
5
5
  //#region src/shared/assistant/avatar/live/liveAvatarController.ts
6
- var s = 12e4, c = 1e4, l = 8e3, ee = 5e3, u = 2e4, te = 1e3, d = {
6
+ var c = 12e4, l = 1e4, u = 8e3, ee = 5e3, d = 2e4, f = 15e3, te = 2, ne = 5, p = 6e3, m = 1e3, re = {
7
7
  voiceLive: !1,
8
8
  offered: !1,
9
9
  tabOpen: !1,
@@ -19,9 +19,15 @@ var s = 12e4, c = 1e4, l = 8e3, ee = 5e3, u = 2e4, te = 1e3, d = {
19
19
  budgetScope: null,
20
20
  notice: null,
21
21
  audioBlocked: !1,
22
- videoReady: !1
22
+ videoReady: !1,
23
+ videoBlocked: !1,
24
+ minutes: null,
25
+ minutesReason: null,
26
+ sessionMinutes: null,
27
+ sessionEndsAt: null,
28
+ purchase: "idle"
23
29
  };
24
- function f(e) {
30
+ function ie(e) {
25
31
  switch (e) {
26
32
  case "permission_revoked": return {
27
33
  problem: "unavailable",
@@ -57,88 +63,97 @@ function f(e) {
57
63
  };
58
64
  }
59
65
  }
60
- var p = new Set(["playback-blocked", "needs-hosted-voice"]), m = {
66
+ var ae = new Set(["playback-blocked", "needs-hosted-voice"]), oe = {
61
67
  problem: "unavailable",
62
68
  hide: !0
63
- };
64
- function h(s) {
65
- let { scheduler: c, preferences: l } = s, u = s.idleMs ?? 12e4, te = s.endBeforeDeadlineMs ?? 1e4, h = s.connectTimeoutMs ?? 2e4, g = s.requestTimeoutMs ?? 8e3, _ = {
66
- ...d,
67
- tabOffered: s.browserSupported()
68
- }, v = /* @__PURE__ */ new Set(), y = !1, b = null, x = 0, S = !1, C = !1, w = 0, T = null, E = null, D = [], O = 0, k = !1, A = "user", j = !1, M = !1, N = null, P = null, F = null, I = null, L = !1;
69
- function R(e) {
69
+ }, se = new Set([
70
+ "minutes-exhausted",
71
+ "minutes-in-use",
72
+ "minutes-in-use-self",
73
+ "minutes-unavailable"
74
+ ]), ce = new Set([
75
+ "minutes-exhausted",
76
+ "minutes-in-use",
77
+ "minutes-in-use-self"
78
+ ]);
79
+ function h(c) {
80
+ let { scheduler: l, preferences: u } = c, d = c.idleMs ?? 12e4, te = c.endBeforeDeadlineMs ?? 1e4, ne = c.connectTimeoutMs ?? 2e4, m = c.requestTimeoutMs ?? 8e3, h = {
81
+ ...re,
82
+ tabOffered: c.browserSupported()
83
+ }, g = /* @__PURE__ */ new Set(), _ = !1, v = null, le = null, ue = 0, y = !1, b = !1, x = 0, S = null, C = null, w = [], de = 0, fe = !1, pe = "user", T = !1, E = !1, D = null, O = null, k = null, A = null, j = !1, me = 0, M = 0, N = null, P = !1, F = !1, I = null, L = null, R = 0, z = 0, he = !1, B = 0, V = null, H = !1;
84
+ function U(e) {
70
85
  try {
71
- s.onLog?.(e);
86
+ c.onLog?.(e);
72
87
  } catch {}
73
88
  }
74
- function z() {
75
- return !y && s.browserSupported();
89
+ function ge() {
90
+ return !_ && c.browserSupported();
76
91
  }
77
- function ne(e, t) {
78
- return (e || t) && z();
92
+ function _e(e, t) {
93
+ return (e || t) && ge();
79
94
  }
80
- function B() {
81
- return _.retryAt !== null && s.now() < _.retryAt;
95
+ function W() {
96
+ return h.retryAt !== null && c.now() < h.retryAt;
82
97
  }
83
- function V(e) {
98
+ function G(e) {
84
99
  let t = {
85
- ..._,
100
+ ...h,
86
101
  ...e
87
102
  };
88
- e.problem !== void 0 && e.problem !== _.problem && (e.retryAt === void 0 && (t.retryAt = null), e.budgetScope === void 0 && (t.budgetScope = null));
103
+ e.problem !== void 0 && e.problem !== h.problem && (e.retryAt === void 0 && (t.retryAt = null), e.budgetScope === void 0 && (t.budgetScope = null), e.minutesReason === void 0 && (t.minutesReason = null));
89
104
  let n = {
90
105
  ...t,
91
- offered: ne(t.voiceLive, t.tabOpen),
92
- tabOffered: z(),
93
- heldByVoice: M && t.voiceLive
106
+ offered: _e(t.voiceLive, t.tabOpen),
107
+ tabOffered: ge(),
108
+ heldByVoice: E && t.voiceLive
94
109
  };
95
- if (!Object.keys(n).every((e) => n[e] === _[e])) {
96
- n.retryAt !== _.retryAt && (I?.(), I = null), _ = n;
97
- for (let e of [...v]) try {
110
+ if (!Object.keys(n).every((e) => n[e] === h[e])) {
111
+ n.retryAt !== h.retryAt && (A?.(), A = null), h = n;
112
+ for (let e of [...g]) try {
98
113
  e();
99
114
  } catch {}
100
115
  }
101
116
  }
102
- function H() {
103
- return k && !j ? "voice_end" : "user";
117
+ function ve() {
118
+ return fe && !T ? "voice_end" : "user";
104
119
  }
105
- function U() {
106
- l.getState().avatarEnabled !== S && l.setAvatarEnabled(S);
120
+ function K() {
121
+ u.getState().avatarEnabled !== y && u.setAvatarEnabled(y);
107
122
  }
108
- let re = {
123
+ let ye = {
109
124
  positionSec: null,
110
125
  synthetic: !0,
111
126
  rpc: "none"
112
- }, W = r({
127
+ }, q = r({
113
128
  port: {
114
- isActive: () => E !== null && E.port.isActive(),
115
- isAudioBlocked: () => E?.port.isAudioBlocked() ?? !1,
116
- connectionId: () => E?.port.connectionId() ?? 0,
117
- isMeterHealthy: () => E?.port.isMeterHealthy() ?? !1,
118
- isMeterAudible: () => E?.port.isMeterAudible() ?? !1,
119
- openSegment: () => E ? E.port.openSegment() : Promise.reject(new e("connection")),
120
- clearBuffer: (e) => E ? E.port.clearBuffer(e) : Promise.resolve(re),
121
- setOutputMuted: (e) => E?.port.setOutputMuted(e),
122
- subscribe: (e) => E ? E.port.subscribe(e) : () => void 0
129
+ isActive: () => C !== null && C.port.isActive(),
130
+ isAudioBlocked: () => C?.port.isAudioBlocked() ?? !1,
131
+ connectionId: () => C?.port.connectionId() ?? 0,
132
+ isMeterHealthy: () => C?.port.isMeterHealthy() ?? !1,
133
+ isMeterAudible: () => C?.port.isMeterAudible() ?? !1,
134
+ openSegment: () => C ? C.port.openSegment() : Promise.reject(new e("connection")),
135
+ clearBuffer: (e) => C ? C.port.clearBuffer(e) : Promise.resolve(ye),
136
+ setOutputMuted: (e) => C?.port.setOutputMuted(e),
137
+ subscribe: (e) => C ? C.port.subscribe(e) : () => void 0
123
138
  },
124
- scheduler: c,
125
- decode: s.decode,
126
- ...s.trackerConfig ? { trackerConfig: s.trackerConfig } : {},
127
- ...s.maxDrainMs === void 0 ? {} : { maxDrainMs: s.maxDrainMs },
128
- ...s.stallMs === void 0 ? {} : { stallMs: s.stallMs },
139
+ scheduler: l,
140
+ decode: c.decode,
141
+ ...c.trackerConfig ? { trackerConfig: c.trackerConfig } : {},
142
+ ...c.maxDrainMs === void 0 ? {} : { maxDrainMs: c.maxDrainMs },
143
+ ...c.stallMs === void 0 ? {} : { stallMs: c.stallMs },
129
144
  onNotice: (e) => {
130
- switch (R({
145
+ switch (U({
131
146
  event: "notice",
132
147
  notice: e
133
148
  }), e.kind) {
134
149
  case "interrupted":
135
- V({ notice: "interrupted" });
150
+ G({ notice: "interrupted" });
136
151
  return;
137
152
  case "voice-fallback":
138
- S && V({ notice: "voice-only" });
153
+ y && G({ notice: "voice-only" });
139
154
  return;
140
155
  case "audio-blocked":
141
- V({
156
+ G({
142
157
  audioBlocked: !0,
143
158
  problem: "playback-blocked"
144
159
  });
@@ -148,28 +163,31 @@ function h(s) {
148
163
  },
149
164
  onActivity: (e) => {
150
165
  if (e) {
151
- P?.(), P = null;
166
+ O?.(), O = null;
152
167
  return;
153
168
  }
154
- if (C) {
155
- K("user", { notice: "time-limit" });
169
+ if (b) {
170
+ J("user", { notice: be() });
156
171
  return;
157
172
  }
158
- G();
173
+ xe();
159
174
  }
160
175
  });
161
- function G() {
162
- P?.(), P = null, _.phase === "ready" && (P = c.setTimeout(() => {
163
- P = null, _.phase === "ready" && !W.isBusy() && K("idle", {});
164
- }, u));
165
- }
166
- function ie() {
167
- P?.(), P = null, F?.(), F = null;
168
- }
169
- function ae() {
170
- W.leave();
171
- let e = E;
172
- if (E = null, e !== null) {
176
+ function be() {
177
+ return he ? "minutes-ended" : "time-limit";
178
+ }
179
+ function xe() {
180
+ O?.(), O = null, h.phase === "ready" && (O = l.setTimeout(() => {
181
+ O = null, h.phase === "ready" && !q.isBusy() && J("idle", {});
182
+ }, d));
183
+ }
184
+ function Se() {
185
+ O?.(), O = null, k?.(), k = null;
186
+ }
187
+ function Ce() {
188
+ q.leave();
189
+ let e = C;
190
+ if (C = null, e !== null) {
173
191
  if (e.unsubscribe?.(), e.meter !== null) {
174
192
  if (e.meterAudible) {
175
193
  e.meterAudible = !1;
@@ -177,153 +195,260 @@ function h(s) {
177
195
  }
178
196
  e.meter.stop();
179
197
  }
180
- e.videoTrack?.detach(), e.transport.dispose(), e.audioElement !== null && s.releaseAudioElement(e.audioElement);
198
+ e.videoTrack?.detach(), e.transport.dispose(), e.audioElement !== null && c.releaseAudioElement(e.audioElement);
181
199
  }
182
200
  }
183
- function K(e, t) {
184
- w += 1, A = e, S = !1, C = !1, M = !1, N = null, ae(), ie();
185
- let n = T;
186
- T = null, U(), n !== null && (R({
187
- event: "session-ended",
188
- reason: e
189
- }), s.client()?.end(n, {
190
- reason: e,
191
- keepalive: t.keepalive === !0
192
- }).catch(() => void 0)), V({
201
+ function J(e, t) {
202
+ x += 1, pe = e, y = !1, b = !1, E = !1, D = null, he = !1, Ce(), Se();
203
+ let n = S;
204
+ if (S = null, K(), n !== null) {
205
+ U({
206
+ event: "session-ended",
207
+ reason: e
208
+ });
209
+ let r = c.client(), i = () => ze(e);
210
+ r?.end(n, {
211
+ reason: e,
212
+ keepalive: t.keepalive === !0
213
+ }).then(i, i);
214
+ }
215
+ Be(), G({
193
216
  phase: "off",
194
217
  closing: !1,
195
218
  audioBlocked: !1,
196
219
  videoReady: !1,
197
- ...t.problem === void 0 ? _.problem !== null && p.has(_.problem) ? { problem: null } : {} : { problem: t.problem },
220
+ videoBlocked: !1,
221
+ sessionMinutes: null,
222
+ sessionEndsAt: null,
223
+ ...t.problem === void 0 ? h.problem !== null && ae.has(h.problem) ? { problem: null } : {} : { problem: t.problem },
198
224
  ...t.notice === void 0 ? {} : { notice: t.notice }
199
225
  });
200
226
  }
201
- function q(e) {
202
- let t = o(e);
203
- t.hide && (y = !0), e instanceof i && R({
227
+ function we(e) {
228
+ let t = s(e);
229
+ t.hide && (_ = !0), e instanceof i && U({
204
230
  event: "refused",
205
231
  status: e.status,
206
232
  code: e.code
207
- }), S = !1, M = !1, N = null, U();
208
- let n = t.retryAfterSeconds !== void 0 && t.retryAfterSeconds > 0 ? t.retryAfterSeconds * 1e3 : 0, r = n > 0 ? s.now() + n : null;
209
- return V({
233
+ }), y = !1, E = !1, D = null, K();
234
+ let n = t.retryAfterSeconds !== void 0 && t.retryAfterSeconds > 0 ? t.retryAfterSeconds * 1e3 : 0, r = n > 0 ? c.now() + n : null;
235
+ return G({
210
236
  phase: "off",
211
237
  problem: t.problem,
212
238
  retryAt: r,
213
- budgetScope: t.scope ?? null
214
- }), r !== null && _.retryAt === r && (I = c.setTimeout(() => {
215
- I = null, J(r);
216
- }, n)), t;
239
+ budgetScope: t.scope ?? null,
240
+ minutesReason: t.minutesReason ?? null
241
+ }), r !== null && h.retryAt === r && (A = l.setTimeout(() => {
242
+ A = null, Te(r);
243
+ }, n)), t.problem !== null && se.has(t.problem) && Z(!0), t;
217
244
  }
218
- function J(e) {
219
- _.retryAt === e && V({
245
+ function Te(e) {
246
+ h.retryAt === e && G({
220
247
  problem: null,
221
248
  retryAt: null
222
249
  });
223
250
  }
224
- function Y() {
225
- let e = _.retryAt;
226
- L || e === null || B() || J(e);
251
+ function Ee() {
252
+ let e = h.retryAt;
253
+ j || e === null || W() || Te(e);
254
+ }
255
+ function Y(e = oe) {
256
+ e.hide && (_ = !0), y = !1, E = !1, D = null, K(), Pe(), G({
257
+ phase: "off",
258
+ problem: e.problem,
259
+ retryAt: null,
260
+ avatars: [],
261
+ minutes: null,
262
+ minutesReason: null
263
+ });
227
264
  }
228
- function X(e = m) {
229
- e.hide && (y = !0), S = !1, M = !1, N = null, U(), V({
265
+ function De(e) {
266
+ D = null, G({
230
267
  phase: "off",
231
268
  problem: e.problem,
232
269
  retryAt: null,
233
- avatars: []
270
+ minutesReason: e.minutesReason ?? null
234
271
  });
235
272
  }
236
- function oe(e) {
273
+ function Oe() {
274
+ return N = l.now(), me += 1, me;
275
+ }
276
+ function ke(e) {
277
+ return e <= M ? !1 : (M = e, !0);
278
+ }
279
+ function Ae(e, t) {
280
+ return ke(e) ? { minutes: t } : {};
281
+ }
282
+ function je(e, t) {
283
+ if (!ke(e)) return {};
284
+ let { problem: n } = h;
285
+ if (!(n !== null && ce.has(n) && h.retryAt === null && h.minutesReason !== "ZERO_SESSION_LIMIT")) return { minutes: t };
286
+ let r = o(t);
287
+ return {
288
+ minutes: t,
289
+ problem: r?.problem ?? null,
290
+ minutesReason: r?.minutesReason ?? null
291
+ };
292
+ }
293
+ function Me() {
294
+ return c.isPageVisible?.() ?? !0;
295
+ }
296
+ function Ne() {
297
+ I?.(), I = null, L = null;
298
+ }
299
+ function X() {
300
+ B += 1, V?.(), V = null, h.purchase !== "idle" && G({ purchase: "idle" });
301
+ }
302
+ function Pe() {
303
+ M = me, F = !1, R = 0, Ne(), X();
304
+ }
305
+ function Fe() {
306
+ return !j && h.minutes !== null && h.offered && (h.phase === "off" || h.phase === "choosing");
307
+ }
308
+ function Z(e) {
309
+ if (e && (R = 0), !Fe() || !Me()) return;
310
+ if (P) {
311
+ F = !0;
312
+ return;
313
+ }
314
+ let t = l.now(), n = Math.max(N === null ? t : N + f, z);
315
+ if (t < n) {
316
+ Ie(n);
317
+ return;
318
+ }
319
+ let r = c.client();
320
+ r !== null && Re(r);
321
+ }
322
+ function Ie(e) {
323
+ I !== null && L !== null && L <= e || (Ne(), L = e, I = l.setTimeout(() => {
324
+ I = null, L = null, Z(!1);
325
+ }, e - l.now()));
326
+ }
327
+ function Le(e) {
328
+ return !(e instanceof i) || e.status !== 429 ? !1 : (z = Math.max(z, l.now() + Math.max(0, e.retryAfterSeconds ?? 0) * 1e3), !0);
329
+ }
330
+ function Re(e) {
331
+ let t = Oe();
332
+ P = !0, Ge((t) => e.availability(t)).then((e) => {
333
+ j || (R = 0, G(je(t, e.available ? e.minutes ?? null : null)));
334
+ }, (e) => {
335
+ j || Le(e) && t > M && R < 2 && (R += 1, F = !0);
336
+ }).finally(() => {
337
+ P = !1, F && (F = !1, Z(!1));
338
+ });
339
+ }
340
+ function ze(e) {
341
+ e === "workspace_switch" || e === "page_hide" || Z(!0);
342
+ }
343
+ function Be() {
344
+ let e = v;
345
+ v = null, e?.();
346
+ }
347
+ function Ve() {
348
+ v !== null || !c.subscribeUserGesture || (v = c.subscribeUserGesture(() => {
349
+ let e = C;
350
+ e === null || !h.videoBlocked || e.transport.resumeVideo().catch(() => void 0);
351
+ }));
352
+ }
353
+ function He(e) {
237
354
  switch (e.type) {
238
355
  case "audioPlayback":
239
- e.canPlay ? _.problem === "playback-blocked" ? V({
356
+ e.canPlay ? h.problem === "playback-blocked" ? G({
240
357
  audioBlocked: !1,
241
358
  problem: null
242
- }) : V({ audioBlocked: !1 }) : V({
359
+ }) : G({ audioBlocked: !1 }) : G({
243
360
  audioBlocked: !0,
244
361
  problem: "playback-blocked"
245
362
  });
246
363
  return;
364
+ case "videoPlayback":
365
+ G({ videoBlocked: !e.canPlay }), e.canPlay ? Be() : Ve();
366
+ return;
247
367
  case "avatarLeft":
248
368
  case "disconnected":
249
- se();
369
+ Ue();
250
370
  return;
251
371
  default: return;
252
372
  }
253
373
  }
254
- async function se() {
255
- let e = T;
256
- if (e === null || _.phase === "ending" || _.phase === "off") return;
257
- let t = w;
258
- V({ phase: "ending" });
374
+ async function Ue() {
375
+ let e = S;
376
+ if (e === null || h.phase === "ending" || h.phase === "off") return;
377
+ let t = x;
378
+ G({ phase: "ending" });
259
379
  let n = null, r = !1;
260
380
  try {
261
- let t = s.client(), i = t === null ? void 0 : await le((n) => t.status(e, n));
381
+ let t = c.client(), i = t === null ? void 0 : await Ge((n) => t.status(e, n));
262
382
  n = i?.endedReason ?? null, r = i !== void 0 && [
263
383
  "ended",
264
384
  "failed",
265
385
  "canceled"
266
386
  ].includes(i.state);
267
387
  } catch {}
268
- if (w !== t) return;
269
- let i = f(n);
270
- i.hide && (y = !0), r && (T = null, R({
388
+ if (x !== t) return;
389
+ let i = ie(n);
390
+ i.hide && (_ = !0), r && (S = null, U({
271
391
  event: "session-ended",
272
392
  reason: "server"
273
- })), K("client_error", i);
393
+ }));
394
+ let a = i.notice === "time-limit" ? be() : i.notice;
395
+ J("client_error", {
396
+ problem: i.problem,
397
+ notice: a
398
+ }), r && ze("client_error");
274
399
  }
275
- async function ce(e, r) {
276
- let i = s.client();
400
+ async function We(e, r) {
401
+ let i = c.client();
277
402
  if (i === null) {
278
- X();
403
+ Y();
279
404
  return;
280
405
  }
281
- let a = ++w;
282
- V({
406
+ let a = ++x;
407
+ G({
283
408
  phase: "starting",
284
409
  problem: null,
285
410
  notice: null
286
411
  });
287
412
  let o;
288
413
  try {
289
- o = await s.openRoom();
414
+ o = await c.openRoom();
290
415
  } catch {
291
- w === a && X();
416
+ x === a && Y();
292
417
  return;
293
418
  }
294
- let l = () => {
419
+ let s = () => {
295
420
  o.disconnect().catch(() => void 0);
296
421
  };
297
- if (w !== a) {
298
- l();
422
+ if (x !== a) {
423
+ s();
299
424
  return;
300
425
  }
301
- let u = c.now(), d;
426
+ let u = l.now(), d;
302
427
  try {
303
428
  d = await i.create({
304
429
  avatarId: e,
305
430
  consentVersion: r,
306
- idempotencyKey: s.newIdempotencyKey()
431
+ idempotencyKey: c.newIdempotencyKey()
307
432
  });
308
433
  } catch (e) {
309
- if (l(), w !== a) return;
310
- q(e).showDisclosure && (b = null, $.requestOn({ start: !1 }));
434
+ if (s(), x !== a) return;
435
+ we(e).showDisclosure && (le = null, $.requestOn({ start: !1 }));
311
436
  return;
312
437
  }
313
- if (w !== a) {
314
- l(), i.end(d.sessionId, { reason: A === "voice_end" ? "voice_end" : "user" }).catch(() => void 0);
438
+ if (x !== a) {
439
+ s(), i.end(d.sessionId, { reason: pe === "voice_end" ? "voice_end" : "user" }).catch(() => void 0);
315
440
  return;
316
441
  }
317
- T = d.sessionId, V({ phase: "connecting" });
442
+ S = d.sessionId, G({ phase: "connecting" });
318
443
  let f = new t({
319
444
  room: o,
320
445
  avatarIdentity: d.avatarIdentity,
321
- scheduler: c,
322
- ...s.readinessProbe === void 0 ? {} : { readinessProbe: s.readinessProbe }
446
+ scheduler: l,
447
+ ...c.readinessProbe === void 0 ? {} : { readinessProbe: c.readinessProbe }
323
448
  }), p = /* @__PURE__ */ new Set(), m = {
324
449
  session: d,
325
450
  transport: f,
326
- audioElement: s.createAudioElement(),
451
+ audioElement: c.createAudioElement(),
327
452
  meter: null,
328
453
  meterAudible: !1,
329
454
  meterListeners: p,
@@ -331,22 +456,22 @@ function h(s) {
331
456
  unsubscribe: null,
332
457
  port: n({
333
458
  transport: f,
334
- isEnabled: () => S && !C,
459
+ isEnabled: () => y && !b,
335
460
  subscribeMeter: (e) => (p.add(e), () => {
336
461
  p.delete(e);
337
462
  }),
338
463
  isMeterHealthy: () => m.meter?.isRunning() ?? !1
339
464
  })
340
465
  };
341
- E = m, m.unsubscribe = f.subscribe(oe);
466
+ C = m, m.unsubscribe = f.subscribe(He);
342
467
  try {
343
- await ue(f.connect({
468
+ await Ke(f.connect({
344
469
  url: d.livekitUrl,
345
470
  token: d.participantToken,
346
471
  audioElement: m.audioElement,
347
472
  onAvatarAudio: (e) => {
348
473
  if (!(e.mediaStreamTrack === null || m.meter !== null)) try {
349
- m.meter = s.startMeter(e.mediaStreamTrack, (e) => {
474
+ m.meter = c.startMeter(e.mediaStreamTrack, (e) => {
350
475
  m.meterAudible = e;
351
476
  for (let t of [...p]) t(e);
352
477
  });
@@ -356,35 +481,39 @@ function h(s) {
356
481
  },
357
482
  onAvatarVideo: (e) => {
358
483
  m.videoTrack = e;
359
- let t = Z();
360
- t !== null && e.attach(t), E === m && V({ videoReady: !0 });
484
+ let t = qe();
485
+ t !== null && e.attach(t), C === m && G({ videoReady: !0 });
361
486
  }
362
- }), h);
487
+ }), ne);
363
488
  } catch (e) {
364
- if (w !== a) return;
365
- R({
489
+ if (x !== a) return;
490
+ U({
366
491
  event: "connect-failed",
367
492
  error: e instanceof Error ? e.name : "error"
368
- }), K("client_error", { problem: "connection" });
493
+ }), J("client_error", { problem: "connection" });
369
494
  return;
370
495
  }
371
- if (w !== a || E !== m) return;
372
- V({
496
+ if (x !== a || C !== m) return;
497
+ let re = d.maxSessionSeconds === void 0 ? ue : d.maxSessionSeconds * 1e3, ie = re > 0 ? u + re - ee - l.now() : d.endsAt - c.now();
498
+ he = d.minutes?.limitedByBalance === !0, G({
373
499
  phase: "ready",
374
500
  audioBlocked: f.audioBlocked,
375
- ...f.audioBlocked ? { problem: "playback-blocked" } : {}
376
- }), G();
377
- let g = x > 0 ? u + x - ee - c.now() : d.endsAt - s.now(), _ = Math.max(0, g - te);
378
- F = c.setTimeout(() => {
379
- F = null, w === a && (C = !0, V({ closing: !0 }), W.isBusy() || K("user", { notice: "time-limit" }));
380
- }, _);
381
- }
382
- function le(t) {
501
+ videoBlocked: f.videoBlocked,
502
+ ...f.audioBlocked ? { problem: "playback-blocked" } : {},
503
+ sessionMinutes: d.minutes ?? null,
504
+ sessionEndsAt: d.maxSessionSeconds === void 0 ? null : c.now() + ie
505
+ }), xe();
506
+ let ae = Math.max(0, ie - te);
507
+ k = l.setTimeout(() => {
508
+ k = null, x === a && (b = !0, G({ closing: !0 }), q.isBusy() || J("user", { notice: be() }));
509
+ }, ae);
510
+ }
511
+ function Ge(t) {
383
512
  let n = new AbortController();
384
513
  return new Promise((r, i) => {
385
- let a = c.setTimeout(() => {
514
+ let a = l.setTimeout(() => {
386
515
  n.abort(), i(new e("connection"));
387
- }, g);
516
+ }, m);
388
517
  t(n.signal).then((e) => {
389
518
  a(), r(e);
390
519
  }, (e) => {
@@ -392,9 +521,9 @@ function h(s) {
392
521
  });
393
522
  });
394
523
  }
395
- function ue(t, n) {
524
+ function Ke(t, n) {
396
525
  return new Promise((r, i) => {
397
- let a = c.setTimeout(() => i(new e("connection")), n);
526
+ let a = l.setTimeout(() => i(new e("connection")), n);
398
527
  t.then((e) => {
399
528
  a(), r(e);
400
529
  }, (e) => {
@@ -402,192 +531,242 @@ function h(s) {
402
531
  });
403
532
  });
404
533
  }
405
- function Z() {
406
- return D[D.length - 1] ?? null;
534
+ function qe() {
535
+ return w[w.length - 1] ?? null;
407
536
  }
408
- function de(e) {
409
- let t = D.indexOf(e);
537
+ function Je(e) {
538
+ let t = w.indexOf(e);
410
539
  if (t === -1) return;
411
- let n = t === D.length - 1;
412
- D.splice(t, 1);
413
- let r = E?.videoTrack ?? null;
540
+ let n = t === w.length - 1;
541
+ w.splice(t, 1);
542
+ let r = C?.videoTrack ?? null;
414
543
  if (!n || r === null) return;
415
544
  r.detach();
416
- let i = Z();
545
+ let i = qe();
417
546
  i !== null && r.attach(i);
418
547
  }
419
548
  let Q = [];
420
- Q.push(l.subscribe(() => {
421
- let e = l.getState().avatarEnabled;
422
- if (e !== S) {
549
+ Q.push(u.subscribe(() => {
550
+ let e = u.getState().avatarEnabled;
551
+ if (e !== y) {
423
552
  if (e) {
424
- l.setAvatarEnabled(!1);
553
+ u.setAvatarEnabled(!1);
425
554
  return;
426
555
  }
427
- _.phase !== "off" && _.phase !== "checking" && _.phase !== "choosing" ? K(H(), {}) : S = !1;
556
+ h.phase !== "off" && h.phase !== "checking" && h.phase !== "choosing" ? J(ve(), {}) : y = !1;
428
557
  }
429
- })), s.subscribeWorkspaceChange && Q.push(s.subscribeWorkspaceChange(() => {
430
- if (y = !1, _.phase === "off" ? V({
558
+ })), c.subscribeWorkspaceChange && Q.push(c.subscribeWorkspaceChange(() => {
559
+ if (_ = !1, Pe(), h.phase === "off" ? G({
431
560
  problem: null,
432
561
  avatars: [],
433
- consentVersion: null
434
- }) : (K("workspace_switch", { problem: null }), V({
562
+ consentVersion: null,
563
+ minutes: null
564
+ }) : (J("workspace_switch", { problem: null }), G({
435
565
  avatars: [],
436
- consentVersion: null
437
- })), j) {
438
- let e = w;
439
- c.setTimeout(() => {
440
- j && w === e && $.requestOn({ start: !1 });
566
+ consentVersion: null,
567
+ minutes: null
568
+ })), T) {
569
+ let e = x;
570
+ l.setTimeout(() => {
571
+ T && x === e && $.requestOn({ start: !1 });
441
572
  }, 0);
442
573
  }
443
- })), s.subscribePageHide && Q.push(s.subscribePageHide(() => {
444
- (T !== null || _.phase !== "off") && K("page_hide", { keepalive: !0 });
445
- })), s.subscribePageShow && Q.push(s.subscribePageShow(Y));
574
+ })), c.subscribePageHide && Q.push(c.subscribePageHide(() => {
575
+ (S !== null || h.phase !== "off") && J("page_hide", { keepalive: !0 });
576
+ })), c.subscribePageHidden && Q.push(c.subscribePageHidden(() => {
577
+ c.endOnHide?.() === !0 && (S !== null || h.phase !== "off") && J("page_hide", { keepalive: !0 });
578
+ })), c.subscribePageVisible && Q.push(c.subscribePageVisible(() => {
579
+ P || Z(!0);
580
+ })), c.subscribePageShow && Q.push(c.subscribePageShow(Ee));
446
581
  let $ = {
447
582
  subscribe(e) {
448
- return v.add(e), () => {
449
- v.delete(e);
583
+ return g.add(e), () => {
584
+ g.delete(e);
450
585
  };
451
586
  },
452
- getSnapshot: () => _,
587
+ getSnapshot: () => h,
453
588
  setVoiceLive(e) {
454
- if (k = !e, e) {
455
- V({
589
+ if (fe = !e, e) {
590
+ G({
456
591
  voiceLive: !0,
457
- problem: y || j && B() ? _.problem : null,
592
+ problem: _ || T && W() ? h.problem : null,
458
593
  notice: null
459
594
  });
460
595
  return;
461
596
  }
462
- if (M = !1, j) {
463
- V({ voiceLive: !1 });
597
+ if (E = !1, T) {
598
+ G({ voiceLive: !1 });
464
599
  return;
465
600
  }
466
- (T !== null || _.phase !== "off") && (_.phase === "checking" || _.phase === "choosing" ? (w += 1, V({ phase: "off" })) : K("voice_end", {})), V({
601
+ (S !== null || h.phase !== "off") && (h.phase === "checking" || h.phase === "choosing" ? (x += 1, G({ phase: "off" })) : J("voice_end", {})), G({
467
602
  voiceLive: !1,
468
603
  notice: null
469
604
  });
470
605
  },
471
606
  requestOn(e = {}) {
472
- if (L || !_.offered || _.phase !== "off") return;
607
+ if (j || !h.offered || h.phase !== "off") return;
473
608
  let t = e.start === void 0 ? "auto" : e.start ? "start" : "choose";
474
- if (t === "start" && B()) return;
475
- let n = e.avatarId ?? _.selectedAvatarId, r = _.consentVersion, i = s.client();
609
+ if (t === "start" && W()) return;
610
+ let n = e.avatarId ?? h.selectedAvatarId, r = h.consentVersion, i = c.client();
476
611
  if (i === null) {
477
- X();
612
+ Y();
478
613
  return;
479
614
  }
480
- t === "start" && (N = c.now());
481
- let o = ++w;
482
- V({
615
+ t === "start" && (D = l.now());
616
+ let o = ++x, s = Oe();
617
+ F = !1, Ne(), G({
483
618
  phase: "checking",
484
- problem: B() ? _.problem : null,
619
+ problem: W() ? h.problem : null,
485
620
  notice: null
486
- }), le((e) => i.availability(e)).then((e) => {
487
- if (w !== o) return;
621
+ }), Ge((e) => i.availability(e)).then((e) => {
622
+ if (x !== o) return;
488
623
  if (!e.available) {
489
- X(a(e.reason));
624
+ Y(a(e.reason));
490
625
  return;
491
626
  }
492
- x = e.maxSessionSeconds * 1e3;
493
- let i = t === "start" && n !== null && e.avatars.includes(n), s = l.getState().avatarId, c = i ? n : s !== null && e.avatars.includes(s) ? s : e.avatars[0] ?? null;
494
- switch (V({
627
+ ue = e.maxSessionSeconds * 1e3;
628
+ let i = t === "start" && n !== null && e.avatars.includes(n), c = u.getState().avatarId, l = i ? n : c !== null && e.avatars.includes(c) ? c : e.avatars[0] ?? null;
629
+ switch (G({
495
630
  phase: "choosing",
496
631
  avatars: e.avatars,
497
- selectedAvatarId: c,
498
- consentVersion: e.consentVersion
632
+ selectedAvatarId: l,
633
+ consentVersion: e.consentVersion,
634
+ ...Ae(s, e.minutes ?? null)
499
635
  }), t) {
500
636
  case "auto":
501
- b === e.consentVersion && e.avatars.length === 1 && $.confirm();
637
+ le === e.consentVersion && e.avatars.length === 1 && $.confirm();
502
638
  return;
503
639
  case "start":
504
- i && r === e.consentVersion ? $.confirm() : N = null;
640
+ i && r === e.consentVersion ? $.confirm() : D = null;
505
641
  return;
506
642
  case "choose": return;
507
643
  }
508
644
  }, (e) => {
509
- w === o && q(e);
645
+ Le(e), x === o && we(e);
510
646
  });
511
647
  },
512
648
  confirm() {
513
- if (_.phase !== "choosing" || !(_.voiceLive || j) || B()) return;
514
- let e = _.selectedAvatarId, t = _.consentVersion;
515
- e === null || t === null || (b = t, l.setAvatarId(e), S = !0, M = !j, j && (N ??= c.now()), U(), ce(e, t));
649
+ if (h.phase !== "choosing" || !(h.voiceLive || T) || W()) return;
650
+ let e = o(h.minutes);
651
+ if (e !== null) {
652
+ De(e);
653
+ return;
654
+ }
655
+ let t = h.selectedAvatarId, n = h.consentVersion;
656
+ t === null || n === null || (le = n, u.setAvatarId(t), y = !0, E = !T, T && (D ??= l.now()), K(), We(t, n));
516
657
  },
517
- recheckRetry: Y,
658
+ recheckRetry: Ee,
518
659
  cancelChoice() {
519
- _.phase === "choosing" && (w += 1, N = null, V({ phase: "off" }));
660
+ h.phase === "choosing" && (x += 1, D = null, G({ phase: "off" }));
661
+ },
662
+ refreshMinutes() {
663
+ Z(!0);
664
+ },
665
+ checkMinutesPurchase() {
666
+ if (j || h.minutes === null) return;
667
+ let e = c.client();
668
+ if (e === null) return;
669
+ X();
670
+ let t = B, n = l.now(), r = N === null ? n : Math.max(n, N + p), i = h.minutes.balance?.availableMinutes ?? 0, a = 0;
671
+ G({ purchase: "checking" });
672
+ let o = () => {
673
+ if (V = null, t !== B) return;
674
+ a += 1;
675
+ let n = a >= 5;
676
+ if (h.phase !== "off" && h.phase !== "choosing" && h.phase !== "checking") {
677
+ X();
678
+ return;
679
+ }
680
+ if (n || (V = l.setTimeout(o, r + a * p - l.now())), !Me() || h.phase === "checking" || P || H || l.now() < z) {
681
+ n && X();
682
+ return;
683
+ }
684
+ H = !0;
685
+ let s = Oe();
686
+ Ge((t) => e.availability(t)).then((e) => {
687
+ if (H = !1, j) return;
688
+ let r = e.available ? e.minutes ?? null : null;
689
+ G(je(s, r)), t === B && ((r?.balance?.availableMinutes ?? 0) > i || n) && X();
690
+ }, (e) => {
691
+ H = !1, !j && (Le(e), t === B && n && X());
692
+ });
693
+ };
694
+ r > n ? V = l.setTimeout(o, r - n) : o();
520
695
  },
521
696
  setTabOpen(e) {
522
- if (L || e === j) return;
523
- if (j = e, e) {
524
- V({ tabOpen: !0 }), _.phase === "checking" && (w += 1, V({ phase: "off" }), $.requestOn({ start: !1 }));
697
+ if (j || e === T) return;
698
+ if (T = e, e) {
699
+ if (G({ tabOpen: !0 }), h.phase === "checking") {
700
+ x += 1, G({ phase: "off" }), $.requestOn({ start: !1 });
701
+ return;
702
+ }
703
+ Z(!0);
525
704
  return;
526
705
  }
527
- N = null;
528
- let t = _.phase;
706
+ D = null;
707
+ let t = h.phase;
529
708
  if (t === "checking" || t === "choosing") {
530
- w += 1, V({
709
+ x += 1, G({
531
710
  tabOpen: !1,
532
711
  phase: "off"
533
712
  });
534
713
  return;
535
714
  }
536
- (T !== null || t !== "off") && !_.heldByVoice && K("user", {}), V({ tabOpen: !1 });
715
+ (S !== null || t !== "off") && !h.heldByVoice && J("user", {}), G({ tabOpen: !1 });
537
716
  },
538
717
  selectAvatar(e) {
539
- _.avatars.includes(e) && V({ selectedAvatarId: e });
718
+ h.avatars.includes(e) && G({ selectedAvatarId: e });
540
719
  },
541
720
  switchOff() {
542
- let { phase: e } = _;
543
- if (!(j && N !== null && (e === "checking" || e === "starting" || e === "connecting") && c.now() - N < 1e3)) {
721
+ let { phase: e } = h;
722
+ if (!(T && D !== null && (e === "checking" || e === "starting" || e === "connecting") && l.now() - D < 1e3)) {
544
723
  if (e === "checking" || e === "choosing") {
545
- w += 1, N = null, V({ phase: "off" });
724
+ x += 1, D = null, G({ phase: "off" });
546
725
  return;
547
726
  }
548
- if (e === "off" && !S) {
549
- U();
727
+ if (e === "off" && !y) {
728
+ K();
550
729
  return;
551
730
  }
552
- K(H(), {});
731
+ J(ve(), {});
553
732
  }
554
733
  },
555
734
  resumeAudio() {
556
- let e = E;
557
- e !== null && (e.transport.resumeAudio().catch(() => void 0), e.meter?.resume().catch(() => void 0));
735
+ let e = C;
736
+ e !== null && (e.transport.resumeAudio().catch(() => void 0), e.meter?.resume().catch(() => void 0), h.videoBlocked && e.transport.resumeVideo().catch(() => void 0));
558
737
  },
559
738
  setStageMounted(e) {
560
- O = Math.max(0, O + (e ? 1 : -1));
739
+ de = Math.max(0, de + (e ? 1 : -1));
561
740
  },
562
741
  attachVideo(e) {
563
742
  if (e === null) {
564
- let e = Z();
565
- e !== null && de(e);
743
+ let e = qe();
744
+ e !== null && Je(e);
566
745
  return;
567
746
  }
568
- let t = D.indexOf(e);
569
- t !== -1 && D.splice(t, 1), D.push(e);
570
- let n = E?.videoTrack ?? null;
571
- return n !== null && (n.detach(), n.attach(e)), () => de(e);
747
+ let t = w.indexOf(e);
748
+ t !== -1 && w.splice(t, 1), w.push(e);
749
+ let n = C?.videoTrack ?? null;
750
+ return n !== null && (n.detach(), n.attach(e)), () => Je(e);
572
751
  },
573
752
  route(e, t) {
574
- if (_.phase !== "ready" || C || !S || O === 0 || E === null || E.port.isAudioBlocked() || e.fallback === !1) return "speakers";
753
+ if (h.phase !== "ready" || b || !y || de === 0 || C === null || C.port.isAudioBlocked() || e.fallback === !1) return "speakers";
575
754
  let n = e.voice;
576
- return n !== null && n.source !== "hosted" || !t.listVoices().some((e) => e.source === "hosted") ? (R({
755
+ return n !== null && n.source !== "hosted" || !t.listVoices().some((e) => e.source === "hosted") ? (U({
577
756
  event: "notice",
578
757
  notice: { kind: "needs-hosted-voice" }
579
- }), V({ problem: "needs-hosted-voice" }), "speakers") : (_.problem === "needs-hosted-voice" && V({ problem: null }), "avatar");
758
+ }), G({ problem: "needs-hosted-voice" }), "speakers") : (h.problem === "needs-hosted-voice" && G({ problem: null }), "avatar");
580
759
  },
581
- createOutput: () => W.createOutput(),
760
+ createOutput: () => q.createOutput(),
582
761
  dispose() {
583
- if (!L) {
584
- L = !0, (T !== null || _.phase !== "off") && K("user", {}), I?.(), I = null;
762
+ if (!j) {
763
+ j = !0, (S !== null || h.phase !== "off") && J("user", {}), A?.(), A = null, Ne(), B += 1, V?.(), V = null;
585
764
  for (let e of Q.splice(0)) e();
586
- v.clear();
765
+ Be(), g.clear();
587
766
  }
588
767
  }
589
768
  };
590
769
  return $;
591
770
  }
592
771
  //#endregion
593
- export { u as LIVE_AVATAR_CONNECT_TIMEOUT_MS, c as LIVE_AVATAR_END_BEFORE_DEADLINE_MS, s as LIVE_AVATAR_IDLE_MS, l as LIVE_AVATAR_REQUEST_TIMEOUT_MS, te as LIVE_AVATAR_TAB_OFF_GUARD_MS, h as createLiveAvatarController };
772
+ export { d as LIVE_AVATAR_CONNECT_TIMEOUT_MS, l as LIVE_AVATAR_END_BEFORE_DEADLINE_MS, c as LIVE_AVATAR_IDLE_MS, te as LIVE_AVATAR_MINUTES_BUSY_RETRIES, f as LIVE_AVATAR_MINUTES_REFRESH_MS, ne as LIVE_AVATAR_PURCHASE_POLLS, p as LIVE_AVATAR_PURCHASE_POLL_MS, u as LIVE_AVATAR_REQUEST_TIMEOUT_MS, m as LIVE_AVATAR_TAB_OFF_GUARD_MS, h as createLiveAvatarController };