@vehicle-sil/gui-client 0.4.0-rc.1 → 0.5.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 +68 -54
- package/README.md +68 -54
- package/dist/index.js +347 -89
- package/package.json +1 -1
- package/types/client.d.ts +16 -8
- package/types/front-types.d.ts +8 -2
- package/types/front.d.ts +2 -2
- package/types/http.d.ts +4 -2
- package/types/index.d.ts +2 -2
- package/types/protocol/launcher.d.ts +17 -0
- package/types/protocol/server.d.ts +8 -0
- package/types/session-state.d.ts +8 -0
- package/types/session.d.ts +8 -2
- package/types/time.d.ts +8 -0
- package/types/variable-binding.d.ts +6 -2
- package/types/variable-state.d.ts +5 -0
- package/types/variables.d.ts +23 -0
package/dist/index.js
CHANGED
|
@@ -458,6 +458,13 @@ var readFinding = (value, path, u) => {
|
|
|
458
458
|
detail: field(f, path, "detail", soft(nullable(string), null, u))
|
|
459
459
|
});
|
|
460
460
|
};
|
|
461
|
+
var readVariableEnumItem = (value, path) => {
|
|
462
|
+
const f = object(value, path);
|
|
463
|
+
return withRaw(f, {
|
|
464
|
+
name: field(f, path, "name", string),
|
|
465
|
+
value: field(f, path, "value", integer)
|
|
466
|
+
});
|
|
467
|
+
};
|
|
461
468
|
var readVariable = (value, path) => {
|
|
462
469
|
const f = object(value, path);
|
|
463
470
|
return withRaw(f, {
|
|
@@ -467,6 +474,9 @@ var readVariable = (value, path) => {
|
|
|
467
474
|
unit: field(f, path, "unit", optional(string, "")),
|
|
468
475
|
min: field(f, path, "min", optional(nullable(number), null)),
|
|
469
476
|
max: field(f, path, "max", optional(nullable(number), null)),
|
|
477
|
+
step: field(f, path, "step", optional(nullable(number), null)),
|
|
478
|
+
description: field(f, path, "description", optional(nullable(string), "")),
|
|
479
|
+
items: field(f, path, "items", optional(nullable(array(readVariableEnumItem)), [])),
|
|
470
480
|
builtin: field(f, path, "builtin", optional(nullable(boolean), null))
|
|
471
481
|
});
|
|
472
482
|
};
|
|
@@ -488,7 +498,8 @@ var readCheckScenario = (value, path, u) => {
|
|
|
488
498
|
return withRaw(f, {
|
|
489
499
|
file: field(f, path, "file", lenient(string, "", u)),
|
|
490
500
|
name: field(f, path, "name", soft(nullable(string), null, u)),
|
|
491
|
-
steps: field(f, path, "steps", lenient(integer, 0, u))
|
|
501
|
+
steps: field(f, path, "steps", lenient(integer, 0, u)),
|
|
502
|
+
end_ms: field(f, path, "end_ms", soft(nullable(integer), null, u))
|
|
492
503
|
});
|
|
493
504
|
};
|
|
494
505
|
var readScenarioResult = (value, path, u) => {
|
|
@@ -498,6 +509,7 @@ var readScenarioResult = (value, path, u) => {
|
|
|
498
509
|
name: field(f, path, "name", soft(nullable(string), null, u)),
|
|
499
510
|
status: field(f, path, "status", lenient(string, "", u)),
|
|
500
511
|
over_at_ms: field(f, path, "over_at_ms", soft(nullable(number), null, u)),
|
|
512
|
+
end_ms: field(f, path, "end_ms", soft(nullable(integer), null, u)),
|
|
501
513
|
steps: field(
|
|
502
514
|
f,
|
|
503
515
|
path,
|
|
@@ -853,6 +865,8 @@ function readStateFields(f, path, u) {
|
|
|
853
865
|
)
|
|
854
866
|
),
|
|
855
867
|
scenario: field(f, path, "scenario", soft(nullable(boolean), null, u)),
|
|
868
|
+
handed_over: field(f, path, "handed_over", soft(boolean, false, u)),
|
|
869
|
+
scenario_over_at_ms: field(f, path, "scenario_over_at_ms", soft(nullable(number), null, u)),
|
|
856
870
|
allowed: field(f, path, "allowed", lenient(record(readLauncherAllowedItem), {}, u)),
|
|
857
871
|
outside: field(
|
|
858
872
|
f,
|
|
@@ -1114,9 +1128,10 @@ var readRecording = (value) => {
|
|
|
1114
1128
|
state: field(r, path, "state", string),
|
|
1115
1129
|
available: field(r, path, "available", boolean),
|
|
1116
1130
|
reason: field(r, path, "reason", nullable(string)),
|
|
1117
|
-
writes: field(r, path, "writes",
|
|
1118
|
-
omitted: field(r, path, "omitted",
|
|
1119
|
-
steps: field(r, path, "steps",
|
|
1131
|
+
writes: field(r, path, "writes", nonNegativeInteger),
|
|
1132
|
+
omitted: field(r, path, "omitted", nonNegativeInteger),
|
|
1133
|
+
steps: field(r, path, "steps", nonNegativeInteger),
|
|
1134
|
+
end_ms: field(r, path, "end_ms", optional(nullable(nonNegativeInteger), null)),
|
|
1120
1135
|
yaml: field(r, path, "yaml", nullable(string))
|
|
1121
1136
|
};
|
|
1122
1137
|
};
|
|
@@ -1216,6 +1231,7 @@ var readSummaryScenario = (value, path, u) => {
|
|
|
1216
1231
|
steps_omitted: field(f, path, "steps_omitted", soft(integer, 0, u)),
|
|
1217
1232
|
status: field(f, path, "status", soft(nullable(string), null, u)),
|
|
1218
1233
|
over_at_ms: field(f, path, "over_at_ms", soft(nullable(number), null, u)),
|
|
1234
|
+
...f["handed_over"] === void 0 ? {} : { handed_over: field(f, path, "handed_over", soft(boolean, false, u)) },
|
|
1219
1235
|
timeline_url: field(f, path, "timeline_url", soft(nullable(string), null, u))
|
|
1220
1236
|
};
|
|
1221
1237
|
};
|
|
@@ -1788,7 +1804,8 @@ function errorMessage(error) {
|
|
|
1788
1804
|
}
|
|
1789
1805
|
function fetchTransport(options) {
|
|
1790
1806
|
const send = options.fetch ?? ((input, init) => globalThis.fetch(input, init));
|
|
1791
|
-
const
|
|
1807
|
+
const rawToken = options.token;
|
|
1808
|
+
const token = typeof rawToken === "function" ? rawToken : () => rawToken ?? null;
|
|
1792
1809
|
return (request, done) => {
|
|
1793
1810
|
const headers = {};
|
|
1794
1811
|
const current = token();
|
|
@@ -1811,6 +1828,7 @@ function fetchTransport(options) {
|
|
|
1811
1828
|
redirect: "error",
|
|
1812
1829
|
signal: abort.signal
|
|
1813
1830
|
};
|
|
1831
|
+
if (request.keepalive !== void 0) init.keepalive = request.keepalive;
|
|
1814
1832
|
if (request.method === "POST") init.body = JSON.stringify(request.body ?? {});
|
|
1815
1833
|
const fail = (error) => done({
|
|
1816
1834
|
ok: false,
|
|
@@ -1882,15 +1900,18 @@ function commandView(command, seq) {
|
|
|
1882
1900
|
seq
|
|
1883
1901
|
};
|
|
1884
1902
|
}
|
|
1885
|
-
function scenarioView(summary) {
|
|
1903
|
+
function scenarioView(summary, launcherState = null) {
|
|
1904
|
+
const rawHandedOver = summary.handed_over === true || launcherState?.handed_over === true;
|
|
1905
|
+
const handedOver = rawHandedOver && (summary.status === null || summary.status === "passed");
|
|
1886
1906
|
return {
|
|
1887
1907
|
file: summary.file,
|
|
1888
1908
|
name: summary.name,
|
|
1889
1909
|
stepCount: summary.step_count,
|
|
1890
1910
|
steps: summary.steps,
|
|
1891
1911
|
stepsOmitted: summary.steps_omitted,
|
|
1892
|
-
status: summary.status,
|
|
1893
|
-
|
|
1912
|
+
status: handedOver ? summary.status ?? "passed" : summary.status,
|
|
1913
|
+
handedOver,
|
|
1914
|
+
overAtMs: summary.over_at_ms ?? (handedOver ? launcherState?.scenario_over_at_ms ?? null : null),
|
|
1894
1915
|
timelineUrl: summary.timeline_url
|
|
1895
1916
|
};
|
|
1896
1917
|
}
|
|
@@ -1917,6 +1938,18 @@ function isLauncherAlive(session) {
|
|
|
1917
1938
|
function isHolding(session) {
|
|
1918
1939
|
return isRunActive(session) && session.launcherState?.holding === true;
|
|
1919
1940
|
}
|
|
1941
|
+
function isScenarioHandedOver(session) {
|
|
1942
|
+
if (!session?.scenario) return false;
|
|
1943
|
+
const scenario = session.scenario;
|
|
1944
|
+
if (scenario.status !== null && scenario.status !== void 0 && scenario.status !== "passed") {
|
|
1945
|
+
return false;
|
|
1946
|
+
}
|
|
1947
|
+
const launcher = "launcherState" in session ? session.launcherState : session.launcher_state;
|
|
1948
|
+
return (scenario.handedOver ?? scenario.handed_over) === true || launcher?.handed_over === true;
|
|
1949
|
+
}
|
|
1950
|
+
function isScenarioRunning(session) {
|
|
1951
|
+
return isRunActive(session) && session.result === null && session.scenario !== null && !isScenarioHandedOver(session) && session.scenario.status === null;
|
|
1952
|
+
}
|
|
1920
1953
|
function runOutcome(session) {
|
|
1921
1954
|
if (isRunActive(session)) {
|
|
1922
1955
|
if (session.result) return "finishing";
|
|
@@ -1967,6 +2000,7 @@ function addDropped(session, dropped) {
|
|
|
1967
2000
|
const mark = session.droppedMarks + 1;
|
|
1968
2001
|
const gaps = counts.map(([source, count]) => ({
|
|
1969
2002
|
seq: session.lastSeq + 0.5,
|
|
2003
|
+
tMs: null,
|
|
1970
2004
|
key: `dropped ${mark} ${source}`,
|
|
1971
2005
|
source,
|
|
1972
2006
|
line: "",
|
|
@@ -2028,11 +2062,19 @@ function applySummary(session, summary) {
|
|
|
2028
2062
|
...participants,
|
|
2029
2063
|
...session.participants.filter((p) => !participants.some((current) => current.name === p.name))
|
|
2030
2064
|
];
|
|
2065
|
+
const launcherState = newerState(session.launcherState, summary.launcher_state ?? null);
|
|
2066
|
+
const rawHandedOver = summary.scenario?.handed_over === true || launcherState?.handed_over === true || session.scenario?.handedOver === true;
|
|
2067
|
+
const effectiveStatus = result?.scenario?.status ?? summary.scenario?.status ?? session.scenario?.status ?? null;
|
|
2068
|
+
const handedOver = rawHandedOver && (effectiveStatus === null || effectiveStatus === "passed");
|
|
2031
2069
|
let scenario = summary.scenario ? {
|
|
2032
|
-
...scenarioView(summary.scenario),
|
|
2070
|
+
...scenarioView(summary.scenario, launcherState),
|
|
2071
|
+
handedOver,
|
|
2072
|
+
status: handedOver ? summary.scenario.status ?? "passed" : summary.scenario.status,
|
|
2073
|
+
overAtMs: summary.scenario.over_at_ms ?? (handedOver ? launcherState?.scenario_over_at_ms ?? session.scenario?.overAtMs ?? null : null),
|
|
2033
2074
|
timelineUrl: summary.scenario.timeline_url ?? session.scenario?.timelineUrl ?? null
|
|
2034
2075
|
} : session.scenario;
|
|
2035
2076
|
if (scenario && result?.scenario) {
|
|
2077
|
+
const resultHandedOver = handedOver && result.scenario.status === "passed";
|
|
2036
2078
|
scenario = {
|
|
2037
2079
|
...scenario,
|
|
2038
2080
|
name: result.scenario.name ?? scenario.name,
|
|
@@ -2040,7 +2082,8 @@ function applySummary(session, summary) {
|
|
|
2040
2082
|
steps: result.scenario.steps,
|
|
2041
2083
|
stepsOmitted: 0,
|
|
2042
2084
|
status: result.scenario.status,
|
|
2043
|
-
|
|
2085
|
+
handedOver: resultHandedOver,
|
|
2086
|
+
overAtMs: result.scenario.over_at_ms ?? (resultHandedOver ? scenario.overAtMs : null)
|
|
2044
2087
|
};
|
|
2045
2088
|
}
|
|
2046
2089
|
const problems = summary.problems.slice(0, MAX_PROBLEMS);
|
|
@@ -2063,7 +2106,7 @@ function applySummary(session, summary) {
|
|
|
2063
2106
|
timeOmittedFields: summary.sim_ms === null ? session.timeOmittedFields : summary.time_omitted_fields,
|
|
2064
2107
|
time: summary.time ? timeView(summary.time) : session.time,
|
|
2065
2108
|
lastCommand: summary.last_command ? commandView(summary.last_command, summary.last_command.seq ?? -1) : session.lastCommand,
|
|
2066
|
-
launcherState
|
|
2109
|
+
launcherState,
|
|
2067
2110
|
findings: summary.findings.slice(0, MAX_FINDINGS),
|
|
2068
2111
|
result,
|
|
2069
2112
|
check,
|
|
@@ -2207,13 +2250,20 @@ function applyOne(session, event, logs) {
|
|
|
2207
2250
|
};
|
|
2208
2251
|
}
|
|
2209
2252
|
case "log":
|
|
2210
|
-
logs.push({
|
|
2253
|
+
logs.push({
|
|
2254
|
+
seq: event.seq,
|
|
2255
|
+
tMs: event.t_ms,
|
|
2256
|
+
key: String(event.seq),
|
|
2257
|
+
source: event.source,
|
|
2258
|
+
line: event.line
|
|
2259
|
+
});
|
|
2211
2260
|
return next;
|
|
2212
2261
|
case "log_dropped":
|
|
2213
2262
|
for (const [source, count] of Object.entries(event.sources)) {
|
|
2214
2263
|
if (count > 0) {
|
|
2215
2264
|
logs.push({
|
|
2216
2265
|
seq: event.seq,
|
|
2266
|
+
tMs: event.t_ms,
|
|
2217
2267
|
key: `${event.seq} ${source}`,
|
|
2218
2268
|
source,
|
|
2219
2269
|
line: "",
|
|
@@ -2231,25 +2281,46 @@ function applyOne(session, event, logs) {
|
|
|
2231
2281
|
return { ...next, simMs: event.sim_ms, timeOmittedFields: [], time: timeView(event) };
|
|
2232
2282
|
case "command":
|
|
2233
2283
|
return { ...next, lastCommand: commandView(event, event.seq) };
|
|
2234
|
-
case "state":
|
|
2235
|
-
|
|
2236
|
-
|
|
2284
|
+
case "state": {
|
|
2285
|
+
const launcherState = newerState(next.launcherState, event);
|
|
2286
|
+
const handedOver = launcherState?.handed_over === true;
|
|
2287
|
+
if (!next.scenario || !handedOver) return { ...next, launcherState };
|
|
2288
|
+
const status = next.scenario.status;
|
|
2289
|
+
if (status !== null && status !== "passed") return { ...next, launcherState };
|
|
2237
2290
|
return {
|
|
2238
2291
|
...next,
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2292
|
+
launcherState,
|
|
2293
|
+
scenario: {
|
|
2294
|
+
...next.scenario,
|
|
2295
|
+
handedOver: true,
|
|
2296
|
+
status: "passed",
|
|
2297
|
+
overAtMs: next.scenario.overAtMs ?? launcherState.scenario_over_at_ms ?? null
|
|
2298
|
+
}
|
|
2299
|
+
};
|
|
2300
|
+
}
|
|
2301
|
+
case "result": {
|
|
2302
|
+
const scenario = next.scenario && event.result.scenario ? (() => {
|
|
2303
|
+
const handedOver = event.result.scenario.status === "passed" ? next.scenario.handedOver : false;
|
|
2304
|
+
return {
|
|
2245
2305
|
...next.scenario,
|
|
2246
2306
|
name: event.result.scenario.name,
|
|
2247
2307
|
stepCount: next.scenario.stepCount ?? event.result.scenario.steps.length,
|
|
2248
2308
|
steps: event.result.scenario.steps,
|
|
2249
2309
|
status: event.result.scenario.status,
|
|
2250
|
-
|
|
2251
|
-
|
|
2310
|
+
handedOver,
|
|
2311
|
+
overAtMs: event.result.scenario.over_at_ms ?? (handedOver ? next.scenario.overAtMs : null)
|
|
2312
|
+
};
|
|
2313
|
+
})() : next.scenario;
|
|
2314
|
+
return {
|
|
2315
|
+
...next,
|
|
2316
|
+
result: event.result,
|
|
2317
|
+
phase: "ended",
|
|
2318
|
+
phaseRank: phaseIndex("ended"),
|
|
2319
|
+
check: next.check ?? event.result.check,
|
|
2320
|
+
participants: mergeResult(next.participants, event.result),
|
|
2321
|
+
scenario
|
|
2252
2322
|
};
|
|
2323
|
+
}
|
|
2253
2324
|
default:
|
|
2254
2325
|
return next;
|
|
2255
2326
|
}
|
|
@@ -2572,12 +2643,13 @@ function sameRunTarget(left, right) {
|
|
|
2572
2643
|
return left !== null && right !== null && left.run_id === right.run_id && left.instance === right.instance;
|
|
2573
2644
|
}
|
|
2574
2645
|
var SessionFeed = class {
|
|
2575
|
-
constructor(connection, onError = rethrowLater, onInstance) {
|
|
2646
|
+
constructor(connection, onError = rethrowLater, onInstance, hooks) {
|
|
2576
2647
|
this.connection = connection;
|
|
2577
2648
|
this.onError = onError;
|
|
2578
2649
|
this.onInstance = onInstance;
|
|
2650
|
+
this.hooks = hooks;
|
|
2579
2651
|
this.current = new Writable(null, Object.is, onError);
|
|
2580
|
-
this.
|
|
2652
|
+
this.readyValue = new Writable(false, Object.is, onError);
|
|
2581
2653
|
this.allowedValue = new Writable(null, Object.is, onError);
|
|
2582
2654
|
this.allowed = this.allowedValue.readonly();
|
|
2583
2655
|
this.runtimeValue = new Writable(null, Object.is, onError);
|
|
@@ -2591,12 +2663,10 @@ var SessionFeed = class {
|
|
|
2591
2663
|
this.notices = this.noticeList.readonly();
|
|
2592
2664
|
this.rejected = this.rejectedValue.readonly();
|
|
2593
2665
|
this.incompatible = this.incompatibleValue.readonly();
|
|
2594
|
-
this.ready =
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
onError
|
|
2599
|
-
);
|
|
2666
|
+
this.ready = this.readyValue.readonly();
|
|
2667
|
+
connection.state.subscribe((state) => {
|
|
2668
|
+
this.readyValue.set(state === "open" && this.syncedFlag);
|
|
2669
|
+
});
|
|
2600
2670
|
connection.onBatch((batch) => this.receive(batch));
|
|
2601
2671
|
connection.onUnreadable(
|
|
2602
2672
|
(text3) => this.notify(`unreadable message: not JSON (connecting again): ${text3.slice(0, 80)}`)
|
|
@@ -2605,13 +2675,15 @@ var SessionFeed = class {
|
|
|
2605
2675
|
connection;
|
|
2606
2676
|
onError;
|
|
2607
2677
|
onInstance;
|
|
2678
|
+
hooks;
|
|
2608
2679
|
rawListeners = /* @__PURE__ */ new Set();
|
|
2609
2680
|
instanceId = null;
|
|
2610
2681
|
lastStreamSeq = -1;
|
|
2611
2682
|
resyncing = false;
|
|
2683
|
+
syncedFlag = false;
|
|
2612
2684
|
stopTarget = null;
|
|
2613
2685
|
current;
|
|
2614
|
-
|
|
2686
|
+
readyValue;
|
|
2615
2687
|
allowedValue;
|
|
2616
2688
|
runtimeValue;
|
|
2617
2689
|
receivedAt;
|
|
@@ -2633,13 +2705,17 @@ var SessionFeed = class {
|
|
|
2633
2705
|
get stopped() {
|
|
2634
2706
|
return this.stoppedFlag;
|
|
2635
2707
|
}
|
|
2708
|
+
setSyncedDeferred(value) {
|
|
2709
|
+
this.syncedFlag = value;
|
|
2710
|
+
return this.readyValue.setDeferred(this.connection.state.get() === "open" && value);
|
|
2711
|
+
}
|
|
2636
2712
|
/**
|
|
2637
2713
|
* Fields to add to the authentication message: where in the stream it holds the server should resend from. Called
|
|
2638
2714
|
* on every connect (after the call, the copy is not in sync until hello and the resent events have arrived). Used
|
|
2639
2715
|
* only inside the library.
|
|
2640
2716
|
*/
|
|
2641
2717
|
resumeFields() {
|
|
2642
|
-
this.
|
|
2718
|
+
this.setSyncedDeferred(false)();
|
|
2643
2719
|
const session = this.current.get();
|
|
2644
2720
|
if (this.instanceId === null || session === null || this.lastStreamSeq < 0) return {};
|
|
2645
2721
|
return {
|
|
@@ -2724,7 +2800,7 @@ var SessionFeed = class {
|
|
|
2724
2800
|
originInstance = instance;
|
|
2725
2801
|
});
|
|
2726
2802
|
if (!currentOrigin()) return;
|
|
2727
|
-
if (stop === "lost" || stop === "incompatible") this.
|
|
2803
|
+
if (stop === "lost" || stop === "incompatible") this.setSyncedDeferred(false)();
|
|
2728
2804
|
if (stop === "unauthorized") this.rejectedValue.set(true);
|
|
2729
2805
|
if (incompatible !== null) this.incompatibleValue.set(incompatible);
|
|
2730
2806
|
}
|
|
@@ -2739,8 +2815,11 @@ var SessionFeed = class {
|
|
|
2739
2815
|
const notices = [];
|
|
2740
2816
|
const selectedBatch = [];
|
|
2741
2817
|
const selectedRaw = [];
|
|
2818
|
+
let firstSwitchRawIndex = -1;
|
|
2819
|
+
let lastSwitchRawIndex = -1;
|
|
2742
2820
|
let applied = false;
|
|
2743
|
-
let synced = this.
|
|
2821
|
+
let synced = this.syncedFlag;
|
|
2822
|
+
let syncReset = false;
|
|
2744
2823
|
let allowedNow = this.allowedValue.get();
|
|
2745
2824
|
let runtimeNow = this.runtimeValue.get();
|
|
2746
2825
|
const takeAllowed = (incoming) => {
|
|
@@ -2769,6 +2848,7 @@ var SessionFeed = class {
|
|
|
2769
2848
|
switch (message.type) {
|
|
2770
2849
|
case "hello": {
|
|
2771
2850
|
synced = false;
|
|
2851
|
+
syncReset = true;
|
|
2772
2852
|
replaying = true;
|
|
2773
2853
|
const { session: summary, replay } = message;
|
|
2774
2854
|
const sameInstance = instance !== null && instance === message.instance;
|
|
@@ -2790,6 +2870,8 @@ var SessionFeed = class {
|
|
|
2790
2870
|
} else if (!sameInstance) {
|
|
2791
2871
|
runtimeNow = null;
|
|
2792
2872
|
}
|
|
2873
|
+
const prevId = session?.id ?? null;
|
|
2874
|
+
const switchedInstance = instance !== null && instance !== message.instance;
|
|
2793
2875
|
instance = message.instance;
|
|
2794
2876
|
if (!summary) {
|
|
2795
2877
|
session = null;
|
|
@@ -2798,6 +2880,10 @@ var SessionFeed = class {
|
|
|
2798
2880
|
} else {
|
|
2799
2881
|
session = sessionFromSummary(summary);
|
|
2800
2882
|
}
|
|
2883
|
+
if (switchedInstance || (session?.id ?? null) !== prevId) {
|
|
2884
|
+
if (firstSwitchRawIndex < 0) firstSwitchRawIndex = selectedRaw.length;
|
|
2885
|
+
lastSwitchRawIndex = selectedRaw.length;
|
|
2886
|
+
}
|
|
2801
2887
|
selectedBatch.push(message);
|
|
2802
2888
|
selectedRaw.push(rawMessage);
|
|
2803
2889
|
break;
|
|
@@ -2836,15 +2922,21 @@ var SessionFeed = class {
|
|
|
2836
2922
|
selectedBatch.push(message);
|
|
2837
2923
|
selectedRaw.push(rawMessage);
|
|
2838
2924
|
break;
|
|
2839
|
-
case "session":
|
|
2925
|
+
case "session": {
|
|
2926
|
+
const prevId = session?.id ?? null;
|
|
2840
2927
|
takeAllowed(message.session.allowed);
|
|
2841
2928
|
session = session?.id === message.session.id ? applySummary(session, message.session) : sessionFromSummary(message.session);
|
|
2842
2929
|
if (typeof message.stream_seq !== "number" && message.session.last_seq !== null) {
|
|
2843
2930
|
streamSeq = Math.max(streamSeq, message.session.last_seq);
|
|
2844
2931
|
}
|
|
2932
|
+
if (session.id !== prevId) {
|
|
2933
|
+
if (firstSwitchRawIndex < 0) firstSwitchRawIndex = selectedRaw.length;
|
|
2934
|
+
lastSwitchRawIndex = selectedRaw.length;
|
|
2935
|
+
}
|
|
2845
2936
|
selectedBatch.push(message);
|
|
2846
2937
|
selectedRaw.push(rawMessage);
|
|
2847
2938
|
break;
|
|
2939
|
+
}
|
|
2848
2940
|
case "event":
|
|
2849
2941
|
if (session?.id === message.run_id) {
|
|
2850
2942
|
events.push(message.event);
|
|
@@ -2874,13 +2966,14 @@ var SessionFeed = class {
|
|
|
2874
2966
|
break;
|
|
2875
2967
|
case "resync":
|
|
2876
2968
|
synced = false;
|
|
2969
|
+
syncReset = true;
|
|
2877
2970
|
replaying = true;
|
|
2878
2971
|
resyncing = true;
|
|
2879
2972
|
selectedBatch.push(message);
|
|
2880
2973
|
selectedRaw.push(rawMessage);
|
|
2881
2974
|
break;
|
|
2882
2975
|
default:
|
|
2883
|
-
if (
|
|
2976
|
+
if ("run_id" in message && message.run_id !== (session?.id ?? null)) {
|
|
2884
2977
|
continue;
|
|
2885
2978
|
}
|
|
2886
2979
|
selectedBatch.push(message);
|
|
@@ -2892,6 +2985,16 @@ var SessionFeed = class {
|
|
|
2892
2985
|
const stale = (session?.staleEvents ?? 0) - (before?.id === session?.id ? before?.staleEvents ?? 0 : 0);
|
|
2893
2986
|
if (!currentOrigin()) return;
|
|
2894
2987
|
const beforeInstance = this.instanceId;
|
|
2988
|
+
const beforeId = before?.id ?? null;
|
|
2989
|
+
if (lastSwitchRawIndex > 0 && this.hooks?.beforeRunSwitch) {
|
|
2990
|
+
const sameBefore = () => currentOrigin() && this.instanceId === beforeInstance && (this.current.get()?.id ?? null) === beforeId;
|
|
2991
|
+
this.hooks.beforeRunSwitch(
|
|
2992
|
+
selectedRaw.slice(0, firstSwitchRawIndex),
|
|
2993
|
+
selectedRaw.slice(firstSwitchRawIndex, lastSwitchRawIndex),
|
|
2994
|
+
sameBefore
|
|
2995
|
+
);
|
|
2996
|
+
if (!sameBefore()) return;
|
|
2997
|
+
}
|
|
2895
2998
|
this.instanceId = instance;
|
|
2896
2999
|
this.lastStreamSeq = streamSeq;
|
|
2897
3000
|
this.resyncing = resyncing;
|
|
@@ -2899,18 +3002,29 @@ var SessionFeed = class {
|
|
|
2899
3002
|
this.stopTarget = session && instance ? { run_id: session.id, instance } : null;
|
|
2900
3003
|
const sessionId = session?.id ?? null;
|
|
2901
3004
|
const sameStream = () => currentOrigin() && this.instanceId === instance && (this.current.get()?.id ?? null) === sessionId;
|
|
3005
|
+
const instanceChanged = instance !== null && beforeInstance !== null && instance !== beforeInstance;
|
|
2902
3006
|
const notifySession = this.current.setDeferred(session);
|
|
2903
3007
|
const notifyAllowed = this.allowedValue.setDeferred(allowedNow);
|
|
2904
3008
|
const notifyRuntime = this.runtimeValue.setDeferred(runtimeNow);
|
|
2905
|
-
const
|
|
2906
|
-
|
|
3009
|
+
const notifyUnsynced = !synced || syncReset ? this.setSyncedDeferred(false) : void 0;
|
|
3010
|
+
let notifyVarSwitch;
|
|
3011
|
+
if (this.hooks?.stageRunSwitch) {
|
|
3012
|
+
if (lastSwitchRawIndex >= 0 || instance !== null && instance !== beforeInstance) {
|
|
3013
|
+
notifyVarSwitch = this.hooks.stageRunSwitch(
|
|
3014
|
+
instance,
|
|
3015
|
+
sessionId,
|
|
3016
|
+
instanceChanged || lastSwitchRawIndex >= 0
|
|
3017
|
+
);
|
|
3018
|
+
}
|
|
3019
|
+
} else if (instance !== null && instance !== beforeInstance) {
|
|
2907
3020
|
this.onInstance?.(instance);
|
|
2908
3021
|
if (!sameStream()) return;
|
|
2909
3022
|
}
|
|
2910
3023
|
notifySession();
|
|
2911
3024
|
notifyAllowed();
|
|
2912
3025
|
notifyRuntime();
|
|
2913
|
-
|
|
3026
|
+
notifyUnsynced?.();
|
|
3027
|
+
notifyVarSwitch?.();
|
|
2914
3028
|
if (!sameStream()) return;
|
|
2915
3029
|
for (const notice of notices) {
|
|
2916
3030
|
this.notify(notice);
|
|
@@ -2920,10 +3034,14 @@ var SessionFeed = class {
|
|
|
2920
3034
|
if (!sameStream()) return;
|
|
2921
3035
|
if (stale > 0) this.notify(STALE_EVENTS_NOTICE, stale);
|
|
2922
3036
|
if (!sameStream()) return;
|
|
2923
|
-
|
|
2924
|
-
|
|
3037
|
+
const rawToDeliver = this.hooks?.beforeRunSwitch && lastSwitchRawIndex >= 0 ? selectedRaw.slice(lastSwitchRawIndex) : selectedRaw;
|
|
3038
|
+
if (rawToDeliver.length > 0) {
|
|
3039
|
+
callEach(this.rawListeners, [rawToDeliver, sameStream], this.onError, sameStream);
|
|
2925
3040
|
}
|
|
2926
3041
|
if (!sameStream()) return;
|
|
3042
|
+
const notifySynced = this.setSyncedDeferred(synced);
|
|
3043
|
+
notifySynced();
|
|
3044
|
+
if (!sameStream()) return;
|
|
2927
3045
|
if (selectedBatch.length > 0) {
|
|
2928
3046
|
callEach(this.messageListeners, [selectedBatch], this.onError, sameStream);
|
|
2929
3047
|
}
|
|
@@ -2984,6 +3102,12 @@ var TimeControl = class {
|
|
|
2984
3102
|
step(ms) {
|
|
2985
3103
|
return this.send({ command: "step", ms });
|
|
2986
3104
|
}
|
|
3105
|
+
/**
|
|
3106
|
+
* Advances virtual time until atMs and pauses there (the launcher rounds up to a multiple of the time step).
|
|
3107
|
+
*/
|
|
3108
|
+
runUntil(atMs) {
|
|
3109
|
+
return this.send({ command: "run_until", at_ms: atMs });
|
|
3110
|
+
}
|
|
2987
3111
|
/** Changes the speed (a pause stays in effect). */
|
|
2988
3112
|
setSpeed(value) {
|
|
2989
3113
|
return this.send({ command: "speed", value });
|
|
@@ -3104,6 +3228,7 @@ function valueCondition(input) {
|
|
|
3104
3228
|
if (status !== "ready") return { kind: "stale", reading, why: "reconnecting" };
|
|
3105
3229
|
if (!input.peerConnected) return { kind: "stale", reading, why: "peer" };
|
|
3106
3230
|
if (input.readFailing) return { kind: "stale", reading, why: "reading" };
|
|
3231
|
+
if (input.awaitingRefresh) return { kind: "stale", reading, why: "connection" };
|
|
3107
3232
|
return reading.paused ? { kind: "paused", reading } : { kind: "live", reading };
|
|
3108
3233
|
}
|
|
3109
3234
|
function sameCondition(a, b) {
|
|
@@ -3343,11 +3468,14 @@ var VariablesFeed = class {
|
|
|
3343
3468
|
onError;
|
|
3344
3469
|
limits;
|
|
3345
3470
|
instanceId = null;
|
|
3471
|
+
epoch = 0;
|
|
3346
3472
|
stateValue;
|
|
3347
3473
|
operationsValue;
|
|
3348
3474
|
handles = /* @__PURE__ */ new Set();
|
|
3349
3475
|
buckets = /* @__PURE__ */ new Map();
|
|
3350
3476
|
readings = /* @__PURE__ */ new Map();
|
|
3477
|
+
/** Cached keys kept across a reconnect until a post-reconnect `values` sample arrives. */
|
|
3478
|
+
awaitingRefresh = /* @__PURE__ */ new Set();
|
|
3351
3479
|
histories = /* @__PURE__ */ new Map();
|
|
3352
3480
|
pending = /* @__PURE__ */ new Set();
|
|
3353
3481
|
/** Variables someone watches (null: a watch observes all). */
|
|
@@ -3368,6 +3496,7 @@ var VariablesFeed = class {
|
|
|
3368
3496
|
/** Messages sent right after connecting (after authentication): all current subscriptions. */
|
|
3369
3497
|
resume() {
|
|
3370
3498
|
this.syncQueued = false;
|
|
3499
|
+
for (const key of this.readings.keys()) this.awaitingRefresh.add(key);
|
|
3371
3500
|
const messages = [];
|
|
3372
3501
|
for (const [periodMs, wanted] of this.wanted()) {
|
|
3373
3502
|
const bucket = this.bucket(periodMs);
|
|
@@ -3397,6 +3526,48 @@ var VariablesFeed = class {
|
|
|
3397
3526
|
this.instanceId = instance;
|
|
3398
3527
|
if (hadInstance) this.enter(null, true);
|
|
3399
3528
|
}
|
|
3529
|
+
/**
|
|
3530
|
+
* Applies messages belonging to the previous session (`beforeBatch`) while `SessionFeed`
|
|
3531
|
+
* still holds that session, and processes connection-level resyncs/watch errors across any
|
|
3532
|
+
* superseded intermediate runs (`skippedBatch`) before `SessionFeed` commits the final run.
|
|
3533
|
+
*/
|
|
3534
|
+
beforeRunSwitch(beforeBatch, skippedBatch, current = () => true) {
|
|
3535
|
+
let sawResync = false;
|
|
3536
|
+
const preSwitch = [];
|
|
3537
|
+
for (const message of beforeBatch) {
|
|
3538
|
+
if (isObject(message) && message["type"] === "resync") {
|
|
3539
|
+
sawResync = true;
|
|
3540
|
+
} else {
|
|
3541
|
+
preSwitch.push(message);
|
|
3542
|
+
}
|
|
3543
|
+
}
|
|
3544
|
+
if (preSwitch.length > 0) {
|
|
3545
|
+
this.receive(preSwitch, current);
|
|
3546
|
+
if (!current()) return;
|
|
3547
|
+
}
|
|
3548
|
+
for (const message of skippedBatch) {
|
|
3549
|
+
if (!current()) return;
|
|
3550
|
+
if (!isObject(message)) continue;
|
|
3551
|
+
const type = message["type"];
|
|
3552
|
+
if (type === "resync") {
|
|
3553
|
+
sawResync = true;
|
|
3554
|
+
} else if (type === "error") {
|
|
3555
|
+
const code = message["code"];
|
|
3556
|
+
if (code === "invalid-watch" || code === "too-many-watches") {
|
|
3557
|
+
this.problemValue.set({ code, message: text(message["message"]) });
|
|
3558
|
+
}
|
|
3559
|
+
}
|
|
3560
|
+
}
|
|
3561
|
+
if (sawResync && current()) this.resyncWatches();
|
|
3562
|
+
}
|
|
3563
|
+
/**
|
|
3564
|
+
* Clears the previous run's observable variable state synchronously before `SessionFeed`
|
|
3565
|
+
* notifies `session` subscribers of a new run, returning the deferred variable notifications.
|
|
3566
|
+
*/
|
|
3567
|
+
stageRunSwitch(instance, sessionId, instanceChanged) {
|
|
3568
|
+
if (instance !== null) this.instanceId = instance;
|
|
3569
|
+
return this.prepareEnter(sessionId, instanceChanged, sessionId === null ? "off" : "unknown");
|
|
3570
|
+
}
|
|
3400
3571
|
receive(batch, current = () => true) {
|
|
3401
3572
|
const touched = /* @__PURE__ */ new Set();
|
|
3402
3573
|
let touchedAll = false;
|
|
@@ -3411,6 +3582,14 @@ var VariablesFeed = class {
|
|
|
3411
3582
|
if (!current()) return;
|
|
3412
3583
|
if (!isObject(message)) continue;
|
|
3413
3584
|
switch (message["type"]) {
|
|
3585
|
+
case "resync": {
|
|
3586
|
+
flush();
|
|
3587
|
+
if (!current()) return;
|
|
3588
|
+
for (const key of this.readings.keys()) this.awaitingRefresh.add(key);
|
|
3589
|
+
this.resyncWatches();
|
|
3590
|
+
touchedAll = true;
|
|
3591
|
+
break;
|
|
3592
|
+
}
|
|
3414
3593
|
case "hello": {
|
|
3415
3594
|
flush();
|
|
3416
3595
|
if (!current()) return;
|
|
@@ -3444,6 +3623,9 @@ var VariablesFeed = class {
|
|
|
3444
3623
|
notifyOperations = this.prepareOperations(currentOps, listed, sameIdentity);
|
|
3445
3624
|
}
|
|
3446
3625
|
const next = readVariables2(variables, id);
|
|
3626
|
+
if (next.status === "ended" || next.status === "off" || next.status === "failed") {
|
|
3627
|
+
this.awaitingRefresh.clear();
|
|
3628
|
+
}
|
|
3447
3629
|
this.stateValue.set(next);
|
|
3448
3630
|
notifyOperations();
|
|
3449
3631
|
if (sameIdentity() && this.stateValue.get() === next && isObject(variables) && Array.isArray(variables["operations"])) {
|
|
@@ -3457,9 +3639,7 @@ var VariablesFeed = class {
|
|
|
3457
3639
|
}
|
|
3458
3640
|
}
|
|
3459
3641
|
} else {
|
|
3460
|
-
this.enter(null);
|
|
3461
|
-
if (!current()) return;
|
|
3462
|
-
this.stateValue.set({ ...NO_VARIABLES, status: "off" });
|
|
3642
|
+
this.enter(null, false, "off");
|
|
3463
3643
|
}
|
|
3464
3644
|
touchedAll = true;
|
|
3465
3645
|
break;
|
|
@@ -3492,7 +3672,11 @@ var VariablesFeed = class {
|
|
|
3492
3672
|
touchedAll = true;
|
|
3493
3673
|
}
|
|
3494
3674
|
}
|
|
3495
|
-
|
|
3675
|
+
const next = readVariables2(details, id);
|
|
3676
|
+
if (next.status === "ended" || next.status === "off" || next.status === "failed") {
|
|
3677
|
+
this.awaitingRefresh.clear();
|
|
3678
|
+
}
|
|
3679
|
+
this.stateValue.set(next);
|
|
3496
3680
|
break;
|
|
3497
3681
|
}
|
|
3498
3682
|
case "values": {
|
|
@@ -3569,17 +3753,26 @@ var VariablesFeed = class {
|
|
|
3569
3753
|
* are dropped with their memory, so they do not keep growing as the variables change from run to run). Writes
|
|
3570
3754
|
* waiting for the previous run's result are failed, since the result will not come.
|
|
3571
3755
|
*/
|
|
3572
|
-
enter(session, force = false) {
|
|
3573
|
-
|
|
3756
|
+
enter(session, force = false, status = "unknown") {
|
|
3757
|
+
this.prepareEnter(session, force, status)();
|
|
3758
|
+
return this.stateValue.get();
|
|
3759
|
+
}
|
|
3760
|
+
prepareEnter(session, force = false, status = "unknown") {
|
|
3761
|
+
const current = this.stateValue.get();
|
|
3762
|
+
if (!force && session === current.session && status === current.status) {
|
|
3763
|
+
return () => void 0;
|
|
3764
|
+
}
|
|
3765
|
+
this.epoch += 1;
|
|
3574
3766
|
this.readings.clear();
|
|
3767
|
+
this.awaitingRefresh.clear();
|
|
3575
3768
|
this.histories.clear();
|
|
3576
3769
|
this.historyReserved = 0;
|
|
3577
|
-
const initial = { ...NO_VARIABLES, session };
|
|
3770
|
+
const initial = { ...NO_VARIABLES, session, status };
|
|
3578
3771
|
const notifyOperations = this.operationsValue.setDeferred([]);
|
|
3579
3772
|
const notifyState = this.stateValue.setDeferred(initial);
|
|
3580
3773
|
const notifyWatches = [...this.handles].map((handle) => handle.values.setDeferred({}));
|
|
3581
3774
|
for (const pending of [...this.pending]) {
|
|
3582
|
-
if (pending.session !== session) {
|
|
3775
|
+
if (force || pending.session !== session) {
|
|
3583
3776
|
this.settle(
|
|
3584
3777
|
pending,
|
|
3585
3778
|
new WriteError(
|
|
@@ -3589,10 +3782,11 @@ var VariablesFeed = class {
|
|
|
3589
3782
|
);
|
|
3590
3783
|
}
|
|
3591
3784
|
}
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
|
|
3785
|
+
return () => {
|
|
3786
|
+
notifyOperations();
|
|
3787
|
+
notifyState();
|
|
3788
|
+
for (const notify of notifyWatches) notify();
|
|
3789
|
+
};
|
|
3596
3790
|
}
|
|
3597
3791
|
takeValues(message, touched) {
|
|
3598
3792
|
const peers = message["peers"];
|
|
@@ -3611,8 +3805,10 @@ var VariablesFeed = class {
|
|
|
3611
3805
|
const value = typeof raw === "boolean" || typeof raw === "number" && Number.isFinite(raw) ? raw : null;
|
|
3612
3806
|
const key = keyOf(peer, name);
|
|
3613
3807
|
if (this.watched !== null && !this.watched.has(key)) continue;
|
|
3808
|
+
const refreshed = this.awaitingRefresh.delete(key);
|
|
3614
3809
|
const before = this.readings.get(key);
|
|
3615
3810
|
if (before && before.sampleMs === sampleMs && before.simMs === simMs && before.paused === paused && Object.is(before.value, value)) {
|
|
3811
|
+
if (refreshed) touched.add(key);
|
|
3616
3812
|
continue;
|
|
3617
3813
|
}
|
|
3618
3814
|
this.readings.set(key, { value, sampleMs, simMs, paused });
|
|
@@ -3715,6 +3911,7 @@ var VariablesFeed = class {
|
|
|
3715
3911
|
const asked = options.timeoutMs;
|
|
3716
3912
|
const timeoutMs = asked === Infinity ? Infinity : typeof asked === "number" && asked > 0 ? Math.min(asked, TIMER_MAX_MS) : WRITE_TIMEOUT_MS;
|
|
3717
3913
|
const session = this.stateValue.get().session;
|
|
3914
|
+
const epoch = this.epoch;
|
|
3718
3915
|
if (session === null) {
|
|
3719
3916
|
return Promise.reject(
|
|
3720
3917
|
new WriteError("refused", "there is no run to write to", "not-running")
|
|
@@ -3725,10 +3922,12 @@ var VariablesFeed = class {
|
|
|
3725
3922
|
if (options.atMs !== void 0) body["at_ms"] = options.atMs;
|
|
3726
3923
|
if (options.late !== void 0) body["late"] = options.late;
|
|
3727
3924
|
return new Promise((resolve, reject) => {
|
|
3728
|
-
const pending = { session, seq: null, resolve, reject, timer: void 0 };
|
|
3925
|
+
const pending = { session, epoch, seq: null, resolve, reject, timer: void 0 };
|
|
3729
3926
|
this.pending.add(pending);
|
|
3730
3927
|
const known = () => this.operationsValue.get().find((o) => o.seq === pending.seq && o.session === pending.session);
|
|
3731
|
-
|
|
3928
|
+
const request = { method: "POST", path: "api/write", body };
|
|
3929
|
+
if (options.keepalive !== void 0) request.keepalive = options.keepalive;
|
|
3930
|
+
this.http(request, (outcome) => {
|
|
3732
3931
|
if (!this.pending.has(pending)) return;
|
|
3733
3932
|
if (!outcome.ok) {
|
|
3734
3933
|
const error = outcome.error;
|
|
@@ -3757,7 +3956,7 @@ var VariablesFeed = class {
|
|
|
3757
3956
|
);
|
|
3758
3957
|
return;
|
|
3759
3958
|
}
|
|
3760
|
-
if (answered !== pending.session || this.stateValue.get().session !== pending.session) {
|
|
3959
|
+
if (answered !== pending.session || this.stateValue.get().session !== pending.session || this.epoch !== pending.epoch) {
|
|
3761
3960
|
this.settle(
|
|
3762
3961
|
pending,
|
|
3763
3962
|
new WriteError(
|
|
@@ -3839,6 +4038,12 @@ var VariablesFeed = class {
|
|
|
3839
4038
|
}
|
|
3840
4039
|
};
|
|
3841
4040
|
}
|
|
4041
|
+
isStale(ref) {
|
|
4042
|
+
return this.awaitingRefresh.has(keyOf(ref.peer, ref.name));
|
|
4043
|
+
}
|
|
4044
|
+
runEpoch() {
|
|
4045
|
+
return this.epoch;
|
|
4046
|
+
}
|
|
3842
4047
|
/**
|
|
3843
4048
|
* Turns a requested interval into the longest of WATCH_PERIODS_MS that is not longer, kept within the server's range
|
|
3844
4049
|
* (lower and upper limit).
|
|
@@ -3878,7 +4083,12 @@ var VariablesFeed = class {
|
|
|
3878
4083
|
}
|
|
3879
4084
|
}
|
|
3880
4085
|
if (all) return;
|
|
3881
|
-
for (const key of this.readings.keys())
|
|
4086
|
+
for (const key of this.readings.keys()) {
|
|
4087
|
+
if (!seen.has(key)) {
|
|
4088
|
+
this.readings.delete(key);
|
|
4089
|
+
this.awaitingRefresh.delete(key);
|
|
4090
|
+
}
|
|
4091
|
+
}
|
|
3882
4092
|
}
|
|
3883
4093
|
/**
|
|
3884
4094
|
* Per interval, the variables to request (null: all). A variable goes to the shortest interval among the watches that
|
|
@@ -3942,6 +4152,19 @@ var VariablesFeed = class {
|
|
|
3942
4152
|
this.sync();
|
|
3943
4153
|
});
|
|
3944
4154
|
}
|
|
4155
|
+
resyncWatches() {
|
|
4156
|
+
this.syncQueued = false;
|
|
4157
|
+
const wanted = this.wanted();
|
|
4158
|
+
for (const [periodMs, bucket] of [...this.buckets]) {
|
|
4159
|
+
if (!wanted.has(periodMs)) {
|
|
4160
|
+
this.buckets.delete(periodMs);
|
|
4161
|
+
if (bucket.asked !== null) this.link.send({ type: "unwatch", id: bucket.id });
|
|
4162
|
+
} else {
|
|
4163
|
+
bucket.asked = null;
|
|
4164
|
+
}
|
|
4165
|
+
}
|
|
4166
|
+
this.sync();
|
|
4167
|
+
}
|
|
3945
4168
|
sync() {
|
|
3946
4169
|
const wanted = this.wanted();
|
|
3947
4170
|
for (const [periodMs, bucket] of [...this.buckets]) {
|
|
@@ -3971,7 +4194,7 @@ var VariableBinder = class {
|
|
|
3971
4194
|
}
|
|
3972
4195
|
sources;
|
|
3973
4196
|
entries = /* @__PURE__ */ new Map();
|
|
3974
|
-
|
|
4197
|
+
entriesKey = null;
|
|
3975
4198
|
/** Per variable, the functions to call when the write status changes (the binds listen). */
|
|
3976
4199
|
listeners = /* @__PURE__ */ new Map();
|
|
3977
4200
|
/** Lookup table of the list (rebuilt when peers change). */
|
|
@@ -4003,9 +4226,9 @@ var VariableBinder = class {
|
|
|
4003
4226
|
this.lookUp();
|
|
4004
4227
|
return this.connectedPeers.has(peer);
|
|
4005
4228
|
}
|
|
4006
|
-
/** Whether the connection between the client and the GUI server is open. */
|
|
4229
|
+
/** Whether the connection between the client and the GUI server is open and synced. */
|
|
4007
4230
|
connected() {
|
|
4008
|
-
return this.sources.connection.get() === "open";
|
|
4231
|
+
return this.sources.ready ? this.sources.ready.get() : this.sources.connection.get() === "open";
|
|
4009
4232
|
}
|
|
4010
4233
|
/**
|
|
4011
4234
|
* Why the variable cannot be written now (null if it can). Only the widget-independent reasons (Binding adds range
|
|
@@ -4090,9 +4313,11 @@ var VariableBinder = class {
|
|
|
4090
4313
|
*/
|
|
4091
4314
|
entry(ref) {
|
|
4092
4315
|
const session = this.sources.variables.state.get().session;
|
|
4093
|
-
|
|
4316
|
+
const epoch = this.sources.variables.runEpoch?.() ?? 0;
|
|
4317
|
+
const entryKey = session === null ? null : `${epoch}:${session}`;
|
|
4318
|
+
if (entryKey !== this.entriesKey) {
|
|
4094
4319
|
this.entries = /* @__PURE__ */ new Map();
|
|
4095
|
-
this.
|
|
4320
|
+
this.entriesKey = entryKey;
|
|
4096
4321
|
}
|
|
4097
4322
|
if (session === null) return void 0;
|
|
4098
4323
|
const key = keyOf2(ref);
|
|
@@ -4100,6 +4325,7 @@ var VariableBinder = class {
|
|
|
4100
4325
|
if (!entry) {
|
|
4101
4326
|
entry = {
|
|
4102
4327
|
session,
|
|
4328
|
+
epoch,
|
|
4103
4329
|
key,
|
|
4104
4330
|
ref: { peer: ref.peer, name: ref.name },
|
|
4105
4331
|
status: IDLE,
|
|
@@ -4134,7 +4360,7 @@ var VariableBinder = class {
|
|
|
4134
4360
|
}
|
|
4135
4361
|
return;
|
|
4136
4362
|
}
|
|
4137
|
-
const same = this.sources.variables.state.get().session === entry.session;
|
|
4363
|
+
const same = this.sources.variables.state.get().session === entry.session && (this.sources.variables.runEpoch?.() ?? 0) === entry.epoch;
|
|
4138
4364
|
if (same && this.block(entry.ref) === null) {
|
|
4139
4365
|
this.send(entry, next.value);
|
|
4140
4366
|
return;
|
|
@@ -4157,7 +4383,7 @@ var VariableBinder = class {
|
|
|
4157
4383
|
this.changed(entry);
|
|
4158
4384
|
};
|
|
4159
4385
|
this.changed(entry);
|
|
4160
|
-
if (this.sources.connectionEpoch() !== epoch || this.sources.session.get()?.id !== entry.session || this.sources.variables.state.get().session !== entry.session || this.block(entry.ref) !== null) {
|
|
4386
|
+
if (this.sources.connectionEpoch() !== epoch || this.sources.session.get()?.id !== entry.session || this.sources.variables.state.get().session !== entry.session || (this.sources.variables.runEpoch?.() ?? 0) !== entry.epoch || this.block(entry.ref) !== null) {
|
|
4161
4387
|
settled({ kind: "dropped", message: DROPPED_MESSAGE });
|
|
4162
4388
|
return;
|
|
4163
4389
|
}
|
|
@@ -4199,6 +4425,7 @@ var Binding = class {
|
|
|
4199
4425
|
sources.session.subscribe(refresh),
|
|
4200
4426
|
binder.onChange(ref, refresh)
|
|
4201
4427
|
);
|
|
4428
|
+
if (sources.ready) this.stops.push(sources.ready.subscribe(refresh));
|
|
4202
4429
|
this.state = {
|
|
4203
4430
|
// Built from the current state on every read (never returns a stale status, even if another subscriber was called
|
|
4204
4431
|
// first)
|
|
@@ -4234,7 +4461,8 @@ var Binding = class {
|
|
|
4234
4461
|
connected: binder.connected(),
|
|
4235
4462
|
peerConnected: binder.peerConnected(ref.peer),
|
|
4236
4463
|
// A reason while still ready means reading values keeps failing (the value is the last one read)
|
|
4237
|
-
readFailing: variables.status === "ready" && variables.reason !== null
|
|
4464
|
+
readFailing: variables.status === "ready" && variables.reason !== null,
|
|
4465
|
+
awaitingRefresh: sources.variables.isStale?.(ref) ?? false
|
|
4238
4466
|
});
|
|
4239
4467
|
const pending = binder.pending(ref);
|
|
4240
4468
|
const block = this.blockOf(info, reading, pending);
|
|
@@ -4326,7 +4554,8 @@ function clientErrorSink(client) {
|
|
|
4326
4554
|
return clientErrorSinks.get(client);
|
|
4327
4555
|
}
|
|
4328
4556
|
function buildClient(options) {
|
|
4329
|
-
const
|
|
4557
|
+
const rawToken = options.token;
|
|
4558
|
+
const token = typeof rawToken === "function" ? rawToken : () => rawToken ?? null;
|
|
4330
4559
|
const onError = options.onError ?? reportToConsole;
|
|
4331
4560
|
const origin = options.origin ?? defaultOrigin(options.baseUrl);
|
|
4332
4561
|
const http = options.http ?? fetchTransport({ baseUrl: options.baseUrl, token, origin });
|
|
@@ -4348,7 +4577,10 @@ function buildClient(options) {
|
|
|
4348
4577
|
afterGreeting: () => variablesFeed?.resume() ?? [],
|
|
4349
4578
|
onError
|
|
4350
4579
|
});
|
|
4351
|
-
feed = new SessionFeed(connection, onError,
|
|
4580
|
+
feed = new SessionFeed(connection, onError, void 0, {
|
|
4581
|
+
beforeRunSwitch: (beforeBatch, skippedBatch, current) => variablesFeed?.beforeRunSwitch(beforeBatch, skippedBatch, current),
|
|
4582
|
+
stageRunSwitch: (instance, sessionId, instanceChanged) => variablesFeed?.stageRunSwitch(instance, sessionId, instanceChanged) ?? (() => void 0)
|
|
4583
|
+
});
|
|
4352
4584
|
const session = feed;
|
|
4353
4585
|
variablesFeed = new VariablesFeed(
|
|
4354
4586
|
{
|
|
@@ -4371,6 +4603,7 @@ function buildClient(options) {
|
|
|
4371
4603
|
const binder = new VariableBinder({
|
|
4372
4604
|
variables,
|
|
4373
4605
|
connection: connection.state,
|
|
4606
|
+
ready: session.ready,
|
|
4374
4607
|
connectionEpoch: () => connection.batchEpoch(),
|
|
4375
4608
|
session: session.session,
|
|
4376
4609
|
onError
|
|
@@ -4430,6 +4663,7 @@ function buildClient(options) {
|
|
|
4430
4663
|
pause: () => time.pause(),
|
|
4431
4664
|
resume: () => time.resume(),
|
|
4432
4665
|
step: (ms) => time.step(ms),
|
|
4666
|
+
runUntil: (atMs) => time.runUntil(atMs),
|
|
4433
4667
|
setSpeed: (value) => time.setSpeed(value),
|
|
4434
4668
|
send: (command) => time.send(command)
|
|
4435
4669
|
},
|
|
@@ -4444,7 +4678,7 @@ function buildClient(options) {
|
|
|
4444
4678
|
app: app.readonly(),
|
|
4445
4679
|
limits: limits.readonly(),
|
|
4446
4680
|
connect: () => {
|
|
4447
|
-
if (
|
|
4681
|
+
if (!session.stopped) connection.connect();
|
|
4448
4682
|
},
|
|
4449
4683
|
close: () => {
|
|
4450
4684
|
connection.close();
|
|
@@ -4583,8 +4817,9 @@ function runOf(s) {
|
|
|
4583
4817
|
const outcome = runOutcome(session);
|
|
4584
4818
|
if (outcome === "crashed") return starting ? "starting" : "crashed";
|
|
4585
4819
|
if (outcome === "ended" || outcome === "finishing") return starting ? "starting" : "ended";
|
|
4586
|
-
if (outcome === "stopping" || outcome === "forcing" || s.stopConfirmed) return "stopping";
|
|
4587
4820
|
const state = session.launcherState;
|
|
4821
|
+
if (outcome === "stopping" || outcome === "forcing" || s.stopConfirmed || (state?.stop?.requests ?? 0) > 0)
|
|
4822
|
+
return "stopping";
|
|
4588
4823
|
const phase = state?.phase || session.phase;
|
|
4589
4824
|
const paused = state?.paused ?? null;
|
|
4590
4825
|
switch (phase) {
|
|
@@ -4717,7 +4952,11 @@ function composeControls(s, run) {
|
|
|
4717
4952
|
const session = s.session;
|
|
4718
4953
|
const live = isRunActive(session) && run !== "ended" && run !== "crashed";
|
|
4719
4954
|
const state = session?.launcherState ?? null;
|
|
4720
|
-
const stopsAsked = Math.max(
|
|
4955
|
+
const stopsAsked = Math.max(
|
|
4956
|
+
session?.stopRequests ?? 0,
|
|
4957
|
+
state?.stop?.requests ?? 0,
|
|
4958
|
+
s.stopConfirmed ? 1 : 0
|
|
4959
|
+
);
|
|
4721
4960
|
let start;
|
|
4722
4961
|
if (link === "rejected" || link === "incompatible") start = control(false, down);
|
|
4723
4962
|
else if (s.busy.has("start")) start = control(false, busyReason("start"));
|
|
@@ -4734,7 +4973,8 @@ function composeControls(s, run) {
|
|
|
4734
4973
|
reason("already-running", "a run is going: stop it before you start another")
|
|
4735
4974
|
) : control(true);
|
|
4736
4975
|
const serverStop = s.allowed?.stop;
|
|
4737
|
-
const
|
|
4976
|
+
const serverForce = s.allowed?.force;
|
|
4977
|
+
const stoppable = s.busy.has("start") || live || run === "starting" || serverStop?.ok === true || serverForce?.ok === true;
|
|
4738
4978
|
let stop;
|
|
4739
4979
|
if (!s.busy.has("start") && s.allowed?.start.reason === "starting")
|
|
4740
4980
|
stop = control(false, reason("starting", "wait until the new run can be identified"));
|
|
@@ -4750,7 +4990,6 @@ function composeControls(s, run) {
|
|
|
4750
4990
|
reason("already-stopping", "a stop has been asked for: wait, or force the stop")
|
|
4751
4991
|
);
|
|
4752
4992
|
else stop = control(true);
|
|
4753
|
-
const serverForce = s.allowed?.force;
|
|
4754
4993
|
let force;
|
|
4755
4994
|
if (s.busy.has("start") || s.allowed?.start.reason === "starting")
|
|
4756
4995
|
force = control(false, reason("starting", "wait until the new run can be identified"));
|
|
@@ -4861,6 +5100,7 @@ var INTENT_FIELDS = /* @__PURE__ */ new Set([
|
|
|
4861
5100
|
"enable",
|
|
4862
5101
|
"manual",
|
|
4863
5102
|
"scenario",
|
|
5103
|
+
"after_scenario",
|
|
4864
5104
|
"variant",
|
|
4865
5105
|
"params",
|
|
4866
5106
|
"speed",
|
|
@@ -5041,6 +5281,7 @@ var FrontActions = class {
|
|
|
5041
5281
|
...intent.enable ? { enable: intent.enable } : {},
|
|
5042
5282
|
...intent.manual ? { manual: intent.manual } : {},
|
|
5043
5283
|
...intent.scenario !== void 0 ? { scenario: intent.scenario } : {},
|
|
5284
|
+
...intent.after_scenario !== void 0 ? { after_scenario: intent.after_scenario } : {},
|
|
5044
5285
|
...intent.variant !== void 0 ? { variant: intent.variant } : {},
|
|
5045
5286
|
...intent.params ? { params: intent.params } : {},
|
|
5046
5287
|
...intent.speed !== void 0 ? { speed: intent.speed } : {},
|
|
@@ -5577,7 +5818,11 @@ function makeVariable(low, ref, refuse, launcher) {
|
|
|
5577
5818
|
let count = 0;
|
|
5578
5819
|
let stops = [];
|
|
5579
5820
|
const refresh = () => {
|
|
5580
|
-
if (binding)
|
|
5821
|
+
if (!binding) return null;
|
|
5822
|
+
const next = viewOf(binding.state.get(), track.get(), launcher.get());
|
|
5823
|
+
if (!binding) return next;
|
|
5824
|
+
view.set(next);
|
|
5825
|
+
return view.get() ?? next;
|
|
5581
5826
|
};
|
|
5582
5827
|
let peeked = null;
|
|
5583
5828
|
const peek = () => {
|
|
@@ -5591,10 +5836,7 @@ function makeVariable(low, ref, refuse, launcher) {
|
|
|
5591
5836
|
}
|
|
5592
5837
|
};
|
|
5593
5838
|
const readable = {
|
|
5594
|
-
get: () =>
|
|
5595
|
-
if (!binding) return peek();
|
|
5596
|
-
return view.get();
|
|
5597
|
-
},
|
|
5839
|
+
get: () => refresh() ?? peek(),
|
|
5598
5840
|
subscribe: (listener) => {
|
|
5599
5841
|
if (count++ === 0) {
|
|
5600
5842
|
binding = low.variables.bind(ref);
|
|
@@ -5624,17 +5866,23 @@ function makeVariable(low, ref, refuse, launcher) {
|
|
|
5624
5866
|
return {
|
|
5625
5867
|
get: readable.get,
|
|
5626
5868
|
subscribe: readable.subscribe,
|
|
5627
|
-
write: (value) => {
|
|
5869
|
+
write: (value, options) => {
|
|
5628
5870
|
const own = refuse();
|
|
5629
5871
|
if (own) return Promise.reject(own);
|
|
5630
5872
|
track.set({ writing: true, problem: null });
|
|
5631
|
-
return low.variables.write(
|
|
5873
|
+
return low.variables.write(
|
|
5874
|
+
{ [ref.peer]: { [ref.name]: value } },
|
|
5875
|
+
options?.keepalive !== void 0 ? { keepalive: options.keepalive } : void 0
|
|
5876
|
+
).then(
|
|
5632
5877
|
() => {
|
|
5633
5878
|
track.set({ writing: false, problem: null });
|
|
5634
5879
|
},
|
|
5635
5880
|
(error) => {
|
|
5636
5881
|
const failure = writeFailure(error);
|
|
5637
|
-
track.set({
|
|
5882
|
+
track.set({
|
|
5883
|
+
writing: false,
|
|
5884
|
+
problem: { code: failure.code, message: failure.message }
|
|
5885
|
+
});
|
|
5638
5886
|
throw failure;
|
|
5639
5887
|
}
|
|
5640
5888
|
);
|
|
@@ -5765,6 +6013,8 @@ function makeFront(options, onClose) {
|
|
|
5765
6013
|
file: view.file,
|
|
5766
6014
|
name: view.name,
|
|
5767
6015
|
status: view.status,
|
|
6016
|
+
handed_over: view.handedOver,
|
|
6017
|
+
over_at_ms: view.overAtMs,
|
|
5768
6018
|
steps: view.steps,
|
|
5769
6019
|
timeline_url: view.timelineUrl
|
|
5770
6020
|
} : null;
|
|
@@ -5906,15 +6156,14 @@ function createFront(options) {
|
|
|
5906
6156
|
}
|
|
5907
6157
|
function pageOptions() {
|
|
5908
6158
|
const page = globalThis.window;
|
|
5909
|
-
|
|
5910
|
-
if (!page || token === null) {
|
|
6159
|
+
if (!page) {
|
|
5911
6160
|
throw new ActionError(
|
|
5912
6161
|
"no-token",
|
|
5913
|
-
"connect() without options works in a page that the GUI server served
|
|
6162
|
+
"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)",
|
|
5914
6163
|
"refused"
|
|
5915
6164
|
);
|
|
5916
6165
|
}
|
|
5917
|
-
return { base_url: new URL("/", page.location.href).href, token };
|
|
6166
|
+
return { base_url: new URL("/", page.location.href).href, token: takeToken(page) };
|
|
5918
6167
|
}
|
|
5919
6168
|
function connect(options) {
|
|
5920
6169
|
if (options) return open(options, () => void 0);
|
|
@@ -6072,7 +6321,7 @@ function createVariableEditor(front, ref) {
|
|
|
6072
6321
|
canWrite: !closed && client.session.ready.get() && current !== null && current.run_id === client.variables.state.get().session && view.can_write && bound.block === null && !waiting
|
|
6073
6322
|
};
|
|
6074
6323
|
};
|
|
6075
|
-
const state = new Writable(read2(),
|
|
6324
|
+
const state = new Writable(read2(), sameData, clientErrorSink(client));
|
|
6076
6325
|
const reset = () => {
|
|
6077
6326
|
clearTimeout(timer);
|
|
6078
6327
|
timer = void 0;
|
|
@@ -6081,10 +6330,11 @@ function createVariableEditor(front, ref) {
|
|
|
6081
6330
|
};
|
|
6082
6331
|
const refresh = () => {
|
|
6083
6332
|
if (closed) return;
|
|
6084
|
-
const current = client.session.currentTarget();
|
|
6085
6333
|
const bound = binding.state.get();
|
|
6334
|
+
if (closed) return;
|
|
6086
6335
|
const shown = read2(bound);
|
|
6087
6336
|
if (closed) return;
|
|
6337
|
+
const current = client.session.currentTarget();
|
|
6088
6338
|
if (current?.instance !== target?.instance || current?.run_id !== target?.run_id || !shown.view.can_write) {
|
|
6089
6339
|
reset();
|
|
6090
6340
|
} else if (awaiting !== null && shown.view.value === awaiting) {
|
|
@@ -6102,13 +6352,19 @@ function createVariableEditor(front, ref) {
|
|
|
6102
6352
|
reset();
|
|
6103
6353
|
}
|
|
6104
6354
|
target = current;
|
|
6105
|
-
state.set(read2());
|
|
6355
|
+
if (!closed) state.set(read2());
|
|
6106
6356
|
};
|
|
6107
6357
|
const unsubscribe = binding.state.subscribe(refresh);
|
|
6108
6358
|
const unsubscribeSession = client.session.session.subscribe(refresh);
|
|
6109
6359
|
const unsubscribeReady = client.session.ready.subscribe(refresh);
|
|
6110
6360
|
return {
|
|
6111
|
-
state:
|
|
6361
|
+
state: {
|
|
6362
|
+
get: () => {
|
|
6363
|
+
refresh();
|
|
6364
|
+
return state.get();
|
|
6365
|
+
},
|
|
6366
|
+
subscribe: (listener) => state.subscribe(listener)
|
|
6367
|
+
},
|
|
6112
6368
|
write(value) {
|
|
6113
6369
|
const { canWrite, info: info2 } = read2();
|
|
6114
6370
|
if (!canWrite || !info2) return false;
|
|
@@ -6177,6 +6433,8 @@ export {
|
|
|
6177
6433
|
isLauncherAlive,
|
|
6178
6434
|
isLauncherFinishing,
|
|
6179
6435
|
isRunActive,
|
|
6436
|
+
isScenarioHandedOver,
|
|
6437
|
+
isScenarioRunning,
|
|
6180
6438
|
isSessionRunning,
|
|
6181
6439
|
isWriteError,
|
|
6182
6440
|
launcherAnswer,
|