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