@arbidocs/react 0.3.116 → 0.3.118

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
@@ -4,7 +4,7 @@ import { Arbi, connectWithReconnect, resolveCitations, summarizeCitations } from
4
4
  export { Arbi, ArbiError } from '@arbidocs/sdk/browser';
5
5
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
6
6
  import { useQuery, useMutation, useQueries, QueryClient, QueryClientProvider, useQueryClient } from '@tanstack/react-query';
7
- import { Trash2, CheckCheck, Check, Circle, X, ChevronRight, ChevronDown, ChevronUp, Search, MoreVertical, MessageCircleMore, MessageSquareLock, Info, FileQuestion, BookOpen, Upload, LogOut, LayoutGrid, Bell, MessageSquare, CircleUserRound, Wrench, Package, ClipboardList, UserPlus, Contact, Settings2, Users, User, StickyNote, FolderPlus, Hash, EyeOff, Eye, CaptionsOff, FolderOpen, MessageSquareMore, MessageSquarePlus, MessageSquareText, MessageSquareOff, MessagesSquare, Columns3Cog, SquarePlus, SquareM, ChevronsDown, Bot, Calendar, Folder, List, SquareCheckBig, Loader2, AlertTriangle, ShieldCheck, Copy, Sparkles, FileText, GitCompareArrows, Download, Image, CornerDownLeft, Send, Tags, Crown, Activity, Gauge, Gift, PartyPopper, UserCheck, FileX2, FileCheck2, Pencil, SquareArrowOutUpRight } from 'lucide-react';
7
+ import { Trash2, CheckCheck, Check, Circle, X, ChevronRight, ChevronDown, ChevronUp, Search, MoreVertical, MessageCircleMore, MessageSquareLock, Info, FileQuestion, BookOpen, Upload, LogOut, LayoutGrid, Bell, MessageSquare, CircleUserRound, Wrench, Package, ClipboardList, UserPlus, Contact, Settings2, Users, User, StickyNote, FolderPlus, Hash, EyeOff, Eye, CaptionsOff, FolderOpen, MessageSquareMore, MessageSquarePlus, MessageSquareText, MessageSquareOff, MessagesSquare, Columns3Cog, SquarePlus, SquareM, ChevronsDown, Bot, Calendar, Folder, List, SquareCheckBig, Loader2, AlertTriangle, ShieldCheck, Copy, Sparkles, FileText, GitCompareArrows, Download, Image as Image$1, CornerDownLeft, Send, Tags, Crown, Activity, Gauge, Gift, PartyPopper, UserCheck, FileX2, FileCheck2, Pencil, SquareArrowOutUpRight, XCircle, CheckCircle2, ArrowRight } from 'lucide-react';
8
8
  import { clsx } from 'clsx';
9
9
  import { twMerge } from 'tailwind-merge';
10
10
  import { isMessageType } from '@arbidocs/client';
@@ -36,6 +36,9 @@ import ReactMarkdown from 'react-markdown';
36
36
  import remarkGfm from 'remark-gfm';
37
37
  import rehypeRaw from 'rehype-raw';
38
38
  import { AnimatePresence, motion } from 'framer-motion';
39
+ import { Toaster as Toaster$1, toast } from 'sonner';
40
+ export { toast } from 'sonner';
41
+ import Cropper from 'react-easy-crop';
39
42
  import { AgGridReact } from 'ag-grid-react';
40
43
  import { ModuleRegistry, AllCommunityModule } from 'ag-grid-community';
41
44
 
@@ -3224,7 +3227,7 @@ function MessageArtifactCard({
3224
3227
  }) {
3225
3228
  const { docExtId, title, isComplete, mode } = artifact;
3226
3229
  const isImage = mode === "image";
3227
- const Icon2 = isImage ? Image : FileText;
3230
+ const Icon2 = isImage ? Image$1 : FileText;
3228
3231
  const statusText = isImage ? isComplete ? "Image ready" : "Generating\u2026" : isComplete ? "Draft ready" : "Drafting\u2026";
3229
3232
  return /* @__PURE__ */ jsxs(
3230
3233
  Card,
@@ -5738,6 +5741,962 @@ function ActivityFeed({
5738
5741
  );
5739
5742
  }) });
5740
5743
  }
5744
+ var seq = 0;
5745
+ var uid = () => `n${Date.now().toString(36)}${(seq++).toString(36)}`;
5746
+ var useNotify = create((set) => ({
5747
+ notifications: [],
5748
+ markRead: (id) => set((s) => ({
5749
+ notifications: s.notifications.map((n) => n.id === id ? { ...n, read: true } : n)
5750
+ })),
5751
+ markAllRead: () => set((s) => ({ notifications: s.notifications.map((n) => ({ ...n, read: true })) })),
5752
+ removeNotification: (id) => set((s) => ({ notifications: s.notifications.filter((n) => n.id !== id) })),
5753
+ clearNotifications: () => set({ notifications: [] }),
5754
+ seed: (items) => set({ notifications: items }),
5755
+ record: (note) => set((s) => ({ notifications: [note, ...s.notifications].slice(0, 50) }))
5756
+ }));
5757
+ function make(variant) {
5758
+ return (title, opts = {}) => {
5759
+ toast[variant](title, {
5760
+ description: opts.description,
5761
+ duration: opts.duration,
5762
+ action: opts.action,
5763
+ icon: opts.icon
5764
+ });
5765
+ const id = uid();
5766
+ if (opts.record !== false) {
5767
+ useNotify.getState().record({
5768
+ id,
5769
+ title,
5770
+ description: opts.description,
5771
+ variant,
5772
+ ts: Date.now(),
5773
+ read: false,
5774
+ href: opts.href
5775
+ });
5776
+ }
5777
+ return id;
5778
+ };
5779
+ }
5780
+ var notify = {
5781
+ success: make("success"),
5782
+ error: make("error"),
5783
+ info: make("info"),
5784
+ warning: make("warning")
5785
+ };
5786
+ function seedNotifications(items) {
5787
+ useNotify.getState().seed(items);
5788
+ }
5789
+ var selectUnread = (s) => s.notifications.filter((n) => !n.read).length;
5790
+ var DEFAULT_NOTIFY_TONE = {
5791
+ success: "text-green-600",
5792
+ error: "text-destructive",
5793
+ warning: "text-amber-500",
5794
+ info: "text-blue-500"
5795
+ };
5796
+
5797
+ // src/directmessages/utils.ts
5798
+ function userInitials(user) {
5799
+ const parts = [user.given_name, user.family_name].filter(Boolean);
5800
+ if (parts.length) {
5801
+ return parts.map((p) => p[0]?.toUpperCase() ?? "").join("").slice(0, 2);
5802
+ }
5803
+ const local = user.email?.split("@")[0] ?? "";
5804
+ return local.slice(0, 2).toUpperCase() || "?";
5805
+ }
5806
+ function userDisplayName(user) {
5807
+ const name = [user.given_name, user.family_name].filter(Boolean).join(" ").trim();
5808
+ return name || user.email?.split("@")[0] || "Unknown";
5809
+ }
5810
+ var RELATIVE = new Intl.RelativeTimeFormat(void 0, { numeric: "auto" });
5811
+ var DIVISIONS = [
5812
+ { amount: 60, unit: "seconds" },
5813
+ { amount: 60, unit: "minutes" },
5814
+ { amount: 24, unit: "hours" },
5815
+ { amount: 7, unit: "days" },
5816
+ { amount: 4.34524, unit: "weeks" },
5817
+ { amount: 12, unit: "months" },
5818
+ { amount: Number.POSITIVE_INFINITY, unit: "years" }
5819
+ ];
5820
+ function formatRelativeTime(iso) {
5821
+ const then = Date.parse(iso);
5822
+ if (Number.isNaN(then)) return "";
5823
+ let duration = (then - Date.now()) / 1e3;
5824
+ if (Math.abs(duration) < 45) return "just now";
5825
+ for (const division of DIVISIONS) {
5826
+ if (Math.abs(duration) < division.amount) {
5827
+ return RELATIVE.format(Math.round(duration), division.unit);
5828
+ }
5829
+ duration /= division.amount;
5830
+ }
5831
+ return "";
5832
+ }
5833
+ var GLYPH = {
5834
+ success: CheckCircle2,
5835
+ error: XCircle,
5836
+ warning: AlertTriangle,
5837
+ info: Info
5838
+ };
5839
+ function NotificationBell({
5840
+ onNavigate,
5841
+ toneClassNames,
5842
+ emptyText = "You're all caught up.",
5843
+ testId = "notifications"
5844
+ }) {
5845
+ const notifications = useNotify((s) => s.notifications);
5846
+ const unread = useNotify(selectUnread);
5847
+ const markAllRead = useNotify((s) => s.markAllRead);
5848
+ const markRead = useNotify((s) => s.markRead);
5849
+ const tone = (v) => toneClassNames?.[v] ?? DEFAULT_NOTIFY_TONE[v];
5850
+ return /* @__PURE__ */ jsxs(DropdownMenu, { children: [
5851
+ /* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
5852
+ "button",
5853
+ {
5854
+ className: "relative flex size-9 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",
5855
+ "data-testid": testId,
5856
+ "aria-label": `Notifications${unread ? ` (${unread} unread)` : ""}`,
5857
+ children: [
5858
+ /* @__PURE__ */ jsx(Bell, { className: "size-5" }),
5859
+ unread > 0 && /* @__PURE__ */ jsx(
5860
+ "span",
5861
+ {
5862
+ className: "absolute -right-0.5 -top-0.5 flex min-w-4 items-center justify-center rounded-full bg-destructive px-1 text-[10px] font-semibold leading-4 text-white",
5863
+ "data-testid": `${testId}-badge`,
5864
+ children: unread > 9 ? "9+" : unread
5865
+ }
5866
+ )
5867
+ ]
5868
+ }
5869
+ ) }),
5870
+ /* @__PURE__ */ jsxs(DropdownMenuContent, { align: "end", className: "w-[360px] p-0", "data-testid": `${testId}-panel`, children: [
5871
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between border-b border-border px-3.5 py-2.5", children: [
5872
+ /* @__PURE__ */ jsx("p", { className: "text-sm font-semibold text-foreground", children: "Notifications" }),
5873
+ unread > 0 && /* @__PURE__ */ jsxs(
5874
+ "button",
5875
+ {
5876
+ onClick: markAllRead,
5877
+ className: "flex items-center gap-1 text-xs font-medium text-primary transition-colors hover:opacity-80",
5878
+ "data-testid": `${testId}-mark-all`,
5879
+ children: [
5880
+ /* @__PURE__ */ jsx(CheckCheck, { className: "size-3.5" }),
5881
+ " Mark all read"
5882
+ ]
5883
+ }
5884
+ )
5885
+ ] }),
5886
+ notifications.length === 0 ? /* @__PURE__ */ jsx("div", { className: "px-3.5 py-10 text-center text-sm text-muted-foreground", children: emptyText }) : /* @__PURE__ */ jsx(ScrollArea, { className: "max-h-[380px]", children: /* @__PURE__ */ jsx("ul", { "data-testid": `${testId}-list`, children: notifications.map((n) => {
5887
+ const Glyph = GLYPH[n.variant];
5888
+ return /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(
5889
+ "button",
5890
+ {
5891
+ onClick: () => {
5892
+ markRead(n.id);
5893
+ if (n.href) onNavigate?.(n.href);
5894
+ },
5895
+ className: cn(
5896
+ "flex w-full items-start gap-3 border-b border-border/60 px-3.5 py-3 text-left transition-colors hover:bg-accent",
5897
+ !n.read && "bg-accent/40"
5898
+ ),
5899
+ "data-testid": `${testId}-item`,
5900
+ children: [
5901
+ /* @__PURE__ */ jsx(Glyph, { className: cn("mt-0.5 size-4 shrink-0", tone(n.variant)) }),
5902
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
5903
+ /* @__PURE__ */ jsx("p", { className: "text-sm font-medium leading-snug text-foreground", children: n.title }),
5904
+ n.description && /* @__PURE__ */ jsx("p", { className: "mt-0.5 line-clamp-2 text-xs leading-relaxed text-muted-foreground", children: n.description }),
5905
+ /* @__PURE__ */ jsx("p", { className: "mt-1 text-[11px] text-muted-foreground/80", children: formatRelativeTime(new Date(n.ts).toISOString()) })
5906
+ ] }),
5907
+ !n.read && /* @__PURE__ */ jsx("span", { className: "mt-1.5 size-2 shrink-0 rounded-full bg-primary" })
5908
+ ]
5909
+ }
5910
+ ) }, n.id);
5911
+ }) }) })
5912
+ ] })
5913
+ ] });
5914
+ }
5915
+ var DEFAULT_TOAST_OPTIONS = {
5916
+ classNames: {
5917
+ toast: "group toast group-[.toaster]:bg-card group-[.toaster]:text-foreground group-[.toaster]:border group-[.toaster]:border-border group-[.toaster]:shadow-lg group-[.toaster]:rounded-lg",
5918
+ description: "group-[.toast]:text-muted-foreground",
5919
+ actionButton: "group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",
5920
+ cancelButton: "group-[.toast]:bg-muted group-[.toast]:text-muted-foreground"
5921
+ }
5922
+ };
5923
+ function Toaster({ toastOptions, ...props }) {
5924
+ return /* @__PURE__ */ jsx(
5925
+ Toaster$1,
5926
+ {
5927
+ className: "toaster group",
5928
+ toastOptions: toastOptions ?? DEFAULT_TOAST_OPTIONS,
5929
+ ...props
5930
+ }
5931
+ );
5932
+ }
5933
+ var DM_QUERY_KEY = ["arbi", "directMessages"];
5934
+ function groupConversations(notifications, myExtId) {
5935
+ const messagesByPeer = /* @__PURE__ */ new Map();
5936
+ const peers = /* @__PURE__ */ new Map();
5937
+ for (const n of notifications) {
5938
+ if (n.type !== "user_message") continue;
5939
+ if (n.sender.external_id === n.recipient.external_id) continue;
5940
+ const isMine = n.sender.external_id === myExtId;
5941
+ const peer = isMine ? n.recipient : n.sender;
5942
+ if (!peer?.external_id) continue;
5943
+ const message = {
5944
+ externalId: n.external_id,
5945
+ body: n.content ?? "",
5946
+ createdAt: n.created_at,
5947
+ isMine,
5948
+ read: n.read,
5949
+ sender: n.sender,
5950
+ recipient: n.recipient
5951
+ };
5952
+ if (!messagesByPeer.has(peer.external_id)) {
5953
+ messagesByPeer.set(peer.external_id, []);
5954
+ peers.set(peer.external_id, peer);
5955
+ }
5956
+ messagesByPeer.get(peer.external_id).push(message);
5957
+ }
5958
+ const conversations = [];
5959
+ for (const [peerId, messages] of messagesByPeer) {
5960
+ messages.sort((a, b) => a.createdAt.localeCompare(b.createdAt));
5961
+ const unreadCount = messages.filter((m) => !m.isMine && !m.read).length;
5962
+ conversations.push({
5963
+ peer: peers.get(peerId),
5964
+ messages,
5965
+ lastMessage: messages[messages.length - 1],
5966
+ unreadCount
5967
+ });
5968
+ }
5969
+ conversations.sort((a, b) => b.lastMessage.createdAt.localeCompare(a.lastMessage.createdAt));
5970
+ return conversations;
5971
+ }
5972
+ function useDirectMessages(options) {
5973
+ const arbi = useArbi();
5974
+ const queryClient = useQueryClient();
5975
+ const enabled = options?.enabled ?? arbi.isLoggedIn;
5976
+ const query = useQuery({
5977
+ queryKey: DM_QUERY_KEY,
5978
+ queryFn: () => arbi.dm.list(),
5979
+ enabled
5980
+ });
5981
+ useArbiWsMessage("user_message", () => {
5982
+ queryClient.invalidateQueries({ queryKey: DM_QUERY_KEY });
5983
+ });
5984
+ const myExtId = useMemo(() => {
5985
+ try {
5986
+ return arbi.user.identity()?.externalId ?? null;
5987
+ } catch {
5988
+ return null;
5989
+ }
5990
+ }, [arbi, query.data]);
5991
+ const conversations = useMemo(
5992
+ () => groupConversations(query.data ?? [], myExtId),
5993
+ [query.data, myExtId]
5994
+ );
5995
+ const invalidate = () => queryClient.invalidateQueries({ queryKey: DM_QUERY_KEY });
5996
+ const sendMutation = useMutation({
5997
+ mutationFn: (vars) => arbi.dm.sendTo(vars.recipientExtId, vars.recipientPublicKey, vars.text),
5998
+ onSuccess: invalidate
5999
+ });
6000
+ const sendToMutation = useMutation({
6001
+ mutationFn: (vars) => arbi.dm.send(vars.recipient, vars.text),
6002
+ onSuccess: invalidate
6003
+ });
6004
+ const markReadMutation = useMutation({
6005
+ mutationFn: (messageIds) => arbi.dm.markRead(messageIds),
6006
+ onSuccess: invalidate
6007
+ });
6008
+ return {
6009
+ conversations,
6010
+ myExtId,
6011
+ isLoading: query.isLoading && enabled,
6012
+ isError: query.isError,
6013
+ error: query.error,
6014
+ refetch: () => query.refetch(),
6015
+ sendMessage: (recipientExtId, recipientPublicKey, text) => sendMutation.mutateAsync({ recipientExtId, recipientPublicKey, text }),
6016
+ sendMessageTo: (recipient, text) => sendToMutation.mutateAsync({ recipient, text }),
6017
+ isSending: sendMutation.isPending || sendToMutation.isPending,
6018
+ markRead: (messageIds) => markReadMutation.mutateAsync(messageIds)
6019
+ };
6020
+ }
6021
+ function DmAvatar({ user, className }) {
6022
+ const name = userDisplayName(user);
6023
+ const tint = getEntityColorStyles(user.external_id);
6024
+ return /* @__PURE__ */ jsxs(Avatar, { className: cn("size-10", className), children: [
6025
+ user.picture ? /* @__PURE__ */ jsx(AvatarImage, { src: user.picture, alt: name }) : null,
6026
+ /* @__PURE__ */ jsx(AvatarFallback, { style: tint, className: "text-xs font-semibold", children: userInitials(user) })
6027
+ ] });
6028
+ }
6029
+ function ConversationList({
6030
+ conversations,
6031
+ selectedPeerId,
6032
+ onSelect,
6033
+ classNames,
6034
+ emptyState
6035
+ }) {
6036
+ return /* @__PURE__ */ jsxs(
6037
+ "aside",
6038
+ {
6039
+ className: "flex min-h-0 flex-col border-b border-border md:w-80 md:shrink-0 md:border-b-0 md:border-r",
6040
+ "data-testid": "arbi-dm-list",
6041
+ children: [
6042
+ /* @__PURE__ */ jsxs("div", { className: "border-b border-border px-4 py-3", children: [
6043
+ /* @__PURE__ */ jsx("p", { className: "text-sm font-semibold text-foreground", children: "Conversations" }),
6044
+ /* @__PURE__ */ jsxs("p", { className: "text-xs text-muted-foreground", children: [
6045
+ conversations.length,
6046
+ " ",
6047
+ conversations.length === 1 ? "colleague" : "colleagues"
6048
+ ] })
6049
+ ] }),
6050
+ /* @__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) => {
6051
+ const { peer, lastMessage, unreadCount } = c;
6052
+ const active = peer.external_id === selectedPeerId;
6053
+ const preview = `${lastMessage.isMine ? "You: " : ""}${lastMessage.body}`;
6054
+ return /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(
6055
+ "button",
6056
+ {
6057
+ type: "button",
6058
+ onClick: () => onSelect(peer.external_id),
6059
+ "data-testid": `arbi-dm-conversation-${peer.external_id}`,
6060
+ className: cn(
6061
+ "flex w-full items-start gap-3 border-b border-border/60 px-4 py-3 text-left transition-colors",
6062
+ active ? "bg-accent" : "hover:bg-accent/60"
6063
+ ),
6064
+ children: [
6065
+ /* @__PURE__ */ jsx(DmAvatar, { user: peer }),
6066
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
6067
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
6068
+ /* @__PURE__ */ jsx("span", { className: "truncate text-sm font-semibold text-foreground", children: userDisplayName(peer) }),
6069
+ /* @__PURE__ */ jsx("span", { className: "shrink-0 text-[11px] text-muted-foreground", children: formatRelativeTime(lastMessage.createdAt) })
6070
+ ] }),
6071
+ /* @__PURE__ */ jsxs("div", { className: "mt-1 flex items-center gap-2", children: [
6072
+ /* @__PURE__ */ jsx("p", { className: "min-w-0 flex-1 truncate text-xs text-muted-foreground", children: preview }),
6073
+ unreadCount > 0 ? /* @__PURE__ */ jsx(Badge, { className: cn("px-1.5 py-0 text-[10px]", classNames?.unreadBadge), children: unreadCount }) : null
6074
+ ] })
6075
+ ] })
6076
+ ]
6077
+ }
6078
+ ) }, peer.external_id);
6079
+ }) }) })
6080
+ ]
6081
+ }
6082
+ );
6083
+ }
6084
+ function MessageBubble2({ message, classNames }) {
6085
+ const { isMine } = message;
6086
+ const who = isMine ? "You" : userDisplayName(message.sender);
6087
+ return /* @__PURE__ */ jsxs(
6088
+ "div",
6089
+ {
6090
+ "data-testid": "arbi-dm-message",
6091
+ className: cn("flex flex-col gap-1", isMine ? "items-end" : "items-start"),
6092
+ children: [
6093
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 px-1", children: [
6094
+ /* @__PURE__ */ jsx("span", { className: "text-[11px] font-medium text-foreground", children: who }),
6095
+ /* @__PURE__ */ jsx("span", { className: "text-[11px] text-muted-foreground", children: formatRelativeTime(message.createdAt) })
6096
+ ] }),
6097
+ /* @__PURE__ */ jsx(
6098
+ "div",
6099
+ {
6100
+ className: cn(
6101
+ "max-w-[80%] rounded-2xl px-3.5 py-2 text-sm shadow-sm",
6102
+ isMine ? cn("rounded-br-sm bg-accent text-accent-foreground", classNames?.ownBubble) : cn(
6103
+ "rounded-bl-sm border border-border bg-card text-card-foreground",
6104
+ classNames?.peerBubble
6105
+ )
6106
+ ),
6107
+ children: message.body
6108
+ }
6109
+ )
6110
+ ]
6111
+ }
6112
+ );
6113
+ }
6114
+ function MessageThread({ conversation, classNames, emptyState }) {
6115
+ const bottomRef = useRef(null);
6116
+ useEffect(() => {
6117
+ bottomRef.current?.scrollIntoView({ block: "end" });
6118
+ }, [conversation?.peer.external_id, conversation?.messages.length]);
6119
+ if (!conversation) {
6120
+ return /* @__PURE__ */ jsx("section", { className: "flex min-h-0 flex-1 flex-col items-center justify-center gap-3 p-8 text-center", children: emptyState ?? /* @__PURE__ */ jsxs(Fragment, { children: [
6121
+ /* @__PURE__ */ jsx("div", { className: "flex size-14 items-center justify-center rounded-full bg-accent", children: /* @__PURE__ */ jsx(MessagesSquare, { className: "size-6 text-muted-foreground" }) }),
6122
+ /* @__PURE__ */ jsxs("div", { children: [
6123
+ /* @__PURE__ */ jsx("p", { className: "text-sm font-semibold text-foreground", children: "No conversation selected" }),
6124
+ /* @__PURE__ */ jsx("p", { className: "mx-auto mt-1 max-w-xs text-xs text-muted-foreground", children: "Choose a colleague from the list to read the thread and send a direct message." })
6125
+ ] })
6126
+ ] }) });
6127
+ }
6128
+ const { peer, messages } = conversation;
6129
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
6130
+ /* @__PURE__ */ jsxs("header", { className: "flex items-center gap-3 border-b border-border px-4 py-3", children: [
6131
+ /* @__PURE__ */ jsx(DmAvatar, { user: peer, className: "size-9" }),
6132
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
6133
+ /* @__PURE__ */ jsx("p", { className: "truncate text-sm font-semibold text-foreground", children: userDisplayName(peer) }),
6134
+ /* @__PURE__ */ jsx("p", { className: "truncate text-xs text-muted-foreground", children: peer.email })
6135
+ ] })
6136
+ ] }),
6137
+ /* @__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: [
6138
+ messages.map((m) => /* @__PURE__ */ jsx(MessageBubble2, { message: m, classNames }, m.externalId)),
6139
+ /* @__PURE__ */ jsx("div", { ref: bottomRef })
6140
+ ] }) })
6141
+ ] });
6142
+ }
6143
+ function DmComposer({ placeholder, disabled, onSend, classNames }) {
6144
+ const [draft, setDraft] = useState("");
6145
+ const submit = () => {
6146
+ const text = draft.trim();
6147
+ if (!text || disabled) return;
6148
+ onSend(text);
6149
+ setDraft("");
6150
+ };
6151
+ const onKeyDown = (e) => {
6152
+ if (e.key === "Enter" && !e.shiftKey) {
6153
+ e.preventDefault();
6154
+ submit();
6155
+ }
6156
+ };
6157
+ return /* @__PURE__ */ jsx("div", { className: "border-t border-border p-3", children: /* @__PURE__ */ jsxs("div", { className: "flex items-end gap-2", children: [
6158
+ /* @__PURE__ */ jsx(
6159
+ Textarea,
6160
+ {
6161
+ value: draft,
6162
+ onChange: (e) => setDraft(e.target.value),
6163
+ onKeyDown,
6164
+ placeholder,
6165
+ rows: 1,
6166
+ disabled,
6167
+ className: "max-h-40 min-h-[44px] resize-none",
6168
+ "data-testid": "arbi-dm-input"
6169
+ }
6170
+ ),
6171
+ /* @__PURE__ */ jsxs(
6172
+ Button,
6173
+ {
6174
+ type: "button",
6175
+ onClick: submit,
6176
+ disabled: disabled || !draft.trim(),
6177
+ className: cn(classNames?.sendButton),
6178
+ "data-testid": "arbi-dm-send",
6179
+ children: [
6180
+ /* @__PURE__ */ jsx(Send, { className: "size-4" }),
6181
+ " Send"
6182
+ ]
6183
+ }
6184
+ )
6185
+ ] }) });
6186
+ }
6187
+ function DirectMessages({
6188
+ className,
6189
+ classNames,
6190
+ emptyThread,
6191
+ emptyList
6192
+ }) {
6193
+ const { conversations, isLoading, sendMessage, markRead } = useDirectMessages();
6194
+ const [selectedPeerId, setSelectedPeerId] = useState(null);
6195
+ const selected = useMemo(
6196
+ () => conversations.find((c) => c.peer.external_id === selectedPeerId) ?? null,
6197
+ [conversations, selectedPeerId]
6198
+ );
6199
+ useEffect(() => {
6200
+ if (!selected || selected.unreadCount === 0) return;
6201
+ const unreadIds = selected.messages.filter((m) => !m.isMine && !m.read).map((m) => m.externalId);
6202
+ if (unreadIds.length) void markRead(unreadIds);
6203
+ }, [selected?.peer.external_id, selected?.unreadCount]);
6204
+ const handleSend = (text) => {
6205
+ if (!selected) return;
6206
+ void sendMessage(selected.peer.external_id, selected.peer.encryption_public_key, text);
6207
+ };
6208
+ return /* @__PURE__ */ jsxs(
6209
+ "div",
6210
+ {
6211
+ "data-testid": "arbi-dm",
6212
+ style: { height: "calc(100vh - 16rem)", minHeight: "28rem" },
6213
+ className: cn(
6214
+ "flex flex-col overflow-hidden rounded-xl border border-border bg-card md:flex-row",
6215
+ className
6216
+ ),
6217
+ children: [
6218
+ /* @__PURE__ */ jsx(
6219
+ ConversationList,
6220
+ {
6221
+ conversations,
6222
+ selectedPeerId: selected?.peer.external_id ?? null,
6223
+ onSelect: setSelectedPeerId,
6224
+ classNames,
6225
+ emptyState: isLoading ? "Loading messages\u2026" : emptyList
6226
+ }
6227
+ ),
6228
+ /* @__PURE__ */ jsxs("div", { className: "flex min-h-0 min-w-0 flex-1 flex-col", children: [
6229
+ /* @__PURE__ */ jsx(MessageThread, { conversation: selected, classNames, emptyState: emptyThread }),
6230
+ selected ? /* @__PURE__ */ jsx(
6231
+ DmComposer,
6232
+ {
6233
+ placeholder: `Message ${userDisplayName(selected.peer).split(" ")[0]}\u2026`,
6234
+ onSend: handleSend,
6235
+ classNames
6236
+ }
6237
+ ) : null
6238
+ ] })
6239
+ ]
6240
+ }
6241
+ );
6242
+ }
6243
+ var DEFAULT_ASPECT_OPTIONS = [
6244
+ { label: "1:1", value: 1 },
6245
+ { label: "4:3", value: 4 / 3 },
6246
+ { label: "3:4", value: 3 / 4 },
6247
+ { label: "16:9", value: 16 / 9 },
6248
+ { label: "9:16", value: 9 / 16 }
6249
+ ];
6250
+ function ImageCropper({
6251
+ image,
6252
+ aspect = 1,
6253
+ aspectOptions,
6254
+ cropShape = "rect",
6255
+ minZoom = 1,
6256
+ maxZoom = 3,
6257
+ className,
6258
+ onCropComplete
6259
+ }) {
6260
+ const [crop, setCrop] = useState({ x: 0, y: 0 });
6261
+ const [zoom, setZoom] = useState(1);
6262
+ const [activeAspect, setActiveAspect] = useState(aspectOptions?.[0]?.value ?? aspect);
6263
+ useEffect(() => {
6264
+ if (!aspectOptions) setActiveAspect(aspect);
6265
+ }, [aspect, aspectOptions]);
6266
+ const handleComplete = useCallback(
6267
+ (_, areaPixels) => {
6268
+ onCropComplete?.(areaPixels, activeAspect);
6269
+ },
6270
+ [onCropComplete, activeAspect]
6271
+ );
6272
+ return /* @__PURE__ */ jsxs("div", { className: cn("flex flex-col gap-3", className), children: [
6273
+ /* @__PURE__ */ jsx("div", { className: "relative h-72 w-full overflow-hidden rounded-md bg-foreground/95", children: /* @__PURE__ */ jsx(
6274
+ Cropper,
6275
+ {
6276
+ image,
6277
+ crop,
6278
+ zoom,
6279
+ aspect: activeAspect,
6280
+ cropShape,
6281
+ showGrid: cropShape === "rect",
6282
+ onCropChange: setCrop,
6283
+ onZoomChange: setZoom,
6284
+ onCropComplete: handleComplete,
6285
+ objectFit: "contain"
6286
+ }
6287
+ ) }),
6288
+ aspectOptions && aspectOptions.length > 1 ? /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-1", "data-testid": "image-cropper-aspects", children: [
6289
+ /* @__PURE__ */ jsx("span", { className: "mr-1 text-[11px] font-semibold uppercase tracking-wider text-muted-foreground", children: "Ratio" }),
6290
+ aspectOptions.map((opt) => {
6291
+ const on = opt.value === activeAspect;
6292
+ return /* @__PURE__ */ jsx(
6293
+ "button",
6294
+ {
6295
+ type: "button",
6296
+ onClick: () => setActiveAspect(opt.value),
6297
+ "data-testid": `image-cropper-aspect-${opt.label}`,
6298
+ className: cn(
6299
+ "rounded-md px-2 py-1 text-xs font-medium transition-colors",
6300
+ on ? "bg-primary text-primary-foreground" : "text-muted-foreground hover:bg-accent hover:text-foreground"
6301
+ ),
6302
+ children: opt.label
6303
+ },
6304
+ opt.label
6305
+ );
6306
+ })
6307
+ ] }) : null,
6308
+ /* @__PURE__ */ jsxs("div", { className: "space-y-1.5", children: [
6309
+ /* @__PURE__ */ jsx("label", { className: "text-[11px] font-semibold uppercase tracking-wider text-muted-foreground", children: "Zoom" }),
6310
+ /* @__PURE__ */ jsx(
6311
+ Slider,
6312
+ {
6313
+ value: [zoom],
6314
+ onValueChange: ([v]) => setZoom(v ?? 1),
6315
+ min: minZoom,
6316
+ max: maxZoom,
6317
+ step: 0.01
6318
+ }
6319
+ )
6320
+ ] })
6321
+ ] });
6322
+ }
6323
+
6324
+ // src/imagecrop/cropImage.ts
6325
+ function loadImage(src) {
6326
+ return new Promise((resolve, reject) => {
6327
+ const img = new Image();
6328
+ img.crossOrigin = "anonymous";
6329
+ img.onload = () => resolve(img);
6330
+ img.onerror = () => reject(new Error("Failed to load image for cropping"));
6331
+ img.src = src;
6332
+ });
6333
+ }
6334
+ async function cropImage(imageSrc, area, output = {}) {
6335
+ const { maxSize, mimeType = "image/jpeg", quality = 0.9, background = "#ffffff" } = output;
6336
+ const img = await loadImage(imageSrc);
6337
+ let outW = Math.max(1, Math.round(area.width));
6338
+ let outH = Math.max(1, Math.round(area.height));
6339
+ if (maxSize && Math.max(outW, outH) > maxSize) {
6340
+ const scale = maxSize / Math.max(outW, outH);
6341
+ outW = Math.max(1, Math.round(outW * scale));
6342
+ outH = Math.max(1, Math.round(outH * scale));
6343
+ }
6344
+ const canvas = document.createElement("canvas");
6345
+ canvas.width = outW;
6346
+ canvas.height = outH;
6347
+ const ctx = canvas.getContext("2d");
6348
+ if (!ctx) throw new Error("canvas 2d context unavailable");
6349
+ if (mimeType === "image/jpeg") {
6350
+ ctx.fillStyle = background;
6351
+ ctx.fillRect(0, 0, outW, outH);
6352
+ }
6353
+ ctx.drawImage(img, area.x, area.y, area.width, area.height, 0, 0, outW, outH);
6354
+ const dataUrl = canvas.toDataURL(mimeType, quality);
6355
+ const blob = await new Promise(
6356
+ (resolve, reject) => canvas.toBlob(
6357
+ (b) => b ? resolve(b) : reject(new Error("canvas toBlob returned null")),
6358
+ mimeType,
6359
+ quality
6360
+ )
6361
+ );
6362
+ return { dataUrl, blob, width: outW, height: outH };
6363
+ }
6364
+ function ImageCropModal({
6365
+ open,
6366
+ image,
6367
+ title = "Crop image",
6368
+ saveLabel = "Save",
6369
+ aspect,
6370
+ aspectOptions,
6371
+ cropShape = "rect",
6372
+ output,
6373
+ onComplete,
6374
+ onCancel
6375
+ }) {
6376
+ const [area, setArea] = useState(null);
6377
+ const [busy, setBusy] = useState(false);
6378
+ const handleSave = async () => {
6379
+ if (!image || !area) return;
6380
+ setBusy(true);
6381
+ try {
6382
+ const result = await cropImage(image, area, output);
6383
+ await onComplete(result);
6384
+ } finally {
6385
+ setBusy(false);
6386
+ }
6387
+ };
6388
+ return /* @__PURE__ */ jsx(Dialog, { open, onOpenChange: (next) => !next ? onCancel() : void 0, children: /* @__PURE__ */ jsxs(DialogContent, { className: "sm:max-w-md", "data-testid": "image-crop-modal", children: [
6389
+ /* @__PURE__ */ jsx(DialogHeader, { children: /* @__PURE__ */ jsx(DialogTitle, { children: title }) }),
6390
+ image ? /* @__PURE__ */ jsx(
6391
+ ImageCropper,
6392
+ {
6393
+ image,
6394
+ aspect,
6395
+ aspectOptions,
6396
+ cropShape,
6397
+ onCropComplete: setArea
6398
+ }
6399
+ ) : null,
6400
+ /* @__PURE__ */ jsxs(DialogFooter, { className: "gap-2 sm:gap-2", children: [
6401
+ /* @__PURE__ */ jsx(Button, { variant: "ghost", onClick: onCancel, disabled: busy, children: "Cancel" }),
6402
+ /* @__PURE__ */ jsxs(Button, { onClick: handleSave, disabled: !area || busy, "data-testid": "image-crop-save", children: [
6403
+ busy ? /* @__PURE__ */ jsx(Loader2, { className: "mr-1 size-4 animate-spin" }) : null,
6404
+ saveLabel
6405
+ ] })
6406
+ ] })
6407
+ ] }) });
6408
+ }
6409
+ var MAX_NAV = 5;
6410
+ var MAX_DOCS = 4;
6411
+ function CommandPalette({
6412
+ open,
6413
+ onOpenChange,
6414
+ navItems,
6415
+ onNavigate,
6416
+ buildAskPrompt = (q) => q,
6417
+ askDocIds = [],
6418
+ model,
6419
+ searchDocIds,
6420
+ onOpenDoc,
6421
+ placeholder = "Ask AI, or jump to a page\u2026",
6422
+ askHint = "Grounded in the live workspace",
6423
+ classNames,
6424
+ testId = "command-palette"
6425
+ }) {
6426
+ const task = useAiTask();
6427
+ const searchable = !!searchDocIds && searchDocIds.length > 0;
6428
+ const { results, search, status: searchStatus } = useSemanticSearch(searchDocIds ?? []);
6429
+ const [query, setQuery] = useState("");
6430
+ const inputRef = useRef(null);
6431
+ useEffect(() => {
6432
+ if (open) {
6433
+ setQuery("");
6434
+ task.reset();
6435
+ const t = setTimeout(() => inputRef.current?.focus(), 40);
6436
+ return () => clearTimeout(t);
6437
+ }
6438
+ }, [open]);
6439
+ const showingAnswer = task.status !== "idle";
6440
+ useEffect(() => {
6441
+ if (!searchable || showingAnswer) return;
6442
+ const q = query.trim();
6443
+ if (q.length < 2) return;
6444
+ const t = setTimeout(() => void search(q, "hybrid"), 300);
6445
+ return () => clearTimeout(t);
6446
+ }, [query, searchable, showingAnswer, search]);
6447
+ const navMatches = useMemo(() => {
6448
+ const q = query.trim().toLowerCase();
6449
+ if (!q) return navItems.slice(0, MAX_NAV);
6450
+ return navItems.filter(
6451
+ (i) => i.label.toLowerCase().includes(q) || (i.keywords ? i.keywords.toLowerCase().includes(q) : false)
6452
+ ).slice(0, MAX_NAV);
6453
+ }, [query, navItems]);
6454
+ const docHits = useMemo(() => results.slice(0, MAX_DOCS), [results]);
6455
+ const go = (to) => {
6456
+ onOpenChange(false);
6457
+ onNavigate(to);
6458
+ };
6459
+ const openDoc = (docId) => {
6460
+ onOpenChange(false);
6461
+ onOpenDoc?.(docId);
6462
+ };
6463
+ const ask = () => {
6464
+ const q = query.trim();
6465
+ if (!q || task.isRunning) return;
6466
+ void task.run(buildAskPrompt(q), askDocIds, { model });
6467
+ };
6468
+ return /* @__PURE__ */ jsx(Dialog, { open, onOpenChange, children: /* @__PURE__ */ jsxs(
6469
+ DialogContent,
6470
+ {
6471
+ className: cn(
6472
+ "top-[12%] max-w-2xl translate-y-0 gap-0 overflow-hidden p-0",
6473
+ classNames?.dialog
6474
+ ),
6475
+ "data-testid": testId,
6476
+ children: [
6477
+ /* @__PURE__ */ jsx(DialogTitle, { className: "sr-only", children: "Command palette" }),
6478
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 border-b border-border px-4", children: [
6479
+ /* @__PURE__ */ jsx(Sparkles, { className: cn("size-4 shrink-0 text-ai-accent", classNames?.leadingIcon) }),
6480
+ /* @__PURE__ */ jsx(
6481
+ "input",
6482
+ {
6483
+ ref: inputRef,
6484
+ value: query,
6485
+ onChange: (e) => setQuery(e.target.value),
6486
+ onKeyDown: (e) => {
6487
+ if (e.key === "Enter") {
6488
+ e.preventDefault();
6489
+ ask();
6490
+ }
6491
+ },
6492
+ placeholder,
6493
+ className: cn(
6494
+ "h-14 flex-1 bg-transparent text-base outline-none placeholder:text-muted-foreground",
6495
+ classNames?.input
6496
+ ),
6497
+ "data-testid": `${testId}-input`
6498
+ }
6499
+ ),
6500
+ /* @__PURE__ */ jsx("kbd", { className: "hidden rounded border border-border px-1.5 py-0.5 text-[10px] text-muted-foreground sm:inline", children: "\u2318K" })
6501
+ ] }),
6502
+ /* @__PURE__ */ jsxs("div", { className: "max-h-[60vh] overflow-y-auto p-2", children: [
6503
+ query.trim() && !showingAnswer && /* @__PURE__ */ jsxs(
6504
+ "button",
6505
+ {
6506
+ type: "button",
6507
+ onClick: ask,
6508
+ className: cn(
6509
+ "mb-1 flex w-full items-center gap-3 rounded-lg px-3 py-2.5 text-left hover:bg-accent",
6510
+ classNames?.askAction
6511
+ ),
6512
+ "data-testid": `${testId}-ask`,
6513
+ children: [
6514
+ /* @__PURE__ */ jsx(
6515
+ "span",
6516
+ {
6517
+ className: cn(
6518
+ "flex size-8 items-center justify-center rounded-md bg-ai-surface text-ai-accent",
6519
+ classNames?.askChip
6520
+ ),
6521
+ children: /* @__PURE__ */ jsx(Sparkles, { className: "size-4" })
6522
+ }
6523
+ ),
6524
+ /* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1", children: [
6525
+ /* @__PURE__ */ jsxs("span", { className: "block truncate text-sm font-medium text-foreground", children: [
6526
+ "Ask AI: \u201C",
6527
+ query.trim(),
6528
+ "\u201D"
6529
+ ] }),
6530
+ /* @__PURE__ */ jsx("span", { className: "block text-xs text-muted-foreground", children: askHint })
6531
+ ] }),
6532
+ /* @__PURE__ */ jsx(CornerDownLeft, { className: "size-4 text-muted-foreground" })
6533
+ ]
6534
+ }
6535
+ ),
6536
+ showingAnswer && /* @__PURE__ */ jsxs("div", { className: "px-3 py-2", "data-testid": `${testId}-answer`, children: [
6537
+ /* @__PURE__ */ jsx(
6538
+ AiAnswer,
6539
+ {
6540
+ status: task.status,
6541
+ text: task.text,
6542
+ stepCount: task.stepCount,
6543
+ error: task.error,
6544
+ testId: `${testId}-ai`
6545
+ }
6546
+ ),
6547
+ task.isDone && /* @__PURE__ */ jsx("div", { className: "mt-3 flex justify-end", children: /* @__PURE__ */ jsx(
6548
+ Button,
6549
+ {
6550
+ variant: "outline",
6551
+ size: "sm",
6552
+ onClick: () => task.reset(),
6553
+ "data-testid": `${testId}-clear`,
6554
+ children: "Ask another"
6555
+ }
6556
+ ) })
6557
+ ] }),
6558
+ !showingAnswer && /* @__PURE__ */ jsxs(Fragment, { children: [
6559
+ /* @__PURE__ */ jsx("p", { className: "px-3 pb-1 pt-2 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground", children: query.trim() ? "Jump to" : "Go to" }),
6560
+ navMatches.length === 0 && /* @__PURE__ */ jsx("p", { className: "px-3 py-2 text-sm text-muted-foreground", children: "No pages match \u2014 press Enter to ask AI." }),
6561
+ navMatches.map((item) => /* @__PURE__ */ jsxs(
6562
+ "button",
6563
+ {
6564
+ type: "button",
6565
+ onClick: () => go(item.to),
6566
+ className: cn(
6567
+ "flex w-full items-center gap-3 rounded-lg px-3 py-2 text-left hover:bg-accent",
6568
+ classNames?.navItem
6569
+ ),
6570
+ "data-testid": `${testId}-nav-${item.id}`,
6571
+ children: [
6572
+ item.icon && /* @__PURE__ */ jsx(item.icon, { className: "size-4 text-muted-foreground" }),
6573
+ /* @__PURE__ */ jsx("span", { className: "flex-1 text-sm text-foreground", children: item.label }),
6574
+ /* @__PURE__ */ jsx(ArrowRight, { className: "size-3.5 text-muted-foreground" })
6575
+ ]
6576
+ },
6577
+ item.id
6578
+ )),
6579
+ searchable && query.trim().length >= 2 && /* @__PURE__ */ jsxs(Fragment, { children: [
6580
+ /* @__PURE__ */ jsx("p", { className: "px-3 pb-1 pt-3 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground", children: "Documents" }),
6581
+ searchStatus === "done" && docHits.length === 0 && /* @__PURE__ */ jsx("p", { className: "px-3 py-2 text-sm text-muted-foreground", children: "No passages matched." }),
6582
+ docHits.map((hit, i) => /* @__PURE__ */ jsxs(
6583
+ "button",
6584
+ {
6585
+ type: "button",
6586
+ onClick: () => hit.docId && openDoc(hit.docId),
6587
+ className: "flex w-full items-start gap-3 rounded-lg px-3 py-2 text-left hover:bg-accent",
6588
+ "data-testid": `${testId}-doc-${i}`,
6589
+ children: [
6590
+ /* @__PURE__ */ jsx(FileText, { className: "mt-0.5 size-4 shrink-0 text-ai-accent" }),
6591
+ /* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1", children: [
6592
+ /* @__PURE__ */ jsxs("span", { className: "block truncate text-sm text-foreground", children: [
6593
+ hit.docTitle ?? "Document",
6594
+ hit.page != null && /* @__PURE__ */ jsxs("span", { className: "text-muted-foreground", children: [
6595
+ " \xB7 p.",
6596
+ hit.page
6597
+ ] })
6598
+ ] }),
6599
+ /* @__PURE__ */ jsx("span", { className: "line-clamp-1 text-xs text-muted-foreground", children: hit.content })
6600
+ ] })
6601
+ ]
6602
+ },
6603
+ `${hit.docId}-${hit.page}-${i}`
6604
+ ))
6605
+ ] })
6606
+ ] })
6607
+ ] })
6608
+ ]
6609
+ }
6610
+ ) });
6611
+ }
6612
+ var CommandPaletteCtx = createContext(null);
6613
+ function useCommandPalette() {
6614
+ const v = useContext(CommandPaletteCtx);
6615
+ if (!v) throw new Error("useCommandPalette must be used within a CommandPaletteProvider");
6616
+ return v;
6617
+ }
6618
+ function CommandPaletteProvider({
6619
+ children,
6620
+ hotkey = true,
6621
+ ...paletteProps
6622
+ }) {
6623
+ const [isOpen, setIsOpen] = useState(false);
6624
+ const open = useCallback(() => setIsOpen(true), []);
6625
+ const close = useCallback(() => setIsOpen(false), []);
6626
+ const toggle = useCallback(() => setIsOpen((o) => !o), []);
6627
+ useEffect(() => {
6628
+ if (!hotkey) return;
6629
+ const onKey = (e) => {
6630
+ if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "k") {
6631
+ e.preventDefault();
6632
+ toggle();
6633
+ }
6634
+ };
6635
+ window.addEventListener("keydown", onKey);
6636
+ return () => window.removeEventListener("keydown", onKey);
6637
+ }, [hotkey, toggle]);
6638
+ const value = useMemo(() => ({ open, close, toggle, isOpen }), [open, close, toggle, isOpen]);
6639
+ return /* @__PURE__ */ jsxs(CommandPaletteCtx.Provider, { value, children: [
6640
+ children,
6641
+ /* @__PURE__ */ jsx(CommandPalette, { open: isOpen, onOpenChange: setIsOpen, ...paletteProps })
6642
+ ] });
6643
+ }
6644
+ function nameInitials(name) {
6645
+ const parts = name.trim().split(/\s+/).filter(Boolean);
6646
+ if (!parts.length) return "?";
6647
+ return parts.slice(0, 2).map((p) => p[0]?.toUpperCase() ?? "").join("");
6648
+ }
6649
+ function UserMenu({
6650
+ user,
6651
+ items = [],
6652
+ onLogout,
6653
+ logoutLabel = "Sign out",
6654
+ align = "end",
6655
+ classNames,
6656
+ testId = "user-menu",
6657
+ logoutTestId
6658
+ }) {
6659
+ return /* @__PURE__ */ jsxs(DropdownMenu, { children: [
6660
+ /* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
6661
+ "button",
6662
+ {
6663
+ className: cn(
6664
+ "flex items-center gap-2 rounded-md px-1.5 py-1 transition-colors hover:bg-accent",
6665
+ classNames?.trigger
6666
+ ),
6667
+ "data-testid": testId,
6668
+ children: [
6669
+ /* @__PURE__ */ jsxs(Avatar, { className: "size-8", children: [
6670
+ user.picture ? /* @__PURE__ */ jsx(AvatarImage, { src: user.picture, alt: user.name }) : null,
6671
+ /* @__PURE__ */ jsx(
6672
+ AvatarFallback,
6673
+ {
6674
+ className: cn("bg-primary text-primary-foreground", classNames?.fallback),
6675
+ children: nameInitials(user.name)
6676
+ }
6677
+ )
6678
+ ] }),
6679
+ /* @__PURE__ */ jsx(ChevronDown, { className: "size-4 text-muted-foreground" })
6680
+ ]
6681
+ }
6682
+ ) }),
6683
+ /* @__PURE__ */ jsxs(DropdownMenuContent, { align, className: "w-56", children: [
6684
+ /* @__PURE__ */ jsxs(DropdownMenuLabel, { children: [
6685
+ /* @__PURE__ */ jsx("div", { className: "font-medium text-foreground", children: user.name }),
6686
+ user.email && /* @__PURE__ */ jsx("div", { className: "text-xs font-normal text-muted-foreground", children: user.email })
6687
+ ] }),
6688
+ /* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
6689
+ items.map((item) => /* @__PURE__ */ jsxs(DropdownMenuItem, { onClick: item.onSelect, "data-testid": item.testId, children: [
6690
+ item.icon && /* @__PURE__ */ jsx(item.icon, { className: "size-4" }),
6691
+ item.label
6692
+ ] }, item.label)),
6693
+ /* @__PURE__ */ jsxs(DropdownMenuItem, { onClick: onLogout, "data-testid": logoutTestId ?? `${testId}-logout`, children: [
6694
+ /* @__PURE__ */ jsx(LogOut, { className: "size-4" }),
6695
+ logoutLabel
6696
+ ] })
6697
+ ] })
6698
+ ] });
6699
+ }
5741
6700
  var useArbiUiStore = create((set) => ({
5742
6701
  selectedDocIds: [],
5743
6702
  setSelectedDocIds: (ids) => set({ selectedDocIds: ids }),
@@ -6306,6 +7265,6 @@ function DocumentReview({
6306
7265
  );
6307
7266
  }
6308
7267
 
6309
- export { ActivityFeed, AiActionCard, AiAnswer, AiMarkdown, AppleIcon, ArbiBotHeadIcon, ArbiBotIcon, ArbiChat, ArbiChatPanel, ArbiIcon, ArbiProvider, ArbiWebSocketProvider, ArtifactCanvas, AudIcon, Avatar, AvatarFallback, AvatarImage, BASE_COLORS2 as BASE_COLORS, Badge, Button, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, ChatBubble, Checkbox, CitationRenderer, ClaudeIcon, Collapsible, CollapsibleContent2 as CollapsibleContent, CollapsibleTrigger2 as CollapsibleTrigger, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DocIcon, DocQaPanel, DocSearch, DocumentEntity, DocumentGallery, DocumentReview, DocumentTable, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, ENTITY_MAPPINGS, EmlIcon, EntityIcon, EntityPill, FILE_TYPE_COLORS, FileIcon, FireworksIcon, GeminiIcon, GitHubIcon, GoogleIcon, HoverCard, HoverCardContent, HoverCardTrigger, HtmlIcon, ImgIcon, Input, Label, LinkedInIcon, MessageArtifactCard, NEUTRAL_GRAY2 as NEUTRAL_GRAY, OpenAIIcon, PLACEHOLDER_COLOR, PdfIcon, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, Progress, ProjectEntity, ProviderIcon, RadioGroup, RadioGroupItem, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, Slider, Switch, TAG_TYPE_ICONS, TAG_TYPE_LABELS, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsList, TabsTrigger, TagEntity, Textarea, Toggle, ToggleGroup, ToggleGroupItem, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, TxtIcon, TypingIndicator, UserEntity, VISIBILITY_ICONS, VidIcon, VisibilityIcon, XlsIcon, arbiQueryKeys, badgeVariants, buttonVariants, cardVariants, cn, configureEntityRegistry, describeActivity, getEntityColor2 as getEntityColor, getEntityColorStyles, getEntityIcon, getEntityLabel, getNotificationTypeMeta, getTagTypeIcon, getTagTypeLabel, getWorkspaceActionText, getWorkspaceColor, getWorkspaceSentPhrase, isWorkspaceNotificationType, markdownBaseComponents, parseActivityContent, redlineStats, textToArtifact, toRedlineMarkdown, toggleVariants, useActivity, useAgents, useAiTask, useArbi, useArbiConnected, useArbiDocumentSync, useArbiUiStore, useArbiWebSocket, useArbiWsContext, useArbiWsMessage, useArbiWsStatus, useArbiWsStore, useArbiWsTask, useArbiWsTasks, useAssistantQuery, useConfigs, useConversations, useDeleteAgents, useDocuments, useHealth, useMemories, useParsedDocument, useProjectInvoices, useProjectUsage, useProjects, useProjectsUsage, useSemanticSearch, useSessions, useTags, useTasks, useThumbnails, useUserUsageToday, useWorkspaceChronology, useWorkspaceDocs, useWorkspaces };
7268
+ export { ActivityFeed, AiActionCard, AiAnswer, AiMarkdown, AppleIcon, ArbiBotHeadIcon, ArbiBotIcon, ArbiChat, ArbiChatPanel, ArbiIcon, ArbiProvider, ArbiWebSocketProvider, ArtifactCanvas, AudIcon, Avatar, AvatarFallback, AvatarImage, BASE_COLORS2 as BASE_COLORS, Badge, Button, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, ChatBubble, Checkbox, CitationRenderer, ClaudeIcon, Collapsible, CollapsibleContent2 as CollapsibleContent, CollapsibleTrigger2 as CollapsibleTrigger, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandPalette, CommandPaletteProvider, CommandSeparator, CommandShortcut, ConversationList, DEFAULT_ASPECT_OPTIONS, DEFAULT_NOTIFY_TONE, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DirectMessages, DmAvatar, DmComposer, DocIcon, DocQaPanel, DocSearch, DocumentEntity, DocumentGallery, DocumentReview, DocumentTable, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, ENTITY_MAPPINGS, EmlIcon, EntityIcon, EntityPill, FILE_TYPE_COLORS, FileIcon, FireworksIcon, GeminiIcon, GitHubIcon, GoogleIcon, HoverCard, HoverCardContent, HoverCardTrigger, HtmlIcon, ImageCropModal, ImageCropper, ImgIcon, Input, Label, LinkedInIcon, MessageArtifactCard, MessageBubble2 as MessageBubble, MessageThread, NEUTRAL_GRAY2 as NEUTRAL_GRAY, NotificationBell, OpenAIIcon, PLACEHOLDER_COLOR, PdfIcon, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, Progress, ProjectEntity, ProviderIcon, RadioGroup, RadioGroupItem, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, Slider, Switch, TAG_TYPE_ICONS, TAG_TYPE_LABELS, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsList, TabsTrigger, TagEntity, Textarea, Toaster, Toggle, ToggleGroup, ToggleGroupItem, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, TxtIcon, TypingIndicator, UserEntity, UserMenu, VISIBILITY_ICONS, VidIcon, VisibilityIcon, XlsIcon, arbiQueryKeys, badgeVariants, buttonVariants, cardVariants, cn, configureEntityRegistry, cropImage, describeActivity, formatRelativeTime, getEntityColor2 as getEntityColor, getEntityColorStyles, getEntityIcon, getEntityLabel, getNotificationTypeMeta, getTagTypeIcon, getTagTypeLabel, getWorkspaceActionText, getWorkspaceColor, getWorkspaceSentPhrase, isWorkspaceNotificationType, markdownBaseComponents, notify, parseActivityContent, redlineStats, seedNotifications, selectUnread, textToArtifact, toRedlineMarkdown, toggleVariants, useActivity, useAgents, useAiTask, useArbi, useArbiConnected, useArbiDocumentSync, useArbiUiStore, useArbiWebSocket, useArbiWsContext, useArbiWsMessage, useArbiWsStatus, useArbiWsStore, useArbiWsTask, useArbiWsTasks, useAssistantQuery, useCommandPalette, useConfigs, useConversations, useDeleteAgents, useDirectMessages, useDocuments, useHealth, useMemories, useNotify, useParsedDocument, useProjectInvoices, useProjectUsage, useProjects, useProjectsUsage, useSemanticSearch, useSessions, useTags, useTasks, useThumbnails, useUserUsageToday, useWorkspaceChronology, useWorkspaceDocs, useWorkspaces, userDisplayName, userInitials };
6310
7269
  //# sourceMappingURL=index.js.map
6311
7270
  //# sourceMappingURL=index.js.map