@arbidocs/react 0.5.22 → 0.5.24

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.
@@ -1,11 +1,11 @@
1
1
  import { clearSealedDrafts, useWorkspaces } from './chunk-LYGJVSNM.js';
2
2
  import { arbiQueryKeys, callQueryKeys } from './chunk-PBXJFMES.js';
3
- import { getUserDisplayName, DEFAULT_SEGMENTER_CONFIG, INITIAL_SEGMENTER_STATE, flushSegmenter, stepSegmenter, levelFromRms } from './chunk-APZZQZ6P.js';
4
3
  import { notify } from './chunk-5HDC43MF.js';
4
+ import { getUserDisplayName, DEFAULT_SEGMENTER_CONFIG, INITIAL_SEGMENTER_STATE, flushSegmenter, stepSegmenter, levelFromRms } from './chunk-APZZQZ6P.js';
5
5
  import { useArbiHost, useArbi } from './chunk-KGCGA452.js';
6
- import { createContext, useContext, useEffect, useState, useCallback, useMemo, useSyncExternalStore, useRef } from 'react';
6
+ import { chats, calls, ArbiApiError, CallApiError, documents, continuityPrompt } from '@arbidocs/sdk/browser';
7
+ import { useSyncExternalStore, useEffect, useState, useCallback, useMemo } from 'react';
7
8
  import { useQueryClient, useQuery, useMutation } from '@tanstack/react-query';
8
- import { chats, ArbiApiError, CallApiError, calls, documents, continuityPrompt } from '@arbidocs/sdk/browser';
9
9
  import { generateChatKey, sealCallKey, sealChatKey, decryptCallTitle, encryptWithChatKey, decryptWithChatKey, initSodium, bytesToBase64, encryptFile, decryptFile, base64ToBytes, buildCallLink, encryptCallTitle } from '@arbidocs/client';
10
10
 
11
11
  // src/conversation-list.ts
@@ -65,243 +65,6 @@ function invalidateConversationDetails(queryClient, conversationId) {
65
65
  predicate: ({ queryKey }) => queryKey[0] === "arbi" && queryKey[1] === "conversations" && queryKey[2] === conversationId && queryKey[3] !== "threads"
66
66
  });
67
67
  }
68
- var ArbiWsContext = createContext(null);
69
- function useArbiWsContext() {
70
- const ctx = useContext(ArbiWsContext);
71
- if (!ctx) {
72
- throw new Error("useArbiWebSocket hooks must be used within an <ArbiWebSocketProvider>");
73
- }
74
- return ctx;
75
- }
76
- function toProfileView(profile) {
77
- return {
78
- ...profile,
79
- fullName: [profile.givenName, profile.familyName].map((part) => part?.trim()).filter(Boolean).join(" ")
80
- };
81
- }
82
- function useProfile(options) {
83
- const { client, enabled } = useAccountClient();
84
- const qc = useQueryClient();
85
- useEffect(
86
- () => client.onProfileChange(() => qc.setQueryData(arbiQueryKeys.profile(), client.profile())),
87
- [client, qc]
88
- );
89
- return useQuery({
90
- queryKey: arbiQueryKeys.profile(),
91
- queryFn: () => client.profile(),
92
- enabled: (options?.enabled ?? true) && enabled,
93
- staleTime: Infinity
94
- });
95
- }
96
- function useUpdateProfile() {
97
- const { client } = useAccountClient();
98
- const qc = useQueryClient();
99
- return useMutation({
100
- mutationFn: async (vars) => {
101
- await client.updateProfile(vars);
102
- return client.profile();
103
- },
104
- onSuccess: (profile) => {
105
- qc.setQueryData(arbiQueryKeys.profile(), profile);
106
- void qc.invalidateQueries({ queryKey: arbiQueryKeys.identity() });
107
- return qc.invalidateQueries({ queryKey: arbiQueryKeys.workspaces() });
108
- }
109
- });
110
- }
111
- function useNameEditor({ givenName, familyName, save }) {
112
- const [isEditing, setIsEditing] = useState(false);
113
- const [given, setGiven] = useState("");
114
- const [family, setFamily] = useState("");
115
- const [isSaving, setIsSaving] = useState(false);
116
- const [error, setError] = useState(null);
117
- const onStartEdit = useCallback(() => {
118
- setGiven(givenName ?? "");
119
- setFamily(familyName ?? "");
120
- setError(null);
121
- setIsEditing(true);
122
- }, [givenName, familyName]);
123
- const onSave = useCallback(() => {
124
- const trimmedGiven = given.trim();
125
- if (!trimmedGiven) return;
126
- setIsSaving(true);
127
- setError(null);
128
- void Promise.resolve().then(() => save({ givenName: trimmedGiven, familyName: family.trim() })).then(() => setIsEditing(false)).catch((e) => setError(e)).finally(() => setIsSaving(false));
129
- }, [given, family, save]);
130
- return {
131
- isEditing,
132
- givenName: given,
133
- familyName: family,
134
- onGivenNameChange: setGiven,
135
- onFamilyNameChange: setFamily,
136
- onStartEdit,
137
- onSave,
138
- onCancel: () => setIsEditing(false),
139
- isSaving,
140
- error
141
- };
142
- }
143
- var MAX_AVATAR_FILE_BYTES = 5 * 1024 * 1024;
144
- function useAvatarCrop({
145
- upload,
146
- onProblem,
147
- maxBytes = MAX_AVATAR_FILE_BYTES
148
- }) {
149
- const [pendingImage, setPendingImage] = useState(null);
150
- const [isUploading, setIsUploading] = useState(false);
151
- const onFileChosen = useCallback(
152
- (file) => {
153
- if (!file.type.startsWith("image/")) return onProblem?.("not-image");
154
- if (file.size > maxBytes) return onProblem?.("too-large");
155
- const reader = new FileReader();
156
- reader.onload = () => setPendingImage(reader.result);
157
- reader.onerror = () => onProblem?.("unreadable");
158
- reader.readAsDataURL(file);
159
- },
160
- [maxBytes, onProblem]
161
- );
162
- const onCropComplete = useCallback(
163
- (result) => {
164
- setPendingImage(null);
165
- setIsUploading(true);
166
- void Promise.resolve().then(() => upload(result.dataUrl)).catch(() => {
167
- }).finally(() => setIsUploading(false));
168
- },
169
- [upload]
170
- );
171
- return {
172
- onFileChosen,
173
- pendingImage,
174
- onCropComplete,
175
- onCropCancel: () => setPendingImage(null),
176
- isUploading
177
- };
178
- }
179
-
180
- // src/account/client.tsx
181
- function arbiProfile(arbi) {
182
- const profile = arbi.user.profile();
183
- return profile ? toProfileView(profile) : null;
184
- }
185
- function arbiAccountClient(arbi, overrides = {}) {
186
- return {
187
- profile: () => arbiProfile(arbi),
188
- onProfileChange: (listener) => arbi.user.onProfileChange(() => listener()),
189
- updateProfile: async (vars) => {
190
- await arbi.profile.update({
191
- ...vars.givenName !== void 0 && { given_name: vars.givenName.trim() },
192
- ...vars.familyName !== void 0 && { family_name: vars.familyName.trim() },
193
- ...vars.picture !== void 0 && { picture: vars.picture }
194
- });
195
- },
196
- requestEmailChange: (newEmail) => arbi.account.requestEmailChange(newEmail),
197
- confirmEmailChange: async (newEmail, code) => {
198
- await arbi.account.confirmEmailChange(newEmail, code);
199
- },
200
- changePassword: (vars) => arbi.account.changePassword(vars),
201
- listSessions: () => arbi.sessions.list(),
202
- currentSessionId: () => arbi.sessions.currentId(),
203
- terminateSession: (sessionId) => arbi.sessions.terminate(sessionId),
204
- signOut: async ({ everywhere } = {}) => {
205
- try {
206
- if (everywhere) await arbi.sessions.logoutAll();
207
- else await arbi.logout();
208
- } finally {
209
- clearSealedDrafts();
210
- }
211
- },
212
- requestDeletion: () => arbi.account.requestDeletion(),
213
- identity: {
214
- status: () => arbi.identity.status(),
215
- purchase: () => arbi.identity.purchase(),
216
- startSession: () => arbi.identity.startSession(),
217
- refresh: () => arbi.identity.refresh(),
218
- acceptName: () => arbi.identity.acceptName(),
219
- remove: () => arbi.identity.remove()
220
- },
221
- ...overrides
222
- };
223
- }
224
- var NO_ACCOUNT_ERROR = "The account needs an <ArbiHost> with `account` or an `arbi`";
225
- var refuse = () => Promise.reject(new Error(NO_ACCOUNT_ERROR));
226
- var NO_ACCOUNT = {
227
- client: {
228
- profile: () => null,
229
- onProfileChange: () => () => {
230
- },
231
- updateProfile: refuse,
232
- requestEmailChange: refuse,
233
- confirmEmailChange: refuse,
234
- changePassword: refuse,
235
- listSessions: refuse,
236
- currentSessionId: () => null,
237
- terminateSession: refuse,
238
- signOut: refuse,
239
- requestDeletion: refuse,
240
- identity: {
241
- status: refuse,
242
- purchase: refuse,
243
- startSession: refuse,
244
- refresh: refuse,
245
- acceptName: refuse,
246
- remove: refuse
247
- }
248
- },
249
- enabled: false
250
- };
251
- var ALWAYS = () => true;
252
- function useAccountClient() {
253
- const { account, arbi } = useArbiHost();
254
- const fallback = useMemo(() => arbi ? arbiAccountClient(arbi) : null, [arbi]);
255
- const useEnabled = account?.useEnabled ?? ALWAYS;
256
- const enabled = useEnabled();
257
- const client = account?.client;
258
- const provided = useMemo(() => client ? { client, enabled } : null, [client, enabled]);
259
- if (provided) return provided;
260
- if (!arbi || !fallback) return NO_ACCOUNT;
261
- return { client: fallback, enabled: arbi.isLoggedIn };
262
- }
263
- function useEntitlements() {
264
- const arbi = useArbi();
265
- return useQuery({
266
- queryKey: arbiQueryKeys.entitlements(),
267
- queryFn: () => arbi.account.entitlements(),
268
- enabled: arbi.isLoggedIn,
269
- // A plan change shows on the next read; the API enforces it at once either way.
270
- staleTime: 5 * 60 * 1e3
271
- });
272
- }
273
- function useIsEntitled(feature) {
274
- const { data } = useEntitlements();
275
- return data?.[feature] === true;
276
- }
277
- function entitlementRefusal(reason) {
278
- switch (reason) {
279
- case "external_user":
280
- return {
281
- title: "Not available for external users",
282
- description: "Mail, Calendar and hosting calls are for members of the firm. You can still join calls others host."
283
- };
284
- case "not_entitled":
285
- return {
286
- title: "Not available on this account",
287
- description: "Mail, Calendar and hosting calls are not available on this account."
288
- };
289
- default:
290
- return {
291
- title: "Available on Pro",
292
- description: "Mail, Calendar and hosting calls come with a Pro plan. You can still join calls others host."
293
- };
294
- }
295
- }
296
-
297
- // src/calls/keys.ts
298
- function invalidateCall(queryClient, message) {
299
- void queryClient.invalidateQueries({ queryKey: callQueryKeys.call(message.call_ext_id) });
300
- const thread = message.log_conversation_ext_id;
301
- if (thread) {
302
- void queryClient.invalidateQueries({ queryKey: arbiQueryKeys.conversationActivity(thread) });
303
- }
304
- }
305
68
  function myChatId(arbi) {
306
69
  try {
307
70
  return arbi.user.identity()?.externalId ?? null;
@@ -474,24 +237,543 @@ async function applyChatEvent(arbi, queryClient, event) {
474
237
  return applyChatUpdated(arbi, queryClient, e.chat_ext_id, e.message);
475
238
  if (e.type === "agent_dm_status") applyAgentDmStatus(queryClient, e);
476
239
  }
477
- function meetingChatRefFrom(row) {
478
- if (row.chat_ext_id) return { kind: "chat", chatExtId: row.chat_ext_id };
479
- const workspaceExtId = row.workspace_ext_id ?? row.locked_workspace_ext_id;
480
- if (row.meeting_conversation_ext_id && workspaceExtId) {
481
- return {
482
- kind: "thread",
483
- conversationExtId: row.meeting_conversation_ext_id,
484
- workspaceExtId
485
- };
240
+
241
+ // src/calls/keys.ts
242
+ function invalidateCall(queryClient, message) {
243
+ void queryClient.invalidateQueries({ queryKey: callQueryKeys.call(message.call_ext_id) });
244
+ const thread = message.log_conversation_ext_id;
245
+ if (thread) {
246
+ void queryClient.invalidateQueries({ queryKey: arbiQueryKeys.conversationActivity(thread) });
486
247
  }
487
- return null;
488
248
  }
489
- function callMemberKeys(call) {
490
- const keys = /* @__PURE__ */ new Map();
491
- if (call.creator_ext_id && call.creator_encryption_public_key) {
492
- keys.set(call.creator_ext_id, call.creator_encryption_public_key);
493
- }
494
- for (const i of call.invitees ?? []) {
249
+
250
+ // src/calls/moderation.ts
251
+ var CALL_MODERATION_TOPIC = "arbi.moderation";
252
+ function trackOf(value) {
253
+ return value === "audio" || value === "video" ? value : null;
254
+ }
255
+ function mutedNoticeFromPacket(payload) {
256
+ try {
257
+ const parsed = JSON.parse(new TextDecoder().decode(payload));
258
+ if (!parsed || typeof parsed !== "object") return null;
259
+ const p = parsed;
260
+ const track = trackOf(p.track);
261
+ if (p.action !== "muted" || !track) return null;
262
+ return { track, byName: typeof p.by_name === "string" ? p.by_name : null };
263
+ } catch {
264
+ return null;
265
+ }
266
+ }
267
+ function mutedNoticeText(notice) {
268
+ return notice.track === "audio" ? "The host muted you" : "The host turned off your camera";
269
+ }
270
+ var MUTED_DEDUPE_MS = 5e3;
271
+ function createMutedNotifier(show, now = Date.now) {
272
+ const last = /* @__PURE__ */ new Map();
273
+ return (notice) => {
274
+ const at = now();
275
+ const prev = last.get(notice.track);
276
+ if (prev !== void 0 && at - prev < MUTED_DEDUPE_MS) return;
277
+ last.set(notice.track, at);
278
+ show(mutedNoticeText(notice));
279
+ };
280
+ }
281
+ function mutedNoticeFromEvent(raw) {
282
+ if (!raw || typeof raw !== "object") return null;
283
+ const r = raw;
284
+ const track = trackOf(r.track);
285
+ if (typeof r.call_ext_id !== "string" || !track) return null;
286
+ return {
287
+ callExtId: r.call_ext_id,
288
+ track,
289
+ byName: typeof r.by_name === "string" ? r.by_name : null
290
+ };
291
+ }
292
+ var DEFAULT_JOIN_CHOICES = { audioEnabled: true, videoEnabled: false };
293
+ var EMPTY_CALL_SESSION = {
294
+ active: null,
295
+ incoming: [],
296
+ knocks: [],
297
+ liveCalls: {}
298
+ };
299
+ var state = EMPTY_CALL_SESSION;
300
+ var listeners = /* @__PURE__ */ new Set();
301
+ function update(next) {
302
+ const changed = next(state);
303
+ if (changed === state) return;
304
+ state = changed;
305
+ for (const listener of listeners) listener();
306
+ }
307
+ var callSession = {
308
+ getState: () => state,
309
+ subscribe(listener) {
310
+ listeners.add(listener);
311
+ return () => {
312
+ listeners.delete(listener);
313
+ };
314
+ },
315
+ setActiveCall(next) {
316
+ update((s) => ({
317
+ ...s,
318
+ active: { ...next, minimized: next.minimized ?? false, startedAt: Date.now() },
319
+ // Joining a call answers any ring for it; knocks belong to the previous call.
320
+ incoming: s.incoming.filter((ring) => ring.call_ext_id !== next.callExtId),
321
+ knocks: s.knocks.filter((k) => k.callExtId === next.callExtId)
322
+ }));
323
+ },
324
+ /** Patch the active call (no-op when it is a different call or none). */
325
+ updateActiveCall(callExtId, patch) {
326
+ update(
327
+ (s) => s.active?.callExtId === callExtId ? { ...s, active: { ...s.active, ...patch } } : s
328
+ );
329
+ },
330
+ endActiveCall() {
331
+ update((s) => {
332
+ s.active?.knock?.abort();
333
+ return { ...s, active: null, knocks: [] };
334
+ });
335
+ },
336
+ setCallMinimized(minimized) {
337
+ update((s) => s.active ? { ...s, active: { ...s.active, minimized } } : s);
338
+ },
339
+ /** Queue a ring. A repeat ring for the same call replaces the earlier entry. */
340
+ enqueueIncomingCall(ring) {
341
+ update((s) => {
342
+ if (s.active?.callExtId === ring.call_ext_id) return s;
343
+ return {
344
+ ...s,
345
+ incoming: [
346
+ ...s.incoming.filter((r) => r.call_ext_id !== ring.call_ext_id),
347
+ { ...ring, receivedAt: Date.now() }
348
+ ]
349
+ };
350
+ });
351
+ },
352
+ removeIncomingCall(callExtId) {
353
+ update((s) => ({ ...s, incoming: s.incoming.filter((r) => r.call_ext_id !== callExtId) }));
354
+ },
355
+ addKnock(knock) {
356
+ update((s) => {
357
+ if (s.active?.callExtId !== knock.callExtId) return s;
358
+ return {
359
+ ...s,
360
+ knocks: [
361
+ ...s.knocks.filter((k) => k.knockId !== knock.knockId),
362
+ { ...knock, receivedAt: Date.now() }
363
+ ]
364
+ };
365
+ });
366
+ },
367
+ removeKnock(knockId) {
368
+ update((s) => ({ ...s, knocks: s.knocks.filter((k) => k.knockId !== knockId) }));
369
+ },
370
+ markCallLive(callExtId, where) {
371
+ update((s) => ({ ...s, liveCalls: { ...s.liveCalls, [callExtId]: where } }));
372
+ },
373
+ /** Call ended: forget it and drop any unanswered ring / knock for it. */
374
+ markCallEnded(callExtId) {
375
+ update((s) => {
376
+ const liveCalls = { ...s.liveCalls };
377
+ delete liveCalls[callExtId];
378
+ return {
379
+ ...s,
380
+ liveCalls,
381
+ incoming: s.incoming.filter((r) => r.call_ext_id !== callExtId),
382
+ knocks: s.knocks.filter((k) => k.callExtId !== callExtId)
383
+ };
384
+ });
385
+ }
386
+ };
387
+ function resetCallSession() {
388
+ update(() => EMPTY_CALL_SESSION);
389
+ }
390
+ function useCallSession(selector) {
391
+ return useSyncExternalStore(
392
+ callSession.subscribe,
393
+ () => selector(state),
394
+ () => selector(state)
395
+ );
396
+ }
397
+ function threadLiveCallId(s, conversationExtId) {
398
+ const found = Object.entries(s.liveCalls).find(
399
+ ([, c]) => c.logConversationExtId === conversationExtId
400
+ );
401
+ return found ? found[0] : null;
402
+ }
403
+ function threadHasLiveCall(s, conversationExtId) {
404
+ return threadLiveCallId(s, conversationExtId) !== null;
405
+ }
406
+ function chatLiveCallId(s, chatExtId) {
407
+ const found = Object.entries(s.liveCalls).find(([, c]) => c.chatExtId === chatExtId);
408
+ return found ? found[0] : null;
409
+ }
410
+ function chatHasLiveCall(s, chatExtId) {
411
+ return chatLiveCallId(s, chatExtId) !== null;
412
+ }
413
+ var listeners2 = /* @__PURE__ */ new Map();
414
+ function onCallEvent(type, listener) {
415
+ let set = listeners2.get(type);
416
+ if (!set) listeners2.set(type, set = /* @__PURE__ */ new Set());
417
+ set.add(listener);
418
+ return () => {
419
+ set.delete(listener);
420
+ };
421
+ }
422
+ function relay(type, message) {
423
+ if (!message) return;
424
+ for (const listener of listeners2.get(type) ?? []) {
425
+ listener(message);
426
+ }
427
+ }
428
+ var str = (value) => typeof value === "string" && value ? value : null;
429
+ function applyCallEvent(queryClient, event, options = {}) {
430
+ const m = event;
431
+ const callExtId = str(m.call_ext_id);
432
+ switch (m.type) {
433
+ case "call.ringing": {
434
+ const ring = m;
435
+ if (options.acceptRings === false || !callExtId || !ring.sealed_key) return true;
436
+ if (options.me && ring.caller_ext_id === options.me) return true;
437
+ callSession.enqueueIncomingCall({
438
+ call_ext_id: ring.call_ext_id,
439
+ room_name: ring.room_name,
440
+ caller_ext_id: ring.caller_ext_id,
441
+ caller_name: ring.caller_name,
442
+ chat_ext_id: ring.chat_ext_id ?? null,
443
+ log_conversation_ext_id: ring.log_conversation_ext_id ?? null,
444
+ meeting_conversation_ext_id: ring.meeting_conversation_ext_id ?? null,
445
+ workspace_ext_id: ring.workspace_ext_id ?? null,
446
+ context: ring.context ?? null,
447
+ sealed_key: ring.sealed_key,
448
+ link_version: ring.link_version,
449
+ title: ring.title ?? null
450
+ });
451
+ return true;
452
+ }
453
+ case "call.declined":
454
+ if (callExtId && callSession.getState().active?.callExtId === callExtId) {
455
+ notify.info("Call declined", { record: false, ambient: false });
456
+ }
457
+ return true;
458
+ case "call.started":
459
+ if (!callExtId) return true;
460
+ callSession.markCallLive(callExtId, {
461
+ chatExtId: str(m.chat_ext_id),
462
+ logConversationExtId: str(m.log_conversation_ext_id),
463
+ meetingConversationExtId: str(m.meeting_conversation_ext_id)
464
+ });
465
+ invalidateCall(queryClient, {
466
+ call_ext_id: callExtId,
467
+ log_conversation_ext_id: str(m.log_conversation_ext_id)
468
+ });
469
+ return true;
470
+ case "call.ended":
471
+ if (!callExtId) return true;
472
+ callSession.markCallEnded(callExtId);
473
+ invalidateCall(queryClient, {
474
+ call_ext_id: callExtId,
475
+ log_conversation_ext_id: str(m.log_conversation_ext_id)
476
+ });
477
+ return true;
478
+ case "call.knock": {
479
+ const knock = m;
480
+ if (!callExtId) return true;
481
+ callSession.addKnock({
482
+ callExtId,
483
+ knockId: knock.knock_id,
484
+ displayName: knock.display_name,
485
+ userExtId: knock.user_ext_id
486
+ });
487
+ return true;
488
+ }
489
+ case "call.knock_resolved": {
490
+ const knockId = str(m.knock_id);
491
+ if (knockId) callSession.removeKnock(knockId);
492
+ return true;
493
+ }
494
+ case "call.recording": {
495
+ if (callExtId)
496
+ void queryClient.invalidateQueries({ queryKey: callQueryKeys.recordingsOf(callExtId) });
497
+ const state2 = calls.recordingStateFrom(m);
498
+ relay("call.recording", callExtId && state2 ? { ...state2, call_ext_id: callExtId } : null);
499
+ return true;
500
+ }
501
+ case "call.recording_updated": {
502
+ if (callExtId)
503
+ void queryClient.invalidateQueries({ queryKey: callQueryKeys.recordingsOf(callExtId) });
504
+ return true;
505
+ }
506
+ case "call.recording_deleted": {
507
+ if (callExtId)
508
+ void queryClient.invalidateQueries({ queryKey: callQueryKeys.recordingsOf(callExtId) });
509
+ const recordingExtId = str(m.recording_ext_id);
510
+ relay(
511
+ "call.recording_deleted",
512
+ callExtId && recordingExtId ? { call_ext_id: callExtId, recording_ext_id: recordingExtId } : null
513
+ );
514
+ return true;
515
+ }
516
+ case "call.transcription": {
517
+ const state2 = calls.transcriptionStateFrom(m);
518
+ relay("call.transcription", callExtId && state2 ? { ...state2, call_ext_id: callExtId } : null);
519
+ return true;
520
+ }
521
+ case "call.webinar":
522
+ relay(
523
+ "call.webinar",
524
+ callExtId && typeof m.live === "boolean" ? {
525
+ type: "call.webinar",
526
+ call_ext_id: callExtId,
527
+ live: m.live,
528
+ chat: m.chat === "everyone" ? "everyone" : "panelists"
529
+ } : null
530
+ );
531
+ return true;
532
+ case "call.muted":
533
+ relay("call.muted", mutedNoticeFromEvent(m));
534
+ return true;
535
+ default:
536
+ return false;
537
+ }
538
+ }
539
+ function toProfileView(profile) {
540
+ return {
541
+ ...profile,
542
+ fullName: [profile.givenName, profile.familyName].map((part) => part?.trim()).filter(Boolean).join(" ")
543
+ };
544
+ }
545
+ function useProfile(options) {
546
+ const { client, enabled } = useAccountClient();
547
+ const qc = useQueryClient();
548
+ useEffect(
549
+ () => client.onProfileChange(() => qc.setQueryData(arbiQueryKeys.profile(), client.profile())),
550
+ [client, qc]
551
+ );
552
+ return useQuery({
553
+ queryKey: arbiQueryKeys.profile(),
554
+ queryFn: () => client.profile(),
555
+ enabled: (options?.enabled ?? true) && enabled,
556
+ staleTime: Infinity
557
+ });
558
+ }
559
+ function useUpdateProfile() {
560
+ const { client } = useAccountClient();
561
+ const qc = useQueryClient();
562
+ return useMutation({
563
+ mutationFn: async (vars) => {
564
+ await client.updateProfile(vars);
565
+ return client.profile();
566
+ },
567
+ onSuccess: (profile) => {
568
+ qc.setQueryData(arbiQueryKeys.profile(), profile);
569
+ void qc.invalidateQueries({ queryKey: arbiQueryKeys.identity() });
570
+ return qc.invalidateQueries({ queryKey: arbiQueryKeys.workspaces() });
571
+ }
572
+ });
573
+ }
574
+ function useNameEditor({ givenName, familyName, save }) {
575
+ const [isEditing, setIsEditing] = useState(false);
576
+ const [given, setGiven] = useState("");
577
+ const [family, setFamily] = useState("");
578
+ const [isSaving, setIsSaving] = useState(false);
579
+ const [error, setError] = useState(null);
580
+ const onStartEdit = useCallback(() => {
581
+ setGiven(givenName ?? "");
582
+ setFamily(familyName ?? "");
583
+ setError(null);
584
+ setIsEditing(true);
585
+ }, [givenName, familyName]);
586
+ const onSave = useCallback(() => {
587
+ const trimmedGiven = given.trim();
588
+ if (!trimmedGiven) return;
589
+ setIsSaving(true);
590
+ setError(null);
591
+ void Promise.resolve().then(() => save({ givenName: trimmedGiven, familyName: family.trim() })).then(() => setIsEditing(false)).catch((e) => setError(e)).finally(() => setIsSaving(false));
592
+ }, [given, family, save]);
593
+ return {
594
+ isEditing,
595
+ givenName: given,
596
+ familyName: family,
597
+ onGivenNameChange: setGiven,
598
+ onFamilyNameChange: setFamily,
599
+ onStartEdit,
600
+ onSave,
601
+ onCancel: () => setIsEditing(false),
602
+ isSaving,
603
+ error
604
+ };
605
+ }
606
+ var MAX_AVATAR_FILE_BYTES = 5 * 1024 * 1024;
607
+ function useAvatarCrop({
608
+ upload,
609
+ onProblem,
610
+ maxBytes = MAX_AVATAR_FILE_BYTES
611
+ }) {
612
+ const [pendingImage, setPendingImage] = useState(null);
613
+ const [isUploading, setIsUploading] = useState(false);
614
+ const onFileChosen = useCallback(
615
+ (file) => {
616
+ if (!file.type.startsWith("image/")) return onProblem?.("not-image");
617
+ if (file.size > maxBytes) return onProblem?.("too-large");
618
+ const reader = new FileReader();
619
+ reader.onload = () => setPendingImage(reader.result);
620
+ reader.onerror = () => onProblem?.("unreadable");
621
+ reader.readAsDataURL(file);
622
+ },
623
+ [maxBytes, onProblem]
624
+ );
625
+ const onCropComplete = useCallback(
626
+ (result) => {
627
+ setPendingImage(null);
628
+ setIsUploading(true);
629
+ void Promise.resolve().then(() => upload(result.dataUrl)).catch(() => {
630
+ }).finally(() => setIsUploading(false));
631
+ },
632
+ [upload]
633
+ );
634
+ return {
635
+ onFileChosen,
636
+ pendingImage,
637
+ onCropComplete,
638
+ onCropCancel: () => setPendingImage(null),
639
+ isUploading
640
+ };
641
+ }
642
+
643
+ // src/account/client.tsx
644
+ function arbiProfile(arbi) {
645
+ const profile = arbi.user.profile();
646
+ return profile ? toProfileView(profile) : null;
647
+ }
648
+ function arbiAccountClient(arbi, overrides = {}) {
649
+ return {
650
+ profile: () => arbiProfile(arbi),
651
+ onProfileChange: (listener) => arbi.user.onProfileChange(() => listener()),
652
+ updateProfile: async (vars) => {
653
+ await arbi.profile.update({
654
+ ...vars.givenName !== void 0 && { given_name: vars.givenName.trim() },
655
+ ...vars.familyName !== void 0 && { family_name: vars.familyName.trim() },
656
+ ...vars.picture !== void 0 && { picture: vars.picture }
657
+ });
658
+ },
659
+ requestEmailChange: (newEmail) => arbi.account.requestEmailChange(newEmail),
660
+ confirmEmailChange: async (newEmail, code) => {
661
+ await arbi.account.confirmEmailChange(newEmail, code);
662
+ },
663
+ changePassword: (vars) => arbi.account.changePassword(vars),
664
+ listSessions: () => arbi.sessions.list(),
665
+ currentSessionId: () => arbi.sessions.currentId(),
666
+ terminateSession: (sessionId) => arbi.sessions.terminate(sessionId),
667
+ signOut: async ({ everywhere } = {}) => {
668
+ try {
669
+ if (everywhere) await arbi.sessions.logoutAll();
670
+ else await arbi.logout();
671
+ } finally {
672
+ clearSealedDrafts();
673
+ }
674
+ },
675
+ requestDeletion: () => arbi.account.requestDeletion(),
676
+ identity: {
677
+ status: () => arbi.identity.status(),
678
+ purchase: () => arbi.identity.purchase(),
679
+ startSession: () => arbi.identity.startSession(),
680
+ refresh: () => arbi.identity.refresh(),
681
+ acceptName: () => arbi.identity.acceptName(),
682
+ remove: () => arbi.identity.remove()
683
+ },
684
+ ...overrides
685
+ };
686
+ }
687
+ var NO_ACCOUNT_ERROR = "The account needs an <ArbiHost> with `account` or an `arbi`";
688
+ var refuse = () => Promise.reject(new Error(NO_ACCOUNT_ERROR));
689
+ var NO_ACCOUNT = {
690
+ client: {
691
+ profile: () => null,
692
+ onProfileChange: () => () => {
693
+ },
694
+ updateProfile: refuse,
695
+ requestEmailChange: refuse,
696
+ confirmEmailChange: refuse,
697
+ changePassword: refuse,
698
+ listSessions: refuse,
699
+ currentSessionId: () => null,
700
+ terminateSession: refuse,
701
+ signOut: refuse,
702
+ requestDeletion: refuse,
703
+ identity: {
704
+ status: refuse,
705
+ purchase: refuse,
706
+ startSession: refuse,
707
+ refresh: refuse,
708
+ acceptName: refuse,
709
+ remove: refuse
710
+ }
711
+ },
712
+ enabled: false
713
+ };
714
+ var ALWAYS = () => true;
715
+ function useAccountClient() {
716
+ const { account, arbi } = useArbiHost();
717
+ const fallback = useMemo(() => arbi ? arbiAccountClient(arbi) : null, [arbi]);
718
+ const useEnabled = account?.useEnabled ?? ALWAYS;
719
+ const enabled = useEnabled();
720
+ const client = account?.client;
721
+ const provided = useMemo(() => client ? { client, enabled } : null, [client, enabled]);
722
+ if (provided) return provided;
723
+ if (!arbi || !fallback) return NO_ACCOUNT;
724
+ return { client: fallback, enabled: arbi.isLoggedIn };
725
+ }
726
+ function useEntitlements() {
727
+ const arbi = useArbi();
728
+ return useQuery({
729
+ queryKey: arbiQueryKeys.entitlements(),
730
+ queryFn: () => arbi.account.entitlements(),
731
+ enabled: arbi.isLoggedIn,
732
+ // A plan change shows on the next read; the API enforces it at once either way.
733
+ staleTime: 5 * 60 * 1e3
734
+ });
735
+ }
736
+ function useIsEntitled(feature) {
737
+ const { data } = useEntitlements();
738
+ return data?.[feature] === true;
739
+ }
740
+ function entitlementRefusal(reason) {
741
+ switch (reason) {
742
+ case "external_user":
743
+ return {
744
+ title: "Not available for external users",
745
+ description: "Mail, Calendar and hosting calls are for members of the firm. You can still join calls others host."
746
+ };
747
+ case "not_entitled":
748
+ return {
749
+ title: "Not available on this account",
750
+ description: "Mail, Calendar and hosting calls are not available on this account."
751
+ };
752
+ default:
753
+ return {
754
+ title: "Available on Pro",
755
+ description: "Mail, Calendar and hosting calls come with a Pro plan. You can still join calls others host."
756
+ };
757
+ }
758
+ }
759
+ function meetingChatRefFrom(row) {
760
+ if (row.chat_ext_id) return { kind: "chat", chatExtId: row.chat_ext_id };
761
+ const workspaceExtId = row.workspace_ext_id ?? row.locked_workspace_ext_id;
762
+ if (row.meeting_conversation_ext_id && workspaceExtId) {
763
+ return {
764
+ kind: "thread",
765
+ conversationExtId: row.meeting_conversation_ext_id,
766
+ workspaceExtId
767
+ };
768
+ }
769
+ return null;
770
+ }
771
+ function callMemberKeys(call) {
772
+ const keys = /* @__PURE__ */ new Map();
773
+ if (call.creator_ext_id && call.creator_encryption_public_key) {
774
+ keys.set(call.creator_ext_id, call.creator_encryption_public_key);
775
+ }
776
+ for (const i of call.invitees ?? []) {
495
777
  if (i.encryption_public_key) keys.set(i.user_ext_id, i.encryption_public_key);
496
778
  }
497
779
  return keys;
@@ -1562,417 +1844,111 @@ async function transcribeRecording(params) {
1562
1844
  pcm = await decode(bytes);
1563
1845
  } catch (err) {
1564
1846
  console.warn("[calls] a recording part does not decode; sending it whole", err);
1565
- }
1566
- if (pcm) {
1567
- await sendPieces(cutter.push(part.offset_ms, pcm));
1568
- } else {
1569
- await send({
1570
- audio: new Blob([standalone(bytes)], { type: track.mime_type }),
1571
- seq: part.seq,
1572
- offsetMs: part.offset_ms
1573
- });
1574
- }
1575
- onProgress?.(++done, total);
1576
- }
1577
- await sendPieces(cutter.finish());
1578
- }
1579
- return { stored, failed };
1580
- }
1581
- function useCallsConfig() {
1582
- const arbi = useArbi();
1583
- const { data } = useQuery({
1584
- queryKey: callQueryKeys.config(),
1585
- queryFn: () => arbi.calls.config(),
1586
- enabled: arbi.isLoggedIn,
1587
- staleTime: 5 * 6e4,
1588
- retry: false
1589
- });
1590
- return data;
1591
- }
1592
- function useServerCallsEnabled() {
1593
- return useCallsConfig()?.enabled === true;
1594
- }
1595
- function useCallTranscriptionAvailable() {
1596
- return useCallsConfig()?.transcription_available === true;
1597
- }
1598
- function useCall(callExtId) {
1599
- const arbi = useArbi();
1600
- return useQuery({
1601
- queryKey: callQueryKeys.call(callExtId ?? ""),
1602
- queryFn: () => arbi.calls.get(callExtId),
1603
- enabled: !!callExtId && arbi.isLoggedIn,
1604
- staleTime: 6e4,
1605
- retry: false
1606
- });
1607
- }
1608
- function useCallRecordings(callExtId, enabled = true) {
1609
- const arbi = useArbi();
1610
- return useQuery({
1611
- queryKey: callQueryKeys.recordings(callExtId ?? ""),
1612
- queryFn: () => arbi.calls.recording.list(callExtId),
1613
- enabled: !!callExtId && enabled && arbi.isLoggedIn,
1614
- retry: false
1615
- });
1616
- }
1617
- function useCallRecording(callExtId, recordingExtId) {
1618
- const arbi = useArbi();
1619
- return useQuery({
1620
- queryKey: callQueryKeys.recording(callExtId ?? "", recordingExtId ?? ""),
1621
- queryFn: () => arbi.calls.recording.get(callExtId, recordingExtId),
1622
- enabled: !!callExtId && !!recordingExtId && arbi.isLoggedIn,
1623
- retry: false
1624
- });
1625
- }
1626
- var NO_WINDOWS = [];
1627
- function useRecordingWindows(callExtId, enabled) {
1628
- const { data } = useCallRecordings(callExtId, enabled);
1629
- return useMemo(() => data ? recordingWindowsOf(data) : NO_WINDOWS, [data]);
1630
- }
1631
- function useCallInviteLinks(callExtId) {
1632
- const arbi = useArbi();
1633
- return useQuery({
1634
- queryKey: callQueryKeys.inviteLinks(callExtId ?? ""),
1635
- queryFn: () => arbi.calls.inviteLinks.list(callExtId),
1636
- enabled: !!callExtId && arbi.isLoggedIn,
1637
- retry: false
1638
- });
1639
- }
1640
- function useRecordingActions(call) {
1641
- const arbi = useArbi();
1642
- const queryClient = useQueryClient();
1643
- return useMemo(
1644
- () => ({
1645
- refresh: () => void queryClient.invalidateQueries({
1646
- queryKey: callQueryKeys.recordingsOf(call.external_id)
1647
- }),
1648
- open: (recording) => openRecording(arbi, queryClient, call, recording.external_id, recording),
1649
- transcribe: async (opened, onProgress) => transcribeRecording({
1650
- arbi,
1651
- queryClient,
1652
- callExtId: call.external_id,
1653
- opened,
1654
- ref: await meetingRefForCall(arbi, queryClient, call),
1655
- onProgress
1656
- })
1657
- }),
1658
- [arbi, queryClient, call]
1659
- );
1660
- }
1661
- function useRevokeCallInviteLink(callExtId) {
1662
- const arbi = useArbi();
1663
- const queryClient = useQueryClient();
1664
- return useCallback(
1665
- async (inviteExtId) => {
1666
- await arbi.calls.inviteLinks.revoke(callExtId, inviteExtId);
1667
- void queryClient.invalidateQueries({ queryKey: callQueryKeys.inviteLinks(callExtId) });
1668
- },
1669
- [arbi, queryClient, callExtId]
1670
- );
1671
- }
1672
- var DEFAULT_JOIN_CHOICES = { audioEnabled: true, videoEnabled: false };
1673
- var EMPTY_CALL_SESSION = {
1674
- active: null,
1675
- incoming: [],
1676
- knocks: [],
1677
- liveCalls: {}
1678
- };
1679
- var state = EMPTY_CALL_SESSION;
1680
- var listeners = /* @__PURE__ */ new Set();
1681
- function update(next) {
1682
- const changed = next(state);
1683
- if (changed === state) return;
1684
- state = changed;
1685
- for (const listener of listeners) listener();
1686
- }
1687
- var callSession = {
1688
- getState: () => state,
1689
- subscribe(listener) {
1690
- listeners.add(listener);
1691
- return () => {
1692
- listeners.delete(listener);
1693
- };
1694
- },
1695
- setActiveCall(next) {
1696
- update((s) => ({
1697
- ...s,
1698
- active: { ...next, minimized: next.minimized ?? false, startedAt: Date.now() },
1699
- // Joining a call answers any ring for it; knocks belong to the previous call.
1700
- incoming: s.incoming.filter((ring) => ring.call_ext_id !== next.callExtId),
1701
- knocks: s.knocks.filter((k) => k.callExtId === next.callExtId)
1702
- }));
1703
- },
1704
- /** Patch the active call (no-op when it is a different call or none). */
1705
- updateActiveCall(callExtId, patch) {
1706
- update(
1707
- (s) => s.active?.callExtId === callExtId ? { ...s, active: { ...s.active, ...patch } } : s
1708
- );
1709
- },
1710
- endActiveCall() {
1711
- update((s) => {
1712
- s.active?.knock?.abort();
1713
- return { ...s, active: null, knocks: [] };
1714
- });
1715
- },
1716
- setCallMinimized(minimized) {
1717
- update((s) => s.active ? { ...s, active: { ...s.active, minimized } } : s);
1718
- },
1719
- /** Queue a ring. A repeat ring for the same call replaces the earlier entry. */
1720
- enqueueIncomingCall(ring) {
1721
- update((s) => {
1722
- if (s.active?.callExtId === ring.call_ext_id) return s;
1723
- return {
1724
- ...s,
1725
- incoming: [
1726
- ...s.incoming.filter((r) => r.call_ext_id !== ring.call_ext_id),
1727
- { ...ring, receivedAt: Date.now() }
1728
- ]
1729
- };
1730
- });
1731
- },
1732
- removeIncomingCall(callExtId) {
1733
- update((s) => ({ ...s, incoming: s.incoming.filter((r) => r.call_ext_id !== callExtId) }));
1734
- },
1735
- addKnock(knock) {
1736
- update((s) => {
1737
- if (s.active?.callExtId !== knock.callExtId) return s;
1738
- return {
1739
- ...s,
1740
- knocks: [
1741
- ...s.knocks.filter((k) => k.knockId !== knock.knockId),
1742
- { ...knock, receivedAt: Date.now() }
1743
- ]
1744
- };
1745
- });
1746
- },
1747
- removeKnock(knockId) {
1748
- update((s) => ({ ...s, knocks: s.knocks.filter((k) => k.knockId !== knockId) }));
1749
- },
1750
- markCallLive(callExtId, where) {
1751
- update((s) => ({ ...s, liveCalls: { ...s.liveCalls, [callExtId]: where } }));
1752
- },
1753
- /** Call ended: forget it and drop any unanswered ring / knock for it. */
1754
- markCallEnded(callExtId) {
1755
- update((s) => {
1756
- const liveCalls = { ...s.liveCalls };
1757
- delete liveCalls[callExtId];
1758
- return {
1759
- ...s,
1760
- liveCalls,
1761
- incoming: s.incoming.filter((r) => r.call_ext_id !== callExtId),
1762
- knocks: s.knocks.filter((k) => k.callExtId !== callExtId)
1763
- };
1764
- });
1765
- }
1766
- };
1767
- function resetCallSession() {
1768
- update(() => EMPTY_CALL_SESSION);
1769
- }
1770
- function useCallSession(selector) {
1771
- return useSyncExternalStore(
1772
- callSession.subscribe,
1773
- () => selector(state),
1774
- () => selector(state)
1775
- );
1776
- }
1777
- function threadLiveCallId(s, conversationExtId) {
1778
- const found = Object.entries(s.liveCalls).find(
1779
- ([, c]) => c.logConversationExtId === conversationExtId
1780
- );
1781
- return found ? found[0] : null;
1782
- }
1783
- function threadHasLiveCall(s, conversationExtId) {
1784
- return threadLiveCallId(s, conversationExtId) !== null;
1785
- }
1786
- function chatLiveCallId(s, chatExtId) {
1787
- const found = Object.entries(s.liveCalls).find(([, c]) => c.chatExtId === chatExtId);
1788
- return found ? found[0] : null;
1789
- }
1790
- function chatHasLiveCall(s, chatExtId) {
1791
- return chatLiveCallId(s, chatExtId) !== null;
1847
+ }
1848
+ if (pcm) {
1849
+ await sendPieces(cutter.push(part.offset_ms, pcm));
1850
+ } else {
1851
+ await send({
1852
+ audio: new Blob([standalone(bytes)], { type: track.mime_type }),
1853
+ seq: part.seq,
1854
+ offsetMs: part.offset_ms
1855
+ });
1856
+ }
1857
+ onProgress?.(++done, total);
1858
+ }
1859
+ await sendPieces(cutter.finish());
1860
+ }
1861
+ return { stored, failed };
1792
1862
  }
1793
-
1794
- // src/calls/moderation.ts
1795
- var CALL_MODERATION_TOPIC = "arbi.moderation";
1796
- function trackOf(value) {
1797
- return value === "audio" || value === "video" ? value : null;
1863
+ function useCallsConfig() {
1864
+ const arbi = useArbi();
1865
+ const { data } = useQuery({
1866
+ queryKey: callQueryKeys.config(),
1867
+ queryFn: () => arbi.calls.config(),
1868
+ enabled: arbi.isLoggedIn,
1869
+ staleTime: 5 * 6e4,
1870
+ retry: false
1871
+ });
1872
+ return data;
1798
1873
  }
1799
- function mutedNoticeFromPacket(payload) {
1800
- try {
1801
- const parsed = JSON.parse(new TextDecoder().decode(payload));
1802
- if (!parsed || typeof parsed !== "object") return null;
1803
- const p = parsed;
1804
- const track = trackOf(p.track);
1805
- if (p.action !== "muted" || !track) return null;
1806
- return { track, byName: typeof p.by_name === "string" ? p.by_name : null };
1807
- } catch {
1808
- return null;
1809
- }
1874
+ function useServerCallsEnabled() {
1875
+ return useCallsConfig()?.enabled === true;
1810
1876
  }
1811
- function mutedNoticeText(notice) {
1812
- return notice.track === "audio" ? "The host muted you" : "The host turned off your camera";
1877
+ function useCallTranscriptionAvailable() {
1878
+ return useCallsConfig()?.transcription_available === true;
1813
1879
  }
1814
- var MUTED_DEDUPE_MS = 5e3;
1815
- function createMutedNotifier(show, now = Date.now) {
1816
- const last = /* @__PURE__ */ new Map();
1817
- return (notice) => {
1818
- const at = now();
1819
- const prev = last.get(notice.track);
1820
- if (prev !== void 0 && at - prev < MUTED_DEDUPE_MS) return;
1821
- last.set(notice.track, at);
1822
- show(mutedNoticeText(notice));
1823
- };
1880
+ function useCall(callExtId) {
1881
+ const arbi = useArbi();
1882
+ return useQuery({
1883
+ queryKey: callQueryKeys.call(callExtId ?? ""),
1884
+ queryFn: () => arbi.calls.get(callExtId),
1885
+ enabled: !!callExtId && arbi.isLoggedIn,
1886
+ staleTime: 6e4,
1887
+ retry: false
1888
+ });
1824
1889
  }
1825
- function mutedNoticeFromEvent(raw) {
1826
- if (!raw || typeof raw !== "object") return null;
1827
- const r = raw;
1828
- const track = trackOf(r.track);
1829
- if (typeof r.call_ext_id !== "string" || !track) return null;
1830
- return {
1831
- callExtId: r.call_ext_id,
1832
- track,
1833
- byName: typeof r.by_name === "string" ? r.by_name : null
1834
- };
1890
+ function useCallRecordings(callExtId, enabled = true) {
1891
+ const arbi = useArbi();
1892
+ return useQuery({
1893
+ queryKey: callQueryKeys.recordings(callExtId ?? ""),
1894
+ queryFn: () => arbi.calls.recording.list(callExtId),
1895
+ enabled: !!callExtId && enabled && arbi.isLoggedIn,
1896
+ retry: false
1897
+ });
1835
1898
  }
1836
- var listeners2 = /* @__PURE__ */ new Map();
1837
- function onCallEvent(type, listener) {
1838
- let set = listeners2.get(type);
1839
- if (!set) listeners2.set(type, set = /* @__PURE__ */ new Set());
1840
- set.add(listener);
1841
- return () => {
1842
- set.delete(listener);
1843
- };
1899
+ function useCallRecording(callExtId, recordingExtId) {
1900
+ const arbi = useArbi();
1901
+ return useQuery({
1902
+ queryKey: callQueryKeys.recording(callExtId ?? "", recordingExtId ?? ""),
1903
+ queryFn: () => arbi.calls.recording.get(callExtId, recordingExtId),
1904
+ enabled: !!callExtId && !!recordingExtId && arbi.isLoggedIn,
1905
+ retry: false
1906
+ });
1844
1907
  }
1845
- function relay(type, message) {
1846
- if (!message) return;
1847
- for (const listener of listeners2.get(type) ?? []) {
1848
- listener(message);
1849
- }
1908
+ var NO_WINDOWS = [];
1909
+ function useRecordingWindows(callExtId, enabled) {
1910
+ const { data } = useCallRecordings(callExtId, enabled);
1911
+ return useMemo(() => data ? recordingWindowsOf(data) : NO_WINDOWS, [data]);
1850
1912
  }
1851
- var str = (value) => typeof value === "string" && value ? value : null;
1852
- function applyCallEvent(queryClient, event, options = {}) {
1853
- const m = event;
1854
- const callExtId = str(m.call_ext_id);
1855
- switch (m.type) {
1856
- case "call.ringing": {
1857
- const ring = m;
1858
- if (options.acceptRings === false || !callExtId || !ring.sealed_key) return true;
1859
- if (options.me && ring.caller_ext_id === options.me) return true;
1860
- callSession.enqueueIncomingCall({
1861
- call_ext_id: ring.call_ext_id,
1862
- room_name: ring.room_name,
1863
- caller_ext_id: ring.caller_ext_id,
1864
- caller_name: ring.caller_name,
1865
- chat_ext_id: ring.chat_ext_id ?? null,
1866
- log_conversation_ext_id: ring.log_conversation_ext_id ?? null,
1867
- meeting_conversation_ext_id: ring.meeting_conversation_ext_id ?? null,
1868
- workspace_ext_id: ring.workspace_ext_id ?? null,
1869
- context: ring.context ?? null,
1870
- sealed_key: ring.sealed_key,
1871
- link_version: ring.link_version,
1872
- title: ring.title ?? null
1873
- });
1874
- return true;
1875
- }
1876
- case "call.declined":
1877
- if (callExtId && callSession.getState().active?.callExtId === callExtId) {
1878
- notify.info("Call declined", { record: false, ambient: false });
1879
- }
1880
- return true;
1881
- case "call.started":
1882
- if (!callExtId) return true;
1883
- callSession.markCallLive(callExtId, {
1884
- chatExtId: str(m.chat_ext_id),
1885
- logConversationExtId: str(m.log_conversation_ext_id),
1886
- meetingConversationExtId: str(m.meeting_conversation_ext_id)
1887
- });
1888
- invalidateCall(queryClient, {
1889
- call_ext_id: callExtId,
1890
- log_conversation_ext_id: str(m.log_conversation_ext_id)
1891
- });
1892
- return true;
1893
- case "call.ended":
1894
- if (!callExtId) return true;
1895
- callSession.markCallEnded(callExtId);
1896
- invalidateCall(queryClient, {
1897
- call_ext_id: callExtId,
1898
- log_conversation_ext_id: str(m.log_conversation_ext_id)
1899
- });
1900
- return true;
1901
- case "call.knock": {
1902
- const knock = m;
1903
- if (!callExtId) return true;
1904
- callSession.addKnock({
1905
- callExtId,
1906
- knockId: knock.knock_id,
1907
- displayName: knock.display_name,
1908
- userExtId: knock.user_ext_id
1909
- });
1910
- return true;
1911
- }
1912
- case "call.knock_resolved": {
1913
- const knockId = str(m.knock_id);
1914
- if (knockId) callSession.removeKnock(knockId);
1915
- return true;
1916
- }
1917
- case "call.recording": {
1918
- if (callExtId)
1919
- void queryClient.invalidateQueries({ queryKey: callQueryKeys.recordingsOf(callExtId) });
1920
- const state2 = calls.recordingStateFrom(m);
1921
- relay("call.recording", callExtId && state2 ? { ...state2, call_ext_id: callExtId } : null);
1922
- return true;
1923
- }
1924
- case "call.recording_updated": {
1925
- if (callExtId)
1926
- void queryClient.invalidateQueries({ queryKey: callQueryKeys.recordingsOf(callExtId) });
1927
- return true;
1928
- }
1929
- case "call.recording_deleted": {
1930
- if (callExtId)
1931
- void queryClient.invalidateQueries({ queryKey: callQueryKeys.recordingsOf(callExtId) });
1932
- const recordingExtId = str(m.recording_ext_id);
1933
- relay(
1934
- "call.recording_deleted",
1935
- callExtId && recordingExtId ? { call_ext_id: callExtId, recording_ext_id: recordingExtId } : null
1936
- );
1937
- return true;
1938
- }
1939
- case "call.transcription": {
1940
- const state2 = calls.transcriptionStateFrom(m);
1941
- relay("call.transcription", callExtId && state2 ? { ...state2, call_ext_id: callExtId } : null);
1942
- return true;
1943
- }
1944
- case "call.webinar":
1945
- relay(
1946
- "call.webinar",
1947
- callExtId && typeof m.live === "boolean" ? {
1948
- type: "call.webinar",
1949
- call_ext_id: callExtId,
1950
- live: m.live,
1951
- chat: m.chat === "everyone" ? "everyone" : "panelists"
1952
- } : null
1953
- );
1954
- return true;
1955
- case "call.muted":
1956
- relay("call.muted", mutedNoticeFromEvent(m));
1957
- return true;
1958
- default:
1959
- return false;
1960
- }
1913
+ function useCallInviteLinks(callExtId) {
1914
+ const arbi = useArbi();
1915
+ return useQuery({
1916
+ queryKey: callQueryKeys.inviteLinks(callExtId ?? ""),
1917
+ queryFn: () => arbi.calls.inviteLinks.list(callExtId),
1918
+ enabled: !!callExtId && arbi.isLoggedIn,
1919
+ retry: false
1920
+ });
1961
1921
  }
1962
- function useCallLiveUpdates(options = {}) {
1922
+ function useRecordingActions(call) {
1963
1923
  const arbi = useArbi();
1964
1924
  const queryClient = useQueryClient();
1965
- const ws = useContext(ArbiWsContext);
1966
- const latest = useRef({ ...options, me: options.me ?? null });
1967
- latest.current = {
1968
- ...options,
1969
- me: options.me ?? (arbi.isLoggedIn ? arbi.user.identity()?.externalId ?? null : null)
1970
- };
1971
- useEffect(
1972
- () => ws?.subscribe((message) => {
1973
- if (message.type.startsWith("call.")) applyCallEvent(queryClient, message, latest.current);
1925
+ return useMemo(
1926
+ () => ({
1927
+ refresh: () => void queryClient.invalidateQueries({
1928
+ queryKey: callQueryKeys.recordingsOf(call.external_id)
1929
+ }),
1930
+ open: (recording) => openRecording(arbi, queryClient, call, recording.external_id, recording),
1931
+ transcribe: async (opened, onProgress) => transcribeRecording({
1932
+ arbi,
1933
+ queryClient,
1934
+ callExtId: call.external_id,
1935
+ opened,
1936
+ ref: await meetingRefForCall(arbi, queryClient, call),
1937
+ onProgress
1938
+ })
1974
1939
  }),
1975
- [ws, queryClient]
1940
+ [arbi, queryClient, call]
1941
+ );
1942
+ }
1943
+ function useRevokeCallInviteLink(callExtId) {
1944
+ const arbi = useArbi();
1945
+ const queryClient = useQueryClient();
1946
+ return useCallback(
1947
+ async (inviteExtId) => {
1948
+ await arbi.calls.inviteLinks.revoke(callExtId, inviteExtId);
1949
+ void queryClient.invalidateQueries({ queryKey: callQueryKeys.inviteLinks(callExtId) });
1950
+ },
1951
+ [arbi, queryClient, callExtId]
1976
1952
  );
1977
1953
  }
1978
1954
  async function postToThread(arbi, conversationExtId, newThreadTitle, content) {
@@ -2357,6 +2333,6 @@ function useOpenCallMeetingChat() {
2357
2333
  );
2358
2334
  }
2359
2335
 
2360
- export { AUDIENCE_CHOICES, ArbiWsContext, CALL_CAPTION_TOPIC, CALL_CHAT_MAX_CHARS, CALL_CHAT_TOPIC, CALL_MODERATION_TOPIC, CALL_RECORDING_TOPIC, CALL_TRANSCRIPTION_TOPIC, CALL_WEBINAR_TOPIC, CAPTION_MAX_CHARS, COMPOSITE_AUDIO_BITS_PER_SECOND, COMPOSITE_VIDEO_BITS_PER_SECOND, DEFAULT_JOIN_CHOICES, EMPTY_CALL_SESSION, EXPORT_SAMPLE_RATE, HISTORY_LIMIT, LIVE_SEGMENTER, MAX_AVATAR_FILE_BYTES, MUTED_DEDUPE_MS, PLAYBACK_LOOKAHEAD_MS, READ_ONLY_MEETING_TEXT, RECORDING_CHUNK_MS, RECORDING_SEGMENTER, SEGMENT_FRAME_MS, SEGMENT_ID_PATTERN, SEGMENT_PRE_ROLL_MS, SHORT_PIECE_MERGE_GAP_MS, SPEAKER_AUDIO_BITS_PER_SECOND, TrackUploader, UPLOAD_ATTEMPTS, UPLOAD_BACKOFF_MS, acceptRing, addConversationToList, appendToThread, applyAgentDmStatus, applyCallEvent, applyChatEvent, applyChatMessage, applyChatRead, applyChatUpdated, arbiAccountClient, buildMeetingChatBody, cachedChat, cachedChats, callLink, callMemberKeys, callSession, chatByExtId, chatHasLiveCall, chatLiveCallId, chatTranscriptRef, clearMeetingChatCache, clearTrackUploaders, clockTime, compositeFiles, compositeTrack, conversationKeyForCall, createMutedNotifier, createTrackCutter, cutAtPauses, declineRing, decodeCallChatPacket, decodeCaptionPacket, decodeMono16k, decryptPart, deleteChatMessage, dropFromThread, encodeCallChatPacket, encodeCaptionPacket, encodeWav, encryptPart, ensureMeetingChat, entitlementRefusal, extensionFor, fetchPart, fileSafe, findConversation, floatToWav, formatTranscriptMarkdown, getOpenChat, hasRecordingTranscript, invalidateCall, invalidateConversationDetails, invalidateConversationLists, isConversationListKey, isConversationShared, isKnownSoloConversation, isRecordingOver, isRecordingSegmentId, isRetryable, isWorkspaceGuestOf, joinFromPreJoin, knownMeetingChat, loadMeetingHistory, markRejoining, meetingChatRefFrom, meetingRefForCall, mergeChatLines, mutedNoticeFromEvent, mutedNoticeFromPacket, mutedNoticeText, myChatId, newPacketId, newSegmentId, newTrackKey, nextSeqAfter, onCallEvent, openCall, openQuestion, openRecording, parseWebinarPacket, partKey, partOffsetMs, partsDue, patchConversation, patchConversationList, persistMeetingMessage, persistTranscriptSegment, playheadAt, postRecordingDocsToThread, postTranscriptToThread, recordingFiles, recordingWindowsOf, rejoinAsAudience, removeChat, removeConversationFromLists, resetCallSession, resolveMeetingChat, saveRecordingFilesToThread, schedulePart, sealQuestionText, setOpenChat, sortTranscriptMessages, sortedParts, speakerTracks, speakerWav, splitIntoFiles, standalone, startChatCall, startContactsCall, startDmCall, startThreadCall, startsMediaFile, storeTranscriptSegment, stripSpeakerPrefix, supersedeLiveTranscript, supersededTranscriptLines, threadHasLiveCall, threadLiveCallId, threadTranscriptLines, threadTranscriptRef, threadTranscriptText, timelineDurationMs, timelineOf, toProfileView, trackUploaderFor, transcribeRecording, transcriptPersistRole, transcriptSegmentOf, unwrapTrackKey, upsertChat, useAccountClient, useArbiWsContext, useAvatarCrop, useCall, useCallInviteLinks, useCallLiveUpdates, useCallRecording, useCallRecordings, useCallSession, useCallTranscriptionAvailable, useCallsConfig, useCallsEnabled, useCanHostCalls, useEntitlements, useIsEntitled, useMeetingReadOnly, useNameEditor, useOpenCallMeetingChat, useProfile, useRecordingActions, useRecordingWindows, useRevokeCallInviteLink, useSaveToThread, useServerCallsEnabled, useUpdateProfile, wrapTrackKey, writeSamples };
2361
- //# sourceMappingURL=chunk-N7SIWO4X.js.map
2362
- //# sourceMappingURL=chunk-N7SIWO4X.js.map
2336
+ export { AUDIENCE_CHOICES, CALL_CAPTION_TOPIC, CALL_CHAT_MAX_CHARS, CALL_CHAT_TOPIC, CALL_MODERATION_TOPIC, CALL_RECORDING_TOPIC, CALL_TRANSCRIPTION_TOPIC, CALL_WEBINAR_TOPIC, CAPTION_MAX_CHARS, COMPOSITE_AUDIO_BITS_PER_SECOND, COMPOSITE_VIDEO_BITS_PER_SECOND, DEFAULT_JOIN_CHOICES, EMPTY_CALL_SESSION, EXPORT_SAMPLE_RATE, HISTORY_LIMIT, LIVE_SEGMENTER, MAX_AVATAR_FILE_BYTES, MUTED_DEDUPE_MS, PLAYBACK_LOOKAHEAD_MS, READ_ONLY_MEETING_TEXT, RECORDING_CHUNK_MS, RECORDING_SEGMENTER, SEGMENT_FRAME_MS, SEGMENT_ID_PATTERN, SEGMENT_PRE_ROLL_MS, SHORT_PIECE_MERGE_GAP_MS, SPEAKER_AUDIO_BITS_PER_SECOND, TrackUploader, UPLOAD_ATTEMPTS, UPLOAD_BACKOFF_MS, acceptRing, addConversationToList, appendToThread, applyAgentDmStatus, applyCallEvent, applyChatEvent, applyChatMessage, applyChatRead, applyChatUpdated, arbiAccountClient, buildMeetingChatBody, cachedChat, cachedChats, callLink, callMemberKeys, callSession, chatByExtId, chatHasLiveCall, chatLiveCallId, chatTranscriptRef, clearMeetingChatCache, clearTrackUploaders, clockTime, compositeFiles, compositeTrack, conversationKeyForCall, createMutedNotifier, createTrackCutter, cutAtPauses, declineRing, decodeCallChatPacket, decodeCaptionPacket, decodeMono16k, decryptPart, deleteChatMessage, dropFromThread, encodeCallChatPacket, encodeCaptionPacket, encodeWav, encryptPart, ensureMeetingChat, entitlementRefusal, extensionFor, fetchPart, fileSafe, findConversation, floatToWav, formatTranscriptMarkdown, getOpenChat, hasRecordingTranscript, invalidateCall, invalidateConversationDetails, invalidateConversationLists, isConversationListKey, isConversationShared, isKnownSoloConversation, isRecordingOver, isRecordingSegmentId, isRetryable, isWorkspaceGuestOf, joinFromPreJoin, knownMeetingChat, loadMeetingHistory, markRejoining, meetingChatRefFrom, meetingRefForCall, mergeChatLines, mutedNoticeFromEvent, mutedNoticeFromPacket, mutedNoticeText, myChatId, newPacketId, newSegmentId, newTrackKey, nextSeqAfter, onCallEvent, openCall, openQuestion, openRecording, parseWebinarPacket, partKey, partOffsetMs, partsDue, patchConversation, patchConversationList, persistMeetingMessage, persistTranscriptSegment, playheadAt, postRecordingDocsToThread, postTranscriptToThread, recordingFiles, recordingWindowsOf, rejoinAsAudience, removeChat, removeConversationFromLists, resetCallSession, resolveMeetingChat, saveRecordingFilesToThread, schedulePart, sealQuestionText, setOpenChat, sortTranscriptMessages, sortedParts, speakerTracks, speakerWav, splitIntoFiles, standalone, startChatCall, startContactsCall, startDmCall, startThreadCall, startsMediaFile, storeTranscriptSegment, stripSpeakerPrefix, supersedeLiveTranscript, supersededTranscriptLines, threadHasLiveCall, threadLiveCallId, threadTranscriptLines, threadTranscriptRef, threadTranscriptText, timelineDurationMs, timelineOf, toProfileView, trackUploaderFor, transcribeRecording, transcriptPersistRole, transcriptSegmentOf, unwrapTrackKey, upsertChat, useAccountClient, useAvatarCrop, useCall, useCallInviteLinks, useCallRecording, useCallRecordings, useCallSession, useCallTranscriptionAvailable, useCallsConfig, useCallsEnabled, useCanHostCalls, useEntitlements, useIsEntitled, useMeetingReadOnly, useNameEditor, useOpenCallMeetingChat, useProfile, useRecordingActions, useRecordingWindows, useRevokeCallInviteLink, useSaveToThread, useServerCallsEnabled, useUpdateProfile, wrapTrackKey, writeSamples };
2337
+ //# sourceMappingURL=chunk-I4WI3MNH.js.map
2338
+ //# sourceMappingURL=chunk-I4WI3MNH.js.map