@ai-matrx/agents 0.9.0 → 0.9.2

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.
@@ -15,6 +15,24 @@ var SORT_OPTIONS = [
15
15
  { value: "name-desc", label: "Z \u2192 A" },
16
16
  { value: "category-asc", label: "Category" }
17
17
  ];
18
+ var ARCHIVE_FILTER_ORDER = [
19
+ "active",
20
+ "both",
21
+ "archived"
22
+ ];
23
+ var ARCHIVE_FILTER_OPTIONS = [
24
+ { value: "active", label: "Hide archived", chip: "Archive" },
25
+ { value: "both", label: "Show all", chip: "All + archived" },
26
+ { value: "archived", label: "Archived only", chip: "Archived only" }
27
+ ];
28
+ function nextArchFilter(current) {
29
+ const index = ARCHIVE_FILTER_ORDER.indexOf(current);
30
+ if (index < 0) return ARCHIVE_FILTER_ORDER[0];
31
+ return ARCHIVE_FILTER_ORDER[(index + 1) % ARCHIVE_FILTER_ORDER.length];
32
+ }
33
+ function isAgentArchFilter(value) {
34
+ return value === "active" || value === "archived" || value === "both";
35
+ }
18
36
  var AGENT_NONE_SENTINEL = "__none__";
19
37
  var DEFAULT_AGENT_CONSUMER_STATE = {
20
38
  tab: "mine",
@@ -219,8 +237,8 @@ async function readSingleAgentRow(client, agentId) {
219
237
  }
220
238
  return null;
221
239
  }
222
- async function writeAgentFavorite(client, agentId, isFavorite) {
223
- const { error } = await client.schema("agent").from("definition").update({ is_favorite: isFavorite }).eq("id", agentId);
240
+ async function writeAgentFavorite(client, agentId, isFavorite2) {
241
+ const { error } = await client.schema("agent").from("definition").update({ is_favorite: isFavorite2 }).eq("id", agentId);
224
242
  if (error) {
225
243
  throw new AgentCatalogReadError(
226
244
  "agent.definition.is_favorite",
@@ -637,6 +655,18 @@ function createAgentCatalog(config) {
637
655
  remedy: "pass `identity: { requireUserId() }` \u2014 never a silent anonymous read"
638
656
  });
639
657
  }
658
+ const archiveDefault = config.defaults?.archiveFilter;
659
+ if (archiveDefault !== void 0 && !isAgentArchFilter(archiveDefault)) {
660
+ throw new AgentCatalogConfigError({
661
+ code: "invalid_archive_default",
662
+ message: `defaults.archiveFilter was ${JSON.stringify(archiveDefault)}, which is not one of the three states of the platform archive filter`,
663
+ remedy: 'pass "active" (hide archived), "both" (show all) or "archived" (archived only)'
664
+ });
665
+ }
666
+ const consumerDefaults = {
667
+ ...DEFAULT_AGENT_CONSUMER_STATE,
668
+ ...archiveDefault ? { archFilter: archiveDefault } : {}
669
+ };
640
670
  const catalogId = config.catalogId ?? "default";
641
671
  const client = config.client;
642
672
  const identity = config.identity;
@@ -737,7 +767,7 @@ function createAgentCatalog(config) {
737
767
  return run;
738
768
  }
739
769
  function getConsumer(consumerId) {
740
- return state.consumers[consumerId] ?? DEFAULT_AGENT_CONSUMER_STATE;
770
+ return state.consumers[consumerId] ?? consumerDefaults;
741
771
  }
742
772
  function writeConsumer(consumerId, next) {
743
773
  publish({
@@ -748,7 +778,7 @@ function createAgentCatalog(config) {
748
778
  function registerConsumer(consumerId, initial) {
749
779
  if (state.consumers[consumerId]) return;
750
780
  writeConsumer(consumerId, {
751
- ...DEFAULT_AGENT_CONSUMER_STATE,
781
+ ...consumerDefaults,
752
782
  ...initial ?? {}
753
783
  });
754
784
  }
@@ -759,9 +789,7 @@ function createAgentCatalog(config) {
759
789
  publish({ ...state, consumers });
760
790
  }
761
791
  function setConsumerFilter(consumerId, patch) {
762
- const current = state.consumers[consumerId] ?? {
763
- ...DEFAULT_AGENT_CONSUMER_STATE
764
- };
792
+ const current = state.consumers[consumerId] ?? { ...consumerDefaults };
765
793
  writeConsumer(consumerId, {
766
794
  ...current,
767
795
  ...patch,
@@ -778,9 +806,7 @@ function createAgentCatalog(config) {
778
806
  );
779
807
  }
780
808
  function setConsumerServerSearch(consumerId, args) {
781
- const current = state.consumers[consumerId] ?? {
782
- ...DEFAULT_AGENT_CONSUMER_STATE
783
- };
809
+ const current = state.consumers[consumerId] ?? { ...consumerDefaults };
784
810
  const next = { ...current };
785
811
  if (args.matchedIds !== void 0) next.serverMatchedIds = args.matchedIds;
786
812
  if (args.isSearching !== void 0) next.isServerSearching = args.isSearching;
@@ -791,14 +817,14 @@ function createAgentCatalog(config) {
791
817
  }
792
818
  function resetConsumerFilters(consumerId) {
793
819
  if (!state.consumers[consumerId]) return;
794
- writeConsumer(consumerId, { ...DEFAULT_AGENT_CONSUMER_STATE });
820
+ writeConsumer(consumerId, { ...consumerDefaults });
795
821
  }
796
822
  async function searchServer(query, deep = false) {
797
823
  const result = await searchAgentsOnServer(client, { query, deep });
798
824
  mergeRows(result.rows);
799
825
  return result.ids;
800
826
  }
801
- async function setFavorite(agentId, isFavorite) {
827
+ async function setFavorite(agentId, isFavorite2) {
802
828
  const existing = state.byId[agentId];
803
829
  if (!existing) {
804
830
  errorSink({
@@ -807,15 +833,15 @@ function createAgentCatalog(config) {
807
833
  });
808
834
  return;
809
835
  }
810
- mergeRows([{ ...existing, isFavorite }]);
836
+ mergeRows([{ ...existing, isFavorite: isFavorite2 }]);
811
837
  try {
812
- await writeAgentFavorite(client, agentId, isFavorite);
838
+ await writeAgentFavorite(client, agentId, isFavorite2);
813
839
  } catch (e) {
814
840
  mergeRows([existing]);
815
841
  errorSink({
816
842
  code: "favorite_write_failed",
817
843
  message: `the favorite could not be saved: ${errorMessage(e)}`,
818
- context: { agentId, isFavorite }
844
+ context: { agentId, isFavorite: isFavorite2 }
819
845
  });
820
846
  notifier?.({
821
847
  level: "error",
@@ -921,6 +947,7 @@ function createAgentCatalog(config) {
921
947
  errorSink,
922
948
  notifier,
923
949
  canResolveMandates: transport !== void 0,
950
+ consumerDefaults,
924
951
  getState: () => state,
925
952
  subscribe: (listener) => {
926
953
  listeners.add(listener);
@@ -998,6 +1025,26 @@ function shouldDefaultAgentListToPublicTab(args) {
998
1025
  if (!args.agentsLoaded) return false;
999
1026
  return args.ownedCount === 0;
1000
1027
  }
1028
+ function agentArchiveFilterChipLabel(archFilter) {
1029
+ return ARCHIVE_FILTER_OPTIONS.find((o) => o.value === archFilter)?.chip ?? "Archive";
1030
+ }
1031
+ function agentArchiveFilterStateLabel(archFilter) {
1032
+ return ARCHIVE_FILTER_OPTIONS.find((o) => o.value === archFilter)?.label ?? "Hide archived";
1033
+ }
1034
+ function agentArchiveFilterControlLabel(archFilter) {
1035
+ return `Archive filter: ${agentArchiveFilterStateLabel(
1036
+ archFilter
1037
+ ).toLowerCase()}. Click for ${agentArchiveFilterStateLabel(
1038
+ nextArchFilter(archFilter)
1039
+ ).toLowerCase()}`;
1040
+ }
1041
+ function agentListFooterLabel(args) {
1042
+ const { count, archFilter, archivedHiddenCount } = args;
1043
+ if (archFilter === "archived") return `${count} archived shown`;
1044
+ const base = `${count} agent${count !== 1 ? "s" : ""}`;
1045
+ if (archFilter === "both") return `${base} \xB7 archived shown`;
1046
+ return archivedHiddenCount > 0 ? `${base} \xB7 ${archivedHiddenCount} archived hidden` : base;
1047
+ }
1001
1048
 
1002
1049
  // catalog/score.ts
1003
1050
  function computeAgentSearchScore(agent, query) {
@@ -1094,7 +1141,19 @@ function memoize3(fn) {
1094
1141
  return last;
1095
1142
  };
1096
1143
  }
1144
+ function compareAgentIds(a, b) {
1145
+ const idA = a.id ?? "";
1146
+ const idB = b.id ?? "";
1147
+ if (idA < idB) return -1;
1148
+ if (idA > idB) return 1;
1149
+ return 0;
1150
+ }
1097
1151
  function applyAgentSortComparator(a, b, sortBy) {
1152
+ const primary = compareAgentSortKey(a, b, sortBy);
1153
+ if (!Number.isFinite(primary) || primary === 0) return compareAgentIds(a, b);
1154
+ return primary;
1155
+ }
1156
+ function compareAgentSortKey(a, b, sortBy) {
1098
1157
  switch (sortBy) {
1099
1158
  case "name-asc":
1100
1159
  return (a.name ?? "").localeCompare(b.name ?? "");
@@ -1196,8 +1255,7 @@ function filterUserTypeAgents(agents, consumer) {
1196
1255
  if (tab === "mine" && agent.isOwner !== true) return false;
1197
1256
  if (tab === "shared" && !(agent.isOwner === false && agent.accessLevel != null))
1198
1257
  return false;
1199
- if (archFilter === "active" && agent.isArchived) return false;
1200
- if (archFilter === "archived" && !agent.isArchived) return false;
1258
+ if (!agentMatchesArchiveFilter(agent, archFilter)) return false;
1201
1259
  if (favFilter === "yes" && !agent.isFavorite) return false;
1202
1260
  if (favFilter === "no" && agent.isFavorite) return false;
1203
1261
  if (accessFilter === "owned" && agent.isOwner !== true) return false;
@@ -1227,9 +1285,10 @@ function filterUserTypeAgents(agents, consumer) {
1227
1285
  return sortFilteredAgents(filtered, consumer);
1228
1286
  }
1229
1287
  function filterBuiltinTypeAgents(agents, consumer) {
1230
- const { searchTerm, favFilter, includedCats, includedTags } = consumer;
1288
+ const { searchTerm, favFilter, archFilter, includedCats, includedTags } = consumer;
1231
1289
  const serverMatched = new Set(consumer.serverMatchedIds);
1232
1290
  const filtered = agents.filter((agent) => {
1291
+ if (!agentMatchesArchiveFilter(agent, archFilter)) return false;
1233
1292
  if (favFilter === "yes" && !agent.isFavorite) return false;
1234
1293
  if (favFilter === "no" && agent.isFavorite) return false;
1235
1294
  if (includedCats.length > 0) {
@@ -1342,22 +1401,55 @@ var makeSelectFilteredBuiltinAgentsCount = () => {
1342
1401
  function agentConsumerHasActiveFilters(consumer, defaults) {
1343
1402
  return consumer.tab !== defaults.tab || consumer.sortBy !== defaults.sortBy || consumer.searchTerm !== "" || consumer.includedCats.length > 0 || consumer.includedTags.length > 0 || consumer.favFilter !== defaults.favFilter || consumer.archFilter !== defaults.archFilter || consumer.accessFilter !== defaults.accessFilter || consumer.favoritesFirst !== defaults.favoritesFirst;
1344
1403
  }
1404
+ function agentMatchesArchiveFilter(agent, archFilter) {
1405
+ if (archFilter === "active") return !agent.isArchived;
1406
+ if (archFilter === "archived") return Boolean(agent.isArchived);
1407
+ return true;
1408
+ }
1409
+ function countBuiltinRows(agents, archFilter) {
1410
+ let n = 0;
1411
+ for (const a of agents) {
1412
+ if (a.agentType !== "builtin") continue;
1413
+ if (!agentMatchesArchiveFilter(a, archFilter)) continue;
1414
+ n += 1;
1415
+ }
1416
+ return n;
1417
+ }
1418
+ function countUserRows(agents, archFilter, predicate) {
1419
+ let n = 0;
1420
+ for (const a of agents) {
1421
+ if (a.agentType !== "user") continue;
1422
+ if (!agentMatchesArchiveFilter(a, archFilter)) continue;
1423
+ if (predicate(a)) n += 1;
1424
+ }
1425
+ return n;
1426
+ }
1427
+ var isOwned = (a) => a.isOwner === true;
1428
+ var isShared = (a) => a.isOwner === false && a.accessLevel != null;
1429
+ var isAny = () => true;
1430
+ var isFavorite = (a) => Boolean(a.isFavorite);
1431
+ var selectAgentTabCounts = memoize2(
1432
+ (agents, archFilter) => ({
1433
+ mine: countUserRows(agents, archFilter, isOwned),
1434
+ shared: countUserRows(agents, archFilter, isShared),
1435
+ all: countUserRows(agents, archFilter, isAny),
1436
+ system: countBuiltinRows(agents, archFilter)
1437
+ })
1438
+ );
1345
1439
  var selectTotalUserAgentsCount = memoize1(
1346
- (agents) => selectUserTypeAgents(agents).length
1440
+ (agents) => countUserRows(agents, "active", isAny)
1347
1441
  );
1348
1442
  var selectTotalOwnedAgentsCount = memoize1(
1349
- (agents) => selectUserTypeAgents(agents).filter((a) => a.isOwner === true).length
1443
+ (agents) => countUserRows(agents, "active", isOwned)
1350
1444
  );
1351
1445
  var selectTotalSharedAgentsCount = memoize1(
1352
- (agents) => selectUserTypeAgents(agents).filter(
1353
- (a) => a.isOwner === false && a.accessLevel != null
1354
- ).length
1446
+ (agents) => countUserRows(agents, "active", isShared)
1355
1447
  );
1356
1448
  var selectTotalBuiltinAgentsCount = memoize1(
1357
- (agents) => selectBuiltinTypeAgents(agents).length
1449
+ (agents) => countBuiltinRows(agents, "active")
1358
1450
  );
1359
1451
  var selectTotalFavoriteAgentsCount = memoize1(
1360
- (agents) => selectUserTypeAgents(agents).filter((a) => a.isFavorite).length
1452
+ (agents) => countUserRows(agents, "active", isFavorite)
1361
1453
  );
1362
1454
  export {
1363
1455
  AGENT_CARDS_LIMIT_DESKTOP,
@@ -1365,6 +1457,8 @@ export {
1365
1457
  AGENT_LIST_ITEMS_PER_PAGE,
1366
1458
  AGENT_NONE_SENTINEL,
1367
1459
  AGENT_SEARCH_LIMIT,
1460
+ ARCHIVE_FILTER_OPTIONS,
1461
+ ARCHIVE_FILTER_ORDER,
1368
1462
  AgentCatalogConfigError,
1369
1463
  AgentCatalogReadError,
1370
1464
  DEFAULT_AGENT_CATALOG_LABELS,
@@ -1372,12 +1466,18 @@ export {
1372
1466
  MandateDefaultRowError,
1373
1467
  SORT_OPTIONS,
1374
1468
  _resetCatalogGlobalState,
1469
+ agentArchiveFilterChipLabel,
1470
+ agentArchiveFilterControlLabel,
1471
+ agentArchiveFilterStateLabel,
1375
1472
  agentConsumerHasActiveFilters,
1376
1473
  agentListEmptyLabel,
1474
+ agentListFooterLabel,
1475
+ agentMatchesArchiveFilter,
1377
1476
  agentMatchesSearch,
1378
1477
  applyAgentSortComparator,
1379
1478
  asAgentId,
1380
1479
  assertAgentCatalogSchema,
1480
+ compareAgentIds,
1381
1481
  computeAgentSearchScore,
1382
1482
  createAgentCatalog,
1383
1483
  createMemoryStorage,
@@ -1387,6 +1487,7 @@ export {
1387
1487
  filterBuiltinTypeAgents,
1388
1488
  filterUserTypeAgents,
1389
1489
  getRegisteredAgentCatalog,
1490
+ isAgentArchFilter,
1390
1491
  isMandateAgentId,
1391
1492
  makeSelectFilteredAgents,
1392
1493
  makeSelectFilteredAgentsCount,
@@ -1402,6 +1503,7 @@ export {
1402
1503
  memoize1,
1403
1504
  memoize2,
1404
1505
  memoize3,
1506
+ nextArchFilter,
1405
1507
  orchestraDelegatesLine,
1406
1508
  orchestraDepthLine,
1407
1509
  orchestraLabel,
@@ -1413,6 +1515,7 @@ export {
1413
1515
  readSingleAgentRow,
1414
1516
  resolveDefaultRow,
1415
1517
  searchAgentsOnServer,
1518
+ selectAgentTabCounts,
1416
1519
  selectAllAgentCategories,
1417
1520
  selectAllAgentTags,
1418
1521
  selectAllSystemAgentCategories,