@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.
@@ -567,6 +567,11 @@ declare function useAgentConsumer(consumerId: string, options?: {
567
567
  * The four ownership counts a tab strip prints. Declared HERE, beside the code
568
568
  * that computes them, so both the web tab strip and the native one name the
569
569
  * same shape (0.9.0 — it used to live in the web-only `AgentListTabs`).
570
+ *
571
+ * 🚨 These are the numbers on the BADGES, and since 0.9.1 they count exactly
572
+ * the rows the tab renders under the consumer's own archive filter. A badge
573
+ * that counted rows the list hid was the screen telling the user something
574
+ * untrue about her own agents.
570
575
  */
571
576
  interface AgentListTabCounts {
572
577
  mine: number;
@@ -567,6 +567,11 @@ declare function useAgentConsumer(consumerId: string, options?: {
567
567
  * The four ownership counts a tab strip prints. Declared HERE, beside the code
568
568
  * that computes them, so both the web tab strip and the native one name the
569
569
  * same shape (0.9.0 — it used to live in the web-only `AgentListTabs`).
570
+ *
571
+ * 🚨 These are the numbers on the BADGES, and since 0.9.1 they count exactly
572
+ * the rows the tab renders under the consumer's own archive filter. A badge
573
+ * that counted rows the list hid was the screen telling the user something
574
+ * untrue about her own agents.
570
575
  */
571
576
  interface AgentListTabCounts {
572
577
  mine: number;
@@ -422,7 +422,19 @@ function memoize2(fn) {
422
422
  return last;
423
423
  };
424
424
  }
425
+ function compareAgentIds(a, b) {
426
+ const idA = a.id ?? "";
427
+ const idB = b.id ?? "";
428
+ if (idA < idB) return -1;
429
+ if (idA > idB) return 1;
430
+ return 0;
431
+ }
425
432
  function applyAgentSortComparator(a, b, sortBy) {
433
+ const primary = compareAgentSortKey(a, b, sortBy);
434
+ if (!Number.isFinite(primary) || primary === 0) return compareAgentIds(a, b);
435
+ return primary;
436
+ }
437
+ function compareAgentSortKey(a, b, sortBy) {
426
438
  switch (sortBy) {
427
439
  case "name-asc":
428
440
  return (a.name ?? "").localeCompare(b.name ?? "");
@@ -598,22 +610,46 @@ var makeSelectFilteredAgents = (includeSystemInAll = false) => memoize2(
598
610
  return filterUserTypeAgents(userAgents, consumer);
599
611
  }
600
612
  );
613
+ function agentMatchesArchiveFilter(agent, archFilter) {
614
+ if (archFilter === "active") return !agent.isArchived;
615
+ if (archFilter === "archived") return Boolean(agent.isArchived);
616
+ return true;
617
+ }
618
+ function countUserRows(agents, archFilter, predicate) {
619
+ let n = 0;
620
+ for (const a of agents) {
621
+ if (a.agentType !== "user") continue;
622
+ if (!agentMatchesArchiveFilter(a, archFilter)) continue;
623
+ if (predicate(a)) n += 1;
624
+ }
625
+ return n;
626
+ }
627
+ var isOwned = (a) => a.isOwner === true;
628
+ var isShared = (a) => a.isOwner === false && a.accessLevel != null;
629
+ var isAny = () => true;
630
+ var isFavorite = (a) => Boolean(a.isFavorite);
631
+ var selectAgentTabCounts = memoize2(
632
+ (agents, archFilter) => ({
633
+ mine: countUserRows(agents, archFilter, isOwned),
634
+ shared: countUserRows(agents, archFilter, isShared),
635
+ all: countUserRows(agents, archFilter, isAny),
636
+ system: selectBuiltinTypeAgents(agents).length
637
+ })
638
+ );
601
639
  var selectTotalUserAgentsCount = memoize1(
602
- (agents) => selectUserTypeAgents(agents).length
640
+ (agents) => countUserRows(agents, "active", isAny)
603
641
  );
604
642
  var selectTotalOwnedAgentsCount = memoize1(
605
- (agents) => selectUserTypeAgents(agents).filter((a) => a.isOwner === true).length
643
+ (agents) => countUserRows(agents, "active", isOwned)
606
644
  );
607
645
  var selectTotalSharedAgentsCount = memoize1(
608
- (agents) => selectUserTypeAgents(agents).filter(
609
- (a) => a.isOwner === false && a.accessLevel != null
610
- ).length
646
+ (agents) => countUserRows(agents, "active", isShared)
611
647
  );
612
648
  var selectTotalBuiltinAgentsCount = memoize1(
613
649
  (agents) => selectBuiltinTypeAgents(agents).length
614
650
  );
615
651
  var selectTotalFavoriteAgentsCount = memoize1(
616
- (agents) => selectUserTypeAgents(agents).filter((a) => a.isFavorite).length
652
+ (agents) => countUserRows(agents, "active", isFavorite)
617
653
  );
618
654
 
619
655
  // catalog/shared/useAgentListCore.ts
@@ -644,7 +680,8 @@ function useAgentListCore({
644
680
  const consumer = useAgentConsumer(consumerId, { unregisterOnUnmount: true });
645
681
  const rows = useAgentCatalogRows();
646
682
  const userId = catalog.getUserIdOrNull();
647
- const ownedCount = selectTotalOwnedAgentsCount(rows);
683
+ const tabCountsForFilter = selectAgentTabCounts(rows, consumer.state.archFilter);
684
+ const ownedCount = tabCountsForFilter.mine;
648
685
  const selectFiltered = useMemo3(
649
686
  () => makeSelectFilteredAgents(includeSystemInAll),
650
687
  [includeSystemInAll]
@@ -661,12 +698,7 @@ function useAgentListCore({
661
698
  const onSystemTab = consumer.tab === "system";
662
699
  const allCategories = onSystemTab ? selectAllSystemAgentCategories(rows) : selectAllAgentCategories(rows);
663
700
  const allTags = onSystemTab ? selectAllSystemAgentTags(rows) : selectAllAgentTags(rows);
664
- const tabCounts = {
665
- mine: ownedCount,
666
- shared: selectTotalSharedAgentsCount(rows),
667
- all: selectTotalUserAgentsCount(rows),
668
- system: selectTotalBuiltinAgentsCount(rows)
669
- };
701
+ const tabCounts = tabCountsForFilter;
670
702
  const isLoading = status === "loading";
671
703
  const agentsLoaded = status === "succeeded" || status === "failed";
672
704
  const ensureLoaded = useCallback3(() => {
@@ -1196,15 +1228,15 @@ function FavoriteAgentButton({
1196
1228
  [id]
1197
1229
  );
1198
1230
  const record = useAgentCatalogState(select);
1199
- const isFavorite = record?.isFavorite ?? false;
1231
+ const isFavorite2 = record?.isFavorite ?? false;
1200
1232
  const isOwner = record?.isOwner ?? true;
1201
1233
  const handleClick = (e) => {
1202
1234
  e.stopPropagation();
1203
1235
  if (disabled || !isOwner) return;
1204
- void catalog.setFavorite(id, !isFavorite).catch(() => {
1236
+ void catalog.setFavorite(id, !isFavorite2).catch(() => {
1205
1237
  });
1206
1238
  };
1207
- const title = isOwner ? isFavorite ? "Remove from favorites" : "Add to favorites" : "Shared \u2014 cannot favorite";
1239
+ const title = isOwner ? isFavorite2 ? "Remove from favorites" : "Add to favorites" : "Shared \u2014 cannot favorite";
1208
1240
  if (variant === "list") {
1209
1241
  return /* @__PURE__ */ jsx6(
1210
1242
  "button",
@@ -1218,14 +1250,14 @@ function FavoriteAgentButton({
1218
1250
  onClick: handleClick,
1219
1251
  disabled: disabled || !isOwner,
1220
1252
  title,
1221
- "aria-label": isFavorite ? "Remove from favorites" : "Add to favorites",
1253
+ "aria-label": isFavorite2 ? "Remove from favorites" : "Add to favorites",
1222
1254
  children: /* @__PURE__ */ jsx6(
1223
1255
  StarIcon,
1224
1256
  {
1225
- filled: isFavorite,
1257
+ filled: isFavorite2,
1226
1258
  className: cn2(
1227
1259
  "h-3.5 w-3.5 transition-all duration-150",
1228
- isFavorite ? "matrx-agent-star-on" : "text-muted-foreground/40 hover:matrx-agent-star-on"
1260
+ isFavorite2 ? "matrx-agent-star-on" : "text-muted-foreground/40 hover:matrx-agent-star-on"
1229
1261
  )
1230
1262
  }
1231
1263
  )
@@ -1240,13 +1272,13 @@ function FavoriteAgentButton({
1240
1272
  "absolute top-2.5 right-2.5 z-10 p-0.5 rounded transition-all duration-150",
1241
1273
  "focus:outline-none focus-visible:ring-2 focus-visible:ring-primary",
1242
1274
  disabled || !isOwner ? "cursor-not-allowed" : "hover:scale-110 cursor-pointer",
1243
- isFavorite ? "matrx-agent-star-on" : "text-muted-foreground/40 hover:matrx-agent-star-on"
1275
+ isFavorite2 ? "matrx-agent-star-on" : "text-muted-foreground/40 hover:matrx-agent-star-on"
1244
1276
  ),
1245
1277
  onClick: handleClick,
1246
1278
  disabled: disabled || !isOwner,
1247
1279
  title,
1248
- "aria-label": isFavorite ? "Remove from favorites" : "Add to favorites",
1249
- children: /* @__PURE__ */ jsx6(StarIcon, { filled: isFavorite, className: "w-4 h-4 transition-all duration-150" })
1280
+ "aria-label": isFavorite2 ? "Remove from favorites" : "Add to favorites",
1281
+ children: /* @__PURE__ */ jsx6(StarIcon, { filled: isFavorite2, className: "w-4 h-4 transition-all duration-150" })
1250
1282
  }
1251
1283
  );
1252
1284
  }
@@ -1582,6 +1614,7 @@ function AgentRow({
1582
1614
  return /* @__PURE__ */ jsxs7(
1583
1615
  "div",
1584
1616
  {
1617
+ "data-testid": `agent-row-${agent.id}`,
1585
1618
  className: cn5(
1586
1619
  "flex items-center w-full text-left transition-colors group",
1587
1620
  "hover:bg-muted/50 active:bg-muted/70",