@genesislcap/ai-assistant 15.48.0 → 15.50.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.
Files changed (63) hide show
  1. package/dist/ai-assistant.api.json +65 -0
  2. package/dist/ai-assistant.d.ts +35 -16
  3. package/dist/custom-elements.json +118 -2
  4. package/dist/dts/genesis/config.d.ts +31 -0
  5. package/dist/dts/genesis/config.d.ts.map +1 -1
  6. package/dist/dts/genesis/consumes.d.ts.map +1 -1
  7. package/dist/dts/genesis/index.d.ts +2 -2
  8. package/dist/dts/genesis/index.d.ts.map +1 -1
  9. package/dist/dts/genesis/reference-check.d.ts +4 -3
  10. package/dist/dts/genesis/reference-check.d.ts.map +1 -1
  11. package/dist/dts/genesis/reference-existence.d.ts +3 -3
  12. package/dist/dts/genesis/reference-existence.d.ts.map +1 -1
  13. package/dist/dts/genesis/review-model.d.ts +59 -4
  14. package/dist/dts/genesis/review-model.d.ts.map +1 -1
  15. package/dist/dts/genesis/types.d.ts +43 -0
  16. package/dist/dts/genesis/types.d.ts.map +1 -1
  17. package/dist/dts/genesis/write-commit.d.ts +2 -2
  18. package/dist/dts/genesis/write-commit.d.ts.map +1 -1
  19. package/dist/dts/genesis/write-op.d.ts +34 -0
  20. package/dist/dts/genesis/write-op.d.ts.map +1 -0
  21. package/dist/dts/genesis/write-outcome.d.ts +2 -2
  22. package/dist/dts/genesis/write-outcome.d.ts.map +1 -1
  23. package/dist/dts/genesis/write-payload.d.ts +3 -3
  24. package/dist/dts/genesis/write-payload.d.ts.map +1 -1
  25. package/dist/dts/genesis/write-plan.d.ts +18 -7
  26. package/dist/dts/genesis/write-plan.d.ts.map +1 -1
  27. package/dist/dts/genesis/write-review/write-review.d.ts +6 -0
  28. package/dist/dts/genesis/write-review/write-review.d.ts.map +1 -1
  29. package/dist/dts/genesis/write-review/write-review.styles.d.ts.map +1 -1
  30. package/dist/dts/genesis/write-review/write-review.template.d.ts.map +1 -1
  31. package/dist/dts/genesis/write-tools.d.ts +2 -2
  32. package/dist/dts/genesis/write-tools.d.ts.map +1 -1
  33. package/dist/dts/genesis/write-turn.d.ts +5 -3
  34. package/dist/dts/genesis/write-turn.d.ts.map +1 -1
  35. package/dist/dts/main/main.d.ts +16 -0
  36. package/dist/dts/main/main.d.ts.map +1 -1
  37. package/dist/dts/main/main.styles.d.ts.map +1 -1
  38. package/dist/dts/main/main.template.d.ts +7 -4
  39. package/dist/dts/main/main.template.d.ts.map +1 -1
  40. package/dist/esm/genesis/config.js +204 -5
  41. package/dist/esm/genesis/consumes.js +5 -0
  42. package/dist/esm/genesis/index.js +1 -1
  43. package/dist/esm/genesis/review-model.js +62 -10
  44. package/dist/esm/genesis/write-op.js +18 -0
  45. package/dist/esm/genesis/write-outcome.js +13 -6
  46. package/dist/esm/genesis/write-payload.js +22 -10
  47. package/dist/esm/genesis/write-plan.js +121 -12
  48. package/dist/esm/genesis/write-review/write-review.js +20 -1
  49. package/dist/esm/genesis/write-review/write-review.styles.js +14 -0
  50. package/dist/esm/genesis/write-review/write-review.template.js +25 -7
  51. package/dist/esm/genesis/write-tools.js +304 -74
  52. package/dist/esm/genesis/write-turn.js +9 -5
  53. package/dist/esm/main/main.js +21 -0
  54. package/dist/esm/main/main.styles.js +25 -0
  55. package/dist/esm/main/main.template.js +76 -34
  56. package/dist/genesis-consumes.cjs +6 -1
  57. package/dist/genesis-consumes.cjs.map +2 -2
  58. package/dist/genesis-consumes.mjs +6 -1
  59. package/dist/genesis-consumes.mjs.map +2 -2
  60. package/docs/genesis.md +171 -45
  61. package/docs/styling.md +130 -0
  62. package/package.json +17 -17
  63. package/scripts/smoke-genesis-consumes-node.mjs +14 -1
@@ -1,7 +1,7 @@
1
1
  import { __awaiter, __rest } from "tslib";
2
2
  import { getConnect } from '@genesislcap/foundation-comms';
3
3
  import { logger } from '../utils/logger';
4
- import { capIsReadable, customCodeOf, firstPerToolName, opFromName, referencesProblems, toolNameOf, } from './config';
4
+ import { capIsReadable, customCodeOf, firstPerToolName, notReadableReason, opFromName, referencesProblems, rowActionProblem, toolNameOf, } from './config';
5
5
  import { fieldKindOf as criteriaKindOf } from './criteria';
6
6
  import { loadEventFields } from './event-fields';
7
7
  import { cannotBeChanged, createReferenceGate, notAcceptedHere, } from './reference-check';
@@ -11,8 +11,9 @@ import { buildReviewModel, reviewDecisionOf, selectedRows, } from './review-mode
11
11
  import { MAX_FEEDBACK_CHARS } from './review-payload';
12
12
  import { createRequestRowSource } from './row-source';
13
13
  import { genesisTypeName } from './type-name';
14
- import { GENESIS_EVENT_OPS, } from './types';
14
+ import { GENESIS_EVENT_OPS } from './types';
15
15
  import { commitRows } from './write-commit';
16
+ import { readsRow } from './write-op';
16
17
  import { isCarryOnly, isWholeNumberType, PLATFORM_MAINTAINED, sendableFields, } from './write-payload';
17
18
  import { MAX_WRITE_ROWS, planWrite, stillCurrent, } from './write-plan';
18
19
  import { GENESIS_WRITE_REVIEW } from './write-review/write-review';
@@ -203,25 +204,119 @@ const keyFieldsOf = (fields, keyable) => fields
203
204
  return kind !== undefined && kind !== 'datetime';
204
205
  })
205
206
  .map((field) => field.name);
207
+ /** The fields of a declared key whose kind is a date and time, which no read matches exactly. */
208
+ const datetimeKeyFields = (resource, fields) => {
209
+ var _a;
210
+ return ((_a = resource.key) !== null && _a !== void 0 ? _a : []).filter((name) => {
211
+ const field = fields.find((one) => one.name === name);
212
+ return !!field && criteriaKindOf(field.type) === 'datetime';
213
+ });
214
+ };
215
+ /**
216
+ * The key a write names its row by, when the config declares one (contracts C-18.3, C-19): a row
217
+ * action's always, and a modify's or a delete's unless a field of it is a date and time. Such a
218
+ * key cannot be matched by equality, so that modify or delete is built as before, from the fields
219
+ * its row source can search by.
220
+ */
221
+ const declaredKey = (resource, op, fields) => {
222
+ var _a;
223
+ if (op === 'row-action')
224
+ return resource.key;
225
+ if ((op !== 'modify' && op !== 'delete') || !((_a = resource.key) === null || _a === void 0 ? void 0 : _a.length))
226
+ return undefined;
227
+ return datetimeKeyFields(resource, fields).length ? undefined : resource.key;
228
+ };
229
+ /** Said once when a modify's or a delete's declared key is set aside for a date-and-time field. */
230
+ const warnUnusedKey = (resource, op, fields) => {
231
+ const datetimes = op === 'modify' || op === 'delete' ? datetimeKeyFields(resource, fields) : [];
232
+ if (!datetimes.length)
233
+ return;
234
+ logger.warn(`Genesis assistant: ${resource.name} names its row by ${datetimes.join(', ')}, a date and ` +
235
+ 'time no read can match exactly, so its key is not used and its row is found as before.');
236
+ };
237
+ /**
238
+ * Why a write's declared key, or a run's key or inputs, do not fit its event, or `''`. Said when the
239
+ * tool is defined, so a modify's or a delete's key set aside for a date and time is said here too.
240
+ */
241
+ const fieldsProblem = (resource, op, fields) => {
242
+ warnUnusedKey(resource, op, fields);
243
+ return op === 'row-action'
244
+ ? rowActionFieldProblem(resource, fields)
245
+ : keyFieldProblem(declaredKey(resource, op, fields), fields);
246
+ };
247
+ /** Why a declared key does not fit its event, or `''`: a field the handler would not be sent. */
248
+ const keyFieldProblem = (key, fields) => (key !== null && key !== void 0 ? key : [])
249
+ .filter((name) => !fields.some((field) => field.name === name))
250
+ .map((name) => `its key ${name} is not a field of the event`)
251
+ .join('; ');
252
+ /**
253
+ * Why no row could be found by what the row source searches by, or `''`: it searches by none of
254
+ * the event's fields, or not by every field of a declared key, which is all the row is named by.
255
+ */
256
+ const unfindable = (key, fields, keyable, sourceName) => {
257
+ const searchable = keyFieldsOf(fields, keyable);
258
+ if (!searchable.length) {
259
+ return (`${sourceName} can be searched by none of the fields it declares, so no row could be found ` +
260
+ 'to act on');
261
+ }
262
+ const unsearchable = (key !== null && key !== void 0 ? key : []).filter((name) => !searchable.includes(name));
263
+ return unsearchable.length
264
+ ? `${sourceName} cannot be searched by its key field(s) ${unsearchable.join(', ')}, so its ` +
265
+ 'row could not be found'
266
+ : '';
267
+ };
206
268
  /**
207
269
  * @param keyable - The row source's filter fields. Empty unless given, so a caller that forgets
208
270
  * it offers no key at all rather than falling back to the event's own fields.
209
271
  */
210
272
  function rowSchema(fields, op, keyable = new Map(),
211
273
  // Required: a default would offer every field, checked or not.
212
- references) {
274
+ references,
275
+ /** A row action's declared inputs, by field name. */
276
+ rowInputs = [],
277
+ /** A declared key, the only fields the row is named by; empty when there is none. */
278
+ rowKey = []) {
213
279
  // A value whose reference cannot be checked is not offered: see reference-check.ts.
214
280
  const writable = writableFields(fields, op).filter((field) => !references.unchecked.has(field.name));
215
281
  const sentences = checkedSentences(references.checkable);
216
282
  if (op === 'insert' || op === 'custom') {
217
283
  return objectOf(writable, writable.filter((field) => !field.optional).map((field) => field.name), sentences);
218
284
  }
219
- const key = {
220
- type: 'object',
221
- description: 'Which row to act on: the values that identify exactly one row, such as its id.',
222
- properties: Object.fromEntries(keyFieldsOf(fields, keyable).map((name) => [name, { type: 'string' }])),
223
- additionalProperties: false,
224
- };
285
+ // A declared key names the row by those fields and nothing else, every one required: a search by
286
+ // other values finds the row once, but cannot find it again after one of them changes.
287
+ const key = rowKey.length
288
+ ? {
289
+ type: 'object',
290
+ description: `${op === 'row-action' ? 'The row to run the handler on' : 'Which row to act on'}, named ` +
291
+ 'by its key. To act on rows found by other values, read the table first to get their keys.',
292
+ properties: Object.fromEntries(rowKey.map((name) => [name, { type: 'string' }])),
293
+ required: [...rowKey],
294
+ additionalProperties: false,
295
+ }
296
+ : {
297
+ type: 'object',
298
+ description: 'Which row to act on: the values that identify exactly one row, such as its id.',
299
+ properties: Object.fromEntries(keyFieldsOf(fields, keyable).map((name) => [name, { type: 'string' }])),
300
+ additionalProperties: false,
301
+ };
302
+ // A run is named by its key, as a modify is, and given its inputs, every one required. Never
303
+ // `changes`: nothing here says what the row becomes, and no column keeps its value because the
304
+ // model left it out. The handler's code decides (contracts C-18.7.5).
305
+ if (op === 'row-action') {
306
+ const given = [...new Set(rowInputs)]
307
+ .map((name) => fields.find((field) => field.name === name))
308
+ .filter((field) => !!field);
309
+ return {
310
+ type: 'object',
311
+ properties: Object.assign({ key }, (given.length
312
+ ? {
313
+ inputs: Object.assign(Object.assign({}, objectOf(given, given.map((field) => field.name))), { description: 'What the handler needs. Every one is required.' }),
314
+ }
315
+ : {})),
316
+ required: given.length ? ['key', 'inputs'] : ['key'],
317
+ additionalProperties: false,
318
+ };
319
+ }
225
320
  return op === 'delete'
226
321
  ? { type: 'object', properties: { key }, required: ['key'], additionalProperties: false }
227
322
  : {
@@ -238,23 +333,31 @@ references) {
238
333
  /**
239
334
  * `custom` has no entry because a custom event never reaches a definition — see {@link
240
335
  * decideOp}. A vague verb here ("Runs") was the only thing standing between the model and a
241
- * path with none of this module's guarantees.
336
+ * path with none of this module's guarantees. A row action has one, because it has them all: its
337
+ * row is read, merged, reviewed and read again before it is written.
242
338
  */
243
339
  const WHAT_IT_DOES = {
244
340
  insert: 'Adds rows to',
245
341
  modify: 'Changes rows in',
246
342
  delete: 'Removes rows from',
343
+ 'row-action': 'Runs a handler on rows of',
247
344
  };
345
+ /** What a run's description says about the row it sends and what its handler does with it. */
346
+ const RUN_SENTENCE = "The row is sent as it is now with your inputs applied; the handler's code decides what it " +
347
+ 'changes; every input is required.';
248
348
  function writeDefinition(resource, op, fields, keyable,
249
349
  // Required, for the reason rowSchema's is.
250
350
  references) {
351
+ var _a;
251
352
  const notOffered = [...references.unchecked.keys()].join(', ');
252
353
  const checked = checkedLine(references.checkable);
253
354
  return {
254
355
  name: toolNameOf(resource.name),
255
356
  description: `${resource.context}\n\n` +
256
357
  (checked ? `${checked}\n\n` : '') +
257
- `${WHAT_IT_DOES[op]} ${resource.name}. Nothing is written until the user has read the ` +
358
+ `${WHAT_IT_DOES[op]} ${resource.name}. ` +
359
+ (op === 'row-action' ? `${RUN_SENTENCE} ` : '') +
360
+ 'Nothing is written until the user has read the ' +
258
361
  'rows in a review and approved them, one by one — so propose the whole change and let ' +
259
362
  'them decide, rather than asking in chat first. The result says what happened to each ' +
260
363
  'row; read it rather than assuming the write succeeded.' +
@@ -276,7 +379,7 @@ references) {
276
379
  // by being refused.
277
380
  minItems: 1,
278
381
  maxItems: MAX_WRITE_ROWS,
279
- items: rowSchema(fields, op, keyable, references),
382
+ items: rowSchema(fields, op, keyable, references, (_a = resource.inputs) === null || _a === void 0 ? void 0 : _a.map((input) => input.field), declaredKey(resource, op, fields)),
280
383
  },
281
384
  },
282
385
  required: ['rows'],
@@ -284,7 +387,7 @@ references) {
284
387
  },
285
388
  };
286
389
  }
287
- const decideOp = (resource) => {
390
+ const decideOp = (resource, requestNames, whyNotReadable) => {
288
391
  const named = opFromName(resource.name);
289
392
  const declared = resource.op;
290
393
  // An op outside the known set is no op at all. This factory is exported and never runs the
@@ -319,6 +422,13 @@ const decideOp = (resource) => {
319
422
  };
320
423
  }
321
424
  if (op === 'custom') {
425
+ // A row action only with every one of its fields well formed (contracts C-18.7.4); a malformed
426
+ // one is refused with what is wrong with it, and any other custom event as before.
427
+ const problem = rowActionProblem(resource, requestNames, whyNotReadable);
428
+ if (problem)
429
+ return { refused: problem };
430
+ if (resource.shape === 'row')
431
+ return { op: 'row-action' };
322
432
  return {
323
433
  refused: 'a custom event gets no write tool yet: every rule this path follows was learned from ' +
324
434
  "generated CRUD handlers, and a custom handler is the app's own. If it replaces the " +
@@ -327,6 +437,35 @@ const decideOp = (resource) => {
327
437
  }
328
438
  return { op };
329
439
  };
440
+ /**
441
+ * Why a row action's key and inputs do not fit its event's fields, or `''` (contracts C-18.7.5).
442
+ *
443
+ * @remarks
444
+ * Each is a tool that would refuse every row: a key the handler would not be sent, or an input the
445
+ * model may not set. A carry-only input, a NANO_TIMESTAMP, is one this assistant never sets.
446
+ */
447
+ function rowActionFieldProblem(resource, fields) {
448
+ var _a, _b;
449
+ const byName = new Map(fields.map((field) => [field.name, field]));
450
+ const problems = [];
451
+ for (const name of (_a = resource.key) !== null && _a !== void 0 ? _a : []) {
452
+ if (!byName.has(name))
453
+ problems.push(`its key ${name} is not a field of the event`);
454
+ }
455
+ for (const { field: name } of (_b = resource.inputs) !== null && _b !== void 0 ? _b : []) {
456
+ const field = byName.get(name);
457
+ if (!field)
458
+ problems.push(`its input ${name} is not a field of the event`);
459
+ else if (PLATFORM_MAINTAINED.has(name))
460
+ problems.push(`its input ${name} is set by the platform`);
461
+ else if (field.readOnly)
462
+ problems.push(`its input ${name} is read-only`);
463
+ else if (isCarryOnly(field)) {
464
+ problems.push(`its input ${name} is a ${genesisTypeName(field.type)}, which this assistant does not set`);
465
+ }
466
+ }
467
+ return problems.join('; ');
468
+ }
330
469
  /** The Connect the tools were given, or the app's own; none when neither can be had yet. */
331
470
  const connectOf = (options) => {
332
471
  var _a;
@@ -381,12 +520,14 @@ const joined = (items) => items.length > 1 ? `${items.slice(0, -1).join(', ')} a
381
520
  * `tools` are the events that can get a write tool by the config, sharing the key, in config
382
521
  * order: the denial's `next` names them, so it promises exactly what the lock refuses.
383
522
  */
384
- const locksOf = (resources, decide, sourceNameOf) => {
523
+ const locksOf = (resources, decide, sourceNameOf,
524
+ // Required, with no default: without it a row action decides as refused and locks only itself,
525
+ // where its table's other write tools should share its lock.
526
+ requestNames) => {
385
527
  const keyOf = (resource) => {
386
528
  var _a;
387
- const decided = decideOp(resource);
388
- const readsRows = decided.op === 'modify' || decided.op === 'delete';
389
- const source = (_a = readResourceFor(resource.name)) !== null && _a !== void 0 ? _a : (readsRows ? sourceNameOf(resource, decided.op) : undefined);
529
+ const decided = decideOp(resource, requestNames);
530
+ const source = (_a = readResourceFor(resource.name)) !== null && _a !== void 0 ? _a : (readsRow(decided.op) ? sourceNameOf(resource, decided.op) : undefined);
390
531
  // Only a `REQ_` name gives a table: a request a host named anything else (`ALL_TRADES`) is no
391
532
  // table this can name, so the event locks only itself rather than a table that is a guess.
392
533
  const table = (source === null || source === void 0 ? void 0 : source.startsWith('REQ_')) ? source.slice('REQ_'.length) : undefined;
@@ -487,19 +628,25 @@ function configRules(resources, options) {
487
628
  : 'none is accepted, as its name does not end in _INSERT, _MODIFY or _DELETE') +
488
629
  '. A view or a query is never a pre-image');
489
630
  };
631
+ // A row action's own request can be in the config and still not readable. Said as it is, since
632
+ // "the config has none" sends whoever reads the console looking for something that is there.
633
+ const whyNotReadable = notReadableReason({ unreadable, leftOut, queries: queryNames });
490
634
  /**
491
635
  * The op a write through this event does, or why it gets no tool: its own op rules first, then
492
636
  * its rowSources entry. One decision for both the definition and the handler, so they cannot
493
637
  * disagree about which events may write.
494
638
  */
495
639
  const decide = (resource) => {
496
- const decided = decideOp(resource);
640
+ const decided = decideOp(resource, requestNames, whyNotReadable);
497
641
  // The references rule the validator applies, here as well because a direct call skips it.
498
642
  const malformed = referencesProblems(resource, decided.refused ? resource.op : decided.op);
499
643
  const reasons = [
500
644
  decided.refused,
501
645
  rowSourceRefusal(resource.name),
502
646
  malformed.length ? `its references are malformed: ${malformed.join('; ')}` : undefined,
647
+ // The row-action rule the validator applies, here as well for the same reason. A custom
648
+ // event's has been said by decideOp already.
649
+ resource.op === 'custom' ? undefined : rowActionProblem(resource, requestNames),
503
650
  ].filter((reason) => !!reason);
504
651
  // Every reason that holds: the op's alone would leave a wrong rowSources entry unsaid, to come
505
652
  // back as a refusal the day the op is fixed.
@@ -542,9 +689,10 @@ function configRules(resources, options) {
542
689
  * rowSourceRefusal).
543
690
  */
544
691
  const readsFrom = (resource, op) => {
545
- if (op !== 'modify' && op !== 'delete')
692
+ if (!readsRow(op))
546
693
  return undefined;
547
- const name = readResourceFor(resource.name);
694
+ // A row action's table is its entity, never its name, which names its handler.
695
+ const name = op === 'row-action' ? `REQ_${resource.entity}` : readResourceFor(resource.name);
548
696
  return name && requestNames.has(name) ? name : undefined;
549
697
  };
550
698
  /**
@@ -640,7 +788,7 @@ export function createGenesisWriteTools(resources, options = {}) {
640
788
  const gateNotices = { failed: new Set(), waiting: new Set() };
641
789
  const resolveConnect = () => connectOf(options);
642
790
  const sources = new Map();
643
- const lockOf = locksOf(resources, decide, readsFrom);
791
+ const lockOf = locksOf(resources, decide, readsFrom, requestNames);
644
792
  /**
645
793
  * The resource a modify or delete reads through, or nothing — in which case the event gets no
646
794
  * tool. A modify with no row to read cannot be built: under replace semantics the fields
@@ -723,7 +871,7 @@ export function createGenesisWriteTools(resources, options = {}) {
723
871
  return;
724
872
  }
725
873
  const source = sourceFor(resource, decided.op, connect);
726
- const needsRow = decided.op === 'modify' || decided.op === 'delete';
874
+ const needsRow = readsRow(decided.op);
727
875
  if (needsRow && !source) {
728
876
  // Settled for good: the app exposes no resource to read this event's rows
729
877
  // through, which is a property of the config rather than of this moment, so
@@ -735,6 +883,13 @@ export function createGenesisWriteTools(resources, options = {}) {
735
883
  const fields = yield loadFields(resource, connect);
736
884
  if (!fields)
737
885
  return;
886
+ // A write whose key or inputs the event cannot carry would refuse every row it is sent.
887
+ const unfit = fieldsProblem(resource, decided.op, fields);
888
+ if (unfit) {
889
+ skipped.add(resource.name);
890
+ logger.warn(`Genesis assistant: ${resource.name} has no write tool because ${unfit}.`);
891
+ return;
892
+ }
738
893
  // Whether its references can be checked comes first: it can withhold the tool, and it
739
894
  // decides which fields are offered at all.
740
895
  const references = yield gateForTool(resource.name, () => referenceGate(resource, decided.op, fields, connect), skipped, gateNotices);
@@ -771,7 +926,7 @@ export function createGenesisWriteTools(resources, options = {}) {
771
926
  // Only a MODIFY needs full coverage: it replaces the record, so a column the read
772
927
  // cannot see is a column written null. A delete sends its key and nothing else, so
773
928
  // demanding the rest would refuse a tool over fields it never puts on the wire.
774
- if (source && decided.op === 'modify') {
929
+ if (source && (decided.op === 'modify' || decided.op === 'row-action')) {
775
930
  const covered = yield coverage(decided.op, fields, source);
776
931
  if (!covered)
777
932
  return;
@@ -794,11 +949,11 @@ export function createGenesisWriteTools(resources, options = {}) {
794
949
  keyable = yield source.filterableBy();
795
950
  if (!keyable)
796
951
  return;
797
- if (!keyFieldsOf(fields, keyable).length) {
952
+ const key = declaredKey(resource, decided.op, fields);
953
+ const unfound = unfindable(key, fields, keyable, source.resource);
954
+ if (unfound) {
798
955
  skipped.add(resource.name);
799
- logger.warn(`Genesis assistant: ${resource.name} has no write tool because ` +
800
- `${source.resource} can be searched by none of the fields it declares, so no ` +
801
- 'row could be found to act on.');
956
+ logger.warn(`Genesis assistant: ${resource.name} has no write tool because ${unfound}.`);
802
957
  return;
803
958
  }
804
959
  }
@@ -890,6 +1045,43 @@ const summarise = (rows) => {
890
1045
  // into a not-written count is how a row gets written twice.
891
1046
  return [...counts.entries()].map(([status, count]) => `${count} ${status}`).join(', ');
892
1047
  };
1048
+ /**
1049
+ * A run's declared inputs, by field name: what the model must send, and all it may. Once each: a
1050
+ * hand-written config can name one twice, and nothing refuses that (contracts C-18.R2).
1051
+ */
1052
+ const declaredInputs = (resource) => {
1053
+ var _a, _b;
1054
+ return [
1055
+ ...new Set((_b = (_a = resource.inputs) === null || _a === void 0 ? void 0 : _a.map((input) => input.field)) !== null && _b !== void 0 ? _b : []),
1056
+ ];
1057
+ };
1058
+ /**
1059
+ * What a write's review shows: its planned rows, with the columns this op can send.
1060
+ *
1061
+ * @remarks
1062
+ * The columns are the fields the op can SEND — the platform's own never travel, so a column for
1063
+ * them would show a user a blank for something no write touches — plus, for a delete, the ones it
1064
+ * merely shows. A delete SENDS its key and nothing else, but what the user approves is the removal
1065
+ * of a whole row, so its table shows the row; the payload is still what gets committed. A run's
1066
+ * review names its handler and table, and marks its key and inputs (contracts C-18.7.7).
1067
+ */
1068
+ function reviewOf(resource, op, planned, shownFields, customCode, inputs) {
1069
+ var _a, _b, _c;
1070
+ return buildReviewModel(Object.assign({ resource: resource.name, op, fields: shownFields, rows: planned.map((row) => {
1071
+ var _a;
1072
+ return (Object.assign(Object.assign({ index: row.index, details: (_a = row.details) !== null && _a !== void 0 ? _a : {} }, (op === 'delete' && row.preImage ? { display: row.preImage } : {})), { preImage: op === 'delete' ? undefined : row.preImage, problems: row.problems }));
1073
+ }), customCode }, (op === 'row-action'
1074
+ ? {
1075
+ rowAction: {
1076
+ handler: resource.name.replace(/^EVENT_/, ''),
1077
+ entity: (_a = resource.entity) !== null && _a !== void 0 ? _a : '',
1078
+ key: (_b = resource.key) !== null && _b !== void 0 ? _b : [],
1079
+ inputs,
1080
+ effects: (_c = resource.effects) !== null && _c !== void 0 ? _c : [],
1081
+ },
1082
+ }
1083
+ : {})));
1084
+ }
893
1085
  function runWrite(resource, args, context, deps) {
894
1086
  return __awaiter(this, void 0, void 0, function* () {
895
1087
  var _a, _b, _c, _d, _e, _f, _g, _h;
@@ -926,28 +1118,24 @@ function runWrite(resource, args, context, deps) {
926
1118
  if (!fields) {
927
1119
  return fail('request_failed', `${resource.name} could not be described, so nothing was sent.`);
928
1120
  }
929
- const source = deps.sourceFor(resource, op, connect);
930
- if ((op === 'modify' || op === 'delete') && !source) {
931
- return fail('rejected', `${resource.name} cannot be written: ${deps.whyNoSource(resource.name)}. Nothing was sent.`);
932
- }
933
- if (source && op === 'modify') {
934
- // Checked here as well as when the tool was defined, because this factory is exported: a
935
- // host can hold the handlers without ever calling toolDefinitions(), and the guarantee must
936
- // not depend on which of the two ran first.
937
- const covered = yield deps.coverage(op, fields, source);
938
- if (!covered) {
939
- return fail('request_failed', `${source.resource} could not be described, so nothing was sent.`);
940
- }
941
- if (covered.missing.length) {
942
- return fail('rejected', `${resource.name} cannot be written through ${source.resource}, which does not return ` +
943
- `${covered.missing.join(', ')}. Writing without those would set them empty.`);
944
- }
945
- }
1121
+ const readable = yield sourceForRun(resource, op, fields, connect, deps);
1122
+ if ('error' in readable)
1123
+ return fail(readable.error, readable.message);
1124
+ const { source } = readable;
946
1125
  // The definition's reference gate again, for the reason `coverage` is repeated above.
947
1126
  const references = yield referencesForRun(resource, op, fields, connect, deps.referenceGate);
948
1127
  if ('error' in references)
949
1128
  return fail(references.error, references.message);
950
- const plan = yield planWrite(args.rows, { op, fields, source, unchecked: references.unchecked });
1129
+ const inputs = declaredInputs(resource);
1130
+ const key = declaredKey(resource, op, fields);
1131
+ const plan = yield planWrite(args.rows, {
1132
+ op,
1133
+ fields,
1134
+ source,
1135
+ unchecked: references.unchecked,
1136
+ keyFields: key,
1137
+ inputs,
1138
+ });
951
1139
  if (plan.status === 'rejected')
952
1140
  return fail('rejected', plan.reason);
953
1141
  // Whether each reference a row sets names a row that exists. Before the proposal is taken, so a
@@ -964,7 +1152,7 @@ function runWrite(resource, args, context, deps) {
964
1152
  return fail(checked.error, checked.message);
965
1153
  const planned = checked.rows;
966
1154
  // What the identical check below compares: see write-turn.ts.
967
- const proposal = proposalOf(op, planned, fields);
1155
+ const proposal = proposalOf(op, planned, fields, inputs);
968
1156
  // Every column the review will RENDER needs a type, and for a delete that is more than the
969
1157
  // event declares: it shows the whole row, including columns the event never mentions, and
970
1158
  // without a type a date is shown to the approver as raw epoch millis — `1789948800000` is not
@@ -989,19 +1177,7 @@ function runWrite(resource, args, context, deps) {
989
1177
  }
990
1178
  }
991
1179
  }
992
- const model = buildReviewModel({
993
- resource: resource.name,
994
- op,
995
- // The columns are the fields this op can SEND — the platform's own never travel, so a column
996
- // for them would show a user a blank for something no write touches — plus, for a delete,
997
- // the ones it merely shows.
998
- fields: shownFields,
999
- rows: planned.map((row) => {
1000
- var _a;
1001
- return (Object.assign(Object.assign({ index: row.index, details: (_a = row.details) !== null && _a !== void 0 ? _a : {} }, (op === 'delete' && row.preImage ? { display: row.preImage } : {})), { preImage: op === 'delete' ? undefined : row.preImage, problems: row.problems }));
1002
- }),
1003
- customCode: deps.customCode,
1004
- });
1180
+ const model = reviewOf(resource, op, planned, shownFields, deps.customCode, inputs);
1005
1181
  // What the staleness check compares: every column the review RENDERED, because what the user
1006
1182
  // saw is evidence for what was checked only if the two are the same set. For a modify that is
1007
1183
  // the event's own fields, which are also everything the write can change. A delete SENDS its
@@ -1107,18 +1283,10 @@ function runWrite(resource, args, context, deps) {
1107
1283
  });
1108
1284
  }
1109
1285
  }
1110
- yield commitApproved(approved, lines, {
1111
- eventName: resource.name,
1112
- op,
1286
+ yield commitApproved(approved, lines, Object.assign(Object.assign({ eventName: resource.name, op,
1113
1287
  byIndex,
1114
- source,
1115
- checkedFields,
1116
- fields,
1117
- checkable: references.checkable,
1118
- connect,
1119
- commitMs: (_f = deps.timeouts) === null || _f === void 0 ? void 0 : _f.commitMs,
1120
- turnSignal: context.turnSignal,
1121
- });
1288
+ source }, (key ? { keyFields: key } : {})), { checkedFields,
1289
+ fields, checkable: references.checkable, connect, commitMs: (_f = deps.timeouts) === null || _f === void 0 ? void 0 : _f.commitMs, turnSignal: context.turnSignal }));
1122
1290
  const rows = planned.map((row) => {
1123
1291
  var _a;
1124
1292
  return (_a = lines.get(row.index)) !== null && _a !== void 0 ? _a : {
@@ -1143,6 +1311,67 @@ const reviewOutcomeOf = (rows, approved, stopped) => {
1143
1311
  .map(({ index, status, message }) => ({ index, status, message })),
1144
1312
  };
1145
1313
  };
1314
+ /**
1315
+ * The definition's checks on a write's fields and row source, run again for a call: its source, or
1316
+ * why the call is refused.
1317
+ *
1318
+ * @remarks
1319
+ * Checked here as well as when the tool was defined, because this factory is exported: a host can
1320
+ * hold the handlers without ever calling toolDefinitions(), and the guarantee must not depend on
1321
+ * which of the two ran first.
1322
+ */
1323
+ function sourceForRun(resource, op, fields, connect, deps) {
1324
+ return __awaiter(this, void 0, void 0, function* () {
1325
+ // A key the event does not declare would leave DETAILS without one, and the handler sent no row
1326
+ // to run on.
1327
+ const key = declaredKey(resource, op, fields);
1328
+ const unfit = op === 'row-action' ? rowActionFieldProblem(resource, fields) : keyFieldProblem(key, fields);
1329
+ if (unfit) {
1330
+ return { error: 'rejected', message: `${resource.name} has no write tool because ${unfit}.` };
1331
+ }
1332
+ const source = deps.sourceFor(resource, op, connect);
1333
+ if (readsRow(op) && !source) {
1334
+ return {
1335
+ error: 'rejected',
1336
+ message: `${resource.name} cannot be written: ${deps.whyNoSource(resource.name)}. Nothing was sent.`,
1337
+ };
1338
+ }
1339
+ if (source && (op === 'modify' || op === 'row-action')) {
1340
+ const covered = yield deps.coverage(op, fields, source);
1341
+ if (!covered) {
1342
+ return {
1343
+ error: 'request_failed',
1344
+ message: `${source.resource} could not be described, so nothing was sent.`,
1345
+ };
1346
+ }
1347
+ if (covered.missing.length) {
1348
+ return {
1349
+ error: 'rejected',
1350
+ message: `${resource.name} cannot be written through ${source.resource}, which does not return ` +
1351
+ `${covered.missing.join(', ')}. Writing without those would set them empty.`,
1352
+ };
1353
+ }
1354
+ }
1355
+ // And its search check: a key field the row source cannot search by finds no row to act on.
1356
+ if (source && (key === null || key === void 0 ? void 0 : key.length)) {
1357
+ const keyable = yield source.filterableBy();
1358
+ if (!keyable) {
1359
+ return {
1360
+ error: 'request_failed',
1361
+ message: `${source.resource} could not be described, so nothing was sent.`,
1362
+ };
1363
+ }
1364
+ const unfound = unfindable(key, fields, keyable, source.resource);
1365
+ if (unfound) {
1366
+ return {
1367
+ error: 'rejected',
1368
+ message: `${resource.name} has no write tool because ${unfound}.`,
1369
+ };
1370
+ }
1371
+ }
1372
+ return { source };
1373
+ });
1374
+ }
1146
1375
  /**
1147
1376
  * The definition's reference gate, run again for a call: what it means for the write, or why the
1148
1377
  * call is refused when it withholds the tool.
@@ -1226,17 +1455,18 @@ function commitApproved(approved, lines, run) {
1226
1455
  if (stoppedAt(row.index))
1227
1456
  continue;
1228
1457
  const planned = run.byIndex.get(row.index);
1229
- const readsRow = run.op === 'modify' || run.op === 'delete';
1458
+ // THE staleness gate: every op that read a row reads it again before it writes.
1459
+ const rereads = readsRow(run.op);
1230
1460
  // The same references the review checked, from the same frozen payload and pre-image.
1231
1461
  const asks = planned ? asksOf(planned, run.op, run.fields, run.checkable).asks : [];
1232
- if (readsRow || asks.length) {
1462
+ if (rereads || asks.length) {
1233
1463
  // A check run early is a check of a row that may since have moved: it has to run against
1234
1464
  // the row as it is at the moment of writing, which is the whole point of interleaving. Its
1235
1465
  // references are read beside it, not after it, so the window stays one round trip.
1236
1466
  // oxlint-disable-next-line no-await-in-loop -- each row is checked as it is written
1237
1467
  const [outcome, references] = yield Promise.all([
1238
- readsRow
1239
- ? stillCurrent(planned, { source: run.source, fields: run.checkedFields })
1468
+ rereads
1469
+ ? stillCurrent(planned, Object.assign({ source: run.source, fields: run.checkedFields }, (run.keyFields ? { keyFields: run.keyFields } : {})))
1240
1470
  : undefined,
1241
1471
  referencesNow(asks),
1242
1472
  ]);
@@ -6,19 +6,23 @@ import { sameValue } from './value-compare';
6
6
  * @remarks
7
7
  * A modify's payload is the whole merged row, so it also carries every column it leaves alone,
8
8
  * as read. Compared whole, a column somebody else changed between two reviews made a resent
9
- * proposal look new. Only the fields that differ from the row as read are kept.
9
+ * proposal look new. Only the fields that differ from the row as read are kept. A run's payload
10
+ * is the whole row too, and what the model proposes in it is its inputs, so those are kept.
10
11
  *
12
+ * @param inputs - A row action's declared inputs, by field name.
11
13
  * @internal
12
14
  */
13
- export function proposalOf(op, rows, fields) {
15
+ export function proposalOf(op, rows, fields, inputs = []) {
14
16
  const typeOf = new Map(fields.map((field) => [field.name, field.type]));
15
17
  return rows.map((row) => {
16
18
  var _a, _b, _c, _d, _e;
17
19
  const details = (_a = row.details) !== null && _a !== void 0 ? _a : {};
18
20
  const preImage = (_b = row.preImage) !== null && _b !== void 0 ? _b : {};
19
- const change = op === 'modify'
20
- ? Object.fromEntries(Object.entries(details).filter(([name, value]) => !sameValue(value, preImage[name], typeOf.get(name))))
21
- : details;
21
+ const change = op === 'row-action'
22
+ ? Object.fromEntries(inputs.map((field) => [field, details[field]]))
23
+ : op === 'modify'
24
+ ? Object.fromEntries(Object.entries(details).filter(([name, value]) => !sameValue(value, preImage[name], typeOf.get(name))))
25
+ : details;
22
26
  return { target: (_c = row.key) !== null && _c !== void 0 ? _c : {}, change, problems: (_d = row.problems) !== null && _d !== void 0 ? _d : [], notes: (_e = row.notes) !== null && _e !== void 0 ? _e : [] };
23
27
  });
24
28
  }
@@ -329,6 +329,14 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
329
329
  this.timestampClock = Date.now();
330
330
  // ---- Transient UI state (stays as @observable on the component) ----
331
331
  this._suggestionsGeneration = 0;
332
+ /**
333
+ * Elements assigned to the `stepper` slot, tracked so the conversation container can say
334
+ * whether it is holding anything.
335
+ *
336
+ * Comment nodes and whitespace text are filtered out by the template's `slotted` filter, so an
337
+ * empty slot really is empty here and `hasStepper` does not go true for formatting whitespace.
338
+ */
339
+ this.stepperNodes = [];
332
340
  /** Whether the loading spinner is currently visible. Controlled by the loading delay timer. */
333
341
  this.showLoadingIndicator = false;
334
342
  /**
@@ -1442,6 +1450,16 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
1442
1450
  set attachmentErrors(value) {
1443
1451
  this.attachmentCtrl.errors = value;
1444
1452
  }
1453
+ /**
1454
+ * Whether anything is slotted alongside the conversation.
1455
+ *
1456
+ * Drives the `conversation-has-stepper` part, which is what lets an app apply a side-by-side
1457
+ * layout only when there is a second thing to lay out — a `flex-direction: row` that applied
1458
+ * unconditionally would do nothing visible but would still be live CSS to reason about.
1459
+ */
1460
+ get hasStepper() {
1461
+ return this.stepperNodes.length > 0;
1462
+ }
1445
1463
  /** Bump to re-render app settings toggles when the host provider notifies a change. */
1446
1464
  get appSettingsRevision() {
1447
1465
  return this.settings.appSettingsRevision;
@@ -4396,6 +4414,9 @@ __decorate([
4396
4414
  __decorate([
4397
4415
  volatile
4398
4416
  ], FoundationAiAssistant.prototype, "effectiveChatInputDuringExecution", null);
4417
+ __decorate([
4418
+ observable
4419
+ ], FoundationAiAssistant.prototype, "stepperNodes", void 0);
4399
4420
  __decorate([
4400
4421
  observable
4401
4422
  ], FoundationAiAssistant.prototype, "showLoadingIndicator", void 0);