@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,61 @@
|
|
|
1
|
+
import type { ConnectionState } from './connection.js';
|
|
2
|
+
import type { AppInfo, ServerAllowed } from './protocol.js';
|
|
3
|
+
import { SessionView } from './session-state.js';
|
|
4
|
+
import type { Control, FrontClock, FrontControls, FrontResult, FrontStatus, Link, OperationName, Reason, RunState } from './front-types.js';
|
|
5
|
+
/** Everything the composition reads. */
|
|
6
|
+
export interface Snapshot {
|
|
7
|
+
connection: ConnectionState;
|
|
8
|
+
/** How many times the socket closed before it opened. */
|
|
9
|
+
failures: number;
|
|
10
|
+
/** The socket was closed at least once since it last received a notification. */
|
|
11
|
+
closedBefore: boolean;
|
|
12
|
+
rejected: boolean;
|
|
13
|
+
/** Why the versions differ (null if they match). */
|
|
14
|
+
incompatible: string | null;
|
|
15
|
+
/** The session copy matches the server. */
|
|
16
|
+
ready: boolean;
|
|
17
|
+
session: SessionView | null;
|
|
18
|
+
/** What the GUI server accepts (null until it says). */
|
|
19
|
+
allowed: ServerAllowed | null;
|
|
20
|
+
limits: AppInfo['limits'];
|
|
21
|
+
/** Operations of this page whose request has not been answered yet. */
|
|
22
|
+
busy: ReadonlySet<OperationName>;
|
|
23
|
+
}
|
|
24
|
+
export declare function linkOf(s: Snapshot): Link;
|
|
25
|
+
export declare function runOf(s: Snapshot): RunState;
|
|
26
|
+
export declare function resultFor(s: Snapshot, run: RunState): FrontResult | null;
|
|
27
|
+
export declare function statusOf(s: Snapshot, initialFile: string | null): Omit<FrontStatus, 'problem'>;
|
|
28
|
+
/**
|
|
29
|
+
* Where virtual time is, as far as the session copy knows: the last time event, or the time the launcher's state says
|
|
30
|
+
* it stands still at (`paused_at_ms`), whichever is later. The state can be ahead of the time events: the launcher
|
|
31
|
+
* writes the time event of a standstill at its next look.
|
|
32
|
+
*/
|
|
33
|
+
export declare function simMsOf(session: SessionView | null): number | null;
|
|
34
|
+
/**
|
|
35
|
+
* Where the launcher's latest state says the run stands still (`paused_at_ms`), or null: not paused, or paused but not
|
|
36
|
+
* yet standing at a time (a run_until to a time already passed, at the maximum speed, until the next step). A time event
|
|
37
|
+
* is not used: the last one can be from before the run stood still.
|
|
38
|
+
*/
|
|
39
|
+
export declare function standsAt(session: SessionView | null): number | null;
|
|
40
|
+
/**
|
|
41
|
+
* Whether a step or a run_until that the launcher accepted has not been seen to arrive. It has arrived when the latest
|
|
42
|
+
* state says the run stands still at or after the `at_ms` of its command event (standsAt). Another command after it (a
|
|
43
|
+
* pause, a resume) ends the question (it is then the last command), and so does the end of the run.
|
|
44
|
+
*/
|
|
45
|
+
export declare function onItsWay(session: SessionView | null): boolean;
|
|
46
|
+
export declare function clockOf(s: Snapshot): FrontClock;
|
|
47
|
+
export declare function controlsOf(s: Snapshot, run: RunState): FrontControls;
|
|
48
|
+
/** Whether the launcher takes a write now (`state.allowed.write` with the connection and the run). Not in `controls`: a variable says whether it can be written, and uses this. */
|
|
49
|
+
export declare function writeOf(s: Snapshot, run: RunState): Control;
|
|
50
|
+
/** What `status.problem` chooses from besides the connection. */
|
|
51
|
+
export interface Candidate {
|
|
52
|
+
/** Later is newer. */
|
|
53
|
+
stamp: number;
|
|
54
|
+
problem: Reason;
|
|
55
|
+
}
|
|
56
|
+
/** The connection's problem, if it has one (it beats every other). */
|
|
57
|
+
export declare function linkProblem(s: Snapshot): Reason | null;
|
|
58
|
+
/** The newest of the candidates (null if none). */
|
|
59
|
+
export declare function newest(candidates: readonly Candidate[]): Reason | null;
|
|
60
|
+
/** Structural equality of plain data (what the front's values are made of). */
|
|
61
|
+
export declare function sameData(a: unknown, b: unknown): boolean;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { GuiClient } from './client.js';
|
|
2
|
+
import type { Connections } from './protocol.js';
|
|
3
|
+
import type { ConnectEntry, Outside } from './front-types.js';
|
|
4
|
+
import { ErrorSink, Readable } from './values.js';
|
|
5
|
+
/**
|
|
6
|
+
* The entries of every backend of the answer, in its order: the targets of a backend that listed, and one entry with
|
|
7
|
+
* the launcher's sentence for a backend that could not (`list.error`). An error finding of the answer (a file that
|
|
8
|
+
* cannot be read) is an entry of its own, after them. A target without a `value` is left out.
|
|
9
|
+
*/
|
|
10
|
+
export declare function entriesOf(answer: Connections): ConnectEntry[];
|
|
11
|
+
/**
|
|
12
|
+
* The rows of `front.outside`: `outside[]` of the launcher's last `state` while the launcher of the run runs, each with
|
|
13
|
+
* the counts of the last `outside` event of its network in that run (null until one has arrived on this page: the
|
|
14
|
+
* server does not send old ones again after a reconnect). Returns the value and the function that stops it.
|
|
15
|
+
*/
|
|
16
|
+
export declare function outsideRows(low: GuiClient, onError: ErrorSink): {
|
|
17
|
+
value: Readable<readonly Outside[]>;
|
|
18
|
+
stop: () => void;
|
|
19
|
+
};
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import type { GuiClient } from './client.js';
|
|
2
|
+
import type { CheckResult, ConfigText, SavedConfig, Finding, OutsideState, RunEnd, ScenarioFile, ScenarioStatus, ScenarioStep } from './protocol.js';
|
|
3
|
+
import type { ValueCondition, WriteBlock, WriteStatus } from './variable-state.js';
|
|
4
|
+
import type { VariableRef, VariableValue } from './variables.js';
|
|
5
|
+
import type { Readable } from './values.js';
|
|
6
|
+
import type { Reason } from './session-state.js';
|
|
7
|
+
/** A reason: a code that stays the same and one English sentence (defined with the session copy, which reads them too). */
|
|
8
|
+
export type { Reason };
|
|
9
|
+
/** How the page stands with the GUI server. */
|
|
10
|
+
export type Link = 'connecting' | 'online' | 'offline' | 'rejected' | 'incompatible';
|
|
11
|
+
/**
|
|
12
|
+
* Where the run stands. `starting`: a start is on its way (this page's or another page's) or the launcher has not
|
|
13
|
+
* begun; `waiting`: the launcher waits for the participants to join (phase `waiting`; a run held before the first step with start_paused is `paused`); `ended`: the
|
|
14
|
+
* run has a result; `crashed`: the launcher ended without one.
|
|
15
|
+
*/
|
|
16
|
+
export type RunState = 'none' | 'starting' | 'waiting' | 'running' | 'paused' | 'stopping' | 'ended' | 'crashed';
|
|
17
|
+
/**
|
|
18
|
+
* How a run ended, as the launcher's result says (`end`). `crashed` is the client's own: the launcher ended without
|
|
19
|
+
* writing a result. A launcher newer than this library may write a value that is not listed.
|
|
20
|
+
*/
|
|
21
|
+
export type EndKind = RunEnd | 'crashed';
|
|
22
|
+
/** The result of the last run. */
|
|
23
|
+
export interface FrontResult {
|
|
24
|
+
/** null when nothing was started: the check failed, or the file or the command line could not be used. */
|
|
25
|
+
end: EndKind | null;
|
|
26
|
+
/** The scenario's verdict (null for a run without a scenario). */
|
|
27
|
+
scenario: ScenarioStatus | null;
|
|
28
|
+
/**
|
|
29
|
+
* Whether the run succeeded, as the launcher's result says (`ok`: its exit code is 0). A stop by the operator is a
|
|
30
|
+
* success, unless it cut a scenario short (the scenario has no verdict then).
|
|
31
|
+
*/
|
|
32
|
+
ok: boolean;
|
|
33
|
+
/** One English sentence for a person, as the launcher wrote it. */
|
|
34
|
+
message: string;
|
|
35
|
+
}
|
|
36
|
+
/** What a screen shows as the state (discrete values only; the time is in `clock`). */
|
|
37
|
+
export interface FrontStatus {
|
|
38
|
+
link: Link;
|
|
39
|
+
run: RunState;
|
|
40
|
+
/** The configuration file of the run (the last one if none is running); the start-up file when there has been no run. */
|
|
41
|
+
file: string | null;
|
|
42
|
+
/** Set while `run` is `ended` or `crashed`. */
|
|
43
|
+
result: FrontResult | null;
|
|
44
|
+
/** The one problem to tell the user now (null if none). The connection comes first; then the newer of the launcher's crash, the last action's failure and a failed run. */
|
|
45
|
+
problem: Reason | null;
|
|
46
|
+
}
|
|
47
|
+
/** Whether the run keeps to its speed. */
|
|
48
|
+
export type Pacing = 'not-paced' | 'on-time' | 'late';
|
|
49
|
+
/** Time and speed (changes often, so it is apart from `status`). */
|
|
50
|
+
export interface FrontClock {
|
|
51
|
+
/** Virtual time (ms); null until the first time event. */
|
|
52
|
+
sim_ms: number | null;
|
|
53
|
+
/** The speed that was asked for. */
|
|
54
|
+
speed: number | 'max' | null;
|
|
55
|
+
/** The speed over about the last second; null while paused or just started. */
|
|
56
|
+
actual_speed: number | null;
|
|
57
|
+
pacing: Pacing;
|
|
58
|
+
}
|
|
59
|
+
/** Whether one operation can be used now. `ok` is for a button: it is false also when the operation would change nothing. */
|
|
60
|
+
export interface Control {
|
|
61
|
+
ok: boolean;
|
|
62
|
+
/** Why not (null if ok). */
|
|
63
|
+
reason: Reason | null;
|
|
64
|
+
/** The operation is accepted, but something is worth knowing first (null if none). */
|
|
65
|
+
caution: Reason | null;
|
|
66
|
+
}
|
|
67
|
+
/** What each operation can do now. Built from the launcher's `state` and the GUI server's `allowed`. */
|
|
68
|
+
export interface FrontControls {
|
|
69
|
+
start: Control;
|
|
70
|
+
stop: Control;
|
|
71
|
+
force_stop: Control;
|
|
72
|
+
pause: Control;
|
|
73
|
+
resume: Control;
|
|
74
|
+
step: Control & {
|
|
75
|
+
min_ms: number;
|
|
76
|
+
max_ms: number;
|
|
77
|
+
};
|
|
78
|
+
run_until: Control;
|
|
79
|
+
/** `fastest`: whether the speed `'max'` is accepted besides the numbers from `min` to `max`. */
|
|
80
|
+
speed: Control & {
|
|
81
|
+
min: number;
|
|
82
|
+
max: number;
|
|
83
|
+
fastest: boolean;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* `saveConfig()`, from the GUI server's `allowed.save` (`save-disabled`: started with `--no-save`). `caution`
|
|
87
|
+
* `command-changes-allowed`: the server also saves edits that change the commands that run, and new files; show it
|
|
88
|
+
* near the save button. Whether one edit is saved is the server's answer to it, not this.
|
|
89
|
+
*/
|
|
90
|
+
save: Control;
|
|
91
|
+
}
|
|
92
|
+
/** The operations that have a control. */
|
|
93
|
+
export type OperationName = keyof FrontControls;
|
|
94
|
+
/** The progress of the scenario of the run. */
|
|
95
|
+
export interface FrontScenario {
|
|
96
|
+
file: string;
|
|
97
|
+
name: string | null;
|
|
98
|
+
status: ScenarioStatus | null;
|
|
99
|
+
steps: readonly ScenarioStep[];
|
|
100
|
+
/** Where the server serves the timeline of the run (null until the run has ended with one). */
|
|
101
|
+
timeline_url: string | null;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* An action that did not go through. `refused`: the owner said no (nothing happened). `unknown`: it may have been
|
|
105
|
+
* done (no answer, an answer that cannot be tied to the command, interrupted before it arrived): look at `status` and
|
|
106
|
+
* `clock` before sending it again.
|
|
107
|
+
*/
|
|
108
|
+
export declare class ActionError extends Error {
|
|
109
|
+
/** A code that stays the same: the owner's `reason` (`not-paused`, `check-failed`, ...) or the client's (`busy`, `no-answer`, `interrupted`, `timeout`, ...). */
|
|
110
|
+
readonly code: string;
|
|
111
|
+
readonly outcome: 'refused' | 'unknown';
|
|
112
|
+
/** For `check-failed`: the findings of the check that refused the start. */
|
|
113
|
+
readonly findings: readonly Finding[];
|
|
114
|
+
constructor(
|
|
115
|
+
/** A code that stays the same: the owner's `reason` (`not-paused`, `check-failed`, ...) or the client's (`busy`, `no-answer`, `interrupted`, `timeout`, ...). */
|
|
116
|
+
code: string, message: string, outcome: 'refused' | 'unknown',
|
|
117
|
+
/** For `check-failed`: the findings of the check that refused the start. */
|
|
118
|
+
findings?: readonly Finding[]);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* What a start asks for: the keys of the request file (`schema/run-request.schema.json`), with its names and value
|
|
122
|
+
* forms. A choice that is not made is left out of the object: there is no null.
|
|
123
|
+
*/
|
|
124
|
+
export interface Intent {
|
|
125
|
+
/** The format of the request file: 1, or left out (the client adds none). */
|
|
126
|
+
vehicle_sil_run_request?: 1;
|
|
127
|
+
disable?: string[];
|
|
128
|
+
enable?: string[];
|
|
129
|
+
manual?: string[];
|
|
130
|
+
/**
|
|
131
|
+
* A `path` of `scenarios()` (relative to the root of the GUI server, as the list gives it; the server turns it into
|
|
132
|
+
* the path the request file needs, which is relative to the configuration file's directory). Do not compose it.
|
|
133
|
+
*/
|
|
134
|
+
scenario?: string;
|
|
135
|
+
variant?: string;
|
|
136
|
+
params?: Record<string, string | number | boolean>;
|
|
137
|
+
speed?: number | 'max';
|
|
138
|
+
start_paused?: boolean;
|
|
139
|
+
strict?: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Network name to where it is connected outside the simulation: a `value` that `connections()` gave with `usable`
|
|
142
|
+
* true, as written there, or `'none'` (SIL Kit only; the same as leaving the network out). The server refuses a value
|
|
143
|
+
* that its last list of that network did not give (`target-not-listed`).
|
|
144
|
+
*/
|
|
145
|
+
connect?: Record<string, string>;
|
|
146
|
+
/** A run connected outside keeps real time (`realtime`, the launcher's default) unless `free` is chosen. */
|
|
147
|
+
time_policy?: 'realtime' | 'free';
|
|
148
|
+
}
|
|
149
|
+
/** A place where a network can be connected, as the bridge of one backend listed it. */
|
|
150
|
+
export interface ConnectTarget {
|
|
151
|
+
/** The bridge's backend (`packet`, `tap`, `socketcan`, `npcap`, ...); null if the list did not say. */
|
|
152
|
+
backend: string | null;
|
|
153
|
+
/** What `connect` gives the network. */
|
|
154
|
+
value: string;
|
|
155
|
+
label: string;
|
|
156
|
+
/** One English line from the bridge (state, and a device in use by another bridge). */
|
|
157
|
+
detail: string;
|
|
158
|
+
/** false: it cannot be chosen; `reason` says why. */
|
|
159
|
+
usable: boolean;
|
|
160
|
+
reason: string | null;
|
|
161
|
+
}
|
|
162
|
+
/** A backend whose bridge could not list (it is missing on this computer, or it failed). */
|
|
163
|
+
export interface ConnectListError {
|
|
164
|
+
backend: string | null;
|
|
165
|
+
/** The launcher's English sentence. */
|
|
166
|
+
error: string;
|
|
167
|
+
}
|
|
168
|
+
/** One entry of `connections()`: a target, or a backend that has no list. */
|
|
169
|
+
export type ConnectEntry = ConnectTarget | ConnectListError;
|
|
170
|
+
/**
|
|
171
|
+
* A network connected outside the simulation in the run (`outside[]` of the launcher's `state`), with the counts of its
|
|
172
|
+
* `outside` events.
|
|
173
|
+
*/
|
|
174
|
+
export interface Outside {
|
|
175
|
+
network: string;
|
|
176
|
+
target: string | null;
|
|
177
|
+
/** The bridge (`bridge.<network>`). */
|
|
178
|
+
participant: string | null;
|
|
179
|
+
/** Ethernet: `up`, `down` or `unknown` (null before the bridge has said). */
|
|
180
|
+
link: OutsideState['link'];
|
|
181
|
+
/** CAN: `active`, `passive`, `bus-off` or `unknown` (null for Ethernet, or before the bridge has said). */
|
|
182
|
+
bus: OutsideState['bus'];
|
|
183
|
+
/** `ok`, `interrupted` or `degraded`. */
|
|
184
|
+
condition: OutsideState['condition'];
|
|
185
|
+
/** Codes, in the launcher's order (empty when the condition is ok). */
|
|
186
|
+
reasons: readonly string[];
|
|
187
|
+
/** Frames went to the bus and nothing came back for 10 s (apart from `condition`, which can still be `ok`). */
|
|
188
|
+
nothing_received: boolean;
|
|
189
|
+
/** Frames the bridge sent to the bus so far; null until an `outside` event has arrived on this page. */
|
|
190
|
+
to_outside: number | null;
|
|
191
|
+
/** Frames that came from a device on the bus so far; null until an `outside` event has arrived on this page. */
|
|
192
|
+
from_outside: number | null;
|
|
193
|
+
}
|
|
194
|
+
/** Operations of the run. Each resolves when the server has taken the request; whether the run began is `status.run`. */
|
|
195
|
+
export interface FrontRun {
|
|
196
|
+
/** Starts a run of `file` (default: the start-up file). Rejects with `check-failed` and the findings if the check refuses it. */
|
|
197
|
+
start(intent?: Intent, options?: {
|
|
198
|
+
file?: string;
|
|
199
|
+
}): Promise<void>;
|
|
200
|
+
/** Stops in order. Works whatever the state of the connection (the request is sent if the network is up). */
|
|
201
|
+
stop(): Promise<void>;
|
|
202
|
+
/** Stops without waiting for the participants. */
|
|
203
|
+
forceStop(): Promise<void>;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Time operations. `pause`, `resume` and `setSpeed` resolve when the launcher has answered; `step` and `runUntil`
|
|
207
|
+
* resolve when time has arrived and the run is paused again (read `clock` after `await`). Another command sent before
|
|
208
|
+
* it arrives (from this page, another page or stdin) rejects it with `interrupted`.
|
|
209
|
+
*/
|
|
210
|
+
export interface FrontTime {
|
|
211
|
+
pause(): Promise<void>;
|
|
212
|
+
resume(): Promise<void>;
|
|
213
|
+
step(ms: number): Promise<void>;
|
|
214
|
+
setSpeed(value: number | 'max'): Promise<void>;
|
|
215
|
+
runUntil(ms: number): Promise<void>;
|
|
216
|
+
}
|
|
217
|
+
/** What a screen shows for one variable. */
|
|
218
|
+
export interface VariableView {
|
|
219
|
+
value: VariableValue;
|
|
220
|
+
/** The value as text (an enum shows its item's name). Empty while there is no value. */
|
|
221
|
+
text: string;
|
|
222
|
+
unit: string;
|
|
223
|
+
min: number | null;
|
|
224
|
+
max: number | null;
|
|
225
|
+
step: number | null;
|
|
226
|
+
/** Virtual time of the step that read the value (ms). */
|
|
227
|
+
sim_ms: number | null;
|
|
228
|
+
/** The value may be out of date. */
|
|
229
|
+
stale: boolean;
|
|
230
|
+
/** One English sentence when the value is not a live one (waiting, paused, stale, ended, ...); null while live. */
|
|
231
|
+
note: string | null;
|
|
232
|
+
/**
|
|
233
|
+
* Whether the ECU uses the variable now (information only: `can_write`, `why`, `note` and `condition` do not look at
|
|
234
|
+
* it). `active` from a server that does not say; `unknown` while the ECU has not said or the variable is not in the run.
|
|
235
|
+
*/
|
|
236
|
+
availability: 'unknown' | 'active' | 'inactive';
|
|
237
|
+
/** Whether it can be written: the variable's own conditions and what the launcher accepts (`state.allowed.write`). */
|
|
238
|
+
can_write: boolean;
|
|
239
|
+
/** Why the variable cannot be written (null if it can). */
|
|
240
|
+
why: Reason | null;
|
|
241
|
+
/** A write is on its way. */
|
|
242
|
+
writing: boolean;
|
|
243
|
+
/** Why the last write of this page did not go through (null if none). */
|
|
244
|
+
problem: Reason | null;
|
|
245
|
+
condition: ValueCondition;
|
|
246
|
+
block: WriteBlock | null;
|
|
247
|
+
write_status: WriteStatus;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* A variable. Values arrive while someone subscribes (the first subscription asks the server for them, the last
|
|
251
|
+
* unsubscribe stops it: there is no close()). `write` needs no subscription.
|
|
252
|
+
*/
|
|
253
|
+
export interface FrontVariable extends Readable<VariableView> {
|
|
254
|
+
/** Resolves when the value has been applied in an ECU step. Rejects with an ActionError (`no-answer` is `unknown`: it is not sent again). */
|
|
255
|
+
write(value: number | boolean | string): Promise<void>;
|
|
256
|
+
}
|
|
257
|
+
/** The front door: `connect()` returns it. */
|
|
258
|
+
export interface Front {
|
|
259
|
+
/** The client of the same connection (events, logs, findings, participants, the write trail). */
|
|
260
|
+
readonly low: GuiClient;
|
|
261
|
+
readonly status: Readable<FrontStatus>;
|
|
262
|
+
readonly clock: Readable<FrontClock>;
|
|
263
|
+
readonly controls: Readable<FrontControls>;
|
|
264
|
+
readonly scenario: Readable<FrontScenario | null>;
|
|
265
|
+
readonly run: FrontRun;
|
|
266
|
+
readonly time: FrontTime;
|
|
267
|
+
/**
|
|
268
|
+
* The networks of the run that the start's `connect` connected outside (empty when there are none, when no run is
|
|
269
|
+
* going, and in a run that a `role: bridge` participant of the file connects: do not read "connected or not" from it).
|
|
270
|
+
* Changes as the launcher's `state` and `outside` events arrive.
|
|
271
|
+
*/
|
|
272
|
+
readonly outside: Readable<readonly Outside[]>;
|
|
273
|
+
/**
|
|
274
|
+
* Where `network` of `file` (default: the start-up file, as for `run.start`) can be connected on the computer of the
|
|
275
|
+
* GUI server: the entries of every backend, in the launcher's order. It starts that network's bridge to list it (on
|
|
276
|
+
* Windows, Npcap may ask to raise the rights): call it when the user opens the choice, not when the page opens. A
|
|
277
|
+
* backend that cannot list is an entry with `error`, not a failure. Rejects with an ActionError (`check-busy`,
|
|
278
|
+
* `unknown-network`, ...).
|
|
279
|
+
*/
|
|
280
|
+
connections(request: {
|
|
281
|
+
network: string;
|
|
282
|
+
}, options?: {
|
|
283
|
+
file?: string;
|
|
284
|
+
}): Promise<ConnectEntry[]>;
|
|
285
|
+
/**
|
|
286
|
+
* The scenario files next to `file` (default: the start-up file, as for `run.start` and `connections()`; pass the
|
|
287
|
+
* same `file` to this and to `run.start` when a run uses another file), as the list that
|
|
288
|
+
* `client.low.scenarios(file)` gives, without its directory. Give `path` of an entry as `intent.scenario`. Rejects
|
|
289
|
+
* with an ActionError (`no-file` when there is no file to ask for, and the server's code otherwise).
|
|
290
|
+
*/
|
|
291
|
+
scenarios(options?: {
|
|
292
|
+
file?: string;
|
|
293
|
+
}): Promise<ScenarioFile[]>;
|
|
294
|
+
/**
|
|
295
|
+
* Checks what `intent` would start, without starting it (`POST api/check`), and returns the launcher's check result
|
|
296
|
+
* (`findings`; `time_lock` and `networks[].outside` are in `raw`). Rejects with an ActionError (`target-not-listed`,
|
|
297
|
+
* `check-busy`, `unknown-field`, ...); a failure is not put into `status.problem`. It sends one check at a time (the
|
|
298
|
+
* next after the answer to the one before), and a check of the same intent and file as one that waits or is on its
|
|
299
|
+
* way shares it (`fresh`: only one that waits, so that the answer reads the file as it is now). A check that waits is
|
|
300
|
+
* not sent when `signal` has aborted for every caller of it (it rejects with the signal's reason), nor after
|
|
301
|
+
* `close()` (`closed`).
|
|
302
|
+
*
|
|
303
|
+
* With `text`, it checks that text as the content of `file` (a text that is not saved yet; no process starts). The
|
|
304
|
+
* intent then takes only `variant`, `strict` and `vehicle_sil_run_request` (another field is `unknown-field`). A check of a text is never
|
|
305
|
+
* shared with another check, and its answer is the caller's alone: the parts of the page do not see it.
|
|
306
|
+
*/
|
|
307
|
+
check(intent: Pick<Intent, 'vehicle_sil_run_request' | 'variant' | 'strict'>, options: {
|
|
308
|
+
file?: string;
|
|
309
|
+
text: string;
|
|
310
|
+
signal?: AbortSignal;
|
|
311
|
+
}): Promise<CheckResult>;
|
|
312
|
+
check(intent?: Intent, options?: {
|
|
313
|
+
file?: string;
|
|
314
|
+
signal?: AbortSignal;
|
|
315
|
+
fresh?: boolean;
|
|
316
|
+
}): Promise<CheckResult>;
|
|
317
|
+
/**
|
|
318
|
+
* Reads the text of a configuration file as it is saved (`GET api/config`), with the SHA-256 of its bytes (`stamp`).
|
|
319
|
+
* `file` defaults to the start-up file (`no-file` if there is none). Rejects with an ActionError
|
|
320
|
+
* (`not-a-configuration`, `config-too-large`, `config-unreadable`, ...); a failure is not put into `status.problem`.
|
|
321
|
+
*/
|
|
322
|
+
readConfig(options?: {
|
|
323
|
+
file?: string;
|
|
324
|
+
}): Promise<ConfigText>;
|
|
325
|
+
/**
|
|
326
|
+
* Describes the participants of the saved `file` again (`POST api/describe`: after an executable was built again),
|
|
327
|
+
* so that the checks of a text compare them, and returns that check as `check()` does. The answer is the caller's
|
|
328
|
+
* alone: it does not change what the parts of the page show. A describe of the same file and variant that waits or is on its way is shared. Rejects with an ActionError (`check-busy`,
|
|
329
|
+
* `check-timeout`, ...); a failure is not put into `status.problem`.
|
|
330
|
+
*/
|
|
331
|
+
describeAgain(options?: {
|
|
332
|
+
file?: string;
|
|
333
|
+
variant?: string;
|
|
334
|
+
}): Promise<CheckResult>;
|
|
335
|
+
/**
|
|
336
|
+
* Saves `text` as the content of `file` (`POST api/config`), with the `stamp` that `readConfig()` gave (null: a new
|
|
337
|
+
* file), and resolves with the stamp of the saved content. By default the server saves only an edit that keeps the
|
|
338
|
+
* commands that run, as the launcher's check of the text says (`controls.save` tells what applies). `file` defaults
|
|
339
|
+
* to the start-up file (`no-file` if there is none). Rejects with an ActionError: `save-disabled`,
|
|
340
|
+
* `commands-changed` (`findings` are the launcher's; also a new file, `stamp` null, to a server started without
|
|
341
|
+
* `--allow-command-changes`), `config-changed` (read the file again and make the edit on
|
|
342
|
+
* that text), `config-busy`, `config-unreadable`, `text-too-large`, ...; a failure is not put into `status.problem`.
|
|
343
|
+
*/
|
|
344
|
+
saveConfig(options: {
|
|
345
|
+
file?: string;
|
|
346
|
+
text: string;
|
|
347
|
+
stamp: string | null;
|
|
348
|
+
}): Promise<SavedConfig>;
|
|
349
|
+
/** A variable by `"Peer.variable"` (cut at the first dot) or `{peer, name}` (for a peer whose name has a dot). */
|
|
350
|
+
variable(ref: string | VariableRef): FrontVariable;
|
|
351
|
+
/** Disconnects and fails what is waiting. A connection that `connect()` shares is made again by the next `connect()`. */
|
|
352
|
+
close(): void;
|
|
353
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { GuiClient } from './client.js';
|
|
2
|
+
import { ActionError, Control, FrontVariable, Reason, VariableView } from './front-types.js';
|
|
3
|
+
import type { BoundVariable } from './variable-binding.js';
|
|
4
|
+
import type { ValueCondition } from './variable-state.js';
|
|
5
|
+
import { Readable } from './values.js';
|
|
6
|
+
import { VariableRef } from './variables.js';
|
|
7
|
+
/** The sentence for a value that is not a live one (null while it is live). */
|
|
8
|
+
export declare function noteOf(condition: ValueCondition): string | null;
|
|
9
|
+
/** Split `"Peer.variable"` at the first dot (as the scenario files do); an object is taken as it is. */
|
|
10
|
+
export declare function refOf(ref: string | VariableRef): VariableRef;
|
|
11
|
+
interface Track {
|
|
12
|
+
writing: boolean;
|
|
13
|
+
problem: Reason | null;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* `launcher` is what the launcher accepts for a write now (`state.allowed.write`, with the connection and the run). The
|
|
17
|
+
* variable's own reason (it is an output, the ECU is not connected, ...) comes first; otherwise the launcher's, as
|
|
18
|
+
* `bind` reports it (`block` `launcher`) or as `launcher` has it.
|
|
19
|
+
*/
|
|
20
|
+
export declare function viewOf(bound: BoundVariable, track: Track, launcher: Control): VariableView;
|
|
21
|
+
/** A write that failed, as an ActionError (`no-answer` and `closed` may have been applied: `unknown`). */
|
|
22
|
+
export declare function writeFailure(error: unknown): ActionError;
|
|
23
|
+
export declare function makeVariable(low: GuiClient, ref: VariableRef,
|
|
24
|
+
/** Refuses a write the client must not send (the connection is refused, or the versions differ). */
|
|
25
|
+
refuse: () => ActionError | null,
|
|
26
|
+
/** What the launcher accepts for a write (see `viewOf`). */
|
|
27
|
+
launcher: Readable<Control>): FrontVariable;
|
|
28
|
+
export {};
|
package/types/front.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ClientOptions } from './client.js';
|
|
2
|
+
import type { HttpTransport } from './http.js';
|
|
3
|
+
import type { SocketFactory } from './connection.js';
|
|
4
|
+
import { Front } from './front-types.js';
|
|
5
|
+
import { ErrorSink, Readable } from './values.js';
|
|
6
|
+
/** Options of `connect()`. In the browser, call it without options (the page's own server and token are used). */
|
|
7
|
+
export interface ConnectOptions {
|
|
8
|
+
/** URL of the GUI server (what the server printed, without `#token=...`). */
|
|
9
|
+
base_url: string;
|
|
10
|
+
/** The token (what follows `#token=`). A function is called each time the token is used. */
|
|
11
|
+
token: string | (() => string | null);
|
|
12
|
+
/** Origin to send (Node sends the origin of `base_url` if omitted). */
|
|
13
|
+
origin?: string;
|
|
14
|
+
/** HTTP transport (default: fetch). For tests. */
|
|
15
|
+
http?: HttpTransport;
|
|
16
|
+
/** Function that opens the WebSocket (default: the platform's). For tests. */
|
|
17
|
+
socket?: SocketFactory;
|
|
18
|
+
/** How long to wait for the launcher's answer to a time command (ms; default 5000). */
|
|
19
|
+
answer_timeout_ms?: number;
|
|
20
|
+
/** Receives what subscribers threw (default: console.error). */
|
|
21
|
+
on_error?: ErrorSink;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Makes the front door without connecting and without waiting for the server (as `createClient` does for the client
|
|
25
|
+
* below it). For an app that must show its screens before the server answers, and while it cannot be reached: it calls
|
|
26
|
+
* `front.low.connect()` and `front.low.loadApp()` itself, and reads `status` (the connection, `rejected`, `incompatible`)
|
|
27
|
+
* meanwhile. Until `loadApp()` has answered, the front knows no start-up file, and the ranges in `controls` are the
|
|
28
|
+
* defaults (`DEFAULT_LIMITS`).
|
|
29
|
+
* Most code wants `connect()`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function createFront(options: ClientOptions): Front;
|
|
32
|
+
/**
|
|
33
|
+
* Connects to the GUI server and returns the front door. Without options (in the browser) it connects once and returns
|
|
34
|
+
* the same connection to every caller: the parts of a page share it. With options it makes a connection of its own
|
|
35
|
+
* (close it with `close()`). A failure to connect is not remembered: the next call connects again.
|
|
36
|
+
*/
|
|
37
|
+
export declare function connect(options?: ConnectOptions): Promise<Front>;
|
|
38
|
+
/** Calls `fn` now and each time the value changes. Returns the function that stops it. */
|
|
39
|
+
export declare function watch<T>(source: Readable<T>, fn: (value: T) => void): () => void;
|
|
40
|
+
export declare function watch<T extends unknown[]>(sources: {
|
|
41
|
+
[K in keyof T]: Readable<T[K]>;
|
|
42
|
+
}, fn: (...values: T) => void): () => void;
|
|
43
|
+
/**
|
|
44
|
+
* Resolves with the first value that satisfies `test` (the current one counts). Rejects with an ActionError `timeout`
|
|
45
|
+
* after `timeout_ms`, or `aborted` when `signal` aborts (`unknown`: the thing waited for may still happen).
|
|
46
|
+
*/
|
|
47
|
+
export declare function until<T>(source: Readable<T>, test: (value: T) => boolean, options?: {
|
|
48
|
+
timeout_ms?: number;
|
|
49
|
+
signal?: AbortSignal;
|
|
50
|
+
}): Promise<T>;
|
package/types/http.d.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { ServerProblem } from './protocol.js';
|
|
2
|
+
/** One request to the GUI server. path is relative to the base (`api/run` and so on, with no leading /). */
|
|
3
|
+
export interface HttpRequest {
|
|
4
|
+
method: 'GET' | 'POST';
|
|
5
|
+
path: string;
|
|
6
|
+
/** Body of a POST (sent as JSON). */
|
|
7
|
+
body?: unknown;
|
|
8
|
+
/** How long to wait for the answer (ms). Omitted: the transport's default (DEFAULT_TIMEOUT_MS for fetchTransport). */
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
}
|
|
11
|
+
/** Default time to wait for an answer (ms). A check (`api/check`) waits for the server's check limit plus this. */
|
|
12
|
+
export declare const DEFAULT_TIMEOUT_MS = 30000;
|
|
13
|
+
/** Outcome of a request: the answer's JSON on success, an HttpError on failure. */
|
|
14
|
+
export type HttpOutcome = {
|
|
15
|
+
ok: true;
|
|
16
|
+
body: unknown;
|
|
17
|
+
} | {
|
|
18
|
+
ok: false;
|
|
19
|
+
error: HttpError;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Sends requests to the GUI server. Calls done exactly once, with the outcome. Adding the token (Authorization) and
|
|
23
|
+
* Origin is the transport's job. The default is fetchTransport; it can be replaced with a framework's HTTP tool
|
|
24
|
+
* (such as Angular's HttpClient).
|
|
25
|
+
*/
|
|
26
|
+
export type HttpTransport = (request: HttpRequest, done: (outcome: HttpOutcome) => void) => void;
|
|
27
|
+
/**
|
|
28
|
+
* HTTP failure. Status 0 means the server did not answer (the request never arrived, or the wait timed out). problem
|
|
29
|
+
* is the content of the server's error shape (`{"error": {...}}`). timedOut means the client gave up after the
|
|
30
|
+
* timeout (the server may have received the request and still be working on it).
|
|
31
|
+
*/
|
|
32
|
+
export declare class HttpError extends Error {
|
|
33
|
+
readonly status: number;
|
|
34
|
+
readonly statusText: string;
|
|
35
|
+
readonly problem: ServerProblem | null;
|
|
36
|
+
readonly timedOut: boolean;
|
|
37
|
+
constructor(status: number, statusText: string, problem: ServerProblem | null, timedOut?: boolean);
|
|
38
|
+
/** Error for a request given up after the timeout. */
|
|
39
|
+
static noAnswer(method: string, path: string, timeoutMs: number): HttpError;
|
|
40
|
+
/**
|
|
41
|
+
* Builds the error from the answer's body (parsed JSON). problem is null unless the body has the server's error
|
|
42
|
+
* shape.
|
|
43
|
+
*/
|
|
44
|
+
static from(status: number, statusText: string, body: unknown): HttpError;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Gets the text to show a person for a failure: the server's message for a server error (in English, including how
|
|
48
|
+
* to fix it), the status code for other HTTP failures.
|
|
49
|
+
*/
|
|
50
|
+
export declare function errorMessage(error: unknown): string;
|
|
51
|
+
/** Options of fetchTransport. */
|
|
52
|
+
export interface FetchTransportOptions {
|
|
53
|
+
/** URL of the server (`http://127.0.0.1:<port>/`). Request paths are relative to it. */
|
|
54
|
+
baseUrl: string;
|
|
55
|
+
/** The token (what follows `#token=` in the URL the server printed). A function is called for each request. */
|
|
56
|
+
token: string | (() => string | null);
|
|
57
|
+
/**
|
|
58
|
+
* Origin to send with POST. Browsers add it themselves (a value given here is not used). Outside the browser (Node
|
|
59
|
+
* and so on), pass the server's own origin (the origin of baseUrl).
|
|
60
|
+
*/
|
|
61
|
+
origin?: string;
|
|
62
|
+
/** The fetch to use (default globalThis.fetch). */
|
|
63
|
+
fetch?: typeof fetch;
|
|
64
|
+
/** Default time to wait for an answer (ms; a request's timeoutMs takes precedence). */
|
|
65
|
+
timeoutMs?: number;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* HttpTransport that sends with the standard fetch. Works in browsers and in Node 18 or later. Does not follow
|
|
69
|
+
* redirects (so the token is never sent elsewhere). After the timeout, fails with an HttpError of status 0.
|
|
70
|
+
*/
|
|
71
|
+
export declare function fetchTransport(options: FetchTransportOptions): HttpTransport;
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export { DEFAULT_LIMITS, createClient } from './client.js';
|
|
2
|
+
export type { ClientOptions, GuiClient } from './client.js';
|
|
3
|
+
export type { ClientConnection, CloseInfo, ConnectionState } from './connection.js';
|
|
4
|
+
export type { ClientSession, Notice } from './session.js';
|
|
5
|
+
export type { ClientRun, StopAction } from './run.js';
|
|
6
|
+
export type { ClientTime, Lateness, NotSentReason, SendResult, TimeFailure, TimeState, } from './time.js';
|
|
7
|
+
export { ANSWER_TIMEOUT_MS } from './time.js';
|
|
8
|
+
export { connect, createFront, until, watch } from './front.js';
|
|
9
|
+
export type { ConnectOptions } from './front.js';
|
|
10
|
+
export { ActionError } from './front-types.js';
|
|
11
|
+
export type { ConnectEntry, ConnectListError, ConnectTarget, Control, EndKind, Front, FrontClock, FrontControls, FrontResult, FrontRun, FrontScenario, FrontStatus, FrontTime, FrontVariable, Intent, Link, OperationName, Outside, Pacing, Reason, RunState, VariableView, } from './front-types.js';
|
|
12
|
+
export { TOKEN_STORAGE_KEY, takeToken } from './token.js';
|
|
13
|
+
export type { TokenPlace } from './token.js';
|
|
14
|
+
export { HISTORY_MAX, HISTORY_TOTAL_MAX, OPERATIONS_KEPT, WATCH_PERIODS_MS, WATCH_PERIOD_MS, WRITE_TIMEOUT_MS, WriteError, } from './variables.js';
|
|
15
|
+
export type { ClientVariables, HistoryPoint, OperationPeer, OperationView, VariableInfo, VariablePeer, VariableReading, VariableRef, VariableValue, VariableWatch, VariablesState, VariablesStatus, WatchOptions, WatchProblem, WatchValues, WriteOptions, } from './variables.js';
|
|
16
|
+
export { DROPPED_MESSAGE } from './variable-binding.js';
|
|
17
|
+
export type { BindOptions, BoundVariable, VariableBinding } from './variable-binding.js';
|
|
18
|
+
export { hasRange, isWriteError, valueCondition, writeBlock } from './variable-state.js';
|
|
19
|
+
export type { ConditionInput, ValueCondition, WriteBlock, WriteBlockInput, WriteStatus, WriteValue, } from './variable-state.js';
|
|
20
|
+
export type { Readable } from './values.js';
|
|
21
|
+
export { BATCH_MS, TRY_AGAIN_LATER, webSocketFactory } from './connection.js';
|
|
22
|
+
export type { SocketFactory, SocketHandlers, SocketLike } from './connection.js';
|
|
23
|
+
export { DEFAULT_TIMEOUT_MS, HttpError, errorMessage, fetchTransport } from './http.js';
|
|
24
|
+
export type { FetchTransportOptions, HttpOutcome, HttpRequest, HttpTransport } from './http.js';
|
|
25
|
+
export { isHolding, launcherAnswer, phaseIndex, runOutcome } from './session-state.js';
|
|
26
|
+
export type { CommandView, LauncherAnswer, LauncherView, LogLine, LogSource, ParticipantView, RunOutcome, ScenarioView, SessionView, TimeView, } from './session-state.js';
|
|
27
|
+
export { PHASES, PROTOCOL_VERSION, ProtocolError, readAppInfo, readCheckResponse, readConfigList, readConfigText, readSavedConfig, readConnections, readDashboardResponse, readRecording, readScenarioList, readServerMessage, readSessionAllowed, readSessionResponse, readTimeResponse, readVariablesSummary, readWriteResponse, severityRank, } from './protocol.js';
|
|
28
|
+
export type { AppInfo, AuthMessage, CheckNetwork, CheckOutcome, CheckParticipant, CheckRequest, CheckResult, CheckScenario, CheckStatus, CheckTextRequest, Caution, CommandReport, ConfigFile, ConfigList, ConfigText, SaveConfigRequest, SavedConfig, Connections, ConnectionsRequest, ControlLink, ControlOffer, ControlState, DashboardFile, DashboardFileError, DashboardFileItem, DashboardFileSection, DashboardPanelModule, DashboardResponse, DescribeRequest, DashboardVariable, Dropped, Finding, FromLauncher, LauncherAllowedItem, LauncherEvent, LauncherFields, LogCounts, Open, OutsideState, ParticipantRole, ParticipantState, Phase, Recording, Replay, RunParticipant, RunRequest, RunResult, RunEnd, RunResultName, RunTiming, RunTraffic, ScenarioFile, ScenarioList, ScenarioResult, ScenarioStatus, ScenarioStep, ScenarioStepStatus, ServerAllowed, ServerAllowedItem, ServerSaveItem, ServerMessage, ServerProblem, SessionSummary, Severity, Speed, StateReport, StopRequest, StopRequestBody, SummaryCommand, SummaryLauncher, SummaryParticipant, SummaryScenario, SummaryState, TimeAnswer, TimeCommand, TimeCommandName, TimeReport, TrafficNetwork, TrafficParticipant, TrafficUnplaced, ValuesMessage, Variable, VariableSummary, VariablesSummary, OperationReport, VariableAvailability, WatchMessage, WriteAnswer, } from './protocol.js';
|