@genesislcap/ai-assistant 15.40.0 → 15.41.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 +409 -9
- package/dist/ai-assistant.d.ts +196 -6
- package/dist/chat-driver.cjs +567 -134
- package/dist/chat-driver.cjs.map +3 -3
- package/dist/chat-driver.mjs +560 -134
- package/dist/chat-driver.mjs.map +3 -3
- package/dist/custom-elements.json +1258 -687
- package/dist/dts/chat-driver-node.d.ts +2 -2
- package/dist/dts/chat-driver-node.d.ts.map +1 -1
- package/dist/dts/components/ai-driver/ai-driver.d.ts +4 -0
- package/dist/dts/components/ai-driver/ai-driver.d.ts.map +1 -1
- package/dist/dts/components/chat-driver/chat-driver.d.ts +121 -4
- package/dist/dts/components/chat-driver/chat-driver.d.ts.map +1 -1
- package/dist/dts/components/chat-driver/interaction-controller.d.ts.map +1 -1
- package/dist/dts/components/chat-driver/turn-failures.d.ts +7 -1
- package/dist/dts/components/chat-driver/turn-failures.d.ts.map +1 -1
- package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts +3 -1
- package/dist/dts/components/orchestrating-driver/orchestrating-driver.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 +21 -0
- package/dist/dts/genesis/register-genesis-assistant.d.ts.map +1 -1
- package/dist/dts/genesis/review-model.d.ts +40 -0
- package/dist/dts/genesis/review-model.d.ts.map +1 -1
- package/dist/dts/genesis/review-payload.d.ts +47 -0
- package/dist/dts/genesis/review-payload.d.ts.map +1 -0
- package/dist/dts/genesis/write-review/write-review.d.ts +75 -11
- 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 +49 -0
- package/dist/dts/genesis/write-tools.d.ts.map +1 -1
- package/dist/dts/genesis/write-turn.d.ts +114 -0
- package/dist/dts/genesis/write-turn.d.ts.map +1 -0
- package/dist/dts/index.d.ts +2 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/main/budget-controller.d.ts +12 -2
- package/dist/dts/main/budget-controller.d.ts.map +1 -1
- package/dist/dts/main/main.d.ts +33 -6
- package/dist/dts/main/main.d.ts.map +1 -1
- package/dist/dts/react.d.ts +2 -1
- package/dist/dts/state/ai-assistant-slice.d.ts +15 -0
- package/dist/dts/state/ai-assistant-slice.d.ts.map +1 -1
- package/dist/dts/state/session-store.d.ts +1 -0
- package/dist/dts/state/session-store.d.ts.map +1 -1
- package/dist/dts/suggestions/generate-suggestions.d.ts.map +1 -1
- package/dist/dts/utils/history-transform.d.ts.map +1 -1
- package/dist/esm/chat-driver-node.js +5 -1
- package/dist/esm/components/chat-driver/chat-driver.js +431 -92
- package/dist/esm/components/chat-driver/interaction-controller.js +25 -2
- package/dist/esm/components/chat-driver/turn-failures.js +9 -2
- package/dist/esm/components/orchestrating-driver/orchestrating-driver.js +30 -4
- package/dist/esm/genesis/register-genesis-assistant.js +38 -2
- package/dist/esm/genesis/review-model.js +47 -1
- package/dist/esm/genesis/review-payload.js +18 -0
- package/dist/esm/genesis/write-review/write-review.js +225 -40
- package/dist/esm/genesis/write-review/write-review.styles.js +18 -0
- package/dist/esm/genesis/write-review/write-review.template.js +46 -22
- package/dist/esm/genesis/write-tools.js +321 -49
- package/dist/esm/genesis/write-turn.js +110 -0
- package/dist/esm/main/budget-controller.js +39 -5
- package/dist/esm/main/main.js +45 -23
- package/dist/esm/state/ai-assistant-slice.js +11 -1
- package/dist/esm/state/debug-event-log.js +1 -1
- package/dist/esm/suggestions/generate-suggestions.js +4 -1
- package/dist/esm/utils/history-transform.js +7 -1
- package/dist/react.cjs +14 -2
- package/dist/react.mjs +14 -2
- package/docs/genesis.md +120 -3
- package/docs/migration-GENC-1464.md +12 -2
- package/docs/sub_agent.md +21 -4
- package/package.json +18 -18
- package/scripts/smoke-chat-driver-node.mjs +15 -0
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
2
|
import { customElement, GenesisElement, observable } from '@genesislcap/web-core';
|
|
3
|
-
import { canWrite, initialSelection, restoredSelection } from '../review-model';
|
|
3
|
+
import { canWrite, initialSelection, restoredSelection, reviewDecisionOf, } from '../review-model';
|
|
4
|
+
import { MAX_FEEDBACK_CHARS, } from '../review-payload';
|
|
5
|
+
import { isBlankText } from '../write-payload';
|
|
4
6
|
import { WriteReviewStyles as styles } from './write-review.styles';
|
|
5
7
|
import { WriteReviewTemplate as template } from './write-review.template';
|
|
6
8
|
/**
|
|
@@ -9,11 +11,49 @@ import { WriteReviewTemplate as template } from './write-review.template';
|
|
|
9
11
|
* @beta
|
|
10
12
|
*/
|
|
11
13
|
export const GENESIS_WRITE_REVIEW = 'genesis-write-review';
|
|
14
|
+
/**
|
|
15
|
+
* Every ASCII punctuation mark, as its four ranges: CommonMark makes any of them literal behind a
|
|
16
|
+
* backslash.
|
|
17
|
+
*/
|
|
18
|
+
const ASCII_PUNCTUATION = /[!-/:-@[-`{-~]/g;
|
|
19
|
+
/**
|
|
20
|
+
* The user's words as markdown that renders as exactly those words.
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* The echo is drawn by the chat's markdown renderer, as a typed message is, while the model gets
|
|
24
|
+
* the text as it is. So `use *500*` showed as emphasis, a `<b>` vanished, and lines ran together:
|
|
25
|
+
* the bubble told the user something other than what the model was told. Every punctuation mark
|
|
26
|
+
* is escaped, and each line break made a hard one. For trimmed text: a break at the very end
|
|
27
|
+
* would show as a stray backslash.
|
|
28
|
+
*/
|
|
29
|
+
const literalMarkdown = (text) => text
|
|
30
|
+
.split(/\r\n|\r|\n/)
|
|
31
|
+
.map((line) => line.replace(ASCII_PUNCTUATION, '\\$&'))
|
|
32
|
+
.join('\\\n');
|
|
33
|
+
/**
|
|
34
|
+
* Reviews answered on this page, by interaction id, until a review showing them resolved takes
|
|
35
|
+
* the entry.
|
|
36
|
+
*
|
|
37
|
+
* @remarks
|
|
38
|
+
* The review that answers is not the one that shows the answer. The host rebuilds its trailing
|
|
39
|
+
* interaction row on every history update (`repeat` with `recycle: false`), so the resolved
|
|
40
|
+
* review arrives as a FRESH element, already holding its outcome. A live region that starts
|
|
41
|
+
* populated announces nothing, and the button that was pressed goes with the old element, which
|
|
42
|
+
* drops focus to the page. This is how the fresh one knows it is showing an answer given just now
|
|
43
|
+
* rather than one read back from history, which must neither announce nor take focus. Taken once:
|
|
44
|
+
* the next re-mount of the same review is history.
|
|
45
|
+
*/
|
|
46
|
+
const answeredHere = new Map();
|
|
47
|
+
/**
|
|
48
|
+
* How long a fresh live region stays empty before it is given the outcome. A region added with its
|
|
49
|
+
* text already in it is not announced; one that is there, empty, and then fills is.
|
|
50
|
+
*/
|
|
51
|
+
const ANNOUNCE_DELAY_MS = 100;
|
|
12
52
|
/** Where a still-open review parks what the user has done, on its interaction context's state. */
|
|
13
53
|
const PARKED = {
|
|
14
54
|
selected: 'selected',
|
|
15
|
-
|
|
16
|
-
|
|
55
|
+
asking: 'asking',
|
|
56
|
+
changeText: 'changeText',
|
|
17
57
|
};
|
|
18
58
|
/**
|
|
19
59
|
* The review a user reads before anything is written.
|
|
@@ -29,6 +69,8 @@ const PARKED = {
|
|
|
29
69
|
* discipline: nothing this component returns could be a rebuilt or cloned row, because it
|
|
30
70
|
* returns no rows at all.
|
|
31
71
|
*
|
|
72
|
+
* @fires interaction-completed - Fired once, when the user writes, asks for changes or denies. detail: `GenesisWriteReviewCompletedEventDetail`
|
|
73
|
+
*
|
|
32
74
|
* @beta
|
|
33
75
|
*/
|
|
34
76
|
let GenesisWriteReview = class GenesisWriteReview extends GenesisElement {
|
|
@@ -38,13 +80,21 @@ let GenesisWriteReview = class GenesisWriteReview extends GenesisElement {
|
|
|
38
80
|
this.interactionId = '';
|
|
39
81
|
/** Chosen rows, by index. Starts empty — see {@link canWrite} and the model's own reasoning. */
|
|
40
82
|
this.selected = initialSelection();
|
|
41
|
-
/** True while the user is writing
|
|
42
|
-
this.
|
|
43
|
-
|
|
83
|
+
/** True while the user is writing what they want changed. */
|
|
84
|
+
this.asking = false;
|
|
85
|
+
/** What they have typed so far. */
|
|
86
|
+
this.changeText = '';
|
|
87
|
+
/** What the live region says: the outcome once the review has resolved. See `sayOutcome`. */
|
|
88
|
+
this.announcement = '';
|
|
89
|
+
/**
|
|
90
|
+
* Set when this element sends its answer. The host marks the review resolved after that, and
|
|
91
|
+
* until it did, a second click sent a second answer — a Deny straight after a Write included.
|
|
92
|
+
*/
|
|
93
|
+
this.answered = false;
|
|
44
94
|
}
|
|
45
95
|
/**
|
|
46
96
|
* The rows, whether the review is still open or already resolved: a user who has approved a
|
|
47
|
-
* write should still be able to see what they approved. Acting on it is what `
|
|
97
|
+
* write should still be able to see what they approved. Acting on it is what `settled`
|
|
48
98
|
* stops, not reading it.
|
|
49
99
|
*/
|
|
50
100
|
get model() {
|
|
@@ -55,21 +105,28 @@ let GenesisWriteReview = class GenesisWriteReview extends GenesisElement {
|
|
|
55
105
|
var _a;
|
|
56
106
|
return ((_a = this.interaction) === null || _a === void 0 ? void 0 : _a.status) === 'resolved';
|
|
57
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Whether the review is past taking input: it has resolved, or it has sent its answer. Every
|
|
110
|
+
* action checks this rather than `resolved`, which is still false in between.
|
|
111
|
+
*/
|
|
112
|
+
get settled() {
|
|
113
|
+
return this.resolved || this.answered;
|
|
114
|
+
}
|
|
58
115
|
/**
|
|
59
116
|
* The rows the user approved, once the review has resolved — empty for a rejection or a
|
|
60
117
|
* timeout, and while it is still open.
|
|
61
118
|
*/
|
|
62
119
|
get approved() {
|
|
63
|
-
var _a, _b
|
|
120
|
+
var _a, _b;
|
|
64
121
|
const interaction = this.interaction;
|
|
65
|
-
if ((interaction === null || interaction === void 0 ? void 0 : interaction.status) !== 'resolved'
|
|
122
|
+
if ((interaction === null || interaction === void 0 ? void 0 : interaction.status) !== 'resolved')
|
|
66
123
|
return [];
|
|
67
|
-
const
|
|
124
|
+
const read = reviewDecisionOf(interaction.result, this.model);
|
|
68
125
|
// Only rows that COULD be approved: a refused row's index in a payload is not an approval of
|
|
69
126
|
// it, and counting it would tell the user a row was approved that the review never offered.
|
|
70
|
-
const selectable = (
|
|
71
|
-
return
|
|
72
|
-
?
|
|
127
|
+
const selectable = (_b = (_a = this.model) === null || _a === void 0 ? void 0 : _a.selectable) !== null && _b !== void 0 ? _b : [];
|
|
128
|
+
return read.decision === 'approved'
|
|
129
|
+
? read.rows.filter((index) => selectable.includes(index))
|
|
73
130
|
: [];
|
|
74
131
|
}
|
|
75
132
|
/**
|
|
@@ -83,17 +140,23 @@ let GenesisWriteReview = class GenesisWriteReview extends GenesisElement {
|
|
|
83
140
|
* screen carry as well as the tints do.
|
|
84
141
|
*/
|
|
85
142
|
get closedSummary() {
|
|
86
|
-
var _a, _b;
|
|
87
143
|
const interaction = this.interaction;
|
|
88
144
|
if ((interaction === null || interaction === void 0 ? void 0 : interaction.status) !== 'resolved')
|
|
89
145
|
return '';
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
146
|
+
const read = reviewDecisionOf(interaction.result, this.model);
|
|
147
|
+
switch (read.decision) {
|
|
148
|
+
case 'approved':
|
|
149
|
+
// The reply is where the written rows are named, and a stopped turn has none: said, so the
|
|
150
|
+
// user is not left waiting on it.
|
|
151
|
+
return (`Approved ${this.approved.length} row(s). The reply says which were written; if the ` +
|
|
152
|
+
'turn was stopped, some may not be.');
|
|
153
|
+
case 'timed_out':
|
|
154
|
+
return 'Closed without a decision. Nothing was written.';
|
|
155
|
+
case 'changes_requested':
|
|
156
|
+
return `You asked for changes: “${read.text}”. Nothing was written.`;
|
|
157
|
+
default:
|
|
158
|
+
return 'Denied. Nothing was written.';
|
|
95
159
|
}
|
|
96
|
-
return 'Denied. Nothing was written.';
|
|
97
160
|
}
|
|
98
161
|
/**
|
|
99
162
|
* Every mount is a fresh element whose selection starts empty, so each state says where its
|
|
@@ -105,8 +168,8 @@ let GenesisWriteReview = class GenesisWriteReview extends GenesisElement {
|
|
|
105
168
|
* from the result, the one thing both paths have, and never from the context: the host disposes
|
|
106
169
|
* that on resolve, and a disposed context's state still holds whatever was last parked there.
|
|
107
170
|
*
|
|
108
|
-
* A PENDING review resumes from its interaction context what the user had ticked, and a
|
|
109
|
-
* they had started: a reparent, a dock or a transcript re-render rebuilds the element while
|
|
171
|
+
* A PENDING review resumes from its interaction context what the user had ticked, and a change
|
|
172
|
+
* request they had started: a reparent, a dock or a transcript re-render rebuilds the element while
|
|
110
173
|
* the review is open, and everything it held was dropped. Assigned once, not replayed through
|
|
111
174
|
* the setters, and never written back from here — only a user's action parks (see `park`).
|
|
112
175
|
* Each restored box goes from unticked to ticked once when it binds and echoes once, into a
|
|
@@ -116,15 +179,60 @@ let GenesisWriteReview = class GenesisWriteReview extends GenesisElement {
|
|
|
116
179
|
const interaction = this.interaction;
|
|
117
180
|
if ((interaction === null || interaction === void 0 ? void 0 : interaction.status) === 'resolved') {
|
|
118
181
|
this.selected = this.approved;
|
|
182
|
+
// A review that times out or is stopped while the user is typing closes the request too: it
|
|
183
|
+
// stayed open, and took typing that nothing would ever read.
|
|
184
|
+
this.asking = false;
|
|
185
|
+
this.sayOutcome();
|
|
119
186
|
return;
|
|
120
187
|
}
|
|
121
188
|
if ((interaction === null || interaction === void 0 ? void 0 : interaction.status) !== 'pending')
|
|
122
189
|
return;
|
|
123
190
|
const { state } = interaction.interactionContext;
|
|
124
191
|
this.selected = restoredSelection(interaction.data, state[PARKED.selected]);
|
|
125
|
-
this.
|
|
126
|
-
const
|
|
127
|
-
this.
|
|
192
|
+
this.asking = state[PARKED.asking] === true;
|
|
193
|
+
const text = state[PARKED.changeText];
|
|
194
|
+
this.changeText = typeof text === 'string' ? text : '';
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Puts the outcome in the live region, so that an answer given just now is heard, and one read
|
|
198
|
+
* back from history is not.
|
|
199
|
+
*
|
|
200
|
+
* @remarks
|
|
201
|
+
* An answer given on this page, by this element or by the one it replaced (see `answeredHere`),
|
|
202
|
+
* is said one way or the other, never both. If focus was inside the review when it was
|
|
203
|
+
* answered, focus moves to the outcome, which a screen reader reads on focus: moving it spares a
|
|
204
|
+
* keyboard user the jump to the top of the page when the pressed button went away. Otherwise
|
|
205
|
+
* the region starts empty and fills a moment later, which is what gets it announced. An outcome
|
|
206
|
+
* read back from history is just shown: announcing it, or taking focus, on every re-render of
|
|
207
|
+
* a transcript would be noise at best.
|
|
208
|
+
*/
|
|
209
|
+
sayOutcome() {
|
|
210
|
+
var _a;
|
|
211
|
+
const answered = (_a = this.answeredNow) !== null && _a !== void 0 ? _a : answeredHere.get(this.interactionId);
|
|
212
|
+
this.answeredNow = undefined;
|
|
213
|
+
answeredHere.delete(this.interactionId);
|
|
214
|
+
if (!answered || answered.focused) {
|
|
215
|
+
this.announcement = this.closedSummary;
|
|
216
|
+
if (answered)
|
|
217
|
+
this.focusSoon('.closed');
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
this.announcement = '';
|
|
221
|
+
setTimeout(() => {
|
|
222
|
+
if (this.isConnected)
|
|
223
|
+
this.announcement = this.closedSummary;
|
|
224
|
+
}, ANNOUNCE_DELAY_MS);
|
|
225
|
+
}
|
|
226
|
+
/** Whether focus is on something inside this review, however deep in shadow roots. */
|
|
227
|
+
hasFocus() {
|
|
228
|
+
var _a, _b;
|
|
229
|
+
let active = document.activeElement;
|
|
230
|
+
while (active) {
|
|
231
|
+
if (active === this)
|
|
232
|
+
return true;
|
|
233
|
+
active = (_b = (_a = active.shadowRoot) === null || _a === void 0 ? void 0 : _a.activeElement) !== null && _b !== void 0 ? _b : null;
|
|
234
|
+
}
|
|
235
|
+
return false;
|
|
128
236
|
}
|
|
129
237
|
/**
|
|
130
238
|
* Keeps what the user has done so far on the interaction's context, where the next mount of a
|
|
@@ -143,15 +251,15 @@ let GenesisWriteReview = class GenesisWriteReview extends GenesisElement {
|
|
|
143
251
|
return;
|
|
144
252
|
const { state } = interaction.interactionContext;
|
|
145
253
|
state[PARKED.selected] = [...this.selected];
|
|
146
|
-
state[PARKED.
|
|
147
|
-
state[PARKED.
|
|
254
|
+
state[PARKED.asking] = this.asking;
|
|
255
|
+
state[PARKED.changeText] = this.changeText;
|
|
148
256
|
}
|
|
149
257
|
get rowsSelected() {
|
|
150
258
|
return this.selected.length;
|
|
151
259
|
}
|
|
152
260
|
/** Whether Write may fire: never on an empty selection. */
|
|
153
261
|
get writable() {
|
|
154
|
-
return !this.
|
|
262
|
+
return !this.settled && canWrite(this.selected);
|
|
155
263
|
}
|
|
156
264
|
get allSelected() {
|
|
157
265
|
var _a, _b;
|
|
@@ -176,7 +284,7 @@ let GenesisWriteReview = class GenesisWriteReview extends GenesisElement {
|
|
|
176
284
|
*/
|
|
177
285
|
setSelected(index, checked) {
|
|
178
286
|
var _a;
|
|
179
|
-
if (this.
|
|
287
|
+
if (this.settled || !((_a = this.model) === null || _a === void 0 ? void 0 : _a.selectable.includes(index)))
|
|
180
288
|
return;
|
|
181
289
|
if (checked === this.isSelected(index))
|
|
182
290
|
return;
|
|
@@ -197,7 +305,7 @@ let GenesisWriteReview = class GenesisWriteReview extends GenesisElement {
|
|
|
197
305
|
*/
|
|
198
306
|
setAll(checked) {
|
|
199
307
|
var _a, _b;
|
|
200
|
-
if (this.
|
|
308
|
+
if (this.settled || checked === this.allSelected)
|
|
201
309
|
return;
|
|
202
310
|
this.selected = checked ? [...((_b = (_a = this.model) === null || _a === void 0 ? void 0 : _a.selectable) !== null && _b !== void 0 ? _b : [])] : [];
|
|
203
311
|
this.park();
|
|
@@ -214,23 +322,94 @@ let GenesisWriteReview = class GenesisWriteReview extends GenesisElement {
|
|
|
214
322
|
}
|
|
215
323
|
/** The one way this widget talks back: `interaction-completed`, exactly once. */
|
|
216
324
|
resolve(result) {
|
|
325
|
+
this.answered = true;
|
|
326
|
+
// Taken now, while the pressed button still has focus: it is disabled on the next render.
|
|
327
|
+
const answered = { focused: this.hasFocus() };
|
|
328
|
+
this.answeredNow = answered;
|
|
329
|
+
// For the element that will show the outcome, when the host rebuilds this one (see
|
|
330
|
+
// answeredHere). A review mounted without an id cannot be found again, so it is not recorded.
|
|
331
|
+
if (this.interactionId)
|
|
332
|
+
answeredHere.set(this.interactionId, answered);
|
|
217
333
|
this.$emit('interaction-completed', result);
|
|
218
334
|
}
|
|
219
|
-
|
|
220
|
-
|
|
335
|
+
/**
|
|
336
|
+
* No, and nothing else: one click, no reason. Denying is the safe direction — nothing is
|
|
337
|
+
* written, and the tool is not proposed again this turn — so it needs no confirmation. A reason
|
|
338
|
+
* the user wants acted on is a change request, which is what "Ask for changes" is for; a deny
|
|
339
|
+
* reason travelled inside a result the model is told to treat as data, and was ignored.
|
|
340
|
+
*/
|
|
341
|
+
deny() {
|
|
342
|
+
if (this.settled)
|
|
343
|
+
return;
|
|
344
|
+
this.resolve({ status: 'rejected' });
|
|
345
|
+
}
|
|
346
|
+
/** Opens the change request, and puts the cursor in it. */
|
|
347
|
+
startAsking() {
|
|
348
|
+
if (this.settled)
|
|
349
|
+
return;
|
|
350
|
+
this.asking = true;
|
|
221
351
|
this.park();
|
|
352
|
+
this.focusSoon('.change-request', 'textarea');
|
|
222
353
|
}
|
|
223
|
-
/**
|
|
224
|
-
|
|
225
|
-
this.
|
|
354
|
+
/** Closes the change request without sending it; the text is kept for a second try. */
|
|
355
|
+
back() {
|
|
356
|
+
if (this.settled)
|
|
357
|
+
return;
|
|
358
|
+
this.asking = false;
|
|
226
359
|
this.park();
|
|
360
|
+
this.focusSoon('.ask', 'button');
|
|
227
361
|
}
|
|
228
|
-
|
|
229
|
-
|
|
362
|
+
/** The change request as the user types it, until the review has its answer. */
|
|
363
|
+
setChangeText(text) {
|
|
364
|
+
if (this.settled)
|
|
230
365
|
return;
|
|
366
|
+
this.changeText = text;
|
|
367
|
+
this.park();
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* How much more the change request can take. The field stops at the cap without a sound, so the
|
|
371
|
+
* count is on screen rather than discovered by typing into it.
|
|
372
|
+
*/
|
|
373
|
+
get charactersLeft() {
|
|
374
|
+
return Math.max(0, MAX_FEEDBACK_CHARS - this.changeText.length);
|
|
375
|
+
}
|
|
376
|
+
/** Whether there is a change to send: text that shows something. */
|
|
377
|
+
get canSendChanges() {
|
|
378
|
+
return !this.settled && this.asking && !isBlankText(this.changeText);
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Sends the change request. Nothing is written, whatever is ticked: the rows that were ticked
|
|
382
|
+
* travel as context for the next proposal, which the user approves in a fresh review. They are
|
|
383
|
+
* the review's own indexes, in the order it shows them, so they can be matched against the rows
|
|
384
|
+
* of the tool's result. `userMessage` shows the request on the user's side of the chat, as the
|
|
385
|
+
* words the model gets (see `literalMarkdown`); the driver never sends that to the model.
|
|
386
|
+
*/
|
|
387
|
+
sendChanges() {
|
|
388
|
+
var _a, _b;
|
|
389
|
+
if (!this.canSendChanges)
|
|
390
|
+
return;
|
|
391
|
+
const text = this.changeText.trim();
|
|
392
|
+
const rowsTicked = ((_b = (_a = this.model) === null || _a === void 0 ? void 0 : _a.rows) !== null && _b !== void 0 ? _b : [])
|
|
393
|
+
.map((row) => row.index)
|
|
394
|
+
.filter((index) => this.selected.includes(index));
|
|
231
395
|
this.resolve({
|
|
232
396
|
status: 'rejected',
|
|
233
|
-
|
|
397
|
+
payload: Object.assign({ changes: text }, (rowsTicked.length ? { rowsTicked } : {})),
|
|
398
|
+
userMessage: literalMarkdown(text),
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Focuses an element the next render adds. The design-system controls do not delegate focus,
|
|
403
|
+
* so this drills into the control's own shadow root (see the chat input's
|
|
404
|
+
* `maybeAutoFocusChatInput`), and falls back to the host.
|
|
405
|
+
*/
|
|
406
|
+
focusSoon(selector, inner) {
|
|
407
|
+
requestAnimationFrame(() => {
|
|
408
|
+
var _a, _b, _c, _d;
|
|
409
|
+
if (!this.isConnected)
|
|
410
|
+
return;
|
|
411
|
+
const host = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector(selector);
|
|
412
|
+
(_d = ((_c = (inner ? (_b = host === null || host === void 0 ? void 0 : host.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector(inner) : undefined)) !== null && _c !== void 0 ? _c : host)) === null || _d === void 0 ? void 0 : _d.focus();
|
|
234
413
|
});
|
|
235
414
|
}
|
|
236
415
|
};
|
|
@@ -242,10 +421,16 @@ __decorate([
|
|
|
242
421
|
], GenesisWriteReview.prototype, "selected", void 0);
|
|
243
422
|
__decorate([
|
|
244
423
|
observable
|
|
245
|
-
], GenesisWriteReview.prototype, "
|
|
424
|
+
], GenesisWriteReview.prototype, "asking", void 0);
|
|
425
|
+
__decorate([
|
|
426
|
+
observable
|
|
427
|
+
], GenesisWriteReview.prototype, "changeText", void 0);
|
|
428
|
+
__decorate([
|
|
429
|
+
observable
|
|
430
|
+
], GenesisWriteReview.prototype, "announcement", void 0);
|
|
246
431
|
__decorate([
|
|
247
432
|
observable
|
|
248
|
-
], GenesisWriteReview.prototype, "
|
|
433
|
+
], GenesisWriteReview.prototype, "answered", void 0);
|
|
249
434
|
GenesisWriteReview = __decorate([
|
|
250
435
|
customElement({ name: GENESIS_WRITE_REVIEW, template, styles })
|
|
251
436
|
], GenesisWriteReview);
|
|
@@ -211,4 +211,22 @@ export const WriteReviewStyles = css `
|
|
|
211
211
|
gap: calc(var(--design-unit, 4) * 2px);
|
|
212
212
|
margin-top: calc(var(--design-unit, 4) * 2px);
|
|
213
213
|
}
|
|
214
|
+
|
|
215
|
+
/* The change request takes the width the buttons leave it. */
|
|
216
|
+
.change-request {
|
|
217
|
+
flex: 1 1 24ch;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/* The outcome's live region is always there; while the review is open it takes no room. */
|
|
221
|
+
.closed:empty {
|
|
222
|
+
margin: 0;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/* The count sits at the foot of the field, beside it rather than in its way. */
|
|
226
|
+
.remaining {
|
|
227
|
+
align-self: flex-end;
|
|
228
|
+
white-space: nowrap;
|
|
229
|
+
font-size: var(--type-ramp-minus-1-font-size, 0.875em);
|
|
230
|
+
color: var(--neutral-foreground-hint);
|
|
231
|
+
}
|
|
214
232
|
`;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { html, repeat, when } from '@genesislcap/web-core';
|
|
2
|
+
import { MAX_FEEDBACK_CHARS } from '../review-payload';
|
|
2
3
|
import { isBlankText } from '../write-payload';
|
|
3
4
|
/**
|
|
4
5
|
* What a checkbox says NOW, read from the event rather than inferred from the state.
|
|
@@ -98,7 +99,7 @@ const row = html `
|
|
|
98
99
|
aria-label="Select ${(x) => x.label}"
|
|
99
100
|
aria-describedby="${(x) => { var _a; return (((_a = x.problems) === null || _a === void 0 ? void 0 : _a.length) ? `problems-${x.index}` : ''); }}"
|
|
100
101
|
:checked="${(x, c) => c.parent.isSelected(x.index)}"
|
|
101
|
-
?disabled="${(x, c) => { var _a; return !!((_a = x.problems) === null || _a === void 0 ? void 0 : _a.length) || c.parent.
|
|
102
|
+
?disabled="${(x, c) => { var _a; return !!((_a = x.problems) === null || _a === void 0 ? void 0 : _a.length) || c.parent.settled; }}"
|
|
102
103
|
@change="${(x, c) => c.parent.setSelected(x.index, checkedOf(c.event))}"
|
|
103
104
|
></rapid-checkbox>
|
|
104
105
|
${when((x, c) => rowClass(x, c.parent) === 'added', html `
|
|
@@ -136,7 +137,7 @@ export const WriteReviewTemplate = html `
|
|
|
136
137
|
<rapid-checkbox
|
|
137
138
|
aria-label="Select all rows"
|
|
138
139
|
:checked="${(x) => x.allSelected}"
|
|
139
|
-
?disabled="${(x) => { var _a; return x.
|
|
140
|
+
?disabled="${(x) => { var _a; return x.settled || !((_a = x.model) === null || _a === void 0 ? void 0 : _a.selectable.length); }}"
|
|
140
141
|
@change="${(x, c) => x.setAll(checkedOf(c.event))}"
|
|
141
142
|
></rapid-checkbox>
|
|
142
143
|
</th>
|
|
@@ -149,34 +150,57 @@ export const WriteReviewTemplate = html `
|
|
|
149
150
|
</table>
|
|
150
151
|
</div>
|
|
151
152
|
<div class="actions">
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
<rapid-button
|
|
153
|
+
${when((x) => !x.asking, html `
|
|
154
|
+
<rapid-button
|
|
155
|
+
appearance="accent"
|
|
156
|
+
?disabled="${(x) => !x.writable}"
|
|
157
|
+
@click="${(x) => x.write()}"
|
|
158
|
+
>
|
|
159
|
+
Write ${(x) => (x.rowsSelected ? `${x.rowsSelected} row(s)` : '')}
|
|
160
|
+
</rapid-button>
|
|
161
|
+
<rapid-button
|
|
162
|
+
class="ask"
|
|
163
|
+
?disabled="${(x) => x.settled}"
|
|
164
|
+
@click="${(x) => x.startAsking()}"
|
|
165
|
+
>
|
|
166
|
+
Ask for changes
|
|
167
|
+
</rapid-button>
|
|
168
|
+
<rapid-button ?disabled="${(x) => x.settled}" @click="${(x) => x.deny()}">
|
|
161
169
|
Deny
|
|
162
170
|
</rapid-button>
|
|
163
171
|
`)}
|
|
164
|
-
${when((x) => x.
|
|
165
|
-
<rapid-text-
|
|
166
|
-
|
|
167
|
-
:value="${(x) => x.
|
|
172
|
+
${when((x) => x.asking, html `
|
|
173
|
+
<rapid-text-area
|
|
174
|
+
class="change-request"
|
|
175
|
+
:value="${(x) => x.changeText}"
|
|
176
|
+
?readonly="${(x) => x.settled}"
|
|
177
|
+
maxlength="${() => MAX_FEEDBACK_CHARS}"
|
|
168
178
|
@input="${(x, c) => {
|
|
169
|
-
x.
|
|
179
|
+
x.setChangeText(c.event.target.value);
|
|
170
180
|
return true;
|
|
171
181
|
}}"
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
182
|
+
>
|
|
183
|
+
What should change?
|
|
184
|
+
</rapid-text-area>
|
|
185
|
+
<span class="remaining">${(x) => x.charactersLeft} characters left</span>
|
|
186
|
+
<rapid-button
|
|
187
|
+
class="send"
|
|
188
|
+
appearance="accent"
|
|
189
|
+
?disabled="${(x) => !x.canSendChanges}"
|
|
190
|
+
@click="${(x) => x.sendChanges()}"
|
|
191
|
+
>
|
|
192
|
+
Send
|
|
193
|
+
</rapid-button>
|
|
194
|
+
<rapid-button class="back" ?disabled="${(x) => x.settled}" @click="${(x) => x.back()}">
|
|
195
|
+
Back
|
|
175
196
|
</rapid-button>
|
|
176
197
|
`)}
|
|
177
198
|
</div>
|
|
178
199
|
`)}
|
|
179
|
-
${
|
|
180
|
-
|
|
181
|
-
|
|
200
|
+
${
|
|
201
|
+
/* A live region, and there from the start: a screen reader announces a change to one it
|
|
202
|
+
already knows, and a region added with its text already in it was not announced at all.
|
|
203
|
+
Empty while the review is open; filled by sayOutcome, which also decides when. Focusable
|
|
204
|
+
from script only, so focus can land on the outcome after an answer. */ ''}
|
|
205
|
+
<p class="closed" role="status" tabindex="-1">${(x) => x.announcement}</p>
|
|
182
206
|
`;
|