@marktiderman/genesis-chat 0.11.3 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +116 -3
  2. package/dist/{chunk-ZQFREERR.js → chunk-2HNQWDLF.js} +3 -3
  3. package/dist/{chunk-ZQFREERR.js.map → chunk-2HNQWDLF.js.map} +1 -1
  4. package/dist/{chunk-O2QSBRSH.js → chunk-3HQN2FZ5.js} +3 -3
  5. package/dist/{chunk-O2QSBRSH.js.map → chunk-3HQN2FZ5.js.map} +1 -1
  6. package/dist/{chunk-D4RPOYB7.js → chunk-K5GYNHNE.js} +61 -11
  7. package/dist/chunk-K5GYNHNE.js.map +1 -0
  8. package/dist/{chunk-5XYDVUPS.js → chunk-VBIYDXL2.js} +9 -3
  9. package/dist/chunk-VBIYDXL2.js.map +1 -0
  10. package/dist/{client-DP7rhJ1U.d.ts → client-DJs3ltZc.d.ts} +15 -0
  11. package/dist/index.d.ts +4 -4
  12. package/dist/index.js +3 -3
  13. package/dist/native.d.ts +339 -137
  14. package/dist/native.js +668 -192
  15. package/dist/native.js.map +1 -1
  16. package/dist/{outbox-C4LnqpKT.d.ts → outbox-YFTbGIAl.d.ts} +1 -1
  17. package/dist/push.d.ts +2 -2
  18. package/dist/react.d.ts +13 -5
  19. package/dist/react.js +3 -3
  20. package/dist/server.d.ts +1 -1
  21. package/dist/server.js +1 -1
  22. package/dist/{thread-CSzdqNR_.d.ts → thread-CgHP00Jw.d.ts} +1 -1
  23. package/dist/web.d.ts +3 -3
  24. package/dist/web.js +5 -5
  25. package/migrations/0006_genesis_chat_read_receipts.sql +110 -0
  26. package/migrations/tests/0006_genesis_chat_read_receipts.test.sql +131 -0
  27. package/package.json +9 -5
  28. package/src/core/client.ts +9 -0
  29. package/src/core/types.ts +7 -0
  30. package/src/native/__tests__/bubble-native-feel.test.tsx +153 -0
  31. package/src/native/__tests__/composer-attach-menu.test.tsx +47 -0
  32. package/src/native/__tests__/media-cache-key.test.tsx +21 -0
  33. package/src/native/__tests__/organise-screens.test.tsx +2 -0
  34. package/src/native/__tests__/receipts.test.ts +95 -0
  35. package/src/native/__tests__/review-lows.test.tsx +80 -0
  36. package/src/native/__tests__/sheets-fit.test.tsx +45 -0
  37. package/src/native/__tests__/stable-hooks.test.tsx +68 -0
  38. package/src/native/__tests__/thread-screen-audit.test.tsx +248 -0
  39. package/src/native/__tests__/thread-screen.test.tsx +111 -0
  40. package/src/native/__tests__/thread-title.test.tsx +59 -0
  41. package/src/native/composer.tsx +61 -26
  42. package/src/native/copy.ts +40 -0
  43. package/src/native/emoji-picker.tsx +1 -1
  44. package/src/native/index.ts +6 -1
  45. package/src/native/media.tsx +7 -1
  46. package/src/native/message-actions-sheet.tsx +1 -1
  47. package/src/native/message-bubble.tsx +171 -19
  48. package/src/native/modules.ts +3 -1
  49. package/src/native/receipts.ts +102 -0
  50. package/src/native/schedule-sheet.tsx +8 -3
  51. package/src/native/stack-options.ts +35 -3
  52. package/src/native/thread-screen.tsx +243 -17
  53. package/src/native/thread-times.tsx +89 -0
  54. package/src/native/thread-title.tsx +111 -0
  55. package/src/native/typing-bubble.tsx +85 -0
  56. package/src/react/index.tsx +74 -7
  57. package/dist/chunk-5XYDVUPS.js.map +0 -1
  58. package/dist/chunk-D4RPOYB7.js.map +0 -1
@@ -0,0 +1,85 @@
1
+ /**
2
+ * @feat:chat
3
+ * Someone typing, the way iMessage shows it: a bubble of three dots on the other side, at the
4
+ * bottom of the thread, under the newest message. In a group the typer's avatar sits beside it,
5
+ * as it does beside their messages. The dots pulse in turn (held still with Reduce Motion), and the
6
+ * bubble reads as the activity line ("Sam is typing…") to VoiceOver and TalkBack.
7
+ */
8
+ import { useEffect, useRef } from "react";
9
+ import { AccessibilityInfo, Animated, Platform, View } from "react-native";
10
+ import { NativeAvatar } from "@marktiderman/genesis-ui-native/components";
11
+ import { useThemeRoles } from "@marktiderman/genesis-ui-native/hooks";
12
+ import { initials, useChatNative } from "./context";
13
+
14
+ export interface ChatTypingBubbleProps {
15
+ /** Read out: "Sam is typing…". */
16
+ label: string;
17
+ /** Who is typing (the first, in a group): their avatar shows beside the bubble. */
18
+ userId?: string | null;
19
+ group: boolean;
20
+ reducedMotion: boolean;
21
+ testID: string;
22
+ }
23
+
24
+ const DOT = 8;
25
+ /** The least time between two "is typing" announcements on iOS. */
26
+ const ANNOUNCE_GAP_MS = 4000;
27
+
28
+ export function ChatTypingBubble({ label, userId, group, reducedMotion, testID }: ChatTypingBubbleProps) {
29
+ const colors = useThemeRoles();
30
+ const { person } = useChatNative();
31
+ const typer = userId ? person(userId) : null;
32
+ const dots = useRef([new Animated.Value(0.4), new Animated.Value(0.4), new Animated.Value(0.4)]).current;
33
+
34
+ // iOS has no live regions: VoiceOver hears who is typing when it changes, at most every few seconds.
35
+ const lastSaid = useRef<{ label: string; at: number } | null>(null);
36
+ useEffect(() => {
37
+ if (Platform.OS !== "ios") return;
38
+ const now = Date.now();
39
+ const last = lastSaid.current;
40
+ if (last && (last.label === label || now - last.at < ANNOUNCE_GAP_MS)) return;
41
+ lastSaid.current = { label, at: now };
42
+ (AccessibilityInfo as { announceForAccessibility?: (t: string) => void }).announceForAccessibility?.(label);
43
+ }, [label]);
44
+
45
+ useEffect(() => {
46
+ if (reducedMotion) {
47
+ dots.forEach((d) => d.setValue(0.6));
48
+ return;
49
+ }
50
+ // One loop per dot, each a beat behind the one before (a hold at the low point is the beat).
51
+ const pulses = dots.map((d, i) =>
52
+ Animated.loop(
53
+ Animated.sequence([
54
+ Animated.timing(d, { toValue: 0.4, duration: i * 160, useNativeDriver: true }),
55
+ Animated.timing(d, { toValue: 1, duration: 300, useNativeDriver: true }),
56
+ Animated.timing(d, { toValue: 0.4, duration: 300, useNativeDriver: true }),
57
+ Animated.timing(d, { toValue: 0.4, duration: (dots.length - 1 - i) * 160, useNativeDriver: true }),
58
+ ]),
59
+ ),
60
+ );
61
+ pulses.forEach((p) => p.start());
62
+ return () => pulses.forEach((p) => p.stop());
63
+ }, [dots, reducedMotion]);
64
+
65
+ return (
66
+ <View
67
+ testID={testID}
68
+ accessible
69
+ accessibilityLabel={label}
70
+ accessibilityLiveRegion="polite"
71
+ style={{ flexDirection: "row", alignItems: "flex-end", paddingTop: 8, paddingBottom: 6, paddingHorizontal: 8 }}
72
+ >
73
+ {group ? (
74
+ <View style={{ width: 40, alignItems: "flex-start" }}>
75
+ <NativeAvatar size={32} src={typer?.avatarUrl ?? null} fallback={initials(typer?.name)} alt={typer?.name} recyclingKey={userId ?? undefined} />
76
+ </View>
77
+ ) : null}
78
+ <View testID={`${testID}-bubble`} style={{ flexDirection: "row", alignItems: "center", gap: 5, paddingHorizontal: 14, paddingVertical: 12, borderRadius: 18, backgroundColor: colors.surface }}>
79
+ {dots.map((opacity, i) => (
80
+ <Animated.View key={i} testID={`${testID}-dot-${i}`} style={{ width: DOT, height: DOT, borderRadius: DOT / 2, backgroundColor: colors.secondaryLabel, opacity }} />
81
+ ))}
82
+ </View>
83
+ </View>
84
+ );
85
+ }
@@ -5,7 +5,7 @@
5
5
  * Realtime hints, sending through the outbox, and message actions. Server
6
6
  * state is TanStack Query's; the renderers in /web and /native only draw.
7
7
  */
8
- import { useQueries, useQuery, useQueryClient } from "@tanstack/react-query";
8
+ import { keepPreviousData, useQueries, useQuery, useQueryClient } from "@tanstack/react-query";
9
9
  import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, type ReactNode } from "react";
10
10
  import type { ChatClient, ConversationChannel, MessagePage } from "../core/client";
11
11
  import {
@@ -26,6 +26,7 @@ import type {
26
26
  ChatAttachment,
27
27
  ChatAvailability,
28
28
  ChatLinkPreview,
29
+ ChatMember,
29
30
  ChatMessage,
30
31
  ChatSearchHit,
31
32
  ChatSignal,
@@ -332,6 +333,9 @@ export interface UseConversationOptions {
332
333
  }
333
334
 
334
335
  /** One conversation: its messages (with what you are still sending), members, your role, and who is typing. */
336
+ /** How long a `read` hint waits for others before the members are read again. */
337
+ const READ_REFETCH_MS = 300;
338
+
335
339
  export function useConversation(conversationId: string | null | undefined, opts: UseConversationOptions = {}) {
336
340
  const { client, userId, outbox, queue } = useChat();
337
341
  const queryClient = useQueryClient();
@@ -368,6 +372,20 @@ export function useConversation(conversationId: string | null | undefined, opts:
368
372
  const hasEarlier = messages.data?.hasEarlier ?? false;
369
373
  // Where "New" goes: what you had read when the conversation opened.
370
374
  const [readWhenOpened, setReadWhenOpened] = useState<number | null>(null);
375
+ // Another conversation in the same screen (a split view, no remount) opens at its own read place:
376
+ // forget the last one's, and read this one's members afresh (a cached copy may be from an earlier visit).
377
+ const [openedFor, setOpenedFor] = useState(id);
378
+ if (openedFor !== id) {
379
+ setOpenedFor(id);
380
+ setReadWhenOpened(null);
381
+ }
382
+ const { refetch: refetchMembers } = members;
383
+ const firstId = useRef(id);
384
+ useEffect(() => {
385
+ if (firstId.current === id) return;
386
+ firstId.current = id;
387
+ if (enabled) void refetchMembers();
388
+ }, [id, enabled, refetchMembers]);
371
389
 
372
390
  const merge = useCallback(
373
391
  (incoming: ChatMessage[], hasEarlierNow?: boolean) =>
@@ -402,8 +420,11 @@ export function useConversation(conversationId: string | null | undefined, opts:
402
420
 
403
421
  const [activity, setActivity] = useState<ChatActivity[]>([]);
404
422
  const channel = useRef<ConversationChannel | null>(null);
423
+ // Whether the live channel is joined: null until the client first says, false when it dropped.
424
+ const [live, setLive] = useState<boolean | null>(null);
405
425
  useEffect(() => {
406
426
  if (!enabled) return;
427
+ setLive(null);
407
428
  const fetchOne = async (messageId: string) => {
408
429
  const m = await client.message(messageId);
409
430
  if (!m) return;
@@ -414,11 +435,21 @@ export function useConversation(conversationId: string | null | undefined, opts:
414
435
  if (root) merge([root]);
415
436
  }
416
437
  };
438
+ let readRefetch: ReturnType<typeof setTimeout> | null = null;
417
439
  channel.current = client.subscribeConversation(id, userId, {
418
440
  onSignal: (s) => {
419
441
  if (s.type === "message") void fetchOne(s.id);
420
442
  else if (s.type === "reaction") void fetchOne(s.messageId);
421
- else if (s.type === "members") {
443
+ else if (s.type === "read") {
444
+ // Read receipts: a cue to read the members again, never the read place itself (a payload
445
+ // is only as good as whoever sent it). Coalesced, so a burst of reads is one fetch.
446
+ if (readRefetch === null) {
447
+ readRefetch = setTimeout(() => {
448
+ readRefetch = null;
449
+ void queryClient.invalidateQueries({ queryKey: chatKeys.members(id) });
450
+ }, READ_REFETCH_MS);
451
+ }
452
+ } else if (s.type === "members") {
422
453
  void queryClient.invalidateQueries({ queryKey: chatKeys.members(id) });
423
454
  void queryClient.invalidateQueries({ queryKey: chatKeys.role(id) });
424
455
  } else if (s.type === "conversation") {
@@ -429,9 +460,15 @@ export function useConversation(conversationId: string | null | undefined, opts:
429
460
  }
430
461
  },
431
462
  onActivity: (a) => setActivity((prev) => currentActivity([...prev, a])),
432
- onJoin: () => void catchUp().catch(() => undefined),
463
+ // Every join: what was missed while the channel was down, messages and read places both.
464
+ onJoin: () => {
465
+ void catchUp().catch(() => undefined);
466
+ void queryClient.invalidateQueries({ queryKey: chatKeys.members(id) });
467
+ },
468
+ onLive: setLive,
433
469
  });
434
470
  return () => {
471
+ if (readRefetch) clearTimeout(readRefetch);
435
472
  channel.current?.unsubscribe();
436
473
  channel.current = null;
437
474
  };
@@ -482,6 +519,13 @@ export function useConversation(conversationId: string | null | undefined, opts:
482
519
  [queryClient, id],
483
520
  );
484
521
 
522
+ const { refetch: refetchMessages } = messages;
523
+ const { refetch: refetchConversationRow } = conversation;
524
+ const reload = useCallback(
525
+ () => Promise.all([refetchConversationRow(), refetchMessages()]).then(() => undefined),
526
+ [refetchConversationRow, refetchMessages],
527
+ );
528
+
485
529
  const loadEarlier = useCallback(async () => {
486
530
  const first = list[0];
487
531
  if (!first || loadingEarlier) return;
@@ -575,6 +619,8 @@ export function useConversation(conversationId: string | null | undefined, opts:
575
619
  loadUntil,
576
620
  /** Where to draw the "New" line, from what you had read when it opened. */
577
621
  firstUnreadId: readWhenOpened === null ? null : firstUnreadId(list, readWhenOpened, userId),
622
+ /** Whether `firstUnreadId` is known yet (your read place as of this opening has been fetched). */
623
+ firstUnreadKnown: readWhenOpened !== null,
578
624
  activity: currentActivity(activity),
579
625
  signalTyping,
580
626
  signalRecording,
@@ -585,6 +631,10 @@ export function useConversation(conversationId: string | null | undefined, opts:
585
631
  retry: outbox.retry,
586
632
  discard: outbox.discard,
587
633
  refetch: catchUp,
634
+ /** The conversation and its first page again, after either failed (a Retry on the thread's error row). */
635
+ reload,
636
+ /** The live channel: true once joined, false when it dropped (errored, timed out, closed), null until the client says. */
637
+ live,
588
638
  };
589
639
  }
590
640
 
@@ -624,6 +674,14 @@ export function useMessageActions() {
624
674
  }, [client, queryClient]);
625
675
  }
626
676
 
677
+ /**
678
+ * What the read hooks return while there is nothing yet: one frozen object (and array) for every
679
+ * caller, so a row's memo holds across renders instead of seeing a fresh `{}` each time.
680
+ */
681
+ const NO_PEOPLE: Record<string, ChatPerson> = Object.freeze({}) as Record<string, ChatPerson>;
682
+ const NO_URLS: Record<string, string> = Object.freeze({}) as Record<string, string>;
683
+ const NO_PINS: string[] = Object.freeze([]) as unknown as string[];
684
+
627
685
  /**
628
686
  * Names and avatars for these people, from the provider's `loadPeople`, fetched as one
629
687
  * batch per set of ids and cached. Unknown ids are left out.
@@ -637,7 +695,7 @@ export function usePeople(userIds: (string | null | undefined)[]): Record<string
637
695
  queryFn: () => loadPeople!(ids),
638
696
  enabled: Boolean(loadPeople) && ids.length > 0,
639
697
  staleTime: 5 * 60_000,
640
- }).data ?? {}
698
+ }).data ?? NO_PEOPLE
641
699
  );
642
700
  }
643
701
 
@@ -651,16 +709,25 @@ export function usePerson(userId: string | null | undefined): ChatPerson | null
651
709
  export function usePins(conversationId: string | null | undefined): string[] {
652
710
  const { client } = useChat();
653
711
  return (
654
- useQuery({ queryKey: chatKeys.pins(conversationId ?? ""), queryFn: () => client.pins(conversationId!), enabled: Boolean(conversationId) }).data ?? []
712
+ useQuery({ queryKey: chatKeys.pins(conversationId ?? ""), queryFn: () => client.pins(conversationId!), enabled: Boolean(conversationId) }).data ?? NO_PINS
655
713
  );
656
714
  }
657
715
 
658
- /** Signed links for files (cached by the client until shortly before they expire). */
716
+ /**
717
+ * Signed links for files (cached by the client until shortly before they expire). While a new set
718
+ * of paths loads (a photo arrives), the links already signed stay: the photos on screen don't blank.
719
+ */
659
720
  export function useFileUrls(paths: (string | null | undefined)[]): Record<string, string> {
660
721
  const { client } = useChat();
661
722
  const list = useMemo(() => [...new Set(paths.filter((p): p is string => Boolean(p)))], [paths]);
662
723
  return (
663
- useQuery({ queryKey: chatKeys.files(list), queryFn: () => client.fileUrls(list), enabled: list.length > 0, staleTime: 50 * 60_000 }).data ?? {}
724
+ useQuery({
725
+ queryKey: chatKeys.files(list),
726
+ queryFn: () => client.fileUrls(list),
727
+ enabled: list.length > 0,
728
+ staleTime: 50 * 60_000,
729
+ placeholderData: keepPreviousData,
730
+ }).data ?? NO_URLS
664
731
  );
665
732
  }
666
733
 
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/core/availability.ts","../src/core/media.ts","../src/core/client.ts","../src/core/transfer.ts"],"names":["rows"],"mappings":";AASO,IAAM,QAAA,GAA+B,CAAC,KAAA,EAAO,KAAA,EAAO,OAAO,KAAA,EAAO,KAAA,EAAO,OAAO,KAAK;AAE5F,IAAM,KAAA,GAAiC,EAAE,GAAA,EAAK,KAAA,EAAO,KAAK,KAAA,EAAO,GAAA,EAAK,KAAA,EAAO,GAAA,EAAK,OAAO,GAAA,EAAK,KAAA,EAAO,GAAA,EAAK,KAAA,EAAO,KAAK,KAAA,EAAM;AAGrH,SAAS,UAAU,IAAA,EAA8B;AACtD,EAAA,IAAI,OAAO,IAAA,KAAS,QAAA,EAAU,OAAO,IAAA;AACrC,EAAA,MAAM,CAAA,GAAI,qBAAA,CAAsB,IAAA,CAAK,IAAA,CAAK,MAAM,CAAA;AAChD,EAAA,IAAI,CAAC,GAAG,OAAO,IAAA;AACf,EAAA,MAAM,CAAA,GAAI,MAAA,CA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AS,CAAA;AAAA,IAClB,CAAA;AACA,IAAA,IAAA,CAAK,QAAQ,gBAAA,CAAiB,OAAA,EAAS,SAAS,EAAE,IAAA,EAAM,MAAM,CAAA;AAC9D,IAAA,GAAA,CAAI,KAAK,IAAI,CAAA;AAAA,EACf,CAAC,CAAA;AACH","file":"chunk-5XYDVUPS.js","sourcesContent":["/**\n * @feat:chat\n * Availability, the same on every platform: is someone inside their working hours (read in\n * their own time zone), are they away, and the one line a thread shows about it (\"Mark\n * replies Mon–Fri, 9–5 (Eastern)\", \"Away until Monday: Back Monday\"). Pure: `now` is passed\n * in, and time zones come from Intl.\n */\nimport type { ChatAvailability, Weekday, WorkingHours } from \"./types\";\n\nexport const WEEKDAYS: readonly Weekday[] = [\"mon\", \"tue\", \"wed\", \"thu\", \"fri\", \"sat\", \"sun\"];\n\nconst SHORT: Record<Weekday, string> = { mon: \"Mon\", tue: \"Tue\", wed: \"Wed\", thu: \"Thu\", fri: \"Fri\", sat: \"Sat\", sun: \"Sun\" };\n\n/** \"09:30\" → 570; a bad value (anything but such a string) → null. \"24:00\" is allowed as the end of a day. */\nexport function minutesOf(hhmm: unknown): number | null {\n if (typeof hhmm !== \"string\") return null;\n const m = /^(\\d{1,2}):(\\d{2})$/.exec(hhmm.trim());\n if (!m) return null;\n const h = Number(m[1]);\n const min = Number(m[2]);\n if (h > 24 || min > 59 || (h === 24 && min > 0)) return null;\n return h * 60 + min;\n}\n\n/** At most this many ranges a day, as the database allows. */\nexport const MAX_RANGES_PER_DAY = 4;\n\n/**\n * Working hours as they may safely be read: only mon..sun, each an array of `[\"HH:MM\", \"HH:MM\"]`\n * string pairs (at most four a day); every other day, range or value is dropped. Null when\n * nothing is left. Hours come from other people, so they are never trusted as typed.\n */\nexport function normalizeHours(raw: unknown): WorkingHours | null {\n if (!raw || typeof raw !== \"object\" || Array.isArray(raw)) return null;\n const src = raw as Record<string, unknown>;\n const out: WorkingHours = {};\n let any = false;\n for (const day of WEEKDAYS) {\n if (!Object.prototype.hasOwnProperty.call(src, day)) continue;\n const ranges = src[day];\n if (!Array.isArray(ranges)) continue;\n const kept: [string, string][] = [];\n for (const r of ranges) {\n if (!Array.isArray(r) || r.length !== 2) continue;\n const [from, to] = r as unknown[];\n if (typeof from !== \"string\" || typeof to !== \"string\" || minutesOf(from) == null || minutesOf(to) == null) continue;\n kept.push([from, to]);\n if (kept.length >= MAX_RANGES_PER_DAY) break;\n }\n if (kept.length) {\n out[day] = kept;\n any = true;\n }\n }\n return any ? out : null;\n}\n\n/** The weekday and minute of the day at `now` in `timeZone` (the device's zone when null or unknown). */\nexport function localClock(now: Date, timeZone?: string | null): { day: Weekday; minutes: number } {\n let parts: Intl.DateTimeFormatPart[];\n try {\n parts = new Intl.DateTimeFormat(\"en-US\", {\n timeZone: timeZone || undefined,\n weekday: \"short\",\n hour: \"2-digit\",\n minute: \"2-digit\",\n hourCycle: \"h23\",\n }).formatToParts(now);\n } catch {\n parts = new Intl.DateTimeFormat(\"en-US\", { weekday: \"short\", hour: \"2-digit\", minute: \"2-digit\", hourCycle: \"h23\" }).formatToParts(now);\n }\n const get = (t: string) => parts.find((p) => p.type === t)?.value ?? \"\";\n const day = get(\"weekday\").slice(0, 3).toLowerCase() as Weekday;\n const hour = Number(get(\"hour\")) % 24;\n return { day: WEEKDAYS.includes(day) ? day : \"mon\", minutes: hour * 60 + Number(get(\"minute\")) };\n}\n\n/**\n * Is `now` inside these working hours, read in `timeZone`? No hours set means always.\n * A range whose end is at or before its start runs overnight into the next day\n * (`fri: [[\"22:00\",\"02:00\"]]` covers Friday 22:00 to Saturday 02:00).\n */\nexport function isWithinWorkingHours(raw: WorkingHours | null | undefined, timeZone: string | null | undefined, now: Date = new Date()): boolean {\n const hours = normalizeHours(raw);\n if (!hours) return true;\n const { day, minutes } = localClock(now, timeZone);\n const yesterday = WEEKDAYS[(WEEKDAYS.indexOf(day) + 6) % 7]!;\n for (const [from, to] of hours[day] ?? []) {\n const a = minutesOf(from);\n const b = minutesOf(to);\n if (a == null || b == null) continue;\n if (b > a ? minutes >= a && minutes < b : minutes >= a) return true;\n }\n for (const [from, to] of hours[yesterday] ?? []) {\n const a = minutesOf(from);\n const b = minutesOf(to);\n if (a == null || b == null) continue;\n if (b <= a && minutes < b) return true;\n }\n return false;\n}\n\n/** Away now: an away message with no end date, or an end date still ahead. */\nexport function isAway(a: Pick<ChatAvailability, \"awayMessage\" | \"awayUntil\"> | null | undefined, now: Date = new Date()): boolean {\n if (!a) return false;\n if (a.awayUntil) return Date.parse(a.awayUntil) > now.getTime();\n return Boolean(a.awayMessage?.trim());\n}\n\n/** \"9\", \"9:30\", \"5\" (12-hour, no am/pm: the range reads \"9–5\"). */\nfunction clock(hhmm: string): string {\n const total = minutesOf(hhmm) ?? 0;\n const h = Math.floor(total / 60) % 24;\n const m = total % 60;\n const h12 = h % 12 === 0 ? 12 : h % 12;\n return m ? `${h12}:${String(m).padStart(2, \"0\")}` : String(h12);\n}\n\n/** \"Mon–Fri, 9–5\", \"Mon–Thu, 9–5; Fri, 9–1\". Days with the same hours are grouped. Empty when none. */\nexport function hoursSummary(raw: WorkingHours | null | undefined): string {\n const hours = normalizeHours(raw);\n if (!hours) return \"\";\n const key = (d: Weekday) => (hours[d] ?? []).map(([a, b]) => `${clock(a)}–${clock(b)}`).join(\", \");\n const runs: { from: Weekday; to: Weekday; text: string }[] = [];\n for (const d of WEEKDAYS) {\n const text = key(d);\n if (!text) continue;\n const last = runs[runs.length - 1];\n if (last && last.text === text && WEEKDAYS.indexOf(last.to) === WEEKDAYS.indexOf(d) - 1) last.to = d;\n else runs.push({ from: d, to: d, text });\n }\n return runs\n .map((r) => {\n const days = r.from === r.to ? SHORT[r.from] : WEEKDAYS.indexOf(r.to) - WEEKDAYS.indexOf(r.from) === 1 ? `${SHORT[r.from]}, ${SHORT[r.to]}` : `${SHORT[r.from]}–${SHORT[r.to]}`;\n return `${days}, ${r.text}`;\n })\n .join(\"; \");\n}\n\n/** \"Eastern\" for America/New_York (the zone's generic name, less \" Time\"); the city when Intl has no name. */\nexport function timeZoneLabel(timeZone: string | null | undefined, locale = \"en-US\"): string {\n if (!timeZone) return \"\";\n try {\n const name = new Intl.DateTimeFormat(locale, { timeZone, timeZoneName: \"longGeneric\" })\n .formatToParts(new Date())\n .find((p) => p.type === \"timeZoneName\")?.value;\n if (name && !/^GMT|^UTC/.test(name)) return name.replace(/ Time$/, \"\");\n } catch {\n // an unknown zone: fall through\n }\n return (timeZone.split(\"/\").pop() ?? timeZone).replace(/_/g, \" \");\n}\n\n/** \"3:00 PM\" today, \"Monday\" within the week, else \"12 Mar\". */\nexport function untilLabel(iso: string, now: Date = new Date(), locale?: string, timeZone?: string | null): string {\n const d = new Date(iso);\n if (!Number.isFinite(d.getTime())) return \"later\";\n try {\n return untilIn(d, now, locale, timeZone || undefined);\n } catch {\n // An unknown zone or locale: the device's.\n return untilIn(d, now, undefined, undefined);\n }\n}\n\nfunction untilIn(d: Date, now: Date, locale: string | undefined, tz: string | undefined): string {\n const dayKey = (x: Date) => new Intl.DateTimeFormat(\"en-CA\", { timeZone: tz, year: \"numeric\", month: \"2-digit\", day: \"2-digit\" }).format(x);\n if (dayKey(d) === dayKey(now)) return d.toLocaleTimeString(locale, { hour: \"numeric\", minute: \"2-digit\", timeZone: tz });\n const days = (d.getTime() - now.getTime()) / 86_400_000;\n if (days < 7) return d.toLocaleDateString(locale, { weekday: \"long\", timeZone: tz });\n return d.toLocaleDateString(locale, { day: \"numeric\", month: \"short\", timeZone: tz });\n}\n\nexport interface AwayLineOptions {\n now?: Date;\n locale?: string;\n /** Show the hours line even inside working hours (a profile, not a banner). */\n always?: boolean;\n}\n\n/**\n * The line a thread shows about someone, or null when they are around:\n * - away with a date: \"Away until Monday: Back Monday\" (the away message after the colon);\n * - away with no date: \"Mark is away: On a retreat\";\n * - outside working hours: \"Mark replies Mon–Fri, 9–5 (Eastern)\".\n */\nexport function awayLine(a: ChatAvailability | null | undefined, name: string, opts: AwayLineOptions = {}): string | null {\n if (!a) return null;\n const now = opts.now ?? new Date();\n const message = a.awayMessage?.trim();\n if (isAway(a, now)) {\n if (a.awayUntil) return `Away until ${untilLabel(a.awayUntil, now, opts.locale, a.timeZone)}${message ? `: ${message}` : \"\"}`;\n return `${name} is away${message ? `: ${message}` : \"\"}`;\n }\n const summary = hoursSummary(a.hours);\n if (!summary) return null;\n if (!opts.always && isWithinWorkingHours(a.hours, a.timeZone, now)) return null;\n const zone = timeZoneLabel(a.timeZone, opts.locale);\n return `${name} replies ${summary}${zone ? ` (${zone})` : \"\"}`;\n}\n\n/** \"Sam\", \"Sam and Lee\", \"Sam, Lee and 3 others\": at most two names. */\nexport function namesLine(names: string[]): string {\n if (names.length <= 1) return names[0] ?? \"\";\n if (names.length === 2) return `${names[0]} and ${names[1]}`;\n const rest = names.length - 2;\n return `${names[0]}, ${names[1]} and ${rest === 1 ? \"1 other\" : `${rest} others`}`;\n}\n\n/**\n * The line for several people (a group's members): one person's full `awayLine`, or for more\n * \"Sam and Lee are away\", \"Sam, Lee and 2 others are outside their hours\", or \"… are away or\n * outside their hours\" when it's a mix. Null when everyone is around.\n */\nexport function awaySummary(people: { availability: ChatAvailability | null | undefined; name: string }[], opts: AwayLineOptions = {}): string | null {\n const now = opts.now ?? new Date();\n const out = people.filter((p) => awayLine(p.availability, p.name, { ...opts, now, always: false }) !== null);\n if (out.length === 0) return null;\n if (out.length === 1) return awayLine(out[0]!.availability, out[0]!.name, { ...opts, now, always: false });\n const away = out.filter((p) => isAway(p.availability, now)).length;\n const what = away === out.length ? \"away\" : away === 0 ? \"outside their hours\" : \"away or outside their hours\";\n return `${namesLine(out.map((p) => p.name))} are ${what}`;\n}\n","/**\n * @feat:chat\n * Media rules shared by every platform: which files may be sent (the same list\n * migration 0001 checks), what kind an upload becomes, the default limits, and\n * the waveform a voice note carries so its bubble draws before the audio loads.\n */\nimport type { AttachmentKind } from \"./types\";\n\n/**\n * A random UUID (v4): `crypto.randomUUID` where the platform has it (some React Native\n * runtimes don't), else `crypto.getRandomValues`, else Math.random as a last resort. Ids\n * only need to be unique per sender: the server checks (sender, client_id).\n */\nexport function randomId(): string {\n const c = (globalThis as { crypto?: { randomUUID?: () => string; getRandomValues?: (a: Uint8Array) => Uint8Array } }).crypto;\n if (c?.randomUUID) return c.randomUUID();\n const b = new Uint8Array(16);\n if (c?.getRandomValues) c.getRandomValues(b);\n else for (let i = 0; i < 16; i++) b[i] = Math.floor(Math.random() * 256);\n b[6] = (b[6]! & 0x0f) | 0x40;\n b[8] = (b[8]! & 0x3f) | 0x80;\n const h = [...b].map((x) => x.toString(16).padStart(2, \"0\")).join(\"\");\n return `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20)}`;\n}\n\n/** Mirrors genesis_chat.allowed_extension. Never SVG or HTML, which a browser runs as a page. */\nexport const ALLOWED_EXTENSIONS = [\n \"png\", \"jpg\", \"jpeg\", \"webp\", \"gif\", \"heic\", \"heif\",\n \"m4a\", \"aac\", \"mp3\", \"ogg\", \"oga\", \"opus\", \"weba\", \"webm\",\n \"mp4\", \"mov\", \"pdf\", \"txt\", \"csv\", \"docx\", \"xlsx\", \"pptx\",\n] as const;\n\nconst MIME_EXTENSIONS: Record<string, string> = {\n \"image/png\": \"png\",\n \"image/jpeg\": \"jpg\",\n \"image/webp\": \"webp\",\n \"image/gif\": \"gif\",\n \"image/heic\": \"heic\",\n \"image/heif\": \"heif\",\n \"audio/mp4\": \"m4a\",\n \"audio/x-m4a\": \"m4a\",\n \"audio/aac\": \"aac\",\n \"audio/mpeg\": \"mp3\",\n \"audio/ogg\": \"ogg\",\n \"audio/webm\": \"webm\",\n \"video/mp4\": \"mp4\",\n \"video/quicktime\": \"mov\",\n \"video/webm\": \"webm\",\n \"application/pdf\": \"pdf\",\n \"text/plain\": \"txt\",\n \"text/csv\": \"csv\",\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\": \"docx\",\n \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\": \"xlsx\",\n \"application/vnd.openxmlformats-officedocument.presentationml.presentation\": \"pptx\",\n};\n\n/** The extension a file is stored under: from its content type, else its name. */\nexport function fileExtension(name: string, contentType?: string): string {\n const base = (contentType ?? \"\").split(\";\")[0]!.trim().toLowerCase();\n const fromType = MIME_EXTENSIONS[base];\n if (fromType) return fromType;\n const dot = name.lastIndexOf(\".\");\n return dot >= 0 ? name.slice(dot + 1).toLowerCase() : \"\";\n}\n\nexport function isAllowedExtension(ext: string): boolean {\n return (ALLOWED_EXTENSIONS as readonly string[]).includes(ext.toLowerCase());\n}\n\n/** What an upload becomes in a message. */\nexport function attachmentKindFor(contentType: string, opts: { recordedVoice?: boolean } = {}): AttachmentKind {\n const t = contentType.toLowerCase();\n if (opts.recordedVoice || t.startsWith(\"audio/\")) return \"voice\";\n if (t.startsWith(\"image/\")) return \"image\";\n if (t.startsWith(\"video/\")) return \"video\";\n return \"file\";\n}\n\n/** Default limits (decision 5): an app may lower them, not raise them past the bucket's 100 MB. */\nexport const CHAT_LIMITS = {\n /** Voice notes and videos, for members. */\n recordingMs: 5 * 60_000,\n /** For owners, admins and observers (coaches, staff). */\n staffRecordingMs: 10 * 60_000,\n fileBytes: 50 * 1024 * 1024,\n videoBytes: 100 * 1024 * 1024,\n attachmentsPerMessage: 20,\n bodyChars: 10_000,\n} as const;\n\n/** The longest recording this role may make. */\nexport function recordingLimitMs(role: string | null | undefined): number {\n return role === \"owner\" || role === \"admin\" || role === \"observer\" ? CHAT_LIMITS.staffRecordingMs : CHAT_LIMITS.recordingMs;\n}\n\n/**\n * Peaks for a waveform: `count` values 0–100 from raw samples (-1…1), the loudest\n * in each bucket, scaled so the loudest bucket is 100. Quiet recordings still show\n * a shape; silence shows a flat line.\n */\nexport function waveformPeaks(samples: ArrayLike<number>, count = 48): number[] {\n const n = Math.max(1, Math.min(128, Math.floor(count)));\n if (samples.length === 0) return new Array(n).fill(0);\n const size = samples.length / n;\n const raw: number[] = [];\n for (let i = 0; i < n; i++) {\n let peak = 0;\n const end = Math.min(samples.length, Math.floor((i + 1) * size));\n for (let j = Math.floor(i * size); j < end; j++) {\n const v = Math.abs(samples[j]!);\n if (v > peak) peak = v;\n }\n raw.push(peak);\n }\n const max = Math.max(...raw);\n if (max < 0.01) return raw.map(() => 0);\n return raw.map((v) => Math.round((v / max) * 100));\n}\n\n/**\n * Peaks from a level meter read while recording (expo-audio's `metering`, in dB,\n * about -160…0): resampled to `count` values 0–100.\n */\nexport function waveformFromMetering(levelsDb: number[], count = 48): number[] {\n const linear = levelsDb.map((db) => (Number.isFinite(db) ? Math.pow(10, Math.max(-60, Math.min(0, db)) / 20) : 0));\n return waveformPeaks(linear, count);\n}\n\n/** 0:42, 1:05:09. */\nexport function formatDuration(ms: number | null | undefined): string {\n const total = Math.max(0, Math.round((ms ?? 0) / 1000));\n const h = Math.floor(total / 3600);\n const m = Math.floor((total % 3600) / 60);\n const s = total % 60;\n return h > 0 ? `${h}:${String(m).padStart(2, \"0\")}:${String(s).padStart(2, \"0\")}` : `${m}:${String(s).padStart(2, \"0\")}`;\n}\n\n/** Playback speeds offered for voice and video (free for everyone, decision 5). */\nexport const PLAYBACK_RATES = [1, 1.5, 2] as const;\n\nexport function nextPlaybackRate(rate: number): number {\n const i = PLAYBACK_RATES.indexOf(rate as (typeof PLAYBACK_RATES)[number]);\n return PLAYBACK_RATES[(i + 1) % PLAYBACK_RATES.length]!;\n}\n","/**\n * @feat:chat\n * The chat client: the app's own Supabase (migrations 0001 and 0002, the genesis_chat\n * schema) under row level security. Reads are table selects; every write is a\n * genesis_chat function. Live updates are hints on private Realtime topics,\n * after which the client fetches again, so nothing is trusted from the wire.\n */\nimport type { RealtimeChannel, SupabaseClient } from \"@supabase/supabase-js\";\nimport type {\n AttachmentInput,\n AvailabilityInput,\n ChatActivity,\n ChatAttachment,\n ChatAvailability,\n ChatLinkPreview,\n ChatSearchHit,\n ChatTopic,\n ScheduleInput,\n ScheduledMessage,\n TopicInput,\n ChatConversation,\n ChatInboxItem,\n ChatKindRules,\n ChatMember,\n ChatMessage,\n ChatRole,\n ChatSignal,\n SendInput,\n StartConversationOptions,\n} from \"./types\";\nimport { normalizeHours } from \"./availability\";\nimport { fileExtension, isAllowedExtension, randomId } from \"./media\";\nimport { sendBytes, type UploadProgress } from \"./transfer\";\n\n/** Any supabase-js client; the app's generated Database types don't need to list genesis_chat. */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type ChatSupabase = SupabaseClient<any, any, any>;\n\nexport const CHAT_SCHEMA = \"genesis_chat\";\nexport const CHAT_BUCKET = \"genesis-chat\";\n\nexport const conversationTopic = (conversationId: string) => `genesis-chat:conv:${conversationId}`;\nexport const userTopic = (userId: string) => `genesis-chat:user:${userId}`;\n\n/** A refusal from the database, with its SQLSTATE (`42501` not allowed, `22023` bad input, `GS429` too many). */\nexport class ChatError extends Error {\n constructor(\n message: string,\n readonly code: string | undefined,\n readonly operation: string,\n ) {\n super(message);\n this.name = \"ChatError\";\n }\n get forbidden(): boolean {\n return this.code === \"42501\";\n }\n get rateLimited(): boolean {\n return this.code === \"GS429\";\n }\n /** Worth trying again: the network, not the database, said no. */\n get transient(): boolean {\n return this.code === undefined || this.code === \"\" || /^(08|57|53)/.test(this.code) || this.code === \"PGRST000\";\n }\n /**\n * Sending it again won't help: the database refused what was sent (not allowed 42501, bad\n * data 22xxx such as 22023, a conflict 23xxx such as 23505, another refusal 42xxx, or a\n * function's own `raise` P0001). A person may still retry by hand; nothing retries it alone.\n */\n get permanent(): boolean {\n return !this.transient && !this.rateLimited && /^(22|23|42|P0)/.test(this.code ?? \"\");\n }\n}\n\nfunction must<T>(operation: string, result: { data: T | null; error: { message: string; code?: string } | null }): T {\n if (result.error) throw new ChatError(result.error.message, result.error.code, operation);\n return result.data as T;\n}\n\ntype Row = Record<string, unknown>;\nconst str = (v: unknown) => (v == null ? null : String(v));\nconst num = (v: unknown) => (v == null ? null : Number(v));\n\nexport function toAttachment(r: Row): ChatAttachment {\n return {\n id: String(r.id),\n messageId: String(r.message_id),\n position: Number(r.position ?? 0),\n kind: String(r.kind),\n ref: (r.ref as Record<string, unknown>) ?? {},\n provider: (r.provider as ChatAttachment[\"provider\"]) ?? \"storage\",\n path: str(r.path),\n providerId: str(r.provider_id),\n playbackId: str(r.playback_id),\n url: str(r.url),\n status: (r.status as ChatAttachment[\"status\"]) ?? \"ready\",\n name: str(r.name),\n mime: str(r.mime),\n bytes: num(r.bytes),\n width: num(r.width),\n height: num(r.height),\n durationMs: num(r.duration_ms),\n waveform: (r.waveform as number[] | null) ?? null,\n posterPath: str(r.poster_path),\n thumbhash: str(r.thumbhash),\n transcript: str(r.transcript),\n transcriptStatus: (r.transcript_status as ChatAttachment[\"transcriptStatus\"]) ?? null,\n };\n}\n\nexport function toMessage(r: Row): ChatMessage {\n const attachments = ((r.attachments as Row[] | undefined) ?? []).map(toAttachment).sort((a, b) => a.position - b.position);\n const reactions = ((r.reactions as Row[] | undefined) ?? []).map((x) => ({ emoji: String(x.emoji), userId: String(x.user_id) }));\n return {\n id: String(r.id),\n conversationId: String(r.conversation_id),\n seq: Number(r.seq),\n clientId: String(r.client_id),\n senderId: str(r.sender_id),\n senderRole: r.sender_role as ChatMessage[\"senderRole\"],\n kind: (r.kind as ChatMessage[\"kind\"]) ?? \"text\",\n body: String(r.body ?? \"\"),\n mentions: (r.mentions as string[]) ?? [],\n replyToId: str(r.reply_to_id),\n threadRootId: str(r.thread_root_id),\n threadCount: Number(r.thread_count ?? 0),\n threadLastAt: str(r.thread_last_at),\n topic: str(r.topic),\n visibility: (r.visibility as ChatMessage[\"visibility\"]) ?? \"everyone\",\n silent: Boolean(r.silent),\n meta: (r.meta as Record<string, unknown>) ?? {},\n createdAt: String(r.created_at),\n editedAt: str(r.edited_at),\n deletedAt: str(r.deleted_at),\n moderation: r.moderation === \"hidden\" || r.moderation === \"flagged\" ? r.moderation : null,\n attachments,\n reactions,\n };\n}\n\nfunction toConversation(r: Row): ChatConversation {\n return {\n id: String(r.id),\n kind: String(r.kind),\n title: str(r.title),\n subjectType: str(r.subject_type),\n subjectId: str(r.subject_id),\n tenantId: str(r.tenant_id),\n settings: (r.settings as ChatConversation[\"settings\"]) ?? {},\n status: (r.status as ChatConversation[\"status\"]) ?? null,\n assigneeId: str(r.assignee_id),\n lastSeq: Number(r.last_seq ?? 0),\n lastMessageAt: str(r.last_message_at),\n createdAt: String(r.created_at),\n archivedAt: str(r.archived_at),\n };\n}\n\nfunction toInboxItem(r: Row): ChatInboxItem {\n const last = r.last_message as Row | null;\n return {\n conversationId: String(r.conversation_id),\n kind: String(r.kind),\n title: str(r.title),\n subjectType: str(r.subject_type),\n subjectId: str(r.subject_id),\n status: (r.status as ChatInboxItem[\"status\"]) ?? null,\n role: r.role as ChatRole,\n otherUserId: str(r.other_user_id),\n memberCount: Number(r.member_count ?? 0),\n lastSeq: Number(r.last_seq ?? 0),\n lastReadSeq: Number(r.last_read_seq ?? 0),\n unread: Number(r.unread ?? 0),\n mentioned: Boolean(r.mentioned),\n muted: Boolean(r.muted),\n pinned: Boolean(r.pinned),\n archived: Boolean(r.archived),\n lastMessageAt: str(r.last_message_at),\n lastMessage: last\n ? {\n id: String(last.id),\n seq: Number(last.seq),\n senderId: str(last.sender_id),\n kind: (last.kind as \"text\" | \"system\") ?? \"text\",\n body: String(last.body ?? \"\"),\n deleted: Boolean(last.deleted),\n createdAt: String(last.created_at),\n attachment: (last.attachment as string | null) ?? null,\n }\n : null,\n };\n}\n\nexport function toTopic(r: Row): ChatTopic {\n return {\n conversationId: String(r.conversation_id),\n topic: String(r.topic),\n title: String(r.title ?? r.topic),\n position: Number(r.position ?? 0),\n closedAt: str(r.closed_at),\n createdBy: str(r.created_by),\n createdAt: String(r.created_at),\n };\n}\n\nfunction fromAttachmentArg(a: Row): AttachmentInput {\n const out: AttachmentInput = { kind: String(a.kind ?? \"file\") };\n const map: [keyof AttachmentInput, string][] = [\n [\"path\", \"path\"], [\"provider\", \"provider\"], [\"providerId\", \"provider_id\"], [\"url\", \"url\"], [\"ref\", \"ref\"],\n [\"status\", \"status\"], [\"name\", \"name\"], [\"mime\", \"mime\"], [\"bytes\", \"bytes\"], [\"width\", \"width\"],\n [\"height\", \"height\"], [\"durationMs\", \"duration_ms\"], [\"waveform\", \"waveform\"], [\"posterPath\", \"poster_path\"], [\"thumbhash\", \"thumbhash\"],\n ];\n for (const [k, col] of map) if (a[col] != null) (out as unknown as Record<string, unknown>)[k] = a[col];\n return out;\n}\n\nexport function toScheduled(r: Row): ScheduledMessage {\n const sentMessageId = str(r.sent_message_id);\n const cancelledAt = str(r.cancelled_at);\n const error = str(r.error);\n return {\n id: String(r.id),\n conversationId: String(r.conversation_id),\n clientId: String(r.client_id),\n body: String(r.body ?? \"\"),\n attachments: ((r.attachments as Row[] | null) ?? []).map(fromAttachmentArg),\n replyToId: str(r.reply_to_id),\n topic: str(r.topic),\n mentions: (r.mentions as string[] | null) ?? [],\n silent: Boolean(r.silent),\n sendAt: String(r.send_at),\n sentMessageId,\n cancelledAt,\n error,\n createdAt: String(r.created_at),\n status: sentMessageId ? \"sent\" : cancelledAt ? \"cancelled\" : error ? \"failed\" : \"scheduled\",\n };\n}\n\nexport function toAvailability(r: Row): ChatAvailability {\n return {\n userId: String(r.user_id),\n awayMessage: str(r.away_message),\n awayUntil: str(r.away_until),\n timeZone: str(r.time_zone),\n // Someone else's hours: only well-formed days and ranges reach the renderers.\n hours: normalizeHours(r.hours),\n };\n}\n\nexport function toSearchHit(r: Row): ChatSearchHit {\n return {\n messageId: String(r.message_id),\n conversationId: String(r.conversation_id),\n seq: Number(r.seq),\n senderId: str(r.sender_id),\n createdAt: String(r.created_at),\n snippet: String(r.snippet ?? \"\"),\n inTranscript: Boolean(r.in_transcript),\n threadRootId: str(r.thread_root_id),\n };\n}\n\nexport function toLinkPreview(r: Row): ChatLinkPreview {\n const image = str(r.image_url);\n return {\n url: String(r.url),\n status: (r.status as ChatLinkPreview[\"status\"]) ?? \"ok\",\n title: str(r.title),\n description: str(r.description),\n imageUrl: image && /^https:\\/\\//i.test(image) ? image : null,\n siteName: str(r.site_name),\n fetchedAt: String(r.fetched_at),\n };\n}\n\nconst MESSAGE_COLUMNS = \"*, attachments(*), reactions(emoji, user_id)\";\n\nexport interface MessagePage {\n messages: ChatMessage[];\n /** More, older messages exist before the first one. */\n hasEarlier: boolean;\n}\n\nexport interface ChatClientOptions {\n /** Signed file links live this long (seconds). Default an hour. */\n signedUrlSeconds?: number;\n}\n\nexport interface Subscription {\n unsubscribe(): void;\n}\n\nexport interface ConversationHandlers {\n onSignal: (s: ChatSignal) => void;\n onActivity?: (a: ChatActivity) => void;\n /** Every join, the first included: catch up on what arrived before the channel was live. */\n onJoin?: () => void;\n /** Re-joins only. Prefer `onJoin`. */\n onReconnect?: () => void;\n}\n\nexport interface ConversationChannel extends Subscription {\n /** Tell the others you are typing or recording (throttle to once every 3 seconds). */\n signal(activity: ChatActivity[\"activity\"]): void;\n}\n\nexport function createChatClient(supabase: ChatSupabase, options: ChatClientOptions = {}) {\n const db = () => supabase.schema(CHAT_SCHEMA);\n const signedUrlSeconds = options.signedUrlSeconds ?? 3600;\n const signedCache = new Map<string, { url: string; until: number }>();\n\n /**\n * Private Realtime channels authorise with the signed-in user's token; set it before\n * joining (supabase-js doesn't for a channel joined before the session loads), or the\n * join is refused and no hint ever arrives. A refusal to set it still joins and retries.\n */\n const unsubscribed = new WeakSet<RealtimeChannel>();\n function join(channel: RealtimeChannel, onStatus?: (status: string) => void) {\n const realtime = (supabase as unknown as { realtime?: { setAuth?: (token?: string | null) => Promise<void> | void } }).realtime;\n void Promise.resolve(realtime?.setAuth?.())\n .catch(() => undefined)\n .then(() => {\n if (!unsubscribed.has(channel)) channel.subscribe(onStatus);\n });\n return () => {\n unsubscribed.add(channel);\n void supabase.removeChannel(channel);\n };\n }\n\n async function rpc<T>(fn: string, args: Record<string, unknown>): Promise<T> {\n return must<T>(fn, await db().rpc(fn, args));\n }\n\n return {\n supabase,\n\n /** Your conversations: one `kind`, several `kinds`, or all but `excludeKinds` (e.g. Messages without `support`). */\n async inbox(\n opts: { kind?: string; kinds?: string[]; excludeKinds?: string[]; archived?: boolean; limit?: number; before?: string } = {},\n ): Promise<ChatInboxItem[]> {\n const rows = await rpc<Row[]>(\"inbox\", {\n p_kind: opts.kind ?? null,\n p_archived: opts.archived ?? false,\n p_limit: opts.limit ?? 50,\n p_before: opts.before ?? null,\n ...(opts.kinds?.length ? { p_kinds: opts.kinds } : {}),\n ...(opts.excludeKinds?.length ? { p_exclude_kinds: opts.excludeKinds } : {}),\n });\n return rows.map(toInboxItem);\n },\n\n async observed(kind: string, opts: { status?: string; limit?: number; before?: string } = {}) {\n return rpc<Row[]>(\"observed\", { p_kind: kind, p_status: opts.status ?? null, p_limit: opts.limit ?? 50, p_before: opts.before ?? null });\n },\n\n /** Unread across your conversations (for a badge), leaving out `excludeKinds` to match an inbox that does. */\n async unreadTotal(opts: { excludeKinds?: string[] } = {}): Promise<number> {\n return rpc<number>(\"unread_total\", opts.excludeKinds?.length ? { p_exclude_kinds: opts.excludeKinds } : {});\n },\n\n async conversation(id: string): Promise<ChatConversation | null> {\n const row = must(\"conversation\", await db().from(\"conversations\").select(\"*\").eq(\"id\", id).maybeSingle());\n return row ? toConversation(row as Row) : null;\n },\n\n /** A kind's rules (how many members, who posts, threads), for what the UI offers. */\n async kind(kind: string): Promise<ChatKindRules | null> {\n const row = must(\"kind\", await db().from(\"kinds\").select(\"kind, label, max_members, who_posts, membership, threads, observers_post\").eq(\"kind\", kind).maybeSingle()) as Row | null;\n return row\n ? {\n kind: String(row.kind),\n label: String(row.label),\n maxMembers: row.max_members == null ? null : Number(row.max_members),\n whoPosts: row.who_posts as ChatKindRules[\"whoPosts\"],\n membership: row.membership as ChatKindRules[\"membership\"],\n threads: Boolean(row.threads),\n observersPost: Boolean(row.observers_post),\n }\n : null;\n },\n\n async myRole(id: string): Promise<ChatRole | null> {\n return rpc<ChatRole | null>(\"my_role\", { p_conversation_id: id });\n },\n\n async canPost(id: string): Promise<boolean> {\n return rpc<boolean>(\"can_post\", { p_conversation_id: id });\n },\n\n async members(id: string): Promise<ChatMember[]> {\n const rows = must<Row[]>(\n \"members\",\n await db().from(\"members\").select(\"*\").eq(\"conversation_id\", id).is(\"left_at\", null).neq(\"role\", \"observer\"),\n );\n return rows.map((r) => ({\n conversationId: String(r.conversation_id),\n userId: String(r.user_id),\n role: r.role as ChatRole,\n lastReadSeq: Number(r.last_read_seq ?? 0),\n joinedAt: String(r.joined_at),\n }));\n },\n\n /**\n * A page of messages, oldest first: the latest `limit` (default 50), or those\n * before `beforeSeq`, or (to catch up after a reconnect) those after `afterSeq`.\n * A thread's replies with `threadRootId`; one topic's with `topic`.\n */\n async messages(\n conversationId: string,\n opts: { beforeSeq?: number; afterSeq?: number; limit?: number; threadRootId?: string; topic?: string } = {},\n ): Promise<MessagePage> {\n const limit = Math.min(Math.max(opts.limit ?? 50, 1), 200);\n let q = db().from(\"messages\").select(MESSAGE_COLUMNS).eq(\"conversation_id\", conversationId);\n q = opts.threadRootId ? q.eq(\"thread_root_id\", opts.threadRootId) : q.is(\"thread_root_id\", null);\n if (opts.topic) q = q.eq(\"topic\", opts.topic);\n if (opts.afterSeq != null) {\n const rows = must<Row[]>(\"messages\", await q.gt(\"seq\", opts.afterSeq).order(\"seq\", { ascending: true }).limit(limit));\n return { messages: rows.map(toMessage), hasEarlier: false };\n }\n if (opts.beforeSeq != null) q = q.lt(\"seq\", opts.beforeSeq);\n const rows = must<Row[]>(\"messages\", await q.order(\"seq\", { ascending: false }).limit(limit + 1));\n const hasEarlier = rows.length > limit;\n return { messages: rows.slice(0, limit).map(toMessage).reverse(), hasEarlier };\n },\n\n async message(id: string): Promise<ChatMessage | null> {\n const row = must(\"message\", await db().from(\"messages\").select(MESSAGE_COLUMNS).eq(\"id\", id).maybeSingle());\n return row ? toMessage(row as Row) : null;\n },\n\n async startConversation(kind: string, memberIds: string[], opts: StartConversationOptions = {}) {\n return rpc<string>(\"start_conversation\", {\n p_kind: kind,\n p_member_ids: memberIds,\n p_title: opts.title ?? null,\n p_subject_type: opts.subjectType ?? null,\n p_subject_id: opts.subjectId ?? null,\n // Only when given: the same call still reaches a database before 0004.\n ...(opts.tenantId ? { p_tenant_id: opts.tenantId } : {}),\n });\n },\n\n /** Sends a message. Safe to retry with the same clientId. */\n async send(input: SendInput): Promise<ChatMessage> {\n const row = await rpc<Row>(\"send_message\", {\n p_conversation_id: input.conversationId,\n p_client_id: input.clientId,\n p_body: input.body ?? \"\",\n p_attachments: (input.attachments ?? []).map(attachmentArg),\n p_reply_to_id: input.replyToId ?? null,\n p_thread_root_id: input.threadRootId ?? null,\n p_topic: input.topic ?? null,\n p_mentions: input.mentions ?? [],\n p_visibility: input.visibility ?? \"everyone\",\n p_silent: input.silent ?? false,\n });\n // The function returns the message row; fetch it again for its attachments.\n return (await this.message(String(row.id))) ?? toMessage(row);\n },\n\n async edit(messageId: string, body: string, mentions: string[] = []) {\n return toMessage(await rpc<Row>(\"edit_message\", { p_message_id: messageId, p_body: body, p_mentions: mentions }));\n },\n\n async remove(messageId: string) {\n await rpc(\"delete_message\", { p_message_id: messageId });\n },\n\n async react(messageId: string, emoji: string, on = true) {\n await rpc(\"react\", { p_message_id: messageId, p_emoji: emoji, p_on: on });\n },\n\n async markRead(conversationId: string, seq?: number) {\n return rpc<number>(\"mark_read\", { p_conversation_id: conversationId, p_seq: seq ?? null });\n },\n\n async setMySettings(\n conversationId: string,\n s: { mutedUntil?: string | null; notify?: \"all\" | \"mentions\" | \"none\"; archived?: boolean; pinned?: boolean },\n ) {\n await rpc(\"set_my_settings\", {\n p_conversation_id: conversationId,\n p_muted_until: s.mutedUntil ?? null,\n p_notify: s.notify ?? null,\n p_archived: s.archived ?? null,\n p_pinned: s.pinned ?? null,\n p_clear_mute: s.mutedUntil === null,\n });\n },\n\n async updateConversation(conversationId: string, s: { title?: string; settings?: Record<string, unknown> }) {\n await rpc(\"update_conversation\", { p_conversation_id: conversationId, p_title: s.title ?? null, p_settings: s.settings ?? null });\n },\n\n async addMembers(conversationId: string, userIds: string[]) {\n await rpc(\"add_members\", { p_conversation_id: conversationId, p_user_ids: userIds });\n },\n\n async removeMember(conversationId: string, userId?: string) {\n await rpc(\"remove_member\", { p_conversation_id: conversationId, p_user_id: userId ?? null });\n },\n\n async setStatus(conversationId: string, status: ChatConversation[\"status\"], assigneeId?: string | null) {\n await rpc(\"set_status\", { p_conversation_id: conversationId, p_status: status, p_assignee_id: assigneeId ?? null });\n },\n\n async pin(messageId: string, on = true) {\n await rpc(\"pin_message\", { p_message_id: messageId, p_on: on });\n },\n\n async pins(conversationId: string): Promise<string[]> {\n const rows = must<Row[]>(\"pins\", await db().from(\"pins\").select(\"message_id\").eq(\"conversation_id\", conversationId));\n return rows.map((r) => String(r.message_id));\n },\n\n async save(messageId: string, on = true, note?: string) {\n await rpc(\"save_message\", { p_message_id: messageId, p_on: on, p_note: note ?? null });\n },\n\n async report(messageId: string, reason: \"spam\" | \"harassment\" | \"safety\" | \"other\", note?: string) {\n return rpc<string>(\"report_message\", { p_message_id: messageId, p_reason: reason, p_note: note ?? null });\n },\n\n // ── Migration 0002 ──────────────────────────────────────────────────────\n\n /** A conversation's topics, in order (position, then key). */\n async topics(conversationId: string): Promise<ChatTopic[]> {\n const rows = must<Row[]>(\n \"topics\",\n await db().from(\"topics\").select(\"*\").eq(\"conversation_id\", conversationId).order(\"position\", { ascending: true }).order(\"topic\", { ascending: true }),\n );\n return rows.map(toTopic);\n },\n\n /** Adds a topic, or renames, reorders, closes (`closed: true`) or reopens it. Owners and admins. */\n async setTopic(conversationId: string, topic: string, input: TopicInput = {}) {\n await rpc(\"set_topic\", {\n p_conversation_id: conversationId,\n p_topic: topic,\n p_title: input.title ?? null,\n p_position: input.position ?? null,\n p_closed: input.closed ?? null,\n });\n },\n\n /** Schedules a message (a minute to a year ahead) and returns its id. Safe to retry with the same clientId. */\n async schedule(input: ScheduleInput): Promise<string> {\n const sendAt = typeof input.sendAt === \"string\" ? input.sendAt : input.sendAt.toISOString();\n return rpc<string>(\"schedule_message\", {\n p_conversation_id: input.conversationId,\n p_client_id: input.clientId,\n p_send_at: sendAt,\n p_body: input.body ?? \"\",\n p_attachments: (input.attachments ?? []).map(attachmentArg),\n p_reply_to_id: input.replyToId ?? null,\n p_topic: input.topic ?? null,\n p_mentions: input.mentions ?? [],\n p_silent: input.silent ?? false,\n });\n },\n\n /** Your messages still waiting to go (and ones that failed when due), soonest first; in one conversation or all. */\n async scheduled(conversationId?: string): Promise<ScheduledMessage[]> {\n let q = db().from(\"scheduled\").select(\"*\").is(\"sent_message_id\", null).is(\"cancelled_at\", null);\n if (conversationId) q = q.eq(\"conversation_id\", conversationId);\n const rows = must<Row[]>(\"scheduled\", await q.order(\"send_at\", { ascending: true }).limit(200));\n return rows.map(toScheduled);\n },\n\n async cancelScheduled(id: string) {\n await rpc(\"cancel_scheduled\", { p_id: id });\n },\n\n /** The away message and hours of a conversation's members who set them (not observers). */\n async availabilityFor(conversationId: string): Promise<ChatAvailability[]> {\n const rows = await rpc<Row[]>(\"availability_for\", { p_conversation_id: conversationId });\n return (rows ?? []).map(toAvailability);\n },\n\n /** Your own away message and hours, or null when never set. */\n async myAvailability(): Promise<ChatAvailability | null> {\n const row = must(\"myAvailability\", await db().from(\"availability\").select(\"*\").maybeSingle()) as Row | null;\n return row ? toAvailability(row) : null;\n },\n\n /** Replaces your away message and hours (a field left out is cleared). */\n async setAvailability(input: AvailabilityInput) {\n const until = input.awayUntil ?? null;\n await rpc(\"set_availability\", {\n p_away_message: input.awayMessage ?? null,\n p_away_until: until,\n p_time_zone: input.timeZone ?? null,\n p_hours: input.hours ?? null,\n });\n },\n\n /**\n * Sends one text message into each of these conversations where you may post (a coach to\n * each client's direct conversation), so replies come back privately. Text only. Safe to\n * retry with the same clientId. Returns the ids of the messages sent.\n */\n async broadcast(conversationIds: string[], clientId: string, body: string, opts: { silent?: boolean } = {}): Promise<string[]> {\n const ids = await rpc<string[] | null>(\"broadcast_message\", {\n p_conversation_ids: conversationIds,\n p_client_id: clientId,\n p_body: body,\n p_attachments: [],\n p_silent: opts.silent ?? false,\n });\n return (ids ?? []).map(String);\n },\n\n /** Messages (and transcripts) you can read that match, newest first: in one conversation or all of yours. Two characters at least. */\n async search(query: string, conversationId?: string | null, opts: { limit?: number } = {}): Promise<ChatSearchHit[]> {\n if (query.trim().length < 2) return [];\n const rows = await rpc<Row[] | null>(\"search_messages\", {\n p_query: query,\n p_conversation_id: conversationId ?? null,\n p_limit: opts.limit ?? 30,\n });\n return (rows ?? []).map(toSearchHit);\n },\n\n /**\n * The previews the server has fetched for the links in these messages, by message id (only\n * `ok` ones; links not fetched yet are left out). Read through link_previews_for, one call\n * per message (up to 6 at once), which answers only for messages you can read: the preview\n * table itself is closed, since a URL can carry a secret.\n */\n async linkPreviewsFor(messageIds: string[]): Promise<Record<string, ChatLinkPreview[]>> {\n const ids = [...new Set(messageIds.filter(Boolean))].slice(0, 200);\n const out: Record<string, ChatLinkPreview[]> = {};\n let next = 0;\n const worker = async () => {\n while (next < ids.length) {\n const id = ids[next++]!;\n const rows = await rpc<Row[] | null>(\"link_previews_for\", { p_message_id: id });\n out[id] = (rows ?? []).map(toLinkPreview).filter((p) => p.status === \"ok\");\n }\n };\n await Promise.all(Array.from({ length: Math.min(6, ids.length) }, worker));\n return out;\n },\n\n /**\n * Uploads a file into the conversation's folder for the signed-in person and\n * returns its path, ready to attach. Resumable for big files is the native\n * renderer's job (Supabase TUS); this is the plain upload.\n *\n * With `onProgress(sent, total)`, where XMLHttpRequest exists (browsers, React Native), the\n * bytes go to a signed upload URL (`createSignedUploadUrl`, which checks the same storage\n * policy as a plain upload) through XMLHttpRequest, which reports progress; elsewhere the\n * plain upload runs and reports once, at the end. `signal` cancels it.\n */\n async upload(\n conversationId: string,\n userId: string,\n file: Blob | ArrayBuffer,\n opts: { name: string; contentType: string; id?: string; onProgress?: UploadProgress; signal?: AbortSignal },\n ) {\n const ext = fileExtension(opts.name, opts.contentType);\n if (!isAllowedExtension(ext)) throw new ChatError(`Files of type .${ext} can't be sent`, \"22023\", \"upload\");\n const id = opts.id ?? randomId();\n const path = `${conversationId}/${userId}/${id}.${ext}`;\n const bucket = supabase.storage.from(CHAT_BUCKET);\n if (opts.onProgress && typeof XMLHttpRequest !== \"undefined\" && typeof bucket.createSignedUploadUrl === \"function\") {\n const signed = must<{ signedUrl: string } | null>(\"upload\", await bucket.createSignedUploadUrl(path));\n if (!signed?.signedUrl) throw new ChatError(\"No upload URL came back\", undefined, \"upload\");\n await sendBytes(signed.signedUrl, file, {\n method: \"PUT\",\n headers: { \"content-type\": opts.contentType, \"x-upsert\": \"false\", \"cache-control\": \"max-age=3600\" },\n signal: opts.signal,\n onProgress: opts.onProgress,\n });\n return path;\n }\n must(\"upload\", await bucket.upload(path, file, { contentType: opts.contentType, upsert: false }));\n const total = typeof Blob !== \"undefined\" && file instanceof Blob ? file.size : (file as ArrayBuffer).byteLength;\n opts.onProgress?.(total, total);\n return path;\n },\n\n /** Signed links for files, cached until shortly before they expire. */\n async fileUrls(paths: string[]): Promise<Record<string, string>> {\n const now = Date.now();\n const out: Record<string, string> = {};\n const missing: string[] = [];\n for (const p of new Set(paths)) {\n const hit = signedCache.get(p);\n if (hit && hit.until > now) out[p] = hit.url;\n else missing.push(p);\n }\n if (missing.length) {\n const { data, error } = await supabase.storage.from(CHAT_BUCKET).createSignedUrls(missing, signedUrlSeconds);\n if (error) throw new ChatError(error.message, undefined, \"fileUrls\");\n for (const d of data ?? []) {\n if (d.signedUrl && d.path) {\n out[d.path] = d.signedUrl;\n signedCache.set(d.path, { url: d.signedUrl, until: now + (signedUrlSeconds - 60) * 1000 });\n }\n }\n }\n return out;\n },\n\n /** Your inbox's live hints (a new message anywhere you are, a membership change). */\n subscribeInbox(userId: string, onSignal: (s: ChatSignal) => void): Subscription {\n const channel = supabase\n .channel(userTopic(userId), { config: { private: true } })\n .on(\"broadcast\", { event: \"inbox\" }, ({ payload }) =>\n onSignal({ type: \"inbox\", conversationId: String(payload?.conversation_id), seq: payload?.seq }),\n );\n return { unsubscribe: join(channel) };\n },\n\n /**\n * A conversation's live hints, plus who is typing or recording. `onJoin` runs every\n * time the channel joins, the first time included: the moment to fetch what arrived\n * before the subscription was live. `onReconnect` (kept for older callers) runs on\n * re-joins only.\n */\n subscribeConversation(\n conversationId: string,\n me: string,\n handlers: ConversationHandlers,\n ): ConversationChannel {\n let joinedOnce = false;\n const channel: RealtimeChannel = supabase\n .channel(conversationTopic(conversationId), { config: { private: true, broadcast: { self: false } } })\n .on(\"broadcast\", { event: \"message\" }, ({ payload }) =>\n handlers.onSignal({ type: \"message\", conversationId, id: String(payload?.id), seq: payload?.seq, op: payload?.op ?? \"insert\" }),\n )\n .on(\"broadcast\", { event: \"reaction\" }, ({ payload }) =>\n handlers.onSignal({ type: \"reaction\", conversationId, messageId: String(payload?.message_id) }),\n )\n .on(\"broadcast\", { event: \"members\" }, () => handlers.onSignal({ type: \"members\", conversationId }))\n .on(\"broadcast\", { event: \"conversation\" }, () => handlers.onSignal({ type: \"conversation\", conversationId }))\n .on(\"broadcast\", { event: \"activity\" }, ({ payload }) => {\n if (payload?.userId && payload.userId !== me) handlers.onActivity?.({ userId: payload.userId, activity: payload.activity, at: Date.now() });\n });\n // Typing and recording are ephemeral: until the channel has joined, they're dropped\n // rather than sent (supabase-js would fall back to REST and warn).\n let joined = false;\n const leave = join(channel, (status) => {\n joined = status === \"SUBSCRIBED\";\n if (status === \"SUBSCRIBED\") {\n handlers.onJoin?.();\n if (joinedOnce) handlers.onReconnect?.();\n joinedOnce = true;\n }\n });\n return {\n signal(activity) {\n if (!joined) return;\n void channel.send({ type: \"broadcast\", event: \"activity\", payload: { userId: me, activity } });\n },\n unsubscribe: leave,\n };\n },\n };\n}\n\nexport type ChatClient = ReturnType<typeof createChatClient>;\n\nfunction attachmentArg(a: AttachmentInput) {\n return {\n kind: a.kind,\n path: a.path,\n provider: a.provider,\n provider_id: a.providerId,\n url: a.url,\n ref: a.ref,\n status: a.status,\n name: a.name,\n mime: a.mime,\n bytes: a.bytes,\n width: a.width,\n height: a.height,\n duration_ms: a.durationMs,\n waveform: a.waveform,\n poster_path: a.posterPath,\n thumbhash: a.thumbhash,\n };\n}\n","/**\n * @feat:chat\n * Sending bytes with progress, the same on every platform. fetch can't report how much of a\n * request body has gone, so where XMLHttpRequest exists (browsers, React Native) the body goes\n * through it and `onProgress(sent, total)` follows `upload.onprogress`; elsewhere it goes\n * through fetch and reports once, at the end.\n */\nimport { ChatError } from \"./client\";\n\nexport type UploadProgress = (sent: number, total: number) => void;\n\nexport interface SendBytesOptions {\n method?: \"PUT\" | \"POST\";\n headers?: Record<string, string>;\n signal?: AbortSignal;\n onProgress?: UploadProgress;\n /** For tests and runtimes without XMLHttpRequest. */\n fetch?: typeof fetch;\n}\n\nconst sizeOf = (body: Blob | ArrayBuffer) => (typeof Blob !== \"undefined\" && body instanceof Blob ? body.size : (body as ArrayBuffer).byteLength);\n\n/** A failed answer's code: a 5xx, 408 or no answer is worth retrying, 429 waits, any other 4xx is a refusal. */\nconst refusal = (status: number) => (status >= 500 || status === 0 || status === 408 ? undefined : status === 429 ? \"GS429\" : \"22023\");\n\nconst aborted = () => new ChatError(\"The upload was cancelled\", \"GSABORT\", \"upload\");\n\n/** Sends `body` to `url`; resolves with the response text, throws a ChatError on a non-2xx answer. */\nexport function sendBytes(url: string, body: Blob | ArrayBuffer, opts: SendBytesOptions = {}): Promise<string> {\n const method = opts.method ?? \"PUT\";\n const total = sizeOf(body);\n if (opts.signal?.aborted) return Promise.reject(aborted());\n if (typeof XMLHttpRequest === \"undefined\" || opts.fetch) {\n const f = opts.fetch ?? fetch;\n return f(url, { method, body, headers: opts.headers, signal: opts.signal }).then(async (res) => {\n if (!res.ok) throw new ChatError(`The upload failed (${res.status})`, refusal(res.status), \"upload\");\n opts.onProgress?.(total, total);\n return res.text().catch(() => \"\");\n });\n }\n return new Promise<string>((resolve, reject) => {\n const xhr = new XMLHttpRequest();\n const onAbort = () => xhr.abort();\n const done = () => opts.signal?.removeEventListener(\"abort\", onAbort);\n xhr.open(method, url);\n for (const [k, v] of Object.entries(opts.headers ?? {})) xhr.setRequestHeader(k, v);\n if (opts.onProgress && xhr.upload) {\n xhr.upload.onprogress = (e: ProgressEvent) => opts.onProgress?.(e.loaded, e.lengthComputable ? e.total : total);\n }\n xhr.onload = () => {\n done();\n if (xhr.status >= 200 && xhr.status < 300) {\n opts.onProgress?.(total, total);\n resolve(typeof xhr.responseText === \"string\" ? xhr.responseText : \"\");\n } else {\n reject(new ChatError(`The upload failed (${xhr.status})`, refusal(xhr.status), \"upload\"));\n }\n };\n // No answer at all: the connection, worth retrying.\n xhr.onerror = () => {\n done();\n reject(new ChatError(\"The upload didn't reach the server\", undefined, \"upload\"));\n };\n xhr.onabort = () => {\n done();\n reject(aborted());\n };\n opts.signal?.addEventListener(\"abort\", onAbort, { once: true });\n xhr.send(body);\n });\n}\n"]}