@molecule/app-ide-panel-logic 1.3.1 → 1.4.1
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/README.md +285 -3
- package/dist/chatTimelineOrdering.d.ts +175 -1
- package/dist/chatTimelineOrdering.d.ts.map +1 -1
- package/dist/chatTimelineOrdering.js +192 -1
- package/dist/chatTimelineOrdering.js.map +1 -1
- package/dist/components/chat-card-event-utilities.d.ts +320 -0
- package/dist/components/chat-card-event-utilities.d.ts.map +1 -0
- package/dist/components/chat-card-event-utilities.js +198 -0
- package/dist/components/chat-card-event-utilities.js.map +1 -0
- package/dist/components/chat-card-style.d.ts +7 -1
- package/dist/components/chat-card-style.d.ts.map +1 -1
- package/dist/components/chat-card-style.js +8 -2
- package/dist/components/chat-card-style.js.map +1 -1
- package/dist/components/chat-composer-utilities.d.ts +472 -0
- package/dist/components/chat-composer-utilities.d.ts.map +1 -0
- package/dist/components/chat-composer-utilities.js +519 -0
- package/dist/components/chat-composer-utilities.js.map +1 -0
- package/dist/components/chat-dictation-controller.d.ts +376 -0
- package/dist/components/chat-dictation-controller.d.ts.map +1 -0
- package/dist/components/chat-dictation-controller.js +559 -0
- package/dist/components/chat-dictation-controller.js.map +1 -0
- package/dist/components/chat-effort-utilities.d.ts +24 -0
- package/dist/components/chat-effort-utilities.d.ts.map +1 -1
- package/dist/components/chat-effort-utilities.js +41 -0
- package/dist/components/chat-effort-utilities.js.map +1 -1
- package/dist/components/chat-format-utilities.d.ts +71 -0
- package/dist/components/chat-format-utilities.d.ts.map +1 -0
- package/dist/components/chat-format-utilities.js +192 -0
- package/dist/components/chat-format-utilities.js.map +1 -0
- package/dist/components/chat-models-utilities.d.ts +168 -0
- package/dist/components/chat-models-utilities.d.ts.map +1 -1
- package/dist/components/chat-models-utilities.js +253 -0
- package/dist/components/chat-models-utilities.js.map +1 -1
- package/dist/components/chat-settings-utilities.d.ts +153 -1
- package/dist/components/chat-settings-utilities.d.ts.map +1 -1
- package/dist/components/chat-settings-utilities.js +204 -1
- package/dist/components/chat-settings-utilities.js.map +1 -1
- package/dist/components/chat-stream-utilities.d.ts +165 -1
- package/dist/components/chat-stream-utilities.d.ts.map +1 -1
- package/dist/components/chat-stream-utilities.js +155 -1
- package/dist/components/chat-stream-utilities.js.map +1 -1
- package/dist/components/chat-tests-controller.d.ts +249 -0
- package/dist/components/chat-tests-controller.d.ts.map +1 -0
- package/dist/components/chat-tests-controller.js +504 -0
- package/dist/components/chat-tests-controller.js.map +1 -0
- package/dist/components/chat-timeline-utilities.d.ts +90 -0
- package/dist/components/chat-timeline-utilities.d.ts.map +1 -0
- package/dist/components/chat-timeline-utilities.js +71 -0
- package/dist/components/chat-timeline-utilities.js.map +1 -0
- package/dist/components/chat-ui-constants.d.ts +98 -0
- package/dist/components/chat-ui-constants.d.ts.map +1 -0
- package/dist/components/chat-ui-constants.js +146 -0
- package/dist/components/chat-ui-constants.js.map +1 -0
- package/dist/components/chat-undo-utilities.d.ts +47 -0
- package/dist/components/chat-undo-utilities.d.ts.map +1 -0
- package/dist/components/chat-undo-utilities.js +73 -0
- package/dist/components/chat-undo-utilities.js.map +1 -0
- package/dist/components/context-usage-utilities.d.ts +25 -3
- package/dist/components/context-usage-utilities.d.ts.map +1 -1
- package/dist/components/context-usage-utilities.js +42 -2
- package/dist/components/context-usage-utilities.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/panels.d.ts +6 -0
- package/dist/panels.d.ts.map +1 -1
- package/dist/panels.js +6 -0
- package/dist/panels.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,504 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The chat panel's `/test` region as framework-neutral state and behaviour.
|
|
3
|
+
*
|
|
4
|
+
* The list and the in-flight run live in this controller, not inside the tests
|
|
5
|
+
* card, for one reason: the card is an overlay the person closes. A run that is
|
|
6
|
+
* streaming (a browser spec can take a minute) must survive that close and
|
|
7
|
+
* still be there when they re-open it, and re-running `/test` must re-list
|
|
8
|
+
* without killing it. So the card is presentational and this owns the state.
|
|
9
|
+
*
|
|
10
|
+
* Every framework's chat panel subscribes with {@link ChatTestsController.subscribe}
|
|
11
|
+
* and renders {@link ChatTestsController.snapshot}; the panel keeps its own
|
|
12
|
+
* effects where they are and starts the controller's work from them, so the
|
|
13
|
+
* order of the host's requests and of the timers cannot move. The controller
|
|
14
|
+
* reads everything else from its parameters, and performs no I/O when it is
|
|
15
|
+
* constructed.
|
|
16
|
+
*
|
|
17
|
+
* @module
|
|
18
|
+
*/
|
|
19
|
+
import { applyTestRunEvent, buildTestFixMessage, EMPTY_RUN_STATE, failRun, markSkipUnavailable, requestSkip, TestRunProjection, } from './tests-card-utilities.js';
|
|
20
|
+
/** Only COMPLETED own ids are bounded; active own ids are pinned separately. */
|
|
21
|
+
export const COMPLETED_OWN_TEST_RUN_ID_LIMIT = 32;
|
|
22
|
+
/**
|
|
23
|
+
* Remember a completed own run for its delayed feed copy.
|
|
24
|
+
*
|
|
25
|
+
* @param ids - The completed own-run ids, oldest first.
|
|
26
|
+
* @param runId - The run that just completed.
|
|
27
|
+
*/
|
|
28
|
+
export function rememberCompletedOwnTestRunId(ids, runId) {
|
|
29
|
+
ids.delete(runId);
|
|
30
|
+
ids.add(runId);
|
|
31
|
+
if (ids.size <= COMPLETED_OWN_TEST_RUN_ID_LIMIT)
|
|
32
|
+
return;
|
|
33
|
+
const oldest = ids.values().next();
|
|
34
|
+
if (!oldest.done)
|
|
35
|
+
ids.delete(oldest.value);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The tests region's state and behaviour (see the module docs). React (or a
|
|
39
|
+
* framework binding) subscribes to it, renders {@link ChatTestsController.snapshot},
|
|
40
|
+
* keeps its own effects where they are, and starts the controller's work from
|
|
41
|
+
* them.
|
|
42
|
+
*/
|
|
43
|
+
export class ChatTestsController {
|
|
44
|
+
list = [];
|
|
45
|
+
status = 'loading';
|
|
46
|
+
run = EMPTY_RUN_STATE;
|
|
47
|
+
// Each callback closes over its own folded run. Only this invocation owns
|
|
48
|
+
// controls; stopped/completed invocations can still report trailing verdicts.
|
|
49
|
+
ownRun = null;
|
|
50
|
+
// One incremental projection: per-file verdicts plus bounded live/latest run
|
|
51
|
+
// state. Server ids dedupe the direct stream and feed echo; legacy id-less
|
|
52
|
+
// custom hosts use the bounded id guard.
|
|
53
|
+
projection = new TestRunProjection();
|
|
54
|
+
activeOwnRunIds = new Set();
|
|
55
|
+
completedOwnRunIds = new Set();
|
|
56
|
+
// Live for the async callbacks, so a list resolving after an unmount, or a
|
|
57
|
+
// run event arriving then, never sets state on a dead tree.
|
|
58
|
+
mounted = true;
|
|
59
|
+
current = { list: this.list, status: this.status, run: this.run };
|
|
60
|
+
listeners = new Set();
|
|
61
|
+
isTurnInFlight;
|
|
62
|
+
now;
|
|
63
|
+
setTimer;
|
|
64
|
+
clearTimer;
|
|
65
|
+
warn;
|
|
66
|
+
/**
|
|
67
|
+
* Creates the controller. Performs no I/O.
|
|
68
|
+
*
|
|
69
|
+
* @param options - The environment it reads; every one has a default.
|
|
70
|
+
*/
|
|
71
|
+
constructor(options = {}) {
|
|
72
|
+
this.isTurnInFlight = options.isTurnInFlight ?? (() => false);
|
|
73
|
+
this.now = options.now ?? (() => Date.now());
|
|
74
|
+
this.setTimer = options.setTimer ?? ((callback, delayMs) => setTimeout(callback, delayMs));
|
|
75
|
+
this.clearTimer = options.clearTimer ?? ((timer) => clearTimeout(timer));
|
|
76
|
+
this.warn = options.warn ?? (() => { });
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The current state. The identity changes only when one of its fields does.
|
|
80
|
+
*
|
|
81
|
+
* @returns The snapshot to render.
|
|
82
|
+
*/
|
|
83
|
+
snapshot = () => this.current;
|
|
84
|
+
/**
|
|
85
|
+
* Listens for a new snapshot.
|
|
86
|
+
*
|
|
87
|
+
* @param listener - Called after each change.
|
|
88
|
+
* @returns Stops listening.
|
|
89
|
+
*/
|
|
90
|
+
subscribe = (listener) => {
|
|
91
|
+
this.listeners.add(listener);
|
|
92
|
+
return () => {
|
|
93
|
+
this.listeners.delete(listener);
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Marks the panel as mounted. React's mount effect calls this, so a reconnect
|
|
98
|
+
* (StrictMode/Suspense) does not permanently silence discovery and run events.
|
|
99
|
+
*/
|
|
100
|
+
mount() {
|
|
101
|
+
this.mounted = true;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Marks the panel as unmounted and gives up this panel's own run: its handle
|
|
105
|
+
* is cancelled and later run events are ignored.
|
|
106
|
+
*/
|
|
107
|
+
unmount() {
|
|
108
|
+
this.mounted = false;
|
|
109
|
+
const own = this.ownRun;
|
|
110
|
+
this.ownRun = null;
|
|
111
|
+
own?.handle?.cancel();
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Whether the panel is mounted — a list resolving after an unmount must not
|
|
115
|
+
* start a run the person can no longer see.
|
|
116
|
+
*
|
|
117
|
+
* @returns True while the panel is mounted.
|
|
118
|
+
*/
|
|
119
|
+
isMounted() {
|
|
120
|
+
return this.mounted;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Sets the listing status (the tests bar shows "loading" while discovery
|
|
124
|
+
* starts).
|
|
125
|
+
*
|
|
126
|
+
* @param status - The new status.
|
|
127
|
+
*/
|
|
128
|
+
setStatus(status) {
|
|
129
|
+
this.patch({ status });
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* The list request alone: every state change follows the host's answer.
|
|
133
|
+
*
|
|
134
|
+
* @param list - The host's discovery function.
|
|
135
|
+
* @returns A promise resolved once the listing settled.
|
|
136
|
+
*/
|
|
137
|
+
loadTests(list) {
|
|
138
|
+
return list().then((found) => {
|
|
139
|
+
if (!this.mounted)
|
|
140
|
+
return;
|
|
141
|
+
this.patch({ list: found.tests ?? [], status: 'ready' });
|
|
142
|
+
}, (error) => {
|
|
143
|
+
this.warn('Failed to list project tests', { error });
|
|
144
|
+
if (!this.mounted)
|
|
145
|
+
return;
|
|
146
|
+
this.patch({ status: 'error' });
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Re-reads the project's tests. A host that wires no discovery has no tests to
|
|
151
|
+
* show, and a down environment keeps the list the person was reading.
|
|
152
|
+
*
|
|
153
|
+
* @param host - The host's discovery and environment availability.
|
|
154
|
+
* @returns A promise resolved once the listing settled.
|
|
155
|
+
*/
|
|
156
|
+
async refreshTests(host) {
|
|
157
|
+
if (!host.listTests) {
|
|
158
|
+
this.patch({ status: 'error' });
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (host.testsAvailable === false) {
|
|
162
|
+
this.patch({ status: 'unavailable' });
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (this.status !== 'ready')
|
|
166
|
+
this.patch({ status: 'loading' });
|
|
167
|
+
await this.loadTests(host.listTests);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Starts this panel's own run over a selection.
|
|
171
|
+
*
|
|
172
|
+
* @param selection - What to run.
|
|
173
|
+
* @param host - The host's runner, permissions and translator.
|
|
174
|
+
*/
|
|
175
|
+
startTestsRun(selection, host) {
|
|
176
|
+
if (!host.runTests)
|
|
177
|
+
return;
|
|
178
|
+
if (host.canRunTests === false || host.canEdit === false)
|
|
179
|
+
return;
|
|
180
|
+
if (host.testsAvailable === false || this.run.running || this.ownRun)
|
|
181
|
+
return;
|
|
182
|
+
if (selection.ids?.length === 0)
|
|
183
|
+
return;
|
|
184
|
+
// Seed a running state immediately: the host's `start` event may be a
|
|
185
|
+
// round trip away, and a Run button that appears to do nothing is the
|
|
186
|
+
// failure this feature exists to remove.
|
|
187
|
+
const initial = {
|
|
188
|
+
...EMPTY_RUN_STATE,
|
|
189
|
+
running: true,
|
|
190
|
+
queued: [...(selection.ids ?? [])],
|
|
191
|
+
startedAt: this.now(),
|
|
192
|
+
external: false,
|
|
193
|
+
};
|
|
194
|
+
const invocation = {
|
|
195
|
+
state: initial,
|
|
196
|
+
handle: null,
|
|
197
|
+
ended: null,
|
|
198
|
+
};
|
|
199
|
+
this.ownRun = invocation;
|
|
200
|
+
const results = { ...this.run.results };
|
|
201
|
+
for (const id of initial.queued)
|
|
202
|
+
delete results[id];
|
|
203
|
+
this.patch({ run: { ...initial, results } });
|
|
204
|
+
try {
|
|
205
|
+
const handle = host.runTests(selection, (event) => {
|
|
206
|
+
if (!this.mounted)
|
|
207
|
+
return;
|
|
208
|
+
const current = this.ownRun === invocation;
|
|
209
|
+
const ended = invocation.ended;
|
|
210
|
+
invocation.state = applyTestRunEvent(invocation.state, event);
|
|
211
|
+
const runId = invocation.state.runId;
|
|
212
|
+
// Completion owns cleanup even when no start ever supplied an id. Otherwise one failed
|
|
213
|
+
// start leaves this invocation occupied and every later Run click returns early.
|
|
214
|
+
if (event.type === 'done') {
|
|
215
|
+
invocation.ended = event;
|
|
216
|
+
if (current)
|
|
217
|
+
this.ownRun = null;
|
|
218
|
+
void this.refreshTests(host);
|
|
219
|
+
}
|
|
220
|
+
if (runId == null) {
|
|
221
|
+
if (current)
|
|
222
|
+
this.patch({ run: invocation.state });
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if (event.type === 'start') {
|
|
226
|
+
this.recordOwnTestRunEvent(event);
|
|
227
|
+
if (ended) {
|
|
228
|
+
// A start delayed past cancellation is history, never a live own run.
|
|
229
|
+
invocation.state = applyTestRunEvent(invocation.state, ended);
|
|
230
|
+
this.recordOwnTestRunEvent({ ...ended, runId });
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
this.recordOwnTestRunEvent({ ...event, runId });
|
|
235
|
+
}
|
|
236
|
+
if (event.type === 'done' && !event.eventId) {
|
|
237
|
+
this.activeOwnRunIds.delete(runId);
|
|
238
|
+
rememberCompletedOwnTestRunId(this.completedOwnRunIds, runId);
|
|
239
|
+
}
|
|
240
|
+
this.projectTestsRun();
|
|
241
|
+
});
|
|
242
|
+
// The host is allowed to finish synchronously, before returning its
|
|
243
|
+
// handle. It no longer owns controls after handing the card onward.
|
|
244
|
+
if (this.ownRun !== invocation)
|
|
245
|
+
return;
|
|
246
|
+
invocation.handle = handle;
|
|
247
|
+
// Whether a Skip control belongs on screen is decided HERE, by whether
|
|
248
|
+
// this host's handle serves one — not by the card guessing, and not by
|
|
249
|
+
// a button that would do nothing when clicked.
|
|
250
|
+
const skips = typeof handle.skipCurrent === 'function';
|
|
251
|
+
invocation.state = {
|
|
252
|
+
...invocation.state,
|
|
253
|
+
skipPending: false,
|
|
254
|
+
skipUnavailable: !skips,
|
|
255
|
+
};
|
|
256
|
+
this.patch({ run: { ...this.run, skipPending: false, skipUnavailable: !skips } });
|
|
257
|
+
}
|
|
258
|
+
catch (error) {
|
|
259
|
+
this.warn('Failed to start a test run', { error });
|
|
260
|
+
if (this.ownRun !== invocation)
|
|
261
|
+
return;
|
|
262
|
+
this.ownRun = null;
|
|
263
|
+
const message = error instanceof Error
|
|
264
|
+
? error.message
|
|
265
|
+
: host.translate('ide.tests.runError', undefined, {
|
|
266
|
+
defaultValue: 'The test run could not start.',
|
|
267
|
+
});
|
|
268
|
+
const runId = invocation.state.runId;
|
|
269
|
+
if (runId != null) {
|
|
270
|
+
const done = { type: 'done', outcome: 'error', error: message };
|
|
271
|
+
invocation.ended = done;
|
|
272
|
+
invocation.state = applyTestRunEvent(invocation.state, done);
|
|
273
|
+
this.activeOwnRunIds.delete(runId);
|
|
274
|
+
this.recordOwnTestRunEvent({ ...done, runId });
|
|
275
|
+
this.projectTestsRun();
|
|
276
|
+
}
|
|
277
|
+
else if (this.projection.show().running) {
|
|
278
|
+
this.projectTestsRun();
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
this.patch({ run: failRun(this.run, message) });
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Stops this panel's own run. Only its own run can be stopped from here; the
|
|
287
|
+
* controls are not offered on a run it is only watching.
|
|
288
|
+
*/
|
|
289
|
+
cancelTestsRun() {
|
|
290
|
+
const invocation = this.ownRun;
|
|
291
|
+
if (!invocation)
|
|
292
|
+
return;
|
|
293
|
+
// Relinquish ownership before cancel(), which may synchronously call back.
|
|
294
|
+
this.ownRun = null;
|
|
295
|
+
const done = { type: 'done', outcome: 'cancelled' };
|
|
296
|
+
invocation.ended = done;
|
|
297
|
+
invocation.state = applyTestRunEvent(invocation.state, done);
|
|
298
|
+
const runId = invocation.state.runId;
|
|
299
|
+
if (runId != null) {
|
|
300
|
+
this.activeOwnRunIds.delete(runId);
|
|
301
|
+
this.recordOwnTestRunEvent({ ...done, runId });
|
|
302
|
+
this.projectTestsRun();
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
this.patch({ run: { ...invocation.state, skipUnavailable: true } });
|
|
306
|
+
}
|
|
307
|
+
invocation.handle?.cancel();
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Skips the command the run is ON, leaving the run itself alive. The state
|
|
311
|
+
* only records that the request went out — the run's own `result` for that
|
|
312
|
+
* file is what moves the row, so a skip can never paint itself as a pass. A
|
|
313
|
+
* host answering "there was nothing to skip" is a race the person did not
|
|
314
|
+
* cause: the control goes away, no error line.
|
|
315
|
+
*
|
|
316
|
+
* @param options - The panel's edit and run permissions.
|
|
317
|
+
*/
|
|
318
|
+
skipCurrentTest(options) {
|
|
319
|
+
if (options.canEdit === false || options.canRunTests === false)
|
|
320
|
+
return;
|
|
321
|
+
const invocation = this.ownRun;
|
|
322
|
+
if (!invocation)
|
|
323
|
+
return;
|
|
324
|
+
const skip = invocation.handle?.skipCurrent;
|
|
325
|
+
if (!invocation.handle || !skip) {
|
|
326
|
+
invocation.state = markSkipUnavailable(invocation.state);
|
|
327
|
+
this.patch({ run: markSkipUnavailable(this.run) });
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
invocation.state = requestSkip(invocation.state);
|
|
331
|
+
this.patch({ run: requestSkip(this.run) });
|
|
332
|
+
const handle = invocation.handle;
|
|
333
|
+
const unavailable = () => {
|
|
334
|
+
if (this.mounted && this.ownRun === invocation) {
|
|
335
|
+
invocation.state = markSkipUnavailable(invocation.state);
|
|
336
|
+
this.patch({ run: markSkipUnavailable(this.run) });
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
try {
|
|
340
|
+
const outcome = skip.call(handle);
|
|
341
|
+
if (outcome) {
|
|
342
|
+
void outcome.then((accepted) => {
|
|
343
|
+
if (accepted === false)
|
|
344
|
+
unavailable();
|
|
345
|
+
}, (error) => {
|
|
346
|
+
this.warn('Failed to skip the running test', { error });
|
|
347
|
+
unavailable();
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
catch (error) {
|
|
352
|
+
this.warn('Failed to skip the running test', { error });
|
|
353
|
+
unavailable();
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Skips the executor's in-flight tool call WITHOUT ending the turn — the
|
|
358
|
+
* model is told the command did not run and carries on.
|
|
359
|
+
*
|
|
360
|
+
* @param toolCallId - The tool call to skip.
|
|
361
|
+
* @param options - The panel's edit permission and the host's skip action.
|
|
362
|
+
* @returns The host's answer (`false` when it had already finished), or `false`
|
|
363
|
+
* when skipping is not allowed or the host failed.
|
|
364
|
+
*/
|
|
365
|
+
async handleSkipToolCall(toolCallId, options) {
|
|
366
|
+
if (options.canEdit === false || !options.skipToolCall)
|
|
367
|
+
return false;
|
|
368
|
+
try {
|
|
369
|
+
return await options.skipToolCall(toolCallId);
|
|
370
|
+
}
|
|
371
|
+
catch (error) {
|
|
372
|
+
this.warn('Failed to skip the running tool call', { error });
|
|
373
|
+
return false;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Hands the failing tests to the agent as ONE ordinary user message — the
|
|
378
|
+
* same move as the editor's "Fix with AI" and the auto-fix loop: compose the
|
|
379
|
+
* problem, send it through the normal path, let the turn answer. The overlay
|
|
380
|
+
* closes so the person watches the turn they just started.
|
|
381
|
+
*
|
|
382
|
+
* @param failures - The failing tests the card lists.
|
|
383
|
+
* @param options - The panel's edit permission, the overlay closer and the message sender.
|
|
384
|
+
*/
|
|
385
|
+
fixTests(failures, options) {
|
|
386
|
+
if (options.canEdit === false || failures.length === 0)
|
|
387
|
+
return;
|
|
388
|
+
if (this.isTurnInFlight())
|
|
389
|
+
return;
|
|
390
|
+
const message = buildTestFixMessage(failures);
|
|
391
|
+
if (!message)
|
|
392
|
+
return;
|
|
393
|
+
options.closeOverlay();
|
|
394
|
+
options.sendMessage(message);
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Subscribes to every run in the project, however it was started: the host
|
|
398
|
+
* replays the runs it still holds, then streams new ones. A completed run
|
|
399
|
+
* schedules one re-list so the browser shows the fresh verdicts.
|
|
400
|
+
*
|
|
401
|
+
* @param watchTestRuns - The host's feed subscription, or undefined when unwired.
|
|
402
|
+
* @param refresh - Re-lists the project's tests (the panel's effect event).
|
|
403
|
+
* @returns The effect cleanup: stops the subscription and the pending re-list.
|
|
404
|
+
*/
|
|
405
|
+
watchRuns(watchTestRuns, refresh) {
|
|
406
|
+
if (!watchTestRuns)
|
|
407
|
+
return () => { };
|
|
408
|
+
let relist = null;
|
|
409
|
+
let unsubscribe = null;
|
|
410
|
+
try {
|
|
411
|
+
unsubscribe = watchTestRuns((event) => {
|
|
412
|
+
if (!this.mounted)
|
|
413
|
+
return;
|
|
414
|
+
// Only id-less legacy hosts need run-id suppression. Ordered copies dedupe by event id.
|
|
415
|
+
if (!event.eventId &&
|
|
416
|
+
(this.activeOwnRunIds.has(event.runId) || this.completedOwnRunIds.has(event.runId))) {
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
this.projection.apply(event, this.ownRun?.state.runId ?? null);
|
|
420
|
+
this.projectTestsRun();
|
|
421
|
+
if (event.type === 'done') {
|
|
422
|
+
if (relist)
|
|
423
|
+
this.clearTimer(relist);
|
|
424
|
+
relist = this.setTimer(() => {
|
|
425
|
+
relist = null;
|
|
426
|
+
refresh();
|
|
427
|
+
}, 500);
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
this.projectTestsRun();
|
|
431
|
+
}
|
|
432
|
+
catch (error) {
|
|
433
|
+
this.warn('Failed to watch the project test runs', { error });
|
|
434
|
+
}
|
|
435
|
+
return () => {
|
|
436
|
+
if (relist)
|
|
437
|
+
this.clearTimer(relist);
|
|
438
|
+
unsubscribe?.();
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Shows what the projection holds, folding in the live own run's skip state
|
|
443
|
+
* when the card is on that run.
|
|
444
|
+
*/
|
|
445
|
+
projectTestsRun() {
|
|
446
|
+
const invocation = this.ownRun;
|
|
447
|
+
if (invocation && invocation.state.runId == null) {
|
|
448
|
+
this.patch({ run: invocation.state });
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
const activeOwnRunId = invocation?.state.runId ?? null;
|
|
452
|
+
const next = this.projection.show(activeOwnRunId);
|
|
453
|
+
this.patch({
|
|
454
|
+
run: invocation && next.runId === invocation.state.runId
|
|
455
|
+
? {
|
|
456
|
+
...next,
|
|
457
|
+
skipPending: invocation.state.skipPending,
|
|
458
|
+
skipUnavailable: invocation.state.skipUnavailable,
|
|
459
|
+
}
|
|
460
|
+
: next,
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Records an own-run event for the projection and the delayed-echo guard.
|
|
465
|
+
*
|
|
466
|
+
* @param event - The event, always carrying the invocation's run id.
|
|
467
|
+
*/
|
|
468
|
+
recordOwnTestRunEvent(event) {
|
|
469
|
+
const legacy = !event.eventId;
|
|
470
|
+
if (legacy) {
|
|
471
|
+
if (this.ownRun?.state.runId === event.runId)
|
|
472
|
+
this.activeOwnRunIds.add(event.runId);
|
|
473
|
+
else
|
|
474
|
+
rememberCompletedOwnTestRunId(this.completedOwnRunIds, event.runId);
|
|
475
|
+
}
|
|
476
|
+
this.projection.apply(event, this.ownRun?.state.runId ?? null);
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Stores a changed field and tells the subscribers, once.
|
|
480
|
+
*
|
|
481
|
+
* @param next - The fields that changed.
|
|
482
|
+
*/
|
|
483
|
+
patch(next) {
|
|
484
|
+
let changed = false;
|
|
485
|
+
if (next.list !== undefined && next.list !== this.list) {
|
|
486
|
+
this.list = next.list;
|
|
487
|
+
changed = true;
|
|
488
|
+
}
|
|
489
|
+
if (next.status !== undefined && next.status !== this.status) {
|
|
490
|
+
this.status = next.status;
|
|
491
|
+
changed = true;
|
|
492
|
+
}
|
|
493
|
+
if (next.run !== undefined && next.run !== this.run) {
|
|
494
|
+
this.run = next.run;
|
|
495
|
+
changed = true;
|
|
496
|
+
}
|
|
497
|
+
if (!changed)
|
|
498
|
+
return;
|
|
499
|
+
this.current = { list: this.list, status: this.status, run: this.run };
|
|
500
|
+
for (const listener of [...this.listeners])
|
|
501
|
+
listener();
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
//# sourceMappingURL=chat-tests-controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-tests-controller.js","sourceRoot":"","sources":["../../src/components/chat-tests-controller.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAYH,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,OAAO,EACP,mBAAmB,EACnB,WAAW,EAEX,iBAAiB,GAElB,MAAM,2BAA2B,CAAA;AA4BlC,gFAAgF;AAChF,MAAM,CAAC,MAAM,+BAA+B,GAAG,EAAE,CAAA;AAEjD;;;;;GAKG;AACH,MAAM,UAAU,6BAA6B,CAAC,GAAgB,EAAE,KAAa;IAC3E,GAAG,CAA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CAAC;YAAE,QAAQ,EAAE,CAAA;IACxD,CAAC;CACF"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pure derivations behind the chat timeline's card list: which recorded
|
|
3
|
+
* limit card the live banner already states, which local commit cards a history
|
|
4
|
+
* reload has made redundant, and the context handed to the host's
|
|
5
|
+
* `buildUpgradeCta` for a refusal.
|
|
6
|
+
*
|
|
7
|
+
* Every framework's chat panel builds the same card list from the same inputs,
|
|
8
|
+
* so these rules live here, framework-neutral. Nothing in this module reads
|
|
9
|
+
* React state, refs, props or hooks: the caller passes every input in.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
import type { ChatErrorMeta, ChatMessage } from '@molecule/app-ai-chat';
|
|
14
|
+
import type { CommitCard, SystemCard } from './chat-card-event-utilities.js';
|
|
15
|
+
/**
|
|
16
|
+
* The card fields {@link cardCoveredByLimit} reads: the card's variant (only
|
|
17
|
+
* the plain card is suppressed — never the `/help` or skills notice) and the
|
|
18
|
+
* limit it already explains.
|
|
19
|
+
*/
|
|
20
|
+
export type LimitCoveringCard = Pick<SystemCard, 'variant'> & {
|
|
21
|
+
/** The limit this card already explains (a backend `limitType`). */
|
|
22
|
+
coversLimitType?: string;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Whether a recorded card states the SAME limit the live error banner is
|
|
26
|
+
* already stating, so rendering it too would state one fact twice. The banner
|
|
27
|
+
* is never the one suppressed — it is the refused send's only feedback.
|
|
28
|
+
*
|
|
29
|
+
* Only the plain card qualifies: a `/help` or skills notice has its own body,
|
|
30
|
+
* so it is never the redundant copy of the banner.
|
|
31
|
+
*
|
|
32
|
+
* @param card - The recorded card.
|
|
33
|
+
* @param liveLimitType - The limit rule the live error carries, if any.
|
|
34
|
+
* @returns True when the card is redundant while that error is showing.
|
|
35
|
+
*/
|
|
36
|
+
export declare function cardCoveredByLimit(card: LimitCoveringCard, liveLimitType: string | undefined): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* The commit hashes the persisted transcript already carries as `commitRecord`
|
|
39
|
+
* messages — a history reload pulls a committed record into `messages`, and the
|
|
40
|
+
* local card for the same commit is then a duplicate.
|
|
41
|
+
*
|
|
42
|
+
* @param messages - The visible transcript.
|
|
43
|
+
* @returns The set of persisted commit hashes.
|
|
44
|
+
*/
|
|
45
|
+
export declare function persistedCommitHashes(messages: readonly ChatMessage[]): Set<string>;
|
|
46
|
+
/**
|
|
47
|
+
* Whether a local commit card still renders: it has no hash yet (the commit is
|
|
48
|
+
* in flight) or its hash is not in the persisted transcript.
|
|
49
|
+
*
|
|
50
|
+
* @param card - The local commit card.
|
|
51
|
+
* @param persisted - The persisted commit hashes.
|
|
52
|
+
* @returns True when the card is not a duplicate.
|
|
53
|
+
*/
|
|
54
|
+
export declare function commitCardVisible(card: Pick<CommitCard, 'hash'>, persisted: ReadonlySet<string>): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* The context the panel forwards to the host's `buildUpgradeCta` for a
|
|
57
|
+
* refusal: everything the backend said about it — the rule that fired, the
|
|
58
|
+
* remedy it resolved and the plan an upgrade would move to.
|
|
59
|
+
*
|
|
60
|
+
* The rest is the backend's own description of the limit that fired, forwarded
|
|
61
|
+
* verbatim so the host never has to guess the right button:
|
|
62
|
+
*
|
|
63
|
+
* - `limitType` — the RULE the backend enforced (e.g. `usage_balance`,
|
|
64
|
+
* `spend_cap`, `ai_cost`, `max_tool_loops`).
|
|
65
|
+
* - `billingAction` — the REMEDY the backend resolved (e.g. `sign_up`,
|
|
66
|
+
* `upgrade`, `add_payment_method`, `add_funds`, `raise_spend_cap`,
|
|
67
|
+
* `enable_extra_usage`, `contact_support`, `owner_only`, `none`).
|
|
68
|
+
* - `upgradeTier` — the plan an upgrade would move to, explicitly `null` when
|
|
69
|
+
* there is no higher tier, so a top-tier user is never sent to a plans page
|
|
70
|
+
* with nothing to sell them.
|
|
71
|
+
*/
|
|
72
|
+
export interface UpgradeCtaContext {
|
|
73
|
+
/** Whether the backend says the caller must sign up rather than upgrade. */
|
|
74
|
+
requiresSignup?: boolean;
|
|
75
|
+
/** The limit rule the backend enforced. */
|
|
76
|
+
limitType?: string;
|
|
77
|
+
/** The remedy the backend resolved for this account. */
|
|
78
|
+
billingAction?: string;
|
|
79
|
+
/** The plan an upgrade would move to, or `null` when there is none. */
|
|
80
|
+
upgradeTier?: string | null;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The exact context the panel forwards to the host's `buildUpgradeCta` for a
|
|
84
|
+
* refusal: every field, present or undefined.
|
|
85
|
+
*
|
|
86
|
+
* @param meta - The error's limit metadata, or null.
|
|
87
|
+
* @returns The context React forwards (every field, present or undefined).
|
|
88
|
+
*/
|
|
89
|
+
export declare function upgradeContextFromError(meta: ChatErrorMeta | null): UpgradeCtaContext;
|
|
90
|
+
//# sourceMappingURL=chat-timeline-utilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-timeline-utilities.d.ts","sourceRoot":"","sources":["../../src/components/chat-timeline-utilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAEvE,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAA;AAE5E;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC,GAAG;IAC5D,oEAAoE;IACpE,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB,CAAA;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,iBAAiB,EACvB,aAAa,EAAE,MAAM,GAAG,SAAS,GAChC,OAAO,CAET;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,SAAS,WAAW,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,CAOnF;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,EAC9B,SAAS,EAAE,WAAW,CAAC,MAAM,CAAC,GAC7B,OAAO,CAET;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,iBAAiB;IAChC,4EAA4E;IAC5E,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,2CAA2C;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,wDAAwD;IACxD,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,uEAAuE;IACvE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAC5B;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,aAAa,GAAG,IAAI,GAAG,iBAAiB,CAOrF"}
|