@genesislcap/ai-assistant 15.43.0 → 15.45.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/ai-assistant.api.json +34 -19
- package/dist/ai-assistant.d.ts +36 -2
- package/dist/chat-driver.cjs +89 -10
- package/dist/chat-driver.cjs.map +2 -2
- package/dist/chat-driver.mjs +89 -10
- package/dist/chat-driver.mjs.map +2 -2
- package/dist/custom-elements.json +466 -285
- package/dist/dts/components/chat-driver/chat-driver.d.ts +15 -2
- package/dist/dts/components/chat-driver/chat-driver.d.ts.map +1 -1
- package/dist/dts/components/chat-driver/interaction-controller.d.ts +26 -3
- package/dist/dts/components/chat-driver/interaction-controller.d.ts.map +1 -1
- package/dist/dts/components/chat-interaction-wrapper/chat-interaction-wrapper.d.ts +6 -0
- package/dist/dts/components/chat-interaction-wrapper/chat-interaction-wrapper.d.ts.map +1 -1
- package/dist/dts/genesis/config.d.ts +28 -1
- package/dist/dts/genesis/config.d.ts.map +1 -1
- package/dist/dts/genesis/consumes.d.ts.map +1 -1
- package/dist/dts/genesis/index.d.ts +2 -1
- package/dist/dts/genesis/index.d.ts.map +1 -1
- package/dist/dts/genesis/register-genesis-assistant.d.ts.map +1 -1
- package/dist/dts/genesis/review-model.d.ts +72 -1
- package/dist/dts/genesis/review-model.d.ts.map +1 -1
- package/dist/dts/genesis/types.d.ts +32 -0
- package/dist/dts/genesis/types.d.ts.map +1 -1
- package/dist/dts/genesis/write-review/write-review.d.ts +22 -1
- package/dist/dts/genesis/write-review/write-review.d.ts.map +1 -1
- package/dist/dts/genesis/write-review/write-review.styles.d.ts.map +1 -1
- package/dist/dts/genesis/write-review/write-review.template.d.ts.map +1 -1
- package/dist/dts/genesis/write-tools.d.ts +6 -1
- package/dist/dts/genesis/write-tools.d.ts.map +1 -1
- package/dist/dts/main/main.template.d.ts +8 -0
- package/dist/dts/main/main.template.d.ts.map +1 -1
- package/dist/dts/state/debug-event-log.d.ts +1 -1
- package/dist/dts/state/debug-event-log.d.ts.map +1 -1
- package/dist/dts/types/ai-chat-widget.d.ts +7 -0
- package/dist/dts/types/ai-chat-widget.d.ts.map +1 -1
- package/dist/esm/components/chat-driver/chat-driver.js +39 -6
- package/dist/esm/components/chat-driver/interaction-controller.js +50 -4
- package/dist/esm/components/chat-interaction-wrapper/chat-interaction-wrapper.js +17 -6
- package/dist/esm/genesis/config.js +108 -7
- package/dist/esm/genesis/consumes.js +8 -1
- package/dist/esm/genesis/index.js +1 -0
- package/dist/esm/genesis/register-genesis-assistant.js +7 -0
- package/dist/esm/genesis/review-model.js +115 -7
- package/dist/esm/genesis/write-review/write-review.js +80 -19
- package/dist/esm/genesis/write-review/write-review.styles.js +5 -2
- package/dist/esm/genesis/write-review/write-review.template.js +19 -2
- package/dist/esm/genesis/write-tools.js +49 -13
- package/dist/esm/main/main.template.js +19 -10
- package/dist/esm/state/debug-event-log.js +4 -0
- package/dist/genesis-consumes.cjs +8 -1
- package/dist/genesis-consumes.cjs.map +2 -2
- package/dist/genesis-consumes.mjs +8 -1
- package/dist/genesis-consumes.mjs.map +2 -2
- package/docs/genesis.md +60 -2
- package/package.json +18 -18
- package/scripts/smoke-genesis-consumes-node.mjs +1 -1
|
@@ -31,6 +31,13 @@ export type AiChatInteraction<TData = unknown, TResult = unknown> = {
|
|
|
31
31
|
data: TData;
|
|
32
32
|
/** The interaction outcome. */
|
|
33
33
|
result: InteractionResult<TResult>;
|
|
34
|
+
/**
|
|
35
|
+
* What came of the answer, when the tool that opened the widget recorded it afterwards (see
|
|
36
|
+
* `recordInteractionOutcome` on the tool handler context): which rows a write review's
|
|
37
|
+
* approval actually wrote, say. Absent until then, and for a tool that records none.
|
|
38
|
+
* Display-only: the widget shows it, and it is never sent to a model.
|
|
39
|
+
*/
|
|
40
|
+
outcome?: unknown;
|
|
34
41
|
};
|
|
35
42
|
/**
|
|
36
43
|
* Interface that AI inline interaction components implement. The
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-chat-widget.d.ts","sourceRoot":"","sources":["../../../src/types/ai-chat-widget.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhE;;;;;;;;;;GAUG;AACH,MAAM,MAAM,iBAAiB,CAAC,KAAK,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,IAC5D;IACE,MAAM,EAAE,SAAS,CAAC;IAClB,4CAA4C;IAC5C,IAAI,EAAE,KAAK,CAAC;IACZ;;;OAGG;IACH,eAAe,EAAE,OAAO,CAAC;IACzB;;;OAGG;IACH,kBAAkB,EAAE,kBAAkB,CAAC;CACxC,GACD;IACE,MAAM,EAAE,UAAU,CAAC;IACnB,wDAAwD;IACxD,IAAI,EAAE,KAAK,CAAC;IACZ,+BAA+B;IAC/B,MAAM,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"ai-chat-widget.d.ts","sourceRoot":"","sources":["../../../src/types/ai-chat-widget.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhE;;;;;;;;;;GAUG;AACH,MAAM,MAAM,iBAAiB,CAAC,KAAK,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,IAC5D;IACE,MAAM,EAAE,SAAS,CAAC;IAClB,4CAA4C;IAC5C,IAAI,EAAE,KAAK,CAAC;IACZ;;;OAGG;IACH,eAAe,EAAE,OAAO,CAAC;IACzB;;;OAGG;IACH,kBAAkB,EAAE,kBAAkB,CAAC;CACxC,GACD;IACE,MAAM,EAAE,UAAU,CAAC;IACnB,wDAAwD;IACxD,IAAI,EAAE,KAAK,CAAC;IACZ,+BAA+B;IAC/B,MAAM,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;IACnC;;;;;OAKG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEN;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,YAAY,CAAC,KAAK,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO;IAC9D,qFAAqF;IACrF,aAAa,EAAE,MAAM,CAAC;IAEtB,2DAA2D;IAC3D,WAAW,EAAE,iBAAiB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;CAChD"}
|
|
@@ -1564,8 +1564,8 @@ export class ChatDriver extends EventTarget {
|
|
|
1564
1564
|
* resolves through) the parent's history and pending map. Calls chain
|
|
1565
1565
|
* naturally: a grandchild → child → root.
|
|
1566
1566
|
*/
|
|
1567
|
-
setHostInteractionRequester(fn) {
|
|
1568
|
-
this.interactions.setHostRequester(fn);
|
|
1567
|
+
setHostInteractionRequester(fn, recordOutcome) {
|
|
1568
|
+
this.interactions.setHostRequester(fn, recordOutcome);
|
|
1569
1569
|
}
|
|
1570
1570
|
/**
|
|
1571
1571
|
* Request a custom UI interaction. Emits a new message with the interaction.
|
|
@@ -1586,11 +1586,25 @@ export class ChatDriver extends EventTarget {
|
|
|
1586
1586
|
* and `presentation` to control whether the host wraps the widget in a chat
|
|
1587
1587
|
* bubble and/or shows the "Assistant" label.
|
|
1588
1588
|
*/
|
|
1589
|
-
requestInteraction(componentName, data, options) {
|
|
1589
|
+
requestInteraction(componentName, data, options, onOpened) {
|
|
1590
1590
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1591
|
-
return this.interactions.request(componentName, data, options);
|
|
1591
|
+
return this.interactions.request(componentName, data, options, onOpened);
|
|
1592
1592
|
});
|
|
1593
1593
|
}
|
|
1594
|
+
/**
|
|
1595
|
+
* Record what came of an interaction, after it resolved, on its history message
|
|
1596
|
+
* (`interaction.outcome`): handed to its widget and persisted with the session, never sent to a
|
|
1597
|
+
* model. Routed to the host driver when the interaction lives there (a sub-agent's). `false`,
|
|
1598
|
+
* changing nothing, when it is unknown, still pending, or the value cannot be stored as JSON.
|
|
1599
|
+
*
|
|
1600
|
+
* Tool handlers reach this through `recordInteractionOutcome` on their context, which binds it
|
|
1601
|
+
* to the interaction that call opened: see `buildHandlerContext`.
|
|
1602
|
+
*
|
|
1603
|
+
* @internal
|
|
1604
|
+
*/
|
|
1605
|
+
recordInteractionOutcome(interactionId, outcome) {
|
|
1606
|
+
return this.interactions.recordOutcome(interactionId, outcome);
|
|
1607
|
+
}
|
|
1594
1608
|
/**
|
|
1595
1609
|
* Add external (non-LLM) spend to an interaction's message AFTER it has resolved — for a widget
|
|
1596
1610
|
* that resolves early so the assistant stops waiting, then keeps doing paid work on the user's
|
|
@@ -1741,7 +1755,24 @@ export class ChatDriver extends EventTarget {
|
|
|
1741
1755
|
*/
|
|
1742
1756
|
buildHandlerContext(activeToolCallId, traceCapture) {
|
|
1743
1757
|
var _a;
|
|
1744
|
-
|
|
1758
|
+
// The interaction THIS call opened, if any: the only one its `recordInteractionOutcome` can
|
|
1759
|
+
// reach, so a tool can never write an outcome onto a widget another tool opened.
|
|
1760
|
+
let opened;
|
|
1761
|
+
let recorded = false;
|
|
1762
|
+
return Object.assign(Object.assign({ requestInteraction: (componentName, data, options) => this.requestInteraction(componentName, data, options, (interactionId) => {
|
|
1763
|
+
opened = interactionId;
|
|
1764
|
+
}), recordInteractionOutcome: (outcome) => {
|
|
1765
|
+
var _a;
|
|
1766
|
+
if (!opened)
|
|
1767
|
+
return false;
|
|
1768
|
+
if (recorded) {
|
|
1769
|
+
logger.warn(`ChatDriver(${(_a = this.activeAgentName) !== null && _a !== void 0 ? _a : 'unknown'}): recordInteractionOutcome called ` +
|
|
1770
|
+
'more than once in one tool call — ignoring');
|
|
1771
|
+
return false;
|
|
1772
|
+
}
|
|
1773
|
+
recorded = true;
|
|
1774
|
+
return this.recordInteractionOutcome(opened, outcome);
|
|
1775
|
+
},
|
|
1745
1776
|
// The MESSAGE's scope: one object per `sendMessage`, kept across a handoff's continuation
|
|
1746
1777
|
// and handed to a sub-agent, and aborted by `cancel()` as well as a dispose. Not the
|
|
1747
1778
|
// per-request `turnController`, which every continuation replaces.
|
|
@@ -1876,7 +1907,9 @@ export class ChatDriver extends EventTarget {
|
|
|
1876
1907
|
// parent's (ultimately the root's) history and resolve via the same
|
|
1877
1908
|
// pending map the main UI is wired to. Recurses naturally for nested
|
|
1878
1909
|
// sub-agents.
|
|
1879
|
-
child.setHostInteractionRequester((componentName, data, opts) => this.requestInteraction(componentName, data, opts)
|
|
1910
|
+
child.setHostInteractionRequester((componentName, data, opts, onOpened) => this.requestInteraction(componentName, data, opts, onOpened),
|
|
1911
|
+
// An outcome goes where its interaction went.
|
|
1912
|
+
(interactionId, outcome) => this.recordInteractionOutcome(interactionId, outcome));
|
|
1880
1913
|
// The same route for a refusal the child absorbs, so the user sees it in the root transcript.
|
|
1881
1914
|
child.hostAIServiceNotice = (code) => this.noticeAIServiceRefusal(code);
|
|
1882
1915
|
const forwardTrace = (e) => {
|
|
@@ -28,13 +28,17 @@ export class InteractionController {
|
|
|
28
28
|
this.contexts = new Map();
|
|
29
29
|
}
|
|
30
30
|
/** See `ChatDriver.setHostInteractionRequester`. */
|
|
31
|
-
setHostRequester(fn) {
|
|
31
|
+
setHostRequester(fn, recordOutcome) {
|
|
32
32
|
this.hostRequester = fn;
|
|
33
|
+
this.hostOutcome = recordOutcome;
|
|
33
34
|
}
|
|
34
|
-
/**
|
|
35
|
-
|
|
35
|
+
/**
|
|
36
|
+
* See `ChatDriver.requestInteraction`. `onOpened` is told the id of the interaction this call
|
|
37
|
+
* opens, wherever it opens it, so the caller can later record its outcome and no other's.
|
|
38
|
+
*/
|
|
39
|
+
request(componentName, data, options, onOpened) {
|
|
36
40
|
if (this.hostRequester) {
|
|
37
|
-
return this.hostRequester(componentName, data, options);
|
|
41
|
+
return this.hostRequester(componentName, data, options, onOpened);
|
|
38
42
|
}
|
|
39
43
|
if (this.pending.size > 0) {
|
|
40
44
|
throw new Error('requestInteraction: another user interaction is already in flight. ' +
|
|
@@ -42,6 +46,7 @@ export class InteractionController {
|
|
|
42
46
|
'rather than spawning widgets from parallel sub-agents or parallel tool calls.');
|
|
43
47
|
}
|
|
44
48
|
const interactionId = crypto.randomUUID();
|
|
49
|
+
onOpened === null || onOpened === void 0 ? void 0 : onOpened(interactionId);
|
|
45
50
|
const chatInputDuringExecution = options === null || options === void 0 ? void 0 : options.chatInputDuringExecution;
|
|
46
51
|
const timeoutMs = options === null || options === void 0 ? void 0 : options.timeoutMs;
|
|
47
52
|
const presentation = options === null || options === void 0 ? void 0 : options.presentation;
|
|
@@ -226,6 +231,47 @@ export class InteractionController {
|
|
|
226
231
|
}));
|
|
227
232
|
return true;
|
|
228
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* See `ChatDriver.recordInteractionOutcome`.
|
|
236
|
+
*
|
|
237
|
+
* @remarks
|
|
238
|
+
* Only once the interaction has resolved: an outcome is what came of an answer. The message is
|
|
239
|
+
* REPLACED, as `resolve` replaces it, never changed in place — the host's store freezes what it
|
|
240
|
+
* holds. The value is copied as JSON, the form it is persisted in, so what the widget shows now
|
|
241
|
+
* is what a reload shows, and nothing the caller keeps can change it afterwards.
|
|
242
|
+
*
|
|
243
|
+
* Announced on `history-updated`, unlike `recordExternalCost`: the outcome changes what the
|
|
244
|
+
* widget shows, so the resolved widget has to be rebuilt with it.
|
|
245
|
+
*/
|
|
246
|
+
recordOutcome(interactionId, outcome) {
|
|
247
|
+
if (this.hostOutcome)
|
|
248
|
+
return this.hostOutcome(interactionId, outcome);
|
|
249
|
+
const drop = (reason) => {
|
|
250
|
+
recordMetaEvent(this.deps.sessionKey, 'interaction.outcome-dropped', {
|
|
251
|
+
interactionId,
|
|
252
|
+
reason,
|
|
253
|
+
});
|
|
254
|
+
return false;
|
|
255
|
+
};
|
|
256
|
+
if (this.pending.has(interactionId))
|
|
257
|
+
return drop('interaction not resolved');
|
|
258
|
+
let copy;
|
|
259
|
+
try {
|
|
260
|
+
const json = JSON.stringify(outcome);
|
|
261
|
+
if (json === undefined)
|
|
262
|
+
return drop('no value to store');
|
|
263
|
+
copy = JSON.parse(json);
|
|
264
|
+
}
|
|
265
|
+
catch (_a) {
|
|
266
|
+
return drop('not storable as JSON');
|
|
267
|
+
}
|
|
268
|
+
const patched = this.deps.patchInteractionMessage(interactionId, (message) => (Object.assign(Object.assign({}, message), { interaction: Object.assign(Object.assign({}, message.interaction), { outcome: copy }) })));
|
|
269
|
+
if (!patched)
|
|
270
|
+
return drop('interaction message no longer in history');
|
|
271
|
+
recordMetaEvent(this.deps.sessionKey, 'interaction.outcome', { interactionId });
|
|
272
|
+
this.deps.notifyHistoryUpdated();
|
|
273
|
+
return true;
|
|
274
|
+
}
|
|
229
275
|
/** See `ChatDriver.getInteractionContext`. */
|
|
230
276
|
context(interactionId) {
|
|
231
277
|
var _a;
|
|
@@ -20,6 +20,8 @@ let AiChatInteractionWrapper = class AiChatInteractionWrapper extends GenesisEle
|
|
|
20
20
|
this.interactionId = '';
|
|
21
21
|
/** The resolved result once the interaction has completed. Forwarded to the rendered component. @internal */
|
|
22
22
|
this.resolved = undefined;
|
|
23
|
+
/** See `AiChatInteraction`'s resolved `outcome`: recorded after the answer, by the tool. */
|
|
24
|
+
this.outcome = undefined;
|
|
23
25
|
}
|
|
24
26
|
connectedCallback() {
|
|
25
27
|
super.connectedCallback();
|
|
@@ -54,14 +56,21 @@ let AiChatInteractionWrapper = class AiChatInteractionWrapper extends GenesisEle
|
|
|
54
56
|
// in place, preserving its DOM/state (no re-create). If no matching element exists
|
|
55
57
|
// yet (e.g. a history re-render straight into the resolved state), render it fresh.
|
|
56
58
|
if (element && ((_b = element.tagName) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === this.componentName) {
|
|
57
|
-
if (this.resolved)
|
|
58
|
-
element.interaction =
|
|
59
|
-
}
|
|
59
|
+
if (this.resolved)
|
|
60
|
+
element.interaction = this.resolvedInteraction();
|
|
60
61
|
}
|
|
61
62
|
else if (this.resolved) {
|
|
62
63
|
this.renderComponent();
|
|
63
64
|
}
|
|
64
65
|
}
|
|
66
|
+
/** An outcome recorded after the answer reaches a widget already showing that answer. */
|
|
67
|
+
outcomeChanged() {
|
|
68
|
+
this.resolvedChanged();
|
|
69
|
+
}
|
|
70
|
+
/** The resolved descriptor, with the outcome when one has been recorded. */
|
|
71
|
+
resolvedInteraction() {
|
|
72
|
+
return Object.assign({ status: 'resolved', data: this.data, result: this.resolved }, (this.outcome !== undefined ? { outcome: this.outcome } : {}));
|
|
73
|
+
}
|
|
65
74
|
/**
|
|
66
75
|
* Watch the rendered widget element for box-size changes. When the widget
|
|
67
76
|
* grows or shrinks mid-lifecycle (e.g. expanding a "More info" panel,
|
|
@@ -162,9 +171,8 @@ let AiChatInteractionWrapper = class AiChatInteractionWrapper extends GenesisEle
|
|
|
162
171
|
*/
|
|
163
172
|
buildInteraction(host) {
|
|
164
173
|
var _a;
|
|
165
|
-
if (this.resolved)
|
|
166
|
-
return
|
|
167
|
-
}
|
|
174
|
+
if (this.resolved)
|
|
175
|
+
return this.resolvedInteraction();
|
|
168
176
|
// Pending. The driver creates a live context for EVERY pending interaction BEFORE the widget
|
|
169
177
|
// mounts, returns the SAME instance on every remount, and drops it the instant the interaction
|
|
170
178
|
// resolves (see `ChatDriver.resolveInteraction`). So a MISSING context is not "pending, context
|
|
@@ -202,6 +210,9 @@ __decorate([
|
|
|
202
210
|
__decorate([
|
|
203
211
|
observable
|
|
204
212
|
], AiChatInteractionWrapper.prototype, "resolved", void 0);
|
|
213
|
+
__decorate([
|
|
214
|
+
observable
|
|
215
|
+
], AiChatInteractionWrapper.prototype, "outcome", void 0);
|
|
205
216
|
AiChatInteractionWrapper = __decorate([
|
|
206
217
|
customElement({
|
|
207
218
|
name: 'ai-chat-interaction-wrapper',
|
|
@@ -70,7 +70,12 @@ const KNOWN_KINDS = ['request', 'event'];
|
|
|
70
70
|
export function validateGenesisAiConfig(config) {
|
|
71
71
|
var _a;
|
|
72
72
|
if (!config || typeof config !== 'object') {
|
|
73
|
-
return {
|
|
73
|
+
return {
|
|
74
|
+
problems: ['the AI config is missing or not an object'],
|
|
75
|
+
resources: [],
|
|
76
|
+
dropped: [],
|
|
77
|
+
warnings: [],
|
|
78
|
+
};
|
|
74
79
|
}
|
|
75
80
|
const c = config;
|
|
76
81
|
const problems = [];
|
|
@@ -96,9 +101,14 @@ export function validateGenesisAiConfig(config) {
|
|
|
96
101
|
// registration logs a warning naming both causes. What that case needs is a signal, not a
|
|
97
102
|
// block.
|
|
98
103
|
if (c.resources === undefined)
|
|
99
|
-
return { problems, resources: [], dropped: [] };
|
|
104
|
+
return { problems, resources: [], dropped: [], warnings: [] };
|
|
100
105
|
if (!Array.isArray(c.resources)) {
|
|
101
|
-
return {
|
|
106
|
+
return {
|
|
107
|
+
problems: [...problems, 'resources must be an array'],
|
|
108
|
+
resources: [],
|
|
109
|
+
dropped: [],
|
|
110
|
+
warnings: [],
|
|
111
|
+
};
|
|
102
112
|
}
|
|
103
113
|
// Counted over every entry before any is judged: a duplicate leaves out EVERY copy. Which one
|
|
104
114
|
// the generator meant is unknown, and keeping the first would be a guess at it. Two tools with
|
|
@@ -112,16 +122,107 @@ export function validateGenesisAiConfig(config) {
|
|
|
112
122
|
}
|
|
113
123
|
const resources = [];
|
|
114
124
|
const dropped = [];
|
|
125
|
+
const warnings = [];
|
|
115
126
|
c.resources.forEach((resource, i) => {
|
|
116
127
|
var _a;
|
|
117
128
|
const name = typeof (resource === null || resource === void 0 ? void 0 : resource.name) === 'string' ? resource.name : undefined;
|
|
118
129
|
const wrong = resourceProblems(resource, (_a = copies.get(name !== null && name !== void 0 ? name : '')) !== null && _a !== void 0 ? _a : 0);
|
|
119
|
-
if (wrong.length)
|
|
130
|
+
if (wrong.length) {
|
|
120
131
|
dropped.push({ at: `resources[${i}]`, name, problems: wrong });
|
|
121
|
-
|
|
122
|
-
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const customCode = customCodeOf(resource);
|
|
135
|
+
if (customCode.warning)
|
|
136
|
+
warnings.push({ name, warning: customCode.warning });
|
|
137
|
+
resources.push(keptCopy(resource, customCode.value));
|
|
123
138
|
});
|
|
124
|
-
return { problems, resources, dropped };
|
|
139
|
+
return { problems, resources, dropped, warnings };
|
|
140
|
+
}
|
|
141
|
+
/** A table name as the generator writes one. */
|
|
142
|
+
const TABLE_NAME = /^[A-Z0-9_]+$/;
|
|
143
|
+
/** The keys `customCode` has, and every other is a sign it was not built by the generator. */
|
|
144
|
+
const CUSTOM_CODE_KEYS = ['alsoWrites', 'listComplete'];
|
|
145
|
+
/** The ops `customCode` applies to. */
|
|
146
|
+
const CRUD_OPS = ['insert', 'modify', 'delete'];
|
|
147
|
+
/**
|
|
148
|
+
* A resource's `customCode` as it is used: the one reader of the field.
|
|
149
|
+
*
|
|
150
|
+
* @remarks
|
|
151
|
+
* Called by the validator AND by the write tools, because `createGenesisWriteTools` is exported
|
|
152
|
+
* and never validates: one rule, whichever way the resource arrives. It never throws and never
|
|
153
|
+
* drops the resource.
|
|
154
|
+
*
|
|
155
|
+
* - On anything but an insert, modify or delete event, the field has no meaning: it is dropped,
|
|
156
|
+
* with a warning, and the resource is kept.
|
|
157
|
+
* - Malformed — not an object, a key it has no place for, `alsoWrites` not a list, a member that
|
|
158
|
+
* is not a table name or is named twice, `listComplete` not true or false — keeps the valid
|
|
159
|
+
* names, in order, and reads `listComplete` as FALSE, with a warning. The review then says the
|
|
160
|
+
* code can also write to other records: over-disclosure is the safe end, and a malformed value
|
|
161
|
+
* must never read as a complete list.
|
|
162
|
+
*
|
|
163
|
+
* @beta
|
|
164
|
+
*/
|
|
165
|
+
export function customCodeOf(resource) {
|
|
166
|
+
var _a;
|
|
167
|
+
const given = resource.customCode;
|
|
168
|
+
if (given === undefined)
|
|
169
|
+
return {};
|
|
170
|
+
const op = (_a = resource.op) !== null && _a !== void 0 ? _a : opFromName(resource.name);
|
|
171
|
+
if (resource.kind !== 'event' || !CRUD_OPS.includes(op)) {
|
|
172
|
+
return {
|
|
173
|
+
warning: `${resource.name} carries customCode, which applies to insert, modify and delete ` +
|
|
174
|
+
'events only, so the field is ignored',
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
const record = given && typeof given === 'object' && !Array.isArray(given)
|
|
178
|
+
? given
|
|
179
|
+
: undefined;
|
|
180
|
+
const reasons = [];
|
|
181
|
+
if (!record)
|
|
182
|
+
reasons.push('it is not an object');
|
|
183
|
+
const stray = Object.keys(record !== null && record !== void 0 ? record : {}).filter((key) => !CUSTOM_CODE_KEYS.includes(key));
|
|
184
|
+
if (stray.length)
|
|
185
|
+
reasons.push(`it carries ${stray.join(', ')}, which it has no place for`);
|
|
186
|
+
const list = record === null || record === void 0 ? void 0 : record.alsoWrites;
|
|
187
|
+
if (record && !Array.isArray(list))
|
|
188
|
+
reasons.push('alsoWrites is not a list');
|
|
189
|
+
const alsoWrites = [];
|
|
190
|
+
for (const name of Array.isArray(list) ? list : []) {
|
|
191
|
+
if (typeof name !== 'string' || !TABLE_NAME.test(name)) {
|
|
192
|
+
reasons.push(`alsoWrites holds ${typeof name === 'string' ? `'${name}'` : typeof name}, not a table name`);
|
|
193
|
+
}
|
|
194
|
+
else if (alsoWrites.includes(name)) {
|
|
195
|
+
reasons.push(`alsoWrites names ${name} twice`);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
alsoWrites.push(name);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (record && typeof record.listComplete !== 'boolean') {
|
|
202
|
+
reasons.push('listComplete is not true or false');
|
|
203
|
+
}
|
|
204
|
+
if (!reasons.length) {
|
|
205
|
+
return { value: { alsoWrites, listComplete: record.listComplete } };
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
value: { alsoWrites, listComplete: false },
|
|
209
|
+
warning: `${resource.name} carries a malformed customCode (${reasons.join('; ')}), so the review ` +
|
|
210
|
+
'says its code can also write to other records',
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* A surviving resource as it is kept: a new object holding the fields this version reads, and
|
|
215
|
+
* nothing else.
|
|
216
|
+
*
|
|
217
|
+
* @remarks
|
|
218
|
+
* Never the imported object. The config is the app's `ai-config.json`, imported once and shared,
|
|
219
|
+
* and whatever the assistant goes on to do with a resource must not be able to change it. Built
|
|
220
|
+
* field by field rather than spread, because a spread reads — and carries on — every key there
|
|
221
|
+
* is, including ones this version does not read: a field only gets used once it is copied here,
|
|
222
|
+
* which is when GENESIS_AI_CONSUMES has to name it.
|
|
223
|
+
*/
|
|
224
|
+
function keptCopy(resource, customCode) {
|
|
225
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({ name: resource.name, kind: resource.kind }, (resource.op !== undefined ? { op: resource.op } : {})), { context: resource.context }), (resource.maxRows !== undefined ? { maxRows: resource.maxRows } : {})), (customCode ? { customCode } : {}));
|
|
125
226
|
}
|
|
126
227
|
/** What is wrong with one resource, if anything. `copies` is how many entries share its name. */
|
|
127
228
|
function resourceProblems(resource, copies) {
|
|
@@ -24,7 +24,14 @@
|
|
|
24
24
|
*/
|
|
25
25
|
export const GENESIS_AI_CONSUMES = Object.freeze({
|
|
26
26
|
kinds: Object.freeze(['request', 'event']),
|
|
27
|
-
resourceFields: Object.freeze([
|
|
27
|
+
resourceFields: Object.freeze([
|
|
28
|
+
'name',
|
|
29
|
+
'kind',
|
|
30
|
+
'op',
|
|
31
|
+
'context',
|
|
32
|
+
'maxRows',
|
|
33
|
+
'customCode',
|
|
34
|
+
]),
|
|
28
35
|
vendors: Object.freeze(['anthropic', 'gemini']),
|
|
29
36
|
tiers: Object.freeze(['low', 'high', 'reasoning']),
|
|
30
37
|
});
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* @beta
|
|
12
12
|
*/
|
|
13
13
|
export { GENESIS_AGENT_NAME, registerGenesisAssistant } from './register-genesis-assistant';
|
|
14
|
+
export { customCodeOf } from './config';
|
|
14
15
|
export { GENESIS_AI_CONSUMES } from './consumes';
|
|
15
16
|
export { createGenesisResourceTools, GENESIS_DATA_SOURCE } from './resource-tools';
|
|
16
17
|
export { createGenesisWriteTools } from './write-tools';
|
|
@@ -311,6 +311,13 @@ export function registerGenesisAssistant(options) {
|
|
|
311
311
|
// The last check that can block is behind us.
|
|
312
312
|
for (const line of leftOut)
|
|
313
313
|
logger.warn(`Genesis assistant: ${line}`);
|
|
314
|
+
// Only of a resource the assistant still has. One an extension replaced gets no review, so
|
|
315
|
+
// "the review says…" would describe one nobody will see; its left-out line has said why.
|
|
316
|
+
const kept = new Set(resources.map((resource) => resource.name));
|
|
317
|
+
for (const { name, warning } of check.warnings) {
|
|
318
|
+
if (kept.has(name))
|
|
319
|
+
logger.warn(`Genesis assistant: ${warning}.`);
|
|
320
|
+
}
|
|
314
321
|
// Accepted (see validateGenesisAiConfig), but announced. An assistant with no generated tools
|
|
315
322
|
// is a real configuration, and it is indistinguishable from one whose resource list came out
|
|
316
323
|
// empty by mistake: the chat opens and answers, and can reach no data, with nothing anywhere
|
|
@@ -31,6 +31,33 @@ const defaultTitle = (name) => name
|
|
|
31
31
|
* value long enough to push the change out of view wraps, where being on several lines is plain.
|
|
32
32
|
*/
|
|
33
33
|
export const LONG_VALUE = 24;
|
|
34
|
+
/** `A`, `A and B`, `A, B and C`. */
|
|
35
|
+
const joined = (items) => items.length > 1 ? `${items.slice(0, -1).join(', ')} and ${items[items.length - 1]}` : items[0];
|
|
36
|
+
/**
|
|
37
|
+
* The line a review shows when the event runs custom code: that the code can do more than the
|
|
38
|
+
* row shown, and what the generator found it can also write to.
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
* Every form says the code can do more than the values shown, because the row a coded handler
|
|
42
|
+
* saves is built in its code, not taken from the review. The named tables are a FLOOR, dated to
|
|
43
|
+
* when the app was generated (the app's code can change after), and end in "other records" unless
|
|
44
|
+
* the generator proved the list complete. The exact words are pinned by contracts C-18.D.4.
|
|
45
|
+
*
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
export function customCodeLine(op, customCode) {
|
|
49
|
+
const verb = op === 'delete' ? 'remove the row shown' : 'save the values shown';
|
|
50
|
+
const opening = `This action runs custom code, so it can do more than ${verb}`;
|
|
51
|
+
if (!customCode.alsoWrites.length) {
|
|
52
|
+
return customCode.listComplete
|
|
53
|
+
? `${opening}.`
|
|
54
|
+
: `${opening}, and it can also write to other records.`;
|
|
55
|
+
}
|
|
56
|
+
const names = customCode.listComplete
|
|
57
|
+
? customCode.alsoWrites
|
|
58
|
+
: [...customCode.alsoWrites, 'other records'];
|
|
59
|
+
return `${opening}. When this app was generated, that code could also write to ${joined(names)}.`;
|
|
60
|
+
}
|
|
34
61
|
/**
|
|
35
62
|
* How much of a value is spoken in a row's accessible name.
|
|
36
63
|
*
|
|
@@ -144,7 +171,7 @@ export function displayValue(value, type) {
|
|
|
144
171
|
*/
|
|
145
172
|
export function buildReviewModel(options) {
|
|
146
173
|
var _a;
|
|
147
|
-
const { resource, op, fields = [], rows } = options;
|
|
174
|
+
const { resource, op, fields = [], rows, customCode } = options;
|
|
148
175
|
const byName = new Map(fields.map((field) => [field.name, field]));
|
|
149
176
|
// Declared order first, then anything a row carries that the metadata did not describe, in the
|
|
150
177
|
// order it is first seen. One column list, so every row's cells line up under it.
|
|
@@ -204,13 +231,16 @@ export function buildReviewModel(options) {
|
|
|
204
231
|
.join(', ');
|
|
205
232
|
return Object.assign({ index: row.index, details: row.details, cells, label: spoken || `row ${row.index + 1}` }, (((_c = row.problems) === null || _c === void 0 ? void 0 : _c.length) ? { problems: row.problems } : {}));
|
|
206
233
|
});
|
|
207
|
-
return {
|
|
208
|
-
resource,
|
|
234
|
+
return Object.assign({ resource,
|
|
209
235
|
op,
|
|
210
|
-
columns,
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
236
|
+
columns, rows: built, selectable: built.filter((row) => { var _a; return !((_a = row.problems) === null || _a === void 0 ? void 0 : _a.length); }).map((row) => row.index) }, (customCode
|
|
237
|
+
? {
|
|
238
|
+
customCode: {
|
|
239
|
+
alsoWrites: [...customCode.alsoWrites],
|
|
240
|
+
listComplete: customCode.listComplete,
|
|
241
|
+
},
|
|
242
|
+
}
|
|
243
|
+
: {}));
|
|
214
244
|
}
|
|
215
245
|
/**
|
|
216
246
|
* The selection a freshly opened review starts with: none.
|
|
@@ -305,3 +335,81 @@ export function reviewDecisionOf(result, model) {
|
|
|
305
335
|
export const selectedRows = (model, selection) => model.rows
|
|
306
336
|
.filter((row) => { var _a; return selection.has(row.index) && !((_a = row.problems) === null || _a === void 0 ? void 0 : _a.length); })
|
|
307
337
|
.map((row) => ({ index: row.index, details: row.details }));
|
|
338
|
+
/**
|
|
339
|
+
* A recorded outcome as the review can use it, or nothing.
|
|
340
|
+
*
|
|
341
|
+
* @remarks
|
|
342
|
+
* It comes back from history — a saved session, a later version's shape — so it is read, not
|
|
343
|
+
* trusted: a row that does not have its three fields is left out rather than shown wrong.
|
|
344
|
+
*
|
|
345
|
+
* @internal
|
|
346
|
+
*/
|
|
347
|
+
export function reviewOutcomeFrom(value) {
|
|
348
|
+
if (!value || typeof value !== 'object')
|
|
349
|
+
return undefined;
|
|
350
|
+
const { stopped, rows } = value;
|
|
351
|
+
if (typeof stopped !== 'boolean' || !Array.isArray(rows))
|
|
352
|
+
return undefined;
|
|
353
|
+
return {
|
|
354
|
+
stopped,
|
|
355
|
+
rows: rows
|
|
356
|
+
.filter((row) => row &&
|
|
357
|
+
typeof row.index === 'number' &&
|
|
358
|
+
typeof row.status === 'string' &&
|
|
359
|
+
typeof row.message === 'string')
|
|
360
|
+
.map(({ index, status, message }) => ({ index, status, message })),
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* What a stopped write's closed review says: how many of its approved rows were written.
|
|
365
|
+
*
|
|
366
|
+
* @remarks
|
|
367
|
+
* Counted in three, never two: a row that was sent and got no answer (`unknown`) may well have
|
|
368
|
+
* been written, and counting it as not written is how a record gets written twice.
|
|
369
|
+
*
|
|
370
|
+
* @internal
|
|
371
|
+
*/
|
|
372
|
+
export function stoppedSummary(outcome) {
|
|
373
|
+
const written = outcome.rows.filter((row) => row.status === 'written').length;
|
|
374
|
+
const unknown = outcome.rows.filter((row) => row.status === 'unknown').length;
|
|
375
|
+
const notWritten = outcome.rows.length - written - unknown;
|
|
376
|
+
return (`Stopped while writing: ${written} written, ${notWritten} not written` +
|
|
377
|
+
`${unknown ? `, ${unknown} may have been written` : ''}.`);
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* What an approved row's mark says, from its recorded fate, in words for the user.
|
|
381
|
+
*
|
|
382
|
+
* @remarks
|
|
383
|
+
* A fate's `message` is written for the MODEL ("Read it again before proposing…"), so it is shown
|
|
384
|
+
* only where it carries the app's or the database's own refusal, which is the reason the user
|
|
385
|
+
* needs. A status this version does not know is marked as possibly written: the safe end, since
|
|
386
|
+
* a row counted as not written is one a user may write twice.
|
|
387
|
+
*
|
|
388
|
+
* @internal
|
|
389
|
+
*/
|
|
390
|
+
export function rowFate(fate) {
|
|
391
|
+
switch (fate.status) {
|
|
392
|
+
case 'written':
|
|
393
|
+
return 'written';
|
|
394
|
+
case 'checked':
|
|
395
|
+
return 'checked, not written';
|
|
396
|
+
case 'stopped':
|
|
397
|
+
return 'not written (stopped)';
|
|
398
|
+
case 'changed_since_review':
|
|
399
|
+
return 'not written (changed since the review)';
|
|
400
|
+
case 'gone':
|
|
401
|
+
return 'not written (row changed or no longer exists)';
|
|
402
|
+
case 'invalid_payload':
|
|
403
|
+
return 'not written (not valid)';
|
|
404
|
+
case 'unavailable':
|
|
405
|
+
return 'not written (the app cannot take this action)';
|
|
406
|
+
case 'failed':
|
|
407
|
+
return 'not written (not sent)';
|
|
408
|
+
case 'refused_by_app':
|
|
409
|
+
case 'duplicate':
|
|
410
|
+
case 'database_error':
|
|
411
|
+
return fate.message;
|
|
412
|
+
default:
|
|
413
|
+
return 'may have been written';
|
|
414
|
+
}
|
|
415
|
+
}
|