agent-web-interface 4.1.1 → 4.2.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 (71) hide show
  1. package/dist/src/browser/session-manager.d.ts +28 -1
  2. package/dist/src/browser/session-manager.d.ts.map +1 -1
  3. package/dist/src/browser/session-manager.js +73 -0
  4. package/dist/src/browser/session-manager.js.map +1 -1
  5. package/dist/src/index.d.ts +10 -1
  6. package/dist/src/index.d.ts.map +1 -1
  7. package/dist/src/index.js +47 -0
  8. package/dist/src/index.js.map +1 -1
  9. package/dist/src/server/mcp-server.d.ts +14 -1
  10. package/dist/src/server/mcp-server.d.ts.map +1 -1
  11. package/dist/src/server/mcp-server.js +21 -6
  12. package/dist/src/server/mcp-server.js.map +1 -1
  13. package/dist/src/server/session-store.d.ts +18 -3
  14. package/dist/src/server/session-store.d.ts.map +1 -1
  15. package/dist/src/server/session-store.js +27 -3
  16. package/dist/src/server/session-store.js.map +1 -1
  17. package/dist/src/session/session-worker-binding.d.ts +57 -0
  18. package/dist/src/session/session-worker-binding.d.ts.map +1 -0
  19. package/dist/src/session/session-worker-binding.js +109 -0
  20. package/dist/src/session/session-worker-binding.js.map +1 -0
  21. package/dist/src/shared/services/logging.service.d.ts +8 -0
  22. package/dist/src/shared/services/logging.service.d.ts.map +1 -1
  23. package/dist/src/shared/services/logging.service.js +10 -0
  24. package/dist/src/shared/services/logging.service.js.map +1 -1
  25. package/dist/src/snapshot/snapshot-compiler.d.ts.map +1 -1
  26. package/dist/src/snapshot/snapshot-compiler.js +68 -1
  27. package/dist/src/snapshot/snapshot-compiler.js.map +1 -1
  28. package/dist/src/tools/tool-schemas.d.ts +22 -22
  29. package/dist/src/tools/tool-schemas.d.ts.map +1 -1
  30. package/dist/src/tools/tool-schemas.js.map +1 -1
  31. package/dist/src/worker/chrome-worker-process.d.ts +123 -0
  32. package/dist/src/worker/chrome-worker-process.d.ts.map +1 -0
  33. package/dist/src/worker/chrome-worker-process.js +294 -0
  34. package/dist/src/worker/chrome-worker-process.js.map +1 -0
  35. package/dist/src/worker/errors/index.d.ts +5 -0
  36. package/dist/src/worker/errors/index.d.ts.map +1 -0
  37. package/dist/src/worker/errors/index.js +5 -0
  38. package/dist/src/worker/errors/index.js.map +1 -0
  39. package/dist/src/worker/errors/worker.error.d.ts +122 -0
  40. package/dist/src/worker/errors/worker.error.d.ts.map +1 -0
  41. package/dist/src/worker/errors/worker.error.js +199 -0
  42. package/dist/src/worker/errors/worker.error.js.map +1 -0
  43. package/dist/src/worker/health-monitor.d.ts +141 -0
  44. package/dist/src/worker/health-monitor.d.ts.map +1 -0
  45. package/dist/src/worker/health-monitor.js +260 -0
  46. package/dist/src/worker/health-monitor.js.map +1 -0
  47. package/dist/src/worker/index.d.ts +16 -0
  48. package/dist/src/worker/index.d.ts.map +1 -0
  49. package/dist/src/worker/index.js +19 -0
  50. package/dist/src/worker/index.js.map +1 -0
  51. package/dist/src/worker/lease-manager.d.ts +137 -0
  52. package/dist/src/worker/lease-manager.d.ts.map +1 -0
  53. package/dist/src/worker/lease-manager.js +334 -0
  54. package/dist/src/worker/lease-manager.js.map +1 -0
  55. package/dist/src/worker/multi-tenant-config.d.ts +46 -0
  56. package/dist/src/worker/multi-tenant-config.d.ts.map +1 -0
  57. package/dist/src/worker/multi-tenant-config.js +94 -0
  58. package/dist/src/worker/multi-tenant-config.js.map +1 -0
  59. package/dist/src/worker/port-allocator.d.ts +96 -0
  60. package/dist/src/worker/port-allocator.d.ts.map +1 -0
  61. package/dist/src/worker/port-allocator.js +153 -0
  62. package/dist/src/worker/port-allocator.js.map +1 -0
  63. package/dist/src/worker/types.d.ts +218 -0
  64. package/dist/src/worker/types.d.ts.map +1 -0
  65. package/dist/src/worker/types.js +38 -0
  66. package/dist/src/worker/types.js.map +1 -0
  67. package/dist/src/worker/worker-manager.d.ts +157 -0
  68. package/dist/src/worker/worker-manager.d.ts.map +1 -0
  69. package/dist/src/worker/worker-manager.js +500 -0
  70. package/dist/src/worker/worker-manager.js.map +1 -0
  71. package/package.json +1 -1
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Worker Error
3
+ *
4
+ * Standardized error classification for worker operations.
5
+ * Provides error codes for programmatic handling and detailed messages for debugging.
6
+ */
7
+ /**
8
+ * Error codes for worker operations
9
+ */
10
+ export type WorkerErrorCode = 'WORKER_NOT_FOUND' | 'WORKER_NOT_RUNNING' | 'WORKER_CRASHED' | 'WORKER_START_FAILED' | 'WORKER_STOP_FAILED' | 'LEASE_NOT_FOUND' | 'LEASE_NOT_HELD' | 'LEASE_EXPIRED' | 'LEASE_ALREADY_HELD' | 'PORT_EXHAUSTED' | 'MAX_WORKERS_REACHED' | 'HEALTH_CHECK_FAILED' | 'HEALTH_CHECK_TIMEOUT' | 'INVALID_STATE' | 'OPERATION_FAILED';
11
+ /**
12
+ * Standardized error for worker operations.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * throw new WorkerError(
17
+ * 'Worker crashed unexpectedly',
18
+ * 'WORKER_CRASHED',
19
+ * { workerId: 'w-123', exitCode: 1 }
20
+ * );
21
+ *
22
+ * // Catching and handling by code
23
+ * try {
24
+ * await workerManager.acquireForTenant('tenant-a', 'controller-1');
25
+ * } catch (error) {
26
+ * if (error instanceof WorkerError) {
27
+ * switch (error.code) {
28
+ * case 'MAX_WORKERS_REACHED':
29
+ * console.log('Worker limit reached, try again later');
30
+ * break;
31
+ * case 'LEASE_ALREADY_HELD':
32
+ * console.log('Another session has the lease');
33
+ * break;
34
+ * }
35
+ * }
36
+ * }
37
+ * ```
38
+ */
39
+ export declare class WorkerError extends Error {
40
+ /**
41
+ * Error code for programmatic handling
42
+ */
43
+ readonly code: WorkerErrorCode;
44
+ /**
45
+ * Original error that caused this error (if any)
46
+ */
47
+ readonly cause?: Error;
48
+ /**
49
+ * Additional context for debugging
50
+ */
51
+ readonly context?: Record<string, unknown>;
52
+ constructor(message: string, code: WorkerErrorCode, context?: Record<string, unknown>, cause?: Error);
53
+ /**
54
+ * Create a JSON-serializable representation of the error
55
+ */
56
+ toJSON(): Record<string, unknown>;
57
+ /**
58
+ * Type guard to check if an error is a WorkerError
59
+ */
60
+ static isWorkerError(error: unknown): error is WorkerError;
61
+ /**
62
+ * Create error for worker not found
63
+ */
64
+ static workerNotFound(workerId: string, context?: Record<string, unknown>): WorkerError;
65
+ /**
66
+ * Create error for worker not running
67
+ */
68
+ static workerNotRunning(workerId: string, currentState: string, context?: Record<string, unknown>): WorkerError;
69
+ /**
70
+ * Create error for worker crash
71
+ */
72
+ static workerCrashed(workerId: string, exitCode: number | null, signal: string | null, context?: Record<string, unknown>): WorkerError;
73
+ /**
74
+ * Create error for worker start failure
75
+ */
76
+ static workerStartFailed(workerId: string, cause: Error, context?: Record<string, unknown>): WorkerError;
77
+ /**
78
+ * Create error for worker stop failure
79
+ */
80
+ static workerStopFailed(workerId: string, cause: Error, context?: Record<string, unknown>): WorkerError;
81
+ /**
82
+ * Create error for lease not found
83
+ */
84
+ static leaseNotFound(tenantId: string, context?: Record<string, unknown>): WorkerError;
85
+ /**
86
+ * Create error for lease not held by controller
87
+ */
88
+ static leaseNotHeld(tenantId: string, controllerId: string, actualControllerId: string, context?: Record<string, unknown>): WorkerError;
89
+ /**
90
+ * Create error for expired lease
91
+ */
92
+ static leaseExpired(tenantId: string, expiredAt: number, context?: Record<string, unknown>): WorkerError;
93
+ /**
94
+ * Create error for lease already held
95
+ */
96
+ static leaseAlreadyHeld(tenantId: string, heldByControllerId: string, context?: Record<string, unknown>): WorkerError;
97
+ /**
98
+ * Create error for port exhaustion
99
+ */
100
+ static portExhausted(portMin: number, portMax: number, context?: Record<string, unknown>): WorkerError;
101
+ /**
102
+ * Create error for max workers reached
103
+ */
104
+ static maxWorkersReached(maxWorkers: number, currentCount: number, context?: Record<string, unknown>): WorkerError;
105
+ /**
106
+ * Create error for health check failure
107
+ */
108
+ static healthCheckFailed(workerId: string, cause: Error, context?: Record<string, unknown>): WorkerError;
109
+ /**
110
+ * Create error for health check timeout
111
+ */
112
+ static healthCheckTimeout(workerId: string, timeoutMs: number, context?: Record<string, unknown>): WorkerError;
113
+ /**
114
+ * Create error for invalid state transition
115
+ */
116
+ static invalidState(currentState: string, attemptedOperation: string, context?: Record<string, unknown>): WorkerError;
117
+ /**
118
+ * Create error for generic operation failure
119
+ */
120
+ static operationFailed(operation: string, cause: Error, context?: Record<string, unknown>): WorkerError;
121
+ }
122
+ //# sourceMappingURL=worker.error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.error.d.ts","sourceRoot":"","sources":["../../../../src/worker/errors/worker.error.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,MAAM,eAAe,GAEvB,kBAAkB,GAClB,oBAAoB,GACpB,gBAAgB,GAChB,qBAAqB,GACrB,oBAAoB,GAEpB,iBAAiB,GACjB,gBAAgB,GAChB,eAAe,GACf,oBAAoB,GAEpB,gBAAgB,GAChB,qBAAqB,GAErB,qBAAqB,GACrB,sBAAsB,GAEtB,eAAe,GACf,kBAAkB,CAAC;AAEvB;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAE/B;;OAEG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IAEvB;;OAEG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAGzC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,eAAe,EACrB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,KAAK,CAAC,EAAE,KAAK;IAcf;;OAEG;IACH,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAgBjC;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,I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ker Error
3
+ *
4
+ * Standardized error classification for worker operations.
5
+ * Provides error codes for programmatic handling and detailed messages for debugging.
6
+ */
7
+ /**
8
+ * Standardized error for worker operations.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * throw new WorkerError(
13
+ * 'Worker crashed unexpectedly',
14
+ * 'WORKER_CRASHED',
15
+ * { workerId: 'w-123', exitCode: 1 }
16
+ * );
17
+ *
18
+ * // Catching and handling by code
19
+ * try {
20
+ * await workerManager.acquireForTenant('tenant-a', 'controller-1');
21
+ * } catch (error) {
22
+ * if (error instanceof WorkerError) {
23
+ * switch (error.code) {
24
+ * case 'MAX_WORKERS_REACHED':
25
+ * console.log('Worker limit reached, try again later');
26
+ * break;
27
+ * case 'LEASE_ALREADY_HELD':
28
+ * console.log('Another session has the lease');
29
+ * break;
30
+ * }
31
+ * }
32
+ * }
33
+ * ```
34
+ */
35
+ export class WorkerError extends Error {
36
+ /**
37
+ * Error code for programmatic handling
38
+ */
39
+ code;
40
+ /**
41
+ * Original error that caused this error (if any)
42
+ */
43
+ cause;
44
+ /**
45
+ * Additional context for debugging
46
+ */
47
+ context;
48
+ constructor(message, code, context, cause) {
49
+ super(message);
50
+ this.name = 'WorkerError';
51
+ this.code = code;
52
+ this.cause = cause;
53
+ this.context = context;
54
+ // Maintains proper stack trace for where error was thrown (V8 only)
55
+ if (Error.captureStackTrace) {
56
+ Error.captureStackTrace(this, WorkerError);
57
+ }
58
+ }
59
+ /**
60
+ * Create a JSON-serializable representation of the error
61
+ */
62
+ toJSON() {
63
+ return {
64
+ name: this.name,
65
+ message: this.message,
66
+ code: this.code,
67
+ context: this.context,
68
+ cause: this.cause
69
+ ? {
70
+ name: this.cause.name,
71
+ message: this.cause.message,
72
+ }
73
+ : undefined,
74
+ stack: this.stack,
75
+ };
76
+ }
77
+ /**
78
+ * Type guard to check if an error is a WorkerError
79
+ */
80
+ static isWorkerError(error) {
81
+ return error instanceof WorkerError;
82
+ }
83
+ // ==================== Factory Methods ====================
84
+ /**
85
+ * Create error for worker not found
86
+ */
87
+ static workerNotFound(workerId, context) {
88
+ return new WorkerError('Worker not found', 'WORKER_NOT_FOUND', { workerId, ...context });
89
+ }
90
+ /**
91
+ * Create error for worker not running
92
+ */
93
+ static workerNotRunning(workerId, currentState, context) {
94
+ return new WorkerError(`Worker is not running (current state: ${currentState})`, 'WORKER_NOT_RUNNING', { workerId, currentState, ...context });
95
+ }
96
+ /**
97
+ * Create error for worker crash
98
+ */
99
+ static workerCrashed(workerId, exitCode, signal, context) {
100
+ return new WorkerError(`Worker crashed (exit code: ${exitCode}, signal: ${signal})`, 'WORKER_CRASHED', { workerId, exitCode, signal, ...context });
101
+ }
102
+ /**
103
+ * Create error for worker start failure
104
+ */
105
+ static workerStartFailed(workerId, cause, context) {
106
+ return new WorkerError(`Failed to start worker: ${cause.message}`, 'WORKER_START_FAILED', { workerId, ...context }, cause);
107
+ }
108
+ /**
109
+ * Create error for worker stop failure
110
+ */
111
+ static workerStopFailed(workerId, cause, context) {
112
+ return new WorkerError(`Failed to stop worker: ${cause.message}`, 'WORKER_STOP_FAILED', { workerId, ...context }, cause);
113
+ }
114
+ /**
115
+ * Create error for lease not found
116
+ */
117
+ static leaseNotFound(tenantId, context) {
118
+ return new WorkerError('Lease not found for tenant', 'LEASE_NOT_FOUND', {
119
+ tenantId,
120
+ ...context,
121
+ });
122
+ }
123
+ /**
124
+ * Create error for lease not held by controller
125
+ */
126
+ static leaseNotHeld(tenantId, controllerId, actualControllerId, context) {
127
+ return new WorkerError('Lease is held by a different controller', 'LEASE_NOT_HELD', {
128
+ tenantId,
129
+ controllerId,
130
+ actualControllerId,
131
+ ...context,
132
+ });
133
+ }
134
+ /**
135
+ * Create error for expired lease
136
+ */
137
+ static leaseExpired(tenantId, expiredAt, context) {
138
+ return new WorkerError('Lease has expired', 'LEASE_EXPIRED', {
139
+ tenantId,
140
+ expiredAt,
141
+ ...context,
142
+ });
143
+ }
144
+ /**
145
+ * Create error for lease already held
146
+ */
147
+ static leaseAlreadyHeld(tenantId, heldByControllerId, context) {
148
+ return new WorkerError('Lease is already held by another controller', 'LEASE_ALREADY_HELD', {
149
+ tenantId,
150
+ heldByControllerId,
151
+ ...context,
152
+ });
153
+ }
154
+ /**
155
+ * Create error for port exhaustion
156
+ */
157
+ static portExhausted(portMin, portMax, context) {
158
+ return new WorkerError(`No available ports in range ${portMin}-${portMax}`, 'PORT_EXHAUSTED', {
159
+ portMin,
160
+ portMax,
161
+ ...context,
162
+ });
163
+ }
164
+ /**
165
+ * Create error for max workers reached
166
+ */
167
+ static maxWorkersReached(maxWorkers, currentCount, context) {
168
+ return new WorkerError(`Maximum worker limit reached (${currentCount}/${maxWorkers})`, 'MAX_WORKERS_REACHED', { maxWorkers, currentCount, ...context });
169
+ }
170
+ /**
171
+ * Create error for health check failure
172
+ */
173
+ static healthCheckFailed(workerId, cause, context) {
174
+ return new WorkerError(`Health check failed: ${cause.message}`, 'HEALTH_CHECK_FAILED', { workerId, ...context }, cause);
175
+ }
176
+ /**
177
+ * Create error for health check timeout
178
+ */
179
+ static healthCheckTimeout(workerId, timeoutMs, context) {
180
+ return new WorkerError(`Health check timed out after ${timeoutMs}ms`, 'HEALTH_CHECK_TIMEOUT', {
181
+ workerId,
182
+ timeoutMs,
183
+ ...context,
184
+ });
185
+ }
186
+ /**
187
+ * Create error for invalid state transition
188
+ */
189
+ static invalidState(currentState, attemptedOperation, context) {
190
+ return new WorkerError(`Invalid operation "${attemptedOperation}" in state "${currentState}"`, 'INVALID_STATE', { currentState, attemptedOperation, ...context });
191
+ }
192
+ /**
193
+ * Create error for generic operation failure
194
+ */
195
+ static operationFailed(operation, cause, context) {
196
+ return new WorkerError(`Operation failed: ${operation} - ${cause.message}`, 'OPERATION_FAILED', { operation, ...context }, cause);
197
+ }
198
+ }
199
+ //# sourceMappingURL=worker.error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.error.js","sourceRoot":"","sources":["../../../../src/worker/errors/worker.error.ts"],"names":[],"mappings":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qBAAqB,EACrB,EAAE,QAAQ,EAAE,GAAG,OAAO,EAAE,EACxB,KAAK,CACN,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,kBAAkB,CACvB,QAAgB,EAChB,SAAiB,EACjB,OAAiC;QAEjC,OAAO,IAAI,WAAW,CAAC,gCAAgC,SAAS,IAAI,EAAE,sBAAsB,EAAE;YAC5F,QAAQ;YACR,SAAS;YACT,GAAG,OAAO;SACX,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,YAAY,CACjB,YAAoB,EACpB,kBAA0B,EAC1B,OAAiC;QAEjC,OAAO,IAAI,WAAW,CACpB,sBAAsB,kBAAkB,eAAe,YAAY,GAAG,EACtE,eAAe,EACf,EAAE,YAAY,EAAE,kBAAkB,EAAE,GAAG,OAAO,EAAE,CACjD,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,eAAe,CACpB,SAAiB,EACjB,KAAY,EACZ,OAAiC;QAEjC,OAAO,IAAI,WAAW,CACpB,qBAAqB,SAAS,MAAM,KAAK,CAAC,OAAO,EAAE,EACnD,kBAAkB,EAClB,EAAE,SAAS,EAAE,GAAG,OAAO,EAAE,EACzB,KAAK,CACN,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Health Monitor
3
+ *
4
+ * Monitors the health of Chrome workers by periodically checking
5
+ * their CDP endpoints via /json/version.
6
+ */
7
+ import { EventEmitter } from 'events';
8
+ import type { HealthCheckResult, HealthMonitorEvents } from './types.js';
9
+ /**
10
+ * Configuration for health checking
11
+ */
12
+ export interface HealthCheckConfig {
13
+ /** Timeout for individual health checks (ms) */
14
+ timeoutMs?: number;
15
+ /** Number of consecutive failures before considered unhealthy */
16
+ failureThreshold?: number;
17
+ }
18
+ /**
19
+ * Track health state for a worker
20
+ */
21
+ interface WorkerHealthState {
22
+ workerId: string;
23
+ port: number;
24
+ healthy: boolean;
25
+ consecutiveFailures: number;
26
+ lastCheck?: HealthCheckResult;
27
+ lastCheckTime?: number;
28
+ }
29
+ /**
30
+ * Type-safe EventEmitter for HealthMonitor
31
+ */
32
+ interface HealthMonitorEmitter {
33
+ on<K extends keyof HealthMonitorEvents>(event: K, listener: (data: HealthMonitorEvents[K]) => void): this;
34
+ once<K extends keyof HealthMonitorEvents>(event: K, listener: (data: HealthMonitorEvents[K]) => void): this;
35
+ emit<K extends keyof HealthMonitorEvents>(event: K, data: HealthMonitorEvents[K]): boolean;
36
+ off<K extends keyof HealthMonitorEvents>(event: K, listener: (data: HealthMonitorEvents[K]) => void): this;
37
+ removeAllListeners<K extends keyof HealthMonitorEvents>(event?: K): this;
38
+ }
39
+ /**
40
+ * Monitors the health of Chrome workers.
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * const monitor = new HealthMonitor({ intervalMs: 30000 });
45
+ *
46
+ * monitor.on('healthChange', ({ workerId, healthy, result }) => {
47
+ * if (!healthy) {
48
+ * console.log(`Worker ${workerId} became unhealthy: ${result.error}`);
49
+ * }
50
+ * });
51
+ *
52
+ * monitor.registerWorker('w-123', 9300);
53
+ * monitor.start();
54
+ *
55
+ * // Later...
56
+ * monitor.unregisterWorker('w-123');
57
+ * monitor.stop();
58
+ * ```
59
+ */
60
+ export declare class HealthMonitor extends EventEmitter implements HealthMonitorEmitter {
61
+ private readonly intervalMs;
62
+ private readonly config;
63
+ private readonly workers;
64
+ private intervalId;
65
+ private _isRunning;
66
+ constructor(intervalMs?: number, config?: HealthCheckConfig);
67
+ /**
68
+ * Check if the monitor is currently running
69
+ */
70
+ get isRunning(): boolean;
71
+ /**
72
+ * Get the number of registered workers
73
+ */
74
+ get workerCount(): number;
75
+ /**
76
+ * Register a worker for health monitoring
77
+ *
78
+ * @param workerId - Unique worker identifier
79
+ * @param port - CDP port number
80
+ */
81
+ registerWorker(workerId: string, port: number): void;
82
+ /**
83
+ * Unregister a worker from health monitoring
84
+ *
85
+ * @param workerId - Unique worker identifier
86
+ * @returns true if the worker was found and removed
87
+ */
88
+ unregisterWorker(workerId: string): boolean;
89
+ /**
90
+ * Check if a worker is registered
91
+ */
92
+ isWorkerRegistered(workerId: string): boolean;
93
+ /**
94
+ * Get the current health state of a worker
95
+ */
96
+ getWorkerHealth(workerId: string): WorkerHealthState | undefined;
97
+ /**
98
+ * Start periodic health monitoring
99
+ */
100
+ start(): void;
101
+ /**
102
+ * Stop periodic health monitoring
103
+ */
104
+ stop(): void;
105
+ /**
106
+ * Check health of all registered workers
107
+ */
108
+ checkAllWorkers(): Promise<void>;
109
+ /**
110
+ * Check health of a specific worker by ID
111
+ *
112
+ * @param workerId - Worker identifier
113
+ * @returns Health check result
114
+ */
115
+ checkWorkerById(workerId: string): Promise<HealthCheckResult>;
116
+ /**
117
+ * Perform a single health check on a worker
118
+ */
119
+ private checkWorker;
120
+ /**
121
+ * Perform a health check against the CDP endpoint
122
+ *
123
+ * @param port - CDP port number
124
+ * @returns Health check result
125
+ */
126
+ performHealthCheck(port: number): Promise<HealthCheckResult>;
127
+ /**
128
+ * Get all unhealthy workers
129
+ */
130
+ getUnhealthyWorkers(): string[];
131
+ /**
132
+ * Reset health state for a worker (e.g., after restart)
133
+ */
134
+ resetWorkerHealth(workerId: string): void;
135
+ /**
136
+ * Clear all registered workers
137
+ */
138
+ clear(): void;
139
+ }
140
+ export {};
141
+ //# sourceMappingURL=health-monitor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health-monitor.d.ts","sourceRoot":"","sources":["../../../src/worker/health-monitor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,iBAAiB,EAAkB,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAKzF;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iEAAiE;IACjE,gBAAgB,CAAC,EAAE,MAAM,CAAC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