@iota-uz/sdk 0.4.33 → 0.4.34

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.
@@ -3659,16 +3659,26 @@ function hashString(str) {
3659
3659
  return Math.abs(hash);
3660
3660
  }
3661
3661
  var colorPalette = [
3662
- { bg: "bg-blue-500", text: "text-white" },
3663
- { bg: "bg-green-500", text: "text-white" },
3664
- { bg: "bg-purple-500", text: "text-white" },
3665
- { bg: "bg-pink-500", text: "text-white" },
3666
- { bg: "bg-indigo-500", text: "text-white" },
3667
- { bg: "bg-teal-500", text: "text-white" },
3668
- { bg: "bg-orange-500", text: "text-white" },
3669
- { bg: "bg-cyan-500", text: "text-white" },
3670
- { bg: "bg-amber-500", text: "text-white" },
3671
- { bg: "bg-lime-500", text: "text-white" }
3662
+ { bg: "#3b82f6", text: "#ffffff" },
3663
+ // blue-500
3664
+ { bg: "#22c55e", text: "#111827" },
3665
+ // green-500 (light bg)
3666
+ { bg: "#a855f7", text: "#ffffff" },
3667
+ // purple-500
3668
+ { bg: "#ec4899", text: "#ffffff" },
3669
+ // pink-500
3670
+ { bg: "#6366f1", text: "#ffffff" },
3671
+ // indigo-500
3672
+ { bg: "#14b8a6", text: "#111827" },
3673
+ // teal-500 (light bg)
3674
+ { bg: "#f97316", text: "#ffffff" },
3675
+ // orange-500
3676
+ { bg: "#06b6d4", text: "#111827" },
3677
+ // cyan-500 (light bg)
3678
+ { bg: "#f59e0b", text: "#111827" },
3679
+ // amber-500 (light bg)
3680
+ { bg: "#84cc16", text: "#111827" }
3681
+ // lime-500 (light bg)
3672
3682
  ];
3673
3683
  var sizeClasses = {
3674
3684
  xs: "w-6 h-6 text-[10px]",
@@ -3698,8 +3708,6 @@ function UserAvatar({
3698
3708
  {
3699
3709
  className: `
3700
3710
  ${sizeClasses[size]}
3701
- ${colors.bg}
3702
- ${colors.text}
3703
3711
  ${className}
3704
3712
  rounded-full
3705
3713
  flex
@@ -3709,6 +3717,7 @@ function UserAvatar({
3709
3717
  flex-shrink-0
3710
3718
  select-none
3711
3719
  `,
3720
+ style: { backgroundColor: colors.bg, color: colors.text },
3712
3721
  "aria-label": `${firstName} ${lastName}`,
3713
3722
  title: `${firstName} ${lastName}`,
3714
3723
  children: initials
@@ -14385,6 +14394,62 @@ function AllChatsList({ dataSource, onSessionSelect, activeSessionId }) {
14385
14394
  });
14386
14395
  return Array.from(userMap.values());
14387
14396
  }, [chats, users, dataSource.listUsers]);
14397
+ const [expandedGroups, setExpandedGroups] = React.useState(/* @__PURE__ */ new Set());
14398
+ const toggleGroup = React.useCallback((ownerId) => {
14399
+ setExpandedGroups((prev) => {
14400
+ const next = new Set(prev);
14401
+ if (next.has(ownerId)) {
14402
+ next.delete(ownerId);
14403
+ } else {
14404
+ next.add(ownerId);
14405
+ }
14406
+ return next;
14407
+ });
14408
+ }, []);
14409
+ React.useEffect(() => {
14410
+ if (!activeSessionId || selectedUser) {
14411
+ return;
14412
+ }
14413
+ const chat = chats.find((c) => c.id === activeSessionId);
14414
+ if (chat?.owner?.id) {
14415
+ setExpandedGroups((prev) => {
14416
+ if (prev.has(chat.owner.id)) {
14417
+ return prev;
14418
+ }
14419
+ return /* @__PURE__ */ new Set([...prev, chat.owner.id]);
14420
+ });
14421
+ }
14422
+ }, [activeSessionId, chats, selectedUser]);
14423
+ const groupedChats = React.useMemo(() => {
14424
+ if (selectedUser) {
14425
+ return null;
14426
+ }
14427
+ const groupMap = /* @__PURE__ */ new Map();
14428
+ chats.forEach((chat) => {
14429
+ const owner = chat.owner ?? {
14430
+ id: "__unknown__",
14431
+ firstName: t("BiChat.Common.Untitled"),
14432
+ lastName: "",
14433
+ initials: "?"
14434
+ };
14435
+ const ownerId = owner.id;
14436
+ if (!groupMap.has(ownerId)) {
14437
+ groupMap.set(ownerId, {
14438
+ owner,
14439
+ chats: [],
14440
+ latestUpdatedAt: chat.updatedAt
14441
+ });
14442
+ }
14443
+ const group = groupMap.get(ownerId);
14444
+ group.chats.push(chat);
14445
+ if (chat.updatedAt > group.latestUpdatedAt) {
14446
+ group.latestUpdatedAt = chat.updatedAt;
14447
+ }
14448
+ });
14449
+ return Array.from(groupMap.values()).sort(
14450
+ (a, b) => b.latestUpdatedAt.localeCompare(a.latestUpdatedAt)
14451
+ );
14452
+ }, [chats, selectedUser, t]);
14388
14453
  return /* @__PURE__ */ jsxRuntime.jsxs(
14389
14454
  "div",
14390
14455
  {
@@ -14430,61 +14495,159 @@ function AllChatsList({ dataSource, onSessionSelect, activeSessionId }) {
14430
14495
  role: "list",
14431
14496
  "aria-label": t("BiChat.AllChats.OrganizationChatSessions"),
14432
14497
  children: [
14433
- chats.map((chat) => {
14434
- const owner = chat.owner ?? {
14435
- firstName: "",
14436
- lastName: "",
14437
- initials: "U"
14438
- };
14439
- const ownerName = [owner.firstName, owner.lastName].filter(Boolean).join(" ");
14440
- return /* @__PURE__ */ jsxRuntime.jsx(
14441
- framerMotion.motion.div,
14442
- {
14443
- initial: { opacity: 0, y: -10 },
14444
- animate: { opacity: 1, y: 0 },
14445
- exit: { opacity: 0, y: -10 },
14446
- children: /* @__PURE__ */ jsxRuntime.jsx(
14498
+ groupedChats ? (
14499
+ /* ── Grouped view (no user selected) ── */
14500
+ groupedChats.map((group) => {
14501
+ const ownerId = group.owner.id;
14502
+ const ownerName = [group.owner.firstName, group.owner.lastName].filter(Boolean).join(" ");
14503
+ const isCollapsed = !expandedGroups.has(ownerId);
14504
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-1", children: [
14505
+ /* @__PURE__ */ jsxRuntime.jsxs(
14447
14506
  "div",
14448
14507
  {
14449
- role: "link",
14508
+ role: "button",
14450
14509
  tabIndex: 0,
14451
- onClick: () => onSessionSelect(chat.id),
14510
+ onClick: () => toggleGroup(ownerId),
14452
14511
  onKeyDown: (e) => {
14453
14512
  if (e.key === "Enter" || e.key === " ") {
14454
14513
  e.preventDefault();
14455
- onSessionSelect(chat.id);
14514
+ toggleGroup(ownerId);
14456
14515
  }
14457
14516
  },
14458
- className: `
14459
- block px-3 py-2 rounded-lg transition-smooth group cursor-pointer
14460
- ${chat.id === activeSessionId ? "bg-primary-50/50 dark:bg-primary-900/30 text-primary-700 dark:text-primary-400 border-l-4 border-primary-400 dark:border-primary-600" : "text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 border-l-4 border-transparent"}
14461
- `,
14462
- "aria-current": chat.id === activeSessionId ? "page" : void 0,
14463
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start gap-2", children: [
14517
+ className: "flex items-center gap-2 px-3 py-2 cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-lg transition-smooth select-none",
14518
+ "aria-expanded": !isCollapsed,
14519
+ children: [
14520
+ /* @__PURE__ */ jsxRuntime.jsx(
14521
+ react.CaretRight,
14522
+ {
14523
+ size: 14,
14524
+ weight: "bold",
14525
+ className: `shrink-0 text-gray-500 dark:text-gray-400 transition-transform duration-150 ${isCollapsed ? "" : "rotate-90"}`
14526
+ }
14527
+ ),
14464
14528
  /* @__PURE__ */ jsxRuntime.jsx(
14465
14529
  MemoizedUserAvatar,
14466
14530
  {
14467
- firstName: owner.firstName,
14468
- lastName: owner.lastName,
14469
- initials: owner.initials,
14531
+ firstName: group.owner.firstName,
14532
+ lastName: group.owner.lastName,
14533
+ initials: group.owner.initials,
14470
14534
  size: "sm"
14471
14535
  }
14472
14536
  ),
14473
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1 min-w-0", children: [
14474
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm font-medium truncate", children: chat.title || t("BiChat.Common.Untitled") }),
14475
- ownerName && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 truncate", children: ownerName }),
14476
- chat.status === "archived" && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "inline-flex items-center gap-1 mt-1 px-2 py-0.5 bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400 rounded-full text-xs", children: [
14477
- /* @__PURE__ */ jsxRuntime.jsx(react.Archive, { size: 12, className: "w-3 h-3" }),
14478
- t("BiChat.Chat.Archived")
14537
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm font-medium text-gray-700 dark:text-gray-300 truncate flex-1 min-w-0", children: ownerName || t("BiChat.Common.Untitled") }),
14538
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs text-gray-500 dark:text-gray-400 bg-gray-100 dark:bg-gray-800 px-2 py-0.5 rounded-full flex-shrink-0", children: group.chats.length })
14539
+ ]
14540
+ }
14541
+ ),
14542
+ /* @__PURE__ */ jsxRuntime.jsx(framerMotion.AnimatePresence, { initial: false, children: !isCollapsed && /* @__PURE__ */ jsxRuntime.jsx(
14543
+ framerMotion.motion.div,
14544
+ {
14545
+ initial: { height: 0, opacity: 0 },
14546
+ animate: { height: "auto", opacity: 1 },
14547
+ exit: { height: 0, opacity: 0 },
14548
+ transition: { duration: 0.2, ease: [0.4, 0, 0.2, 1] },
14549
+ className: "overflow-hidden",
14550
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-0.5 pl-6", children: group.chats.map((chat) => /* @__PURE__ */ jsxRuntime.jsx(
14551
+ framerMotion.motion.div,
14552
+ {
14553
+ initial: { opacity: 0, y: -10 },
14554
+ animate: { opacity: 1, y: 0 },
14555
+ exit: { opacity: 0, y: -10 },
14556
+ children: /* @__PURE__ */ jsxRuntime.jsx(
14557
+ "div",
14558
+ {
14559
+ role: "link",
14560
+ tabIndex: 0,
14561
+ onClick: () => onSessionSelect(chat.id),
14562
+ onKeyDown: (e) => {
14563
+ if (e.key === "Enter" || e.key === " ") {
14564
+ e.preventDefault();
14565
+ onSessionSelect(chat.id);
14566
+ }
14567
+ },
14568
+ className: `
14569
+ block px-3 py-2 rounded-lg transition-smooth group cursor-pointer
14570
+ ${chat.id === activeSessionId ? "bg-primary-50/50 dark:bg-primary-900/30 text-primary-700 dark:text-primary-400 border-l-4 border-primary-400 dark:border-primary-600" : "text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 border-l-4 border-transparent"}
14571
+ `,
14572
+ "aria-current": chat.id === activeSessionId ? "page" : void 0,
14573
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 min-w-0", children: [
14574
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm truncate flex-1 min-w-0", children: chat.title || t("BiChat.Common.Untitled") }),
14575
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5 flex-shrink-0", children: [
14576
+ chat.isGroup && chat.memberCount && chat.memberCount > 1 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs text-gray-400 dark:text-gray-500", children: chat.memberCount }),
14577
+ chat.status === "archived" && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "inline-flex items-center gap-1 px-2 py-0.5 bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400 rounded-full text-xs", children: [
14578
+ /* @__PURE__ */ jsxRuntime.jsx(react.Archive, { size: 12, className: "w-3 h-3" }),
14579
+ t("BiChat.Chat.Archived")
14580
+ ] })
14581
+ ] })
14582
+ ] })
14583
+ }
14584
+ )
14585
+ },
14586
+ chat.id
14587
+ )) })
14588
+ },
14589
+ `group-${ownerId}`
14590
+ ) })
14591
+ ] }, ownerId);
14592
+ })
14593
+ ) : (
14594
+ /* ── Flat view (user selected) ── */
14595
+ chats.map((chat) => {
14596
+ const owner = chat.owner ?? {
14597
+ firstName: "",
14598
+ lastName: "",
14599
+ initials: "U"
14600
+ };
14601
+ const ownerName = [owner.firstName, owner.lastName].filter(Boolean).join(" ");
14602
+ return /* @__PURE__ */ jsxRuntime.jsx(
14603
+ framerMotion.motion.div,
14604
+ {
14605
+ initial: { opacity: 0, y: -10 },
14606
+ animate: { opacity: 1, y: 0 },
14607
+ exit: { opacity: 0, y: -10 },
14608
+ children: /* @__PURE__ */ jsxRuntime.jsx(
14609
+ "div",
14610
+ {
14611
+ role: "link",
14612
+ tabIndex: 0,
14613
+ onClick: () => onSessionSelect(chat.id),
14614
+ onKeyDown: (e) => {
14615
+ if (e.key === "Enter" || e.key === " ") {
14616
+ e.preventDefault();
14617
+ onSessionSelect(chat.id);
14618
+ }
14619
+ },
14620
+ className: `
14621
+ block px-3 py-2 rounded-lg transition-smooth group cursor-pointer
14622
+ ${chat.id === activeSessionId ? "bg-primary-50/50 dark:bg-primary-900/30 text-primary-700 dark:text-primary-400 border-l-4 border-primary-400 dark:border-primary-600" : "text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 border-l-4 border-transparent"}
14623
+ `,
14624
+ "aria-current": chat.id === activeSessionId ? "page" : void 0,
14625
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start gap-2", children: [
14626
+ /* @__PURE__ */ jsxRuntime.jsx(
14627
+ MemoizedUserAvatar,
14628
+ {
14629
+ firstName: owner.firstName,
14630
+ lastName: owner.lastName,
14631
+ initials: owner.initials,
14632
+ size: "sm"
14633
+ }
14634
+ ),
14635
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1 min-w-0", children: [
14636
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm font-medium truncate", children: chat.title || t("BiChat.Common.Untitled") }),
14637
+ ownerName && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 truncate", children: ownerName }),
14638
+ chat.status === "archived" && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "inline-flex items-center gap-1 mt-1 px-2 py-0.5 bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400 rounded-full text-xs", children: [
14639
+ /* @__PURE__ */ jsxRuntime.jsx(react.Archive, { size: 12, className: "w-3 h-3" }),
14640
+ t("BiChat.Chat.Archived")
14641
+ ] })
14479
14642
  ] })
14480
14643
  ] })
14481
- ] })
14482
- }
14483
- )
14484
- },
14485
- chat.id
14486
- );
14487
- }),
14644
+ }
14645
+ )
14646
+ },
14647
+ chat.id
14648
+ );
14649
+ })
14650
+ ),
14488
14651
  hasMore && /* @__PURE__ */ jsxRuntime.jsx("div", { ref: loadMoreRef, className: "py-4 text-center", children: fetching ? /* @__PURE__ */ jsxRuntime.jsx(SessionSkeleton, { count: 2 }) : /* @__PURE__ */ jsxRuntime.jsx(
14489
14652
  "button",
14490
14653
  {
@@ -14707,7 +14870,9 @@ function Sidebar2({
14707
14870
  onClose,
14708
14871
  headerSlot,
14709
14872
  footerSlot,
14710
- className = ""
14873
+ className = "",
14874
+ activeTab: controlledActiveTab,
14875
+ onTabChange
14711
14876
  }) {
14712
14877
  const { t } = useTranslation();
14713
14878
  const toast = useToast();
@@ -14767,7 +14932,14 @@ function Sidebar2({
14767
14932
  const timer = setTimeout(() => setCollapsedOverflowVisible(true), 300);
14768
14933
  return () => clearTimeout(timer);
14769
14934
  }, [showCollapsed]);
14770
- const [activeTab, setActiveTab] = React.useState("my-chats");
14935
+ const [internalActiveTab, setInternalActiveTab] = React.useState("my-chats");
14936
+ const activeTab = controlledActiveTab ?? internalActiveTab;
14937
+ const handleTabChange = React.useCallback((tab) => {
14938
+ if (controlledActiveTab === void 0) {
14939
+ setInternalActiveTab(tab);
14940
+ }
14941
+ onTabChange?.(tab);
14942
+ }, [controlledActiveTab, onTabChange]);
14771
14943
  const [searchQuery, setSearchQuery] = React.useState("");
14772
14944
  const [sessions, setSessions] = React.useState([]);
14773
14945
  const [loading, setLoading] = React.useState(true);
@@ -15381,7 +15553,7 @@ function Sidebar2({
15381
15553
  onClick: (e) => {
15382
15554
  e.preventDefault();
15383
15555
  e.stopPropagation();
15384
- setActiveTab("all-chats");
15556
+ handleTabChange("all-chats");
15385
15557
  close();
15386
15558
  },
15387
15559
  className: `cursor-pointer flex w-full items-center gap-2.5 rounded-lg px-2.5 py-1.5 text-[13px] text-gray-600 dark:text-gray-300 transition-colors ${focus ? "bg-gray-100 dark:bg-gray-800/70" : ""}`,
@@ -15398,7 +15570,7 @@ function Sidebar2({
15398
15570
  onClick: (e) => {
15399
15571
  e.preventDefault();
15400
15572
  e.stopPropagation();
15401
- setActiveTab("my-chats");
15573
+ handleTabChange("my-chats");
15402
15574
  close();
15403
15575
  },
15404
15576
  className: `cursor-pointer flex w-full items-center gap-2.5 rounded-lg px-2.5 py-1.5 text-[13px] text-gray-600 dark:text-gray-300 transition-colors ${focus ? "bg-gray-100 dark:bg-gray-800/70" : ""}`,
@@ -17505,42 +17677,66 @@ function useBichatRouter({
17505
17677
  pathname,
17506
17678
  onNavigate
17507
17679
  }) {
17680
+ const isAllChats = pathname.startsWith("/all-chats");
17508
17681
  const activeSessionId = React.useMemo(
17509
17682
  () => pathname.match(SESSION_PATH_REGEX)?.[1],
17510
17683
  [pathname]
17511
17684
  );
17685
+ const sidebarTab = React.useMemo(
17686
+ () => isAllChats ? "all-chats" : "my-chats",
17687
+ [isAllChats]
17688
+ );
17512
17689
  const maybeClose = React.useCallback(() => {
17513
17690
  onNavigate?.();
17514
17691
  }, [onNavigate]);
17515
17692
  const onSessionSelect = React.useCallback(
17516
17693
  (sessionId) => {
17517
17694
  if (sessionId) {
17518
- navigate(`/session/${sessionId}`);
17695
+ const prefix = isAllChats ? "/all-chats" : "";
17696
+ navigate(`${prefix}/session/${sessionId}`);
17519
17697
  } else {
17520
- navigate("/");
17698
+ navigate(isAllChats ? "/all-chats" : "/");
17521
17699
  }
17522
17700
  maybeClose();
17523
17701
  },
17524
- [navigate, maybeClose]
17702
+ [navigate, maybeClose, isAllChats]
17525
17703
  );
17526
17704
  const onNewChat = React.useCallback(() => {
17527
- navigate("/");
17705
+ navigate(isAllChats ? "/all-chats" : "/");
17528
17706
  maybeClose();
17529
- }, [navigate, maybeClose]);
17707
+ }, [navigate, maybeClose, isAllChats]);
17530
17708
  const onArchivedView = React.useCallback(() => {
17531
17709
  navigate("/archived");
17532
17710
  maybeClose();
17533
17711
  }, [navigate, maybeClose]);
17712
+ const onAllChatsView = React.useCallback(() => {
17713
+ navigate("/all-chats");
17714
+ maybeClose();
17715
+ }, [navigate, maybeClose]);
17534
17716
  const onBack = React.useCallback(() => {
17535
17717
  navigate("/");
17536
17718
  maybeClose();
17537
17719
  }, [navigate, maybeClose]);
17720
+ const onSidebarTabChange = React.useCallback(
17721
+ (tab) => {
17722
+ if (tab === "all-chats") {
17723
+ navigate("/all-chats");
17724
+ } else {
17725
+ navigate("/");
17726
+ }
17727
+ maybeClose();
17728
+ },
17729
+ [navigate, maybeClose]
17730
+ );
17538
17731
  return {
17539
17732
  activeSessionId,
17540
17733
  onSessionSelect,
17541
17734
  onNewChat,
17542
17735
  onArchivedView,
17543
- onBack
17736
+ onBack,
17737
+ onAllChatsView,
17738
+ sidebarTab,
17739
+ onSidebarTabChange
17544
17740
  };
17545
17741
  }
17546
17742