@vehicle-sil/gui-client 0.4.0 → 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 +67 -53
- package/README.md +67 -53
- package/dist/index.js +330 -78
- package/package.json +1 -1
- package/types/client.d.ts +11 -3
- package/types/front-types.d.ts +8 -2
- package/types/http.d.ts +2 -0
- 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
|
};
|
|
@@ -1812,6 +1828,7 @@ function fetchTransport(options) {
|
|
|
1812
1828
|
redirect: "error",
|
|
1813
1829
|
signal: abort.signal
|
|
1814
1830
|
};
|
|
1831
|
+
if (request.keepalive !== void 0) init.keepalive = request.keepalive;
|
|
1815
1832
|
if (request.method === "POST") init.body = JSON.stringify(request.body ?? {});
|
|
1816
1833
|
const fail = (error) => done({
|
|
1817
1834
|
ok: false,
|
|
@@ -1883,15 +1900,18 @@ function commandView(command, seq) {
|
|
|
1883
1900
|
seq
|
|
1884
1901
|
};
|
|
1885
1902
|
}
|
|
1886
|
-
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");
|
|
1887
1906
|
return {
|
|
1888
1907
|
file: summary.file,
|
|
1889
1908
|
name: summary.name,
|
|
1890
1909
|
stepCount: summary.step_count,
|
|
1891
1910
|
steps: summary.steps,
|
|
1892
1911
|
stepsOmitted: summary.steps_omitted,
|
|
1893
|
-
status: summary.status,
|
|
1894
|
-
|
|
1912
|
+
status: handedOver ? summary.status ?? "passed" : summary.status,
|
|
1913
|
+
handedOver,
|
|
1914
|
+
overAtMs: summary.over_at_ms ?? (handedOver ? launcherState?.scenario_over_at_ms ?? null : null),
|
|
1895
1915
|
timelineUrl: summary.timeline_url
|
|
1896
1916
|
};
|
|
1897
1917
|
}
|
|
@@ -1918,6 +1938,18 @@ function isLauncherAlive(session) {
|
|
|
1918
1938
|
function isHolding(session) {
|
|
1919
1939
|
return isRunActive(session) && session.launcherState?.holding === true;
|
|
1920
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
|
+
}
|
|
1921
1953
|
function runOutcome(session) {
|
|
1922
1954
|
if (isRunActive(session)) {
|
|
1923
1955
|
if (session.result) return "finishing";
|
|
@@ -1968,6 +2000,7 @@ function addDropped(session, dropped) {
|
|
|
1968
2000
|
const mark = session.droppedMarks + 1;
|
|
1969
2001
|
const gaps = counts.map(([source, count]) => ({
|
|
1970
2002
|
seq: session.lastSeq + 0.5,
|
|
2003
|
+
tMs: null,
|
|
1971
2004
|
key: `dropped ${mark} ${source}`,
|
|
1972
2005
|
source,
|
|
1973
2006
|
line: "",
|
|
@@ -2029,11 +2062,19 @@ function applySummary(session, summary) {
|
|
|
2029
2062
|
...participants,
|
|
2030
2063
|
...session.participants.filter((p) => !participants.some((current) => current.name === p.name))
|
|
2031
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");
|
|
2032
2069
|
let scenario = summary.scenario ? {
|
|
2033
|
-
...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),
|
|
2034
2074
|
timelineUrl: summary.scenario.timeline_url ?? session.scenario?.timelineUrl ?? null
|
|
2035
2075
|
} : session.scenario;
|
|
2036
2076
|
if (scenario && result?.scenario) {
|
|
2077
|
+
const resultHandedOver = handedOver && result.scenario.status === "passed";
|
|
2037
2078
|
scenario = {
|
|
2038
2079
|
...scenario,
|
|
2039
2080
|
name: result.scenario.name ?? scenario.name,
|
|
@@ -2041,7 +2082,8 @@ function applySummary(session, summary) {
|
|
|
2041
2082
|
steps: result.scenario.steps,
|
|
2042
2083
|
stepsOmitted: 0,
|
|
2043
2084
|
status: result.scenario.status,
|
|
2044
|
-
|
|
2085
|
+
handedOver: resultHandedOver,
|
|
2086
|
+
overAtMs: result.scenario.over_at_ms ?? (resultHandedOver ? scenario.overAtMs : null)
|
|
2045
2087
|
};
|
|
2046
2088
|
}
|
|
2047
2089
|
const problems = summary.problems.slice(0, MAX_PROBLEMS);
|
|
@@ -2064,7 +2106,7 @@ function applySummary(session, summary) {
|
|
|
2064
2106
|
timeOmittedFields: summary.sim_ms === null ? session.timeOmittedFields : summary.time_omitted_fields,
|
|
2065
2107
|
time: summary.time ? timeView(summary.time) : session.time,
|
|
2066
2108
|
lastCommand: summary.last_command ? commandView(summary.last_command, summary.last_command.seq ?? -1) : session.lastCommand,
|
|
2067
|
-
launcherState
|
|
2109
|
+
launcherState,
|
|
2068
2110
|
findings: summary.findings.slice(0, MAX_FINDINGS),
|
|
2069
2111
|
result,
|
|
2070
2112
|
check,
|
|
@@ -2208,13 +2250,20 @@ function applyOne(session, event, logs) {
|
|
|
2208
2250
|
};
|
|
2209
2251
|
}
|
|
2210
2252
|
case "log":
|
|
2211
|
-
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
|
+
});
|
|
2212
2260
|
return next;
|
|
2213
2261
|
case "log_dropped":
|
|
2214
2262
|
for (const [source, count] of Object.entries(event.sources)) {
|
|
2215
2263
|
if (count > 0) {
|
|
2216
2264
|
logs.push({
|
|
2217
2265
|
seq: event.seq,
|
|
2266
|
+
tMs: event.t_ms,
|
|
2218
2267
|
key: `${event.seq} ${source}`,
|
|
2219
2268
|
source,
|
|
2220
2269
|
line: "",
|
|
@@ -2232,25 +2281,46 @@ function applyOne(session, event, logs) {
|
|
|
2232
2281
|
return { ...next, simMs: event.sim_ms, timeOmittedFields: [], time: timeView(event) };
|
|
2233
2282
|
case "command":
|
|
2234
2283
|
return { ...next, lastCommand: commandView(event, event.seq) };
|
|
2235
|
-
case "state":
|
|
2236
|
-
|
|
2237
|
-
|
|
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 };
|
|
2238
2290
|
return {
|
|
2239
2291
|
...next,
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
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 {
|
|
2246
2305
|
...next.scenario,
|
|
2247
2306
|
name: event.result.scenario.name,
|
|
2248
2307
|
stepCount: next.scenario.stepCount ?? event.result.scenario.steps.length,
|
|
2249
2308
|
steps: event.result.scenario.steps,
|
|
2250
2309
|
status: event.result.scenario.status,
|
|
2251
|
-
|
|
2252
|
-
|
|
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
|
|
2253
2322
|
};
|
|
2323
|
+
}
|
|
2254
2324
|
default:
|
|
2255
2325
|
return next;
|
|
2256
2326
|
}
|
|
@@ -2573,12 +2643,13 @@ function sameRunTarget(left, right) {
|
|
|
2573
2643
|
return left !== null && right !== null && left.run_id === right.run_id && left.instance === right.instance;
|
|
2574
2644
|
}
|
|
2575
2645
|
var SessionFeed = class {
|
|
2576
|
-
constructor(connection, onError = rethrowLater, onInstance) {
|
|
2646
|
+
constructor(connection, onError = rethrowLater, onInstance, hooks) {
|
|
2577
2647
|
this.connection = connection;
|
|
2578
2648
|
this.onError = onError;
|
|
2579
2649
|
this.onInstance = onInstance;
|
|
2650
|
+
this.hooks = hooks;
|
|
2580
2651
|
this.current = new Writable(null, Object.is, onError);
|
|
2581
|
-
this.
|
|
2652
|
+
this.readyValue = new Writable(false, Object.is, onError);
|
|
2582
2653
|
this.allowedValue = new Writable(null, Object.is, onError);
|
|
2583
2654
|
this.allowed = this.allowedValue.readonly();
|
|
2584
2655
|
this.runtimeValue = new Writable(null, Object.is, onError);
|
|
@@ -2592,12 +2663,10 @@ var SessionFeed = class {
|
|
|
2592
2663
|
this.notices = this.noticeList.readonly();
|
|
2593
2664
|
this.rejected = this.rejectedValue.readonly();
|
|
2594
2665
|
this.incompatible = this.incompatibleValue.readonly();
|
|
2595
|
-
this.ready =
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
onError
|
|
2600
|
-
);
|
|
2666
|
+
this.ready = this.readyValue.readonly();
|
|
2667
|
+
connection.state.subscribe((state) => {
|
|
2668
|
+
this.readyValue.set(state === "open" && this.syncedFlag);
|
|
2669
|
+
});
|
|
2601
2670
|
connection.onBatch((batch) => this.receive(batch));
|
|
2602
2671
|
connection.onUnreadable(
|
|
2603
2672
|
(text3) => this.notify(`unreadable message: not JSON (connecting again): ${text3.slice(0, 80)}`)
|
|
@@ -2606,13 +2675,15 @@ var SessionFeed = class {
|
|
|
2606
2675
|
connection;
|
|
2607
2676
|
onError;
|
|
2608
2677
|
onInstance;
|
|
2678
|
+
hooks;
|
|
2609
2679
|
rawListeners = /* @__PURE__ */ new Set();
|
|
2610
2680
|
instanceId = null;
|
|
2611
2681
|
lastStreamSeq = -1;
|
|
2612
2682
|
resyncing = false;
|
|
2683
|
+
syncedFlag = false;
|
|
2613
2684
|
stopTarget = null;
|
|
2614
2685
|
current;
|
|
2615
|
-
|
|
2686
|
+
readyValue;
|
|
2616
2687
|
allowedValue;
|
|
2617
2688
|
runtimeValue;
|
|
2618
2689
|
receivedAt;
|
|
@@ -2634,13 +2705,17 @@ var SessionFeed = class {
|
|
|
2634
2705
|
get stopped() {
|
|
2635
2706
|
return this.stoppedFlag;
|
|
2636
2707
|
}
|
|
2708
|
+
setSyncedDeferred(value) {
|
|
2709
|
+
this.syncedFlag = value;
|
|
2710
|
+
return this.readyValue.setDeferred(this.connection.state.get() === "open" && value);
|
|
2711
|
+
}
|
|
2637
2712
|
/**
|
|
2638
2713
|
* Fields to add to the authentication message: where in the stream it holds the server should resend from. Called
|
|
2639
2714
|
* on every connect (after the call, the copy is not in sync until hello and the resent events have arrived). Used
|
|
2640
2715
|
* only inside the library.
|
|
2641
2716
|
*/
|
|
2642
2717
|
resumeFields() {
|
|
2643
|
-
this.
|
|
2718
|
+
this.setSyncedDeferred(false)();
|
|
2644
2719
|
const session = this.current.get();
|
|
2645
2720
|
if (this.instanceId === null || session === null || this.lastStreamSeq < 0) return {};
|
|
2646
2721
|
return {
|
|
@@ -2725,7 +2800,7 @@ var SessionFeed = class {
|
|
|
2725
2800
|
originInstance = instance;
|
|
2726
2801
|
});
|
|
2727
2802
|
if (!currentOrigin()) return;
|
|
2728
|
-
if (stop === "lost" || stop === "incompatible") this.
|
|
2803
|
+
if (stop === "lost" || stop === "incompatible") this.setSyncedDeferred(false)();
|
|
2729
2804
|
if (stop === "unauthorized") this.rejectedValue.set(true);
|
|
2730
2805
|
if (incompatible !== null) this.incompatibleValue.set(incompatible);
|
|
2731
2806
|
}
|
|
@@ -2740,8 +2815,11 @@ var SessionFeed = class {
|
|
|
2740
2815
|
const notices = [];
|
|
2741
2816
|
const selectedBatch = [];
|
|
2742
2817
|
const selectedRaw = [];
|
|
2818
|
+
let firstSwitchRawIndex = -1;
|
|
2819
|
+
let lastSwitchRawIndex = -1;
|
|
2743
2820
|
let applied = false;
|
|
2744
|
-
let synced = this.
|
|
2821
|
+
let synced = this.syncedFlag;
|
|
2822
|
+
let syncReset = false;
|
|
2745
2823
|
let allowedNow = this.allowedValue.get();
|
|
2746
2824
|
let runtimeNow = this.runtimeValue.get();
|
|
2747
2825
|
const takeAllowed = (incoming) => {
|
|
@@ -2770,6 +2848,7 @@ var SessionFeed = class {
|
|
|
2770
2848
|
switch (message.type) {
|
|
2771
2849
|
case "hello": {
|
|
2772
2850
|
synced = false;
|
|
2851
|
+
syncReset = true;
|
|
2773
2852
|
replaying = true;
|
|
2774
2853
|
const { session: summary, replay } = message;
|
|
2775
2854
|
const sameInstance = instance !== null && instance === message.instance;
|
|
@@ -2791,6 +2870,8 @@ var SessionFeed = class {
|
|
|
2791
2870
|
} else if (!sameInstance) {
|
|
2792
2871
|
runtimeNow = null;
|
|
2793
2872
|
}
|
|
2873
|
+
const prevId = session?.id ?? null;
|
|
2874
|
+
const switchedInstance = instance !== null && instance !== message.instance;
|
|
2794
2875
|
instance = message.instance;
|
|
2795
2876
|
if (!summary) {
|
|
2796
2877
|
session = null;
|
|
@@ -2799,6 +2880,10 @@ var SessionFeed = class {
|
|
|
2799
2880
|
} else {
|
|
2800
2881
|
session = sessionFromSummary(summary);
|
|
2801
2882
|
}
|
|
2883
|
+
if (switchedInstance || (session?.id ?? null) !== prevId) {
|
|
2884
|
+
if (firstSwitchRawIndex < 0) firstSwitchRawIndex = selectedRaw.length;
|
|
2885
|
+
lastSwitchRawIndex = selectedRaw.length;
|
|
2886
|
+
}
|
|
2802
2887
|
selectedBatch.push(message);
|
|
2803
2888
|
selectedRaw.push(rawMessage);
|
|
2804
2889
|
break;
|
|
@@ -2837,15 +2922,21 @@ var SessionFeed = class {
|
|
|
2837
2922
|
selectedBatch.push(message);
|
|
2838
2923
|
selectedRaw.push(rawMessage);
|
|
2839
2924
|
break;
|
|
2840
|
-
case "session":
|
|
2925
|
+
case "session": {
|
|
2926
|
+
const prevId = session?.id ?? null;
|
|
2841
2927
|
takeAllowed(message.session.allowed);
|
|
2842
2928
|
session = session?.id === message.session.id ? applySummary(session, message.session) : sessionFromSummary(message.session);
|
|
2843
2929
|
if (typeof message.stream_seq !== "number" && message.session.last_seq !== null) {
|
|
2844
2930
|
streamSeq = Math.max(streamSeq, message.session.last_seq);
|
|
2845
2931
|
}
|
|
2932
|
+
if (session.id !== prevId) {
|
|
2933
|
+
if (firstSwitchRawIndex < 0) firstSwitchRawIndex = selectedRaw.length;
|
|
2934
|
+
lastSwitchRawIndex = selectedRaw.length;
|
|
2935
|
+
}
|
|
2846
2936
|
selectedBatch.push(message);
|
|
2847
2937
|
selectedRaw.push(rawMessage);
|
|
2848
2938
|
break;
|
|
2939
|
+
}
|
|
2849
2940
|
case "event":
|
|
2850
2941
|
if (session?.id === message.run_id) {
|
|
2851
2942
|
events.push(message.event);
|
|
@@ -2875,13 +2966,14 @@ var SessionFeed = class {
|
|
|
2875
2966
|
break;
|
|
2876
2967
|
case "resync":
|
|
2877
2968
|
synced = false;
|
|
2969
|
+
syncReset = true;
|
|
2878
2970
|
replaying = true;
|
|
2879
2971
|
resyncing = true;
|
|
2880
2972
|
selectedBatch.push(message);
|
|
2881
2973
|
selectedRaw.push(rawMessage);
|
|
2882
2974
|
break;
|
|
2883
2975
|
default:
|
|
2884
|
-
if (
|
|
2976
|
+
if ("run_id" in message && message.run_id !== (session?.id ?? null)) {
|
|
2885
2977
|
continue;
|
|
2886
2978
|
}
|
|
2887
2979
|
selectedBatch.push(message);
|
|
@@ -2893,6 +2985,16 @@ var SessionFeed = class {
|
|
|
2893
2985
|
const stale = (session?.staleEvents ?? 0) - (before?.id === session?.id ? before?.staleEvents ?? 0 : 0);
|
|
2894
2986
|
if (!currentOrigin()) return;
|
|
2895
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
|
+
}
|
|
2896
2998
|
this.instanceId = instance;
|
|
2897
2999
|
this.lastStreamSeq = streamSeq;
|
|
2898
3000
|
this.resyncing = resyncing;
|
|
@@ -2900,18 +3002,29 @@ var SessionFeed = class {
|
|
|
2900
3002
|
this.stopTarget = session && instance ? { run_id: session.id, instance } : null;
|
|
2901
3003
|
const sessionId = session?.id ?? null;
|
|
2902
3004
|
const sameStream = () => currentOrigin() && this.instanceId === instance && (this.current.get()?.id ?? null) === sessionId;
|
|
3005
|
+
const instanceChanged = instance !== null && beforeInstance !== null && instance !== beforeInstance;
|
|
2903
3006
|
const notifySession = this.current.setDeferred(session);
|
|
2904
3007
|
const notifyAllowed = this.allowedValue.setDeferred(allowedNow);
|
|
2905
3008
|
const notifyRuntime = this.runtimeValue.setDeferred(runtimeNow);
|
|
2906
|
-
const
|
|
2907
|
-
|
|
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) {
|
|
2908
3020
|
this.onInstance?.(instance);
|
|
2909
3021
|
if (!sameStream()) return;
|
|
2910
3022
|
}
|
|
2911
3023
|
notifySession();
|
|
2912
3024
|
notifyAllowed();
|
|
2913
3025
|
notifyRuntime();
|
|
2914
|
-
|
|
3026
|
+
notifyUnsynced?.();
|
|
3027
|
+
notifyVarSwitch?.();
|
|
2915
3028
|
if (!sameStream()) return;
|
|
2916
3029
|
for (const notice of notices) {
|
|
2917
3030
|
this.notify(notice);
|
|
@@ -2921,10 +3034,14 @@ var SessionFeed = class {
|
|
|
2921
3034
|
if (!sameStream()) return;
|
|
2922
3035
|
if (stale > 0) this.notify(STALE_EVENTS_NOTICE, stale);
|
|
2923
3036
|
if (!sameStream()) return;
|
|
2924
|
-
|
|
2925
|
-
|
|
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);
|
|
2926
3040
|
}
|
|
2927
3041
|
if (!sameStream()) return;
|
|
3042
|
+
const notifySynced = this.setSyncedDeferred(synced);
|
|
3043
|
+
notifySynced();
|
|
3044
|
+
if (!sameStream()) return;
|
|
2928
3045
|
if (selectedBatch.length > 0) {
|
|
2929
3046
|
callEach(this.messageListeners, [selectedBatch], this.onError, sameStream);
|
|
2930
3047
|
}
|
|
@@ -2985,6 +3102,12 @@ var TimeControl = class {
|
|
|
2985
3102
|
step(ms) {
|
|
2986
3103
|
return this.send({ command: "step", ms });
|
|
2987
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
|
+
}
|
|
2988
3111
|
/** Changes the speed (a pause stays in effect). */
|
|
2989
3112
|
setSpeed(value) {
|
|
2990
3113
|
return this.send({ command: "speed", value });
|
|
@@ -3105,6 +3228,7 @@ function valueCondition(input) {
|
|
|
3105
3228
|
if (status !== "ready") return { kind: "stale", reading, why: "reconnecting" };
|
|
3106
3229
|
if (!input.peerConnected) return { kind: "stale", reading, why: "peer" };
|
|
3107
3230
|
if (input.readFailing) return { kind: "stale", reading, why: "reading" };
|
|
3231
|
+
if (input.awaitingRefresh) return { kind: "stale", reading, why: "connection" };
|
|
3108
3232
|
return reading.paused ? { kind: "paused", reading } : { kind: "live", reading };
|
|
3109
3233
|
}
|
|
3110
3234
|
function sameCondition(a, b) {
|
|
@@ -3344,11 +3468,14 @@ var VariablesFeed = class {
|
|
|
3344
3468
|
onError;
|
|
3345
3469
|
limits;
|
|
3346
3470
|
instanceId = null;
|
|
3471
|
+
epoch = 0;
|
|
3347
3472
|
stateValue;
|
|
3348
3473
|
operationsValue;
|
|
3349
3474
|
handles = /* @__PURE__ */ new Set();
|
|
3350
3475
|
buckets = /* @__PURE__ */ new Map();
|
|
3351
3476
|
readings = /* @__PURE__ */ new Map();
|
|
3477
|
+
/** Cached keys kept across a reconnect until a post-reconnect `values` sample arrives. */
|
|
3478
|
+
awaitingRefresh = /* @__PURE__ */ new Set();
|
|
3352
3479
|
histories = /* @__PURE__ */ new Map();
|
|
3353
3480
|
pending = /* @__PURE__ */ new Set();
|
|
3354
3481
|
/** Variables someone watches (null: a watch observes all). */
|
|
@@ -3369,6 +3496,7 @@ var VariablesFeed = class {
|
|
|
3369
3496
|
/** Messages sent right after connecting (after authentication): all current subscriptions. */
|
|
3370
3497
|
resume() {
|
|
3371
3498
|
this.syncQueued = false;
|
|
3499
|
+
for (const key of this.readings.keys()) this.awaitingRefresh.add(key);
|
|
3372
3500
|
const messages = [];
|
|
3373
3501
|
for (const [periodMs, wanted] of this.wanted()) {
|
|
3374
3502
|
const bucket = this.bucket(periodMs);
|
|
@@ -3398,6 +3526,48 @@ var VariablesFeed = class {
|
|
|
3398
3526
|
this.instanceId = instance;
|
|
3399
3527
|
if (hadInstance) this.enter(null, true);
|
|
3400
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
|
+
}
|
|
3401
3571
|
receive(batch, current = () => true) {
|
|
3402
3572
|
const touched = /* @__PURE__ */ new Set();
|
|
3403
3573
|
let touchedAll = false;
|
|
@@ -3412,6 +3582,14 @@ var VariablesFeed = class {
|
|
|
3412
3582
|
if (!current()) return;
|
|
3413
3583
|
if (!isObject(message)) continue;
|
|
3414
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
|
+
}
|
|
3415
3593
|
case "hello": {
|
|
3416
3594
|
flush();
|
|
3417
3595
|
if (!current()) return;
|
|
@@ -3445,6 +3623,9 @@ var VariablesFeed = class {
|
|
|
3445
3623
|
notifyOperations = this.prepareOperations(currentOps, listed, sameIdentity);
|
|
3446
3624
|
}
|
|
3447
3625
|
const next = readVariables2(variables, id);
|
|
3626
|
+
if (next.status === "ended" || next.status === "off" || next.status === "failed") {
|
|
3627
|
+
this.awaitingRefresh.clear();
|
|
3628
|
+
}
|
|
3448
3629
|
this.stateValue.set(next);
|
|
3449
3630
|
notifyOperations();
|
|
3450
3631
|
if (sameIdentity() && this.stateValue.get() === next && isObject(variables) && Array.isArray(variables["operations"])) {
|
|
@@ -3458,9 +3639,7 @@ var VariablesFeed = class {
|
|
|
3458
3639
|
}
|
|
3459
3640
|
}
|
|
3460
3641
|
} else {
|
|
3461
|
-
this.enter(null);
|
|
3462
|
-
if (!current()) return;
|
|
3463
|
-
this.stateValue.set({ ...NO_VARIABLES, status: "off" });
|
|
3642
|
+
this.enter(null, false, "off");
|
|
3464
3643
|
}
|
|
3465
3644
|
touchedAll = true;
|
|
3466
3645
|
break;
|
|
@@ -3493,7 +3672,11 @@ var VariablesFeed = class {
|
|
|
3493
3672
|
touchedAll = true;
|
|
3494
3673
|
}
|
|
3495
3674
|
}
|
|
3496
|
-
|
|
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);
|
|
3497
3680
|
break;
|
|
3498
3681
|
}
|
|
3499
3682
|
case "values": {
|
|
@@ -3570,17 +3753,26 @@ var VariablesFeed = class {
|
|
|
3570
3753
|
* are dropped with their memory, so they do not keep growing as the variables change from run to run). Writes
|
|
3571
3754
|
* waiting for the previous run's result are failed, since the result will not come.
|
|
3572
3755
|
*/
|
|
3573
|
-
enter(session, force = false) {
|
|
3574
|
-
|
|
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;
|
|
3575
3766
|
this.readings.clear();
|
|
3767
|
+
this.awaitingRefresh.clear();
|
|
3576
3768
|
this.histories.clear();
|
|
3577
3769
|
this.historyReserved = 0;
|
|
3578
|
-
const initial = { ...NO_VARIABLES, session };
|
|
3770
|
+
const initial = { ...NO_VARIABLES, session, status };
|
|
3579
3771
|
const notifyOperations = this.operationsValue.setDeferred([]);
|
|
3580
3772
|
const notifyState = this.stateValue.setDeferred(initial);
|
|
3581
3773
|
const notifyWatches = [...this.handles].map((handle) => handle.values.setDeferred({}));
|
|
3582
3774
|
for (const pending of [...this.pending]) {
|
|
3583
|
-
if (pending.session !== session) {
|
|
3775
|
+
if (force || pending.session !== session) {
|
|
3584
3776
|
this.settle(
|
|
3585
3777
|
pending,
|
|
3586
3778
|
new WriteError(
|
|
@@ -3590,10 +3782,11 @@ var VariablesFeed = class {
|
|
|
3590
3782
|
);
|
|
3591
3783
|
}
|
|
3592
3784
|
}
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3785
|
+
return () => {
|
|
3786
|
+
notifyOperations();
|
|
3787
|
+
notifyState();
|
|
3788
|
+
for (const notify of notifyWatches) notify();
|
|
3789
|
+
};
|
|
3597
3790
|
}
|
|
3598
3791
|
takeValues(message, touched) {
|
|
3599
3792
|
const peers = message["peers"];
|
|
@@ -3612,8 +3805,10 @@ var VariablesFeed = class {
|
|
|
3612
3805
|
const value = typeof raw === "boolean" || typeof raw === "number" && Number.isFinite(raw) ? raw : null;
|
|
3613
3806
|
const key = keyOf(peer, name);
|
|
3614
3807
|
if (this.watched !== null && !this.watched.has(key)) continue;
|
|
3808
|
+
const refreshed = this.awaitingRefresh.delete(key);
|
|
3615
3809
|
const before = this.readings.get(key);
|
|
3616
3810
|
if (before && before.sampleMs === sampleMs && before.simMs === simMs && before.paused === paused && Object.is(before.value, value)) {
|
|
3811
|
+
if (refreshed) touched.add(key);
|
|
3617
3812
|
continue;
|
|
3618
3813
|
}
|
|
3619
3814
|
this.readings.set(key, { value, sampleMs, simMs, paused });
|
|
@@ -3716,6 +3911,7 @@ var VariablesFeed = class {
|
|
|
3716
3911
|
const asked = options.timeoutMs;
|
|
3717
3912
|
const timeoutMs = asked === Infinity ? Infinity : typeof asked === "number" && asked > 0 ? Math.min(asked, TIMER_MAX_MS) : WRITE_TIMEOUT_MS;
|
|
3718
3913
|
const session = this.stateValue.get().session;
|
|
3914
|
+
const epoch = this.epoch;
|
|
3719
3915
|
if (session === null) {
|
|
3720
3916
|
return Promise.reject(
|
|
3721
3917
|
new WriteError("refused", "there is no run to write to", "not-running")
|
|
@@ -3726,10 +3922,12 @@ var VariablesFeed = class {
|
|
|
3726
3922
|
if (options.atMs !== void 0) body["at_ms"] = options.atMs;
|
|
3727
3923
|
if (options.late !== void 0) body["late"] = options.late;
|
|
3728
3924
|
return new Promise((resolve, reject) => {
|
|
3729
|
-
const pending = { session, seq: null, resolve, reject, timer: void 0 };
|
|
3925
|
+
const pending = { session, epoch, seq: null, resolve, reject, timer: void 0 };
|
|
3730
3926
|
this.pending.add(pending);
|
|
3731
3927
|
const known = () => this.operationsValue.get().find((o) => o.seq === pending.seq && o.session === pending.session);
|
|
3732
|
-
|
|
3928
|
+
const request = { method: "POST", path: "api/write", body };
|
|
3929
|
+
if (options.keepalive !== void 0) request.keepalive = options.keepalive;
|
|
3930
|
+
this.http(request, (outcome) => {
|
|
3733
3931
|
if (!this.pending.has(pending)) return;
|
|
3734
3932
|
if (!outcome.ok) {
|
|
3735
3933
|
const error = outcome.error;
|
|
@@ -3758,7 +3956,7 @@ var VariablesFeed = class {
|
|
|
3758
3956
|
);
|
|
3759
3957
|
return;
|
|
3760
3958
|
}
|
|
3761
|
-
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) {
|
|
3762
3960
|
this.settle(
|
|
3763
3961
|
pending,
|
|
3764
3962
|
new WriteError(
|
|
@@ -3840,6 +4038,12 @@ var VariablesFeed = class {
|
|
|
3840
4038
|
}
|
|
3841
4039
|
};
|
|
3842
4040
|
}
|
|
4041
|
+
isStale(ref) {
|
|
4042
|
+
return this.awaitingRefresh.has(keyOf(ref.peer, ref.name));
|
|
4043
|
+
}
|
|
4044
|
+
runEpoch() {
|
|
4045
|
+
return this.epoch;
|
|
4046
|
+
}
|
|
3843
4047
|
/**
|
|
3844
4048
|
* Turns a requested interval into the longest of WATCH_PERIODS_MS that is not longer, kept within the server's range
|
|
3845
4049
|
* (lower and upper limit).
|
|
@@ -3879,7 +4083,12 @@ var VariablesFeed = class {
|
|
|
3879
4083
|
}
|
|
3880
4084
|
}
|
|
3881
4085
|
if (all) return;
|
|
3882
|
-
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
|
+
}
|
|
3883
4092
|
}
|
|
3884
4093
|
/**
|
|
3885
4094
|
* Per interval, the variables to request (null: all). A variable goes to the shortest interval among the watches that
|
|
@@ -3943,6 +4152,19 @@ var VariablesFeed = class {
|
|
|
3943
4152
|
this.sync();
|
|
3944
4153
|
});
|
|
3945
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
|
+
}
|
|
3946
4168
|
sync() {
|
|
3947
4169
|
const wanted = this.wanted();
|
|
3948
4170
|
for (const [periodMs, bucket] of [...this.buckets]) {
|
|
@@ -3972,7 +4194,7 @@ var VariableBinder = class {
|
|
|
3972
4194
|
}
|
|
3973
4195
|
sources;
|
|
3974
4196
|
entries = /* @__PURE__ */ new Map();
|
|
3975
|
-
|
|
4197
|
+
entriesKey = null;
|
|
3976
4198
|
/** Per variable, the functions to call when the write status changes (the binds listen). */
|
|
3977
4199
|
listeners = /* @__PURE__ */ new Map();
|
|
3978
4200
|
/** Lookup table of the list (rebuilt when peers change). */
|
|
@@ -4004,9 +4226,9 @@ var VariableBinder = class {
|
|
|
4004
4226
|
this.lookUp();
|
|
4005
4227
|
return this.connectedPeers.has(peer);
|
|
4006
4228
|
}
|
|
4007
|
-
/** 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. */
|
|
4008
4230
|
connected() {
|
|
4009
|
-
return this.sources.connection.get() === "open";
|
|
4231
|
+
return this.sources.ready ? this.sources.ready.get() : this.sources.connection.get() === "open";
|
|
4010
4232
|
}
|
|
4011
4233
|
/**
|
|
4012
4234
|
* Why the variable cannot be written now (null if it can). Only the widget-independent reasons (Binding adds range
|
|
@@ -4091,9 +4313,11 @@ var VariableBinder = class {
|
|
|
4091
4313
|
*/
|
|
4092
4314
|
entry(ref) {
|
|
4093
4315
|
const session = this.sources.variables.state.get().session;
|
|
4094
|
-
|
|
4316
|
+
const epoch = this.sources.variables.runEpoch?.() ?? 0;
|
|
4317
|
+
const entryKey = session === null ? null : `${epoch}:${session}`;
|
|
4318
|
+
if (entryKey !== this.entriesKey) {
|
|
4095
4319
|
this.entries = /* @__PURE__ */ new Map();
|
|
4096
|
-
this.
|
|
4320
|
+
this.entriesKey = entryKey;
|
|
4097
4321
|
}
|
|
4098
4322
|
if (session === null) return void 0;
|
|
4099
4323
|
const key = keyOf2(ref);
|
|
@@ -4101,6 +4325,7 @@ var VariableBinder = class {
|
|
|
4101
4325
|
if (!entry) {
|
|
4102
4326
|
entry = {
|
|
4103
4327
|
session,
|
|
4328
|
+
epoch,
|
|
4104
4329
|
key,
|
|
4105
4330
|
ref: { peer: ref.peer, name: ref.name },
|
|
4106
4331
|
status: IDLE,
|
|
@@ -4135,7 +4360,7 @@ var VariableBinder = class {
|
|
|
4135
4360
|
}
|
|
4136
4361
|
return;
|
|
4137
4362
|
}
|
|
4138
|
-
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;
|
|
4139
4364
|
if (same && this.block(entry.ref) === null) {
|
|
4140
4365
|
this.send(entry, next.value);
|
|
4141
4366
|
return;
|
|
@@ -4158,7 +4383,7 @@ var VariableBinder = class {
|
|
|
4158
4383
|
this.changed(entry);
|
|
4159
4384
|
};
|
|
4160
4385
|
this.changed(entry);
|
|
4161
|
-
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) {
|
|
4162
4387
|
settled({ kind: "dropped", message: DROPPED_MESSAGE });
|
|
4163
4388
|
return;
|
|
4164
4389
|
}
|
|
@@ -4200,6 +4425,7 @@ var Binding = class {
|
|
|
4200
4425
|
sources.session.subscribe(refresh),
|
|
4201
4426
|
binder.onChange(ref, refresh)
|
|
4202
4427
|
);
|
|
4428
|
+
if (sources.ready) this.stops.push(sources.ready.subscribe(refresh));
|
|
4203
4429
|
this.state = {
|
|
4204
4430
|
// Built from the current state on every read (never returns a stale status, even if another subscriber was called
|
|
4205
4431
|
// first)
|
|
@@ -4235,7 +4461,8 @@ var Binding = class {
|
|
|
4235
4461
|
connected: binder.connected(),
|
|
4236
4462
|
peerConnected: binder.peerConnected(ref.peer),
|
|
4237
4463
|
// A reason while still ready means reading values keeps failing (the value is the last one read)
|
|
4238
|
-
readFailing: variables.status === "ready" && variables.reason !== null
|
|
4464
|
+
readFailing: variables.status === "ready" && variables.reason !== null,
|
|
4465
|
+
awaitingRefresh: sources.variables.isStale?.(ref) ?? false
|
|
4239
4466
|
});
|
|
4240
4467
|
const pending = binder.pending(ref);
|
|
4241
4468
|
const block = this.blockOf(info, reading, pending);
|
|
@@ -4350,7 +4577,10 @@ function buildClient(options) {
|
|
|
4350
4577
|
afterGreeting: () => variablesFeed?.resume() ?? [],
|
|
4351
4578
|
onError
|
|
4352
4579
|
});
|
|
4353
|
-
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
|
+
});
|
|
4354
4584
|
const session = feed;
|
|
4355
4585
|
variablesFeed = new VariablesFeed(
|
|
4356
4586
|
{
|
|
@@ -4373,6 +4603,7 @@ function buildClient(options) {
|
|
|
4373
4603
|
const binder = new VariableBinder({
|
|
4374
4604
|
variables,
|
|
4375
4605
|
connection: connection.state,
|
|
4606
|
+
ready: session.ready,
|
|
4376
4607
|
connectionEpoch: () => connection.batchEpoch(),
|
|
4377
4608
|
session: session.session,
|
|
4378
4609
|
onError
|
|
@@ -4432,6 +4663,7 @@ function buildClient(options) {
|
|
|
4432
4663
|
pause: () => time.pause(),
|
|
4433
4664
|
resume: () => time.resume(),
|
|
4434
4665
|
step: (ms) => time.step(ms),
|
|
4666
|
+
runUntil: (atMs) => time.runUntil(atMs),
|
|
4435
4667
|
setSpeed: (value) => time.setSpeed(value),
|
|
4436
4668
|
send: (command) => time.send(command)
|
|
4437
4669
|
},
|
|
@@ -4868,6 +5100,7 @@ var INTENT_FIELDS = /* @__PURE__ */ new Set([
|
|
|
4868
5100
|
"enable",
|
|
4869
5101
|
"manual",
|
|
4870
5102
|
"scenario",
|
|
5103
|
+
"after_scenario",
|
|
4871
5104
|
"variant",
|
|
4872
5105
|
"params",
|
|
4873
5106
|
"speed",
|
|
@@ -5048,6 +5281,7 @@ var FrontActions = class {
|
|
|
5048
5281
|
...intent.enable ? { enable: intent.enable } : {},
|
|
5049
5282
|
...intent.manual ? { manual: intent.manual } : {},
|
|
5050
5283
|
...intent.scenario !== void 0 ? { scenario: intent.scenario } : {},
|
|
5284
|
+
...intent.after_scenario !== void 0 ? { after_scenario: intent.after_scenario } : {},
|
|
5051
5285
|
...intent.variant !== void 0 ? { variant: intent.variant } : {},
|
|
5052
5286
|
...intent.params ? { params: intent.params } : {},
|
|
5053
5287
|
...intent.speed !== void 0 ? { speed: intent.speed } : {},
|
|
@@ -5584,7 +5818,11 @@ function makeVariable(low, ref, refuse, launcher) {
|
|
|
5584
5818
|
let count = 0;
|
|
5585
5819
|
let stops = [];
|
|
5586
5820
|
const refresh = () => {
|
|
5587
|
-
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;
|
|
5588
5826
|
};
|
|
5589
5827
|
let peeked = null;
|
|
5590
5828
|
const peek = () => {
|
|
@@ -5598,10 +5836,7 @@ function makeVariable(low, ref, refuse, launcher) {
|
|
|
5598
5836
|
}
|
|
5599
5837
|
};
|
|
5600
5838
|
const readable = {
|
|
5601
|
-
get: () =>
|
|
5602
|
-
if (!binding) return peek();
|
|
5603
|
-
return view.get();
|
|
5604
|
-
},
|
|
5839
|
+
get: () => refresh() ?? peek(),
|
|
5605
5840
|
subscribe: (listener) => {
|
|
5606
5841
|
if (count++ === 0) {
|
|
5607
5842
|
binding = low.variables.bind(ref);
|
|
@@ -5631,17 +5866,23 @@ function makeVariable(low, ref, refuse, launcher) {
|
|
|
5631
5866
|
return {
|
|
5632
5867
|
get: readable.get,
|
|
5633
5868
|
subscribe: readable.subscribe,
|
|
5634
|
-
write: (value) => {
|
|
5869
|
+
write: (value, options) => {
|
|
5635
5870
|
const own = refuse();
|
|
5636
5871
|
if (own) return Promise.reject(own);
|
|
5637
5872
|
track.set({ writing: true, problem: null });
|
|
5638
|
-
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(
|
|
5639
5877
|
() => {
|
|
5640
5878
|
track.set({ writing: false, problem: null });
|
|
5641
5879
|
},
|
|
5642
5880
|
(error) => {
|
|
5643
5881
|
const failure = writeFailure(error);
|
|
5644
|
-
track.set({
|
|
5882
|
+
track.set({
|
|
5883
|
+
writing: false,
|
|
5884
|
+
problem: { code: failure.code, message: failure.message }
|
|
5885
|
+
});
|
|
5645
5886
|
throw failure;
|
|
5646
5887
|
}
|
|
5647
5888
|
);
|
|
@@ -5772,6 +6013,8 @@ function makeFront(options, onClose) {
|
|
|
5772
6013
|
file: view.file,
|
|
5773
6014
|
name: view.name,
|
|
5774
6015
|
status: view.status,
|
|
6016
|
+
handed_over: view.handedOver,
|
|
6017
|
+
over_at_ms: view.overAtMs,
|
|
5775
6018
|
steps: view.steps,
|
|
5776
6019
|
timeline_url: view.timelineUrl
|
|
5777
6020
|
} : null;
|
|
@@ -6078,7 +6321,7 @@ function createVariableEditor(front, ref) {
|
|
|
6078
6321
|
canWrite: !closed && client.session.ready.get() && current !== null && current.run_id === client.variables.state.get().session && view.can_write && bound.block === null && !waiting
|
|
6079
6322
|
};
|
|
6080
6323
|
};
|
|
6081
|
-
const state = new Writable(read2(),
|
|
6324
|
+
const state = new Writable(read2(), sameData, clientErrorSink(client));
|
|
6082
6325
|
const reset = () => {
|
|
6083
6326
|
clearTimeout(timer);
|
|
6084
6327
|
timer = void 0;
|
|
@@ -6087,10 +6330,11 @@ function createVariableEditor(front, ref) {
|
|
|
6087
6330
|
};
|
|
6088
6331
|
const refresh = () => {
|
|
6089
6332
|
if (closed) return;
|
|
6090
|
-
const current = client.session.currentTarget();
|
|
6091
6333
|
const bound = binding.state.get();
|
|
6334
|
+
if (closed) return;
|
|
6092
6335
|
const shown = read2(bound);
|
|
6093
6336
|
if (closed) return;
|
|
6337
|
+
const current = client.session.currentTarget();
|
|
6094
6338
|
if (current?.instance !== target?.instance || current?.run_id !== target?.run_id || !shown.view.can_write) {
|
|
6095
6339
|
reset();
|
|
6096
6340
|
} else if (awaiting !== null && shown.view.value === awaiting) {
|
|
@@ -6108,13 +6352,19 @@ function createVariableEditor(front, ref) {
|
|
|
6108
6352
|
reset();
|
|
6109
6353
|
}
|
|
6110
6354
|
target = current;
|
|
6111
|
-
state.set(read2());
|
|
6355
|
+
if (!closed) state.set(read2());
|
|
6112
6356
|
};
|
|
6113
6357
|
const unsubscribe = binding.state.subscribe(refresh);
|
|
6114
6358
|
const unsubscribeSession = client.session.session.subscribe(refresh);
|
|
6115
6359
|
const unsubscribeReady = client.session.ready.subscribe(refresh);
|
|
6116
6360
|
return {
|
|
6117
|
-
state:
|
|
6361
|
+
state: {
|
|
6362
|
+
get: () => {
|
|
6363
|
+
refresh();
|
|
6364
|
+
return state.get();
|
|
6365
|
+
},
|
|
6366
|
+
subscribe: (listener) => state.subscribe(listener)
|
|
6367
|
+
},
|
|
6118
6368
|
write(value) {
|
|
6119
6369
|
const { canWrite, info: info2 } = read2();
|
|
6120
6370
|
if (!canWrite || !info2) return false;
|
|
@@ -6183,6 +6433,8 @@ export {
|
|
|
6183
6433
|
isLauncherAlive,
|
|
6184
6434
|
isLauncherFinishing,
|
|
6185
6435
|
isRunActive,
|
|
6436
|
+
isScenarioHandedOver,
|
|
6437
|
+
isScenarioRunning,
|
|
6186
6438
|
isSessionRunning,
|
|
6187
6439
|
isWriteError,
|
|
6188
6440
|
launcherAnswer,
|