@adapttable/ai-react 0.2.4 → 0.2.6

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.
package/dist/index.cjs CHANGED
@@ -4,7 +4,6 @@ let _adapttable_ai = require("@adapttable/ai");
4
4
  let _adapttable_react_adapter = require("@adapttable/react/adapter");
5
5
  let react = require("react");
6
6
  let _adapttable_ai_context = require("@adapttable/ai/context");
7
- let _adapttable_core = require("@adapttable/core");
8
7
  let react_dom = require("react-dom");
9
8
  let react_jsx_runtime = require("react/jsx-runtime");
10
9
  let _adapttable_ai_voice = require("@adapttable/ai/voice");
@@ -132,640 +131,17 @@ function inputsOf(options, approval, alwaysAllow, viewState, progress) {
132
131
  * `@adapttable/ai` stays React-free. This package mounts a provider that
133
132
  * observes the live table and publishes a versioned manifest.
134
133
  */
135
- const PAGE_ONLY_SOURCE = {
136
- fullDataset: false,
137
- grouping: false,
138
- selectAcrossPages: false,
139
- exportScope: "page",
140
- totalCount: "loaded"
141
- };
142
134
  /**
143
135
  * Feature-state key for the live {@link AgentSession}.
144
136
  *
145
137
  * @public
146
138
  */
147
139
  const TABLE_AGENT_STATE = (0, _adapttable_react_adapter.featureStateKey)("table-agent");
148
- function mergeColumn(base, patch) {
149
- const extra = patch?.[base.id];
150
- if (!extra) return base;
151
- return {
152
- ...base,
153
- ...extra
154
- };
155
- }
156
- function cellRecord(row, columns, wanted) {
157
- const record = row && typeof row === "object" ? row : {};
158
- const cells = {};
159
- for (const column of columns) {
160
- if (!column.readable) continue;
161
- if (wanted && !wanted.includes(column.id)) continue;
162
- cells[column.id] = record[column.id];
163
- }
164
- return cells;
165
- }
166
- function viewRevisionStamp(view) {
167
- const table = view?.neutralTable;
168
- if (table) return (0, _adapttable_ai.monotonicRevision)(table.revisions, void 0).token;
169
- const rows = view?.rows ?? [];
170
- const getRowId = view?.getRowId;
171
- const query = view?.query;
172
- return JSON.stringify({
173
- ids: rows.map((row) => getRowId ? getRowId(row) : null),
174
- payloads: rows,
175
- page: query?.page ?? 1,
176
- limit: query?.limit ?? 10,
177
- search: query?.search ?? "",
178
- sortBy: query?.sortBy,
179
- sortDir: query?.sortDir,
180
- filters: query?.extra,
181
- groupBy: view?.groupingState?.groupBy,
182
- aggregateOverrides: view?.groupingState?.aggregateOverrides,
183
- pinnedColumns: view?.pinning?.columns,
184
- pinnedRows: view?.pinning?.rows,
185
- hiddenColumns: view?.columnLayout?.hidden,
186
- columnOrder: view?.columnLayout?.keys
187
- });
188
- }
189
- function liveReadRows(runtime, columns, query, readMax) {
190
- const table = runtime.view()?.neutralTable;
191
- if (table) return (0, _adapttable_ai.readRowsFromNeutral)(table, columns, query, readMax);
192
- const view = runtime.view();
193
- const rows = (query.scope ?? "visible") === "visible" ? view?.visibleRows ?? view?.rows ?? [] : view?.rows ?? [];
194
- const getRowId = view?.getRowId ?? (() => "");
195
- const hidden = columns.filter((column) => !column.readable).map((c) => c.id);
196
- const limit = Math.max(0, Math.min(query.limit, readMax));
197
- return {
198
- rows: rows.slice(query.offset, query.offset + limit).map((row) => ({
199
- rowKey: getRowId(row),
200
- cells: cellRecord(row, columns, query.columns)
201
- })),
202
- offset: query.offset,
203
- limit,
204
- redacted: hidden
205
- };
206
- }
207
- function liveResolveRow(runtime, ref, scope) {
208
- const table = runtime.view()?.neutralTable;
209
- if (table) return (0, _adapttable_ai.resolveRowFromNeutral)(table, ref);
210
- const view = runtime.view();
211
- const rows = scope === "visible" ? view?.visibleRows ?? view?.rows ?? [] : view?.rows ?? [];
212
- const getRowId = view?.getRowId ?? (() => "");
213
- if ("rowKey" in ref) return {
214
- rowKey: ref.rowKey,
215
- scope
216
- };
217
- const row = rows[ref.position - 1];
218
- if (!row) throw new Error(`no row at 1-based position ${ref.position}`);
219
- return {
220
- rowKey: getRowId(row),
221
- scope: ref.scope,
222
- position: ref.position
223
- };
224
- }
225
- function findRow(runtime, rowKey) {
226
- const table = runtime.view()?.neutralTable;
227
- if (table) return table.rowByKey(rowKey);
228
- const view = runtime.view();
229
- const rows = view?.rows ?? [];
230
- const getRowId = view?.getRowId;
231
- if (!getRowId) return void 0;
232
- return rows.find((row) => getRowId(row) === rowKey);
233
- }
234
- function stampColumnLayout(columns, layout) {
235
- if (!layout) return columns;
236
- const byId = new Map(columns.map((column) => [column.id, column]));
237
- const hidden = new Set(layout.hidden);
238
- return (layout.keys.length > 0 ? layout.keys : columns.map((c) => c.id)).map((id) => {
239
- const existing = byId.get(id);
240
- const visible = !hidden.has(id);
241
- if (existing) return {
242
- ...existing,
243
- visible
244
- };
245
- return {
246
- id,
247
- label: id,
248
- type: "unknown",
249
- readable: true,
250
- writable: false,
251
- sortable: false,
252
- visible
253
- };
254
- });
255
- }
256
- function columnsForRuntime(options, runtime) {
257
- const table = runtime.view()?.neutralTable;
258
- if (table) return (0, _adapttable_ai.agentColumnsFromNeutral)(table, options.columns);
259
- if (!options.columns) return [];
260
- return Object.entries(options.columns).map(([id, extra]) => mergeColumn({
261
- id,
262
- label: extra.label ?? id,
263
- type: extra.type ?? "unknown",
264
- readable: extra.readable ?? true,
265
- writable: extra.writable ?? false,
266
- sortable: extra.sortable ?? false
267
- }, options.columns));
268
- }
269
- function observationPolicy(options) {
270
- const approval = (0, _adapttable_ai.sharedApproval)(options.approval);
271
- return {
272
- ...options.writePolicy ? { writePolicy: options.writePolicy } : {},
273
- approval: approval.policy,
274
- ...approval.presentation ? { presentation: approval.presentation } : {},
275
- ...options.commit ? { commit: options.commit } : {}
276
- };
277
- }
278
- function observationFromRuntime(options, runtime, revision, apply) {
279
- const view = runtime.view();
280
- const table = view?.neutralTable;
281
- const query = view?.query;
282
- const ids = runtime.featureIds();
283
- const pages = serverPagination(view, query);
284
- if (table) {
285
- const live = (0, _adapttable_ai.observationFromNeutral)(table, options, revision, apply, ids, query ? {
286
- page: query.page,
287
- limit: query.limit,
288
- search: query.search,
289
- sortBy: query.sortBy,
290
- sortDir: query.sortDir,
291
- pinnedColumns: view?.pinning?.columns,
292
- pinnedRows: view?.pinning?.rows,
293
- hiddenColumns: view?.columnLayout?.hidden,
294
- columnOrder: view?.columnLayout?.keys
295
- } : void 0);
296
- const sizes = offeredPageSizes(query);
297
- return {
298
- ...live,
299
- columns: stampColumnLayout(live.columns, view?.columnLayout),
300
- pagination: live.pagination ? {
301
- ...live.pagination,
302
- pageSizeOptions: sizes
303
- } : {
304
- ...pages,
305
- pageSizeOptions: sizes
306
- },
307
- groupBy: view?.groupingState?.groupBy,
308
- aggregations: (0, _adapttable_ai.aggregationsFor)(aggregationInputs(view, options)),
309
- availableFilters: (0, _adapttable_ai.agentFiltersFromDefs)(view?.filterDefs, view?.filterRegistry, options.columns),
310
- filters: query?.extra
311
- };
312
- }
313
- const columns = stampColumnLayout(columnsForRuntime(options, runtime).map((column) => mergeColumn(column, options.columns)), view?.columnLayout);
314
- return (0, _adapttable_ai.agentObservation)({
315
- tableId: options.tableId,
316
- viewRevision: revision,
317
- featureIds: ids,
318
- columns,
319
- source: view?.sourceCapabilities ?? PAGE_ONLY_SOURCE,
320
- operations: {
321
- ...(0, _adapttable_react_adapter.deriveRuntimeOperations)(view),
322
- applyView: apply.applyView !== void 0
323
- },
324
- apply: options.apply ?? {},
325
- policy: observationPolicy(options),
326
- view: {
327
- search: query?.search ?? "",
328
- ...query?.sortBy === void 0 ? {} : { sortBy: query.sortBy },
329
- ...query?.sortDir === void 0 ? {} : { sortDir: query.sortDir },
330
- ...view?.groupingState?.groupBy === void 0 ? {} : { groupBy: view.groupingState.groupBy },
331
- ...view?.pinning?.columns ? { pinnedColumns: view.pinning.columns } : {},
332
- ...view?.pinning?.rows ? { pinnedRows: view.pinning.rows } : {},
333
- ...view?.columnLayout?.hidden ? { hiddenColumns: view.columnLayout.hidden } : {},
334
- ...view?.columnLayout?.keys ? { columnOrder: view.columnLayout.keys } : {},
335
- ...query?.extra === void 0 ? {} : { filters: query.extra }
336
- },
337
- pagination: pages,
338
- rowAddressScope: "visible",
339
- readMax: options.readMax ?? 50,
340
- aggregations: (0, _adapttable_ai.aggregationsFor)(aggregationInputs(view, options)),
341
- availableFilters: (0, _adapttable_ai.agentFiltersFromDefs)(view?.filterDefs, view?.filterRegistry, options.columns)
342
- });
343
- }
344
- /**
345
- * What a server-backed table's pages are, from what the source will say.
346
- *
347
- * The total is the server's count for the *current query* — the figure the
348
- * table's own pagination is computed from — and it is published only when the
349
- * source claims to have counted. A source that has not counted keeps an
350
- * unknown total rather than being handed the rows that happen to be loaded,
351
- * and a short page is the one thing it still proves about its own end.
352
- */
353
- /** The sizes the table's own rows-per-page control lists. */
354
- function offeredPageSizes(query) {
355
- const limit = query?.limit ?? 10;
356
- const published = query?.defaultLimit ?? limit;
357
- return (0, _adapttable_core.pageSizeOptions)([limit, published]);
358
- }
359
- function serverPagination(view, query) {
360
- const counted = (view?.sourceCapabilities ?? PAGE_ONLY_SOURCE).totalCount === "exact";
361
- const total = query?.total;
362
- const loaded = view?.rows.length;
363
- return (0, _adapttable_ai.agentPagination)({
364
- page: query?.page ?? 1,
365
- pageSize: query?.limit ?? 10,
366
- pageSizeOptions: offeredPageSizes(query),
367
- ...counted && total !== void 0 ? { totalRows: total } : {},
368
- ...loaded === void 0 ? {} : { loadedRows: loaded },
369
- canJump: query?.setPage !== void 0
370
- });
371
- }
372
- function liveEditCells(runtime, extra, edits) {
373
- if (extra?.editCells) return extra.editCells(edits);
374
- const onCellEdit = runtime.view()?.editing?.onCellEdit;
375
- if (!onCellEdit) throw new Error("editCells is not wired");
376
- for (const edit of edits) {
377
- const row = findRow(runtime, edit.rowKey);
378
- if (!row) throw new Error(`row "${edit.rowKey}" is not in the current view`);
379
- onCellEdit(row, edit.column, edit.value);
380
- }
381
- }
382
- function liveStageCells(runtime, extra, edits) {
383
- if (extra?.stageCells) return extra.stageCells(edits);
384
- const stage = runtime.view()?.editing?.stageCell;
385
- if (!stage) throw new Error("stageCells is not wired");
386
- for (const edit of edits) {
387
- const row = findRow(runtime, edit.rowKey);
388
- if (!row) throw new Error(`row "${edit.rowKey}" is not in the current view`);
389
- stage(row, edit.rowKey, edit.column, typeof edit.value === "string" ? edit.value : String(edit.value));
390
- }
391
- }
392
- function liveSetSelection(runtime, extra, ids) {
393
- extra?.setSelection?.(ids);
394
- if (!extra?.setSelection) runtime.view()?.selection?.replace(ids);
395
- }
396
- function rowScope(ref) {
397
- return "scope" in ref ? ref.scope : "visible";
398
- }
399
- function pickReadRows(runtime, extra, columns, readMax) {
400
- return (query) => {
401
- if (extra?.readRows) return extra.readRows(query);
402
- return liveReadRows(runtime, columns, query, readMax);
403
- };
404
- }
405
- function pickResolveRow(runtime, extra) {
406
- return (ref) => {
407
- if (extra?.resolveRow) return extra.resolveRow(ref);
408
- return liveResolveRow(runtime, ref, rowScope(ref));
409
- };
410
- }
411
- function liveQueryFilters(query) {
412
- return query ? query : {};
413
- }
414
- function applyLiveFilters(query, filters) {
415
- const live = liveQueryFilters(query);
416
- if (!live.setExtras && !live.clearExtras) return false;
417
- if (filters == null) {
418
- live.clearExtras?.();
419
- return true;
420
- }
421
- if (typeof filters !== "object" || Array.isArray(filters)) throw new TypeError("setFilters requires a filter object");
422
- if (Object.keys(filters).length === 0) {
423
- live.clearExtras?.();
424
- return true;
425
- }
426
- live.setExtras?.(filters);
427
- return true;
428
- }
429
- function requireQuery(view, name) {
430
- const fn = view()?.query?.[name];
431
- if (!fn) throw new Error(`${name} is not wired`);
432
- return fn;
433
- }
434
- /**
435
- * What the LIVE TABLE can do, before the host's own callbacks are laid over
436
- * it.
437
- *
438
- * `currentApply` builds `{ ...applyFromRuntime(...), ...options.apply }`, so
439
- * a callback the host supplied is the one that runs. A guard here that
440
- * checked for the same callback would be shadowed by that spread and could
441
- * never fire, which is why the view operations below reach straight for the
442
- * live table. `extra` still travels to the row, edit, stage and selection
443
- * helpers, which read it for their own reasons.
444
- */
445
- function applyFromRuntime(runtime, options, extra) {
446
- const columns = columnsForRuntime(options, runtime);
447
- const readMax = options.readMax ?? 50;
448
- const view = () => runtime.view();
449
- return {
450
- readRows: pickReadRows(runtime, extra, columns, readMax),
451
- resolveRow: pickResolveRow(runtime, extra),
452
- setPage: (page) => {
453
- requireQuery(view, "setPage")(page);
454
- },
455
- setLimit: (limit) => {
456
- requireQuery(view, "setLimit")(limit);
457
- },
458
- setSearch: (search) => {
459
- requireQuery(view, "setSearch")(search);
460
- },
461
- setSort: (key, dir) => {
462
- requireQuery(view, "setSort")(key, dir);
463
- },
464
- setGroupBy: (key) => {
465
- const grouping = view()?.groupingState;
466
- if (!grouping) throw new Error("setGroupBy is not wired");
467
- grouping.setGroupBy(key);
468
- },
469
- setAggregations: (patch) => {
470
- (0, _adapttable_ai.applyAggregations)(aggregationInputs(view(), options), patch);
471
- },
472
- pinColumn: (key, side) => {
473
- const pinning = view()?.pinning;
474
- if (!pinning?.setColumnPin) throw new Error("pinColumn is not wired");
475
- pinning.setColumnPin(key, side);
476
- },
477
- hideColumn: (key, hidden) => {
478
- const layout = view()?.columnLayout;
479
- if (!layout?.setHidden) throw new Error("hideColumn is not wired");
480
- layout.setHidden(key, hidden);
481
- },
482
- moveColumn: (key, toIndex) => {
483
- const layout = view()?.columnLayout;
484
- if (!layout?.move) throw new Error("moveColumn is not wired");
485
- layout.move(key, toIndex);
486
- },
487
- setColumnOrder: (order) => {
488
- const layout = view()?.columnLayout;
489
- if (!layout?.setOrder) throw new Error("setColumnOrder is not wired");
490
- layout.setOrder(order);
491
- },
492
- pinRow: (rowKey, side) => {
493
- const pinning = view()?.pinning;
494
- if (!pinning?.setRowPin) throw new Error("pinRow is not wired");
495
- pinning.setRowPin(rowKey, side);
496
- },
497
- editCells: (edits) => liveEditCells(runtime, extra, edits),
498
- stageCells: (edits) => liveStageCells(runtime, extra, edits),
499
- setSelection: (ids) => liveSetSelection(runtime, extra, ids)
500
- };
501
- }
502
- /**
503
- * The live view and filter catalog, in the shape the context builder takes.
504
- *
505
- * The same values the observation carries, read straight off the runtime so
506
- * the caller does not have to rebuild an observation to get at them. What the
507
- * table cannot answer for is simply absent, and the sanitized view names the
508
- * gap rather than defaulting it.
509
- */
510
- /**
511
- * Column ids whose author asked for live values.
512
- *
513
- * The flag is the author's, so it is read from the contract rather than from
514
- * anything a reader can move. A column the agent may not read is not sampled
515
- * whatever it says — the sampler refuses it too, and asking twice is cheaper
516
- * than a read that comes back empty.
517
- */
518
- function sampledColumns(session) {
519
- return session.manifest().columns.filter((column) => column.readable && column.ai?.sample === true).map((column) => column.id);
520
- }
521
- function viewInputsFromRuntime(runtime, options, samples) {
522
- const view = runtime.view();
523
- const query = view?.query;
524
- const filters = (0, _adapttable_ai.agentFiltersFromDefs)(view?.filterDefs, view?.filterRegistry, options.columns);
525
- const aggregations = (0, _adapttable_ai.aggregationsFor)(aggregationInputs(view, options));
526
- return {
527
- ...filters && filters.length > 0 ? { filters } : {},
528
- ...aggregations ? { aggregations } : {},
529
- ...Object.keys(samples).length > 0 ? { samples } : {},
530
- view: {
531
- ...query?.page === void 0 ? {} : { page: query.page },
532
- ...query?.limit === void 0 ? {} : { limit: query.limit },
533
- ...query?.search === void 0 ? {} : { search: query.search },
534
- ...query?.sortBy ? { sortBy: query.sortBy } : {},
535
- ...query?.sortDir ? { sortDir: query.sortDir } : {},
536
- ...view?.groupingState?.groupBy ? { groupBy: view.groupingState.groupBy } : {},
537
- ...query?.extra ? { filters: query.extra } : {},
538
- ...view?.pinning?.columns ? { pinnedColumns: view.pinning.columns } : {},
539
- ...view?.pinning?.rows ? { pinnedRows: view.pinning.rows } : {},
540
- ...view?.columnLayout?.hidden ? { hiddenColumns: view.columnLayout.hidden } : {},
541
- ...view?.columnLayout?.keys ? { columnOrder: view.columnLayout.keys } : {}
542
- }
543
- };
544
- }
545
- /**
546
- * A row-by-row refusal, with the reader's stated reason when they gave one.
547
- *
548
- * The reason travels with the refusal so the receipt and the model-visible
549
- * result can say why rather than only that.
550
- */
551
- function perItemRefusal(transaction, stated) {
552
- return {
553
- ...(0, _adapttable_ai.settleDecisions)(transaction.decisions, "rejected"),
554
- ...stated ? { reason: stated } : {}
555
- };
556
- }
557
- /** One comparable string for an exclusion list, order-insensitive. */
558
- function exclusionKey(keys) {
559
- return keys ? [...keys].sort((a, b) => a.localeCompare(b)).join("|") : "";
560
- }
561
- /**
562
- * What a capability does to the table, from the live catalog.
563
- *
564
- * Read through the session rather than kept in a list here: the definition is
565
- * the only thing that knows, and item 11 published it on the catalog entry so
566
- * every surface reads the same answer.
567
- */
568
- function capabilityKind(session, capability) {
569
- if (!session || capability === void 0) return void 0;
570
- return session.catalog().find((entry) => entry.key === capability)?.kind;
571
- }
572
- /**
573
- * The opt-in list, with an action's own demand for a human applied.
574
- *
575
- * The shared configuration is what the binding can see directly; an action
576
- * that sets `approval: "required"` is read from the custom definition it was
577
- * declared on, so a capability that must always be confirmed never offers the
578
- * control however the table was configured.
579
- */
580
- function alwaysAllowFor(approval, capabilities, capability) {
581
- const shared = (0, _adapttable_ai.sharedApproval)(approval);
582
- if (capability === void 0) return shared.alwaysAllow;
583
- const definition = capabilities?.find((entry) => entry.key === capability);
584
- return (0, _adapttable_ai.resolveApproval)(shared, definition?.ai).alwaysAllow;
585
- }
586
- /**
587
- * How this binding finds what the person in front of the table may see.
588
- *
589
- * The lookups are React's — only this side knows how to find a row in a
590
- * runtime view. What is done with them is not: the enrichment algorithm lives
591
- * in `@adapttable/ai`, so every binding reports an unreadable column the same
592
- * way rather than each inventing its own blank cell.
593
- */
594
- function readerResolver(runtime, columns) {
595
- const view = runtime.view();
596
- const recordFor = (rowKey) => {
597
- const row = findRow(runtime, rowKey);
598
- return row && typeof row === "object" ? row : void 0;
599
- };
600
- return {
601
- rowLabel: (rowKey) => {
602
- const row = findRow(runtime, rowKey);
603
- return row !== void 0 && view?.rowLabel ? view.rowLabel(row) : void 0;
604
- },
605
- cellValue: (rowKey, column) => recordFor(rowKey)?.[column],
606
- cellText: (rowKey, column, value) => {
607
- const format = (runtime.view()?.groupingState?.columns?.find((entry) => entry.key === column))?.formatValue;
608
- const record = recordFor(rowKey);
609
- if (!format || !record) return void 0;
610
- return format({
611
- ...record,
612
- [column]: value
613
- });
614
- },
615
- readable: (column) => columns?.[column]?.readable !== false,
616
- columnLabel: (column) => columns?.[column]?.label
617
- };
618
- }
619
- /**
620
- * The live table's grouping state, as the neutral rules want it.
621
- *
622
- * A projection, not a decision: it names where the facts are and which
623
- * columns the agent may read. What may be offered and what may be set is
624
- * `@adapttable/ai`'s to answer, so a second binding gets the same answers.
625
- */
626
- function aggregationInputs(view, options) {
627
- return {
628
- state: view?.groupingState,
629
- grouping: view?.sourceCapabilities?.grouping,
630
- allows: (key) => options.columns?.[key]?.readable !== false
631
- };
632
- }
633
- function asCallable(value) {
634
- if (typeof value !== "function") return void 0;
635
- return value;
636
- }
637
- /**
638
- * View mutations whose default implementation belongs to this binding.
639
- *
640
- * They call React-backed runtime setters. Committing those setters before the
641
- * call returns lets the session attribute the resulting table revision to the
642
- * exact apply call that made it. Host overrides are deliberately excluded:
643
- * only the host can say when its own async callback has settled.
644
- */
645
- const BINDING_VIEW_MUTATIONS = /* @__PURE__ */ new Set([
646
- "setPage",
647
- "setLimit",
648
- "setSearch",
649
- "setSort",
650
- "setFilters",
651
- "setGroupBy",
652
- "setAggregations",
653
- "pinColumn",
654
- "hideColumn",
655
- "moveColumn",
656
- "setColumnOrder",
657
- "pinRow",
658
- "setSelection"
659
- ]);
660
- function createRevisionCounter() {
661
- let token;
662
- let revision = 1;
663
- const bumpFromToken = (nextToken) => {
664
- if (token === void 0) {
665
- token = nextToken;
666
- return revision;
667
- }
668
- if (token === nextToken) return revision;
669
- token = nextToken;
670
- revision += 1;
671
- return revision;
672
- };
673
- return {
674
- bumpFrom(revisions) {
675
- return bumpFromToken((0, _adapttable_ai.revisionToken)(revisions));
676
- },
677
- bumpFromStamp(stamp) {
678
- return bumpFromToken(stamp);
679
- },
680
- current() {
681
- return revision;
682
- }
683
- };
684
- }
685
- function currentApply(options, runtime) {
686
- const apply = {
687
- ...applyFromRuntime(runtime, options, options.apply),
688
- ...options.apply
689
- };
690
- apply.setFilters = (filters) => {
691
- if (options.apply?.setFilters) {
692
- options.apply.setFilters(filters);
693
- return;
694
- }
695
- if (!applyLiveFilters(runtime.view()?.query, filters)) throw new Error("setFilters is not wired");
696
- };
697
- return apply;
698
- }
699
- function bindLiveSession(optionsRef, runtimeRef, revisionCounter, flushAdmission, waitForChrome, reportProgress) {
700
- const apply = new Proxy({}, { get(_target, prop) {
701
- if (typeof prop !== "string") return void 0;
702
- if (!(prop in currentApply(optionsRef.current, runtimeRef.current))) return void 0;
703
- return (...args) => {
704
- const options = optionsRef.current;
705
- const fn = asCallable(currentApply(options, runtimeRef.current)[prop]);
706
- if (!fn) return void 0;
707
- const host = options.apply;
708
- if (BINDING_VIEW_MUTATIONS.has(prop) && !asCallable(host?.[prop])) {
709
- let result;
710
- (0, react_dom.flushSync)(() => {
711
- result = fn(...args);
712
- });
713
- return result;
714
- }
715
- return fn(...args);
716
- };
717
- } });
718
- const observe = () => {
719
- const options = optionsRef.current;
720
- if (options.observe) return options.observe();
721
- const runtimeView = runtimeRef.current.view();
722
- const table = runtimeView?.neutralTable;
723
- let viewRevision = revisionCounter.current();
724
- if (table) viewRevision = revisionCounter.bumpFrom(table.revisions);
725
- else if (runtimeView) viewRevision = revisionCounter.bumpFromStamp(viewRevisionStamp(runtimeView));
726
- return observationFromRuntime(options, runtimeRef.current, viewRevision, apply);
727
- };
728
- const onApprove = (subject, signal) => {
729
- const options = optionsRef.current;
730
- if (options.onApprove) return options.onApprove(subject, signal);
731
- return waitForChrome.current(subject, signal);
732
- };
733
- const inner = (0, _adapttable_ai.createAgentSession)({
734
- observe,
735
- apply,
736
- onApprove,
737
- onProgress: (report) => {
738
- reportProgress.current(report);
739
- },
740
- capabilities: [...optionsRef.current.capabilities ?? [], ...(0, _adapttable_ai.tableActionCapabilities)(runtimeRef.current.view()?.actions, {
741
- actions: () => runtimeRef.current.view()?.actions,
742
- rowFor: (rowKey) => {
743
- const view = runtimeRef.current.view();
744
- return view?.rows.find((row) => view.getRowId(row) === rowKey);
745
- },
746
- selectedIds: () => {
747
- const selection = runtimeRef.current.view()?.selection;
748
- return selection ? [...selection.selectedIds] : void 0;
749
- }
750
- })],
751
- ...optionsRef.current.capabilityApproval ? { capabilityApproval: optionsRef.current.capabilityApproval } : {},
752
- ...optionsRef.current.excludeCapabilities ? { excludeCapabilities: optionsRef.current.excludeCapabilities } : {}
753
- });
754
- return {
755
- catalog: () => inner.catalog(),
756
- describe: (key) => inner.describe(key),
757
- execute: async (key, args, expectedRevision, idempotencyKey, signal) => {
758
- flushAdmission.current();
759
- return await inner.execute(key, args, expectedRevision, idempotencyKey, signal);
760
- },
761
- manifest: () => inner.manifest()
762
- };
763
- }
764
140
  /** One open approval, whichever shape the write took. */
765
141
  function TableAgentProvider({ feature, children }) {
766
142
  const options = feature.options;
767
143
  const runtime = (0, _adapttable_react_adapter.useTableRuntime)();
768
- const revisionCounterRef = (0, react.useRef)(createRevisionCounter());
144
+ const revisionCounterRef = (0, react.useRef)((0, _adapttable_ai.createRevisionCounter)());
769
145
  const optionsRef = (0, react.useRef)(options);
770
146
  optionsRef.current = options;
771
147
  const runtimeRef = (0, react.useRef)(runtime);
@@ -780,7 +156,7 @@ function TableAgentProvider({ feature, children }) {
780
156
  const waitForChrome = (0, react.useRef)(() => Promise.resolve(false));
781
157
  const reportProgress = (0, react.useRef)(() => void 0);
782
158
  const tableIdRef = (0, react.useRef)(options.tableId);
783
- const registryKeyOf = (next) => `${exclusionKey(next.excludeCapabilities)}!${JSON.stringify(next.capabilityApproval ?? {})}!${(0, _adapttable_ai.tableActionSignature)(runtime.view()?.actions)}`;
159
+ const registryKeyOf = (next) => `${(0, _adapttable_ai.exclusionKey)(next.excludeCapabilities)}!${JSON.stringify(next.capabilityApproval ?? {})}!${(0, _adapttable_ai.tableActionSignature)(runtime.view()?.actions)}`;
784
160
  const registryRef = (0, react.useRef)(registryKeyOf(options));
785
161
  const registryKey = registryKeyOf(options);
786
162
  const sessionRef = (0, react.useRef)(null);
@@ -788,9 +164,17 @@ function TableAgentProvider({ feature, children }) {
788
164
  tableIdRef.current = options.tableId;
789
165
  registryRef.current = registryKey;
790
166
  sessionRef.current = null;
791
- revisionCounterRef.current = createRevisionCounter();
167
+ revisionCounterRef.current = (0, _adapttable_ai.createRevisionCounter)();
792
168
  }
793
- sessionRef.current ??= bindLiveSession(optionsRef, runtimeRef, revisionCounterRef.current, flushAdmission, waitForChrome, reportProgress);
169
+ sessionRef.current ??= (0, _adapttable_ai.bindLiveSession)({
170
+ options: optionsRef,
171
+ runtime: runtimeRef,
172
+ revisions: revisionCounterRef.current,
173
+ flushAdmission,
174
+ waitForChrome,
175
+ reportProgress,
176
+ flush: react_dom.flushSync
177
+ });
794
178
  const session = sessionRef.current;
795
179
  const [revocations, setRevocations] = (0, react.useState)(0);
796
180
  const [progress, setProgress] = (0, react.useState)(null);
@@ -798,7 +182,7 @@ function TableAgentProvider({ feature, children }) {
798
182
  const pendingRef = (0, react.useRef)(null);
799
183
  const transactionId = (0, react.useRef)(0);
800
184
  const neutralTable = runtime.view()?.neutralTable;
801
- const readStamp = (0, react.useCallback)(() => neutralTable ? (0, _adapttable_ai.revisionToken)(neutralTable.revisions) : viewRevisionStamp(runtime.view()), [neutralTable, runtime]);
185
+ const readStamp = (0, react.useCallback)(() => neutralTable ? (0, _adapttable_ai.revisionToken)(neutralTable.revisions) : (0, _adapttable_ai.viewRevisionStamp)(runtime.view()), [neutralTable, runtime]);
802
186
  const subscribeToTable = (0, react.useCallback)((onStoreChange) => neutralTable ? neutralTable.subscribe("all", onStoreChange) : () => void 0, [neutralTable]);
803
187
  const stamp = (0, react.useSyncExternalStore)(subscribeToTable, readStamp, readStamp);
804
188
  (0, react.useDebugValue)(stamp);
@@ -831,15 +215,15 @@ function TableAgentProvider({ feature, children }) {
831
215
  const capability = subject.kind === "operation" ? subject.capability : void 0;
832
216
  if ((0, _adapttable_ai.mayAlwaysAllow)({
833
217
  capability,
834
- kind: capabilityKind(session, capability),
835
- alwaysAllow: alwaysAllowFor(optionsRef.current.approval, optionsRef.current.capabilities, capability)
218
+ kind: (0, _adapttable_ai.capabilityKind)(session, capability),
219
+ alwaysAllow: (0, _adapttable_ai.alwaysAllowFor)(optionsRef.current.approval, optionsRef.current.capabilities, capability)
836
220
  }) && capability !== void 0 && approvalMemory.current.allows(capability, contractVersion())) return Promise.resolve(true);
837
221
  return new Promise((resolve) => {
838
222
  const rows = subject.kind === "rows";
839
223
  let settled = false;
840
224
  const entry = {
841
225
  ...rows ? {} : { capability: subject.capability },
842
- proposals: rows ? (0, _adapttable_ai.displayProposals)(subject.proposals, readerResolver(runtimeRef.current, optionsRef.current.columns)) : [],
226
+ proposals: rows ? (0, _adapttable_ai.displayProposals)(subject.proposals, (0, _adapttable_ai.readerResolver)(runtimeRef.current, optionsRef.current.columns)) : [],
843
227
  perItem: rows && subject.perItem,
844
228
  ...rows ? {} : { operation: {
845
229
  capability: subject.capability,
@@ -876,7 +260,7 @@ function TableAgentProvider({ feature, children }) {
876
260
  manifest: () => session.manifest()
877
261
  };
878
262
  const samplesRef = (0, react.useRef)({});
879
- const viewStateValue = (0, react.useRef)({ read: () => viewInputsFromRuntime(runtimeRef.current, optionsRef.current, samplesRef.current) }).current;
263
+ const viewStateValue = (0, react.useRef)({ read: () => (0, _adapttable_ai.viewInputsFromRuntime)(runtimeRef.current, optionsRef.current, samplesRef.current) }).current;
880
264
  (0, react.useEffect)(() => {
881
265
  options.bridge?.attach?.(session);
882
266
  options.bridge?.viewInputs?.(viewStateValue.read);
@@ -893,7 +277,7 @@ function TableAgentProvider({ feature, children }) {
893
277
  last.current = encoded;
894
278
  options.bridge?.publish?.(published);
895
279
  });
896
- const sampledKey = sampledColumns(session).join("\0");
280
+ const sampledKey = (0, _adapttable_ai.sampledColumns)(session).join("\0");
897
281
  (0, react.useEffect)(() => {
898
282
  const wanted = sampledKey === "" ? [] : sampledKey.split("\0");
899
283
  if (wanted.length === 0) {
@@ -955,8 +339,8 @@ function TableAgentProvider({ feature, children }) {
955
339
  presentation: transaction.presentation,
956
340
  ...(0, _adapttable_ai.mayAlwaysAllow)({
957
341
  capability: transaction.pending.capability,
958
- kind: capabilityKind(session, transaction.pending.capability),
959
- alwaysAllow: alwaysAllowFor(optionsRef.current.approval, optionsRef.current.capabilities, transaction.pending.capability)
342
+ kind: (0, _adapttable_ai.capabilityKind)(session, transaction.pending.capability),
343
+ alwaysAllow: (0, _adapttable_ai.alwaysAllowFor)(optionsRef.current.approval, optionsRef.current.capabilities, transaction.pending.capability)
960
344
  }) ? { alwaysAllow: () => {
961
345
  const capability = transaction.pending.capability;
962
346
  if (capability === void 0) return;
@@ -967,7 +351,7 @@ function TableAgentProvider({ feature, children }) {
967
351
  reject: (reason) => {
968
352
  const stated = typeof reason === "string" ? reason.trim() : void 0;
969
353
  if (transaction.pending.perItem) {
970
- transaction.pending.resolve(perItemRefusal(transaction, stated));
354
+ transaction.pending.resolve((0, _adapttable_ai.perItemRefusal)(transaction, stated));
971
355
  return;
972
356
  }
973
357
  transaction.pending.resolve(stated ? {