@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,6 +1,31 @@
1
1
  import { __awaiter } from "tslib";
2
+ import { fieldKindOf } from './criteria';
2
3
  import { sameValue } from './value-compare';
4
+ import { aWrite, readsRow } from './write-op';
3
5
  import { buildEventPayload, isBlankEntry, PLATFORM_MAINTAINED, sendableFields, } from './write-payload';
6
+ /**
7
+ * The key a modify or a delete names its row by: the model's own, or, with a declared key (C-19),
8
+ * cut to those fields. Every declared field is asked for before anything is read, and anything
9
+ * else the model put in its key is let go, so it can neither steer the read nor read as a change
10
+ * to the row's own key.
11
+ */
12
+ function namedKey(op, named, keyFields) {
13
+ if ((op !== 'modify' && op !== 'delete') || !(keyFields === null || keyFields === void 0 ? void 0 : keyFields.length))
14
+ return { key: named };
15
+ const missing = keyFields.filter((field) => named[field] === undefined || isBlankEntry(named[field]));
16
+ if (missing.length) {
17
+ return {
18
+ problem: `${aWrite(op)} names its row by ${keyFields.join(', ')}; send ${missing.join(', ')} in key`,
19
+ };
20
+ }
21
+ return { key: Object.fromEntries(keyFields.map((field) => [field, named[field]])) };
22
+ }
23
+ /**
24
+ * A key's values as the row holds them, never as the model wrote them: a read can match a value
25
+ * the payload would send differently (an INT '010' finds row 8 and would write row 10), and the row
26
+ * the user approved is the row the read found.
27
+ */
28
+ const asTheRowHolds = (key, row) => Object.fromEntries(Object.keys(key).map((name) => [name, name in row ? row[name] : key[name]]));
4
29
  /**
5
30
  * A batch a person can actually read before approving it.
6
31
  *
@@ -16,7 +41,33 @@ const asRecord = (value) => value && typeof value === 'object' && !Array.isArray
16
41
  /** The key a modify or delete entry names its row by; `changes` carries what it wants set. */
17
42
  const keyOf = (entry) => asRecord(entry.key);
18
43
  /**
19
- * Builds what the review will show, reading the current row for every modify and delete.
44
+ * Why a run's inputs cannot be sent, before anything is read: every declared one present and not
45
+ * blank, and nothing else.
46
+ *
47
+ * @remarks
48
+ * Blank is the payload builder's own test, so a whitespace-only or zero-width value is refused here
49
+ * rather than reaching the builder, where a modify would have kept the row's value in its place.
50
+ * For a row action that is the hazard itself: a handler told to respond with the row's current
51
+ * price, as though the model had sent it (contracts C-18.7.6).
52
+ */
53
+ function inputProblems(given, declared) {
54
+ var _a;
55
+ if (given !== undefined && !asRecord(given)) {
56
+ return ['inputs must be an object of field names to values'];
57
+ }
58
+ const sent = (_a = asRecord(given)) !== null && _a !== void 0 ? _a : {};
59
+ const problems = declared
60
+ .filter((field) => sent[field] === undefined || isBlankEntry(sent[field]))
61
+ .map((field) => `input ${field} is required`);
62
+ const stray = Object.keys(sent).filter((name) => !declared.includes(name));
63
+ if (stray.length) {
64
+ problems.push(`${stray.join(', ')} ${stray.length > 1 ? 'are not inputs' : 'is not an input'} of this ` +
65
+ `handler. ${declared.length ? `Its inputs are: ${declared.join(', ')}` : 'It takes none'}`);
66
+ }
67
+ return problems;
68
+ }
69
+ /**
70
+ * Builds what the review will show, reading the current row for every modify, delete and row action.
20
71
  *
21
72
  * @remarks
22
73
  * Reads run together — they are reads, and a batch of 25 sequential round trips is a visibly
@@ -25,7 +76,17 @@ const keyOf = (entry) => asRecord(entry.key);
25
76
  * @internal
26
77
  */
27
78
  export function planWrite(rows_1, _a) {
28
- return __awaiter(this, arguments, void 0, function* (rows, { op, fields, source, unchecked }) {
79
+ return __awaiter(this, arguments, void 0, function* (rows, { op, fields, source, unchecked, keyFields, inputs }) {
80
+ // Without its key fields there is nothing to check the row's key against: refused, rather than
81
+ // run with the check skipped.
82
+ if (op === 'row-action' && !(keyFields === null || keyFields === void 0 ? void 0 : keyFields.length)) {
83
+ return { status: 'rejected', reason: 'This handler has no key to look its row up by.' };
84
+ }
85
+ // Nor without its inputs. Read as none, every input would be refused as "not an input", or,
86
+ // past that check, filled from the row as it stands. An empty list is a handler that takes none.
87
+ if (op === 'row-action' && !inputs) {
88
+ return { status: 'rejected', reason: 'This handler has no list of the inputs it takes.' };
89
+ }
29
90
  if (!Array.isArray(rows) || !rows.length) {
30
91
  return { status: 'rejected', reason: 'rows must be a non-empty list of rows to write.' };
31
92
  }
@@ -36,7 +97,7 @@ export function planWrite(rows_1, _a) {
36
97
  `${MAX_WRITE_ROWS} at a time.`,
37
98
  };
38
99
  }
39
- const needsRow = op === 'modify' || op === 'delete';
100
+ const needsRow = readsRow(op);
40
101
  // Shape first, so a bad entry costs no round trip and the reads that follow all have a key.
41
102
  const prepared = rows.map((entry, index) => {
42
103
  const given = asRecord(entry);
@@ -45,13 +106,17 @@ export function planWrite(rows_1, _a) {
45
106
  }
46
107
  if (!needsRow)
47
108
  return { index, given };
48
- const key = keyOf(given);
49
- if (!key) {
109
+ const named = keyOf(given);
110
+ if (!named) {
50
111
  return {
51
112
  index,
52
- problems: [`a ${op} names its row with key, e.g. {"key": {"TRADE_ID": "..."}}`],
113
+ problems: [`${aWrite(op)} names its row with key, e.g. {"key": {"TRADE_ID": "..."}}`],
53
114
  };
54
115
  }
116
+ const keyed = namedKey(op, named, keyFields);
117
+ if ('problem' in keyed)
118
+ return { index, key: named, problems: [keyed.problem] };
119
+ const { key } = keyed;
55
120
  // A modify has to SAY what changes, and is refused by name when it does not — the same way a
56
121
  // missing key is, one line up. `changes` used to fall back to `{}`, so a modify with none
57
122
  // (absent, not an object, or empty) merged nothing over the row, wrote it back UNCHANGED, and
@@ -68,8 +133,19 @@ export function planWrite(rows_1, _a) {
68
133
  ],
69
134
  };
70
135
  }
136
+ // A run sends its inputs, every one, and nothing else: refused before any read, so a row
137
+ // refused here has no pre-image, and its review shows only the problem (contracts C-18.R2).
138
+ if (op === 'row-action') {
139
+ const wrong = inputProblems(given.inputs, inputs !== null && inputs !== void 0 ? inputs : []);
140
+ if (wrong.length)
141
+ return { index, key, problems: wrong };
142
+ }
71
143
  if (!source) {
72
- return { index, key, problems: [`a ${op} needs a row to read, and none is configured`] };
144
+ return {
145
+ index,
146
+ key,
147
+ problems: [`${aWrite(op)} needs a row to read, and none is configured`],
148
+ };
73
149
  }
74
150
  return { index, given, key };
75
151
  });
@@ -82,7 +158,7 @@ export function planWrite(rows_1, _a) {
82
158
  return {
83
159
  status: 'ok',
84
160
  rows: prepared.map((entry, at) => {
85
- var _a;
161
+ var _a, _b;
86
162
  if (entry.problems)
87
163
  return { index: entry.index, key: entry.key, problems: entry.problems };
88
164
  if (!needsRow) {
@@ -143,6 +219,22 @@ export function planWrite(rows_1, _a) {
143
219
  };
144
220
  }
145
221
  seen.set(identity, entry.index);
222
+ // A run is built from the row as read with the inputs applied, and from nothing else. The
223
+ // search key is never merged in: it found the row, and the row's own key is what the handler
224
+ // looks it up by, so a search key naming an input cannot override the input (C-18.7.6).
225
+ if (op === 'row-action') {
226
+ const empty = (keyFields !== null && keyFields !== void 0 ? keyFields : []).filter((field) => read.row[field] == null);
227
+ const built = buildEventPayload(fields, (_a = asRecord(entry.given.inputs)) !== null && _a !== void 0 ? _a : {}, {
228
+ op,
229
+ preImage: read.row,
230
+ unchecked,
231
+ });
232
+ const problems = [
233
+ ...empty.map((field) => `the handler looks this row up by ${field}, which is empty`),
234
+ ...(built.status === 'rejected' ? built.problems : []),
235
+ ];
236
+ return Object.assign(Object.assign({ index: entry.index, key: entry.key, preImage: read.row }, (built.status === 'ok' ? { details: built.details } : {})), (problems.length ? { problems } : {}));
237
+ }
146
238
  // `changes` on a delete is meaningless: the row is the row. Ignored rather than refused,
147
239
  // so a model that sends one does not lose the whole batch over it. On a modify it has
148
240
  // already been checked above to be a non-empty object, so no default is needed here —
@@ -153,7 +245,7 @@ export function planWrite(rows_1, _a) {
153
245
  // generated handler it either creates a second record or fails, neither of which is what
154
246
  // a review of "change TR1's quantity" asked for. Said out loud rather than done quietly.
155
247
  const overridden = Object.keys(changes).filter((name) => name in entry.key && !sameValue(changes[name], entry.key[name]));
156
- const built = buildEventPayload(fields, Object.assign(Object.assign({}, changes), entry.key), {
248
+ const built = buildEventPayload(fields, Object.assign(Object.assign({}, changes), asTheRowHolds(entry.key, read.row)), {
157
249
  op,
158
250
  preImage: read.row,
159
251
  unchecked,
@@ -178,7 +270,7 @@ export function planWrite(rows_1, _a) {
178
270
  // "the row already has that value" is not the reason, and a model told so may report to
179
271
  // the user that it cleared the column. Said as it is instead.
180
272
  const blanked = op === 'modify'
181
- ? Object.entries((_a = asRecord(entry.given.changes)) !== null && _a !== void 0 ? _a : {})
273
+ ? Object.entries((_b = asRecord(entry.given.changes)) !== null && _b !== void 0 ? _b : {})
182
274
  .filter(([name, value]) => isBlankEntry(value) && read.row[name] != null)
183
275
  .map(([name]) => name)
184
276
  : [];
@@ -252,11 +344,28 @@ function rowIdentity(row) {
252
344
  * @internal
253
345
  */
254
346
  export function stillCurrent(row_1, _a) {
255
- return __awaiter(this, arguments, void 0, function* (row, { source, fields }) {
347
+ return __awaiter(this, arguments, void 0, function* (row, { source, fields, keyFields, }) {
256
348
  if (!row.key || !row.preImage) {
257
349
  return { status: 'unreadable', reason: 'it was never read in the first place' };
258
350
  }
259
- const read = yield source.read(row.key);
351
+ // The model's search key can name a field somebody changed while the review was open, and a row
352
+ // looked for by its old value reads as gone when it has only changed. A run is looked for by its
353
+ // own key, as the row held it.
354
+ // A DATE key field is the one exception: the row holds it as epoch millis, which a read does not
355
+ // match the way it matched the day the model sent, so that value is the one asked for again.
356
+ const preImage = row.preImage;
357
+ const asked = row.key;
358
+ const isDate = (name) => {
359
+ const field = fields.find((one) => one.name === name);
360
+ return !!field && fieldKindOf(field.type) === 'date';
361
+ };
362
+ const key = keyFields
363
+ ? Object.fromEntries(keyFields.map((name) => [
364
+ name,
365
+ isDate(name) && name in asked ? asked[name] : preImage[name],
366
+ ]))
367
+ : row.key;
368
+ const read = yield source.read(key);
260
369
  if (read.status === 'missing')
261
370
  return { status: 'gone' };
262
371
  if (read.status === 'ambiguous') {
@@ -1,6 +1,6 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { customElement, GenesisElement, observable } from '@genesislcap/web-core';
3
- import { canWrite, customCodeLine, initialSelection, restoredSelection, reviewDecisionOf, reviewOutcomeFrom, stoppedSummary, } from '../review-model';
3
+ import { canWrite, customCodeLine, initialSelection, restoredSelection, reviewDecisionOf, rowActionHeading, rowActionLines, reviewOutcomeFrom, stoppedSummary, } from '../review-model';
4
4
  import { MAX_FEEDBACK_CHARS, } from '../review-payload';
5
5
  import { isBlankText } from '../write-payload';
6
6
  import { WriteReviewStyles as styles } from './write-review.styles';
@@ -135,6 +135,25 @@ let GenesisWriteReview = class GenesisWriteReview extends GenesisElement {
135
135
  const model = this.model;
136
136
  return (model === null || model === void 0 ? void 0 : model.customCode) ? customCodeLine(model.op, model.customCode) : '';
137
137
  }
138
+ /** A row action's header, or `''` for any other write: see `rowActionHeading`. */
139
+ get rowActionHeading() {
140
+ const model = this.model;
141
+ return (model === null || model === void 0 ? void 0 : model.rowAction) ? rowActionHeading(model.rowAction, model.rows.length) : '';
142
+ }
143
+ /** The table's accessible name. A run's names its handler and table, as its header does. */
144
+ get tableLabel() {
145
+ var _a;
146
+ const model = this.model;
147
+ return (model === null || model === void 0 ? void 0 : model.rowAction)
148
+ ? `${model.rowAction.entity} rows to run ${model.rowAction.handler} on`
149
+ : `Rows to be written to ${(_a = model === null || model === void 0 ? void 0 : model.resource) !== null && _a !== void 0 ? _a : ''}`;
150
+ }
151
+ /** The lines under a row action's header, from the model, so a re-mount says them too. */
152
+ get rowActionLines() {
153
+ var _a;
154
+ const rowAction = (_a = this.model) === null || _a === void 0 ? void 0 : _a.rowAction;
155
+ return rowAction ? rowActionLines(rowAction) : [];
156
+ }
138
157
  /**
139
158
  * Whether the review is past taking input: it has resolved, or it has sent its answer. Every
140
159
  * action checks this rather than `resolved`, which is still false in between.
@@ -165,6 +165,20 @@ export const WriteReviewStyles = css `
165
165
  color: var(--neutral-foreground-hint);
166
166
  }
167
167
 
168
+ /*
169
+ * A row action's input is what its handler is given, not a change to the row, so it is labelled
170
+ * rather than marked as a diff. The label is text, so it reaches a screen reader as well.
171
+ */
172
+ .input-mark {
173
+ font-style: italic;
174
+ color: var(--neutral-foreground-hint);
175
+ padding-inline-end: calc(var(--design-unit, 4) * 1px);
176
+ }
177
+
178
+ .row-action p {
179
+ margin-block: calc(var(--design-unit, 4) * 1px);
180
+ }
181
+
168
182
  /* The empty placeholder: a style no row text can take, so a literal "(blank)" cannot pass for it. */
169
183
  .blank {
170
184
  font-style: italic;
@@ -4,6 +4,7 @@ import { MAX_FEEDBACK_CHARS } from '../review-payload';
4
4
  import { isBlankText } from '../write-payload';
5
5
  /** The custom-code line's id: the table is described by it, when there is one. */
6
6
  const CUSTOM_CODE_LINE_ID = 'custom-code';
7
+ const ROW_ACTION_LINES_ID = 'row-action-lines';
7
8
  /**
8
9
  * What a checkbox says NOW, read from the event rather than inferred from the state.
9
10
  *
@@ -84,7 +85,7 @@ const cell = html `
84
85
  class="${(x) => [x.changed ? 'changed' : '', x.identifying ? 'identifying' : '', x.long ? 'long' : '']
85
86
  .join(' ')
86
87
  .trim()}"
87
- title="${(x) => (x.identifying ? 'This field identifies the row being removed' : '')}"
88
+ title="${(x) => { var _a; return x.identifying ? `This field identifies ${(_a = x.identifies) !== null && _a !== void 0 ? _a : 'the row being removed'}` : ''; }}"
88
89
  >
89
90
  ${when((x) => x.identifying, html `
90
91
  <span class="sr-only">identifies this row:</span>
@@ -95,6 +96,9 @@ const cell = html `
95
96
  <span class="sr-only">now</span>
96
97
  <span class="now">${mark('+')}${valueOrBlank((x) => x.display)}</span>
97
98
  `)}
99
+ ${when((x) => !!x.input, html `
100
+ <span class="input-mark">input:</span>
101
+ `)}
98
102
  ${when((x) => !(x.changed && x.previousDisplay !== undefined), html `
99
103
  ${(x) => x.display}
100
104
  `)}
@@ -136,17 +140,31 @@ const row = html `
136
140
  `;
137
141
  export const WriteReviewTemplate = html `
138
142
  ${when((x) => !!x.model, html `
139
- <p>
140
- ${(x) => { var _a; return (_a = x.model) === null || _a === void 0 ? void 0 : _a.op; }} ${(x) => { var _a; return (_a = x.model) === null || _a === void 0 ? void 0 : _a.rows.length; }} row(s) in ${(x) => { var _a; return (_a = x.model) === null || _a === void 0 ? void 0 : _a.resource; }}.
141
- Nothing is written until you choose rows and select Write.
142
- </p>
143
+ ${when((x) => !x.rowActionHeading, html `
144
+ <p>
145
+ ${(x) => { var _a; return (_a = x.model) === null || _a === void 0 ? void 0 : _a.op; }} ${(x) => { var _a; return (_a = x.model) === null || _a === void 0 ? void 0 : _a.rows.length; }} row(s) in
146
+ ${(x) => { var _a; return (_a = x.model) === null || _a === void 0 ? void 0 : _a.resource; }}. Nothing is written until you choose rows and select Write.
147
+ </p>
148
+ `)}
149
+ ${when((x) => !!x.rowActionHeading, html `
150
+ <p class="row-action-heading">${(x) => x.rowActionHeading}</p>
151
+ <div class="row-action" id="${ROW_ACTION_LINES_ID}">
152
+ ${repeat((x) => x.rowActionLines, html `
153
+ <p>${(x) => x}</p>
154
+ `)}
155
+ </div>
156
+ `)}
143
157
  ${when((x) => !!x.customCodeLine, html `
144
158
  <p class="custom-code" id="${CUSTOM_CODE_LINE_ID}">${(x) => x.customCodeLine}</p>
145
159
  `)}
146
160
  <div class="scroller">
147
161
  <table
148
- aria-label="Rows to be written to ${(x) => { var _a; return (_a = x.model) === null || _a === void 0 ? void 0 : _a.resource; }}"
149
- aria-describedby="${(x) => (x.customCodeLine ? CUSTOM_CODE_LINE_ID : undefined)}"
162
+ aria-label="${(x) => x.tableLabel}"
163
+ aria-describedby="${(x) => x.customCodeLine
164
+ ? CUSTOM_CODE_LINE_ID
165
+ : x.rowActionHeading
166
+ ? ROW_ACTION_LINES_ID
167
+ : undefined}"
150
168
  >
151
169
  <thead>
152
170
  <tr>