@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 @@
1
+ {"version":3,"file":"tier1-renderer.d.ts","sourceRoot":"","sources":["../../src/manifest/tier1-renderer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAE9E,gFAAgF;AAChF,MAAM,WAAW,UAAU;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,cAAc,CAAC;CAC1B;AAED,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,UAAU,EAAE,CAAC;IACxB,4EAA4E;IAC5E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,uFAAuF;IACvF,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3C;AAED,MAAM,WAAW,WAAW;IAC1B,yEAAyE;IACzE,KAAK,EAAE,MAAM,CAAC;IACd,uDAAuD;IACvD,MAAM,EAAE,MAAM,CAAC;IACf,iDAAiD;IACjD,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AA2CD;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,CAmC1D"}
@@ -0,0 +1,68 @@
1
+ import { encodingForModel } from 'js-tiktoken';
2
+ const DEFAULT_BUDGET = 5000;
3
+ const HEADER = '## Available Capabilities\n\n';
4
+ const FOOTER = '\n\nFor more capabilities, call `list_capabilities()` to see what else is available,\nthen `load_capability(name)` to make its tools available.';
5
+ let cachedEncoder = null;
6
+ function tiktokenEstimate(text) {
7
+ cachedEncoder ??= encodingForModel('gpt-4o');
8
+ return cachedEncoder.encode(text).length;
9
+ }
10
+ function formatExample(ex) {
11
+ const argSummary = ex.args && Object.keys(ex.args).length > 0
12
+ ? `${ex.tool}(${JSON.stringify(ex.args)})`
13
+ : `${ex.tool}()`;
14
+ return `"${ex.user}" → ${argSummary}`;
15
+ }
16
+ function formatEntry(entry) {
17
+ const { pluginName, manifest } = entry;
18
+ const lines = [`- **${pluginName}** — ${manifest.summary}`];
19
+ const whenToUse = manifest.whenToUse.slice(0, 2);
20
+ if (whenToUse.length > 0) {
21
+ lines.push(` - When to use: ${whenToUse.join('; ')}`);
22
+ }
23
+ if (manifest.whenNotToUse && manifest.whenNotToUse.length > 0) {
24
+ lines.push(` - Avoid for: ${manifest.whenNotToUse[0]}`);
25
+ }
26
+ const firstExample = manifest.examples?.[0];
27
+ if (firstExample) {
28
+ lines.push(` - Example: ${formatExample(firstExample)}`);
29
+ }
30
+ return lines.join('\n');
31
+ }
32
+ /**
33
+ * Compose the Tier-1 capability block from a list of plugin manifests.
34
+ *
35
+ * Only `visibility: 'always'` manifests are included, sorted alphabetically
36
+ * for prompt-caching determinism. Over-budget calls produce a warning naming
37
+ * the largest manifests so operators can mark them `'on-demand'` — degrading
38
+ * verbosity is an operator decision, not a runtime guess.
39
+ */
40
+ export function renderTier1(input) {
41
+ const budget = input.tokenBudget ?? DEFAULT_BUDGET;
42
+ const estimate = input.estimateTokens ?? tiktokenEstimate;
43
+ const entries = input.manifests
44
+ .filter(({ manifest }) => manifest.visibility === 'always')
45
+ .slice()
46
+ .sort((a, b) => a.pluginName.localeCompare(b.pluginName));
47
+ if (entries.length === 0) {
48
+ return { block: '', tokens: 0, warnings: [] };
49
+ }
50
+ const renderedLines = entries.map(formatEntry);
51
+ const tokens = renderedLines.reduce((sum, line) => sum + estimate(line), 0);
52
+ const warnings = [];
53
+ if (tokens > budget) {
54
+ const largest = entries
55
+ .map((entry) => ({
56
+ name: entry.pluginName,
57
+ t: estimate(formatEntry(entry)),
58
+ }))
59
+ .sort((a, b) => b.t - a.t)
60
+ .slice(0, 3)
61
+ .map((e) => `${e.name} (~${e.t} tok)`)
62
+ .join(', ');
63
+ warnings.push(`Tier-1 prompt is ${tokens} tokens (budget ${budget}). ` +
64
+ `Consider marking these on-demand: ${largest}.`);
65
+ }
66
+ const block = `${HEADER}${renderedLines.join('\n\n')}${FOOTER}`;
67
+ return { block, tokens, warnings };
68
+ }
@@ -0,0 +1,34 @@
1
+ import type { PluginManifest } from '../plugin-api/types.js';
2
+ /** Result of validating a single plugin manifest. */
3
+ export interface ManifestValidationResult {
4
+ valid: boolean;
5
+ errors: string[];
6
+ warnings: string[];
7
+ }
8
+ /**
9
+ * Validate a plugin manifest at boot time.
10
+ *
11
+ * Hard rules push to `errors` and set `valid: false`.
12
+ * Soft rules push to `warnings` only — `valid` stays `true`.
13
+ *
14
+ * Cross-tool reference checking lives in `validateExamplesAgainstTools`
15
+ * because the registered tool list is only known once the plugin's
16
+ * `getTools()` has run.
17
+ */
18
+ export declare function validateManifest(manifest: unknown, pluginName: string): ManifestValidationResult;
19
+ /**
20
+ * Cross-check `examples[].tool` references against the set of tool names
21
+ * actually registered by this plugin. Run after the plugin's `getTools()`
22
+ * has been invoked.
23
+ *
24
+ * **Lenient for MCP-sourced plugins**: when `registeredToolNames` is empty,
25
+ * the plugin's tools come from `getRequestTools` (fetched per-request from
26
+ * an upstream MCP server like sandbox or memory) — boot-time validation
27
+ * can't see them. We skip the cross-check in that case rather than
28
+ * false-flag every example. Plugins with boot-time tools still get the
29
+ * full check, so stale `examples[].tool` references are caught.
30
+ */
31
+ export declare function validateExamplesAgainstTools(manifest: PluginManifest, registeredToolNames: string[], pluginName: string): {
32
+ errors: string[];
33
+ };
34
+ //# sourceMappingURL=validator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/manifest/validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAG7D,qDAAqD;AACrD,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAiBD;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,OAAO,EACjB,UAAU,EAAE,MAAM,GACjB,wBAAwB,CAoF1B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,cAAc,EACxB,mBAAmB,EAAE,MAAM,EAAE,EAC7B,UAAU,EAAE,MAAM,GACjB;IAAE,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAkBtB"}
@@ -0,0 +1,111 @@
1
+ import { pluginManifestSchema } from './schema.js';
2
+ /** Soft-cap thresholds — violations only emit warnings. */
3
+ const SOFT_LIMITS = {
4
+ summaryMaxChars: 120,
5
+ whenToUseMaxItems: 8,
6
+ whenToUseItemMaxChars: 100,
7
+ whenNotToUseMaxItems: 4,
8
+ whenNotToUseItemMaxChars: 80,
9
+ examplesMaxItems: 3,
10
+ };
11
+ /** Format a per-plugin, per-field message prefix. */
12
+ function tag(pluginName, fieldPath) {
13
+ return `[${pluginName}] ${fieldPath}:`;
14
+ }
15
+ /**
16
+ * Validate a plugin manifest at boot time.
17
+ *
18
+ * Hard rules push to `errors` and set `valid: false`.
19
+ * Soft rules push to `warnings` only — `valid` stays `true`.
20
+ *
21
+ * Cross-tool reference checking lives in `validateExamplesAgainstTools`
22
+ * because the registered tool list is only known once the plugin's
23
+ * `getTools()` has run.
24
+ */
25
+ export function validateManifest(manifest, pluginName) {
26
+ const errors = [];
27
+ const warnings = [];
28
+ const parsed = pluginManifestSchema.safeParse(manifest);
29
+ if (!parsed.success) {
30
+ for (const issue of parsed.error.issues) {
31
+ const path = issue.path.length > 0 ? issue.path.join('.') : '<root>';
32
+ errors.push(`${tag(pluginName, path)} ${issue.message}`);
33
+ }
34
+ return { valid: false, errors, warnings };
35
+ }
36
+ const m = parsed.data;
37
+ // Hard rule: summary must be non-empty.
38
+ if (m.summary.trim().length === 0) {
39
+ errors.push(`${tag(pluginName, 'summary')} must be non-empty.`);
40
+ }
41
+ // Hard rule: whenToUse must have ≥1 entry unless plugin is silent.
42
+ const visibility = m.visibility ?? 'on-demand';
43
+ if (visibility !== 'silent' && m.whenToUse.length < 1) {
44
+ errors.push(`${tag(pluginName, 'whenToUse')} must contain at least one entry when visibility is '${visibility}'.`);
45
+ }
46
+ // Hard rule: tags, if present, must all be lowercase.
47
+ if (m.tags) {
48
+ m.tags.forEach((t, i) => {
49
+ if (t !== t.toLowerCase()) {
50
+ errors.push(`${tag(pluginName, `tags[${i}]`)} must be lowercase (got "${t}").`);
51
+ }
52
+ });
53
+ }
54
+ // Soft rule: summary length cap.
55
+ if (m.summary.length > SOFT_LIMITS.summaryMaxChars) {
56
+ warnings.push(`${tag(pluginName, 'summary')} is ${m.summary.length} chars (recommended ≤ ${SOFT_LIMITS.summaryMaxChars}).`);
57
+ }
58
+ // Soft rule: whenToUse caps.
59
+ if (m.whenToUse.length > SOFT_LIMITS.whenToUseMaxItems) {
60
+ warnings.push(`${tag(pluginName, 'whenToUse')} has ${m.whenToUse.length} items (recommended ≤ ${SOFT_LIMITS.whenToUseMaxItems}).`);
61
+ }
62
+ m.whenToUse.forEach((line, i) => {
63
+ if (line.length > SOFT_LIMITS.whenToUseItemMaxChars) {
64
+ warnings.push(`${tag(pluginName, `whenToUse[${i}]`)} is ${line.length} chars (recommended ≤ ${SOFT_LIMITS.whenToUseItemMaxChars}).`);
65
+ }
66
+ });
67
+ // Soft rule: whenNotToUse caps.
68
+ if (m.whenNotToUse) {
69
+ if (m.whenNotToUse.length > SOFT_LIMITS.whenNotToUseMaxItems) {
70
+ warnings.push(`${tag(pluginName, 'whenNotToUse')} has ${m.whenNotToUse.length} items (recommended ≤ ${SOFT_LIMITS.whenNotToUseMaxItems}).`);
71
+ }
72
+ m.whenNotToUse.forEach((line, i) => {
73
+ if (line.length > SOFT_LIMITS.whenNotToUseItemMaxChars) {
74
+ warnings.push(`${tag(pluginName, `whenNotToUse[${i}]`)} is ${line.length} chars (recommended ≤ ${SOFT_LIMITS.whenNotToUseItemMaxChars}).`);
75
+ }
76
+ });
77
+ }
78
+ // Soft rule: examples cap.
79
+ if (m.examples && m.examples.length > SOFT_LIMITS.examplesMaxItems) {
80
+ warnings.push(`${tag(pluginName, 'examples')} has ${m.examples.length} items (recommended ≤ ${SOFT_LIMITS.examplesMaxItems}).`);
81
+ }
82
+ return { valid: errors.length === 0, errors, warnings };
83
+ }
84
+ /**
85
+ * Cross-check `examples[].tool` references against the set of tool names
86
+ * actually registered by this plugin. Run after the plugin's `getTools()`
87
+ * has been invoked.
88
+ *
89
+ * **Lenient for MCP-sourced plugins**: when `registeredToolNames` is empty,
90
+ * the plugin's tools come from `getRequestTools` (fetched per-request from
91
+ * an upstream MCP server like sandbox or memory) — boot-time validation
92
+ * can't see them. We skip the cross-check in that case rather than
93
+ * false-flag every example. Plugins with boot-time tools still get the
94
+ * full check, so stale `examples[].tool` references are caught.
95
+ */
96
+ export function validateExamplesAgainstTools(manifest, registeredToolNames, pluginName) {
97
+ const errors = [];
98
+ if (!manifest.examples)
99
+ return { errors };
100
+ // No boot-time tools registered for this plugin — tools come from
101
+ // request-time MCP fetch. We can't validate references at boot.
102
+ if (registeredToolNames.length === 0)
103
+ return { errors };
104
+ const known = new Set(registeredToolNames);
105
+ manifest.examples.forEach((ex, i) => {
106
+ if (!known.has(ex.tool)) {
107
+ errors.push(`${tag(pluginName, `examples[${i}].tool`)} references unknown tool "${ex.tool}".`);
108
+ }
109
+ });
110
+ return { errors };
111
+ }
@@ -0,0 +1,66 @@
1
+ import { type MatrixEvent } from '@ixo/matrix';
2
+ import { type File } from 'node:buffer';
3
+ export type MatrixMediaEvent = MatrixEvent<{
4
+ msgtype: 'm.file';
5
+ body: string;
6
+ filename: string;
7
+ cid: string;
8
+ sender: string;
9
+ info: {
10
+ mimetype: string;
11
+ size: number;
12
+ };
13
+ file: {
14
+ url: string;
15
+ mimetype: string;
16
+ size: number;
17
+ };
18
+ }>;
19
+ /**
20
+ * Uploads media to a Matrix room
21
+ * @param roomId The room ID to upload the media to
22
+ * @param file The file to upload
23
+ * @returns Object containing the event ID and CID of the uploaded media
24
+ */
25
+ export declare function uploadMediaToRoom(roomId: string, file: File, // This is the sqlite file it's .db file
26
+ storageKey: string): Promise<{
27
+ eventId: string;
28
+ storageKey: string;
29
+ event: MatrixMediaEvent;
30
+ }>;
31
+ export interface GetMediaFromRoomByStorageKeyResult {
32
+ mediaBuffer: Buffer;
33
+ contentInfo: {
34
+ mimetype: string;
35
+ filename: string;
36
+ storageKey: string;
37
+ };
38
+ }
39
+ /**
40
+ * Gets media from a Matrix room by CID
41
+ * @param roomId The room ID
42
+ * @param storageKey The storage key of the media
43
+ * @returns Object containing the media buffer and content info
44
+ */
45
+ export declare function getMediaFromRoomByStorageKey(roomId: string, storageKey: string): Promise<GetMediaFromRoomByStorageKeyResult | null>;
46
+ /**
47
+ * Retrieves media from a Matrix room
48
+ * @param roomId The room ID where the media is located
49
+ * @param eventId The event ID of the media
50
+ * @returns Object containing the media buffer and content info
51
+ */
52
+ export declare function getMediaFromRoom(roomId?: string, eventId?: string, cachedEvent?: MatrixMediaEvent): Promise<{
53
+ mediaBuffer: Buffer;
54
+ contentInfo: {
55
+ mimetype: string;
56
+ filename: string;
57
+ };
58
+ }>;
59
+ /**
60
+ * Deletes media from a Matrix room by storage key
61
+ * @param roomId The room ID where the media is located
62
+ * @param storageKey The storage key of the media to delete
63
+ * @returns True if deletion was successful, false if not found
64
+ */
65
+ export declare function deleteMediaFromRoom(roomId: string, storageKey: string): Promise<boolean>;
66
+ //# sourceMappingURL=matrix-upload-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matrix-upload-utils.d.ts","sourceRoot":"","sources":["../../../src/matrix/checkpointer/matrix-upload-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAiB,MAAM,aAAa,CAAC;AAE9D,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAkBxC,MAAM,MAAM,gBAAgB,GAAG,WAAW,CAAC;IACzC,OAAO,EAAE,QAAQ,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE;QACJ,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,IAAI,EAAE;QACJ,GAAG,EAAE,MAAM,CAAC;QACZ,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH,CAAC,CAAC;AAEH;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,IAAI,EAAE,wCAAwC;AACpD,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,gBAAgB,CAAA;CAAE,CAAC,CA0H3E;AAED,MAAM,WAAW,kCAAkC;IACjD,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE;QACX,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;CACH;AAED;;;;;GAKG;AACH,wBAAsB,4BAA4B,CAChD,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,kCAAkC,GAAG,IAAI,CAAC,CA6DpD;AAED;;;;;GAKG;AAEH,wBAAsB,gBAAgB,CACpC,MAAM,CAAC,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,gBAAgB,GAC7B,OAAO,CAAC;IACT,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE;QACX,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;CACH,CAAC,CA0CD;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,OAAO,CAAC,CAqElB"}
@@ -0,0 +1,228 @@
1
+ import { MatrixManager } from '@ixo/matrix';
2
+ import { Logger } from '@nestjs/common';
3
+ const logger = new Logger('MatrixUploadUtils');
4
+ const getClient = () => {
5
+ const client = MatrixManager.getInstance().getClient();
6
+ if (!client) {
7
+ throw new Error('Matrix client not found');
8
+ }
9
+ return client;
10
+ };
11
+ const EVENTS = {
12
+ MEDIA_STATE: 'm.ixo.media_state',
13
+ MEDIA_UPLOAD: 'm.ixo.media_upload',
14
+ MEDIA: 'm.ixo.media',
15
+ };
16
+ /**
17
+ * Uploads media to a Matrix room
18
+ * @param roomId The room ID to upload the media to
19
+ * @param file The file to upload
20
+ * @returns Object containing the event ID and CID of the uploaded media
21
+ */
22
+ export async function uploadMediaToRoom(roomId, file, // This is the sqlite file it's .db file
23
+ storageKey) {
24
+ const client = getClient();
25
+ logger.debug(`Uploading media to room ${roomId} with storageKey ${storageKey}, file size: ${file.size} bytes`);
26
+ // Look up the old media event ID (if any) so we can redact it AFTER the new upload succeeds.
27
+ // This avoids data loss if the upload fails — the old checkpoint stays intact until replaced.
28
+ let oldEventId;
29
+ try {
30
+ const existingMedia = await client.mxClient.getRoomStateEvent(roomId, EVENTS.MEDIA_STATE, storageKey);
31
+ if (existingMedia && existingMedia.eventId) {
32
+ oldEventId = existingMedia.eventId;
33
+ logger.debug(`Found existing media event ${oldEventId} for storageKey ${storageKey}, will redact after successful upload`);
34
+ }
35
+ }
36
+ catch (_error) {
37
+ // State event doesn't exist, proceed with upload
38
+ logger.debug(`No existing media state event found for storageKey ${storageKey}, proceeding with new upload`);
39
+ }
40
+ // Check if room is encrypted and upload media
41
+ const isRoomEncrypted = await client.mxClient.crypto.isRoomEncrypted(roomId);
42
+ logger.debug(`Room ${roomId} is ${isRoomEncrypted ? 'encrypted' : 'unencrypted'}, proceeding with ${isRoomEncrypted ? 'encrypted' : 'unencrypted'} upload`);
43
+ let event;
44
+ let eventId;
45
+ if (isRoomEncrypted) {
46
+ // For encrypted rooms
47
+ logger.debug(`Encrypting media for storageKey ${storageKey}`);
48
+ const encrypted = await client.mxClient.crypto.encryptMedia(Buffer.from(await file.arrayBuffer()));
49
+ logger.debug(`Uploading encrypted content for storageKey ${storageKey}`);
50
+ const mxc = await client.mxClient.uploadContent(encrypted.buffer);
51
+ eventId = await client.mxClient.sendEvent(roomId, EVENTS.MEDIA_UPLOAD, {
52
+ msgtype: 'm.file',
53
+ body: storageKey,
54
+ filename: storageKey,
55
+ cid: storageKey,
56
+ sender: client.mxClient.getUserId(),
57
+ info: {
58
+ mimetype: 'application/x-sqlite3',
59
+ size: file.size,
60
+ },
61
+ file: {
62
+ url: mxc,
63
+ ...encrypted.file,
64
+ },
65
+ });
66
+ logger.debug(`Media event created with eventId ${eventId} for storageKey ${storageKey}`);
67
+ event = await client.mxClient.getEvent(roomId, eventId);
68
+ }
69
+ else {
70
+ // For unencrypted rooms
71
+ logger.debug(`Uploading unencrypted content for storageKey ${storageKey}`);
72
+ const mxc = await client.mxClient.uploadContent(Buffer.from(await file.arrayBuffer()));
73
+ eventId = await client.mxClient.sendEvent(roomId, EVENTS.MEDIA_UPLOAD, {
74
+ msgtype: 'm.file',
75
+ body: storageKey,
76
+ filename: storageKey,
77
+ cid: storageKey,
78
+ sender: client.mxClient.getUserId(),
79
+ info: {
80
+ mimetype: 'application/x-sqlite3',
81
+ size: file.size,
82
+ },
83
+ url: mxc,
84
+ });
85
+ logger.debug(`Media event created with eventId ${eventId} for storageKey ${storageKey}`);
86
+ event = await client.mxClient.getEvent(roomId, eventId);
87
+ }
88
+ // Save the media event ID in the room state with storageKey as the key
89
+ logger.debug(`Saving media state event for storageKey ${storageKey} with eventId ${eventId}`);
90
+ await client.mxClient.sendStateEvent(roomId, EVENTS.MEDIA_STATE, storageKey, {
91
+ eventId,
92
+ });
93
+ // Now that the new upload is live and the state pointer is updated,
94
+ // redact the old media event to reclaim storage. This is safe — if
95
+ // redaction fails, we just have a dangling old blob (no data loss).
96
+ if (oldEventId) {
97
+ try {
98
+ await client.mxClient.redactEvent(roomId, oldEventId, 'Replacing with updated file');
99
+ logger.debug(`Successfully redacted old media event ${oldEventId}`);
100
+ }
101
+ catch (redactError) {
102
+ logger.warn(`Failed to redact old media event ${oldEventId}:`, redactError);
103
+ }
104
+ }
105
+ logger.debug(`Successfully uploaded media to room ${roomId} with storageKey ${storageKey}, eventId: ${eventId}`);
106
+ return { eventId, storageKey, event };
107
+ }
108
+ /**
109
+ * Gets media from a Matrix room by CID
110
+ * @param roomId The room ID
111
+ * @param storageKey The storage key of the media
112
+ * @returns Object containing the media buffer and content info
113
+ */
114
+ export async function getMediaFromRoomByStorageKey(roomId, storageKey) {
115
+ const client = getClient();
116
+ // Get the event ID from room state
117
+ try {
118
+ logger.debug(`Attempting to retrieve media from room ${roomId} with storageKey ${storageKey}`);
119
+ const stateEvent = await client.mxClient.getRoomStateEvent(roomId, EVENTS.MEDIA_STATE, storageKey);
120
+ if (!stateEvent || !stateEvent.eventId) {
121
+ logger.warn(`No media state event found with storageKey: ${storageKey} in room ${roomId}`);
122
+ return null;
123
+ }
124
+ logger.debug(`Found media state event with eventId: ${stateEvent.eventId} for storageKey: ${storageKey}`);
125
+ // Get the media using the event ID
126
+ const result = await getMediaFromRoom(roomId, stateEvent.eventId);
127
+ logger.debug(`Successfully retrieved media for storageKey: ${storageKey}, size: ${result.mediaBuffer.length} bytes`);
128
+ // Add CID to content info
129
+ return {
130
+ mediaBuffer: result.mediaBuffer,
131
+ contentInfo: {
132
+ ...result.contentInfo,
133
+ storageKey,
134
+ },
135
+ };
136
+ }
137
+ catch (error) {
138
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
139
+ // Check if it's an M_NOT_FOUND error and ignore it
140
+ if (errorMessage.includes('M_NOT_FOUND') ||
141
+ errorMessage.includes('Event not found')) {
142
+ logger.debug(`Media not found in Matrix for storageKey ${storageKey} (M_NOT_FOUND), this is expected for new checkpoints`);
143
+ return null;
144
+ }
145
+ // For other errors, log and rethrow
146
+ logger.error(`Error retrieving media with storageKey ${storageKey}: ${errorMessage}`, error instanceof Error ? error.stack : undefined);
147
+ throw new Error(`Error retrieving media with storageKey ${storageKey}: ${errorMessage}`);
148
+ }
149
+ }
150
+ /**
151
+ * Retrieves media from a Matrix room
152
+ * @param roomId The room ID where the media is located
153
+ * @param eventId The event ID of the media
154
+ * @returns Object containing the media buffer and content info
155
+ */
156
+ export async function getMediaFromRoom(roomId, eventId, cachedEvent) {
157
+ if ((!roomId || !eventId) && !cachedEvent) {
158
+ throw new Error('Either roomId and eventId or cachedEvent must be provided');
159
+ }
160
+ const client = getClient();
161
+ const event = cachedEvent || (await client.mxClient.getEvent(roomId, eventId));
162
+ if (!event.content ||
163
+ !['m.file', 'm.image'].includes(event.content.msgtype)) {
164
+ throw new Error('Event is not a media event.');
165
+ }
166
+ const isEncrypted = !!event.content.file;
167
+ if (isEncrypted) {
168
+ const decryptedData = await client.mxClient.crypto.decryptMedia(event.content.file);
169
+ return {
170
+ mediaBuffer: decryptedData,
171
+ contentInfo: {
172
+ mimetype: event.content.info?.mimetype || 'application/octet-stream',
173
+ filename: event.content.filename || 'download',
174
+ },
175
+ };
176
+ }
177
+ else {
178
+ const mediaBuffer = await client.mxClient.downloadContent(event.content.url);
179
+ return {
180
+ mediaBuffer: mediaBuffer.data,
181
+ contentInfo: {
182
+ mimetype: event.content.info?.mimetype || 'application/octet-stream',
183
+ filename: event.content.filename || 'download',
184
+ },
185
+ };
186
+ }
187
+ }
188
+ /**
189
+ * Deletes media from a Matrix room by storage key
190
+ * @param roomId The room ID where the media is located
191
+ * @param storageKey The storage key of the media to delete
192
+ * @returns True if deletion was successful, false if not found
193
+ */
194
+ export async function deleteMediaFromRoom(roomId, storageKey) {
195
+ const client = getClient();
196
+ try {
197
+ logger.debug(`Attempting to delete media from room ${roomId} with storageKey ${storageKey}`);
198
+ // Get the event ID from room state
199
+ const stateEvent = await client.mxClient.getRoomStateEvent(roomId, EVENTS.MEDIA_STATE, storageKey);
200
+ if (!stateEvent || !stateEvent.eventId) {
201
+ logger.warn(`No media state event found with storageKey: ${storageKey} in room ${roomId}`);
202
+ return false;
203
+ }
204
+ logger.debug(`Found media event ${stateEvent.eventId} for storageKey ${storageKey}, attempting to redact`);
205
+ // Redact the media event to delete the DB file from the server
206
+ try {
207
+ await client.mxClient.redactEvent(roomId, stateEvent.eventId, 'User requested deletion');
208
+ logger.debug(`Successfully redacted media event ${stateEvent.eventId} for storageKey ${storageKey}`);
209
+ }
210
+ catch (redactError) {
211
+ logger.error(`Failed to redact media event ${stateEvent.eventId}:`, redactError);
212
+ throw redactError;
213
+ }
214
+ return true;
215
+ }
216
+ catch (error) {
217
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
218
+ // Check if it's an M_NOT_FOUND error
219
+ if (errorMessage.includes('M_NOT_FOUND') ||
220
+ errorMessage.includes('Event not found')) {
221
+ logger.debug(`Media not found in Matrix for storageKey ${storageKey} (M_NOT_FOUND)`);
222
+ return false;
223
+ }
224
+ // For other errors, log and rethrow
225
+ logger.error(`Error deleting media with storageKey ${storageKey}: ${errorMessage}`, error instanceof Error ? error.stack : undefined);
226
+ throw new Error(`Error deleting media with storageKey ${storageKey}: ${errorMessage}`);
227
+ }
228
+ }
@@ -0,0 +1,4 @@
1
+ export interface BaseSyncArgs {
2
+ userDid: string;
3
+ }
4
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../src/matrix/checkpointer/type.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;CACjB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export declare class CheckpointStorageSyncModule {
2
+ }
3
+ //# sourceMappingURL=user-matrix-sqlite-sync-service.module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user-matrix-sqlite-sync-service.module.d.ts","sourceRoot":"","sources":["../../../src/matrix/checkpointer/user-matrix-sqlite-sync-service.module.ts"],"names":[],"mappings":"AAGA,qBASa,2BAA2B;CAAG"}
@@ -0,0 +1,22 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { Module } from '@nestjs/common';
8
+ import { UserMatrixSqliteSyncService } from './user-matrix-sqlite-sync-service.service.js';
9
+ let CheckpointStorageSyncModule = class CheckpointStorageSyncModule {
10
+ };
11
+ CheckpointStorageSyncModule = __decorate([
12
+ Module({
13
+ providers: [
14
+ {
15
+ provide: UserMatrixSqliteSyncService,
16
+ useFactory: () => UserMatrixSqliteSyncService.getInstance(),
17
+ },
18
+ ],
19
+ exports: [UserMatrixSqliteSyncService],
20
+ })
21
+ ], CheckpointStorageSyncModule);
22
+ export { CheckpointStorageSyncModule };
@@ -0,0 +1,93 @@
1
+ import { OnModuleInit } from '@nestjs/common';
2
+ import { type Database as DatabaseType } from 'better-sqlite3';
3
+ import { type BaseSyncArgs } from './type.js';
4
+ export declare class UserMatrixSqliteSyncService implements OnModuleInit {
5
+ private static instance;
6
+ readonly fileEventsDatabase: DatabaseType;
7
+ private constructor();
8
+ private readonly filePathCache;
9
+ private readonly dbConnectionCache;
10
+ /** Reference-counted active users — supports nested markUserActive/markUserInactive calls */
11
+ private readonly activeUsers;
12
+ private readonly downloadInProgress;
13
+ private readonly recoveryInProgress;
14
+ private readonly lastUploadedChecksum;
15
+ /**
16
+ * Users whose SQLite checkpoint has been synced from Matrix at least once
17
+ * in this process lifetime. We're a single-node deployment: after the
18
+ * first sync, the local copy IS the source of truth until shutdown (which
19
+ * uploads back to Matrix). Skipping re-syncs on subsequent requests for
20
+ * the same user is the dominant TTFB win.
21
+ */
22
+ private readonly syncedUsers;
23
+ /** Prevents overlapping cron executions from interleaving I/O on the same files */
24
+ private cronRunning;
25
+ markUserActive(userDid: string): void;
26
+ markUserInactive(userDid: string): void;
27
+ private isUserActive;
28
+ static createUserStorageKey(userDid: string): string;
29
+ static getUserCheckpointDbPath(userDid: string): string;
30
+ static checkpointsFolder: string;
31
+ onModuleInit(): Promise<void>;
32
+ /**
33
+ * Get or create database connection for a user.
34
+ * Ensures database exists and is synced from Matrix on the first request
35
+ * per user per process; subsequent calls reuse the local file.
36
+ * Includes automatic corruption recovery.
37
+ */
38
+ getUserDatabase(userDid: string): Promise<DatabaseType>;
39
+ /**
40
+ * Same as `getUserDatabase` but never triggers a Matrix → SQLite sync.
41
+ * Used by hot paths that follow an earlier `getUserDatabase` call within
42
+ * the same request (e.g. the fire-and-forget post-message sync).
43
+ */
44
+ getUserDatabaseNoSync(userDid: string): Promise<DatabaseType>;
45
+ private openUserDatabaseFromDisk;
46
+ /**
47
+ * Attempts cascading recovery when a local database is corrupt:
48
+ * 1. Clear local → re-download from Matrix → validate
49
+ * 2. If Matrix copy also corrupt → delete from Matrix → create fresh empty DB
50
+ */
51
+ private recoverCorruptDatabase;
52
+ /**
53
+ * Opens a SQLite database and validates it is not corrupt.
54
+ * Returns the Database instance if valid, or null if corrupt/missing.
55
+ */
56
+ private openAndValidateDatabase;
57
+ /**
58
+ * Deletes local checkpoint file and clears all associated caches for a user.
59
+ */
60
+ private clearLocalCheckpoint;
61
+ private initializeSessionsAndCallsTables;
62
+ localStorageCacheCleanUpTask(): Promise<void>;
63
+ /**
64
+ * Get the singleton instance of UserMatrixSqliteSyncService
65
+ * @param maxCacheSize - Maximum number of cached files (default: 100)
66
+ * @returns The singleton instance
67
+ */
68
+ static getInstance(): UserMatrixSqliteSyncService;
69
+ /**
70
+ * Load the checkpoint SQLite file for a user.
71
+ * First checks the local cache, then matrix storage if not cached.
72
+ * @param userDid - The user's DID identifier
73
+ * @returns Promise resolving to the SQLite file buffer
74
+ */
75
+ syncLocalStorageFromMatrixStorage(params: BaseSyncArgs): Promise<void>;
76
+ private _syncLocalStorageFromMatrixStorage;
77
+ /**
78
+ * Sync checkpoint file from local cache to S3.
79
+ * @param userDid - The user's DID identifier
80
+ * @returns Promise that resolves when sync is complete
81
+ */
82
+ uploadCheckpointToMatrixStorage(params: BaseSyncArgs): Promise<void>;
83
+ uploadCheckpointToMatrixStorageTask(): Promise<void>;
84
+ /**
85
+ * Deletes user storage from Matrix and cleans up local cache
86
+ * @param userDid The user DID
87
+ * @param storageKey Optional storage key. If not provided, uses the default user storage key
88
+ * @returns True if deletion was successful, false if not found
89
+ */
90
+ deleteUserStorageFromMatrix(userDid: string, storageKey?: string): Promise<boolean>;
91
+ private saveFileEventToDB;
92
+ }
93
+ //# sourceMappingURL=user-matrix-sqlite-sync-service.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user-matrix-sqlite-sync-service.service.d.ts","sourceRoot":"","sources":["../../../src/matrix/checkpointer/user-matrix-sqlite-sync-service.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAIL,YAAY,EACb,MAAM,gBAAgB,CAAC;AAWxB,OAAiB,EAAE,KAAK,QAAQ,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAUzE,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AA+C9C,qBACa,2BAA4B,YAAW,YAAY;IAC9D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA8B;IAErD,QAAQ,CAAC,kBAAkB,EAAE,YAAY,CAAC;IAC1C,OAAO;IAkBP,OAAO,CAAC,QAAQ,CAAC,aAAa,CAM1B;IAEJ,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAM9B;IAEJ,6FAA6F;IAC7F,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA6B;IAEzD,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAoC;IACvE,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAG/B;IAEJ,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAA6B;IAElE;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAqB;IAEjD,mFAAmF;IACnF,OAAO,CAAC,WAAW,CAAS;IAErB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAKrC,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAS9C,OAAO,CAAC,YAAY;IAGpB,MAAM,CAAC,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAKpD,MAAM,CAAC,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IASvD,MAAM,CAAC,iBAAiB,SAGtB;IAEW,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAuE1C;;;;;OAKG;IACU,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IASpE;;;;OAIG;IACU,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;YAI5D,wBAAwB;IAqDtC;;;;OAIG;YACW,sBAAsB;IA0DpC;;;OAGG;IACH,OAAO,CAAC,uBAAuB;IAwC/B;;OAEG;YACW,oBAAoB;IAiDlC,OAAO,CAAC,gCAAgC;IA4B3B,4BAA4B,IAAI,OAAO,CAAC,IAAI,CAAC;IA2F1D;;;;OAIG;WACW,WAAW,IAAI,2BAA2B;IAOxD;;;;;OAKG;IACU,iCAAiC,CAC5C,MAAM,EAAE,YAAY,GACnB,OAAO,CAAC,IAAI,CAAC;YAsBF,kCAAkC;IA2LhD;;;;OAIG;IACG,+BAA+B,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAoHpE,mCAAmC,IAAI,OAAO,CAAC,IAAI,CAAC;IAqC1D;;;;;OAKG;IACG,2BAA2B,CAC/B,OAAO,EAAE,MAAM,EACf,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,OAAO,CAAC;YAyFL,iBAAiB;CAsBhC"}