@arbidocs/react 0.3.148 → 0.3.150

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
  {
@@ -4403,6 +4397,13 @@ var presencePositionClasses = {
4403
4397
  md: "-right-1.5 -bottom-0.5",
4404
4398
  lg: "-right-1.5 -bottom-0.5"
4405
4399
  };
4400
+ var PRESENCE_LABELS = {
4401
+ connected: "Online",
4402
+ connecting: "Connecting",
4403
+ disconnected: "Offline",
4404
+ error: "Connection problem",
4405
+ hidden: "Status hidden"
4406
+ };
4406
4407
  var presenceColorClasses = {
4407
4408
  connected: "bg-status-online",
4408
4409
  connecting: "bg-status-connecting",
@@ -4423,6 +4424,7 @@ var UserEntity = memo(function UserEntity2({
4423
4424
  colorClass = "",
4424
4425
  isAgent = false,
4425
4426
  agentStyle,
4427
+ avatarStyle,
4426
4428
  isMe = false,
4427
4429
  displayStatus,
4428
4430
  onClick,
@@ -4442,6 +4444,7 @@ var UserEntity = memo(function UserEntity2({
4442
4444
  const agentBadge = isAgent ? /* @__PURE__ */ jsx(ArbiBotHeadIcon, { className: "w-3.5 h-3.5 text-muted-foreground" }) : void 0;
4443
4445
  const canMessage = interactive && !isMe && !isAgent;
4444
4446
  const showUnread = hasUnreadMessages && !isMe && !isAgent;
4447
+ const surfaceStyle = avatarStyle ?? agentStyle;
4445
4448
  const avatarCore = /* @__PURE__ */ jsxs(
4446
4449
  Avatar,
4447
4450
  {
@@ -4449,7 +4452,7 @@ var UserEntity = memo(function UserEntity2({
4449
4452
  sizeClasses[size],
4450
4453
  isAgent ? "rounded-full border-2 border-dashed" : "border border-white"
4451
4454
  ),
4452
- style: agentStyle,
4455
+ style: surfaceStyle,
4453
4456
  "data-testid": "user-entity",
4454
4457
  children: [
4455
4458
  picture && /* @__PURE__ */ jsx(AvatarImage, { src: picture, alt: initials }),
@@ -4461,7 +4464,7 @@ var UserEntity = memo(function UserEntity2({
4461
4464
  "font-semibold leading-none",
4462
4465
  isAgent ? "rounded-full bg-transparent" : `text-white ${colorClass}`
4463
4466
  ),
4464
- style: agentStyle,
4467
+ style: surfaceStyle,
4465
4468
  children: initials
4466
4469
  }
4467
4470
  )
@@ -4478,7 +4481,10 @@ var UserEntity = memo(function UserEntity2({
4478
4481
  !showUnread && displayStatus ? presenceColorClasses[displayStatus] : ""
4479
4482
  ),
4480
4483
  style: showUnread ? { backgroundColor: "#00adef" } : void 0,
4481
- "data-testid": "user-entity-presence"
4484
+ "data-testid": "user-entity-presence",
4485
+ role: "img",
4486
+ "aria-label": showUnread ? "Unread messages" : PRESENCE_LABELS[displayStatus],
4487
+ title: showUnread ? "Unread messages" : PRESENCE_LABELS[displayStatus]
4482
4488
  }
4483
4489
  ) : null;
4484
4490
  const avatarElement = statusDot ? /* @__PURE__ */ jsxs(
@@ -4555,6 +4561,59 @@ var UserEntity = memo(function UserEntity2({
4555
4561
  }
4556
4562
  return avatarElement;
4557
4563
  });
4564
+ function AgentBadge({ className }) {
4565
+ return /* @__PURE__ */ jsxs(
4566
+ "span",
4567
+ {
4568
+ "data-testid": "agent-badge",
4569
+ className: cn(
4570
+ "inline-flex shrink-0 items-center gap-1 rounded-full border border-ai-accent/50",
4571
+ "bg-ai-accent-soft px-2 py-0.5 text-[11px] font-bold uppercase tracking-wider text-ai-accent",
4572
+ className
4573
+ ),
4574
+ children: [
4575
+ /* @__PURE__ */ jsx(ArbiBotHeadIcon, { size: 14, className: "text-ai-accent" }),
4576
+ "Agent"
4577
+ ]
4578
+ }
4579
+ );
4580
+ }
4581
+ var PRESENCE_WORDS = {
4582
+ connected: "Online",
4583
+ connecting: "Connecting",
4584
+ disconnected: "Offline",
4585
+ error: "Connection problem",
4586
+ hidden: null
4587
+ };
4588
+ function PresenceLabel({
4589
+ status,
4590
+ className
4591
+ }) {
4592
+ if (!status) return null;
4593
+ const word = PRESENCE_WORDS[status];
4594
+ if (!word) return null;
4595
+ const online = status === "connected";
4596
+ return /* @__PURE__ */ jsxs(
4597
+ "span",
4598
+ {
4599
+ "data-testid": "presence-label",
4600
+ className: cn("inline-flex shrink-0 items-center gap-1 text-xs", className),
4601
+ children: [
4602
+ /* @__PURE__ */ jsx(
4603
+ "span",
4604
+ {
4605
+ className: cn(
4606
+ "size-1.5 rounded-full",
4607
+ online ? "bg-status-online" : "bg-muted-foreground/50"
4608
+ ),
4609
+ "aria-hidden": "true"
4610
+ }
4611
+ ),
4612
+ /* @__PURE__ */ jsx("span", { className: online ? "font-medium text-status-online" : "text-muted-foreground", children: word })
4613
+ ]
4614
+ }
4615
+ );
4616
+ }
4558
4617
  var PACKAGE_BADGE_VARIANTS = [
4559
4618
  "default",
4560
4619
  "accent",
@@ -5174,6 +5233,9 @@ function userDisplayName(user) {
5174
5233
  const name = [user.given_name, user.family_name].filter(Boolean).join(" ").trim();
5175
5234
  return name || user.email?.split("@")[0] || "Unknown";
5176
5235
  }
5236
+ function isAgentUser(user) {
5237
+ return user.external_id.startsWith("agt-");
5238
+ }
5177
5239
  var RELATIVE = new Intl.RelativeTimeFormat(void 0, { numeric: "auto" });
5178
5240
  var DIVISIONS = [
5179
5241
  { amount: 60, unit: "seconds" },
@@ -5422,101 +5484,235 @@ function useDirectMessages(options) {
5422
5484
  markRead: (messageIds) => markReadMutation.mutateAsync(messageIds)
5423
5485
  };
5424
5486
  }
5425
- function DmAvatar({ user, className }) {
5426
- const name = userDisplayName(user);
5427
- const tint = getEntityColorStyles(user.external_id);
5428
- return /* @__PURE__ */ jsxs(Avatar, { className: cn("size-10", className), children: [
5429
- user.picture ? /* @__PURE__ */ jsx(AvatarImage, { src: user.picture, alt: name }) : null,
5430
- /* @__PURE__ */ jsx(AvatarFallback, { style: tint, className: "text-xs font-semibold", children: userInitials(user) })
5431
- ] });
5487
+ function DmAvatar({ user, className, size = "lg" }) {
5488
+ const presence = useArbiWsStore((s) => s.presence[user.external_id]);
5489
+ const displayStatus = presence === void 0 ? void 0 : presence === "online" ? "connected" : "disconnected";
5490
+ return /* @__PURE__ */ jsx(
5491
+ UserEntity,
5492
+ {
5493
+ variant: "icon",
5494
+ size,
5495
+ className,
5496
+ interactive: false,
5497
+ showTooltip: false,
5498
+ initials: userInitials(user),
5499
+ displayName: userDisplayName(user),
5500
+ picture: user.picture,
5501
+ avatarStyle: getEntityColorStyles(user.external_id),
5502
+ isAgent: isAgentUser(user),
5503
+ displayStatus
5504
+ }
5505
+ );
5432
5506
  }
5433
5507
  function ConversationList({
5434
5508
  conversations,
5435
5509
  selectedPeerId,
5436
5510
  onSelect,
5437
5511
  classNames,
5438
- emptyState
5512
+ emptyState,
5513
+ header,
5514
+ className
5439
5515
  }) {
5440
5516
  return /* @__PURE__ */ jsxs(
5441
5517
  "aside",
5442
5518
  {
5443
- className: "flex min-h-0 flex-col border-b border-border md:w-80 md:shrink-0 md:border-b-0 md:border-r",
5519
+ className: cn(
5520
+ "flex min-h-0 flex-col border-b border-border md:w-80 md:shrink-0 md:border-b-0 md:border-r",
5521
+ className
5522
+ ),
5444
5523
  "data-testid": "arbi-dm-list",
5445
5524
  children: [
5446
- /* @__PURE__ */ jsxs("div", { className: "border-b border-border px-4 py-3", children: [
5525
+ header === void 0 ? /* @__PURE__ */ jsxs("div", { className: "border-b border-border px-4 py-3", children: [
5447
5526
  /* @__PURE__ */ jsx("p", { className: "text-sm font-semibold text-foreground", children: "Conversations" }),
5448
5527
  /* @__PURE__ */ jsxs("p", { className: "text-xs text-muted-foreground", children: [
5449
5528
  conversations.length,
5450
5529
  " ",
5451
5530
  conversations.length === 1 ? "colleague" : "colleagues"
5452
5531
  ] })
5453
- ] }),
5454
- /* @__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) => {
5532
+ ] }) : header,
5533
+ /* @__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) => {
5455
5534
  const { peer, lastMessage, unreadCount } = c;
5535
+ const newSection = c.sectionLabel && c.sectionLabel !== conversations[i - 1]?.sectionLabel;
5456
5536
  const active = peer.external_id === selectedPeerId;
5457
- const preview = lastMessage ? `${lastMessage.isMine ? "You: " : ""}${lastMessage.body}` : "No messages yet \u2014 say hello";
5458
- return /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(
5459
- "button",
5460
- {
5461
- type: "button",
5462
- onClick: () => onSelect(peer.external_id),
5463
- "data-testid": `arbi-dm-conversation-${peer.external_id}`,
5464
- className: cn(
5465
- "flex w-full items-start gap-3 border-b border-border/60 px-4 py-3 text-left transition-colors",
5466
- active ? "bg-accent" : "hover:bg-accent/60"
5467
- ),
5468
- children: [
5469
- /* @__PURE__ */ jsx(DmAvatar, { user: peer }),
5470
- /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
5471
- /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
5472
- /* @__PURE__ */ jsx("span", { className: "truncate text-sm font-semibold text-foreground", children: userDisplayName(peer) }),
5473
- /* @__PURE__ */ jsx("span", { className: "shrink-0 text-[11px] text-muted-foreground", children: lastMessage ? formatRelativeTime(lastMessage.createdAt) : "" })
5474
- ] }),
5475
- /* @__PURE__ */ jsxs("div", { className: "mt-1 flex items-center gap-2", children: [
5476
- /* @__PURE__ */ jsx("p", { className: "min-w-0 flex-1 truncate text-xs text-muted-foreground", children: preview }),
5477
- unreadCount > 0 ? /* @__PURE__ */ jsx(Badge, { className: cn("px-1.5 py-0 text-[10px]", classNames?.unreadBadge), children: unreadCount }) : null
5478
- ] })
5479
- ] })
5480
- ]
5481
- }
5482
- ) }, peer.external_id);
5537
+ const preview = lastMessage?.body ?? "No messages yet \u2014 say hello";
5538
+ const unread = unreadCount > 0;
5539
+ const body = /* @__PURE__ */ jsxs(Fragment, { children: [
5540
+ c.leading ?? /* @__PURE__ */ jsx(DmAvatar, { user: peer }),
5541
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
5542
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
5543
+ /* @__PURE__ */ jsxs("span", { className: "flex min-w-0 items-center gap-1.5", children: [
5544
+ /* @__PURE__ */ jsx(
5545
+ "span",
5546
+ {
5547
+ className: cn(
5548
+ "truncate text-sm text-foreground",
5549
+ unread ? "font-bold" : "font-semibold"
5550
+ ),
5551
+ children: userDisplayName(peer)
5552
+ }
5553
+ ),
5554
+ c.badge ?? (isAgentUser(peer) ? /* @__PURE__ */ jsx(AgentBadge, {}) : null)
5555
+ ] }),
5556
+ c.statusLabel ? /* @__PURE__ */ jsx(
5557
+ Badge,
5558
+ {
5559
+ variant: "outline",
5560
+ className: "shrink-0 rounded-full px-2 py-0 text-[10px] font-medium text-muted-foreground",
5561
+ children: c.statusLabel
5562
+ }
5563
+ ) : unreadCount > 0 ? (
5564
+ // Quiet by default: a filled brand pill with a shadow
5565
+ // shouted louder than the message it was counting.
5566
+ // Enough to catch the eye scanning the list, no more.
5567
+ /* @__PURE__ */ jsx(
5568
+ Badge,
5569
+ {
5570
+ variant: "accent",
5571
+ className: cn(
5572
+ "min-w-[1.125rem] justify-center rounded-full px-1 py-0 text-[10px] font-medium leading-[1.125rem] shadow-none",
5573
+ classNames?.unreadBadge
5574
+ ),
5575
+ children: unreadCount
5576
+ }
5577
+ )
5578
+ ) : null
5579
+ ] }),
5580
+ /* @__PURE__ */ jsxs("div", { className: "mt-1 flex items-center gap-1.5", children: [
5581
+ lastMessage?.isMine ? lastMessage.read ? /* @__PURE__ */ jsx(
5582
+ CheckCheck,
5583
+ {
5584
+ className: "size-3.5 shrink-0 text-ai-accent",
5585
+ "aria-label": "Read"
5586
+ }
5587
+ ) : /* @__PURE__ */ jsx(
5588
+ Check,
5589
+ {
5590
+ className: "size-3.5 shrink-0 text-muted-foreground",
5591
+ "aria-label": "Sent"
5592
+ }
5593
+ ) : null,
5594
+ /* @__PURE__ */ jsx(
5595
+ "p",
5596
+ {
5597
+ className: cn(
5598
+ "min-w-0 flex-1 truncate text-xs",
5599
+ unread ? "font-medium text-foreground" : "text-muted-foreground"
5600
+ ),
5601
+ children: c.subtitle ?? preview
5602
+ }
5603
+ ),
5604
+ /* @__PURE__ */ jsx("span", { className: "shrink-0 text-[11px] text-muted-foreground", children: lastMessage ? formatRelativeTime(lastMessage.createdAt) : "" })
5605
+ ] })
5606
+ ] })
5607
+ ] });
5608
+ const rowClass = cn(
5609
+ // Each row is its own opaque surface. Left transparent it takes
5610
+ // the panel's colour, and the chips stop reading as cards at all
5611
+ // — which is the whole point of them.
5612
+ "flex w-full items-start gap-3 border-b border-border/60 bg-card px-4 py-3 text-left transition-colors",
5613
+ c.disabled ? "cursor-default" : active ? "bg-ai-accent-soft" : "hover:bg-accent/40"
5614
+ );
5615
+ return /* @__PURE__ */ jsxs("li", { children: [
5616
+ newSection && /* @__PURE__ */ jsx(
5617
+ "p",
5618
+ {
5619
+ className: "bg-muted/40 px-4 py-1.5 text-[11px] font-medium uppercase tracking-wide text-muted-foreground",
5620
+ "data-testid": "arbi-dm-section",
5621
+ children: c.sectionLabel
5622
+ }
5623
+ ),
5624
+ c.disabled ? /* @__PURE__ */ jsxs(
5625
+ "div",
5626
+ {
5627
+ "data-testid": `arbi-dm-conversation-${peer.external_id}`,
5628
+ className: rowClass,
5629
+ children: [
5630
+ body,
5631
+ c.trailing
5632
+ ]
5633
+ }
5634
+ ) : /* @__PURE__ */ jsx(
5635
+ "button",
5636
+ {
5637
+ type: "button",
5638
+ onClick: () => onSelect(peer.external_id),
5639
+ "data-testid": `arbi-dm-conversation-${peer.external_id}`,
5640
+ className: rowClass,
5641
+ children: body
5642
+ }
5643
+ )
5644
+ ] }, peer.external_id);
5483
5645
  }) }) })
5484
5646
  ]
5485
5647
  }
5486
5648
  );
5487
5649
  }
5488
- function MessageBubble2({ message, classNames }) {
5489
- const { isMine } = message;
5490
- const who = isMine ? "You" : userDisplayName(message.sender);
5491
- return /* @__PURE__ */ jsxs(
5492
- "div",
5650
+
5651
+ // src/directmessages/grouping.ts
5652
+ var RUN_WINDOW_MS = 2 * 60 * 1e3;
5653
+ function dayKey(iso) {
5654
+ const d = new Date(iso);
5655
+ if (Number.isNaN(d.getTime())) return iso;
5656
+ return `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}`;
5657
+ }
5658
+ function annotateThread(messages, accessors, runWindowMs = RUN_WINDOW_MS) {
5659
+ const { senderId, createdAt } = accessors;
5660
+ return messages.map((message, i) => {
5661
+ const next = messages[i + 1];
5662
+ const prev = messages[i - 1];
5663
+ const day = dayKey(createdAt(message));
5664
+ const continuesIntoNext = !!next && senderId(next) === senderId(message) && dayKey(createdAt(next)) === day && Date.parse(createdAt(next)) - Date.parse(createdAt(message)) < runWindowMs;
5665
+ return {
5666
+ message,
5667
+ isLastOfRun: !continuesIntoNext,
5668
+ isFirstOfDay: !prev || dayKey(createdAt(prev)) !== day
5669
+ };
5670
+ });
5671
+ }
5672
+ function DateSeparator({ children }) {
5673
+ 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 }) });
5674
+ }
5675
+ function MessageBubble2({
5676
+ message,
5677
+ classNames,
5678
+ isLastOfRun = true,
5679
+ onDelete,
5680
+ deleted
5681
+ }) {
5682
+ return /* @__PURE__ */ jsx(
5683
+ ChatBubble,
5493
5684
  {
5494
5685
  "data-testid": "arbi-dm-message",
5495
- className: cn("flex flex-col gap-1", isMine ? "items-end" : "items-start"),
5496
- children: [
5497
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 px-1", children: [
5498
- /* @__PURE__ */ jsx("span", { className: "text-[11px] font-medium text-foreground", children: who }),
5499
- /* @__PURE__ */ jsx("span", { className: "text-[11px] text-muted-foreground", children: formatRelativeTime(message.createdAt) })
5500
- ] }),
5501
- /* @__PURE__ */ jsx(
5502
- "div",
5503
- {
5504
- className: cn(
5505
- "max-w-[80%] rounded-2xl px-3.5 py-2 text-sm shadow-sm",
5506
- isMine ? cn("rounded-br-sm bg-accent text-accent-foreground", classNames?.ownBubble) : cn(
5507
- "rounded-bl-sm border border-border bg-card text-card-foreground",
5508
- classNames?.peerBubble
5509
- )
5510
- ),
5511
- children: message.body
5512
- }
5513
- )
5514
- ]
5686
+ message: message.body,
5687
+ timestamp: message.createdAt,
5688
+ isSent: message.isMine,
5689
+ read: message.read,
5690
+ deleted,
5691
+ onDelete,
5692
+ isLastOfRun,
5693
+ senderName: message.isMine ? "You" : userDisplayName(message.sender),
5694
+ classNames,
5695
+ formatTimestamp: formatRelativeTime
5515
5696
  }
5516
5697
  );
5517
5698
  }
5518
- function MessageThread({ conversation, classNames, emptyState }) {
5699
+ var THREAD_ACCESSORS = {
5700
+ senderId: (m) => m.sender.external_id,
5701
+ createdAt: (m) => m.createdAt
5702
+ };
5703
+ function MessageThread({
5704
+ conversation,
5705
+ classNames,
5706
+ emptyState,
5707
+ formatDay,
5708
+ onDeleteMessage,
5709
+ deletedIds
5710
+ }) {
5519
5711
  const bottomRef = useRef(null);
5712
+ const items = useMemo(
5713
+ () => annotateThread(conversation?.messages ?? [], THREAD_ACCESSORS),
5714
+ [conversation?.messages]
5715
+ );
5520
5716
  useEffect(() => {
5521
5717
  bottomRef.current?.scrollIntoView({ block: "end" });
5522
5718
  }, [conversation?.peer.external_id, conversation?.messages.length]);
@@ -5529,7 +5725,7 @@ function MessageThread({ conversation, classNames, emptyState }) {
5529
5725
  ] })
5530
5726
  ] }) });
5531
5727
  }
5532
- const { peer, messages } = conversation;
5728
+ const { peer } = conversation;
5533
5729
  return /* @__PURE__ */ jsxs(Fragment, { children: [
5534
5730
  /* @__PURE__ */ jsxs("header", { className: "flex items-center gap-3 border-b border-border px-4 py-3", children: [
5535
5731
  /* @__PURE__ */ jsx(DmAvatar, { user: peer, className: "size-9" }),
@@ -5538,20 +5734,42 @@ function MessageThread({ conversation, classNames, emptyState }) {
5538
5734
  /* @__PURE__ */ jsx("p", { className: "truncate text-xs text-muted-foreground", children: peer.email })
5539
5735
  ] })
5540
5736
  ] }),
5541
- /* @__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: [
5542
- messages.map((m) => /* @__PURE__ */ jsx(MessageBubble2, { message: m, classNames }, m.externalId)),
5737
+ /* @__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: [
5738
+ items.map(({ message: m, isLastOfRun, isFirstOfDay }) => /* @__PURE__ */ jsxs(Fragment$1, { children: [
5739
+ isFirstOfDay && formatDay && /* @__PURE__ */ jsx(DateSeparator, { children: formatDay(m.createdAt) }),
5740
+ /* @__PURE__ */ jsx(
5741
+ MessageBubble2,
5742
+ {
5743
+ message: m,
5744
+ classNames,
5745
+ isLastOfRun,
5746
+ deleted: deletedIds?.has(m.externalId),
5747
+ onDelete: onDeleteMessage ? () => onDeleteMessage(m) : void 0
5748
+ }
5749
+ )
5750
+ ] }, m.externalId)),
5543
5751
  /* @__PURE__ */ jsx("div", { ref: bottomRef })
5544
5752
  ] }) })
5545
5753
  ] });
5546
5754
  }
5547
- function DmComposer({ placeholder, disabled, onSend, error, classNames }) {
5755
+ function DmComposer({
5756
+ placeholder,
5757
+ disabled,
5758
+ busy,
5759
+ onSend,
5760
+ error,
5761
+ children,
5762
+ classNames
5763
+ }) {
5548
5764
  const [draft, setDraft] = useState("");
5765
+ const inputRef = useRef(null);
5549
5766
  const submit = async () => {
5550
5767
  const text = draft.trim();
5551
- if (!text || disabled) return;
5768
+ if (!text || disabled || busy) return;
5552
5769
  setDraft("");
5553
5770
  try {
5554
5771
  await onSend(text);
5772
+ inputRef.current?.focus();
5555
5773
  } catch {
5556
5774
  setDraft(text);
5557
5775
  }
@@ -5563,10 +5781,12 @@ function DmComposer({ placeholder, disabled, onSend, error, classNames }) {
5563
5781
  }
5564
5782
  };
5565
5783
  return /* @__PURE__ */ jsxs("div", { className: "border-t border-border p-3", children: [
5784
+ children,
5566
5785
  /* @__PURE__ */ jsxs("div", { className: "flex items-end gap-2", children: [
5567
5786
  /* @__PURE__ */ jsx(
5568
5787
  Textarea,
5569
5788
  {
5789
+ ref: inputRef,
5570
5790
  value: draft,
5571
5791
  onChange: (e) => setDraft(e.target.value),
5572
5792
  onKeyDown,
@@ -5582,11 +5802,12 @@ function DmComposer({ placeholder, disabled, onSend, error, classNames }) {
5582
5802
  {
5583
5803
  type: "button",
5584
5804
  onClick: () => void submit(),
5585
- disabled: disabled || !draft.trim(),
5805
+ disabled: disabled || busy || !draft.trim(),
5586
5806
  className: cn(classNames?.sendButton),
5587
5807
  "data-testid": "arbi-dm-send",
5808
+ "aria-label": "Send message",
5588
5809
  children: [
5589
- /* @__PURE__ */ jsx(Send, { className: "size-4" }),
5810
+ busy ? /* @__PURE__ */ jsx(Loader2, { className: "size-4 animate-spin" }) : /* @__PURE__ */ jsx(Send, { className: "size-4" }),
5590
5811
  " Send"
5591
5812
  ]
5592
5813
  }
@@ -6790,6 +7011,6 @@ function DocumentGallery({
6790
7011
  );
6791
7012
  }
6792
7013
 
6793
- 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, PassageCard, PdfIcon, ProjectEntity, ProviderIcon, RagDot, RelevanceDot, 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 };
7014
+ export { ActivityFeed, AgentBadge, 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, PresenceLabel, 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 };
6794
7015
  //# sourceMappingURL=index.js.map
6795
7016
  //# sourceMappingURL=index.js.map