@kymoscope/sdk 0.12.0 → 0.13.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.
@@ -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
  /**
@@ -335,8 +327,6 @@ export declare function createEngine(options?: EngineOptions): {
335
327
  /** Live window of a worksheet's charts (default: active; seconds, null = all). Each worksheet has its own, shared
336
328
  * by its charts; a worksheet that never set one follows the workbook's. */
337
329
  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
330
  };
341
331
  mathChannels: {
342
332
  /** Create a channel (`name` and `formula` at least). Returns it. */
@@ -387,7 +377,7 @@ export declare function createEngine(options?: EngineOptions): {
387
377
  startedAt: number;
388
378
  droppedSamples: number;
389
379
  } | null;
390
- /** Live against a reference (Historian phase 5): the definition's rule, the axis column and deltas on a connection. */
380
+ /** Live segment axis: a cycle rule's axis column on a connection (cycle-only, no live reference). */
391
381
  setSegmentAxis(id: string, cfg: LiveSegmentAxis | null): void;
392
382
  /** Samples currently buffered for a connection (cheap; poll it for counters). */
393
383
  rowCount(id: string): number;
@@ -182,12 +182,6 @@ export interface LiveConnectionInfo {
182
182
  /** Its columns as of the last structural change (the time column first). */
183
183
  channels: string[];
184
184
  }
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
185
  export interface EngineState {
192
186
  datasets: DatasetInfo[];
193
187
  /** Plotted ids: dataset ids, lap ids and live connection ids. */
@@ -198,8 +192,6 @@ export interface EngineState {
198
192
  live: LiveConnectionInfo[];
199
193
  /** Scrolling window for live charts on a time X axis (seconds; null = all): the active worksheet's. */
200
194
  liveWindowSeconds: number | null;
201
- /** The Segments panel's history, definition and reference, or null. */
202
- segmentContext: SegmentContext | null;
203
195
  /** Cycle and phase rules (engine.cycles), saved with the workbook. */
204
196
  cycleRules: CycleDefinition[];
205
197
  limits: KymoscopeLimits;
@@ -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';
@@ -120,9 +120,6 @@ export declare function deviceFingerprint(publicKey: string): Promise<string>;
120
120
  export declare const WORKBOOK_EXPORT_AAD = "kymoscope-workbook-export-v2";
121
121
  export declare const workbookBodyAad: (workbookId: string, version: number) => string;
122
122
  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
123
  /** A project's config key (alert rules) sealed under the project key: resource_keys 'project_config', id = the project. */
127
124
  export declare const projectConfigKeyAad: (projectId: string, epoch: number) => string;
128
125
  /** An alert rule's kyr/1 body sealed under its project's config key: bound to the rule, its version and project. */
@@ -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,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.13.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",
@@ -1,51 +0,0 @@
1
- /**
2
- * Historian ranges as a DataSource (plan P5): a list of pieces, each one block's times with Float32 values per channel
3
- * (raw: lo and hi are the same arrays; a rollup: the bucket's min and max at its middle). The time column is
4
- * `ElapsedTime` in Unix seconds, the same X as a collector's live stream. Decimation reads each piece on its own times,
5
- * so tag groups never share a padded table. Everything is pure computation (sync), like the in-memory sources.
6
- */
7
- import type { ColumnSchema, DataSource, DecimatedSeries, MultiSeriesResult, SeriesQuery, Viewport } from './dataSource';
8
- import type { DatasetRow } from '../parseDataset';
9
- import type { HistoryLevel } from '../historian/khd1';
10
- export interface HistoryPiece {
11
- /** Unix seconds, ascending. */
12
- t: Float64Array;
13
- /** Per channel: the value (raw) or the bucket minimum (rollup). NaN: no value at that time. */
14
- lo: Map<string, Float32Array>;
15
- /** Per channel: the bucket maximum (rollup); the very same Map as `lo` for raw data. */
16
- hi: Map<string, Float32Array>;
17
- level: HistoryLevel;
18
- }
19
- /** First index with t[i] >= x, or with t[i] > x when `after`. */
20
- export declare function bound(t: Float64Array, x: number, after?: boolean): number;
21
- /** Rows [i, j) of a piece (views, nothing copied); null when empty. */
22
- export declare function slicePiece(p: HistoryPiece, i: number, j: number): HistoryPiece | null;
23
- /** The rows of `p` with t in [t0, t1]. */
24
- export declare const clipPiece: (p: HistoryPiece, t0: number, t1: number) => HistoryPiece | null;
25
- /** The overview outside [a, b] with the detail inside: the pan/zoom view (plan P6). */
26
- export declare function splicePieces(overview: HistoryPiece[], detail: HistoryPiece[], a: number, b: number): HistoryPiece[];
27
- export declare class HistoryDataSource implements DataSource {
28
- #private;
29
- readonly pieces: readonly HistoryPiece[];
30
- constructor(pieces: HistoryPiece[], units?: Record<string, string>);
31
- schemaSync(): ColumnSchema[];
32
- getSchema(): Promise<ColumnSchema[]>;
33
- /** Rows are the pieces' rows in time order (a rollup: its minimum); NaN where a piece lacks the channel. */
34
- readColumns(columns: string[], offset: number, limit: number): Promise<Record<string, Float64Array>>;
35
- getSeriesMultiSync(columns: string[], viewport: Viewport, maxPoints: number): MultiSeriesResult;
36
- getSeriesMulti(columns: string[], viewport: Viewport, maxPoints: number): Promise<MultiSeriesResult>;
37
- getSeries(q: SeriesQuery): Promise<DecimatedSeries>;
38
- xBoundsSync(column: string): {
39
- x0: number;
40
- x1: number;
41
- };
42
- xBounds(column: string): Promise<{
43
- x0: number;
44
- x1: number;
45
- }>;
46
- /** At most `maxRows` rows in time order for the row-based charts and math channels: one stride over all pieces' rows
47
- * end to end (pieces smaller than the stride may be skipped); a row holds its piece's channels only (a rollup: the
48
- * bucket minimum). ponytail: no cross-group alignment in the sample. */
49
- sampleRowsSync(maxRows: number): DatasetRow[];
50
- dispose(): Promise<void>;
51
- }
@@ -1,32 +0,0 @@
1
- /**
2
- * History bytes cached in the origin-private file system (spec D2; plan P4): "<segmentId>/footer" and
3
- * "<segmentId>/<block>". It keeps the bytes as stored (sealed): the device holds ciphertext only, and a segment id
4
- * never changes content (a new version is a new segment), so nothing is invalidated. Past the budget (min(2 GiB,
5
- * 20 % of the origin's quota)) the oldest-written files go, down to 90 %. Without OPFS (old browsers, some private
6
- * windows) every call is a no-op. ponytail: eviction by write time (FIFO); track reads (LRU) if old ranges miss too often.
7
- * ponytail: each tab keeps its own index and total, so several tabs writing at once can overshoot the budget until one
8
- * of them rescans (next page load); share the index through a BroadcastChannel or a Web Lock if that ever matters.
9
- */
10
- export interface BlockCache {
11
- get(key: string): Promise<Uint8Array | null>;
12
- put(key: string, bytes: Uint8Array): Promise<void>;
13
- }
14
- /** The part of FileSystemDirectoryHandle the cache uses (a fake in tests). */
15
- export interface CacheDir {
16
- getFileHandle(name: string, o?: {
17
- create?: boolean;
18
- }): Promise<{
19
- getFile(): Promise<File>;
20
- createWritable(): Promise<{
21
- write(b: BufferSource): Promise<void>;
22
- close(): Promise<void>;
23
- abort?(): Promise<void>;
24
- }>;
25
- }>;
26
- removeEntry(name: string): Promise<void>;
27
- entries(): AsyncIterable<[string, {
28
- kind: string;
29
- getFile?: () => Promise<File>;
30
- }]>;
31
- }
32
- export declare function blockCache(root?: () => Promise<CacheDir | null>, budget?: () => Promise<number>): BlockCache;
@@ -1,31 +0,0 @@
1
- import type { ExportPart } from '../recordings/export';
2
- import { type HistoryPiece } from '../data/historyDataSource';
3
- import { type HistoryReadOptions, type HistorySegmentRef } from './reader';
4
- export type HistoryExportFormat = 'csv' | 'mf4' | 'parquet';
5
- /** ponytail: wide tables over unaligned tag groups grow as times x channels (float32 cells); Parquet (long) has no such limit. */
6
- export declare const MAX_WIDE_CELLS = 25000000;
7
- /** ponytail: the Parquet file is built in DuckDB-WASM's memory (~4 GB address space); stream row groups out if larger
8
- * exports are needed. */
9
- export declare const MAX_PARQUET_VALUES = 30000000;
10
- /** The shortest decimal that reads back as the same float32 (0.1, not 0.10000000149011612). */
11
- export declare function f32text(v: number): string;
12
- /** ISO 8601 UTC with microseconds. */
13
- export declare function isoMicros(t: number): string;
14
- /** One row per distinct time across `channels`, NaN where a channel has none. */
15
- export declare function wideDay(pieces: HistoryPiece[], channels: string[]): {
16
- t: Float64Array;
17
- cols: Float32Array[];
18
- };
19
- export declare function exportHistoryTo(o: Omit<HistoryReadOptions, 'level'>, format: HistoryExportFormat, write: (part: ExportPart) => void | Promise<void>, opts?: {
20
- onProgress?: (fraction: number) => void;
21
- }): Promise<{
22
- skippedDays: string[];
23
- missingDays: string[];
24
- }>;
25
- /** Days of raw values into one Parquet file: appended to DuckDB `chunk` values at a time, at most `max` values. */
26
- export declare function parquetTo(raw: HistorySegmentRef[], day: (s: HistorySegmentRef) => Promise<{
27
- pieces: HistoryPiece[];
28
- }>, channels: string[], write: (part: ExportPart) => void | Promise<void>, step: (i: number) => void, limits?: {
29
- max: number;
30
- chunk: number;
31
- }): Promise<void>;
@@ -1,41 +0,0 @@
1
- export declare const KHD1_TRAILER_BYTES = 9;
2
- export type HistoryKind = 'raw' | 'rollup';
3
- export type HistoryLevel = 0 | 60 | 3600;
4
- export interface KhdChannel {
5
- n: string;
6
- u: string;
7
- }
8
- export interface KhdBlock {
9
- ch: number[];
10
- t0: number;
11
- t1: number;
12
- off: number;
13
- len: number;
14
- rows: number;
15
- values: number;
16
- }
17
- export interface KhdFooter {
18
- format: 1;
19
- stream: string;
20
- day: string;
21
- tz: string;
22
- kind: HistoryKind;
23
- level: HistoryLevel;
24
- t0: number;
25
- t1: number;
26
- channels: KhdChannel[];
27
- blocks: KhdBlock[];
28
- }
29
- /** Which file of a history: what the AAD of its blocks and footer binds. */
30
- export interface KhdFileId {
31
- stream: string;
32
- day: string;
33
- kind: HistoryKind;
34
- level: HistoryLevel;
35
- }
36
- export declare const blockAad: (f: KhdFileId, index: number | "footer") => string;
37
- /** The sealed footer's length, from bytes that end where the file ends (at least the 9-byte trailer). */
38
- export declare function footerLength(tail: Uint8Array): number;
39
- /** One sealed block (or the footer) opened; WebCrypto throws on a wrong key, file or index. */
40
- export declare function openSealed(key: CryptoKey, sealed: Uint8Array, f: KhdFileId, index: number | 'footer'): Promise<Uint8Array>;
41
- export declare function openFooter(key: CryptoKey, sealed: Uint8Array, f: KhdFileId): Promise<KhdFooter>;
@@ -1,21 +0,0 @@
1
- export interface RawBlock {
2
- t: Float64Array;
3
- cols: Float32Array[];
4
- }
5
- export interface RollupBlock {
6
- t: Float64Array;
7
- ch: Int32Array;
8
- min: Float32Array;
9
- max: Float32Array;
10
- }
11
- /** Loads DuckDB-WASM ahead of the first read (the History dialog calls it while the user picks). */
12
- /** Loads DuckDB and runs one tiny Parquet round trip, so the first real decode doesn't pay the first-query cost
13
- * (0.3-0.7 s measured, historian-notes/phase4.md). Call it while the user picks channels. */
14
- export declare function warmHistoryDecoder(): void;
15
- /** A raw block's times (Unix seconds) and the columns of `channels` (footer indexes; NaN = no value). */
16
- export declare function decodeRawBlock(bytes: Uint8Array, channels: number[]): Promise<RawBlock>;
17
- /** Rollup blocks' rows of their `channels`, one result per block, sorted by (ch, t): one query for the whole batch. */
18
- export declare function decodeRollupBlocks(blocks: Array<{
19
- bytes: Uint8Array;
20
- channels: number[];
21
- }>): Promise<RollupBlock[]>;