@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,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Status & Health Routes
|
|
4
|
+
* Routes: GET /status, GET /health, GET /system/health, GET /system/resources
|
|
5
|
+
*/
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.createStatusRoutes = createStatusRoutes;
|
|
11
|
+
const express_1 = require("express");
|
|
12
|
+
const fs_1 = __importDefault(require("fs"));
|
|
13
|
+
const path_1 = __importDefault(require("path"));
|
|
14
|
+
const v8_1 = __importDefault(require("v8"));
|
|
15
|
+
const runtimeConfig_js_1 = require("../../../config/runtimeConfig.js");
|
|
16
|
+
/** Derive short git commit (best-effort; never throws) */
|
|
17
|
+
function getGitCommit() {
|
|
18
|
+
try {
|
|
19
|
+
const head = path_1.default.join(process.cwd(), '.git', 'HEAD');
|
|
20
|
+
if (!fs_1.default.existsSync(head))
|
|
21
|
+
return null;
|
|
22
|
+
let ref = fs_1.default.readFileSync(head, 'utf8').trim();
|
|
23
|
+
if (ref.startsWith('ref:')) {
|
|
24
|
+
const refPath = path_1.default.join(process.cwd(), '.git', ref.split(' ')[1]);
|
|
25
|
+
if (fs_1.default.existsSync(refPath)) {
|
|
26
|
+
ref = fs_1.default.readFileSync(refPath, 'utf8').trim();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return ref.substring(0, 12);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** Approximate build time via dist/server/index-server.js mtime (falls back to null) */
|
|
36
|
+
function getBuildTime() {
|
|
37
|
+
try {
|
|
38
|
+
const candidate = path_1.default.join(process.cwd(), 'dist', 'server', 'index-server.js');
|
|
39
|
+
if (fs_1.default.existsSync(candidate)) {
|
|
40
|
+
const stat = fs_1.default.statSync(candidate);
|
|
41
|
+
return new Date(stat.mtimeMs).toISOString();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch { /* ignore */ }
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
function createStatusRoutes(metricsCollector) {
|
|
48
|
+
const router = (0, express_1.Router)();
|
|
49
|
+
/**
|
|
50
|
+
* GET /api/status - Server status and basic info
|
|
51
|
+
*/
|
|
52
|
+
router.get('/status', (_req, res) => {
|
|
53
|
+
try {
|
|
54
|
+
const snapshot = metricsCollector.getCurrentSnapshot();
|
|
55
|
+
const git = getGitCommit();
|
|
56
|
+
const buildTime = getBuildTime();
|
|
57
|
+
// Prevent stale caching of build/version metadata in browsers / proxies
|
|
58
|
+
res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate');
|
|
59
|
+
res.setHeader('Pragma', 'no-cache');
|
|
60
|
+
res.setHeader('Expires', '0');
|
|
61
|
+
res.json({
|
|
62
|
+
status: 'online',
|
|
63
|
+
version: snapshot.server.version,
|
|
64
|
+
build: git || undefined,
|
|
65
|
+
buildTime: buildTime || undefined,
|
|
66
|
+
uptime: snapshot.server.uptime,
|
|
67
|
+
startTime: snapshot.server.startTime,
|
|
68
|
+
timestamp: Date.now(),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
console.error('[API] Status error:', error);
|
|
73
|
+
res.status(500).json({
|
|
74
|
+
error: 'Failed to get server status',
|
|
75
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
/**
|
|
80
|
+
* GET /api/health - Health check endpoint
|
|
81
|
+
*/
|
|
82
|
+
router.get('/health', (_req, res) => {
|
|
83
|
+
try {
|
|
84
|
+
const snapshot = metricsCollector.getCurrentSnapshot();
|
|
85
|
+
const memUsage = snapshot.server.memoryUsage;
|
|
86
|
+
// Thresholds (configurable via runtime configuration)
|
|
87
|
+
const healthConfig = (0, runtimeConfig_js_1.getRuntimeConfig)().metrics.health;
|
|
88
|
+
const memoryThreshold = healthConfig.memoryThreshold;
|
|
89
|
+
const errorRateThreshold = healthConfig.errorRateThreshold;
|
|
90
|
+
const minUptimeMs = healthConfig.minUptimeMs;
|
|
91
|
+
// Simple health indicators (boolean flags)
|
|
92
|
+
// Use V8 heap_size_limit (not heapTotal) for memory ratio -- V8 keeps
|
|
93
|
+
// heapTotal only slightly above heapUsed, so heapUsed/heapTotal is
|
|
94
|
+
// almost always >85% and would false-alarm on default thresholds.
|
|
95
|
+
const heapLimit = v8_1.default.getHeapStatistics().heap_size_limit || memUsage.heapTotal;
|
|
96
|
+
const isHealthy = {
|
|
97
|
+
uptime: snapshot.server.uptime >= minUptimeMs,
|
|
98
|
+
memory: (memUsage.heapUsed / Math.max(1, heapLimit)) < memoryThreshold,
|
|
99
|
+
errors: snapshot.performance.errorRate < errorRateThreshold,
|
|
100
|
+
};
|
|
101
|
+
const failingChecks = Object.entries(isHealthy)
|
|
102
|
+
.filter(([, ok]) => !ok)
|
|
103
|
+
.map(([k]) => k);
|
|
104
|
+
const overallHealth = failingChecks.length === 0;
|
|
105
|
+
res.status(overallHealth ? 200 : 503).json({
|
|
106
|
+
status: overallHealth ? 'healthy' : 'degraded',
|
|
107
|
+
checks: isHealthy,
|
|
108
|
+
failingChecks,
|
|
109
|
+
thresholds: {
|
|
110
|
+
memoryRatio: memoryThreshold,
|
|
111
|
+
errorRatePercent: errorRateThreshold,
|
|
112
|
+
minUptimeMs
|
|
113
|
+
},
|
|
114
|
+
metrics: {
|
|
115
|
+
uptimeMs: snapshot.server.uptime,
|
|
116
|
+
memory: {
|
|
117
|
+
heapUsed: memUsage.heapUsed,
|
|
118
|
+
heapTotal: memUsage.heapTotal,
|
|
119
|
+
heapLimit: v8_1.default.getHeapStatistics().heap_size_limit,
|
|
120
|
+
ratio: memUsage.heapTotal ? memUsage.heapUsed / (v8_1.default.getHeapStatistics().heap_size_limit || memUsage.heapTotal) : 0
|
|
121
|
+
},
|
|
122
|
+
errorRate: snapshot.performance.errorRate
|
|
123
|
+
},
|
|
124
|
+
timestamp: Date.now(),
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
console.error('[API] Health check error:', error);
|
|
129
|
+
res.status(500).json({
|
|
130
|
+
status: 'error',
|
|
131
|
+
error: 'Health check failed',
|
|
132
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
133
|
+
timestamp: Date.now(),
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
/**
|
|
138
|
+
* GET /api/system/health - Advanced system health metrics
|
|
139
|
+
*/
|
|
140
|
+
router.get('/system/health', (_req, res) => {
|
|
141
|
+
try {
|
|
142
|
+
const systemHealth = metricsCollector.getSystemHealth();
|
|
143
|
+
res.json({
|
|
144
|
+
success: true,
|
|
145
|
+
data: systemHealth,
|
|
146
|
+
timestamp: Date.now()
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
console.error('[API] System health error:', error);
|
|
151
|
+
res.status(500).json({
|
|
152
|
+
error: 'Failed to get system health',
|
|
153
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
/**
|
|
158
|
+
* GET /api/system/resources - CPU & memory sample history (for long-term monitoring UI)
|
|
159
|
+
* query params: limit (number of most recent samples)
|
|
160
|
+
*/
|
|
161
|
+
router.get('/system/resources', (req, res) => {
|
|
162
|
+
try {
|
|
163
|
+
const limit = req.query.limit ? parseInt(req.query.limit, 10) : 200;
|
|
164
|
+
const history = metricsCollector.getResourceHistory(limit);
|
|
165
|
+
res.json({
|
|
166
|
+
success: true,
|
|
167
|
+
data: history,
|
|
168
|
+
limit,
|
|
169
|
+
sampleCount: history.samples.length,
|
|
170
|
+
timestamp: Date.now()
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
console.error('[API] System resources error:', error);
|
|
175
|
+
res.status(500).json({
|
|
176
|
+
success: false,
|
|
177
|
+
error: 'Failed to get system resource history',
|
|
178
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
return router;
|
|
183
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Synthetic Activity Routes
|
|
3
|
+
* Routes: POST /admin/synthetic/activity, GET /admin/synthetic/status
|
|
4
|
+
*/
|
|
5
|
+
import { Router } from 'express';
|
|
6
|
+
import { MetricsCollector } from '../MetricsCollector.js';
|
|
7
|
+
export declare function createSyntheticRoutes(_metricsCollector: MetricsCollector): Router;
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Synthetic Activity Routes
|
|
4
|
+
* Routes: POST /admin/synthetic/activity, GET /admin/synthetic/status
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.createSyntheticRoutes = createSyntheticRoutes;
|
|
8
|
+
const express_1 = require("express");
|
|
9
|
+
const registry_js_1 = require("../../../server/registry.js");
|
|
10
|
+
const WebSocketManager_js_1 = require("../WebSocketManager.js");
|
|
11
|
+
function createSyntheticRoutes(_metricsCollector) {
|
|
12
|
+
const router = (0, express_1.Router)();
|
|
13
|
+
// Module-private state
|
|
14
|
+
let syntheticActiveRequests = 0;
|
|
15
|
+
let lastSyntheticSummary = null;
|
|
16
|
+
let lastSyntheticRunId = null;
|
|
17
|
+
/**
|
|
18
|
+
* POST /api/admin/synthetic/activity - Generate synthetic tool activity to exercise metrics
|
|
19
|
+
* body: { iterations?: number, concurrency?: number }
|
|
20
|
+
*/
|
|
21
|
+
router.post('/admin/synthetic/activity', async (req, res) => {
|
|
22
|
+
try {
|
|
23
|
+
const iterations = Math.min(Math.max(parseInt(req.body.iterations || '10', 10), 1), 500);
|
|
24
|
+
const concurrency = Math.min(Math.max(parseInt(req.body.concurrency || '2', 10), 1), 25);
|
|
25
|
+
const start = Date.now();
|
|
26
|
+
const runId = `${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
|
|
27
|
+
const wantTrace = req.query.trace === '1' || req.body?.trace === true || req.query.debug === '1' || req.body?.debug === true;
|
|
28
|
+
const wantStream = wantTrace && (req.query.stream === '1' || req.body?.stream === true);
|
|
29
|
+
// Whitelist of safe, read-only or idempotent methods + minimal params
|
|
30
|
+
const PARAM_MAP = {
|
|
31
|
+
'health_check': {},
|
|
32
|
+
'metrics_snapshot': {},
|
|
33
|
+
'meta_tools': {},
|
|
34
|
+
'gates_evaluate': {},
|
|
35
|
+
'index_dispatch:add': { action: 'add', entry: { id: `synthetic-${runId}`, title: 'Synthetic Instruction', body: 'Temporary synthetic entry', audience: 'all', requirement: 'optional', priority: 'low', categories: ['synthetic'], owner: 'synthetic' }, overwrite: true, lax: true },
|
|
36
|
+
'index_dispatch:get': { action: 'get', id: `synthetic-${runId}` },
|
|
37
|
+
'index_dispatch:list': { action: 'list' },
|
|
38
|
+
'index_dispatch:query': { action: 'query', keyword: 'Synthetic', categoriesAll: [], requirement: undefined },
|
|
39
|
+
'index_dispatch:update': { action: 'add', entry: { id: `synthetic-${runId}`, title: 'Synthetic Instruction Updated', body: 'Updated body', audience: 'all', requirement: 'optional', priority: 'medium', categories: ['synthetic', 'updated'], owner: 'synthetic' }, overwrite: true, lax: true },
|
|
40
|
+
'index_dispatch:remove': { action: 'remove', id: `synthetic-${runId}` },
|
|
41
|
+
'usage_track': { id: 'synthetic.activity' }
|
|
42
|
+
};
|
|
43
|
+
const allRegistered = (0, registry_js_1.listRegisteredMethods)();
|
|
44
|
+
const expandedParamEntries = Object.entries(PARAM_MAP).map(([k, v]) => {
|
|
45
|
+
if (k.startsWith('index_dispatch:'))
|
|
46
|
+
return ['index_dispatch', v];
|
|
47
|
+
return [k, v];
|
|
48
|
+
});
|
|
49
|
+
const available = allRegistered.filter(m => expandedParamEntries.some(([name]) => name === m));
|
|
50
|
+
if (!available.length) {
|
|
51
|
+
return res.status(503).json({
|
|
52
|
+
success: false,
|
|
53
|
+
error: 'No safe tools available for synthetic activity',
|
|
54
|
+
registeredCount: allRegistered.length,
|
|
55
|
+
registeredSample: allRegistered.slice(0, 15),
|
|
56
|
+
expectedAnyOf: Object.keys(PARAM_MAP),
|
|
57
|
+
hint: 'If this persists, ensure handlers.* imports occur before dashboard start (see server/index.ts import order).',
|
|
58
|
+
timestamp: Date.now()
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
let executed = 0;
|
|
62
|
+
let errors = 0;
|
|
63
|
+
let missingHandlerCount = 0;
|
|
64
|
+
const traces = [];
|
|
65
|
+
let seq = 0;
|
|
66
|
+
const wsManager = wantStream ? (0, WebSocketManager_js_1.getWebSocketManager)() : null;
|
|
67
|
+
const runOne = async () => {
|
|
68
|
+
const picked = expandedParamEntries[Math.floor(Math.random() * expandedParamEntries.length)];
|
|
69
|
+
const method = picked[0];
|
|
70
|
+
if (!available.includes(method))
|
|
71
|
+
return;
|
|
72
|
+
const payload = picked[1];
|
|
73
|
+
const handler = (0, registry_js_1.getLocalHandler)(method);
|
|
74
|
+
const started = Date.now();
|
|
75
|
+
try {
|
|
76
|
+
syntheticActiveRequests++;
|
|
77
|
+
if (handler) {
|
|
78
|
+
await Promise.resolve(handler(payload));
|
|
79
|
+
const ended = Date.now();
|
|
80
|
+
if (wantTrace && traces.length < iterations)
|
|
81
|
+
traces.push({ method, success: true, durationMs: ended - started, started, ended });
|
|
82
|
+
if (wantStream && wsManager) {
|
|
83
|
+
try {
|
|
84
|
+
wsManager.broadcast({ type: 'synthetic_trace', timestamp: Date.now(), data: { runId, seq: ++seq, total: iterations, method, success: true, durationMs: ended - started, started, ended } });
|
|
85
|
+
}
|
|
86
|
+
catch { /* ignore */ }
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
missingHandlerCount++;
|
|
91
|
+
const ended = Date.now();
|
|
92
|
+
if (wantTrace && traces.length < iterations)
|
|
93
|
+
traces.push({ method, success: false, durationMs: ended - started, started, ended, error: 'handler_not_registered', skipped: true });
|
|
94
|
+
if (wantStream && wsManager) {
|
|
95
|
+
try {
|
|
96
|
+
wsManager.broadcast({ type: 'synthetic_trace', timestamp: Date.now(), data: { runId, seq: ++seq, total: iterations, method, success: false, durationMs: ended - started, started, ended, error: 'handler_not_registered', skipped: true } });
|
|
97
|
+
}
|
|
98
|
+
catch { /* ignore */ }
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
errors++;
|
|
104
|
+
const ended = Date.now();
|
|
105
|
+
if (wantTrace && traces.length < iterations)
|
|
106
|
+
traces.push({ method, success: false, durationMs: ended - started, started, ended, error: err instanceof Error ? err.message : String(err) });
|
|
107
|
+
if (wantStream && wsManager) {
|
|
108
|
+
try {
|
|
109
|
+
wsManager.broadcast({ type: 'synthetic_trace', timestamp: Date.now(), data: { runId, seq: ++seq, total: iterations, method, success: false, durationMs: ended - started, started, ended, error: err instanceof Error ? err.message : String(err) } });
|
|
110
|
+
}
|
|
111
|
+
catch { /* ignore */ }
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
executed++;
|
|
115
|
+
syntheticActiveRequests--;
|
|
116
|
+
};
|
|
117
|
+
// Concurrency control
|
|
118
|
+
const inFlight = [];
|
|
119
|
+
for (let i = 0; i < iterations; i++) {
|
|
120
|
+
if (inFlight.length >= concurrency) {
|
|
121
|
+
await Promise.race(inFlight);
|
|
122
|
+
}
|
|
123
|
+
const p = runOne().finally(() => {
|
|
124
|
+
const idx = inFlight.indexOf(p);
|
|
125
|
+
if (idx >= 0)
|
|
126
|
+
inFlight.splice(idx, 1);
|
|
127
|
+
});
|
|
128
|
+
inFlight.push(p);
|
|
129
|
+
}
|
|
130
|
+
await Promise.all(inFlight);
|
|
131
|
+
const durationMs = Date.now() - start;
|
|
132
|
+
const debug = req.query.debug === '1' || req.body?.debug === true;
|
|
133
|
+
const traceReason = wantTrace && traces.length === 0
|
|
134
|
+
? (available.length === 0
|
|
135
|
+
? 'no_safe_tools_registered'
|
|
136
|
+
: missingHandlerCount === iterations
|
|
137
|
+
? 'all_selected_handlers_missing'
|
|
138
|
+
: 'no_traces_captured')
|
|
139
|
+
: undefined;
|
|
140
|
+
lastSyntheticRunId = runId;
|
|
141
|
+
lastSyntheticSummary = {
|
|
142
|
+
runId,
|
|
143
|
+
executed,
|
|
144
|
+
errors,
|
|
145
|
+
durationMs,
|
|
146
|
+
iterationsRequested: iterations,
|
|
147
|
+
concurrency,
|
|
148
|
+
availableCount: available.length,
|
|
149
|
+
missingHandlerCount,
|
|
150
|
+
traceReason,
|
|
151
|
+
timestamp: Date.now()
|
|
152
|
+
};
|
|
153
|
+
syntheticActiveRequests = 0; // safety reset
|
|
154
|
+
res.json({
|
|
155
|
+
success: true,
|
|
156
|
+
message: 'Synthetic activity completed',
|
|
157
|
+
runId,
|
|
158
|
+
executed,
|
|
159
|
+
errors,
|
|
160
|
+
durationMs,
|
|
161
|
+
iterationsRequested: iterations,
|
|
162
|
+
concurrency,
|
|
163
|
+
availableCount: available.length,
|
|
164
|
+
missingHandlerCount,
|
|
165
|
+
...(traceReason ? { traceReason } : {}),
|
|
166
|
+
...(debug ? { available } : {}),
|
|
167
|
+
...(wantTrace ? { traces } : {}),
|
|
168
|
+
timestamp: Date.now()
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
console.error('[API] Synthetic activity error:', error);
|
|
173
|
+
res.status(500).json({
|
|
174
|
+
success: false,
|
|
175
|
+
error: 'Failed to run synthetic activity',
|
|
176
|
+
message: error instanceof Error ? error.message : 'Unknown error'
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
/**
|
|
181
|
+
* GET /api/admin/synthetic/status - real-time synthetic run status (active in-flight requests)
|
|
182
|
+
*/
|
|
183
|
+
router.get('/admin/synthetic/status', (_req, res) => {
|
|
184
|
+
res.json({
|
|
185
|
+
success: true,
|
|
186
|
+
activeRequests: syntheticActiveRequests,
|
|
187
|
+
lastRunId: lastSyntheticRunId,
|
|
188
|
+
lastSummary: lastSyntheticSummary,
|
|
189
|
+
timestamp: Date.now()
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
/** Expose activeSyntheticRequests for other modules (e.g. metrics.routes /performance/detailed) */
|
|
193
|
+
router.getSyntheticActiveRequests = () => syntheticActiveRequests;
|
|
194
|
+
return router;
|
|
195
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Tools Routes — REST bridge for MCP tool handlers
|
|
4
|
+
* Routes: POST /tools/:name, GET /tools
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.createToolsRoutes = createToolsRoutes;
|
|
8
|
+
const express_1 = require("express");
|
|
9
|
+
const registry_js_1 = require("../../../server/registry.js");
|
|
10
|
+
function createToolsRoutes() {
|
|
11
|
+
const router = (0, express_1.Router)();
|
|
12
|
+
/**
|
|
13
|
+
* GET /api/tools — List all registered tool names
|
|
14
|
+
*/
|
|
15
|
+
router.get('/tools', (_req, res) => {
|
|
16
|
+
res.json({ tools: (0, registry_js_1.listRegisteredMethods)() });
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* POST /api/tools/:name — Invoke a registered MCP tool handler by name
|
|
20
|
+
* Body: JSON params passed directly to the handler
|
|
21
|
+
* Returns: handler result or error
|
|
22
|
+
*/
|
|
23
|
+
router.post('/tools/:name', async (req, res) => {
|
|
24
|
+
const toolName = req.params.name;
|
|
25
|
+
if (!toolName || !/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(toolName)) {
|
|
26
|
+
res.status(400).json({ error: 'Invalid tool name' });
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const handler = (0, registry_js_1.getLocalHandler)(toolName);
|
|
30
|
+
if (!handler) {
|
|
31
|
+
res.status(404).json({ error: `Tool not found: ${toolName}`, available: (0, registry_js_1.listRegisteredMethods)() });
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const result = await handler(req.body);
|
|
36
|
+
res.json(result);
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
const message = err instanceof Error ? err.message
|
|
40
|
+
: (typeof err === 'object' && err !== null) ? JSON.stringify(err)
|
|
41
|
+
: String(err);
|
|
42
|
+
res.status(500).json({ error: message });
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return router;
|
|
46
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Usage Signal Routes
|
|
4
|
+
* Routes: GET /usage/snapshot - returns per-instruction usage signals
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.createUsageRoutes = createUsageRoutes;
|
|
8
|
+
const express_1 = require("express");
|
|
9
|
+
const indexContext_js_1 = require("../../../services/indexContext.js");
|
|
10
|
+
function createUsageRoutes() {
|
|
11
|
+
const router = (0, express_1.Router)();
|
|
12
|
+
/**
|
|
13
|
+
* GET /api/usage/snapshot - Get the usage snapshot (per-instruction signals)
|
|
14
|
+
*/
|
|
15
|
+
router.get('/usage/snapshot', (_req, res) => {
|
|
16
|
+
try {
|
|
17
|
+
const snap = (0, indexContext_js_1.loadUsageSnapshot)();
|
|
18
|
+
res.json({ success: true, snapshot: snap, count: Object.keys(snap).length, timestamp: Date.now() });
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
res.status(500).json({ success: false, error: 'Failed to load usage snapshot', message: error instanceof Error ? error.message : 'Unknown error' });
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return router;
|
|
25
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* wsInit — WebSocket server initialization and metrics broadcast wiring.
|
|
3
|
+
* Extracted from DashboardServer.ts to keep the coordinator within line limits.
|
|
4
|
+
*/
|
|
5
|
+
import { Server as HttpServer } from 'http';
|
|
6
|
+
import { WebSocketManager } from './WebSocketManager.js';
|
|
7
|
+
import { MetricsCollector } from './MetricsCollector.js';
|
|
8
|
+
/** Attaches the WebSocket server to an existing HTTP/HTTPS server instance. */
|
|
9
|
+
export declare function initWebSocket(server: HttpServer, wsManager: WebSocketManager): void;
|
|
10
|
+
/**
|
|
11
|
+
* Starts a recurring timer that broadcasts the full metrics snapshot to all
|
|
12
|
+
* connected WebSocket clients. Returns the timer handle so the caller can clear it.
|
|
13
|
+
*
|
|
14
|
+
* A lower-bound of 250 ms is enforced regardless of the configured interval.
|
|
15
|
+
*/
|
|
16
|
+
export declare function startMetricsBroadcast(wsManager: WebSocketManager, metricsCollector: MetricsCollector, intervalMs: number): NodeJS.Timeout;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* wsInit — WebSocket server initialization and metrics broadcast wiring.
|
|
4
|
+
* Extracted from DashboardServer.ts to keep the coordinator within line limits.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.initWebSocket = initWebSocket;
|
|
8
|
+
exports.startMetricsBroadcast = startMetricsBroadcast;
|
|
9
|
+
/** Attaches the WebSocket server to an existing HTTP/HTTPS server instance. */
|
|
10
|
+
function initWebSocket(server, wsManager) {
|
|
11
|
+
wsManager.initialize(server);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Starts a recurring timer that broadcasts the full metrics snapshot to all
|
|
15
|
+
* connected WebSocket clients. Returns the timer handle so the caller can clear it.
|
|
16
|
+
*
|
|
17
|
+
* A lower-bound of 250 ms is enforced regardless of the configured interval.
|
|
18
|
+
*/
|
|
19
|
+
function startMetricsBroadcast(wsManager, metricsCollector, intervalMs) {
|
|
20
|
+
const safeInterval = Math.max(250, intervalMs);
|
|
21
|
+
return setInterval(() => {
|
|
22
|
+
try {
|
|
23
|
+
const snapshot = metricsCollector.getCurrentSnapshot();
|
|
24
|
+
wsManager.broadcast({
|
|
25
|
+
type: 'metrics_update',
|
|
26
|
+
timestamp: Date.now(),
|
|
27
|
+
data: snapshot,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
// eslint-disable-next-line no-console
|
|
32
|
+
console.error('[Dashboard] metrics broadcast failed', e);
|
|
33
|
+
}
|
|
34
|
+
}, safeInterval);
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|