@kymoscope/sdk 0.25.0 → 0.27.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.
@@ -21,7 +21,11 @@ export interface LiveChartSource {
21
21
  * last time (datasets under a live overlay, a beacon's reference) is measured
22
22
  * and handed to the line renderer once; the others every time the data changes.
23
23
  */
24
- pull: (x0: number, x1: number, maxPoints: number, cutX?: number, clipsCut?: boolean) => PointColumns[];
24
+ pull: (x0: number, x1: number, maxPoints: number, cutX?: number, clipsCut?: boolean, window?: [number, number]) => PointColumns[];
25
+ /** With it, a live window on this X is in time (see the chart's tick): the X span of the samples whose time is in
26
+ * [t0, t1] (null: none), and `pull` is given that `window` (instead of cutX) to draw only those samples. For an X
27
+ * that is not time (lap distance). */
28
+ windowXBounds?: (t0: number, t1: number) => [number, number] | null;
25
29
  /** With `clipsCut` (see pull), the points come back untrimmed and unchanged until the data changes, and the chart
26
30
  * clips them at the display edge on the GPU: no copy of every point each frame. Set only when every layer is
27
31
  * this live trace (a dataset or reference under it must not be clipped). */
@@ -59,6 +59,8 @@ export interface InternalState {
59
59
  video: VideoSource[];
60
60
  mathChannels: MathChannel[];
61
61
  limits: KymoscopeLimits;
62
+ /** Worksheets outside the limits (worksheets.add with `exempt`). Never saved. */
63
+ exempt: string[];
62
64
  palette: string[];
63
65
  importing: number;
64
66
  /** null until the licence check finishes. */
@@ -25,6 +25,9 @@ export interface KymoscopeLimits {
25
25
  canImportExportWorkspaces: boolean;
26
26
  }
27
27
  export declare const UNLIMITED: KymoscopeLimits;
28
+ /** The worksheets a worksheet limit of `max` shows (at least one): every exempt one (lib/exemptWorksheet,
29
+ * host-only), plus the first `max` of the others. */
30
+ export declare function worksheetsWithinLimit<W>(list: W[], max: number | null, exempt: (w: W) => boolean): W[];
28
31
  /**
29
32
  * Where math channels are persisted. Without one they live in memory. With one,
30
33
  * the engine calls these for every change and the host pushes its authoritative
@@ -161,6 +164,9 @@ export interface WorksheetState {
161
164
  /** Live window of the worksheet's charts (seconds; null = all): each worksheet has its own. */
162
165
  liveWindowSeconds: number | null;
163
166
  charts: ChartModel[];
167
+ /** Outside the host's limits (lib/exemptWorksheet, host-only): its charts and channels are never limited, and
168
+ * it doesn't count toward the worksheet limit. Never saved: a loaded worksheet is limited. */
169
+ exempt?: boolean;
164
170
  }
165
171
  export interface LiveConnectionInfo {
166
172
  id: string;
@@ -12,7 +12,7 @@ export { createEngine } from './engine/createEngine';
12
12
  export type { KymoscopeEngine, Snapshot, ImportSource, ImportResult, ImportOptions, Exported, ParsedFile, ChartSettingsPatch, } from './engine/createEngine';
13
13
  export { KymoscopeError } from './engine/errors';
14
14
  export type { KymoscopeErrorCode } from './engine/errors';
15
- export { UNLIMITED } from './engine/types';
15
+ export { UNLIMITED, worksheetsWithinLimit } from './engine/types';
16
16
  export type { EngineOptions, EngineState, EngineEvents, KymoscopeLimits, LimitReason, MathChannelStoreAdapter, DatasetInfo, ColumnInfo, LapInfo, LapCycle, ChartKind, ChartModel, WorksheetState, LiveConnectionInfo, } from './engine/types';
17
17
  export type { ChartMark, RuleStateInfo } from './engine/alerts';
18
18
  export { CHART_KINDS, chartLabel } from './engine/kinds';
@@ -30,7 +30,10 @@ export declare class LiveDataSource implements DataSource {
30
30
  * out of the ring when first asked for (incrementally, see
31
31
  * LiveBuffer.mirrorColumn). A new map per call: the columns as they are now.
32
32
  */
33
- columns(): ReadonlyMap<string, Float64Array>;
33
+ columns(view?: {
34
+ max?: number;
35
+ tail?: number;
36
+ }): ReadonlyMap<string, Float64Array>;
34
37
  /**
35
38
  * Every buffered sample of `column`, oldest first (see LiveBuffer.mirrorColumn: a call copies only what arrived
36
39
  * since the last), and how many samples the stream had before the first of them: an index that stays put while
@@ -58,6 +61,13 @@ export declare class LiveDataSource implements DataSource {
58
61
  /** {@link getSeriesMultiSync} as chart points: on the live time axis with no
59
62
  * row objects in between (see LiveBuffer.decimatePoints). */
60
63
  getPointsSync(columns: string[], viewport: Viewport, maxPoints: number): PointColumns;
64
+ /** {@link getPointsSync} over only the samples whose time is in [t0, t1] (see LiveBuffer.decimateWindow). */
65
+ getWindowPointsSync(columns: string[], viewport: Viewport, maxPoints: number, t0: number, t1: number): PointColumns;
66
+ /** Min/max of `column` over the samples whose time is in [t0, t1] (see LiveBuffer.windowXBounds). */
67
+ windowXBoundsSync(column: string, t0: number, t1: number): {
68
+ x0: number;
69
+ x1: number;
70
+ } | null;
61
71
  xBounds(column: string): Promise<{
62
72
  x0: number;
63
73
  x1: number;
@@ -110,3 +120,14 @@ export declare class LiveDataSource implements DataSource {
110
120
  readColumns(columns: string[], offset: number, limit: number): Promise<Record<string, Float64Array>>;
111
121
  dispose(): Promise<void>;
112
122
  }
123
+ /** Columns read when first asked for (`has` answers without reading). */
124
+ /**
125
+ * A view of a buffered column for charts that can't use millions of samples a refresh: `tail`, the newest samples
126
+ * in a row (a signal for an FFT); `max`, at most that many spread over all of them, every stride-th on a grid
127
+ * counted from the stream's first sample (`first`, the absolute index of `all[0]`), so a point drawn stays drawn
128
+ * while the ring rolls.
129
+ */
130
+ export declare function liveView(all: Float64Array, first: number, view: {
131
+ max?: number;
132
+ tail?: number;
133
+ }): Float64Array;
@@ -0,0 +1,12 @@
1
+ import type { Batch } from './sampler';
2
+ export interface Plain {
3
+ kind: number;
4
+ plaintext: Uint8Array;
5
+ }
6
+ /** The relay keeps one schema for late viewers, so a batch is ONE block: it is re-sent when the channel set grows and at least every this many seconds. */
7
+ export declare const SCHEMA_RESEND_S = 10;
8
+ export declare function createEncoder(timeOrigin?: number, now?: () => number): {
9
+ encode(b: Batch): Promise<Plain[]>;
10
+ /** After a reconnect the viewer may have missed the schema: send it again with the next batch. */
11
+ reset(): void;
12
+ };
@@ -0,0 +1,2 @@
1
+ export { startSession, type Session, type SessionOptions, type EndReason } from './session';
2
+ export { isActive as diagnosticsActive, reportDiagnosticError } from './registry';
@@ -0,0 +1,18 @@
1
+ export interface SessionRecordingOptions {
2
+ /** The session's call to live-performance; throws with `status` on an HTTP error. */
3
+ post: (body: Record<string, unknown>) => Promise<{
4
+ url?: string;
5
+ ticket?: string;
6
+ }>;
7
+ /** PUT `bytes` to `url` with `Authorization: Bearer <ticket>`; throws with `status` on an HTTP error. */
8
+ put: (url: string, ticket: string, bytes: Uint8Array<ArrayBuffer>) => Promise<void>;
9
+ recordingId: string;
10
+ }
11
+ export type SessionRecording = ReturnType<typeof createSessionRecording>;
12
+ export declare function createSessionRecording(o: SessionRecordingOptions): {
13
+ add(at: number, bytes: Uint8Array): void;
14
+ /** Bytes held: the open chunk and the chunks waiting to upload. */
15
+ buffered: () => number;
16
+ /** Cuts the last chunk, waits for the uploads (at most 10 s), then rec_close (at most 3 s). Never throws. */
17
+ close(): Promise<void>;
18
+ };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Live Performance Support's seam between the app and the charts: the app turns a session on, every chart frame
3
+ * registers its PerfStats while one runs. Off: charts measure nothing (unless the debug overlay is on).
4
+ */
5
+ import type { RefObject } from 'react';
6
+ import type { PerfStats } from '../../charts/PerfHud';
7
+ export interface ChartEntry {
8
+ kind: string;
9
+ stats: PerfStats;
10
+ host: RefObject<HTMLElement | null>;
11
+ }
12
+ export interface RegisteredChart extends ChartEntry {
13
+ index: number;
14
+ }
15
+ export declare const isActive: () => boolean;
16
+ export declare function setActive(on: boolean): void;
17
+ export declare function subscribe(l: () => void): () => void;
18
+ export declare function registerChart(e: ChartEntry): () => void;
19
+ export declare const charts: () => RegisteredChart[];
20
+ /** The running session's error sink (null when none runs). */
21
+ export declare function setDiagnosticReporter(fn: ((e: unknown) => void) | null): void;
22
+ /** An error the page can't see as a window error (an import worker crashing): recorded when a session runs, else nothing. */
23
+ export declare function reportDiagnosticError(e: unknown): void;
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Diagnostics sampling (spec §5). Fast columns: one row per real frame (cheap reads only). Slow columns: once a second
3
+ * (DOM count, canvas size, heap, points: measuring them per frame would cause the spikes we look for). Marks: spikes
4
+ * with the last 10 s of frame times, and errors. No data values, file names, titles or channel names ever.
5
+ */
6
+ import type { RegisteredChart } from './registry';
7
+ export declare const SPIKE_FRAME_MS = 100;
8
+ export declare const SPIKE_TASK_MS = 200;
9
+ export declare const SPIKE_LAG_JUMP_S = 1;
10
+ export interface Sources {
11
+ now: () => number;
12
+ charts: () => RegisteredChart[];
13
+ live: () => {
14
+ age: number;
15
+ lag: number;
16
+ wait: number;
17
+ } | null;
18
+ heapMb: () => number | null;
19
+ domNodes: () => number;
20
+ canvasMp: () => number;
21
+ /** document.visibilityState === 'hidden' */
22
+ hidden: () => boolean;
23
+ }
24
+ export interface Columns {
25
+ t: number[];
26
+ columns: Record<string, number[]>;
27
+ }
28
+ export interface Script {
29
+ url?: string;
30
+ fn?: string;
31
+ ms?: number;
32
+ invoker?: string;
33
+ }
34
+ export type Mark = {
35
+ type: 'spike';
36
+ at: number;
37
+ reason: 'frame' | 'task' | 'lag';
38
+ ms: number;
39
+ frames: number[];
40
+ scripts?: Script[];
41
+ suppressed?: number;
42
+ } | {
43
+ type: 'error';
44
+ at: number;
45
+ message: string;
46
+ stack: string;
47
+ repeats?: number;
48
+ }
49
+ /** The browser's environment, sent once at the start (see environment()). */
50
+ | {
51
+ type: 'env';
52
+ at: number;
53
+ [k: string]: unknown;
54
+ };
55
+ export interface Batch {
56
+ fast: Columns;
57
+ slow: Columns;
58
+ marks: Mark[];
59
+ }
60
+ /**
61
+ * Removes anything that could name the customer's files, channels or machine from error text (spec §5). Input is cut
62
+ * to 4000 chars first and every pattern starts at a token boundary, so the cost is linear. Prefers over-scrubbing:
63
+ * `foo.bar` identifiers go too. Function names without a dot (`at foo`) survive.
64
+ */
65
+ export declare function scrub(s: string): string;
66
+ export declare function createSampler(src: Sources): {
67
+ /** Call from the page's visibilitychange: the gap that follows is a hidden tab, not a freeze. */
68
+ visibilityChanged(): void;
69
+ /** Call once per animation frame. */
70
+ frame(): void;
71
+ /** Time the diagnostics themselves took (frame sampling, encoding, sealing); summed into the slow lane's diag.overhead_ms. */
72
+ overhead(ms: number): void;
73
+ /** A long task / long animation frame from PerformanceObserver. */
74
+ longTask(ms: number, scripts?: Script[]): void;
75
+ error(e: unknown): void;
76
+ drain(): Batch;
77
+ };
78
+ /** Environment, sent once (spec §5 metadata). */
79
+ export declare function environment(): Promise<Record<string, unknown>>;
@@ -0,0 +1,22 @@
1
+ /** The server ends a session after an hour; this browser stops then even when it can't hear the server. */
2
+ export declare const SESSION_MS = 3600000;
3
+ export type EndReason = 'stopped' | 'expired' | 'error';
4
+ export interface SessionOptions {
5
+ /** e.g. `${SUPABASE_URL}/functions/v1` */
6
+ functionsUrl: string;
7
+ jwt: () => string | Promise<string>;
8
+ subject: string;
9
+ body: string;
10
+ fetch?: typeof fetch;
11
+ WebSocket?: typeof WebSocket;
12
+ raf?: (cb: FrameRequestCallback) => number;
13
+ cancelRaf?: (id: number) => void;
14
+ onEnded?: (reason: EndReason) => void;
15
+ }
16
+ export interface Session {
17
+ streamId: string;
18
+ caseId: string;
19
+ caseNumber: string;
20
+ stop(): Promise<void>;
21
+ }
22
+ export declare function startSession(o: SessionOptions): Promise<Session>;
@@ -0,0 +1,6 @@
1
+ import type { KymoscopeEngine } from '../engine/createEngine';
2
+ /** Host-only: the engine's way to add a worksheet outside the limits (a support session's). Kept off the public
3
+ * API: this file is reachable only inside the repo (`@kymoscope/sdk/lib/*`), never from the npm package. */
4
+ export declare const exemptAdders: WeakMap<object, (name: string) => string>;
5
+ /** Adds a worksheet outside the host's limits (its charts and channels too), not counted toward them, never saved. */
6
+ export declare function addExemptWorksheet(engine: KymoscopeEngine, name: string): string;
@@ -0,0 +1,72 @@
1
+ /**
2
+ * MIL-STD-1553 (Chapter 10 data type 0x19, format 1) and ARINC-429 (0x38, format 0) bus data, as channels.
3
+ *
4
+ * Without a dictionary every data word is a raw channel: a 1553 message's words are `<channel> RT<rt> <T|R>
5
+ * SA<sa> W<k>` (mode codes with a data word `<channel> RT<rt> mode <code>`), an ARINC-429 word's data field (bits
6
+ * 11-29) is `<channel> bus <b> label <octal>` (` SDI <n>` when its SDI is not 0).
7
+ * With an ICD (a CSV, see `parseIcd`) only its measurements are read, by name, with their bits, type, scale and
8
+ * unit; messages and labels it does not name are counted and skipped.
9
+ * The collector's ch10 source (kymoscope_collector/ch10_source.py) reads both the same way: a recording opened as a
10
+ * file and the live stream have the same channel names.
11
+ */
12
+ export declare const MS1553 = 25;
13
+ export declare const ARINC429 = 56;
14
+ /** One measurement of the ICD. */
15
+ export interface IcdRow {
16
+ name: string;
17
+ unit: string;
18
+ /** Recorder channel id or name; null: any. */
19
+ channel: string | null;
20
+ kind: '1553' | '429';
21
+ rt: number;
22
+ tr: 'T' | 'R';
23
+ sa: number;
24
+ /** 1-based data words, most significant first (two for a 32-bit value). */
25
+ words: number[];
26
+ label: number;
27
+ sdi: number | null;
28
+ bus: number | null;
29
+ /** Lowest bit (0: LSB of the raw value: the word(s) for 1553, the whole 32-bit word for 429) and the bit count. */
30
+ bit: number;
31
+ bits: number;
32
+ type: 'u' | 's' | 'bcd' | 'f32';
33
+ scale: number;
34
+ add: number;
35
+ }
36
+ export declare class IcdError extends Error {
37
+ }
38
+ /**
39
+ * An ICD as CSV: a header row naming its columns (any order, case ignored): name, unit, channel, then for 1553 rt,
40
+ * tr (T or R), sa, word (1-based; `3+4` for a 32-bit value, high word first), for ARINC-429 label (octal), sdi, bus;
41
+ * and bit (lowest bit, 0 = LSB; 1553 default 0, 429 default 10, ARINC bit 11), bits (1553 default 16 per word, 429
42
+ * default 19), type (u unsigned, s two's complement, bcd, f32 IEEE float; default u), scale (default 1), add
43
+ * (default 0): value = raw × scale + add. A row with a label is ARINC-429, with an rt 1553.
44
+ */
45
+ export declare function parseIcd(text: string): IcdRow[];
46
+ /** A measurement's value from its raw integer (the word(s), or the whole ARINC word). */
47
+ export declare function icdValue(r: IcdRow, raw: number): number;
48
+ /** ARINC-429 label: bits 1-8 of the word, sent most significant first (the low byte reversed), in octal. */
49
+ export declare const labelOf: (w: number) => number;
50
+ export declare const octal: (n: number) => string;
51
+ /**
52
+ * A 1553 message's identity and its data words: the command's RT, T/R and SA (the transmitting side of an RT-to-RT
53
+ * transfer), its word count, and where its data words start among the message's words. A mode code (SA 0 or 31)
54
+ * has `mode` and at most one data word. Null when it holds no data or its words are short.
55
+ */
56
+ export declare function message1553(words: number[], rt2rt: boolean): {
57
+ rt: number;
58
+ tr: 'T' | 'R';
59
+ sa: number;
60
+ mode: number | null;
61
+ data: number[];
62
+ } | null;
63
+ /** Visits a 1553 format 1 packet's messages: (rtc of its time stamp, block status, data words). */
64
+ export declare function each1553(dv: DataView, at: number, dlen: number, ipts: (o: number) => number, on: (rtc: number, status: number, words: number[]) => void): number;
65
+ /** Visits an ARINC-429 format 0 packet's words: (rtc, bus, word); returns the words with a parity or format error. */
66
+ export declare function each429(dv: DataView, at: number, dlen: number, rtc: number, on: (rtc: number, bus: number, w: number) => void): number;
67
+ /** The raw channel name of a 1553 data word or mode code. */
68
+ export declare const raw1553: (ch: string, rt: number, tr: string, sa: number, mode: number | null, k: number) => string;
69
+ /** The raw channel name of an ARINC-429 label. */
70
+ export declare const raw429: (ch: string, bus: number, label: number, sdi: number) => string;
71
+ /** ICD rows that apply to a recorder channel (by id or name). */
72
+ export declare const rowsFor: (icd: IcdRow[], id: number, name: string) => IcdRow[];
@@ -58,8 +58,13 @@ export declare class LiveBuffer {
58
58
  /** Time never decreases across the buffered samples (see lastBackAbs). */
59
59
  private get timeMonotonic();
60
60
  private lastPushT;
61
- /** Cached bucket map for the incremental live pull; see {@link decimateColumns}. */
62
- private decCache;
61
+ /** decimateColumns' bucket maps, one per X and column set (each chart on a stream keeps its own: with one shared,
62
+ * every chart's pull rebuilt the whole lap the previous chart had just built). Least recently built first. */
63
+ private decCaches;
64
+ /** decimateWindow's blocks, per X, column set and bucket width (see there). Least recently used first. */
65
+ private winBlocks;
66
+ /** windowXBounds' min/max of X per block, per X column. */
67
+ private winX;
63
68
  /** Where the newest pass of a wrapping X starts (see {@link passStart}). */
64
69
  private passTrack;
65
70
  /** The previous cycle's points (see decimateCyclePoints). */
@@ -214,6 +219,12 @@ export declare class LiveBuffer {
214
219
  * (RPM) channels. Absolute buckets keep a sample in the same bucket as the view
215
220
  * scrolls, so shared buckets are identical between pulls. */
216
221
  private accumulate;
222
+ /**
223
+ * {@link accumulate} for the samples at absolute indices [from, to), a run of samples in one bucket at a time: the
224
+ * min/max of a run are kept in locals and written to its row once (a lap-distance X stays in a bucket for many
225
+ * samples at a high rate). Same rows as accumulating one by one. Returns the lowest bucket (Infinity: none).
226
+ */
227
+ private foldRuns;
217
228
  /**
218
229
  * Min/max-decimate several columns over [x0,x1] straight from the ring — no
219
230
  * per-column copy, so the live pull allocates only the small bucket result.
@@ -239,6 +250,27 @@ export declare class LiveBuffer {
239
250
  * candidates and re-checked against the range as it is now.
240
251
  */
241
252
  private passStart;
253
+ /** Logical index of the first sample whose time is > `t` (time ascending). */
254
+ private timeIndexAfter;
255
+ /** Absolute indices [a0, a1) of the samples whose time is in [t0, t1] (time ascending). */
256
+ private windowRange;
257
+ /**
258
+ * {@link decimatePoints} on an X that is not time, over only the samples whose time is in [t0, t1]: a live window
259
+ * (the newest N seconds, or all of them) drawn against lap distance, as a time axis draws it. Buckets by X value,
260
+ * like decimateColumns. The ring is cut into blocks of WIN_BLOCK samples on the absolute index; a whole block's
261
+ * buckets are made once and kept, so a pull merges the blocks inside the window (about 1,500 at 50 kHz over 30 s)
262
+ * and folds only the samples of its two partial ends. A block a late message moved is made again. Time must ascend
263
+ * (else, and on the time axis: decimatePoints).
264
+ */
265
+ decimateWindow(xKey: string, columns: string[], x0: number, x1: number, maxPoints: number, t0: number, t1: number): PointColumns;
266
+ /** Block `k` of decimateWindow (samples [k, k + 1) x WIN_BLOCK): its buckets on X, in the order first met. */
267
+ private winBlock;
268
+ /** Min/max of `xKey` over the samples whose time is in [t0, t1] (null: none): the X a live window spans. A block
269
+ * of WIN_BLOCK samples is read once (its min/max kept); the ends of the window sample by sample. */
270
+ windowXBounds(xKey: string, t0: number, t1: number): {
271
+ x0: number;
272
+ x1: number;
273
+ } | null;
242
274
  /** Logical index (0 = oldest) of the first sample whose time is ≥ `t` (time ascending). */
243
275
  private timeIndex;
244
276
  /** Fold the samples at logical indices [from, to) into `store` (time ascending). */
@@ -14,6 +14,8 @@ export declare const KIND_LAST_VALUES = 7;
14
14
  export declare const KIND_CHAIN = 8;
15
15
  /** Events of a stream over 1,000 channels, each one channel at its own time (see blockWire.ts decodeSparse). */
16
16
  export declare const KIND_SPARSE = 9;
17
+ /** JSON marks (spikes, errors) of a Live Performance Support stream; viewers that do not know this kind skip it. */
18
+ export declare const KIND_EVENT = 10;
17
19
  export declare const KEY_ID_FLAG = 128;
18
20
  export interface SealedMessage {
19
21
  kind: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kymoscope/sdk",
3
- "version": "0.25.0",
3
+ "version": "0.27.0",
4
4
  "description": "The Kymoscope data engine and charts for the browser: import large measurement files, plot them, stream live data end-to-end encrypted.",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "homepage": "https://kymoscope.com/docs/introduction",