@vehicle-sil/gui-client 0.1.0 → 0.2.0-rc.2
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.ja.md +412 -96
- package/README.md +403 -89
- package/dist/elements.js +872 -0
- package/dist/index.js +2869 -259
- package/package.json +20 -2
- package/timeline/vehicle-sil-timeline.d.ts +108 -0
- package/timeline/vehicle-sil-timeline.js +4577 -0
- package/timeline/vehicle-sil-timeline.mjs +4579 -0
- package/types/client.d.ts +47 -7
- package/types/connection.d.ts +4 -0
- package/types/elements/index.d.ts +25 -0
- package/types/elements/outside-parts.d.ts +20 -0
- package/types/elements/page-intent.d.ts +10 -0
- package/types/elements/part.d.ts +48 -0
- package/types/elements/reasons.d.ts +12 -0
- package/types/elements/run-parts.d.ts +21 -0
- package/types/elements/scenario-parts.d.ts +18 -0
- package/types/elements/variable-parts.d.ts +28 -0
- package/types/front-actions.d.ts +130 -0
- package/types/front-compose.d.ts +61 -0
- package/types/front-outside.d.ts +19 -0
- package/types/front-types.d.ts +360 -0
- package/types/front-variable.d.ts +28 -0
- package/types/front.d.ts +50 -0
- package/types/index.d.ts +13 -5
- package/types/protocol/launcher.d.ts +581 -0
- package/types/protocol/read.d.ts +72 -0
- package/types/protocol/server.d.ts +780 -0
- package/types/protocol.d.ts +10 -972
- package/types/run.d.ts +21 -6
- package/types/session-state.d.ts +66 -10
- package/types/session.d.ts +48 -2
- package/types/time.d.ts +16 -45
- package/types/values.d.ts +2 -0
- package/types/variable-binding.d.ts +20 -5
- package/types/variable-editor.d.ts +25 -0
- package/types/variable-state.d.ts +12 -6
- package/types/variables.d.ts +36 -4
- package/types/waveforms.d.ts +14 -0
package/dist/index.js
CHANGED
|
@@ -31,10 +31,14 @@ var Writable = class {
|
|
|
31
31
|
return this.value;
|
|
32
32
|
}
|
|
33
33
|
set(value) {
|
|
34
|
-
|
|
34
|
+
this.setDeferred(value)();
|
|
35
|
+
}
|
|
36
|
+
/** Changes the value immediately and returns its notification, for an atomic multi-value update. */
|
|
37
|
+
setDeferred(value) {
|
|
38
|
+
if (this.equal(this.value, value)) return () => void 0;
|
|
35
39
|
this.value = value;
|
|
36
40
|
const version2 = ++this.version;
|
|
37
|
-
callEach(this.listeners, [value], this.onError, () => this.version === version2);
|
|
41
|
+
return () => callEach(this.listeners, [value], this.onError, () => this.version === version2);
|
|
38
42
|
}
|
|
39
43
|
update(change) {
|
|
40
44
|
this.set(change(this.value));
|
|
@@ -73,14 +77,14 @@ function webSocketFactory(options = {}) {
|
|
|
73
77
|
try {
|
|
74
78
|
socket = options.origin ? new WebSocketClass(url, { headers: { Origin: options.origin } }) : new WebSocketClass(url);
|
|
75
79
|
} catch (error) {
|
|
76
|
-
const
|
|
77
|
-
setTimeout(() => on.close(NOT_OPENED,
|
|
80
|
+
const reason2 = `cannot open the WebSocket: ${error instanceof Error ? error.message : String(error)}`;
|
|
81
|
+
setTimeout(() => on.close(NOT_OPENED, reason2), 0);
|
|
78
82
|
return { send: () => void 0, close: () => void 0 };
|
|
79
83
|
}
|
|
80
84
|
socket.onopen = () => on.open();
|
|
81
85
|
socket.onmessage = (event) => on.message(typeof event.data === "string" ? event.data : String(event.data));
|
|
82
86
|
socket.onclose = (event) => on.close(event.code ?? 0, event.reason ?? "");
|
|
83
|
-
return { send: (
|
|
87
|
+
return { send: (text3) => socket.send(text3), close: () => socket.close() };
|
|
84
88
|
};
|
|
85
89
|
}
|
|
86
90
|
function backoffMs(attempt, maxMs = 5e3) {
|
|
@@ -114,6 +118,8 @@ var Connection = class {
|
|
|
114
118
|
batchListeners = /* @__PURE__ */ new Set();
|
|
115
119
|
unreadableListeners = /* @__PURE__ */ new Set();
|
|
116
120
|
socket = null;
|
|
121
|
+
connectionEpoch = 0;
|
|
122
|
+
attemptRevision = 0;
|
|
117
123
|
wanted = false;
|
|
118
124
|
/** Consecutive drops without a readable notification. */
|
|
119
125
|
attempts = 0;
|
|
@@ -138,6 +144,7 @@ var Connection = class {
|
|
|
138
144
|
}
|
|
139
145
|
/** Disconnects, without reconnecting. Drops notifications still being batched. */
|
|
140
146
|
close() {
|
|
147
|
+
const revision = ++this.attemptRevision;
|
|
141
148
|
this.wanted = false;
|
|
142
149
|
this.restarts = 0;
|
|
143
150
|
this.attempts = 0;
|
|
@@ -148,7 +155,7 @@ var Connection = class {
|
|
|
148
155
|
const socket = this.socket;
|
|
149
156
|
this.socket = null;
|
|
150
157
|
socket?.close();
|
|
151
|
-
this.stateValue.set("closed");
|
|
158
|
+
if (revision === this.attemptRevision) this.stateValue.set("closed");
|
|
152
159
|
}
|
|
153
160
|
/**
|
|
154
161
|
* Drops the current connection and reconnects after a delay (when a reader could not rebuild its state from the
|
|
@@ -159,14 +166,16 @@ var Connection = class {
|
|
|
159
166
|
}
|
|
160
167
|
restartAfter(delayMs) {
|
|
161
168
|
if (!this.wanted) return;
|
|
169
|
+
const revision = ++this.attemptRevision;
|
|
162
170
|
this.restartAsked = true;
|
|
163
171
|
this.dropPending();
|
|
164
172
|
clearTimeout(this.steadyTimer);
|
|
165
173
|
const socket = this.socket;
|
|
166
174
|
this.socket = null;
|
|
167
175
|
socket?.close();
|
|
176
|
+
if (revision !== this.attemptRevision) return;
|
|
168
177
|
this.stateValue.set("closed");
|
|
169
|
-
this.scheduleRetry(delayMs);
|
|
178
|
+
if (revision === this.attemptRevision) this.scheduleRetry(delayMs);
|
|
170
179
|
}
|
|
171
180
|
/**
|
|
172
181
|
* Sends a notification to the server (one that follows authentication, such as a variable subscription). Sends only
|
|
@@ -211,22 +220,35 @@ var Connection = class {
|
|
|
211
220
|
this.pending = [];
|
|
212
221
|
}
|
|
213
222
|
open() {
|
|
223
|
+
const revision = ++this.attemptRevision;
|
|
224
|
+
const currentAttempt = () => this.wanted && this.attemptRevision === revision;
|
|
214
225
|
try {
|
|
215
|
-
this.openSocket();
|
|
226
|
+
this.openSocket(currentAttempt);
|
|
216
227
|
} catch (error) {
|
|
228
|
+
if (!currentAttempt()) return;
|
|
217
229
|
this.onError(error);
|
|
230
|
+
if (!currentAttempt()) return;
|
|
218
231
|
this.socket = null;
|
|
219
232
|
this.lastCloseValue.set({
|
|
220
233
|
code: NOT_OPENED,
|
|
221
234
|
reason: `cannot open the WebSocket: ${error instanceof Error ? error.message : String(error)}`
|
|
222
235
|
});
|
|
236
|
+
if (!currentAttempt()) return;
|
|
223
237
|
this.stateValue.set("closed");
|
|
224
|
-
|
|
238
|
+
if (currentAttempt())
|
|
239
|
+
this.scheduleRetry(backoffMs(++this.attempts, this.options.maxBackoffMs));
|
|
225
240
|
}
|
|
226
241
|
}
|
|
227
|
-
|
|
242
|
+
/** Identifies the connection that produced a batch; restarting alone does not create the next one. */
|
|
243
|
+
batchEpoch() {
|
|
244
|
+
return this.connectionEpoch;
|
|
245
|
+
}
|
|
246
|
+
openSocket(currentAttempt) {
|
|
247
|
+
++this.connectionEpoch;
|
|
228
248
|
const greeting = this.options.greeting();
|
|
249
|
+
if (!currentAttempt()) return;
|
|
229
250
|
this.stateValue.set("connecting");
|
|
251
|
+
if (!currentAttempt()) return;
|
|
230
252
|
let opened = false;
|
|
231
253
|
let socket = null;
|
|
232
254
|
const current = () => socket !== null && this.socket === socket;
|
|
@@ -235,6 +257,7 @@ var Connection = class {
|
|
|
235
257
|
if (!current()) return;
|
|
236
258
|
opened = true;
|
|
237
259
|
this.stateValue.set("open");
|
|
260
|
+
if (!current()) return;
|
|
238
261
|
clearTimeout(this.steadyTimer);
|
|
239
262
|
this.steadyTimer = setTimeout(() => this.garbled = 0, STEADY_MS);
|
|
240
263
|
for (const message of greeting) socket?.send(JSON.stringify(message));
|
|
@@ -246,32 +269,44 @@ var Connection = class {
|
|
|
246
269
|
this.onError(error);
|
|
247
270
|
}
|
|
248
271
|
},
|
|
249
|
-
message: (
|
|
272
|
+
message: (text3) => {
|
|
250
273
|
if (!current()) return;
|
|
251
274
|
let message;
|
|
252
275
|
try {
|
|
253
|
-
message = JSON.parse(
|
|
276
|
+
message = JSON.parse(text3);
|
|
254
277
|
} catch {
|
|
255
|
-
callEach(this.unreadableListeners, [
|
|
278
|
+
callEach(this.unreadableListeners, [text3], this.onError);
|
|
279
|
+
if (!current()) return;
|
|
256
280
|
this.restartAfter(backoffMs(++this.garbled, this.options.maxBackoffMs));
|
|
257
281
|
return;
|
|
258
282
|
}
|
|
259
283
|
this.attempts = 0;
|
|
260
284
|
if (this.lastCloseValue.get() !== null) this.lastCloseValue.set(null);
|
|
285
|
+
if (!current()) return;
|
|
261
286
|
this.pending.push(message);
|
|
262
287
|
this.batchTimer ??= setTimeout(() => this.flush(), this.options.batchMs ?? BATCH_MS);
|
|
263
288
|
},
|
|
264
|
-
close: (code,
|
|
289
|
+
close: (code, reason2) => {
|
|
290
|
+
if (!current()) return;
|
|
291
|
+
this.flush();
|
|
265
292
|
if (!current()) return;
|
|
266
293
|
this.socket = null;
|
|
294
|
+
const closedEpoch = this.connectionEpoch;
|
|
267
295
|
clearTimeout(this.steadyTimer);
|
|
268
296
|
if (!opened) this.failureCount.update((n) => n + 1);
|
|
269
|
-
this.
|
|
297
|
+
if (this.connectionEpoch !== closedEpoch) return;
|
|
298
|
+
this.lastCloseValue.set({ code, reason: reason2 });
|
|
299
|
+
if (this.connectionEpoch !== closedEpoch) return;
|
|
270
300
|
this.stateValue.set("closed");
|
|
301
|
+
if (this.connectionEpoch !== closedEpoch) return;
|
|
271
302
|
this.scheduleRetry(backoffMs(++this.attempts, this.options.maxBackoffMs));
|
|
272
303
|
}
|
|
273
304
|
};
|
|
274
305
|
socket = this.options.socket(this.options.url, handlers);
|
|
306
|
+
if (!currentAttempt()) {
|
|
307
|
+
socket.close();
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
275
310
|
this.socket = socket;
|
|
276
311
|
}
|
|
277
312
|
scheduleRetry(delayMs) {
|
|
@@ -283,7 +318,7 @@ var Connection = class {
|
|
|
283
318
|
}
|
|
284
319
|
};
|
|
285
320
|
|
|
286
|
-
// ../client/src/protocol.ts
|
|
321
|
+
// ../client/src/protocol/read.ts
|
|
287
322
|
var ProtocolError = class extends Error {
|
|
288
323
|
constructor(path, expected) {
|
|
289
324
|
super(`${path}: expected ${expected}`);
|
|
@@ -294,7 +329,6 @@ var ProtocolError = class extends Error {
|
|
|
294
329
|
path;
|
|
295
330
|
expected;
|
|
296
331
|
};
|
|
297
|
-
var PROTOCOL_VERSION = 1;
|
|
298
332
|
function object(value, path) {
|
|
299
333
|
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
300
334
|
throw new ProtocolError(path, "an object");
|
|
@@ -391,12 +425,30 @@ function version(fields, path, key, expected, u) {
|
|
|
391
425
|
u.add(error.path);
|
|
392
426
|
}
|
|
393
427
|
}
|
|
428
|
+
function record(read2) {
|
|
429
|
+
return (value, path) => Object.fromEntries(
|
|
430
|
+
Object.entries(object(value, path)).map(([key, item]) => [key, read2(item, `${path}.${key}`)])
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
function withRaw(raw, read2) {
|
|
434
|
+
Object.defineProperty(read2, "raw", {
|
|
435
|
+
value: raw,
|
|
436
|
+
enumerable: false,
|
|
437
|
+
writable: false,
|
|
438
|
+
configurable: false
|
|
439
|
+
});
|
|
440
|
+
return read2;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// ../client/src/protocol/launcher.ts
|
|
444
|
+
var readSpeed = (value, path) => value === null || value === "max" ? value : number(value, path);
|
|
394
445
|
function severityRank(severity) {
|
|
395
446
|
return severity === "note" ? 2 : severity === "warning" ? 1 : 0;
|
|
396
447
|
}
|
|
397
448
|
var readFinding = (value, path, u) => {
|
|
398
449
|
const f = object(value, path);
|
|
399
|
-
return {
|
|
450
|
+
return withRaw(f, {
|
|
451
|
+
...Number.isSafeInteger(f["event_seq"]) && f["event_seq"] >= 0 ? { event_seq: f["event_seq"] } : {},
|
|
400
452
|
severity: field(f, path, "severity", string),
|
|
401
453
|
code: field(f, path, "code", lenient(string, "", u)),
|
|
402
454
|
file: field(f, path, "file", soft(nullable(string), null, u)),
|
|
@@ -405,11 +457,11 @@ var readFinding = (value, path, u) => {
|
|
|
405
457
|
network: field(f, path, "network", soft(nullable(string), null, u)),
|
|
406
458
|
message: field(f, path, "message", string),
|
|
407
459
|
detail: field(f, path, "detail", soft(nullable(string), null, u))
|
|
408
|
-
};
|
|
460
|
+
});
|
|
409
461
|
};
|
|
410
462
|
var readVariable = (value, path) => {
|
|
411
463
|
const f = object(value, path);
|
|
412
|
-
return {
|
|
464
|
+
return withRaw(f, {
|
|
413
465
|
name: field(f, path, "name", string),
|
|
414
466
|
type: field(f, path, "type", string),
|
|
415
467
|
causality: field(f, path, "causality", string),
|
|
@@ -417,12 +469,9 @@ var readVariable = (value, path) => {
|
|
|
417
469
|
min: field(f, path, "min", optional(nullable(number), null)),
|
|
418
470
|
max: field(f, path, "max", optional(nullable(number), null)),
|
|
419
471
|
builtin: field(f, path, "builtin", optional(nullable(boolean), null))
|
|
420
|
-
};
|
|
472
|
+
});
|
|
421
473
|
};
|
|
422
|
-
var
|
|
423
|
-
var FEATURE_SCENARIO_CONTROL = "scenario-control";
|
|
424
|
-
var FEATURE_MANUAL = "manual-participants";
|
|
425
|
-
var readScenarioStepFields = (f, path, u) => ({
|
|
474
|
+
var readScenarioStepFields = (f, path, u) => withRaw(f, {
|
|
426
475
|
index: field(f, path, "index", integer),
|
|
427
476
|
line: field(f, path, "line", soft(nullable(integer), null, u)),
|
|
428
477
|
kind: field(f, path, "kind", lenient(string, "", u)),
|
|
@@ -437,15 +486,15 @@ var readScenarioStepFields = (f, path, u) => ({
|
|
|
437
486
|
var readScenarioStep = (value, path, u) => readScenarioStepFields(object(value, path), path, u);
|
|
438
487
|
var readCheckScenario = (value, path, u) => {
|
|
439
488
|
const f = object(value, path);
|
|
440
|
-
return {
|
|
489
|
+
return withRaw(f, {
|
|
441
490
|
file: field(f, path, "file", lenient(string, "", u)),
|
|
442
491
|
name: field(f, path, "name", soft(nullable(string), null, u)),
|
|
443
492
|
steps: field(f, path, "steps", lenient(integer, 0, u))
|
|
444
|
-
};
|
|
493
|
+
});
|
|
445
494
|
};
|
|
446
495
|
var readScenarioResult = (value, path, u) => {
|
|
447
496
|
const f = object(value, path);
|
|
448
|
-
return {
|
|
497
|
+
return withRaw(f, {
|
|
449
498
|
file: field(f, path, "file", lenient(string, "", u)),
|
|
450
499
|
name: field(f, path, "name", soft(nullable(string), null, u)),
|
|
451
500
|
status: field(f, path, "status", lenient(string, "", u)),
|
|
@@ -456,11 +505,11 @@ var readScenarioResult = (value, path, u) => {
|
|
|
456
505
|
"steps",
|
|
457
506
|
items((v, p) => readScenarioStep(v, p, u), u)
|
|
458
507
|
)
|
|
459
|
-
};
|
|
508
|
+
});
|
|
460
509
|
};
|
|
461
510
|
var readCheckParticipant = (value, path, u) => {
|
|
462
511
|
const f = object(value, path);
|
|
463
|
-
return {
|
|
512
|
+
return withRaw(f, {
|
|
464
513
|
name: field(f, path, "name", nullable(string)),
|
|
465
514
|
line: field(f, path, "line", soft(nullable(integer), null, u)),
|
|
466
515
|
required: field(f, path, "required", lenient(nullable(boolean), null, u)),
|
|
@@ -483,27 +532,29 @@ var readCheckParticipant = (value, path, u) => {
|
|
|
483
532
|
null,
|
|
484
533
|
u
|
|
485
534
|
)
|
|
486
|
-
)
|
|
487
|
-
|
|
535
|
+
),
|
|
536
|
+
role: field(f, path, "role", soft(nullable(string), null, u))
|
|
537
|
+
});
|
|
488
538
|
};
|
|
489
539
|
var readCheckNetwork = (value, path, u) => {
|
|
490
540
|
const f = object(value, path);
|
|
491
|
-
return {
|
|
541
|
+
return withRaw(f, {
|
|
492
542
|
name: field(f, path, "name", lenient(nullable(string), null, u)),
|
|
493
543
|
kind: field(f, path, "kind", lenient(nullable(string), null, u)),
|
|
494
544
|
participants: field(f, path, "participants", items(string, u))
|
|
495
|
-
};
|
|
545
|
+
});
|
|
496
546
|
};
|
|
497
547
|
var readCheckResult = (value, path, u) => {
|
|
498
548
|
const f = object(value, path);
|
|
499
549
|
version(f, path, "vehicle_sil_check", 1, u);
|
|
500
|
-
return {
|
|
550
|
+
return withRaw(f, {
|
|
501
551
|
file: field(f, path, "file", soft(nullable(string), null, u)),
|
|
502
552
|
result: field(f, path, "result", lenient(string, "", u)),
|
|
503
553
|
errors: field(f, path, "errors", lenient(integer, 0, u)),
|
|
504
554
|
warnings: field(f, path, "warnings", lenient(integer, 0, u)),
|
|
505
555
|
notes: field(f, path, "notes", lenient(integer, 0, u)),
|
|
506
556
|
stop_at_ms: field(f, path, "stop_at_ms", soft(nullable(number), null, u)),
|
|
557
|
+
...f["time_step_ms"] === void 0 ? {} : { time_step_ms: field(f, path, "time_step_ms", soft(nullable(number), null, u)) },
|
|
507
558
|
participants: field(
|
|
508
559
|
f,
|
|
509
560
|
path,
|
|
@@ -532,7 +583,7 @@ var readCheckResult = (value, path, u) => {
|
|
|
532
583
|
u
|
|
533
584
|
)
|
|
534
585
|
)
|
|
535
|
-
};
|
|
586
|
+
});
|
|
536
587
|
};
|
|
537
588
|
var CONTROL_EVENT = "control_link";
|
|
538
589
|
var CONTROL_RESULT_KEY = "control_link";
|
|
@@ -540,23 +591,24 @@ var CONTROL_SUMMARY_KEY = "control_link";
|
|
|
540
591
|
var CONTROL_CHECK_KEY = "control";
|
|
541
592
|
var readControlOffer = (value, path, u) => {
|
|
542
593
|
const f = object(value, path);
|
|
543
|
-
return {
|
|
594
|
+
return withRaw(f, {
|
|
544
595
|
transport: field(f, path, "transport", lenient(string, "", u)),
|
|
545
|
-
wire_version: field(f, path, "wire_version", soft(nullable(integer), null, u))
|
|
546
|
-
|
|
596
|
+
wire_version: field(f, path, "wire_version", soft(nullable(integer), null, u)),
|
|
597
|
+
wire_revision: field(f, path, "wire_revision", soft(nullable(integer), null, u))
|
|
598
|
+
});
|
|
547
599
|
};
|
|
548
600
|
var readControlLink = (value, path, u) => {
|
|
549
601
|
const f = object(value, path);
|
|
550
|
-
return {
|
|
602
|
+
return withRaw(f, {
|
|
551
603
|
state: field(f, path, "state", string),
|
|
552
604
|
variables: field(f, path, "variables", soft(nullable(integer), null, u)),
|
|
553
605
|
version: field(f, path, "version", soft(nullable(integer), null, u)),
|
|
554
606
|
late_messages: field(f, path, "late_messages", soft(nullable(integer), null, u))
|
|
555
|
-
};
|
|
607
|
+
});
|
|
556
608
|
};
|
|
557
609
|
var readRunParticipant = (value, path, u) => {
|
|
558
610
|
const f = object(value, path);
|
|
559
|
-
return {
|
|
611
|
+
return withRaw(f, {
|
|
560
612
|
name: field(f, path, "name", string),
|
|
561
613
|
required: field(f, path, "required", lenient(boolean, true, u)),
|
|
562
614
|
enabled: field(f, path, "enabled", lenient(boolean, true, u)),
|
|
@@ -574,13 +626,14 @@ var readRunParticipant = (value, path, u) => {
|
|
|
574
626
|
null,
|
|
575
627
|
u
|
|
576
628
|
)
|
|
577
|
-
)
|
|
578
|
-
|
|
629
|
+
),
|
|
630
|
+
log: field(f, path, "log", soft(nullable(string), null, u))
|
|
631
|
+
});
|
|
579
632
|
};
|
|
580
633
|
var readRunTiming = (value, path, u) => {
|
|
581
634
|
const f = object(value, path);
|
|
582
635
|
const count2 = (key) => field(f, path, key, soft(nullable(number), null, u));
|
|
583
|
-
return {
|
|
636
|
+
return withRaw(f, {
|
|
584
637
|
speed: field(f, path, "speed", soft(readSpeed, null, u)),
|
|
585
638
|
time_step_ms: count2("time_step_ms"),
|
|
586
639
|
ecu_step_ms: count2("ecu_step_ms"),
|
|
@@ -595,14 +648,77 @@ var readRunTiming = (value, path, u) => {
|
|
|
595
648
|
slipped_ms: count2("slipped_ms"),
|
|
596
649
|
late_ms: count2("late_ms"),
|
|
597
650
|
paused_ms: count2("paused_ms")
|
|
598
|
-
};
|
|
651
|
+
});
|
|
652
|
+
};
|
|
653
|
+
var readTrafficUnplaced = (value, path, u) => {
|
|
654
|
+
const f = object(value, path);
|
|
655
|
+
return withRaw(f, {
|
|
656
|
+
participant: field(f, path, "participant", string),
|
|
657
|
+
reason: field(f, path, "reason", lenient(string, "", u))
|
|
658
|
+
});
|
|
659
|
+
};
|
|
660
|
+
var readTrafficParticipant = (value, path, u) => {
|
|
661
|
+
const f = object(value, path);
|
|
662
|
+
return withRaw(f, {
|
|
663
|
+
name: field(f, path, "name", string),
|
|
664
|
+
counted: field(f, path, "counted", lenient(boolean, false, u)),
|
|
665
|
+
not_counted: field(f, path, "not_counted", soft(nullable(string), null, u)),
|
|
666
|
+
virtual_time: field(f, path, "virtual_time", soft(nullable(boolean), null, u)),
|
|
667
|
+
at_ms: field(f, path, "at_ms", soft(nullable(number), null, u)),
|
|
668
|
+
frames_sent: field(f, path, "frames_sent", soft(nullable(integer), null, u)),
|
|
669
|
+
frames_received: field(f, path, "frames_received", soft(nullable(integer), null, u))
|
|
670
|
+
});
|
|
671
|
+
};
|
|
672
|
+
var readTrafficNetwork = (value, path, u) => {
|
|
673
|
+
const f = object(value, path);
|
|
674
|
+
return withRaw(f, {
|
|
675
|
+
name: field(f, path, "name", string),
|
|
676
|
+
kind: field(f, path, "kind", soft(nullable(string), null, u)),
|
|
677
|
+
counted: field(f, path, "counted", lenient(integer, 0, u)),
|
|
678
|
+
senders: field(f, path, "senders", lenient(integer, 0, u)),
|
|
679
|
+
receivers: field(f, path, "receivers", lenient(integer, 0, u)),
|
|
680
|
+
delivered: field(f, path, "delivered", soft(nullable(boolean), null, u)),
|
|
681
|
+
unplaced: field(
|
|
682
|
+
f,
|
|
683
|
+
path,
|
|
684
|
+
"unplaced",
|
|
685
|
+
items((v, p) => readTrafficUnplaced(v, p, u), u)
|
|
686
|
+
),
|
|
687
|
+
participants: field(
|
|
688
|
+
f,
|
|
689
|
+
path,
|
|
690
|
+
"participants",
|
|
691
|
+
items((v, p) => readTrafficParticipant(v, p, u), u)
|
|
692
|
+
)
|
|
693
|
+
});
|
|
694
|
+
};
|
|
695
|
+
var readRunTraffic = (value, path, u) => {
|
|
696
|
+
const f = object(value, path);
|
|
697
|
+
return withRaw(f, {
|
|
698
|
+
before_ms: field(f, path, "before_ms", soft(nullable(number), null, u)),
|
|
699
|
+
unplaced: field(
|
|
700
|
+
f,
|
|
701
|
+
path,
|
|
702
|
+
"unplaced",
|
|
703
|
+
items((v, p) => readTrafficUnplaced(v, p, u), u)
|
|
704
|
+
),
|
|
705
|
+
networks: field(
|
|
706
|
+
f,
|
|
707
|
+
path,
|
|
708
|
+
"networks",
|
|
709
|
+
items((v, p) => readTrafficNetwork(v, p, u), u)
|
|
710
|
+
)
|
|
711
|
+
});
|
|
599
712
|
};
|
|
600
713
|
var readRunResult = (value, path, u) => {
|
|
601
714
|
const f = object(value, path);
|
|
602
|
-
version(f, path, "vehicle_sil_run",
|
|
603
|
-
return {
|
|
715
|
+
version(f, path, "vehicle_sil_run", 2, u);
|
|
716
|
+
return withRaw(f, {
|
|
604
717
|
file: field(f, path, "file", soft(nullable(string), null, u)),
|
|
605
718
|
result: field(f, path, "result", lenient(string, "", u)),
|
|
719
|
+
end: field(f, path, "end", soft(nullable(string), null, u)),
|
|
720
|
+
ok: field(f, path, "ok", lenient(boolean, false, u)),
|
|
721
|
+
message: field(f, path, "message", lenient(string, "", u)),
|
|
606
722
|
errors: field(f, path, "errors", lenient(integer, 0, u)),
|
|
607
723
|
warnings: field(f, path, "warnings", lenient(integer, 0, u)),
|
|
608
724
|
notes: field(f, path, "notes", lenient(integer, 0, u)),
|
|
@@ -649,16 +765,24 @@ var readRunResult = (value, path, u) => {
|
|
|
649
765
|
null,
|
|
650
766
|
u
|
|
651
767
|
)
|
|
768
|
+
),
|
|
769
|
+
traffic: field(
|
|
770
|
+
f,
|
|
771
|
+
path,
|
|
772
|
+
"traffic",
|
|
773
|
+
soft(
|
|
774
|
+
nullable((v, p) => readRunTraffic(v, p, u)),
|
|
775
|
+
null,
|
|
776
|
+
u
|
|
777
|
+
)
|
|
652
778
|
)
|
|
653
|
-
};
|
|
779
|
+
});
|
|
654
780
|
};
|
|
655
781
|
var PHASES = ["checking", "starting", "waiting", "running", "stopping", "ended"];
|
|
656
782
|
function readTimeFields(f, path, u) {
|
|
657
783
|
const count2 = (key) => field(f, path, key, soft(nullable(number), null, u));
|
|
658
784
|
return {
|
|
659
785
|
sim_ms: field(f, path, "sim_ms", number),
|
|
660
|
-
speed: field(f, path, "speed", soft(readSpeed, null, u)),
|
|
661
|
-
paused: field(f, path, "paused", soft(nullable(boolean), null, u)),
|
|
662
786
|
actual_speed: count2("actual_speed"),
|
|
663
787
|
late_steps: count2("late_steps"),
|
|
664
788
|
max_late_ms: count2("max_late_ms"),
|
|
@@ -672,7 +796,75 @@ function readCommandFields(f, path, u) {
|
|
|
672
796
|
source: field(f, path, "source", soft(string, "stdin", u)),
|
|
673
797
|
accepted: field(f, path, "accepted", boolean),
|
|
674
798
|
message: field(f, path, "message", soft(nullable(string), null, u)),
|
|
675
|
-
ms: field(f, path, "ms", soft(nullable(integer), null, u))
|
|
799
|
+
ms: field(f, path, "ms", soft(nullable(integer), null, u)),
|
|
800
|
+
reason: field(f, path, "reason", soft(nullable(string), null, u)),
|
|
801
|
+
id: field(f, path, "id", soft(nullable(integer), null, u)),
|
|
802
|
+
at_ms: field(f, path, "at_ms", soft(nullable(number), null, u))
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
var readCaution = (value, path) => {
|
|
806
|
+
const c = object(value, path);
|
|
807
|
+
return { code: field(c, path, "code", string), message: field(c, path, "message", string) };
|
|
808
|
+
};
|
|
809
|
+
var readLauncherAllowedItem = (value, path) => {
|
|
810
|
+
const f = object(value, path);
|
|
811
|
+
return withRaw(f, {
|
|
812
|
+
ok: field(f, path, "ok", boolean),
|
|
813
|
+
reason: field(f, path, "reason", soft(nullable(string), null)),
|
|
814
|
+
message: field(f, path, "message", soft(nullable(string), null)),
|
|
815
|
+
caution: field(f, path, "caution", soft(nullable(readCaution), null))
|
|
816
|
+
});
|
|
817
|
+
};
|
|
818
|
+
var readOutsideState = (value, path, u) => {
|
|
819
|
+
const f = object(value, path);
|
|
820
|
+
return withRaw(f, {
|
|
821
|
+
network: field(f, path, "network", string),
|
|
822
|
+
target: field(f, path, "target", soft(nullable(string), null, u)),
|
|
823
|
+
participant: field(f, path, "participant", soft(nullable(string), null, u)),
|
|
824
|
+
link: field(f, path, "link", soft(nullable(string), null, u)),
|
|
825
|
+
bus: field(f, path, "bus", soft(nullable(string), null, u)),
|
|
826
|
+
nothing_received: field(f, path, "nothing_received", soft(boolean, false, u)),
|
|
827
|
+
condition: field(f, path, "condition", lenient(string, "", u)),
|
|
828
|
+
reasons: field(f, path, "reasons", soft(items(string, u), [], u))
|
|
829
|
+
});
|
|
830
|
+
};
|
|
831
|
+
function readStateFields(f, path, u) {
|
|
832
|
+
return {
|
|
833
|
+
rev: field(f, path, "rev", integer),
|
|
834
|
+
phase: field(f, path, "phase", lenient(string, "", u)),
|
|
835
|
+
paused: field(f, path, "paused", soft(nullable(boolean), null, u)),
|
|
836
|
+
paused_at_ms: field(f, path, "paused_at_ms", soft(nullable(number), null, u)),
|
|
837
|
+
holding: field(f, path, "holding", soft(nullable(boolean), null, u)),
|
|
838
|
+
speed: field(f, path, "speed", soft(readSpeed, null, u)),
|
|
839
|
+
pacing: field(f, path, "pacing", soft(nullable(string), null, u)),
|
|
840
|
+
stop: field(
|
|
841
|
+
f,
|
|
842
|
+
path,
|
|
843
|
+
"stop",
|
|
844
|
+
soft(
|
|
845
|
+
nullable((v, p) => {
|
|
846
|
+
const s = object(v, p);
|
|
847
|
+
return {
|
|
848
|
+
requests: field(s, p, "requests", integer),
|
|
849
|
+
by: field(s, p, "by", nullable(string))
|
|
850
|
+
};
|
|
851
|
+
}),
|
|
852
|
+
null,
|
|
853
|
+
u
|
|
854
|
+
)
|
|
855
|
+
),
|
|
856
|
+
scenario: field(f, path, "scenario", soft(nullable(boolean), null, u)),
|
|
857
|
+
allowed: field(f, path, "allowed", lenient(record(readLauncherAllowedItem), {}, u)),
|
|
858
|
+
outside: field(
|
|
859
|
+
f,
|
|
860
|
+
path,
|
|
861
|
+
"outside",
|
|
862
|
+
soft(
|
|
863
|
+
items((v, p) => readOutsideState(v, p, u), u),
|
|
864
|
+
[],
|
|
865
|
+
u
|
|
866
|
+
)
|
|
867
|
+
)
|
|
676
868
|
};
|
|
677
869
|
}
|
|
678
870
|
var readLauncherEvent = (value, path, partly = false) => {
|
|
@@ -690,7 +882,7 @@ var readLauncherEvent = (value, path, partly = false) => {
|
|
|
690
882
|
u
|
|
691
883
|
);
|
|
692
884
|
if (event && u && u.parts.length > 0) event.unreadable = u.parts;
|
|
693
|
-
return event;
|
|
885
|
+
return event && withRaw(f, event);
|
|
694
886
|
};
|
|
695
887
|
function readEventFields(f, path, kind, base, u) {
|
|
696
888
|
switch (kind) {
|
|
@@ -761,6 +953,16 @@ function readEventFields(f, path, kind, base, u) {
|
|
|
761
953
|
return { ...base, event: kind, ...readTimeFields(f, path, u) };
|
|
762
954
|
case "command":
|
|
763
955
|
return { ...base, event: kind, ...readCommandFields(f, path, u) };
|
|
956
|
+
case "state":
|
|
957
|
+
return { ...base, event: kind, ...readStateFields(f, path, u) };
|
|
958
|
+
case "outside":
|
|
959
|
+
return {
|
|
960
|
+
...base,
|
|
961
|
+
event: kind,
|
|
962
|
+
network: field(f, path, "network", string),
|
|
963
|
+
to_outside: field(f, path, "to_outside", integer),
|
|
964
|
+
from_outside: field(f, path, "from_outside", integer)
|
|
965
|
+
};
|
|
764
966
|
case "scenario_step":
|
|
765
967
|
return { ...base, event: kind, step: readScenarioStepFields(f, path, u) };
|
|
766
968
|
case "result":
|
|
@@ -773,12 +975,17 @@ function readEventFields(f, path, kind, base, u) {
|
|
|
773
975
|
return null;
|
|
774
976
|
}
|
|
775
977
|
}
|
|
978
|
+
|
|
979
|
+
// ../client/src/protocol/server.ts
|
|
980
|
+
var PROTOCOL_VERSION = 3;
|
|
776
981
|
var readServerProblem = (value, path) => {
|
|
777
982
|
const f = object(value, path);
|
|
778
983
|
const problem = {
|
|
779
984
|
code: field(f, path, "code", string),
|
|
780
985
|
message: field(f, path, "message", string)
|
|
781
986
|
};
|
|
987
|
+
if (Number.isSafeInteger(f["problem_seq"]) && f["problem_seq"] >= 0)
|
|
988
|
+
problem.problem_seq = f["problem_seq"];
|
|
782
989
|
const detail = f["detail"];
|
|
783
990
|
if (typeof detail === "object" && detail !== null && "skipped" in detail) {
|
|
784
991
|
const skipped = detail.skipped;
|
|
@@ -786,9 +993,21 @@ var readServerProblem = (value, path) => {
|
|
|
786
993
|
problem.skipped = skipped;
|
|
787
994
|
}
|
|
788
995
|
}
|
|
996
|
+
if (typeof detail === "object" && detail !== null && "findings" in detail) {
|
|
997
|
+
const list = detail.findings;
|
|
998
|
+
if (Array.isArray(list)) {
|
|
999
|
+
const findings = [];
|
|
1000
|
+
list.forEach((item, i) => {
|
|
1001
|
+
try {
|
|
1002
|
+
findings.push(readFinding(item, `${path}.detail.findings[${i}]`));
|
|
1003
|
+
} catch {
|
|
1004
|
+
}
|
|
1005
|
+
});
|
|
1006
|
+
problem.findings = findings;
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
789
1009
|
return problem;
|
|
790
1010
|
};
|
|
791
|
-
var readSpeed = (value, path) => value === null || value === "max" ? value : number(value, path);
|
|
792
1011
|
var readAppInfo = (value) => {
|
|
793
1012
|
const path = "app";
|
|
794
1013
|
const f = object(value, path);
|
|
@@ -836,11 +1055,28 @@ var readConfigList = (value) => {
|
|
|
836
1055
|
f,
|
|
837
1056
|
path,
|
|
838
1057
|
"files",
|
|
839
|
-
array((item, p) =>
|
|
1058
|
+
array((item, p) => {
|
|
1059
|
+
const entry = object(item, p);
|
|
1060
|
+
const simulation = field(entry, p, "simulation", optional(boolean, void 0));
|
|
1061
|
+
return {
|
|
1062
|
+
path: field(entry, p, "path", string),
|
|
1063
|
+
...simulation === void 0 ? {} : { simulation }
|
|
1064
|
+
};
|
|
1065
|
+
})
|
|
840
1066
|
),
|
|
841
1067
|
truncated: field(f, path, "truncated", boolean)
|
|
842
1068
|
};
|
|
843
1069
|
};
|
|
1070
|
+
var readConnections = (value) => {
|
|
1071
|
+
const path = "connections";
|
|
1072
|
+
const f = object(value, path);
|
|
1073
|
+
return {
|
|
1074
|
+
file: field(f, path, "file", string),
|
|
1075
|
+
network: field(f, path, "network", string),
|
|
1076
|
+
exit_code: field(f, path, "exit_code", integer),
|
|
1077
|
+
connections: field(f, path, "connections", object)
|
|
1078
|
+
};
|
|
1079
|
+
};
|
|
844
1080
|
var readScenarioList = (value) => {
|
|
845
1081
|
const path = "scenarios";
|
|
846
1082
|
const f = object(value, path);
|
|
@@ -876,6 +1112,23 @@ var readRecording = (value) => {
|
|
|
876
1112
|
yaml: field(r, path, "yaml", nullable(string))
|
|
877
1113
|
};
|
|
878
1114
|
};
|
|
1115
|
+
var readConfigText = (value) => {
|
|
1116
|
+
const path = "config";
|
|
1117
|
+
const f = object(value, path);
|
|
1118
|
+
return {
|
|
1119
|
+
file: field(f, path, "file", string),
|
|
1120
|
+
text: field(f, path, "text", string),
|
|
1121
|
+
stamp: field(f, path, "stamp", string)
|
|
1122
|
+
};
|
|
1123
|
+
};
|
|
1124
|
+
var readSavedConfig = (value) => {
|
|
1125
|
+
const path = "saved";
|
|
1126
|
+
const f = object(value, path);
|
|
1127
|
+
return {
|
|
1128
|
+
file: field(f, path, "file", string),
|
|
1129
|
+
stamp: field(f, path, "stamp", string)
|
|
1130
|
+
};
|
|
1131
|
+
};
|
|
879
1132
|
var readCheckResponse = (value) => field(object(value, "response"), "response", "check", readCheckResult);
|
|
880
1133
|
var readSummaryParticipant = (value, path, u) => {
|
|
881
1134
|
const f = object(value, path);
|
|
@@ -917,11 +1170,6 @@ var readLogCounts = (value, path) => {
|
|
|
917
1170
|
const f = object(value, path);
|
|
918
1171
|
return { kept: field(f, path, "kept", integer), dropped: field(f, path, "dropped", integer) };
|
|
919
1172
|
};
|
|
920
|
-
function record(read2) {
|
|
921
|
-
return (value, path) => Object.fromEntries(
|
|
922
|
-
Object.entries(object(value, path)).map(([key, item]) => [key, read2(item, `${path}.${key}`)])
|
|
923
|
-
);
|
|
924
|
-
}
|
|
925
1173
|
var readSummaryScenario = (value, path, u) => {
|
|
926
1174
|
const f = object(value, path);
|
|
927
1175
|
return {
|
|
@@ -936,7 +1184,8 @@ var readSummaryScenario = (value, path, u) => {
|
|
|
936
1184
|
),
|
|
937
1185
|
steps_omitted: field(f, path, "steps_omitted", soft(integer, 0, u)),
|
|
938
1186
|
status: field(f, path, "status", soft(nullable(string), null, u)),
|
|
939
|
-
over_at_ms: field(f, path, "over_at_ms", soft(nullable(number), null, u))
|
|
1187
|
+
over_at_ms: field(f, path, "over_at_ms", soft(nullable(number), null, u)),
|
|
1188
|
+
timeline_url: field(f, path, "timeline_url", soft(nullable(string), null, u))
|
|
940
1189
|
};
|
|
941
1190
|
};
|
|
942
1191
|
var readSessionSummary = (value, path) => {
|
|
@@ -946,6 +1195,7 @@ var readSessionSummary = (value, path) => {
|
|
|
946
1195
|
const timePath = `${path}.time`;
|
|
947
1196
|
const summary = {
|
|
948
1197
|
id: field(f, path, "id", integer),
|
|
1198
|
+
...f["snapshot_rev"] === void 0 ? {} : { snapshot_rev: field(f, path, "snapshot_rev", soft(nullable(integer), null, u)) },
|
|
949
1199
|
state: field(f, path, "state", string),
|
|
950
1200
|
launcher: field(f, path, "launcher", readSummaryLauncher),
|
|
951
1201
|
stop: field(f, path, "stop", string),
|
|
@@ -976,6 +1226,23 @@ var readSessionSummary = (value, path) => {
|
|
|
976
1226
|
u
|
|
977
1227
|
)
|
|
978
1228
|
),
|
|
1229
|
+
launcher_state: field(
|
|
1230
|
+
f,
|
|
1231
|
+
path,
|
|
1232
|
+
"launcher_state",
|
|
1233
|
+
soft(
|
|
1234
|
+
nullable((v, p) => {
|
|
1235
|
+
const s = object(v, p);
|
|
1236
|
+
return {
|
|
1237
|
+
...readStateFields(s, p, u),
|
|
1238
|
+
seq: field(s, p, "seq", soft(nullable(integer), null, u))
|
|
1239
|
+
};
|
|
1240
|
+
}),
|
|
1241
|
+
null,
|
|
1242
|
+
u
|
|
1243
|
+
)
|
|
1244
|
+
),
|
|
1245
|
+
allowed: field(f, path, "allowed", soft(nullable(readServerAllowed), null, u)),
|
|
979
1246
|
check: field(
|
|
980
1247
|
f,
|
|
981
1248
|
path,
|
|
@@ -1011,6 +1278,7 @@ var readSessionSummary = (value, path) => {
|
|
|
1011
1278
|
log: field(f, path, "log", soft(partlyRecord(readLogCounts, u), {}, u)),
|
|
1012
1279
|
problems: field(f, path, "problems", items(readServerProblem, u)),
|
|
1013
1280
|
problems_omitted: field(f, path, "problems_omitted", soft(integer, 0, u)),
|
|
1281
|
+
...f["problem_seq"] === void 0 ? {} : { problem_seq: field(f, path, "problem_seq", soft(nullable(integer), null, u)) },
|
|
1014
1282
|
scenario: field(
|
|
1015
1283
|
f,
|
|
1016
1284
|
path,
|
|
@@ -1024,6 +1292,28 @@ var readSessionSummary = (value, path) => {
|
|
|
1024
1292
|
};
|
|
1025
1293
|
return { ...summary, unreadable: u.parts };
|
|
1026
1294
|
};
|
|
1295
|
+
var readServerAllowedItem = (value, path) => {
|
|
1296
|
+
const f = object(value, path);
|
|
1297
|
+
return {
|
|
1298
|
+
ok: field(f, path, "ok", boolean),
|
|
1299
|
+
reason: field(f, path, "reason", optional(nullable(string), null)),
|
|
1300
|
+
message: field(f, path, "message", optional(nullable(string), null))
|
|
1301
|
+
};
|
|
1302
|
+
};
|
|
1303
|
+
var readServerSaveItem = (value, path) => ({
|
|
1304
|
+
...readServerAllowedItem(value, path),
|
|
1305
|
+
caution: field(object(value, path), path, "caution", nullable(readCaution))
|
|
1306
|
+
});
|
|
1307
|
+
var readServerAllowed = (value, path) => {
|
|
1308
|
+
const f = object(value, path);
|
|
1309
|
+
return {
|
|
1310
|
+
rev: field(f, path, "rev", optional(integer, 0)),
|
|
1311
|
+
start: field(f, path, "start", readServerAllowedItem),
|
|
1312
|
+
stop: field(f, path, "stop", readServerAllowedItem),
|
|
1313
|
+
force: field(f, path, "force", readServerAllowedItem),
|
|
1314
|
+
save: field(f, path, "save", readServerSaveItem)
|
|
1315
|
+
};
|
|
1316
|
+
};
|
|
1027
1317
|
function partlyRecord(read2, u) {
|
|
1028
1318
|
return (value, path) => {
|
|
1029
1319
|
const out = {};
|
|
@@ -1035,15 +1325,28 @@ function partlyRecord(read2, u) {
|
|
|
1035
1325
|
};
|
|
1036
1326
|
}
|
|
1037
1327
|
var readSessionResponse = (value) => field(object(value, "response"), "response", "session", nullable(readSessionSummary));
|
|
1328
|
+
var readSessionInstance = (value) => field(object(value, "response"), "response", "instance", (instance, path) => {
|
|
1329
|
+
if (typeof instance !== "string" || !instance)
|
|
1330
|
+
throw new ProtocolError(path, "a server instance ID. Use the GUI server from this release");
|
|
1331
|
+
return instance;
|
|
1332
|
+
});
|
|
1333
|
+
var readSessionAllowed = (value) => field(
|
|
1334
|
+
object(value, "response"),
|
|
1335
|
+
"response",
|
|
1336
|
+
"allowed",
|
|
1337
|
+
optional(nullable(readServerAllowed), null)
|
|
1338
|
+
);
|
|
1038
1339
|
var readTimeResponse = (value) => {
|
|
1039
1340
|
const path = "response";
|
|
1040
1341
|
const f = object(value, path);
|
|
1041
1342
|
const command = field(f, path, "command", object);
|
|
1042
1343
|
return {
|
|
1043
1344
|
session_id: field(f, path, "session_id", integer),
|
|
1044
|
-
command: field(command, `${path}.command`, "command", string)
|
|
1345
|
+
command: field(command, `${path}.command`, "command", string),
|
|
1346
|
+
id: field(command, `${path}.command`, "id", optional(nullable(integer), null))
|
|
1045
1347
|
};
|
|
1046
1348
|
};
|
|
1349
|
+
var readAvailability = (value) => value === "unknown" || value === "inactive" ? value : "active";
|
|
1047
1350
|
var readOperationReport = (value, path) => {
|
|
1048
1351
|
const f = object(value, path);
|
|
1049
1352
|
return {
|
|
@@ -1060,7 +1363,9 @@ var readOperationReport = (value, path) => {
|
|
|
1060
1363
|
state: field(t, p, "state", string),
|
|
1061
1364
|
applied_at_ms: field(t, p, "applied_at_ms", optional(nullable(number), null)),
|
|
1062
1365
|
late: field(t, p, "late", optional(boolean, false)),
|
|
1063
|
-
reason: field(t, p, "reason", optional(nullable(string), null))
|
|
1366
|
+
reason: field(t, p, "reason", optional(nullable(string), null)),
|
|
1367
|
+
applied_writes: field(t, p, "applied_writes", optional(nullable(integer), null)),
|
|
1368
|
+
failed_write: field(t, p, "failed_write", optional(nullable(integer), null))
|
|
1064
1369
|
};
|
|
1065
1370
|
})
|
|
1066
1371
|
)
|
|
@@ -1091,13 +1396,15 @@ var readVariableSummary = (value, path) => {
|
|
|
1091
1396
|
),
|
|
1092
1397
|
null
|
|
1093
1398
|
)
|
|
1094
|
-
)
|
|
1399
|
+
),
|
|
1400
|
+
availability: readAvailability(f["availability"])
|
|
1095
1401
|
};
|
|
1096
1402
|
};
|
|
1097
1403
|
var readVariablesSummary = (value) => readVariables(value, "variables");
|
|
1098
1404
|
var readVariables = (value, path) => {
|
|
1099
1405
|
const f = object(value, path);
|
|
1100
1406
|
return {
|
|
1407
|
+
...f["rev"] === void 0 ? {} : { rev: field(f, path, "rev", optional(nullable(integer), null)) },
|
|
1101
1408
|
state: field(f, path, "state", string),
|
|
1102
1409
|
reason: field(f, path, "reason", optional(nullable(string), null)),
|
|
1103
1410
|
peers: field(
|
|
@@ -1226,6 +1533,7 @@ var readServerMessage = (value) => {
|
|
|
1226
1533
|
type,
|
|
1227
1534
|
instance: field(f, path, "instance", string),
|
|
1228
1535
|
session: field(f, path, "session", nullable(readSessionSummary)),
|
|
1536
|
+
allowed: field(f, path, "allowed", optional(nullable(readServerAllowed), null)),
|
|
1229
1537
|
replay: field(f, path, "replay", nullable(readReplay))
|
|
1230
1538
|
};
|
|
1231
1539
|
case "event": {
|
|
@@ -1255,6 +1563,12 @@ var readServerMessage = (value) => {
|
|
|
1255
1563
|
at_least: field(f, path, "at_least", array(string)),
|
|
1256
1564
|
events: field(f, path, "events", integer)
|
|
1257
1565
|
};
|
|
1566
|
+
case "allowed":
|
|
1567
|
+
return {
|
|
1568
|
+
type,
|
|
1569
|
+
session: field(f, path, "session", nullable(integer)),
|
|
1570
|
+
allowed: field(f, path, "allowed", readServerAllowed)
|
|
1571
|
+
};
|
|
1258
1572
|
case "resync":
|
|
1259
1573
|
return { type, message: field(f, path, "message", optional(string, "")) };
|
|
1260
1574
|
case "variables":
|
|
@@ -1297,6 +1611,18 @@ var readServerMessage = (value) => {
|
|
|
1297
1611
|
session: field(f, path, "session", integer),
|
|
1298
1612
|
...readOperationReport(value, path)
|
|
1299
1613
|
};
|
|
1614
|
+
case "availability":
|
|
1615
|
+
return {
|
|
1616
|
+
type,
|
|
1617
|
+
session: field(f, path, "session", integer),
|
|
1618
|
+
...f["rev"] === void 0 ? {} : { rev: field(f, path, "rev", optional(nullable(integer), null)) },
|
|
1619
|
+
peers: field(
|
|
1620
|
+
f,
|
|
1621
|
+
path,
|
|
1622
|
+
"peers",
|
|
1623
|
+
record((v, p) => record((x) => readAvailability(x))(v, p))
|
|
1624
|
+
)
|
|
1625
|
+
};
|
|
1300
1626
|
default:
|
|
1301
1627
|
return null;
|
|
1302
1628
|
}
|
|
@@ -1403,10 +1729,20 @@ var RunControl = class {
|
|
|
1403
1729
|
this.startTimeoutMs = startTimeoutMs;
|
|
1404
1730
|
this.startSending = new Writable(false, Object.is, onError);
|
|
1405
1731
|
this.stopSending = new Writable(null, Object.is, onError);
|
|
1732
|
+
this.pendingRevision = new Writable(0, Object.is, onError);
|
|
1406
1733
|
this.stopAskedWhileStarting = new Writable(false, Object.is, onError);
|
|
1407
1734
|
this.failure = new Writable(null, Object.is, onError);
|
|
1408
1735
|
this.starting = this.startSending.readonly();
|
|
1409
1736
|
this.stopping = this.stopSending.readonly();
|
|
1737
|
+
this.currentStopping = derived(
|
|
1738
|
+
[this.pendingRevision, this.startSending, feed.session],
|
|
1739
|
+
() => {
|
|
1740
|
+
const key = this.startSending.get() ? this.startOperation : JSON.stringify(feed.currentTarget());
|
|
1741
|
+
return [...this.pendingStops].filter((pending) => pending.key === key).at(-1)?.action ?? null;
|
|
1742
|
+
},
|
|
1743
|
+
Object.is,
|
|
1744
|
+
onError
|
|
1745
|
+
);
|
|
1410
1746
|
this.stopWhileStarting = this.stopAskedWhileStarting.readonly();
|
|
1411
1747
|
this.error = derived(
|
|
1412
1748
|
[this.failure, feed.session],
|
|
@@ -1424,66 +1760,180 @@ var RunControl = class {
|
|
|
1424
1760
|
feed;
|
|
1425
1761
|
transport;
|
|
1426
1762
|
startTimeoutMs;
|
|
1763
|
+
startOperation = null;
|
|
1764
|
+
pendingStops = /* @__PURE__ */ new Set();
|
|
1765
|
+
pendingRevision;
|
|
1427
1766
|
startSending;
|
|
1428
1767
|
stopSending;
|
|
1429
1768
|
stopAskedWhileStarting;
|
|
1430
1769
|
failure;
|
|
1431
1770
|
starting;
|
|
1432
1771
|
stopping;
|
|
1772
|
+
currentStopping;
|
|
1433
1773
|
stopWhileStarting;
|
|
1434
1774
|
error;
|
|
1435
1775
|
/** Starts a run. */
|
|
1436
1776
|
start(request) {
|
|
1437
|
-
this.startSending.
|
|
1777
|
+
if (this.startSending.get()) return Promise.reject(new Error("a start is already pending"));
|
|
1778
|
+
let resolveStart;
|
|
1779
|
+
let rejectStart;
|
|
1780
|
+
const operation = new Promise(
|
|
1781
|
+
(resolve, reject) => {
|
|
1782
|
+
resolveStart = resolve;
|
|
1783
|
+
rejectStart = reject;
|
|
1784
|
+
}
|
|
1785
|
+
);
|
|
1786
|
+
this.startOperation = operation;
|
|
1438
1787
|
this.stopAskedWhileStarting.set(false);
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1788
|
+
this.startSending.set(true);
|
|
1789
|
+
let instance = null;
|
|
1790
|
+
this.send(
|
|
1791
|
+
"api/run",
|
|
1792
|
+
request,
|
|
1793
|
+
this.startTimeoutMs() || void 0,
|
|
1794
|
+
() => {
|
|
1795
|
+
this.startSending.set(false);
|
|
1796
|
+
},
|
|
1797
|
+
(seen) => {
|
|
1798
|
+
instance = seen;
|
|
1446
1799
|
}
|
|
1447
|
-
});
|
|
1800
|
+
).then((summary) => resolveStart({ summary, instance }), rejectStart);
|
|
1801
|
+
return operation.then(({ summary }) => summary);
|
|
1448
1802
|
}
|
|
1449
1803
|
/** Stops in order (waits for the participants to end). Asking again never turns it into a stop without waiting. */
|
|
1450
1804
|
stop() {
|
|
1451
|
-
|
|
1452
|
-
this.stopSending.set("stop");
|
|
1453
|
-
return this.send("api/stop", { force: false }, void 0, () => this.stopSending.set(null));
|
|
1805
|
+
return this.requestStop(false);
|
|
1454
1806
|
}
|
|
1455
1807
|
/** Stops without waiting (kills the participants). */
|
|
1456
1808
|
forceStop() {
|
|
1457
|
-
this.
|
|
1458
|
-
|
|
1809
|
+
return this.requestStop(true);
|
|
1810
|
+
}
|
|
1811
|
+
captureStop() {
|
|
1812
|
+
const starting = this.startSending.get() ? this.startOperation : null;
|
|
1813
|
+
const target = starting ? null : this.feed.currentTarget();
|
|
1814
|
+
return {
|
|
1815
|
+
key: starting ?? JSON.stringify(target),
|
|
1816
|
+
send: (force) => this.requestStop(force, starting, target)
|
|
1817
|
+
};
|
|
1818
|
+
}
|
|
1819
|
+
requestStop(force, starting = this.startSending.get() ? this.startOperation : null, target = starting ? null : this.feed.currentTarget()) {
|
|
1820
|
+
const session = this.feed.session.get();
|
|
1821
|
+
const pending = {
|
|
1822
|
+
action: force ? "force" : "stop",
|
|
1823
|
+
starting: !!starting,
|
|
1824
|
+
key: starting ?? JSON.stringify(target)
|
|
1825
|
+
};
|
|
1826
|
+
this.pendingStops.add(pending);
|
|
1827
|
+
this.pendingRevision.update((n) => n + 1);
|
|
1828
|
+
this.stopSending.set(pending.action);
|
|
1829
|
+
const done = () => {
|
|
1830
|
+
this.pendingStops.delete(pending);
|
|
1831
|
+
this.pendingRevision.update((n) => n + 1);
|
|
1832
|
+
const remaining = [...this.pendingStops];
|
|
1833
|
+
this.stopAskedWhileStarting.set(remaining.some((p) => p.starting));
|
|
1834
|
+
this.stopSending.set(remaining.at(-1)?.action ?? null);
|
|
1835
|
+
};
|
|
1836
|
+
if (!starting) {
|
|
1837
|
+
if (!target) {
|
|
1838
|
+
const message = "no session and server instance are known: no stop was sent; reconnect and check the current run";
|
|
1839
|
+
this.failure.set({
|
|
1840
|
+
message,
|
|
1841
|
+
session: session?.id ?? null,
|
|
1842
|
+
running: session?.launcher.running ?? false
|
|
1843
|
+
});
|
|
1844
|
+
done();
|
|
1845
|
+
return Promise.reject(new Error(message));
|
|
1846
|
+
}
|
|
1847
|
+
return this.send("api/stop-session", { force, ...target }, void 0, done);
|
|
1848
|
+
}
|
|
1849
|
+
this.stopAskedWhileStarting.set(true);
|
|
1850
|
+
return starting.then(
|
|
1851
|
+
({ summary, instance }) => {
|
|
1852
|
+
if (!summary || !instance) {
|
|
1853
|
+
const message = "the start answer did not identify the run; no stop was sent";
|
|
1854
|
+
const session2 = this.feed.session.get();
|
|
1855
|
+
this.failure.set({
|
|
1856
|
+
message,
|
|
1857
|
+
session: session2?.id ?? null,
|
|
1858
|
+
running: session2?.launcher.running ?? false
|
|
1859
|
+
});
|
|
1860
|
+
throw new Error(message);
|
|
1861
|
+
}
|
|
1862
|
+
pending.key = JSON.stringify({ session: summary.id, instance });
|
|
1863
|
+
this.pendingRevision.update((n) => n + 1);
|
|
1864
|
+
return this.send(
|
|
1865
|
+
"api/stop-session",
|
|
1866
|
+
{ force, session: summary.id, instance },
|
|
1867
|
+
void 0,
|
|
1868
|
+
() => void 0
|
|
1869
|
+
);
|
|
1870
|
+
},
|
|
1871
|
+
(error) => {
|
|
1872
|
+
const message = `the start was not confirmed; no stop was sent: ${errorMessage(error)}`;
|
|
1873
|
+
const session2 = this.feed.session.get();
|
|
1874
|
+
this.failure.set({
|
|
1875
|
+
message,
|
|
1876
|
+
session: session2?.id ?? null,
|
|
1877
|
+
running: session2?.launcher.running ?? false
|
|
1878
|
+
});
|
|
1879
|
+
throw new Error(message);
|
|
1880
|
+
}
|
|
1881
|
+
).finally(done);
|
|
1459
1882
|
}
|
|
1460
1883
|
/**
|
|
1461
1884
|
* Sends and applies the summary in the answer. done is called after the answer (failures too), before the Promise
|
|
1462
1885
|
* settles.
|
|
1463
1886
|
*/
|
|
1464
|
-
send(path, body, timeoutMs, done) {
|
|
1887
|
+
send(path, body, timeoutMs, done, onInstance) {
|
|
1888
|
+
const incompatible = this.feed.incompatible.get();
|
|
1889
|
+
if (incompatible) {
|
|
1890
|
+
done();
|
|
1891
|
+
return Promise.reject(new Error(incompatible));
|
|
1892
|
+
}
|
|
1465
1893
|
this.failure.set(null);
|
|
1466
1894
|
return new Promise((resolve, reject) => {
|
|
1467
1895
|
this.transport({ method: "POST", path, body, timeoutMs }, (outcome) => {
|
|
1468
1896
|
if (!outcome.ok) {
|
|
1897
|
+
const failure = path === "api/stop-session" && outcome.error.status === 404 ? new HttpError(404, outcome.error.statusText, {
|
|
1898
|
+
code: "targeted-stop-unsupported",
|
|
1899
|
+
message: "the GUI server cannot stop a particular session: no stop was sent; use the GUI server of this release"
|
|
1900
|
+
}) : outcome.error;
|
|
1469
1901
|
const session = this.feed.session.get();
|
|
1470
1902
|
this.failure.set({
|
|
1471
|
-
message: answerMissing(path,
|
|
1903
|
+
message: answerMissing(path, failure) ?? errorMessage(failure),
|
|
1472
1904
|
session: session?.id ?? null,
|
|
1473
1905
|
running: session?.launcher.running ?? false
|
|
1474
1906
|
});
|
|
1475
1907
|
done();
|
|
1476
|
-
reject(
|
|
1908
|
+
reject(failure);
|
|
1477
1909
|
return;
|
|
1478
1910
|
}
|
|
1479
1911
|
let summary = null;
|
|
1480
1912
|
try {
|
|
1913
|
+
const instance = path === "api/stop-session" ? body.instance : readSessionInstance(outcome.body);
|
|
1481
1914
|
summary = readSessionResponse(outcome.body);
|
|
1482
|
-
|
|
1915
|
+
if (path === "api/stop-session" && (!summary || summary.id !== body.session)) {
|
|
1916
|
+
throw new Error("the stop answer did not identify the requested session");
|
|
1917
|
+
}
|
|
1918
|
+
onInstance?.(instance);
|
|
1919
|
+
this.feed.adopt(summary, instance);
|
|
1483
1920
|
} catch (error) {
|
|
1484
1921
|
this.feed.report(
|
|
1485
1922
|
error instanceof ProtocolError ? `unreadable answer: ${error.message}` : String(error)
|
|
1486
1923
|
);
|
|
1924
|
+
const missingInstance = error instanceof ProtocolError && error.path === "response.instance";
|
|
1925
|
+
if (path === "api/stop-session" || missingInstance) {
|
|
1926
|
+
const message = missingInstance ? `${error.message}. The run may have started. Check the current run before retrying` : "the stop answer was unreadable: check the session before trying again";
|
|
1927
|
+
const session = this.feed.session.get();
|
|
1928
|
+
this.failure.set({
|
|
1929
|
+
message,
|
|
1930
|
+
session: session?.id ?? null,
|
|
1931
|
+
running: session?.launcher.running ?? false
|
|
1932
|
+
});
|
|
1933
|
+
done();
|
|
1934
|
+
reject(new Error(message));
|
|
1935
|
+
return;
|
|
1936
|
+
}
|
|
1487
1937
|
}
|
|
1488
1938
|
done();
|
|
1489
1939
|
resolve(summary);
|
|
@@ -1493,6 +1943,33 @@ var RunControl = class {
|
|
|
1493
1943
|
};
|
|
1494
1944
|
|
|
1495
1945
|
// ../client/src/session-state.ts
|
|
1946
|
+
function launcherAnswer(state, name) {
|
|
1947
|
+
if (!state) {
|
|
1948
|
+
return {
|
|
1949
|
+
reason: { code: "unsupported", message: "the launcher has not said yet what it accepts" },
|
|
1950
|
+
caution: null
|
|
1951
|
+
};
|
|
1952
|
+
}
|
|
1953
|
+
const item = Object.hasOwn(state.allowed, name) ? state.allowed[name] : void 0;
|
|
1954
|
+
if (!item) {
|
|
1955
|
+
return {
|
|
1956
|
+
reason: {
|
|
1957
|
+
code: "unsupported",
|
|
1958
|
+
message: `this launcher does not say whether it accepts ${name}`
|
|
1959
|
+
},
|
|
1960
|
+
caution: null
|
|
1961
|
+
};
|
|
1962
|
+
}
|
|
1963
|
+
const caution = item.caution ? { code: item.caution.code, message: item.caution.message } : null;
|
|
1964
|
+
if (item.ok) return { reason: null, caution };
|
|
1965
|
+
return {
|
|
1966
|
+
reason: {
|
|
1967
|
+
code: item.reason ?? "refused",
|
|
1968
|
+
message: item.message ?? "the launcher does not accept it now"
|
|
1969
|
+
},
|
|
1970
|
+
caution
|
|
1971
|
+
};
|
|
1972
|
+
}
|
|
1496
1973
|
var MAX_LOG_LINES_PER_SOURCE = 2e3;
|
|
1497
1974
|
var MAX_LOG_LINES = 2e4;
|
|
1498
1975
|
var MAX_PROBLEMS = 200;
|
|
@@ -1500,8 +1977,6 @@ var MAX_FINDINGS = 500;
|
|
|
1500
1977
|
function timeView(time) {
|
|
1501
1978
|
return {
|
|
1502
1979
|
simMs: time.sim_ms,
|
|
1503
|
-
speed: time.speed,
|
|
1504
|
-
paused: time.paused,
|
|
1505
1980
|
actualSpeed: time.actual_speed,
|
|
1506
1981
|
lateSteps: time.late_steps,
|
|
1507
1982
|
maxLateMs: time.max_late_ms,
|
|
@@ -1515,6 +1990,7 @@ function commandView(command, seq) {
|
|
|
1515
1990
|
accepted: command.accepted,
|
|
1516
1991
|
message: command.message,
|
|
1517
1992
|
ms: command.ms,
|
|
1993
|
+
atMs: command.at_ms,
|
|
1518
1994
|
seq
|
|
1519
1995
|
};
|
|
1520
1996
|
}
|
|
@@ -1526,15 +2002,42 @@ function scenarioView(summary) {
|
|
|
1526
2002
|
steps: summary.steps,
|
|
1527
2003
|
stepsOmitted: summary.steps_omitted,
|
|
1528
2004
|
status: summary.status,
|
|
1529
|
-
overAtMs: summary.over_at_ms
|
|
2005
|
+
overAtMs: summary.over_at_ms,
|
|
2006
|
+
timelineUrl: summary.timeline_url
|
|
2007
|
+
};
|
|
2008
|
+
}
|
|
2009
|
+
function fullStepText(incoming, current) {
|
|
2010
|
+
if (incoming === null || current === null) return incoming;
|
|
2011
|
+
const cut = /^(.*)\.\.\. \((\d+) more characters\)$/s.exec(incoming);
|
|
2012
|
+
if (!cut) return incoming;
|
|
2013
|
+
const prefix = cut[1];
|
|
2014
|
+
return current.startsWith(prefix) && Array.from(current).length === Array.from(prefix).length + Number(cut[2]) ? current : incoming;
|
|
2015
|
+
}
|
|
2016
|
+
function mergeScenarioStep(current, incoming) {
|
|
2017
|
+
return {
|
|
2018
|
+
...incoming,
|
|
2019
|
+
text: fullStepText(incoming.text, current.text) ?? incoming.text,
|
|
2020
|
+
message: fullStepText(incoming.message, current.message)
|
|
1530
2021
|
};
|
|
1531
2022
|
}
|
|
2023
|
+
var stepPositions = /* @__PURE__ */ new WeakMap();
|
|
2024
|
+
function mergeScenarioSteps(current, incoming, merge = (_old, next) => next) {
|
|
2025
|
+
const steps = new Map(current.map((step) => [step.index, step]));
|
|
2026
|
+
for (const step of incoming) {
|
|
2027
|
+
const old = steps.get(step.index);
|
|
2028
|
+
steps.set(step.index, old ? merge(old, step) : step);
|
|
2029
|
+
}
|
|
2030
|
+
return [...steps.values()].sort((a, b) => a.index - b.index);
|
|
2031
|
+
}
|
|
1532
2032
|
function withStep(steps, step) {
|
|
1533
2033
|
const i = steps.findIndex((s) => s.index >= step.index);
|
|
1534
2034
|
if (i < 0) return [...steps, step];
|
|
1535
2035
|
if (steps[i].index === step.index) return steps.map((s, j) => j === i ? step : s);
|
|
1536
2036
|
return [...steps.slice(0, i), step, ...steps.slice(i)];
|
|
1537
2037
|
}
|
|
2038
|
+
function isHolding(session) {
|
|
2039
|
+
return !!session && session.launcher.running && session.launcherState?.holding === true;
|
|
2040
|
+
}
|
|
1538
2041
|
function runOutcome(session) {
|
|
1539
2042
|
if (session.launcher.running) {
|
|
1540
2043
|
if (session.result) return "finishing";
|
|
@@ -1546,6 +2049,7 @@ function runOutcome(session) {
|
|
|
1546
2049
|
function sessionFromSummary(summary) {
|
|
1547
2050
|
const blank = {
|
|
1548
2051
|
id: summary.id,
|
|
2052
|
+
...summary.snapshot_rev == null ? {} : { snapshotRev: summary.snapshot_rev },
|
|
1549
2053
|
lastSeq: -1,
|
|
1550
2054
|
file: summary.file,
|
|
1551
2055
|
disable: summary.disable,
|
|
@@ -1565,6 +2069,7 @@ function sessionFromSummary(summary) {
|
|
|
1565
2069
|
time: null,
|
|
1566
2070
|
stopRequests: 0,
|
|
1567
2071
|
lastCommand: null,
|
|
2072
|
+
launcherState: null,
|
|
1568
2073
|
result: null,
|
|
1569
2074
|
launcher: launcherOf(summary),
|
|
1570
2075
|
problems: [],
|
|
@@ -1574,7 +2079,11 @@ function sessionFromSummary(summary) {
|
|
|
1574
2079
|
droppedMarks: 0,
|
|
1575
2080
|
scenario: null
|
|
1576
2081
|
};
|
|
1577
|
-
|
|
2082
|
+
const adopted = applySummary(blank, summary, true);
|
|
2083
|
+
return summary.last_seq == null ? adopted : {
|
|
2084
|
+
...adopted,
|
|
2085
|
+
pendingFindings: { through: summary.last_seq, keys: summary.findings.map(findingIdentity) }
|
|
2086
|
+
};
|
|
1578
2087
|
}
|
|
1579
2088
|
function addDropped(session, dropped) {
|
|
1580
2089
|
const counts = Object.entries(dropped.log).filter(([, count2]) => count2 > 0);
|
|
@@ -1585,7 +2094,11 @@ function addDropped(session, dropped) {
|
|
|
1585
2094
|
key: `dropped ${mark} ${source}`,
|
|
1586
2095
|
source,
|
|
1587
2096
|
line: "",
|
|
1588
|
-
gap: {
|
|
2097
|
+
gap: {
|
|
2098
|
+
count: count2,
|
|
2099
|
+
atLeast: dropped.at_least.includes(source),
|
|
2100
|
+
...dropped.reason === "not-kept" ? { notKept: true } : {}
|
|
2101
|
+
}
|
|
1589
2102
|
}));
|
|
1590
2103
|
const next = { ...appendLogs(session, gaps), droppedMarks: mark };
|
|
1591
2104
|
const sources = { ...next.logSources };
|
|
@@ -1607,23 +2120,49 @@ function launcherOf(summary) {
|
|
|
1607
2120
|
};
|
|
1608
2121
|
}
|
|
1609
2122
|
function applySummary(session, summary, force = false, controlOnly = false) {
|
|
1610
|
-
const
|
|
2123
|
+
const incomingRev = summary.snapshot_rev ?? null;
|
|
2124
|
+
const currentRev = session.snapshotRev ?? null;
|
|
2125
|
+
const staleControl = currentRev !== null && (incomingRev === null || incomingRev < currentRev);
|
|
2126
|
+
const projectionRev = session.projectionRev ?? null;
|
|
2127
|
+
const staleProjection = projectionRev !== null && (incomingRev === null || incomingRev < projectionRev);
|
|
2128
|
+
if (staleControl && (staleProjection || !force && controlOnly)) return session;
|
|
2129
|
+
const newer = force || (summary.last_seq ?? -1) > Math.max(session.lastSeq, session.observedSeq ?? -1, session.projectionSeq ?? -1);
|
|
1611
2130
|
const launcher = !force && !session.launcher.running && summary.launcher.running ? session.launcher : launcherOf(summary);
|
|
1612
2131
|
const notLess = summary.problems.length + summary.problems_omitted >= session.problems.length + session.problemsOmitted;
|
|
1613
|
-
const
|
|
2132
|
+
const mergedProblems = [...summary.problems];
|
|
2133
|
+
let omitted = summary.problems_omitted;
|
|
2134
|
+
if (summary.problem_seq != null) {
|
|
2135
|
+
const included = new Set(mergedProblems.map((problem) => problem.problem_seq));
|
|
2136
|
+
for (const problem of session.problems) {
|
|
2137
|
+
if (problem.problem_seq === void 0 || included.has(problem.problem_seq)) continue;
|
|
2138
|
+
if (mergedProblems.length >= MAX_PROBLEMS) break;
|
|
2139
|
+
mergedProblems.push(problem);
|
|
2140
|
+
if (problem.problem_seq <= summary.problem_seq && omitted > 0) omitted--;
|
|
2141
|
+
}
|
|
2142
|
+
}
|
|
2143
|
+
if (mergedProblems.every((problem) => problem.problem_seq !== void 0))
|
|
2144
|
+
mergedProblems.sort((a, b) => a.problem_seq - b.problem_seq);
|
|
2145
|
+
const next = staleControl ? session : {
|
|
1614
2146
|
...session,
|
|
2147
|
+
...incomingRev === null ? {} : { snapshotRev: incomingRev },
|
|
2148
|
+
...summary.problem_seq == null ? {} : { problemSeq: Math.max(session.problemSeq ?? 0, summary.problem_seq) },
|
|
1615
2149
|
launcher,
|
|
1616
2150
|
stopRequests: Math.max(session.stopRequests, stopRequestsOf(summary.stop)),
|
|
1617
2151
|
logSources: withSources(session.logSources, Object.keys(summary.log)),
|
|
1618
|
-
...
|
|
2152
|
+
...summary.scenario?.timeline_url ? {
|
|
2153
|
+
scenario: session.scenario ? { ...session.scenario, timelineUrl: summary.scenario.timeline_url } : scenarioView(summary.scenario)
|
|
2154
|
+
} : {},
|
|
2155
|
+
...force || notLess ? { problems: mergedProblems, problemsOmitted: omitted } : {}
|
|
1619
2156
|
};
|
|
1620
|
-
if (!newer || !force && controlOnly) {
|
|
2157
|
+
if (!newer || staleProjection || !force && controlOnly) {
|
|
1621
2158
|
return next;
|
|
1622
2159
|
}
|
|
1623
2160
|
const phase = summary.phase ?? next.phase;
|
|
1624
2161
|
const rank = phaseIndex(phase);
|
|
1625
|
-
const
|
|
1626
|
-
const
|
|
2162
|
+
const preserveEvents = force && controlOnly;
|
|
2163
|
+
const behind = (...kinds) => summary.last_seq !== null && kinds.some((kind) => (session.eventSeqs?.[kind] ?? -1) > summary.last_seq);
|
|
2164
|
+
const check = (preserveEvents ? next.check : null) ?? summary.check ?? next.check ?? summary.result?.check ?? null;
|
|
2165
|
+
const result = (preserveEvents ? next.result : null) ?? summary.result ?? next.result;
|
|
1627
2166
|
const known = new Map(session.participants.map((p) => [p.name, p]));
|
|
1628
2167
|
const participants = summary.participants.map((p) => ({
|
|
1629
2168
|
name: p.name,
|
|
@@ -1633,35 +2172,72 @@ function applySummary(session, summary, force = false, controlOnly = false) {
|
|
|
1633
2172
|
exitCode: p.exit_code,
|
|
1634
2173
|
signal: p.signal,
|
|
1635
2174
|
failure: p.reason,
|
|
1636
|
-
message: p.message,
|
|
2175
|
+
message: p.message ?? (preserveEvents ? known.get(p.name)?.message ?? null : null),
|
|
1637
2176
|
// A stop the launcher asked for is kept even in summaries of later states (ended and so on)
|
|
1638
2177
|
stopRequested: p.stop_requested || p.state === "stop_requested" || !!known.get(p.name)?.stopRequested,
|
|
1639
2178
|
omittedFields: p.omitted_fields,
|
|
1640
2179
|
controlLink: p.control_link ?? known.get(p.name)?.controlLink ?? null,
|
|
1641
2180
|
manual: p.state === "manual" || p.command_line !== null || !!known.get(p.name)?.manual,
|
|
1642
|
-
commandLine: p.command_line,
|
|
1643
|
-
workingDirectory: p.working_directory,
|
|
1644
|
-
environment: p.environment ?? {}
|
|
2181
|
+
commandLine: p.command_line ?? (preserveEvents ? known.get(p.name)?.commandLine ?? null : null),
|
|
2182
|
+
workingDirectory: p.working_directory ?? (preserveEvents ? known.get(p.name)?.workingDirectory ?? null : null),
|
|
2183
|
+
environment: p.environment ?? (preserveEvents ? known.get(p.name)?.environment ?? {} : {})
|
|
1645
2184
|
}));
|
|
1646
|
-
|
|
2185
|
+
const scenario = summary.scenario ? {
|
|
2186
|
+
...scenarioView(summary.scenario),
|
|
2187
|
+
timelineUrl: next.scenario?.timelineUrl ?? summary.scenario.timeline_url
|
|
2188
|
+
} : next.scenario;
|
|
2189
|
+
let mergedScenario = preserveEvents && scenario && next.scenario ? {
|
|
2190
|
+
...scenario,
|
|
2191
|
+
steps: mergeScenarioSteps(
|
|
2192
|
+
next.scenario.steps,
|
|
2193
|
+
scenario.steps,
|
|
2194
|
+
(old, step) => summary.last_seq !== null && (stepPositions.get(old) ?? -1) > summary.last_seq ? old : mergeScenarioStep(old, step)
|
|
2195
|
+
)
|
|
2196
|
+
} : scenario;
|
|
2197
|
+
if (mergedScenario && result?.scenario) {
|
|
2198
|
+
mergedScenario = {
|
|
2199
|
+
...mergedScenario,
|
|
2200
|
+
steps: mergeScenarioSteps(mergedScenario.steps, result.scenario.steps)
|
|
2201
|
+
};
|
|
2202
|
+
}
|
|
2203
|
+
if (mergedScenario && scenario && mergedScenario !== scenario) {
|
|
2204
|
+
mergedScenario.stepsOmitted = Math.max(
|
|
2205
|
+
0,
|
|
2206
|
+
scenario.stepsOmitted - (mergedScenario.steps.length - scenario.steps.length)
|
|
2207
|
+
);
|
|
2208
|
+
}
|
|
2209
|
+
const mergedParticipants = preserveEvents ? [
|
|
2210
|
+
...participants,
|
|
2211
|
+
...next.participants.filter(
|
|
2212
|
+
(p) => !participants.some((current) => current.name === p.name)
|
|
2213
|
+
)
|
|
2214
|
+
] : participants;
|
|
2215
|
+
return {
|
|
1647
2216
|
...next,
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
2217
|
+
...incomingRev === null ? {} : { projectionRev: incomingRev },
|
|
2218
|
+
projectionSeq: Math.max(next.projectionSeq ?? -1, summary.last_seq ?? -1),
|
|
2219
|
+
unreadable: force && !behind("finding", "result", "participant") ? summary.unreadable : union(next.unreadable, summary.unreadable),
|
|
2220
|
+
phase: behind("phase", "result") ? next.phase ?? phase : phase,
|
|
2221
|
+
phaseRank: behind("phase", "result") ? next.phaseRank : rank >= 0 ? rank : next.phaseRank,
|
|
1651
2222
|
elapsedMs: Math.max(next.elapsedMs, summary.last_t_ms ?? 0),
|
|
1652
|
-
simMs: summary.sim_ms ?? next.simMs,
|
|
1653
|
-
timeOmittedFields: summary.sim_ms === null ? next.timeOmittedFields : summary.time_omitted_fields,
|
|
1654
|
-
time: summary.time ? timeView(summary.time) : next.time,
|
|
1655
|
-
lastCommand: summary.last_command ? commandView(summary.last_command, summary.last_command.seq ?? -1) : next.lastCommand,
|
|
1656
|
-
|
|
2223
|
+
simMs: behind("time") ? next.simMs ?? summary.sim_ms : summary.sim_ms ?? next.simMs,
|
|
2224
|
+
timeOmittedFields: behind("time") || summary.sim_ms === null ? next.timeOmittedFields : summary.time_omitted_fields,
|
|
2225
|
+
time: behind("time") && next.time ? next.time : summary.time ? timeView(summary.time) : next.time,
|
|
2226
|
+
lastCommand: behind("command") && next.lastCommand ? next.lastCommand : summary.last_command ? commandView(summary.last_command, summary.last_command.seq ?? -1) : next.lastCommand,
|
|
2227
|
+
launcherState: newerState(next.launcherState, summary.launcher_state ?? null),
|
|
2228
|
+
findings: preserveEvents ? mergeFindings(next.findings, summary.findings) : summary.findings,
|
|
1657
2229
|
result,
|
|
1658
2230
|
check,
|
|
1659
|
-
scenario:
|
|
2231
|
+
scenario: mergedScenario,
|
|
1660
2232
|
// Whether a participant is required or left out is in the check result (as is the order, that of the configuration
|
|
1661
2233
|
// file). If there is a result, how it ended (stopped or not) comes from the result too
|
|
1662
|
-
participants: withResult(check ? mergeCheck(
|
|
2234
|
+
participants: behind("participant", "result", CONTROL_EVENT) && next.participants.length > 0 ? next.participants : withResult(check ? mergeCheck(mergedParticipants, check) : mergedParticipants, result)
|
|
1663
2235
|
};
|
|
1664
2236
|
}
|
|
2237
|
+
function newerState(current, incoming) {
|
|
2238
|
+
if (!incoming) return current;
|
|
2239
|
+
return !current || incoming.rev >= current.rev ? incoming : current;
|
|
2240
|
+
}
|
|
1665
2241
|
function union(a, b) {
|
|
1666
2242
|
return b.every((name) => a.includes(name)) ? a : [.../* @__PURE__ */ new Set([...a, ...b])];
|
|
1667
2243
|
}
|
|
@@ -1673,20 +2249,101 @@ function withSources(sources, names) {
|
|
|
1673
2249
|
return next;
|
|
1674
2250
|
}
|
|
1675
2251
|
function addProblem(session, problem) {
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
}
|
|
1679
|
-
|
|
2252
|
+
const seq = problem.problem_seq;
|
|
2253
|
+
if (seq !== void 0 && seq <= (session.problemEventSeq ?? 0)) return session;
|
|
2254
|
+
const updated = seq === void 0 ? session : { ...session, problemEventSeq: seq };
|
|
2255
|
+
if (seq !== void 0 && session.problems.some((item) => item.problem_seq === seq))
|
|
2256
|
+
return updated;
|
|
2257
|
+
if (updated.problems.length >= MAX_PROBLEMS) {
|
|
2258
|
+
const alreadyCounted2 = seq !== void 0 && seq <= (session.problemSeq ?? 0);
|
|
2259
|
+
return alreadyCounted2 ? updated : { ...updated, problemsOmitted: updated.problemsOmitted + 1 };
|
|
2260
|
+
}
|
|
2261
|
+
const alreadyCounted = seq !== void 0 && seq <= (session.problemSeq ?? 0);
|
|
2262
|
+
const problems = [...updated.problems, problem];
|
|
2263
|
+
if (problems.every((item) => item.problem_seq !== void 0))
|
|
2264
|
+
problems.sort((a, b) => a.problem_seq - b.problem_seq);
|
|
2265
|
+
return {
|
|
2266
|
+
...updated,
|
|
2267
|
+
problems,
|
|
2268
|
+
problemsOmitted: alreadyCounted ? Math.max(0, updated.problemsOmitted - 1) : updated.problemsOmitted
|
|
2269
|
+
};
|
|
1680
2270
|
}
|
|
1681
2271
|
function phaseIndex(phase) {
|
|
1682
2272
|
return phase === null ? -1 : PHASES.indexOf(phase);
|
|
1683
2273
|
}
|
|
2274
|
+
function findingKey(finding) {
|
|
2275
|
+
return JSON.stringify([
|
|
2276
|
+
finding.severity,
|
|
2277
|
+
finding.code,
|
|
2278
|
+
finding.file,
|
|
2279
|
+
finding.line,
|
|
2280
|
+
finding.participant,
|
|
2281
|
+
finding.network,
|
|
2282
|
+
finding.message,
|
|
2283
|
+
finding.detail
|
|
2284
|
+
]);
|
|
2285
|
+
}
|
|
2286
|
+
function findingIdentity(finding) {
|
|
2287
|
+
return finding.event_seq === void 0 ? `body:${findingKey(finding)}` : `seq:${finding.event_seq}`;
|
|
2288
|
+
}
|
|
2289
|
+
function mergeFindings(current, incoming) {
|
|
2290
|
+
const a = current.slice(0, MAX_FINDINGS);
|
|
2291
|
+
const b = incoming.slice(0, MAX_FINDINGS);
|
|
2292
|
+
if (a.every((finding) => finding.event_seq !== void 0) && b.every((finding) => finding.event_seq !== void 0)) {
|
|
2293
|
+
const bySeq = /* @__PURE__ */ new Map();
|
|
2294
|
+
for (const finding of [...b, ...a]) bySeq.set(finding.event_seq, finding);
|
|
2295
|
+
return [...bySeq.values()].sort((left, right) => left.event_seq - right.event_seq).slice(0, MAX_FINDINGS);
|
|
2296
|
+
}
|
|
2297
|
+
const ak = a.map(findingKey);
|
|
2298
|
+
const bk = b.map(findingKey);
|
|
2299
|
+
const sizes = Array.from({ length: a.length + 1 }, () => new Uint16Array(b.length + 1));
|
|
2300
|
+
for (let i2 = a.length - 1; i2 >= 0; --i2)
|
|
2301
|
+
for (let j2 = b.length - 1; j2 >= 0; --j2)
|
|
2302
|
+
sizes[i2][j2] = ak[i2] === bk[j2] ? 1 + sizes[i2 + 1][j2 + 1] : Math.max(sizes[i2 + 1][j2], sizes[i2][j2 + 1]);
|
|
2303
|
+
const merged = [];
|
|
2304
|
+
let i = 0, j = 0;
|
|
2305
|
+
while ((i < a.length || j < b.length) && merged.length < MAX_FINDINGS) {
|
|
2306
|
+
if (i < a.length && j < b.length && ak[i] === bk[j]) {
|
|
2307
|
+
merged.push(a[i++]);
|
|
2308
|
+
j++;
|
|
2309
|
+
} else if (j === b.length || i < a.length && sizes[i + 1][j] >= sizes[i][j + 1])
|
|
2310
|
+
merged.push(a[i++]);
|
|
2311
|
+
else merged.push(b[j++]);
|
|
2312
|
+
}
|
|
2313
|
+
return merged;
|
|
2314
|
+
}
|
|
1684
2315
|
function applyEvents(session, events, countStale = false) {
|
|
1685
2316
|
let next = session;
|
|
1686
2317
|
const logs = [];
|
|
1687
2318
|
let stale = 0;
|
|
1688
2319
|
for (const event of events) {
|
|
1689
2320
|
if (event.seq > next.lastSeq) {
|
|
2321
|
+
const tracked = [
|
|
2322
|
+
"time",
|
|
2323
|
+
"phase",
|
|
2324
|
+
"result",
|
|
2325
|
+
"finding",
|
|
2326
|
+
"participant",
|
|
2327
|
+
"command",
|
|
2328
|
+
CONTROL_EVENT
|
|
2329
|
+
].includes(event.event);
|
|
2330
|
+
if (event.event === "scenario_step") stepPositions.set(event.step, event.seq);
|
|
2331
|
+
next = {
|
|
2332
|
+
...next,
|
|
2333
|
+
observedSeq: Math.max(next.observedSeq ?? -1, event.seq),
|
|
2334
|
+
...tracked ? { eventSeqs: { ...next.eventSeqs, [event.event]: event.seq } } : {}
|
|
2335
|
+
};
|
|
2336
|
+
const pending = next.pendingFindings;
|
|
2337
|
+
if (event.event === "finding" && pending && event.seq <= pending.through) {
|
|
2338
|
+
const numbered = pending.keys.indexOf(`seq:${event.seq}`);
|
|
2339
|
+
const index = numbered === -1 ? pending.keys.indexOf(`body:${findingKey(event.finding)}`) : numbered;
|
|
2340
|
+
if (index !== -1) {
|
|
2341
|
+
const keys = [...pending.keys];
|
|
2342
|
+
keys.splice(index, 1);
|
|
2343
|
+
next = { ...next, lastSeq: event.seq, pendingFindings: { ...pending, keys } };
|
|
2344
|
+
continue;
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
1690
2347
|
next = applyOne(next, event, logs);
|
|
1691
2348
|
if (event.unreadable)
|
|
1692
2349
|
next = { ...next, unreadable: union(next.unreadable, event.unreadable) };
|
|
@@ -1706,6 +2363,37 @@ function applyEvents(session, events, countStale = false) {
|
|
|
1706
2363
|
}
|
|
1707
2364
|
return { ...next, logSources: sources };
|
|
1708
2365
|
}
|
|
2366
|
+
function recoverReplayLogs(session, recovered, notKept) {
|
|
2367
|
+
if (!recovered.length) return session;
|
|
2368
|
+
const sources = Object.fromEntries(
|
|
2369
|
+
Object.entries(session.logSources).map(([name, source]) => [
|
|
2370
|
+
name,
|
|
2371
|
+
{ lines: 0, dropped: source.dropped }
|
|
2372
|
+
])
|
|
2373
|
+
);
|
|
2374
|
+
const restored = /* @__PURE__ */ new Map();
|
|
2375
|
+
for (const line of recovered) {
|
|
2376
|
+
const source = sources[line.source] ??= { lines: 0, dropped: 0 };
|
|
2377
|
+
if (line.gap) source.dropped += line.gap.count;
|
|
2378
|
+
else {
|
|
2379
|
+
const count2 = restored.get(line.source) ?? 0;
|
|
2380
|
+
if (count2 < (notKept.get(line.source) ?? 0)) {
|
|
2381
|
+
source.dropped--;
|
|
2382
|
+
restored.set(line.source, count2 + 1);
|
|
2383
|
+
}
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2386
|
+
const logs = session.logs.flatMap((line) => {
|
|
2387
|
+
if (!line.gap?.notKept) return [line];
|
|
2388
|
+
const available = restored.get(line.source) ?? 0;
|
|
2389
|
+
const count2 = Math.max(0, line.gap.count - available);
|
|
2390
|
+
restored.set(line.source, Math.max(0, available - line.gap.count));
|
|
2391
|
+
return count2 > 0 ? [{ ...line, gap: { ...line.gap, count: count2 } }] : [];
|
|
2392
|
+
});
|
|
2393
|
+
logs.push(...recovered);
|
|
2394
|
+
logs.sort((a, b) => a.seq - b.seq);
|
|
2395
|
+
return appendLogs({ ...session, logs: [], logSources: sources }, logs);
|
|
2396
|
+
}
|
|
1709
2397
|
function appendLogs(session, added) {
|
|
1710
2398
|
const sources = {};
|
|
1711
2399
|
for (const [source, counts] of Object.entries(session.logSources))
|
|
@@ -1799,11 +2487,16 @@ function applyOne(session, event, logs) {
|
|
|
1799
2487
|
}
|
|
1800
2488
|
return next;
|
|
1801
2489
|
case "finding":
|
|
1802
|
-
return next.findings.length >= MAX_FINDINGS ? next : {
|
|
2490
|
+
return next.findings.length >= MAX_FINDINGS ? next : {
|
|
2491
|
+
...next,
|
|
2492
|
+
findings: next.findings.every((finding) => finding.event_seq !== void 0) ? mergeFindings(next.findings, [{ ...event.finding, event_seq: event.seq }]) : [...next.findings, { ...event.finding, event_seq: event.seq }]
|
|
2493
|
+
};
|
|
1803
2494
|
case "time":
|
|
1804
2495
|
return { ...next, simMs: event.sim_ms, timeOmittedFields: [], time: timeView(event) };
|
|
1805
2496
|
case "command":
|
|
1806
2497
|
return { ...next, lastCommand: commandView(event, event.seq) };
|
|
2498
|
+
case "state":
|
|
2499
|
+
return { ...next, launcherState: newerState(next.launcherState, event) };
|
|
1807
2500
|
case "result":
|
|
1808
2501
|
return {
|
|
1809
2502
|
...next,
|
|
@@ -1920,6 +2613,8 @@ var SessionFeed = class {
|
|
|
1920
2613
|
this.onError = onError;
|
|
1921
2614
|
this.current = new Writable(null, Object.is, onError);
|
|
1922
2615
|
this.synced = new Writable(false, Object.is, onError);
|
|
2616
|
+
this.allowedValue = new Writable(null, Object.is, onError);
|
|
2617
|
+
this.allowed = this.allowedValue.readonly();
|
|
1923
2618
|
this.receivedAt = new Writable(0, Object.is, onError);
|
|
1924
2619
|
this.noticeList = new Writable([], Object.is, onError);
|
|
1925
2620
|
this.rejectedValue = new Writable(false, Object.is, onError);
|
|
@@ -1937,13 +2632,20 @@ var SessionFeed = class {
|
|
|
1937
2632
|
);
|
|
1938
2633
|
connection.onBatch((batch) => this.receive(batch));
|
|
1939
2634
|
connection.onUnreadable(
|
|
1940
|
-
(
|
|
2635
|
+
(text3) => this.notify(`unreadable message: not JSON (connecting again): ${text3.slice(0, 80)}`)
|
|
1941
2636
|
);
|
|
1942
2637
|
}
|
|
1943
2638
|
connection;
|
|
1944
2639
|
onError;
|
|
2640
|
+
rawListeners = /* @__PURE__ */ new Set();
|
|
2641
|
+
snapshotVersion = () => 0;
|
|
2642
|
+
instanceId = null;
|
|
2643
|
+
adoptionRevision = 0;
|
|
2644
|
+
instanceListener = () => void 0;
|
|
2645
|
+
stopTarget = null;
|
|
1945
2646
|
current;
|
|
1946
2647
|
synced;
|
|
2648
|
+
allowedValue;
|
|
1947
2649
|
receivedAt;
|
|
1948
2650
|
noticeList;
|
|
1949
2651
|
rejectedValue;
|
|
@@ -1951,8 +2653,10 @@ var SessionFeed = class {
|
|
|
1951
2653
|
messageListeners = /* @__PURE__ */ new Set();
|
|
1952
2654
|
noticeId = 0;
|
|
1953
2655
|
stoppedFlag = false;
|
|
2656
|
+
replayLogs = null;
|
|
1954
2657
|
session;
|
|
1955
2658
|
ready;
|
|
2659
|
+
allowed;
|
|
1956
2660
|
lastEventAt;
|
|
1957
2661
|
notices;
|
|
1958
2662
|
rejected;
|
|
@@ -1968,8 +2672,7 @@ var SessionFeed = class {
|
|
|
1968
2672
|
*/
|
|
1969
2673
|
resumeFields() {
|
|
1970
2674
|
this.synced.set(false);
|
|
1971
|
-
|
|
1972
|
-
return session ? { session: session.id, from_seq: session.lastSeq + 1 } : {};
|
|
2675
|
+
return {};
|
|
1973
2676
|
}
|
|
1974
2677
|
onMessages(listener) {
|
|
1975
2678
|
this.messageListeners.add(listener);
|
|
@@ -1983,14 +2686,65 @@ var SessionFeed = class {
|
|
|
1983
2686
|
* request for the same run (the rest arrives in notifications). A summary of an earlier run never brings back an old
|
|
1984
2687
|
* run over a new one.
|
|
1985
2688
|
*/
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
this.
|
|
1992
|
-
|
|
1993
|
-
|
|
2689
|
+
onRawMessages(listener) {
|
|
2690
|
+
this.rawListeners.add(listener);
|
|
2691
|
+
return () => this.rawListeners.delete(listener);
|
|
2692
|
+
}
|
|
2693
|
+
onSnapshotVersion(read2) {
|
|
2694
|
+
this.snapshotVersion = read2;
|
|
2695
|
+
}
|
|
2696
|
+
/** Called before a new server's session can be published. */
|
|
2697
|
+
onInstance(listener) {
|
|
2698
|
+
this.instanceListener = listener;
|
|
2699
|
+
}
|
|
2700
|
+
/** Instance associated with the current session, or null if its origin is not known. */
|
|
2701
|
+
currentInstance() {
|
|
2702
|
+
return this.instanceId;
|
|
2703
|
+
}
|
|
2704
|
+
currentTarget() {
|
|
2705
|
+
return this.stopTarget ? { ...this.stopTarget } : null;
|
|
2706
|
+
}
|
|
2707
|
+
adopt(summary, instance, resyncFrom) {
|
|
2708
|
+
const switching = this.instanceId !== null && instance !== this.instanceId;
|
|
2709
|
+
if (switching && (resyncFrom !== this.instanceId || this.connection.state.get() === "open"))
|
|
2710
|
+
return null;
|
|
2711
|
+
const previous = switching ? null : this.current.get();
|
|
2712
|
+
if (summary && previous && summary.id < previous.id) return null;
|
|
2713
|
+
if (!summary && instance === this.instanceId)
|
|
2714
|
+
return {
|
|
2715
|
+
revision: this.adoptionRevision,
|
|
2716
|
+
instance,
|
|
2717
|
+
session: previous?.id ?? null
|
|
2718
|
+
};
|
|
2719
|
+
const revision = ++this.adoptionRevision;
|
|
2720
|
+
const next = !summary ? null : previous?.id === summary.id ? applySummary(previous, summary, false, this.connection.state.get() === "open") : sessionFromSummary(summary);
|
|
2721
|
+
const changedInstance = instance !== this.instanceId;
|
|
2722
|
+
this.instanceId = instance;
|
|
2723
|
+
const adoption = { revision, instance, session: next?.id ?? null };
|
|
2724
|
+
this.stopTarget = next ? { session: next.id, instance } : null;
|
|
2725
|
+
const notifySession = this.current.setDeferred(next);
|
|
2726
|
+
const notifyAllowed = switching ? this.allowedValue.setDeferred(null) : () => void 0;
|
|
2727
|
+
if (changedInstance) this.instanceListener(instance, () => this.isCurrent(revision));
|
|
2728
|
+
notifySession();
|
|
2729
|
+
notifyAllowed();
|
|
2730
|
+
if (!this.sameRun(adoption)) return null;
|
|
2731
|
+
this.adoptAllowed(summary?.allowed ?? null);
|
|
2732
|
+
return this.sameRun(adoption) ? adoption : null;
|
|
2733
|
+
}
|
|
2734
|
+
sameRun(adoption) {
|
|
2735
|
+
return this.instanceId === adoption.instance && (this.current.get()?.id ?? null) === adoption.session;
|
|
2736
|
+
}
|
|
2737
|
+
isCurrent(revision) {
|
|
2738
|
+
return revision === this.adoptionRevision;
|
|
2739
|
+
}
|
|
2740
|
+
/**
|
|
2741
|
+
* Takes what the server accepts (an HTTP answer or a notification): the one with the larger `rev` wins (rev 0 is a
|
|
2742
|
+
* server that does not number it: the newest arrival wins). Used inside the library.
|
|
2743
|
+
*/
|
|
2744
|
+
adoptAllowed(allowed) {
|
|
2745
|
+
if (!allowed) return;
|
|
2746
|
+
const current = this.allowedValue.get();
|
|
2747
|
+
if (!current || allowed.rev === 0 || allowed.rev >= current.rev) this.allowedValue.set(allowed);
|
|
1994
2748
|
}
|
|
1995
2749
|
report(message, count2 = 1) {
|
|
1996
2750
|
this.notify(message, count2);
|
|
@@ -2000,7 +2754,12 @@ var SessionFeed = class {
|
|
|
2000
2754
|
}
|
|
2001
2755
|
/** Reads and applies a batch from the connection. */
|
|
2002
2756
|
receive(raw) {
|
|
2757
|
+
const snapshotVersion = this.snapshotVersion();
|
|
2758
|
+
const epoch = this.connection.batchEpoch();
|
|
2759
|
+
let originInstance = this.instanceId;
|
|
2760
|
+
const currentOrigin = () => this.connection.batchEpoch() === epoch && this.instanceId === originInstance;
|
|
2003
2761
|
const batch = [];
|
|
2762
|
+
const accepted = [];
|
|
2004
2763
|
let stop = null;
|
|
2005
2764
|
let incompatible = null;
|
|
2006
2765
|
for (const value of raw) {
|
|
@@ -2011,6 +2770,7 @@ var SessionFeed = class {
|
|
|
2011
2770
|
this.notify(
|
|
2012
2771
|
error instanceof ProtocolError ? `unreadable message: ${error.message}` : String(error)
|
|
2013
2772
|
);
|
|
2773
|
+
if (!currentOrigin()) return;
|
|
2014
2774
|
const type = value?.type;
|
|
2015
2775
|
if (type === "hello" && error instanceof ProtocolError && error.path === "message.vehicle_sil_gui") {
|
|
2016
2776
|
const version2 = JSON.stringify(value.vehicle_sil_gui);
|
|
@@ -2026,28 +2786,82 @@ var SessionFeed = class {
|
|
|
2026
2786
|
}
|
|
2027
2787
|
if (message === null) continue;
|
|
2028
2788
|
batch.push(message);
|
|
2789
|
+
accepted.push(value);
|
|
2029
2790
|
if (message.type === "error" && message.code === "unauthorized") {
|
|
2030
2791
|
stop = "unauthorized";
|
|
2031
2792
|
break;
|
|
2032
2793
|
}
|
|
2033
2794
|
}
|
|
2795
|
+
let filtered = this.filterOlderRuns(batch, accepted);
|
|
2796
|
+
if (filtered.staleHello && stop === null) stop = "lost";
|
|
2034
2797
|
if (stop === "unauthorized" || stop === "incompatible") {
|
|
2035
2798
|
this.stoppedFlag = true;
|
|
2036
2799
|
this.connection.close();
|
|
2037
2800
|
}
|
|
2801
|
+
if (!currentOrigin()) {
|
|
2802
|
+
if (stop === "unauthorized" || stop === "incompatible") this.stoppedFlag = false;
|
|
2803
|
+
return;
|
|
2804
|
+
}
|
|
2038
2805
|
if (stop === "lost") this.connection.restart();
|
|
2039
|
-
|
|
2806
|
+
if (!currentOrigin()) return;
|
|
2807
|
+
filtered = this.filterOlderRuns(filtered.batch, filtered.raw);
|
|
2808
|
+
this.apply(filtered.batch, filtered.raw, snapshotVersion, currentOrigin, (instance) => {
|
|
2809
|
+
originInstance = instance;
|
|
2810
|
+
});
|
|
2811
|
+
if (!currentOrigin()) return;
|
|
2040
2812
|
if (stop === "lost" || stop === "incompatible") this.synced.set(false);
|
|
2041
2813
|
if (stop === "unauthorized") this.rejectedValue.set(true);
|
|
2042
2814
|
if (incompatible !== null) this.incompatibleValue.set(incompatible);
|
|
2043
2815
|
}
|
|
2044
|
-
|
|
2816
|
+
/** Keep messages at or after the run already observed over HTTP, within each server instance. */
|
|
2817
|
+
filterOlderRuns(batch, raw) {
|
|
2818
|
+
let instance = this.instanceId;
|
|
2819
|
+
let floor = this.current.get()?.id ?? null;
|
|
2820
|
+
let staleHello = false;
|
|
2821
|
+
const selected = [];
|
|
2822
|
+
const selectedRaw = [];
|
|
2823
|
+
batch.forEach((message, index) => {
|
|
2824
|
+
if (message.type === "hello") {
|
|
2825
|
+
const id = message.session?.id ?? null;
|
|
2826
|
+
if (instance === message.instance && floor !== null && (id === null || id < floor)) {
|
|
2827
|
+
staleHello = true;
|
|
2828
|
+
return;
|
|
2829
|
+
}
|
|
2830
|
+
if (instance !== message.instance) {
|
|
2831
|
+
instance = message.instance;
|
|
2832
|
+
floor = id;
|
|
2833
|
+
} else if (id !== null) floor = id;
|
|
2834
|
+
} else {
|
|
2835
|
+
const id = message.type === "session" ? message.session.id : "session" in message && typeof message.session === "number" ? message.session : null;
|
|
2836
|
+
if (id !== null && floor !== null && id < floor) return;
|
|
2837
|
+
if (message.type === "session" && (floor === null || message.session.id > floor))
|
|
2838
|
+
floor = message.session.id;
|
|
2839
|
+
}
|
|
2840
|
+
selected.push(message);
|
|
2841
|
+
selectedRaw.push(raw[index]);
|
|
2842
|
+
});
|
|
2843
|
+
return { batch: selected, raw: selectedRaw, staleHello };
|
|
2844
|
+
}
|
|
2845
|
+
apply(batch, raw, snapshotVersion, currentOrigin, commitOrigin) {
|
|
2045
2846
|
if (batch.length === 0) return;
|
|
2847
|
+
const revision = ++this.adoptionRevision;
|
|
2046
2848
|
const before = this.current.get();
|
|
2849
|
+
const originalInstance = this.instanceId;
|
|
2850
|
+
let instance = originalInstance;
|
|
2047
2851
|
let session = before;
|
|
2852
|
+
let replayLogs = this.replayLogs?.instance === instance && this.replayLogs?.session === session?.id ? this.replayLogs : null;
|
|
2853
|
+
const unseenLogs = () => replayLogs?.logs.filter((line) => replayLogs?.unseen.has(line.seq)) ?? [];
|
|
2048
2854
|
let events = [];
|
|
2855
|
+
const notices = [];
|
|
2049
2856
|
let applied = false;
|
|
2050
2857
|
let synced = this.synced.get();
|
|
2858
|
+
let allowedNow = this.allowedValue.get();
|
|
2859
|
+
const takeAllowed = (incoming, replace = false) => {
|
|
2860
|
+
if (!incoming) return;
|
|
2861
|
+
if (replace || !allowedNow || incoming.rev === 0 || incoming.rev >= allowedNow.rev) {
|
|
2862
|
+
allowedNow = incoming;
|
|
2863
|
+
}
|
|
2864
|
+
};
|
|
2051
2865
|
let replaying = !synced;
|
|
2052
2866
|
const flush = () => {
|
|
2053
2867
|
if (session && events.length > 0) {
|
|
@@ -2063,34 +2877,81 @@ var SessionFeed = class {
|
|
|
2063
2877
|
synced = false;
|
|
2064
2878
|
replaying = true;
|
|
2065
2879
|
const { session: summary, replay } = message;
|
|
2066
|
-
const
|
|
2067
|
-
|
|
2880
|
+
const staleSnapshot = !!summary && instance === message.instance && session?.id === summary.id && session.snapshotRev != null && (summary.snapshot_rev == null || summary.snapshot_rev < session.snapshotRev);
|
|
2881
|
+
takeAllowed(message.allowed ?? summary?.allowed ?? null, !staleSnapshot);
|
|
2882
|
+
const sameRun2 = summary && instance === message.instance && session?.id === summary.id;
|
|
2883
|
+
const resumed = sameRun2 && replay?.from_seq != null;
|
|
2884
|
+
instance = message.instance;
|
|
2885
|
+
if (!sameRun2) replayLogs = null;
|
|
2886
|
+
if (!summary) {
|
|
2887
|
+
session = null;
|
|
2888
|
+
} else if (sameRun2 && session) {
|
|
2889
|
+
const kept = applySummary(session, summary, true, true);
|
|
2890
|
+
if (!resumed && instance) {
|
|
2891
|
+
const logs = replayLogs ? recoverReplayLogs(kept, unseenLogs(), replayLogs.notKept).logs : kept.logs;
|
|
2892
|
+
replayLogs = {
|
|
2893
|
+
instance,
|
|
2894
|
+
session: summary.id,
|
|
2895
|
+
logs: logs.filter((line) => !line.gap || line.gap.launcher),
|
|
2896
|
+
unseen: new Set(logs.map((line) => line.seq)),
|
|
2897
|
+
notKept: /* @__PURE__ */ new Map()
|
|
2898
|
+
};
|
|
2899
|
+
}
|
|
2900
|
+
session = resumed ? kept : { ...kept, lastSeq: -1, logs: [], logSources: {}, droppedMarks: 0 };
|
|
2901
|
+
} else {
|
|
2902
|
+
session = sessionFromSummary(summary);
|
|
2903
|
+
}
|
|
2068
2904
|
break;
|
|
2069
2905
|
}
|
|
2070
2906
|
case "dropped": {
|
|
2071
|
-
if (session && message.session === session.id)
|
|
2907
|
+
if (session && message.session === session.id) {
|
|
2908
|
+
session = addDropped(session, message);
|
|
2909
|
+
if (message.reason === "not-kept" && replayLogs) {
|
|
2910
|
+
for (const [source, count2] of Object.entries(message.log))
|
|
2911
|
+
replayLogs.notKept.set(source, (replayLogs.notKept.get(source) ?? 0) + count2);
|
|
2912
|
+
}
|
|
2913
|
+
}
|
|
2072
2914
|
break;
|
|
2073
2915
|
}
|
|
2074
2916
|
case "synced":
|
|
2917
|
+
if (session && replayLogs && replayLogs.instance === instance && replayLogs.session === session.id)
|
|
2918
|
+
session = recoverReplayLogs(session, unseenLogs(), replayLogs.notKept);
|
|
2919
|
+
replayLogs = null;
|
|
2075
2920
|
synced = true;
|
|
2076
2921
|
replaying = false;
|
|
2077
2922
|
break;
|
|
2923
|
+
case "allowed":
|
|
2924
|
+
takeAllowed(message.allowed);
|
|
2925
|
+
break;
|
|
2078
2926
|
case "session":
|
|
2079
|
-
|
|
2927
|
+
if (session?.id !== message.session.id) replayLogs = null;
|
|
2928
|
+
takeAllowed(message.session.allowed);
|
|
2929
|
+
session = session?.id === message.session.id ? applySummary(
|
|
2930
|
+
session,
|
|
2931
|
+
message.session,
|
|
2932
|
+
true,
|
|
2933
|
+
message.session.last_seq !== null && (session.observedSeq ?? session.lastSeq) >= message.session.last_seq
|
|
2934
|
+
) : sessionFromSummary(message.session);
|
|
2080
2935
|
break;
|
|
2081
2936
|
case "event":
|
|
2082
|
-
if (session?.id === message.session)
|
|
2937
|
+
if (session?.id === message.session) {
|
|
2938
|
+
if (message.event.event === "log" || message.event.event === "log_dropped")
|
|
2939
|
+
replayLogs?.unseen.delete(message.event.seq);
|
|
2940
|
+
events.push(message.event);
|
|
2941
|
+
}
|
|
2083
2942
|
break;
|
|
2084
2943
|
case "error":
|
|
2085
2944
|
if (message.code === "unauthorized") {
|
|
2086
2945
|
} else if (session && message.session === session.id) {
|
|
2087
|
-
const { code, message:
|
|
2088
|
-
session = addProblem(
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2946
|
+
const { code, message: text3, skipped, problem_seq } = message;
|
|
2947
|
+
session = addProblem(session, {
|
|
2948
|
+
code,
|
|
2949
|
+
message: text3,
|
|
2950
|
+
...skipped === void 0 ? {} : { skipped },
|
|
2951
|
+
...problem_seq === void 0 ? {} : { problem_seq }
|
|
2952
|
+
});
|
|
2092
2953
|
} else {
|
|
2093
|
-
|
|
2954
|
+
notices.push(message.message);
|
|
2094
2955
|
}
|
|
2095
2956
|
break;
|
|
2096
2957
|
case "resync":
|
|
@@ -2101,11 +2962,32 @@ var SessionFeed = class {
|
|
|
2101
2962
|
}
|
|
2102
2963
|
flush();
|
|
2103
2964
|
const stale = (session?.staleEvents ?? 0) - (before?.id === session?.id ? before?.staleEvents ?? 0 : 0);
|
|
2104
|
-
this.
|
|
2105
|
-
this.
|
|
2965
|
+
if (!currentOrigin() || !this.isCurrent(revision)) return;
|
|
2966
|
+
this.instanceId = instance;
|
|
2967
|
+
commitOrigin(instance);
|
|
2968
|
+
this.replayLogs = replayLogs && replayLogs.session === session?.id && replayLogs.instance === instance ? replayLogs : null;
|
|
2969
|
+
this.stopTarget = session && instance ? { session: session.id, instance } : null;
|
|
2970
|
+
const sessionId = session?.id ?? null;
|
|
2971
|
+
const sameRun = () => currentOrigin() && this.instanceId === instance && (this.current.get()?.id ?? null) === sessionId;
|
|
2972
|
+
const notifySession = this.current.setDeferred(session);
|
|
2973
|
+
const notifyAllowed = this.allowedValue.setDeferred(allowedNow);
|
|
2974
|
+
const notifySynced = this.synced.setDeferred(synced);
|
|
2975
|
+
if (instance && instance !== originalInstance) this.instanceListener(instance, sameRun);
|
|
2976
|
+
notifySession();
|
|
2977
|
+
notifyAllowed();
|
|
2978
|
+
notifySynced();
|
|
2979
|
+
if (!sameRun()) return;
|
|
2980
|
+
for (const notice of notices) {
|
|
2981
|
+
this.notify(notice);
|
|
2982
|
+
if (!sameRun()) return;
|
|
2983
|
+
}
|
|
2106
2984
|
if (applied) this.receivedAt.set(Date.now());
|
|
2985
|
+
if (!sameRun()) return;
|
|
2107
2986
|
if (stale > 0) this.notify(STALE_EVENTS_NOTICE, stale);
|
|
2108
|
-
|
|
2987
|
+
if (!sameRun()) return;
|
|
2988
|
+
callEach(this.rawListeners, [raw, sameRun, snapshotVersion], this.onError, sameRun);
|
|
2989
|
+
if (!sameRun()) return;
|
|
2990
|
+
callEach(this.messageListeners, [batch], this.onError, sameRun);
|
|
2109
2991
|
}
|
|
2110
2992
|
notify(message, count2 = 1) {
|
|
2111
2993
|
this.noticeList.update((list) => {
|
|
@@ -2119,30 +3001,18 @@ var SessionFeed = class {
|
|
|
2119
3001
|
};
|
|
2120
3002
|
|
|
2121
3003
|
// ../client/src/time.ts
|
|
2122
|
-
var FEATURE_SPEED = "speed";
|
|
2123
|
-
var FEATURE_START_PAUSED = "start-paused";
|
|
2124
|
-
var FEATURE_TIME_COMMANDS = "time-commands";
|
|
2125
3004
|
var ANSWER_TIMEOUT_MS = 5e3;
|
|
2126
3005
|
var TimeControl = class {
|
|
2127
|
-
constructor(session,
|
|
3006
|
+
constructor(session, transport, answerTimeoutMs = ANSWER_TIMEOUT_MS, onError = rethrowLater) {
|
|
2128
3007
|
this.session = session;
|
|
2129
3008
|
this.transport = transport;
|
|
2130
3009
|
this.answerTimeoutMs = answerTimeoutMs;
|
|
2131
|
-
this.variables = variables;
|
|
2132
3010
|
this.inFlight = new Writable(0, Object.is, onError);
|
|
2133
3011
|
this.pending = new Writable(null, Object.is, onError);
|
|
2134
3012
|
this.failureValue = new Writable(null, Object.is, onError);
|
|
2135
3013
|
this.state = derived(
|
|
2136
|
-
[
|
|
2137
|
-
|
|
2138
|
-
ready,
|
|
2139
|
-
app,
|
|
2140
|
-
this.inFlight,
|
|
2141
|
-
this.pending,
|
|
2142
|
-
this.failureValue,
|
|
2143
|
-
...variables ? [variables] : []
|
|
2144
|
-
],
|
|
2145
|
-
() => this.compute(session.get(), ready.get(), app.get()),
|
|
3014
|
+
[session, this.inFlight, this.pending, this.failureValue],
|
|
3015
|
+
() => this.compute(session.get()),
|
|
2146
3016
|
shallowEqual,
|
|
2147
3017
|
onError
|
|
2148
3018
|
);
|
|
@@ -2150,13 +3020,12 @@ var TimeControl = class {
|
|
|
2150
3020
|
session;
|
|
2151
3021
|
transport;
|
|
2152
3022
|
answerTimeoutMs;
|
|
2153
|
-
variables;
|
|
2154
3023
|
inFlight;
|
|
2155
3024
|
pending;
|
|
2156
3025
|
failureValue;
|
|
2157
3026
|
answerTimer;
|
|
2158
3027
|
lastLateness = null;
|
|
2159
|
-
/** Time state
|
|
3028
|
+
/** Time state. */
|
|
2160
3029
|
state;
|
|
2161
3030
|
pause() {
|
|
2162
3031
|
return this.send({ command: "pause" });
|
|
@@ -2175,10 +3044,10 @@ var TimeControl = class {
|
|
|
2175
3044
|
return this.send({ command: "speed", value });
|
|
2176
3045
|
}
|
|
2177
3046
|
/**
|
|
2178
|
-
* Sends a command. The result arrives as the launcher's command and time events (the content of the HTTP answer is
|
|
3047
|
+
* Sends a command. The result arrives as the launcher's command, state and time events (the content of the HTTP answer is
|
|
2179
3048
|
* not used). With no run, or while waiting for the answer to the previous command (sending), nothing is sent and
|
|
2180
3049
|
* `{sent: false, reason}` is returned. If no answer comes within answerTimeoutMs, stops waiting and reports it in
|
|
2181
|
-
* failure.
|
|
3050
|
+
* failure. Whether the launcher would accept the command is `allowed` of its state.
|
|
2182
3051
|
*/
|
|
2183
3052
|
send(command) {
|
|
2184
3053
|
const session = this.session.get();
|
|
@@ -2224,8 +3093,7 @@ var TimeControl = class {
|
|
|
2224
3093
|
session: pending.session
|
|
2225
3094
|
});
|
|
2226
3095
|
}
|
|
2227
|
-
compute(session
|
|
2228
|
-
const supported = app?.launcher.features.includes(FEATURE_TIME_COMMANDS) ?? false;
|
|
3096
|
+
compute(session) {
|
|
2229
3097
|
const time = session?.time ?? null;
|
|
2230
3098
|
let lateness = !time || time.lateSteps === null || time.maxLateMs === null ? null : {
|
|
2231
3099
|
lateSteps: time.lateSteps,
|
|
@@ -2238,34 +3106,20 @@ var TimeControl = class {
|
|
|
2238
3106
|
}
|
|
2239
3107
|
this.lastLateness = lateness;
|
|
2240
3108
|
const lastCommand = session?.lastCommand ?? null;
|
|
2241
|
-
const variables = this.variables?.get();
|
|
2242
|
-
const beforeStart = !!session && session.startPaused && session.phase === "waiting" && session.time === null && session.launcher.running && session.result === null && variables?.session === session.id && variables.status !== "off" && variables.status !== "unknown";
|
|
2243
|
-
const controllable = supported && ready && !!session && (session.phase === "running" && session.time !== null || beforeStart) && session.launcher.running && session.result === null && session.stopRequests === 0;
|
|
2244
3109
|
const pending = this.pending.get();
|
|
2245
3110
|
let sending = null;
|
|
2246
3111
|
if (pending) {
|
|
2247
3112
|
const answered = !session || session.id !== pending.session || !session.launcher.running || (session.lastCommand?.seq ?? -1) > pending.afterSeq;
|
|
2248
3113
|
sending = this.inFlight.get() > 0 || !answered ? pending.command : null;
|
|
2249
3114
|
}
|
|
2250
|
-
const paused = time?.paused ?? (beforeStart ? true : null);
|
|
2251
|
-
const stepping = lastCommand?.name === "step" && lastCommand.accepted && paused === false;
|
|
2252
|
-
const free = controllable && sending === null;
|
|
2253
|
-
const canResume = free && (paused === true || stepping);
|
|
2254
3115
|
const failure = this.failureValue.get();
|
|
2255
3116
|
return {
|
|
2256
|
-
supported,
|
|
2257
3117
|
time,
|
|
2258
|
-
paced: typeof
|
|
3118
|
+
paced: typeof session?.launcherState?.speed === "number",
|
|
2259
3119
|
lateness,
|
|
2260
3120
|
behind: (lateness?.lateSteps ?? 0) > 0,
|
|
2261
3121
|
lastCommand,
|
|
2262
|
-
controllable,
|
|
2263
|
-
beforeStart,
|
|
2264
3122
|
sending,
|
|
2265
|
-
stepping,
|
|
2266
|
-
canPause: free && paused === false,
|
|
2267
|
-
canResume,
|
|
2268
|
-
canStep: canResume,
|
|
2269
3123
|
failure: failure && failure.session === (session?.id ?? null) ? failure : null
|
|
2270
3124
|
};
|
|
2271
3125
|
}
|
|
@@ -2309,6 +3163,7 @@ function writeBlock(input) {
|
|
|
2309
3163
|
if (status !== "ready") return "not-ready";
|
|
2310
3164
|
if (info === void 0) return "missing";
|
|
2311
3165
|
if (!input.peerConnected) return "peer-disconnected";
|
|
3166
|
+
if (input.launcherRefuses) return "launcher";
|
|
2312
3167
|
if (info.role === "parameter" && !input.beforeStart) return "parameter";
|
|
2313
3168
|
return null;
|
|
2314
3169
|
}
|
|
@@ -2347,6 +3202,7 @@ var NO_VARIABLES = {
|
|
|
2347
3202
|
status: "unknown",
|
|
2348
3203
|
reason: null,
|
|
2349
3204
|
peers: [],
|
|
3205
|
+
availability: /* @__PURE__ */ new Map(),
|
|
2350
3206
|
peersOmitted: 0,
|
|
2351
3207
|
variablesOmitted: 0
|
|
2352
3208
|
};
|
|
@@ -2363,12 +3219,15 @@ var isObject = (value) => typeof value === "object" && value !== null && !Array.
|
|
|
2363
3219
|
var text = (value, fallback = "") => typeof value === "string" ? value : fallback;
|
|
2364
3220
|
var numberOrNull = (value) => typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
2365
3221
|
var count = (value) => typeof value === "number" && value >= 0 ? value : 0;
|
|
3222
|
+
var positionOrNull = (value) => Number.isSafeInteger(value) && value >= 0 ? value : null;
|
|
2366
3223
|
function readVariables2(value, session) {
|
|
2367
3224
|
if (!isObject(value)) return { ...NO_VARIABLES, session };
|
|
2368
3225
|
const peers = [];
|
|
3226
|
+
const availability = /* @__PURE__ */ new Map();
|
|
2369
3227
|
for (const p of Array.isArray(value["peers"]) ? value["peers"] : []) {
|
|
2370
3228
|
if (!isObject(p) || typeof p["name"] !== "string") continue;
|
|
2371
3229
|
const variables = [];
|
|
3230
|
+
const states = /* @__PURE__ */ new Map();
|
|
2372
3231
|
for (const v of Array.isArray(p["variables"]) ? p["variables"] : []) {
|
|
2373
3232
|
if (!isObject(v) || typeof v["name"] !== "string") continue;
|
|
2374
3233
|
const items2 = Array.isArray(v["enum"]) ? v["enum"].flatMap(
|
|
@@ -2386,7 +3245,9 @@ function readVariables2(value, session) {
|
|
|
2386
3245
|
description: text(v["description"]),
|
|
2387
3246
|
enum: items2
|
|
2388
3247
|
});
|
|
3248
|
+
states.set(v["name"], readAvailability(v["availability"]));
|
|
2389
3249
|
}
|
|
3250
|
+
availability.set(p["name"], states);
|
|
2390
3251
|
peers.push({ name: p["name"], connected: p["connected"] === true, variables });
|
|
2391
3252
|
}
|
|
2392
3253
|
return {
|
|
@@ -2394,6 +3255,7 @@ function readVariables2(value, session) {
|
|
|
2394
3255
|
status: text(value["state"], "unknown"),
|
|
2395
3256
|
reason: typeof value["reason"] === "string" ? value["reason"] : null,
|
|
2396
3257
|
peers,
|
|
3258
|
+
availability,
|
|
2397
3259
|
peersOmitted: count(value["peers_omitted"]),
|
|
2398
3260
|
variablesOmitted: count(value["variables_omitted"])
|
|
2399
3261
|
};
|
|
@@ -2409,7 +3271,9 @@ function readOperation(value, session) {
|
|
|
2409
3271
|
state: text(p["state"], "unknown"),
|
|
2410
3272
|
appliedAtMs: numberOrNull(p["applied_at_ms"]),
|
|
2411
3273
|
late: p["late"] === true,
|
|
2412
|
-
reason: typeof p["reason"] === "string" ? p["reason"] : null
|
|
3274
|
+
reason: typeof p["reason"] === "string" ? p["reason"] : null,
|
|
3275
|
+
appliedWrites: positionOrNull(p["applied_writes"]),
|
|
3276
|
+
failedWrite: positionOrNull(p["failed_write"])
|
|
2413
3277
|
};
|
|
2414
3278
|
}
|
|
2415
3279
|
return {
|
|
@@ -2526,12 +3390,18 @@ var VariablesFeed = class {
|
|
|
2526
3390
|
this.state = this.stateValue.readonly();
|
|
2527
3391
|
this.operations = this.operationsValue.readonly();
|
|
2528
3392
|
this.watchProblem = this.problemValue.readonly();
|
|
2529
|
-
link.onBatch(
|
|
3393
|
+
link.onBatch(
|
|
3394
|
+
(batch, current, snapshotCurrent) => this.receive(batch, current, snapshotCurrent)
|
|
3395
|
+
);
|
|
2530
3396
|
}
|
|
2531
3397
|
link;
|
|
2532
3398
|
http;
|
|
2533
3399
|
onError;
|
|
2534
3400
|
limits;
|
|
3401
|
+
instanceId = null;
|
|
3402
|
+
snapshotVersionValue = 0;
|
|
3403
|
+
snapshotIdentity = null;
|
|
3404
|
+
serverRevision = null;
|
|
2535
3405
|
stateValue;
|
|
2536
3406
|
operationsValue;
|
|
2537
3407
|
handles = /* @__PURE__ */ new Set();
|
|
@@ -2580,26 +3450,43 @@ var VariablesFeed = class {
|
|
|
2580
3450
|
}
|
|
2581
3451
|
}
|
|
2582
3452
|
// --- Notifications --------------------------------------------------------------------------
|
|
2583
|
-
receive(batch) {
|
|
3453
|
+
receive(batch, current = () => true, initialSnapshotVersion = this.snapshotVersionValue) {
|
|
3454
|
+
let snapshotVersion = initialSnapshotVersion;
|
|
3455
|
+
const snapshotCurrent = (session, rev) => this.isSnapshotCurrent(snapshotVersion, this.instanceId, session, rev);
|
|
2584
3456
|
const touched = /* @__PURE__ */ new Set();
|
|
2585
3457
|
let touchedAll = false;
|
|
2586
3458
|
let operations = null;
|
|
2587
3459
|
let fresh = [];
|
|
2588
3460
|
const flush = () => {
|
|
2589
|
-
if (operations) this.setOperations(operations, fresh);
|
|
3461
|
+
if (operations) this.setOperations(operations, fresh, current);
|
|
2590
3462
|
operations = null;
|
|
2591
3463
|
fresh = [];
|
|
2592
3464
|
};
|
|
2593
3465
|
for (const message of batch) {
|
|
3466
|
+
if (!current()) return;
|
|
2594
3467
|
if (!isObject(message)) continue;
|
|
3468
|
+
const messageSession = message["session"];
|
|
3469
|
+
const existingSession = this.stateValue.get().session;
|
|
3470
|
+
if (typeof messageSession === "number" && existingSession !== null && messageSession < existingSession)
|
|
3471
|
+
continue;
|
|
2595
3472
|
switch (message["type"]) {
|
|
2596
3473
|
case "hello": {
|
|
2597
3474
|
flush();
|
|
3475
|
+
if (!current()) return;
|
|
2598
3476
|
const summary = message["session"];
|
|
3477
|
+
this.adoptInstance(message["instance"]);
|
|
3478
|
+
if (!current()) return;
|
|
2599
3479
|
if (isObject(summary) && Number.isSafeInteger(summary["id"])) {
|
|
2600
|
-
|
|
3480
|
+
const id = summary["id"];
|
|
3481
|
+
const details = summary["variables"];
|
|
3482
|
+
const rev = isObject(details) ? positionOrNull(details["rev"]) : null;
|
|
3483
|
+
const applied = this.adoptSummary(summary, current, () => snapshotCurrent(id, rev));
|
|
3484
|
+
if (applied !== null && this.snapshotVersionValue === applied)
|
|
3485
|
+
snapshotVersion = applied;
|
|
2601
3486
|
} else {
|
|
3487
|
+
if (this.stateValue.get().session !== null) break;
|
|
2602
3488
|
this.enter(null);
|
|
3489
|
+
if (!current()) return;
|
|
2603
3490
|
this.stateValue.set({ ...NO_VARIABLES, status: "off" });
|
|
2604
3491
|
}
|
|
2605
3492
|
touchedAll = true;
|
|
@@ -2608,10 +3495,16 @@ var VariablesFeed = class {
|
|
|
2608
3495
|
case "session": {
|
|
2609
3496
|
const summary = message["session"];
|
|
2610
3497
|
const id = isObject(summary) ? summary["id"] : null;
|
|
3498
|
+
const existing = this.stateValue.get().session;
|
|
3499
|
+
if (typeof id === "number" && existing !== null && id < existing) break;
|
|
2611
3500
|
if (Number.isSafeInteger(id) && id !== this.stateValue.get().session) {
|
|
2612
3501
|
flush();
|
|
3502
|
+
if (!current()) return;
|
|
3503
|
+
const afterFlush = this.stateValue.get().session;
|
|
3504
|
+
if (afterFlush !== null && id < afterFlush) break;
|
|
2613
3505
|
this.enter(id);
|
|
2614
|
-
|
|
3506
|
+
if (!current()) return;
|
|
3507
|
+
if (this.stateValue.get().session !== id) break;
|
|
2615
3508
|
touchedAll = true;
|
|
2616
3509
|
}
|
|
2617
3510
|
break;
|
|
@@ -2619,12 +3512,30 @@ var VariablesFeed = class {
|
|
|
2619
3512
|
case "variables": {
|
|
2620
3513
|
const id = message["session"];
|
|
2621
3514
|
if (!Number.isSafeInteger(id)) break;
|
|
2622
|
-
|
|
3515
|
+
const details = message["variables"];
|
|
3516
|
+
const rev = isObject(details) ? positionOrNull(details["rev"]) : null;
|
|
3517
|
+
const existing = this.stateValue.get().session;
|
|
3518
|
+
if (existing !== null && id < existing) break;
|
|
3519
|
+
if (id !== existing) {
|
|
2623
3520
|
flush();
|
|
2624
|
-
|
|
2625
|
-
|
|
3521
|
+
if (!current()) return;
|
|
3522
|
+
const afterFlush = this.stateValue.get().session;
|
|
3523
|
+
if (afterFlush !== null && id < afterFlush) break;
|
|
3524
|
+
if (afterFlush !== id) {
|
|
3525
|
+
this.enter(id);
|
|
3526
|
+
if (!current()) return;
|
|
3527
|
+
if (this.stateValue.get().session !== id) break;
|
|
3528
|
+
touchedAll = true;
|
|
3529
|
+
}
|
|
3530
|
+
}
|
|
3531
|
+
if (snapshotCurrent(id, rev)) {
|
|
3532
|
+
const version2 = this.applySnapshot(
|
|
3533
|
+
readVariables2(details, id),
|
|
3534
|
+
id,
|
|
3535
|
+
rev
|
|
3536
|
+
);
|
|
3537
|
+
if (this.snapshotVersionValue === version2) snapshotVersion = version2;
|
|
2626
3538
|
}
|
|
2627
|
-
this.stateValue.set(readVariables2(message["variables"], id));
|
|
2628
3539
|
break;
|
|
2629
3540
|
}
|
|
2630
3541
|
case "values": {
|
|
@@ -2642,6 +3553,16 @@ var VariablesFeed = class {
|
|
|
2642
3553
|
}
|
|
2643
3554
|
break;
|
|
2644
3555
|
}
|
|
3556
|
+
case "availability": {
|
|
3557
|
+
const id = this.stateValue.get().session;
|
|
3558
|
+
if (message["session"] !== id || id === null) break;
|
|
3559
|
+
const rev = positionOrNull(message["rev"]);
|
|
3560
|
+
if (!snapshotCurrent(id, rev)) break;
|
|
3561
|
+
const version2 = this.markSnapshot(id, rev);
|
|
3562
|
+
if (this.takeAvailability(message["peers"])) touchedAll = true;
|
|
3563
|
+
if (this.snapshotVersionValue === version2) snapshotVersion = version2;
|
|
3564
|
+
break;
|
|
3565
|
+
}
|
|
2645
3566
|
case "error": {
|
|
2646
3567
|
const code = message["code"];
|
|
2647
3568
|
if (code === "invalid-watch" || code === "too-many-watches") {
|
|
@@ -2652,31 +3573,104 @@ var VariablesFeed = class {
|
|
|
2652
3573
|
}
|
|
2653
3574
|
}
|
|
2654
3575
|
flush();
|
|
2655
|
-
if (touchedAll || touched.size > 0)
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
3576
|
+
if (current() && (touchedAll || touched.size > 0))
|
|
3577
|
+
this.publish(touchedAll ? null : touched, current);
|
|
3578
|
+
}
|
|
3579
|
+
/** Returns whether any state changed. Only the availability table changes: `peers` keeps its identity. */
|
|
3580
|
+
takeAvailability(peers) {
|
|
3581
|
+
if (!isObject(peers)) return false;
|
|
3582
|
+
const state = this.stateValue.get();
|
|
3583
|
+
let next = null;
|
|
3584
|
+
for (const peer of state.peers) {
|
|
3585
|
+
const told = peers[peer.name];
|
|
3586
|
+
if (!isObject(told)) continue;
|
|
3587
|
+
const before = state.availability.get(peer.name);
|
|
3588
|
+
const states = new Map(peer.variables.map((v) => [v.name, readAvailability(told[v.name])]));
|
|
3589
|
+
if (before?.size === states.size && [...states].every(([name, value]) => before.get(name) === value))
|
|
3590
|
+
continue;
|
|
3591
|
+
next ??= new Map(state.availability);
|
|
3592
|
+
next.set(peer.name, states);
|
|
3593
|
+
}
|
|
3594
|
+
if (!next) return false;
|
|
3595
|
+
this.stateValue.set({ ...state, availability: next });
|
|
3596
|
+
return true;
|
|
3597
|
+
}
|
|
3598
|
+
snapshotVersion() {
|
|
3599
|
+
return this.snapshotVersionValue;
|
|
3600
|
+
}
|
|
3601
|
+
/** Compare server capture order when available; legacy peers use the local best-effort watermark. */
|
|
3602
|
+
isSnapshotCurrent(version2, instance, session, rev) {
|
|
3603
|
+
if (session === null) return true;
|
|
3604
|
+
const source = this.serverRevision;
|
|
3605
|
+
if (source && source.instance === instance && source.session === session) {
|
|
3606
|
+
return rev !== null && rev >= source.rev;
|
|
3607
|
+
}
|
|
3608
|
+
if (rev !== null) return true;
|
|
3609
|
+
const identity = this.snapshotIdentity;
|
|
3610
|
+
return !identity || identity.instance !== instance || identity.session !== session || this.snapshotVersionValue <= version2;
|
|
3611
|
+
}
|
|
3612
|
+
markSnapshot(session, rev) {
|
|
3613
|
+
const version2 = ++this.snapshotVersionValue;
|
|
3614
|
+
this.snapshotIdentity = { instance: this.instanceId, session };
|
|
3615
|
+
if (rev !== null) this.serverRevision = { instance: this.instanceId, session, rev };
|
|
3616
|
+
return version2;
|
|
3617
|
+
}
|
|
3618
|
+
applySnapshot(state, session, rev) {
|
|
3619
|
+
const version2 = this.markSnapshot(session, rev);
|
|
3620
|
+
this.stateValue.set(state);
|
|
3621
|
+
return version2;
|
|
3622
|
+
}
|
|
3623
|
+
/** A reused numeric session on another server is a different run. */
|
|
3624
|
+
adoptInstance(value) {
|
|
3625
|
+
if (typeof value !== "string" || !value) return;
|
|
3626
|
+
const changed = this.instanceId !== null && this.instanceId !== value;
|
|
3627
|
+
this.instanceId = value;
|
|
3628
|
+
if (changed) this.enter(null, true);
|
|
3629
|
+
}
|
|
3630
|
+
/** Applies a summary: an older snapshot can still carry a terminal write result. */
|
|
3631
|
+
adoptSummary(summary, current = () => true, snapshotCurrent = current) {
|
|
3632
|
+
if (!isObject(summary) || !Number.isSafeInteger(summary["id"]) || !current()) return null;
|
|
2660
3633
|
const id = summary["id"];
|
|
3634
|
+
const instance = this.instanceId;
|
|
3635
|
+
const existing = this.stateValue.get().session;
|
|
3636
|
+
if (existing !== null && id < existing) return null;
|
|
2661
3637
|
const variables = summary["variables"];
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
this.
|
|
2665
|
-
|
|
2666
|
-
|
|
3638
|
+
let applyState = snapshotCurrent();
|
|
3639
|
+
if (id !== existing) {
|
|
3640
|
+
const initial = this.enter(id);
|
|
3641
|
+
if (!current()) return null;
|
|
3642
|
+
if (this.stateValue.get() !== initial) applyState = applyState && snapshotCurrent();
|
|
2667
3643
|
}
|
|
2668
|
-
this.stateValue.
|
|
3644
|
+
const sameIdentity = () => current() && this.instanceId === instance && this.stateValue.get().session === id;
|
|
3645
|
+
if (!sameIdentity() || variables === void 0) return null;
|
|
3646
|
+
applyState = applyState && snapshotCurrent();
|
|
3647
|
+
let notifyOperations = () => void 0;
|
|
3648
|
+
const listed = [];
|
|
2669
3649
|
if (isObject(variables) && Array.isArray(variables["operations"])) {
|
|
2670
3650
|
let operations = this.operationsValue.get();
|
|
2671
|
-
const listed = [];
|
|
2672
3651
|
for (const entry of variables["operations"]) {
|
|
2673
3652
|
const operation = readOperation(entry, id);
|
|
2674
|
-
if (operation) {
|
|
3653
|
+
if (operation && (applyState || operation.done)) {
|
|
2675
3654
|
listed.push(operation);
|
|
2676
3655
|
operations = this.withOperation(operations, operation);
|
|
2677
3656
|
}
|
|
2678
3657
|
}
|
|
2679
|
-
this.
|
|
3658
|
+
notifyOperations = this.prepareOperations(operations, listed, sameIdentity);
|
|
3659
|
+
}
|
|
3660
|
+
let next = null;
|
|
3661
|
+
let appliedVersion = null;
|
|
3662
|
+
if (applyState && snapshotCurrent() && sameIdentity()) {
|
|
3663
|
+
next = readVariables2(variables, id);
|
|
3664
|
+
appliedVersion = this.applySnapshot(
|
|
3665
|
+
next,
|
|
3666
|
+
id,
|
|
3667
|
+
isObject(variables) ? positionOrNull(variables["rev"]) : null
|
|
3668
|
+
);
|
|
3669
|
+
}
|
|
3670
|
+
notifyOperations();
|
|
3671
|
+
if (!sameIdentity() || appliedVersion === null || this.snapshotVersionValue !== appliedVersion || !next || this.stateValue.get() !== next)
|
|
3672
|
+
return appliedVersion;
|
|
3673
|
+
if (isObject(variables) && Array.isArray(variables["operations"])) {
|
|
2680
3674
|
const fromSeq = variables["operations_from_seq"];
|
|
2681
3675
|
const openOmitted = variables["operations_open_omitted"];
|
|
2682
3676
|
this.forgetLost(id, {
|
|
@@ -2685,6 +3679,7 @@ var VariablesFeed = class {
|
|
|
2685
3679
|
openOmitted: typeof openOmitted === "number" && openOmitted > 0
|
|
2686
3680
|
});
|
|
2687
3681
|
}
|
|
3682
|
+
return appliedVersion;
|
|
2688
3683
|
}
|
|
2689
3684
|
/**
|
|
2690
3685
|
* With the summary after a reconnect (or from api/session), settles as "no answer came" (lost) the writes waiting for
|
|
@@ -2707,12 +3702,15 @@ var VariablesFeed = class {
|
|
|
2707
3702
|
* are dropped with their memory, so they do not keep growing as the variables change from run to run). Writes
|
|
2708
3703
|
* waiting for the previous run's result are failed, since the result will not come.
|
|
2709
3704
|
*/
|
|
2710
|
-
enter(session) {
|
|
2711
|
-
if (session === this.stateValue.get().session) return;
|
|
3705
|
+
enter(session, force = false) {
|
|
3706
|
+
if (!force && session === this.stateValue.get().session) return this.stateValue.get();
|
|
2712
3707
|
this.readings.clear();
|
|
2713
3708
|
this.histories.clear();
|
|
2714
3709
|
this.historyReserved = 0;
|
|
2715
|
-
|
|
3710
|
+
const initial = { ...NO_VARIABLES, session };
|
|
3711
|
+
const notifyOperations = this.operationsValue.setDeferred([]);
|
|
3712
|
+
const notifyState = this.stateValue.setDeferred(initial);
|
|
3713
|
+
const notifyWatches = [...this.handles].map((handle) => handle.values.setDeferred({}));
|
|
2716
3714
|
for (const pending of [...this.pending]) {
|
|
2717
3715
|
if (pending.session !== session) {
|
|
2718
3716
|
this.settle(
|
|
@@ -2724,6 +3722,10 @@ var VariablesFeed = class {
|
|
|
2724
3722
|
);
|
|
2725
3723
|
}
|
|
2726
3724
|
}
|
|
3725
|
+
notifyOperations();
|
|
3726
|
+
notifyState();
|
|
3727
|
+
for (const notify of notifyWatches) notify();
|
|
3728
|
+
return initial;
|
|
2727
3729
|
}
|
|
2728
3730
|
takeValues(message, touched) {
|
|
2729
3731
|
const peers = message["peers"];
|
|
@@ -2765,8 +3767,9 @@ var VariablesFeed = class {
|
|
|
2765
3767
|
}
|
|
2766
3768
|
}
|
|
2767
3769
|
/** Rebuilds values of the watches that observe the changed variables (all watches if touched is null). */
|
|
2768
|
-
publish(touched) {
|
|
3770
|
+
publish(touched, current = () => true) {
|
|
2769
3771
|
for (const handle of this.handles) {
|
|
3772
|
+
if (!current()) return;
|
|
2770
3773
|
if (touched !== null && handle.keys !== null) {
|
|
2771
3774
|
let hit = false;
|
|
2772
3775
|
for (const key of handle.keys) {
|
|
@@ -2799,7 +3802,7 @@ var VariablesFeed = class {
|
|
|
2799
3802
|
// --- Operations -----------------------------------------------------------------------------
|
|
2800
3803
|
withOperation(operations, operation) {
|
|
2801
3804
|
const at = operations.findIndex((o) => o.seq === operation.seq);
|
|
2802
|
-
if (at >= 0 && operations[at]?.done
|
|
3805
|
+
if (at >= 0 && operations[at]?.done) return [...operations];
|
|
2803
3806
|
const next = at >= 0 ? operations.map((o, i) => i === at ? operation : o) : [...operations, operation];
|
|
2804
3807
|
return next.length > OPERATIONS_KEPT ? next.slice(next.length - OPERATIONS_KEPT) : next;
|
|
2805
3808
|
}
|
|
@@ -2808,14 +3811,19 @@ var VariablesFeed = class {
|
|
|
2808
3811
|
* just arrived (a batch of notifications, the list in a summary): the list is cut to OPERATIONS_KEPT entries, so
|
|
2809
3812
|
* settled operations cut from the list are picked up from here.
|
|
2810
3813
|
*/
|
|
2811
|
-
setOperations(operations, fresh = []) {
|
|
2812
|
-
this.
|
|
3814
|
+
setOperations(operations, fresh = [], current = () => true) {
|
|
3815
|
+
this.prepareOperations(operations, fresh, current)();
|
|
3816
|
+
}
|
|
3817
|
+
prepareOperations(operations, fresh, current) {
|
|
3818
|
+
if (!current()) return () => void 0;
|
|
3819
|
+
const notify = this.operationsValue.setDeferred(operations);
|
|
2813
3820
|
for (const pending of [...this.pending]) {
|
|
2814
3821
|
if (pending.seq === null) continue;
|
|
2815
3822
|
const mine = (o) => o.done && o.seq === pending.seq && o.session === pending.session;
|
|
2816
3823
|
const operation = fresh.find(mine) ?? operations.find(mine);
|
|
2817
3824
|
if (operation) this.settle(pending, operation);
|
|
2818
3825
|
}
|
|
3826
|
+
return notify;
|
|
2819
3827
|
}
|
|
2820
3828
|
settle(pending, outcome) {
|
|
2821
3829
|
if (!this.pending.delete(pending)) return;
|
|
@@ -2842,11 +3850,7 @@ var VariablesFeed = class {
|
|
|
2842
3850
|
const session = this.stateValue.get().session;
|
|
2843
3851
|
if (session === null) {
|
|
2844
3852
|
return Promise.reject(
|
|
2845
|
-
new WriteError(
|
|
2846
|
-
"refused",
|
|
2847
|
-
"there is no run to write to (wait for the variables of a run: client.variables.state)",
|
|
2848
|
-
"not-running"
|
|
2849
|
-
)
|
|
3853
|
+
new WriteError("refused", "there is no run to write to", "not-running")
|
|
2850
3854
|
);
|
|
2851
3855
|
}
|
|
2852
3856
|
const body = { session, writes };
|
|
@@ -2943,10 +3947,10 @@ var VariablesFeed = class {
|
|
|
2943
3947
|
this.forget();
|
|
2944
3948
|
handle.values.set(this.valuesOf(handle));
|
|
2945
3949
|
this.queueSync();
|
|
2946
|
-
let
|
|
3950
|
+
let open2 = true;
|
|
2947
3951
|
const mine = (ref) => {
|
|
2948
3952
|
const key = keyOf(ref.peer, ref.name);
|
|
2949
|
-
return
|
|
3953
|
+
return open2 && (handle.keys === null || handle.keys.has(key)) ? key : null;
|
|
2950
3954
|
};
|
|
2951
3955
|
return {
|
|
2952
3956
|
values: handle.values.readonly(),
|
|
@@ -2959,8 +3963,8 @@ var VariablesFeed = class {
|
|
|
2959
3963
|
return key === null ? [] : this.histories.get(key)?.last(handle.history) ?? [];
|
|
2960
3964
|
},
|
|
2961
3965
|
close: () => {
|
|
2962
|
-
if (!
|
|
2963
|
-
|
|
3966
|
+
if (!open2) return;
|
|
3967
|
+
open2 = false;
|
|
2964
3968
|
this.handles.delete(handle);
|
|
2965
3969
|
this.forget();
|
|
2966
3970
|
this.queueSync();
|
|
@@ -3090,7 +4094,7 @@ var VariablesFeed = class {
|
|
|
3090
4094
|
};
|
|
3091
4095
|
|
|
3092
4096
|
// ../client/src/variable-binding.ts
|
|
3093
|
-
var DROPPED_MESSAGE = "the value kept back was not sent: the variable cannot be written any more (the run ended or another one started,
|
|
4097
|
+
var DROPPED_MESSAGE = "the value kept back was not sent: the variable cannot be written any more (the run ended or another one started, the ECU is not connected, or the launcher does not take writes now). Check the value and write it again";
|
|
3094
4098
|
var keyOf2 = (ref) => `${ref.peer}\0${ref.name}`;
|
|
3095
4099
|
var IDLE = { kind: "idle" };
|
|
3096
4100
|
var VariableBinder = class {
|
|
@@ -3136,18 +4140,26 @@ var VariableBinder = class {
|
|
|
3136
4140
|
return this.sources.connection.get() === "open";
|
|
3137
4141
|
}
|
|
3138
4142
|
/**
|
|
3139
|
-
* Why the variable cannot be written now (null if it can). Only the widget-independent reasons (Binding adds
|
|
3140
|
-
*
|
|
4143
|
+
* Why the variable cannot be written now (null if it can). Only the widget-independent reasons (Binding adds range
|
|
4144
|
+
* and value).
|
|
3141
4145
|
*/
|
|
3142
4146
|
block(ref) {
|
|
3143
4147
|
return writeBlock({
|
|
3144
4148
|
info: this.find(ref),
|
|
3145
4149
|
status: this.sources.variables.state.get().status,
|
|
3146
4150
|
connected: this.connected(),
|
|
3147
|
-
beforeStart: this.sources.
|
|
3148
|
-
peerConnected: this.peerConnected(ref.peer)
|
|
4151
|
+
beforeStart: isHolding(this.sources.session.get()),
|
|
4152
|
+
peerConnected: this.peerConnected(ref.peer),
|
|
4153
|
+
launcherRefuses: this.launcherReason() !== null
|
|
3149
4154
|
});
|
|
3150
4155
|
}
|
|
4156
|
+
/**
|
|
4157
|
+
* Why the launcher does not take a write now (launcherAnswer of its last `state`; `unsupported` until a `state` says).
|
|
4158
|
+
* The client keeps no rule of its own about it.
|
|
4159
|
+
*/
|
|
4160
|
+
launcherReason() {
|
|
4161
|
+
return launcherAnswer(this.sources.session.get()?.launcherState ?? null, "write").reason;
|
|
4162
|
+
}
|
|
3151
4163
|
/** Status of the last write to that variable in the current run. */
|
|
3152
4164
|
status(ref) {
|
|
3153
4165
|
return this.entry(ref)?.status ?? IDLE;
|
|
@@ -3234,6 +4246,7 @@ var VariableBinder = class {
|
|
|
3234
4246
|
return entry;
|
|
3235
4247
|
}
|
|
3236
4248
|
send(entry, value) {
|
|
4249
|
+
const epoch = this.sources.connectionEpoch();
|
|
3237
4250
|
const mine = { value };
|
|
3238
4251
|
const { peer, name } = entry.ref;
|
|
3239
4252
|
entry.sending = mine;
|
|
@@ -3241,7 +4254,6 @@ var VariableBinder = class {
|
|
|
3241
4254
|
entry.shown = mine;
|
|
3242
4255
|
entry.status = { kind: "sending" };
|
|
3243
4256
|
entry.pending = value;
|
|
3244
|
-
this.changed(entry);
|
|
3245
4257
|
const accepted = (seq) => {
|
|
3246
4258
|
if (entry.sending !== mine) return;
|
|
3247
4259
|
entry.sending = null;
|
|
@@ -3276,6 +4288,11 @@ var VariableBinder = class {
|
|
|
3276
4288
|
if (entry.shown === mine) entry.status = status;
|
|
3277
4289
|
this.changed(entry);
|
|
3278
4290
|
};
|
|
4291
|
+
this.changed(entry);
|
|
4292
|
+
if (this.sources.connectionEpoch() !== epoch || this.sources.session.get()?.id !== entry.session || this.sources.variables.state.get().session !== entry.session || this.block(entry.ref) !== null) {
|
|
4293
|
+
settled({ kind: "dropped", message: DROPPED_MESSAGE });
|
|
4294
|
+
return;
|
|
4295
|
+
}
|
|
3279
4296
|
this.sources.variables.write(
|
|
3280
4297
|
{ [peer]: { [name]: value } },
|
|
3281
4298
|
{
|
|
@@ -3297,7 +4314,7 @@ var VariableBinder = class {
|
|
|
3297
4314
|
}
|
|
3298
4315
|
};
|
|
3299
4316
|
function sameBound(a, b) {
|
|
3300
|
-
return a.info === b.info && a.reading === b.reading && a.block === b.block && a.writeStatus === b.writeStatus && a.pending === b.pending && sameCondition(a.condition, b.condition);
|
|
4317
|
+
return a.info === b.info && a.availability === b.availability && a.reading === b.reading && a.block === b.block && a.launcherReason?.code === b.launcherReason?.code && a.launcherReason?.message === b.launcherReason?.message && a.writeStatus === b.writeStatus && a.pending === b.pending && sameCondition(a.condition, b.condition);
|
|
3301
4318
|
}
|
|
3302
4319
|
var Binding = class {
|
|
3303
4320
|
constructor(binder, ref, options) {
|
|
@@ -3311,7 +4328,6 @@ var Binding = class {
|
|
|
3311
4328
|
this.stops.push(
|
|
3312
4329
|
sources.variables.state.subscribe(refresh),
|
|
3313
4330
|
sources.connection.subscribe(refresh),
|
|
3314
|
-
sources.time.subscribe(refresh),
|
|
3315
4331
|
sources.session.subscribe(refresh),
|
|
3316
4332
|
binder.onChange(ref, refresh)
|
|
3317
4333
|
);
|
|
@@ -3353,12 +4369,15 @@ var Binding = class {
|
|
|
3353
4369
|
readFailing: variables.status === "ready" && variables.reason !== null
|
|
3354
4370
|
});
|
|
3355
4371
|
const pending = binder.pending(ref);
|
|
4372
|
+
const block = this.blockOf(info, reading, pending);
|
|
3356
4373
|
return {
|
|
3357
4374
|
ref,
|
|
3358
4375
|
info,
|
|
4376
|
+
availability: variables.availability.get(ref.peer)?.get(ref.name) ?? "unknown",
|
|
3359
4377
|
reading,
|
|
3360
4378
|
condition,
|
|
3361
|
-
block
|
|
4379
|
+
block,
|
|
4380
|
+
launcherReason: block === "launcher" ? binder.launcherReason() : null,
|
|
3362
4381
|
writeStatus: binder.status(ref),
|
|
3363
4382
|
pending
|
|
3364
4383
|
};
|
|
@@ -3366,17 +4385,15 @@ var Binding = class {
|
|
|
3366
4385
|
blockOf(info, reading, pending) {
|
|
3367
4386
|
const base = this.binder.block(this.ref);
|
|
3368
4387
|
if (base !== null) return base;
|
|
3369
|
-
const session = this.binder.sources.session.get();
|
|
3370
|
-
if (session?.scenario && session.launcher.running) return "scenario";
|
|
3371
4388
|
if (this.options.needsRange && info && !hasRange(info)) return "no-range";
|
|
3372
4389
|
if (this.options.needsValue && reading === void 0 && pending === null) return "no-value";
|
|
3373
4390
|
return null;
|
|
3374
4391
|
}
|
|
3375
4392
|
openWatch() {
|
|
3376
4393
|
const { periodMs, history } = this.options;
|
|
3377
|
-
const
|
|
3378
|
-
this.watch =
|
|
3379
|
-
this.stopWatch =
|
|
4394
|
+
const watch2 = this.binder.sources.variables.watch([this.ref], { periodMs, history });
|
|
4395
|
+
this.watch = watch2;
|
|
4396
|
+
this.stopWatch = watch2.values.subscribe(() => this.refresh());
|
|
3380
4397
|
}
|
|
3381
4398
|
closeWatch() {
|
|
3382
4399
|
this.stopWatch?.();
|
|
@@ -3434,6 +4451,13 @@ function defaultOrigin(baseUrl, runtime = globalThis) {
|
|
|
3434
4451
|
return isNode(runtime) ? new URL(baseUrl).origin : void 0;
|
|
3435
4452
|
}
|
|
3436
4453
|
function createClient(options) {
|
|
4454
|
+
return buildClient(options).client;
|
|
4455
|
+
}
|
|
4456
|
+
var clientErrorSinks = /* @__PURE__ */ new WeakMap();
|
|
4457
|
+
function clientErrorSink(client) {
|
|
4458
|
+
return clientErrorSinks.get(client);
|
|
4459
|
+
}
|
|
4460
|
+
function buildClient(options) {
|
|
3437
4461
|
const token = typeof options.token === "function" ? options.token : () => options.token;
|
|
3438
4462
|
const onError = options.onError ?? reportToConsole;
|
|
3439
4463
|
const origin = options.origin ?? defaultOrigin(options.baseUrl);
|
|
@@ -3459,22 +4483,29 @@ function createClient(options) {
|
|
|
3459
4483
|
});
|
|
3460
4484
|
feed = new SessionFeed(connection, onError);
|
|
3461
4485
|
const session = feed;
|
|
3462
|
-
variablesFeed = new VariablesFeed(
|
|
4486
|
+
variablesFeed = new VariablesFeed(
|
|
4487
|
+
{
|
|
4488
|
+
send: (message) => connection.send(message),
|
|
4489
|
+
onBatch: (listener) => session.onRawMessages(listener)
|
|
4490
|
+
},
|
|
4491
|
+
http,
|
|
4492
|
+
onError,
|
|
4493
|
+
() => limits.get()
|
|
4494
|
+
);
|
|
3463
4495
|
const variables = variablesFeed;
|
|
4496
|
+
session.onSnapshotVersion(() => variables.snapshotVersion());
|
|
4497
|
+
session.onInstance((instance) => variables.adoptInstance(instance));
|
|
3464
4498
|
const run = new RunControl(session, http, onError, () => longRequestMs(limits.get()));
|
|
3465
4499
|
const time = new TimeControl(
|
|
3466
4500
|
session.session,
|
|
3467
|
-
session.ready,
|
|
3468
|
-
app.readonly(),
|
|
3469
4501
|
http,
|
|
3470
4502
|
options.answerTimeoutMs ?? ANSWER_TIMEOUT_MS,
|
|
3471
|
-
onError
|
|
3472
|
-
variables.state
|
|
4503
|
+
onError
|
|
3473
4504
|
);
|
|
3474
4505
|
const binder = new VariableBinder({
|
|
3475
4506
|
variables,
|
|
3476
4507
|
connection: connection.state,
|
|
3477
|
-
|
|
4508
|
+
connectionEpoch: () => connection.batchEpoch(),
|
|
3478
4509
|
session: session.session,
|
|
3479
4510
|
onError
|
|
3480
4511
|
});
|
|
@@ -3493,7 +4524,7 @@ function createClient(options) {
|
|
|
3493
4524
|
}
|
|
3494
4525
|
})
|
|
3495
4526
|
);
|
|
3496
|
-
|
|
4527
|
+
const client = {
|
|
3497
4528
|
connection: {
|
|
3498
4529
|
state: connection.state,
|
|
3499
4530
|
failures: connection.failures,
|
|
@@ -3504,7 +4535,10 @@ function createClient(options) {
|
|
|
3504
4535
|
},
|
|
3505
4536
|
session: {
|
|
3506
4537
|
session: session.session,
|
|
4538
|
+
currentTarget: () => session.currentTarget(),
|
|
4539
|
+
currentInstance: () => session.currentInstance(),
|
|
3507
4540
|
ready: session.ready,
|
|
4541
|
+
allowed: session.allowed,
|
|
3508
4542
|
lastEventAt: session.lastEventAt,
|
|
3509
4543
|
notices: session.notices,
|
|
3510
4544
|
rejected: session.rejected,
|
|
@@ -3516,6 +4550,7 @@ function createClient(options) {
|
|
|
3516
4550
|
run: {
|
|
3517
4551
|
starting: run.starting,
|
|
3518
4552
|
stopping: run.stopping,
|
|
4553
|
+
currentStopping: run.currentStopping,
|
|
3519
4554
|
stopWhileStarting: run.stopWhileStarting,
|
|
3520
4555
|
error: run.error,
|
|
3521
4556
|
start: (request) => run.start(request),
|
|
@@ -3551,6 +4586,20 @@ function createClient(options) {
|
|
|
3551
4586
|
},
|
|
3552
4587
|
loadApp: () => call({ method: "GET", path: "api/app" }, readAppInfo, (info) => app.set(info)),
|
|
3553
4588
|
configs: () => call({ method: "GET", path: "api/configs" }, readConfigList),
|
|
4589
|
+
config: (file) => call({ method: "GET", path: `api/config?file=${encodeURIComponent(file)}` }, readConfigText),
|
|
4590
|
+
describe: (body) => call(
|
|
4591
|
+
{
|
|
4592
|
+
method: "POST",
|
|
4593
|
+
path: "api/describe",
|
|
4594
|
+
body,
|
|
4595
|
+
timeoutMs: longRequestMs(limits.get())
|
|
4596
|
+
},
|
|
4597
|
+
readCheckResponse
|
|
4598
|
+
),
|
|
4599
|
+
saveConfig: (body) => call(
|
|
4600
|
+
{ method: "POST", path: "api/config", body, timeoutMs: longRequestMs(limits.get()) },
|
|
4601
|
+
readSavedConfig
|
|
4602
|
+
),
|
|
3554
4603
|
dashboard: (file) => call(
|
|
3555
4604
|
{ method: "GET", path: `api/dashboard?file=${encodeURIComponent(file)}` },
|
|
3556
4605
|
readDashboardResponse
|
|
@@ -3569,23 +4618,57 @@ function createClient(options) {
|
|
|
3569
4618
|
},
|
|
3570
4619
|
readCheckResponse
|
|
3571
4620
|
),
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
}
|
|
3586
|
-
|
|
3587
|
-
|
|
4621
|
+
connections: (body) => call(
|
|
4622
|
+
{
|
|
4623
|
+
method: "POST",
|
|
4624
|
+
path: "api/connections",
|
|
4625
|
+
body,
|
|
4626
|
+
timeoutMs: longRequestMs(limits.get())
|
|
4627
|
+
},
|
|
4628
|
+
readConnections
|
|
4629
|
+
),
|
|
4630
|
+
fetchSession: () => {
|
|
4631
|
+
const resyncFrom = session.currentInstance();
|
|
4632
|
+
const snapshotVersion = variables.snapshotVersion();
|
|
4633
|
+
return new Promise(
|
|
4634
|
+
(resolve, reject) => http({ method: "GET", path: "api/session" }, (outcome) => {
|
|
4635
|
+
if (!outcome.ok) {
|
|
4636
|
+
reject(outcome.error);
|
|
4637
|
+
return;
|
|
4638
|
+
}
|
|
4639
|
+
try {
|
|
4640
|
+
const summary = readSessionResponse(outcome.body);
|
|
4641
|
+
const instance = readSessionInstance(outcome.body);
|
|
4642
|
+
const adoption = session.adopt(summary, instance, resyncFrom);
|
|
4643
|
+
if (adoption !== null) {
|
|
4644
|
+
const rawSession = outcome.body?.session;
|
|
4645
|
+
const rev = rawSession?.variables?.rev;
|
|
4646
|
+
const current = () => variables.isSnapshotCurrent(
|
|
4647
|
+
snapshotVersion,
|
|
4648
|
+
adoption.instance,
|
|
4649
|
+
adoption.session,
|
|
4650
|
+
Number.isSafeInteger(rev) && rev >= 0 ? rev : null
|
|
4651
|
+
);
|
|
4652
|
+
if (session.sameRun(adoption)) session.adoptAllowed(readSessionAllowed(outcome.body));
|
|
4653
|
+
const sameRun = () => session.sameRun(adoption);
|
|
4654
|
+
if (sameRun()) variables.adoptInstance(instance);
|
|
4655
|
+
if (sameRun())
|
|
4656
|
+
variables.adoptSummary(
|
|
4657
|
+
outcome.body?.session,
|
|
4658
|
+
sameRun,
|
|
4659
|
+
current
|
|
4660
|
+
);
|
|
4661
|
+
}
|
|
4662
|
+
resolve(summary);
|
|
4663
|
+
} catch (error) {
|
|
4664
|
+
reject(error);
|
|
4665
|
+
}
|
|
4666
|
+
})
|
|
4667
|
+
);
|
|
4668
|
+
}
|
|
3588
4669
|
};
|
|
4670
|
+
clientErrorSinks.set(client, onError);
|
|
4671
|
+
return { client, http, onError, runControl: run };
|
|
3589
4672
|
}
|
|
3590
4673
|
|
|
3591
4674
|
// ../client/src/token.ts
|
|
@@ -3630,18 +4713,1533 @@ function read(storage) {
|
|
|
3630
4713
|
return null;
|
|
3631
4714
|
}
|
|
3632
4715
|
}
|
|
4716
|
+
|
|
4717
|
+
// ../client/src/front-types.ts
|
|
4718
|
+
var ActionError = class extends Error {
|
|
4719
|
+
constructor(code, message, outcome, findings = []) {
|
|
4720
|
+
super(message);
|
|
4721
|
+
this.code = code;
|
|
4722
|
+
this.outcome = outcome;
|
|
4723
|
+
this.findings = findings;
|
|
4724
|
+
this.name = "ActionError";
|
|
4725
|
+
}
|
|
4726
|
+
code;
|
|
4727
|
+
outcome;
|
|
4728
|
+
findings;
|
|
4729
|
+
};
|
|
4730
|
+
|
|
4731
|
+
// ../client/src/front-compose.ts
|
|
4732
|
+
function linkOf(s) {
|
|
4733
|
+
if (s.rejected) return "rejected";
|
|
4734
|
+
if (s.incompatible !== null) return "incompatible";
|
|
4735
|
+
if (s.connection === "open") return s.ready ? "online" : "connecting";
|
|
4736
|
+
return s.connection === "closed" || s.failures > 0 || s.closedBefore ? "offline" : "connecting";
|
|
4737
|
+
}
|
|
4738
|
+
var NOT_PACED = "not-paced";
|
|
4739
|
+
function startOnItsWay(s) {
|
|
4740
|
+
return s.busy.has("start") || s.allowed?.start.reason === "starting";
|
|
4741
|
+
}
|
|
4742
|
+
function runOf(s) {
|
|
4743
|
+
const session = s.session;
|
|
4744
|
+
const starting = startOnItsWay(s);
|
|
4745
|
+
if (!session) return starting ? "starting" : "none";
|
|
4746
|
+
const outcome = runOutcome(session);
|
|
4747
|
+
if (outcome === "crashed") return starting ? "starting" : "crashed";
|
|
4748
|
+
if (outcome === "ended" || outcome === "finishing") return starting ? "starting" : "ended";
|
|
4749
|
+
if (outcome === "stopping" || outcome === "forcing") return "stopping";
|
|
4750
|
+
const state = session.launcherState;
|
|
4751
|
+
const phase = state?.phase || session.phase;
|
|
4752
|
+
const paused = state?.paused ?? null;
|
|
4753
|
+
switch (phase) {
|
|
4754
|
+
case null:
|
|
4755
|
+
case "checking":
|
|
4756
|
+
case "starting":
|
|
4757
|
+
return "starting";
|
|
4758
|
+
case "waiting":
|
|
4759
|
+
return state?.holding === true ? "paused" : "waiting";
|
|
4760
|
+
case "stopping":
|
|
4761
|
+
return "stopping";
|
|
4762
|
+
case "ended":
|
|
4763
|
+
return "stopping";
|
|
4764
|
+
default:
|
|
4765
|
+
return paused === true ? "paused" : "running";
|
|
4766
|
+
}
|
|
4767
|
+
}
|
|
4768
|
+
function resultOf(result) {
|
|
4769
|
+
return {
|
|
4770
|
+
end: result.end,
|
|
4771
|
+
scenario: result.scenario?.status ?? null,
|
|
4772
|
+
ok: result.ok,
|
|
4773
|
+
// A result whose sentence could not be read (or that the server shrank) still says something
|
|
4774
|
+
message: result.message || `the run ended with the result ${result.result || "unknown"}`
|
|
4775
|
+
};
|
|
4776
|
+
}
|
|
4777
|
+
function resultFor(s, run) {
|
|
4778
|
+
const session = s.session;
|
|
4779
|
+
if (!session) return null;
|
|
4780
|
+
if (run === "crashed") {
|
|
4781
|
+
const how = session.launcher.signal ? `signal ${session.launcher.signal}` : session.launcher.exitCode !== null ? `exit code ${session.launcher.exitCode}` : "no exit code";
|
|
4782
|
+
return {
|
|
4783
|
+
end: "crashed",
|
|
4784
|
+
scenario: null,
|
|
4785
|
+
ok: false,
|
|
4786
|
+
message: `the launcher ended without a result (${how}): start again`
|
|
4787
|
+
};
|
|
4788
|
+
}
|
|
4789
|
+
return run === "ended" && session.result ? resultOf(session.result) : null;
|
|
4790
|
+
}
|
|
4791
|
+
function statusOf(s, initialFile) {
|
|
4792
|
+
const run = runOf(s);
|
|
4793
|
+
return {
|
|
4794
|
+
link: linkOf(s),
|
|
4795
|
+
run,
|
|
4796
|
+
file: s.session?.file ?? initialFile,
|
|
4797
|
+
result: resultFor(s, run)
|
|
4798
|
+
};
|
|
4799
|
+
}
|
|
4800
|
+
function simMsOf(session) {
|
|
4801
|
+
if (!session) return null;
|
|
4802
|
+
const sim = session.time?.simMs ?? session.simMs;
|
|
4803
|
+
const state = session.launcherState;
|
|
4804
|
+
const stands = state?.paused === true ? state.paused_at_ms : null;
|
|
4805
|
+
if (stands === null || stands === void 0) return sim;
|
|
4806
|
+
return sim === null ? stands : Math.max(sim, stands);
|
|
4807
|
+
}
|
|
4808
|
+
function standsAt(session) {
|
|
4809
|
+
const state = session?.launcherState;
|
|
4810
|
+
return state?.paused === true ? state.paused_at_ms ?? null : null;
|
|
4811
|
+
}
|
|
4812
|
+
function onItsWay(session) {
|
|
4813
|
+
const last = session?.lastCommand;
|
|
4814
|
+
if (!session || !session.launcher.running || !last || !last.accepted || last.atMs === null)
|
|
4815
|
+
return false;
|
|
4816
|
+
if (last.name !== "step" && last.name !== "run_until") return false;
|
|
4817
|
+
const stands = standsAt(session);
|
|
4818
|
+
return !(stands !== null && stands >= last.atMs);
|
|
4819
|
+
}
|
|
4820
|
+
function clockOf(s) {
|
|
4821
|
+
const session = s.session;
|
|
4822
|
+
const state = session?.launcherState ?? null;
|
|
4823
|
+
const time = session?.time ?? null;
|
|
4824
|
+
const live = !!session && session.launcher.running;
|
|
4825
|
+
const pacing = state?.pacing;
|
|
4826
|
+
return {
|
|
4827
|
+
sim_ms: simMsOf(session ?? null),
|
|
4828
|
+
speed: state?.speed ?? null,
|
|
4829
|
+
// The last time event may be from before the pause: nothing moves while it stands still
|
|
4830
|
+
actual_speed: state?.paused === true ? null : time?.actualSpeed ?? null,
|
|
4831
|
+
pacing: !live ? NOT_PACED : pacing === "late" ? "late" : pacing === "on-time" ? "on-time" : NOT_PACED
|
|
4832
|
+
};
|
|
4833
|
+
}
|
|
4834
|
+
var reason = (code, message) => ({ code, message });
|
|
4835
|
+
function control(ok, why = null, caution = null) {
|
|
4836
|
+
return { ok, reason: ok ? null : why, caution };
|
|
4837
|
+
}
|
|
4838
|
+
function linkReason(link, s) {
|
|
4839
|
+
switch (link) {
|
|
4840
|
+
case "online":
|
|
4841
|
+
return null;
|
|
4842
|
+
case "rejected":
|
|
4843
|
+
return reason(
|
|
4844
|
+
"rejected",
|
|
4845
|
+
"the server refused the token: open the URL that the server printed again (it ends with #token=...)"
|
|
4846
|
+
);
|
|
4847
|
+
case "incompatible":
|
|
4848
|
+
return reason(
|
|
4849
|
+
"incompatible",
|
|
4850
|
+
s.incompatible ?? "the server speaks another version of the GUI protocol"
|
|
4851
|
+
);
|
|
4852
|
+
case "offline":
|
|
4853
|
+
return reason(
|
|
4854
|
+
"offline",
|
|
4855
|
+
"the connection to the GUI server is down: the client connects again by itself, then try again"
|
|
4856
|
+
);
|
|
4857
|
+
default:
|
|
4858
|
+
return reason(
|
|
4859
|
+
"connecting",
|
|
4860
|
+
"the client is still connecting to the GUI server: try again in a moment"
|
|
4861
|
+
);
|
|
4862
|
+
}
|
|
4863
|
+
}
|
|
4864
|
+
var busyReason = (name) => reason("busy", `the previous ${name} has not been answered yet: wait for it`);
|
|
4865
|
+
function fromServer(item, fallback, caution = null) {
|
|
4866
|
+
return item.ok ? control(true, null, caution) : control(false, reason(item.reason ?? "refused", item.message ?? fallback));
|
|
4867
|
+
}
|
|
4868
|
+
function numberOf(item, key) {
|
|
4869
|
+
const value = item?.raw?.[key];
|
|
4870
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
4871
|
+
}
|
|
4872
|
+
function controlsOf(s, run) {
|
|
4873
|
+
return composeControls(s, run).controls;
|
|
4874
|
+
}
|
|
4875
|
+
function writeOf(s, run) {
|
|
4876
|
+
return composeControls(s, run).write;
|
|
4877
|
+
}
|
|
4878
|
+
function composeControls(s, run) {
|
|
4879
|
+
const link = linkOf(s);
|
|
4880
|
+
const down = linkReason(link, s);
|
|
4881
|
+
const session = s.session;
|
|
4882
|
+
const live = !!session && session.launcher.running && run !== "ended" && run !== "crashed";
|
|
4883
|
+
const state = session?.launcherState ?? null;
|
|
4884
|
+
const stopsAsked = session?.stopRequests ?? 0;
|
|
4885
|
+
let start;
|
|
4886
|
+
if (link === "rejected" || link === "incompatible") start = control(false, down);
|
|
4887
|
+
else if (s.busy.has("start")) start = control(false, busyReason("start"));
|
|
4888
|
+
else if (down) start = control(false, down);
|
|
4889
|
+
else if (s.allowed) start = fromServer(s.allowed.start, "the server does not start a run now");
|
|
4890
|
+
else
|
|
4891
|
+
start = live ? control(
|
|
4892
|
+
false,
|
|
4893
|
+
reason("already-running", "a run is going: stop it before you start another")
|
|
4894
|
+
) : control(true);
|
|
4895
|
+
const serverStop = s.allowed?.stop;
|
|
4896
|
+
const stoppable = s.busy.has("start") || live || run === "starting" || serverStop?.ok === true;
|
|
4897
|
+
let stop;
|
|
4898
|
+
if (!s.busy.has("start") && s.allowed?.start.reason === "starting")
|
|
4899
|
+
stop = control(false, reason("starting", "wait until the new run can be identified"));
|
|
4900
|
+
else if (s.busy.has("stop")) stop = control(false, busyReason("stop"));
|
|
4901
|
+
else if (s.busy.has("start")) stop = control(true);
|
|
4902
|
+
else if (serverStop && !serverStop.ok && serverStop.reason !== "not-running")
|
|
4903
|
+
stop = fromServer(serverStop, "the server does not stop the run now");
|
|
4904
|
+
else if (!stoppable)
|
|
4905
|
+
stop = control(false, reason("not-running", "no run is going: there is nothing to stop"));
|
|
4906
|
+
else if (stopsAsked > 0)
|
|
4907
|
+
stop = control(
|
|
4908
|
+
false,
|
|
4909
|
+
reason("already-stopping", "a stop has been asked for: wait, or force the stop")
|
|
4910
|
+
);
|
|
4911
|
+
else stop = control(true);
|
|
4912
|
+
const serverForce = s.allowed?.force;
|
|
4913
|
+
let force;
|
|
4914
|
+
if (s.busy.has("start") || s.allowed?.start.reason === "starting")
|
|
4915
|
+
force = control(false, reason("starting", "wait until the new run can be identified"));
|
|
4916
|
+
else if (s.busy.has("force_stop")) force = control(false, busyReason("force stop"));
|
|
4917
|
+
else if (serverForce && !serverForce.ok && serverForce.reason !== "not-running")
|
|
4918
|
+
force = fromServer(serverForce, "the server does not force a stop now");
|
|
4919
|
+
else if (!stoppable)
|
|
4920
|
+
force = control(false, reason("not-running", "no run is going: there is nothing to stop"));
|
|
4921
|
+
else if (stopsAsked === 0 && !s.busy.has("stop"))
|
|
4922
|
+
force = control(
|
|
4923
|
+
false,
|
|
4924
|
+
reason("not-stopping", "ask for a stop first: force the stop only if it does not end")
|
|
4925
|
+
);
|
|
4926
|
+
else force = control(true);
|
|
4927
|
+
const timeControl = (name, label) => {
|
|
4928
|
+
if (link === "rejected" || link === "incompatible") return control(false, down);
|
|
4929
|
+
if (name !== "write" && s.busy.has(name)) return control(false, busyReason(label));
|
|
4930
|
+
if (down) return control(false, down);
|
|
4931
|
+
if (!live) return control(false, reason("not-running", "no run is going: start one first"));
|
|
4932
|
+
const said = launcherAnswer(state, name);
|
|
4933
|
+
return control(said.reason === null, said.reason, said.caution);
|
|
4934
|
+
};
|
|
4935
|
+
const withReason = (base, code, message) => base.ok ? control(false, reason(code, message), base.caution) : base;
|
|
4936
|
+
const paused = state && !onItsWay(session) ? state.paused : null;
|
|
4937
|
+
const pauseBase = timeControl("pause", "pause");
|
|
4938
|
+
const pause = paused === true ? withReason(pauseBase, "paused", "the simulation is already paused") : pauseBase;
|
|
4939
|
+
const resumeBase = timeControl("resume", "resume");
|
|
4940
|
+
const resume = paused === false ? withReason(resumeBase, "not-paused", "the simulation is not paused") : resumeBase;
|
|
4941
|
+
const stepItem = state?.allowed["step"];
|
|
4942
|
+
const speedItem = state?.allowed["speed"];
|
|
4943
|
+
const speedMin = numberOf(speedItem, "min") ?? s.limits.speed_min;
|
|
4944
|
+
const speedMax = numberOf(speedItem, "max") ?? s.limits.speed_max;
|
|
4945
|
+
const runUntil = timeControl("run_until", "run until");
|
|
4946
|
+
let save;
|
|
4947
|
+
if (down) save = control(false, down);
|
|
4948
|
+
else if (s.allowed)
|
|
4949
|
+
save = fromServer(s.allowed.save, "the server does not save now", s.allowed.save.caution);
|
|
4950
|
+
else save = control(true);
|
|
4951
|
+
const controls = {
|
|
4952
|
+
start,
|
|
4953
|
+
stop,
|
|
4954
|
+
force_stop: force,
|
|
4955
|
+
pause,
|
|
4956
|
+
resume,
|
|
4957
|
+
step: {
|
|
4958
|
+
...timeControl("step", "step"),
|
|
4959
|
+
min_ms: numberOf(stepItem, "min_ms") ?? 1,
|
|
4960
|
+
max_ms: numberOf(stepItem, "max_ms") ?? s.limits.step_ms_max
|
|
4961
|
+
},
|
|
4962
|
+
run_until: runUntil,
|
|
4963
|
+
speed: {
|
|
4964
|
+
...timeControl("speed", "speed change"),
|
|
4965
|
+
min: speedMin,
|
|
4966
|
+
max: speedMax,
|
|
4967
|
+
// The launcher's promise (docs/simulation-events.md, `allowed`): "max" is accepted unless min equals max
|
|
4968
|
+
fastest: speedMin !== speedMax
|
|
4969
|
+
},
|
|
4970
|
+
save
|
|
4971
|
+
};
|
|
4972
|
+
return { controls, write: timeControl("write", "write") };
|
|
4973
|
+
}
|
|
4974
|
+
function linkProblem(s) {
|
|
4975
|
+
const link = linkOf(s);
|
|
4976
|
+
return link === "rejected" || link === "incompatible" || link === "offline" ? linkReason(link, s) : null;
|
|
4977
|
+
}
|
|
4978
|
+
function newest(candidates) {
|
|
4979
|
+
let best = null;
|
|
4980
|
+
for (const c of candidates) if (!best || c.stamp > best.stamp) best = c;
|
|
4981
|
+
return best?.problem ?? null;
|
|
4982
|
+
}
|
|
4983
|
+
function sameData(a, b) {
|
|
4984
|
+
if (Object.is(a, b)) return true;
|
|
4985
|
+
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
|
|
4986
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
4987
|
+
const ka = Object.keys(a);
|
|
4988
|
+
const kb = Object.keys(b);
|
|
4989
|
+
if (ka.length !== kb.length) return false;
|
|
4990
|
+
return ka.every(
|
|
4991
|
+
(key) => sameData(a[key], b[key])
|
|
4992
|
+
);
|
|
4993
|
+
}
|
|
4994
|
+
|
|
4995
|
+
// ../client/src/front-actions.ts
|
|
4996
|
+
function actionError(error) {
|
|
4997
|
+
if (error instanceof ActionError) return error;
|
|
4998
|
+
if (error instanceof HttpError) {
|
|
4999
|
+
if (error.status === 0) {
|
|
5000
|
+
return new ActionError(
|
|
5001
|
+
error.timedOut ? "no-answer" : "network",
|
|
5002
|
+
error.timedOut ? `${error.message}: the server may have done it; look at status and clock before you send it again` : `${error.message}: the request did not reach the server`,
|
|
5003
|
+
"unknown"
|
|
5004
|
+
);
|
|
5005
|
+
}
|
|
5006
|
+
return new ActionError(
|
|
5007
|
+
error.problem?.code ?? `http-${error.status}`,
|
|
5008
|
+
error.message,
|
|
5009
|
+
"refused",
|
|
5010
|
+
error.problem?.findings ?? []
|
|
5011
|
+
);
|
|
5012
|
+
}
|
|
5013
|
+
return new ActionError("failed", errorMessage(error), "unknown");
|
|
5014
|
+
}
|
|
5015
|
+
var closedCheck = () => new ActionError("closed", "the client was closed before the check was sent", "refused");
|
|
5016
|
+
var MOVES = /* @__PURE__ */ new Set(["pause", "resume"]);
|
|
5017
|
+
var INTENT_FIELDS = /* @__PURE__ */ new Set([
|
|
5018
|
+
"vehicle_sil_run_request",
|
|
5019
|
+
"disable",
|
|
5020
|
+
"enable",
|
|
5021
|
+
"manual",
|
|
5022
|
+
"scenario",
|
|
5023
|
+
"variant",
|
|
5024
|
+
"params",
|
|
5025
|
+
"speed",
|
|
5026
|
+
"start_paused",
|
|
5027
|
+
"stop_at_ms",
|
|
5028
|
+
"late_tolerance_ms",
|
|
5029
|
+
"strict",
|
|
5030
|
+
"connect",
|
|
5031
|
+
"time_policy"
|
|
5032
|
+
]);
|
|
5033
|
+
var TEXT_INTENT_FIELDS = /* @__PURE__ */ new Set(["vehicle_sil_run_request", "variant", "strict"]);
|
|
5034
|
+
var noFileError = () => new ActionError(
|
|
5035
|
+
"no-file",
|
|
5036
|
+
"no configuration file was given and the server has none to start with: pass { file } (a path from client.low.configs())",
|
|
5037
|
+
"refused"
|
|
5038
|
+
);
|
|
5039
|
+
var FrontActions = class {
|
|
5040
|
+
constructor(src, idStart = 1 + Math.floor(Math.random() * 2 ** 40)) {
|
|
5041
|
+
this.src = src;
|
|
5042
|
+
this.nextId = idStart;
|
|
5043
|
+
this.closing.catch(() => void 0);
|
|
5044
|
+
this.busyValue = new Writable(/* @__PURE__ */ new Set(), Object.is, src.onError);
|
|
5045
|
+
this.failureValue = new Writable(null, Object.is, src.onError);
|
|
5046
|
+
this.busy = this.busyValue.readonly();
|
|
5047
|
+
this.failure = this.failureValue.readonly();
|
|
5048
|
+
this.stops.push(
|
|
5049
|
+
src.low.session.onMessages((batch) => this.onMessages(batch)),
|
|
5050
|
+
src.low.session.session.subscribe(() => this.evaluate())
|
|
5051
|
+
);
|
|
5052
|
+
}
|
|
5053
|
+
src;
|
|
5054
|
+
busyValue;
|
|
5055
|
+
failureValue;
|
|
5056
|
+
waiting = /* @__PURE__ */ new Map();
|
|
5057
|
+
inFlight = /* @__PURE__ */ new Map();
|
|
5058
|
+
/** The checks not answered yet, in the order they are sent: the first is on its way, the others wait. */
|
|
5059
|
+
checks = [];
|
|
5060
|
+
/** Rejects when the client closes: a check that waits ends with it. */
|
|
5061
|
+
close = () => void 0;
|
|
5062
|
+
closing = new Promise((_, reject) => this.close = reject);
|
|
5063
|
+
nextId;
|
|
5064
|
+
lastSim = null;
|
|
5065
|
+
stops = [];
|
|
5066
|
+
disposed = false;
|
|
5067
|
+
busy;
|
|
5068
|
+
failure;
|
|
5069
|
+
// --- run ---------------------------------------------------------------------------------------
|
|
5070
|
+
start(intent = {}, options = {}) {
|
|
5071
|
+
const request = this.requestOf(intent, options);
|
|
5072
|
+
if (request instanceof ActionError) return this.fail(request);
|
|
5073
|
+
const own = this.refusalOfStart();
|
|
5074
|
+
if (own) return this.fail(own);
|
|
5075
|
+
const start = this.src.low.run.start(request);
|
|
5076
|
+
return this.guarded("start", () => start.then(() => void 0));
|
|
5077
|
+
}
|
|
5078
|
+
/**
|
|
5079
|
+
* Checks what `intent` would start (`api/check`). Its failure is the caller's: it is not kept for `status.problem`.
|
|
5080
|
+
* One check at a time: a check is sent after the answer to the one before (the server runs them one at a time, and
|
|
5081
|
+
* refuses with `check-busy` when too many wait). A check of the same request as one that waits or is on its way
|
|
5082
|
+
* shares it (the parts and the screen of a page check the same page intent); with `fresh`, only one that waits (a
|
|
5083
|
+
* check that the user asks for again reads the file as it is now). A check whose callers have all aborted
|
|
5084
|
+
* (`signal`) while it waits is not sent, and neither is one that waits when the client closes (`closed`).
|
|
5085
|
+
*/
|
|
5086
|
+
check(intent = {}, options = {}) {
|
|
5087
|
+
const request = options.text === void 0 ? this.requestOf(intent, options) : this.textRequestOf(intent, options.file, options.text);
|
|
5088
|
+
if (request instanceof ActionError) return Promise.reject(request);
|
|
5089
|
+
if (this.disposed) return Promise.reject(closedCheck());
|
|
5090
|
+
const signal = options.signal ?? null;
|
|
5091
|
+
if (signal?.aborted) return Promise.reject(signal.reason);
|
|
5092
|
+
const key = options.text === void 0 ? JSON.stringify(request) : null;
|
|
5093
|
+
const going = key === null ? void 0 : this.checks.find((c) => c.key === key && !(options.fresh && c === this.checks[0]));
|
|
5094
|
+
if (going) {
|
|
5095
|
+
going.callers.push(signal);
|
|
5096
|
+
return going.promise;
|
|
5097
|
+
}
|
|
5098
|
+
return this.enqueue(key, [signal], () => this.src.low.check(request));
|
|
5099
|
+
}
|
|
5100
|
+
/** Reads a configuration file as it is saved. Its failure is the caller's: it is not kept for `status.problem`. */
|
|
5101
|
+
readConfig(options = {}) {
|
|
5102
|
+
const named = options.file ?? this.src.initialFile();
|
|
5103
|
+
if (named === null) return Promise.reject(noFileError());
|
|
5104
|
+
return this.src.low.config(named).catch((error) => {
|
|
5105
|
+
throw actionError(error);
|
|
5106
|
+
});
|
|
5107
|
+
}
|
|
5108
|
+
/** Saves a text as a configuration file. Its failure is the caller's: it is not kept for `status.problem`. */
|
|
5109
|
+
saveConfig(options) {
|
|
5110
|
+
const file = options.file ?? this.src.initialFile();
|
|
5111
|
+
if (file === null) return Promise.reject(noFileError());
|
|
5112
|
+
return this.src.low.saveConfig({ file, text: options.text, stamp: options.stamp }).catch((error) => {
|
|
5113
|
+
throw actionError(error);
|
|
5114
|
+
});
|
|
5115
|
+
}
|
|
5116
|
+
/** Describes the participants of the saved file again. It waits in the line of the checks; it shares only with a describe of the same file and variant. */
|
|
5117
|
+
describeAgain(options = {}) {
|
|
5118
|
+
const file = options.file ?? this.src.initialFile();
|
|
5119
|
+
if (file === null) return Promise.reject(noFileError());
|
|
5120
|
+
if (this.disposed) return Promise.reject(closedCheck());
|
|
5121
|
+
const request = {
|
|
5122
|
+
file,
|
|
5123
|
+
...options.variant !== void 0 ? { variant: options.variant } : {}
|
|
5124
|
+
};
|
|
5125
|
+
const key = `describe:${JSON.stringify(request)}`;
|
|
5126
|
+
const going = this.checks.find((c) => c.key === key);
|
|
5127
|
+
if (going) return going.promise;
|
|
5128
|
+
return this.enqueue(key, [null], () => this.src.low.describe(request));
|
|
5129
|
+
}
|
|
5130
|
+
/** The line of the checks: one is sent after the answer to the one before. `key` null: nothing is shared. */
|
|
5131
|
+
enqueue(key, callers, run) {
|
|
5132
|
+
const send = () => run().catch((error) => {
|
|
5133
|
+
throw actionError(error);
|
|
5134
|
+
});
|
|
5135
|
+
const before = this.checks.at(-1)?.done;
|
|
5136
|
+
const promise = before ? Promise.race([
|
|
5137
|
+
before.then(() => {
|
|
5138
|
+
if (this.disposed) return Promise.reject(closedCheck());
|
|
5139
|
+
const aborted = callers.every((s) => s?.aborted) ? callers[0] : null;
|
|
5140
|
+
return aborted ? Promise.reject(aborted.reason) : send();
|
|
5141
|
+
}),
|
|
5142
|
+
this.closing
|
|
5143
|
+
]) : send();
|
|
5144
|
+
const leave = () => {
|
|
5145
|
+
this.checks.splice(
|
|
5146
|
+
this.checks.findIndex((c) => c.promise === promise),
|
|
5147
|
+
1
|
|
5148
|
+
);
|
|
5149
|
+
};
|
|
5150
|
+
this.checks.push({ key, callers, promise, done: promise.then(leave, leave) });
|
|
5151
|
+
return promise;
|
|
5152
|
+
}
|
|
5153
|
+
/** The body of api/run and api/check for `intent`, or why it cannot be sent. */
|
|
5154
|
+
requestOf(intent, options) {
|
|
5155
|
+
const file = options.file ?? this.src.initialFile();
|
|
5156
|
+
if (file === null) return noFileError();
|
|
5157
|
+
const unknown = Object.keys(intent).filter((k) => !INTENT_FIELDS.has(k));
|
|
5158
|
+
if (unknown.length > 0) {
|
|
5159
|
+
return new ActionError(
|
|
5160
|
+
"unknown-field",
|
|
5161
|
+
`the intent has ${unknown.join(", ")}, which start and check do not know: the fields are ${[...INTENT_FIELDS].join(", ")}`,
|
|
5162
|
+
"refused"
|
|
5163
|
+
);
|
|
5164
|
+
}
|
|
5165
|
+
return {
|
|
5166
|
+
file,
|
|
5167
|
+
disable: intent.disable ?? [],
|
|
5168
|
+
...intent.vehicle_sil_run_request ? { vehicle_sil_run_request: intent.vehicle_sil_run_request } : {},
|
|
5169
|
+
...intent.enable ? { enable: intent.enable } : {},
|
|
5170
|
+
...intent.manual ? { manual: intent.manual } : {},
|
|
5171
|
+
...intent.scenario !== void 0 ? { scenario: intent.scenario } : {},
|
|
5172
|
+
...intent.variant !== void 0 ? { variant: intent.variant } : {},
|
|
5173
|
+
...intent.params ? { params: intent.params } : {},
|
|
5174
|
+
...intent.speed !== void 0 ? { speed: intent.speed } : {},
|
|
5175
|
+
...intent.start_paused ? { start_paused: true } : {},
|
|
5176
|
+
...intent.stop_at_ms !== void 0 ? { stop_at_ms: intent.stop_at_ms } : {},
|
|
5177
|
+
...intent.late_tolerance_ms !== void 0 ? { late_tolerance_ms: intent.late_tolerance_ms } : {},
|
|
5178
|
+
...intent.strict ? { strict: true } : {},
|
|
5179
|
+
...intent.connect ? { connect: intent.connect } : {},
|
|
5180
|
+
...intent.time_policy !== void 0 ? { time_policy: intent.time_policy } : {}
|
|
5181
|
+
};
|
|
5182
|
+
}
|
|
5183
|
+
/** The body of api/check for a text: the server takes only the configuration (`variant`, `strict`), not a run's choices. */
|
|
5184
|
+
textRequestOf(intent, fileOption, text3) {
|
|
5185
|
+
const file = fileOption ?? this.src.initialFile();
|
|
5186
|
+
if (file === null) return noFileError();
|
|
5187
|
+
const unknown = Object.keys(intent).filter((k) => !TEXT_INTENT_FIELDS.has(k));
|
|
5188
|
+
if (unknown.length > 0) {
|
|
5189
|
+
return new ActionError(
|
|
5190
|
+
"unknown-field",
|
|
5191
|
+
`the intent of a check of a text has ${unknown.join(", ")}, which it does not take: a text is checked as the configuration, so the fields are ${[...TEXT_INTENT_FIELDS].join(", ")}`,
|
|
5192
|
+
"refused"
|
|
5193
|
+
);
|
|
5194
|
+
}
|
|
5195
|
+
return {
|
|
5196
|
+
file,
|
|
5197
|
+
text: text3,
|
|
5198
|
+
...intent.vehicle_sil_run_request ? { vehicle_sil_run_request: intent.vehicle_sil_run_request } : {},
|
|
5199
|
+
...intent.variant !== void 0 ? { variant: intent.variant } : {},
|
|
5200
|
+
...intent.strict ? { strict: true } : {}
|
|
5201
|
+
};
|
|
5202
|
+
}
|
|
5203
|
+
/** What the client refuses before it sends a start: the connection, and a start of this page still on its way. */
|
|
5204
|
+
refusalOfStart() {
|
|
5205
|
+
const link = linkOf(this.src.snapshot());
|
|
5206
|
+
if (link === "rejected" || link === "incompatible") {
|
|
5207
|
+
const why = this.src.controls().start.reason;
|
|
5208
|
+
return new ActionError(link, why?.message ?? link, "refused");
|
|
5209
|
+
}
|
|
5210
|
+
return this.busyValue.get().has("start") ? new ActionError(
|
|
5211
|
+
"busy",
|
|
5212
|
+
"the previous start has not been answered yet: wait for it",
|
|
5213
|
+
"refused"
|
|
5214
|
+
) : null;
|
|
5215
|
+
}
|
|
5216
|
+
stop() {
|
|
5217
|
+
return this.once("stop", false);
|
|
5218
|
+
}
|
|
5219
|
+
forceStop(target) {
|
|
5220
|
+
const current = this.src.low.session.currentTarget();
|
|
5221
|
+
if (target && (current?.session !== target.session || current.instance !== target.instance))
|
|
5222
|
+
return this.fail(
|
|
5223
|
+
new ActionError("session-changed", "the confirmed run has changed", "refused")
|
|
5224
|
+
);
|
|
5225
|
+
if (this.src.low.run.starting.get())
|
|
5226
|
+
return this.fail(
|
|
5227
|
+
new ActionError("starting", "wait until the new run can be identified", "refused")
|
|
5228
|
+
);
|
|
5229
|
+
return this.once("force_stop", true);
|
|
5230
|
+
}
|
|
5231
|
+
/** Pending stop only affects controls of the run it was sent for. */
|
|
5232
|
+
busyForCurrent() {
|
|
5233
|
+
const busy = new Set(this.busyValue.get());
|
|
5234
|
+
const key = this.stopKey();
|
|
5235
|
+
for (const name of ["stop", "force_stop"]) {
|
|
5236
|
+
if (this.inFlight.get(name)?.key !== key) busy.delete(name);
|
|
5237
|
+
}
|
|
5238
|
+
return busy;
|
|
5239
|
+
}
|
|
5240
|
+
stopKey() {
|
|
5241
|
+
return this.src.captureStop().key;
|
|
5242
|
+
}
|
|
5243
|
+
/** Repeated requests for the same run share one operation. */
|
|
5244
|
+
once(name, force) {
|
|
5245
|
+
const capture = this.src.captureStop();
|
|
5246
|
+
const key = capture.key;
|
|
5247
|
+
const running = this.inFlight.get(name);
|
|
5248
|
+
if (running?.key === key) return running.promise;
|
|
5249
|
+
let resolve;
|
|
5250
|
+
let reject;
|
|
5251
|
+
const promise = new Promise((ok, fail) => {
|
|
5252
|
+
resolve = ok;
|
|
5253
|
+
reject = fail;
|
|
5254
|
+
});
|
|
5255
|
+
const entry = { key, promise };
|
|
5256
|
+
this.inFlight.set(name, entry);
|
|
5257
|
+
this.failureValue.set(null);
|
|
5258
|
+
const operation = capture.send(force);
|
|
5259
|
+
if (this.busyValue.get().has(name)) this.busyValue.set(new Set(this.busyValue.get()));
|
|
5260
|
+
else this.setBusy(name, true);
|
|
5261
|
+
operation.then(
|
|
5262
|
+
() => {
|
|
5263
|
+
if (this.inFlight.get(name) === entry) {
|
|
5264
|
+
this.inFlight.delete(name);
|
|
5265
|
+
this.setBusy(name, false);
|
|
5266
|
+
}
|
|
5267
|
+
resolve();
|
|
5268
|
+
},
|
|
5269
|
+
(error) => {
|
|
5270
|
+
if (this.inFlight.get(name) === entry) {
|
|
5271
|
+
this.inFlight.delete(name);
|
|
5272
|
+
this.setBusy(name, false);
|
|
5273
|
+
}
|
|
5274
|
+
reject(this.record(actionError(error)));
|
|
5275
|
+
}
|
|
5276
|
+
);
|
|
5277
|
+
return promise;
|
|
5278
|
+
}
|
|
5279
|
+
guarded(name, send) {
|
|
5280
|
+
this.failureValue.set(null);
|
|
5281
|
+
this.setBusy(name, true);
|
|
5282
|
+
return send().then(
|
|
5283
|
+
() => this.setBusy(name, false),
|
|
5284
|
+
(error) => {
|
|
5285
|
+
this.setBusy(name, false);
|
|
5286
|
+
throw this.record(actionError(error));
|
|
5287
|
+
}
|
|
5288
|
+
);
|
|
5289
|
+
}
|
|
5290
|
+
// --- time --------------------------------------------------------------------------------------
|
|
5291
|
+
pause() {
|
|
5292
|
+
return this.time("pause", { command: "pause" }, 0);
|
|
5293
|
+
}
|
|
5294
|
+
resume() {
|
|
5295
|
+
return this.time("resume", { command: "resume" }, 0);
|
|
5296
|
+
}
|
|
5297
|
+
step(ms) {
|
|
5298
|
+
if (!Number.isFinite(ms) || ms <= 0) {
|
|
5299
|
+
return this.fail(
|
|
5300
|
+
new ActionError(
|
|
5301
|
+
"invalid-argument",
|
|
5302
|
+
"step needs a number of milliseconds greater than 0",
|
|
5303
|
+
"refused"
|
|
5304
|
+
)
|
|
5305
|
+
);
|
|
5306
|
+
}
|
|
5307
|
+
return this.time("step", { command: "step", ms }, ms);
|
|
5308
|
+
}
|
|
5309
|
+
setSpeed(value) {
|
|
5310
|
+
if (value !== "max" && !(Number.isFinite(value) && value > 0)) {
|
|
5311
|
+
return this.fail(
|
|
5312
|
+
new ActionError(
|
|
5313
|
+
"invalid-argument",
|
|
5314
|
+
"the speed is a number greater than 0, or 'max'",
|
|
5315
|
+
"refused"
|
|
5316
|
+
)
|
|
5317
|
+
);
|
|
5318
|
+
}
|
|
5319
|
+
return this.time("speed", { command: "speed", value }, 0);
|
|
5320
|
+
}
|
|
5321
|
+
runUntil(ms) {
|
|
5322
|
+
if (!Number.isFinite(ms) || ms < 0) {
|
|
5323
|
+
return this.fail(
|
|
5324
|
+
new ActionError(
|
|
5325
|
+
"invalid-argument",
|
|
5326
|
+
"run_until needs a time in milliseconds, 0 or more",
|
|
5327
|
+
"refused"
|
|
5328
|
+
)
|
|
5329
|
+
);
|
|
5330
|
+
}
|
|
5331
|
+
return this.time("run_until", { command: "run_until", at_ms: ms }, ms);
|
|
5332
|
+
}
|
|
5333
|
+
time(op, body, amount) {
|
|
5334
|
+
this.failureValue.set(null);
|
|
5335
|
+
const snapshot = this.src.snapshot();
|
|
5336
|
+
const link = linkOf(snapshot);
|
|
5337
|
+
const own = link === "rejected" || link === "incompatible" ? this.src.controls()[op].reason : this.busyValue.get().has(op) ? { code: "busy", message: `the previous ${op} has not been answered yet: wait for it` } : null;
|
|
5338
|
+
if (own) return this.fail(new ActionError(own.code, own.message, "refused"));
|
|
5339
|
+
const code = this.src.controls()[op === "pause" ? "pause" : "resume"].reason?.code;
|
|
5340
|
+
if (op === "pause" && code === "paused" || op === "resume" && code === "not-paused") {
|
|
5341
|
+
return Promise.resolve();
|
|
5342
|
+
}
|
|
5343
|
+
const session = snapshot.session;
|
|
5344
|
+
const id = this.nextId++;
|
|
5345
|
+
return new Promise((resolve, reject) => {
|
|
5346
|
+
const waiting = {
|
|
5347
|
+
id,
|
|
5348
|
+
op,
|
|
5349
|
+
amount,
|
|
5350
|
+
session: session?.id ?? -1,
|
|
5351
|
+
stage: "sent",
|
|
5352
|
+
target: 0,
|
|
5353
|
+
from: 0,
|
|
5354
|
+
exact: false,
|
|
5355
|
+
timer: void 0,
|
|
5356
|
+
resolve,
|
|
5357
|
+
reject
|
|
5358
|
+
};
|
|
5359
|
+
this.waiting.set(id, waiting);
|
|
5360
|
+
this.setBusy(op, true);
|
|
5361
|
+
waiting.timer = setTimeout(() => {
|
|
5362
|
+
this.settle(
|
|
5363
|
+
waiting,
|
|
5364
|
+
new ActionError(
|
|
5365
|
+
"no-answer",
|
|
5366
|
+
`the launcher did not answer ${op} within ${this.src.answerTimeoutMs / 1e3} s (it may not read its input, or the answer went to another command): look at status and clock before you send it again`,
|
|
5367
|
+
"unknown"
|
|
5368
|
+
)
|
|
5369
|
+
);
|
|
5370
|
+
}, this.src.answerTimeoutMs);
|
|
5371
|
+
this.src.http({ method: "POST", path: "api/time", body: { ...body, id } }, (outcome) => {
|
|
5372
|
+
if (!outcome.ok) this.settle(waiting, actionError(outcome.error));
|
|
5373
|
+
});
|
|
5374
|
+
});
|
|
5375
|
+
}
|
|
5376
|
+
/** Ends a waiting command: with an error, or (null) as done. A command ended twice is ended once. */
|
|
5377
|
+
settle(waiting, error, report = true) {
|
|
5378
|
+
if (this.waiting.get(waiting.id) !== waiting) return;
|
|
5379
|
+
clearTimeout(waiting.timer);
|
|
5380
|
+
this.waiting.delete(waiting.id);
|
|
5381
|
+
if (waiting.stage === "sent") this.setBusy(waiting.op, this.stillSent(waiting.op));
|
|
5382
|
+
if (error) {
|
|
5383
|
+
if (report) this.record(error);
|
|
5384
|
+
waiting.reject(error);
|
|
5385
|
+
} else waiting.resolve();
|
|
5386
|
+
}
|
|
5387
|
+
stillSent(op) {
|
|
5388
|
+
for (const w of this.waiting.values()) if (w.op === op && w.stage === "sent") return true;
|
|
5389
|
+
return false;
|
|
5390
|
+
}
|
|
5391
|
+
setBusy(name, on) {
|
|
5392
|
+
const now = this.busyValue.get();
|
|
5393
|
+
if (now.has(name) === on) return;
|
|
5394
|
+
const next = new Set(now);
|
|
5395
|
+
if (on) next.add(name);
|
|
5396
|
+
else next.delete(name);
|
|
5397
|
+
this.busyValue.set(next);
|
|
5398
|
+
}
|
|
5399
|
+
/** The launcher's events: an answer to a command of ours, and commands of other senders. */
|
|
5400
|
+
onMessages(batch) {
|
|
5401
|
+
let sim = this.lastSim;
|
|
5402
|
+
for (const message of batch) {
|
|
5403
|
+
if (message.type !== "event") continue;
|
|
5404
|
+
const event = message.event;
|
|
5405
|
+
if (event.event === "time") sim = event.sim_ms;
|
|
5406
|
+
if (event.event !== "command") continue;
|
|
5407
|
+
const mine = event.id === null ? void 0 : this.waiting.get(event.id);
|
|
5408
|
+
if (mine && mine.session === message.session) this.answered(mine, event, sim);
|
|
5409
|
+
else if (event.accepted && event.command !== null && MOVES.has(event.command)) {
|
|
5410
|
+
this.interruptMoving(
|
|
5411
|
+
null,
|
|
5412
|
+
"another command (from another page or from stdin) came before it arrived"
|
|
5413
|
+
);
|
|
5414
|
+
}
|
|
5415
|
+
}
|
|
5416
|
+
this.lastSim = this.src.low.session.session.get()?.time?.simMs ?? sim;
|
|
5417
|
+
this.evaluate();
|
|
5418
|
+
}
|
|
5419
|
+
answered(waiting, event, sim) {
|
|
5420
|
+
if (!event.accepted) {
|
|
5421
|
+
this.settle(
|
|
5422
|
+
waiting,
|
|
5423
|
+
new ActionError(
|
|
5424
|
+
event.reason ?? "refused",
|
|
5425
|
+
event.message ?? `the launcher did not accept ${waiting.op}`,
|
|
5426
|
+
"refused"
|
|
5427
|
+
)
|
|
5428
|
+
);
|
|
5429
|
+
return;
|
|
5430
|
+
}
|
|
5431
|
+
if (waiting.op === "pause" || waiting.op === "resume") {
|
|
5432
|
+
this.interruptMoving(waiting, `${waiting.op} of this page came before it arrived`, false);
|
|
5433
|
+
}
|
|
5434
|
+
if (waiting.op === "step" || waiting.op === "run_until") {
|
|
5435
|
+
clearTimeout(waiting.timer);
|
|
5436
|
+
waiting.stage = "moving";
|
|
5437
|
+
waiting.from = sim ?? 0;
|
|
5438
|
+
waiting.exact = event.at_ms !== null;
|
|
5439
|
+
waiting.target = event.at_ms ?? (waiting.op === "step" ? waiting.from + (event.ms ?? waiting.amount) : waiting.amount);
|
|
5440
|
+
this.setBusy(waiting.op, this.stillSent(waiting.op));
|
|
5441
|
+
return;
|
|
5442
|
+
}
|
|
5443
|
+
this.settle(waiting, null);
|
|
5444
|
+
}
|
|
5445
|
+
/** Ends the steps and run_untils on their way (except `keep`) as interrupted. */
|
|
5446
|
+
interruptMoving(keep, why, report = true) {
|
|
5447
|
+
for (const w of [...this.waiting.values()]) {
|
|
5448
|
+
if (w !== keep && w.stage === "moving") {
|
|
5449
|
+
this.settle(
|
|
5450
|
+
w,
|
|
5451
|
+
new ActionError(
|
|
5452
|
+
"interrupted",
|
|
5453
|
+
`${w.op} did not arrive: ${why}; read clock to see where the time is`,
|
|
5454
|
+
"unknown"
|
|
5455
|
+
),
|
|
5456
|
+
report
|
|
5457
|
+
);
|
|
5458
|
+
}
|
|
5459
|
+
}
|
|
5460
|
+
}
|
|
5461
|
+
/** Ends what the state of the run decides: the run is over, time has arrived, or a stop is on its way. */
|
|
5462
|
+
evaluate() {
|
|
5463
|
+
if (this.waiting.size === 0) return;
|
|
5464
|
+
const session = this.src.low.session.session.get();
|
|
5465
|
+
for (const w of [...this.waiting.values()]) {
|
|
5466
|
+
if (!session || session.id !== w.session || !session.launcher.running || session.result) {
|
|
5467
|
+
this.settle(
|
|
5468
|
+
w,
|
|
5469
|
+
new ActionError(
|
|
5470
|
+
"not-running",
|
|
5471
|
+
`the run ended (or another one began) before ${w.op} was done: look at status`,
|
|
5472
|
+
"unknown"
|
|
5473
|
+
)
|
|
5474
|
+
);
|
|
5475
|
+
continue;
|
|
5476
|
+
}
|
|
5477
|
+
if (w.stage !== "moving") continue;
|
|
5478
|
+
const state = session.launcherState;
|
|
5479
|
+
if ((state?.stop?.requests ?? 0) > 0 || session.stopRequests > 0) {
|
|
5480
|
+
this.settle(
|
|
5481
|
+
w,
|
|
5482
|
+
new ActionError("interrupted", `${w.op} did not arrive: a stop was asked for`, "unknown"),
|
|
5483
|
+
false
|
|
5484
|
+
// a stop by the operator is not a problem to show
|
|
5485
|
+
);
|
|
5486
|
+
continue;
|
|
5487
|
+
}
|
|
5488
|
+
const stands = standsAt(session);
|
|
5489
|
+
if (stands !== null && (w.exact || stands > w.from) && stands >= w.target)
|
|
5490
|
+
this.settle(w, null);
|
|
5491
|
+
}
|
|
5492
|
+
}
|
|
5493
|
+
// --- bookkeeping -------------------------------------------------------------------------------
|
|
5494
|
+
/** Keeps the error for `status.problem`. */
|
|
5495
|
+
record(error) {
|
|
5496
|
+
this.failureValue.set({ error, run: this.src.run(), stamp: this.src.stamp() });
|
|
5497
|
+
return error;
|
|
5498
|
+
}
|
|
5499
|
+
fail(error) {
|
|
5500
|
+
return Promise.reject(this.record(error));
|
|
5501
|
+
}
|
|
5502
|
+
/** Stops waiting (the client closes): what is waiting ends as unknown, and a check that waits is not sent. */
|
|
5503
|
+
dispose() {
|
|
5504
|
+
if (this.disposed) return;
|
|
5505
|
+
this.disposed = true;
|
|
5506
|
+
this.close(closedCheck());
|
|
5507
|
+
for (const stop of this.stops) stop();
|
|
5508
|
+
for (const w of [...this.waiting.values()]) {
|
|
5509
|
+
this.settle(
|
|
5510
|
+
w,
|
|
5511
|
+
new ActionError("closed", `the client was closed before ${w.op} was done`, "unknown")
|
|
5512
|
+
);
|
|
5513
|
+
}
|
|
5514
|
+
}
|
|
5515
|
+
};
|
|
5516
|
+
|
|
5517
|
+
// ../client/src/front-outside.ts
|
|
5518
|
+
var isObject2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5519
|
+
var text2 = (value) => typeof value === "string" ? value : null;
|
|
5520
|
+
function entriesOf(answer) {
|
|
5521
|
+
const entries = [];
|
|
5522
|
+
const networks = answer.connections["networks"];
|
|
5523
|
+
for (const network of Array.isArray(networks) ? networks : []) {
|
|
5524
|
+
if (!isObject2(network) || !isObject2(network["list"])) continue;
|
|
5525
|
+
const list = network["list"];
|
|
5526
|
+
const backend = text2(list["backend"]) ?? text2(network["backend"]);
|
|
5527
|
+
for (const target of Array.isArray(list["targets"]) ? list["targets"] : []) {
|
|
5528
|
+
if (!isObject2(target)) continue;
|
|
5529
|
+
const value = text2(target["value"]);
|
|
5530
|
+
if (value === null) continue;
|
|
5531
|
+
entries.push({
|
|
5532
|
+
backend,
|
|
5533
|
+
value,
|
|
5534
|
+
label: text2(target["label"]) ?? value,
|
|
5535
|
+
detail: text2(target["detail"]) ?? "",
|
|
5536
|
+
usable: target["usable"] === true,
|
|
5537
|
+
reason: text2(target["reason"])
|
|
5538
|
+
});
|
|
5539
|
+
}
|
|
5540
|
+
if (isObject2(list["error"])) {
|
|
5541
|
+
entries.push({ backend, error: text2(list["error"]["message"]) ?? "the list failed" });
|
|
5542
|
+
}
|
|
5543
|
+
}
|
|
5544
|
+
const findings = answer.connections["findings"];
|
|
5545
|
+
for (const finding of Array.isArray(findings) ? findings : []) {
|
|
5546
|
+
if (isObject2(finding) && finding["severity"] === "error" && text2(finding["message"]) !== null) {
|
|
5547
|
+
entries.push({ backend: null, error: text2(finding["message"]) });
|
|
5548
|
+
}
|
|
5549
|
+
}
|
|
5550
|
+
return entries;
|
|
5551
|
+
}
|
|
5552
|
+
function outsideRows(low, onError) {
|
|
5553
|
+
const counts = new Writable(null, Object.is, onError);
|
|
5554
|
+
const stop = low.session.onMessages((batch) => {
|
|
5555
|
+
let next = counts.get();
|
|
5556
|
+
for (const message of batch) {
|
|
5557
|
+
if (message.type !== "event" || message.event.event !== "outside") continue;
|
|
5558
|
+
const { network, to_outside, from_outside } = message.event;
|
|
5559
|
+
const networks = new Map(next?.session === message.session ? next.networks : []);
|
|
5560
|
+
networks.set(network, { to: to_outside, from: from_outside });
|
|
5561
|
+
next = { session: message.session, networks };
|
|
5562
|
+
}
|
|
5563
|
+
if (next !== counts.get()) counts.set(next);
|
|
5564
|
+
});
|
|
5565
|
+
const value = derived(
|
|
5566
|
+
[low.session.session, counts],
|
|
5567
|
+
() => {
|
|
5568
|
+
const session = low.session.session.get();
|
|
5569
|
+
if (!session?.launcher.running) return [];
|
|
5570
|
+
const known = counts.get();
|
|
5571
|
+
const of = known?.session === session.id ? known.networks : /* @__PURE__ */ new Map();
|
|
5572
|
+
return (session.launcherState?.outside ?? []).map((row) => {
|
|
5573
|
+
const count2 = of.get(row.network);
|
|
5574
|
+
return {
|
|
5575
|
+
network: row.network,
|
|
5576
|
+
target: row.target,
|
|
5577
|
+
participant: row.participant,
|
|
5578
|
+
link: row.link,
|
|
5579
|
+
bus: row.bus,
|
|
5580
|
+
condition: row.condition,
|
|
5581
|
+
reasons: row.reasons,
|
|
5582
|
+
nothing_received: row.nothing_received,
|
|
5583
|
+
to_outside: count2?.to ?? null,
|
|
5584
|
+
from_outside: count2?.from ?? null
|
|
5585
|
+
};
|
|
5586
|
+
});
|
|
5587
|
+
},
|
|
5588
|
+
sameData,
|
|
5589
|
+
onError
|
|
5590
|
+
);
|
|
5591
|
+
return { value, stop };
|
|
5592
|
+
}
|
|
5593
|
+
|
|
5594
|
+
// ../client/src/front-variable.ts
|
|
5595
|
+
var WHY_BLOCKED = {
|
|
5596
|
+
"read-only": "this variable is an output of the ECU: it cannot be written",
|
|
5597
|
+
disconnected: "the connection to the GUI server is down: wait until it is back",
|
|
5598
|
+
"not-ready": "the variables are not available now (no run, or the run has no Control Server)",
|
|
5599
|
+
ended: "the run has ended: start a new one to write again",
|
|
5600
|
+
missing: "this variable is not in the current run: check the names (ECU and variable)",
|
|
5601
|
+
"peer-disconnected": "the ECU is not connected to the Control Server now",
|
|
5602
|
+
parameter: "a parameter can be written only before the first step: start the run paused",
|
|
5603
|
+
"no-range": "the variable has no range (min and max)",
|
|
5604
|
+
"no-value": "there is no value yet"
|
|
5605
|
+
};
|
|
5606
|
+
function noteOf(condition) {
|
|
5607
|
+
switch (condition.kind) {
|
|
5608
|
+
case "live":
|
|
5609
|
+
return null;
|
|
5610
|
+
case "paused":
|
|
5611
|
+
return "the value at the paused time";
|
|
5612
|
+
case "waiting":
|
|
5613
|
+
return "no value has arrived yet";
|
|
5614
|
+
case "missing":
|
|
5615
|
+
return "this variable is not in the current run: check the names (ECU and variable)";
|
|
5616
|
+
case "ended":
|
|
5617
|
+
return "the last value of the run that has ended";
|
|
5618
|
+
case "unavailable":
|
|
5619
|
+
return "the variables are not available now (no run, or the run has no Control Server)";
|
|
5620
|
+
case "stale":
|
|
5621
|
+
return {
|
|
5622
|
+
connection: "the connection to the GUI server is down: the value may be out of date",
|
|
5623
|
+
reconnecting: "the server is connecting to the launcher again: the value may be out of date",
|
|
5624
|
+
peer: "the ECU is not connected to the Control Server: the value may be out of date",
|
|
5625
|
+
reading: "reading the values keeps failing: the value may be out of date"
|
|
5626
|
+
}[condition.why];
|
|
5627
|
+
}
|
|
5628
|
+
}
|
|
5629
|
+
function textOf(bound) {
|
|
5630
|
+
const value = bound.reading?.value;
|
|
5631
|
+
if (value === void 0 || value === null) return "";
|
|
5632
|
+
const item = bound.info?.enum?.find((e) => e.value === value);
|
|
5633
|
+
return item ? item.name : String(value);
|
|
5634
|
+
}
|
|
5635
|
+
function refOf(ref) {
|
|
5636
|
+
if (typeof ref !== "string") return { peer: ref.peer, name: ref.name };
|
|
5637
|
+
const dot = ref.indexOf(".");
|
|
5638
|
+
if (dot <= 0 || dot === ref.length - 1) {
|
|
5639
|
+
throw new ActionError(
|
|
5640
|
+
"invalid-argument",
|
|
5641
|
+
`'${ref}' is not "ECU.variable": write the ECU's name, a dot, then the variable (or pass {peer, name} for an ECU whose name has a dot)`,
|
|
5642
|
+
"refused"
|
|
5643
|
+
);
|
|
5644
|
+
}
|
|
5645
|
+
return { peer: ref.slice(0, dot), name: ref.slice(dot + 1) };
|
|
5646
|
+
}
|
|
5647
|
+
function whyOf(bound, launcher) {
|
|
5648
|
+
if (bound.block === null) return launcher.reason;
|
|
5649
|
+
if (bound.block === "launcher") return bound.launcherReason ?? launcher.reason;
|
|
5650
|
+
return { code: bound.block, message: WHY_BLOCKED[bound.block] };
|
|
5651
|
+
}
|
|
5652
|
+
function viewOf(bound, track, launcher) {
|
|
5653
|
+
const status = bound.writeStatus;
|
|
5654
|
+
const failed = status.kind === "invalid" || status.kind === "dropped" || "code" in status ? {
|
|
5655
|
+
code: "code" in status && status.code ? status.code : status.kind,
|
|
5656
|
+
message: status.message
|
|
5657
|
+
} : null;
|
|
5658
|
+
return {
|
|
5659
|
+
value: bound.reading?.value ?? null,
|
|
5660
|
+
text: textOf(bound),
|
|
5661
|
+
unit: bound.info?.unit ?? "",
|
|
5662
|
+
min: bound.info?.min ?? null,
|
|
5663
|
+
max: bound.info?.max ?? null,
|
|
5664
|
+
step: bound.info?.step ?? null,
|
|
5665
|
+
sim_ms: bound.reading?.sampleMs ?? null,
|
|
5666
|
+
stale: bound.condition.kind === "stale",
|
|
5667
|
+
note: noteOf(bound.condition),
|
|
5668
|
+
availability: bound.availability,
|
|
5669
|
+
can_write: bound.block === null && launcher.ok,
|
|
5670
|
+
why: whyOf(bound, launcher),
|
|
5671
|
+
writing: track.writing || status.kind === "sending" || status.kind === "queued" || bound.pending !== null,
|
|
5672
|
+
problem: track.problem ?? failed,
|
|
5673
|
+
condition: bound.condition,
|
|
5674
|
+
block: bound.block,
|
|
5675
|
+
write_status: status
|
|
5676
|
+
};
|
|
5677
|
+
}
|
|
5678
|
+
function writeFailure(error) {
|
|
5679
|
+
if (error instanceof WriteError) {
|
|
5680
|
+
return new ActionError(
|
|
5681
|
+
error.code ?? error.kind,
|
|
5682
|
+
error.message,
|
|
5683
|
+
error.kind === "no-answer" || error.kind === "closed" ? "unknown" : "refused"
|
|
5684
|
+
);
|
|
5685
|
+
}
|
|
5686
|
+
return actionError(error);
|
|
5687
|
+
}
|
|
5688
|
+
function makeVariable(low, ref, refuse, launcher) {
|
|
5689
|
+
const track = new Writable({ writing: false, problem: null }, sameData);
|
|
5690
|
+
const view = new Writable(null, sameData);
|
|
5691
|
+
let binding = null;
|
|
5692
|
+
let count2 = 0;
|
|
5693
|
+
let stops = [];
|
|
5694
|
+
const refresh = () => {
|
|
5695
|
+
if (binding) view.set(viewOf(binding.state.get(), track.get(), launcher.get()));
|
|
5696
|
+
};
|
|
5697
|
+
let peeked = null;
|
|
5698
|
+
const peek = () => {
|
|
5699
|
+
const once = low.variables.bind(ref, { visible: false });
|
|
5700
|
+
try {
|
|
5701
|
+
const next = viewOf(once.state.get(), track.get(), launcher.get());
|
|
5702
|
+
if (!peeked || !sameData(peeked, next)) peeked = next;
|
|
5703
|
+
return peeked;
|
|
5704
|
+
} finally {
|
|
5705
|
+
once.close();
|
|
5706
|
+
}
|
|
5707
|
+
};
|
|
5708
|
+
const readable = {
|
|
5709
|
+
get: () => {
|
|
5710
|
+
if (!binding) return peek();
|
|
5711
|
+
return view.get();
|
|
5712
|
+
},
|
|
5713
|
+
subscribe: (listener) => {
|
|
5714
|
+
if (count2++ === 0) {
|
|
5715
|
+
binding = low.variables.bind(ref);
|
|
5716
|
+
stops = [
|
|
5717
|
+
binding.state.subscribe(refresh),
|
|
5718
|
+
track.subscribe(refresh),
|
|
5719
|
+
launcher.subscribe(refresh)
|
|
5720
|
+
];
|
|
5721
|
+
refresh();
|
|
5722
|
+
}
|
|
5723
|
+
const off = view.subscribe((v) => v && listener(v));
|
|
5724
|
+
let done = false;
|
|
5725
|
+
return () => {
|
|
5726
|
+
if (done) return;
|
|
5727
|
+
done = true;
|
|
5728
|
+
off();
|
|
5729
|
+
if (--count2 === 0) {
|
|
5730
|
+
for (const stop of stops) stop();
|
|
5731
|
+
stops = [];
|
|
5732
|
+
binding?.close();
|
|
5733
|
+
binding = null;
|
|
5734
|
+
view.set(null);
|
|
5735
|
+
}
|
|
5736
|
+
};
|
|
5737
|
+
}
|
|
5738
|
+
};
|
|
5739
|
+
return {
|
|
5740
|
+
get: readable.get,
|
|
5741
|
+
subscribe: readable.subscribe,
|
|
5742
|
+
write: (value) => {
|
|
5743
|
+
const own = refuse();
|
|
5744
|
+
if (own) return Promise.reject(own);
|
|
5745
|
+
track.set({ writing: true, problem: null });
|
|
5746
|
+
return low.variables.write({ [ref.peer]: { [ref.name]: value } }).then(
|
|
5747
|
+
() => {
|
|
5748
|
+
track.set({ writing: false, problem: null });
|
|
5749
|
+
},
|
|
5750
|
+
(error) => {
|
|
5751
|
+
const failure = writeFailure(error);
|
|
5752
|
+
track.set({ writing: false, problem: { code: failure.code, message: failure.message } });
|
|
5753
|
+
throw failure;
|
|
5754
|
+
}
|
|
5755
|
+
);
|
|
5756
|
+
}
|
|
5757
|
+
};
|
|
5758
|
+
}
|
|
5759
|
+
|
|
5760
|
+
// ../client/src/front.ts
|
|
5761
|
+
function makeFront(options, onClose) {
|
|
5762
|
+
const { client: low, http, onError, runControl } = buildClient(options);
|
|
5763
|
+
let counter = 0;
|
|
5764
|
+
const stamp = () => ++counter;
|
|
5765
|
+
const stamps = /* @__PURE__ */ new Map();
|
|
5766
|
+
const stampFor = (key) => {
|
|
5767
|
+
let value = stamps.get(key);
|
|
5768
|
+
if (value === void 0) stamps.set(key, value = stamp());
|
|
5769
|
+
return value;
|
|
5770
|
+
};
|
|
5771
|
+
const initialFile = () => low.app.get()?.initial_file ?? null;
|
|
5772
|
+
let actions;
|
|
5773
|
+
const snapshot = () => ({
|
|
5774
|
+
connection: low.connection.state.get(),
|
|
5775
|
+
failures: low.connection.failures.get(),
|
|
5776
|
+
closedBefore: low.connection.lastClose.get() !== null,
|
|
5777
|
+
rejected: low.session.rejected.get(),
|
|
5778
|
+
incompatible: low.session.incompatible.get(),
|
|
5779
|
+
ready: low.session.ready.get(),
|
|
5780
|
+
session: low.session.session.get(),
|
|
5781
|
+
allowed: low.session.allowed.get(),
|
|
5782
|
+
limits: low.limits.get(),
|
|
5783
|
+
busy: actions.busyForCurrent()
|
|
5784
|
+
});
|
|
5785
|
+
const sources = [
|
|
5786
|
+
low.connection.state,
|
|
5787
|
+
low.connection.failures,
|
|
5788
|
+
low.connection.lastClose,
|
|
5789
|
+
low.session.rejected,
|
|
5790
|
+
low.session.incompatible,
|
|
5791
|
+
low.session.ready,
|
|
5792
|
+
low.session.session,
|
|
5793
|
+
low.session.allowed,
|
|
5794
|
+
low.limits,
|
|
5795
|
+
low.app
|
|
5796
|
+
];
|
|
5797
|
+
const controls = {
|
|
5798
|
+
get: () => controlsValue.get(),
|
|
5799
|
+
subscribe: (listener) => controlsValue.subscribe(listener)
|
|
5800
|
+
};
|
|
5801
|
+
const run = () => runOf(snapshot());
|
|
5802
|
+
actions = new FrontActions({
|
|
5803
|
+
low,
|
|
5804
|
+
http,
|
|
5805
|
+
captureStop: () => runControl.captureStop(),
|
|
5806
|
+
snapshot,
|
|
5807
|
+
controls: () => controls.get(),
|
|
5808
|
+
run,
|
|
5809
|
+
initialFile,
|
|
5810
|
+
answerTimeoutMs: options.answerTimeoutMs ?? ANSWER_TIMEOUT_MS,
|
|
5811
|
+
onError,
|
|
5812
|
+
stamp
|
|
5813
|
+
});
|
|
5814
|
+
const controlsValue = derived(
|
|
5815
|
+
[...sources, actions.busy],
|
|
5816
|
+
() => {
|
|
5817
|
+
const s = snapshot();
|
|
5818
|
+
return controlsOf(s, runOf(s));
|
|
5819
|
+
},
|
|
5820
|
+
sameData,
|
|
5821
|
+
onError
|
|
5822
|
+
);
|
|
5823
|
+
const writeControl = derived(
|
|
5824
|
+
[...sources, actions.busy],
|
|
5825
|
+
() => {
|
|
5826
|
+
const s = snapshot();
|
|
5827
|
+
return writeOf(s, runOf(s));
|
|
5828
|
+
},
|
|
5829
|
+
sameData,
|
|
5830
|
+
onError
|
|
5831
|
+
);
|
|
5832
|
+
const status = derived(
|
|
5833
|
+
[...sources, actions.busy, actions.failure],
|
|
5834
|
+
() => {
|
|
5835
|
+
const s = snapshot();
|
|
5836
|
+
const base = statusOf(s, initialFile());
|
|
5837
|
+
let problem = linkProblem(s);
|
|
5838
|
+
if (!problem) {
|
|
5839
|
+
const id = s.session?.id;
|
|
5840
|
+
const candidates = [];
|
|
5841
|
+
if (base.run === "crashed" && base.result) {
|
|
5842
|
+
candidates.push({
|
|
5843
|
+
stamp: stampFor(`crashed:${id}`),
|
|
5844
|
+
problem: { code: "launcher-crashed", message: base.result.message }
|
|
5845
|
+
});
|
|
5846
|
+
}
|
|
5847
|
+
if (base.run === "ended" && base.result && !base.result.ok) {
|
|
5848
|
+
candidates.push({
|
|
5849
|
+
stamp: stampFor(`failed:${id}`),
|
|
5850
|
+
problem: { code: "run-failed", message: base.result.message }
|
|
5851
|
+
});
|
|
5852
|
+
}
|
|
5853
|
+
const failure = actions.failure.get();
|
|
5854
|
+
if (failure && failure.run === base.run) {
|
|
5855
|
+
candidates.push({
|
|
5856
|
+
stamp: failure.stamp,
|
|
5857
|
+
problem: { code: failure.error.code, message: failure.error.message }
|
|
5858
|
+
});
|
|
5859
|
+
}
|
|
5860
|
+
problem = newest(candidates);
|
|
5861
|
+
}
|
|
5862
|
+
return { ...base, problem };
|
|
5863
|
+
},
|
|
5864
|
+
sameData,
|
|
5865
|
+
onError
|
|
5866
|
+
);
|
|
5867
|
+
const clock = derived(
|
|
5868
|
+
sources,
|
|
5869
|
+
() => clockOf(snapshot()),
|
|
5870
|
+
sameData,
|
|
5871
|
+
onError
|
|
5872
|
+
);
|
|
5873
|
+
const scenario = derived(
|
|
5874
|
+
[low.session.session],
|
|
5875
|
+
() => {
|
|
5876
|
+
const view = low.session.session.get()?.scenario;
|
|
5877
|
+
return view ? {
|
|
5878
|
+
file: view.file,
|
|
5879
|
+
name: view.name,
|
|
5880
|
+
status: view.status,
|
|
5881
|
+
steps: view.steps,
|
|
5882
|
+
timeline_url: view.timelineUrl
|
|
5883
|
+
} : null;
|
|
5884
|
+
},
|
|
5885
|
+
sameData,
|
|
5886
|
+
onError
|
|
5887
|
+
);
|
|
5888
|
+
const outside = outsideRows(low, onError);
|
|
5889
|
+
const variables = /* @__PURE__ */ new Map();
|
|
5890
|
+
let closed = false;
|
|
5891
|
+
return {
|
|
5892
|
+
low,
|
|
5893
|
+
status,
|
|
5894
|
+
clock,
|
|
5895
|
+
controls,
|
|
5896
|
+
scenario,
|
|
5897
|
+
outside: outside.value,
|
|
5898
|
+
connections: ({ network }, listOptions = {}) => {
|
|
5899
|
+
const file = listOptions.file ?? initialFile();
|
|
5900
|
+
if (file === null) {
|
|
5901
|
+
return Promise.reject(noFileError());
|
|
5902
|
+
}
|
|
5903
|
+
return low.connections({ file, network }).then(entriesOf, (error) => {
|
|
5904
|
+
throw actionError(error);
|
|
5905
|
+
});
|
|
5906
|
+
},
|
|
5907
|
+
scenarios: (listOptions = {}) => {
|
|
5908
|
+
const file = listOptions.file ?? initialFile();
|
|
5909
|
+
if (file === null) {
|
|
5910
|
+
return Promise.reject(
|
|
5911
|
+
new ActionError(
|
|
5912
|
+
"no-file",
|
|
5913
|
+
"no configuration file was given and the server has none to start with: pass { file } (a path from client.low.configs())",
|
|
5914
|
+
"refused"
|
|
5915
|
+
)
|
|
5916
|
+
);
|
|
5917
|
+
}
|
|
5918
|
+
return low.scenarios(file).then(
|
|
5919
|
+
(list) => list.scenarios,
|
|
5920
|
+
(error) => {
|
|
5921
|
+
throw actionError(error);
|
|
5922
|
+
}
|
|
5923
|
+
);
|
|
5924
|
+
},
|
|
5925
|
+
check: (intent, checkOptions) => actions.check(intent, checkOptions),
|
|
5926
|
+
readConfig: (readOptions2) => actions.readConfig(readOptions2),
|
|
5927
|
+
describeAgain: (describeOptions) => actions.describeAgain(describeOptions),
|
|
5928
|
+
saveConfig: (saveOptions) => actions.saveConfig(saveOptions),
|
|
5929
|
+
run: {
|
|
5930
|
+
start: (intent, startOptions) => actions.start(intent, startOptions),
|
|
5931
|
+
stop: () => actions.stop(),
|
|
5932
|
+
forceStop: (target) => actions.forceStop(target)
|
|
5933
|
+
},
|
|
5934
|
+
time: {
|
|
5935
|
+
pause: () => actions.pause(),
|
|
5936
|
+
resume: () => actions.resume(),
|
|
5937
|
+
step: (ms) => actions.step(ms),
|
|
5938
|
+
setSpeed: (value) => actions.setSpeed(value),
|
|
5939
|
+
runUntil: (ms) => actions.runUntil(ms)
|
|
5940
|
+
},
|
|
5941
|
+
variable: (ref) => {
|
|
5942
|
+
const named = refOf(ref);
|
|
5943
|
+
const key = `${named.peer}\0${named.name}`;
|
|
5944
|
+
let variable = variables.get(key);
|
|
5945
|
+
if (!variable) {
|
|
5946
|
+
variable = makeVariable(
|
|
5947
|
+
low,
|
|
5948
|
+
named,
|
|
5949
|
+
() => {
|
|
5950
|
+
const link = linkOf(snapshot());
|
|
5951
|
+
return link === "rejected" || link === "incompatible" ? new ActionError(link, writeControl.get().reason?.message ?? link, "refused") : null;
|
|
5952
|
+
},
|
|
5953
|
+
writeControl
|
|
5954
|
+
);
|
|
5955
|
+
variables.set(key, variable);
|
|
5956
|
+
}
|
|
5957
|
+
return variable;
|
|
5958
|
+
},
|
|
5959
|
+
close: () => {
|
|
5960
|
+
if (closed) return;
|
|
5961
|
+
closed = true;
|
|
5962
|
+
outside.stop();
|
|
5963
|
+
actions.dispose();
|
|
5964
|
+
low.close();
|
|
5965
|
+
onClose();
|
|
5966
|
+
}
|
|
5967
|
+
};
|
|
5968
|
+
}
|
|
5969
|
+
var shared = null;
|
|
5970
|
+
async function open(options, onClose) {
|
|
5971
|
+
const front = makeFront(
|
|
5972
|
+
{
|
|
5973
|
+
baseUrl: options.base_url,
|
|
5974
|
+
token: options.token,
|
|
5975
|
+
origin: options.origin,
|
|
5976
|
+
http: options.http,
|
|
5977
|
+
socket: options.socket,
|
|
5978
|
+
answerTimeoutMs: options.answer_timeout_ms,
|
|
5979
|
+
onError: options.on_error
|
|
5980
|
+
},
|
|
5981
|
+
onClose
|
|
5982
|
+
);
|
|
5983
|
+
front.low.connect();
|
|
5984
|
+
try {
|
|
5985
|
+
await front.low.loadApp();
|
|
5986
|
+
} catch (error) {
|
|
5987
|
+
front.close();
|
|
5988
|
+
throw actionError(error);
|
|
5989
|
+
}
|
|
5990
|
+
return front;
|
|
5991
|
+
}
|
|
5992
|
+
function createFront(options) {
|
|
5993
|
+
return makeFront(options, () => void 0);
|
|
5994
|
+
}
|
|
5995
|
+
function pageOptions() {
|
|
5996
|
+
const page = globalThis.window;
|
|
5997
|
+
const token = page ? takeToken(page) : null;
|
|
5998
|
+
if (!page || token === null) {
|
|
5999
|
+
throw new ActionError(
|
|
6000
|
+
"no-token",
|
|
6001
|
+
"connect() without options works in a page that the GUI server served and that was opened from the URL it printed (it ends with #token=...). In Node, pass { base_url, token }",
|
|
6002
|
+
"refused"
|
|
6003
|
+
);
|
|
6004
|
+
}
|
|
6005
|
+
return { base_url: new URL("/", page.location.href).href, token };
|
|
6006
|
+
}
|
|
6007
|
+
function connect(options) {
|
|
6008
|
+
if (options) return open(options, () => void 0);
|
|
6009
|
+
if (shared) return shared;
|
|
6010
|
+
let promise;
|
|
6011
|
+
try {
|
|
6012
|
+
promise = open(pageOptions(), () => {
|
|
6013
|
+
if (shared === promise) shared = null;
|
|
6014
|
+
});
|
|
6015
|
+
} catch (error) {
|
|
6016
|
+
return Promise.reject(error);
|
|
6017
|
+
}
|
|
6018
|
+
shared = promise;
|
|
6019
|
+
promise.catch(() => {
|
|
6020
|
+
if (shared === promise) shared = null;
|
|
6021
|
+
});
|
|
6022
|
+
return promise;
|
|
6023
|
+
}
|
|
6024
|
+
function watch(source, fn) {
|
|
6025
|
+
const list = Array.isArray(source) ? source : [source];
|
|
6026
|
+
const call = fn;
|
|
6027
|
+
const run = () => call(...list.map((s) => s.get()));
|
|
6028
|
+
const stops = list.map((s) => s.subscribe(run));
|
|
6029
|
+
run();
|
|
6030
|
+
return () => stops.forEach((stop) => stop());
|
|
6031
|
+
}
|
|
6032
|
+
function until(source, test, options = {}) {
|
|
6033
|
+
return new Promise((resolve, reject) => {
|
|
6034
|
+
let timer;
|
|
6035
|
+
const cleanups = [];
|
|
6036
|
+
const finish = (done) => {
|
|
6037
|
+
clearTimeout(timer);
|
|
6038
|
+
cleanups.forEach((cleanup) => cleanup());
|
|
6039
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
6040
|
+
done();
|
|
6041
|
+
};
|
|
6042
|
+
const onAbort = () => finish(() => reject(new ActionError("aborted", "the wait was aborted", "unknown")));
|
|
6043
|
+
if (options.signal?.aborted) {
|
|
6044
|
+
reject(new ActionError("aborted", "the wait was aborted", "unknown"));
|
|
6045
|
+
return;
|
|
6046
|
+
}
|
|
6047
|
+
const check = (value) => {
|
|
6048
|
+
if (test(value)) finish(() => resolve(value));
|
|
6049
|
+
};
|
|
6050
|
+
cleanups.push(source.subscribe(check));
|
|
6051
|
+
options.signal?.addEventListener("abort", onAbort);
|
|
6052
|
+
if (options.timeout_ms !== void 0) {
|
|
6053
|
+
timer = setTimeout(
|
|
6054
|
+
() => finish(
|
|
6055
|
+
() => reject(
|
|
6056
|
+
new ActionError(
|
|
6057
|
+
"timeout",
|
|
6058
|
+
`the condition did not hold within ${options.timeout_ms / 1e3} s: look at the state before you wait again`,
|
|
6059
|
+
"unknown"
|
|
6060
|
+
)
|
|
6061
|
+
)
|
|
6062
|
+
),
|
|
6063
|
+
options.timeout_ms
|
|
6064
|
+
);
|
|
6065
|
+
}
|
|
6066
|
+
const first = source.get();
|
|
6067
|
+
if (test(first)) finish(() => resolve(first));
|
|
6068
|
+
});
|
|
6069
|
+
}
|
|
6070
|
+
|
|
6071
|
+
// ../client/src/waveforms.ts
|
|
6072
|
+
function createWaveforms(client, options = {}) {
|
|
6073
|
+
const settings = { ...options, history: options.history ?? 600 };
|
|
6074
|
+
const series = new Writable([], Object.is, clientErrorSink(client));
|
|
6075
|
+
let historyTarget = client.session.currentTarget();
|
|
6076
|
+
let selection = [];
|
|
6077
|
+
let active = null;
|
|
6078
|
+
let unsubscribe;
|
|
6079
|
+
let closed = false;
|
|
6080
|
+
const setSignals = (refs) => {
|
|
6081
|
+
if (closed) return;
|
|
6082
|
+
const seen = /* @__PURE__ */ new Set();
|
|
6083
|
+
const next = refs.flatMap(({ peer, name }) => {
|
|
6084
|
+
const key = JSON.stringify([peer, name]);
|
|
6085
|
+
if (seen.has(key)) return [];
|
|
6086
|
+
seen.add(key);
|
|
6087
|
+
return [{ peer, name }];
|
|
6088
|
+
});
|
|
6089
|
+
if (next.length === selection.length && next.every((ref, i) => ref.peer === selection[i].peer && ref.name === selection[i].name))
|
|
6090
|
+
return;
|
|
6091
|
+
const previous = active;
|
|
6092
|
+
unsubscribe?.();
|
|
6093
|
+
const feed = next.length ? client.variables.watch(next, settings) : null;
|
|
6094
|
+
selection = next;
|
|
6095
|
+
active = feed;
|
|
6096
|
+
const refresh = () => {
|
|
6097
|
+
if (active !== feed || closed) return;
|
|
6098
|
+
historyTarget = client.session.currentTarget();
|
|
6099
|
+
const current = historyTarget && historyTarget.session === client.variables.state.get().session;
|
|
6100
|
+
series.set(
|
|
6101
|
+
next.map((ref) => ({ ref: { ...ref }, points: current && feed ? feed.history(ref) : [] }))
|
|
6102
|
+
);
|
|
6103
|
+
};
|
|
6104
|
+
unsubscribe = feed?.values.subscribe(refresh);
|
|
6105
|
+
previous?.close();
|
|
6106
|
+
refresh();
|
|
6107
|
+
};
|
|
6108
|
+
return {
|
|
6109
|
+
series: {
|
|
6110
|
+
subscribe: (listener) => series.subscribe(listener),
|
|
6111
|
+
get() {
|
|
6112
|
+
const target = client.session.currentTarget();
|
|
6113
|
+
if (target?.instance !== historyTarget?.instance || target?.session !== historyTarget?.session)
|
|
6114
|
+
return series.get().map(({ ref }) => ({ ref, points: [] }));
|
|
6115
|
+
return series.get();
|
|
6116
|
+
}
|
|
6117
|
+
},
|
|
6118
|
+
setSignals,
|
|
6119
|
+
close() {
|
|
6120
|
+
if (closed) return;
|
|
6121
|
+
closed = true;
|
|
6122
|
+
unsubscribe?.();
|
|
6123
|
+
active?.close();
|
|
6124
|
+
active = null;
|
|
6125
|
+
series.set([]);
|
|
6126
|
+
}
|
|
6127
|
+
};
|
|
6128
|
+
}
|
|
6129
|
+
|
|
6130
|
+
// ../client/src/variable-editor.ts
|
|
6131
|
+
var READBACK_MS = 500;
|
|
6132
|
+
function createVariableEditor(front, ref) {
|
|
6133
|
+
const client = front.low;
|
|
6134
|
+
const variable = front.variable(ref);
|
|
6135
|
+
const binding = client.variables.bind({ ...ref }, { visible: false });
|
|
6136
|
+
let requested = null;
|
|
6137
|
+
let awaiting = null;
|
|
6138
|
+
let timer;
|
|
6139
|
+
let target = client.session.currentTarget();
|
|
6140
|
+
let closed = false;
|
|
6141
|
+
let stopReading;
|
|
6142
|
+
let infoSource;
|
|
6143
|
+
let info;
|
|
6144
|
+
const read2 = (bound = binding.state.get()) => {
|
|
6145
|
+
const view = variable.get();
|
|
6146
|
+
if (bound.info !== infoSource) {
|
|
6147
|
+
infoSource = bound.info;
|
|
6148
|
+
info = infoSource && {
|
|
6149
|
+
...infoSource,
|
|
6150
|
+
enum: infoSource.enum?.map((item) => ({ ...item })) ?? null
|
|
6151
|
+
};
|
|
6152
|
+
}
|
|
6153
|
+
const waiting = bound.pending !== null || view.writing || awaiting !== null;
|
|
6154
|
+
const current = client.session.currentTarget();
|
|
6155
|
+
return {
|
|
6156
|
+
info,
|
|
6157
|
+
view,
|
|
6158
|
+
shown: bound.pending ?? view.value,
|
|
6159
|
+
waiting,
|
|
6160
|
+
canWrite: !closed && client.session.ready.get() && current !== null && current.session === client.variables.state.get().session && view.can_write && bound.block === null && !waiting
|
|
6161
|
+
};
|
|
6162
|
+
};
|
|
6163
|
+
const state = new Writable(read2(), Object.is, clientErrorSink(client));
|
|
6164
|
+
const reset = () => {
|
|
6165
|
+
clearTimeout(timer);
|
|
6166
|
+
timer = void 0;
|
|
6167
|
+
requested = null;
|
|
6168
|
+
awaiting = null;
|
|
6169
|
+
};
|
|
6170
|
+
const refresh = () => {
|
|
6171
|
+
if (closed) return;
|
|
6172
|
+
const current = client.session.currentTarget();
|
|
6173
|
+
const bound = binding.state.get();
|
|
6174
|
+
const shown = read2(bound);
|
|
6175
|
+
if (closed) return;
|
|
6176
|
+
if (current?.instance !== target?.instance || current?.session !== target?.session || !shown.view.can_write) {
|
|
6177
|
+
reset();
|
|
6178
|
+
} else if (awaiting !== null && shown.view.value === awaiting) {
|
|
6179
|
+
reset();
|
|
6180
|
+
} else if (requested !== null && bound.writeStatus.kind === "applied") {
|
|
6181
|
+
if (shown.view.value !== requested) {
|
|
6182
|
+
awaiting = requested;
|
|
6183
|
+
timer = setTimeout(() => {
|
|
6184
|
+
reset();
|
|
6185
|
+
state.set(read2());
|
|
6186
|
+
}, READBACK_MS);
|
|
6187
|
+
}
|
|
6188
|
+
requested = null;
|
|
6189
|
+
} else if ("message" in bound.writeStatus) {
|
|
6190
|
+
reset();
|
|
6191
|
+
}
|
|
6192
|
+
target = current;
|
|
6193
|
+
state.set(read2());
|
|
6194
|
+
};
|
|
6195
|
+
const unsubscribe = binding.state.subscribe(refresh);
|
|
6196
|
+
const unsubscribeSession = client.session.session.subscribe(refresh);
|
|
6197
|
+
const unsubscribeReady = client.session.ready.subscribe(refresh);
|
|
6198
|
+
return {
|
|
6199
|
+
state: state.readonly(),
|
|
6200
|
+
write(value) {
|
|
6201
|
+
const { canWrite, info: info2 } = read2();
|
|
6202
|
+
if (!canWrite || !info2) return false;
|
|
6203
|
+
const valid = typeof value === "boolean" ? info2.type === "bool" : typeof value === "string" ? info2.type === "enum" && info2.enum?.some((item) => item.name === value) : Number.isFinite(value) && (info2.type === "real" || info2.type === "integer" && Number.isInteger(value) || info2.type === "enum" && info2.enum?.some((item) => item.value === value)) && (info2.min === null || value >= info2.min) && (info2.max === null || value <= info2.max);
|
|
6204
|
+
if (!valid) {
|
|
6205
|
+
binding.reject("the edit does not match the variable type or range");
|
|
6206
|
+
return false;
|
|
6207
|
+
}
|
|
6208
|
+
requested = typeof value === "boolean" ? value : null;
|
|
6209
|
+
binding.write(value);
|
|
6210
|
+
return true;
|
|
6211
|
+
},
|
|
6212
|
+
setVisible(visible) {
|
|
6213
|
+
if (closed || visible === !!stopReading) return;
|
|
6214
|
+
if (visible) {
|
|
6215
|
+
stopReading = variable.subscribe(refresh);
|
|
6216
|
+
} else {
|
|
6217
|
+
const stop = stopReading;
|
|
6218
|
+
stopReading = void 0;
|
|
6219
|
+
stop?.();
|
|
6220
|
+
}
|
|
6221
|
+
refresh();
|
|
6222
|
+
},
|
|
6223
|
+
close() {
|
|
6224
|
+
if (closed) return;
|
|
6225
|
+
closed = true;
|
|
6226
|
+
unsubscribe();
|
|
6227
|
+
unsubscribeSession();
|
|
6228
|
+
unsubscribeReady();
|
|
6229
|
+
stopReading?.();
|
|
6230
|
+
reset();
|
|
6231
|
+
binding.close();
|
|
6232
|
+
state.set(read2());
|
|
6233
|
+
}
|
|
6234
|
+
};
|
|
6235
|
+
}
|
|
3633
6236
|
export {
|
|
3634
6237
|
ANSWER_TIMEOUT_MS,
|
|
6238
|
+
ActionError,
|
|
3635
6239
|
BATCH_MS,
|
|
3636
6240
|
DEFAULT_LIMITS,
|
|
3637
6241
|
DEFAULT_TIMEOUT_MS,
|
|
3638
6242
|
DROPPED_MESSAGE,
|
|
3639
|
-
FEATURE_MANUAL,
|
|
3640
|
-
FEATURE_SCENARIO,
|
|
3641
|
-
FEATURE_SCENARIO_CONTROL,
|
|
3642
|
-
FEATURE_SPEED,
|
|
3643
|
-
FEATURE_START_PAUSED,
|
|
3644
|
-
FEATURE_TIME_COMMANDS,
|
|
3645
6243
|
HISTORY_MAX,
|
|
3646
6244
|
HISTORY_TOTAL_MAX,
|
|
3647
6245
|
HttpError,
|
|
@@ -3655,19 +6253,29 @@ export {
|
|
|
3655
6253
|
WATCH_PERIOD_MS,
|
|
3656
6254
|
WRITE_TIMEOUT_MS,
|
|
3657
6255
|
WriteError,
|
|
6256
|
+
connect,
|
|
3658
6257
|
createClient,
|
|
6258
|
+
createFront,
|
|
6259
|
+
createVariableEditor,
|
|
6260
|
+
createWaveforms,
|
|
3659
6261
|
errorMessage,
|
|
3660
6262
|
fetchTransport,
|
|
3661
6263
|
hasRange,
|
|
6264
|
+
isHolding,
|
|
3662
6265
|
isWriteError,
|
|
6266
|
+
launcherAnswer,
|
|
3663
6267
|
phaseIndex,
|
|
3664
6268
|
readAppInfo,
|
|
3665
6269
|
readCheckResponse,
|
|
3666
6270
|
readConfigList,
|
|
6271
|
+
readConfigText,
|
|
6272
|
+
readConnections,
|
|
3667
6273
|
readDashboardResponse,
|
|
3668
6274
|
readRecording,
|
|
6275
|
+
readSavedConfig,
|
|
3669
6276
|
readScenarioList,
|
|
3670
6277
|
readServerMessage,
|
|
6278
|
+
readSessionAllowed,
|
|
3671
6279
|
readSessionResponse,
|
|
3672
6280
|
readTimeResponse,
|
|
3673
6281
|
readVariablesSummary,
|
|
@@ -3675,7 +6283,9 @@ export {
|
|
|
3675
6283
|
runOutcome,
|
|
3676
6284
|
severityRank,
|
|
3677
6285
|
takeToken,
|
|
6286
|
+
until,
|
|
3678
6287
|
valueCondition,
|
|
6288
|
+
watch,
|
|
3679
6289
|
webSocketFactory,
|
|
3680
6290
|
writeBlock
|
|
3681
6291
|
};
|