@kymoscope/sdk 0.15.0 → 0.17.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.
Files changed (47) hide show
  1. package/dist/kymoscope-embed.js +78 -78
  2. package/dist/kymoscope-sdk.js +84 -84
  3. package/dist/types/analysis/actions.d.ts +9 -0
  4. package/dist/types/analysis/aiCheck.d.ts +40 -0
  5. package/dist/types/analysis/badParts.d.ts +32 -0
  6. package/dist/types/analysis/capability.d.ts +1 -1
  7. package/dist/types/analysis/changes.d.ts +8 -0
  8. package/dist/types/analysis/context.d.ts +9 -3
  9. package/dist/types/analysis/control.d.ts +1 -1
  10. package/dist/types/analysis/energy.d.ts +21 -0
  11. package/dist/types/analysis/gap.d.ts +6 -0
  12. package/dist/types/analysis/golden.d.ts +6 -0
  13. package/dist/types/analysis/index.d.ts +4 -0
  14. package/dist/types/analysis/infer.d.ts +1 -1
  15. package/dist/types/analysis/known.d.ts +27 -0
  16. package/dist/types/analysis/lines.d.ts +1 -1
  17. package/dist/types/analysis/losses.d.ts +1 -1
  18. package/dist/types/analysis/oee.d.ts +6 -2
  19. package/dist/types/analysis/presets.d.ts +3 -3
  20. package/dist/types/analysis/ranges.d.ts +18 -0
  21. package/dist/types/analysis/reliability.d.ts +62 -1
  22. package/dist/types/analysis/report.d.ts +3 -3
  23. package/dist/types/analysis/review.d.ts +119 -0
  24. package/dist/types/analysis/runWear.d.ts +13 -0
  25. package/dist/types/analysis/shifts.d.ts +1 -0
  26. package/dist/types/analysis/stops.d.ts +10 -0
  27. package/dist/types/analysis/text.d.ts +1 -1
  28. package/dist/types/analysis/types.d.ts +35 -4
  29. package/dist/types/charts/ChartBody.d.ts +6 -1
  30. package/dist/types/components/SpectrogramChart.d.ts +24 -1
  31. package/dist/types/engine/createEngine.d.ts +22 -1
  32. package/dist/types/index.d.ts +6 -1
  33. package/dist/types/lib/data/liveDataSource.d.ts +9 -0
  34. package/dist/types/lib/live/clockProbe.d.ts +26 -0
  35. package/dist/types/lib/live/publisher.d.ts +5 -0
  36. package/dist/types/lib/live/types.d.ts +8 -0
  37. package/dist/types/lib/live/videoTrack.d.ts +46 -2
  38. package/dist/types/lib/measurePack.d.ts +13 -0
  39. package/dist/types/lib/recordings/videoSource.d.ts +12 -1
  40. package/dist/types/lib/render/heatGrid.d.ts +5 -0
  41. package/dist/types/lib/segments/rules.d.ts +4 -0
  42. package/dist/types/lib/stft.d.ts +30 -0
  43. package/dist/types/lib/sync/detect.d.ts +28 -0
  44. package/dist/types/lib/sync/estimate.d.ts +143 -0
  45. package/dist/types/lib/sync/flash.d.ts +49 -0
  46. package/dist/types/lib/sync/frameFeatures.d.ts +16 -0
  47. package/package.json +1 -1
@@ -7,7 +7,17 @@ export declare const IDLE_FACTOR = 5;
7
7
  export declare const ATTRIB_S = 60;
8
8
  export declare const STOP_CRIT = 0.2;
9
9
  export declare const OFF_GAP_S = 7200;
10
+ export declare const OFF_DAY_S: number;
11
+ export declare const RUN_GAPS = 5;
10
12
  /** `part`: a later piece of a stop a break or the time between shifts cut (1, 2…): its time counts, it is not one more stop. */
13
+ /** 05.6 lists the stops of LONG_STOP_S or more, the longest first (at most LONG_STOPS, SHOWN_STOPS of them unfolded). */
14
+ export declare const LONG_STOPS = 10;
15
+ export declare const SHOWN_STOPS = 5;
16
+ export declare const LONG_STOP_S = 7200;
17
+ /** A gap with no data while every other stream made batches in DARK_COVER of its STOP_MIN_S slots: the line ran, so
18
+ * it is a stop or a recorder that was off, which the data can't tell; 05.4 says both, for the DARK_SHOWN longest. */
19
+ export declare const DARK_COVER = 0.8;
20
+ export declare const DARK_SHOWN = 3;
11
21
  export interface Stop {
12
22
  streamId: string;
13
23
  t0: number;
@@ -3,7 +3,7 @@ import { type Finding } from './types';
3
3
  export declare const pct: (x: number) => string;
4
4
  /** A percentage already in %: whole from 10 up, one decimal under it (4.13 → "4.1%", 20.4 → "20%"). */
5
5
  export declare const pct1: (p: number) => string;
6
- /** An amount in the Process context's currency: cents under 100, whole units above. */
6
+ /** An amount in the project’s Context's currency: cents under 100, whole units above. */
7
7
  export declare function money(x: number, currency: string): string;
8
8
  /** Numbers as a manager reads them, the report's one formatter: at most 3 significant figures (2 under 1: "0.37",
9
9
  * "0.012"), whole with thousands separators from 1,000 up ("33,392"). */
@@ -33,8 +33,10 @@ export interface CycleIn {
33
33
  flag: 'good' | 'bad' | 'excluded' | null;
34
34
  /** Per channel, its lowest and highest value in the batch (measured with the deviation): what a level alert would see. */
35
35
  range?: Record<string, [number, number]> | null;
36
- /** The batch's energy in kWh (09), measured with the Process context's energy channel. */
36
+ /** The batch's energy in kWh (09), measured with the project’s Context's energy channel. */
37
37
  kwh?: number | null;
38
+ /** Seconds the batch spent in each phase of its rule (none: the rule has no phases). */
39
+ phases?: Record<string, number>;
38
40
  }
39
41
  /** A stream's golden: its value to compare, the spread of its own batches, and its band's half-width per channel. */
40
42
  /** `proposed`: no golden set, one batch stands in (not saved); `auto`: none was set, so this report set one. */
@@ -96,7 +98,7 @@ export interface ReportInput {
96
98
  t0: number;
97
99
  t1: number;
98
100
  }>;
99
- /** The project's Process context and its version (delivery B); null or absent: none set. */
101
+ /** The project’s Context and its version (delivery B); null or absent: none set. */
100
102
  context?: ProcessContext | null;
101
103
  contextVersion?: number | null;
102
104
  /** The project's enabled alert rules and the alerts they raised in the period's recordings (07). */
@@ -280,6 +282,9 @@ export interface Finding {
280
282
  /** Sections the evidence is in. */
281
283
  refs: SectionId[];
282
284
  numbers: Record<string, number>;
285
+ /** Its signature (known.ts): its section and words without numbers or dates, in the engine's vocabulary; what a
286
+ * person's "Not a problem" is kept against. */
287
+ sig?: string;
283
288
  /** Section 03's proposed golden: the batch the viewer can make its stream's golden. */
284
289
  golden?: {
285
290
  streamId: string;
@@ -346,7 +351,7 @@ export interface ReportSection {
346
351
  }>;
347
352
  /** An industry preset starts this section as its verdict alone, the rest one press away (the PDF prints it whole). */
348
353
  collapsed?: true;
349
- /** What this section took from the data because nobody set it in Process context yet (shifts, planned stops…). */
354
+ /** What this section took from the data because nobody set it in the project’s Context yet (shifts, planned stops…). */
350
355
  assumed?: string[];
351
356
  }
352
357
  export interface SectionOut {
@@ -374,7 +379,7 @@ export interface ReportCover {
374
379
  madeBy: string;
375
380
  madeAt: number;
376
381
  tz: string;
377
- /** "Process context v3" (absent in reports made before delivery B); the AI model that wrote the text, if one did. */
382
+ /** "Context v3" (absent in reports made before delivery B); the AI model that wrote the text, if one did. */
378
383
  context?: string;
379
384
  ai?: string;
380
385
  }
@@ -390,6 +395,32 @@ export interface ReportDoc {
390
395
  title: string;
391
396
  needs: string;
392
397
  }>;
398
+ /** Kymoscope's AI review (review.ts): the model, the checks it asked for and their results (what was sent back),
399
+ * and the findings it set aside or merged, each with its reason. Absent: no review. */
400
+ /** Findings set aside because the project’s Context lists them as known (known.ts), each with the reason a person gave. */
401
+ known?: Array<{
402
+ id: string;
403
+ section: string;
404
+ text: string;
405
+ reason: string;
406
+ note: string;
407
+ at: number;
408
+ }>;
409
+ review?: {
410
+ model: string;
411
+ checks: Array<{
412
+ id: string;
413
+ check: unknown;
414
+ text: string;
415
+ }>;
416
+ setAside: Array<{
417
+ id: string;
418
+ section: string;
419
+ text: string;
420
+ reason: string;
421
+ into: string | null;
422
+ }>;
423
+ };
393
424
  }
394
425
  export type Level = 'off' | 'golden' | 'better';
395
426
  /** A batch judged against its stream's golden; `gap` > 0 is worse. */
@@ -57,7 +57,12 @@ export interface ChartBodyProps {
57
57
  onContextMenu: (e: ContextMenuEvent) => void;
58
58
  xyzRef?: Ref<XYZMeshChartHandle>;
59
59
  }
60
- /** Every column a chart's settings pick (series, slots, lists); helper fields such as the multiband's add picker don't count. */
60
+ /**
61
+ * Whether a spectrogram reads its stream itself, every frame (SpectrogramLive): the flat view of one live stream
62
+ * shown alone (`loneLive`). The worksheet's data is still refreshed as samples arrive (its sample rate when it comes
63
+ * from a time column, and what `view.data()` returns); the picture no longer waits for that.
64
+ */
65
+ export declare function spectrogramPullsLive(settings: PanelChartSettings | undefined, loneLive: boolean): boolean;
61
66
  export declare function chosenColumns(settings: PanelChartSettings | undefined): string[];
62
67
  /** Renders the chart and reports whether it had anything to draw: an empty chart whose chosen
63
68
  * channels aren't all in this data says so ('missing'), the same for every kind. */
@@ -12,5 +12,28 @@ export interface SpectrogramChartProps {
12
12
  clientX: number;
13
13
  clientY: number;
14
14
  }) => void;
15
+ /**
16
+ * A live stream read every frame (no React at data rate): its raw samples, transformed as they arrive (only the
17
+ * new windows, see rollingSpectrogram) and scrolled with the smooth playout the live multiband uses, so the
18
+ * picture moves every frame instead of in a step per received message. `signal` is not read then.
19
+ */
20
+ live?: SpectrogramLive;
15
21
  }
16
- export declare function SpectrogramChart({ signal, sampleRate, windowSize, overlap, winFunc, yMode, logFreq, label, backgroundToken, onPlotContextMenu, }: SpectrogramChartProps): import("react/jsx-runtime").JSX.Element;
22
+ export interface SpectrogramLive {
23
+ /** Changes whenever samples arrive. */
24
+ version: () => number;
25
+ /** Every buffered sample of the signal, oldest first, and how many the stream had before them (see
26
+ * LiveDataSource.samplesSync). null: the stream has no such column. */
27
+ samples: () => {
28
+ values: Float64Array;
29
+ first: number;
30
+ } | null;
31
+ /** Time of the newest sample, and of the oldest after a time: the smooth playout (see advancePlayout). */
32
+ latestT: () => number;
33
+ timeAfter?: (t: number) => number;
34
+ /** The stream's id: its charts share one playout, so they show one instant. */
35
+ id?: string;
36
+ /** Seconds shown, ending now (the worksheet's live window); null: everything buffered. */
37
+ windowSeconds: number | null;
38
+ }
39
+ export declare function SpectrogramChart({ signal, sampleRate, windowSize, overlap, winFunc, yMode, logFreq, label, backgroundToken, onPlotContextMenu, live, }: SpectrogramChartProps): import("react/jsx-runtime").JSX.Element;
@@ -13,7 +13,10 @@ import { type PanelChartSettings } from '../lib/panelChartSettings';
13
13
  import type { MathChannel, MathChannelPatch } from '../lib/mathChannels/types';
14
14
  import type { EvalResult } from '../lib/mathChannels/types';
15
15
  import type { LiveConnection, LiveStreamDescriptor, LiveStreamOptions, LocalLiveStream, StreamKeyProvider } from '../lib/live/types';
16
- import { type VideoSource } from '../lib/live/videoTrack';
16
+ import { type CameraSync, type VideoSource } from '../lib/live/videoTrack';
17
+ import { type DetectSyncOptions, type DetectSyncResult } from '../lib/sync/detect';
18
+ import { type FlashResult, type FlashSwitch } from '../lib/sync/flash';
19
+ import { type ClockEstimate } from '../lib/live/clockProbe';
17
20
  import type { ChannelChooser } from '../lib/importers/types';
18
21
  import type { RecordingKey } from '../lib/recordings/keys';
19
22
  import { DATASET_PALETTE } from '../lib/datasetColors';
@@ -393,6 +396,24 @@ export declare function createEngine(options?: EngineOptions): {
393
396
  sources: () => VideoSource[];
394
397
  /** Add a video source (e.g. a RecordedVideoSource of an open recording); replaces one with the same id and recordingId. */
395
398
  register(source: VideoSource): void;
399
+ /** Set the sync record of camera `id`'s sources (live and recorded; only that recording's when `recordingId` is
400
+ * given, only the live one for null): what the Camera panel applies. Storing it is the host's (set_camera_sync). */
401
+ setSync(id: string, recordingId: string | null | undefined, sync: CameraSync | null): void;
402
+ /** Estimate recorded camera `id`'s offset (and drift) against the open recording `recordingId` it was recorded
403
+ * with, from what the picture and the data show (lib/sync): its frames are decoded in this browser. Resolves with
404
+ * the estimate or a refusal and why; stores and applies nothing (store it as method 'auto', then setSync). */
405
+ detectSync(id: string, recordingId: string, o?: DetectSyncOptions): Promise<DetectSyncResult>;
406
+ /** This browser's clock against the relay's (GET /v1/time; clockProbe.ts), or null (no relay, or an old one). */
407
+ relayClock(): Promise<ClockEstimate | null>;
408
+ /** Flash calibration of live camera `id` (lib/sync/flash.ts): it filmed a screen showing `switches` (relay Unix s;
409
+ * `displayClockOffsetMs`: the showing browser's clock against the relay's, used for the camera when its sender
410
+ * reported none). Waits until the camera's frames cover the last switch plus 3 s (at most 15 s), decodes them here
411
+ * and estimates its latency. Stores nothing: store it as method 'calibration', then setSync. */
412
+ calibrateFlash(id: string, switches: FlashSwitch[], o?: {
413
+ displayClockOffsetMs?: number | null;
414
+ signal?: AbortSignal;
415
+ onProgress?: (fraction: number) => void;
416
+ }): Promise<FlashResult>;
396
417
  /** Remove the registered sources of camera `id` (of only that recording when `recordingId` is given). */
397
418
  unregister(id: string, recordingId?: string): void;
398
419
  };
@@ -67,7 +67,12 @@ export { openMessage, sealMessage, KIND_VIDEO, KIND_CHAIN } from './lib/live/wir
67
67
  export { ChainLane, chainVerifier, decodeChain, encodeChain, newRun, CHAIN_LIVE, CHAIN_RECORDING } from './lib/live/chainWire';
68
68
  export type { Chain, StreamIntegrity } from './lib/live/chainWire';
69
69
  export { encodeVideo, decodeVideo, fragmentVideo, VIDEO_MAX_FRAGMENT, type VideoMessage } from './lib/live/videoWire';
70
- export type { VideoSource, EncodedUnit, VideoTrackInfo } from './lib/live/videoTrack';
70
+ export type { VideoSource, EncodedUnit, VideoTrackInfo, CameraSync } from './lib/live/videoTrack';
71
+ export { clockShiftS, syncShiftS } from './lib/live/videoTrack';
72
+ export { estimateSync, confidenceLabel, type FrameFeatures, type DataChannel, type EstimateOptions, type SyncEstimate, type SyncRefusal, type SyncResult, type TriedChannel } from './lib/sync/estimate';
73
+ export { type DetectSyncResult, type DetectSyncOptions } from './lib/sync/detect';
74
+ export { estimateFlash, flashCycle, flashLevel, nextFlashCycle, FLASH_ACTIVE_S, FLASH_CYCLE_S, type FlashResult, type FlashSwitch } from './lib/sync/flash';
75
+ export { probeClock, type ClockEstimate } from './lib/live/clockProbe';
71
76
  export { RecordedVideoSource, type RecordedVideoSourceOptions } from './lib/recordings/videoSource';
72
77
  export { LivePublisher, fetchUsage, liveBytesPerSec, RegistryError, type CameraQuality, type LiveProfile, type LiveUsage, type PublisherDeps, type PublisherOptions, type PublisherState, type PublisherStatus } from './lib/live/publisher';
73
78
  export { CameraSender, CAMERA_QUALITIES, LOW_PRESET, type CameraPreset, type CameraStats, type CameraLayerStats, type CameraSenderDeps, type CameraRecorder } from './lib/live/cameraSender';
@@ -26,6 +26,15 @@ export declare class LiveDataSource implements DataSource {
26
26
  * LiveBuffer.mirrorColumn). A new map per call: the columns as they are now.
27
27
  */
28
28
  columns(): ReadonlyMap<string, Float64Array>;
29
+ /**
30
+ * Every buffered sample of `column`, oldest first (see LiveBuffer.mirrorColumn: a call copies only what arrived
31
+ * since the last), and how many samples the stream had before the first of them: an index that stays put while
32
+ * the ring drops its oldest. For charts that read the raw signal every frame (the live spectrogram).
33
+ */
34
+ samplesSync(column: string): {
35
+ values: Float64Array;
36
+ first: number;
37
+ } | null;
29
38
  /** Whether `column` has had a finite value (a column the snapshot rows may thin out of view). */
30
39
  hasValues(column: string): boolean;
31
40
  /** A fresh row snapshot of the newest samples (at most `maxRows`, evenly thinned). */
@@ -0,0 +1,26 @@
1
+ /**
2
+ * This device's clock against the relay's (spec 2026-11-19-camera-sync-design.md, 4.0), as the Python library's
3
+ * clocksync: a few GET /v1/time probes, the one with the smallest round trip, the relay's reading taken at its midpoint
4
+ * (NTP). offsetMs = local − relay, good to ±rttMs/2. Senders report it at register and with every heartbeat; the
5
+ * Camera panel applies only the difference between a camera's and its data's (clockShiftS).
6
+ */
7
+ export interface ClockEstimate {
8
+ offsetMs: number;
9
+ rttMs: number;
10
+ }
11
+ export declare const CLOCK_PROBES = 5;
12
+ /** Probed again this often (ms). */
13
+ export declare const CLOCK_REPROBE_MS = 600000;
14
+ /** A probe not answered within this (ms) is lost: a stalled relay never holds a register or heartbeat. */
15
+ export declare const CLOCK_PROBE_TIMEOUT_MS = 3000;
16
+ /** The estimate, or null when no probe answered (an old relay without /v1/time). `now`: ms epoch, the clock the
17
+ * sender stamps with. */
18
+ export declare function probeClock(relayUrl: string, fetchFn: typeof fetch, now: () => number, probes?: number, timeoutMs?: number): Promise<ClockEstimate | null>;
19
+ /** The register/heartbeat body fields of an estimate (none: {}). */
20
+ export declare const clockFields: (e: ClockEstimate | null) => {
21
+ clock_offset_ms: number;
22
+ clock_rtt_ms: number;
23
+ } | {
24
+ clock_offset_ms?: undefined;
25
+ clock_rtt_ms?: undefined;
26
+ };
@@ -187,6 +187,9 @@ export declare class LivePublisher {
187
187
  private usage;
188
188
  private bitrate;
189
189
  private noticeCode;
190
+ /** This device's clock against the relay's (clockProbe.ts), reported at register and with every heartbeat. */
191
+ private clock;
192
+ private clockAt;
190
193
  constructor(opts: PublisherOptions, deps: PublisherDeps);
191
194
  /** The registered stream id (null until start() registers). */
192
195
  get streamId(): string | null;
@@ -230,6 +233,8 @@ export declare class LivePublisher {
230
233
  private mint;
231
234
  private call;
232
235
  private register;
236
+ /** Probe the relay's clock when due (at start, then every CLOCK_REPROBE_MS); a failed probe keeps the last estimate. */
237
+ private probeClock;
233
238
  private admitted;
234
239
  private notice;
235
240
  private senderDevice;
@@ -35,6 +35,10 @@ export interface LiveStreamDescriptor {
35
35
  low_of_stream_id?: string | null;
36
36
  /** Set while a plan limit holds the stream back (e.g. "Video limit reached this month"); null/absent otherwise. */
37
37
  limit_notice?: string | null;
38
+ /** A camera's sync record (list_stream_cameras); null/absent: none. */
39
+ sync?: import('./videoTrack').CameraSync | null;
40
+ /** Its sender's clock minus the relay's (ms, reported by the sender); null/absent: not reported. */
41
+ clock_offset_ms?: number | null;
38
42
  }
39
43
  /**
40
44
  * The keys of a stream in an end-to-end encrypted project: frames name their key id
@@ -112,4 +116,8 @@ export interface LiveConnection {
112
116
  integrity?: StreamIntegrity;
113
117
  /** The plan-limit banner it was opened with (LiveStreamDescriptor.limit_notice); a Camera panel shows it. */
114
118
  limitNotice?: string | null;
119
+ /** A camera's sync record (LiveStreamDescriptor.sync), else null/absent. */
120
+ sync?: import('./videoTrack').CameraSync | null;
121
+ /** Its sender's clock minus the relay's (LiveStreamDescriptor.clock_offset_ms), else null/absent. */
122
+ clockOffsetMs?: number | null;
115
123
  }
@@ -24,6 +24,27 @@ export interface VideoTrackInfo {
24
24
  * and four of the camera's usual gaps for a slow one. */
25
25
  export declare const NO_SIGNAL_MIN_MS = 3000;
26
26
  export declare function noSignalAfterMs(gapMs: number | null | undefined): number;
27
+ /**
28
+ * A camera's sync record: how its frames' stamps relate to the data's clock. offsetMs > 0: a frame is stamped that
29
+ * much after what it shows (render, sensor, encoder latency), so the player shows a later frame; driftPpm: the camera's
30
+ * clock running fast (ppm) from tRef (Unix s). Stored with the camera stream (its device's) and copied to each camera
31
+ * recording; method 'default' (its sender's, e.g. 50 ms for game capture) < 'auto' < 'calibration' < 'manual'.
32
+ */
33
+ export interface CameraSync {
34
+ offsetMs: number;
35
+ driftPpm: number;
36
+ tRef: number;
37
+ method: 'default' | 'manual' | 'auto' | 'calibration';
38
+ confidence?: number;
39
+ spreadMs?: number;
40
+ }
41
+ /** Seconds to add to the data's wall time `t` (Unix s) to get the camera stamp that shows it: offset + drift·(t − tRef). */
42
+ export declare function syncShiftS(sync: CameraSync | null | undefined, t: number): number;
43
+ /**
44
+ * Seconds to add for two senders' clocks: a camera's clock offset minus its data's (each the sender's clock minus the
45
+ * relay's, ms; see clockProbe.ts). 0 when either is unknown (an old sender reports none): nothing is guessed.
46
+ */
47
+ export declare function clockShiftS(cameraMs: number | null | undefined, dataMs: number | null | undefined): number;
27
48
  /**
28
49
  * A camera's video as the Camera panel plays it: a live camera connection's ring (kind 'live'), or a camera
29
50
  * recorded with a cloud recording (kind 'recorded', RecordedVideoSource). Listed by engine.video.sources().
@@ -41,11 +62,23 @@ export interface VideoSource {
41
62
  parentName?: string | null;
42
63
  /** Recorded: the data recording it was recorded with (that dataset's info.meta.recordingId). */
43
64
  recordingId?: string | null;
65
+ /** Its sync record (the camera recording's, or the live camera's); null/absent: none (offset 0). The Camera panel
66
+ * applies it (syncShiftS) under its own offset. engine.video.setSync changes it. */
67
+ sync?: CameraSync | null;
68
+ /** Its sender's clock minus the relay's (ms); null/absent: not reported. The Camera panel applies it against its
69
+ * data's (clockShiftS). */
70
+ clockOffsetMs?: number | null;
71
+ /** Recorded: its data recording's clock offset (the data it was recorded with); live: the data connection's. */
72
+ dataClockOffsetMs?: number | null;
44
73
  info(): VideoTrackInfo;
45
74
  /** Earliest and latest capture times (Unix s), or null. */
46
75
  range(): [number, number] | null;
47
- /** Units to decode to show the frame at capture time `t` (Unix s): the last keyframe <= t through the last unit <= t. */
76
+ /** Units to decode to show the frame at capture time `t` (Unix s): the last keyframe before it through the unit
77
+ * nearest `t` (nearestEnd). */
48
78
  seekPlan(t: number): EncodedUnit[] | Promise<EncodedUnit[]>;
79
+ /** The units to decode the span [t0, t1] (from the keyframe at or before t0), for the sync estimator and flash
80
+ * calibration (live: what the ring still holds). */
81
+ unitsBetween?(t0: number, t1: number): Promise<EncodedUnit[]>;
49
82
  /** Live: the newest keyframe and everything after it. */
50
83
  livePlan?(): EncodedUnit[];
51
84
  /** Live: each new unit; returns an unsubscribe. */
@@ -60,6 +93,13 @@ export interface VideoSource {
60
93
  /** Recorded: resolves once the codec is known (info().codec). */
61
94
  ready?(): Promise<void>;
62
95
  }
96
+ /**
97
+ * The index of the unit to show at `t` in `units` (capture order): the nearest one (a tie: the earlier), so the
98
+ * error is ±½ frame, not 0..1 frame late; before the first unit, none (-1). `floor`: the last index with t <= `t`.
99
+ */
100
+ export declare function nearestEnd(units: readonly {
101
+ t: number;
102
+ }[], t: number, floor: number): number;
63
103
  /** A live camera connection's track as a VideoSource (the same object per track while id/name/parent stay). */
64
104
  export declare function liveVideoSource(c: {
65
105
  id: string;
@@ -67,6 +107,8 @@ export declare function liveVideoSource(c: {
67
107
  parentId: string | null;
68
108
  lowOf?: string | null;
69
109
  video: VideoTrack;
110
+ sync?: CameraSync | null;
111
+ clockOffsetMs?: number | null;
70
112
  }): VideoSource;
71
113
  /** Per-camera ring of encoded units: reassembles fragments, bounds memory at GOP boundaries, plans decodes. */
72
114
  export declare class VideoTrack {
@@ -87,8 +129,10 @@ export declare class VideoTrack {
87
129
  push(m: VideoMessage): EncodedUnit | null;
88
130
  /** Drop whole GOPs from the front while over budget; the only GOP is never dropped. */
89
131
  private trim;
90
- /** Units to decode to show the frame at wall time `t` (unix s): last keyframe <= t through last unit <= t. */
132
+ /** Units to decode to show the frame at wall time `t` (unix s): its keyframe through the unit nearest t. */
91
133
  seekPlan(t: number): EncodedUnit[];
134
+ /** The units from the keyframe at or before `t0` through the last at or before `t1` (what the ring still holds). */
135
+ unitsBetween(t0: number, t1: number): EncodedUnit[];
92
136
  /** The newest keyframe and everything after it. */
93
137
  livePlan(): EncodedUnit[];
94
138
  /** Called with each completed unit added to the ring. Returns an unsubscribe. */
@@ -0,0 +1,13 @@
1
+ /** How a recording measure is stored (recording_measures.data; the app's measures.ts and the report service). A
2
+ * measure over GZIP_FROM bytes of JSON (a day of short batches' deviation runs to megabytes, over the server's 2 MB
3
+ * per row) is gzipped: plain as { gz: base64 }, sealed as the gzip bytes (JSON never starts with gzip's 0x1f 0x8b).
4
+ * Rows stored before read as they are. */
5
+ export declare const GZIP_FROM = 64000;
6
+ /** The bytes to seal for `data`: its JSON, gzipped when large. */
7
+ export declare function measureBytes(data: unknown): Promise<Uint8Array>;
8
+ /** The body to store unsealed for `data`: the measure itself, or { gz } when large. */
9
+ export declare function measureBody(data: unknown): Promise<unknown>;
10
+ /** An unsealed body back to its measure. */
11
+ export declare function fromMeasureBody<T>(x: unknown): Promise<T>;
12
+ /** Opened bytes back to their measure. */
13
+ export declare function fromMeasureBytes<T>(b: Uint8Array): Promise<T>;
@@ -1,5 +1,5 @@
1
1
  import { type MessageKey } from '../live/wire';
2
- import type { EncodedUnit, VideoSource, VideoTrackInfo } from '../live/videoTrack';
2
+ import { type CameraSync, type EncodedUnit, type VideoSource, type VideoTrackInfo } from '../live/videoTrack';
3
3
  import { type ChainCount } from './chainCheck';
4
4
  export interface RecordedVideoSourceOptions {
5
5
  /** The camera stream's id (what a Camera panel's cameraStreamId names). */
@@ -22,6 +22,11 @@ export interface RecordedVideoSourceOptions {
22
22
  open: MessageKey;
23
23
  /** Decoded units kept, in bytes (default 256 MB); least recently used chunks go first. */
24
24
  maxBytes?: number;
25
+ /** The camera recording's sync record (VideoSource.sync). */
26
+ sync?: CameraSync | null;
27
+ /** Its sender's clock offset and its data recording's (VideoSource.clockOffsetMs, dataClockOffsetMs). */
28
+ clockOffsetMs?: number | null;
29
+ dataClockOffsetMs?: number | null;
25
30
  }
26
31
  export declare class RecordedVideoSource implements VideoSource {
27
32
  readonly kind: "recorded";
@@ -30,6 +35,9 @@ export declare class RecordedVideoSource implements VideoSource {
30
35
  readonly parentId: string | null;
31
36
  readonly parentName: string | null;
32
37
  readonly recordingId: string;
38
+ sync: CameraSync | null;
39
+ clockOffsetMs: number | null;
40
+ dataClockOffsetMs: number | null;
33
41
  private chunks;
34
42
  private fetch;
35
43
  private open;
@@ -52,6 +60,9 @@ export declare class RecordedVideoSource implements VideoSource {
52
60
  /** Chunk i's units in order, its last one finished from the next chunk; [] when it can't be downloaded. */
53
61
  private units;
54
62
  seekPlan(t: number): Promise<EncodedUnit[]>;
63
+ /** Units from the last keyframe at or before `t0` through the last one at or before `t1` (capture order): what a
64
+ * decode of that span needs (the sync estimator's frame features). */
65
+ unitsBetween(t0: number, t1: number): Promise<EncodedUnit[]>;
55
66
  /** Resolves once the codec is known (the first keyframe of the first chunks), or they had none. */
56
67
  ready(): Promise<void>;
57
68
  info(): VideoTrackInfo;
@@ -7,3 +7,8 @@ export declare function narrowed(g: HeatGrid, maxW: number): {
7
7
  grid: HeatGrid;
8
8
  per: number;
9
9
  };
10
+ /**
11
+ * A colour scale a theme gives as hex colours separated by commas, lowest first (`--chart-spectrogram`), as RGB
12
+ * stops. null when it is unset or anything but two or more hex colours: the chart keeps its own scale.
13
+ */
14
+ export declare function hexStops(css: string): [number, number, number][] | null;
@@ -6,9 +6,13 @@
6
6
  export type CompareOp = '>' | '>=' | '<' | '<=' | '==' | '!=';
7
7
  export type KpiStat = 'min' | 'max' | 'mean' | 'integral' | 'first' | 'last' | 'delta';
8
8
  export declare const KPI_STATS: KpiStat[];
9
+ /** A rule's value only: `target`, the value is the distance to it, closer is better (a dimension or a weight to hit);
10
+ * `better`, which way is better when there is no target (set with the rule: everyone judges its cycles alike). */
9
11
  export interface KpiSpec {
10
12
  channel: string;
11
13
  stat: KpiStat;
14
+ target?: number;
15
+ better?: 'min' | 'max';
12
16
  }
13
17
  /** `duration` (s) and `<channel>:<stat>`; null when the channel had no sample in the segment. */
14
18
  export type Kpis = Record<string, number | null>;
@@ -35,3 +35,33 @@ export interface SpectrogramGrid {
35
35
  readonly key: string;
36
36
  }
37
37
  export declare function spectrogramGrid(signal: ArrayLike<number>, winSz: number, step: number, useHann: boolean, db: boolean, rowBin: Int32Array | null, prev?: SpectrogramGrid | null): SpectrogramGrid;
38
+ /**
39
+ * A spectrogram that follows a stream: the newest `cap` windows on the stream's own hop grid (window F starts at
40
+ * the stream's sample F * hop, counted from its first ever), the newest in the last column. A live chart reads the
41
+ * stream every frame, and the stream arrives in blocks of any size: {@link spectrogramGrid} finds the windows two
42
+ * signals share only when one starts a whole number of hops into the other, which a ring fed 500 samples at a time
43
+ * never does, so there every window was transformed again at each block and landed on a new grid (the picture
44
+ * re-rolled in place). Here the grid is the stream's: an update transforms the windows that became whole since the
45
+ * last one and moves the rest left in place. Nothing is allocated after the first call.
46
+ */
47
+ export interface RollingSpectrogram {
48
+ /** `bins` rows × `cap` columns (row r, column c at values[r * cap + c]), as amplitudes or dB like
49
+ * {@link SpectrogramGrid}; a column never filled is NaN. */
50
+ readonly values: Float32Array;
51
+ readonly cap: number;
52
+ readonly bins: number;
53
+ /** One past the newest window held, on the stream's hop grid: the columns end there. -1 before the first. */
54
+ end: number;
55
+ /** Windows held, in the last `count` columns. */
56
+ count: number;
57
+ /** The largest amplitude among them. */
58
+ max: number;
59
+ /** Windows transformed by the last update. */
60
+ computed: number;
61
+ /**
62
+ * The stream as it is now: `samples` oldest first, `first` how many samples it had before them (a ring that
63
+ * dropped its oldest). True when it took a new window.
64
+ */
65
+ update(samples: ArrayLike<number>, first: number): boolean;
66
+ }
67
+ export declare function rollingSpectrogram(winSz: number, hop: number, cap: number, useHann: boolean, db: boolean, rowBin: Int32Array | null): RollingSpectrogram;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * "Detect sync" for a recorded camera: its recording's numeric channels and its frames (decoded here, nothing leaves
3
+ * the browser) through the estimator. Reads the data, picks the active channels and the segments, decodes only the
4
+ * video those segments need, estimates. Stores nothing: the caller applies the result (set_camera_sync, method 'auto').
5
+ */
6
+ import type { DataSource, ColumnSchema } from '../data/dataSource';
7
+ import type { VideoSource } from '../live/videoTrack';
8
+ import { type EstimateOptions, type SyncResult } from './estimate';
9
+ export interface DetectSyncInput {
10
+ video: VideoSource;
11
+ /** The data recording the camera was recorded with: its dataset's source and schema. */
12
+ data: DataSource;
13
+ schema: ColumnSchema[];
14
+ /** The time column (s) and the Unix time at its 0 (the recording's info.meta.wallOrigin). */
15
+ timeKey: string;
16
+ wallOrigin: number;
17
+ }
18
+ export interface DetectSyncOptions {
19
+ signal?: AbortSignal;
20
+ /** 0..1: reading the data, then decoding (most of it), then the estimate. */
21
+ onProgress?: (fraction: number) => void;
22
+ estimate?: EstimateOptions;
23
+ }
24
+ export type DetectSyncResult = SyncResult & {
25
+ elapsedMs: number;
26
+ frames: number;
27
+ };
28
+ export declare function detectSync(input: DetectSyncInput, o?: DetectSyncOptions): Promise<DetectSyncResult>;