@arbidocs/react 0.5.136 → 0.5.138
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/documents/useUploadFiles.js +4 -1
- package/dist/documents/useUploadFiles.js.map +2 -2
- package/dist/facts.js +4 -1
- package/dist/facts.js.map +2 -2
- package/dist/index.cjs +98 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/notifications/server-notifications.js +51 -1
- package/dist/notifications/server-notifications.js.map +2 -2
- package/package.json +3 -3
|
@@ -9,7 +9,7 @@ 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
|
-
const { mimeFromName } = documentOps;
|
|
12
|
+
const { mimeFromName, newUploadSet } = documentOps;
|
|
13
13
|
const BATCH_SIZE = 100;
|
|
14
14
|
const CONCURRENT_BATCHES = 4;
|
|
15
15
|
const uploadedFolders = /* @__PURE__ */ new Map();
|
|
@@ -59,6 +59,7 @@ function useUploadFiles() {
|
|
|
59
59
|
workspaceKey = null;
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
+
const uploadSet = newUploadSet(input.files.length);
|
|
62
63
|
const total = input.files.reduce((sum, file) => sum + file.size, 0);
|
|
63
64
|
const loadedByBatch = new Array(batches.length).fill(0);
|
|
64
65
|
const filesByBatch = new Array(batches.length).fill(0);
|
|
@@ -86,6 +87,7 @@ function useUploadFiles() {
|
|
|
86
87
|
configExtId: input.configExtId ?? void 0,
|
|
87
88
|
// Named even when it is the open one: batches sent after a switch stay in this workspace.
|
|
88
89
|
workspaceExtId: workspaceId,
|
|
90
|
+
uploadSet,
|
|
89
91
|
// One request for the batch: its files count by the share of its bytes sent.
|
|
90
92
|
onProgress: (loaded) => {
|
|
91
93
|
loadedByBatch[index] = Math.min(loaded, bytes);
|
|
@@ -108,6 +110,7 @@ function useUploadFiles() {
|
|
|
108
110
|
shared: input.shared,
|
|
109
111
|
folder: folder ?? void 0,
|
|
110
112
|
configExtId: input.configExtId ?? void 0,
|
|
113
|
+
uploadSet,
|
|
111
114
|
// Per file, in ciphertext bytes: that file's share sent, scaled back to its own
|
|
112
115
|
// size so the byte total stays true.
|
|
113
116
|
onBytesProgress: ({ fileIndex, loaded, total: sent }) => {
|
|
@@ -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. 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 } = 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 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 // 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 // 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": "
|
|
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,UAAU,gBAAgB,IAAI,KAAK;AACzC,SAAO,SAAS,gBAAgB,cAAc,QAAQ,SAAS;AACjE;AAGO,SAAS,6BAA6B,OAAqB;AAChE,kBAAgB,OAAO,KA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a,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;",
|
|
6
6
|
"names": ["docIds"]
|
|
7
7
|
}
|
package/dist/facts.js
CHANGED
|
@@ -18,7 +18,10 @@ function useFacts(workspaceId, options) {
|
|
|
18
18
|
}
|
|
19
19
|
function useRefreshFacts() {
|
|
20
20
|
const qc = useQueryClient();
|
|
21
|
-
return () =>
|
|
21
|
+
return () => Promise.all([
|
|
22
|
+
qc.invalidateQueries({ queryKey: arbiQueryKeys.allFacts() }),
|
|
23
|
+
qc.invalidateQueries({ queryKey: arbiQueryKeys.allTags() })
|
|
24
|
+
]);
|
|
22
25
|
}
|
|
23
26
|
function useCreateFact(workspaceId) {
|
|
24
27
|
const arbi = useArbi();
|
package/dist/facts.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/facts.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Workspace facts (notes): a workspace's list, filtered for the timeline or by tag, the writes\n * (create, batch, patch, delete) and the search. List, create and search name their workspace (the\n * one given, else the open one, captured when they are sent); patch and delete act in the fact's\n * own workspace. Every write refreshes every cached list.\n *\n * Requires an `ArbiHost` (with an `arbi`) and a React Query client above it.\n */\n\nimport { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'\nimport type {\n CreateFactRequest,\n CreateFactsRequest,\n FactResponse,\n FactSearchRequest,\n FactSearchResponse,\n ListFactsOptions,\n UpdateFactRequest,\n} from '@arbidocs/sdk/browser'\nimport { useArbi } from './useArbi'\nimport { arbiQueryKeys } from './hooks'\n\n/** The workspace a fact call names: the one given, else the one open now ('' when none is). */\nfunction factWorkspace(arbi: ReturnType<typeof useArbi>, workspaceId?: string | null): string {\n return workspaceId || (arbi.hasWorkspace ? arbi.getWorkspaceId() : '')\n}\n\n/** What a list asks for: the timeline range, or the notes carrying tags or citing a document. */\nexport type FactListFilter = Pick<\n ListFactsOptions,\n 'from' | 'to' | 'datedOnly' | 'tagExtIds' | 'docExtId'\n>\n\n/**\n * The facts of `workspaceId` (default: the open one), newest first, or the filtered ones\n * (`datedOnly` / a range: the timeline, by date; `tagExtIds`: the notes carrying all those tags).\n */\nexport function useFacts(\n workspaceId?: string | null,\n options?: FactListFilter & { enabled?: boolean }\n) {\n const arbi = useArbi()\n const { enabled = true, ...filter } = options ?? {}\n const workspace = factWorkspace(arbi, workspaceId)\n return useQuery({\n queryKey: arbiQueryKeys.factList(workspace, filter),\n // The request names the workspace, so a switch while it runs cannot answer for another.\n queryFn: (): Promise<FactResponse[]> => arbi.facts.list({ ...filter, workspaceId: workspace }),\n enabled: enabled && !!workspace && arbi.hasWorkspace,\n staleTime: 30_000,\n })\n}\n\n
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/**\n * Workspace facts (notes): a workspace's list, filtered for the timeline or by tag, the writes\n * (create, batch, patch, delete) and the search. List, create and search name their workspace (the\n * one given, else the open one, captured when they are sent); patch and delete act in the fact's\n * own workspace. Every write refreshes every cached fact list and the workspace's tags \u2014 a fact's\n * tags move the `facttag_count` the Tags page reads from the tag list.\n *\n * Requires an `ArbiHost` (with an `arbi`) and a React Query client above it.\n */\n\nimport { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'\nimport type {\n CreateFactRequest,\n CreateFactsRequest,\n FactResponse,\n FactSearchRequest,\n FactSearchResponse,\n ListFactsOptions,\n UpdateFactRequest,\n} from '@arbidocs/sdk/browser'\nimport { useArbi } from './useArbi'\nimport { arbiQueryKeys } from './hooks'\n\n/** The workspace a fact call names: the one given, else the one open now ('' when none is). */\nfunction factWorkspace(arbi: ReturnType<typeof useArbi>, workspaceId?: string | null): string {\n return workspaceId || (arbi.hasWorkspace ? arbi.getWorkspaceId() : '')\n}\n\n/** What a list asks for: the timeline range, or the notes carrying tags or citing a document. */\nexport type FactListFilter = Pick<\n ListFactsOptions,\n 'from' | 'to' | 'datedOnly' | 'tagExtIds' | 'docExtId'\n>\n\n/**\n * The facts of `workspaceId` (default: the open one), newest first, or the filtered ones\n * (`datedOnly` / a range: the timeline, by date; `tagExtIds`: the notes carrying all those tags).\n */\nexport function useFacts(\n workspaceId?: string | null,\n options?: FactListFilter & { enabled?: boolean }\n) {\n const arbi = useArbi()\n const { enabled = true, ...filter } = options ?? {}\n const workspace = factWorkspace(arbi, workspaceId)\n return useQuery({\n queryKey: arbiQueryKeys.factList(workspace, filter),\n // The request names the workspace, so a switch while it runs cannot answer for another.\n queryFn: (): Promise<FactResponse[]> => arbi.facts.list({ ...filter, workspaceId: workspace }),\n enabled: enabled && !!workspace && arbi.hasWorkspace,\n staleTime: 30_000,\n })\n}\n\n/**\n * Refresh every cached fact list after a write, and the tag lists: a fact's tags move the\n * `facttag_count` the Tags page shows, so the workspace's tags must re-read too.\n */\nfunction useRefreshFacts() {\n const qc = useQueryClient()\n return () =>\n Promise.all([\n qc.invalidateQueries({ queryKey: arbiQueryKeys.allFacts() }),\n qc.invalidateQueries({ queryKey: arbiQueryKeys.allTags() }),\n ])\n}\n\n/**\n * Add a fact (by hand it is confirmed: typing it is the vouch) to `workspaceId` (the message's or\n * the page's), else to the workspace open when it is sent.\n */\nexport function useCreateFact(workspaceId?: string | null) {\n const arbi = useArbi()\n const refresh = useRefreshFacts()\n return useMutation({\n mutationFn: (body: CreateFactRequest) =>\n arbi.facts.create(body, { workspaceId: factWorkspace(arbi, workspaceId) || undefined }),\n onSuccess: refresh,\n })\n}\n\n/**\n * Add several facts in one all-or-nothing request (an imported chronology, say) to `workspaceId`,\n * else to the workspace open when it is sent.\n */\nexport function useCreateFacts(workspaceId?: string | null) {\n const arbi = useArbi()\n const refresh = useRefreshFacts()\n return useMutation({\n mutationFn: (body: CreateFactsRequest) =>\n arbi.facts.createBatch(body, { workspaceId: factWorkspace(arbi, workspaceId) || undefined }),\n onSuccess: refresh,\n })\n}\n\n/**\n * Patch a fact. A text edit replaces the fact (the old one is kept as history); `shared` and\n * `confirmed` change in place.\n */\nexport function useUpdateFact() {\n const arbi = useArbi()\n const refresh = useRefreshFacts()\n return useMutation({\n mutationFn: ({ factId, patch }: { factId: string; patch: UpdateFactRequest }) =>\n arbi.facts.update(factId, patch),\n onSuccess: refresh,\n })\n}\n\n/** Delete a fact (only where the server allows it: a refused delete fails with its reason). */\nexport function useDeleteFact() {\n const arbi = useArbi()\n const refresh = useRefreshFacts()\n return useMutation({\n mutationFn: (factId: string) => arbi.facts.delete(factId),\n onSuccess: refresh,\n })\n}\n\n/**\n * Search the facts of `workspaceId` (default: the open one), hybrid by default, as the agent's fact\n * recall does. The workspace is captured when the search is sent and named on the request.\n */\nexport function useSearchFacts(workspaceId?: string | null) {\n const arbi = useArbi()\n return useMutation({\n mutationFn: (body: FactSearchRequest): Promise<FactSearchResponse> =>\n arbi.facts.search(body, { workspaceId: factWorkspace(arbi, workspaceId) || undefined }),\n })\n}\n"],
|
|
5
|
+
"mappings": "AAUA,SAAS,aAAa,UAAU,sBAAsB;AAUtD,SAAS,eAAe;AACxB,SAAS,qBAAqB;AAG9B,SAAS,cAAc,MAAkC,aAAqC;AAC5F,SAAO,gBAAgB,KAAK,eAAe,KAAK,eAAe,IAAI;AACrE;AAYO,SAAS,SACd,aACA,SACA;AACA,QAAM,OAAO,QAAQ;AACrB,QAAM,EAAE,UAAU,MAAM,GAAG,OAAO,IAAI,WAAW,CAAC;AAClD,QAAM,YAAY,cAAc,MAAM,WAAW;AACjD,SAAO,SAAS;AAAA,IACd,UAAU,cAAc,SAAS,WAAW,MAAM;AAAA;AAAA,IAElD,SAAS,MAA+B,KAAK,MAAM,KAAK,EAAE,GAAG,QAAQ,aAAa,UAAU,CAAC;AAAA,IAC7F,SAAS,WAAW,CAAC,CAAC,aAAa,KAAK;AAAA,IACxC,WAAW;AAAA,EACb,CAAC;AACH;AAMA,SAAS,kBAAkB;AACzB,QAAM,KAAK,eAAe;AAC1B,SAAO,MACL,QAAQ,IAAI;AAAA,IACV,GAAG,kBAAkB,EAAE,UAAU,cAAc,SAAS,EAAE,CAAC;AAAA,IAC3D,GAAG,kBAAkB,EAAE,UAAU,cAAc,QAAQ,EAAE,CAAC;AAAA,EAC5D,CAAC;AACL;AAMO,SAAS,cAAc,aAA6B;AACzD,QAAM,OAAO,QAAQ;AACrB,QAAM,UAAU,gBAAgB;AAChC,SAAO,YAAY;AAAA,IACjB,YAAY,CAAC,SACX,KAAK,MAAM,OAAO,MAAM,EAAE,aAAa,cAAc,MAAM,WAAW,KAAK,OAAU,CAAC;AAAA,IACxF,WAAW;AAAA,EACb,CAAC;AACH;AAMO,SAAS,eAAe,aAA6B;AAC1D,QAAM,OAAO,QAAQ;AACrB,QAAM,UAAU,gBAAgB;AAChC,SAAO,YAAY;AAAA,IACjB,YAAY,CAAC,SACX,KAAK,MAAM,YAAY,MAAM,EAAE,aAAa,cAAc,MAAM,WAAW,KAAK,OAAU,CAAC;AAAA,IAC7F,WAAW;AAAA,EACb,CAAC;AACH;AAMO,SAAS,gBAAgB;AAC9B,QAAM,OAAO,QAAQ;AACrB,QAAM,UAAU,gBAAgB;AAChC,SAAO,YAAY;AAAA,IACjB,YAAY,CAAC,EAAE,QAAQ,MAAM,MAC3B,KAAK,MAAM,OAAO,QAAQ,KAAK;AAAA,IACjC,WAAW;AAAA,EACb,CAAC;AACH;AAGO,SAAS,gBAAgB;AAC9B,QAAM,OAAO,QAAQ;AACrB,QAAM,UAAU,gBAAgB;AAChC,SAAO,YAAY;AAAA,IACjB,YAAY,CAAC,WAAmB,KAAK,MAAM,OAAO,MAAM;AAAA,IACxD,WAAW;AAAA,EACb,CAAC;AACH;AAMO,SAAS,eAAe,aAA6B;AAC1D,QAAM,OAAO,QAAQ;AACrB,SAAO,YAAY;AAAA,IACjB,YAAY,CAAC,SACX,KAAK,MAAM,OAAO,MAAM,EAAE,aAAa,cAAc,MAAM,WAAW,KAAK,OAAU,CAAC;AAAA,EAC1F,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -1730,9 +1730,9 @@ function useWorkspaceProcessing(workspaceId) {
|
|
|
1730
1730
|
React.useEffect(() => {
|
|
1731
1731
|
if (!workspaceId) return;
|
|
1732
1732
|
const store2 = chunkPDE246CA_cjs.useArbiWsStore.getState();
|
|
1733
|
-
const
|
|
1734
|
-
store2.settleTasks(
|
|
1735
|
-
const listed = new Set(
|
|
1733
|
+
const documents3 = chunkPDE246CA_cjs.getCachedDocuments(queryClient, workspaceId) ?? [];
|
|
1734
|
+
store2.settleTasks(documents3);
|
|
1735
|
+
const listed = new Set(documents3.map((d) => d.external_id));
|
|
1736
1736
|
const now = Date.now();
|
|
1737
1737
|
for (const task of Object.values(chunkPDE246CA_cjs.useArbiWsStore.getState().tasks)) {
|
|
1738
1738
|
if (task.workspace_ext_id !== workspaceId || !chunkPDE246CA_cjs.IN_FLIGHT_DOCUMENT_STATUSES.has(task.status))
|
|
@@ -1740,7 +1740,7 @@ function useWorkspaceProcessing(workspaceId) {
|
|
|
1740
1740
|
const since = task.startTime ?? task.endTime;
|
|
1741
1741
|
const age = since == null ? null : now - since;
|
|
1742
1742
|
const stale = age != null && age > STALE_TASK_MS;
|
|
1743
|
-
const orphan =
|
|
1743
|
+
const orphan = documents3.length > 0 && !listed.has(task.doc_ext_id) && age != null && age > ORPHAN_TASK_MS;
|
|
1744
1744
|
if (stale || orphan) store2.clearTask(task.doc_ext_id);
|
|
1745
1745
|
}
|
|
1746
1746
|
}, [workspaceId, queryClient]);
|
|
@@ -1985,7 +1985,7 @@ function useUpdateDocuments() {
|
|
|
1985
1985
|
input.workspaceId,
|
|
1986
1986
|
() => arbi.documents.update(input.documents)
|
|
1987
1987
|
),
|
|
1988
|
-
onMutate: ({ documents:
|
|
1988
|
+
onMutate: ({ documents: documents3 }) => reactQuery.onlineManager.isOnline() || !documents3.length ? void 0 : applyOptimisticDocumentEdit(qc, documents3),
|
|
1989
1989
|
// Not sent because its workspace can't be opened: the edit stays, listed as not sent.
|
|
1990
1990
|
onError: (error, _input, context) => {
|
|
1991
1991
|
if (!chunkPDE246CA_cjs.isWorkspaceUnavailable(error)) rollbackOptimisticDocumentEdit(qc, context);
|
|
@@ -2004,7 +2004,7 @@ function useRenameFolder() {
|
|
|
2004
2004
|
const qc = reactQuery.useQueryClient();
|
|
2005
2005
|
const { mutateAsync } = useUpdateDocuments();
|
|
2006
2006
|
return React.useCallback(
|
|
2007
|
-
async (
|
|
2007
|
+
async (documents3, from, to) => {
|
|
2008
2008
|
const moved = (folder) => {
|
|
2009
2009
|
const segments = folderSegments(folder);
|
|
2010
2010
|
if (from.length === 0 || segments.length < from.length) return void 0;
|
|
@@ -2012,7 +2012,7 @@ function useRenameFolder() {
|
|
|
2012
2012
|
const next = [...to, ...segments.slice(from.length)];
|
|
2013
2013
|
return next.length > 0 ? next.join("/") : null;
|
|
2014
2014
|
};
|
|
2015
|
-
const updates =
|
|
2015
|
+
const updates = documents3.flatMap((doc) => {
|
|
2016
2016
|
const folder = moved(doc.folder);
|
|
2017
2017
|
return folder === void 0 ? [] : [{ external_id: doc.external_id, folder }];
|
|
2018
2018
|
});
|
|
@@ -2133,11 +2133,11 @@ function useUpdateDocTag() {
|
|
|
2133
2133
|
)
|
|
2134
2134
|
);
|
|
2135
2135
|
}
|
|
2136
|
-
function queueProcessing(
|
|
2136
|
+
function queueProcessing(documents3) {
|
|
2137
2137
|
const store2 = chunkPDE246CA_cjs.useArbiWsStore.getState();
|
|
2138
|
-
const previous =
|
|
2138
|
+
const previous = documents3.map(({ docId }) => [docId, store2.tasks[docId]]);
|
|
2139
2139
|
const now = Date.now();
|
|
2140
|
-
for (const doc of
|
|
2140
|
+
for (const doc of documents3)
|
|
2141
2141
|
store2.putTask({
|
|
2142
2142
|
doc_ext_id: doc.docId,
|
|
2143
2143
|
workspace_ext_id: doc.workspaceId,
|
|
@@ -2236,9 +2236,9 @@ var COLUMN_MAPPING = {
|
|
|
2236
2236
|
file_size: { header: "File Size", getValue: (d) => d.file_size || "" },
|
|
2237
2237
|
shared: { header: "Shared", getValue: (d) => d.shared ? "Yes" : "No" }
|
|
2238
2238
|
};
|
|
2239
|
-
function buildDocumentMetadataRows(
|
|
2239
|
+
function buildDocumentMetadataRows(documents3, selectedColumns) {
|
|
2240
2240
|
const columns = selectedColumns || Object.keys(COLUMN_MAPPING);
|
|
2241
|
-
return
|
|
2241
|
+
return documents3.map((doc) => {
|
|
2242
2242
|
const row = {};
|
|
2243
2243
|
for (const colId of columns) {
|
|
2244
2244
|
const standard = COLUMN_MAPPING[colId];
|
|
@@ -2270,9 +2270,9 @@ function useDownloadDocuments({ workspaceName } = {}) {
|
|
|
2270
2270
|
);
|
|
2271
2271
|
const downloadDocuments = React.useCallback(
|
|
2272
2272
|
// selectedColumns: undefined = all default columns; [] = files only (no index.csv)
|
|
2273
|
-
async (
|
|
2273
|
+
async (documents3, selectedColumns) => {
|
|
2274
2274
|
const includeMetadataCsv = selectedColumns === void 0 || selectedColumns.length > 0;
|
|
2275
|
-
if (
|
|
2275
|
+
if (documents3.length === 0) {
|
|
2276
2276
|
chunkIX4HOS5Z_cjs.notify.error("No documents to download");
|
|
2277
2277
|
return;
|
|
2278
2278
|
}
|
|
@@ -2282,7 +2282,7 @@ function useDownloadDocuments({ workspaceName } = {}) {
|
|
|
2282
2282
|
const zip = new JSZip();
|
|
2283
2283
|
const downloaded = [];
|
|
2284
2284
|
const failedDocs = [];
|
|
2285
|
-
for (const doc of
|
|
2285
|
+
for (const doc of documents3) {
|
|
2286
2286
|
try {
|
|
2287
2287
|
const file = await fetchNamedFile(doc);
|
|
2288
2288
|
zip.file(file.name, file.blob);
|
|
@@ -3307,7 +3307,7 @@ function uploadFolderOf(file, base) {
|
|
|
3307
3307
|
const own = slash > 0 ? relative.slice(0, slash) : "";
|
|
3308
3308
|
return sanitizeFolderPath([base, own].filter(Boolean).join("/")) || null;
|
|
3309
3309
|
}
|
|
3310
|
-
var { mimeFromName: mimeFromName2 } = browser.documents;
|
|
3310
|
+
var { mimeFromName: mimeFromName2, newUploadSet } = browser.documents;
|
|
3311
3311
|
var BATCH_SIZE2 = 100;
|
|
3312
3312
|
var CONCURRENT_BATCHES = 4;
|
|
3313
3313
|
var uploadedFolders = /* @__PURE__ */ new Map();
|
|
@@ -3357,6 +3357,7 @@ function useUploadFiles() {
|
|
|
3357
3357
|
workspaceKey = null;
|
|
3358
3358
|
}
|
|
3359
3359
|
}
|
|
3360
|
+
const uploadSet = newUploadSet(input.files.length);
|
|
3360
3361
|
const total = input.files.reduce((sum, file) => sum + file.size, 0);
|
|
3361
3362
|
const loadedByBatch = new Array(batches.length).fill(0);
|
|
3362
3363
|
const filesByBatch = new Array(batches.length).fill(0);
|
|
@@ -3384,6 +3385,7 @@ function useUploadFiles() {
|
|
|
3384
3385
|
configExtId: input.configExtId ?? void 0,
|
|
3385
3386
|
// Named even when it is the open one: batches sent after a switch stay in this workspace.
|
|
3386
3387
|
workspaceExtId: workspaceId,
|
|
3388
|
+
uploadSet,
|
|
3387
3389
|
// One request for the batch: its files count by the share of its bytes sent.
|
|
3388
3390
|
onProgress: (loaded) => {
|
|
3389
3391
|
loadedByBatch[index] = Math.min(loaded, bytes);
|
|
@@ -3406,6 +3408,7 @@ function useUploadFiles() {
|
|
|
3406
3408
|
shared: input.shared,
|
|
3407
3409
|
folder: folder ?? void 0,
|
|
3408
3410
|
configExtId: input.configExtId ?? void 0,
|
|
3411
|
+
uploadSet,
|
|
3409
3412
|
// Per file, in ciphertext bytes: that file's share sent, scaled back to its own
|
|
3410
3413
|
// size so the byte total stays true.
|
|
3411
3414
|
onBytesProgress: ({ fileIndex, loaded, total: sent }) => {
|
|
@@ -3534,11 +3537,11 @@ function getRelatedLabels(related) {
|
|
|
3534
3537
|
}
|
|
3535
3538
|
return parts;
|
|
3536
3539
|
}
|
|
3537
|
-
function useRelatedDocuments(
|
|
3540
|
+
function useRelatedDocuments(documents3) {
|
|
3538
3541
|
const { data: similarData } = chunkPDE246CA_cjs.useSimilarDocuments();
|
|
3539
3542
|
const structuralKey = React.useMemo(() => {
|
|
3540
3543
|
const parts = [];
|
|
3541
|
-
for (const doc of
|
|
3544
|
+
for (const doc of documents3) {
|
|
3542
3545
|
parts.push(doc.external_id);
|
|
3543
3546
|
parts.push(doc.parent_ext_id || "");
|
|
3544
3547
|
parts.push(doc.content_hash || "");
|
|
@@ -3547,17 +3550,17 @@ function useRelatedDocuments(documents2) {
|
|
|
3547
3550
|
parts.push(source.doc_ext_id, source.role, String(source.version ?? ""));
|
|
3548
3551
|
}
|
|
3549
3552
|
return parts.join("|");
|
|
3550
|
-
}, [
|
|
3553
|
+
}, [documents3]);
|
|
3551
3554
|
const prevKeyRef = React.useRef(structuralKey);
|
|
3552
3555
|
const prevMapRef = React.useRef(/* @__PURE__ */ new Map());
|
|
3553
|
-
const prevDocsRef = React.useRef(
|
|
3556
|
+
const prevDocsRef = React.useRef(documents3);
|
|
3554
3557
|
const prevSimilarRef = React.useRef(similarData);
|
|
3555
3558
|
return React.useMemo(() => {
|
|
3556
|
-
if (prevKeyRef.current === structuralKey && prevSimilarRef.current === similarData && prevMapRef.current.size > 0 && prevDocsRef.current ===
|
|
3559
|
+
if (prevKeyRef.current === structuralKey && prevSimilarRef.current === similarData && prevMapRef.current.size > 0 && prevDocsRef.current === documents3) {
|
|
3557
3560
|
return prevMapRef.current;
|
|
3558
3561
|
}
|
|
3559
3562
|
prevKeyRef.current = structuralKey;
|
|
3560
|
-
prevDocsRef.current =
|
|
3563
|
+
prevDocsRef.current = documents3;
|
|
3561
3564
|
prevSimilarRef.current = similarData;
|
|
3562
3565
|
const map = /* @__PURE__ */ new Map();
|
|
3563
3566
|
const getOrCreate = (docId) => {
|
|
@@ -3569,18 +3572,18 @@ function useRelatedDocuments(documents2) {
|
|
|
3569
3572
|
return entry;
|
|
3570
3573
|
};
|
|
3571
3574
|
const docById = /* @__PURE__ */ new Map();
|
|
3572
|
-
for (const doc of
|
|
3575
|
+
for (const doc of documents3) {
|
|
3573
3576
|
docById.set(doc.external_id, doc);
|
|
3574
3577
|
}
|
|
3575
3578
|
const byHash = /* @__PURE__ */ new Map();
|
|
3576
|
-
for (const doc of
|
|
3579
|
+
for (const doc of documents3) {
|
|
3577
3580
|
if (doc.content_hash) {
|
|
3578
3581
|
const list = byHash.get(doc.content_hash) || [];
|
|
3579
3582
|
list.push(doc);
|
|
3580
3583
|
byHash.set(doc.content_hash, list);
|
|
3581
3584
|
}
|
|
3582
3585
|
}
|
|
3583
|
-
for (const doc of
|
|
3586
|
+
for (const doc of documents3) {
|
|
3584
3587
|
if (doc.parent_ext_id) {
|
|
3585
3588
|
const parent = docById.get(doc.parent_ext_id);
|
|
3586
3589
|
if (parent) {
|
|
@@ -3589,7 +3592,7 @@ function useRelatedDocuments(documents2) {
|
|
|
3589
3592
|
}
|
|
3590
3593
|
}
|
|
3591
3594
|
}
|
|
3592
|
-
for (const doc of
|
|
3595
|
+
for (const doc of documents3) {
|
|
3593
3596
|
for (const source of doc.derived_from ?? []) {
|
|
3594
3597
|
const from = docById.get(source.doc_ext_id);
|
|
3595
3598
|
if (!from) continue;
|
|
@@ -3632,7 +3635,7 @@ function useRelatedDocuments(documents2) {
|
|
|
3632
3635
|
}
|
|
3633
3636
|
prevMapRef.current = map;
|
|
3634
3637
|
return map;
|
|
3635
|
-
}, [
|
|
3638
|
+
}, [documents3, similarData, structuralKey]);
|
|
3636
3639
|
}
|
|
3637
3640
|
var REPLAYABLE = [
|
|
3638
3641
|
...chunkPDE246CA_cjs.replayableTagMutations,
|
|
@@ -3794,7 +3797,7 @@ var PENDING_SYNC_PREDICATE = (m) => (
|
|
|
3794
3797
|
isReplayableArbiMutation(m.options.mutationKey) && (m.state.isPaused || m.state.status === "error" || chunkPDE246CA_cjs.isBlockedOnWorkspace(m))
|
|
3795
3798
|
);
|
|
3796
3799
|
function usePendingSyncItems() {
|
|
3797
|
-
const { data:
|
|
3800
|
+
const { data: documents3 } = chunkPDE246CA_cjs.useDocuments();
|
|
3798
3801
|
const { data: tags } = chunkZZZYVNFW_cjs.useTags();
|
|
3799
3802
|
const raw = reactQuery.useMutationState({
|
|
3800
3803
|
filters: { predicate: PENDING_SYNC_PREDICATE },
|
|
@@ -3810,12 +3813,12 @@ function usePendingSyncItems() {
|
|
|
3810
3813
|
});
|
|
3811
3814
|
return React.useMemo(() => {
|
|
3812
3815
|
const docNameById = /* @__PURE__ */ new Map();
|
|
3813
|
-
for (const doc of
|
|
3816
|
+
for (const doc of documents3 ?? [])
|
|
3814
3817
|
docNameById.set(doc.external_id, chunk4NGWDVHD_cjs.getDocumentTitle(doc, doc.file_name ?? ""));
|
|
3815
3818
|
const tagNameById = /* @__PURE__ */ new Map();
|
|
3816
3819
|
for (const tag of tags ?? []) tagNameById.set(tag.external_id, tag.name);
|
|
3817
3820
|
return raw.map((r) => buildPendingSyncItem(r, docNameById, tagNameById));
|
|
3818
|
-
}, [raw,
|
|
3821
|
+
}, [raw, documents3, tags]);
|
|
3819
3822
|
}
|
|
3820
3823
|
function usePendingSyncCounts() {
|
|
3821
3824
|
const statuses = reactQuery.useMutationState({
|
|
@@ -4279,10 +4282,10 @@ function createStreamHandlers(ctx, params) {
|
|
|
4279
4282
|
chunkIX4HOS5Z_cjs.recordChatArtifact(artifact, streamState.conversationId);
|
|
4280
4283
|
host.onArtifact?.(artifact, streamState.conversationId);
|
|
4281
4284
|
if (artifact.is_complete) {
|
|
4282
|
-
const
|
|
4283
|
-
if (!
|
|
4285
|
+
const documents3 = session.getState().conversationDocuments[streamState.conversationId] ?? [];
|
|
4286
|
+
if (!documents3.some((d) => d.docId === artifact.doc_ext_id))
|
|
4284
4287
|
session.setConversationDocuments(streamState.conversationId, [
|
|
4285
|
-
...
|
|
4288
|
+
...documents3,
|
|
4286
4289
|
{ docId: artifact.doc_ext_id, isPinned: false }
|
|
4287
4290
|
]);
|
|
4288
4291
|
if (artifact.mode === "html" || artifact.mode === "react")
|
|
@@ -5116,9 +5119,9 @@ function useConversationData() {
|
|
|
5116
5119
|
selectThread(session, firstThreadId);
|
|
5117
5120
|
const history = defaultThread?.history || [];
|
|
5118
5121
|
const key = session.getState().conversationId || "new";
|
|
5119
|
-
const
|
|
5120
|
-
if (
|
|
5121
|
-
session.setConversationDocuments(key,
|
|
5122
|
+
const documents3 = browser.extractDocumentIdsFromMessages(history);
|
|
5123
|
+
if (documents3.length > 0 && session.getState().conversationDocuments[key] === void 0)
|
|
5124
|
+
session.setConversationDocuments(key, documents3);
|
|
5122
5125
|
const factIds = browser.extractFactIdsFromMessages(history);
|
|
5123
5126
|
if (factIds && factIds.length > 0) session.setConversationFacts(key, factIds);
|
|
5124
5127
|
}
|
|
@@ -5634,7 +5637,7 @@ function useConversation(options = {}) {
|
|
|
5634
5637
|
() => (agentId ? [] : docs).map((d) => d.external_id).filter((id) => !!id && !deselected.has(id)),
|
|
5635
5638
|
[docs, deselected, agentId]
|
|
5636
5639
|
);
|
|
5637
|
-
const
|
|
5640
|
+
const documents3 = React.useMemo(
|
|
5638
5641
|
() => agentId ? stagedFiles.map((file) => ({ ...file, isSelected: !deselected.has(file.id) })) : docs.filter((d) => !!d.external_id).map((d) => ({
|
|
5639
5642
|
id: d.external_id,
|
|
5640
5643
|
name: d.file_name ?? d.external_id,
|
|
@@ -5846,7 +5849,7 @@ function useConversation(options = {}) {
|
|
|
5846
5849
|
isLoadingThread: !!conversationId && threadsLoading && !threadsError,
|
|
5847
5850
|
isLoadingThreads,
|
|
5848
5851
|
historyError: historyError ?? (threadsError ? messageOf(threadsError, "The conversation could not be loaded.") : null),
|
|
5849
|
-
documents:
|
|
5852
|
+
documents: documents3,
|
|
5850
5853
|
isLoadingDocuments,
|
|
5851
5854
|
isUploading,
|
|
5852
5855
|
uploadError,
|
|
@@ -6056,12 +6059,12 @@ function useConversationDocuments() {
|
|
|
6056
6059
|
const inConversationDocuments = chunkZZZYVNFW_cjs.useArbiSessionState(
|
|
6057
6060
|
(state) => state.conversationDocuments[convKey] || EMPTY_DOCS
|
|
6058
6061
|
);
|
|
6059
|
-
const { data:
|
|
6062
|
+
const { data: documents3 = [], isLoading: isLoadingDocs } = chunkPDE246CA_cjs.useDocuments();
|
|
6060
6063
|
const conversationDocuments = React__default.default.useMemo(() => {
|
|
6061
6064
|
if (inConversationDocuments.length === 0) {
|
|
6062
6065
|
return [];
|
|
6063
6066
|
}
|
|
6064
|
-
const docArray = Array.isArray(
|
|
6067
|
+
const docArray = Array.isArray(documents3) ? documents3 : [];
|
|
6065
6068
|
const conversationDocMap = new Map(
|
|
6066
6069
|
inConversationDocuments.map((doc) => [doc.docId, doc.isPinned])
|
|
6067
6070
|
);
|
|
@@ -6076,7 +6079,7 @@ function useConversationDocuments() {
|
|
|
6076
6079
|
return conversationDocMap.has(docId);
|
|
6077
6080
|
});
|
|
6078
6081
|
return filteredDocs;
|
|
6079
|
-
}, [
|
|
6082
|
+
}, [documents3, inConversationDocuments]);
|
|
6080
6083
|
return {
|
|
6081
6084
|
data: conversationDocuments,
|
|
6082
6085
|
isLoading: isLoadingDocs,
|
|
@@ -9550,7 +9553,7 @@ function useWorkspaceExportDownload({
|
|
|
9550
9553
|
const arbi = chunkFE6ZSNZE_cjs.useArbi();
|
|
9551
9554
|
const [progress, setProgress] = React.useState(null);
|
|
9552
9555
|
const download = React.useCallback(
|
|
9553
|
-
async ({ scope, documents:
|
|
9556
|
+
async ({ scope, documents: documents3 = [], csvColumns }) => {
|
|
9554
9557
|
setProgress({ done: 0, total: 0 });
|
|
9555
9558
|
try {
|
|
9556
9559
|
const data = await arbi.workspaces.transfer.exportData(
|
|
@@ -9562,7 +9565,7 @@ function useWorkspaceExportDownload({
|
|
|
9562
9565
|
const exported = new Set(
|
|
9563
9566
|
(data.files ?? []).filter((f) => !f.markup).map((f) => f.doc_ext_id)
|
|
9564
9567
|
);
|
|
9565
|
-
const rows =
|
|
9568
|
+
const rows = documents3.filter((d) => exported.has(d.external_id));
|
|
9566
9569
|
if (rows.length > 0) {
|
|
9567
9570
|
const Papa = (await import('papaparse')).default;
|
|
9568
9571
|
metadataCsv = Papa.unparse(buildDocumentMetadataRows(rows, csvColumns));
|
|
@@ -9687,7 +9690,10 @@ function useFacts(workspaceId, options) {
|
|
|
9687
9690
|
}
|
|
9688
9691
|
function useRefreshFacts() {
|
|
9689
9692
|
const qc = reactQuery.useQueryClient();
|
|
9690
|
-
return () =>
|
|
9693
|
+
return () => Promise.all([
|
|
9694
|
+
qc.invalidateQueries({ queryKey: chunkFE6ZSNZE_cjs.arbiQueryKeys.allFacts() }),
|
|
9695
|
+
qc.invalidateQueries({ queryKey: chunkFE6ZSNZE_cjs.arbiQueryKeys.allTags() })
|
|
9696
|
+
]);
|
|
9691
9697
|
}
|
|
9692
9698
|
function useCreateFact(workspaceId) {
|
|
9693
9699
|
const arbi = chunkFE6ZSNZE_cjs.useArbi();
|
|
@@ -15887,6 +15893,35 @@ function parse(content) {
|
|
|
15887
15893
|
return null;
|
|
15888
15894
|
}
|
|
15889
15895
|
}
|
|
15896
|
+
function uploadSetMeta(content) {
|
|
15897
|
+
const meta = parse(content) ?? {};
|
|
15898
|
+
const count = (key) => {
|
|
15899
|
+
const value = meta[key];
|
|
15900
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : 0;
|
|
15901
|
+
};
|
|
15902
|
+
const ids2 = Array.isArray(meta.failed_doc_ext_ids) ? meta.failed_doc_ext_ids : [];
|
|
15903
|
+
return {
|
|
15904
|
+
total: count("total"),
|
|
15905
|
+
completed: count("completed"),
|
|
15906
|
+
failed: count("failed"),
|
|
15907
|
+
failedDocumentIds: ids2.filter(
|
|
15908
|
+
(id) => typeof id === "string" && DOCUMENT_ID.test(id)
|
|
15909
|
+
),
|
|
15910
|
+
refused: count("refused"),
|
|
15911
|
+
notUploaded: count("not_uploaded")
|
|
15912
|
+
};
|
|
15913
|
+
}
|
|
15914
|
+
var documents2 = (n) => `${n} document${n === 1 ? "" : "s"}`;
|
|
15915
|
+
function uploadSetTitle(content) {
|
|
15916
|
+
const { total, completed, failed, refused, notUploaded } = uploadSetMeta(content);
|
|
15917
|
+
const parts = [
|
|
15918
|
+
completed === total || total === 0 ? `${documents2(completed)} indexed` : `${completed} of ${documents2(total)} indexed`
|
|
15919
|
+
];
|
|
15920
|
+
if (failed) parts.push(`${failed} failed`);
|
|
15921
|
+
if (refused) parts.push(`${refused} skipped`);
|
|
15922
|
+
if (notUploaded) parts.push(`${notUploaded} not uploaded`);
|
|
15923
|
+
return parts.join(" \xB7 ");
|
|
15924
|
+
}
|
|
15890
15925
|
function inputRequestTitle(content) {
|
|
15891
15926
|
const metadata = parse(content);
|
|
15892
15927
|
if (!metadata) return "ARBI needs your input \u2014 open the thread to reply";
|
|
@@ -16075,6 +16110,25 @@ function describeServerNotification(n, options = {}) {
|
|
|
16075
16110
|
target: { kind: "url", url: `/shared-files/${id}` }
|
|
16076
16111
|
};
|
|
16077
16112
|
}
|
|
16113
|
+
// One upload action finished (however many batches it was sent and processed in). A failed
|
|
16114
|
+
// document is where it leads when there is one; otherwise the workspace.
|
|
16115
|
+
case "upload_set_complete": {
|
|
16116
|
+
const meta = uploadSetMeta(n.content);
|
|
16117
|
+
const problems = meta.failed + meta.notUploaded;
|
|
16118
|
+
const failed = meta.failedDocumentIds;
|
|
16119
|
+
return {
|
|
16120
|
+
title: uploadSetTitle(n.content),
|
|
16121
|
+
variant: problems ? "warning" : "success",
|
|
16122
|
+
...failed.length === 1 ? {
|
|
16123
|
+
actionLabel: "Open failed document",
|
|
16124
|
+
target: {
|
|
16125
|
+
kind: "document",
|
|
16126
|
+
workspaceId: n.workspace_ext_id ?? void 0,
|
|
16127
|
+
documentId: failed[0]
|
|
16128
|
+
}
|
|
16129
|
+
} : { target: workspace }
|
|
16130
|
+
};
|
|
16131
|
+
}
|
|
16078
16132
|
case "call_missed":
|
|
16079
16133
|
return {
|
|
16080
16134
|
title: `Missed call from ${senderName}`,
|