@genesislcap/ai-assistant 15.46.5 → 15.47.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.
- package/dist/custom-elements.json +426 -214
- package/dist/dts/genesis/config.d.ts +30 -6
- package/dist/dts/genesis/config.d.ts.map +1 -1
- package/dist/dts/genesis/consumes.d.ts.map +1 -1
- package/dist/dts/genesis/event-fields.d.ts.map +1 -1
- package/dist/dts/genesis/filter-fields.d.ts +31 -0
- package/dist/dts/genesis/filter-fields.d.ts.map +1 -1
- package/dist/dts/genesis/index.d.ts +3 -1
- package/dist/dts/genesis/index.d.ts.map +1 -1
- package/dist/dts/genesis/reference-check.d.ts +83 -0
- package/dist/dts/genesis/reference-check.d.ts.map +1 -0
- package/dist/dts/genesis/reference-existence.d.ts +110 -0
- package/dist/dts/genesis/reference-existence.d.ts.map +1 -0
- package/dist/dts/genesis/resource-tools.d.ts +4 -4
- package/dist/dts/genesis/resource-tools.d.ts.map +1 -1
- package/dist/dts/genesis/review-model.d.ts +2 -2
- package/dist/dts/genesis/review-model.d.ts.map +1 -1
- package/dist/dts/genesis/row-source.d.ts +32 -0
- package/dist/dts/genesis/row-source.d.ts.map +1 -1
- package/dist/dts/genesis/server-text.d.ts +29 -0
- package/dist/dts/genesis/server-text.d.ts.map +1 -1
- package/dist/dts/genesis/types.d.ts +32 -5
- package/dist/dts/genesis/types.d.ts.map +1 -1
- package/dist/dts/genesis/write-payload.d.ts +14 -1
- package/dist/dts/genesis/write-payload.d.ts.map +1 -1
- package/dist/dts/genesis/write-plan.d.ts +8 -2
- package/dist/dts/genesis/write-plan.d.ts.map +1 -1
- package/dist/dts/genesis/write-tools.d.ts +5 -3
- package/dist/dts/genesis/write-tools.d.ts.map +1 -1
- package/dist/dts/genesis/write-turn.d.ts +4 -1
- package/dist/dts/genesis/write-turn.d.ts.map +1 -1
- package/dist/esm/genesis/config.js +152 -20
- package/dist/esm/genesis/consumes.js +2 -1
- package/dist/esm/genesis/event-fields.js +5 -8
- package/dist/esm/genesis/filter-fields.js +159 -78
- package/dist/esm/genesis/index.js +1 -0
- package/dist/esm/genesis/reference-check.js +132 -0
- package/dist/esm/genesis/reference-existence.js +283 -0
- package/dist/esm/genesis/resource-tools.js +135 -18
- package/dist/esm/genesis/review-model.js +3 -1
- package/dist/esm/genesis/row-source.js +107 -16
- package/dist/esm/genesis/server-text.js +52 -0
- package/dist/esm/genesis/write-payload.js +32 -4
- package/dist/esm/genesis/write-plan.js +3 -2
- package/dist/esm/genesis/write-tools.js +248 -44
- package/dist/genesis-consumes.cjs +3 -2
- package/dist/genesis-consumes.cjs.map +2 -2
- package/dist/genesis-consumes.mjs +3 -2
- package/dist/genesis-consumes.mjs.map +2 -2
- package/docs/genesis.md +131 -21
- package/package.json +17 -17
- package/scripts/smoke-genesis-consumes-node.mjs +2 -2
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { __awaiter } from "tslib";
|
|
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, opFromName, toolNameOf } from './config';
|
|
4
|
+
import { capIsReadable, customCodeOf, firstPerToolName, opFromName, referencesProblems, toolNameOf, } from './config';
|
|
5
5
|
import { fieldKindOf as criteriaKindOf } from './criteria';
|
|
6
6
|
import { loadEventFields } from './event-fields';
|
|
7
|
+
import { cannotBeChanged, createReferenceGate, notAcceptedHere, } from './reference-check';
|
|
8
|
+
import { asksOf, checkedLine, checkedSentences, checkReferences, referencesNow, withReferenceProblems, } from './reference-existence';
|
|
7
9
|
import { GENESIS_DATA_SOURCE } from './resource-tools';
|
|
8
10
|
import { buildReviewModel, reviewDecisionOf, selectedRows, } from './review-model';
|
|
9
11
|
import { MAX_FEEDBACK_CHARS } from './review-payload';
|
|
@@ -172,7 +174,13 @@ function propertyFor(field) {
|
|
|
172
174
|
: { type: 'string' };
|
|
173
175
|
}
|
|
174
176
|
}
|
|
175
|
-
|
|
177
|
+
/** A property with the sentence for a checked reference after any description it has. */
|
|
178
|
+
const withSentence = (property, sentence) => sentence
|
|
179
|
+
? Object.assign(Object.assign({}, property), { description: property.description ? `${property.description} ${sentence}` : sentence }) : property;
|
|
180
|
+
const objectOf = (fields, required, sentences = new Map()) => (Object.assign(Object.assign({ type: 'object', properties: Object.fromEntries(fields.map((field) => [
|
|
181
|
+
field.name,
|
|
182
|
+
withSentence(propertyFor(field), sentences.get(field.name)),
|
|
183
|
+
])) }, (required.length ? { required: [...required] } : {})), { additionalProperties: false }));
|
|
176
184
|
/** The row shape each op takes: values for an insert, a key (and changes) for the rest. */
|
|
177
185
|
/**
|
|
178
186
|
* The event fields a row can be found by: the ones the row source can match by EQUALITY.
|
|
@@ -199,10 +207,14 @@ const keyFieldsOf = (fields, keyable) => fields
|
|
|
199
207
|
* @param keyable - The row source's filter fields. Empty unless given, so a caller that forgets
|
|
200
208
|
* it offers no key at all rather than falling back to the event's own fields.
|
|
201
209
|
*/
|
|
202
|
-
function rowSchema(fields, op, keyable = new Map()
|
|
203
|
-
|
|
210
|
+
function rowSchema(fields, op, keyable = new Map(),
|
|
211
|
+
// Required: a default would offer every field, checked or not.
|
|
212
|
+
references) {
|
|
213
|
+
// A value whose reference cannot be checked is not offered: see reference-check.ts.
|
|
214
|
+
const writable = writableFields(fields, op).filter((field) => !references.unchecked.has(field.name));
|
|
215
|
+
const sentences = checkedSentences(references.checkable);
|
|
204
216
|
if (op === 'insert' || op === 'custom') {
|
|
205
|
-
return objectOf(writable, writable.filter((field) => !field.optional).map((field) => field.name));
|
|
217
|
+
return objectOf(writable, writable.filter((field) => !field.optional).map((field) => field.name), sentences);
|
|
206
218
|
}
|
|
207
219
|
const key = {
|
|
208
220
|
type: 'object',
|
|
@@ -216,7 +228,7 @@ function rowSchema(fields, op, keyable = new Map()) {
|
|
|
216
228
|
type: 'object',
|
|
217
229
|
properties: {
|
|
218
230
|
key,
|
|
219
|
-
changes: Object.assign(Object.assign({}, objectOf(writable, [])), { description: 'Only the fields to change. Everything else keeps the value it has now. An empty ' +
|
|
231
|
+
changes: Object.assign(Object.assign({}, objectOf(writable, [], sentences)), { description: 'Only the fields to change. Everything else keeps the value it has now. An empty ' +
|
|
220
232
|
'string or null also leaves a field as it is: this tool cannot clear a column.' }),
|
|
221
233
|
},
|
|
222
234
|
required: ['key', 'changes'],
|
|
@@ -233,14 +245,27 @@ const WHAT_IT_DOES = {
|
|
|
233
245
|
modify: 'Changes rows in',
|
|
234
246
|
delete: 'Removes rows from',
|
|
235
247
|
};
|
|
236
|
-
function writeDefinition(resource, op, fields, keyable
|
|
248
|
+
function writeDefinition(resource, op, fields, keyable,
|
|
249
|
+
// Required, for the reason rowSchema's is.
|
|
250
|
+
references) {
|
|
251
|
+
const notOffered = [...references.unchecked.keys()].join(', ');
|
|
252
|
+
const checked = checkedLine(references.checkable);
|
|
237
253
|
return {
|
|
238
254
|
name: toolNameOf(resource.name),
|
|
239
255
|
description: `${resource.context}\n\n` +
|
|
256
|
+
(checked ? `${checked}\n\n` : '') +
|
|
240
257
|
`${WHAT_IT_DOES[op]} ${resource.name}. Nothing is written until the user has read the ` +
|
|
241
258
|
'rows in a review and approved them, one by one — so propose the whole change and let ' +
|
|
242
259
|
'them decide, rather than asking in chat first. The result says what happened to each ' +
|
|
243
|
-
'row; read it rather than assuming the write succeeded.'
|
|
260
|
+
'row; read it rather than assuming the write succeeded.' +
|
|
261
|
+
(notOffered
|
|
262
|
+
? op === 'modify'
|
|
263
|
+
? ` ${notOffered} cannot be changed here: each must match a row of another table, ` +
|
|
264
|
+
'which cannot be checked in this app.'
|
|
265
|
+
: ` ${notOffered} ${references.unchecked.size > 1 ? 'are' : 'is'} not accepted here: ` +
|
|
266
|
+
'each must match a row of another table, ' +
|
|
267
|
+
'which cannot be checked in this app.'
|
|
268
|
+
: ''),
|
|
244
269
|
parameters: {
|
|
245
270
|
type: 'object',
|
|
246
271
|
properties: {
|
|
@@ -251,7 +276,7 @@ function writeDefinition(resource, op, fields, keyable) {
|
|
|
251
276
|
// by being refused.
|
|
252
277
|
minItems: 1,
|
|
253
278
|
maxItems: MAX_WRITE_ROWS,
|
|
254
|
-
items: rowSchema(fields, op, keyable),
|
|
279
|
+
items: rowSchema(fields, op, keyable, references),
|
|
255
280
|
},
|
|
256
281
|
},
|
|
257
282
|
required: ['rows'],
|
|
@@ -393,15 +418,19 @@ const locksOf = (resources, decide, sourceNameOf) => {
|
|
|
393
418
|
*/
|
|
394
419
|
function configRules(resources, options) {
|
|
395
420
|
var _a, _b;
|
|
396
|
-
const
|
|
397
|
-
|
|
398
|
-
.sort((a, b) => a.name.localeCompare(b.name));
|
|
421
|
+
const allEvents = resources.filter((r) => r.kind === 'event');
|
|
422
|
+
const events = firstPerToolName(allEvents).sort((a, b) => a.name.localeCompare(b.name));
|
|
399
423
|
const requests = resources.filter((r) => r.kind === 'request');
|
|
400
424
|
// The requests the assistant can read: one whose cap cannot be read gets no read tool, and so is
|
|
401
425
|
// no row source either (see capIsReadable).
|
|
402
426
|
const requestNames = new Set(requests.filter(capIsReadable).map((r) => r.name));
|
|
403
427
|
const unreadable = new Set(requests.filter((r) => !capIsReadable(r)).map((r) => r.name));
|
|
404
|
-
const
|
|
428
|
+
const queryNames = new Set(resources.filter((r) => r.kind === 'query').map((r) => r.name));
|
|
429
|
+
// An event that lost its tool name to an earlier one is left out too, and was said so.
|
|
430
|
+
const leftOut = new Set([
|
|
431
|
+
...((_a = options.leftOut) !== null && _a !== void 0 ? _a : []),
|
|
432
|
+
...allEvents.filter((r) => !events.includes(r)).map((r) => r.name),
|
|
433
|
+
]);
|
|
405
434
|
// An entry for no event these tools were given does nothing, and whoever wrote it believes it
|
|
406
435
|
// does: a misspelt key most of all. Said here, once, so a direct call hears it as registration
|
|
407
436
|
// does (contracts C-15A.4: ignored with a warning that names it).
|
|
@@ -465,12 +494,16 @@ function configRules(resources, options) {
|
|
|
465
494
|
*/
|
|
466
495
|
const decide = (resource) => {
|
|
467
496
|
const decided = decideOp(resource);
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
497
|
+
// The references rule the validator applies, here as well because a direct call skips it.
|
|
498
|
+
const malformed = referencesProblems(resource, decided.refused ? resource.op : decided.op);
|
|
499
|
+
const reasons = [
|
|
500
|
+
decided.refused,
|
|
501
|
+
rowSourceRefusal(resource.name),
|
|
502
|
+
malformed.length ? `its references are malformed: ${malformed.join('; ')}` : undefined,
|
|
503
|
+
].filter((reason) => !!reason);
|
|
504
|
+
// Every reason that holds: the op's alone would leave a wrong rowSources entry unsaid, to come
|
|
505
|
+
// back as a refusal the day the op is fixed.
|
|
506
|
+
return reasons.length ? { refused: reasons.join('; and ') } : decided;
|
|
474
507
|
};
|
|
475
508
|
/**
|
|
476
509
|
* Why a modify or delete has no row source: said when its tool is withheld and by its handler.
|
|
@@ -488,6 +521,10 @@ function configRules(resources, options) {
|
|
|
488
521
|
'there is nothing to read its rows from' +
|
|
489
522
|
(forConsole ? '. The warning that names it says why' : ''));
|
|
490
523
|
}
|
|
524
|
+
if (derived && queryNames.has(derived)) {
|
|
525
|
+
return (`${derived} is a query in the AI config, not its table's own request resource, and a ` +
|
|
526
|
+
'query is never a row source');
|
|
527
|
+
}
|
|
491
528
|
return derived
|
|
492
529
|
? `the app exposes no request resource to read its rows from. Add ${derived} to the AI config`
|
|
493
530
|
: 'its name does not end in _MODIFY or _DELETE, so there is no table to read its rows from';
|
|
@@ -532,8 +569,64 @@ function configRules(resources, options) {
|
|
|
532
569
|
logger.warn(`Genesis assistant: ${resource.name} has no write tool because ` +
|
|
533
570
|
`${(_b = decided.refused) !== null && _b !== void 0 ? _b : whyNoSource(resource.name, true)}.`);
|
|
534
571
|
}
|
|
572
|
+
// A config older than references, or a table the generator had no fields for: nothing is
|
|
573
|
+
// checked, as before, and said once here rather than on every turn (contracts C-17.6).
|
|
574
|
+
if (!decided.refused &&
|
|
575
|
+
(decided.op === 'insert' || decided.op === 'modify') &&
|
|
576
|
+
resource.references === undefined) {
|
|
577
|
+
logger.warn(`Genesis assistant: ${resource.name} declares no references; values that must match ` +
|
|
578
|
+
'another table are not checked before the review.');
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
return { events, decide, whyNoSource, readsFrom, writable, requestNames };
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Runs an event's reference gate for its tool, which the gate can withhold: `undefined` when the
|
|
585
|
+
* event has no tool this turn. An insert whose required reference cannot be checked joins
|
|
586
|
+
* `skipped` for good. Only the gate is guarded: a throw costs the event this turn, and it is
|
|
587
|
+
* asked again on the next.
|
|
588
|
+
*/
|
|
589
|
+
function gateForTool(name, gate, skipped, said) {
|
|
590
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
591
|
+
let references;
|
|
592
|
+
try {
|
|
593
|
+
references = yield gate();
|
|
594
|
+
}
|
|
595
|
+
catch (error) {
|
|
596
|
+
if (!said.failed.has(name)) {
|
|
597
|
+
said.failed.add(name);
|
|
598
|
+
logger.error(`Genesis assistant: ${name} reference check threw`, error);
|
|
599
|
+
logger.warn(`Genesis assistant: ${name} has no write tool for now: checking its references failed. ` +
|
|
600
|
+
'It will be asked again.');
|
|
601
|
+
}
|
|
602
|
+
return undefined;
|
|
603
|
+
}
|
|
604
|
+
if (references.noTool) {
|
|
605
|
+
skipped.add(name);
|
|
606
|
+
logger.warn(`Genesis assistant: ${name} has no write tool because ${references.noTool}.`);
|
|
607
|
+
return undefined;
|
|
608
|
+
}
|
|
609
|
+
if (references.transient) {
|
|
610
|
+
if (!said.waiting.has(name)) {
|
|
611
|
+
said.waiting.add(name);
|
|
612
|
+
logger.warn(`Genesis assistant: ${name} has no write tool yet because ${references.transient}; it ` +
|
|
613
|
+
'will be asked again.');
|
|
614
|
+
}
|
|
615
|
+
return undefined;
|
|
616
|
+
}
|
|
617
|
+
return references;
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
/** Each field whose reference cannot be checked, as `F → REQ_T (reason)`. */
|
|
621
|
+
const uncheckedNames = (unchecked) => [...unchecked]
|
|
622
|
+
.map(([field, { resource, reason }]) => `${field} → ${resource} (${reason})`)
|
|
623
|
+
.join('; ');
|
|
624
|
+
/** Says, for a settled tool, each field left out of it and why. */
|
|
625
|
+
function warnUnchecked(name, op, unchecked) {
|
|
626
|
+
for (const [field, why] of unchecked) {
|
|
627
|
+
logger.warn(`Genesis assistant: ${name}: ` +
|
|
628
|
+
(op === 'modify' ? cannotBeChanged(field, why) : notAcceptedHere(field, why)));
|
|
535
629
|
}
|
|
536
|
-
return { events, decide, whyNoSource, readsFrom, writable };
|
|
537
630
|
}
|
|
538
631
|
/**
|
|
539
632
|
* Builds the assistant's write tools from an app's event resources.
|
|
@@ -542,7 +635,9 @@ function configRules(resources, options) {
|
|
|
542
635
|
*/
|
|
543
636
|
export function createGenesisWriteTools(resources, options = {}) {
|
|
544
637
|
var _a;
|
|
545
|
-
const { events, decide, whyNoSource, readsFrom, writable } = configRules(resources, options);
|
|
638
|
+
const { events, decide, whyNoSource, readsFrom, writable, requestNames } = configRules(resources, options);
|
|
639
|
+
const referenceGate = createReferenceGate(requestNames, options.timeouts);
|
|
640
|
+
const gateNotices = { failed: new Set(), waiting: new Set() };
|
|
546
641
|
const resolveConnect = () => connectOf(options);
|
|
547
642
|
const sources = new Map();
|
|
548
643
|
const lockOf = locksOf(resources, decide, readsFrom);
|
|
@@ -640,16 +735,29 @@ export function createGenesisWriteTools(resources, options = {}) {
|
|
|
640
735
|
const fields = yield loadFields(resource, connect);
|
|
641
736
|
if (!fields)
|
|
642
737
|
return;
|
|
738
|
+
// Whether its references can be checked comes first: it can withhold the tool, and it
|
|
739
|
+
// decides which fields are offered at all.
|
|
740
|
+
const references = yield gateForTool(resource.name, () => referenceGate(resource, decided.op, fields, connect), skipped, gateNotices);
|
|
741
|
+
if (!references)
|
|
742
|
+
return;
|
|
743
|
+
const unchecked = new Set(references.unchecked.keys());
|
|
643
744
|
// An insert or a modify with nothing a model may SET could never be built: every
|
|
644
|
-
// call would be refused. Its fields are all key, platform-maintained,
|
|
645
|
-
// No tool, and the console says why. A delete is
|
|
646
|
-
// it sends the row's key.
|
|
745
|
+
// call would be refused. Its fields are all key, platform-maintained, carry-only, or
|
|
746
|
+
// a reference that cannot be checked. No tool, and the console says why. A delete is
|
|
747
|
+
// exempt by design: it sets nothing, it sends the row's key.
|
|
748
|
+
const settable = decided.op === 'insert' || decided.op === 'modify'
|
|
749
|
+
? writableFields(fields, decided.op)
|
|
750
|
+
: [];
|
|
647
751
|
if ((decided.op === 'insert' || decided.op === 'modify') &&
|
|
648
|
-
!
|
|
752
|
+
!settable.filter((field) => !unchecked.has(field.name)).length) {
|
|
649
753
|
skipped.add(resource.name);
|
|
650
|
-
logger.warn(
|
|
651
|
-
|
|
652
|
-
|
|
754
|
+
logger.warn(settable.length
|
|
755
|
+
? `Genesis assistant: ${resource.name} has no write tool because every field ` +
|
|
756
|
+
"it could set must match another table's row, and none of them can be " +
|
|
757
|
+
`checked here: ${uncheckedNames(references.unchecked)}.`
|
|
758
|
+
: `Genesis assistant: ${resource.name} has no write tool because it has no ` +
|
|
759
|
+
'field a model may set: each one is its key, maintained by the platform, ' +
|
|
760
|
+
'or a NANO_TIMESTAMP this assistant does not set.');
|
|
653
761
|
return;
|
|
654
762
|
}
|
|
655
763
|
const unsettable = decided.op === 'insert' ? requiredCarryOnly(fields) : [];
|
|
@@ -694,7 +802,9 @@ export function createGenesisWriteTools(resources, options = {}) {
|
|
|
694
802
|
return;
|
|
695
803
|
}
|
|
696
804
|
}
|
|
697
|
-
settled
|
|
805
|
+
// Said once: a settled event is not decided again.
|
|
806
|
+
warnUnchecked(resource.name, decided.op, references.unchecked);
|
|
807
|
+
settled.set(resource.name, writeDefinition(resource, decided.op, fields, keyable, references));
|
|
698
808
|
})));
|
|
699
809
|
return events
|
|
700
810
|
.map((resource) => settled.get(resource.name))
|
|
@@ -718,6 +828,7 @@ export function createGenesisWriteTools(resources, options = {}) {
|
|
|
718
828
|
decide,
|
|
719
829
|
loadFields,
|
|
720
830
|
coverage,
|
|
831
|
+
referenceGate,
|
|
721
832
|
timeouts: options.timeouts,
|
|
722
833
|
turns,
|
|
723
834
|
feedbackKey,
|
|
@@ -832,11 +943,28 @@ function runWrite(resource, args, context, deps) {
|
|
|
832
943
|
`${covered.missing.join(', ')}. Writing without those would set them empty.`);
|
|
833
944
|
}
|
|
834
945
|
}
|
|
835
|
-
|
|
946
|
+
// The definition's reference gate again, for the reason `coverage` is repeated above.
|
|
947
|
+
const references = yield referencesForRun(resource, op, fields, connect, deps.referenceGate);
|
|
948
|
+
if ('error' in references)
|
|
949
|
+
return fail(references.error, references.message);
|
|
950
|
+
const plan = yield planWrite(args.rows, { op, fields, source, unchecked: references.unchecked });
|
|
836
951
|
if (plan.status === 'rejected')
|
|
837
952
|
return fail('rejected', plan.reason);
|
|
953
|
+
// Whether each reference a row sets names a row that exists. Before the proposal is taken, so a
|
|
954
|
+
// refusal is part of what an unchanged re-proposal is compared on (see reference-existence.ts).
|
|
955
|
+
const checked = yield withReferencesChecked(plan.rows, {
|
|
956
|
+
op,
|
|
957
|
+
fields,
|
|
958
|
+
checkable: references.checkable,
|
|
959
|
+
connect,
|
|
960
|
+
signal: context.turnSignal,
|
|
961
|
+
timeouts: deps.timeouts,
|
|
962
|
+
});
|
|
963
|
+
if ('error' in checked)
|
|
964
|
+
return fail(checked.error, checked.message);
|
|
965
|
+
const planned = checked.rows;
|
|
838
966
|
// What the identical check below compares: see write-turn.ts.
|
|
839
|
-
const proposal = proposalOf(op,
|
|
967
|
+
const proposal = proposalOf(op, planned, fields);
|
|
840
968
|
// Every column the review will RENDER needs a type, and for a delete that is more than the
|
|
841
969
|
// event declares: it shows the whole row, including columns the event never mentions, and
|
|
842
970
|
// without a type a date is shown to the approver as raw epoch millis — `1789948800000` is not
|
|
@@ -868,7 +996,7 @@ function runWrite(resource, args, context, deps) {
|
|
|
868
996
|
// for them would show a user a blank for something no write touches — plus, for a delete,
|
|
869
997
|
// the ones it merely shows.
|
|
870
998
|
fields: shownFields,
|
|
871
|
-
rows:
|
|
999
|
+
rows: planned.map((row) => {
|
|
872
1000
|
var _a;
|
|
873
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 }));
|
|
874
1002
|
}),
|
|
@@ -894,7 +1022,7 @@ function runWrite(resource, args, context, deps) {
|
|
|
894
1022
|
};
|
|
895
1023
|
})
|
|
896
1024
|
: fields;
|
|
897
|
-
const byIndex = new Map(
|
|
1025
|
+
const byIndex = new Map(planned.map((row) => [row.index, row]));
|
|
898
1026
|
const refused = (row) => {
|
|
899
1027
|
var _a;
|
|
900
1028
|
return ({
|
|
@@ -959,7 +1087,7 @@ function runWrite(resource, args, context, deps) {
|
|
|
959
1087
|
turn.lastAsked = read.decision === 'changes_requested' ? proposal : undefined;
|
|
960
1088
|
}
|
|
961
1089
|
if (read.decision !== 'approved') {
|
|
962
|
-
return declinedResult(resource.name,
|
|
1090
|
+
return declinedResult(resource.name, planned, read, turn.changeRequests, deps.feedbackKey, lock);
|
|
963
1091
|
}
|
|
964
1092
|
// Indexes, never rows: what the review hands back cannot be a payload, so `selectedRows`
|
|
965
1093
|
// reads the objects the table rendered out of the model itself — and re-applies the rule that
|
|
@@ -967,7 +1095,7 @@ function runWrite(resource, args, context, deps) {
|
|
|
967
1095
|
const chosen = new Set(read.rows);
|
|
968
1096
|
const approved = selectedRows(model, chosen);
|
|
969
1097
|
const lines = new Map();
|
|
970
|
-
for (const row of
|
|
1098
|
+
for (const row of planned) {
|
|
971
1099
|
if ((_e = row.problems) === null || _e === void 0 ? void 0 : _e.length)
|
|
972
1100
|
lines.set(row.index, refused(row));
|
|
973
1101
|
else if (!chosen.has(row.index)) {
|
|
@@ -985,11 +1113,13 @@ function runWrite(resource, args, context, deps) {
|
|
|
985
1113
|
byIndex,
|
|
986
1114
|
source,
|
|
987
1115
|
checkedFields,
|
|
1116
|
+
fields,
|
|
1117
|
+
checkable: references.checkable,
|
|
988
1118
|
connect,
|
|
989
1119
|
commitMs: (_f = deps.timeouts) === null || _f === void 0 ? void 0 : _f.commitMs,
|
|
990
1120
|
turnSignal: context.turnSignal,
|
|
991
1121
|
});
|
|
992
|
-
const rows =
|
|
1122
|
+
const rows = planned.map((row) => {
|
|
993
1123
|
var _a;
|
|
994
1124
|
return (_a = lines.get(row.index)) !== null && _a !== void 0 ? _a : {
|
|
995
1125
|
index: row.index,
|
|
@@ -1013,6 +1143,60 @@ const reviewOutcomeOf = (rows, approved, stopped) => {
|
|
|
1013
1143
|
.map(({ index, status, message }) => ({ index, status, message })),
|
|
1014
1144
|
};
|
|
1015
1145
|
};
|
|
1146
|
+
/**
|
|
1147
|
+
* The definition's reference gate, run again for a call: what it means for the write, or why the
|
|
1148
|
+
* call is refused when it withholds the tool.
|
|
1149
|
+
*/
|
|
1150
|
+
function referencesForRun(resource, op, fields, connect, gate) {
|
|
1151
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1152
|
+
let references;
|
|
1153
|
+
try {
|
|
1154
|
+
references = yield gate(resource, op, fields, connect);
|
|
1155
|
+
}
|
|
1156
|
+
catch (_a) {
|
|
1157
|
+
return {
|
|
1158
|
+
error: 'request_failed',
|
|
1159
|
+
message: `${resource.name}'s references could not be checked, so nothing was sent.`,
|
|
1160
|
+
};
|
|
1161
|
+
}
|
|
1162
|
+
if (references.noTool) {
|
|
1163
|
+
return {
|
|
1164
|
+
error: 'rejected',
|
|
1165
|
+
message: `${resource.name} cannot be written: ${references.noTool}. Nothing was sent.`,
|
|
1166
|
+
};
|
|
1167
|
+
}
|
|
1168
|
+
if (references.transient) {
|
|
1169
|
+
return {
|
|
1170
|
+
error: 'request_failed',
|
|
1171
|
+
message: `${resource.name} cannot be written right now: ${references.transient}, so its ` +
|
|
1172
|
+
'references cannot be checked. Nothing was sent.',
|
|
1173
|
+
};
|
|
1174
|
+
}
|
|
1175
|
+
return references;
|
|
1176
|
+
});
|
|
1177
|
+
}
|
|
1178
|
+
/**
|
|
1179
|
+
* The rows with what the reference reads found added to their problems, or why the whole call is
|
|
1180
|
+
* refused: a Stop, more values than one review may check, or the connection lost while reading.
|
|
1181
|
+
*/
|
|
1182
|
+
function withReferencesChecked(rows, _a) {
|
|
1183
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1184
|
+
var { timeouts } = _a, options = __rest(_a, ["timeouts"]);
|
|
1185
|
+
const checked = yield checkReferences(rows, Object.assign(Object.assign({}, options), { deadlineMs: timeouts === null || timeouts === void 0 ? void 0 : timeouts.readMs }));
|
|
1186
|
+
if (checked.status === 'stopped')
|
|
1187
|
+
return { error: 'rejected', message: STOPPED_BEFORE_REVIEW };
|
|
1188
|
+
if (checked.status === 'refused')
|
|
1189
|
+
return { error: 'rejected', message: checked.reason };
|
|
1190
|
+
if (checked.status === 'not_connected') {
|
|
1191
|
+
return {
|
|
1192
|
+
error: 'not_connected',
|
|
1193
|
+
message: 'The app lost its connection while the references were being checked. Nothing was ' +
|
|
1194
|
+
'shown or written.',
|
|
1195
|
+
};
|
|
1196
|
+
}
|
|
1197
|
+
return { rows: withReferenceProblems(rows, checked.problems) };
|
|
1198
|
+
});
|
|
1199
|
+
}
|
|
1016
1200
|
/**
|
|
1017
1201
|
* Re-checks and commits the approved rows ONE AT A TIME, in order, recording each outcome in
|
|
1018
1202
|
* `lines`.
|
|
@@ -1042,18 +1226,38 @@ function commitApproved(approved, lines, run) {
|
|
|
1042
1226
|
if (stoppedAt(row.index))
|
|
1043
1227
|
continue;
|
|
1044
1228
|
const planned = run.byIndex.get(row.index);
|
|
1045
|
-
|
|
1229
|
+
const readsRow = run.op === 'modify' || run.op === 'delete';
|
|
1230
|
+
// The same references the review checked, from the same frozen payload and pre-image.
|
|
1231
|
+
const asks = planned ? asksOf(planned, run.op, run.fields, run.checkable).asks : [];
|
|
1232
|
+
if (readsRow || asks.length) {
|
|
1046
1233
|
// A check run early is a check of a row that may since have moved: it has to run against
|
|
1047
|
-
// the row as it is at the moment of writing, which is the whole point of interleaving.
|
|
1234
|
+
// the row as it is at the moment of writing, which is the whole point of interleaving. Its
|
|
1235
|
+
// references are read beside it, not after it, so the window stays one round trip.
|
|
1048
1236
|
// oxlint-disable-next-line no-await-in-loop -- each row is checked as it is written
|
|
1049
|
-
const outcome = yield
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1237
|
+
const [outcome, references] = yield Promise.all([
|
|
1238
|
+
readsRow
|
|
1239
|
+
? stillCurrent(planned, { source: run.source, fields: run.checkedFields })
|
|
1240
|
+
: undefined,
|
|
1241
|
+
referencesNow(asks),
|
|
1242
|
+
]);
|
|
1243
|
+
if (outcome && outcome.status !== 'current') {
|
|
1054
1244
|
lines.set(row.index, notCurrent(row.index, outcome));
|
|
1055
1245
|
continue;
|
|
1056
1246
|
}
|
|
1247
|
+
if (references.status === 'gone') {
|
|
1248
|
+
lines.set(row.index, {
|
|
1249
|
+
index: row.index,
|
|
1250
|
+
status: 'reference_gone',
|
|
1251
|
+
committed: false,
|
|
1252
|
+
message: references.message,
|
|
1253
|
+
});
|
|
1254
|
+
continue;
|
|
1255
|
+
}
|
|
1256
|
+
if (references.status === 'unreadable') {
|
|
1257
|
+
lines.set(row.index, notCurrent(row.index, references));
|
|
1258
|
+
continue;
|
|
1259
|
+
}
|
|
1260
|
+
// After any read, an insert's included: a Stop pressed during it stops this row too.
|
|
1057
1261
|
if (stoppedAt(row.index))
|
|
1058
1262
|
continue;
|
|
1059
1263
|
}
|
|
@@ -23,14 +23,15 @@ __export(consumes_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(consumes_exports);
|
|
25
25
|
var GENESIS_AI_CONSUMES = Object.freeze({
|
|
26
|
-
kinds: Object.freeze(["request", "event"]),
|
|
26
|
+
kinds: Object.freeze(["request", "event", "query"]),
|
|
27
27
|
resourceFields: Object.freeze([
|
|
28
28
|
"name",
|
|
29
29
|
"kind",
|
|
30
30
|
"op",
|
|
31
31
|
"context",
|
|
32
32
|
"maxRows",
|
|
33
|
-
"customCode"
|
|
33
|
+
"customCode",
|
|
34
|
+
"references"
|
|
34
35
|
]),
|
|
35
36
|
vendors: Object.freeze(["anthropic", "gemini"]),
|
|
36
37
|
tiers: Object.freeze(["low", "high", "reasoning"])
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/genesis/consumes.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * What this version of the assistant reads from a generated AI config\n * (`@genesislcap/ai-assistant/genesis/consumes`).\n *\n * @remarks\n * Its own entry point, loadable in bare Node, because the seed's CI reads it in a Node step and\n * `./genesis` cannot be: that entry is bundler-target ESM, and its closure registers custom\n * elements, which need a DOM. So this module imports nothing at run time. A type from `./types`\n * is all it may take, and a test holds it to that. The Node build bundles it to\n * `dist/genesis-consumes.mjs` and `.cjs`, and a smoke test loads both without a DOM.\n *\n * @packageDocumentation\n * @beta\n */\nimport type { GenesisAiConsumes } from './types';\n\nexport type { GenesisAiConsumes } from './types';\n\n/**\n * What this version of the assistant reads from a generated AI config: the resource kinds it\n * accepts, the resource fields its validator or a tool reads, and the `vendor` and `tier` values\n * it accepts.\n *\n * @remarks\n * The generator must not emit what the installed assistant does not read, or a new kind is left out\n * and a new field ignored \u2014 and an older assistant used to block entirely on a kind it did not know.\n * Nothing in the generator can say which version will run its output. So the app's seed declares\n * what it expects, and the seed's CI checks that declaration against this constant, exported from\n * the version it installs. That makes this the single statement of what an assistant consumes, and\n * it carries no version number because it needs none.\n *\n * A test holds it to the code: its kinds are the ones validation accepts, and its fields are the\n * ones read. A change that teaches the validator a kind, or a tool a field, updates it in the same\n * commit.\n *\n * A resource this version does not read is only left out, but an unknown `vendor` or `tier` still\n * blocks the whole assistant, so those are here too. They are written out rather than imported\n * from foundation-ai, which this entry must not load; a test holds them equal to its\n * `AI_TIER_VENDORS` and `AI_TIER_IDS`, which the validator checks against.\n *\n * @beta\n */\nexport const GENESIS_AI_CONSUMES: GenesisAiConsumes = Object.freeze({\n kinds: Object.freeze(['request', 'event'] as const),\n resourceFields: Object.freeze([\n 'name',\n 'kind',\n 'op',\n 'context',\n 'maxRows',\n 'customCode',\n ] as const),\n vendors: Object.freeze(['anthropic', 'gemini'] as const),\n tiers: Object.freeze(['low', 'high', 'reasoning'] as const),\n});\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA0CO,IAAM,sBAAyC,OAAO,OAAO;AAAA,EAClE,OAAO,OAAO,OAAO,CAAC,WAAW,OAAO,CAAU;AAAA,
|
|
4
|
+
"sourcesContent": ["/**\n * What this version of the assistant reads from a generated AI config\n * (`@genesislcap/ai-assistant/genesis/consumes`).\n *\n * @remarks\n * Its own entry point, loadable in bare Node, because the seed's CI reads it in a Node step and\n * `./genesis` cannot be: that entry is bundler-target ESM, and its closure registers custom\n * elements, which need a DOM. So this module imports nothing at run time. A type from `./types`\n * is all it may take, and a test holds it to that. The Node build bundles it to\n * `dist/genesis-consumes.mjs` and `.cjs`, and a smoke test loads both without a DOM.\n *\n * @packageDocumentation\n * @beta\n */\nimport type { GenesisAiConsumes } from './types';\n\nexport type { GenesisAiConsumes } from './types';\n\n/**\n * What this version of the assistant reads from a generated AI config: the resource kinds it\n * accepts, the resource fields its validator or a tool reads, and the `vendor` and `tier` values\n * it accepts.\n *\n * @remarks\n * The generator must not emit what the installed assistant does not read, or a new kind is left out\n * and a new field ignored \u2014 and an older assistant used to block entirely on a kind it did not know.\n * Nothing in the generator can say which version will run its output. So the app's seed declares\n * what it expects, and the seed's CI checks that declaration against this constant, exported from\n * the version it installs. That makes this the single statement of what an assistant consumes, and\n * it carries no version number because it needs none.\n *\n * A test holds it to the code: its kinds are the ones validation accepts, and its fields are the\n * ones read. A change that teaches the validator a kind, or a tool a field, updates it in the same\n * commit.\n *\n * A resource this version does not read is only left out, but an unknown `vendor` or `tier` still\n * blocks the whole assistant, so those are here too. They are written out rather than imported\n * from foundation-ai, which this entry must not load; a test holds them equal to its\n * `AI_TIER_VENDORS` and `AI_TIER_IDS`, which the validator checks against.\n *\n * @beta\n */\nexport const GENESIS_AI_CONSUMES: GenesisAiConsumes = Object.freeze({\n kinds: Object.freeze(['request', 'event', 'query'] as const),\n resourceFields: Object.freeze([\n 'name',\n 'kind',\n 'op',\n 'context',\n 'maxRows',\n 'customCode',\n 'references',\n ] as const),\n vendors: Object.freeze(['anthropic', 'gemini'] as const),\n tiers: Object.freeze(['low', 'high', 'reasoning'] as const),\n});\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA0CO,IAAM,sBAAyC,OAAO,OAAO;AAAA,EAClE,OAAO,OAAO,OAAO,CAAC,WAAW,SAAS,OAAO,CAAU;AAAA,EAC3D,gBAAgB,OAAO,OAAO;AAAA,IAC5B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAU;AAAA,EACV,SAAS,OAAO,OAAO,CAAC,aAAa,QAAQ,CAAU;AAAA,EACvD,OAAO,OAAO,OAAO,CAAC,OAAO,QAAQ,WAAW,CAAU;AAC5D,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
// src/genesis/consumes.ts
|
|
2
2
|
var GENESIS_AI_CONSUMES = Object.freeze({
|
|
3
|
-
kinds: Object.freeze(["request", "event"]),
|
|
3
|
+
kinds: Object.freeze(["request", "event", "query"]),
|
|
4
4
|
resourceFields: Object.freeze([
|
|
5
5
|
"name",
|
|
6
6
|
"kind",
|
|
7
7
|
"op",
|
|
8
8
|
"context",
|
|
9
9
|
"maxRows",
|
|
10
|
-
"customCode"
|
|
10
|
+
"customCode",
|
|
11
|
+
"references"
|
|
11
12
|
]),
|
|
12
13
|
vendors: Object.freeze(["anthropic", "gemini"]),
|
|
13
14
|
tiers: Object.freeze(["low", "high", "reasoning"])
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/genesis/consumes.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * What this version of the assistant reads from a generated AI config\n * (`@genesislcap/ai-assistant/genesis/consumes`).\n *\n * @remarks\n * Its own entry point, loadable in bare Node, because the seed's CI reads it in a Node step and\n * `./genesis` cannot be: that entry is bundler-target ESM, and its closure registers custom\n * elements, which need a DOM. So this module imports nothing at run time. A type from `./types`\n * is all it may take, and a test holds it to that. The Node build bundles it to\n * `dist/genesis-consumes.mjs` and `.cjs`, and a smoke test loads both without a DOM.\n *\n * @packageDocumentation\n * @beta\n */\nimport type { GenesisAiConsumes } from './types';\n\nexport type { GenesisAiConsumes } from './types';\n\n/**\n * What this version of the assistant reads from a generated AI config: the resource kinds it\n * accepts, the resource fields its validator or a tool reads, and the `vendor` and `tier` values\n * it accepts.\n *\n * @remarks\n * The generator must not emit what the installed assistant does not read, or a new kind is left out\n * and a new field ignored \u2014 and an older assistant used to block entirely on a kind it did not know.\n * Nothing in the generator can say which version will run its output. So the app's seed declares\n * what it expects, and the seed's CI checks that declaration against this constant, exported from\n * the version it installs. That makes this the single statement of what an assistant consumes, and\n * it carries no version number because it needs none.\n *\n * A test holds it to the code: its kinds are the ones validation accepts, and its fields are the\n * ones read. A change that teaches the validator a kind, or a tool a field, updates it in the same\n * commit.\n *\n * A resource this version does not read is only left out, but an unknown `vendor` or `tier` still\n * blocks the whole assistant, so those are here too. They are written out rather than imported\n * from foundation-ai, which this entry must not load; a test holds them equal to its\n * `AI_TIER_VENDORS` and `AI_TIER_IDS`, which the validator checks against.\n *\n * @beta\n */\nexport const GENESIS_AI_CONSUMES: GenesisAiConsumes = Object.freeze({\n kinds: Object.freeze(['request', 'event'] as const),\n resourceFields: Object.freeze([\n 'name',\n 'kind',\n 'op',\n 'context',\n 'maxRows',\n 'customCode',\n ] as const),\n vendors: Object.freeze(['anthropic', 'gemini'] as const),\n tiers: Object.freeze(['low', 'high', 'reasoning'] as const),\n});\n"],
|
|
5
|
-
"mappings": ";AA0CO,IAAM,sBAAyC,OAAO,OAAO;AAAA,EAClE,OAAO,OAAO,OAAO,CAAC,WAAW,OAAO,CAAU;AAAA,
|
|
4
|
+
"sourcesContent": ["/**\n * What this version of the assistant reads from a generated AI config\n * (`@genesislcap/ai-assistant/genesis/consumes`).\n *\n * @remarks\n * Its own entry point, loadable in bare Node, because the seed's CI reads it in a Node step and\n * `./genesis` cannot be: that entry is bundler-target ESM, and its closure registers custom\n * elements, which need a DOM. So this module imports nothing at run time. A type from `./types`\n * is all it may take, and a test holds it to that. The Node build bundles it to\n * `dist/genesis-consumes.mjs` and `.cjs`, and a smoke test loads both without a DOM.\n *\n * @packageDocumentation\n * @beta\n */\nimport type { GenesisAiConsumes } from './types';\n\nexport type { GenesisAiConsumes } from './types';\n\n/**\n * What this version of the assistant reads from a generated AI config: the resource kinds it\n * accepts, the resource fields its validator or a tool reads, and the `vendor` and `tier` values\n * it accepts.\n *\n * @remarks\n * The generator must not emit what the installed assistant does not read, or a new kind is left out\n * and a new field ignored \u2014 and an older assistant used to block entirely on a kind it did not know.\n * Nothing in the generator can say which version will run its output. So the app's seed declares\n * what it expects, and the seed's CI checks that declaration against this constant, exported from\n * the version it installs. That makes this the single statement of what an assistant consumes, and\n * it carries no version number because it needs none.\n *\n * A test holds it to the code: its kinds are the ones validation accepts, and its fields are the\n * ones read. A change that teaches the validator a kind, or a tool a field, updates it in the same\n * commit.\n *\n * A resource this version does not read is only left out, but an unknown `vendor` or `tier` still\n * blocks the whole assistant, so those are here too. They are written out rather than imported\n * from foundation-ai, which this entry must not load; a test holds them equal to its\n * `AI_TIER_VENDORS` and `AI_TIER_IDS`, which the validator checks against.\n *\n * @beta\n */\nexport const GENESIS_AI_CONSUMES: GenesisAiConsumes = Object.freeze({\n kinds: Object.freeze(['request', 'event', 'query'] as const),\n resourceFields: Object.freeze([\n 'name',\n 'kind',\n 'op',\n 'context',\n 'maxRows',\n 'customCode',\n 'references',\n ] as const),\n vendors: Object.freeze(['anthropic', 'gemini'] as const),\n tiers: Object.freeze(['low', 'high', 'reasoning'] as const),\n});\n"],
|
|
5
|
+
"mappings": ";AA0CO,IAAM,sBAAyC,OAAO,OAAO;AAAA,EAClE,OAAO,OAAO,OAAO,CAAC,WAAW,SAAS,OAAO,CAAU;AAAA,EAC3D,gBAAgB,OAAO,OAAO;AAAA,IAC5B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAU;AAAA,EACV,SAAS,OAAO,OAAO,CAAC,aAAa,QAAQ,CAAU;AAAA,EACvD,OAAO,OAAO,OAAO,CAAC,OAAO,QAAQ,WAAW,CAAU;AAC5D,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|