@ai-matrx/agents 0.6.2 → 0.7.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.
@@ -0,0 +1,819 @@
1
+ import * as react from 'react';
2
+ import { ComponentType, ReactNode, Ref } from 'react';
3
+
4
+ /**
5
+ * `@ai-matrx/agents/catalog` — the row shape and the per-consumer view state.
6
+ *
7
+ * `AgentSummary` is the 19-column row `agx_get_list_full()` returns, camelCased.
8
+ * It is deliberately NOT the editable agent record: dirty tracking, undo,
9
+ * messages, tools and `_fetchStatus` stay in whichever host owns the editor.
10
+ * A list row is a list row.
11
+ *
12
+ * The view-state types are a VERBATIM port of matrx-frontend
13
+ * `features/agents/redux/agent-consumers/slice.ts` — only the coupling seam
14
+ * inverts (Redux reducers become store actions in `./store`).
15
+ */
16
+ /**
17
+ * A branded agent id. Every id that reaches `onSelect` is one of these:
18
+ * either a `agent.definition` UUID, or the `mandate:<key>` reference a
19
+ * default row carries (byte-identical to the ref shape matrx-extend
20
+ * `src/lib/mandates.ts` and matrx-local `desktop/src/lib/mandates.ts`
21
+ * already hand back to their hosts).
22
+ *
23
+ * 🚨 The brand is a STRING LITERAL, never `unique symbol`. This package emits
24
+ * `./catalog` and `./catalog/react` as two separate bundles, so each `.d.ts`
25
+ * carries its own copy of these declarations. A `unique symbol` brand is
26
+ * NOMINAL: two copies of it are unrelated types, so `createAgentCatalog()`
27
+ * from `./catalog` was not assignable to `<AgentCatalogProvider catalog=…>`
28
+ * from `./catalog/react` — the exact two-import wiring the README, the
29
+ * CHANGELOG and every consumer use. A literal brand is structural, so the two
30
+ * copies unify, while a bare `string` still cannot be passed where an
31
+ * `AgentId` is required (which is the whole point of branding). Any future
32
+ * brand in this package follows the same rule.
33
+ */
34
+ type AgentId = string & {
35
+ readonly __agentId: "ai-matrx.agent-id";
36
+ };
37
+ /** `agent_type` verbatim. Only `builtin` changes how a row is grouped. */
38
+ type AgentCatalogAgentType = "user" | "builtin";
39
+ /**
40
+ * `access_level` verbatim from `agx_get_list_full`. Widened over the raw
41
+ * string because it is a DB-owned vocabulary: an unknown level renders as
42
+ * itself rather than being coerced into a wrong one.
43
+ */
44
+ type AgentAccessLevel = "owner" | "admin" | "editor" | "viewer" | "system" | (string & {});
45
+ /**
46
+ * One `agx_get_list_full()` row, camelCased. Nineteen columns, no more:
47
+ * anything richer needs a different read and is a different type.
48
+ */
49
+ interface AgentSummary {
50
+ id: AgentId;
51
+ name: string | null;
52
+ description: string | null;
53
+ category: string | null;
54
+ tags: string[];
55
+ agentType: AgentCatalogAgentType;
56
+ modelId: string | null;
57
+ isActive: boolean;
58
+ isArchived: boolean;
59
+ isFavorite: boolean;
60
+ createdBy: string | null;
61
+ organizationId: string | null;
62
+ taskId: string | null;
63
+ sourceAgentId: string | null;
64
+ createdAt: string | null;
65
+ updatedAt: string | null;
66
+ isOwner: boolean | null;
67
+ accessLevel: AgentAccessLevel | null;
68
+ sharedByEmail: string | null;
69
+ /**
70
+ * Set only on a mandate default row — the key it resolved through, so a
71
+ * host can tell "the default" from a stored agent without parsing the id.
72
+ */
73
+ mandateKey?: string;
74
+ }
75
+ type AgentSortOption = "updated-desc" | "created-desc" | "name-asc" | "name-desc" | "category-asc";
76
+ /** Which ownership tab is active in the agent list. */
77
+ type AgentTab = "mine" | "shared" | "all" | "system";
78
+ /** Favorite filter. */
79
+ type AgentFavFilter = "all" | "yes" | "no";
80
+ /** Archive filter. */
81
+ type AgentArchFilter = "active" | "archived" | "both";
82
+ /**
83
+ * Access level filter.
84
+ * 'any' = no restriction (default).
85
+ * 'owned' = only agents the user owns (isOwner = true).
86
+ * 'shared' = only agents shared with the user (isOwner = false).
87
+ * 'editable' = owner + admin + editor.
88
+ */
89
+ type AgentAccessFilter = "any" | "owned" | "shared" | "editable";
90
+ interface AgentConsumerState {
91
+ tab: AgentTab;
92
+ sortBy: AgentSortOption;
93
+ searchTerm: string;
94
+ /** INCLUSION model: empty = show all; non-empty = only matching. */
95
+ includedCats: string[];
96
+ /** INCLUSION model: empty = show all; non-empty = only matching. */
97
+ includedTags: string[];
98
+ favFilter: AgentFavFilter;
99
+ archFilter: AgentArchFilter;
100
+ accessFilter: AgentAccessFilter;
101
+ favoritesFirst: boolean;
102
+ /** Current page for owned-agent list items (after the card section). */
103
+ listPage: number;
104
+ /** Current page for shared-agent list items. */
105
+ sharedPage: number;
106
+ /**
107
+ * Ids returned by the last server-side search (`agx_search`), in server rank
108
+ * order. Additive: an agent in this list survives the search filter even
109
+ * when the local scorer gives it 0.
110
+ *
111
+ * That is load-bearing for tier 2. A deep search matches an agent's prompt
112
+ * content, which the client never loads — so the local scorer cannot see it.
113
+ * Without this list the server would return prompt matches and the UI would
114
+ * immediately filter them back out.
115
+ *
116
+ * Server-only matches sort BELOW every locally-scored match, in server rank
117
+ * order, so obvious matches always come first.
118
+ */
119
+ serverMatchedIds: string[];
120
+ /** True while a server search is in flight — drives the search spinner. */
121
+ isServerSearching: boolean;
122
+ /** Tier 2: also search agent prompt content. Opt-in, per consumer. */
123
+ deepSearch: boolean;
124
+ }
125
+ /** The subset of consumer state a caller may patch (paging is derived). */
126
+ type AgentConsumerPatch = Partial<Omit<AgentConsumerState, "listPage" | "sharedPage">>;
127
+
128
+ /**
129
+ * catalog/default-row-types.ts — @ai-matrx/agents/catalog
130
+ *
131
+ * Split out of `default-row.ts` so `global-state.ts` can name the cached
132
+ * shape without importing the resolver (and its transport work) — the same
133
+ * split-out reflex C8 asks for, at module scale.
134
+ */
135
+
136
+ /** A resolved default row, cached for first paint and compared for drift. */
137
+ interface ResolvedDefaultRow {
138
+ mandateKey: string;
139
+ /** The `agent.definition` id the mandate resolved to. */
140
+ holderId: string;
141
+ /** The holder's REAL name, read from the catalogue — never hardcoded. */
142
+ holderName: string;
143
+ holderDescription: string | null;
144
+ provenance: string;
145
+ /** Epoch ms of this resolution. */
146
+ at: number;
147
+ }
148
+ /** What the picker renders and what it screams, together. */
149
+ interface DefaultRowState {
150
+ mandateKey: string;
151
+ /** The row to render at the top of the list. `null` until resolved. */
152
+ row: AgentSummary | null;
153
+ /** The last live resolution, or the cached one before the live answer lands. */
154
+ resolved: ResolvedDefaultRow | null;
155
+ /** True while the resolution is in flight. */
156
+ loading: boolean;
157
+ /**
158
+ * 🚨 THE DRIFT SCREAM. Set when the cached first-paint row and the LIVE
159
+ * resolution disagree on holder id or holder name. Rendered as a persistent
160
+ * in-picker banner AND sent to the `notifier` port — never console-only.
161
+ */
162
+ drift: string | null;
163
+ /** Set when the mandate could not be resolved at all. Loud, with a remedy. */
164
+ error: string | null;
165
+ }
166
+
167
+ /**
168
+ * `@ai-matrx/agents/catalog` — THE PORTS.
169
+ *
170
+ * Two are required (`client`, `identity`); every other one ships a working
171
+ * default with a DOCUMENTED degradation, per THE ALL-INCLUSIVE LAW. A host
172
+ * injects identity and a Supabase client and nothing else; the picker's only
173
+ * contract back to the host is `onSelect(agentId)`.
174
+ *
175
+ * React appears nowhere in this file — it is import-inert and legal in any
176
+ * graph, server components included.
177
+ */
178
+
179
+ /**
180
+ * Every degraded path, every failed read, every drift detection reports here.
181
+ * DEFAULT: a tagged `console.error` that announces ONCE that no sink is bound
182
+ * and names the remedy.
183
+ */
184
+ type AgentCatalogErrorSink = (event: {
185
+ code: string;
186
+ message: string;
187
+ context?: object;
188
+ }) => void;
189
+ /**
190
+ * The drift scream's second channel. DEFAULT: none — and that is safe
191
+ * ONLY because the in-picker persistent banner is the primary scream and
192
+ * always renders. A drift is never console-only.
193
+ */
194
+ type AgentCatalogNotifier = (event: {
195
+ level: "warning" | "error";
196
+ title: string;
197
+ message: string;
198
+ }) => void;
199
+ /** Every user-visible string the picker renders, overridable per host. */
200
+ interface AgentCatalogLabels {
201
+ /** User-facing label for the `system` ownership tab. */
202
+ publicTab: string;
203
+ /**
204
+ * Badge label on a builtin row. Default `"system"` — the string
205
+ * `AgentRow` actually rendered in matrx-frontend. (The frontend also
206
+ * declared `AGENT_PUBLIC_BADGE_LABEL = "Public"` for this badge and NOTHING
207
+ * ever read it — a constant that named the badge without being the badge.
208
+ * Recorded in the CHANGELOG and dropped rather than ported.)
209
+ */
210
+ systemBadge: string;
211
+ searchPlaceholder: string;
212
+ currentAgentHeading: string;
213
+ emptyDefault: string;
214
+ emptyShared: string;
215
+ emptySystem: string;
216
+ loading: string;
217
+ triggerFallback: string;
218
+ triggerResolving: string;
219
+ triggerUnnameable: string;
220
+ hoverHint: string;
221
+ }
222
+ /**
223
+ * Where a row's href goes when someone cmd-clicks it, and where `navigateTo`
224
+ * lands. DEFAULT: `window.location.assign` (so cmd-click and ordinary
225
+ * navigation both work with no host wiring at all).
226
+ */
227
+ type AgentCatalogNavigate = (href: string) => void;
228
+ /**
229
+ * The sneak-peek affordance. Absent → the affordance is HIDDEN, never a dead
230
+ * button (nothing fails silently, and nothing looks alive when it is not).
231
+ */
232
+ type AgentCatalogOpenPeek = (agent: AgentSummary) => void;
233
+
234
+ /**
235
+ * catalog/schema.ts — @ai-matrx/agents/catalog
236
+ *
237
+ * THE DEMANDED SCHEMA PROBE (the `@ai-matrx/associations` `assertDemandedSchema`
238
+ * precedent). It proves that the database a host pointed this catalog at can
239
+ * actually answer the three functions the picker demands.
240
+ *
241
+ * 🚨 IT MUST BE ABLE TO FAIL. A probe whose green result is unconditional
242
+ * proves nothing, so `selfTest: true` also probes a fabricated function name
243
+ * and REQUIRES it to come back missing. `catalog/__tests__/schema.test.ts`
244
+ * runs the whole probe against a client whose `rpc` answers PostgreSQL 42883
245
+ * (`undefined_function`, which PostgREST surfaces as PGRST202) and asserts the
246
+ * loud error.
247
+ */
248
+
249
+ interface AgentCatalogSchemaReport {
250
+ ok: boolean;
251
+ /** Demanded functions the database cannot answer. */
252
+ missing: string[];
253
+ /** Functions the probe could not reach (transport/unknown failure). */
254
+ unreachable: {
255
+ fn: string;
256
+ error: unknown;
257
+ }[];
258
+ /** Functions that answered (success or any non-missing refusal). */
259
+ answered: string[];
260
+ /** True when `agent.definition.is_favorite` is writable by this caller. */
261
+ favoriteWritable: boolean | null;
262
+ }
263
+ interface AssertAgentCatalogSchemaOptions {
264
+ /**
265
+ * Also probe a fabricated function name and REQUIRE it to come back
266
+ * missing — proves this probe can fail.
267
+ */
268
+ selfTest?: boolean;
269
+ /** Return the report instead of throwing. The self-test failure ALWAYS throws. */
270
+ throwOnViolation?: boolean;
271
+ /**
272
+ * Also probe the ONE write (`agent.definition.is_favorite`) against an
273
+ * impossible id, so a 42501/permission refusal is seen at boot rather than
274
+ * on a user's first click. Default: on.
275
+ */
276
+ probeWrite?: boolean;
277
+ }
278
+
279
+ /**
280
+ * catalog/store.ts — @ai-matrx/agents/catalog
281
+ *
282
+ * `createAgentCatalog(config)` — the headless kernel. Everything the picker
283
+ * knows lives here: the row registry, the complete-list read with its
284
+ * session-shared in-flight dedupe and freshness window, the tier-2 server
285
+ * search, the per-consumer view state, the ONE write, and the mandate default
286
+ * row with its drift screamer.
287
+ *
288
+ * The host injects a Supabase client and who the user is. Nothing else.
289
+ *
290
+ * The consumer reducers below are a VERBATIM port of matrx-frontend
291
+ * `features/agents/redux/agent-consumers/slice.ts`; only the seam inverts
292
+ * (a Redux reducer becomes a store method, and Immer's draft mutation becomes
293
+ * an explicit copy so the store can publish a new reference).
294
+ */
295
+
296
+ type AgentCatalogStatus = "idle" | "loading" | "succeeded" | "failed";
297
+ interface AgentCatalogState {
298
+ /** Every row, one stable array reference per change (memoization depends on it). */
299
+ rows: AgentSummary[];
300
+ byId: Record<string, AgentSummary>;
301
+ status: AgentCatalogStatus;
302
+ error: string | null;
303
+ consumers: Record<string, AgentConsumerState>;
304
+ /** Keyed by mandate key. */
305
+ defaultRows: Record<string, DefaultRowState>;
306
+ }
307
+ interface AgentCatalog {
308
+ readonly catalogId: string;
309
+ readonly labels: AgentCatalogLabels;
310
+ readonly errorSink: AgentCatalogErrorSink;
311
+ readonly notifier: AgentCatalogNotifier | undefined;
312
+ /** True when this catalog was given a transport and can resolve mandates. */
313
+ readonly canResolveMandates: boolean;
314
+ getState(): AgentCatalogState;
315
+ subscribe(listener: () => void): () => void;
316
+ getAgent(agentId: string): AgentSummary | undefined;
317
+ /**
318
+ * The signed-in user id, or `null` when there is no session. The ONE place
319
+ * `identity.requireUserId()`'s throw is caught — a signed-out visitor
320
+ * legitimately lands on the public catalogue — and it is reported to the
321
+ * errorSink the first time so it is never silent.
322
+ */
323
+ getUserIdOrNull(): string | null;
324
+ /** Load the catalogue if it is not fresh. Safe to call on every mount. */
325
+ ensureLoaded(options?: {
326
+ force?: boolean;
327
+ }): Promise<void>;
328
+ /** True when the last load is inside the 15-minute TTL. */
329
+ isFresh(): boolean;
330
+ /** True when the last load is older than 4 hours (tab-restore threshold). */
331
+ isStale(): boolean;
332
+ getConsumer(consumerId: string): AgentConsumerState;
333
+ registerConsumer(consumerId: string, initial?: AgentConsumerPatch): void;
334
+ unregisterConsumer(consumerId: string): void;
335
+ setConsumerFilter(consumerId: string, patch: AgentConsumerPatch): void;
336
+ setConsumerPage(consumerId: string, which: "list" | "shared", page: number): void;
337
+ setConsumerServerSearch(consumerId: string, args: {
338
+ matchedIds?: string[];
339
+ isSearching?: boolean;
340
+ }): void;
341
+ resetConsumerFilters(consumerId: string): void;
342
+ /** Tier-2 search. Purely additive; merges rows into the registry. */
343
+ searchServer(query: string, deep?: boolean): Promise<string[]>;
344
+ /** THE ONE WRITE. Optimistic, rolled back on failure, loud either way. */
345
+ setFavorite(agentId: string, isFavorite: boolean): Promise<void>;
346
+ /** Resolve (once) the default row for a mandate key. Idempotent. */
347
+ ensureDefaultRow(mandateKey: string): void;
348
+ getDefaultRow(mandateKey: string): DefaultRowState | undefined;
349
+ /** A person acknowledged the drift banner. The notifier already fired. */
350
+ dismissDefaultRowDrift(mandateKey: string): void;
351
+ assertSchema(options?: AssertAgentCatalogSchemaOptions): Promise<AgentCatalogSchemaReport>;
352
+ }
353
+
354
+ /**
355
+ * The anchor a row renders for cmd/ctrl-click. DEFAULT: a plain `<a>` — which
356
+ * is a REAL, working link in every framework. A Next.js host passes
357
+ * `next/link`; a TanStack host passes its own `Link`.
358
+ */
359
+ type AgentCatalogLinkComponent = ComponentType<{
360
+ href: string;
361
+ className?: string;
362
+ target?: string;
363
+ rel?: string;
364
+ title?: string;
365
+ "aria-label"?: string;
366
+ onClick?: (e: React.MouseEvent<HTMLAnchorElement>) => void;
367
+ children: ReactNode;
368
+ }>;
369
+ /** Render a model id as whatever door the host has. DEFAULT: plain text. */
370
+ type AgentCatalogRenderModelRef = (args: {
371
+ modelId: string;
372
+ className?: string;
373
+ }) => ReactNode;
374
+ interface AgentCatalogUiPorts {
375
+ /** DEFAULT: `window.location.assign`. */
376
+ navigate?: AgentCatalogNavigate;
377
+ /** DEFAULT: a plain `<a>`. */
378
+ LinkComponent?: AgentCatalogLinkComponent;
379
+ /** DEFAULT: the model id as plain text. */
380
+ renderModelRef?: AgentCatalogRenderModelRef;
381
+ /** ABSENT: the sneak-peek affordance is HIDDEN — never a dead button. */
382
+ openPeek?: AgentCatalogOpenPeek;
383
+ /**
384
+ * Portal container for the desktop popover, when the picker is mounted
385
+ * inside a dialog. DEFAULT: the document body (Radix's own default).
386
+ */
387
+ popoverContainer?: HTMLElement | null;
388
+ }
389
+ interface AgentCatalogProviderProps extends AgentCatalogUiPorts {
390
+ catalog: AgentCatalog;
391
+ children: ReactNode;
392
+ }
393
+ declare function AgentCatalogProvider({ catalog, children, ...ports }: AgentCatalogProviderProps): react.JSX.Element;
394
+ /** The headless catalog this tree is bound to. Throws with no provider. */
395
+ declare function useAgentCatalog(): AgentCatalog;
396
+ /** The UI ports this tree is bound to, with every default already applied. */
397
+ declare function useAgentCatalogUiPorts(): Required<Pick<AgentCatalogUiPorts, "navigate" | "LinkComponent" | "renderModelRef">> & {
398
+ openPeek: AgentCatalogOpenPeek | undefined;
399
+ popoverContainer: HTMLElement | null | undefined;
400
+ };
401
+ /**
402
+ * Subscribe to a slice of catalog state. `useSyncExternalStore` because the
403
+ * catalog is an external store and React 18/19 concurrency must not tear it.
404
+ * `select` MUST return a stable reference for unchanged state — every
405
+ * selector in `../selectors` does.
406
+ */
407
+ declare function useAgentCatalogState<T>(select: (state: AgentCatalogState) => T): T;
408
+ /** Every row currently in the catalogue, as one stable array. */
409
+ declare function useAgentCatalogRows(): AgentSummary[];
410
+
411
+ interface UseAgentConsumerReturn {
412
+ tab: AgentTab;
413
+ sortBy: AgentSortOption;
414
+ searchTerm: string;
415
+ includedCats: string[];
416
+ includedTags: string[];
417
+ favFilter: AgentFavFilter;
418
+ archFilter: AgentArchFilter;
419
+ accessFilter: AgentAccessFilter;
420
+ favoritesFirst: boolean;
421
+ listPage: number;
422
+ sharedPage: number;
423
+ /** The whole slot, for the selectors that take a consumer state. */
424
+ state: AgentConsumerState;
425
+ /** True if any filter differs from its default value. */
426
+ hasActiveFilters: boolean;
427
+ /** Tier 2 search — also match against agent prompt content. */
428
+ deepSearch: boolean;
429
+ /** True while a server-side search is in flight. */
430
+ isServerSearching: boolean;
431
+ setSearchTerm: (value: string) => void;
432
+ setDeepSearch: (value: boolean) => void;
433
+ setSortBy: (value: AgentSortOption) => void;
434
+ setTab: (value: AgentTab) => void;
435
+ setFavFilter: (value: AgentFavFilter) => void;
436
+ setArchFilter: (value: AgentArchFilter) => void;
437
+ setAccessFilter: (value: AgentAccessFilter) => void;
438
+ /** Add category to inclusion set; if already present, remove (toggle). */
439
+ toggleCategory: (cat: string) => void;
440
+ /** Add tag to inclusion set; if already present, remove (toggle). */
441
+ toggleTag: (tag: string) => void;
442
+ /**
443
+ * Replace the WHOLE category inclusion set in one write.
444
+ *
445
+ * Prefer this over looping `toggleCategory` whenever more than one value
446
+ * changes. Each `toggleCategory` call computes its next array from the
447
+ * `includedCats` captured in the CURRENT render, so two toggles fired in the
448
+ * same tick both start from the same snapshot and the second one's patch
449
+ * overwrites the first — a "Clear filter" click with three categories active
450
+ * removes only one. One write of the final set cannot drift that way.
451
+ */
452
+ setIncludedCats: (next: string[]) => void;
453
+ /** Replace the WHOLE tag inclusion set in one write. See setIncludedCats. */
454
+ setIncludedTags: (next: string[]) => void;
455
+ toggleFavoritesFirst: () => void;
456
+ loadMoreList: () => void;
457
+ loadMoreShared: () => void;
458
+ resetFilters: () => void;
459
+ }
460
+ declare function useAgentConsumer(consumerId: string, options?: {
461
+ /** Delete the slot on unmount. Default false — persistent consumers keep state. */
462
+ unregisterOnUnmount?: boolean;
463
+ /** Applied only when the consumer is first registered (idempotent). */
464
+ initialTab?: AgentTab;
465
+ }): UseAgentConsumerReturn;
466
+
467
+ interface AgentListTabCounts {
468
+ mine: number;
469
+ shared: number;
470
+ all: number;
471
+ system: number;
472
+ }
473
+ interface AgentListTabsProps {
474
+ consumer: UseAgentConsumerReturn;
475
+ tabCounts: AgentListTabCounts;
476
+ /** Limit the ownership tabs for constrained pickers. */
477
+ visibleTabs?: readonly AgentTab[] | undefined;
478
+ /**
479
+ * Label for the builtin-agent tab. Users see "Public" (that is what a
480
+ * platform agent is to them); ADMIN surfaces pass "System", because there
481
+ * these are the agents they own and maintain.
482
+ */
483
+ systemTabLabel?: string | undefined;
484
+ }
485
+ declare function AgentListTabs({ consumer, tabCounts, systemTabLabel, visibleTabs, }: AgentListTabsProps): react.JSX.Element;
486
+
487
+ interface AgentListCoreOptions {
488
+ consumerId: string;
489
+ onSelect?: (agentId: string) => void;
490
+ navigateTo?: string;
491
+ /** Route-scoped agent id (chat/builder headers). `undefined` = nothing pinned. */
492
+ activeAgentIdOverride?: string | null;
493
+ /**
494
+ * Tab this surface opens on, applied once on first mount. Admin surfaces
495
+ * that manage system agents pass `"system"`. When omitted the normal
496
+ * user heuristic applies (a user with no agents of their own lands on the
497
+ * public/system catalogue).
498
+ */
499
+ initialTab?: AgentTab;
500
+ /**
501
+ * ADMIN reading of the "All" tab: blend system agents into it instead of
502
+ * keeping them to their own tab. See `makeSelectFilteredAgents`.
503
+ */
504
+ includeSystemInAll?: boolean;
505
+ /**
506
+ * 🚨 THE OWNERSHIP TABS THIS CALL SITE MAY REACH — a HARD restriction, not a
507
+ * default.
508
+ *
509
+ * `AgentListTabs` already hides the buttons this list omits, but hiding a
510
+ * button never emptied the list behind it: the active tab lives in the
511
+ * consumer's REMEMBERED state, and `initialTab` is applied exactly once per
512
+ * mount (`defaultTabAppliedRef`). So a person who had been on "Mine" and
513
+ * then moved a control that narrows the picker got the personal catalogue
514
+ * with the tab bar removed — the forbidden list, and no way to see that it
515
+ * was forbidden. That is the defect Arman named on the mandate binding
516
+ * screen's global rung (VISION-RECONCILIATION D2, 2026-08-31: the picker
517
+ * opened on "Mine · 40").
518
+ *
519
+ * Given here, the tab is COERCED into the allowed set on every change of it,
520
+ * not just at mount — so a restriction that arrives later is enforced later.
521
+ */
522
+ visibleTabs?: readonly AgentTab[];
523
+ /** Hide records that are invalid for this call site. */
524
+ excludeAgentIds?: readonly string[];
525
+ /**
526
+ * Show the platform DEFAULT agent for this mandate key at the top of the
527
+ * list, resolved live through the server (never a hardcoded name). Requires
528
+ * the catalog to have been built with a `transport`.
529
+ */
530
+ defaultMandateKey?: string;
531
+ }
532
+ /**
533
+ * How long the hover-preview detail panel stays open after the cursor leaves
534
+ * an agent row (or the panel itself) before it closes. Generous on purpose:
535
+ * the panel renders to the side of the list, so the user needs ample time to
536
+ * travel the cursor across the gap to reach it without it vanishing. Paired
537
+ * with a reserved, non-resizing popover width so the target never moves.
538
+ */
539
+ declare const HOVER_GRACE_MS = 900;
540
+ /**
541
+ * THE RULE, ALONE AND TESTABLE: which tab a restricted picker must land on.
542
+ *
543
+ * Returns `null` when the current tab is already allowed (nothing to do), and
544
+ * otherwise the tab to switch to — `initialTab` when that is itself allowed,
545
+ * else the first allowed tab.
546
+ */
547
+ declare function coerceVisibleTab(current: AgentTab, allowed: readonly AgentTab[], initialTab?: AgentTab): AgentTab | null;
548
+ declare function useAgentListCore({ consumerId, onSelect, navigateTo, activeAgentIdOverride, initialTab, includeSystemInAll, visibleTabs, excludeAgentIds, defaultMandateKey, }: AgentListCoreOptions): {
549
+ agents: AgentSummary[];
550
+ isLoading: boolean;
551
+ activeAgentId: string | null;
552
+ pinnedAgent: AgentSummary | null;
553
+ defaultRow: DefaultRowState | null;
554
+ allCategories: string[];
555
+ allTags: string[];
556
+ consumer: UseAgentConsumerReturn;
557
+ tabCounts: AgentListTabCounts;
558
+ activeFilterCount: number;
559
+ hoveredAgent: AgentSummary | null;
560
+ setHoveredAgent: react.Dispatch<react.SetStateAction<AgentSummary | null>>;
561
+ ensureLoaded: () => void;
562
+ handleSelectAgent: (agent: AgentSummary) => void;
563
+ handleAgentHover: (agent: AgentSummary, panelOpen: boolean) => void;
564
+ handleAgentHoverEnd: (agent: AgentSummary, onClear: () => void) => void;
565
+ handleDetailPanelMouseEnter: () => void;
566
+ handleDetailPanelMouseLeave: (onClear: () => void) => void;
567
+ };
568
+
569
+ interface AgentListDropdownProps {
570
+ onSelect?: (agentId: string) => void;
571
+ navigateTo?: string;
572
+ className?: string;
573
+ label?: string;
574
+ /** Custom trigger element — replaces the default text button. */
575
+ triggerSlot?: React.ReactNode;
576
+ /** Remove the border from the default trigger button. */
577
+ noBorder?: boolean;
578
+ /** Use a compact (h-5) trigger instead of the default h-7. */
579
+ compact?: boolean;
580
+ /** Route-scoped agent id — highlights + pins the current agent in the list. */
581
+ activeAgentId?: string | null;
582
+ /**
583
+ * Which side the desktop popover opens toward. Defaults to Radix's "bottom".
584
+ * Pass "right" when the trigger lives in a narrow vertical rail so the panel
585
+ * opens beside the rail instead of covering it. Ignored on mobile (Drawer).
586
+ */
587
+ contentSide?: "top" | "right" | "bottom" | "left";
588
+ /**
589
+ * Isolate this dropdown's filter/tab state under its own consumer id.
590
+ * Defaults to the shared `agent-list-dropdown` consumer so ordinary chat
591
+ * triggers keep one remembered set of filters across the app.
592
+ */
593
+ consumerId?: string;
594
+ /** Tab to open on. Admin surfaces managing system agents pass `"system"`. */
595
+ initialTab?: AgentTab;
596
+ /** ADMIN variant: blend system agents into the "All" tab. */
597
+ includeSystemInAll?: boolean;
598
+ /** Restrict which ownership tabs are available for domain-constrained pickers. */
599
+ visibleTabs?: readonly AgentTab[];
600
+ /** Label override for the builtin-agent tab. Admin surfaces use "System". */
601
+ systemTabLabel?: string;
602
+ /** Resolve the route used by each named agent door. */
603
+ resolveAgentHref?: (agent: AgentSummary) => string;
604
+ /** Show the active agent above the filtered list. Default true. */
605
+ showPinnedAgent?: boolean;
606
+ /** Hide records that are invalid for this call site. */
607
+ excludeAgentIds?: readonly string[];
608
+ /**
609
+ * Offer the platform DEFAULT agent for this mandate key at the top of the
610
+ * list, named LIVE from the mandate's real Holder. `onSelect` receives
611
+ * `mandate:<key>` for that row — the ref shape every client already speaks.
612
+ */
613
+ defaultMandateKey?: string;
614
+ }
615
+ declare function AgentListDropdown({ onSelect, navigateTo, className, label, triggerSlot, noBorder, compact, activeAgentId: activeAgentIdProp, contentSide, consumerId, initialTab, includeSystemInAll, visibleTabs, systemTabLabel, resolveAgentHref: resolveAgentHrefProp, showPinnedAgent, excludeAgentIds, defaultMandateKey, }: AgentListDropdownProps): react.JSX.Element;
616
+
617
+ interface AgentListInlinePickerProps {
618
+ /** Unique consumer id for filter/tab state (see `useAgentConsumer`). */
619
+ consumerId: string;
620
+ onSelect: (agentId: string) => void;
621
+ activeAgentId?: string | null;
622
+ className?: string;
623
+ /** Auto-focus the search field on mount. Default true. */
624
+ autoFocusSearch?: boolean;
625
+ /** Tab to open on. Admin surfaces that manage system agents pass `"system"`. */
626
+ initialTab?: AgentTab;
627
+ /** ADMIN variant: blend system agents into the "All" tab. */
628
+ includeSystemInAll?: boolean;
629
+ /** Restrict which ownership tabs are available for domain-constrained pickers. */
630
+ visibleTabs?: readonly AgentTab[];
631
+ /** Label override for the builtin-agent tab. Admin surfaces use "System". */
632
+ systemTabLabel?: string;
633
+ /** Resolve the route used by each named agent door. */
634
+ resolveAgentHref?: (agent: AgentSummary) => string;
635
+ /** Show the globally active agent above the filtered list. Default true. */
636
+ showPinnedAgent?: boolean;
637
+ /** Hide records that are invalid for this call site. */
638
+ excludeAgentIds?: readonly string[];
639
+ /** Offer the mandate's live-resolved default agent at the top of the list. */
640
+ defaultMandateKey?: string;
641
+ }
642
+ declare function AgentListInlinePicker({ consumerId, onSelect, activeAgentId, className, autoFocusSearch, initialTab, includeSystemInAll, visibleTabs, systemTabLabel, resolveAgentHref, showPinnedAgent, excludeAgentIds, defaultMandateKey, }: AgentListInlinePickerProps): react.JSX.Element;
643
+
644
+ /**
645
+ * catalog/react/types.ts — VERBATIM port of matrx-frontend
646
+ * `features/agents/components/agent-listings/core/types.ts`.
647
+ */
648
+
649
+ type RightPanel = "detail" | "sort" | "categories" | "tags" | null;
650
+ declare const SORT_OPTIONS: {
651
+ value: AgentSortOption;
652
+ label: string;
653
+ }[];
654
+ declare const PANEL_HEIGHT = "528px";
655
+ /**
656
+ * 🚨 THE PANEL NEVER OUTGROWS THE SPACE IT HAS.
657
+ *
658
+ * The popover reserves a FIXED footprint on purpose (a resizing panel in a
659
+ * narrow rail gets collision-shifted out from under the cursor). But a flat
660
+ * 528px is taller than the room above a trigger sitting mid-page on a laptop,
661
+ * and Radix cannot shift what does not fit either way — so the top of the
662
+ * panel, which is the SEARCH BOX, was rendered off-screen. Measured 2026-09-08
663
+ * on the mandate Holder screen at 1280x900: the popover sat at `top: -76`.
664
+ *
665
+ * Clamping to Radix's own measurement keeps the footprint fixed whenever there
666
+ * IS room and merely shortens the list when there is not — the panel still
667
+ * never resizes while open, because the available height does not change while
668
+ * the popover is open.
669
+ */
670
+ declare const LIST_MAX_HEIGHT = "min(528px, var(--radix-popper-available-height, 528px))";
671
+
672
+ interface AgentListContentProps {
673
+ agents: AgentSummary[];
674
+ isLoading: boolean;
675
+ consumer: UseAgentConsumerReturn;
676
+ activeAgentId: string | null;
677
+ allCategories: string[];
678
+ allTags: string[];
679
+ inputRef: React.RefObject<HTMLInputElement | null>;
680
+ onSelectAgent: (a: AgentSummary) => void;
681
+ /** Per-row href for cmd/ctrl+click. Defaults to `/agents/go/[id]`. */
682
+ resolveAgentHref?: ((agent: AgentSummary) => string) | undefined;
683
+ onReset: () => void;
684
+ activeFilterCount: number;
685
+ isMobile: boolean;
686
+ hoveredAgent: AgentSummary | null;
687
+ onAgentHover: (a: AgentSummary) => void;
688
+ onAgentHoverEnd: (a: AgentSummary) => void;
689
+ onDetailPress: (a: AgentSummary) => void;
690
+ onFilterChipClick: (panel: "sort" | "categories" | "tags") => void;
691
+ rightPanel: RightPanel;
692
+ tabCounts: AgentListTabCounts;
693
+ /** Limit the ownership tabs shown by this picker. */
694
+ visibleTabs?: readonly AgentTab[] | undefined;
695
+ /** Label override for the builtin tab — admin surfaces pass "System". */
696
+ systemTabLabel?: string | undefined;
697
+ /** Resolved current agent — pinned at the top when the list opens. */
698
+ pinnedAgent?: AgentSummary | null | undefined;
699
+ /** The mandate default row, when this picker was given a `defaultMandateKey`. */
700
+ defaultRow?: DefaultRowState | null | undefined;
701
+ /** When true, scroll the list to the pinned row (top). */
702
+ listOpen?: boolean | undefined;
703
+ }
704
+ declare function AgentListContent({ agents, isLoading, consumer, activeAgentId, allCategories, allTags, inputRef, onSelectAgent, resolveAgentHref, onReset, activeFilterCount, isMobile, hoveredAgent, onAgentHover, onAgentHoverEnd, onDetailPress, onFilterChipClick, rightPanel, tabCounts, visibleTabs, systemTabLabel, pinnedAgent, defaultRow, listOpen, }: AgentListContentProps): react.JSX.Element;
705
+
706
+ interface AgentFilterBarProps {
707
+ consumer: UseAgentConsumerReturn;
708
+ allCategories: string[];
709
+ allTags: string[];
710
+ activeFilterCount: number;
711
+ isMobile: boolean;
712
+ rightPanel: RightPanel;
713
+ onFilterChipClick: (panel: "sort" | "categories" | "tags") => void;
714
+ onReset: () => void;
715
+ }
716
+ /**
717
+ * The filter bar is IDENTICAL on every tab, system included. A tab that offers
718
+ * fewer controls than its neighbour is the half-built shape this list exists
719
+ * to prevent — the system tab's category/tag options simply come from the
720
+ * builtin population (see `selectAllSystemAgentCategories`).
721
+ */
722
+ declare function AgentFilterBar({ consumer, allCategories, allTags, activeFilterCount, isMobile, rightPanel, onFilterChipClick, onReset, }: AgentFilterBarProps): react.JSX.Element;
723
+
724
+ interface AgentRowProps {
725
+ agent: AgentSummary;
726
+ isActive: boolean;
727
+ isHovered: boolean;
728
+ isMobile: boolean;
729
+ /** Row href. Defaults to `/agents/go/[id]`. */
730
+ href?: string | undefined;
731
+ onClick: () => void;
732
+ onHover: () => void;
733
+ onHoverEnd: () => void;
734
+ onDetailPress: () => void;
735
+ }
736
+ declare function AgentRow({ agent, isActive, isHovered, isMobile, href, onClick, onHover, onHoverEnd, onDetailPress, }: AgentRowProps): react.JSX.Element;
737
+
738
+ interface AgentDetailCardProps {
739
+ agent: AgentSummary;
740
+ onSelect: () => void;
741
+ }
742
+ declare function AgentDetailCard({ agent, onSelect }: AgentDetailCardProps): react.JSX.Element;
743
+
744
+ interface AgentSortPanelProps {
745
+ consumer: UseAgentConsumerReturn;
746
+ onClose: () => void;
747
+ }
748
+ declare function AgentSortPanel({ consumer, onClose }: AgentSortPanelProps): react.JSX.Element;
749
+
750
+ interface AgentCategoriesPanelProps {
751
+ consumer: UseAgentConsumerReturn;
752
+ allCategories: string[];
753
+ search: string;
754
+ setSearch: (v: string) => void;
755
+ onClose: () => void;
756
+ }
757
+ declare function AgentCategoriesPanel({ consumer, allCategories, search, setSearch, onClose, }: AgentCategoriesPanelProps): react.JSX.Element;
758
+
759
+ interface AgentTagsPanelProps {
760
+ consumer: UseAgentConsumerReturn;
761
+ allTags: string[];
762
+ search: string;
763
+ setSearch: (v: string) => void;
764
+ onClose: () => void;
765
+ }
766
+ declare function AgentTagsPanel({ consumer, allTags, search, setSearch, onClose, }: AgentTagsPanelProps): react.JSX.Element;
767
+
768
+ interface AgentMobileSubViewProps {
769
+ view: "sort" | "categories" | "tags";
770
+ consumer: UseAgentConsumerReturn;
771
+ allCategories: string[];
772
+ allTags: string[];
773
+ catSearch: string;
774
+ setCatSearch: (v: string) => void;
775
+ tagSearch: string;
776
+ setTagSearch: (v: string) => void;
777
+ onBack: () => void;
778
+ }
779
+ declare function AgentMobileSubView({ view, consumer, allCategories, allTags, catSearch, setCatSearch, tagSearch, setTagSearch, onBack, }: AgentMobileSubViewProps): react.JSX.Element;
780
+
781
+ interface FavoriteAgentButtonProps {
782
+ id: string;
783
+ /** "card" = absolute-positioned corner star, "list" = inline icon button */
784
+ variant?: "card" | "list";
785
+ disabled?: boolean;
786
+ }
787
+ declare function FavoriteAgentButton({ id, variant, disabled, }: FavoriteAgentButtonProps): react.JSX.Element;
788
+
789
+ declare const SearchInput: ({ ref, value, onChange, placeholder, }: {
790
+ ref?: Ref<HTMLInputElement>;
791
+ value: string;
792
+ onChange: (v: string) => void;
793
+ placeholder: string;
794
+ }) => react.JSX.Element;
795
+ declare function FilterChip({ icon: Icon, label, active, focused, onClick, }: {
796
+ icon: ComponentType<{
797
+ className?: string;
798
+ }>;
799
+ label: string;
800
+ active: boolean;
801
+ focused?: boolean;
802
+ onClick: () => void;
803
+ }): react.JSX.Element;
804
+ declare function OptionRow({ label, selected, onClick, }: {
805
+ label: string;
806
+ selected: boolean;
807
+ onClick: () => void;
808
+ }): react.JSX.Element;
809
+ declare function CheckRow({ label, checked, onClick, }: {
810
+ label: string;
811
+ checked: boolean;
812
+ onClick: () => void;
813
+ }): react.JSX.Element;
814
+ declare function SidePanelHeader({ title, onClose, }: {
815
+ title: string;
816
+ onClose: () => void;
817
+ }): react.JSX.Element;
818
+
819
+ export { type AgentCatalogLinkComponent, AgentCatalogProvider, type AgentCatalogProviderProps, type AgentCatalogRenderModelRef, type AgentCatalogUiPorts, AgentCategoriesPanel, type AgentCategoriesPanelProps, AgentDetailCard, type AgentDetailCardProps, AgentFilterBar, type AgentFilterBarProps, AgentListContent, type AgentListContentProps, type AgentListCoreOptions, AgentListDropdown, type AgentListDropdownProps, AgentListInlinePicker, type AgentListInlinePickerProps, type AgentListTabCounts, AgentListTabs, AgentMobileSubView, type AgentMobileSubViewProps, AgentRow, type AgentRowProps, AgentSortPanel, type AgentSortPanelProps, AgentTagsPanel, type AgentTagsPanelProps, CheckRow, FavoriteAgentButton, FilterChip, HOVER_GRACE_MS, LIST_MAX_HEIGHT, OptionRow, PANEL_HEIGHT, type RightPanel, SORT_OPTIONS, SearchInput, SidePanelHeader, type UseAgentConsumerReturn, coerceVisibleTab, useAgentCatalog, useAgentCatalogRows, useAgentCatalogState, useAgentCatalogUiPorts, useAgentConsumer, useAgentListCore };