@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.
- package/README.md +13 -6
- package/dist/{ProductionDialog-Dhf9MXH-.d.cts → ProductionDialog.d-BD1osHeq.d.cts} +1 -1
- package/dist/{ProductionDialog-BvRVGdvH.d.ts → ProductionDialog.d-CttHqQAh.d.ts} +1 -1
- package/dist/annotations/freeze/index.d.cts +3 -3
- package/dist/annotations/freeze/index.d.ts +3 -3
- package/dist/annotations/index.d.cts +4 -4
- package/dist/annotations/index.d.ts +4 -4
- package/dist/artifacts/index.cjs +12 -11
- package/dist/artifacts/index.cjs.map +1 -1
- package/dist/artifacts/index.d.cts +4 -4
- package/dist/artifacts/index.d.ts +4 -4
- package/dist/artifacts/index.js +3 -2
- package/dist/artifacts/index.js.map +1 -1
- package/dist/{chunk-RDLAOB55.cjs → chunk-3LMX6GXR.cjs} +150 -14
- package/dist/chunk-3LMX6GXR.cjs.map +1 -0
- package/dist/{chunk-37TQBT7Y.cjs → chunk-6MTKKT2O.cjs} +188 -126
- package/dist/chunk-6MTKKT2O.cjs.map +1 -0
- package/dist/{chunk-HKIR456G.js → chunk-CEZCFQ47.js} +149 -92
- package/dist/chunk-CEZCFQ47.js.map +1 -0
- package/dist/chunk-CPZ36AQS.js +11 -0
- package/dist/chunk-CPZ36AQS.js.map +1 -0
- package/dist/{chunk-JFKWH6EP.cjs → chunk-EUC2BTNS.cjs} +35 -4
- package/dist/chunk-EUC2BTNS.cjs.map +1 -0
- package/dist/chunk-GTJ667CP.cjs +26 -0
- package/dist/chunk-GTJ667CP.cjs.map +1 -0
- package/dist/{chunk-3XYIQZTH.js → chunk-I5ZBQ63Y.js} +33 -5
- package/dist/chunk-I5ZBQ63Y.js.map +1 -0
- package/dist/chunk-JSSKEXRR.js +22 -0
- package/dist/chunk-JSSKEXRR.js.map +1 -0
- package/dist/{chunk-QKNJ6FRD.cjs → chunk-ON4PL6DQ.cjs} +4 -4
- package/dist/chunk-ON4PL6DQ.cjs.map +1 -0
- package/dist/chunk-RCKA7BEF.cjs +14 -0
- package/dist/chunk-RCKA7BEF.cjs.map +1 -0
- package/dist/{chunk-2HNEVAXO.js → chunk-SVHGCX25.js} +3 -3
- package/dist/chunk-SVHGCX25.js.map +1 -0
- package/dist/{chunk-CNGWJDMG.js → chunk-WOXITGVS.js} +139 -15
- package/dist/chunk-WOXITGVS.js.map +1 -0
- package/dist/document-tools/index.cjs +35 -34
- package/dist/document-tools/index.cjs.map +1 -1
- package/dist/document-tools/index.d.cts +4 -4
- package/dist/document-tools/index.d.ts +4 -4
- package/dist/document-tools/index.js +4 -3
- package/dist/document-tools/index.js.map +1 -1
- package/dist/index.cjs +1694 -1432
- package/dist/index.cjs.map +1 -1
- package/dist/{index-DyFzmDZ2.d.ts → index.d-DfCFKora.d.cts} +49 -5
- package/dist/{index-DyFzmDZ2.d.cts → index.d-DfCFKora.d.ts} +49 -5
- package/dist/{index-CDTwtUr9.d.cts → index.d-eRbU1qpQ.d.cts} +333 -196
- package/dist/{index-CDTwtUr9.d.ts → index.d-eRbU1qpQ.d.ts} +333 -196
- package/dist/index.d.cts +1797 -1504
- package/dist/index.d.ts +1797 -1504
- package/dist/index.js +928 -765
- package/dist/index.js.map +1 -1
- package/dist/shell/index.cjs +24 -15
- package/dist/shell/index.d.cts +1 -1
- package/dist/shell/index.d.ts +1 -1
- package/dist/shell/index.js +2 -1
- package/dist/ui/index.cjs +191 -142
- package/dist/ui/index.d.cts +1 -1
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.js +2 -1
- package/dist/viewers/index.cjs +3 -2
- package/dist/viewers/index.cjs.map +1 -1
- package/dist/viewers/index.d.cts +2 -2
- package/dist/viewers/index.d.ts +2 -2
- package/dist/viewers/index.js +2 -1
- package/dist/viewers/index.js.map +1 -1
- package/package.json +4 -6
- package/dist/chunk-2HNEVAXO.js.map +0 -1
- package/dist/chunk-37TQBT7Y.cjs.map +0 -1
- package/dist/chunk-3XYIQZTH.js.map +0 -1
- package/dist/chunk-CNGWJDMG.js.map +0 -1
- package/dist/chunk-CPPBN2JB.js +0 -31
- package/dist/chunk-CPPBN2JB.js.map +0 -1
- package/dist/chunk-HKIR456G.js.map +0 -1
- package/dist/chunk-JFKWH6EP.cjs.map +0 -1
- package/dist/chunk-QKNJ6FRD.cjs.map +0 -1
- package/dist/chunk-R2MF7YCW.cjs +0 -36
- package/dist/chunk-R2MF7YCW.cjs.map +0 -1
- package/dist/chunk-RDLAOB55.cjs.map +0 -1
- /package/dist/{PdfViewer-bQH9yxFg.d.cts → PdfViewer.d-bQH9yxFg.d.cts} +0 -0
- /package/dist/{PdfViewer-bQH9yxFg.d.ts → PdfViewer.d-bQH9yxFg.d.ts} +0 -0
- /package/dist/{bundle-BnCSbHy2.d.cts → bundle.d-BnCSbHy2.d.cts} +0 -0
- /package/dist/{bundle-BnCSbHy2.d.ts → bundle.d-BnCSbHy2.d.ts} +0 -0
- /package/dist/{model-D63gedpb.d.cts → model.d-D63gedpb.d.cts} +0 -0
- /package/dist/{model-D63gedpb.d.ts → model.d-D63gedpb.d.ts} +0 -0
- /package/dist/{stored-markdown-Bp18vrbr.d.cts → stored-markdown.d-Bp18vrbr.d.cts} +0 -0
- /package/dist/{stored-markdown-Bp18vrbr.d.ts → stored-markdown.d-Bp18vrbr.d.ts} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { arbiMutationKeys, replayableTagMutations, patchDocuments, setCachedDocument, adjustTagCounts, arbiQueryKeys, patchCachedDocument, useDocuments, useConversations, useAssistantQuery, useConversationThreads, refreshDocuments, FINISHED_DOCUMENT_STATUSES, useWorkspaces, forgetDocuments, getCachedDocuments, useActivity, useTags,
|
|
2
|
-
export { DOCUMENTS_FIRST_PAGE_MEASURE, DOCUMENTS_FIRST_PAGE_SIZE, DOCUMENTS_PAGE_SIZE, FINISHED_DOCUMENT_STATUSES, PROJECT_CREATION_DENIED_REASON, SIMILARITY_THRESHOLD, adjustTagCounts, arbiMutationKeys, arbiQueryKeys, forgetDocuments, getCachedDocuments, invalidateTagData, invalidateTagTables, isDocumentsLoading, isUsageMetered, patchCachedDocument, patchDocuments, patchWorkspaceTags, refreshDocuments, setCachedDocument, stopDocumentsLoading, subscribeDocumentRows, upsertDocuments, useActivity, useAgents, useAssistantQuery, useAvailableModels, useCanCreateProjects, useConfigs, useConversationThreads, useConversations, useCreateTag, useCurrentUser, useDeleteAgents, useDeleteTag, useDocument, useDocumentVersionList, useDocuments, useDocumentsById, useDocumentsLoading, useExtractEntities, useFirmPool, useHealth, useInvalidateTagData, useParsedDocument, useProjectInvoices, useProjectUsage, useProjects, useProjectsUsage, useSetTagValues, useSimilarDocuments, useTagKindSchema, useTags, useThumbnails, useTopUpFirmPool, useUpdateTag, useUpdateTagKindSchema, useUserUsageToday, useWorkspaceActivity, useWorkspaces } from './chunk-
|
|
3
|
-
import { downloadBlob, fetchDocumentFile } from './chunk-
|
|
1
|
+
import { arbiMutationKeys, replayableTagMutations, patchDocuments, setCachedDocument, adjustTagCounts, arbiQueryKeys, patchCachedDocument, useDocuments, useConversations, useAssistantQuery, useConversationThreads, refreshDocuments, FINISHED_DOCUMENT_STATUSES, useWorkspaces, forgetDocuments, getCachedDocuments, useActivity, useParsedDocument, useTags, useSimilarDocuments, SIMILARITY_THRESHOLD, finishEntityExtraction } from './chunk-CEZCFQ47.js';
|
|
2
|
+
export { DOCUMENTS_FIRST_PAGE_MEASURE, DOCUMENTS_FIRST_PAGE_SIZE, DOCUMENTS_PAGE_SIZE, FINISHED_DOCUMENT_STATUSES, PROJECT_CREATION_DENIED_REASON, SIMILARITY_THRESHOLD, adjustTagCounts, arbiMutationKeys, arbiQueryKeys, dropTagFromCachedDocuments, finishEntityExtraction, forgetDocuments, getCachedDocuments, invalidateTagData, invalidateTagTables, isDocumentsLoading, isUsageMetered, patchCachedDocument, patchDocuments, patchWorkspaceTags, refreshDocuments, setCachedDocument, startEntityExtraction, stopDocumentsLoading, subscribeDocumentRows, upsertDocuments, useActivity, useAgents, useAssistantQuery, useAvailableModels, useCanCreateProjects, useConfigs, useConversationThreads, useConversations, useCreateTag, useCurrentUser, useDeleteAgents, useDeleteTag, useDocument, useDocumentVersionList, useDocuments, useDocumentsById, useDocumentsLoading, useEntityExtractionDocIds, useExtractEntities, useFirmPool, useHealth, useInvalidateTagData, useIsCreatingTag, useParsedDocument, useProjectInvoices, useProjectUsage, useProjects, useProjectsUsage, useSetTagValues, useSimilarDocuments, useTagKindSchema, useTags, useThumbnails, useTopUpFirmPool, useUpdateTag, useUpdateTagKindSchema, useUserUsageToday, useWorkspaceActivity, useWorkspaces } from './chunk-CEZCFQ47.js';
|
|
3
|
+
import { downloadBlob, fetchDocumentFile } from './chunk-SVHGCX25.js';
|
|
4
4
|
import { parseVersionRef } from './chunk-NNWMHMEC.js';
|
|
5
5
|
export { cleanDraftMarkdown, cleanDraftWithReport, promoteBoldTitle, repairParsedStructure, repairParsedTitle, stripAgentPreamble, unescapeMarkdown, unwrapCitationLinks } from './chunk-NNWMHMEC.js';
|
|
6
6
|
import './chunk-WUTL62MC.js';
|
|
7
|
-
import { createSearchSession, clearSearchSession, formatRelativeTime, notify } from './chunk-
|
|
8
|
-
export { DEFAULT_NOTIFY_TONE, MAX_SESSION_NOTIFICATIONS, NotificationBell, Toaster, clearSearchSession, configureNotify, createSearchSession, formatRelativeTime, notify, persistNotifyHistory, persistSearchSession, requestSearch, seedNotifications, selectUnread, sharedSearchSession, takePendingSearch, toast, useNotify } from './chunk-
|
|
9
|
-
import { returnFocusToMark, MarkMenu, AiMarkdown, Card, Badge, Input, FILE_TYPE_COLORS, getEntityIcon, UserEntity, getEntityColorStyles, AgentBadge, Textarea, Label, Slider, getDocumentTitle,
|
|
10
|
-
export { AUDIO_MIME_PREFERENCE, AgentBadge, AiMarkdown, ArbiBotHeadIcon, ArbiIcon, AudIcon, Avatar, AvatarFallback, AvatarImage, BASE_COLORS, Badge, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, Collapsible, CollapsibleContent, CollapsibleTrigger, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, DEFAULT_SEGMENTER_CONFIG, DebouncedInput,
|
|
7
|
+
import { ArbiHost, OWN_SESSION_SLOT, createSearchSession, clearSearchSession, formatRelativeTime, notify } from './chunk-I5ZBQ63Y.js';
|
|
8
|
+
export { DEFAULT_NOTIFY_TONE, MAX_SESSION_NOTIFICATIONS, NotificationBell, Toaster, clearSearchSession, configureNotify, createSearchSession, formatRelativeTime, mergeHostConfig, notify, persistNotifyHistory, persistSearchSession, requestSearch, seedNotifications, selectUnread, sharedSearchSession, takePendingSearch, toast, useNotify } from './chunk-I5ZBQ63Y.js';
|
|
9
|
+
import { returnFocusToMark, MarkMenu, AiMarkdown, Card, Badge, Input, FILE_TYPE_COLORS, getEntityIcon, UserEntity, getEntityColorStyles, AgentBadge, Textarea, Label, Slider, getDocumentTitle, TagEntity, useAudioRecorder, MicWaveformIndicator, IconToggle, classifyMediaError, formatElapsed, getDocumentDate } from './chunk-WOXITGVS.js';
|
|
10
|
+
export { AUDIO_MIME_PREFERENCE, AgentBadge, AiMarkdown, ArbiBotHeadIcon, ArbiIcon, AudIcon, Avatar, AvatarFallback, AvatarImage, BASE_COLORS, Badge, COLUMN_LABEL_FALLBACKS, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, Collapsible, CollapsibleContent, CollapsibleTrigger, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, DEFAULT_METADATA_TAGS, DEFAULT_SEGMENTER_CONFIG, DebouncedInput, DocIcon, DocumentCard, DocumentEntity, ENTITY_MAPPINGS, EmlIcon, EntityIcon, EntityPill, FILE_TYPE_COLORS, HoverCard, HoverCardContent, HoverCardTrigger, HtmlIcon, INITIAL_SEGMENTER_STATE, IconToggle, ImgIcon, InlineMicButton, Input, Label, MarkMenu, MicRecordingOverlay, MicWaveformIndicator, NEUTRAL_GRAY, PLACEHOLDER_COLOR, PassageCard, PdfIcon, Popover, PopoverAnchor, PopoverClose, PopoverContent, PopoverTrigger, PresenceLabel, Progress, ProjectEntity, RadioGroup, RadioGroupItem, RagDot, RelevanceDot, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, ShieldIcon, Slider, StatusPill, Switch, TAG_TYPE_ICONS, TAG_TYPE_LABELS, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsList, TabsTrigger, TagEntity, Textarea, ThreadVisibilityIcon, Toggle, ToggleGroup, ToggleGroupItem, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, TxtIcon, UserEntity, UserMenu, VIDEO_MIME_PREFERENCE, VISIBILITY_ICONS, VerifiedBadge, VerifiedToggle, VidIcon, VisibilityIcon, VisibilityToggle, XlsIcon, agentAvatarColors, badgeVariants, buildFolderTree, canonicalFolderPath, cardVariants, classifyMediaError, configureEntityRegistry, configureRagLabels, configureStatusRegistry, createChunkedRecorder, createUserAvatarIcon, extensionFromMime, flushSegmenter, formatDocDate, formatElapsed, formatFolderLabel, formatFriendlyDate, friendlyFileType, getDocIcon, getDocumentAuthor, getDocumentDate, getDocumentNature, getDocumentSubject, getDocumentTitle, getEntityColor, getEntityColorStyles, getEntityIcon, getEntityLabel, getFileExtension, getFileTypeIcon, getStatusVariant, getTagTypeIcon, getTagTypeLabel, getUserAvatarColor, getUserDisplayName, getUserInitials, getWorkspaceColor, isAgent, isAudioFile, isDocumentAddableToConversation, isDownloadOnlyFile, isImageDocument, isImageFile, isMediaFile, isVideoFile, levelFromRms, markdownToPlainText, markdownToPlainTextBlocks, pickRecorderMimeType, stepSegmenter, tagKindNouns, tagKindTitle, toggleVariants, useAudioRecorder, useDictateContext, usesOriginalBytesForViewer } from './chunk-WOXITGVS.js';
|
|
11
11
|
import { MarkdownRenderer } from './chunk-C44GO33B.js';
|
|
12
12
|
export { MarkdownCode, MarkdownLink, MarkdownRenderer, MarkdownStreamingContext, markdownBaseComponents, markdownSanitizeSchema, splitMarkdownBlocks } from './chunk-C44GO33B.js';
|
|
13
13
|
import { Button, Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from './chunk-YNNAJJ5Z.js';
|
|
@@ -21,11 +21,12 @@ export { DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMe
|
|
|
21
21
|
import { cn } from './chunk-SN5YV6FF.js';
|
|
22
22
|
export { cn } from './chunk-SN5YV6FF.js';
|
|
23
23
|
import { AudioViewer, ImageViewer, VideoViewer } from './chunk-HDCRPPBW.js';
|
|
24
|
-
import { useArbi,
|
|
25
|
-
export {
|
|
26
|
-
|
|
24
|
+
import { useArbi, useArbiHost } from './chunk-JSSKEXRR.js';
|
|
25
|
+
export { useArbi, useArbiHost, useDeploymentDomain } from './chunk-JSSKEXRR.js';
|
|
26
|
+
export { useHostConfigRecord } from './chunk-CPZ36AQS.js';
|
|
27
|
+
import React3, { memo, useState, createContext, useMemo, useCallback, useEffect, useRef, useLayoutEffect, useContext, useSyncExternalStore, useId, Fragment as Fragment$1 } from 'react';
|
|
27
28
|
import { useQueryClient, useMutation, useQuery, useQueries, onlineManager, partialMatchKey } from '@tanstack/react-query';
|
|
28
|
-
import { documents, doctags, houseTemplates, resolveCitations, summarizeCitations, settings, isConnectorVendorVisible, ArbiApiError, ACCOUNT_VENDOR, searchChunks, formatFileSize, connectWithReconnect,
|
|
29
|
+
import { documents, doctags, houseTemplates, resolveCitations, summarizeCitations, settings, isConnectorVendorVisible, ArbiApiError, ACCOUNT_VENDOR, searchChunks, chats, formatFileSize, connectWithReconnect, identityErrorCode } from '@arbidocs/sdk/browser';
|
|
29
30
|
export { ACCOUNT_VENDOR, Arbi, ArbiError, DEFAULT_AI_USD_PER_GBP, DRIVE_SYNC_VENDORS, GOOGLE_VENDORS, IMANAGE_VENDORS, MAILBOX_SYNC_VENDORS, MAX_RETRIEVE_DOC_IDS, MICROSOFT_VENDORS, PublicBookingError, SHAREPOINT_VENDORS, bookPublicSlot, cancelPublicBooking, connectErrorMessage, formatGbp, formatGbpPerMillionTokens, getPublicBookingPage, isConnectorVendorVisible, isDriveSyncVendor, isMailboxSyncVendor, isSharePointVendor, usdToGbp } from '@arbidocs/sdk/browser';
|
|
30
31
|
import { Link, Trash2, CheckCheck, Check, Loader2, AlertTriangle, ShieldCheck, Copy, Sparkles, FileText, GitCompareArrows, Download, Search, CornerDownLeft, Send, Tags, Crown, Info, Activity, HardDrive, Gauge, Gift, PartyPopper, UserPlus, UserCheck, Reply, PenLine, AtSign, MessageCircleMore, FileX2, FileCheck2, Pencil, FolderPlus, SquareArrowOutUpRight, MessagesSquare, Paperclip, X, ArrowRight, MoreHorizontal, SquarePen, Mic, Pause, Play, Square, RotateCcw, Camera, Circle, Image as Image$1, AppWindow } from 'lucide-react';
|
|
31
32
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
@@ -37,9 +38,9 @@ import { AnimatePresence, motion } from 'framer-motion';
|
|
|
37
38
|
import { createPortal } from 'react-dom';
|
|
38
39
|
import ReactMarkdown from 'react-markdown';
|
|
39
40
|
import Cropper from 'react-easy-crop';
|
|
40
|
-
import { AgGridReact } from 'ag-grid-react';
|
|
41
|
-
import { ModuleRegistry, AllCommunityModule } from 'ag-grid-community';
|
|
42
41
|
|
|
42
|
+
// src/host/index.ts
|
|
43
|
+
var ArbiHost2 = ArbiHost;
|
|
43
44
|
function useUpdateConversation() {
|
|
44
45
|
const arbi = useArbi();
|
|
45
46
|
const qc = useQueryClient();
|
|
@@ -279,18 +280,7 @@ function useRevokeAgentAccess() {
|
|
|
279
280
|
const arbi = useArbi();
|
|
280
281
|
const qc = useQueryClient();
|
|
281
282
|
return useMutation({
|
|
282
|
-
mutationFn:
|
|
283
|
-
agentExtId,
|
|
284
|
-
workspaceId
|
|
285
|
-
}) => {
|
|
286
|
-
const previous = arbi.hasWorkspace ? arbi.getWorkspaceId() : null;
|
|
287
|
-
await arbi.selectWorkspace(workspaceId);
|
|
288
|
-
try {
|
|
289
|
-
await arbi.workspaces.removeUsers([agentExtId]);
|
|
290
|
-
} finally {
|
|
291
|
-
if (previous && previous !== workspaceId) await arbi.selectWorkspace(previous);
|
|
292
|
-
}
|
|
293
|
-
},
|
|
283
|
+
mutationFn: ({ agentExtId, workspaceId }) => arbi.workspaces.removeUsers([agentExtId], { workspaceId }),
|
|
294
284
|
onSuccess: (_res, { agentExtId }) => qc.invalidateQueries({ queryKey: arbiQueryKeys.agentWorkspaces(agentExtId) })
|
|
295
285
|
});
|
|
296
286
|
}
|
|
@@ -310,10 +300,7 @@ function useUploadSkillFiles() {
|
|
|
310
300
|
return useMutation({
|
|
311
301
|
mutationFn: async (entries) => {
|
|
312
302
|
if (!entries.length) throw new Error("Choose at least one skill file.");
|
|
313
|
-
for (const entry of entries)
|
|
314
|
-
if (!/^skills\/[a-z0-9][a-z0-9_-]*(?:\/[^/]+)*$/.test(entry.folder) || entry.folder.split("/").some((segment) => segment === ".." || segment === "."))
|
|
315
|
-
throw new Error("Skill files need a folder under skills/<name>.");
|
|
316
|
-
}
|
|
303
|
+
for (const entry of entries) assertSkillFolder(entry.folder);
|
|
317
304
|
const results = [];
|
|
318
305
|
for (const entry of entries) {
|
|
319
306
|
const result = await arbi.documents.uploadFile(entry.content, entry.fileName, {
|
|
@@ -321,10 +308,7 @@ function useUploadSkillFiles() {
|
|
|
321
308
|
wpType: "skill",
|
|
322
309
|
shared: entry.shared ?? false
|
|
323
310
|
});
|
|
324
|
-
|
|
325
|
-
throw new Error(
|
|
326
|
-
result.skipped.map((file) => `${file.file_name}: ${file.reason}`).join("; ")
|
|
327
|
-
);
|
|
311
|
+
throwOnSkipped(result);
|
|
328
312
|
results.push(result);
|
|
329
313
|
}
|
|
330
314
|
return results;
|
|
@@ -332,6 +316,31 @@ function useUploadSkillFiles() {
|
|
|
332
316
|
onSuccess: () => qc.invalidateQueries({ queryKey: arbiQueryKeys.skills() })
|
|
333
317
|
});
|
|
334
318
|
}
|
|
319
|
+
function assertSkillFolder(folder) {
|
|
320
|
+
if (!/^skills\/[a-z0-9][a-z0-9_-]*(?:\/[^/]+)*$/.test(folder) || folder.split("/").some((segment) => segment === ".." || segment === "."))
|
|
321
|
+
throw new Error("Skill files need a folder under skills/<name>.");
|
|
322
|
+
}
|
|
323
|
+
function throwOnSkipped(result) {
|
|
324
|
+
if (result.skipped?.length)
|
|
325
|
+
throw new Error(result.skipped.map((file) => `${file.file_name}: ${file.reason}`).join("; "));
|
|
326
|
+
}
|
|
327
|
+
function useSaveSkill() {
|
|
328
|
+
const arbi = useArbi();
|
|
329
|
+
const qc = useQueryClient();
|
|
330
|
+
return useMutation({
|
|
331
|
+
mutationFn: async ({
|
|
332
|
+
slug,
|
|
333
|
+
markdown,
|
|
334
|
+
shared
|
|
335
|
+
}) => {
|
|
336
|
+
assertSkillFolder(`skills/${slug}`);
|
|
337
|
+
const result = await arbi.assistant.uploadSkill(slug, markdown, { shared });
|
|
338
|
+
throwOnSkipped(result);
|
|
339
|
+
return result;
|
|
340
|
+
},
|
|
341
|
+
onSuccess: () => qc.invalidateQueries({ queryKey: arbiQueryKeys.skills() })
|
|
342
|
+
});
|
|
343
|
+
}
|
|
335
344
|
function useSkillSource(docExtId, options) {
|
|
336
345
|
const arbi = useArbi();
|
|
337
346
|
return useQuery({
|
|
@@ -1334,6 +1343,8 @@ function ArbiWebSocketProvider({ enabled = true, children }) {
|
|
|
1334
1343
|
const onMessage = (msg) => {
|
|
1335
1344
|
if (isMessageType(msg, "task_update")) applyTaskUpdate(msg);
|
|
1336
1345
|
else if (isMessageType(msg, "presence_update")) applyPresence(msg);
|
|
1346
|
+
else if (isMessageType(msg, "batch_complete") && msg.batch_type === "entity_extract")
|
|
1347
|
+
finishEntityExtraction(msg.doc_ext_ids ?? []);
|
|
1337
1348
|
for (const fn of subscribersRef.current) {
|
|
1338
1349
|
try {
|
|
1339
1350
|
fn(msg);
|
|
@@ -1425,6 +1436,100 @@ function useArbiDocumentSync(workspaceId) {
|
|
|
1425
1436
|
});
|
|
1426
1437
|
}
|
|
1427
1438
|
|
|
1439
|
+
// src/session/store.ts
|
|
1440
|
+
var DEFAULT_DOCUMENT_VIEWER_STATE = {
|
|
1441
|
+
tab: "pdf",
|
|
1442
|
+
compareId: null,
|
|
1443
|
+
tabRequest: null,
|
|
1444
|
+
textScale: 1,
|
|
1445
|
+
phonePdfChosen: false
|
|
1446
|
+
};
|
|
1447
|
+
var EMPTY_SESSION_STATE = {
|
|
1448
|
+
workspaceId: null,
|
|
1449
|
+
conversationId: null,
|
|
1450
|
+
viewingDocument: null,
|
|
1451
|
+
documentViewer: DEFAULT_DOCUMENT_VIEWER_STATE,
|
|
1452
|
+
selectedDocumentIds: [],
|
|
1453
|
+
generating: {},
|
|
1454
|
+
paMode: false,
|
|
1455
|
+
conversationDocuments: {}
|
|
1456
|
+
};
|
|
1457
|
+
var selectViewingDocumentId = (state) => state.viewingDocument ? parseVersionRef(state.viewingDocument.id).docId : null;
|
|
1458
|
+
var selectIsGenerating = (conversationId) => (state) => !!conversationId && !!state.generating[conversationId]?.isGenerating;
|
|
1459
|
+
function nextViewingDocument(current, input) {
|
|
1460
|
+
if (!input) return null;
|
|
1461
|
+
const same = current?.id === input.id;
|
|
1462
|
+
return {
|
|
1463
|
+
id: input.id,
|
|
1464
|
+
page: input.page !== void 0 ? input.page : same ? current?.page ?? null : null,
|
|
1465
|
+
passageId: input.passageId !== void 0 ? input.passageId : current?.passageId ?? null
|
|
1466
|
+
};
|
|
1467
|
+
}
|
|
1468
|
+
function createArbiSessionStore(initial = {}) {
|
|
1469
|
+
let state = { ...EMPTY_SESSION_STATE, ...initial };
|
|
1470
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
1471
|
+
const update = (patch) => {
|
|
1472
|
+
state = { ...state, ...patch };
|
|
1473
|
+
listeners.forEach((listener) => listener());
|
|
1474
|
+
};
|
|
1475
|
+
return {
|
|
1476
|
+
getState: () => state,
|
|
1477
|
+
subscribe: (listener) => {
|
|
1478
|
+
listeners.add(listener);
|
|
1479
|
+
return () => listeners.delete(listener);
|
|
1480
|
+
},
|
|
1481
|
+
setWorkspaceId: (workspaceId) => {
|
|
1482
|
+
if (state.workspaceId !== workspaceId) update({ workspaceId });
|
|
1483
|
+
},
|
|
1484
|
+
setConversationId: (conversationId) => {
|
|
1485
|
+
if (state.conversationId !== conversationId) update({ conversationId });
|
|
1486
|
+
},
|
|
1487
|
+
setViewingDocument: (input) => update({ viewingDocument: nextViewingDocument(state.viewingDocument, input) }),
|
|
1488
|
+
setDocumentViewer: (change) => {
|
|
1489
|
+
const next = { ...state.documentViewer, ...change };
|
|
1490
|
+
const keys = Object.keys(change);
|
|
1491
|
+
if (keys.some((key) => next[key] !== state.documentViewer[key]))
|
|
1492
|
+
update({ documentViewer: next });
|
|
1493
|
+
},
|
|
1494
|
+
setSelectedDocumentIds: (ids) => update({ selectedDocumentIds: ids }),
|
|
1495
|
+
setConversationGenerating: (conversationId, isGenerating) => {
|
|
1496
|
+
const current = state.generating[conversationId];
|
|
1497
|
+
update({
|
|
1498
|
+
generating: {
|
|
1499
|
+
...state.generating,
|
|
1500
|
+
[conversationId]: {
|
|
1501
|
+
isGenerating,
|
|
1502
|
+
error: isGenerating ? null : current?.error ?? null,
|
|
1503
|
+
startTime: isGenerating ? Date.now() : null
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
});
|
|
1507
|
+
},
|
|
1508
|
+
setPaMode: (paMode) => {
|
|
1509
|
+
if (state.paMode !== paMode) update({ paMode });
|
|
1510
|
+
},
|
|
1511
|
+
setConversationDocuments: (conversationId, documents2) => update({
|
|
1512
|
+
conversationDocuments: { ...state.conversationDocuments, [conversationId]: documents2 }
|
|
1513
|
+
})
|
|
1514
|
+
};
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1517
|
+
// src/session/session-hooks.ts
|
|
1518
|
+
var moduleDefault = null;
|
|
1519
|
+
var defaultStore = () => moduleDefault ??= createArbiSessionStore();
|
|
1520
|
+
function useArbiSessionStore() {
|
|
1521
|
+
const host = useArbiHost();
|
|
1522
|
+
if (host.session) return host.session;
|
|
1523
|
+
const own = host[OWN_SESSION_SLOT];
|
|
1524
|
+
if (own) return own.current ??= createArbiSessionStore();
|
|
1525
|
+
return defaultStore();
|
|
1526
|
+
}
|
|
1527
|
+
function useArbiSessionState(selector) {
|
|
1528
|
+
const store = useArbiSessionStore();
|
|
1529
|
+
const select = () => selector(store.getState());
|
|
1530
|
+
return useSyncExternalStore(store.subscribe, select, select);
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1428
1533
|
// src/workspaces/shell-workspaces.ts
|
|
1429
1534
|
function getWorkspaceKind(workspace) {
|
|
1430
1535
|
if (workspace.is_public) return "common";
|
|
@@ -1548,14 +1653,20 @@ function useShellWorkspaces(options) {
|
|
|
1548
1653
|
}
|
|
1549
1654
|
function useArbiShellWorkspaces(options = {}) {
|
|
1550
1655
|
const arbi = useArbi();
|
|
1656
|
+
const session = useArbiSessionStore();
|
|
1657
|
+
const sessionWorkspaceId = useArbiSessionState((s) => s.workspaceId);
|
|
1551
1658
|
const query = useWorkspaces();
|
|
1552
1659
|
const { select, ...rest } = options;
|
|
1553
1660
|
const defaultSelect = useCallback(
|
|
1554
|
-
(workspace) =>
|
|
1555
|
-
|
|
1661
|
+
async (workspace) => {
|
|
1662
|
+
await arbi.selectWorkspace(workspace.id);
|
|
1663
|
+
session.setWorkspaceId(workspace.id);
|
|
1664
|
+
},
|
|
1665
|
+
[arbi, session]
|
|
1556
1666
|
);
|
|
1557
1667
|
return useShellWorkspaces({
|
|
1558
1668
|
...rest,
|
|
1669
|
+
selectedId: rest.selectedId !== void 0 ? rest.selectedId : sessionWorkspaceId,
|
|
1559
1670
|
workspaces: Array.isArray(query.data) ? query.data : void 0,
|
|
1560
1671
|
isLoading: query.isLoading,
|
|
1561
1672
|
loadError: query.error,
|
|
@@ -1716,15 +1827,11 @@ function usePassageQuotes(docIds) {
|
|
|
1716
1827
|
[passages]
|
|
1717
1828
|
);
|
|
1718
1829
|
}
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
children
|
|
1723
|
-
}) {
|
|
1724
|
-
return /* @__PURE__ */ jsx(DocumentsSupportContext.Provider, { value: support, children });
|
|
1725
|
-
}
|
|
1830
|
+
|
|
1831
|
+
// src/documents/support.tsx
|
|
1832
|
+
var NO_SUPPORT = {};
|
|
1726
1833
|
function useDocumentsSupport() {
|
|
1727
|
-
return
|
|
1834
|
+
return useArbiHost().documents ?? NO_SUPPORT;
|
|
1728
1835
|
}
|
|
1729
1836
|
function useProcessingTasks() {
|
|
1730
1837
|
const { useProcessingTasks: useHostTasks } = useDocumentsSupport();
|
|
@@ -1738,6 +1845,24 @@ function useProcessingTask(docId) {
|
|
|
1738
1845
|
const host = useHostTask?.(docId);
|
|
1739
1846
|
return useHostTask ? host : own;
|
|
1740
1847
|
}
|
|
1848
|
+
var NO_ACTIONS = {};
|
|
1849
|
+
var NO_IDS = /* @__PURE__ */ new Set();
|
|
1850
|
+
function useDocumentHostActions() {
|
|
1851
|
+
const { useHostActions } = useDocumentsSupport();
|
|
1852
|
+
return useHostActions?.() ?? NO_ACTIONS;
|
|
1853
|
+
}
|
|
1854
|
+
function useOfflineDocumentIds() {
|
|
1855
|
+
const { useOfflineDocumentIds: useHostIds } = useDocumentsSupport();
|
|
1856
|
+
return useHostIds?.() ?? NO_IDS;
|
|
1857
|
+
}
|
|
1858
|
+
function useOpenViewerDocumentId() {
|
|
1859
|
+
const { useOpenViewerDocumentId: useHostViewing } = useDocumentsSupport();
|
|
1860
|
+
return useHostViewing?.() ?? null;
|
|
1861
|
+
}
|
|
1862
|
+
function useDocumentPendingSync(docId) {
|
|
1863
|
+
const { useDocumentPendingSync: useHostPending } = useDocumentsSupport();
|
|
1864
|
+
return useHostPending?.(docId) ?? false;
|
|
1865
|
+
}
|
|
1741
1866
|
|
|
1742
1867
|
// src/documents/documents-writes.ts
|
|
1743
1868
|
function applyOptimisticDocumentEdit(qc, updates) {
|
|
@@ -2059,19 +2184,21 @@ function registerArbiMutationDefaults(queryClient, client) {
|
|
|
2059
2184
|
});
|
|
2060
2185
|
}
|
|
2061
2186
|
}
|
|
2062
|
-
var
|
|
2187
|
+
var DOCUMENT_FAMILIES = [
|
|
2063
2188
|
"documents",
|
|
2064
2189
|
"document",
|
|
2065
2190
|
"documentsById",
|
|
2066
2191
|
"documentVersions",
|
|
2067
2192
|
"similarDocuments"
|
|
2068
2193
|
];
|
|
2194
|
+
var OFFLINE_READABLE = [...DOCUMENT_FAMILIES, "workspaces", "userSettings"];
|
|
2069
2195
|
function isOfflineReadableArbiQuery(queryKey) {
|
|
2070
2196
|
return queryKey[0] === "arbi" && OFFLINE_READABLE.includes(queryKey[1]);
|
|
2071
2197
|
}
|
|
2072
2198
|
function isRestorableArbiQueryOnline(queryKey, data) {
|
|
2073
2199
|
if (queryKey[0] !== "arbi") return true;
|
|
2074
2200
|
if (queryKey[1] === "documents") return false;
|
|
2201
|
+
if (!DOCUMENT_FAMILIES.includes(queryKey[1])) return true;
|
|
2075
2202
|
const docs = Array.isArray(data) ? data : [data];
|
|
2076
2203
|
return !docs.some((doc) => {
|
|
2077
2204
|
const status = doc?.status;
|
|
@@ -2335,7 +2462,8 @@ function useContacts(options) {
|
|
|
2335
2462
|
return useQuery({
|
|
2336
2463
|
queryKey: arbiQueryKeys.contacts(),
|
|
2337
2464
|
queryFn: () => arbi.contacts.list(),
|
|
2338
|
-
enabled: (options?.enabled ?? true) && arbi.isLoggedIn
|
|
2465
|
+
enabled: (options?.enabled ?? true) && arbi.isLoggedIn,
|
|
2466
|
+
staleTime: 3e4
|
|
2339
2467
|
});
|
|
2340
2468
|
}
|
|
2341
2469
|
function usePendingContacts(options) {
|
|
@@ -2374,6 +2502,26 @@ function useUpdateContact() {
|
|
|
2374
2502
|
onSuccess: () => invalidate()
|
|
2375
2503
|
});
|
|
2376
2504
|
}
|
|
2505
|
+
function useLinkContact() {
|
|
2506
|
+
const arbi = useArbi();
|
|
2507
|
+
const invalidate = useInvalidateContacts();
|
|
2508
|
+
return useMutation({
|
|
2509
|
+
mutationFn: ({
|
|
2510
|
+
contact,
|
|
2511
|
+
email,
|
|
2512
|
+
card
|
|
2513
|
+
}) => contact.external_id ? arbi.contacts.link(contact.external_id, email, card) : arbi.contacts.create({ email, card, invite: true }),
|
|
2514
|
+
onSettled: () => invalidate()
|
|
2515
|
+
});
|
|
2516
|
+
}
|
|
2517
|
+
function useImportContacts() {
|
|
2518
|
+
const arbi = useArbi();
|
|
2519
|
+
const invalidate = useInvalidateContacts();
|
|
2520
|
+
return useMutation({
|
|
2521
|
+
mutationFn: (file) => arbi.contacts.import(file),
|
|
2522
|
+
onSettled: () => invalidate()
|
|
2523
|
+
});
|
|
2524
|
+
}
|
|
2377
2525
|
function useDeleteContact() {
|
|
2378
2526
|
const arbi = useArbi();
|
|
2379
2527
|
const invalidate = useInvalidateContacts();
|
|
@@ -2422,7 +2570,6 @@ function useSetWorkspaceHouseTemplate() {
|
|
|
2422
2570
|
var supportsHouseTemplates = houseTemplates.supportsHouseTemplates;
|
|
2423
2571
|
var workspaceHouseTemplateId = houseTemplates.workspaceHouseTemplateId;
|
|
2424
2572
|
var isDeploymentAdmin = houseTemplates.isDeploymentAdmin;
|
|
2425
|
-
var AccountClientContext = createContext(null);
|
|
2426
2573
|
function arbiProfile(arbi) {
|
|
2427
2574
|
const profile = arbi.user.profile();
|
|
2428
2575
|
return profile ? toProfileView(profile) : null;
|
|
@@ -2462,7 +2609,7 @@ function arbiAccountClient(arbi, overrides = {}) {
|
|
|
2462
2609
|
...overrides
|
|
2463
2610
|
};
|
|
2464
2611
|
}
|
|
2465
|
-
var NO_ACCOUNT_ERROR = "The account needs an <
|
|
2612
|
+
var NO_ACCOUNT_ERROR = "The account needs an <ArbiHost> with `account` or an `arbi`";
|
|
2466
2613
|
var refuse = () => Promise.reject(new Error(NO_ACCOUNT_ERROR));
|
|
2467
2614
|
var NO_ACCOUNT = {
|
|
2468
2615
|
client: {
|
|
@@ -2489,18 +2636,14 @@ var NO_ACCOUNT = {
|
|
|
2489
2636
|
},
|
|
2490
2637
|
enabled: false
|
|
2491
2638
|
};
|
|
2492
|
-
|
|
2493
|
-
client,
|
|
2494
|
-
enabled = true,
|
|
2495
|
-
children
|
|
2496
|
-
}) {
|
|
2497
|
-
const value = useMemo(() => ({ client, enabled }), [client, enabled]);
|
|
2498
|
-
return /* @__PURE__ */ jsx(AccountClientContext.Provider, { value, children });
|
|
2499
|
-
}
|
|
2639
|
+
var ALWAYS = () => true;
|
|
2500
2640
|
function useAccountClient() {
|
|
2501
|
-
const
|
|
2502
|
-
const arbi = useContext(ArbiContext);
|
|
2641
|
+
const { account, arbi } = useArbiHost();
|
|
2503
2642
|
const fallback = useMemo(() => arbi ? arbiAccountClient(arbi) : null, [arbi]);
|
|
2643
|
+
const useEnabled = account?.useEnabled ?? ALWAYS;
|
|
2644
|
+
const enabled = useEnabled();
|
|
2645
|
+
const client = account?.client;
|
|
2646
|
+
const provided = useMemo(() => client ? { client, enabled } : null, [client, enabled]);
|
|
2504
2647
|
if (provided) return provided;
|
|
2505
2648
|
if (!arbi || !fallback) return NO_ACCOUNT;
|
|
2506
2649
|
return { client: fallback, enabled: arbi.isLoggedIn };
|
|
@@ -3311,6 +3454,39 @@ async function downloadRecoveryFile(params) {
|
|
|
3311
3454
|
});
|
|
3312
3455
|
downloadBlob(new Blob([file.html], { type: "text/html" }), file.filename);
|
|
3313
3456
|
}
|
|
3457
|
+
function useEntitlements() {
|
|
3458
|
+
const arbi = useArbi();
|
|
3459
|
+
return useQuery({
|
|
3460
|
+
queryKey: arbiQueryKeys.entitlements(),
|
|
3461
|
+
queryFn: () => arbi.account.entitlements(),
|
|
3462
|
+
enabled: arbi.isLoggedIn,
|
|
3463
|
+
// A plan change shows on the next read; the API enforces it at once either way.
|
|
3464
|
+
staleTime: 5 * 60 * 1e3
|
|
3465
|
+
});
|
|
3466
|
+
}
|
|
3467
|
+
function useIsEntitled(feature) {
|
|
3468
|
+
const { data } = useEntitlements();
|
|
3469
|
+
return data?.[feature] === true;
|
|
3470
|
+
}
|
|
3471
|
+
function entitlementRefusal(reason) {
|
|
3472
|
+
switch (reason) {
|
|
3473
|
+
case "external_user":
|
|
3474
|
+
return {
|
|
3475
|
+
title: "Not available for external users",
|
|
3476
|
+
description: "Mail, Calendar and hosting calls are for members of the firm. You can still join calls others host."
|
|
3477
|
+
};
|
|
3478
|
+
case "not_entitled":
|
|
3479
|
+
return {
|
|
3480
|
+
title: "Not available on this account",
|
|
3481
|
+
description: "Mail, Calendar and hosting calls are not available on this account."
|
|
3482
|
+
};
|
|
3483
|
+
default:
|
|
3484
|
+
return {
|
|
3485
|
+
title: "Available on Pro",
|
|
3486
|
+
description: "Mail, Calendar and hosting calls come with a Pro plan. You can still join calls others host."
|
|
3487
|
+
};
|
|
3488
|
+
}
|
|
3489
|
+
}
|
|
3314
3490
|
|
|
3315
3491
|
// src/mail/client.ts
|
|
3316
3492
|
var MailOfflineUnavailableError = class extends Error {
|
|
@@ -3400,27 +3576,24 @@ function mailDraftIdFromContent(content) {
|
|
|
3400
3576
|
return void 0;
|
|
3401
3577
|
}
|
|
3402
3578
|
}
|
|
3403
|
-
var MailClientContext = createContext(null);
|
|
3404
3579
|
var NO_MAIL = {
|
|
3405
3580
|
client: createMailClient(
|
|
3406
|
-
() => Promise.reject(new Error("Mail needs
|
|
3581
|
+
() => Promise.reject(new Error("Mail needs an <ArbiHost> with `mail` or an `arbi`"))
|
|
3407
3582
|
),
|
|
3408
3583
|
enabled: false,
|
|
3409
3584
|
sessionKey: null
|
|
3410
3585
|
};
|
|
3411
|
-
|
|
3412
|
-
client,
|
|
3413
|
-
enabled = true,
|
|
3414
|
-
sessionKey = "session",
|
|
3415
|
-
children
|
|
3416
|
-
}) {
|
|
3417
|
-
const value = useMemo(() => ({ client, enabled, sessionKey }), [client, enabled, sessionKey]);
|
|
3418
|
-
return /* @__PURE__ */ jsx(MailClientContext.Provider, { value, children });
|
|
3419
|
-
}
|
|
3586
|
+
var ALWAYS2 = () => ({ enabled: true, sessionKey: "session" });
|
|
3420
3587
|
function useMailClient() {
|
|
3421
|
-
const
|
|
3422
|
-
const arbi = useContext(ArbiContext);
|
|
3588
|
+
const { mail, arbi } = useArbiHost();
|
|
3423
3589
|
const fallback = useMemo(() => arbi ? arbiMailClient(arbi) : null, [arbi]);
|
|
3590
|
+
const useStatus = mail ? mail.useStatus ?? ALWAYS2 : ALWAYS2;
|
|
3591
|
+
const { enabled, sessionKey } = useStatus();
|
|
3592
|
+
const client = mail?.client;
|
|
3593
|
+
const provided = useMemo(
|
|
3594
|
+
() => client ? { client, enabled, sessionKey } : null,
|
|
3595
|
+
[client, enabled, sessionKey]
|
|
3596
|
+
);
|
|
3424
3597
|
if (provided) return provided;
|
|
3425
3598
|
if (!arbi || !fallback) return NO_MAIL;
|
|
3426
3599
|
let identity = null;
|
|
@@ -4005,18 +4178,14 @@ function useConnectorAutoSync(workspaceExtId, opened) {
|
|
|
4005
4178
|
function connectorErrorStatus(err) {
|
|
4006
4179
|
return err instanceof ArbiApiError ? err.status : void 0;
|
|
4007
4180
|
}
|
|
4181
|
+
|
|
4182
|
+
// src/calendar/support.tsx
|
|
4008
4183
|
function isQueuedCalendarWrite(value) {
|
|
4009
4184
|
return !!value && typeof value === "object" && value.queued === true;
|
|
4010
4185
|
}
|
|
4011
|
-
var
|
|
4012
|
-
function CalendarSupportProvider({
|
|
4013
|
-
value,
|
|
4014
|
-
children
|
|
4015
|
-
}) {
|
|
4016
|
-
return /* @__PURE__ */ jsx(CalendarSupportContext.Provider, { value, children });
|
|
4017
|
-
}
|
|
4186
|
+
var NO_SUPPORT2 = {};
|
|
4018
4187
|
function useCalendarSupport() {
|
|
4019
|
-
const support =
|
|
4188
|
+
const support = useArbiHost().calendar ?? NO_SUPPORT2;
|
|
4020
4189
|
const arbi = useArbi();
|
|
4021
4190
|
const qc = useQueryClient();
|
|
4022
4191
|
return useMemo(
|
|
@@ -6673,164 +6842,571 @@ function userDisplayName(user) {
|
|
|
6673
6842
|
function isAgentUser(user) {
|
|
6674
6843
|
return user.external_id.startsWith("agt-");
|
|
6675
6844
|
}
|
|
6676
|
-
|
|
6677
|
-
|
|
6678
|
-
|
|
6679
|
-
|
|
6680
|
-
|
|
6681
|
-
for (const c of contacts) {
|
|
6682
|
-
const peer = c.user;
|
|
6683
|
-
if (!peer?.external_id || byPeer.has(peer.external_id)) continue;
|
|
6684
|
-
byPeer.set(peer.external_id, { peer, messages: [], unreadCount: 0, isContactOnly: true });
|
|
6845
|
+
function myChatId(arbi) {
|
|
6846
|
+
try {
|
|
6847
|
+
return arbi.user.identity()?.externalId ?? null;
|
|
6848
|
+
} catch {
|
|
6849
|
+
return null;
|
|
6685
6850
|
}
|
|
6686
|
-
|
|
6687
|
-
|
|
6688
|
-
|
|
6689
|
-
|
|
6690
|
-
|
|
6691
|
-
|
|
6692
|
-
|
|
6851
|
+
}
|
|
6852
|
+
var openChatExtId = null;
|
|
6853
|
+
function setOpenChat(chatExtId) {
|
|
6854
|
+
openChatExtId = chatExtId;
|
|
6855
|
+
}
|
|
6856
|
+
function getOpenChat() {
|
|
6857
|
+
return openChatExtId;
|
|
6858
|
+
}
|
|
6859
|
+
function byActivity(a, b) {
|
|
6860
|
+
const at = Date.parse(a.last_message_at ?? a.created_at);
|
|
6861
|
+
const bt = Date.parse(b.last_message_at ?? b.created_at);
|
|
6862
|
+
return bt - at;
|
|
6863
|
+
}
|
|
6864
|
+
function cachedChats(queryClient) {
|
|
6865
|
+
return queryClient.getQueryData(arbiQueryKeys.chatList()) ?? [];
|
|
6866
|
+
}
|
|
6867
|
+
function cachedChat(queryClient, chatExtId) {
|
|
6868
|
+
return cachedChats(queryClient).find((c) => c.external_id === chatExtId);
|
|
6869
|
+
}
|
|
6870
|
+
function upsertChat(queryClient, chat) {
|
|
6871
|
+
queryClient.setQueryData(arbiQueryKeys.chatList(), (old) => {
|
|
6872
|
+
if (!old) return old;
|
|
6873
|
+
const rest = old.filter((c) => c.external_id !== chat.external_id);
|
|
6874
|
+
return [chat, ...rest].sort(byActivity);
|
|
6693
6875
|
});
|
|
6694
6876
|
}
|
|
6695
|
-
function
|
|
6696
|
-
|
|
6697
|
-
|
|
6698
|
-
|
|
6699
|
-
|
|
6700
|
-
|
|
6701
|
-
|
|
6702
|
-
|
|
6703
|
-
|
|
6704
|
-
|
|
6705
|
-
|
|
6706
|
-
|
|
6707
|
-
|
|
6708
|
-
|
|
6709
|
-
|
|
6877
|
+
function removeChat(queryClient, chatExtId) {
|
|
6878
|
+
queryClient.setQueryData(
|
|
6879
|
+
arbiQueryKeys.chatList(),
|
|
6880
|
+
(old) => old?.filter((c) => c.external_id !== chatExtId)
|
|
6881
|
+
);
|
|
6882
|
+
queryClient.removeQueries({ queryKey: arbiQueryKeys.chatThread(chatExtId) });
|
|
6883
|
+
}
|
|
6884
|
+
function appendToThread(queryClient, chatExtId, message, replaceOptimisticId) {
|
|
6885
|
+
queryClient.setQueryData(arbiQueryKeys.chatThread(chatExtId), (old) => {
|
|
6886
|
+
if (!old) return old;
|
|
6887
|
+
const without = old.messages.filter(
|
|
6888
|
+
(m) => m.external_id !== message.external_id && m.external_id !== replaceOptimisticId
|
|
6889
|
+
);
|
|
6890
|
+
return { ...old, messages: [...without, message] };
|
|
6891
|
+
});
|
|
6892
|
+
}
|
|
6893
|
+
function dropFromThread(queryClient, chatExtId, messageExtId) {
|
|
6894
|
+
queryClient.setQueryData(
|
|
6895
|
+
arbiQueryKeys.chatThread(chatExtId),
|
|
6896
|
+
(old) => old ? { ...old, messages: old.messages.filter((m) => m.external_id !== messageExtId) } : old
|
|
6897
|
+
);
|
|
6898
|
+
}
|
|
6899
|
+
function replaceInThread(queryClient, chatExtId, message) {
|
|
6900
|
+
queryClient.setQueryData(arbiQueryKeys.chatThread(chatExtId), (old) => {
|
|
6901
|
+
if (!old || !old.messages.some((m) => m.external_id === message.external_id)) return old;
|
|
6710
6902
|
return {
|
|
6711
|
-
|
|
6712
|
-
|
|
6713
|
-
body: m.deleted ? "" : m.content ?? "",
|
|
6714
|
-
createdAt: m.created_at,
|
|
6715
|
-
isMine,
|
|
6716
|
-
// Mine: has the peer read it? Theirs: have I?
|
|
6717
|
-
read: chats.hasRead(isMine ? peerMember : meMember, m),
|
|
6718
|
-
sender,
|
|
6719
|
-
recipient: isMine ? peer : meMember?.user,
|
|
6720
|
-
chatExtId: chat.external_id,
|
|
6721
|
-
...m.deleted ? { deleted: true } : {}
|
|
6903
|
+
...old,
|
|
6904
|
+
messages: old.messages.map((m) => m.external_id === message.external_id ? message : m)
|
|
6722
6905
|
};
|
|
6723
6906
|
});
|
|
6724
|
-
messages.sort((a, b) => a.createdAt.localeCompare(b.createdAt));
|
|
6725
|
-
if (messages.length === 0) return null;
|
|
6726
|
-
const shown = messages.filter((m) => !m.deleted);
|
|
6727
|
-
return {
|
|
6728
|
-
peer,
|
|
6729
|
-
chatExtId: chat.external_id,
|
|
6730
|
-
messages,
|
|
6731
|
-
lastMessage: shown[shown.length - 1],
|
|
6732
|
-
unreadCount: chat.unread_count ?? 0
|
|
6733
|
-
};
|
|
6734
6907
|
}
|
|
6735
|
-
function
|
|
6736
|
-
|
|
6737
|
-
|
|
6738
|
-
|
|
6739
|
-
|
|
6740
|
-
|
|
6741
|
-
|
|
6742
|
-
|
|
6743
|
-
|
|
6744
|
-
|
|
6745
|
-
|
|
6746
|
-
|
|
6747
|
-
const
|
|
6748
|
-
|
|
6749
|
-
|
|
6750
|
-
enabled
|
|
6751
|
-
});
|
|
6752
|
-
const invalidate = () => queryClient.invalidateQueries({ queryKey: DM_QUERY_KEY });
|
|
6753
|
-
useArbiWsMessage("chat.message", () => void invalidate());
|
|
6754
|
-
useArbiWsMessage("chat.read", () => void invalidate());
|
|
6755
|
-
useArbiWsMessage("chat.updated", () => void invalidate());
|
|
6756
|
-
let myExtId = null;
|
|
6908
|
+
function patchLastMessage(queryClient, chatExtId, message) {
|
|
6909
|
+
queryClient.setQueryData(
|
|
6910
|
+
arbiQueryKeys.chatList(),
|
|
6911
|
+
(old) => old?.map(
|
|
6912
|
+
(c) => c.external_id === chatExtId && c.last_message?.external_id === message.external_id ? { ...c, last_message: message } : c
|
|
6913
|
+
)
|
|
6914
|
+
);
|
|
6915
|
+
}
|
|
6916
|
+
async function deleteChatMessage(arbi, queryClient, chatExtId, messageExtId) {
|
|
6917
|
+
const thread = queryClient.getQueryData(arbiQueryKeys.chatThread(chatExtId));
|
|
6918
|
+
const before = thread?.messages.find((m) => m.external_id === messageExtId);
|
|
6919
|
+
const listed = cachedChat(queryClient, chatExtId);
|
|
6920
|
+
const wasLast = listed?.last_message?.external_id === messageExtId ? listed.last_message : null;
|
|
6921
|
+
if (before) replaceInThread(queryClient, chatExtId, chats.chatMessageTombstone(before));
|
|
6922
|
+
if (wasLast) patchLastMessage(queryClient, chatExtId, chats.chatMessageTombstone(wasLast));
|
|
6757
6923
|
try {
|
|
6758
|
-
|
|
6759
|
-
} catch {
|
|
6760
|
-
|
|
6924
|
+
await arbi.chats.deleteMessage(chatExtId, messageExtId);
|
|
6925
|
+
} catch (err) {
|
|
6926
|
+
if (before) replaceInThread(queryClient, chatExtId, before);
|
|
6927
|
+
if (wasLast) patchLastMessage(queryClient, chatExtId, wasLast);
|
|
6928
|
+
throw err;
|
|
6761
6929
|
}
|
|
6762
|
-
const [pendingSent, setPendingSent] = useState([]);
|
|
6763
|
-
const serverIds = useMemo(
|
|
6764
|
-
() => new Set((query.data ?? []).flatMap((c) => c.messages.map((m) => m.external_id))),
|
|
6765
|
-
[query.data]
|
|
6766
|
-
);
|
|
6767
|
-
useEffect(() => {
|
|
6768
|
-
setPendingSent(
|
|
6769
|
-
(pending) => pending.some((p) => serverIds.has(p.message.external_id)) ? pending.filter((p) => !serverIds.has(p.message.external_id)) : pending
|
|
6770
|
-
);
|
|
6771
|
-
}, [serverIds]);
|
|
6772
|
-
const conversations = useMemo(() => {
|
|
6773
|
-
const pending = pendingSent.filter((p) => !serverIds.has(p.message.external_id));
|
|
6774
|
-
const pendingMessages = pending.map((p) => p.message);
|
|
6775
|
-
const threads = (query.data ?? []).map((loaded) => toConversation(loaded, myExtId, pendingMessages)).filter((c) => c !== null);
|
|
6776
|
-
const merged = mergeContacts(threads, contactsQuery.data ?? []);
|
|
6777
|
-
return merged.map((c) => {
|
|
6778
|
-
if (c.chatExtId) return c;
|
|
6779
|
-
const mine = pending.filter((p) => p.peerExtId === c.peer.external_id);
|
|
6780
|
-
if (!mine.length) return c;
|
|
6781
|
-
const messages = mine.map(({ message: m }) => ({
|
|
6782
|
-
externalId: m.external_id,
|
|
6783
|
-
body: m.content ?? "",
|
|
6784
|
-
createdAt: m.created_at,
|
|
6785
|
-
isMine: true,
|
|
6786
|
-
read: false,
|
|
6787
|
-
sender: { external_id: myExtId ?? "usr-me" },
|
|
6788
|
-
recipient: c.peer,
|
|
6789
|
-
chatExtId: m.chat_ext_id
|
|
6790
|
-
})).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
|
|
6791
|
-
return {
|
|
6792
|
-
...c,
|
|
6793
|
-
isContactOnly: false,
|
|
6794
|
-
chatExtId: messages[0].chatExtId,
|
|
6795
|
-
messages,
|
|
6796
|
-
lastMessage: messages[messages.length - 1]
|
|
6797
|
-
};
|
|
6798
|
-
});
|
|
6799
|
-
}, [query.data, serverIds, pendingSent, contactsQuery.data, myExtId]);
|
|
6800
|
-
const absorbSent = (message, peerExtId) => {
|
|
6801
|
-
setPendingSent((pending) => [{ message, peerExtId }, ...pending]);
|
|
6802
|
-
void invalidate();
|
|
6803
|
-
};
|
|
6804
|
-
const sendMutation = useMutation({
|
|
6805
|
-
mutationFn: (vars) => arbi.dm.sendTo(vars.recipientExtId, vars.text),
|
|
6806
|
-
onSuccess: (message, vars) => absorbSent(message, vars.recipientExtId)
|
|
6807
|
-
});
|
|
6808
|
-
const sendToMutation = useMutation({
|
|
6809
|
-
mutationFn: (vars) => arbi.dm.send(vars.recipient, vars.text),
|
|
6810
|
-
onSuccess: (message, vars) => absorbSent(message, vars.recipient.includes("@") ? void 0 : vars.recipient)
|
|
6811
|
-
});
|
|
6812
|
-
const markReadMutation = useMutation({
|
|
6813
|
-
mutationFn: (vars) => arbi.chats.markRead(vars.chatExtId, vars.messageExtId),
|
|
6814
|
-
onSuccess: invalidate
|
|
6815
|
-
});
|
|
6816
|
-
return {
|
|
6817
|
-
conversations,
|
|
6818
|
-
myExtId,
|
|
6819
|
-
isLoading: (query.isLoading || contactsQuery.isLoading) && enabled,
|
|
6820
|
-
isError: query.isError,
|
|
6821
|
-
error: query.error,
|
|
6822
|
-
refetch: () => void query.refetch(),
|
|
6823
|
-
sendMessage: (recipientExtId, _recipientPublicKey, text) => sendMutation.mutateAsync({ recipientExtId, text }),
|
|
6824
|
-
sendMessageTo: (recipient, text) => sendToMutation.mutateAsync({ recipient, text }),
|
|
6825
|
-
isSending: sendMutation.isPending || sendToMutation.isPending,
|
|
6826
|
-
sendError: sendMutation.error ?? sendToMutation.error,
|
|
6827
|
-
markRead: (chatExtId, messageExtId) => markReadMutation.mutateAsync({ chatExtId, messageExtId })
|
|
6828
|
-
};
|
|
6829
6930
|
}
|
|
6830
|
-
function
|
|
6831
|
-
|
|
6832
|
-
|
|
6833
|
-
|
|
6931
|
+
async function applyChangedMessage(arbi, queryClient, chatExtId, message) {
|
|
6932
|
+
if (message.deleted) {
|
|
6933
|
+
replaceInThread(queryClient, chatExtId, chats.chatMessageTombstone(message));
|
|
6934
|
+
patchLastMessage(queryClient, chatExtId, chats.chatMessageTombstone(message));
|
|
6935
|
+
return;
|
|
6936
|
+
}
|
|
6937
|
+
const chat = cachedChat(queryClient, chatExtId);
|
|
6938
|
+
if (!chat || !queryClient.getQueryData(arbiQueryKeys.chatThread(chatExtId))) return;
|
|
6939
|
+
try {
|
|
6940
|
+
replaceInThread(queryClient, chatExtId, await arbi.chats.decrypt(chat, message));
|
|
6941
|
+
} catch (err) {
|
|
6942
|
+
console.error("[chats] could not decrypt a changed message", err);
|
|
6943
|
+
}
|
|
6944
|
+
}
|
|
6945
|
+
async function applyChatMessage(arbi, queryClient, chatExtId, message) {
|
|
6946
|
+
if (message.deleted) return applyChangedMessage(arbi, queryClient, chatExtId, message);
|
|
6947
|
+
const me = myChatId(arbi);
|
|
6948
|
+
const chat = cachedChat(queryClient, chatExtId);
|
|
6949
|
+
if (!chat) {
|
|
6950
|
+
void queryClient.invalidateQueries({ queryKey: arbiQueryKeys.chatList() });
|
|
6951
|
+
return;
|
|
6952
|
+
}
|
|
6953
|
+
const mine = message.sender_ext_id === me;
|
|
6954
|
+
const isOpen = openChatExtId === chatExtId;
|
|
6955
|
+
upsertChat(queryClient, {
|
|
6956
|
+
...chat,
|
|
6957
|
+
last_message: message,
|
|
6958
|
+
last_message_at: message.created_at,
|
|
6959
|
+
unread_count: mine ? 0 : isOpen ? chat.unread_count : chat.unread_count + 1,
|
|
6960
|
+
members: mine ? chat.members.map(
|
|
6961
|
+
(m) => m.user.external_id === me ? { ...m, last_read_at: message.created_at } : m
|
|
6962
|
+
) : chat.members
|
|
6963
|
+
});
|
|
6964
|
+
if (queryClient.getQueryData(arbiQueryKeys.chatThread(chatExtId))) {
|
|
6965
|
+
try {
|
|
6966
|
+
appendToThread(queryClient, chatExtId, await arbi.chats.decrypt(chat, message));
|
|
6967
|
+
} catch (err) {
|
|
6968
|
+
console.error("[chats] could not decrypt a live message", err);
|
|
6969
|
+
}
|
|
6970
|
+
}
|
|
6971
|
+
}
|
|
6972
|
+
function applyChatRead(arbi, queryClient, chatExtId, userExtId, lastReadAt) {
|
|
6973
|
+
const me = myChatId(arbi);
|
|
6974
|
+
queryClient.setQueryData(
|
|
6975
|
+
arbiQueryKeys.chatList(),
|
|
6976
|
+
(old) => old?.map(
|
|
6977
|
+
(c) => c.external_id !== chatExtId ? c : {
|
|
6978
|
+
...c,
|
|
6979
|
+
unread_count: userExtId === me ? 0 : c.unread_count,
|
|
6980
|
+
members: c.members.map(
|
|
6981
|
+
(m) => m.user.external_id === userExtId ? { ...m, last_read_at: lastReadAt } : m
|
|
6982
|
+
)
|
|
6983
|
+
}
|
|
6984
|
+
)
|
|
6985
|
+
);
|
|
6986
|
+
}
|
|
6987
|
+
async function applyChatUpdated(arbi, queryClient, chatExtId, message) {
|
|
6988
|
+
if (message) await applyChangedMessage(arbi, queryClient, chatExtId, message);
|
|
6989
|
+
let chat;
|
|
6990
|
+
try {
|
|
6991
|
+
chat = await arbi.chats.get(chatExtId);
|
|
6992
|
+
} catch {
|
|
6993
|
+
removeChat(queryClient, chatExtId);
|
|
6994
|
+
return;
|
|
6995
|
+
}
|
|
6996
|
+
if (chat.rotation_required) {
|
|
6997
|
+
chat = await arbi.chats.ready(chat).catch(() => chat);
|
|
6998
|
+
}
|
|
6999
|
+
upsertChat(queryClient, chat);
|
|
7000
|
+
if (!message)
|
|
7001
|
+
void queryClient.invalidateQueries({ queryKey: arbiQueryKeys.chatThread(chatExtId) });
|
|
7002
|
+
}
|
|
7003
|
+
function applyAgentDmStatus(queryClient, status) {
|
|
7004
|
+
if (!["queued", "working", "done", "failed"].includes(status.status)) return;
|
|
7005
|
+
queryClient.setQueryData(arbiQueryKeys.agentDmStatus(status.agent_ext_id), status);
|
|
7006
|
+
}
|
|
7007
|
+
async function applyChatEvent(arbi, queryClient, event) {
|
|
7008
|
+
const e = event;
|
|
7009
|
+
if (e.type === "chat.message")
|
|
7010
|
+
return applyChatMessage(arbi, queryClient, e.chat_ext_id, e.message);
|
|
7011
|
+
if (e.type === "chat.read")
|
|
7012
|
+
return applyChatRead(arbi, queryClient, e.chat_ext_id, e.user_ext_id, e.last_read_at);
|
|
7013
|
+
if (e.type === "chat.updated")
|
|
7014
|
+
return applyChatUpdated(arbi, queryClient, e.chat_ext_id, e.message);
|
|
7015
|
+
if (e.type === "agent_dm_status") applyAgentDmStatus(queryClient, e);
|
|
7016
|
+
}
|
|
7017
|
+
function useChats(options = {}) {
|
|
7018
|
+
const arbi = useArbi();
|
|
7019
|
+
return useQuery({
|
|
7020
|
+
queryKey: arbiQueryKeys.chatList(),
|
|
7021
|
+
queryFn: () => arbi.chats.list(),
|
|
7022
|
+
enabled: (options.enabled ?? true) && arbi.isLoggedIn
|
|
7023
|
+
});
|
|
7024
|
+
}
|
|
7025
|
+
function useChatLiveUpdates() {
|
|
7026
|
+
const arbi = useArbi();
|
|
7027
|
+
const queryClient = useQueryClient();
|
|
7028
|
+
const ws = useContext(ArbiWsContext);
|
|
7029
|
+
const arbiRef = useRef(arbi);
|
|
7030
|
+
arbiRef.current = arbi;
|
|
7031
|
+
useEffect(
|
|
7032
|
+
() => ws?.subscribe((message) => {
|
|
7033
|
+
if (message.type.startsWith("chat.") || message.type === "agent_dm_status")
|
|
7034
|
+
void applyChatEvent(arbiRef.current, queryClient, message);
|
|
7035
|
+
}),
|
|
7036
|
+
[ws, queryClient]
|
|
7037
|
+
);
|
|
7038
|
+
}
|
|
7039
|
+
function useAgentDmStatus(agentExtId) {
|
|
7040
|
+
const { data } = useQuery({
|
|
7041
|
+
queryKey: arbiQueryKeys.agentDmStatus(agentExtId ?? ""),
|
|
7042
|
+
// Written by the events only: nothing to fetch.
|
|
7043
|
+
queryFn: () => null,
|
|
7044
|
+
enabled: false,
|
|
7045
|
+
staleTime: Infinity
|
|
7046
|
+
});
|
|
7047
|
+
return agentExtId ? data ?? void 0 : void 0;
|
|
7048
|
+
}
|
|
7049
|
+
function useChatUnreadTotal() {
|
|
7050
|
+
const { data = [] } = useChats();
|
|
7051
|
+
return useMemo(() => data.reduce((sum, c) => sum + (c.unread_count ?? 0), 0), [data]);
|
|
7052
|
+
}
|
|
7053
|
+
function useUnreadByPeer() {
|
|
7054
|
+
const arbi = useArbi();
|
|
7055
|
+
const { data = [] } = useChats();
|
|
7056
|
+
const me = myChatId(arbi);
|
|
7057
|
+
return useMemo(() => {
|
|
7058
|
+
const out = /* @__PURE__ */ new Map();
|
|
7059
|
+
for (const c of data) {
|
|
7060
|
+
if (c.kind !== "direct" || !c.unread_count) continue;
|
|
7061
|
+
const peer = c.members.find((m) => m.user.external_id !== me)?.user.external_id ?? me;
|
|
7062
|
+
if (peer) out.set(peer, (out.get(peer) ?? 0) + c.unread_count);
|
|
7063
|
+
}
|
|
7064
|
+
return out;
|
|
7065
|
+
}, [data, me]);
|
|
7066
|
+
}
|
|
7067
|
+
function useChatSummaries(chats3) {
|
|
7068
|
+
const arbi = useArbi();
|
|
7069
|
+
const [summaries, setSummaries] = useState({});
|
|
7070
|
+
const runId = useRef(0);
|
|
7071
|
+
const key = chats3.map(
|
|
7072
|
+
(c) => `${c.external_id}:${c.key_version}:${c.title ?? ""}:${c.last_message?.external_id ?? ""}:${c.last_message?.deleted ? "x" : ""}`
|
|
7073
|
+
).join("|");
|
|
7074
|
+
useEffect(() => {
|
|
7075
|
+
if (!chats3.length || !arbi.isLoggedIn) return;
|
|
7076
|
+
const id = ++runId.current;
|
|
7077
|
+
void (async () => {
|
|
7078
|
+
const next = {};
|
|
7079
|
+
for (const chat of chats3) {
|
|
7080
|
+
const title = await arbi.chats.title(chat).catch(() => null);
|
|
7081
|
+
const last = chat.last_message?.deleted ? null : chat.last_message;
|
|
7082
|
+
let preview = null;
|
|
7083
|
+
if (last) {
|
|
7084
|
+
preview = await arbi.chats.decrypt(chat, last).then(chats.chatMessagePreview).catch(() => chats.ENCRYPTED_PREVIEW);
|
|
7085
|
+
}
|
|
7086
|
+
next[chat.external_id] = { title, preview };
|
|
7087
|
+
}
|
|
7088
|
+
if (id === runId.current) setSummaries(next);
|
|
7089
|
+
})();
|
|
7090
|
+
}, [key, arbi]);
|
|
7091
|
+
return summaries;
|
|
7092
|
+
}
|
|
7093
|
+
function useChatThread(chat) {
|
|
7094
|
+
const arbi = useArbi();
|
|
7095
|
+
const queryClient = useQueryClient();
|
|
7096
|
+
const chatExtId = chat?.external_id ?? "";
|
|
7097
|
+
const chatRef = useRef(chat);
|
|
7098
|
+
chatRef.current = chat;
|
|
7099
|
+
const query = useQuery({
|
|
7100
|
+
queryKey: arbiQueryKeys.chatThread(chatExtId),
|
|
7101
|
+
queryFn: () => arbi.chats.page(chatRef.current),
|
|
7102
|
+
enabled: !!chat && arbi.isLoggedIn,
|
|
7103
|
+
staleTime: Infinity
|
|
7104
|
+
});
|
|
7105
|
+
const [loadingOlder, setLoadingOlder] = useState(false);
|
|
7106
|
+
const loadOlder = useCallback(async () => {
|
|
7107
|
+
const key = arbiQueryKeys.chatThread(chatExtId);
|
|
7108
|
+
const current = queryClient.getQueryData(key);
|
|
7109
|
+
const oldest = current?.messages.find((m) => !m.optimistic);
|
|
7110
|
+
if (!chatRef.current || !current?.hasMore || !oldest) return;
|
|
7111
|
+
setLoadingOlder(true);
|
|
7112
|
+
try {
|
|
7113
|
+
const page = await arbi.chats.page(chatRef.current, { before: oldest.external_id });
|
|
7114
|
+
queryClient.setQueryData(
|
|
7115
|
+
key,
|
|
7116
|
+
(old) => old ? {
|
|
7117
|
+
hasMore: page.hasMore,
|
|
7118
|
+
messages: [
|
|
7119
|
+
...page.messages.filter(
|
|
7120
|
+
(m) => !old.messages.some((o) => o.external_id === m.external_id)
|
|
7121
|
+
),
|
|
7122
|
+
...old.messages
|
|
7123
|
+
]
|
|
7124
|
+
} : old
|
|
7125
|
+
);
|
|
7126
|
+
} finally {
|
|
7127
|
+
setLoadingOlder(false);
|
|
7128
|
+
}
|
|
7129
|
+
}, [arbi, queryClient, chatExtId]);
|
|
7130
|
+
return {
|
|
7131
|
+
messages: query.data?.messages ?? [],
|
|
7132
|
+
hasMore: query.data?.hasMore ?? false,
|
|
7133
|
+
isLoading: query.isLoading && !!chat,
|
|
7134
|
+
loadOlder,
|
|
7135
|
+
loadingOlder
|
|
7136
|
+
};
|
|
7137
|
+
}
|
|
7138
|
+
function useChatPost() {
|
|
7139
|
+
const arbi = useArbi();
|
|
7140
|
+
const queryClient = useQueryClient();
|
|
7141
|
+
return useCallback(
|
|
7142
|
+
async (target, post) => {
|
|
7143
|
+
const me = myChatId(arbi);
|
|
7144
|
+
if (!me) throw new Error("No active session");
|
|
7145
|
+
let chat = target.chat;
|
|
7146
|
+
if (!chat) {
|
|
7147
|
+
if (!target.peerExtId) throw new Error("Could not resolve the conversation");
|
|
7148
|
+
chat = await arbi.chats.openDirect(target.peerExtId);
|
|
7149
|
+
upsertChat(queryClient, chat);
|
|
7150
|
+
queryClient.setQueryData(
|
|
7151
|
+
arbiQueryKeys.chatThread(chat.external_id),
|
|
7152
|
+
(old) => old ?? { messages: [], hasMore: false }
|
|
7153
|
+
);
|
|
7154
|
+
}
|
|
7155
|
+
const files = post.files ?? [];
|
|
7156
|
+
const optimisticId = `optimistic-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;
|
|
7157
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
7158
|
+
const optimistic = {
|
|
7159
|
+
external_id: optimisticId,
|
|
7160
|
+
chat_ext_id: chat.external_id,
|
|
7161
|
+
sender_ext_id: me,
|
|
7162
|
+
kind: "text",
|
|
7163
|
+
content: post.text,
|
|
7164
|
+
key_version: chat.key_version,
|
|
7165
|
+
deleted: false,
|
|
7166
|
+
context_only: !!post.contextOnly,
|
|
7167
|
+
workspace_ext_id: post.workspaceExtId ?? null,
|
|
7168
|
+
created_at: now,
|
|
7169
|
+
updated_at: now,
|
|
7170
|
+
optimistic: true
|
|
7171
|
+
};
|
|
7172
|
+
appendToThread(queryClient, chat.external_id, optimistic);
|
|
7173
|
+
try {
|
|
7174
|
+
let attachments = [];
|
|
7175
|
+
if (files.length) {
|
|
7176
|
+
chats.checkChatAttachmentLimits(files);
|
|
7177
|
+
attachments = await arbi.chats.uploadAttachments(
|
|
7178
|
+
await Promise.all(
|
|
7179
|
+
files.map(async (file) => ({
|
|
7180
|
+
name: file.name,
|
|
7181
|
+
type: file.type,
|
|
7182
|
+
bytes: new Uint8Array(await file.arrayBuffer())
|
|
7183
|
+
}))
|
|
7184
|
+
)
|
|
7185
|
+
);
|
|
7186
|
+
}
|
|
7187
|
+
const message = await arbi.chats.send(chat, post.text, {
|
|
7188
|
+
attachments,
|
|
7189
|
+
...post.workspaceExtId ? { workspaceExtId: post.workspaceExtId } : {},
|
|
7190
|
+
contextOnly: !!post.contextOnly
|
|
7191
|
+
});
|
|
7192
|
+
appendToThread(queryClient, chat.external_id, message, optimisticId);
|
|
7193
|
+
upsertChat(queryClient, {
|
|
7194
|
+
...chat,
|
|
7195
|
+
last_message: message,
|
|
7196
|
+
last_message_at: message.created_at
|
|
7197
|
+
});
|
|
7198
|
+
return { chat, message };
|
|
7199
|
+
} catch (err) {
|
|
7200
|
+
dropFromThread(queryClient, chat.external_id, optimisticId);
|
|
7201
|
+
void queryClient.invalidateQueries({ queryKey: arbiQueryKeys.chatList() });
|
|
7202
|
+
throw err;
|
|
7203
|
+
}
|
|
7204
|
+
},
|
|
7205
|
+
[arbi, queryClient]
|
|
7206
|
+
);
|
|
7207
|
+
}
|
|
7208
|
+
function useDeleteChatMessage() {
|
|
7209
|
+
const arbi = useArbi();
|
|
7210
|
+
const queryClient = useQueryClient();
|
|
7211
|
+
return useCallback(
|
|
7212
|
+
(chatExtId, messageExtId) => deleteChatMessage(arbi, queryClient, chatExtId, messageExtId),
|
|
7213
|
+
[arbi, queryClient]
|
|
7214
|
+
);
|
|
7215
|
+
}
|
|
7216
|
+
function useMarkChatRead() {
|
|
7217
|
+
const arbi = useArbi();
|
|
7218
|
+
const queryClient = useQueryClient();
|
|
7219
|
+
return useCallback(
|
|
7220
|
+
(chat, messageExtId) => {
|
|
7221
|
+
upsertChat(queryClient, { ...chat, unread_count: 0 });
|
|
7222
|
+
return arbi.chats.markRead(chat.external_id, messageExtId).then(
|
|
7223
|
+
() => void 0,
|
|
7224
|
+
() => void 0
|
|
7225
|
+
);
|
|
7226
|
+
},
|
|
7227
|
+
[arbi, queryClient]
|
|
7228
|
+
);
|
|
7229
|
+
}
|
|
7230
|
+
function useCreateGroupChat() {
|
|
7231
|
+
const arbi = useArbi();
|
|
7232
|
+
const queryClient = useQueryClient();
|
|
7233
|
+
return useMutation({
|
|
7234
|
+
mutationFn: (params) => arbi.chats.createGroup(params),
|
|
7235
|
+
onSuccess: (chat) => upsertChat(queryClient, chat)
|
|
7236
|
+
});
|
|
7237
|
+
}
|
|
7238
|
+
function useRenameChat() {
|
|
7239
|
+
const arbi = useArbi();
|
|
7240
|
+
const queryClient = useQueryClient();
|
|
7241
|
+
return useMutation({
|
|
7242
|
+
mutationFn: (vars) => arbi.chats.rename(vars.chat, vars.title),
|
|
7243
|
+
onSuccess: (chat) => upsertChat(queryClient, chat)
|
|
7244
|
+
});
|
|
7245
|
+
}
|
|
7246
|
+
function useAddChatMembers() {
|
|
7247
|
+
const arbi = useArbi();
|
|
7248
|
+
const queryClient = useQueryClient();
|
|
7249
|
+
return useMutation({
|
|
7250
|
+
mutationFn: (vars) => arbi.chats.addMembers(vars.chat, vars.members, { callKey: vars.callKey }),
|
|
7251
|
+
onSuccess: (chat) => upsertChat(queryClient, chat)
|
|
7252
|
+
});
|
|
7253
|
+
}
|
|
7254
|
+
function useRemoveChatMember() {
|
|
7255
|
+
const arbi = useArbi();
|
|
7256
|
+
const queryClient = useQueryClient();
|
|
7257
|
+
return useMutation({
|
|
7258
|
+
mutationFn: (vars) => arbi.chats.removeMember(vars.chat, vars.userExtId),
|
|
7259
|
+
onSuccess: (_data, vars) => {
|
|
7260
|
+
if (vars.userExtId === myChatId(arbi)) removeChat(queryClient, vars.chat.external_id);
|
|
7261
|
+
else return queryClient.invalidateQueries({ queryKey: arbiQueryKeys.chatList() });
|
|
7262
|
+
}
|
|
7263
|
+
});
|
|
7264
|
+
}
|
|
7265
|
+
|
|
7266
|
+
// src/directmessages/useDirectMessages.ts
|
|
7267
|
+
function mergeContacts(threads, contacts) {
|
|
7268
|
+
const byPeer = /* @__PURE__ */ new Map();
|
|
7269
|
+
for (const t of threads) byPeer.set(t.peer.external_id, t);
|
|
7270
|
+
for (const c of contacts) {
|
|
7271
|
+
const peer = c.user;
|
|
7272
|
+
if (!peer?.external_id || byPeer.has(peer.external_id)) continue;
|
|
7273
|
+
byPeer.set(peer.external_id, { peer, messages: [], unreadCount: 0, isContactOnly: true });
|
|
7274
|
+
}
|
|
7275
|
+
return [...byPeer.values()].sort((a, b) => {
|
|
7276
|
+
const at = a.lastMessage?.createdAt;
|
|
7277
|
+
const bt = b.lastMessage?.createdAt;
|
|
7278
|
+
if (at && bt) return bt.localeCompare(at);
|
|
7279
|
+
if (at) return -1;
|
|
7280
|
+
if (bt) return 1;
|
|
7281
|
+
return userDisplayName(a.peer).localeCompare(userDisplayName(b.peer));
|
|
7282
|
+
});
|
|
7283
|
+
}
|
|
7284
|
+
function toConversation(chat, thread, myExtId) {
|
|
7285
|
+
const peerMember = chat.members.find((m) => m.user.external_id !== myExtId);
|
|
7286
|
+
if (!peerMember) return null;
|
|
7287
|
+
const meMember = chat.members.find((m) => m.user.external_id === myExtId);
|
|
7288
|
+
const peer = peerMember.user;
|
|
7289
|
+
const userById = new Map(chat.members.map((m) => [m.user.external_id, m.user]));
|
|
7290
|
+
const messages = (thread?.messages ?? []).filter((m) => m.kind === "text" && !m.context_only).map((m) => {
|
|
7291
|
+
const isMine = m.sender_ext_id === myExtId;
|
|
7292
|
+
const sender = userById.get(m.sender_ext_id ?? "") ?? { external_id: m.sender_ext_id ?? "usr-unknown" };
|
|
7293
|
+
return {
|
|
7294
|
+
externalId: m.external_id,
|
|
7295
|
+
// A tombstone (deleted) has no content: it renders as "Message deleted".
|
|
7296
|
+
body: m.deleted ? "" : m.content ?? "",
|
|
7297
|
+
createdAt: m.created_at,
|
|
7298
|
+
isMine,
|
|
7299
|
+
// Mine: has the peer read it? Theirs: have I? (Never for a send still in flight.)
|
|
7300
|
+
read: !m.optimistic && chats.hasRead(isMine ? peerMember : meMember, m),
|
|
7301
|
+
sender,
|
|
7302
|
+
recipient: isMine ? peer : meMember?.user,
|
|
7303
|
+
chatExtId: chat.external_id,
|
|
7304
|
+
...m.deleted ? { deleted: true } : {}
|
|
7305
|
+
};
|
|
7306
|
+
});
|
|
7307
|
+
messages.sort((a, b) => a.createdAt.localeCompare(b.createdAt));
|
|
7308
|
+
if (messages.length === 0) return null;
|
|
7309
|
+
const shown = messages.filter((m) => !m.deleted);
|
|
7310
|
+
return {
|
|
7311
|
+
peer,
|
|
7312
|
+
chatExtId: chat.external_id,
|
|
7313
|
+
messages,
|
|
7314
|
+
lastMessage: shown[shown.length - 1],
|
|
7315
|
+
unreadCount: chat.unread_count ?? 0
|
|
7316
|
+
};
|
|
7317
|
+
}
|
|
7318
|
+
function combineThreads(results) {
|
|
7319
|
+
return {
|
|
7320
|
+
data: results.map((r) => r.data),
|
|
7321
|
+
error: results.find((r) => r.isError)?.error ?? null
|
|
7322
|
+
};
|
|
7323
|
+
}
|
|
7324
|
+
function directPeerId(chat, myExtId) {
|
|
7325
|
+
return chat.members.find((m) => m.user.external_id !== myExtId)?.user.external_id ?? myExtId;
|
|
7326
|
+
}
|
|
7327
|
+
function useDirectMessages(options) {
|
|
7328
|
+
const arbi = useArbi();
|
|
7329
|
+
const queryClient = useQueryClient();
|
|
7330
|
+
const enabled = (options?.enabled ?? true) && arbi.isLoggedIn;
|
|
7331
|
+
useChatLiveUpdates();
|
|
7332
|
+
const chatsQuery = useChats({ enabled });
|
|
7333
|
+
const direct = useMemo(
|
|
7334
|
+
() => (chatsQuery.data ?? []).filter((c) => c.kind === "direct"),
|
|
7335
|
+
[chatsQuery.data]
|
|
7336
|
+
);
|
|
7337
|
+
const threads = useQueries({
|
|
7338
|
+
queries: direct.map((chat) => ({
|
|
7339
|
+
queryKey: arbiQueryKeys.chatThread(chat.external_id),
|
|
7340
|
+
queryFn: () => arbi.chats.page(chat),
|
|
7341
|
+
enabled,
|
|
7342
|
+
staleTime: Infinity
|
|
7343
|
+
})),
|
|
7344
|
+
combine: combineThreads
|
|
7345
|
+
});
|
|
7346
|
+
const contactsQuery = useQuery({
|
|
7347
|
+
queryKey: arbiQueryKeys.contacts(),
|
|
7348
|
+
queryFn: () => arbi.contacts.list(),
|
|
7349
|
+
enabled
|
|
7350
|
+
});
|
|
7351
|
+
const myExtId = myChatId(arbi);
|
|
7352
|
+
const conversations = useMemo(() => {
|
|
7353
|
+
const rows = direct.map((chat, i) => toConversation(chat, threads.data[i], myExtId)).filter((c) => c !== null);
|
|
7354
|
+
return mergeContacts(rows, contactsQuery.data ?? []);
|
|
7355
|
+
}, [direct, threads.data, contactsQuery.data, myExtId]);
|
|
7356
|
+
const post = useChatPost();
|
|
7357
|
+
const markChatRead = useMarkChatRead();
|
|
7358
|
+
const [sending, setSending] = useState(0);
|
|
7359
|
+
const [sendError, setSendError] = useState(null);
|
|
7360
|
+
const sendToPeer = useCallback(
|
|
7361
|
+
async (peerExtId, text) => {
|
|
7362
|
+
setSending((n) => n + 1);
|
|
7363
|
+
setSendError(null);
|
|
7364
|
+
try {
|
|
7365
|
+
const chat = cachedChats(queryClient).find(
|
|
7366
|
+
(c) => c.kind === "direct" && directPeerId(c, myExtId) === peerExtId
|
|
7367
|
+
) ?? null;
|
|
7368
|
+
return (await post({ chat, peerExtId }, { text })).message;
|
|
7369
|
+
} catch (err) {
|
|
7370
|
+
setSendError(err instanceof Error ? err : new Error(String(err)));
|
|
7371
|
+
throw err;
|
|
7372
|
+
} finally {
|
|
7373
|
+
setSending((n) => n - 1);
|
|
7374
|
+
}
|
|
7375
|
+
},
|
|
7376
|
+
[post, queryClient, myExtId]
|
|
7377
|
+
);
|
|
7378
|
+
return {
|
|
7379
|
+
conversations,
|
|
7380
|
+
myExtId,
|
|
7381
|
+
isLoading: (chatsQuery.isLoading || contactsQuery.isLoading) && enabled,
|
|
7382
|
+
isError: chatsQuery.isError || threads.error !== null,
|
|
7383
|
+
error: chatsQuery.error ?? threads.error,
|
|
7384
|
+
refetch: () => void queryClient.invalidateQueries({ queryKey: arbiQueryKeys.chats() }),
|
|
7385
|
+
sendMessage: (recipientExtId, _recipientPublicKey, text) => sendToPeer(recipientExtId, text),
|
|
7386
|
+
sendMessageTo: async (recipient, text) => {
|
|
7387
|
+
if (!recipient.includes("@")) return sendToPeer(recipient, text);
|
|
7388
|
+
const resolved = await arbi.dm.resolveRecipient(recipient).catch(() => null);
|
|
7389
|
+
if (!resolved) {
|
|
7390
|
+
const err = new Error(
|
|
7391
|
+
`Could not resolve recipient "${recipient}" (not a known contact, agent, or workspace member)`
|
|
7392
|
+
);
|
|
7393
|
+
setSendError(err);
|
|
7394
|
+
throw err;
|
|
7395
|
+
}
|
|
7396
|
+
return sendToPeer(resolved.extId, text);
|
|
7397
|
+
},
|
|
7398
|
+
isSending: sending > 0,
|
|
7399
|
+
sendError,
|
|
7400
|
+
markRead: (chatExtId, messageExtId) => {
|
|
7401
|
+
const chat = (chatsQuery.data ?? []).find((c) => c.external_id === chatExtId);
|
|
7402
|
+
return chat ? markChatRead(chat, messageExtId) : arbi.chats.markRead(chatExtId, messageExtId);
|
|
7403
|
+
}
|
|
7404
|
+
};
|
|
7405
|
+
}
|
|
7406
|
+
function DmAvatar({ user, className, size = "lg" }) {
|
|
7407
|
+
const presence = useArbiWsStore((s) => s.presence[user.external_id]);
|
|
7408
|
+
const displayStatus = presence === void 0 ? void 0 : presence === "online" ? "connected" : "disconnected";
|
|
7409
|
+
return /* @__PURE__ */ jsx(
|
|
6834
7410
|
UserEntity,
|
|
6835
7411
|
{
|
|
6836
7412
|
variant: "icon",
|
|
@@ -7899,103 +8475,6 @@ function CommandPaletteProvider({
|
|
|
7899
8475
|
] });
|
|
7900
8476
|
}
|
|
7901
8477
|
|
|
7902
|
-
// src/documents/document-fields.ts
|
|
7903
|
-
var ADDABLE_STATUSES = /* @__PURE__ */ new Set(["completed", "empty", "low-content"]);
|
|
7904
|
-
var isDocumentAddableToConversation = (document2) => {
|
|
7905
|
-
if (!document2) return false;
|
|
7906
|
-
if (!document2.status) return true;
|
|
7907
|
-
return ADDABLE_STATUSES.has(document2.status.toLowerCase());
|
|
7908
|
-
};
|
|
7909
|
-
var getDocumentDate = (document2) => {
|
|
7910
|
-
if (!document2) return void 0;
|
|
7911
|
-
return document2.doc_metadata?.doc_date;
|
|
7912
|
-
};
|
|
7913
|
-
var formatDocDate = (value) => {
|
|
7914
|
-
if (!value) return "";
|
|
7915
|
-
if (value.includes("T")) {
|
|
7916
|
-
const d = new Date(value);
|
|
7917
|
-
if (!Number.isNaN(d.getTime())) {
|
|
7918
|
-
const pad = (n) => String(n).padStart(2, "0");
|
|
7919
|
-
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
|
7920
|
-
}
|
|
7921
|
-
}
|
|
7922
|
-
return value;
|
|
7923
|
-
};
|
|
7924
|
-
var getDocumentNature = (document2) => {
|
|
7925
|
-
if (!document2) return void 0;
|
|
7926
|
-
return document2.doc_metadata?.doc_nature;
|
|
7927
|
-
};
|
|
7928
|
-
var getDocumentAuthor = (document2) => {
|
|
7929
|
-
if (!document2) return void 0;
|
|
7930
|
-
return document2.doc_metadata?.doc_author;
|
|
7931
|
-
};
|
|
7932
|
-
var getDocumentSubject = (document2) => {
|
|
7933
|
-
if (!document2) return void 0;
|
|
7934
|
-
return document2.doc_metadata?.doc_subject;
|
|
7935
|
-
};
|
|
7936
|
-
var DEFAULT_METADATA_TAGS = [
|
|
7937
|
-
{ name: "doc_date", label: "Date" },
|
|
7938
|
-
{ name: "doc_nature", label: "Type" },
|
|
7939
|
-
{ name: "doc_author", label: "Author" },
|
|
7940
|
-
{ name: "doc_subject", label: "Abstract" }
|
|
7941
|
-
];
|
|
7942
|
-
var canonicalFolderPath = (folder) => {
|
|
7943
|
-
if (!folder) return null;
|
|
7944
|
-
const segments = folder.split("/").map((segment) => segment.trim()).filter(Boolean);
|
|
7945
|
-
return segments.length > 0 ? segments.join("/") : null;
|
|
7946
|
-
};
|
|
7947
|
-
var buildFolderTree = (docs) => {
|
|
7948
|
-
const counts = /* @__PURE__ */ new Map();
|
|
7949
|
-
let unfiledCount = 0;
|
|
7950
|
-
for (const doc of docs) {
|
|
7951
|
-
const folder = canonicalFolderPath(doc.folder);
|
|
7952
|
-
if (!folder) {
|
|
7953
|
-
unfiledCount++;
|
|
7954
|
-
continue;
|
|
7955
|
-
}
|
|
7956
|
-
const parts = folder.split("/");
|
|
7957
|
-
for (let i = 1; i <= parts.length; i++) {
|
|
7958
|
-
const path = parts.slice(0, i).join("/");
|
|
7959
|
-
counts.set(path, (counts.get(path) ?? 0) + 1);
|
|
7960
|
-
}
|
|
7961
|
-
}
|
|
7962
|
-
const nodes = [...counts.keys()].sort((a, b) => a.localeCompare(b)).map((path) => ({
|
|
7963
|
-
path,
|
|
7964
|
-
label: path.split("/").pop() ?? path,
|
|
7965
|
-
depth: path.split("/").length - 1,
|
|
7966
|
-
count: counts.get(path) ?? 0
|
|
7967
|
-
}));
|
|
7968
|
-
return { nodes, unfiledCount };
|
|
7969
|
-
};
|
|
7970
|
-
var formatFolderLabel = (path) => {
|
|
7971
|
-
if (!path) return "";
|
|
7972
|
-
const parts = path.split("/");
|
|
7973
|
-
const name = parts[parts.length - 1] || path;
|
|
7974
|
-
const depth = parts.length - 1;
|
|
7975
|
-
if (depth === 0) return name;
|
|
7976
|
-
return "../".repeat(depth) + name;
|
|
7977
|
-
};
|
|
7978
|
-
var COLUMN_LABEL_FALLBACKS = {
|
|
7979
|
-
title: "Document Name",
|
|
7980
|
-
doc_nature: "Type",
|
|
7981
|
-
doc_author: "Author",
|
|
7982
|
-
doc_subject: "Abstract",
|
|
7983
|
-
doc_date: "Date",
|
|
7984
|
-
n_pages: "Pages",
|
|
7985
|
-
created_at: "Uploaded",
|
|
7986
|
-
updated_at: "Last modified",
|
|
7987
|
-
file_name: "File name",
|
|
7988
|
-
file_size: "Size",
|
|
7989
|
-
file_type: "File type",
|
|
7990
|
-
shared: "Shared",
|
|
7991
|
-
inConversation: "In chat",
|
|
7992
|
-
created_by: "By",
|
|
7993
|
-
sender: "From",
|
|
7994
|
-
all_tags: "Labels",
|
|
7995
|
-
doc_id: "DocID",
|
|
7996
|
-
related: "Related"
|
|
7997
|
-
};
|
|
7998
|
-
|
|
7999
8478
|
// src/documents/document-download.ts
|
|
8000
8479
|
function fallbackFileName(doc) {
|
|
8001
8480
|
if (doc.file_name) return doc.file_name;
|
|
@@ -8184,307 +8663,6 @@ function useDocumentThumbnails(visibleIds) {
|
|
|
8184
8663
|
}, [tasks, idsKey, fetchMissing]);
|
|
8185
8664
|
return thumbnails;
|
|
8186
8665
|
}
|
|
8187
|
-
|
|
8188
|
-
// src/session/store.ts
|
|
8189
|
-
var DEFAULT_DOCUMENT_VIEWER_STATE = {
|
|
8190
|
-
tab: "pdf",
|
|
8191
|
-
compareId: null,
|
|
8192
|
-
tabRequest: null,
|
|
8193
|
-
textScale: 1,
|
|
8194
|
-
phonePdfChosen: false
|
|
8195
|
-
};
|
|
8196
|
-
var EMPTY_SESSION_STATE = {
|
|
8197
|
-
workspaceId: null,
|
|
8198
|
-
conversationId: null,
|
|
8199
|
-
viewingDocument: null,
|
|
8200
|
-
documentViewer: DEFAULT_DOCUMENT_VIEWER_STATE,
|
|
8201
|
-
selectedDocumentIds: [],
|
|
8202
|
-
generating: {},
|
|
8203
|
-
paMode: false,
|
|
8204
|
-
conversationDocuments: {}
|
|
8205
|
-
};
|
|
8206
|
-
var selectViewingDocumentId = (state) => state.viewingDocument ? parseVersionRef(state.viewingDocument.id).docId : null;
|
|
8207
|
-
var selectIsGenerating = (conversationId) => (state) => !!conversationId && !!state.generating[conversationId]?.isGenerating;
|
|
8208
|
-
function nextViewingDocument(current, input) {
|
|
8209
|
-
if (!input) return null;
|
|
8210
|
-
const same = current?.id === input.id;
|
|
8211
|
-
return {
|
|
8212
|
-
id: input.id,
|
|
8213
|
-
page: input.page !== void 0 ? input.page : same ? current?.page ?? null : null,
|
|
8214
|
-
passageId: input.passageId !== void 0 ? input.passageId : current?.passageId ?? null
|
|
8215
|
-
};
|
|
8216
|
-
}
|
|
8217
|
-
function createArbiSessionStore(initial = {}) {
|
|
8218
|
-
let state = { ...EMPTY_SESSION_STATE, ...initial };
|
|
8219
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
8220
|
-
const update = (patch) => {
|
|
8221
|
-
state = { ...state, ...patch };
|
|
8222
|
-
listeners.forEach((listener) => listener());
|
|
8223
|
-
};
|
|
8224
|
-
return {
|
|
8225
|
-
getState: () => state,
|
|
8226
|
-
subscribe: (listener) => {
|
|
8227
|
-
listeners.add(listener);
|
|
8228
|
-
return () => listeners.delete(listener);
|
|
8229
|
-
},
|
|
8230
|
-
setWorkspaceId: (workspaceId) => {
|
|
8231
|
-
if (state.workspaceId !== workspaceId) update({ workspaceId });
|
|
8232
|
-
},
|
|
8233
|
-
setConversationId: (conversationId) => {
|
|
8234
|
-
if (state.conversationId !== conversationId) update({ conversationId });
|
|
8235
|
-
},
|
|
8236
|
-
setViewingDocument: (input) => update({ viewingDocument: nextViewingDocument(state.viewingDocument, input) }),
|
|
8237
|
-
setDocumentViewer: (change) => {
|
|
8238
|
-
const next = { ...state.documentViewer, ...change };
|
|
8239
|
-
const keys = Object.keys(change);
|
|
8240
|
-
if (keys.some((key) => next[key] !== state.documentViewer[key]))
|
|
8241
|
-
update({ documentViewer: next });
|
|
8242
|
-
},
|
|
8243
|
-
setSelectedDocumentIds: (ids) => update({ selectedDocumentIds: ids }),
|
|
8244
|
-
setConversationGenerating: (conversationId, isGenerating) => {
|
|
8245
|
-
const current = state.generating[conversationId];
|
|
8246
|
-
update({
|
|
8247
|
-
generating: {
|
|
8248
|
-
...state.generating,
|
|
8249
|
-
[conversationId]: {
|
|
8250
|
-
isGenerating,
|
|
8251
|
-
error: isGenerating ? null : current?.error ?? null,
|
|
8252
|
-
startTime: isGenerating ? Date.now() : null
|
|
8253
|
-
}
|
|
8254
|
-
}
|
|
8255
|
-
});
|
|
8256
|
-
},
|
|
8257
|
-
setPaMode: (paMode) => {
|
|
8258
|
-
if (state.paMode !== paMode) update({ paMode });
|
|
8259
|
-
},
|
|
8260
|
-
setConversationDocuments: (conversationId, documents2) => update({
|
|
8261
|
-
conversationDocuments: { ...state.conversationDocuments, [conversationId]: documents2 }
|
|
8262
|
-
})
|
|
8263
|
-
};
|
|
8264
|
-
}
|
|
8265
|
-
var ArbiSessionStoreContext = createContext(null);
|
|
8266
|
-
var moduleDefault = null;
|
|
8267
|
-
var defaultStore = () => moduleDefault ??= createArbiSessionStore();
|
|
8268
|
-
function ArbiSessionStateProvider({
|
|
8269
|
-
store,
|
|
8270
|
-
children
|
|
8271
|
-
}) {
|
|
8272
|
-
const enclosing = useContext(ArbiSessionStoreContext);
|
|
8273
|
-
const [own] = useState(createArbiSessionStore);
|
|
8274
|
-
return /* @__PURE__ */ jsx(ArbiSessionStoreContext.Provider, { value: store ?? enclosing ?? own, children });
|
|
8275
|
-
}
|
|
8276
|
-
function useArbiSessionStore() {
|
|
8277
|
-
return useContext(ArbiSessionStoreContext) ?? defaultStore();
|
|
8278
|
-
}
|
|
8279
|
-
function useArbiSessionState(selector) {
|
|
8280
|
-
const store = useArbiSessionStore();
|
|
8281
|
-
const select = () => selector(store.getState());
|
|
8282
|
-
return useSyncExternalStore(store.subscribe, select, select);
|
|
8283
|
-
}
|
|
8284
|
-
ModuleRegistry.registerModules([AllCommunityModule]);
|
|
8285
|
-
function formatBytes(bytes) {
|
|
8286
|
-
if (bytes == null || Number.isNaN(bytes)) return "\u2014";
|
|
8287
|
-
if (bytes < 1024) return `${bytes} B`;
|
|
8288
|
-
const units = ["KB", "MB", "GB", "TB"];
|
|
8289
|
-
let value = bytes / 1024;
|
|
8290
|
-
let i = 0;
|
|
8291
|
-
while (value >= 1024 && i < units.length - 1) {
|
|
8292
|
-
value /= 1024;
|
|
8293
|
-
i++;
|
|
8294
|
-
}
|
|
8295
|
-
return `${value.toFixed(value >= 10 || i === 0 ? 0 : 1)} ${units[i]}`;
|
|
8296
|
-
}
|
|
8297
|
-
var STATUS_VARIANTS = {
|
|
8298
|
-
completed: "default",
|
|
8299
|
-
empty: "secondary",
|
|
8300
|
-
"low-content": "secondary",
|
|
8301
|
-
processing: "outline",
|
|
8302
|
-
queued: "outline",
|
|
8303
|
-
failed: "destructive",
|
|
8304
|
-
skipped: "destructive"
|
|
8305
|
-
};
|
|
8306
|
-
function DocumentTable({
|
|
8307
|
-
workspaceId,
|
|
8308
|
-
documents: documents2,
|
|
8309
|
-
onOpenDocument,
|
|
8310
|
-
openOnRowClick = true,
|
|
8311
|
-
selectedIds,
|
|
8312
|
-
onSelectionChange,
|
|
8313
|
-
height = 480,
|
|
8314
|
-
extraColumns,
|
|
8315
|
-
className
|
|
8316
|
-
}) {
|
|
8317
|
-
const query = useDocuments(workspaceId, { enabled: !documents2 });
|
|
8318
|
-
const rows = documents2 ?? query.data ?? [];
|
|
8319
|
-
const isLoading = !documents2 && query.isLoading;
|
|
8320
|
-
const tagsQuery = useTags(workspaceId);
|
|
8321
|
-
const tagNameById = React3.useMemo(() => {
|
|
8322
|
-
const map = /* @__PURE__ */ new Map();
|
|
8323
|
-
for (const t of tagsQuery.data ?? []) {
|
|
8324
|
-
if (t.external_id) map.set(t.external_id, t.name ?? t.external_id.slice(0, 8));
|
|
8325
|
-
}
|
|
8326
|
-
return map;
|
|
8327
|
-
}, [tagsQuery.data]);
|
|
8328
|
-
const session = useArbiSessionStore();
|
|
8329
|
-
const storeSelected = useArbiSessionState((s) => s.selectedDocumentIds);
|
|
8330
|
-
const storeSetSelected = session.setSelectedDocumentIds;
|
|
8331
|
-
const viewingDocId = useArbiSessionState(selectViewingDocumentId);
|
|
8332
|
-
const effectiveSelected = selectedIds ?? storeSelected;
|
|
8333
|
-
const emitSelection = onSelectionChange ?? storeSetSelected;
|
|
8334
|
-
const gridApiRef = React3.useRef(null);
|
|
8335
|
-
const openDocument = React3.useCallback(
|
|
8336
|
-
(id) => {
|
|
8337
|
-
session.setViewingDocument({ id });
|
|
8338
|
-
onOpenDocument?.(id);
|
|
8339
|
-
},
|
|
8340
|
-
[onOpenDocument, session]
|
|
8341
|
-
);
|
|
8342
|
-
const applySelection = React3.useCallback(() => {
|
|
8343
|
-
const api = gridApiRef.current;
|
|
8344
|
-
if (!api) return;
|
|
8345
|
-
const wanted = new Set(effectiveSelected);
|
|
8346
|
-
api.forEachNode((node) => {
|
|
8347
|
-
const id = node.data?.external_id;
|
|
8348
|
-
const shouldSelect = !!id && wanted.has(id);
|
|
8349
|
-
if (node.isSelected() !== shouldSelect) node.setSelected(shouldSelect);
|
|
8350
|
-
});
|
|
8351
|
-
}, [effectiveSelected]);
|
|
8352
|
-
React3.useEffect(() => {
|
|
8353
|
-
applySelection();
|
|
8354
|
-
}, [applySelection]);
|
|
8355
|
-
const columnDefs = React3.useMemo(
|
|
8356
|
-
() => [
|
|
8357
|
-
{
|
|
8358
|
-
colId: "select",
|
|
8359
|
-
headerName: "",
|
|
8360
|
-
width: 44,
|
|
8361
|
-
pinned: "left",
|
|
8362
|
-
checkboxSelection: true,
|
|
8363
|
-
headerCheckboxSelection: true,
|
|
8364
|
-
sortable: false,
|
|
8365
|
-
filter: false,
|
|
8366
|
-
resizable: false,
|
|
8367
|
-
suppressMovable: true
|
|
8368
|
-
},
|
|
8369
|
-
{
|
|
8370
|
-
colId: "title",
|
|
8371
|
-
headerName: "Document Name",
|
|
8372
|
-
flex: 3,
|
|
8373
|
-
minWidth: 240,
|
|
8374
|
-
sortable: true,
|
|
8375
|
-
valueGetter: (p) => p.data?.doc_metadata?.title || p.data?.file_name || "",
|
|
8376
|
-
cellRenderer: (p) => {
|
|
8377
|
-
const doc = p.data;
|
|
8378
|
-
if (!doc) return null;
|
|
8379
|
-
return /* @__PURE__ */ jsx(
|
|
8380
|
-
DocumentEntity,
|
|
8381
|
-
{
|
|
8382
|
-
doc,
|
|
8383
|
-
size: "base",
|
|
8384
|
-
fullWidth: true,
|
|
8385
|
-
viewing: viewingDocId === doc.external_id,
|
|
8386
|
-
onClick: (e) => {
|
|
8387
|
-
e.stopPropagation();
|
|
8388
|
-
if (doc.external_id) openDocument(doc.external_id);
|
|
8389
|
-
}
|
|
8390
|
-
}
|
|
8391
|
-
);
|
|
8392
|
-
}
|
|
8393
|
-
},
|
|
8394
|
-
{
|
|
8395
|
-
colId: "status",
|
|
8396
|
-
headerName: "Status",
|
|
8397
|
-
width: 140,
|
|
8398
|
-
sortable: true,
|
|
8399
|
-
field: "status",
|
|
8400
|
-
cellRenderer: (p) => {
|
|
8401
|
-
const status = p.data?.status;
|
|
8402
|
-
if (!status) return null;
|
|
8403
|
-
return /* @__PURE__ */ jsx(Badge, { variant: STATUS_VARIANTS[status.toLowerCase()] ?? "secondary", children: status });
|
|
8404
|
-
}
|
|
8405
|
-
},
|
|
8406
|
-
{
|
|
8407
|
-
colId: "all_tags",
|
|
8408
|
-
headerName: "Labels",
|
|
8409
|
-
flex: 1,
|
|
8410
|
-
minWidth: 160,
|
|
8411
|
-
sortable: false,
|
|
8412
|
-
filter: false,
|
|
8413
|
-
cellRenderer: (p) => {
|
|
8414
|
-
const doctags = p.data?.doctags ?? [];
|
|
8415
|
-
if (doctags.length === 0) return null;
|
|
8416
|
-
return /* @__PURE__ */ jsx("div", { className: "flex flex-wrap items-center gap-1 py-1", children: doctags.map((dt) => /* @__PURE__ */ jsx(
|
|
8417
|
-
TagEntity,
|
|
8418
|
-
{
|
|
8419
|
-
size: "sm",
|
|
8420
|
-
tag: {
|
|
8421
|
-
external_id: dt.tag_ext_id,
|
|
8422
|
-
name: tagNameById.get(dt.tag_ext_id) ?? dt.tag_ext_id.slice(0, 8)
|
|
8423
|
-
}
|
|
8424
|
-
},
|
|
8425
|
-
dt.tag_ext_id
|
|
8426
|
-
)) });
|
|
8427
|
-
}
|
|
8428
|
-
},
|
|
8429
|
-
{
|
|
8430
|
-
colId: "file_size",
|
|
8431
|
-
headerName: "Size",
|
|
8432
|
-
width: 110,
|
|
8433
|
-
sortable: true,
|
|
8434
|
-
field: "file_size",
|
|
8435
|
-
valueFormatter: (p) => formatBytes(p.value)
|
|
8436
|
-
},
|
|
8437
|
-
{
|
|
8438
|
-
colId: "folder",
|
|
8439
|
-
headerName: "Folder",
|
|
8440
|
-
flex: 1,
|
|
8441
|
-
minWidth: 140,
|
|
8442
|
-
sortable: true,
|
|
8443
|
-
field: "folder",
|
|
8444
|
-
valueFormatter: (p) => p.value || "\u2014"
|
|
8445
|
-
},
|
|
8446
|
-
...extraColumns ?? []
|
|
8447
|
-
],
|
|
8448
|
-
[openDocument, viewingDocId, tagNameById, extraColumns]
|
|
8449
|
-
);
|
|
8450
|
-
const handleGridReady = (e) => {
|
|
8451
|
-
gridApiRef.current = e.api;
|
|
8452
|
-
applySelection();
|
|
8453
|
-
};
|
|
8454
|
-
const handleSelectionChanged = (e) => {
|
|
8455
|
-
const ids = e.api.getSelectedRows().map((r) => r.external_id).filter((id) => !!id);
|
|
8456
|
-
emitSelection(ids);
|
|
8457
|
-
};
|
|
8458
|
-
const handleRowClicked = (e) => {
|
|
8459
|
-
if (!openOnRowClick) return;
|
|
8460
|
-
const id = e.data?.external_id;
|
|
8461
|
-
if (id) openDocument(id);
|
|
8462
|
-
};
|
|
8463
|
-
const getRowId = React3.useCallback((params) => params.data.external_id, []);
|
|
8464
|
-
const autoHeight = height === "auto";
|
|
8465
|
-
const style = autoHeight ? {} : { height: typeof height === "number" ? `${height}px` : height, width: "100%" };
|
|
8466
|
-
if (isLoading) {
|
|
8467
|
-
return /* @__PURE__ */ jsx("div", { className, style, children: /* @__PURE__ */ jsx("div", { className: "flex h-full w-full items-center justify-center p-8 text-sm text-muted-foreground", children: "Loading documents\u2026" }) });
|
|
8468
|
-
}
|
|
8469
|
-
if (rows.length === 0) {
|
|
8470
|
-
return /* @__PURE__ */ jsx("div", { className, style, children: /* @__PURE__ */ jsx("div", { className: "flex h-full w-full items-center justify-center p-8 text-sm text-muted-foreground", children: "No documents" }) });
|
|
8471
|
-
}
|
|
8472
|
-
return /* @__PURE__ */ jsx("div", { className, style, children: /* @__PURE__ */ jsx(
|
|
8473
|
-
AgGridReact,
|
|
8474
|
-
{
|
|
8475
|
-
columnDefs,
|
|
8476
|
-
rowData: rows,
|
|
8477
|
-
getRowId,
|
|
8478
|
-
rowSelection: "multiple",
|
|
8479
|
-
suppressRowClickSelection: true,
|
|
8480
|
-
domLayout: autoHeight ? "autoHeight" : "normal",
|
|
8481
|
-
rowHeight: 44,
|
|
8482
|
-
onGridReady: handleGridReady,
|
|
8483
|
-
onSelectionChanged: handleSelectionChanged,
|
|
8484
|
-
onRowClicked: handleRowClicked
|
|
8485
|
-
}
|
|
8486
|
-
) });
|
|
8487
|
-
}
|
|
8488
8666
|
function DocumentCardMenu({
|
|
8489
8667
|
docId,
|
|
8490
8668
|
fileName,
|
|
@@ -8562,146 +8740,6 @@ function DocumentCardMenu({
|
|
|
8562
8740
|
] })
|
|
8563
8741
|
] });
|
|
8564
8742
|
}
|
|
8565
|
-
function docTitle(doc) {
|
|
8566
|
-
return doc.doc_metadata?.title || doc.file_name || "Untitled";
|
|
8567
|
-
}
|
|
8568
|
-
function TileTooltip({ title, labels }) {
|
|
8569
|
-
return /* @__PURE__ */ jsxs("div", { className: "max-w-xs space-y-2", children: [
|
|
8570
|
-
/* @__PURE__ */ jsx("div", { className: "break-words text-xs font-semibold leading-snug", children: title }),
|
|
8571
|
-
labels.length > 0 && /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-1 border-t border-border/60 pt-1.5", children: labels.map((label) => /* @__PURE__ */ jsx(
|
|
8572
|
-
"span",
|
|
8573
|
-
{
|
|
8574
|
-
className: "rounded bg-muted px-1.5 py-0.5 text-xs font-medium text-foreground/80",
|
|
8575
|
-
children: label
|
|
8576
|
-
},
|
|
8577
|
-
label
|
|
8578
|
-
)) })
|
|
8579
|
-
] });
|
|
8580
|
-
}
|
|
8581
|
-
function DocumentGallery({
|
|
8582
|
-
workspaceId,
|
|
8583
|
-
documents: documents2,
|
|
8584
|
-
onOpenDocument,
|
|
8585
|
-
selectedIds,
|
|
8586
|
-
onSelectionChange,
|
|
8587
|
-
minTileWidth = 148,
|
|
8588
|
-
className
|
|
8589
|
-
}) {
|
|
8590
|
-
const query = useDocuments(workspaceId, { enabled: !documents2 });
|
|
8591
|
-
const rows = documents2 ?? query.data ?? [];
|
|
8592
|
-
const isLoading = !documents2 && query.isLoading;
|
|
8593
|
-
const tagsQuery = useTags(workspaceId);
|
|
8594
|
-
const tagNameById = React3.useMemo(() => {
|
|
8595
|
-
const map = /* @__PURE__ */ new Map();
|
|
8596
|
-
for (const t of tagsQuery.data ?? []) {
|
|
8597
|
-
if (t.external_id) map.set(t.external_id, t.name ?? t.external_id.slice(0, 8));
|
|
8598
|
-
}
|
|
8599
|
-
return map;
|
|
8600
|
-
}, [tagsQuery.data]);
|
|
8601
|
-
const docIds = React3.useMemo(
|
|
8602
|
-
() => rows.map((d) => d.external_id).filter((id) => !!id),
|
|
8603
|
-
[rows]
|
|
8604
|
-
);
|
|
8605
|
-
const thumbsQuery = useThumbnails(docIds);
|
|
8606
|
-
const thumbs = thumbsQuery.data ?? {};
|
|
8607
|
-
const session = useArbiSessionStore();
|
|
8608
|
-
const storeSelected = useArbiSessionState((s) => s.selectedDocumentIds);
|
|
8609
|
-
const storeSetSelected = session.setSelectedDocumentIds;
|
|
8610
|
-
const viewingDocId = useArbiSessionState(selectViewingDocumentId);
|
|
8611
|
-
const effectiveSelected = selectedIds ?? storeSelected;
|
|
8612
|
-
const emitSelection = onSelectionChange ?? storeSetSelected;
|
|
8613
|
-
const selectedSet = React3.useMemo(() => new Set(effectiveSelected), [effectiveSelected]);
|
|
8614
|
-
const toggleSelected = React3.useCallback(
|
|
8615
|
-
(id) => {
|
|
8616
|
-
const next = new Set(effectiveSelected);
|
|
8617
|
-
if (next.has(id)) next.delete(id);
|
|
8618
|
-
else next.add(id);
|
|
8619
|
-
emitSelection([...next]);
|
|
8620
|
-
},
|
|
8621
|
-
[effectiveSelected, emitSelection]
|
|
8622
|
-
);
|
|
8623
|
-
const openDocument = React3.useCallback(
|
|
8624
|
-
(id) => {
|
|
8625
|
-
session.setViewingDocument({ id });
|
|
8626
|
-
onOpenDocument?.(id);
|
|
8627
|
-
},
|
|
8628
|
-
[onOpenDocument, session]
|
|
8629
|
-
);
|
|
8630
|
-
const [renamingId, setRenamingId] = React3.useState(null);
|
|
8631
|
-
const update = useUpdateDocuments();
|
|
8632
|
-
const rename = (doc, title) => update.mutate(
|
|
8633
|
-
{
|
|
8634
|
-
documents: [{ external_id: doc.external_id, doc_metadata: { ...doc.doc_metadata, title } }]
|
|
8635
|
-
},
|
|
8636
|
-
{ onSettled: () => setRenamingId(null) }
|
|
8637
|
-
);
|
|
8638
|
-
if (isLoading) {
|
|
8639
|
-
return /* @__PURE__ */ jsx(
|
|
8640
|
-
"div",
|
|
8641
|
-
{
|
|
8642
|
-
className: cn(
|
|
8643
|
-
"flex items-center justify-center p-8 text-sm text-muted-foreground",
|
|
8644
|
-
className
|
|
8645
|
-
),
|
|
8646
|
-
children: "Loading documents\u2026"
|
|
8647
|
-
}
|
|
8648
|
-
);
|
|
8649
|
-
}
|
|
8650
|
-
if (rows.length === 0) {
|
|
8651
|
-
return /* @__PURE__ */ jsx(
|
|
8652
|
-
"div",
|
|
8653
|
-
{
|
|
8654
|
-
className: cn(
|
|
8655
|
-
"flex items-center justify-center p-8 text-sm text-muted-foreground",
|
|
8656
|
-
className
|
|
8657
|
-
),
|
|
8658
|
-
children: "No documents"
|
|
8659
|
-
}
|
|
8660
|
-
);
|
|
8661
|
-
}
|
|
8662
|
-
return /* @__PURE__ */ jsx(
|
|
8663
|
-
"div",
|
|
8664
|
-
{
|
|
8665
|
-
"data-testid": "document-gallery",
|
|
8666
|
-
className: cn("grid gap-3", className),
|
|
8667
|
-
style: { gridTemplateColumns: `repeat(auto-fill, minmax(${minTileWidth}px, 1fr))` },
|
|
8668
|
-
children: rows.map((doc) => {
|
|
8669
|
-
const id = doc.external_id;
|
|
8670
|
-
if (!id) return null;
|
|
8671
|
-
const title = docTitle(doc);
|
|
8672
|
-
const labels = (doc.doctags ?? []).map(
|
|
8673
|
-
(dt) => tagNameById.get(dt.tag_ext_id) ?? dt.tag_ext_id.slice(0, 8)
|
|
8674
|
-
);
|
|
8675
|
-
return /* @__PURE__ */ jsx("div", { "data-doc-id": id, "data-testid": "document-gallery-card", children: /* @__PURE__ */ jsx(
|
|
8676
|
-
DocumentCard,
|
|
8677
|
-
{
|
|
8678
|
-
doc,
|
|
8679
|
-
thumbnailUrl: thumbs[id],
|
|
8680
|
-
status: doc.status,
|
|
8681
|
-
selected: selectedSet.has(id),
|
|
8682
|
-
onToggleSelect: () => toggleSelected(id),
|
|
8683
|
-
viewing: viewingDocId === id,
|
|
8684
|
-
onOpen: () => openDocument(id),
|
|
8685
|
-
renaming: renamingId === id,
|
|
8686
|
-
onCommitRename: (newTitle) => rename(doc, newTitle),
|
|
8687
|
-
onCancelRename: () => setRenamingId(null),
|
|
8688
|
-
actions: /* @__PURE__ */ jsx(
|
|
8689
|
-
DocumentCardMenu,
|
|
8690
|
-
{
|
|
8691
|
-
docId: id,
|
|
8692
|
-
fileName: doc.file_name ?? title,
|
|
8693
|
-
onOpen: () => openDocument(id),
|
|
8694
|
-
onRename: () => setRenamingId(id),
|
|
8695
|
-
testId: `document-card-menu-${id}`
|
|
8696
|
-
}
|
|
8697
|
-
),
|
|
8698
|
-
tooltipContent: /* @__PURE__ */ jsx(TileTooltip, { title, labels })
|
|
8699
|
-
}
|
|
8700
|
-
) }, id);
|
|
8701
|
-
})
|
|
8702
|
-
}
|
|
8703
|
-
);
|
|
8704
|
-
}
|
|
8705
8743
|
function DocumentReview({
|
|
8706
8744
|
docId,
|
|
8707
8745
|
doc,
|
|
@@ -9759,7 +9797,132 @@ function useUploadFromUrls() {
|
|
|
9759
9797
|
[uploadUrls, extractZip]
|
|
9760
9798
|
);
|
|
9761
9799
|
}
|
|
9800
|
+
function getRelatedTotal(related) {
|
|
9801
|
+
return (related.parent ? 1 : 0) + related.children.length + related.madeFrom.length + related.copies.length + related.duplicates.length + related.similar.length;
|
|
9802
|
+
}
|
|
9803
|
+
function getRelatedLabels(related) {
|
|
9804
|
+
const parts = [];
|
|
9805
|
+
if (related.parent) parts.push("1 parent");
|
|
9806
|
+
if (related.children.length > 0) {
|
|
9807
|
+
const n = related.children.length;
|
|
9808
|
+
parts.push(`${n} ${n === 1 ? "attachment" : "attachments"}`);
|
|
9809
|
+
}
|
|
9810
|
+
if (related.madeFrom.length > 0) parts.push(`made from ${related.madeFrom.length}`);
|
|
9811
|
+
if (related.copies.length > 0) {
|
|
9812
|
+
const n = related.copies.length;
|
|
9813
|
+
parts.push(`${n} ${n === 1 ? "copy" : "copies"}`);
|
|
9814
|
+
}
|
|
9815
|
+
if (related.duplicates.length > 0) {
|
|
9816
|
+
const n = related.duplicates.length;
|
|
9817
|
+
parts.push(`${n} ${n === 1 ? "duplicate" : "duplicates"}`);
|
|
9818
|
+
}
|
|
9819
|
+
if (related.similar.length > 0) {
|
|
9820
|
+
const n = related.similar.length;
|
|
9821
|
+
parts.push(`${n} similar`);
|
|
9822
|
+
}
|
|
9823
|
+
return parts;
|
|
9824
|
+
}
|
|
9825
|
+
function useRelatedDocuments(documents2) {
|
|
9826
|
+
const { data: similarData } = useSimilarDocuments();
|
|
9827
|
+
const structuralKey = useMemo(() => {
|
|
9828
|
+
const parts = [];
|
|
9829
|
+
for (const doc of documents2) {
|
|
9830
|
+
parts.push(doc.external_id);
|
|
9831
|
+
parts.push(doc.parent_ext_id || "");
|
|
9832
|
+
parts.push(doc.content_hash || "");
|
|
9833
|
+
parts.push(String(doc.current_version ?? 1));
|
|
9834
|
+
for (const source of doc.derived_from ?? [])
|
|
9835
|
+
parts.push(source.doc_ext_id, source.role, String(source.version ?? ""));
|
|
9836
|
+
}
|
|
9837
|
+
return parts.join("|");
|
|
9838
|
+
}, [documents2]);
|
|
9839
|
+
const prevKeyRef = useRef(structuralKey);
|
|
9840
|
+
const prevMapRef = useRef(/* @__PURE__ */ new Map());
|
|
9841
|
+
const prevDocsRef = useRef(documents2);
|
|
9842
|
+
const prevSimilarRef = useRef(similarData);
|
|
9843
|
+
return useMemo(() => {
|
|
9844
|
+
if (prevKeyRef.current === structuralKey && prevSimilarRef.current === similarData && prevMapRef.current.size > 0 && prevDocsRef.current === documents2) {
|
|
9845
|
+
return prevMapRef.current;
|
|
9846
|
+
}
|
|
9847
|
+
prevKeyRef.current = structuralKey;
|
|
9848
|
+
prevDocsRef.current = documents2;
|
|
9849
|
+
prevSimilarRef.current = similarData;
|
|
9850
|
+
const map = /* @__PURE__ */ new Map();
|
|
9851
|
+
const getOrCreate = (docId) => {
|
|
9852
|
+
let entry = map.get(docId);
|
|
9853
|
+
if (!entry) {
|
|
9854
|
+
entry = { children: [], madeFrom: [], copies: [], roles: {}, duplicates: [], similar: [] };
|
|
9855
|
+
map.set(docId, entry);
|
|
9856
|
+
}
|
|
9857
|
+
return entry;
|
|
9858
|
+
};
|
|
9859
|
+
const docById = /* @__PURE__ */ new Map();
|
|
9860
|
+
for (const doc of documents2) {
|
|
9861
|
+
docById.set(doc.external_id, doc);
|
|
9862
|
+
}
|
|
9863
|
+
const byHash = /* @__PURE__ */ new Map();
|
|
9864
|
+
for (const doc of documents2) {
|
|
9865
|
+
if (doc.content_hash) {
|
|
9866
|
+
const list = byHash.get(doc.content_hash) || [];
|
|
9867
|
+
list.push(doc);
|
|
9868
|
+
byHash.set(doc.content_hash, list);
|
|
9869
|
+
}
|
|
9870
|
+
}
|
|
9871
|
+
for (const doc of documents2) {
|
|
9872
|
+
if (doc.parent_ext_id) {
|
|
9873
|
+
const parent = docById.get(doc.parent_ext_id);
|
|
9874
|
+
if (parent) {
|
|
9875
|
+
getOrCreate(doc.external_id).parent = parent;
|
|
9876
|
+
getOrCreate(parent.external_id).children.push(doc);
|
|
9877
|
+
}
|
|
9878
|
+
}
|
|
9879
|
+
}
|
|
9880
|
+
for (const doc of documents2) {
|
|
9881
|
+
for (const source of doc.derived_from ?? []) {
|
|
9882
|
+
const from = docById.get(source.doc_ext_id);
|
|
9883
|
+
if (!from) continue;
|
|
9884
|
+
const made = getOrCreate(doc.external_id);
|
|
9885
|
+
made.madeFrom.push(from);
|
|
9886
|
+
made.roles[from.external_id] = source.role;
|
|
9887
|
+
if (source.version && source.version !== (from.current_version ?? 1)) {
|
|
9888
|
+
made.versions = { ...made.versions, [from.external_id]: source.version };
|
|
9889
|
+
}
|
|
9890
|
+
const original = getOrCreate(from.external_id);
|
|
9891
|
+
original.copies.push(doc);
|
|
9892
|
+
original.roles[doc.external_id] = source.role;
|
|
9893
|
+
}
|
|
9894
|
+
}
|
|
9895
|
+
for (const [, docs] of byHash) {
|
|
9896
|
+
if (docs.length > 1) {
|
|
9897
|
+
for (const doc of docs) {
|
|
9898
|
+
getOrCreate(doc.external_id).duplicates = docs.filter(
|
|
9899
|
+
(d) => d.external_id !== doc.external_id
|
|
9900
|
+
);
|
|
9901
|
+
}
|
|
9902
|
+
}
|
|
9903
|
+
}
|
|
9904
|
+
if (similarData?.pairs) {
|
|
9905
|
+
for (const pair of similarData.pairs) {
|
|
9906
|
+
if (pair.similarity < SIMILARITY_THRESHOLD || pair.similarity >= 1) continue;
|
|
9907
|
+
const docA = docById.get(pair.doc_a.external_id);
|
|
9908
|
+
const docB = docById.get(pair.doc_b.external_id);
|
|
9909
|
+
if (docA && docB) {
|
|
9910
|
+
getOrCreate(docA.external_id).similar.push({
|
|
9911
|
+
doc: docB,
|
|
9912
|
+
similarity: pair.similarity
|
|
9913
|
+
});
|
|
9914
|
+
getOrCreate(docB.external_id).similar.push({
|
|
9915
|
+
doc: docA,
|
|
9916
|
+
similarity: pair.similarity
|
|
9917
|
+
});
|
|
9918
|
+
}
|
|
9919
|
+
}
|
|
9920
|
+
}
|
|
9921
|
+
prevMapRef.current = map;
|
|
9922
|
+
return map;
|
|
9923
|
+
}, [documents2, similarData, structuralKey]);
|
|
9924
|
+
}
|
|
9762
9925
|
|
|
9763
|
-
export { ALLOWED_PORTAL_ORIGINS,
|
|
9926
|
+
export { ALLOWED_PORTAL_ORIGINS, ActivityFeed, AiActionCard, AiAnswer, AppleIcon, ArbiBotIcon, ArbiHost2 as ArbiHost, ArbiWebSocketProvider, ArtifactCanvas, BOX_SEAT_REFUSED, BOX_SEAT_REFUSED_ACTION, BOX_SEAT_REFUSED_TITLE, ChatBubble, CitationRenderer, ClaudeIcon, CommandPalette, CommandPaletteProvider, ConversationList, DEFAULT_ASPECT_OPTIONS, DEFAULT_DOCUMENT_VIEWER_STATE, DEFAULT_PASSWORD_CHANGE_FORM_MESSAGES, DEFAULT_START_BY_EMAIL_LABELS, DateSeparator, DirectMessages, DmAvatar, DmComposer, DocQaPanel, DocSearch, DocumentCardMenu, DocumentReview, DraftTitleControls, EMPTY_SESSION_STATE, FileIcon, FireworksIcon, GeminiIcon, GitHubIcon, GoogleIcon, ImageCropModal, ImageCropper, LinkedInIcon, MAIL_DRAFT_REPLACED_EVENT, MAX_AVATAR_FILE_BYTES, MailOfflineUnavailableError, MessageArtifactCard, MessageBubble, MessageThread, OpenAIIcon, POLL_EVERY_MS, PhotoCapture, ProviderIcon, RUN_WINDOW_MS, SIGNATURE_NOTIFICATION_TYPES, SLOW_AFTER_MS, STILL_WORKING, StartByEmail, TypingIndicator, UPLOAD_ACCEPT, UPLOAD_MAX_FILE_SIZE, VideoCapture, VoiceNoteRecorder, WORK_NOTIFICATION_LABELS, accountPath, aliasTakenMessage, annotateThread, announceMailDraftReplaced, appendToThread, applyAgentDmStatus, applyChatEvent, applyChatMessage, applyChatRead, applyChatUpdated, applyOptimisticDocumentEdit, arbiAccountClient, arbiMailClient, archiveName, buildDocumentMetadataRows, cachedChat, cachedChats, calendarQueryKeys, callNotificationMeta, captureFrameAsBlob, connectOAuthCalendarAccount, connectorErrorStatus, connectorQueryKeys, connectorReturnTo, createArbiSessionStore, createMailClient, cropImage, dayKey, defaultMailAlias, deploymentUserMeta, describeActivity, describeServerNotification, documentActivityMeta, documentActivityPhrase, documentDisplayName, docxMentionMeta, downloadRecoveryFile, entitlementRefusal, extractZipFile, fallbackFileName, fileAttachment, filesFromDrop, forgetUploadedDocumentFolder, formatIdentityPrice, getNotificationTypeMeta, getOpenChat, getRelatedLabels, getRelatedTotal, getWorkspaceActionText, getWorkspaceKind, getWorkspaceSentPhrase, hasVideoTrack, identityStepFor, inputRequestTitle, invalidateCalendarEvents, invalidateCalendars, isAliasTakenError, isDeploymentAdmin, isDeploymentUserNotification, isOfflineReadableArbiQuery, isQueuedCalendarWrite, isReplayableArbiMutation, isRestorableArbiQueryOnline, isSignatureNotificationType, isWorkspaceNotificationType, isZipFile, mailDraftIdFromContent, mailJson, mailQueryKeys, mountDiditVerification, myChatId, nextAliasSuggestion, nextViewingDocument, notificationUserName, parseActivityContent, parseDeleteAccountBlockers, pickRecentWorkspaces, prepareUploadFiles, redlineStats, registerArbiMutationDefaults, removeChat, resetCalendarAccountSyncState, resolveActiveWorkspace, rollbackOptimisticDocumentEdit, safePortalUrl, selectIsGenerating, selectViewingDocumentId, setOpenChat, signatureNotificationPhrase, signatureRequestMeta, supportsHouseTemplates, textToArtifact, titleFromQuestion, toChatCitations, toNotificationPreferences, toProfileView, toRedlineMarkdown, toShellWorkspace, uploadFolderOf, uploadedDocumentFolder, upsertChat, useAccountClient, useActOnStep, useAddChatMembers, useAddHolidayCalendar, useAddProjectAddonBlock, useAddWorkspaceMembers, useAddonQuote, useAgentChats, useAgentConfig, useAgentDmStatus, useAgentModels, useAgentSession, useAgentWorkspaces, useAiTask, useArbiChat, useArbiConnected, useArbiDocumentSync, useArbiSessionState, useArbiSessionStore, useArbiShellWorkspaces, useArbiWebSocket, useArbiWsContext, useArbiWsMessage, useArbiWsStatus, useArbiWsStore, useArbiWsTask, useArbiWsTasks, useAssignDocTags, useAuthorizeLimits, useAvatarCrop, useBookingPages, useCalDavProfiles, useCalendarAccounts, useCalendarEvent, useCalendarEventByUid, useCalendarEvents, useCalendarInvitations, useCalendarOutbox, useCalendarOverlays, useCalendarSettings, useCalendarShares, useCalendarSupport, useCalendars, useCameraStream, useCancelDriveSync, useCancelMailboxSync, useCancelProjectSubscription, useChangeProjectPlan, useChargeWatch, useChatLiveUpdates, useChatPost, useChatSummaries, useChatThread, useChatUnreadTotal, useChats, useClaimNativeAlias, useCloseAgentSession, useCommandPalette, useConfirmEmailChange, useConnectCalDavAccount, useConnectMailAccount, useConnectOAuthAccount, useConnectorAutoSync, useConnectorCatalog, useConnectorVendorVisibility, useContacts, useConversationActivity, useConversationPendingAuth, useConversationUsage, useCreateAgent, useCreateCalendar, useCreateContact, useCreateEvent, useCreateFact, useCreateFacts, useCreateGroupChat, useCreateProject, useCreateProjectCheckout, useCreateRoom, useCreateWork, useCreateWorkflow, useCurrentSessionId, useDecideCounter, useDeleteAccount, useDeleteAccountFlow, useDeleteBookingPage, useDeleteCalendar, useDeleteChatMessage, useDeleteContact, useDeleteDocuments, useDeleteEvent, useDeleteFact, useDeleteNotifications, useDeleteProject, useDeleteSkill, useDeleteWorkflow, useDeleteWorkspaces, useDirectMessages, useDisconnectCalendarAccount, useDisconnectConnector, useDisconnectMailAccount, useDisconnectSlack, useDocumentHostActions, useDocumentPendingSync, useDocumentThumbnails, useDocumentsSupport, useDownloadDocuments, useDriveFolderChildren, useDriveFolderDocCount, useDriveFolders, useDriveSyncEstimate, useDriveSyncProgress, useEmailChange, useEnableDriveSync, useEnableMailboxSync, useEntitlements, useFacts, useFetchCalendarEvent, useFilteredProjects, useFinaliseTranslation, useFindTime, useFollowThread, useFreeBusy, useGenerateAgentAvatar, useGenerateDocTags, useGrantAgentAccess, useHolidayCountries, useHouseTemplateCandidates, useIdentityVerification, useIdentityVerificationFlow, useImportCalendar, useImportContacts, useInvalidateProjects, useInviteContacts, useIsEntitled, useIsSlow, useLinkContact, useMailAccounts, useMailAttachmentText, useMailCache, useMailClient, useMailDraftCompose, useMailDraftEditor, useMailDraftReplaced, useMailFolders, useMailMessage, useMailMessages, useMailOnline, useMailPolicy, useMailProjects, useMailUnlock, useMailboxFolders, useMailboxSyncProgress, useMarkChatRead, useMarkNotificationsRead, useMcpTools, useMoveEvent, useMyConnectors, useNameEditor, useNotificationPreferences, useNotifications, useOfflineDocumentIds, useOpenViewerDocumentId, usePassageQuotes, usePasswordChange, usePasswordChangeForm, usePendingContacts, usePlanQuote, usePlanWork, usePreviewProjectPlanChange, useProcessingTask, useProcessingTasks, useProducts, useProfile, useProjectBillingPortal, useProjectConversationUsage, useProjectEvents, usePublishCalendar, useRefreshCalendar, useRefreshConnectorsOnRunEnd, useRefreshProject, useRelatedDocuments, useRemoveChatMember, useRemoveDocTags, useRemoveWorkspaceMembers, useRenameChat, useRenameFolder, useRequestEmailChange, useRespondToEvent, useResumeCalendarAccountConnect, useRevokeAgentAccess, useRooms, useRunConversation, useRunWorkflow, useSaveAgentConfig, useSaveBookingPage, useSaveCalendarSettings, useSaveMailDraft, useSaveSkill, useSearchContacts, useSearchFacts, useSemanticSearch, useSendBackStep, useSendMail, useSessions, useSetSkillVisibility, useSetWorkspaceHouseTemplate, useSetWorkspaceMemberRoles, useShareCalendar, useShellWorkspaces, useSignOut, useSkillSource, useSkills, useSlackConnection, useStartAgentSession, useStartCalendarAccountOAuth, useStartWorkQuery, useSubscribeCalendar, useSyncAccountsOnOpen, useSyncCalendarAccount, useTerminateSession, useTriggerDriveSync, useTriggerMailboxSync, useUnreadByPeer, useUnshareCalendar, useUpdateCalendar, useUpdateCalendarAccount, useUpdateContact, useUpdateConversation, useUpdateDocTag, useUpdateDocuments, useUpdateEvent, useUpdateFact, useUpdateMailMessage, useUpdateProfile, useUpdateProjectAddonSettings, useUpdateProjectFields, useUpdateProjectNextPeriodAddons, useUpdateUserSettings, useUpdateWorkflow, useUpdateWorkspace, useUploadDocuments, useUploadFiles, useUploadFromUrls, useUploadSkillFiles, useUploadUrls, useUserSettings, useVideoRecorder, useWorkNotifications, useWorkflowRuns, useWorkflows, useWorkspaceDocs, useWorkspaceNotificationLevel, useWorkspaceUsers, userDisplayName, userInitials, withRelativePath, workflowStepOf, workspaceHouseTemplateId };
|
|
9764
9927
|
//# sourceMappingURL=index.js.map
|
|
9765
9928
|
//# sourceMappingURL=index.js.map
|