@vehicle-sil/gui-client 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -632,22 +632,22 @@ var readRunParticipant = (value, path, u) => {
632
632
  };
633
633
  var readRunTiming = (value, path, u) => {
634
634
  const f = object(value, path);
635
- const count2 = (key) => field(f, path, key, soft(nullable(number), null, u));
635
+ const count = (key) => field(f, path, key, soft(nullable(number), null, u));
636
636
  return withRaw(f, {
637
637
  speed: field(f, path, "speed", soft(readSpeed, null, u)),
638
- time_step_ms: count2("time_step_ms"),
639
- ecu_step_ms: count2("ecu_step_ms"),
640
- step_delay_ms: count2("step_delay_ms"),
641
- late_tolerance_ms: count2("late_tolerance_ms"),
642
- sim_ms: count2("sim_ms"),
643
- wall_ms: count2("wall_ms"),
644
- actual_speed: count2("actual_speed"),
645
- paced_steps: count2("paced_steps"),
646
- late_steps: count2("late_steps"),
647
- max_late_ms: count2("max_late_ms"),
648
- slipped_ms: count2("slipped_ms"),
649
- late_ms: count2("late_ms"),
650
- paused_ms: count2("paused_ms")
638
+ time_step_ms: count("time_step_ms"),
639
+ ecu_step_ms: count("ecu_step_ms"),
640
+ step_delay_ms: count("step_delay_ms"),
641
+ late_tolerance_ms: count("late_tolerance_ms"),
642
+ sim_ms: count("sim_ms"),
643
+ wall_ms: count("wall_ms"),
644
+ actual_speed: count("actual_speed"),
645
+ paced_steps: count("paced_steps"),
646
+ late_steps: count("late_steps"),
647
+ max_late_ms: count("max_late_ms"),
648
+ slipped_ms: count("slipped_ms"),
649
+ late_ms: count("late_ms"),
650
+ paused_ms: count("paused_ms")
651
651
  });
652
652
  };
653
653
  var readTrafficUnplaced = (value, path, u) => {
@@ -780,14 +780,14 @@ var readRunResult = (value, path, u) => {
780
780
  };
781
781
  var PHASES = ["checking", "starting", "waiting", "running", "stopping", "ended"];
782
782
  function readTimeFields(f, path, u) {
783
- const count2 = (key) => field(f, path, key, soft(nullable(number), null, u));
783
+ const count = (key) => field(f, path, key, soft(nullable(number), null, u));
784
784
  return {
785
785
  sim_ms: field(f, path, "sim_ms", number),
786
- actual_speed: count2("actual_speed"),
787
- late_steps: count2("late_steps"),
788
- max_late_ms: count2("max_late_ms"),
789
- slipped_ms: count2("slipped_ms"),
790
- late_ms: count2("late_ms")
786
+ actual_speed: count("actual_speed"),
787
+ late_steps: count("late_steps"),
788
+ max_late_ms: count("max_late_ms"),
789
+ slipped_ms: count("slipped_ms"),
790
+ late_ms: count("late_ms")
791
791
  };
792
792
  }
793
793
  function readCommandFields(f, path, u) {
@@ -1157,10 +1157,32 @@ var readSummaryParticipant = (value, path, u) => {
1157
1157
  )
1158
1158
  };
1159
1159
  };
1160
+ var readRuntimeStatus = (value, path) => {
1161
+ const f = object(value, path);
1162
+ return {
1163
+ mode: field(f, path, "mode", string),
1164
+ state: field(f, path, "state", string),
1165
+ config: field(f, path, "config", nullable(string)),
1166
+ reason: field(f, path, "reason", nullable(string)),
1167
+ message: field(f, path, "message", nullable(string))
1168
+ };
1169
+ };
1170
+ var readPrepareResponse = (value) => {
1171
+ const path = "response";
1172
+ const f = object(value, path);
1173
+ return {
1174
+ instance: field(f, path, "instance", string),
1175
+ runtime: field(f, path, "runtime", readRuntimeStatus)
1176
+ };
1177
+ };
1160
1178
  var readSummaryLauncher = (value, path) => {
1161
1179
  const f = object(value, path);
1180
+ const mode = field(f, path, "mode", optional(string, void 0));
1181
+ const processAlive = field(f, path, "process_alive", optional(boolean, void 0));
1162
1182
  return {
1163
1183
  running: field(f, path, "running", boolean),
1184
+ ...mode === void 0 ? {} : { mode },
1185
+ ...processAlive === void 0 ? {} : { process_alive: processAlive },
1164
1186
  exit_code: field(f, path, "exit_code", nullable(integer)),
1165
1187
  signal: field(f, path, "signal", nullable(integer)),
1166
1188
  silent_s: field(f, path, "silent_s", optional(nullable(integer), null))
@@ -1317,6 +1339,7 @@ var readServerAllowed = (value, path) => {
1317
1339
  };
1318
1340
  };
1319
1341
  function partlyRecord(read2, u) {
1342
+ if (!u) return record(read2);
1320
1343
  return (value, path) => {
1321
1344
  const out = {};
1322
1345
  for (const [key, item] of Object.entries(object(value, path))) {
@@ -1338,6 +1361,12 @@ var readSessionAllowed = (value) => field(
1338
1361
  "allowed",
1339
1362
  optional(nullable(readServerAllowed), null)
1340
1363
  );
1364
+ var readSessionRuntime = (value) => field(
1365
+ object(value, "response"),
1366
+ "response",
1367
+ "runtime",
1368
+ optional(nullable(readRuntimeStatus), void 0)
1369
+ );
1341
1370
  var readTimeResponse = (value) => {
1342
1371
  const path = "response";
1343
1372
  const f = object(value, path);
@@ -1349,89 +1378,140 @@ var readTimeResponse = (value) => {
1349
1378
  };
1350
1379
  };
1351
1380
  var readAvailability = (value) => value === "unknown" || value === "inactive" ? value : "active";
1352
- var readOperationReport = (value, path) => {
1381
+ var safeInteger = (value, path) => {
1382
+ if (!Number.isSafeInteger(value)) throw new ProtocolError(path, "an integer");
1383
+ return value;
1384
+ };
1385
+ var nonNegativeInteger = (value, path) => {
1386
+ const n = safeInteger(value, path);
1387
+ if (n < 0) throw new ProtocolError(path, "a non-negative integer");
1388
+ return n;
1389
+ };
1390
+ var readOperationReport = (value, path, u) => {
1353
1391
  const f = object(value, path);
1354
1392
  return {
1355
- seq: field(f, path, "seq", integer),
1393
+ seq: field(f, path, "seq", safeInteger),
1356
1394
  state: field(f, path, "state", string),
1357
- done: field(f, path, "done", boolean),
1395
+ done: field(f, path, "done", lenient(boolean, false, u)),
1358
1396
  peers: field(
1359
1397
  f,
1360
1398
  path,
1361
1399
  "peers",
1362
- record((v, p) => {
1363
- const t = object(v, p);
1364
- return {
1365
- state: field(t, p, "state", string),
1366
- applied_at_ms: field(t, p, "applied_at_ms", optional(nullable(number), null)),
1367
- late: field(t, p, "late", optional(boolean, false)),
1368
- reason: field(t, p, "reason", optional(nullable(string), null)),
1369
- applied_writes: field(t, p, "applied_writes", optional(nullable(integer), null)),
1370
- failed_write: field(t, p, "failed_write", optional(nullable(integer), null))
1371
- };
1372
- })
1400
+ soft(
1401
+ partlyRecord((v, p) => {
1402
+ const t = object(v, p);
1403
+ return {
1404
+ state: field(t, p, "state", lenient(string, "unknown", u)),
1405
+ applied_at_ms: field(t, p, "applied_at_ms", soft(nullable(number), null, u)),
1406
+ late: field(t, p, "late", soft(boolean, false, u)),
1407
+ reason: field(t, p, "reason", soft(nullable(string), null, u)),
1408
+ applied_writes: field(
1409
+ t,
1410
+ p,
1411
+ "applied_writes",
1412
+ soft(nullable(nonNegativeInteger), null, u)
1413
+ ),
1414
+ failed_write: field(t, p, "failed_write", soft(nullable(nonNegativeInteger), null, u))
1415
+ };
1416
+ }, u),
1417
+ {},
1418
+ u
1419
+ )
1373
1420
  )
1374
1421
  };
1375
1422
  };
1376
- var readVariableSummary = (value, path) => {
1423
+ var readEnumItem = (value, path) => {
1424
+ const item = object(value, path);
1425
+ return { name: field(item, path, "name", string), value: field(item, path, "value", number) };
1426
+ };
1427
+ var readVariableSummary = (value, path, u) => {
1377
1428
  const f = object(value, path);
1378
1429
  return {
1379
1430
  name: field(f, path, "name", string),
1380
- type: field(f, path, "type", string),
1381
- role: field(f, path, "role", optional(string, "output")),
1382
- writable: field(f, path, "writable", optional(boolean, false)),
1383
- unit: field(f, path, "unit", optional(string, "")),
1384
- min: field(f, path, "min", optional(nullable(number), null)),
1385
- max: field(f, path, "max", optional(nullable(number), null)),
1386
- step: field(f, path, "step", optional(nullable(number), null)),
1387
- description: field(f, path, "description", optional(string, "")),
1431
+ type: field(f, path, "type", lenient(string, "", u)),
1432
+ role: field(f, path, "role", soft(string, "output", u)),
1433
+ writable: field(f, path, "writable", soft(boolean, false, u)),
1434
+ unit: field(f, path, "unit", soft(string, "", u)),
1435
+ min: field(f, path, "min", soft(nullable(number), null, u)),
1436
+ max: field(f, path, "max", soft(nullable(number), null, u)),
1437
+ step: field(f, path, "step", soft(nullable(number), null, u)),
1438
+ description: field(f, path, "description", soft(string, "", u)),
1388
1439
  enum: field(
1389
1440
  f,
1390
1441
  path,
1391
1442
  "enum",
1392
- optional(
1393
- nullable(
1394
- array((v, p) => {
1395
- const item = object(v, p);
1396
- return { name: field(item, p, "name", string), value: field(item, p, "value", number) };
1397
- })
1398
- ),
1399
- null
1443
+ soft(
1444
+ nullable((v, p) => {
1445
+ if (!Array.isArray(v)) throw new ProtocolError(p, "an array");
1446
+ return items(readEnumItem, u)(v, p);
1447
+ }),
1448
+ null,
1449
+ u
1400
1450
  )
1401
1451
  ),
1402
1452
  availability: readAvailability(f["availability"])
1403
1453
  };
1404
1454
  };
1405
- var readVariablesSummary = (value) => readVariables(value, "variables");
1406
- var readVariables = (value, path) => {
1455
+ var readVariablesSummary = (value) => readVariablesReport(value, "variables");
1456
+ var readVariablesReport = (value, path, u) => {
1407
1457
  const f = object(value, path);
1408
1458
  return {
1409
- ...f["rev"] === void 0 ? {} : { rev: field(f, path, "rev", optional(nullable(integer), null)) },
1410
- state: field(f, path, "state", string),
1411
- reason: field(f, path, "reason", optional(nullable(string), null)),
1459
+ ...f["rev"] === void 0 ? {} : { rev: field(f, path, "rev", soft(nullable(nonNegativeInteger), null, u)) },
1460
+ state: field(f, path, "state", lenient(string, "unknown", u)),
1461
+ reason: field(f, path, "reason", soft(nullable(string), null, u)),
1412
1462
  peers: field(
1413
1463
  f,
1414
1464
  path,
1415
1465
  "peers",
1416
- optional(
1417
- array((v, p) => {
1466
+ soft(
1467
+ items((v, p) => {
1418
1468
  const peer = object(v, p);
1419
1469
  return {
1420
1470
  name: field(peer, p, "name", string),
1421
- connected: field(peer, p, "connected", optional(boolean, false)),
1422
- variables: field(peer, p, "variables", optional(array(readVariableSummary), []))
1471
+ connected: field(peer, p, "connected", soft(boolean, false, u)),
1472
+ variables: field(
1473
+ peer,
1474
+ p,
1475
+ "variables",
1476
+ soft(
1477
+ items((item, ip) => readVariableSummary(item, ip, u), u),
1478
+ [],
1479
+ u
1480
+ )
1481
+ )
1423
1482
  };
1424
- }),
1425
- []
1483
+ }, u),
1484
+ [],
1485
+ u
1426
1486
  )
1427
1487
  ),
1428
- peers_omitted: field(f, path, "peers_omitted", optional(integer, 0)),
1429
- variables_omitted: field(f, path, "variables_omitted", optional(integer, 0)),
1430
- operations: field(f, path, "operations", optional(array(readOperationReport), [])),
1431
- operations_from_seq: field(f, path, "operations_from_seq", optional(integer, null)),
1432
- operations_open_omitted: field(f, path, "operations_open_omitted", optional(integer, 0))
1488
+ peers_omitted: field(f, path, "peers_omitted", soft(nonNegativeInteger, 0, u)),
1489
+ variables_omitted: field(f, path, "variables_omitted", soft(nonNegativeInteger, 0, u)),
1490
+ operations: field(
1491
+ f,
1492
+ path,
1493
+ "operations",
1494
+ soft(
1495
+ items((item, ip) => readOperationReport(item, ip, u), u),
1496
+ [],
1497
+ u
1498
+ )
1499
+ ),
1500
+ operations_from_seq: field(
1501
+ f,
1502
+ path,
1503
+ "operations_from_seq",
1504
+ soft(nullable(safeInteger), null, u)
1505
+ ),
1506
+ operations_open_omitted: field(
1507
+ f,
1508
+ path,
1509
+ "operations_open_omitted",
1510
+ soft(nonNegativeInteger, 0, u)
1511
+ )
1433
1512
  };
1434
1513
  };
1514
+ var readVariables = readVariablesReport;
1435
1515
  var readWriteResponse = (value) => {
1436
1516
  const f = object(value, "response");
1437
1517
  return {
@@ -1529,15 +1609,20 @@ var readServerMessage = (value) => {
1529
1609
  const f = object(value, path);
1530
1610
  const type = field(f, path, "type", string);
1531
1611
  switch (type) {
1532
- case "hello":
1612
+ case "hello": {
1533
1613
  version(f, path, "vehicle_sil_gui", PROTOCOL_VERSION);
1614
+ const runtime = field(f, path, "runtime", optional(nullable(readRuntimeStatus), void 0));
1534
1615
  return {
1535
1616
  type,
1536
1617
  instance: field(f, path, "instance", string),
1537
1618
  session: field(f, path, "session", nullable(readSessionSummary)),
1538
1619
  allowed: field(f, path, "allowed", optional(nullable(readServerAllowed), null)),
1539
- replay: field(f, path, "replay", nullable(readReplay))
1620
+ replay: field(f, path, "replay", nullable(readReplay)),
1621
+ ...runtime === void 0 ? {} : { runtime }
1540
1622
  };
1623
+ }
1624
+ case "runtime":
1625
+ return { type, runtime: field(f, path, "runtime", readRuntimeStatus) };
1541
1626
  case "event": {
1542
1627
  const event = field(f, path, "event", (v, p) => readLauncherEvent(v, p, true));
1543
1628
  return event && { type, session: field(f, path, "session", integer), event };
@@ -1708,241 +1793,16 @@ function fetchTransport(options) {
1708
1793
  send(url, init).then(async (response) => {
1709
1794
  const body = await response.json().catch(() => null);
1710
1795
  clearTimeout(timer);
1711
- if (timedOut) {
1712
- fail(null);
1713
- return;
1714
- }
1715
- done(
1716
- response.ok ? { ok: true, body } : { ok: false, error: HttpError.from(response.status, response.statusText, body) }
1717
- );
1718
- }, fail).finally(() => clearTimeout(timer));
1719
- };
1720
- }
1721
-
1722
- // ../client/src/run.ts
1723
- function answerMissing(path, error) {
1724
- if (!error.timedOut) return null;
1725
- return path === "api/run" ? `${error.message}: the server may still start the run (it checks the file again when it has changed); whether it did shows in the session over the WebSocket` : `${error.message}: the server may have done it; the session over the WebSocket shows what happened`;
1726
- }
1727
- var RunControl = class {
1728
- constructor(feed, transport, onError = rethrowLater, startTimeoutMs = () => 0) {
1729
- this.feed = feed;
1730
- this.transport = transport;
1731
- this.startTimeoutMs = startTimeoutMs;
1732
- this.startSending = new Writable(false, Object.is, onError);
1733
- this.stopSending = new Writable(null, Object.is, onError);
1734
- this.pendingRevision = new Writable(0, Object.is, onError);
1735
- this.stopAskedWhileStarting = new Writable(false, Object.is, onError);
1736
- this.failure = new Writable(null, Object.is, onError);
1737
- this.starting = this.startSending.readonly();
1738
- this.stopping = this.stopSending.readonly();
1739
- this.currentStopping = derived(
1740
- [this.pendingRevision, this.startSending, feed.session],
1741
- () => {
1742
- const key = this.startSending.get() ? this.startOperation : JSON.stringify(feed.currentTarget());
1743
- return [...this.pendingStops].filter((pending) => pending.key === key).at(-1)?.action ?? null;
1744
- },
1745
- Object.is,
1746
- onError
1747
- );
1748
- this.stopWhileStarting = this.stopAskedWhileStarting.readonly();
1749
- this.error = derived(
1750
- [this.failure, feed.session],
1751
- () => {
1752
- const failure = this.failure.get();
1753
- const session = feed.session.get();
1754
- if (!failure) return null;
1755
- const same = failure.session === (session?.id ?? null) && failure.running === (session?.launcher.running ?? false);
1756
- return same ? failure.message : null;
1757
- },
1758
- Object.is,
1759
- onError
1760
- );
1761
- }
1762
- feed;
1763
- transport;
1764
- startTimeoutMs;
1765
- startOperation = null;
1766
- pendingStops = /* @__PURE__ */ new Set();
1767
- pendingRevision;
1768
- startSending;
1769
- stopSending;
1770
- stopAskedWhileStarting;
1771
- failure;
1772
- starting;
1773
- stopping;
1774
- currentStopping;
1775
- stopWhileStarting;
1776
- error;
1777
- /** Starts a run. */
1778
- start(request) {
1779
- if (this.startSending.get()) return Promise.reject(new Error("a start is already pending"));
1780
- let resolveStart;
1781
- let rejectStart;
1782
- const operation = new Promise(
1783
- (resolve, reject) => {
1784
- resolveStart = resolve;
1785
- rejectStart = reject;
1786
- }
1787
- );
1788
- this.startOperation = operation;
1789
- this.stopAskedWhileStarting.set(false);
1790
- this.startSending.set(true);
1791
- let instance = null;
1792
- this.send(
1793
- "api/run",
1794
- request,
1795
- this.startTimeoutMs() || void 0,
1796
- () => {
1797
- this.startSending.set(false);
1798
- },
1799
- (seen) => {
1800
- instance = seen;
1801
- }
1802
- ).then((summary) => resolveStart({ summary, instance }), rejectStart);
1803
- return operation.then(({ summary }) => summary);
1804
- }
1805
- /** Stops in order (waits for the participants to end). Asking again never turns it into a stop without waiting. */
1806
- stop() {
1807
- return this.requestStop(false);
1808
- }
1809
- /** Stops without waiting (kills the participants). */
1810
- forceStop() {
1811
- return this.requestStop(true);
1812
- }
1813
- captureStop() {
1814
- const starting = this.startSending.get() ? this.startOperation : null;
1815
- const target = starting ? null : this.feed.currentTarget();
1816
- return {
1817
- key: starting ?? JSON.stringify(target),
1818
- send: (force) => this.requestStop(force, starting, target)
1819
- };
1820
- }
1821
- requestStop(force, starting = this.startSending.get() ? this.startOperation : null, target = starting ? null : this.feed.currentTarget()) {
1822
- const session = this.feed.session.get();
1823
- const pending = {
1824
- action: force ? "force" : "stop",
1825
- starting: !!starting,
1826
- key: starting ?? JSON.stringify(target)
1827
- };
1828
- this.pendingStops.add(pending);
1829
- this.pendingRevision.update((n) => n + 1);
1830
- this.stopSending.set(pending.action);
1831
- const done = () => {
1832
- this.pendingStops.delete(pending);
1833
- this.pendingRevision.update((n) => n + 1);
1834
- const remaining = [...this.pendingStops];
1835
- this.stopAskedWhileStarting.set(remaining.some((p) => p.starting));
1836
- this.stopSending.set(remaining.at(-1)?.action ?? null);
1837
- };
1838
- if (!starting) {
1839
- if (!target) {
1840
- const message = "no session and server instance are known: no stop was sent; reconnect and check the current run";
1841
- this.failure.set({
1842
- message,
1843
- session: session?.id ?? null,
1844
- running: session?.launcher.running ?? false
1845
- });
1846
- done();
1847
- return Promise.reject(new Error(message));
1848
- }
1849
- return this.send("api/stop-session", { force, ...target }, void 0, done);
1850
- }
1851
- this.stopAskedWhileStarting.set(true);
1852
- return starting.then(
1853
- ({ summary, instance }) => {
1854
- if (!summary || !instance) {
1855
- const message = "the start answer did not identify the run; no stop was sent";
1856
- const session2 = this.feed.session.get();
1857
- this.failure.set({
1858
- message,
1859
- session: session2?.id ?? null,
1860
- running: session2?.launcher.running ?? false
1861
- });
1862
- throw new Error(message);
1863
- }
1864
- pending.key = JSON.stringify({ session: summary.id, instance });
1865
- this.pendingRevision.update((n) => n + 1);
1866
- return this.send(
1867
- "api/stop-session",
1868
- { force, session: summary.id, instance },
1869
- void 0,
1870
- () => void 0
1871
- );
1872
- },
1873
- (error) => {
1874
- const message = `the start was not confirmed; no stop was sent: ${errorMessage(error)}`;
1875
- const session2 = this.feed.session.get();
1876
- this.failure.set({
1877
- message,
1878
- session: session2?.id ?? null,
1879
- running: session2?.launcher.running ?? false
1880
- });
1881
- throw new Error(message);
1882
- }
1883
- ).finally(done);
1884
- }
1885
- /**
1886
- * Sends and applies the summary in the answer. done is called after the answer (failures too), before the Promise
1887
- * settles.
1888
- */
1889
- send(path, body, timeoutMs, done, onInstance) {
1890
- const incompatible = this.feed.incompatible.get();
1891
- if (incompatible) {
1892
- done();
1893
- return Promise.reject(new Error(incompatible));
1894
- }
1895
- this.failure.set(null);
1896
- return new Promise((resolve, reject) => {
1897
- this.transport({ method: "POST", path, body, timeoutMs }, (outcome) => {
1898
- if (!outcome.ok) {
1899
- const failure = path === "api/stop-session" && outcome.error.status === 404 ? new HttpError(404, outcome.error.statusText, {
1900
- code: "targeted-stop-unsupported",
1901
- message: "the GUI server cannot stop a particular session: no stop was sent; use the GUI server of this release"
1902
- }) : outcome.error;
1903
- const session = this.feed.session.get();
1904
- this.failure.set({
1905
- message: answerMissing(path, failure) ?? errorMessage(failure),
1906
- session: session?.id ?? null,
1907
- running: session?.launcher.running ?? false
1908
- });
1909
- done();
1910
- reject(failure);
1911
- return;
1912
- }
1913
- let summary = null;
1914
- try {
1915
- const instance = path === "api/stop-session" ? body.instance : readSessionInstance(outcome.body);
1916
- summary = readSessionResponse(outcome.body);
1917
- if (path === "api/stop-session" && (!summary || summary.id !== body.session)) {
1918
- throw new Error("the stop answer did not identify the requested session");
1919
- }
1920
- onInstance?.(instance);
1921
- this.feed.adopt(summary, instance);
1922
- } catch (error) {
1923
- this.feed.report(
1924
- error instanceof ProtocolError ? `unreadable answer: ${error.message}` : String(error)
1925
- );
1926
- const missingInstance = error instanceof ProtocolError && error.path === "response.instance";
1927
- if (path === "api/stop-session" || missingInstance) {
1928
- const message = missingInstance ? `${error.message}. The run may have started. Check the current run before retrying` : "the stop answer was unreadable: check the session before trying again";
1929
- const session = this.feed.session.get();
1930
- this.failure.set({
1931
- message,
1932
- session: session?.id ?? null,
1933
- running: session?.launcher.running ?? false
1934
- });
1935
- done();
1936
- reject(new Error(message));
1937
- return;
1938
- }
1939
- }
1940
- done();
1941
- resolve(summary);
1942
- });
1943
- });
1944
- }
1945
- };
1796
+ if (timedOut) {
1797
+ fail(null);
1798
+ return;
1799
+ }
1800
+ done(
1801
+ response.ok ? { ok: true, body } : { ok: false, error: HttpError.from(response.status, response.statusText, body) }
1802
+ );
1803
+ }, fail).finally(() => clearTimeout(timer));
1804
+ };
1805
+ }
1946
1806
 
1947
1807
  // ../client/src/session-state.ts
1948
1808
  function launcherAnswer(state, name) {
@@ -2037,11 +1897,25 @@ function withStep(steps, step) {
2037
1897
  if (steps[i].index === step.index) return steps.map((s, j) => j === i ? step : s);
2038
1898
  return [...steps.slice(0, i), step, ...steps.slice(i)];
2039
1899
  }
1900
+ function isSessionRunning(session) {
1901
+ return !!session && session.state === "running";
1902
+ }
1903
+ function isRunActive(session) {
1904
+ return !!session && session.state === "running" && session.launcher.running;
1905
+ }
1906
+ function isLauncherFinishing(session) {
1907
+ return !!session && isRunActive(session) && session.result !== null;
1908
+ }
1909
+ function isLauncherAlive(session) {
1910
+ if (!session) return false;
1911
+ const launcher = session.launcher;
1912
+ return launcher.processAlive ?? launcher.process_alive ?? launcher.running;
1913
+ }
2040
1914
  function isHolding(session) {
2041
- return !!session && session.launcher.running && session.launcherState?.holding === true;
1915
+ return isRunActive(session) && session.launcherState?.holding === true;
2042
1916
  }
2043
1917
  function runOutcome(session) {
2044
- if (session.launcher.running) {
1918
+ if (isRunActive(session)) {
2045
1919
  if (session.result) return "finishing";
2046
1920
  if (session.stopRequests >= 2) return "forcing";
2047
1921
  return session.stopRequests >= 1 ? "stopping" : "running";
@@ -2058,6 +1932,7 @@ function sessionFromSummary(summary) {
2058
1932
  manual: summary.manual,
2059
1933
  speed: summary.speed,
2060
1934
  startPaused: summary.start_paused,
1935
+ state: summary.state,
2061
1936
  phase: null,
2062
1937
  phaseRank: -1,
2063
1938
  check: null,
@@ -2088,24 +1963,24 @@ function sessionFromSummary(summary) {
2088
1963
  };
2089
1964
  }
2090
1965
  function addDropped(session, dropped) {
2091
- const counts = Object.entries(dropped.log).filter(([, count2]) => count2 > 0);
1966
+ const counts = Object.entries(dropped.log).filter(([, count]) => count > 0);
2092
1967
  if (counts.length === 0) return session;
2093
1968
  const mark = session.droppedMarks + 1;
2094
- const gaps = counts.map(([source, count2]) => ({
1969
+ const gaps = counts.map(([source, count]) => ({
2095
1970
  seq: session.lastSeq + 0.5,
2096
1971
  key: `dropped ${mark} ${source}`,
2097
1972
  source,
2098
1973
  line: "",
2099
1974
  gap: {
2100
- count: count2,
1975
+ count,
2101
1976
  atLeast: dropped.at_least.includes(source),
2102
1977
  ...dropped.reason === "not-kept" ? { notKept: true } : {}
2103
1978
  }
2104
1979
  }));
2105
1980
  const next = { ...appendLogs(session, gaps), droppedMarks: mark };
2106
1981
  const sources = { ...next.logSources };
2107
- for (const [source, count2] of counts) {
2108
- sources[source] = { ...sources[source], dropped: sources[source].dropped + count2 };
1982
+ for (const [source, count] of counts) {
1983
+ sources[source] = { ...sources[source], dropped: sources[source].dropped + count };
2109
1984
  }
2110
1985
  return { ...next, logSources: sources };
2111
1986
  }
@@ -2116,6 +1991,8 @@ function stopRequestsOf(stop) {
2116
1991
  function launcherOf(summary) {
2117
1992
  return {
2118
1993
  running: summary.launcher.running,
1994
+ ...summary.launcher.mode === void 0 ? {} : { mode: summary.launcher.mode },
1995
+ ...summary.launcher.process_alive === void 0 ? {} : { processAlive: summary.launcher.process_alive },
2119
1996
  exitCode: summary.launcher.exit_code,
2120
1997
  signal: summary.launcher.signal,
2121
1998
  silentSeconds: summary.launcher.silent_s
@@ -2129,7 +2006,10 @@ function applySummary(session, summary, force = false, controlOnly = false) {
2129
2006
  const staleProjection = projectionRev !== null && (incomingRev === null || incomingRev < projectionRev);
2130
2007
  if (staleControl && (staleProjection || !force && controlOnly)) return session;
2131
2008
  const newer = force || (summary.last_seq ?? -1) > Math.max(session.lastSeq, session.observedSeq ?? -1, session.projectionSeq ?? -1);
2132
- const launcher = !force && !session.launcher.running && summary.launcher.running ? session.launcher : launcherOf(summary);
2009
+ const staleEndRegression = !force && session.state === "ended" && summary.state === "running";
2010
+ const stillEnded = staleEndRegression || !force && !isRunActive(session) && summary.launcher.running && summary.state === "running";
2011
+ const launcher = stillEnded ? session.launcher : launcherOf(summary);
2012
+ const state = staleEndRegression ? session.state : summary.state;
2133
2013
  const notLess = summary.problems.length + summary.problems_omitted >= session.problems.length + session.problemsOmitted;
2134
2014
  const mergedProblems = [...summary.problems];
2135
2015
  let omitted = summary.problems_omitted;
@@ -2149,6 +2029,7 @@ function applySummary(session, summary, force = false, controlOnly = false) {
2149
2029
  ...incomingRev === null ? {} : { snapshotRev: incomingRev },
2150
2030
  ...summary.stop_at_ms === void 0 ? {} : { stopAtMs: summary.stop_at_ms },
2151
2031
  ...summary.problem_seq == null ? {} : { problemSeq: Math.max(session.problemSeq ?? 0, summary.problem_seq) },
2032
+ state,
2152
2033
  launcher,
2153
2034
  stopRequests: Math.max(session.stopRequests, stopRequestsOf(summary.stop)),
2154
2035
  logSources: withSources(session.logSources, Object.keys(summary.log)),
@@ -2379,19 +2260,19 @@ function recoverReplayLogs(session, recovered, notKept) {
2379
2260
  const source = sources[line.source] ??= { lines: 0, dropped: 0 };
2380
2261
  if (line.gap) source.dropped += line.gap.count;
2381
2262
  else {
2382
- const count2 = restored.get(line.source) ?? 0;
2383
- if (count2 < (notKept.get(line.source) ?? 0)) {
2263
+ const count = restored.get(line.source) ?? 0;
2264
+ if (count < (notKept.get(line.source) ?? 0)) {
2384
2265
  source.dropped--;
2385
- restored.set(line.source, count2 + 1);
2266
+ restored.set(line.source, count + 1);
2386
2267
  }
2387
2268
  }
2388
2269
  }
2389
2270
  const logs = session.logs.flatMap((line) => {
2390
2271
  if (!line.gap?.notKept) return [line];
2391
2272
  const available = restored.get(line.source) ?? 0;
2392
- const count2 = Math.max(0, line.gap.count - available);
2273
+ const count = Math.max(0, line.gap.count - available);
2393
2274
  restored.set(line.source, Math.max(0, available - line.gap.count));
2394
- return count2 > 0 ? [{ ...line, gap: { ...line.gap, count: count2 } }] : [];
2275
+ return count > 0 ? [{ ...line, gap: { ...line.gap, count } }] : [];
2395
2276
  });
2396
2277
  logs.push(...recovered);
2397
2278
  logs.sort((a, b) => a.seq - b.seq);
@@ -2406,10 +2287,10 @@ function appendLogs(session, added) {
2406
2287
  if (!line.gap) counts.lines++;
2407
2288
  }
2408
2289
  const drop = /* @__PURE__ */ new Map();
2409
- const take = (source, count2) => {
2410
- sources[source].lines -= count2;
2411
- sources[source].dropped += count2;
2412
- drop.set(source, (drop.get(source) ?? 0) + count2);
2290
+ const take = (source, count) => {
2291
+ sources[source].lines -= count;
2292
+ sources[source].dropped += count;
2293
+ drop.set(source, (drop.get(source) ?? 0) + count);
2413
2294
  };
2414
2295
  let total = 0;
2415
2296
  for (const [source, counts] of Object.entries(sources)) {
@@ -2419,12 +2300,12 @@ function appendLogs(session, added) {
2419
2300
  }
2420
2301
  while (total > MAX_LOG_LINES) {
2421
2302
  const [largest, second] = Object.entries(sources).sort(([, a], [, b]) => b.lines - a.lines);
2422
- const count2 = Math.max(
2303
+ const count = Math.max(
2423
2304
  1,
2424
2305
  Math.min(total - MAX_LOG_LINES, largest[1].lines - (second?.[1].lines ?? 0))
2425
2306
  );
2426
- take(largest[0], count2);
2427
- total -= count2;
2307
+ take(largest[0], count);
2308
+ total -= count;
2428
2309
  }
2429
2310
  const all = [...session.logs, ...added];
2430
2311
  if (drop.size === 0) return { ...session, logs: all, logSources: sources };
@@ -2477,14 +2358,14 @@ function applyOne(session, event, logs) {
2477
2358
  logs.push({ seq: event.seq, key: String(event.seq), source: event.source, line: event.line });
2478
2359
  return next;
2479
2360
  case "log_dropped":
2480
- for (const [source, count2] of Object.entries(event.sources)) {
2481
- if (count2 > 0) {
2361
+ for (const [source, count] of Object.entries(event.sources)) {
2362
+ if (count > 0) {
2482
2363
  logs.push({
2483
2364
  seq: event.seq,
2484
2365
  key: `${event.seq} ${source}`,
2485
2366
  source,
2486
2367
  line: "",
2487
- gap: { count: count2, atLeast: false, launcher: true }
2368
+ gap: { count, atLeast: false, launcher: true }
2488
2369
  });
2489
2370
  }
2490
2371
  }
@@ -2607,6 +2488,230 @@ function blankParticipant(name) {
2607
2488
  };
2608
2489
  }
2609
2490
 
2491
+ // ../client/src/run.ts
2492
+ function answerMissing(path, error) {
2493
+ if (!error.timedOut) return null;
2494
+ return path === "api/run" ? `${error.message}: the server may still start the run (it checks the file again when it has changed); whether it did shows in the session over the WebSocket` : `${error.message}: the server may have done it; the session over the WebSocket shows what happened`;
2495
+ }
2496
+ var RunControl = class {
2497
+ constructor(feed, transport, onError = rethrowLater, startTimeoutMs = () => 0) {
2498
+ this.feed = feed;
2499
+ this.transport = transport;
2500
+ this.startTimeoutMs = startTimeoutMs;
2501
+ this.startSending = new Writable(false, Object.is, onError);
2502
+ this.stopSending = new Writable(null, Object.is, onError);
2503
+ this.pendingRevision = new Writable(0, Object.is, onError);
2504
+ this.stopAskedWhileStarting = new Writable(false, Object.is, onError);
2505
+ this.failure = new Writable(null, Object.is, onError);
2506
+ this.starting = this.startSending.readonly();
2507
+ this.stopping = this.stopSending.readonly();
2508
+ this.currentStopping = derived(
2509
+ [this.pendingRevision, this.startSending, feed.session],
2510
+ () => {
2511
+ const key = this.startSending.get() ? this.startOperation : JSON.stringify(feed.currentTarget());
2512
+ return [...this.pendingStops].filter((pending) => pending.key === key).at(-1)?.action ?? null;
2513
+ },
2514
+ Object.is,
2515
+ onError
2516
+ );
2517
+ this.stopWhileStarting = this.stopAskedWhileStarting.readonly();
2518
+ this.error = derived(
2519
+ [this.failure, feed.session],
2520
+ () => {
2521
+ const failure = this.failure.get();
2522
+ const session = feed.session.get();
2523
+ if (!failure) return null;
2524
+ const same = failure.session === (session?.id ?? null) && failure.running === isRunActive(session);
2525
+ return same ? failure.message : null;
2526
+ },
2527
+ Object.is,
2528
+ onError
2529
+ );
2530
+ }
2531
+ feed;
2532
+ transport;
2533
+ startTimeoutMs;
2534
+ startOperation = null;
2535
+ pendingStops = /* @__PURE__ */ new Set();
2536
+ pendingRevision;
2537
+ startSending;
2538
+ stopSending;
2539
+ stopAskedWhileStarting;
2540
+ failure;
2541
+ starting;
2542
+ stopping;
2543
+ currentStopping;
2544
+ stopWhileStarting;
2545
+ error;
2546
+ /** Starts a run. */
2547
+ start(request) {
2548
+ if (this.startSending.get()) return Promise.reject(new Error("a start is already pending"));
2549
+ let resolveStart;
2550
+ let rejectStart;
2551
+ const operation = new Promise(
2552
+ (resolve, reject) => {
2553
+ resolveStart = resolve;
2554
+ rejectStart = reject;
2555
+ }
2556
+ );
2557
+ this.startOperation = operation;
2558
+ this.stopAskedWhileStarting.set(false);
2559
+ this.startSending.set(true);
2560
+ let instance = null;
2561
+ this.send(
2562
+ "api/run",
2563
+ request,
2564
+ this.startTimeoutMs() || void 0,
2565
+ () => {
2566
+ this.startSending.set(false);
2567
+ },
2568
+ (seen) => {
2569
+ instance = seen;
2570
+ }
2571
+ ).then((summary) => resolveStart({ summary, instance }), rejectStart);
2572
+ return operation.then(({ summary }) => summary);
2573
+ }
2574
+ /** Stops in order (waits for the participants to end). Asking again never turns it into a stop without waiting. */
2575
+ stop() {
2576
+ return this.requestStop(false);
2577
+ }
2578
+ /** Stops without waiting (kills the participants). */
2579
+ forceStop() {
2580
+ return this.requestStop(true);
2581
+ }
2582
+ captureStop() {
2583
+ const starting = this.startSending.get() ? this.startOperation : null;
2584
+ const target = starting ? null : this.feed.currentTarget();
2585
+ return {
2586
+ key: starting ?? JSON.stringify(target),
2587
+ send: (force) => this.requestStop(force, starting, target)
2588
+ };
2589
+ }
2590
+ requestStop(force, starting = this.startSending.get() ? this.startOperation : null, target = starting ? null : this.feed.currentTarget()) {
2591
+ const session = this.feed.session.get();
2592
+ const pending = {
2593
+ action: force ? "force" : "stop",
2594
+ starting: !!starting,
2595
+ key: starting ?? JSON.stringify(target)
2596
+ };
2597
+ this.pendingStops.add(pending);
2598
+ this.pendingRevision.update((n) => n + 1);
2599
+ this.stopSending.set(pending.action);
2600
+ const done = () => {
2601
+ this.pendingStops.delete(pending);
2602
+ this.pendingRevision.update((n) => n + 1);
2603
+ const remaining = [...this.pendingStops];
2604
+ this.stopAskedWhileStarting.set(remaining.some((p) => p.starting));
2605
+ this.stopSending.set(remaining.at(-1)?.action ?? null);
2606
+ };
2607
+ if (!starting) {
2608
+ if (!target) {
2609
+ const message = "no session and server instance are known: no stop was sent; reconnect and check the current run";
2610
+ this.failure.set({
2611
+ message,
2612
+ session: session?.id ?? null,
2613
+ running: isRunActive(session)
2614
+ });
2615
+ done();
2616
+ return Promise.reject(new Error(message));
2617
+ }
2618
+ return this.send("api/stop-session", { force, ...target }, void 0, done);
2619
+ }
2620
+ this.stopAskedWhileStarting.set(true);
2621
+ return starting.then(
2622
+ ({ summary, instance }) => {
2623
+ if (!summary || !instance) {
2624
+ const message = "the start answer did not identify the run; no stop was sent";
2625
+ const session2 = this.feed.session.get();
2626
+ this.failure.set({
2627
+ message,
2628
+ session: session2?.id ?? null,
2629
+ running: isRunActive(session2)
2630
+ });
2631
+ throw new Error(message);
2632
+ }
2633
+ pending.key = JSON.stringify({ session: summary.id, instance });
2634
+ this.pendingRevision.update((n) => n + 1);
2635
+ return this.send(
2636
+ "api/stop-session",
2637
+ { force, session: summary.id, instance },
2638
+ void 0,
2639
+ () => void 0
2640
+ );
2641
+ },
2642
+ (error) => {
2643
+ const session2 = this.feed.session.get();
2644
+ this.failure.set({
2645
+ message: `the start was not confirmed; no stop was sent: ${errorMessage(error)}`,
2646
+ session: session2?.id ?? null,
2647
+ running: isRunActive(session2)
2648
+ });
2649
+ throw new Error(`the start was not confirmed; no stop was sent: ${errorMessage(error)}`);
2650
+ }
2651
+ ).finally(done);
2652
+ }
2653
+ /**
2654
+ * Sends and applies the summary in the answer. done is called after the answer (failures too), before the Promise
2655
+ * settles.
2656
+ */
2657
+ send(path, body, timeoutMs, done, onInstance) {
2658
+ const incompatible = this.feed.incompatible.get();
2659
+ if (incompatible) {
2660
+ done();
2661
+ return Promise.reject(new Error(incompatible));
2662
+ }
2663
+ this.failure.set(null);
2664
+ return new Promise((resolve, reject) => {
2665
+ this.transport({ method: "POST", path, body, timeoutMs }, (outcome) => {
2666
+ if (!outcome.ok) {
2667
+ const failure = path === "api/stop-session" && outcome.error.status === 404 ? new HttpError(404, outcome.error.statusText, {
2668
+ code: "targeted-stop-unsupported",
2669
+ message: "the GUI server cannot stop a particular session: no stop was sent; use the GUI server of this release"
2670
+ }) : outcome.error;
2671
+ const session = this.feed.session.get();
2672
+ this.failure.set({
2673
+ message: answerMissing(path, failure) ?? errorMessage(failure),
2674
+ session: session?.id ?? null,
2675
+ running: isRunActive(session)
2676
+ });
2677
+ done();
2678
+ reject(failure);
2679
+ return;
2680
+ }
2681
+ let summary = null;
2682
+ try {
2683
+ const instance = path === "api/stop-session" ? body.instance : readSessionInstance(outcome.body);
2684
+ summary = readSessionResponse(outcome.body);
2685
+ if (path === "api/stop-session" && (!summary || summary.id !== body.session)) {
2686
+ throw new Error("the stop answer did not identify the requested session");
2687
+ }
2688
+ onInstance?.(instance);
2689
+ this.feed.adopt(summary, instance);
2690
+ } catch (error) {
2691
+ this.feed.report(
2692
+ error instanceof ProtocolError ? `unreadable answer: ${error.message}` : String(error)
2693
+ );
2694
+ const missingInstance = error instanceof ProtocolError && error.path === "response.instance";
2695
+ if (path === "api/stop-session" || missingInstance) {
2696
+ const message = missingInstance ? `${error.message}. The run may have started. Check the current run before retrying` : "the stop answer was unreadable: check the session before trying again";
2697
+ const session = this.feed.session.get();
2698
+ this.failure.set({
2699
+ message,
2700
+ session: session?.id ?? null,
2701
+ running: isRunActive(session)
2702
+ });
2703
+ done();
2704
+ reject(new Error(message));
2705
+ return;
2706
+ }
2707
+ }
2708
+ done();
2709
+ resolve(summary);
2710
+ });
2711
+ });
2712
+ }
2713
+ };
2714
+
2610
2715
  // ../client/src/session.ts
2611
2716
  var MAX_NOTICES = 20;
2612
2717
  var STALE_EVENTS_NOTICE = "events came with a seq that is not after the last one, and were not shown (the launcher wrote them out of order, or the server sent them again)";
@@ -2621,6 +2726,8 @@ var SessionFeed = class {
2621
2726
  this.synced = new Writable(false, Object.is, onError);
2622
2727
  this.allowedValue = new Writable(null, Object.is, onError);
2623
2728
  this.allowed = this.allowedValue.readonly();
2729
+ this.runtimeValue = new Writable(null, Object.is, onError);
2730
+ this.runtime = this.runtimeValue.readonly();
2624
2731
  this.receivedAt = new Writable(0, Object.is, onError);
2625
2732
  this.noticeList = new Writable([], Object.is, onError);
2626
2733
  this.rejectedValue = new Writable(false, Object.is, onError);
@@ -2652,6 +2759,7 @@ var SessionFeed = class {
2652
2759
  current;
2653
2760
  synced;
2654
2761
  allowedValue;
2762
+ runtimeValue;
2655
2763
  receivedAt;
2656
2764
  noticeList;
2657
2765
  rejectedValue;
@@ -2663,6 +2771,7 @@ var SessionFeed = class {
2663
2771
  session;
2664
2772
  ready;
2665
2773
  allowed;
2774
+ runtime;
2666
2775
  lastEventAt;
2667
2776
  notices;
2668
2777
  rejected;
@@ -2752,8 +2861,12 @@ var SessionFeed = class {
2752
2861
  const current = this.allowedValue.get();
2753
2862
  if (!current || allowed.rev === 0 || allowed.rev >= current.rev) this.allowedValue.set(allowed);
2754
2863
  }
2755
- report(message, count2 = 1) {
2756
- this.notify(message, count2);
2864
+ /** Updates the current persistent runtime status (from HTTP `prepare`/`session`). Used inside the library. */
2865
+ adoptRuntime(runtime) {
2866
+ this.runtimeValue.set(runtime);
2867
+ }
2868
+ report(message, count = 1) {
2869
+ this.notify(message, count);
2757
2870
  }
2758
2871
  dismissNotice(id) {
2759
2872
  this.noticeList.update((list) => list.filter((notice) => notice.id !== id));
@@ -2862,6 +2975,7 @@ var SessionFeed = class {
2862
2975
  let applied = false;
2863
2976
  let synced = this.synced.get();
2864
2977
  let allowedNow = this.allowedValue.get();
2978
+ let runtimeNow = this.runtimeValue.get();
2865
2979
  const takeAllowed = (incoming, replace = false) => {
2866
2980
  if (!incoming) return;
2867
2981
  if (replace || !allowedNow || incoming.rev === 0 || incoming.rev >= allowedNow.rev) {
@@ -2885,6 +2999,11 @@ var SessionFeed = class {
2885
2999
  const { session: summary, replay } = message;
2886
3000
  const staleSnapshot = !!summary && instance === message.instance && session?.id === summary.id && session.snapshotRev != null && (summary.snapshot_rev == null || summary.snapshot_rev < session.snapshotRev);
2887
3001
  takeAllowed(message.allowed ?? summary?.allowed ?? null, !staleSnapshot);
3002
+ if (message.runtime !== void 0) {
3003
+ runtimeNow = message.runtime;
3004
+ } else if (message.instance !== instance) {
3005
+ runtimeNow = null;
3006
+ }
2888
3007
  const sameRun2 = summary && instance === message.instance && session?.id === summary.id;
2889
3008
  const resumed = sameRun2 && replay?.from_seq != null;
2890
3009
  instance = message.instance;
@@ -2913,8 +3032,8 @@ var SessionFeed = class {
2913
3032
  if (session && message.session === session.id) {
2914
3033
  session = addDropped(session, message);
2915
3034
  if (message.reason === "not-kept" && replayLogs) {
2916
- for (const [source, count2] of Object.entries(message.log))
2917
- replayLogs.notKept.set(source, (replayLogs.notKept.get(source) ?? 0) + count2);
3035
+ for (const [source, count] of Object.entries(message.log))
3036
+ replayLogs.notKept.set(source, (replayLogs.notKept.get(source) ?? 0) + count);
2918
3037
  }
2919
3038
  }
2920
3039
  break;
@@ -2929,6 +3048,9 @@ var SessionFeed = class {
2929
3048
  case "allowed":
2930
3049
  takeAllowed(message.allowed);
2931
3050
  break;
3051
+ case "runtime":
3052
+ runtimeNow = message.runtime;
3053
+ break;
2932
3054
  case "session":
2933
3055
  if (session?.id !== message.session.id) replayLogs = null;
2934
3056
  takeAllowed(message.session.allowed);
@@ -2977,10 +3099,12 @@ var SessionFeed = class {
2977
3099
  const sameRun = () => currentOrigin() && this.instanceId === instance && (this.current.get()?.id ?? null) === sessionId;
2978
3100
  const notifySession = this.current.setDeferred(session);
2979
3101
  const notifyAllowed = this.allowedValue.setDeferred(allowedNow);
3102
+ const notifyRuntime = this.runtimeValue.setDeferred(runtimeNow);
2980
3103
  const notifySynced = this.synced.setDeferred(synced);
2981
3104
  if (instance && instance !== originalInstance) this.instanceListener(instance, sameRun);
2982
3105
  notifySession();
2983
3106
  notifyAllowed();
3107
+ notifyRuntime();
2984
3108
  notifySynced();
2985
3109
  if (!sameRun()) return;
2986
3110
  for (const notice of notices) {
@@ -2995,13 +3119,13 @@ var SessionFeed = class {
2995
3119
  if (!sameRun()) return;
2996
3120
  callEach(this.messageListeners, [batch], this.onError, sameRun);
2997
3121
  }
2998
- notify(message, count2 = 1) {
3122
+ notify(message, count = 1) {
2999
3123
  this.noticeList.update((list) => {
3000
3124
  const same = list.find((notice) => notice.message === message);
3001
3125
  if (same) {
3002
- return [...list.filter((n) => n !== same), { ...same, count: same.count + count2 }];
3126
+ return [...list.filter((n) => n !== same), { ...same, count: same.count + count }];
3003
3127
  }
3004
- return [...list, { id: ++this.noticeId, message, count: count2 }].slice(-MAX_NOTICES);
3128
+ return [...list, { id: ++this.noticeId, message, count }].slice(-MAX_NOTICES);
3005
3129
  });
3006
3130
  }
3007
3131
  };
@@ -3134,7 +3258,7 @@ var TimeControl = class {
3134
3258
  const target = this.currentTarget();
3135
3259
  let sending = null;
3136
3260
  if (pending && sameRunTarget(pending.target, target)) {
3137
- const answered = !session || !session.launcher.running || (session.lastCommand?.seq ?? -1) > pending.afterSeq;
3261
+ const answered = !session || !isRunActive(session) || (session.lastCommand?.seq ?? -1) > pending.afterSeq;
3138
3262
  sending = this.awaitingHttp.get() === pending || !answered ? pending.command : null;
3139
3263
  }
3140
3264
  const failure = this.failureValue.get();
@@ -3243,69 +3367,57 @@ var keyOf = (peer, name) => `${peer}\0${name}`;
3243
3367
  var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
3244
3368
  var text = (value, fallback = "") => typeof value === "string" ? value : fallback;
3245
3369
  var numberOrNull = (value) => typeof value === "number" && Number.isFinite(value) ? value : null;
3246
- var count = (value) => typeof value === "number" && value >= 0 ? value : 0;
3247
3370
  var positionOrNull = (value) => Number.isSafeInteger(value) && value >= 0 ? value : null;
3248
3371
  function readVariables2(value, session) {
3249
- if (!isObject(value)) return { ...NO_VARIABLES, session };
3372
+ const u = new Unreadable("variables");
3373
+ const summary = lenient(
3374
+ (v) => readVariablesReport(v, "variables", u),
3375
+ null,
3376
+ u
3377
+ )(value, "variables");
3378
+ if (!summary) return { ...NO_VARIABLES, session };
3250
3379
  const peers = [];
3251
3380
  const availability = /* @__PURE__ */ new Map();
3252
- for (const p of Array.isArray(value["peers"]) ? value["peers"] : []) {
3253
- if (!isObject(p) || typeof p["name"] !== "string") continue;
3381
+ for (const p of summary.peers) {
3254
3382
  const variables = [];
3255
3383
  const states = /* @__PURE__ */ new Map();
3256
- for (const v of Array.isArray(p["variables"]) ? p["variables"] : []) {
3257
- if (!isObject(v) || typeof v["name"] !== "string") continue;
3258
- const items2 = Array.isArray(v["enum"]) ? v["enum"].flatMap(
3259
- (i) => isObject(i) && typeof i["name"] === "string" && typeof i["value"] === "number" ? [{ name: i["name"], value: i["value"] }] : []
3260
- ) : null;
3261
- variables.push({
3262
- name: v["name"],
3263
- type: text(v["type"]),
3264
- role: text(v["role"], "output"),
3265
- writable: v["writable"] === true,
3266
- unit: text(v["unit"]),
3267
- min: numberOrNull(v["min"]),
3268
- max: numberOrNull(v["max"]),
3269
- step: numberOrNull(v["step"]),
3270
- description: text(v["description"]),
3271
- enum: items2
3272
- });
3273
- states.set(v["name"], readAvailability(v["availability"]));
3384
+ for (const { availability: state, ...info } of p.variables) {
3385
+ variables.push(info);
3386
+ states.set(info.name, state);
3274
3387
  }
3275
- availability.set(p["name"], states);
3276
- peers.push({ name: p["name"], connected: p["connected"] === true, variables });
3388
+ availability.set(p.name, states);
3389
+ peers.push({ name: p.name, connected: p.connected, variables });
3277
3390
  }
3278
3391
  return {
3279
3392
  session,
3280
- status: text(value["state"], "unknown"),
3281
- reason: typeof value["reason"] === "string" ? value["reason"] : null,
3393
+ status: summary.state,
3394
+ reason: summary.reason,
3282
3395
  peers,
3283
3396
  availability,
3284
- peersOmitted: count(value["peers_omitted"]),
3285
- variablesOmitted: count(value["variables_omitted"])
3397
+ peersOmitted: summary.peers_omitted,
3398
+ variablesOmitted: summary.variables_omitted
3286
3399
  };
3287
3400
  }
3288
3401
  function readOperation(value, session) {
3289
- if (!isObject(value) || !Number.isSafeInteger(value["seq"]) || typeof value["state"] !== "string") {
3290
- return null;
3291
- }
3402
+ const u = new Unreadable("operation");
3403
+ const report = lenient((v, p) => readOperationReport(v, p, u), null, u)(value, "operation");
3404
+ if (!report) return null;
3292
3405
  const peers = {};
3293
- for (const [name, p] of Object.entries(isObject(value["peers"]) ? value["peers"] : {})) {
3294
- if (!isObject(p)) continue;
3406
+ for (const [name, p] of Object.entries(report.peers)) {
3295
3407
  peers[name] = {
3296
- state: text(p["state"], "unknown"),
3297
- appliedAtMs: numberOrNull(p["applied_at_ms"]),
3298
- late: p["late"] === true,
3299
- reason: typeof p["reason"] === "string" ? p["reason"] : null,
3300
- appliedWrites: positionOrNull(p["applied_writes"]),
3301
- failedWrite: positionOrNull(p["failed_write"])
3408
+ state: p.state,
3409
+ appliedAtMs: p.applied_at_ms,
3410
+ late: p.late,
3411
+ reason: p.reason,
3412
+ appliedWrites: p.applied_writes,
3413
+ failedWrite: p.failed_write
3302
3414
  };
3303
3415
  }
3304
3416
  return {
3305
3417
  session,
3306
- seq: value["seq"],
3307
- state: value["state"],
3308
- done: value["done"] === true,
3418
+ seq: report.seq,
3419
+ state: report.state,
3420
+ done: report.done,
3309
3421
  peers
3310
3422
  };
3311
3423
  }
@@ -3879,6 +3991,7 @@ var VariablesFeed = class {
3879
3991
  );
3880
3992
  }
3881
3993
  const body = { session, writes };
3994
+ if (options.instance !== void 0) body["instance"] = options.instance;
3882
3995
  if (options.atMs !== void 0) body["at_ms"] = options.atMs;
3883
3996
  if (options.late !== void 0) body["late"] = options.late;
3884
3997
  return new Promise((resolve, reject) => {
@@ -4565,12 +4678,13 @@ function buildClient(options) {
4565
4678
  currentInstance: () => session.currentInstance(),
4566
4679
  ready: session.ready,
4567
4680
  allowed: session.allowed,
4681
+ runtime: session.runtime,
4568
4682
  lastEventAt: session.lastEventAt,
4569
4683
  notices: session.notices,
4570
4684
  rejected: session.rejected,
4571
4685
  incompatible: session.incompatible,
4572
4686
  onMessages: (listener) => session.onMessages(listener),
4573
- report: (message, count2) => session.report(message, count2),
4687
+ report: (message, count) => session.report(message, count),
4574
4688
  dismissNotice: (id) => session.dismissNotice(id)
4575
4689
  },
4576
4690
  run: {
@@ -4653,6 +4767,16 @@ function buildClient(options) {
4653
4767
  },
4654
4768
  readConnections
4655
4769
  ),
4770
+ prepare: (body) => call(
4771
+ {
4772
+ method: "POST",
4773
+ path: "api/prepare",
4774
+ body,
4775
+ timeoutMs: longRequestMs(limits.get())
4776
+ },
4777
+ readPrepareResponse,
4778
+ (res) => session.adoptRuntime(res.runtime)
4779
+ ),
4656
4780
  fetchSession: () => {
4657
4781
  const resyncFrom = session.currentInstance();
4658
4782
  const snapshotVersion = variables.snapshotVersion();
@@ -4665,8 +4789,10 @@ function buildClient(options) {
4665
4789
  try {
4666
4790
  const summary = readSessionResponse(outcome.body);
4667
4791
  const instance = readSessionInstance(outcome.body);
4792
+ const runtime = readSessionRuntime(outcome.body);
4668
4793
  const adoption = session.adopt(summary, instance, resyncFrom);
4669
4794
  if (adoption !== null) {
4795
+ if (runtime !== void 0) session.adoptRuntime(runtime);
4670
4796
  const rawSession = outcome.body?.session;
4671
4797
  const rev = rawSession?.variables?.rev;
4672
4798
  const current = () => variables.isSnapshotCurrent(
@@ -4837,8 +4963,7 @@ function standsAt(session) {
4837
4963
  }
4838
4964
  function onItsWay(session) {
4839
4965
  const last = session?.lastCommand;
4840
- if (!session || !session.launcher.running || !last || !last.accepted || last.atMs === null)
4841
- return false;
4966
+ if (!isRunActive(session) || !last || !last.accepted || last.atMs === null) return false;
4842
4967
  if (last.name !== "step" && last.name !== "run_until") return false;
4843
4968
  const stands = standsAt(session);
4844
4969
  return !(stands !== null && stands >= last.atMs);
@@ -4847,7 +4972,7 @@ function clockOf(s) {
4847
4972
  const session = s.session;
4848
4973
  const state = session?.launcherState ?? null;
4849
4974
  const time = session?.time ?? null;
4850
- const live = !!session && session.launcher.running;
4975
+ const live = isRunActive(session);
4851
4976
  const pacing = state?.pacing;
4852
4977
  return {
4853
4978
  sim_ms: simMsOf(session ?? null),
@@ -4905,7 +5030,7 @@ function composeControls(s, run) {
4905
5030
  const link = linkOf(s);
4906
5031
  const down = linkReason(link, s);
4907
5032
  const session = s.session;
4908
- const live = !!session && session.launcher.running && run !== "ended" && run !== "crashed";
5033
+ const live = isRunActive(session) && run !== "ended" && run !== "crashed";
4909
5034
  const state = session?.launcherState ?? null;
4910
5035
  const stopsAsked = session?.stopRequests ?? 0;
4911
5036
  let start;
@@ -5099,7 +5224,12 @@ var FrontActions = class {
5099
5224
  const own = this.refusalOfStart();
5100
5225
  if (own) return this.fail(own);
5101
5226
  const start = this.src.low.run.start(request);
5102
- return this.guarded("start", () => start.then(() => void 0));
5227
+ return this.guarded(
5228
+ "start",
5229
+ () => start.then((started) => {
5230
+ if (started) options.onStarted?.(started);
5231
+ })
5232
+ );
5103
5233
  }
5104
5234
  /**
5105
5235
  * Checks what `intent` would start (`api/check`). Its failure is the caller's: it is not kept for `status.problem`.
@@ -5499,7 +5629,7 @@ var FrontActions = class {
5499
5629
  const session = this.src.low.session.session.get();
5500
5630
  const instance = this.src.low.session.currentInstance();
5501
5631
  for (const w of [...this.waiting.values()]) {
5502
- if (!session || session.id !== w.session || instance !== w.instance || !session.launcher.running || session.result) {
5632
+ if (!session || !isRunActive(session) || session.id !== w.session || instance !== w.instance || session.result) {
5503
5633
  this.settle(
5504
5634
  w,
5505
5635
  new ActionError(
@@ -5602,11 +5732,11 @@ function outsideRows(low, onError) {
5602
5732
  [low.session.session, counts],
5603
5733
  () => {
5604
5734
  const session = low.session.session.get();
5605
- if (!session?.launcher.running) return [];
5735
+ if (!session || !isRunActive(session)) return [];
5606
5736
  const known = counts.get();
5607
5737
  const of = known?.session === session.id ? known.networks : /* @__PURE__ */ new Map();
5608
5738
  return (session.launcherState?.outside ?? []).map((row) => {
5609
- const count2 = of.get(row.network);
5739
+ const count = of.get(row.network);
5610
5740
  return {
5611
5741
  network: row.network,
5612
5742
  target: row.target,
@@ -5616,8 +5746,8 @@ function outsideRows(low, onError) {
5616
5746
  condition: row.condition,
5617
5747
  reasons: row.reasons,
5618
5748
  nothing_received: row.nothing_received,
5619
- to_outside: count2?.to ?? null,
5620
- from_outside: count2?.from ?? null
5749
+ to_outside: count?.to ?? null,
5750
+ from_outside: count?.from ?? null
5621
5751
  };
5622
5752
  });
5623
5753
  },
@@ -5725,7 +5855,7 @@ function makeVariable(low, ref, refuse, launcher) {
5725
5855
  const track = new Writable({ writing: false, problem: null }, sameData);
5726
5856
  const view = new Writable(null, sameData);
5727
5857
  let binding = null;
5728
- let count2 = 0;
5858
+ let count = 0;
5729
5859
  let stops = [];
5730
5860
  const refresh = () => {
5731
5861
  if (binding) view.set(viewOf(binding.state.get(), track.get(), launcher.get()));
@@ -5747,7 +5877,7 @@ function makeVariable(low, ref, refuse, launcher) {
5747
5877
  return view.get();
5748
5878
  },
5749
5879
  subscribe: (listener) => {
5750
- if (count2++ === 0) {
5880
+ if (count++ === 0) {
5751
5881
  binding = low.variables.bind(ref);
5752
5882
  stops = [
5753
5883
  binding.state.subscribe(refresh),
@@ -5762,7 +5892,7 @@ function makeVariable(low, ref, refuse, launcher) {
5762
5892
  if (done) return;
5763
5893
  done = true;
5764
5894
  off();
5765
- if (--count2 === 0) {
5895
+ if (--count === 0) {
5766
5896
  for (const stop of stops) stop();
5767
5897
  stops = [];
5768
5898
  binding?.close();
@@ -5930,7 +6060,32 @@ function makeFront(options, onClose) {
5930
6060
  clock,
5931
6061
  controls,
5932
6062
  scenario,
6063
+ runtime: low.session.runtime,
5933
6064
  outside: outside.value,
6065
+ prepare: (prepareOptions = {}) => {
6066
+ const file = prepareOptions.file ?? initialFile();
6067
+ if (file === null) {
6068
+ return Promise.reject(noFileError());
6069
+ }
6070
+ return low.prepare({
6071
+ file,
6072
+ ...prepareOptions.variant !== void 0 ? { variant: prepareOptions.variant } : {},
6073
+ ...prepareOptions.disable !== void 0 ? { disable: prepareOptions.disable } : {},
6074
+ ...prepareOptions.enable !== void 0 ? { enable: prepareOptions.enable } : {},
6075
+ ...prepareOptions.manual !== void 0 ? { manual: prepareOptions.manual } : {}
6076
+ }).then(
6077
+ (res) => res.runtime,
6078
+ (error) => {
6079
+ throw actionError(error);
6080
+ }
6081
+ );
6082
+ },
6083
+ configs: () => low.configs().catch((error) => {
6084
+ throw actionError(error);
6085
+ }),
6086
+ recording: () => low.recording().catch((error) => {
6087
+ throw actionError(error);
6088
+ }),
5934
6089
  connections: ({ network }, listOptions = {}) => {
5935
6090
  const file = listOptions.file ?? initialFile();
5936
6091
  if (file === null) {
@@ -6298,6 +6453,10 @@ export {
6298
6453
  fetchTransport,
6299
6454
  hasRange,
6300
6455
  isHolding,
6456
+ isLauncherAlive,
6457
+ isLauncherFinishing,
6458
+ isRunActive,
6459
+ isSessionRunning,
6301
6460
  isWriteError,
6302
6461
  launcherAnswer,
6303
6462
  phaseIndex,
@@ -6307,12 +6466,15 @@ export {
6307
6466
  readConfigText,
6308
6467
  readConnections,
6309
6468
  readDashboardResponse,
6469
+ readPrepareResponse,
6310
6470
  readRecording,
6471
+ readRuntimeStatus,
6311
6472
  readSavedConfig,
6312
6473
  readScenarioList,
6313
6474
  readServerMessage,
6314
6475
  readSessionAllowed,
6315
6476
  readSessionResponse,
6477
+ readSessionRuntime,
6316
6478
  readTimeResponse,
6317
6479
  readVariablesSummary,
6318
6480
  readWriteResponse,