@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,293 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Messaging Routes — Dashboard REST API for inter-agent messaging.
|
|
4
|
+
*
|
|
5
|
+
* Routes:
|
|
6
|
+
* POST /api/messages — send a message
|
|
7
|
+
* GET /api/messages/channels — list channels
|
|
8
|
+
* GET /api/messages/stats — reader stats
|
|
9
|
+
* GET /api/messages/:channel — read messages from channel
|
|
10
|
+
* POST /api/messages/ack — acknowledge messages
|
|
11
|
+
* GET /api/messages/by-id/:id — get message by ID
|
|
12
|
+
* PUT /api/messages/by-id/:id — update message
|
|
13
|
+
* DELETE /api/messages — purge messages
|
|
14
|
+
* POST /api/messages/inbound — peer inbound (cross-instance)
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.createMessagingRoutes = createMessagingRoutes;
|
|
18
|
+
const express_1 = require("express");
|
|
19
|
+
const agentMailbox_js_1 = require("../../../services/messaging/agentMailbox.js");
|
|
20
|
+
const runtimeConfig_js_1 = require("../../../config/runtimeConfig.js");
|
|
21
|
+
const messagingTypes_js_1 = require("../../../services/messaging/messagingTypes.js");
|
|
22
|
+
const WebSocketManager_js_1 = require("../WebSocketManager.js");
|
|
23
|
+
let _mailbox = null;
|
|
24
|
+
function getMailbox() {
|
|
25
|
+
if (!_mailbox) {
|
|
26
|
+
_mailbox = new agentMailbox_js_1.AgentMailbox((0, runtimeConfig_js_1.getRuntimeConfig)().messaging);
|
|
27
|
+
}
|
|
28
|
+
return _mailbox;
|
|
29
|
+
}
|
|
30
|
+
/** Format Zod issues with field paths for actionable error messages. */
|
|
31
|
+
function formatZodIssues(issues) {
|
|
32
|
+
return issues.map(i => {
|
|
33
|
+
const field = i.path.length ? i.path.join('.') : 'body';
|
|
34
|
+
return `${field}: ${i.message}`;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const SEND_SCHEMA_HINT = {
|
|
38
|
+
required: { channel: 'string', sender: 'string', recipients: 'string[]', body: 'string' },
|
|
39
|
+
optional: { priority: 'low|normal|high|critical', ttlSeconds: 'number (1-86400)', persistent: 'boolean', payload: 'object', parentId: 'string', tags: 'string[]', requiresAck: 'boolean', ackBySeconds: 'number' },
|
|
40
|
+
};
|
|
41
|
+
function createMessagingRoutes() {
|
|
42
|
+
const router = (0, express_1.Router)();
|
|
43
|
+
// POST /api/messages — send a message
|
|
44
|
+
router.post('/messages', (req, res) => {
|
|
45
|
+
try {
|
|
46
|
+
const parsed = messagingTypes_js_1.SendMessageOptionsSchema.safeParse(req.body);
|
|
47
|
+
if (!parsed.success) {
|
|
48
|
+
res.status(400).json({
|
|
49
|
+
success: false,
|
|
50
|
+
error: 'Invalid message payload',
|
|
51
|
+
issues: formatZodIssues(parsed.error.issues),
|
|
52
|
+
hint: 'POST /api/messages expects a JSON body with required fields: channel, sender, recipients, body',
|
|
53
|
+
schema: SEND_SCHEMA_HINT,
|
|
54
|
+
});
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const mailbox = getMailbox();
|
|
58
|
+
mailbox.send(parsed.data).then(messageId => {
|
|
59
|
+
try {
|
|
60
|
+
(0, WebSocketManager_js_1.getWebSocketManager)().broadcast({ type: 'message_received', timestamp: Date.now(), data: { messageId, channel: parsed.data.channel } });
|
|
61
|
+
}
|
|
62
|
+
catch { /* ws optional */ }
|
|
63
|
+
res.status(201).json({
|
|
64
|
+
success: true,
|
|
65
|
+
messageId,
|
|
66
|
+
channel: parsed.data.channel,
|
|
67
|
+
status: 'sent',
|
|
68
|
+
});
|
|
69
|
+
}).catch(err => {
|
|
70
|
+
res.status(500).json({ success: false, error: err instanceof Error ? err.message : 'Send failed' });
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
res.status(500).json({ success: false, error: error instanceof Error ? error.message : 'Unknown error' });
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
// GET /api/messages/channels — list all channels
|
|
78
|
+
router.get('/messages/channels', (_req, res) => {
|
|
79
|
+
try {
|
|
80
|
+
const mailbox = getMailbox();
|
|
81
|
+
const channels = mailbox.listChannels();
|
|
82
|
+
res.json({ success: true, count: channels.length, channels });
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
res.status(500).json({ success: false, error: error instanceof Error ? error.message : 'Unknown error' });
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
// GET /api/messages/stats — reader stats
|
|
89
|
+
router.get('/messages/stats', (req, res) => {
|
|
90
|
+
try {
|
|
91
|
+
const reader = req.query.reader || '*';
|
|
92
|
+
const mailbox = getMailbox();
|
|
93
|
+
const stats = mailbox.getStats(reader);
|
|
94
|
+
res.json({ success: true, reader, ...stats });
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
res.status(500).json({ success: false, error: error instanceof Error ? error.message : 'Unknown error' });
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
// GET /api/messages/by-id/:id — get message by ID
|
|
101
|
+
router.get('/messages/by-id/:id', (req, res) => {
|
|
102
|
+
try {
|
|
103
|
+
const mailbox = getMailbox();
|
|
104
|
+
const message = mailbox.getMessage(req.params.id);
|
|
105
|
+
if (!message) {
|
|
106
|
+
res.status(404).json({ success: false, error: `Message not found: ${req.params.id}`, hint: 'Use GET /api/messages/channels to list channels, then GET /api/messages/:channel to browse messages' });
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
res.json({ success: true, message });
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
res.status(500).json({ success: false, error: error instanceof Error ? error.message : 'Unknown error' });
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
// PUT /api/messages/by-id/:id — update message
|
|
116
|
+
router.put('/messages/by-id/:id', (req, res) => {
|
|
117
|
+
try {
|
|
118
|
+
const mailbox = getMailbox();
|
|
119
|
+
const updated = mailbox.updateMessage(req.params.id, {
|
|
120
|
+
body: req.body.body,
|
|
121
|
+
recipients: req.body.recipients,
|
|
122
|
+
payload: req.body.payload,
|
|
123
|
+
persistent: req.body.persistent,
|
|
124
|
+
});
|
|
125
|
+
if (!updated) {
|
|
126
|
+
res.status(404).json({ success: false, error: `Message not found: ${req.params.id}`, hint: 'Use GET /api/messages/by-id/:id to verify the message exists before updating' });
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
(0, WebSocketManager_js_1.getWebSocketManager)().broadcast({ type: 'message_received', timestamp: Date.now(), data: { messageId: req.params.id } });
|
|
131
|
+
}
|
|
132
|
+
catch { /* ws optional */ }
|
|
133
|
+
res.json({ success: true, message: updated });
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
res.status(500).json({ success: false, error: error instanceof Error ? error.message : 'Unknown error' });
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
// GET /api/messages/thread/:parentId — get full thread
|
|
140
|
+
router.get('/messages/thread/:parentId', (req, res) => {
|
|
141
|
+
try {
|
|
142
|
+
const parentId = decodeURIComponent(req.params.parentId);
|
|
143
|
+
const mailbox = getMailbox();
|
|
144
|
+
const thread = mailbox.getThread(parentId);
|
|
145
|
+
if (!thread || thread.length === 0) {
|
|
146
|
+
res.status(404).json({ success: false, error: `No thread found for parentId: ${parentId}` });
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
res.json({ success: true, parentId, count: thread.length, messages: thread });
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
res.status(500).json({ success: false, error: error instanceof Error ? error.message : 'Unknown error' });
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
// GET /api/messages/:channel — read messages from channel
|
|
156
|
+
router.get('/messages/:channel', (req, res) => {
|
|
157
|
+
try {
|
|
158
|
+
const channel = decodeURIComponent(req.params.channel);
|
|
159
|
+
const reader = req.query.reader || '*';
|
|
160
|
+
const unreadOnly = req.query.unreadOnly === 'true';
|
|
161
|
+
const limit = req.query.limit ? parseInt(req.query.limit, 10) : undefined;
|
|
162
|
+
const markRead = req.query.markRead === 'true';
|
|
163
|
+
const tags = req.query.tags ? req.query.tags.split(',').map(t => t.trim()).filter(Boolean) : undefined;
|
|
164
|
+
const sender = req.query.sender || undefined;
|
|
165
|
+
const mailbox = getMailbox();
|
|
166
|
+
const messages = mailbox.read({ channel, reader, unreadOnly, limit, markRead, tags, sender });
|
|
167
|
+
res.json({ success: true, channel, reader, count: messages.length, messages });
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
res.status(500).json({ success: false, error: error instanceof Error ? error.message : 'Unknown error' });
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
// POST /api/messages/ack — acknowledge messages
|
|
174
|
+
router.post('/messages/ack', (req, res) => {
|
|
175
|
+
try {
|
|
176
|
+
const { messageIds, reader } = req.body;
|
|
177
|
+
if (!Array.isArray(messageIds) || !reader) {
|
|
178
|
+
res.status(400).json({
|
|
179
|
+
success: false,
|
|
180
|
+
error: 'Invalid ack request',
|
|
181
|
+
issues: [
|
|
182
|
+
...(!Array.isArray(messageIds) ? ['messageIds: must be a non-empty array of message ID strings'] : []),
|
|
183
|
+
...(!reader ? ['reader: must be a non-empty string identifying the acknowledging agent'] : []),
|
|
184
|
+
],
|
|
185
|
+
hint: 'POST /api/messages/ack expects { "messageIds": ["msg-..."], "reader": "agent-name" }',
|
|
186
|
+
});
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
const mailbox = getMailbox();
|
|
190
|
+
const acknowledged = mailbox.ack(messageIds, reader);
|
|
191
|
+
res.json({ success: true, acknowledged, reader });
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
res.status(500).json({ success: false, error: error instanceof Error ? error.message : 'Unknown error' });
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
// DELETE /api/messages — purge messages
|
|
198
|
+
router.delete('/messages', (req, res) => {
|
|
199
|
+
try {
|
|
200
|
+
const mailbox = getMailbox();
|
|
201
|
+
let removed = 0;
|
|
202
|
+
let action = 'none';
|
|
203
|
+
if (req.body?.messageIds?.length) {
|
|
204
|
+
removed = mailbox.deleteMessages(req.body.messageIds);
|
|
205
|
+
action = 'delete_by_ids';
|
|
206
|
+
}
|
|
207
|
+
else if (req.body?.channel) {
|
|
208
|
+
removed = mailbox.purgeChannel(req.body.channel);
|
|
209
|
+
action = 'purge_channel';
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
removed = mailbox.purgeAll();
|
|
213
|
+
action = 'purge_all';
|
|
214
|
+
}
|
|
215
|
+
try {
|
|
216
|
+
(0, WebSocketManager_js_1.getWebSocketManager)().broadcast({ type: 'message_purged', timestamp: Date.now(), data: { count: removed } });
|
|
217
|
+
}
|
|
218
|
+
catch { /* ws optional */ }
|
|
219
|
+
res.json({ success: true, action, purged: removed });
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
res.status(500).json({ success: false, error: error instanceof Error ? error.message : 'Unknown error' });
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
// POST /api/messages/inbound — receive message from peer instance
|
|
226
|
+
router.post('/messages/inbound', (req, res) => {
|
|
227
|
+
try {
|
|
228
|
+
if (!req.body || !req.body.id || !req.body.channel) {
|
|
229
|
+
res.status(400).json({
|
|
230
|
+
success: false,
|
|
231
|
+
error: 'Invalid inbound message',
|
|
232
|
+
issues: [
|
|
233
|
+
...(!req.body?.id ? ['id: required — unique message identifier'] : []),
|
|
234
|
+
...(!req.body?.channel ? ['channel: required — target channel name'] : []),
|
|
235
|
+
],
|
|
236
|
+
hint: 'POST /api/messages/inbound expects { "id": "...", "channel": "...", "sender": "...", "body": "..." }',
|
|
237
|
+
});
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const mailbox = getMailbox();
|
|
241
|
+
mailbox.send({
|
|
242
|
+
channel: req.body.channel,
|
|
243
|
+
sender: req.body.sender || 'peer',
|
|
244
|
+
recipients: req.body.recipients || ['*'],
|
|
245
|
+
body: req.body.body || '',
|
|
246
|
+
ttlSeconds: req.body.ttlSeconds,
|
|
247
|
+
persistent: req.body.persistent,
|
|
248
|
+
payload: req.body.payload,
|
|
249
|
+
priority: req.body.priority,
|
|
250
|
+
parentId: req.body.parentId,
|
|
251
|
+
tags: req.body.tags,
|
|
252
|
+
}).then(() => {
|
|
253
|
+
try {
|
|
254
|
+
(0, WebSocketManager_js_1.getWebSocketManager)().broadcast({ type: 'message_received', timestamp: Date.now(), data: { channel: req.body.channel } });
|
|
255
|
+
}
|
|
256
|
+
catch { /* ws optional */ }
|
|
257
|
+
res.json({ success: true, status: 'received' });
|
|
258
|
+
}).catch(err => {
|
|
259
|
+
res.status(500).json({ success: false, error: err instanceof Error ? err.message : 'Inbound failed' });
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
catch (error) {
|
|
263
|
+
res.status(500).json({ success: false, error: error instanceof Error ? error.message : 'Unknown error' });
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
// POST /api/messages/reply — reply to a message
|
|
267
|
+
router.post('/messages/reply', async (req, res) => {
|
|
268
|
+
try {
|
|
269
|
+
const { parentId, sender, body, replyAll, recipients, priority, tags, persistent, payload } = req.body || {};
|
|
270
|
+
if (!parentId || !sender || !body) {
|
|
271
|
+
res.status(400).json({
|
|
272
|
+
success: false,
|
|
273
|
+
error: 'Missing required fields: parentId, sender, body',
|
|
274
|
+
hint: 'POST /api/messages/reply expects { "parentId": "...", "sender": "...", "body": "...", "replyAll": false }',
|
|
275
|
+
});
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const mailbox = getMailbox();
|
|
279
|
+
const result = await mailbox.reply(parentId, sender, body, { replyAll, recipients, priority, tags, persistent, payload });
|
|
280
|
+
try {
|
|
281
|
+
(0, WebSocketManager_js_1.getWebSocketManager)().broadcast({ type: 'message_received', timestamp: Date.now(), data: { channel: result.channel } });
|
|
282
|
+
}
|
|
283
|
+
catch { /* ws optional */ }
|
|
284
|
+
res.json({ success: true, message: result });
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
const msg = error instanceof Error ? error.message : 'Unknown error';
|
|
288
|
+
const status = msg.includes('not found') ? 404 : 500;
|
|
289
|
+
res.status(status).json({ success: false, error: msg });
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
return router;
|
|
293
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metrics & Analytics Routes
|
|
3
|
+
* Routes: GET /metrics, GET /metrics/history, GET /tools, GET /tools/:toolName,
|
|
4
|
+
* GET /performance, GET /performance/detailed, GET /realtime,
|
|
5
|
+
* GET /streaming/data, GET /charts/tool-usage, GET /charts/performance,
|
|
6
|
+
* GET /charts/timerange, GET /charts/export, GET /analytics/advanced
|
|
7
|
+
*/
|
|
8
|
+
import { Router } from 'express';
|
|
9
|
+
import { MetricsCollector } from '../MetricsCollector.js';
|
|
10
|
+
export declare function createMetricsRoutes(metricsCollector: MetricsCollector): Router;
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Metrics & Analytics Routes
|
|
4
|
+
* Routes: GET /metrics, GET /metrics/history, GET /tools, GET /tools/:toolName,
|
|
5
|
+
* GET /performance, GET /performance/detailed, GET /realtime,
|
|
6
|
+
* GET /streaming/data, GET /charts/tool-usage, GET /charts/performance,
|
|
7
|
+
* GET /charts/timerange, GET /charts/export, GET /analytics/advanced
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.createMetricsRoutes = createMetricsRoutes;
|
|
11
|
+
const express_1 = require("express");
|
|
12
|
+
const registry_js_1 = require("../../../server/registry.js");
|
|
13
|
+
function createMetricsRoutes(metricsCollector) {
|
|
14
|
+
const router = (0, express_1.Router)();
|
|
15
|
+
/**
|
|
16
|
+
* GET /api/tools - List all registered tools
|
|
17
|
+
*/
|
|
18
|
+
router.get('/tools', (_req, res) => {
|
|
19
|
+
try {
|
|
20
|
+
const tools = (0, registry_js_1.listRegisteredMethods)();
|
|
21
|
+
const toolMetrics = metricsCollector.getToolMetrics();
|
|
22
|
+
const enrichedTools = tools.map(toolName => ({
|
|
23
|
+
name: toolName,
|
|
24
|
+
metrics: toolMetrics[toolName] || {
|
|
25
|
+
callCount: 0,
|
|
26
|
+
successCount: 0,
|
|
27
|
+
errorCount: 0,
|
|
28
|
+
totalResponseTime: 0,
|
|
29
|
+
errorTypes: {},
|
|
30
|
+
},
|
|
31
|
+
}));
|
|
32
|
+
res.json({
|
|
33
|
+
tools: enrichedTools,
|
|
34
|
+
totalTools: tools.length,
|
|
35
|
+
timestamp: Date.now(),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
console.error('[API] Tools error:', error);
|
|
40
|
+
res.status(500).json({
|
|
41
|
+
error: 'Failed to get tools list',
|
|
42
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
/**
|
|
47
|
+
* GET /api/metrics - Current metrics snapshot
|
|
48
|
+
*/
|
|
49
|
+
router.get('/metrics', (_req, res) => {
|
|
50
|
+
try {
|
|
51
|
+
const snapshot = metricsCollector.getCurrentSnapshot();
|
|
52
|
+
res.json(snapshot);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
console.error('[API] Metrics error:', error);
|
|
56
|
+
res.status(500).json({
|
|
57
|
+
error: 'Failed to get metrics',
|
|
58
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
/**
|
|
63
|
+
* GET /api/metrics/history - Historical metrics snapshots
|
|
64
|
+
*/
|
|
65
|
+
router.get('/metrics/history', (req, res) => {
|
|
66
|
+
try {
|
|
67
|
+
const count = req.query.count ? parseInt(req.query.count, 10) : undefined;
|
|
68
|
+
const snapshots = metricsCollector.getSnapshots(count);
|
|
69
|
+
res.json({
|
|
70
|
+
snapshots,
|
|
71
|
+
count: snapshots.length,
|
|
72
|
+
timestamp: Date.now(),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
console.error('[API] Metrics history error:', error);
|
|
77
|
+
res.status(500).json({
|
|
78
|
+
error: 'Failed to get metrics history',
|
|
79
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
/**
|
|
84
|
+
* GET /api/tools/:toolName - Specific tool metrics
|
|
85
|
+
*/
|
|
86
|
+
router.get('/tools/:toolName', (req, res) => {
|
|
87
|
+
try {
|
|
88
|
+
const { toolName } = req.params;
|
|
89
|
+
const metrics = metricsCollector.getToolMetrics(toolName);
|
|
90
|
+
if (!metrics) {
|
|
91
|
+
return res.status(404).json({
|
|
92
|
+
error: 'Tool not found',
|
|
93
|
+
toolName,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
res.json({
|
|
97
|
+
toolName,
|
|
98
|
+
metrics,
|
|
99
|
+
timestamp: Date.now(),
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
console.error('[API] Tool metrics error:', error);
|
|
104
|
+
res.status(500).json({
|
|
105
|
+
error: 'Failed to get tool metrics',
|
|
106
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
/**
|
|
111
|
+
* GET /api/performance - Performance summary
|
|
112
|
+
*/
|
|
113
|
+
router.get('/performance', (_req, res) => {
|
|
114
|
+
try {
|
|
115
|
+
const snapshot = metricsCollector.getCurrentSnapshot();
|
|
116
|
+
res.json({
|
|
117
|
+
performance: snapshot.performance,
|
|
118
|
+
server: {
|
|
119
|
+
uptime: snapshot.server.uptime,
|
|
120
|
+
memoryUsage: snapshot.server.memoryUsage,
|
|
121
|
+
cpuUsage: snapshot.server.cpuUsage,
|
|
122
|
+
},
|
|
123
|
+
connections: snapshot.connections,
|
|
124
|
+
timestamp: snapshot.timestamp,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
console.error('[API] Performance error:', error);
|
|
129
|
+
res.status(500).json({
|
|
130
|
+
error: 'Failed to get performance metrics',
|
|
131
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
/**
|
|
136
|
+
* GET /api/realtime - Real-time metrics for dashboard widgets
|
|
137
|
+
*/
|
|
138
|
+
router.get('/realtime', (_req, res) => {
|
|
139
|
+
try {
|
|
140
|
+
const realtimeMetrics = metricsCollector.getRealtimeMetrics();
|
|
141
|
+
res.json({
|
|
142
|
+
success: true,
|
|
143
|
+
data: realtimeMetrics,
|
|
144
|
+
timestamp: Date.now(),
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
console.error('[API] Realtime metrics error:', error);
|
|
149
|
+
res.status(500).json({
|
|
150
|
+
error: 'Failed to get realtime metrics',
|
|
151
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
/**
|
|
156
|
+
* GET /api/streaming/data - Real-time streaming data for Phase 4
|
|
157
|
+
*/
|
|
158
|
+
router.get('/streaming/data', (_req, res) => {
|
|
159
|
+
try {
|
|
160
|
+
const streamingData = metricsCollector.getRealtimeStreamingData();
|
|
161
|
+
res.json({
|
|
162
|
+
success: true,
|
|
163
|
+
data: streamingData,
|
|
164
|
+
timestamp: Date.now()
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
console.error('[API] Streaming data error:', error);
|
|
169
|
+
res.status(500).json({
|
|
170
|
+
error: 'Failed to get streaming data',
|
|
171
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
/**
|
|
176
|
+
* GET /api/charts/tool-usage - Tool usage chart data
|
|
177
|
+
* Query params: minutes (default: 60)
|
|
178
|
+
*/
|
|
179
|
+
router.get('/charts/tool-usage', (req, res) => {
|
|
180
|
+
try {
|
|
181
|
+
const minutes = parseInt(req.query.minutes) || 60;
|
|
182
|
+
const chartData = metricsCollector.getToolUsageChartData(minutes);
|
|
183
|
+
res.json({
|
|
184
|
+
success: true,
|
|
185
|
+
data: chartData,
|
|
186
|
+
timeRange: `${minutes} minutes`,
|
|
187
|
+
timestamp: Date.now(),
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
console.error('[API] Tool usage chart error:', error);
|
|
192
|
+
res.status(500).json({
|
|
193
|
+
error: 'Failed to get tool usage chart data',
|
|
194
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
/**
|
|
199
|
+
* GET /api/charts/performance - Performance metrics chart data
|
|
200
|
+
* Query params: minutes (default: 60)
|
|
201
|
+
*/
|
|
202
|
+
router.get('/charts/performance', (req, res) => {
|
|
203
|
+
try {
|
|
204
|
+
const minutes = parseInt(req.query.minutes) || 60;
|
|
205
|
+
const chartData = metricsCollector.getPerformanceChartData(minutes);
|
|
206
|
+
res.json({
|
|
207
|
+
success: true,
|
|
208
|
+
data: chartData,
|
|
209
|
+
timeRange: `${minutes} minutes`,
|
|
210
|
+
timestamp: Date.now(),
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
console.error('[API] Performance chart error:', error);
|
|
215
|
+
res.status(500).json({
|
|
216
|
+
error: 'Failed to get performance chart data',
|
|
217
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
/**
|
|
222
|
+
* GET /api/charts/timerange - Metrics for specific time ranges
|
|
223
|
+
* Query params: range (1h, 6h, 24h, 7d, 30d)
|
|
224
|
+
*/
|
|
225
|
+
router.get('/charts/timerange', (req, res) => {
|
|
226
|
+
try {
|
|
227
|
+
const range = req.query.range || '1h';
|
|
228
|
+
const validRanges = ['1h', '6h', '24h', '7d', '30d'];
|
|
229
|
+
if (!validRanges.includes(range)) {
|
|
230
|
+
return res.status(400).json({
|
|
231
|
+
error: 'Invalid time range',
|
|
232
|
+
message: `Range must be one of: ${validRanges.join(', ')}`,
|
|
233
|
+
validRanges,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
const timeRangeData = metricsCollector.getTimeRangeMetrics(range);
|
|
237
|
+
res.json({
|
|
238
|
+
success: true,
|
|
239
|
+
data: timeRangeData,
|
|
240
|
+
range,
|
|
241
|
+
count: timeRangeData.length,
|
|
242
|
+
timestamp: Date.now(),
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
console.error('[API] Time range chart error:', error);
|
|
247
|
+
res.status(500).json({
|
|
248
|
+
error: 'Failed to get time range data',
|
|
249
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
/**
|
|
254
|
+
* GET /api/charts/export - Export chart data for reports
|
|
255
|
+
* Query params: format (json, csv), range (1h, 6h, 24h, 7d, 30d)
|
|
256
|
+
*/
|
|
257
|
+
router.get('/charts/export', (req, res) => {
|
|
258
|
+
try {
|
|
259
|
+
const format = req.query.format || 'json';
|
|
260
|
+
const range = req.query.range || '1h';
|
|
261
|
+
if (!['json', 'csv'].includes(format)) {
|
|
262
|
+
return res.status(400).json({
|
|
263
|
+
error: 'Invalid export format',
|
|
264
|
+
message: 'Format must be either json or csv',
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
const data = metricsCollector.getTimeRangeMetrics(range);
|
|
268
|
+
if (format === 'csv') {
|
|
269
|
+
// Convert to CSV format
|
|
270
|
+
const csvHeaders = 'timestamp,activeConnections,requestsPerMinute,successRate,errorRate,avgResponseTime\n';
|
|
271
|
+
const csvRows = data.map(snapshot => `${snapshot.timestamp},${snapshot.connections.activeConnections},${snapshot.performance.requestsPerMinute},${snapshot.performance.successRate},${snapshot.performance.errorRate},${snapshot.performance.avgResponseTime}`).join('\n');
|
|
272
|
+
res.setHeader('Content-Type', 'text/csv');
|
|
273
|
+
res.setHeader('Content-Disposition', `attachment; filename="metrics-${range}-${Date.now()}.csv"`);
|
|
274
|
+
res.send(csvHeaders + csvRows);
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
res.json({
|
|
278
|
+
success: true,
|
|
279
|
+
data,
|
|
280
|
+
range,
|
|
281
|
+
exportedAt: Date.now(),
|
|
282
|
+
format: 'json',
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
console.error('[API] Chart export error:', error);
|
|
288
|
+
res.status(500).json({
|
|
289
|
+
error: 'Failed to export chart data',
|
|
290
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
/**
|
|
295
|
+
* GET /api/performance/detailed - Extended performance metrics (UI convenience endpoint)
|
|
296
|
+
* Supplies the fields the dashboard Monitoring panel expects without the client
|
|
297
|
+
* needing to stitch multiple endpoints. P95/P99 are approximations until full
|
|
298
|
+
* latency histogram support is implemented.
|
|
299
|
+
*/
|
|
300
|
+
router.get('/performance/detailed', (_req, res) => {
|
|
301
|
+
try {
|
|
302
|
+
const snap = metricsCollector.getCurrentSnapshot();
|
|
303
|
+
// Approximate p95 by avgResponseTime + (errorRate factor) as a placeholder; real implementation would use distribution.
|
|
304
|
+
const avg = snap.performance.avgResponseTime;
|
|
305
|
+
const p95 = avg ? Math.round(avg * 1.35) : 0;
|
|
306
|
+
res.json({
|
|
307
|
+
success: true,
|
|
308
|
+
data: {
|
|
309
|
+
requestThroughput: snap.performance.requestsPerMinute,
|
|
310
|
+
averageResponseTime: avg,
|
|
311
|
+
p95ResponseTime: p95,
|
|
312
|
+
errorRate: snap.performance.errorRate,
|
|
313
|
+
concurrentConnections: snap.connections.activeConnections,
|
|
314
|
+
successRate: snap.performance.successRate ?? (100 - snap.performance.errorRate),
|
|
315
|
+
activeSyntheticRequests: 0
|
|
316
|
+
},
|
|
317
|
+
timestamp: Date.now()
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
catch (err) {
|
|
321
|
+
res.status(500).json({ success: false, error: 'Failed to compute performance metrics', message: err instanceof Error ? err.message : String(err) });
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
/**
|
|
325
|
+
* GET /api/analytics/advanced - Advanced analytics data
|
|
326
|
+
*/
|
|
327
|
+
router.get('/analytics/advanced', (req, res) => {
|
|
328
|
+
try {
|
|
329
|
+
const timeRange = req.query.timeRange || '1h';
|
|
330
|
+
const analytics = metricsCollector.getAdvancedAnalytics(timeRange);
|
|
331
|
+
res.json({
|
|
332
|
+
success: true,
|
|
333
|
+
data: analytics,
|
|
334
|
+
timestamp: Date.now()
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
catch (error) {
|
|
338
|
+
console.error('[API] Advanced analytics error:', error);
|
|
339
|
+
res.status(500).json({
|
|
340
|
+
error: 'Failed to get advanced analytics',
|
|
341
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
return router;
|
|
346
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scripts Routes — Serve client scripts for download
|
|
3
|
+
* Routes: GET /scripts, GET /scripts/:name
|
|
4
|
+
*
|
|
5
|
+
* Provides downloadable REST client scripts for agents and users
|
|
6
|
+
* that lack MCP tool access and need to interact via HTTP.
|
|
7
|
+
*/
|
|
8
|
+
import { Router } from 'express';
|
|
9
|
+
export declare function createScriptsRoutes(): Router;
|