@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
package/types/run.d.ts CHANGED
@@ -4,12 +4,18 @@ import { SessionFeed } from './session.js';
4
4
  import { ErrorSink, Readable } from './values.js';
5
5
  /** Stop action: stop in order, or stop without waiting. */
6
6
  export type StopAction = 'stop' | 'force';
7
+ export interface StopCapture {
8
+ readonly key: object | string;
9
+ readonly send: (force: boolean) => Promise<SessionSummary | null>;
10
+ }
7
11
  /** Run control and its state (GuiClient.run). */
8
12
  export interface ClientRun {
9
13
  /** A start was sent and its answer is pending. */
10
14
  readonly starting: Readable<boolean>;
11
15
  /** A stop was sent and its answer is pending (which kind of stop). */
12
16
  readonly stopping: Readable<StopAction | null>;
17
+ /** A pending stop of the current session or current start, if any. */
18
+ readonly currentStopping: Readable<StopAction | null>;
13
19
  /** A stop was asked for while the answer to a start was pending. */
14
20
  readonly stopWhileStarting: Readable<boolean>;
15
21
  /** Why the last action was refused (the server's text, unchanged). null once a run starts or ends. */
@@ -22,19 +28,22 @@ export interface ClientRun {
22
28
  * have started it.
23
29
  */
24
30
  start(request: RunRequest): Promise<SessionSummary | null>;
25
- /** Stops in order (`POST api/stop` `{force: false}`). Asking again has no further effect. */
31
+ /**
32
+ * Stops the session currently seen by this client. During its own pending start, waits for the answer and targets
33
+ * that session. If the ID or server instance is unknown, or the start answer is lost, rejects without sending an
34
+ * unscoped stop. An older server without `api/stop-session` is refused, rather than stopping an unrelated run.
35
+ */
26
36
  stop(): Promise<SessionSummary | null>;
27
- /** Stops without waiting (`POST api/stop` `{force: true}`). */
37
+ /** Stops without waiting for participants. A stop during this client's pending start is targeted the same way. */
28
38
  forceStop(): Promise<SessionSummary | null>;
29
39
  }
30
40
  /**
31
- * Run control: start (`POST api/run`), stop in order or without waiting (`POST api/stop`), and the state for them.
41
+ * Run control: start (`POST api/run`), stop in order or without waiting (`POST api/stop-session`), and their state.
32
42
  *
33
43
  * - The answer to an action (the current summary) is applied to the session copy without waiting for the notification
34
44
  * (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).
45
+ * - A stop requested while a start is pending waits for its answer, then names that session in the stop request. The
46
+ * server checks the ID atomically, so a later run cannot be stopped by the delayed request.
38
47
  * - error holds the reason for a refusal (the server's English text). It is cleared once a run starts or ends.
39
48
  * - The Promises of start() and stop() resolve with the summary in the answer (null if unreadable) and reject with an
40
49
  * HttpError when refused. No answer (`timedOut`) is not a refusal: the session copy tells whether the run started.
@@ -47,12 +56,16 @@ export declare class RunControl implements ClientRun {
47
56
  * How long to wait for the answer to a start (ms). Long, because the server may check again as part of the start.
48
57
  */
49
58
  private readonly startTimeoutMs;
59
+ private startOperation;
60
+ private readonly pendingStops;
61
+ private readonly pendingRevision;
50
62
  private readonly startSending;
51
63
  private readonly stopSending;
52
64
  private readonly stopAskedWhileStarting;
53
65
  private readonly failure;
54
66
  readonly starting: Readable<boolean>;
55
67
  readonly stopping: Readable<StopAction | null>;
68
+ readonly currentStopping: Readable<StopAction | null>;
56
69
  readonly stopWhileStarting: Readable<boolean>;
57
70
  readonly error: Readable<string | null>;
58
71
  constructor(feed: SessionFeed, transport: HttpTransport, onError?: ErrorSink,
@@ -66,6 +79,8 @@ export declare class RunControl implements ClientRun {
66
79
  stop(): Promise<SessionSummary | null>;
67
80
  /** Stops without waiting (kills the participants). */
68
81
  forceStop(): Promise<SessionSummary | null>;
82
+ captureStop(): StopCapture;
83
+ private requestStop;
69
84
  /**
70
85
  * Sends and applies the summary in the answer. done is called after the answer (failures too), before the Promise
71
86
  * settles.
@@ -1,4 +1,25 @@
1
- import { CheckResult, ControlLink, Dropped, Finding, LauncherEvent, ParticipantState, Phase, RunResult, ScenarioStatus, ScenarioStep, ServerProblem, SessionSummary, Speed, TimeReport } from './protocol.js';
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;
2
23
  /** Log lines kept per source (participant or launcher). The same number the server keeps. */
3
24
  export declare const MAX_LOG_LINES_PER_SOURCE = 2000;
4
25
  /** Log lines kept in total. Beyond this, the oldest lines of the source holding the most are dropped. */
@@ -24,6 +45,7 @@ export interface LogLine {
24
45
  count: number;
25
46
  atLeast: boolean;
26
47
  launcher?: boolean;
48
+ notKept?: boolean;
27
49
  };
28
50
  }
29
51
  /** Log counts per source. */
@@ -87,17 +109,12 @@ export interface LauncherView {
87
109
  silentSeconds: number | null;
88
110
  }
89
111
  /**
90
- * Virtual time and how it advances (the last time event, or time of the summary). Fields an older launcher does not
91
- * write are null. TimeControl (time.ts) derives from this what the time controls need (whether they can be used now
92
- * and so on).
112
+ * Virtual time and how it keeps up (the last time event, or time of the summary). Fields that are not written are
113
+ * null. Whether the run is paused, and the speed set, are in the launcher's state (SessionView.launcherState).
93
114
  */
94
115
  export interface TimeView {
95
116
  simMs: number;
96
- /** The current speed (a number or 'max'; null if not written). */
97
- speed: Speed;
98
- /** Whether it is paused (null if not written). */
99
- paused: boolean | null;
100
- /** Actual speed over roughly the last second (null while paused and when starting to move). */
117
+ /** Actual speed over roughly the last second (null when starting to move, and in an event written while paused). */
101
118
  actualSpeed: number | null;
102
119
  /** Number of late time steps. */
103
120
  lateSteps: number | null;
@@ -117,6 +134,8 @@ export interface CommandView {
117
134
  message: string | null;
118
135
  /** For an accepted step, the virtual time it actually advances (ms). */
119
136
  ms: number | null;
137
+ /** For an accepted step or run_until, the virtual time at which the simulation pauses after it (ms). */
138
+ atMs: number | null;
120
139
  /** seq of that event (-1 if unknown). Tells a new answer from the same answer arriving again in a summary. */
121
140
  seq: number;
122
141
  }
@@ -139,11 +158,35 @@ export interface ScenarioView {
139
158
  status: ScenarioStatus | null;
140
159
  /** Virtual time at which the scenario ended. */
141
160
  overAtMs: number | null;
161
+ /**
162
+ * Where the server serves the run's timeline file (`api/timeline/<session id>`), once the run has ended with one;
163
+ * else null. The page `timeline/` of the server draws it (see "Timeline of a scenario run" in docs/gui.md).
164
+ */
165
+ timelineUrl: string | null;
142
166
  }
143
167
  /** State of one session (one run of the launcher), as the screen sees it. */
144
168
  export interface SessionView {
145
169
  /** Session number the server assigned. */
146
170
  id: number;
171
+ /** Server snapshot capture order for this run, null on older servers. */
172
+ snapshotRev?: number | null;
173
+ /** Capture order of the last adopted launcher projection, independent of server state. */
174
+ projectionRev?: number | null;
175
+ /** Highest launcher event position included in an adopted summary projection. */
176
+ projectionSeq?: number;
177
+ /** Highest diagnostic identifier represented in this view. */
178
+ problemSeq?: number;
179
+ /** Highest diagnostic delivered by the ordered WebSocket stream. */
180
+ problemEventSeq?: number;
181
+ /** Summary findings awaiting possible earlier buffered live events. */
182
+ pendingFindings?: {
183
+ through: number;
184
+ keys: readonly string[];
185
+ };
186
+ /** Highest live or replay event observed, retained across full log replay. */
187
+ observedSeq?: number;
188
+ /** Last event position for each launcher projection, retained across replay. */
189
+ eventSeqs?: Readonly<Record<string, number>>;
147
190
  /** seq of the last event received (-1 if none). On reconnect, the resend is requested from the next one. */
148
191
  lastSeq: number;
149
192
  /** The configuration file (relative to root). */
@@ -154,7 +197,7 @@ export interface SessionView {
154
197
  * Participants the user chose on the screen to start themselves (manual: true in the configuration file is in check).
155
198
  */
156
199
  manual: readonly string[];
157
- /** Speed given at the start (null means as in the configuration file). The current speed is time.speed. */
200
+ /** Speed requested at the start (null means no speed was requested). The current speed is `speed` of launcherState. */
158
201
  speed: Speed;
159
202
  /** Whether the run started paused. */
160
203
  startPaused: boolean;
@@ -184,6 +227,11 @@ export interface SessionView {
184
227
  stopRequests: number;
185
228
  /** The last command event received (whether it was accepted, and why not). */
186
229
  lastCommand: CommandView | null;
230
+ /**
231
+ * What the launcher accepts now and where the run stands (the last `state` event, or `launcher_state` of the
232
+ * summary; the one with the larger `rev` wins). null until one arrives (and for a launcher without `state`).
233
+ */
234
+ launcherState: StateReport | null;
187
235
  result: RunResult | null;
188
236
  launcher: LauncherView;
189
237
  /** What the server noticed (shown in English, unchanged). */
@@ -219,6 +267,12 @@ export type RunOutcome =
219
267
  | 'ended'
220
268
  /** The launcher exited without a result. */
221
269
  | 'crashed';
270
+ /**
271
+ * Whether the run waits before its first step (the step at time 0) for a resume or a step: the launcher's state says
272
+ * so (`holding`; a run started paused whose launcher has a Control Server). Meanwhile the launcher writes no time
273
+ * events, and a variable written is applied in the step at time 0.
274
+ */
275
+ export declare function isHolding(session: SessionView | null): boolean;
222
276
  export declare function runOutcome(session: SessionView): RunOutcome;
223
277
  /** Builds a session from the server's summary (hello, a new session). The log arrives in the resend that follows. */
224
278
  export declare function sessionFromSummary(summary: SessionSummary): SessionView;
@@ -253,3 +307,5 @@ export declare function phaseIndex(phase: Phase | null): number;
253
307
  * staleEvents (seq went back). The log array is rebuilt once per batch (not copied for every event).
254
308
  */
255
309
  export declare function applyEvents(session: SessionView, events: readonly LauncherEvent[], countStale?: boolean): SessionView;
310
+ /** Combines a same-run full replay with lines only the client still holds. */
311
+ export declare function recoverReplayLogs(session: SessionView, recovered: readonly LogLine[], notKept: ReadonlyMap<string, number>): SessionView;
@@ -1,5 +1,5 @@
1
1
  import { Connection } from './connection.js';
2
- import { AuthMessage, ServerMessage, SessionSummary } from './protocol.js';
2
+ import { AuthMessage, ServerAllowed, ServerMessage, SessionSummary } from './protocol.js';
3
3
  import { SessionView } from './session-state.js';
4
4
  import { ErrorSink, Readable } from './values.js';
5
5
  /** How many kinds of notices not tied to a session are kept. */
@@ -23,12 +23,24 @@ export interface Notice {
23
23
  export interface ClientSession {
24
24
  /** The current (or last) session. null while the server has none yet. */
25
25
  readonly session: Readable<SessionView | null>;
26
+ /** Identity of the session suitable for a targeted action. */
27
+ currentTarget(): {
28
+ session: number;
29
+ instance: string;
30
+ } | null;
31
+ /** The last authenticated server instance, even when there is no session. */
32
+ currentInstance(): string | null;
26
33
  /**
27
34
  * The session copy matches the server: connected, and hello and the resent events have all arrived. Until then,
28
35
  * Start and Stop are disabled so that nobody acts on a stale display. Other features (values and so on) have their
29
36
  * own ready.
30
37
  */
31
38
  readonly ready: Readable<boolean>;
39
+ /**
40
+ * What the server accepts now (start, stop, force and why not). null until it says (hello), and from a server that
41
+ * does not say. What the launcher accepts is `launcherState` of the session.
42
+ */
43
+ readonly allowed: Readable<ServerAllowed | null>;
32
44
  /** When an event was last applied (Date.now()). The starting point for advancing elapsed time with the clock. */
33
45
  readonly lastEventAt: Readable<number>;
34
46
  /**
@@ -59,6 +71,11 @@ export interface ClientSession {
59
71
  /** Removes a notice. */
60
72
  dismissNotice(id: number): void;
61
73
  }
74
+ interface Adoption {
75
+ revision: number;
76
+ instance: string | null;
77
+ session: number | null;
78
+ }
62
79
  /**
63
80
  * Copy of a session (one run of the launcher). Reads the notifications of the connection (Connection) and builds the
64
81
  * state from the server's summary and events.
@@ -77,8 +94,15 @@ export interface ClientSession {
77
94
  export declare class SessionFeed implements ClientSession {
78
95
  private readonly connection;
79
96
  private readonly onError;
97
+ private readonly rawListeners;
98
+ private snapshotVersion;
99
+ private instanceId;
100
+ private adoptionRevision;
101
+ private instanceListener;
102
+ private stopTarget;
80
103
  private readonly current;
81
104
  private readonly synced;
105
+ private readonly allowedValue;
82
106
  private readonly receivedAt;
83
107
  private readonly noticeList;
84
108
  private readonly rejectedValue;
@@ -86,8 +110,10 @@ export declare class SessionFeed implements ClientSession {
86
110
  private readonly messageListeners;
87
111
  private noticeId;
88
112
  private stoppedFlag;
113
+ private replayLogs;
89
114
  readonly session: Readable<SessionView | null>;
90
115
  readonly ready: Readable<boolean>;
116
+ readonly allowed: Readable<ServerAllowed | null>;
91
117
  readonly lastEventAt: Readable<number>;
92
118
  readonly notices: Readable<readonly Notice[]>;
93
119
  readonly rejected: Readable<boolean>;
@@ -108,11 +134,31 @@ export declare class SessionFeed implements ClientSession {
108
134
  * request for the same run (the rest arrives in notifications). A summary of an earlier run never brings back an old
109
135
  * run over a new one.
110
136
  */
111
- adopt(summary: SessionSummary | null): void;
137
+ onRawMessages(listener: (batch: readonly unknown[], current: () => boolean, snapshotVersion: number) => void): () => void;
138
+ onSnapshotVersion(read: () => number): void;
139
+ /** Called before a new server's session can be published. */
140
+ onInstance(listener: (instance: string, current: () => boolean) => void): void;
141
+ /** Instance associated with the current session, or null if its origin is not known. */
142
+ currentInstance(): string | null;
143
+ currentTarget(): {
144
+ session: number;
145
+ instance: string;
146
+ } | null;
147
+ adopt(summary: SessionSummary | null, instance: string, resyncFrom?: string | null): Adoption | null;
148
+ sameRun(adoption: Adoption): boolean;
149
+ isCurrent(revision: number): boolean;
150
+ /**
151
+ * Takes what the server accepts (an HTTP answer or a notification): the one with the larger `rev` wins (rev 0 is a
152
+ * server that does not number it: the newest arrival wins). Used inside the library.
153
+ */
154
+ adoptAllowed(allowed: ServerAllowed | null): void;
112
155
  report(message: string, count?: number): void;
113
156
  dismissNotice(id: number): void;
114
157
  /** Reads and applies a batch from the connection. */
115
158
  private receive;
159
+ /** Keep messages at or after the run already observed over HTTP, within each server instance. */
160
+ private filterOlderRuns;
116
161
  private apply;
117
162
  private notify;
118
163
  }
164
+ export {};
package/types/time.d.ts CHANGED
@@ -1,12 +1,7 @@
1
1
  import { HttpTransport } from './http.js';
2
- import { AppInfo, TimeCommand, TimeCommandName } from './protocol.js';
2
+ import { TimeCommand, TimeCommandName } from './protocol.js';
3
3
  import { CommandView, SessionView, TimeView } from './session-state.js';
4
4
  import { ErrorSink, Readable } from './values.js';
5
- import { VariablesState } from './variables.js';
6
- /** The launcher features that concern time. */
7
- export declare const FEATURE_SPEED = "speed";
8
- export declare const FEATURE_START_PAUSED = "start-paused";
9
- export declare const FEATURE_TIME_COMMANDS = "time-commands";
10
5
  /**
11
6
  * How long to wait for the launcher's answer (the command event) to a command sent (ms). After that, the client stops
12
7
  * waiting, enables the controls again and reports the missing answer as an error (a launcher that does not read its
@@ -42,14 +37,14 @@ export interface Lateness {
42
37
  lateMs: number;
43
38
  }
44
39
  /**
45
- * Time state and the commands that may be used now. All values come from the session copy and the server information.
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.
46
43
  */
47
44
  export interface TimeState {
48
- /** Whether the launcher has time commands (pause, resume, step, speed). If not, no controls are shown. */
49
- supported: boolean;
50
45
  /** Time of the current session (null until a time event arrives). */
51
46
  time: TimeView | null;
52
- /** The speed is paced (a numeric speed). Lateness is not counted when running as fast as possible. */
47
+ /** The speed is paced (the launcher's state has a numeric speed). Lateness is not counted when running as fast as possible. */
53
48
  paced: boolean;
54
49
  /** Lateness figures (null when the launcher does not write them). */
55
50
  lateness: Lateness | null;
@@ -61,38 +56,17 @@ export interface TimeState {
61
56
  behind: boolean;
62
57
  /** The last command event received (stop included). */
63
58
  lastCommand: CommandView | null;
64
- /**
65
- * Whether time commands can be sent: the launcher supports them, the session copy is in sync, the phase is running,
66
- * a time event has arrived, there is no result yet and no stop has been requested. Once the phase moves on to
67
- * stopping, the launcher no longer accepts them. Commands can also be sent during beforeStart.
68
- */
69
- controllable: boolean;
70
- /**
71
- * Whether the run is before its first step (not started yet), waiting for a resume or a step: a run started paused
72
- * (start_paused) whose launcher has a Control Server (the variable status is not off) and that has not started
73
- * moving. Meanwhile the launcher writes no time events but accepts resume and step (it accepts pause too, which
74
- * changes nothing), and variables written are applied in the step at time 0.
75
- */
76
- beforeStart: boolean;
77
59
  /**
78
60
  * A command sent whose answer has not been seen yet (waiting for the HTTP answer or the launcher's command event).
79
61
  * Meanwhile no further command is sent (so a double click or a repeated Enter does not step twice).
80
62
  */
81
63
  sending: TimeCommandName | null;
82
- /** A step is in progress (meanwhile the launcher counts as paused and accepts resume and step). */
83
- stepping: boolean;
84
- /** Whether Pause can be used (while running, also during a step). */
85
- canPause: boolean;
86
- /** Whether Resume can be used (while paused, or during a step). */
87
- canResume: boolean;
88
- /** Whether Step can be used (the same as canResume; the launcher's rule). */
89
- canStep: boolean;
90
64
  /** The last command that went wrong. null once the run changes. */
91
65
  failure: TimeFailure | null;
92
66
  }
93
67
  /** Read side and commands of time (GuiClient.time). */
94
68
  export interface ClientTime {
95
- /** Time state and the commands that may be used now. */
69
+ /** Time state. */
96
70
  readonly state: Readable<TimeState>;
97
71
  /** How long to wait for the answer to a command (ms). */
98
72
  readonly answerTimeoutMs: number;
@@ -105,9 +79,10 @@ export interface ClientTime {
105
79
  /** Changes the speed (a pause stays in effect). */
106
80
  setSpeed(value: number | 'max'): SendResult;
107
81
  /**
108
- * Sends a command. The result arrives as the launcher's command and time events. With no run, or while waiting for
109
- * the answer to the previous command, nothing is sent and `{sent: false, reason}` is returned. Check whether a
110
- * command can be used (canPause in state and so on) before sending.
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.
111
86
  */
112
87
  send(command: TimeCommand): SendResult;
113
88
  }
@@ -118,27 +93,23 @@ export interface ClientTime {
118
93
  * - The state is built from the session copy (summary and launcher events; the summary is authoritative). A client
119
94
  * that connects midway gets the same state from the summary.
120
95
  * - The server passes commands to the launcher and returns at once. lastCommand shows whether the launcher accepted a
121
- * command, time shows that it took effect.
96
+ * command; the launcher's state (a pause, a resume, the speed) and time (where it is) show that it took effect.
122
97
  */
123
98
  export declare class TimeControl implements ClientTime {
124
99
  private readonly session;
125
100
  private readonly transport;
126
101
  /** How long to wait for an answer (ms). */
127
102
  readonly answerTimeoutMs: number;
128
- /** Variable state (used to decide beforeStart; if absent, always false). */
129
- private readonly variables;
130
103
  private readonly inFlight;
131
104
  private readonly pending;
132
105
  private readonly failureValue;
133
106
  private answerTimer;
134
107
  private lastLateness;
135
- /** Time state and the commands that may be used now. */
108
+ /** Time state. */
136
109
  readonly state: Readable<TimeState>;
137
- constructor(session: Readable<SessionView | null>, ready: Readable<boolean>, app: Readable<AppInfo | null>, transport: HttpTransport,
110
+ constructor(session: Readable<SessionView | null>, transport: HttpTransport,
138
111
  /** How long to wait for an answer (ms). */
139
- answerTimeoutMs?: number, onError?: ErrorSink,
140
- /** Variable state (used to decide beforeStart; if absent, always false). */
141
- variables?: Readable<VariablesState> | null);
112
+ answerTimeoutMs?: number, onError?: ErrorSink);
142
113
  pause(): SendResult;
143
114
  resume(): SendResult;
144
115
  /**
@@ -148,10 +119,10 @@ export declare class TimeControl implements ClientTime {
148
119
  /** Changes the speed (a pause stays in effect). */
149
120
  setSpeed(value: number | 'max'): SendResult;
150
121
  /**
151
- * Sends a command. The result arrives as the launcher's command and time events (the content of the HTTP answer is
122
+ * Sends a command. The result arrives as the launcher's command, state and time events (the content of the HTTP answer is
152
123
  * not used). With no run, or while waiting for the answer to the previous command (sending), nothing is sent and
153
124
  * `{sent: false, reason}` is returned. If no answer comes within answerTimeoutMs, stops waiting and reports it in
154
- * failure. Check whether a command can be used (canPause and so on) before sending.
125
+ * failure. Whether the launcher would accept the command is `allowed` of its state.
155
126
  */
156
127
  send(command: TimeCommand): SendResult;
157
128
  /** Stops the wait timer and stops waiting for the answer (when the client closes). */
package/types/values.d.ts CHANGED
@@ -39,6 +39,8 @@ export declare class Writable<T> implements Readable<T> {
39
39
  onError?: ErrorSink);
40
40
  get(): T;
41
41
  set(value: T): void;
42
+ /** Changes the value immediately and returns its notification, for an atomic multi-value update. */
43
+ setDeferred(value: T): () => void;
42
44
  update(change: (value: T) => T): void;
43
45
  subscribe(listener: (value: T) => void): () => void;
44
46
  /** Read-only view (get and subscribe only). */
@@ -1,6 +1,6 @@
1
+ import type { VariableAvailability } from './protocol.js';
1
2
  import { ConnectionState } from './connection.js';
2
- import { SessionView } from './session-state.js';
3
- import { TimeState } from './time.js';
3
+ import { Reason, SessionView } from './session-state.js';
4
4
  import { ErrorSink, Readable } from './values.js';
5
5
  import { ValueCondition, WriteBlock, WriteStatus, WriteValue } from './variable-state.js';
6
6
  import { HistoryPoint, OperationView, VariableInfo, VariableReading, VariableRef, VariableWatch, VariablesState, WatchOptions, WriteOptions } from './variables.js';
@@ -31,10 +31,20 @@ export interface BoundVariable {
31
31
  readonly info: VariableInfo | undefined;
32
32
  /** The last value (undefined if none yet, or if values are not received (visible is false)). */
33
33
  readonly reading: VariableReading | undefined;
34
+ /**
35
+ * Whether the ECU uses the variable now (`unknown` if the variable is not in the current run). Information only: it
36
+ * does not enter condition or block, and a disconnection does not change it.
37
+ */
38
+ readonly availability: VariableAvailability;
34
39
  /** State of the value (stale, none yet, the value at the paused time and so on). */
35
40
  readonly condition: ValueCondition;
36
41
  /** Why the variable cannot be written now (null if it can). */
37
42
  readonly block: WriteBlock | null;
43
+ /**
44
+ * When block is `launcher`: the launcher's reason, as it wrote it in `allowed.write` of its `state` (`code`, such as
45
+ * `scenario-running`, and one English sentence). null otherwise.
46
+ */
47
+ readonly launcherReason: Reason | null;
38
48
  /**
39
49
  * Status of the last write to this variable (in the current run). Every bind of the same variable sees the same
40
50
  * status.
@@ -102,7 +112,7 @@ export interface BindingSources {
102
112
  write(writes: Record<string, Record<string, number | boolean | string>>, options?: WriteOptions): Promise<OperationView>;
103
113
  };
104
114
  readonly connection: Readable<ConnectionState>;
105
- readonly time: Readable<TimeState>;
115
+ readonly connectionEpoch: () => number;
106
116
  readonly session: Readable<SessionView | null>;
107
117
  readonly onError: ErrorSink;
108
118
  }
@@ -133,10 +143,15 @@ export declare class VariableBinder {
133
143
  /** Whether the connection between the client and the GUI server is open. */
134
144
  connected(): boolean;
135
145
  /**
136
- * Why the variable cannot be written now (null if it can). Only the widget-independent reasons (Binding adds
137
- * scenario, range and value).
146
+ * Why the variable cannot be written now (null if it can). Only the widget-independent reasons (Binding adds range
147
+ * and value).
138
148
  */
139
149
  block(ref: VariableRef): WriteBlock | null;
150
+ /**
151
+ * Why the launcher does not take a write now (launcherAnswer of its last `state`; `unsupported` until a `state` says).
152
+ * The client keeps no rule of its own about it.
153
+ */
154
+ launcherReason(): Reason | null;
140
155
  /** Status of the last write to that variable in the current run. */
141
156
  status(ref: VariableRef): WriteStatus;
142
157
  /** The value sent whose result has not arrived yet (null if none). */
@@ -0,0 +1,25 @@
1
+ import type { Front, VariableView } from './front-types.js';
2
+ import { type Readable } from './values.js';
3
+ import type { VariableInfo, VariableRef } from './variables.js';
4
+ import type { WriteValue } from './variable-state.js';
5
+ export interface VariableEditorState {
6
+ readonly info: (Omit<Readonly<VariableInfo>, 'enum'> & {
7
+ readonly enum: readonly Readonly<{
8
+ name: string;
9
+ value: number;
10
+ }>[] | null;
11
+ }) | undefined;
12
+ readonly view: VariableView;
13
+ readonly shown: WriteValue | null;
14
+ readonly waiting: boolean;
15
+ readonly canWrite: boolean;
16
+ }
17
+ export interface VariableEditor {
18
+ readonly state: Readable<VariableEditorState>;
19
+ /** Returns false when no edit can be attempted. Read the write result in state. */
20
+ write(value: WriteValue): boolean;
21
+ setVisible(visible: boolean): void;
22
+ close(): void;
23
+ }
24
+ /** Binds a typed editor to a variable, including the acknowledgement and readback of a Boolean edit. */
25
+ export declare function createVariableEditor(front: Front, ref: VariableRef): VariableEditor;
@@ -54,34 +54,40 @@ export declare function valueCondition(input: ConditionInput): ValueCondition;
54
54
  /** Whether two value states are the same (kind, value, reason). */
55
55
  export declare function sameCondition(a: ValueCondition, b: ValueCondition): boolean;
56
56
  /**
57
- * Why the variable cannot be written now (null if it can).
57
+ * Why the variable cannot be written now (null if it can). In this order: the facts of the variable and the run first,
58
+ * then the launcher's answer, then the client's prediction (parameter), then what the widget needs.
58
59
  * - read-only: a read-only variable (role output).
59
60
  * - disconnected: the connection between the client and the GUI server is down.
60
61
  * - not-ready: the variable API is unavailable (not running, connecting, cannot connect).
61
62
  * - ended: the run has ended.
62
63
  * - missing: the variable is not in the current run.
63
64
  * - peer-disconnected: that ECU is not connected to the Control Server.
64
- * - parameter: a parameter can only be written before the first step.
65
- * - scenario: a scenario is running (watch only; the launcher refuses writes).
65
+ * - launcher: the launcher does not take a write now (`allowed.write` of its `state`, for example `scenario-running`
66
+ * while a scenario plays), or has not said yet that it does (no `state` yet: `unsupported`). Its reason, code and
67
+ * sentence, is BoundVariable.launcherReason (launcherAnswer of session-state.ts).
68
+ * - parameter: a parameter can only be written before the first step (the client's prediction of the ECU's rule: the
69
+ * launcher does not say it for each variable).
66
70
  * - no-range: a widget that needs a range (slider) is bound to a variable without one (min and max)
67
71
  * (BindOptions.needsRange).
68
72
  * - no-value: there is no value yet, so a widget that moves from the value (slider) cannot move
69
73
  * (BindOptions.needsValue).
70
74
  */
71
- export type WriteBlock = 'read-only' | 'disconnected' | 'not-ready' | 'ended' | 'missing' | 'peer-disconnected' | 'parameter' | 'no-range' | 'no-value' | 'scenario';
75
+ export type WriteBlock = 'read-only' | 'disconnected' | 'not-ready' | 'ended' | 'missing' | 'peer-disconnected' | 'launcher' | 'parameter' | 'no-range' | 'no-value';
72
76
  /** Input of writeBlock. */
73
77
  export interface WriteBlockInput {
74
78
  info: VariableInfo | undefined;
75
79
  status: VariablesStatus;
76
80
  connected: boolean;
77
- /** Whether a run started paused is waiting before the first step (beforeStart of client.time.state). */
81
+ /** Whether a run started paused is waiting before the first step (isHolding() of the session: `holding` of the launcher's state). */
78
82
  beforeStart: boolean;
79
83
  /** Whether that ECU is connected to the Control Server. */
80
84
  peerConnected: boolean;
85
+ /** Whether the launcher does not take a write now, or has not said that it does (launcherAnswer(state, 'write')). */
86
+ launcherRefuses: boolean;
81
87
  }
82
88
  /**
83
89
  * Decides why the variable cannot be written now (null if it can). Only the reasons that do not depend on the widget:
84
- * client.variables.bind adds scenario, no-range and no-value.
90
+ * client.variables.bind adds no-range and no-value.
85
91
  */
86
92
  export declare function writeBlock(input: WriteBlockInput): WriteBlock | null;
87
93
  /** Value to write: a boolean for bool, a number for numbers, an item's value (number) or name for enums. */