@vehicle-sil/gui-client 0.2.0 → 0.3.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vehicle-sil/gui-client",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Client library of the vehicle-sil GUI server: connection, run and time control, ECU variables. No dependencies; browser and Node.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/types/client.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ClientConnection, SocketFactory } from './connection.js';
2
2
  import { HttpTransport } from './http.js';
3
- import { AppInfo, CheckRequest, CheckTextRequest, ConfigText, DescribeRequest, CheckResult, ConfigList, Connections, ConnectionsRequest, DashboardResponse, Recording, SaveConfigRequest, SavedConfig, ScenarioList, SessionSummary } from './protocol.js';
3
+ import { AppInfo, CheckRequest, CheckTextRequest, ConfigText, DescribeRequest, CheckResult, ConfigList, Connections, ConnectionsRequest, DashboardResponse, PrepareRequest, PrepareResponse, Recording, SaveConfigRequest, SavedConfig, ScenarioList, SessionSummary } from './protocol.js';
4
4
  import { ClientRun, RunControl } from './run.js';
5
5
  import { ClientSession } from './session.js';
6
6
  import { ClientTime } from './time.js';
@@ -112,6 +112,8 @@ export interface GuiClient {
112
112
  * the user opens the choice. Waits in the queue of the checks, as long as `check`.
113
113
  */
114
114
  connections(request: ConnectionsRequest): Promise<Connections>;
115
+ /** `POST api/prepare`: prepares a persistent launcher when eligible. */
116
+ prepare(request: PrepareRequest): Promise<PrepareResponse>;
115
117
  /** `GET api/session`: summary of the current session (null if none). Also applied to the session copy. */
116
118
  fetchSession(): Promise<SessionSummary | null>;
117
119
  /**
@@ -5,7 +5,7 @@ import { ActionError } from './front-types.js';
5
5
  import type { Snapshot } from './front-compose.js';
6
6
  import type { StopCapture } from './run.js';
7
7
  import { type RunTarget } from './session.js';
8
- import type { CheckResult, ConfigText, SavedConfig } from './protocol.js';
8
+ import type { CheckResult, ConfigText, SavedConfig, SessionSummary } from './protocol.js';
9
9
  import { ErrorSink, Readable } from './values.js';
10
10
  /** A failed action, kept for `status.problem`. */
11
11
  export interface Failure {
@@ -57,6 +57,7 @@ export declare class FrontActions {
57
57
  idStart?: number);
58
58
  start(intent?: Intent, options?: {
59
59
  file?: string;
60
+ onStarted?: (session: SessionSummary) => void;
60
61
  }): Promise<void>;
61
62
  /**
62
63
  * Checks what `intent` would start (`api/check`). Its failure is the caller's: it is not kept for `status.problem`.
@@ -1,6 +1,6 @@
1
1
  import type { GuiClient } from './client.js';
2
2
  import type { RunTarget } from './session.js';
3
- import type { CheckResult, ConfigText, SavedConfig, Finding, OutsideState, RunEnd, ScenarioFile, ScenarioStatus, ScenarioStep } from './protocol.js';
3
+ import type { CheckResult, ConfigList, ConfigText, SavedConfig, Finding, OutsideState, Recording, RunEnd, RuntimeStatus, ScenarioFile, ScenarioStatus, ScenarioStep, SessionSummary } from './protocol.js';
4
4
  import type { ValueCondition, WriteBlock, WriteStatus } from './variable-state.js';
5
5
  import type { VariableRef, VariableValue } from './variables.js';
6
6
  import type { Readable } from './values.js';
@@ -201,6 +201,7 @@ export interface FrontRun {
201
201
  /** Starts a run of `file` (default: the start-up file). Rejects with `check-failed` and the findings if the check refuses it. */
202
202
  start(intent?: Intent, options?: {
203
203
  file?: string;
204
+ onStarted?: (session: SessionSummary) => void;
204
205
  }): Promise<void>;
205
206
  /** Stops in order. Works whatever the state of the connection (the request is sent if the network is up). */
206
207
  stop(): Promise<void>;
@@ -271,8 +272,24 @@ export interface Front {
271
272
  readonly clock: Readable<FrontClock>;
272
273
  readonly controls: Readable<FrontControls>;
273
274
  readonly scenario: Readable<FrontScenario | null>;
275
+ /** Current persistent runtime state (mode, ready/preparing/resetting/cold reason), or null until received. */
276
+ readonly runtime: Readable<RuntimeStatus | null>;
274
277
  readonly run: FrontRun;
275
278
  readonly time: FrontTime;
279
+ /**
280
+ * Prepares the persistent launcher for `options.file` (default: the start-up file) when eligible (`POST api/prepare`).
281
+ */
282
+ prepare(options?: {
283
+ file?: string;
284
+ variant?: string;
285
+ disable?: string[];
286
+ enable?: string[];
287
+ manual?: string[];
288
+ }): Promise<RuntimeStatus>;
289
+ /** Lists the configuration files under the server root (`GET api/configs`). */
290
+ configs(): Promise<ConfigList>;
291
+ /** Returns applied writes recorded in the current or last run as scenario YAML (`GET api/recording`). */
292
+ recording(): Promise<Recording | null>;
276
293
  /**
277
294
  * The networks of the run that the start's `connect` connected outside (empty when there are none, when no run is
278
295
  * going, and in a run that a `role: bridge` participant of the file connects: do not read "connected or not" from it).
package/types/index.d.ts CHANGED
@@ -22,10 +22,10 @@ export { BATCH_MS, TRY_AGAIN_LATER, webSocketFactory } from './connection.js';
22
22
  export type { SocketFactory, SocketHandlers, SocketLike } from './connection.js';
23
23
  export { DEFAULT_TIMEOUT_MS, HttpError, errorMessage, fetchTransport } from './http.js';
24
24
  export type { FetchTransportOptions, HttpOutcome, HttpRequest, HttpTransport } from './http.js';
25
- export { isHolding, launcherAnswer, phaseIndex, runOutcome } from './session-state.js';
25
+ export { isHolding, isLauncherAlive, isLauncherFinishing, isRunActive, isSessionRunning, launcherAnswer, phaseIndex, runOutcome, } from './session-state.js';
26
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, StopSessionRequestBody, SummaryCommand, SummaryLauncher, SummaryParticipant, SummaryScenario, SummaryState, TimeAnswer, TimeCommand, TimeCommandName, TimeReport, TrafficNetwork, TrafficParticipant, TrafficUnplaced, ValuesMessage, Variable, VariableSummary, VariablesSummary, OperationReport, VariableAvailability, WatchMessage, WriteAnswer, } from './protocol.js';
27
+ export { PHASES, PROTOCOL_VERSION, ProtocolError, readAppInfo, readCheckResponse, readConfigList, readConfigText, readSavedConfig, readConnections, readDashboardResponse, readPrepareResponse, readRecording, readRuntimeStatus, readScenarioList, readServerMessage, readSessionAllowed, readSessionResponse, readSessionRuntime, 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, LauncherMode, LogCounts, Open, OutsideState, ParticipantRole, ParticipantState, Phase, PrepareRequest, PrepareResponse, Recording, Replay, RunParticipant, RunRequest, RunResult, RunEnd, RunResultName, RunTiming, RunTraffic, RuntimeMode, RuntimeState, RuntimeStatus, ScenarioFile, ScenarioList, ScenarioResult, ScenarioStatus, ScenarioStep, ScenarioStepStatus, ServerAllowed, ServerAllowedItem, ServerSaveItem, ServerMessage, ServerProblem, SessionSummary, Severity, Speed, StateReport, StopRequest, StopRequestBody, StopSessionRequestBody, SummaryCommand, SummaryLauncher, SummaryParticipant, SummaryScenario, SummaryState, TimeAnswer, TimeCommand, TimeCommandName, TimeReport, TrafficNetwork, TrafficParticipant, TrafficUnplaced, ValuesMessage, Variable, VariableSummary, VariablesSummary, OperationReport, VariableAvailability, WatchMessage, WriteAnswer, } from './protocol.js';
29
29
  export { createWaveforms } from './waveforms.js';
30
30
  export type { Waveforms, WaveformSeries } from './waveforms.js';
31
31
  export { createVariableEditor } from './variable-editor.js';
@@ -2,7 +2,7 @@
2
2
  * The shapes the GUI server decides: the HTTP API (`api/*`), the WebSocket messages and the dashboard files. Parts that
3
3
  * come from the launcher (check, result, events) have the shapes of launcher.ts. Rules of the parsers: read.ts.
4
4
  */
5
- import { Open, Reader } from './read.js';
5
+ import { Open, Reader, Unreadable } from './read.js';
6
6
  import { CheckResult, ControlLink, Finding, LauncherEvent, ParticipantState, Phase, RunResult, ScenarioStatus, ScenarioStep, Speed, SummaryCommand, SummaryState, TimeReport, Caution } from './launcher.js';
7
7
  /**
8
8
  * The version of the GUI server's API that this library reads (`vehicle_sil_gui` of `api/app` and `hello`). It does not
@@ -278,13 +278,40 @@ export interface SummaryParticipant {
278
278
  /** State of the connection to the ECU's variables (the launcher's control_link event). null until it arrives. */
279
279
  control_link: ControlLink | null;
280
280
  }
281
+ export type LauncherMode = Open<'cold' | 'hot'>;
282
+ export type RuntimeMode = Open<'cold' | 'hot'>;
283
+ export type RuntimeState = Open<'idle' | 'preparing' | 'ready' | 'running' | 'resetting' | 'cold'>;
284
+ /** Persistent launcher status reported on `api/session`, `api/prepare`, `hello`, and `runtime` notifications. */
285
+ export interface RuntimeStatus {
286
+ mode: RuntimeMode;
287
+ state: RuntimeState;
288
+ config: string | null;
289
+ reason: string | null;
290
+ message: string | null;
291
+ }
292
+ export declare const readRuntimeStatus: Reader<RuntimeStatus>;
293
+ export interface PrepareRequest {
294
+ file: string;
295
+ variant?: string;
296
+ disable?: string[];
297
+ enable?: string[];
298
+ manual?: string[];
299
+ }
300
+ export interface PrepareResponse {
301
+ instance: string;
302
+ runtime: RuntimeStatus;
303
+ }
304
+ export declare const readPrepareResponse: (value: unknown) => PrepareResponse;
281
305
  /** launcher of the summary: whether the launcher process is running and, if it ended, how. */
282
306
  export interface SummaryLauncher {
283
307
  /**
284
- * Whether it is running. Stays true after it printed the result, until the process exits. Decides whether it can be
285
- * stopped.
308
+ * Whether the run is still active on its launcher (false once ended, even when a persistent launcher stays alive).
286
309
  */
287
310
  running: boolean;
311
+ /** Persistent `'hot'` or per-run `'cold'`. Omitted on older servers. */
312
+ mode?: LauncherMode;
313
+ /** Whether the underlying launcher process itself is still alive. Omitted on older servers. */
314
+ process_alive?: boolean;
288
315
  exit_code: number | null;
289
316
  /** Number of the signal that ended it (POSIX only). */
290
317
  signal: number | null;
@@ -441,6 +468,8 @@ export declare const readSessionResponse: (value: unknown) => SessionSummary | n
441
468
  export declare const readSessionInstance: (value: unknown) => string;
442
469
  /** What the server accepts, from `allowed` of an `api/session` response: also there when there is no run. */
443
470
  export declare const readSessionAllowed: (value: unknown) => ServerAllowed | null;
471
+ /** Persistent runtime status carried alongside `api/session` (undefined on older servers). */
472
+ export declare const readSessionRuntime: (value: unknown) => RuntimeStatus | null | undefined;
444
473
  /**
445
474
  * Body of POST api/stop. force: false stops in order (asking again has no further effect); true stops without waiting.
446
475
  */
@@ -559,8 +588,10 @@ export interface VariablesSummary {
559
588
  /** Number of unsettled operations the server could not keep (normally 0). */
560
589
  operations_open_omitted: number;
561
590
  }
591
+ export declare const readOperationReport: (value: unknown, path: string, u?: Unreadable) => OperationReport;
562
592
  /** Reads `variables` of a summary (present in `hello` and HTTP summaries, absent from `session` notifications). */
563
593
  export declare const readVariablesSummary: (value: unknown) => VariablesSummary;
594
+ export declare const readVariablesReport: (value: unknown, path: string, u?: Unreadable) => VariablesSummary;
564
595
  /** The `values` notification: the last values of the watched variables, and when they are from. */
565
596
  export interface ValuesMessage {
566
597
  type: 'values';
@@ -710,6 +741,10 @@ export type ServerMessage =
710
741
  /** What the server accepts now; also there when `session` is null. null from a server that does not say. */
711
742
  allowed: ServerAllowed | null;
712
743
  replay: Replay | null;
744
+ runtime?: RuntimeStatus | null;
745
+ } | {
746
+ type: 'runtime';
747
+ runtime: RuntimeStatus;
713
748
  }
714
749
  /**
715
750
  * What the server accepts changed with no `session` to carry it (a start begins or fails, the server begins to end).
@@ -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;
@@ -235,6 +239,7 @@ export interface SessionView {
235
239
  */
236
240
  launcherState: StateReport | null;
237
241
  result: RunResult | null;
242
+ state: 'running' | 'ended' | string;
238
243
  launcher: LauncherView;
239
244
  /** What the server noticed (shown in English, unchanged). */
240
245
  problems: readonly ServerProblem[];
@@ -269,6 +274,14 @@ export type RunOutcome =
269
274
  | 'ended'
270
275
  /** The launcher exited without a result. */
271
276
  | 'crashed';
277
+ /** Whether the session is running (`state === 'running'`). */
278
+ export declare function isSessionRunning(session: SessionView | SessionSummary | null | undefined): boolean;
279
+ /** Whether the run itself is actively executing on its launcher. */
280
+ export declare function isRunActive(session: SessionView | SessionSummary | null | undefined): boolean;
281
+ /** Whether a result has arrived while a one-shot launcher process is still finishing. */
282
+ export declare function isLauncherFinishing(session: SessionView | SessionSummary | null | undefined): boolean;
283
+ /** Whether the underlying launcher process is still alive (falls back to `launcher.running` on older servers). */
284
+ export declare function isLauncherAlive(session: SessionView | SessionSummary | null | undefined): boolean;
272
285
  /**
273
286
  * 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
287
  * so (`holding`; a run started paused whose launcher has a Control Server). Meanwhile the launcher writes no time
@@ -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, 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. */
@@ -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, runtime notifications, and prepare answers. */
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
  /**
@@ -106,6 +108,7 @@ export declare class SessionFeed implements ClientSession {
106
108
  private readonly current;
107
109
  private readonly synced;
108
110
  private readonly allowedValue;
111
+ private readonly runtimeValue;
109
112
  private readonly receivedAt;
110
113
  private readonly noticeList;
111
114
  private readonly rejectedValue;
@@ -117,6 +120,7 @@ export declare class SessionFeed implements ClientSession {
117
120
  readonly session: Readable<SessionView | null>;
118
121
  readonly ready: Readable<boolean>;
119
122
  readonly allowed: Readable<ServerAllowed | null>;
123
+ readonly runtime: Readable<RuntimeStatus | null>;
120
124
  readonly lastEventAt: Readable<number>;
121
125
  readonly notices: Readable<readonly Notice[]>;
122
126
  readonly rejected: Readable<boolean>;
@@ -152,6 +156,8 @@ export declare class SessionFeed implements ClientSession {
152
156
  * server that does not number it: the newest arrival wins). Used inside the library.
153
157
  */
154
158
  adoptAllowed(allowed: ServerAllowed | null): void;
159
+ /** Updates the current persistent runtime status (from HTTP `prepare`/`session`). Used inside the library. */
160
+ adoptRuntime(runtime: RuntimeStatus | null): void;
155
161
  report(message: string, count?: number): void;
156
162
  dismissNotice(id: number): void;
157
163
  /** Reads and applies a batch from the connection. */
@@ -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). */