create-fluxstack 1.7.5 โ†’ 1.8.3

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 (154) hide show
  1. package/.dockerignore +82 -0
  2. package/.env.example +19 -0
  3. package/Dockerfile +70 -0
  4. package/README.md +6 -3
  5. package/app/client/SIMPLIFICATION.md +140 -0
  6. package/app/client/frontend-only.ts +1 -1
  7. package/app/client/src/App.tsx +148 -283
  8. package/app/client/src/index.css +5 -20
  9. package/app/client/src/lib/eden-api.ts +53 -220
  10. package/app/client/src/main.tsx +2 -3
  11. package/app/server/app.ts +20 -5
  12. package/app/server/backend-only.ts +15 -12
  13. package/app/server/controllers/users.controller.ts +57 -31
  14. package/app/server/index.ts +86 -96
  15. package/app/server/live/register-components.ts +18 -7
  16. package/app/server/routes/env-test.ts +110 -0
  17. package/app/server/routes/index.ts +1 -8
  18. package/app/server/routes/users.routes.ts +192 -91
  19. package/config/app.config.ts +2 -54
  20. package/config/client.config.ts +95 -0
  21. package/config/fluxstack.config.ts +2 -2
  22. package/config/index.ts +57 -22
  23. package/config/monitoring.config.ts +114 -0
  24. package/config/plugins.config.ts +80 -0
  25. package/config/runtime.config.ts +0 -17
  26. package/config/server.config.ts +50 -30
  27. package/core/build/bundler.ts +17 -16
  28. package/core/build/flux-plugins-generator.ts +34 -23
  29. package/core/build/index.ts +32 -31
  30. package/core/build/live-components-generator.ts +44 -30
  31. package/core/build/optimizer.ts +37 -17
  32. package/core/cli/command-registry.ts +4 -14
  33. package/core/cli/commands/plugin-deps.ts +8 -8
  34. package/core/cli/generators/component.ts +3 -3
  35. package/core/cli/generators/controller.ts +4 -4
  36. package/core/cli/generators/index.ts +8 -8
  37. package/core/cli/generators/interactive.ts +4 -4
  38. package/core/cli/generators/plugin.ts +3 -3
  39. package/core/cli/generators/prompts.ts +1 -1
  40. package/core/cli/generators/route.ts +27 -11
  41. package/core/cli/generators/service.ts +5 -5
  42. package/core/cli/generators/template-engine.ts +1 -1
  43. package/core/cli/generators/types.ts +1 -1
  44. package/core/cli/index.ts +158 -189
  45. package/core/cli/plugin-discovery.ts +3 -3
  46. package/core/client/hooks/index.ts +2 -2
  47. package/core/client/hooks/state-validator.ts +1 -1
  48. package/core/client/hooks/useAuth.ts +1 -1
  49. package/core/client/hooks/useChunkedUpload.ts +1 -1
  50. package/core/client/hooks/useHybridLiveComponent.ts +1 -1
  51. package/core/client/hooks/useWebSocket.ts +1 -1
  52. package/core/config/env.ts +5 -1
  53. package/core/config/runtime-config.ts +12 -10
  54. package/core/config/schema.ts +33 -2
  55. package/core/framework/server.ts +30 -14
  56. package/core/framework/types.ts +2 -2
  57. package/core/index.ts +31 -23
  58. package/core/live/ComponentRegistry.ts +1 -1
  59. package/core/plugins/built-in/live-components/commands/create-live-component.ts +1 -1
  60. package/core/plugins/built-in/live-components/index.ts +1 -1
  61. package/core/plugins/built-in/monitoring/index.ts +65 -161
  62. package/core/plugins/built-in/static/index.ts +75 -277
  63. package/core/plugins/built-in/swagger/index.ts +301 -231
  64. package/core/plugins/built-in/vite/index.ts +342 -377
  65. package/core/plugins/config.ts +2 -2
  66. package/core/plugins/dependency-manager.ts +2 -2
  67. package/core/plugins/discovery.ts +1 -1
  68. package/core/plugins/executor.ts +2 -2
  69. package/core/plugins/manager.ts +19 -4
  70. package/core/plugins/module-resolver.ts +1 -1
  71. package/core/plugins/registry.ts +25 -21
  72. package/core/plugins/types.ts +147 -5
  73. package/core/server/backend-entry.ts +51 -0
  74. package/core/server/framework.ts +2 -2
  75. package/core/server/live/ComponentRegistry.ts +9 -26
  76. package/core/server/live/FileUploadManager.ts +1 -1
  77. package/core/server/live/auto-generated-components.ts +26 -0
  78. package/core/server/live/websocket-plugin.ts +211 -19
  79. package/core/server/middleware/errorHandling.ts +1 -1
  80. package/core/server/middleware/index.ts +4 -4
  81. package/core/server/plugins/database.ts +1 -2
  82. package/core/server/plugins/static-files-plugin.ts +259 -231
  83. package/core/server/plugins/swagger.ts +1 -1
  84. package/core/server/services/BaseService.ts +1 -1
  85. package/core/server/services/ServiceContainer.ts +1 -1
  86. package/core/server/services/index.ts +4 -4
  87. package/core/server/standalone.ts +16 -1
  88. package/core/testing/index.ts +1 -1
  89. package/core/testing/setup.ts +1 -1
  90. package/core/types/plugin.ts +6 -0
  91. package/core/utils/build-logger.ts +324 -0
  92. package/core/utils/config-schema.ts +2 -6
  93. package/core/utils/helpers.ts +14 -9
  94. package/core/utils/logger/startup-banner.ts +7 -33
  95. package/core/utils/regenerate-files.ts +69 -0
  96. package/core/utils/version.ts +6 -6
  97. package/create-fluxstack.ts +68 -25
  98. package/fluxstack.config.ts +138 -252
  99. package/package.json +3 -18
  100. package/plugins/crypto-auth/index.ts +52 -47
  101. package/plugins/crypto-auth/server/AuthMiddleware.ts +1 -1
  102. package/plugins/crypto-auth/server/middlewares/helpers.ts +16 -1
  103. package/vitest.config.ts +17 -26
  104. package/app/client/src/App.css +0 -883
  105. package/app/client/src/components/ErrorBoundary.tsx +0 -107
  106. package/app/client/src/components/ErrorDisplay.css +0 -365
  107. package/app/client/src/components/ErrorDisplay.tsx +0 -258
  108. package/app/client/src/components/FluxStackConfig.tsx +0 -1321
  109. package/app/client/src/components/HybridLiveCounter.tsx +0 -140
  110. package/app/client/src/components/LiveClock.tsx +0 -286
  111. package/app/client/src/components/MainLayout.tsx +0 -388
  112. package/app/client/src/components/SidebarNavigation.tsx +0 -391
  113. package/app/client/src/components/StateDemo.tsx +0 -178
  114. package/app/client/src/components/SystemMonitor.tsx +0 -1044
  115. package/app/client/src/components/UserProfile.tsx +0 -809
  116. package/app/client/src/hooks/useAuth.ts +0 -39
  117. package/app/client/src/hooks/useNotifications.ts +0 -56
  118. package/app/client/src/lib/errors.ts +0 -340
  119. package/app/client/src/lib/hooks/useErrorHandler.ts +0 -258
  120. package/app/client/src/lib/index.ts +0 -45
  121. package/app/client/src/pages/ApiDocs.tsx +0 -182
  122. package/app/client/src/pages/CryptoAuthPage.tsx +0 -394
  123. package/app/client/src/pages/Demo.tsx +0 -174
  124. package/app/client/src/pages/HybridLive.tsx +0 -263
  125. package/app/client/src/pages/Overview.tsx +0 -155
  126. package/app/client/src/store/README.md +0 -43
  127. package/app/client/src/store/index.ts +0 -16
  128. package/app/client/src/store/slices/uiSlice.ts +0 -151
  129. package/app/client/src/store/slices/userSlice.ts +0 -161
  130. package/app/client/src/test/README.md +0 -257
  131. package/app/client/src/test/setup.ts +0 -70
  132. package/app/client/src/test/types.ts +0 -12
  133. package/app/server/live/CounterComponent.ts +0 -191
  134. package/app/server/live/FluxStackConfig.ts +0 -534
  135. package/app/server/live/SidebarNavigation.ts +0 -157
  136. package/app/server/live/SystemMonitor.ts +0 -595
  137. package/app/server/live/SystemMonitorIntegration.ts +0 -151
  138. package/app/server/live/UserProfileComponent.ts +0 -141
  139. package/app/server/middleware/auth.ts +0 -136
  140. package/app/server/middleware/errorHandling.ts +0 -252
  141. package/app/server/middleware/index.ts +0 -10
  142. package/app/server/middleware/rateLimit.ts +0 -193
  143. package/app/server/middleware/requestLogging.ts +0 -215
  144. package/app/server/middleware/validation.ts +0 -270
  145. package/app/server/routes/config.ts +0 -145
  146. package/app/server/routes/crypto-auth-demo.routes.ts +0 -167
  147. package/app/server/routes/example-with-crypto-auth.routes.ts +0 -235
  148. package/app/server/routes/exemplo-posts.routes.ts +0 -161
  149. package/app/server/routes/upload.ts +0 -92
  150. package/app/server/services/NotificationService.ts +0 -302
  151. package/app/server/services/UserService.ts +0 -222
  152. package/app/server/services/index.ts +0 -46
  153. package/app/server/types/index.ts +0 -1
  154. package/config/build.config.ts +0 -24
@@ -1,595 +0,0 @@
1
- // ๐Ÿ”ฅ System Monitor Live Component
2
-
3
- import { LiveComponent } from '@/core/types/types'
4
- import { componentRegistry } from '@/core/server/live/ComponentRegistry'
5
-
6
- export interface SystemMonitorState {
7
- // Real-time metrics
8
- totalComponents: number
9
- activeConnections: number
10
- totalRooms: number
11
- messagesPerSecond: number
12
- averageResponseTime: number
13
-
14
- // Component breakdown
15
- componentsByType: Record<string, number>
16
- roomDetails: Record<string, number>
17
-
18
- // Performance metrics
19
- memoryUsage: {
20
- used: number
21
- total: number
22
- percentage: number
23
- }
24
-
25
- // Recent activity
26
- recentConnections: Array<{
27
- id: string
28
- timestamp: number
29
- componentType: string
30
- status: 'connected' | 'disconnected' | 'rehydrated'
31
- }>
32
-
33
- recentMessages: Array<{
34
- id: string
35
- timestamp: number
36
- type: string
37
- componentId: string
38
- success: boolean
39
- responseTime?: number
40
- }>
41
-
42
- // System health
43
- systemHealth: {
44
- status: 'healthy' | 'warning' | 'critical'
45
- uptime: number
46
- lastRestart: number
47
- errors: number
48
- warnings: number
49
- }
50
-
51
- // Auto-refresh settings
52
- autoRefresh: boolean
53
- refreshInterval: number
54
- lastUpdated: number
55
- }
56
-
57
- export class SystemMonitor extends LiveComponent<SystemMonitorState> {
58
- private refreshTimer: NodeJS.Timeout | null = null
59
- private pushTimer: NodeJS.Timeout | null = null
60
- private messageCount = 0
61
- private lastMessageTime = Date.now()
62
- private responseTimes: number[] = []
63
- private startTime = Date.now()
64
- private pushInterval = 1000 // Push every 1 second
65
- private isActive = true // Control flag for stopping all activities
66
- private version = 1 // Component version
67
-
68
- constructor(initialState: SystemMonitorState, ws: any, options?: any) {
69
- super(initialState, ws, options)
70
-
71
- // Set default state
72
- this.state = {
73
- totalComponents: 0,
74
- activeConnections: 0,
75
- totalRooms: 0,
76
- messagesPerSecond: 0,
77
- averageResponseTime: 0,
78
- componentsByType: {},
79
- roomDetails: {},
80
- memoryUsage: {
81
- used: 0,
82
- total: 0,
83
- percentage: 0
84
- },
85
- recentConnections: [],
86
- recentMessages: [],
87
- systemHealth: {
88
- status: 'healthy',
89
- uptime: 0,
90
- lastRestart: Date.now(),
91
- errors: 0,
92
- warnings: 0
93
- },
94
- autoRefresh: true,
95
- refreshInterval: 2000, // 2 seconds
96
- lastUpdated: Date.now(),
97
- ...initialState
98
- }
99
-
100
- // Start auto-refresh if enabled
101
- if (this.state.autoRefresh) {
102
- this.startAutoRefresh()
103
- }
104
-
105
- // Start automatic push timer
106
- this.startAutoPush()
107
-
108
- // Initial data collection with push
109
- this.collectMetricsWithPush()
110
- }
111
-
112
- // Start auto-refresh timer
113
- async startAutoRefresh() {
114
- if (this.refreshTimer) {
115
- clearInterval(this.refreshTimer)
116
- }
117
-
118
- this.refreshTimer = setInterval(() => {
119
- this.collectMetricsWithPush()
120
- }, this.state.refreshInterval)
121
-
122
- console.log(`๐Ÿ”„ SystemMonitor: Auto-refresh started (${this.state.refreshInterval}ms)`)
123
- }
124
-
125
- // Stop auto-refresh timer
126
- async stopAutoRefresh() {
127
- if (this.refreshTimer) {
128
- clearInterval(this.refreshTimer)
129
- this.refreshTimer = null
130
- }
131
-
132
- console.log('โน๏ธ SystemMonitor: Auto-refresh stopped')
133
- }
134
-
135
- // Start automatic push timer
136
- async startAutoPush() {
137
- if (this.pushTimer) {
138
- clearInterval(this.pushTimer)
139
- }
140
-
141
- this.pushTimer = setInterval(() => {
142
- this.sendLiveUpdate()
143
- }, this.pushInterval)
144
-
145
- console.log(`๐Ÿ“ก SystemMonitor: Auto-push started (${this.pushInterval}ms)`)
146
- }
147
-
148
- // Stop automatic push timer
149
- async stopAutoPush() {
150
- if (this.pushTimer) {
151
- clearInterval(this.pushTimer)
152
- this.pushTimer = null
153
- }
154
-
155
- console.log('โน๏ธ SystemMonitor: Auto-push stopped')
156
- }
157
-
158
- // Send live update to frontend
159
- private sendLiveUpdate() {
160
- if (!this.isActive) {
161
- return // Stop sending updates if component is not active
162
- }
163
-
164
- try {
165
- const quickMetrics = {
166
- timestamp: Date.now(),
167
- uptime: Math.round((Date.now() - this.startTime) / 1000),
168
- connections: componentRegistry.getStats().connections,
169
- components: componentRegistry.getStats().components,
170
- memoryPercentage: this.state.memoryUsage.percentage,
171
- healthStatus: this.state.systemHealth.status,
172
- lastActivity: Math.max(
173
- ...this.state.recentMessages.map(m => m.timestamp),
174
- ...this.state.recentConnections.map(c => c.timestamp),
175
- 0
176
- )
177
- }
178
-
179
- this.pushUpdate({
180
- type: 'LIVE_UPDATE',
181
- ...quickMetrics
182
- })
183
-
184
- } catch (error: any) {
185
- console.warn('โš ๏ธ SystemMonitor: Failed to send live update:', error.message)
186
- }
187
- }
188
-
189
- // Toggle auto-refresh
190
- async toggleAutoRefresh() {
191
- const newAutoRefresh = !this.state.autoRefresh
192
-
193
- this.setState({
194
- autoRefresh: newAutoRefresh
195
- })
196
-
197
- if (newAutoRefresh) {
198
- this.startAutoRefresh()
199
- this.startAutoPush() // Also restart push when enabling
200
- } else {
201
- this.stopAutoRefresh()
202
- this.stopAutoPush() // Also stop push when disabling
203
- }
204
-
205
- this.emit('AUTO_REFRESH_TOGGLED', {
206
- enabled: newAutoRefresh,
207
- timestamp: Date.now()
208
- })
209
- }
210
-
211
- // Set refresh interval
212
- async setRefreshInterval(data: { interval: number }) {
213
- if (data.interval < 500 || data.interval > 60000) {
214
- throw new Error('Refresh interval must be between 500ms and 60s')
215
- }
216
-
217
- this.setState({
218
- refreshInterval: data.interval
219
- })
220
-
221
- // Restart auto-refresh with new interval
222
- if (this.state.autoRefresh) {
223
- this.startAutoRefresh()
224
- }
225
-
226
- this.emit('REFRESH_INTERVAL_CHANGED', {
227
- interval: data.interval,
228
- timestamp: Date.now()
229
- })
230
-
231
- console.log(`โฑ๏ธ SystemMonitor: Refresh interval set to ${data.interval}ms`)
232
- }
233
-
234
- // Set push interval for live updates
235
- async setPushInterval(data: { interval: number }) {
236
- if (data.interval < 100 || data.interval > 10000) {
237
- throw new Error('Push interval must be between 100ms and 10s')
238
- }
239
-
240
- this.pushInterval = data.interval
241
-
242
- // Restart push timer with new interval
243
- this.startAutoPush()
244
-
245
- this.emit('PUSH_INTERVAL_CHANGED', {
246
- interval: data.interval,
247
- timestamp: Date.now()
248
- })
249
-
250
- console.log(`๐Ÿ“ก SystemMonitor: Push interval set to ${data.interval}ms`)
251
- }
252
-
253
- // Collect all system metrics
254
- async collectMetrics() {
255
- try {
256
- const registryStats = componentRegistry.getStats()
257
- const memUsage = process.memoryUsage()
258
- const uptime = Date.now() - this.startTime
259
-
260
- // Calculate messages per second
261
- const now = Date.now()
262
- const timeDiff = (now - this.lastMessageTime) / 1000
263
- const messagesPerSecond = timeDiff > 0 ? this.messageCount / timeDiff : 0
264
-
265
- // Calculate average response time
266
- const avgResponseTime = this.responseTimes.length > 0
267
- ? this.responseTimes.reduce((a, b) => a + b, 0) / this.responseTimes.length
268
- : 0
269
-
270
- // Determine system health
271
- const systemHealth = this.calculateSystemHealth(registryStats, memUsage)
272
-
273
- // Update state with new metrics
274
- this.setState({
275
- totalComponents: registryStats.components,
276
- activeConnections: registryStats.connections,
277
- totalRooms: registryStats.rooms,
278
- messagesPerSecond: Math.round(messagesPerSecond * 100) / 100,
279
- averageResponseTime: Math.round(avgResponseTime * 100) / 100,
280
- componentsByType: this.getComponentsByType(),
281
- roomDetails: registryStats.roomDetails,
282
- memoryUsage: {
283
- used: Math.round(memUsage.heapUsed / 1024 / 1024 * 100) / 100, // MB
284
- total: Math.round(memUsage.heapTotal / 1024 / 1024 * 100) / 100, // MB
285
- percentage: Math.round((memUsage.heapUsed / memUsage.heapTotal) * 100)
286
- },
287
- systemHealth: {
288
- ...this.state.systemHealth,
289
- status: systemHealth.status,
290
- uptime: Math.round(uptime / 1000), // seconds
291
- },
292
- lastUpdated: Date.now()
293
- })
294
-
295
- // Push automatic update to frontend
296
- this.pushUpdate({
297
- type: 'METRICS_UPDATED',
298
- timestamp: Date.now(),
299
- metrics: {
300
- components: registryStats.components,
301
- connections: registryStats.connections,
302
- rooms: registryStats.rooms,
303
- messagesPerSecond: Math.round(messagesPerSecond * 100) / 100,
304
- memoryUsage: this.state.memoryUsage,
305
- systemHealth: this.state.systemHealth
306
- }
307
- })
308
-
309
- this.emit('METRICS_UPDATED', {
310
- timestamp: Date.now(),
311
- metrics: {
312
- components: registryStats.components,
313
- connections: registryStats.connections,
314
- rooms: registryStats.rooms,
315
- messagesPerSecond: Math.round(messagesPerSecond * 100) / 100
316
- }
317
- })
318
-
319
- } catch (error: any) {
320
- console.error('โŒ SystemMonitor: Error collecting metrics:', error.message)
321
- this.incrementErrorCount()
322
- }
323
- }
324
-
325
- // Calculate system health based on metrics
326
- private calculateSystemHealth(stats: any, memUsage: any) {
327
- let status: 'healthy' | 'warning' | 'critical' = 'healthy'
328
-
329
- // Check memory usage
330
- const memPercentage = (memUsage.heapUsed / memUsage.heapTotal) * 100
331
- if (memPercentage > 90) {
332
- status = 'critical'
333
- } else if (memPercentage > 75) {
334
- status = 'warning'
335
- }
336
-
337
- // Check connection count (arbitrary thresholds)
338
- if (stats.connections > 100) {
339
- status = status === 'critical' ? 'critical' : 'warning'
340
- }
341
-
342
- // Check error rate
343
- if (this.state.systemHealth.errors > 10) {
344
- status = 'critical'
345
- } else if (this.state.systemHealth.errors > 5) {
346
- status = status === 'critical' ? 'critical' : 'warning'
347
- }
348
-
349
- return { status }
350
- }
351
-
352
- // Get component breakdown by type
353
- private getComponentsByType(): Record<string, number> {
354
- // This would ideally be integrated with the registry
355
- // For now, return mock data based on known components
356
- return {
357
- 'UserProfile': 1,
358
- 'SidebarNavigation': 1,
359
- 'SystemMonitor': 1,
360
- 'Counter': 0,
361
- 'TestComponent': 0
362
- }
363
- }
364
-
365
- // Record a new connection event
366
- async recordConnection(data: { componentType: string; status: 'connected' | 'disconnected' | 'rehydrated' }) {
367
- const connectionEvent = {
368
- id: `conn-${Date.now()}-${Math.random().toString(36).substr(2, 6)}`,
369
- timestamp: Date.now(),
370
- componentType: data.componentType,
371
- status: data.status
372
- }
373
-
374
- // Add to recent connections (keep last 50)
375
- const recentConnections = [connectionEvent, ...this.state.recentConnections].slice(0, 50)
376
-
377
- this.setState({ recentConnections })
378
-
379
- this.emit('CONNECTION_RECORDED', connectionEvent)
380
-
381
- console.log(`๐Ÿ“Š SystemMonitor: Recorded ${data.status} for ${data.componentType}`)
382
- }
383
-
384
- // Record a new message event
385
- async recordMessage(data: { type: string; componentId: string; success: boolean; responseTime?: number }) {
386
- const messageEvent = {
387
- id: `msg-${Date.now()}-${Math.random().toString(36).substr(2, 6)}`,
388
- timestamp: Date.now(),
389
- type: data.type,
390
- componentId: data.componentId,
391
- success: data.success,
392
- responseTime: data.responseTime
393
- }
394
-
395
- // Add to recent messages (keep last 100)
396
- const recentMessages = [messageEvent, ...this.state.recentMessages].slice(0, 100)
397
-
398
- this.setState({ recentMessages })
399
-
400
- // Update response time tracking
401
- if (data.responseTime) {
402
- this.responseTimes.push(data.responseTime)
403
- if (this.responseTimes.length > 100) {
404
- this.responseTimes = this.responseTimes.slice(-100)
405
- }
406
- }
407
-
408
- // Update message count for rate calculation
409
- this.messageCount++
410
-
411
- this.emit('MESSAGE_RECORDED', messageEvent)
412
- }
413
-
414
- // Increment error count
415
- private incrementErrorCount() {
416
- this.setState({
417
- systemHealth: {
418
- ...this.state.systemHealth,
419
- errors: this.state.systemHealth.errors + 1
420
- }
421
- })
422
- }
423
-
424
- // Clear all recent activity
425
- async clearActivity() {
426
- this.setState({
427
- recentConnections: [],
428
- recentMessages: [],
429
- systemHealth: {
430
- ...this.state.systemHealth,
431
- errors: 0,
432
- warnings: 0
433
- }
434
- })
435
-
436
- // Reset counters
437
- this.messageCount = 0
438
- this.lastMessageTime = Date.now()
439
- this.responseTimes = []
440
-
441
- this.emit('ACTIVITY_CLEARED', {
442
- timestamp: Date.now()
443
- })
444
-
445
- console.log('๐Ÿงน SystemMonitor: Activity cleared')
446
- }
447
-
448
- // Get detailed system info
449
- async getSystemInfo() {
450
- const info = {
451
- nodeVersion: process.version,
452
- platform: process.platform,
453
- arch: process.arch,
454
- uptime: process.uptime(),
455
- pid: process.pid,
456
- execPath: process.execPath,
457
- cwd: process.cwd(),
458
- timestamp: Date.now()
459
- }
460
-
461
- this.emit('SYSTEM_INFO_REQUESTED', info)
462
-
463
- return info
464
- }
465
-
466
- // Force metrics refresh
467
- async refreshMetrics() {
468
- await this.collectMetrics()
469
-
470
- this.emit('METRICS_REFRESHED', {
471
- timestamp: Date.now()
472
- })
473
-
474
- console.log('๐Ÿ”„ SystemMonitor: Metrics refreshed manually')
475
- }
476
-
477
- // Emergency stop - stops everything immediately
478
- async emergencyStop() {
479
- console.log('๐Ÿšจ SystemMonitor: EMERGENCY STOP activated')
480
-
481
- // Stop all timers
482
- this.isActive = false
483
-
484
- if (this.refreshTimer) {
485
- clearInterval(this.refreshTimer)
486
- this.refreshTimer = null
487
- }
488
- if (this.pushTimer) {
489
- clearInterval(this.pushTimer)
490
- this.pushTimer = null
491
- }
492
-
493
- // Update state
494
- this.setState({
495
- autoRefresh: false
496
- })
497
-
498
- this.emit('EMERGENCY_STOP', {
499
- timestamp: Date.now(),
500
- reason: 'Manual emergency stop'
501
- })
502
-
503
- console.log('๐Ÿ›‘ SystemMonitor: All activities stopped via emergency stop')
504
- }
505
-
506
- // Push automatic updates to frontend
507
- private pushUpdate(data: any) {
508
- if (!this.isActive) {
509
- return // Stop all push updates if component is not active
510
- }
511
-
512
- try {
513
- // Force state synchronization to frontend
514
- this.emit('AUTO_UPDATE', data)
515
-
516
- // Also trigger a state change notification
517
- this.sendStateUpdate()
518
-
519
- console.log('๐Ÿ“ก SystemMonitor: Pushed automatic update to frontend', {
520
- type: data.type,
521
- timestamp: data.timestamp,
522
- connections: data.metrics?.connections || 0
523
- })
524
-
525
- } catch (error: any) {
526
- console.warn('โš ๏ธ SystemMonitor: Failed to push update to frontend:', error.message)
527
- }
528
- }
529
-
530
- // Send state update to all connected clients
531
- private sendStateUpdate() {
532
- try {
533
- // This will trigger the useHybridLiveComponent hook to update
534
- const stateUpdate = {
535
- componentId: this.id,
536
- state: this.state,
537
- timestamp: Date.now(),
538
- version: this.version || 1
539
- }
540
-
541
- // Emit state change to trigger frontend update
542
- this.emit('STATE_CHANGED', stateUpdate)
543
-
544
- } catch (error: any) {
545
- console.warn('โš ๏ธ SystemMonitor: Failed to send state update:', error.message)
546
- }
547
- }
548
-
549
- // Enhanced metrics collection with automatic frontend push
550
- async collectMetricsWithPush() {
551
- await this.collectMetrics()
552
-
553
- // Additional push with real-time data
554
- this.pushUpdate({
555
- type: 'REAL_TIME_METRICS',
556
- timestamp: Date.now(),
557
- realTimeData: {
558
- uptime: Math.round((Date.now() - this.startTime) / 1000),
559
- lastUpdated: this.state.lastUpdated,
560
- autoRefreshActive: this.state.autoRefresh,
561
- recentActivityCount: this.state.recentMessages.length + this.state.recentConnections.length
562
- }
563
- })
564
- }
565
-
566
- // Stop all activities (method to be called externally)
567
- async stopAllActivities() {
568
- this.isActive = false
569
-
570
- if (this.refreshTimer) {
571
- clearInterval(this.refreshTimer)
572
- this.refreshTimer = null
573
- }
574
- if (this.pushTimer) {
575
- clearInterval(this.pushTimer)
576
- this.pushTimer = null
577
- }
578
-
579
- console.log('๐Ÿ›‘ SystemMonitor: All activities stopped')
580
- }
581
-
582
- // Cleanup on destroy
583
- destroy() {
584
- this.isActive = false
585
-
586
- if (this.refreshTimer) {
587
- clearInterval(this.refreshTimer)
588
- }
589
- if (this.pushTimer) {
590
- clearInterval(this.pushTimer)
591
- }
592
- super.destroy()
593
- console.log('๐Ÿ’ฅ SystemMonitor: Destroyed and cleanup completed')
594
- }
595
- }