stelo 1.0.1

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 (141) hide show
  1. package/LICENSE +184 -0
  2. package/README.md +853 -0
  3. package/dist/accessibility.d.ts +227 -0
  4. package/dist/accessibility.d.ts.map +1 -0
  5. package/dist/accessibility.js +602 -0
  6. package/dist/accessibility.js.map +1 -0
  7. package/dist/agent.d.ts +870 -0
  8. package/dist/agent.d.ts.map +1 -0
  9. package/dist/agent.js +1107 -0
  10. package/dist/agent.js.map +1 -0
  11. package/dist/audio-stream.d.ts +114 -0
  12. package/dist/audio-stream.d.ts.map +1 -0
  13. package/dist/audio-stream.js +167 -0
  14. package/dist/audio-stream.js.map +1 -0
  15. package/dist/clipboard.d.ts +99 -0
  16. package/dist/clipboard.d.ts.map +1 -0
  17. package/dist/clipboard.js +352 -0
  18. package/dist/clipboard.js.map +1 -0
  19. package/dist/config.d.ts +183 -0
  20. package/dist/config.d.ts.map +1 -0
  21. package/dist/config.js +477 -0
  22. package/dist/config.js.map +1 -0
  23. package/dist/context.d.ts +213 -0
  24. package/dist/context.d.ts.map +1 -0
  25. package/dist/context.js +387 -0
  26. package/dist/context.js.map +1 -0
  27. package/dist/cortex.d.ts +548 -0
  28. package/dist/cortex.d.ts.map +1 -0
  29. package/dist/cortex.js +1479 -0
  30. package/dist/cortex.js.map +1 -0
  31. package/dist/errors.d.ts +133 -0
  32. package/dist/errors.d.ts.map +1 -0
  33. package/dist/errors.js +278 -0
  34. package/dist/errors.js.map +1 -0
  35. package/dist/events.d.ts +227 -0
  36. package/dist/events.d.ts.map +1 -0
  37. package/dist/events.js +429 -0
  38. package/dist/events.js.map +1 -0
  39. package/dist/executor.d.ts +212 -0
  40. package/dist/executor.d.ts.map +1 -0
  41. package/dist/executor.js +545 -0
  42. package/dist/executor.js.map +1 -0
  43. package/dist/index.d.ts +69 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +167 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/integration.d.ts +159 -0
  48. package/dist/integration.d.ts.map +1 -0
  49. package/dist/integration.js +533 -0
  50. package/dist/integration.js.map +1 -0
  51. package/dist/keyboard.d.ts +276 -0
  52. package/dist/keyboard.d.ts.map +1 -0
  53. package/dist/keyboard.js +404 -0
  54. package/dist/keyboard.js.map +1 -0
  55. package/dist/logger.d.ts +198 -0
  56. package/dist/logger.d.ts.map +1 -0
  57. package/dist/logger.js +516 -0
  58. package/dist/logger.js.map +1 -0
  59. package/dist/middleware.d.ts +183 -0
  60. package/dist/middleware.d.ts.map +1 -0
  61. package/dist/middleware.js +493 -0
  62. package/dist/middleware.js.map +1 -0
  63. package/dist/monitor.d.ts +136 -0
  64. package/dist/monitor.d.ts.map +1 -0
  65. package/dist/monitor.js +341 -0
  66. package/dist/monitor.js.map +1 -0
  67. package/dist/mouse.d.ts +290 -0
  68. package/dist/mouse.d.ts.map +1 -0
  69. package/dist/mouse.js +466 -0
  70. package/dist/mouse.js.map +1 -0
  71. package/dist/plugin.d.ts +157 -0
  72. package/dist/plugin.d.ts.map +1 -0
  73. package/dist/plugin.js +409 -0
  74. package/dist/plugin.js.map +1 -0
  75. package/dist/process.d.ts +106 -0
  76. package/dist/process.d.ts.map +1 -0
  77. package/dist/process.js +326 -0
  78. package/dist/process.js.map +1 -0
  79. package/dist/recorder.d.ts +100 -0
  80. package/dist/recorder.d.ts.map +1 -0
  81. package/dist/recorder.js +258 -0
  82. package/dist/recorder.js.map +1 -0
  83. package/dist/safety.d.ts +59 -0
  84. package/dist/safety.d.ts.map +1 -0
  85. package/dist/safety.js +98 -0
  86. package/dist/safety.js.map +1 -0
  87. package/dist/scheduler.d.ts +152 -0
  88. package/dist/scheduler.d.ts.map +1 -0
  89. package/dist/scheduler.js +615 -0
  90. package/dist/scheduler.js.map +1 -0
  91. package/dist/screen.d.ts +96 -0
  92. package/dist/screen.d.ts.map +1 -0
  93. package/dist/screen.js +154 -0
  94. package/dist/screen.js.map +1 -0
  95. package/dist/session.d.ts +209 -0
  96. package/dist/session.d.ts.map +1 -0
  97. package/dist/session.js +479 -0
  98. package/dist/session.js.map +1 -0
  99. package/dist/stream.d.ts +168 -0
  100. package/dist/stream.d.ts.map +1 -0
  101. package/dist/stream.js +298 -0
  102. package/dist/stream.js.map +1 -0
  103. package/dist/telemetry.d.ts +223 -0
  104. package/dist/telemetry.d.ts.map +1 -0
  105. package/dist/telemetry.js +433 -0
  106. package/dist/telemetry.js.map +1 -0
  107. package/dist/types.d.ts +165 -0
  108. package/dist/types.d.ts.map +1 -0
  109. package/dist/types.js +8 -0
  110. package/dist/types.js.map +1 -0
  111. package/dist/utils/bezier.d.ts +51 -0
  112. package/dist/utils/bezier.d.ts.map +1 -0
  113. package/dist/utils/bezier.js +117 -0
  114. package/dist/utils/bezier.js.map +1 -0
  115. package/dist/utils/helpers.d.ts +90 -0
  116. package/dist/utils/helpers.d.ts.map +1 -0
  117. package/dist/utils/helpers.js +143 -0
  118. package/dist/utils/helpers.js.map +1 -0
  119. package/dist/utils/index.d.ts +4 -0
  120. package/dist/utils/index.d.ts.map +1 -0
  121. package/dist/utils/index.js +18 -0
  122. package/dist/utils/index.js.map +1 -0
  123. package/dist/validation.d.ts +254 -0
  124. package/dist/validation.d.ts.map +1 -0
  125. package/dist/validation.js +478 -0
  126. package/dist/validation.js.map +1 -0
  127. package/dist/vision.d.ts +719 -0
  128. package/dist/vision.d.ts.map +1 -0
  129. package/dist/vision.js +1197 -0
  130. package/dist/vision.js.map +1 -0
  131. package/dist/window.d.ts +80 -0
  132. package/dist/window.d.ts.map +1 -0
  133. package/dist/window.js +170 -0
  134. package/dist/window.js.map +1 -0
  135. package/dist/workflow.d.ts +224 -0
  136. package/dist/workflow.d.ts.map +1 -0
  137. package/dist/workflow.js +578 -0
  138. package/dist/workflow.js.map +1 -0
  139. package/index.d.ts +840 -0
  140. package/index.js +495 -0
  141. package/package.json +91 -0
package/dist/stream.js ADDED
@@ -0,0 +1,298 @@
1
+ "use strict";
2
+ // ============================================================================
3
+ // Stelo — Real-Time Screen Streaming API
4
+ // ============================================================================
5
+ // Ultra-low-latency continuous screen capture at up to 4K resolution.
6
+ //
7
+ // Designed for automation workloads, background tasks, and real-time vision pipelines
8
+ // that need a non-stop live feed of the screen while the user works.
9
+ //
10
+ // Features:
11
+ // - Continuous real-time capture at configurable FPS (up to 120fps)
12
+ // - 4K native resolution support
13
+ // - Background capture thread (never blocks Node.js event loop)
14
+ // - Double-buffered frames with zero-copy handoff
15
+ // - Per-frame metadata: cursor position, timestamp, sequence, FPS
16
+ // - Event-driven: onFrame callback, polling, or async iteration
17
+ // - Region capture & downscaling for bandwidth-constrained scenarios
18
+ //
19
+ // @example
20
+ // ```typescript
21
+ // import { stream } from 'stelo';
22
+ //
23
+ // // Start a 4K 60fps live stream
24
+ // stream.start({ fps: 60 });
25
+ //
26
+ // // Grab frames in a loop
27
+ // setInterval(() => {
28
+ // const frame = stream.latestFrame();
29
+ // if (frame) {
30
+ // model.processFrame(frame.data, frame.width, frame.height);
31
+ // }
32
+ // }, 16);
33
+ //
34
+ // // Or use the event-driven API
35
+ // stream.onFrame((frame) => {
36
+ // console.log(`Frame #${frame.sequence} ${frame.width}x${frame.height} @ ${frame.measuredFps}fps`);
37
+ // });
38
+ //
39
+ // // Or async iteration
40
+ // for await (const frame of stream) {
41
+ // await processFrame(frame);
42
+ // }
43
+ //
44
+ // stream.stop();
45
+ // ```
46
+ // ============================================================================
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ exports.stream = void 0;
49
+ const native = require('../index.js');
50
+ // ── Stream API ──────────────────────────────────────────────────────────────
51
+ /**
52
+ * Real-time screen streaming engine.
53
+ *
54
+ * Provides continuous, non-blocking screen capture at up to 4K resolution
55
+ * and 120fps. The capture runs on a dedicated native thread, so it never
56
+ * blocks the Node.js event loop.
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * import { stream } from 'stelo';
61
+ *
62
+ * // Start 4K stream at 60fps
63
+ * stream.start({ fps: 60 });
64
+ *
65
+ * // Get latest frame for processing
66
+ * const frame = stream.latestFrame();
67
+ *
68
+ * // Get stream performance info
69
+ * const stats = stream.stats();
70
+ * console.log(`Running at ${stats.currentFps} fps`);
71
+ *
72
+ * // Subscribe to frames
73
+ * const unsub = stream.onFrame(frame => {
74
+ * // Process every frame
75
+ * });
76
+ *
77
+ * // Async iteration
78
+ * for await (const frame of stream) {
79
+ * await analyzeFrame(frame);
80
+ * }
81
+ *
82
+ * stream.stop();
83
+ * ```
84
+ */
85
+ exports.stream = {
86
+ // Internal state for frame polling
87
+ _frameHandlers: [],
88
+ _pollTimer: null,
89
+ _lastSequence: 0,
90
+ /**
91
+ * Start a continuous real-time screen stream.
92
+ *
93
+ * The stream runs on a dedicated native thread and captures frames
94
+ * continuously at the configured FPS. Frames are double-buffered,
95
+ * so reading never blocks capture.
96
+ *
97
+ * @param config - Stream configuration (fps, region, scale, buffer)
98
+ */
99
+ start(config) {
100
+ const nativeConfig = {};
101
+ if (config?.fps !== undefined)
102
+ nativeConfig.fps = config.fps;
103
+ if (config?.scale !== undefined)
104
+ nativeConfig.scale = config.scale;
105
+ if (config?.bufferSize !== undefined)
106
+ nativeConfig.bufferSize = config.bufferSize;
107
+ if (config?.region) {
108
+ nativeConfig.regionX = config.region.x;
109
+ nativeConfig.regionY = config.region.y;
110
+ nativeConfig.regionWidth = config.region.width;
111
+ nativeConfig.regionHeight = config.region.height;
112
+ }
113
+ native.streamStart(nativeConfig);
114
+ // Prime: wait briefly for the native capture thread to produce the first
115
+ // frame so `latestFrame()` calls immediately after `start()` are more
116
+ // likely to return a valid frame in tests and short-lived usage.
117
+ try {
118
+ // native.streamWaitForFrame blocks until a frame or timeout (ms)
119
+ native.streamWaitForFrame && native.streamWaitForFrame(500);
120
+ }
121
+ catch {
122
+ // Ignore any errors — stream will continue running and subsequent
123
+ // calls to latestFrame()/waitForFrame() will succeed.
124
+ }
125
+ // Start polling for frame handlers if any are registered
126
+ this._startPollingIfNeeded();
127
+ },
128
+ /**
129
+ * Stop the screen stream and release all resources.
130
+ */
131
+ stop() {
132
+ this._stopPolling();
133
+ this._lastSequence = 0;
134
+ native.streamStop();
135
+ },
136
+ /**
137
+ * Check if a stream is currently running.
138
+ */
139
+ isRunning() {
140
+ return native.streamIsRunning();
141
+ },
142
+ /**
143
+ * Get the latest captured frame.
144
+ * Returns null if no frames have been captured yet.
145
+ *
146
+ * This is the primary method for real-time automation — call it whenever
147
+ * you need the current screen state.
148
+ */
149
+ latestFrame() {
150
+ const frame = native.streamGetLatestFrame();
151
+ return frame ? toStreamFrame(frame) : null;
152
+ },
153
+ /**
154
+ * Get the most recent N frames from the ring buffer.
155
+ * Useful for temporal analysis (motion detection, change tracking).
156
+ *
157
+ * @param count - Number of recent frames to retrieve (default: 3)
158
+ */
159
+ recentFrames(count) {
160
+ const frames = native.streamGetRecentFrames(count ?? 3);
161
+ return frames.map(toStreamFrame);
162
+ },
163
+ /**
164
+ * Wait for the next new frame (blocks until available or timeout).
165
+ * Returns null if timeout is reached before a new frame arrives.
166
+ *
167
+ * @param timeoutMs - Maximum time to wait in ms (default: 1000)
168
+ */
169
+ waitForFrame(timeoutMs) {
170
+ const frame = native.streamWaitForFrame(timeoutMs ?? 1000);
171
+ return frame ? toStreamFrame(frame) : null;
172
+ },
173
+ /**
174
+ * Get stream performance statistics.
175
+ */
176
+ stats() {
177
+ const s = native.streamGetStats();
178
+ return {
179
+ isRunning: s.isRunning,
180
+ totalFrames: s.totalFrames,
181
+ droppedFrames: s.droppedFrames,
182
+ currentFps: s.currentFps,
183
+ targetFps: s.targetFps,
184
+ uptimeMs: s.uptimeMs,
185
+ };
186
+ },
187
+ /**
188
+ * Register a callback that fires for every new frame.
189
+ * Returns an unsubscribe function.
190
+ *
191
+ * @param handler - Function called with each new frame
192
+ * @returns Unsubscribe function
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * const unsub = stream.onFrame(frame => {
197
+ * console.log(`Frame ${frame.sequence}: ${frame.width}x${frame.height}`);
198
+ * });
199
+ *
200
+ * // Later: stop receiving frames
201
+ * unsub();
202
+ * ```
203
+ */
204
+ onFrame(handler) {
205
+ this._frameHandlers.push(handler);
206
+ this._startPollingIfNeeded();
207
+ return () => {
208
+ const idx = this._frameHandlers.indexOf(handler);
209
+ if (idx !== -1) {
210
+ this._frameHandlers.splice(idx, 1);
211
+ }
212
+ if (this._frameHandlers.length === 0) {
213
+ this._stopPolling();
214
+ }
215
+ };
216
+ },
217
+ /**
218
+ * Async iterator for frames. Yields new frames as they arrive.
219
+ *
220
+ * @example
221
+ * ```typescript
222
+ * stream.start({ fps: 30 });
223
+ * for await (const frame of stream) {
224
+ * const result = await model.analyze(frame.data);
225
+ * if (result.found) break;
226
+ * }
227
+ * stream.stop();
228
+ * ```
229
+ */
230
+ [Symbol.asyncIterator]() {
231
+ const self = this;
232
+ return {
233
+ async next() {
234
+ if (!self.isRunning()) {
235
+ return { done: true, value: undefined };
236
+ }
237
+ const frame = self.waitForFrame(5000);
238
+ if (!frame) {
239
+ return { done: true, value: undefined };
240
+ }
241
+ return { done: false, value: frame };
242
+ },
243
+ [Symbol.asyncIterator]() {
244
+ return this;
245
+ },
246
+ };
247
+ },
248
+ // ── Internal Polling ────────────────────────────────────────────────────
249
+ /** @internal */
250
+ _startPollingIfNeeded() {
251
+ if (this._pollTimer !== null)
252
+ return;
253
+ if (this._frameHandlers.length === 0)
254
+ return;
255
+ if (!this.isRunning())
256
+ return;
257
+ // Poll at 1ms intervals (native code handles actual FPS)
258
+ this._pollTimer = setInterval(() => {
259
+ if (!this.isRunning() || this._frameHandlers.length === 0) {
260
+ this._stopPolling();
261
+ return;
262
+ }
263
+ const frame = this.latestFrame();
264
+ if (frame && frame.sequence > this._lastSequence) {
265
+ this._lastSequence = frame.sequence;
266
+ for (const handler of this._frameHandlers) {
267
+ try {
268
+ handler(frame);
269
+ }
270
+ catch {
271
+ // Don't let handler errors kill the poll loop
272
+ }
273
+ }
274
+ }
275
+ }, 1);
276
+ },
277
+ /** @internal */
278
+ _stopPolling() {
279
+ if (this._pollTimer !== null) {
280
+ clearInterval(this._pollTimer);
281
+ this._pollTimer = null;
282
+ }
283
+ },
284
+ };
285
+ // ── Helpers ─────────────────────────────────────────────────────────────────
286
+ function toStreamFrame(raw) {
287
+ return {
288
+ data: raw.data,
289
+ width: raw.width,
290
+ height: raw.height,
291
+ sequence: raw.sequence,
292
+ timestampMs: raw.timestampMs,
293
+ measuredFps: raw.measuredFps,
294
+ cursorX: raw.cursorX,
295
+ cursorY: raw.cursorY,
296
+ };
297
+ }
298
+ //# sourceMappingURL=stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.js","sourceRoot":"","sources":["../ts/stream.ts"],"names":[],"mappings":";AAAA,+EAA+E;AAC/E,yCAAyC;AACzC,+EAA+E;AAC/E,sEAAsE;AACtE,EAAE;AACF,sFAAsF;AACtF,qEAAqE;AACrE,EAAE;AACF,YAAY;AACZ,sEAAsE;AACtE,mCAAmC;AACnC,kEAAkE;AAClE,oDAAoD;AACpD,oEAAoE;AACpE,kEAAkE;AAClE,uEAAuE;AACvE,EAAE;AACF,WAAW;AACX,gBAAgB;AAChB,kCAAkC;AAClC,EAAE;AACF,kCAAkC;AAClC,6BAA6B;AAC7B,EAAE;AACF,2BAA2B;AAC3B,sBAAsB;AACtB,wCAAwC;AACxC,iBAAiB;AACjB,iEAAiE;AACjE,MAAM;AACN,UAAU;AACV,EAAE;AACF,iCAAiC;AACjC,8BAA8B;AAC9B,sGAAsG;AACtG,MAAM;AACN,EAAE;AACF,wBAAwB;AACxB,sCAAsC;AACtC,+BAA+B;AAC/B,IAAI;AACJ,EAAE;AACF,iBAAiB;AACjB,MAAM;AACN,+EAA+E;;;AAI/E,MAAM,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AAuDtC,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACU,QAAA,MAAM,GAAG;IACpB,mCAA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+ /**
2
+ * Event severity levels for telemetry
3
+ */
4
+ export type TelemetrySeverity = 'debug' | 'info' | 'warn' | 'error' | 'critical';
5
+ /**
6
+ * Operation categories for structured logging
7
+ */
8
+ export type OperationCategory = 'mouse' | 'keyboard' | 'screen' | 'window' | 'safety' | 'stream' | 'system';
9
+ /**
10
+ * Telemetry event payload
11
+ */
12
+ export interface TelemetryEvent {
13
+ /** Unique event ID */
14
+ id: string;
15
+ /** ISO timestamp */
16
+ timestamp: string;
17
+ /** Event severity */
18
+ severity: TelemetrySeverity;
19
+ /** Operation category */
20
+ category: OperationCategory;
21
+ /** Operation name (e.g., 'mouse.click', 'keyboard.type') */
22
+ operation: string;
23
+ /** Duration in milliseconds (if applicable) */
24
+ durationMs?: number;
25
+ /** Success or failure */
26
+ success: boolean;
27
+ /** Error details (if failed) */
28
+ error?: {
29
+ code: string;
30
+ message: string;
31
+ recoverable: boolean;
32
+ };
33
+ /** Additional context */
34
+ metadata?: Record<string, unknown>;
35
+ }
36
+ /**
37
+ * Performance metrics snapshot
38
+ */
39
+ export interface PerformanceMetrics {
40
+ /** Total operations executed */
41
+ totalOperations: number;
42
+ /** Successful operations */
43
+ successCount: number;
44
+ /** Failed operations */
45
+ failureCount: number;
46
+ /** Average operation duration (ms) */
47
+ avgDurationMs: number;
48
+ /** P95 operation duration (ms) */
49
+ p95DurationMs: number;
50
+ /** P99 operation duration (ms) */
51
+ p99DurationMs: number;
52
+ /** Operations per second (last minute) */
53
+ opsPerSecond: number;
54
+ /** Active circuit breakers */
55
+ activeCircuitBreakers: string[];
56
+ /** Uptime in milliseconds */
57
+ uptimeMs: number;
58
+ }
59
+ /**
60
+ * Health check result
61
+ */
62
+ export interface HealthCheckResult {
63
+ /** Overall health status */
64
+ status: 'healthy' | 'degraded' | 'unhealthy';
65
+ /** Individual check results */
66
+ checks: {
67
+ name: string;
68
+ status: 'pass' | 'fail' | 'warn';
69
+ message?: string;
70
+ durationMs: number;
71
+ }[];
72
+ /** Timestamp of check */
73
+ timestamp: string;
74
+ }
75
+ type TelemetryHandler = (event: TelemetryEvent) => void;
76
+ type MetricsHandler = (metrics: PerformanceMetrics) => void;
77
+ /**
78
+ * Telemetry system for enterprise observability
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * import { telemetry } from 'stelo';
83
+ *
84
+ * // Enable telemetry
85
+ * telemetry.enable();
86
+ *
87
+ * // Subscribe to events
88
+ * telemetry.onEvent((event) => {
89
+ * console.log(`[${event.severity}] ${event.operation}: ${event.success}`);
90
+ * });
91
+ *
92
+ * // Get performance metrics
93
+ * const metrics = telemetry.getMetrics();
94
+ * console.log(`Ops/sec: ${metrics.opsPerSecond}`);
95
+ *
96
+ * // Run health checks
97
+ * const health = await telemetry.healthCheck();
98
+ * console.log(`System status: ${health.status}`);
99
+ * ```
100
+ */
101
+ export declare const telemetry: {
102
+ /**
103
+ * Enable telemetry collection
104
+ */
105
+ enable(): void;
106
+ /**
107
+ * Disable telemetry collection
108
+ */
109
+ disable(): void;
110
+ /**
111
+ * Check if telemetry is enabled
112
+ */
113
+ isEnabled(): boolean;
114
+ /**
115
+ * Enable metrics collection
116
+ */
117
+ enableMetrics(): void;
118
+ /**
119
+ * Disable metrics collection
120
+ */
121
+ disableMetrics(): void;
122
+ /**
123
+ * Subscribe to telemetry events
124
+ */
125
+ onEvent(handler: TelemetryHandler): () => void;
126
+ /**
127
+ * Subscribe to periodic metrics updates
128
+ */
129
+ onMetrics(handler: MetricsHandler): () => void;
130
+ /**
131
+ * Emit a telemetry event
132
+ * @internal Used by Stelo internals
133
+ */
134
+ emit(category: OperationCategory, operation: string, success: boolean, options?: {
135
+ severity?: TelemetrySeverity;
136
+ durationMs?: number;
137
+ error?: {
138
+ code: string;
139
+ message: string;
140
+ recoverable: boolean;
141
+ };
142
+ metadata?: Record<string, unknown>;
143
+ }): void;
144
+ /**
145
+ * Get current performance metrics
146
+ */
147
+ getMetrics(): PerformanceMetrics;
148
+ /**
149
+ * Run system health checks
150
+ */
151
+ healthCheck(): Promise<HealthCheckResult>;
152
+ /**
153
+ * Reset all metrics
154
+ */
155
+ resetMetrics(): void;
156
+ /**
157
+ * Wrap an operation with telemetry tracking
158
+ */
159
+ track<T>(category: OperationCategory, operation: string, fn: () => T, metadata?: Record<string, unknown>): T;
160
+ /**
161
+ * Wrap an async operation with telemetry tracking
162
+ */
163
+ trackAsync<T>(category: OperationCategory, operation: string, fn: () => Promise<T>, metadata?: Record<string, unknown>): Promise<T>;
164
+ };
165
+ /**
166
+ * Circuit breaker state
167
+ */
168
+ export type CircuitState = 'closed' | 'open' | 'half-open';
169
+ /**
170
+ * Circuit breaker configuration
171
+ */
172
+ export interface CircuitBreakerOptions {
173
+ /** Failure threshold before opening (default: 5) */
174
+ failureThreshold?: number;
175
+ /** Time to wait before half-open state (ms, default: 30000) */
176
+ resetTimeoutMs?: number;
177
+ /** Successes needed to close from half-open (default: 2) */
178
+ successThreshold?: number;
179
+ }
180
+ /**
181
+ * Circuit breaker for fault tolerance
182
+ */
183
+ export declare class CircuitBreaker {
184
+ readonly name: string;
185
+ private state;
186
+ private failureCount;
187
+ private successCount;
188
+ private lastFailureTime;
189
+ private readonly failureThreshold;
190
+ private readonly resetTimeoutMs;
191
+ private readonly successThreshold;
192
+ constructor(name: string, options?: CircuitBreakerOptions);
193
+ /**
194
+ * Get current circuit state
195
+ */
196
+ getState(): CircuitState;
197
+ /**
198
+ * Check if circuit is open (blocking)
199
+ */
200
+ isOpen(): boolean;
201
+ /**
202
+ * Record a successful operation
203
+ */
204
+ recordSuccess(): void;
205
+ /**
206
+ * Record a failed operation
207
+ */
208
+ recordFailure(): void;
209
+ /**
210
+ * Execute an operation with circuit breaker protection
211
+ */
212
+ execute<T>(fn: () => Promise<T>): Promise<T>;
213
+ /**
214
+ * Force reset the circuit breaker
215
+ */
216
+ reset(): void;
217
+ }
218
+ /**
219
+ * Get all registered circuit breakers
220
+ */
221
+ export declare function getCircuitBreakers(): CircuitBreaker[];
222
+ export {};
223
+ //# sourceMappingUR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