@vehicle-sil/gui-client 0.3.0 → 0.4.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/README.ja.md +16 -16
- package/README.md +16 -16
- package/dist/index.js +451 -723
- package/package.json +1 -1
- package/types/client.d.ts +6 -8
- package/types/front-actions.d.ts +9 -6
- package/types/front-compose.d.ts +4 -0
- package/types/front-types.d.ts +4 -7
- package/types/front.d.ts +2 -2
- package/types/http.d.ts +2 -2
- package/types/index.d.ts +2 -2
- package/types/protocol/launcher.d.ts +4 -2
- package/types/protocol/server.d.ts +49 -51
- package/types/run.d.ts +24 -26
- package/types/session-state.d.ts +7 -35
- package/types/session.d.ts +13 -41
- package/types/time.d.ts +2 -2
- package/types/variables.d.ts +10 -22
package/dist/index.js
CHANGED
|
@@ -448,7 +448,6 @@ function severityRank(severity) {
|
|
|
448
448
|
var readFinding = (value, path, u) => {
|
|
449
449
|
const f = object(value, path);
|
|
450
450
|
return withRaw(f, {
|
|
451
|
-
...Number.isSafeInteger(f["event_seq"]) && f["event_seq"] >= 0 ? { event_seq: f["event_seq"] } : {},
|
|
452
451
|
severity: field(f, path, "severity", string),
|
|
453
452
|
code: field(f, path, "code", lenient(string, "", u)),
|
|
454
453
|
file: field(f, path, "file", soft(nullable(string), null, u)),
|
|
@@ -896,6 +895,13 @@ function readEventFields(f, path, kind, base, u) {
|
|
|
896
895
|
file: field(f, path, "file", soft(nullable(string), null, u)),
|
|
897
896
|
arguments: field(f, path, "arguments", soft(items(string, u), [], u))
|
|
898
897
|
};
|
|
898
|
+
case "run_start":
|
|
899
|
+
return {
|
|
900
|
+
...base,
|
|
901
|
+
event: kind,
|
|
902
|
+
id: field(f, path, "id", soft(nullable(integer), null, u)),
|
|
903
|
+
run: field(f, path, "run", soft(nullable(string), null, u))
|
|
904
|
+
};
|
|
899
905
|
case "phase":
|
|
900
906
|
return { ...base, event: kind, phase: field(f, path, "phase", string) };
|
|
901
907
|
case "check":
|
|
@@ -977,15 +983,17 @@ function readEventFields(f, path, kind, base, u) {
|
|
|
977
983
|
}
|
|
978
984
|
|
|
979
985
|
// ../client/src/protocol/server.ts
|
|
980
|
-
var PROTOCOL_VERSION =
|
|
986
|
+
var PROTOCOL_VERSION = 4;
|
|
987
|
+
var nonEmptyString = (value, path) => {
|
|
988
|
+
if (typeof value !== "string" || !value) throw new ProtocolError(path, "a non-empty string");
|
|
989
|
+
return value;
|
|
990
|
+
};
|
|
981
991
|
var readServerProblem = (value, path) => {
|
|
982
992
|
const f = object(value, path);
|
|
983
993
|
const problem = {
|
|
984
994
|
code: field(f, path, "code", string),
|
|
985
995
|
message: field(f, path, "message", string)
|
|
986
996
|
};
|
|
987
|
-
if (Number.isSafeInteger(f["problem_seq"]) && f["problem_seq"] >= 0)
|
|
988
|
-
problem.problem_seq = f["problem_seq"];
|
|
989
997
|
const detail = f["detail"];
|
|
990
998
|
if (typeof detail === "object" && detail !== null && "skipped" in detail) {
|
|
991
999
|
const skipped = detail.skipped;
|
|
@@ -1101,7 +1109,7 @@ var readRecording = (value) => {
|
|
|
1101
1109
|
if (r === null) return null;
|
|
1102
1110
|
const path = "response.recording";
|
|
1103
1111
|
return {
|
|
1104
|
-
|
|
1112
|
+
run_id: field(r, path, "run_id", nonEmptyString),
|
|
1105
1113
|
file: field(r, path, "file", string),
|
|
1106
1114
|
state: field(r, path, "state", string),
|
|
1107
1115
|
available: field(r, path, "available", boolean),
|
|
@@ -1170,9 +1178,10 @@ var readRuntimeStatus = (value, path) => {
|
|
|
1170
1178
|
var readPrepareResponse = (value) => {
|
|
1171
1179
|
const path = "response";
|
|
1172
1180
|
const f = object(value, path);
|
|
1181
|
+
const runtime = field(f, path, "runtime", optional(readRuntimeStatus, void 0));
|
|
1173
1182
|
return {
|
|
1174
|
-
instance: field(f, path, "instance",
|
|
1175
|
-
runtime:
|
|
1183
|
+
instance: field(f, path, "instance", nonEmptyString),
|
|
1184
|
+
...runtime === void 0 ? {} : { runtime }
|
|
1176
1185
|
};
|
|
1177
1186
|
};
|
|
1178
1187
|
var readSummaryLauncher = (value, path) => {
|
|
@@ -1217,8 +1226,8 @@ var readSessionSummary = (value, path) => {
|
|
|
1217
1226
|
const timePath = `${path}.time`;
|
|
1218
1227
|
const stopAt = field(f, path, "stop_at_ms", soft(nullable(integer), void 0, u));
|
|
1219
1228
|
const summary = {
|
|
1220
|
-
id: field(f, path, "id",
|
|
1221
|
-
...f["
|
|
1229
|
+
id: field(f, path, "id", nonEmptyString),
|
|
1230
|
+
...f["run_t0_ms"] === void 0 ? {} : { run_t0_ms: field(f, path, "run_t0_ms", soft(nullable(number), null, u)) },
|
|
1222
1231
|
state: field(f, path, "state", string),
|
|
1223
1232
|
launcher: field(f, path, "launcher", readSummaryLauncher),
|
|
1224
1233
|
stop: field(f, path, "stop", string),
|
|
@@ -1302,7 +1311,6 @@ var readSessionSummary = (value, path) => {
|
|
|
1302
1311
|
log: field(f, path, "log", soft(partlyRecord(readLogCounts, u), {}, u)),
|
|
1303
1312
|
problems: field(f, path, "problems", items(readServerProblem, u)),
|
|
1304
1313
|
problems_omitted: field(f, path, "problems_omitted", soft(integer, 0, u)),
|
|
1305
|
-
...f["problem_seq"] === void 0 ? {} : { problem_seq: field(f, path, "problem_seq", soft(nullable(integer), null, u)) },
|
|
1306
1314
|
scenario: field(
|
|
1307
1315
|
f,
|
|
1308
1316
|
path,
|
|
@@ -1331,7 +1339,6 @@ var readServerSaveItem = (value, path) => ({
|
|
|
1331
1339
|
var readServerAllowed = (value, path) => {
|
|
1332
1340
|
const f = object(value, path);
|
|
1333
1341
|
return {
|
|
1334
|
-
rev: field(f, path, "rev", optional(integer, 0)),
|
|
1335
1342
|
start: field(f, path, "start", readServerAllowedItem),
|
|
1336
1343
|
stop: field(f, path, "stop", readServerAllowedItem),
|
|
1337
1344
|
force: field(f, path, "force", readServerAllowedItem),
|
|
@@ -1355,6 +1362,14 @@ var readSessionInstance = (value) => field(object(value, "response"), "response"
|
|
|
1355
1362
|
throw new ProtocolError(path, "a server instance ID. Use the GUI server from this release");
|
|
1356
1363
|
return instance;
|
|
1357
1364
|
});
|
|
1365
|
+
var readRunResponse = (value) => {
|
|
1366
|
+
const path = "response";
|
|
1367
|
+
const f = object(value, path);
|
|
1368
|
+
return {
|
|
1369
|
+
instance: readSessionInstance(value),
|
|
1370
|
+
run_id: field(f, path, "run_id", nonEmptyString)
|
|
1371
|
+
};
|
|
1372
|
+
};
|
|
1358
1373
|
var readSessionAllowed = (value) => field(
|
|
1359
1374
|
object(value, "response"),
|
|
1360
1375
|
"response",
|
|
@@ -1372,7 +1387,7 @@ var readTimeResponse = (value) => {
|
|
|
1372
1387
|
const f = object(value, path);
|
|
1373
1388
|
const command = field(f, path, "command", object);
|
|
1374
1389
|
return {
|
|
1375
|
-
|
|
1390
|
+
run_id: field(f, path, "run_id", nonEmptyString),
|
|
1376
1391
|
command: field(command, `${path}.command`, "command", string),
|
|
1377
1392
|
id: field(command, `${path}.command`, "id", optional(nullable(integer), null))
|
|
1378
1393
|
};
|
|
@@ -1456,7 +1471,6 @@ var readVariablesSummary = (value) => readVariablesReport(value, "variables");
|
|
|
1456
1471
|
var readVariablesReport = (value, path, u) => {
|
|
1457
1472
|
const f = object(value, path);
|
|
1458
1473
|
return {
|
|
1459
|
-
...f["rev"] === void 0 ? {} : { rev: field(f, path, "rev", soft(nullable(nonNegativeInteger), null, u)) },
|
|
1460
1474
|
state: field(f, path, "state", lenient(string, "unknown", u)),
|
|
1461
1475
|
reason: field(f, path, "reason", soft(nullable(string), null, u)),
|
|
1462
1476
|
peers: field(
|
|
@@ -1515,7 +1529,7 @@ var readVariables = readVariablesReport;
|
|
|
1515
1529
|
var readWriteResponse = (value) => {
|
|
1516
1530
|
const f = object(value, "response");
|
|
1517
1531
|
return {
|
|
1518
|
-
|
|
1532
|
+
run_id: field(f, "response", "run_id", nonEmptyString),
|
|
1519
1533
|
operation: field(f, "response", "operation", integer)
|
|
1520
1534
|
};
|
|
1521
1535
|
};
|
|
@@ -1602,19 +1616,22 @@ var readDashboardResponse = (value) => {
|
|
|
1602
1616
|
};
|
|
1603
1617
|
var readReplay = (value, path) => {
|
|
1604
1618
|
const f = object(value, path);
|
|
1605
|
-
return {
|
|
1619
|
+
return { after_stream_seq: field(f, path, "after_stream_seq", nullable(integer)) };
|
|
1606
1620
|
};
|
|
1607
1621
|
var readServerMessage = (value) => {
|
|
1608
1622
|
const path = "message";
|
|
1609
1623
|
const f = object(value, path);
|
|
1610
1624
|
const type = field(f, path, "type", string);
|
|
1625
|
+
const streamSeq = f["stream_seq"] === void 0 ? void 0 : field(f, path, "stream_seq", nonNegativeInteger);
|
|
1626
|
+
const seqField = streamSeq === void 0 ? {} : { stream_seq: streamSeq };
|
|
1611
1627
|
switch (type) {
|
|
1612
1628
|
case "hello": {
|
|
1613
1629
|
version(f, path, "vehicle_sil_gui", PROTOCOL_VERSION);
|
|
1614
1630
|
const runtime = field(f, path, "runtime", optional(nullable(readRuntimeStatus), void 0));
|
|
1615
1631
|
return {
|
|
1616
1632
|
type,
|
|
1617
|
-
|
|
1633
|
+
...seqField,
|
|
1634
|
+
instance: field(f, path, "instance", nonEmptyString),
|
|
1618
1635
|
session: field(f, path, "session", nullable(readSessionSummary)),
|
|
1619
1636
|
allowed: field(f, path, "allowed", optional(nullable(readServerAllowed), null)),
|
|
1620
1637
|
replay: field(f, path, "replay", nullable(readReplay)),
|
|
@@ -1622,29 +1639,32 @@ var readServerMessage = (value) => {
|
|
|
1622
1639
|
};
|
|
1623
1640
|
}
|
|
1624
1641
|
case "runtime":
|
|
1625
|
-
return { type, runtime: field(f, path, "runtime", readRuntimeStatus) };
|
|
1642
|
+
return { type, ...seqField, runtime: field(f, path, "runtime", readRuntimeStatus) };
|
|
1626
1643
|
case "event": {
|
|
1627
1644
|
const event = field(f, path, "event", (v, p) => readLauncherEvent(v, p, true));
|
|
1628
|
-
return event && { type,
|
|
1645
|
+
return event && { type, ...seqField, run_id: field(f, path, "run_id", nonEmptyString), event };
|
|
1629
1646
|
}
|
|
1630
1647
|
case "synced":
|
|
1631
1648
|
return {
|
|
1632
1649
|
type,
|
|
1633
|
-
|
|
1650
|
+
...seqField,
|
|
1651
|
+
run_id: field(f, path, "run_id", nullable(nonEmptyString)),
|
|
1634
1652
|
last_seq: field(f, path, "last_seq", nullable(integer))
|
|
1635
1653
|
};
|
|
1636
1654
|
case "session":
|
|
1637
|
-
return { type, session: field(f, path, "session", readSessionSummary) };
|
|
1655
|
+
return { type, ...seqField, session: field(f, path, "session", readSessionSummary) };
|
|
1638
1656
|
case "error":
|
|
1639
1657
|
return {
|
|
1640
1658
|
type,
|
|
1641
|
-
|
|
1659
|
+
...seqField,
|
|
1660
|
+
run_id: field(f, path, "run_id", nullable(nonEmptyString)),
|
|
1642
1661
|
...readServerProblem(value, path)
|
|
1643
1662
|
};
|
|
1644
1663
|
case "dropped":
|
|
1645
1664
|
return {
|
|
1646
1665
|
type,
|
|
1647
|
-
|
|
1666
|
+
...seqField,
|
|
1667
|
+
run_id: field(f, path, "run_id", nullable(nonEmptyString)),
|
|
1648
1668
|
reason: field(f, path, "reason", string),
|
|
1649
1669
|
log: field(f, path, "log", record(integer)),
|
|
1650
1670
|
at_least: field(f, path, "at_least", array(string)),
|
|
@@ -1653,7 +1673,8 @@ var readServerMessage = (value) => {
|
|
|
1653
1673
|
case "allowed":
|
|
1654
1674
|
return {
|
|
1655
1675
|
type,
|
|
1656
|
-
|
|
1676
|
+
...seqField,
|
|
1677
|
+
run_id: field(f, path, "run_id", nullable(nonEmptyString)),
|
|
1657
1678
|
allowed: field(f, path, "allowed", readServerAllowed)
|
|
1658
1679
|
};
|
|
1659
1680
|
case "resync":
|
|
@@ -1661,14 +1682,17 @@ var readServerMessage = (value) => {
|
|
|
1661
1682
|
case "variables":
|
|
1662
1683
|
return {
|
|
1663
1684
|
type,
|
|
1664
|
-
|
|
1685
|
+
...seqField,
|
|
1686
|
+
run_id: field(f, path, "run_id", nonEmptyString),
|
|
1665
1687
|
variables: field(f, path, "variables", readVariables)
|
|
1666
1688
|
};
|
|
1667
|
-
case "values":
|
|
1689
|
+
case "values": {
|
|
1690
|
+
const watchId = f["watch_id"] !== void 0 ? field(f, path, "watch_id", integer) : field(f, path, "id", integer);
|
|
1668
1691
|
return {
|
|
1669
1692
|
type,
|
|
1670
|
-
id:
|
|
1671
|
-
|
|
1693
|
+
id: watchId,
|
|
1694
|
+
watch_id: watchId,
|
|
1695
|
+
run_id: field(f, path, "run_id", nonEmptyString),
|
|
1672
1696
|
sim_ms: field(f, path, "sim_ms", nullable(number)),
|
|
1673
1697
|
paused: field(f, path, "paused", boolean),
|
|
1674
1698
|
peers: field(
|
|
@@ -1692,17 +1716,19 @@ var readServerMessage = (value) => {
|
|
|
1692
1716
|
})
|
|
1693
1717
|
)
|
|
1694
1718
|
};
|
|
1719
|
+
}
|
|
1695
1720
|
case "operation":
|
|
1696
1721
|
return {
|
|
1697
1722
|
type,
|
|
1698
|
-
|
|
1723
|
+
...seqField,
|
|
1724
|
+
run_id: field(f, path, "run_id", nonEmptyString),
|
|
1699
1725
|
...readOperationReport(value, path)
|
|
1700
1726
|
};
|
|
1701
1727
|
case "availability":
|
|
1702
1728
|
return {
|
|
1703
1729
|
type,
|
|
1704
|
-
|
|
1705
|
-
|
|
1730
|
+
...seqField,
|
|
1731
|
+
run_id: field(f, path, "run_id", nonEmptyString),
|
|
1706
1732
|
peers: field(
|
|
1707
1733
|
f,
|
|
1708
1734
|
path,
|
|
@@ -1762,7 +1788,8 @@ function errorMessage(error) {
|
|
|
1762
1788
|
}
|
|
1763
1789
|
function fetchTransport(options) {
|
|
1764
1790
|
const send = options.fetch ?? ((input, init) => globalThis.fetch(input, init));
|
|
1765
|
-
const
|
|
1791
|
+
const rawToken = options.token;
|
|
1792
|
+
const token = typeof rawToken === "function" ? rawToken : () => rawToken ?? null;
|
|
1766
1793
|
return (request, done) => {
|
|
1767
1794
|
const headers = {};
|
|
1768
1795
|
const current = token();
|
|
@@ -1868,29 +1895,6 @@ function scenarioView(summary) {
|
|
|
1868
1895
|
timelineUrl: summary.timeline_url
|
|
1869
1896
|
};
|
|
1870
1897
|
}
|
|
1871
|
-
function fullStepText(incoming, current) {
|
|
1872
|
-
if (incoming === null || current === null) return incoming;
|
|
1873
|
-
const cut = /^(.*)\.\.\. \((\d+) more characters\)$/s.exec(incoming);
|
|
1874
|
-
if (!cut) return incoming;
|
|
1875
|
-
const prefix = cut[1];
|
|
1876
|
-
return current.startsWith(prefix) && Array.from(current).length === Array.from(prefix).length + Number(cut[2]) ? current : incoming;
|
|
1877
|
-
}
|
|
1878
|
-
function mergeScenarioStep(current, incoming) {
|
|
1879
|
-
return {
|
|
1880
|
-
...incoming,
|
|
1881
|
-
text: fullStepText(incoming.text, current.text) ?? incoming.text,
|
|
1882
|
-
message: fullStepText(incoming.message, current.message)
|
|
1883
|
-
};
|
|
1884
|
-
}
|
|
1885
|
-
var stepPositions = /* @__PURE__ */ new WeakMap();
|
|
1886
|
-
function mergeScenarioSteps(current, incoming, merge = (_old, next) => next) {
|
|
1887
|
-
const steps = new Map(current.map((step) => [step.index, step]));
|
|
1888
|
-
for (const step of incoming) {
|
|
1889
|
-
const old = steps.get(step.index);
|
|
1890
|
-
steps.set(step.index, old ? merge(old, step) : step);
|
|
1891
|
-
}
|
|
1892
|
-
return [...steps.values()].sort((a, b) => a.index - b.index);
|
|
1893
|
-
}
|
|
1894
1898
|
function withStep(steps, step) {
|
|
1895
1899
|
const i = steps.findIndex((s) => s.index >= step.index);
|
|
1896
1900
|
if (i < 0) return [...steps, step];
|
|
@@ -1925,8 +1929,8 @@ function runOutcome(session) {
|
|
|
1925
1929
|
function sessionFromSummary(summary) {
|
|
1926
1930
|
const blank = {
|
|
1927
1931
|
id: summary.id,
|
|
1928
|
-
...summary.snapshot_rev == null ? {} : { snapshotRev: summary.snapshot_rev },
|
|
1929
1932
|
lastSeq: -1,
|
|
1933
|
+
runT0Ms: summary.run_t0_ms ?? 0,
|
|
1930
1934
|
file: summary.file,
|
|
1931
1935
|
disable: summary.disable,
|
|
1932
1936
|
manual: summary.manual,
|
|
@@ -1956,11 +1960,7 @@ function sessionFromSummary(summary) {
|
|
|
1956
1960
|
droppedMarks: 0,
|
|
1957
1961
|
scenario: null
|
|
1958
1962
|
};
|
|
1959
|
-
|
|
1960
|
-
return summary.last_seq == null ? adopted : {
|
|
1961
|
-
...adopted,
|
|
1962
|
-
pendingFindings: { through: summary.last_seq, keys: summary.findings.map(findingIdentity) }
|
|
1963
|
-
};
|
|
1963
|
+
return applySummary(blank, summary);
|
|
1964
1964
|
}
|
|
1965
1965
|
function addDropped(session, dropped) {
|
|
1966
1966
|
const counts = Object.entries(dropped.log).filter(([, count]) => count > 0);
|
|
@@ -1998,55 +1998,14 @@ function launcherOf(summary) {
|
|
|
1998
1998
|
silentSeconds: summary.launcher.silent_s
|
|
1999
1999
|
};
|
|
2000
2000
|
}
|
|
2001
|
-
function applySummary(session, summary
|
|
2002
|
-
|
|
2003
|
-
const
|
|
2004
|
-
const
|
|
2005
|
-
const
|
|
2006
|
-
const staleProjection = projectionRev !== null && (incomingRev === null || incomingRev < projectionRev);
|
|
2007
|
-
if (staleControl && (staleProjection || !force && controlOnly)) return session;
|
|
2008
|
-
const newer = force || (summary.last_seq ?? -1) > Math.max(session.lastSeq, session.observedSeq ?? -1, session.projectionSeq ?? -1);
|
|
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;
|
|
2013
|
-
const notLess = summary.problems.length + summary.problems_omitted >= session.problems.length + session.problemsOmitted;
|
|
2014
|
-
const mergedProblems = [...summary.problems];
|
|
2015
|
-
let omitted = summary.problems_omitted;
|
|
2016
|
-
if (summary.problem_seq != null) {
|
|
2017
|
-
const included = new Set(mergedProblems.map((problem) => problem.problem_seq));
|
|
2018
|
-
for (const problem of session.problems) {
|
|
2019
|
-
if (problem.problem_seq === void 0 || included.has(problem.problem_seq)) continue;
|
|
2020
|
-
if (mergedProblems.length >= MAX_PROBLEMS) break;
|
|
2021
|
-
mergedProblems.push(problem);
|
|
2022
|
-
if (problem.problem_seq <= summary.problem_seq && omitted > 0) omitted--;
|
|
2023
|
-
}
|
|
2024
|
-
}
|
|
2025
|
-
if (mergedProblems.every((problem) => problem.problem_seq !== void 0))
|
|
2026
|
-
mergedProblems.sort((a, b) => a.problem_seq - b.problem_seq);
|
|
2027
|
-
const next = staleControl ? session : {
|
|
2028
|
-
...session,
|
|
2029
|
-
...incomingRev === null ? {} : { snapshotRev: incomingRev },
|
|
2030
|
-
...summary.stop_at_ms === void 0 ? {} : { stopAtMs: summary.stop_at_ms },
|
|
2031
|
-
...summary.problem_seq == null ? {} : { problemSeq: Math.max(session.problemSeq ?? 0, summary.problem_seq) },
|
|
2032
|
-
state,
|
|
2033
|
-
launcher,
|
|
2034
|
-
stopRequests: Math.max(session.stopRequests, stopRequestsOf(summary.stop)),
|
|
2035
|
-
logSources: withSources(session.logSources, Object.keys(summary.log)),
|
|
2036
|
-
...summary.scenario?.timeline_url ? {
|
|
2037
|
-
scenario: session.scenario ? { ...session.scenario, timelineUrl: summary.scenario.timeline_url } : scenarioView(summary.scenario)
|
|
2038
|
-
} : {},
|
|
2039
|
-
...force || notLess ? { problems: mergedProblems, problemsOmitted: omitted } : {}
|
|
2040
|
-
};
|
|
2041
|
-
if (!newer || staleProjection || !force && controlOnly) {
|
|
2042
|
-
return next;
|
|
2043
|
-
}
|
|
2044
|
-
const phase = summary.phase ?? next.phase;
|
|
2001
|
+
function applySummary(session, summary) {
|
|
2002
|
+
if (summary.id !== session.id) return sessionFromSummary(summary);
|
|
2003
|
+
const runT0Ms = summary.run_t0_ms ?? session.runT0Ms;
|
|
2004
|
+
const elapsedMs = summary.last_t_ms === null ? session.elapsedMs : Math.max(session.elapsedMs, Math.max(0, summary.last_t_ms - runT0Ms));
|
|
2005
|
+
const phase = summary.phase ?? session.phase;
|
|
2045
2006
|
const rank = phaseIndex(phase);
|
|
2046
|
-
const
|
|
2047
|
-
const
|
|
2048
|
-
const check = (preserveEvents ? next.check : null) ?? summary.check ?? next.check ?? summary.result?.check ?? null;
|
|
2049
|
-
const result = (preserveEvents ? next.result : null) ?? summary.result ?? next.result;
|
|
2007
|
+
const check = summary.check ?? session.check ?? summary.result?.check ?? null;
|
|
2008
|
+
const result = summary.result ?? session.result;
|
|
2050
2009
|
const known = new Map(session.participants.map((p) => [p.name, p]));
|
|
2051
2010
|
const participants = summary.participants.map((p) => ({
|
|
2052
2011
|
name: p.name,
|
|
@@ -2056,66 +2015,66 @@ function applySummary(session, summary, force = false, controlOnly = false) {
|
|
|
2056
2015
|
exitCode: p.exit_code,
|
|
2057
2016
|
signal: p.signal,
|
|
2058
2017
|
failure: p.reason,
|
|
2059
|
-
message: p.message ??
|
|
2018
|
+
message: p.message ?? known.get(p.name)?.message ?? null,
|
|
2060
2019
|
// A stop the launcher asked for is kept even in summaries of later states (ended and so on)
|
|
2061
2020
|
stopRequested: p.stop_requested || p.state === "stop_requested" || !!known.get(p.name)?.stopRequested,
|
|
2062
2021
|
omittedFields: p.omitted_fields,
|
|
2063
2022
|
controlLink: p.control_link ?? known.get(p.name)?.controlLink ?? null,
|
|
2064
2023
|
manual: p.state === "manual" || p.command_line !== null || !!known.get(p.name)?.manual,
|
|
2065
|
-
commandLine: p.command_line ??
|
|
2066
|
-
workingDirectory: p.working_directory ??
|
|
2067
|
-
environment: p.environment ??
|
|
2024
|
+
commandLine: p.command_line ?? known.get(p.name)?.commandLine ?? null,
|
|
2025
|
+
workingDirectory: p.working_directory ?? known.get(p.name)?.workingDirectory ?? null,
|
|
2026
|
+
environment: p.environment ?? known.get(p.name)?.environment ?? {}
|
|
2068
2027
|
}));
|
|
2069
|
-
const
|
|
2028
|
+
const mergedParticipants = [
|
|
2029
|
+
...participants,
|
|
2030
|
+
...session.participants.filter((p) => !participants.some((current) => current.name === p.name))
|
|
2031
|
+
];
|
|
2032
|
+
let scenario = summary.scenario ? {
|
|
2070
2033
|
...scenarioView(summary.scenario),
|
|
2071
|
-
timelineUrl:
|
|
2072
|
-
} :
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
scenario.steps,
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
mergedScenario = {
|
|
2083
|
-
...mergedScenario,
|
|
2084
|
-
steps: mergeScenarioSteps(mergedScenario.steps, result.scenario.steps)
|
|
2034
|
+
timelineUrl: summary.scenario.timeline_url ?? session.scenario?.timelineUrl ?? null
|
|
2035
|
+
} : session.scenario;
|
|
2036
|
+
if (scenario && result?.scenario) {
|
|
2037
|
+
scenario = {
|
|
2038
|
+
...scenario,
|
|
2039
|
+
name: result.scenario.name ?? scenario.name,
|
|
2040
|
+
stepCount: result.scenario.steps.length,
|
|
2041
|
+
steps: result.scenario.steps,
|
|
2042
|
+
stepsOmitted: 0,
|
|
2043
|
+
status: result.scenario.status,
|
|
2044
|
+
overAtMs: result.scenario.over_at_ms
|
|
2085
2045
|
};
|
|
2086
2046
|
}
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
0,
|
|
2090
|
-
scenario.stepsOmitted - (mergedScenario.steps.length - scenario.steps.length)
|
|
2091
|
-
);
|
|
2092
|
-
}
|
|
2093
|
-
const mergedParticipants = preserveEvents ? [
|
|
2094
|
-
...participants,
|
|
2095
|
-
...next.participants.filter(
|
|
2096
|
-
(p) => !participants.some((current) => current.name === p.name)
|
|
2097
|
-
)
|
|
2098
|
-
] : participants;
|
|
2047
|
+
const problems = summary.problems.slice(0, MAX_PROBLEMS);
|
|
2048
|
+
const problemsOmitted = summary.problems_omitted + Math.max(0, summary.problems.length - problems.length);
|
|
2099
2049
|
return {
|
|
2100
|
-
...
|
|
2101
|
-
...
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2050
|
+
...session,
|
|
2051
|
+
...summary.stop_at_ms === void 0 ? {} : { stopAtMs: summary.stop_at_ms },
|
|
2052
|
+
runT0Ms,
|
|
2053
|
+
state: summary.state,
|
|
2054
|
+
launcher: launcherOf(summary),
|
|
2055
|
+
stopRequests: Math.max(session.stopRequests, stopRequestsOf(summary.stop)),
|
|
2056
|
+
logSources: withSources(session.logSources, Object.keys(summary.log)),
|
|
2057
|
+
problems,
|
|
2058
|
+
problemsOmitted,
|
|
2059
|
+
unreadable: summary.unreadable,
|
|
2060
|
+
phase: result ? "ended" : phase,
|
|
2061
|
+
phaseRank: result ? phaseIndex("ended") : rank >= 0 ? rank : session.phaseRank,
|
|
2062
|
+
elapsedMs,
|
|
2063
|
+
simMs: summary.sim_ms ?? session.simMs,
|
|
2064
|
+
timeOmittedFields: summary.sim_ms === null ? session.timeOmittedFields : summary.time_omitted_fields,
|
|
2065
|
+
time: summary.time ? timeView(summary.time) : session.time,
|
|
2066
|
+
lastCommand: summary.last_command ? commandView(summary.last_command, summary.last_command.seq ?? -1) : session.lastCommand,
|
|
2067
|
+
launcherState: newerState(session.launcherState, summary.launcher_state ?? null),
|
|
2068
|
+
findings: summary.findings.slice(0, MAX_FINDINGS),
|
|
2113
2069
|
result,
|
|
2114
2070
|
check,
|
|
2115
|
-
scenario
|
|
2071
|
+
scenario,
|
|
2116
2072
|
// Whether a participant is required or left out is in the check result (as is the order, that of the configuration
|
|
2117
2073
|
// file). If there is a result, how it ended (stopped or not) comes from the result too
|
|
2118
|
-
participants:
|
|
2074
|
+
participants: withResult(
|
|
2075
|
+
check ? mergeCheck(mergedParticipants, check) : mergedParticipants,
|
|
2076
|
+
result
|
|
2077
|
+
)
|
|
2119
2078
|
};
|
|
2120
2079
|
}
|
|
2121
2080
|
function newerState(current, incoming) {
|
|
@@ -2133,101 +2092,23 @@ function withSources(sources, names) {
|
|
|
2133
2092
|
return next;
|
|
2134
2093
|
}
|
|
2135
2094
|
function addProblem(session, problem) {
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
if (seq !== void 0 && session.problems.some((item) => item.problem_seq === seq))
|
|
2140
|
-
return updated;
|
|
2141
|
-
if (updated.problems.length >= MAX_PROBLEMS) {
|
|
2142
|
-
const alreadyCounted2 = seq !== void 0 && seq <= (session.problemSeq ?? 0);
|
|
2143
|
-
return alreadyCounted2 ? updated : { ...updated, problemsOmitted: updated.problemsOmitted + 1 };
|
|
2144
|
-
}
|
|
2145
|
-
const alreadyCounted = seq !== void 0 && seq <= (session.problemSeq ?? 0);
|
|
2146
|
-
const problems = [...updated.problems, problem];
|
|
2147
|
-
if (problems.every((item) => item.problem_seq !== void 0))
|
|
2148
|
-
problems.sort((a, b) => a.problem_seq - b.problem_seq);
|
|
2095
|
+
if (session.problems.length >= MAX_PROBLEMS) {
|
|
2096
|
+
return { ...session, problemsOmitted: session.problemsOmitted + 1 };
|
|
2097
|
+
}
|
|
2149
2098
|
return {
|
|
2150
|
-
...
|
|
2151
|
-
problems,
|
|
2152
|
-
problemsOmitted: alreadyCounted ? Math.max(0, updated.problemsOmitted - 1) : updated.problemsOmitted
|
|
2099
|
+
...session,
|
|
2100
|
+
problems: [...session.problems, problem]
|
|
2153
2101
|
};
|
|
2154
2102
|
}
|
|
2155
2103
|
function phaseIndex(phase) {
|
|
2156
2104
|
return phase === null ? -1 : PHASES.indexOf(phase);
|
|
2157
2105
|
}
|
|
2158
|
-
function findingKey(finding) {
|
|
2159
|
-
return JSON.stringify([
|
|
2160
|
-
finding.severity,
|
|
2161
|
-
finding.code,
|
|
2162
|
-
finding.file,
|
|
2163
|
-
finding.line,
|
|
2164
|
-
finding.participant,
|
|
2165
|
-
finding.network,
|
|
2166
|
-
finding.message,
|
|
2167
|
-
finding.detail
|
|
2168
|
-
]);
|
|
2169
|
-
}
|
|
2170
|
-
function findingIdentity(finding) {
|
|
2171
|
-
return finding.event_seq === void 0 ? `body:${findingKey(finding)}` : `seq:${finding.event_seq}`;
|
|
2172
|
-
}
|
|
2173
|
-
function mergeFindings(current, incoming) {
|
|
2174
|
-
const a = current.slice(0, MAX_FINDINGS);
|
|
2175
|
-
const b = incoming.slice(0, MAX_FINDINGS);
|
|
2176
|
-
if (a.every((finding) => finding.event_seq !== void 0) && b.every((finding) => finding.event_seq !== void 0)) {
|
|
2177
|
-
const bySeq = /* @__PURE__ */ new Map();
|
|
2178
|
-
for (const finding of [...b, ...a]) bySeq.set(finding.event_seq, finding);
|
|
2179
|
-
return [...bySeq.values()].sort((left, right) => left.event_seq - right.event_seq).slice(0, MAX_FINDINGS);
|
|
2180
|
-
}
|
|
2181
|
-
const ak = a.map(findingKey);
|
|
2182
|
-
const bk = b.map(findingKey);
|
|
2183
|
-
const sizes = Array.from({ length: a.length + 1 }, () => new Uint16Array(b.length + 1));
|
|
2184
|
-
for (let i2 = a.length - 1; i2 >= 0; --i2)
|
|
2185
|
-
for (let j2 = b.length - 1; j2 >= 0; --j2)
|
|
2186
|
-
sizes[i2][j2] = ak[i2] === bk[j2] ? 1 + sizes[i2 + 1][j2 + 1] : Math.max(sizes[i2 + 1][j2], sizes[i2][j2 + 1]);
|
|
2187
|
-
const merged = [];
|
|
2188
|
-
let i = 0, j = 0;
|
|
2189
|
-
while ((i < a.length || j < b.length) && merged.length < MAX_FINDINGS) {
|
|
2190
|
-
if (i < a.length && j < b.length && ak[i] === bk[j]) {
|
|
2191
|
-
merged.push(a[i++]);
|
|
2192
|
-
j++;
|
|
2193
|
-
} else if (j === b.length || i < a.length && sizes[i + 1][j] >= sizes[i][j + 1])
|
|
2194
|
-
merged.push(a[i++]);
|
|
2195
|
-
else merged.push(b[j++]);
|
|
2196
|
-
}
|
|
2197
|
-
return merged;
|
|
2198
|
-
}
|
|
2199
2106
|
function applyEvents(session, events, countStale = false) {
|
|
2200
2107
|
let next = session;
|
|
2201
2108
|
const logs = [];
|
|
2202
2109
|
let stale = 0;
|
|
2203
2110
|
for (const event of events) {
|
|
2204
2111
|
if (event.seq > next.lastSeq) {
|
|
2205
|
-
const tracked = [
|
|
2206
|
-
"time",
|
|
2207
|
-
"phase",
|
|
2208
|
-
"result",
|
|
2209
|
-
"finding",
|
|
2210
|
-
"participant",
|
|
2211
|
-
"command",
|
|
2212
|
-
CONTROL_EVENT
|
|
2213
|
-
].includes(event.event);
|
|
2214
|
-
if (event.event === "scenario_step") stepPositions.set(event.step, event.seq);
|
|
2215
|
-
next = {
|
|
2216
|
-
...next,
|
|
2217
|
-
observedSeq: Math.max(next.observedSeq ?? -1, event.seq),
|
|
2218
|
-
...tracked ? { eventSeqs: { ...next.eventSeqs, [event.event]: event.seq } } : {}
|
|
2219
|
-
};
|
|
2220
|
-
const pending = next.pendingFindings;
|
|
2221
|
-
if (event.event === "finding" && pending && event.seq <= pending.through) {
|
|
2222
|
-
const numbered = pending.keys.indexOf(`seq:${event.seq}`);
|
|
2223
|
-
const index = numbered === -1 ? pending.keys.indexOf(`body:${findingKey(event.finding)}`) : numbered;
|
|
2224
|
-
if (index !== -1) {
|
|
2225
|
-
const keys = [...pending.keys];
|
|
2226
|
-
keys.splice(index, 1);
|
|
2227
|
-
next = { ...next, lastSeq: event.seq, pendingFindings: { ...pending, keys } };
|
|
2228
|
-
continue;
|
|
2229
|
-
}
|
|
2230
|
-
}
|
|
2231
2112
|
next = applyOne(next, event, logs);
|
|
2232
2113
|
if (event.unreadable)
|
|
2233
2114
|
next = { ...next, unreadable: union(next.unreadable, event.unreadable) };
|
|
@@ -2247,37 +2128,6 @@ function applyEvents(session, events, countStale = false) {
|
|
|
2247
2128
|
}
|
|
2248
2129
|
return { ...next, logSources: sources };
|
|
2249
2130
|
}
|
|
2250
|
-
function recoverReplayLogs(session, recovered, notKept) {
|
|
2251
|
-
if (!recovered.length) return session;
|
|
2252
|
-
const sources = Object.fromEntries(
|
|
2253
|
-
Object.entries(session.logSources).map(([name, source]) => [
|
|
2254
|
-
name,
|
|
2255
|
-
{ lines: 0, dropped: source.dropped }
|
|
2256
|
-
])
|
|
2257
|
-
);
|
|
2258
|
-
const restored = /* @__PURE__ */ new Map();
|
|
2259
|
-
for (const line of recovered) {
|
|
2260
|
-
const source = sources[line.source] ??= { lines: 0, dropped: 0 };
|
|
2261
|
-
if (line.gap) source.dropped += line.gap.count;
|
|
2262
|
-
else {
|
|
2263
|
-
const count = restored.get(line.source) ?? 0;
|
|
2264
|
-
if (count < (notKept.get(line.source) ?? 0)) {
|
|
2265
|
-
source.dropped--;
|
|
2266
|
-
restored.set(line.source, count + 1);
|
|
2267
|
-
}
|
|
2268
|
-
}
|
|
2269
|
-
}
|
|
2270
|
-
const logs = session.logs.flatMap((line) => {
|
|
2271
|
-
if (!line.gap?.notKept) return [line];
|
|
2272
|
-
const available = restored.get(line.source) ?? 0;
|
|
2273
|
-
const count = Math.max(0, line.gap.count - available);
|
|
2274
|
-
restored.set(line.source, Math.max(0, available - line.gap.count));
|
|
2275
|
-
return count > 0 ? [{ ...line, gap: { ...line.gap, count } }] : [];
|
|
2276
|
-
});
|
|
2277
|
-
logs.push(...recovered);
|
|
2278
|
-
logs.sort((a, b) => a.seq - b.seq);
|
|
2279
|
-
return appendLogs({ ...session, logs: [], logSources: sources }, logs);
|
|
2280
|
-
}
|
|
2281
2131
|
function appendLogs(session, added) {
|
|
2282
2132
|
const sources = {};
|
|
2283
2133
|
for (const [source, counts] of Object.entries(session.logSources))
|
|
@@ -2318,10 +2168,13 @@ function appendLogs(session, added) {
|
|
|
2318
2168
|
return { ...session, logs: kept, logSources: sources };
|
|
2319
2169
|
}
|
|
2320
2170
|
function applyOne(session, event, logs) {
|
|
2171
|
+
const runT0Ms = event.event === "run_start" && event.t_ms !== null ? event.t_ms : session.runT0Ms;
|
|
2172
|
+
const elapsedMs = event.t_ms === null ? session.elapsedMs : Math.max(session.elapsedMs, Math.max(0, event.t_ms - runT0Ms));
|
|
2321
2173
|
const next = {
|
|
2322
2174
|
...session,
|
|
2323
2175
|
lastSeq: event.seq,
|
|
2324
|
-
|
|
2176
|
+
runT0Ms,
|
|
2177
|
+
elapsedMs
|
|
2325
2178
|
};
|
|
2326
2179
|
switch (event.event) {
|
|
2327
2180
|
case "phase": {
|
|
@@ -2373,7 +2226,7 @@ function applyOne(session, event, logs) {
|
|
|
2373
2226
|
case "finding":
|
|
2374
2227
|
return next.findings.length >= MAX_FINDINGS ? next : {
|
|
2375
2228
|
...next,
|
|
2376
|
-
findings:
|
|
2229
|
+
findings: [...next.findings, { ...event.finding }]
|
|
2377
2230
|
};
|
|
2378
2231
|
case "time":
|
|
2379
2232
|
return { ...next, simMs: event.sim_ms, timeOmittedFields: [], time: timeView(event) };
|
|
@@ -2508,13 +2361,16 @@ var RunControl = class {
|
|
|
2508
2361
|
this.currentStopping = derived(
|
|
2509
2362
|
[this.pendingRevision, this.startSending, feed.session],
|
|
2510
2363
|
() => {
|
|
2511
|
-
const key = this.startSending.get() ? this.startOperation : JSON.stringify(
|
|
2364
|
+
const key = this.startSending.get() ? this.startOperation : JSON.stringify(this.activeTarget());
|
|
2512
2365
|
return [...this.pendingStops].filter((pending) => pending.key === key).at(-1)?.action ?? null;
|
|
2513
2366
|
},
|
|
2514
2367
|
Object.is,
|
|
2515
2368
|
onError
|
|
2516
2369
|
);
|
|
2517
2370
|
this.stopWhileStarting = this.stopAskedWhileStarting.readonly();
|
|
2371
|
+
feed.session.subscribe(() => {
|
|
2372
|
+
this.startedTarget = null;
|
|
2373
|
+
});
|
|
2518
2374
|
this.error = derived(
|
|
2519
2375
|
[this.failure, feed.session],
|
|
2520
2376
|
() => {
|
|
@@ -2532,6 +2388,7 @@ var RunControl = class {
|
|
|
2532
2388
|
transport;
|
|
2533
2389
|
startTimeoutMs;
|
|
2534
2390
|
startOperation = null;
|
|
2391
|
+
startedTarget = null;
|
|
2535
2392
|
pendingStops = /* @__PURE__ */ new Set();
|
|
2536
2393
|
pendingRevision;
|
|
2537
2394
|
startSending;
|
|
@@ -2548,28 +2405,30 @@ var RunControl = class {
|
|
|
2548
2405
|
if (this.startSending.get()) return Promise.reject(new Error("a start is already pending"));
|
|
2549
2406
|
let resolveStart;
|
|
2550
2407
|
let rejectStart;
|
|
2551
|
-
const operation = new Promise(
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
}
|
|
2556
|
-
);
|
|
2408
|
+
const operation = new Promise((resolve, reject) => {
|
|
2409
|
+
resolveStart = resolve;
|
|
2410
|
+
rejectStart = reject;
|
|
2411
|
+
});
|
|
2557
2412
|
this.startOperation = operation;
|
|
2413
|
+
this.startedTarget = null;
|
|
2558
2414
|
this.stopAskedWhileStarting.set(false);
|
|
2559
2415
|
this.startSending.set(true);
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
this.startSending.set(false);
|
|
2567
|
-
},
|
|
2568
|
-
(seen) => {
|
|
2569
|
-
instance = seen;
|
|
2416
|
+
this.send("api/run", request, this.startTimeoutMs() || void 0, (ack) => {
|
|
2417
|
+
if (ack && this.feed.currentTarget()?.run_id !== ack.run_id) {
|
|
2418
|
+
this.startedTarget = {
|
|
2419
|
+
target: { run_id: ack.run_id, instance: ack.instance },
|
|
2420
|
+
sessionBefore: this.feed.session.get()
|
|
2421
|
+
};
|
|
2570
2422
|
}
|
|
2571
|
-
|
|
2572
|
-
|
|
2423
|
+
this.startSending.set(false);
|
|
2424
|
+
}).then(resolveStart, rejectStart);
|
|
2425
|
+
return operation;
|
|
2426
|
+
}
|
|
2427
|
+
activeTarget() {
|
|
2428
|
+
if (this.startedTarget && this.feed.session.get() === this.startedTarget.sessionBefore) {
|
|
2429
|
+
return this.startedTarget.target;
|
|
2430
|
+
}
|
|
2431
|
+
return this.feed.currentTarget();
|
|
2573
2432
|
}
|
|
2574
2433
|
/** Stops in order (waits for the participants to end). Asking again never turns it into a stop without waiting. */
|
|
2575
2434
|
stop() {
|
|
@@ -2581,13 +2440,13 @@ var RunControl = class {
|
|
|
2581
2440
|
}
|
|
2582
2441
|
captureStop() {
|
|
2583
2442
|
const starting = this.startSending.get() ? this.startOperation : null;
|
|
2584
|
-
const target = starting ? null : this.
|
|
2443
|
+
const target = starting ? null : this.activeTarget();
|
|
2585
2444
|
return {
|
|
2586
2445
|
key: starting ?? JSON.stringify(target),
|
|
2587
2446
|
send: (force) => this.requestStop(force, starting, target)
|
|
2588
2447
|
};
|
|
2589
2448
|
}
|
|
2590
|
-
requestStop(force, starting = this.startSending.get() ? this.startOperation : null, target = starting ? null : this.
|
|
2449
|
+
requestStop(force, starting = this.startSending.get() ? this.startOperation : null, target = starting ? null : this.activeTarget()) {
|
|
2591
2450
|
const session = this.feed.session.get();
|
|
2592
2451
|
const pending = {
|
|
2593
2452
|
action: force ? "force" : "stop",
|
|
@@ -2619,22 +2478,12 @@ var RunControl = class {
|
|
|
2619
2478
|
}
|
|
2620
2479
|
this.stopAskedWhileStarting.set(true);
|
|
2621
2480
|
return starting.then(
|
|
2622
|
-
(
|
|
2623
|
-
|
|
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 });
|
|
2481
|
+
(ack) => {
|
|
2482
|
+
pending.key = JSON.stringify({ run_id: ack.run_id, instance: ack.instance });
|
|
2634
2483
|
this.pendingRevision.update((n) => n + 1);
|
|
2635
2484
|
return this.send(
|
|
2636
2485
|
"api/stop-session",
|
|
2637
|
-
{ force,
|
|
2486
|
+
{ force, run_id: ack.run_id, instance: ack.instance },
|
|
2638
2487
|
void 0,
|
|
2639
2488
|
() => void 0
|
|
2640
2489
|
);
|
|
@@ -2651,10 +2500,10 @@ var RunControl = class {
|
|
|
2651
2500
|
).finally(done);
|
|
2652
2501
|
}
|
|
2653
2502
|
/**
|
|
2654
|
-
* Sends and
|
|
2655
|
-
* settles.
|
|
2503
|
+
* Sends an HTTP command and reads its `{instance, run_id}` acknowledgement. done is called after the answer
|
|
2504
|
+
* (failures too), before the Promise settles.
|
|
2656
2505
|
*/
|
|
2657
|
-
send(path, body, timeoutMs, done
|
|
2506
|
+
send(path, body, timeoutMs, done) {
|
|
2658
2507
|
const incompatible = this.feed.incompatible.get();
|
|
2659
2508
|
if (incompatible) {
|
|
2660
2509
|
done();
|
|
@@ -2678,35 +2527,40 @@ var RunControl = class {
|
|
|
2678
2527
|
reject(failure);
|
|
2679
2528
|
return;
|
|
2680
2529
|
}
|
|
2681
|
-
let
|
|
2530
|
+
let ack;
|
|
2682
2531
|
try {
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2532
|
+
if (path === "api/stop-session") {
|
|
2533
|
+
const target = body;
|
|
2534
|
+
const raw = typeof outcome.body === "object" && outcome.body !== null ? outcome.body : {};
|
|
2535
|
+
ack = readRunResponse({
|
|
2536
|
+
instance: raw["instance"] ?? target.instance,
|
|
2537
|
+
run_id: raw["run_id"]
|
|
2538
|
+
});
|
|
2539
|
+
if (ack.run_id !== target.run_id || ack.instance !== target.instance) {
|
|
2540
|
+
throw new Error("the stop answer did not identify the requested session");
|
|
2541
|
+
}
|
|
2542
|
+
} else {
|
|
2543
|
+
readSessionInstance(outcome.body);
|
|
2544
|
+
ack = readRunResponse(outcome.body);
|
|
2687
2545
|
}
|
|
2688
|
-
onInstance?.(instance);
|
|
2689
|
-
this.feed.adopt(summary, instance);
|
|
2690
2546
|
} catch (error) {
|
|
2691
2547
|
this.feed.report(
|
|
2692
2548
|
error instanceof ProtocolError ? `unreadable answer: ${error.message}` : String(error)
|
|
2693
2549
|
);
|
|
2694
2550
|
const missingInstance = error instanceof ProtocolError && error.path === "response.instance";
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
return;
|
|
2706
|
-
}
|
|
2551
|
+
const message = missingInstance ? `${error.message}. The run may have started. Check the current run before retrying` : path === "api/stop-session" ? "the stop answer was unreadable: check the session before trying again" : "the start answer did not identify the run; no stop was sent";
|
|
2552
|
+
const session = this.feed.session.get();
|
|
2553
|
+
this.failure.set({
|
|
2554
|
+
message,
|
|
2555
|
+
session: session?.id ?? null,
|
|
2556
|
+
running: isRunActive(session)
|
|
2557
|
+
});
|
|
2558
|
+
done();
|
|
2559
|
+
reject(new Error(message));
|
|
2560
|
+
return;
|
|
2707
2561
|
}
|
|
2708
|
-
done();
|
|
2709
|
-
resolve(
|
|
2562
|
+
done(ack);
|
|
2563
|
+
resolve(ack);
|
|
2710
2564
|
});
|
|
2711
2565
|
});
|
|
2712
2566
|
}
|
|
@@ -2716,12 +2570,13 @@ var RunControl = class {
|
|
|
2716
2570
|
var MAX_NOTICES = 20;
|
|
2717
2571
|
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)";
|
|
2718
2572
|
function sameRunTarget(left, right) {
|
|
2719
|
-
return left !== null && right !== null && left.
|
|
2573
|
+
return left !== null && right !== null && left.run_id === right.run_id && left.instance === right.instance;
|
|
2720
2574
|
}
|
|
2721
2575
|
var SessionFeed = class {
|
|
2722
|
-
constructor(connection, onError = rethrowLater) {
|
|
2576
|
+
constructor(connection, onError = rethrowLater, onInstance) {
|
|
2723
2577
|
this.connection = connection;
|
|
2724
2578
|
this.onError = onError;
|
|
2579
|
+
this.onInstance = onInstance;
|
|
2725
2580
|
this.current = new Writable(null, Object.is, onError);
|
|
2726
2581
|
this.synced = new Writable(false, Object.is, onError);
|
|
2727
2582
|
this.allowedValue = new Writable(null, Object.is, onError);
|
|
@@ -2750,11 +2605,11 @@ var SessionFeed = class {
|
|
|
2750
2605
|
}
|
|
2751
2606
|
connection;
|
|
2752
2607
|
onError;
|
|
2608
|
+
onInstance;
|
|
2753
2609
|
rawListeners = /* @__PURE__ */ new Set();
|
|
2754
|
-
snapshotVersion = () => 0;
|
|
2755
2610
|
instanceId = null;
|
|
2756
|
-
|
|
2757
|
-
|
|
2611
|
+
lastStreamSeq = -1;
|
|
2612
|
+
resyncing = false;
|
|
2758
2613
|
stopTarget = null;
|
|
2759
2614
|
current;
|
|
2760
2615
|
synced;
|
|
@@ -2767,7 +2622,6 @@ var SessionFeed = class {
|
|
|
2767
2622
|
messageListeners = /* @__PURE__ */ new Set();
|
|
2768
2623
|
noticeId = 0;
|
|
2769
2624
|
stoppedFlag = false;
|
|
2770
|
-
replayLogs = null;
|
|
2771
2625
|
session;
|
|
2772
2626
|
ready;
|
|
2773
2627
|
allowed;
|
|
@@ -2781,13 +2635,19 @@ var SessionFeed = class {
|
|
|
2781
2635
|
return this.stoppedFlag;
|
|
2782
2636
|
}
|
|
2783
2637
|
/**
|
|
2784
|
-
* Fields to add to the authentication message: where in the
|
|
2638
|
+
* Fields to add to the authentication message: where in the stream it holds the server should resend from. Called
|
|
2785
2639
|
* on every connect (after the call, the copy is not in sync until hello and the resent events have arrived). Used
|
|
2786
2640
|
* only inside the library.
|
|
2787
2641
|
*/
|
|
2788
2642
|
resumeFields() {
|
|
2789
2643
|
this.synced.set(false);
|
|
2790
|
-
|
|
2644
|
+
const session = this.current.get();
|
|
2645
|
+
if (this.instanceId === null || session === null || this.lastStreamSeq < 0) return {};
|
|
2646
|
+
return {
|
|
2647
|
+
instance: this.instanceId,
|
|
2648
|
+
run_id: session.id,
|
|
2649
|
+
after_stream_seq: this.lastStreamSeq
|
|
2650
|
+
};
|
|
2791
2651
|
}
|
|
2792
2652
|
onMessages(listener) {
|
|
2793
2653
|
this.messageListeners.add(listener);
|
|
@@ -2795,23 +2655,10 @@ var SessionFeed = class {
|
|
|
2795
2655
|
this.messageListeners.delete(listener);
|
|
2796
2656
|
};
|
|
2797
2657
|
}
|
|
2798
|
-
/**
|
|
2799
|
-
* Applies the summary in an HTTP answer without waiting for the notification (the answers to start, stop and
|
|
2800
|
-
* fetchSession(); used inside the library). While the WebSocket is connected, takes only the launcher and the stop
|
|
2801
|
-
* request for the same run (the rest arrives in notifications). A summary of an earlier run never brings back an old
|
|
2802
|
-
* run over a new one.
|
|
2803
|
-
*/
|
|
2804
2658
|
onRawMessages(listener) {
|
|
2805
2659
|
this.rawListeners.add(listener);
|
|
2806
2660
|
return () => this.rawListeners.delete(listener);
|
|
2807
2661
|
}
|
|
2808
|
-
onSnapshotVersion(read2) {
|
|
2809
|
-
this.snapshotVersion = read2;
|
|
2810
|
-
}
|
|
2811
|
-
/** Called before a new server's session can be published. */
|
|
2812
|
-
onInstance(listener) {
|
|
2813
|
-
this.instanceListener = listener;
|
|
2814
|
-
}
|
|
2815
2662
|
/** Instance associated with the current session, or null if its origin is not known. */
|
|
2816
2663
|
currentInstance() {
|
|
2817
2664
|
return this.instanceId;
|
|
@@ -2819,52 +2666,6 @@ var SessionFeed = class {
|
|
|
2819
2666
|
currentTarget() {
|
|
2820
2667
|
return this.stopTarget ? { ...this.stopTarget } : null;
|
|
2821
2668
|
}
|
|
2822
|
-
adopt(summary, instance, resyncFrom) {
|
|
2823
|
-
const switching = this.instanceId !== null && instance !== this.instanceId;
|
|
2824
|
-
if (switching && (resyncFrom !== this.instanceId || this.connection.state.get() === "open"))
|
|
2825
|
-
return null;
|
|
2826
|
-
const previous = switching ? null : this.current.get();
|
|
2827
|
-
if (summary && previous && summary.id < previous.id) return null;
|
|
2828
|
-
if (!summary && instance === this.instanceId)
|
|
2829
|
-
return {
|
|
2830
|
-
revision: this.adoptionRevision,
|
|
2831
|
-
instance,
|
|
2832
|
-
session: previous?.id ?? null
|
|
2833
|
-
};
|
|
2834
|
-
const revision = ++this.adoptionRevision;
|
|
2835
|
-
const next = !summary ? null : previous?.id === summary.id ? applySummary(previous, summary, false, this.connection.state.get() === "open") : sessionFromSummary(summary);
|
|
2836
|
-
const changedInstance = instance !== this.instanceId;
|
|
2837
|
-
this.instanceId = instance;
|
|
2838
|
-
const adoption = { revision, instance, session: next?.id ?? null };
|
|
2839
|
-
this.stopTarget = next ? { session: next.id, instance } : null;
|
|
2840
|
-
const notifySession = this.current.setDeferred(next);
|
|
2841
|
-
const notifyAllowed = switching ? this.allowedValue.setDeferred(null) : () => void 0;
|
|
2842
|
-
if (changedInstance) this.instanceListener(instance, () => this.isCurrent(revision));
|
|
2843
|
-
notifySession();
|
|
2844
|
-
notifyAllowed();
|
|
2845
|
-
if (!this.sameRun(adoption)) return null;
|
|
2846
|
-
this.adoptAllowed(summary?.allowed ?? null);
|
|
2847
|
-
return this.sameRun(adoption) ? adoption : null;
|
|
2848
|
-
}
|
|
2849
|
-
sameRun(adoption) {
|
|
2850
|
-
return this.instanceId === adoption.instance && (this.current.get()?.id ?? null) === adoption.session;
|
|
2851
|
-
}
|
|
2852
|
-
isCurrent(revision) {
|
|
2853
|
-
return revision === this.adoptionRevision;
|
|
2854
|
-
}
|
|
2855
|
-
/**
|
|
2856
|
-
* Takes what the server accepts (an HTTP answer or a notification): the one with the larger `rev` wins (rev 0 is a
|
|
2857
|
-
* server that does not number it: the newest arrival wins). Used inside the library.
|
|
2858
|
-
*/
|
|
2859
|
-
adoptAllowed(allowed) {
|
|
2860
|
-
if (!allowed) return;
|
|
2861
|
-
const current = this.allowedValue.get();
|
|
2862
|
-
if (!current || allowed.rev === 0 || allowed.rev >= current.rev) this.allowedValue.set(allowed);
|
|
2863
|
-
}
|
|
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
2669
|
report(message, count = 1) {
|
|
2869
2670
|
this.notify(message, count);
|
|
2870
2671
|
}
|
|
@@ -2873,7 +2674,6 @@ var SessionFeed = class {
|
|
|
2873
2674
|
}
|
|
2874
2675
|
/** Reads and applies a batch from the connection. */
|
|
2875
2676
|
receive(raw) {
|
|
2876
|
-
const snapshotVersion = this.snapshotVersion();
|
|
2877
2677
|
const epoch = this.connection.batchEpoch();
|
|
2878
2678
|
let originInstance = this.instanceId;
|
|
2879
2679
|
const currentOrigin = () => this.connection.batchEpoch() === epoch && this.instanceId === originInstance;
|
|
@@ -2911,8 +2711,6 @@ var SessionFeed = class {
|
|
|
2911
2711
|
break;
|
|
2912
2712
|
}
|
|
2913
2713
|
}
|
|
2914
|
-
let filtered = this.filterOlderRuns(batch, accepted);
|
|
2915
|
-
if (filtered.staleHello && stop === null) stop = "lost";
|
|
2916
2714
|
if (stop === "unauthorized" || stop === "incompatible") {
|
|
2917
2715
|
this.stoppedFlag = true;
|
|
2918
2716
|
this.connection.close();
|
|
@@ -2923,8 +2721,7 @@ var SessionFeed = class {
|
|
|
2923
2721
|
}
|
|
2924
2722
|
if (stop === "lost") this.connection.restart();
|
|
2925
2723
|
if (!currentOrigin()) return;
|
|
2926
|
-
|
|
2927
|
-
this.apply(filtered.batch, filtered.raw, snapshotVersion, currentOrigin, (instance) => {
|
|
2724
|
+
this.apply(batch, accepted, currentOrigin, (instance) => {
|
|
2928
2725
|
originInstance = instance;
|
|
2929
2726
|
});
|
|
2930
2727
|
if (!currentOrigin()) return;
|
|
@@ -2932,53 +2729,23 @@ var SessionFeed = class {
|
|
|
2932
2729
|
if (stop === "unauthorized") this.rejectedValue.set(true);
|
|
2933
2730
|
if (incompatible !== null) this.incompatibleValue.set(incompatible);
|
|
2934
2731
|
}
|
|
2935
|
-
|
|
2936
|
-
filterOlderRuns(batch, raw) {
|
|
2937
|
-
let instance = this.instanceId;
|
|
2938
|
-
let floor = this.current.get()?.id ?? null;
|
|
2939
|
-
let staleHello = false;
|
|
2940
|
-
const selected = [];
|
|
2941
|
-
const selectedRaw = [];
|
|
2942
|
-
batch.forEach((message, index) => {
|
|
2943
|
-
if (message.type === "hello") {
|
|
2944
|
-
const id = message.session?.id ?? null;
|
|
2945
|
-
if (instance === message.instance && floor !== null && (id === null || id < floor)) {
|
|
2946
|
-
staleHello = true;
|
|
2947
|
-
return;
|
|
2948
|
-
}
|
|
2949
|
-
if (instance !== message.instance) {
|
|
2950
|
-
instance = message.instance;
|
|
2951
|
-
floor = id;
|
|
2952
|
-
} else if (id !== null) floor = id;
|
|
2953
|
-
} else {
|
|
2954
|
-
const id = message.type === "session" ? message.session.id : "session" in message && typeof message.session === "number" ? message.session : null;
|
|
2955
|
-
if (id !== null && floor !== null && id < floor) return;
|
|
2956
|
-
if (message.type === "session" && (floor === null || message.session.id > floor))
|
|
2957
|
-
floor = message.session.id;
|
|
2958
|
-
}
|
|
2959
|
-
selected.push(message);
|
|
2960
|
-
selectedRaw.push(raw[index]);
|
|
2961
|
-
});
|
|
2962
|
-
return { batch: selected, raw: selectedRaw, staleHello };
|
|
2963
|
-
}
|
|
2964
|
-
apply(batch, raw, snapshotVersion, currentOrigin, commitOrigin) {
|
|
2732
|
+
apply(batch, raw, currentOrigin, commitOrigin) {
|
|
2965
2733
|
if (batch.length === 0) return;
|
|
2966
|
-
const revision = ++this.adoptionRevision;
|
|
2967
2734
|
const before = this.current.get();
|
|
2968
|
-
|
|
2969
|
-
let instance = originalInstance;
|
|
2735
|
+
let instance = this.instanceId;
|
|
2970
2736
|
let session = before;
|
|
2971
|
-
let
|
|
2972
|
-
|
|
2737
|
+
let streamSeq = this.lastStreamSeq;
|
|
2738
|
+
let resyncing = this.resyncing;
|
|
2973
2739
|
let events = [];
|
|
2974
2740
|
const notices = [];
|
|
2741
|
+
const selectedBatch = [];
|
|
2742
|
+
const selectedRaw = [];
|
|
2975
2743
|
let applied = false;
|
|
2976
2744
|
let synced = this.synced.get();
|
|
2977
2745
|
let allowedNow = this.allowedValue.get();
|
|
2978
2746
|
let runtimeNow = this.runtimeValue.get();
|
|
2979
|
-
const takeAllowed = (incoming
|
|
2980
|
-
if (
|
|
2981
|
-
if (replace || !allowedNow || incoming.rev === 0 || incoming.rev >= allowedNow.rev) {
|
|
2747
|
+
const takeAllowed = (incoming) => {
|
|
2748
|
+
if (incoming) {
|
|
2982
2749
|
allowedNow = incoming;
|
|
2983
2750
|
}
|
|
2984
2751
|
};
|
|
@@ -2990,134 +2757,177 @@ var SessionFeed = class {
|
|
|
2990
2757
|
}
|
|
2991
2758
|
events = [];
|
|
2992
2759
|
};
|
|
2993
|
-
for (
|
|
2760
|
+
for (let i = 0; i < batch.length; i++) {
|
|
2761
|
+
const message = batch[i];
|
|
2762
|
+
const rawMessage = raw[i];
|
|
2763
|
+
if (message.type !== "hello" && message.type !== "resync" && message.type !== "values" && typeof message.stream_seq === "number") {
|
|
2764
|
+
if (!replaying && message.stream_seq <= streamSeq) {
|
|
2765
|
+
continue;
|
|
2766
|
+
}
|
|
2767
|
+
streamSeq = Math.max(streamSeq, message.stream_seq);
|
|
2768
|
+
}
|
|
2994
2769
|
if (message.type !== "event") flush();
|
|
2995
2770
|
switch (message.type) {
|
|
2996
2771
|
case "hello": {
|
|
2997
2772
|
synced = false;
|
|
2998
2773
|
replaying = true;
|
|
2999
2774
|
const { session: summary, replay } = message;
|
|
3000
|
-
const
|
|
3001
|
-
|
|
2775
|
+
const sameInstance = instance !== null && instance === message.instance;
|
|
2776
|
+
const sameRun = !!summary && sameInstance && session?.id === summary.id;
|
|
2777
|
+
const deltaResume = sameRun && !resyncing && replay?.after_stream_seq != null;
|
|
2778
|
+
resyncing = false;
|
|
2779
|
+
if (typeof message.stream_seq === "number") {
|
|
2780
|
+
streamSeq = message.stream_seq;
|
|
2781
|
+
} else if (!sameInstance) {
|
|
2782
|
+
streamSeq = summary ? summary.last_seq ?? 0 : -1;
|
|
2783
|
+
} else if (summary) {
|
|
2784
|
+
streamSeq = deltaResume ? Math.max(streamSeq, summary.last_seq ?? 0) : summary.last_seq ?? 0;
|
|
2785
|
+
} else {
|
|
2786
|
+
streamSeq = -1;
|
|
2787
|
+
}
|
|
2788
|
+
takeAllowed(message.allowed ?? summary?.allowed ?? null);
|
|
3002
2789
|
if (message.runtime !== void 0) {
|
|
3003
2790
|
runtimeNow = message.runtime;
|
|
3004
|
-
} else if (
|
|
2791
|
+
} else if (!sameInstance) {
|
|
3005
2792
|
runtimeNow = null;
|
|
3006
2793
|
}
|
|
3007
|
-
const sameRun2 = summary && instance === message.instance && session?.id === summary.id;
|
|
3008
|
-
const resumed = sameRun2 && replay?.from_seq != null;
|
|
3009
2794
|
instance = message.instance;
|
|
3010
|
-
if (!sameRun2) replayLogs = null;
|
|
3011
2795
|
if (!summary) {
|
|
3012
2796
|
session = null;
|
|
3013
|
-
} else if (
|
|
3014
|
-
|
|
3015
|
-
if (!resumed && instance) {
|
|
3016
|
-
const logs = replayLogs ? recoverReplayLogs(kept, unseenLogs(), replayLogs.notKept).logs : kept.logs;
|
|
3017
|
-
replayLogs = {
|
|
3018
|
-
instance,
|
|
3019
|
-
session: summary.id,
|
|
3020
|
-
logs: logs.filter((line) => !line.gap || line.gap.launcher),
|
|
3021
|
-
unseen: new Set(logs.map((line) => line.seq)),
|
|
3022
|
-
notKept: /* @__PURE__ */ new Map()
|
|
3023
|
-
};
|
|
3024
|
-
}
|
|
3025
|
-
session = resumed ? kept : { ...kept, lastSeq: -1, logs: [], logSources: {}, droppedMarks: 0 };
|
|
2797
|
+
} else if (deltaResume && session) {
|
|
2798
|
+
session = applySummary(session, summary);
|
|
3026
2799
|
} else {
|
|
3027
2800
|
session = sessionFromSummary(summary);
|
|
3028
2801
|
}
|
|
2802
|
+
selectedBatch.push(message);
|
|
2803
|
+
selectedRaw.push(rawMessage);
|
|
3029
2804
|
break;
|
|
3030
2805
|
}
|
|
3031
2806
|
case "dropped": {
|
|
3032
|
-
if (session && message.
|
|
2807
|
+
if (session && message.run_id === session.id) {
|
|
3033
2808
|
session = addDropped(session, message);
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
replayLogs.notKept.set(source, (replayLogs.notKept.get(source) ?? 0) + count);
|
|
3037
|
-
}
|
|
2809
|
+
} else if (session && message.run_id !== null) {
|
|
2810
|
+
continue;
|
|
3038
2811
|
}
|
|
2812
|
+
selectedBatch.push(message);
|
|
2813
|
+
selectedRaw.push(rawMessage);
|
|
3039
2814
|
break;
|
|
3040
2815
|
}
|
|
3041
|
-
case "synced":
|
|
3042
|
-
if (
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
2816
|
+
case "synced": {
|
|
2817
|
+
if (message.run_id === null ? session === null : session?.id === message.run_id) {
|
|
2818
|
+
synced = true;
|
|
2819
|
+
replaying = false;
|
|
2820
|
+
} else {
|
|
2821
|
+
continue;
|
|
2822
|
+
}
|
|
2823
|
+
selectedBatch.push(message);
|
|
2824
|
+
selectedRaw.push(rawMessage);
|
|
3047
2825
|
break;
|
|
2826
|
+
}
|
|
3048
2827
|
case "allowed":
|
|
2828
|
+
if (message.run_id !== null && (!session || message.run_id !== session.id)) {
|
|
2829
|
+
continue;
|
|
2830
|
+
}
|
|
3049
2831
|
takeAllowed(message.allowed);
|
|
2832
|
+
selectedBatch.push(message);
|
|
2833
|
+
selectedRaw.push(rawMessage);
|
|
3050
2834
|
break;
|
|
3051
2835
|
case "runtime":
|
|
3052
2836
|
runtimeNow = message.runtime;
|
|
2837
|
+
selectedBatch.push(message);
|
|
2838
|
+
selectedRaw.push(rawMessage);
|
|
3053
2839
|
break;
|
|
3054
2840
|
case "session":
|
|
3055
|
-
if (session?.id !== message.session.id) replayLogs = null;
|
|
3056
2841
|
takeAllowed(message.session.allowed);
|
|
3057
|
-
session = session?.id === message.session.id ? applySummary(
|
|
3058
|
-
|
|
3059
|
-
message.session
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
2842
|
+
session = session?.id === message.session.id ? applySummary(session, message.session) : sessionFromSummary(message.session);
|
|
2843
|
+
if (typeof message.stream_seq !== "number" && message.session.last_seq !== null) {
|
|
2844
|
+
streamSeq = Math.max(streamSeq, message.session.last_seq);
|
|
2845
|
+
}
|
|
2846
|
+
selectedBatch.push(message);
|
|
2847
|
+
selectedRaw.push(rawMessage);
|
|
3063
2848
|
break;
|
|
3064
2849
|
case "event":
|
|
3065
|
-
if (session?.id === message.
|
|
3066
|
-
if (message.event.event === "log" || message.event.event === "log_dropped")
|
|
3067
|
-
replayLogs?.unseen.delete(message.event.seq);
|
|
2850
|
+
if (session?.id === message.run_id) {
|
|
3068
2851
|
events.push(message.event);
|
|
2852
|
+
if (typeof message.stream_seq !== "number") {
|
|
2853
|
+
streamSeq = Math.max(streamSeq, message.event.seq);
|
|
2854
|
+
}
|
|
2855
|
+
selectedBatch.push(message);
|
|
2856
|
+
selectedRaw.push(rawMessage);
|
|
3069
2857
|
}
|
|
3070
2858
|
break;
|
|
3071
2859
|
case "error":
|
|
3072
2860
|
if (message.code === "unauthorized") {
|
|
3073
|
-
} else if (session && message.
|
|
3074
|
-
const { code, message: text3, skipped
|
|
2861
|
+
} else if (session && message.run_id === session.id) {
|
|
2862
|
+
const { code, message: text3, skipped } = message;
|
|
3075
2863
|
session = addProblem(session, {
|
|
3076
2864
|
code,
|
|
3077
2865
|
message: text3,
|
|
3078
|
-
...skipped === void 0 ? {} : { skipped }
|
|
3079
|
-
...problem_seq === void 0 ? {} : { problem_seq }
|
|
2866
|
+
...skipped === void 0 ? {} : { skipped }
|
|
3080
2867
|
});
|
|
3081
|
-
} else {
|
|
2868
|
+
} else if (message.run_id === null) {
|
|
3082
2869
|
notices.push(message.message);
|
|
2870
|
+
} else {
|
|
2871
|
+
continue;
|
|
3083
2872
|
}
|
|
2873
|
+
selectedBatch.push(message);
|
|
2874
|
+
selectedRaw.push(rawMessage);
|
|
3084
2875
|
break;
|
|
3085
2876
|
case "resync":
|
|
3086
2877
|
synced = false;
|
|
3087
2878
|
replaying = true;
|
|
2879
|
+
resyncing = true;
|
|
2880
|
+
selectedBatch.push(message);
|
|
2881
|
+
selectedRaw.push(rawMessage);
|
|
2882
|
+
break;
|
|
2883
|
+
default:
|
|
2884
|
+
if (session !== null && "run_id" in message && message.run_id !== session.id) {
|
|
2885
|
+
continue;
|
|
2886
|
+
}
|
|
2887
|
+
selectedBatch.push(message);
|
|
2888
|
+
selectedRaw.push(rawMessage);
|
|
3088
2889
|
break;
|
|
3089
2890
|
}
|
|
3090
2891
|
}
|
|
3091
2892
|
flush();
|
|
3092
2893
|
const stale = (session?.staleEvents ?? 0) - (before?.id === session?.id ? before?.staleEvents ?? 0 : 0);
|
|
3093
|
-
if (!currentOrigin()
|
|
2894
|
+
if (!currentOrigin()) return;
|
|
2895
|
+
const beforeInstance = this.instanceId;
|
|
3094
2896
|
this.instanceId = instance;
|
|
2897
|
+
this.lastStreamSeq = streamSeq;
|
|
2898
|
+
this.resyncing = resyncing;
|
|
3095
2899
|
commitOrigin(instance);
|
|
3096
|
-
this.
|
|
3097
|
-
this.stopTarget = session && instance ? { session: session.id, instance } : null;
|
|
2900
|
+
this.stopTarget = session && instance ? { run_id: session.id, instance } : null;
|
|
3098
2901
|
const sessionId = session?.id ?? null;
|
|
3099
|
-
const
|
|
2902
|
+
const sameStream = () => currentOrigin() && this.instanceId === instance && (this.current.get()?.id ?? null) === sessionId;
|
|
3100
2903
|
const notifySession = this.current.setDeferred(session);
|
|
3101
2904
|
const notifyAllowed = this.allowedValue.setDeferred(allowedNow);
|
|
3102
2905
|
const notifyRuntime = this.runtimeValue.setDeferred(runtimeNow);
|
|
3103
2906
|
const notifySynced = this.synced.setDeferred(synced);
|
|
3104
|
-
if (instance && instance !==
|
|
2907
|
+
if (instance !== null && instance !== beforeInstance) {
|
|
2908
|
+
this.onInstance?.(instance);
|
|
2909
|
+
if (!sameStream()) return;
|
|
2910
|
+
}
|
|
3105
2911
|
notifySession();
|
|
3106
2912
|
notifyAllowed();
|
|
3107
2913
|
notifyRuntime();
|
|
3108
2914
|
notifySynced();
|
|
3109
|
-
if (!
|
|
2915
|
+
if (!sameStream()) return;
|
|
3110
2916
|
for (const notice of notices) {
|
|
3111
2917
|
this.notify(notice);
|
|
3112
|
-
if (!
|
|
2918
|
+
if (!sameStream()) return;
|
|
3113
2919
|
}
|
|
3114
2920
|
if (applied) this.receivedAt.set(Date.now());
|
|
3115
|
-
if (!
|
|
2921
|
+
if (!sameStream()) return;
|
|
3116
2922
|
if (stale > 0) this.notify(STALE_EVENTS_NOTICE, stale);
|
|
3117
|
-
if (!
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
2923
|
+
if (!sameStream()) return;
|
|
2924
|
+
if (selectedRaw.length > 0) {
|
|
2925
|
+
callEach(this.rawListeners, [selectedRaw, sameStream], this.onError, sameStream);
|
|
2926
|
+
}
|
|
2927
|
+
if (!sameStream()) return;
|
|
2928
|
+
if (selectedBatch.length > 0) {
|
|
2929
|
+
callEach(this.messageListeners, [selectedBatch], this.onError, sameStream);
|
|
2930
|
+
}
|
|
3121
2931
|
}
|
|
3122
2932
|
notify(message, count = 1) {
|
|
3123
2933
|
this.noticeList.update((list) => {
|
|
@@ -3188,7 +2998,7 @@ var TimeControl = class {
|
|
|
3188
2998
|
send(command) {
|
|
3189
2999
|
const session = this.session.get();
|
|
3190
3000
|
const target = this.currentTarget();
|
|
3191
|
-
if (!session || target?.
|
|
3001
|
+
if (!session || target?.run_id !== session.id) return { sent: false, reason: "no-session" };
|
|
3192
3002
|
if (this.state.get().sending !== null) return { sent: false, reason: "waiting" };
|
|
3193
3003
|
this.failureValue.set(null);
|
|
3194
3004
|
const pending = {
|
|
@@ -3214,7 +3024,7 @@ var TimeControl = class {
|
|
|
3214
3024
|
kind: "server",
|
|
3215
3025
|
message: errorMessage(outcome.error),
|
|
3216
3026
|
command: pending.command,
|
|
3217
|
-
session: target.
|
|
3027
|
+
session: target.run_id
|
|
3218
3028
|
}
|
|
3219
3029
|
});
|
|
3220
3030
|
}
|
|
@@ -3237,7 +3047,7 @@ var TimeControl = class {
|
|
|
3237
3047
|
kind: "no-answer",
|
|
3238
3048
|
message: `the launcher did not answer the command (${pending.command}) within ${this.answerTimeoutMs / 1e3} s; it may not read its input. You can send it again.`,
|
|
3239
3049
|
command: pending.command,
|
|
3240
|
-
session: pending.target.
|
|
3050
|
+
session: pending.target.run_id
|
|
3241
3051
|
}
|
|
3242
3052
|
});
|
|
3243
3053
|
}
|
|
@@ -3367,7 +3177,6 @@ var keyOf = (peer, name) => `${peer}\0${name}`;
|
|
|
3367
3177
|
var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3368
3178
|
var text = (value, fallback = "") => typeof value === "string" ? value : fallback;
|
|
3369
3179
|
var numberOrNull = (value) => typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
3370
|
-
var positionOrNull = (value) => Number.isSafeInteger(value) && value >= 0 ? value : null;
|
|
3371
3180
|
function readVariables2(value, session) {
|
|
3372
3181
|
const u = new Unreadable("variables");
|
|
3373
3182
|
const summary = lenient(
|
|
@@ -3515,6 +3324,7 @@ function lost(seq, summary) {
|
|
|
3515
3324
|
summary.openOmitted ? `the server does not keep track of the write (operation ${seq}) any more (it holds too many open operations): its result may not come; look at the values before writing again` : `the result of the write (operation ${seq}) was lost while the connection was down (it was settled meanwhile, and the server does not list it any more): look at the values before writing again`
|
|
3516
3325
|
);
|
|
3517
3326
|
}
|
|
3327
|
+
var runIdOf = (value) => typeof value === "string" && value.length > 0 ? value : null;
|
|
3518
3328
|
var VariablesFeed = class {
|
|
3519
3329
|
constructor(link, http, onError = rethrowLater, limits = () => ({})) {
|
|
3520
3330
|
this.link = link;
|
|
@@ -3527,18 +3337,13 @@ var VariablesFeed = class {
|
|
|
3527
3337
|
this.state = this.stateValue.readonly();
|
|
3528
3338
|
this.operations = this.operationsValue.readonly();
|
|
3529
3339
|
this.watchProblem = this.problemValue.readonly();
|
|
3530
|
-
link.onBatch(
|
|
3531
|
-
(batch, current, snapshotCurrent) => this.receive(batch, current, snapshotCurrent)
|
|
3532
|
-
);
|
|
3340
|
+
link.onBatch((batch, current) => this.receive(batch, current));
|
|
3533
3341
|
}
|
|
3534
3342
|
link;
|
|
3535
3343
|
http;
|
|
3536
3344
|
onError;
|
|
3537
3345
|
limits;
|
|
3538
3346
|
instanceId = null;
|
|
3539
|
-
snapshotVersionValue = 0;
|
|
3540
|
-
snapshotIdentity = null;
|
|
3541
|
-
serverRevision = null;
|
|
3542
3347
|
stateValue;
|
|
3543
3348
|
operationsValue;
|
|
3544
3349
|
handles = /* @__PURE__ */ new Set();
|
|
@@ -3587,9 +3392,13 @@ var VariablesFeed = class {
|
|
|
3587
3392
|
}
|
|
3588
3393
|
}
|
|
3589
3394
|
// --- Notifications --------------------------------------------------------------------------
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
const
|
|
3395
|
+
onInstance(instance) {
|
|
3396
|
+
if (this.instanceId === instance) return;
|
|
3397
|
+
const hadInstance = this.instanceId !== null;
|
|
3398
|
+
this.instanceId = instance;
|
|
3399
|
+
if (hadInstance) this.enter(null, true);
|
|
3400
|
+
}
|
|
3401
|
+
receive(batch, current = () => true) {
|
|
3593
3402
|
const touched = /* @__PURE__ */ new Set();
|
|
3594
3403
|
let touchedAll = false;
|
|
3595
3404
|
let operations = null;
|
|
@@ -3602,26 +3411,53 @@ var VariablesFeed = class {
|
|
|
3602
3411
|
for (const message of batch) {
|
|
3603
3412
|
if (!current()) return;
|
|
3604
3413
|
if (!isObject(message)) continue;
|
|
3605
|
-
const messageSession = message["session"];
|
|
3606
|
-
const existingSession = this.stateValue.get().session;
|
|
3607
|
-
if (typeof messageSession === "number" && existingSession !== null && messageSession < existingSession)
|
|
3608
|
-
continue;
|
|
3609
3414
|
switch (message["type"]) {
|
|
3610
3415
|
case "hello": {
|
|
3611
3416
|
flush();
|
|
3612
3417
|
if (!current()) return;
|
|
3613
3418
|
const summary = message["session"];
|
|
3614
|
-
|
|
3419
|
+
const nextInstance = runIdOf(message["instance"]);
|
|
3420
|
+
const instanceChanged = this.instanceId !== null && nextInstance !== null && this.instanceId !== nextInstance;
|
|
3421
|
+
if (nextInstance !== null) this.instanceId = nextInstance;
|
|
3422
|
+
if (instanceChanged) this.enter(null, true);
|
|
3615
3423
|
if (!current()) return;
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
const
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3424
|
+
const id = isObject(summary) ? runIdOf(summary["id"]) : null;
|
|
3425
|
+
if (isObject(summary) && id !== null) {
|
|
3426
|
+
const instance = this.instanceId;
|
|
3427
|
+
if (id !== this.stateValue.get().session) {
|
|
3428
|
+
this.enter(id);
|
|
3429
|
+
if (!current()) return;
|
|
3430
|
+
}
|
|
3431
|
+
const sameIdentity = () => current() && this.instanceId === instance && this.stateValue.get().session === id;
|
|
3432
|
+
const variables = summary["variables"];
|
|
3433
|
+
if (sameIdentity() && variables !== void 0) {
|
|
3434
|
+
let notifyOperations = () => void 0;
|
|
3435
|
+
const listed = [];
|
|
3436
|
+
if (isObject(variables) && Array.isArray(variables["operations"])) {
|
|
3437
|
+
let currentOps = this.operationsValue.get();
|
|
3438
|
+
for (const entry of variables["operations"]) {
|
|
3439
|
+
const operation = readOperation(entry, id);
|
|
3440
|
+
if (operation) {
|
|
3441
|
+
listed.push(operation);
|
|
3442
|
+
currentOps = this.withOperation(currentOps, operation);
|
|
3443
|
+
}
|
|
3444
|
+
}
|
|
3445
|
+
notifyOperations = this.prepareOperations(currentOps, listed, sameIdentity);
|
|
3446
|
+
}
|
|
3447
|
+
const next = readVariables2(variables, id);
|
|
3448
|
+
this.stateValue.set(next);
|
|
3449
|
+
notifyOperations();
|
|
3450
|
+
if (sameIdentity() && this.stateValue.get() === next && isObject(variables) && Array.isArray(variables["operations"])) {
|
|
3451
|
+
const fromSeq = variables["operations_from_seq"];
|
|
3452
|
+
const openOmitted = variables["operations_open_omitted"];
|
|
3453
|
+
this.forgetLost(id, {
|
|
3454
|
+
operations: listed,
|
|
3455
|
+
fromSeq: Number.isSafeInteger(fromSeq) ? fromSeq : null,
|
|
3456
|
+
openOmitted: typeof openOmitted === "number" && openOmitted > 0
|
|
3457
|
+
});
|
|
3458
|
+
}
|
|
3459
|
+
}
|
|
3623
3460
|
} else {
|
|
3624
|
-
if (this.stateValue.get().session !== null) break;
|
|
3625
3461
|
this.enter(null);
|
|
3626
3462
|
if (!current()) return;
|
|
3627
3463
|
this.stateValue.set({ ...NO_VARIABLES, status: "off" });
|
|
@@ -3631,14 +3467,10 @@ var VariablesFeed = class {
|
|
|
3631
3467
|
}
|
|
3632
3468
|
case "session": {
|
|
3633
3469
|
const summary = message["session"];
|
|
3634
|
-
const id = isObject(summary) ? summary["id"] : null;
|
|
3635
|
-
|
|
3636
|
-
if (typeof id === "number" && existing !== null && id < existing) break;
|
|
3637
|
-
if (Number.isSafeInteger(id) && id !== this.stateValue.get().session) {
|
|
3470
|
+
const id = isObject(summary) ? runIdOf(summary["id"]) : null;
|
|
3471
|
+
if (id !== null && id !== this.stateValue.get().session) {
|
|
3638
3472
|
flush();
|
|
3639
3473
|
if (!current()) return;
|
|
3640
|
-
const afterFlush = this.stateValue.get().session;
|
|
3641
|
-
if (afterFlush !== null && id < afterFlush) break;
|
|
3642
3474
|
this.enter(id);
|
|
3643
3475
|
if (!current()) return;
|
|
3644
3476
|
if (this.stateValue.get().session !== id) break;
|
|
@@ -3647,42 +3479,31 @@ var VariablesFeed = class {
|
|
|
3647
3479
|
break;
|
|
3648
3480
|
}
|
|
3649
3481
|
case "variables": {
|
|
3650
|
-
const id = message["
|
|
3651
|
-
if (
|
|
3482
|
+
const id = runIdOf(message["run_id"]);
|
|
3483
|
+
if (id === null) break;
|
|
3652
3484
|
const details = message["variables"];
|
|
3653
|
-
const rev = isObject(details) ? positionOrNull(details["rev"]) : null;
|
|
3654
3485
|
const existing = this.stateValue.get().session;
|
|
3655
|
-
if (existing !== null && id < existing) break;
|
|
3656
3486
|
if (id !== existing) {
|
|
3657
3487
|
flush();
|
|
3658
3488
|
if (!current()) return;
|
|
3659
|
-
|
|
3660
|
-
if (afterFlush !== null && id < afterFlush) break;
|
|
3661
|
-
if (afterFlush !== id) {
|
|
3489
|
+
if (this.stateValue.get().session !== id) {
|
|
3662
3490
|
this.enter(id);
|
|
3663
3491
|
if (!current()) return;
|
|
3664
3492
|
if (this.stateValue.get().session !== id) break;
|
|
3665
3493
|
touchedAll = true;
|
|
3666
3494
|
}
|
|
3667
3495
|
}
|
|
3668
|
-
|
|
3669
|
-
const version2 = this.applySnapshot(
|
|
3670
|
-
readVariables2(details, id),
|
|
3671
|
-
id,
|
|
3672
|
-
rev
|
|
3673
|
-
);
|
|
3674
|
-
if (this.snapshotVersionValue === version2) snapshotVersion = version2;
|
|
3675
|
-
}
|
|
3496
|
+
this.stateValue.set(readVariables2(details, id));
|
|
3676
3497
|
break;
|
|
3677
3498
|
}
|
|
3678
3499
|
case "values": {
|
|
3679
|
-
if (message["
|
|
3500
|
+
if (runIdOf(message["run_id"]) !== this.stateValue.get().session) break;
|
|
3680
3501
|
this.takeValues(message, touched);
|
|
3681
3502
|
break;
|
|
3682
3503
|
}
|
|
3683
3504
|
case "operation": {
|
|
3684
|
-
const id = message["
|
|
3685
|
-
if (id !== this.stateValue.get().session) break;
|
|
3505
|
+
const id = runIdOf(message["run_id"]);
|
|
3506
|
+
if (id === null || id !== this.stateValue.get().session) break;
|
|
3686
3507
|
const operation = readOperation(message, id);
|
|
3687
3508
|
if (operation) {
|
|
3688
3509
|
operations = this.withOperation(operations ?? this.operationsValue.get(), operation);
|
|
@@ -3692,12 +3513,8 @@ var VariablesFeed = class {
|
|
|
3692
3513
|
}
|
|
3693
3514
|
case "availability": {
|
|
3694
3515
|
const id = this.stateValue.get().session;
|
|
3695
|
-
if (message["
|
|
3696
|
-
const rev = positionOrNull(message["rev"]);
|
|
3697
|
-
if (!snapshotCurrent(id, rev)) break;
|
|
3698
|
-
const version2 = this.markSnapshot(id, rev);
|
|
3516
|
+
if (runIdOf(message["run_id"]) !== id || id === null) break;
|
|
3699
3517
|
if (this.takeAvailability(message["peers"])) touchedAll = true;
|
|
3700
|
-
if (this.snapshotVersionValue === version2) snapshotVersion = version2;
|
|
3701
3518
|
break;
|
|
3702
3519
|
}
|
|
3703
3520
|
case "error": {
|
|
@@ -3732,94 +3549,8 @@ var VariablesFeed = class {
|
|
|
3732
3549
|
this.stateValue.set({ ...state, availability: next });
|
|
3733
3550
|
return true;
|
|
3734
3551
|
}
|
|
3735
|
-
snapshotVersion() {
|
|
3736
|
-
return this.snapshotVersionValue;
|
|
3737
|
-
}
|
|
3738
|
-
/** Compare server capture order when available; legacy peers use the local best-effort watermark. */
|
|
3739
|
-
isSnapshotCurrent(version2, instance, session, rev) {
|
|
3740
|
-
if (session === null) return true;
|
|
3741
|
-
const source = this.serverRevision;
|
|
3742
|
-
if (source && source.instance === instance && source.session === session) {
|
|
3743
|
-
return rev !== null && rev >= source.rev;
|
|
3744
|
-
}
|
|
3745
|
-
if (rev !== null) return true;
|
|
3746
|
-
const identity = this.snapshotIdentity;
|
|
3747
|
-
return !identity || identity.instance !== instance || identity.session !== session || this.snapshotVersionValue <= version2;
|
|
3748
|
-
}
|
|
3749
|
-
markSnapshot(session, rev) {
|
|
3750
|
-
const version2 = ++this.snapshotVersionValue;
|
|
3751
|
-
this.snapshotIdentity = { instance: this.instanceId, session };
|
|
3752
|
-
if (rev !== null) this.serverRevision = { instance: this.instanceId, session, rev };
|
|
3753
|
-
return version2;
|
|
3754
|
-
}
|
|
3755
|
-
applySnapshot(state, session, rev) {
|
|
3756
|
-
const version2 = this.markSnapshot(session, rev);
|
|
3757
|
-
this.stateValue.set(state);
|
|
3758
|
-
return version2;
|
|
3759
|
-
}
|
|
3760
|
-
/** A reused numeric session on another server is a different run. */
|
|
3761
|
-
adoptInstance(value) {
|
|
3762
|
-
if (typeof value !== "string" || !value) return;
|
|
3763
|
-
const changed = this.instanceId !== null && this.instanceId !== value;
|
|
3764
|
-
this.instanceId = value;
|
|
3765
|
-
if (changed) this.enter(null, true);
|
|
3766
|
-
}
|
|
3767
|
-
/** Applies a summary: an older snapshot can still carry a terminal write result. */
|
|
3768
|
-
adoptSummary(summary, current = () => true, snapshotCurrent = current) {
|
|
3769
|
-
if (!isObject(summary) || !Number.isSafeInteger(summary["id"]) || !current()) return null;
|
|
3770
|
-
const id = summary["id"];
|
|
3771
|
-
const instance = this.instanceId;
|
|
3772
|
-
const existing = this.stateValue.get().session;
|
|
3773
|
-
if (existing !== null && id < existing) return null;
|
|
3774
|
-
const variables = summary["variables"];
|
|
3775
|
-
let applyState = snapshotCurrent();
|
|
3776
|
-
if (id !== existing) {
|
|
3777
|
-
const initial = this.enter(id);
|
|
3778
|
-
if (!current()) return null;
|
|
3779
|
-
if (this.stateValue.get() !== initial) applyState = applyState && snapshotCurrent();
|
|
3780
|
-
}
|
|
3781
|
-
const sameIdentity = () => current() && this.instanceId === instance && this.stateValue.get().session === id;
|
|
3782
|
-
if (!sameIdentity() || variables === void 0) return null;
|
|
3783
|
-
applyState = applyState && snapshotCurrent();
|
|
3784
|
-
let notifyOperations = () => void 0;
|
|
3785
|
-
const listed = [];
|
|
3786
|
-
if (isObject(variables) && Array.isArray(variables["operations"])) {
|
|
3787
|
-
let operations = this.operationsValue.get();
|
|
3788
|
-
for (const entry of variables["operations"]) {
|
|
3789
|
-
const operation = readOperation(entry, id);
|
|
3790
|
-
if (operation && (applyState || operation.done)) {
|
|
3791
|
-
listed.push(operation);
|
|
3792
|
-
operations = this.withOperation(operations, operation);
|
|
3793
|
-
}
|
|
3794
|
-
}
|
|
3795
|
-
notifyOperations = this.prepareOperations(operations, listed, sameIdentity);
|
|
3796
|
-
}
|
|
3797
|
-
let next = null;
|
|
3798
|
-
let appliedVersion = null;
|
|
3799
|
-
if (applyState && snapshotCurrent() && sameIdentity()) {
|
|
3800
|
-
next = readVariables2(variables, id);
|
|
3801
|
-
appliedVersion = this.applySnapshot(
|
|
3802
|
-
next,
|
|
3803
|
-
id,
|
|
3804
|
-
isObject(variables) ? positionOrNull(variables["rev"]) : null
|
|
3805
|
-
);
|
|
3806
|
-
}
|
|
3807
|
-
notifyOperations();
|
|
3808
|
-
if (!sameIdentity() || appliedVersion === null || this.snapshotVersionValue !== appliedVersion || !next || this.stateValue.get() !== next)
|
|
3809
|
-
return appliedVersion;
|
|
3810
|
-
if (isObject(variables) && Array.isArray(variables["operations"])) {
|
|
3811
|
-
const fromSeq = variables["operations_from_seq"];
|
|
3812
|
-
const openOmitted = variables["operations_open_omitted"];
|
|
3813
|
-
this.forgetLost(id, {
|
|
3814
|
-
operations: listed,
|
|
3815
|
-
fromSeq: Number.isSafeInteger(fromSeq) ? fromSeq : null,
|
|
3816
|
-
openOmitted: typeof openOmitted === "number" && openOmitted > 0
|
|
3817
|
-
});
|
|
3818
|
-
}
|
|
3819
|
-
return appliedVersion;
|
|
3820
|
-
}
|
|
3821
3552
|
/**
|
|
3822
|
-
* With the summary after a reconnect
|
|
3553
|
+
* With the summary after a reconnect, settles as "no answer came" (lost) the writes waiting for
|
|
3823
3554
|
* a result that will no longer arrive. For writes whose number is not known yet (before the HTTP answer), the summary
|
|
3824
3555
|
* is kept and checked the same way once the number is known.
|
|
3825
3556
|
*/
|
|
@@ -3990,7 +3721,7 @@ var VariablesFeed = class {
|
|
|
3990
3721
|
new WriteError("refused", "there is no run to write to", "not-running")
|
|
3991
3722
|
);
|
|
3992
3723
|
}
|
|
3993
|
-
const body = { session, writes };
|
|
3724
|
+
const body = { run_id: session, writes };
|
|
3994
3725
|
if (options.instance !== void 0) body["instance"] = options.instance;
|
|
3995
3726
|
if (options.atMs !== void 0) body["at_ms"] = options.atMs;
|
|
3996
3727
|
if (options.late !== void 0) body["late"] = options.late;
|
|
@@ -4016,8 +3747,8 @@ var VariablesFeed = class {
|
|
|
4016
3747
|
}
|
|
4017
3748
|
const answer = outcome.body;
|
|
4018
3749
|
const seq = isObject(answer) ? answer["operation"] : null;
|
|
4019
|
-
const answered = isObject(answer) ? answer["
|
|
4020
|
-
if (!Number.isSafeInteger(seq) ||
|
|
3750
|
+
const answered = isObject(answer) ? runIdOf(answer["run_id"]) : null;
|
|
3751
|
+
if (!Number.isSafeInteger(seq) || answered === null) {
|
|
4021
3752
|
this.settle(
|
|
4022
3753
|
pending,
|
|
4023
3754
|
new WriteError(
|
|
@@ -4596,7 +4327,8 @@ function clientErrorSink(client) {
|
|
|
4596
4327
|
return clientErrorSinks.get(client);
|
|
4597
4328
|
}
|
|
4598
4329
|
function buildClient(options) {
|
|
4599
|
-
const
|
|
4330
|
+
const rawToken = options.token;
|
|
4331
|
+
const token = typeof rawToken === "function" ? rawToken : () => rawToken ?? null;
|
|
4600
4332
|
const onError = options.onError ?? reportToConsole;
|
|
4601
4333
|
const origin = options.origin ?? defaultOrigin(options.baseUrl);
|
|
4602
4334
|
const http = options.http ?? fetchTransport({ baseUrl: options.baseUrl, token, origin });
|
|
@@ -4612,14 +4344,13 @@ function buildClient(options) {
|
|
|
4612
4344
|
{
|
|
4613
4345
|
type: "auth",
|
|
4614
4346
|
token: token() ?? "",
|
|
4615
|
-
...feed?.resumeFields()
|
|
4616
|
-
session_without_check: true
|
|
4347
|
+
...feed?.resumeFields()
|
|
4617
4348
|
}
|
|
4618
4349
|
],
|
|
4619
4350
|
afterGreeting: () => variablesFeed?.resume() ?? [],
|
|
4620
4351
|
onError
|
|
4621
4352
|
});
|
|
4622
|
-
feed = new SessionFeed(connection, onError);
|
|
4353
|
+
feed = new SessionFeed(connection, onError, (instance) => variablesFeed?.onInstance(instance));
|
|
4623
4354
|
const session = feed;
|
|
4624
4355
|
variablesFeed = new VariablesFeed(
|
|
4625
4356
|
{
|
|
@@ -4631,8 +4362,6 @@ function buildClient(options) {
|
|
|
4631
4362
|
() => limits.get()
|
|
4632
4363
|
);
|
|
4633
4364
|
const variables = variablesFeed;
|
|
4634
|
-
session.onSnapshotVersion(() => variables.snapshotVersion());
|
|
4635
|
-
session.onInstance((instance) => variables.adoptInstance(instance));
|
|
4636
4365
|
const run = new RunControl(session, http, onError, () => longRequestMs(limits.get()));
|
|
4637
4366
|
const time = new TimeControl(
|
|
4638
4367
|
session.session,
|
|
@@ -4717,7 +4446,7 @@ function buildClient(options) {
|
|
|
4717
4446
|
app: app.readonly(),
|
|
4718
4447
|
limits: limits.readonly(),
|
|
4719
4448
|
connect: () => {
|
|
4720
|
-
if (
|
|
4449
|
+
if (!session.stopped) connection.connect();
|
|
4721
4450
|
},
|
|
4722
4451
|
close: () => {
|
|
4723
4452
|
connection.close();
|
|
@@ -4774,50 +4503,8 @@ function buildClient(options) {
|
|
|
4774
4503
|
body,
|
|
4775
4504
|
timeoutMs: longRequestMs(limits.get())
|
|
4776
4505
|
},
|
|
4777
|
-
readPrepareResponse
|
|
4778
|
-
|
|
4779
|
-
),
|
|
4780
|
-
fetchSession: () => {
|
|
4781
|
-
const resyncFrom = session.currentInstance();
|
|
4782
|
-
const snapshotVersion = variables.snapshotVersion();
|
|
4783
|
-
return new Promise(
|
|
4784
|
-
(resolve, reject) => http({ method: "GET", path: "api/session" }, (outcome) => {
|
|
4785
|
-
if (!outcome.ok) {
|
|
4786
|
-
reject(outcome.error);
|
|
4787
|
-
return;
|
|
4788
|
-
}
|
|
4789
|
-
try {
|
|
4790
|
-
const summary = readSessionResponse(outcome.body);
|
|
4791
|
-
const instance = readSessionInstance(outcome.body);
|
|
4792
|
-
const runtime = readSessionRuntime(outcome.body);
|
|
4793
|
-
const adoption = session.adopt(summary, instance, resyncFrom);
|
|
4794
|
-
if (adoption !== null) {
|
|
4795
|
-
if (runtime !== void 0) session.adoptRuntime(runtime);
|
|
4796
|
-
const rawSession = outcome.body?.session;
|
|
4797
|
-
const rev = rawSession?.variables?.rev;
|
|
4798
|
-
const current = () => variables.isSnapshotCurrent(
|
|
4799
|
-
snapshotVersion,
|
|
4800
|
-
adoption.instance,
|
|
4801
|
-
adoption.session,
|
|
4802
|
-
Number.isSafeInteger(rev) && rev >= 0 ? rev : null
|
|
4803
|
-
);
|
|
4804
|
-
if (session.sameRun(adoption)) session.adoptAllowed(readSessionAllowed(outcome.body));
|
|
4805
|
-
const sameRun = () => session.sameRun(adoption);
|
|
4806
|
-
if (sameRun()) variables.adoptInstance(instance);
|
|
4807
|
-
if (sameRun())
|
|
4808
|
-
variables.adoptSummary(
|
|
4809
|
-
outcome.body?.session,
|
|
4810
|
-
sameRun,
|
|
4811
|
-
current
|
|
4812
|
-
);
|
|
4813
|
-
}
|
|
4814
|
-
resolve(summary);
|
|
4815
|
-
} catch (error) {
|
|
4816
|
-
reject(error);
|
|
4817
|
-
}
|
|
4818
|
-
})
|
|
4819
|
-
);
|
|
4820
|
-
}
|
|
4506
|
+
readPrepareResponse
|
|
4507
|
+
)
|
|
4821
4508
|
};
|
|
4822
4509
|
clientErrorSinks.set(client, onError);
|
|
4823
4510
|
return { client, http, onError, runControl: run };
|
|
@@ -4889,7 +4576,7 @@ function linkOf(s) {
|
|
|
4889
4576
|
}
|
|
4890
4577
|
var NOT_PACED = "not-paced";
|
|
4891
4578
|
function startOnItsWay(s) {
|
|
4892
|
-
return s.busy.has("start") || s.allowed?.start.reason === "starting";
|
|
4579
|
+
return s.busy.has("start") || s.awaitingRunSession === true || s.allowed?.start.reason === "starting";
|
|
4893
4580
|
}
|
|
4894
4581
|
function runOf(s) {
|
|
4895
4582
|
const session = s.session;
|
|
@@ -4898,8 +4585,9 @@ function runOf(s) {
|
|
|
4898
4585
|
const outcome = runOutcome(session);
|
|
4899
4586
|
if (outcome === "crashed") return starting ? "starting" : "crashed";
|
|
4900
4587
|
if (outcome === "ended" || outcome === "finishing") return starting ? "starting" : "ended";
|
|
4901
|
-
if (outcome === "stopping" || outcome === "forcing") return "stopping";
|
|
4902
4588
|
const state = session.launcherState;
|
|
4589
|
+
if (outcome === "stopping" || outcome === "forcing" || s.stopConfirmed || (state?.stop?.requests ?? 0) > 0)
|
|
4590
|
+
return "stopping";
|
|
4903
4591
|
const phase = state?.phase || session.phase;
|
|
4904
4592
|
const paused = state?.paused ?? null;
|
|
4905
4593
|
switch (phase) {
|
|
@@ -5032,11 +4720,20 @@ function composeControls(s, run) {
|
|
|
5032
4720
|
const session = s.session;
|
|
5033
4721
|
const live = isRunActive(session) && run !== "ended" && run !== "crashed";
|
|
5034
4722
|
const state = session?.launcherState ?? null;
|
|
5035
|
-
const stopsAsked =
|
|
4723
|
+
const stopsAsked = Math.max(
|
|
4724
|
+
session?.stopRequests ?? 0,
|
|
4725
|
+
state?.stop?.requests ?? 0,
|
|
4726
|
+
s.stopConfirmed ? 1 : 0
|
|
4727
|
+
);
|
|
5036
4728
|
let start;
|
|
5037
4729
|
if (link === "rejected" || link === "incompatible") start = control(false, down);
|
|
5038
4730
|
else if (s.busy.has("start")) start = control(false, busyReason("start"));
|
|
5039
4731
|
else if (down) start = control(false, down);
|
|
4732
|
+
else if (s.awaitingRunSession)
|
|
4733
|
+
start = control(
|
|
4734
|
+
false,
|
|
4735
|
+
reason("already-running", "a run is going: stop it before you start another")
|
|
4736
|
+
);
|
|
5040
4737
|
else if (s.allowed) start = fromServer(s.allowed.start, "the server does not start a run now");
|
|
5041
4738
|
else
|
|
5042
4739
|
start = live ? control(
|
|
@@ -5044,7 +4741,8 @@ function composeControls(s, run) {
|
|
|
5044
4741
|
reason("already-running", "a run is going: stop it before you start another")
|
|
5045
4742
|
) : control(true);
|
|
5046
4743
|
const serverStop = s.allowed?.stop;
|
|
5047
|
-
const
|
|
4744
|
+
const serverForce = s.allowed?.force;
|
|
4745
|
+
const stoppable = s.busy.has("start") || live || run === "starting" || serverStop?.ok === true || serverForce?.ok === true;
|
|
5048
4746
|
let stop;
|
|
5049
4747
|
if (!s.busy.has("start") && s.allowed?.start.reason === "starting")
|
|
5050
4748
|
stop = control(false, reason("starting", "wait until the new run can be identified"));
|
|
@@ -5060,7 +4758,6 @@ function composeControls(s, run) {
|
|
|
5060
4758
|
reason("already-stopping", "a stop has been asked for: wait, or force the stop")
|
|
5061
4759
|
);
|
|
5062
4760
|
else stop = control(true);
|
|
5063
|
-
const serverForce = s.allowed?.force;
|
|
5064
4761
|
let force;
|
|
5065
4762
|
if (s.busy.has("start") || s.allowed?.start.reason === "starting")
|
|
5066
4763
|
force = control(false, reason("starting", "wait until the new run can be identified"));
|
|
@@ -5194,16 +4891,25 @@ var FrontActions = class {
|
|
|
5194
4891
|
this.closing.catch(() => void 0);
|
|
5195
4892
|
this.busyValue = new Writable(/* @__PURE__ */ new Set(), Object.is, src.onError);
|
|
5196
4893
|
this.failureValue = new Writable(null, Object.is, src.onError);
|
|
4894
|
+
this.startedRunIdValue = new Writable(null, Object.is, src.onError);
|
|
4895
|
+
this.stopConfirmedForValue = new Writable(null, Object.is, src.onError);
|
|
5197
4896
|
this.busy = this.busyValue.readonly();
|
|
5198
4897
|
this.failure = this.failureValue.readonly();
|
|
4898
|
+
this.startedRunId = this.startedRunIdValue.readonly();
|
|
4899
|
+
this.stopConfirmedFor = this.stopConfirmedForValue.readonly();
|
|
5199
4900
|
this.stops.push(
|
|
5200
4901
|
src.low.session.onMessages((batch) => this.onMessages(batch)),
|
|
5201
|
-
src.low.session.session.subscribe(() =>
|
|
4902
|
+
src.low.session.session.subscribe(() => {
|
|
4903
|
+
this.startedRunIdValue.set(null);
|
|
4904
|
+
this.evaluate();
|
|
4905
|
+
})
|
|
5202
4906
|
);
|
|
5203
4907
|
}
|
|
5204
4908
|
src;
|
|
5205
4909
|
busyValue;
|
|
5206
4910
|
failureValue;
|
|
4911
|
+
startedRunIdValue;
|
|
4912
|
+
stopConfirmedForValue;
|
|
5207
4913
|
waiting = /* @__PURE__ */ new Map();
|
|
5208
4914
|
inFlight = /* @__PURE__ */ new Map();
|
|
5209
4915
|
/** The checks not answered yet, in the order they are sent: the first is on its way, the others wait. */
|
|
@@ -5217,20 +4923,37 @@ var FrontActions = class {
|
|
|
5217
4923
|
disposed = false;
|
|
5218
4924
|
busy;
|
|
5219
4925
|
failure;
|
|
4926
|
+
startedRunId;
|
|
4927
|
+
stopConfirmedFor;
|
|
5220
4928
|
// --- run ---------------------------------------------------------------------------------------
|
|
5221
4929
|
start(intent = {}, options = {}) {
|
|
5222
4930
|
const request = this.requestOf(intent, options);
|
|
5223
4931
|
if (request instanceof ActionError) return this.fail(request);
|
|
5224
4932
|
const own = this.refusalOfStart();
|
|
5225
4933
|
if (own) return this.fail(own);
|
|
4934
|
+
this.stopConfirmedForValue.set(null);
|
|
5226
4935
|
const start = this.src.low.run.start(request);
|
|
5227
4936
|
return this.guarded(
|
|
5228
4937
|
"start",
|
|
5229
4938
|
() => start.then((started) => {
|
|
5230
|
-
if (started)
|
|
4939
|
+
if (started) {
|
|
4940
|
+
if (this.src.low.session.session.get()?.id !== started.run_id) {
|
|
4941
|
+
this.startedRunIdValue.set(started.run_id);
|
|
4942
|
+
}
|
|
4943
|
+
options.onStarted?.(started);
|
|
4944
|
+
}
|
|
5231
4945
|
})
|
|
5232
4946
|
);
|
|
5233
4947
|
}
|
|
4948
|
+
isAwaitingRunSession() {
|
|
4949
|
+
const id = this.startedRunIdValue.get();
|
|
4950
|
+
return id !== null && this.src.low.session.session.get()?.id !== id;
|
|
4951
|
+
}
|
|
4952
|
+
isStopConfirmed() {
|
|
4953
|
+
const id = this.stopConfirmedForValue.get();
|
|
4954
|
+
const session = this.src.low.session.session.get();
|
|
4955
|
+
return id !== null && session !== null && isRunActive(session) && session.id === id;
|
|
4956
|
+
}
|
|
5234
4957
|
/**
|
|
5235
4958
|
* Checks what `intent` would start (`api/check`). Its failure is the caller's: it is not kept for `status.problem`.
|
|
5236
4959
|
* 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
|
|
@@ -5373,15 +5096,17 @@ var FrontActions = class {
|
|
|
5373
5096
|
return this.once("stop", false);
|
|
5374
5097
|
}
|
|
5375
5098
|
forceStop(target) {
|
|
5376
|
-
const current = this.src.low.session.currentTarget();
|
|
5377
|
-
if (target && (current?.session !== target.session || current.instance !== target.instance))
|
|
5378
|
-
return this.fail(
|
|
5379
|
-
new ActionError("session-changed", "the confirmed run has changed", "refused")
|
|
5380
|
-
);
|
|
5381
5099
|
if (this.src.low.run.starting.get())
|
|
5382
5100
|
return this.fail(
|
|
5383
5101
|
new ActionError("starting", "wait until the new run can be identified", "refused")
|
|
5384
5102
|
);
|
|
5103
|
+
const current = this.src.low.session.currentTarget();
|
|
5104
|
+
const startedId = this.startedRunIdValue.get();
|
|
5105
|
+
const effectiveRunId = startedId ?? current?.run_id ?? null;
|
|
5106
|
+
if (target && (effectiveRunId !== target.run_id || current?.instance !== target.instance))
|
|
5107
|
+
return this.fail(
|
|
5108
|
+
new ActionError("session-changed", "the confirmed run has changed", "refused")
|
|
5109
|
+
);
|
|
5385
5110
|
return this.once("force_stop", true);
|
|
5386
5111
|
}
|
|
5387
5112
|
/** Pending stop only affects controls of the run it was sent for. */
|
|
@@ -5415,7 +5140,8 @@ var FrontActions = class {
|
|
|
5415
5140
|
if (this.busyValue.get().has(name)) this.busyValue.set(new Set(this.busyValue.get()));
|
|
5416
5141
|
else this.setBusy(name, true);
|
|
5417
5142
|
operation.then(
|
|
5418
|
-
() => {
|
|
5143
|
+
(ack) => {
|
|
5144
|
+
this.stopConfirmedForValue.set(ack.run_id);
|
|
5419
5145
|
if (this.inFlight.get(name) === entry) {
|
|
5420
5146
|
this.inFlight.delete(name);
|
|
5421
5147
|
this.setBusy(name, false);
|
|
@@ -5570,7 +5296,7 @@ var FrontActions = class {
|
|
|
5570
5296
|
if (event.event === "time") sim = event.sim_ms;
|
|
5571
5297
|
if (event.event !== "command") continue;
|
|
5572
5298
|
const mine = event.id === null ? void 0 : this.waiting.get(event.id);
|
|
5573
|
-
if (mine && mine.
|
|
5299
|
+
if (mine && mine.run_id === message.run_id) this.answered(mine, event, sim);
|
|
5574
5300
|
else if (event.accepted && event.command !== null && MOVES.has(event.command)) {
|
|
5575
5301
|
this.interruptMoving(
|
|
5576
5302
|
null,
|
|
@@ -5629,7 +5355,7 @@ var FrontActions = class {
|
|
|
5629
5355
|
const session = this.src.low.session.session.get();
|
|
5630
5356
|
const instance = this.src.low.session.currentInstance();
|
|
5631
5357
|
for (const w of [...this.waiting.values()]) {
|
|
5632
|
-
if (!session || !isRunActive(session) || session.id !== w.
|
|
5358
|
+
if (!session || !isRunActive(session) || session.id !== w.run_id || instance !== w.instance || session.result) {
|
|
5633
5359
|
this.settle(
|
|
5634
5360
|
w,
|
|
5635
5361
|
new ActionError(
|
|
@@ -5722,9 +5448,9 @@ function outsideRows(low, onError) {
|
|
|
5722
5448
|
for (const message of batch) {
|
|
5723
5449
|
if (message.type !== "event" || message.event.event !== "outside") continue;
|
|
5724
5450
|
const { network, to_outside, from_outside } = message.event;
|
|
5725
|
-
const networks = new Map(next?.
|
|
5451
|
+
const networks = new Map(next?.run_id === message.run_id ? next.networks : []);
|
|
5726
5452
|
networks.set(network, { to: to_outside, from: from_outside });
|
|
5727
|
-
next = {
|
|
5453
|
+
next = { run_id: message.run_id, networks };
|
|
5728
5454
|
}
|
|
5729
5455
|
if (next !== counts.get()) counts.set(next);
|
|
5730
5456
|
});
|
|
@@ -5734,7 +5460,7 @@ function outsideRows(low, onError) {
|
|
|
5734
5460
|
const session = low.session.session.get();
|
|
5735
5461
|
if (!session || !isRunActive(session)) return [];
|
|
5736
5462
|
const known = counts.get();
|
|
5737
|
-
const of = known?.
|
|
5463
|
+
const of = known?.run_id === session.id ? known.networks : /* @__PURE__ */ new Map();
|
|
5738
5464
|
return (session.launcherState?.outside ?? []).map((row) => {
|
|
5739
5465
|
const count = of.get(row.network);
|
|
5740
5466
|
return {
|
|
@@ -5946,7 +5672,9 @@ function makeFront(options, onClose) {
|
|
|
5946
5672
|
session: low.session.session.get(),
|
|
5947
5673
|
allowed: low.session.allowed.get(),
|
|
5948
5674
|
limits: low.limits.get(),
|
|
5949
|
-
busy: actions.busyForCurrent()
|
|
5675
|
+
busy: actions.busyForCurrent(),
|
|
5676
|
+
awaitingRunSession: actions.isAwaitingRunSession(),
|
|
5677
|
+
stopConfirmed: actions.isStopConfirmed()
|
|
5950
5678
|
});
|
|
5951
5679
|
const sources = [
|
|
5952
5680
|
low.connection.state,
|
|
@@ -5978,7 +5706,7 @@ function makeFront(options, onClose) {
|
|
|
5978
5706
|
stamp
|
|
5979
5707
|
});
|
|
5980
5708
|
const controlsValue = derived(
|
|
5981
|
-
[...sources, actions.busy],
|
|
5709
|
+
[...sources, actions.busy, actions.startedRunId, actions.stopConfirmedFor],
|
|
5982
5710
|
() => {
|
|
5983
5711
|
const s = snapshot();
|
|
5984
5712
|
return controlsOf(s, runOf(s));
|
|
@@ -5987,7 +5715,7 @@ function makeFront(options, onClose) {
|
|
|
5987
5715
|
onError
|
|
5988
5716
|
);
|
|
5989
5717
|
const writeControl = derived(
|
|
5990
|
-
[...sources, actions.busy],
|
|
5718
|
+
[...sources, actions.busy, actions.startedRunId, actions.stopConfirmedFor],
|
|
5991
5719
|
() => {
|
|
5992
5720
|
const s = snapshot();
|
|
5993
5721
|
return writeOf(s, runOf(s));
|
|
@@ -5996,7 +5724,7 @@ function makeFront(options, onClose) {
|
|
|
5996
5724
|
onError
|
|
5997
5725
|
);
|
|
5998
5726
|
const status = derived(
|
|
5999
|
-
[...sources, actions.busy, actions.failure],
|
|
5727
|
+
[...sources, actions.busy, actions.startedRunId, actions.stopConfirmedFor, actions.failure],
|
|
6000
5728
|
() => {
|
|
6001
5729
|
const s = snapshot();
|
|
6002
5730
|
const base = statusOf(s, initialFile());
|
|
@@ -6074,7 +5802,7 @@ function makeFront(options, onClose) {
|
|
|
6074
5802
|
...prepareOptions.enable !== void 0 ? { enable: prepareOptions.enable } : {},
|
|
6075
5803
|
...prepareOptions.manual !== void 0 ? { manual: prepareOptions.manual } : {}
|
|
6076
5804
|
}).then(
|
|
6077
|
-
(res) => res.runtime,
|
|
5805
|
+
(res) => res.runtime ?? low.session.runtime.get(),
|
|
6078
5806
|
(error) => {
|
|
6079
5807
|
throw actionError(error);
|
|
6080
5808
|
}
|
|
@@ -6185,15 +5913,14 @@ function createFront(options) {
|
|
|
6185
5913
|
}
|
|
6186
5914
|
function pageOptions() {
|
|
6187
5915
|
const page = globalThis.window;
|
|
6188
|
-
|
|
6189
|
-
if (!page || token === null) {
|
|
5916
|
+
if (!page) {
|
|
6190
5917
|
throw new ActionError(
|
|
6191
5918
|
"no-token",
|
|
6192
|
-
"connect() without options works in a page that the GUI server served
|
|
5919
|
+
"connect() without options works in a page that the GUI server served. In Node, pass { base_url } (and token unless the server runs with --no-auth)",
|
|
6193
5920
|
"refused"
|
|
6194
5921
|
);
|
|
6195
5922
|
}
|
|
6196
|
-
return { base_url: new URL("/", page.location.href).href, token };
|
|
5923
|
+
return { base_url: new URL("/", page.location.href).href, token: takeToken(page) };
|
|
6197
5924
|
}
|
|
6198
5925
|
function connect(options) {
|
|
6199
5926
|
if (options) return open(options, () => void 0);
|
|
@@ -6287,7 +6014,7 @@ function createWaveforms(client, options = {}) {
|
|
|
6287
6014
|
const refresh = () => {
|
|
6288
6015
|
if (active !== feed || closed) return;
|
|
6289
6016
|
historyTarget = client.session.currentTarget();
|
|
6290
|
-
const current = historyTarget && historyTarget.
|
|
6017
|
+
const current = historyTarget && historyTarget.run_id === client.variables.state.get().session;
|
|
6291
6018
|
series.set(
|
|
6292
6019
|
next.map((ref) => ({ ref: { ...ref }, points: current && feed ? feed.history(ref) : [] }))
|
|
6293
6020
|
);
|
|
@@ -6301,7 +6028,7 @@ function createWaveforms(client, options = {}) {
|
|
|
6301
6028
|
subscribe: (listener) => series.subscribe(listener),
|
|
6302
6029
|
get() {
|
|
6303
6030
|
const target = client.session.currentTarget();
|
|
6304
|
-
if (target?.instance !== historyTarget?.instance || target?.
|
|
6031
|
+
if (target?.instance !== historyTarget?.instance || target?.run_id !== historyTarget?.run_id)
|
|
6305
6032
|
return series.get().map(({ ref }) => ({ ref, points: [] }));
|
|
6306
6033
|
return series.get();
|
|
6307
6034
|
}
|
|
@@ -6348,7 +6075,7 @@ function createVariableEditor(front, ref) {
|
|
|
6348
6075
|
view,
|
|
6349
6076
|
shown: bound.pending ?? view.value,
|
|
6350
6077
|
waiting,
|
|
6351
|
-
canWrite: !closed && client.session.ready.get() && current !== null && current.
|
|
6078
|
+
canWrite: !closed && client.session.ready.get() && current !== null && current.run_id === client.variables.state.get().session && view.can_write && bound.block === null && !waiting
|
|
6352
6079
|
};
|
|
6353
6080
|
};
|
|
6354
6081
|
const state = new Writable(read2(), Object.is, clientErrorSink(client));
|
|
@@ -6364,7 +6091,7 @@ function createVariableEditor(front, ref) {
|
|
|
6364
6091
|
const bound = binding.state.get();
|
|
6365
6092
|
const shown = read2(bound);
|
|
6366
6093
|
if (closed) return;
|
|
6367
|
-
if (current?.instance !== target?.instance || current?.
|
|
6094
|
+
if (current?.instance !== target?.instance || current?.run_id !== target?.run_id || !shown.view.can_write) {
|
|
6368
6095
|
reset();
|
|
6369
6096
|
} else if (awaiting !== null && shown.view.value === awaiting) {
|
|
6370
6097
|
reset();
|
|
@@ -6468,6 +6195,7 @@ export {
|
|
|
6468
6195
|
readDashboardResponse,
|
|
6469
6196
|
readPrepareResponse,
|
|
6470
6197
|
readRecording,
|
|
6198
|
+
readRunResponse,
|
|
6471
6199
|
readRuntimeStatus,
|
|
6472
6200
|
readSavedConfig,
|
|
6473
6201
|
readScenarioList,
|