@arbidocs/react 0.5.137 → 0.5.139

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
@@ -2,7 +2,7 @@
2
2
 
3
3
  var chunkTMPDW7J5_cjs = require('./chunk-TMPDW7J5.cjs');
4
4
  var chunk26SZ3DS4_cjs = require('./chunk-26SZ3DS4.cjs');
5
- var chunkPDE246CA_cjs = require('./chunk-PDE246CA.cjs');
5
+ var chunkVO7OWQP6_cjs = require('./chunk-VO7OWQP6.cjs');
6
6
  var chunkZZZYVNFW_cjs = require('./chunk-ZZZYVNFW.cjs');
7
7
  var chunkFDYZA6NO_cjs = require('./chunk-FDYZA6NO.cjs');
8
8
  var chunkFE6ZSNZE_cjs = require('./chunk-FE6ZSNZE.cjs');
@@ -1679,19 +1679,11 @@ function subscribeDocumentReads(qc, onRows) {
1679
1679
  var STALE_TASK_MS = 6 * 60 * 60 * 1e3;
1680
1680
  var ORPHAN_TASK_MS = 15 * 60 * 1e3;
1681
1681
  var SNAPSHOT_MS = 500;
1682
- function applyTaskEvent(queryClient, arbi, message, me) {
1683
- const workspaceId = message.workspace_ext_id;
1684
- if (!workspaceId) return;
1685
- if (chunkPDE246CA_cjs.FINISHED_DOCUMENT_STATUSES.has(message.status)) {
1686
- void chunkPDE246CA_cjs.refreshDocuments(queryClient, arbi, [message.doc_ext_id]);
1687
- return;
1688
- }
1689
- const cached = chunkPDE246CA_cjs.getCachedDocuments(queryClient, workspaceId);
1690
- if (!cached || cached.some((d) => d.external_id === message.doc_ext_id)) return;
1682
+ function placeholderRow(message, me) {
1691
1683
  const now = (/* @__PURE__ */ new Date()).toISOString();
1692
- const placeholder = {
1684
+ return {
1693
1685
  external_id: message.doc_ext_id,
1694
- workspace_ext_id: workspaceId,
1686
+ workspace_ext_id: message.workspace_ext_id,
1695
1687
  file_name: message.file_name ?? "Uploading\u2026",
1696
1688
  status: message.status,
1697
1689
  folder: message.folder ?? null,
@@ -1703,23 +1695,50 @@ function applyTaskEvent(queryClient, arbi, message, me) {
1703
1695
  created_at: now,
1704
1696
  updated_at: now
1705
1697
  };
1706
- chunkPDE246CA_cjs.patchDocuments(
1707
- queryClient,
1708
- (old) => old.some((d) => d.external_id === message.doc_ext_id) ? old : [...old, placeholder],
1709
- workspaceId
1710
- );
1698
+ }
1699
+ function applyTaskEvents(queryClient, arbi, messages, me) {
1700
+ const finished = /* @__PURE__ */ new Set();
1701
+ const pending = /* @__PURE__ */ new Map();
1702
+ for (const message of messages) {
1703
+ const workspaceId = message.workspace_ext_id;
1704
+ if (!workspaceId) continue;
1705
+ if (chunkVO7OWQP6_cjs.FINISHED_DOCUMENT_STATUSES.has(message.status)) {
1706
+ finished.add(message.doc_ext_id);
1707
+ continue;
1708
+ }
1709
+ const rows = pending.get(workspaceId) ?? /* @__PURE__ */ new Map();
1710
+ if (!rows.has(message.doc_ext_id)) rows.set(message.doc_ext_id, message);
1711
+ pending.set(workspaceId, rows);
1712
+ }
1713
+ chunkVO7OWQP6_cjs.queueDocumentReads(queryClient, arbi, [...finished]);
1714
+ for (const [workspaceId, rows] of pending) {
1715
+ const cached = chunkVO7OWQP6_cjs.getCachedDocuments(queryClient, workspaceId);
1716
+ if (!cached) continue;
1717
+ const listed = new Set(cached.map((d) => d.external_id));
1718
+ const fresh = [...rows.values()].filter((m) => !listed.has(m.doc_ext_id));
1719
+ if (!fresh.length) continue;
1720
+ chunkVO7OWQP6_cjs.patchDocuments(
1721
+ queryClient,
1722
+ (old) => {
1723
+ const known = old === cached ? listed : new Set(old.map((d) => d.external_id));
1724
+ const add = fresh.filter((m) => !known.has(m.doc_ext_id)).map((m) => placeholderRow(m, me));
1725
+ return add.length ? [...old, ...add] : old;
1726
+ },
1727
+ workspaceId
1728
+ );
1729
+ }
1711
1730
  }
1712
1731
  function useWorkspaceProcessing(workspaceId) {
1713
1732
  const queryClient = reactQuery.useQueryClient();
1714
1733
  const arbi = chunkFE6ZSNZE_cjs.useArbi();
1715
- const [snapshot, setSnapshot] = React.useState(() => chunkPDE246CA_cjs.useArbiWsStore.getState().tasks);
1734
+ const [snapshot, setSnapshot] = React.useState(() => chunkVO7OWQP6_cjs.useArbiWsStore.getState().tasks);
1716
1735
  React.useEffect(() => {
1717
1736
  let timer = null;
1718
- const unsubscribe = chunkPDE246CA_cjs.useArbiWsStore.subscribe((state, previous) => {
1737
+ const unsubscribe = chunkVO7OWQP6_cjs.useArbiWsStore.subscribe((state, previous) => {
1719
1738
  if (state.tasks === previous.tasks || timer) return;
1720
1739
  timer = setTimeout(() => {
1721
1740
  timer = null;
1722
- setSnapshot(chunkPDE246CA_cjs.useArbiWsStore.getState().tasks);
1741
+ setSnapshot(chunkVO7OWQP6_cjs.useArbiWsStore.getState().tasks);
1723
1742
  }, SNAPSHOT_MS);
1724
1743
  });
1725
1744
  return () => {
@@ -1729,18 +1748,18 @@ function useWorkspaceProcessing(workspaceId) {
1729
1748
  }, []);
1730
1749
  React.useEffect(() => {
1731
1750
  if (!workspaceId) return;
1732
- const store2 = chunkPDE246CA_cjs.useArbiWsStore.getState();
1733
- const documents2 = chunkPDE246CA_cjs.getCachedDocuments(queryClient, workspaceId) ?? [];
1734
- store2.settleTasks(documents2);
1735
- const listed = new Set(documents2.map((d) => d.external_id));
1751
+ const store2 = chunkVO7OWQP6_cjs.useArbiWsStore.getState();
1752
+ const documents3 = chunkVO7OWQP6_cjs.getCachedDocuments(queryClient, workspaceId) ?? [];
1753
+ store2.settleTasks(documents3);
1754
+ const listed = new Set(documents3.map((d) => d.external_id));
1736
1755
  const now = Date.now();
1737
- for (const task of Object.values(chunkPDE246CA_cjs.useArbiWsStore.getState().tasks)) {
1738
- if (task.workspace_ext_id !== workspaceId || !chunkPDE246CA_cjs.IN_FLIGHT_DOCUMENT_STATUSES.has(task.status))
1756
+ for (const task of Object.values(chunkVO7OWQP6_cjs.useArbiWsStore.getState().tasks)) {
1757
+ if (task.workspace_ext_id !== workspaceId || !chunkVO7OWQP6_cjs.IN_FLIGHT_DOCUMENT_STATUSES.has(task.status))
1739
1758
  continue;
1740
1759
  const since = task.startTime ?? task.endTime;
1741
1760
  const age = since == null ? null : now - since;
1742
1761
  const stale = age != null && age > STALE_TASK_MS;
1743
- const orphan = documents2.length > 0 && !listed.has(task.doc_ext_id) && age != null && age > ORPHAN_TASK_MS;
1762
+ const orphan = documents3.length > 0 && !listed.has(task.doc_ext_id) && age != null && age > ORPHAN_TASK_MS;
1744
1763
  if (stale || orphan) store2.clearTask(task.doc_ext_id);
1745
1764
  }
1746
1765
  }, [workspaceId, queryClient]);
@@ -1748,16 +1767,16 @@ function useWorkspaceProcessing(workspaceId) {
1748
1767
  if (!workspaceId) return;
1749
1768
  const unsubscribeReads = subscribeDocumentReads(
1750
1769
  queryClient,
1751
- (rows) => chunkPDE246CA_cjs.useArbiWsStore.getState().settleTasks(rows)
1770
+ (rows) => chunkVO7OWQP6_cjs.useArbiWsStore.getState().settleTasks(rows)
1752
1771
  );
1753
1772
  const recheck = async () => {
1754
- const ids2 = Object.values(chunkPDE246CA_cjs.useArbiWsStore.getState().tasks).filter(
1755
- (t) => t.workspace_ext_id === workspaceId && chunkPDE246CA_cjs.IN_FLIGHT_DOCUMENT_STATUSES.has(t.status)
1773
+ const ids2 = Object.values(chunkVO7OWQP6_cjs.useArbiWsStore.getState().tasks).filter(
1774
+ (t) => t.workspace_ext_id === workspaceId && chunkVO7OWQP6_cjs.IN_FLIGHT_DOCUMENT_STATUSES.has(t.status)
1756
1775
  ).map((t) => t.doc_ext_id);
1757
- if (ids2.length) await chunkPDE246CA_cjs.refreshDocuments(queryClient, arbi, ids2);
1776
+ if (ids2.length) await chunkVO7OWQP6_cjs.refreshDocuments(queryClient, arbi, ids2);
1758
1777
  };
1759
- let wasConnected = chunkPDE246CA_cjs.useArbiWsStore.getState().status === "connected";
1760
- const unsubscribeStatus = chunkPDE246CA_cjs.useArbiWsStore.subscribe((state) => {
1778
+ let wasConnected = chunkVO7OWQP6_cjs.useArbiWsStore.getState().status === "connected";
1779
+ const unsubscribeStatus = chunkVO7OWQP6_cjs.useArbiWsStore.subscribe((state) => {
1761
1780
  const connected = state.status === "connected";
1762
1781
  if (connected && !wasConnected) void recheck();
1763
1782
  wasConnected = connected;
@@ -1772,11 +1791,11 @@ function useWorkspaceProcessing(workspaceId) {
1772
1791
  const count = (statuses) => allTasks.filter(
1773
1792
  (t) => Array.isArray(statuses) ? statuses.includes(t.status) : statuses.has(t.status)
1774
1793
  ).length;
1775
- const { clearTask, clearFinishedTasks } = chunkPDE246CA_cjs.useArbiWsStore.getState();
1794
+ const { clearTask, clearFinishedTasks } = chunkVO7OWQP6_cjs.useArbiWsStore.getState();
1776
1795
  return {
1777
1796
  tasks: Object.fromEntries(allTasks.map((t) => [t.doc_ext_id, t])),
1778
1797
  allTasks,
1779
- processingCount: count(chunkPDE246CA_cjs.IN_FLIGHT_DOCUMENT_STATUSES),
1798
+ processingCount: count(chunkVO7OWQP6_cjs.IN_FLIGHT_DOCUMENT_STATUSES),
1780
1799
  completedCount: count(["completed", "low-content"]),
1781
1800
  failedCount: count(["failed"]),
1782
1801
  skippedCount: count(["skipped"]),
@@ -1788,7 +1807,7 @@ function useWorkspaceProcessing(workspaceId) {
1788
1807
  function applyOptimisticDocumentEdit(qc, updates) {
1789
1808
  const byId = new Map(updates.map((update2) => [update2.external_id, update2]));
1790
1809
  const previous = [];
1791
- chunkPDE246CA_cjs.patchDocuments(qc, (old) => {
1810
+ chunkVO7OWQP6_cjs.patchDocuments(qc, (old) => {
1792
1811
  let changed = false;
1793
1812
  const next = old.map((doc) => {
1794
1813
  const update2 = byId.get(doc.external_id);
@@ -1803,7 +1822,7 @@ function applyOptimisticDocumentEdit(qc, updates) {
1803
1822
  const own = qc.getQueryData(
1804
1823
  chunkFE6ZSNZE_cjs.arbiQueryKeys.document(update2.external_id)
1805
1824
  );
1806
- if (own) chunkPDE246CA_cjs.setCachedDocument(qc, { ...own, ...update2 });
1825
+ if (own) chunkVO7OWQP6_cjs.setCachedDocument(qc, { ...own, ...update2 });
1807
1826
  return [update2.external_id, own];
1808
1827
  });
1809
1828
  return { optimistic: true, previous, previousOwn };
@@ -1813,7 +1832,7 @@ function rollbackOptimisticDocumentEdit(qc, context) {
1813
1832
  if (!edit?.optimistic) return;
1814
1833
  if (edit.previous.length) {
1815
1834
  const restore = new Map(edit.previous.map((doc) => [doc.external_id, doc]));
1816
- chunkPDE246CA_cjs.patchDocuments(
1835
+ chunkVO7OWQP6_cjs.patchDocuments(
1817
1836
  qc,
1818
1837
  (old) => old.some((doc) => restore.has(doc.external_id)) ? old.map((doc) => restore.get(doc.external_id) ?? doc) : old
1819
1838
  );
@@ -1823,19 +1842,19 @@ function rollbackOptimisticDocumentEdit(qc, context) {
1823
1842
  function settleUpdatedDocuments(qc, updated) {
1824
1843
  if (!updated.length) return;
1825
1844
  const byId = new Map(updated.map((doc) => [doc.external_id, doc]));
1826
- chunkPDE246CA_cjs.patchDocuments(
1845
+ chunkVO7OWQP6_cjs.patchDocuments(
1827
1846
  qc,
1828
1847
  (old) => old.some((doc) => byId.has(doc.external_id)) ? old.map((doc) => byId.get(doc.external_id) ?? doc) : old
1829
1848
  );
1830
- for (const doc of updated) chunkPDE246CA_cjs.setCachedDocument(qc, doc);
1849
+ for (const doc of updated) chunkVO7OWQP6_cjs.setCachedDocument(qc, doc);
1831
1850
  }
1832
1851
  function patchEachDocument(qc, docIds, reducer) {
1833
1852
  const ids2 = new Set(docIds);
1834
- chunkPDE246CA_cjs.patchDocuments(
1853
+ chunkVO7OWQP6_cjs.patchDocuments(
1835
1854
  qc,
1836
1855
  (old) => old.some((doc) => ids2.has(doc.external_id)) ? old.map((doc) => ids2.has(doc.external_id) ? reducer(doc) : doc) : old
1837
1856
  );
1838
- for (const id of ids2) chunkPDE246CA_cjs.patchCachedDocument(qc, id, reducer);
1857
+ for (const id of ids2) chunkVO7OWQP6_cjs.patchCachedDocument(qc, id, reducer);
1839
1858
  }
1840
1859
  function workspaceOf(qc, docId) {
1841
1860
  for (const [, docs] of qc.getQueriesData({
@@ -1862,7 +1881,7 @@ function settleAssignedDocTags(qc, created) {
1862
1881
  ...doc,
1863
1882
  doctags: [...doc.doctags ?? [], ...byDoc.get(doc.external_id) ?? []]
1864
1883
  }));
1865
- for (const [workspaceId, delta] of workspaces) chunkPDE246CA_cjs.adjustTagCounts(qc, workspaceId, delta);
1884
+ for (const [workspaceId, delta] of workspaces) chunkVO7OWQP6_cjs.adjustTagCounts(qc, workspaceId, delta);
1866
1885
  }
1867
1886
  function settleRemovedDocTags(qc, { tagId, docIds }) {
1868
1887
  const ids2 = new Set(docIds);
@@ -1884,7 +1903,7 @@ function settleRemovedDocTags(qc, { tagId, docIds }) {
1884
1903
  doctags: (doc.doctags ?? []).filter((dt) => dt.tag_ext_id !== tagId)
1885
1904
  }));
1886
1905
  for (const [workspaceId, removed] of removedByWorkspace)
1887
- chunkPDE246CA_cjs.adjustTagCounts(qc, workspaceId, /* @__PURE__ */ new Map([[tagId, -removed]]));
1906
+ chunkVO7OWQP6_cjs.adjustTagCounts(qc, workspaceId, /* @__PURE__ */ new Map([[tagId, -removed]]));
1888
1907
  }
1889
1908
  function settleUpdatedDocTag(qc, updated) {
1890
1909
  patchEachDocument(qc, [updated.doc_ext_id], (doc) => ({
@@ -1892,23 +1911,23 @@ function settleUpdatedDocTag(qc, updated) {
1892
1911
  doctags: (doc.doctags ?? []).map((dt) => dt.tag_ext_id === updated.tag_ext_id ? updated : dt)
1893
1912
  }));
1894
1913
  }
1895
- var sendUpdateDocuments = (client, input) => chunkPDE246CA_cjs.inWorkspace(
1896
- chunkPDE246CA_cjs.primeOnClient(client),
1914
+ var sendUpdateDocuments = (client, input) => chunkVO7OWQP6_cjs.inWorkspace(
1915
+ chunkVO7OWQP6_cjs.primeOnClient(client),
1897
1916
  input.workspaceId,
1898
1917
  () => browser.documents.updateDocuments(client, input.documents)
1899
1918
  );
1900
- var sendAssignDocTags = (client, input) => chunkPDE246CA_cjs.inWorkspace(
1901
- chunkPDE246CA_cjs.primeOnClient(client),
1919
+ var sendAssignDocTags = (client, input) => chunkVO7OWQP6_cjs.inWorkspace(
1920
+ chunkVO7OWQP6_cjs.primeOnClient(client),
1902
1921
  input.workspaceId,
1903
1922
  () => browser.doctags.assignDocTags(client, input.tagId, input.docIds, input.note, input.citations)
1904
1923
  );
1905
- var sendRemoveDocTags = (client, input) => chunkPDE246CA_cjs.inWorkspace(
1906
- chunkPDE246CA_cjs.primeOnClient(client),
1924
+ var sendRemoveDocTags = (client, input) => chunkVO7OWQP6_cjs.inWorkspace(
1925
+ chunkVO7OWQP6_cjs.primeOnClient(client),
1907
1926
  input.workspaceId,
1908
1927
  () => browser.doctags.removeDocTags(client, input.tagId, input.docIds)
1909
1928
  );
1910
- var sendUpdateDocTag = (client, input) => chunkPDE246CA_cjs.inWorkspace(
1911
- chunkPDE246CA_cjs.primeOnClient(client),
1929
+ var sendUpdateDocTag = (client, input) => chunkVO7OWQP6_cjs.inWorkspace(
1930
+ chunkVO7OWQP6_cjs.primeOnClient(client),
1912
1931
  input.workspaceId,
1913
1932
  () => browser.doctags.updateDocTag(client, input.tagId, input.docId, {
1914
1933
  note: input.note,
@@ -1961,7 +1980,7 @@ function useMarkDocumentShared() {
1961
1980
  const qc = reactQuery.useQueryClient();
1962
1981
  return React.useCallback(
1963
1982
  (documentExtId) => {
1964
- chunkPDE246CA_cjs.patchDocuments(
1983
+ chunkVO7OWQP6_cjs.patchDocuments(
1965
1984
  qc,
1966
1985
  (old) => old.map((doc) => doc.external_id === documentExtId ? { ...doc, shared: true } : doc)
1967
1986
  );
@@ -1977,21 +1996,21 @@ function useUpdateDocuments() {
1977
1996
  (input) => input.documents[0]?.external_id
1978
1997
  );
1979
1998
  return resolvingOffline(
1980
- chunkPDE246CA_cjs.useCapturingWorkspace(
1999
+ chunkVO7OWQP6_cjs.useCapturingWorkspace(
1981
2000
  reactQuery.useMutation({
1982
2001
  mutationKey: chunkFE6ZSNZE_cjs.arbiMutationKeys.updateDocuments(),
1983
- mutationFn: (input) => chunkPDE246CA_cjs.inWorkspace(
1984
- chunkPDE246CA_cjs.primeOnArbi(arbi),
2002
+ mutationFn: (input) => chunkVO7OWQP6_cjs.inWorkspace(
2003
+ chunkVO7OWQP6_cjs.primeOnArbi(arbi),
1985
2004
  input.workspaceId,
1986
2005
  () => arbi.documents.update(input.documents)
1987
2006
  ),
1988
- onMutate: ({ documents: documents2 }) => reactQuery.onlineManager.isOnline() || !documents2.length ? void 0 : applyOptimisticDocumentEdit(qc, documents2),
2007
+ onMutate: ({ documents: documents3 }) => reactQuery.onlineManager.isOnline() || !documents3.length ? void 0 : applyOptimisticDocumentEdit(qc, documents3),
1989
2008
  // Not sent because its workspace can't be opened: the edit stays, listed as not sent.
1990
2009
  onError: (error, _input, context) => {
1991
- if (!chunkPDE246CA_cjs.isWorkspaceUnavailable(error)) rollbackOptimisticDocumentEdit(qc, context);
2010
+ if (!chunkVO7OWQP6_cjs.isWorkspaceUnavailable(error)) rollbackOptimisticDocumentEdit(qc, context);
1992
2011
  },
1993
2012
  onSuccess: (updated) => settleUpdatedDocuments(qc, updated),
1994
- ...chunkPDE246CA_cjs.QUEUED_WRITE_RETRY
2013
+ ...chunkVO7OWQP6_cjs.QUEUED_WRITE_RETRY
1995
2014
  }),
1996
2015
  capture
1997
2016
  )
@@ -2004,7 +2023,7 @@ function useRenameFolder() {
2004
2023
  const qc = reactQuery.useQueryClient();
2005
2024
  const { mutateAsync } = useUpdateDocuments();
2006
2025
  return React.useCallback(
2007
- async (documents2, from, to) => {
2026
+ async (documents3, from, to) => {
2008
2027
  const moved = (folder) => {
2009
2028
  const segments = folderSegments(folder);
2010
2029
  if (from.length === 0 || segments.length < from.length) return void 0;
@@ -2012,12 +2031,12 @@ function useRenameFolder() {
2012
2031
  const next = [...to, ...segments.slice(from.length)];
2013
2032
  return next.length > 0 ? next.join("/") : null;
2014
2033
  };
2015
- const updates = documents2.flatMap((doc) => {
2034
+ const updates = documents3.flatMap((doc) => {
2016
2035
  const folder = moved(doc.folder);
2017
2036
  return folder === void 0 ? [] : [{ external_id: doc.external_id, folder }];
2018
2037
  });
2019
2038
  if (updates.length > 0) await mutateAsync({ documents: updates });
2020
- chunkPDE246CA_cjs.patchDocuments(qc, (rows) => {
2039
+ chunkVO7OWQP6_cjs.patchDocuments(qc, (rows) => {
2021
2040
  let changed = false;
2022
2041
  const next = rows.map((doc) => {
2023
2042
  const folder = moved(doc.folder);
@@ -2040,19 +2059,19 @@ function useDeleteDocuments() {
2040
2059
  mutationFn: (docIds) => arbi.documents.delete(docIds),
2041
2060
  onSuccess: (_data, docIds) => {
2042
2061
  const gone = new Set(docIds);
2043
- chunkPDE246CA_cjs.patchDocuments(
2062
+ chunkVO7OWQP6_cjs.patchDocuments(
2044
2063
  qc,
2045
2064
  (old) => old.some((doc) => gone.has(doc.external_id)) ? old.filter((doc) => !gone.has(doc.external_id)) : old
2046
2065
  );
2047
- chunkPDE246CA_cjs.forgetDocuments(qc, docIds);
2048
- const { clearTask } = chunkPDE246CA_cjs.useArbiWsStore.getState();
2066
+ chunkVO7OWQP6_cjs.forgetDocuments(qc, docIds);
2067
+ const { clearTask } = chunkVO7OWQP6_cjs.useArbiWsStore.getState();
2049
2068
  for (const id of docIds) clearTask(id);
2050
2069
  return qc.invalidateQueries({ queryKey: chunkFE6ZSNZE_cjs.arbiQueryKeys.workspaces() });
2051
2070
  }
2052
2071
  });
2053
2072
  }
2054
2073
  async function settleUpload(qc, arbi, docIds) {
2055
- if (docIds?.length) await chunkPDE246CA_cjs.refreshDocuments(qc, arbi, docIds);
2074
+ if (docIds?.length) await chunkVO7OWQP6_cjs.refreshDocuments(qc, arbi, docIds);
2056
2075
  await qc.invalidateQueries({ queryKey: chunkFE6ZSNZE_cjs.arbiQueryKeys.workspaces() });
2057
2076
  }
2058
2077
  function useUploadDocuments() {
@@ -2082,16 +2101,16 @@ function useAssignDocTags() {
2082
2101
  const qc = reactQuery.useQueryClient();
2083
2102
  const capture = useDocumentWriteWorkspace((input) => input.docIds[0]);
2084
2103
  return resolvingOffline(
2085
- chunkPDE246CA_cjs.useCapturingWorkspace(
2104
+ chunkVO7OWQP6_cjs.useCapturingWorkspace(
2086
2105
  reactQuery.useMutation({
2087
2106
  mutationKey: chunkFE6ZSNZE_cjs.arbiMutationKeys.assignDocTags(),
2088
- mutationFn: ({ workspaceId, tagId, docIds, note, citations }) => chunkPDE246CA_cjs.inWorkspace(
2089
- chunkPDE246CA_cjs.primeOnArbi(arbi),
2107
+ mutationFn: ({ workspaceId, tagId, docIds, note, citations }) => chunkVO7OWQP6_cjs.inWorkspace(
2108
+ chunkVO7OWQP6_cjs.primeOnArbi(arbi),
2090
2109
  workspaceId,
2091
2110
  () => arbi.doctags.assign(tagId, docIds, note, citations)
2092
2111
  ),
2093
2112
  onSuccess: (created) => settleAssignedDocTags(qc, created),
2094
- ...chunkPDE246CA_cjs.QUEUED_WRITE_RETRY
2113
+ ...chunkVO7OWQP6_cjs.QUEUED_WRITE_RETRY
2095
2114
  }),
2096
2115
  capture
2097
2116
  )
@@ -2102,12 +2121,12 @@ function useRemoveDocTags() {
2102
2121
  const qc = reactQuery.useQueryClient();
2103
2122
  const capture = useDocumentWriteWorkspace((input) => input.docIds[0]);
2104
2123
  return resolvingOffline(
2105
- chunkPDE246CA_cjs.useCapturingWorkspace(
2124
+ chunkVO7OWQP6_cjs.useCapturingWorkspace(
2106
2125
  reactQuery.useMutation({
2107
2126
  mutationKey: chunkFE6ZSNZE_cjs.arbiMutationKeys.removeDocTags(),
2108
- mutationFn: ({ workspaceId, tagId, docIds }) => chunkPDE246CA_cjs.inWorkspace(chunkPDE246CA_cjs.primeOnArbi(arbi), workspaceId, () => arbi.doctags.remove(tagId, docIds)),
2127
+ mutationFn: ({ workspaceId, tagId, docIds }) => chunkVO7OWQP6_cjs.inWorkspace(chunkVO7OWQP6_cjs.primeOnArbi(arbi), workspaceId, () => arbi.doctags.remove(tagId, docIds)),
2109
2128
  onSuccess: (_data, input) => settleRemovedDocTags(qc, input),
2110
- ...chunkPDE246CA_cjs.QUEUED_WRITE_RETRY
2129
+ ...chunkVO7OWQP6_cjs.QUEUED_WRITE_RETRY
2111
2130
  }),
2112
2131
  capture
2113
2132
  )
@@ -2118,26 +2137,26 @@ function useUpdateDocTag() {
2118
2137
  const qc = reactQuery.useQueryClient();
2119
2138
  const capture = useDocumentWriteWorkspace((input) => input.docId);
2120
2139
  return resolvingOffline(
2121
- chunkPDE246CA_cjs.useCapturingWorkspace(
2140
+ chunkVO7OWQP6_cjs.useCapturingWorkspace(
2122
2141
  reactQuery.useMutation({
2123
2142
  mutationKey: chunkFE6ZSNZE_cjs.arbiMutationKeys.updateDocTag(),
2124
- mutationFn: ({ workspaceId, tagId, docId, note, citations }) => chunkPDE246CA_cjs.inWorkspace(
2125
- chunkPDE246CA_cjs.primeOnArbi(arbi),
2143
+ mutationFn: ({ workspaceId, tagId, docId, note, citations }) => chunkVO7OWQP6_cjs.inWorkspace(
2144
+ chunkVO7OWQP6_cjs.primeOnArbi(arbi),
2126
2145
  workspaceId,
2127
2146
  () => arbi.doctags.update(tagId, docId, { note, citations })
2128
2147
  ),
2129
2148
  onSuccess: (updated) => settleUpdatedDocTag(qc, updated),
2130
- ...chunkPDE246CA_cjs.QUEUED_WRITE_RETRY
2149
+ ...chunkVO7OWQP6_cjs.QUEUED_WRITE_RETRY
2131
2150
  }),
2132
2151
  capture
2133
2152
  )
2134
2153
  );
2135
2154
  }
2136
- function queueProcessing(documents2) {
2137
- const store2 = chunkPDE246CA_cjs.useArbiWsStore.getState();
2138
- const previous = documents2.map(({ docId }) => [docId, store2.tasks[docId]]);
2155
+ function queueProcessing(documents3) {
2156
+ const store2 = chunkVO7OWQP6_cjs.useArbiWsStore.getState();
2157
+ const previous = documents3.map(({ docId }) => [docId, store2.tasks[docId]]);
2139
2158
  const now = Date.now();
2140
- for (const doc of documents2)
2159
+ for (const doc of documents3)
2141
2160
  store2.putTask({
2142
2161
  doc_ext_id: doc.docId,
2143
2162
  workspace_ext_id: doc.workspaceId,
@@ -2147,7 +2166,7 @@ function queueProcessing(documents2) {
2147
2166
  progress: 0,
2148
2167
  startTime: now
2149
2168
  });
2150
- return () => chunkPDE246CA_cjs.useArbiWsStore.setState((state) => {
2169
+ return () => chunkVO7OWQP6_cjs.useArbiWsStore.setState((state) => {
2151
2170
  const tasks = { ...state.tasks };
2152
2171
  for (const [docId, task] of previous) {
2153
2172
  if (task) tasks[docId] = task;
@@ -2166,7 +2185,7 @@ function useGenerateDocTags() {
2166
2185
  if (!docIds.length) return void 0;
2167
2186
  const workspaceId = arbi.hasWorkspace ? arbi.getWorkspaceId() : "";
2168
2187
  const listed = new Map(
2169
- (chunkPDE246CA_cjs.getCachedDocuments(qc, workspaceId) ?? []).map((doc) => [doc.external_id, doc])
2188
+ (chunkVO7OWQP6_cjs.getCachedDocuments(qc, workspaceId) ?? []).map((doc) => [doc.external_id, doc])
2170
2189
  );
2171
2190
  return {
2172
2191
  undo: queueProcessing(
@@ -2187,7 +2206,7 @@ function useFinaliseTranslation() {
2187
2206
  const qc = reactQuery.useQueryClient();
2188
2207
  return reactQuery.useMutation({
2189
2208
  mutationFn: (docId) => arbi.documents.finaliseTranslation(docId),
2190
- onSuccess: (result) => void chunkPDE246CA_cjs.refreshDocuments(qc, arbi, [result.document_ext_id])
2209
+ onSuccess: (result) => void chunkVO7OWQP6_cjs.refreshDocuments(qc, arbi, [result.document_ext_id])
2191
2210
  });
2192
2211
  }
2193
2212
 
@@ -2197,10 +2216,10 @@ function useDocumentsSupport() {
2197
2216
  return chunkFE6ZSNZE_cjs.useArbiHost().documents ?? NO_SUPPORT;
2198
2217
  }
2199
2218
  function useProcessingTasks() {
2200
- return chunkPDE246CA_cjs.useArbiWsStore((state) => state.tasks);
2219
+ return chunkVO7OWQP6_cjs.useArbiWsStore((state) => state.tasks);
2201
2220
  }
2202
2221
  function useProcessingTask(docId) {
2203
- return chunkPDE246CA_cjs.useArbiWsStore((state) => state.tasks[docId]);
2222
+ return chunkVO7OWQP6_cjs.useArbiWsStore((state) => state.tasks[docId]);
2204
2223
  }
2205
2224
  var NO_ACTIONS = {};
2206
2225
  function useDocumentHostActions() {
@@ -2236,9 +2255,9 @@ var COLUMN_MAPPING = {
2236
2255
  file_size: { header: "File Size", getValue: (d) => d.file_size || "" },
2237
2256
  shared: { header: "Shared", getValue: (d) => d.shared ? "Yes" : "No" }
2238
2257
  };
2239
- function buildDocumentMetadataRows(documents2, selectedColumns) {
2258
+ function buildDocumentMetadataRows(documents3, selectedColumns) {
2240
2259
  const columns = selectedColumns || Object.keys(COLUMN_MAPPING);
2241
- return documents2.map((doc) => {
2260
+ return documents3.map((doc) => {
2242
2261
  const row = {};
2243
2262
  for (const colId of columns) {
2244
2263
  const standard = COLUMN_MAPPING[colId];
@@ -2270,9 +2289,9 @@ function useDownloadDocuments({ workspaceName } = {}) {
2270
2289
  );
2271
2290
  const downloadDocuments = React.useCallback(
2272
2291
  // selectedColumns: undefined = all default columns; [] = files only (no index.csv)
2273
- async (documents2, selectedColumns) => {
2292
+ async (documents3, selectedColumns) => {
2274
2293
  const includeMetadataCsv = selectedColumns === void 0 || selectedColumns.length > 0;
2275
- if (documents2.length === 0) {
2294
+ if (documents3.length === 0) {
2276
2295
  chunkIX4HOS5Z_cjs.notify.error("No documents to download");
2277
2296
  return;
2278
2297
  }
@@ -2282,7 +2301,7 @@ function useDownloadDocuments({ workspaceName } = {}) {
2282
2301
  const zip = new JSZip();
2283
2302
  const downloaded = [];
2284
2303
  const failedDocs = [];
2285
- for (const doc of documents2) {
2304
+ for (const doc of documents3) {
2286
2305
  try {
2287
2306
  const file = await fetchNamedFile(doc);
2288
2307
  zip.file(file.name, file.blob);
@@ -2394,7 +2413,7 @@ function useDocumentThumbnails(visibleIds) {
2394
2413
  for (const id of visibleIds)
2395
2414
  if (IN_PROGRESS.has(tasks[id]?.status ?? "")) resolvedRef.current.delete(id);
2396
2415
  const ready = visibleIds.filter(
2397
- (id) => !resolvedRef.current.has(id) && chunkPDE246CA_cjs.FINISHED_DOCUMENT_STATUSES.has(tasks[id]?.status ?? "")
2416
+ (id) => !resolvedRef.current.has(id) && chunkVO7OWQP6_cjs.FINISHED_DOCUMENT_STATUSES.has(tasks[id]?.status ?? "")
2398
2417
  );
2399
2418
  if (ready.length > 0) void fetchMissing(ready);
2400
2419
  }, [tasks, idsKey, fetchMissing]);
@@ -2416,8 +2435,8 @@ function DocumentReview({
2416
2435
  onClose,
2417
2436
  className
2418
2437
  }) {
2419
- const processingInProp = !!doc?.status && !chunkPDE246CA_cjs.FINISHED_DOCUMENT_STATUSES.has(doc.status);
2420
- const { data: polled } = chunkPDE246CA_cjs.useDocument(docId, {
2438
+ const processingInProp = !!doc?.status && !chunkVO7OWQP6_cjs.FINISHED_DOCUMENT_STATUSES.has(doc.status);
2439
+ const { data: polled } = chunkVO7OWQP6_cjs.useDocument(docId, {
2421
2440
  enabled: processingInProp,
2422
2441
  pollWhileProcessing: true
2423
2442
  });
@@ -3307,9 +3326,53 @@ function uploadFolderOf(file, base) {
3307
3326
  const own = slash > 0 ? relative.slice(0, slash) : "";
3308
3327
  return sanitizeFolderPath([base, own].filter(Boolean).join("/")) || null;
3309
3328
  }
3310
- var { mimeFromName: mimeFromName2 } = browser.documents;
3329
+
3330
+ // src/lib/throttle.ts
3331
+ function throttle(fn, intervalMs) {
3332
+ let last = -Infinity;
3333
+ let pending = null;
3334
+ let timer = null;
3335
+ const run2 = (args) => {
3336
+ last = Date.now();
3337
+ pending = null;
3338
+ fn(...args);
3339
+ };
3340
+ const clear = () => {
3341
+ if (timer) clearTimeout(timer);
3342
+ timer = null;
3343
+ };
3344
+ const throttled = ((...args) => {
3345
+ const wait = last + intervalMs - Date.now();
3346
+ if (wait <= 0 && !timer) {
3347
+ run2(args);
3348
+ return;
3349
+ }
3350
+ pending = args;
3351
+ if (!timer)
3352
+ timer = setTimeout(
3353
+ () => {
3354
+ timer = null;
3355
+ if (pending) run2(pending);
3356
+ },
3357
+ Math.max(0, wait)
3358
+ );
3359
+ });
3360
+ throttled.flush = () => {
3361
+ clear();
3362
+ if (pending) run2(pending);
3363
+ };
3364
+ throttled.cancel = () => {
3365
+ clear();
3366
+ pending = null;
3367
+ };
3368
+ return throttled;
3369
+ }
3370
+
3371
+ // src/documents/useUploadFiles.ts
3372
+ var { mimeFromName: mimeFromName2, newUploadSet } = browser.documents;
3311
3373
  var BATCH_SIZE2 = 100;
3312
3374
  var CONCURRENT_BATCHES = 4;
3375
+ var UPLOAD_PROGRESS_INTERVAL_MS = 100;
3313
3376
  var uploadedFolders = /* @__PURE__ */ new Map();
3314
3377
  function uploadedDocumentFolder(workspaceId, docId) {
3315
3378
  const pending = uploadedFolders.get(docId);
@@ -3357,17 +3420,22 @@ function useUploadFiles() {
3357
3420
  workspaceKey = null;
3358
3421
  }
3359
3422
  }
3423
+ const uploadSet = newUploadSet(input.files.length);
3360
3424
  const total = input.files.reduce((sum, file) => sum + file.size, 0);
3361
3425
  const loadedByBatch = new Array(batches.length).fill(0);
3362
3426
  const filesByBatch = new Array(batches.length).fill(0);
3363
3427
  let done = 0;
3364
3428
  let highest = 0;
3429
+ const emit = throttle(
3430
+ (progress) => onProgress?.(progress),
3431
+ UPLOAD_PROGRESS_INTERVAL_MS
3432
+ );
3365
3433
  const report = () => {
3366
3434
  const loaded = loadedByBatch.reduce((sum, bytes) => sum + bytes, 0);
3367
3435
  const sent = filesByBatch.reduce((sum, files) => sum + files, 0);
3368
3436
  const share = input.files.length > 0 ? sent / input.files.length : 0;
3369
3437
  highest = Math.max(highest, Math.min(Math.round(share * 100), 100));
3370
- onProgress?.({
3438
+ emit({
3371
3439
  loaded,
3372
3440
  total,
3373
3441
  percentage: highest,
@@ -3384,6 +3452,7 @@ function useUploadFiles() {
3384
3452
  configExtId: input.configExtId ?? void 0,
3385
3453
  // Named even when it is the open one: batches sent after a switch stay in this workspace.
3386
3454
  workspaceExtId: workspaceId,
3455
+ uploadSet,
3387
3456
  // One request for the batch: its files count by the share of its bytes sent.
3388
3457
  onProgress: (loaded) => {
3389
3458
  loadedByBatch[index] = Math.min(loaded, bytes);
@@ -3406,6 +3475,7 @@ function useUploadFiles() {
3406
3475
  shared: input.shared,
3407
3476
  folder: folder ?? void 0,
3408
3477
  configExtId: input.configExtId ?? void 0,
3478
+ uploadSet,
3409
3479
  // Per file, in ciphertext bytes: that file's share sent, scaled back to its own
3410
3480
  // size so the byte total stays true.
3411
3481
  onBytesProgress: ({ fileIndex, loaded, total: sent }) => {
@@ -3424,7 +3494,7 @@ function useUploadFiles() {
3424
3494
  if (docIds2.length > 0) {
3425
3495
  for (const docId of docIds2) uploadedFolders.set(docId, { workspaceId, folder });
3426
3496
  const made = new Set(docIds2);
3427
- chunkPDE246CA_cjs.patchDocuments(
3497
+ chunkVO7OWQP6_cjs.patchDocuments(
3428
3498
  qc,
3429
3499
  (rows) => rows.map((doc) => made.has(doc.external_id) ? { ...doc, folder } : doc),
3430
3500
  workspaceId
@@ -3437,20 +3507,22 @@ function useUploadFiles() {
3437
3507
  return result;
3438
3508
  }),
3439
3509
  CONCURRENT_BATCHES
3440
- );
3510
+ ).finally(() => emit.cancel());
3511
+ report();
3512
+ emit.flush();
3441
3513
  const docIds = results.flatMap((result) => result.doc_ext_ids ?? []);
3442
3514
  const skipped = results.flatMap((result) => result.skipped ?? []);
3443
- if (docIds.length > 0) {
3444
- const read = await chunkPDE246CA_cjs.refreshDocuments(qc, arbi, docIds);
3445
- for (const doc of read) forgetUploadedDocumentFolder(doc.external_id);
3446
- }
3447
- await qc.invalidateQueries({ queryKey: chunkFE6ZSNZE_cjs.arbiQueryKeys.workspaces() });
3448
- if (docIds.length > 0 && input.generateTagIds?.length) {
3449
- await generateDocTags({ tagIds: input.generateTagIds, docIds, overwrite: false }).catch(
3450
- () => void 0
3451
- );
3452
- }
3453
- return { docIds, skipped };
3515
+ const settled = (async () => {
3516
+ if (docIds.length > 0) {
3517
+ const read = await chunkVO7OWQP6_cjs.refreshDocuments(qc, arbi, docIds);
3518
+ for (const doc of read) forgetUploadedDocumentFolder(doc.external_id);
3519
+ }
3520
+ await qc.invalidateQueries({ queryKey: chunkFE6ZSNZE_cjs.arbiQueryKeys.workspaces() });
3521
+ if (docIds.length > 0 && input.generateTagIds?.length) {
3522
+ await generateDocTags({ tagIds: input.generateTagIds, docIds, overwrite: false });
3523
+ }
3524
+ })().catch(() => void 0);
3525
+ return { docIds, skipped, settled };
3454
3526
  },
3455
3527
  [arbi, qc, direct, resolveWorkspaceKey, generateDocTags]
3456
3528
  );
@@ -3534,11 +3606,11 @@ function getRelatedLabels(related) {
3534
3606
  }
3535
3607
  return parts;
3536
3608
  }
3537
- function useRelatedDocuments(documents2) {
3538
- const { data: similarData } = chunkPDE246CA_cjs.useSimilarDocuments();
3609
+ function useRelatedDocuments(documents3) {
3610
+ const { data: similarData } = chunkVO7OWQP6_cjs.useSimilarDocuments();
3539
3611
  const structuralKey = React.useMemo(() => {
3540
3612
  const parts = [];
3541
- for (const doc of documents2) {
3613
+ for (const doc of documents3) {
3542
3614
  parts.push(doc.external_id);
3543
3615
  parts.push(doc.parent_ext_id || "");
3544
3616
  parts.push(doc.content_hash || "");
@@ -3547,17 +3619,17 @@ function useRelatedDocuments(documents2) {
3547
3619
  parts.push(source.doc_ext_id, source.role, String(source.version ?? ""));
3548
3620
  }
3549
3621
  return parts.join("|");
3550
- }, [documents2]);
3622
+ }, [documents3]);
3551
3623
  const prevKeyRef = React.useRef(structuralKey);
3552
3624
  const prevMapRef = React.useRef(/* @__PURE__ */ new Map());
3553
- const prevDocsRef = React.useRef(documents2);
3625
+ const prevDocsRef = React.useRef(documents3);
3554
3626
  const prevSimilarRef = React.useRef(similarData);
3555
3627
  return React.useMemo(() => {
3556
- if (prevKeyRef.current === structuralKey && prevSimilarRef.current === similarData && prevMapRef.current.size > 0 && prevDocsRef.current === documents2) {
3628
+ if (prevKeyRef.current === structuralKey && prevSimilarRef.current === similarData && prevMapRef.current.size > 0 && prevDocsRef.current === documents3) {
3557
3629
  return prevMapRef.current;
3558
3630
  }
3559
3631
  prevKeyRef.current = structuralKey;
3560
- prevDocsRef.current = documents2;
3632
+ prevDocsRef.current = documents3;
3561
3633
  prevSimilarRef.current = similarData;
3562
3634
  const map = /* @__PURE__ */ new Map();
3563
3635
  const getOrCreate = (docId) => {
@@ -3569,18 +3641,18 @@ function useRelatedDocuments(documents2) {
3569
3641
  return entry;
3570
3642
  };
3571
3643
  const docById = /* @__PURE__ */ new Map();
3572
- for (const doc of documents2) {
3644
+ for (const doc of documents3) {
3573
3645
  docById.set(doc.external_id, doc);
3574
3646
  }
3575
3647
  const byHash = /* @__PURE__ */ new Map();
3576
- for (const doc of documents2) {
3648
+ for (const doc of documents3) {
3577
3649
  if (doc.content_hash) {
3578
3650
  const list = byHash.get(doc.content_hash) || [];
3579
3651
  list.push(doc);
3580
3652
  byHash.set(doc.content_hash, list);
3581
3653
  }
3582
3654
  }
3583
- for (const doc of documents2) {
3655
+ for (const doc of documents3) {
3584
3656
  if (doc.parent_ext_id) {
3585
3657
  const parent = docById.get(doc.parent_ext_id);
3586
3658
  if (parent) {
@@ -3589,7 +3661,7 @@ function useRelatedDocuments(documents2) {
3589
3661
  }
3590
3662
  }
3591
3663
  }
3592
- for (const doc of documents2) {
3664
+ for (const doc of documents3) {
3593
3665
  for (const source of doc.derived_from ?? []) {
3594
3666
  const from = docById.get(source.doc_ext_id);
3595
3667
  if (!from) continue;
@@ -3615,7 +3687,7 @@ function useRelatedDocuments(documents2) {
3615
3687
  }
3616
3688
  if (similarData?.pairs) {
3617
3689
  for (const pair of similarData.pairs) {
3618
- if (pair.similarity < chunkPDE246CA_cjs.SIMILARITY_THRESHOLD || pair.similarity >= 1) continue;
3690
+ if (pair.similarity < chunkVO7OWQP6_cjs.SIMILARITY_THRESHOLD || pair.similarity >= 1) continue;
3619
3691
  const docA = docById.get(pair.doc_a.external_id);
3620
3692
  const docB = docById.get(pair.doc_b.external_id);
3621
3693
  if (docA && docB) {
@@ -3632,10 +3704,10 @@ function useRelatedDocuments(documents2) {
3632
3704
  }
3633
3705
  prevMapRef.current = map;
3634
3706
  return map;
3635
- }, [documents2, similarData, structuralKey]);
3707
+ }, [documents3, similarData, structuralKey]);
3636
3708
  }
3637
3709
  var REPLAYABLE = [
3638
- ...chunkPDE246CA_cjs.replayableTagMutations,
3710
+ ...chunkVO7OWQP6_cjs.replayableTagMutations,
3639
3711
  ...replayableDocumentMutations
3640
3712
  ];
3641
3713
  function isReplayableArbiMutation(mutationKey) {
@@ -3649,7 +3721,7 @@ function registerArbiMutationDefaults(queryClient, client) {
3649
3721
  // kept as not sent.
3650
3722
  mutationFn: (variables) => m.run(client(), variables),
3651
3723
  onSuccess: (data, variables) => m.settle(queryClient, data, variables),
3652
- ...chunkPDE246CA_cjs.QUEUED_WRITE_RETRY
3724
+ ...chunkVO7OWQP6_cjs.QUEUED_WRITE_RETRY
3653
3725
  });
3654
3726
  }
3655
3727
  }
@@ -3677,7 +3749,7 @@ function isRestorableArbiQueryOnline(queryKey, data) {
3677
3749
  const docs = Array.isArray(data) ? data : [data];
3678
3750
  return !docs.some((doc) => {
3679
3751
  const status = doc?.status;
3680
- return !!status && !chunkPDE246CA_cjs.FINISHED_DOCUMENT_STATUSES.has(status);
3752
+ return !!status && !chunkVO7OWQP6_cjs.FINISHED_DOCUMENT_STATUSES.has(status);
3681
3753
  });
3682
3754
  }
3683
3755
 
@@ -3776,7 +3848,7 @@ function buildPendingSyncItem(raw, docNameById, tagNameById) {
3776
3848
  status: raw.status,
3777
3849
  at: raw.at,
3778
3850
  docIds,
3779
- ...raw.blocked ? { notice: chunkPDE246CA_cjs.QUEUED_WRITE_BLOCKED_MESSAGE } : {}
3851
+ ...raw.blocked ? { notice: chunkVO7OWQP6_cjs.QUEUED_WRITE_BLOCKED_MESSAGE } : {}
3780
3852
  };
3781
3853
  }
3782
3854
  var PENDING_SYNC_PREDICATE = (m) => (
@@ -3791,10 +3863,10 @@ var PENDING_SYNC_PREDICATE = (m) => (
3791
3863
  // flash "pending/syncing" while fully online. `error` is kept so a failed
3792
3864
  // sync stays visible to review/undo.
3793
3865
  // A write held back because its workspace can't be opened (tried again meanwhile) is waiting too.
3794
- isReplayableArbiMutation(m.options.mutationKey) && (m.state.isPaused || m.state.status === "error" || chunkPDE246CA_cjs.isBlockedOnWorkspace(m))
3866
+ isReplayableArbiMutation(m.options.mutationKey) && (m.state.isPaused || m.state.status === "error" || chunkVO7OWQP6_cjs.isBlockedOnWorkspace(m))
3795
3867
  );
3796
3868
  function usePendingSyncItems() {
3797
- const { data: documents2 } = chunkPDE246CA_cjs.useDocuments();
3869
+ const { data: documents3 } = chunkVO7OWQP6_cjs.useDocuments();
3798
3870
  const { data: tags } = chunkZZZYVNFW_cjs.useTags();
3799
3871
  const raw = reactQuery.useMutationState({
3800
3872
  filters: { predicate: PENDING_SYNC_PREDICATE },
@@ -3803,19 +3875,19 @@ function usePendingSyncItems() {
3803
3875
  kind: kindOf(m.options.mutationKey) ?? "fields",
3804
3876
  variables: m.state.variables,
3805
3877
  context: m.state.context,
3806
- status: statusOf(m.state.isPaused, m.state.status, chunkPDE246CA_cjs.isBlockedOnWorkspace(m)),
3878
+ status: statusOf(m.state.isPaused, m.state.status, chunkVO7OWQP6_cjs.isBlockedOnWorkspace(m)),
3807
3879
  at: m.state.submittedAt,
3808
- blocked: chunkPDE246CA_cjs.isBlockedOnWorkspace(m)
3880
+ blocked: chunkVO7OWQP6_cjs.isBlockedOnWorkspace(m)
3809
3881
  })
3810
3882
  });
3811
3883
  return React.useMemo(() => {
3812
3884
  const docNameById = /* @__PURE__ */ new Map();
3813
- for (const doc of documents2 ?? [])
3885
+ for (const doc of documents3 ?? [])
3814
3886
  docNameById.set(doc.external_id, chunk4NGWDVHD_cjs.getDocumentTitle(doc, doc.file_name ?? ""));
3815
3887
  const tagNameById = /* @__PURE__ */ new Map();
3816
3888
  for (const tag of tags ?? []) tagNameById.set(tag.external_id, tag.name);
3817
3889
  return raw.map((r) => buildPendingSyncItem(r, docNameById, tagNameById));
3818
- }, [raw, documents2, tags]);
3890
+ }, [raw, documents3, tags]);
3819
3891
  }
3820
3892
  function usePendingSyncCounts() {
3821
3893
  const statuses = reactQuery.useMutationState({
@@ -3980,7 +4052,7 @@ function useKeepDocumentsOffline() {
3980
4052
  return reactQuery.useMutation({
3981
4053
  mutationFn: async (docs) => {
3982
4054
  await keepDocumentsOffline(arbi.getClient().fetch, docs);
3983
- for (const doc of docs) chunkPDE246CA_cjs.setCachedDocument(queryClient, doc);
4055
+ for (const doc of docs) chunkVO7OWQP6_cjs.setCachedDocument(queryClient, doc);
3984
4056
  await onKeptOffline?.();
3985
4057
  return docs.length;
3986
4058
  },
@@ -4279,10 +4351,10 @@ function createStreamHandlers(ctx, params) {
4279
4351
  chunkIX4HOS5Z_cjs.recordChatArtifact(artifact, streamState.conversationId);
4280
4352
  host.onArtifact?.(artifact, streamState.conversationId);
4281
4353
  if (artifact.is_complete) {
4282
- const documents2 = session.getState().conversationDocuments[streamState.conversationId] ?? [];
4283
- if (!documents2.some((d) => d.docId === artifact.doc_ext_id))
4354
+ const documents3 = session.getState().conversationDocuments[streamState.conversationId] ?? [];
4355
+ if (!documents3.some((d) => d.docId === artifact.doc_ext_id))
4284
4356
  session.setConversationDocuments(streamState.conversationId, [
4285
- ...documents2,
4357
+ ...documents3,
4286
4358
  { docId: artifact.doc_ext_id, isPinned: false }
4287
4359
  ]);
4288
4360
  if (artifact.mode === "html" || artifact.mode === "react")
@@ -4373,7 +4445,7 @@ function useStreamHandlers() {
4373
4445
  return "";
4374
4446
  }
4375
4447
  },
4376
- refreshDocuments: (ids2) => chunkPDE246CA_cjs.refreshDocuments(queryClient, arbi, ids2)
4448
+ refreshDocuments: (ids2) => chunkVO7OWQP6_cjs.refreshDocuments(queryClient, arbi, ids2)
4377
4449
  },
4378
4450
  params
4379
4451
  ),
@@ -4630,7 +4702,7 @@ function useConversationActions({
4630
4702
  conversationId: convId,
4631
4703
  workspaceId: turnWorkspaceId
4632
4704
  });
4633
- const flushing = chunkPDE246CA_cjs.flushDocumentForTurn(activeArtifactExtId);
4705
+ const flushing = chunkVO7OWQP6_cjs.flushDocumentForTurn(activeArtifactExtId);
4634
4706
  if (flushing) await flushing;
4635
4707
  const pendingTools = state.pendingTools;
4636
4708
  if (pendingTools) session.setPendingTools(null);
@@ -5116,9 +5188,9 @@ function useConversationData() {
5116
5188
  selectThread(session, firstThreadId);
5117
5189
  const history = defaultThread?.history || [];
5118
5190
  const key = session.getState().conversationId || "new";
5119
- const documents2 = browser.extractDocumentIdsFromMessages(history);
5120
- if (documents2.length > 0 && session.getState().conversationDocuments[key] === void 0)
5121
- session.setConversationDocuments(key, documents2);
5191
+ const documents3 = browser.extractDocumentIdsFromMessages(history);
5192
+ if (documents3.length > 0 && session.getState().conversationDocuments[key] === void 0)
5193
+ session.setConversationDocuments(key, documents3);
5122
5194
  const factIds = browser.extractFactIdsFromMessages(history);
5123
5195
  if (factIds && factIds.length > 0) session.setConversationFacts(key, factIds);
5124
5196
  }
@@ -5543,7 +5615,7 @@ function useConversation(options = {}) {
5543
5615
  React.useEffect(() => {
5544
5616
  if (agentId && workspaceId && !conversationId) session.setNewAgentChat({ agentId, workspaceId });
5545
5617
  }, [session, agentId, workspaceId, conversationId]);
5546
- const { data: docs = [], isLoading: isLoadingDocuments } = chunkPDE246CA_cjs.useDocuments(workspaceId);
5618
+ const { data: docs = [], isLoading: isLoadingDocuments } = chunkVO7OWQP6_cjs.useDocuments(workspaceId);
5547
5619
  const ordinaryHistory = chunkZZZYVNFW_cjs.useConversations(workspaceId, { enabled: !agentId, live: true });
5548
5620
  const agentHistory = useAgentChats(agentId);
5549
5621
  const stored = React.useMemo(
@@ -5634,7 +5706,7 @@ function useConversation(options = {}) {
5634
5706
  () => (agentId ? [] : docs).map((d) => d.external_id).filter((id) => !!id && !deselected.has(id)),
5635
5707
  [docs, deselected, agentId]
5636
5708
  );
5637
- const documents2 = React.useMemo(
5709
+ const documents3 = React.useMemo(
5638
5710
  () => agentId ? stagedFiles.map((file) => ({ ...file, isSelected: !deselected.has(file.id) })) : docs.filter((d) => !!d.external_id).map((d) => ({
5639
5711
  id: d.external_id,
5640
5712
  name: d.file_name ?? d.external_id,
@@ -5821,7 +5893,7 @@ function useConversation(options = {}) {
5821
5893
  uploaded.push(...result.doc_ext_ids ?? []);
5822
5894
  }
5823
5895
  }
5824
- if (uploaded.length) await chunkPDE246CA_cjs.refreshDocuments(queryClient, arbi, uploaded);
5896
+ if (uploaded.length) await chunkVO7OWQP6_cjs.refreshDocuments(queryClient, arbi, uploaded);
5825
5897
  } catch (e) {
5826
5898
  setUploadError(messageOf(e, "The upload failed."));
5827
5899
  } finally {
@@ -5846,7 +5918,7 @@ function useConversation(options = {}) {
5846
5918
  isLoadingThread: !!conversationId && threadsLoading && !threadsError,
5847
5919
  isLoadingThreads,
5848
5920
  historyError: historyError ?? (threadsError ? messageOf(threadsError, "The conversation could not be loaded.") : null),
5849
- documents: documents2,
5921
+ documents: documents3,
5850
5922
  isLoadingDocuments,
5851
5923
  isUploading,
5852
5924
  uploadError,
@@ -6056,12 +6128,12 @@ function useConversationDocuments() {
6056
6128
  const inConversationDocuments = chunkZZZYVNFW_cjs.useArbiSessionState(
6057
6129
  (state) => state.conversationDocuments[convKey] || EMPTY_DOCS
6058
6130
  );
6059
- const { data: documents2 = [], isLoading: isLoadingDocs } = chunkPDE246CA_cjs.useDocuments();
6131
+ const { data: documents3 = [], isLoading: isLoadingDocs } = chunkVO7OWQP6_cjs.useDocuments();
6060
6132
  const conversationDocuments = React__default.default.useMemo(() => {
6061
6133
  if (inConversationDocuments.length === 0) {
6062
6134
  return [];
6063
6135
  }
6064
- const docArray = Array.isArray(documents2) ? documents2 : [];
6136
+ const docArray = Array.isArray(documents3) ? documents3 : [];
6065
6137
  const conversationDocMap = new Map(
6066
6138
  inConversationDocuments.map((doc) => [doc.docId, doc.isPinned])
6067
6139
  );
@@ -6076,7 +6148,7 @@ function useConversationDocuments() {
6076
6148
  return conversationDocMap.has(docId);
6077
6149
  });
6078
6150
  return filteredDocs;
6079
- }, [documents2, inConversationDocuments]);
6151
+ }, [documents3, inConversationDocuments]);
6080
6152
  return {
6081
6153
  data: conversationDocuments,
6082
6154
  isLoading: isLoadingDocs,
@@ -6801,7 +6873,7 @@ function computeOnline(wsStatus, isAuthenticated, workOffline, wsEverConnected)
6801
6873
  }
6802
6874
  function useOnlineSync() {
6803
6875
  const session = chunkZZZYVNFW_cjs.useArbiSessionStore();
6804
- const wsStatus = chunkPDE246CA_cjs.useArbiWsStore((s) => s.status);
6876
+ const wsStatus = chunkVO7OWQP6_cjs.useArbiWsStore((s) => s.status);
6805
6877
  const signedIn2 = chunkZZZYVNFW_cjs.useArbiSession().status === "signed-in";
6806
6878
  const [workOffline] = useWorkOffline();
6807
6879
  const wsEverConnected = React.useRef(false);
@@ -6814,7 +6886,7 @@ function useOnlineSync() {
6814
6886
  React.useEffect(() => {
6815
6887
  const update2 = () => reactQuery.onlineManager.setOnline(
6816
6888
  computeOnline(
6817
- chunkPDE246CA_cjs.useArbiWsStore.getState().status,
6889
+ chunkVO7OWQP6_cjs.useArbiWsStore.getState().status,
6818
6890
  signedInRef.current,
6819
6891
  isWorkingOffline(session),
6820
6892
  wsEverConnected.current
@@ -7420,7 +7492,7 @@ async function applyMailChangesOnce(sender, isOnline) {
7420
7492
  var NO_PRIMER = () => void 0;
7421
7493
  async function sendMailFile(fetch2, prime, account, messageId, request) {
7422
7494
  const { threadId } = request;
7423
- return chunkPDE246CA_cjs.inWorkspace(prime, request.workspaceExtId, async () => {
7495
+ return chunkVO7OWQP6_cjs.inWorkspace(prime, request.workspaceExtId, async () => {
7424
7496
  if (!threadId) return browser.mail.fileMessage(fetch2, messageId, request.workspaceExtId, account.id);
7425
7497
  const { filed } = await browser.mail.fileConversation(fetch2, {
7426
7498
  accountId: account.id,
@@ -7433,7 +7505,7 @@ async function sendMailFile(fetch2, prime, account, messageId, request) {
7433
7505
  }
7434
7506
  function useMailWorkspacePrimer() {
7435
7507
  const { arbi } = chunkFE6ZSNZE_cjs.useArbiHost();
7436
- return arbi ? chunkPDE246CA_cjs.primeOnArbi(arbi) : NO_PRIMER;
7508
+ return arbi ? chunkVO7OWQP6_cjs.primeOnArbi(arbi) : NO_PRIMER;
7437
7509
  }
7438
7510
  function useMailFiling(account, messageIds, threadIds, options = {}) {
7439
7511
  const { client } = useMailClient();
@@ -7467,7 +7539,7 @@ function useSetNativeMailFiling() {
7467
7539
  const prime = useMailWorkspacePrimer();
7468
7540
  const queryClient = reactQuery.useQueryClient();
7469
7541
  return reactQuery.useMutation({
7470
- mutationFn: (input) => chunkPDE246CA_cjs.inWorkspace(prime, input.workspaceExtId, () => browser.mail.setNativeFiling(client.fetch, input)),
7542
+ mutationFn: (input) => chunkVO7OWQP6_cjs.inWorkspace(prime, input.workspaceExtId, () => browser.mail.setNativeFiling(client.fetch, input)),
7471
7543
  onSuccess: () => queryClient.invalidateQueries({ queryKey: chunkFE6ZSNZE_cjs.mailQueryKeys.allFiling() })
7472
7544
  });
7473
7545
  }
@@ -8051,7 +8123,7 @@ function liveChangeSender(arbi) {
8051
8123
  const { kind: _, ...request } = change;
8052
8124
  await sendMailFile(
8053
8125
  (p, i) => arbi.mail.fetch(p, i),
8054
- chunkPDE246CA_cjs.primeOnArbi(arbi),
8126
+ chunkVO7OWQP6_cjs.primeOnArbi(arbi),
8055
8127
  account,
8056
8128
  messageId,
8057
8129
  request
@@ -8740,7 +8812,7 @@ function applyRunFinished(queryClient, arbi, session, message, onQuotaExceeded)
8740
8812
  if (!conversationId) return;
8741
8813
  session.setConversationGenerating(conversationId, false, null);
8742
8814
  if (message.doc_ext_ids?.length) {
8743
- chunkPDE246CA_cjs.refreshDocuments(queryClient, arbi, message.doc_ext_ids).catch(
8815
+ chunkVO7OWQP6_cjs.refreshDocuments(queryClient, arbi, message.doc_ext_ids).catch(
8744
8816
  (error) => client.logger.error("[WebSocket] Failed to refresh task outputs:", error)
8745
8817
  );
8746
8818
  }
@@ -8787,6 +8859,7 @@ function signedInId(arbi) {
8787
8859
  return arbi.isLoggedIn ? arbi.user.identity()?.externalId ?? null : null;
8788
8860
  }
8789
8861
  var EVICTED_CLOSE_CODE = 1008;
8862
+ var TASK_UPDATE_FLUSH_MS = 250;
8790
8863
  function ArbiWebSocketProvider({
8791
8864
  enabled = true,
8792
8865
  onAuthenticated,
@@ -8798,11 +8871,11 @@ function ArbiWebSocketProvider({
8798
8871
  arbiRef.current = arbi;
8799
8872
  const queryClient = reactQuery.useQueryClient();
8800
8873
  const subscribersRef = React.useRef(/* @__PURE__ */ new Set());
8801
- const setStatus = chunkPDE246CA_cjs.useArbiWsStore((s) => s.setStatus);
8802
- const applyTaskUpdate = chunkPDE246CA_cjs.useArbiWsStore((s) => s.applyTaskUpdate);
8803
- const applyPresence = chunkPDE246CA_cjs.useArbiWsStore((s) => s.applyPresence);
8804
- const reset = chunkPDE246CA_cjs.useArbiWsStore((s) => s.reset);
8805
- const setEvicted = chunkPDE246CA_cjs.useArbiWsStore((s) => s.setEvicted);
8874
+ const setStatus = chunkVO7OWQP6_cjs.useArbiWsStore((s) => s.setStatus);
8875
+ const applyTaskUpdates = chunkVO7OWQP6_cjs.useArbiWsStore((s) => s.applyTaskUpdates);
8876
+ const applyPresence = chunkVO7OWQP6_cjs.useArbiWsStore((s) => s.applyPresence);
8877
+ const reset = chunkVO7OWQP6_cjs.useArbiWsStore((s) => s.reset);
8878
+ const setEvicted = chunkVO7OWQP6_cjs.useArbiWsStore((s) => s.setEvicted);
8806
8879
  const onAuthenticatedRef = React.useRef(onAuthenticated);
8807
8880
  onAuthenticatedRef.current = onAuthenticated;
8808
8881
  const handlersRef = React.useRef(handlers);
@@ -8837,13 +8910,43 @@ function ArbiWebSocketProvider({
8837
8910
  let cancelled = false;
8838
8911
  let evicted = false;
8839
8912
  const me = () => signedInId(arbiRef.current);
8913
+ const deliver = (msg) => {
8914
+ const type = msg.type;
8915
+ try {
8916
+ handlersRef.current?.[type]?.(msg);
8917
+ } catch (error) {
8918
+ client.logger.error(`[WebSocket] The host's ${type} handler failed:`, error);
8919
+ }
8920
+ for (const fn of subscribersRef.current) {
8921
+ try {
8922
+ fn(msg);
8923
+ } catch {
8924
+ }
8925
+ }
8926
+ };
8927
+ let taskBuffer = [];
8928
+ let taskTimer = null;
8929
+ const flushTasks = () => {
8930
+ if (taskTimer) clearTimeout(taskTimer);
8931
+ taskTimer = null;
8932
+ if (!taskBuffer.length) return;
8933
+ const batch = taskBuffer;
8934
+ taskBuffer = [];
8935
+ const taken = applyTaskUpdates(batch);
8936
+ if (taken.length) applyTaskEvents(queryClient, arbiRef.current, taken, me());
8937
+ for (const msg of batch) deliver(msg);
8938
+ };
8840
8939
  const onMessage = (msg) => {
8841
8940
  const type = msg.type;
8941
+ if (client.isMessageType(msg, "task_update")) {
8942
+ taskBuffer.push(msg);
8943
+ taskTimer ??= setTimeout(flushTasks, TASK_UPDATE_FLUSH_MS);
8944
+ return;
8945
+ }
8946
+ flushTasks();
8842
8947
  if (type === "connection_closed") {
8843
8948
  evicted = true;
8844
8949
  setEvicted(true);
8845
- } else if (client.isMessageType(msg, "task_update")) {
8846
- if (applyTaskUpdate(msg)) applyTaskEvent(queryClient, arbiRef.current, msg, me());
8847
8950
  } else if (client.isMessageType(msg, "presence_update")) applyPresence(msg);
8848
8951
  else if (client.isMessageType(msg, "response_complete"))
8849
8952
  applyRunFinished(
@@ -8857,12 +8960,12 @@ function ArbiWebSocketProvider({
8857
8960
  client.logger.error("[WebSocket] Server error:", msg.message);
8858
8961
  else if (client.isMessageType(msg, "batch_complete")) {
8859
8962
  if (msg.batch_type === "entity_extract") {
8860
- chunkPDE246CA_cjs.finishEntityExtraction(msg.doc_ext_ids ?? []);
8963
+ chunkVO7OWQP6_cjs.finishEntityExtraction(msg.doc_ext_ids ?? []);
8861
8964
  void queryClient.invalidateQueries({ queryKey: chunkFE6ZSNZE_cjs.arbiQueryKeys.allFacts() });
8862
8965
  }
8863
8966
  if (msg.batch_type === "upload" || msg.batch_type === "entity_extract") {
8864
8967
  if (msg.doc_ext_ids?.length)
8865
- void chunkPDE246CA_cjs.refreshDocuments(queryClient, arbiRef.current, msg.doc_ext_ids);
8968
+ chunkVO7OWQP6_cjs.queueDocumentReads(queryClient, arbiRef.current, msg.doc_ext_ids);
8866
8969
  void queryClient.invalidateQueries({ queryKey: chunkFE6ZSNZE_cjs.arbiQueryKeys.allTags() });
8867
8970
  }
8868
8971
  } else if (type.startsWith("chat.") || type === "agent_dm_status")
@@ -8871,17 +8974,7 @@ function ArbiWebSocketProvider({
8871
8974
  chunk26SZ3DS4_cjs.applyCallEvent(queryClient, msg, { me: me(), acceptRings: acceptRingsRef.current });
8872
8975
  else if (isNotificationRow(msg)) applyNotificationRow(queryClient, msg, me());
8873
8976
  else void applyLiveUpdate(queryClient, msg);
8874
- try {
8875
- handlersRef.current?.[type]?.(msg);
8876
- } catch (error) {
8877
- client.logger.error(`[WebSocket] The host's ${type} handler failed:`, error);
8878
- }
8879
- for (const fn of subscribersRef.current) {
8880
- try {
8881
- fn(msg);
8882
- } catch {
8883
- }
8884
- }
8977
+ deliver(msg);
8885
8978
  };
8886
8979
  let retryTimer2 = null;
8887
8980
  let attempt3 = 0;
@@ -8954,11 +9047,12 @@ function ArbiWebSocketProvider({
8954
9047
  void start();
8955
9048
  return () => {
8956
9049
  cancelled = true;
9050
+ if (taskTimer) clearTimeout(taskTimer);
8957
9051
  if (retryTimer2) clearTimeout(retryTimer2);
8958
9052
  conn?.close();
8959
9053
  reset();
8960
9054
  };
8961
- }, [enabled, queryClient, setStatus, setEvicted, applyTaskUpdate, applyPresence, reset]);
9055
+ }, [enabled, queryClient, setStatus, setEvicted, applyTaskUpdates, applyPresence, reset]);
8962
9056
  return /* @__PURE__ */ jsxRuntime.jsx(ArbiWsContext.Provider, { value: context, children });
8963
9057
  }
8964
9058
  function useArbiWebSocket(onMessage) {
@@ -8979,7 +9073,7 @@ function useArbiWsMessage(type, handler) {
8979
9073
  );
8980
9074
  }
8981
9075
  function useArbiWsStatus() {
8982
- return chunkPDE246CA_cjs.useArbiWsStore((s) => s.status);
9076
+ return chunkVO7OWQP6_cjs.useArbiWsStore((s) => s.status);
8983
9077
  }
8984
9078
 
8985
9079
  // src/workspaces/shell-workspaces.ts
@@ -9550,7 +9644,7 @@ function useWorkspaceExportDownload({
9550
9644
  const arbi = chunkFE6ZSNZE_cjs.useArbi();
9551
9645
  const [progress, setProgress] = React.useState(null);
9552
9646
  const download = React.useCallback(
9553
- async ({ scope, documents: documents2 = [], csvColumns }) => {
9647
+ async ({ scope, documents: documents3 = [], csvColumns }) => {
9554
9648
  setProgress({ done: 0, total: 0 });
9555
9649
  try {
9556
9650
  const data = await arbi.workspaces.transfer.exportData(
@@ -9562,7 +9656,7 @@ function useWorkspaceExportDownload({
9562
9656
  const exported = new Set(
9563
9657
  (data.files ?? []).filter((f) => !f.markup).map((f) => f.doc_ext_id)
9564
9658
  );
9565
- const rows = documents2.filter((d) => exported.has(d.external_id));
9659
+ const rows = documents3.filter((d) => exported.has(d.external_id));
9566
9660
  if (rows.length > 0) {
9567
9661
  const Papa = (await import('papaparse')).default;
9568
9662
  metadataCsv = Papa.unparse(buildDocumentMetadataRows(rows, csvColumns));
@@ -10795,7 +10889,7 @@ function createDocumentsSource(labels) {
10795
10889
  description: l.description,
10796
10890
  useFields: staticFields(fields),
10797
10891
  useRows(params, enabled) {
10798
- const query = chunkPDE246CA_cjs.useDocuments(workspaceOf2(params), { enabled });
10892
+ const query = chunkVO7OWQP6_cjs.useDocuments(workspaceOf2(params), { enabled });
10799
10893
  const nameOf = useNames(enabled);
10800
10894
  const rows = React.useMemo(
10801
10895
  () => query.data?.map((d) => ({
@@ -11593,9 +11687,16 @@ var IDB_KEY = "arbi-react-query-cache";
11593
11687
  var OWNER_KEY = "arbi-react-query-cache-owner";
11594
11688
  var CACHE_BUSTER = "arbi-rq-v2";
11595
11689
  var MAX_AGE = 1e3 * 60 * 60 * 24 * 7;
11690
+ var PERSIST_THROTTLE_MS = 1e3;
11596
11691
  function createIDBPersister() {
11692
+ const write3 = throttle((client) => {
11693
+ void withStorage(() => idbKeyval.set(IDB_KEY, client));
11694
+ }, PERSIST_THROTTLE_MS);
11695
+ if (typeof window !== "undefined") window.addEventListener("pagehide", () => write3.flush());
11597
11696
  return {
11598
- persistClient: (client) => withStorage(() => idbKeyval.set(IDB_KEY, client)),
11697
+ persistClient: async (client) => {
11698
+ write3(client);
11699
+ },
11599
11700
  // The offline persister must be INERT when online. Because the documents
11600
11701
  // list never auto-refetches, a rehydrated copy would be trusted
11601
11702
  // indefinitely and surface stale statuses across a reload — e.g. a document
@@ -11617,7 +11718,10 @@ function createIDBPersister() {
11617
11718
  );
11618
11719
  return persisted;
11619
11720
  },
11620
- removeClient: () => withStorage(() => idbKeyval.del(IDB_KEY))
11721
+ removeClient: () => {
11722
+ write3.cancel();
11723
+ return withStorage(() => idbKeyval.del(IDB_KEY));
11724
+ }
11621
11725
  };
11622
11726
  }
11623
11727
  async function claimOfflineQueue(userExtId) {
@@ -14636,7 +14740,7 @@ function useCalendarOfflineRuntime() {
14636
14740
  }, [ready, arbi, queryClient]);
14637
14741
  }
14638
14742
  function useWorkspaceDocs(workspaceId) {
14639
- const { data: docs = [], isLoading, isError } = chunkPDE246CA_cjs.useDocuments(workspaceId);
14743
+ const { data: docs = [], isLoading, isError } = chunkVO7OWQP6_cjs.useDocuments(workspaceId);
14640
14744
  const docIds = React.useMemo(
14641
14745
  () => docs.map((d) => d.external_id).filter((id) => !!id),
14642
14746
  [docs]
@@ -15890,6 +15994,35 @@ function parse(content) {
15890
15994
  return null;
15891
15995
  }
15892
15996
  }
15997
+ function uploadSetMeta(content) {
15998
+ const meta = parse(content) ?? {};
15999
+ const count = (key) => {
16000
+ const value = meta[key];
16001
+ return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : 0;
16002
+ };
16003
+ const ids2 = Array.isArray(meta.failed_doc_ext_ids) ? meta.failed_doc_ext_ids : [];
16004
+ return {
16005
+ total: count("total"),
16006
+ completed: count("completed"),
16007
+ failed: count("failed"),
16008
+ failedDocumentIds: ids2.filter(
16009
+ (id) => typeof id === "string" && DOCUMENT_ID.test(id)
16010
+ ),
16011
+ refused: count("refused"),
16012
+ notUploaded: count("not_uploaded")
16013
+ };
16014
+ }
16015
+ var documents2 = (n) => `${n} document${n === 1 ? "" : "s"}`;
16016
+ function uploadSetTitle(content) {
16017
+ const { total, completed, failed, refused, notUploaded } = uploadSetMeta(content);
16018
+ const parts = [
16019
+ completed === total || total === 0 ? `${documents2(completed)} indexed` : `${completed} of ${documents2(total)} indexed`
16020
+ ];
16021
+ if (failed) parts.push(`${failed} failed`);
16022
+ if (refused) parts.push(`${refused} skipped`);
16023
+ if (notUploaded) parts.push(`${notUploaded} not uploaded`);
16024
+ return parts.join(" \xB7 ");
16025
+ }
15893
16026
  function inputRequestTitle(content) {
15894
16027
  const metadata = parse(content);
15895
16028
  if (!metadata) return "ARBI needs your input \u2014 open the thread to reply";
@@ -16078,6 +16211,25 @@ function describeServerNotification(n, options = {}) {
16078
16211
  target: { kind: "url", url: `/shared-files/${id}` }
16079
16212
  };
16080
16213
  }
16214
+ // One upload action finished (however many batches it was sent and processed in). A failed
16215
+ // document is where it leads when there is one; otherwise the workspace.
16216
+ case "upload_set_complete": {
16217
+ const meta = uploadSetMeta(n.content);
16218
+ const problems = meta.failed + meta.notUploaded;
16219
+ const failed = meta.failedDocumentIds;
16220
+ return {
16221
+ title: uploadSetTitle(n.content),
16222
+ variant: problems ? "warning" : "success",
16223
+ ...failed.length === 1 ? {
16224
+ actionLabel: "Open failed document",
16225
+ target: {
16226
+ kind: "document",
16227
+ workspaceId: n.workspace_ext_id ?? void 0,
16228
+ documentId: failed[0]
16229
+ }
16230
+ } : { target: workspace }
16231
+ };
16232
+ }
16081
16233
  case "call_missed":
16082
16234
  return {
16083
16235
  title: `Missed call from ${senderName}`,
@@ -16415,7 +16567,7 @@ function isAgentUser(user) {
16415
16567
  return user.external_id.startsWith("agt-");
16416
16568
  }
16417
16569
  function DmAvatar({ user, className, size = "lg" }) {
16418
- const presence = chunkPDE246CA_cjs.useArbiWsStore((s) => s.presence[user.external_id]);
16570
+ const presence = chunkVO7OWQP6_cjs.useArbiWsStore((s) => s.presence[user.external_id]);
16419
16571
  const displayStatus = presence === void 0 ? void 0 : presence === "online" ? "connected" : "disconnected";
16420
16572
  return /* @__PURE__ */ jsxRuntime.jsx(
16421
16573
  chunk4NGWDVHD_cjs.UserEntity,
@@ -18087,187 +18239,187 @@ Object.defineProperty(exports, "writeSamples", {
18087
18239
  });
18088
18240
  Object.defineProperty(exports, "DISMISSED_TASK_TTL_MS", {
18089
18241
  enumerable: true,
18090
- get: function () { return chunkPDE246CA_cjs.DISMISSED_TASK_TTL_MS; }
18242
+ get: function () { return chunkVO7OWQP6_cjs.DISMISSED_TASK_TTL_MS; }
18091
18243
  });
18092
18244
  Object.defineProperty(exports, "DOCUMENTS_FIRST_PAGE_MEASURE", {
18093
18245
  enumerable: true,
18094
- get: function () { return chunkPDE246CA_cjs.DOCUMENTS_FIRST_PAGE_MEASURE; }
18246
+ get: function () { return chunkVO7OWQP6_cjs.DOCUMENTS_FIRST_PAGE_MEASURE; }
18095
18247
  });
18096
18248
  Object.defineProperty(exports, "DOCUMENTS_FIRST_PAGE_SIZE", {
18097
18249
  enumerable: true,
18098
- get: function () { return chunkPDE246CA_cjs.DOCUMENTS_FIRST_PAGE_SIZE; }
18250
+ get: function () { return chunkVO7OWQP6_cjs.DOCUMENTS_FIRST_PAGE_SIZE; }
18099
18251
  });
18100
18252
  Object.defineProperty(exports, "DOCUMENTS_PAGE_SIZE", {
18101
18253
  enumerable: true,
18102
- get: function () { return chunkPDE246CA_cjs.DOCUMENTS_PAGE_SIZE; }
18254
+ get: function () { return chunkVO7OWQP6_cjs.DOCUMENTS_PAGE_SIZE; }
18103
18255
  });
18104
18256
  Object.defineProperty(exports, "FINISHED_DOCUMENT_STATUSES", {
18105
18257
  enumerable: true,
18106
- get: function () { return chunkPDE246CA_cjs.FINISHED_DOCUMENT_STATUSES; }
18258
+ get: function () { return chunkVO7OWQP6_cjs.FINISHED_DOCUMENT_STATUSES; }
18107
18259
  });
18108
18260
  Object.defineProperty(exports, "IN_FLIGHT_DOCUMENT_STATUSES", {
18109
18261
  enumerable: true,
18110
- get: function () { return chunkPDE246CA_cjs.IN_FLIGHT_DOCUMENT_STATUSES; }
18262
+ get: function () { return chunkVO7OWQP6_cjs.IN_FLIGHT_DOCUMENT_STATUSES; }
18111
18263
  });
18112
18264
  Object.defineProperty(exports, "SIMILARITY_THRESHOLD", {
18113
18265
  enumerable: true,
18114
- get: function () { return chunkPDE246CA_cjs.SIMILARITY_THRESHOLD; }
18266
+ get: function () { return chunkVO7OWQP6_cjs.SIMILARITY_THRESHOLD; }
18115
18267
  });
18116
18268
  Object.defineProperty(exports, "adjustTagCounts", {
18117
18269
  enumerable: true,
18118
- get: function () { return chunkPDE246CA_cjs.adjustTagCounts; }
18270
+ get: function () { return chunkVO7OWQP6_cjs.adjustTagCounts; }
18119
18271
  });
18120
18272
  Object.defineProperty(exports, "dropTagFromCachedDocuments", {
18121
18273
  enumerable: true,
18122
- get: function () { return chunkPDE246CA_cjs.dropTagFromCachedDocuments; }
18274
+ get: function () { return chunkVO7OWQP6_cjs.dropTagFromCachedDocuments; }
18123
18275
  });
18124
18276
  Object.defineProperty(exports, "finishEntityExtraction", {
18125
18277
  enumerable: true,
18126
- get: function () { return chunkPDE246CA_cjs.finishEntityExtraction; }
18278
+ get: function () { return chunkVO7OWQP6_cjs.finishEntityExtraction; }
18127
18279
  });
18128
18280
  Object.defineProperty(exports, "flushDocumentForTurn", {
18129
18281
  enumerable: true,
18130
- get: function () { return chunkPDE246CA_cjs.flushDocumentForTurn; }
18282
+ get: function () { return chunkVO7OWQP6_cjs.flushDocumentForTurn; }
18131
18283
  });
18132
18284
  Object.defineProperty(exports, "forgetDocuments", {
18133
18285
  enumerable: true,
18134
- get: function () { return chunkPDE246CA_cjs.forgetDocuments; }
18286
+ get: function () { return chunkVO7OWQP6_cjs.forgetDocuments; }
18135
18287
  });
18136
18288
  Object.defineProperty(exports, "getCachedDocuments", {
18137
18289
  enumerable: true,
18138
- get: function () { return chunkPDE246CA_cjs.getCachedDocuments; }
18290
+ get: function () { return chunkVO7OWQP6_cjs.getCachedDocuments; }
18139
18291
  });
18140
18292
  Object.defineProperty(exports, "invalidateTagData", {
18141
18293
  enumerable: true,
18142
- get: function () { return chunkPDE246CA_cjs.invalidateTagData; }
18294
+ get: function () { return chunkVO7OWQP6_cjs.invalidateTagData; }
18143
18295
  });
18144
18296
  Object.defineProperty(exports, "invalidateTagTables", {
18145
18297
  enumerable: true,
18146
- get: function () { return chunkPDE246CA_cjs.invalidateTagTables; }
18298
+ get: function () { return chunkVO7OWQP6_cjs.invalidateTagTables; }
18147
18299
  });
18148
18300
  Object.defineProperty(exports, "isDocumentsLoading", {
18149
18301
  enumerable: true,
18150
- get: function () { return chunkPDE246CA_cjs.isDocumentsLoading; }
18302
+ get: function () { return chunkVO7OWQP6_cjs.isDocumentsLoading; }
18151
18303
  });
18152
18304
  Object.defineProperty(exports, "isRowNewer", {
18153
18305
  enumerable: true,
18154
- get: function () { return chunkPDE246CA_cjs.isRowNewer; }
18306
+ get: function () { return chunkVO7OWQP6_cjs.isRowNewer; }
18155
18307
  });
18156
18308
  Object.defineProperty(exports, "isStaleTaskUpdate", {
18157
18309
  enumerable: true,
18158
- get: function () { return chunkPDE246CA_cjs.isStaleTaskUpdate; }
18310
+ get: function () { return chunkVO7OWQP6_cjs.isStaleTaskUpdate; }
18159
18311
  });
18160
18312
  Object.defineProperty(exports, "patchCachedDocument", {
18161
18313
  enumerable: true,
18162
- get: function () { return chunkPDE246CA_cjs.patchCachedDocument; }
18314
+ get: function () { return chunkVO7OWQP6_cjs.patchCachedDocument; }
18163
18315
  });
18164
18316
  Object.defineProperty(exports, "patchDocuments", {
18165
18317
  enumerable: true,
18166
- get: function () { return chunkPDE246CA_cjs.patchDocuments; }
18318
+ get: function () { return chunkVO7OWQP6_cjs.patchDocuments; }
18167
18319
  });
18168
18320
  Object.defineProperty(exports, "patchWorkspaceTags", {
18169
18321
  enumerable: true,
18170
- get: function () { return chunkPDE246CA_cjs.patchWorkspaceTags; }
18322
+ get: function () { return chunkVO7OWQP6_cjs.patchWorkspaceTags; }
18171
18323
  });
18172
18324
  Object.defineProperty(exports, "refreshDocuments", {
18173
18325
  enumerable: true,
18174
- get: function () { return chunkPDE246CA_cjs.refreshDocuments; }
18326
+ get: function () { return chunkVO7OWQP6_cjs.refreshDocuments; }
18175
18327
  });
18176
18328
  Object.defineProperty(exports, "registerDocumentTurnFlush", {
18177
18329
  enumerable: true,
18178
- get: function () { return chunkPDE246CA_cjs.registerDocumentTurnFlush; }
18330
+ get: function () { return chunkVO7OWQP6_cjs.registerDocumentTurnFlush; }
18179
18331
  });
18180
18332
  Object.defineProperty(exports, "resolveDocumentStatus", {
18181
18333
  enumerable: true,
18182
- get: function () { return chunkPDE246CA_cjs.resolveDocumentStatus; }
18334
+ get: function () { return chunkVO7OWQP6_cjs.resolveDocumentStatus; }
18183
18335
  });
18184
18336
  Object.defineProperty(exports, "setCachedDocument", {
18185
18337
  enumerable: true,
18186
- get: function () { return chunkPDE246CA_cjs.setCachedDocument; }
18338
+ get: function () { return chunkVO7OWQP6_cjs.setCachedDocument; }
18187
18339
  });
18188
18340
  Object.defineProperty(exports, "settledByRows", {
18189
18341
  enumerable: true,
18190
- get: function () { return chunkPDE246CA_cjs.settledByRows; }
18342
+ get: function () { return chunkVO7OWQP6_cjs.settledByRows; }
18191
18343
  });
18192
18344
  Object.defineProperty(exports, "startEntityExtraction", {
18193
18345
  enumerable: true,
18194
- get: function () { return chunkPDE246CA_cjs.startEntityExtraction; }
18346
+ get: function () { return chunkVO7OWQP6_cjs.startEntityExtraction; }
18195
18347
  });
18196
18348
  Object.defineProperty(exports, "stopDocumentsLoading", {
18197
18349
  enumerable: true,
18198
- get: function () { return chunkPDE246CA_cjs.stopDocumentsLoading; }
18350
+ get: function () { return chunkVO7OWQP6_cjs.stopDocumentsLoading; }
18199
18351
  });
18200
18352
  Object.defineProperty(exports, "subscribeDocumentRows", {
18201
18353
  enumerable: true,
18202
- get: function () { return chunkPDE246CA_cjs.subscribeDocumentRows; }
18354
+ get: function () { return chunkVO7OWQP6_cjs.subscribeDocumentRows; }
18203
18355
  });
18204
18356
  Object.defineProperty(exports, "upsertDocuments", {
18205
18357
  enumerable: true,
18206
- get: function () { return chunkPDE246CA_cjs.upsertDocuments; }
18358
+ get: function () { return chunkVO7OWQP6_cjs.upsertDocuments; }
18207
18359
  });
18208
18360
  Object.defineProperty(exports, "useArbiWsStore", {
18209
18361
  enumerable: true,
18210
- get: function () { return chunkPDE246CA_cjs.useArbiWsStore; }
18362
+ get: function () { return chunkVO7OWQP6_cjs.useArbiWsStore; }
18211
18363
  });
18212
18364
  Object.defineProperty(exports, "useCreateTag", {
18213
18365
  enumerable: true,
18214
- get: function () { return chunkPDE246CA_cjs.useCreateTag; }
18366
+ get: function () { return chunkVO7OWQP6_cjs.useCreateTag; }
18215
18367
  });
18216
18368
  Object.defineProperty(exports, "useDeleteTag", {
18217
18369
  enumerable: true,
18218
- get: function () { return chunkPDE246CA_cjs.useDeleteTag; }
18370
+ get: function () { return chunkVO7OWQP6_cjs.useDeleteTag; }
18219
18371
  });
18220
18372
  Object.defineProperty(exports, "useDocument", {
18221
18373
  enumerable: true,
18222
- get: function () { return chunkPDE246CA_cjs.useDocument; }
18374
+ get: function () { return chunkVO7OWQP6_cjs.useDocument; }
18223
18375
  });
18224
18376
  Object.defineProperty(exports, "useDocuments", {
18225
18377
  enumerable: true,
18226
- get: function () { return chunkPDE246CA_cjs.useDocuments; }
18378
+ get: function () { return chunkVO7OWQP6_cjs.useDocuments; }
18227
18379
  });
18228
18380
  Object.defineProperty(exports, "useDocumentsLoading", {
18229
18381
  enumerable: true,
18230
- get: function () { return chunkPDE246CA_cjs.useDocumentsLoading; }
18382
+ get: function () { return chunkVO7OWQP6_cjs.useDocumentsLoading; }
18231
18383
  });
18232
18384
  Object.defineProperty(exports, "useEntityExtractionDocIds", {
18233
18385
  enumerable: true,
18234
- get: function () { return chunkPDE246CA_cjs.useEntityExtractionDocIds; }
18386
+ get: function () { return chunkVO7OWQP6_cjs.useEntityExtractionDocIds; }
18235
18387
  });
18236
18388
  Object.defineProperty(exports, "useExtractEntities", {
18237
18389
  enumerable: true,
18238
- get: function () { return chunkPDE246CA_cjs.useExtractEntities; }
18390
+ get: function () { return chunkVO7OWQP6_cjs.useExtractEntities; }
18239
18391
  });
18240
18392
  Object.defineProperty(exports, "useInvalidateTagData", {
18241
18393
  enumerable: true,
18242
- get: function () { return chunkPDE246CA_cjs.useInvalidateTagData; }
18394
+ get: function () { return chunkVO7OWQP6_cjs.useInvalidateTagData; }
18243
18395
  });
18244
18396
  Object.defineProperty(exports, "useIsCreatingTag", {
18245
18397
  enumerable: true,
18246
- get: function () { return chunkPDE246CA_cjs.useIsCreatingTag; }
18398
+ get: function () { return chunkVO7OWQP6_cjs.useIsCreatingTag; }
18247
18399
  });
18248
18400
  Object.defineProperty(exports, "useRefreshDocuments", {
18249
18401
  enumerable: true,
18250
- get: function () { return chunkPDE246CA_cjs.useRefreshDocuments; }
18402
+ get: function () { return chunkVO7OWQP6_cjs.useRefreshDocuments; }
18251
18403
  });
18252
18404
  Object.defineProperty(exports, "useSetTagValues", {
18253
18405
  enumerable: true,
18254
- get: function () { return chunkPDE246CA_cjs.useSetTagValues; }
18406
+ get: function () { return chunkVO7OWQP6_cjs.useSetTagValues; }
18255
18407
  });
18256
18408
  Object.defineProperty(exports, "useSimilarDocuments", {
18257
18409
  enumerable: true,
18258
- get: function () { return chunkPDE246CA_cjs.useSimilarDocuments; }
18410
+ get: function () { return chunkVO7OWQP6_cjs.useSimilarDocuments; }
18259
18411
  });
18260
18412
  Object.defineProperty(exports, "useTagKindSchema", {
18261
18413
  enumerable: true,
18262
- get: function () { return chunkPDE246CA_cjs.useTagKindSchema; }
18414
+ get: function () { return chunkVO7OWQP6_cjs.useTagKindSchema; }
18263
18415
  });
18264
18416
  Object.defineProperty(exports, "useUpdateTag", {
18265
18417
  enumerable: true,
18266
- get: function () { return chunkPDE246CA_cjs.useUpdateTag; }
18418
+ get: function () { return chunkVO7OWQP6_cjs.useUpdateTag; }
18267
18419
  });
18268
18420
  Object.defineProperty(exports, "useUpdateTagKindSchema", {
18269
18421
  enumerable: true,
18270
- get: function () { return chunkPDE246CA_cjs.useUpdateTagKindSchema; }
18422
+ get: function () { return chunkVO7OWQP6_cjs.useUpdateTagKindSchema; }
18271
18423
  });
18272
18424
  Object.defineProperty(exports, "DEFAULT_DOCUMENT_VIEWER_STATE", {
18273
18425
  enumerable: true,
@@ -20021,7 +20173,7 @@ exports.applyLiveUpdate = applyLiveUpdate;
20021
20173
  exports.applyNotificationRow = applyNotificationRow;
20022
20174
  exports.applyOptimisticDocumentEdit = applyOptimisticDocumentEdit;
20023
20175
  exports.applyOutputItemToMessage = applyOutputItemToMessage;
20024
- exports.applyTaskEvent = applyTaskEvent;
20176
+ exports.applyTaskEvents = applyTaskEvents;
20025
20177
  exports.arbiMailClient = arbiMailClient;
20026
20178
  exports.archiveName = archiveName;
20027
20179
  exports.archivedWorkspaceMessage = archivedWorkspaceMessage;