@arbidocs/react 0.3.116 → 0.3.117

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.cjs CHANGED
@@ -35,6 +35,7 @@ var ReactMarkdown = require('react-markdown');
35
35
  var remarkGfm = require('remark-gfm');
36
36
  var rehypeRaw = require('rehype-raw');
37
37
  var framerMotion = require('framer-motion');
38
+ var Cropper = require('react-easy-crop');
38
39
  var agGridReact = require('ag-grid-react');
39
40
  var agGridCommunity = require('ag-grid-community');
40
41
 
@@ -79,6 +80,7 @@ var SelectPrimitive__namespace = /*#__PURE__*/_interopNamespace(SelectPrimitive)
79
80
  var ReactMarkdown__default = /*#__PURE__*/_interopDefault(ReactMarkdown);
80
81
  var remarkGfm__default = /*#__PURE__*/_interopDefault(remarkGfm);
81
82
  var rehypeRaw__default = /*#__PURE__*/_interopDefault(rehypeRaw);
83
+ var Cropper__default = /*#__PURE__*/_interopDefault(Cropper);
82
84
 
83
85
  // src/ArbiProvider.tsx
84
86
  var ArbiContext = React.createContext(null);
@@ -5779,6 +5781,1013 @@ function ActivityFeed({
5779
5781
  );
5780
5782
  }) });
5781
5783
  }
5784
+ var seq = 0;
5785
+ var uid = () => `n${Date.now().toString(36)}${(seq++).toString(36)}`;
5786
+ var useNotify = zustand.create((set) => ({
5787
+ toasts: [],
5788
+ notifications: [],
5789
+ push: (variant, title, opts = {}) => {
5790
+ const id = uid();
5791
+ const duration = opts.duration ?? (variant === "error" ? 7e3 : 4500);
5792
+ set((s) => {
5793
+ const toast = { id, title, description: opts.description, variant, duration };
5794
+ const next = { toasts: [...s.toasts, toast] };
5795
+ if (opts.record !== false) {
5796
+ const note = {
5797
+ id,
5798
+ title,
5799
+ description: opts.description,
5800
+ variant,
5801
+ ts: Date.now(),
5802
+ read: false,
5803
+ href: opts.href
5804
+ };
5805
+ next.notifications = [note, ...s.notifications].slice(0, 50);
5806
+ }
5807
+ return next;
5808
+ });
5809
+ return id;
5810
+ },
5811
+ dismiss: (id) => set((s) => ({ toasts: s.toasts.filter((t) => t.id !== id) })),
5812
+ markRead: (id) => set((s) => ({
5813
+ notifications: s.notifications.map((n) => n.id === id ? { ...n, read: true } : n)
5814
+ })),
5815
+ markAllRead: () => set((s) => ({ notifications: s.notifications.map((n) => ({ ...n, read: true })) })),
5816
+ removeNotification: (id) => set((s) => ({ notifications: s.notifications.filter((n) => n.id !== id) })),
5817
+ clearNotifications: () => set({ notifications: [] }),
5818
+ seed: (items) => set({ notifications: items })
5819
+ }));
5820
+ function make(variant) {
5821
+ return (title, opts) => useNotify.getState().push(variant, title, opts);
5822
+ }
5823
+ var notify = {
5824
+ success: make("success"),
5825
+ error: make("error"),
5826
+ info: make("info"),
5827
+ warning: make("warning")
5828
+ };
5829
+ function seedNotifications(items) {
5830
+ useNotify.getState().seed(items);
5831
+ }
5832
+ var selectUnread = (s) => s.notifications.filter((n) => !n.read).length;
5833
+ var DEFAULT_NOTIFY_TONE = {
5834
+ success: "text-green-600",
5835
+ error: "text-destructive",
5836
+ warning: "text-amber-500",
5837
+ info: "text-blue-500"
5838
+ };
5839
+
5840
+ // src/directmessages/utils.ts
5841
+ function userInitials(user) {
5842
+ const parts = [user.given_name, user.family_name].filter(Boolean);
5843
+ if (parts.length) {
5844
+ return parts.map((p) => p[0]?.toUpperCase() ?? "").join("").slice(0, 2);
5845
+ }
5846
+ const local = user.email?.split("@")[0] ?? "";
5847
+ return local.slice(0, 2).toUpperCase() || "?";
5848
+ }
5849
+ function userDisplayName(user) {
5850
+ const name = [user.given_name, user.family_name].filter(Boolean).join(" ").trim();
5851
+ return name || user.email?.split("@")[0] || "Unknown";
5852
+ }
5853
+ var RELATIVE = new Intl.RelativeTimeFormat(void 0, { numeric: "auto" });
5854
+ var DIVISIONS = [
5855
+ { amount: 60, unit: "seconds" },
5856
+ { amount: 60, unit: "minutes" },
5857
+ { amount: 24, unit: "hours" },
5858
+ { amount: 7, unit: "days" },
5859
+ { amount: 4.34524, unit: "weeks" },
5860
+ { amount: 12, unit: "months" },
5861
+ { amount: Number.POSITIVE_INFINITY, unit: "years" }
5862
+ ];
5863
+ function formatRelativeTime(iso) {
5864
+ const then = Date.parse(iso);
5865
+ if (Number.isNaN(then)) return "";
5866
+ let duration = (then - Date.now()) / 1e3;
5867
+ if (Math.abs(duration) < 45) return "just now";
5868
+ for (const division of DIVISIONS) {
5869
+ if (Math.abs(duration) < division.amount) {
5870
+ return RELATIVE.format(Math.round(duration), division.unit);
5871
+ }
5872
+ duration /= division.amount;
5873
+ }
5874
+ return "";
5875
+ }
5876
+ var GLYPH = {
5877
+ success: lucideReact.CheckCircle2,
5878
+ error: lucideReact.XCircle,
5879
+ warning: lucideReact.AlertTriangle,
5880
+ info: lucideReact.Info
5881
+ };
5882
+ function NotificationBell({
5883
+ onNavigate,
5884
+ toneClassNames,
5885
+ emptyText = "You're all caught up.",
5886
+ testId = "notifications"
5887
+ }) {
5888
+ const notifications = useNotify((s) => s.notifications);
5889
+ const unread = useNotify(selectUnread);
5890
+ const markAllRead = useNotify((s) => s.markAllRead);
5891
+ const markRead = useNotify((s) => s.markRead);
5892
+ const tone = (v) => toneClassNames?.[v] ?? DEFAULT_NOTIFY_TONE[v];
5893
+ return /* @__PURE__ */ jsxRuntime.jsxs(DropdownMenu, { children: [
5894
+ /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(
5895
+ "button",
5896
+ {
5897
+ className: "relative flex size-9 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",
5898
+ "data-testid": testId,
5899
+ "aria-label": `Notifications${unread ? ` (${unread} unread)` : ""}`,
5900
+ children: [
5901
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Bell, { className: "size-5" }),
5902
+ unread > 0 && /* @__PURE__ */ jsxRuntime.jsx(
5903
+ "span",
5904
+ {
5905
+ 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",
5906
+ "data-testid": `${testId}-badge`,
5907
+ children: unread > 9 ? "9+" : unread
5908
+ }
5909
+ )
5910
+ ]
5911
+ }
5912
+ ) }),
5913
+ /* @__PURE__ */ jsxRuntime.jsxs(DropdownMenuContent, { align: "end", className: "w-[360px] p-0", "data-testid": `${testId}-panel`, children: [
5914
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between border-b border-border px-3.5 py-2.5", children: [
5915
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm font-semibold text-foreground", children: "Notifications" }),
5916
+ unread > 0 && /* @__PURE__ */ jsxRuntime.jsxs(
5917
+ "button",
5918
+ {
5919
+ onClick: markAllRead,
5920
+ className: "flex items-center gap-1 text-xs font-medium text-primary transition-colors hover:opacity-80",
5921
+ "data-testid": `${testId}-mark-all`,
5922
+ children: [
5923
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CheckCheck, { className: "size-3.5" }),
5924
+ " Mark all read"
5925
+ ]
5926
+ }
5927
+ )
5928
+ ] }),
5929
+ notifications.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-3.5 py-10 text-center text-sm text-muted-foreground", children: emptyText }) : /* @__PURE__ */ jsxRuntime.jsx(ScrollArea, { className: "max-h-[380px]", children: /* @__PURE__ */ jsxRuntime.jsx("ul", { "data-testid": `${testId}-list`, children: notifications.map((n) => {
5930
+ const Glyph = GLYPH[n.variant];
5931
+ return /* @__PURE__ */ jsxRuntime.jsx("li", { children: /* @__PURE__ */ jsxRuntime.jsxs(
5932
+ "button",
5933
+ {
5934
+ onClick: () => {
5935
+ markRead(n.id);
5936
+ if (n.href) onNavigate?.(n.href);
5937
+ },
5938
+ className: cn(
5939
+ "flex w-full items-start gap-3 border-b border-border/60 px-3.5 py-3 text-left transition-colors hover:bg-accent",
5940
+ !n.read && "bg-accent/40"
5941
+ ),
5942
+ "data-testid": `${testId}-item`,
5943
+ children: [
5944
+ /* @__PURE__ */ jsxRuntime.jsx(Glyph, { className: cn("mt-0.5 size-4 shrink-0", tone(n.variant)) }),
5945
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "min-w-0 flex-1", children: [
5946
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm font-medium leading-snug text-foreground", children: n.title }),
5947
+ n.description && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-0.5 line-clamp-2 text-xs leading-relaxed text-muted-foreground", children: n.description }),
5948
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-1 text-[11px] text-muted-foreground/80", children: formatRelativeTime(new Date(n.ts).toISOString()) })
5949
+ ] }),
5950
+ !n.read && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "mt-1.5 size-2 shrink-0 rounded-full bg-primary" })
5951
+ ]
5952
+ }
5953
+ ) }, n.id);
5954
+ }) }) })
5955
+ ] })
5956
+ ] });
5957
+ }
5958
+ var GLYPH2 = {
5959
+ success: lucideReact.CheckCircle2,
5960
+ error: lucideReact.XCircle,
5961
+ warning: lucideReact.AlertTriangle,
5962
+ info: lucideReact.Info
5963
+ };
5964
+ function Toaster({ className, toneClassNames, testId = "toaster" }) {
5965
+ const toasts = useNotify((s) => s.toasts);
5966
+ return /* @__PURE__ */ jsxRuntime.jsx(
5967
+ "div",
5968
+ {
5969
+ className: cn(
5970
+ "pointer-events-none fixed bottom-4 right-4 z-[100] flex w-[min(92vw,380px)] flex-col gap-2.5",
5971
+ className
5972
+ ),
5973
+ "data-testid": testId,
5974
+ "aria-live": "polite",
5975
+ "aria-atomic": "false",
5976
+ children: /* @__PURE__ */ jsxRuntime.jsx(framerMotion.AnimatePresence, { initial: false, children: toasts.map((t) => /* @__PURE__ */ jsxRuntime.jsx(ToastCard, { toast: t, toneClassNames }, t.id)) })
5977
+ }
5978
+ );
5979
+ }
5980
+ function ToastCard({
5981
+ toast,
5982
+ toneClassNames
5983
+ }) {
5984
+ const dismiss = useNotify((s) => s.dismiss);
5985
+ const Glyph = GLYPH2[toast.variant];
5986
+ const tone = toneClassNames?.[toast.variant] ?? DEFAULT_NOTIFY_TONE[toast.variant];
5987
+ React.useEffect(() => {
5988
+ if (!toast.duration) return;
5989
+ const timer = setTimeout(() => dismiss(toast.id), toast.duration);
5990
+ return () => clearTimeout(timer);
5991
+ }, [toast.id, toast.duration, dismiss]);
5992
+ return /* @__PURE__ */ jsxRuntime.jsxs(
5993
+ framerMotion.motion.div,
5994
+ {
5995
+ layout: true,
5996
+ initial: { opacity: 0, y: 16, scale: 0.97 },
5997
+ animate: { opacity: 1, y: 0, scale: 1 },
5998
+ exit: { opacity: 0, x: 24, scale: 0.97, transition: { duration: 0.18 } },
5999
+ transition: { type: "spring", stiffness: 380, damping: 30 },
6000
+ className: "pointer-events-auto flex items-start gap-3 rounded-lg border border-border bg-card p-3.5 shadow-lg",
6001
+ "data-testid": `toast-${toast.variant}`,
6002
+ "data-toast": "",
6003
+ role: toast.variant === "error" ? "alert" : "status",
6004
+ children: [
6005
+ /* @__PURE__ */ jsxRuntime.jsx(Glyph, { className: cn("mt-0.5 size-[18px] shrink-0", tone) }),
6006
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "min-w-0 flex-1", children: [
6007
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm font-semibold leading-snug text-foreground", children: toast.title }),
6008
+ toast.description && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-0.5 text-xs leading-relaxed text-muted-foreground", children: toast.description })
6009
+ ] }),
6010
+ /* @__PURE__ */ jsxRuntime.jsx(
6011
+ "button",
6012
+ {
6013
+ onClick: () => dismiss(toast.id),
6014
+ className: "shrink-0 rounded p-0.5 text-muted-foreground/70 transition-colors hover:bg-accent hover:text-foreground",
6015
+ "aria-label": "Dismiss",
6016
+ "data-testid": "toast-dismiss",
6017
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { className: "size-4" })
6018
+ }
6019
+ )
6020
+ ]
6021
+ }
6022
+ );
6023
+ }
6024
+ var DM_QUERY_KEY = ["arbi", "directMessages"];
6025
+ function groupConversations(notifications, myExtId) {
6026
+ const messagesByPeer = /* @__PURE__ */ new Map();
6027
+ const peers = /* @__PURE__ */ new Map();
6028
+ for (const n of notifications) {
6029
+ if (n.type !== "user_message") continue;
6030
+ if (n.sender.external_id === n.recipient.external_id) continue;
6031
+ const isMine = n.sender.external_id === myExtId;
6032
+ const peer = isMine ? n.recipient : n.sender;
6033
+ if (!peer?.external_id) continue;
6034
+ const message = {
6035
+ externalId: n.external_id,
6036
+ body: n.content ?? "",
6037
+ createdAt: n.created_at,
6038
+ isMine,
6039
+ read: n.read,
6040
+ sender: n.sender,
6041
+ recipient: n.recipient
6042
+ };
6043
+ if (!messagesByPeer.has(peer.external_id)) {
6044
+ messagesByPeer.set(peer.external_id, []);
6045
+ peers.set(peer.external_id, peer);
6046
+ }
6047
+ messagesByPeer.get(peer.external_id).push(message);
6048
+ }
6049
+ const conversations = [];
6050
+ for (const [peerId, messages] of messagesByPeer) {
6051
+ messages.sort((a, b) => a.createdAt.localeCompare(b.createdAt));
6052
+ const unreadCount = messages.filter((m) => !m.isMine && !m.read).length;
6053
+ conversations.push({
6054
+ peer: peers.get(peerId),
6055
+ messages,
6056
+ lastMessage: messages[messages.length - 1],
6057
+ unreadCount
6058
+ });
6059
+ }
6060
+ conversations.sort((a, b) => b.lastMessage.createdAt.localeCompare(a.lastMessage.createdAt));
6061
+ return conversations;
6062
+ }
6063
+ function useDirectMessages(options) {
6064
+ const arbi = useArbi();
6065
+ const queryClient = reactQuery.useQueryClient();
6066
+ const enabled = options?.enabled ?? arbi.isLoggedIn;
6067
+ const query = reactQuery.useQuery({
6068
+ queryKey: DM_QUERY_KEY,
6069
+ queryFn: () => arbi.dm.list(),
6070
+ enabled
6071
+ });
6072
+ useArbiWsMessage("user_message", () => {
6073
+ queryClient.invalidateQueries({ queryKey: DM_QUERY_KEY });
6074
+ });
6075
+ const myExtId = React.useMemo(() => {
6076
+ try {
6077
+ return arbi.user.identity()?.externalId ?? null;
6078
+ } catch {
6079
+ return null;
6080
+ }
6081
+ }, [arbi, query.data]);
6082
+ const conversations = React.useMemo(
6083
+ () => groupConversations(query.data ?? [], myExtId),
6084
+ [query.data, myExtId]
6085
+ );
6086
+ const invalidate = () => queryClient.invalidateQueries({ queryKey: DM_QUERY_KEY });
6087
+ const sendMutation = reactQuery.useMutation({
6088
+ mutationFn: (vars) => arbi.dm.sendTo(vars.recipientExtId, vars.recipientPublicKey, vars.text),
6089
+ onSuccess: invalidate
6090
+ });
6091
+ const sendToMutation = reactQuery.useMutation({
6092
+ mutationFn: (vars) => arbi.dm.send(vars.recipient, vars.text),
6093
+ onSuccess: invalidate
6094
+ });
6095
+ const markReadMutation = reactQuery.useMutation({
6096
+ mutationFn: (messageIds) => arbi.dm.markRead(messageIds),
6097
+ onSuccess: invalidate
6098
+ });
6099
+ return {
6100
+ conversations,
6101
+ myExtId,
6102
+ isLoading: query.isLoading && enabled,
6103
+ isError: query.isError,
6104
+ error: query.error,
6105
+ refetch: () => query.refetch(),
6106
+ sendMessage: (recipientExtId, recipientPublicKey, text) => sendMutation.mutateAsync({ recipientExtId, recipientPublicKey, text }),
6107
+ sendMessageTo: (recipient, text) => sendToMutation.mutateAsync({ recipient, text }),
6108
+ isSending: sendMutation.isPending || sendToMutation.isPending,
6109
+ markRead: (messageIds) => markReadMutation.mutateAsync(messageIds)
6110
+ };
6111
+ }
6112
+ function DmAvatar({ user, className }) {
6113
+ const name = userDisplayName(user);
6114
+ const tint = getEntityColorStyles(user.external_id);
6115
+ return /* @__PURE__ */ jsxRuntime.jsxs(Avatar, { className: cn("size-10", className), children: [
6116
+ user.picture ? /* @__PURE__ */ jsxRuntime.jsx(AvatarImage, { src: user.picture, alt: name }) : null,
6117
+ /* @__PURE__ */ jsxRuntime.jsx(AvatarFallback, { style: tint, className: "text-xs font-semibold", children: userInitials(user) })
6118
+ ] });
6119
+ }
6120
+ function ConversationList({
6121
+ conversations,
6122
+ selectedPeerId,
6123
+ onSelect,
6124
+ classNames,
6125
+ emptyState
6126
+ }) {
6127
+ return /* @__PURE__ */ jsxRuntime.jsxs(
6128
+ "aside",
6129
+ {
6130
+ className: "flex min-h-0 flex-col border-b border-border md:w-80 md:shrink-0 md:border-b-0 md:border-r",
6131
+ "data-testid": "arbi-dm-list",
6132
+ children: [
6133
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "border-b border-border px-4 py-3", children: [
6134
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm font-semibold text-foreground", children: "Conversations" }),
6135
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-xs text-muted-foreground", children: [
6136
+ conversations.length,
6137
+ " ",
6138
+ conversations.length === 1 ? "colleague" : "colleagues"
6139
+ ] })
6140
+ ] }),
6141
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "min-h-0 flex-1 overflow-y-auto", children: conversations.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-4 py-6 text-xs text-muted-foreground", children: emptyState ?? "No conversations yet." }) : /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "w-full", children: conversations.map((c) => {
6142
+ const { peer, lastMessage, unreadCount } = c;
6143
+ const active = peer.external_id === selectedPeerId;
6144
+ const preview = `${lastMessage.isMine ? "You: " : ""}${lastMessage.body}`;
6145
+ return /* @__PURE__ */ jsxRuntime.jsx("li", { children: /* @__PURE__ */ jsxRuntime.jsxs(
6146
+ "button",
6147
+ {
6148
+ type: "button",
6149
+ onClick: () => onSelect(peer.external_id),
6150
+ "data-testid": `arbi-dm-conversation-${peer.external_id}`,
6151
+ className: cn(
6152
+ "flex w-full items-start gap-3 border-b border-border/60 px-4 py-3 text-left transition-colors",
6153
+ active ? "bg-accent" : "hover:bg-accent/60"
6154
+ ),
6155
+ children: [
6156
+ /* @__PURE__ */ jsxRuntime.jsx(DmAvatar, { user: peer }),
6157
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "min-w-0 flex-1", children: [
6158
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-2", children: [
6159
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate text-sm font-semibold text-foreground", children: userDisplayName(peer) }),
6160
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "shrink-0 text-[11px] text-muted-foreground", children: formatRelativeTime(lastMessage.createdAt) })
6161
+ ] }),
6162
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-1 flex items-center gap-2", children: [
6163
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "min-w-0 flex-1 truncate text-xs text-muted-foreground", children: preview }),
6164
+ unreadCount > 0 ? /* @__PURE__ */ jsxRuntime.jsx(Badge, { className: cn("px-1.5 py-0 text-[10px]", classNames?.unreadBadge), children: unreadCount }) : null
6165
+ ] })
6166
+ ] })
6167
+ ]
6168
+ }
6169
+ ) }, peer.external_id);
6170
+ }) }) })
6171
+ ]
6172
+ }
6173
+ );
6174
+ }
6175
+ function MessageBubble2({ message, classNames }) {
6176
+ const { isMine } = message;
6177
+ const who = isMine ? "You" : userDisplayName(message.sender);
6178
+ return /* @__PURE__ */ jsxRuntime.jsxs(
6179
+ "div",
6180
+ {
6181
+ "data-testid": "arbi-dm-message",
6182
+ className: cn("flex flex-col gap-1", isMine ? "items-end" : "items-start"),
6183
+ children: [
6184
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 px-1", children: [
6185
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[11px] font-medium text-foreground", children: who }),
6186
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[11px] text-muted-foreground", children: formatRelativeTime(message.createdAt) })
6187
+ ] }),
6188
+ /* @__PURE__ */ jsxRuntime.jsx(
6189
+ "div",
6190
+ {
6191
+ className: cn(
6192
+ "max-w-[80%] rounded-2xl px-3.5 py-2 text-sm shadow-sm",
6193
+ isMine ? cn("rounded-br-sm bg-accent text-accent-foreground", classNames?.ownBubble) : cn(
6194
+ "rounded-bl-sm border border-border bg-card text-card-foreground",
6195
+ classNames?.peerBubble
6196
+ )
6197
+ ),
6198
+ children: message.body
6199
+ }
6200
+ )
6201
+ ]
6202
+ }
6203
+ );
6204
+ }
6205
+ function MessageThread({ conversation, classNames, emptyState }) {
6206
+ const bottomRef = React.useRef(null);
6207
+ React.useEffect(() => {
6208
+ bottomRef.current?.scrollIntoView({ block: "end" });
6209
+ }, [conversation?.peer.external_id, conversation?.messages.length]);
6210
+ if (!conversation) {
6211
+ return /* @__PURE__ */ jsxRuntime.jsx("section", { className: "flex min-h-0 flex-1 flex-col items-center justify-center gap-3 p-8 text-center", children: emptyState ?? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
6212
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex size-14 items-center justify-center rounded-full bg-accent", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.MessagesSquare, { className: "size-6 text-muted-foreground" }) }),
6213
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
6214
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm font-semibold text-foreground", children: "No conversation selected" }),
6215
+ /* @__PURE__ */ jsxRuntime.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." })
6216
+ ] })
6217
+ ] }) });
6218
+ }
6219
+ const { peer, messages } = conversation;
6220
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
6221
+ /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex items-center gap-3 border-b border-border px-4 py-3", children: [
6222
+ /* @__PURE__ */ jsxRuntime.jsx(DmAvatar, { user: peer, className: "size-9" }),
6223
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "min-w-0", children: [
6224
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "truncate text-sm font-semibold text-foreground", children: userDisplayName(peer) }),
6225
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "truncate text-xs text-muted-foreground", children: peer.email })
6226
+ ] })
6227
+ ] }),
6228
+ /* @__PURE__ */ jsxRuntime.jsx(ScrollArea, { className: "min-h-0 flex-1 bg-background", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3 px-4 py-4", "data-testid": "arbi-dm-thread", children: [
6229
+ messages.map((m) => /* @__PURE__ */ jsxRuntime.jsx(MessageBubble2, { message: m, classNames }, m.externalId)),
6230
+ /* @__PURE__ */ jsxRuntime.jsx("div", { ref: bottomRef })
6231
+ ] }) })
6232
+ ] });
6233
+ }
6234
+ function DmComposer({ placeholder, disabled, onSend, classNames }) {
6235
+ const [draft, setDraft] = React.useState("");
6236
+ const submit = () => {
6237
+ const text = draft.trim();
6238
+ if (!text || disabled) return;
6239
+ onSend(text);
6240
+ setDraft("");
6241
+ };
6242
+ const onKeyDown = (e) => {
6243
+ if (e.key === "Enter" && !e.shiftKey) {
6244
+ e.preventDefault();
6245
+ submit();
6246
+ }
6247
+ };
6248
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "border-t border-border p-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-end gap-2", children: [
6249
+ /* @__PURE__ */ jsxRuntime.jsx(
6250
+ Textarea,
6251
+ {
6252
+ value: draft,
6253
+ onChange: (e) => setDraft(e.target.value),
6254
+ onKeyDown,
6255
+ placeholder,
6256
+ rows: 1,
6257
+ disabled,
6258
+ className: "max-h-40 min-h-[44px] resize-none",
6259
+ "data-testid": "arbi-dm-input"
6260
+ }
6261
+ ),
6262
+ /* @__PURE__ */ jsxRuntime.jsxs(
6263
+ Button,
6264
+ {
6265
+ type: "button",
6266
+ onClick: submit,
6267
+ disabled: disabled || !draft.trim(),
6268
+ className: cn(classNames?.sendButton),
6269
+ "data-testid": "arbi-dm-send",
6270
+ children: [
6271
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Send, { className: "size-4" }),
6272
+ " Send"
6273
+ ]
6274
+ }
6275
+ )
6276
+ ] }) });
6277
+ }
6278
+ function DirectMessages({
6279
+ className,
6280
+ classNames,
6281
+ emptyThread,
6282
+ emptyList
6283
+ }) {
6284
+ const { conversations, isLoading, sendMessage, markRead } = useDirectMessages();
6285
+ const [selectedPeerId, setSelectedPeerId] = React.useState(null);
6286
+ const selected = React.useMemo(
6287
+ () => conversations.find((c) => c.peer.external_id === selectedPeerId) ?? null,
6288
+ [conversations, selectedPeerId]
6289
+ );
6290
+ React.useEffect(() => {
6291
+ if (!selected || selected.unreadCount === 0) return;
6292
+ const unreadIds = selected.messages.filter((m) => !m.isMine && !m.read).map((m) => m.externalId);
6293
+ if (unreadIds.length) void markRead(unreadIds);
6294
+ }, [selected?.peer.external_id, selected?.unreadCount]);
6295
+ const handleSend = (text) => {
6296
+ if (!selected) return;
6297
+ void sendMessage(selected.peer.external_id, selected.peer.encryption_public_key, text);
6298
+ };
6299
+ return /* @__PURE__ */ jsxRuntime.jsxs(
6300
+ "div",
6301
+ {
6302
+ "data-testid": "arbi-dm",
6303
+ style: { height: "calc(100vh - 16rem)", minHeight: "28rem" },
6304
+ className: cn(
6305
+ "flex flex-col overflow-hidden rounded-xl border border-border bg-card md:flex-row",
6306
+ className
6307
+ ),
6308
+ children: [
6309
+ /* @__PURE__ */ jsxRuntime.jsx(
6310
+ ConversationList,
6311
+ {
6312
+ conversations,
6313
+ selectedPeerId: selected?.peer.external_id ?? null,
6314
+ onSelect: setSelectedPeerId,
6315
+ classNames,
6316
+ emptyState: isLoading ? "Loading messages\u2026" : emptyList
6317
+ }
6318
+ ),
6319
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex min-h-0 min-w-0 flex-1 flex-col", children: [
6320
+ /* @__PURE__ */ jsxRuntime.jsx(MessageThread, { conversation: selected, classNames, emptyState: emptyThread }),
6321
+ selected ? /* @__PURE__ */ jsxRuntime.jsx(
6322
+ DmComposer,
6323
+ {
6324
+ placeholder: `Message ${userDisplayName(selected.peer).split(" ")[0]}\u2026`,
6325
+ onSend: handleSend,
6326
+ classNames
6327
+ }
6328
+ ) : null
6329
+ ] })
6330
+ ]
6331
+ }
6332
+ );
6333
+ }
6334
+ var DEFAULT_ASPECT_OPTIONS = [
6335
+ { label: "1:1", value: 1 },
6336
+ { label: "4:3", value: 4 / 3 },
6337
+ { label: "3:4", value: 3 / 4 },
6338
+ { label: "16:9", value: 16 / 9 },
6339
+ { label: "9:16", value: 9 / 16 }
6340
+ ];
6341
+ function ImageCropper({
6342
+ image,
6343
+ aspect = 1,
6344
+ aspectOptions,
6345
+ cropShape = "rect",
6346
+ minZoom = 1,
6347
+ maxZoom = 3,
6348
+ className,
6349
+ onCropComplete
6350
+ }) {
6351
+ const [crop, setCrop] = React.useState({ x: 0, y: 0 });
6352
+ const [zoom, setZoom] = React.useState(1);
6353
+ const [activeAspect, setActiveAspect] = React.useState(aspectOptions?.[0]?.value ?? aspect);
6354
+ React.useEffect(() => {
6355
+ if (!aspectOptions) setActiveAspect(aspect);
6356
+ }, [aspect, aspectOptions]);
6357
+ const handleComplete = React.useCallback(
6358
+ (_, areaPixels) => {
6359
+ onCropComplete?.(areaPixels, activeAspect);
6360
+ },
6361
+ [onCropComplete, activeAspect]
6362
+ );
6363
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("flex flex-col gap-3", className), children: [
6364
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative h-72 w-full overflow-hidden rounded-md bg-foreground/95", children: /* @__PURE__ */ jsxRuntime.jsx(
6365
+ Cropper__default.default,
6366
+ {
6367
+ image,
6368
+ crop,
6369
+ zoom,
6370
+ aspect: activeAspect,
6371
+ cropShape,
6372
+ showGrid: cropShape === "rect",
6373
+ onCropChange: setCrop,
6374
+ onZoomChange: setZoom,
6375
+ onCropComplete: handleComplete,
6376
+ objectFit: "contain"
6377
+ }
6378
+ ) }),
6379
+ aspectOptions && aspectOptions.length > 1 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap items-center gap-1", "data-testid": "image-cropper-aspects", children: [
6380
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "mr-1 text-[11px] font-semibold uppercase tracking-wider text-muted-foreground", children: "Ratio" }),
6381
+ aspectOptions.map((opt) => {
6382
+ const on = opt.value === activeAspect;
6383
+ return /* @__PURE__ */ jsxRuntime.jsx(
6384
+ "button",
6385
+ {
6386
+ type: "button",
6387
+ onClick: () => setActiveAspect(opt.value),
6388
+ "data-testid": `image-cropper-aspect-${opt.label}`,
6389
+ className: cn(
6390
+ "rounded-md px-2 py-1 text-xs font-medium transition-colors",
6391
+ on ? "bg-primary text-primary-foreground" : "text-muted-foreground hover:bg-accent hover:text-foreground"
6392
+ ),
6393
+ children: opt.label
6394
+ },
6395
+ opt.label
6396
+ );
6397
+ })
6398
+ ] }) : null,
6399
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [
6400
+ /* @__PURE__ */ jsxRuntime.jsx("label", { className: "text-[11px] font-semibold uppercase tracking-wider text-muted-foreground", children: "Zoom" }),
6401
+ /* @__PURE__ */ jsxRuntime.jsx(
6402
+ Slider,
6403
+ {
6404
+ value: [zoom],
6405
+ onValueChange: ([v]) => setZoom(v ?? 1),
6406
+ min: minZoom,
6407
+ max: maxZoom,
6408
+ step: 0.01
6409
+ }
6410
+ )
6411
+ ] })
6412
+ ] });
6413
+ }
6414
+
6415
+ // src/imagecrop/cropImage.ts
6416
+ function loadImage(src) {
6417
+ return new Promise((resolve, reject) => {
6418
+ const img = new Image();
6419
+ img.crossOrigin = "anonymous";
6420
+ img.onload = () => resolve(img);
6421
+ img.onerror = () => reject(new Error("Failed to load image for cropping"));
6422
+ img.src = src;
6423
+ });
6424
+ }
6425
+ async function cropImage(imageSrc, area, output = {}) {
6426
+ const { maxSize, mimeType = "image/jpeg", quality = 0.9, background = "#ffffff" } = output;
6427
+ const img = await loadImage(imageSrc);
6428
+ let outW = Math.max(1, Math.round(area.width));
6429
+ let outH = Math.max(1, Math.round(area.height));
6430
+ if (maxSize && Math.max(outW, outH) > maxSize) {
6431
+ const scale = maxSize / Math.max(outW, outH);
6432
+ outW = Math.max(1, Math.round(outW * scale));
6433
+ outH = Math.max(1, Math.round(outH * scale));
6434
+ }
6435
+ const canvas = document.createElement("canvas");
6436
+ canvas.width = outW;
6437
+ canvas.height = outH;
6438
+ const ctx = canvas.getContext("2d");
6439
+ if (!ctx) throw new Error("canvas 2d context unavailable");
6440
+ if (mimeType === "image/jpeg") {
6441
+ ctx.fillStyle = background;
6442
+ ctx.fillRect(0, 0, outW, outH);
6443
+ }
6444
+ ctx.drawImage(img, area.x, area.y, area.width, area.height, 0, 0, outW, outH);
6445
+ const dataUrl = canvas.toDataURL(mimeType, quality);
6446
+ const blob = await new Promise(
6447
+ (resolve, reject) => canvas.toBlob(
6448
+ (b) => b ? resolve(b) : reject(new Error("canvas toBlob returned null")),
6449
+ mimeType,
6450
+ quality
6451
+ )
6452
+ );
6453
+ return { dataUrl, blob, width: outW, height: outH };
6454
+ }
6455
+ function ImageCropModal({
6456
+ open,
6457
+ image,
6458
+ title = "Crop image",
6459
+ saveLabel = "Save",
6460
+ aspect,
6461
+ aspectOptions,
6462
+ cropShape = "rect",
6463
+ output,
6464
+ onComplete,
6465
+ onCancel
6466
+ }) {
6467
+ const [area, setArea] = React.useState(null);
6468
+ const [busy, setBusy] = React.useState(false);
6469
+ const handleSave = async () => {
6470
+ if (!image || !area) return;
6471
+ setBusy(true);
6472
+ try {
6473
+ const result = await cropImage(image, area, output);
6474
+ await onComplete(result);
6475
+ } finally {
6476
+ setBusy(false);
6477
+ }
6478
+ };
6479
+ return /* @__PURE__ */ jsxRuntime.jsx(Dialog, { open, onOpenChange: (next) => !next ? onCancel() : void 0, children: /* @__PURE__ */ jsxRuntime.jsxs(DialogContent, { className: "sm:max-w-md", "data-testid": "image-crop-modal", children: [
6480
+ /* @__PURE__ */ jsxRuntime.jsx(DialogHeader, { children: /* @__PURE__ */ jsxRuntime.jsx(DialogTitle, { children: title }) }),
6481
+ image ? /* @__PURE__ */ jsxRuntime.jsx(
6482
+ ImageCropper,
6483
+ {
6484
+ image,
6485
+ aspect,
6486
+ aspectOptions,
6487
+ cropShape,
6488
+ onCropComplete: setArea
6489
+ }
6490
+ ) : null,
6491
+ /* @__PURE__ */ jsxRuntime.jsxs(DialogFooter, { className: "gap-2 sm:gap-2", children: [
6492
+ /* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "ghost", onClick: onCancel, disabled: busy, children: "Cancel" }),
6493
+ /* @__PURE__ */ jsxRuntime.jsxs(Button, { onClick: handleSave, disabled: !area || busy, "data-testid": "image-crop-save", children: [
6494
+ busy ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "mr-1 size-4 animate-spin" }) : null,
6495
+ saveLabel
6496
+ ] })
6497
+ ] })
6498
+ ] }) });
6499
+ }
6500
+ var MAX_NAV = 5;
6501
+ var MAX_DOCS = 4;
6502
+ function CommandPalette({
6503
+ open,
6504
+ onOpenChange,
6505
+ navItems,
6506
+ onNavigate,
6507
+ buildAskPrompt = (q) => q,
6508
+ askDocIds = [],
6509
+ model,
6510
+ searchDocIds,
6511
+ onOpenDoc,
6512
+ placeholder = "Ask AI, or jump to a page\u2026",
6513
+ askHint = "Grounded in the live workspace",
6514
+ classNames,
6515
+ testId = "command-palette"
6516
+ }) {
6517
+ const task = useAiTask();
6518
+ const searchable = !!searchDocIds && searchDocIds.length > 0;
6519
+ const { results, search, status: searchStatus } = useSemanticSearch(searchDocIds ?? []);
6520
+ const [query, setQuery] = React.useState("");
6521
+ const inputRef = React.useRef(null);
6522
+ React.useEffect(() => {
6523
+ if (open) {
6524
+ setQuery("");
6525
+ task.reset();
6526
+ const t = setTimeout(() => inputRef.current?.focus(), 40);
6527
+ return () => clearTimeout(t);
6528
+ }
6529
+ }, [open]);
6530
+ const showingAnswer = task.status !== "idle";
6531
+ React.useEffect(() => {
6532
+ if (!searchable || showingAnswer) return;
6533
+ const q = query.trim();
6534
+ if (q.length < 2) return;
6535
+ const t = setTimeout(() => void search(q, "hybrid"), 300);
6536
+ return () => clearTimeout(t);
6537
+ }, [query, searchable, showingAnswer, search]);
6538
+ const navMatches = React.useMemo(() => {
6539
+ const q = query.trim().toLowerCase();
6540
+ if (!q) return navItems.slice(0, MAX_NAV);
6541
+ return navItems.filter(
6542
+ (i) => i.label.toLowerCase().includes(q) || (i.keywords ? i.keywords.toLowerCase().includes(q) : false)
6543
+ ).slice(0, MAX_NAV);
6544
+ }, [query, navItems]);
6545
+ const docHits = React.useMemo(() => results.slice(0, MAX_DOCS), [results]);
6546
+ const go = (to) => {
6547
+ onOpenChange(false);
6548
+ onNavigate(to);
6549
+ };
6550
+ const openDoc = (docId) => {
6551
+ onOpenChange(false);
6552
+ onOpenDoc?.(docId);
6553
+ };
6554
+ const ask = () => {
6555
+ const q = query.trim();
6556
+ if (!q || task.isRunning) return;
6557
+ void task.run(buildAskPrompt(q), askDocIds, { model });
6558
+ };
6559
+ return /* @__PURE__ */ jsxRuntime.jsx(Dialog, { open, onOpenChange, children: /* @__PURE__ */ jsxRuntime.jsxs(
6560
+ DialogContent,
6561
+ {
6562
+ className: cn(
6563
+ "top-[12%] max-w-2xl translate-y-0 gap-0 overflow-hidden p-0",
6564
+ classNames?.dialog
6565
+ ),
6566
+ "data-testid": testId,
6567
+ children: [
6568
+ /* @__PURE__ */ jsxRuntime.jsx(DialogTitle, { className: "sr-only", children: "Command palette" }),
6569
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3 border-b border-border px-4", children: [
6570
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Sparkles, { className: cn("size-4 shrink-0 text-ai-accent", classNames?.leadingIcon) }),
6571
+ /* @__PURE__ */ jsxRuntime.jsx(
6572
+ "input",
6573
+ {
6574
+ ref: inputRef,
6575
+ value: query,
6576
+ onChange: (e) => setQuery(e.target.value),
6577
+ onKeyDown: (e) => {
6578
+ if (e.key === "Enter") {
6579
+ e.preventDefault();
6580
+ ask();
6581
+ }
6582
+ },
6583
+ placeholder,
6584
+ className: cn(
6585
+ "h-14 flex-1 bg-transparent text-base outline-none placeholder:text-muted-foreground",
6586
+ classNames?.input
6587
+ ),
6588
+ "data-testid": `${testId}-input`
6589
+ }
6590
+ ),
6591
+ /* @__PURE__ */ jsxRuntime.jsx("kbd", { className: "hidden rounded border border-border px-1.5 py-0.5 text-[10px] text-muted-foreground sm:inline", children: "\u2318K" })
6592
+ ] }),
6593
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "max-h-[60vh] overflow-y-auto p-2", children: [
6594
+ query.trim() && !showingAnswer && /* @__PURE__ */ jsxRuntime.jsxs(
6595
+ "button",
6596
+ {
6597
+ type: "button",
6598
+ onClick: ask,
6599
+ className: cn(
6600
+ "mb-1 flex w-full items-center gap-3 rounded-lg px-3 py-2.5 text-left hover:bg-accent",
6601
+ classNames?.askAction
6602
+ ),
6603
+ "data-testid": `${testId}-ask`,
6604
+ children: [
6605
+ /* @__PURE__ */ jsxRuntime.jsx(
6606
+ "span",
6607
+ {
6608
+ className: cn(
6609
+ "flex size-8 items-center justify-center rounded-md bg-ai-surface text-ai-accent",
6610
+ classNames?.askChip
6611
+ ),
6612
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Sparkles, { className: "size-4" })
6613
+ }
6614
+ ),
6615
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "min-w-0 flex-1", children: [
6616
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "block truncate text-sm font-medium text-foreground", children: [
6617
+ "Ask AI: \u201C",
6618
+ query.trim(),
6619
+ "\u201D"
6620
+ ] }),
6621
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "block text-xs text-muted-foreground", children: askHint })
6622
+ ] }),
6623
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CornerDownLeft, { className: "size-4 text-muted-foreground" })
6624
+ ]
6625
+ }
6626
+ ),
6627
+ showingAnswer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-3 py-2", "data-testid": `${testId}-answer`, children: [
6628
+ /* @__PURE__ */ jsxRuntime.jsx(
6629
+ AiAnswer,
6630
+ {
6631
+ status: task.status,
6632
+ text: task.text,
6633
+ stepCount: task.stepCount,
6634
+ error: task.error,
6635
+ testId: `${testId}-ai`
6636
+ }
6637
+ ),
6638
+ task.isDone && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-3 flex justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(
6639
+ Button,
6640
+ {
6641
+ variant: "outline",
6642
+ size: "sm",
6643
+ onClick: () => task.reset(),
6644
+ "data-testid": `${testId}-clear`,
6645
+ children: "Ask another"
6646
+ }
6647
+ ) })
6648
+ ] }),
6649
+ !showingAnswer && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
6650
+ /* @__PURE__ */ jsxRuntime.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" }),
6651
+ navMatches.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "px-3 py-2 text-sm text-muted-foreground", children: "No pages match \u2014 press Enter to ask AI." }),
6652
+ navMatches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
6653
+ "button",
6654
+ {
6655
+ type: "button",
6656
+ onClick: () => go(item.to),
6657
+ className: cn(
6658
+ "flex w-full items-center gap-3 rounded-lg px-3 py-2 text-left hover:bg-accent",
6659
+ classNames?.navItem
6660
+ ),
6661
+ "data-testid": `${testId}-nav-${item.id}`,
6662
+ children: [
6663
+ item.icon && /* @__PURE__ */ jsxRuntime.jsx(item.icon, { className: "size-4 text-muted-foreground" }),
6664
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-1 text-sm text-foreground", children: item.label }),
6665
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ArrowRight, { className: "size-3.5 text-muted-foreground" })
6666
+ ]
6667
+ },
6668
+ item.id
6669
+ )),
6670
+ searchable && query.trim().length >= 2 && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
6671
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "px-3 pb-1 pt-3 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground", children: "Documents" }),
6672
+ searchStatus === "done" && docHits.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "px-3 py-2 text-sm text-muted-foreground", children: "No passages matched." }),
6673
+ docHits.map((hit, i) => /* @__PURE__ */ jsxRuntime.jsxs(
6674
+ "button",
6675
+ {
6676
+ type: "button",
6677
+ onClick: () => hit.docId && openDoc(hit.docId),
6678
+ className: "flex w-full items-start gap-3 rounded-lg px-3 py-2 text-left hover:bg-accent",
6679
+ "data-testid": `${testId}-doc-${i}`,
6680
+ children: [
6681
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.FileText, { className: "mt-0.5 size-4 shrink-0 text-ai-accent" }),
6682
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "min-w-0 flex-1", children: [
6683
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "block truncate text-sm text-foreground", children: [
6684
+ hit.docTitle ?? "Document",
6685
+ hit.page != null && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-muted-foreground", children: [
6686
+ " \xB7 p.",
6687
+ hit.page
6688
+ ] })
6689
+ ] }),
6690
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "line-clamp-1 text-xs text-muted-foreground", children: hit.content })
6691
+ ] })
6692
+ ]
6693
+ },
6694
+ `${hit.docId}-${hit.page}-${i}`
6695
+ ))
6696
+ ] })
6697
+ ] })
6698
+ ] })
6699
+ ]
6700
+ }
6701
+ ) });
6702
+ }
6703
+ var CommandPaletteCtx = React.createContext(null);
6704
+ function useCommandPalette() {
6705
+ const v = React.useContext(CommandPaletteCtx);
6706
+ if (!v) throw new Error("useCommandPalette must be used within a CommandPaletteProvider");
6707
+ return v;
6708
+ }
6709
+ function CommandPaletteProvider({
6710
+ children,
6711
+ hotkey = true,
6712
+ ...paletteProps
6713
+ }) {
6714
+ const [isOpen, setIsOpen] = React.useState(false);
6715
+ const open = React.useCallback(() => setIsOpen(true), []);
6716
+ const close = React.useCallback(() => setIsOpen(false), []);
6717
+ const toggle = React.useCallback(() => setIsOpen((o) => !o), []);
6718
+ React.useEffect(() => {
6719
+ if (!hotkey) return;
6720
+ const onKey = (e) => {
6721
+ if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "k") {
6722
+ e.preventDefault();
6723
+ toggle();
6724
+ }
6725
+ };
6726
+ window.addEventListener("keydown", onKey);
6727
+ return () => window.removeEventListener("keydown", onKey);
6728
+ }, [hotkey, toggle]);
6729
+ const value = React.useMemo(() => ({ open, close, toggle, isOpen }), [open, close, toggle, isOpen]);
6730
+ return /* @__PURE__ */ jsxRuntime.jsxs(CommandPaletteCtx.Provider, { value, children: [
6731
+ children,
6732
+ /* @__PURE__ */ jsxRuntime.jsx(CommandPalette, { open: isOpen, onOpenChange: setIsOpen, ...paletteProps })
6733
+ ] });
6734
+ }
6735
+ function nameInitials(name) {
6736
+ const parts = name.trim().split(/\s+/).filter(Boolean);
6737
+ if (!parts.length) return "?";
6738
+ return parts.slice(0, 2).map((p) => p[0]?.toUpperCase() ?? "").join("");
6739
+ }
6740
+ function UserMenu({
6741
+ user,
6742
+ items = [],
6743
+ onLogout,
6744
+ logoutLabel = "Sign out",
6745
+ align = "end",
6746
+ classNames,
6747
+ testId = "user-menu",
6748
+ logoutTestId
6749
+ }) {
6750
+ return /* @__PURE__ */ jsxRuntime.jsxs(DropdownMenu, { children: [
6751
+ /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(
6752
+ "button",
6753
+ {
6754
+ className: cn(
6755
+ "flex items-center gap-2 rounded-md px-1.5 py-1 transition-colors hover:bg-accent",
6756
+ classNames?.trigger
6757
+ ),
6758
+ "data-testid": testId,
6759
+ children: [
6760
+ /* @__PURE__ */ jsxRuntime.jsxs(Avatar, { className: "size-8", children: [
6761
+ user.picture ? /* @__PURE__ */ jsxRuntime.jsx(AvatarImage, { src: user.picture, alt: user.name }) : null,
6762
+ /* @__PURE__ */ jsxRuntime.jsx(
6763
+ AvatarFallback,
6764
+ {
6765
+ className: cn("bg-primary text-primary-foreground", classNames?.fallback),
6766
+ children: nameInitials(user.name)
6767
+ }
6768
+ )
6769
+ ] }),
6770
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronDown, { className: "size-4 text-muted-foreground" })
6771
+ ]
6772
+ }
6773
+ ) }),
6774
+ /* @__PURE__ */ jsxRuntime.jsxs(DropdownMenuContent, { align, className: "w-56", children: [
6775
+ /* @__PURE__ */ jsxRuntime.jsxs(DropdownMenuLabel, { children: [
6776
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-medium text-foreground", children: user.name }),
6777
+ user.email && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs font-normal text-muted-foreground", children: user.email })
6778
+ ] }),
6779
+ /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuSeparator, {}),
6780
+ items.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(DropdownMenuItem, { onClick: item.onSelect, "data-testid": item.testId, children: [
6781
+ item.icon && /* @__PURE__ */ jsxRuntime.jsx(item.icon, { className: "size-4" }),
6782
+ item.label
6783
+ ] }, item.label)),
6784
+ /* @__PURE__ */ jsxRuntime.jsxs(DropdownMenuItem, { onClick: onLogout, "data-testid": logoutTestId ?? `${testId}-logout`, children: [
6785
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.LogOut, { className: "size-4" }),
6786
+ logoutLabel
6787
+ ] })
6788
+ ] })
6789
+ ] });
6790
+ }
5782
6791
  var useArbiUiStore = zustand.create((set) => ({
5783
6792
  selectedDocIds: [],
5784
6793
  setSelectedDocIds: (ids) => set({ selectedDocIds: ids }),
@@ -6399,8 +7408,13 @@ exports.CommandGroup = CommandGroup;
6399
7408
  exports.CommandInput = CommandInput;
6400
7409
  exports.CommandItem = CommandItem;
6401
7410
  exports.CommandList = CommandList;
7411
+ exports.CommandPalette = CommandPalette;
7412
+ exports.CommandPaletteProvider = CommandPaletteProvider;
6402
7413
  exports.CommandSeparator = CommandSeparator;
6403
7414
  exports.CommandShortcut = CommandShortcut;
7415
+ exports.ConversationList = ConversationList;
7416
+ exports.DEFAULT_ASPECT_OPTIONS = DEFAULT_ASPECT_OPTIONS;
7417
+ exports.DEFAULT_NOTIFY_TONE = DEFAULT_NOTIFY_TONE;
6404
7418
  exports.Dialog = Dialog;
6405
7419
  exports.DialogClose = DialogClose;
6406
7420
  exports.DialogContent = DialogContent;
@@ -6411,6 +7425,9 @@ exports.DialogOverlay = DialogOverlay;
6411
7425
  exports.DialogPortal = DialogPortal;
6412
7426
  exports.DialogTitle = DialogTitle;
6413
7427
  exports.DialogTrigger = DialogTrigger;
7428
+ exports.DirectMessages = DirectMessages;
7429
+ exports.DmAvatar = DmAvatar;
7430
+ exports.DmComposer = DmComposer;
6414
7431
  exports.DocIcon = DocIcon;
6415
7432
  exports.DocQaPanel = DocQaPanel;
6416
7433
  exports.DocSearch = DocSearch;
@@ -6447,12 +7464,17 @@ exports.HoverCard = HoverCard;
6447
7464
  exports.HoverCardContent = HoverCardContent;
6448
7465
  exports.HoverCardTrigger = HoverCardTrigger;
6449
7466
  exports.HtmlIcon = HtmlIcon;
7467
+ exports.ImageCropModal = ImageCropModal;
7468
+ exports.ImageCropper = ImageCropper;
6450
7469
  exports.ImgIcon = ImgIcon;
6451
7470
  exports.Input = Input;
6452
7471
  exports.Label = Label;
6453
7472
  exports.LinkedInIcon = LinkedInIcon;
6454
7473
  exports.MessageArtifactCard = MessageArtifactCard;
7474
+ exports.MessageBubble = MessageBubble2;
7475
+ exports.MessageThread = MessageThread;
6455
7476
  exports.NEUTRAL_GRAY = NEUTRAL_GRAY2;
7477
+ exports.NotificationBell = NotificationBell;
6456
7478
  exports.OpenAIIcon = OpenAIIcon;
6457
7479
  exports.PLACEHOLDER_COLOR = PLACEHOLDER_COLOR;
6458
7480
  exports.PdfIcon = PdfIcon;
@@ -6496,6 +7518,7 @@ exports.TabsList = TabsList;
6496
7518
  exports.TabsTrigger = TabsTrigger;
6497
7519
  exports.TagEntity = TagEntity;
6498
7520
  exports.Textarea = Textarea;
7521
+ exports.Toaster = Toaster;
6499
7522
  exports.Toggle = Toggle;
6500
7523
  exports.ToggleGroup = ToggleGroup;
6501
7524
  exports.ToggleGroupItem = ToggleGroupItem;
@@ -6506,6 +7529,7 @@ exports.TooltipTrigger = TooltipTrigger;
6506
7529
  exports.TxtIcon = TxtIcon;
6507
7530
  exports.TypingIndicator = TypingIndicator;
6508
7531
  exports.UserEntity = UserEntity;
7532
+ exports.UserMenu = UserMenu;
6509
7533
  exports.VISIBILITY_ICONS = VISIBILITY_ICONS;
6510
7534
  exports.VidIcon = VidIcon;
6511
7535
  exports.VisibilityIcon = VisibilityIcon;
@@ -6516,7 +7540,9 @@ exports.buttonVariants = buttonVariants;
6516
7540
  exports.cardVariants = cardVariants;
6517
7541
  exports.cn = cn;
6518
7542
  exports.configureEntityRegistry = configureEntityRegistry;
7543
+ exports.cropImage = cropImage;
6519
7544
  exports.describeActivity = describeActivity;
7545
+ exports.formatRelativeTime = formatRelativeTime;
6520
7546
  exports.getEntityColor = getEntityColor2;
6521
7547
  exports.getEntityColorStyles = getEntityColorStyles;
6522
7548
  exports.getEntityIcon = getEntityIcon;
@@ -6529,8 +7555,11 @@ exports.getWorkspaceColor = getWorkspaceColor;
6529
7555
  exports.getWorkspaceSentPhrase = getWorkspaceSentPhrase;
6530
7556
  exports.isWorkspaceNotificationType = isWorkspaceNotificationType;
6531
7557
  exports.markdownBaseComponents = markdownBaseComponents;
7558
+ exports.notify = notify;
6532
7559
  exports.parseActivityContent = parseActivityContent;
6533
7560
  exports.redlineStats = redlineStats;
7561
+ exports.seedNotifications = seedNotifications;
7562
+ exports.selectUnread = selectUnread;
6534
7563
  exports.textToArtifact = textToArtifact;
6535
7564
  exports.toRedlineMarkdown = toRedlineMarkdown;
6536
7565
  exports.toggleVariants = toggleVariants;
@@ -6549,12 +7578,15 @@ exports.useArbiWsStore = useArbiWsStore;
6549
7578
  exports.useArbiWsTask = useArbiWsTask;
6550
7579
  exports.useArbiWsTasks = useArbiWsTasks;
6551
7580
  exports.useAssistantQuery = useAssistantQuery;
7581
+ exports.useCommandPalette = useCommandPalette;
6552
7582
  exports.useConfigs = useConfigs;
6553
7583
  exports.useConversations = useConversations;
6554
7584
  exports.useDeleteAgents = useDeleteAgents;
7585
+ exports.useDirectMessages = useDirectMessages;
6555
7586
  exports.useDocuments = useDocuments;
6556
7587
  exports.useHealth = useHealth;
6557
7588
  exports.useMemories = useMemories;
7589
+ exports.useNotify = useNotify;
6558
7590
  exports.useParsedDocument = useParsedDocument;
6559
7591
  exports.useProjectInvoices = useProjectInvoices;
6560
7592
  exports.useProjectUsage = useProjectUsage;
@@ -6569,5 +7601,7 @@ exports.useUserUsageToday = useUserUsageToday;
6569
7601
  exports.useWorkspaceChronology = useWorkspaceChronology;
6570
7602
  exports.useWorkspaceDocs = useWorkspaceDocs;
6571
7603
  exports.useWorkspaces = useWorkspaces;
7604
+ exports.userDisplayName = userDisplayName;
7605
+ exports.userInitials = userInitials;
6572
7606
  //# sourceMappingURL=index.cjs.map
6573
7607
  //# sourceMappingURL=index.cjs.map