@vehicle-sil/gui-client 0.0.0-stage → 0.2.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.ja.md +839 -0
- package/README.md +836 -2
- package/dist/elements.js +872 -0
- package/dist/index.js +5354 -0
- package/package.json +39 -4
- package/timeline/vehicle-sil-timeline.d.ts +108 -0
- package/timeline/vehicle-sil-timeline.js +4391 -0
- package/timeline/vehicle-sil-timeline.mjs +4393 -0
- package/types/client.d.ts +148 -0
- package/types/connection.d.ts +155 -0
- package/types/elements/index.d.ts +25 -0
- package/types/elements/outside-parts.d.ts +20 -0
- package/types/elements/page-intent.d.ts +10 -0
- package/types/elements/part.d.ts +48 -0
- package/types/elements/reasons.d.ts +12 -0
- package/types/elements/run-parts.d.ts +21 -0
- package/types/elements/scenario-parts.d.ts +18 -0
- package/types/elements/variable-parts.d.ts +28 -0
- package/types/front-actions.d.ts +122 -0
- package/types/front-compose.d.ts +61 -0
- package/types/front-outside.d.ts +19 -0
- package/types/front-types.d.ts +353 -0
- package/types/front-variable.d.ts +28 -0
- package/types/front.d.ts +50 -0
- package/types/http.d.ts +71 -0
- package/types/index.d.ts +28 -0
- package/types/protocol/launcher.d.ts +578 -0
- package/types/protocol/read.d.ts +72 -0
- package/types/protocol/server.d.ts +758 -0
- package/types/protocol.d.ts +15 -0
- package/types/run.d.ts +74 -0
- package/types/session-state.d.ts +289 -0
- package/types/session.d.ts +130 -0
- package/types/time.d.ts +133 -0
- package/types/token.d.ts +35 -0
- package/types/urls.d.ts +8 -0
- package/types/values.d.ts +54 -0
- package/types/variable-binding.d.ts +181 -0
- package/types/variable-state.d.ts +134 -0
- package/types/variables.d.ts +382 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shapes of the data exchanged with the server, and their parsers (gui/protocol/ is the authority).
|
|
3
|
+
*
|
|
4
|
+
* The types of the server API are written only in protocol/; users of the library (the screens too) import them from
|
|
5
|
+
* the entry point (index.ts). JSON that arrives (HTTP answers, WebSocket notifications) is used only after a read*
|
|
6
|
+
* function there has checked its type.
|
|
7
|
+
* - protocol/launcher.ts: the shapes the launcher decides (check --json, run --json, run --events).
|
|
8
|
+
* - protocol/server.ts: the shapes the GUI server decides (api/*, WebSocket messages, dashboard files).
|
|
9
|
+
* - protocol/read.ts: building blocks of the parsers, and the rules they follow.
|
|
10
|
+
* The unit tests (protocol.spec.ts) feed every example in gui/protocol/examples/ through these parsers.
|
|
11
|
+
*/
|
|
12
|
+
export { ProtocolError, Unreadable } from './protocol/read.js';
|
|
13
|
+
export type { Open, Reader } from './protocol/read.js';
|
|
14
|
+
export * from './protocol/launcher.js';
|
|
15
|
+
export * from './protocol/server.js';
|
package/types/run.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { HttpTransport } from './http.js';
|
|
2
|
+
import { RunRequest, SessionSummary } from './protocol.js';
|
|
3
|
+
import { SessionFeed } from './session.js';
|
|
4
|
+
import { ErrorSink, Readable } from './values.js';
|
|
5
|
+
/** Stop action: stop in order, or stop without waiting. */
|
|
6
|
+
export type StopAction = 'stop' | 'force';
|
|
7
|
+
/** Run control and its state (GuiClient.run). */
|
|
8
|
+
export interface ClientRun {
|
|
9
|
+
/** A start was sent and its answer is pending. */
|
|
10
|
+
readonly starting: Readable<boolean>;
|
|
11
|
+
/** A stop was sent and its answer is pending (which kind of stop). */
|
|
12
|
+
readonly stopping: Readable<StopAction | null>;
|
|
13
|
+
/** A stop was asked for while the answer to a start was pending. */
|
|
14
|
+
readonly stopWhileStarting: Readable<boolean>;
|
|
15
|
+
/** Why the last action was refused (the server's text, unchanged). null once a run starts or ends. */
|
|
16
|
+
readonly error: Readable<string | null>;
|
|
17
|
+
/**
|
|
18
|
+
* Starts a run (`POST api/run`). Resolves with the summary in the answer; rejects with an HttpError if refused.
|
|
19
|
+
* The server may check the configuration file again as part of the start, so this waits up to twice the check limit
|
|
20
|
+
* (waiting its turn, then checking) plus a margin. If there is still no answer, it rejects with an HttpError with
|
|
21
|
+
* `timedOut` and error says that no answer came (the WebSocket state tells whether the run started). The server may
|
|
22
|
+
* have started it.
|
|
23
|
+
*/
|
|
24
|
+
start(request: RunRequest): Promise<SessionSummary | null>;
|
|
25
|
+
/** Stops in order (`POST api/stop` `{force: false}`). Asking again has no further effect. */
|
|
26
|
+
stop(): Promise<SessionSummary | null>;
|
|
27
|
+
/** Stops without waiting (`POST api/stop` `{force: true}`). */
|
|
28
|
+
forceStop(): Promise<SessionSummary | null>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Run control: start (`POST api/run`), stop in order or without waiting (`POST api/stop`), and the state for them.
|
|
32
|
+
*
|
|
33
|
+
* - The answer to an action (the current summary) is applied to the session copy without waiting for the notification
|
|
34
|
+
* (no stale display right after a click).
|
|
35
|
+
* - Start and stop are sent separately. A stop can be asked for while the answer to a start is pending (the server
|
|
36
|
+
* delivers it once the launcher has started; stopping in order has no further effect when asked again, so if the
|
|
37
|
+
* summary in the start's answer does not show the stop as asked for yet, it is asked for again).
|
|
38
|
+
* - error holds the reason for a refusal (the server's English text). It is cleared once a run starts or ends.
|
|
39
|
+
* - The Promises of start() and stop() resolve with the summary in the answer (null if unreadable) and reject with an
|
|
40
|
+
* HttpError when refused. No answer (`timedOut`) is not a refusal: the session copy tells whether the run started.
|
|
41
|
+
* The state (starting and so on) has already changed when the Promise resolves.
|
|
42
|
+
*/
|
|
43
|
+
export declare class RunControl implements ClientRun {
|
|
44
|
+
private readonly feed;
|
|
45
|
+
private readonly transport;
|
|
46
|
+
/**
|
|
47
|
+
* How long to wait for the answer to a start (ms). Long, because the server may check again as part of the start.
|
|
48
|
+
*/
|
|
49
|
+
private readonly startTimeoutMs;
|
|
50
|
+
private readonly startSending;
|
|
51
|
+
private readonly stopSending;
|
|
52
|
+
private readonly stopAskedWhileStarting;
|
|
53
|
+
private readonly failure;
|
|
54
|
+
readonly starting: Readable<boolean>;
|
|
55
|
+
readonly stopping: Readable<StopAction | null>;
|
|
56
|
+
readonly stopWhileStarting: Readable<boolean>;
|
|
57
|
+
readonly error: Readable<string | null>;
|
|
58
|
+
constructor(feed: SessionFeed, transport: HttpTransport, onError?: ErrorSink,
|
|
59
|
+
/**
|
|
60
|
+
* How long to wait for the answer to a start (ms). Long, because the server may check again as part of the start.
|
|
61
|
+
*/
|
|
62
|
+
startTimeoutMs?: () => number);
|
|
63
|
+
/** Starts a run. */
|
|
64
|
+
start(request: RunRequest): Promise<SessionSummary | null>;
|
|
65
|
+
/** Stops in order (waits for the participants to end). Asking again never turns it into a stop without waiting. */
|
|
66
|
+
stop(): Promise<SessionSummary | null>;
|
|
67
|
+
/** Stops without waiting (kills the participants). */
|
|
68
|
+
forceStop(): Promise<SessionSummary | null>;
|
|
69
|
+
/**
|
|
70
|
+
* Sends and applies the summary in the answer. done is called after the answer (failures too), before the Promise
|
|
71
|
+
* settles.
|
|
72
|
+
*/
|
|
73
|
+
private send;
|
|
74
|
+
}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import { CheckResult, ControlLink, Dropped, Finding, LauncherEvent, ParticipantState, Phase, RunResult, ScenarioStatus, ScenarioStep, ServerProblem, SessionSummary, Speed, StateReport, TimeReport } from './protocol.js';
|
|
2
|
+
/**
|
|
3
|
+
* A reason: a code that stays the same (an entry of the owner's reason codes, or one the client names) and one English
|
|
4
|
+
* sentence.
|
|
5
|
+
*/
|
|
6
|
+
export interface Reason {
|
|
7
|
+
code: string;
|
|
8
|
+
message: string;
|
|
9
|
+
}
|
|
10
|
+
/** What the launcher says of one operation: why it does not accept it now (null if it does), and its warning. */
|
|
11
|
+
export interface LauncherAnswer {
|
|
12
|
+
reason: Reason | null;
|
|
13
|
+
caution: Reason | null;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* What the launcher's last `state` says of one operation (`allowed.<name>`, such as `write` or `pause`), as it wrote
|
|
17
|
+
* it. A launcher that has not said yet does not accept it (`unsupported`): no `state` yet (at the start of a run,
|
|
18
|
+
* before the launcher's first one), or a `state` with no entry for the operation.
|
|
19
|
+
* The one place the client reads `allowed` of the launcher: `controls` of the front door and `client.variables.bind`
|
|
20
|
+
* both use it.
|
|
21
|
+
*/
|
|
22
|
+
export declare function launcherAnswer(state: StateReport | null, name: string): LauncherAnswer;
|
|
23
|
+
/** Log lines kept per source (participant or launcher). The same number the server keeps. */
|
|
24
|
+
export declare const MAX_LOG_LINES_PER_SOURCE = 2000;
|
|
25
|
+
/** Log lines kept in total. Beyond this, the oldest lines of the source holding the most are dropped. */
|
|
26
|
+
export declare const MAX_LOG_LINES = 20000;
|
|
27
|
+
/** Server notices kept. Beyond this, only the number is counted. */
|
|
28
|
+
export declare const MAX_PROBLEMS = 200;
|
|
29
|
+
/** Findings of the run kept. */
|
|
30
|
+
export declare const MAX_FINDINGS = 500;
|
|
31
|
+
/** One log line. */
|
|
32
|
+
export interface LogLine {
|
|
33
|
+
/** seq of the event. A marker for dropped lines has the seq of the line before it + 0.5 (markers may share a seq). */
|
|
34
|
+
seq: number;
|
|
35
|
+
/** Key the screen tells lines apart by (unique within the session, markers included). */
|
|
36
|
+
key: string;
|
|
37
|
+
/** The participant name, or `vehicle_sil_launch`. */
|
|
38
|
+
source: string;
|
|
39
|
+
line: string;
|
|
40
|
+
/**
|
|
41
|
+
* Only on a marker for dropped lines ("N lines were dropped here"). launcher: lines the launcher could not write
|
|
42
|
+
* (log_dropped).
|
|
43
|
+
*/
|
|
44
|
+
gap?: {
|
|
45
|
+
count: number;
|
|
46
|
+
atLeast: boolean;
|
|
47
|
+
launcher?: boolean;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/** Log counts per source. */
|
|
51
|
+
export interface LogSource {
|
|
52
|
+
/** Lines held now (markers for dropped lines not counted). */
|
|
53
|
+
lines: number;
|
|
54
|
+
/** Old lines dropped (those the server no longer kept, and those the screen dropped at its limit). */
|
|
55
|
+
dropped: number;
|
|
56
|
+
}
|
|
57
|
+
/** State of a participant during the run. */
|
|
58
|
+
export interface ParticipantView {
|
|
59
|
+
name: string;
|
|
60
|
+
/** The last state received. null if nothing has arrived yet. */
|
|
61
|
+
state: ParticipantState | null;
|
|
62
|
+
required: boolean | null;
|
|
63
|
+
pid: number | null;
|
|
64
|
+
exitCode: number | null;
|
|
65
|
+
signal: string | null;
|
|
66
|
+
/**
|
|
67
|
+
* Why the launcher decided the participant failed (reason of the failed event; may arrive before the process ends).
|
|
68
|
+
* Kept even if ended arrives later. null unless it was decided to have failed.
|
|
69
|
+
*/
|
|
70
|
+
failure: string | null;
|
|
71
|
+
/** Why it could not be started (not_started), or the text of the failure finding (failed). In English, unchanged. */
|
|
72
|
+
message: string | null;
|
|
73
|
+
/**
|
|
74
|
+
* The launcher asked it to stop (stop_requested; ended in the result is stopped). How it ends after that is not
|
|
75
|
+
* colored as a failure.
|
|
76
|
+
*/
|
|
77
|
+
stopRequested: boolean;
|
|
78
|
+
/** Names of fields the server left out because the summary was full (empty once a later event arrives). */
|
|
79
|
+
omittedFields: readonly string[];
|
|
80
|
+
/**
|
|
81
|
+
* State of the connection to the ECU's variables (the control_link event, or control_link of the result). null while
|
|
82
|
+
* unknown.
|
|
83
|
+
*/
|
|
84
|
+
controlLink: ControlLink | null;
|
|
85
|
+
/** A participant the user starts (manual of the check result, or the manual event). */
|
|
86
|
+
manual: boolean;
|
|
87
|
+
/** manual: the command line that starts it (as the launcher wrote it). null if it has not arrived. */
|
|
88
|
+
commandLine: string | null;
|
|
89
|
+
/** manual: the directory to run that command in. null if it has not arrived. */
|
|
90
|
+
workingDirectory: string | null;
|
|
91
|
+
/**
|
|
92
|
+
* manual: environment variables to set when starting it (names and values, as the launcher wrote them). Empty if
|
|
93
|
+
* there are none. When the registry is not on a loopback address, it includes `VEHICLE_SIL_LISTEN_ON_NETWORK` with
|
|
94
|
+
* `1`.
|
|
95
|
+
*/
|
|
96
|
+
environment: Readonly<Record<string, string>>;
|
|
97
|
+
}
|
|
98
|
+
/** State of the launcher process (as the server sees it). */
|
|
99
|
+
export interface LauncherView {
|
|
100
|
+
/** Whether it is running. Stays true after the result arrives, until it exits. Decides whether it can be stopped. */
|
|
101
|
+
running: boolean;
|
|
102
|
+
exitCode: number | null;
|
|
103
|
+
/** Number of the signal that ended it (POSIX only). */
|
|
104
|
+
signal: number | null;
|
|
105
|
+
/**
|
|
106
|
+
* Seconds it has been running without writing anything (the server watches with a heartbeat). null while it writes.
|
|
107
|
+
*/
|
|
108
|
+
silentSeconds: number | null;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Virtual time and how it keeps up (the last time event, or time of the summary). Fields that are not written are
|
|
112
|
+
* null. Whether the run is paused, and the speed set, are in the launcher's state (SessionView.launcherState).
|
|
113
|
+
*/
|
|
114
|
+
export interface TimeView {
|
|
115
|
+
simMs: number;
|
|
116
|
+
/** Actual speed over roughly the last second (null when starting to move, and in an event written while paused). */
|
|
117
|
+
actualSpeed: number | null;
|
|
118
|
+
/** Number of late time steps. */
|
|
119
|
+
lateSteps: number | null;
|
|
120
|
+
/** Max lateness (ms). */
|
|
121
|
+
maxLateMs: number | null;
|
|
122
|
+
/** Total slip (ms). */
|
|
123
|
+
slippedMs: number | null;
|
|
124
|
+
/** Lateness of a time step that is past its deadline and has not started yet (ms). */
|
|
125
|
+
lateMs: number | null;
|
|
126
|
+
}
|
|
127
|
+
/** The last command event received (stop included). */
|
|
128
|
+
export interface CommandView {
|
|
129
|
+
/** Name of the command (null for an unreadable line). */
|
|
130
|
+
name: string | null;
|
|
131
|
+
accepted: boolean;
|
|
132
|
+
/** Why it was not accepted (in English, unchanged). */
|
|
133
|
+
message: string | null;
|
|
134
|
+
/** For an accepted step, the virtual time it actually advances (ms). */
|
|
135
|
+
ms: number | null;
|
|
136
|
+
/** For an accepted step or run_until, the virtual time at which the simulation pauses after it (ms). */
|
|
137
|
+
atMs: number | null;
|
|
138
|
+
/** seq of that event (-1 if unknown). Tells a new answer from the same answer arriving again in a summary. */
|
|
139
|
+
seq: number;
|
|
140
|
+
}
|
|
141
|
+
export declare function timeView(time: TimeReport): TimeView;
|
|
142
|
+
/**
|
|
143
|
+
* Progress of a scenario run (from scenario of the summary, scenario_step events, and scenario of the check and the
|
|
144
|
+
* result).
|
|
145
|
+
*/
|
|
146
|
+
export interface ScenarioView {
|
|
147
|
+
/** The scenario file (relative to root). */
|
|
148
|
+
file: string;
|
|
149
|
+
name: string | null;
|
|
150
|
+
/** Number of steps (from the check result; null until then). */
|
|
151
|
+
stepCount: number | null;
|
|
152
|
+
/** Steps received (in index order, the last state of each step). After the result, every step. */
|
|
153
|
+
steps: readonly ScenarioStep[];
|
|
154
|
+
/** Number of steps beyond the limit that the server did not keep. */
|
|
155
|
+
stepsOmitted: number;
|
|
156
|
+
/** Result of the scenario (passed, failed, incomplete, not_run). null until there is a result. */
|
|
157
|
+
status: ScenarioStatus | null;
|
|
158
|
+
/** Virtual time at which the scenario ended. */
|
|
159
|
+
overAtMs: number | null;
|
|
160
|
+
/**
|
|
161
|
+
* Where the server serves the run's timeline file (`api/timeline/<session id>`), once the run has ended with one;
|
|
162
|
+
* else null. The page `timeline/` of the server draws it (see "Timeline of a scenario run" in docs/gui.md).
|
|
163
|
+
*/
|
|
164
|
+
timelineUrl: string | null;
|
|
165
|
+
}
|
|
166
|
+
/** State of one session (one run of the launcher), as the screen sees it. */
|
|
167
|
+
export interface SessionView {
|
|
168
|
+
/** Session number the server assigned. */
|
|
169
|
+
id: number;
|
|
170
|
+
/** seq of the last event received (-1 if none). On reconnect, the resend is requested from the next one. */
|
|
171
|
+
lastSeq: number;
|
|
172
|
+
/** The configuration file (relative to root). */
|
|
173
|
+
file: string;
|
|
174
|
+
/** Participants left out. */
|
|
175
|
+
disable: readonly string[];
|
|
176
|
+
/**
|
|
177
|
+
* Participants the user chose on the screen to start themselves (manual: true in the configuration file is in check).
|
|
178
|
+
*/
|
|
179
|
+
manual: readonly string[];
|
|
180
|
+
/** Speed given at the start (null means as in the configuration file). The current speed is `speed` of launcherState. */
|
|
181
|
+
speed: Speed;
|
|
182
|
+
/** Whether the run started paused. */
|
|
183
|
+
startPaused: boolean;
|
|
184
|
+
phase: Phase | null;
|
|
185
|
+
/** Position of the last known phase received (so an unknown phase never moves the phase backwards). */
|
|
186
|
+
phaseRank: number;
|
|
187
|
+
check: CheckResult | null;
|
|
188
|
+
participants: readonly ParticipantView[];
|
|
189
|
+
/** Log lines (in seq order). */
|
|
190
|
+
logs: readonly LogLine[];
|
|
191
|
+
/** Per source, the number of lines held and dropped. */
|
|
192
|
+
logSources: Readonly<Record<string, LogSource>>;
|
|
193
|
+
/** Findings decided during the run (the check's findings are in check). */
|
|
194
|
+
findings: readonly Finding[];
|
|
195
|
+
/** t_ms of the last event received (real time since the launcher started). */
|
|
196
|
+
elapsedMs: number;
|
|
197
|
+
/** Virtual time (only once a time event has arrived). */
|
|
198
|
+
simMs: number | null;
|
|
199
|
+
/**
|
|
200
|
+
* Names of the fields of the last time that the server left out because the summary was full (empty once a later
|
|
201
|
+
* event arrives).
|
|
202
|
+
*/
|
|
203
|
+
timeOmittedFields: readonly string[];
|
|
204
|
+
/** Virtual time and how it advances (once a time event has arrived). */
|
|
205
|
+
time: TimeView | null;
|
|
206
|
+
/** Number of stop requests (1: "stopping"; 2: after "stop without waiting" was requested). */
|
|
207
|
+
stopRequests: number;
|
|
208
|
+
/** The last command event received (whether it was accepted, and why not). */
|
|
209
|
+
lastCommand: CommandView | null;
|
|
210
|
+
/**
|
|
211
|
+
* What the launcher accepts now and where the run stands (the last `state` event, or `launcher_state` of the
|
|
212
|
+
* summary; the one with the larger `rev` wins). null until one arrives (and for a launcher without `state`).
|
|
213
|
+
*/
|
|
214
|
+
launcherState: StateReport | null;
|
|
215
|
+
result: RunResult | null;
|
|
216
|
+
launcher: LauncherView;
|
|
217
|
+
/** What the server noticed (shown in English, unchanged). */
|
|
218
|
+
problems: readonly ServerProblem[];
|
|
219
|
+
/** Number of server notices beyond the limit that were not kept. */
|
|
220
|
+
problemsOmitted: number;
|
|
221
|
+
/**
|
|
222
|
+
* Names of the parts that could not be read (`result.participants` of the summary, `finding.code` of an event and so
|
|
223
|
+
* on). The screen shows "some parts cannot be displayed" for the parts listed here.
|
|
224
|
+
*/
|
|
225
|
+
unreadable: readonly string[];
|
|
226
|
+
/**
|
|
227
|
+
* Events not applied because their seq was not after the previous event's (overlap with the server's resend, or seq
|
|
228
|
+
* went back).
|
|
229
|
+
*/
|
|
230
|
+
staleEvents: number;
|
|
231
|
+
/** Number of markers placed for lines the server did not send (dropped); used for the markers' keys. */
|
|
232
|
+
droppedMarks: number;
|
|
233
|
+
/** Progress of the scenario (null for a run without a scenario). */
|
|
234
|
+
scenario: ScenarioView | null;
|
|
235
|
+
}
|
|
236
|
+
/** Where the run stands now (used by the status bar and the result display). */
|
|
237
|
+
export type RunOutcome =
|
|
238
|
+
/** Running, with no stop requested. */
|
|
239
|
+
'running'
|
|
240
|
+
/** A stop was requested (waiting for the participants to end). */
|
|
241
|
+
| 'stopping'
|
|
242
|
+
/** A stop without waiting was requested. */
|
|
243
|
+
| 'forcing'
|
|
244
|
+
/** There is a result, but the launcher is still running (waiting for it to exit). */
|
|
245
|
+
| 'finishing'
|
|
246
|
+
/** The launcher printed a result and exited. */
|
|
247
|
+
| 'ended'
|
|
248
|
+
/** The launcher exited without a result. */
|
|
249
|
+
| 'crashed';
|
|
250
|
+
/**
|
|
251
|
+
* Whether the run waits before its first step (the step at time 0) for a resume or a step: the launcher's state says
|
|
252
|
+
* so (`holding`; a run started paused whose launcher has a Control Server). Meanwhile the launcher writes no time
|
|
253
|
+
* events, and a variable written is applied in the step at time 0.
|
|
254
|
+
*/
|
|
255
|
+
export declare function isHolding(session: SessionView | null): boolean;
|
|
256
|
+
export declare function runOutcome(session: SessionView): RunOutcome;
|
|
257
|
+
/** Builds a session from the server's summary (hello, a new session). The log arrives in the resend that follows. */
|
|
258
|
+
export declare function sessionFromSummary(summary: SessionSummary): SessionView;
|
|
259
|
+
/**
|
|
260
|
+
* Counts log lines that were not sent (dropped) and places an "N lines were dropped here" marker at the current
|
|
261
|
+
* position of that source's log. Before the resend (not-kept), it goes before the lines being resent.
|
|
262
|
+
*/
|
|
263
|
+
export declare function addDropped(session: SessionView, dropped: Dropped): SessionView;
|
|
264
|
+
/**
|
|
265
|
+
* Applies a summary. The local log is kept.
|
|
266
|
+
*
|
|
267
|
+
* - force (WebSocket hello and session): arrives in the same order as events, so everything is taken as correct at
|
|
268
|
+
* the time it arrives.
|
|
269
|
+
* - Without force (an HTTP answer): its order relative to notifications is unknown. Whether the launcher runs and the
|
|
270
|
+
* stop requests are taken, but a launcher that has ended in the same run is never set back to running. Server
|
|
271
|
+
* notices are taken only when there are no fewer than held locally (the server only adds, so a summary with fewer is
|
|
272
|
+
* old). Phase, check, participants, findings, result and virtual time are taken only when the summary is newer than
|
|
273
|
+
* the local events, and not at all with controlOnly (the WebSocket is connected and the same things arrive in
|
|
274
|
+
* notifications), so findings do not appear twice, once from the summary and once from a notification.
|
|
275
|
+
*/
|
|
276
|
+
export declare function applySummary(session: SessionView, summary: SessionSummary, force?: boolean, controlOnly?: boolean): SessionView;
|
|
277
|
+
/**
|
|
278
|
+
* Adds a server notice (later summaries carry the same one and replace it). Beyond the limit, only the number is
|
|
279
|
+
* counted.
|
|
280
|
+
*/
|
|
281
|
+
export declare function addProblem(session: SessionView, problem: ServerProblem): SessionView;
|
|
282
|
+
/** Position of the phase (-1 for an unknown phase). */
|
|
283
|
+
export declare function phaseIndex(phase: Phase | null): number;
|
|
284
|
+
/**
|
|
285
|
+
* Applies a batch of events. Events with the same or an earlier seq are not applied (overlap with the resend: what
|
|
286
|
+
* arrived before the reconnect). With countStale (events that are not a resend), those not applied are counted in
|
|
287
|
+
* staleEvents (seq went back). The log array is rebuilt once per batch (not copied for every event).
|
|
288
|
+
*/
|
|
289
|
+
export declare function applyEvents(session: SessionView, events: readonly LauncherEvent[], countStale?: boolean): SessionView;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { Connection } from './connection.js';
|
|
2
|
+
import { AuthMessage, ServerAllowed, ServerMessage, SessionSummary } from './protocol.js';
|
|
3
|
+
import { SessionView } from './session-state.js';
|
|
4
|
+
import { ErrorSink, Readable } from './values.js';
|
|
5
|
+
/** How many kinds of notices not tied to a session are kept. */
|
|
6
|
+
export declare const MAX_NOTICES = 20;
|
|
7
|
+
/**
|
|
8
|
+
* Notice for an event not applied because its seq was not after the previous event's (English, shown as is like the
|
|
9
|
+
* other notices).
|
|
10
|
+
*/
|
|
11
|
+
export declare const STALE_EVENTS_NOTICE: string;
|
|
12
|
+
/**
|
|
13
|
+
* Notice not tied to a session (an unreadable notification and so on; the English text is shown as is). Identical texts
|
|
14
|
+
* are counted together.
|
|
15
|
+
*/
|
|
16
|
+
export interface Notice {
|
|
17
|
+
id: number;
|
|
18
|
+
message: string;
|
|
19
|
+
/** How many times the same text arrived. */
|
|
20
|
+
count: number;
|
|
21
|
+
}
|
|
22
|
+
/** Read side of the session copy (GuiClient.session). */
|
|
23
|
+
export interface ClientSession {
|
|
24
|
+
/** The current (or last) session. null while the server has none yet. */
|
|
25
|
+
readonly session: Readable<SessionView | null>;
|
|
26
|
+
/**
|
|
27
|
+
* The session copy matches the server: connected, and hello and the resent events have all arrived. Until then,
|
|
28
|
+
* Start and Stop are disabled so that nobody acts on a stale display. Other features (values and so on) have their
|
|
29
|
+
* own ready.
|
|
30
|
+
*/
|
|
31
|
+
readonly ready: Readable<boolean>;
|
|
32
|
+
/**
|
|
33
|
+
* What the server accepts now (start, stop, force and why not). null until it says (hello), and from a server that
|
|
34
|
+
* does not say. What the launcher accepts is `launcherState` of the session.
|
|
35
|
+
*/
|
|
36
|
+
readonly allowed: Readable<ServerAllowed | null>;
|
|
37
|
+
/** When an event was last applied (Date.now()). The starting point for advancing elapsed time with the clock. */
|
|
38
|
+
readonly lastEventAt: Readable<number>;
|
|
39
|
+
/**
|
|
40
|
+
* Notices not tied to a session. Notices about the session (a gap in seq and so on) are in the problems of session.
|
|
41
|
+
*/
|
|
42
|
+
readonly notices: Readable<readonly Notice[]>;
|
|
43
|
+
/**
|
|
44
|
+
* The server refused the token (WebSocket unauthorized). The connection no longer reconnects. Once set, it stays
|
|
45
|
+
* set (to use another token, create a new client).
|
|
46
|
+
*/
|
|
47
|
+
readonly rejected: Readable<boolean>;
|
|
48
|
+
/**
|
|
49
|
+
* The text (English) saying why the server API's version differs from the version this library reads
|
|
50
|
+
* (PROTOCOL_VERSION). The connection no longer reconnects (waiting will not fix it). Once set, it stays set. null if
|
|
51
|
+
* the versions match.
|
|
52
|
+
*/
|
|
53
|
+
readonly incompatible: Readable<string | null>;
|
|
54
|
+
/**
|
|
55
|
+
* Receives the readable notifications, one batch at a time, after they are applied to the state. Call the returned
|
|
56
|
+
* function to unsubscribe.
|
|
57
|
+
*/
|
|
58
|
+
onMessages(listener: (batch: readonly ServerMessage[]) => void): () => void;
|
|
59
|
+
/**
|
|
60
|
+
* Adds something the user noticed (an unreadable answer and so on) to the notices. Identical texts are counted
|
|
61
|
+
* together.
|
|
62
|
+
*/
|
|
63
|
+
report(message: string, count?: number): void;
|
|
64
|
+
/** Removes a notice. */
|
|
65
|
+
dismissNotice(id: number): void;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Copy of a session (one run of the launcher). Reads the notifications of the connection (Connection) and builds the
|
|
69
|
+
* state from the server's summary and events.
|
|
70
|
+
*
|
|
71
|
+
* - Rebuilds the state from the summary in hello (the summary is authoritative), then applies the events that follow
|
|
72
|
+
* (the resent log and new events).
|
|
73
|
+
* - On every connect, puts into the authentication message where in the session it holds the server should resend
|
|
74
|
+
* from (resumeFields).
|
|
75
|
+
* - On a hello or session whose summary core is unreadable, marks itself not in sync and asks the connection to
|
|
76
|
+
* restart (receive again from hello).
|
|
77
|
+
* - Passes unknown notifications and unknown events through without applying them (onMessages gets only the readable
|
|
78
|
+
* ones, the connection's onBatch gets all of them).
|
|
79
|
+
* - Requests to the connection (disconnect after a refusal, restart) are made before subscribers are notified (so
|
|
80
|
+
* they happen even if a subscriber throws).
|
|
81
|
+
*/
|
|
82
|
+
export declare class SessionFeed implements ClientSession {
|
|
83
|
+
private readonly connection;
|
|
84
|
+
private readonly onError;
|
|
85
|
+
private readonly current;
|
|
86
|
+
private readonly synced;
|
|
87
|
+
private readonly allowedValue;
|
|
88
|
+
private readonly receivedAt;
|
|
89
|
+
private readonly noticeList;
|
|
90
|
+
private readonly rejectedValue;
|
|
91
|
+
private readonly incompatibleValue;
|
|
92
|
+
private readonly messageListeners;
|
|
93
|
+
private noticeId;
|
|
94
|
+
private stoppedFlag;
|
|
95
|
+
readonly session: Readable<SessionView | null>;
|
|
96
|
+
readonly ready: Readable<boolean>;
|
|
97
|
+
readonly allowed: Readable<ServerAllowed | null>;
|
|
98
|
+
readonly lastEventAt: Readable<number>;
|
|
99
|
+
readonly notices: Readable<readonly Notice[]>;
|
|
100
|
+
readonly rejected: Readable<boolean>;
|
|
101
|
+
readonly incompatible: Readable<string | null>;
|
|
102
|
+
constructor(connection: Connection, onError?: ErrorSink);
|
|
103
|
+
/** Refused, or the versions differ: never connect again (set before the readable values and before disconnecting). */
|
|
104
|
+
get stopped(): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Fields to add to the authentication message: where in the session it holds the server should resend from. Called
|
|
107
|
+
* on every connect (after the call, the copy is not in sync until hello and the resent events have arrived). Used
|
|
108
|
+
* only inside the library.
|
|
109
|
+
*/
|
|
110
|
+
resumeFields(): Pick<AuthMessage, 'session' | 'from_seq'>;
|
|
111
|
+
onMessages(listener: (batch: readonly ServerMessage[]) => void): () => void;
|
|
112
|
+
/**
|
|
113
|
+
* Applies the summary in an HTTP answer without waiting for the notification (the answers to start, stop and
|
|
114
|
+
* fetchSession(); used inside the library). While the WebSocket is connected, takes only the launcher and the stop
|
|
115
|
+
* request for the same run (the rest arrives in notifications). A summary of an earlier run never brings back an old
|
|
116
|
+
* run over a new one.
|
|
117
|
+
*/
|
|
118
|
+
adopt(summary: SessionSummary | null): void;
|
|
119
|
+
/**
|
|
120
|
+
* Takes what the server accepts (an HTTP answer or a notification): the one with the larger `rev` wins (rev 0 is a
|
|
121
|
+
* server that does not number it: the newest arrival wins). Used inside the library.
|
|
122
|
+
*/
|
|
123
|
+
adoptAllowed(allowed: ServerAllowed | null): void;
|
|
124
|
+
report(message: string, count?: number): void;
|
|
125
|
+
dismissNotice(id: number): void;
|
|
126
|
+
/** Reads and applies a batch from the connection. */
|
|
127
|
+
private receive;
|
|
128
|
+
private apply;
|
|
129
|
+
private notify;
|
|
130
|
+
}
|
package/types/time.d.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { HttpTransport } from './http.js';
|
|
2
|
+
import { TimeCommand, TimeCommandName } from './protocol.js';
|
|
3
|
+
import { CommandView, SessionView, TimeView } from './session-state.js';
|
|
4
|
+
import { ErrorSink, Readable } from './values.js';
|
|
5
|
+
/**
|
|
6
|
+
* How long to wait for the launcher's answer (the command event) to a command sent (ms). After that, the client stops
|
|
7
|
+
* waiting, enables the controls again and reports the missing answer as an error (a launcher that does not read its
|
|
8
|
+
* input).
|
|
9
|
+
*/
|
|
10
|
+
export declare const ANSWER_TIMEOUT_MS = 5000;
|
|
11
|
+
/** Why nothing was sent: no run, or waiting for the answer to the previous command. */
|
|
12
|
+
export type NotSentReason = 'no-session' | 'waiting';
|
|
13
|
+
/** Result of send() and the like: whether it was sent and, if not, why. */
|
|
14
|
+
export type SendResult = {
|
|
15
|
+
sent: true;
|
|
16
|
+
} | {
|
|
17
|
+
sent: false;
|
|
18
|
+
reason: NotSentReason;
|
|
19
|
+
};
|
|
20
|
+
/** A time command that went wrong. */
|
|
21
|
+
export interface TimeFailure {
|
|
22
|
+
/** server: the server refused (message is the server's English text); no-answer: the launcher did not answer. */
|
|
23
|
+
kind: 'server' | 'no-answer';
|
|
24
|
+
/**
|
|
25
|
+
* English text to show a person. To put it in the screen's language, build it from kind, command and answerTimeoutMs.
|
|
26
|
+
*/
|
|
27
|
+
message: string;
|
|
28
|
+
command: TimeCommandName;
|
|
29
|
+
/** Number of the run it was sent to. */
|
|
30
|
+
session: number | null;
|
|
31
|
+
}
|
|
32
|
+
/** Lateness figures (meaningful only while the speed is paced, such as at real-time speed). */
|
|
33
|
+
export interface Lateness {
|
|
34
|
+
lateSteps: number;
|
|
35
|
+
maxLateMs: number;
|
|
36
|
+
slippedMs: number;
|
|
37
|
+
lateMs: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Time state: the virtual time, the lateness, and the answer to the last command. All values come from the session
|
|
41
|
+
* copy. Whether a command may be used now is not here: the launcher says it (`allowed` of
|
|
42
|
+
* its state, SessionView.launcherState), and `controls` of connect() puts it together with the connection.
|
|
43
|
+
*/
|
|
44
|
+
export interface TimeState {
|
|
45
|
+
/** Time of the current session (null until a time event arrives). */
|
|
46
|
+
time: TimeView | null;
|
|
47
|
+
/** The speed is paced (the launcher's state has a numeric speed). Lateness is not counted when running as fast as possible. */
|
|
48
|
+
paced: boolean;
|
|
49
|
+
/** Lateness figures (null when the launcher does not write them). */
|
|
50
|
+
lateness: Lateness | null;
|
|
51
|
+
/**
|
|
52
|
+
* Whether the run fell behind real time (some time steps were later than the tolerance). Small late_ms within the
|
|
53
|
+
* tolerance come and go with every step synchronization, so they are not counted here. Lateness so far is kept after
|
|
54
|
+
* switching to as fast as possible.
|
|
55
|
+
*/
|
|
56
|
+
behind: boolean;
|
|
57
|
+
/** The last command event received (stop included). */
|
|
58
|
+
lastCommand: CommandView | null;
|
|
59
|
+
/**
|
|
60
|
+
* A command sent whose answer has not been seen yet (waiting for the HTTP answer or the launcher's command event).
|
|
61
|
+
* Meanwhile no further command is sent (so a double click or a repeated Enter does not step twice).
|
|
62
|
+
*/
|
|
63
|
+
sending: TimeCommandName | null;
|
|
64
|
+
/** The last command that went wrong. null once the run changes. */
|
|
65
|
+
failure: TimeFailure | null;
|
|
66
|
+
}
|
|
67
|
+
/** Read side and commands of time (GuiClient.time). */
|
|
68
|
+
export interface ClientTime {
|
|
69
|
+
/** Time state. */
|
|
70
|
+
readonly state: Readable<TimeState>;
|
|
71
|
+
/** How long to wait for the answer to a command (ms). */
|
|
72
|
+
readonly answerTimeoutMs: number;
|
|
73
|
+
pause(): SendResult;
|
|
74
|
+
resume(): SendResult;
|
|
75
|
+
/**
|
|
76
|
+
* While paused, advances virtual time by ms and pauses again (the launcher rounds up to a multiple of the time step).
|
|
77
|
+
*/
|
|
78
|
+
step(ms: number): SendResult;
|
|
79
|
+
/** Changes the speed (a pause stays in effect). */
|
|
80
|
+
setSpeed(value: number | 'max'): SendResult;
|
|
81
|
+
/**
|
|
82
|
+
* Sends a command. The result arrives as the launcher's command, state and time events. With no run, or while waiting for
|
|
83
|
+
* the answer to the previous command, nothing is sent and `{sent: false, reason}` is returned. Whether the launcher
|
|
84
|
+
* would accept the command is `allowed` of its state (or `controls` of connect()); a command it refuses comes back in
|
|
85
|
+
* lastCommand with the reason.
|
|
86
|
+
*/
|
|
87
|
+
send(command: TimeCommand): SendResult;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Simulation time: exposes the state (TimeState) as a readable value and sends time commands (pause, resume, step,
|
|
91
|
+
* speed change) to the GUI server (`POST api/time`).
|
|
92
|
+
*
|
|
93
|
+
* - The state is built from the session copy (summary and launcher events; the summary is authoritative). A client
|
|
94
|
+
* that connects midway gets the same state from the summary.
|
|
95
|
+
* - The server passes commands to the launcher and returns at once. lastCommand shows whether the launcher accepted a
|
|
96
|
+
* command; the launcher's state (a pause, a resume, the speed) and time (where it is) show that it took effect.
|
|
97
|
+
*/
|
|
98
|
+
export declare class TimeControl implements ClientTime {
|
|
99
|
+
private readonly session;
|
|
100
|
+
private readonly transport;
|
|
101
|
+
/** How long to wait for an answer (ms). */
|
|
102
|
+
readonly answerTimeoutMs: number;
|
|
103
|
+
private readonly inFlight;
|
|
104
|
+
private readonly pending;
|
|
105
|
+
private readonly failureValue;
|
|
106
|
+
private answerTimer;
|
|
107
|
+
private lastLateness;
|
|
108
|
+
/** Time state. */
|
|
109
|
+
readonly state: Readable<TimeState>;
|
|
110
|
+
constructor(session: Readable<SessionView | null>, transport: HttpTransport,
|
|
111
|
+
/** How long to wait for an answer (ms). */
|
|
112
|
+
answerTimeoutMs?: number, onError?: ErrorSink);
|
|
113
|
+
pause(): SendResult;
|
|
114
|
+
resume(): SendResult;
|
|
115
|
+
/**
|
|
116
|
+
* While paused, advances virtual time by ms and pauses again (the launcher rounds up to a multiple of the time step).
|
|
117
|
+
*/
|
|
118
|
+
step(ms: number): SendResult;
|
|
119
|
+
/** Changes the speed (a pause stays in effect). */
|
|
120
|
+
setSpeed(value: number | 'max'): SendResult;
|
|
121
|
+
/**
|
|
122
|
+
* Sends a command. The result arrives as the launcher's command, state and time events (the content of the HTTP answer is
|
|
123
|
+
* not used). With no run, or while waiting for the answer to the previous command (sending), nothing is sent and
|
|
124
|
+
* `{sent: false, reason}` is returned. If no answer comes within answerTimeoutMs, stops waiting and reports it in
|
|
125
|
+
* failure. Whether the launcher would accept the command is `allowed` of its state.
|
|
126
|
+
*/
|
|
127
|
+
send(command: TimeCommand): SendResult;
|
|
128
|
+
/** Stops the wait timer and stops waiting for the answer (when the client closes). */
|
|
129
|
+
dispose(): void;
|
|
130
|
+
/** The answer timed out: if no answer has come yet, stop waiting and say so. */
|
|
131
|
+
private giveUp;
|
|
132
|
+
private compute;
|
|
133
|
+
}
|