@mxf-dev/core 1.0.1 → 2.0.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.
Files changed (303) hide show
  1. package/README.md +18 -0
  2. package/dist/adapters/FrameworkAdapter.js +1 -1
  3. package/dist/adapters/FrameworkAdapter.js.map +1 -1
  4. package/dist/config/ConfigManager.d.ts +9 -8
  5. package/dist/config/ConfigManager.d.ts.map +1 -1
  6. package/dist/config/ConfigManager.js +47 -17
  7. package/dist/config/ConfigManager.js.map +1 -1
  8. package/dist/config/memory-strata.config.d.ts +25 -0
  9. package/dist/config/memory-strata.config.d.ts.map +1 -0
  10. package/dist/config/memory-strata.config.js +107 -0
  11. package/dist/config/memory-strata.config.js.map +1 -0
  12. package/dist/constants/ToolNames.d.ts +1 -29
  13. package/dist/constants/ToolNames.d.ts.map +1 -1
  14. package/dist/constants/ToolNames.js +4 -17
  15. package/dist/constants/ToolNames.js.map +1 -1
  16. package/dist/database/DatabaseAdapterFactory.d.ts +14 -2
  17. package/dist/database/DatabaseAdapterFactory.d.ts.map +1 -1
  18. package/dist/database/DatabaseAdapterFactory.js +21 -6
  19. package/dist/database/DatabaseAdapterFactory.js.map +1 -1
  20. package/dist/database/adapters/mongodb/MongoBaseRepository.d.ts +7 -1
  21. package/dist/database/adapters/mongodb/MongoBaseRepository.d.ts.map +1 -1
  22. package/dist/database/adapters/mongodb/MongoBaseRepository.js +12 -2
  23. package/dist/database/adapters/mongodb/MongoBaseRepository.js.map +1 -1
  24. package/dist/events/ClientEventBus.d.ts +16 -77
  25. package/dist/events/ClientEventBus.d.ts.map +1 -1
  26. package/dist/events/ClientEventBus.js +38 -311
  27. package/dist/events/ClientEventBus.js.map +1 -1
  28. package/dist/events/EventBus.d.ts +1 -1
  29. package/dist/events/EventBus.d.ts.map +1 -1
  30. package/dist/events/EventBus.js +5 -4
  31. package/dist/events/EventBus.js.map +1 -1
  32. package/dist/events/EventBusBase.d.ts +139 -34
  33. package/dist/events/EventBusBase.d.ts.map +1 -1
  34. package/dist/events/EventBusBase.js +366 -88
  35. package/dist/events/EventBusBase.js.map +1 -1
  36. package/dist/events/EventNames.d.ts +10 -1
  37. package/dist/events/EventNames.d.ts.map +1 -1
  38. package/dist/events/EventNames.js +3 -0
  39. package/dist/events/EventNames.js.map +1 -1
  40. package/dist/events/PublicEvents.d.ts +6 -2
  41. package/dist/events/PublicEvents.d.ts.map +1 -1
  42. package/dist/events/PublicEvents.js +7 -4
  43. package/dist/events/PublicEvents.js.map +1 -1
  44. package/dist/events/ServerEventBus.d.ts +23 -112
  45. package/dist/events/ServerEventBus.d.ts.map +1 -1
  46. package/dist/events/ServerEventBus.js +58 -323
  47. package/dist/events/ServerEventBus.js.map +1 -1
  48. package/dist/events/event-definitions/LlmBudgetEvents.d.ts +68 -0
  49. package/dist/events/event-definitions/LlmBudgetEvents.d.ts.map +1 -0
  50. package/dist/events/event-definitions/LlmBudgetEvents.js +35 -0
  51. package/dist/events/event-definitions/LlmBudgetEvents.js.map +1 -0
  52. package/dist/interfaces/IMemoryPersistence.d.ts +41 -0
  53. package/dist/interfaces/IMemoryPersistence.d.ts.map +1 -0
  54. package/dist/interfaces/IMemoryPersistence.js +15 -0
  55. package/dist/interfaces/IMemoryPersistence.js.map +1 -0
  56. package/dist/middleware/MxpMiddleware.d.ts +8 -1
  57. package/dist/middleware/MxpMiddleware.d.ts.map +1 -1
  58. package/dist/middleware/MxpMiddleware.js +42 -20
  59. package/dist/middleware/MxpMiddleware.js.map +1 -1
  60. package/dist/models/channelKey.d.ts +1 -0
  61. package/dist/models/channelKey.d.ts.map +1 -1
  62. package/dist/models/channelKey.js +5 -0
  63. package/dist/models/channelKey.js.map +1 -1
  64. package/dist/models/memoryUtility.d.ts +39 -0
  65. package/dist/models/memoryUtility.d.ts.map +1 -0
  66. package/dist/models/memoryUtility.js +39 -0
  67. package/dist/models/memoryUtility.js.map +1 -0
  68. package/dist/models/user.d.ts.map +1 -1
  69. package/dist/models/user.js +23 -1
  70. package/dist/models/user.js.map +1 -1
  71. package/dist/mxp/BinaryProtocolLayer.d.ts +24 -8
  72. package/dist/mxp/BinaryProtocolLayer.d.ts.map +1 -1
  73. package/dist/mxp/BinaryProtocolLayer.js +90 -103
  74. package/dist/mxp/BinaryProtocolLayer.js.map +1 -1
  75. package/dist/mxp/ContextCompressionEngine.d.ts +57 -10
  76. package/dist/mxp/ContextCompressionEngine.d.ts.map +1 -1
  77. package/dist/mxp/ContextCompressionEngine.js +170 -128
  78. package/dist/mxp/ContextCompressionEngine.js.map +1 -1
  79. package/dist/mxp/MxpTokenOptimizer.d.ts +7 -3
  80. package/dist/mxp/MxpTokenOptimizer.d.ts.map +1 -1
  81. package/dist/mxp/MxpTokenOptimizer.js +8 -5
  82. package/dist/mxp/MxpTokenOptimizer.js.map +1 -1
  83. package/dist/prompts/MxfAgentSystemPrompt.d.ts +1 -1
  84. package/dist/prompts/MxfAgentSystemPrompt.d.ts.map +1 -1
  85. package/dist/prompts/MxfAgentSystemPrompt.js +47 -57
  86. package/dist/prompts/MxfAgentSystemPrompt.js.map +1 -1
  87. package/dist/protocols/mcp/ToolError.d.ts +123 -0
  88. package/dist/protocols/mcp/ToolError.d.ts.map +1 -0
  89. package/dist/protocols/mcp/ToolError.js +108 -0
  90. package/dist/protocols/mcp/ToolError.js.map +1 -0
  91. package/dist/protocols/mcp/defineTool.d.ts +133 -0
  92. package/dist/protocols/mcp/defineTool.d.ts.map +1 -0
  93. package/dist/protocols/mcp/defineTool.js +236 -0
  94. package/dist/protocols/mcp/defineTool.js.map +1 -0
  95. package/dist/protocols/mcp/security/HttpTargetGuard.d.ts +38 -0
  96. package/dist/protocols/mcp/security/HttpTargetGuard.d.ts.map +1 -0
  97. package/dist/protocols/mcp/security/HttpTargetGuard.js +227 -0
  98. package/dist/protocols/mcp/security/HttpTargetGuard.js.map +1 -0
  99. package/dist/protocols/mcp/security/McpSecurityGuard.d.ts +9 -1
  100. package/dist/protocols/mcp/security/McpSecurityGuard.d.ts.map +1 -1
  101. package/dist/protocols/mcp/security/McpSecurityGuard.js +10 -2
  102. package/dist/protocols/mcp/security/McpSecurityGuard.js.map +1 -1
  103. package/dist/protocols/mcp/security/McpToolPolicy.d.ts +81 -0
  104. package/dist/protocols/mcp/security/McpToolPolicy.d.ts.map +1 -0
  105. package/dist/protocols/mcp/security/McpToolPolicy.js +202 -0
  106. package/dist/protocols/mcp/security/McpToolPolicy.js.map +1 -0
  107. package/dist/protocols/mcp/services/ExternalMcpServerManager.d.ts +51 -18
  108. package/dist/protocols/mcp/services/ExternalMcpServerManager.d.ts.map +1 -1
  109. package/dist/protocols/mcp/services/ExternalMcpServerManager.js +256 -283
  110. package/dist/protocols/mcp/services/ExternalMcpServerManager.js.map +1 -1
  111. package/dist/protocols/mcp/services/ExternalServerConfigs.d.ts +39 -6
  112. package/dist/protocols/mcp/services/ExternalServerConfigs.d.ts.map +1 -1
  113. package/dist/protocols/mcp/services/ExternalServerConfigs.js +76 -18
  114. package/dist/protocols/mcp/services/ExternalServerConfigs.js.map +1 -1
  115. package/dist/protocols/mcp/tools/AnalyticsTools.js +1 -1
  116. package/dist/protocols/mcp/tools/AnalyticsTools.js.map +1 -1
  117. package/dist/protocols/mcp/tools/CodeAnalysisTools.d.ts.map +1 -1
  118. package/dist/protocols/mcp/tools/CodeAnalysisTools.js +15 -0
  119. package/dist/protocols/mcp/tools/CodeAnalysisTools.js.map +1 -1
  120. package/dist/protocols/mcp/tools/EffectivenessTools.js +3 -3
  121. package/dist/protocols/mcp/tools/EffectivenessTools.js.map +1 -1
  122. package/dist/protocols/mcp/tools/GitTools.d.ts +9 -369
  123. package/dist/protocols/mcp/tools/GitTools.d.ts.map +1 -1
  124. package/dist/protocols/mcp/tools/GitTools.js +222 -517
  125. package/dist/protocols/mcp/tools/GitTools.js.map +1 -1
  126. package/dist/protocols/mcp/tools/InfrastructureTools.d.ts +56 -24
  127. package/dist/protocols/mcp/tools/InfrastructureTools.d.ts.map +1 -1
  128. package/dist/protocols/mcp/tools/InfrastructureTools.js +117 -26
  129. package/dist/protocols/mcp/tools/InfrastructureTools.js.map +1 -1
  130. package/dist/protocols/mcp/tools/MemorySearchTools.d.ts +0 -3
  131. package/dist/protocols/mcp/tools/MemorySearchTools.d.ts.map +1 -1
  132. package/dist/protocols/mcp/tools/MemorySearchTools.js +58 -1
  133. package/dist/protocols/mcp/tools/MemorySearchTools.js.map +1 -1
  134. package/dist/protocols/mcp/tools/OrparTools.d.ts +8 -0
  135. package/dist/protocols/mcp/tools/OrparTools.d.ts.map +1 -1
  136. package/dist/protocols/mcp/tools/OrparTools.js +66 -0
  137. package/dist/protocols/mcp/tools/OrparTools.js.map +1 -1
  138. package/dist/protocols/mcp/tools/SafetyTools.d.ts +7 -525
  139. package/dist/protocols/mcp/tools/SafetyTools.d.ts.map +1 -1
  140. package/dist/protocols/mcp/tools/SafetyTools.js +349 -514
  141. package/dist/protocols/mcp/tools/SafetyTools.js.map +1 -1
  142. package/dist/protocols/mcp/tools/TaskPlanningTools.d.ts.map +1 -1
  143. package/dist/protocols/mcp/tools/TaskPlanningTools.js +56 -26
  144. package/dist/protocols/mcp/tools/TaskPlanningTools.js.map +1 -1
  145. package/dist/protocols/mcp/tools/TestTools.d.ts +15 -376
  146. package/dist/protocols/mcp/tools/TestTools.d.ts.map +1 -1
  147. package/dist/protocols/mcp/tools/TestTools.js +241 -363
  148. package/dist/protocols/mcp/tools/TestTools.js.map +1 -1
  149. package/dist/protocols/mcp/tools/TypeScriptTools.d.ts +6 -276
  150. package/dist/protocols/mcp/tools/TypeScriptTools.d.ts.map +1 -1
  151. package/dist/protocols/mcp/tools/TypeScriptTools.js +223 -337
  152. package/dist/protocols/mcp/tools/TypeScriptTools.js.map +1 -1
  153. package/dist/protocols/mcp/tools/WebTools.d.ts +15 -728
  154. package/dist/protocols/mcp/tools/WebTools.d.ts.map +1 -1
  155. package/dist/protocols/mcp/tools/WebTools.js +151 -257
  156. package/dist/protocols/mcp/tools/WebTools.js.map +1 -1
  157. package/dist/protocols/mcp/tools/shell/ShellExecuteHandler.d.ts +5 -3
  158. package/dist/protocols/mcp/tools/shell/ShellExecuteHandler.d.ts.map +1 -1
  159. package/dist/protocols/mcp/tools/shell/ShellExecuteHandler.js +31 -6
  160. package/dist/protocols/mcp/tools/shell/ShellExecuteHandler.js.map +1 -1
  161. package/dist/schemas/EventPayloadSchema.d.ts +21 -0
  162. package/dist/schemas/EventPayloadSchema.d.ts.map +1 -1
  163. package/dist/schemas/EventPayloadSchema.js +14 -0
  164. package/dist/schemas/EventPayloadSchema.js.map +1 -1
  165. package/dist/services/BackgroundTaskManager.d.ts.map +1 -1
  166. package/dist/services/BackgroundTaskManager.js +12 -4
  167. package/dist/services/BackgroundTaskManager.js.map +1 -1
  168. package/dist/services/BrowserManager.d.ts +1 -1
  169. package/dist/services/BrowserManager.d.ts.map +1 -1
  170. package/dist/services/BrowserManager.js +26 -3
  171. package/dist/services/BrowserManager.js.map +1 -1
  172. package/dist/services/MemoryCompressor.d.ts +11 -2
  173. package/dist/services/MemoryCompressor.d.ts.map +1 -1
  174. package/dist/services/MemoryCompressor.js +8 -26
  175. package/dist/services/MemoryCompressor.js.map +1 -1
  176. package/dist/services/MemoryService.d.ts +16 -3
  177. package/dist/services/MemoryService.d.ts.map +1 -1
  178. package/dist/services/MemoryService.js +79 -55
  179. package/dist/services/MemoryService.js.map +1 -1
  180. package/dist/services/MxfMLService.d.ts +5 -0
  181. package/dist/services/MxfMLService.d.ts.map +1 -1
  182. package/dist/services/MxfMLService.js +32 -6
  183. package/dist/services/MxfMLService.js.map +1 -1
  184. package/dist/services/PredictiveAnalyticsService.d.ts +45 -9
  185. package/dist/services/PredictiveAnalyticsService.d.ts.map +1 -1
  186. package/dist/services/PredictiveAnalyticsService.js +82 -44
  187. package/dist/services/PredictiveAnalyticsService.js.map +1 -1
  188. package/dist/services/QValueManager.d.ts +7 -0
  189. package/dist/services/QValueManager.d.ts.map +1 -1
  190. package/dist/services/QValueManager.js +9 -0
  191. package/dist/services/QValueManager.js.map +1 -1
  192. package/dist/services/RewardSignalProcessor.d.ts +38 -1
  193. package/dist/services/RewardSignalProcessor.d.ts.map +1 -1
  194. package/dist/services/RewardSignalProcessor.js +109 -7
  195. package/dist/services/RewardSignalProcessor.js.map +1 -1
  196. package/dist/services/SharedStateService.d.ts +16 -2
  197. package/dist/services/SharedStateService.d.ts.map +1 -1
  198. package/dist/services/SharedStateService.js +44 -3
  199. package/dist/services/SharedStateService.js.map +1 -1
  200. package/dist/services/TaskEffectivenessService.d.ts +34 -18
  201. package/dist/services/TaskEffectivenessService.d.ts.map +1 -1
  202. package/dist/services/TaskEffectivenessService.js +91 -155
  203. package/dist/services/TaskEffectivenessService.js.map +1 -1
  204. package/dist/services/WebSearchService.d.ts.map +1 -1
  205. package/dist/services/WebSearchService.js.map +1 -1
  206. package/dist/services/dag/TaskDagService.d.ts.map +1 -1
  207. package/dist/services/dag/TaskDagService.js +2 -0
  208. package/dist/services/dag/TaskDagService.js.map +1 -1
  209. package/dist/services/orpar-memory/OrparMemoryCoordinator.d.ts +7 -0
  210. package/dist/services/orpar-memory/OrparMemoryCoordinator.d.ts.map +1 -1
  211. package/dist/services/orpar-memory/OrparMemoryCoordinator.js +71 -10
  212. package/dist/services/orpar-memory/OrparMemoryCoordinator.js.map +1 -1
  213. package/dist/types/MemoryUtilityTypes.d.ts +2 -0
  214. package/dist/types/MemoryUtilityTypes.d.ts.map +1 -1
  215. package/dist/types/MemoryUtilityTypes.js.map +1 -1
  216. package/dist/utils/Logger.d.ts +43 -3
  217. package/dist/utils/Logger.d.ts.map +1 -1
  218. package/dist/utils/Logger.js +78 -36
  219. package/dist/utils/Logger.js.map +1 -1
  220. package/dist/utils/MxpEncryption.d.ts +19 -6
  221. package/dist/utils/MxpEncryption.d.ts.map +1 -1
  222. package/dist/utils/MxpEncryption.js +48 -16
  223. package/dist/utils/MxpEncryption.js.map +1 -1
  224. package/package.json +19 -4
  225. package/src/adapters/FrameworkAdapter.ts +1 -1
  226. package/src/config/ConfigManager.ts +52 -19
  227. package/src/config/memory-strata.config.ts +136 -0
  228. package/src/constants/ToolNames.ts +4 -18
  229. package/src/database/DatabaseAdapterFactory.ts +23 -6
  230. package/src/database/adapters/mongodb/MongoBaseRepository.ts +16 -2
  231. package/src/events/ClientEventBus.ts +68 -403
  232. package/src/events/EventBus.ts +7 -8
  233. package/src/events/EventBusBase.ts +479 -116
  234. package/src/events/EventNames.ts +6 -0
  235. package/src/events/PublicEvents.ts +7 -4
  236. package/src/events/ServerEventBus.ts +78 -473
  237. package/src/events/event-definitions/LlmBudgetEvents.ts +74 -0
  238. package/src/interfaces/IMemoryPersistence.ts +51 -0
  239. package/src/middleware/MxpMiddleware.ts +51 -24
  240. package/src/models/channelKey.ts +18 -4
  241. package/src/models/memoryUtility.ts +64 -0
  242. package/src/models/user.ts +36 -4
  243. package/src/mxp/BinaryProtocolLayer.ts +108 -124
  244. package/src/mxp/ContextCompressionEngine.ts +219 -161
  245. package/src/mxp/MxpTokenOptimizer.ts +10 -10
  246. package/src/prompts/MxfAgentSystemPrompt.ts +45 -55
  247. package/src/protocols/mcp/ToolError.ts +201 -0
  248. package/src/protocols/mcp/defineTool.ts +379 -0
  249. package/src/protocols/mcp/security/HttpTargetGuard.ts +267 -0
  250. package/src/protocols/mcp/security/McpSecurityGuard.ts +10 -3
  251. package/src/protocols/mcp/security/McpToolPolicy.ts +221 -0
  252. package/src/protocols/mcp/services/ExternalMcpServerManager.ts +340 -322
  253. package/src/protocols/mcp/services/ExternalServerConfigs.ts +82 -19
  254. package/src/protocols/mcp/tools/AnalyticsTools.ts +1 -1
  255. package/src/protocols/mcp/tools/CodeAnalysisTools.ts +15 -0
  256. package/src/protocols/mcp/tools/EffectivenessTools.ts +3 -3
  257. package/src/protocols/mcp/tools/GitTools.ts +290 -569
  258. package/src/protocols/mcp/tools/InfrastructureTools.ts +189 -43
  259. package/src/protocols/mcp/tools/MemorySearchTools.ts +77 -1
  260. package/src/protocols/mcp/tools/OrparTools.ts +87 -0
  261. package/src/protocols/mcp/tools/SafetyTools.ts +501 -579
  262. package/src/protocols/mcp/tools/TaskPlanningTools.ts +81 -39
  263. package/src/protocols/mcp/tools/TestTools.ts +339 -419
  264. package/src/protocols/mcp/tools/TypeScriptTools.ts +316 -376
  265. package/src/protocols/mcp/tools/WebTools.ts +209 -307
  266. package/src/protocols/mcp/tools/shell/ShellExecuteHandler.ts +53 -14
  267. package/src/schemas/EventPayloadSchema.ts +37 -0
  268. package/src/services/BackgroundTaskManager.ts +12 -4
  269. package/src/services/BrowserManager.ts +41 -1
  270. package/src/services/MemoryCompressor.ts +20 -32
  271. package/src/services/MemoryService.ts +96 -58
  272. package/src/services/MxfMLService.ts +41 -7
  273. package/src/services/PredictiveAnalyticsService.ts +101 -51
  274. package/src/services/QValueManager.ts +10 -0
  275. package/src/services/RewardSignalProcessor.ts +138 -9
  276. package/src/services/SharedStateService.ts +56 -8
  277. package/src/services/TaskEffectivenessService.ts +114 -187
  278. package/src/services/WebSearchService.ts +2 -1
  279. package/src/services/dag/TaskDagService.ts +2 -0
  280. package/src/services/orpar-memory/OrparMemoryCoordinator.ts +86 -10
  281. package/src/types/MemoryUtilityTypes.ts +2 -0
  282. package/src/utils/Logger.ts +116 -40
  283. package/src/utils/MxpEncryption.ts +69 -34
  284. package/dist/mxp/MxpEventForwardingEnhancer.d.ts +0 -134
  285. package/dist/mxp/MxpEventForwardingEnhancer.d.ts.map +0 -1
  286. package/dist/mxp/MxpEventForwardingEnhancer.js +0 -361
  287. package/dist/mxp/MxpEventForwardingEnhancer.js.map +0 -1
  288. package/dist/protocols/mcp/services/ToolSchemaEnhancements.d.ts +0 -56
  289. package/dist/protocols/mcp/services/ToolSchemaEnhancements.d.ts.map +0 -1
  290. package/dist/protocols/mcp/services/ToolSchemaEnhancements.js +0 -57
  291. package/dist/protocols/mcp/services/ToolSchemaEnhancements.js.map +0 -1
  292. package/dist/protocols/mcp/tools/ControlLoopLifecycle.d.ts +0 -270
  293. package/dist/protocols/mcp/tools/ControlLoopLifecycle.d.ts.map +0 -1
  294. package/dist/protocols/mcp/tools/ControlLoopLifecycle.js +0 -256
  295. package/dist/protocols/mcp/tools/ControlLoopLifecycle.js.map +0 -1
  296. package/dist/protocols/mcp/tools/LspTools.d.ts +0 -495
  297. package/dist/protocols/mcp/tools/LspTools.d.ts.map +0 -1
  298. package/dist/protocols/mcp/tools/LspTools.js +0 -469
  299. package/dist/protocols/mcp/tools/LspTools.js.map +0 -1
  300. package/src/mxp/MxpEventForwardingEnhancer.ts +0 -471
  301. package/src/protocols/mcp/services/ToolSchemaEnhancements.ts +0 -92
  302. package/src/protocols/mcp/tools/ControlLoopLifecycle.ts +0 -302
  303. 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, validateEventName, isReservedEvent, invokeHandlerSafely } from './EventBusBase.js';
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
- * Emit an event to the server event bus
79
- * All components listen to this event bus
102
+ * Forward an emitted event to the Socket.IO server.
80
103
  *
81
- * @param event Event name
82
- * @param payload Event payload
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
- * @param event Event name
179
- * @param handler Event handler function
180
- * @returns Subscription to use for unsubscribing
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
- once(event, handler) {
183
- // Create a filtered observable for this event
184
- const observable = this.eventSubject.pipe(filter((e) => e.type === event), map((e) => e.payload));
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 eventHandlers = this.handlerSubscriptions.get(event);
204
- if (eventHandlers) {
205
- eventHandlers.set(handler, subscription);
118
+ const eventName = String(event);
119
+ if (isReservedEvent(eventName) || ServerEventBus.AGENT_SPECIFIC_EVENTS.has(eventName)) {
120
+ return;
206
121
  }
207
- return subscription;
122
+ this.ioInstance.emit(eventName, payload);
208
123
  }
209
124
  /**
210
- * Subscribe to all events in the server event bus
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
- if (this.ioInstance) {
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
- * Clean up all subscriptions and listeners
137
+ * Dispose every subscription and detach the Socket.IO server.
138
+ *
245
139
  * @returns this (for chaining)
246
140
  */
247
141
  cleanup() {
248
- // Clean up all subscriptions
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;AAWH,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAI7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAC/D,OAAO,EAEH,0BAA0B,EAI1B,iBAAiB,EACjB,eAAe,EACjB,mBAAmB,EAAa,MAAM,mBAAmB,CAAC;AAM5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,8CAA8C;AAC9C,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,gBAAgB,EAAE,QAAQ,CAAC,CAAC;AAE9D,uDAAuD;AACvD,MAAM,SA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AAwB;QAC3B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QAEvB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;OAIG;IACI,OAAO;QACV,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAC1B,IAAI,CAAC,wBAAwB,EAAE,CAAC;QAEhC,OAAO,IAAI,CAAC;IAChB,CAAC"}
@@ -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
  /**