@alert-whatif/ui 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/index.d.ts +244 -0
- package/dist/index.js +5233 -0
- package/dist/index.js.map +1 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 The Alertcraft Authors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { Sample, MetricSeries, AlertConfig, GrafanaAlertState, Result, GrafanaRuleObservation, RuleSummary, Threshold, Duration, NoDataState, ExecErrState, ReducerKind, NanMode, Tick, EvalEvent } from '@alert-whatif/core';
|
|
3
|
+
export { GrafanaAlertState, GrafanaRuleObservation, RuleSummary } from '@alert-whatif/core';
|
|
4
|
+
import { ReactNode } from 'react';
|
|
5
|
+
|
|
6
|
+
type RuleMetadata = {
|
|
7
|
+
readonly title: string;
|
|
8
|
+
readonly labels: Readonly<Record<string, string>>;
|
|
9
|
+
readonly paused: boolean;
|
|
10
|
+
readonly query: {
|
|
11
|
+
readonly expr: string;
|
|
12
|
+
readonly mode: 'range' | 'instant';
|
|
13
|
+
};
|
|
14
|
+
readonly updatedMs?: number;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type WhatIfDataSourceCapabilities = {
|
|
18
|
+
readonly fixtures: boolean;
|
|
19
|
+
readonly live: boolean;
|
|
20
|
+
readonly fetchRuleByUid: boolean;
|
|
21
|
+
readonly fetchRuleList: boolean;
|
|
22
|
+
readonly grafanaStateOracle: boolean;
|
|
23
|
+
readonly initialStateOracle: boolean;
|
|
24
|
+
readonly alertHistoryOracle: boolean;
|
|
25
|
+
readonly snapshot: boolean;
|
|
26
|
+
};
|
|
27
|
+
type SampleRequest = {
|
|
28
|
+
readonly datasourceUid: string;
|
|
29
|
+
readonly expr: string;
|
|
30
|
+
readonly startSec: number;
|
|
31
|
+
readonly endSec: number;
|
|
32
|
+
readonly stepSec: number;
|
|
33
|
+
};
|
|
34
|
+
type Dataset = {
|
|
35
|
+
readonly id: string;
|
|
36
|
+
readonly displayName: string;
|
|
37
|
+
readonly description: string;
|
|
38
|
+
readonly source: string;
|
|
39
|
+
readonly samples: ReadonlyArray<Sample>;
|
|
40
|
+
readonly seriesList?: ReadonlyArray<MetricSeries>;
|
|
41
|
+
readonly defaultAlertConfig: AlertConfig;
|
|
42
|
+
readonly rateInnerWindow?: number;
|
|
43
|
+
readonly evalGridOffsetMs?: number;
|
|
44
|
+
readonly endTimeMs?: number;
|
|
45
|
+
readonly startTimeMs?: number;
|
|
46
|
+
readonly drillFocalMs?: number;
|
|
47
|
+
readonly drillFocalSide?: 'leading' | 'trailing';
|
|
48
|
+
readonly grafanaHistory?: ReadonlyArray<{
|
|
49
|
+
readonly t: number;
|
|
50
|
+
readonly state: GrafanaAlertState;
|
|
51
|
+
}>;
|
|
52
|
+
readonly ruleMetadata?: RuleMetadata;
|
|
53
|
+
};
|
|
54
|
+
interface WhatIfDataSource {
|
|
55
|
+
readonly capabilities: WhatIfDataSourceCapabilities;
|
|
56
|
+
fetchSamples(req: SampleRequest): Promise<Result<ReadonlyArray<MetricSeries>, string>>;
|
|
57
|
+
fetchRuleState?(ruleTitle: string): Promise<GrafanaRuleObservation>;
|
|
58
|
+
listFixtures?(): ReadonlyArray<Dataset>;
|
|
59
|
+
fetchRuleByUid?(uid: string): Promise<unknown | null>;
|
|
60
|
+
listRules?(): Promise<Result<ReadonlyArray<RuleSummary>, string>>;
|
|
61
|
+
fetchInitialAlertState?(ruleTitle: string, atTimeMs: number): Promise<Result<'Normal' | 'Firing' | 'NoData', string>>;
|
|
62
|
+
fetchAlertHistory?(ruleTitle: string, fromMs: number, toMs: number): Promise<Result<ReadonlyArray<{
|
|
63
|
+
readonly t: number;
|
|
64
|
+
readonly state: GrafanaAlertState;
|
|
65
|
+
}>, string>>;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
type ConfigOverrides = {
|
|
69
|
+
readonly threshold?: Threshold;
|
|
70
|
+
readonly forDuration?: Duration;
|
|
71
|
+
readonly keepFiringFor?: Duration;
|
|
72
|
+
readonly evaluationInterval?: Duration;
|
|
73
|
+
readonly intervalMs?: Duration;
|
|
74
|
+
readonly maxDataPoints?: number;
|
|
75
|
+
readonly noDataState?: NoDataState;
|
|
76
|
+
readonly execErrState?: ExecErrState;
|
|
77
|
+
readonly windowDuration?: Duration;
|
|
78
|
+
readonly reducer?: ReducerKind;
|
|
79
|
+
readonly nanMode?: NanMode;
|
|
80
|
+
};
|
|
81
|
+
type WhatIfPreset = {
|
|
82
|
+
readonly datasetId?: string;
|
|
83
|
+
readonly overrides?: ConfigOverrides;
|
|
84
|
+
readonly tick?: number;
|
|
85
|
+
};
|
|
86
|
+
type LiveContext = {
|
|
87
|
+
readonly datasourceUid: string;
|
|
88
|
+
readonly query: string;
|
|
89
|
+
readonly ruleTitle: string;
|
|
90
|
+
readonly defaultConfig: AlertConfig;
|
|
91
|
+
readonly ruleMetadata?: RuleMetadata;
|
|
92
|
+
readonly rateInnerWindow?: number;
|
|
93
|
+
readonly footerSlot?: ReactNode;
|
|
94
|
+
};
|
|
95
|
+
type Props$5 = {
|
|
96
|
+
readonly adapter: WhatIfDataSource;
|
|
97
|
+
readonly themeToggleSlot?: ReactNode;
|
|
98
|
+
readonly liveContext?: LiveContext;
|
|
99
|
+
readonly initialRuleUid?: string;
|
|
100
|
+
readonly initialPreset?: WhatIfPreset;
|
|
101
|
+
readonly initialLookbackSec?: number;
|
|
102
|
+
readonly initialDrill?: 'first' | 'last';
|
|
103
|
+
readonly initialPlay?: boolean;
|
|
104
|
+
readonly titleLogo?: ReactNode;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
declare function WhatIfPage({ adapter, themeToggleSlot, liveContext, initialRuleUid, initialPreset, initialLookbackSec, initialDrill, initialPlay, titleLogo, }: Props$5): react_jsx_runtime.JSX.Element;
|
|
108
|
+
|
|
109
|
+
type CrossingDirection = 'ignition' | 'resolution';
|
|
110
|
+
type ThresholdCrossing = {
|
|
111
|
+
readonly t: number;
|
|
112
|
+
readonly v: number;
|
|
113
|
+
readonly direction: CrossingDirection;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
type Props$4 = {
|
|
117
|
+
readonly samples: ReadonlyArray<Sample>;
|
|
118
|
+
readonly visibleSamples?: ReadonlyArray<Sample>;
|
|
119
|
+
readonly ticks?: ReadonlyArray<Tick>;
|
|
120
|
+
readonly rightAnchorT?: number | undefined;
|
|
121
|
+
readonly yMax?: number | undefined;
|
|
122
|
+
readonly threshold: Threshold;
|
|
123
|
+
readonly evaluationInterval: number;
|
|
124
|
+
readonly windowDuration: number;
|
|
125
|
+
readonly crossings?: ReadonlyArray<ThresholdCrossing>;
|
|
126
|
+
readonly reducer?: ReducerKind;
|
|
127
|
+
readonly events?: ReadonlyArray<EvalEvent>;
|
|
128
|
+
readonly baselineEvents?: ReadonlyArray<EvalEvent>;
|
|
129
|
+
readonly subtitle?: string;
|
|
130
|
+
readonly currentState?: EvalEvent['kind'] | 'Normal';
|
|
131
|
+
readonly initialState?: 'Normal' | 'Firing' | 'NoData';
|
|
132
|
+
readonly displayEndT?: number;
|
|
133
|
+
readonly displayStartT?: number;
|
|
134
|
+
readonly focalMs?: number;
|
|
135
|
+
readonly pollSignal?: number;
|
|
136
|
+
readonly grafanaHistory?: ReadonlyArray<{
|
|
137
|
+
readonly t: number;
|
|
138
|
+
readonly state: string;
|
|
139
|
+
}> | undefined;
|
|
140
|
+
readonly grafanaHistoryEnd?: number | undefined;
|
|
141
|
+
readonly bottomSlot?: ReactNode;
|
|
142
|
+
};
|
|
143
|
+
declare function MetricChart({ samples, visibleSamples, ticks, threshold, evaluationInterval, windowDuration, crossings: crossingsOverride, reducer, events, subtitle, rightAnchorT, yMax, bottomSlot, currentState, grafanaHistory, grafanaHistoryEnd, baselineEvents, initialState, displayEndT, displayStartT, focalMs, pollSignal, }: Props$4): react_jsx_runtime.JSX.Element;
|
|
144
|
+
|
|
145
|
+
type Props$3 = {
|
|
146
|
+
readonly config: AlertConfig;
|
|
147
|
+
readonly onChange: (next: AlertConfig) => void;
|
|
148
|
+
readonly onApply: () => void;
|
|
149
|
+
readonly onReset: () => void;
|
|
150
|
+
readonly ruleMetadata?: RuleMetadata | undefined;
|
|
151
|
+
readonly paused?: boolean | undefined;
|
|
152
|
+
readonly onPausedChange?: ((paused: boolean) => void) | undefined;
|
|
153
|
+
readonly changedLabels?: ReadonlySet<string> | undefined;
|
|
154
|
+
};
|
|
155
|
+
declare function ParamControls({ config, onChange, onApply, onReset, ruleMetadata, paused, onPausedChange, changedLabels, }: Props$3): react_jsx_runtime.JSX.Element;
|
|
156
|
+
|
|
157
|
+
type OurState = 'Normal' | 'Pending' | 'Firing' | 'NoData' | 'Recovering';
|
|
158
|
+
|
|
159
|
+
type CommonProps = {
|
|
160
|
+
readonly ourState: OurState;
|
|
161
|
+
readonly query?: string;
|
|
162
|
+
readonly pillExtra?: ReactNode;
|
|
163
|
+
};
|
|
164
|
+
type LiveProps = CommonProps & {
|
|
165
|
+
readonly mode: 'live';
|
|
166
|
+
readonly grafanaState?: GrafanaAlertState;
|
|
167
|
+
readonly lastPollAt: number | null;
|
|
168
|
+
readonly intervalSec: number;
|
|
169
|
+
readonly error: string | null;
|
|
170
|
+
readonly onSnapshot?: () => void;
|
|
171
|
+
readonly canSnapshot?: boolean;
|
|
172
|
+
readonly onExport?: () => void;
|
|
173
|
+
readonly canExport?: boolean;
|
|
174
|
+
readonly onImport?: (file: File) => void;
|
|
175
|
+
readonly exportToast?: string | null;
|
|
176
|
+
readonly footerSlot?: ReactNode;
|
|
177
|
+
};
|
|
178
|
+
type MockProps = CommonProps & {
|
|
179
|
+
readonly mode: 'mock';
|
|
180
|
+
readonly replayButtons: ReactNode;
|
|
181
|
+
readonly tickIndex: number;
|
|
182
|
+
readonly tickCount: number;
|
|
183
|
+
readonly grafanaState?: GrafanaAlertState;
|
|
184
|
+
readonly onExport?: () => void;
|
|
185
|
+
readonly onImport?: (file: File) => void;
|
|
186
|
+
};
|
|
187
|
+
type Props$2 = LiveProps | MockProps;
|
|
188
|
+
declare function LiveStatusStrip(props: Props$2): react_jsx_runtime.JSX.Element;
|
|
189
|
+
|
|
190
|
+
type Props$1 = {
|
|
191
|
+
readonly rules: ReadonlyArray<RuleSummary>;
|
|
192
|
+
readonly selectedUid: string | null;
|
|
193
|
+
readonly onSelect: (uid: string) => void;
|
|
194
|
+
readonly loading: boolean;
|
|
195
|
+
readonly error: string | null;
|
|
196
|
+
readonly onRefresh?: () => void;
|
|
197
|
+
};
|
|
198
|
+
declare function RulePicker({ rules, selectedUid, onSelect, loading, error, onRefresh, }: Props$1): react_jsx_runtime.JSX.Element;
|
|
199
|
+
|
|
200
|
+
type Theme = 'dark' | 'light';
|
|
201
|
+
declare function useTheme(): readonly [Theme, (next: Theme) => void];
|
|
202
|
+
|
|
203
|
+
type Props = {
|
|
204
|
+
readonly theme: Theme;
|
|
205
|
+
readonly onChange: (next: Theme) => void;
|
|
206
|
+
};
|
|
207
|
+
declare function ThemeToggle({ theme, onChange }: Props): react_jsx_runtime.JSX.Element;
|
|
208
|
+
|
|
209
|
+
type LiveModeOptions = {
|
|
210
|
+
readonly active: boolean;
|
|
211
|
+
readonly datasourceUid: string;
|
|
212
|
+
readonly query: string;
|
|
213
|
+
readonly ruleTitle: string;
|
|
214
|
+
readonly intervalSec: number;
|
|
215
|
+
readonly lookbackSec: number;
|
|
216
|
+
readonly stepSec: number;
|
|
217
|
+
readonly evaluationIntervalMs: number;
|
|
218
|
+
};
|
|
219
|
+
type LiveModeState = {
|
|
220
|
+
readonly samples: ReadonlyArray<Sample>;
|
|
221
|
+
readonly grafanaState: GrafanaAlertState;
|
|
222
|
+
readonly lastPollAt: number | null;
|
|
223
|
+
readonly grafanaLastEvalMs: number | null;
|
|
224
|
+
readonly grafanaLatestEvalMs: number | null;
|
|
225
|
+
readonly error: string | null;
|
|
226
|
+
};
|
|
227
|
+
declare function useLiveMode(opts: LiveModeOptions, adapter: WhatIfDataSource): LiveModeState;
|
|
228
|
+
|
|
229
|
+
declare function describeFetchError(err: unknown): string;
|
|
230
|
+
|
|
231
|
+
type PromQueryRangeResponse = {
|
|
232
|
+
readonly status: 'success' | 'error';
|
|
233
|
+
readonly error?: string;
|
|
234
|
+
readonly errorType?: string;
|
|
235
|
+
readonly data?: {
|
|
236
|
+
readonly resultType: 'matrix';
|
|
237
|
+
readonly result: ReadonlyArray<{
|
|
238
|
+
readonly metric: Readonly<Record<string, string>>;
|
|
239
|
+
readonly values: ReadonlyArray<readonly [number, string]>;
|
|
240
|
+
}>;
|
|
241
|
+
};
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
export { type ConfigOverrides, type Dataset, LiveStatusStrip, MetricChart, ParamControls, type PromQueryRangeResponse, type RuleMetadata, RulePicker, type Theme, ThemeToggle, type WhatIfDataSource, WhatIfPage, type WhatIfPreset, describeFetchError, useLiveMode, useTheme };
|