@arbidocs/react 0.3.147 → 0.3.149

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
- import { cn, Avatar, AvatarFallback, AvatarImage, Tooltip, TooltipTrigger, TooltipContent, Popover, PopoverTrigger, PopoverContent, AiMarkdown, Card, Button, Badge, MarkdownRenderer, Input, DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, ScrollArea, Textarea, Slider, Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuItem, Checkbox } from './chunk-VTX77MYP.js';
2
- export { AiMarkdown, Avatar, AvatarFallback, AvatarImage, Badge, Button, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, Collapsible, CollapsibleContent, CollapsibleTrigger, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, HoverCard, HoverCardContent, HoverCardTrigger, Input, Label, MarkdownRenderer, MarkdownStreamingContext, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, Progress, RadioGroup, RadioGroupItem, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, Slider, Switch, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsList, TabsTrigger, Textarea, Toggle, ToggleGroup, ToggleGroupItem, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, badgeVariants, buttonVariants, cardVariants, cn, markdownBaseComponents, splitMarkdownBlocks, toggleVariants } from './chunk-VTX77MYP.js';
3
1
  import { useArbi, ArbiProvider } from './chunk-J4MX2W4H.js';
4
2
  export { ArbiProvider, useArbi } from './chunk-J4MX2W4H.js';
5
- import React2, { memo, useState, createContext, forwardRef, useMemo, useCallback, useId, useRef, useContext, useEffect } from 'react';
3
+ import { cn, Avatar, AvatarFallback, AvatarImage, Tooltip, TooltipTrigger, TooltipContent, Popover, PopoverTrigger, PopoverContent, AiMarkdown, Card, Button, Badge, MarkdownRenderer, Input, DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, ScrollArea, Textarea, Slider, Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuItem, Checkbox } from './chunk-VTX77MYP.js';
4
+ export { AiMarkdown, Avatar, AvatarFallback, AvatarImage, Badge, Button, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, Collapsible, CollapsibleContent, CollapsibleTrigger, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, HoverCard, HoverCardContent, HoverCardTrigger, Input, Label, MarkdownRenderer, MarkdownStreamingContext, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, Progress, RadioGroup, RadioGroupItem, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, Slider, Switch, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsList, TabsTrigger, Textarea, Toggle, ToggleGroup, ToggleGroupItem, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, badgeVariants, buttonVariants, cardVariants, cn, markdownBaseComponents, splitMarkdownBlocks, toggleVariants } from './chunk-VTX77MYP.js';
5
+ import React2, { memo, useState, createContext, forwardRef, useMemo, useCallback, useId, useRef, useContext, useEffect, Fragment as Fragment$1 } from 'react';
6
6
  import { useQuery, useMutation, useQueries, QueryClient, QueryClientProvider, useQueryClient } from '@tanstack/react-query';
7
7
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
8
8
  import { connectWithReconnect, resolveCitations, summarizeCitations } from '@arbidocs/sdk/browser';
@@ -1333,7 +1333,7 @@ function ArbiChat({
1333
1333
  ) }) });
1334
1334
  }
1335
1335
  var TypingIndicator = memo(function TypingIndicator2() {
1336
- return /* @__PURE__ */ jsx("div", { className: "flex w-full justify-start mb-2", children: /* @__PURE__ */ jsx("div", { className: "bg-card border border-primary rounded-2xl rounded-bl-md px-4 py-2.5", children: /* @__PURE__ */ jsxs("div", { className: "flex gap-1 items-center", children: [
1336
+ return /* @__PURE__ */ jsx("div", { className: "flex w-full justify-start mb-2", "data-testid": "dm-typing-indicator", children: /* @__PURE__ */ jsx("div", { className: "bg-card border border-primary rounded-2xl rounded-bl-md px-4 py-2.5", children: /* @__PURE__ */ jsxs("div", { className: "flex gap-1 items-center", children: [
1337
1337
  /* @__PURE__ */ jsx("span", { className: "w-1.5 h-1.5 rounded-full bg-muted-foreground animate-bounce [animation-delay:0ms]" }),
1338
1338
  /* @__PURE__ */ jsx("span", { className: "w-1.5 h-1.5 rounded-full bg-muted-foreground animate-bounce [animation-delay:150ms]" }),
1339
1339
  /* @__PURE__ */ jsx("span", { className: "w-1.5 h-1.5 rounded-full bg-muted-foreground animate-bounce [animation-delay:300ms]" })
@@ -1347,23 +1347,35 @@ var ChatBubble = memo(function ChatBubble2({
1347
1347
  read,
1348
1348
  onDelete,
1349
1349
  isLastOfRun = true,
1350
+ senderName,
1351
+ classNames,
1350
1352
  renderMessage = (m) => m,
1351
- formatTimestamp = (t) => t
1353
+ formatTimestamp = (t) => t,
1354
+ "data-testid": testId
1352
1355
  }) {
1353
1356
  const [isHovered, setIsHovered] = useState(false);
1354
1357
  const [isFocused, setIsFocused] = useState(false);
1355
1358
  const showDeleteButton = isHovered || isFocused;
1356
1359
  if (deleted) {
1357
- return /* @__PURE__ */ jsx("div", { className: `flex w-full ${isSent ? "justify-end" : "justify-start"} mb-2`, children: /* @__PURE__ */ jsx("div", { className: "text-sm text-muted-foreground italic px-3 py-1", children: "Message deleted" }) });
1360
+ return /* @__PURE__ */ jsx(
1361
+ "div",
1362
+ {
1363
+ "data-testid": testId,
1364
+ className: `flex w-full ${isSent ? "justify-end" : "justify-start"} mb-2`,
1365
+ children: /* @__PURE__ */ jsx("div", { className: "text-sm text-muted-foreground italic px-3 py-1", children: "Message deleted" })
1366
+ }
1367
+ );
1358
1368
  }
1359
1369
  const bubbleRadius = cn(
1360
1370
  "rounded-2xl",
1361
- isSent && isLastOfRun && "rounded-br-md",
1362
- !isSent && isLastOfRun && "rounded-bl-md"
1371
+ isSent && isLastOfRun && "rounded-br-sm",
1372
+ !isSent && isLastOfRun && "rounded-bl-sm"
1363
1373
  );
1374
+ const bubbleSurface = isSent ? cn("bg-ai-accent-soft text-foreground chat-bubble-sent", classNames?.ownBubble) : cn("border border-border bg-card text-card-foreground", classNames?.peerBubble);
1364
1375
  return /* @__PURE__ */ jsxs(
1365
1376
  "div",
1366
1377
  {
1378
+ "data-testid": testId,
1367
1379
  className: cn(
1368
1380
  "flex w-full items-end",
1369
1381
  isLastOfRun ? "mb-2" : "mb-0.5",
@@ -1386,41 +1398,23 @@ var ChatBubble = memo(function ChatBubble2({
1386
1398
  children: /* @__PURE__ */ jsx(Trash2, { className: "w-3.5 h-3.5" })
1387
1399
  }
1388
1400
  ),
1389
- /* @__PURE__ */ jsx("div", { className: "flex flex-col max-w-[80%] md:max-w-[60%]", children: /* @__PURE__ */ jsxs(
1390
- "div",
1391
- {
1392
- className: cn(
1393
- "px-3 py-1.5 break-words",
1394
- bubbleRadius,
1395
- isSent ? "bg-primary text-primary-foreground chat-bubble-sent" : "bg-card border border-primary"
1396
- ),
1397
- children: [
1398
- /* @__PURE__ */ jsx("div", { className: "text-sm [&_.markdown-content]:space-y-1.5 [&_pre]:max-w-full [&_pre]:overflow-x-auto", children: renderMessage(message) }),
1399
- isLastOfRun && /* @__PURE__ */ jsxs(
1400
- "div",
1401
- {
1402
- className: cn(
1403
- "flex items-center gap-1 mt-0.5",
1404
- isSent ? "justify-end" : "justify-start"
1405
- ),
1406
- children: [
1407
- /* @__PURE__ */ jsx(
1408
- "span",
1409
- {
1410
- className: cn(
1411
- "text-[11px] leading-none",
1412
- isSent ? "text-primary-foreground/70" : "text-muted-foreground"
1413
- ),
1414
- children: formatTimestamp(timestamp)
1415
- }
1416
- ),
1417
- isSent && (read ? /* @__PURE__ */ jsx(CheckCheck, { className: "w-3.5 h-3.5 text-primary-foreground/80 flex-shrink-0" }) : /* @__PURE__ */ jsx(Check, { className: "w-3.5 h-3.5 text-primary-foreground/60 flex-shrink-0" }))
1418
- ]
1419
- }
1420
- )
1421
- ]
1422
- }
1423
- ) }),
1401
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col max-w-[80%] md:max-w-[60%]", children: /* @__PURE__ */ jsxs("div", { className: cn("px-3.5 py-2 break-words shadow-sm", bubbleRadius, bubbleSurface), children: [
1402
+ /* @__PURE__ */ jsx("div", { className: "text-sm [&_.markdown-content]:space-y-1.5 [&_pre]:max-w-full [&_pre]:overflow-x-auto", children: renderMessage(message) }),
1403
+ isLastOfRun && /* @__PURE__ */ jsxs(
1404
+ "div",
1405
+ {
1406
+ className: cn(
1407
+ "flex items-center gap-1.5 mt-0.5",
1408
+ isSent ? "justify-end" : "justify-start"
1409
+ ),
1410
+ children: [
1411
+ senderName && /* @__PURE__ */ jsx("span", { className: "text-[11px] font-medium leading-none opacity-90", children: senderName }),
1412
+ /* @__PURE__ */ jsx("span", { className: "text-[11px] leading-none opacity-70", children: formatTimestamp(timestamp) }),
1413
+ isSent && (read ? /* @__PURE__ */ jsx(CheckCheck, { className: "w-3.5 h-3.5 flex-shrink-0 opacity-80" }) : /* @__PURE__ */ jsx(Check, { className: "w-3.5 h-3.5 flex-shrink-0 opacity-60" }))
1414
+ ]
1415
+ }
1416
+ )
1417
+ ] }) }),
1424
1418
  !isSent && onDelete && /* @__PURE__ */ jsx(
1425
1419
  "button",
1426
1420
  {
@@ -2698,6 +2692,79 @@ function DocumentReview({
2698
2692
  }
2699
2693
  );
2700
2694
  }
2695
+ var TIERS = [
2696
+ { min: 0.7, tone: "bg-emerald-500", label: "High relevance" },
2697
+ { min: 0.4, tone: "bg-amber-500", label: "Medium relevance" },
2698
+ { min: -Infinity, tone: "bg-muted-foreground/40", label: "Low relevance" }
2699
+ ];
2700
+ function RelevanceDot({ score }) {
2701
+ if (score == null) return null;
2702
+ const tier = TIERS.find((t) => score >= t.min) ?? TIERS[TIERS.length - 1];
2703
+ return /* @__PURE__ */ jsx(
2704
+ "span",
2705
+ {
2706
+ role: "img",
2707
+ "aria-label": tier.label,
2708
+ title: `${tier.label} (${score.toFixed(2)})`,
2709
+ className: cn("size-1.5 shrink-0 rounded-full", tier.tone),
2710
+ "data-testid": "passage-relevance"
2711
+ }
2712
+ );
2713
+ }
2714
+ function PassageCard({
2715
+ header,
2716
+ score,
2717
+ headerRight,
2718
+ active,
2719
+ onClick,
2720
+ footer,
2721
+ className,
2722
+ children,
2723
+ "data-testid": testId
2724
+ }) {
2725
+ const body = /* @__PURE__ */ jsxs(Fragment, { children: [
2726
+ /* @__PURE__ */ jsxs("div", { className: "mb-1.5 flex items-center gap-2", children: [
2727
+ header,
2728
+ (score != null || headerRight) && /* @__PURE__ */ jsxs("div", { className: "ml-auto flex shrink-0 items-center gap-2", children: [
2729
+ /* @__PURE__ */ jsx(RelevanceDot, { score }),
2730
+ headerRight
2731
+ ] })
2732
+ ] }),
2733
+ /* @__PURE__ */ jsx("div", { className: "[&_mark]:rounded-sm [&_mark]:bg-ai-accent/20 [&_mark]:px-0.5 [&_mark]:font-medium [&_mark]:text-foreground", children })
2734
+ ] });
2735
+ return /* @__PURE__ */ jsxs(
2736
+ "div",
2737
+ {
2738
+ className: cn(
2739
+ "group rounded-lg border border-border bg-card p-3 text-left transition-colors",
2740
+ onClick && "hover:border-ai-accent/40 focus-within:ring-2 focus-within:ring-ai-accent/40",
2741
+ active && "border-ai-accent/60 ring-1 ring-ai-accent/30",
2742
+ className
2743
+ ),
2744
+ children: [
2745
+ onClick ? /* @__PURE__ */ jsx(
2746
+ "div",
2747
+ {
2748
+ role: "button",
2749
+ tabIndex: 0,
2750
+ onClick,
2751
+ onKeyDown: (e) => {
2752
+ if (e.key === "Enter" || e.key === " ") {
2753
+ e.preventDefault();
2754
+ onClick(e);
2755
+ }
2756
+ },
2757
+ "aria-current": active || void 0,
2758
+ "data-testid": testId,
2759
+ className: "cursor-pointer focus:outline-none",
2760
+ children: body
2761
+ }
2762
+ ) : /* @__PURE__ */ jsx("div", { "aria-current": active || void 0, "data-testid": testId, children: body }),
2763
+ footer
2764
+ ]
2765
+ }
2766
+ );
2767
+ }
2701
2768
  function queryTerms(query) {
2702
2769
  const terms = /* @__PURE__ */ new Set();
2703
2770
  for (const phrase of query.match(/"([^"]+)"/g) ?? []) {
@@ -2714,20 +2781,10 @@ function HighlightedSnippet({ text, terms }) {
2714
2781
  if (terms.length === 0) return [text];
2715
2782
  const escaped = terms.map((t) => t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
2716
2783
  const re = new RegExp(`(${escaped.join("|")})`, "gi");
2717
- return text.split(re).map(
2718
- (part, i) => i % 2 === 1 ? /* @__PURE__ */ jsx("mark", { className: "rounded-sm bg-ai-accent/20 px-0.5 text-foreground", children: part }, i) : part
2719
- );
2784
+ return text.split(re).map((part, i) => i % 2 === 1 ? /* @__PURE__ */ jsx("mark", { children: part }, i) : part);
2720
2785
  }, [text, terms]);
2721
2786
  return /* @__PURE__ */ jsx(Fragment, { children: nodes });
2722
2787
  }
2723
- function RelevanceDot({ score }) {
2724
- if (score == null) return null;
2725
- const tone = score >= 0.7 ? "bg-emerald-500" : score >= 0.4 ? "bg-amber-500" : "bg-muted-foreground/40";
2726
- return /* @__PURE__ */ jsxs("span", { className: "ml-auto inline-flex items-center gap-1.5 text-[10px] text-muted-foreground", children: [
2727
- /* @__PURE__ */ jsx("span", { className: cn("size-1.5 rounded-full", tone), "aria-hidden": true }),
2728
- score.toFixed(2)
2729
- ] });
2730
- }
2731
2788
  function ResultRow({
2732
2789
  result,
2733
2790
  index,
@@ -2735,34 +2792,26 @@ function ResultRow({
2735
2792
  isActive,
2736
2793
  onSelect
2737
2794
  }) {
2738
- return /* @__PURE__ */ jsxs(
2739
- "button",
2795
+ return /* @__PURE__ */ jsx(
2796
+ PassageCard,
2740
2797
  {
2741
- type: "button",
2742
2798
  onClick: onSelect,
2799
+ active: isActive,
2800
+ score: result.score,
2743
2801
  "data-testid": `arbi-semantic-search-result-${index}`,
2744
- "aria-current": isActive,
2745
- className: cn(
2746
- "w-full rounded-lg border border-border bg-card p-3 text-left transition-colors",
2747
- "hover:border-ai-accent/40 focus:outline-none focus-visible:ring-2 focus-visible:ring-ai-accent/40",
2748
- isActive && "border-ai-accent/60 ring-1 ring-ai-accent/30"
2749
- ),
2750
- children: [
2751
- /* @__PURE__ */ jsxs("div", { className: "mb-1 flex items-center gap-2", children: [
2752
- /* @__PURE__ */ jsx(FileText, { className: "size-3.5 shrink-0 text-ai-accent" }),
2753
- /* @__PURE__ */ jsx("span", { className: "truncate text-xs font-medium text-foreground", children: result.docTitle ?? "Document" }),
2754
- result.page != null && /* @__PURE__ */ jsxs(Badge, { variant: "secondary", children: [
2755
- "p.",
2756
- result.page
2757
- ] }),
2758
- /* @__PURE__ */ jsx(RelevanceDot, { score: result.score })
2759
- ] }),
2760
- /* @__PURE__ */ jsxs("p", { className: "line-clamp-3 text-xs leading-relaxed text-muted-foreground", children: [
2761
- /* @__PURE__ */ jsx("span", { className: "text-muted-foreground/60", children: "\u2026 " }),
2762
- /* @__PURE__ */ jsx(HighlightedSnippet, { text: result.content, terms }),
2763
- /* @__PURE__ */ jsx("span", { className: "text-muted-foreground/60", children: " \u2026" })
2802
+ header: /* @__PURE__ */ jsxs(Fragment, { children: [
2803
+ /* @__PURE__ */ jsx(FileText, { className: "size-3.5 shrink-0 text-ai-accent" }),
2804
+ /* @__PURE__ */ jsx("span", { className: "truncate text-xs font-medium text-foreground", children: result.docTitle ?? "Document" }),
2805
+ result.page != null && /* @__PURE__ */ jsxs(Badge, { variant: "secondary", children: [
2806
+ "p.",
2807
+ result.page
2764
2808
  ] })
2765
- ]
2809
+ ] }),
2810
+ children: /* @__PURE__ */ jsxs("p", { className: "line-clamp-3 text-xs leading-relaxed text-muted-foreground", children: [
2811
+ /* @__PURE__ */ jsx("span", { className: "text-muted-foreground/60", children: "\u2026 " }),
2812
+ /* @__PURE__ */ jsx(HighlightedSnippet, { text: result.content, terms }),
2813
+ /* @__PURE__ */ jsx("span", { className: "text-muted-foreground/60", children: " \u2026" })
2814
+ ] })
2766
2815
  }
2767
2816
  );
2768
2817
  }
@@ -5380,88 +5429,207 @@ function ConversationList({
5380
5429
  selectedPeerId,
5381
5430
  onSelect,
5382
5431
  classNames,
5383
- emptyState
5432
+ emptyState,
5433
+ header,
5434
+ className
5384
5435
  }) {
5385
5436
  return /* @__PURE__ */ jsxs(
5386
5437
  "aside",
5387
5438
  {
5388
- className: "flex min-h-0 flex-col border-b border-border md:w-80 md:shrink-0 md:border-b-0 md:border-r",
5439
+ className: cn(
5440
+ "flex min-h-0 flex-col border-b border-border md:w-80 md:shrink-0 md:border-b-0 md:border-r",
5441
+ className
5442
+ ),
5389
5443
  "data-testid": "arbi-dm-list",
5390
5444
  children: [
5391
- /* @__PURE__ */ jsxs("div", { className: "border-b border-border px-4 py-3", children: [
5445
+ header === void 0 ? /* @__PURE__ */ jsxs("div", { className: "border-b border-border px-4 py-3", children: [
5392
5446
  /* @__PURE__ */ jsx("p", { className: "text-sm font-semibold text-foreground", children: "Conversations" }),
5393
5447
  /* @__PURE__ */ jsxs("p", { className: "text-xs text-muted-foreground", children: [
5394
5448
  conversations.length,
5395
5449
  " ",
5396
5450
  conversations.length === 1 ? "colleague" : "colleagues"
5397
5451
  ] })
5398
- ] }),
5399
- /* @__PURE__ */ jsx("div", { className: "min-h-0 flex-1 overflow-y-auto", children: conversations.length === 0 ? /* @__PURE__ */ jsx("div", { className: "px-4 py-6 text-xs text-muted-foreground", children: emptyState ?? "No conversations yet." }) : /* @__PURE__ */ jsx("ul", { className: "w-full", children: conversations.map((c) => {
5452
+ ] }) : header,
5453
+ /* @__PURE__ */ jsx("div", { className: "min-h-0 flex-1 overflow-y-auto", children: conversations.length === 0 ? /* @__PURE__ */ jsx("div", { className: "px-4 py-6 text-xs text-muted-foreground", children: emptyState ?? "No conversations yet." }) : /* @__PURE__ */ jsx("ul", { className: "w-full", children: conversations.map((c, i) => {
5400
5454
  const { peer, lastMessage, unreadCount } = c;
5455
+ const newSection = c.sectionLabel && c.sectionLabel !== conversations[i - 1]?.sectionLabel;
5401
5456
  const active = peer.external_id === selectedPeerId;
5402
- const preview = lastMessage ? `${lastMessage.isMine ? "You: " : ""}${lastMessage.body}` : "No messages yet \u2014 say hello";
5403
- return /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(
5404
- "button",
5405
- {
5406
- type: "button",
5407
- onClick: () => onSelect(peer.external_id),
5408
- "data-testid": `arbi-dm-conversation-${peer.external_id}`,
5409
- className: cn(
5410
- "flex w-full items-start gap-3 border-b border-border/60 px-4 py-3 text-left transition-colors",
5411
- active ? "bg-accent" : "hover:bg-accent/60"
5412
- ),
5413
- children: [
5414
- /* @__PURE__ */ jsx(DmAvatar, { user: peer }),
5415
- /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
5416
- /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
5417
- /* @__PURE__ */ jsx("span", { className: "truncate text-sm font-semibold text-foreground", children: userDisplayName(peer) }),
5418
- /* @__PURE__ */ jsx("span", { className: "shrink-0 text-[11px] text-muted-foreground", children: lastMessage ? formatRelativeTime(lastMessage.createdAt) : "" })
5419
- ] }),
5420
- /* @__PURE__ */ jsxs("div", { className: "mt-1 flex items-center gap-2", children: [
5421
- /* @__PURE__ */ jsx("p", { className: "min-w-0 flex-1 truncate text-xs text-muted-foreground", children: preview }),
5422
- unreadCount > 0 ? /* @__PURE__ */ jsx(Badge, { className: cn("px-1.5 py-0 text-[10px]", classNames?.unreadBadge), children: unreadCount }) : null
5423
- ] })
5424
- ] })
5425
- ]
5426
- }
5427
- ) }, peer.external_id);
5457
+ const preview = lastMessage?.body ?? "No messages yet \u2014 say hello";
5458
+ const unread = unreadCount > 0;
5459
+ const body = /* @__PURE__ */ jsxs(Fragment, { children: [
5460
+ c.leading ?? /* @__PURE__ */ jsx(DmAvatar, { user: peer }),
5461
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
5462
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
5463
+ /* @__PURE__ */ jsx(
5464
+ "span",
5465
+ {
5466
+ className: cn(
5467
+ "truncate text-sm text-foreground",
5468
+ unread ? "font-bold" : "font-semibold"
5469
+ ),
5470
+ children: userDisplayName(peer)
5471
+ }
5472
+ ),
5473
+ c.statusLabel ? /* @__PURE__ */ jsx(
5474
+ Badge,
5475
+ {
5476
+ variant: "outline",
5477
+ className: "shrink-0 rounded-full px-2 py-0 text-[10px] font-medium text-muted-foreground",
5478
+ children: c.statusLabel
5479
+ }
5480
+ ) : unreadCount > 0 ? (
5481
+ // Quiet by default: a filled brand pill with a shadow
5482
+ // shouted louder than the message it was counting.
5483
+ // Enough to catch the eye scanning the list, no more.
5484
+ /* @__PURE__ */ jsx(
5485
+ Badge,
5486
+ {
5487
+ variant: "accent",
5488
+ className: cn(
5489
+ "min-w-[1.125rem] justify-center rounded-full px-1 py-0 text-[10px] font-medium leading-[1.125rem] shadow-none",
5490
+ classNames?.unreadBadge
5491
+ ),
5492
+ children: unreadCount
5493
+ }
5494
+ )
5495
+ ) : null
5496
+ ] }),
5497
+ /* @__PURE__ */ jsxs("div", { className: "mt-1 flex items-center gap-1.5", children: [
5498
+ lastMessage?.isMine ? lastMessage.read ? /* @__PURE__ */ jsx(
5499
+ CheckCheck,
5500
+ {
5501
+ className: "size-3.5 shrink-0 text-ai-accent",
5502
+ "aria-label": "Read"
5503
+ }
5504
+ ) : /* @__PURE__ */ jsx(
5505
+ Check,
5506
+ {
5507
+ className: "size-3.5 shrink-0 text-muted-foreground",
5508
+ "aria-label": "Sent"
5509
+ }
5510
+ ) : null,
5511
+ /* @__PURE__ */ jsx(
5512
+ "p",
5513
+ {
5514
+ className: cn(
5515
+ "min-w-0 flex-1 truncate text-xs",
5516
+ unread ? "font-medium text-foreground" : "text-muted-foreground"
5517
+ ),
5518
+ children: c.subtitle ?? preview
5519
+ }
5520
+ ),
5521
+ /* @__PURE__ */ jsx("span", { className: "shrink-0 text-[11px] text-muted-foreground", children: lastMessage ? formatRelativeTime(lastMessage.createdAt) : "" })
5522
+ ] })
5523
+ ] })
5524
+ ] });
5525
+ const rowClass = cn(
5526
+ // Each row is its own opaque surface. Left transparent it takes
5527
+ // the panel's colour, and the chips stop reading as cards at all
5528
+ // — which is the whole point of them.
5529
+ "flex w-full items-start gap-3 border-b border-border/60 bg-card px-4 py-3 text-left transition-colors",
5530
+ c.disabled ? "cursor-default" : active ? "bg-ai-accent-soft" : "hover:bg-accent/40"
5531
+ );
5532
+ return /* @__PURE__ */ jsxs("li", { children: [
5533
+ newSection && /* @__PURE__ */ jsx(
5534
+ "p",
5535
+ {
5536
+ className: "bg-muted/40 px-4 py-1.5 text-[11px] font-medium uppercase tracking-wide text-muted-foreground",
5537
+ "data-testid": "arbi-dm-section",
5538
+ children: c.sectionLabel
5539
+ }
5540
+ ),
5541
+ c.disabled ? /* @__PURE__ */ jsxs(
5542
+ "div",
5543
+ {
5544
+ "data-testid": `arbi-dm-conversation-${peer.external_id}`,
5545
+ className: rowClass,
5546
+ children: [
5547
+ body,
5548
+ c.trailing
5549
+ ]
5550
+ }
5551
+ ) : /* @__PURE__ */ jsx(
5552
+ "button",
5553
+ {
5554
+ type: "button",
5555
+ onClick: () => onSelect(peer.external_id),
5556
+ "data-testid": `arbi-dm-conversation-${peer.external_id}`,
5557
+ className: rowClass,
5558
+ children: body
5559
+ }
5560
+ )
5561
+ ] }, peer.external_id);
5428
5562
  }) }) })
5429
5563
  ]
5430
5564
  }
5431
5565
  );
5432
5566
  }
5433
- function MessageBubble2({ message, classNames }) {
5434
- const { isMine } = message;
5435
- const who = isMine ? "You" : userDisplayName(message.sender);
5436
- return /* @__PURE__ */ jsxs(
5437
- "div",
5567
+
5568
+ // src/directmessages/grouping.ts
5569
+ var RUN_WINDOW_MS = 2 * 60 * 1e3;
5570
+ function dayKey(iso) {
5571
+ const d = new Date(iso);
5572
+ if (Number.isNaN(d.getTime())) return iso;
5573
+ return `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}`;
5574
+ }
5575
+ function annotateThread(messages, accessors, runWindowMs = RUN_WINDOW_MS) {
5576
+ const { senderId, createdAt } = accessors;
5577
+ return messages.map((message, i) => {
5578
+ const next = messages[i + 1];
5579
+ const prev = messages[i - 1];
5580
+ const day = dayKey(createdAt(message));
5581
+ const continuesIntoNext = !!next && senderId(next) === senderId(message) && dayKey(createdAt(next)) === day && Date.parse(createdAt(next)) - Date.parse(createdAt(message)) < runWindowMs;
5582
+ return {
5583
+ message,
5584
+ isLastOfRun: !continuesIntoNext,
5585
+ isFirstOfDay: !prev || dayKey(createdAt(prev)) !== day
5586
+ };
5587
+ });
5588
+ }
5589
+ function DateSeparator({ children }) {
5590
+ return /* @__PURE__ */ jsx("div", { className: "my-3 flex justify-center", "data-testid": "dm-date-separator", children: /* @__PURE__ */ jsx("span", { className: "rounded-full bg-background/80 px-2 py-0.5 text-xs text-muted-foreground", children }) });
5591
+ }
5592
+ function MessageBubble2({
5593
+ message,
5594
+ classNames,
5595
+ isLastOfRun = true,
5596
+ onDelete,
5597
+ deleted
5598
+ }) {
5599
+ return /* @__PURE__ */ jsx(
5600
+ ChatBubble,
5438
5601
  {
5439
5602
  "data-testid": "arbi-dm-message",
5440
- className: cn("flex flex-col gap-1", isMine ? "items-end" : "items-start"),
5441
- children: [
5442
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 px-1", children: [
5443
- /* @__PURE__ */ jsx("span", { className: "text-[11px] font-medium text-foreground", children: who }),
5444
- /* @__PURE__ */ jsx("span", { className: "text-[11px] text-muted-foreground", children: formatRelativeTime(message.createdAt) })
5445
- ] }),
5446
- /* @__PURE__ */ jsx(
5447
- "div",
5448
- {
5449
- className: cn(
5450
- "max-w-[80%] rounded-2xl px-3.5 py-2 text-sm shadow-sm",
5451
- isMine ? cn("rounded-br-sm bg-accent text-accent-foreground", classNames?.ownBubble) : cn(
5452
- "rounded-bl-sm border border-border bg-card text-card-foreground",
5453
- classNames?.peerBubble
5454
- )
5455
- ),
5456
- children: message.body
5457
- }
5458
- )
5459
- ]
5603
+ message: message.body,
5604
+ timestamp: message.createdAt,
5605
+ isSent: message.isMine,
5606
+ read: message.read,
5607
+ deleted,
5608
+ onDelete,
5609
+ isLastOfRun,
5610
+ senderName: message.isMine ? "You" : userDisplayName(message.sender),
5611
+ classNames,
5612
+ formatTimestamp: formatRelativeTime
5460
5613
  }
5461
5614
  );
5462
5615
  }
5463
- function MessageThread({ conversation, classNames, emptyState }) {
5616
+ var THREAD_ACCESSORS = {
5617
+ senderId: (m) => m.sender.external_id,
5618
+ createdAt: (m) => m.createdAt
5619
+ };
5620
+ function MessageThread({
5621
+ conversation,
5622
+ classNames,
5623
+ emptyState,
5624
+ formatDay,
5625
+ onDeleteMessage,
5626
+ deletedIds
5627
+ }) {
5464
5628
  const bottomRef = useRef(null);
5629
+ const items = useMemo(
5630
+ () => annotateThread(conversation?.messages ?? [], THREAD_ACCESSORS),
5631
+ [conversation?.messages]
5632
+ );
5465
5633
  useEffect(() => {
5466
5634
  bottomRef.current?.scrollIntoView({ block: "end" });
5467
5635
  }, [conversation?.peer.external_id, conversation?.messages.length]);
@@ -5474,7 +5642,7 @@ function MessageThread({ conversation, classNames, emptyState }) {
5474
5642
  ] })
5475
5643
  ] }) });
5476
5644
  }
5477
- const { peer, messages } = conversation;
5645
+ const { peer } = conversation;
5478
5646
  return /* @__PURE__ */ jsxs(Fragment, { children: [
5479
5647
  /* @__PURE__ */ jsxs("header", { className: "flex items-center gap-3 border-b border-border px-4 py-3", children: [
5480
5648
  /* @__PURE__ */ jsx(DmAvatar, { user: peer, className: "size-9" }),
@@ -5483,20 +5651,42 @@ function MessageThread({ conversation, classNames, emptyState }) {
5483
5651
  /* @__PURE__ */ jsx("p", { className: "truncate text-xs text-muted-foreground", children: peer.email })
5484
5652
  ] })
5485
5653
  ] }),
5486
- /* @__PURE__ */ jsx(ScrollArea, { className: "min-h-0 flex-1 bg-background", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 px-4 py-4", "data-testid": "arbi-dm-thread", children: [
5487
- messages.map((m) => /* @__PURE__ */ jsx(MessageBubble2, { message: m, classNames }, m.externalId)),
5654
+ /* @__PURE__ */ jsx(ScrollArea, { className: "min-h-0 flex-1 bg-background", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col px-4 py-4", "data-testid": "arbi-dm-thread", children: [
5655
+ items.map(({ message: m, isLastOfRun, isFirstOfDay }) => /* @__PURE__ */ jsxs(Fragment$1, { children: [
5656
+ isFirstOfDay && formatDay && /* @__PURE__ */ jsx(DateSeparator, { children: formatDay(m.createdAt) }),
5657
+ /* @__PURE__ */ jsx(
5658
+ MessageBubble2,
5659
+ {
5660
+ message: m,
5661
+ classNames,
5662
+ isLastOfRun,
5663
+ deleted: deletedIds?.has(m.externalId),
5664
+ onDelete: onDeleteMessage ? () => onDeleteMessage(m) : void 0
5665
+ }
5666
+ )
5667
+ ] }, m.externalId)),
5488
5668
  /* @__PURE__ */ jsx("div", { ref: bottomRef })
5489
5669
  ] }) })
5490
5670
  ] });
5491
5671
  }
5492
- function DmComposer({ placeholder, disabled, onSend, error, classNames }) {
5672
+ function DmComposer({
5673
+ placeholder,
5674
+ disabled,
5675
+ busy,
5676
+ onSend,
5677
+ error,
5678
+ children,
5679
+ classNames
5680
+ }) {
5493
5681
  const [draft, setDraft] = useState("");
5682
+ const inputRef = useRef(null);
5494
5683
  const submit = async () => {
5495
5684
  const text = draft.trim();
5496
- if (!text || disabled) return;
5685
+ if (!text || disabled || busy) return;
5497
5686
  setDraft("");
5498
5687
  try {
5499
5688
  await onSend(text);
5689
+ inputRef.current?.focus();
5500
5690
  } catch {
5501
5691
  setDraft(text);
5502
5692
  }
@@ -5508,10 +5698,12 @@ function DmComposer({ placeholder, disabled, onSend, error, classNames }) {
5508
5698
  }
5509
5699
  };
5510
5700
  return /* @__PURE__ */ jsxs("div", { className: "border-t border-border p-3", children: [
5701
+ children,
5511
5702
  /* @__PURE__ */ jsxs("div", { className: "flex items-end gap-2", children: [
5512
5703
  /* @__PURE__ */ jsx(
5513
5704
  Textarea,
5514
5705
  {
5706
+ ref: inputRef,
5515
5707
  value: draft,
5516
5708
  onChange: (e) => setDraft(e.target.value),
5517
5709
  onKeyDown,
@@ -5527,11 +5719,12 @@ function DmComposer({ placeholder, disabled, onSend, error, classNames }) {
5527
5719
  {
5528
5720
  type: "button",
5529
5721
  onClick: () => void submit(),
5530
- disabled: disabled || !draft.trim(),
5722
+ disabled: disabled || busy || !draft.trim(),
5531
5723
  className: cn(classNames?.sendButton),
5532
5724
  "data-testid": "arbi-dm-send",
5725
+ "aria-label": "Send message",
5533
5726
  children: [
5534
- /* @__PURE__ */ jsx(Send, { className: "size-4" }),
5727
+ busy ? /* @__PURE__ */ jsx(Loader2, { className: "size-4 animate-spin" }) : /* @__PURE__ */ jsx(Send, { className: "size-4" }),
5535
5728
  " Send"
5536
5729
  ]
5537
5730
  }
@@ -6735,6 +6928,6 @@ function DocumentGallery({
6735
6928
  );
6736
6929
  }
6737
6930
 
6738
- export { ActivityFeed, AiActionCard, AiAnswer, AppleIcon, ArbiBotHeadIcon, ArbiBotIcon, ArbiChat, ArbiChatPanel, ArbiIcon, ArbiWebSocketProvider, ArtifactCanvas, AudIcon, BASE_COLORS2 as BASE_COLORS, ChatBubble, CitationRenderer, ClaudeIcon, CommandPalette, CommandPaletteProvider, ConversationList, DEFAULT_ASPECT_OPTIONS, DEFAULT_NOTIFY_TONE, DirectMessages, DmAvatar, DmComposer, DocIcon, DocQaPanel, DocSearch, DocumentCard, DocumentCardMenu, DocumentEntity, DocumentGallery, DocumentReview, DocumentTable, ENTITY_MAPPINGS, EmlIcon, EntityIcon, EntityPill, FILE_TYPE_COLORS, FileIcon, FireworksIcon, GeminiIcon, GitHubIcon, GoogleIcon, HtmlIcon, ImageCropModal, ImageCropper, ImgIcon, LinkedInIcon, MessageArtifactCard, MessageBubble2 as MessageBubble, MessageThread, NEUTRAL_GRAY2 as NEUTRAL_GRAY, NotificationBell, OpenAIIcon, PLACEHOLDER_COLOR, PdfIcon, ProjectEntity, ProviderIcon, RagDot, SemanticSearch, StatusPill, TAG_TYPE_ICONS, TAG_TYPE_LABELS, TagEntity, Toaster, TxtIcon, TypingIndicator, UserEntity, UserMenu, VISIBILITY_ICONS, VidIcon, VisibilityIcon, XlsIcon, arbiQueryKeys, configureEntityRegistry, configureRagLabels, configureStatusRegistry, cropImage, describeActivity, formatRelativeTime, getEntityColor2 as getEntityColor, getEntityColorStyles, getEntityIcon, getEntityLabel, getNotificationTypeMeta, getStatusVariant, getTagTypeIcon, getTagTypeLabel, getWorkspaceActionText, getWorkspaceColor, getWorkspaceSentPhrase, isWorkspaceNotificationType, notify, parseActivityContent, redlineStats, seedNotifications, selectUnread, textToArtifact, toRedlineMarkdown, useActivity, useAgents, useAiTask, useArbiConnected, useArbiDocumentSync, useArbiUiStore, useArbiWebSocket, useArbiWsContext, useArbiWsMessage, useArbiWsStatus, useArbiWsStore, useArbiWsTask, useArbiWsTasks, useAssistantQuery, useCommandPalette, useConfigs, useConversations, useDeleteAgents, useDirectMessages, useDocuments, useFacts, useHealth, useNotify, useParsedDocument, useProjectInvoices, useProjectUsage, useProjects, useProjectsUsage, useSemanticSearch, useSessions, useTags, useTasks, useThumbnails, useUserUsageToday, useWorkspaceDocs, useWorkspaces, userDisplayName, userInitials };
6931
+ export { ActivityFeed, AiActionCard, AiAnswer, AppleIcon, ArbiBotHeadIcon, ArbiBotIcon, ArbiChat, ArbiChatPanel, ArbiIcon, ArbiWebSocketProvider, ArtifactCanvas, AudIcon, BASE_COLORS2 as BASE_COLORS, ChatBubble, CitationRenderer, ClaudeIcon, CommandPalette, CommandPaletteProvider, ConversationList, DEFAULT_ASPECT_OPTIONS, DEFAULT_NOTIFY_TONE, DateSeparator, DirectMessages, DmAvatar, DmComposer, DocIcon, DocQaPanel, DocSearch, DocumentCard, DocumentCardMenu, DocumentEntity, DocumentGallery, DocumentReview, DocumentTable, ENTITY_MAPPINGS, EmlIcon, EntityIcon, EntityPill, FILE_TYPE_COLORS, FileIcon, FireworksIcon, GeminiIcon, GitHubIcon, GoogleIcon, HtmlIcon, ImageCropModal, ImageCropper, ImgIcon, LinkedInIcon, MessageArtifactCard, MessageBubble2 as MessageBubble, MessageThread, NEUTRAL_GRAY2 as NEUTRAL_GRAY, NotificationBell, OpenAIIcon, PLACEHOLDER_COLOR, PassageCard, PdfIcon, ProjectEntity, ProviderIcon, RUN_WINDOW_MS, RagDot, RelevanceDot, SemanticSearch, StatusPill, TAG_TYPE_ICONS, TAG_TYPE_LABELS, TagEntity, Toaster, TxtIcon, TypingIndicator, UserEntity, UserMenu, VISIBILITY_ICONS, VidIcon, VisibilityIcon, XlsIcon, annotateThread, arbiQueryKeys, configureEntityRegistry, configureRagLabels, configureStatusRegistry, cropImage, dayKey, describeActivity, formatRelativeTime, getEntityColor2 as getEntityColor, getEntityColorStyles, getEntityIcon, getEntityLabel, getNotificationTypeMeta, getStatusVariant, getTagTypeIcon, getTagTypeLabel, getWorkspaceActionText, getWorkspaceColor, getWorkspaceSentPhrase, isWorkspaceNotificationType, notify, parseActivityContent, redlineStats, seedNotifications, selectUnread, textToArtifact, toRedlineMarkdown, useActivity, useAgents, useAiTask, useArbiConnected, useArbiDocumentSync, useArbiUiStore, useArbiWebSocket, useArbiWsContext, useArbiWsMessage, useArbiWsStatus, useArbiWsStore, useArbiWsTask, useArbiWsTasks, useAssistantQuery, useCommandPalette, useConfigs, useConversations, useDeleteAgents, useDirectMessages, useDocuments, useFacts, useHealth, useNotify, useParsedDocument, useProjectInvoices, useProjectUsage, useProjects, useProjectsUsage, useSemanticSearch, useSessions, useTags, useTasks, useThumbnails, useUserUsageToday, useWorkspaceDocs, useWorkspaces, userDisplayName, userInitials };
6739
6932
  //# sourceMappingURL=index.js.map
6740
6933
  //# sourceMappingURL=index.js.map