@vehicle-sil/gui-client 0.2.0 → 0.4.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.
@@ -1,4 +1,4 @@
1
- import { CheckResult, ControlLink, Dropped, Finding, LauncherEvent, ParticipantState, Phase, RunResult, ScenarioStatus, ScenarioStep, ServerProblem, SessionSummary, Speed, StateReport, TimeReport } from './protocol.js';
1
+ import { CheckResult, ControlLink, Dropped, Finding, LauncherEvent, LauncherMode, ParticipantState, Phase, RunResult, ScenarioStatus, ScenarioStep, ServerProblem, SessionSummary, Speed, StateReport, TimeReport } from './protocol.js';
2
2
  /**
3
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
4
  * sentence.
@@ -98,8 +98,12 @@ export interface ParticipantView {
98
98
  }
99
99
  /** State of the launcher process (as the server sees it). */
100
100
  export interface LauncherView {
101
- /** Whether it is running. Stays true after the result arrives, until it exits. Decides whether it can be stopped. */
101
+ /** Whether the run is still active on its launcher (false once ended, even in hot mode). */
102
102
  running: boolean;
103
+ /** Persistent `'hot'` or per-run `'cold'`. Undefined from older servers. */
104
+ mode?: LauncherMode;
105
+ /** Whether the underlying launcher process itself is still alive. Undefined from older servers. */
106
+ processAlive?: boolean;
103
107
  exitCode: number | null;
104
108
  /** Number of the signal that ended it (POSIX only). */
105
109
  signal: number | null;
@@ -166,29 +170,12 @@ export interface ScenarioView {
166
170
  }
167
171
  /** State of one session (one run of the launcher), as the screen sees it. */
168
172
  export interface SessionView {
169
- /** Session number the server assigned. */
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>>;
190
- /** seq of the last event received (-1 if none). On reconnect, the resend is requested from the next one. */
173
+ /** Run identifier the server assigned. */
174
+ id: string;
175
+ /** seq of the last event received (-1 if none). */
191
176
  lastSeq: number;
177
+ /** Baseline launcher t_ms at the start of the run (0 on cold runs). */
178
+ runT0Ms: number;
192
179
  /** The configuration file (relative to root). */
193
180
  file: string;
194
181
  /** Participants left out. */
@@ -235,6 +222,7 @@ export interface SessionView {
235
222
  */
236
223
  launcherState: StateReport | null;
237
224
  result: RunResult | null;
225
+ state: 'running' | 'ended' | string;
238
226
  launcher: LauncherView;
239
227
  /** What the server noticed (shown in English, unchanged). */
240
228
  problems: readonly ServerProblem[];
@@ -269,6 +257,14 @@ export type RunOutcome =
269
257
  | 'ended'
270
258
  /** The launcher exited without a result. */
271
259
  | 'crashed';
260
+ /** Whether the session is running (`state === 'running'`). */
261
+ export declare function isSessionRunning(session: SessionView | SessionSummary | null | undefined): boolean;
262
+ /** Whether the run itself is actively executing on its launcher. */
263
+ export declare function isRunActive(session: SessionView | SessionSummary | null | undefined): boolean;
264
+ /** Whether a result has arrived while a one-shot launcher process is still finishing. */
265
+ export declare function isLauncherFinishing(session: SessionView | SessionSummary | null | undefined): boolean;
266
+ /** Whether the underlying launcher process is still alive (falls back to `launcher.running` on older servers). */
267
+ export declare function isLauncherAlive(session: SessionView | SessionSummary | null | undefined): boolean;
272
268
  /**
273
269
  * Whether the run waits before its first step (the step at time 0) for a resume or a step: the launcher's state says
274
270
  * so (`holding`; a run started paused whose launcher has a Control Server). Meanwhile the launcher writes no time
@@ -284,18 +280,9 @@ export declare function sessionFromSummary(summary: SessionSummary): SessionView
284
280
  */
285
281
  export declare function addDropped(session: SessionView, dropped: Dropped): SessionView;
286
282
  /**
287
- * Applies a summary. The local log is kept.
288
- *
289
- * - force (WebSocket hello and session): arrives in the same order as events, so everything is taken as correct at
290
- * the time it arrives.
291
- * - Without force (an HTTP answer): its order relative to notifications is unknown. Whether the launcher runs and the
292
- * stop requests are taken, but a launcher that has ended in the same run is never set back to running. Server
293
- * notices are taken only when there are no fewer than held locally (the server only adds, so a summary with fewer is
294
- * old). Phase, check, participants, findings, result and virtual time are taken only when the summary is newer than
295
- * the local events, and not at all with controlOnly (the WebSocket is connected and the same things arrive in
296
- * notifications), so findings do not appear twice, once from the summary and once from a notification.
283
+ * Applies an authoritative summary from the WebSocket stream (hello or session). The local log is kept.
297
284
  */
298
- export declare function applySummary(session: SessionView, summary: SessionSummary, force?: boolean, controlOnly?: boolean): SessionView;
285
+ export declare function applySummary(session: SessionView, summary: SessionSummary): SessionView;
299
286
  /**
300
287
  * Adds a server notice (later summaries carry the same one and replace it). Beyond the limit, only the number is
301
288
  * counted.
@@ -309,5 +296,3 @@ export declare function phaseIndex(phase: Phase | null): number;
309
296
  * staleEvents (seq went back). The log array is rebuilt once per batch (not copied for every event).
310
297
  */
311
298
  export declare function applyEvents(session: SessionView, events: readonly LauncherEvent[], countStale?: boolean): SessionView;
312
- /** Combines a same-run full replay with lines only the client still holds. */
313
- 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, ServerAllowed, ServerMessage, SessionSummary } from './protocol.js';
2
+ import { AuthMessage, RuntimeStatus, ServerAllowed, ServerMessage } 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. */
@@ -21,7 +21,7 @@ export interface Notice {
21
21
  }
22
22
  /** Identity of one run across all starts of the server. */
23
23
  export interface RunTarget {
24
- session: number;
24
+ run_id: string;
25
25
  instance: string;
26
26
  }
27
27
  export declare function sameRunTarget(left: RunTarget | null, right: RunTarget | null): boolean;
@@ -44,6 +44,8 @@ export interface ClientSession {
44
44
  * does not say. What the launcher accepts is `launcherState` of the session.
45
45
  */
46
46
  readonly allowed: Readable<ServerAllowed | null>;
47
+ /** Persistent launcher status reported on hello and runtime notifications. */
48
+ readonly runtime: Readable<RuntimeStatus | null>;
47
49
  /** When an event was last applied (Date.now()). The starting point for advancing elapsed time with the clock. */
48
50
  readonly lastEventAt: Readable<number>;
49
51
  /**
@@ -74,19 +76,14 @@ export interface ClientSession {
74
76
  /** Removes a notice. */
75
77
  dismissNotice(id: number): void;
76
78
  }
77
- interface Adoption {
78
- revision: number;
79
- instance: string | null;
80
- session: number | null;
81
- }
82
79
  /**
83
80
  * Copy of a session (one run of the launcher). Reads the notifications of the connection (Connection) and builds the
84
- * state from the server's summary and events.
81
+ * state from the server's single WebSocket stream (summary and events).
85
82
  *
86
83
  * - Rebuilds the state from the summary in hello (the summary is authoritative), then applies the events that follow
87
84
  * (the resent log and new events).
88
- * - On every connect, puts into the authentication message where in the session it holds the server should resend
89
- * from (resumeFields).
85
+ * - On every connect, puts into the authentication message where in the stream it holds the server should resend
86
+ * from (`{instance, run_id, after_stream_seq}` via `resumeFields`).
90
87
  * - On a hello or session whose summary core is unreadable, marks itself not in sync and asks the connection to
91
88
  * restart (receive again from hello).
92
89
  * - Passes unknown notifications and unknown events through without applying them (onMessages gets only the readable
@@ -97,15 +94,16 @@ interface Adoption {
97
94
  export declare class SessionFeed implements ClientSession {
98
95
  private readonly connection;
99
96
  private readonly onError;
97
+ private readonly onInstance?;
100
98
  private readonly rawListeners;
101
- private snapshotVersion;
102
99
  private instanceId;
103
- private adoptionRevision;
104
- private instanceListener;
100
+ private lastStreamSeq;
101
+ private resyncing;
105
102
  private stopTarget;
106
103
  private readonly current;
107
104
  private readonly synced;
108
105
  private readonly allowedValue;
106
+ private readonly runtimeValue;
109
107
  private readonly receivedAt;
110
108
  private readonly noticeList;
111
109
  private readonly rejectedValue;
@@ -113,52 +111,32 @@ export declare class SessionFeed implements ClientSession {
113
111
  private readonly messageListeners;
114
112
  private noticeId;
115
113
  private stoppedFlag;
116
- private replayLogs;
117
114
  readonly session: Readable<SessionView | null>;
118
115
  readonly ready: Readable<boolean>;
119
116
  readonly allowed: Readable<ServerAllowed | null>;
117
+ readonly runtime: Readable<RuntimeStatus | null>;
120
118
  readonly lastEventAt: Readable<number>;
121
119
  readonly notices: Readable<readonly Notice[]>;
122
120
  readonly rejected: Readable<boolean>;
123
121
  readonly incompatible: Readable<string | null>;
124
- constructor(connection: Connection, onError?: ErrorSink);
122
+ constructor(connection: Connection, onError?: ErrorSink, onInstance?: ((instance: string) => void) | undefined);
125
123
  /** Refused, or the versions differ: never connect again (set before the readable values and before disconnecting). */
126
124
  get stopped(): boolean;
127
125
  /**
128
- * Fields to add to the authentication message: where in the session it holds the server should resend from. Called
126
+ * Fields to add to the authentication message: where in the stream it holds the server should resend from. Called
129
127
  * on every connect (after the call, the copy is not in sync until hello and the resent events have arrived). Used
130
128
  * only inside the library.
131
129
  */
132
- resumeFields(): Pick<AuthMessage, 'session' | 'from_seq'>;
130
+ resumeFields(): Pick<AuthMessage, 'instance' | 'run_id' | 'after_stream_seq'>;
133
131
  onMessages(listener: (batch: readonly ServerMessage[]) => void): () => void;
134
- /**
135
- * Applies the summary in an HTTP answer without waiting for the notification (the answers to start, stop and
136
- * fetchSession(); used inside the library). While the WebSocket is connected, takes only the launcher and the stop
137
- * request for the same run (the rest arrives in notifications). A summary of an earlier run never brings back an old
138
- * run over a new one.
139
- */
140
- onRawMessages(listener: (batch: readonly unknown[], current: () => boolean, snapshotVersion: number) => void): () => void;
141
- onSnapshotVersion(read: () => number): void;
142
- /** Called before a new server's session can be published. */
143
- onInstance(listener: (instance: string, current: () => boolean) => void): void;
132
+ onRawMessages(listener: (batch: readonly unknown[], current: () => boolean) => void): () => void;
144
133
  /** Instance associated with the current session, or null if its origin is not known. */
145
134
  currentInstance(): string | null;
146
135
  currentTarget(): RunTarget | 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;
155
136
  report(message: string, count?: number): void;
156
137
  dismissNotice(id: number): void;
157
138
  /** Reads and applies a batch from the connection. */
158
139
  private receive;
159
- /** Keep messages at or after the run already observed over HTTP, within each server instance. */
160
- private filterOlderRuns;
161
140
  private apply;
162
141
  private notify;
163
142
  }
164
- export {};
package/types/time.d.ts CHANGED
@@ -27,8 +27,8 @@ export interface TimeFailure {
27
27
  */
28
28
  message: string;
29
29
  command: TimeCommandName;
30
- /** Number of the run it was sent to. */
31
- session: number | null;
30
+ /** Run identifier it was sent to. */
31
+ session: string | null;
32
32
  }
33
33
  /** Lateness figures (meaningful only while the speed is paced, such as at real-time speed). */
34
34
  export interface Lateness {
@@ -50,7 +50,7 @@ export type VariablesStatus = Open<'unknown' | 'off' | 'connecting' | 'ready' |
50
50
  /** List and state of the variables (of the current run). */
51
51
  export interface VariablesState {
52
52
  /** Which run they belong to (null without a run). */
53
- session: number | null;
53
+ session: string | null;
54
54
  status: VariablesStatus;
55
55
  /** Why the API is unavailable or cannot connect (the server's English text). null if none. */
56
56
  reason: string | null;
@@ -143,7 +143,7 @@ export interface OperationPeer {
143
143
  }
144
144
  /** Result of a write (operation). */
145
145
  export interface OperationView {
146
- session: number;
146
+ session: string;
147
147
  /** Operation number (operation in the `api/write` answer). */
148
148
  seq: number;
149
149
  /**
@@ -157,6 +157,8 @@ export interface OperationView {
157
157
  }
158
158
  /** Options of a write. */
159
159
  export interface WriteOptions {
160
+ /** Optional server instance identifier to reject stale writes across server restarts. */
161
+ instance?: string;
160
162
  /** Virtual time at which to apply it (ms). Omitted: the next step. */
161
163
  atMs?: number;
162
164
  /** If the requested time cannot be met: reject (default; not applied) or apply (applied in the next step). */
@@ -175,7 +177,7 @@ export interface WriteOptions {
175
177
  * `operations`, so a widget can show "accepted, waiting to be applied" or know that it may send the next write.
176
178
  */
177
179
  onAccepted?: (operation: {
178
- session: number;
180
+ session: string;
179
181
  seq: number;
180
182
  }) => void;
181
183
  }
@@ -270,21 +272,20 @@ export declare const WATCH_PERIOD_MS = 100;
270
272
  */
271
273
  export declare const WATCH_PERIODS_MS: readonly [20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 60000];
272
274
  /** Reads `variables` of a summary. Unreadable parts are skipped as if absent (additions are compatible). */
273
- export declare function readVariables(value: unknown, session: number | null): VariablesState;
275
+ export declare function readVariables(value: unknown, session: string | null): VariablesState;
274
276
  /** Reads an `operation` notification (or one entry of operations in a summary). null if unreadable. */
275
- export declare function readOperation(value: unknown, session: number): OperationView | null;
277
+ export declare function readOperation(value: unknown, session: string): OperationView | null;
276
278
  /** What VariablesFeed asks of the connection. */
277
279
  export interface VariablesLink {
278
280
  /** Sends if connected (does nothing otherwise; resume() sends what is needed on connect). */
279
281
  send(message: unknown): unknown;
280
- onBatch(listener: (batch: readonly unknown[], current?: () => boolean, snapshotVersion?: number) => void): () => void;
282
+ onBatch(listener: (batch: readonly unknown[], current?: () => boolean) => void): () => void;
281
283
  }
282
284
  /**
283
285
  * ECU variables: list and state, value watches, writes and their results. No framework needed.
284
286
  *
285
- * - List and state come from `variables` in hello and in HTTP summaries, and from `variables` notifications (`session`
286
- * notifications do not carry them). When the run changes, they are unknown until that run's `variables`
287
- * notification arrives.
287
+ * - List and state come from `variables` in hello and from `variables` notifications (`session` notifications do not
288
+ * carry them). When the run changes, they are unknown until that run's `variables` notification arrives.
288
289
  * - Each variable goes into the subscription with the shortest interval requested for it (one subscription per
289
290
  * interval). A changed subscription is resent with the same id (the server replaces it); after a reconnect, resume()
290
291
  * resends them all.
@@ -300,9 +301,6 @@ export declare class VariablesFeed implements Omit<ClientVariables, 'bind'> {
300
301
  /** Limits (from limits of api/app; the defaults until then). */
301
302
  private readonly limits;
302
303
  private instanceId;
303
- private snapshotVersionValue;
304
- private snapshotIdentity;
305
- private serverRevision;
306
304
  private readonly stateValue;
307
305
  private readonly operationsValue;
308
306
  private readonly handles;
@@ -335,20 +333,12 @@ export declare class VariablesFeed implements Omit<ClientVariables, 'bind'> {
335
333
  resume(): unknown[];
336
334
  /** The client was closed: fail the pending writes (including those waiting for the HTTP answer). Watches stay. */
337
335
  dispose(): void;
336
+ onInstance(instance: string): void;
338
337
  private receive;
339
338
  /** Returns whether any state changed. Only the availability table changes: `peers` keeps its identity. */
340
339
  private takeAvailability;
341
- snapshotVersion(): number;
342
- /** Compare server capture order when available; legacy peers use the local best-effort watermark. */
343
- isSnapshotCurrent(version: number, instance: string | null, session: number | null, rev: number | null): boolean;
344
- private markSnapshot;
345
- private applySnapshot;
346
- /** A reused numeric session on another server is a different run. */
347
- adoptInstance(value: unknown): void;
348
- /** Applies a summary: an older snapshot can still carry a terminal write result. */
349
- adoptSummary(summary: unknown, current?: () => boolean, snapshotCurrent?: () => boolean): number | null;
350
340
  /**
351
- * With the summary after a reconnect (or from api/session), settles as "no answer came" (lost) the writes waiting for
341
+ * With the summary after a reconnect, settles as "no answer came" (lost) the writes waiting for
352
342
  * a result that will no longer arrive. For writes whose number is not known yet (before the HTTP answer), the summary
353
343
  * is kept and checked the same way once the number is known.
354
344
  */