@jagilber-org/index-server 1.19.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.
- package/CHANGELOG.md +1218 -0
- package/CODE_OF_CONDUCT.md +49 -0
- package/CONTRIBUTING.md +75 -0
- package/LICENSE +21 -0
- package/README.md +523 -0
- package/SECURITY.md +50 -0
- package/dist/config/configUtils.d.ts +11 -0
- package/dist/config/configUtils.js +87 -0
- package/dist/config/dashboardConfig.d.ts +45 -0
- package/dist/config/dashboardConfig.js +63 -0
- package/dist/config/defaultValues.d.ts +61 -0
- package/dist/config/defaultValues.js +70 -0
- package/dist/config/dirConstants.d.ts +17 -0
- package/dist/config/dirConstants.js +28 -0
- package/dist/config/featureConfig.d.ts +61 -0
- package/dist/config/featureConfig.js +121 -0
- package/dist/config/runtimeConfig.d.ts +145 -0
- package/dist/config/runtimeConfig.js +334 -0
- package/dist/config/serverConfig.d.ts +90 -0
- package/dist/config/serverConfig.js +164 -0
- package/dist/dashboard/analytics/AnalyticsEngine.d.ts +142 -0
- package/dist/dashboard/analytics/AnalyticsEngine.js +373 -0
- package/dist/dashboard/analytics/BusinessIntelligence.d.ts +187 -0
- package/dist/dashboard/analytics/BusinessIntelligence.js +594 -0
- package/dist/dashboard/client/admin.html +2150 -0
- package/dist/dashboard/client/chunks/mermaid-layout-elk.esm.min/chunk-SP2CHFBE.mjs +1 -0
- package/dist/dashboard/client/chunks/mermaid-layout-elk.esm.min/render-T6MDALS3.mjs +27 -0
- package/dist/dashboard/client/css/admin.css +1466 -0
- package/dist/dashboard/client/js/admin.boot.js +359 -0
- package/dist/dashboard/client/js/admin.config.js +196 -0
- package/dist/dashboard/client/js/admin.embeddings.js +425 -0
- package/dist/dashboard/client/js/admin.graph.js +583 -0
- package/dist/dashboard/client/js/admin.instances.js +120 -0
- package/dist/dashboard/client/js/admin.instructions.js +552 -0
- package/dist/dashboard/client/js/admin.logs.js +113 -0
- package/dist/dashboard/client/js/admin.maintenance.js +354 -0
- package/dist/dashboard/client/js/admin.messaging.js +635 -0
- package/dist/dashboard/client/js/admin.monitor.js +181 -0
- package/dist/dashboard/client/js/admin.overview.js +221 -0
- package/dist/dashboard/client/js/admin.performance.js +61 -0
- package/dist/dashboard/client/js/admin.sessions.js +293 -0
- package/dist/dashboard/client/js/admin.sqlite.js +366 -0
- package/dist/dashboard/client/js/admin.utils.js +49 -0
- package/dist/dashboard/client/js/chart.umd.js +14 -0
- package/dist/dashboard/client/js/elk.bundled.js +6696 -0
- package/dist/dashboard/client/js/marked.umd.js +74 -0
- package/dist/dashboard/client/js/mermaid.min.js +3022 -0
- package/dist/dashboard/client/mermaid-layout-elk.esm.min.mjs +1 -0
- package/dist/dashboard/export/DataExporter.d.ts +169 -0
- package/dist/dashboard/export/DataExporter.js +737 -0
- package/dist/dashboard/export/exporters/csvExporter.d.ts +11 -0
- package/dist/dashboard/export/exporters/csvExporter.js +46 -0
- package/dist/dashboard/export/exporters/exportTypes.d.ts +89 -0
- package/dist/dashboard/export/exporters/exportTypes.js +5 -0
- package/dist/dashboard/export/exporters/jsonExporter.d.ts +7 -0
- package/dist/dashboard/export/exporters/jsonExporter.js +22 -0
- package/dist/dashboard/export/exporters/xmlExporter.d.ts +17 -0
- package/dist/dashboard/export/exporters/xmlExporter.js +175 -0
- package/dist/dashboard/integration/APIIntegration.d.ts +41 -0
- package/dist/dashboard/integration/APIIntegration.js +95 -0
- package/dist/dashboard/security/SecurityMonitor.d.ts +167 -0
- package/dist/dashboard/security/SecurityMonitor.js +559 -0
- package/dist/dashboard/server/AdminPanel.d.ts +183 -0
- package/dist/dashboard/server/AdminPanel.js +792 -0
- package/dist/dashboard/server/AdminPanelConfig.d.ts +42 -0
- package/dist/dashboard/server/AdminPanelConfig.js +80 -0
- package/dist/dashboard/server/AdminPanelState.d.ts +47 -0
- package/dist/dashboard/server/AdminPanelState.js +214 -0
- package/dist/dashboard/server/ApiRoutes.d.ts +17 -0
- package/dist/dashboard/server/ApiRoutes.js +149 -0
- package/dist/dashboard/server/DashboardServer.d.ts +49 -0
- package/dist/dashboard/server/DashboardServer.js +159 -0
- package/dist/dashboard/server/FileMetricsStorage.d.ts +49 -0
- package/dist/dashboard/server/FileMetricsStorage.js +195 -0
- package/dist/dashboard/server/HttpTransport.d.ts +23 -0
- package/dist/dashboard/server/HttpTransport.js +116 -0
- package/dist/dashboard/server/InstanceManager.d.ts +53 -0
- package/dist/dashboard/server/InstanceManager.js +284 -0
- package/dist/dashboard/server/KnowledgeStore.d.ts +35 -0
- package/dist/dashboard/server/KnowledgeStore.js +105 -0
- package/dist/dashboard/server/LeaderElection.d.ts +81 -0
- package/dist/dashboard/server/LeaderElection.js +268 -0
- package/dist/dashboard/server/MetricsCollector.d.ts +200 -0
- package/dist/dashboard/server/MetricsCollector.js +803 -0
- package/dist/dashboard/server/SessionPersistenceManager.d.ts +88 -0
- package/dist/dashboard/server/SessionPersistenceManager.js +457 -0
- package/dist/dashboard/server/ThinClient.d.ts +64 -0
- package/dist/dashboard/server/ThinClient.js +237 -0
- package/dist/dashboard/server/WebSocketManager.d.ts +161 -0
- package/dist/dashboard/server/WebSocketManager.js +463 -0
- package/dist/dashboard/server/httpLifecycle.d.ts +17 -0
- package/dist/dashboard/server/httpLifecycle.js +35 -0
- package/dist/dashboard/server/legacyDashboardHtml.d.ts +9 -0
- package/dist/dashboard/server/legacyDashboardHtml.js +618 -0
- package/dist/dashboard/server/legacyDashboardStyles.d.ts +5 -0
- package/dist/dashboard/server/legacyDashboardStyles.js +490 -0
- package/dist/dashboard/server/metricsAggregation.d.ts +252 -0
- package/dist/dashboard/server/metricsAggregation.js +206 -0
- package/dist/dashboard/server/metricsSerializer.d.ts +25 -0
- package/dist/dashboard/server/metricsSerializer.js +195 -0
- package/dist/dashboard/server/routes/admin.routes.d.ts +16 -0
- package/dist/dashboard/server/routes/admin.routes.js +596 -0
- package/dist/dashboard/server/routes/alerts.routes.d.ts +7 -0
- package/dist/dashboard/server/routes/alerts.routes.js +93 -0
- package/dist/dashboard/server/routes/api.feedback.routes.d.ts +73 -0
- package/dist/dashboard/server/routes/api.feedback.routes.js +171 -0
- package/dist/dashboard/server/routes/api.instructions.routes.d.ts +101 -0
- package/dist/dashboard/server/routes/api.instructions.routes.js +213 -0
- package/dist/dashboard/server/routes/api.usage.routes.d.ts +57 -0
- package/dist/dashboard/server/routes/api.usage.routes.js +374 -0
- package/dist/dashboard/server/routes/embeddings.routes.d.ts +6 -0
- package/dist/dashboard/server/routes/embeddings.routes.js +246 -0
- package/dist/dashboard/server/routes/graph.routes.d.ts +6 -0
- package/dist/dashboard/server/routes/graph.routes.js +280 -0
- package/dist/dashboard/server/routes/index.d.ts +38 -0
- package/dist/dashboard/server/routes/index.js +194 -0
- package/dist/dashboard/server/routes/instances.routes.d.ts +6 -0
- package/dist/dashboard/server/routes/instances.routes.js +35 -0
- package/dist/dashboard/server/routes/instructions.routes.d.ts +8 -0
- package/dist/dashboard/server/routes/instructions.routes.js +336 -0
- package/dist/dashboard/server/routes/knowledge.routes.d.ts +6 -0
- package/dist/dashboard/server/routes/knowledge.routes.js +82 -0
- package/dist/dashboard/server/routes/logs.routes.d.ts +6 -0
- package/dist/dashboard/server/routes/logs.routes.js +164 -0
- package/dist/dashboard/server/routes/messaging.routes.d.ts +16 -0
- package/dist/dashboard/server/routes/messaging.routes.js +293 -0
- package/dist/dashboard/server/routes/metrics.routes.d.ts +10 -0
- package/dist/dashboard/server/routes/metrics.routes.js +346 -0
- package/dist/dashboard/server/routes/scripts.routes.d.ts +9 -0
- package/dist/dashboard/server/routes/scripts.routes.js +84 -0
- package/dist/dashboard/server/routes/sqlite.routes.d.ts +9 -0
- package/dist/dashboard/server/routes/sqlite.routes.js +569 -0
- package/dist/dashboard/server/routes/status.routes.d.ts +7 -0
- package/dist/dashboard/server/routes/status.routes.js +183 -0
- package/dist/dashboard/server/routes/synthetic.routes.d.ts +7 -0
- package/dist/dashboard/server/routes/synthetic.routes.js +195 -0
- package/dist/dashboard/server/routes/tools.routes.d.ts +6 -0
- package/dist/dashboard/server/routes/tools.routes.js +46 -0
- package/dist/dashboard/server/routes/usage.routes.d.ts +6 -0
- package/dist/dashboard/server/routes/usage.routes.js +25 -0
- package/dist/dashboard/server/wsInit.d.ts +16 -0
- package/dist/dashboard/server/wsInit.js +35 -0
- package/dist/externalClientLib.d.ts +1 -0
- package/dist/externalClientLib.js +2 -0
- package/dist/minimal/index.d.ts +1 -0
- package/dist/minimal/index.js +140 -0
- package/dist/models/SessionPersistence.d.ts +115 -0
- package/dist/models/SessionPersistence.js +66 -0
- package/dist/models/instruction.d.ts +45 -0
- package/dist/models/instruction.js +2 -0
- package/dist/perf/benchmark.d.ts +1 -0
- package/dist/perf/benchmark.js +50 -0
- package/dist/portableClientWrapper.d.ts +1 -0
- package/dist/portableClientWrapper.js +2 -0
- package/dist/schemas/index.d.ts +128 -0
- package/dist/schemas/index.js +371 -0
- package/dist/scripts/runPerformanceBaseline.d.ts +1 -0
- package/dist/scripts/runPerformanceBaseline.js +17 -0
- package/dist/server/handshakeManager.d.ts +25 -0
- package/dist/server/handshakeManager.js +472 -0
- package/dist/server/index-server.d.ts +56 -0
- package/dist/server/index-server.js +822 -0
- package/dist/server/registry.d.ts +44 -0
- package/dist/server/registry.js +236 -0
- package/dist/server/sdkServer.d.ts +8 -0
- package/dist/server/sdkServer.js +299 -0
- package/dist/server/shutdownGuard.d.ts +41 -0
- package/dist/server/shutdownGuard.js +52 -0
- package/dist/server/thin-client.d.ts +22 -0
- package/dist/server/thin-client.js +111 -0
- package/dist/server/transport.d.ts +41 -0
- package/dist/server/transport.js +312 -0
- package/dist/server/transportFactory.d.ts +21 -0
- package/dist/server/transportFactory.js +429 -0
- package/dist/services/atomicFs.d.ts +22 -0
- package/dist/services/atomicFs.js +103 -0
- package/dist/services/auditLog.d.ts +38 -0
- package/dist/services/auditLog.js +142 -0
- package/dist/services/autoBackup.d.ts +14 -0
- package/dist/services/autoBackup.js +171 -0
- package/dist/services/autoSplit.d.ts +32 -0
- package/dist/services/autoSplit.js +113 -0
- package/dist/services/backupZip.d.ts +25 -0
- package/dist/services/backupZip.js +110 -0
- package/dist/services/bootstrapGating.d.ts +123 -0
- package/dist/services/bootstrapGating.js +221 -0
- package/dist/services/canonical.d.ts +23 -0
- package/dist/services/canonical.js +65 -0
- package/dist/services/categoryRules.d.ts +7 -0
- package/dist/services/categoryRules.js +37 -0
- package/dist/services/classificationService.d.ts +42 -0
- package/dist/services/classificationService.js +168 -0
- package/dist/services/embeddingService.d.ts +62 -0
- package/dist/services/embeddingService.js +259 -0
- package/dist/services/errors.d.ts +22 -0
- package/dist/services/errors.js +31 -0
- package/dist/services/featureFlags.d.ts +25 -0
- package/dist/services/featureFlags.js +89 -0
- package/dist/services/features.d.ts +13 -0
- package/dist/services/features.js +35 -0
- package/dist/services/handlers/instructions.add.d.ts +1 -0
- package/dist/services/handlers/instructions.add.js +496 -0
- package/dist/services/handlers/instructions.groom.d.ts +1 -0
- package/dist/services/handlers/instructions.groom.js +523 -0
- package/dist/services/handlers/instructions.import.d.ts +1 -0
- package/dist/services/handlers/instructions.import.js +173 -0
- package/dist/services/handlers/instructions.patch.d.ts +1 -0
- package/dist/services/handlers/instructions.patch.js +167 -0
- package/dist/services/handlers/instructions.query.d.ts +163 -0
- package/dist/services/handlers/instructions.query.js +522 -0
- package/dist/services/handlers/instructions.reload.d.ts +1 -0
- package/dist/services/handlers/instructions.reload.js +13 -0
- package/dist/services/handlers/instructions.remove.d.ts +1 -0
- package/dist/services/handlers/instructions.remove.js +118 -0
- package/dist/services/handlers/instructions.shared.d.ts +31 -0
- package/dist/services/handlers/instructions.shared.js +124 -0
- package/dist/services/handlers.activation.d.ts +1 -0
- package/dist/services/handlers.activation.js +203 -0
- package/dist/services/handlers.bootstrap.d.ts +1 -0
- package/dist/services/handlers.bootstrap.js +38 -0
- package/dist/services/handlers.dashboardConfig.d.ts +34 -0
- package/dist/services/handlers.dashboardConfig.js +108 -0
- package/dist/services/handlers.diagnostics.d.ts +1 -0
- package/dist/services/handlers.diagnostics.js +64 -0
- package/dist/services/handlers.feedback.d.ts +15 -0
- package/dist/services/handlers.feedback.js +378 -0
- package/dist/services/handlers.gates.d.ts +1 -0
- package/dist/services/handlers.gates.js +46 -0
- package/dist/services/handlers.graph.d.ts +53 -0
- package/dist/services/handlers.graph.js +231 -0
- package/dist/services/handlers.help.d.ts +1 -0
- package/dist/services/handlers.help.js +119 -0
- package/dist/services/handlers.instructionSchema.d.ts +1 -0
- package/dist/services/handlers.instructionSchema.js +227 -0
- package/dist/services/handlers.instructions.d.ts +8 -0
- package/dist/services/handlers.instructions.js +14 -0
- package/dist/services/handlers.instructionsDiagnostics.d.ts +1 -0
- package/dist/services/handlers.instructionsDiagnostics.js +14 -0
- package/dist/services/handlers.integrity.d.ts +1 -0
- package/dist/services/handlers.integrity.js +35 -0
- package/dist/services/handlers.manifest.d.ts +1 -0
- package/dist/services/handlers.manifest.js +24 -0
- package/dist/services/handlers.messaging.d.ts +12 -0
- package/dist/services/handlers.messaging.js +203 -0
- package/dist/services/handlers.metrics.d.ts +1 -0
- package/dist/services/handlers.metrics.js +43 -0
- package/dist/services/handlers.promote.d.ts +1 -0
- package/dist/services/handlers.promote.js +306 -0
- package/dist/services/handlers.prompt.d.ts +1 -0
- package/dist/services/handlers.prompt.js +7 -0
- package/dist/services/handlers.search.d.ts +69 -0
- package/dist/services/handlers.search.js +645 -0
- package/dist/services/handlers.testPrimitive.d.ts +1 -0
- package/dist/services/handlers.testPrimitive.js +5 -0
- package/dist/services/handlers.trace.d.ts +1 -0
- package/dist/services/handlers.trace.js +31 -0
- package/dist/services/handlers.usage.d.ts +1 -0
- package/dist/services/handlers.usage.js +11 -0
- package/dist/services/hotScore.d.ts +137 -0
- package/dist/services/hotScore.js +244 -0
- package/dist/services/indexContext.d.ts +117 -0
- package/dist/services/indexContext.js +968 -0
- package/dist/services/indexLoader.d.ts +44 -0
- package/dist/services/indexLoader.js +921 -0
- package/dist/services/indexRepository.d.ts +32 -0
- package/dist/services/indexRepository.js +71 -0
- package/dist/services/indexingService.d.ts +1 -0
- package/dist/services/indexingService.js +2 -0
- package/dist/services/instructions.dispatcher.d.ts +1 -0
- package/dist/services/instructions.dispatcher.js +231 -0
- package/dist/services/logPrefix.d.ts +1 -0
- package/dist/services/logPrefix.js +30 -0
- package/dist/services/logger.d.ts +52 -0
- package/dist/services/logger.js +268 -0
- package/dist/services/manifestManager.d.ts +82 -0
- package/dist/services/manifestManager.js +200 -0
- package/dist/services/messaging/agentMailbox.d.ts +60 -0
- package/dist/services/messaging/agentMailbox.js +353 -0
- package/dist/services/messaging/messagingPersistence.d.ts +20 -0
- package/dist/services/messaging/messagingPersistence.js +111 -0
- package/dist/services/messaging/messagingTypes.d.ts +150 -0
- package/dist/services/messaging/messagingTypes.js +66 -0
- package/dist/services/ownershipService.d.ts +1 -0
- package/dist/services/ownershipService.js +38 -0
- package/dist/services/performanceBaseline.d.ts +19 -0
- package/dist/services/performanceBaseline.js +210 -0
- package/dist/services/preflight.d.ts +12 -0
- package/dist/services/preflight.js +79 -0
- package/dist/services/promptReviewService.d.ts +44 -0
- package/dist/services/promptReviewService.js +101 -0
- package/dist/services/responseEnvelope.d.ts +6 -0
- package/dist/services/responseEnvelope.js +25 -0
- package/dist/services/seedBootstrap.d.ts +34 -0
- package/dist/services/seedBootstrap.js +427 -0
- package/dist/services/storage/factory.d.ts +17 -0
- package/dist/services/storage/factory.js +35 -0
- package/dist/services/storage/hashUtils.d.ts +11 -0
- package/dist/services/storage/hashUtils.js +35 -0
- package/dist/services/storage/index.d.ts +12 -0
- package/dist/services/storage/index.js +18 -0
- package/dist/services/storage/jsonFileStore.d.ts +32 -0
- package/dist/services/storage/jsonFileStore.js +241 -0
- package/dist/services/storage/migrationEngine.d.ts +35 -0
- package/dist/services/storage/migrationEngine.js +93 -0
- package/dist/services/storage/sqliteMessageStore.d.ts +53 -0
- package/dist/services/storage/sqliteMessageStore.js +146 -0
- package/dist/services/storage/sqliteSchema.d.ts +12 -0
- package/dist/services/storage/sqliteSchema.js +122 -0
- package/dist/services/storage/sqliteStore.d.ts +41 -0
- package/dist/services/storage/sqliteStore.js +339 -0
- package/dist/services/storage/sqliteUsageStore.d.ts +35 -0
- package/dist/services/storage/sqliteUsageStore.js +94 -0
- package/dist/services/storage/types.d.ts +171 -0
- package/dist/services/storage/types.js +12 -0
- package/dist/services/toolHandlers.d.ts +23 -0
- package/dist/services/toolHandlers.js +50 -0
- package/dist/services/toolRegistry.d.ts +20 -0
- package/dist/services/toolRegistry.js +490 -0
- package/dist/services/toolRegistry.zod.d.ts +10 -0
- package/dist/services/toolRegistry.zod.js +323 -0
- package/dist/services/tracing.d.ts +26 -0
- package/dist/services/tracing.js +260 -0
- package/dist/services/usageBuckets.d.ts +161 -0
- package/dist/services/usageBuckets.js +364 -0
- package/dist/services/validationService.d.ts +38 -0
- package/dist/services/validationService.js +125 -0
- package/dist/utils/BufferRing.d.ts +203 -0
- package/dist/utils/BufferRing.js +551 -0
- package/dist/utils/BufferRingExamples.d.ts +55 -0
- package/dist/utils/BufferRingExamples.js +188 -0
- package/dist/utils/envUtils.d.ts +42 -0
- package/dist/utils/envUtils.js +80 -0
- package/dist/utils/memoryMonitor.d.ts +83 -0
- package/dist/utils/memoryMonitor.js +275 -0
- package/dist/versioning/schemaVersion.d.ts +6 -0
- package/dist/versioning/schemaVersion.js +93 -0
- package/package.json +134 -0
- package/schemas/README.md +13 -0
- package/schemas/feedback-entry.schema.json +27 -0
- package/schemas/graph-export-v2.schema.json +60 -0
- package/schemas/index-server.code-schema.json +38477 -0
- package/schemas/instruction.schema.json +262 -0
- package/schemas/json-schema/SessionPersistence-persisted-admin-session.schema.json +54 -0
- package/schemas/json-schema/SessionPersistence-persisted-session-history-entry.schema.json +51 -0
- package/schemas/json-schema/SessionPersistence-persisted-web-socket-connection.schema.json +54 -0
- package/schemas/json-schema/SessionPersistence-session-persistence-config.schema.json +110 -0
- package/schemas/json-schema/SessionPersistence-session-persistence-data.schema.json +229 -0
- package/schemas/json-schema/SessionPersistence-session-persistence-manifest.schema.json +109 -0
- package/schemas/json-schema/SessionPersistence-session-persistence-metadata.schema.json +55 -0
- package/schemas/json-schema/instruction-audience-scope.schema.json +14 -0
- package/schemas/json-schema/instruction-content-type.schema.json +17 -0
- package/schemas/json-schema/instruction-instruction-entry.schema.json +206 -0
- package/schemas/json-schema/instruction-requirement-level.schema.json +16 -0
- package/schemas/manifest.json +78 -0
- package/schemas/manifest.schema.json +33 -0
- package/schemas/usage-batch.schema.json +16 -0
- package/schemas/usage-buckets.schema.json +30 -0
- package/schemas/usage-event.schema.json +17 -0
- package/scripts/copy-dashboard-assets.mjs +170 -0
- package/scripts/setup-hooks.cjs +28 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AdminPanelConfig — Configuration rendering and serialization logic.
|
|
3
|
+
*
|
|
4
|
+
* Owns the AdminConfig data structure and provides CRUD methods for
|
|
5
|
+
* reading and updating admin panel configuration.
|
|
6
|
+
*/
|
|
7
|
+
export interface AdminConfig {
|
|
8
|
+
serverSettings: {
|
|
9
|
+
maxConnections: number;
|
|
10
|
+
requestTimeout: number;
|
|
11
|
+
enableVerboseLogging: boolean;
|
|
12
|
+
enableMutation: boolean;
|
|
13
|
+
rateLimit: {
|
|
14
|
+
windowMs: number;
|
|
15
|
+
maxRequests: number;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
indexSettings: {
|
|
19
|
+
autoRefreshInterval: number;
|
|
20
|
+
cacheSize: number;
|
|
21
|
+
enableVersioning: boolean;
|
|
22
|
+
};
|
|
23
|
+
securitySettings: {
|
|
24
|
+
enableCors: boolean;
|
|
25
|
+
allowedOrigins: string[];
|
|
26
|
+
enableAuthentication: boolean;
|
|
27
|
+
sessionTimeout: number;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export declare class AdminPanelConfig {
|
|
31
|
+
private config;
|
|
32
|
+
constructor();
|
|
33
|
+
private loadDefaultConfig;
|
|
34
|
+
getAdminConfig(): AdminConfig;
|
|
35
|
+
updateAdminConfig(updates: Partial<AdminConfig>): {
|
|
36
|
+
success: boolean;
|
|
37
|
+
message: string;
|
|
38
|
+
};
|
|
39
|
+
private applyConfigChanges;
|
|
40
|
+
/** Session timeout in milliseconds — consumed by state management. */
|
|
41
|
+
get sessionTimeout(): number;
|
|
42
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* AdminPanelConfig — Configuration rendering and serialization logic.
|
|
4
|
+
*
|
|
5
|
+
* Owns the AdminConfig data structure and provides CRUD methods for
|
|
6
|
+
* reading and updating admin panel configuration.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.AdminPanelConfig = void 0;
|
|
10
|
+
const runtimeConfig_1 = require("../../config/runtimeConfig");
|
|
11
|
+
class AdminPanelConfig {
|
|
12
|
+
config;
|
|
13
|
+
constructor() {
|
|
14
|
+
this.config = this.loadDefaultConfig();
|
|
15
|
+
}
|
|
16
|
+
loadDefaultConfig() {
|
|
17
|
+
const runtimeConfig = (0, runtimeConfig_1.getRuntimeConfig)();
|
|
18
|
+
const serverHttp = runtimeConfig.dashboard.http;
|
|
19
|
+
return {
|
|
20
|
+
serverSettings: {
|
|
21
|
+
maxConnections: serverHttp?.maxConnections ?? 100,
|
|
22
|
+
requestTimeout: serverHttp?.requestTimeoutMs ?? 30000,
|
|
23
|
+
enableVerboseLogging: !!serverHttp?.verboseLogging,
|
|
24
|
+
enableMutation: runtimeConfig.mutation.enabled,
|
|
25
|
+
rateLimit: {
|
|
26
|
+
windowMs: 60000,
|
|
27
|
+
maxRequests: 100
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
indexSettings: {
|
|
31
|
+
autoRefreshInterval: 300000,
|
|
32
|
+
cacheSize: 1000,
|
|
33
|
+
enableVersioning: true
|
|
34
|
+
},
|
|
35
|
+
securitySettings: {
|
|
36
|
+
enableCors: false,
|
|
37
|
+
allowedOrigins: ['http://localhost', 'http://127.0.0.1', 'https://localhost', 'https://127.0.0.1'],
|
|
38
|
+
enableAuthentication: false,
|
|
39
|
+
sessionTimeout: 3600000
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
getAdminConfig() {
|
|
44
|
+
return JSON.parse(JSON.stringify(this.config));
|
|
45
|
+
}
|
|
46
|
+
updateAdminConfig(updates) {
|
|
47
|
+
try {
|
|
48
|
+
this.config = { ...this.config, ...updates };
|
|
49
|
+
this.applyConfigChanges(updates);
|
|
50
|
+
return { success: true, message: 'Configuration updated successfully' };
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
return {
|
|
54
|
+
success: false,
|
|
55
|
+
message: `Failed to update configuration: ${error instanceof Error ? error.message : String(error)}`
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
applyConfigChanges(updates) {
|
|
60
|
+
if (updates.serverSettings) {
|
|
61
|
+
let runtimeReloadNeeded = false;
|
|
62
|
+
if (updates.serverSettings.enableVerboseLogging !== undefined) {
|
|
63
|
+
process.env.INDEX_SERVER_VERBOSE_LOGGING = updates.serverSettings.enableVerboseLogging ? '1' : '0';
|
|
64
|
+
runtimeReloadNeeded = true;
|
|
65
|
+
}
|
|
66
|
+
if (updates.serverSettings.enableMutation !== undefined) {
|
|
67
|
+
process.env.INDEX_SERVER_MUTATION = updates.serverSettings.enableMutation ? '1' : '0';
|
|
68
|
+
runtimeReloadNeeded = true;
|
|
69
|
+
}
|
|
70
|
+
if (runtimeReloadNeeded) {
|
|
71
|
+
(0, runtimeConfig_1.reloadRuntimeConfig)();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** Session timeout in milliseconds — consumed by state management. */
|
|
76
|
+
get sessionTimeout() {
|
|
77
|
+
return this.config.securitySettings.sessionTimeout;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.AdminPanelConfig = AdminPanelConfig;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AdminPanelState — Session state management logic.
|
|
3
|
+
*
|
|
4
|
+
* Manages active admin sessions and session history, including
|
|
5
|
+
* persistence, creation, termination, and cleanup of expired sessions.
|
|
6
|
+
*/
|
|
7
|
+
export interface AdminSession {
|
|
8
|
+
id: string;
|
|
9
|
+
userId: string;
|
|
10
|
+
startTime: Date;
|
|
11
|
+
lastActivity: Date;
|
|
12
|
+
ipAddress: string;
|
|
13
|
+
userAgent: string;
|
|
14
|
+
permissions: string[];
|
|
15
|
+
}
|
|
16
|
+
export interface AdminSessionHistoryEntry {
|
|
17
|
+
id: string;
|
|
18
|
+
userId: string;
|
|
19
|
+
startTime: Date;
|
|
20
|
+
endTime?: Date;
|
|
21
|
+
ipAddress: string;
|
|
22
|
+
userAgent: string;
|
|
23
|
+
terminated?: boolean;
|
|
24
|
+
terminationReason?: string;
|
|
25
|
+
}
|
|
26
|
+
export declare class AdminPanelState {
|
|
27
|
+
readonly activeSessions: Map<string, AdminSession>;
|
|
28
|
+
private sessionHistory;
|
|
29
|
+
private sessionHistoryIndex;
|
|
30
|
+
private persistenceManager;
|
|
31
|
+
private get maxSessionHistory();
|
|
32
|
+
constructor();
|
|
33
|
+
initializePersistence(): Promise<void>;
|
|
34
|
+
persistSessionState(): Promise<void>;
|
|
35
|
+
getActiveSessions(sessionTimeout: number): AdminSession[];
|
|
36
|
+
createAdminSession(userId: string, ipAddress: string, userAgent: string): AdminSession;
|
|
37
|
+
terminateSession(sessionId: string): boolean;
|
|
38
|
+
cleanupExpiredSessions(sessionTimeout: number): void;
|
|
39
|
+
generateSessionId(): string;
|
|
40
|
+
getSessionHistory(limit?: number): AdminSessionHistoryEntry[];
|
|
41
|
+
clearSessionHistory(): Promise<{
|
|
42
|
+
success: boolean;
|
|
43
|
+
message: string;
|
|
44
|
+
clearedCount: number;
|
|
45
|
+
}>;
|
|
46
|
+
updateSessionActivity(sessionId: string): boolean;
|
|
47
|
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* AdminPanelState — Session state management logic.
|
|
4
|
+
*
|
|
5
|
+
* Manages active admin sessions and session history, including
|
|
6
|
+
* persistence, creation, termination, and cleanup of expired sessions.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.AdminPanelState = void 0;
|
|
10
|
+
const runtimeConfig_1 = require("../../config/runtimeConfig");
|
|
11
|
+
const SessionPersistenceManager_1 = require("./SessionPersistenceManager");
|
|
12
|
+
class AdminPanelState {
|
|
13
|
+
activeSessions = new Map();
|
|
14
|
+
sessionHistory = [];
|
|
15
|
+
sessionHistoryIndex = new Map();
|
|
16
|
+
persistenceManager;
|
|
17
|
+
get maxSessionHistory() {
|
|
18
|
+
const value = (0, runtimeConfig_1.getRuntimeConfig)().dashboard.admin.maxSessionHistory;
|
|
19
|
+
return Number.isFinite(value) ? value : 200;
|
|
20
|
+
}
|
|
21
|
+
constructor() {
|
|
22
|
+
this.persistenceManager = new SessionPersistenceManager_1.SessionPersistenceManager();
|
|
23
|
+
this.initializePersistence();
|
|
24
|
+
}
|
|
25
|
+
async initializePersistence() {
|
|
26
|
+
try {
|
|
27
|
+
const persistedData = await this.persistenceManager.loadData();
|
|
28
|
+
if (persistedData) {
|
|
29
|
+
this.activeSessions.clear();
|
|
30
|
+
persistedData.adminSessions.forEach(persistedSession => {
|
|
31
|
+
const adminSession = {
|
|
32
|
+
id: persistedSession.id,
|
|
33
|
+
userId: persistedSession.userId,
|
|
34
|
+
startTime: new Date(persistedSession.startTime),
|
|
35
|
+
lastActivity: new Date(persistedSession.lastActivity),
|
|
36
|
+
ipAddress: persistedSession.ipAddress,
|
|
37
|
+
userAgent: persistedSession.userAgent,
|
|
38
|
+
permissions: persistedSession.permissions
|
|
39
|
+
};
|
|
40
|
+
this.activeSessions.set(adminSession.id, adminSession);
|
|
41
|
+
});
|
|
42
|
+
this.sessionHistory = [];
|
|
43
|
+
this.sessionHistoryIndex.clear();
|
|
44
|
+
persistedData.sessionHistory.forEach(persistedEntry => {
|
|
45
|
+
const historyEntry = {
|
|
46
|
+
id: persistedEntry.id,
|
|
47
|
+
userId: persistedEntry.userId,
|
|
48
|
+
startTime: new Date(persistedEntry.startTime),
|
|
49
|
+
endTime: persistedEntry.endTime ? new Date(persistedEntry.endTime) : undefined,
|
|
50
|
+
ipAddress: persistedEntry.ipAddress,
|
|
51
|
+
userAgent: persistedEntry.userAgent,
|
|
52
|
+
terminated: persistedEntry.terminated,
|
|
53
|
+
terminationReason: persistedEntry.terminationReason
|
|
54
|
+
};
|
|
55
|
+
this.sessionHistory.push(historyEntry);
|
|
56
|
+
this.sessionHistoryIndex.set(historyEntry.id, historyEntry);
|
|
57
|
+
});
|
|
58
|
+
console.log(`Loaded ${this.activeSessions.size} active sessions and ${this.sessionHistory.length} history entries from persistence`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
console.error('Failed to initialize session persistence:', error);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async persistSessionState() {
|
|
66
|
+
try {
|
|
67
|
+
const adminSessions = Array.from(this.activeSessions.values()).map(session => ({
|
|
68
|
+
id: session.id,
|
|
69
|
+
userId: session.userId,
|
|
70
|
+
startTime: session.startTime.toISOString(),
|
|
71
|
+
lastActivity: session.lastActivity.toISOString(),
|
|
72
|
+
ipAddress: session.ipAddress,
|
|
73
|
+
userAgent: session.userAgent,
|
|
74
|
+
permissions: session.permissions,
|
|
75
|
+
persistedAt: new Date().toISOString(),
|
|
76
|
+
version: 1
|
|
77
|
+
}));
|
|
78
|
+
const sessionHistory = this.sessionHistory.map(entry => ({
|
|
79
|
+
id: entry.id,
|
|
80
|
+
userId: entry.userId,
|
|
81
|
+
startTime: entry.startTime.toISOString(),
|
|
82
|
+
endTime: entry.endTime?.toISOString(),
|
|
83
|
+
ipAddress: entry.ipAddress,
|
|
84
|
+
userAgent: entry.userAgent,
|
|
85
|
+
terminated: entry.terminated,
|
|
86
|
+
terminationReason: entry.terminationReason,
|
|
87
|
+
persistedAt: new Date().toISOString(),
|
|
88
|
+
version: 1
|
|
89
|
+
}));
|
|
90
|
+
const persistedData = {
|
|
91
|
+
adminSessions,
|
|
92
|
+
webSocketConnections: [],
|
|
93
|
+
sessionHistory,
|
|
94
|
+
metadata: {
|
|
95
|
+
lastPersisted: new Date().toISOString(),
|
|
96
|
+
version: 1,
|
|
97
|
+
totalSessions: adminSessions.length,
|
|
98
|
+
totalConnections: 0,
|
|
99
|
+
totalHistoryEntries: sessionHistory.length,
|
|
100
|
+
checksums: { sessions: '', connections: '', history: '' }
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
await this.persistenceManager.persistData(persistedData);
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
console.error('Failed to persist session state:', error);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
getActiveSessions(sessionTimeout) {
|
|
110
|
+
this.cleanupExpiredSessions(sessionTimeout);
|
|
111
|
+
return Array.from(this.activeSessions.values());
|
|
112
|
+
}
|
|
113
|
+
createAdminSession(userId, ipAddress, userAgent) {
|
|
114
|
+
const session = {
|
|
115
|
+
id: this.generateSessionId(),
|
|
116
|
+
userId,
|
|
117
|
+
startTime: new Date(),
|
|
118
|
+
lastActivity: new Date(),
|
|
119
|
+
ipAddress,
|
|
120
|
+
userAgent,
|
|
121
|
+
permissions: ['read', 'write', 'admin']
|
|
122
|
+
};
|
|
123
|
+
this.activeSessions.set(session.id, session);
|
|
124
|
+
const hist = {
|
|
125
|
+
id: session.id,
|
|
126
|
+
userId: session.userId,
|
|
127
|
+
startTime: session.startTime,
|
|
128
|
+
ipAddress: session.ipAddress,
|
|
129
|
+
userAgent: session.userAgent
|
|
130
|
+
};
|
|
131
|
+
this.sessionHistory.unshift(hist);
|
|
132
|
+
this.sessionHistoryIndex.set(hist.id, hist);
|
|
133
|
+
if (this.sessionHistory.length > this.maxSessionHistory) {
|
|
134
|
+
const removed = this.sessionHistory.pop();
|
|
135
|
+
if (removed)
|
|
136
|
+
this.sessionHistoryIndex.delete(removed.id);
|
|
137
|
+
}
|
|
138
|
+
this.persistSessionState().catch(error => {
|
|
139
|
+
console.error('Failed to persist session state after creation:', error);
|
|
140
|
+
});
|
|
141
|
+
return session;
|
|
142
|
+
}
|
|
143
|
+
terminateSession(sessionId) {
|
|
144
|
+
const existed = this.activeSessions.delete(sessionId);
|
|
145
|
+
if (existed) {
|
|
146
|
+
const hist = this.sessionHistoryIndex.get(sessionId);
|
|
147
|
+
if (hist && !hist.terminated) {
|
|
148
|
+
hist.endTime = new Date();
|
|
149
|
+
hist.terminated = true;
|
|
150
|
+
hist.terminationReason = 'manual';
|
|
151
|
+
}
|
|
152
|
+
this.persistSessionState().catch(error => {
|
|
153
|
+
console.error('Failed to persist session state after termination:', error);
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
return existed;
|
|
157
|
+
}
|
|
158
|
+
cleanupExpiredSessions(sessionTimeout) {
|
|
159
|
+
const now = new Date();
|
|
160
|
+
let hasChanges = false;
|
|
161
|
+
for (const [id, session] of this.activeSessions.entries()) {
|
|
162
|
+
if (now.getTime() - session.lastActivity.getTime() > sessionTimeout) {
|
|
163
|
+
this.activeSessions.delete(id);
|
|
164
|
+
const hist = this.sessionHistoryIndex.get(id);
|
|
165
|
+
if (hist && !hist.terminated) {
|
|
166
|
+
hist.endTime = new Date();
|
|
167
|
+
hist.terminated = true;
|
|
168
|
+
hist.terminationReason = 'expired';
|
|
169
|
+
}
|
|
170
|
+
hasChanges = true;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (hasChanges) {
|
|
174
|
+
this.persistSessionState().catch(error => {
|
|
175
|
+
console.error('Failed to persist session state after cleanup:', error);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
generateSessionId() {
|
|
180
|
+
return `admin_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
181
|
+
}
|
|
182
|
+
getSessionHistory(limit) {
|
|
183
|
+
const slice = typeof limit === 'number' ? this.sessionHistory.slice(0, Math.max(0, limit)) : this.sessionHistory;
|
|
184
|
+
return slice.map(h => ({ ...h }));
|
|
185
|
+
}
|
|
186
|
+
async clearSessionHistory() {
|
|
187
|
+
try {
|
|
188
|
+
const clearedCount = this.sessionHistory.length;
|
|
189
|
+
this.sessionHistory = [];
|
|
190
|
+
this.sessionHistoryIndex.clear();
|
|
191
|
+
await this.persistSessionState();
|
|
192
|
+
return { success: true, message: `Successfully cleared ${clearedCount} session history entries`, clearedCount };
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
return {
|
|
196
|
+
success: false,
|
|
197
|
+
message: `Failed to clear session history: ${error instanceof Error ? error.message : String(error)}`,
|
|
198
|
+
clearedCount: 0
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
updateSessionActivity(sessionId) {
|
|
203
|
+
const session = this.activeSessions.get(sessionId);
|
|
204
|
+
if (session) {
|
|
205
|
+
session.lastActivity = new Date();
|
|
206
|
+
this.persistSessionState().catch(error => {
|
|
207
|
+
console.error('Failed to persist session activity update:', error);
|
|
208
|
+
});
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
exports.AdminPanelState = AdminPanelState;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ApiRoutes - Dashboard REST API Orchestrator
|
|
3
|
+
*
|
|
4
|
+
* Thin composition layer that mounts route modules from ./routes/ and applies
|
|
5
|
+
* shared middleware (CORS, JSON parsing, HTTP metrics instrumentation, error
|
|
6
|
+
* handling). Individual route handlers live in their own focused modules.
|
|
7
|
+
*/
|
|
8
|
+
import { Router } from 'express';
|
|
9
|
+
export interface ApiRoutesOptions {
|
|
10
|
+
enableCors?: boolean;
|
|
11
|
+
rateLimit?: {
|
|
12
|
+
windowMs: number;
|
|
13
|
+
max: number;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export declare function createApiRoutes(options?: ApiRoutesOptions): Router;
|
|
17
|
+
export default createApiRoutes;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ApiRoutes - Dashboard REST API Orchestrator
|
|
4
|
+
*
|
|
5
|
+
* Thin composition layer that mounts route modules from ./routes/ and applies
|
|
6
|
+
* shared middleware (CORS, JSON parsing, HTTP metrics instrumentation, error
|
|
7
|
+
* handling). Individual route handlers live in their own focused modules.
|
|
8
|
+
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(o, k2, desc);
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
26
|
+
var ownKeys = function(o) {
|
|
27
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
28
|
+
var ar = [];
|
|
29
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
30
|
+
return ar;
|
|
31
|
+
};
|
|
32
|
+
return ownKeys(o);
|
|
33
|
+
};
|
|
34
|
+
return function (mod) {
|
|
35
|
+
if (mod && mod.__esModule) return mod;
|
|
36
|
+
var result = {};
|
|
37
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
38
|
+
__setModuleDefault(result, mod);
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
})();
|
|
42
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
+
exports.createApiRoutes = createApiRoutes;
|
|
44
|
+
const express_1 = __importStar(require("express"));
|
|
45
|
+
const MetricsCollector_js_1 = require("./MetricsCollector.js");
|
|
46
|
+
const auditLog_1 = require("../../services/auditLog");
|
|
47
|
+
const runtimeConfig_js_1 = require("../../config/runtimeConfig.js");
|
|
48
|
+
const index_js_1 = require("./routes/index.js");
|
|
49
|
+
function createApiRoutes(options = {}) {
|
|
50
|
+
const router = (0, express_1.Router)();
|
|
51
|
+
const metricsCollector = (0, MetricsCollector_js_1.getMetricsCollector)();
|
|
52
|
+
// CORS middleware (if enabled)
|
|
53
|
+
if (options.enableCors) {
|
|
54
|
+
router.use((req, res, next) => {
|
|
55
|
+
const origin = req.headers.origin;
|
|
56
|
+
if (origin && /^https?:\/\/(localhost|127\.0\.0\.1)(:\d+)?$/.test(origin)) {
|
|
57
|
+
res.header('Access-Control-Allow-Origin', origin);
|
|
58
|
+
}
|
|
59
|
+
res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
|
|
60
|
+
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
61
|
+
next();
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
// JSON middleware
|
|
65
|
+
router.use(express_1.default.json());
|
|
66
|
+
// --- HTTP Metrics Instrumentation ---------------------------------------
|
|
67
|
+
try {
|
|
68
|
+
const enableHttpMetrics = (0, runtimeConfig_js_1.getRuntimeConfig)().dashboard.http.enableHttpMetrics;
|
|
69
|
+
if (enableHttpMetrics) {
|
|
70
|
+
const normalizeRoute = (req) => {
|
|
71
|
+
if (req.route?.path)
|
|
72
|
+
return req.route.path;
|
|
73
|
+
return req.path
|
|
74
|
+
.replace(/\/[0-9a-f]{8,}/gi, '/:id')
|
|
75
|
+
.replace(/\/\d+/g, '/:id');
|
|
76
|
+
};
|
|
77
|
+
router.use((req, res, next) => {
|
|
78
|
+
const startNs = typeof process.hrtime === 'function' ? process.hrtime.bigint() : BigInt(Date.now()) * 1000000n;
|
|
79
|
+
res.on('finish', () => {
|
|
80
|
+
try {
|
|
81
|
+
const endNs = typeof process.hrtime === 'function' ? process.hrtime.bigint() : BigInt(Date.now()) * 1000000n;
|
|
82
|
+
const ms = Number(endNs - startNs) / 1_000_000;
|
|
83
|
+
const success = res.statusCode < 500;
|
|
84
|
+
const route = normalizeRoute(req);
|
|
85
|
+
const toolId = `http/${req.method} ${route}`;
|
|
86
|
+
metricsCollector.recordToolCall(toolId, success, ms, success ? undefined : `http_${res.statusCode}`);
|
|
87
|
+
}
|
|
88
|
+
catch { /* never block response path */ }
|
|
89
|
+
});
|
|
90
|
+
next();
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch { /* ignore instrumentation failures */ }
|
|
95
|
+
// -------------------------------------------------------------------------
|
|
96
|
+
// --- HTTP Audit Logging -------------------------------------------------
|
|
97
|
+
// Logs every HTTP request to the audit trail with client IP, method, route,
|
|
98
|
+
// status code, and duration. Fires on response finish (non-blocking).
|
|
99
|
+
router.use((req, res, next) => {
|
|
100
|
+
const startNs = typeof process.hrtime === 'function' ? process.hrtime.bigint() : BigInt(Date.now()) * 1000000n;
|
|
101
|
+
res.on('finish', () => {
|
|
102
|
+
try {
|
|
103
|
+
const endNs = typeof process.hrtime === 'function' ? process.hrtime.bigint() : BigInt(Date.now()) * 1000000n;
|
|
104
|
+
const ms = Number(endNs - startNs) / 1_000_000;
|
|
105
|
+
const route = req.route?.path ?? req.path;
|
|
106
|
+
const clientIp = req.ip || req.socket?.remoteAddress;
|
|
107
|
+
const userAgent = req.get('user-agent');
|
|
108
|
+
(0, auditLog_1.logHttpAudit)(req.method, route, res.statusCode, ms, clientIp, userAgent);
|
|
109
|
+
}
|
|
110
|
+
catch { /* never block response path */ }
|
|
111
|
+
});
|
|
112
|
+
next();
|
|
113
|
+
});
|
|
114
|
+
// Cache-control: API responses should not be cached (pen test I2 fix)
|
|
115
|
+
router.use((_req, res, next) => {
|
|
116
|
+
res.header('Cache-Control', 'no-store, no-cache, must-revalidate, private');
|
|
117
|
+
res.header('Pragma', 'no-cache');
|
|
118
|
+
next();
|
|
119
|
+
});
|
|
120
|
+
// -------------------------------------------------------------------------
|
|
121
|
+
// Mount route modules
|
|
122
|
+
router.use((0, index_js_1.createStatusRoutes)(metricsCollector));
|
|
123
|
+
router.use((0, index_js_1.createMetricsRoutes)(metricsCollector));
|
|
124
|
+
router.use((0, index_js_1.createAdminRoutes)(metricsCollector));
|
|
125
|
+
router.use((0, index_js_1.createGraphRoutes)());
|
|
126
|
+
router.use((0, index_js_1.createInstructionsRoutes)());
|
|
127
|
+
router.use((0, index_js_1.createKnowledgeRoutes)());
|
|
128
|
+
router.use((0, index_js_1.createAlertsRoutes)(metricsCollector));
|
|
129
|
+
router.use((0, index_js_1.createLogsRoutes)());
|
|
130
|
+
router.use((0, index_js_1.createSyntheticRoutes)(metricsCollector));
|
|
131
|
+
router.use((0, index_js_1.createInstancesRoutes)());
|
|
132
|
+
router.use((0, index_js_1.createToolsRoutes)());
|
|
133
|
+
router.use((0, index_js_1.createEmbeddingsRoutes)());
|
|
134
|
+
router.use((0, index_js_1.createUsageRoutes)());
|
|
135
|
+
router.use((0, index_js_1.createScriptsRoutes)());
|
|
136
|
+
router.use((0, index_js_1.createMessagingRoutes)());
|
|
137
|
+
router.use((0, index_js_1.createSqliteRoutes)());
|
|
138
|
+
// Error handling middleware
|
|
139
|
+
router.use((error, _req, res, _next) => {
|
|
140
|
+
console.error('[API] Unhandled error:', error);
|
|
141
|
+
res.status(500).json({
|
|
142
|
+
error: 'Internal server error',
|
|
143
|
+
message: error.message,
|
|
144
|
+
timestamp: Date.now(),
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
return router;
|
|
148
|
+
}
|
|
149
|
+
exports.default = createApiRoutes;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DashboardServer - Enhanced Phase 2 Dashboard with Real-time Features
|
|
3
|
+
*
|
|
4
|
+
* Coordinator class that wires together:
|
|
5
|
+
* - Express middleware and routes (via mountDashboardRoutes)
|
|
6
|
+
* - HTTP/HTTPS server lifecycle (via httpLifecycle)
|
|
7
|
+
* - WebSocket initialization and metrics broadcast (via wsInit)
|
|
8
|
+
*/
|
|
9
|
+
import { TlsOptions } from './httpLifecycle.js';
|
|
10
|
+
export interface DashboardServerOptions {
|
|
11
|
+
host?: string;
|
|
12
|
+
port?: number;
|
|
13
|
+
maxPortTries?: number;
|
|
14
|
+
enableWebSockets?: boolean;
|
|
15
|
+
enableCors?: boolean;
|
|
16
|
+
/** Interval (ms) for broadcasting metrics_update messages over WebSocket (default 5000). */
|
|
17
|
+
metricsBroadcastIntervalMs?: number;
|
|
18
|
+
/** TLS certificate and key for HTTPS. When provided the dashboard serves over HTTPS/WSS. */
|
|
19
|
+
tls?: TlsOptions;
|
|
20
|
+
/** Enable the Graph visualization tab (loads ~4.5MB of mermaid+elkjs). Default false. */
|
|
21
|
+
graphEnabled?: boolean;
|
|
22
|
+
}
|
|
23
|
+
interface ServerInfo {
|
|
24
|
+
port: number;
|
|
25
|
+
host: string;
|
|
26
|
+
url: string;
|
|
27
|
+
}
|
|
28
|
+
export declare class DashboardServer {
|
|
29
|
+
private app;
|
|
30
|
+
private server;
|
|
31
|
+
private metricsCollector;
|
|
32
|
+
private webSocketManager;
|
|
33
|
+
private metricsBroadcastTimer;
|
|
34
|
+
private options;
|
|
35
|
+
private get tlsEnabled();
|
|
36
|
+
private get httpProtocol();
|
|
37
|
+
private get wsProtocol();
|
|
38
|
+
constructor(options?: DashboardServerOptions);
|
|
39
|
+
start(): Promise<{
|
|
40
|
+
url: string;
|
|
41
|
+
port: number;
|
|
42
|
+
close: () => void;
|
|
43
|
+
}>;
|
|
44
|
+
stop(): Promise<void>;
|
|
45
|
+
getServerInfo(): ServerInfo | null;
|
|
46
|
+
private setupMiddleware;
|
|
47
|
+
}
|
|
48
|
+
export declare function createDashboardServer(options?: DashboardServerOptions): DashboardServer;
|
|
49
|
+
export default createDashboardServer;
|