@vehicle-sil/gui-client 0.1.0 → 0.2.0-rc.2

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.
Files changed (39) hide show
  1. package/README.ja.md +412 -96
  2. package/README.md +403 -89
  3. package/dist/elements.js +872 -0
  4. package/dist/index.js +2869 -259
  5. package/package.json +20 -2
  6. package/timeline/vehicle-sil-timeline.d.ts +108 -0
  7. package/timeline/vehicle-sil-timeline.js +4577 -0
  8. package/timeline/vehicle-sil-timeline.mjs +4579 -0
  9. package/types/client.d.ts +47 -7
  10. package/types/connection.d.ts +4 -0
  11. package/types/elements/index.d.ts +25 -0
  12. package/types/elements/outside-parts.d.ts +20 -0
  13. package/types/elements/page-intent.d.ts +10 -0
  14. package/types/elements/part.d.ts +48 -0
  15. package/types/elements/reasons.d.ts +12 -0
  16. package/types/elements/run-parts.d.ts +21 -0
  17. package/types/elements/scenario-parts.d.ts +18 -0
  18. package/types/elements/variable-parts.d.ts +28 -0
  19. package/types/front-actions.d.ts +130 -0
  20. package/types/front-compose.d.ts +61 -0
  21. package/types/front-outside.d.ts +19 -0
  22. package/types/front-types.d.ts +360 -0
  23. package/types/front-variable.d.ts +28 -0
  24. package/types/front.d.ts +50 -0
  25. package/types/index.d.ts +13 -5
  26. package/types/protocol/launcher.d.ts +581 -0
  27. package/types/protocol/read.d.ts +72 -0
  28. package/types/protocol/server.d.ts +780 -0
  29. package/types/protocol.d.ts +10 -972
  30. package/types/run.d.ts +21 -6
  31. package/types/session-state.d.ts +66 -10
  32. package/types/session.d.ts +48 -2
  33. package/types/time.d.ts +16 -45
  34. package/types/values.d.ts +2 -0
  35. package/types/variable-binding.d.ts +20 -5
  36. package/types/variable-editor.d.ts +25 -0
  37. package/types/variable-state.d.ts +12 -6
  38. package/types/variables.d.ts +36 -4
  39. package/types/waveforms.d.ts +14 -0
@@ -1,977 +1,15 @@
1
1
  /**
2
2
  * Shapes of the data exchanged with the server, and their parsers (gui/protocol/ is the authority).
3
3
  *
4
- * The types of the server API are written here only; users of the library (the screens too) import them from the
5
- * entry point (index.ts). JSON that arrives (HTTP answers, WebSocket notifications) is used only after a read*
6
- * function here has checked its type.
7
- * - Unknown fields are ignored. Unknown events and unknown notifications become null and are skipped.
8
- * - Fields whose set of values may grow (phase, state, result and so on) pass unknown values through as strings.
9
- * - Data of the wrong shape (missing field, wrong type, unknown format version) throws ProtocolError.
10
- * - Exception: the session summary and launcher events are read part by part (readSessionSummary, readServerMessage).
11
- * If a part that comes from the launcher (check, result, findings, participants) or a part the server shrank to fit
12
- * its limits cannot be read, the readable parts are still used; an unreadable part gets its default value and its
13
- * name goes into `unreadable`. Only when the summary core (id, state, launcher, stop) or the event core (seq, event)
14
- * cannot be read is the whole thing unreadable.
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.
15
10
  * The unit tests (protocol.spec.ts) feed every example in gui/protocol/examples/ through these parsers.
16
11
  */
17
- /** Data of an unreadable shape. path is where it broke (for example `event.participants[0].name`). */
18
- export declare class ProtocolError extends Error {
19
- readonly path: string;
20
- readonly expected: string;
21
- constructor(path: string, expected: string);
22
- }
23
- /** A string whose set of values may grow. Known values get completion; unknown values are allowed too. */
24
- export type Open<T extends string> = T | (string & {});
25
- /**
26
- * The version of the GUI server's API that this library reads (`vehicle_sil_gui` of `api/app` and `hello`). It does not
27
- * read a hello or an api/app of another version (their fields may mean something else). When to raise the version:
28
- * "Versioning and compatibility" in gui/protocol/README.md.
29
- */
30
- export declare const PROTOCOL_VERSION = 1;
31
- /**
32
- * Reads a received value. path is how the error location is shown (for example `message.session`). Throws ProtocolError
33
- * on the wrong shape.
34
- */
35
- export type Reader<T> = (value: unknown, path: string) => T;
36
- /**
37
- * Collects the names of the parts that could not be read when reading part by part. Names are relative to root,
38
- * without array indexes (`message.session.participants[2].signal` → `participants.signal`).
39
- */
40
- export declare class Unreadable {
41
- private readonly root;
42
- private readonly prefix;
43
- private readonly names;
44
- constructor(root: string, prefix?: string);
45
- add(path: string): void;
46
- get parts(): string[];
47
- }
48
- /** Severity of a finding. An unknown severity is treated as an error (severityRank). */
49
- export type Severity = Open<'error' | 'warning' | 'note'>;
50
- /** A finding of the check or the run. message and detail are shown in English, unchanged. */
51
- export interface Finding {
52
- severity: Severity;
53
- code: string;
54
- file: string | null;
55
- line: number | null;
56
- participant: string | null;
57
- network: string | null;
58
- message: string;
59
- detail: string | null;
60
- }
61
- /** Rank for sorting by severity, most severe first (error 0, warning 1, note 2; an unknown severity ranks as error). */
62
- export declare function severityRank(severity: Severity): number;
63
- /** Reads a finding. With u, part by part (if the severity and text cannot be read, the finding is unreadable). */
64
- export declare const readFinding: (value: unknown, path: string, u?: Unreadable) => Finding;
65
- /** A variable the ECU declared about itself (so panels can be drawn before the run). */
66
- export interface Variable {
67
- name: string;
68
- type: Open<'bool' | 'integer' | 'real' | 'enum'>;
69
- causality: Open<'input' | 'output' | 'parameter'>;
70
- unit: string;
71
- min: number | null;
72
- max: number | null;
73
- /**
74
- * true for a variable vehicle-sil adds to every ECU (`ecu.connected` and so on), false for a variable the ECU
75
- * declared. null from an older launcher that does not write it.
76
- */
77
- builtin: boolean | null;
78
- }
79
- /** Launcher feature: can run scenarios (`--scenario`). */
80
- export declare const FEATURE_SCENARIO = "scenario";
81
- /**
82
- * Launcher feature: can keep a Control Server during a scenario run (variables can be read; the launcher refuses
83
- * writes). With a launcher without it, a scenario run has no variables.
84
- */
85
- export declare const FEATURE_SCENARIO_CONTROL = "scenario-control";
86
- /**
87
- * Launcher feature: participants the user starts (`manual: true` in the configuration file, `--manual`). The launcher
88
- * does not start them; it reports the command that starts them in a participant event (state `manual`) and waits for
89
- * them to join.
90
- */
91
- export declare const FEATURE_MANUAL = "manual-participants";
92
- /** State of a scenario step. running only appears in events (not in the steps of the result). */
93
- export type ScenarioStepStatus = Open<'running' | 'passed' | 'failed' | 'unfinished' | 'not_run'>;
94
- /** Overall result of a scenario. */
95
- export type ScenarioStatus = Open<'passed' | 'failed' | 'incomplete' | 'not_run'>;
96
- /**
97
- * One scenario step (the `scenario_step` event, `scenario.steps[]` of the result, `scenario.steps[]` of the summary).
98
- */
99
- export interface ScenarioStep {
100
- /** From 1. */
101
- index: number;
102
- /** Line in the scenario file. */
103
- line: number | null;
104
- kind: Open<'set' | 'ramp' | 'wave' | 'expect' | 'wait_until'>;
105
- /** Text of the step (shown in English, unchanged). */
106
- text: string;
107
- status: ScenarioStepStatus;
108
- /** Time of the step (virtual time, ms). */
109
- start_ms: number | null;
110
- /** Virtual time at which the step's result was decided. */
111
- at_ms: number | null;
112
- /** Virtual time at which the step ends (null if not fixed). */
113
- end_ms: number | null;
114
- /** code and text of the failure finding (shown in English, unchanged). */
115
- code: string | null;
116
- message: string | null;
117
- }
118
- /** `scenario` of the check result (only with `--scenario`). */
119
- export interface CheckScenario {
120
- /** The scenario file (as passed to the launcher). */
121
- file: string;
122
- name: string | null;
123
- /** Number of steps. */
124
- steps: number;
125
- }
126
- /** `scenario` of the run result (only with `--scenario`). */
127
- export interface ScenarioResult {
128
- file: string;
129
- name: string | null;
130
- status: ScenarioStatus;
131
- /** The controller step at which the scenario ended (passed and failed; null otherwise). */
132
- over_at_ms: number | null;
133
- steps: ScenarioStep[];
134
- }
135
- export type CheckStatus = Open<'described' | 'not_checked' | 'failed' | 'skipped' | 'disabled'>;
136
- export interface CheckParticipant {
137
- /** null if unreadable. */
138
- name: string | null;
139
- line: number | null;
140
- required: boolean | null;
141
- enabled: boolean | null;
142
- /**
143
- * Started by the user (`manual: true` in the configuration file, or `--manual`). Older launchers do not write it, so
144
- * false.
145
- */
146
- manual: boolean;
147
- step_ms: number | null;
148
- status: CheckStatus;
149
- /** Self-declared variables. null means unknown (not declared, left out, or unreadable); an empty array means none. */
150
- variables: Variable[] | null;
151
- /** How the ECU declared it exposes its variables. null if not declared, not checked, or from an older launcher. */
152
- control: ControlOffer | null;
153
- }
154
- export interface CheckNetwork {
155
- name: string | null;
156
- kind: string | null;
157
- /** Participant names in use (in configuration file order). */
158
- participants: string[];
159
- }
160
- export type CheckOutcome = Open<'passed' | 'failed' | 'unreadable' | 'usage'>;
161
- /** Result of `vehicle_sil_launch check --json` (format version 1). */
162
- export interface CheckResult {
163
- file: string | null;
164
- result: CheckOutcome;
165
- errors: number;
166
- warnings: number;
167
- notes: number;
168
- stop_at_ms: number | null;
169
- participants: CheckParticipant[];
170
- networks: CheckNetwork[];
171
- findings: Finding[];
172
- /** The scenario (only for a check with `--scenario`; null otherwise). */
173
- scenario: CheckScenario | null;
174
- }
175
- /** Reads a check result. With u, part by part. */
176
- export declare const readCheckResult: (value: unknown, path: string, u?: Unreadable) => CheckResult;
177
- export interface RunParticipant {
178
- name: string;
179
- required: boolean;
180
- enabled: boolean;
181
- /**
182
- * A participant the user started (or is to start). ended stays not_started (the joined event tells whether it
183
- * joined).
184
- */
185
- manual: boolean;
186
- ended: Open<'exited' | 'stopped' | 'killed' | 'not_started'>;
187
- exit_code: number | null;
188
- signal: string | null;
189
- left_processes: boolean;
190
- /** State of the connection to the ECU's variables at the start (null from older launchers, which do not write it). */
191
- control_link: ControlLink | null;
192
- }
193
- /**
194
- * State of the connection to the ECU's variables (the launcher's control links). The launcher's words appear only here
195
- * (unknown values pass through as strings, in case names are added or changed).
196
- * connected: variables can be read and written; no_hello: the ECU declared that it exposes variables but no hello
197
- * came; version_mismatch: the format versions differ; not_offered: the ECU has variables but did not declare that it
198
- * exposes them (--no-control, an older executable); none: not an ECU that exposes variables.
199
- */
200
- export type ControlState = Open<'connected' | 'no_hello' | 'version_mismatch' | 'not_offered' | 'none'>;
201
- /** Name of the launcher event (state of the connection to the ECU's variables). */
202
- export declare const CONTROL_EVENT = "control_link";
203
- /** Key (an object) for the variable interface's connection in participants[] of the launcher's result. */
204
- export declare const CONTROL_RESULT_KEY = "control_link";
205
- /**
206
- * Field for the variable interface's connection in participants[] of the GUI server's summary (the event fields laid
207
- * over each other).
208
- */
209
- export declare const CONTROL_SUMMARY_KEY = "control_link";
210
- /** Field in participants[] of the check result for how the ECU declared it exposes its variables. */
211
- export declare const CONTROL_CHECK_KEY = "control";
212
- /** How the ECU declared it exposes its variables (participants[].control of the check). */
213
- export interface ControlOffer {
214
- /** Transport (silkit for now). */
215
- transport: string;
216
- /** Format version of the messages. */
217
- wire_version: number | null;
218
- }
219
- /**
220
- * The launcher's control_link event and result (and control_link of a participant in the summary): how a participant's
221
- * variable interface is connected.
222
- */
223
- export interface ControlLink {
224
- state: ControlState;
225
- /** connected: number of variables the ECU exposes. */
226
- variables: number | null;
227
- /** version_mismatch: the other side's format version. */
228
- version: number | null;
229
- /** Number of messages that arrived later than promised (result only; events lack it, so null). */
230
- late_messages: number | null;
231
- }
232
- /** Name of the run result (`result.result` of the `result` event). */
233
- export type RunResultName = Open<'passed' | 'failed' | 'interrupted' | 'check_failed' | 'unreadable' | 'setup_failed' | 'usage'>;
234
- /**
235
- * The result's timing: how time advanced (the numbers are defined in "Running at a set speed (`speed`)" in
236
- * docs/simulation-run.md). null in the result when nothing was started, or from an older launcher. Each field is null
237
- * when it is missing or cannot be read.
238
- */
239
- export interface RunTiming {
240
- /** Speed at the end. */
241
- speed: Speed;
242
- /** The controller's time step (ms). A step command is rounded up to a multiple of it. */
243
- time_step_ms: number | null;
244
- ecu_step_ms: number | null;
245
- /** Maximum by which an ECU step runs late because the time step is coarser than the ECU's step (ms). */
246
- step_delay_ms: number | null;
247
- late_tolerance_ms: number | null;
248
- sim_ms: number | null;
249
- /** Real time taken (including time spent paused). */
250
- wall_ms: number | null;
251
- actual_speed: number | null;
252
- /** Number of paced time steps. 0 means it ran as fast as possible (lateness not counted). */
253
- paced_steps: number | null;
254
- late_steps: number | null;
255
- max_late_ms: number | null;
256
- slipped_ms: number | null;
257
- late_ms: number | null;
258
- paused_ms: number | null;
259
- }
260
- /** Result of `vehicle_sil_launch run --json` (format version 1). */
261
- export interface RunResult {
262
- file: string | null;
263
- result: RunResultName;
264
- errors: number;
265
- warnings: number;
266
- notes: number;
267
- simulation: string | null;
268
- interrupted_by: string | null;
269
- /** How time advanced. null from older launchers, and when nothing was started. */
270
- timing: RunTiming | null;
271
- participants: RunParticipant[];
272
- findings: Finding[];
273
- check: CheckResult | null;
274
- /** Result of the scenario (only for a run with `--scenario`; null otherwise). */
275
- scenario: ScenarioResult | null;
276
- }
277
- /**
278
- * Reads a run result. With u, part by part: a result the server shrank to fit its limits (only the short, non-nested
279
- * fields) is still read as a result (participants and findings become empty and go into the unreadable parts). ''
280
- * if the result's name cannot be read.
281
- */
282
- export declare const readRunResult: (value: unknown, path: string, u?: Unreadable) => RunResult;
283
- /** Phases. They advance in this order; one may be skipped, but they never go back. */
284
- export declare const PHASES: readonly ["checking", "starting", "waiting", "running", "stopping", "ended"];
285
- export type Phase = Open<(typeof PHASES)[number]>;
286
- export type ParticipantState = Open<'disabled' | 'not_started' | 'started'
287
- /** Not started because the user starts this participant (instead of started). joined follows once it joins. */
288
- | 'manual' | 'joined' | 'failed' | 'ended' | 'stop_requested' | 'killed'>;
289
- interface EventBase {
290
- seq: number;
291
- /** Real time since the launcher started (ms). Some events lack it (the server passes them through without it). */
292
- t_ms: number | null;
293
- /**
294
- * Names of the fields that could not be read (prefixed with the event kind, as in `finding.code`). Absent if none.
295
- */
296
- unreadable?: string[];
297
- }
298
- export type LauncherEvent = (EventBase & {
299
- event: 'hello';
300
- vehicle_sil_events: number;
301
- vehicle_sil: string;
302
- pid: number | null;
303
- file: string | null;
304
- arguments: string[];
305
- }) | (EventBase & {
306
- event: 'phase';
307
- phase: Phase;
308
- }) | (EventBase & {
309
- event: 'check';
310
- check: CheckResult | null;
311
- }) | (EventBase & {
312
- event: 'registry';
313
- uri: string | null;
314
- }) | (EventBase & {
315
- event: 'participant';
316
- name: string;
317
- state: ParticipantState;
318
- pid: number | null;
319
- exit_code: number | null;
320
- signal: string | null;
321
- /**
322
- * failed: why it was counted as failed (left_simulation, process_ended, ended_before_start; more may be added).
323
- */
324
- reason: string | null;
325
- /** not_started: why it could not be started. failed: the text of that finding (if decided). */
326
- message: string | null;
327
- /** manual: the command that starts it, as one line to paste into this OS's shell (as the launcher wrote it). */
328
- command_line: string | null;
329
- /** manual: the directory to run that command in. */
330
- working_directory: string | null;
331
- /**
332
- * manual: environment variables to set when starting it (names and values). Only when the registry is not on a
333
- * loopback address (`{"VEHICLE_SIL_LISTEN_ON_NETWORK": "1"}`). null if none.
334
- */
335
- environment: Record<string, string> | null;
336
- }) | (EventBase & {
337
- event: 'log';
338
- source: string;
339
- line: string;
340
- })
341
- /** State of the connection to the ECU's variables (once per started participant, just before the start). */
342
- | (EventBase & {
343
- event: typeof CONTROL_EVENT;
344
- name: string;
345
- link: ControlLink;
346
- })
347
- /**
348
- * Number of log lines the launcher could not write because the reader was slow (per source). Arrives at their
349
- * position.
350
- */
351
- | (EventBase & {
352
- event: 'log_dropped';
353
- count: number;
354
- sources: Record<string, number>;
355
- }) | (EventBase & {
356
- event: 'finding';
357
- finding: Finding;
358
- }) | (EventBase & {
359
- event: 'time';
360
- } & TimeReport) | (EventBase & {
361
- event: 'command';
362
- } & CommandReport)
363
- /** A scenario step started (status running) or was decided. */
364
- | (EventBase & {
365
- event: 'scenario_step';
366
- step: ScenarioStep;
367
- }) | (EventBase & {
368
- event: 'result';
369
- result: RunResult;
370
- });
371
- /**
372
- * The time event (and time of the summary): the virtual time the controller sees, and how it advances. Older launchers
373
- * write only sim_ms, so the other fields are null when absent or unreadable (the screen does not show null values).
374
- */
375
- export interface TimeReport {
376
- /** Virtual time (ms; never decreases). */
377
- sim_ms: number;
378
- /** The current speed (a number or 'max'). null if not written. */
379
- speed: Speed;
380
- /** Whether it is paused (true once it reaches the time it was to stop at). null if not written. */
381
- paused: boolean | null;
382
- /** Actual speed over roughly the last second. null when it has run only briefly, or while paused. */
383
- actual_speed: number | null;
384
- /** Number of late time steps so far (the value if it ended now; 0 when running as fast as possible). */
385
- late_steps: number | null;
386
- /** Max lateness so far (ms). */
387
- max_late_ms: number | null;
388
- /** Total slip so far (ms). */
389
- slipped_ms: number | null;
390
- /** Current lateness of a time step that is past its deadline and has not started yet (ms; 0 if none). */
391
- late_ms: number | null;
392
- }
393
- /** The command event (and last_command of the summary): whether the launcher accepted a command from stdin. */
394
- export interface CommandReport {
395
- /** Name of the command (null for an unreadable line). */
396
- command: string | null;
397
- /** stdin: arrived as a line; eof: end of stdin. */
398
- source: Open<'stdin' | 'eof'>;
399
- accepted: boolean;
400
- /** Why it was not accepted (shown in English, unchanged). null if accepted. */
401
- message: string | null;
402
- /**
403
- * For an accepted step, the virtual time it actually advances (rounded up to a multiple of the time step). null
404
- * otherwise.
405
- */
406
- ms: number | null;
407
- }
408
- /**
409
- * last_command of the summary: the event's fields and that event's seq (null from older servers, which do not write
410
- * it).
411
- */
412
- export type SummaryCommand = CommandReport & {
413
- seq: number | null;
414
- };
415
- /**
416
- * Reads one launcher event. An unknown event is null (skipped). If partly is true, reads part by part: an unreadable
417
- * field gets its default value and its name goes into unreadable (throws only when the core seq and event, or the core
418
- * fields of the event kind, cannot be read).
419
- */
420
- export declare const readLauncherEvent: (value: unknown, path: string, partly?: boolean) => LauncherEvent | null;
421
- /**
422
- * A server notice (an API error, a WebSocket error, problems of the session). message is shown in English, unchanged.
423
- */
424
- export interface ServerProblem {
425
- code: string;
426
- message: string;
427
- /** For launcher-stderr, the number of lines dropped at this point (`detail.skipped`). Other notices lack it. */
428
- skipped?: number;
429
- }
430
- /** Reads a server notice (`{code, message, detail}`). The `error` in an HTTP error has the same shape. */
431
- export declare const readServerProblem: Reader<ServerProblem>;
432
- /**
433
- * Speed. 'max' is as fast as possible; a number is a factor (1 is real-time speed). null means the launcher's default
434
- * (the value in the configuration file) when given at the start, and "not written" in a value the launcher writes.
435
- */
436
- export type Speed = null | number | 'max';
437
- /** GET api/app: versions of the server and the launcher, whether they are usable, and limits. */
438
- export interface AppInfo {
439
- version: string;
440
- /** An identifier that changes every time the server starts. If it changed, the server restarted. */
441
- instance: string;
442
- /** Where configuration files can be chosen from (for display). */
443
- root: string;
444
- /** The configuration file given at start-up (relative to root). null if none. */
445
- initial_file: string | null;
446
- launcher: {
447
- path: string | null;
448
- /** Whether the launcher has the features the screen needs. */
449
- usable: boolean;
450
- /** Why it is unusable (shown in English, unchanged). */
451
- problems: ServerProblem[];
452
- features: string[];
453
- };
454
- limits: {
455
- speed_min: number;
456
- speed_max: number;
457
- /** Upper limit of the ms of a step. Older servers do not write it, so the launcher's limit (10^12). */
458
- step_ms_max: number;
459
- /** Time limit of a check (s; `--check-timeout`). Older servers do not write it, so its default (120). */
460
- check_timeout_s: number;
461
- /**
462
- * Variable watches: lower and upper limit of the interval (ms), number per connection, variables that can be named
463
- * in one.
464
- */
465
- watch_period_ms_min: number;
466
- watch_period_ms_max: number;
467
- watches: number;
468
- watch_variables: number;
469
- /** Limit on the variables in one write, and limit on the virtual time (ms) a write can name. */
470
- writes_per_request: number;
471
- write_at_ms_max: number;
472
- };
473
- /**
474
- * Whether variables could be read and written if a run started now (the launcher has a Control Server and the GUI
475
- * server has gRPC), and why not (shown in English, unchanged). Older servers do not write it (available is false,
476
- * reason is null).
477
- */
478
- variables: {
479
- available: boolean;
480
- reason: string | null;
481
- };
482
- }
483
- export declare const readAppInfo: (value: unknown) => AppInfo;
484
- /** One entry of GET api/configs. */
485
- export interface ConfigFile {
486
- /** Path relative to root (separator /). */
487
- path: string;
488
- }
489
- /** GET api/configs: the configuration files under root. */
490
- export interface ConfigList {
491
- files: ConfigFile[];
492
- /** Whether the list was cut off at the limit. */
493
- truncated: boolean;
494
- }
495
- export declare const readConfigList: (value: unknown) => ConfigList;
496
- /** Body of POST api/check. */
497
- export interface CheckRequest {
498
- /** Path relative to root. */
499
- file: string;
500
- /** Names of the participants to leave out (only names in the check result). */
501
- disable: string[];
502
- /**
503
- * Names of the participants the user starts (only names in the check result that are not in disable). Send only when
504
- * the launcher's `features` include `manual-participants`.
505
- */
506
- manual?: string[];
507
- /**
508
- * The scenario (`path` from `GET api/scenarios`; only one in the list for that configuration file). Omitted or null
509
- * means none. Send only when the launcher's `features` include `scenario`.
510
- */
511
- scenario?: string | null;
512
- }
513
- /** One entry of GET api/scenarios. */
514
- export interface ScenarioFile {
515
- /** Path relative to root (send it as is in `scenario` of api/check and api/run). */
516
- path: string;
517
- /** File name. */
518
- name: string;
519
- }
520
- /** GET api/scenarios: the .yaml and .yml files in `scenarios` next to the configuration file. */
521
- export interface ScenarioList {
522
- /** The configuration file (relative to root). */
523
- file: string;
524
- /** The scenario directory (relative to root). */
525
- directory: string;
526
- /** Whether the directory exists (a symbolic link to a directory counts as absent). */
527
- found: boolean;
528
- scenarios: ScenarioFile[];
529
- truncated: boolean;
530
- }
531
- export declare const readScenarioList: (value: unknown) => ScenarioList;
532
- /**
533
- * GET api/recording: the values written through the GUI server and applied in the current (or last) run, as scenario
534
- * YAML. The server writes no file (the screen hands it over as a browser download).
535
- */
536
- export interface Recording {
537
- session_id: number;
538
- /** The run's configuration file (relative to root). */
539
- file: string;
540
- state: Open<'running' | 'ended'>;
541
- /** Whether this run is being recorded (false for a run without variables and for a scenario run). */
542
- available: boolean;
543
- /** Why there is no yaml (shown in English, unchanged). */
544
- reason: string | null;
545
- /** Number of values put in the YAML. */
546
- writes: number;
547
- /** Number of values beyond the limit that were left out. */
548
- omitted: number;
549
- /** Number of steps (`set`) in the YAML. */
550
- steps: number;
551
- /** Scenario YAML. null while no write has been applied yet. */
552
- yaml: string | null;
553
- }
554
- /** Answer of GET api/recording (null if there has been no run yet). */
555
- export declare const readRecording: (value: unknown) => Recording | null;
556
- /** Takes the launcher's check result out of the answer to POST api/check. */
557
- export declare const readCheckResponse: (value: unknown) => CheckResult;
558
- /** Body of POST api/run. */
559
- export interface RunRequest extends CheckRequest {
560
- speed: Speed;
561
- start_paused: boolean;
562
- }
563
- /**
564
- * A participant in the session summary (the participant events laid over each other per name; fields not received yet
565
- * are null).
566
- */
567
- export interface SummaryParticipant {
568
- name: string;
569
- state: ParticipantState | null;
570
- pid: number | null;
571
- exit_code: number | null;
572
- signal: string | null;
573
- /** reason of the failed event (why it was counted as failed; kept even if ended arrives later). */
574
- reason: string | null;
575
- /** The reason of not_started, or the text of the failed finding. */
576
- message: string | null;
577
- /** Names of fields too large to put in the summary (cleared once a later event delivers the field). */
578
- omitted_fields: string[];
579
- /** The launcher asked it to stop (a stop_requested event arrived; kept in later states). */
580
- stop_requested: boolean;
581
- /** command_line of the manual event (the command that starts it, as one line). null if none. */
582
- command_line: string | null;
583
- /** working_directory of the manual event. null if none. */
584
- working_directory: string | null;
585
- /** environment of the manual event (environment variables to set when starting it). null if none. */
586
- environment: Record<string, string> | null;
587
- /** State of the connection to the ECU's variables (the launcher's control_link event). null until it arrives. */
588
- control_link: ControlLink | null;
589
- }
590
- /** launcher of the summary: whether the launcher process is running and, if it ended, how. */
591
- export interface SummaryLauncher {
592
- /**
593
- * Whether it is running. Stays true after it printed the result, until the process exits. Decides whether it can be
594
- * stopped.
595
- */
596
- running: boolean;
597
- exit_code: number | null;
598
- /** Number of the signal that ended it (POSIX only). */
599
- signal: number | null;
600
- /**
601
- * Running but has written nothing for longer than this many seconds (no heartbeat either; it may be stuck). null if
602
- * not.
603
- */
604
- silent_s: number | null;
605
- }
606
- /**
607
- * The stop the server requested from the launcher. none: not requested; requested: stop in order; forced: stop without
608
- * waiting.
609
- */
610
- export type StopRequest = Open<'none' | 'requested' | 'forced'>;
611
- /** Per source, the number of lines the server holds and has dropped. */
612
- export interface LogCounts {
613
- kept: number;
614
- dropped: number;
615
- }
616
- /**
617
- * Summary of a server session (one run of the launcher). The screen rebuilds its state from it (the summary is
618
- * authoritative).
619
- */
620
- export interface SessionSummary {
621
- id: number;
622
- /** Path relative to root. */
623
- file: string;
624
- disable: string[];
625
- /**
626
- * Participants the user chose on the screen to start themselves (`--manual`; `manual: true` in the configuration file
627
- * is in the check result).
628
- */
629
- manual: string[];
630
- /** Speed given at the start (null means as in the configuration file). The current speed is time.speed. */
631
- speed: Speed;
632
- /** Whether the run started paused. */
633
- start_paused: boolean;
634
- /** State as the server sees it. `ended` means the launcher has exited and its output has been read to the end. */
635
- state: Open<'running' | 'ended'>;
636
- launcher: SummaryLauncher;
637
- stop: StopRequest;
638
- phase: Phase | null;
639
- last_seq: number | null;
640
- /** t_ms of the last event received. */
641
- last_t_ms: number | null;
642
- /** Virtual time of the last time event. */
643
- sim_ms: number | null;
644
- /** Names of the fields of the last time event too large to put in the summary. */
645
- time_omitted_fields: string[];
646
- /** The last time event (virtual time, speed, pause, lateness figures). null until it arrives. */
647
- time: TimeReport | null;
648
- /** The last command event (whether it was accepted, and why not). null until it arrives. */
649
- last_command: SummaryCommand | null;
650
- /**
651
- * The check result of this run (the check event). null until it arrives. The `session` notifications of a connection
652
- * that asked for `session_without_check` lack the field and read it as null (the local check result is used as is).
653
- */
654
- check: CheckResult | null;
655
- participants: SummaryParticipant[];
656
- findings: Finding[];
657
- result: RunResult | null;
658
- /** Per source, the number of lines the server holds and has dropped. */
659
- log: Record<string, LogCounts>;
660
- problems: ServerProblem[];
661
- problems_omitted: number;
662
- /** Progress of the scenario run (`scenario` of `api/run`). null for a run without a scenario. */
663
- scenario: SummaryScenario | null;
664
- /**
665
- * Names of the parts that could not be read (`result.participants`, `findings.code` and so on; set by the screen,
666
- * not a server field). The missing fields of a result shrunk to fit the limits go here too.
667
- */
668
- unreadable: string[];
669
- }
670
- /**
671
- * `scenario` of the summary: what the server put together from the check, the `scenario_step` events and the result.
672
- */
673
- export interface SummaryScenario {
674
- /** The scenario file (relative to root). */
675
- file: string;
676
- name: string | null;
677
- /** Number of steps (from the check result; null until then). */
678
- step_count: number | null;
679
- /** Steps received (in index order). After the result, every step (not_run included). */
680
- steps: ScenarioStep[];
681
- /** Number of steps beyond the limit that were not kept. */
682
- steps_omitted: number;
683
- /** status of the result (null until there is a result). */
684
- status: ScenarioStatus | null;
685
- over_at_ms: number | null;
686
- }
687
- /**
688
- * Reads a session summary part by part. Throws if the core (id, state, launcher, stop) cannot be read. Any other part
689
- * that cannot be read gets its default value (null, empty) and its name goes into unreadable.
690
- */
691
- export declare const readSessionSummary: Reader<SessionSummary>;
692
- /** Answer of GET api/session, POST api/run and POST api/stop (the current session; null if none). */
693
- export declare const readSessionResponse: (value: unknown) => SessionSummary | null;
694
- /**
695
- * Body of POST api/stop. force: false stops in order (asking again has no further effect); true stops without waiting.
696
- */
697
- export interface StopRequestBody {
698
- force: boolean;
699
- }
700
- /** Names of the time commands (the launcher's stdin commands other than stop). */
701
- export type TimeCommandName = 'pause' | 'resume' | 'step' | 'speed';
702
- /**
703
- * Body of POST api/time. The server passes it to the launcher as one line and returns at once. Whether it was accepted
704
- * arrives as a command event, and its effect as a time event.
705
- */
706
- export type TimeCommand = {
707
- command: 'pause';
708
- } | {
709
- command: 'resume';
710
- }
711
- /** Only while paused. Advances by ms and pauses again (the launcher rounds up to a multiple of the time step). */
712
- | {
713
- command: 'step';
714
- ms: number;
715
- } | {
716
- command: 'speed';
717
- value: number | 'max';
718
- };
719
- /** Answer of POST api/time: the number of the run it was sent to, and the command passed to the launcher. */
720
- export interface TimeAnswer {
721
- session_id: number;
722
- command: TimeCommandName;
723
- }
724
- export declare const readTimeResponse: (value: unknown) => TimeAnswer;
725
- /**
726
- * The first message sent right after connecting. With session and from_seq, the server resends from where that left
727
- * off.
728
- */
729
- /** Definition of one variable (`variables.peers[].variables[]` of the summary). */
730
- export interface VariableSummary {
731
- name: string;
732
- type: Open<'bool' | 'integer' | 'real' | 'enum'>;
733
- role: Open<'input' | 'output' | 'parameter'>;
734
- writable: boolean;
735
- unit: string;
736
- min: number | null;
737
- max: number | null;
738
- step: number | null;
739
- description: string;
740
- /** Items of an enum (when type is enum; null otherwise). */
741
- enum: {
742
- name: string;
743
- value: number;
744
- }[] | null;
745
- }
746
- /** Result of a write (the `operation` notification, and `variables.operations[]` of the summary). */
747
- export interface OperationReport {
748
- seq: number;
749
- /** sent, queued (in progress). Once settled: applied, late, rejected, cancelled, invalid, busy, unknown, mixed. */
750
- state: string;
751
- done: boolean;
752
- peers: Record<string, {
753
- state: string;
754
- applied_at_ms: number | null;
755
- late: boolean;
756
- reason: string | null;
757
- }>;
758
- }
759
- /** `variables` of the summary: state of the variable API, variables per participant, recent operations. */
760
- export interface VariablesSummary {
761
- state: Open<'off' | 'connecting' | 'ready' | 'failed' | 'ended'>;
762
- reason: string | null;
763
- peers: {
764
- name: string;
765
- connected: boolean;
766
- variables: VariableSummary[];
767
- }[];
768
- peers_omitted: number;
769
- variables_omitted: number;
770
- /** Every unsettled operation (those the server keeps), and the recent operations. */
771
- operations: OperationReport[];
772
- /** Every operation numbered at or above this is in operations (null from a server that does not say). */
773
- operations_from_seq: number | null;
774
- /** Number of unsettled operations the server could not keep (normally 0). */
775
- operations_open_omitted: number;
776
- }
777
- /** Reads `variables` of a summary (present in `hello` and HTTP summaries, absent from `session` notifications). */
778
- export declare const readVariablesSummary: (value: unknown) => VariablesSummary;
779
- /** The `values` notification: the last values of the watched variables, and when they are from. */
780
- export interface ValuesMessage {
781
- type: 'values';
782
- /** id of the watch. */
783
- id: number;
784
- session: number;
785
- /** The controller's virtual time (ms; null if unknown). */
786
- sim_ms: number | null;
787
- /** true: paused, and the values include every step that began before sim_ms. */
788
- paused: boolean;
789
- /**
790
- * Per participant, the virtual time of the step that read the values, and the values (null for a non-finite real).
791
- */
792
- peers: Record<string, {
793
- sample_ms: number;
794
- values: Record<string, number | boolean | null>;
795
- }>;
796
- }
797
- /** Answer of `api/write`. */
798
- export interface WriteAnswer {
799
- session_id: number;
800
- /** Operation number. The result arrives in `operation` notifications. */
801
- operation: number;
802
- }
803
- export declare const readWriteResponse: (value: unknown) => WriteAnswer;
804
- /**
805
- * One error in a dashboard file: line and column (from 1), location in the data (`sections[0].items[2].widget`), and
806
- * English text that says how to fix it.
807
- */
808
- export interface DashboardFileError {
809
- line: number;
810
- column: number;
811
- at: string;
812
- message: string;
813
- }
814
- /** A variable written in the file (`<participant>.<variable name>` split up). */
815
- export interface DashboardVariable {
816
- peer: string;
817
- name: string;
818
- }
819
- /**
820
- * An item in the file, of exactly one of these shapes (the parser drops items of an unknown shape).
821
- * - variable: shows a variable with a widget (the default widget if widget is null).
822
- * - panel: a custom panel (the name of a custom element).
823
- * - auto: the variables of that participant not placed elsewhere in the file (with the default widgets).
824
- */
825
- export type DashboardFileItem = {
826
- variable: DashboardVariable;
827
- widget: string | null;
828
- label: string | null;
829
- options: Record<string, unknown>;
830
- } | {
831
- panel: string;
832
- label: string | null;
833
- options: Record<string, unknown>;
834
- variables: DashboardVariable[];
835
- } | {
836
- auto: string;
837
- };
838
- /** A section of the file. */
839
- export interface DashboardFileSection {
840
- title: string;
841
- collapsed: boolean;
842
- items: DashboardFileItem[];
843
- }
844
- /** A custom panel module: the name written in the file, and the URL to load (relative to the screen's base). */
845
- export interface DashboardPanelModule {
846
- module: string;
847
- url: string;
848
- }
849
- /** Contents of a dashboard file, as checked by the server. */
850
- export interface DashboardFile {
851
- title: string | null;
852
- panels: DashboardPanelModule[];
853
- sections: DashboardFileSection[];
854
- }
855
- /**
856
- * `GET api/dashboard?file=<configuration file>`: `<name>.dashboard.yaml` next to the configuration file. When there is
857
- * none (found is false) or it has errors (errors; dashboard is null), the screen uses the automatic dashboard.
858
- */
859
- export interface DashboardResponse {
860
- /** The configuration file (relative to root). */
861
- file: string;
862
- /** The dashboard file (relative to root). */
863
- path: string;
864
- found: boolean;
865
- errors: DashboardFileError[];
866
- dashboard: DashboardFile | null;
867
- }
868
- export declare const readDashboardResponse: (value: unknown) => DashboardResponse;
869
- /**
870
- * Notifications the screen sends after authentication: start a variable watch (replacing one with the same id), or stop
871
- * it.
872
- */
873
- export type WatchMessage = {
874
- type: 'watch';
875
- id: number;
876
- variables: 'all' | {
877
- peer: string;
878
- name: string;
879
- }[];
880
- period_ms?: number;
881
- } | {
882
- type: 'unwatch';
883
- id: number;
884
- };
885
- export interface AuthMessage {
886
- type: 'auth';
887
- token: string;
888
- session?: number;
889
- from_seq?: number;
890
- /**
891
- * If true, the summaries in this connection's `session` notifications leave out `check` (it arrives in the `hello`
892
- * summary and the `check` event), because the check result is large and does not change during the run.
893
- */
894
- session_without_check?: boolean;
895
- }
896
- /** replay of hello: where the resend starts (null: from the beginning). */
897
- export interface Replay {
898
- from_seq: number | null;
899
- }
900
- /** dropped: how much was not sent to this screen. */
901
- export interface Dropped {
902
- type: 'dropped';
903
- session: number | null;
904
- /**
905
- * not-kept: the server no longer holds it (before the resend); slow-client: the screen read too slowly and the server
906
- * dropped some of what it was to send.
907
- */
908
- reason: Open<'not-kept' | 'slow-client'>;
909
- /** Per source, the number of log lines dropped. */
910
- log: Record<string, number>;
911
- /** Sources whose count is only a lower bound (more may have been dropped). */
912
- at_least: string[];
913
- /** Number of other events dropped. */
914
- events: number;
915
- }
916
- export type ServerMessage =
917
- /**
918
- * Right after connecting (and after resync): summary of the current session, and a description of the resend that
919
- * follows.
920
- */
921
- {
922
- type: 'hello';
923
- instance: string;
924
- session: SessionSummary | null;
925
- replay: Replay | null;
926
- }
927
- /** A launcher event (resent log lines as well as new events). */
928
- | {
929
- type: 'event';
930
- session: number;
931
- event: LauncherEvent;
932
- }
933
- /** The resend has finished. */
934
- | {
935
- type: 'synced';
936
- session: number | null;
937
- last_seq: number | null;
938
- }
939
- /** The session summary changed (started, stop requested, the launcher exited, the run ended). */
940
- | {
941
- type: 'session';
942
- session: SessionSummary;
943
- }
944
- /**
945
- * A server notice (a gap in seq, an invalid line from the launcher, an end without a result, failed authentication
946
- * and so on).
947
- */
948
- | ({
949
- type: 'error';
950
- session: number | null;
951
- } & ServerProblem)
952
- /** How much was not sent. */
953
- | Dropped
954
- /** The screen read too slowly and messages were dropped. Everything is sent again, starting with hello. */
955
- | {
956
- type: 'resync';
957
- message: string;
958
- }
959
- /** The state or the list of the variable API changed (also once right after a run starts). */
960
- | {
961
- type: 'variables';
962
- session: number;
963
- variables: VariablesSummary;
964
- }
965
- /** Values of the watched variables. */
966
- | ValuesMessage
967
- /** The result of a write changed. */
968
- | ({
969
- type: 'operation';
970
- session: number;
971
- } & OperationReport);
972
- /**
973
- * Reads one WebSocket notification. Unknown notifications, and notifications wrapping an unknown event, are null
974
- * (skipped).
975
- */
976
- export declare const readServerMessage: (value: unknown) => ServerMessage | null;
977
- export {};
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';