@arbidocs/react 0.4.144 → 0.4.146

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.
@@ -3,6 +3,7 @@
3
3
  var chunkR2MF7YCW_cjs = require('./chunk-R2MF7YCW.cjs');
4
4
  var react = require('react');
5
5
  var reactQuery = require('@tanstack/react-query');
6
+ var browser = require('@arbidocs/sdk/browser');
6
7
 
7
8
  // src/usage-metered.ts
8
9
  function isUsageMetered(usage, subscription) {
@@ -12,7 +13,15 @@ function isUsageMetered(usage, subscription) {
12
13
  var arbiQueryKeys = {
13
14
  workspaces: () => ["arbi", "workspaces"],
14
15
  workspaceUsers: (workspaceId) => ["arbi", "workspaceUsers", workspaceId],
16
+ /** Every workspace's documents list: the prefix a write patches when it does not know the workspace. */
17
+ allDocuments: () => ["arbi", "documents"],
15
18
  documents: (workspaceId) => ["arbi", "documents", workspaceId],
19
+ /** One document (a viewer's); writes keep it current next to the list. */
20
+ document: (docId) => ["arbi", "document", docId],
21
+ documentsById: (docIds) => ["arbi", "documentsById", [...docIds].sort().join(",")],
22
+ /** Every workspace's near-duplicate pairs. */
23
+ allSimilarDocuments: () => ["arbi", "similarDocuments"],
24
+ similarDocuments: (workspaceId, threshold) => ["arbi", "similarDocuments", workspaceId, threshold],
16
25
  /** Every version list: the prefix a new version invalidates. */
17
26
  allDocumentVersions: () => ["arbi", "documentVersions"],
18
27
  documentVersions: (docId) => ["arbi", "documentVersions", docId],
@@ -36,6 +45,8 @@ var arbiQueryKeys = {
36
45
  /** Under the conversations prefix: every step action or conversation write refreshes it. */
37
46
  conversationUsage: (conversationId) => ["arbi", "conversations", conversationId, "usage"],
38
47
  thumbnails: (docIds) => ["arbi", "thumbnails", [...docIds].sort().join(",")],
48
+ /** Every stage of a document's parsed content. */
49
+ parsedDocument: (docId) => ["arbi", "parsedDoc", docId],
39
50
  parsedDoc: (docId, stage) => ["arbi", "parsedDoc", docId, stage],
40
51
  agents: () => ["arbi", "agents"],
41
52
  sessions: () => ["arbi", "sessions"],
@@ -74,6 +85,7 @@ var arbiQueryKeys = {
74
85
  authorizeLimits: () => ["arbi", "authorizeLimits"],
75
86
  mcpTools: () => ["arbi", "mcpTools"],
76
87
  models: () => ["arbi", "models"],
88
+ availableModels: () => ["arbi", "availableModels"],
77
89
  /** The signed-in user's own profile (name, picture, email). */
78
90
  profile: () => ["arbi", "profile"],
79
91
  identity: () => ["arbi", "identity"],
@@ -92,7 +104,17 @@ var arbiMutationKeys = {
92
104
  createTag: () => ["arbi", "tags", "create"],
93
105
  updateTag: () => ["arbi", "tags", "update"],
94
106
  deleteTag: () => ["arbi", "tags", "delete"],
95
- extractEntities: () => ["arbi", "tags", "entities", "extract"]
107
+ extractEntities: () => ["arbi", "tags", "entities", "extract"],
108
+ updateDocuments: () => ["arbi", "documents", "update"],
109
+ deleteDocuments: () => ["arbi", "documents", "delete"],
110
+ uploadDocuments: () => ["arbi", "documents", "upload"],
111
+ uploadUrls: () => ["arbi", "documents", "uploadUrls"],
112
+ assignDocTags: () => ["arbi", "doctags", "assign"],
113
+ removeDocTags: () => ["arbi", "doctags", "remove"],
114
+ updateDocTag: () => ["arbi", "doctags", "update"],
115
+ generateDocTags: () => ["arbi", "doctags", "generate"],
116
+ /** Members added to or removed from a workspace (leaving included). */
117
+ workspaceMembership: () => ["arbi", "workspaces", "members"]
96
118
  };
97
119
  function useWorkspaceUsers(workspaceId, options) {
98
120
  const arbi = chunkR2MF7YCW_cjs.useArbi();
@@ -115,14 +137,6 @@ function useWorkspaces(options) {
115
137
  enabled: options?.enabled ?? arbi.isLoggedIn
116
138
  });
117
139
  }
118
- function useDocuments(workspaceId, options) {
119
- const arbi = chunkR2MF7YCW_cjs.useArbi();
120
- return reactQuery.useQuery({
121
- queryKey: arbiQueryKeys.documents(workspaceId ?? ""),
122
- queryFn: () => arbi.documents.list(),
123
- enabled: (options?.enabled ?? true) && !!workspaceId && arbi.hasWorkspace
124
- });
125
- }
126
140
  function useDocumentVersionList(docId, options) {
127
141
  const arbi = chunkR2MF7YCW_cjs.useArbi();
128
142
  return reactQuery.useQuery({
@@ -227,6 +241,15 @@ function useHealth(options) {
227
241
  enabled: options?.enabled
228
242
  });
229
243
  }
244
+ function useAvailableModels(options) {
245
+ const arbi = chunkR2MF7YCW_cjs.useArbi();
246
+ return reactQuery.useQuery({
247
+ queryKey: arbiQueryKeys.availableModels(),
248
+ queryFn: () => arbi.health.models(),
249
+ staleTime: Infinity,
250
+ enabled: (options?.enabled ?? true) && arbi.isLoggedIn
251
+ });
252
+ }
230
253
  function useConfigs(options) {
231
254
  const arbi = chunkR2MF7YCW_cjs.useArbi();
232
255
  return reactQuery.useQuery({
@@ -407,35 +430,495 @@ function useUserUsageToday(options) {
407
430
  staleTime: 15e3
408
431
  });
409
432
  }
433
+ function openWorkspaceId(arbi) {
434
+ return arbi.hasWorkspace ? arbi.getWorkspaceId() : null;
435
+ }
436
+ function patchWorkspaceTags(qc, workspaceId, reducer) {
437
+ const key = arbiQueryKeys.tags(workspaceId);
438
+ const current = qc.getQueryData(key);
439
+ if (!current) return;
440
+ const next = reducer(current);
441
+ if (next !== current) qc.setQueryData(key, next);
442
+ }
443
+ function invalidateTagTables(qc, workspaceId) {
444
+ return qc.invalidateQueries({ queryKey: arbiQueryKeys.tagLists(workspaceId) });
445
+ }
446
+ function invalidateTagData(qc, workspaceId) {
447
+ return Promise.all([
448
+ qc.invalidateQueries({ queryKey: arbiQueryKeys.tags(workspaceId) }),
449
+ qc.invalidateQueries({ queryKey: arbiQueryKeys.facts(workspaceId) })
450
+ ]);
451
+ }
452
+ function useInvalidateTagData() {
453
+ const arbi = chunkR2MF7YCW_cjs.useArbi();
454
+ const qc = reactQuery.useQueryClient();
455
+ return react.useCallback(() => {
456
+ const workspaceId = openWorkspaceId(arbi);
457
+ return workspaceId ? invalidateTagData(qc, workspaceId) : Promise.resolve();
458
+ }, [arbi, qc]);
459
+ }
460
+ function settleCreatedTag(qc, created) {
461
+ const workspaceId = created.workspace_ext_id;
462
+ patchWorkspaceTags(
463
+ qc,
464
+ workspaceId,
465
+ (old) => old.some((t) => t.external_id === created.external_id) ? old : [...old, created]
466
+ );
467
+ return invalidateTagTables(qc, workspaceId);
468
+ }
469
+ function settleChangedTag(qc, tag) {
470
+ const workspaceId = tag.workspace_ext_id;
471
+ patchWorkspaceTags(
472
+ qc,
473
+ workspaceId,
474
+ (old) => old.map((t) => t.external_id === tag.external_id ? { ...t, ...tag } : t)
475
+ );
476
+ return invalidateTagTables(qc, workspaceId);
477
+ }
478
+ var replayableTagMutations = [
479
+ {
480
+ mutationKey: arbiMutationKeys.createTag(),
481
+ run: (client, input) => browser.tags.createTag(client, input),
482
+ settle: (qc, created) => settleCreatedTag(qc, created)
483
+ }
484
+ ];
485
+ function useCreateTag() {
486
+ const arbi = chunkR2MF7YCW_cjs.useArbi();
487
+ const qc = reactQuery.useQueryClient();
488
+ return reactQuery.useMutation({
489
+ mutationKey: arbiMutationKeys.createTag(),
490
+ mutationFn: (input) => arbi.tags.create(input),
491
+ onSuccess: (created) => settleCreatedTag(qc, created)
492
+ });
493
+ }
494
+ function useUpdateTag() {
495
+ const arbi = chunkR2MF7YCW_cjs.useArbi();
496
+ const qc = reactQuery.useQueryClient();
497
+ return reactQuery.useMutation({
498
+ mutationKey: arbiMutationKeys.updateTag(),
499
+ mutationFn: ({ tagId, change }) => arbi.tags.update(tagId, change),
500
+ onSuccess: (tag) => settleChangedTag(qc, tag)
501
+ });
502
+ }
503
+ function useSetTagValues() {
504
+ const arbi = chunkR2MF7YCW_cjs.useArbi();
505
+ const qc = reactQuery.useQueryClient();
506
+ return reactQuery.useMutation({
507
+ mutationKey: arbiMutationKeys.updateTag(),
508
+ mutationFn: ({
509
+ tagId,
510
+ values
511
+ }) => arbi.tags.setValues(tagId, values),
512
+ onSuccess: (tag) => settleChangedTag(qc, tag)
513
+ });
514
+ }
515
+ function useDeleteTag() {
516
+ const arbi = chunkR2MF7YCW_cjs.useArbi();
517
+ const qc = reactQuery.useQueryClient();
518
+ return reactQuery.useMutation({
519
+ mutationKey: arbiMutationKeys.deleteTag(),
520
+ mutationFn: (tagId) => arbi.tags.delete(tagId),
521
+ onSuccess: (_data, tagId) => {
522
+ const workspaceId = openWorkspaceId(arbi);
523
+ if (!workspaceId) return;
524
+ patchWorkspaceTags(
525
+ qc,
526
+ workspaceId,
527
+ (old) => old.filter((t) => t.external_id !== tagId).map((t) => t.parent_ext_id === tagId ? { ...t, parent_ext_id: null } : t)
528
+ );
529
+ return Promise.all([
530
+ invalidateTagTables(qc, workspaceId),
531
+ qc.invalidateQueries({ queryKey: arbiQueryKeys.facts(workspaceId) })
532
+ ]);
533
+ }
534
+ });
535
+ }
536
+ function useExtractEntities() {
537
+ const arbi = chunkR2MF7YCW_cjs.useArbi();
538
+ return reactQuery.useMutation({
539
+ mutationKey: arbiMutationKeys.extractEntities(),
540
+ mutationFn: (docIds) => arbi.tags.extractEntities(docIds)
541
+ });
542
+ }
543
+ function useTagKindSchema(kind, options) {
544
+ const arbi = chunkR2MF7YCW_cjs.useArbi();
545
+ const workspaceId = openWorkspaceId(arbi) ?? "";
546
+ return reactQuery.useQuery({
547
+ queryKey: arbiQueryKeys.tagKind(workspaceId, kind ?? ""),
548
+ queryFn: () => arbi.tagKinds.get(kind),
549
+ enabled: (options?.enabled ?? true) && !!kind && !!workspaceId
550
+ });
551
+ }
552
+ function useUpdateTagKindSchema() {
553
+ const arbi = chunkR2MF7YCW_cjs.useArbi();
554
+ const qc = reactQuery.useQueryClient();
555
+ return reactQuery.useMutation({
556
+ mutationKey: arbiMutationKeys.updateTagKindSchema(),
557
+ mutationFn: ({
558
+ kind,
559
+ fields
560
+ }) => arbi.tagKinds.update(kind, fields),
561
+ onSuccess: (schema) => {
562
+ const workspaceId = openWorkspaceId(arbi);
563
+ if (!workspaceId) return;
564
+ qc.setQueryData(arbiQueryKeys.tagKind(workspaceId, schema.kind), schema);
565
+ return invalidateTagData(qc, workspaceId);
566
+ }
567
+ });
568
+ }
569
+
570
+ // src/documents/documents-cache.ts
571
+ var rowListeners = /* @__PURE__ */ new Set();
572
+ function subscribeDocumentRows(listener) {
573
+ rowListeners.add(listener);
574
+ return () => {
575
+ rowListeners.delete(listener);
576
+ };
577
+ }
578
+ function getCachedDocuments(qc, workspaceId) {
579
+ if (!workspaceId) return void 0;
580
+ return qc.getQueryData(arbiQueryKeys.documents(workspaceId));
581
+ }
582
+ function cachedLists(qc) {
583
+ return qc.getQueriesData({ queryKey: arbiQueryKeys.allDocuments() }).flatMap(
584
+ ([key, data]) => typeof key[2] === "string" && Array.isArray(data) ? [[key[2], data]] : []
585
+ );
586
+ }
587
+ function diffRows(workspaceId, before, after) {
588
+ const beforeById = new Map(before.map((doc) => [doc.external_id, doc]));
589
+ const add = [];
590
+ const update = [];
591
+ const seen = /* @__PURE__ */ new Set();
592
+ for (const doc of after) {
593
+ seen.add(doc.external_id);
594
+ const previous = beforeById.get(doc.external_id);
595
+ if (!previous) add.push(doc);
596
+ else if (previous !== doc) update.push(doc);
597
+ }
598
+ const remove = [...beforeById.keys()].filter((id) => !seen.has(id));
599
+ return { workspaceId, add, update, remove };
600
+ }
601
+ function patchDocuments(qc, reducer, workspaceId) {
602
+ const lists = workspaceId ? (() => {
603
+ const current = getCachedDocuments(qc, workspaceId);
604
+ return current ? [[workspaceId, current]] : [];
605
+ })() : cachedLists(qc);
606
+ for (const [id, before] of lists) {
607
+ const after = reducer(before);
608
+ if (after === before) continue;
609
+ qc.setQueryData(arbiQueryKeys.documents(id), after);
610
+ const change = diffRows(id, before, after);
611
+ const beforeById = new Map(before.map((doc) => [doc.external_id, doc]));
612
+ if (change.update.some(
613
+ (doc) => doc.current_version !== beforeById.get(doc.external_id)?.current_version
614
+ ))
615
+ void qc.invalidateQueries({ queryKey: arbiQueryKeys.allDocumentVersions() });
616
+ if (change.add.length || change.update.length || change.remove.length)
617
+ for (const listener of rowListeners) listener(change);
618
+ }
619
+ }
620
+ function upsertDocuments(qc, documents, workspaceId) {
621
+ if (!documents.length) return;
622
+ const byId = new Map(documents.map((doc) => [doc.external_id, doc]));
623
+ const byWorkspace = /* @__PURE__ */ new Map();
624
+ for (const doc of documents) {
625
+ const ws = workspaceId ?? doc.workspace_ext_id;
626
+ byWorkspace.set(ws, [...byWorkspace.get(ws) ?? [], doc]);
627
+ }
628
+ for (const [ws, incoming] of byWorkspace) {
629
+ patchDocuments(
630
+ qc,
631
+ (old) => {
632
+ const known = new Set(old.map((doc) => doc.external_id));
633
+ return [
634
+ ...old.map((doc) => byId.get(doc.external_id) ?? doc),
635
+ ...incoming.filter((doc) => !known.has(doc.external_id))
636
+ ];
637
+ },
638
+ ws
639
+ );
640
+ }
641
+ }
642
+ function setCachedDocument(qc, doc) {
643
+ qc.setQueryData(arbiQueryKeys.document(doc.external_id), doc);
644
+ }
645
+ function patchCachedDocument(qc, docId, reducer) {
646
+ const current = qc.getQueryData(arbiQueryKeys.document(docId));
647
+ if (current) qc.setQueryData(arbiQueryKeys.document(docId), reducer(current));
648
+ }
649
+ function forgetDocuments(qc, docIds) {
650
+ for (const id of docIds) {
651
+ qc.removeQueries({ queryKey: arbiQueryKeys.document(id) });
652
+ qc.removeQueries({ queryKey: arbiQueryKeys.documentVersions(id) });
653
+ qc.removeQueries({ queryKey: arbiQueryKeys.parsedDocument(id) });
654
+ }
655
+ }
656
+ var DOCUMENTS_FIRST_PAGE_SIZE = 500;
657
+ var DOCUMENTS_PAGE_SIZE = 2e3;
658
+ var DOCUMENTS_FIRST_PAGE_MEASURE = "arbi:document-list:page1";
659
+ var FIRST_PAGE_MEASURE = DOCUMENTS_FIRST_PAGE_MEASURE;
660
+ var FIRST_PAGE_START = "arbi:document-list:start";
661
+ function mark(name) {
662
+ try {
663
+ performance.mark(name);
664
+ } catch {
665
+ }
666
+ }
667
+ function measure(name, start) {
668
+ try {
669
+ performance.measure(name, start);
670
+ } catch {
671
+ }
672
+ }
673
+ var backgroundReads = /* @__PURE__ */ new Map();
674
+ var loadingListeners = /* @__PURE__ */ new Set();
675
+ function emitLoading() {
676
+ for (const listener of loadingListeners) listener();
677
+ }
678
+ function subscribeLoading(listener) {
679
+ loadingListeners.add(listener);
680
+ return () => {
681
+ loadingListeners.delete(listener);
682
+ };
683
+ }
684
+ function isDocumentsLoading() {
685
+ return backgroundReads.size > 0;
686
+ }
687
+ function useDocumentsLoading() {
688
+ return react.useSyncExternalStore(subscribeLoading, isDocumentsLoading, () => false);
689
+ }
690
+ function stopDocumentsLoading(workspaceId) {
691
+ const controller = backgroundReads.get(workspaceId);
692
+ if (!controller) return;
693
+ controller.abort();
694
+ backgroundReads.delete(workspaceId);
695
+ emitLoading();
696
+ }
697
+ async function loadDocuments(qc, arbi, workspaceId, signal) {
698
+ let stopped = false;
699
+ for (const [id, controller2] of backgroundReads) {
700
+ if (id === workspaceId) continue;
701
+ controller2.abort();
702
+ backgroundReads.delete(id);
703
+ stopped = true;
704
+ }
705
+ if (stopped) emitLoading();
706
+ const controller = new AbortController();
707
+ signal?.addEventListener("abort", () => controller.abort(), { once: true });
708
+ const pages = arbi.documents.listPaginated({
709
+ pageSize: DOCUMENTS_PAGE_SIZE,
710
+ firstPageSize: DOCUMENTS_FIRST_PAGE_SIZE,
711
+ signal: controller.signal
712
+ });
713
+ mark(FIRST_PAGE_START);
714
+ const first = await pages.next();
715
+ const firstPage = first.done ? [] : first.value;
716
+ measure(FIRST_PAGE_MEASURE, FIRST_PAGE_START);
717
+ if (first.done || firstPage.length < DOCUMENTS_FIRST_PAGE_SIZE) return firstPage;
718
+ if (backgroundReads.has(workspaceId)) {
719
+ controller.abort();
720
+ return firstPage;
721
+ }
722
+ backgroundReads.set(workspaceId, controller);
723
+ emitLoading();
724
+ void appendRemainingPages(qc, workspaceId, pages, controller.signal).finally(() => {
725
+ if (backgroundReads.get(workspaceId) !== controller) return;
726
+ backgroundReads.delete(workspaceId);
727
+ emitLoading();
728
+ });
729
+ return firstPage;
730
+ }
731
+ async function appendRemainingPages(qc, workspaceId, pages, signal) {
732
+ await Promise.resolve();
733
+ try {
734
+ for await (const page of pages) {
735
+ if (signal.aborted) return;
736
+ patchDocuments(
737
+ qc,
738
+ (old) => {
739
+ const known = new Set(old.map((doc) => doc.external_id));
740
+ const fresh = page.filter((doc) => !known.has(doc.external_id));
741
+ return fresh.length ? [...old, ...fresh] : old;
742
+ },
743
+ workspaceId
744
+ );
745
+ }
746
+ } catch (error) {
747
+ if (!signal.aborted) console.error(`Reading the documents of ${workspaceId} failed:`, error);
748
+ }
749
+ }
750
+ var FINISHED_DOCUMENT_STATUSES = /* @__PURE__ */ new Set([
751
+ "completed",
752
+ "low-content",
753
+ "failed",
754
+ "skipped",
755
+ "empty"
756
+ ]);
757
+ function openWorkspaceId2(arbi) {
758
+ return arbi.hasWorkspace ? arbi.getWorkspaceId() : null;
759
+ }
760
+ function useDocuments(workspaceId, options) {
761
+ const arbi = chunkR2MF7YCW_cjs.useArbi();
762
+ const qc = reactQuery.useQueryClient();
763
+ const workspace = workspaceId ?? openWorkspaceId2(arbi) ?? "";
764
+ return reactQuery.useQuery({
765
+ queryKey: arbiQueryKeys.documents(workspace),
766
+ queryFn: ({ signal }) => {
767
+ if (openWorkspaceId2(arbi) !== workspace)
768
+ return Promise.reject(new Error("The selected workspace changed."));
769
+ return loadDocuments(qc, arbi, workspace, signal);
770
+ },
771
+ enabled: (options?.enabled ?? true) && !!workspace && arbi.hasWorkspace,
772
+ staleTime: Infinity,
773
+ refetchOnMount: false,
774
+ refetchOnReconnect: false,
775
+ refetchOnWindowFocus: false
776
+ });
777
+ }
778
+ var DOCUMENT_STATUS_POLL_MS = 4e3;
779
+ function processingInterval(doc) {
780
+ return doc?.status && !FINISHED_DOCUMENT_STATUSES.has(doc.status) ? DOCUMENT_STATUS_POLL_MS : false;
781
+ }
782
+ function useDocument(docId, options) {
783
+ const arbi = chunkR2MF7YCW_cjs.useArbi();
784
+ return reactQuery.useQuery({
785
+ queryKey: arbiQueryKeys.document(docId ?? ""),
786
+ queryFn: async () => (await arbi.documents.get([docId]))[0] ?? null,
787
+ enabled: (options?.enabled ?? true) && !!docId && arbi.isLoggedIn,
788
+ refetchInterval: options?.pollWhileProcessing ? (query) => processingInterval(query.state.data) : false
789
+ });
790
+ }
791
+ function useDocumentsById(docIds, options) {
792
+ const arbi = chunkR2MF7YCW_cjs.useArbi();
793
+ return reactQuery.useQuery({
794
+ queryKey: arbiQueryKeys.documentsById(docIds),
795
+ queryFn: () => arbi.documents.get(docIds),
796
+ enabled: (options?.enabled ?? true) && docIds.length > 0 && arbi.isLoggedIn
797
+ });
798
+ }
799
+ var SIMILARITY_THRESHOLD = 0.98;
800
+ function useSimilarDocuments(options) {
801
+ const arbi = chunkR2MF7YCW_cjs.useArbi();
802
+ const workspace = openWorkspaceId2(arbi) ?? "";
803
+ return reactQuery.useQuery({
804
+ queryKey: arbiQueryKeys.similarDocuments(workspace, SIMILARITY_THRESHOLD),
805
+ queryFn: () => arbi.documents.similar({ threshold: SIMILARITY_THRESHOLD }),
806
+ enabled: (options?.enabled ?? true) && !!workspace
807
+ });
808
+ }
809
+ var readSeq = 0;
810
+ var latestReadByDoc = /* @__PURE__ */ new Map();
811
+ async function refreshDocuments(qc, arbi, docIds, options) {
812
+ if (!docIds.length) return [];
813
+ const seq = ++readSeq;
814
+ for (const id of docIds) latestReadByDoc.set(id, seq);
815
+ try {
816
+ const read = await arbi.documents.get(docIds);
817
+ const fresh = read.filter((doc) => latestReadByDoc.get(doc.external_id) === seq).map((doc) => {
818
+ const live = options?.processingStatus?.(doc.external_id);
819
+ return live && FINISHED_DOCUMENT_STATUSES.has(live) && doc.status !== live ? { ...doc, status: live } : doc;
820
+ });
821
+ if (!fresh.length) return [];
822
+ reconcileTagCounts(qc, fresh);
823
+ upsertDocuments(qc, fresh);
824
+ for (const doc of fresh) setCachedDocument(qc, doc);
825
+ return fresh;
826
+ } catch (error) {
827
+ console.error("Re-reading documents failed; the cached ones are kept:", error);
828
+ return [];
829
+ } finally {
830
+ for (const id of docIds) if (latestReadByDoc.get(id) === seq) latestReadByDoc.delete(id);
831
+ }
832
+ }
833
+ function reconcileTagCounts(qc, fresh) {
834
+ const byWorkspace = /* @__PURE__ */ new Map();
835
+ for (const doc of fresh) {
836
+ const cached = getCachedDocuments(qc, doc.workspace_ext_id)?.find(
837
+ (d) => d.external_id === doc.external_id
838
+ );
839
+ const before = new Set((cached?.doctags ?? []).map((dt) => dt.tag_ext_id));
840
+ const after = new Set((doc.doctags ?? []).map((dt) => dt.tag_ext_id));
841
+ const delta = byWorkspace.get(doc.workspace_ext_id) ?? /* @__PURE__ */ new Map();
842
+ for (const id of after) if (!before.has(id)) delta.set(id, (delta.get(id) ?? 0) + 1);
843
+ for (const id of before) if (!after.has(id)) delta.set(id, (delta.get(id) ?? 0) - 1);
844
+ byWorkspace.set(doc.workspace_ext_id, delta);
845
+ }
846
+ for (const [workspaceId, delta] of byWorkspace) adjustTagCounts(qc, workspaceId, delta);
847
+ }
848
+ function adjustTagCounts(qc, workspaceId, delta) {
849
+ if (![...delta.values()].some(Boolean)) return;
850
+ patchWorkspaceTags(
851
+ qc,
852
+ workspaceId,
853
+ (tags) => tags.map((tag) => {
854
+ const change = delta.get(tag.external_id);
855
+ return change ? { ...tag, doctag_count: Math.max(0, tag.doctag_count + change) } : tag;
856
+ })
857
+ );
858
+ void invalidateTagTables(qc, workspaceId);
859
+ }
410
860
 
861
+ exports.DOCUMENTS_FIRST_PAGE_MEASURE = DOCUMENTS_FIRST_PAGE_MEASURE;
862
+ exports.DOCUMENTS_FIRST_PAGE_SIZE = DOCUMENTS_FIRST_PAGE_SIZE;
863
+ exports.DOCUMENTS_PAGE_SIZE = DOCUMENTS_PAGE_SIZE;
864
+ exports.FINISHED_DOCUMENT_STATUSES = FINISHED_DOCUMENT_STATUSES;
411
865
  exports.PROJECT_CREATION_DENIED_REASON = PROJECT_CREATION_DENIED_REASON;
866
+ exports.SIMILARITY_THRESHOLD = SIMILARITY_THRESHOLD;
867
+ exports.adjustTagCounts = adjustTagCounts;
412
868
  exports.arbiMutationKeys = arbiMutationKeys;
413
869
  exports.arbiQueryKeys = arbiQueryKeys;
870
+ exports.forgetDocuments = forgetDocuments;
871
+ exports.getCachedDocuments = getCachedDocuments;
872
+ exports.invalidateTagData = invalidateTagData;
873
+ exports.invalidateTagTables = invalidateTagTables;
874
+ exports.isDocumentsLoading = isDocumentsLoading;
414
875
  exports.isUsageMetered = isUsageMetered;
876
+ exports.patchCachedDocument = patchCachedDocument;
877
+ exports.patchDocuments = patchDocuments;
878
+ exports.patchWorkspaceTags = patchWorkspaceTags;
879
+ exports.refreshDocuments = refreshDocuments;
880
+ exports.replayableTagMutations = replayableTagMutations;
881
+ exports.setCachedDocument = setCachedDocument;
882
+ exports.stopDocumentsLoading = stopDocumentsLoading;
883
+ exports.subscribeDocumentRows = subscribeDocumentRows;
884
+ exports.upsertDocuments = upsertDocuments;
415
885
  exports.useActivity = useActivity;
416
886
  exports.useAgents = useAgents;
417
887
  exports.useAssistantQuery = useAssistantQuery;
888
+ exports.useAvailableModels = useAvailableModels;
418
889
  exports.useCanCreateProjects = useCanCreateProjects;
419
890
  exports.useConfigs = useConfigs;
420
891
  exports.useConversationThreads = useConversationThreads;
421
892
  exports.useConversations = useConversations;
893
+ exports.useCreateTag = useCreateTag;
422
894
  exports.useCurrentUser = useCurrentUser;
423
895
  exports.useDeleteAgents = useDeleteAgents;
896
+ exports.useDeleteTag = useDeleteTag;
897
+ exports.useDocument = useDocument;
424
898
  exports.useDocumentVersionList = useDocumentVersionList;
425
899
  exports.useDocuments = useDocuments;
900
+ exports.useDocumentsById = useDocumentsById;
901
+ exports.useDocumentsLoading = useDocumentsLoading;
902
+ exports.useExtractEntities = useExtractEntities;
426
903
  exports.useFirmPool = useFirmPool;
427
904
  exports.useHealth = useHealth;
905
+ exports.useInvalidateTagData = useInvalidateTagData;
428
906
  exports.useParsedDocument = useParsedDocument;
429
907
  exports.useProjectInvoices = useProjectInvoices;
430
908
  exports.useProjectUsage = useProjectUsage;
431
909
  exports.useProjects = useProjects;
432
910
  exports.useProjectsUsage = useProjectsUsage;
911
+ exports.useSetTagValues = useSetTagValues;
912
+ exports.useSimilarDocuments = useSimilarDocuments;
913
+ exports.useTagKindSchema = useTagKindSchema;
433
914
  exports.useTags = useTags;
434
915
  exports.useThumbnails = useThumbnails;
435
916
  exports.useTopUpFirmPool = useTopUpFirmPool;
917
+ exports.useUpdateTag = useUpdateTag;
918
+ exports.useUpdateTagKindSchema = useUpdateTagKindSchema;
436
919
  exports.useUserUsageToday = useUserUsageToday;
437
920
  exports.useWorkspaceActivity = useWorkspaceActivity;
438
921
  exports.useWorkspaceUsers = useWorkspaceUsers;
439
922
  exports.useWorkspaces = useWorkspaces;
440
- //# sourceMappingURL=chunk-CVJ25DFD.cjs.map
441
- //# sourceMappingURL=chunk-CVJ25DFD.cjs.map
923
+ //# sourceMappingURL=chunk-YIFUMQGA.cjs.map
924
+ //# sourceMappingURL=chunk-YIFUMQGA.cjs.map