@kymoscope/sdk 0.12.0 → 0.14.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 (34) hide show
  1. package/dist/assets/{importer.worker-C63-1oBd.js → importer.worker-BblHvxro.js} +1 -1
  2. package/dist/importers-f62zcRz2.js +5 -0
  3. package/dist/keys-CdXDP3WJ.js +11 -0
  4. package/dist/kymoscope-embed.js +66 -66
  5. package/dist/kymoscope-sdk.js +85 -87
  6. package/dist/types/charts/chartWindow.d.ts +13 -0
  7. package/dist/types/components/dashboardGridLayout.d.ts +7 -0
  8. package/dist/types/engine/columns.d.ts +1 -10
  9. package/dist/types/engine/createEngine.d.ts +6 -13
  10. package/dist/types/engine/types.d.ts +8 -8
  11. package/dist/types/index.d.ts +4 -12
  12. package/dist/types/lib/cycles/evaluator.d.ts +1 -2
  13. package/dist/types/lib/duckdb/duckdbInstance.d.ts +0 -5
  14. package/dist/types/lib/live/blockWire.d.ts +1 -1
  15. package/dist/types/lib/live/crypto.d.ts +1 -3
  16. package/dist/types/lib/live/publisher.d.ts +2 -1
  17. package/dist/types/lib/live/videoTrack.d.ts +5 -0
  18. package/dist/types/lib/recordings/chainCheck.d.ts +24 -0
  19. package/dist/types/lib/recordings/export.d.ts +0 -1
  20. package/dist/types/lib/recordings/videoSource.d.ts +6 -0
  21. package/dist/types/lib/recordings/writer.d.ts +6 -0
  22. package/dist/types/lib/segments/liveAxis.d.ts +8 -40
  23. package/dist/types/lib/segments/rules.d.ts +3 -42
  24. package/dist/types/lib/workspaces/io.d.ts +0 -6
  25. package/dist/types/lib/yAxisTicks.d.ts +1 -1
  26. package/package.json +1 -1
  27. package/dist/importers-4CjV0qH8.js +0 -5
  28. package/dist/keys-ved5HXBj.js +0 -11
  29. package/dist/types/lib/data/historyDataSource.d.ts +0 -51
  30. package/dist/types/lib/historian/blockCache.d.ts +0 -32
  31. package/dist/types/lib/historian/export.d.ts +0 -31
  32. package/dist/types/lib/historian/khd1.d.ts +0 -41
  33. package/dist/types/lib/historian/parquet.d.ts +0 -21
  34. package/dist/types/lib/historian/reader.d.ts +0 -73
@@ -13,8 +13,19 @@ export interface ChartWindowOptions {
13
13
  /** Initial size in CSS px (the browser may adjust it). */
14
14
  width?: number;
15
15
  height?: number;
16
+ /** Initial position in screen px. Another screen than the page's needs the browser's window-management
17
+ * permission (`getScreenDetails()`); without it the browser keeps the window on the page's screen. */
18
+ left?: number;
19
+ top?: number;
16
20
  mount?: MountOptions;
17
21
  }
22
+ /** Where a chart window sits on the screens: its position and its content size. */
23
+ export interface WindowPlacement {
24
+ left: number;
25
+ top: number;
26
+ width: number;
27
+ height: number;
28
+ }
18
29
  export interface ChartWindow {
19
30
  readonly chartId: string;
20
31
  readonly window: Window;
@@ -29,3 +40,5 @@ export interface ChartWindow {
29
40
  export declare function openChartWindow(engine: KymoscopeEngine, chartId: string, mount: (element: HTMLElement, options?: MountOptions) => ChartView, o?: ChartWindowOptions): ChartWindow;
30
41
  /** Close every chart window of an engine (on dispose). */
31
42
  export declare function closeChartWindows(engine: KymoscopeEngine): void;
43
+ /** Where each open chart window of an engine is now. */
44
+ export declare function windowPlacements(engine: KymoscopeEngine): Map<string, WindowPlacement>;
@@ -20,6 +20,13 @@ export interface DashboardPanel {
20
20
  rect: DashboardGridRect;
21
21
  /** User-defined chart title. When empty/undefined the kind label is used. */
22
22
  title?: string;
23
+ /** Its own browser window when recorded (charts.recordWindows): a saved workbook keeps it so the host can offer to reopen it there. */
24
+ window?: {
25
+ left: number;
26
+ top: number;
27
+ width: number;
28
+ height: number;
29
+ };
23
30
  }
24
31
  /** Legacy 12-col grid → current scale (96 / 12 = 8). */
25
32
  export declare const LEGACY_GRID_SCALE = 8;
@@ -1,5 +1,4 @@
1
1
  import type { LoadedDataset } from '../types/loadedDataset';
2
- import { type HistoryPiece } from '../lib/data/historyDataSource';
3
2
  /** Columnar numeric data handed over by the host. */
4
3
  export interface ColumnsInput {
5
4
  name: string;
@@ -12,7 +11,7 @@ export interface ColumnsInput {
12
11
  * times a second, where the copy is most of the cost.
13
12
  */
14
13
  transfer?: boolean;
15
- /** Bands to shade under columns (a reference's envelope, Historian phase 5): edges aligned with the columns' rows. */
14
+ /** Bands to shade under columns (a reference's envelope): edges aligned with the columns' rows. */
16
15
  bands?: Record<string, {
17
16
  lo: ArrayLike<number>;
18
17
  hi: ArrayLike<number>;
@@ -50,11 +49,3 @@ export declare function replaceColumns(ds: LoadedDataset, input: Record<string,
50
49
  * (cached), never on load or on each replaceColumns.
51
50
  */
52
51
  export declare function columnsText(ds: LoadedDataset): string;
53
- /** A Historian range handed to the engine (Historian phase 4): pieces from readHistoryRange and the channels' units. */
54
- export interface HistoryRangeView {
55
- name: string;
56
- pieces: HistoryPiece[];
57
- units?: Record<string, string>;
58
- }
59
- /** A Historian range as a dataset: read through HistoryDataSource; its rows are a time-ordered sample. */
60
- export declare function historyDataset(id: string, view: HistoryRangeView): LoadedDataset;
@@ -26,7 +26,7 @@ import { type WorkbookFileOptions } from '../lib/workspaces/encrypted';
26
26
  import { canPickDirectory, isImportable, pickDirectoryEntries, type DirNode, type FolderEntry } from '../lib/folderTree';
27
27
  import { type ChartView, type MountOptions } from '../charts/runtime';
28
28
  import { type ChartWindow, type ChartWindowOptions } from '../charts/chartWindow';
29
- import { type ColumnsInput, type HistoryRangeView } from './columns';
29
+ import { type ColumnsInput } from './columns';
30
30
  import { createDerivations } from './derive';
31
31
  import { chartLabel, type ChartKindInfo } from './kinds';
32
32
  import { createLiveController } from './liveController';
@@ -35,7 +35,7 @@ import { type ChartMark, type RuleStateInfo } from './alerts';
35
35
  import type { RuleDoc } from '../rules/types';
36
36
  import type { LinkedRuleLine } from '../lib/panelChartSettings';
37
37
  import { createStore } from './store';
38
- import { type ChartKind, type ChartModel, type EngineEvents, type EngineOptions, type EngineState, type KymoscopeLimits, type SegmentContext } from './types';
38
+ import { type ChartKind, type ChartModel, type EngineEvents, type EngineOptions, type EngineState, type KymoscopeLimits } from './types';
39
39
  export declare const DEFAULT_X = "ET";
40
40
  /** Default series / scatter colours (matches the app). */
41
41
  export declare const PALETTE: string[];
@@ -49,7 +49,6 @@ export interface InternalState {
49
49
  offsets: Record<string, number>;
50
50
  colors: Record<string, string>;
51
51
  liveWindowSeconds: number | null;
52
- segmentContext: SegmentContext | null;
53
52
  /** Cycle and phase rules (lib/cycles), saved with the workbook. */
54
53
  cycleRules: CycleDefinition[];
55
54
  live: LiveConnection[];
@@ -146,13 +145,6 @@ export declare function createEngine(options?: EngineOptions): {
146
145
  }): Promise<string>;
147
146
  /** New chunks of an open recording: the dataset keeps its id, selection, colour, offset and laps. */
148
147
  reopenRecording(id: string, input: RecordingInput): Promise<void>;
149
- /**
150
- * A time range of a Historian history as a dataset (pieces from readHistoryRange; X `ElapsedTime`, Unix seconds).
151
- * Returns the id. Selected like any new dataset.
152
- */
153
- openHistoryRange(view: HistoryRangeView): string;
154
- /** New pieces for a history dataset (pan/zoom, a later read): same id, selection, colour and offset. */
155
- updateHistoryRange(id: string, view: HistoryRangeView): void;
156
148
  /** Add numeric columns from the host (selected immediately). */
157
149
  addColumns(input: ColumnsInput): string;
158
150
  /**
@@ -277,6 +269,9 @@ export declare function createEngine(options?: EngineOptions): {
277
269
  * Opening an already open chart focuses its window. Throws `popup_blocked` when the browser refuses.
278
270
  */
279
271
  openWindow(chartId: string, options?: ChartWindowOptions): ChartWindow;
272
+ /** Record in every chart where its window is now (chart.window; null: in no window), so a workbook saved next
273
+ * reopens the windows open then. Call it before a deliberate save; autosaves keep what was recorded. No undo step. */
274
+ recordWindows(): void;
280
275
  /** Font families for every chart's text (canvas text cannot inherit CSS fonts). */
281
276
  setFonts(fonts: {
282
277
  sans?: string;
@@ -335,8 +330,6 @@ export declare function createEngine(options?: EngineOptions): {
335
330
  /** Live window of a worksheet's charts (default: active; seconds, null = all). Each worksheet has its own, shared
336
331
  * by its charts; a worksheet that never set one follows the workbook's. */
337
332
  setLiveWindow(seconds: number | null, worksheetId?: string): void;
338
- /** The Segments panel's ids (history, definition, reference); saved with the workbook. */
339
- setSegmentContext(ctx: SegmentContext | null): void;
340
333
  };
341
334
  mathChannels: {
342
335
  /** Create a channel (`name` and `formula` at least). Returns it. */
@@ -387,7 +380,7 @@ export declare function createEngine(options?: EngineOptions): {
387
380
  startedAt: number;
388
381
  droppedSamples: number;
389
382
  } | null;
390
- /** Live against a reference (Historian phase 5): the definition's rule, the axis column and deltas on a connection. */
383
+ /** Live segment axis: a cycle rule's axis column on a connection (cycle-only, no live reference). */
391
384
  setSegmentAxis(id: string, cfg: LiveSegmentAxis | null): void;
392
385
  /** Samples currently buffered for a connection (cheap; poll it for counters). */
393
386
  rowCount(id: string): number;
@@ -140,6 +140,14 @@ export interface ChartModel {
140
140
  w: number;
141
141
  h: number;
142
142
  };
143
+ /** Where its own browser window was at the last charts.recordWindows(), in screen px (content size); null: in none.
144
+ * A workbook opened with this set has no window yet: offer to reopen it (openWindow puts it back there). */
145
+ window: {
146
+ left: number;
147
+ top: number;
148
+ width: number;
149
+ height: number;
150
+ } | null;
143
151
  }
144
152
  export interface WorksheetState {
145
153
  id: string;
@@ -182,12 +190,6 @@ export interface LiveConnectionInfo {
182
190
  /** Its columns as of the last structural change (the time column first). */
183
191
  channels: string[];
184
192
  }
185
- /** What the Segments panel shows (Historian phase 5): saved in workbooks by id (spec E4), never data. */
186
- export interface SegmentContext {
187
- historyId: string;
188
- definitionId: string | null;
189
- referenceId: string | null;
190
- }
191
193
  export interface EngineState {
192
194
  datasets: DatasetInfo[];
193
195
  /** Plotted ids: dataset ids, lap ids and live connection ids. */
@@ -198,8 +200,6 @@ export interface EngineState {
198
200
  live: LiveConnectionInfo[];
199
201
  /** Scrolling window for live charts on a time X axis (seconds; null = all): the active worksheet's. */
200
202
  liveWindowSeconds: number | null;
201
- /** The Segments panel's history, definition and reference, or null. */
202
- segmentContext: SegmentContext | null;
203
203
  /** Cycle and phase rules (engine.cycles), saved with the workbook. */
204
204
  cycleRules: CycleDefinition[];
205
205
  limits: KymoscopeLimits;
@@ -21,7 +21,7 @@ export type { ColumnsInput } from './engine/columns';
21
21
  export { verifyLicense } from './embed/license';
22
22
  export type { LicenseResult } from './embed/license';
23
23
  export type { ChartView, ChartViewEvents, MountOptions, ChartStyle } from './charts/runtime';
24
- export type { ChartWindow, ChartWindowOptions } from './charts/chartWindow';
24
+ export type { ChartWindow, ChartWindowOptions, WindowPlacement } from './charts/chartWindow';
25
25
  export type { ChartStatus, ContextMenuEvent } from './charts/ChartBody';
26
26
  export * from './lib/panelChartSettings';
27
27
  export { chartChannelCount } from './lib/chartChannels';
@@ -79,25 +79,17 @@ export { parseKrc, parseKrcHeader, KRC_HEADER_BYTES } from './lib/recordings/krc
79
79
  export type { RecordingInput } from './engine/createEngine';
80
80
  export { exportRecording, exportRecordingTo, EXPORT_TYPES, type ExportPart, type RecordingSource } from './lib/recordings/export';
81
81
  export type { EncryptedEnvelope, DeviceWrap, SealedKey, PasswordSealed } from './lib/live/crypto';
82
- export { generateApiToken, splitApiKey, generateDeviceKeyPair, unwrapStreamKey, unwrapForDevice, wrapForDevice, projectWrapAad, streamKeyAad, bindKeyAad, randomKey, importStreamKey, sealUnderProjectKey, openUnderProjectKey, senderBindKey, senderBinding, verifySenderBinding, deviceFingerprint, hashToken, generateSalt, deriveKey, OPEN_STREAM_PASSWORD, deriveRawKeyBase64, makeKeyCheck, verifyKeyCheck, WORKBOOK_EXPORT_AAD, workbookBodyAad, workbookKeyAad, historyKeyAad, projectConfigKeyAad, alertRuleAad, recoveryKeyAad, recoveryAttestationAad, sealWithKey, openWithKey, sealWithPassword, openWithPassword, recoveryCode, parseRecoveryCode, generateRecoveryKeyPair, recoveryPrivateKey, } from './lib/live/crypto';
82
+ export { generateApiToken, splitApiKey, generateDeviceKeyPair, unwrapStreamKey, unwrapForDevice, wrapForDevice, projectWrapAad, streamKeyAad, bindKeyAad, randomKey, importStreamKey, sealUnderProjectKey, openUnderProjectKey, senderBindKey, senderBinding, verifySenderBinding, deviceFingerprint, hashToken, generateSalt, deriveKey, OPEN_STREAM_PASSWORD, deriveRawKeyBase64, makeKeyCheck, verifyKeyCheck, WORKBOOK_EXPORT_AAD, workbookBodyAad, workbookKeyAad, projectConfigKeyAad, alertRuleAad, recoveryKeyAad, recoveryAttestationAad, sealWithKey, openWithKey, sealWithPassword, openWithPassword, recoveryCode, parseRecoveryCode, generateRecoveryKeyPair, recoveryPrivateKey, } from './lib/live/crypto';
83
83
  export * from './rules/types';
84
84
  export { validateRule, type RuleProblem } from './rules/validate';
85
85
  export { thresholdOf } from './rules/threshold';
86
86
  export { createRuleEvaluator, type RuleEvaluator, type RuleTarget, type AlertTransition, type RuleEvaluatorState, type LiveBlock } from './rules/evaluator';
87
- export { footerLength, openFooter, openSealed, blockAad, type KhdFooter, type KhdBlock, type KhdChannel, type KhdFileId, type HistoryKind, type HistoryLevel } from './lib/historian/khd1';
88
- export { warmHistoryDecoder } from './lib/historian/parquet';
89
- export { blockCache, type BlockCache, type CacheDir } from './lib/historian/blockCache';
90
- export { HistoryDataSource, splicePieces, clipPiece, slicePiece, type HistoryPiece } from './lib/data/historyDataSource';
91
- export type { HistoryRangeView } from './engine/columns';
92
87
  export { isClockAxis, formatClockTick, formatClockValue, setClockTimeZone, getClockTimeZone, subscribeClockTimeZone } from './lib/yAxisTicks';
93
- export { readHistoryRange, readFooter, chooseLevel, pickSegments, coalesce, pool, RANGE_PARALLEL, HISTORY_PIXELS, type HistorySegmentRef, type HistoryReadOptions, type HistoryRange } from './lib/historian/reader';
94
- export { exportHistoryTo, wideDay, f32text, isoMicros, MAX_WIDE_CELLS, MAX_PARQUET_VALUES, type HistoryExportFormat } from './lib/historian/export';
95
88
  export { CycleRunner, CycleSet, cycleRuleChannels, type CycleRule, type Trigger as CycleTrigger, type Condition as CycleCondition, type CycleLimits, type CycleFlag, type CycleInstance, type CycleFound, type RuleDef, type CycleDefinition, parseCycleDefinitions } from './lib/cycles/evaluator';
96
89
  export { CYCLE_TIME, readSource, findCycles, cutCycle, cycleTables, definitionChannels, kpiColumn, kpisOf, rowsCsv, type SourceColumns } from './lib/cycles/cut';
97
- export { RuleRunner, KpiAcc, resetStep, newResetState, compareOp, kpiKey, ruleChannels, localDay, zonedInstant, shiftDay, tzOffsetS, KPI_STATS, type SegmentRule, type CompareOp, type EdgeOn, type KpiStat, type KpiSpec, type Kpis, type DetectedSegment, type ResetState } from './lib/segments/rules';
98
- export type { SegmentContext } from './engine/types';
90
+ export { KpiAcc, resetStep, newResetState, compareOp, kpiKey, localDay, zonedInstant, shiftDay, tzOffsetS, KPI_STATS, type CompareOp, type KpiStat, type KpiSpec, type Kpis, type DetectedSegment, type ResetState } from './lib/segments/rules';
99
91
  export { referenceBands } from './charts/beacon';
100
92
  export { alignSegment, AxisState, axisColumn, localSeconds, resample, gridAt, buildReference, bandEdges, pooledSd, compareToReference, encodeBand, decodeBand, MAX_GRID, MAX_BAND_CELLS, type AlignAxis, type AlignedSegment, type Band, type BandFor, type ReferenceCurve, type ReferenceChannel, type Comparison } from './lib/segments/align';
101
- export { liveSegmentTracker, DELTA_SUFFIX, type LiveSegmentAxis, type LiveSegmentEvent, type LiveReference } from './lib/segments/liveAxis';
93
+ export { liveSegmentTracker, type LiveSegmentAxis, type LiveSegmentEvent } from './lib/segments/liveAxis';
102
94
  export * as analysis from './analysis';
103
95
  export { buildReport, listedFindings, viewSections, evidenceLabel, HealthAcc, EVIDENCE_TEXT, REPORT_ROLES, SECTION_TITLES, CHANNEL_ROLES, CHANNEL_ROLE_TEXT, PROCESS_MAX, completeness, confirmAll, confirmed, moneyGaps, emptyChannel, emptyContext, energyChannel, parseContext, roleOf, suggestedCount, applyInferred, inferContext, type InferInput, type InferRecording, type InferStream, type Inferred, type PlannedStop, aiInput, applyAi, type AiInput, type AiText, PRESETS, PRESET_IDS, applyPreset, namesOf, presetForIndustry, presetOf, term, type Preset, type PresetId, type AlertIn, type ChannelContext, type ChannelRole, type ProcessContext, type ChannelHealth, type RecordingHealth, type CycleIn, type Evidence, type Finding, type GoldenIn, type RecordingIn, type ReportAction, type ReportChart, type ReportCover, type ReportDoc, type ReportInput, type ReportRole, type ReportSection, type SectionId, } from './analysis';
@@ -1,8 +1,7 @@
1
1
  /**
2
2
  * Cycle rules v2 (spec docs/superpowers/specs/2026-10-28-cycles-design.md, "Rules"): where a source is cut into cycles,
3
3
  * and phases inside them. Boundaries and flags only; KPIs are the app's job. The collector runs the same semantics
4
- * (packages/collector/src/kymoscope_collector/cycles.py), pinned by tests/vectors/cycle-rules-v2.json. Saved v1 rules
5
- * (segment_definitions rule_v 1) keep running through ../segments/rules.ts RuleRunner.
4
+ * (packages/collector/src/kymoscope_collector/cycles.py), pinned by tests/vectors/cycle-rules-v2.json.
6
5
  *
7
6
  * Semantics:
8
7
  * - A start fires when its trigger becomes true (a condition rising, or an event: change, cross, reset, clock,
@@ -5,8 +5,3 @@ import * as duckdb from '@duckdb/duckdb-wasm';
5
5
  export declare function wasmModuleUrl(url: string): Promise<string>;
6
6
  /** Lazily instantiate a single DuckDB-WASM database for this tab. */
7
7
  export declare function getDuckDb(): Promise<duckdb.AsyncDuckDB>;
8
- /** The DuckDB of getDuckDb() with the Parquet extension loaded (the browser build doesn't include it). It is loaded
9
- * from this site (`/duckdb-ext/v<version>/wasm_eh/parquet.duckdb_extension.wasm`, DuckDB's own signed file copied
10
- * into public/), never from extensions.duckdb.org. A failed load is retried on the next call.
11
- * ponytail: same origin as the page; an SDK host that serves the app elsewhere copies that folder too. */
12
- export declare function getParquetDuckDb(): Promise<duckdb.AsyncDuckDB>;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Wire v2: KIND_BLOCK_SCHEMA carries the channel table once (the relay keeps the latest for viewers who join and
3
3
  * puts it first in every recording chunk); KIND_BLOCK rows refer to it by id, with µs time deltas and byte-split
4
- * values, deflate-compressed before sealing. Normative format: docs/superpowers/plans/2026-10-23-historian-phase1.md;
4
+ * values, deflate-compressed before sealing. Normative format: docs/wire-format.md;
5
5
  * pinned by tests/vectors/block-v2.json; byte-compatible with packages/python/src/kymoscope/wire.py.
6
6
  */
7
7
  import type { LiveColumnsBlock } from './buffer';
@@ -30,6 +30,7 @@ export declare function deriveKey(passphrase: string, saltB64: string): Promise<
30
30
  export declare function deriveRawKeyBase64(passphrase: string, saltB64: string): Promise<string>;
31
31
  /** Import raw AES-256 key bytes (base64) for encrypt/decrypt — e.g. a stream key. */
32
32
  export declare function importRawKeyBase64(keyB64: string): Promise<CryptoKey>;
33
+ export declare function gcmIv(): Uint8Array;
33
34
  /** Encrypt a JSON-serializable value into an envelope. */
34
35
  export declare function encryptJSON(key: CryptoKey, value: unknown): Promise<EncryptedEnvelope>;
35
36
  /** Decrypt an envelope to raw plaintext bytes. Throws if tampered/wrong key. */
@@ -120,9 +121,6 @@ export declare function deviceFingerprint(publicKey: string): Promise<string>;
120
121
  export declare const WORKBOOK_EXPORT_AAD = "kymoscope-workbook-export-v2";
121
122
  export declare const workbookBodyAad: (workbookId: string, version: number) => string;
122
123
  export declare const workbookKeyAad: (workbookId: string, projectId: string, epoch: number) => string;
123
- /** A collector's day-history key sealed under the project key (resource_keys 'history_key'). Python twin:
124
- * kymoscope.crypto.history_key_aad. */
125
- export declare const historyKeyAad: (keyId: string, projectId: string, epoch: number) => string;
126
124
  /** A project's config key (alert rules) sealed under the project key: resource_keys 'project_config', id = the project. */
127
125
  export declare const projectConfigKeyAad: (projectId: string, epoch: number) => string;
128
126
  /** An alert rule's kyr/1 body sealed under its project's config key: bound to the rule, its version and project. */
@@ -211,7 +211,8 @@ export declare class LivePublisher {
211
211
  /** Seal with the current stream key (the key id of its epoch when e2ee) and send; false if not sent
212
212
  * (no key yet, socket down, stopped). */
213
213
  send(kind: number, plaintext: Uint8Array): Promise<boolean>;
214
- /** The sealed message send() would publish (what a recorder keeps), or null without a stream key yet. */
214
+ /** The sealed message send() would publish (what a recorder keeps), or null without a stream key yet. It still
215
+ * seals after stop(): a recorder closing then seals its last chunk's checkpoint. */
215
216
  seal(kind: number, plaintext: Uint8Array): Promise<Uint8Array<ArrayBuffer> | null>;
216
217
  /** Publish an already sealed message; false when the socket is down. While a checkpoint is being sealed it waits
217
218
  * for it (a few ms), so the wire keeps the order the checkpoint counts. */
@@ -52,6 +52,11 @@ export interface VideoSource {
52
52
  onUnit?(fn: (u: EncodedUnit) => void): () => void;
53
53
  /** Live: hold the video while it is shown; returns the release. */
54
54
  acquire?(): () => void;
55
+ /** Recorded: its chunks' integrity checkpoints so far (RecordedVideoSource.integrity); null: none had one. */
56
+ integrity?(): {
57
+ verified: number;
58
+ broken: number;
59
+ } | null;
55
60
  /** Recorded: resolves once the codec is known (info().codec). */
56
61
  ready?(): Promise<void>;
57
62
  }
@@ -0,0 +1,24 @@
1
+ import type { KrcHeader, KrcMessage } from './krc';
2
+ export type ChunkCheck = 'verified' | 'broken' | 'unchecked';
3
+ export interface ChainCount {
4
+ verified: number;
5
+ broken: number;
6
+ unchecked: number;
7
+ }
8
+ type Open = (m: Uint8Array) => Promise<{
9
+ kind: number;
10
+ plaintext: Uint8Array;
11
+ } | null>;
12
+ /** One chunk's own checkpoint; `expectSeq`: the seq it must have (the one after the previous chunk of its recording,
13
+ * 0 for the first). Unchecked: it has none (an older sender, or a checkpoint its sender couldn't seal). */
14
+ export declare function checkChunk(header: Pick<KrcHeader, 'recordingId' | 'seq'>, messages: KrcMessage[], open: Open, expectSeq: number): Promise<ChunkCheck>;
15
+ /**
16
+ * The chunks' results by recording id. A chunk without a checkpoint in a recording whose other chunks have one is
17
+ * broken itself (stripped, or its sender failed to seal it): it never breaks the next one, which is checked against
18
+ * its header's seq. A recording with none at all (an older sender) is only unchecked.
19
+ */
20
+ export declare function chainCount(results: Iterable<{
21
+ rid: string;
22
+ check: ChunkCheck;
23
+ }>): ChainCount;
24
+ export {};
@@ -15,7 +15,6 @@ export interface ExportOptions {
15
15
  export declare const EXPORT_TYPES: {
16
16
  readonly csv: "text/csv";
17
17
  readonly mf4: "application/octet-stream";
18
- readonly parquet: "application/vnd.apache.parquet";
19
18
  };
20
19
  /**
21
20
  * A recording as a CSV or MF4 file, built in the browser from its encrypted chunks and handed to `write` piece by
@@ -1,5 +1,6 @@
1
1
  import { type MessageKey } from '../live/wire';
2
2
  import type { EncodedUnit, VideoSource, VideoTrackInfo } from '../live/videoTrack';
3
+ import { type ChainCount } from './chainCheck';
3
4
  export interface RecordedVideoSourceOptions {
4
5
  /** The camera stream's id (what a Camera panel's cameraStreamId names). */
5
6
  id: string;
@@ -42,6 +43,8 @@ export declare class RecordedVideoSource implements VideoSource {
42
43
  private height;
43
44
  private codec;
44
45
  private waiting;
46
+ /** Each downloaded chunk's checkpoint result, by chunk index (kept when its units are evicted). */
47
+ private checks;
45
48
  constructor(o: RecordedVideoSourceOptions);
46
49
  private parse;
47
50
  private parsed;
@@ -52,5 +55,8 @@ export declare class RecordedVideoSource implements VideoSource {
52
55
  /** Resolves once the codec is known (the first keyframe of the first chunks), or they had none. */
53
56
  ready(): Promise<void>;
54
57
  info(): VideoTrackInfo;
58
+ /** The checkpoints of the chunks downloaded so far; null while none had one (an older sender). A chunk of another
59
+ * recording than most of them is broken. ponytail: "most" of those downloaded so far. */
60
+ integrity(): ChainCount | null;
55
61
  range(): [number, number] | null;
56
62
  }
@@ -74,6 +74,9 @@ export interface BrowserRecorderOptions {
74
74
  /** Own storage only: how long it keeps the files. */
75
75
  retentionDays?: number;
76
76
  onStatus?: (s: RecorderStatus) => void;
77
+ /** Seal with the stream key (LivePublisher.seal): every chunk then ends with a lane-1 checkpoint. Without it the
78
+ * chunks carry none (as before). */
79
+ seal?: (kind: number, plaintext: Uint8Array) => Promise<Uint8Array | null>;
77
80
  /** Test seams. */
78
81
  root?: () => Promise<RecDir>;
79
82
  fetch?: typeof fetch;
@@ -155,6 +158,9 @@ export declare class BrowserRecorder {
155
158
  private openFile;
156
159
  private endFile;
157
160
  private flush;
161
+ /** Lane 1: the chunk's last record becomes a checkpoint over its records (none without `seal`, a stream id that
162
+ * isn't a uuid, or no stream key: the chunk is then unchecked, as an older sender's). */
163
+ private checkpoint;
158
164
  /** Every file under rec/ counts (one budget for every stream); past it the oldest chunks go. */
159
165
  private enforceMax;
160
166
  private status;
@@ -1,62 +1,30 @@
1
1
  /**
2
- * Live against a reference (Historian phase 5; spec E3 "Live against reference"; plan S6): on every ingested block the
3
- * definition's rule runs over the new samples, and the open segment's X on the alignment axis is written into the ring
4
- * as a computed column (`column`), restarting at each segment, so the beacon chart (cycles on that column) draws the
5
- * open segment over the reference dataset with no React at data rate. With a reference, `<channel> Δ` columns (value −
6
- * reference mean at the same X) are written too, and every sample is checked against the band where the reference has
7
- * ≥ 2 segments (a single reference gives a delta, never deviations; as compareToReference): `onEvent` fires only on
8
- * transitions (open, close, deviation start once it lasted minDeviationS, deviation end after minDeviationS back in band). Work is per block: a few arrays per
9
- * block, nothing allocated per sample.
2
+ * A live stream's cycles: on every ingested block the cycle rule (rules v2) runs over the new samples, and the open
3
+ * cycle's X on the alignment axis is written into the ring as a computed column (`column`), restarting at each cycle,
4
+ * so the beacon chart (cycles on that column) draws the running cycle with no React at data rate. `onEvent` fires on
5
+ * transitions only (a cycle opens, a cycle closes). Work is per block: a few arrays per block, nothing allocated per
6
+ * sample.
10
7
  */
11
8
  import { type LiveBuffer } from '../live/buffer';
12
9
  import { type AlignAxis } from './align';
13
- import { type DetectedSegment, type KpiSpec, type SegmentRule } from './rules';
10
+ import type { DetectedSegment } from './rules';
14
11
  import { type CycleRule } from '../cycles/evaluator';
15
- export declare const DELTA_SUFFIX = " \u0394";
16
- export interface LiveReference {
17
- grid: Float64Array;
18
- /** Per channel: mean and band edges on the grid, and the segments behind each point (the band counts where n ≥ 2). */
19
- channels: Map<string, {
20
- mean: Float32Array;
21
- lo: Float32Array;
22
- hi: Float32Array;
23
- n: ArrayLike<number>;
24
- }>;
25
- }
26
12
  export type LiveSegmentEvent = {
27
13
  type: 'open';
28
14
  tstart: number;
29
15
  } | {
30
16
  type: 'close';
31
17
  segment: DetectedSegment;
32
- } | {
33
- type: 'deviation';
34
- t0: number;
35
- channels: string[];
36
- } | {
37
- type: 'deviation-end';
38
- t0: number;
39
- t1: number;
40
- channels: string[];
41
18
  };
42
19
  export interface LiveSegmentAxis {
43
- /** A segment rule (v1); unused with `cycle`. */
44
- rule?: SegmentRule;
45
- /** A cycle rule (rules v2) instead of `rule` ("Follow the running cycle" on a cycle rule): its cycles open and close
46
- * the axis; KPIs are not computed live for it. */
47
- cycle?: CycleRule;
48
- kpis?: KpiSpec[];
20
+ /** The cycle rule ("Follow the running cycle"): its cycles open and close the axis; KPIs are not computed live. */
21
+ cycle: CycleRule;
49
22
  axis: AlignAxis;
50
23
  /** The computed X column written into the ring, and its unit. */
51
24
  column: string;
52
25
  unit: string;
53
- /** The open segment's start when the ring may no longer hold it (the collector's open segment), else null. */
54
- start?: number | null;
55
- reference?: LiveReference | null;
56
26
  /** Also report the cycles already in the ring when it starts (open / close events for them); default: only new ones. */
57
27
  replay?: boolean;
58
- /** A deviation is reported once out of band this long (s); default 5. */
59
- minDeviationS?: number;
60
28
  onEvent?: (e: LiveSegmentEvent) => void;
61
29
  }
62
30
  export declare function liveSegmentTracker(cfg: LiveSegmentAxis): {
@@ -1,31 +1,9 @@
1
1
  /**
2
- * Segment rules (Historian phase 5; spec E1 "Segment definition"): where a stream is cut into segments, and the KPIs
3
- * captured when a segment closes. One state machine for every use: a history read day by day (app segmentRun.ts), the
4
- * live ring buffer (liveAxis.ts) and, from the same JSON, the collector (packages/collector/src/kymoscope_collector/
5
- * segments.py), pinned by tests/vectors/segment-rules-v1.json. Semantics: the plan's Formats "Rule JSON". A NaN value
6
- * never changes a rule. splitLaps (../beacon.ts) is the edge rule `reset` through resetStep.
2
+ * Helpers shared by the cycle rules (../cycles/evaluator.ts, pinned by tests/vectors/cycle-rules-v2.json), the cycle
3
+ * cut and the analysis: comparisons, the reset rule, zones and KPIs. A NaN value never changes a rule. splitLaps
4
+ * (../beacon.ts) is the reset rule through resetStep.
7
5
  */
8
6
  export type CompareOp = '>' | '>=' | '<' | '<=' | '==' | '!=';
9
- export type EdgeOn = 'change' | 'rise' | 'fall' | 'reset';
10
- export type SegmentRule = {
11
- kind: 'manual';
12
- } | {
13
- kind: 'edge';
14
- channel: string;
15
- on: EdgeOn;
16
- value?: number;
17
- } | {
18
- kind: 'condition';
19
- channel: string;
20
- op: CompareOp;
21
- value: number;
22
- hysteresis?: number;
23
- min_s?: number;
24
- } | {
25
- kind: 'window';
26
- starts: string[];
27
- tz: string;
28
- };
29
7
  export type KpiStat = 'min' | 'max' | 'mean' | 'integral' | 'first' | 'last' | 'delta';
30
8
  export declare const KPI_STATS: KpiStat[];
31
9
  export interface KpiSpec {
@@ -42,7 +20,6 @@ export interface DetectedSegment {
42
20
  flags?: Array<'late' | 'too-long' | 'too-short'>;
43
21
  }
44
22
  export declare const kpiKey: (k: KpiSpec) => string;
45
- export declare const ruleChannels: (r: SegmentRule) => string[];
46
23
  export declare function compareOp(op: CompareOp, v: number, c: number): boolean;
47
24
  /** A cycle's running state for resetStep; prev NaN: nothing seen yet. */
48
25
  export interface ResetState {
@@ -73,19 +50,3 @@ export declare class KpiAcc {
73
50
  add(t: number, v: number): void;
74
51
  value(stat: KpiStat): number | null;
75
52
  }
76
- export declare class RuleRunner {
77
- #private;
78
- readonly rule: SegmentRule;
79
- readonly kpis: KpiSpec[];
80
- constructor(rule: SegmentRule, kpis?: KpiSpec[]);
81
- /** Continue a segment that started at `tstart`, before the data fed from now on (a live ring that no longer holds it). */
82
- assumeOpen(tstart: number): void;
83
- /**
84
- * Samples in time order; returns the segments they closed. `col(name)`: the column of a channel, aligned with `t`
85
- * (NaN where it has no value), or undefined. `each(i, start)`: after sample i, the start of the open segment (a
86
- * condition still shorter than min_s counts), null outside one.
87
- */
88
- feed(t: ArrayLike<number>, col: (name: string) => ArrayLike<number> | undefined, each?: (i: number, start: number | null) => void): DetectedSegment[];
89
- /** The open segment so far (its KPIs up to the last sample; tend null), or null. A condition shows once it lasted min_s. */
90
- open(): DetectedSegment | null;
91
- }
@@ -4,7 +4,6 @@ import type { PanelChartSettings } from '../panelChartSettings';
4
4
  import type { DashboardPanel, DashboardPanelKind } from '../../components/dashboardGridLayout';
5
5
  import type { BeaconConfig } from '../beacon';
6
6
  import type { MathChannel } from '../mathChannels/types';
7
- import type { SegmentContext } from '../../engine/types';
8
7
  import { type CycleDefinition } from '../cycles/evaluator';
9
8
  type ExportedWorksheet = {
10
9
  name: string;
@@ -35,8 +34,6 @@ export interface WorkbookBody {
35
34
  liveWindowSeconds: number | null;
36
35
  /** Lap / cycle split, without the dataset it came from. */
37
36
  laps: BeaconConfig | null;
38
- /** The Segments panel's ids (Historian phase 5); absent in older bodies. */
39
- segments?: SegmentContext | null;
40
37
  /** Cycle and phase rules (lib/cycles); absent in older bodies. */
41
38
  cycles?: CycleDefinition[];
42
39
  }
@@ -82,8 +79,6 @@ export interface ParsedWorkbook extends ImportResult {
82
79
  mathChannels: WorkbookChannel[];
83
80
  liveWindowSeconds: number | null | undefined;
84
81
  laps: BeaconConfig | null | undefined;
85
- /** Undefined: a body from before segments (keep the current context). */
86
- segments: SegmentContext | null | undefined;
87
82
  /** Cycle and phase rules; [] in bodies without them. */
88
83
  cycles: CycleDefinition[];
89
84
  }
@@ -112,7 +107,6 @@ export declare function buildWorkbookBody(s: {
112
107
  }>;
113
108
  liveWindowSeconds: number | null;
114
109
  laps: BeaconConfig | null;
115
- segments?: SegmentContext | null;
116
110
  cycles?: CycleDefinition[];
117
111
  }): WorkbookBody;
118
112
  export declare function buildWorkspaceExportBlob(worksheets: Worksheet[]): Blob;
@@ -27,7 +27,7 @@ export declare function formatTick(v: number, step: number): string;
27
27
  */
28
28
  export declare function formatValue(v: number): string;
29
29
  /** X reads as clock time: a seconds axis ("Name (s)") whose both ends are Unix times of 2000–2100 (collector streams
30
- * and Historian ranges carry Unix seconds in ElapsedTime). */
30
+ * and recordings carry Unix seconds in ElapsedTime). */
31
31
  export declare function isClockAxis(xLabel: string, lo: number, hi: number): boolean;
32
32
  export declare function setClockTimeZone(tz: string | undefined): void;
33
33
  export declare const getClockTimeZone: () => string | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kymoscope/sdk",
3
- "version": "0.12.0",
3
+ "version": "0.14.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",