@arbidocs/react 0.4.159 → 0.4.161

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.
Files changed (88) hide show
  1. package/README.md +13 -6
  2. package/dist/{ProductionDialog-Dhf9MXH-.d.cts → ProductionDialog.d-BD1osHeq.d.cts} +1 -1
  3. package/dist/{ProductionDialog-BvRVGdvH.d.ts → ProductionDialog.d-CttHqQAh.d.ts} +1 -1
  4. package/dist/annotations/freeze/index.d.cts +3 -3
  5. package/dist/annotations/freeze/index.d.ts +3 -3
  6. package/dist/annotations/index.d.cts +4 -4
  7. package/dist/annotations/index.d.ts +4 -4
  8. package/dist/artifacts/index.cjs +12 -11
  9. package/dist/artifacts/index.cjs.map +1 -1
  10. package/dist/artifacts/index.d.cts +4 -4
  11. package/dist/artifacts/index.d.ts +4 -4
  12. package/dist/artifacts/index.js +3 -2
  13. package/dist/artifacts/index.js.map +1 -1
  14. package/dist/{chunk-RDLAOB55.cjs → chunk-3LMX6GXR.cjs} +150 -14
  15. package/dist/chunk-3LMX6GXR.cjs.map +1 -0
  16. package/dist/{chunk-37TQBT7Y.cjs → chunk-6MTKKT2O.cjs} +188 -126
  17. package/dist/chunk-6MTKKT2O.cjs.map +1 -0
  18. package/dist/{chunk-HKIR456G.js → chunk-CEZCFQ47.js} +149 -92
  19. package/dist/chunk-CEZCFQ47.js.map +1 -0
  20. package/dist/chunk-CPZ36AQS.js +11 -0
  21. package/dist/chunk-CPZ36AQS.js.map +1 -0
  22. package/dist/{chunk-JFKWH6EP.cjs → chunk-EUC2BTNS.cjs} +35 -4
  23. package/dist/chunk-EUC2BTNS.cjs.map +1 -0
  24. package/dist/chunk-GTJ667CP.cjs +26 -0
  25. package/dist/chunk-GTJ667CP.cjs.map +1 -0
  26. package/dist/{chunk-3XYIQZTH.js → chunk-I5ZBQ63Y.js} +33 -5
  27. package/dist/chunk-I5ZBQ63Y.js.map +1 -0
  28. package/dist/chunk-JSSKEXRR.js +22 -0
  29. package/dist/chunk-JSSKEXRR.js.map +1 -0
  30. package/dist/{chunk-QKNJ6FRD.cjs → chunk-ON4PL6DQ.cjs} +4 -4
  31. package/dist/chunk-ON4PL6DQ.cjs.map +1 -0
  32. package/dist/chunk-RCKA7BEF.cjs +14 -0
  33. package/dist/chunk-RCKA7BEF.cjs.map +1 -0
  34. package/dist/{chunk-2HNEVAXO.js → chunk-SVHGCX25.js} +3 -3
  35. package/dist/chunk-SVHGCX25.js.map +1 -0
  36. package/dist/{chunk-CNGWJDMG.js → chunk-WOXITGVS.js} +139 -15
  37. package/dist/chunk-WOXITGVS.js.map +1 -0
  38. package/dist/document-tools/index.cjs +35 -34
  39. package/dist/document-tools/index.cjs.map +1 -1
  40. package/dist/document-tools/index.d.cts +4 -4
  41. package/dist/document-tools/index.d.ts +4 -4
  42. package/dist/document-tools/index.js +4 -3
  43. package/dist/document-tools/index.js.map +1 -1
  44. package/dist/index.cjs +1694 -1432
  45. package/dist/index.cjs.map +1 -1
  46. package/dist/{index-DyFzmDZ2.d.ts → index.d-DfCFKora.d.cts} +49 -5
  47. package/dist/{index-DyFzmDZ2.d.cts → index.d-DfCFKora.d.ts} +49 -5
  48. package/dist/{index-CDTwtUr9.d.cts → index.d-eRbU1qpQ.d.cts} +333 -196
  49. package/dist/{index-CDTwtUr9.d.ts → index.d-eRbU1qpQ.d.ts} +333 -196
  50. package/dist/index.d.cts +1797 -1504
  51. package/dist/index.d.ts +1797 -1504
  52. package/dist/index.js +928 -765
  53. package/dist/index.js.map +1 -1
  54. package/dist/shell/index.cjs +24 -15
  55. package/dist/shell/index.d.cts +1 -1
  56. package/dist/shell/index.d.ts +1 -1
  57. package/dist/shell/index.js +2 -1
  58. package/dist/ui/index.cjs +191 -142
  59. package/dist/ui/index.d.cts +1 -1
  60. package/dist/ui/index.d.ts +1 -1
  61. package/dist/ui/index.js +2 -1
  62. package/dist/viewers/index.cjs +3 -2
  63. package/dist/viewers/index.cjs.map +1 -1
  64. package/dist/viewers/index.d.cts +2 -2
  65. package/dist/viewers/index.d.ts +2 -2
  66. package/dist/viewers/index.js +2 -1
  67. package/dist/viewers/index.js.map +1 -1
  68. package/package.json +4 -6
  69. package/dist/chunk-2HNEVAXO.js.map +0 -1
  70. package/dist/chunk-37TQBT7Y.cjs.map +0 -1
  71. package/dist/chunk-3XYIQZTH.js.map +0 -1
  72. package/dist/chunk-CNGWJDMG.js.map +0 -1
  73. package/dist/chunk-CPPBN2JB.js +0 -31
  74. package/dist/chunk-CPPBN2JB.js.map +0 -1
  75. package/dist/chunk-HKIR456G.js.map +0 -1
  76. package/dist/chunk-JFKWH6EP.cjs.map +0 -1
  77. package/dist/chunk-QKNJ6FRD.cjs.map +0 -1
  78. package/dist/chunk-R2MF7YCW.cjs +0 -36
  79. package/dist/chunk-R2MF7YCW.cjs.map +0 -1
  80. package/dist/chunk-RDLAOB55.cjs.map +0 -1
  81. /package/dist/{PdfViewer-bQH9yxFg.d.cts → PdfViewer.d-bQH9yxFg.d.cts} +0 -0
  82. /package/dist/{PdfViewer-bQH9yxFg.d.ts → PdfViewer.d-bQH9yxFg.d.ts} +0 -0
  83. /package/dist/{bundle-BnCSbHy2.d.cts → bundle.d-BnCSbHy2.d.cts} +0 -0
  84. /package/dist/{bundle-BnCSbHy2.d.ts → bundle.d-BnCSbHy2.d.ts} +0 -0
  85. /package/dist/{model-D63gedpb.d.cts → model.d-D63gedpb.d.cts} +0 -0
  86. /package/dist/{model-D63gedpb.d.ts → model.d-D63gedpb.d.ts} +0 -0
  87. /package/dist/{stored-markdown-Bp18vrbr.d.cts → stored-markdown.d-Bp18vrbr.d.cts} +0 -0
  88. /package/dist/{stored-markdown-Bp18vrbr.d.ts → stored-markdown.d-Bp18vrbr.d.ts} +0 -0
@@ -1,9 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  var chunkZWFMFOGP_cjs = require('./chunk-ZWFMFOGP.cjs');
4
- var chunkR2MF7YCW_cjs = require('./chunk-R2MF7YCW.cjs');
4
+ var chunkGTJ667CP_cjs = require('./chunk-GTJ667CP.cjs');
5
5
  var react = require('react');
6
6
  var reactQuery = require('@tanstack/react-query');
7
+ var zustand = require('zustand');
7
8
  var browser = require('@arbidocs/sdk/browser');
8
9
 
9
10
  // src/usage-metered.ts
@@ -80,6 +81,16 @@ var arbiQueryKeys = {
80
81
  currentUser: () => ["arbi", "currentUser"],
81
82
  firmPool: () => ["arbi", "firmPool"],
82
83
  contacts: () => ["arbi", "contacts"],
84
+ /** Every chat query (the list and each open thread). */
85
+ chats: () => ["arbi", "chats"],
86
+ /** My chats, raw (titles and last messages are ciphertext), most recently active first. */
87
+ chatList: () => ["arbi", "chats", "list"],
88
+ /** One thread's loaded messages, decrypted, oldest first (`ChatThreadData`). */
89
+ chatThread: (chatExtId) => ["arbi", "chats", "thread", chatExtId],
90
+ /** My own agent's progress on my last message to it (`agent_dm_status`), per agent. */
91
+ agentDmStatus: (agentExtId) => ["arbi", "chats", "agentStatus", agentExtId],
92
+ /** The paid features this person may use (`/v1/user/entitlements`). */
93
+ entitlements: () => ["arbi", "entitlements"],
83
94
  skills: () => ["arbi", "skills"],
84
95
  /** A skill's main file (SKILL.md), as text. */
85
96
  skillSource: (docExtId) => ["arbi", "skills", "source", docExtId],
@@ -126,7 +137,7 @@ var arbiMutationKeys = {
126
137
  workspaceMembership: () => ["arbi", "workspaces", "members"]
127
138
  };
128
139
  function useWorkspaces(options) {
129
- const arbi = chunkR2MF7YCW_cjs.useArbi();
140
+ const arbi = chunkGTJ667CP_cjs.useArbi();
130
141
  return reactQuery.useQuery({
131
142
  queryKey: arbiQueryKeys.workspaces(),
132
143
  queryFn: () => arbi.workspaces.list(),
@@ -134,7 +145,7 @@ function useWorkspaces(options) {
134
145
  });
135
146
  }
136
147
  function useDocumentVersionList(docId, options) {
137
- const arbi = chunkR2MF7YCW_cjs.useArbi();
148
+ const arbi = chunkGTJ667CP_cjs.useArbi();
138
149
  return reactQuery.useQuery({
139
150
  queryKey: arbiQueryKeys.documentVersions(docId ?? ""),
140
151
  queryFn: () => arbi.documents.versions(docId),
@@ -142,7 +153,7 @@ function useDocumentVersionList(docId, options) {
142
153
  });
143
154
  }
144
155
  function useConversations(workspaceId, options) {
145
- const arbi = chunkR2MF7YCW_cjs.useArbi();
156
+ const arbi = chunkGTJ667CP_cjs.useArbi();
146
157
  return reactQuery.useQuery({
147
158
  queryKey: arbiQueryKeys.conversations(workspaceId ?? ""),
148
159
  queryFn: () => arbi.conversations.list(),
@@ -151,7 +162,7 @@ function useConversations(workspaceId, options) {
151
162
  });
152
163
  }
153
164
  function useConversationThreads(workspaceId, conversationId, options) {
154
- const arbi = chunkR2MF7YCW_cjs.useArbi();
165
+ const arbi = chunkGTJ667CP_cjs.useArbi();
155
166
  return reactQuery.useQuery({
156
167
  queryKey: arbiQueryKeys.conversationThreads(workspaceId ?? "", conversationId ?? ""),
157
168
  queryFn: () => arbi.conversations.getThreads(conversationId),
@@ -168,7 +179,7 @@ var tagListKey = (query) => [
168
179
  query.linksLimit !== void 0 ? `links:${query.linksLimit}` : ""
169
180
  ].filter(Boolean).join("|");
170
181
  function useTags(workspaceId, options) {
171
- const arbi = chunkR2MF7YCW_cjs.useArbi();
182
+ const arbi = chunkGTJ667CP_cjs.useArbi();
172
183
  const { enabled, ...query } = options ?? {};
173
184
  const workspace = workspaceId ?? (arbi.hasWorkspace ? arbi.getWorkspaceId() : "");
174
185
  const key = tagListKey(query);
@@ -180,7 +191,7 @@ function useTags(workspaceId, options) {
180
191
  });
181
192
  }
182
193
  function useThumbnails(docIds, options) {
183
- const arbi = chunkR2MF7YCW_cjs.useArbi();
194
+ const arbi = chunkGTJ667CP_cjs.useArbi();
184
195
  return reactQuery.useQuery({
185
196
  queryKey: arbiQueryKeys.thumbnails(docIds),
186
197
  queryFn: () => arbi.documents.getThumbnails(docIds),
@@ -189,7 +200,7 @@ function useThumbnails(docIds, options) {
189
200
  });
190
201
  }
191
202
  function useParsedDocument(docId, stage = "final", options) {
192
- const arbi = chunkR2MF7YCW_cjs.useArbi();
203
+ const arbi = chunkGTJ667CP_cjs.useArbi();
193
204
  return reactQuery.useQuery({
194
205
  queryKey: arbiQueryKeys.parsedDoc(docId ?? "", stage),
195
206
  queryFn: () => {
@@ -204,13 +215,13 @@ function useParsedDocument(docId, stage = "final", options) {
204
215
  });
205
216
  }
206
217
  function useAssistantQuery() {
207
- const arbi = chunkR2MF7YCW_cjs.useArbi();
218
+ const arbi = chunkGTJ667CP_cjs.useArbi();
208
219
  return reactQuery.useMutation({
209
220
  mutationFn: ({ question, ...options }) => arbi.assistant.query(question, options)
210
221
  });
211
222
  }
212
223
  function useAgents(options) {
213
- const arbi = chunkR2MF7YCW_cjs.useArbi();
224
+ const arbi = chunkGTJ667CP_cjs.useArbi();
214
225
  return reactQuery.useQuery({
215
226
  queryKey: arbiQueryKeys.agents(),
216
227
  queryFn: () => arbi.agents.list(),
@@ -218,7 +229,7 @@ function useAgents(options) {
218
229
  });
219
230
  }
220
231
  function useDeleteAgents() {
221
- const arbi = chunkR2MF7YCW_cjs.useArbi();
232
+ const arbi = chunkGTJ667CP_cjs.useArbi();
222
233
  const qc = reactQuery.useQueryClient();
223
234
  return reactQuery.useMutation({
224
235
  mutationFn: ({ agentExtIds }) => arbi.agents.delete(agentExtIds),
@@ -237,7 +248,7 @@ function useDeleteAgents() {
237
248
  });
238
249
  }
239
250
  function useHealth(options) {
240
- const arbi = chunkR2MF7YCW_cjs.useArbi();
251
+ const arbi = chunkGTJ667CP_cjs.useArbi();
241
252
  return reactQuery.useQuery({
242
253
  queryKey: arbiQueryKeys.health(),
243
254
  queryFn: () => arbi.health.check(),
@@ -245,7 +256,7 @@ function useHealth(options) {
245
256
  });
246
257
  }
247
258
  function useAvailableModels(options) {
248
- const arbi = chunkR2MF7YCW_cjs.useArbi();
259
+ const arbi = chunkGTJ667CP_cjs.useArbi();
249
260
  return reactQuery.useQuery({
250
261
  queryKey: arbiQueryKeys.availableModels(),
251
262
  queryFn: () => arbi.health.models(),
@@ -254,7 +265,7 @@ function useAvailableModels(options) {
254
265
  });
255
266
  }
256
267
  function useConfigs(options) {
257
- const arbi = chunkR2MF7YCW_cjs.useArbi();
268
+ const arbi = chunkGTJ667CP_cjs.useArbi();
258
269
  return reactQuery.useQuery({
259
270
  queryKey: arbiQueryKeys.configs(),
260
271
  queryFn: () => arbi.agentConfig.list(),
@@ -262,7 +273,7 @@ function useConfigs(options) {
262
273
  });
263
274
  }
264
275
  function useActivity(options) {
265
- const arbi = chunkR2MF7YCW_cjs.useArbi();
276
+ const arbi = chunkGTJ667CP_cjs.useArbi();
266
277
  return reactQuery.useQuery({
267
278
  queryKey: arbiQueryKeys.activity(),
268
279
  queryFn: () => arbi.dm.listActivity({ limit: options?.limit, offset: options?.offset }),
@@ -270,7 +281,7 @@ function useActivity(options) {
270
281
  });
271
282
  }
272
283
  function useWorkspaceActivity(workspaceId, options) {
273
- const arbi = chunkR2MF7YCW_cjs.useArbi();
284
+ const arbi = chunkGTJ667CP_cjs.useArbi();
274
285
  return reactQuery.useInfiniteQuery({
275
286
  queryKey: arbiQueryKeys.workspaceActivity(workspaceId ?? ""),
276
287
  queryFn: async ({ pageParam }) => {
@@ -286,7 +297,7 @@ function useWorkspaceActivity(workspaceId, options) {
286
297
  });
287
298
  }
288
299
  function useProjects(options) {
289
- const arbi = chunkR2MF7YCW_cjs.useArbi();
300
+ const arbi = chunkGTJ667CP_cjs.useArbi();
290
301
  return reactQuery.useQuery({
291
302
  queryKey: arbiQueryKeys.projects(),
292
303
  queryFn: () => arbi.projects.list(),
@@ -294,7 +305,7 @@ function useProjects(options) {
294
305
  });
295
306
  }
296
307
  function useProjectUsage(projectExtId, monthsBack = 0, options) {
297
- const arbi = chunkR2MF7YCW_cjs.useArbi();
308
+ const arbi = chunkGTJ667CP_cjs.useArbi();
298
309
  const usage = reactQuery.useQuery({
299
310
  queryKey: arbiQueryKeys.projectUsage(projectExtId ?? "", monthsBack),
300
311
  queryFn: () => arbi.projects.usage(projectExtId, monthsBack),
@@ -306,7 +317,7 @@ function useProjectUsage(projectExtId, monthsBack = 0, options) {
306
317
  return { ...usage, metered };
307
318
  }
308
319
  function useProjectsUsage(projectExtIds, monthsBack = 0, options) {
309
- const arbi = chunkR2MF7YCW_cjs.useArbi();
320
+ const arbi = chunkGTJ667CP_cjs.useArbi();
310
321
  const enabled = (options?.enabled ?? true) && arbi.isLoggedIn;
311
322
  const projects = useProjects({ enabled: enabled && projectExtIds.length > 0 });
312
323
  const results = reactQuery.useQueries({
@@ -380,7 +391,7 @@ function useProjectsUsage(projectExtIds, monthsBack = 0, options) {
380
391
  }, [signature]);
381
392
  }
382
393
  function useProjectInvoices(projectExtId, options) {
383
- const arbi = chunkR2MF7YCW_cjs.useArbi();
394
+ const arbi = chunkGTJ667CP_cjs.useArbi();
384
395
  return reactQuery.useQuery({
385
396
  queryKey: arbiQueryKeys.projectInvoices(projectExtId ?? ""),
386
397
  queryFn: () => arbi.projects.invoices(projectExtId),
@@ -388,7 +399,7 @@ function useProjectInvoices(projectExtId, options) {
388
399
  });
389
400
  }
390
401
  function useCurrentUser(options) {
391
- const arbi = chunkR2MF7YCW_cjs.useArbi();
402
+ const arbi = chunkGTJ667CP_cjs.useArbi();
392
403
  return reactQuery.useQuery({
393
404
  queryKey: arbiQueryKeys.currentUser(),
394
405
  queryFn: () => arbi.user.me(),
@@ -398,7 +409,7 @@ function useCurrentUser(options) {
398
409
  });
399
410
  }
400
411
  function useFirmPool(options) {
401
- const arbi = chunkR2MF7YCW_cjs.useArbi();
412
+ const arbi = chunkGTJ667CP_cjs.useArbi();
402
413
  return reactQuery.useQuery({
403
414
  queryKey: arbiQueryKeys.firmPool(),
404
415
  queryFn: () => arbi.firm.pool(),
@@ -409,7 +420,7 @@ function useFirmPool(options) {
409
420
  });
410
421
  }
411
422
  function useTopUpFirmPool() {
412
- const arbi = chunkR2MF7YCW_cjs.useArbi();
423
+ const arbi = chunkGTJ667CP_cjs.useArbi();
413
424
  const queryClient = reactQuery.useQueryClient();
414
425
  return reactQuery.useMutation({
415
426
  mutationFn: (aiAddons) => arbi.firm.topUp(aiAddons),
@@ -434,7 +445,7 @@ function useCanCreateProjects() {
434
445
  return user.data?.can_create_projects;
435
446
  }
436
447
  function useUserUsageToday(options) {
437
- const arbi = chunkR2MF7YCW_cjs.useArbi();
448
+ const arbi = chunkGTJ667CP_cjs.useArbi();
438
449
  return reactQuery.useQuery({
439
450
  queryKey: arbiQueryKeys.userUsageToday(),
440
451
  queryFn: () => arbi.user.usageToday(),
@@ -444,6 +455,124 @@ function useUserUsageToday(options) {
444
455
  staleTime: 15e3
445
456
  });
446
457
  }
458
+
459
+ // src/documents/documents-cache.ts
460
+ var rowListeners = /* @__PURE__ */ new Set();
461
+ function subscribeDocumentRows(listener) {
462
+ rowListeners.add(listener);
463
+ return () => {
464
+ rowListeners.delete(listener);
465
+ };
466
+ }
467
+ function getCachedDocuments(qc, workspaceId) {
468
+ if (!workspaceId) return void 0;
469
+ return qc.getQueryData(arbiQueryKeys.documents(workspaceId));
470
+ }
471
+ function cachedLists(qc) {
472
+ return qc.getQueriesData({ queryKey: arbiQueryKeys.allDocuments() }).flatMap(
473
+ ([key, data]) => typeof key[2] === "string" && Array.isArray(data) ? [[key[2], data]] : []
474
+ );
475
+ }
476
+ function diffRows(workspaceId, before, after) {
477
+ const beforeById = new Map(before.map((doc) => [doc.external_id, doc]));
478
+ const add = [];
479
+ const update2 = [];
480
+ const seen = /* @__PURE__ */ new Set();
481
+ for (const doc of after) {
482
+ seen.add(doc.external_id);
483
+ const previous = beforeById.get(doc.external_id);
484
+ if (!previous) add.push(doc);
485
+ else if (previous !== doc) update2.push(doc);
486
+ }
487
+ const remove = [...beforeById.keys()].filter((id) => !seen.has(id));
488
+ return { workspaceId, add, update: update2, remove };
489
+ }
490
+ function patchDocuments(qc, reducer, workspaceId) {
491
+ const lists = workspaceId ? (() => {
492
+ const current = getCachedDocuments(qc, workspaceId);
493
+ return current ? [[workspaceId, current]] : [];
494
+ })() : cachedLists(qc);
495
+ for (const [id, before] of lists) {
496
+ const after = reducer(before);
497
+ if (after === before) continue;
498
+ qc.setQueryData(arbiQueryKeys.documents(id), after);
499
+ const change = diffRows(id, before, after);
500
+ const beforeById = new Map(before.map((doc) => [doc.external_id, doc]));
501
+ if (change.update.some(
502
+ (doc) => doc.current_version !== beforeById.get(doc.external_id)?.current_version
503
+ ))
504
+ void qc.invalidateQueries({ queryKey: arbiQueryKeys.allDocumentVersions() });
505
+ if (change.add.length || change.update.length || change.remove.length)
506
+ for (const listener of rowListeners) listener(change);
507
+ }
508
+ }
509
+ function upsertDocuments(qc, documents, workspaceId) {
510
+ if (!documents.length) return;
511
+ const byId = new Map(documents.map((doc) => [doc.external_id, doc]));
512
+ const byWorkspace = /* @__PURE__ */ new Map();
513
+ for (const doc of documents) {
514
+ const ws = workspaceId ?? doc.workspace_ext_id;
515
+ byWorkspace.set(ws, [...byWorkspace.get(ws) ?? [], doc]);
516
+ }
517
+ for (const [ws, incoming] of byWorkspace) {
518
+ patchDocuments(
519
+ qc,
520
+ (old) => {
521
+ const known = new Set(old.map((doc) => doc.external_id));
522
+ return [
523
+ ...old.map((doc) => byId.get(doc.external_id) ?? doc),
524
+ ...incoming.filter((doc) => !known.has(doc.external_id))
525
+ ];
526
+ },
527
+ ws
528
+ );
529
+ }
530
+ }
531
+ function setCachedDocument(qc, doc) {
532
+ qc.setQueryData(arbiQueryKeys.document(doc.external_id), doc);
533
+ }
534
+ function patchCachedDocument(qc, docId, reducer) {
535
+ const current = qc.getQueryData(arbiQueryKeys.document(docId));
536
+ if (current) qc.setQueryData(arbiQueryKeys.document(docId), reducer(current));
537
+ }
538
+ function dropTagFromCachedDocuments(qc, tagId) {
539
+ const strip = (doc) => {
540
+ const doctags = doc.doctags?.filter((dt) => dt.tag_ext_id !== tagId);
541
+ return doctags && doctags.length !== doc.doctags?.length ? { ...doc, doctags } : doc;
542
+ };
543
+ const carriers = [];
544
+ patchDocuments(qc, (docs) => {
545
+ const next = docs.map(strip);
546
+ next.forEach((doc, i) => doc !== docs[i] && carriers.push(doc.external_id));
547
+ return carriers.length ? next : docs;
548
+ });
549
+ for (const id of carriers) patchCachedDocument(qc, id, strip);
550
+ }
551
+ function forgetDocuments(qc, docIds) {
552
+ for (const id of docIds) {
553
+ qc.removeQueries({ queryKey: arbiQueryKeys.document(id) });
554
+ qc.removeQueries({ queryKey: arbiQueryKeys.documentVersions(id) });
555
+ qc.removeQueries({ queryKey: arbiQueryKeys.parsedDocument(id) });
556
+ }
557
+ }
558
+ var useEntityExtractionStore = zustand.create(() => ({ docIds: [] }));
559
+ function update(docIds, running) {
560
+ if (!docIds.length) return;
561
+ useEntityExtractionStore.setState((state) => {
562
+ const ids = new Set(state.docIds);
563
+ docIds.forEach((id) => running ? ids.add(id) : ids.delete(id));
564
+ return { docIds: [...ids] };
565
+ });
566
+ }
567
+ function startEntityExtraction(docIds) {
568
+ update(docIds, true);
569
+ }
570
+ function finishEntityExtraction(docIds) {
571
+ update(docIds, false);
572
+ }
573
+ function useEntityExtractionDocIds() {
574
+ return useEntityExtractionStore((state) => state.docIds);
575
+ }
447
576
  function openWorkspaceId(arbi) {
448
577
  return arbi.hasWorkspace ? arbi.getWorkspaceId() : null;
449
578
  }
@@ -464,7 +593,7 @@ function invalidateTagData(qc, workspaceId) {
464
593
  ]);
465
594
  }
466
595
  function useInvalidateTagData() {
467
- const arbi = chunkR2MF7YCW_cjs.useArbi();
596
+ const arbi = chunkGTJ667CP_cjs.useArbi();
468
597
  const qc = reactQuery.useQueryClient();
469
598
  return react.useCallback(() => {
470
599
  const workspaceId = openWorkspaceId(arbi);
@@ -497,7 +626,7 @@ var replayableTagMutations = [
497
626
  }
498
627
  ];
499
628
  function useCreateTag() {
500
- const arbi = chunkR2MF7YCW_cjs.useArbi();
629
+ const arbi = chunkGTJ667CP_cjs.useArbi();
501
630
  const qc = reactQuery.useQueryClient();
502
631
  return reactQuery.useMutation({
503
632
  mutationKey: arbiMutationKeys.createTag(),
@@ -505,8 +634,21 @@ function useCreateTag() {
505
634
  onSuccess: (created) => settleCreatedTag(qc, created)
506
635
  });
507
636
  }
637
+ function useIsCreatingTag() {
638
+ const qc = reactQuery.useQueryClient();
639
+ return react.useCallback(
640
+ (name) => {
641
+ const wanted = name.trim().toLowerCase();
642
+ return qc.getMutationCache().findAll({
643
+ mutationKey: arbiMutationKeys.createTag(),
644
+ predicate: (m) => m.state.status === "pending" && m.state.variables?.name.trim().toLowerCase() === wanted
645
+ }).length > 0;
646
+ },
647
+ [qc]
648
+ );
649
+ }
508
650
  function useUpdateTag() {
509
- const arbi = chunkR2MF7YCW_cjs.useArbi();
651
+ const arbi = chunkGTJ667CP_cjs.useArbi();
510
652
  const qc = reactQuery.useQueryClient();
511
653
  return reactQuery.useMutation({
512
654
  mutationKey: arbiMutationKeys.updateTag(),
@@ -515,7 +657,7 @@ function useUpdateTag() {
515
657
  });
516
658
  }
517
659
  function useSetTagValues() {
518
- const arbi = chunkR2MF7YCW_cjs.useArbi();
660
+ const arbi = chunkGTJ667CP_cjs.useArbi();
519
661
  const qc = reactQuery.useQueryClient();
520
662
  return reactQuery.useMutation({
521
663
  mutationKey: arbiMutationKeys.updateTag(),
@@ -527,12 +669,13 @@ function useSetTagValues() {
527
669
  });
528
670
  }
529
671
  function useDeleteTag() {
530
- const arbi = chunkR2MF7YCW_cjs.useArbi();
672
+ const arbi = chunkGTJ667CP_cjs.useArbi();
531
673
  const qc = reactQuery.useQueryClient();
532
674
  return reactQuery.useMutation({
533
675
  mutationKey: arbiMutationKeys.deleteTag(),
534
676
  mutationFn: (tagId) => arbi.tags.delete(tagId),
535
677
  onSuccess: (_data, tagId) => {
678
+ dropTagFromCachedDocuments(qc, tagId);
536
679
  const workspaceId = openWorkspaceId(arbi);
537
680
  if (!workspaceId) return;
538
681
  patchWorkspaceTags(
@@ -548,14 +691,15 @@ function useDeleteTag() {
548
691
  });
549
692
  }
550
693
  function useExtractEntities() {
551
- const arbi = chunkR2MF7YCW_cjs.useArbi();
694
+ const arbi = chunkGTJ667CP_cjs.useArbi();
552
695
  return reactQuery.useMutation({
553
696
  mutationKey: arbiMutationKeys.extractEntities(),
554
- mutationFn: (docIds) => arbi.tags.extractEntities(docIds)
697
+ mutationFn: (docIds) => arbi.tags.extractEntities(docIds),
698
+ onSuccess: (data) => startEntityExtraction(data.doc_ext_ids)
555
699
  });
556
700
  }
557
701
  function useTagKindSchema(kind, options) {
558
- const arbi = chunkR2MF7YCW_cjs.useArbi();
702
+ const arbi = chunkGTJ667CP_cjs.useArbi();
559
703
  const workspaceId = openWorkspaceId(arbi) ?? "";
560
704
  return reactQuery.useQuery({
561
705
  queryKey: arbiQueryKeys.tagKind(workspaceId, kind ?? ""),
@@ -564,7 +708,7 @@ function useTagKindSchema(kind, options) {
564
708
  });
565
709
  }
566
710
  function useUpdateTagKindSchema() {
567
- const arbi = chunkR2MF7YCW_cjs.useArbi();
711
+ const arbi = chunkGTJ667CP_cjs.useArbi();
568
712
  const qc = reactQuery.useQueryClient();
569
713
  return reactQuery.useMutation({
570
714
  mutationKey: arbiMutationKeys.updateTagKindSchema(),
@@ -580,93 +724,6 @@ function useUpdateTagKindSchema() {
580
724
  }
581
725
  });
582
726
  }
583
-
584
- // src/documents/documents-cache.ts
585
- var rowListeners = /* @__PURE__ */ new Set();
586
- function subscribeDocumentRows(listener) {
587
- rowListeners.add(listener);
588
- return () => {
589
- rowListeners.delete(listener);
590
- };
591
- }
592
- function getCachedDocuments(qc, workspaceId) {
593
- if (!workspaceId) return void 0;
594
- return qc.getQueryData(arbiQueryKeys.documents(workspaceId));
595
- }
596
- function cachedLists(qc) {
597
- return qc.getQueriesData({ queryKey: arbiQueryKeys.allDocuments() }).flatMap(
598
- ([key, data]) => typeof key[2] === "string" && Array.isArray(data) ? [[key[2], data]] : []
599
- );
600
- }
601
- function diffRows(workspaceId, before, after) {
602
- const beforeById = new Map(before.map((doc) => [doc.external_id, doc]));
603
- const add = [];
604
- const update = [];
605
- const seen = /* @__PURE__ */ new Set();
606
- for (const doc of after) {
607
- seen.add(doc.external_id);
608
- const previous = beforeById.get(doc.external_id);
609
- if (!previous) add.push(doc);
610
- else if (previous !== doc) update.push(doc);
611
- }
612
- const remove = [...beforeById.keys()].filter((id) => !seen.has(id));
613
- return { workspaceId, add, update, remove };
614
- }
615
- function patchDocuments(qc, reducer, workspaceId) {
616
- const lists = workspaceId ? (() => {
617
- const current = getCachedDocuments(qc, workspaceId);
618
- return current ? [[workspaceId, current]] : [];
619
- })() : cachedLists(qc);
620
- for (const [id, before] of lists) {
621
- const after = reducer(before);
622
- if (after === before) continue;
623
- qc.setQueryData(arbiQueryKeys.documents(id), after);
624
- const change = diffRows(id, before, after);
625
- const beforeById = new Map(before.map((doc) => [doc.external_id, doc]));
626
- if (change.update.some(
627
- (doc) => doc.current_version !== beforeById.get(doc.external_id)?.current_version
628
- ))
629
- void qc.invalidateQueries({ queryKey: arbiQueryKeys.allDocumentVersions() });
630
- if (change.add.length || change.update.length || change.remove.length)
631
- for (const listener of rowListeners) listener(change);
632
- }
633
- }
634
- function upsertDocuments(qc, documents, workspaceId) {
635
- if (!documents.length) return;
636
- const byId = new Map(documents.map((doc) => [doc.external_id, doc]));
637
- const byWorkspace = /* @__PURE__ */ new Map();
638
- for (const doc of documents) {
639
- const ws = workspaceId ?? doc.workspace_ext_id;
640
- byWorkspace.set(ws, [...byWorkspace.get(ws) ?? [], doc]);
641
- }
642
- for (const [ws, incoming] of byWorkspace) {
643
- patchDocuments(
644
- qc,
645
- (old) => {
646
- const known = new Set(old.map((doc) => doc.external_id));
647
- return [
648
- ...old.map((doc) => byId.get(doc.external_id) ?? doc),
649
- ...incoming.filter((doc) => !known.has(doc.external_id))
650
- ];
651
- },
652
- ws
653
- );
654
- }
655
- }
656
- function setCachedDocument(qc, doc) {
657
- qc.setQueryData(arbiQueryKeys.document(doc.external_id), doc);
658
- }
659
- function patchCachedDocument(qc, docId, reducer) {
660
- const current = qc.getQueryData(arbiQueryKeys.document(docId));
661
- if (current) qc.setQueryData(arbiQueryKeys.document(docId), reducer(current));
662
- }
663
- function forgetDocuments(qc, docIds) {
664
- for (const id of docIds) {
665
- qc.removeQueries({ queryKey: arbiQueryKeys.document(id) });
666
- qc.removeQueries({ queryKey: arbiQueryKeys.documentVersions(id) });
667
- qc.removeQueries({ queryKey: arbiQueryKeys.parsedDocument(id) });
668
- }
669
- }
670
727
  var DOCUMENTS_FIRST_PAGE_SIZE = 500;
671
728
  var DOCUMENTS_PAGE_SIZE = 2e3;
672
729
  var DOCUMENTS_FIRST_PAGE_MEASURE = "arbi:document-list:page1";
@@ -772,7 +829,7 @@ function openWorkspaceId2(arbi) {
772
829
  return arbi.hasWorkspace ? arbi.getWorkspaceId() : null;
773
830
  }
774
831
  function useDocuments(workspaceId, options) {
775
- const arbi = chunkR2MF7YCW_cjs.useArbi();
832
+ const arbi = chunkGTJ667CP_cjs.useArbi();
776
833
  const qc = reactQuery.useQueryClient();
777
834
  const workspace = workspaceId ?? openWorkspaceId2(arbi) ?? "";
778
835
  return reactQuery.useQuery({
@@ -794,7 +851,7 @@ function processingInterval(doc) {
794
851
  return doc?.status && !FINISHED_DOCUMENT_STATUSES.has(doc.status) ? DOCUMENT_STATUS_POLL_MS : false;
795
852
  }
796
853
  function useDocument(docId, options) {
797
- const arbi = chunkR2MF7YCW_cjs.useArbi();
854
+ const arbi = chunkGTJ667CP_cjs.useArbi();
798
855
  return reactQuery.useQuery({
799
856
  queryKey: arbiQueryKeys.document(docId ?? ""),
800
857
  queryFn: async () => (await arbi.documents.get([docId]))[0] ?? null,
@@ -803,7 +860,7 @@ function useDocument(docId, options) {
803
860
  });
804
861
  }
805
862
  function useDocumentsById(docIds, options) {
806
- const arbi = chunkR2MF7YCW_cjs.useArbi();
863
+ const arbi = chunkGTJ667CP_cjs.useArbi();
807
864
  return reactQuery.useQuery({
808
865
  queryKey: arbiQueryKeys.documentsById(docIds),
809
866
  queryFn: () => arbi.documents.get(docIds),
@@ -812,7 +869,7 @@ function useDocumentsById(docIds, options) {
812
869
  }
813
870
  var SIMILARITY_THRESHOLD = 0.98;
814
871
  function useSimilarDocuments(options) {
815
- const arbi = chunkR2MF7YCW_cjs.useArbi();
872
+ const arbi = chunkGTJ667CP_cjs.useArbi();
816
873
  const workspace = openWorkspaceId2(arbi) ?? "";
817
874
  return reactQuery.useQuery({
818
875
  queryKey: arbiQueryKeys.similarDocuments(workspace, SIMILARITY_THRESHOLD),
@@ -881,6 +938,8 @@ exports.SIMILARITY_THRESHOLD = SIMILARITY_THRESHOLD;
881
938
  exports.adjustTagCounts = adjustTagCounts;
882
939
  exports.arbiMutationKeys = arbiMutationKeys;
883
940
  exports.arbiQueryKeys = arbiQueryKeys;
941
+ exports.dropTagFromCachedDocuments = dropTagFromCachedDocuments;
942
+ exports.finishEntityExtraction = finishEntityExtraction;
884
943
  exports.forgetDocuments = forgetDocuments;
885
944
  exports.getCachedDocuments = getCachedDocuments;
886
945
  exports.invalidateTagData = invalidateTagData;
@@ -893,6 +952,7 @@ exports.patchWorkspaceTags = patchWorkspaceTags;
893
952
  exports.refreshDocuments = refreshDocuments;
894
953
  exports.replayableTagMutations = replayableTagMutations;
895
954
  exports.setCachedDocument = setCachedDocument;
955
+ exports.startEntityExtraction = startEntityExtraction;
896
956
  exports.stopDocumentsLoading = stopDocumentsLoading;
897
957
  exports.subscribeDocumentRows = subscribeDocumentRows;
898
958
  exports.upsertDocuments = upsertDocuments;
@@ -913,10 +973,12 @@ exports.useDocumentVersionList = useDocumentVersionList;
913
973
  exports.useDocuments = useDocuments;
914
974
  exports.useDocumentsById = useDocumentsById;
915
975
  exports.useDocumentsLoading = useDocumentsLoading;
976
+ exports.useEntityExtractionDocIds = useEntityExtractionDocIds;
916
977
  exports.useExtractEntities = useExtractEntities;
917
978
  exports.useFirmPool = useFirmPool;
918
979
  exports.useHealth = useHealth;
919
980
  exports.useInvalidateTagData = useInvalidateTagData;
981
+ exports.useIsCreatingTag = useIsCreatingTag;
920
982
  exports.useParsedDocument = useParsedDocument;
921
983
  exports.useProjectInvoices = useProjectInvoices;
922
984
  exports.useProjectUsage = useProjectUsage;
@@ -933,5 +995,5 @@ exports.useUpdateTagKindSchema = useUpdateTagKindSchema;
933
995
  exports.useUserUsageToday = useUserUsageToday;
934
996
  exports.useWorkspaceActivity = useWorkspaceActivity;
935
997
  exports.useWorkspaces = useWorkspaces;
936
- //# sourceMappingURL=chunk-37TQBT7Y.cjs.map
937
- //# sourceMappingURL=chunk-37TQBT7Y.cjs.map
998
+ //# sourceMappingURL=chunk-6MTKKT2O.cjs.map
999
+ //# sourceMappingURL=chunk-6MTKKT2O.cjs.map