@ixo/oracle-runtime 0.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 (583) hide show
  1. package/dist/bootstrap/ambient-factory.d.ts +32 -0
  2. package/dist/bootstrap/ambient-factory.d.ts.map +1 -0
  3. package/dist/bootstrap/ambient-factory.js +128 -0
  4. package/dist/bootstrap/create-oracle-app.d.ts +112 -0
  5. package/dist/bootstrap/create-oracle-app.d.ts.map +1 -0
  6. package/dist/bootstrap/create-oracle-app.js +530 -0
  7. package/dist/bootstrap/graceful-shutdown.d.ts +20 -0
  8. package/dist/bootstrap/graceful-shutdown.d.ts.map +1 -0
  9. package/dist/bootstrap/graceful-shutdown.js +61 -0
  10. package/dist/bootstrap/index.d.ts +13 -0
  11. package/dist/bootstrap/index.d.ts.map +1 -0
  12. package/dist/bootstrap/index.js +6 -0
  13. package/dist/bootstrap/inspect.d.ts +74 -0
  14. package/dist/bootstrap/inspect.d.ts.map +1 -0
  15. package/dist/bootstrap/inspect.js +111 -0
  16. package/dist/bootstrap/plugin-loader.d.ts +50 -0
  17. package/dist/bootstrap/plugin-loader.d.ts.map +1 -0
  18. package/dist/bootstrap/plugin-loader.js +119 -0
  19. package/dist/bootstrap/runtime-app-module.d.ts +38 -0
  20. package/dist/bootstrap/runtime-app-module.d.ts.map +1 -0
  21. package/dist/bootstrap/runtime-app-module.js +114 -0
  22. package/dist/bootstrap/schema-composer.d.ts +46 -0
  23. package/dist/bootstrap/schema-composer.d.ts.map +1 -0
  24. package/dist/bootstrap/schema-composer.js +65 -0
  25. package/dist/config/base-env-config.d.ts +31 -0
  26. package/dist/config/base-env-config.d.ts.map +1 -0
  27. package/dist/config/base-env-config.js +70 -0
  28. package/dist/config/base-env-schema.d.ts +77 -0
  29. package/dist/config/base-env-schema.d.ts.map +1 -0
  30. package/dist/config/base-env-schema.js +102 -0
  31. package/dist/events/scoped-emitter.d.ts +33 -0
  32. package/dist/events/scoped-emitter.d.ts.map +1 -0
  33. package/dist/events/scoped-emitter.js +32 -0
  34. package/dist/graph/index.d.ts +8 -0
  35. package/dist/graph/index.d.ts.map +1 -0
  36. package/dist/graph/index.js +6 -0
  37. package/dist/graph/main-agent-types.d.ts +88 -0
  38. package/dist/graph/main-agent-types.d.ts.map +1 -0
  39. package/dist/graph/main-agent-types.js +20 -0
  40. package/dist/graph/main-agent.d.ts +16 -0
  41. package/dist/graph/main-agent.d.ts.map +1 -0
  42. package/dist/graph/main-agent.js +251 -0
  43. package/dist/graph/middlewares/capability-gate-middleware.d.ts +35 -0
  44. package/dist/graph/middlewares/capability-gate-middleware.d.ts.map +1 -0
  45. package/dist/graph/middlewares/capability-gate-middleware.js +54 -0
  46. package/dist/graph/middlewares/index.d.ts +7 -0
  47. package/dist/graph/middlewares/index.d.ts.map +1 -0
  48. package/dist/graph/middlewares/index.js +6 -0
  49. package/dist/graph/middlewares/page-context-middleware.d.ts +23 -0
  50. package/dist/graph/middlewares/page-context-middleware.d.ts.map +1 -0
  51. package/dist/graph/middlewares/page-context-middleware.js +68 -0
  52. package/dist/graph/middlewares/safety-guardrail-middleware.d.ts +26 -0
  53. package/dist/graph/middlewares/safety-guardrail-middleware.d.ts.map +1 -0
  54. package/dist/graph/middlewares/safety-guardrail-middleware.js +88 -0
  55. package/dist/graph/middlewares/summarization-middleware.d.ts +17 -0
  56. package/dist/graph/middlewares/summarization-middleware.d.ts.map +1 -0
  57. package/dist/graph/middlewares/summarization-middleware.js +62 -0
  58. package/dist/graph/middlewares/tool-repetition-guard-middleware.d.ts +24 -0
  59. package/dist/graph/middlewares/tool-repetition-guard-middleware.d.ts.map +1 -0
  60. package/dist/graph/middlewares/tool-repetition-guard-middleware.js +112 -0
  61. package/dist/graph/middlewares/tool-validation-middleware.d.ts +24 -0
  62. package/dist/graph/middlewares/tool-validation-middleware.d.ts.map +1 -0
  63. package/dist/graph/middlewares/tool-validation-middleware.js +61 -0
  64. package/dist/graph/prompt-composer.d.ts +69 -0
  65. package/dist/graph/prompt-composer.d.ts.map +1 -0
  66. package/dist/graph/prompt-composer.js +315 -0
  67. package/dist/graph/state.d.ts +65 -0
  68. package/dist/graph/state.d.ts.map +1 -0
  69. package/dist/graph/state.js +60 -0
  70. package/dist/graph/sub-agent-fallback.d.ts +56 -0
  71. package/dist/graph/sub-agent-fallback.d.ts.map +1 -0
  72. package/dist/graph/sub-agent-fallback.js +79 -0
  73. package/dist/graph/subagent-as-tool.d.ts +77 -0
  74. package/dist/graph/subagent-as-tool.d.ts.map +1 -0
  75. package/dist/graph/subagent-as-tool.js +197 -0
  76. package/dist/graph/wrap-plugin-tool.d.ts +28 -0
  77. package/dist/graph/wrap-plugin-tool.d.ts.map +1 -0
  78. package/dist/graph/wrap-plugin-tool.js +30 -0
  79. package/dist/index.d.ts +33 -0
  80. package/dist/index.d.ts.map +1 -0
  81. package/dist/index.js +28 -0
  82. package/dist/llm/index.d.ts +2 -0
  83. package/dist/llm/index.d.ts.map +1 -0
  84. package/dist/llm/index.js +1 -0
  85. package/dist/llm/llm-provider.d.ts +41 -0
  86. package/dist/llm/llm-provider.d.ts.map +1 -0
  87. package/dist/llm/llm-provider.js +130 -0
  88. package/dist/manifest/index.d.ts +6 -0
  89. package/dist/manifest/index.d.ts.map +1 -0
  90. package/dist/manifest/index.js +3 -0
  91. package/dist/manifest/schema.d.ts +31 -0
  92. package/dist/manifest/schema.d.ts.map +1 -0
  93. package/dist/manifest/schema.js +44 -0
  94. package/dist/manifest/tier1-renderer.d.ts +31 -0
  95. package/dist/manifest/tier1-renderer.d.ts.map +1 -0
  96. package/dist/manifest/tier1-renderer.js +68 -0
  97. package/dist/manifest/validator.d.ts +34 -0
  98. package/dist/manifest/validator.d.ts.map +1 -0
  99. package/dist/manifest/validator.js +111 -0
  100. package/dist/matrix/checkpointer/matrix-upload-utils.d.ts +66 -0
  101. package/dist/matrix/checkpointer/matrix-upload-utils.d.ts.map +1 -0
  102. package/dist/matrix/checkpointer/matrix-upload-utils.js +228 -0
  103. package/dist/matrix/checkpointer/type.d.ts +4 -0
  104. package/dist/matrix/checkpointer/type.d.ts.map +1 -0
  105. package/dist/matrix/checkpointer/type.js +1 -0
  106. package/dist/matrix/checkpointer/user-matrix-sqlite-sync-service.module.d.ts +3 -0
  107. package/dist/matrix/checkpointer/user-matrix-sqlite-sync-service.module.d.ts.map +1 -0
  108. package/dist/matrix/checkpointer/user-matrix-sqlite-sync-service.module.js +22 -0
  109. package/dist/matrix/checkpointer/user-matrix-sqlite-sync-service.service.d.ts +93 -0
  110. package/dist/matrix/checkpointer/user-matrix-sqlite-sync-service.service.d.ts.map +1 -0
  111. package/dist/matrix/checkpointer/user-matrix-sqlite-sync-service.service.js +856 -0
  112. package/dist/matrix/room-membership.d.ts +11 -0
  113. package/dist/matrix/room-membership.d.ts.map +1 -0
  114. package/dist/matrix/room-membership.js +33 -0
  115. package/dist/meta-tools/index.d.ts +28 -0
  116. package/dist/meta-tools/index.d.ts.map +1 -0
  117. package/dist/meta-tools/index.js +24 -0
  118. package/dist/meta-tools/list-capabilities.d.ts +12 -0
  119. package/dist/meta-tools/list-capabilities.d.ts.map +1 -0
  120. package/dist/meta-tools/list-capabilities.js +55 -0
  121. package/dist/meta-tools/load-capability.d.ts +24 -0
  122. package/dist/meta-tools/load-capability.d.ts.map +1 -0
  123. package/dist/meta-tools/load-capability.js +82 -0
  124. package/dist/modules/auth/auth-header.middleware.d.ts +37 -0
  125. package/dist/modules/auth/auth-header.middleware.d.ts.map +1 -0
  126. package/dist/modules/auth/auth-header.middleware.js +115 -0
  127. package/dist/modules/auth/auth.module.d.ts +9 -0
  128. package/dist/modules/auth/auth.module.d.ts.map +1 -0
  129. package/dist/modules/auth/auth.module.js +27 -0
  130. package/dist/modules/auth/index.d.ts +3 -0
  131. package/dist/modules/auth/index.d.ts.map +1 -0
  132. package/dist/modules/auth/index.js +2 -0
  133. package/dist/modules/auth/validate-ucan-delegation.d.ts +31 -0
  134. package/dist/modules/auth/validate-ucan-delegation.d.ts.map +1 -0
  135. package/dist/modules/auth/validate-ucan-delegation.js +36 -0
  136. package/dist/modules/blob-store/blob-store.module.d.ts +10 -0
  137. package/dist/modules/blob-store/blob-store.module.d.ts.map +1 -0
  138. package/dist/modules/blob-store/blob-store.module.js +25 -0
  139. package/dist/modules/blob-store/blob-store.service.d.ts +66 -0
  140. package/dist/modules/blob-store/blob-store.service.d.ts.map +1 -0
  141. package/dist/modules/blob-store/blob-store.service.js +108 -0
  142. package/dist/modules/blob-store/index.d.ts +3 -0
  143. package/dist/modules/blob-store/index.d.ts.map +1 -0
  144. package/dist/modules/blob-store/index.js +2 -0
  145. package/dist/modules/health/health.controller.d.ts +18 -0
  146. package/dist/modules/health/health.controller.d.ts.map +1 -0
  147. package/dist/modules/health/health.controller.js +48 -0
  148. package/dist/modules/health/health.module.d.ts +8 -0
  149. package/dist/modules/health/health.module.d.ts.map +1 -0
  150. package/dist/modules/health/health.module.js +21 -0
  151. package/dist/modules/index.d.ts +8 -0
  152. package/dist/modules/index.d.ts.map +1 -0
  153. package/dist/modules/index.js +6 -0
  154. package/dist/modules/messages/__test-fixtures__/deps.d.ts +41 -0
  155. package/dist/modules/messages/__test-fixtures__/deps.d.ts.map +1 -0
  156. package/dist/modules/messages/__test-fixtures__/deps.js +73 -0
  157. package/dist/modules/messages/__test-fixtures__/fake-agent.d.ts +27 -0
  158. package/dist/modules/messages/__test-fixtures__/fake-agent.d.ts.map +1 -0
  159. package/dist/modules/messages/__test-fixtures__/fake-agent.js +41 -0
  160. package/dist/modules/messages/__test-fixtures__/fake-response.d.ts +29 -0
  161. package/dist/modules/messages/__test-fixtures__/fake-response.d.ts.map +1 -0
  162. package/dist/modules/messages/__test-fixtures__/fake-response.js +55 -0
  163. package/dist/modules/messages/agent-builder.d.ts +64 -0
  164. package/dist/modules/messages/agent-builder.d.ts.map +1 -0
  165. package/dist/modules/messages/agent-builder.js +219 -0
  166. package/dist/modules/messages/batch-invoker.d.ts +36 -0
  167. package/dist/modules/messages/batch-invoker.d.ts.map +1 -0
  168. package/dist/modules/messages/batch-invoker.js +58 -0
  169. package/dist/modules/messages/dto/list-messages.dto.d.ts +4 -0
  170. package/dist/modules/messages/dto/list-messages.dto.d.ts.map +1 -0
  171. package/dist/modules/messages/dto/list-messages.dto.js +17 -0
  172. package/dist/modules/messages/dto/send-message.dto.d.ts +73 -0
  173. package/dist/modules/messages/dto/send-message.dto.d.ts.map +1 -0
  174. package/dist/modules/messages/dto/send-message.dto.js +318 -0
  175. package/dist/modules/messages/file-processing-credit-sink.port.d.ts +20 -0
  176. package/dist/modules/messages/file-processing-credit-sink.port.d.ts.map +1 -0
  177. package/dist/modules/messages/file-processing-credit-sink.port.js +1 -0
  178. package/dist/modules/messages/file-processing.service.d.ts +195 -0
  179. package/dist/modules/messages/file-processing.service.d.ts.map +1 -0
  180. package/dist/modules/messages/file-processing.service.js +1278 -0
  181. package/dist/modules/messages/homeserver-cache.d.ts +11 -0
  182. package/dist/modules/messages/homeserver-cache.d.ts.map +1 -0
  183. package/dist/modules/messages/homeserver-cache.js +31 -0
  184. package/dist/modules/messages/matrix-listener-bridge.d.ts +63 -0
  185. package/dist/modules/messages/matrix-listener-bridge.d.ts.map +1 -0
  186. package/dist/modules/messages/matrix-listener-bridge.js +280 -0
  187. package/dist/modules/messages/messages.controller.d.ts +13 -0
  188. package/dist/modules/messages/messages.controller.d.ts.map +1 -0
  189. package/dist/modules/messages/messages.controller.js +95 -0
  190. package/dist/modules/messages/messages.module.d.ts +3 -0
  191. package/dist/modules/messages/messages.module.d.ts.map +1 -0
  192. package/dist/modules/messages/messages.module.js +75 -0
  193. package/dist/modules/messages/messages.service.d.ts +112 -0
  194. package/dist/modules/messages/messages.service.d.ts.map +1 -0
  195. package/dist/modules/messages/messages.service.js +279 -0
  196. package/dist/modules/messages/oracle-runtime-bundle.d.ts +38 -0
  197. package/dist/modules/messages/oracle-runtime-bundle.d.ts.map +1 -0
  198. package/dist/modules/messages/oracle-runtime-bundle.js +40 -0
  199. package/dist/modules/messages/post-message-syncer.d.ts +30 -0
  200. package/dist/modules/messages/post-message-syncer.d.ts.map +1 -0
  201. package/dist/modules/messages/post-message-syncer.js +73 -0
  202. package/dist/modules/messages/request-preparer.d.ts +53 -0
  203. package/dist/modules/messages/request-preparer.d.ts.map +1 -0
  204. package/dist/modules/messages/request-preparer.js +139 -0
  205. package/dist/modules/messages/sse-stream-runner.d.ts +73 -0
  206. package/dist/modules/messages/sse-stream-runner.d.ts.map +1 -0
  207. package/dist/modules/messages/sse-stream-runner.js +352 -0
  208. package/dist/modules/messages/sse.utils.d.ts +29 -0
  209. package/dist/modules/messages/sse.utils.d.ts.map +1 -0
  210. package/dist/modules/messages/sse.utils.js +77 -0
  211. package/dist/modules/messages/user-context-fetcher.d.ts +41 -0
  212. package/dist/modules/messages/user-context-fetcher.d.ts.map +1 -0
  213. package/dist/modules/messages/user-context-fetcher.js +117 -0
  214. package/dist/modules/secrets/index.d.ts +2 -0
  215. package/dist/modules/secrets/index.d.ts.map +1 -0
  216. package/dist/modules/secrets/index.js +1 -0
  217. package/dist/modules/secrets/secrets.service.d.ts +29 -0
  218. package/dist/modules/secrets/secrets.service.d.ts.map +1 -0
  219. package/dist/modules/secrets/secrets.service.js +107 -0
  220. package/dist/modules/sessions/dto/create-session.dto.d.ts +6 -0
  221. package/dist/modules/sessions/dto/create-session.dto.d.ts.map +1 -0
  222. package/dist/modules/sessions/dto/create-session.dto.js +5 -0
  223. package/dist/modules/sessions/dto/delete-session.dto.d.ts +6 -0
  224. package/dist/modules/sessions/dto/delete-session.dto.d.ts.map +1 -0
  225. package/dist/modules/sessions/dto/delete-session.dto.js +5 -0
  226. package/dist/modules/sessions/dto/list-sessions.dto.d.ts +7 -0
  227. package/dist/modules/sessions/dto/list-sessions.dto.d.ts.map +1 -0
  228. package/dist/modules/sessions/dto/list-sessions.dto.js +6 -0
  229. package/dist/modules/sessions/session-history-processor.service.d.ts +48 -0
  230. package/dist/modules/sessions/session-history-processor.service.d.ts.map +1 -0
  231. package/dist/modules/sessions/session-history-processor.service.js +254 -0
  232. package/dist/modules/sessions/sessions.controller.d.ts +13 -0
  233. package/dist/modules/sessions/sessions.controller.d.ts.map +1 -0
  234. package/dist/modules/sessions/sessions.controller.js +113 -0
  235. package/dist/modules/sessions/sessions.module.d.ts +3 -0
  236. package/dist/modules/sessions/sessions.module.d.ts.map +1 -0
  237. package/dist/modules/sessions/sessions.module.js +49 -0
  238. package/dist/modules/sessions/sessions.service.d.ts +23 -0
  239. package/dist/modules/sessions/sessions.service.d.ts.map +1 -0
  240. package/dist/modules/sessions/sessions.service.js +168 -0
  241. package/dist/modules/subscription/subscription.middleware.d.ts +37 -0
  242. package/dist/modules/subscription/subscription.middleware.d.ts.map +1 -0
  243. package/dist/modules/subscription/subscription.middleware.js +141 -0
  244. package/dist/modules/subscription/subscription.module.d.ts +12 -0
  245. package/dist/modules/subscription/subscription.module.d.ts.map +1 -0
  246. package/dist/modules/subscription/subscription.module.js +26 -0
  247. package/dist/modules/throttler/throttler.module.d.ts +11 -0
  248. package/dist/modules/throttler/throttler.module.d.ts.map +1 -0
  249. package/dist/modules/throttler/throttler.module.js +32 -0
  250. package/dist/modules/ucan/index.d.ts +7 -0
  251. package/dist/modules/ucan/index.d.ts.map +1 -0
  252. package/dist/modules/ucan/index.js +6 -0
  253. package/dist/modules/ucan/ucan.config.d.ts +87 -0
  254. package/dist/modules/ucan/ucan.config.d.ts.map +1 -0
  255. package/dist/modules/ucan/ucan.config.js +114 -0
  256. package/dist/modules/ucan/ucan.module.d.ts +29 -0
  257. package/dist/modules/ucan/ucan.module.d.ts.map +1 -0
  258. package/dist/modules/ucan/ucan.module.js +46 -0
  259. package/dist/modules/ucan/ucan.service.d.ts +129 -0
  260. package/dist/modules/ucan/ucan.service.d.ts.map +1 -0
  261. package/dist/modules/ucan/ucan.service.js +582 -0
  262. package/dist/modules/ws/emitter.d.ts +12 -0
  263. package/dist/modules/ws/emitter.d.ts.map +1 -0
  264. package/dist/modules/ws/emitter.js +12 -0
  265. package/dist/modules/ws/ws.gateway.d.ts +34 -0
  266. package/dist/modules/ws/ws.gateway.d.ts.map +1 -0
  267. package/dist/modules/ws/ws.gateway.js +241 -0
  268. package/dist/modules/ws/ws.module.d.ts +3 -0
  269. package/dist/modules/ws/ws.module.d.ts.map +1 -0
  270. package/dist/modules/ws/ws.module.js +21 -0
  271. package/dist/modules/ws/ws.service.d.ts +25 -0
  272. package/dist/modules/ws/ws.service.d.ts.map +1 -0
  273. package/dist/modules/ws/ws.service.js +113 -0
  274. package/dist/plugin-api/define-plugin.d.ts +19 -0
  275. package/dist/plugin-api/define-plugin.d.ts.map +1 -0
  276. package/dist/plugin-api/define-plugin.js +25 -0
  277. package/dist/plugin-api/oracle-plugin.d.ts +92 -0
  278. package/dist/plugin-api/oracle-plugin.d.ts.map +1 -0
  279. package/dist/plugin-api/oracle-plugin.js +15 -0
  280. package/dist/plugin-api/tool-helper.d.ts +33 -0
  281. package/dist/plugin-api/tool-helper.d.ts.map +1 -0
  282. package/dist/plugin-api/tool-helper.js +40 -0
  283. package/dist/plugin-api/types.d.ts +378 -0
  284. package/dist/plugin-api/types.d.ts.map +1 -0
  285. package/dist/plugin-api/types.js +1 -0
  286. package/dist/plugins/agui/agui-agent.d.ts +10 -0
  287. package/dist/plugins/agui/agui-agent.d.ts.map +1 -0
  288. package/dist/plugins/agui/agui-agent.js +110 -0
  289. package/dist/plugins/agui/agui.plugin.d.ts +16 -0
  290. package/dist/plugins/agui/agui.plugin.d.ts.map +1 -0
  291. package/dist/plugins/agui/agui.plugin.js +117 -0
  292. package/dist/plugins/agui/index.d.ts +3 -0
  293. package/dist/plugins/agui/index.d.ts.map +1 -0
  294. package/dist/plugins/agui/index.js +2 -0
  295. package/dist/plugins/composio/composio-tools.d.ts +59 -0
  296. package/dist/plugins/composio/composio-tools.d.ts.map +1 -0
  297. package/dist/plugins/composio/composio-tools.js +88 -0
  298. package/dist/plugins/composio/composio-ucan.d.ts +14 -0
  299. package/dist/plugins/composio/composio-ucan.d.ts.map +1 -0
  300. package/dist/plugins/composio/composio-ucan.js +32 -0
  301. package/dist/plugins/composio/composio.plugin.d.ts +45 -0
  302. package/dist/plugins/composio/composio.plugin.d.ts.map +1 -0
  303. package/dist/plugins/composio/composio.plugin.js +116 -0
  304. package/dist/plugins/composio/index.d.ts +4 -0
  305. package/dist/plugins/composio/index.d.ts.map +1 -0
  306. package/dist/plugins/composio/index.js +3 -0
  307. package/dist/plugins/credits/claim-processing.module.d.ts +28 -0
  308. package/dist/plugins/credits/claim-processing.module.d.ts.map +1 -0
  309. package/dist/plugins/credits/claim-processing.module.js +37 -0
  310. package/dist/plugins/credits/claim-processing.service.d.ts +92 -0
  311. package/dist/plugins/credits/claim-processing.service.d.ts.map +1 -0
  312. package/dist/plugins/credits/claim-processing.service.js +406 -0
  313. package/dist/plugins/credits/credits-middleware.d.ts +23 -0
  314. package/dist/plugins/credits/credits-middleware.d.ts.map +1 -0
  315. package/dist/plugins/credits/credits-middleware.js +154 -0
  316. package/dist/plugins/credits/credits.plugin.d.ts +55 -0
  317. package/dist/plugins/credits/credits.plugin.d.ts.map +1 -0
  318. package/dist/plugins/credits/credits.plugin.js +95 -0
  319. package/dist/plugins/credits/file-processing-sink.module.d.ts +18 -0
  320. package/dist/plugins/credits/file-processing-sink.module.d.ts.map +1 -0
  321. package/dist/plugins/credits/file-processing-sink.module.js +56 -0
  322. package/dist/plugins/credits/index.d.ts +8 -0
  323. package/dist/plugins/credits/index.d.ts.map +1 -0
  324. package/dist/plugins/credits/index.js +7 -0
  325. package/dist/plugins/credits/subscription-sink.module.d.ts +23 -0
  326. package/dist/plugins/credits/subscription-sink.module.d.ts.map +1 -0
  327. package/dist/plugins/credits/subscription-sink.module.js +54 -0
  328. package/dist/plugins/credits/token-limiter.d.ts +139 -0
  329. package/dist/plugins/credits/token-limiter.d.ts.map +1 -0
  330. package/dist/plugins/credits/token-limiter.js +302 -0
  331. package/dist/plugins/domain-indexer/domain-indexer-agent.d.ts +7 -0
  332. package/dist/plugins/domain-indexer/domain-indexer-agent.d.ts.map +1 -0
  333. package/dist/plugins/domain-indexer/domain-indexer-agent.js +48 -0
  334. package/dist/plugins/domain-indexer/domain-indexer-tools.d.ts +8 -0
  335. package/dist/plugins/domain-indexer/domain-indexer-tools.d.ts.map +1 -0
  336. package/dist/plugins/domain-indexer/domain-indexer-tools.js +194 -0
  337. package/dist/plugins/domain-indexer/domain-indexer.plugin.d.ts +20 -0
  338. package/dist/plugins/domain-indexer/domain-indexer.plugin.d.ts.map +1 -0
  339. package/dist/plugins/domain-indexer/domain-indexer.plugin.js +78 -0
  340. package/dist/plugins/domain-indexer/index.d.ts +2 -0
  341. package/dist/plugins/domain-indexer/index.d.ts.map +1 -0
  342. package/dist/plugins/domain-indexer/index.js +1 -0
  343. package/dist/plugins/editor/apply-sandbox-output.d.ts +33 -0
  344. package/dist/plugins/editor/apply-sandbox-output.d.ts.map +1 -0
  345. package/dist/plugins/editor/apply-sandbox-output.js +302 -0
  346. package/dist/plugins/editor/block-actions.d.ts +84 -0
  347. package/dist/plugins/editor/block-actions.d.ts.map +1 -0
  348. package/dist/plugins/editor/block-actions.js +471 -0
  349. package/dist/plugins/editor/blocknote-helper.d.ts +147 -0
  350. package/dist/plugins/editor/blocknote-helper.d.ts.map +1 -0
  351. package/dist/plugins/editor/blocknote-helper.js +542 -0
  352. package/dist/plugins/editor/blocknote-tools.d.ts +364 -0
  353. package/dist/plugins/editor/blocknote-tools.d.ts.map +1 -0
  354. package/dist/plugins/editor/blocknote-tools.js +2123 -0
  355. package/dist/plugins/editor/editor-agent.d.ts +47 -0
  356. package/dist/plugins/editor/editor-agent.d.ts.map +1 -0
  357. package/dist/plugins/editor/editor-agent.js +158 -0
  358. package/dist/plugins/editor/editor-mx.d.ts +56 -0
  359. package/dist/plugins/editor/editor-mx.d.ts.map +1 -0
  360. package/dist/plugins/editor/editor-mx.js +100 -0
  361. package/dist/plugins/editor/editor.plugin.d.ts +32 -0
  362. package/dist/plugins/editor/editor.plugin.d.ts.map +1 -0
  363. package/dist/plugins/editor/editor.plugin.js +189 -0
  364. package/dist/plugins/editor/index.d.ts +6 -0
  365. package/dist/plugins/editor/index.d.ts.map +1 -0
  366. package/dist/plugins/editor/index.js +5 -0
  367. package/dist/plugins/editor/mint-invocation-tool.d.ts +72 -0
  368. package/dist/plugins/editor/mint-invocation-tool.d.ts.map +1 -0
  369. package/dist/plugins/editor/mint-invocation-tool.js +173 -0
  370. package/dist/plugins/editor/page-functions.d.ts +100 -0
  371. package/dist/plugins/editor/page-functions.d.ts.map +1 -0
  372. package/dist/plugins/editor/page-functions.js +317 -0
  373. package/dist/plugins/editor/page-tools.d.ts +75 -0
  374. package/dist/plugins/editor/page-tools.d.ts.map +1 -0
  375. package/dist/plugins/editor/page-tools.js +238 -0
  376. package/dist/plugins/editor/prompts.d.ts +22 -0
  377. package/dist/plugins/editor/prompts.d.ts.map +1 -0
  378. package/dist/plugins/editor/prompts.js +451 -0
  379. package/dist/plugins/editor/provider.d.ts +101 -0
  380. package/dist/plugins/editor/provider.d.ts.map +1 -0
  381. package/dist/plugins/editor/provider.js +249 -0
  382. package/dist/plugins/editor/standalone-editor-tool.d.ts +17 -0
  383. package/dist/plugins/editor/standalone-editor-tool.d.ts.map +1 -0
  384. package/dist/plugins/editor/standalone-editor-tool.js +136 -0
  385. package/dist/plugins/editor/survey-helpers.d.ts +112 -0
  386. package/dist/plugins/editor/survey-helpers.d.ts.map +1 -0
  387. package/dist/plugins/editor/survey-helpers.js +358 -0
  388. package/dist/plugins/firecrawl/firecrawl-agent.d.ts +7 -0
  389. package/dist/plugins/firecrawl/firecrawl-agent.d.ts.map +1 -0
  390. package/dist/plugins/firecrawl/firecrawl-agent.js +84 -0
  391. package/dist/plugins/firecrawl/firecrawl-tools.d.ts +37 -0
  392. package/dist/plugins/firecrawl/firecrawl-tools.d.ts.map +1 -0
  393. package/dist/plugins/firecrawl/firecrawl-tools.js +129 -0
  394. package/dist/plugins/firecrawl/firecrawl.plugin.d.ts +32 -0
  395. package/dist/plugins/firecrawl/firecrawl.plugin.d.ts.map +1 -0
  396. package/dist/plugins/firecrawl/firecrawl.plugin.js +69 -0
  397. package/dist/plugins/firecrawl/index.d.ts +3 -0
  398. package/dist/plugins/firecrawl/index.d.ts.map +1 -0
  399. package/dist/plugins/firecrawl/index.js +2 -0
  400. package/dist/plugins/index.d.ts +47 -0
  401. package/dist/plugins/index.d.ts.map +1 -0
  402. package/dist/plugins/index.js +69 -0
  403. package/dist/plugins/matrix-group-chats/channel-memory.module.d.ts +7 -0
  404. package/dist/plugins/matrix-group-chats/channel-memory.module.d.ts.map +1 -0
  405. package/dist/plugins/matrix-group-chats/channel-memory.module.js +22 -0
  406. package/dist/plugins/matrix-group-chats/channel-memory.repo.d.ts +62 -0
  407. package/dist/plugins/matrix-group-chats/channel-memory.repo.d.ts.map +1 -0
  408. package/dist/plugins/matrix-group-chats/channel-memory.repo.js +311 -0
  409. package/dist/plugins/matrix-group-chats/channel-memory.service.d.ts +89 -0
  410. package/dist/plugins/matrix-group-chats/channel-memory.service.d.ts.map +1 -0
  411. package/dist/plugins/matrix-group-chats/channel-memory.service.js +565 -0
  412. package/dist/plugins/matrix-group-chats/channel-memory.summarizer.d.ts +18 -0
  413. package/dist/plugins/matrix-group-chats/channel-memory.summarizer.d.ts.map +1 -0
  414. package/dist/plugins/matrix-group-chats/channel-memory.summarizer.js +128 -0
  415. package/dist/plugins/matrix-group-chats/channel-memory.types.d.ts +50 -0
  416. package/dist/plugins/matrix-group-chats/channel-memory.types.d.ts.map +1 -0
  417. package/dist/plugins/matrix-group-chats/channel-memory.types.js +2 -0
  418. package/dist/plugins/matrix-group-chats/guard.d.ts +83 -0
  419. package/dist/plugins/matrix-group-chats/guard.d.ts.map +1 -0
  420. package/dist/plugins/matrix-group-chats/guard.js +138 -0
  421. package/dist/plugins/matrix-group-chats/index.d.ts +59 -0
  422. package/dist/plugins/matrix-group-chats/index.d.ts.map +1 -0
  423. package/dist/plugins/matrix-group-chats/index.js +140 -0
  424. package/dist/plugins/matrix-group-chats/middleware.d.ts +31 -0
  425. package/dist/plugins/matrix-group-chats/middleware.d.ts.map +1 -0
  426. package/dist/plugins/matrix-group-chats/middleware.js +186 -0
  427. package/dist/plugins/matrix-group-chats/power-levels.d.ts +15 -0
  428. package/dist/plugins/matrix-group-chats/power-levels.d.ts.map +1 -0
  429. package/dist/plugins/matrix-group-chats/power-levels.js +36 -0
  430. package/dist/plugins/matrix-group-chats/room-info.d.ts +23 -0
  431. package/dist/plugins/matrix-group-chats/room-info.d.ts.map +1 -0
  432. package/dist/plugins/matrix-group-chats/room-info.js +34 -0
  433. package/dist/plugins/matrix-group-chats/tools.d.ts +8 -0
  434. package/dist/plugins/matrix-group-chats/tools.d.ts.map +1 -0
  435. package/dist/plugins/matrix-group-chats/tools.js +154 -0
  436. package/dist/plugins/memory/index.d.ts +5 -0
  437. package/dist/plugins/memory/index.d.ts.map +1 -0
  438. package/dist/plugins/memory/index.js +3 -0
  439. package/dist/plugins/memory/memory-tools.d.ts +52 -0
  440. package/dist/plugins/memory/memory-tools.d.ts.map +1 -0
  441. package/dist/plugins/memory/memory-tools.js +88 -0
  442. package/dist/plugins/memory/memory-ucan.d.ts +17 -0
  443. package/dist/plugins/memory/memory-ucan.d.ts.map +1 -0
  444. package/dist/plugins/memory/memory-ucan.js +43 -0
  445. package/dist/plugins/memory/memory.plugin.d.ts +51 -0
  446. package/dist/plugins/memory/memory.plugin.d.ts.map +1 -0
  447. package/dist/plugins/memory/memory.plugin.js +76 -0
  448. package/dist/plugins/memory/types.d.ts +75 -0
  449. package/dist/plugins/memory/types.d.ts.map +1 -0
  450. package/dist/plugins/memory/types.js +2 -0
  451. package/dist/plugins/portal/index.d.ts +3 -0
  452. package/dist/plugins/portal/index.d.ts.map +1 -0
  453. package/dist/plugins/portal/index.js +2 -0
  454. package/dist/plugins/portal/portal-agent.d.ts +9 -0
  455. package/dist/plugins/portal/portal-agent.d.ts.map +1 -0
  456. package/dist/plugins/portal/portal-agent.js +70 -0
  457. package/dist/plugins/portal/portal.plugin.d.ts +16 -0
  458. package/dist/plugins/portal/portal.plugin.d.ts.map +1 -0
  459. package/dist/plugins/portal/portal.plugin.js +115 -0
  460. package/dist/plugins/sandbox/index.d.ts +3 -0
  461. package/dist/plugins/sandbox/index.d.ts.map +1 -0
  462. package/dist/plugins/sandbox/index.js +2 -0
  463. package/dist/plugins/sandbox/sandbox-mcp.d.ts +46 -0
  464. package/dist/plugins/sandbox/sandbox-mcp.d.ts.map +1 -0
  465. package/dist/plugins/sandbox/sandbox-mcp.js +80 -0
  466. package/dist/plugins/sandbox/sandbox-write-blob.d.ts +22 -0
  467. package/dist/plugins/sandbox/sandbox-write-blob.d.ts.map +1 -0
  468. package/dist/plugins/sandbox/sandbox-write-blob.js +80 -0
  469. package/dist/plugins/sandbox/sandbox.plugin.d.ts +80 -0
  470. package/dist/plugins/sandbox/sandbox.plugin.d.ts.map +1 -0
  471. package/dist/plugins/sandbox/sandbox.plugin.js +204 -0
  472. package/dist/plugins/skills/index.d.ts +3 -0
  473. package/dist/plugins/skills/index.d.ts.map +1 -0
  474. package/dist/plugins/skills/index.js +2 -0
  475. package/dist/plugins/skills/skills-tools.d.ts +20 -0
  476. package/dist/plugins/skills/skills-tools.d.ts.map +1 -0
  477. package/dist/plugins/skills/skills-tools.js +204 -0
  478. package/dist/plugins/skills/skills-ucan.d.ts +24 -0
  479. package/dist/plugins/skills/skills-ucan.d.ts.map +1 -0
  480. package/dist/plugins/skills/skills-ucan.js +28 -0
  481. package/dist/plugins/skills/skills.plugin.d.ts +37 -0
  482. package/dist/plugins/skills/skills.plugin.d.ts.map +1 -0
  483. package/dist/plugins/skills/skills.plugin.js +82 -0
  484. package/dist/plugins/slack/index.d.ts +4 -0
  485. package/dist/plugins/slack/index.d.ts.map +1 -0
  486. package/dist/plugins/slack/index.js +3 -0
  487. package/dist/plugins/slack/slack.module.d.ts +9 -0
  488. package/dist/plugins/slack/slack.module.d.ts.map +1 -0
  489. package/dist/plugins/slack/slack.module.js +27 -0
  490. package/dist/plugins/slack/slack.plugin.d.ts +30 -0
  491. package/dist/plugins/slack/slack.plugin.d.ts.map +1 -0
  492. package/dist/plugins/slack/slack.plugin.js +40 -0
  493. package/dist/plugins/slack/slack.service.d.ts +32 -0
  494. package/dist/plugins/slack/slack.service.d.ts.map +1 -0
  495. package/dist/plugins/slack/slack.service.js +157 -0
  496. package/dist/plugins/user-preferences/index.d.ts +4 -0
  497. package/dist/plugins/user-preferences/index.d.ts.map +1 -0
  498. package/dist/plugins/user-preferences/index.js +3 -0
  499. package/dist/plugins/user-preferences/service/user-preferences.service.d.ts +61 -0
  500. package/dist/plugins/user-preferences/service/user-preferences.service.d.ts.map +1 -0
  501. package/dist/plugins/user-preferences/service/user-preferences.service.js +105 -0
  502. package/dist/plugins/user-preferences/user-preferences-http.module.d.ts +10 -0
  503. package/dist/plugins/user-preferences/user-preferences-http.module.d.ts.map +1 -0
  504. package/dist/plugins/user-preferences/user-preferences-http.module.js +23 -0
  505. package/dist/plugins/user-preferences/user-preferences-tool.d.ts +22 -0
  506. package/dist/plugins/user-preferences/user-preferences-tool.d.ts.map +1 -0
  507. package/dist/plugins/user-preferences/user-preferences-tool.js +103 -0
  508. package/dist/plugins/user-preferences/user-preferences.controller.d.ts +18 -0
  509. package/dist/plugins/user-preferences/user-preferences.controller.d.ts.map +1 -0
  510. package/dist/plugins/user-preferences/user-preferences.controller.js +72 -0
  511. package/dist/plugins/user-preferences/user-preferences.plugin.d.ts +27 -0
  512. package/dist/plugins/user-preferences/user-preferences.plugin.d.ts.map +1 -0
  513. package/dist/plugins/user-preferences/user-preferences.plugin.js +66 -0
  514. package/dist/registries/config-schema-registry.d.ts +24 -0
  515. package/dist/registries/config-schema-registry.d.ts.map +1 -0
  516. package/dist/registries/config-schema-registry.js +27 -0
  517. package/dist/registries/index.d.ts +13 -0
  518. package/dist/registries/index.d.ts.map +1 -0
  519. package/dist/registries/index.js +6 -0
  520. package/dist/registries/manifest-registry.d.ts +49 -0
  521. package/dist/registries/manifest-registry.d.ts.map +1 -0
  522. package/dist/registries/manifest-registry.js +53 -0
  523. package/dist/registries/middleware-registry.d.ts +41 -0
  524. package/dist/registries/middleware-registry.d.ts.map +1 -0
  525. package/dist/registries/middleware-registry.js +52 -0
  526. package/dist/registries/shared-state-registry.d.ts +41 -0
  527. package/dist/registries/shared-state-registry.d.ts.map +1 -0
  528. package/dist/registries/shared-state-registry.js +65 -0
  529. package/dist/registries/subagent-registry.d.ts +55 -0
  530. package/dist/registries/subagent-registry.d.ts.map +1 -0
  531. package/dist/registries/subagent-registry.js +106 -0
  532. package/dist/registries/test-fixtures.d.ts +47 -0
  533. package/dist/registries/test-fixtures.d.ts.map +1 -0
  534. package/dist/registries/test-fixtures.js +168 -0
  535. package/dist/registries/tool-registry.d.ts +74 -0
  536. package/dist/registries/tool-registry.d.ts.map +1 -0
  537. package/dist/registries/tool-registry.js +130 -0
  538. package/dist/runtime-context/ambient.d.ts +118 -0
  539. package/dist/runtime-context/ambient.d.ts.map +1 -0
  540. package/dist/runtime-context/ambient.js +1 -0
  541. package/dist/runtime-context/build-plugin.d.ts +20 -0
  542. package/dist/runtime-context/build-plugin.d.ts.map +1 -0
  543. package/dist/runtime-context/build-plugin.js +16 -0
  544. package/dist/runtime-context/build-runtime.d.ts +60 -0
  545. package/dist/runtime-context/build-runtime.d.ts.map +1 -0
  546. package/dist/runtime-context/build-runtime.js +81 -0
  547. package/dist/testing/create-test-runtime.d.ts +95 -0
  548. package/dist/testing/create-test-runtime.d.ts.map +1 -0
  549. package/dist/testing/create-test-runtime.js +302 -0
  550. package/dist/testing/index.d.ts +5 -0
  551. package/dist/testing/index.d.ts.map +1 -0
  552. package/dist/testing/index.js +5 -0
  553. package/dist/testing/integration/chat-client.d.ts +143 -0
  554. package/dist/testing/integration/chat-client.d.ts.map +1 -0
  555. package/dist/testing/integration/chat-client.js +238 -0
  556. package/dist/testing/integration/harness.d.ts +189 -0
  557. package/dist/testing/integration/harness.d.ts.map +1 -0
  558. package/dist/testing/integration/harness.js +461 -0
  559. package/dist/testing/integration/index.d.ts +14 -0
  560. package/dist/testing/integration/index.d.ts.map +1 -0
  561. package/dist/testing/integration/index.js +18 -0
  562. package/dist/testing/integration/setup.d.ts +2 -0
  563. package/dist/testing/integration/setup.d.ts.map +1 -0
  564. package/dist/testing/integration/setup.js +41 -0
  565. package/dist/testing/integration/sse-parser.d.ts +99 -0
  566. package/dist/testing/integration/sse-parser.d.ts.map +1 -0
  567. package/dist/testing/integration/sse-parser.js +125 -0
  568. package/dist/testing/integration/ucan.d.ts +74 -0
  569. package/dist/testing/integration/ucan.d.ts.map +1 -0
  570. package/dist/testing/integration/ucan.js +95 -0
  571. package/dist/testing/integration/wait-for-matrix-loaded.d.ts +19 -0
  572. package/dist/testing/integration/wait-for-matrix-loaded.d.ts.map +1 -0
  573. package/dist/testing/integration/wait-for-matrix-loaded.js +31 -0
  574. package/dist/testing/mocks.d.ts +64 -0
  575. package/dist/testing/mocks.d.ts.map +1 -0
  576. package/dist/testing/mocks.js +141 -0
  577. package/dist/testing/nest-doubles.d.ts +10 -0
  578. package/dist/testing/nest-doubles.d.ts.map +1 -0
  579. package/dist/testing/nest-doubles.js +19 -0
  580. package/dist/utils/emoji.d.ts +3 -0
  581. package/dist/utils/emoji.d.ts.map +1 -0
  582. package/dist/utils/emoji.js +36 -0
  583. package/package.json +102 -0
@@ -0,0 +1,186 @@
1
+ import { MatrixManager } from '@ixo/matrix';
2
+ import { createMiddleware } from 'langchain';
3
+ import { mainAgentRequestContextSchema } from '../../graph/main-agent-types.js';
4
+ import { ChannelMemoryService } from './channel-memory.service.js';
5
+ import { markBotThreadActive, shouldAgentRespond, sweepExpiredBotThreads, } from './guard.js';
6
+ import { getBotPowerLevel } from './power-levels.js';
7
+ import { RoomInfoCache } from './room-info.js';
8
+ const NOOP_LOGGER = {
9
+ log: () => undefined,
10
+ warn: () => undefined,
11
+ error: () => undefined,
12
+ };
13
+ /**
14
+ * Per-turn gate for Matrix group rooms. Runs as `beforeAgent`:
15
+ *
16
+ * - Non-Matrix transports → pass through.
17
+ * - DMs / rooms with ≤2 members → pass through.
18
+ * - Group rooms (>2 members):
19
+ * - Capture the latest HumanMessage into channel memory (side effect).
20
+ * - Run `shouldAgentRespond` (mention / reply-to-bot / active-thread).
21
+ * - If the bot shouldn't respond → short-circuit with `jumpTo: 'end'`.
22
+ * - If it should → check `m.room.power_levels`; short-circuit when the
23
+ * bot lacks send permission.
24
+ *
25
+ * Does NOT declare a `stateSchema` and NEVER returns state updates.
26
+ * Re-declaring the agent's built-in `messages` channel clobbers its
27
+ * `addMessages` reducer and resets the conversation per turn — that's why
28
+ * earlier versions of this middleware caused "every message is a new
29
+ * thread" behaviour. Side effects only.
30
+ */
31
+ export const createGroupChatMiddleware = (options) => {
32
+ const logger = options.logger ?? NOOP_LOGGER;
33
+ const activeBotThreads = new Map();
34
+ const roomInfoCache = new RoomInfoCache(options.roomInfoTtlMs);
35
+ return createMiddleware({
36
+ name: 'GroupChatMiddleware',
37
+ contextSchema: mainAgentRequestContextSchema,
38
+ beforeAgent: {
39
+ canJumpTo: ['end'],
40
+ hook: async (state, runtime) => {
41
+ const parsedCtx = mainAgentRequestContextSchema.safeParse(runtime.context);
42
+ if (!parsedCtx.success)
43
+ return;
44
+ const ctx = parsedCtx.data;
45
+ if (ctx.session.client !== 'matrix' || !ctx.session.roomId) {
46
+ return;
47
+ }
48
+ const roomId = ctx.session.roomId;
49
+ const messages = Array.isArray(state.messages)
50
+ ? state.messages
51
+ : [];
52
+ const lastHuman = findLastHuman(messages);
53
+ if (!lastHuman)
54
+ return;
55
+ const kwargs = lastHuman.additional_kwargs
56
+ ? { ...lastHuman.additional_kwargs }
57
+ : {};
58
+ const eventId = pickString(kwargs.eventId);
59
+ const threadId = pickString(kwargs.threadId) ?? eventId;
60
+ if (!eventId || !threadId) {
61
+ logger.warn?.('[GroupChatMiddleware] Last HumanMessage is missing eventId/threadId metadata — passing through');
62
+ return;
63
+ }
64
+ let roomInfo;
65
+ try {
66
+ roomInfo = await roomInfoCache.get(roomId);
67
+ }
68
+ catch (err) {
69
+ logger.warn?.(`[GroupChatMiddleware] getRoomInfo failed for ${roomId}: ${err instanceof Error ? err.message : String(err)}`);
70
+ return;
71
+ }
72
+ if (roomInfo.isDirect || roomInfo.memberCount <= 2) {
73
+ return;
74
+ }
75
+ const channelMemory = ChannelMemoryService.getInstance();
76
+ const senderDid = pickString(kwargs.senderDid) ?? ctx.user.did;
77
+ const senderMatrixUserId = pickString(kwargs.senderMatrixUserId) ?? ctx.user.matrixUserId;
78
+ const senderDisplayName = pickString(kwargs.senderDisplayName) ?? senderMatrixUserId;
79
+ const body = stringifyContent(lastHuman.content);
80
+ const observed = {
81
+ eventId,
82
+ threadId,
83
+ senderDid,
84
+ senderMatrixUserId,
85
+ senderDisplayName,
86
+ body,
87
+ timestamp: Date.now(),
88
+ };
89
+ if (channelMemory) {
90
+ try {
91
+ channelMemory.observeMessage(roomId, observed);
92
+ }
93
+ catch (err) {
94
+ logger.warn?.(`[GroupChatMiddleware] observeMessage failed for ${roomId}: ${err instanceof Error ? err.message : String(err)}`);
95
+ }
96
+ }
97
+ sweepExpiredBotThreads(activeBotThreads);
98
+ const matrixManager = MatrixManager.getInstance();
99
+ const botMatrixUserId = matrixManager.getBotMatrixUserId();
100
+ const event = { eventId, content: kwargs };
101
+ const decision = await shouldAgentRespond({
102
+ event,
103
+ roomId,
104
+ threadId,
105
+ matrixManager,
106
+ botMatrixUserId,
107
+ roomInfo,
108
+ activeBotThreads,
109
+ activeBotThreadTtlMs: options.activeThreadTtlMs,
110
+ });
111
+ if (!decision.respond) {
112
+ logger.log(`[GroupChatMiddleware] room=${roomId} thread=${threadId.slice(0, 10)} ignored (${decision.reason})`);
113
+ return { jumpTo: 'end' };
114
+ }
115
+ // Power-level check — short-circuit silently if the bot can't post.
116
+ try {
117
+ const pl = await getBotPowerLevel(roomId, botMatrixUserId);
118
+ if (!pl.allowed(options.requirePowerLevel)) {
119
+ logger.warn(`[GroupChatMiddleware] room=${roomId} bot PL ${pl.pl} < required ${Math.max(pl.sendThreshold, options.requirePowerLevel)} — skipping`);
120
+ return { jumpTo: 'end' };
121
+ }
122
+ }
123
+ catch (err) {
124
+ logger.warn?.(`[GroupChatMiddleware] power_levels check failed for ${roomId}: ${err instanceof Error ? err.message : String(err)}`);
125
+ }
126
+ markBotThreadActive(activeBotThreads, roomId, threadId, options.activeThreadTtlMs);
127
+ // Refresh the member roster mid-conversation. Fire-and-forget so
128
+ // we never block the turn waiting on Matrix.
129
+ if (channelMemory) {
130
+ channelMemory
131
+ .refreshMembers(roomId, matrixManager)
132
+ .catch(() => undefined);
133
+ // JIT compaction — service has its own 3-sec timeout cap.
134
+ await channelMemory.compactJustInTime(roomId).catch(() => undefined);
135
+ }
136
+ // Intentionally NO state mutation here. Returning `{ messages: ... }`
137
+ // from `beforeAgent` interacts with the `addMessages` reducer in
138
+ // ways that break checkpointer thread continuity. The speaker
139
+ // identity is already on the HumanMessage's `additional_kwargs`
140
+ // for downstream consumers; we don't need to rewrite the content.
141
+ return;
142
+ },
143
+ },
144
+ });
145
+ };
146
+ function findLastHuman(messages) {
147
+ for (let i = messages.length - 1; i >= 0; i--) {
148
+ const m = messages[i];
149
+ if (m?.type === 'human') {
150
+ return m;
151
+ }
152
+ }
153
+ return undefined;
154
+ }
155
+ function pickString(value) {
156
+ return typeof value === 'string' && value.length > 0 ? value : undefined;
157
+ }
158
+ function stringifyContent(content) {
159
+ if (typeof content === 'string')
160
+ return content;
161
+ if (Array.isArray(content)) {
162
+ return content
163
+ .map((part) => {
164
+ if (typeof part === 'string')
165
+ return part;
166
+ if (part && typeof part === 'object' && 'text' in part) {
167
+ const t = part.text;
168
+ return typeof t === 'string' ? t : '';
169
+ }
170
+ return '';
171
+ })
172
+ .join('');
173
+ }
174
+ return '';
175
+ }
176
+ /** Build the middleware from `PluginContext` config. */
177
+ export function buildGroupChatMiddleware(ctx) {
178
+ const config = ctx.config;
179
+ return createGroupChatMiddleware({
180
+ activeThreadTtlMs: config.GROUP_CHAT_ACTIVE_THREAD_TTL_MS ?? 30 * 60 * 1000,
181
+ requirePowerLevel: config.GROUP_CHAT_REQUIRE_POWER_LEVEL ?? 0,
182
+ roomInfoTtlMs: config.GROUP_CHAT_ROOM_INFO_TTL_MS ?? 30 * 60 * 1000,
183
+ logger: ctx.logger,
184
+ });
185
+ }
186
+ export { RoomInfoCache } from './room-info.js';
@@ -0,0 +1,15 @@
1
+ export interface BotPowerLevel {
2
+ /** Bot's effective power level in this room. */
3
+ pl: number;
4
+ /** Power level required to send `m.room.message` events. */
5
+ sendThreshold: number;
6
+ /** True when bot has at least `max(sendThreshold, requiredMin)` PL. */
7
+ allowed: (requiredMin?: number) => boolean;
8
+ }
9
+ /**
10
+ * Read `m.room.power_levels` for the room and resolve whether the bot has
11
+ * permission to send `m.room.message` events. Missing power-levels event
12
+ * is treated as "everyone allowed" — that's the Matrix default.
13
+ */
14
+ export declare function getBotPowerLevel(roomId: string, botUserId: string): Promise<BotPowerLevel>;
15
+ //# sourceMappingURL=power-levels.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"power-levels.d.ts","sourceRoot":"","sources":["../../../src/plugins/matrix-group-chats/power-levels.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,aAAa;IAC5B,gDAAgD;IAChD,EAAE,EAAE,MAAM,CAAC;IACX,4DAA4D;IAC5D,aAAa,EAAE,MAAM,CAAC;IACtB,uEAAuE;IACvE,OAAO,EAAE,CAAC,WAAW,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC;CAC5C;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,aAAa,CAAC,CAgCxB"}
@@ -0,0 +1,36 @@
1
+ import { MatrixManager } from '@ixo/matrix';
2
+ import { Logger } from '@nestjs/common';
3
+ const logger = new Logger('GroupChatPowerLevels');
4
+ /**
5
+ * Read `m.room.power_levels` for the room and resolve whether the bot has
6
+ * permission to send `m.room.message` events. Missing power-levels event
7
+ * is treated as "everyone allowed" — that's the Matrix default.
8
+ */
9
+ export async function getBotPowerLevel(roomId, botUserId) {
10
+ let content = null;
11
+ try {
12
+ const client = MatrixManager.getInstance().getClient();
13
+ if (!client) {
14
+ throw new Error('Matrix client not initialised');
15
+ }
16
+ const event = await client.mxClient.getRoomStateEvent(roomId, 'm.room.power_levels', '');
17
+ if (event && typeof event === 'object') {
18
+ content = event;
19
+ }
20
+ }
21
+ catch (err) {
22
+ const message = err instanceof Error ? err.message : String(err);
23
+ if (!/M_NOT_FOUND|not found/i.test(message)) {
24
+ logger.warn(`Failed to read power_levels for ${roomId}: ${message}`);
25
+ }
26
+ }
27
+ const usersDefault = content?.users_default ?? 0;
28
+ const eventsDefault = content?.events_default ?? 0;
29
+ const pl = content?.users?.[botUserId] ?? usersDefault;
30
+ const sendThreshold = content?.events?.['m.room.message'] ?? eventsDefault;
31
+ return {
32
+ pl,
33
+ sendThreshold,
34
+ allowed: (requiredMin = 0) => pl >= Math.max(sendThreshold, requiredMin),
35
+ };
36
+ }
@@ -0,0 +1,23 @@
1
+ import type { RoomTypeInfo } from './guard.js';
2
+ interface CacheEntry {
3
+ info: RoomTypeInfo & {
4
+ joinedMemberIds: string[];
5
+ };
6
+ expiresAt: number;
7
+ }
8
+ /**
9
+ * Tiny TTL cache around `MatrixManager.getRoomInfo`. Reused by the
10
+ * group-chat middleware and the request-time tool builder so we don't pay
11
+ * a Matrix round-trip on every turn.
12
+ */
13
+ export declare class RoomInfoCache {
14
+ private readonly ttlMs;
15
+ private readonly entries;
16
+ constructor(ttlMs: number);
17
+ get(roomId: string): Promise<CacheEntry['info']>;
18
+ /** Drop a single room (e.g. on member event). */
19
+ invalidate(roomId: string): void;
20
+ clear(): void;
21
+ }
22
+ export {};
23
+ //# sourceMappingURL=room-info.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"room-info.d.ts","sourceRoot":"","sources":["../../../src/plugins/matrix-group-chats/room-info.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,UAAU,UAAU;IAClB,IAAI,EAAE,YAAY,GAAG;QAAE,eAAe,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;IACnD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,qBAAa,aAAa;IAGZ,OAAO,CAAC,QAAQ,CAAC,KAAK;IAFlC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiC;gBAE5B,KAAK,EAAE,MAAM;IAEpC,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAetD,iDAAiD;IACjD,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAIhC,KAAK,IAAI,IAAI;CAGd"}
@@ -0,0 +1,34 @@
1
+ import { MatrixManager } from '@ixo/matrix';
2
+ /**
3
+ * Tiny TTL cache around `MatrixManager.getRoomInfo`. Reused by the
4
+ * group-chat middleware and the request-time tool builder so we don't pay
5
+ * a Matrix round-trip on every turn.
6
+ */
7
+ export class RoomInfoCache {
8
+ ttlMs;
9
+ entries = new Map();
10
+ constructor(ttlMs) {
11
+ this.ttlMs = ttlMs;
12
+ }
13
+ async get(roomId) {
14
+ const cached = this.entries.get(roomId);
15
+ if (cached && cached.expiresAt > Date.now()) {
16
+ return cached.info;
17
+ }
18
+ const fresh = await MatrixManager.getInstance().getRoomInfo(roomId);
19
+ const info = {
20
+ isDirect: fresh.isDirect,
21
+ memberCount: fresh.memberCount,
22
+ joinedMemberIds: fresh.joinedMemberIds,
23
+ };
24
+ this.entries.set(roomId, { info, expiresAt: Date.now() + this.ttlMs });
25
+ return info;
26
+ }
27
+ /** Drop a single room (e.g. on member event). */
28
+ invalidate(roomId) {
29
+ this.entries.delete(roomId);
30
+ }
31
+ clear() {
32
+ this.entries.clear();
33
+ }
34
+ }
@@ -0,0 +1,8 @@
1
+ import type { PluginTool } from '../../plugin-api/types.js';
2
+ /**
3
+ * Build the per-room channel-memory tools. Visibility=`always` on each so
4
+ * they bypass the capability gate — gating happens in `getRequestTools`,
5
+ * which returns these only when the session is in a Matrix group room.
6
+ */
7
+ export declare function buildChannelMemoryTools(): PluginTool[];
8
+ //# sourceMappingURL=tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../../src/plugins/matrix-group-chats/tools.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,2BAA2B,CAAC;AAoC5E;;;;GAIG;AACH,wBAAgB,uBAAuB,IAAI,UAAU,EAAE,CA+HtD"}
@@ -0,0 +1,154 @@
1
+ import { z } from 'zod';
2
+ import { ChannelMemoryService } from './channel-memory.service.js';
3
+ const formatChunk = (chunk) => ({
4
+ id: chunk.id,
5
+ tier: chunk.tier,
6
+ fromTimestamp: new Date(chunk.fromTimestamp).toISOString(),
7
+ toTimestamp: new Date(chunk.toTimestamp).toISOString(),
8
+ messageCount: chunk.messageCount,
9
+ participants: chunk.participants,
10
+ threadIds: chunk.threadIds,
11
+ summary: chunk.summary,
12
+ });
13
+ function getService(rtCtx) {
14
+ const instance = ChannelMemoryService.getInstance();
15
+ if (!instance) {
16
+ rtCtx.logger.warn('ChannelMemoryService not initialised — matrix-group-chats tool invoked without a running Nest context');
17
+ throw new Error('ChannelMemoryService not initialised');
18
+ }
19
+ return instance;
20
+ }
21
+ function requireRoomId(rtCtx) {
22
+ const roomId = rtCtx.session.roomId;
23
+ if (!roomId) {
24
+ throw new Error('No active Matrix room — channel-memory tools require a roomId in the current session.');
25
+ }
26
+ return roomId;
27
+ }
28
+ /**
29
+ * Build the per-room channel-memory tools. Visibility=`always` on each so
30
+ * they bypass the capability gate — gating happens in `getRequestTools`,
31
+ * which returns these only when the session is in a Matrix group room.
32
+ */
33
+ export function buildChannelMemoryTools() {
34
+ return [
35
+ {
36
+ name: 'recall_channel_memory',
37
+ description: 'Read recent channel memory: most recent compacted summary chunks, pinned facts, and the member roster for the current group room. Use this to understand what has been happening in this channel before responding.',
38
+ visibility: 'always',
39
+ schema: z.object({
40
+ limit: z
41
+ .number()
42
+ .int()
43
+ .min(1)
44
+ .max(30)
45
+ .optional()
46
+ .describe('Number of recent summary chunks to return (default 10, max 30).'),
47
+ }),
48
+ async handler(args, rtCtx) {
49
+ const roomId = requireRoomId(rtCtx);
50
+ const service = getService(rtCtx);
51
+ const parsed = z
52
+ .object({ limit: z.number().int().min(1).max(30).optional() })
53
+ .parse(args);
54
+ const cap = parsed.limit ?? 10;
55
+ const [chunks, facts, members] = await Promise.all([
56
+ service.recentChunks(roomId, cap),
57
+ service.listPinnedFacts(roomId),
58
+ service.getMembers(roomId),
59
+ ]);
60
+ return {
61
+ chunks: chunks.map(formatChunk),
62
+ pinnedFacts: facts,
63
+ members,
64
+ };
65
+ },
66
+ },
67
+ {
68
+ name: 'search_channel_memory',
69
+ description: 'Keyword-search the compacted summary chunks for the current group room. Use to find earlier discussions of a topic, decisions, names, dates. Returns matching chunks with their summaries.',
70
+ visibility: 'always',
71
+ schema: z.object({
72
+ query: z
73
+ .string()
74
+ .min(1)
75
+ .describe('Keywords or phrase to search for in channel memory.'),
76
+ limit: z
77
+ .number()
78
+ .int()
79
+ .min(1)
80
+ .max(30)
81
+ .optional()
82
+ .describe('Maximum matching chunks to return (default 10).'),
83
+ }),
84
+ async handler(args, rtCtx) {
85
+ const roomId = requireRoomId(rtCtx);
86
+ const service = getService(rtCtx);
87
+ const parsed = z
88
+ .object({
89
+ query: z.string().min(1),
90
+ limit: z.number().int().min(1).max(30).optional(),
91
+ })
92
+ .parse(args);
93
+ const cap = parsed.limit ?? 10;
94
+ const chunks = await service.search(roomId, parsed.query, cap);
95
+ if (chunks.length === 0) {
96
+ return { chunks: [], note: 'No matching chunks.' };
97
+ }
98
+ return { chunks: chunks.map(formatChunk) };
99
+ },
100
+ },
101
+ {
102
+ name: 'pin_room_fact',
103
+ description: "Save a durable fact to the current group room's memory — survives across threads and sessions. Use for decisions, deadlines, member roles, project context. Surface in your reply so users know it has been saved.",
104
+ visibility: 'always',
105
+ schema: z.object({
106
+ fact: z
107
+ .string()
108
+ .min(3)
109
+ .max(500)
110
+ .describe('Concise factual statement to remember (max 500 chars).'),
111
+ sourceEventId: z
112
+ .string()
113
+ .optional()
114
+ .describe('Optional Matrix event id this fact was derived from.'),
115
+ }),
116
+ async handler(args, rtCtx) {
117
+ const roomId = requireRoomId(rtCtx);
118
+ const service = getService(rtCtx);
119
+ const parsed = z
120
+ .object({
121
+ fact: z.string().min(3).max(500),
122
+ sourceEventId: z.string().optional(),
123
+ })
124
+ .parse(args);
125
+ const trimmed = parsed.fact.trim();
126
+ if (!trimmed) {
127
+ throw new Error('Pinned fact must not be empty.');
128
+ }
129
+ const pinned = await service.pinFact({
130
+ roomId,
131
+ fact: trimmed.slice(0, 500),
132
+ pinnedByDid: rtCtx.user.did,
133
+ sourceEventId: parsed.sourceEventId,
134
+ });
135
+ return { factId: pinned.id, fact: pinned.fact };
136
+ },
137
+ },
138
+ {
139
+ name: 'unpin_room_fact',
140
+ description: "Remove a previously pinned fact from this group room's memory by its factId.",
141
+ visibility: 'always',
142
+ schema: z.object({
143
+ factId: z.string().min(1).describe('The id of the fact to remove.'),
144
+ }),
145
+ async handler(args, rtCtx) {
146
+ const roomId = requireRoomId(rtCtx);
147
+ const service = getService(rtCtx);
148
+ const parsed = z.object({ factId: z.string().min(1) }).parse(args);
149
+ const ok = await service.unpinFact(roomId, parsed.factId);
150
+ return { ok };
151
+ },
152
+ },
153
+ ];
154
+ }
@@ -0,0 +1,5 @@
1
+ export { createDefaultMemoryMcpFactory, DEFAULT_MEMORY_TOOLS, fetchMemoryTools, MEMORY_ADD_MCP_NAME, MEMORY_ADD_ORACLE_KNOWLEDGE_MCP_NAME, MEMORY_CLEAR_MCP_NAME, MEMORY_DELETE_EDGE_MCP_NAME, MEMORY_DELETE_EPISODE_MCP_NAME, MEMORY_SEARCH_MCP_NAME, type MemoryMcpFactory, type UpstreamMcpTool, } from './memory-tools.js';
2
+ export { buildMemoryHeaders } from './memory-ucan.js';
3
+ export { MemoryPlugin, type MemoryPluginOptions } from './memory.plugin.js';
4
+ export type * from './types.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/memory/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,EACpB,gBAAgB,EAChB,mBAAmB,EACnB,oCAAoC,EACpC,qBAAqB,EACrB,2BAA2B,EAC3B,8BAA8B,EAC9B,sBAAsB,EACtB,KAAK,gBAAgB,EACrB,KAAK,eAAe,GACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC5E,mBAAmB,YAAY,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { createDefaultMemoryMcpFactory, DEFAULT_MEMORY_TOOLS, fetchMemoryTools, MEMORY_ADD_MCP_NAME, MEMORY_ADD_ORACLE_KNOWLEDGE_MCP_NAME, MEMORY_CLEAR_MCP_NAME, MEMORY_DELETE_EDGE_MCP_NAME, MEMORY_DELETE_EPISODE_MCP_NAME, MEMORY_SEARCH_MCP_NAME, } from './memory-tools.js';
2
+ export { buildMemoryHeaders } from './memory-ucan.js';
3
+ export { MemoryPlugin } from './memory.plugin.js';
@@ -0,0 +1,52 @@
1
+ import type { z } from 'zod';
2
+ import type { PluginTool, RuntimeContext } from '../../plugin-api/types.js';
3
+ /**
4
+ * Tool names the upstream Memory Engine MCP server exposes (prefixed with the
5
+ * server name configured in `MultiServerMCPClient`). The plugin surfaces these
6
+ * upstream tools as-is — name, description, and schema all come from the
7
+ * upstream server. Wrapping them locally with a different shape (as an earlier
8
+ * iteration did) caused upstream-side schema rejections at invoke time
9
+ * because the wrapper schema didn't match the server's contract.
10
+ */
11
+ export declare const MEMORY_SEARCH_MCP_NAME = "memory-engine__search_memory_engine";
12
+ export declare const MEMORY_ADD_MCP_NAME = "memory-engine__add_memory";
13
+ export declare const MEMORY_ADD_ORACLE_KNOWLEDGE_MCP_NAME = "memory-engine__add_oracle_knowledge";
14
+ export declare const MEMORY_DELETE_EPISODE_MCP_NAME = "memory-engine__delete_episode";
15
+ export declare const MEMORY_DELETE_EDGE_MCP_NAME = "memory-engine__delete_edge";
16
+ export declare const MEMORY_CLEAR_MCP_NAME = "memory-engine__clear";
17
+ /**
18
+ * Default selection — mirrors the old `apps/app` Memory Agent default: search,
19
+ * add, and delete-episode. Forks that need org-owner knowledge writes or the
20
+ * destructive `clear` op pass an explicit list via plugin options.
21
+ */
22
+ export declare const DEFAULT_MEMORY_TOOLS: readonly ["memory-engine__search_memory_engine", "memory-engine__add_memory", "memory-engine__delete_episode", "memory-engine__clear"];
23
+ /**
24
+ * Minimal shape every upstream MCP tool exposes. `@langchain/mcp-adapters`
25
+ * returns `StructuredTool` instances whose runtime shape includes these
26
+ * fields. The plugin only depends on this slice; tests can satisfy it with a
27
+ * plain object.
28
+ */
29
+ export interface UpstreamMcpTool {
30
+ name: string;
31
+ description: string;
32
+ schema: z.ZodType;
33
+ invoke: (input: unknown) => Promise<unknown>;
34
+ }
35
+ export type MemoryMcpFactory = (runCtx: RuntimeContext) => Promise<UpstreamMcpTool[] | null>;
36
+ /**
37
+ * Default factory: opens an HTTP MCP client to `MEMORY_MCP_URL` with the
38
+ * per-request UCAN headers from {@link buildMemoryHeaders} and returns the
39
+ * upstream's tool list. A fresh client per request mirrors the old apps/app
40
+ * pattern and ensures each invocation runs against the authenticated user.
41
+ */
42
+ export declare function createDefaultMemoryMcpFactory(memoryMcpUrl: string): MemoryMcpFactory;
43
+ /**
44
+ * Fetch the upstream Memory Engine MCP tools for this request and return them
45
+ * as `PluginTool[]`. Filtered by `selectedTools` so forks can scope the
46
+ * surface (e.g. drop `clear`, add `add_oracle_knowledge` for org-owner mode).
47
+ *
48
+ * Returns `[]` when the factory cannot mint auth — the agent then sees no
49
+ * memory tools rather than getting a half-built request to upstream.
50
+ */
51
+ export declare function fetchMemoryTools(runCtx: RuntimeContext, factory: MemoryMcpFactory, selectedTools?: readonly string[]): Promise<PluginTool[]>;
52
+ //# sourceMappingURL=memory-tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-tools.d.ts","sourceRoot":"","sources":["../../../src/plugins/memory/memory-tools.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAG5E;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,wCAAwC,CAAC;AAC5E,eAAO,MAAM,mBAAmB,8BAA8B,CAAC;AAC/D,eAAO,MAAM,oCAAoC,wCACV,CAAC;AACxC,eAAO,MAAM,8BAA8B,kCAAkC,CAAC;AAC9E,eAAO,MAAM,2BAA2B,+BAA+B,CAAC;AACxE,eAAO,MAAM,qBAAqB,yBAAyB,CAAC;AAE5D;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,wIAKvB,CAAC;AAEX;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC;IAClB,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAC9C;AAED,MAAM,MAAM,gBAAgB,GAAG,CAC7B,MAAM,EAAE,cAAc,KACnB,OAAO,CAAC,eAAe,EAAE,GAAG,IAAI,CAAC,CAAC;AAEvC;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,YAAY,EAAE,MAAM,GACnB,gBAAgB,CAyBlB;AAiBD;;;;;;;GAOG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,cAAc,EACtB,OAAO,EAAE,gBAAgB,EACzB,aAAa,GAAE,SAAS,MAAM,EAAyB,GACtD,OAAO,CAAC,UAAU,EAAE,CAAC,CAMvB"}
@@ -0,0 +1,88 @@
1
+ import { MultiServerMCPClient } from '@langchain/mcp-adapters';
2
+ import { buildMemoryHeaders } from './memory-ucan.js';
3
+ /**
4
+ * Tool names the upstream Memory Engine MCP server exposes (prefixed with the
5
+ * server name configured in `MultiServerMCPClient`). The plugin surfaces these
6
+ * upstream tools as-is — name, description, and schema all come from the
7
+ * upstream server. Wrapping them locally with a different shape (as an earlier
8
+ * iteration did) caused upstream-side schema rejections at invoke time
9
+ * because the wrapper schema didn't match the server's contract.
10
+ */
11
+ export const MEMORY_SEARCH_MCP_NAME = 'memory-engine__search_memory_engine';
12
+ export const MEMORY_ADD_MCP_NAME = 'memory-engine__add_memory';
13
+ export const MEMORY_ADD_ORACLE_KNOWLEDGE_MCP_NAME = 'memory-engine__add_oracle_knowledge';
14
+ export const MEMORY_DELETE_EPISODE_MCP_NAME = 'memory-engine__delete_episode';
15
+ export const MEMORY_DELETE_EDGE_MCP_NAME = 'memory-engine__delete_edge';
16
+ export const MEMORY_CLEAR_MCP_NAME = 'memory-engine__clear';
17
+ /**
18
+ * Default selection — mirrors the old `apps/app` Memory Agent default: search,
19
+ * add, and delete-episode. Forks that need org-owner knowledge writes or the
20
+ * destructive `clear` op pass an explicit list via plugin options.
21
+ */
22
+ export const DEFAULT_MEMORY_TOOLS = [
23
+ MEMORY_SEARCH_MCP_NAME,
24
+ MEMORY_ADD_MCP_NAME,
25
+ MEMORY_DELETE_EPISODE_MCP_NAME,
26
+ MEMORY_CLEAR_MCP_NAME,
27
+ ];
28
+ /**
29
+ * Default factory: opens an HTTP MCP client to `MEMORY_MCP_URL` with the
30
+ * per-request UCAN headers from {@link buildMemoryHeaders} and returns the
31
+ * upstream's tool list. A fresh client per request mirrors the old apps/app
32
+ * pattern and ensures each invocation runs against the authenticated user.
33
+ */
34
+ export function createDefaultMemoryMcpFactory(memoryMcpUrl) {
35
+ return async (runCtx) => {
36
+ const headers = await buildMemoryHeaders(runCtx, memoryMcpUrl);
37
+ if (!headers)
38
+ return null;
39
+ const client = new MultiServerMCPClient({
40
+ useStandardContentBlocks: true,
41
+ prefixToolNameWithServerName: true,
42
+ mcpServers: {
43
+ 'memory-engine': {
44
+ type: 'http',
45
+ transport: 'http',
46
+ url: memoryMcpUrl,
47
+ headers,
48
+ reconnect: {
49
+ enabled: true,
50
+ maxAttempts: 3,
51
+ delayMs: 2000,
52
+ },
53
+ defaultToolTimeout: 420_000,
54
+ },
55
+ },
56
+ });
57
+ return (await client.getTools());
58
+ };
59
+ }
60
+ /**
61
+ * Adapt one upstream MCP tool into a `PluginTool`. Name, description, and
62
+ * schema are taken VERBATIM from upstream — the agent sees the same contract
63
+ * the Memory Engine server publishes, and our handler is a thin passthrough
64
+ * to `mcpTool.invoke`.
65
+ */
66
+ function adaptMcpTool(mcpTool) {
67
+ return {
68
+ name: mcpTool.name,
69
+ description: mcpTool.description,
70
+ schema: mcpTool.schema,
71
+ handler: async (args) => mcpTool.invoke(args),
72
+ };
73
+ }
74
+ /**
75
+ * Fetch the upstream Memory Engine MCP tools for this request and return them
76
+ * as `PluginTool[]`. Filtered by `selectedTools` so forks can scope the
77
+ * surface (e.g. drop `clear`, add `add_oracle_knowledge` for org-owner mode).
78
+ *
79
+ * Returns `[]` when the factory cannot mint auth — the agent then sees no
80
+ * memory tools rather than getting a half-built request to upstream.
81
+ */
82
+ export async function fetchMemoryTools(runCtx, factory, selectedTools = DEFAULT_MEMORY_TOOLS) {
83
+ const mcpTools = await factory(runCtx);
84
+ if (!mcpTools)
85
+ return [];
86
+ const allow = new Set(selectedTools);
87
+ return mcpTools.filter((t) => allow.has(t.name)).map(adaptMcpTool);
88
+ }
@@ -0,0 +1,17 @@
1
+ import type { RuntimeContext } from '../../plugin-api/types.js';
2
+ /**
3
+ * Build the headers needed to call the Memory Engine MCP server on behalf of
4
+ * the current user.
5
+ *
6
+ * 1. Resolve the memory service DID via `runCtx.ucan.resolveServiceDid`
7
+ * (delegates the did:web lookup + cache to the Tier-0 UCAN service).
8
+ * 2. Mint an `ixo:memory` invocation using the user's signing key.
9
+ * 3. Layer the resulting Bearer token plus the active `x-room-id`.
10
+ *
11
+ * UCAN-only — no Matrix-OpenID fallback. If minting fails for any reason
12
+ * (no signing key, no cached delegation, did:web unresolved) the function
13
+ * returns `null` so callers can degrade silently rather than leak a
14
+ * half-built request to the upstream service.
15
+ */
16
+ export declare function buildMemoryHeaders(runCtx: RuntimeContext, memoryMcpUrl: string): Promise<Record<string, string> | null>;
17
+ //# sourceMappingURL=memory-ucan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-ucan.d.ts","sourceRoot":"","sources":["../../../src/plugins/memory/memory-ucan.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE;;;;;;;;;;;;;GAaG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,cAAc,EACtB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC,CA4BxC"}