@mxf-dev/core 1.0.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/dist/adapters/FrameworkAdapter.js +1 -1
- package/dist/adapters/FrameworkAdapter.js.map +1 -1
- package/dist/config/ConfigManager.d.ts +9 -8
- package/dist/config/ConfigManager.d.ts.map +1 -1
- package/dist/config/ConfigManager.js +47 -17
- package/dist/config/ConfigManager.js.map +1 -1
- package/dist/config/memory-strata.config.d.ts +25 -0
- package/dist/config/memory-strata.config.d.ts.map +1 -0
- package/dist/config/memory-strata.config.js +107 -0
- package/dist/config/memory-strata.config.js.map +1 -0
- package/dist/constants/ToolNames.d.ts +1 -29
- package/dist/constants/ToolNames.d.ts.map +1 -1
- package/dist/constants/ToolNames.js +4 -17
- package/dist/constants/ToolNames.js.map +1 -1
- package/dist/database/DatabaseAdapterFactory.d.ts +14 -2
- package/dist/database/DatabaseAdapterFactory.d.ts.map +1 -1
- package/dist/database/DatabaseAdapterFactory.js +21 -6
- package/dist/database/DatabaseAdapterFactory.js.map +1 -1
- package/dist/database/adapters/mongodb/MongoBaseRepository.d.ts +7 -1
- package/dist/database/adapters/mongodb/MongoBaseRepository.d.ts.map +1 -1
- package/dist/database/adapters/mongodb/MongoBaseRepository.js +12 -2
- package/dist/database/adapters/mongodb/MongoBaseRepository.js.map +1 -1
- package/dist/events/ClientEventBus.d.ts +16 -77
- package/dist/events/ClientEventBus.d.ts.map +1 -1
- package/dist/events/ClientEventBus.js +38 -311
- package/dist/events/ClientEventBus.js.map +1 -1
- package/dist/events/EventBus.d.ts +1 -1
- package/dist/events/EventBus.d.ts.map +1 -1
- package/dist/events/EventBus.js +5 -4
- package/dist/events/EventBus.js.map +1 -1
- package/dist/events/EventBusBase.d.ts +139 -34
- package/dist/events/EventBusBase.d.ts.map +1 -1
- package/dist/events/EventBusBase.js +366 -88
- package/dist/events/EventBusBase.js.map +1 -1
- package/dist/events/EventNames.d.ts +10 -1
- package/dist/events/EventNames.d.ts.map +1 -1
- package/dist/events/EventNames.js +3 -0
- package/dist/events/EventNames.js.map +1 -1
- package/dist/events/PublicEvents.d.ts +6 -2
- package/dist/events/PublicEvents.d.ts.map +1 -1
- package/dist/events/PublicEvents.js +7 -4
- package/dist/events/PublicEvents.js.map +1 -1
- package/dist/events/ServerEventBus.d.ts +23 -112
- package/dist/events/ServerEventBus.d.ts.map +1 -1
- package/dist/events/ServerEventBus.js +58 -323
- package/dist/events/ServerEventBus.js.map +1 -1
- package/dist/events/event-definitions/LlmBudgetEvents.d.ts +68 -0
- package/dist/events/event-definitions/LlmBudgetEvents.d.ts.map +1 -0
- package/dist/events/event-definitions/LlmBudgetEvents.js +35 -0
- package/dist/events/event-definitions/LlmBudgetEvents.js.map +1 -0
- package/dist/interfaces/IMemoryPersistence.d.ts +41 -0
- package/dist/interfaces/IMemoryPersistence.d.ts.map +1 -0
- package/dist/interfaces/IMemoryPersistence.js +15 -0
- package/dist/interfaces/IMemoryPersistence.js.map +1 -0
- package/dist/middleware/MxpMiddleware.d.ts +8 -1
- package/dist/middleware/MxpMiddleware.d.ts.map +1 -1
- package/dist/middleware/MxpMiddleware.js +42 -20
- package/dist/middleware/MxpMiddleware.js.map +1 -1
- package/dist/models/channelKey.d.ts +1 -0
- package/dist/models/channelKey.d.ts.map +1 -1
- package/dist/models/channelKey.js +5 -0
- package/dist/models/channelKey.js.map +1 -1
- package/dist/models/memoryUtility.d.ts +39 -0
- package/dist/models/memoryUtility.d.ts.map +1 -0
- package/dist/models/memoryUtility.js +39 -0
- package/dist/models/memoryUtility.js.map +1 -0
- package/dist/models/user.d.ts.map +1 -1
- package/dist/models/user.js +23 -1
- package/dist/models/user.js.map +1 -1
- package/dist/mxp/BinaryProtocolLayer.d.ts +24 -8
- package/dist/mxp/BinaryProtocolLayer.d.ts.map +1 -1
- package/dist/mxp/BinaryProtocolLayer.js +90 -103
- package/dist/mxp/BinaryProtocolLayer.js.map +1 -1
- package/dist/mxp/ContextCompressionEngine.d.ts +57 -10
- package/dist/mxp/ContextCompressionEngine.d.ts.map +1 -1
- package/dist/mxp/ContextCompressionEngine.js +170 -128
- package/dist/mxp/ContextCompressionEngine.js.map +1 -1
- package/dist/mxp/MxpTokenOptimizer.d.ts +7 -3
- package/dist/mxp/MxpTokenOptimizer.d.ts.map +1 -1
- package/dist/mxp/MxpTokenOptimizer.js +8 -5
- package/dist/mxp/MxpTokenOptimizer.js.map +1 -1
- package/dist/prompts/MxfAgentSystemPrompt.d.ts +1 -1
- package/dist/prompts/MxfAgentSystemPrompt.d.ts.map +1 -1
- package/dist/prompts/MxfAgentSystemPrompt.js +47 -57
- package/dist/prompts/MxfAgentSystemPrompt.js.map +1 -1
- package/dist/protocols/mcp/ToolError.d.ts +123 -0
- package/dist/protocols/mcp/ToolError.d.ts.map +1 -0
- package/dist/protocols/mcp/ToolError.js +108 -0
- package/dist/protocols/mcp/ToolError.js.map +1 -0
- package/dist/protocols/mcp/defineTool.d.ts +133 -0
- package/dist/protocols/mcp/defineTool.d.ts.map +1 -0
- package/dist/protocols/mcp/defineTool.js +236 -0
- package/dist/protocols/mcp/defineTool.js.map +1 -0
- package/dist/protocols/mcp/security/HttpTargetGuard.d.ts +38 -0
- package/dist/protocols/mcp/security/HttpTargetGuard.d.ts.map +1 -0
- package/dist/protocols/mcp/security/HttpTargetGuard.js +227 -0
- package/dist/protocols/mcp/security/HttpTargetGuard.js.map +1 -0
- package/dist/protocols/mcp/security/McpSecurityGuard.d.ts +9 -1
- package/dist/protocols/mcp/security/McpSecurityGuard.d.ts.map +1 -1
- package/dist/protocols/mcp/security/McpSecurityGuard.js +10 -2
- package/dist/protocols/mcp/security/McpSecurityGuard.js.map +1 -1
- package/dist/protocols/mcp/security/McpToolPolicy.d.ts +81 -0
- package/dist/protocols/mcp/security/McpToolPolicy.d.ts.map +1 -0
- package/dist/protocols/mcp/security/McpToolPolicy.js +202 -0
- package/dist/protocols/mcp/security/McpToolPolicy.js.map +1 -0
- package/dist/protocols/mcp/services/ExternalMcpServerManager.d.ts +51 -18
- package/dist/protocols/mcp/services/ExternalMcpServerManager.d.ts.map +1 -1
- package/dist/protocols/mcp/services/ExternalMcpServerManager.js +256 -283
- package/dist/protocols/mcp/services/ExternalMcpServerManager.js.map +1 -1
- package/dist/protocols/mcp/services/ExternalServerConfigs.d.ts +39 -6
- package/dist/protocols/mcp/services/ExternalServerConfigs.d.ts.map +1 -1
- package/dist/protocols/mcp/services/ExternalServerConfigs.js +76 -18
- package/dist/protocols/mcp/services/ExternalServerConfigs.js.map +1 -1
- package/dist/protocols/mcp/tools/AnalyticsTools.js +1 -1
- package/dist/protocols/mcp/tools/AnalyticsTools.js.map +1 -1
- package/dist/protocols/mcp/tools/CodeAnalysisTools.d.ts.map +1 -1
- package/dist/protocols/mcp/tools/CodeAnalysisTools.js +15 -0
- package/dist/protocols/mcp/tools/CodeAnalysisTools.js.map +1 -1
- package/dist/protocols/mcp/tools/EffectivenessTools.js +3 -3
- package/dist/protocols/mcp/tools/EffectivenessTools.js.map +1 -1
- package/dist/protocols/mcp/tools/GitTools.d.ts +9 -369
- package/dist/protocols/mcp/tools/GitTools.d.ts.map +1 -1
- package/dist/protocols/mcp/tools/GitTools.js +222 -517
- package/dist/protocols/mcp/tools/GitTools.js.map +1 -1
- package/dist/protocols/mcp/tools/InfrastructureTools.d.ts +56 -24
- package/dist/protocols/mcp/tools/InfrastructureTools.d.ts.map +1 -1
- package/dist/protocols/mcp/tools/InfrastructureTools.js +117 -26
- package/dist/protocols/mcp/tools/InfrastructureTools.js.map +1 -1
- package/dist/protocols/mcp/tools/MemorySearchTools.d.ts +0 -3
- package/dist/protocols/mcp/tools/MemorySearchTools.d.ts.map +1 -1
- package/dist/protocols/mcp/tools/MemorySearchTools.js +58 -1
- package/dist/protocols/mcp/tools/MemorySearchTools.js.map +1 -1
- package/dist/protocols/mcp/tools/OrparTools.d.ts +8 -0
- package/dist/protocols/mcp/tools/OrparTools.d.ts.map +1 -1
- package/dist/protocols/mcp/tools/OrparTools.js +66 -0
- package/dist/protocols/mcp/tools/OrparTools.js.map +1 -1
- package/dist/protocols/mcp/tools/SafetyTools.d.ts +7 -525
- package/dist/protocols/mcp/tools/SafetyTools.d.ts.map +1 -1
- package/dist/protocols/mcp/tools/SafetyTools.js +349 -514
- package/dist/protocols/mcp/tools/SafetyTools.js.map +1 -1
- package/dist/protocols/mcp/tools/TaskPlanningTools.d.ts.map +1 -1
- package/dist/protocols/mcp/tools/TaskPlanningTools.js +56 -26
- package/dist/protocols/mcp/tools/TaskPlanningTools.js.map +1 -1
- package/dist/protocols/mcp/tools/TestTools.d.ts +15 -376
- package/dist/protocols/mcp/tools/TestTools.d.ts.map +1 -1
- package/dist/protocols/mcp/tools/TestTools.js +241 -363
- package/dist/protocols/mcp/tools/TestTools.js.map +1 -1
- package/dist/protocols/mcp/tools/TypeScriptTools.d.ts +6 -276
- package/dist/protocols/mcp/tools/TypeScriptTools.d.ts.map +1 -1
- package/dist/protocols/mcp/tools/TypeScriptTools.js +223 -337
- package/dist/protocols/mcp/tools/TypeScriptTools.js.map +1 -1
- package/dist/protocols/mcp/tools/WebTools.d.ts +15 -728
- package/dist/protocols/mcp/tools/WebTools.d.ts.map +1 -1
- package/dist/protocols/mcp/tools/WebTools.js +151 -257
- package/dist/protocols/mcp/tools/WebTools.js.map +1 -1
- package/dist/protocols/mcp/tools/shell/ShellExecuteHandler.d.ts +5 -3
- package/dist/protocols/mcp/tools/shell/ShellExecuteHandler.d.ts.map +1 -1
- package/dist/protocols/mcp/tools/shell/ShellExecuteHandler.js +31 -6
- package/dist/protocols/mcp/tools/shell/ShellExecuteHandler.js.map +1 -1
- package/dist/schemas/EventPayloadSchema.d.ts +21 -0
- package/dist/schemas/EventPayloadSchema.d.ts.map +1 -1
- package/dist/schemas/EventPayloadSchema.js +14 -0
- package/dist/schemas/EventPayloadSchema.js.map +1 -1
- package/dist/services/BackgroundTaskManager.d.ts.map +1 -1
- package/dist/services/BackgroundTaskManager.js +12 -4
- package/dist/services/BackgroundTaskManager.js.map +1 -1
- package/dist/services/BrowserManager.d.ts +1 -1
- package/dist/services/BrowserManager.d.ts.map +1 -1
- package/dist/services/BrowserManager.js +26 -3
- package/dist/services/BrowserManager.js.map +1 -1
- package/dist/services/MemoryCompressor.d.ts +11 -2
- package/dist/services/MemoryCompressor.d.ts.map +1 -1
- package/dist/services/MemoryCompressor.js +8 -26
- package/dist/services/MemoryCompressor.js.map +1 -1
- package/dist/services/MemoryService.d.ts +16 -3
- package/dist/services/MemoryService.d.ts.map +1 -1
- package/dist/services/MemoryService.js +79 -55
- package/dist/services/MemoryService.js.map +1 -1
- package/dist/services/PredictiveAnalyticsService.d.ts +34 -4
- package/dist/services/PredictiveAnalyticsService.d.ts.map +1 -1
- package/dist/services/PredictiveAnalyticsService.js +41 -25
- package/dist/services/PredictiveAnalyticsService.js.map +1 -1
- package/dist/services/QValueManager.d.ts +7 -0
- package/dist/services/QValueManager.d.ts.map +1 -1
- package/dist/services/QValueManager.js +9 -0
- package/dist/services/QValueManager.js.map +1 -1
- package/dist/services/RewardSignalProcessor.d.ts +38 -1
- package/dist/services/RewardSignalProcessor.d.ts.map +1 -1
- package/dist/services/RewardSignalProcessor.js +109 -7
- package/dist/services/RewardSignalProcessor.js.map +1 -1
- package/dist/services/SharedStateService.d.ts +16 -2
- package/dist/services/SharedStateService.d.ts.map +1 -1
- package/dist/services/SharedStateService.js +44 -3
- package/dist/services/SharedStateService.js.map +1 -1
- package/dist/services/TaskEffectivenessService.d.ts +34 -18
- package/dist/services/TaskEffectivenessService.d.ts.map +1 -1
- package/dist/services/TaskEffectivenessService.js +91 -155
- package/dist/services/TaskEffectivenessService.js.map +1 -1
- package/dist/services/WebSearchService.d.ts.map +1 -1
- package/dist/services/WebSearchService.js.map +1 -1
- package/dist/services/dag/TaskDagService.d.ts.map +1 -1
- package/dist/services/dag/TaskDagService.js +2 -0
- package/dist/services/dag/TaskDagService.js.map +1 -1
- package/dist/services/orpar-memory/OrparMemoryCoordinator.d.ts +7 -0
- package/dist/services/orpar-memory/OrparMemoryCoordinator.d.ts.map +1 -1
- package/dist/services/orpar-memory/OrparMemoryCoordinator.js +71 -10
- package/dist/services/orpar-memory/OrparMemoryCoordinator.js.map +1 -1
- package/dist/types/MemoryUtilityTypes.d.ts +2 -0
- package/dist/types/MemoryUtilityTypes.d.ts.map +1 -1
- package/dist/types/MemoryUtilityTypes.js.map +1 -1
- package/dist/utils/Logger.d.ts +43 -3
- package/dist/utils/Logger.d.ts.map +1 -1
- package/dist/utils/Logger.js +78 -36
- package/dist/utils/Logger.js.map +1 -1
- package/dist/utils/MxpEncryption.d.ts +19 -6
- package/dist/utils/MxpEncryption.d.ts.map +1 -1
- package/dist/utils/MxpEncryption.js +48 -16
- package/dist/utils/MxpEncryption.js.map +1 -1
- package/package.json +19 -4
- package/src/adapters/FrameworkAdapter.ts +1 -1
- package/src/config/ConfigManager.ts +52 -19
- package/src/config/memory-strata.config.ts +136 -0
- package/src/constants/ToolNames.ts +4 -18
- package/src/database/DatabaseAdapterFactory.ts +23 -6
- package/src/database/adapters/mongodb/MongoBaseRepository.ts +16 -2
- package/src/events/ClientEventBus.ts +68 -403
- package/src/events/EventBus.ts +7 -8
- package/src/events/EventBusBase.ts +479 -116
- package/src/events/EventNames.ts +6 -0
- package/src/events/PublicEvents.ts +7 -4
- package/src/events/ServerEventBus.ts +78 -473
- package/src/events/event-definitions/LlmBudgetEvents.ts +74 -0
- package/src/interfaces/IMemoryPersistence.ts +51 -0
- package/src/middleware/MxpMiddleware.ts +51 -24
- package/src/models/channelKey.ts +18 -4
- package/src/models/memoryUtility.ts +64 -0
- package/src/models/user.ts +36 -4
- package/src/mxp/BinaryProtocolLayer.ts +108 -124
- package/src/mxp/ContextCompressionEngine.ts +219 -161
- package/src/mxp/MxpTokenOptimizer.ts +10 -10
- package/src/prompts/MxfAgentSystemPrompt.ts +45 -55
- package/src/protocols/mcp/ToolError.ts +201 -0
- package/src/protocols/mcp/defineTool.ts +379 -0
- package/src/protocols/mcp/security/HttpTargetGuard.ts +267 -0
- package/src/protocols/mcp/security/McpSecurityGuard.ts +10 -3
- package/src/protocols/mcp/security/McpToolPolicy.ts +221 -0
- package/src/protocols/mcp/services/ExternalMcpServerManager.ts +340 -322
- package/src/protocols/mcp/services/ExternalServerConfigs.ts +82 -19
- package/src/protocols/mcp/tools/AnalyticsTools.ts +1 -1
- package/src/protocols/mcp/tools/CodeAnalysisTools.ts +15 -0
- package/src/protocols/mcp/tools/EffectivenessTools.ts +3 -3
- package/src/protocols/mcp/tools/GitTools.ts +290 -569
- package/src/protocols/mcp/tools/InfrastructureTools.ts +189 -43
- package/src/protocols/mcp/tools/MemorySearchTools.ts +77 -1
- package/src/protocols/mcp/tools/OrparTools.ts +87 -0
- package/src/protocols/mcp/tools/SafetyTools.ts +501 -579
- package/src/protocols/mcp/tools/TaskPlanningTools.ts +81 -39
- package/src/protocols/mcp/tools/TestTools.ts +339 -419
- package/src/protocols/mcp/tools/TypeScriptTools.ts +316 -376
- package/src/protocols/mcp/tools/WebTools.ts +209 -307
- package/src/protocols/mcp/tools/shell/ShellExecuteHandler.ts +53 -14
- package/src/schemas/EventPayloadSchema.ts +37 -0
- package/src/services/BackgroundTaskManager.ts +12 -4
- package/src/services/BrowserManager.ts +41 -1
- package/src/services/MemoryCompressor.ts +20 -32
- package/src/services/MemoryService.ts +96 -58
- package/src/services/PredictiveAnalyticsService.ts +55 -32
- package/src/services/QValueManager.ts +10 -0
- package/src/services/RewardSignalProcessor.ts +138 -9
- package/src/services/SharedStateService.ts +56 -8
- package/src/services/TaskEffectivenessService.ts +114 -187
- package/src/services/WebSearchService.ts +2 -1
- package/src/services/dag/TaskDagService.ts +2 -0
- package/src/services/orpar-memory/OrparMemoryCoordinator.ts +86 -10
- package/src/types/MemoryUtilityTypes.ts +2 -0
- package/src/utils/Logger.ts +116 -40
- package/src/utils/MxpEncryption.ts +69 -34
- package/dist/mxp/MxpEventForwardingEnhancer.d.ts +0 -134
- package/dist/mxp/MxpEventForwardingEnhancer.d.ts.map +0 -1
- package/dist/mxp/MxpEventForwardingEnhancer.js +0 -361
- package/dist/mxp/MxpEventForwardingEnhancer.js.map +0 -1
- package/dist/protocols/mcp/services/ToolSchemaEnhancements.d.ts +0 -56
- package/dist/protocols/mcp/services/ToolSchemaEnhancements.d.ts.map +0 -1
- package/dist/protocols/mcp/services/ToolSchemaEnhancements.js +0 -57
- package/dist/protocols/mcp/services/ToolSchemaEnhancements.js.map +0 -1
- package/dist/protocols/mcp/tools/ControlLoopLifecycle.d.ts +0 -270
- package/dist/protocols/mcp/tools/ControlLoopLifecycle.d.ts.map +0 -1
- package/dist/protocols/mcp/tools/ControlLoopLifecycle.js +0 -256
- package/dist/protocols/mcp/tools/ControlLoopLifecycle.js.map +0 -1
- package/dist/protocols/mcp/tools/LspTools.d.ts +0 -495
- package/dist/protocols/mcp/tools/LspTools.d.ts.map +0 -1
- package/dist/protocols/mcp/tools/LspTools.js +0 -469
- package/dist/protocols/mcp/tools/LspTools.js.map +0 -1
- package/src/mxp/MxpEventForwardingEnhancer.ts +0 -471
- package/src/protocols/mcp/services/ToolSchemaEnhancements.ts +0 -92
- package/src/protocols/mcp/tools/ControlLoopLifecycle.ts +0 -302
- package/src/protocols/mcp/tools/LspTools.ts +0 -476
|
@@ -17,12 +17,11 @@
|
|
|
17
17
|
* @repository https://github.com/BradA1878/model-exchange-framework
|
|
18
18
|
* @documentation https://mxf-dev.github.io/mxf/
|
|
19
19
|
*/
|
|
20
|
-
import { filter, map } from 'rxjs/operators';
|
|
21
20
|
import { ControlLoopEvents } from './event-definitions/ControlLoopEvents.js';
|
|
22
21
|
import { OrparEvents } from './event-definitions/OrparEvents.js';
|
|
23
22
|
import { McpEvents } from './event-definitions/McpEvents.js';
|
|
24
23
|
import { TaskEvents } from './event-definitions/TaskEvents.js';
|
|
25
|
-
import { BaseEventBusImplementation,
|
|
24
|
+
import { BaseEventBusImplementation, isReservedEvent } from './EventBusBase.js';
|
|
26
25
|
import { createStrictValidator } from '../utils/validation.js';
|
|
27
26
|
import { Logger } from '../utils/Logger.js';
|
|
28
27
|
// Create a logger instance for ServerEventBus
|
|
@@ -33,20 +32,45 @@ const validator = createStrictValidator('ServerEventBus');
|
|
|
33
32
|
* Server-side event bus implementation
|
|
34
33
|
*/
|
|
35
34
|
export class ServerEventBus extends BaseEventBusImplementation {
|
|
35
|
+
/**
|
|
36
|
+
* Events delivered to specific agents/channels by eventForwardingHandlers.
|
|
37
|
+
* Broadcasting these over io.emit() would deliver them twice.
|
|
38
|
+
*/
|
|
39
|
+
static AGENT_SPECIFIC_EVENTS = new Set([
|
|
40
|
+
...Object.values(ControlLoopEvents),
|
|
41
|
+
...Object.values(OrparEvents),
|
|
42
|
+
// MCP response events
|
|
43
|
+
McpEvents.TOOL_RESULT,
|
|
44
|
+
McpEvents.TOOL_ERROR,
|
|
45
|
+
McpEvents.TOOL_REGISTERED,
|
|
46
|
+
McpEvents.TOOL_UNREGISTERED,
|
|
47
|
+
McpEvents.MXF_TOOL_LIST_RESULT,
|
|
48
|
+
McpEvents.MXF_TOOL_LIST_ERROR,
|
|
49
|
+
McpEvents.RESOURCE_RESULT,
|
|
50
|
+
McpEvents.RESOURCE_ERROR,
|
|
51
|
+
McpEvents.EXTERNAL_SERVER_REGISTERED,
|
|
52
|
+
McpEvents.EXTERNAL_SERVER_UNREGISTERED,
|
|
53
|
+
McpEvents.EXTERNAL_SERVER_REGISTRATION_FAILED,
|
|
54
|
+
McpEvents.CHANNEL_SERVER_REGISTERED,
|
|
55
|
+
McpEvents.CHANNEL_SERVER_UNREGISTERED,
|
|
56
|
+
McpEvents.CHANNEL_SERVER_REGISTRATION_FAILED,
|
|
57
|
+
// Task lifecycle events
|
|
58
|
+
TaskEvents.CREATED,
|
|
59
|
+
TaskEvents.ASSIGNED,
|
|
60
|
+
TaskEvents.STARTED,
|
|
61
|
+
TaskEvents.PROGRESS_UPDATED,
|
|
62
|
+
TaskEvents.COMPLETED,
|
|
63
|
+
TaskEvents.FAILED,
|
|
64
|
+
TaskEvents.ERROR,
|
|
65
|
+
TaskEvents.CANCELLED,
|
|
66
|
+
]);
|
|
36
67
|
ioInstance = null;
|
|
37
|
-
subscriptions = [];
|
|
38
|
-
categorySubscriptions = new Map();
|
|
39
|
-
// Track subscriptions by event and handler for proper off() support
|
|
40
|
-
handlerSubscriptions = new Map();
|
|
41
|
-
debugMode = false;
|
|
42
|
-
debugSubscription = null;
|
|
43
68
|
/**
|
|
44
69
|
* Create a new ServerEventBus
|
|
45
70
|
* @param eventSubject Subject to use for events
|
|
46
71
|
*/
|
|
47
72
|
constructor(eventSubject) {
|
|
48
|
-
super(eventSubject);
|
|
49
|
-
//;
|
|
73
|
+
super(eventSubject, logger);
|
|
50
74
|
}
|
|
51
75
|
/**
|
|
52
76
|
* Set the Socket.IO server instance
|
|
@@ -75,337 +99,48 @@ export class ServerEventBus extends BaseEventBusImplementation {
|
|
|
75
99
|
return this;
|
|
76
100
|
}
|
|
77
101
|
/**
|
|
78
|
-
*
|
|
79
|
-
* All components listen to this event bus
|
|
102
|
+
* Forward an emitted event to the Socket.IO server.
|
|
80
103
|
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*/
|
|
84
|
-
emit(event, payload) {
|
|
85
|
-
try {
|
|
86
|
-
// Validate event name and payload
|
|
87
|
-
validateEventName(event);
|
|
88
|
-
this.validateEventPayload(event, payload);
|
|
89
|
-
// Handle null/undefined payload
|
|
90
|
-
if (payload === undefined || payload === null) {
|
|
91
|
-
logger.warn(`[ServerEventBus] Warning: Emitting event '${event}' with ${payload === null ? 'null' : 'undefined'} payload.`);
|
|
92
|
-
payload = {};
|
|
93
|
-
}
|
|
94
|
-
// Special logging for critical events like agent registration
|
|
95
|
-
if (event.startsWith('agent:')) {
|
|
96
|
-
}
|
|
97
|
-
// Emit to local event bus first
|
|
98
|
-
this.eventSubject.next({
|
|
99
|
-
type: event,
|
|
100
|
-
payload,
|
|
101
|
-
});
|
|
102
|
-
// Also emit to the Socket.IO server if available
|
|
103
|
-
// IMPORTANT: Do NOT broadcast agent-specific events via io.emit().
|
|
104
|
-
// These events are forwarded to specific agents/channels via
|
|
105
|
-
// eventForwardingHandlers.forwardEventToAgent()/forwardEventToChannel().
|
|
106
|
-
// Broadcasting them causes duplicates: the SDK's ClientEventBus.setupClientSocketForwarding()
|
|
107
|
-
// has socket.onAny() that re-injects received socket events back into the RxJS Subject,
|
|
108
|
-
// so MxfChannelMonitor sees each broadcast event twice (once from Subject push, once from
|
|
109
|
-
// socket re-injection).
|
|
110
|
-
const agentSpecificEvents = new Set([
|
|
111
|
-
...Object.values(ControlLoopEvents),
|
|
112
|
-
...Object.values(OrparEvents),
|
|
113
|
-
// MCP response events — already forwarded to specific agents via eventForwardingHandlers
|
|
114
|
-
McpEvents.TOOL_RESULT,
|
|
115
|
-
McpEvents.TOOL_ERROR,
|
|
116
|
-
McpEvents.TOOL_REGISTERED,
|
|
117
|
-
McpEvents.TOOL_UNREGISTERED,
|
|
118
|
-
McpEvents.MXF_TOOL_LIST_RESULT,
|
|
119
|
-
McpEvents.MXF_TOOL_LIST_ERROR,
|
|
120
|
-
McpEvents.RESOURCE_RESULT,
|
|
121
|
-
McpEvents.RESOURCE_ERROR,
|
|
122
|
-
McpEvents.EXTERNAL_SERVER_REGISTERED,
|
|
123
|
-
McpEvents.EXTERNAL_SERVER_UNREGISTERED,
|
|
124
|
-
McpEvents.EXTERNAL_SERVER_REGISTRATION_FAILED,
|
|
125
|
-
McpEvents.CHANNEL_SERVER_REGISTERED,
|
|
126
|
-
McpEvents.CHANNEL_SERVER_UNREGISTERED,
|
|
127
|
-
McpEvents.CHANNEL_SERVER_REGISTRATION_FAILED,
|
|
128
|
-
// Task lifecycle events — already forwarded to specific agents/channels
|
|
129
|
-
TaskEvents.CREATED,
|
|
130
|
-
TaskEvents.ASSIGNED,
|
|
131
|
-
TaskEvents.STARTED,
|
|
132
|
-
TaskEvents.PROGRESS_UPDATED,
|
|
133
|
-
TaskEvents.COMPLETED,
|
|
134
|
-
TaskEvents.FAILED,
|
|
135
|
-
TaskEvents.ERROR,
|
|
136
|
-
TaskEvents.CANCELLED,
|
|
137
|
-
]);
|
|
138
|
-
if (this.ioInstance && !isReservedEvent(event) && !agentSpecificEvents.has(event)) {
|
|
139
|
-
//;
|
|
140
|
-
this.ioInstance.emit(event, payload);
|
|
141
|
-
}
|
|
142
|
-
//;
|
|
143
|
-
}
|
|
144
|
-
catch (error) {
|
|
145
|
-
logger.error(`[ServerEventBus] Error emitting event '${event}':`, error instanceof Error ? error.message : String(error));
|
|
146
|
-
// Re-throw the error for the caller to handle
|
|
147
|
-
throw error;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Override the base on method to track handlers and subscriptions
|
|
152
|
-
* @param event Event name
|
|
153
|
-
* @param handler Event handler function
|
|
154
|
-
* @returns Subscription to use for unsubscribing
|
|
155
|
-
*/
|
|
156
|
-
on(event, handler) {
|
|
157
|
-
// Create a filtered observable for this event
|
|
158
|
-
const observable = this.eventSubject.pipe(filter((e) => e.type === event), map((e) => e.payload));
|
|
159
|
-
// Subscribe with throw/rejection isolation so one bad handler cannot
|
|
160
|
-
// kill the subscription or fail silently.
|
|
161
|
-
const subscription = observable.subscribe((payload) => invokeHandlerSafely(logger, event, handler, payload));
|
|
162
|
-
// Store the subscription for cleanup
|
|
163
|
-
this.subscriptions.push(subscription);
|
|
164
|
-
// Track handlers for off() support
|
|
165
|
-
if (!this.handlerSubscriptions.has(event)) {
|
|
166
|
-
this.handlerSubscriptions.set(event, new Map());
|
|
167
|
-
}
|
|
168
|
-
const eventHandlers = this.handlerSubscriptions.get(event);
|
|
169
|
-
if (eventHandlers) {
|
|
170
|
-
eventHandlers.set(handler, subscription);
|
|
171
|
-
}
|
|
172
|
-
return subscription;
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Override the base once method to track handlers and subscriptions
|
|
176
|
-
* Once the event is fired, the subscription is automatically removed
|
|
104
|
+
* Called by BaseEventBusImplementation.emit() after validation and local
|
|
105
|
+
* delivery.
|
|
177
106
|
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
107
|
+
* Agent-specific events are NOT broadcast with io.emit(). They are routed
|
|
108
|
+
* to individual agents/channels by eventForwardingHandlers. Broadcasting
|
|
109
|
+
* them would duplicate delivery: the SDK's ClientEventBus.setupClientSocketForwarding()
|
|
110
|
+
* re-injects everything the socket receives back into the shared RxJS Subject,
|
|
111
|
+
* so a broadcast event would be seen twice (once from the Subject push, once
|
|
112
|
+
* from the socket re-injection).
|
|
181
113
|
*/
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
// Create a wrapper handler that will unsubscribe after first execution
|
|
186
|
-
const onceHandler = (payload) => {
|
|
187
|
-
try {
|
|
188
|
-
invokeHandlerSafely(logger, event, handler, payload);
|
|
189
|
-
}
|
|
190
|
-
finally {
|
|
191
|
-
// Always unsubscribe — once means once, even when the handler throws.
|
|
192
|
-
this.off(event, onceHandler);
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
// Subscribe to the observable with the one-time handler
|
|
196
|
-
const subscription = observable.subscribe(onceHandler);
|
|
197
|
-
// Store the subscription for cleanup
|
|
198
|
-
this.subscriptions.push(subscription);
|
|
199
|
-
// Track handlers for off() support
|
|
200
|
-
if (!this.handlerSubscriptions.has(event)) {
|
|
201
|
-
this.handlerSubscriptions.set(event, new Map());
|
|
114
|
+
forwardToTransport(event, payload) {
|
|
115
|
+
if (!this.ioInstance) {
|
|
116
|
+
return;
|
|
202
117
|
}
|
|
203
|
-
const
|
|
204
|
-
if (
|
|
205
|
-
|
|
118
|
+
const eventName = String(event);
|
|
119
|
+
if (isReservedEvent(eventName) || ServerEventBus.AGENT_SPECIFIC_EVENTS.has(eventName)) {
|
|
120
|
+
return;
|
|
206
121
|
}
|
|
207
|
-
|
|
122
|
+
this.ioInstance.emit(eventName, payload);
|
|
208
123
|
}
|
|
209
124
|
/**
|
|
210
|
-
*
|
|
125
|
+
* Drop the Socket.IO server reference so no further events are broadcast.
|
|
126
|
+
*
|
|
127
|
+
* The bus attaches no listeners to the Socket.IO server — it only calls
|
|
128
|
+
* io.emit() — so there is nothing else to detach here.
|
|
211
129
|
*
|
|
212
|
-
* @param listener Listener function that receives both event type and payload
|
|
213
|
-
* @returns Subscription that can be unsubscribed to stop listening
|
|
214
|
-
*/
|
|
215
|
-
onAll(listener) {
|
|
216
|
-
// Create an observable that passes both event type and payload
|
|
217
|
-
const observable = this.eventSubject.pipe(map((e) => ({ type: e.type, payload: e.payload })));
|
|
218
|
-
// Subscribe to the observable with the listener
|
|
219
|
-
const subscription = observable.subscribe(event => {
|
|
220
|
-
listener(event.type, event.payload);
|
|
221
|
-
});
|
|
222
|
-
// Store the subscription for cleanup
|
|
223
|
-
this.subscriptions.push(subscription);
|
|
224
|
-
return subscription;
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Remove all server event listeners
|
|
228
130
|
* @returns this (for chaining)
|
|
229
131
|
*/
|
|
230
132
|
removeAllSocketListeners() {
|
|
231
|
-
|
|
232
|
-
try {
|
|
233
|
-
// Since Socket.IO Server doesn't have a direct equivalent to removeAllListeners(),
|
|
234
|
-
// we would need to track all listeners separately if we want to remove them.
|
|
235
|
-
// For now, we log that this operation is not fully implemented.
|
|
236
|
-
}
|
|
237
|
-
catch (error) {
|
|
238
|
-
logger.error('[ServerEventBus] Error removing socket listeners:', error instanceof Error ? error.message : String(error));
|
|
239
|
-
}
|
|
240
|
-
}
|
|
133
|
+
this.ioInstance = null;
|
|
241
134
|
return this;
|
|
242
135
|
}
|
|
243
136
|
/**
|
|
244
|
-
*
|
|
137
|
+
* Dispose every subscription and detach the Socket.IO server.
|
|
138
|
+
*
|
|
245
139
|
* @returns this (for chaining)
|
|
246
140
|
*/
|
|
247
141
|
cleanup() {
|
|
248
|
-
|
|
249
|
-
this.subscriptions.forEach(subscription => subscription.unsubscribe());
|
|
250
|
-
this.subscriptions = [];
|
|
251
|
-
// Clear category subscriptions
|
|
252
|
-
this.categorySubscriptions.clear();
|
|
253
|
-
// Remove socket listeners
|
|
142
|
+
this.removeAllListeners();
|
|
254
143
|
this.removeAllSocketListeners();
|
|
255
|
-
// Reset debug mode
|
|
256
|
-
this.debugMode = false;
|
|
257
|
-
this.debugSubscription = null;
|
|
258
|
-
return this;
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Enable or disable debug mode to log all events
|
|
262
|
-
*
|
|
263
|
-
* @param enabled Whether debug mode should be enabled
|
|
264
|
-
* @returns this (for chaining)
|
|
265
|
-
*/
|
|
266
|
-
enableDebugMode(enabled = true) {
|
|
267
|
-
// If already in the requested mode, do nothing
|
|
268
|
-
if (this.debugMode === enabled) {
|
|
269
|
-
return this;
|
|
270
|
-
}
|
|
271
|
-
this.debugMode = enabled;
|
|
272
|
-
// If enabling debug mode
|
|
273
|
-
if (enabled) {
|
|
274
|
-
// Create a subscription to all events
|
|
275
|
-
this.debugSubscription = this.onAll((eventType, payload) => {
|
|
276
|
-
// ;
|
|
277
|
-
});
|
|
278
|
-
// Make sure it's tracked for cleanup
|
|
279
|
-
if (this.debugSubscription) {
|
|
280
|
-
this.subscriptions.push(this.debugSubscription);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
// If disabling debug mode
|
|
284
|
-
else if (this.debugSubscription) {
|
|
285
|
-
// Unsubscribe from the debug subscription
|
|
286
|
-
this.debugSubscription.unsubscribe();
|
|
287
|
-
// Remove from subscriptions array
|
|
288
|
-
const index = this.subscriptions.indexOf(this.debugSubscription);
|
|
289
|
-
if (index !== -1) {
|
|
290
|
-
this.subscriptions.splice(index, 1);
|
|
291
|
-
}
|
|
292
|
-
this.debugSubscription = null;
|
|
293
|
-
}
|
|
294
|
-
return this;
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Subscribe to an event with category for grouped subscription management
|
|
298
|
-
*
|
|
299
|
-
* @param category Category name for grouping subscriptions
|
|
300
|
-
* @param event Event name to subscribe to
|
|
301
|
-
* @param listener Listener function to call when the event is emitted
|
|
302
|
-
* @returns Subscription that can be unsubscribed to stop listening
|
|
303
|
-
*/
|
|
304
|
-
onWithCategory(category, event, listener) {
|
|
305
|
-
// Create a subscription using the standard on method
|
|
306
|
-
const subscription = this.on(event, listener);
|
|
307
|
-
// Store in the category map
|
|
308
|
-
if (!this.categorySubscriptions.has(category)) {
|
|
309
|
-
this.categorySubscriptions.set(category, []);
|
|
310
|
-
}
|
|
311
|
-
const categorySubs = this.categorySubscriptions.get(category);
|
|
312
|
-
if (categorySubs) {
|
|
313
|
-
categorySubs.push(subscription);
|
|
314
|
-
}
|
|
315
|
-
// ;
|
|
316
|
-
return subscription;
|
|
317
|
-
}
|
|
318
|
-
/**
|
|
319
|
-
* Unsubscribe from all events in a specific category
|
|
320
|
-
*
|
|
321
|
-
* @param category Category name to unsubscribe from
|
|
322
|
-
* @returns this (for chaining)
|
|
323
|
-
*/
|
|
324
|
-
unsubscribeCategory(category) {
|
|
325
|
-
const subscriptions = this.categorySubscriptions.get(category) || [];
|
|
326
|
-
if (subscriptions.length > 0) {
|
|
327
|
-
// Unsubscribe from each subscription in the category
|
|
328
|
-
subscriptions.forEach(subscription => {
|
|
329
|
-
subscription.unsubscribe();
|
|
330
|
-
// Also remove from the main subscriptions array
|
|
331
|
-
const index = this.subscriptions.indexOf(subscription);
|
|
332
|
-
if (index !== -1) {
|
|
333
|
-
this.subscriptions.splice(index, 1);
|
|
334
|
-
}
|
|
335
|
-
});
|
|
336
|
-
// Clear the category
|
|
337
|
-
this.categorySubscriptions.delete(category);
|
|
338
|
-
}
|
|
339
|
-
else {
|
|
340
|
-
// ;
|
|
341
|
-
}
|
|
342
|
-
return this;
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* Unsubscribe from an event
|
|
346
|
-
* @param event Event name
|
|
347
|
-
* @param handler Event handler function (optional)
|
|
348
|
-
*/
|
|
349
|
-
off(event, handler) {
|
|
350
|
-
validateEventName(event);
|
|
351
|
-
const eventHandlers = this.handlerSubscriptions.get(event);
|
|
352
|
-
if (!eventHandlers) {
|
|
353
|
-
// No handlers for this event found
|
|
354
|
-
// ;
|
|
355
|
-
return;
|
|
356
|
-
}
|
|
357
|
-
if (handler) {
|
|
358
|
-
// If specific handler provided, just unsubscribe that one
|
|
359
|
-
const subscription = eventHandlers.get(handler);
|
|
360
|
-
if (subscription) {
|
|
361
|
-
// Unsubscribe from the RxJS subscription
|
|
362
|
-
subscription.unsubscribe();
|
|
363
|
-
// Remove from our handler registry
|
|
364
|
-
eventHandlers.delete(handler);
|
|
365
|
-
// Remove from the array if present
|
|
366
|
-
const index = this.subscriptions.indexOf(subscription);
|
|
367
|
-
if (index !== -1) {
|
|
368
|
-
this.subscriptions.splice(index, 1);
|
|
369
|
-
}
|
|
370
|
-
// ;
|
|
371
|
-
}
|
|
372
|
-
else {
|
|
373
|
-
// ;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
else {
|
|
377
|
-
// If no specific handler, unsubscribe all handlers for this event
|
|
378
|
-
let unsubscribedCount = 0;
|
|
379
|
-
eventHandlers.forEach((subscription) => {
|
|
380
|
-
// Unsubscribe from the RxJS subscription
|
|
381
|
-
subscription.unsubscribe();
|
|
382
|
-
// Remove from the array if present
|
|
383
|
-
const index = this.subscriptions.indexOf(subscription);
|
|
384
|
-
if (index !== -1) {
|
|
385
|
-
this.subscriptions.splice(index, 1);
|
|
386
|
-
}
|
|
387
|
-
unsubscribedCount++;
|
|
388
|
-
});
|
|
389
|
-
// Clear all handlers for this event
|
|
390
|
-
eventHandlers.clear();
|
|
391
|
-
// ;
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
/**
|
|
395
|
-
* Remove all event listeners for a specific event or all events
|
|
396
|
-
* @param event Optional specific event name to remove listeners for
|
|
397
|
-
* @returns this (for chaining)
|
|
398
|
-
*/
|
|
399
|
-
removeAllListeners(event) {
|
|
400
|
-
// Remove all event listeners
|
|
401
|
-
this.eventSubject.observers = [];
|
|
402
|
-
// Also clear our handler registries if appropriate
|
|
403
|
-
if (event) {
|
|
404
|
-
this.handlerSubscriptions.delete(event);
|
|
405
|
-
}
|
|
406
|
-
else {
|
|
407
|
-
this.handlerSubscriptions.clear();
|
|
408
|
-
}
|
|
409
144
|
return this;
|
|
410
145
|
}
|
|
411
146
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServerEventBus.js","sourceRoot":"","sources":["../../src/events/ServerEventBus.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;
|
|
1
|
+
{"version":3,"file":"ServerEventBus.js","sourceRoot":"","sources":["../../src/events/ServerEventBus.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2024 Brad Anderson
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
* @author Brad Anderson <BradA1878@pm.me>
|
|
17
|
+
* @repository https://github.com/BradA1878/model-exchange-framework
|
|
18
|
+
* @documentation https://mxf-dev.github.io/mxf/
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* LLM Budget Events
|
|
22
|
+
*
|
|
23
|
+
* Emitted as SystemLLM spend approaches and crosses its daily ceiling. SystemLLM runs on
|
|
24
|
+
* Claude Opus and had no absolute spend cap — only per-channel and global cooldowns — so
|
|
25
|
+
* a busy or looping channel could run up real cost with nothing to stop it. These events
|
|
26
|
+
* make that spend observable, and the EXCEEDED event marks the point where SystemLLM
|
|
27
|
+
* calls start being refused.
|
|
28
|
+
*/
|
|
29
|
+
import { AgentId, ChannelId } from '../../types/ChannelContext.js';
|
|
30
|
+
/**
|
|
31
|
+
* Events emitted as SystemLLM spend approaches and crosses the daily ceiling.
|
|
32
|
+
*/
|
|
33
|
+
export declare const LlmBudgetEvents: {
|
|
34
|
+
/** Spend crossed the warning threshold. SystemLLM is still running. */
|
|
35
|
+
readonly WARNING: "llm:budget:warning";
|
|
36
|
+
/** Spend reached the daily ceiling. SystemLLM calls are refused until reset. */
|
|
37
|
+
readonly EXCEEDED: "llm:budget:exceeded";
|
|
38
|
+
/** A new budget day started and spend went back to zero. */
|
|
39
|
+
readonly RESET: "llm:budget:reset";
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Spend figures carried by every budget event.
|
|
43
|
+
*/
|
|
44
|
+
export interface LlmBudgetEventData {
|
|
45
|
+
/** Money spent so far in the current budget day, in USD. */
|
|
46
|
+
spentUsd: number;
|
|
47
|
+
/** The daily ceiling, in USD. */
|
|
48
|
+
limitUsd: number;
|
|
49
|
+
/** Fraction of the ceiling used (spentUsd / limitUsd). */
|
|
50
|
+
utilization: number;
|
|
51
|
+
/** Start of the current budget day, as an ISO timestamp. */
|
|
52
|
+
periodStart: string;
|
|
53
|
+
/** Model whose call triggered the event, when there was one. */
|
|
54
|
+
model?: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Payload types for LLM budget events.
|
|
58
|
+
*/
|
|
59
|
+
export interface LlmBudgetPayloads {
|
|
60
|
+
'llm:budget:warning': LlmBudgetEventData;
|
|
61
|
+
'llm:budget:exceeded': LlmBudgetEventData;
|
|
62
|
+
'llm:budget:reset': LlmBudgetEventData;
|
|
63
|
+
}
|
|
64
|
+
/** Actor recorded on budget events. Spend is a property of the server, not an agent. */
|
|
65
|
+
export declare const LLM_BUDGET_ACTOR_ID: AgentId;
|
|
66
|
+
/** Channel recorded on budget events. The ceiling is global, not per channel. */
|
|
67
|
+
export declare const LLM_BUDGET_CHANNEL_ID: ChannelId;
|
|
68
|
+
//# sourceMappingURL=LlmBudgetEvents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LlmBudgetEvents.d.ts","sourceRoot":"","sources":["../../../src/events/event-definitions/LlmBudgetEvents.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH;;;;;;;;GAQG;AAEH,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAEnE;;GAEG;AACH,eAAO,MAAM,eAAe;IACxB,uEAAuE;;IAEvE,gFAAgF;;IAEhF,4DAA4D;;CAEtD,CAAC;AAEX;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAC/B,4DAA4D;IAC5D,QAAQ,EAAE,MAAM,CAAC;IACjB,iCAAiC;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,0DAA0D;IAC1D,WAAW,EAAE,MAAM,CAAC;IACpB,4DAA4D;IAC5D,WAAW,EAAE,MAAM,CAAC;IACpB,gEAAgE;IAChE,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAC9B,oBAAoB,EAAE,kBAAkB,CAAC;IACzC,qBAAqB,EAAE,kBAAkB,CAAC;IAC1C,kBAAkB,EAAE,kBAAkB,CAAC;CAC1C;AAED,wFAAwF;AACxF,eAAO,MAAM,mBAAmB,EAA0B,OAAO,CAAC;AAElE,iFAAiF;AACjF,eAAO,MAAM,qBAAqB,EAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2024 Brad Anderson
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
* @author Brad Anderson <BradA1878@pm.me>
|
|
17
|
+
* @repository https://github.com/BradA1878/model-exchange-framework
|
|
18
|
+
* @documentation https://mxf-dev.github.io/mxf/
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Events emitted as SystemLLM spend approaches and crosses the daily ceiling.
|
|
22
|
+
*/
|
|
23
|
+
export const LlmBudgetEvents = {
|
|
24
|
+
/** Spend crossed the warning threshold. SystemLLM is still running. */
|
|
25
|
+
WARNING: 'llm:budget:warning',
|
|
26
|
+
/** Spend reached the daily ceiling. SystemLLM calls are refused until reset. */
|
|
27
|
+
EXCEEDED: 'llm:budget:exceeded',
|
|
28
|
+
/** A new budget day started and spend went back to zero. */
|
|
29
|
+
RESET: 'llm:budget:reset'
|
|
30
|
+
};
|
|
31
|
+
/** Actor recorded on budget events. Spend is a property of the server, not an agent. */
|
|
32
|
+
export const LLM_BUDGET_ACTOR_ID = 'system-llm-budget';
|
|
33
|
+
/** Channel recorded on budget events. The ceiling is global, not per channel. */
|
|
34
|
+
export const LLM_BUDGET_CHANNEL_ID = 'global';
|
|
35
|
+
//# sourceMappingURL=LlmBudgetEvents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LlmBudgetEvents.js","sourceRoot":"","sources":["../../../src/events/event-definitions/LlmBudgetEvents.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAcH;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC3B,uEAAuE;IACvE,OAAO,EAAE,oBAAoB;IAC7B,gFAAgF;IAChF,QAAQ,EAAE,qBAAqB;IAC/B,4DAA4D;IAC5D,KAAK,EAAE,kBAAkB;CACnB,CAAC;AA2BX,wFAAwF;AACxF,MAAM,CAAC,MAAM,mBAAmB,GAAG,mBAA8B,CAAC;AAElE,iFAAiF;AACjF,MAAM,CAAC,MAAM,qBAAqB,GAAG,QAAqB,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory persistence contract.
|
|
3
|
+
*
|
|
4
|
+
* MemoryService lives in @mxf-dev/core but the concrete persistence implementation
|
|
5
|
+
* lives in the server (it owns the Mongoose connection). Core must not import from
|
|
6
|
+
* src/**, so the server injects its implementation into MemoryService at boot.
|
|
7
|
+
*
|
|
8
|
+
* This interface is that injection point. It exists so the dependency is typed:
|
|
9
|
+
* MemoryService previously held the persistence service as `any`, which allowed a
|
|
10
|
+
* call to `updateAgentMemoryUtility?.()` — a method that was never implemented — to
|
|
11
|
+
* compile and then silently no-op forever, discarding every learned Q-value. Typing
|
|
12
|
+
* the contract turns that class of mistake into a compile error.
|
|
13
|
+
*/
|
|
14
|
+
import { Observable } from 'rxjs';
|
|
15
|
+
import { IAgentMemory, IChannelMemory } from '../types/MemoryTypes.js';
|
|
16
|
+
import { MemoryUtilitySubdocument } from '../types/MemoryUtilityTypes.js';
|
|
17
|
+
export interface IMemoryPersistence {
|
|
18
|
+
/** Load an agent's memory document. */
|
|
19
|
+
getAgentMemory(agentId: string): Observable<IAgentMemory>;
|
|
20
|
+
/** Persist an agent's memory document. */
|
|
21
|
+
saveAgentMemory(memory: IAgentMemory): Observable<IAgentMemory>;
|
|
22
|
+
/** Persist a channel's memory document. */
|
|
23
|
+
saveChannelMemory(memory: IChannelMemory): Observable<IChannelMemory>;
|
|
24
|
+
/**
|
|
25
|
+
* Persist the MULS utility subdocument for a single memory.
|
|
26
|
+
*
|
|
27
|
+
* Called by QValueManager's persistence callback whenever a Q-value changes, and
|
|
28
|
+
* again when a dirty cache entry is evicted. Must throw on failure — a silent
|
|
29
|
+
* failure here means the system reports learning it did not retain.
|
|
30
|
+
*/
|
|
31
|
+
updateAgentMemoryUtility(memoryId: string, utility: Partial<MemoryUtilitySubdocument>): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Load utility subdocuments for a batch of memories.
|
|
34
|
+
*
|
|
35
|
+
* Used to hydrate the Q-value cache on retrieval so learning survives a restart.
|
|
36
|
+
* Memories with no stored utility are simply absent from the returned map; the
|
|
37
|
+
* caller falls back to the configured default Q-value for those.
|
|
38
|
+
*/
|
|
39
|
+
getAgentMemoryUtilities(memoryIds: string[]): Promise<Map<string, MemoryUtilitySubdocument>>;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=IMemoryPersistence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IMemoryPersistence.d.ts","sourceRoot":"","sources":["../../src/interfaces/IMemoryPersistence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAE1E,MAAM,WAAW,kBAAkB;IAC/B,uCAAuC;IACvC,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;IAE1D,0CAA0C;IAC1C,eAAe,CAAC,MAAM,EAAE,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;IAEhE,2CAA2C;IAC3C,iBAAiB,CAAC,MAAM,EAAE,cAAc,GAAG,UAAU,CAAC,cAAc,CAAC,CAAC;IAEtE;;;;;;OAMG;IACH,wBAAwB,CACpB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,OAAO,CAAC,wBAAwB,CAAC,GAC3C,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjB;;;;;;OAMG;IACH,uBAAuB,CACnB,SAAS,EAAE,MAAM,EAAE,GACpB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC,CAAC;CACrD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory persistence contract.
|
|
3
|
+
*
|
|
4
|
+
* MemoryService lives in @mxf-dev/core but the concrete persistence implementation
|
|
5
|
+
* lives in the server (it owns the Mongoose connection). Core must not import from
|
|
6
|
+
* src/**, so the server injects its implementation into MemoryService at boot.
|
|
7
|
+
*
|
|
8
|
+
* This interface is that injection point. It exists so the dependency is typed:
|
|
9
|
+
* MemoryService previously held the persistence service as `any`, which allowed a
|
|
10
|
+
* call to `updateAgentMemoryUtility?.()` — a method that was never implemented — to
|
|
11
|
+
* compile and then silently no-op forever, discarding every learned Q-value. Typing
|
|
12
|
+
* the contract turns that class of mistake into a compile error.
|
|
13
|
+
*/
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=IMemoryPersistence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IMemoryPersistence.js","sourceRoot":"","sources":["../../src/interfaces/IMemoryPersistence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG"}
|
|
@@ -50,7 +50,14 @@ export declare class MxpMiddleware {
|
|
|
50
50
|
*/
|
|
51
51
|
private static extractOperationArgs;
|
|
52
52
|
/**
|
|
53
|
-
* Handle encryption for MXP messages
|
|
53
|
+
* Handle encryption for MXP messages.
|
|
54
|
+
*
|
|
55
|
+
* `forceEncryption` means exactly that: if the message cannot be encrypted,
|
|
56
|
+
* this throws rather than putting the plaintext on the wire. An earlier
|
|
57
|
+
* version incremented an `encryptionFailures` counter and returned the
|
|
58
|
+
* message unencrypted, so callers that asked for encryption silently got none.
|
|
59
|
+
*
|
|
60
|
+
* @throws If forceEncryption is set and encryption is unavailable or fails.
|
|
54
61
|
*/
|
|
55
62
|
private static handleMxpEncryption;
|
|
56
63
|
/**
|