@ai-matrx/agents 0.9.0 → 0.9.1

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.
@@ -468,7 +468,19 @@ function memoize2(fn) {
468
468
  return last;
469
469
  };
470
470
  }
471
+ function compareAgentIds(a, b) {
472
+ const idA = a.id ?? "";
473
+ const idB = b.id ?? "";
474
+ if (idA < idB) return -1;
475
+ if (idA > idB) return 1;
476
+ return 0;
477
+ }
471
478
  function applyAgentSortComparator(a, b, sortBy) {
479
+ const primary = compareAgentSortKey(a, b, sortBy);
480
+ if (!Number.isFinite(primary) || primary === 0) return compareAgentIds(a, b);
481
+ return primary;
482
+ }
483
+ function compareAgentSortKey(a, b, sortBy) {
472
484
  switch (sortBy) {
473
485
  case "name-asc":
474
486
  return (a.name ?? "").localeCompare(b.name ?? "");
@@ -644,22 +656,46 @@ var makeSelectFilteredAgents = (includeSystemInAll = false) => memoize2(
644
656
  return filterUserTypeAgents(userAgents, consumer);
645
657
  }
646
658
  );
659
+ function agentMatchesArchiveFilter(agent, archFilter) {
660
+ if (archFilter === "active") return !agent.isArchived;
661
+ if (archFilter === "archived") return Boolean(agent.isArchived);
662
+ return true;
663
+ }
664
+ function countUserRows(agents, archFilter, predicate) {
665
+ let n = 0;
666
+ for (const a of agents) {
667
+ if (a.agentType !== "user") continue;
668
+ if (!agentMatchesArchiveFilter(a, archFilter)) continue;
669
+ if (predicate(a)) n += 1;
670
+ }
671
+ return n;
672
+ }
673
+ var isOwned = (a) => a.isOwner === true;
674
+ var isShared = (a) => a.isOwner === false && a.accessLevel != null;
675
+ var isAny = () => true;
676
+ var isFavorite = (a) => Boolean(a.isFavorite);
677
+ var selectAgentTabCounts = memoize2(
678
+ (agents, archFilter) => ({
679
+ mine: countUserRows(agents, archFilter, isOwned),
680
+ shared: countUserRows(agents, archFilter, isShared),
681
+ all: countUserRows(agents, archFilter, isAny),
682
+ system: selectBuiltinTypeAgents(agents).length
683
+ })
684
+ );
647
685
  var selectTotalUserAgentsCount = memoize1(
648
- (agents) => selectUserTypeAgents(agents).length
686
+ (agents) => countUserRows(agents, "active", isAny)
649
687
  );
650
688
  var selectTotalOwnedAgentsCount = memoize1(
651
- (agents) => selectUserTypeAgents(agents).filter((a) => a.isOwner === true).length
689
+ (agents) => countUserRows(agents, "active", isOwned)
652
690
  );
653
691
  var selectTotalSharedAgentsCount = memoize1(
654
- (agents) => selectUserTypeAgents(agents).filter(
655
- (a) => a.isOwner === false && a.accessLevel != null
656
- ).length
692
+ (agents) => countUserRows(agents, "active", isShared)
657
693
  );
658
694
  var selectTotalBuiltinAgentsCount = memoize1(
659
695
  (agents) => selectBuiltinTypeAgents(agents).length
660
696
  );
661
697
  var selectTotalFavoriteAgentsCount = memoize1(
662
- (agents) => selectUserTypeAgents(agents).filter((a) => a.isFavorite).length
698
+ (agents) => countUserRows(agents, "active", isFavorite)
663
699
  );
664
700
 
665
701
  // catalog/shared/useAgentListCore.ts
@@ -690,7 +726,8 @@ function useAgentListCore({
690
726
  const consumer = useAgentConsumer(consumerId, { unregisterOnUnmount: true });
691
727
  const rows = useAgentCatalogRows();
692
728
  const userId = catalog.getUserIdOrNull();
693
- const ownedCount = selectTotalOwnedAgentsCount(rows);
729
+ const tabCountsForFilter = selectAgentTabCounts(rows, consumer.state.archFilter);
730
+ const ownedCount = tabCountsForFilter.mine;
694
731
  const selectFiltered = (0, import_react4.useMemo)(
695
732
  () => makeSelectFilteredAgents(includeSystemInAll),
696
733
  [includeSystemInAll]
@@ -707,12 +744,7 @@ function useAgentListCore({
707
744
  const onSystemTab = consumer.tab === "system";
708
745
  const allCategories = onSystemTab ? selectAllSystemAgentCategories(rows) : selectAllAgentCategories(rows);
709
746
  const allTags = onSystemTab ? selectAllSystemAgentTags(rows) : selectAllAgentTags(rows);
710
- const tabCounts = {
711
- mine: ownedCount,
712
- shared: selectTotalSharedAgentsCount(rows),
713
- all: selectTotalUserAgentsCount(rows),
714
- system: selectTotalBuiltinAgentsCount(rows)
715
- };
747
+ const tabCounts = tabCountsForFilter;
716
748
  const isLoading = status === "loading";
717
749
  const agentsLoaded = status === "succeeded" || status === "failed";
718
750
  const ensureLoaded = (0, import_react4.useCallback)(() => {
@@ -1229,15 +1261,15 @@ function FavoriteAgentButton({
1229
1261
  [id]
1230
1262
  );
1231
1263
  const record = useAgentCatalogState(select);
1232
- const isFavorite = record?.isFavorite ?? false;
1264
+ const isFavorite2 = record?.isFavorite ?? false;
1233
1265
  const isOwner = record?.isOwner ?? true;
1234
1266
  const handleClick = (e) => {
1235
1267
  e.stopPropagation();
1236
1268
  if (disabled || !isOwner) return;
1237
- void catalog.setFavorite(id, !isFavorite).catch(() => {
1269
+ void catalog.setFavorite(id, !isFavorite2).catch(() => {
1238
1270
  });
1239
1271
  };
1240
- const title = isOwner ? isFavorite ? "Remove from favorites" : "Add to favorites" : "Shared \u2014 cannot favorite";
1272
+ const title = isOwner ? isFavorite2 ? "Remove from favorites" : "Add to favorites" : "Shared \u2014 cannot favorite";
1241
1273
  if (variant === "list") {
1242
1274
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1243
1275
  "button",
@@ -1251,14 +1283,14 @@ function FavoriteAgentButton({
1251
1283
  onClick: handleClick,
1252
1284
  disabled: disabled || !isOwner,
1253
1285
  title,
1254
- "aria-label": isFavorite ? "Remove from favorites" : "Add to favorites",
1286
+ "aria-label": isFavorite2 ? "Remove from favorites" : "Add to favorites",
1255
1287
  children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1256
1288
  StarIcon,
1257
1289
  {
1258
- filled: isFavorite,
1290
+ filled: isFavorite2,
1259
1291
  className: (0, import_design_system2.cn)(
1260
1292
  "h-3.5 w-3.5 transition-all duration-150",
1261
- isFavorite ? "matrx-agent-star-on" : "text-muted-foreground/40 hover:matrx-agent-star-on"
1293
+ isFavorite2 ? "matrx-agent-star-on" : "text-muted-foreground/40 hover:matrx-agent-star-on"
1262
1294
  )
1263
1295
  }
1264
1296
  )
@@ -1273,13 +1305,13 @@ function FavoriteAgentButton({
1273
1305
  "absolute top-2.5 right-2.5 z-10 p-0.5 rounded transition-all duration-150",
1274
1306
  "focus:outline-none focus-visible:ring-2 focus-visible:ring-primary",
1275
1307
  disabled || !isOwner ? "cursor-not-allowed" : "hover:scale-110 cursor-pointer",
1276
- isFavorite ? "matrx-agent-star-on" : "text-muted-foreground/40 hover:matrx-agent-star-on"
1308
+ isFavorite2 ? "matrx-agent-star-on" : "text-muted-foreground/40 hover:matrx-agent-star-on"
1277
1309
  ),
1278
1310
  onClick: handleClick,
1279
1311
  disabled: disabled || !isOwner,
1280
1312
  title,
1281
- "aria-label": isFavorite ? "Remove from favorites" : "Add to favorites",
1282
- children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(StarIcon, { filled: isFavorite, className: "w-4 h-4 transition-all duration-150" })
1313
+ "aria-label": isFavorite2 ? "Remove from favorites" : "Add to favorites",
1314
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(StarIcon, { filled: isFavorite2, className: "w-4 h-4 transition-all duration-150" })
1283
1315
  }
1284
1316
  );
1285
1317
  }
@@ -1615,6 +1647,7 @@ function AgentRow({
1615
1647
  return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
1616
1648
  "div",
1617
1649
  {
1650
+ "data-testid": `agent-row-${agent.id}`,
1618
1651
  className: (0, import_design_system5.cn)(
1619
1652
  "flex items-center w-full text-left transition-colors group",
1620
1653
  "hover:bg-muted/50 active:bg-muted/70",