@ai-matrx/agents 0.7.1 → 0.9.0

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,643 @@
1
+ /**
2
+ * `@ai-matrx/agents/catalog` — the row shape and the per-consumer view state.
3
+ *
4
+ * `AgentSummary` is the 19-column row `agx_get_list_full()` returns, camelCased.
5
+ * It is deliberately NOT the editable agent record: dirty tracking, undo,
6
+ * messages, tools and `_fetchStatus` stay in whichever host owns the editor.
7
+ * A list row is a list row.
8
+ *
9
+ * The view-state types are a VERBATIM port of matrx-frontend
10
+ * `features/agents/redux/agent-consumers/slice.ts` — only the coupling seam
11
+ * inverts (Redux reducers become store actions in `./store`).
12
+ */
13
+ /**
14
+ * A branded agent id. Every id that reaches `onSelect` is one of these:
15
+ * either a `agent.definition` UUID, or the `mandate:<key>` reference a
16
+ * default row carries (byte-identical to the ref shape matrx-extend
17
+ * `src/lib/mandates.ts` and matrx-local `desktop/src/lib/mandates.ts`
18
+ * already hand back to their hosts).
19
+ *
20
+ * 🚨 The brand is a STRING LITERAL, never `unique symbol`. This package emits
21
+ * `./catalog` and `./catalog/react` as two separate bundles, so each `.d.ts`
22
+ * carries its own copy of these declarations. A `unique symbol` brand is
23
+ * NOMINAL: two copies of it are unrelated types, so `createAgentCatalog()`
24
+ * from `./catalog` was not assignable to `<AgentCatalogProvider catalog=…>`
25
+ * from `./catalog/react` — the exact two-import wiring the README, the
26
+ * CHANGELOG and every consumer use. A literal brand is structural, so the two
27
+ * copies unify, while a bare `string` still cannot be passed where an
28
+ * `AgentId` is required (which is the whole point of branding). Any future
29
+ * brand in this package follows the same rule.
30
+ */
31
+ type AgentId = string & {
32
+ readonly __agentId: "ai-matrx.agent-id";
33
+ };
34
+ /** Brand a raw string as an `AgentId`. */
35
+ declare function asAgentId(value: string): AgentId;
36
+ /** The `mandate:<key>` ref shape every client already speaks. */
37
+ declare function mandateAgentId(mandateKey: string): AgentId;
38
+ /** True when an id is a mandate default row rather than a stored agent. */
39
+ declare function isMandateAgentId(id: string): boolean;
40
+ /** `agent_type` verbatim. Only `builtin` changes how a row is grouped. */
41
+ type AgentCatalogAgentType = "user" | "builtin";
42
+ /**
43
+ * `access_level` verbatim from `agx_get_list_full`. Widened over the raw
44
+ * string because it is a DB-owned vocabulary: an unknown level renders as
45
+ * itself rather than being coerced into a wrong one.
46
+ */
47
+ type AgentAccessLevel = "owner" | "admin" | "editor" | "viewer" | "system" | (string & {});
48
+ /**
49
+ * Present on a catalog row ONLY when that agent is an **Orchestra** — a
50
+ * conductor that delegates to member agents at run time. Choosing one for a
51
+ * step, a chat or a workflow node runs the whole ensemble, so a person has to
52
+ * be able to SEE that before choosing, not discover it from the run.
53
+ *
54
+ * The DB decides. `agx_get_list_full` / `agx_get_list` / `agx_search` build
55
+ * this from `platform.associations` (the conductor self-edge plus its member
56
+ * edges) in one `agx_orchestra_badges()` join — never a second fetch, and
57
+ * never a per-row read. `null` for every ordinary agent.
58
+ *
59
+ * History: the badge lived only in the Python `GET /agents` route, so every
60
+ * client lost it when the pickers moved to the RPC. It is a ROW FIELD now, in
61
+ * the one read every client shares.
62
+ */
63
+ interface OrchestraBadge {
64
+ /** How the ensemble runs: `supervisor` | `sequential` | `parallel` | `dag`, or a future mode verbatim. */
65
+ mode: string;
66
+ /** The composition's one-line description, when its author wrote one. */
67
+ tagline: string | null;
68
+ /**
69
+ * The per-composition delegation-depth budget AS DECLARED, or `null` when
70
+ * the composition declares none. Deliberately NOT defaulted here: the
71
+ * platform's fallback ceiling is enforced by the server that runs the
72
+ * ensemble, and a badge that invented a number would be reporting a promise
73
+ * nobody made.
74
+ */
75
+ depthBudget: number | null;
76
+ /** Member edges. From the ROW count, so an unlabelled ensemble still counts. */
77
+ memberCount: number;
78
+ /** Only REAL role titles — an ensemble with unlabelled edges yields `[]`. */
79
+ memberTitles: string[];
80
+ }
81
+ /**
82
+ * One `agx_get_list_full()` row, camelCased. Nineteen columns, no more:
83
+ * anything richer needs a different read and is a different type.
84
+ */
85
+ interface AgentSummary {
86
+ id: AgentId;
87
+ name: string | null;
88
+ description: string | null;
89
+ category: string | null;
90
+ tags: string[];
91
+ agentType: AgentCatalogAgentType;
92
+ modelId: string | null;
93
+ isActive: boolean;
94
+ isArchived: boolean;
95
+ isFavorite: boolean;
96
+ createdBy: string | null;
97
+ organizationId: string | null;
98
+ taskId: string | null;
99
+ sourceAgentId: string | null;
100
+ createdAt: string | null;
101
+ updatedAt: string | null;
102
+ isOwner: boolean | null;
103
+ accessLevel: AgentAccessLevel | null;
104
+ sharedByEmail: string | null;
105
+ /**
106
+ * The Orchestra badge, or `null` for an ordinary agent. Strict: every row
107
+ * carries the key, so a surface reads `agent.orchestra` and never has to ask
108
+ * whether the column existed.
109
+ */
110
+ orchestra: OrchestraBadge | null;
111
+ /**
112
+ * Set only on a mandate default row — the key it resolved through, so a
113
+ * host can tell "the default" from a stored agent without parsing the id.
114
+ */
115
+ mandateKey?: string;
116
+ }
117
+ type AgentSortOption = "updated-desc" | "created-desc" | "name-asc" | "name-desc" | "category-asc";
118
+ /**
119
+ * The sort choices a picker offers, in order. PURE DATA, so it lives in the
120
+ * pure entry: a server-reachable manifest reads it at module scope, and
121
+ * importing it from the client-stamped `./catalog/react` bundle dragged React
122
+ * into a server graph for the sake of five string pairs. `./catalog/react`
123
+ * re-exports it unchanged, so no consumer has to move.
124
+ *
125
+ * (Written "client-stamped", never with the literal directive: this comment is
126
+ * emitted into `dist/catalog/index.d.ts`, and the tarball canary rightly
127
+ * refuses that directive anywhere in a PURE entry.)
128
+ */
129
+ declare const SORT_OPTIONS: {
130
+ value: AgentSortOption;
131
+ label: string;
132
+ }[];
133
+ /** Which ownership tab is active in the agent list. */
134
+ type AgentTab = "mine" | "shared" | "all" | "system";
135
+ /** Favorite filter. */
136
+ type AgentFavFilter = "all" | "yes" | "no";
137
+ /** Archive filter. */
138
+ type AgentArchFilter = "active" | "archived" | "both";
139
+ /**
140
+ * Access level filter.
141
+ * 'any' = no restriction (default).
142
+ * 'owned' = only agents the user owns (isOwner = true).
143
+ * 'shared' = only agents shared with the user (isOwner = false).
144
+ * 'editable' = owner + admin + editor.
145
+ */
146
+ type AgentAccessFilter = "any" | "owned" | "shared" | "editable";
147
+ /** Sentinel meaning "include uncategorized / untagged" items. */
148
+ declare const AGENT_NONE_SENTINEL = "__none__";
149
+ interface AgentConsumerState {
150
+ tab: AgentTab;
151
+ sortBy: AgentSortOption;
152
+ searchTerm: string;
153
+ /** INCLUSION model: empty = show all; non-empty = only matching. */
154
+ includedCats: string[];
155
+ /** INCLUSION model: empty = show all; non-empty = only matching. */
156
+ includedTags: string[];
157
+ favFilter: AgentFavFilter;
158
+ archFilter: AgentArchFilter;
159
+ accessFilter: AgentAccessFilter;
160
+ favoritesFirst: boolean;
161
+ /** Current page for owned-agent list items (after the card section). */
162
+ listPage: number;
163
+ /** Current page for shared-agent list items. */
164
+ sharedPage: number;
165
+ /**
166
+ * Ids returned by the last server-side search (`agx_search`), in server rank
167
+ * order. Additive: an agent in this list survives the search filter even
168
+ * when the local scorer gives it 0.
169
+ *
170
+ * That is load-bearing for tier 2. A deep search matches an agent's prompt
171
+ * content, which the client never loads — so the local scorer cannot see it.
172
+ * Without this list the server would return prompt matches and the UI would
173
+ * immediately filter them back out.
174
+ *
175
+ * Server-only matches sort BELOW every locally-scored match, in server rank
176
+ * order, so obvious matches always come first.
177
+ */
178
+ serverMatchedIds: string[];
179
+ /** True while a server search is in flight — drives the search spinner. */
180
+ isServerSearching: boolean;
181
+ /** Tier 2: also search agent prompt content. Opt-in, per consumer. */
182
+ deepSearch: boolean;
183
+ }
184
+ declare const DEFAULT_AGENT_CONSUMER_STATE: AgentConsumerState;
185
+ /** The subset of consumer state a caller may patch (paging is derived). */
186
+ type AgentConsumerPatch = Partial<Omit<AgentConsumerState, "listPage" | "sharedPage">>;
187
+ /**
188
+ * Thrown by `createAgentCatalog` when a REQUIRED port is missing or an
189
+ * optional feature was asked for without the port it needs. Never a warning,
190
+ * never a degraded catalog: a picker that cannot read is not a picker.
191
+ */
192
+ declare class AgentCatalogConfigError extends Error {
193
+ readonly name = "AgentCatalogConfigError";
194
+ /** Machine code, for a host that routes config failures. */
195
+ readonly code: string;
196
+ /** What the host must do, in a sentence a person can act on. */
197
+ readonly remedy: string;
198
+ constructor(args: {
199
+ code: string;
200
+ message: string;
201
+ remedy: string;
202
+ });
203
+ }
204
+
205
+ /**
206
+ * `@ai-matrx/agents/catalog` — THE PORTS.
207
+ *
208
+ * Two are required (`client`, `identity`); every other one ships a working
209
+ * default with a DOCUMENTED degradation, per THE ALL-INCLUSIVE LAW. A host
210
+ * injects identity and a Supabase client and nothing else; the picker's only
211
+ * contract back to the host is `onSelect(agentId)`.
212
+ *
213
+ * React appears nowhere in this file — it is import-inert and legal in any
214
+ * graph, server components included.
215
+ */
216
+
217
+ /** A PostgREST error, structurally. */
218
+ interface PgErrorLike {
219
+ message: string;
220
+ code?: string;
221
+ details?: string | null;
222
+ hint?: string | null;
223
+ }
224
+ /** What every supabase-js call resolves to, structurally. */
225
+ interface PgResultLike {
226
+ data: unknown;
227
+ error: PgErrorLike | null;
228
+ count?: number | null;
229
+ }
230
+ /**
231
+ * The thenable builder supabase-js returns from `.rpc()`. `range` is what
232
+ * makes a COMPLETE list read possible (`readAllRows`); `order` is what makes
233
+ * that paging stable. Both are the real builder's own methods — this is a
234
+ * structural subset, never a re-implementation.
235
+ */
236
+ interface AgentCatalogRpcCall extends PromiseLike<PgResultLike> {
237
+ range(from: number, to: number): PromiseLike<PgResultLike>;
238
+ order(column: string, options?: {
239
+ ascending?: boolean;
240
+ }): AgentCatalogRpcCall;
241
+ }
242
+ /** The one write this package performs: `agent.definition.is_favorite`. */
243
+ interface AgentCatalogTableQuery {
244
+ update(patch: Record<string, unknown>): {
245
+ eq(column: string, value: string): PromiseLike<{
246
+ data?: unknown;
247
+ error: PgErrorLike | null;
248
+ }>;
249
+ };
250
+ }
251
+ /**
252
+ * REQUIRED. A structural subset of `SupabaseClient` — anything that can answer
253
+ * `agx_get_list_full`, `agx_search`, `agx_resolve_agent_address` and write one
254
+ * column on `agent.definition`. A real supabase-js client satisfies it as-is.
255
+ *
256
+ * Absent → `createAgentCatalog` throws `AgentCatalogConfigError`. There is no
257
+ * degraded mode: the package IS the catalogue read.
258
+ */
259
+ interface AgentCatalogClient {
260
+ rpc(fn: string, args?: Record<string, unknown>, options?: {
261
+ count?: "exact" | "planned" | "estimated";
262
+ }): AgentCatalogRpcCall;
263
+ schema(name: string): {
264
+ from(table: string): AgentCatalogTableQuery;
265
+ };
266
+ }
267
+ /**
268
+ * REQUIRED. Who is asking. Needed for the "zero owned agents → open on the
269
+ * public tab" heuristic and for the favorite write.
270
+ *
271
+ * `requireUserId` THROWS when there is no session — never a silent anonymous
272
+ * read. The catalog catches that throw in exactly ONE place (the tab-default
273
+ * heuristic, where a signed-out visitor legitimately lands on the public
274
+ * catalogue) and reports it to the `errorSink` the first time; every other
275
+ * caller lets it propagate.
276
+ */
277
+ interface AgentCatalogIdentity {
278
+ requireUserId(): string;
279
+ }
280
+ /**
281
+ * Every degraded path, every failed read, every drift detection reports here.
282
+ * DEFAULT: a tagged `console.error` that announces ONCE that no sink is bound
283
+ * and names the remedy.
284
+ */
285
+ type AgentCatalogErrorSink = (event: {
286
+ code: string;
287
+ message: string;
288
+ context?: object;
289
+ }) => void;
290
+ /**
291
+ * The drift scream's second channel. DEFAULT: none — and that is safe
292
+ * ONLY because the in-picker persistent banner is the primary scream and
293
+ * always renders. A drift is never console-only.
294
+ */
295
+ type AgentCatalogNotifier = (event: {
296
+ level: "warning" | "error";
297
+ title: string;
298
+ message: string;
299
+ }) => void;
300
+ /**
301
+ * First-paint cache for resolved default rows. DEFAULT: `localStorage` when
302
+ * present, else an in-memory map (so SSR and a Chrome service worker both
303
+ * work). Absent storage degrades to "no first paint of the default row until
304
+ * the mandate resolves" — never a wrong name on screen.
305
+ */
306
+ interface AgentCatalogStorage {
307
+ getItem(key: string): string | null;
308
+ setItem(key: string, value: string): void;
309
+ removeItem(key: string): void;
310
+ }
311
+ /**
312
+ * The SAME seam for a platform whose only key-value store is asynchronous.
313
+ *
314
+ * 🚨 WHY THIS EXISTS (0.9.0). React Native has no `localStorage`; every Expo
315
+ * app's store (`@react-native-async-storage/async-storage`, `expo-secure-store`,
316
+ * MMKV's async face) answers with a promise. Before this, a native host had
317
+ * exactly two options — hand the package a storage that lies by returning
318
+ * `null` synchronously, or lose the default row's first paint entirely. Both
319
+ * are the silent degradation this package exists to refuse.
320
+ *
321
+ * The shape is `AsyncStorage`'s own, so an Expo host passes AsyncStorage
322
+ * directly with no adapter. Every method may answer synchronously OR with a
323
+ * promise, which is what makes `AgentCatalogStorage` a subtype of this one:
324
+ * the WEB PATH IS UNCHANGED — a sync storage still resolves in the same
325
+ * microtask, and `readCachedDefaultRow`/`writeCachedDefaultRow` keep their
326
+ * synchronous signatures for every existing caller.
327
+ */
328
+ interface AgentCatalogAsyncStorage {
329
+ getItem(key: string): string | null | Promise<string | null>;
330
+ setItem(key: string, value: string): void | Promise<void>;
331
+ removeItem(key: string): void | Promise<void>;
332
+ }
333
+ /** Either storage shape. What `AgentCatalogConfig.storage` accepts. */
334
+ type AgentCatalogStorageLike = AgentCatalogStorage | AgentCatalogAsyncStorage;
335
+ /** Every user-visible string the picker renders, overridable per host. */
336
+ interface AgentCatalogLabels {
337
+ /** User-facing label for the `system` ownership tab. */
338
+ publicTab: string;
339
+ /**
340
+ * Badge label on a builtin row. Default `"system"` — the string
341
+ * `AgentRow` actually rendered in matrx-frontend. (The frontend also
342
+ * declared `AGENT_PUBLIC_BADGE_LABEL = "Public"` for this badge and NOTHING
343
+ * ever read it — a constant that named the badge without being the badge.
344
+ * Recorded in the CHANGELOG and dropped rather than ported.)
345
+ */
346
+ systemBadge: string;
347
+ searchPlaceholder: string;
348
+ currentAgentHeading: string;
349
+ emptyDefault: string;
350
+ emptyShared: string;
351
+ emptySystem: string;
352
+ loading: string;
353
+ triggerFallback: string;
354
+ triggerResolving: string;
355
+ triggerUnnameable: string;
356
+ hoverHint: string;
357
+ }
358
+ declare const DEFAULT_AGENT_CATALOG_LABELS: AgentCatalogLabels;
359
+ interface AgentCatalogConfig {
360
+ /** REQUIRED — the Supabase client. */
361
+ client: AgentCatalogClient;
362
+ /** REQUIRED — who is asking. */
363
+ identity: AgentCatalogIdentity;
364
+ /**
365
+ * The catalog's registry key on `globalThis`. Two `createAgentCatalog`
366
+ * calls with the same id are the same catalog (and the second one screams
367
+ * through the errorSink before replacing the first). Default `"default"`.
368
+ */
369
+ catalogId?: string;
370
+ /** OPTIONAL — see `AgentCatalogErrorSink`. */
371
+ errorSink?: AgentCatalogErrorSink;
372
+ /** OPTIONAL — see `AgentCatalogNotifier`. */
373
+ notifier?: AgentCatalogNotifier;
374
+ /**
375
+ * OPTIONAL — see `AgentCatalogStorage` and `AgentCatalogAsyncStorage`. A
376
+ * synchronous store (the web `localStorage` default) and an asynchronous
377
+ * one (React Native's `AsyncStorage`) are both accepted verbatim.
378
+ */
379
+ storage?: AgentCatalogStorageLike;
380
+ /**
381
+ * OPTIONAL — the package's own `MatrxTransport` (`createMatrxTransport`
382
+ * from `@ai-matrx/agents/matrx`). REQUIRED the moment any picker instance
383
+ * passes a `defaultMandateKey`: THE PLATFORM RULE D-R1 says clients never
384
+ * walk the mandate ladder, so the default row can only be resolved through
385
+ * the aidream door `GET /mandates/{mandate_key}/resolution`. A
386
+ * `defaultMandateKey` with no transport throws `AgentCatalogConfigError`.
387
+ */
388
+ transport?: AgentCatalogTransport;
389
+ /** OPTIONAL — label overrides. */
390
+ labels?: Partial<AgentCatalogLabels>;
391
+ }
392
+ /**
393
+ * The transport seam, structurally identical to `MatrxTransport` from
394
+ * `@ai-matrx/agents/matrx` (declared structurally so `./catalog` never
395
+ * imports the transport module and stays import-inert).
396
+ */
397
+ interface AgentCatalogTransport {
398
+ fetch(path: string, init: {
399
+ method: "GET" | "POST";
400
+ headers: Record<string, string>;
401
+ body?: string;
402
+ signal?: AbortSignal;
403
+ }): Promise<Response>;
404
+ }
405
+ /**
406
+ * Where a row's href goes when someone cmd-clicks it, and where `navigateTo`
407
+ * lands. DEFAULT: `window.location.assign` (so cmd-click and ordinary
408
+ * navigation both work with no host wiring at all).
409
+ */
410
+ type AgentCatalogNavigate = (href: string) => void;
411
+ /** Resolve a per-row href. DEFAULT: `/agents/go/<id>` — the always-valid door. */
412
+ type AgentCatalogResolveHref = (agent: AgentSummary) => string;
413
+ /**
414
+ * The sneak-peek affordance. Absent → the affordance is HIDDEN, never a dead
415
+ * button (nothing fails silently, and nothing looks alive when it is not).
416
+ */
417
+ type AgentCatalogOpenPeek = (agent: AgentSummary) => void;
418
+
419
+ /**
420
+ * catalog/default-row-types.ts — @ai-matrx/agents/catalog
421
+ *
422
+ * Split out of `default-row.ts` so `global-state.ts` can name the cached
423
+ * shape without importing the resolver (and its transport work) — the same
424
+ * split-out reflex C8 asks for, at module scale.
425
+ */
426
+
427
+ /** The wire shape of `GET /mandates/{mandate_key}/resolution`, narrowed. */
428
+ interface MandateResolutionVerdict {
429
+ mandateKey: string;
430
+ holderType: string;
431
+ /** The executable id. `null` for a workflow Holder — a picker cannot run one. */
432
+ agentId: string | null;
433
+ isVersion: boolean;
434
+ /** Always the `agent.definition` id, even when `agentId` is a version. */
435
+ definitionAgentId: string | null;
436
+ /** Which precedence layer answered. Shown so a person can see WHY. */
437
+ provenance: string;
438
+ }
439
+ /** A resolved default row, cached for first paint and compared for drift. */
440
+ interface ResolvedDefaultRow {
441
+ mandateKey: string;
442
+ /** The `agent.definition` id the mandate resolved to. */
443
+ holderId: string;
444
+ /** The holder's REAL name, read from the catalogue — never hardcoded. */
445
+ holderName: string;
446
+ holderDescription: string | null;
447
+ provenance: string;
448
+ /** Epoch ms of this resolution. */
449
+ at: number;
450
+ }
451
+ /** What the picker renders and what it screams, together. */
452
+ interface DefaultRowState {
453
+ mandateKey: string;
454
+ /** The row to render at the top of the list. `null` until resolved. */
455
+ row: AgentSummary | null;
456
+ /** The last live resolution, or the cached one before the live answer lands. */
457
+ resolved: ResolvedDefaultRow | null;
458
+ /** True while the resolution is in flight. */
459
+ loading: boolean;
460
+ /**
461
+ * 🚨 THE DRIFT SCREAM. Set when the cached first-paint row and the LIVE
462
+ * resolution disagree on holder id or holder name. Rendered as a persistent
463
+ * in-picker banner AND sent to the `notifier` port — never console-only.
464
+ */
465
+ drift: string | null;
466
+ /** Set when the mandate could not be resolved at all. Loud, with a remedy. */
467
+ error: string | null;
468
+ }
469
+
470
+ /**
471
+ * catalog/schema.ts — @ai-matrx/agents/catalog
472
+ *
473
+ * THE DEMANDED SCHEMA PROBE (the `@ai-matrx/associations` `assertDemandedSchema`
474
+ * precedent). It proves that the database a host pointed this catalog at can
475
+ * actually answer the three functions the picker demands.
476
+ *
477
+ * 🚨 IT MUST BE ABLE TO FAIL. A probe whose green result is unconditional
478
+ * proves nothing, so `selfTest: true` also probes a fabricated function name
479
+ * and REQUIRES it to come back missing. `catalog/__tests__/schema.test.ts`
480
+ * runs the whole probe against a client whose `rpc` answers PostgreSQL 42883
481
+ * (`undefined_function`, which PostgREST surfaces as PGRST202) and asserts the
482
+ * loud error.
483
+ */
484
+
485
+ interface AgentCatalogSchemaReport {
486
+ ok: boolean;
487
+ /** Demanded functions the database cannot answer. */
488
+ missing: string[];
489
+ /** Functions the probe could not reach (transport/unknown failure). */
490
+ unreachable: {
491
+ fn: string;
492
+ error: unknown;
493
+ }[];
494
+ /** Functions that answered (success or any non-missing refusal). */
495
+ answered: string[];
496
+ /** True when `agent.definition.is_favorite` is writable by this caller. */
497
+ favoriteWritable: boolean | null;
498
+ /**
499
+ * Whether `agx_get_list_full` carries the `orchestra` badge column (added to
500
+ * the platform 2026-09-08).
501
+ *
502
+ * NOT a violation when absent — the picker degrades to no conductor marker,
503
+ * which is honest — but it is never SILENT either: a `false` here is the one
504
+ * signal that tells a host "this database predates the badge" instead of
505
+ * leaving someone to wonder why their Orchestra looks like a plain agent.
506
+ * `null` means the probe could not tell (the caller can see no agents at
507
+ * all), never "fine".
508
+ */
509
+ orchestraColumn: boolean | null;
510
+ }
511
+ interface AssertAgentCatalogSchemaOptions {
512
+ /**
513
+ * Also probe a fabricated function name and REQUIRE it to come back
514
+ * missing — proves this probe can fail.
515
+ */
516
+ selfTest?: boolean;
517
+ /** Return the report instead of throwing. The self-test failure ALWAYS throws. */
518
+ throwOnViolation?: boolean;
519
+ /**
520
+ * Also probe the ONE write (`agent.definition.is_favorite`) against an
521
+ * impossible id, so a 42501/permission refusal is seen at boot rather than
522
+ * on a user's first click. Default: on.
523
+ */
524
+ probeWrite?: boolean;
525
+ }
526
+ /**
527
+ * Probe every demanded function. Throws an `Error` naming each missing one
528
+ * (unless `throwOnViolation: false`), and ALWAYS throws when the probe itself
529
+ * cannot be trusted (unreachable database, failed self-test).
530
+ */
531
+ declare function assertAgentCatalogSchema(client: AgentCatalogClient, options?: AssertAgentCatalogSchemaOptions): Promise<AgentCatalogSchemaReport>;
532
+
533
+ /**
534
+ * catalog/store.ts — @ai-matrx/agents/catalog
535
+ *
536
+ * `createAgentCatalog(config)` — the headless kernel. Everything the picker
537
+ * knows lives here: the row registry, the complete-list read with its
538
+ * session-shared in-flight dedupe and freshness window, the tier-2 server
539
+ * search, the per-consumer view state, the ONE write, and the mandate default
540
+ * row with its drift screamer.
541
+ *
542
+ * The host injects a Supabase client and who the user is. Nothing else.
543
+ *
544
+ * The consumer reducers below are a VERBATIM port of matrx-frontend
545
+ * `features/agents/redux/agent-consumers/slice.ts`; only the seam inverts
546
+ * (a Redux reducer becomes a store method, and Immer's draft mutation becomes
547
+ * an explicit copy so the store can publish a new reference).
548
+ */
549
+
550
+ type AgentCatalogStatus = "idle" | "loading" | "succeeded" | "failed";
551
+ interface AgentCatalogState {
552
+ /** Every row, one stable array reference per change (memoization depends on it). */
553
+ rows: AgentSummary[];
554
+ byId: Record<string, AgentSummary>;
555
+ status: AgentCatalogStatus;
556
+ error: string | null;
557
+ consumers: Record<string, AgentConsumerState>;
558
+ /** Keyed by mandate key. */
559
+ defaultRows: Record<string, DefaultRowState>;
560
+ }
561
+ interface AgentCatalog {
562
+ readonly catalogId: string;
563
+ readonly labels: AgentCatalogLabels;
564
+ readonly errorSink: AgentCatalogErrorSink;
565
+ readonly notifier: AgentCatalogNotifier | undefined;
566
+ /** True when this catalog was given a transport and can resolve mandates. */
567
+ readonly canResolveMandates: boolean;
568
+ getState(): AgentCatalogState;
569
+ subscribe(listener: () => void): () => void;
570
+ getAgent(agentId: string): AgentSummary | undefined;
571
+ /**
572
+ * The signed-in user id, or `null` when there is no session. The ONE place
573
+ * `identity.requireUserId()`'s throw is caught — a signed-out visitor
574
+ * legitimately lands on the public catalogue — and it is reported to the
575
+ * errorSink the first time so it is never silent.
576
+ */
577
+ getUserIdOrNull(): string | null;
578
+ /** Load the catalogue if it is not fresh. Safe to call on every mount. */
579
+ ensureLoaded(options?: {
580
+ force?: boolean;
581
+ }): Promise<void>;
582
+ /** True when the last load is inside the 15-minute TTL. */
583
+ isFresh(): boolean;
584
+ /** True when the last load is older than 4 hours (tab-restore threshold). */
585
+ isStale(): boolean;
586
+ getConsumer(consumerId: string): AgentConsumerState;
587
+ registerConsumer(consumerId: string, initial?: AgentConsumerPatch): void;
588
+ unregisterConsumer(consumerId: string): void;
589
+ setConsumerFilter(consumerId: string, patch: AgentConsumerPatch): void;
590
+ setConsumerPage(consumerId: string, which: "list" | "shared", page: number): void;
591
+ setConsumerServerSearch(consumerId: string, args: {
592
+ matchedIds?: string[];
593
+ isSearching?: boolean;
594
+ }): void;
595
+ resetConsumerFilters(consumerId: string): void;
596
+ /** Tier-2 search. Purely additive; merges rows into the registry. */
597
+ searchServer(query: string, deep?: boolean): Promise<string[]>;
598
+ /** THE ONE WRITE. Optimistic, rolled back on failure, loud either way. */
599
+ setFavorite(agentId: string, isFavorite: boolean): Promise<void>;
600
+ /** Resolve (once) the default row for a mandate key. Idempotent. */
601
+ ensureDefaultRow(mandateKey: string): void;
602
+ getDefaultRow(mandateKey: string): DefaultRowState | undefined;
603
+ /** A person acknowledged the drift banner. The notifier already fired. */
604
+ dismissDefaultRowDrift(mandateKey: string): void;
605
+ assertSchema(options?: AssertAgentCatalogSchemaOptions): Promise<AgentCatalogSchemaReport>;
606
+ }
607
+ declare function createAgentCatalog(config: AgentCatalogConfig): AgentCatalog;
608
+ /**
609
+ * The catalog registered under `catalogId`, across loader graphs. Returns
610
+ * `undefined` when none has been created yet — never a silent stub.
611
+ */
612
+ declare function getRegisteredAgentCatalog(catalogId?: string): AgentCatalog | undefined;
613
+
614
+ /**
615
+ * catalog/orchestra.ts — @ai-matrx/agents/catalog
616
+ *
617
+ * Creator words for an Orchestra badge. A VERBATIM port of the helpers the
618
+ * Workflow Studio's hand-rolled picker carried (`apps/workflow-studio/src/
619
+ * hooks/use-agents.ts` before `c0f958b43`), lifted here so every client says
620
+ * the same sentence about the same ensemble.
621
+ *
622
+ * Pure — no React, no DOM. The row shape is `OrchestraBadge` in `./types`.
623
+ */
624
+
625
+ declare function orchestraModeLabel(mode: string): string;
626
+ /** Human label for a badge: "Orchestra · supervisor · 3 members" (singular-safe). */
627
+ declare function orchestraLabel(badge: OrchestraBadge): string;
628
+ /**
629
+ * The member-call ceiling in Creator language ("Team members can call helpers
630
+ * up to 2 levels deep"), or `null` when the composition declared none. A badge
631
+ * never invents the platform default: the server that runs the ensemble owns
632
+ * that number, and printing a promise nobody made is worse than printing
633
+ * nothing.
634
+ */
635
+ declare function orchestraDepthLine(badge: OrchestraBadge): string | null;
636
+ /**
637
+ * One visible line naming who the Orchestra delegates to, collapsing past
638
+ * `limit` into "+N more". `null` when no member carries a real role title —
639
+ * "Member, Member, Member" is noise that reads like data.
640
+ */
641
+ declare function orchestraDelegatesLine(badge: OrchestraBadge, limit?: number): string | null;
642
+
643
+ export { type AgentSummary as A, type AgentCatalogStatus as B, type AgentCatalogTableQuery as C, type AgentConsumerPatch as D, type AgentFavFilter as E, type AgentId as F, type AssertAgentCatalogSchemaOptions as G, DEFAULT_AGENT_CATALOG_LABELS as H, DEFAULT_AGENT_CONSUMER_STATE as I, type DefaultRowState as J, type PgResultLike as K, asAgentId as L, type MandateResolutionVerdict as M, assertAgentCatalogSchema as N, type OrchestraBadge as O, type PgErrorLike as P, createAgentCatalog as Q, type ResolvedDefaultRow as R, SORT_OPTIONS as S, getRegisteredAgentCatalog as T, isMandateAgentId as U, mandateAgentId as V, orchestraDelegatesLine as W, orchestraDepthLine as X, orchestraLabel as Y, orchestraModeLabel as Z, type AgentCatalogClient as a, type AgentCatalogTransport as b, type AgentCatalogStorageLike as c, type AgentCatalogErrorSink as d, type AgentCatalogStorage as e, type AgentTab as f, type AgentCatalogLabels as g, type AgentConsumerState as h, type AgentSortOption as i, AGENT_NONE_SENTINEL as j, type AgentAccessFilter as k, type AgentAccessLevel as l, type AgentArchFilter as m, type AgentCatalog as n, type AgentCatalogAgentType as o, type AgentCatalogAsyncStorage as p, type AgentCatalogConfig as q, AgentCatalogConfigError as r, type AgentCatalogIdentity as s, type AgentCatalogNavigate as t, type AgentCatalogNotifier as u, type AgentCatalogOpenPeek as v, type AgentCatalogResolveHref as w, type AgentCatalogRpcCall as x, type AgentCatalogSchemaReport as y, type AgentCatalogState as z };