@arbidocs/react 0.5.146 → 0.5.147
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/artifacts/index.cjs +14 -14
- package/dist/calls/livekit/index.cjs +48 -48
- package/dist/chat/conversation-cache.js +5 -0
- package/dist/chat/conversation-cache.js.map +2 -2
- package/dist/chat/useConversation.js +10 -5
- package/dist/chat/useConversation.js.map +2 -2
- package/dist/chat/useConversationActions.js +4 -0
- package/dist/chat/useConversationActions.js.map +2 -2
- package/dist/chat/useConversationSettings.js +4 -10
- package/dist/chat/useConversationSettings.js.map +2 -2
- package/dist/{chunk-FE6ZSNZE.cjs → chunk-5FQB5F2F.cjs} +9 -4
- package/dist/chunk-5FQB5F2F.cjs.map +1 -0
- package/dist/{chunk-2F24LLVZ.cjs → chunk-MHYTO2EX.cjs} +38 -38
- package/dist/{chunk-2F24LLVZ.cjs.map → chunk-MHYTO2EX.cjs.map} +1 -1
- package/dist/{chunk-26SZ3DS4.cjs → chunk-MJIXYLI4.cjs} +66 -66
- package/dist/{chunk-26SZ3DS4.cjs.map → chunk-MJIXYLI4.cjs.map} +1 -1
- package/dist/{chunk-ZZZYVNFW.cjs → chunk-VBUEDJMK.cjs} +57 -57
- package/dist/{chunk-ZZZYVNFW.cjs.map → chunk-VBUEDJMK.cjs.map} +1 -1
- package/dist/{chunk-FDYZA6NO.cjs → chunk-XBY4RLC6.cjs} +4 -4
- package/dist/{chunk-FDYZA6NO.cjs.map → chunk-XBY4RLC6.cjs.map} +1 -1
- package/dist/{chunk-VO7OWQP6.cjs → chunk-ZFTWH6B6.cjs} +44 -44
- package/dist/{chunk-VO7OWQP6.cjs.map → chunk-ZFTWH6B6.cjs.map} +1 -1
- package/dist/databases.js +9 -6
- package/dist/databases.js.map +2 -2
- package/dist/datasets/index.js +25 -21
- package/dist/datasets/index.js.map +2 -2
- package/dist/datasets/pages.js +208 -0
- package/dist/datasets/pages.js.map +7 -0
- package/dist/datasets/registry.js.map +2 -2
- package/dist/datasets/sources/database.js +21 -23
- package/dist/datasets/sources/database.js.map +2 -2
- package/dist/document-tools/core.cjs +98 -98
- package/dist/document-tools/core.d.ts +2 -2
- package/dist/document-tools/index.cjs +100 -100
- package/dist/document-tools/index.d.ts +1 -1
- package/dist/documents/documents-writes.js +45 -14
- package/dist/documents/documents-writes.js.map +2 -2
- package/dist/documents/index.js +8 -0
- package/dist/documents/index.js.map +2 -2
- package/dist/documents/tag-when-processed.js +47 -0
- package/dist/documents/tag-when-processed.js.map +7 -0
- package/dist/host/config.js.map +1 -1
- package/dist/index.cjs +1880 -1583
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +319 -97
- package/dist/index.js +27 -5
- package/dist/index.js.map +2 -2
- package/dist/notifications/notification-types.js +7 -0
- package/dist/notifications/notification-types.js.map +2 -2
- package/dist/notifications/server-notifications.js +66 -10
- package/dist/notifications/server-notifications.js.map +2 -2
- package/dist/{query-keys.d-d2M4FAq2.d.ts → query-keys.d-pgq-4jyZ.d.ts} +7 -2
- package/dist/query-keys.js +7 -2
- package/dist/query-keys.js.map +2 -2
- package/dist/table-views.js +166 -0
- package/dist/table-views.js.map +7 -0
- package/package.json +3 -3
- package/dist/account/table-views.js +0 -16
- package/dist/account/table-views.js.map +0 -7
- package/dist/chunk-FE6ZSNZE.cjs.map +0 -1
- package/dist/datasets/store.js +0 -194
- package/dist/datasets/store.js.map +0 -7
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/documents/documents-writes.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Writing documents: field edits, deletion, uploads (files and URLs), and their tags (applying,\n * removing, re-noting, filling them with AI). Every write patches the caches that show its\n * documents in place (the workspace list, each document's own entry, the tag counts) instead of\n * re-reading a list that can be 100k documents long.\n *\n * Offline: field edits and tag applications / removals / notes pause and are sent on reconnect.\n * While queued, a field edit already shows (it is applied to the cache, and undone if the send\n * fails or the change is cancelled: {@link rollbackOptimisticDocumentEdit}), and awaiting one\n * resolves at once rather than when the connection is back. A host that persists its query cache\n * keeps them across a reload by registering `registerArbiMutationDefaults` (`offline.ts`).\n */\n\nimport { useCallback } from 'react'\nimport { onlineManager, useMutation, useQueryClient, type QueryClient } from '@tanstack/react-query'\nimport type { ArbiClient, components } from '@arbidocs/client'\nimport {\n documents as documentOps,\n doctags as doctagOps,\n type Arbi,\n type UploadDocumentsOptions,\n type UploadResult,\n} from '@arbidocs/sdk/browser'\nimport { useArbi } from '../useArbi'\nimport { arbiMutationKeys, arbiQueryKeys } from '../hooks'\nimport {\n forgetDocuments,\n getCachedDocuments,\n patchCachedDocument,\n patchDocuments,\n setCachedDocument,\n type WorkspaceDocument,\n} from './documents-cache'\nimport { adjustTagCounts, refreshDocuments } from './documents-data'\nimport { useArbiWsStore, type LiveTask } from '../websocket/store'\nimport {\n QUEUED_WRITE_RETRY,\n inWorkspace,\n isWorkspaceUnavailable,\n primeOnArbi,\n primeOnClient,\n useCapturingWorkspace,\n type QueuedWriteWorkspace,\n} from '../queued-writes'\n\ntype DocUpdate = components['schemas']['DocUpdateRequest']\ntype DocTag = components['schemas']['DocTagResponse']\ntype CitationSources = components['schemas']['CitationSources']\n\n/** A field edit: the documents' ids with the fields that change (folder, sharing, metadata, \u2026). */\nexport interface UpdateDocumentsInput extends QueuedWriteWorkspace {\n documents: DocUpdate[]\n}\n\n/** Applying a tag to documents (with a note, e.g. a field's value, and the passages it cites). */\nexport interface AssignDocTagsInput extends QueuedWriteWorkspace {\n tagId: string\n docIds: string[]\n note?: string | null\n citations?: CitationSources | null\n}\n\n/** Removing a tag from documents. */\nexport interface RemoveDocTagsInput extends QueuedWriteWorkspace {\n tagId: string\n docIds: string[]\n}\n\n/** Changing the note (or its cited passages) of a tag on one document. */\nexport interface UpdateDocTagInput extends QueuedWriteWorkspace {\n tagId: string\n docId: string\n note?: string | null\n citations?: CitationSources | null\n}\n\n/**\n * Snapshot taken when a queued field edit was applied to the cache; restoring it undoes the edit.\n * It is the mutation's context, so a host's list of pending changes can undo one.\n */\nexport interface OptimisticDocumentEdit {\n optimistic: true\n previous: WorkspaceDocument[]\n previousOwn: Array<[string, WorkspaceDocument | null | undefined]>\n}\n\n/**\n * Show a queued field edit in the caches at once (offline only: online, the server's answer is the\n * one source). A second edit of the same document layers on the first, so undoing the later one\n * restores the earlier one.\n */\nexport function applyOptimisticDocumentEdit(\n qc: QueryClient,\n updates: DocUpdate[]\n): OptimisticDocumentEdit {\n const byId = new Map(updates.map((update) => [update.external_id, update]))\n const previous: WorkspaceDocument[] = []\n patchDocuments(qc, (old) => {\n let changed = false\n const next = old.map((doc) => {\n const update = byId.get(doc.external_id)\n if (!update) return doc\n changed = true\n previous.push(doc)\n return { ...doc, ...update } as WorkspaceDocument\n })\n return changed ? next : old\n })\n const previousOwn = updates.map((update): [string, WorkspaceDocument | null | undefined] => {\n const own = qc.getQueryData<WorkspaceDocument | null>(\n arbiQueryKeys.document(update.external_id)\n )\n if (own) setCachedDocument(qc, { ...own, ...update } as WorkspaceDocument)\n return [update.external_id, own]\n })\n return { optimistic: true, previous, previousOwn }\n}\n\n/** Undo {@link applyOptimisticDocumentEdit} from its snapshot (anything else: nothing to undo). */\nexport function rollbackOptimisticDocumentEdit(qc: QueryClient, context: unknown): void {\n const edit = context as OptimisticDocumentEdit | undefined\n if (!edit?.optimistic) return\n if (edit.previous.length) {\n const restore = new Map(edit.previous.map((doc) => [doc.external_id, doc]))\n patchDocuments(qc, (old) =>\n old.some((doc) => restore.has(doc.external_id))\n ? old.map((doc) => restore.get(doc.external_id) ?? doc)\n : old\n )\n }\n for (const [id, own] of edit.previousOwn) qc.setQueryData(arbiQueryKeys.document(id), own)\n}\n\n/** The server's documents after an edit replace the cached ones. */\nfunction settleUpdatedDocuments(qc: QueryClient, updated: WorkspaceDocument[]): void {\n if (!updated.length) return\n const byId = new Map(updated.map((doc) => [doc.external_id, doc]))\n patchDocuments(qc, (old) =>\n old.some((doc) => byId.has(doc.external_id))\n ? old.map((doc) => byId.get(doc.external_id) ?? doc)\n : old\n )\n for (const doc of updated) setCachedDocument(qc, doc)\n}\n\n/** Apply `reducer` to the given documents wherever they are cached (lists and own entries). */\nfunction patchEachDocument(\n qc: QueryClient,\n docIds: Iterable<string>,\n reducer: (doc: WorkspaceDocument) => WorkspaceDocument\n): void {\n const ids = new Set(docIds)\n patchDocuments(qc, (old) =>\n old.some((doc) => ids.has(doc.external_id))\n ? old.map((doc) => (ids.has(doc.external_id) ? reducer(doc) : doc))\n : old\n )\n for (const id of ids) patchCachedDocument(qc, id, reducer)\n}\n\n/** The workspace a cached document belongs to. */\nfunction workspaceOf(qc: QueryClient, docId: string): string | undefined {\n for (const [, docs] of qc.getQueriesData<WorkspaceDocument[]>({\n queryKey: arbiQueryKeys.allDocuments(),\n })) {\n const doc = Array.isArray(docs) ? docs.find((d) => d.external_id === docId) : undefined\n if (doc) return doc.workspace_ext_id\n }\n return qc.getQueryData<WorkspaceDocument | null>(arbiQueryKeys.document(docId))?.workspace_ext_id\n}\n\n/** Tags applied: each document gains them, each tag's document count rises. */\nfunction settleAssignedDocTags(qc: QueryClient, created: DocTag[]): void {\n const byDoc = new Map<string, DocTag[]>()\n for (const doctag of created)\n byDoc.set(doctag.doc_ext_id, [...(byDoc.get(doctag.doc_ext_id) ?? []), doctag])\n const workspaces = new Map<string, Map<string, number>>()\n for (const doctag of created) {\n const workspaceId = workspaceOf(qc, doctag.doc_ext_id)\n if (!workspaceId) continue\n const delta = workspaces.get(workspaceId) ?? new Map<string, number>()\n delta.set(doctag.tag_ext_id, (delta.get(doctag.tag_ext_id) ?? 0) + 1)\n workspaces.set(workspaceId, delta)\n }\n patchEachDocument(qc, byDoc.keys(), (doc) => ({\n ...doc,\n doctags: [...(doc.doctags ?? []), ...(byDoc.get(doc.external_id) ?? [])],\n }))\n for (const [workspaceId, delta] of workspaces) adjustTagCounts(qc, workspaceId, delta)\n}\n\n/** A tag removed: the documents lose it, its count drops by the documents that had it. */\nfunction settleRemovedDocTags(qc: QueryClient, { tagId, docIds }: RemoveDocTagsInput): void {\n const ids = new Set(docIds)\n const removedByWorkspace = new Map<string, number>()\n for (const [, docs] of qc.getQueriesData<WorkspaceDocument[]>({\n queryKey: arbiQueryKeys.allDocuments(),\n })) {\n for (const doc of Array.isArray(docs) ? docs : []) {\n if (!ids.has(doc.external_id)) continue\n if (!doc.doctags?.some((dt) => dt.tag_ext_id === tagId)) continue\n removedByWorkspace.set(\n doc.workspace_ext_id,\n (removedByWorkspace.get(doc.workspace_ext_id) ?? 0) + 1\n )\n }\n }\n patchEachDocument(qc, ids, (doc) => ({\n ...doc,\n doctags: (doc.doctags ?? []).filter((dt) => dt.tag_ext_id !== tagId),\n }))\n for (const [workspaceId, removed] of removedByWorkspace)\n adjustTagCounts(qc, workspaceId, new Map([[tagId, -removed]]))\n}\n\n/** A tag's note changed on a document: the document's copy of it is replaced. */\nfunction settleUpdatedDocTag(qc: QueryClient, updated: DocTag): void {\n patchEachDocument(qc, [updated.doc_ext_id], (doc) => ({\n ...doc,\n doctags: (doc.doctags ?? []).map((dt) => (dt.tag_ext_id === updated.tag_ext_id ? updated : dt)),\n }))\n}\n\n/**\n * Each document write's request on a bare client (a replay after a reload), in the workspace it was\n * made in. The server keys a document or doctag write by the resource's own workspace, so once that\n * workspace is opened for the session the write cannot land in the one open now.\n */\nconst sendUpdateDocuments = (client: ArbiClient, input: UpdateDocumentsInput) =>\n inWorkspace(primeOnClient(client), input.workspaceId, () =>\n documentOps.updateDocuments(client, input.documents)\n ) as Promise<WorkspaceDocument[]>\nconst sendAssignDocTags = (client: ArbiClient, input: AssignDocTagsInput) =>\n inWorkspace(primeOnClient(client), input.workspaceId, () =>\n doctagOps.assignDocTags(client, input.tagId, input.docIds, input.note, input.citations)\n )\nconst sendRemoveDocTags = (client: ArbiClient, input: RemoveDocTagsInput) =>\n inWorkspace(primeOnClient(client), input.workspaceId, () =>\n doctagOps.removeDocTags(client, input.tagId, input.docIds)\n )\nconst sendUpdateDocTag = (client: ArbiClient, input: UpdateDocTagInput) =>\n inWorkspace(primeOnClient(client), input.workspaceId, () =>\n doctagOps.updateDocTag(client, input.tagId, input.docId, {\n note: input.note,\n citations: input.citations,\n })\n )\n\n/**\n * The document writes a host may queue offline and replay after a reload (`offline.ts`): each\n * key's request on a bare client (in the workspace the write was made in), and what its success\n * does to the cache.\n */\nexport const replayableDocumentMutations = [\n {\n mutationKey: arbiMutationKeys.updateDocuments(),\n run: sendUpdateDocuments,\n settle: (qc: QueryClient, updated: WorkspaceDocument[]) => settleUpdatedDocuments(qc, updated),\n },\n {\n mutationKey: arbiMutationKeys.assignDocTags(),\n run: sendAssignDocTags,\n settle: (qc: QueryClient, created: DocTag[]) => settleAssignedDocTags(qc, created),\n },\n {\n mutationKey: arbiMutationKeys.removeDocTags(),\n run: sendRemoveDocTags,\n settle: (qc: QueryClient, _data: unknown, input: RemoveDocTagsInput) =>\n settleRemovedDocTags(qc, input),\n },\n {\n mutationKey: arbiMutationKeys.updateDocTag(),\n run: sendUpdateDocTag,\n settle: (qc: QueryClient, updated: DocTag) => settleUpdatedDocTag(qc, updated),\n },\n] as const\n\n/**\n * The workspace a document write is made in, when its caller named none: the edited documents'\n * own (from the cache: a document can be edited from a view of another workspace), else the\n * current one. Read when the write is made, before it can be queued.\n */\nfunction useDocumentWriteWorkspace<V extends QueuedWriteWorkspace>(\n docIdOf: (variables: V) => string | undefined\n): (variables: V) => V {\n const arbi = useArbi()\n const qc = useQueryClient()\n return (variables: V) => {\n if (variables.workspaceId) return variables\n const docId = docIdOf(variables)\n const workspaceId =\n (docId ? workspaceOf(qc, docId) : undefined) ??\n (arbi.hasWorkspace ? arbi.getWorkspaceId() : undefined)\n return workspaceId ? { ...variables, workspaceId } : variables\n }\n}\n\n/**\n * `mutateAsync` that, while offline, queues the write and resolves at once (with `undefined`), so\n * a caller awaiting it to close a dialog never waits for the connection. For writes whose callers\n * do not need the server's answer.\n */\nfunction resolvingOffline<\n T extends { mutate: (...args: never[]) => unknown; mutateAsync: unknown },\n>(mutation: T): T {\n const mutateAsync = ((variables: never, options: never) => {\n if (!onlineManager.isOnline()) {\n ;(mutation.mutate as (v: never, o: never) => void)(variables, options)\n return Promise.resolve(undefined)\n }\n return (mutation.mutateAsync as (v: never, o: never) => Promise<unknown>)(variables, options)\n }) as T['mutateAsync']\n return { ...mutation, mutateAsync }\n}\n\n/** Reflect a confirmed resource share in every files view, and refresh its document detail. */\nexport function useMarkDocumentShared(): (documentExtId: string) => void {\n const qc = useQueryClient()\n return useCallback(\n (documentExtId: string) => {\n patchDocuments(qc, (old) =>\n old.map((doc) => (doc.external_id === documentExtId ? { ...doc, shared: true } : doc))\n )\n void qc.invalidateQueries({ queryKey: arbiQueryKeys.document(documentExtId) })\n },\n [qc]\n )\n}\n\n/**\n * Edit documents' fields (folder, sharing, title and other metadata, status). The answer replaces\n * the cached documents; offline the edit shows at once and is sent on reconnect.\n */\nexport function useUpdateDocuments() {\n const arbi = useArbi()\n const qc = useQueryClient()\n const capture = useDocumentWriteWorkspace<UpdateDocumentsInput>(\n (input) => input.documents[0]?.external_id\n )\n return resolvingOffline(\n useCapturingWorkspace(\n useMutation({\n mutationKey: arbiMutationKeys.updateDocuments(),\n mutationFn: (input: UpdateDocumentsInput): Promise<WorkspaceDocument[]> =>\n inWorkspace(primeOnArbi(arbi), input.workspaceId, () =>\n arbi.documents.update(input.documents)\n ),\n onMutate: ({ documents }) =>\n onlineManager.isOnline() || !documents.length\n ? undefined\n : applyOptimisticDocumentEdit(qc, documents),\n // Not sent because its workspace can't be opened: the edit stays, listed as not sent.\n onError: (error, _input, context) => {\n if (!isWorkspaceUnavailable(error)) rollbackOptimisticDocumentEdit(qc, context)\n },\n onSuccess: (updated) => settleUpdatedDocuments(qc, updated),\n ...QUEUED_WRITE_RETRY,\n }),\n capture\n )\n )\n}\n\n/** A folder path's segments: the `folder` string split on \"/\", trimmed, empty ones dropped. */\nfunction folderSegments(folder: string | null | undefined): string[] {\n return (folder ?? '')\n .split('/')\n .map((segment) => segment.trim())\n .filter(Boolean)\n}\n\n/**\n * Rename or move a folder: each of `documents` beneath `from` moves under `to`, keeping the\n * structure below it. The batch write does not return an email's attachments, so every cached row\n * beneath `from` moves too. Resolves to how many documents were written.\n */\nexport function useRenameFolder() {\n const qc = useQueryClient()\n const { mutateAsync } = useUpdateDocuments()\n return useCallback(\n async (documents: WorkspaceDocument[], from: string[], to: string[]): Promise<number> => {\n const moved = (folder: string | null | undefined): string | null | undefined => {\n const segments = folderSegments(folder)\n if (from.length === 0 || segments.length < from.length) return undefined\n if (!from.every((segment, i) => segments[i] === segment)) return undefined\n const next = [...to, ...segments.slice(from.length)]\n return next.length > 0 ? next.join('/') : null\n }\n const updates = documents.flatMap((doc) => {\n const folder = moved(doc.folder)\n return folder === undefined ? [] : [{ external_id: doc.external_id, folder }]\n })\n if (updates.length > 0) await mutateAsync({ documents: updates })\n patchDocuments(qc, (rows) => {\n let changed = false\n const next = rows.map((doc) => {\n const folder = moved(doc.folder)\n if (folder === undefined || folder === doc.folder) return doc\n changed = true\n return { ...doc, folder }\n })\n return changed ? next : rows\n })\n return updates.length\n },\n [qc, mutateAsync]\n )\n}\n\n/**\n * Delete documents (each with all its versions; an email with its attachments). They leave every\n * list, what was cached about them is forgotten, and the workspaces' file counts re-read.\n */\nexport function useDeleteDocuments() {\n const arbi = useArbi()\n const qc = useQueryClient()\n return useMutation({\n mutationKey: arbiMutationKeys.deleteDocuments(),\n mutationFn: (docIds: string[]) => arbi.documents.delete(docIds),\n onSuccess: (_data, docIds) => {\n const gone = new Set(docIds)\n patchDocuments(qc, (old) =>\n old.some((doc) => gone.has(doc.external_id))\n ? old.filter((doc) => !gone.has(doc.external_id))\n : old\n )\n forgetDocuments(qc, docIds)\n // A deleted document (a failed upload especially) leaves the processing rows too.\n const { clearTask } = useArbiWsStore.getState()\n for (const id of docIds) clearTask(id)\n return qc.invalidateQueries({ queryKey: arbiQueryKeys.workspaces() })\n },\n })\n}\n\n/** Re-read the documents an upload made and the workspaces' file counts. */\nasync function settleUpload(\n qc: QueryClient,\n arbi: Arbi,\n docIds: string[] | undefined\n): Promise<void> {\n if (docIds?.length) await refreshDocuments(qc, arbi, docIds)\n await qc.invalidateQueries({ queryKey: arbiQueryKeys.workspaces() })\n}\n\n/** Files to upload and where they go. */\nexport interface UploadDocumentsInput {\n files: Array<Blob | File>\n options?: UploadDocumentsOptions\n}\n\n/**\n * Upload files (to the open workspace, or `options.workspaceExtId`): resolves with the new\n * documents' ids (and the files the server skipped). The new documents join their list.\n */\nexport function useUploadDocuments() {\n const arbi = useArbi()\n const qc = useQueryClient()\n return useMutation({\n mutationKey: arbiMutationKeys.uploadDocuments(),\n mutationFn: ({ files, options }: UploadDocumentsInput): Promise<UploadResult> =>\n arbi.documents.upload(files, options),\n onSuccess: (result) => settleUpload(qc, arbi, result.doc_ext_ids),\n })\n}\n\n/** Web pages or files to fetch into a workspace (default: the open one). */\nexport interface UploadUrlsInput {\n urls: string[]\n shared?: boolean\n configExtId?: string | null\n /** The workspace the documents are made in; named on the request. Default: the open one. */\n workspaceId?: string | null\n}\n\n/** Add documents from URLs to a workspace (default: the open one); they join its list. */\nexport function useUploadUrls() {\n const arbi = useArbi()\n const qc = useQueryClient()\n return useMutation({\n mutationKey: arbiMutationKeys.uploadUrls(),\n mutationFn: ({ urls, shared, configExtId, workspaceId }: UploadUrlsInput) =>\n arbi.documents.uploadUrl(urls, {\n workspaceId: workspaceId ?? arbi.getWorkspaceId() ?? undefined,\n shared,\n configExtId,\n }),\n onSuccess: (result) =>\n settleUpload(qc, arbi, (result as { doc_ext_ids?: string[] }).doc_ext_ids),\n })\n}\n\n/** Apply a tag to documents: they show it at once, its count rises. Queued offline. */\nexport function useAssignDocTags() {\n const arbi = useArbi()\n const qc = useQueryClient()\n const capture = useDocumentWriteWorkspace<AssignDocTagsInput>((input) => input.docIds[0])\n return resolvingOffline(\n useCapturingWorkspace(\n useMutation({\n mutationKey: arbiMutationKeys.assignDocTags(),\n mutationFn: ({ workspaceId, tagId, docIds, note, citations }: AssignDocTagsInput) =>\n inWorkspace(primeOnArbi(arbi), workspaceId, () =>\n arbi.doctags.assign(tagId, docIds, note, citations)\n ) as Promise<DocTag[]>,\n onSuccess: (created) => settleAssignedDocTags(qc, created),\n ...QUEUED_WRITE_RETRY,\n }),\n capture\n )\n )\n}\n\n/** Remove a tag from documents: they lose it, its count drops. Queued offline. */\nexport function useRemoveDocTags() {\n const arbi = useArbi()\n const qc = useQueryClient()\n const capture = useDocumentWriteWorkspace<RemoveDocTagsInput>((input) => input.docIds[0])\n return resolvingOffline(\n useCapturingWorkspace(\n useMutation({\n mutationKey: arbiMutationKeys.removeDocTags(),\n mutationFn: ({ workspaceId, tagId, docIds }: RemoveDocTagsInput) =>\n inWorkspace(primeOnArbi(arbi), workspaceId, () => arbi.doctags.remove(tagId, docIds)),\n onSuccess: (_data, input) => settleRemovedDocTags(qc, input),\n ...QUEUED_WRITE_RETRY,\n }),\n capture\n )\n )\n}\n\n/** Change a tag's note (or its cited passages) on a document. Queued offline. */\nexport function useUpdateDocTag() {\n const arbi = useArbi()\n const qc = useQueryClient()\n const capture = useDocumentWriteWorkspace<UpdateDocTagInput>((input) => input.docId)\n return resolvingOffline(\n useCapturingWorkspace(\n useMutation({\n mutationKey: arbiMutationKeys.updateDocTag(),\n mutationFn: ({ workspaceId, tagId, docId, note, citations }: UpdateDocTagInput) =>\n inWorkspace(primeOnArbi(arbi), workspaceId, () =>\n arbi.doctags.update(tagId, docId, { note, citations })\n ) as Promise<DocTag>,\n onSuccess: (updated) => settleUpdatedDocTag(qc, updated),\n ...QUEUED_WRITE_RETRY,\n }),\n capture\n )\n )\n}\n\n/** Tags whose values AI fills on documents. */\nexport interface GenerateDocTagsInput {\n tagIds: string[]\n docIds: string[]\n /** Also where a document already has a value (default: only where it has none). */\n overwrite?: boolean\n}\n\n/**\n * Show documents sent back into processing (AI fields being filled) as queued, as an upload shows,\n * until their real task updates take over. Returns the undo (the write was refused).\n */\nfunction queueProcessing(\n documents: Array<{ docId: string; workspaceId: string; fileName: string; version: number }>\n): () => void {\n const store = useArbiWsStore.getState()\n const previous = documents.map(({ docId }) => [docId, store.tasks[docId]] as const)\n const now = Date.now()\n for (const doc of documents)\n store.putTask({\n doc_ext_id: doc.docId,\n workspace_ext_id: doc.workspaceId,\n file_name: doc.fileName,\n version: doc.version,\n status: 'queued',\n progress: 0,\n startTime: now,\n } as LiveTask)\n return () =>\n useArbiWsStore.setState((state) => {\n const tasks = { ...state.tasks }\n for (const [docId, task] of previous) {\n if (task) tasks[docId] = task\n else delete tasks[docId]\n }\n return { tasks }\n })\n}\n\n/**\n * Fill tags' values on documents with AI. Accepted at once; the work runs in the background and a\n * `batch_complete` (`doctag_generate`) event names the documents when it is done\n * (`refreshDocuments` then brings their values). Meanwhile the documents show as queued for\n * processing (as queued), undone if the request is refused.\n */\nexport function useGenerateDocTags() {\n const arbi = useArbi()\n const qc = useQueryClient()\n return useMutation({\n mutationKey: arbiMutationKeys.generateDocTags(),\n mutationFn: ({ tagIds, docIds, overwrite }: GenerateDocTagsInput) =>\n arbi.doctags.generate(tagIds, docIds, { overwrite }),\n onMutate: ({ docIds }) => {\n if (!docIds.length) return undefined\n const workspaceId = arbi.hasWorkspace ? arbi.getWorkspaceId() : ''\n const listed = new Map(\n (getCachedDocuments(qc, workspaceId) ?? []).map((doc) => [doc.external_id, doc])\n )\n // Reprocessing works on each document's current version.\n return {\n undo: queueProcessing(\n docIds.map((docId) => ({\n docId,\n workspaceId,\n fileName: listed.get(docId)?.file_name ?? '',\n version: listed.get(docId)?.current_version ?? 1,\n }))\n ),\n }\n },\n onError: (_error, _input, context) => context?.undo(),\n })\n}\n\n/**\n * Finalise a translation: its current version is saved as a new PDF document, labelled\n * \"Translation\" and linked to the original. Resolves with the new document's id; the new document\n * joins the list with its links, so the original's translations show it at once.\n */\nexport function useFinaliseTranslation() {\n const arbi = useArbi()\n const qc = useQueryClient()\n return useMutation({\n mutationFn: (docId: string) => arbi.documents.finaliseTranslation(docId),\n onSuccess: (result) => void refreshDocuments(qc, arbi, [result.document_ext_id]),\n })\n}\n"],
|
|
5
|
-
"mappings": "AAaA,SAAS,mBAAmB;AAC5B,SAAS,eAAe,aAAa,sBAAwC;AAE7E;AAAA,EACE,aAAa;AAAA,EACb,WAAW;AAAA,OAIN;AACP,SAAS,eAAe;AACxB,SAAS,kBAAkB,qBAAqB;AAChD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,iBAAiB,wBAAwB;AAClD,SAAS,sBAAqC;AAC9C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAgDA,SAAS,4BACd,IACA,SACwB;AACxB,QAAM,OAAO,IAAI,IAAI,QAAQ,IAAI,CAAC,WAAW,CAAC,OAAO,aAAa,MAAM,CAAC,CAAC;AAC1E,QAAM,WAAgC,CAAC;AACvC,iBAAe,IAAI,CAAC,QAAQ;AAC1B,QAAI,UAAU;AACd,UAAM,OAAO,IAAI,IAAI,CAAC,QAAQ;AAC5B,YAAM,SAAS,KAAK,IAAI,IAAI,WAAW;AACvC,UAAI,CAAC,OAAQ,QAAO;AACpB,gBAAU;AACV,eAAS,KAAK,GAAG;AACjB,aAAO,EAAE,GAAG,KAAK,GAAG,OAAO;AAAA,IAC7B,CAAC;AACD,WAAO,UAAU,OAAO;AAAA,EAC1B,CAAC;AACD,QAAM,cAAc,QAAQ,IAAI,CAAC,WAA2D;AAC1F,UAAM,MAAM,GAAG;AAAA,MACb,cAAc,SAAS,OAAO,WAAW;AAAA,IAC3C;AACA,QAAI,IAAK,mBAAkB,IAAI,EAAE,GAAG,KAAK,GAAG,OAAO,CAAsB;AACzE,WAAO,CAAC,OAAO,aAAa,GAAG;AAAA,EACjC,CAAC;AACD,SAAO,EAAE,YAAY,MAAM,UAAU,YAAY;AACnD;AAGO,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;AAC1B,SAAO,YAAY;AAAA,IACjB,aAAa,iBAAiB,gBAAgB;AAAA,IAC9C,YAAY,CAAC,EAAE,QAAQ,QAAQ,UAAU,MACvC,KAAK,QAAQ,SAAS,QAAQ,QAAQ,EAAE,UAAU,CAAC;AAAA,IACrD,UAAU,CAAC,EAAE,OAAO,MAAM;AACxB,UAAI,CAAC,OAAO,OAAQ,QAAO;AAC3B,YAAM,cAAc,KAAK,eAAe,KAAK,eAAe,IAAI;AAChE,YAAM,SAAS,IAAI;AAAA,SAChB,mBAAmB,IAAI,WAAW,KAAK,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,aAAa,GAAG,CAAC;AAAA,MACjF;AAEA,aAAO;AAAA,QACL,MAAM;AAAA,UACJ,OAAO,IAAI,CAAC,WAAW;AAAA,YACrB;AAAA,YACA;AAAA,YACA,UAAU,OAAO,IAAI,KAAK,GAAG,aAAa;AAAA,YAC1C,SAAS,OAAO,IAAI,KAAK,GAAG,mBAAmB;AAAA,UACjD,EAAE;AAAA,QACJ;AAAA,MACF;AAAA,IACF;AAAA,IACA,SAAS,CAAC,QAAQ,QAAQ,YAAY,SAAS,KAAK;AAAA,EACtD,CAAC;AACH;AAOO,SAAS,yBAAyB;AACvC,QAAM,OAAO,QAAQ;AACrB,QAAM,KAAK,eAAe;AAC1B,SAAO,YAAY;AAAA,IACjB,YAAY,CAAC,UAAkB,KAAK,UAAU,oBAAoB,KAAK;AAAA,IACvE,WAAW,CAAC,WAAW,KAAK,iBAAiB,IAAI,MAAM,CAAC,OAAO,eAAe,CAAC;AAAA,EACjF,CAAC;AACH;",
|
|
4
|
+
"sourcesContent": ["/**\n * Writing documents: field edits, deletion, uploads (files and URLs), and their tags (applying,\n * removing, re-noting, filling them with AI). Every write patches the caches that show its\n * documents in place (the workspace list, each document's own entry, the tag counts) instead of\n * re-reading a list that can be 100k documents long.\n *\n * Offline: field edits and tag applications / removals / notes pause and are sent on reconnect.\n * While queued, a field edit already shows (it is applied to the cache, and undone if the send\n * fails or the change is cancelled: {@link rollbackOptimisticDocumentEdit}), and awaiting one\n * resolves at once rather than when the connection is back. A host that persists its query cache\n * keeps them across a reload by registering `registerArbiMutationDefaults` (`offline.ts`).\n */\n\nimport { useCallback } from 'react'\nimport { onlineManager, useMutation, useQueryClient, type QueryClient } from '@tanstack/react-query'\nimport { logger, type ArbiClient, type components } from '@arbidocs/client'\nimport {\n documents as documentOps,\n doctags as doctagOps,\n type Arbi,\n type UploadDocumentsOptions,\n type UploadResult,\n} from '@arbidocs/sdk/browser'\nimport { useArbi } from '../useArbi'\nimport { arbiMutationKeys, arbiQueryKeys } from '../hooks'\nimport {\n forgetDocuments,\n getCachedDocuments,\n patchCachedDocument,\n patchDocuments,\n setCachedDocument,\n type WorkspaceDocument,\n} from './documents-cache'\nimport { adjustTagCounts, refreshDocuments } from './documents-data'\nimport { documentReadiness, whenProcessed } from './tag-when-processed'\nimport { useArbiWsStore, type LiveTask } from '../websocket/store'\nimport {\n QUEUED_WRITE_RETRY,\n inWorkspace,\n isWorkspaceUnavailable,\n primeOnArbi,\n primeOnClient,\n useCapturingWorkspace,\n type QueuedWriteWorkspace,\n} from '../queued-writes'\n\ntype DocUpdate = components['schemas']['DocUpdateRequest']\ntype DocTag = components['schemas']['DocTagResponse']\ntype CitationSources = components['schemas']['CitationSources']\n\n/** A field edit: the documents' ids with the fields that change (folder, sharing, metadata, \u2026). */\nexport interface UpdateDocumentsInput extends QueuedWriteWorkspace {\n documents: DocUpdate[]\n}\n\n/** Applying a tag to documents (with a note, e.g. a field's value, and the passages it cites). */\nexport interface AssignDocTagsInput extends QueuedWriteWorkspace {\n tagId: string\n docIds: string[]\n note?: string | null\n citations?: CitationSources | null\n}\n\n/** Removing a tag from documents. */\nexport interface RemoveDocTagsInput extends QueuedWriteWorkspace {\n tagId: string\n docIds: string[]\n}\n\n/** Changing the note (or its cited passages) of a tag on one document. */\nexport interface UpdateDocTagInput extends QueuedWriteWorkspace {\n tagId: string\n docId: string\n note?: string | null\n citations?: CitationSources | null\n}\n\n/**\n * Snapshot taken when a queued field edit was applied to the cache; restoring it undoes the edit.\n * It is the mutation's context, so a host's list of pending changes can undo one.\n */\nexport interface OptimisticDocumentEdit {\n optimistic: true\n previous: WorkspaceDocument[]\n previousOwn: Array<[string, WorkspaceDocument | null | undefined]>\n}\n\n/**\n * Show a queued field edit in the caches at once (offline only: online, the server's answer is the\n * one source). A second edit of the same document layers on the first, so undoing the later one\n * restores the earlier one.\n */\nexport function applyOptimisticDocumentEdit(\n qc: QueryClient,\n updates: DocUpdate[]\n): OptimisticDocumentEdit {\n const byId = new Map(updates.map((update) => [update.external_id, update]))\n const previous: WorkspaceDocument[] = []\n patchDocuments(qc, (old) => {\n let changed = false\n const next = old.map((doc) => {\n const update = byId.get(doc.external_id)\n if (!update) return doc\n changed = true\n previous.push(doc)\n return { ...doc, ...update } as WorkspaceDocument\n })\n return changed ? next : old\n })\n const previousOwn = updates.map((update): [string, WorkspaceDocument | null | undefined] => {\n const own = qc.getQueryData<WorkspaceDocument | null>(\n arbiQueryKeys.document(update.external_id)\n )\n if (own) setCachedDocument(qc, { ...own, ...update } as WorkspaceDocument)\n return [update.external_id, own]\n })\n return { optimistic: true, previous, previousOwn }\n}\n\n/** Undo {@link applyOptimisticDocumentEdit} from its snapshot (anything else: nothing to undo). */\nexport function rollbackOptimisticDocumentEdit(qc: QueryClient, context: unknown): void {\n const edit = context as OptimisticDocumentEdit | undefined\n if (!edit?.optimistic) return\n if (edit.previous.length) {\n const restore = new Map(edit.previous.map((doc) => [doc.external_id, doc]))\n patchDocuments(qc, (old) =>\n old.some((doc) => restore.has(doc.external_id))\n ? old.map((doc) => restore.get(doc.external_id) ?? doc)\n : old\n )\n }\n for (const [id, own] of edit.previousOwn) qc.setQueryData(arbiQueryKeys.document(id), own)\n}\n\n/** The server's documents after an edit replace the cached ones. */\nfunction settleUpdatedDocuments(qc: QueryClient, updated: WorkspaceDocument[]): void {\n if (!updated.length) return\n const byId = new Map(updated.map((doc) => [doc.external_id, doc]))\n patchDocuments(qc, (old) =>\n old.some((doc) => byId.has(doc.external_id))\n ? old.map((doc) => byId.get(doc.external_id) ?? doc)\n : old\n )\n for (const doc of updated) setCachedDocument(qc, doc)\n}\n\n/** Apply `reducer` to the given documents wherever they are cached (lists and own entries). */\nfunction patchEachDocument(\n qc: QueryClient,\n docIds: Iterable<string>,\n reducer: (doc: WorkspaceDocument) => WorkspaceDocument\n): void {\n const ids = new Set(docIds)\n patchDocuments(qc, (old) =>\n old.some((doc) => ids.has(doc.external_id))\n ? old.map((doc) => (ids.has(doc.external_id) ? reducer(doc) : doc))\n : old\n )\n for (const id of ids) patchCachedDocument(qc, id, reducer)\n}\n\n/** The workspace a cached document belongs to. */\nfunction workspaceOf(qc: QueryClient, docId: string): string | undefined {\n for (const [, docs] of qc.getQueriesData<WorkspaceDocument[]>({\n queryKey: arbiQueryKeys.allDocuments(),\n })) {\n const doc = Array.isArray(docs) ? docs.find((d) => d.external_id === docId) : undefined\n if (doc) return doc.workspace_ext_id\n }\n return qc.getQueryData<WorkspaceDocument | null>(arbiQueryKeys.document(docId))?.workspace_ext_id\n}\n\n/** Tags applied: each document gains them, each tag's document count rises. */\nfunction settleAssignedDocTags(qc: QueryClient, created: DocTag[]): void {\n const byDoc = new Map<string, DocTag[]>()\n for (const doctag of created)\n byDoc.set(doctag.doc_ext_id, [...(byDoc.get(doctag.doc_ext_id) ?? []), doctag])\n const workspaces = new Map<string, Map<string, number>>()\n for (const doctag of created) {\n const workspaceId = workspaceOf(qc, doctag.doc_ext_id)\n if (!workspaceId) continue\n const delta = workspaces.get(workspaceId) ?? new Map<string, number>()\n delta.set(doctag.tag_ext_id, (delta.get(doctag.tag_ext_id) ?? 0) + 1)\n workspaces.set(workspaceId, delta)\n }\n patchEachDocument(qc, byDoc.keys(), (doc) => ({\n ...doc,\n doctags: [...(doc.doctags ?? []), ...(byDoc.get(doc.external_id) ?? [])],\n }))\n for (const [workspaceId, delta] of workspaces) adjustTagCounts(qc, workspaceId, delta)\n}\n\n/** A tag removed: the documents lose it, its count drops by the documents that had it. */\nfunction settleRemovedDocTags(qc: QueryClient, { tagId, docIds }: RemoveDocTagsInput): void {\n const ids = new Set(docIds)\n const removedByWorkspace = new Map<string, number>()\n for (const [, docs] of qc.getQueriesData<WorkspaceDocument[]>({\n queryKey: arbiQueryKeys.allDocuments(),\n })) {\n for (const doc of Array.isArray(docs) ? docs : []) {\n if (!ids.has(doc.external_id)) continue\n if (!doc.doctags?.some((dt) => dt.tag_ext_id === tagId)) continue\n removedByWorkspace.set(\n doc.workspace_ext_id,\n (removedByWorkspace.get(doc.workspace_ext_id) ?? 0) + 1\n )\n }\n }\n patchEachDocument(qc, ids, (doc) => ({\n ...doc,\n doctags: (doc.doctags ?? []).filter((dt) => dt.tag_ext_id !== tagId),\n }))\n for (const [workspaceId, removed] of removedByWorkspace)\n adjustTagCounts(qc, workspaceId, new Map([[tagId, -removed]]))\n}\n\n/** A tag's note changed on a document: the document's copy of it is replaced. */\nfunction settleUpdatedDocTag(qc: QueryClient, updated: DocTag): void {\n patchEachDocument(qc, [updated.doc_ext_id], (doc) => ({\n ...doc,\n doctags: (doc.doctags ?? []).map((dt) => (dt.tag_ext_id === updated.tag_ext_id ? updated : dt)),\n }))\n}\n\n/**\n * Each document write's request on a bare client (a replay after a reload), in the workspace it was\n * made in. The server keys a document or doctag write by the resource's own workspace, so once that\n * workspace is opened for the session the write cannot land in the one open now.\n */\nconst sendUpdateDocuments = (client: ArbiClient, input: UpdateDocumentsInput) =>\n inWorkspace(primeOnClient(client), input.workspaceId, () =>\n documentOps.updateDocuments(client, input.documents)\n ) as Promise<WorkspaceDocument[]>\nconst sendAssignDocTags = (client: ArbiClient, input: AssignDocTagsInput) =>\n inWorkspace(primeOnClient(client), input.workspaceId, () =>\n doctagOps.assignDocTags(client, input.tagId, input.docIds, input.note, input.citations)\n )\nconst sendRemoveDocTags = (client: ArbiClient, input: RemoveDocTagsInput) =>\n inWorkspace(primeOnClient(client), input.workspaceId, () =>\n doctagOps.removeDocTags(client, input.tagId, input.docIds)\n )\nconst sendUpdateDocTag = (client: ArbiClient, input: UpdateDocTagInput) =>\n inWorkspace(primeOnClient(client), input.workspaceId, () =>\n doctagOps.updateDocTag(client, input.tagId, input.docId, {\n note: input.note,\n citations: input.citations,\n })\n )\n\n/**\n * The document writes a host may queue offline and replay after a reload (`offline.ts`): each\n * key's request on a bare client (in the workspace the write was made in), and what its success\n * does to the cache.\n */\nexport const replayableDocumentMutations = [\n {\n mutationKey: arbiMutationKeys.updateDocuments(),\n run: sendUpdateDocuments,\n settle: (qc: QueryClient, updated: WorkspaceDocument[]) => settleUpdatedDocuments(qc, updated),\n },\n {\n mutationKey: arbiMutationKeys.assignDocTags(),\n run: sendAssignDocTags,\n settle: (qc: QueryClient, created: DocTag[]) => settleAssignedDocTags(qc, created),\n },\n {\n mutationKey: arbiMutationKeys.removeDocTags(),\n run: sendRemoveDocTags,\n settle: (qc: QueryClient, _data: unknown, input: RemoveDocTagsInput) =>\n settleRemovedDocTags(qc, input),\n },\n {\n mutationKey: arbiMutationKeys.updateDocTag(),\n run: sendUpdateDocTag,\n settle: (qc: QueryClient, updated: DocTag) => settleUpdatedDocTag(qc, updated),\n },\n] as const\n\n/**\n * The workspace a document write is made in, when its caller named none: the edited documents'\n * own (from the cache: a document can be edited from a view of another workspace), else the\n * current one. Read when the write is made, before it can be queued.\n */\nfunction useDocumentWriteWorkspace<V extends QueuedWriteWorkspace>(\n docIdOf: (variables: V) => string | undefined\n): (variables: V) => V {\n const arbi = useArbi()\n const qc = useQueryClient()\n return (variables: V) => {\n if (variables.workspaceId) return variables\n const docId = docIdOf(variables)\n const workspaceId =\n (docId ? workspaceOf(qc, docId) : undefined) ??\n (arbi.hasWorkspace ? arbi.getWorkspaceId() : undefined)\n return workspaceId ? { ...variables, workspaceId } : variables\n }\n}\n\n/**\n * `mutateAsync` that, while offline, queues the write and resolves at once (with `undefined`), so\n * a caller awaiting it to close a dialog never waits for the connection. For writes whose callers\n * do not need the server's answer.\n */\nfunction resolvingOffline<\n T extends { mutate: (...args: never[]) => unknown; mutateAsync: unknown },\n>(mutation: T): T {\n const mutateAsync = ((variables: never, options: never) => {\n if (!onlineManager.isOnline()) {\n ;(mutation.mutate as (v: never, o: never) => void)(variables, options)\n return Promise.resolve(undefined)\n }\n return (mutation.mutateAsync as (v: never, o: never) => Promise<unknown>)(variables, options)\n }) as T['mutateAsync']\n return { ...mutation, mutateAsync }\n}\n\n/** Reflect a confirmed resource share in every files view, and refresh its document detail. */\nexport function useMarkDocumentShared(): (documentExtId: string) => void {\n const qc = useQueryClient()\n return useCallback(\n (documentExtId: string) => {\n patchDocuments(qc, (old) =>\n old.map((doc) => (doc.external_id === documentExtId ? { ...doc, shared: true } : doc))\n )\n void qc.invalidateQueries({ queryKey: arbiQueryKeys.document(documentExtId) })\n },\n [qc]\n )\n}\n\n/**\n * Edit documents' fields (folder, sharing, title and other metadata, status). The answer replaces\n * the cached documents; offline the edit shows at once and is sent on reconnect.\n */\nexport function useUpdateDocuments() {\n const arbi = useArbi()\n const qc = useQueryClient()\n const capture = useDocumentWriteWorkspace<UpdateDocumentsInput>(\n (input) => input.documents[0]?.external_id\n )\n return resolvingOffline(\n useCapturingWorkspace(\n useMutation({\n mutationKey: arbiMutationKeys.updateDocuments(),\n mutationFn: (input: UpdateDocumentsInput): Promise<WorkspaceDocument[]> =>\n inWorkspace(primeOnArbi(arbi), input.workspaceId, () =>\n arbi.documents.update(input.documents)\n ),\n onMutate: ({ documents }) =>\n onlineManager.isOnline() || !documents.length\n ? undefined\n : applyOptimisticDocumentEdit(qc, documents),\n // Not sent because its workspace can't be opened: the edit stays, listed as not sent.\n onError: (error, _input, context) => {\n if (!isWorkspaceUnavailable(error)) rollbackOptimisticDocumentEdit(qc, context)\n },\n onSuccess: (updated) => settleUpdatedDocuments(qc, updated),\n ...QUEUED_WRITE_RETRY,\n }),\n capture\n )\n )\n}\n\n/** A folder path's segments: the `folder` string split on \"/\", trimmed, empty ones dropped. */\nfunction folderSegments(folder: string | null | undefined): string[] {\n return (folder ?? '')\n .split('/')\n .map((segment) => segment.trim())\n .filter(Boolean)\n}\n\n/**\n * Rename or move a folder: each of `documents` beneath `from` moves under `to`, keeping the\n * structure below it. The batch write does not return an email's attachments, so every cached row\n * beneath `from` moves too. Resolves to how many documents were written.\n */\nexport function useRenameFolder() {\n const qc = useQueryClient()\n const { mutateAsync } = useUpdateDocuments()\n return useCallback(\n async (documents: WorkspaceDocument[], from: string[], to: string[]): Promise<number> => {\n const moved = (folder: string | null | undefined): string | null | undefined => {\n const segments = folderSegments(folder)\n if (from.length === 0 || segments.length < from.length) return undefined\n if (!from.every((segment, i) => segments[i] === segment)) return undefined\n const next = [...to, ...segments.slice(from.length)]\n return next.length > 0 ? next.join('/') : null\n }\n const updates = documents.flatMap((doc) => {\n const folder = moved(doc.folder)\n return folder === undefined ? [] : [{ external_id: doc.external_id, folder }]\n })\n if (updates.length > 0) await mutateAsync({ documents: updates })\n patchDocuments(qc, (rows) => {\n let changed = false\n const next = rows.map((doc) => {\n const folder = moved(doc.folder)\n if (folder === undefined || folder === doc.folder) return doc\n changed = true\n return { ...doc, folder }\n })\n return changed ? next : rows\n })\n return updates.length\n },\n [qc, mutateAsync]\n )\n}\n\n/**\n * Delete documents (each with all its versions; an email with its attachments). They leave every\n * list, what was cached about them is forgotten, and the workspaces' file counts re-read.\n */\nexport function useDeleteDocuments() {\n const arbi = useArbi()\n const qc = useQueryClient()\n return useMutation({\n mutationKey: arbiMutationKeys.deleteDocuments(),\n mutationFn: (docIds: string[]) => arbi.documents.delete(docIds),\n onSuccess: (_data, docIds) => {\n const gone = new Set(docIds)\n patchDocuments(qc, (old) =>\n old.some((doc) => gone.has(doc.external_id))\n ? old.filter((doc) => !gone.has(doc.external_id))\n : old\n )\n forgetDocuments(qc, docIds)\n // A deleted document (a failed upload especially) leaves the processing rows too.\n const { clearTask } = useArbiWsStore.getState()\n for (const id of docIds) clearTask(id)\n return qc.invalidateQueries({ queryKey: arbiQueryKeys.workspaces() })\n },\n })\n}\n\n/** Re-read the documents an upload made and the workspaces' file counts. */\nasync function settleUpload(\n qc: QueryClient,\n arbi: Arbi,\n docIds: string[] | undefined\n): Promise<void> {\n if (docIds?.length) await refreshDocuments(qc, arbi, docIds)\n await qc.invalidateQueries({ queryKey: arbiQueryKeys.workspaces() })\n}\n\n/** Files to upload and where they go. */\nexport interface UploadDocumentsInput {\n files: Array<Blob | File>\n options?: UploadDocumentsOptions\n}\n\n/**\n * Upload files (to the open workspace, or `options.workspaceExtId`): resolves with the new\n * documents' ids (and the files the server skipped). The new documents join their list.\n */\nexport function useUploadDocuments() {\n const arbi = useArbi()\n const qc = useQueryClient()\n return useMutation({\n mutationKey: arbiMutationKeys.uploadDocuments(),\n mutationFn: ({ files, options }: UploadDocumentsInput): Promise<UploadResult> =>\n arbi.documents.upload(files, options),\n onSuccess: (result) => settleUpload(qc, arbi, result.doc_ext_ids),\n })\n}\n\n/** Web pages or files to fetch into a workspace (default: the open one). */\nexport interface UploadUrlsInput {\n urls: string[]\n shared?: boolean\n configExtId?: string | null\n /** The workspace the documents are made in; named on the request. Default: the open one. */\n workspaceId?: string | null\n}\n\n/** Add documents from URLs to a workspace (default: the open one); they join its list. */\nexport function useUploadUrls() {\n const arbi = useArbi()\n const qc = useQueryClient()\n return useMutation({\n mutationKey: arbiMutationKeys.uploadUrls(),\n mutationFn: ({ urls, shared, configExtId, workspaceId }: UploadUrlsInput) =>\n arbi.documents.uploadUrl(urls, {\n workspaceId: workspaceId ?? arbi.getWorkspaceId() ?? undefined,\n shared,\n configExtId,\n }),\n onSuccess: (result) =>\n settleUpload(qc, arbi, (result as { doc_ext_ids?: string[] }).doc_ext_ids),\n })\n}\n\n/** Apply a tag to documents: they show it at once, its count rises. Queued offline. */\nexport function useAssignDocTags() {\n const arbi = useArbi()\n const qc = useQueryClient()\n const capture = useDocumentWriteWorkspace<AssignDocTagsInput>((input) => input.docIds[0])\n return resolvingOffline(\n useCapturingWorkspace(\n useMutation({\n mutationKey: arbiMutationKeys.assignDocTags(),\n mutationFn: ({ workspaceId, tagId, docIds, note, citations }: AssignDocTagsInput) =>\n inWorkspace(primeOnArbi(arbi), workspaceId, () =>\n arbi.doctags.assign(tagId, docIds, note, citations)\n ) as Promise<DocTag[]>,\n onSuccess: (created) => settleAssignedDocTags(qc, created),\n ...QUEUED_WRITE_RETRY,\n }),\n capture\n )\n )\n}\n\n/** Remove a tag from documents: they lose it, its count drops. Queued offline. */\nexport function useRemoveDocTags() {\n const arbi = useArbi()\n const qc = useQueryClient()\n const capture = useDocumentWriteWorkspace<RemoveDocTagsInput>((input) => input.docIds[0])\n return resolvingOffline(\n useCapturingWorkspace(\n useMutation({\n mutationKey: arbiMutationKeys.removeDocTags(),\n mutationFn: ({ workspaceId, tagId, docIds }: RemoveDocTagsInput) =>\n inWorkspace(primeOnArbi(arbi), workspaceId, () => arbi.doctags.remove(tagId, docIds)),\n onSuccess: (_data, input) => settleRemovedDocTags(qc, input),\n ...QUEUED_WRITE_RETRY,\n }),\n capture\n )\n )\n}\n\n/** Change a tag's note (or its cited passages) on a document. Queued offline. */\nexport function useUpdateDocTag() {\n const arbi = useArbi()\n const qc = useQueryClient()\n const capture = useDocumentWriteWorkspace<UpdateDocTagInput>((input) => input.docId)\n return resolvingOffline(\n useCapturingWorkspace(\n useMutation({\n mutationKey: arbiMutationKeys.updateDocTag(),\n mutationFn: ({ workspaceId, tagId, docId, note, citations }: UpdateDocTagInput) =>\n inWorkspace(primeOnArbi(arbi), workspaceId, () =>\n arbi.doctags.update(tagId, docId, { note, citations })\n ) as Promise<DocTag>,\n onSuccess: (updated) => settleUpdatedDocTag(qc, updated),\n ...QUEUED_WRITE_RETRY,\n }),\n capture\n )\n )\n}\n\n/** Tags whose values AI fills on documents. */\nexport interface GenerateDocTagsInput {\n tagIds: string[]\n docIds: string[]\n /** Also where a document already has a value (default: only where it has none). */\n overwrite?: boolean\n}\n\n/**\n * Show documents sent back into processing (AI fields being filled) as queued, as an upload shows,\n * until their real task updates take over. Returns the undo (the write was refused).\n */\nfunction queueProcessing(\n documents: Array<{ docId: string; workspaceId: string; fileName: string; version: number }>\n): () => void {\n const store = useArbiWsStore.getState()\n const previous = documents.map(({ docId }) => [docId, store.tasks[docId]] as const)\n const now = Date.now()\n for (const doc of documents)\n store.putTask({\n doc_ext_id: doc.docId,\n workspace_ext_id: doc.workspaceId,\n file_name: doc.fileName,\n version: doc.version,\n status: 'queued',\n progress: 0,\n startTime: now,\n } as LiveTask)\n return () =>\n useArbiWsStore.setState((state) => {\n const tasks = { ...state.tasks }\n for (const [docId, task] of previous) {\n if (task) tasks[docId] = task\n else delete tasks[docId]\n }\n return { tasks }\n })\n}\n\n/** What a request to fill AI fields did: requested now, waiting for processing, never. */\nexport interface GenerateDocTagsResult {\n /** Processed documents: requested now. */\n docIds: string[]\n /** Still processing: requested once each is processed (see `whenProcessed`). */\n queuedDocIds: string[]\n /** Their processing failed (or was skipped): never tagged. */\n unprocessableDocIds: string[]\n}\n\n/**\n * Fill tags' values on documents with AI. Only processed documents can be tagged (the server\n * refuses any other with 409): those are requested at once; one still processing (an upload's new\n * files) is requested once a read says it finished; one whose processing failed never. A request\n * is accepted at once and runs in the background; a `batch_complete` (`doctag_generate`) event\n * names its documents when it is done (`refreshDocuments` then brings their values). Meanwhile\n * they show as queued for processing, undone if the request is refused.\n */\nexport function useGenerateDocTags() {\n const arbi = useArbi()\n const qc = useQueryClient()\n return useMutation({\n mutationKey: arbiMutationKeys.generateDocTags(),\n mutationFn: async ({\n tagIds,\n docIds,\n overwrite,\n }: GenerateDocTagsInput): Promise<GenerateDocTagsResult> => {\n const workspaceId = arbi.hasWorkspace ? arbi.getWorkspaceId() : ''\n const rowOf = (docId: string) =>\n getCachedDocuments(qc, workspaceId)?.find((doc) => doc.external_id === docId) ??\n qc.getQueryData<WorkspaceDocument>(arbiQueryKeys.document(docId))\n const request = async (ids: string[]) => {\n // Reprocessing works on each document's current version.\n const undo = queueProcessing(\n ids.map((docId) => ({\n docId,\n workspaceId,\n fileName: rowOf(docId)?.file_name ?? '',\n version: rowOf(docId)?.current_version ?? 1,\n }))\n )\n try {\n await arbi.doctags.generate(tagIds, ids, { overwrite })\n } catch (error) {\n undo()\n throw error\n }\n }\n const result: GenerateDocTagsResult = {\n docIds: [],\n queuedDocIds: [],\n unprocessableDocIds: [],\n }\n for (const docId of docIds) {\n const readiness = documentReadiness(rowOf(docId))\n if (readiness === 'processed') result.docIds.push(docId)\n else if (readiness === 'processing') result.queuedDocIds.push(docId)\n else result.unprocessableDocIds.push(docId)\n }\n if (result.queuedDocIds.length) {\n whenProcessed(qc, result.queuedDocIds, (ready) =>\n request(ready).catch((error) =>\n logger.error('Filling AI fields on processed documents failed:', error)\n )\n )\n // Not read yet (an upload's new files): a read says at once whether they are processed.\n const unread = result.queuedDocIds.filter((docId) => !rowOf(docId))\n if (unread.length) void refreshDocuments(qc, arbi, unread)\n }\n if (result.docIds.length) await request(result.docIds)\n return result\n },\n })\n}\n\n/**\n * Finalise a translation: its current version is saved as a new PDF document, labelled\n * \"Translation\" and linked to the original. Resolves with the new document's id; the new document\n * joins the list with its links, so the original's translations show it at once.\n */\nexport function useFinaliseTranslation() {\n const arbi = useArbi()\n const qc = useQueryClient()\n return useMutation({\n mutationFn: (docId: string) => arbi.documents.finaliseTranslation(docId),\n onSuccess: (result) => void refreshDocuments(qc, arbi, [result.document_ext_id]),\n })\n}\n"],
|
|
5
|
+
"mappings": "AAaA,SAAS,mBAAmB;AAC5B,SAAS,eAAe,aAAa,sBAAwC;AAC7E,SAAS,cAAgD;AACzD;AAAA,EACE,aAAa;AAAA,EACb,WAAW;AAAA,OAIN;AACP,SAAS,eAAe;AACxB,SAAS,kBAAkB,qBAAqB;AAChD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,iBAAiB,wBAAwB;AAClD,SAAS,mBAAmB,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WAAW,CAAC,WAAW,KAAK,iBAAiB,IAAI,MAAM,CAAC,OAAO,eAAe,CAAC;AAAA,EACjF,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/documents/index.js
CHANGED
|
@@ -16,6 +16,11 @@ import {
|
|
|
16
16
|
IN_FLIGHT_DOCUMENT_STATUSES
|
|
17
17
|
} from "./processing-order.js";
|
|
18
18
|
import { subscribeDocumentReads } from "./processing-settle.js";
|
|
19
|
+
import {
|
|
20
|
+
TAGGABLE_DOCUMENT_STATUSES,
|
|
21
|
+
documentReadiness,
|
|
22
|
+
whenProcessed
|
|
23
|
+
} from "./tag-when-processed.js";
|
|
19
24
|
import {
|
|
20
25
|
useWorkspaceProcessing,
|
|
21
26
|
applyTaskEvents
|
|
@@ -167,6 +172,7 @@ export {
|
|
|
167
172
|
PENDING_SYNC_PREDICATE,
|
|
168
173
|
PhotoCapture,
|
|
169
174
|
SIMILARITY_THRESHOLD,
|
|
175
|
+
TAGGABLE_DOCUMENT_STATUSES,
|
|
170
176
|
UPLOAD_ACCEPT,
|
|
171
177
|
UPLOAD_MAX_FILE_SIZE,
|
|
172
178
|
VIDEO_MIME_PREFERENCE,
|
|
@@ -183,6 +189,7 @@ export {
|
|
|
183
189
|
captureFrameAsBlob,
|
|
184
190
|
classifyMediaError,
|
|
185
191
|
createChunkedRecorder,
|
|
192
|
+
documentReadiness,
|
|
186
193
|
dropTagFromCachedDocuments,
|
|
187
194
|
extractZipFile,
|
|
188
195
|
fallbackFileName,
|
|
@@ -263,6 +270,7 @@ export {
|
|
|
263
270
|
useUploadUrls,
|
|
264
271
|
useVideoRecorder,
|
|
265
272
|
useWorkspaceProcessing,
|
|
273
|
+
whenProcessed,
|
|
266
274
|
wipeOfflineDocuments,
|
|
267
275
|
withRelativePath
|
|
268
276
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/documents/index.ts"],
|
|
4
|
-
"sourcesContent": ["// The documents of a workspace: reading (progressive), the cache every write patches, the writes\n// (offline-aware), and what a host adds (its live processing state)\nexport {\n useDocuments,\n useDocument,\n useSimilarDocuments,\n refreshDocuments,\n useRefreshDocuments,\n adjustTagCounts,\n SIMILARITY_THRESHOLD,\n FINISHED_DOCUMENT_STATUSES,\n} from './documents-data'\nexport {\n resolveDocumentStatus,\n isStaleTaskUpdate,\n isRowNewer,\n settledByRows,\n IN_FLIGHT_DOCUMENT_STATUSES,\n type SequencedTask,\n type SequencedRow,\n} from './processing-order'\nexport { subscribeDocumentReads } from './processing-settle'\nexport {\n useWorkspaceProcessing,\n applyTaskEvents,\n type WorkspaceProcessing,\n} from './processing-live'\nexport {\n useDocumentsLoading,\n isDocumentsLoading,\n stopDocumentsLoading,\n DOCUMENTS_FIRST_PAGE_SIZE,\n DOCUMENTS_PAGE_SIZE,\n DOCUMENTS_FIRST_PAGE_MEASURE,\n} from './documents-loader'\nexport {\n patchDocuments,\n upsertDocuments,\n getCachedDocuments,\n setCachedDocument,\n patchCachedDocument,\n dropTagFromCachedDocuments,\n forgetDocuments,\n subscribeDocumentRows,\n type WorkspaceDocument,\n type DocumentRowChange,\n} from './documents-cache'\nexport {\n useMarkDocumentShared,\n useUpdateDocuments,\n useDeleteDocuments,\n useUploadDocuments,\n useUploadUrls,\n useAssignDocTags,\n useRemoveDocTags,\n useUpdateDocTag,\n useGenerateDocTags,\n useFinaliseTranslation,\n useRenameFolder,\n applyOptimisticDocumentEdit,\n rollbackOptimisticDocumentEdit,\n type OptimisticDocumentEdit,\n type UpdateDocumentsInput,\n type UploadDocumentsInput,\n type UploadUrlsInput,\n type AssignDocTagsInput,\n type RemoveDocTagsInput,\n type UpdateDocTagInput,\n type GenerateDocTagsInput,\n} from './documents-writes'\nexport {\n useDocumentsSupport,\n useProcessingTasks,\n useProcessingTask,\n type DocumentsSupport,\n type ProcessingTask,\n useDocumentHostActions,\n useOpenViewerDocumentId,\n type DocumentHostActions,\n type DocumentPerson,\n type DocumentStartItem,\n} from './support'\nexport {\n isDocumentAddableToConversation,\n getDocumentDate,\n formatDocDate,\n getDocumentNature,\n getDocumentAuthor,\n getDocumentSubject,\n DEFAULT_METADATA_TAGS,\n canonicalFolderPath,\n buildFolderTree,\n formatFolderLabel,\n COLUMN_LABEL_FALLBACKS,\n type FolderTreeNode,\n} from './document-fields'\nexport { archiveName, buildDocumentMetadataRows, fallbackFileName } from './document-download'\nexport { useDownloadDocuments, type UseDownloadDocumentsOptions } from './useDownloadDocuments'\nexport { useDocumentThumbnails } from './useDocumentThumbnails'\n\nexport { DocumentReview, type DocumentReviewProps } from './DocumentReview'\nexport type {\n ParsedDocument,\n ParsedChunk,\n ParsedChunkMetadata,\n ParsedDocumentMetadata,\n} from './parsed-types'\n\n// Audio recording \u2014 capture engine, shared waveform visual, and a\n// toggle-style recorder built on both. All props-in/callback-out: no store\n// coupling, so a host app can wire persistence however it likes.\nexport {\n useAudioRecorder,\n type AudioRecorderState,\n type AudioSegment,\n type UseAudioRecorderOptions,\n type UseAudioRecorderResult,\n} from './useAudioRecorder'\nexport {\n DEFAULT_SEGMENTER_CONFIG,\n INITIAL_SEGMENTER_STATE,\n flushSegmenter,\n levelFromRms,\n stepSegmenter,\n type SegmenterConfig,\n type SegmenterEvent,\n type SegmenterState,\n} from './audio-segmenter'\nexport {\n AUDIO_MIME_PREFERENCE,\n VIDEO_MIME_PREFERENCE,\n createChunkedRecorder,\n pickRecorderMimeType,\n type ChunkedRecorder,\n type ChunkedRecorderOptions,\n type RecordedChunk,\n} from './chunked-recorder'\nexport { MicWaveformIndicator, type MicWaveformIndicatorProps } from './MicWaveformIndicator'\nexport { MicRecordingOverlay, type MicRecordingOverlayProps } from './MicRecordingOverlay'\nexport { VoiceNoteRecorder, type VoiceNoteRecorderProps } from './VoiceNoteRecorder'\nexport { DraftTitleControls, type DraftTitleControlsProps } from './DraftTitleControls'\nexport { InlineMicButton, type InlineMicButtonProps } from './InlineMicButton'\nexport { formatElapsed } from './format-elapsed'\n\n// Camera capture \u2014 the photo/video counterparts to the audio recording\n// engine above. useCameraStream is the shared getUserMedia lifecycle;\n// useVideoRecorder layers MediaRecorder on top of its stream; PhotoCapture/\n// VideoCapture are the props-in/callback-out capture UIs (same shape as\n// VoiceNoteRecorder).\nexport { useCameraStream, type UseCameraStreamResult } from './useCameraStream'\nexport {\n useVideoRecorder,\n type UseVideoRecorderResult,\n type VideoRecorderState,\n} from './useVideoRecorder'\nexport { captureFrameAsBlob } from './capture-frame'\nexport { classifyMediaError } from './media-error'\nexport { PhotoCapture, type PhotoCaptureProps } from './PhotoCapture'\nexport { VideoCapture, type VideoCaptureProps } from './VideoCapture'\n\n// Content-based audio/video classification for containers (like .webm) whose\n// extension alone doesn't say which one they are.\nexport { hasVideoTrack } from './has-video-track'\n// Uploading: choosing files (folders, zip archives, refusals), the upload with progress, and adding\n// from web addresses\nexport {\n UPLOAD_ACCEPT,\n UPLOAD_MAX_FILE_SIZE,\n extractZipFile,\n filesFromDrop,\n isZipFile,\n prepareUploadFiles,\n uploadFolderOf,\n withRelativePath,\n type ExtractedZip,\n type RefusedUploadFile,\n type UploadRefusal,\n type ZipExtractor,\n} from './upload-files'\nexport {\n useUploadFiles,\n uploadedDocumentFolder,\n forgetUploadedDocumentFolder,\n type UploadFilesInput,\n type UploadFilesProgress,\n type UploadFilesResult,\n} from './useUploadFiles'\nexport {\n useUploadFromUrls,\n type UploadFromUrlsInput,\n type UploadFromUrlsResult,\n} from './useUploadFromUrls'\n// How documents relate: email family, made from / copies, duplicates, near-duplicates\nexport {\n useRelatedDocuments,\n getRelatedTotal,\n getRelatedLabels,\n type RelatedDocs,\n type RelatedDocsMap,\n} from './related-documents'\n\n// Offline changes waiting to sync: what changed, how many, per document, and undo\nexport {\n usePendingSyncItems,\n usePendingSyncCounts,\n useDocumentPendingSync,\n useCancelManyPendingSync,\n buildPendingSyncItem,\n PENDING_SYNC_PREDICATE,\n type PendingSyncItem,\n type RawPending,\n} from './pending-sync'\n\n// Documents kept on this device for offline use\nexport {\n useOfflineDocumentIds,\n useKeepDocumentsOffline,\n useRemoveDocumentsOffline,\n loadOfflineDocument,\n getOfflineDocument,\n wipeOfflineDocuments,\n requestPersistentStorage,\n type OfflineDocumentRecord,\n} from './offline-documents'\n"],
|
|
5
|
-
"mappings": "AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP,SAAS,8BAA8B;AACvC;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,
|
|
4
|
+
"sourcesContent": ["// The documents of a workspace: reading (progressive), the cache every write patches, the writes\n// (offline-aware), and what a host adds (its live processing state)\nexport {\n useDocuments,\n useDocument,\n useSimilarDocuments,\n refreshDocuments,\n useRefreshDocuments,\n adjustTagCounts,\n SIMILARITY_THRESHOLD,\n FINISHED_DOCUMENT_STATUSES,\n} from './documents-data'\nexport {\n resolveDocumentStatus,\n isStaleTaskUpdate,\n isRowNewer,\n settledByRows,\n IN_FLIGHT_DOCUMENT_STATUSES,\n type SequencedTask,\n type SequencedRow,\n} from './processing-order'\nexport { subscribeDocumentReads } from './processing-settle'\nexport {\n TAGGABLE_DOCUMENT_STATUSES,\n documentReadiness,\n whenProcessed,\n type DocumentReadiness,\n} from './tag-when-processed'\nexport {\n useWorkspaceProcessing,\n applyTaskEvents,\n type WorkspaceProcessing,\n} from './processing-live'\nexport {\n useDocumentsLoading,\n isDocumentsLoading,\n stopDocumentsLoading,\n DOCUMENTS_FIRST_PAGE_SIZE,\n DOCUMENTS_PAGE_SIZE,\n DOCUMENTS_FIRST_PAGE_MEASURE,\n} from './documents-loader'\nexport {\n patchDocuments,\n upsertDocuments,\n getCachedDocuments,\n setCachedDocument,\n patchCachedDocument,\n dropTagFromCachedDocuments,\n forgetDocuments,\n subscribeDocumentRows,\n type WorkspaceDocument,\n type DocumentRowChange,\n} from './documents-cache'\nexport {\n useMarkDocumentShared,\n useUpdateDocuments,\n useDeleteDocuments,\n useUploadDocuments,\n useUploadUrls,\n useAssignDocTags,\n useRemoveDocTags,\n useUpdateDocTag,\n useGenerateDocTags,\n useFinaliseTranslation,\n useRenameFolder,\n applyOptimisticDocumentEdit,\n rollbackOptimisticDocumentEdit,\n type OptimisticDocumentEdit,\n type UpdateDocumentsInput,\n type UploadDocumentsInput,\n type UploadUrlsInput,\n type AssignDocTagsInput,\n type RemoveDocTagsInput,\n type UpdateDocTagInput,\n type GenerateDocTagsInput,\n type GenerateDocTagsResult,\n} from './documents-writes'\nexport {\n useDocumentsSupport,\n useProcessingTasks,\n useProcessingTask,\n type DocumentsSupport,\n type ProcessingTask,\n useDocumentHostActions,\n useOpenViewerDocumentId,\n type DocumentHostActions,\n type DocumentPerson,\n type DocumentStartItem,\n} from './support'\nexport {\n isDocumentAddableToConversation,\n getDocumentDate,\n formatDocDate,\n getDocumentNature,\n getDocumentAuthor,\n getDocumentSubject,\n DEFAULT_METADATA_TAGS,\n canonicalFolderPath,\n buildFolderTree,\n formatFolderLabel,\n COLUMN_LABEL_FALLBACKS,\n type FolderTreeNode,\n} from './document-fields'\nexport { archiveName, buildDocumentMetadataRows, fallbackFileName } from './document-download'\nexport { useDownloadDocuments, type UseDownloadDocumentsOptions } from './useDownloadDocuments'\nexport { useDocumentThumbnails } from './useDocumentThumbnails'\n\nexport { DocumentReview, type DocumentReviewProps } from './DocumentReview'\nexport type {\n ParsedDocument,\n ParsedChunk,\n ParsedChunkMetadata,\n ParsedDocumentMetadata,\n} from './parsed-types'\n\n// Audio recording \u2014 capture engine, shared waveform visual, and a\n// toggle-style recorder built on both. All props-in/callback-out: no store\n// coupling, so a host app can wire persistence however it likes.\nexport {\n useAudioRecorder,\n type AudioRecorderState,\n type AudioSegment,\n type UseAudioRecorderOptions,\n type UseAudioRecorderResult,\n} from './useAudioRecorder'\nexport {\n DEFAULT_SEGMENTER_CONFIG,\n INITIAL_SEGMENTER_STATE,\n flushSegmenter,\n levelFromRms,\n stepSegmenter,\n type SegmenterConfig,\n type SegmenterEvent,\n type SegmenterState,\n} from './audio-segmenter'\nexport {\n AUDIO_MIME_PREFERENCE,\n VIDEO_MIME_PREFERENCE,\n createChunkedRecorder,\n pickRecorderMimeType,\n type ChunkedRecorder,\n type ChunkedRecorderOptions,\n type RecordedChunk,\n} from './chunked-recorder'\nexport { MicWaveformIndicator, type MicWaveformIndicatorProps } from './MicWaveformIndicator'\nexport { MicRecordingOverlay, type MicRecordingOverlayProps } from './MicRecordingOverlay'\nexport { VoiceNoteRecorder, type VoiceNoteRecorderProps } from './VoiceNoteRecorder'\nexport { DraftTitleControls, type DraftTitleControlsProps } from './DraftTitleControls'\nexport { InlineMicButton, type InlineMicButtonProps } from './InlineMicButton'\nexport { formatElapsed } from './format-elapsed'\n\n// Camera capture \u2014 the photo/video counterparts to the audio recording\n// engine above. useCameraStream is the shared getUserMedia lifecycle;\n// useVideoRecorder layers MediaRecorder on top of its stream; PhotoCapture/\n// VideoCapture are the props-in/callback-out capture UIs (same shape as\n// VoiceNoteRecorder).\nexport { useCameraStream, type UseCameraStreamResult } from './useCameraStream'\nexport {\n useVideoRecorder,\n type UseVideoRecorderResult,\n type VideoRecorderState,\n} from './useVideoRecorder'\nexport { captureFrameAsBlob } from './capture-frame'\nexport { classifyMediaError } from './media-error'\nexport { PhotoCapture, type PhotoCaptureProps } from './PhotoCapture'\nexport { VideoCapture, type VideoCaptureProps } from './VideoCapture'\n\n// Content-based audio/video classification for containers (like .webm) whose\n// extension alone doesn't say which one they are.\nexport { hasVideoTrack } from './has-video-track'\n// Uploading: choosing files (folders, zip archives, refusals), the upload with progress, and adding\n// from web addresses\nexport {\n UPLOAD_ACCEPT,\n UPLOAD_MAX_FILE_SIZE,\n extractZipFile,\n filesFromDrop,\n isZipFile,\n prepareUploadFiles,\n uploadFolderOf,\n withRelativePath,\n type ExtractedZip,\n type RefusedUploadFile,\n type UploadRefusal,\n type ZipExtractor,\n} from './upload-files'\nexport {\n useUploadFiles,\n uploadedDocumentFolder,\n forgetUploadedDocumentFolder,\n type UploadFilesInput,\n type UploadFilesProgress,\n type UploadFilesResult,\n} from './useUploadFiles'\nexport {\n useUploadFromUrls,\n type UploadFromUrlsInput,\n type UploadFromUrlsResult,\n} from './useUploadFromUrls'\n// How documents relate: email family, made from / copies, duplicates, near-duplicates\nexport {\n useRelatedDocuments,\n getRelatedTotal,\n getRelatedLabels,\n type RelatedDocs,\n type RelatedDocsMap,\n} from './related-documents'\n\n// Offline changes waiting to sync: what changed, how many, per document, and undo\nexport {\n usePendingSyncItems,\n usePendingSyncCounts,\n useDocumentPendingSync,\n useCancelManyPendingSync,\n buildPendingSyncItem,\n PENDING_SYNC_PREDICATE,\n type PendingSyncItem,\n type RawPending,\n} from './pending-sync'\n\n// Documents kept on this device for offline use\nexport {\n useOfflineDocumentIds,\n useKeepDocumentsOffline,\n useRemoveDocumentsOffline,\n loadOfflineDocument,\n getOfflineDocument,\n wipeOfflineDocuments,\n requestPersistentStorage,\n type OfflineDocumentRecord,\n} from './offline-documents'\n"],
|
|
5
|
+
"mappings": "AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA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ACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP;AAAA,EACE;AAAA,OAGK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useArbiWsStore } from "../websocket/store.js";
|
|
2
|
+
import { subscribeDocumentReads } from "./processing-settle.js";
|
|
3
|
+
import { IN_FLIGHT_DOCUMENT_STATUSES, resolveDocumentStatus } from "./processing-order.js";
|
|
4
|
+
const TAGGABLE_DOCUMENT_STATUSES = /* @__PURE__ */ new Set([
|
|
5
|
+
"completed",
|
|
6
|
+
"low-content",
|
|
7
|
+
"empty"
|
|
8
|
+
]);
|
|
9
|
+
const PROCESSING_WAIT_MS = 6 * 60 * 60 * 1e3;
|
|
10
|
+
function documentReadiness(row) {
|
|
11
|
+
if (!row) return "processing";
|
|
12
|
+
const status = resolveDocumentStatus(row, useArbiWsStore.getState().tasks[row.external_id]);
|
|
13
|
+
if (TAGGABLE_DOCUMENT_STATUSES.has(status)) return "processed";
|
|
14
|
+
if (!status || status === "processing" || IN_FLIGHT_DOCUMENT_STATUSES.has(status))
|
|
15
|
+
return "processing";
|
|
16
|
+
return "unprocessable";
|
|
17
|
+
}
|
|
18
|
+
function whenProcessed(qc, docIds, onProcessed) {
|
|
19
|
+
const waiting = new Set(docIds);
|
|
20
|
+
if (!waiting.size) return () => {
|
|
21
|
+
};
|
|
22
|
+
const unsubscribe = subscribeDocumentReads(qc, (rows) => {
|
|
23
|
+
const ready = [];
|
|
24
|
+
for (const row of rows) {
|
|
25
|
+
if (!waiting.has(row.external_id)) continue;
|
|
26
|
+
const readiness = documentReadiness(row);
|
|
27
|
+
if (readiness === "processing") continue;
|
|
28
|
+
waiting.delete(row.external_id);
|
|
29
|
+
if (readiness === "processed") ready.push(row.external_id);
|
|
30
|
+
}
|
|
31
|
+
if (!waiting.size) stop();
|
|
32
|
+
if (ready.length) onProcessed(ready);
|
|
33
|
+
});
|
|
34
|
+
const timer = setTimeout(() => stop(), PROCESSING_WAIT_MS);
|
|
35
|
+
function stop() {
|
|
36
|
+
unsubscribe();
|
|
37
|
+
clearTimeout(timer);
|
|
38
|
+
}
|
|
39
|
+
return stop;
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
PROCESSING_WAIT_MS,
|
|
43
|
+
TAGGABLE_DOCUMENT_STATUSES,
|
|
44
|
+
documentReadiness,
|
|
45
|
+
whenProcessed
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=tag-when-processed.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/documents/tag-when-processed.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * AI fields are filled only on processed documents. The server reads a document's parsed result to\n * fill them, which exists once processing finished well (completed, low-content, empty), and it\n * refuses (409) a request naming any other. A document still processing (an upload's new files)\n * is asked for once a read says it finished (`whenProcessed`); one whose processing failed never.\n */\n\nimport type { QueryClient } from '@tanstack/react-query'\nimport { useArbiWsStore } from '../websocket/store'\nimport type { WorkspaceDocument } from './documents-cache'\nimport { subscribeDocumentReads } from './processing-settle'\nimport { IN_FLIGHT_DOCUMENT_STATUSES, resolveDocumentStatus } from './processing-order'\n\n/** Statuses of a document that can be tagged: its processing finished well. */\nexport const TAGGABLE_DOCUMENT_STATUSES: ReadonlySet<string> = new Set([\n 'completed',\n 'low-content',\n 'empty',\n])\n\n/** How long a document's processing is waited for before its AI fields are given up. */\nexport const PROCESSING_WAIT_MS = 6 * 60 * 60 * 1000\n\nexport type DocumentReadiness = 'processed' | 'processing' | 'unprocessable'\n\n/** Where a document stands for tagging: from its row and the live status heard for it. */\nexport function documentReadiness(row: WorkspaceDocument | undefined): DocumentReadiness {\n if (!row) return 'processing'\n const status = resolveDocumentStatus(row, useArbiWsStore.getState().tasks[row.external_id])\n if (TAGGABLE_DOCUMENT_STATUSES.has(status)) return 'processed'\n if (!status || status === 'processing' || IN_FLIGHT_DOCUMENT_STATUSES.has(status))\n return 'processing'\n // failed, skipped, duplicate, unsupported: never taggable.\n return 'unprocessable'\n}\n\n/**\n * Call `onProcessed` with each of `docIds` once a read says it is processed (several together when\n * one read says so). A document whose processing failed is dropped. Stops when every document is\n * settled, after `PROCESSING_WAIT_MS`, or when the returned function is called.\n */\nexport function whenProcessed(\n qc: QueryClient,\n docIds: readonly string[],\n onProcessed: (docIds: string[]) => void\n): () => void {\n const waiting = new Set(docIds)\n if (!waiting.size) return () => {}\n const unsubscribe = subscribeDocumentReads(qc, (rows) => {\n const ready: string[] = []\n for (const row of rows) {\n if (!waiting.has(row.external_id)) continue\n const readiness = documentReadiness(row)\n if (readiness === 'processing') continue\n waiting.delete(row.external_id)\n if (readiness === 'processed') ready.push(row.external_id)\n }\n if (!waiting.size) stop()\n if (ready.length) onProcessed(ready)\n })\n const timer = setTimeout(() => stop(), PROCESSING_WAIT_MS)\n function stop() {\n unsubscribe()\n clearTimeout(timer)\n }\n return stop\n}\n"],
|
|
5
|
+
"mappings": "AAQA,SAAS,sBAAsB;AAE/B,SAAS,8BAA8B;AACvC,SAAS,6BAA6B,6BAA6B;AAG5D,MAAM,6BAAkD,oBAAI,IAAI;AAAA,EACrE;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAGM,MAAM,qBAAqB,IAAI,KAAK,KAAK;AAKzC,SAAS,kBAAkB,KAAuD;AACvF,MAAI,CAAC,IAAK,QAAO;AACjB,QAAM,SAAS,sBAAsB,KAAK,eAAe,SAAS,EAAE,MAAM,IAAI,WAAW,CAAC;AAC1F,MAAI,2BAA2B,IAAI,MAAM,EAAG,QAAO;AACnD,MAAI,CAAC,UAAU,WAAW,gBAAgB,4BAA4B,IAAI,MAAM;AAC9E,WAAO;AAET,SAAO;AACT;AAOO,SAAS,cACd,IACA,QACA,aACY;AACZ,QAAM,UAAU,IAAI,IAAI,MAAM;AAC9B,MAAI,CAAC,QAAQ,KAAM,QAAO,MAAM;AAAA,EAAC;AACjC,QAAM,cAAc,uBAAuB,IAAI,CAAC,SAAS;AACvD,UAAM,QAAkB,CAAC;AACzB,eAAW,OAAO,MAAM;AACtB,UAAI,CAAC,QAAQ,IAAI,IAAI,WAAW,EAAG;AACnC,YAAM,YAAY,kBAAkB,GAAG;AACvC,UAAI,cAAc,aAAc;AAChC,cAAQ,OAAO,IAAI,WAAW;AAC9B,UAAI,cAAc,YAAa,OAAM,KAAK,IAAI,WAAW;AAAA,IAC3D;AACA,QAAI,CAAC,QAAQ,KAAM,MAAK;AACxB,QAAI,MAAM,OAAQ,aAAY,KAAK;AAAA,EACrC,CAAC;AACD,QAAM,QAAQ,WAAW,MAAM,KAAK,GAAG,kBAAkB;AACzD,WAAS,OAAO;AACd,gBAAY;AACZ,iBAAa,KAAK;AAAA,EACpB;AACA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/host/config.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/host/config.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * What a host hands the `@arbidocs/react` hooks, as one configuration (`<ArbiHost config>`). Every\n * field is optional: without one the hooks use their own default. `@arbidocs/blocks` extends it\n * with the blocks domains (environment, billing, viewer, \u2026).\n *\n * A field whose value lives in the host's state is a hook (`use\u2026`), called by the hooks and kits\n * that need it, so the configuration itself stays one stable object for the host's life.\n */\n\nimport { useContext } from 'react'\nimport type { Arbi } from '@arbidocs/sdk/browser'\nimport type { AccountClient } from '../account/client'\nimport type { CalendarSupport } from '../calendar/support'\nimport type { MeetingChatRef } from '../calls/meeting-chat'\nimport type { ActiveCall } from '../calls/session'\nimport type { ArbiChatHost } from '../chat/host'\nimport type { DocumentsSupport } from '../documents/support'\nimport type { MailClient } from '../mail/client'\nimport type { ArbiSessionStore } from '../session/store'\nimport type { DictateContextValue } from '../ui/DictateContext'\nimport type { EntityVocabulary } from '../entities/vocabulary'\nimport type { ArbiHostConnection } from './ArbiHost'\nimport type { ArbiFeatures } from './features'\nimport { ArbiHostContext } from './context'\nimport type { DashboardsHost } from '../datasets/registry'\n\n/** The mail client, and whether mail is on for the signed-in user. */\nexport interface MailHost {\n client: MailClient\n /**\n * Whether mail reads run (signed in and entitled), and the server session the mailbox is\n * unlocked for: unlocking runs again when it changes (`null`: none yet, nothing is unlocked).\n * Absent: on, for one session.\n */\n useStatus?: () => { enabled: boolean; sessionKey: string | null }\n /**\n * The mail waiting in this device's Outbox (written offline), by status, while `enabled` (Mail\n * switched on); the offline status counts it as waiting work. Absent: no Outbox.\n */\n useOutbox?: (enabled: boolean) => ReadonlyArray<{ status: string }>\n /** The Outbox's folder, opened through `openMail({ folder })`. */\n outboxFolder?: string\n}\n\n/** The account client of the settings kits, and whether account reads run (signed in). */\nexport interface AccountHost {\n client: AccountClient\n /** Absent: always. */\n useEnabled?: () => boolean\n}\n\n/** Where the call panel goes in the host's layout. */\nexport type CallSlotMode = 'docked' | 'main'\n\n/** What the calls need from the host: navigation and layout are the host's. */\nexport interface CallsHost {\n /**\n * Show a call's meeting chat: an end-to-end chat, or a workspace meeting thread. Absent: the\n * in-call \"Open meeting chat\" does nothing.\n */\n openMeetingChat?: (ref: MeetingChatRef) => void\n /**\n * Once connected, show the call's conversation (its chat and live transcript) beside the call.\n * Absent: nothing is shown.\n */\n showConversation?: (call: ActiveCall) => void | Promise<void>\n /**\n * The element whose box the shown call fills: the right-hand dock, or (a webinar's audience) the\n * main area. The host claims its slot while `shown` and calls `onLost` when another panel takes\n * it (the call then minimises). Absent: the call floats at the right edge.\n */\n useSlot?: (mode: CallSlotMode, shown: boolean, onLost: () => void) => HTMLElement | null\n}\n\nexport interface ArbiHostConfig {\n /**\n * The SDK on the signed-in session. A host with its own login passes one on its session\n * (`new Arbi({ url, session })`); a blocks-only site gets one from `defaultHost`. A new instance (a\n * new session, a newly opened workspace) re-renders every hook.\n */\n arbi?: Arbi\n /** The session state the kits share. Absent: an in-memory one per top-level host. */\n session?: ArbiSessionStore\n /** Live processing, uploads and the host's document actions. Absent: the package's own. */\n documents?: DocumentsSupport\n /** The calendar kept on this device and account OAuth. Absent: online only, the user's connectors. */\n calendar?: CalendarSupport\n /** Absent: mail on the `arbi` session. */\n mail?: MailHost\n /** Absent: the account on the `arbi` session. */\n account?: AccountHost\n /** Absent: calls open no meeting chat from the room. */\n calls?: CallsHost\n /**\n * The parts of the product the user switches on or off, and where each switch is kept (the user's\n * settings, or this device), read with `useFeature(name)`. The call UI also follows the `calls`\n * feature, on top of the server's calls config. Absent, or a feature not listed: on.\n */\n features?: ArbiFeatures\n /** Dictation for every `dictate` field. Absent: no mic button. */\n dictate?: DictateContextValue\n /** The sign-in layer of a blocks-only site (`defaultHost` in `@arbidocs/blocks/connect`). */\n connection?: ArbiHostConnection\n /** Where the chat engine's side effects go (documents shown, mail drafts, used-up quota). */\n chat?: ArbiChatHost\n /**\n * The site's words for the entities (`{ PROJECT: 'Matter' }`), read by every kit through\n * `getEntityLabel`. Absent: the registry's (\"Project\", \"Workspace\", \"Thread\", \u2026).\n */\n vocabulary?: EntityVocabulary\n /**\n * What the site calls its assistant where people address it: the `@<name>` offered in a chat's\n * mention menu, the draft a shared thread starts with, and the name a message is routed to the\n * assistant on. Absent: \"ARBI\".\n */\n assistantName?: string\n /**\n * Charts and dashboards: more data sources (an external feed, a source relabelled in the site's\n * words)
|
|
4
|
+
"sourcesContent": ["/**\n * What a host hands the `@arbidocs/react` hooks, as one configuration (`<ArbiHost config>`). Every\n * field is optional: without one the hooks use their own default. `@arbidocs/blocks` extends it\n * with the blocks domains (environment, billing, viewer, \u2026).\n *\n * A field whose value lives in the host's state is a hook (`use\u2026`), called by the hooks and kits\n * that need it, so the configuration itself stays one stable object for the host's life.\n */\n\nimport { useContext } from 'react'\nimport type { Arbi } from '@arbidocs/sdk/browser'\nimport type { AccountClient } from '../account/client'\nimport type { CalendarSupport } from '../calendar/support'\nimport type { MeetingChatRef } from '../calls/meeting-chat'\nimport type { ActiveCall } from '../calls/session'\nimport type { ArbiChatHost } from '../chat/host'\nimport type { DocumentsSupport } from '../documents/support'\nimport type { MailClient } from '../mail/client'\nimport type { ArbiSessionStore } from '../session/store'\nimport type { DictateContextValue } from '../ui/DictateContext'\nimport type { EntityVocabulary } from '../entities/vocabulary'\nimport type { ArbiHostConnection } from './ArbiHost'\nimport type { ArbiFeatures } from './features'\nimport { ArbiHostContext } from './context'\nimport type { DashboardsHost } from '../datasets/registry'\n\n/** The mail client, and whether mail is on for the signed-in user. */\nexport interface MailHost {\n client: MailClient\n /**\n * Whether mail reads run (signed in and entitled), and the server session the mailbox is\n * unlocked for: unlocking runs again when it changes (`null`: none yet, nothing is unlocked).\n * Absent: on, for one session.\n */\n useStatus?: () => { enabled: boolean; sessionKey: string | null }\n /**\n * The mail waiting in this device's Outbox (written offline), by status, while `enabled` (Mail\n * switched on); the offline status counts it as waiting work. Absent: no Outbox.\n */\n useOutbox?: (enabled: boolean) => ReadonlyArray<{ status: string }>\n /** The Outbox's folder, opened through `openMail({ folder })`. */\n outboxFolder?: string\n}\n\n/** The account client of the settings kits, and whether account reads run (signed in). */\nexport interface AccountHost {\n client: AccountClient\n /** Absent: always. */\n useEnabled?: () => boolean\n}\n\n/** Where the call panel goes in the host's layout. */\nexport type CallSlotMode = 'docked' | 'main'\n\n/** What the calls need from the host: navigation and layout are the host's. */\nexport interface CallsHost {\n /**\n * Show a call's meeting chat: an end-to-end chat, or a workspace meeting thread. Absent: the\n * in-call \"Open meeting chat\" does nothing.\n */\n openMeetingChat?: (ref: MeetingChatRef) => void\n /**\n * Once connected, show the call's conversation (its chat and live transcript) beside the call.\n * Absent: nothing is shown.\n */\n showConversation?: (call: ActiveCall) => void | Promise<void>\n /**\n * The element whose box the shown call fills: the right-hand dock, or (a webinar's audience) the\n * main area. The host claims its slot while `shown` and calls `onLost` when another panel takes\n * it (the call then minimises). Absent: the call floats at the right edge.\n */\n useSlot?: (mode: CallSlotMode, shown: boolean, onLost: () => void) => HTMLElement | null\n}\n\nexport interface ArbiHostConfig {\n /**\n * The SDK on the signed-in session. A host with its own login passes one on its session\n * (`new Arbi({ url, session })`); a blocks-only site gets one from `defaultHost`. A new instance (a\n * new session, a newly opened workspace) re-renders every hook.\n */\n arbi?: Arbi\n /** The session state the kits share. Absent: an in-memory one per top-level host. */\n session?: ArbiSessionStore\n /** Live processing, uploads and the host's document actions. Absent: the package's own. */\n documents?: DocumentsSupport\n /** The calendar kept on this device and account OAuth. Absent: online only, the user's connectors. */\n calendar?: CalendarSupport\n /** Absent: mail on the `arbi` session. */\n mail?: MailHost\n /** Absent: the account on the `arbi` session. */\n account?: AccountHost\n /** Absent: calls open no meeting chat from the room. */\n calls?: CallsHost\n /**\n * The parts of the product the user switches on or off, and where each switch is kept (the user's\n * settings, or this device), read with `useFeature(name)`. The call UI also follows the `calls`\n * feature, on top of the server's calls config. Absent, or a feature not listed: on.\n */\n features?: ArbiFeatures\n /** Dictation for every `dictate` field. Absent: no mic button. */\n dictate?: DictateContextValue\n /** The sign-in layer of a blocks-only site (`defaultHost` in `@arbidocs/blocks/connect`). */\n connection?: ArbiHostConnection\n /** Where the chat engine's side effects go (documents shown, mail drafts, used-up quota). */\n chat?: ArbiChatHost\n /**\n * The site's words for the entities (`{ PROJECT: 'Matter' }`), read by every kit through\n * `getEntityLabel`. Absent: the registry's (\"Project\", \"Workspace\", \"Thread\", \u2026).\n */\n vocabulary?: EntityVocabulary\n /**\n * What the site calls its assistant where people address it: the `@<name>` offered in a chat's\n * mention menu, the draft a shared thread starts with, and the name a message is routed to the\n * assistant on. Absent: \"ARBI\".\n */\n assistantName?: string\n /**\n * Charts and dashboards: more data sources (an external feed, a source relabelled in the site's\n * words). Pages themselves are the workspace's (`/v1/pages`). Absent: the built-in sources.\n */\n dashboards?: DashboardsHost\n}\n\n/** The host configuration in scope (`{}` outside an `<ArbiHost>`). */\nexport function useArbiHost(): ArbiHostConfig {\n return useContext(ArbiHostContext) as ArbiHostConfig\n}\n"],
|
|
5
5
|
"mappings": "AASA,SAAS,kBAAkB;AAc3B,SAAS,uBAAuB;AAqGzB,SAAS,cAA8B;AAC5C,SAAO,WAAW,eAAe;AACnC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|