@arbidocs/react 0.3.100 → 0.3.101

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,8 +1,20 @@
1
- import { createContext, useMemo, useContext, useState, useCallback, useRef, useEffect } from 'react';
1
+ import * as React from 'react';
2
+ import React__default, { createContext, forwardRef, useMemo, useContext, useState, useCallback, useEffect, useRef } from 'react';
2
3
  import { Arbi, resolveCitations, summarizeCitations } from '@arbidocs/sdk/browser';
3
4
  export { Arbi, ArbiError } from '@arbidocs/sdk/browser';
4
5
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
6
  import { useQuery, useMutation, QueryClient, QueryClientProvider } from '@tanstack/react-query';
7
+ import { createPortal } from 'react-dom';
8
+ import { clsx } from 'clsx';
9
+ import { twMerge } from 'tailwind-merge';
10
+ import * as AvatarPrimitive from '@radix-ui/react-avatar';
11
+ import { cva } from 'class-variance-authority';
12
+ import { Slot } from '@radix-ui/react-slot';
13
+ import * as HoverCardPrimitive from '@radix-ui/react-hover-card';
14
+ import { MoreVertical, Eye, FolderOpen, Bot, Calendar, Search, Folder, StickyNote, Hash, List, SquareCheckBig, Package } from 'lucide-react';
15
+ import { AgGridReact } from 'ag-grid-react';
16
+ import { ModuleRegistry, AllCommunityModule } from 'ag-grid-community';
17
+ import { create } from 'zustand';
6
18
 
7
19
  // src/ArbiProvider.tsx
8
20
  var ArbiContext = createContext(null);
@@ -1079,18 +1091,23 @@ function ChatWidget({ theme, labels, initialWorkspaceId, width, height }) {
1079
1091
  const arbi = useArbi();
1080
1092
  const [screen, setScreen] = useState("auth");
1081
1093
  const [workspaceId, setWorkspaceId] = useState(initialWorkspaceId);
1082
- const handleLogin = useCallback(async () => {
1094
+ const resolveWorkspace = useCallback(async () => {
1083
1095
  if (initialWorkspaceId) {
1084
1096
  try {
1085
1097
  await arbi.selectWorkspace(initialWorkspaceId);
1086
1098
  setScreen("chat");
1099
+ return;
1087
1100
  } catch {
1088
1101
  setScreen("workspace");
1102
+ return;
1089
1103
  }
1090
- } else {
1091
- setScreen("workspace");
1092
1104
  }
1105
+ setScreen("workspace");
1093
1106
  }, [arbi, initialWorkspaceId]);
1107
+ const handleLogin = useCallback(() => resolveWorkspace(), [resolveWorkspace]);
1108
+ useEffect(() => {
1109
+ if (arbi.isLoggedIn) void resolveWorkspace();
1110
+ }, [arbi, resolveWorkspace]);
1094
1111
  const handleWorkspaceSelect = useCallback((id) => {
1095
1112
  setWorkspaceId(id);
1096
1113
  setScreen("chat");
@@ -1124,6 +1141,26 @@ function ChatWidget({ theme, labels, initialWorkspaceId, width, height }) {
1124
1141
  ] })
1125
1142
  ] });
1126
1143
  }
1144
+ function ArbiChatPanel({
1145
+ workspaceId,
1146
+ theme: themeOverrides,
1147
+ labels: labelOverrides,
1148
+ width = "100%",
1149
+ height = "100%"
1150
+ }) {
1151
+ const theme = useMemo(() => getTheme(themeOverrides), [themeOverrides]);
1152
+ const labels = useMemo(() => getLabels(labelOverrides), [labelOverrides]);
1153
+ return /* @__PURE__ */ jsx(
1154
+ ChatWidget,
1155
+ {
1156
+ theme,
1157
+ labels,
1158
+ initialWorkspaceId: workspaceId,
1159
+ width,
1160
+ height
1161
+ }
1162
+ );
1163
+ }
1127
1164
  function ArbiChat({
1128
1165
  url,
1129
1166
  workspaceId,
@@ -1141,20 +1178,1263 @@ function ArbiChat({
1141
1178
  }),
1142
1179
  []
1143
1180
  );
1144
- const theme = useMemo(() => getTheme(themeOverrides), [themeOverrides]);
1145
- const labels = useMemo(() => getLabels(labelOverrides), [labelOverrides]);
1146
1181
  return /* @__PURE__ */ jsx(QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ jsx(ArbiProvider, { url, children: /* @__PURE__ */ jsx(
1147
- ChatWidget,
1182
+ ArbiChatPanel,
1148
1183
  {
1149
- theme,
1150
- labels,
1151
- initialWorkspaceId: workspaceId,
1184
+ workspaceId,
1185
+ theme: themeOverrides,
1186
+ labels: labelOverrides,
1152
1187
  width,
1153
1188
  height
1154
1189
  }
1155
1190
  ) }) });
1156
1191
  }
1192
+ function cn(...inputs) {
1193
+ return twMerge(clsx(inputs));
1194
+ }
1195
+ var TooltipContext = React.createContext(null);
1196
+ var TooltipProvider = ({ children }) => /* @__PURE__ */ jsx(Fragment, { children });
1197
+ function Tooltip({ children, delayDuration = 300 }) {
1198
+ const [open, setOpen] = React.useState(false);
1199
+ const triggerRef = React.useRef(null);
1200
+ const timer = React.useRef(null);
1201
+ const contentId = React.useId();
1202
+ const clearTimer = () => {
1203
+ if (timer.current) {
1204
+ clearTimeout(timer.current);
1205
+ timer.current = null;
1206
+ }
1207
+ };
1208
+ const show = React.useCallback(() => {
1209
+ clearTimer();
1210
+ timer.current = setTimeout(() => setOpen(true), delayDuration);
1211
+ }, [delayDuration]);
1212
+ const hide = React.useCallback(() => {
1213
+ clearTimer();
1214
+ setOpen(false);
1215
+ }, []);
1216
+ const setTrigger = React.useCallback((el) => {
1217
+ triggerRef.current = el;
1218
+ }, []);
1219
+ React.useEffect(() => () => clearTimer(), []);
1220
+ const value = React.useMemo(
1221
+ () => ({ open, show, hide, setTrigger, triggerRef, contentId }),
1222
+ [open, show, hide, setTrigger, contentId]
1223
+ );
1224
+ return /* @__PURE__ */ jsx(TooltipContext.Provider, { value, children });
1225
+ }
1226
+ function TooltipTrigger({ asChild, children, ...props }) {
1227
+ const ctx = React.useContext(TooltipContext);
1228
+ if (!ctx) return /* @__PURE__ */ jsx(Fragment, { children });
1229
+ const triggerHandlers = {
1230
+ onPointerEnter: (e) => {
1231
+ props.onPointerEnter?.(e);
1232
+ ctx.show();
1233
+ },
1234
+ onPointerLeave: (e) => {
1235
+ props.onPointerLeave?.(e);
1236
+ ctx.hide();
1237
+ },
1238
+ onFocus: (e) => {
1239
+ props.onFocus?.(e);
1240
+ ctx.show();
1241
+ },
1242
+ onBlur: (e) => {
1243
+ props.onBlur?.(e);
1244
+ ctx.hide();
1245
+ },
1246
+ "aria-describedby": ctx.open ? ctx.contentId : void 0,
1247
+ "data-state": ctx.open ? "open" : "closed"
1248
+ };
1249
+ if (asChild && React.isValidElement(children)) {
1250
+ const child = children;
1251
+ return React.cloneElement(child, {
1252
+ ...props,
1253
+ ...triggerHandlers,
1254
+ ref: ctx.setTrigger
1255
+ });
1256
+ }
1257
+ return /* @__PURE__ */ jsx(
1258
+ "button",
1259
+ {
1260
+ type: "button",
1261
+ ...props,
1262
+ ...triggerHandlers,
1263
+ ref: ctx.setTrigger,
1264
+ children
1265
+ }
1266
+ );
1267
+ }
1268
+ var TRANSFORM_BY_SIDE = {
1269
+ top: "translate(-50%, -100%)",
1270
+ bottom: "translate(-50%, 0)",
1271
+ left: "translate(-100%, -50%)",
1272
+ right: "translate(0, -50%)"
1273
+ };
1274
+ var TooltipContent = React.forwardRef(
1275
+ ({ className, side = "top", sideOffset = 4, style, ...props }, ref) => {
1276
+ const ctx = React.useContext(TooltipContext);
1277
+ const innerRef = React.useRef(null);
1278
+ const [coords, setCoords] = React.useState(null);
1279
+ React.useLayoutEffect(() => {
1280
+ if (!ctx?.open || !ctx.triggerRef.current) {
1281
+ setCoords(null);
1282
+ return;
1283
+ }
1284
+ const r = ctx.triggerRef.current.getBoundingClientRect();
1285
+ const c = innerRef.current?.getBoundingClientRect();
1286
+ const ch = c?.height ?? 0;
1287
+ const cw = c?.width ?? 0;
1288
+ const vh = window.innerHeight;
1289
+ const vw = window.innerWidth;
1290
+ let s = side;
1291
+ if (s === "top" && r.top - sideOffset - ch < 0) s = "bottom";
1292
+ else if (s === "bottom" && r.bottom + sideOffset + ch > vh) s = "top";
1293
+ else if (s === "left" && r.left - sideOffset - cw < 0) s = "right";
1294
+ else if (s === "right" && r.right + sideOffset + cw > vw) s = "left";
1295
+ setCoords({
1296
+ top: s === "top" ? r.top - sideOffset : s === "bottom" ? r.bottom + sideOffset : r.top + r.height / 2,
1297
+ left: s === "left" ? r.left - sideOffset : s === "right" ? r.right + sideOffset : r.left + r.width / 2,
1298
+ transform: TRANSFORM_BY_SIDE[s]
1299
+ });
1300
+ }, [ctx?.open, side, sideOffset, ctx?.triggerRef]);
1301
+ if (!ctx?.open) return null;
1302
+ const setRefs = (node) => {
1303
+ innerRef.current = node;
1304
+ if (typeof ref === "function") ref(node);
1305
+ else if (ref) ref.current = node;
1306
+ };
1307
+ return createPortal(
1308
+ /* @__PURE__ */ jsx(
1309
+ "div",
1310
+ {
1311
+ ref: setRefs,
1312
+ id: ctx.contentId,
1313
+ role: "tooltip",
1314
+ className: cn("tooltip-content pointer-events-none", className),
1315
+ style: {
1316
+ position: "fixed",
1317
+ top: coords?.top ?? -9999,
1318
+ left: coords?.left ?? -9999,
1319
+ transform: coords?.transform ?? TRANSFORM_BY_SIDE[side],
1320
+ opacity: coords ? void 0 : 0,
1321
+ zIndex: 9999,
1322
+ ...style
1323
+ },
1324
+ ...props
1325
+ }
1326
+ ),
1327
+ document.body
1328
+ );
1329
+ }
1330
+ );
1331
+ TooltipContent.displayName = "TooltipContent";
1332
+ var Avatar = React.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
1333
+ AvatarPrimitive.Root,
1334
+ {
1335
+ ref,
1336
+ className: cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full", className),
1337
+ ...props
1338
+ }
1339
+ ));
1340
+ Avatar.displayName = AvatarPrimitive.Root.displayName;
1341
+ var AvatarImage = React.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
1342
+ AvatarPrimitive.Image,
1343
+ {
1344
+ ref,
1345
+ className: cn("aspect-square h-full w-full", className),
1346
+ ...props
1347
+ }
1348
+ ));
1349
+ AvatarImage.displayName = AvatarPrimitive.Image.displayName;
1350
+ var AvatarFallback = React.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
1351
+ AvatarPrimitive.Fallback,
1352
+ {
1353
+ ref,
1354
+ className: cn(
1355
+ "flex h-full w-full items-center justify-center rounded-full bg-muted",
1356
+ className
1357
+ ),
1358
+ ...props
1359
+ }
1360
+ ));
1361
+ AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName;
1362
+ var badgeVariants = cva(
1363
+ "inline-flex items-center rounded-md border px-2.5 py-0.5 text-sm font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
1364
+ {
1365
+ variants: {
1366
+ variant: {
1367
+ default: "border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80",
1368
+ secondary: "border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
1369
+ destructive: "border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",
1370
+ outline: "text-foreground"
1371
+ }
1372
+ },
1373
+ defaultVariants: {
1374
+ variant: "default"
1375
+ }
1376
+ }
1377
+ );
1378
+ function Badge({ className, variant, ...props }) {
1379
+ return /* @__PURE__ */ jsx("div", { className: cn(badgeVariants({ variant }), className), ...props });
1380
+ }
1381
+ var buttonVariants = cva(
1382
+ "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-base font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",
1383
+ {
1384
+ variants: {
1385
+ variant: {
1386
+ default: "bg-primary text-primary-foreground shadow hover:bg-primary/90",
1387
+ destructive: "bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
1388
+ outline: "border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
1389
+ secondary: "bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
1390
+ ghost: "hover:bg-accent hover:text-accent-foreground",
1391
+ link: "text-primary underline-offset-4 hover:underline"
1392
+ },
1393
+ size: {
1394
+ default: "h-9 px-4 py-2",
1395
+ sm: "h-8 rounded-md px-3",
1396
+ lg: "h-10 rounded-md px-8",
1397
+ icon: "h-9 w-9"
1398
+ }
1399
+ },
1400
+ defaultVariants: {
1401
+ variant: "default",
1402
+ size: "default"
1403
+ }
1404
+ }
1405
+ );
1406
+ var Button = React.forwardRef(
1407
+ ({ className, variant, size, asChild = false, ...props }, ref) => {
1408
+ const Comp = asChild ? Slot : "button";
1409
+ return /* @__PURE__ */ jsx(Comp, { className: cn(buttonVariants({ variant, size, className })), ref, ...props });
1410
+ }
1411
+ );
1412
+ Button.displayName = "Button";
1413
+ var HoverCard = HoverCardPrimitive.Root;
1414
+ var HoverCardTrigger = HoverCardPrimitive.Trigger;
1415
+ var HoverCardContent = React.forwardRef(({ className, align = "center", sideOffset = 4, ...props }, ref) => /* @__PURE__ */ jsx(HoverCardPrimitive.Portal, { children: /* @__PURE__ */ jsx(
1416
+ HoverCardPrimitive.Content,
1417
+ {
1418
+ ref,
1419
+ align,
1420
+ sideOffset,
1421
+ className: cn(
1422
+ "z-50 w-64 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-hover-card-content-transform-origin]",
1423
+ className
1424
+ ),
1425
+ ...props
1426
+ }
1427
+ ) }));
1428
+ HoverCardContent.displayName = HoverCardPrimitive.Content.displayName;
1429
+
1430
+ // src/icons/colors.ts
1431
+ var NEUTRAL_GRAY = "#64748b";
1432
+ var FILE_TYPE_COLORS = {
1433
+ pdf: "#ef4444",
1434
+ // red
1435
+ img: "#8b5cf6",
1436
+ // violet-500 (images)
1437
+ vid: "#10b981",
1438
+ // emerald-500 (video)
1439
+ aud: "#f59e0b",
1440
+ // amber-500 (audio)
1441
+ eml: "#0d9488",
1442
+ // teal-600 (email)
1443
+ generic: NEUTRAL_GRAY,
1444
+ // gray (unknown)
1445
+ white: "#ffffff"
1446
+ // for strokes/text on colored backgrounds
1447
+ };
1448
+ var PdfIcon = ({ size = 16, className = "" }) => {
1449
+ return /* @__PURE__ */ jsxs(
1450
+ "svg",
1451
+ {
1452
+ width: size,
1453
+ height: size,
1454
+ viewBox: "0 0 24 24",
1455
+ fill: "none",
1456
+ xmlns: "http://www.w3.org/2000/svg",
1457
+ className,
1458
+ children: [
1459
+ /* @__PURE__ */ jsx(
1460
+ "path",
1461
+ {
1462
+ d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6z",
1463
+ fill: FILE_TYPE_COLORS.pdf,
1464
+ stroke: FILE_TYPE_COLORS.pdf,
1465
+ strokeWidth: "1",
1466
+ strokeLinecap: "round",
1467
+ strokeLinejoin: "round"
1468
+ }
1469
+ ),
1470
+ /* @__PURE__ */ jsx(
1471
+ "path",
1472
+ {
1473
+ d: "M14 2v6h6",
1474
+ fill: "none",
1475
+ stroke: FILE_TYPE_COLORS.white,
1476
+ strokeWidth: "1",
1477
+ strokeLinecap: "round",
1478
+ strokeLinejoin: "round"
1479
+ }
1480
+ ),
1481
+ /* @__PURE__ */ jsx(
1482
+ "text",
1483
+ {
1484
+ x: "12",
1485
+ y: "16",
1486
+ fontSize: "6",
1487
+ fill: "white",
1488
+ textAnchor: "middle",
1489
+ fontWeight: "bold",
1490
+ fontFamily: "Arial, sans-serif",
1491
+ children: "PDF"
1492
+ }
1493
+ )
1494
+ ]
1495
+ }
1496
+ );
1497
+ };
1498
+ var AudIcon = ({ size = 16, className = "" }) => {
1499
+ return /* @__PURE__ */ jsxs(
1500
+ "svg",
1501
+ {
1502
+ width: size,
1503
+ height: size,
1504
+ viewBox: "0 0 24 24",
1505
+ fill: "none",
1506
+ xmlns: "http://www.w3.org/2000/svg",
1507
+ className,
1508
+ children: [
1509
+ /* @__PURE__ */ jsx(
1510
+ "path",
1511
+ {
1512
+ d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6z",
1513
+ fill: FILE_TYPE_COLORS.aud,
1514
+ stroke: FILE_TYPE_COLORS.aud,
1515
+ strokeWidth: "1",
1516
+ strokeLinecap: "round",
1517
+ strokeLinejoin: "round"
1518
+ }
1519
+ ),
1520
+ /* @__PURE__ */ jsx(
1521
+ "path",
1522
+ {
1523
+ d: "M14 2v6h6",
1524
+ fill: "none",
1525
+ stroke: FILE_TYPE_COLORS.white,
1526
+ strokeWidth: "1",
1527
+ strokeLinecap: "round",
1528
+ strokeLinejoin: "round"
1529
+ }
1530
+ ),
1531
+ /* @__PURE__ */ jsx(
1532
+ "text",
1533
+ {
1534
+ x: "12",
1535
+ y: "16",
1536
+ fontSize: "6",
1537
+ fill: "white",
1538
+ textAnchor: "middle",
1539
+ fontWeight: "bold",
1540
+ fontFamily: "Arial, sans-serif",
1541
+ children: "AUD"
1542
+ }
1543
+ )
1544
+ ]
1545
+ }
1546
+ );
1547
+ };
1548
+ var ImgIcon = ({ size = 16, className = "" }) => {
1549
+ return /* @__PURE__ */ jsxs(
1550
+ "svg",
1551
+ {
1552
+ width: size,
1553
+ height: size,
1554
+ viewBox: "0 0 24 24",
1555
+ fill: "none",
1556
+ xmlns: "http://www.w3.org/2000/svg",
1557
+ className,
1558
+ children: [
1559
+ /* @__PURE__ */ jsx(
1560
+ "path",
1561
+ {
1562
+ d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6z",
1563
+ fill: FILE_TYPE_COLORS.img,
1564
+ stroke: FILE_TYPE_COLORS.img,
1565
+ strokeWidth: "1",
1566
+ strokeLinecap: "round",
1567
+ strokeLinejoin: "round"
1568
+ }
1569
+ ),
1570
+ /* @__PURE__ */ jsx(
1571
+ "path",
1572
+ {
1573
+ d: "M14 2v6h6",
1574
+ fill: "none",
1575
+ stroke: FILE_TYPE_COLORS.white,
1576
+ strokeWidth: "1",
1577
+ strokeLinecap: "round",
1578
+ strokeLinejoin: "round"
1579
+ }
1580
+ ),
1581
+ /* @__PURE__ */ jsx(
1582
+ "text",
1583
+ {
1584
+ x: "12",
1585
+ y: "16",
1586
+ fontSize: "6",
1587
+ fill: "white",
1588
+ textAnchor: "middle",
1589
+ fontWeight: "bold",
1590
+ fontFamily: "Arial, sans-serif",
1591
+ children: "IMG"
1592
+ }
1593
+ )
1594
+ ]
1595
+ }
1596
+ );
1597
+ };
1598
+ var VidIcon = ({ size = 16, className = "" }) => {
1599
+ return /* @__PURE__ */ jsxs(
1600
+ "svg",
1601
+ {
1602
+ width: size,
1603
+ height: size,
1604
+ viewBox: "0 0 24 24",
1605
+ fill: "none",
1606
+ xmlns: "http://www.w3.org/2000/svg",
1607
+ className,
1608
+ children: [
1609
+ /* @__PURE__ */ jsx(
1610
+ "path",
1611
+ {
1612
+ d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6z",
1613
+ fill: FILE_TYPE_COLORS.vid,
1614
+ stroke: FILE_TYPE_COLORS.vid,
1615
+ strokeWidth: "1",
1616
+ strokeLinecap: "round",
1617
+ strokeLinejoin: "round"
1618
+ }
1619
+ ),
1620
+ /* @__PURE__ */ jsx(
1621
+ "path",
1622
+ {
1623
+ d: "M14 2v6h6",
1624
+ fill: "none",
1625
+ stroke: FILE_TYPE_COLORS.white,
1626
+ strokeWidth: "1",
1627
+ strokeLinecap: "round",
1628
+ strokeLinejoin: "round"
1629
+ }
1630
+ ),
1631
+ /* @__PURE__ */ jsx(
1632
+ "text",
1633
+ {
1634
+ x: "12",
1635
+ y: "16",
1636
+ fontSize: "6",
1637
+ fill: "white",
1638
+ textAnchor: "middle",
1639
+ fontWeight: "bold",
1640
+ fontFamily: "Arial, sans-serif",
1641
+ children: "VID"
1642
+ }
1643
+ )
1644
+ ]
1645
+ }
1646
+ );
1647
+ };
1648
+ var EmlIcon = ({ size = 16, className = "" }) => {
1649
+ return /* @__PURE__ */ jsxs(
1650
+ "svg",
1651
+ {
1652
+ width: size,
1653
+ height: size,
1654
+ viewBox: "0 0 24 24",
1655
+ fill: "none",
1656
+ xmlns: "http://www.w3.org/2000/svg",
1657
+ className,
1658
+ children: [
1659
+ /* @__PURE__ */ jsx(
1660
+ "path",
1661
+ {
1662
+ d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6z",
1663
+ fill: FILE_TYPE_COLORS.eml,
1664
+ stroke: FILE_TYPE_COLORS.eml,
1665
+ strokeWidth: "1",
1666
+ strokeLinecap: "round",
1667
+ strokeLinejoin: "round"
1668
+ }
1669
+ ),
1670
+ /* @__PURE__ */ jsx(
1671
+ "path",
1672
+ {
1673
+ d: "M14 2v6h6",
1674
+ fill: "none",
1675
+ stroke: FILE_TYPE_COLORS.white,
1676
+ strokeWidth: "1",
1677
+ strokeLinecap: "round",
1678
+ strokeLinejoin: "round"
1679
+ }
1680
+ ),
1681
+ /* @__PURE__ */ jsx(
1682
+ "rect",
1683
+ {
1684
+ x: "7",
1685
+ y: "12",
1686
+ width: "10",
1687
+ height: "7",
1688
+ rx: "1",
1689
+ fill: "none",
1690
+ stroke: "white",
1691
+ strokeWidth: "1.2"
1692
+ }
1693
+ ),
1694
+ /* @__PURE__ */ jsx("path", { d: "M7 13l5 3 5-3", fill: "none", stroke: "white", strokeWidth: "1.2", strokeLinejoin: "round" })
1695
+ ]
1696
+ }
1697
+ );
1698
+ };
1699
+ var FileIcon = ({ size = 16, className = "" }) => {
1700
+ return /* @__PURE__ */ jsxs(
1701
+ "svg",
1702
+ {
1703
+ width: size,
1704
+ height: size,
1705
+ viewBox: "0 0 24 24",
1706
+ fill: "none",
1707
+ xmlns: "http://www.w3.org/2000/svg",
1708
+ className,
1709
+ children: [
1710
+ /* @__PURE__ */ jsx(
1711
+ "path",
1712
+ {
1713
+ d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6z",
1714
+ fill: FILE_TYPE_COLORS.generic,
1715
+ stroke: FILE_TYPE_COLORS.generic,
1716
+ strokeWidth: "1",
1717
+ strokeLinecap: "round",
1718
+ strokeLinejoin: "round"
1719
+ }
1720
+ ),
1721
+ /* @__PURE__ */ jsx(
1722
+ "path",
1723
+ {
1724
+ d: "M14 2v6h6",
1725
+ fill: "none",
1726
+ stroke: FILE_TYPE_COLORS.white,
1727
+ strokeWidth: "1",
1728
+ strokeLinecap: "round",
1729
+ strokeLinejoin: "round"
1730
+ }
1731
+ ),
1732
+ /* @__PURE__ */ jsx(
1733
+ "text",
1734
+ {
1735
+ x: "12",
1736
+ y: "17",
1737
+ fontSize: "10",
1738
+ fill: "white",
1739
+ textAnchor: "middle",
1740
+ fontWeight: "bold",
1741
+ fontFamily: "Arial, sans-serif",
1742
+ children: "?"
1743
+ }
1744
+ )
1745
+ ]
1746
+ }
1747
+ );
1748
+ };
1749
+ var EntityPill = forwardRef(function EntityPill2({
1750
+ icon,
1751
+ label,
1752
+ secondaryText,
1753
+ size = "sm",
1754
+ shape = "rounded",
1755
+ className,
1756
+ labelMaxWidth = "max-w-[320px]",
1757
+ fullWidth = false,
1758
+ highlight = false,
1759
+ onClick,
1760
+ onIconClick,
1761
+ onMoreClick,
1762
+ moreContent,
1763
+ href,
1764
+ disabled = false,
1765
+ tooltipContent,
1766
+ tooltipSide = "bottom",
1767
+ "data-testid": testId
1768
+ }, ref) {
1769
+ const shapeClass = shape === "pill" ? "rounded-full" : "rounded-md";
1770
+ const sizeClasses = size === "base" ? "gap-1.5 px-1.5 py-0.5" : "gap-1 px-1";
1771
+ const textSizeClass = size === "base" ? "text-base" : "text-sm";
1772
+ const baseClasses = cn(
1773
+ "group/pill items-center",
1774
+ fullWidth ? "flex w-full" : "inline-flex",
1775
+ sizeClasses,
1776
+ shapeClass,
1777
+ "bg-muted",
1778
+ "border border-border",
1779
+ "transition-all",
1780
+ className
1781
+ );
1782
+ const interactiveClasses = "cursor-pointer hover:bg-muted/80";
1783
+ const disabledClasses = "cursor-default opacity-60";
1784
+ const highlightClasses = "bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground";
1785
+ const mainContent = /* @__PURE__ */ jsxs(Fragment, { children: [
1786
+ onIconClick ? /* @__PURE__ */ jsx(
1787
+ "span",
1788
+ {
1789
+ role: "button",
1790
+ tabIndex: 0,
1791
+ className: "flex-shrink-0 cursor-pointer hover:opacity-70 transition-opacity",
1792
+ onClick: (e) => {
1793
+ e.stopPropagation();
1794
+ onIconClick(e);
1795
+ },
1796
+ children: icon
1797
+ }
1798
+ ) : icon,
1799
+ /* @__PURE__ */ jsx(
1800
+ "span",
1801
+ {
1802
+ className: cn(textSizeClass, "font-medium truncate leading-tight min-w-0", labelMaxWidth),
1803
+ children: label
1804
+ }
1805
+ ),
1806
+ secondaryText && /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground flex-shrink-0 leading-none", children: secondaryText })
1807
+ ] });
1808
+ const tooltipWrap = (content, tip, side = tooltipSide, triggerClassName, triggerProps) => /* @__PURE__ */ jsxs(Tooltip, { children: [
1809
+ /* @__PURE__ */ jsx(
1810
+ TooltipTrigger,
1811
+ {
1812
+ onFocusCapture: (e) => e.stopPropagation(),
1813
+ className: triggerClassName,
1814
+ ...triggerProps,
1815
+ children: content
1816
+ }
1817
+ ),
1818
+ /* @__PURE__ */ jsx(TooltipContent, { side, className: "p-2", children: tip })
1819
+ ] });
1820
+ const mainAreaClass = cn("inline-flex items-center gap-1", fullWidth && "min-w-0 flex-1");
1821
+ if (onMoreClick || moreContent) {
1822
+ let mainArea;
1823
+ if (tooltipContent) {
1824
+ mainArea = tooltipWrap(
1825
+ mainContent,
1826
+ tooltipContent,
1827
+ tooltipSide,
1828
+ cn(mainAreaClass, disabled && "opacity-60"),
1829
+ {
1830
+ type: "button",
1831
+ onClick: href ? onClick : disabled ? void 0 : onClick,
1832
+ disabled: disabled || void 0
1833
+ }
1834
+ );
1835
+ } else if (href) {
1836
+ mainArea = /* @__PURE__ */ jsx(
1837
+ "a",
1838
+ {
1839
+ href,
1840
+ target: "_blank",
1841
+ rel: "noopener noreferrer",
1842
+ className: mainAreaClass,
1843
+ onClick,
1844
+ children: mainContent
1845
+ }
1846
+ );
1847
+ } else if (onClick) {
1848
+ mainArea = /* @__PURE__ */ jsx(
1849
+ "button",
1850
+ {
1851
+ type: "button",
1852
+ onClick: disabled ? void 0 : onClick,
1853
+ disabled,
1854
+ className: cn("inline-flex items-center gap-1", disabled && "opacity-60"),
1855
+ children: mainContent
1856
+ }
1857
+ );
1858
+ } else {
1859
+ mainArea = /* @__PURE__ */ jsx("span", { className: mainAreaClass, children: mainContent });
1860
+ }
1861
+ const moreArea = moreContent ? /* @__PURE__ */ jsx("span", { className: "flex-shrink-0 leading-none", children: moreContent }) : tooltipWrap(
1862
+ /* @__PURE__ */ jsx(MoreVertical, { className: "w-3.5 h-3.5" }),
1863
+ "Click for more",
1864
+ tooltipSide,
1865
+ "flex-shrink-0 leading-none text-muted-foreground hover:text-foreground",
1866
+ {
1867
+ type: "button",
1868
+ onClick: (e) => {
1869
+ e.stopPropagation();
1870
+ onMoreClick?.(e);
1871
+ }
1872
+ }
1873
+ );
1874
+ return /* @__PURE__ */ jsxs(
1875
+ "span",
1876
+ {
1877
+ ref,
1878
+ className: cn(
1879
+ baseClasses,
1880
+ (onClick || href) && !disabled && interactiveClasses,
1881
+ highlight && highlightClasses
1882
+ ),
1883
+ "data-testid": testId,
1884
+ children: [
1885
+ mainArea,
1886
+ moreArea
1887
+ ]
1888
+ }
1889
+ );
1890
+ }
1891
+ if (tooltipContent) {
1892
+ if (href) {
1893
+ return tooltipWrap(
1894
+ /* @__PURE__ */ jsx(
1895
+ "a",
1896
+ {
1897
+ href,
1898
+ target: "_blank",
1899
+ rel: "noopener noreferrer",
1900
+ className: mainAreaClass,
1901
+ onClick,
1902
+ children: mainContent
1903
+ }
1904
+ ),
1905
+ tooltipContent,
1906
+ tooltipSide,
1907
+ cn(baseClasses, interactiveClasses),
1908
+ { "data-testid": testId }
1909
+ );
1910
+ }
1911
+ return tooltipWrap(
1912
+ mainContent,
1913
+ tooltipContent,
1914
+ tooltipSide,
1915
+ cn(
1916
+ baseClasses,
1917
+ onClick && !disabled ? interactiveClasses : "",
1918
+ disabled ? disabledClasses : "",
1919
+ highlight && highlightClasses
1920
+ ),
1921
+ {
1922
+ type: "button",
1923
+ ref,
1924
+ onClick: onClick && !disabled ? onClick : void 0,
1925
+ disabled: disabled || void 0,
1926
+ "data-testid": testId
1927
+ }
1928
+ );
1929
+ }
1930
+ if (href) {
1931
+ return /* @__PURE__ */ jsx(
1932
+ "a",
1933
+ {
1934
+ ref,
1935
+ href,
1936
+ target: "_blank",
1937
+ rel: "noopener noreferrer",
1938
+ className: cn(baseClasses, interactiveClasses),
1939
+ "data-testid": testId,
1940
+ onClick,
1941
+ children: mainContent
1942
+ }
1943
+ );
1944
+ }
1945
+ if (onClick) {
1946
+ return /* @__PURE__ */ jsx(
1947
+ "button",
1948
+ {
1949
+ ref,
1950
+ type: "button",
1951
+ onClick: disabled ? void 0 : onClick,
1952
+ disabled,
1953
+ className: cn(
1954
+ baseClasses,
1955
+ disabled ? disabledClasses : interactiveClasses,
1956
+ highlight && highlightClasses
1957
+ ),
1958
+ "data-testid": testId,
1959
+ children: mainContent
1960
+ }
1961
+ );
1962
+ }
1963
+ return /* @__PURE__ */ jsx(
1964
+ "span",
1965
+ {
1966
+ ref,
1967
+ className: cn(baseClasses, highlight && highlightClasses),
1968
+ "data-testid": testId,
1969
+ children: mainContent
1970
+ }
1971
+ );
1972
+ });
1973
+ function getDocumentTitle(document2, defaultValue = "") {
1974
+ if (!document2) return defaultValue;
1975
+ return document2.doc_metadata?.title || document2.file_name || defaultValue;
1976
+ }
1977
+ var MAX_LABEL_CHARS = 30;
1978
+ function clampLabel(text) {
1979
+ return text.length > MAX_LABEL_CHARS ? `${text.slice(0, MAX_LABEL_CHARS).trimEnd()}\u2026` : text;
1980
+ }
1981
+ var IMAGE_EXTENSIONS = /* @__PURE__ */ new Set(["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "webp"]);
1982
+ var VIDEO_EXTENSIONS = /* @__PURE__ */ new Set(["mp4", "mpeg", "mpg", "webm", "mov", "avi", "mkv"]);
1983
+ var AUDIO_EXTENSIONS = /* @__PURE__ */ new Set(["mp3", "wav", "m4a", "aac", "ogg", "flac"]);
1984
+ var EMAIL_EXTENSIONS = /* @__PURE__ */ new Set(["eml", "msg"]);
1985
+ function getDocIcon(fileName, iconSize = 14) {
1986
+ const ext = fileName?.split(".").pop()?.toLowerCase();
1987
+ if (ext && VIDEO_EXTENSIONS.has(ext)) return /* @__PURE__ */ jsx(VidIcon, { size: iconSize, className: "flex-shrink-0" });
1988
+ if (ext && AUDIO_EXTENSIONS.has(ext)) return /* @__PURE__ */ jsx(AudIcon, { size: iconSize, className: "flex-shrink-0" });
1989
+ if (ext && IMAGE_EXTENSIONS.has(ext)) return /* @__PURE__ */ jsx(ImgIcon, { size: iconSize, className: "flex-shrink-0" });
1990
+ if (ext && EMAIL_EXTENSIONS.has(ext)) return /* @__PURE__ */ jsx(EmlIcon, { size: iconSize, className: "flex-shrink-0" });
1991
+ return /* @__PURE__ */ jsx(PdfIcon, { size: iconSize, className: "flex-shrink-0" });
1992
+ }
1993
+ function DocumentEntity({
1994
+ doc,
1995
+ icon,
1996
+ size = "sm",
1997
+ labelMaxWidth,
1998
+ onClick,
1999
+ onIconClick,
2000
+ showHoverEye,
2001
+ viewing,
2002
+ iconBadge,
2003
+ actions,
2004
+ tooltipContent,
2005
+ className,
2006
+ fullWidth
2007
+ }) {
2008
+ const title = getDocumentTitle(doc);
2009
+ const ext = doc.file_name?.split(".").pop()?.toLowerCase();
2010
+ const iconSize = size === "base" ? 16 : 14;
2011
+ const eyeSizeClass = size === "base" ? "h-4 w-4" : "h-3.5 w-3.5";
2012
+ const baseIcon = icon ?? getDocIcon(doc.file_name, iconSize);
2013
+ const showEye = showHoverEye || viewing;
2014
+ const displayIcon = showEye || iconBadge ? /* @__PURE__ */ jsxs("span", { className: "relative inline-flex flex-shrink-0 items-center justify-center", children: [
2015
+ showEye ? /* @__PURE__ */ jsxs(Fragment, { children: [
2016
+ /* @__PURE__ */ jsx(
2017
+ "span",
2018
+ {
2019
+ className: cn(
2020
+ "transition-opacity",
2021
+ viewing ? "opacity-0" : "group-hover/pill:opacity-0 group-has-[[data-state=open]]/pill:opacity-0"
2022
+ ),
2023
+ children: baseIcon
2024
+ }
2025
+ ),
2026
+ /* @__PURE__ */ jsx(
2027
+ Eye,
2028
+ {
2029
+ className: cn(
2030
+ "absolute inset-0 m-auto transition-opacity",
2031
+ eyeSizeClass,
2032
+ viewing ? "text-primary-foreground opacity-100" : "text-primary opacity-0 group-hover/pill:opacity-100 group-has-[[data-state=open]]/pill:opacity-100"
2033
+ )
2034
+ }
2035
+ )
2036
+ ] }) : baseIcon,
2037
+ iconBadge
2038
+ ] }) : baseIcon;
2039
+ const defaultTooltip = /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1 text-xs max-w-[300px]", children: [
2040
+ doc.folder && /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-0.5 text-muted-foreground", children: [
2041
+ /* @__PURE__ */ jsx(FolderOpen, { className: "h-3 w-3 text-yellow-600 shrink-0" }),
2042
+ doc.folder.split("/").map((part, i, arr) => /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-0.5 shrink-0", children: [
2043
+ i > 0 && /* @__PURE__ */ jsx("span", { className: "text-muted-foreground/50 mx-0.5", children: "/" }),
2044
+ /* @__PURE__ */ jsx("span", { className: i < arr.length - 1 ? "text-muted-foreground/70" : "", children: part })
2045
+ ] }, i))
2046
+ ] }),
2047
+ /* @__PURE__ */ jsxs("span", { className: "font-medium break-words", children: [
2048
+ title,
2049
+ ext ? `.${ext}` : ""
2050
+ ] })
2051
+ ] });
2052
+ return /* @__PURE__ */ jsx(
2053
+ EntityPill,
2054
+ {
2055
+ icon: displayIcon,
2056
+ size,
2057
+ label: fullWidth ? title : clampLabel(title),
2058
+ labelMaxWidth: labelMaxWidth ?? "max-w-[140px]",
2059
+ fullWidth,
2060
+ onClick,
2061
+ onIconClick,
2062
+ moreContent: actions,
2063
+ className,
2064
+ highlight: viewing,
2065
+ tooltipContent: tooltipContent ?? defaultTooltip
2066
+ }
2067
+ );
2068
+ }
2069
+ var BASE_COLORS = {
2070
+ "0": "#10b981",
2071
+ "1": "#3b82f6",
2072
+ "2": "#8b5cf6",
2073
+ "3": "#f43f5e",
2074
+ "4": "#f59e0b",
2075
+ "5": "#84cc16",
2076
+ "6": "#a855f7",
2077
+ "7": "#06b6d4",
2078
+ "8": "#f97316",
2079
+ "9": "#14b8a6",
2080
+ a: "#ef4444",
2081
+ b: "#6366f1",
2082
+ c: "#ec4899",
2083
+ d: "#22c55e",
2084
+ e: "#eab308",
2085
+ f: "#0ea5e9"
2086
+ };
2087
+ function getEntityColor(entityId) {
2088
+ return BASE_COLORS[entityId[4]] || BASE_COLORS["0"];
2089
+ }
2090
+ var TAG_TYPE_LABELS = {
2091
+ checkbox: "Checkbox",
2092
+ select: "Select",
2093
+ number: "Number",
2094
+ text: "Text",
2095
+ folder: "Folder",
2096
+ search: "Saved Search",
2097
+ date: "Date",
2098
+ assistant: "AI Assistant"
2099
+ };
2100
+ var TAG_TYPE_ICONS = {
2101
+ checkbox: SquareCheckBig,
2102
+ select: List,
2103
+ number: Hash,
2104
+ text: StickyNote,
2105
+ folder: Folder,
2106
+ search: Search,
2107
+ date: Calendar,
2108
+ assistant: Bot
2109
+ };
2110
+ function TagEntity({
2111
+ tag,
2112
+ size = "md",
2113
+ className = "",
2114
+ onClick,
2115
+ showTooltip = true
2116
+ }) {
2117
+ const tagType = tag.tag_type?.type ?? "text";
2118
+ const iconSize = size === "sm" ? 12 : size === "md" ? 14 : 16;
2119
+ const Icon = TAG_TYPE_ICONS[tagType] || StickyNote;
2120
+ const sizeClasses = {
2121
+ sm: "p-0.5",
2122
+ md: "p-1",
2123
+ lg: "p-1.5"
2124
+ };
2125
+ const tagColor = tag.color ?? getEntityColor(tag.external_id);
2126
+ const iconElement = /* @__PURE__ */ jsx(
2127
+ "span",
2128
+ {
2129
+ className: `inline-flex items-center justify-center rounded-md text-white flex-shrink-0 ${sizeClasses[size]}`,
2130
+ style: { backgroundColor: tagColor },
2131
+ children: /* @__PURE__ */ jsx(Icon, { size: iconSize, className: "flex-shrink-0" })
2132
+ }
2133
+ );
2134
+ const pillSize = size === "lg" ? "base" : "sm";
2135
+ const tooltipContent = showTooltip ? /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
2136
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
2137
+ /* @__PURE__ */ jsx(
2138
+ "span",
2139
+ {
2140
+ className: "inline-flex items-center justify-center rounded-md text-white p-1",
2141
+ style: { backgroundColor: tagColor },
2142
+ children: /* @__PURE__ */ jsx(Icon, { size: 16 })
2143
+ }
2144
+ ),
2145
+ /* @__PURE__ */ jsx("span", { className: "font-medium text-sm", children: tag.name })
2146
+ ] }),
2147
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5 text-sm", children: [
2148
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
2149
+ /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: "Type:" }),
2150
+ /* @__PURE__ */ jsx("span", { children: TAG_TYPE_LABELS[tagType] || tagType })
2151
+ ] }),
2152
+ tag.doctag_count != null && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
2153
+ /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: "Documents:" }),
2154
+ /* @__PURE__ */ jsx(Badge, { variant: "secondary", className: "h-5 min-w-[20px] justify-center", children: tag.doctag_count ?? 0 })
2155
+ ] }),
2156
+ tag.shared != null && /* @__PURE__ */ jsx("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: tag.shared ? "Shared" : "Private" }) })
2157
+ ] })
2158
+ ] }) : void 0;
2159
+ return /* @__PURE__ */ jsx(
2160
+ EntityPill,
2161
+ {
2162
+ icon: iconElement,
2163
+ label: tag.name,
2164
+ size: pillSize,
2165
+ shape: "rounded",
2166
+ labelMaxWidth: "max-w-[180px]",
2167
+ tooltipContent,
2168
+ onClick,
2169
+ className,
2170
+ "data-testid": `tag-entity-${tag.external_id}`
2171
+ }
2172
+ );
2173
+ }
2174
+ var VARIANT_STYLES = {
2175
+ "mine-paid": {
2176
+ pill: "bg-primary text-primary-foreground border-transparent",
2177
+ icon: "text-primary-foreground"
2178
+ },
2179
+ other: {
2180
+ pill: "bg-secondary text-secondary-foreground border-transparent",
2181
+ icon: "text-secondary-foreground"
2182
+ },
2183
+ "mine-free": {
2184
+ pill: "bg-muted-foreground text-background border-transparent",
2185
+ icon: "text-background"
2186
+ },
2187
+ common: {
2188
+ pill: "",
2189
+ icon: "text-muted-foreground"
2190
+ }
2191
+ };
2192
+ function resolveVariant(relation, paid, hasCollaborators) {
2193
+ if (relation === "common") return "common";
2194
+ if (relation === "other") return "other";
2195
+ if (relation === "mine") return paid ? "mine-paid" : "mine-free";
2196
+ if (paid) return hasCollaborators ? "other" : "mine-paid";
2197
+ return "mine-free";
2198
+ }
2199
+ function ProjectEntity({
2200
+ name,
2201
+ label,
2202
+ icon,
2203
+ subscription = "none",
2204
+ hasCollaborators = false,
2205
+ size = "sm",
2206
+ className,
2207
+ onClick,
2208
+ relation,
2209
+ isPaid,
2210
+ tooltipContent
2211
+ }) {
2212
+ const paid = isPaid ?? (subscription === "active" || subscription === "past_due" || subscription === "dev");
2213
+ const variant = resolveVariant(relation, paid, hasCollaborators);
2214
+ const { pill, icon: iconClass } = VARIANT_STYLES[variant];
2215
+ const iconSizeClass = size === "base" ? "h-4 w-4" : "h-3.5 w-3.5";
2216
+ const iconNode = icon ?? /* @__PURE__ */ jsx(Package, { className: cn(iconSizeClass, iconClass) });
2217
+ return /* @__PURE__ */ jsx(
2218
+ EntityPill,
2219
+ {
2220
+ icon: iconNode,
2221
+ label: label ?? name,
2222
+ size,
2223
+ shape: "pill",
2224
+ className: cn(pill, className),
2225
+ onClick,
2226
+ tooltipContent
2227
+ }
2228
+ );
2229
+ }
2230
+ var useArbiUiStore = create((set) => ({
2231
+ selectedDocIds: [],
2232
+ setSelectedDocIds: (ids) => set({ selectedDocIds: ids }),
2233
+ viewingDocId: null,
2234
+ setViewingDocId: (id) => set({ viewingDocId: id })
2235
+ }));
2236
+ ModuleRegistry.registerModules([AllCommunityModule]);
2237
+ function formatBytes(bytes) {
2238
+ if (bytes == null || Number.isNaN(bytes)) return "\u2014";
2239
+ if (bytes < 1024) return `${bytes} B`;
2240
+ const units = ["KB", "MB", "GB", "TB"];
2241
+ let value = bytes / 1024;
2242
+ let i = 0;
2243
+ while (value >= 1024 && i < units.length - 1) {
2244
+ value /= 1024;
2245
+ i++;
2246
+ }
2247
+ return `${value.toFixed(value >= 10 || i === 0 ? 0 : 1)} ${units[i]}`;
2248
+ }
2249
+ var STATUS_VARIANTS = {
2250
+ completed: "default",
2251
+ empty: "secondary",
2252
+ "low-content": "secondary",
2253
+ processing: "outline",
2254
+ queued: "outline",
2255
+ failed: "destructive",
2256
+ skipped: "destructive"
2257
+ };
2258
+ function DocumentTable({
2259
+ workspaceId,
2260
+ documents,
2261
+ onOpenDocument,
2262
+ selectedIds,
2263
+ onSelectionChange,
2264
+ height = 480,
2265
+ className
2266
+ }) {
2267
+ const query = useDocuments(workspaceId, { enabled: !documents });
2268
+ const rows = documents ?? query.data ?? [];
2269
+ const isLoading = !documents && query.isLoading;
2270
+ const tagsQuery = useTags(workspaceId);
2271
+ const tagNameById = React__default.useMemo(() => {
2272
+ const map = /* @__PURE__ */ new Map();
2273
+ for (const t of tagsQuery.data ?? []) {
2274
+ if (t.external_id) map.set(t.external_id, t.name ?? t.external_id.slice(0, 8));
2275
+ }
2276
+ return map;
2277
+ }, [tagsQuery.data]);
2278
+ const storeSelected = useArbiUiStore((s) => s.selectedDocIds);
2279
+ const storeSetSelected = useArbiUiStore((s) => s.setSelectedDocIds);
2280
+ const viewingDocId = useArbiUiStore((s) => s.viewingDocId);
2281
+ const setViewingDocId = useArbiUiStore((s) => s.setViewingDocId);
2282
+ const effectiveSelected = selectedIds ?? storeSelected;
2283
+ const emitSelection = onSelectionChange ?? storeSetSelected;
2284
+ const gridApiRef = React__default.useRef(null);
2285
+ const openDocument = React__default.useCallback(
2286
+ (id) => {
2287
+ setViewingDocId(id);
2288
+ onOpenDocument?.(id);
2289
+ },
2290
+ [onOpenDocument, setViewingDocId]
2291
+ );
2292
+ const applySelection = React__default.useCallback(() => {
2293
+ const api = gridApiRef.current;
2294
+ if (!api) return;
2295
+ const wanted = new Set(effectiveSelected);
2296
+ api.forEachNode((node) => {
2297
+ const id = node.data?.external_id;
2298
+ const shouldSelect = !!id && wanted.has(id);
2299
+ if (node.isSelected() !== shouldSelect) node.setSelected(shouldSelect);
2300
+ });
2301
+ }, [effectiveSelected]);
2302
+ React__default.useEffect(() => {
2303
+ applySelection();
2304
+ }, [applySelection]);
2305
+ const columnDefs = React__default.useMemo(
2306
+ () => [
2307
+ {
2308
+ colId: "select",
2309
+ headerName: "",
2310
+ width: 44,
2311
+ pinned: "left",
2312
+ checkboxSelection: true,
2313
+ headerCheckboxSelection: true,
2314
+ sortable: false,
2315
+ filter: false,
2316
+ resizable: false,
2317
+ suppressMovable: true
2318
+ },
2319
+ {
2320
+ colId: "title",
2321
+ headerName: "Document Name",
2322
+ flex: 3,
2323
+ minWidth: 240,
2324
+ sortable: true,
2325
+ valueGetter: (p) => p.data?.doc_metadata?.title || p.data?.file_name || "",
2326
+ cellRenderer: (p) => {
2327
+ const doc = p.data;
2328
+ if (!doc) return null;
2329
+ return /* @__PURE__ */ jsx(
2330
+ DocumentEntity,
2331
+ {
2332
+ doc,
2333
+ size: "base",
2334
+ fullWidth: true,
2335
+ showHoverEye: true,
2336
+ viewing: viewingDocId === doc.external_id,
2337
+ onClick: (e) => {
2338
+ e.stopPropagation();
2339
+ if (doc.external_id) openDocument(doc.external_id);
2340
+ }
2341
+ }
2342
+ );
2343
+ }
2344
+ },
2345
+ {
2346
+ colId: "status",
2347
+ headerName: "Status",
2348
+ width: 140,
2349
+ sortable: true,
2350
+ field: "status",
2351
+ cellRenderer: (p) => {
2352
+ const status = p.data?.status;
2353
+ if (!status) return null;
2354
+ return /* @__PURE__ */ jsx(Badge, { variant: STATUS_VARIANTS[status.toLowerCase()] ?? "secondary", children: status });
2355
+ }
2356
+ },
2357
+ {
2358
+ colId: "all_tags",
2359
+ headerName: "Labels",
2360
+ flex: 1,
2361
+ minWidth: 160,
2362
+ sortable: false,
2363
+ filter: false,
2364
+ cellRenderer: (p) => {
2365
+ const doctags = p.data?.doctags ?? [];
2366
+ if (doctags.length === 0) return null;
2367
+ return /* @__PURE__ */ jsx("div", { className: "flex flex-wrap items-center gap-1 py-1", children: doctags.map((dt) => /* @__PURE__ */ jsx(
2368
+ TagEntity,
2369
+ {
2370
+ size: "sm",
2371
+ tag: {
2372
+ external_id: dt.tag_ext_id,
2373
+ name: tagNameById.get(dt.tag_ext_id) ?? dt.tag_ext_id.slice(0, 8)
2374
+ }
2375
+ },
2376
+ dt.tag_ext_id
2377
+ )) });
2378
+ }
2379
+ },
2380
+ {
2381
+ colId: "file_size",
2382
+ headerName: "Size",
2383
+ width: 110,
2384
+ sortable: true,
2385
+ field: "file_size",
2386
+ valueFormatter: (p) => formatBytes(p.value)
2387
+ },
2388
+ {
2389
+ colId: "folder",
2390
+ headerName: "Folder",
2391
+ flex: 1,
2392
+ minWidth: 140,
2393
+ sortable: true,
2394
+ field: "folder",
2395
+ valueFormatter: (p) => p.value || "\u2014"
2396
+ }
2397
+ ],
2398
+ [openDocument, viewingDocId, tagNameById]
2399
+ );
2400
+ const handleGridReady = (e) => {
2401
+ gridApiRef.current = e.api;
2402
+ applySelection();
2403
+ };
2404
+ const handleSelectionChanged = (e) => {
2405
+ const ids = e.api.getSelectedRows().map((r) => r.external_id).filter((id) => !!id);
2406
+ emitSelection(ids);
2407
+ };
2408
+ const handleRowClicked = (e) => {
2409
+ const id = e.data?.external_id;
2410
+ if (id) openDocument(id);
2411
+ };
2412
+ const getRowId = React__default.useCallback((params) => params.data.external_id, []);
2413
+ const autoHeight = height === "auto";
2414
+ const style = autoHeight ? {} : { height: typeof height === "number" ? `${height}px` : height, width: "100%" };
2415
+ if (isLoading) {
2416
+ return /* @__PURE__ */ jsx("div", { className, style, children: /* @__PURE__ */ jsx("div", { className: "flex h-full w-full items-center justify-center p-8 text-sm text-muted-foreground", children: "Loading documents\u2026" }) });
2417
+ }
2418
+ if (rows.length === 0) {
2419
+ return /* @__PURE__ */ jsx("div", { className, style, children: /* @__PURE__ */ jsx("div", { className: "flex h-full w-full items-center justify-center p-8 text-sm text-muted-foreground", children: "No documents" }) });
2420
+ }
2421
+ return /* @__PURE__ */ jsx("div", { className, style, children: /* @__PURE__ */ jsx(
2422
+ AgGridReact,
2423
+ {
2424
+ columnDefs,
2425
+ rowData: rows,
2426
+ getRowId,
2427
+ rowSelection: "multiple",
2428
+ suppressRowClickSelection: true,
2429
+ domLayout: autoHeight ? "autoHeight" : "normal",
2430
+ rowHeight: 44,
2431
+ onGridReady: handleGridReady,
2432
+ onSelectionChanged: handleSelectionChanged,
2433
+ onRowClicked: handleRowClicked
2434
+ }
2435
+ ) });
2436
+ }
1157
2437
 
1158
- export { ArbiChat, ArbiProvider, arbiQueryKeys, useAgents, useArbi, useAssistantQuery, useConversations, useDeleteAgents, useDocuments, useHealth, useSessions, useTags, useWorkspaces };
2438
+ export { ArbiChat, ArbiChatPanel, ArbiProvider, AudIcon, Avatar, AvatarFallback, AvatarImage, Badge, Button, DocumentEntity, DocumentTable, EmlIcon, EntityPill, FILE_TYPE_COLORS, FileIcon, HoverCard, HoverCardContent, HoverCardTrigger, ImgIcon, PdfIcon, ProjectEntity, TagEntity, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, VidIcon, arbiQueryKeys, badgeVariants, buttonVariants, cn, useAgents, useArbi, useArbiUiStore, useAssistantQuery, useConversations, useDeleteAgents, useDocuments, useHealth, useSessions, useTags, useWorkspaces };
1159
2439
  //# sourceMappingURL=index.js.map
1160
2440
  //# sourceMappingURL=index.js.map