@vehicle-sil/gui-client 0.1.0 → 0.2.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +384 -92
- package/README.md +375 -85
- package/dist/elements.js +872 -0
- package/dist/index.js +1806 -133
- package/package.json +20 -2
- package/timeline/vehicle-sil-timeline.d.ts +108 -0
- package/timeline/vehicle-sil-timeline.js +4391 -0
- package/timeline/vehicle-sil-timeline.mjs +4393 -0
- package/types/client.d.ts +41 -5
- 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 +122 -0
- package/types/front-compose.d.ts +61 -0
- package/types/front-outside.d.ts +19 -0
- package/types/front-types.d.ts +353 -0
- package/types/front-variable.d.ts +28 -0
- package/types/front.d.ts +50 -0
- package/types/index.d.ts +9 -5
- package/types/protocol/launcher.d.ts +578 -0
- package/types/protocol/read.d.ts +72 -0
- package/types/protocol/server.d.ts +758 -0
- package/types/protocol.d.ts +10 -972
- package/types/session-state.d.ts +44 -10
- package/types/session.d.ts +13 -1
- package/types/time.d.ts +16 -45
- package/types/variable-binding.d.ts +19 -5
- package/types/variable-state.d.ts +12 -6
- package/types/variables.d.ts +21 -1
package/dist/index.js
CHANGED
|
@@ -73,14 +73,14 @@ function webSocketFactory(options = {}) {
|
|
|
73
73
|
try {
|
|
74
74
|
socket = options.origin ? new WebSocketClass(url, { headers: { Origin: options.origin } }) : new WebSocketClass(url);
|
|
75
75
|
} catch (error) {
|
|
76
|
-
const
|
|
77
|
-
setTimeout(() => on.close(NOT_OPENED,
|
|
76
|
+
const reason2 = `cannot open the WebSocket: ${error instanceof Error ? error.message : String(error)}`;
|
|
77
|
+
setTimeout(() => on.close(NOT_OPENED, reason2), 0);
|
|
78
78
|
return { send: () => void 0, close: () => void 0 };
|
|
79
79
|
}
|
|
80
80
|
socket.onopen = () => on.open();
|
|
81
81
|
socket.onmessage = (event) => on.message(typeof event.data === "string" ? event.data : String(event.data));
|
|
82
82
|
socket.onclose = (event) => on.close(event.code ?? 0, event.reason ?? "");
|
|
83
|
-
return { send: (
|
|
83
|
+
return { send: (text3) => socket.send(text3), close: () => socket.close() };
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
86
|
function backoffMs(attempt, maxMs = 5e3) {
|
|
@@ -246,13 +246,13 @@ var Connection = class {
|
|
|
246
246
|
this.onError(error);
|
|
247
247
|
}
|
|
248
248
|
},
|
|
249
|
-
message: (
|
|
249
|
+
message: (text3) => {
|
|
250
250
|
if (!current()) return;
|
|
251
251
|
let message;
|
|
252
252
|
try {
|
|
253
|
-
message = JSON.parse(
|
|
253
|
+
message = JSON.parse(text3);
|
|
254
254
|
} catch {
|
|
255
|
-
callEach(this.unreadableListeners, [
|
|
255
|
+
callEach(this.unreadableListeners, [text3], this.onError);
|
|
256
256
|
this.restartAfter(backoffMs(++this.garbled, this.options.maxBackoffMs));
|
|
257
257
|
return;
|
|
258
258
|
}
|
|
@@ -261,12 +261,12 @@ var Connection = class {
|
|
|
261
261
|
this.pending.push(message);
|
|
262
262
|
this.batchTimer ??= setTimeout(() => this.flush(), this.options.batchMs ?? BATCH_MS);
|
|
263
263
|
},
|
|
264
|
-
close: (code,
|
|
264
|
+
close: (code, reason2) => {
|
|
265
265
|
if (!current()) return;
|
|
266
266
|
this.socket = null;
|
|
267
267
|
clearTimeout(this.steadyTimer);
|
|
268
268
|
if (!opened) this.failureCount.update((n) => n + 1);
|
|
269
|
-
this.lastCloseValue.set({ code, reason });
|
|
269
|
+
this.lastCloseValue.set({ code, reason: reason2 });
|
|
270
270
|
this.stateValue.set("closed");
|
|
271
271
|
this.scheduleRetry(backoffMs(++this.attempts, this.options.maxBackoffMs));
|
|
272
272
|
}
|
|
@@ -283,7 +283,7 @@ var Connection = class {
|
|
|
283
283
|
}
|
|
284
284
|
};
|
|
285
285
|
|
|
286
|
-
// ../client/src/protocol.ts
|
|
286
|
+
// ../client/src/protocol/read.ts
|
|
287
287
|
var ProtocolError = class extends Error {
|
|
288
288
|
constructor(path, expected) {
|
|
289
289
|
super(`${path}: expected ${expected}`);
|
|
@@ -294,7 +294,6 @@ var ProtocolError = class extends Error {
|
|
|
294
294
|
path;
|
|
295
295
|
expected;
|
|
296
296
|
};
|
|
297
|
-
var PROTOCOL_VERSION = 1;
|
|
298
297
|
function object(value, path) {
|
|
299
298
|
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
300
299
|
throw new ProtocolError(path, "an object");
|
|
@@ -391,12 +390,29 @@ function version(fields, path, key, expected, u) {
|
|
|
391
390
|
u.add(error.path);
|
|
392
391
|
}
|
|
393
392
|
}
|
|
393
|
+
function record(read2) {
|
|
394
|
+
return (value, path) => Object.fromEntries(
|
|
395
|
+
Object.entries(object(value, path)).map(([key, item]) => [key, read2(item, `${path}.${key}`)])
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
function withRaw(raw, read2) {
|
|
399
|
+
Object.defineProperty(read2, "raw", {
|
|
400
|
+
value: raw,
|
|
401
|
+
enumerable: false,
|
|
402
|
+
writable: false,
|
|
403
|
+
configurable: false
|
|
404
|
+
});
|
|
405
|
+
return read2;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// ../client/src/protocol/launcher.ts
|
|
409
|
+
var readSpeed = (value, path) => value === null || value === "max" ? value : number(value, path);
|
|
394
410
|
function severityRank(severity) {
|
|
395
411
|
return severity === "note" ? 2 : severity === "warning" ? 1 : 0;
|
|
396
412
|
}
|
|
397
413
|
var readFinding = (value, path, u) => {
|
|
398
414
|
const f = object(value, path);
|
|
399
|
-
return {
|
|
415
|
+
return withRaw(f, {
|
|
400
416
|
severity: field(f, path, "severity", string),
|
|
401
417
|
code: field(f, path, "code", lenient(string, "", u)),
|
|
402
418
|
file: field(f, path, "file", soft(nullable(string), null, u)),
|
|
@@ -405,11 +421,11 @@ var readFinding = (value, path, u) => {
|
|
|
405
421
|
network: field(f, path, "network", soft(nullable(string), null, u)),
|
|
406
422
|
message: field(f, path, "message", string),
|
|
407
423
|
detail: field(f, path, "detail", soft(nullable(string), null, u))
|
|
408
|
-
};
|
|
424
|
+
});
|
|
409
425
|
};
|
|
410
426
|
var readVariable = (value, path) => {
|
|
411
427
|
const f = object(value, path);
|
|
412
|
-
return {
|
|
428
|
+
return withRaw(f, {
|
|
413
429
|
name: field(f, path, "name", string),
|
|
414
430
|
type: field(f, path, "type", string),
|
|
415
431
|
causality: field(f, path, "causality", string),
|
|
@@ -417,12 +433,9 @@ var readVariable = (value, path) => {
|
|
|
417
433
|
min: field(f, path, "min", optional(nullable(number), null)),
|
|
418
434
|
max: field(f, path, "max", optional(nullable(number), null)),
|
|
419
435
|
builtin: field(f, path, "builtin", optional(nullable(boolean), null))
|
|
420
|
-
};
|
|
436
|
+
});
|
|
421
437
|
};
|
|
422
|
-
var
|
|
423
|
-
var FEATURE_SCENARIO_CONTROL = "scenario-control";
|
|
424
|
-
var FEATURE_MANUAL = "manual-participants";
|
|
425
|
-
var readScenarioStepFields = (f, path, u) => ({
|
|
438
|
+
var readScenarioStepFields = (f, path, u) => withRaw(f, {
|
|
426
439
|
index: field(f, path, "index", integer),
|
|
427
440
|
line: field(f, path, "line", soft(nullable(integer), null, u)),
|
|
428
441
|
kind: field(f, path, "kind", lenient(string, "", u)),
|
|
@@ -437,15 +450,15 @@ var readScenarioStepFields = (f, path, u) => ({
|
|
|
437
450
|
var readScenarioStep = (value, path, u) => readScenarioStepFields(object(value, path), path, u);
|
|
438
451
|
var readCheckScenario = (value, path, u) => {
|
|
439
452
|
const f = object(value, path);
|
|
440
|
-
return {
|
|
453
|
+
return withRaw(f, {
|
|
441
454
|
file: field(f, path, "file", lenient(string, "", u)),
|
|
442
455
|
name: field(f, path, "name", soft(nullable(string), null, u)),
|
|
443
456
|
steps: field(f, path, "steps", lenient(integer, 0, u))
|
|
444
|
-
};
|
|
457
|
+
});
|
|
445
458
|
};
|
|
446
459
|
var readScenarioResult = (value, path, u) => {
|
|
447
460
|
const f = object(value, path);
|
|
448
|
-
return {
|
|
461
|
+
return withRaw(f, {
|
|
449
462
|
file: field(f, path, "file", lenient(string, "", u)),
|
|
450
463
|
name: field(f, path, "name", soft(nullable(string), null, u)),
|
|
451
464
|
status: field(f, path, "status", lenient(string, "", u)),
|
|
@@ -456,11 +469,11 @@ var readScenarioResult = (value, path, u) => {
|
|
|
456
469
|
"steps",
|
|
457
470
|
items((v, p) => readScenarioStep(v, p, u), u)
|
|
458
471
|
)
|
|
459
|
-
};
|
|
472
|
+
});
|
|
460
473
|
};
|
|
461
474
|
var readCheckParticipant = (value, path, u) => {
|
|
462
475
|
const f = object(value, path);
|
|
463
|
-
return {
|
|
476
|
+
return withRaw(f, {
|
|
464
477
|
name: field(f, path, "name", nullable(string)),
|
|
465
478
|
line: field(f, path, "line", soft(nullable(integer), null, u)),
|
|
466
479
|
required: field(f, path, "required", lenient(nullable(boolean), null, u)),
|
|
@@ -483,21 +496,22 @@ var readCheckParticipant = (value, path, u) => {
|
|
|
483
496
|
null,
|
|
484
497
|
u
|
|
485
498
|
)
|
|
486
|
-
)
|
|
487
|
-
|
|
499
|
+
),
|
|
500
|
+
role: field(f, path, "role", soft(nullable(string), null, u))
|
|
501
|
+
});
|
|
488
502
|
};
|
|
489
503
|
var readCheckNetwork = (value, path, u) => {
|
|
490
504
|
const f = object(value, path);
|
|
491
|
-
return {
|
|
505
|
+
return withRaw(f, {
|
|
492
506
|
name: field(f, path, "name", lenient(nullable(string), null, u)),
|
|
493
507
|
kind: field(f, path, "kind", lenient(nullable(string), null, u)),
|
|
494
508
|
participants: field(f, path, "participants", items(string, u))
|
|
495
|
-
};
|
|
509
|
+
});
|
|
496
510
|
};
|
|
497
511
|
var readCheckResult = (value, path, u) => {
|
|
498
512
|
const f = object(value, path);
|
|
499
513
|
version(f, path, "vehicle_sil_check", 1, u);
|
|
500
|
-
return {
|
|
514
|
+
return withRaw(f, {
|
|
501
515
|
file: field(f, path, "file", soft(nullable(string), null, u)),
|
|
502
516
|
result: field(f, path, "result", lenient(string, "", u)),
|
|
503
517
|
errors: field(f, path, "errors", lenient(integer, 0, u)),
|
|
@@ -532,7 +546,7 @@ var readCheckResult = (value, path, u) => {
|
|
|
532
546
|
u
|
|
533
547
|
)
|
|
534
548
|
)
|
|
535
|
-
};
|
|
549
|
+
});
|
|
536
550
|
};
|
|
537
551
|
var CONTROL_EVENT = "control_link";
|
|
538
552
|
var CONTROL_RESULT_KEY = "control_link";
|
|
@@ -540,23 +554,24 @@ var CONTROL_SUMMARY_KEY = "control_link";
|
|
|
540
554
|
var CONTROL_CHECK_KEY = "control";
|
|
541
555
|
var readControlOffer = (value, path, u) => {
|
|
542
556
|
const f = object(value, path);
|
|
543
|
-
return {
|
|
557
|
+
return withRaw(f, {
|
|
544
558
|
transport: field(f, path, "transport", lenient(string, "", u)),
|
|
545
|
-
wire_version: field(f, path, "wire_version", soft(nullable(integer), null, u))
|
|
546
|
-
|
|
559
|
+
wire_version: field(f, path, "wire_version", soft(nullable(integer), null, u)),
|
|
560
|
+
wire_revision: field(f, path, "wire_revision", soft(nullable(integer), null, u))
|
|
561
|
+
});
|
|
547
562
|
};
|
|
548
563
|
var readControlLink = (value, path, u) => {
|
|
549
564
|
const f = object(value, path);
|
|
550
|
-
return {
|
|
565
|
+
return withRaw(f, {
|
|
551
566
|
state: field(f, path, "state", string),
|
|
552
567
|
variables: field(f, path, "variables", soft(nullable(integer), null, u)),
|
|
553
568
|
version: field(f, path, "version", soft(nullable(integer), null, u)),
|
|
554
569
|
late_messages: field(f, path, "late_messages", soft(nullable(integer), null, u))
|
|
555
|
-
};
|
|
570
|
+
});
|
|
556
571
|
};
|
|
557
572
|
var readRunParticipant = (value, path, u) => {
|
|
558
573
|
const f = object(value, path);
|
|
559
|
-
return {
|
|
574
|
+
return withRaw(f, {
|
|
560
575
|
name: field(f, path, "name", string),
|
|
561
576
|
required: field(f, path, "required", lenient(boolean, true, u)),
|
|
562
577
|
enabled: field(f, path, "enabled", lenient(boolean, true, u)),
|
|
@@ -574,13 +589,14 @@ var readRunParticipant = (value, path, u) => {
|
|
|
574
589
|
null,
|
|
575
590
|
u
|
|
576
591
|
)
|
|
577
|
-
)
|
|
578
|
-
|
|
592
|
+
),
|
|
593
|
+
log: field(f, path, "log", soft(nullable(string), null, u))
|
|
594
|
+
});
|
|
579
595
|
};
|
|
580
596
|
var readRunTiming = (value, path, u) => {
|
|
581
597
|
const f = object(value, path);
|
|
582
598
|
const count2 = (key) => field(f, path, key, soft(nullable(number), null, u));
|
|
583
|
-
return {
|
|
599
|
+
return withRaw(f, {
|
|
584
600
|
speed: field(f, path, "speed", soft(readSpeed, null, u)),
|
|
585
601
|
time_step_ms: count2("time_step_ms"),
|
|
586
602
|
ecu_step_ms: count2("ecu_step_ms"),
|
|
@@ -595,14 +611,77 @@ var readRunTiming = (value, path, u) => {
|
|
|
595
611
|
slipped_ms: count2("slipped_ms"),
|
|
596
612
|
late_ms: count2("late_ms"),
|
|
597
613
|
paused_ms: count2("paused_ms")
|
|
598
|
-
};
|
|
614
|
+
});
|
|
615
|
+
};
|
|
616
|
+
var readTrafficUnplaced = (value, path, u) => {
|
|
617
|
+
const f = object(value, path);
|
|
618
|
+
return withRaw(f, {
|
|
619
|
+
participant: field(f, path, "participant", string),
|
|
620
|
+
reason: field(f, path, "reason", lenient(string, "", u))
|
|
621
|
+
});
|
|
622
|
+
};
|
|
623
|
+
var readTrafficParticipant = (value, path, u) => {
|
|
624
|
+
const f = object(value, path);
|
|
625
|
+
return withRaw(f, {
|
|
626
|
+
name: field(f, path, "name", string),
|
|
627
|
+
counted: field(f, path, "counted", lenient(boolean, false, u)),
|
|
628
|
+
not_counted: field(f, path, "not_counted", soft(nullable(string), null, u)),
|
|
629
|
+
virtual_time: field(f, path, "virtual_time", soft(nullable(boolean), null, u)),
|
|
630
|
+
at_ms: field(f, path, "at_ms", soft(nullable(number), null, u)),
|
|
631
|
+
frames_sent: field(f, path, "frames_sent", soft(nullable(integer), null, u)),
|
|
632
|
+
frames_received: field(f, path, "frames_received", soft(nullable(integer), null, u))
|
|
633
|
+
});
|
|
634
|
+
};
|
|
635
|
+
var readTrafficNetwork = (value, path, u) => {
|
|
636
|
+
const f = object(value, path);
|
|
637
|
+
return withRaw(f, {
|
|
638
|
+
name: field(f, path, "name", string),
|
|
639
|
+
kind: field(f, path, "kind", soft(nullable(string), null, u)),
|
|
640
|
+
counted: field(f, path, "counted", lenient(integer, 0, u)),
|
|
641
|
+
senders: field(f, path, "senders", lenient(integer, 0, u)),
|
|
642
|
+
receivers: field(f, path, "receivers", lenient(integer, 0, u)),
|
|
643
|
+
delivered: field(f, path, "delivered", soft(nullable(boolean), null, u)),
|
|
644
|
+
unplaced: field(
|
|
645
|
+
f,
|
|
646
|
+
path,
|
|
647
|
+
"unplaced",
|
|
648
|
+
items((v, p) => readTrafficUnplaced(v, p, u), u)
|
|
649
|
+
),
|
|
650
|
+
participants: field(
|
|
651
|
+
f,
|
|
652
|
+
path,
|
|
653
|
+
"participants",
|
|
654
|
+
items((v, p) => readTrafficParticipant(v, p, u), u)
|
|
655
|
+
)
|
|
656
|
+
});
|
|
657
|
+
};
|
|
658
|
+
var readRunTraffic = (value, path, u) => {
|
|
659
|
+
const f = object(value, path);
|
|
660
|
+
return withRaw(f, {
|
|
661
|
+
before_ms: field(f, path, "before_ms", soft(nullable(number), null, u)),
|
|
662
|
+
unplaced: field(
|
|
663
|
+
f,
|
|
664
|
+
path,
|
|
665
|
+
"unplaced",
|
|
666
|
+
items((v, p) => readTrafficUnplaced(v, p, u), u)
|
|
667
|
+
),
|
|
668
|
+
networks: field(
|
|
669
|
+
f,
|
|
670
|
+
path,
|
|
671
|
+
"networks",
|
|
672
|
+
items((v, p) => readTrafficNetwork(v, p, u), u)
|
|
673
|
+
)
|
|
674
|
+
});
|
|
599
675
|
};
|
|
600
676
|
var readRunResult = (value, path, u) => {
|
|
601
677
|
const f = object(value, path);
|
|
602
|
-
version(f, path, "vehicle_sil_run",
|
|
603
|
-
return {
|
|
678
|
+
version(f, path, "vehicle_sil_run", 2, u);
|
|
679
|
+
return withRaw(f, {
|
|
604
680
|
file: field(f, path, "file", soft(nullable(string), null, u)),
|
|
605
681
|
result: field(f, path, "result", lenient(string, "", u)),
|
|
682
|
+
end: field(f, path, "end", soft(nullable(string), null, u)),
|
|
683
|
+
ok: field(f, path, "ok", lenient(boolean, false, u)),
|
|
684
|
+
message: field(f, path, "message", lenient(string, "", u)),
|
|
606
685
|
errors: field(f, path, "errors", lenient(integer, 0, u)),
|
|
607
686
|
warnings: field(f, path, "warnings", lenient(integer, 0, u)),
|
|
608
687
|
notes: field(f, path, "notes", lenient(integer, 0, u)),
|
|
@@ -649,16 +728,24 @@ var readRunResult = (value, path, u) => {
|
|
|
649
728
|
null,
|
|
650
729
|
u
|
|
651
730
|
)
|
|
731
|
+
),
|
|
732
|
+
traffic: field(
|
|
733
|
+
f,
|
|
734
|
+
path,
|
|
735
|
+
"traffic",
|
|
736
|
+
soft(
|
|
737
|
+
nullable((v, p) => readRunTraffic(v, p, u)),
|
|
738
|
+
null,
|
|
739
|
+
u
|
|
740
|
+
)
|
|
652
741
|
)
|
|
653
|
-
};
|
|
742
|
+
});
|
|
654
743
|
};
|
|
655
744
|
var PHASES = ["checking", "starting", "waiting", "running", "stopping", "ended"];
|
|
656
745
|
function readTimeFields(f, path, u) {
|
|
657
746
|
const count2 = (key) => field(f, path, key, soft(nullable(number), null, u));
|
|
658
747
|
return {
|
|
659
748
|
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
749
|
actual_speed: count2("actual_speed"),
|
|
663
750
|
late_steps: count2("late_steps"),
|
|
664
751
|
max_late_ms: count2("max_late_ms"),
|
|
@@ -672,7 +759,75 @@ function readCommandFields(f, path, u) {
|
|
|
672
759
|
source: field(f, path, "source", soft(string, "stdin", u)),
|
|
673
760
|
accepted: field(f, path, "accepted", boolean),
|
|
674
761
|
message: field(f, path, "message", soft(nullable(string), null, u)),
|
|
675
|
-
ms: field(f, path, "ms", soft(nullable(integer), null, u))
|
|
762
|
+
ms: field(f, path, "ms", soft(nullable(integer), null, u)),
|
|
763
|
+
reason: field(f, path, "reason", soft(nullable(string), null, u)),
|
|
764
|
+
id: field(f, path, "id", soft(nullable(integer), null, u)),
|
|
765
|
+
at_ms: field(f, path, "at_ms", soft(nullable(number), null, u))
|
|
766
|
+
};
|
|
767
|
+
}
|
|
768
|
+
var readCaution = (value, path) => {
|
|
769
|
+
const c = object(value, path);
|
|
770
|
+
return { code: field(c, path, "code", string), message: field(c, path, "message", string) };
|
|
771
|
+
};
|
|
772
|
+
var readLauncherAllowedItem = (value, path) => {
|
|
773
|
+
const f = object(value, path);
|
|
774
|
+
return withRaw(f, {
|
|
775
|
+
ok: field(f, path, "ok", boolean),
|
|
776
|
+
reason: field(f, path, "reason", soft(nullable(string), null)),
|
|
777
|
+
message: field(f, path, "message", soft(nullable(string), null)),
|
|
778
|
+
caution: field(f, path, "caution", soft(nullable(readCaution), null))
|
|
779
|
+
});
|
|
780
|
+
};
|
|
781
|
+
var readOutsideState = (value, path, u) => {
|
|
782
|
+
const f = object(value, path);
|
|
783
|
+
return withRaw(f, {
|
|
784
|
+
network: field(f, path, "network", string),
|
|
785
|
+
target: field(f, path, "target", soft(nullable(string), null, u)),
|
|
786
|
+
participant: field(f, path, "participant", soft(nullable(string), null, u)),
|
|
787
|
+
link: field(f, path, "link", soft(nullable(string), null, u)),
|
|
788
|
+
bus: field(f, path, "bus", soft(nullable(string), null, u)),
|
|
789
|
+
nothing_received: field(f, path, "nothing_received", soft(boolean, false, u)),
|
|
790
|
+
condition: field(f, path, "condition", lenient(string, "", u)),
|
|
791
|
+
reasons: field(f, path, "reasons", soft(items(string, u), [], u))
|
|
792
|
+
});
|
|
793
|
+
};
|
|
794
|
+
function readStateFields(f, path, u) {
|
|
795
|
+
return {
|
|
796
|
+
rev: field(f, path, "rev", integer),
|
|
797
|
+
phase: field(f, path, "phase", lenient(string, "", u)),
|
|
798
|
+
paused: field(f, path, "paused", soft(nullable(boolean), null, u)),
|
|
799
|
+
paused_at_ms: field(f, path, "paused_at_ms", soft(nullable(number), null, u)),
|
|
800
|
+
holding: field(f, path, "holding", soft(nullable(boolean), null, u)),
|
|
801
|
+
speed: field(f, path, "speed", soft(readSpeed, null, u)),
|
|
802
|
+
pacing: field(f, path, "pacing", soft(nullable(string), null, u)),
|
|
803
|
+
stop: field(
|
|
804
|
+
f,
|
|
805
|
+
path,
|
|
806
|
+
"stop",
|
|
807
|
+
soft(
|
|
808
|
+
nullable((v, p) => {
|
|
809
|
+
const s = object(v, p);
|
|
810
|
+
return {
|
|
811
|
+
requests: field(s, p, "requests", integer),
|
|
812
|
+
by: field(s, p, "by", nullable(string))
|
|
813
|
+
};
|
|
814
|
+
}),
|
|
815
|
+
null,
|
|
816
|
+
u
|
|
817
|
+
)
|
|
818
|
+
),
|
|
819
|
+
scenario: field(f, path, "scenario", soft(nullable(boolean), null, u)),
|
|
820
|
+
allowed: field(f, path, "allowed", lenient(record(readLauncherAllowedItem), {}, u)),
|
|
821
|
+
outside: field(
|
|
822
|
+
f,
|
|
823
|
+
path,
|
|
824
|
+
"outside",
|
|
825
|
+
soft(
|
|
826
|
+
items((v, p) => readOutsideState(v, p, u), u),
|
|
827
|
+
[],
|
|
828
|
+
u
|
|
829
|
+
)
|
|
830
|
+
)
|
|
676
831
|
};
|
|
677
832
|
}
|
|
678
833
|
var readLauncherEvent = (value, path, partly = false) => {
|
|
@@ -690,7 +845,7 @@ var readLauncherEvent = (value, path, partly = false) => {
|
|
|
690
845
|
u
|
|
691
846
|
);
|
|
692
847
|
if (event && u && u.parts.length > 0) event.unreadable = u.parts;
|
|
693
|
-
return event;
|
|
848
|
+
return event && withRaw(f, event);
|
|
694
849
|
};
|
|
695
850
|
function readEventFields(f, path, kind, base, u) {
|
|
696
851
|
switch (kind) {
|
|
@@ -761,6 +916,16 @@ function readEventFields(f, path, kind, base, u) {
|
|
|
761
916
|
return { ...base, event: kind, ...readTimeFields(f, path, u) };
|
|
762
917
|
case "command":
|
|
763
918
|
return { ...base, event: kind, ...readCommandFields(f, path, u) };
|
|
919
|
+
case "state":
|
|
920
|
+
return { ...base, event: kind, ...readStateFields(f, path, u) };
|
|
921
|
+
case "outside":
|
|
922
|
+
return {
|
|
923
|
+
...base,
|
|
924
|
+
event: kind,
|
|
925
|
+
network: field(f, path, "network", string),
|
|
926
|
+
to_outside: field(f, path, "to_outside", integer),
|
|
927
|
+
from_outside: field(f, path, "from_outside", integer)
|
|
928
|
+
};
|
|
764
929
|
case "scenario_step":
|
|
765
930
|
return { ...base, event: kind, step: readScenarioStepFields(f, path, u) };
|
|
766
931
|
case "result":
|
|
@@ -773,6 +938,9 @@ function readEventFields(f, path, kind, base, u) {
|
|
|
773
938
|
return null;
|
|
774
939
|
}
|
|
775
940
|
}
|
|
941
|
+
|
|
942
|
+
// ../client/src/protocol/server.ts
|
|
943
|
+
var PROTOCOL_VERSION = 2;
|
|
776
944
|
var readServerProblem = (value, path) => {
|
|
777
945
|
const f = object(value, path);
|
|
778
946
|
const problem = {
|
|
@@ -786,9 +954,21 @@ var readServerProblem = (value, path) => {
|
|
|
786
954
|
problem.skipped = skipped;
|
|
787
955
|
}
|
|
788
956
|
}
|
|
957
|
+
if (typeof detail === "object" && detail !== null && "findings" in detail) {
|
|
958
|
+
const list = detail.findings;
|
|
959
|
+
if (Array.isArray(list)) {
|
|
960
|
+
const findings = [];
|
|
961
|
+
list.forEach((item, i) => {
|
|
962
|
+
try {
|
|
963
|
+
findings.push(readFinding(item, `${path}.detail.findings[${i}]`));
|
|
964
|
+
} catch {
|
|
965
|
+
}
|
|
966
|
+
});
|
|
967
|
+
problem.findings = findings;
|
|
968
|
+
}
|
|
969
|
+
}
|
|
789
970
|
return problem;
|
|
790
971
|
};
|
|
791
|
-
var readSpeed = (value, path) => value === null || value === "max" ? value : number(value, path);
|
|
792
972
|
var readAppInfo = (value) => {
|
|
793
973
|
const path = "app";
|
|
794
974
|
const f = object(value, path);
|
|
@@ -841,6 +1021,16 @@ var readConfigList = (value) => {
|
|
|
841
1021
|
truncated: field(f, path, "truncated", boolean)
|
|
842
1022
|
};
|
|
843
1023
|
};
|
|
1024
|
+
var readConnections = (value) => {
|
|
1025
|
+
const path = "connections";
|
|
1026
|
+
const f = object(value, path);
|
|
1027
|
+
return {
|
|
1028
|
+
file: field(f, path, "file", string),
|
|
1029
|
+
network: field(f, path, "network", string),
|
|
1030
|
+
exit_code: field(f, path, "exit_code", integer),
|
|
1031
|
+
connections: field(f, path, "connections", object)
|
|
1032
|
+
};
|
|
1033
|
+
};
|
|
844
1034
|
var readScenarioList = (value) => {
|
|
845
1035
|
const path = "scenarios";
|
|
846
1036
|
const f = object(value, path);
|
|
@@ -876,6 +1066,23 @@ var readRecording = (value) => {
|
|
|
876
1066
|
yaml: field(r, path, "yaml", nullable(string))
|
|
877
1067
|
};
|
|
878
1068
|
};
|
|
1069
|
+
var readConfigText = (value) => {
|
|
1070
|
+
const path = "config";
|
|
1071
|
+
const f = object(value, path);
|
|
1072
|
+
return {
|
|
1073
|
+
file: field(f, path, "file", string),
|
|
1074
|
+
text: field(f, path, "text", string),
|
|
1075
|
+
stamp: field(f, path, "stamp", string)
|
|
1076
|
+
};
|
|
1077
|
+
};
|
|
1078
|
+
var readSavedConfig = (value) => {
|
|
1079
|
+
const path = "saved";
|
|
1080
|
+
const f = object(value, path);
|
|
1081
|
+
return {
|
|
1082
|
+
file: field(f, path, "file", string),
|
|
1083
|
+
stamp: field(f, path, "stamp", string)
|
|
1084
|
+
};
|
|
1085
|
+
};
|
|
879
1086
|
var readCheckResponse = (value) => field(object(value, "response"), "response", "check", readCheckResult);
|
|
880
1087
|
var readSummaryParticipant = (value, path, u) => {
|
|
881
1088
|
const f = object(value, path);
|
|
@@ -917,11 +1124,6 @@ var readLogCounts = (value, path) => {
|
|
|
917
1124
|
const f = object(value, path);
|
|
918
1125
|
return { kept: field(f, path, "kept", integer), dropped: field(f, path, "dropped", integer) };
|
|
919
1126
|
};
|
|
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
1127
|
var readSummaryScenario = (value, path, u) => {
|
|
926
1128
|
const f = object(value, path);
|
|
927
1129
|
return {
|
|
@@ -936,7 +1138,8 @@ var readSummaryScenario = (value, path, u) => {
|
|
|
936
1138
|
),
|
|
937
1139
|
steps_omitted: field(f, path, "steps_omitted", soft(integer, 0, u)),
|
|
938
1140
|
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))
|
|
1141
|
+
over_at_ms: field(f, path, "over_at_ms", soft(nullable(number), null, u)),
|
|
1142
|
+
timeline_url: field(f, path, "timeline_url", soft(nullable(string), null, u))
|
|
940
1143
|
};
|
|
941
1144
|
};
|
|
942
1145
|
var readSessionSummary = (value, path) => {
|
|
@@ -976,6 +1179,23 @@ var readSessionSummary = (value, path) => {
|
|
|
976
1179
|
u
|
|
977
1180
|
)
|
|
978
1181
|
),
|
|
1182
|
+
launcher_state: field(
|
|
1183
|
+
f,
|
|
1184
|
+
path,
|
|
1185
|
+
"launcher_state",
|
|
1186
|
+
soft(
|
|
1187
|
+
nullable((v, p) => {
|
|
1188
|
+
const s = object(v, p);
|
|
1189
|
+
return {
|
|
1190
|
+
...readStateFields(s, p, u),
|
|
1191
|
+
seq: field(s, p, "seq", soft(nullable(integer), null, u))
|
|
1192
|
+
};
|
|
1193
|
+
}),
|
|
1194
|
+
null,
|
|
1195
|
+
u
|
|
1196
|
+
)
|
|
1197
|
+
),
|
|
1198
|
+
allowed: field(f, path, "allowed", soft(nullable(readServerAllowed), null, u)),
|
|
979
1199
|
check: field(
|
|
980
1200
|
f,
|
|
981
1201
|
path,
|
|
@@ -1024,6 +1244,28 @@ var readSessionSummary = (value, path) => {
|
|
|
1024
1244
|
};
|
|
1025
1245
|
return { ...summary, unreadable: u.parts };
|
|
1026
1246
|
};
|
|
1247
|
+
var readServerAllowedItem = (value, path) => {
|
|
1248
|
+
const f = object(value, path);
|
|
1249
|
+
return {
|
|
1250
|
+
ok: field(f, path, "ok", boolean),
|
|
1251
|
+
reason: field(f, path, "reason", optional(nullable(string), null)),
|
|
1252
|
+
message: field(f, path, "message", optional(nullable(string), null))
|
|
1253
|
+
};
|
|
1254
|
+
};
|
|
1255
|
+
var readServerSaveItem = (value, path) => ({
|
|
1256
|
+
...readServerAllowedItem(value, path),
|
|
1257
|
+
caution: field(object(value, path), path, "caution", nullable(readCaution))
|
|
1258
|
+
});
|
|
1259
|
+
var readServerAllowed = (value, path) => {
|
|
1260
|
+
const f = object(value, path);
|
|
1261
|
+
return {
|
|
1262
|
+
rev: field(f, path, "rev", optional(integer, 0)),
|
|
1263
|
+
start: field(f, path, "start", readServerAllowedItem),
|
|
1264
|
+
stop: field(f, path, "stop", readServerAllowedItem),
|
|
1265
|
+
force: field(f, path, "force", readServerAllowedItem),
|
|
1266
|
+
save: field(f, path, "save", readServerSaveItem)
|
|
1267
|
+
};
|
|
1268
|
+
};
|
|
1027
1269
|
function partlyRecord(read2, u) {
|
|
1028
1270
|
return (value, path) => {
|
|
1029
1271
|
const out = {};
|
|
@@ -1035,15 +1277,23 @@ function partlyRecord(read2, u) {
|
|
|
1035
1277
|
};
|
|
1036
1278
|
}
|
|
1037
1279
|
var readSessionResponse = (value) => field(object(value, "response"), "response", "session", nullable(readSessionSummary));
|
|
1280
|
+
var readSessionAllowed = (value) => field(
|
|
1281
|
+
object(value, "response"),
|
|
1282
|
+
"response",
|
|
1283
|
+
"allowed",
|
|
1284
|
+
optional(nullable(readServerAllowed), null)
|
|
1285
|
+
);
|
|
1038
1286
|
var readTimeResponse = (value) => {
|
|
1039
1287
|
const path = "response";
|
|
1040
1288
|
const f = object(value, path);
|
|
1041
1289
|
const command = field(f, path, "command", object);
|
|
1042
1290
|
return {
|
|
1043
1291
|
session_id: field(f, path, "session_id", integer),
|
|
1044
|
-
command: field(command, `${path}.command`, "command", string)
|
|
1292
|
+
command: field(command, `${path}.command`, "command", string),
|
|
1293
|
+
id: field(command, `${path}.command`, "id", optional(nullable(integer), null))
|
|
1045
1294
|
};
|
|
1046
1295
|
};
|
|
1296
|
+
var readAvailability = (value) => value === "unknown" || value === "inactive" ? value : "active";
|
|
1047
1297
|
var readOperationReport = (value, path) => {
|
|
1048
1298
|
const f = object(value, path);
|
|
1049
1299
|
return {
|
|
@@ -1060,7 +1310,9 @@ var readOperationReport = (value, path) => {
|
|
|
1060
1310
|
state: field(t, p, "state", string),
|
|
1061
1311
|
applied_at_ms: field(t, p, "applied_at_ms", optional(nullable(number), null)),
|
|
1062
1312
|
late: field(t, p, "late", optional(boolean, false)),
|
|
1063
|
-
reason: field(t, p, "reason", optional(nullable(string), null))
|
|
1313
|
+
reason: field(t, p, "reason", optional(nullable(string), null)),
|
|
1314
|
+
applied_writes: field(t, p, "applied_writes", optional(nullable(integer), null)),
|
|
1315
|
+
failed_write: field(t, p, "failed_write", optional(nullable(integer), null))
|
|
1064
1316
|
};
|
|
1065
1317
|
})
|
|
1066
1318
|
)
|
|
@@ -1091,7 +1343,8 @@ var readVariableSummary = (value, path) => {
|
|
|
1091
1343
|
),
|
|
1092
1344
|
null
|
|
1093
1345
|
)
|
|
1094
|
-
)
|
|
1346
|
+
),
|
|
1347
|
+
availability: readAvailability(f["availability"])
|
|
1095
1348
|
};
|
|
1096
1349
|
};
|
|
1097
1350
|
var readVariablesSummary = (value) => readVariables(value, "variables");
|
|
@@ -1226,6 +1479,7 @@ var readServerMessage = (value) => {
|
|
|
1226
1479
|
type,
|
|
1227
1480
|
instance: field(f, path, "instance", string),
|
|
1228
1481
|
session: field(f, path, "session", nullable(readSessionSummary)),
|
|
1482
|
+
allowed: field(f, path, "allowed", optional(nullable(readServerAllowed), null)),
|
|
1229
1483
|
replay: field(f, path, "replay", nullable(readReplay))
|
|
1230
1484
|
};
|
|
1231
1485
|
case "event": {
|
|
@@ -1255,6 +1509,12 @@ var readServerMessage = (value) => {
|
|
|
1255
1509
|
at_least: field(f, path, "at_least", array(string)),
|
|
1256
1510
|
events: field(f, path, "events", integer)
|
|
1257
1511
|
};
|
|
1512
|
+
case "allowed":
|
|
1513
|
+
return {
|
|
1514
|
+
type,
|
|
1515
|
+
session: field(f, path, "session", nullable(integer)),
|
|
1516
|
+
allowed: field(f, path, "allowed", readServerAllowed)
|
|
1517
|
+
};
|
|
1258
1518
|
case "resync":
|
|
1259
1519
|
return { type, message: field(f, path, "message", optional(string, "")) };
|
|
1260
1520
|
case "variables":
|
|
@@ -1297,6 +1557,17 @@ var readServerMessage = (value) => {
|
|
|
1297
1557
|
session: field(f, path, "session", integer),
|
|
1298
1558
|
...readOperationReport(value, path)
|
|
1299
1559
|
};
|
|
1560
|
+
case "availability":
|
|
1561
|
+
return {
|
|
1562
|
+
type,
|
|
1563
|
+
session: field(f, path, "session", integer),
|
|
1564
|
+
peers: field(
|
|
1565
|
+
f,
|
|
1566
|
+
path,
|
|
1567
|
+
"peers",
|
|
1568
|
+
record((v, p) => record((x) => readAvailability(x))(v, p))
|
|
1569
|
+
)
|
|
1570
|
+
};
|
|
1300
1571
|
default:
|
|
1301
1572
|
return null;
|
|
1302
1573
|
}
|
|
@@ -1493,6 +1764,33 @@ var RunControl = class {
|
|
|
1493
1764
|
};
|
|
1494
1765
|
|
|
1495
1766
|
// ../client/src/session-state.ts
|
|
1767
|
+
function launcherAnswer(state, name) {
|
|
1768
|
+
if (!state) {
|
|
1769
|
+
return {
|
|
1770
|
+
reason: { code: "unsupported", message: "the launcher has not said yet what it accepts" },
|
|
1771
|
+
caution: null
|
|
1772
|
+
};
|
|
1773
|
+
}
|
|
1774
|
+
const item = Object.hasOwn(state.allowed, name) ? state.allowed[name] : void 0;
|
|
1775
|
+
if (!item) {
|
|
1776
|
+
return {
|
|
1777
|
+
reason: {
|
|
1778
|
+
code: "unsupported",
|
|
1779
|
+
message: `this launcher does not say whether it accepts ${name}`
|
|
1780
|
+
},
|
|
1781
|
+
caution: null
|
|
1782
|
+
};
|
|
1783
|
+
}
|
|
1784
|
+
const caution = item.caution ? { code: item.caution.code, message: item.caution.message } : null;
|
|
1785
|
+
if (item.ok) return { reason: null, caution };
|
|
1786
|
+
return {
|
|
1787
|
+
reason: {
|
|
1788
|
+
code: item.reason ?? "refused",
|
|
1789
|
+
message: item.message ?? "the launcher does not accept it now"
|
|
1790
|
+
},
|
|
1791
|
+
caution
|
|
1792
|
+
};
|
|
1793
|
+
}
|
|
1496
1794
|
var MAX_LOG_LINES_PER_SOURCE = 2e3;
|
|
1497
1795
|
var MAX_LOG_LINES = 2e4;
|
|
1498
1796
|
var MAX_PROBLEMS = 200;
|
|
@@ -1500,8 +1798,6 @@ var MAX_FINDINGS = 500;
|
|
|
1500
1798
|
function timeView(time) {
|
|
1501
1799
|
return {
|
|
1502
1800
|
simMs: time.sim_ms,
|
|
1503
|
-
speed: time.speed,
|
|
1504
|
-
paused: time.paused,
|
|
1505
1801
|
actualSpeed: time.actual_speed,
|
|
1506
1802
|
lateSteps: time.late_steps,
|
|
1507
1803
|
maxLateMs: time.max_late_ms,
|
|
@@ -1515,6 +1811,7 @@ function commandView(command, seq) {
|
|
|
1515
1811
|
accepted: command.accepted,
|
|
1516
1812
|
message: command.message,
|
|
1517
1813
|
ms: command.ms,
|
|
1814
|
+
atMs: command.at_ms,
|
|
1518
1815
|
seq
|
|
1519
1816
|
};
|
|
1520
1817
|
}
|
|
@@ -1526,7 +1823,8 @@ function scenarioView(summary) {
|
|
|
1526
1823
|
steps: summary.steps,
|
|
1527
1824
|
stepsOmitted: summary.steps_omitted,
|
|
1528
1825
|
status: summary.status,
|
|
1529
|
-
overAtMs: summary.over_at_ms
|
|
1826
|
+
overAtMs: summary.over_at_ms,
|
|
1827
|
+
timelineUrl: summary.timeline_url
|
|
1530
1828
|
};
|
|
1531
1829
|
}
|
|
1532
1830
|
function withStep(steps, step) {
|
|
@@ -1535,6 +1833,9 @@ function withStep(steps, step) {
|
|
|
1535
1833
|
if (steps[i].index === step.index) return steps.map((s, j) => j === i ? step : s);
|
|
1536
1834
|
return [...steps.slice(0, i), step, ...steps.slice(i)];
|
|
1537
1835
|
}
|
|
1836
|
+
function isHolding(session) {
|
|
1837
|
+
return !!session && session.launcher.running && session.launcherState?.holding === true;
|
|
1838
|
+
}
|
|
1538
1839
|
function runOutcome(session) {
|
|
1539
1840
|
if (session.launcher.running) {
|
|
1540
1841
|
if (session.result) return "finishing";
|
|
@@ -1565,6 +1866,7 @@ function sessionFromSummary(summary) {
|
|
|
1565
1866
|
time: null,
|
|
1566
1867
|
stopRequests: 0,
|
|
1567
1868
|
lastCommand: null,
|
|
1869
|
+
launcherState: null,
|
|
1568
1870
|
result: null,
|
|
1569
1871
|
launcher: launcherOf(summary),
|
|
1570
1872
|
problems: [],
|
|
@@ -1653,6 +1955,7 @@ function applySummary(session, summary, force = false, controlOnly = false) {
|
|
|
1653
1955
|
timeOmittedFields: summary.sim_ms === null ? next.timeOmittedFields : summary.time_omitted_fields,
|
|
1654
1956
|
time: summary.time ? timeView(summary.time) : next.time,
|
|
1655
1957
|
lastCommand: summary.last_command ? commandView(summary.last_command, summary.last_command.seq ?? -1) : next.lastCommand,
|
|
1958
|
+
launcherState: newerState(next.launcherState, summary.launcher_state ?? null),
|
|
1656
1959
|
findings: summary.findings,
|
|
1657
1960
|
result,
|
|
1658
1961
|
check,
|
|
@@ -1662,6 +1965,10 @@ function applySummary(session, summary, force = false, controlOnly = false) {
|
|
|
1662
1965
|
participants: withResult(check ? mergeCheck(participants, check) : participants, result)
|
|
1663
1966
|
};
|
|
1664
1967
|
}
|
|
1968
|
+
function newerState(current, incoming) {
|
|
1969
|
+
if (!incoming) return current;
|
|
1970
|
+
return !current || incoming.rev >= current.rev ? incoming : current;
|
|
1971
|
+
}
|
|
1665
1972
|
function union(a, b) {
|
|
1666
1973
|
return b.every((name) => a.includes(name)) ? a : [.../* @__PURE__ */ new Set([...a, ...b])];
|
|
1667
1974
|
}
|
|
@@ -1804,6 +2111,8 @@ function applyOne(session, event, logs) {
|
|
|
1804
2111
|
return { ...next, simMs: event.sim_ms, timeOmittedFields: [], time: timeView(event) };
|
|
1805
2112
|
case "command":
|
|
1806
2113
|
return { ...next, lastCommand: commandView(event, event.seq) };
|
|
2114
|
+
case "state":
|
|
2115
|
+
return { ...next, launcherState: newerState(next.launcherState, event) };
|
|
1807
2116
|
case "result":
|
|
1808
2117
|
return {
|
|
1809
2118
|
...next,
|
|
@@ -1920,6 +2229,8 @@ var SessionFeed = class {
|
|
|
1920
2229
|
this.onError = onError;
|
|
1921
2230
|
this.current = new Writable(null, Object.is, onError);
|
|
1922
2231
|
this.synced = new Writable(false, Object.is, onError);
|
|
2232
|
+
this.allowedValue = new Writable(null, Object.is, onError);
|
|
2233
|
+
this.allowed = this.allowedValue.readonly();
|
|
1923
2234
|
this.receivedAt = new Writable(0, Object.is, onError);
|
|
1924
2235
|
this.noticeList = new Writable([], Object.is, onError);
|
|
1925
2236
|
this.rejectedValue = new Writable(false, Object.is, onError);
|
|
@@ -1937,13 +2248,14 @@ var SessionFeed = class {
|
|
|
1937
2248
|
);
|
|
1938
2249
|
connection.onBatch((batch) => this.receive(batch));
|
|
1939
2250
|
connection.onUnreadable(
|
|
1940
|
-
(
|
|
2251
|
+
(text3) => this.notify(`unreadable message: not JSON (connecting again): ${text3.slice(0, 80)}`)
|
|
1941
2252
|
);
|
|
1942
2253
|
}
|
|
1943
2254
|
connection;
|
|
1944
2255
|
onError;
|
|
1945
2256
|
current;
|
|
1946
2257
|
synced;
|
|
2258
|
+
allowedValue;
|
|
1947
2259
|
receivedAt;
|
|
1948
2260
|
noticeList;
|
|
1949
2261
|
rejectedValue;
|
|
@@ -1953,6 +2265,7 @@ var SessionFeed = class {
|
|
|
1953
2265
|
stoppedFlag = false;
|
|
1954
2266
|
session;
|
|
1955
2267
|
ready;
|
|
2268
|
+
allowed;
|
|
1956
2269
|
lastEventAt;
|
|
1957
2270
|
notices;
|
|
1958
2271
|
rejected;
|
|
@@ -1988,10 +2301,20 @@ var SessionFeed = class {
|
|
|
1988
2301
|
const session = this.current.get();
|
|
1989
2302
|
if (session && summary.id < session.id) return;
|
|
1990
2303
|
const live = this.connection.state.get() === "open";
|
|
2304
|
+
this.adoptAllowed(summary.allowed ?? null);
|
|
1991
2305
|
this.current.set(
|
|
1992
2306
|
session?.id === summary.id ? applySummary(session, summary, false, live) : sessionFromSummary(summary)
|
|
1993
2307
|
);
|
|
1994
2308
|
}
|
|
2309
|
+
/**
|
|
2310
|
+
* Takes what the server accepts (an HTTP answer or a notification): the one with the larger `rev` wins (rev 0 is a
|
|
2311
|
+
* server that does not number it: the newest arrival wins). Used inside the library.
|
|
2312
|
+
*/
|
|
2313
|
+
adoptAllowed(allowed) {
|
|
2314
|
+
if (!allowed) return;
|
|
2315
|
+
const current = this.allowedValue.get();
|
|
2316
|
+
if (!current || allowed.rev === 0 || allowed.rev >= current.rev) this.allowedValue.set(allowed);
|
|
2317
|
+
}
|
|
1995
2318
|
report(message, count2 = 1) {
|
|
1996
2319
|
this.notify(message, count2);
|
|
1997
2320
|
}
|
|
@@ -2048,6 +2371,13 @@ var SessionFeed = class {
|
|
|
2048
2371
|
let events = [];
|
|
2049
2372
|
let applied = false;
|
|
2050
2373
|
let synced = this.synced.get();
|
|
2374
|
+
let allowedNow = this.allowedValue.get();
|
|
2375
|
+
const takeAllowed = (incoming, replace = false) => {
|
|
2376
|
+
if (!incoming) return;
|
|
2377
|
+
if (replace || !allowedNow || incoming.rev === 0 || incoming.rev >= allowedNow.rev) {
|
|
2378
|
+
allowedNow = incoming;
|
|
2379
|
+
}
|
|
2380
|
+
};
|
|
2051
2381
|
let replaying = !synced;
|
|
2052
2382
|
const flush = () => {
|
|
2053
2383
|
if (session && events.length > 0) {
|
|
@@ -2063,6 +2393,7 @@ var SessionFeed = class {
|
|
|
2063
2393
|
synced = false;
|
|
2064
2394
|
replaying = true;
|
|
2065
2395
|
const { session: summary, replay } = message;
|
|
2396
|
+
takeAllowed(message.allowed ?? summary?.allowed ?? null, true);
|
|
2066
2397
|
const resumed = summary && session?.id === summary.id && replay?.from_seq != null;
|
|
2067
2398
|
session = !summary ? null : resumed && session ? applySummary(session, summary, true) : sessionFromSummary(summary);
|
|
2068
2399
|
break;
|
|
@@ -2075,7 +2406,11 @@ var SessionFeed = class {
|
|
|
2075
2406
|
synced = true;
|
|
2076
2407
|
replaying = false;
|
|
2077
2408
|
break;
|
|
2409
|
+
case "allowed":
|
|
2410
|
+
takeAllowed(message.allowed);
|
|
2411
|
+
break;
|
|
2078
2412
|
case "session":
|
|
2413
|
+
takeAllowed(message.session.allowed);
|
|
2079
2414
|
session = session?.id === message.session.id ? applySummary(session, message.session, true) : sessionFromSummary(message.session);
|
|
2080
2415
|
break;
|
|
2081
2416
|
case "event":
|
|
@@ -2084,10 +2419,10 @@ var SessionFeed = class {
|
|
|
2084
2419
|
case "error":
|
|
2085
2420
|
if (message.code === "unauthorized") {
|
|
2086
2421
|
} else if (session && message.session === session.id) {
|
|
2087
|
-
const { code, message:
|
|
2422
|
+
const { code, message: text3, skipped } = message;
|
|
2088
2423
|
session = addProblem(
|
|
2089
2424
|
session,
|
|
2090
|
-
skipped === void 0 ? { code, message:
|
|
2425
|
+
skipped === void 0 ? { code, message: text3 } : { code, message: text3, skipped }
|
|
2091
2426
|
);
|
|
2092
2427
|
} else {
|
|
2093
2428
|
this.notify(message.message);
|
|
@@ -2101,6 +2436,7 @@ var SessionFeed = class {
|
|
|
2101
2436
|
}
|
|
2102
2437
|
flush();
|
|
2103
2438
|
const stale = (session?.staleEvents ?? 0) - (before?.id === session?.id ? before?.staleEvents ?? 0 : 0);
|
|
2439
|
+
this.allowedValue.set(allowedNow);
|
|
2104
2440
|
this.current.set(session);
|
|
2105
2441
|
this.synced.set(synced);
|
|
2106
2442
|
if (applied) this.receivedAt.set(Date.now());
|
|
@@ -2119,30 +2455,18 @@ var SessionFeed = class {
|
|
|
2119
2455
|
};
|
|
2120
2456
|
|
|
2121
2457
|
// ../client/src/time.ts
|
|
2122
|
-
var FEATURE_SPEED = "speed";
|
|
2123
|
-
var FEATURE_START_PAUSED = "start-paused";
|
|
2124
|
-
var FEATURE_TIME_COMMANDS = "time-commands";
|
|
2125
2458
|
var ANSWER_TIMEOUT_MS = 5e3;
|
|
2126
2459
|
var TimeControl = class {
|
|
2127
|
-
constructor(session,
|
|
2460
|
+
constructor(session, transport, answerTimeoutMs = ANSWER_TIMEOUT_MS, onError = rethrowLater) {
|
|
2128
2461
|
this.session = session;
|
|
2129
2462
|
this.transport = transport;
|
|
2130
2463
|
this.answerTimeoutMs = answerTimeoutMs;
|
|
2131
|
-
this.variables = variables;
|
|
2132
2464
|
this.inFlight = new Writable(0, Object.is, onError);
|
|
2133
2465
|
this.pending = new Writable(null, Object.is, onError);
|
|
2134
2466
|
this.failureValue = new Writable(null, Object.is, onError);
|
|
2135
2467
|
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()),
|
|
2468
|
+
[session, this.inFlight, this.pending, this.failureValue],
|
|
2469
|
+
() => this.compute(session.get()),
|
|
2146
2470
|
shallowEqual,
|
|
2147
2471
|
onError
|
|
2148
2472
|
);
|
|
@@ -2150,13 +2474,12 @@ var TimeControl = class {
|
|
|
2150
2474
|
session;
|
|
2151
2475
|
transport;
|
|
2152
2476
|
answerTimeoutMs;
|
|
2153
|
-
variables;
|
|
2154
2477
|
inFlight;
|
|
2155
2478
|
pending;
|
|
2156
2479
|
failureValue;
|
|
2157
2480
|
answerTimer;
|
|
2158
2481
|
lastLateness = null;
|
|
2159
|
-
/** Time state
|
|
2482
|
+
/** Time state. */
|
|
2160
2483
|
state;
|
|
2161
2484
|
pause() {
|
|
2162
2485
|
return this.send({ command: "pause" });
|
|
@@ -2175,10 +2498,10 @@ var TimeControl = class {
|
|
|
2175
2498
|
return this.send({ command: "speed", value });
|
|
2176
2499
|
}
|
|
2177
2500
|
/**
|
|
2178
|
-
* Sends a command. The result arrives as the launcher's command and time events (the content of the HTTP answer is
|
|
2501
|
+
* Sends a command. The result arrives as the launcher's command, state and time events (the content of the HTTP answer is
|
|
2179
2502
|
* not used). With no run, or while waiting for the answer to the previous command (sending), nothing is sent and
|
|
2180
2503
|
* `{sent: false, reason}` is returned. If no answer comes within answerTimeoutMs, stops waiting and reports it in
|
|
2181
|
-
* failure.
|
|
2504
|
+
* failure. Whether the launcher would accept the command is `allowed` of its state.
|
|
2182
2505
|
*/
|
|
2183
2506
|
send(command) {
|
|
2184
2507
|
const session = this.session.get();
|
|
@@ -2224,8 +2547,7 @@ var TimeControl = class {
|
|
|
2224
2547
|
session: pending.session
|
|
2225
2548
|
});
|
|
2226
2549
|
}
|
|
2227
|
-
compute(session
|
|
2228
|
-
const supported = app?.launcher.features.includes(FEATURE_TIME_COMMANDS) ?? false;
|
|
2550
|
+
compute(session) {
|
|
2229
2551
|
const time = session?.time ?? null;
|
|
2230
2552
|
let lateness = !time || time.lateSteps === null || time.maxLateMs === null ? null : {
|
|
2231
2553
|
lateSteps: time.lateSteps,
|
|
@@ -2238,34 +2560,20 @@ var TimeControl = class {
|
|
|
2238
2560
|
}
|
|
2239
2561
|
this.lastLateness = lateness;
|
|
2240
2562
|
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
2563
|
const pending = this.pending.get();
|
|
2245
2564
|
let sending = null;
|
|
2246
2565
|
if (pending) {
|
|
2247
2566
|
const answered = !session || session.id !== pending.session || !session.launcher.running || (session.lastCommand?.seq ?? -1) > pending.afterSeq;
|
|
2248
2567
|
sending = this.inFlight.get() > 0 || !answered ? pending.command : null;
|
|
2249
2568
|
}
|
|
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
2569
|
const failure = this.failureValue.get();
|
|
2255
2570
|
return {
|
|
2256
|
-
supported,
|
|
2257
2571
|
time,
|
|
2258
|
-
paced: typeof
|
|
2572
|
+
paced: typeof session?.launcherState?.speed === "number",
|
|
2259
2573
|
lateness,
|
|
2260
2574
|
behind: (lateness?.lateSteps ?? 0) > 0,
|
|
2261
2575
|
lastCommand,
|
|
2262
|
-
controllable,
|
|
2263
|
-
beforeStart,
|
|
2264
2576
|
sending,
|
|
2265
|
-
stepping,
|
|
2266
|
-
canPause: free && paused === false,
|
|
2267
|
-
canResume,
|
|
2268
|
-
canStep: canResume,
|
|
2269
2577
|
failure: failure && failure.session === (session?.id ?? null) ? failure : null
|
|
2270
2578
|
};
|
|
2271
2579
|
}
|
|
@@ -2309,6 +2617,7 @@ function writeBlock(input) {
|
|
|
2309
2617
|
if (status !== "ready") return "not-ready";
|
|
2310
2618
|
if (info === void 0) return "missing";
|
|
2311
2619
|
if (!input.peerConnected) return "peer-disconnected";
|
|
2620
|
+
if (input.launcherRefuses) return "launcher";
|
|
2312
2621
|
if (info.role === "parameter" && !input.beforeStart) return "parameter";
|
|
2313
2622
|
return null;
|
|
2314
2623
|
}
|
|
@@ -2347,6 +2656,7 @@ var NO_VARIABLES = {
|
|
|
2347
2656
|
status: "unknown",
|
|
2348
2657
|
reason: null,
|
|
2349
2658
|
peers: [],
|
|
2659
|
+
availability: /* @__PURE__ */ new Map(),
|
|
2350
2660
|
peersOmitted: 0,
|
|
2351
2661
|
variablesOmitted: 0
|
|
2352
2662
|
};
|
|
@@ -2363,12 +2673,15 @@ var isObject = (value) => typeof value === "object" && value !== null && !Array.
|
|
|
2363
2673
|
var text = (value, fallback = "") => typeof value === "string" ? value : fallback;
|
|
2364
2674
|
var numberOrNull = (value) => typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
2365
2675
|
var count = (value) => typeof value === "number" && value >= 0 ? value : 0;
|
|
2676
|
+
var positionOrNull = (value) => Number.isSafeInteger(value) && value >= 0 ? value : null;
|
|
2366
2677
|
function readVariables2(value, session) {
|
|
2367
2678
|
if (!isObject(value)) return { ...NO_VARIABLES, session };
|
|
2368
2679
|
const peers = [];
|
|
2680
|
+
const availability = /* @__PURE__ */ new Map();
|
|
2369
2681
|
for (const p of Array.isArray(value["peers"]) ? value["peers"] : []) {
|
|
2370
2682
|
if (!isObject(p) || typeof p["name"] !== "string") continue;
|
|
2371
2683
|
const variables = [];
|
|
2684
|
+
const states = /* @__PURE__ */ new Map();
|
|
2372
2685
|
for (const v of Array.isArray(p["variables"]) ? p["variables"] : []) {
|
|
2373
2686
|
if (!isObject(v) || typeof v["name"] !== "string") continue;
|
|
2374
2687
|
const items2 = Array.isArray(v["enum"]) ? v["enum"].flatMap(
|
|
@@ -2386,7 +2699,9 @@ function readVariables2(value, session) {
|
|
|
2386
2699
|
description: text(v["description"]),
|
|
2387
2700
|
enum: items2
|
|
2388
2701
|
});
|
|
2702
|
+
states.set(v["name"], readAvailability(v["availability"]));
|
|
2389
2703
|
}
|
|
2704
|
+
availability.set(p["name"], states);
|
|
2390
2705
|
peers.push({ name: p["name"], connected: p["connected"] === true, variables });
|
|
2391
2706
|
}
|
|
2392
2707
|
return {
|
|
@@ -2394,6 +2709,7 @@ function readVariables2(value, session) {
|
|
|
2394
2709
|
status: text(value["state"], "unknown"),
|
|
2395
2710
|
reason: typeof value["reason"] === "string" ? value["reason"] : null,
|
|
2396
2711
|
peers,
|
|
2712
|
+
availability,
|
|
2397
2713
|
peersOmitted: count(value["peers_omitted"]),
|
|
2398
2714
|
variablesOmitted: count(value["variables_omitted"])
|
|
2399
2715
|
};
|
|
@@ -2409,7 +2725,9 @@ function readOperation(value, session) {
|
|
|
2409
2725
|
state: text(p["state"], "unknown"),
|
|
2410
2726
|
appliedAtMs: numberOrNull(p["applied_at_ms"]),
|
|
2411
2727
|
late: p["late"] === true,
|
|
2412
|
-
reason: typeof p["reason"] === "string" ? p["reason"] : null
|
|
2728
|
+
reason: typeof p["reason"] === "string" ? p["reason"] : null,
|
|
2729
|
+
appliedWrites: positionOrNull(p["applied_writes"]),
|
|
2730
|
+
failedWrite: positionOrNull(p["failed_write"])
|
|
2413
2731
|
};
|
|
2414
2732
|
}
|
|
2415
2733
|
return {
|
|
@@ -2642,6 +2960,11 @@ var VariablesFeed = class {
|
|
|
2642
2960
|
}
|
|
2643
2961
|
break;
|
|
2644
2962
|
}
|
|
2963
|
+
case "availability": {
|
|
2964
|
+
if (message["session"] !== this.stateValue.get().session) break;
|
|
2965
|
+
if (this.takeAvailability(message["peers"])) touchedAll = true;
|
|
2966
|
+
break;
|
|
2967
|
+
}
|
|
2645
2968
|
case "error": {
|
|
2646
2969
|
const code = message["code"];
|
|
2647
2970
|
if (code === "invalid-watch" || code === "too-many-watches") {
|
|
@@ -2654,6 +2977,25 @@ var VariablesFeed = class {
|
|
|
2654
2977
|
flush();
|
|
2655
2978
|
if (touchedAll || touched.size > 0) this.publish(touchedAll ? null : touched);
|
|
2656
2979
|
}
|
|
2980
|
+
/** Returns whether any state changed. Only the availability table changes: `peers` keeps its identity. */
|
|
2981
|
+
takeAvailability(peers) {
|
|
2982
|
+
if (!isObject(peers)) return false;
|
|
2983
|
+
const state = this.stateValue.get();
|
|
2984
|
+
let next = null;
|
|
2985
|
+
for (const peer of state.peers) {
|
|
2986
|
+
const told = peers[peer.name];
|
|
2987
|
+
if (!isObject(told)) continue;
|
|
2988
|
+
const before = state.availability.get(peer.name);
|
|
2989
|
+
const states = new Map(peer.variables.map((v) => [v.name, readAvailability(told[v.name])]));
|
|
2990
|
+
if (before?.size === states.size && [...states].every(([name, value]) => before.get(name) === value))
|
|
2991
|
+
continue;
|
|
2992
|
+
next ??= new Map(state.availability);
|
|
2993
|
+
next.set(peer.name, states);
|
|
2994
|
+
}
|
|
2995
|
+
if (!next) return false;
|
|
2996
|
+
this.stateValue.set({ ...state, availability: next });
|
|
2997
|
+
return true;
|
|
2998
|
+
}
|
|
2657
2999
|
/** Applies the variables part of hello and of an HTTP summary (`session`). */
|
|
2658
3000
|
adoptSummary(summary) {
|
|
2659
3001
|
if (!isObject(summary) || !Number.isSafeInteger(summary["id"])) return;
|
|
@@ -2842,11 +3184,7 @@ var VariablesFeed = class {
|
|
|
2842
3184
|
const session = this.stateValue.get().session;
|
|
2843
3185
|
if (session === null) {
|
|
2844
3186
|
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
|
-
)
|
|
3187
|
+
new WriteError("refused", "there is no run to write to", "not-running")
|
|
2850
3188
|
);
|
|
2851
3189
|
}
|
|
2852
3190
|
const body = { session, writes };
|
|
@@ -2943,10 +3281,10 @@ var VariablesFeed = class {
|
|
|
2943
3281
|
this.forget();
|
|
2944
3282
|
handle.values.set(this.valuesOf(handle));
|
|
2945
3283
|
this.queueSync();
|
|
2946
|
-
let
|
|
3284
|
+
let open2 = true;
|
|
2947
3285
|
const mine = (ref) => {
|
|
2948
3286
|
const key = keyOf(ref.peer, ref.name);
|
|
2949
|
-
return
|
|
3287
|
+
return open2 && (handle.keys === null || handle.keys.has(key)) ? key : null;
|
|
2950
3288
|
};
|
|
2951
3289
|
return {
|
|
2952
3290
|
values: handle.values.readonly(),
|
|
@@ -2959,8 +3297,8 @@ var VariablesFeed = class {
|
|
|
2959
3297
|
return key === null ? [] : this.histories.get(key)?.last(handle.history) ?? [];
|
|
2960
3298
|
},
|
|
2961
3299
|
close: () => {
|
|
2962
|
-
if (!
|
|
2963
|
-
|
|
3300
|
+
if (!open2) return;
|
|
3301
|
+
open2 = false;
|
|
2964
3302
|
this.handles.delete(handle);
|
|
2965
3303
|
this.forget();
|
|
2966
3304
|
this.queueSync();
|
|
@@ -3090,7 +3428,7 @@ var VariablesFeed = class {
|
|
|
3090
3428
|
};
|
|
3091
3429
|
|
|
3092
3430
|
// ../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,
|
|
3431
|
+
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
3432
|
var keyOf2 = (ref) => `${ref.peer}\0${ref.name}`;
|
|
3095
3433
|
var IDLE = { kind: "idle" };
|
|
3096
3434
|
var VariableBinder = class {
|
|
@@ -3136,18 +3474,26 @@ var VariableBinder = class {
|
|
|
3136
3474
|
return this.sources.connection.get() === "open";
|
|
3137
3475
|
}
|
|
3138
3476
|
/**
|
|
3139
|
-
* Why the variable cannot be written now (null if it can). Only the widget-independent reasons (Binding adds
|
|
3140
|
-
*
|
|
3477
|
+
* Why the variable cannot be written now (null if it can). Only the widget-independent reasons (Binding adds range
|
|
3478
|
+
* and value).
|
|
3141
3479
|
*/
|
|
3142
3480
|
block(ref) {
|
|
3143
3481
|
return writeBlock({
|
|
3144
3482
|
info: this.find(ref),
|
|
3145
3483
|
status: this.sources.variables.state.get().status,
|
|
3146
3484
|
connected: this.connected(),
|
|
3147
|
-
beforeStart: this.sources.
|
|
3148
|
-
peerConnected: this.peerConnected(ref.peer)
|
|
3485
|
+
beforeStart: isHolding(this.sources.session.get()),
|
|
3486
|
+
peerConnected: this.peerConnected(ref.peer),
|
|
3487
|
+
launcherRefuses: this.launcherReason() !== null
|
|
3149
3488
|
});
|
|
3150
3489
|
}
|
|
3490
|
+
/**
|
|
3491
|
+
* Why the launcher does not take a write now (launcherAnswer of its last `state`; `unsupported` until a `state` says).
|
|
3492
|
+
* The client keeps no rule of its own about it.
|
|
3493
|
+
*/
|
|
3494
|
+
launcherReason() {
|
|
3495
|
+
return launcherAnswer(this.sources.session.get()?.launcherState ?? null, "write").reason;
|
|
3496
|
+
}
|
|
3151
3497
|
/** Status of the last write to that variable in the current run. */
|
|
3152
3498
|
status(ref) {
|
|
3153
3499
|
return this.entry(ref)?.status ?? IDLE;
|
|
@@ -3297,7 +3643,7 @@ var VariableBinder = class {
|
|
|
3297
3643
|
}
|
|
3298
3644
|
};
|
|
3299
3645
|
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);
|
|
3646
|
+
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
3647
|
}
|
|
3302
3648
|
var Binding = class {
|
|
3303
3649
|
constructor(binder, ref, options) {
|
|
@@ -3311,7 +3657,6 @@ var Binding = class {
|
|
|
3311
3657
|
this.stops.push(
|
|
3312
3658
|
sources.variables.state.subscribe(refresh),
|
|
3313
3659
|
sources.connection.subscribe(refresh),
|
|
3314
|
-
sources.time.subscribe(refresh),
|
|
3315
3660
|
sources.session.subscribe(refresh),
|
|
3316
3661
|
binder.onChange(ref, refresh)
|
|
3317
3662
|
);
|
|
@@ -3353,12 +3698,15 @@ var Binding = class {
|
|
|
3353
3698
|
readFailing: variables.status === "ready" && variables.reason !== null
|
|
3354
3699
|
});
|
|
3355
3700
|
const pending = binder.pending(ref);
|
|
3701
|
+
const block = this.blockOf(info, reading, pending);
|
|
3356
3702
|
return {
|
|
3357
3703
|
ref,
|
|
3358
3704
|
info,
|
|
3705
|
+
availability: variables.availability.get(ref.peer)?.get(ref.name) ?? "unknown",
|
|
3359
3706
|
reading,
|
|
3360
3707
|
condition,
|
|
3361
|
-
block
|
|
3708
|
+
block,
|
|
3709
|
+
launcherReason: block === "launcher" ? binder.launcherReason() : null,
|
|
3362
3710
|
writeStatus: binder.status(ref),
|
|
3363
3711
|
pending
|
|
3364
3712
|
};
|
|
@@ -3366,17 +3714,15 @@ var Binding = class {
|
|
|
3366
3714
|
blockOf(info, reading, pending) {
|
|
3367
3715
|
const base = this.binder.block(this.ref);
|
|
3368
3716
|
if (base !== null) return base;
|
|
3369
|
-
const session = this.binder.sources.session.get();
|
|
3370
|
-
if (session?.scenario && session.launcher.running) return "scenario";
|
|
3371
3717
|
if (this.options.needsRange && info && !hasRange(info)) return "no-range";
|
|
3372
3718
|
if (this.options.needsValue && reading === void 0 && pending === null) return "no-value";
|
|
3373
3719
|
return null;
|
|
3374
3720
|
}
|
|
3375
3721
|
openWatch() {
|
|
3376
3722
|
const { periodMs, history } = this.options;
|
|
3377
|
-
const
|
|
3378
|
-
this.watch =
|
|
3379
|
-
this.stopWatch =
|
|
3723
|
+
const watch2 = this.binder.sources.variables.watch([this.ref], { periodMs, history });
|
|
3724
|
+
this.watch = watch2;
|
|
3725
|
+
this.stopWatch = watch2.values.subscribe(() => this.refresh());
|
|
3380
3726
|
}
|
|
3381
3727
|
closeWatch() {
|
|
3382
3728
|
this.stopWatch?.();
|
|
@@ -3434,6 +3780,9 @@ function defaultOrigin(baseUrl, runtime = globalThis) {
|
|
|
3434
3780
|
return isNode(runtime) ? new URL(baseUrl).origin : void 0;
|
|
3435
3781
|
}
|
|
3436
3782
|
function createClient(options) {
|
|
3783
|
+
return buildClient(options).client;
|
|
3784
|
+
}
|
|
3785
|
+
function buildClient(options) {
|
|
3437
3786
|
const token = typeof options.token === "function" ? options.token : () => options.token;
|
|
3438
3787
|
const onError = options.onError ?? reportToConsole;
|
|
3439
3788
|
const origin = options.origin ?? defaultOrigin(options.baseUrl);
|
|
@@ -3464,17 +3813,13 @@ function createClient(options) {
|
|
|
3464
3813
|
const run = new RunControl(session, http, onError, () => longRequestMs(limits.get()));
|
|
3465
3814
|
const time = new TimeControl(
|
|
3466
3815
|
session.session,
|
|
3467
|
-
session.ready,
|
|
3468
|
-
app.readonly(),
|
|
3469
3816
|
http,
|
|
3470
3817
|
options.answerTimeoutMs ?? ANSWER_TIMEOUT_MS,
|
|
3471
|
-
onError
|
|
3472
|
-
variables.state
|
|
3818
|
+
onError
|
|
3473
3819
|
);
|
|
3474
3820
|
const binder = new VariableBinder({
|
|
3475
3821
|
variables,
|
|
3476
3822
|
connection: connection.state,
|
|
3477
|
-
time: time.state,
|
|
3478
3823
|
session: session.session,
|
|
3479
3824
|
onError
|
|
3480
3825
|
});
|
|
@@ -3493,7 +3838,7 @@ function createClient(options) {
|
|
|
3493
3838
|
}
|
|
3494
3839
|
})
|
|
3495
3840
|
);
|
|
3496
|
-
|
|
3841
|
+
const client = {
|
|
3497
3842
|
connection: {
|
|
3498
3843
|
state: connection.state,
|
|
3499
3844
|
failures: connection.failures,
|
|
@@ -3505,6 +3850,7 @@ function createClient(options) {
|
|
|
3505
3850
|
session: {
|
|
3506
3851
|
session: session.session,
|
|
3507
3852
|
ready: session.ready,
|
|
3853
|
+
allowed: session.allowed,
|
|
3508
3854
|
lastEventAt: session.lastEventAt,
|
|
3509
3855
|
notices: session.notices,
|
|
3510
3856
|
rejected: session.rejected,
|
|
@@ -3551,6 +3897,20 @@ function createClient(options) {
|
|
|
3551
3897
|
},
|
|
3552
3898
|
loadApp: () => call({ method: "GET", path: "api/app" }, readAppInfo, (info) => app.set(info)),
|
|
3553
3899
|
configs: () => call({ method: "GET", path: "api/configs" }, readConfigList),
|
|
3900
|
+
config: (file) => call({ method: "GET", path: `api/config?file=${encodeURIComponent(file)}` }, readConfigText),
|
|
3901
|
+
describe: (body) => call(
|
|
3902
|
+
{
|
|
3903
|
+
method: "POST",
|
|
3904
|
+
path: "api/describe",
|
|
3905
|
+
body,
|
|
3906
|
+
timeoutMs: longRequestMs(limits.get())
|
|
3907
|
+
},
|
|
3908
|
+
readCheckResponse
|
|
3909
|
+
),
|
|
3910
|
+
saveConfig: (body) => call(
|
|
3911
|
+
{ method: "POST", path: "api/config", body, timeoutMs: longRequestMs(limits.get()) },
|
|
3912
|
+
readSavedConfig
|
|
3913
|
+
),
|
|
3554
3914
|
dashboard: (file) => call(
|
|
3555
3915
|
{ method: "GET", path: `api/dashboard?file=${encodeURIComponent(file)}` },
|
|
3556
3916
|
readDashboardResponse
|
|
@@ -3569,6 +3929,15 @@ function createClient(options) {
|
|
|
3569
3929
|
},
|
|
3570
3930
|
readCheckResponse
|
|
3571
3931
|
),
|
|
3932
|
+
connections: (body) => call(
|
|
3933
|
+
{
|
|
3934
|
+
method: "POST",
|
|
3935
|
+
path: "api/connections",
|
|
3936
|
+
body,
|
|
3937
|
+
timeoutMs: longRequestMs(limits.get())
|
|
3938
|
+
},
|
|
3939
|
+
readConnections
|
|
3940
|
+
),
|
|
3572
3941
|
fetchSession: () => new Promise(
|
|
3573
3942
|
(resolve, reject) => http({ method: "GET", path: "api/session" }, (outcome) => {
|
|
3574
3943
|
if (!outcome.ok) {
|
|
@@ -3578,6 +3947,7 @@ function createClient(options) {
|
|
|
3578
3947
|
try {
|
|
3579
3948
|
const summary = readSessionResponse(outcome.body);
|
|
3580
3949
|
session.adopt(summary);
|
|
3950
|
+
session.adoptAllowed(readSessionAllowed(outcome.body));
|
|
3581
3951
|
variables.adoptSummary(outcome.body?.session);
|
|
3582
3952
|
resolve(summary);
|
|
3583
3953
|
} catch (error) {
|
|
@@ -3586,6 +3956,7 @@ function createClient(options) {
|
|
|
3586
3956
|
})
|
|
3587
3957
|
)
|
|
3588
3958
|
};
|
|
3959
|
+
return { client, http, onError };
|
|
3589
3960
|
}
|
|
3590
3961
|
|
|
3591
3962
|
// ../client/src/token.ts
|
|
@@ -3630,18 +4001,1310 @@ function read(storage) {
|
|
|
3630
4001
|
return null;
|
|
3631
4002
|
}
|
|
3632
4003
|
}
|
|
4004
|
+
|
|
4005
|
+
// ../client/src/front-types.ts
|
|
4006
|
+
var ActionError = class extends Error {
|
|
4007
|
+
constructor(code, message, outcome, findings = []) {
|
|
4008
|
+
super(message);
|
|
4009
|
+
this.code = code;
|
|
4010
|
+
this.outcome = outcome;
|
|
4011
|
+
this.findings = findings;
|
|
4012
|
+
this.name = "ActionError";
|
|
4013
|
+
}
|
|
4014
|
+
code;
|
|
4015
|
+
outcome;
|
|
4016
|
+
findings;
|
|
4017
|
+
};
|
|
4018
|
+
|
|
4019
|
+
// ../client/src/front-compose.ts
|
|
4020
|
+
function linkOf(s) {
|
|
4021
|
+
if (s.rejected) return "rejected";
|
|
4022
|
+
if (s.incompatible !== null) return "incompatible";
|
|
4023
|
+
if (s.connection === "open") return s.ready ? "online" : "connecting";
|
|
4024
|
+
return s.connection === "closed" || s.failures > 0 || s.closedBefore ? "offline" : "connecting";
|
|
4025
|
+
}
|
|
4026
|
+
var NOT_PACED = "not-paced";
|
|
4027
|
+
function startOnItsWay(s) {
|
|
4028
|
+
return s.busy.has("start") || s.allowed?.start.reason === "starting";
|
|
4029
|
+
}
|
|
4030
|
+
function runOf(s) {
|
|
4031
|
+
const session = s.session;
|
|
4032
|
+
const starting = startOnItsWay(s);
|
|
4033
|
+
if (!session) return starting ? "starting" : "none";
|
|
4034
|
+
const outcome = runOutcome(session);
|
|
4035
|
+
if (outcome === "crashed") return starting ? "starting" : "crashed";
|
|
4036
|
+
if (outcome === "ended" || outcome === "finishing") return starting ? "starting" : "ended";
|
|
4037
|
+
if (outcome === "stopping" || outcome === "forcing") return "stopping";
|
|
4038
|
+
const state = session.launcherState;
|
|
4039
|
+
const phase = state?.phase || session.phase;
|
|
4040
|
+
const paused = state?.paused ?? null;
|
|
4041
|
+
switch (phase) {
|
|
4042
|
+
case null:
|
|
4043
|
+
case "checking":
|
|
4044
|
+
case "starting":
|
|
4045
|
+
return "starting";
|
|
4046
|
+
case "waiting":
|
|
4047
|
+
return "waiting";
|
|
4048
|
+
case "stopping":
|
|
4049
|
+
return "stopping";
|
|
4050
|
+
case "ended":
|
|
4051
|
+
return "stopping";
|
|
4052
|
+
default:
|
|
4053
|
+
return paused === true ? "paused" : "running";
|
|
4054
|
+
}
|
|
4055
|
+
}
|
|
4056
|
+
function resultOf(result) {
|
|
4057
|
+
return {
|
|
4058
|
+
end: result.end,
|
|
4059
|
+
scenario: result.scenario?.status ?? null,
|
|
4060
|
+
ok: result.ok,
|
|
4061
|
+
// A result whose sentence could not be read (or that the server shrank) still says something
|
|
4062
|
+
message: result.message || `the run ended with the result ${result.result || "unknown"}`
|
|
4063
|
+
};
|
|
4064
|
+
}
|
|
4065
|
+
function resultFor(s, run) {
|
|
4066
|
+
const session = s.session;
|
|
4067
|
+
if (!session) return null;
|
|
4068
|
+
if (run === "crashed") {
|
|
4069
|
+
const how = session.launcher.signal ? `signal ${session.launcher.signal}` : session.launcher.exitCode !== null ? `exit code ${session.launcher.exitCode}` : "no exit code";
|
|
4070
|
+
return {
|
|
4071
|
+
end: "crashed",
|
|
4072
|
+
scenario: null,
|
|
4073
|
+
ok: false,
|
|
4074
|
+
message: `the launcher ended without a result (${how}): start again`
|
|
4075
|
+
};
|
|
4076
|
+
}
|
|
4077
|
+
return run === "ended" && session.result ? resultOf(session.result) : null;
|
|
4078
|
+
}
|
|
4079
|
+
function statusOf(s, initialFile) {
|
|
4080
|
+
const run = runOf(s);
|
|
4081
|
+
return {
|
|
4082
|
+
link: linkOf(s),
|
|
4083
|
+
run,
|
|
4084
|
+
file: s.session?.file ?? initialFile,
|
|
4085
|
+
result: resultFor(s, run)
|
|
4086
|
+
};
|
|
4087
|
+
}
|
|
4088
|
+
function simMsOf(session) {
|
|
4089
|
+
if (!session) return null;
|
|
4090
|
+
const sim = session.time?.simMs ?? session.simMs;
|
|
4091
|
+
const state = session.launcherState;
|
|
4092
|
+
const stands = state?.paused === true ? state.paused_at_ms : null;
|
|
4093
|
+
if (stands === null || stands === void 0) return sim;
|
|
4094
|
+
return sim === null ? stands : Math.max(sim, stands);
|
|
4095
|
+
}
|
|
4096
|
+
function standsAt(session) {
|
|
4097
|
+
const state = session?.launcherState;
|
|
4098
|
+
return state?.paused === true ? state.paused_at_ms ?? null : null;
|
|
4099
|
+
}
|
|
4100
|
+
function onItsWay(session) {
|
|
4101
|
+
const last = session?.lastCommand;
|
|
4102
|
+
if (!session || !session.launcher.running || !last || !last.accepted || last.atMs === null)
|
|
4103
|
+
return false;
|
|
4104
|
+
if (last.name !== "step" && last.name !== "run_until") return false;
|
|
4105
|
+
const stands = standsAt(session);
|
|
4106
|
+
return !(stands !== null && stands >= last.atMs);
|
|
4107
|
+
}
|
|
4108
|
+
function clockOf(s) {
|
|
4109
|
+
const session = s.session;
|
|
4110
|
+
const state = session?.launcherState ?? null;
|
|
4111
|
+
const time = session?.time ?? null;
|
|
4112
|
+
const live = !!session && session.launcher.running;
|
|
4113
|
+
const pacing = state?.pacing;
|
|
4114
|
+
return {
|
|
4115
|
+
sim_ms: simMsOf(session ?? null),
|
|
4116
|
+
speed: state?.speed ?? null,
|
|
4117
|
+
// The last time event may be from before the pause: nothing moves while it stands still
|
|
4118
|
+
actual_speed: state?.paused === true ? null : time?.actualSpeed ?? null,
|
|
4119
|
+
pacing: !live ? NOT_PACED : pacing === "late" ? "late" : pacing === "on-time" ? "on-time" : NOT_PACED
|
|
4120
|
+
};
|
|
4121
|
+
}
|
|
4122
|
+
var reason = (code, message) => ({ code, message });
|
|
4123
|
+
function control(ok, why = null, caution = null) {
|
|
4124
|
+
return { ok, reason: ok ? null : why, caution };
|
|
4125
|
+
}
|
|
4126
|
+
function linkReason(link, s) {
|
|
4127
|
+
switch (link) {
|
|
4128
|
+
case "online":
|
|
4129
|
+
return null;
|
|
4130
|
+
case "rejected":
|
|
4131
|
+
return reason(
|
|
4132
|
+
"rejected",
|
|
4133
|
+
"the server refused the token: open the URL that the server printed again (it ends with #token=...)"
|
|
4134
|
+
);
|
|
4135
|
+
case "incompatible":
|
|
4136
|
+
return reason(
|
|
4137
|
+
"incompatible",
|
|
4138
|
+
s.incompatible ?? "the server speaks another version of the GUI protocol"
|
|
4139
|
+
);
|
|
4140
|
+
case "offline":
|
|
4141
|
+
return reason(
|
|
4142
|
+
"offline",
|
|
4143
|
+
"the connection to the GUI server is down: the client connects again by itself, then try again"
|
|
4144
|
+
);
|
|
4145
|
+
default:
|
|
4146
|
+
return reason(
|
|
4147
|
+
"connecting",
|
|
4148
|
+
"the client is still connecting to the GUI server: try again in a moment"
|
|
4149
|
+
);
|
|
4150
|
+
}
|
|
4151
|
+
}
|
|
4152
|
+
var busyReason = (name) => reason("busy", `the previous ${name} has not been answered yet: wait for it`);
|
|
4153
|
+
function fromServer(item, fallback, caution = null) {
|
|
4154
|
+
return item.ok ? control(true, null, caution) : control(false, reason(item.reason ?? "refused", item.message ?? fallback));
|
|
4155
|
+
}
|
|
4156
|
+
function numberOf(item, key) {
|
|
4157
|
+
const value = item?.raw?.[key];
|
|
4158
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
4159
|
+
}
|
|
4160
|
+
function controlsOf(s, run) {
|
|
4161
|
+
return composeControls(s, run).controls;
|
|
4162
|
+
}
|
|
4163
|
+
function writeOf(s, run) {
|
|
4164
|
+
return composeControls(s, run).write;
|
|
4165
|
+
}
|
|
4166
|
+
function composeControls(s, run) {
|
|
4167
|
+
const link = linkOf(s);
|
|
4168
|
+
const down = linkReason(link, s);
|
|
4169
|
+
const session = s.session;
|
|
4170
|
+
const live = !!session && session.launcher.running && run !== "ended" && run !== "crashed";
|
|
4171
|
+
const state = session?.launcherState ?? null;
|
|
4172
|
+
const stopsAsked = session?.stopRequests ?? 0;
|
|
4173
|
+
let start;
|
|
4174
|
+
if (link === "rejected" || link === "incompatible") start = control(false, down);
|
|
4175
|
+
else if (s.busy.has("start")) start = control(false, busyReason("start"));
|
|
4176
|
+
else if (down) start = control(false, down);
|
|
4177
|
+
else if (s.allowed) start = fromServer(s.allowed.start, "the server does not start a run now");
|
|
4178
|
+
else
|
|
4179
|
+
start = live ? control(
|
|
4180
|
+
false,
|
|
4181
|
+
reason("already-running", "a run is going: stop it before you start another")
|
|
4182
|
+
) : control(true);
|
|
4183
|
+
const serverStop = s.allowed?.stop;
|
|
4184
|
+
const stoppable = s.busy.has("start") || live || run === "starting" || serverStop?.ok === true;
|
|
4185
|
+
let stop;
|
|
4186
|
+
if (s.busy.has("stop")) stop = control(false, busyReason("stop"));
|
|
4187
|
+
else if (s.busy.has("start")) stop = control(true);
|
|
4188
|
+
else if (serverStop && !serverStop.ok && serverStop.reason !== "not-running")
|
|
4189
|
+
stop = fromServer(serverStop, "the server does not stop the run now");
|
|
4190
|
+
else if (!stoppable)
|
|
4191
|
+
stop = control(false, reason("not-running", "no run is going: there is nothing to stop"));
|
|
4192
|
+
else if (stopsAsked > 0)
|
|
4193
|
+
stop = control(
|
|
4194
|
+
false,
|
|
4195
|
+
reason("already-stopping", "a stop has been asked for: wait, or force the stop")
|
|
4196
|
+
);
|
|
4197
|
+
else stop = control(true);
|
|
4198
|
+
const serverForce = s.allowed?.force;
|
|
4199
|
+
let force;
|
|
4200
|
+
if (s.busy.has("force_stop")) force = control(false, busyReason("force stop"));
|
|
4201
|
+
else if (serverForce && !serverForce.ok && serverForce.reason !== "not-running")
|
|
4202
|
+
force = fromServer(serverForce, "the server does not force a stop now");
|
|
4203
|
+
else if (!stoppable)
|
|
4204
|
+
force = control(false, reason("not-running", "no run is going: there is nothing to stop"));
|
|
4205
|
+
else if (stopsAsked === 0 && !s.busy.has("stop"))
|
|
4206
|
+
force = control(
|
|
4207
|
+
false,
|
|
4208
|
+
reason("not-stopping", "ask for a stop first: force the stop only if it does not end")
|
|
4209
|
+
);
|
|
4210
|
+
else force = control(true);
|
|
4211
|
+
const timeControl = (name, label) => {
|
|
4212
|
+
if (link === "rejected" || link === "incompatible") return control(false, down);
|
|
4213
|
+
if (name !== "write" && s.busy.has(name)) return control(false, busyReason(label));
|
|
4214
|
+
if (down) return control(false, down);
|
|
4215
|
+
if (!live) return control(false, reason("not-running", "no run is going: start one first"));
|
|
4216
|
+
const said = launcherAnswer(state, name);
|
|
4217
|
+
return control(said.reason === null, said.reason, said.caution);
|
|
4218
|
+
};
|
|
4219
|
+
const withReason = (base, code, message) => base.ok ? control(false, reason(code, message), base.caution) : base;
|
|
4220
|
+
const paused = state && !onItsWay(session) ? state.paused : null;
|
|
4221
|
+
const pauseBase = timeControl("pause", "pause");
|
|
4222
|
+
const pause = paused === true ? withReason(pauseBase, "paused", "the simulation is already paused") : pauseBase;
|
|
4223
|
+
const resumeBase = timeControl("resume", "resume");
|
|
4224
|
+
const resume = paused === false ? withReason(resumeBase, "not-paused", "the simulation is not paused") : resumeBase;
|
|
4225
|
+
const stepItem = state?.allowed["step"];
|
|
4226
|
+
const speedItem = state?.allowed["speed"];
|
|
4227
|
+
const speedMin = numberOf(speedItem, "min") ?? s.limits.speed_min;
|
|
4228
|
+
const speedMax = numberOf(speedItem, "max") ?? s.limits.speed_max;
|
|
4229
|
+
const runUntil = timeControl("run_until", "run until");
|
|
4230
|
+
let save;
|
|
4231
|
+
if (down) save = control(false, down);
|
|
4232
|
+
else if (s.allowed)
|
|
4233
|
+
save = fromServer(s.allowed.save, "the server does not save now", s.allowed.save.caution);
|
|
4234
|
+
else save = control(true);
|
|
4235
|
+
const controls = {
|
|
4236
|
+
start,
|
|
4237
|
+
stop,
|
|
4238
|
+
force_stop: force,
|
|
4239
|
+
pause,
|
|
4240
|
+
resume,
|
|
4241
|
+
step: {
|
|
4242
|
+
...timeControl("step", "step"),
|
|
4243
|
+
min_ms: numberOf(stepItem, "min_ms") ?? 1,
|
|
4244
|
+
max_ms: numberOf(stepItem, "max_ms") ?? s.limits.step_ms_max
|
|
4245
|
+
},
|
|
4246
|
+
run_until: runUntil,
|
|
4247
|
+
speed: {
|
|
4248
|
+
...timeControl("speed", "speed change"),
|
|
4249
|
+
min: speedMin,
|
|
4250
|
+
max: speedMax,
|
|
4251
|
+
// The launcher's promise (docs/simulation-events.md, `allowed`): "max" is accepted unless min equals max
|
|
4252
|
+
fastest: speedMin !== speedMax
|
|
4253
|
+
},
|
|
4254
|
+
save
|
|
4255
|
+
};
|
|
4256
|
+
return { controls, write: timeControl("write", "write") };
|
|
4257
|
+
}
|
|
4258
|
+
function linkProblem(s) {
|
|
4259
|
+
const link = linkOf(s);
|
|
4260
|
+
return link === "rejected" || link === "incompatible" || link === "offline" ? linkReason(link, s) : null;
|
|
4261
|
+
}
|
|
4262
|
+
function newest(candidates) {
|
|
4263
|
+
let best = null;
|
|
4264
|
+
for (const c of candidates) if (!best || c.stamp > best.stamp) best = c;
|
|
4265
|
+
return best?.problem ?? null;
|
|
4266
|
+
}
|
|
4267
|
+
function sameData(a, b) {
|
|
4268
|
+
if (Object.is(a, b)) return true;
|
|
4269
|
+
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
|
|
4270
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
4271
|
+
const ka = Object.keys(a);
|
|
4272
|
+
const kb = Object.keys(b);
|
|
4273
|
+
if (ka.length !== kb.length) return false;
|
|
4274
|
+
return ka.every(
|
|
4275
|
+
(key) => sameData(a[key], b[key])
|
|
4276
|
+
);
|
|
4277
|
+
}
|
|
4278
|
+
|
|
4279
|
+
// ../client/src/front-actions.ts
|
|
4280
|
+
function actionError(error) {
|
|
4281
|
+
if (error instanceof ActionError) return error;
|
|
4282
|
+
if (error instanceof HttpError) {
|
|
4283
|
+
if (error.status === 0) {
|
|
4284
|
+
return new ActionError(
|
|
4285
|
+
error.timedOut ? "no-answer" : "network",
|
|
4286
|
+
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`,
|
|
4287
|
+
"unknown"
|
|
4288
|
+
);
|
|
4289
|
+
}
|
|
4290
|
+
return new ActionError(
|
|
4291
|
+
error.problem?.code ?? `http-${error.status}`,
|
|
4292
|
+
error.message,
|
|
4293
|
+
"refused",
|
|
4294
|
+
error.problem?.findings ?? []
|
|
4295
|
+
);
|
|
4296
|
+
}
|
|
4297
|
+
return new ActionError("failed", errorMessage(error), "unknown");
|
|
4298
|
+
}
|
|
4299
|
+
var closedCheck = () => new ActionError("closed", "the client was closed before the check was sent", "refused");
|
|
4300
|
+
var MOVES = /* @__PURE__ */ new Set(["pause", "resume"]);
|
|
4301
|
+
var INTENT_FIELDS = /* @__PURE__ */ new Set([
|
|
4302
|
+
"vehicle_sil_run_request",
|
|
4303
|
+
"disable",
|
|
4304
|
+
"enable",
|
|
4305
|
+
"manual",
|
|
4306
|
+
"scenario",
|
|
4307
|
+
"variant",
|
|
4308
|
+
"params",
|
|
4309
|
+
"speed",
|
|
4310
|
+
"start_paused",
|
|
4311
|
+
"strict",
|
|
4312
|
+
"connect",
|
|
4313
|
+
"time_policy"
|
|
4314
|
+
]);
|
|
4315
|
+
var TEXT_INTENT_FIELDS = /* @__PURE__ */ new Set(["vehicle_sil_run_request", "variant", "strict"]);
|
|
4316
|
+
var noFileError = () => new ActionError(
|
|
4317
|
+
"no-file",
|
|
4318
|
+
"no configuration file was given and the server has none to start with: pass { file } (a path from client.low.configs())",
|
|
4319
|
+
"refused"
|
|
4320
|
+
);
|
|
4321
|
+
var FrontActions = class {
|
|
4322
|
+
constructor(src, idStart = 1 + Math.floor(Math.random() * 2 ** 40)) {
|
|
4323
|
+
this.src = src;
|
|
4324
|
+
this.nextId = idStart;
|
|
4325
|
+
this.closing.catch(() => void 0);
|
|
4326
|
+
this.busyValue = new Writable(/* @__PURE__ */ new Set(), Object.is, src.onError);
|
|
4327
|
+
this.failureValue = new Writable(null, Object.is, src.onError);
|
|
4328
|
+
this.busy = this.busyValue.readonly();
|
|
4329
|
+
this.failure = this.failureValue.readonly();
|
|
4330
|
+
this.stops.push(
|
|
4331
|
+
src.low.session.onMessages((batch) => this.onMessages(batch)),
|
|
4332
|
+
src.low.session.session.subscribe(() => this.evaluate())
|
|
4333
|
+
);
|
|
4334
|
+
}
|
|
4335
|
+
src;
|
|
4336
|
+
busyValue;
|
|
4337
|
+
failureValue;
|
|
4338
|
+
waiting = /* @__PURE__ */ new Map();
|
|
4339
|
+
inFlight = /* @__PURE__ */ new Map();
|
|
4340
|
+
/** The checks not answered yet, in the order they are sent: the first is on its way, the others wait. */
|
|
4341
|
+
checks = [];
|
|
4342
|
+
/** Rejects when the client closes: a check that waits ends with it. */
|
|
4343
|
+
close = () => void 0;
|
|
4344
|
+
closing = new Promise((_, reject) => this.close = reject);
|
|
4345
|
+
nextId;
|
|
4346
|
+
lastSim = null;
|
|
4347
|
+
stops = [];
|
|
4348
|
+
disposed = false;
|
|
4349
|
+
busy;
|
|
4350
|
+
failure;
|
|
4351
|
+
// --- run ---------------------------------------------------------------------------------------
|
|
4352
|
+
start(intent = {}, options = {}) {
|
|
4353
|
+
const request = this.requestOf(intent, options);
|
|
4354
|
+
if (request instanceof ActionError) return this.fail(request);
|
|
4355
|
+
const own = this.refusalOfStart();
|
|
4356
|
+
if (own) return this.fail(own);
|
|
4357
|
+
return this.guarded("start", () => this.src.low.run.start(request).then(() => void 0));
|
|
4358
|
+
}
|
|
4359
|
+
/**
|
|
4360
|
+
* Checks what `intent` would start (`api/check`). Its failure is the caller's: it is not kept for `status.problem`.
|
|
4361
|
+
* 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
|
|
4362
|
+
* refuses with `check-busy` when too many wait). A check of the same request as one that waits or is on its way
|
|
4363
|
+
* shares it (the parts and the screen of a page check the same page intent); with `fresh`, only one that waits (a
|
|
4364
|
+
* check that the user asks for again reads the file as it is now). A check whose callers have all aborted
|
|
4365
|
+
* (`signal`) while it waits is not sent, and neither is one that waits when the client closes (`closed`).
|
|
4366
|
+
*/
|
|
4367
|
+
check(intent = {}, options = {}) {
|
|
4368
|
+
const request = options.text === void 0 ? this.requestOf(intent, options) : this.textRequestOf(intent, options.file, options.text);
|
|
4369
|
+
if (request instanceof ActionError) return Promise.reject(request);
|
|
4370
|
+
if (this.disposed) return Promise.reject(closedCheck());
|
|
4371
|
+
const signal = options.signal ?? null;
|
|
4372
|
+
if (signal?.aborted) return Promise.reject(signal.reason);
|
|
4373
|
+
const key = options.text === void 0 ? JSON.stringify(request) : null;
|
|
4374
|
+
const going = key === null ? void 0 : this.checks.find((c) => c.key === key && !(options.fresh && c === this.checks[0]));
|
|
4375
|
+
if (going) {
|
|
4376
|
+
going.callers.push(signal);
|
|
4377
|
+
return going.promise;
|
|
4378
|
+
}
|
|
4379
|
+
return this.enqueue(key, [signal], () => this.src.low.check(request));
|
|
4380
|
+
}
|
|
4381
|
+
/** Reads a configuration file as it is saved. Its failure is the caller's: it is not kept for `status.problem`. */
|
|
4382
|
+
readConfig(options = {}) {
|
|
4383
|
+
const named = options.file ?? this.src.initialFile();
|
|
4384
|
+
if (named === null) return Promise.reject(noFileError());
|
|
4385
|
+
return this.src.low.config(named).catch((error) => {
|
|
4386
|
+
throw actionError(error);
|
|
4387
|
+
});
|
|
4388
|
+
}
|
|
4389
|
+
/** Saves a text as a configuration file. Its failure is the caller's: it is not kept for `status.problem`. */
|
|
4390
|
+
saveConfig(options) {
|
|
4391
|
+
const file = options.file ?? this.src.initialFile();
|
|
4392
|
+
if (file === null) return Promise.reject(noFileError());
|
|
4393
|
+
return this.src.low.saveConfig({ file, text: options.text, stamp: options.stamp }).catch((error) => {
|
|
4394
|
+
throw actionError(error);
|
|
4395
|
+
});
|
|
4396
|
+
}
|
|
4397
|
+
/** 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. */
|
|
4398
|
+
describeAgain(options = {}) {
|
|
4399
|
+
const file = options.file ?? this.src.initialFile();
|
|
4400
|
+
if (file === null) return Promise.reject(noFileError());
|
|
4401
|
+
if (this.disposed) return Promise.reject(closedCheck());
|
|
4402
|
+
const request = {
|
|
4403
|
+
file,
|
|
4404
|
+
...options.variant !== void 0 ? { variant: options.variant } : {}
|
|
4405
|
+
};
|
|
4406
|
+
const key = `describe:${JSON.stringify(request)}`;
|
|
4407
|
+
const going = this.checks.find((c) => c.key === key);
|
|
4408
|
+
if (going) return going.promise;
|
|
4409
|
+
return this.enqueue(key, [null], () => this.src.low.describe(request));
|
|
4410
|
+
}
|
|
4411
|
+
/** The line of the checks: one is sent after the answer to the one before. `key` null: nothing is shared. */
|
|
4412
|
+
enqueue(key, callers, run) {
|
|
4413
|
+
const send = () => run().catch((error) => {
|
|
4414
|
+
throw actionError(error);
|
|
4415
|
+
});
|
|
4416
|
+
const before = this.checks.at(-1)?.done;
|
|
4417
|
+
const promise = before ? Promise.race([
|
|
4418
|
+
before.then(() => {
|
|
4419
|
+
if (this.disposed) return Promise.reject(closedCheck());
|
|
4420
|
+
const aborted = callers.every((s) => s?.aborted) ? callers[0] : null;
|
|
4421
|
+
return aborted ? Promise.reject(aborted.reason) : send();
|
|
4422
|
+
}),
|
|
4423
|
+
this.closing
|
|
4424
|
+
]) : send();
|
|
4425
|
+
const leave = () => {
|
|
4426
|
+
this.checks.splice(
|
|
4427
|
+
this.checks.findIndex((c) => c.promise === promise),
|
|
4428
|
+
1
|
|
4429
|
+
);
|
|
4430
|
+
};
|
|
4431
|
+
this.checks.push({ key, callers, promise, done: promise.then(leave, leave) });
|
|
4432
|
+
return promise;
|
|
4433
|
+
}
|
|
4434
|
+
/** The body of api/run and api/check for `intent`, or why it cannot be sent. */
|
|
4435
|
+
requestOf(intent, options) {
|
|
4436
|
+
const file = options.file ?? this.src.initialFile();
|
|
4437
|
+
if (file === null) return noFileError();
|
|
4438
|
+
const unknown = Object.keys(intent).filter((k) => !INTENT_FIELDS.has(k));
|
|
4439
|
+
if (unknown.length > 0) {
|
|
4440
|
+
return new ActionError(
|
|
4441
|
+
"unknown-field",
|
|
4442
|
+
`the intent has ${unknown.join(", ")}, which start and check do not know: the fields are ${[...INTENT_FIELDS].join(", ")}`,
|
|
4443
|
+
"refused"
|
|
4444
|
+
);
|
|
4445
|
+
}
|
|
4446
|
+
return {
|
|
4447
|
+
file,
|
|
4448
|
+
disable: intent.disable ?? [],
|
|
4449
|
+
...intent.vehicle_sil_run_request ? { vehicle_sil_run_request: intent.vehicle_sil_run_request } : {},
|
|
4450
|
+
...intent.enable ? { enable: intent.enable } : {},
|
|
4451
|
+
...intent.manual ? { manual: intent.manual } : {},
|
|
4452
|
+
...intent.scenario !== void 0 ? { scenario: intent.scenario } : {},
|
|
4453
|
+
...intent.variant !== void 0 ? { variant: intent.variant } : {},
|
|
4454
|
+
...intent.params ? { params: intent.params } : {},
|
|
4455
|
+
...intent.speed !== void 0 ? { speed: intent.speed } : {},
|
|
4456
|
+
...intent.start_paused ? { start_paused: true } : {},
|
|
4457
|
+
...intent.strict ? { strict: true } : {},
|
|
4458
|
+
...intent.connect ? { connect: intent.connect } : {},
|
|
4459
|
+
...intent.time_policy !== void 0 ? { time_policy: intent.time_policy } : {}
|
|
4460
|
+
};
|
|
4461
|
+
}
|
|
4462
|
+
/** The body of api/check for a text: the server takes only the configuration (`variant`, `strict`), not a run's choices. */
|
|
4463
|
+
textRequestOf(intent, fileOption, text3) {
|
|
4464
|
+
const file = fileOption ?? this.src.initialFile();
|
|
4465
|
+
if (file === null) return noFileError();
|
|
4466
|
+
const unknown = Object.keys(intent).filter((k) => !TEXT_INTENT_FIELDS.has(k));
|
|
4467
|
+
if (unknown.length > 0) {
|
|
4468
|
+
return new ActionError(
|
|
4469
|
+
"unknown-field",
|
|
4470
|
+
`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(", ")}`,
|
|
4471
|
+
"refused"
|
|
4472
|
+
);
|
|
4473
|
+
}
|
|
4474
|
+
return {
|
|
4475
|
+
file,
|
|
4476
|
+
text: text3,
|
|
4477
|
+
...intent.vehicle_sil_run_request ? { vehicle_sil_run_request: intent.vehicle_sil_run_request } : {},
|
|
4478
|
+
...intent.variant !== void 0 ? { variant: intent.variant } : {},
|
|
4479
|
+
...intent.strict ? { strict: true } : {}
|
|
4480
|
+
};
|
|
4481
|
+
}
|
|
4482
|
+
/** What the client refuses before it sends a start: the connection, and a start of this page still on its way. */
|
|
4483
|
+
refusalOfStart() {
|
|
4484
|
+
const link = linkOf(this.src.snapshot());
|
|
4485
|
+
if (link === "rejected" || link === "incompatible") {
|
|
4486
|
+
const why = this.src.controls().start.reason;
|
|
4487
|
+
return new ActionError(link, why?.message ?? link, "refused");
|
|
4488
|
+
}
|
|
4489
|
+
return this.busyValue.get().has("start") ? new ActionError(
|
|
4490
|
+
"busy",
|
|
4491
|
+
"the previous start has not been answered yet: wait for it",
|
|
4492
|
+
"refused"
|
|
4493
|
+
) : null;
|
|
4494
|
+
}
|
|
4495
|
+
stop() {
|
|
4496
|
+
return this.once("stop", () => this.src.low.run.stop());
|
|
4497
|
+
}
|
|
4498
|
+
forceStop() {
|
|
4499
|
+
return this.once("force_stop", () => this.src.low.run.forceStop());
|
|
4500
|
+
}
|
|
4501
|
+
/** A stop asked again while its request is on its way is the same request (a double click sends nothing more). */
|
|
4502
|
+
once(name, send) {
|
|
4503
|
+
const running = this.inFlight.get(name);
|
|
4504
|
+
if (running) return running;
|
|
4505
|
+
const promise = this.guarded(name, () => send().then(() => void 0)).finally(() => {
|
|
4506
|
+
this.inFlight.delete(name);
|
|
4507
|
+
});
|
|
4508
|
+
this.inFlight.set(name, promise);
|
|
4509
|
+
return promise;
|
|
4510
|
+
}
|
|
4511
|
+
guarded(name, send) {
|
|
4512
|
+
this.failureValue.set(null);
|
|
4513
|
+
this.setBusy(name, true);
|
|
4514
|
+
return send().then(
|
|
4515
|
+
() => this.setBusy(name, false),
|
|
4516
|
+
(error) => {
|
|
4517
|
+
this.setBusy(name, false);
|
|
4518
|
+
throw this.record(actionError(error));
|
|
4519
|
+
}
|
|
4520
|
+
);
|
|
4521
|
+
}
|
|
4522
|
+
// --- time --------------------------------------------------------------------------------------
|
|
4523
|
+
pause() {
|
|
4524
|
+
return this.time("pause", { command: "pause" }, 0);
|
|
4525
|
+
}
|
|
4526
|
+
resume() {
|
|
4527
|
+
return this.time("resume", { command: "resume" }, 0);
|
|
4528
|
+
}
|
|
4529
|
+
step(ms) {
|
|
4530
|
+
if (!Number.isFinite(ms) || ms <= 0) {
|
|
4531
|
+
return this.fail(
|
|
4532
|
+
new ActionError(
|
|
4533
|
+
"invalid-argument",
|
|
4534
|
+
"step needs a number of milliseconds greater than 0",
|
|
4535
|
+
"refused"
|
|
4536
|
+
)
|
|
4537
|
+
);
|
|
4538
|
+
}
|
|
4539
|
+
return this.time("step", { command: "step", ms }, ms);
|
|
4540
|
+
}
|
|
4541
|
+
setSpeed(value) {
|
|
4542
|
+
if (value !== "max" && !(Number.isFinite(value) && value > 0)) {
|
|
4543
|
+
return this.fail(
|
|
4544
|
+
new ActionError(
|
|
4545
|
+
"invalid-argument",
|
|
4546
|
+
"the speed is a number greater than 0, or 'max'",
|
|
4547
|
+
"refused"
|
|
4548
|
+
)
|
|
4549
|
+
);
|
|
4550
|
+
}
|
|
4551
|
+
return this.time("speed", { command: "speed", value }, 0);
|
|
4552
|
+
}
|
|
4553
|
+
runUntil(ms) {
|
|
4554
|
+
if (!Number.isFinite(ms) || ms < 0) {
|
|
4555
|
+
return this.fail(
|
|
4556
|
+
new ActionError(
|
|
4557
|
+
"invalid-argument",
|
|
4558
|
+
"run_until needs a time in milliseconds, 0 or more",
|
|
4559
|
+
"refused"
|
|
4560
|
+
)
|
|
4561
|
+
);
|
|
4562
|
+
}
|
|
4563
|
+
return this.time("run_until", { command: "run_until", at_ms: ms }, ms);
|
|
4564
|
+
}
|
|
4565
|
+
time(op, body, amount) {
|
|
4566
|
+
this.failureValue.set(null);
|
|
4567
|
+
const snapshot = this.src.snapshot();
|
|
4568
|
+
const link = linkOf(snapshot);
|
|
4569
|
+
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;
|
|
4570
|
+
if (own) return this.fail(new ActionError(own.code, own.message, "refused"));
|
|
4571
|
+
const code = this.src.controls()[op === "pause" ? "pause" : "resume"].reason?.code;
|
|
4572
|
+
if (op === "pause" && code === "paused" || op === "resume" && code === "not-paused") {
|
|
4573
|
+
return Promise.resolve();
|
|
4574
|
+
}
|
|
4575
|
+
const session = snapshot.session;
|
|
4576
|
+
const id = this.nextId++;
|
|
4577
|
+
return new Promise((resolve, reject) => {
|
|
4578
|
+
const waiting = {
|
|
4579
|
+
id,
|
|
4580
|
+
op,
|
|
4581
|
+
amount,
|
|
4582
|
+
session: session?.id ?? -1,
|
|
4583
|
+
stage: "sent",
|
|
4584
|
+
target: 0,
|
|
4585
|
+
from: 0,
|
|
4586
|
+
exact: false,
|
|
4587
|
+
timer: void 0,
|
|
4588
|
+
resolve,
|
|
4589
|
+
reject
|
|
4590
|
+
};
|
|
4591
|
+
this.waiting.set(id, waiting);
|
|
4592
|
+
this.setBusy(op, true);
|
|
4593
|
+
waiting.timer = setTimeout(() => {
|
|
4594
|
+
this.settle(
|
|
4595
|
+
waiting,
|
|
4596
|
+
new ActionError(
|
|
4597
|
+
"no-answer",
|
|
4598
|
+
`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`,
|
|
4599
|
+
"unknown"
|
|
4600
|
+
)
|
|
4601
|
+
);
|
|
4602
|
+
}, this.src.answerTimeoutMs);
|
|
4603
|
+
this.src.http({ method: "POST", path: "api/time", body: { ...body, id } }, (outcome) => {
|
|
4604
|
+
if (!outcome.ok) this.settle(waiting, actionError(outcome.error));
|
|
4605
|
+
});
|
|
4606
|
+
});
|
|
4607
|
+
}
|
|
4608
|
+
/** Ends a waiting command: with an error, or (null) as done. A command ended twice is ended once. */
|
|
4609
|
+
settle(waiting, error, report = true) {
|
|
4610
|
+
if (this.waiting.get(waiting.id) !== waiting) return;
|
|
4611
|
+
clearTimeout(waiting.timer);
|
|
4612
|
+
this.waiting.delete(waiting.id);
|
|
4613
|
+
if (waiting.stage === "sent") this.setBusy(waiting.op, this.stillSent(waiting.op));
|
|
4614
|
+
if (error) {
|
|
4615
|
+
if (report) this.record(error);
|
|
4616
|
+
waiting.reject(error);
|
|
4617
|
+
} else waiting.resolve();
|
|
4618
|
+
}
|
|
4619
|
+
stillSent(op) {
|
|
4620
|
+
for (const w of this.waiting.values()) if (w.op === op && w.stage === "sent") return true;
|
|
4621
|
+
return false;
|
|
4622
|
+
}
|
|
4623
|
+
setBusy(name, on) {
|
|
4624
|
+
const now = this.busyValue.get();
|
|
4625
|
+
if (now.has(name) === on) return;
|
|
4626
|
+
const next = new Set(now);
|
|
4627
|
+
if (on) next.add(name);
|
|
4628
|
+
else next.delete(name);
|
|
4629
|
+
this.busyValue.set(next);
|
|
4630
|
+
}
|
|
4631
|
+
/** The launcher's events: an answer to a command of ours, and commands of other senders. */
|
|
4632
|
+
onMessages(batch) {
|
|
4633
|
+
let sim = this.lastSim;
|
|
4634
|
+
for (const message of batch) {
|
|
4635
|
+
if (message.type !== "event") continue;
|
|
4636
|
+
const event = message.event;
|
|
4637
|
+
if (event.event === "time") sim = event.sim_ms;
|
|
4638
|
+
if (event.event !== "command") continue;
|
|
4639
|
+
const mine = event.id === null ? void 0 : this.waiting.get(event.id);
|
|
4640
|
+
if (mine && mine.session === message.session) this.answered(mine, event, sim);
|
|
4641
|
+
else if (event.accepted && event.command !== null && MOVES.has(event.command)) {
|
|
4642
|
+
this.interruptMoving(
|
|
4643
|
+
null,
|
|
4644
|
+
"another command (from another page or from stdin) came before it arrived"
|
|
4645
|
+
);
|
|
4646
|
+
}
|
|
4647
|
+
}
|
|
4648
|
+
this.lastSim = this.src.low.session.session.get()?.time?.simMs ?? sim;
|
|
4649
|
+
this.evaluate();
|
|
4650
|
+
}
|
|
4651
|
+
answered(waiting, event, sim) {
|
|
4652
|
+
if (!event.accepted) {
|
|
4653
|
+
this.settle(
|
|
4654
|
+
waiting,
|
|
4655
|
+
new ActionError(
|
|
4656
|
+
event.reason ?? "refused",
|
|
4657
|
+
event.message ?? `the launcher did not accept ${waiting.op}`,
|
|
4658
|
+
"refused"
|
|
4659
|
+
)
|
|
4660
|
+
);
|
|
4661
|
+
return;
|
|
4662
|
+
}
|
|
4663
|
+
if (waiting.op === "pause" || waiting.op === "resume") {
|
|
4664
|
+
this.interruptMoving(waiting, `${waiting.op} of this page came before it arrived`, false);
|
|
4665
|
+
}
|
|
4666
|
+
if (waiting.op === "step" || waiting.op === "run_until") {
|
|
4667
|
+
clearTimeout(waiting.timer);
|
|
4668
|
+
waiting.stage = "moving";
|
|
4669
|
+
waiting.from = sim ?? 0;
|
|
4670
|
+
waiting.exact = event.at_ms !== null;
|
|
4671
|
+
waiting.target = event.at_ms ?? (waiting.op === "step" ? waiting.from + (event.ms ?? waiting.amount) : waiting.amount);
|
|
4672
|
+
this.setBusy(waiting.op, this.stillSent(waiting.op));
|
|
4673
|
+
return;
|
|
4674
|
+
}
|
|
4675
|
+
this.settle(waiting, null);
|
|
4676
|
+
}
|
|
4677
|
+
/** Ends the steps and run_untils on their way (except `keep`) as interrupted. */
|
|
4678
|
+
interruptMoving(keep, why, report = true) {
|
|
4679
|
+
for (const w of [...this.waiting.values()]) {
|
|
4680
|
+
if (w !== keep && w.stage === "moving") {
|
|
4681
|
+
this.settle(
|
|
4682
|
+
w,
|
|
4683
|
+
new ActionError(
|
|
4684
|
+
"interrupted",
|
|
4685
|
+
`${w.op} did not arrive: ${why}; read clock to see where the time is`,
|
|
4686
|
+
"unknown"
|
|
4687
|
+
),
|
|
4688
|
+
report
|
|
4689
|
+
);
|
|
4690
|
+
}
|
|
4691
|
+
}
|
|
4692
|
+
}
|
|
4693
|
+
/** Ends what the state of the run decides: the run is over, time has arrived, or a stop is on its way. */
|
|
4694
|
+
evaluate() {
|
|
4695
|
+
if (this.waiting.size === 0) return;
|
|
4696
|
+
const session = this.src.low.session.session.get();
|
|
4697
|
+
for (const w of [...this.waiting.values()]) {
|
|
4698
|
+
if (!session || session.id !== w.session || !session.launcher.running || session.result) {
|
|
4699
|
+
this.settle(
|
|
4700
|
+
w,
|
|
4701
|
+
new ActionError(
|
|
4702
|
+
"not-running",
|
|
4703
|
+
`the run ended (or another one began) before ${w.op} was done: look at status`,
|
|
4704
|
+
"unknown"
|
|
4705
|
+
)
|
|
4706
|
+
);
|
|
4707
|
+
continue;
|
|
4708
|
+
}
|
|
4709
|
+
if (w.stage !== "moving") continue;
|
|
4710
|
+
const state = session.launcherState;
|
|
4711
|
+
if ((state?.stop?.requests ?? 0) > 0 || session.stopRequests > 0) {
|
|
4712
|
+
this.settle(
|
|
4713
|
+
w,
|
|
4714
|
+
new ActionError("interrupted", `${w.op} did not arrive: a stop was asked for`, "unknown"),
|
|
4715
|
+
false
|
|
4716
|
+
// a stop by the operator is not a problem to show
|
|
4717
|
+
);
|
|
4718
|
+
continue;
|
|
4719
|
+
}
|
|
4720
|
+
const stands = standsAt(session);
|
|
4721
|
+
if (stands !== null && (w.exact || stands > w.from) && stands >= w.target)
|
|
4722
|
+
this.settle(w, null);
|
|
4723
|
+
}
|
|
4724
|
+
}
|
|
4725
|
+
// --- bookkeeping -------------------------------------------------------------------------------
|
|
4726
|
+
/** Keeps the error for `status.problem`. */
|
|
4727
|
+
record(error) {
|
|
4728
|
+
this.failureValue.set({ error, run: this.src.run(), stamp: this.src.stamp() });
|
|
4729
|
+
return error;
|
|
4730
|
+
}
|
|
4731
|
+
fail(error) {
|
|
4732
|
+
return Promise.reject(this.record(error));
|
|
4733
|
+
}
|
|
4734
|
+
/** Stops waiting (the client closes): what is waiting ends as unknown, and a check that waits is not sent. */
|
|
4735
|
+
dispose() {
|
|
4736
|
+
if (this.disposed) return;
|
|
4737
|
+
this.disposed = true;
|
|
4738
|
+
this.close(closedCheck());
|
|
4739
|
+
for (const stop of this.stops) stop();
|
|
4740
|
+
for (const w of [...this.waiting.values()]) {
|
|
4741
|
+
this.settle(
|
|
4742
|
+
w,
|
|
4743
|
+
new ActionError("closed", `the client was closed before ${w.op} was done`, "unknown")
|
|
4744
|
+
);
|
|
4745
|
+
}
|
|
4746
|
+
}
|
|
4747
|
+
};
|
|
4748
|
+
|
|
4749
|
+
// ../client/src/front-outside.ts
|
|
4750
|
+
var isObject2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4751
|
+
var text2 = (value) => typeof value === "string" ? value : null;
|
|
4752
|
+
function entriesOf(answer) {
|
|
4753
|
+
const entries = [];
|
|
4754
|
+
const networks = answer.connections["networks"];
|
|
4755
|
+
for (const network of Array.isArray(networks) ? networks : []) {
|
|
4756
|
+
if (!isObject2(network) || !isObject2(network["list"])) continue;
|
|
4757
|
+
const list = network["list"];
|
|
4758
|
+
const backend = text2(list["backend"]) ?? text2(network["backend"]);
|
|
4759
|
+
for (const target of Array.isArray(list["targets"]) ? list["targets"] : []) {
|
|
4760
|
+
if (!isObject2(target)) continue;
|
|
4761
|
+
const value = text2(target["value"]);
|
|
4762
|
+
if (value === null) continue;
|
|
4763
|
+
entries.push({
|
|
4764
|
+
backend,
|
|
4765
|
+
value,
|
|
4766
|
+
label: text2(target["label"]) ?? value,
|
|
4767
|
+
detail: text2(target["detail"]) ?? "",
|
|
4768
|
+
usable: target["usable"] === true,
|
|
4769
|
+
reason: text2(target["reason"])
|
|
4770
|
+
});
|
|
4771
|
+
}
|
|
4772
|
+
if (isObject2(list["error"])) {
|
|
4773
|
+
entries.push({ backend, error: text2(list["error"]["message"]) ?? "the list failed" });
|
|
4774
|
+
}
|
|
4775
|
+
}
|
|
4776
|
+
const findings = answer.connections["findings"];
|
|
4777
|
+
for (const finding of Array.isArray(findings) ? findings : []) {
|
|
4778
|
+
if (isObject2(finding) && finding["severity"] === "error" && text2(finding["message"]) !== null) {
|
|
4779
|
+
entries.push({ backend: null, error: text2(finding["message"]) });
|
|
4780
|
+
}
|
|
4781
|
+
}
|
|
4782
|
+
return entries;
|
|
4783
|
+
}
|
|
4784
|
+
function outsideRows(low, onError) {
|
|
4785
|
+
const counts = new Writable(null, Object.is, onError);
|
|
4786
|
+
const stop = low.session.onMessages((batch) => {
|
|
4787
|
+
let next = counts.get();
|
|
4788
|
+
for (const message of batch) {
|
|
4789
|
+
if (message.type !== "event" || message.event.event !== "outside") continue;
|
|
4790
|
+
const { network, to_outside, from_outside } = message.event;
|
|
4791
|
+
const networks = new Map(next?.session === message.session ? next.networks : []);
|
|
4792
|
+
networks.set(network, { to: to_outside, from: from_outside });
|
|
4793
|
+
next = { session: message.session, networks };
|
|
4794
|
+
}
|
|
4795
|
+
if (next !== counts.get()) counts.set(next);
|
|
4796
|
+
});
|
|
4797
|
+
const value = derived(
|
|
4798
|
+
[low.session.session, counts],
|
|
4799
|
+
() => {
|
|
4800
|
+
const session = low.session.session.get();
|
|
4801
|
+
if (!session?.launcher.running) return [];
|
|
4802
|
+
const known = counts.get();
|
|
4803
|
+
const of = known?.session === session.id ? known.networks : /* @__PURE__ */ new Map();
|
|
4804
|
+
return (session.launcherState?.outside ?? []).map((row) => {
|
|
4805
|
+
const count2 = of.get(row.network);
|
|
4806
|
+
return {
|
|
4807
|
+
network: row.network,
|
|
4808
|
+
target: row.target,
|
|
4809
|
+
participant: row.participant,
|
|
4810
|
+
link: row.link,
|
|
4811
|
+
bus: row.bus,
|
|
4812
|
+
condition: row.condition,
|
|
4813
|
+
reasons: row.reasons,
|
|
4814
|
+
nothing_received: row.nothing_received,
|
|
4815
|
+
to_outside: count2?.to ?? null,
|
|
4816
|
+
from_outside: count2?.from ?? null
|
|
4817
|
+
};
|
|
4818
|
+
});
|
|
4819
|
+
},
|
|
4820
|
+
sameData,
|
|
4821
|
+
onError
|
|
4822
|
+
);
|
|
4823
|
+
return { value, stop };
|
|
4824
|
+
}
|
|
4825
|
+
|
|
4826
|
+
// ../client/src/front-variable.ts
|
|
4827
|
+
var WHY_BLOCKED = {
|
|
4828
|
+
"read-only": "this variable is an output of the ECU: it cannot be written",
|
|
4829
|
+
disconnected: "the connection to the GUI server is down: wait until it is back",
|
|
4830
|
+
"not-ready": "the variables are not available now (no run, or the run has no Control Server)",
|
|
4831
|
+
ended: "the run has ended: start a new one to write again",
|
|
4832
|
+
missing: "this variable is not in the current run: check the names (ECU and variable)",
|
|
4833
|
+
"peer-disconnected": "the ECU is not connected to the Control Server now",
|
|
4834
|
+
parameter: "a parameter can be written only before the first step: start the run paused",
|
|
4835
|
+
"no-range": "the variable has no range (min and max)",
|
|
4836
|
+
"no-value": "there is no value yet"
|
|
4837
|
+
};
|
|
4838
|
+
function noteOf(condition) {
|
|
4839
|
+
switch (condition.kind) {
|
|
4840
|
+
case "live":
|
|
4841
|
+
return null;
|
|
4842
|
+
case "paused":
|
|
4843
|
+
return "the value at the paused time";
|
|
4844
|
+
case "waiting":
|
|
4845
|
+
return "no value has arrived yet";
|
|
4846
|
+
case "missing":
|
|
4847
|
+
return "this variable is not in the current run: check the names (ECU and variable)";
|
|
4848
|
+
case "ended":
|
|
4849
|
+
return "the last value of the run that has ended";
|
|
4850
|
+
case "unavailable":
|
|
4851
|
+
return "the variables are not available now (no run, or the run has no Control Server)";
|
|
4852
|
+
case "stale":
|
|
4853
|
+
return {
|
|
4854
|
+
connection: "the connection to the GUI server is down: the value may be out of date",
|
|
4855
|
+
reconnecting: "the server is connecting to the launcher again: the value may be out of date",
|
|
4856
|
+
peer: "the ECU is not connected to the Control Server: the value may be out of date",
|
|
4857
|
+
reading: "reading the values keeps failing: the value may be out of date"
|
|
4858
|
+
}[condition.why];
|
|
4859
|
+
}
|
|
4860
|
+
}
|
|
4861
|
+
function textOf(bound) {
|
|
4862
|
+
const value = bound.reading?.value;
|
|
4863
|
+
if (value === void 0 || value === null) return "";
|
|
4864
|
+
const item = bound.info?.enum?.find((e) => e.value === value);
|
|
4865
|
+
return item ? item.name : String(value);
|
|
4866
|
+
}
|
|
4867
|
+
function refOf(ref) {
|
|
4868
|
+
if (typeof ref !== "string") return { peer: ref.peer, name: ref.name };
|
|
4869
|
+
const dot = ref.indexOf(".");
|
|
4870
|
+
if (dot <= 0 || dot === ref.length - 1) {
|
|
4871
|
+
throw new ActionError(
|
|
4872
|
+
"invalid-argument",
|
|
4873
|
+
`'${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)`,
|
|
4874
|
+
"refused"
|
|
4875
|
+
);
|
|
4876
|
+
}
|
|
4877
|
+
return { peer: ref.slice(0, dot), name: ref.slice(dot + 1) };
|
|
4878
|
+
}
|
|
4879
|
+
function whyOf(bound, launcher) {
|
|
4880
|
+
if (bound.block === null) return launcher.reason;
|
|
4881
|
+
if (bound.block === "launcher") return bound.launcherReason ?? launcher.reason;
|
|
4882
|
+
return { code: bound.block, message: WHY_BLOCKED[bound.block] };
|
|
4883
|
+
}
|
|
4884
|
+
function viewOf(bound, track, launcher) {
|
|
4885
|
+
const status = bound.writeStatus;
|
|
4886
|
+
const failed = status.kind === "invalid" || status.kind === "dropped" || "code" in status ? {
|
|
4887
|
+
code: "code" in status && status.code ? status.code : status.kind,
|
|
4888
|
+
message: status.message
|
|
4889
|
+
} : null;
|
|
4890
|
+
return {
|
|
4891
|
+
value: bound.reading?.value ?? null,
|
|
4892
|
+
text: textOf(bound),
|
|
4893
|
+
unit: bound.info?.unit ?? "",
|
|
4894
|
+
min: bound.info?.min ?? null,
|
|
4895
|
+
max: bound.info?.max ?? null,
|
|
4896
|
+
step: bound.info?.step ?? null,
|
|
4897
|
+
sim_ms: bound.reading?.sampleMs ?? null,
|
|
4898
|
+
stale: bound.condition.kind === "stale",
|
|
4899
|
+
note: noteOf(bound.condition),
|
|
4900
|
+
availability: bound.availability,
|
|
4901
|
+
can_write: bound.block === null && launcher.ok,
|
|
4902
|
+
why: whyOf(bound, launcher),
|
|
4903
|
+
writing: track.writing || status.kind === "sending" || status.kind === "queued" || bound.pending !== null,
|
|
4904
|
+
problem: track.problem ?? failed,
|
|
4905
|
+
condition: bound.condition,
|
|
4906
|
+
block: bound.block,
|
|
4907
|
+
write_status: status
|
|
4908
|
+
};
|
|
4909
|
+
}
|
|
4910
|
+
function writeFailure(error) {
|
|
4911
|
+
if (error instanceof WriteError) {
|
|
4912
|
+
return new ActionError(
|
|
4913
|
+
error.code ?? error.kind,
|
|
4914
|
+
error.message,
|
|
4915
|
+
error.kind === "no-answer" || error.kind === "closed" ? "unknown" : "refused"
|
|
4916
|
+
);
|
|
4917
|
+
}
|
|
4918
|
+
return actionError(error);
|
|
4919
|
+
}
|
|
4920
|
+
function makeVariable(low, ref, refuse, launcher) {
|
|
4921
|
+
const track = new Writable({ writing: false, problem: null }, sameData);
|
|
4922
|
+
const view = new Writable(null, sameData);
|
|
4923
|
+
let binding = null;
|
|
4924
|
+
let count2 = 0;
|
|
4925
|
+
let stops = [];
|
|
4926
|
+
const refresh = () => {
|
|
4927
|
+
if (binding) view.set(viewOf(binding.state.get(), track.get(), launcher.get()));
|
|
4928
|
+
};
|
|
4929
|
+
let peeked = null;
|
|
4930
|
+
const peek = () => {
|
|
4931
|
+
const once = low.variables.bind(ref, { visible: false });
|
|
4932
|
+
try {
|
|
4933
|
+
const next = viewOf(once.state.get(), track.get(), launcher.get());
|
|
4934
|
+
if (!peeked || !sameData(peeked, next)) peeked = next;
|
|
4935
|
+
return peeked;
|
|
4936
|
+
} finally {
|
|
4937
|
+
once.close();
|
|
4938
|
+
}
|
|
4939
|
+
};
|
|
4940
|
+
const readable = {
|
|
4941
|
+
get: () => {
|
|
4942
|
+
if (!binding) return peek();
|
|
4943
|
+
return view.get();
|
|
4944
|
+
},
|
|
4945
|
+
subscribe: (listener) => {
|
|
4946
|
+
if (count2++ === 0) {
|
|
4947
|
+
binding = low.variables.bind(ref);
|
|
4948
|
+
stops = [
|
|
4949
|
+
binding.state.subscribe(refresh),
|
|
4950
|
+
track.subscribe(refresh),
|
|
4951
|
+
launcher.subscribe(refresh)
|
|
4952
|
+
];
|
|
4953
|
+
refresh();
|
|
4954
|
+
}
|
|
4955
|
+
const off = view.subscribe((v) => v && listener(v));
|
|
4956
|
+
let done = false;
|
|
4957
|
+
return () => {
|
|
4958
|
+
if (done) return;
|
|
4959
|
+
done = true;
|
|
4960
|
+
off();
|
|
4961
|
+
if (--count2 === 0) {
|
|
4962
|
+
for (const stop of stops) stop();
|
|
4963
|
+
stops = [];
|
|
4964
|
+
binding?.close();
|
|
4965
|
+
binding = null;
|
|
4966
|
+
view.set(null);
|
|
4967
|
+
}
|
|
4968
|
+
};
|
|
4969
|
+
}
|
|
4970
|
+
};
|
|
4971
|
+
return {
|
|
4972
|
+
get: readable.get,
|
|
4973
|
+
subscribe: readable.subscribe,
|
|
4974
|
+
write: (value) => {
|
|
4975
|
+
const own = refuse();
|
|
4976
|
+
if (own) return Promise.reject(own);
|
|
4977
|
+
track.set({ writing: true, problem: null });
|
|
4978
|
+
return low.variables.write({ [ref.peer]: { [ref.name]: value } }).then(
|
|
4979
|
+
() => {
|
|
4980
|
+
track.set({ writing: false, problem: null });
|
|
4981
|
+
},
|
|
4982
|
+
(error) => {
|
|
4983
|
+
const failure = writeFailure(error);
|
|
4984
|
+
track.set({ writing: false, problem: { code: failure.code, message: failure.message } });
|
|
4985
|
+
throw failure;
|
|
4986
|
+
}
|
|
4987
|
+
);
|
|
4988
|
+
}
|
|
4989
|
+
};
|
|
4990
|
+
}
|
|
4991
|
+
|
|
4992
|
+
// ../client/src/front.ts
|
|
4993
|
+
function makeFront(options, onClose) {
|
|
4994
|
+
const { client: low, http, onError } = buildClient(options);
|
|
4995
|
+
let counter = 0;
|
|
4996
|
+
const stamp = () => ++counter;
|
|
4997
|
+
const stamps = /* @__PURE__ */ new Map();
|
|
4998
|
+
const stampFor = (key) => {
|
|
4999
|
+
let value = stamps.get(key);
|
|
5000
|
+
if (value === void 0) stamps.set(key, value = stamp());
|
|
5001
|
+
return value;
|
|
5002
|
+
};
|
|
5003
|
+
const initialFile = () => low.app.get()?.initial_file ?? null;
|
|
5004
|
+
let actions;
|
|
5005
|
+
const snapshot = () => ({
|
|
5006
|
+
connection: low.connection.state.get(),
|
|
5007
|
+
failures: low.connection.failures.get(),
|
|
5008
|
+
closedBefore: low.connection.lastClose.get() !== null,
|
|
5009
|
+
rejected: low.session.rejected.get(),
|
|
5010
|
+
incompatible: low.session.incompatible.get(),
|
|
5011
|
+
ready: low.session.ready.get(),
|
|
5012
|
+
session: low.session.session.get(),
|
|
5013
|
+
allowed: low.session.allowed.get(),
|
|
5014
|
+
limits: low.limits.get(),
|
|
5015
|
+
busy: actions.busy.get()
|
|
5016
|
+
});
|
|
5017
|
+
const sources = [
|
|
5018
|
+
low.connection.state,
|
|
5019
|
+
low.connection.failures,
|
|
5020
|
+
low.connection.lastClose,
|
|
5021
|
+
low.session.rejected,
|
|
5022
|
+
low.session.incompatible,
|
|
5023
|
+
low.session.ready,
|
|
5024
|
+
low.session.session,
|
|
5025
|
+
low.session.allowed,
|
|
5026
|
+
low.limits,
|
|
5027
|
+
low.app
|
|
5028
|
+
];
|
|
5029
|
+
const controls = {
|
|
5030
|
+
get: () => controlsValue.get(),
|
|
5031
|
+
subscribe: (listener) => controlsValue.subscribe(listener)
|
|
5032
|
+
};
|
|
5033
|
+
const run = () => runOf(snapshot());
|
|
5034
|
+
actions = new FrontActions({
|
|
5035
|
+
low,
|
|
5036
|
+
http,
|
|
5037
|
+
snapshot,
|
|
5038
|
+
controls: () => controls.get(),
|
|
5039
|
+
run,
|
|
5040
|
+
initialFile,
|
|
5041
|
+
answerTimeoutMs: options.answerTimeoutMs ?? ANSWER_TIMEOUT_MS,
|
|
5042
|
+
onError,
|
|
5043
|
+
stamp
|
|
5044
|
+
});
|
|
5045
|
+
const controlsValue = derived(
|
|
5046
|
+
[...sources, actions.busy],
|
|
5047
|
+
() => {
|
|
5048
|
+
const s = snapshot();
|
|
5049
|
+
return controlsOf(s, runOf(s));
|
|
5050
|
+
},
|
|
5051
|
+
sameData,
|
|
5052
|
+
onError
|
|
5053
|
+
);
|
|
5054
|
+
const writeControl = derived(
|
|
5055
|
+
[...sources, actions.busy],
|
|
5056
|
+
() => {
|
|
5057
|
+
const s = snapshot();
|
|
5058
|
+
return writeOf(s, runOf(s));
|
|
5059
|
+
},
|
|
5060
|
+
sameData,
|
|
5061
|
+
onError
|
|
5062
|
+
);
|
|
5063
|
+
const status = derived(
|
|
5064
|
+
[...sources, actions.busy, actions.failure],
|
|
5065
|
+
() => {
|
|
5066
|
+
const s = snapshot();
|
|
5067
|
+
const base = statusOf(s, initialFile());
|
|
5068
|
+
let problem = linkProblem(s);
|
|
5069
|
+
if (!problem) {
|
|
5070
|
+
const id = s.session?.id;
|
|
5071
|
+
const candidates = [];
|
|
5072
|
+
if (base.run === "crashed" && base.result) {
|
|
5073
|
+
candidates.push({
|
|
5074
|
+
stamp: stampFor(`crashed:${id}`),
|
|
5075
|
+
problem: { code: "launcher-crashed", message: base.result.message }
|
|
5076
|
+
});
|
|
5077
|
+
}
|
|
5078
|
+
if (base.run === "ended" && base.result && !base.result.ok) {
|
|
5079
|
+
candidates.push({
|
|
5080
|
+
stamp: stampFor(`failed:${id}`),
|
|
5081
|
+
problem: { code: "run-failed", message: base.result.message }
|
|
5082
|
+
});
|
|
5083
|
+
}
|
|
5084
|
+
const failure = actions.failure.get();
|
|
5085
|
+
if (failure && failure.run === base.run) {
|
|
5086
|
+
candidates.push({
|
|
5087
|
+
stamp: failure.stamp,
|
|
5088
|
+
problem: { code: failure.error.code, message: failure.error.message }
|
|
5089
|
+
});
|
|
5090
|
+
}
|
|
5091
|
+
problem = newest(candidates);
|
|
5092
|
+
}
|
|
5093
|
+
return { ...base, problem };
|
|
5094
|
+
},
|
|
5095
|
+
sameData,
|
|
5096
|
+
onError
|
|
5097
|
+
);
|
|
5098
|
+
const clock = derived(
|
|
5099
|
+
sources,
|
|
5100
|
+
() => clockOf(snapshot()),
|
|
5101
|
+
sameData,
|
|
5102
|
+
onError
|
|
5103
|
+
);
|
|
5104
|
+
const scenario = derived(
|
|
5105
|
+
[low.session.session],
|
|
5106
|
+
() => {
|
|
5107
|
+
const view = low.session.session.get()?.scenario;
|
|
5108
|
+
return view ? {
|
|
5109
|
+
file: view.file,
|
|
5110
|
+
name: view.name,
|
|
5111
|
+
status: view.status,
|
|
5112
|
+
steps: view.steps,
|
|
5113
|
+
timeline_url: view.timelineUrl
|
|
5114
|
+
} : null;
|
|
5115
|
+
},
|
|
5116
|
+
sameData,
|
|
5117
|
+
onError
|
|
5118
|
+
);
|
|
5119
|
+
const outside = outsideRows(low, onError);
|
|
5120
|
+
const variables = /* @__PURE__ */ new Map();
|
|
5121
|
+
let closed = false;
|
|
5122
|
+
return {
|
|
5123
|
+
low,
|
|
5124
|
+
status,
|
|
5125
|
+
clock,
|
|
5126
|
+
controls,
|
|
5127
|
+
scenario,
|
|
5128
|
+
outside: outside.value,
|
|
5129
|
+
connections: ({ network }, listOptions = {}) => {
|
|
5130
|
+
const file = listOptions.file ?? initialFile();
|
|
5131
|
+
if (file === null) {
|
|
5132
|
+
return Promise.reject(noFileError());
|
|
5133
|
+
}
|
|
5134
|
+
return low.connections({ file, network }).then(entriesOf, (error) => {
|
|
5135
|
+
throw actionError(error);
|
|
5136
|
+
});
|
|
5137
|
+
},
|
|
5138
|
+
scenarios: (listOptions = {}) => {
|
|
5139
|
+
const file = listOptions.file ?? initialFile();
|
|
5140
|
+
if (file === null) {
|
|
5141
|
+
return Promise.reject(
|
|
5142
|
+
new ActionError(
|
|
5143
|
+
"no-file",
|
|
5144
|
+
"no configuration file was given and the server has none to start with: pass { file } (a path from client.low.configs())",
|
|
5145
|
+
"refused"
|
|
5146
|
+
)
|
|
5147
|
+
);
|
|
5148
|
+
}
|
|
5149
|
+
return low.scenarios(file).then(
|
|
5150
|
+
(list) => list.scenarios,
|
|
5151
|
+
(error) => {
|
|
5152
|
+
throw actionError(error);
|
|
5153
|
+
}
|
|
5154
|
+
);
|
|
5155
|
+
},
|
|
5156
|
+
check: (intent, checkOptions) => actions.check(intent, checkOptions),
|
|
5157
|
+
readConfig: (readOptions2) => actions.readConfig(readOptions2),
|
|
5158
|
+
describeAgain: (describeOptions) => actions.describeAgain(describeOptions),
|
|
5159
|
+
saveConfig: (saveOptions) => actions.saveConfig(saveOptions),
|
|
5160
|
+
run: {
|
|
5161
|
+
start: (intent, startOptions) => actions.start(intent, startOptions),
|
|
5162
|
+
stop: () => actions.stop(),
|
|
5163
|
+
forceStop: () => actions.forceStop()
|
|
5164
|
+
},
|
|
5165
|
+
time: {
|
|
5166
|
+
pause: () => actions.pause(),
|
|
5167
|
+
resume: () => actions.resume(),
|
|
5168
|
+
step: (ms) => actions.step(ms),
|
|
5169
|
+
setSpeed: (value) => actions.setSpeed(value),
|
|
5170
|
+
runUntil: (ms) => actions.runUntil(ms)
|
|
5171
|
+
},
|
|
5172
|
+
variable: (ref) => {
|
|
5173
|
+
const named = refOf(ref);
|
|
5174
|
+
const key = `${named.peer}\0${named.name}`;
|
|
5175
|
+
let variable = variables.get(key);
|
|
5176
|
+
if (!variable) {
|
|
5177
|
+
variable = makeVariable(
|
|
5178
|
+
low,
|
|
5179
|
+
named,
|
|
5180
|
+
() => {
|
|
5181
|
+
const link = linkOf(snapshot());
|
|
5182
|
+
return link === "rejected" || link === "incompatible" ? new ActionError(link, writeControl.get().reason?.message ?? link, "refused") : null;
|
|
5183
|
+
},
|
|
5184
|
+
writeControl
|
|
5185
|
+
);
|
|
5186
|
+
variables.set(key, variable);
|
|
5187
|
+
}
|
|
5188
|
+
return variable;
|
|
5189
|
+
},
|
|
5190
|
+
close: () => {
|
|
5191
|
+
if (closed) return;
|
|
5192
|
+
closed = true;
|
|
5193
|
+
outside.stop();
|
|
5194
|
+
actions.dispose();
|
|
5195
|
+
low.close();
|
|
5196
|
+
onClose();
|
|
5197
|
+
}
|
|
5198
|
+
};
|
|
5199
|
+
}
|
|
5200
|
+
var shared = null;
|
|
5201
|
+
async function open(options, onClose) {
|
|
5202
|
+
const front = makeFront(
|
|
5203
|
+
{
|
|
5204
|
+
baseUrl: options.base_url,
|
|
5205
|
+
token: options.token,
|
|
5206
|
+
origin: options.origin,
|
|
5207
|
+
http: options.http,
|
|
5208
|
+
socket: options.socket,
|
|
5209
|
+
answerTimeoutMs: options.answer_timeout_ms,
|
|
5210
|
+
onError: options.on_error
|
|
5211
|
+
},
|
|
5212
|
+
onClose
|
|
5213
|
+
);
|
|
5214
|
+
front.low.connect();
|
|
5215
|
+
try {
|
|
5216
|
+
await front.low.loadApp();
|
|
5217
|
+
} catch (error) {
|
|
5218
|
+
front.close();
|
|
5219
|
+
throw actionError(error);
|
|
5220
|
+
}
|
|
5221
|
+
return front;
|
|
5222
|
+
}
|
|
5223
|
+
function createFront(options) {
|
|
5224
|
+
return makeFront(options, () => void 0);
|
|
5225
|
+
}
|
|
5226
|
+
function pageOptions() {
|
|
5227
|
+
const page = globalThis.window;
|
|
5228
|
+
const token = page ? takeToken(page) : null;
|
|
5229
|
+
if (!page || token === null) {
|
|
5230
|
+
throw new ActionError(
|
|
5231
|
+
"no-token",
|
|
5232
|
+
"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 }",
|
|
5233
|
+
"refused"
|
|
5234
|
+
);
|
|
5235
|
+
}
|
|
5236
|
+
return { base_url: new URL("/", page.location.href).href, token };
|
|
5237
|
+
}
|
|
5238
|
+
function connect(options) {
|
|
5239
|
+
if (options) return open(options, () => void 0);
|
|
5240
|
+
if (shared) return shared;
|
|
5241
|
+
let promise;
|
|
5242
|
+
try {
|
|
5243
|
+
promise = open(pageOptions(), () => {
|
|
5244
|
+
if (shared === promise) shared = null;
|
|
5245
|
+
});
|
|
5246
|
+
} catch (error) {
|
|
5247
|
+
return Promise.reject(error);
|
|
5248
|
+
}
|
|
5249
|
+
shared = promise;
|
|
5250
|
+
promise.catch(() => {
|
|
5251
|
+
if (shared === promise) shared = null;
|
|
5252
|
+
});
|
|
5253
|
+
return promise;
|
|
5254
|
+
}
|
|
5255
|
+
function watch(source, fn) {
|
|
5256
|
+
const list = Array.isArray(source) ? source : [source];
|
|
5257
|
+
const call = fn;
|
|
5258
|
+
const run = () => call(...list.map((s) => s.get()));
|
|
5259
|
+
const stops = list.map((s) => s.subscribe(run));
|
|
5260
|
+
run();
|
|
5261
|
+
return () => stops.forEach((stop) => stop());
|
|
5262
|
+
}
|
|
5263
|
+
function until(source, test, options = {}) {
|
|
5264
|
+
return new Promise((resolve, reject) => {
|
|
5265
|
+
let timer;
|
|
5266
|
+
const cleanups = [];
|
|
5267
|
+
const finish = (done) => {
|
|
5268
|
+
clearTimeout(timer);
|
|
5269
|
+
cleanups.forEach((cleanup) => cleanup());
|
|
5270
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
5271
|
+
done();
|
|
5272
|
+
};
|
|
5273
|
+
const onAbort = () => finish(() => reject(new ActionError("aborted", "the wait was aborted", "unknown")));
|
|
5274
|
+
if (options.signal?.aborted) {
|
|
5275
|
+
reject(new ActionError("aborted", "the wait was aborted", "unknown"));
|
|
5276
|
+
return;
|
|
5277
|
+
}
|
|
5278
|
+
const check = (value) => {
|
|
5279
|
+
if (test(value)) finish(() => resolve(value));
|
|
5280
|
+
};
|
|
5281
|
+
cleanups.push(source.subscribe(check));
|
|
5282
|
+
options.signal?.addEventListener("abort", onAbort);
|
|
5283
|
+
if (options.timeout_ms !== void 0) {
|
|
5284
|
+
timer = setTimeout(
|
|
5285
|
+
() => finish(
|
|
5286
|
+
() => reject(
|
|
5287
|
+
new ActionError(
|
|
5288
|
+
"timeout",
|
|
5289
|
+
`the condition did not hold within ${options.timeout_ms / 1e3} s: look at the state before you wait again`,
|
|
5290
|
+
"unknown"
|
|
5291
|
+
)
|
|
5292
|
+
)
|
|
5293
|
+
),
|
|
5294
|
+
options.timeout_ms
|
|
5295
|
+
);
|
|
5296
|
+
}
|
|
5297
|
+
const first = source.get();
|
|
5298
|
+
if (test(first)) finish(() => resolve(first));
|
|
5299
|
+
});
|
|
5300
|
+
}
|
|
3633
5301
|
export {
|
|
3634
5302
|
ANSWER_TIMEOUT_MS,
|
|
5303
|
+
ActionError,
|
|
3635
5304
|
BATCH_MS,
|
|
3636
5305
|
DEFAULT_LIMITS,
|
|
3637
5306
|
DEFAULT_TIMEOUT_MS,
|
|
3638
5307
|
DROPPED_MESSAGE,
|
|
3639
|
-
FEATURE_MANUAL,
|
|
3640
|
-
FEATURE_SCENARIO,
|
|
3641
|
-
FEATURE_SCENARIO_CONTROL,
|
|
3642
|
-
FEATURE_SPEED,
|
|
3643
|
-
FEATURE_START_PAUSED,
|
|
3644
|
-
FEATURE_TIME_COMMANDS,
|
|
3645
5308
|
HISTORY_MAX,
|
|
3646
5309
|
HISTORY_TOTAL_MAX,
|
|
3647
5310
|
HttpError,
|
|
@@ -3655,19 +5318,27 @@ export {
|
|
|
3655
5318
|
WATCH_PERIOD_MS,
|
|
3656
5319
|
WRITE_TIMEOUT_MS,
|
|
3657
5320
|
WriteError,
|
|
5321
|
+
connect,
|
|
3658
5322
|
createClient,
|
|
5323
|
+
createFront,
|
|
3659
5324
|
errorMessage,
|
|
3660
5325
|
fetchTransport,
|
|
3661
5326
|
hasRange,
|
|
5327
|
+
isHolding,
|
|
3662
5328
|
isWriteError,
|
|
5329
|
+
launcherAnswer,
|
|
3663
5330
|
phaseIndex,
|
|
3664
5331
|
readAppInfo,
|
|
3665
5332
|
readCheckResponse,
|
|
3666
5333
|
readConfigList,
|
|
5334
|
+
readConfigText,
|
|
5335
|
+
readConnections,
|
|
3667
5336
|
readDashboardResponse,
|
|
3668
5337
|
readRecording,
|
|
5338
|
+
readSavedConfig,
|
|
3669
5339
|
readScenarioList,
|
|
3670
5340
|
readServerMessage,
|
|
5341
|
+
readSessionAllowed,
|
|
3671
5342
|
readSessionResponse,
|
|
3672
5343
|
readTimeResponse,
|
|
3673
5344
|
readVariablesSummary,
|
|
@@ -3675,7 +5346,9 @@ export {
|
|
|
3675
5346
|
runOutcome,
|
|
3676
5347
|
severityRank,
|
|
3677
5348
|
takeToken,
|
|
5349
|
+
until,
|
|
3678
5350
|
valueCondition,
|
|
5351
|
+
watch,
|
|
3679
5352
|
webSocketFactory,
|
|
3680
5353
|
writeBlock
|
|
3681
5354
|
};
|