@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,72 @@
1
+ import type { MatrixClient } from 'matrix-js-sdk';
2
+ import { z } from 'zod';
3
+ import type { RuntimeContext } from '../../plugin-api/types.js';
4
+ import { type AppConfig } from './provider.js';
5
+ /**
6
+ * Minimal UCAN surface the tool depends on. Decoupled from the concrete
7
+ * `UcanService` class so the editor plugin can pass `rtCtx.ucan` directly
8
+ * (the runtime adapter exposes exactly these methods).
9
+ */
10
+ export interface UcanMintCapable {
11
+ hasSigningKey(): boolean;
12
+ createInvocationFromDelegation: RuntimeContext['ucan']['createInvocationFromDelegation'];
13
+ }
14
+ /** Same narrow shape for the blob store, taken from `rtCtx.blobStore`. */
15
+ export type BlobStoreCapable = Pick<RuntimeContext['blobStore'], 'put'>;
16
+ export interface CreateMintInvocationEditorToolParams {
17
+ matrixClient: MatrixClient;
18
+ appConfig: AppConfig;
19
+ roomId: string;
20
+ ucanService: UcanMintCapable;
21
+ /** When provided alongside `userDid`, the minted invocation is stored in
22
+ * the blob store and the tool result includes a `blobId` the main agent
23
+ * can pass to `sandbox_write_blob` — avoiding LLM relay of the CAR. */
24
+ blobStore?: BlobStoreCapable;
25
+ /** Owner of the blob — used as the cache namespace. Required for blob
26
+ * storage; without it the tool falls back to returning only the raw CAR. */
27
+ userDid?: string;
28
+ }
29
+ /**
30
+ * Editor-scoped `mint_invocation` tool.
31
+ *
32
+ * Lives on the editor agent (not the main agent) because minting requires
33
+ * Y.Doc access via Matrix to fetch the user's delegation by CID — and the
34
+ * editor agent is the only one with `matrixClient` + `roomId` in its
35
+ * closure. The main agent invokes it through `call_editor_agent`.
36
+ *
37
+ * Two input modes — at least one must be provided:
38
+ *
39
+ * 1. `delegationCid` (preferred). The tool opens the flow's Y.Doc, looks
40
+ * up the delegation entry by CID, and reads its `delegation` field
41
+ * (the base64 CAR) directly. The 580-char base64 string never leaves
42
+ * this process and never crosses the LLM, so it can't be corrupted in
43
+ * transit.
44
+ *
45
+ * 2. `delegationCar` (legacy / external callers). Pass the base64 CAR
46
+ * directly — used when the caller already has the bytes in hand and
47
+ * doesn't want a Y.Doc lookup.
48
+ *
49
+ * Either way, the tool calls `ucanService.createInvocationFromDelegation`
50
+ * and returns a fresh single-use base64 CAR invocation that the caller
51
+ * (typically a sandbox skill) writes to its expected token file.
52
+ */
53
+ export declare const createMintInvocationEditorTool: ({ matrixClient, appConfig, roomId: _roomId, ucanService, blobStore, userDid, }: CreateMintInvocationEditorToolParams) => import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{
54
+ delegationCid: z.ZodNullable<z.ZodOptional<z.ZodString>>;
55
+ delegationCar: z.ZodNullable<z.ZodOptional<z.ZodString>>;
56
+ serviceUrl: z.ZodString;
57
+ can: z.ZodString;
58
+ withResource: z.ZodString;
59
+ }, z.core.$strip>, {
60
+ serviceUrl: string;
61
+ can: string;
62
+ withResource: string;
63
+ delegationCid?: string | null | undefined;
64
+ delegationCar?: string | null | undefined;
65
+ }, {
66
+ serviceUrl: string;
67
+ can: string;
68
+ withResource: string;
69
+ delegationCid?: string | null | undefined;
70
+ delegationCar?: string | null | undefined;
71
+ }, string, unknown, "mint_invocation">;
72
+ //# sourceMappingURL=mint-invocation-tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mint-invocation-tool.d.ts","sourceRoot":"","sources":["../../../src/plugins/editor/mint-invocation-tool.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAGhE,OAAO,EAAE,KAAK,SAAS,EAAyB,MAAM,eAAe,CAAC;AAItE;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,aAAa,IAAI,OAAO,CAAC;IACzB,8BAA8B,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC,gCAAgC,CAAC,CAAC;CAC1F;AAED,0EAA0E;AAC1E,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC,CAAC;AAExE,MAAM,WAAW,oCAAoC;IACnD,YAAY,EAAE,YAAY,CAAC;IAC3B,SAAS,EAAE,SAAS,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,eAAe,CAAC;IAC7B;;2EAEuE;IACvE,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B;gFAC4E;IAC5E,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,8BAA8B,GAAI,gFAW5C,oCAAoC;;;;;;;;;;;;;;;;;;sCA2KpC,CAAC"}
@@ -0,0 +1,173 @@
1
+ import { tool } from '@langchain/core/tools';
2
+ import { Logger } from '@nestjs/common';
3
+ import { z } from 'zod';
4
+ import { readDelegations } from './blocknote-helper.js';
5
+ import { MatrixProviderManager } from './provider.js';
6
+ const logger = new Logger('mint_invocation');
7
+ /**
8
+ * Editor-scoped `mint_invocation` tool.
9
+ *
10
+ * Lives on the editor agent (not the main agent) because minting requires
11
+ * Y.Doc access via Matrix to fetch the user's delegation by CID — and the
12
+ * editor agent is the only one with `matrixClient` + `roomId` in its
13
+ * closure. The main agent invokes it through `call_editor_agent`.
14
+ *
15
+ * Two input modes — at least one must be provided:
16
+ *
17
+ * 1. `delegationCid` (preferred). The tool opens the flow's Y.Doc, looks
18
+ * up the delegation entry by CID, and reads its `delegation` field
19
+ * (the base64 CAR) directly. The 580-char base64 string never leaves
20
+ * this process and never crosses the LLM, so it can't be corrupted in
21
+ * transit.
22
+ *
23
+ * 2. `delegationCar` (legacy / external callers). Pass the base64 CAR
24
+ * directly — used when the caller already has the bytes in hand and
25
+ * doesn't want a Y.Doc lookup.
26
+ *
27
+ * Either way, the tool calls `ucanService.createInvocationFromDelegation`
28
+ * and returns a fresh single-use base64 CAR invocation that the caller
29
+ * (typically a sandbox skill) writes to its expected token file.
30
+ */
31
+ export const createMintInvocationEditorTool = ({ matrixClient, appConfig,
32
+ // roomId is part of the shared tool-factory contract but not used by
33
+ // this specific tool — minting only needs the userDid, ucanService and
34
+ // the delegation source (cid via blobStore, or inline CAR). Prefixed
35
+ // with `_` so the unused-vars rule lets it through.
36
+ roomId: _roomId, ucanService, blobStore, userDid, }) => tool(async ({ delegationCid = null, delegationCar = null, serviceUrl, can, withResource, }) => {
37
+ logger.log(`🪙 mint_invocation invoked (service=${serviceUrl}, can=${can}, with=${withResource}, mode=${delegationCid ? 'cid' : 'car'})`);
38
+ if (!ucanService.hasSigningKey()) {
39
+ return JSON.stringify({
40
+ success: false,
41
+ error: 'Oracle has no UCAN signing key configured. Check SERVICE_ED25519_MNEMONIC.',
42
+ });
43
+ }
44
+ let resolvedCar = null;
45
+ if (delegationCid && typeof delegationCid === 'string') {
46
+ // Preferred path: look up the delegation in this flow's Y.Doc by CID.
47
+ // No string ever crosses the LLM, so corruption-in-relay is impossible.
48
+ const providerManager = new MatrixProviderManager(matrixClient, appConfig);
49
+ try {
50
+ const { doc } = await providerManager.init();
51
+ const { delegations } = readDelegations(doc);
52
+ const match = delegations.find((d) => d['cid'] === delegationCid);
53
+ if (!match) {
54
+ return JSON.stringify({
55
+ success: false,
56
+ error: `Delegation with cid "${delegationCid}" not found in this flow's permissions store. The user may not have signed it yet, or Matrix sync has not delivered it to the oracle. Re-check the cid in the companion prompt and confirm the delegation exists via read_permissions.`,
57
+ });
58
+ }
59
+ const car = match['delegation'];
60
+ if (typeof car !== 'string' || !car) {
61
+ return JSON.stringify({
62
+ success: false,
63
+ error: `Delegation entry for cid "${delegationCid}" has no \`delegation\` (base64 CAR) field. Stored entry shape may be legacy/unsupported.`,
64
+ });
65
+ }
66
+ resolvedCar = car.trim();
67
+ }
68
+ catch (error) {
69
+ return JSON.stringify({
70
+ success: false,
71
+ error: `Failed to read delegation by cid: ${error instanceof Error ? error.message : String(error)}`,
72
+ });
73
+ }
74
+ finally {
75
+ await providerManager.dispose();
76
+ }
77
+ }
78
+ else if (delegationCar && typeof delegationCar === 'string') {
79
+ resolvedCar = delegationCar.trim();
80
+ }
81
+ else {
82
+ return JSON.stringify({
83
+ success: false,
84
+ error: 'Either `delegationCid` (preferred — the tool will look up the CAR from the Y.Doc) or `delegationCar` (the base64 CAR string directly) must be provided.',
85
+ });
86
+ }
87
+ try {
88
+ const result = await ucanService.createInvocationFromDelegation(resolvedCar, serviceUrl, { can, with: withResource });
89
+ if ('error' in result) {
90
+ return JSON.stringify({ success: false, error: result.error });
91
+ }
92
+ // Store the freshly-minted invocation in the blob store so the main
93
+ // agent can write it to the sandbox via `sandbox_write_blob` without
94
+ // ever relaying the long base64 CAR through the LLM. The CAR is
95
+ // STILL returned as `invocation` for back-compat / debugging — the
96
+ // recommended path is for callers to use `blobId`.
97
+ let blobId;
98
+ if (blobStore && userDid) {
99
+ try {
100
+ // TTL = invocation lifetime + 30s headroom for sandbox write.
101
+ // 90s default is enough since the worker rejects expired tokens
102
+ // immediately and replay protection makes a longer window pointless.
103
+ blobId = await blobStore.put({
104
+ userDid,
105
+ name: 'ucan_invocation',
106
+ value: result.invocation,
107
+ ttlSeconds: 90,
108
+ });
109
+ }
110
+ catch (err) {
111
+ logger.warn(`🪙 failed to store invocation in blob store: ${err instanceof Error ? err.message : String(err)} — caller will need to relay CAR directly`);
112
+ }
113
+ }
114
+ return JSON.stringify({
115
+ success: true,
116
+ ...(blobId ? { blobId } : {}),
117
+ invocation: result.invocation,
118
+ audienceResolvedFrom: serviceUrl,
119
+ capability: { can, with: withResource },
120
+ note: blobId
121
+ ? 'Single-use. Pass `blobId` to `sandbox_write_blob` (preferred — keeps the CAR out of the LLM context). The `invocation` field is the same value verbatim if you must handle it directly. Mint a fresh invocation before each protected call.'
122
+ : 'Single-use. Mint a fresh invocation before each protected service call.',
123
+ });
124
+ }
125
+ catch (error) {
126
+ return JSON.stringify({
127
+ success: false,
128
+ error: error instanceof Error ? error.message : String(error),
129
+ });
130
+ }
131
+ }, {
132
+ name: 'mint_invocation',
133
+ description: `Mint a fresh, single-use UCAN invocation against any UCAN-gated service, using a delegation the user already signed in the editor.
134
+
135
+ USE THIS TOOL whenever a skill needs to authenticate against an external service that requires a UCAN bearer token. Each invocation is single-use; mint a fresh one before every protected request (services typically reject reused invocation CIDs as replays).
136
+
137
+ WORKFLOW (preferred — \`delegationCid\` mode):
138
+ 1. The companion prompt provides a \`delegationCid\` (the user's signed delegation to this oracle) and a \`serviceUrl\` (the target service's base URL).
139
+ 2. Call this tool with the cid + serviceUrl + the route's required capability \`{ can, with }\`. The tool itself reads the CAR from the flow's Y.Doc — you do NOT need to call \`read_permissions\` first.
140
+ 3. It returns \`{ success, blobId, invocation, ... }\`. **Use \`blobId\` — pass it to \`sandbox_write_blob\` to write the invocation to the skill's token path.** That way the long base64 CAR never enters the LLM context where it can get corrupted. The \`invocation\` field is the same value verbatim and only there for back-compat / debugging.
141
+ 4. Run the protected command in the sandbox.
142
+
143
+ LEGACY (\`delegationCar\` mode): if you already have the base64 CAR string in hand from somewhere else, you can pass it directly via \`delegationCar\`. NOT recommended — long base64 strings can get mangled when an LLM relays them.
144
+
145
+ The audience is auto-resolved by fetching \`<serviceUrl>/.well-known/did.json\`. The invocation is signed by THIS oracle's key, with the user's delegation embedded as proof. Service validators walk the chain back to the user (the root issuer) and accept the call iff the user is on their root-issuers allowlist.
146
+
147
+ Returns:
148
+ { success: true, invocation: "<base64 CAR>", capability, audienceResolvedFrom }
149
+ or
150
+ { success: false, error: "<reason>" } — surface the error verbatim if it indicates a setup problem (missing/expired delegation, audience mismatch, did:web unreachable, signing key not configured).`,
151
+ schema: z.object({
152
+ delegationCid: z
153
+ .string()
154
+ .optional()
155
+ .nullable()
156
+ .describe('PREFERRED. The CID of a UCAN delegation stored in this flow. The tool looks up the base64 CAR from the Y.Doc itself, so you only ever pass a short ~59-char CID — no risk of string corruption. Use the value from the companion prompt\'s "UCAN delegation CID:" field.'),
157
+ delegationCar: z
158
+ .string()
159
+ .optional()
160
+ .nullable()
161
+ .describe("LEGACY. The base64-encoded delegation CAR string. Only use this when you cannot use delegationCid (e.g. the delegation lives outside the flow's Y.Doc). Long strings are vulnerable to LLM relay corruption — prefer delegationCid."),
162
+ serviceUrl: z
163
+ .string()
164
+ .url()
165
+ .describe('Base URL of the target service (used to resolve did:web). Use the URL from the companion prompt verbatim — do NOT swap to a default or guess.'),
166
+ can: z
167
+ .string()
168
+ .describe('The capability action the route requires, e.g. "service/action" or "service/*". Defined by the target service; check SKILL.md or service docs.'),
169
+ withResource: z
170
+ .string()
171
+ .describe('The capability resource URI, e.g. "ixo:my-service". Defined by the target service.'),
172
+ }),
173
+ });
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Page management functions — reusable from services, API routes, and tests.
3
+ */
4
+ import type { MatrixClient } from 'matrix-js-sdk';
5
+ import { type MatrixConfig, type ProviderConfig } from './provider.js';
6
+ export interface CreatePageParams {
7
+ matrixClient: MatrixClient;
8
+ matrixConfig: Omit<MatrixConfig, 'room'>;
9
+ providerConfig: ProviderConfig;
10
+ title: string;
11
+ topic?: string;
12
+ content?: string;
13
+ parentSpaceId?: string;
14
+ inviteUserIds?: string[];
15
+ }
16
+ export interface CreatePageResult {
17
+ roomId: string;
18
+ alias: string;
19
+ title: string;
20
+ ownerDid: string;
21
+ createdAt: string;
22
+ blockCount: number;
23
+ }
24
+ export interface ReadPageParams {
25
+ matrixClient: MatrixClient;
26
+ matrixConfig: Omit<MatrixConfig, 'room'>;
27
+ providerConfig: ProviderConfig;
28
+ roomId: string;
29
+ }
30
+ export interface ReadPageResult {
31
+ roomId: string;
32
+ metadata: Record<string, unknown>;
33
+ blocks: Array<{
34
+ id: string;
35
+ type: string;
36
+ properties: Record<string, unknown>;
37
+ text?: string;
38
+ }>;
39
+ blockCount: number;
40
+ }
41
+ /**
42
+ * Create a new page.
43
+ *
44
+ * - Generates a FE-compatible `page-{timestamp}` alias
45
+ * - Invites specified users and grants them power level 50
46
+ * - Accepts optional markdown `content` which is parsed into BlockNote blocks
47
+ */
48
+ export declare function createPage(params: CreatePageParams): Promise<CreatePageResult>;
49
+ export interface UpdatePageParams {
50
+ matrixClient: MatrixClient;
51
+ matrixConfig: Omit<MatrixConfig, 'room'>;
52
+ providerConfig: ProviderConfig;
53
+ roomId: string;
54
+ title?: string;
55
+ topic?: string;
56
+ content?: string;
57
+ appendContent?: string;
58
+ }
59
+ export interface PageDiff {
60
+ title?: {
61
+ old: string;
62
+ new: string;
63
+ };
64
+ topic?: {
65
+ old: string;
66
+ new: string;
67
+ };
68
+ content?: {
69
+ old: string;
70
+ new: string;
71
+ };
72
+ }
73
+ export interface UpdatePageResult {
74
+ roomId: string;
75
+ title: string;
76
+ ownerDid: string;
77
+ updatedAt: string;
78
+ updatedFields: string[];
79
+ blockCount: number;
80
+ diff: PageDiff;
81
+ }
82
+ /**
83
+ * Update an existing page — title, topic, content, or append content.
84
+ *
85
+ * - `title` updates the Y.Text 'title' shared type
86
+ * - `topic` updates the Matrix room topic
87
+ * - `content` replaces all blocks with parsed markdown
88
+ * - `appendContent` appends parsed markdown blocks to existing content
89
+ *
90
+ * Returns the page title, ownerDid, timestamp, and a diff object showing
91
+ * old vs new values for each changed field (for GitHub-style change rendering).
92
+ */
93
+ export declare function updatePage(params: UpdatePageParams): Promise<UpdatePageResult>;
94
+ /**
95
+ * Read an existing page by room ID.
96
+ *
97
+ * Returns metadata (title, owner, creation date) and all blocks.
98
+ */
99
+ export declare function readPage(params: ReadPageParams): Promise<ReadPageResult>;
100
+ //# sourceMappingURL=page-functions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-functions.d.ts","sourceRoot":"","sources":["../../../src/plugins/editor/page-functions.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAQlD,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,cAAc,EACpB,MAAM,eAAe,CAAC;AAwBvB,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IACzC,cAAc,EAAE,cAAc,CAAC;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IACzC,cAAc,EAAE,cAAc,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,MAAM,EAAE,KAAK,CAAC;QACZ,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACpC,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC,CAAC;IACH,UAAU,EAAE,MAAM,CAAC;CACpB;AAqCD;;;;;;GAMG;AACH,wBAAsB,UAAU,CAC9B,MAAM,EAAE,gBAAgB,GACvB,OAAO,CAAC,gBAAgB,CAAC,CAuI3B;AAID,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IACzC,cAAc,EAAE,cAAc,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,QAAQ;IACvB,KAAK,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IACrC,KAAK,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IACrC,OAAO,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;CACxC;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,QAAQ,CAAC;CAChB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAC9B,MAAM,EAAE,gBAAgB,GACvB,OAAO,CAAC,gBAAgB,CAAC,CAgJ3B;AAED;;;;GAIG;AACH,wBAAsB,QAAQ,CAC5B,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,cAAc,CAAC,CAsCzB"}
@@ -0,0 +1,317 @@
1
+ /**
2
+ * Page management functions — reusable from services, API routes, and tests.
3
+ */
4
+ import { ServerBlockNoteEditor } from '@blocknote/server-util';
5
+ import { Logger } from '@nestjs/common';
6
+ import { Preset, Visibility } from 'matrix-js-sdk';
7
+ import { collectAllBlocks, readFlowMetadata, simplifyBlockForAgent, } from './blocknote-helper.js';
8
+ import { MatrixProviderManager, } from './provider.js';
9
+ /**
10
+ * Converts a Matrix user ID in hyphen-delimited DID form (`@did-ixo-…`)
11
+ * to the canonical colon-delimited DID (`did:ixo:…`).
12
+ */
13
+ function normalizeDid(input) {
14
+ const username = input.split(':')[0] ?? '';
15
+ const parts = username.split('-');
16
+ if (parts.length < 3 || parts[0] !== '@did') {
17
+ throw new Error(`Invalid DID format: ${input}`);
18
+ }
19
+ const namespace = parts[1];
20
+ const identifier = parts.slice(2).join('-');
21
+ return `did:${namespace}:${identifier}`;
22
+ }
23
+ const logger = new Logger('PageFunctions');
24
+ // Singleton — reuse across calls (stateless, thread-safe)
25
+ const serverEditor = ServerBlockNoteEditor.create();
26
+ // ── Helpers ───────────────────────────────────────────────────────────
27
+ function validateMatrixRoomId(roomId) {
28
+ if (!/^!.+:.+$/.test(roomId)) {
29
+ throw new Error(`Invalid Matrix room ID '${roomId}'. Room IDs must start with '!' followed by the room identifier and homeserver (e.g., '!abc123:matrix.org').`);
30
+ }
31
+ }
32
+ function createPageAlias() {
33
+ return `page-${Date.now()}`;
34
+ }
35
+ function buildPageAppConfig(matrixConfig, providerConfig, roomId) {
36
+ return {
37
+ matrix: {
38
+ ...matrixConfig,
39
+ room: { type: 'id', value: roomId },
40
+ },
41
+ provider: providerConfig,
42
+ blocknote: { mutableAttributeKeys: [] },
43
+ };
44
+ }
45
+ function extractHomeserver(baseUrl) {
46
+ return baseUrl.replace(/^https?:\/\//, '');
47
+ }
48
+ // ── Core Functions ────────────────────────────────────────────────────
49
+ /**
50
+ * Create a new page.
51
+ *
52
+ * - Generates a FE-compatible `page-{timestamp}` alias
53
+ * - Invites specified users and grants them power level 50
54
+ * - Accepts optional markdown `content` which is parsed into BlockNote blocks
55
+ */
56
+ export async function createPage(params) {
57
+ const { matrixClient, matrixConfig, providerConfig, title, topic, content, parentSpaceId, inviteUserIds, } = params;
58
+ const alias = createPageAlias();
59
+ const creatorId = matrixClient.getUserId();
60
+ const homeserver = extractHomeserver(matrixConfig.baseUrl);
61
+ // Build power levels — creator gets 100, invited users get 50
62
+ const users = { [creatorId]: 100 };
63
+ if (inviteUserIds) {
64
+ for (const userId of inviteUserIds) {
65
+ users[userId] = 50;
66
+ }
67
+ }
68
+ // Build initial state events (matching FE pattern)
69
+ const initialState = [
70
+ {
71
+ type: 'm.room.history_visibility',
72
+ state_key: '',
73
+ content: { history_visibility: 'shared' },
74
+ },
75
+ {
76
+ type: 'm.room.guest_access',
77
+ state_key: '',
78
+ content: { guest_access: 'forbidden' },
79
+ },
80
+ ];
81
+ if (parentSpaceId) {
82
+ initialState.push({
83
+ type: 'm.space.parent',
84
+ state_key: parentSpaceId,
85
+ content: { via: [homeserver], canonical: true },
86
+ });
87
+ }
88
+ logger.log(`Creating page room with alias: ${alias}`);
89
+ const createRoomResponse = await matrixClient.createRoom({
90
+ room_alias_name: alias,
91
+ name: title,
92
+ topic: topic ?? 'Page',
93
+ visibility: Visibility.Private,
94
+ preset: Preset.PrivateChat,
95
+ invite: inviteUserIds ?? [],
96
+ initial_state: initialState,
97
+ power_level_content_override: {
98
+ events_default: 50,
99
+ state_default: 50,
100
+ users_default: 0,
101
+ users,
102
+ events: {
103
+ 'com.yjs.webrtc.announce': 0,
104
+ 'com.yjs.webrtc.signal': 0,
105
+ },
106
+ },
107
+ });
108
+ const roomId = createRoomResponse.room_id;
109
+ logger.log(`Page room created: ${roomId}`);
110
+ // If parent space exists, add the room as a child of the space
111
+ if (parentSpaceId) {
112
+ try {
113
+ await matrixClient.sendStateEvent(parentSpaceId,
114
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
115
+ 'm.space.child', { via: [homeserver] }, roomId);
116
+ }
117
+ catch (error) {
118
+ logger.warn(`Failed to add page as child of space ${parentSpaceId}: ${error}`);
119
+ }
120
+ }
121
+ // Parse markdown content into BlockNote blocks if provided
122
+ const blocks = content
123
+ ? await serverEditor.tryParseMarkdownToBlocks(content)
124
+ : [];
125
+ // Initialize Y.Doc with metadata and blocks
126
+ const appConfig = buildPageAppConfig(matrixConfig, providerConfig, roomId);
127
+ const providerManager = new MatrixProviderManager(matrixClient, appConfig);
128
+ const createdAt = new Date().toISOString();
129
+ const ownerDid = normalizeDid(creatorId);
130
+ try {
131
+ const { doc } = await providerManager.init();
132
+ // Set page metadata
133
+ doc.transact(() => {
134
+ const root = doc.getMap('root');
135
+ root.set('@context', 'https://ixo.world/page/0.1');
136
+ root.set('createdAt', createdAt);
137
+ root.set('ownerDid', ownerDid);
138
+ doc.getText('title').insert(0, title);
139
+ });
140
+ // Write parsed blocks into the document fragment
141
+ if (blocks.length > 0) {
142
+ const fragment = doc.getXmlFragment('document');
143
+ serverEditor.blocksToYXmlFragment(blocks, fragment);
144
+ }
145
+ }
146
+ finally {
147
+ await providerManager.dispose();
148
+ }
149
+ logger.log(`Page initialized: ${title} (${blocks.length} blocks)`);
150
+ return {
151
+ roomId,
152
+ alias,
153
+ title,
154
+ ownerDid,
155
+ createdAt,
156
+ blockCount: blocks.length,
157
+ };
158
+ }
159
+ /**
160
+ * Update an existing page — title, topic, content, or append content.
161
+ *
162
+ * - `title` updates the Y.Text 'title' shared type
163
+ * - `topic` updates the Matrix room topic
164
+ * - `content` replaces all blocks with parsed markdown
165
+ * - `appendContent` appends parsed markdown blocks to existing content
166
+ *
167
+ * Returns the page title, ownerDid, timestamp, and a diff object showing
168
+ * old vs new values for each changed field (for GitHub-style change rendering).
169
+ */
170
+ export async function updatePage(params) {
171
+ const { matrixClient, matrixConfig, providerConfig, roomId, title, topic, content, appendContent, } = params;
172
+ validateMatrixRoomId(roomId);
173
+ const updatedFields = [];
174
+ const diff = {};
175
+ // Ensure the client is in the room (same pattern as readPage)
176
+ const isInRoom = matrixClient.getRoom(roomId)?.getMember(matrixClient.getUserId() ?? '')
177
+ ?.membership === 'join';
178
+ if (!isInRoom) {
179
+ try {
180
+ await matrixClient.joinRoom(roomId);
181
+ logger.log(`Joined room ${roomId}`);
182
+ }
183
+ catch (error) {
184
+ logger.warn(`Could not join room ${roomId}: ${error}`);
185
+ }
186
+ }
187
+ // Capture old topic before updating
188
+ if (topic !== undefined) {
189
+ const room = matrixClient.getRoom(roomId);
190
+ const oldTopic = room?.currentState?.getStateEvents('m.room.topic', '')?.getContent()
191
+ ?.topic ?? '';
192
+ try {
193
+ await matrixClient.setRoomTopic(roomId, topic);
194
+ updatedFields.push('topic');
195
+ diff.topic = { old: oldTopic, new: topic };
196
+ }
197
+ catch (error) {
198
+ logger.warn(`Failed to update room topic for ${roomId}: ${error}`);
199
+ }
200
+ }
201
+ // Parse content if provided
202
+ const contentBlocks = content
203
+ ? await serverEditor.tryParseMarkdownToBlocks(content)
204
+ : [];
205
+ const appendBlocks = appendContent
206
+ ? await serverEditor.tryParseMarkdownToBlocks(appendContent)
207
+ : [];
208
+ const appConfig = buildPageAppConfig(matrixConfig, providerConfig, roomId);
209
+ const providerManager = new MatrixProviderManager(matrixClient, appConfig);
210
+ let blockCount = 0;
211
+ let currentTitle = '';
212
+ let ownerDid = '';
213
+ try {
214
+ const { doc } = await providerManager.init();
215
+ // Read metadata before mutations
216
+ const metadata = readFlowMetadata(doc);
217
+ ownerDid = metadata.ownerDid ?? '';
218
+ const oldTitle = doc.getText('title').toString();
219
+ // Snapshot old content as markdown (for diff) before any mutations
220
+ let oldContentMd = '';
221
+ if (content !== undefined || appendContent !== undefined) {
222
+ const oldBlocks = serverEditor.yXmlFragmentToBlocks(doc.getXmlFragment('document'));
223
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
224
+ oldContentMd = await serverEditor.blocksToMarkdownLossy(oldBlocks);
225
+ }
226
+ doc.transact(() => {
227
+ // Update title
228
+ if (title !== undefined) {
229
+ const titleText = doc.getText('title');
230
+ titleText.delete(0, titleText.length);
231
+ titleText.insert(0, title);
232
+ updatedFields.push('title');
233
+ diff.title = { old: oldTitle, new: title };
234
+ }
235
+ // Replace all content
236
+ if (content !== undefined && contentBlocks.length > 0) {
237
+ const fragment = doc.getXmlFragment('document');
238
+ // Clear existing content
239
+ while (fragment.length > 0) {
240
+ fragment.delete(0, 1);
241
+ }
242
+ serverEditor.blocksToYXmlFragment(contentBlocks, fragment);
243
+ updatedFields.push('content');
244
+ }
245
+ // Append content
246
+ if (appendContent !== undefined && appendBlocks.length > 0) {
247
+ const fragment = doc.getXmlFragment('document');
248
+ serverEditor.blocksToYXmlFragment(appendBlocks, fragment);
249
+ updatedFields.push('appendContent');
250
+ }
251
+ });
252
+ // Snapshot new content as markdown (for diff) after mutations
253
+ if (content !== undefined || appendContent !== undefined) {
254
+ const newBlocks = serverEditor.yXmlFragmentToBlocks(doc.getXmlFragment('document'));
255
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
256
+ const newContentMd = await serverEditor.blocksToMarkdownLossy(newBlocks);
257
+ diff.content = { old: oldContentMd, new: newContentMd };
258
+ }
259
+ // Read final title
260
+ currentTitle = doc.getText('title').toString();
261
+ // Count final blocks
262
+ const fragment = doc.getXmlFragment('document');
263
+ const allBlocks = collectAllBlocks(fragment);
264
+ blockCount = allBlocks.length;
265
+ }
266
+ finally {
267
+ await providerManager.dispose();
268
+ }
269
+ logger.log(`Page updated: ${roomId} (fields: ${updatedFields.join(', ')})`);
270
+ return {
271
+ roomId,
272
+ title: currentTitle,
273
+ ownerDid,
274
+ updatedAt: new Date().toISOString(),
275
+ updatedFields,
276
+ blockCount,
277
+ diff,
278
+ };
279
+ }
280
+ /**
281
+ * Read an existing page by room ID.
282
+ *
283
+ * Returns metadata (title, owner, creation date) and all blocks.
284
+ */
285
+ export async function readPage(params) {
286
+ const { matrixClient, matrixConfig, providerConfig, roomId } = params;
287
+ validateMatrixRoomId(roomId);
288
+ // Ensure the client is in the room
289
+ const isInRoom = matrixClient.getRoom(roomId)?.getMember(matrixClient.getUserId() ?? '')
290
+ ?.membership === 'join';
291
+ if (!isInRoom) {
292
+ try {
293
+ await matrixClient.joinRoom(roomId);
294
+ logger.log(`Joined room ${roomId}`);
295
+ }
296
+ catch (error) {
297
+ logger.warn(`Could not join room ${roomId}: ${error}`);
298
+ }
299
+ }
300
+ const appConfig = buildPageAppConfig(matrixConfig, providerConfig, roomId);
301
+ const providerManager = new MatrixProviderManager(matrixClient, appConfig);
302
+ try {
303
+ const { doc } = await providerManager.init();
304
+ const metadata = readFlowMetadata(doc);
305
+ const rawBlocks = collectAllBlocks(doc.getXmlFragment('document'));
306
+ const simplifiedBlocks = rawBlocks.map((b) => simplifyBlockForAgent(b));
307
+ return {
308
+ roomId,
309
+ metadata,
310
+ blocks: simplifiedBlocks,
311
+ blockCount: simplifiedBlocks.length,
312
+ };
313
+ }
314
+ finally {
315
+ await providerManager.dispose();
316
+ }
317
+ }