@arbidocs/react 0.5.138 → 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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/documents/processing-live.ts"],
4
- "sourcesContent": ["/**\n * A workspace's documents in processing, live: what every site's file views show while uploads\n * and re-processing run.\n *\n * - `applyTaskEvent` (the provider runs it on each taken `task_update`): an upload appears as a\n * row the moment it is queued (a light placeholder, so the table and the gallery show it with\n * its live progress), and a finished document replaces its row with the one read afresh.\n * - `useWorkspaceProcessing(workspaceId)`: the workspace's processing rows and their counts\n * (a snapshot every half second, so a batch upload does not re-render on every event), kept\n * honest: stale or orphaned rows are dropped when the workspace opens, rows a document read says\n * finished are settled, and the in-flight ones are re-checked when the connection comes back.\n */\n\nimport { useEffect, useMemo, useState } from 'react'\nimport { useQueryClient, type QueryClient } from '@tanstack/react-query'\nimport type { Arbi } from '@arbidocs/sdk/browser'\nimport type { WsTaskUpdateMessage } from '@arbidocs/client'\nimport { useArbi } from '../useArbi'\nimport { useArbiWsStore, type LiveTask } from '../websocket/store'\nimport { getCachedDocuments, patchDocuments } from './documents-cache'\nimport { refreshDocuments } from './documents-data'\nimport { subscribeDocumentReads } from './processing-settle'\nimport { FINISHED_DOCUMENT_STATUSES, IN_FLIGHT_DOCUMENT_STATUSES } from './processing-order'\nimport type { WorkspaceDocument } from './documents-cache'\n\n/** A row in flight longer than this is a zombie (its completion was lost): no real run takes it. */\nconst STALE_TASK_MS = 6 * 60 * 60 * 1000\n/** A row whose document is missing from a read list is an orphan only after this long. */\nconst ORPHAN_TASK_MS = 15 * 60 * 1000\n/** How often the workspace's rows are re-read into views while processing runs. */\nconst SNAPSHOT_MS = 500\n\n/** Apply one taken `task_update` to the documents list (`me`: who uploads, i.e. this user). */\nexport function applyTaskEvent(\n queryClient: QueryClient,\n arbi: Arbi,\n message: WsTaskUpdateMessage & { folder?: string | null },\n me: string | null | undefined\n): void {\n const workspaceId = message.workspace_ext_id\n if (!workspaceId) return\n if (FINISHED_DOCUMENT_STATUSES.has(message.status)) {\n // The finished document replaces its placeholder row and its own entry.\n void refreshDocuments(queryClient, arbi, [message.doc_ext_id])\n return\n }\n // Only once the list has been read: a placeholder must not stand in for the first read.\n const cached = getCachedDocuments(queryClient, workspaceId)\n if (!cached || cached.some((d) => d.external_id === message.doc_ext_id)) return\n const now = new Date().toISOString()\n // The fields the read document will carry, so the row passes the list's filters meanwhile.\n const placeholder = {\n external_id: message.doc_ext_id,\n workspace_ext_id: workspaceId,\n file_name: message.file_name ?? 'Uploading\u2026',\n status: message.status,\n folder: message.folder ?? null,\n wp_type: 'source',\n shared: false,\n created_by_ext_id: me ?? undefined,\n doc_metadata: {},\n doctags: [],\n created_at: now,\n updated_at: now,\n } as unknown as WorkspaceDocument\n patchDocuments(\n queryClient,\n (old) => (old.some((d) => d.external_id === message.doc_ext_id) ? old : [...old, placeholder]),\n workspaceId\n )\n}\n\n/** The workspace's processing rows (in the order of their document ids) and their counts. */\nexport interface WorkspaceProcessing {\n tasks: Record<string, LiveTask>\n allTasks: LiveTask[]\n processingCount: number\n completedCount: number\n failedCount: number\n skippedCount: number\n clearTask: (docId: string) => void\n clearFinishedTasks: () => void\n}\n\nexport function useWorkspaceProcessing(workspaceId: string | undefined): WorkspaceProcessing {\n const queryClient = useQueryClient()\n const arbi = useArbi()\n const [snapshot, setSnapshot] = useState(() => useArbiWsStore.getState().tasks)\n\n useEffect(() => {\n let timer: ReturnType<typeof setTimeout> | null = null\n const unsubscribe = useArbiWsStore.subscribe((state, previous) => {\n if (state.tasks === previous.tasks || timer) return\n timer = setTimeout(() => {\n timer = null\n setSnapshot(useArbiWsStore.getState().tasks)\n }, SNAPSHOT_MS)\n })\n return () => {\n unsubscribe()\n if (timer) clearTimeout(timer)\n }\n }, [])\n\n // When the workspace opens: settle what its list says finished, and drop zombie rows (in flight\n // for hours) and orphans (their document is gone from the read list).\n useEffect(() => {\n if (!workspaceId) return\n const store = useArbiWsStore.getState()\n const documents = getCachedDocuments(queryClient, workspaceId) ?? []\n store.settleTasks(documents)\n const listed = new Set(documents.map((d) => d.external_id))\n const now = Date.now()\n for (const task of Object.values(useArbiWsStore.getState().tasks)) {\n if (task.workspace_ext_id !== workspaceId || !IN_FLIGHT_DOCUMENT_STATUSES.has(task.status))\n continue\n const since = task.startTime ?? task.endTime\n const age = since == null ? null : now - since\n const stale = age != null && age > STALE_TASK_MS\n const orphan =\n documents.length > 0 && !listed.has(task.doc_ext_id) && age != null && age > ORPHAN_TASK_MS\n if (stale || orphan) store.clearTask(task.doc_ext_id)\n }\n }, [workspaceId, queryClient])\n\n // Afterwards: every documents read settles the rows it shows finished, and a connection that\n // comes back re-checks the in-flight ones (the events it missed are gone for good).\n useEffect(() => {\n if (!workspaceId) return\n const unsubscribeReads = subscribeDocumentReads(queryClient, (rows) =>\n useArbiWsStore.getState().settleTasks(rows)\n )\n const recheck = async () => {\n const ids = Object.values(useArbiWsStore.getState().tasks)\n .filter(\n (t) => t.workspace_ext_id === workspaceId && IN_FLIGHT_DOCUMENT_STATUSES.has(t.status)\n )\n .map((t) => t.doc_ext_id)\n if (ids.length) await refreshDocuments(queryClient, arbi, ids)\n }\n let wasConnected = useArbiWsStore.getState().status === 'connected'\n const unsubscribeStatus = useArbiWsStore.subscribe((state) => {\n const connected = state.status === 'connected'\n if (connected && !wasConnected) void recheck()\n wasConnected = connected\n })\n return () => {\n unsubscribeReads()\n unsubscribeStatus()\n }\n }, [workspaceId, queryClient, arbi])\n\n return useMemo(() => {\n const allTasks = workspaceId\n ? Object.values(snapshot)\n .filter((t) => t.workspace_ext_id === workspaceId)\n .sort((a, b) => a.doc_ext_id.localeCompare(b.doc_ext_id))\n : []\n const count = (statuses: ReadonlySet<string> | string[]) =>\n allTasks.filter((t) =>\n Array.isArray(statuses) ? statuses.includes(t.status) : statuses.has(t.status)\n ).length\n const { clearTask, clearFinishedTasks } = useArbiWsStore.getState()\n return {\n tasks: Object.fromEntries(allTasks.map((t) => [t.doc_ext_id, t])),\n allTasks,\n processingCount: count(IN_FLIGHT_DOCUMENT_STATUSES),\n completedCount: count(['completed', 'low-content']),\n failedCount: count(['failed']),\n skippedCount: count(['skipped']),\n clearTask,\n clearFinishedTasks,\n }\n }, [workspaceId, snapshot])\n}\n"],
5
- "mappings": "AAaA,SAAS,WAAW,SAAS,gBAAgB;AAC7C,SAAS,sBAAwC;AAGjD,SAAS,eAAe;AACxB,SAAS,sBAAqC;AAC9C,SAAS,oBAAoB,sBAAsB;AACnD,SAAS,wBAAwB;AACjC,SAAS,8BAA8B;AACvC,SAAS,4BAA4B,mCAAmC;AAIxE,MAAM,gBAAgB,IAAI,KAAK,KAAK;AAEpC,MAAM,iBAAiB,KAAK,KAAK;AAEjC,MAAM,cAAc;AAGb,SAAS,eACd,aACA,MACA,SACA,IACM;AACN,QAAM,cAAc,QAAQ;AAC5B,MAAI,CAAC,YAAa;AAClB,MAAI,2BAA2B,IAAI,QAAQ,MAAM,GAAG;AAElD,SAAK,iBAAiB,aAAa,MAAM,CAAC,QAAQ,UAAU,CAAC;AAC7D;AAAA,EACF;AAEA,QAAM,SAAS,mBAAmB,aAAa,WAAW;AAC1D,MAAI,CAAC,UAAU,OAAO,KAAK,CAAC,MAAM,EAAE,gBAAgB,QAAQ,UAAU,EAAG;AACzE,QAAM,OAAM,oBAAI,KAAK,GAAE,YAAY;AAEnC,QAAM,cAAc;AAAA,IAClB,aAAa,QAAQ;AAAA,IACrB,kBAAkB;AAAA,IAClB,WAAW,QAAQ,aAAa;AAAA,IAChC,QAAQ,QAAQ;AAAA,IAChB,QAAQ,QAAQ,UAAU;AAAA,IAC1B,SAAS;AAAA,IACT,QAAQ;AAAA,IACR,mBAAmB,MAAM;AAAA,IACzB,cAAc,CAAC;AAAA,IACf,SAAS,CAAC;AAAA,IACV,YAAY;AAAA,IACZ,YAAY;AAAA,EACd;AACA;AAAA,IACE;AAAA,IACA,CAAC,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O,YAAY,SAAS,IAAI,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC;AAAA,MAChE;AAAA,MACA,iBAAiB,MAAM,2BAA2B;AAAA,MAClD,gBAAgB,MAAM,CAAC,aAAa,aAAa,CAAC;AAAA,MAClD,aAAa,MAAM,CAAC,QAAQ,CAAC;AAAA,MAC7B,cAAc,MAAM,CAAC,SAAS,CAAC;AAAA,MAC/B;AAAA,MACA;AAAA,IACF;AAAA,EACF,GAAG,CAAC,aAAa,QAAQ,CAAC;AAC5B;",
4
+ "sourcesContent": ["/**\n * A workspace's documents in processing, live: what every site's file views show while uploads\n * and re-processing run.\n *\n * - `applyTaskEvents` (the provider runs it on the `task_update`s it took, a few times a second):\n * an upload appears as a row the moment it is queued (a light placeholder, so the table and the\n * gallery show it with its live progress), and a finished document replaces its row with the one\n * read afresh. A burst is one write to each list and one read of the finished documents.\n * - `useWorkspaceProcessing(workspaceId)`: the workspace's processing rows and their counts\n * (a snapshot every half second, so a batch upload does not re-render on every event), kept\n * honest: stale or orphaned rows are dropped when the workspace opens, rows a document read says\n * finished are settled, and the in-flight ones are re-checked when the connection comes back.\n */\n\nimport { useEffect, useMemo, useState } from 'react'\nimport { useQueryClient, type QueryClient } from '@tanstack/react-query'\nimport type { Arbi } from '@arbidocs/sdk/browser'\nimport type { WsTaskUpdateMessage } from '@arbidocs/client'\nimport { useArbi } from '../useArbi'\nimport { useArbiWsStore, type LiveTask } from '../websocket/store'\nimport { getCachedDocuments, patchDocuments } from './documents-cache'\nimport { queueDocumentReads, refreshDocuments } from './documents-data'\nimport { subscribeDocumentReads } from './processing-settle'\nimport { FINISHED_DOCUMENT_STATUSES, IN_FLIGHT_DOCUMENT_STATUSES } from './processing-order'\nimport type { WorkspaceDocument } from './documents-cache'\n\n/** A row in flight longer than this is a zombie (its completion was lost): no real run takes it. */\nconst STALE_TASK_MS = 6 * 60 * 60 * 1000\n/** A row whose document is missing from a read list is an orphan only after this long. */\nconst ORPHAN_TASK_MS = 15 * 60 * 1000\n/** How often the workspace's rows are re-read into views while processing runs. */\nconst SNAPSHOT_MS = 500\n\ntype TaskEvent = WsTaskUpdateMessage & { folder?: string | null }\n\n/** The row shown for an upload until its document is read: the fields the list's filters use. */\nfunction placeholderRow(message: TaskEvent, me: string | null | undefined): WorkspaceDocument {\n const now = new Date().toISOString()\n return {\n external_id: message.doc_ext_id,\n workspace_ext_id: message.workspace_ext_id,\n file_name: message.file_name ?? 'Uploading\u2026',\n status: message.status,\n folder: message.folder ?? null,\n wp_type: 'source',\n shared: false,\n created_by_ext_id: me ?? undefined,\n doc_metadata: {},\n doctags: [],\n created_at: now,\n updated_at: now,\n } as unknown as WorkspaceDocument\n}\n\n/**\n * Apply taken `task_update`s to the documents lists (`me`: who uploads, i.e. this user): the\n * finished documents are re-read (together, see `queueDocumentReads`), the others not yet listed\n * join their list as placeholder rows, in one write per list.\n */\nexport function applyTaskEvents(\n queryClient: QueryClient,\n arbi: Arbi,\n messages: TaskEvent[],\n me: string | null | undefined\n): void {\n const finished = new Set<string>()\n const pending = new Map<string, Map<string, TaskEvent>>()\n for (const message of messages) {\n const workspaceId = message.workspace_ext_id\n if (!workspaceId) continue\n if (FINISHED_DOCUMENT_STATUSES.has(message.status)) {\n finished.add(message.doc_ext_id)\n continue\n }\n const rows = pending.get(workspaceId) ?? new Map<string, TaskEvent>()\n // The first event of a document makes its row (as it was queued).\n if (!rows.has(message.doc_ext_id)) rows.set(message.doc_ext_id, message)\n pending.set(workspaceId, rows)\n }\n // The finished documents replace their placeholder rows and their own entries.\n queueDocumentReads(queryClient, arbi, [...finished])\n for (const [workspaceId, rows] of pending) {\n // Only once the list has been read: a placeholder must not stand in for the first read.\n const cached = getCachedDocuments(queryClient, workspaceId)\n if (!cached) continue\n const listed = new Set(cached.map((d) => d.external_id))\n const fresh = [...rows.values()].filter((m) => !listed.has(m.doc_ext_id))\n if (!fresh.length) continue\n patchDocuments(\n queryClient,\n (old) => {\n const known = old === cached ? listed : new Set(old.map((d) => d.external_id))\n const add = fresh.filter((m) => !known.has(m.doc_ext_id)).map((m) => placeholderRow(m, me))\n return add.length ? [...old, ...add] : old\n },\n workspaceId\n )\n }\n}\n\n/** The workspace's processing rows (in the order of their document ids) and their counts. */\nexport interface WorkspaceProcessing {\n tasks: Record<string, LiveTask>\n allTasks: LiveTask[]\n processingCount: number\n completedCount: number\n failedCount: number\n skippedCount: number\n clearTask: (docId: string) => void\n clearFinishedTasks: () => void\n}\n\nexport function useWorkspaceProcessing(workspaceId: string | undefined): WorkspaceProcessing {\n const queryClient = useQueryClient()\n const arbi = useArbi()\n const [snapshot, setSnapshot] = useState(() => useArbiWsStore.getState().tasks)\n\n useEffect(() => {\n let timer: ReturnType<typeof setTimeout> | null = null\n const unsubscribe = useArbiWsStore.subscribe((state, previous) => {\n if (state.tasks === previous.tasks || timer) return\n timer = setTimeout(() => {\n timer = null\n setSnapshot(useArbiWsStore.getState().tasks)\n }, SNAPSHOT_MS)\n })\n return () => {\n unsubscribe()\n if (timer) clearTimeout(timer)\n }\n }, [])\n\n // When the workspace opens: settle what its list says finished, and drop zombie rows (in flight\n // for hours) and orphans (their document is gone from the read list).\n useEffect(() => {\n if (!workspaceId) return\n const store = useArbiWsStore.getState()\n const documents = getCachedDocuments(queryClient, workspaceId) ?? []\n store.settleTasks(documents)\n const listed = new Set(documents.map((d) => d.external_id))\n const now = Date.now()\n for (const task of Object.values(useArbiWsStore.getState().tasks)) {\n if (task.workspace_ext_id !== workspaceId || !IN_FLIGHT_DOCUMENT_STATUSES.has(task.status))\n continue\n const since = task.startTime ?? task.endTime\n const age = since == null ? null : now - since\n const stale = age != null && age > STALE_TASK_MS\n const orphan =\n documents.length > 0 && !listed.has(task.doc_ext_id) && age != null && age > ORPHAN_TASK_MS\n if (stale || orphan) store.clearTask(task.doc_ext_id)\n }\n }, [workspaceId, queryClient])\n\n // Afterwards: every documents read settles the rows it shows finished, and a connection that\n // comes back re-checks the in-flight ones (the events it missed are gone for good).\n useEffect(() => {\n if (!workspaceId) return\n const unsubscribeReads = subscribeDocumentReads(queryClient, (rows) =>\n useArbiWsStore.getState().settleTasks(rows)\n )\n const recheck = async () => {\n const ids = Object.values(useArbiWsStore.getState().tasks)\n .filter(\n (t) => t.workspace_ext_id === workspaceId && IN_FLIGHT_DOCUMENT_STATUSES.has(t.status)\n )\n .map((t) => t.doc_ext_id)\n if (ids.length) await refreshDocuments(queryClient, arbi, ids)\n }\n let wasConnected = useArbiWsStore.getState().status === 'connected'\n const unsubscribeStatus = useArbiWsStore.subscribe((state) => {\n const connected = state.status === 'connected'\n if (connected && !wasConnected) void recheck()\n wasConnected = connected\n })\n return () => {\n unsubscribeReads()\n unsubscribeStatus()\n }\n }, [workspaceId, queryClient, arbi])\n\n return useMemo(() => {\n const allTasks = workspaceId\n ? Object.values(snapshot)\n .filter((t) => t.workspace_ext_id === workspaceId)\n .sort((a, b) => a.doc_ext_id.localeCompare(b.doc_ext_id))\n : []\n const count = (statuses: ReadonlySet<string> | string[]) =>\n allTasks.filter((t) =>\n Array.isArray(statuses) ? statuses.includes(t.status) : statuses.has(t.status)\n ).length\n const { clearTask, clearFinishedTasks } = useArbiWsStore.getState()\n return {\n tasks: Object.fromEntries(allTasks.map((t) => [t.doc_ext_id, t])),\n allTasks,\n processingCount: count(IN_FLIGHT_DOCUMENT_STATUSES),\n completedCount: count(['completed', 'low-content']),\n failedCount: count(['failed']),\n skippedCount: count(['skipped']),\n clearTask,\n clearFinishedTasks,\n }\n }, [workspaceId, snapshot])\n}\n"],
5
+ "mappings": "AAcA,SAAS,WAAW,SAAS,gBAAgB;AAC7C,SAAS,sBAAwC;AAGjD,SAAS,eAAe;AACxB,SAAS,sBAAqC;AAC9C,SAAS,oBAAoB,sBAAsB;AACnD,SAAS,oBAAoB,wBAAwB;AACrD,SAAS,8BAA8B;AACvC,SAAS,4BAA4B,mCAAmC;AAIxE,MAAM,gBAAgB,IAAI,KAAK,KAAK;AAEpC,MAAM,iBAAiB,KAAK,KAAK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,IAC1D,CAAC;AACL,UAAM,QAAQ,CAAC,aACb,SAAS;AAAA,MAAO,CAAC,MACf,MAAM,QAAQ,QAAQ,IAAI,SAAS,SAAS,EAAE,MAAM,IAAI,SAAS,IAAI,EAAE,MAAM;AAAA,IAC/E,EAAE;AACJ,UAAM,EAAE,WAAW,mBAAmB,IAAI,eAAe,SAAS;AAClE,WAAO;AAAA,MACL,OAAO,OAAO,YAAY,SAAS,IAAI,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC;AAAA,MAChE;AAAA,MACA,iBAAiB,MAAM,2BAA2B;AAAA,MAClD,gBAAgB,MAAM,CAAC,aAAa,aAAa,CAAC;AAAA,MAClD,aAAa,MAAM,CAAC,QAAQ,CAAC;AAAA,MAC7B,cAAc,MAAM,CAAC,SAAS,CAAC;AAAA,MAC/B;AAAA,MACA;AAAA,IACF;AAAA,EACF,GAAG,CAAC,aAAa,QAAQ,CAAC;AAC5B;",
6
6
  "names": []
7
7
  }
@@ -9,9 +9,11 @@ import { refreshDocuments } from "./documents-data.js";
9
9
  import { useGenerateDocTags } from "./documents-writes.js";
10
10
  import { useDocumentsSupport } from "./support.js";
11
11
  import { uploadFolderOf } from "./upload-files.js";
12
+ import { throttle } from "../lib/throttle.js";
12
13
  const { mimeFromName, newUploadSet } = documentOps;
13
14
  const BATCH_SIZE = 100;
14
15
  const CONCURRENT_BATCHES = 4;
16
+ const UPLOAD_PROGRESS_INTERVAL_MS = 100;
15
17
  const uploadedFolders = /* @__PURE__ */ new Map();
16
18
  function uploadedDocumentFolder(workspaceId, docId) {
17
19
  const pending = uploadedFolders.get(docId);
@@ -65,12 +67,16 @@ function useUploadFiles() {
65
67
  const filesByBatch = new Array(batches.length).fill(0);
66
68
  let done = 0;
67
69
  let highest = 0;
70
+ const emit = throttle(
71
+ (progress) => onProgress?.(progress),
72
+ UPLOAD_PROGRESS_INTERVAL_MS
73
+ );
68
74
  const report = () => {
69
75
  const loaded = loadedByBatch.reduce((sum, bytes) => sum + bytes, 0);
70
76
  const sent = filesByBatch.reduce((sum, files) => sum + files, 0);
71
77
  const share = input.files.length > 0 ? sent / input.files.length : 0;
72
78
  highest = Math.max(highest, Math.min(Math.round(share * 100), 100));
73
- onProgress?.({
79
+ emit({
74
80
  loaded,
75
81
  total,
76
82
  percentage: highest,
@@ -142,25 +148,28 @@ function useUploadFiles() {
142
148
  return result;
143
149
  }),
144
150
  CONCURRENT_BATCHES
145
- );
151
+ ).finally(() => emit.cancel());
152
+ report();
153
+ emit.flush();
146
154
  const docIds = results.flatMap((result) => result.doc_ext_ids ?? []);
147
155
  const skipped = results.flatMap((result) => result.skipped ?? []);
148
- if (docIds.length > 0) {
149
- const read = await refreshDocuments(qc, arbi, docIds);
150
- for (const doc of read) forgetUploadedDocumentFolder(doc.external_id);
151
- }
152
- await qc.invalidateQueries({ queryKey: arbiQueryKeys.workspaces() });
153
- if (docIds.length > 0 && input.generateTagIds?.length) {
154
- await generateDocTags({ tagIds: input.generateTagIds, docIds, overwrite: false }).catch(
155
- () => void 0
156
- );
157
- }
158
- return { docIds, skipped };
156
+ const settled = (async () => {
157
+ if (docIds.length > 0) {
158
+ const read = await refreshDocuments(qc, arbi, docIds);
159
+ for (const doc of read) forgetUploadedDocumentFolder(doc.external_id);
160
+ }
161
+ await qc.invalidateQueries({ queryKey: arbiQueryKeys.workspaces() });
162
+ if (docIds.length > 0 && input.generateTagIds?.length) {
163
+ await generateDocTags({ tagIds: input.generateTagIds, docIds, overwrite: false });
164
+ }
165
+ })().catch(() => void 0);
166
+ return { docIds, skipped, settled };
159
167
  },
160
168
  [arbi, qc, direct, resolveWorkspaceKey, generateDocTags]
161
169
  );
162
170
  }
163
171
  export {
172
+ UPLOAD_PROGRESS_INTERVAL_MS,
164
173
  forgetUploadedDocumentFolder,
165
174
  uploadedDocumentFolder,
166
175
  useUploadFiles
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/documents/useUploadFiles.ts"],
4
- "sourcesContent": ["/**\n * Upload chosen files to the open workspace, with progress. Files go in batches (one per folder\n * they land in, at most 100 files each, four at a time); each file keeps the folder it sat in below\n * where the upload started. All the batches are one upload set: the person is told once, when every\n * file of it is processed (the server's `upload_set_complete` notification), not once per batch.\n * With direct upload on in the user's settings, and the workspace key\n * held here, files are encrypted here and sent straight to storage; otherwise through the server.\n * The new documents join their list in their folder; the labels asked for fill their AI fields.\n */\n\nimport { useCallback } from 'react'\nimport { useQueryClient } from '@tanstack/react-query'\nimport { documents as documentOps } from '@arbidocs/sdk/browser'\nimport { useArbi } from '../useArbi'\nimport { arbiQueryKeys } from '../hooks'\nimport { useUserSettings } from '../account/settings'\nimport { patchDocuments } from './documents-cache'\nimport { refreshDocuments } from './documents-data'\nimport { useGenerateDocTags } from './documents-writes'\nimport { useDocumentsSupport } from './support'\nimport { uploadFolderOf } from './upload-files'\n\nconst { mimeFromName, newUploadSet } = documentOps\n\nconst BATCH_SIZE = 100\nconst CONCURRENT_BATCHES = 4\n\nexport interface UploadFilesInput {\n files: File[]\n /** Upload to this member workspace instead of the currently open workspace. */\n workspaceExtId?: string\n /** Where the upload started (a folder path); null or absent: the workspace root. */\n folder?: string | null\n shared: boolean\n configExtId?: string | null\n /** Labels whose AI fields are filled on the new documents. */\n generateTagIds?: string[]\n}\n\nexport interface UploadFilesProgress {\n loaded: number\n total: number\n /** Share of the files sent (one on the wire counts by its bytes sent); it never goes back. */\n percentage: number\n /** Batches done of all, when there is more than one. */\n batches: { current: number; total: number } | null\n}\n\nexport interface UploadFilesResult {\n docIds: string[]\n /** Files the server did not take, and why. */\n skipped: { file_name: string; reason: string }[]\n}\n\ninterface PendingFolder {\n workspaceId: string\n folder: string | null\n}\n\n// The folder of each document an upload made, until its row is read: a row announced live before\n// that (processing started) is shown in it.\nconst uploadedFolders = new Map<string, PendingFolder>()\n\n/** The folder an upload put `docId` in, while its row has not been read yet. */\nexport function uploadedDocumentFolder(\n workspaceId: string,\n docId: string\n): string | null | undefined {\n const pending = uploadedFolders.get(docId)\n return pending?.workspaceId === workspaceId ? pending.folder : undefined\n}\n\n/** `docId`'s row was read: its folder is known. */\nexport function forgetUploadedDocumentFolder(docId: string): void {\n uploadedFolders.delete(docId)\n}\n\n/** Run `tasks` at most `limit` at a time; resolves with their results in order. */\nasync function runLimited<T>(tasks: Array<() => Promise<T>>, limit: number): Promise<T[]> {\n const results = new Array<T>(tasks.length)\n let next = 0\n const worker = async () => {\n while (next < tasks.length) {\n const index = next++\n results[index] = await tasks[index]()\n }\n }\n await Promise.all(Array.from({ length: Math.min(limit, tasks.length) }, worker))\n return results\n}\n\nexport function useUploadFiles() {\n const arbi = useArbi()\n const qc = useQueryClient()\n const { resolveWorkspaceKey } = useDocumentsSupport()\n const { data: settings } = useUserSettings()\n const { mutateAsync: generateDocTags } = useGenerateDocTags()\n const direct = settings?.use_s3_direct_upload === true\n\n return useCallback(\n async (\n input: UploadFilesInput,\n onProgress?: (progress: UploadFilesProgress) => void\n ): Promise<UploadFilesResult> => {\n const workspaceId = input.workspaceExtId ?? arbi.getWorkspaceId()\n const groups = new Map<string | null, File[]>()\n for (const file of input.files) {\n const folder = uploadFolderOf(file, input.folder)\n groups.set(folder, [...(groups.get(folder) ?? []), file])\n }\n const batches: { folder: string | null; files: File[] }[] = []\n for (const [folder, files] of groups)\n for (let i = 0; i < files.length; i += BATCH_SIZE)\n batches.push({ folder, files: files.slice(i, i + BATCH_SIZE) })\n\n // The direct upload needs the workspace key here; without it the server encrypts. The key and\n // the workspace its init and commit name are both this upload's `workspaceId`, captured now,\n // so a switch while it runs cannot move a batch (or encrypt one for another workspace).\n let workspaceKey: Uint8Array | null = null\n if (direct && workspaceId && resolveWorkspaceKey) {\n try {\n workspaceKey = await resolveWorkspaceKey(workspaceId)\n } catch {\n workspaceKey = null\n }\n }\n\n // One drop or selection, one set, whatever batches it is sent in.\n const uploadSet = newUploadSet(input.files.length)\n const total = input.files.reduce((sum, file) => sum + file.size, 0)\n // Per batch: the bytes sent, and how many of its files that is (a file part-sent counts by its\n // share of bytes). The bar follows the files, and with four batches on the wire it only grows.\n const loadedByBatch = new Array<number>(batches.length).fill(0)\n const filesByBatch = new Array<number>(batches.length).fill(0)\n let done = 0\n let highest = 0\n const report = () => {\n const loaded = loadedByBatch.reduce((sum, bytes) => sum + bytes, 0)\n const sent = filesByBatch.reduce((sum, files) => sum + files, 0)\n const share = input.files.length > 0 ? sent / input.files.length : 0\n highest = Math.max(highest, Math.min(Math.round(share * 100), 100))\n onProgress?.({\n loaded,\n total,\n percentage: highest,\n batches: batches.length > 1 ? { current: done, total: batches.length } : null,\n })\n }\n report()\n\n const results = await runLimited(\n batches.map(({ folder, files }, index) => async () => {\n const bytes = files.reduce((sum, file) => sum + file.size, 0)\n const throughServer = () =>\n arbi.documents.upload(files, {\n shared: input.shared,\n folder: folder ?? undefined,\n configExtId: input.configExtId ?? undefined,\n // Named even when it is the open one: batches sent after a switch stay in this workspace.\n workspaceExtId: workspaceId,\n uploadSet,\n // One request for the batch: its files count by the share of its bytes sent.\n onProgress: (loaded) => {\n loadedByBatch[index] = Math.min(loaded, bytes)\n filesByBatch[index] = bytes > 0 ? (loadedByBatch[index] / bytes) * files.length : 0\n report()\n },\n })\n // One PUT per file: how much of each has gone.\n const fileShares = new Array<number>(files.length).fill(0)\n const directly = async (key: Uint8Array, workspace: string) =>\n arbi.documents.uploadDirect(\n workspace,\n key,\n await Promise.all(\n files.map(async (file) => ({\n name: file.name,\n data: new Uint8Array(await file.arrayBuffer()),\n contentType: file.type || mimeFromName(file.name),\n }))\n ),\n {\n shared: input.shared,\n folder: folder ?? undefined,\n configExtId: input.configExtId ?? undefined,\n uploadSet,\n // Per file, in ciphertext bytes: that file's share sent, scaled back to its own\n // size so the byte total stays true.\n onBytesProgress: ({ fileIndex, loaded, total: sent }) => {\n const share = sent > 0 ? Math.min(loaded / sent, 1) : 0\n fileShares[fileIndex] = Math.max(fileShares[fileIndex] ?? 0, share)\n loadedByBatch[index] = Math.round(\n files.reduce((sum, file, i) => sum + (fileShares[i] ?? 0) * file.size, 0)\n )\n filesByBatch[index] = fileShares.reduce((sum, part) => sum + part, 0)\n report()\n },\n }\n )\n const result =\n workspaceKey && workspaceId\n ? await directly(workspaceKey, workspaceId)\n : await throughServer()\n const docIds = result.doc_ext_ids ?? []\n if (docIds.length > 0) {\n for (const docId of docIds) uploadedFolders.set(docId, { workspaceId, folder })\n const made = new Set(docIds)\n patchDocuments(\n qc,\n (rows) => rows.map((doc) => (made.has(doc.external_id) ? { ...doc, folder } : doc)),\n workspaceId\n )\n }\n loadedByBatch[index] = bytes\n filesByBatch[index] = files.length\n done += 1\n report()\n return result\n }),\n CONCURRENT_BATCHES\n )\n\n const docIds = results.flatMap((result) => result.doc_ext_ids ?? [])\n const skipped = results.flatMap((result) => result.skipped ?? [])\n if (docIds.length > 0) {\n const read = await refreshDocuments(qc, arbi, docIds)\n for (const doc of read) forgetUploadedDocumentFolder(doc.external_id)\n }\n await qc.invalidateQueries({ queryKey: arbiQueryKeys.workspaces() })\n if (docIds.length > 0 && input.generateTagIds?.length) {\n // The upload stands even when filling the AI fields could not start.\n await generateDocTags({ tagIds: input.generateTagIds, docIds, overwrite: false }).catch(\n () => undefined\n )\n }\n return { docIds, skipped }\n },\n [arbi, qc, direct, resolveWorkspaceKey, generateDocTags]\n )\n}\n"],
5
- "mappings": "AAUA,SAAS,mBAAmB;AAC5B,SAAS,sBAAsB;AAC/B,SAAS,aAAa,mBAAmB;AACzC,SAAS,eAAe;AACxB,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB;AAChC,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AACjC,SAAS,0BAA0B;AACnC,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AAE/B,MAAM,EAAE,cAAc,aAAa,IAAI;AAEvC,MAAM,aAAa;AACnB,MAAM,qBAAqB;AAoC3B,MAAM,kBAAkB,oBAAI,IAA2B;AAGhD,SAAS,uBACd,aACA,OAC2B;AAC3B,QAAM,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;AAC1B,gBAAMA,UAAS,OAAO,eAAe,CAAC;AACtC,cAAIA,QAAO,SAAS,GAAG;AACrB,uBAAW,SAASA,QAAQ,iBAAgB,IAAI,OAAO,EAAE,aAAa,OAAO,CAAC;AAC9E,kBAAM,OAAO,IAAI,IAAIA,OAAM;AAC3B;AAAA,cACE;AAAA,cACA,CAAC,SAAS,KAAK,IAAI,CAAC,QAAS,KAAK,IAAI,IAAI,WAAW,IAAI,EAAE,GAAG,KAAK,OAAO,IAAI,GAAI;AAAA,cAClF;AAAA,YACF;AAAA,UACF;AACA,wBAAc,KAAK,IAAI;AACvB,uBAAa,KAAK,IAAI,MAAM;AAC5B,kBAAQ;AACR,iBAAO;AACP,iBAAO;AAAA,QACT,CAAC;AAAA,QACD;AAAA,MACF;AAEA,YAAM,SAAS,QAAQ,QAAQ,CAAC,WAAW,OAAO,eAAe,CAAC,CAAC;AACnE,YAAM,UAAU,QAAQ,QAAQ,CAAC,WAAW,OAAO,WAAW,CAAC,CAAC;AAChE,UAAI,OAAO,SAAS,GAAG;AACrB,cAAM,OAAO,MAAM,iBAAiB,IAAI,MAAM,MAAM;AACpD,mBAAW,OAAO,KAAM,8BAA6B,IAAI,WAAW;AAAA,MACtE;AACA,YAAM,GAAG,kBAAkB,EAAE,UAAU,cAAc,WAAW,EAAE,CAAC;AACnE,UAAI,OAAO,SAAS,KAAK,MAAM,gBAAgB,QAAQ;AAErD,cAAM,gBAAgB,EAAE,QAAQ,MAAM,gBAAgB,QAAQ,WAAW,MAAM,CAAC,EAAE;AAAA,UAChF,MAAM;AAAA,QACR;AAAA,MACF;AACA,aAAO,EAAE,QAAQ,QAAQ;AAAA,IAC3B;AAAA,IACA,CAAC,MAAM,IAAI,QAAQ,qBAAqB,eAAe;AAAA,EACzD;AACF;",
4
+ "sourcesContent": ["/**\n * Upload chosen files to the open workspace, with progress. Files go in batches (one per folder\n * they land in, at most 100 files each, four at a time); each file keeps the folder it sat in below\n * where the upload started. All the batches are one upload set: the person is told once, when every\n * file of it is processed (the server's `upload_set_complete` notification), not once per batch.\n * With direct upload on in the user's settings, and the workspace key\n * held here, files are encrypted here and sent straight to storage; otherwise through the server.\n * The new documents join their list in their folder; the labels asked for fill their AI fields.\n *\n * The upload resolves as soon as every batch is sent (and committed): what follows (re-reading the\n * new rows, the workspace counts, starting the AI fields) runs after it, in `settled`, so a dialog\n * waiting on the upload closes when the files are sent, not when the follow-up is done. Progress\n * is reported a few times a second, however fast the bytes go.\n */\n\nimport { useCallback } from 'react'\nimport { useQueryClient } from '@tanstack/react-query'\nimport { documents as documentOps } from '@arbidocs/sdk/browser'\nimport { useArbi } from '../useArbi'\nimport { arbiQueryKeys } from '../hooks'\nimport { useUserSettings } from '../account/settings'\nimport { patchDocuments } from './documents-cache'\nimport { refreshDocuments } from './documents-data'\nimport { useGenerateDocTags } from './documents-writes'\nimport { useDocumentsSupport } from './support'\nimport { uploadFolderOf } from './upload-files'\nimport { throttle } from '../lib/throttle'\n\nconst { mimeFromName, newUploadSet } = documentOps\n\nconst BATCH_SIZE = 100\nconst CONCURRENT_BATCHES = 4\n/** At most this often the progress is reported (an XHR progress event comes every few ms). */\nexport const UPLOAD_PROGRESS_INTERVAL_MS = 100\n\nexport interface UploadFilesInput {\n files: File[]\n /** Upload to this member workspace instead of the currently open workspace. */\n workspaceExtId?: string\n /** Where the upload started (a folder path); null or absent: the workspace root. */\n folder?: string | null\n shared: boolean\n configExtId?: string | null\n /** Labels whose AI fields are filled on the new documents. */\n generateTagIds?: string[]\n}\n\nexport interface UploadFilesProgress {\n loaded: number\n total: number\n /** Share of the files sent (one on the wire counts by its bytes sent); it never goes back. */\n percentage: number\n /** Batches done of all, when there is more than one. */\n batches: { current: number; total: number } | null\n}\n\nexport interface UploadFilesResult {\n docIds: string[]\n /** Files the server did not take, and why. */\n skipped: { file_name: string; reason: string }[]\n /**\n * The follow-up after the files were sent: the new rows re-read into their lists, the workspace\n * counts refreshed and the AI fields started. Never rejects.\n */\n settled: Promise<void>\n}\n\ninterface PendingFolder {\n workspaceId: string\n folder: string | null\n}\n\n// The folder of each document an upload made, until its row is read: a row announced live before\n// that (processing started) is shown in it.\nconst uploadedFolders = new Map<string, PendingFolder>()\n\n/** The folder an upload put `docId` in, while its row has not been read yet. */\nexport function uploadedDocumentFolder(\n workspaceId: string,\n docId: string\n): string | null | undefined {\n const pending = uploadedFolders.get(docId)\n return pending?.workspaceId === workspaceId ? pending.folder : undefined\n}\n\n/** `docId`'s row was read: its folder is known. */\nexport function forgetUploadedDocumentFolder(docId: string): void {\n uploadedFolders.delete(docId)\n}\n\n/** Run `tasks` at most `limit` at a time; resolves with their results in order. */\nasync function runLimited<T>(tasks: Array<() => Promise<T>>, limit: number): Promise<T[]> {\n const results = new Array<T>(tasks.length)\n let next = 0\n const worker = async () => {\n while (next < tasks.length) {\n const index = next++\n results[index] = await tasks[index]()\n }\n }\n await Promise.all(Array.from({ length: Math.min(limit, tasks.length) }, worker))\n return results\n}\n\nexport function useUploadFiles() {\n const arbi = useArbi()\n const qc = useQueryClient()\n const { resolveWorkspaceKey } = useDocumentsSupport()\n const { data: settings } = useUserSettings()\n const { mutateAsync: generateDocTags } = useGenerateDocTags()\n const direct = settings?.use_s3_direct_upload === true\n\n return useCallback(\n async (\n input: UploadFilesInput,\n onProgress?: (progress: UploadFilesProgress) => void\n ): Promise<UploadFilesResult> => {\n const workspaceId = input.workspaceExtId ?? arbi.getWorkspaceId()\n const groups = new Map<string | null, File[]>()\n for (const file of input.files) {\n const folder = uploadFolderOf(file, input.folder)\n groups.set(folder, [...(groups.get(folder) ?? []), file])\n }\n const batches: { folder: string | null; files: File[] }[] = []\n for (const [folder, files] of groups)\n for (let i = 0; i < files.length; i += BATCH_SIZE)\n batches.push({ folder, files: files.slice(i, i + BATCH_SIZE) })\n\n // The direct upload needs the workspace key here; without it the server encrypts. The key and\n // the workspace its init and commit name are both this upload's `workspaceId`, captured now,\n // so a switch while it runs cannot move a batch (or encrypt one for another workspace).\n let workspaceKey: Uint8Array | null = null\n if (direct && workspaceId && resolveWorkspaceKey) {\n try {\n workspaceKey = await resolveWorkspaceKey(workspaceId)\n } catch {\n workspaceKey = null\n }\n }\n\n // One drop or selection, one set, whatever batches it is sent in.\n const uploadSet = newUploadSet(input.files.length)\n const total = input.files.reduce((sum, file) => sum + file.size, 0)\n // Per batch: the bytes sent, and how many of its files that is (a file part-sent counts by its\n // share of bytes). The bar follows the files, and with four batches on the wire it only grows.\n const loadedByBatch = new Array<number>(batches.length).fill(0)\n const filesByBatch = new Array<number>(batches.length).fill(0)\n let done = 0\n let highest = 0\n const emit = throttle(\n (progress: UploadFilesProgress) => onProgress?.(progress),\n UPLOAD_PROGRESS_INTERVAL_MS\n )\n const report = () => {\n const loaded = loadedByBatch.reduce((sum, bytes) => sum + bytes, 0)\n const sent = filesByBatch.reduce((sum, files) => sum + files, 0)\n const share = input.files.length > 0 ? sent / input.files.length : 0\n highest = Math.max(highest, Math.min(Math.round(share * 100), 100))\n emit({\n loaded,\n total,\n percentage: highest,\n batches: batches.length > 1 ? { current: done, total: batches.length } : null,\n })\n }\n report()\n\n const results = await runLimited(\n batches.map(({ folder, files }, index) => async () => {\n const bytes = files.reduce((sum, file) => sum + file.size, 0)\n const throughServer = () =>\n arbi.documents.upload(files, {\n shared: input.shared,\n folder: folder ?? undefined,\n configExtId: input.configExtId ?? undefined,\n // Named even when it is the open one: batches sent after a switch stay in this workspace.\n workspaceExtId: workspaceId,\n uploadSet,\n // One request for the batch: its files count by the share of its bytes sent.\n onProgress: (loaded) => {\n loadedByBatch[index] = Math.min(loaded, bytes)\n filesByBatch[index] = bytes > 0 ? (loadedByBatch[index] / bytes) * files.length : 0\n report()\n },\n })\n // One PUT per file: how much of each has gone.\n const fileShares = new Array<number>(files.length).fill(0)\n const directly = async (key: Uint8Array, workspace: string) =>\n arbi.documents.uploadDirect(\n workspace,\n key,\n await Promise.all(\n files.map(async (file) => ({\n name: file.name,\n data: new Uint8Array(await file.arrayBuffer()),\n contentType: file.type || mimeFromName(file.name),\n }))\n ),\n {\n shared: input.shared,\n folder: folder ?? undefined,\n configExtId: input.configExtId ?? undefined,\n uploadSet,\n // Per file, in ciphertext bytes: that file's share sent, scaled back to its own\n // size so the byte total stays true.\n onBytesProgress: ({ fileIndex, loaded, total: sent }) => {\n const share = sent > 0 ? Math.min(loaded / sent, 1) : 0\n fileShares[fileIndex] = Math.max(fileShares[fileIndex] ?? 0, share)\n loadedByBatch[index] = Math.round(\n files.reduce((sum, file, i) => sum + (fileShares[i] ?? 0) * file.size, 0)\n )\n filesByBatch[index] = fileShares.reduce((sum, part) => sum + part, 0)\n report()\n },\n }\n )\n const result =\n workspaceKey && workspaceId\n ? await directly(workspaceKey, workspaceId)\n : await throughServer()\n const docIds = result.doc_ext_ids ?? []\n if (docIds.length > 0) {\n for (const docId of docIds) uploadedFolders.set(docId, { workspaceId, folder })\n const made = new Set(docIds)\n patchDocuments(\n qc,\n (rows) => rows.map((doc) => (made.has(doc.external_id) ? { ...doc, folder } : doc)),\n workspaceId\n )\n }\n loadedByBatch[index] = bytes\n filesByBatch[index] = files.length\n done += 1\n report()\n return result\n }),\n CONCURRENT_BATCHES\n ).finally(() => emit.cancel())\n // The last value (100 %) is reported at once.\n report()\n emit.flush()\n\n const docIds = results.flatMap((result) => result.doc_ext_ids ?? [])\n const skipped = results.flatMap((result) => result.skipped ?? [])\n const settled = (async () => {\n if (docIds.length > 0) {\n const read = await refreshDocuments(qc, arbi, docIds)\n for (const doc of read) forgetUploadedDocumentFolder(doc.external_id)\n }\n await qc.invalidateQueries({ queryKey: arbiQueryKeys.workspaces() })\n if (docIds.length > 0 && input.generateTagIds?.length) {\n // The upload stands even when filling the AI fields could not start.\n await generateDocTags({ tagIds: input.generateTagIds, docIds, overwrite: false })\n }\n })().catch(() => undefined)\n return { docIds, skipped, settled }\n },\n [arbi, qc, direct, resolveWorkspaceKey, generateDocTags]\n )\n}\n"],
5
+ "mappings": "AAeA,SAAS,mBAAmB;AAC5B,SAAS,sBAAsB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