@poolse/react 3.8.0 → 3.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -630,6 +630,9 @@ function useMembers(conversationId) {
630
630
  const [error, setError] = react.useState(null);
631
631
  const membersRef = react.useRef([]);
632
632
  membersRef.current = members;
633
+ react.useEffect(() => {
634
+ chat.users.noteAgents(members);
635
+ }, [chat, members]);
633
636
  const pendingReadsRef = react.useRef([]);
634
637
  const hasFetchedRef = react.useRef(false);
635
638
  const applyRead = (list, evt) => list.map(
@@ -747,6 +750,9 @@ function useMessages(conversationId) {
747
750
  if (loading) return;
748
751
  chat.cache.setMessages(conversationId, messages);
749
752
  }, [chat, conversationId, messages, loading]);
753
+ react.useEffect(() => {
754
+ chat.users.noteAgents(messages);
755
+ }, [chat, messages]);
750
756
  react.useEffect(() => {
751
757
  let cancelled = false;
752
758
  let fresh = false;
@@ -1169,6 +1175,9 @@ var PAGE_SIZE2 = 500;
1169
1175
  function useThread(conversationId, rootMessageId) {
1170
1176
  const chat = usePoolse();
1171
1177
  const [replies, setReplies] = react.useState([]);
1178
+ react.useEffect(() => {
1179
+ chat.users.noteAgents(replies);
1180
+ }, [chat, replies]);
1172
1181
  const [loading, setLoading] = react.useState(true);
1173
1182
  const [error, setError] = react.useState(null);
1174
1183
  const [hasMore, setHasMore] = react.useState(true);
@@ -1676,15 +1685,17 @@ function useAttachmentUrl(attachmentId) {
1676
1685
  }, [chat, attachmentId]);
1677
1686
  return { url, loading, error };
1678
1687
  }
1679
- var EMPTY = { profile: null, loading: false };
1688
+ var EMPTY = { profile: null, loading: false, agent: null };
1680
1689
  function useUser(externalId) {
1681
1690
  const chat = usePoolse();
1682
1691
  const shownForRef = react.useRef(null);
1692
+ const agentRef = react.useRef(null);
1683
1693
  const [state, setState] = react.useState(() => {
1684
1694
  if (!externalId) return EMPTY;
1685
1695
  const cached = chat.users.peek(externalId);
1686
- if (cached === void 0) return { profile: null, loading: true };
1687
- return { profile: cached, loading: false };
1696
+ const agent = chat.users.agentOf(externalId);
1697
+ if (cached === void 0) return { profile: null, loading: true, agent };
1698
+ return { profile: cached, loading: false, agent };
1688
1699
  });
1689
1700
  react.useEffect(() => {
1690
1701
  if (!externalId) {
@@ -1693,13 +1704,15 @@ function useUser(externalId) {
1693
1704
  }
1694
1705
  const apply = () => {
1695
1706
  const cached = chat.users.peek(externalId);
1707
+ const agent = sameAgent(agentRef.current, chat.users.agentOf(externalId));
1708
+ agentRef.current = agent;
1696
1709
  if (cached === void 0) {
1697
1710
  const keep = shownForRef.current === externalId;
1698
- setState((prev) => ({ profile: keep ? prev.profile : null, loading: true }));
1711
+ setState((prev) => ({ profile: keep ? prev.profile : null, loading: true, agent }));
1699
1712
  void chat.users.get(externalId);
1700
1713
  } else {
1701
1714
  shownForRef.current = externalId;
1702
- setState({ profile: cached, loading: false });
1715
+ setState({ profile: cached, loading: false, agent });
1703
1716
  }
1704
1717
  };
1705
1718
  const off = chat.users.subscribe(externalId, apply);
@@ -1708,12 +1721,251 @@ function useUser(externalId) {
1708
1721
  }, [chat, externalId]);
1709
1722
  return state;
1710
1723
  }
1724
+ function sameAgent(prev, next) {
1725
+ if (prev && next && prev.id === next.id && prev.name === next.name && prev.kind === next.kind) {
1726
+ return prev;
1727
+ }
1728
+ return next;
1729
+ }
1730
+ function useAgent(externalId) {
1731
+ const chat = usePoolse();
1732
+ const [agent, setAgent] = react.useState(() => chat.users.agentOf(externalId));
1733
+ react.useEffect(() => {
1734
+ if (!externalId) {
1735
+ setAgent(null);
1736
+ return;
1737
+ }
1738
+ const read = () => setAgent((prev) => sameAgent(prev, chat.users.agentOf(externalId)));
1739
+ read();
1740
+ return chat.users.subscribe(externalId, read);
1741
+ }, [chat, externalId]);
1742
+ return agent;
1743
+ }
1711
1744
  function useAppEvent(handler) {
1712
1745
  const chat = usePoolse();
1713
1746
  const handlerRef = react.useRef(handler);
1714
1747
  handlerRef.current = handler;
1715
1748
  react.useEffect(() => chat.onAppEvent((evt) => handlerRef.current(evt)), [chat]);
1716
1749
  }
1750
+
1751
+ // src/composer-tools.ts
1752
+ var FORMAT_ACTIONS = [
1753
+ { kind: "bold", label: "Bold", glyph: "B", shortcut: "Mod+B" },
1754
+ { kind: "italic", label: "Italic", glyph: "I", shortcut: "Mod+I" },
1755
+ { kind: "strike", label: "Strikethrough", glyph: "S", shortcut: "Mod+Shift+X" },
1756
+ { kind: "code", label: "Code", glyph: "<>", shortcut: "Mod+E" },
1757
+ { kind: "link", label: "Link", glyph: "\u{1F517}", shortcut: "Mod+K" },
1758
+ { kind: "quote", label: "Quote", glyph: "\u275D" },
1759
+ { kind: "bulletList", label: "Bulleted list", glyph: "\u2022" },
1760
+ { kind: "numberedList", label: "Numbered list", glyph: "1." },
1761
+ { kind: "checklist", label: "Checklist", glyph: "\u2610" },
1762
+ { kind: "codeBlock", label: "Code block", glyph: "{}" },
1763
+ { kind: "table", label: "Table", glyph: "\u25A6" }
1764
+ ];
1765
+ var INLINE = {
1766
+ bold: "**",
1767
+ italic: "_",
1768
+ strike: "~~",
1769
+ code: "`"
1770
+ };
1771
+ var LINE_PREFIX = {
1772
+ quote: "> ",
1773
+ bulletList: "- ",
1774
+ checklist: "- [ ] "
1775
+ };
1776
+ function clampSelection(value, sel) {
1777
+ const start = Math.max(0, Math.min(sel.start, sel.end, value.length));
1778
+ const end = Math.max(start, Math.min(Math.max(sel.start, sel.end), value.length));
1779
+ return { start, end };
1780
+ }
1781
+ function applyFormat(value, selection, kind) {
1782
+ const { start, end } = clampSelection(value, selection);
1783
+ const selected = value.slice(start, end);
1784
+ const before = value.slice(0, start);
1785
+ const after = value.slice(end);
1786
+ const marker = INLINE[kind];
1787
+ if (marker) {
1788
+ const m = marker.length;
1789
+ if (before.endsWith(marker) && after.startsWith(marker)) {
1790
+ return {
1791
+ value: before.slice(0, -m) + selected + after.slice(m),
1792
+ selection: { start: start - m, end: end - m }
1793
+ };
1794
+ }
1795
+ if (selected.length > 2 * m && selected.startsWith(marker) && selected.endsWith(marker)) {
1796
+ const inner = selected.slice(m, -m);
1797
+ return { value: before + inner + after, selection: { start, end: start + inner.length } };
1798
+ }
1799
+ return {
1800
+ value: before + marker + selected + marker + after,
1801
+ selection: { start: start + m, end: end + m }
1802
+ };
1803
+ }
1804
+ if (kind === "link") {
1805
+ const text = selected || "text";
1806
+ const url = "https://";
1807
+ const next2 = `${before}[${text}](${url})${after}`;
1808
+ const urlStart = start + text.length + 3;
1809
+ return { value: next2, selection: { start: urlStart, end: urlStart + url.length } };
1810
+ }
1811
+ if (kind === "codeBlock") {
1812
+ const lead = before === "" || before.endsWith("\n") ? "" : "\n";
1813
+ const tail = after === "" || after.startsWith("\n") ? "" : "\n";
1814
+ const block2 = `${lead}\`\`\`
1815
+ ${selected}
1816
+ \`\`\`${tail}`;
1817
+ const innerStart = start + lead.length + 4;
1818
+ return {
1819
+ value: before + block2 + after,
1820
+ selection: { start: innerStart, end: innerStart + selected.length }
1821
+ };
1822
+ }
1823
+ if (kind === "table") {
1824
+ const lead = before === "" || before.endsWith("\n") ? "" : "\n";
1825
+ const header = selected.trim() || "Column";
1826
+ const table = `${lead}| ${header} | Column |
1827
+ | --- | --- |
1828
+ | | |
1829
+ `;
1830
+ const cell = start + table.length - 6;
1831
+ return { value: before + table + after, selection: { start: cell, end: cell } };
1832
+ }
1833
+ const lineStart = value.lastIndexOf("\n", start - 1) + 1;
1834
+ const nl = value.indexOf("\n", end);
1835
+ const lineEnd = nl === -1 ? value.length : nl;
1836
+ const lines = value.slice(lineStart, lineEnd).split("\n");
1837
+ const numbered = /^\d+\. /;
1838
+ const prefix = LINE_PREFIX[kind];
1839
+ const has = (line) => kind === "numberedList" ? numbered.test(line) : line.startsWith(prefix);
1840
+ const allHave = lines.every(has);
1841
+ const nextLines = lines.map((line, i) => {
1842
+ if (allHave)
1843
+ return kind === "numberedList" ? line.replace(numbered, "") : line.slice(prefix.length);
1844
+ const bare = line.replace(/^(\d+\. |- \[[ xX]\] |- |\* |> )/, "");
1845
+ return (kind === "numberedList" ? `${i + 1}. ` : prefix) + bare;
1846
+ });
1847
+ const block = nextLines.join("\n");
1848
+ const next = value.slice(0, lineStart) + block + value.slice(lineEnd);
1849
+ if (start === end) {
1850
+ const caret = lineStart + nextLines[0].length;
1851
+ return { value: next, selection: { start: caret, end: caret } };
1852
+ }
1853
+ return { value: next, selection: { start: lineStart, end: lineStart + block.length } };
1854
+ }
1855
+ function formatForShortcut(e) {
1856
+ if (!(e.metaKey || e.ctrlKey) || e.altKey) return null;
1857
+ const key = e.key.toLowerCase();
1858
+ if (e.shiftKey) return key === "x" ? "strike" : null;
1859
+ switch (key) {
1860
+ case "b":
1861
+ return "bold";
1862
+ case "i":
1863
+ return "italic";
1864
+ case "e":
1865
+ return "code";
1866
+ case "k":
1867
+ return "link";
1868
+ default:
1869
+ return null;
1870
+ }
1871
+ }
1872
+ function slashQuery(value, caret) {
1873
+ if (!value.startsWith("/")) return null;
1874
+ const head = value.slice(1, caret);
1875
+ if (caret < 1 || /\s/.test(head)) return null;
1876
+ const end = value.search(/\s/);
1877
+ if (end !== -1 && caret > end) return null;
1878
+ return { query: head.toLowerCase() };
1879
+ }
1880
+ function filterSlashCommands(commands, query, limit = 8) {
1881
+ const q = query.toLowerCase();
1882
+ const prefix = [];
1883
+ const contains = [];
1884
+ for (const c of commands) {
1885
+ const name = c.name.toLowerCase();
1886
+ if (name.startsWith(q)) prefix.push(c);
1887
+ else if (q && (name.includes(q) || c.description?.toLowerCase().includes(q))) contains.push(c);
1888
+ }
1889
+ prefix.sort((a, b) => a.name.localeCompare(b.name));
1890
+ return [...prefix, ...contains].slice(0, limit);
1891
+ }
1892
+ function applySlashCommand(value, name) {
1893
+ const end = value.search(/\s/);
1894
+ const rest = end === -1 ? "" : value.slice(end).replace(/^\s+/, "");
1895
+ const head = `/${name} `;
1896
+ return { value: head + rest, selection: { start: head.length, end: head.length } };
1897
+ }
1898
+ function slashCommandsFromWorkspace(commands) {
1899
+ return commands.map((c) => ({
1900
+ name: c.command,
1901
+ ...c.description ? { description: c.description } : {},
1902
+ ...c.usage ? { usage: c.usage } : {},
1903
+ ...c.app?.name ? { source: c.app.name } : {}
1904
+ }));
1905
+ }
1906
+ function parseSlashCommand(value) {
1907
+ const m = /^\/([a-z0-9_-]+)(?:\s+([\s\S]*))?$/i.exec(value.trim());
1908
+ if (!m) return null;
1909
+ return { name: m[1].toLowerCase(), args: (m[2] ?? "").trim() };
1910
+ }
1911
+ function rankMentionGroups(groups, query, limit = 8) {
1912
+ const q = query.toLowerCase();
1913
+ const scored = [];
1914
+ for (const g of groups) {
1915
+ const handle = g.handle.toLowerCase();
1916
+ const name = g.name.toLowerCase();
1917
+ const score = q === "" ? 1 : handle.startsWith(q) ? 3 : name.split(/\s+/).some((w) => w.startsWith(q)) ? 2 : handle.includes(q) || name.includes(q) ? 1 : 0;
1918
+ if (score > 0) scored.push({ g, score });
1919
+ }
1920
+ scored.sort((a, b) => b.score - a.score || a.g.handle.localeCompare(b.g.handle));
1921
+ return scored.slice(0, limit).map((s) => s.g);
1922
+ }
1923
+ function mentionGroupMeta(g) {
1924
+ if (g.description) return g.description;
1925
+ if (g.memberCount === void 0) return null;
1926
+ return `${g.memberCount} ${g.memberCount === 1 ? "person" : "people"}`;
1927
+ }
1928
+ var MESSAGE_PLAYBACK_RATES = [1, 1.5, 2];
1929
+ function nextPlaybackRate(rate) {
1930
+ const i = MESSAGE_PLAYBACK_RATES.indexOf(rate);
1931
+ return MESSAGE_PLAYBACK_RATES[(i + 1) % MESSAGE_PLAYBACK_RATES.length];
1932
+ }
1933
+ function playbackRateLabel(rate) {
1934
+ return `${rate}\xD7`;
1935
+ }
1936
+ function waveformBars(samples, bars) {
1937
+ if (bars <= 0) return [];
1938
+ if (samples.length === 0) return new Array(bars).fill(0.08);
1939
+ const out = [];
1940
+ for (let i = 0; i < bars; i++) {
1941
+ const from = Math.floor(i * samples.length / bars);
1942
+ const to = Math.max(from + 1, Math.floor((i + 1) * samples.length / bars));
1943
+ let peak = 0;
1944
+ for (let j = from; j < to && j < samples.length; j++) peak = Math.max(peak, samples[j]);
1945
+ out.push(Math.max(0.08, Math.min(1, peak)));
1946
+ }
1947
+ return out;
1948
+ }
1949
+ var WARN_CODES = /* @__PURE__ */ new Set(["dlp_warning"]);
1950
+ var BLOCK_CODES = /* @__PURE__ */ new Set(["dlp_blocked"]);
1951
+ function readDlpError(err) {
1952
+ if (!(err instanceof sdk.ApiError)) return null;
1953
+ const code = String(err.code);
1954
+ const action = WARN_CODES.has(code) ? "warn" : BLOCK_CODES.has(code) ? "block" : null;
1955
+ if (!action) return null;
1956
+ const details = err.details ?? {};
1957
+ const raw = Array.isArray(details.rules) ? details.rules : Array.isArray(details.matches) ? details.matches : [];
1958
+ const matches = [];
1959
+ for (const m of raw) {
1960
+ if (!m || typeof m !== "object") continue;
1961
+ const r = m;
1962
+ const rule = typeof r.name === "string" ? r.name : typeof r.rule === "string" ? r.rule : null;
1963
+ if (!rule) continue;
1964
+ matches.push({ rule, ...typeof r.excerpt === "string" ? { excerpt: r.excerpt } : {} });
1965
+ }
1966
+ const message = typeof details.message === "string" ? details.message : void 0;
1967
+ return { action, matches, ...message ? { message } : {} };
1968
+ }
1717
1969
  function computeGroupPosition(msg, prev, next, windowMs) {
1718
1970
  const continuesPrev = sameGroup(msg, prev, windowMs);
1719
1971
  const continuesNext = sameGroup(next, msg, windowMs);
@@ -1768,6 +2020,11 @@ function useCallRoom(conversationId, opts) {
1768
2020
  const [activeDevices, setActiveDevices] = react.useState({});
1769
2021
  const [error, setError] = react.useState(null);
1770
2022
  const [sfuAvailable, setSfuAvailable] = react.useState(null);
2023
+ const [canPublish, setCanPublish] = react.useState(true);
2024
+ const [background, setBackgroundState] = react.useState({ type: "none" });
2025
+ const [noiseSuppression, setNoise] = react.useState(opts.noiseSuppression ?? true);
2026
+ const [reconnecting, setReconnecting] = react.useState(false);
2027
+ const [disconnectReason, setDisconnectReason] = react.useState(null);
1771
2028
  const optsRef = react.useRef(opts);
1772
2029
  optsRef.current = opts;
1773
2030
  const joined = react.useRef(false);
@@ -1779,7 +2036,10 @@ function useCallRoom(conversationId, opts) {
1779
2036
  ...optsRef.current.video !== void 0 ? { video: optsRef.current.video } : {},
1780
2037
  ...optsRef.current.muted !== void 0 ? { muted: optsRef.current.muted } : {},
1781
2038
  ...optsRef.current.facing !== void 0 ? { facing: optsRef.current.facing } : {},
1782
- ...optsRef.current.aloneGraceMs !== void 0 ? { aloneGraceMs: optsRef.current.aloneGraceMs } : {}
2039
+ ...optsRef.current.aloneGraceMs !== void 0 ? { aloneGraceMs: optsRef.current.aloneGraceMs } : {},
2040
+ ...optsRef.current.republishOnPermission !== void 0 ? { republishOnPermission: optsRef.current.republishOnPermission } : {},
2041
+ ...optsRef.current.trackProcessors ? { trackProcessors: optsRef.current.trackProcessors } : {},
2042
+ ...optsRef.current.noiseSuppression !== void 0 ? { noiseSuppression: optsRef.current.noiseSuppression } : {}
1783
2043
  });
1784
2044
  }, [poolse, conversationId]);
1785
2045
  const refreshDevices = react.useCallback((target) => {
@@ -1804,6 +2064,7 @@ function useCallRoom(conversationId, opts) {
1804
2064
  setScreen(target.isScreenShareEnabled());
1805
2065
  setCanShare(target.canShareScreen());
1806
2066
  setFacing(target.getFacingMode());
2067
+ setCanPublish(target.canPublish());
1807
2068
  }, []);
1808
2069
  react.useEffect(() => {
1809
2070
  if (!room) {
@@ -1823,12 +2084,22 @@ function useCallRoom(conversationId, opts) {
1823
2084
  const offAlone = room.onAlone(() => setAlone(true));
1824
2085
  const offDevices = room.onDevices(() => refreshDevices(room));
1825
2086
  const offError = room.onError(setError);
2087
+ const offPublish = room.onPublishPermission(() => sync(room));
2088
+ setReconnecting(room.isReconnecting());
2089
+ setDisconnectReason(null);
2090
+ setBackgroundState(room.getBackground());
2091
+ setNoise(room.isNoiseSuppressionEnabled());
2092
+ const offReconnect = room.onReconnecting(setReconnecting);
2093
+ const offDisconnect = room.onDisconnected(setDisconnectReason);
1826
2094
  return () => {
1827
2095
  offStatus();
1828
2096
  offRoster();
1829
2097
  offAlone();
1830
2098
  offDevices();
1831
2099
  offError();
2100
+ offPublish();
2101
+ offReconnect();
2102
+ offDisconnect();
1832
2103
  held.current = null;
1833
2104
  if (joined.current) {
1834
2105
  joined.current = false;
@@ -1921,7 +2192,35 @@ function useCallRoom(conversationId, opts) {
1921
2192
  },
1922
2193
  [room]
1923
2194
  );
2195
+ const republish = react.useCallback(async () => {
2196
+ if (!room) return;
2197
+ await room.republish();
2198
+ sync(room);
2199
+ }, [room, sync]);
2200
+ const setBackground = react.useCallback(
2201
+ async (effect) => {
2202
+ if (!room) return false;
2203
+ setBackgroundState(effect);
2204
+ return room.setBackground(effect);
2205
+ },
2206
+ [room]
2207
+ );
2208
+ const setNoiseSuppression = react.useCallback(
2209
+ async (enabled) => {
2210
+ setNoise(enabled);
2211
+ await room?.setNoiseSuppression(enabled);
2212
+ },
2213
+ [room]
2214
+ );
1924
2215
  return {
2216
+ room,
2217
+ backgroundSupported: room?.backgroundSupported() ?? false,
2218
+ background,
2219
+ setBackground,
2220
+ noiseSuppression,
2221
+ setNoiseSuppression,
2222
+ reconnecting,
2223
+ disconnectReason,
1925
2224
  status,
1926
2225
  participants,
1927
2226
  cameraEnabled,
@@ -1945,9 +2244,110 @@ function useCallRoom(conversationId, opts) {
1945
2244
  setMicrophoneEnabled,
1946
2245
  toggleMic,
1947
2246
  setScreenShareEnabled,
1948
- toggleScreenShare
2247
+ toggleScreenShare,
2248
+ canPublish,
2249
+ republish
1949
2250
  };
1950
2251
  }
2252
+ var IDLE_RECORDING = {
2253
+ available: true,
2254
+ active: false,
2255
+ id: null,
2256
+ mode: null,
2257
+ started_at: null,
2258
+ started_by_user_id: null,
2259
+ auto: false,
2260
+ consent_required: false,
2261
+ consent: { accepted: [], declined: [] }
2262
+ };
2263
+ var without = (list, id) => list.filter((x) => x !== id);
2264
+ function applyCaptureEvent(state, e) {
2265
+ const rec = state.recording ?? IDLE_RECORDING;
2266
+ switch (e.type) {
2267
+ case "recording:started": {
2268
+ const r = e.evt.recording;
2269
+ const starter = r.started_by_user_id;
2270
+ return {
2271
+ ...state,
2272
+ recording: {
2273
+ ...rec,
2274
+ active: true,
2275
+ id: r.id,
2276
+ mode: r.mode,
2277
+ started_at: r.started_at,
2278
+ started_by_user_id: starter,
2279
+ auto: r.auto,
2280
+ consent_required: e.evt.consent_required,
2281
+ // Starting is accepting.
2282
+ consent: starter ? {
2283
+ accepted: [...without(rec.consent.accepted, starter), starter],
2284
+ declined: without(rec.consent.declined, starter)
2285
+ } : rec.consent
2286
+ }
2287
+ };
2288
+ }
2289
+ case "recording:stopped":
2290
+ case "recording:ready":
2291
+ if (rec.id !== null && rec.id !== e.evt.recording.id) return state;
2292
+ return {
2293
+ ...state,
2294
+ recording: { ...rec, active: false, id: null, mode: null, consent_required: false }
2295
+ };
2296
+ case "recording:consent": {
2297
+ const { user_id: who, decision } = e.evt;
2298
+ const accepted = without(rec.consent.accepted, who);
2299
+ const declined = without(rec.consent.declined, who);
2300
+ (decision === "accepted" ? accepted : declined).push(who);
2301
+ return { ...state, recording: { ...rec, consent: { accepted, declined } } };
2302
+ }
2303
+ case "transcript:changed": {
2304
+ const t = e.evt.transcript;
2305
+ return {
2306
+ ...state,
2307
+ transcription: {
2308
+ available: state.transcription?.available ?? true,
2309
+ active: t.status === "live",
2310
+ id: t.id,
2311
+ status: t.status,
2312
+ language: t.language
2313
+ }
2314
+ };
2315
+ }
2316
+ }
2317
+ }
2318
+ function subscribeCapture(chat, conversationId, callId, fn) {
2319
+ const conv = chat.realtime.conversation(conversationId);
2320
+ const mine = (id) => callId === null || id === callId;
2321
+ const offs = [
2322
+ conv.onRecordingStarted((evt) => mine(evt.call_id) && fn({ type: "recording:started", evt })),
2323
+ conv.onRecordingStopped((evt) => mine(evt.call_id) && fn({ type: "recording:stopped", evt })),
2324
+ conv.onRecordingReady((evt) => mine(evt.call_id) && fn({ type: "recording:ready", evt })),
2325
+ conv.onRecordingConsent((evt) => mine(evt.call_id) && fn({ type: "recording:consent", evt })),
2326
+ conv.onTranscriptStarted((evt) => mine(evt.call_id) && fn({ type: "transcript:changed", evt })),
2327
+ conv.onTranscriptStopped((evt) => mine(evt.call_id) && fn({ type: "transcript:changed", evt })),
2328
+ conv.onTranscriptReady((evt) => mine(evt.call_id) && fn({ type: "transcript:changed", evt }))
2329
+ ];
2330
+ return () => offs.forEach((off) => off());
2331
+ }
2332
+ function useMeId(chat) {
2333
+ const [id, setId] = react.useState(() => chat.me.peek()?.id ?? null);
2334
+ react.useEffect(() => {
2335
+ setId(chat.me.peek()?.id ?? null);
2336
+ return chat.me.onChange((me) => setId(me.id));
2337
+ }, [chat]);
2338
+ return id;
2339
+ }
2340
+ function onReconnect(chat, fn) {
2341
+ let wasConnected = chat.realtime.getStatus() === "connected";
2342
+ let connectedBefore = wasConnected;
2343
+ return chat.realtime.onStatus((status) => {
2344
+ if (status === "connected" && !wasConnected && connectedBefore) fn();
2345
+ wasConnected = status === "connected";
2346
+ connectedBefore ||= wasConnected;
2347
+ });
2348
+ }
2349
+
2350
+ // src/use-live-call.ts
1951
2351
  function useLiveCall(conversationId) {
1952
2352
  const chat = usePoolse();
1953
2353
  const [call, setCall] = react.useState(null);
@@ -1980,6 +2380,21 @@ function useLiveCall(conversationId) {
1980
2380
  if (evt.call_id === callIdRef.current) setParticipantIds(evt.participants);
1981
2381
  else refresh();
1982
2382
  });
2383
+ const offCapture = subscribeCapture(chat, conversationId, null, (e) => {
2384
+ if (e.evt.call_id !== callIdRef.current) return;
2385
+ setCall((c) => {
2386
+ if (!c) return c;
2387
+ const next = applyCaptureEvent(
2388
+ { recording: c.recording ?? null, transcription: c.transcription ?? null },
2389
+ e
2390
+ );
2391
+ return {
2392
+ ...c,
2393
+ ...next.recording ? { recording: next.recording } : {},
2394
+ ...next.transcription ? { transcription: next.transcription } : {}
2395
+ };
2396
+ });
2397
+ });
1983
2398
  const offFinished = conv.onCallFinished((evt) => {
1984
2399
  if (evt.call_id !== callIdRef.current) return;
1985
2400
  seq.current++;
@@ -1996,6 +2411,7 @@ function useLiveCall(conversationId) {
1996
2411
  offStarted();
1997
2412
  offParticipants();
1998
2413
  offFinished();
2414
+ offCapture();
1999
2415
  offStatus();
2000
2416
  };
2001
2417
  }, [chat, conversationId, apply, refresh]);
@@ -2050,155 +2466,2493 @@ function useRoom(conversationId, opts) {
2050
2466
  error: error ?? media.error
2051
2467
  };
2052
2468
  }
2053
- function useReadReceipts() {
2469
+ var asError = (err) => err instanceof Error ? err : new Error(String(err));
2470
+ function onReconnect2(chat, fn) {
2471
+ let was = chat.realtime.getStatus() === "connected";
2472
+ let before = was;
2473
+ return chat.realtime.onStatus((status) => {
2474
+ if (status === "connected" && !was && before) fn();
2475
+ was = status === "connected";
2476
+ before ||= was;
2477
+ });
2478
+ }
2479
+ function useLiveValue(conversationId, callId, load, listen, subscribeOpts = {}) {
2054
2480
  const chat = usePoolse();
2055
- const { me } = useMe();
2056
- const state = receiptsOf(me);
2057
- const setShared = react.useCallback(
2058
- async (share) => {
2059
- await chat.me.update({ read_receipts: share });
2481
+ const [value, setValue] = react.useState(null);
2482
+ const [error, setError] = react.useState(null);
2483
+ const [pending, setPending] = react.useState(false);
2484
+ const loadRef = react.useRef(load);
2485
+ loadRef.current = load;
2486
+ const listenRef = react.useRef(listen);
2487
+ listenRef.current = listen;
2488
+ const seq = react.useRef(0);
2489
+ const selfUserId = subscribeOpts.selfUserId ?? null;
2490
+ const refresh = react.useCallback(() => {
2491
+ if (!callId) return;
2492
+ const mine = ++seq.current;
2493
+ loadRef.current(chat, callId).then((v) => {
2494
+ if (mine === seq.current) setValue(v);
2495
+ }).catch((err) => {
2496
+ if (mine === seq.current) setError(asError(err));
2497
+ });
2498
+ }, [chat, callId]);
2499
+ react.useEffect(() => {
2500
+ setValue(null);
2501
+ setError(null);
2502
+ if (!callId || !conversationId) return;
2503
+ refresh();
2504
+ const off = chat.live.subscribe(
2505
+ conversationId,
2506
+ callId,
2507
+ listenRef.current((fn) => {
2508
+ seq.current++;
2509
+ setValue((prev) => fn(prev));
2510
+ }),
2511
+ selfUserId ? { selfUserId } : {}
2512
+ );
2513
+ const offStatus = onReconnect2(chat, refresh);
2514
+ return () => {
2515
+ off();
2516
+ offStatus();
2517
+ };
2518
+ }, [chat, conversationId, callId, refresh, selfUserId]);
2519
+ const run = react.useCallback(
2520
+ async (fn, apply) => {
2521
+ setPending(true);
2522
+ setError(null);
2523
+ try {
2524
+ const r = await fn();
2525
+ if (apply) {
2526
+ seq.current++;
2527
+ apply(r);
2528
+ }
2529
+ return r;
2530
+ } catch (err) {
2531
+ setError(asError(err));
2532
+ return null;
2533
+ } finally {
2534
+ setPending(false);
2535
+ }
2060
2536
  },
2061
- [chat]
2537
+ []
2062
2538
  );
2063
- return { ...state, setShared };
2539
+ return { chat, value, setValue, error, pending, refresh, run };
2064
2540
  }
2065
- function receiptsOf(me) {
2066
- const r = me?.read_receipts;
2541
+ function useStage(conversationId, callId, selfUserId) {
2542
+ const { chat, value, setValue, error, pending, run } = useLiveValue(
2543
+ conversationId,
2544
+ callId,
2545
+ (c, id) => c.live.stage.get(id),
2546
+ (set) => ({ onStage: (s) => set(() => s) }),
2547
+ { selfUserId: selfUserId ?? null }
2548
+ );
2549
+ const ok = (r) => r !== null;
2550
+ const raiseHand = react.useCallback(
2551
+ async () => callId ? ok(await run(() => chat.live.stage.raiseHand(callId), setValue)) : false,
2552
+ [chat, callId, run, setValue]
2553
+ );
2554
+ const lowerHand = react.useCallback(
2555
+ async (userId) => callId ? ok(await run(() => chat.live.stage.lowerHand(callId, userId), setValue)) : false,
2556
+ [chat, callId, run, setValue]
2557
+ );
2558
+ const setRole = react.useCallback(
2559
+ async (userId, role) => callId ? ok(await run(() => chat.live.stage.setRole(callId, userId, role), setValue)) : false,
2560
+ [chat, callId, run, setValue]
2561
+ );
2562
+ const setMode = react.useCallback(
2563
+ async (mode) => callId ? ok(await run(() => chat.live.stage.setMode(callId, mode), setValue)) : false,
2564
+ [chat, callId, run, setValue]
2565
+ );
2566
+ const roleOf = react.useCallback((userId) => sdk.stageRoleOf(value, userId), [value]);
2567
+ const myRole = value?.myRole ?? "speaker";
2067
2568
  return {
2068
- visible: r?.visible ?? true,
2069
- mode: r?.mode ?? "on",
2070
- shared: r?.shared ?? true,
2071
- canChange: r?.can_change ?? false
2569
+ stage: value,
2570
+ myRole,
2571
+ isModerator: myRole === "moderator",
2572
+ handRaised: !!selfUserId && !!value?.hands.some((h) => h.userId === selfUserId),
2573
+ roleOf,
2574
+ raiseHand,
2575
+ lowerHand,
2576
+ setRole,
2577
+ setMode,
2578
+ error,
2579
+ pending
2072
2580
  };
2073
2581
  }
2074
- var EDIT_WINDOW_MS = 15 * 60 * 1e3;
2075
- function canEditOwnMessage(args) {
2076
- if (!args.isSelf || args.deleted) return false;
2077
- if (args.receiptsVisible) return (args.readState ?? "sent") === "sent";
2078
- const sent = Date.parse(args.insertedAt);
2079
- return Number.isFinite(sent) && (args.now ?? Date.now()) - sent < EDIT_WINDOW_MS;
2582
+ function useQuestions(conversationId, callId) {
2583
+ const mineVoted = react.useRef(/* @__PURE__ */ new Set());
2584
+ const merge = (list, q) => {
2585
+ if (q.votedByMe) mineVoted.current.add(q.id);
2586
+ const withMine = { ...q, votedByMe: q.votedByMe || mineVoted.current.has(q.id) };
2587
+ const i = list.findIndex((x) => x.id === q.id);
2588
+ if (i < 0) return [...list, withMine];
2589
+ const next = list.slice();
2590
+ next[i] = withMine;
2591
+ return next;
2592
+ };
2593
+ const { chat, value, setValue, error, pending, run } = useLiveValue(
2594
+ conversationId,
2595
+ callId,
2596
+ async (c, id) => {
2597
+ const list = await c.live.questions.list(id);
2598
+ list.forEach((q) => q.votedByMe && mineVoted.current.add(q.id));
2599
+ return list;
2600
+ },
2601
+ (set) => ({
2602
+ onQuestion: (q) => set((prev) => merge(prev ?? [], q)),
2603
+ onQuestionDeleted: (id) => set((prev) => (prev ?? []).filter((q) => q.id !== id))
2604
+ })
2605
+ );
2606
+ const apply = react.useCallback(
2607
+ (q) => setValue((prev) => merge(prev ?? [], q)),
2608
+ // merge only reads the ref.
2609
+ [setValue]
2610
+ );
2611
+ const ask = react.useCallback(
2612
+ async (text, opts) => {
2613
+ if (!callId || !text.trim()) return false;
2614
+ return await run(() => chat.live.questions.ask(callId, text, opts ?? {}), apply) !== null;
2615
+ },
2616
+ [chat, callId, run, apply]
2617
+ );
2618
+ const toggleVote2 = react.useCallback(
2619
+ async (questionId) => {
2620
+ const voted = mineVoted.current.has(questionId);
2621
+ if (voted) mineVoted.current.delete(questionId);
2622
+ else mineVoted.current.add(questionId);
2623
+ const r = await run(
2624
+ () => voted ? chat.live.questions.unvote(questionId) : chat.live.questions.vote(questionId),
2625
+ (q) => apply({ ...q, votedByMe: !voted })
2626
+ );
2627
+ if (r === null) {
2628
+ if (voted) mineVoted.current.add(questionId);
2629
+ else mineVoted.current.delete(questionId);
2630
+ }
2631
+ },
2632
+ [chat, run, apply]
2633
+ );
2634
+ const setStatus = react.useCallback(
2635
+ async (questionId, status) => {
2636
+ await run(() => chat.live.questions.setStatus(questionId, status), apply);
2637
+ },
2638
+ [chat, run, apply]
2639
+ );
2640
+ const questions = react.useMemo(() => sdk.sortQuestions(value ?? []), [value]);
2641
+ return {
2642
+ questions,
2643
+ openCount: questions.filter((q) => q.status === "open").length,
2644
+ ask,
2645
+ toggleVote: toggleVote2,
2646
+ setStatus,
2647
+ error,
2648
+ pending
2649
+ };
2080
2650
  }
2081
-
2082
- Object.defineProperty(exports, "ApiError", {
2083
- enumerable: true,
2084
- get: function () { return sdk.ApiError; }
2085
- });
2086
- Object.defineProperty(exports, "AuthError", {
2087
- enumerable: true,
2088
- get: function () { return sdk.AuthError; }
2089
- });
2090
- Object.defineProperty(exports, "MessageDiscardedError", {
2091
- enumerable: true,
2092
- get: function () { return sdk.MessageDiscardedError; }
2093
- });
2094
- Object.defineProperty(exports, "MessageQueuedError", {
2095
- enumerable: true,
2096
- get: function () { return sdk.MessageQueuedError; }
2097
- });
2098
- Object.defineProperty(exports, "NetworkError", {
2099
- enumerable: true,
2100
- get: function () { return sdk.NetworkError; }
2101
- });
2102
- Object.defineProperty(exports, "Poolse", {
2103
- enumerable: true,
2104
- get: function () { return sdk.Poolse; }
2105
- });
2106
- Object.defineProperty(exports, "PoolseError", {
2107
- enumerable: true,
2108
- get: function () { return sdk.PoolseError; }
2109
- });
2110
- Object.defineProperty(exports, "RateLimitedError", {
2111
- enumerable: true,
2112
- get: function () { return sdk.RateLimitedError; }
2113
- });
2114
- Object.defineProperty(exports, "callLogDisplayFor", {
2115
- enumerable: true,
2116
- get: function () { return sdk.callLogDisplayFor; }
2117
- });
2118
- Object.defineProperty(exports, "createIndexedDbStorage", {
2119
- enumerable: true,
2120
- get: function () { return sdk.createIndexedDbStorage; }
2121
- });
2122
- Object.defineProperty(exports, "describeCallLog", {
2123
- enumerable: true,
2124
- get: function () { return sdk.describeCallLog; }
2125
- });
2126
- Object.defineProperty(exports, "formatCallDuration", {
2127
- enumerable: true,
2128
- get: function () { return sdk.formatCallDuration; }
2129
- });
2130
- Object.defineProperty(exports, "formatCallLogPreview", {
2131
- enumerable: true,
2132
- get: function () { return sdk.formatCallLogPreview; }
2133
- });
2134
- Object.defineProperty(exports, "isCallLogMessage", {
2135
- enumerable: true,
2136
- get: function () { return sdk.isCallLogMessage; }
2137
- });
2138
- Object.defineProperty(exports, "isMessageVisibleTo", {
2139
- enumerable: true,
2140
- get: function () { return sdk.isMessageVisibleTo; }
2141
- });
2142
- Object.defineProperty(exports, "isTombstone", {
2143
- enumerable: true,
2144
- get: function () { return sdk.isTombstone; }
2145
- });
2146
- Object.defineProperty(exports, "memoryStorage", {
2147
- enumerable: true,
2148
- get: function () { return sdk.memoryStorage; }
2149
- });
2150
- Object.defineProperty(exports, "mergeMessage", {
2151
- enumerable: true,
2152
- get: function () { return sdk.mergeMessage; }
2153
- });
2154
- Object.defineProperty(exports, "parseCallLog", {
2155
- enumerable: true,
2156
- get: function () { return sdk.parseCallLog; }
2157
- });
2158
- Object.defineProperty(exports, "parseCallLogBody", {
2159
- enumerable: true,
2160
- get: function () { return sdk.parseCallLogBody; }
2161
- });
2162
- Object.defineProperty(exports, "toTombstone", {
2163
- enumerable: true,
2164
- get: function () { return sdk.toTombstone; }
2651
+ function useBreakouts(conversationId, callId, opts = {}) {
2652
+ const { chat, value, setValue, error, pending, run } = useLiveValue(
2653
+ conversationId,
2654
+ callId,
2655
+ (c, id) => c.live.breakouts.get(id),
2656
+ (set) => ({ onBreakouts: (b) => set(() => b.status === "closed" ? null : b) })
2657
+ );
2658
+ const session = value ?? null;
2659
+ const [now, setNow] = react.useState(() => Date.now());
2660
+ const deadline = session?.status === "closing" ? session.returnAt : session?.endsAt;
2661
+ react.useEffect(() => {
2662
+ if (!deadline) return;
2663
+ const t = setInterval(() => setNow(Date.now()), 1e3);
2664
+ return () => clearInterval(t);
2665
+ }, [deadline]);
2666
+ const at = deadline ? Date.parse(deadline) : NaN;
2667
+ const secondsLeft = Number.isFinite(at) ? Math.max(0, Math.ceil((at - now) / 1e3)) : null;
2668
+ const open = react.useCallback(
2669
+ async (plan) => callId ? await run(() => chat.live.breakouts.open(callId, plan), setValue) !== null : false,
2670
+ [chat, callId, run, setValue]
2671
+ );
2672
+ const close = react.useCallback(
2673
+ async (afterSeconds) => callId ? await run(() => chat.live.breakouts.close(callId, afterSeconds), setValue) !== null : false,
2674
+ [chat, callId, run, setValue]
2675
+ );
2676
+ const join = react.useCallback(
2677
+ (roomId) => run(() => chat.live.breakouts.join(roomId)),
2678
+ [chat, run]
2679
+ );
2680
+ const returnToMain = react.useCallback(
2681
+ () => callId ? run(() => chat.live.breakouts.returnToMain(callId)) : Promise.resolve(null),
2682
+ [chat, callId, run]
2683
+ );
2684
+ const optsRef = react.useRef(opts);
2685
+ optsRef.current = opts;
2686
+ const inRoom = react.useRef(null);
2687
+ const myRoomId = session?.status === "open" ? session.myRoomId : null;
2688
+ react.useEffect(() => {
2689
+ if (!optsRef.current.auto || !callId) return;
2690
+ if (myRoomId && inRoom.current !== myRoomId) {
2691
+ const room = session?.rooms.find((r) => r.id === myRoomId);
2692
+ inRoom.current = myRoomId;
2693
+ void chat.live.breakouts.join(myRoomId).then((s) => room && optsRef.current.onJoinRoom?.(s, room)).catch(() => {
2694
+ inRoom.current = null;
2695
+ });
2696
+ } else if (!session && inRoom.current) {
2697
+ inRoom.current = null;
2698
+ void chat.live.breakouts.returnToMain(callId).then((s) => optsRef.current.onReturn?.(s)).catch(() => {
2699
+ });
2700
+ }
2701
+ }, [chat, callId, myRoomId, session]);
2702
+ return {
2703
+ session,
2704
+ myRoom: session?.rooms.find((r) => r.id === session.myRoomId) ?? null,
2705
+ secondsLeft,
2706
+ open,
2707
+ close,
2708
+ join,
2709
+ returnToMain,
2710
+ error,
2711
+ pending
2712
+ };
2713
+ }
2714
+ function useLobby(conversationId, callId = null) {
2715
+ const chat = usePoolse();
2716
+ const [lobby, setLobby] = react.useState(null);
2717
+ const [error, setError] = react.useState(null);
2718
+ const [pending, setPending] = react.useState(false);
2719
+ const seq = react.useRef(0);
2720
+ const target = react.useMemo(
2721
+ () => conversationId ? { conversationId, callId } : null,
2722
+ [conversationId, callId]
2723
+ );
2724
+ const refresh = react.useCallback(() => {
2725
+ if (!target) return;
2726
+ const mine = ++seq.current;
2727
+ chat.live.lobby.get(target).then((l) => {
2728
+ if (mine === seq.current) setLobby(l);
2729
+ }).catch((err) => {
2730
+ if (mine === seq.current) setError(asError(err));
2731
+ });
2732
+ }, [chat, target]);
2733
+ react.useEffect(() => {
2734
+ setLobby(null);
2735
+ setError(null);
2736
+ if (!target) return;
2737
+ refresh();
2738
+ const off = chat.live.subscribe(target.conversationId, target.callId ?? "", {
2739
+ onLobby: (l) => {
2740
+ seq.current++;
2741
+ setLobby(l);
2742
+ }
2743
+ });
2744
+ const offStatus = onReconnect2(chat, refresh);
2745
+ return () => {
2746
+ off();
2747
+ offStatus();
2748
+ };
2749
+ }, [chat, target, refresh]);
2750
+ const act = react.useCallback(async (fn) => {
2751
+ setPending(true);
2752
+ setError(null);
2753
+ try {
2754
+ const l = await fn();
2755
+ seq.current++;
2756
+ setLobby(l);
2757
+ return true;
2758
+ } catch (err) {
2759
+ setError(asError(err));
2760
+ return false;
2761
+ } finally {
2762
+ setPending(false);
2763
+ }
2764
+ }, []);
2765
+ const admit = react.useCallback(
2766
+ (id) => target ? act(() => chat.live.lobby.admit(target, id)) : Promise.resolve(false),
2767
+ [chat, target, act]
2768
+ );
2769
+ const deny = react.useCallback(
2770
+ (id) => target ? act(() => chat.live.lobby.deny(target, id)) : Promise.resolve(false),
2771
+ [chat, target, act]
2772
+ );
2773
+ const admitAll = react.useCallback(
2774
+ () => target ? act(() => chat.live.lobby.admitAll(target)) : Promise.resolve(false),
2775
+ [chat, target, act]
2776
+ );
2777
+ return { lobby, waitingCount: lobby?.waiting.length ?? 0, admit, deny, admitAll, error, pending };
2778
+ }
2779
+ function useMoments(conversationId, callId) {
2780
+ const add = (list, m) => (list ?? []).some((x) => x.id === m.id) ? list ?? [] : [...list ?? [], m];
2781
+ const { chat, value, setValue, error, pending, run } = useLiveValue(
2782
+ conversationId,
2783
+ callId,
2784
+ (c, id) => c.live.moments.list(id),
2785
+ (set) => ({ onMoment: (m) => set((prev) => add(prev, m)) })
2786
+ );
2787
+ const [lastMarked, setLast] = react.useState(null);
2788
+ const mark = react.useCallback(
2789
+ async (note) => {
2790
+ if (!callId) return null;
2791
+ const m = await run(
2792
+ () => chat.live.moments.mark(callId, note ? { note } : {}),
2793
+ (r) => setValue((prev) => add(prev, r))
2794
+ );
2795
+ if (m) setLast(m);
2796
+ return m;
2797
+ },
2798
+ [chat, callId, run, setValue]
2799
+ );
2800
+ return { moments: value ?? [], mark, lastMarked, error, pending };
2801
+ }
2802
+ function useAgenda(conversationId, callId) {
2803
+ const [overtime, setOvertime] = react.useState(null);
2804
+ const { chat, value, setValue, error, pending, run } = useLiveValue(
2805
+ conversationId,
2806
+ callId,
2807
+ (c, id) => c.live.agenda.get(id),
2808
+ (set) => ({
2809
+ onAgenda: (a) => set(() => a),
2810
+ onAgendaOvertime: (o) => setOvertime({ itemId: o.itemId, overByMs: o.overByMs })
2811
+ })
2812
+ );
2813
+ const agenda = value ?? null;
2814
+ const current = agenda?.items.find((i) => i.id === agenda.currentItemId) ?? null;
2815
+ const [now, setNow] = react.useState(() => Date.now());
2816
+ react.useEffect(() => {
2817
+ if (!current?.minutes || current.status !== "active") return;
2818
+ const t = setInterval(() => setNow(Date.now()), 5e3);
2819
+ return () => clearInterval(t);
2820
+ }, [current?.id, current?.minutes, current?.status]);
2821
+ react.useEffect(() => {
2822
+ setOvertime((o) => o && o.itemId !== current?.id ? null : o);
2823
+ }, [current?.id]);
2824
+ const act = react.useCallback(
2825
+ async (fn) => await run(fn, setValue) !== null,
2826
+ [run, setValue]
2827
+ );
2828
+ return {
2829
+ agenda,
2830
+ current,
2831
+ overrunMs: current ? sdk.agendaOverrunMs(current, now) : 0,
2832
+ overtime,
2833
+ start: react.useCallback(
2834
+ (id) => callId ? act(() => chat.live.agenda.start(callId, id)) : Promise.resolve(false),
2835
+ [chat, callId, act]
2836
+ ),
2837
+ done: react.useCallback(
2838
+ (id) => callId ? act(() => chat.live.agenda.done(callId, id)) : Promise.resolve(false),
2839
+ [chat, callId, act]
2840
+ ),
2841
+ reopen: react.useCallback(
2842
+ (id) => callId ? act(() => chat.live.agenda.reopen(callId, id)) : Promise.resolve(false),
2843
+ [chat, callId, act]
2844
+ ),
2845
+ error,
2846
+ pending
2847
+ };
2848
+ }
2849
+ function useCallReactions(room, opts = {}) {
2850
+ const visibleMs = opts.visibleMs ?? 4e3;
2851
+ const max = opts.max ?? 30;
2852
+ const [reactions, setReactions] = react.useState([]);
2853
+ const ref = react.useRef(null);
2854
+ react.useEffect(() => {
2855
+ setReactions([]);
2856
+ if (!room) return;
2857
+ const r = new sdk.CallReactions(room);
2858
+ ref.current = r;
2859
+ const timers = /* @__PURE__ */ new Set();
2860
+ const off = r.subscribe((reaction) => {
2861
+ setReactions((list) => [...list, reaction].slice(-max));
2862
+ const t = setTimeout(() => {
2863
+ timers.delete(t);
2864
+ setReactions((list) => list.filter((x) => x.id !== reaction.id));
2865
+ }, visibleMs);
2866
+ timers.add(t);
2867
+ });
2868
+ return () => {
2869
+ off();
2870
+ timers.forEach(clearTimeout);
2871
+ r.destroy();
2872
+ ref.current = null;
2873
+ };
2874
+ }, [room, visibleMs, max]);
2875
+ const send = react.useCallback(
2876
+ (emoji) => ref.current?.send(emoji) ?? Promise.resolve(false),
2877
+ []
2878
+ );
2879
+ return { reactions, send };
2880
+ }
2881
+ function useScreenAnnotations(room, sharerUserId, opts = {}) {
2882
+ const [state, setState] = react.useState(null);
2883
+ const [annotations, setAnnotations] = react.useState(null);
2884
+ const fadeMs = opts.fadeMs;
2885
+ react.useEffect(() => {
2886
+ setState(null);
2887
+ setAnnotations(null);
2888
+ if (!room || !sharerUserId) return;
2889
+ const layer = new sdk.ScreenAnnotations(room, sharerUserId, fadeMs ? { fadeMs } : {});
2890
+ setAnnotations(layer);
2891
+ const off = layer.subscribe(setState);
2892
+ return () => {
2893
+ off();
2894
+ layer.destroy();
2895
+ };
2896
+ }, [room, sharerUserId, fadeMs]);
2897
+ return { state, annotations };
2898
+ }
2899
+ function useCallQuality(room, opts = {}) {
2900
+ const chat = usePoolse();
2901
+ const [report, setReport] = react.useState(null);
2902
+ const intervalMs = opts.intervalMs;
2903
+ const callId = opts.callId ?? null;
2904
+ react.useEffect(() => {
2905
+ setReport(null);
2906
+ if (!room) return;
2907
+ const monitor = new sdk.CallQualityMonitor(room, {
2908
+ ...intervalMs ? { intervalMs } : {},
2909
+ ...callId ? { report: (body) => chat.live.quality.report(callId, body) } : {}
2910
+ });
2911
+ const off = monitor.subscribe(setReport);
2912
+ return () => {
2913
+ off();
2914
+ monitor.stop();
2915
+ };
2916
+ }, [chat, room, intervalMs, callId]);
2917
+ return report;
2918
+ }
2919
+ function useCallMeeting(conversationId, callId) {
2920
+ const { value, refresh } = useLiveValue(
2921
+ conversationId,
2922
+ callId,
2923
+ (c, id) => c.live.meeting(id),
2924
+ (set) => ({
2925
+ onAttendees: (attendees2) => set((m) => m ? { ...m, attendees: attendees2 } : m),
2926
+ onQuality: (q) => set((m) => m ? { ...m, quality: { ...m.quality, [q.identity]: q } } : m),
2927
+ onCaptions: (c) => set((m) => m ? { ...m, captionsUserIds: c.userIds } : m),
2928
+ onBreakouts: (b) => set((m) => m ? { ...m, breakout: b.status === "closed" ? null : b } : m),
2929
+ onLobby: (l) => set((m) => m ? { ...m, lobbyWaiting: l.waiting.length } : m),
2930
+ onStage: (s) => set((m) => m ? { ...m, stage: s.mode === "stage", roles: s.roles, hands: s.hands } : m)
2931
+ })
2932
+ );
2933
+ const attendees = react.useMemo(() => value?.attendees ?? [], [value]);
2934
+ const nameOf = react.useCallback(
2935
+ (identity, nameFor) => {
2936
+ const a = attendees.find((x) => x.identity === identity);
2937
+ if (a) return a.name;
2938
+ return sdk.meetingNameOf(identity, nameFor?.(identity) ?? null);
2939
+ },
2940
+ [attendees]
2941
+ );
2942
+ return { meeting: value, attendees, quality: value?.quality ?? {}, nameOf, refresh };
2943
+ }
2944
+ function useCaptions(conversationId, callId, selfUserId) {
2945
+ const { chat, value, setValue, error, pending, run } = useLiveValue(
2946
+ conversationId,
2947
+ callId,
2948
+ async (c, id) => (await c.live.meeting(id)).captionsUserIds,
2949
+ (set) => ({ onCaptions: (cap) => set(() => cap.userIds) })
2950
+ );
2951
+ const userIds = react.useMemo(() => value ?? [], [value]);
2952
+ const on = !!selfUserId && userIds.includes(selfUserId);
2953
+ const setOn = react.useCallback(
2954
+ async (next) => {
2955
+ if (!callId) return false;
2956
+ const r = await run(
2957
+ () => chat.live.captions.set(callId, next),
2958
+ (cap) => setValue(() => cap.userIds)
2959
+ );
2960
+ return r !== null;
2961
+ },
2962
+ [chat, callId, run, setValue]
2963
+ );
2964
+ const toggle = react.useCallback(() => setOn(!on), [setOn, on]);
2965
+ return { on, userIds, setOn, toggle, error, pending };
2966
+ }
2967
+ function useWhiteboard(callId, Y, opts = {}) {
2968
+ const chat = usePoolse();
2969
+ const [items, setItems] = react.useState([]);
2970
+ const [board, setBoard] = react.useState(null);
2971
+ const [error, setError] = react.useState(null);
2972
+ const optsRef = react.useRef(opts);
2973
+ optsRef.current = opts;
2974
+ const selfUserId = opts.selfUserId ?? null;
2975
+ react.useEffect(() => {
2976
+ setItems([]);
2977
+ setBoard(null);
2978
+ setError(null);
2979
+ if (!callId || !Y) return;
2980
+ let cancelled = false;
2981
+ let open = null;
2982
+ let off = null;
2983
+ const access = () => optsRef.current.access?.(callId) ?? chat.live.whiteboard(callId);
2984
+ access().then((a) => {
2985
+ if (cancelled) return;
2986
+ open = sdk.openWhiteboard(chat, Y, a, { selfUserId, refreshAccess: access });
2987
+ off = open.model.subscribe(setItems);
2988
+ setBoard(open);
2989
+ }).catch((err) => {
2990
+ if (!cancelled) setError(asError(err));
2991
+ });
2992
+ return () => {
2993
+ cancelled = true;
2994
+ off?.();
2995
+ open?.close();
2996
+ };
2997
+ }, [chat, callId, Y, selfUserId]);
2998
+ return { items, model: board?.model ?? null, readOnly: board ? board.readOnly() : true, error };
2999
+ }
3000
+ function useRoomPresence() {
3001
+ const chat = usePoolse();
3002
+ const { me } = useMe();
3003
+ const meId = me?.id ?? null;
3004
+ const [rooms, setRooms] = react.useState([]);
3005
+ const [presence, setPresence] = react.useState({});
3006
+ const refresh = react.useCallback(() => {
3007
+ chat.live.rooms().then((list) => {
3008
+ setRooms(list);
3009
+ setPresence((p) => {
3010
+ const next = { ...p };
3011
+ for (const r of list) next[r.conversationId] = r.presence;
3012
+ return next;
3013
+ });
3014
+ }).catch(() => {
3015
+ });
3016
+ }, [chat]);
3017
+ react.useEffect(() => {
3018
+ if (!meId) return;
3019
+ refresh();
3020
+ const off = chat.live.subscribeUser(meId, {
3021
+ onRoomParticipants: (r) => {
3022
+ setPresence((p) => ({ ...p, [r.conversationId]: r }));
3023
+ setRooms(
3024
+ (list) => list.map(
3025
+ (room) => room.conversationId === r.conversationId ? { ...room, presence: r } : room
3026
+ )
3027
+ );
3028
+ }
3029
+ });
3030
+ const offStatus = onReconnect2(chat, refresh);
3031
+ return () => {
3032
+ off();
3033
+ offStatus();
3034
+ };
3035
+ }, [chat, meId, refresh]);
3036
+ return { rooms, presence, refresh };
3037
+ }
3038
+ function useRecording(callId, conversationId, initial) {
3039
+ const chat = usePoolse();
3040
+ const meId = useMeId(chat);
3041
+ const [state, setState] = react.useState(
3042
+ () => initial && initial.id === callId ? { recording: initial.recording ?? null, transcription: initial.transcription ?? null } : { recording: null, transcription: null }
3043
+ );
3044
+ const [notice, setNotice] = react.useState(null);
3045
+ const [lastRecording, setLastRecording] = react.useState(null);
3046
+ const [pending, setPending] = react.useState(false);
3047
+ const [error, setError] = react.useState(null);
3048
+ const [transcriptConsent, setTranscriptConsent] = react.useState(false);
3049
+ const seq = react.useRef(0);
3050
+ const hasInitial = react.useRef(!!initial && initial.id === callId);
3051
+ const refresh = react.useCallback(() => {
3052
+ if (!callId || !conversationId) return;
3053
+ const mine = ++seq.current;
3054
+ chat.liveCalls.get(conversationId).then((c) => {
3055
+ if (mine !== seq.current) return;
3056
+ if (c && c.id === callId)
3057
+ setState({ recording: c.recording ?? null, transcription: c.transcription ?? null });
3058
+ else
3059
+ setState((s) => ({
3060
+ recording: s.recording ? { ...s.recording, active: false } : null,
3061
+ transcription: s.transcription ? { ...s.transcription, active: false } : null
3062
+ }));
3063
+ }).catch(() => {
3064
+ });
3065
+ }, [chat, callId, conversationId]);
3066
+ react.useEffect(() => {
3067
+ if (!callId || !conversationId) {
3068
+ setState({ recording: null, transcription: null });
3069
+ return;
3070
+ }
3071
+ if (hasInitial.current) hasInitial.current = false;
3072
+ else refresh();
3073
+ const offCapture = subscribeCapture(chat, conversationId, callId, (e) => {
3074
+ seq.current++;
3075
+ setState((s) => applyCaptureEvent(s, e));
3076
+ if (e.type === "recording:started") {
3077
+ setNotice(e.evt.notice);
3078
+ setLastRecording(e.evt.recording);
3079
+ } else if (e.type === "recording:stopped" || e.type === "recording:ready") {
3080
+ setLastRecording(e.evt.recording);
3081
+ }
3082
+ });
3083
+ const conv = chat.realtime.conversation(conversationId);
3084
+ const offFinished = conv.onCallFinished((evt) => {
3085
+ if (evt.call_id !== callId) return;
3086
+ seq.current++;
3087
+ setState((s) => ({
3088
+ recording: s.recording ? { ...s.recording, active: false } : null,
3089
+ transcription: s.transcription ? { ...s.transcription, active: false } : null
3090
+ }));
3091
+ });
3092
+ const offStatus = onReconnect(chat, refresh);
3093
+ return () => {
3094
+ offCapture();
3095
+ offFinished();
3096
+ offStatus();
3097
+ };
3098
+ }, [chat, callId, conversationId, refresh]);
3099
+ const transcribing = !!state.transcription?.active;
3100
+ react.useEffect(() => {
3101
+ if (!conversationId || !transcribing) {
3102
+ setTranscriptConsent(false);
3103
+ return;
3104
+ }
3105
+ let cancelled = false;
3106
+ chat.calls.recording.settings(conversationId).then((s) => {
3107
+ if (!cancelled) setTranscriptConsent(s.effective.consent === "required");
3108
+ }).catch(() => {
3109
+ });
3110
+ return () => {
3111
+ cancelled = true;
3112
+ };
3113
+ }, [chat, conversationId, transcribing]);
3114
+ const run = react.useCallback(async (fn) => {
3115
+ setPending(true);
3116
+ setError(null);
3117
+ try {
3118
+ await fn();
3119
+ return true;
3120
+ } catch (err) {
3121
+ setError(err instanceof Error ? err : new Error(String(err)));
3122
+ return false;
3123
+ } finally {
3124
+ setPending(false);
3125
+ }
3126
+ }, []);
3127
+ const start = react.useCallback(
3128
+ (mode) => run(async () => {
3129
+ if (!callId) throw new Error("no call");
3130
+ const r = await chat.calls.recording.start(callId, mode ? { mode } : {});
3131
+ setLastRecording(r);
3132
+ }),
3133
+ [chat, callId, run]
3134
+ );
3135
+ const stop = react.useCallback(
3136
+ () => run(async () => {
3137
+ if (!callId) throw new Error("no call");
3138
+ const r = await chat.calls.recording.stop(callId);
3139
+ setLastRecording(r);
3140
+ }),
3141
+ [chat, callId, run]
3142
+ );
3143
+ const consent = react.useCallback(
3144
+ (decision) => run(async () => {
3145
+ if (!callId) throw new Error("no call");
3146
+ const res = await chat.calls.consent(callId, decision);
3147
+ setState(
3148
+ (s) => applyCaptureEvent(s, {
3149
+ type: "recording:consent",
3150
+ evt: { cv: 1, call_id: res.call_id, user_id: res.user_id, decision: res.decision }
3151
+ })
3152
+ );
3153
+ }),
3154
+ [chat, callId, run]
3155
+ );
3156
+ const rec = state.recording;
3157
+ const active = !!rec?.active;
3158
+ const capturing = active || transcribing;
3159
+ const consentRequired = active && !!rec?.consent_required || transcribing && transcriptConsent;
3160
+ const myConsent = meId && rec ? rec.consent.accepted.includes(meId) || active && rec.started_by_user_id === meId ? "accepted" : rec.consent.declined.includes(meId) ? "declined" : null : null;
3161
+ return {
3162
+ available: rec?.available ?? false,
3163
+ active,
3164
+ recording: rec,
3165
+ transcription: state.transcription,
3166
+ capturing,
3167
+ consentRequired,
3168
+ myConsent,
3169
+ needsConsent: capturing && consentRequired && myConsent !== "accepted",
3170
+ notice,
3171
+ lastRecording,
3172
+ pending,
3173
+ error,
3174
+ start,
3175
+ stop,
3176
+ consent,
3177
+ refresh
3178
+ };
3179
+ }
3180
+ function useLiveTranscript(callId, opts = {}) {
3181
+ const chat = usePoolse();
3182
+ const enabled = opts.enabled ?? true;
3183
+ const max = opts.maxSegments ?? 1e3;
3184
+ const [segments, setSegments] = react.useState([]);
3185
+ const [transcript, setTranscript] = react.useState(null);
3186
+ const [conversationId, setConversationId] = react.useState(null);
3187
+ const [joined, setJoined] = react.useState(false);
3188
+ const [error, setError] = react.useState(null);
3189
+ const [pending, setPending] = react.useState(false);
3190
+ react.useEffect(() => {
3191
+ setSegments([]);
3192
+ setTranscript(null);
3193
+ setJoined(false);
3194
+ setError(null);
3195
+ if (!callId || !enabled) return;
3196
+ let handle;
3197
+ try {
3198
+ handle = chat.realtime.transcript(callId);
3199
+ } catch (err) {
3200
+ setError(err instanceof Error ? err : new Error(String(err)));
3201
+ return;
3202
+ }
3203
+ const offJoined = handle.onJoined((reply) => {
3204
+ setJoined(true);
3205
+ setError(null);
3206
+ setConversationId(reply.conversation_id || null);
3207
+ setTranscript(reply.transcript);
3208
+ setSegments(reply.segments.slice(-max).map((s) => ({ ...s, final: true })));
3209
+ });
3210
+ const offSegment = handle.onSegment((evt) => {
3211
+ const { cv: _cv, call_id: _call, transcript_id: _t, ...seg } = evt;
3212
+ setSegments((list) => sdk.applyLiveSegment(list, seg, max));
3213
+ });
3214
+ const offError = handle.onError((reason) => {
3215
+ setJoined(false);
3216
+ setError(new Error(reason));
3217
+ });
3218
+ return () => {
3219
+ offJoined();
3220
+ offSegment();
3221
+ offError();
3222
+ handle.release();
3223
+ };
3224
+ }, [chat, callId, enabled, max]);
3225
+ react.useEffect(() => {
3226
+ if (!callId || !conversationId || !enabled) return;
3227
+ const conv = chat.realtime.conversation(conversationId);
3228
+ const apply = (evt) => {
3229
+ if (evt.call_id === callId) setTranscript(evt.transcript);
3230
+ };
3231
+ const offs = [
3232
+ conv.onTranscriptStarted(apply),
3233
+ conv.onTranscriptStopped(apply),
3234
+ conv.onTranscriptReady(apply),
3235
+ conv.onTranscriptSpeakers((evt) => {
3236
+ if (evt.call_id !== callId) return;
3237
+ const names = new Map(evt.speakers.map((s) => [s.key, s.name]));
3238
+ setSegments(
3239
+ (list) => list.map(
3240
+ (s) => names.has(s.speaker) ? { ...s, speaker_name: names.get(s.speaker) } : s
3241
+ )
3242
+ );
3243
+ })
3244
+ ];
3245
+ return () => offs.forEach((off) => off());
3246
+ }, [chat, callId, conversationId, enabled]);
3247
+ const run = react.useCallback(async (fn) => {
3248
+ setPending(true);
3249
+ setError(null);
3250
+ try {
3251
+ setTranscript(await fn());
3252
+ return true;
3253
+ } catch (err) {
3254
+ setError(err instanceof Error ? err : new Error(String(err)));
3255
+ return false;
3256
+ } finally {
3257
+ setPending(false);
3258
+ }
3259
+ }, []);
3260
+ const start = react.useCallback(
3261
+ () => callId ? run(() => chat.calls.transcription.start(callId)) : Promise.resolve(false),
3262
+ [chat, callId, run]
3263
+ );
3264
+ const stop = react.useCallback(
3265
+ () => callId ? run(() => chat.calls.transcription.stop(callId)) : Promise.resolve(false),
3266
+ [chat, callId, run]
3267
+ );
3268
+ const finals = react.useMemo(() => segments.filter((s) => s.final), [segments]);
3269
+ const interim = react.useMemo(() => segments.filter((s) => !s.final), [segments]);
3270
+ return {
3271
+ segments,
3272
+ finals,
3273
+ interim,
3274
+ transcript,
3275
+ live: transcript?.status === "live",
3276
+ joined,
3277
+ error,
3278
+ pending,
3279
+ start,
3280
+ stop
3281
+ };
3282
+ }
3283
+ function withSpeakers(t, speakers) {
3284
+ const names = new Map(speakers.map((s) => [s.key, s.name]));
3285
+ return {
3286
+ ...t,
3287
+ speakers,
3288
+ segments: t.segments.map(
3289
+ (s) => names.has(s.speaker) ? { ...s, speaker_name: names.get(s.speaker) ?? null } : s
3290
+ )
3291
+ };
3292
+ }
3293
+ function useTranscript(callId) {
3294
+ const chat = usePoolse();
3295
+ const [transcript, setTranscript] = react.useState(null);
3296
+ const [loading, setLoading] = react.useState(!!callId);
3297
+ const [missing, setMissing] = react.useState(false);
3298
+ const [error, setError] = react.useState(null);
3299
+ const seq = react.useRef(0);
3300
+ const refresh = react.useCallback(() => {
3301
+ if (!callId) return;
3302
+ const mine = ++seq.current;
3303
+ setLoading(true);
3304
+ chat.calls.transcript.get(callId).then((t) => {
3305
+ if (mine !== seq.current) return;
3306
+ setTranscript(t);
3307
+ setMissing(false);
3308
+ setError(null);
3309
+ }).catch((err) => {
3310
+ if (mine !== seq.current) return;
3311
+ if (err instanceof sdk.ApiError && err.status === 404) {
3312
+ setMissing(true);
3313
+ setTranscript(null);
3314
+ } else setError(err instanceof Error ? err : new Error(String(err)));
3315
+ }).finally(() => {
3316
+ if (mine === seq.current) setLoading(false);
3317
+ });
3318
+ }, [chat, callId]);
3319
+ react.useEffect(() => {
3320
+ setTranscript(null);
3321
+ setMissing(false);
3322
+ setError(null);
3323
+ setLoading(!!callId);
3324
+ refresh();
3325
+ }, [callId, refresh]);
3326
+ const conversationId = transcript?.conversation_id ?? null;
3327
+ react.useEffect(() => {
3328
+ if (!callId || !conversationId) return;
3329
+ const conv = chat.realtime.conversation(conversationId);
3330
+ const offSpeakers = conv.onTranscriptSpeakers((evt) => {
3331
+ if (evt.call_id !== callId) return;
3332
+ seq.current++;
3333
+ setTranscript((t) => t ? withSpeakers(t, evt.speakers) : t);
3334
+ });
3335
+ const offReady = conv.onTranscriptReady((evt) => {
3336
+ if (evt.call_id === callId) refresh();
3337
+ });
3338
+ const offStatus = onReconnect(chat, refresh);
3339
+ return () => {
3340
+ offSpeakers();
3341
+ offReady();
3342
+ offStatus();
3343
+ };
3344
+ }, [chat, callId, conversationId, refresh]);
3345
+ const renameSpeakers = react.useCallback(
3346
+ async (names) => {
3347
+ if (!callId) return;
3348
+ const t = await chat.calls.transcript.renameSpeakers(callId, names);
3349
+ seq.current++;
3350
+ setTranscript(t);
3351
+ },
3352
+ [chat, callId]
3353
+ );
3354
+ return { transcript, loading, missing, error, renameSpeakers, refresh };
3355
+ }
3356
+ function useCaptureList(conversationId, load, subscribe) {
3357
+ const chat = usePoolse();
3358
+ const [items, setItems] = react.useState([]);
3359
+ const [loading, setLoading] = react.useState(!!conversationId);
3360
+ const [error, setError] = react.useState(null);
3361
+ const seq = react.useRef(0);
3362
+ const loadRef = react.useRef(load);
3363
+ loadRef.current = load;
3364
+ const subscribeRef = react.useRef(subscribe);
3365
+ subscribeRef.current = subscribe;
3366
+ const refresh = react.useCallback(() => {
3367
+ if (!conversationId) return;
3368
+ const mine = ++seq.current;
3369
+ setLoading(true);
3370
+ loadRef.current(conversationId).then((list) => {
3371
+ if (mine !== seq.current) return;
3372
+ setItems(list);
3373
+ setError(null);
3374
+ }).catch((err) => {
3375
+ if (mine === seq.current) setError(err instanceof Error ? err : new Error(String(err)));
3376
+ }).finally(() => {
3377
+ if (mine === seq.current) setLoading(false);
3378
+ });
3379
+ }, [conversationId]);
3380
+ react.useEffect(() => {
3381
+ setItems([]);
3382
+ if (!conversationId) {
3383
+ setLoading(false);
3384
+ return;
3385
+ }
3386
+ refresh();
3387
+ const off = subscribeRef.current(conversationId, refresh);
3388
+ const offStatus = onReconnect(chat, refresh);
3389
+ return () => {
3390
+ off();
3391
+ offStatus();
3392
+ };
3393
+ }, [chat, conversationId, refresh]);
3394
+ return { items, loading, error, refresh };
3395
+ }
3396
+ function useTranscripts(conversationId, opts = {}) {
3397
+ const chat = usePoolse();
3398
+ return useCaptureList(
3399
+ conversationId,
3400
+ (id) => chat.calls.transcript.list(id, opts.limit !== void 0 ? { limit: opts.limit } : {}),
3401
+ (id, refresh) => {
3402
+ const conv = chat.realtime.conversation(id);
3403
+ const offs = [conv.onTranscriptStarted(refresh), conv.onTranscriptReady(refresh)];
3404
+ return () => offs.forEach((off) => off());
3405
+ }
3406
+ );
3407
+ }
3408
+ function useRecordings(conversationId, opts = {}) {
3409
+ const chat = usePoolse();
3410
+ return useCaptureList(
3411
+ conversationId,
3412
+ (id) => chat.calls.recording.list(id, opts.limit !== void 0 ? { limit: opts.limit } : {}),
3413
+ (id, refresh) => {
3414
+ const conv = chat.realtime.conversation(id);
3415
+ const offs = [
3416
+ conv.onRecordingStarted(refresh),
3417
+ conv.onRecordingStopped(refresh),
3418
+ conv.onRecordingReady(refresh)
3419
+ ];
3420
+ return () => offs.forEach((off) => off());
3421
+ }
3422
+ );
3423
+ }
3424
+ function useReadReceipts() {
3425
+ const chat = usePoolse();
3426
+ const { me } = useMe();
3427
+ const state = receiptsOf(me);
3428
+ const setShared = react.useCallback(
3429
+ async (share) => {
3430
+ await chat.me.update({ read_receipts: share });
3431
+ },
3432
+ [chat]
3433
+ );
3434
+ return { ...state, setShared };
3435
+ }
3436
+ function receiptsOf(me) {
3437
+ const r = me?.read_receipts;
3438
+ return {
3439
+ visible: r?.visible ?? true,
3440
+ mode: r?.mode ?? "on",
3441
+ shared: r?.shared ?? true,
3442
+ canChange: r?.can_change ?? false
3443
+ };
3444
+ }
3445
+ var EDIT_WINDOW_MS = 15 * 60 * 1e3;
3446
+ function canEditOwnMessage(args) {
3447
+ if (!args.isSelf || args.deleted) return false;
3448
+ if (args.receiptsVisible) return (args.readState ?? "sent") === "sent";
3449
+ const sent = Date.parse(args.insertedAt);
3450
+ return Number.isFinite(sent) && (args.now ?? Date.now()) - sent < EDIT_WINDOW_MS;
3451
+ }
3452
+ function useApprovals(opts = {}) {
3453
+ const chat = usePoolse();
3454
+ const pollMs = opts.pollMs ?? 6e4;
3455
+ const [approvals, setApprovals] = react.useState(() => chat.approvals.pending());
3456
+ const [loading, setLoading] = react.useState(true);
3457
+ const [error, setError] = react.useState(null);
3458
+ const mounted = react.useRef(true);
3459
+ const refresh = react.useCallback(async () => {
3460
+ try {
3461
+ await chat.approvals.list();
3462
+ if (mounted.current) setError(null);
3463
+ } catch (err) {
3464
+ if (mounted.current) setError(err instanceof Error ? err : new Error(String(err)));
3465
+ } finally {
3466
+ if (mounted.current) setLoading(false);
3467
+ }
3468
+ }, [chat]);
3469
+ react.useEffect(() => {
3470
+ mounted.current = true;
3471
+ const off = chat.approvals.subscribe(() => setApprovals(chat.approvals.pending()));
3472
+ setApprovals(chat.approvals.pending());
3473
+ void refresh();
3474
+ void chat.agents.list().catch(() => void 0);
3475
+ const offStatus = onReconnect(chat, () => void refresh());
3476
+ const timer = pollMs > 0 ? setInterval(() => void refresh(), pollMs) : null;
3477
+ return () => {
3478
+ mounted.current = false;
3479
+ off();
3480
+ offStatus();
3481
+ if (timer) clearInterval(timer);
3482
+ };
3483
+ }, [chat, refresh, pollMs]);
3484
+ const approve = react.useCallback(
3485
+ (id, reason) => chat.approvals.approve(id, reason !== void 0 ? { reason } : {}),
3486
+ [chat]
3487
+ );
3488
+ const deny = react.useCallback(
3489
+ (id, reason) => chat.approvals.deny(id, reason !== void 0 ? { reason } : {}),
3490
+ [chat]
3491
+ );
3492
+ return { approvals, loading, error, refresh, approve, deny };
3493
+ }
3494
+ function useApproval(source) {
3495
+ const chat = usePoolse();
3496
+ const id = typeof source === "string" ? source : source?.id ?? null;
3497
+ const sourceRef = react.useRef(source);
3498
+ sourceRef.current = source;
3499
+ const read = () => id ? chat.approvals.peek(id) ?? (typeof sourceRef.current === "object" ? sourceRef.current : null) : null;
3500
+ const [approval, setApproval] = react.useState(read);
3501
+ const [loading, setLoading] = react.useState(() => !!id && !read());
3502
+ const [pending, setPending] = react.useState(null);
3503
+ const [error, setError] = react.useState(null);
3504
+ react.useEffect(() => {
3505
+ if (!id) {
3506
+ setApproval(null);
3507
+ setLoading(false);
3508
+ return;
3509
+ }
3510
+ const given = sourceRef.current;
3511
+ if (given && typeof given === "object") chat.approvals._apply(given);
3512
+ const update = () => setApproval(read());
3513
+ const off = chat.approvals.subscribe(update);
3514
+ update();
3515
+ let live = true;
3516
+ if (!chat.approvals.peek(id)) {
3517
+ setLoading(true);
3518
+ void chat.approvals.ensure(id).catch(() => null).finally(() => {
3519
+ if (live) {
3520
+ setLoading(false);
3521
+ update();
3522
+ }
3523
+ });
3524
+ }
3525
+ return () => {
3526
+ live = false;
3527
+ off();
3528
+ };
3529
+ }, [chat, id]);
3530
+ const decide = react.useCallback(
3531
+ async (action, reason) => {
3532
+ if (!id) return;
3533
+ setPending(action);
3534
+ setError(null);
3535
+ try {
3536
+ const opts = reason !== void 0 ? { reason } : {};
3537
+ await (action === "approve" ? chat.approvals.approve(id, opts) : chat.approvals.deny(id, opts));
3538
+ } catch (err) {
3539
+ setError(err instanceof Error ? err : new Error(String(err)));
3540
+ throw err;
3541
+ } finally {
3542
+ setPending(null);
3543
+ }
3544
+ },
3545
+ [chat, id]
3546
+ );
3547
+ return {
3548
+ approval,
3549
+ loading,
3550
+ pending,
3551
+ error,
3552
+ approve: (reason) => decide("approve", reason),
3553
+ deny: (reason) => decide("deny", reason)
3554
+ };
3555
+ }
3556
+ var asError2 = (err) => err instanceof Error ? err : new Error(String(err));
3557
+ function useCallAgents(conversationId, callId) {
3558
+ const chat = usePoolse();
3559
+ const [agents, setAgents] = react.useState([]);
3560
+ const [directory, setDirectory] = react.useState([]);
3561
+ const [loading, setLoading] = react.useState(!!callId);
3562
+ const [error, setError] = react.useState(null);
3563
+ const [pending, setPending] = react.useState(null);
3564
+ const [said, setSaid] = react.useState(null);
3565
+ const [nonce, setNonce] = react.useState(0);
3566
+ react.useEffect(() => {
3567
+ setSaid(null);
3568
+ if (!callId || !conversationId) {
3569
+ setAgents([]);
3570
+ setLoading(false);
3571
+ return;
3572
+ }
3573
+ const controller = new AbortController();
3574
+ const load = () => chat.callAgents.list(callId, controller.signal).then((list) => {
3575
+ if (controller.signal.aborted) return;
3576
+ setAgents(list);
3577
+ setError(null);
3578
+ }).catch((err) => {
3579
+ if (!controller.signal.aborted) setError(asError2(err));
3580
+ }).finally(() => {
3581
+ if (!controller.signal.aborted) setLoading(false);
3582
+ });
3583
+ setLoading(true);
3584
+ void load();
3585
+ const off = chat.callAgents.subscribe(conversationId, callId, {
3586
+ onAgents: setAgents,
3587
+ onSaid: setSaid
3588
+ });
3589
+ const offRe = onReconnect(chat, () => void load());
3590
+ return () => {
3591
+ controller.abort();
3592
+ off();
3593
+ offRe();
3594
+ };
3595
+ }, [chat, conversationId, callId, nonce]);
3596
+ react.useEffect(() => {
3597
+ let live = true;
3598
+ chat.agents.list().then((list) => live && setDirectory(list)).catch(() => void 0);
3599
+ return () => {
3600
+ live = false;
3601
+ };
3602
+ }, [chat]);
3603
+ const available = react.useMemo(() => {
3604
+ const inCall = new Set(agents.map((a) => a.agentId));
3605
+ return directory.filter(
3606
+ (a) => a.status === "active" && !a.stopped && a.voiceEnabled && !inCall.has(a.id)
3607
+ );
3608
+ }, [agents, directory]);
3609
+ const run = react.useCallback(async (agentId, fn) => {
3610
+ setPending(agentId);
3611
+ setError(null);
3612
+ try {
3613
+ await fn();
3614
+ } catch (err) {
3615
+ setError(asError2(err));
3616
+ throw err;
3617
+ } finally {
3618
+ setPending(null);
3619
+ }
3620
+ }, []);
3621
+ const upsert = (a) => setAgents((prev) => {
3622
+ const i = prev.findIndex((x) => x.agentId === a.agentId);
3623
+ return i < 0 ? [...prev, a] : prev.map((x, j) => j === i ? a : x);
3624
+ });
3625
+ const invite = react.useCallback(
3626
+ (agentId, mode = "notetaker") => run(agentId, async () => {
3627
+ if (callId) upsert(await chat.callAgents.invite(callId, agentId, mode));
3628
+ }),
3629
+ [chat, callId, run]
3630
+ );
3631
+ const setMode = react.useCallback(
3632
+ (agentId, mode) => run(agentId, async () => {
3633
+ if (callId) upsert(await chat.callAgents.setMode(callId, agentId, mode));
3634
+ }),
3635
+ [chat, callId, run]
3636
+ );
3637
+ const remove = react.useCallback(
3638
+ (agentId) => run(agentId, async () => {
3639
+ if (!callId) return;
3640
+ await chat.callAgents.remove(callId, agentId);
3641
+ setAgents((prev) => prev.filter((x) => x.agentId !== agentId));
3642
+ }),
3643
+ [chat, callId, run]
3644
+ );
3645
+ const agentFor = react.useCallback(
3646
+ (identity) => agents.find((a) => a.userId === identity) ?? null,
3647
+ [agents]
3648
+ );
3649
+ const refresh = react.useCallback(() => setNonce((n) => n + 1), []);
3650
+ return {
3651
+ agents,
3652
+ available,
3653
+ loading,
3654
+ error,
3655
+ pending,
3656
+ invite,
3657
+ setMode,
3658
+ remove,
3659
+ said,
3660
+ agentFor,
3661
+ refresh
3662
+ };
3663
+ }
3664
+ function useWhisper(callId) {
3665
+ const chat = usePoolse();
3666
+ const { me } = useMe();
3667
+ const userId = me?.id ?? null;
3668
+ const [whisper, setWhisper] = react.useState(null);
3669
+ const [hints, setHints] = react.useState([]);
3670
+ const [latest, setLatest] = react.useState(null);
3671
+ const [loading, setLoading] = react.useState(!!callId);
3672
+ const [pending, setPending] = react.useState(false);
3673
+ const [error, setError] = react.useState(null);
3674
+ const onRef = react.useRef(false);
3675
+ onRef.current = whisper?.on ?? false;
3676
+ const merge = react.useCallback((list) => {
3677
+ setHints((prev) => {
3678
+ const byId = new Map(prev.map((h) => [h.id, h]));
3679
+ for (const h of list) byId.set(h.id, h);
3680
+ return [...byId.values()].sort((a, b) => (a.at ?? "").localeCompare(b.at ?? ""));
3681
+ });
3682
+ }, []);
3683
+ react.useEffect(() => {
3684
+ setHints([]);
3685
+ setLatest(null);
3686
+ setWhisper(null);
3687
+ if (!callId) {
3688
+ setLoading(false);
3689
+ return;
3690
+ }
3691
+ const controller = new AbortController();
3692
+ const load = () => chat.callAgents.whisper.get(callId, controller.signal).then((res) => {
3693
+ if (controller.signal.aborted) return;
3694
+ setWhisper(res.whisper);
3695
+ merge(res.hints);
3696
+ setError(null);
3697
+ }).catch((err) => {
3698
+ if (!controller.signal.aborted) setError(asError2(err));
3699
+ }).finally(() => {
3700
+ if (!controller.signal.aborted) setLoading(false);
3701
+ });
3702
+ setLoading(true);
3703
+ void load();
3704
+ const off = userId ? chat.callAgents.whisper.subscribe(userId, callId, {
3705
+ onHint: (h) => {
3706
+ merge([h]);
3707
+ setLatest(h);
3708
+ },
3709
+ onChanged: setWhisper
3710
+ }) : () => void 0;
3711
+ const offRe = onReconnect(chat, () => void load());
3712
+ return () => {
3713
+ controller.abort();
3714
+ off();
3715
+ offRe();
3716
+ };
3717
+ }, [chat, callId, userId, merge]);
3718
+ const setOn = react.useCallback(
3719
+ async (next, opts = {}) => {
3720
+ if (!callId) return;
3721
+ setPending(true);
3722
+ setError(null);
3723
+ try {
3724
+ setWhisper(await chat.callAgents.whisper.set(callId, next, opts));
3725
+ } catch (err) {
3726
+ setError(asError2(err));
3727
+ throw err;
3728
+ } finally {
3729
+ setPending(false);
3730
+ }
3731
+ },
3732
+ [chat, callId]
3733
+ );
3734
+ const toggle = react.useCallback(() => setOn(!onRef.current), [setOn]);
3735
+ return {
3736
+ on: whisper?.on ?? false,
3737
+ whisper,
3738
+ agentName: whisper?.on ? whisper.agent?.name ?? null : null,
3739
+ hints,
3740
+ latest,
3741
+ loading,
3742
+ pending,
3743
+ error,
3744
+ setOn,
3745
+ toggle
3746
+ };
3747
+ }
3748
+ function useEscalations(opts = {}) {
3749
+ const chat = usePoolse();
3750
+ const pollMs = opts.pollMs ?? 3e4;
3751
+ const callId = opts.callId ?? null;
3752
+ const read = react.useCallback(
3753
+ () => ({
3754
+ pending: chat.escalations.pending().filter((e) => !callId || e.callId === callId),
3755
+ all: chat.escalations.all().filter((e) => !callId || e.callId === callId)
3756
+ }),
3757
+ [chat, callId]
3758
+ );
3759
+ const [state, setState] = react.useState(read);
3760
+ const [loading, setLoading] = react.useState(true);
3761
+ const [error, setError] = react.useState(null);
3762
+ const [pending, setPending] = react.useState(null);
3763
+ const mounted = react.useRef(true);
3764
+ const refresh = react.useCallback(async () => {
3765
+ try {
3766
+ await chat.escalations.list();
3767
+ if (mounted.current) setError(null);
3768
+ } catch (err) {
3769
+ if (mounted.current) setError(asError2(err));
3770
+ } finally {
3771
+ if (mounted.current) setLoading(false);
3772
+ }
3773
+ }, [chat]);
3774
+ react.useEffect(() => {
3775
+ mounted.current = true;
3776
+ const off = chat.escalations.subscribe(() => setState(read()));
3777
+ setState(read());
3778
+ void refresh();
3779
+ const offRe = onReconnect(chat, () => void refresh());
3780
+ const timer = pollMs > 0 ? setInterval(() => void refresh(), pollMs) : null;
3781
+ return () => {
3782
+ mounted.current = false;
3783
+ off();
3784
+ offRe();
3785
+ if (timer) clearInterval(timer);
3786
+ };
3787
+ }, [chat, read, refresh, pollMs]);
3788
+ const reply = react.useCallback(
3789
+ async (id, r) => {
3790
+ setPending(id);
3791
+ setError(null);
3792
+ try {
3793
+ return await chat.escalations.reply(id, r);
3794
+ } catch (err) {
3795
+ if (mounted.current) setError(asError2(err));
3796
+ throw err;
3797
+ } finally {
3798
+ if (mounted.current) setPending(null);
3799
+ }
3800
+ },
3801
+ [chat]
3802
+ );
3803
+ const [, setNames] = react.useState(0);
3804
+ react.useEffect(() => {
3805
+ let live = true;
3806
+ void chat.agents.list().then(() => live && setNames((n) => n + 1)).catch(() => void 0);
3807
+ return () => {
3808
+ live = false;
3809
+ };
3810
+ }, [chat]);
3811
+ const agentNameOf = react.useCallback(
3812
+ (e) => (e.agentId ? chat.agents.peek(e.agentId)?.name : null) ?? "Your agent",
3813
+ [chat]
3814
+ );
3815
+ return {
3816
+ escalations: state.pending,
3817
+ all: state.all,
3818
+ loading,
3819
+ error,
3820
+ pending,
3821
+ reply,
3822
+ agentNameOf,
3823
+ refresh
3824
+ };
3825
+ }
3826
+ function useAgentBrief(target) {
3827
+ const chat = usePoolse();
3828
+ const meetingId = target.scheduledMeetingId ?? null;
3829
+ const callId = target.callId ?? null;
3830
+ const [brief, setBrief] = react.useState(null);
3831
+ const [loading, setLoading] = react.useState(!!(meetingId || callId));
3832
+ const [saving, setSaving] = react.useState(false);
3833
+ const [error, setError] = react.useState(null);
3834
+ const [nonce, setNonce] = react.useState(0);
3835
+ react.useEffect(() => {
3836
+ setBrief(null);
3837
+ if (!meetingId && !callId) {
3838
+ setLoading(false);
3839
+ return;
3840
+ }
3841
+ const controller = new AbortController();
3842
+ setLoading(true);
3843
+ chat.callAgents.briefs.list({
3844
+ ...meetingId ? { scheduledMeetingId: meetingId } : {},
3845
+ ...callId ? { callId } : {},
3846
+ signal: controller.signal
3847
+ }).then((list) => {
3848
+ if (!controller.signal.aborted) setBrief(list[0] ?? null);
3849
+ }).catch((err) => {
3850
+ if (!controller.signal.aborted) setError(asError2(err));
3851
+ }).finally(() => {
3852
+ if (!controller.signal.aborted) setLoading(false);
3853
+ });
3854
+ return () => controller.abort();
3855
+ }, [chat, meetingId, callId, nonce]);
3856
+ const save = react.useCallback(
3857
+ async (input) => {
3858
+ setSaving(true);
3859
+ setError(null);
3860
+ try {
3861
+ const b = await chat.callAgents.briefs.create({
3862
+ ...input,
3863
+ ...meetingId ? { scheduledMeetingId: meetingId } : {},
3864
+ ...callId && !meetingId ? { callId } : {}
3865
+ });
3866
+ setBrief(b);
3867
+ return b;
3868
+ } catch (err) {
3869
+ setError(asError2(err));
3870
+ throw err;
3871
+ } finally {
3872
+ setSaving(false);
3873
+ }
3874
+ },
3875
+ [chat, meetingId, callId]
3876
+ );
3877
+ const remove = react.useCallback(async () => {
3878
+ if (!brief) return;
3879
+ setSaving(true);
3880
+ setError(null);
3881
+ try {
3882
+ await chat.callAgents.briefs.remove(brief.id);
3883
+ setBrief(null);
3884
+ } catch (err) {
3885
+ setError(asError2(err));
3886
+ throw err;
3887
+ } finally {
3888
+ setSaving(false);
3889
+ }
3890
+ }, [chat, brief]);
3891
+ const refresh = react.useCallback(() => setNonce((n) => n + 1), []);
3892
+ return { brief, loading, saving, error, save, remove, refresh };
3893
+ }
3894
+ function useLoaded(load, key) {
3895
+ const [items, setItems] = react.useState([]);
3896
+ const [loading, setLoading] = react.useState(true);
3897
+ const [error, setError] = react.useState(null);
3898
+ const [nonce, setNonce] = react.useState(0);
3899
+ const loadRef = react.useRef(load);
3900
+ loadRef.current = load;
3901
+ react.useEffect(() => {
3902
+ const controller = new AbortController();
3903
+ setLoading(true);
3904
+ loadRef.current(controller.signal).then((rows) => {
3905
+ if (controller.signal.aborted) return;
3906
+ setItems(rows);
3907
+ setError(null);
3908
+ }).catch((err) => {
3909
+ if (controller.signal.aborted || err?.name === "AbortError") return;
3910
+ setError(err instanceof Error ? err : new Error(String(err)));
3911
+ }).finally(() => {
3912
+ if (!controller.signal.aborted) setLoading(false);
3913
+ });
3914
+ return () => controller.abort();
3915
+ }, [key, nonce]);
3916
+ const refresh = react.useCallback(() => setNonce((n) => n + 1), []);
3917
+ return { items, setItems, loading, error, refresh };
3918
+ }
3919
+ function useAgents() {
3920
+ const chat = usePoolse();
3921
+ const { items, loading, error, refresh } = useLoaded((signal) => chat.agents.list(signal), "all");
3922
+ return { agents: items, loading, error, refresh };
3923
+ }
3924
+ function useConversationAgents(conversationId) {
3925
+ const chat = usePoolse();
3926
+ const { items, setItems, loading, error, refresh } = useLoaded(
3927
+ (signal) => conversationId ? chat.agents.inConversation(conversationId, signal) : Promise.resolve([]),
3928
+ conversationId ?? ""
3929
+ );
3930
+ const put = (scope) => setItems((list) => list.map((a) => a.id === scope.agentId ? { ...a, scope } : a));
3931
+ const setScope = react.useCallback(
3932
+ async (agentId, patch) => {
3933
+ if (!conversationId) throw new Error("no conversation");
3934
+ const scope = await chat.agents.setScope(conversationId, agentId, patch);
3935
+ put(scope);
3936
+ return scope;
3937
+ },
3938
+ // eslint-disable-next-line react-hooks/exhaustive-deps
3939
+ [chat, conversationId]
3940
+ );
3941
+ const resetScope = react.useCallback(
3942
+ async (agentId) => {
3943
+ if (!conversationId) throw new Error("no conversation");
3944
+ const scope = await chat.agents.resetScope(conversationId, agentId);
3945
+ put(scope);
3946
+ return scope;
3947
+ },
3948
+ // eslint-disable-next-line react-hooks/exhaustive-deps
3949
+ [chat, conversationId]
3950
+ );
3951
+ return { agents: items, loading, error, refresh, setScope, resetScope };
3952
+ }
3953
+ function useMemory(opts = {}) {
3954
+ const chat = usePoolse();
3955
+ const key = JSON.stringify([opts.conversationId, opts.kind, opts.q, opts.limit]);
3956
+ const { items, setItems, loading, error, refresh } = useLoaded(
3957
+ (signal) => chat.agents.memory({
3958
+ ...opts.conversationId ? { conversationId: opts.conversationId } : {},
3959
+ ...opts.kind ? { kind: opts.kind } : {},
3960
+ ...opts.q ? { q: opts.q } : {},
3961
+ ...opts.limit !== void 0 ? { limit: opts.limit } : {},
3962
+ signal
3963
+ }),
3964
+ key
3965
+ );
3966
+ const add = react.useCallback(
3967
+ async (input) => {
3968
+ const fact = await chat.agents.addMemory(input);
3969
+ setItems((list) => [fact, ...list]);
3970
+ return fact;
3971
+ },
3972
+ [chat, setItems]
3973
+ );
3974
+ const update = react.useCallback(
3975
+ async (id, patch) => {
3976
+ const fact = await chat.agents.updateMemory(id, patch);
3977
+ setItems((list) => list.map((f) => f.id === id ? fact : f));
3978
+ return fact;
3979
+ },
3980
+ [chat, setItems]
3981
+ );
3982
+ const remove = react.useCallback(
3983
+ async (id) => {
3984
+ await chat.agents.deleteMemory(id);
3985
+ setItems((list) => list.filter((f) => f.id !== id));
3986
+ },
3987
+ [chat, setItems]
3988
+ );
3989
+ return { facts: items, loading, error, refresh, add, update, remove };
3990
+ }
3991
+ function useFollowups(opts = {}) {
3992
+ const chat = usePoolse();
3993
+ const { items, setItems, loading, error, refresh } = useLoaded(
3994
+ (signal) => chat.agents.followups({ ...opts.status ? { status: opts.status } : {}, signal }),
3995
+ opts.status ?? ""
3996
+ );
3997
+ const act = react.useCallback(
3998
+ async (id, action) => {
3999
+ const f = await (action === "done" ? chat.agents.followupDone(id) : chat.agents.followupCancel(id));
4000
+ setItems(
4001
+ (list) => opts.status && f.status !== opts.status ? list.filter((x) => x.id !== id) : list.map((x) => x.id === id ? f : x)
4002
+ );
4003
+ return f;
4004
+ },
4005
+ [chat, setItems, opts.status]
4006
+ );
4007
+ return {
4008
+ followups: items,
4009
+ loading,
4010
+ error,
4011
+ refresh,
4012
+ done: (id) => act(id, "done"),
4013
+ cancel: (id) => act(id, "cancel")
4014
+ };
4015
+ }
4016
+ function useAskMeetings(opts = {}) {
4017
+ const chat = usePoolse();
4018
+ const callId = opts.callId ?? null;
4019
+ const conversationId = opts.conversationId ?? null;
4020
+ const [answer, setAnswer] = react.useState(null);
4021
+ const [question, setQuestion] = react.useState(null);
4022
+ const [loading, setLoading] = react.useState(false);
4023
+ const [error, setError] = react.useState(null);
4024
+ const inflight = react.useRef(null);
4025
+ react.useEffect(() => () => inflight.current?.abort(), []);
4026
+ const reset = react.useCallback(() => {
4027
+ inflight.current?.abort();
4028
+ inflight.current = null;
4029
+ setAnswer(null);
4030
+ setQuestion(null);
4031
+ setLoading(false);
4032
+ setError(null);
4033
+ }, []);
4034
+ react.useEffect(() => reset, [callId, conversationId, reset]);
4035
+ const ask = react.useCallback(
4036
+ async (q) => {
4037
+ const text = q.trim().slice(0, sdk.ASK_QUESTION_MAX);
4038
+ if (!text) return null;
4039
+ inflight.current?.abort();
4040
+ const controller = new AbortController();
4041
+ inflight.current = controller;
4042
+ setQuestion(text);
4043
+ setLoading(true);
4044
+ setError(null);
4045
+ try {
4046
+ const res = await chat.meetings.ask({
4047
+ question: text,
4048
+ ...callId ? { callId } : {},
4049
+ ...conversationId ? { conversationId } : {},
4050
+ signal: controller.signal
4051
+ });
4052
+ if (inflight.current !== controller) return null;
4053
+ setAnswer(res);
4054
+ return res;
4055
+ } catch (err) {
4056
+ if (inflight.current !== controller) return null;
4057
+ if (err?.name === "AbortError") return null;
4058
+ setError(err instanceof Error ? err : new Error(String(err)));
4059
+ return null;
4060
+ } finally {
4061
+ if (inflight.current === controller) {
4062
+ inflight.current = null;
4063
+ setLoading(false);
4064
+ }
4065
+ }
4066
+ },
4067
+ [chat, callId, conversationId]
4068
+ );
4069
+ return { answer, question, loading, error, ask, reset };
4070
+ }
4071
+ function useRecordingUrl(recordingId) {
4072
+ const chat = usePoolse();
4073
+ const [url, setUrl] = react.useState(null);
4074
+ const [contentType, setContentType] = react.useState(null);
4075
+ const [loading, setLoading] = react.useState(!!recordingId);
4076
+ const [error, setError] = react.useState(null);
4077
+ const [nonce, setNonce] = react.useState(0);
4078
+ react.useEffect(() => {
4079
+ if (!recordingId) {
4080
+ setUrl(null);
4081
+ setLoading(false);
4082
+ setError(null);
4083
+ return;
4084
+ }
4085
+ const controller = new AbortController();
4086
+ setLoading(true);
4087
+ setError(null);
4088
+ chat.calls.recording.downloadUrl(recordingId, controller.signal).then((res) => {
4089
+ if (controller.signal.aborted) return;
4090
+ setUrl(res.url);
4091
+ setContentType(res.content_type);
4092
+ setLoading(false);
4093
+ }).catch((err) => {
4094
+ if (controller.signal.aborted) return;
4095
+ setError(err instanceof Error ? err : new Error(String(err)));
4096
+ setLoading(false);
4097
+ });
4098
+ return () => controller.abort();
4099
+ }, [chat, recordingId, nonce]);
4100
+ const refresh = react.useCallback(() => setNonce((n) => n + 1), []);
4101
+ return { url, contentType, loading, error, refresh };
4102
+ }
4103
+ function useCallSummary(callId, initial = null) {
4104
+ const chat = usePoolse();
4105
+ const [summary, setSummary] = react.useState(initial);
4106
+ const [loading, setLoading] = react.useState(false);
4107
+ const [missing, setMissing] = react.useState(false);
4108
+ const [error, setError] = react.useState(null);
4109
+ const seq = react.useRef(0);
4110
+ const conversationId = initial?.conversationId ?? summary?.conversationId ?? null;
4111
+ const refresh = react.useCallback(() => {
4112
+ if (!callId) return;
4113
+ const mine = ++seq.current;
4114
+ setLoading(true);
4115
+ chat.meetings.summary(callId).then((s) => {
4116
+ if (mine !== seq.current) return;
4117
+ setSummary(s);
4118
+ setMissing(false);
4119
+ setError(null);
4120
+ }).catch((err) => {
4121
+ if (mine !== seq.current) return;
4122
+ if (err instanceof sdk.ApiError && err.status === 404) setMissing(true);
4123
+ else setError(err instanceof Error ? err : new Error(String(err)));
4124
+ }).finally(() => {
4125
+ if (mine === seq.current) setLoading(false);
4126
+ });
4127
+ }, [chat, callId]);
4128
+ const needsFull = !initial || initial.shortened;
4129
+ react.useEffect(() => {
4130
+ if (needsFull) refresh();
4131
+ }, [refresh, needsFull]);
4132
+ react.useEffect(() => {
4133
+ if (!callId || !conversationId) return;
4134
+ return chat.realtime.conversation(conversationId).onSummaryReady((evt) => {
4135
+ if (evt.call_id !== callId) return;
4136
+ const s = sdk.summaryFromWire(evt.summary);
4137
+ if (s) {
4138
+ seq.current++;
4139
+ setSummary(s);
4140
+ }
4141
+ refresh();
4142
+ });
4143
+ }, [chat, callId, conversationId, refresh]);
4144
+ return { summary, loading, missing, error, refresh };
4145
+ }
4146
+ function useRecordingPlayback(recordingId) {
4147
+ const chat = usePoolse();
4148
+ const [playback, setPlayback] = react.useState(null);
4149
+ const [loading, setLoading] = react.useState(!!recordingId);
4150
+ const [error, setError] = react.useState(null);
4151
+ const [nonce, setNonce] = react.useState(0);
4152
+ react.useEffect(() => {
4153
+ if (!recordingId) {
4154
+ setPlayback(null);
4155
+ setLoading(false);
4156
+ return;
4157
+ }
4158
+ const controller = new AbortController();
4159
+ setLoading(true);
4160
+ chat.meetings.playback(recordingId, controller.signal).then((p) => {
4161
+ if (controller.signal.aborted) return;
4162
+ setPlayback(p);
4163
+ setError(null);
4164
+ }).catch((err) => {
4165
+ if (controller.signal.aborted) return;
4166
+ setError(err instanceof Error ? err : new Error(String(err)));
4167
+ }).finally(() => {
4168
+ if (!controller.signal.aborted) setLoading(false);
4169
+ });
4170
+ return () => controller.abort();
4171
+ }, [chat, recordingId, nonce]);
4172
+ const refresh = react.useCallback(() => setNonce((n) => n + 1), []);
4173
+ return { playback, loading, error, refresh };
4174
+ }
4175
+ function useClip(clipId, initial = null) {
4176
+ const chat = usePoolse();
4177
+ const [clip, setClip] = react.useState(initial);
4178
+ const [url, setUrl] = react.useState(null);
4179
+ const [loading, setLoading] = react.useState(!!clipId);
4180
+ const [error, setError] = react.useState(null);
4181
+ const [nonce, setNonce] = react.useState(0);
4182
+ react.useEffect(() => {
4183
+ if (!clipId) {
4184
+ setClip(null);
4185
+ setLoading(false);
4186
+ return;
4187
+ }
4188
+ const controller = new AbortController();
4189
+ setLoading(true);
4190
+ chat.meetings.clip(clipId, controller.signal).then(async (c) => {
4191
+ if (controller.signal.aborted) return;
4192
+ setClip(c);
4193
+ if (c.status === "ready") {
4194
+ const d = await chat.meetings.clipDownloadUrl(clipId, controller.signal);
4195
+ if (!controller.signal.aborted) setUrl(d.url);
4196
+ }
4197
+ setError(null);
4198
+ }).catch((err) => {
4199
+ if (controller.signal.aborted) return;
4200
+ setError(err instanceof Error ? err : new Error(String(err)));
4201
+ }).finally(() => {
4202
+ if (!controller.signal.aborted) setLoading(false);
4203
+ });
4204
+ return () => controller.abort();
4205
+ }, [chat, clipId, nonce]);
4206
+ const conversationId = clip?.conversationId ?? null;
4207
+ react.useEffect(() => {
4208
+ if (!clipId || !conversationId) return;
4209
+ const conv = chat.realtime.conversation(conversationId);
4210
+ const apply = (evt) => {
4211
+ const c = sdk.clipFromWire(evt.clip);
4212
+ if (!c || c.id !== clipId) return;
4213
+ setClip(c);
4214
+ if (c.status === "ready") setNonce((n) => n + 1);
4215
+ if (c.status === "deleted") setUrl(null);
4216
+ };
4217
+ const offs = [conv.onClipReady(apply), conv.onClipDeleted(apply)];
4218
+ return () => offs.forEach((off) => off());
4219
+ }, [chat, clipId, conversationId]);
4220
+ const refresh = react.useCallback(() => setNonce((n) => n + 1), []);
4221
+ return { clip, url, loading, error, refresh };
4222
+ }
4223
+ function usePoll(message) {
4224
+ const chat = usePoolse();
4225
+ const [poll, setPoll] = react.useState(message.poll ?? null);
4226
+ const [mine, setMine] = react.useState(message.my_option_ids ?? []);
4227
+ const [pending, setPending] = react.useState(false);
4228
+ const [error, setError] = react.useState(null);
4229
+ const mineRef = react.useRef(mine);
4230
+ mineRef.current = mine;
4231
+ const pollRef = react.useRef(poll);
4232
+ pollRef.current = poll;
4233
+ const pollKey = JSON.stringify(message.poll ?? null);
4234
+ const mineKey = JSON.stringify(message.my_option_ids ?? null);
4235
+ react.useEffect(() => {
4236
+ setPoll(JSON.parse(pollKey));
4237
+ }, [pollKey]);
4238
+ react.useEffect(() => {
4239
+ const m = JSON.parse(mineKey);
4240
+ if (m) setMine(m);
4241
+ }, [mineKey]);
4242
+ react.useEffect(() => {
4243
+ const conv = chat.realtime.conversation(message.conversation_id);
4244
+ return conv.onPollUpdated((evt) => {
4245
+ if (evt.message_id === message.id) setPoll(evt.poll);
4246
+ });
4247
+ }, [chat, message.id, message.conversation_id]);
4248
+ const write = react.useCallback(
4249
+ async (next) => {
4250
+ const before = mineRef.current;
4251
+ const p = pollRef.current;
4252
+ if (!p) return;
4253
+ const me = chat.me.peek()?.id;
4254
+ setMine(next);
4255
+ setPoll(sdk.applyLocalVote(p, before, next, me));
4256
+ setPending(true);
4257
+ setError(null);
4258
+ try {
4259
+ const res = await chat.messages.one(message.id).vote(next);
4260
+ setPoll(res.poll);
4261
+ setMine(res.my_option_ids);
4262
+ } catch (err) {
4263
+ setMine(before);
4264
+ setPoll(p);
4265
+ setError(err);
4266
+ } finally {
4267
+ setPending(false);
4268
+ }
4269
+ },
4270
+ [chat, message.id]
4271
+ );
4272
+ const closed = poll ? sdk.isPollClosed(poll) : true;
4273
+ return {
4274
+ poll,
4275
+ myOptionIds: mine,
4276
+ closed,
4277
+ pending,
4278
+ error,
4279
+ toggle: async (optionId) => {
4280
+ const p = pollRef.current;
4281
+ if (!p || sdk.isPollClosed(p)) return;
4282
+ await write(sdk.toggleVote(p, mineRef.current, optionId));
4283
+ },
4284
+ clear: () => write([]),
4285
+ close: async () => {
4286
+ setError(null);
4287
+ try {
4288
+ const res = await chat.messages.one(message.id).closePoll();
4289
+ setPoll(res.poll);
4290
+ } catch (err) {
4291
+ setError(err);
4292
+ }
4293
+ }
4294
+ };
4295
+ }
4296
+ function usePins(conversationId) {
4297
+ const chat = usePoolse();
4298
+ const [pins, setPins] = react.useState([]);
4299
+ const [loading, setLoading] = react.useState(true);
4300
+ const [error, setError] = react.useState(null);
4301
+ const refresh = react.useCallback(async () => {
4302
+ try {
4303
+ setPins(await chat.conversations.one(conversationId).messages.pins());
4304
+ setError(null);
4305
+ } catch (err) {
4306
+ setError(err);
4307
+ } finally {
4308
+ setLoading(false);
4309
+ }
4310
+ }, [chat, conversationId]);
4311
+ react.useEffect(() => {
4312
+ setLoading(true);
4313
+ void refresh();
4314
+ const conv = chat.realtime.conversation(conversationId);
4315
+ return conv.onPinChanged(() => void refresh());
4316
+ }, [chat, conversationId, refresh]);
4317
+ return {
4318
+ pins,
4319
+ loading,
4320
+ error,
4321
+ refresh,
4322
+ pin: async (id) => {
4323
+ await chat.messages.one(id).pin();
4324
+ await refresh();
4325
+ },
4326
+ unpin: async (id) => {
4327
+ setPins((p) => p.filter((m) => m.id !== id));
4328
+ await chat.messages.one(id).unpin();
4329
+ await refresh();
4330
+ }
4331
+ };
4332
+ }
4333
+ function useThreadFollow(rootId) {
4334
+ const chat = usePoolse();
4335
+ const [following, setState] = react.useState(null);
4336
+ const [error, setError] = react.useState(null);
4337
+ react.useEffect(() => {
4338
+ if (!rootId) return;
4339
+ let live = true;
4340
+ setState(null);
4341
+ chat.messages.one(rootId).followState().then((s) => live && setState(s.following)).catch((err) => live && setError(err));
4342
+ return () => {
4343
+ live = false;
4344
+ };
4345
+ }, [chat, rootId]);
4346
+ return {
4347
+ following,
4348
+ error,
4349
+ setFollowing: async (on) => {
4350
+ if (!rootId) return;
4351
+ const before = following;
4352
+ setState(on);
4353
+ try {
4354
+ setState((await chat.messages.one(rootId).setFollow(on)).following);
4355
+ } catch (err) {
4356
+ setState(before);
4357
+ setError(err);
4358
+ }
4359
+ }
4360
+ };
4361
+ }
4362
+ function useCatchUp(conversationId) {
4363
+ const chat = usePoolse();
4364
+ const [result, setResult] = react.useState(null);
4365
+ const [loading, setLoading] = react.useState(false);
4366
+ const [error, setError] = react.useState(null);
4367
+ return {
4368
+ result,
4369
+ loading,
4370
+ error,
4371
+ run: async (opts) => {
4372
+ setLoading(true);
4373
+ setError(null);
4374
+ try {
4375
+ const r = await chat.conversations.one(conversationId).messages.catchUp(opts);
4376
+ setResult(r);
4377
+ return r;
4378
+ } catch (err) {
4379
+ setError(err);
4380
+ return null;
4381
+ } finally {
4382
+ setLoading(false);
4383
+ }
4384
+ }
4385
+ };
4386
+ }
4387
+ function useTranslation(messageId, language) {
4388
+ const chat = usePoolse();
4389
+ const [translation, setTranslation] = react.useState(null);
4390
+ const [loading, setLoading] = react.useState(false);
4391
+ const [error, setError] = react.useState(null);
4392
+ react.useEffect(() => setTranslation(null), [messageId, language]);
4393
+ return {
4394
+ translation,
4395
+ loading,
4396
+ error,
4397
+ reset: () => setTranslation(null),
4398
+ translate: async () => {
4399
+ setLoading(true);
4400
+ setError(null);
4401
+ try {
4402
+ setTranslation(await chat.messages.one(messageId).translate(language));
4403
+ } catch (err) {
4404
+ setError(err);
4405
+ } finally {
4406
+ setLoading(false);
4407
+ }
4408
+ }
4409
+ };
4410
+ }
4411
+ function useScheduledMessages(conversationId) {
4412
+ const chat = usePoolse();
4413
+ const [scheduled, setScheduled] = react.useState([]);
4414
+ const [loading, setLoading] = react.useState(true);
4415
+ const [error, setError] = react.useState(null);
4416
+ const refresh = react.useCallback(async () => {
4417
+ try {
4418
+ setScheduled(
4419
+ await chat.scheduledMessages.list(
4420
+ conversationId ? { conversation_id: conversationId } : {}
4421
+ )
4422
+ );
4423
+ setError(null);
4424
+ } catch (err) {
4425
+ setError(err);
4426
+ } finally {
4427
+ setLoading(false);
4428
+ }
4429
+ }, [chat, conversationId]);
4430
+ react.useEffect(() => {
4431
+ void refresh();
4432
+ const me = chat.me.peek()?.id;
4433
+ if (!me) return;
4434
+ return chat.realtime.user(me).onScheduledMessage(() => void refresh());
4435
+ }, [chat, refresh]);
4436
+ return {
4437
+ scheduled,
4438
+ loading,
4439
+ error,
4440
+ refresh,
4441
+ schedule: async (cid, req) => {
4442
+ const s = await chat.conversations.one(cid).messages.schedule(req);
4443
+ await refresh();
4444
+ return s;
4445
+ },
4446
+ cancel: async (id) => {
4447
+ setScheduled((l) => l.filter((s) => s.id !== id));
4448
+ await chat.scheduledMessages.cancel(id);
4449
+ },
4450
+ sendNow: async (id) => {
4451
+ setScheduled((l) => l.filter((s) => s.id !== id));
4452
+ await chat.scheduledMessages.sendNow(id);
4453
+ },
4454
+ reschedule: async (id, sendAt) => {
4455
+ await chat.scheduledMessages.update(id, { send_at: sendAt });
4456
+ await refresh();
4457
+ }
4458
+ };
4459
+ }
4460
+ function useFiles(conversationId, kind) {
4461
+ const chat = usePoolse();
4462
+ const [files, setFiles] = react.useState([]);
4463
+ const [cursor, setCursor] = react.useState(null);
4464
+ const [hasMore, setHasMore] = react.useState(false);
4465
+ const [loading, setLoading] = react.useState(true);
4466
+ const [error, setError] = react.useState(null);
4467
+ const load = react.useCallback(
4468
+ async (before) => {
4469
+ setLoading(true);
4470
+ try {
4471
+ const page = await chat.conversations.one(conversationId).messages.files({ ...kind ? { kind } : {}, ...before ? { before } : {} });
4472
+ setFiles((f) => before ? [...f, ...page.data] : page.data);
4473
+ setCursor(page.next_cursor);
4474
+ setHasMore(page.next_cursor !== null);
4475
+ setError(null);
4476
+ } catch (err) {
4477
+ setError(err);
4478
+ } finally {
4479
+ setLoading(false);
4480
+ }
4481
+ },
4482
+ [chat, conversationId, kind]
4483
+ );
4484
+ react.useEffect(() => {
4485
+ void load(null);
4486
+ const conv = chat.realtime.conversation(conversationId);
4487
+ return conv.onAttachmentProcessed((evt) => {
4488
+ if (kind && evt.attachment.kind !== kind) return;
4489
+ setFiles((f) => {
4490
+ const group = evt.attachment.version_group_id;
4491
+ const rest = f.filter(
4492
+ (a) => a.id !== evt.attachment.id && (!group || a.version_group_id !== group)
4493
+ );
4494
+ return [evt.attachment, ...rest];
4495
+ });
4496
+ });
4497
+ }, [chat, conversationId, kind, load]);
4498
+ return {
4499
+ files,
4500
+ loading,
4501
+ error,
4502
+ hasMore,
4503
+ loadMore: async () => {
4504
+ if (cursor) await load(cursor);
4505
+ }
4506
+ };
4507
+ }
4508
+ var NAME = /^[a-z0-9_+-]{1,32}$/;
4509
+ function customEmojiToken(name) {
4510
+ return `:${name}:`;
4511
+ }
4512
+ function parseCustomEmojiToken(token) {
4513
+ const m = /^:([a-z0-9_+-]{1,32}):$/.exec(token);
4514
+ return m ? m[1] : null;
4515
+ }
4516
+ function findCustomEmoji(token, set) {
4517
+ const name = parseCustomEmojiToken(token);
4518
+ if (!name || !set) return null;
4519
+ return set.find((e) => e.name === name) ?? null;
4520
+ }
4521
+ function searchCustomEmoji(set, query) {
4522
+ const words = query.toLowerCase().replace(/:/g, " ").split(/\s+/).filter(Boolean);
4523
+ if (words.length === 0) return [...set];
4524
+ const hits = set.filter((e) => NAME.test(e.name) && words.every((w) => e.name.includes(w)));
4525
+ return hits.sort(
4526
+ (a, b) => Number(!a.name.startsWith(words[0])) - Number(!b.name.startsWith(words[0])) || a.name.localeCompare(b.name)
4527
+ );
4528
+ }
4529
+ var CustomEmojiContext = react.createContext([]);
4530
+ function CustomEmojiProvider({
4531
+ emoji,
4532
+ children
4533
+ }) {
4534
+ return react.createElement(CustomEmojiContext.Provider, { value: emoji }, children);
4535
+ }
4536
+ function useCustomEmoji() {
4537
+ return react.useContext(CustomEmojiContext);
4538
+ }
4539
+
4540
+ Object.defineProperty(exports, "APPROVAL_REASON_MAX", {
4541
+ enumerable: true,
4542
+ get: function () { return sdk.APPROVAL_REASON_MAX; }
4543
+ });
4544
+ Object.defineProperty(exports, "ASK_QUESTION_MAX", {
4545
+ enumerable: true,
4546
+ get: function () { return sdk.ASK_QUESTION_MAX; }
4547
+ });
4548
+ Object.defineProperty(exports, "ApiError", {
4549
+ enumerable: true,
4550
+ get: function () { return sdk.ApiError; }
4551
+ });
4552
+ Object.defineProperty(exports, "AuthError", {
4553
+ enumerable: true,
4554
+ get: function () { return sdk.AuthError; }
4555
+ });
4556
+ Object.defineProperty(exports, "BRIEF_RULE_MAX", {
4557
+ enumerable: true,
4558
+ get: function () { return sdk.BRIEF_RULE_MAX; }
4559
+ });
4560
+ Object.defineProperty(exports, "BRIEF_TEXT_MAX", {
4561
+ enumerable: true,
4562
+ get: function () { return sdk.BRIEF_TEXT_MAX; }
4563
+ });
4564
+ Object.defineProperty(exports, "DEFAULT_DOC_LIMITS", {
4565
+ enumerable: true,
4566
+ get: function () { return sdk.DEFAULT_DOC_LIMITS; }
4567
+ });
4568
+ Object.defineProperty(exports, "DocChannel", {
4569
+ enumerable: true,
4570
+ get: function () { return sdk.DocChannel; }
4571
+ });
4572
+ Object.defineProperty(exports, "DocPushError", {
4573
+ enumerable: true,
4574
+ get: function () { return sdk.DocPushError; }
4575
+ });
4576
+ Object.defineProperty(exports, "ESCALATION_ANSWER_MAX", {
4577
+ enumerable: true,
4578
+ get: function () { return sdk.ESCALATION_ANSWER_MAX; }
4579
+ });
4580
+ Object.defineProperty(exports, "MessageDiscardedError", {
4581
+ enumerable: true,
4582
+ get: function () { return sdk.MessageDiscardedError; }
4583
+ });
4584
+ Object.defineProperty(exports, "MessageQueuedError", {
4585
+ enumerable: true,
4586
+ get: function () { return sdk.MessageQueuedError; }
4587
+ });
4588
+ Object.defineProperty(exports, "NetworkError", {
4589
+ enumerable: true,
4590
+ get: function () { return sdk.NetworkError; }
4591
+ });
4592
+ Object.defineProperty(exports, "PLAYBACK_RATES", {
4593
+ enumerable: true,
4594
+ get: function () { return sdk.PLAYBACK_RATES; }
4595
+ });
4596
+ Object.defineProperty(exports, "POOLSE_SERVICE_IDENTITY_PREFIX", {
4597
+ enumerable: true,
4598
+ get: function () { return sdk.POOLSE_SERVICE_IDENTITY_PREFIX; }
4599
+ });
4600
+ Object.defineProperty(exports, "Poolse", {
4601
+ enumerable: true,
4602
+ get: function () { return sdk.Poolse; }
4603
+ });
4604
+ Object.defineProperty(exports, "PoolseError", {
4605
+ enumerable: true,
4606
+ get: function () { return sdk.PoolseError; }
4607
+ });
4608
+ Object.defineProperty(exports, "RateLimitedError", {
4609
+ enumerable: true,
4610
+ get: function () { return sdk.RateLimitedError; }
4611
+ });
4612
+ Object.defineProperty(exports, "activeSegmentIndex", {
4613
+ enumerable: true,
4614
+ get: function () { return sdk.activeSegmentIndex; }
4615
+ });
4616
+ Object.defineProperty(exports, "agentFromWire", {
4617
+ enumerable: true,
4618
+ get: function () { return sdk.agentFromWire; }
4619
+ });
4620
+ Object.defineProperty(exports, "agentMetaOf", {
4621
+ enumerable: true,
4622
+ get: function () { return sdk.agentMetaOf; }
4623
+ });
4624
+ Object.defineProperty(exports, "applyLiveSegment", {
4625
+ enumerable: true,
4626
+ get: function () { return sdk.applyLiveSegment; }
4627
+ });
4628
+ Object.defineProperty(exports, "approvalErrorMessage", {
4629
+ enumerable: true,
4630
+ get: function () { return sdk.approvalErrorMessage; }
4631
+ });
4632
+ Object.defineProperty(exports, "approvalFromWire", {
4633
+ enumerable: true,
4634
+ get: function () { return sdk.approvalFromWire; }
4635
+ });
4636
+ Object.defineProperty(exports, "approvalIdOf", {
4637
+ enumerable: true,
4638
+ get: function () { return sdk.approvalIdOf; }
4639
+ });
4640
+ Object.defineProperty(exports, "approvalStatusLabel", {
4641
+ enumerable: true,
4642
+ get: function () { return sdk.approvalStatusLabel; }
4643
+ });
4644
+ Object.defineProperty(exports, "callAgentModeLabel", {
4645
+ enumerable: true,
4646
+ get: function () { return sdk.callAgentModeLabel; }
4647
+ });
4648
+ Object.defineProperty(exports, "callAgentOfParticipant", {
4649
+ enumerable: true,
4650
+ get: function () { return sdk.callAgentOfParticipant; }
4651
+ });
4652
+ Object.defineProperty(exports, "callAgentStateLabel", {
4653
+ enumerable: true,
4654
+ get: function () { return sdk.callAgentStateLabel; }
4655
+ });
4656
+ Object.defineProperty(exports, "callAgentStateOf", {
4657
+ enumerable: true,
4658
+ get: function () { return sdk.callAgentStateOf; }
4659
+ });
4660
+ Object.defineProperty(exports, "callLogDisplayFor", {
4661
+ enumerable: true,
4662
+ get: function () { return sdk.callLogDisplayFor; }
4663
+ });
4664
+ Object.defineProperty(exports, "captureErrorMessage", {
4665
+ enumerable: true,
4666
+ get: function () { return sdk.captureErrorMessage; }
4667
+ });
4668
+ Object.defineProperty(exports, "captureLabel", {
4669
+ enumerable: true,
4670
+ get: function () { return sdk.captureLabel; }
4671
+ });
4672
+ Object.defineProperty(exports, "chapterIndexAt", {
4673
+ enumerable: true,
4674
+ get: function () { return sdk.chapterIndexAt; }
4675
+ });
4676
+ Object.defineProperty(exports, "chaptersOf", {
4677
+ enumerable: true,
4678
+ get: function () { return sdk.chaptersOf; }
4679
+ });
4680
+ Object.defineProperty(exports, "citationLabel", {
4681
+ enumerable: true,
4682
+ get: function () { return sdk.citationLabel; }
4683
+ });
4684
+ Object.defineProperty(exports, "citationsOf", {
4685
+ enumerable: true,
4686
+ get: function () { return sdk.citationsOf; }
4687
+ });
4688
+ Object.defineProperty(exports, "clipFromWire", {
4689
+ enumerable: true,
4690
+ get: function () { return sdk.clipFromWire; }
4691
+ });
4692
+ Object.defineProperty(exports, "clipOf", {
4693
+ enumerable: true,
4694
+ get: function () { return sdk.clipOf; }
4695
+ });
4696
+ Object.defineProperty(exports, "createIndexedDbStorage", {
4697
+ enumerable: true,
4698
+ get: function () { return sdk.createIndexedDbStorage; }
4699
+ });
4700
+ Object.defineProperty(exports, "describeCallLog", {
4701
+ enumerable: true,
4702
+ get: function () { return sdk.describeCallLog; }
4703
+ });
4704
+ Object.defineProperty(exports, "describeRecordingNotice", {
4705
+ enumerable: true,
4706
+ get: function () { return sdk.describeRecordingNotice; }
4707
+ });
4708
+ Object.defineProperty(exports, "escalationErrorMessage", {
4709
+ enumerable: true,
4710
+ get: function () { return sdk.escalationErrorMessage; }
4711
+ });
4712
+ Object.defineProperty(exports, "escalationStatusLabel", {
4713
+ enumerable: true,
4714
+ get: function () { return sdk.escalationStatusLabel; }
4715
+ });
4716
+ Object.defineProperty(exports, "findInText", {
4717
+ enumerable: true,
4718
+ get: function () { return sdk.findInText; }
4719
+ });
4720
+ Object.defineProperty(exports, "formatCallDuration", {
4721
+ enumerable: true,
4722
+ get: function () { return sdk.formatCallDuration; }
4723
+ });
4724
+ Object.defineProperty(exports, "formatCallLogPreview", {
4725
+ enumerable: true,
4726
+ get: function () { return sdk.formatCallLogPreview; }
4727
+ });
4728
+ Object.defineProperty(exports, "formatCallSummaryPreview", {
4729
+ enumerable: true,
4730
+ get: function () { return sdk.formatCallSummaryPreview; }
4731
+ });
4732
+ Object.defineProperty(exports, "formatClock", {
4733
+ enumerable: true,
4734
+ get: function () { return sdk.formatClock; }
4735
+ });
4736
+ Object.defineProperty(exports, "formatDue", {
4737
+ enumerable: true,
4738
+ get: function () { return sdk.formatDue; }
4739
+ });
4740
+ Object.defineProperty(exports, "formatRecordingNoticePreview", {
4741
+ enumerable: true,
4742
+ get: function () { return sdk.formatRecordingNoticePreview; }
4743
+ });
4744
+ Object.defineProperty(exports, "formatTimeRange", {
4745
+ enumerable: true,
4746
+ get: function () { return sdk.formatTimeRange; }
4747
+ });
4748
+ Object.defineProperty(exports, "groupTranscript", {
4749
+ enumerable: true,
4750
+ get: function () { return sdk.groupTranscript; }
4751
+ });
4752
+ Object.defineProperty(exports, "isCallLogMessage", {
4753
+ enumerable: true,
4754
+ get: function () { return sdk.isCallLogMessage; }
4755
+ });
4756
+ Object.defineProperty(exports, "isMessageVisibleTo", {
4757
+ enumerable: true,
4758
+ get: function () { return sdk.isMessageVisibleTo; }
4759
+ });
4760
+ Object.defineProperty(exports, "isServiceParticipant", {
4761
+ enumerable: true,
4762
+ get: function () { return sdk.isServiceParticipant; }
4763
+ });
4764
+ Object.defineProperty(exports, "isTombstone", {
4765
+ enumerable: true,
4766
+ get: function () { return sdk.isTombstone; }
4767
+ });
4768
+ Object.defineProperty(exports, "meetingsErrorMessage", {
4769
+ enumerable: true,
4770
+ get: function () { return sdk.meetingsErrorMessage; }
4771
+ });
4772
+ Object.defineProperty(exports, "memoryStorage", {
4773
+ enumerable: true,
4774
+ get: function () { return sdk.memoryStorage; }
4775
+ });
4776
+ Object.defineProperty(exports, "mergeMessage", {
4777
+ enumerable: true,
4778
+ get: function () { return sdk.mergeMessage; }
4779
+ });
4780
+ Object.defineProperty(exports, "messageAgent", {
4781
+ enumerable: true,
4782
+ get: function () { return sdk.messageAgent; }
4783
+ });
4784
+ Object.defineProperty(exports, "momentOf", {
4785
+ enumerable: true,
4786
+ get: function () { return sdk.momentOf; }
4787
+ });
4788
+ Object.defineProperty(exports, "parseCallLog", {
4789
+ enumerable: true,
4790
+ get: function () { return sdk.parseCallLog; }
4791
+ });
4792
+ Object.defineProperty(exports, "parseCallLogBody", {
4793
+ enumerable: true,
4794
+ get: function () { return sdk.parseCallLogBody; }
4795
+ });
4796
+ Object.defineProperty(exports, "parseCallSummary", {
4797
+ enumerable: true,
4798
+ get: function () { return sdk.parseCallSummary; }
4799
+ });
4800
+ Object.defineProperty(exports, "parseRecordingNotice", {
4801
+ enumerable: true,
4802
+ get: function () { return sdk.parseRecordingNotice; }
4803
+ });
4804
+ Object.defineProperty(exports, "parseRecordingNoticeBody", {
4805
+ enumerable: true,
4806
+ get: function () { return sdk.parseRecordingNoticeBody; }
4807
+ });
4808
+ Object.defineProperty(exports, "recordingNoticeDisplayFor", {
4809
+ enumerable: true,
4810
+ get: function () { return sdk.recordingNoticeDisplayFor; }
4811
+ });
4812
+ Object.defineProperty(exports, "silencesFromSegments", {
4813
+ enumerable: true,
4814
+ get: function () { return sdk.silencesFromSegments; }
4815
+ });
4816
+ Object.defineProperty(exports, "silencesOf", {
4817
+ enumerable: true,
4818
+ get: function () { return sdk.silencesOf; }
4819
+ });
4820
+ Object.defineProperty(exports, "skipSilenceTarget", {
4821
+ enumerable: true,
4822
+ get: function () { return sdk.skipSilenceTarget; }
4823
+ });
4824
+ Object.defineProperty(exports, "speakerName", {
4825
+ enumerable: true,
4826
+ get: function () { return sdk.speakerName; }
4827
+ });
4828
+ Object.defineProperty(exports, "summaryFromWire", {
4829
+ enumerable: true,
4830
+ get: function () { return sdk.summaryFromWire; }
4831
+ });
4832
+ Object.defineProperty(exports, "summaryStatusText", {
4833
+ enumerable: true,
4834
+ get: function () { return sdk.summaryStatusText; }
4835
+ });
4836
+ Object.defineProperty(exports, "summaryStyleLabel", {
4837
+ enumerable: true,
4838
+ get: function () { return sdk.summaryStyleLabel; }
4839
+ });
4840
+ Object.defineProperty(exports, "toTombstone", {
4841
+ enumerable: true,
4842
+ get: function () { return sdk.toTombstone; }
4843
+ });
4844
+ Object.defineProperty(exports, "toolLabel", {
4845
+ enumerable: true,
4846
+ get: function () { return sdk.toolLabel; }
4847
+ });
4848
+ Object.defineProperty(exports, "whisperErrorMessage", {
4849
+ enumerable: true,
4850
+ get: function () { return sdk.whisperErrorMessage; }
4851
+ });
4852
+ Object.defineProperty(exports, "whisperHintKindLabel", {
4853
+ enumerable: true,
4854
+ get: function () { return sdk.whisperHintKindLabel; }
2165
4855
  });
4856
+ exports.CustomEmojiProvider = CustomEmojiProvider;
2166
4857
  exports.EDIT_WINDOW_MS = EDIT_WINDOW_MS;
4858
+ exports.FORMAT_ACTIONS = FORMAT_ACTIONS;
4859
+ exports.MESSAGE_PLAYBACK_RATES = MESSAGE_PLAYBACK_RATES;
2167
4860
  exports.PoolseProvider = PoolseProvider;
4861
+ exports.applyCaptureEvent = applyCaptureEvent;
4862
+ exports.applyFormat = applyFormat;
4863
+ exports.applySlashCommand = applySlashCommand;
2168
4864
  exports.canEditOwnMessage = canEditOwnMessage;
2169
4865
  exports.computeGroupPosition = computeGroupPosition;
4866
+ exports.customEmojiToken = customEmojiToken;
2170
4867
  exports.filterConversations = filterConversations;
4868
+ exports.filterSlashCommands = filterSlashCommands;
4869
+ exports.findCustomEmoji = findCustomEmoji;
2171
4870
  exports.formatDayLabel = formatDayLabel;
4871
+ exports.formatForShortcut = formatForShortcut;
4872
+ exports.mentionGroupMeta = mentionGroupMeta;
4873
+ exports.nextPlaybackRate = nextPlaybackRate;
2172
4874
  exports.orderUnread = orderUnread;
4875
+ exports.parseCustomEmojiToken = parseCustomEmojiToken;
4876
+ exports.parseSlashCommand = parseSlashCommand;
4877
+ exports.playbackRateLabel = playbackRateLabel;
4878
+ exports.rankMentionGroups = rankMentionGroups;
4879
+ exports.readDlpError = readDlpError;
2173
4880
  exports.receiptsOf = receiptsOf;
2174
4881
  exports.sameDay = sameDay;
2175
4882
  exports.sameGroup = sameGroup;
4883
+ exports.searchCustomEmoji = searchCustomEmoji;
4884
+ exports.slashCommandsFromWorkspace = slashCommandsFromWorkspace;
4885
+ exports.slashQuery = slashQuery;
4886
+ exports.useAgenda = useAgenda;
4887
+ exports.useAgent = useAgent;
4888
+ exports.useAgentBrief = useAgentBrief;
4889
+ exports.useAgents = useAgents;
2176
4890
  exports.useAppEvent = useAppEvent;
4891
+ exports.useApproval = useApproval;
4892
+ exports.useApprovals = useApprovals;
4893
+ exports.useAskMeetings = useAskMeetings;
2177
4894
  exports.useAttachmentUpload = useAttachmentUpload;
2178
4895
  exports.useAttachmentUrl = useAttachmentUrl;
4896
+ exports.useBreakouts = useBreakouts;
4897
+ exports.useCallAgents = useCallAgents;
4898
+ exports.useCallMeeting = useCallMeeting;
4899
+ exports.useCallQuality = useCallQuality;
4900
+ exports.useCallReactions = useCallReactions;
2179
4901
  exports.useCallRoom = useCallRoom;
4902
+ exports.useCallSummary = useCallSummary;
4903
+ exports.useCaptions = useCaptions;
4904
+ exports.useCatchUp = useCatchUp;
2180
4905
  exports.useClientTimings = useClientTimings;
4906
+ exports.useClip = useClip;
2181
4907
  exports.useConversation = useConversation;
4908
+ exports.useConversationAgents = useConversationAgents;
2182
4909
  exports.useConversationPresence = useConversationPresence;
2183
4910
  exports.useConversations = useConversations;
4911
+ exports.useCustomEmoji = useCustomEmoji;
4912
+ exports.useEscalations = useEscalations;
4913
+ exports.useFiles = useFiles;
4914
+ exports.useFollowups = useFollowups;
2184
4915
  exports.useLiveCall = useLiveCall;
4916
+ exports.useLiveTranscript = useLiveTranscript;
4917
+ exports.useLobby = useLobby;
2185
4918
  exports.useMe = useMe;
2186
4919
  exports.useMembers = useMembers;
4920
+ exports.useMemory = useMemory;
2187
4921
  exports.useMessageStreams = useMessageStreams;
2188
4922
  exports.useMessages = useMessages;
4923
+ exports.useMoments = useMoments;
4924
+ exports.useOptionalPoolse = useOptionalPoolse;
2189
4925
  exports.useOutbox = useOutbox;
4926
+ exports.usePins = usePins;
4927
+ exports.usePoll = usePoll;
2190
4928
  exports.usePoolse = usePoolse;
2191
4929
  exports.usePresence = usePresence;
2192
4930
  exports.usePresenceMany = usePresenceMany;
4931
+ exports.useQuestions = useQuestions;
2193
4932
  exports.useReactions = useReactions;
2194
4933
  exports.useReadReceipts = useReadReceipts;
2195
4934
  exports.useRealtimeStatus = useRealtimeStatus;
4935
+ exports.useRecording = useRecording;
4936
+ exports.useRecordingPlayback = useRecordingPlayback;
4937
+ exports.useRecordingUrl = useRecordingUrl;
4938
+ exports.useRecordings = useRecordings;
2196
4939
  exports.useRoom = useRoom;
4940
+ exports.useRoomPresence = useRoomPresence;
4941
+ exports.useScheduledMessages = useScheduledMessages;
4942
+ exports.useScreenAnnotations = useScreenAnnotations;
4943
+ exports.useStage = useStage;
2197
4944
  exports.useThread = useThread;
4945
+ exports.useThreadFollow = useThreadFollow;
4946
+ exports.useTranscript = useTranscript;
4947
+ exports.useTranscripts = useTranscripts;
4948
+ exports.useTranslation = useTranslation;
2198
4949
  exports.useTyping = useTyping;
2199
4950
  exports.useUnreadQueue = useUnreadQueue;
2200
4951
  exports.useUnreadTotals = useUnreadTotals;
2201
4952
  exports.useUser = useUser;
2202
4953
  exports.useUserPresence = useUserPresence;
4954
+ exports.useWhisper = useWhisper;
4955
+ exports.useWhiteboard = useWhiteboard;
4956
+ exports.waveformBars = waveformBars;
2203
4957
  //# sourceMappingURL=index.cjs.map
2204
4958
  //# sourceMappingURL=index.cjs.map