n8n 2.15.0 → 2.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (414) hide show
  1. package/dist/active-workflow-manager.js +25 -12
  2. package/dist/active-workflow-manager.js.map +1 -1
  3. package/dist/auth/auth.service.js +1 -0
  4. package/dist/auth/auth.service.js.map +1 -1
  5. package/dist/build.tsbuildinfo +1 -1
  6. package/dist/commands/base-command.js +7 -1
  7. package/dist/commands/base-command.js.map +1 -1
  8. package/dist/controllers/ai.controller.js +2 -2
  9. package/dist/controllers/ai.controller.js.map +1 -1
  10. package/dist/controllers/e2e.controller.js +2 -0
  11. package/dist/controllers/e2e.controller.js.map +1 -1
  12. package/dist/credentials/credentials.controller.js +1 -1
  13. package/dist/credentials/credentials.controller.js.map +1 -1
  14. package/dist/credentials/credentials.service.d.ts +7 -4
  15. package/dist/credentials/credentials.service.js +77 -16
  16. package/dist/credentials/credentials.service.js.map +1 -1
  17. package/dist/credentials-helper.js +7 -1
  18. package/dist/credentials-helper.js.map +1 -1
  19. package/dist/errors/http-error-classifier.d.ts +31 -0
  20. package/dist/errors/http-error-classifier.js +60 -0
  21. package/dist/errors/http-error-classifier.js.map +1 -0
  22. package/dist/errors/http-error-serializers.d.ts +18 -0
  23. package/dist/errors/http-error-serializers.js +64 -0
  24. package/dist/errors/http-error-serializers.js.map +1 -0
  25. package/dist/eventbus/event-message-classes/index.d.ts +2 -2
  26. package/dist/eventbus/event-message-classes/index.js +3 -0
  27. package/dist/eventbus/event-message-classes/index.js.map +1 -1
  28. package/dist/events/maps/relay.event-map.d.ts +22 -0
  29. package/dist/events/relays/log-streaming.event-relay.d.ts +3 -0
  30. package/dist/events/relays/log-streaming.event-relay.js +21 -0
  31. package/dist/events/relays/log-streaming.event-relay.js.map +1 -1
  32. package/dist/execution-lifecycle/execution-lifecycle-hooks.js +2 -0
  33. package/dist/execution-lifecycle/execution-lifecycle-hooks.js.map +1 -1
  34. package/dist/executions/execution.service.js +2 -1
  35. package/dist/executions/execution.service.js.map +1 -1
  36. package/dist/modules/chat-hub/chat-hub-workflow.service.d.ts +1 -0
  37. package/dist/modules/chat-hub/chat-hub-workflow.service.js +18 -2
  38. package/dist/modules/chat-hub/chat-hub-workflow.service.js.map +1 -1
  39. package/dist/modules/chat-hub/chat-hub.types.d.ts +5 -0
  40. package/dist/modules/chat-hub/chat-hub.types.js +1 -0
  41. package/dist/modules/chat-hub/chat-hub.types.js.map +1 -1
  42. package/dist/modules/chat-hub/context-limits.js +10 -0
  43. package/dist/modules/chat-hub/context-limits.js.map +1 -1
  44. package/dist/modules/community-packages/community-node-types-utils.d.ts +2 -2
  45. package/dist/modules/community-packages/community-node-types-utils.js +4 -4
  46. package/dist/modules/community-packages/community-node-types-utils.js.map +1 -1
  47. package/dist/modules/community-packages/strapi-utils.d.ts +1 -1
  48. package/dist/modules/data-table/data-table-proxy.service.d.ts +44 -2
  49. package/dist/modules/data-table/data-table-proxy.service.js +86 -2
  50. package/dist/modules/data-table/data-table-proxy.service.js.map +1 -1
  51. package/dist/modules/dynamic-credentials.ee/services/resolver-config-expression.service.js +10 -4
  52. package/dist/modules/dynamic-credentials.ee/services/resolver-config-expression.service.js.map +1 -1
  53. package/dist/modules/instance-ai/compaction.service.d.ts +19 -0
  54. package/dist/modules/instance-ai/compaction.service.js +213 -0
  55. package/dist/modules/instance-ai/compaction.service.js.map +1 -0
  56. package/dist/modules/instance-ai/entities/index.d.ts +7 -0
  57. package/dist/modules/instance-ai/entities/index.js +18 -0
  58. package/dist/modules/instance-ai/entities/index.js.map +1 -0
  59. package/dist/modules/instance-ai/entities/instance-ai-iteration-log.entity.d.ts +7 -0
  60. package/dist/modules/instance-ai/entities/instance-ai-iteration-log.entity.js +38 -0
  61. package/dist/modules/instance-ai/entities/instance-ai-iteration-log.entity.js.map +1 -0
  62. package/dist/modules/instance-ai/entities/instance-ai-message.entity.d.ts +9 -0
  63. package/dist/modules/instance-ai/entities/instance-ai-message.entity.js +47 -0
  64. package/dist/modules/instance-ai/entities/instance-ai-message.entity.js.map +1 -0
  65. package/dist/modules/instance-ai/entities/instance-ai-observational-memory.entity.d.ts +33 -0
  66. package/dist/modules/instance-ai/entities/instance-ai-observational-memory.entity.js +145 -0
  67. package/dist/modules/instance-ai/entities/instance-ai-observational-memory.entity.js.map +1 -0
  68. package/dist/modules/instance-ai/entities/instance-ai-resource.entity.d.ts +6 -0
  69. package/dist/modules/instance-ai/entities/instance-ai-resource.entity.js +33 -0
  70. package/dist/modules/instance-ai/entities/instance-ai-resource.entity.js.map +1 -0
  71. package/dist/modules/instance-ai/entities/instance-ai-run-snapshot.entity.d.ts +8 -0
  72. package/dist/modules/instance-ai/entities/instance-ai-run-snapshot.entity.js +43 -0
  73. package/dist/modules/instance-ai/entities/instance-ai-run-snapshot.entity.js.map +1 -0
  74. package/dist/modules/instance-ai/entities/instance-ai-thread.entity.d.ts +7 -0
  75. package/dist/modules/instance-ai/entities/instance-ai-thread.entity.js +38 -0
  76. package/dist/modules/instance-ai/entities/instance-ai-thread.entity.js.map +1 -0
  77. package/dist/modules/instance-ai/entities/instance-ai-workflow-snapshot.entity.d.ts +8 -0
  78. package/dist/modules/instance-ai/entities/instance-ai-workflow-snapshot.entity.js +41 -0
  79. package/dist/modules/instance-ai/entities/instance-ai-workflow-snapshot.entity.js.map +1 -0
  80. package/dist/modules/instance-ai/event-bus/in-process-event-bus.d.ts +19 -0
  81. package/dist/modules/instance-ai/event-bus/in-process-event-bus.js +98 -0
  82. package/dist/modules/instance-ai/event-bus/in-process-event-bus.js.map +1 -0
  83. package/dist/modules/instance-ai/filesystem/index.d.ts +4 -0
  84. package/dist/modules/instance-ai/filesystem/index.js +10 -0
  85. package/dist/modules/instance-ai/filesystem/index.js.map +1 -0
  86. package/dist/modules/instance-ai/filesystem/local-fs-provider.d.ts +26 -0
  87. package/dist/modules/instance-ai/filesystem/local-fs-provider.js +321 -0
  88. package/dist/modules/instance-ai/filesystem/local-fs-provider.js.map +1 -0
  89. package/dist/modules/instance-ai/filesystem/local-gateway-registry.d.ts +29 -0
  90. package/dist/modules/instance-ai/filesystem/local-gateway-registry.js +137 -0
  91. package/dist/modules/instance-ai/filesystem/local-gateway-registry.js.map +1 -0
  92. package/dist/modules/instance-ai/filesystem/local-gateway.d.ts +35 -0
  93. package/dist/modules/instance-ai/filesystem/local-gateway.js +99 -0
  94. package/dist/modules/instance-ai/filesystem/local-gateway.js.map +1 -0
  95. package/dist/modules/instance-ai/instance-ai-memory.service.d.ts +36 -0
  96. package/dist/modules/instance-ai/instance-ai-memory.service.js +265 -0
  97. package/dist/modules/instance-ai/instance-ai-memory.service.js.map +1 -0
  98. package/dist/modules/instance-ai/instance-ai-settings.service.d.ts +55 -0
  99. package/dist/modules/instance-ai/instance-ai-settings.service.js +430 -0
  100. package/dist/modules/instance-ai/instance-ai-settings.service.js.map +1 -0
  101. package/dist/modules/instance-ai/instance-ai.adapter.service.d.ts +86 -0
  102. package/dist/modules/instance-ai/instance-ai.adapter.service.js +1731 -0
  103. package/dist/modules/instance-ai/instance-ai.adapter.service.js.map +1 -0
  104. package/dist/modules/instance-ai/instance-ai.controller.d.ts +102 -0
  105. package/dist/modules/instance-ai/instance-ai.controller.js +613 -0
  106. package/dist/modules/instance-ai/instance-ai.controller.js.map +1 -0
  107. package/dist/modules/instance-ai/instance-ai.module.d.ts +13 -0
  108. package/dist/modules/instance-ai/instance-ai.module.js +119 -0
  109. package/dist/modules/instance-ai/instance-ai.module.js.map +1 -0
  110. package/dist/modules/instance-ai/instance-ai.service.d.ts +132 -0
  111. package/dist/modules/instance-ai/instance-ai.service.js +1674 -0
  112. package/dist/modules/instance-ai/instance-ai.service.js.map +1 -0
  113. package/dist/modules/instance-ai/internal-messages.d.ts +2 -0
  114. package/dist/modules/instance-ai/internal-messages.js +11 -0
  115. package/dist/modules/instance-ai/internal-messages.js.map +1 -0
  116. package/dist/modules/instance-ai/message-parser.d.ts +12 -0
  117. package/dist/modules/instance-ai/message-parser.js +171 -0
  118. package/dist/modules/instance-ai/message-parser.js.map +1 -0
  119. package/dist/modules/instance-ai/node-definition-resolver.d.ts +19 -0
  120. package/dist/modules/instance-ai/node-definition-resolver.js +290 -0
  121. package/dist/modules/instance-ai/node-definition-resolver.js.map +1 -0
  122. package/dist/modules/instance-ai/repositories/index.d.ts +7 -0
  123. package/dist/modules/instance-ai/repositories/index.js +18 -0
  124. package/dist/modules/instance-ai/repositories/index.js.map +1 -0
  125. package/dist/modules/instance-ai/repositories/instance-ai-iteration-log.repository.d.ts +5 -0
  126. package/dist/modules/instance-ai/repositories/instance-ai-iteration-log.repository.js +26 -0
  127. package/dist/modules/instance-ai/repositories/instance-ai-iteration-log.repository.js.map +1 -0
  128. package/dist/modules/instance-ai/repositories/instance-ai-message.repository.d.ts +5 -0
  129. package/dist/modules/instance-ai/repositories/instance-ai-message.repository.js +26 -0
  130. package/dist/modules/instance-ai/repositories/instance-ai-message.repository.js.map +1 -0
  131. package/dist/modules/instance-ai/repositories/instance-ai-observational-memory.repository.d.ts +5 -0
  132. package/dist/modules/instance-ai/repositories/instance-ai-observational-memory.repository.js +26 -0
  133. package/dist/modules/instance-ai/repositories/instance-ai-observational-memory.repository.js.map +1 -0
  134. package/dist/modules/instance-ai/repositories/instance-ai-resource.repository.d.ts +5 -0
  135. package/dist/modules/instance-ai/repositories/instance-ai-resource.repository.js +26 -0
  136. package/dist/modules/instance-ai/repositories/instance-ai-resource.repository.js.map +1 -0
  137. package/dist/modules/instance-ai/repositories/instance-ai-run-snapshot.repository.d.ts +5 -0
  138. package/dist/modules/instance-ai/repositories/instance-ai-run-snapshot.repository.js +26 -0
  139. package/dist/modules/instance-ai/repositories/instance-ai-run-snapshot.repository.js.map +1 -0
  140. package/dist/modules/instance-ai/repositories/instance-ai-thread.repository.d.ts +5 -0
  141. package/dist/modules/instance-ai/repositories/instance-ai-thread.repository.js +26 -0
  142. package/dist/modules/instance-ai/repositories/instance-ai-thread.repository.js.map +1 -0
  143. package/dist/modules/instance-ai/repositories/instance-ai-workflow-snapshot.repository.d.ts +5 -0
  144. package/dist/modules/instance-ai/repositories/instance-ai-workflow-snapshot.repository.js +26 -0
  145. package/dist/modules/instance-ai/repositories/instance-ai-workflow-snapshot.repository.js.map +1 -0
  146. package/dist/modules/instance-ai/snapshot-pruning.service.d.ts +14 -0
  147. package/dist/modules/instance-ai/snapshot-pruning.service.js +77 -0
  148. package/dist/modules/instance-ai/snapshot-pruning.service.js.map +1 -0
  149. package/dist/modules/instance-ai/storage/db-iteration-log-storage.d.ts +9 -0
  150. package/dist/modules/instance-ai/storage/db-iteration-log-storage.js +45 -0
  151. package/dist/modules/instance-ai/storage/db-iteration-log-storage.js.map +1 -0
  152. package/dist/modules/instance-ai/storage/db-snapshot-storage.d.ts +10 -0
  153. package/dist/modules/instance-ai/storage/db-snapshot-storage.js +74 -0
  154. package/dist/modules/instance-ai/storage/db-snapshot-storage.js.map +1 -0
  155. package/dist/modules/instance-ai/storage/index.d.ts +5 -0
  156. package/dist/modules/instance-ai/storage/index.js +14 -0
  157. package/dist/modules/instance-ai/storage/index.js.map +1 -0
  158. package/dist/modules/instance-ai/storage/typeorm-composite-store.d.ts +9 -0
  159. package/dist/modules/instance-ai/storage/typeorm-composite-store.js +33 -0
  160. package/dist/modules/instance-ai/storage/typeorm-composite-store.js.map +1 -0
  161. package/dist/modules/instance-ai/storage/typeorm-memory-storage.d.ts +96 -0
  162. package/dist/modules/instance-ai/storage/typeorm-memory-storage.js +853 -0
  163. package/dist/modules/instance-ai/storage/typeorm-memory-storage.js.map +1 -0
  164. package/dist/modules/instance-ai/storage/typeorm-workflows-storage.d.ts +44 -0
  165. package/dist/modules/instance-ai/storage/typeorm-workflows-storage.js +156 -0
  166. package/dist/modules/instance-ai/storage/typeorm-workflows-storage.js.map +1 -0
  167. package/dist/modules/instance-ai/web-research/brave-search.d.ts +10 -0
  168. package/dist/modules/instance-ai/web-research/brave-search.js +43 -0
  169. package/dist/modules/instance-ai/web-research/brave-search.js.map +1 -0
  170. package/dist/modules/instance-ai/web-research/cache.d.ts +13 -0
  171. package/dist/modules/instance-ai/web-research/cache.js +43 -0
  172. package/dist/modules/instance-ai/web-research/cache.js.map +1 -0
  173. package/dist/modules/instance-ai/web-research/fetch-and-extract.d.ts +8 -0
  174. package/dist/modules/instance-ai/web-research/fetch-and-extract.js +231 -0
  175. package/dist/modules/instance-ai/web-research/fetch-and-extract.js.map +1 -0
  176. package/dist/modules/instance-ai/web-research/index.d.ts +7 -0
  177. package/dist/modules/instance-ai/web-research/index.js +16 -0
  178. package/dist/modules/instance-ai/web-research/index.js.map +1 -0
  179. package/dist/modules/instance-ai/web-research/searxng-search.d.ts +6 -0
  180. package/dist/modules/instance-ai/web-research/searxng-search.js +39 -0
  181. package/dist/modules/instance-ai/web-research/searxng-search.js.map +1 -0
  182. package/dist/modules/instance-ai/web-research/ssrf-guard.d.ts +1 -0
  183. package/dist/modules/instance-ai/web-research/ssrf-guard.js +85 -0
  184. package/dist/modules/instance-ai/web-research/ssrf-guard.js.map +1 -0
  185. package/dist/modules/instance-ai/web-research/summarize-content.d.ts +4 -0
  186. package/dist/modules/instance-ai/web-research/summarize-content.js +34 -0
  187. package/dist/modules/instance-ai/web-research/summarize-content.js.map +1 -0
  188. package/dist/modules/instance-registry/instance-registry.types.d.ts +1 -0
  189. package/dist/modules/instance-registry/instance-registry.types.js +2 -1
  190. package/dist/modules/instance-registry/instance-registry.types.js.map +1 -1
  191. package/dist/modules/instance-registry/storage/instance-storage.interface.d.ts +1 -0
  192. package/dist/modules/instance-registry/storage/lua-scripts.d.ts +4 -0
  193. package/dist/modules/instance-registry/storage/lua-scripts.js +39 -0
  194. package/dist/modules/instance-registry/storage/lua-scripts.js.map +1 -0
  195. package/dist/modules/instance-registry/storage/memory-storage.d.ts +1 -0
  196. package/dist/modules/instance-registry/storage/memory-storage.js +1 -0
  197. package/dist/modules/instance-registry/storage/memory-storage.js.map +1 -1
  198. package/dist/modules/instance-registry/storage/redis-instance-storage.d.ts +25 -0
  199. package/dist/modules/instance-registry/storage/redis-instance-storage.js +185 -0
  200. package/dist/modules/instance-registry/storage/redis-instance-storage.js.map +1 -0
  201. package/dist/modules/log-streaming.ee/log-streaming.controller.js.map +1 -1
  202. package/dist/modules/mcp/mcp.service.d.ts +3 -1
  203. package/dist/modules/mcp/mcp.service.js +22 -3
  204. package/dist/modules/mcp/mcp.service.js.map +1 -1
  205. package/dist/modules/mcp/mcp.types.d.ts +1 -1
  206. package/dist/modules/mcp/tools/data-table/add-data-table-column.tool.d.ts +13 -0
  207. package/dist/modules/mcp/tools/data-table/add-data-table-column.tool.js +69 -0
  208. package/dist/modules/mcp/tools/data-table/add-data-table-column.tool.js.map +1 -0
  209. package/dist/modules/mcp/tools/data-table/add-data-table-rows.tool.d.ts +12 -0
  210. package/dist/modules/mcp/tools/data-table/add-data-table-rows.tool.js +77 -0
  211. package/dist/modules/mcp/tools/data-table/add-data-table-rows.tool.js.map +1 -0
  212. package/dist/modules/mcp/tools/data-table/create-data-table.tool.d.ts +21 -0
  213. package/dist/modules/mcp/tools/data-table/create-data-table.tool.js +92 -0
  214. package/dist/modules/mcp/tools/data-table/create-data-table.tool.js.map +1 -0
  215. package/dist/modules/mcp/tools/data-table/delete-data-table-column.tool.d.ts +12 -0
  216. package/dist/modules/mcp/tools/data-table/delete-data-table-column.tool.js +60 -0
  217. package/dist/modules/mcp/tools/data-table/delete-data-table-column.tool.js.map +1 -0
  218. package/dist/modules/mcp/tools/data-table/index.d.ts +7 -0
  219. package/dist/modules/mcp/tools/data-table/index.js +18 -0
  220. package/dist/modules/mcp/tools/data-table/index.js.map +1 -0
  221. package/dist/modules/mcp/tools/data-table/rename-data-table-column.tool.d.ts +13 -0
  222. package/dist/modules/mcp/tools/data-table/rename-data-table-column.tool.js +70 -0
  223. package/dist/modules/mcp/tools/data-table/rename-data-table-column.tool.js.map +1 -0
  224. package/dist/modules/mcp/tools/data-table/rename-data-table.tool.d.ts +12 -0
  225. package/dist/modules/mcp/tools/data-table/rename-data-table.tool.js +60 -0
  226. package/dist/modules/mcp/tools/data-table/rename-data-table.tool.js.map +1 -0
  227. package/dist/modules/mcp/tools/data-table/search-data-tables.tool.d.ts +12 -0
  228. package/dist/modules/mcp/tools/data-table/search-data-tables.tool.js +93 -0
  229. package/dist/modules/mcp/tools/data-table/search-data-tables.tool.js.map +1 -0
  230. package/dist/modules/mcp/tools/execute-workflow.tool.d.ts +3 -4
  231. package/dist/modules/mcp/tools/execute-workflow.tool.js +10 -25
  232. package/dist/modules/mcp/tools/execute-workflow.tool.js.map +1 -1
  233. package/dist/modules/mcp/tools/get-execution.tool.js +4 -8
  234. package/dist/modules/mcp/tools/get-execution.tool.js.map +1 -1
  235. package/dist/modules/mcp/tools/schemas.d.ts +73 -2
  236. package/dist/modules/mcp/tools/schemas.js +41 -1
  237. package/dist/modules/mcp/tools/schemas.js.map +1 -1
  238. package/dist/modules/mcp/tools/search-folders.tool.js +2 -7
  239. package/dist/modules/mcp/tools/search-folders.tool.js.map +1 -1
  240. package/dist/modules/mcp/tools/search-projects.tool.js +2 -7
  241. package/dist/modules/mcp/tools/search-projects.tool.js.map +1 -1
  242. package/dist/modules/mcp/tools/search-workflows.tool.js +2 -7
  243. package/dist/modules/mcp/tools/search-workflows.tool.js.map +1 -1
  244. package/dist/modules/mcp/tools/workflow-builder/get-suggested-workflow-nodes.tool.js +1 -37
  245. package/dist/modules/mcp/tools/workflow-builder/get-suggested-workflow-nodes.tool.js.map +1 -1
  246. package/dist/modules/mcp/tools/workflow-builder/get-workflow-node-types.tool.js +1 -37
  247. package/dist/modules/mcp/tools/workflow-builder/get-workflow-node-types.tool.js.map +1 -1
  248. package/dist/modules/mcp/tools/workflow-builder/search-workflow-nodes.tool.js +1 -37
  249. package/dist/modules/mcp/tools/workflow-builder/search-workflow-nodes.tool.js.map +1 -1
  250. package/dist/modules/mcp/tools/workflow-builder/workflow-builder-tools.service.d.ts +17 -0
  251. package/dist/modules/mcp/tools/workflow-builder/workflow-builder-tools.service.js +48 -0
  252. package/dist/modules/mcp/tools/workflow-builder/workflow-builder-tools.service.js.map +1 -1
  253. package/dist/modules/otel/handlers/node-end.handler.d.ts +8 -0
  254. package/dist/modules/otel/handlers/node-end.handler.js +71 -0
  255. package/dist/modules/otel/handlers/node-end.handler.js.map +1 -0
  256. package/dist/modules/otel/handlers/node-start.handler.d.ts +7 -0
  257. package/dist/modules/otel/handlers/node-start.handler.js +37 -0
  258. package/dist/modules/otel/handlers/node-start.handler.js.map +1 -0
  259. package/dist/modules/otel/handlers/workflow-end.handler.d.ts +1 -0
  260. package/dist/modules/otel/handlers/workflow-end.handler.js +8 -0
  261. package/dist/modules/otel/handlers/workflow-end.handler.js.map +1 -1
  262. package/dist/modules/otel/n8n-instrumentation.d.ts +8 -2
  263. package/dist/modules/otel/n8n-instrumentation.js +32 -1
  264. package/dist/modules/otel/n8n-instrumentation.js.map +1 -1
  265. package/dist/modules/otel/otel.config.d.ts +1 -0
  266. package/dist/modules/otel/otel.config.js +5 -0
  267. package/dist/modules/otel/otel.config.js.map +1 -1
  268. package/dist/modules/otel/otel.constants.d.ts +7 -0
  269. package/dist/modules/otel/otel.constants.js +7 -0
  270. package/dist/modules/otel/otel.constants.js.map +1 -1
  271. package/dist/modules/otel/otel.service.d.ts +1 -1
  272. package/dist/modules/otel/otel.service.js +20 -23
  273. package/dist/modules/otel/otel.service.js.map +1 -1
  274. package/dist/modules/otel/span-registry.d.ts +1 -0
  275. package/dist/modules/otel/span-registry.js +11 -0
  276. package/dist/modules/otel/span-registry.js.map +1 -1
  277. package/dist/modules/provisioning.ee/provisioning.service.ee.d.ts +13 -2
  278. package/dist/modules/provisioning.ee/provisioning.service.ee.js +145 -2
  279. package/dist/modules/provisioning.ee/provisioning.service.ee.js.map +1 -1
  280. package/dist/modules/redaction/executions/execution-redaction.service.d.ts +3 -2
  281. package/dist/modules/redaction/executions/execution-redaction.service.js +5 -1
  282. package/dist/modules/redaction/executions/execution-redaction.service.js.map +1 -1
  283. package/dist/modules/redaction/redaction.module.js +0 -6
  284. package/dist/modules/redaction/redaction.module.js.map +1 -1
  285. package/dist/modules/sso-oidc/oidc.controller.ee.d.ts +4 -1
  286. package/dist/modules/sso-oidc/oidc.controller.ee.js +39 -3
  287. package/dist/modules/sso-oidc/oidc.controller.ee.js.map +1 -1
  288. package/dist/modules/sso-oidc/oidc.service.ee.d.ts +14 -2
  289. package/dist/modules/sso-oidc/oidc.service.ee.js +86 -8
  290. package/dist/modules/sso-oidc/oidc.service.ee.js.map +1 -1
  291. package/dist/modules/sso-oidc/views/oidc-test-result.d.ts +5 -0
  292. package/dist/modules/sso-oidc/views/oidc-test-result.js +58 -0
  293. package/dist/modules/sso-oidc/views/oidc-test-result.js.map +1 -0
  294. package/dist/modules/sso-saml/saml-helpers.d.ts +1 -0
  295. package/dist/modules/sso-saml/saml-helpers.js +2 -0
  296. package/dist/modules/sso-saml/saml-helpers.js.map +1 -1
  297. package/dist/modules/sso-saml/saml.service.ee.d.ts +4 -1
  298. package/dist/modules/sso-saml/saml.service.ee.js +13 -7
  299. package/dist/modules/sso-saml/saml.service.ee.js.map +1 -1
  300. package/dist/modules/token-exchange/controllers/embed-auth.controller.d.ts +15 -0
  301. package/dist/modules/token-exchange/controllers/embed-auth.controller.js +67 -0
  302. package/dist/modules/token-exchange/controllers/embed-auth.controller.js.map +1 -0
  303. package/dist/modules/token-exchange/database/entities/token-exchange-jti.entity.d.ts +5 -0
  304. package/dist/modules/token-exchange/database/entities/token-exchange-jti.entity.js +33 -0
  305. package/dist/modules/token-exchange/database/entities/token-exchange-jti.entity.js.map +1 -0
  306. package/dist/modules/token-exchange/database/repositories/token-exchange-jti.repository.d.ts +10 -0
  307. package/dist/modules/token-exchange/database/repositories/token-exchange-jti.repository.js +106 -0
  308. package/dist/modules/token-exchange/database/repositories/token-exchange-jti.repository.js.map +1 -0
  309. package/dist/modules/token-exchange/services/identity-resolution.service.d.ts +5 -0
  310. package/dist/modules/token-exchange/services/identity-resolution.service.js +21 -0
  311. package/dist/modules/token-exchange/services/identity-resolution.service.js.map +1 -0
  312. package/dist/modules/token-exchange/services/jti-cleanup.service.d.ts +18 -0
  313. package/dist/modules/token-exchange/services/jti-cleanup.service.js +90 -0
  314. package/dist/modules/token-exchange/services/jti-cleanup.service.js.map +1 -0
  315. package/dist/modules/token-exchange/services/jti-store.service.d.ts +6 -0
  316. package/dist/modules/token-exchange/services/jti-store.service.js +30 -0
  317. package/dist/modules/token-exchange/services/jti-store.service.js.map +1 -0
  318. package/dist/modules/token-exchange/services/token-exchange.service.d.ts +17 -0
  319. package/dist/modules/token-exchange/services/token-exchange.service.js +93 -0
  320. package/dist/modules/token-exchange/services/token-exchange.service.js.map +1 -0
  321. package/dist/modules/token-exchange/services/trusted-key.service.d.ts +13 -0
  322. package/dist/modules/token-exchange/services/trusted-key.service.js +123 -0
  323. package/dist/modules/token-exchange/services/trusted-key.service.js.map +1 -0
  324. package/dist/modules/token-exchange/token-exchange.config.d.ts +7 -0
  325. package/dist/modules/token-exchange/token-exchange.config.js +47 -0
  326. package/dist/modules/token-exchange/token-exchange.config.js.map +1 -0
  327. package/dist/modules/token-exchange/token-exchange.controller.d.ts +9 -0
  328. package/dist/modules/token-exchange/token-exchange.controller.js +103 -0
  329. package/dist/modules/token-exchange/token-exchange.controller.js.map +1 -0
  330. package/dist/modules/token-exchange/token-exchange.module.d.ts +5 -0
  331. package/dist/modules/token-exchange/token-exchange.module.js +74 -0
  332. package/dist/modules/token-exchange/token-exchange.module.js.map +1 -0
  333. package/dist/modules/token-exchange/token-exchange.schemas.d.ts +131 -0
  334. package/dist/modules/token-exchange/token-exchange.schemas.js +60 -0
  335. package/dist/modules/token-exchange/token-exchange.schemas.js.map +1 -0
  336. package/dist/modules/token-exchange/token-exchange.service.d.ts +9 -0
  337. package/dist/modules/token-exchange/token-exchange.service.js +66 -0
  338. package/dist/modules/token-exchange/token-exchange.service.js.map +1 -0
  339. package/dist/modules/token-exchange/token-exchange.types.d.ts +50 -0
  340. package/dist/modules/token-exchange/token-exchange.types.js +3 -0
  341. package/dist/modules/token-exchange/token-exchange.types.js.map +1 -0
  342. package/dist/public-api/index.js +5 -5
  343. package/dist/public-api/index.js.map +1 -1
  344. package/dist/public-api/types.d.ts +17 -0
  345. package/dist/public-api/v1/handlers/community-packages/community-packages.handler.d.ts +18 -0
  346. package/dist/public-api/v1/handlers/community-packages/community-packages.handler.js +71 -0
  347. package/dist/public-api/v1/handlers/community-packages/community-packages.handler.js.map +1 -0
  348. package/dist/public-api/v1/handlers/community-packages/community-packages.mapper.d.ts +27 -0
  349. package/dist/public-api/v1/handlers/community-packages/community-packages.mapper.js +35 -0
  350. package/dist/public-api/v1/handlers/community-packages/community-packages.mapper.js.map +1 -0
  351. package/dist/public-api/v1/handlers/executions/executions.handler.js +48 -4
  352. package/dist/public-api/v1/handlers/executions/executions.handler.js.map +1 -1
  353. package/dist/public-api/v1/openapi.yml +208 -2
  354. package/dist/public-api/v1/public-api-error-response.d.ts +2 -0
  355. package/dist/public-api/v1/public-api-error-response.js +11 -0
  356. package/dist/public-api/v1/public-api-error-response.js.map +1 -0
  357. package/dist/push/abstract.push.d.ts +1 -0
  358. package/dist/push/abstract.push.js +3 -0
  359. package/dist/push/abstract.push.js.map +1 -1
  360. package/dist/push/sse.push.js +5 -1
  361. package/dist/push/sse.push.js.map +1 -1
  362. package/dist/push/websocket.push.js +3 -1
  363. package/dist/push/websocket.push.js.map +1 -1
  364. package/dist/response-helper.js +6 -29
  365. package/dist/response-helper.js.map +1 -1
  366. package/dist/scaling/pubsub/subscriber.service.d.ts +2 -0
  367. package/dist/scaling/pubsub/subscriber.service.js +17 -8
  368. package/dist/scaling/pubsub/subscriber.service.js.map +1 -1
  369. package/dist/scaling/redis/redis.types.d.ts +1 -1
  370. package/dist/services/ai-workflow-builder.service.d.ts +2 -2
  371. package/dist/services/ai-workflow-builder.service.js +4 -4
  372. package/dist/services/ai-workflow-builder.service.js.map +1 -1
  373. package/dist/services/ai.service.d.ts +4 -0
  374. package/dist/services/ai.service.js +20 -18
  375. package/dist/services/ai.service.js.map +1 -1
  376. package/dist/services/auth-strategy.registry.d.ts +7 -0
  377. package/dist/services/auth-strategy.registry.js +32 -0
  378. package/dist/services/auth-strategy.registry.js.map +1 -0
  379. package/dist/services/auth-strategy.types.d.ts +4 -0
  380. package/dist/services/auth-strategy.types.js +3 -0
  381. package/dist/services/auth-strategy.types.js.map +1 -0
  382. package/dist/services/credentials-tester.service.js +2 -0
  383. package/dist/services/credentials-tester.service.js.map +1 -1
  384. package/dist/services/db-clock.service.d.ts +10 -0
  385. package/dist/services/db-clock.service.js +48 -0
  386. package/dist/services/db-clock.service.js.map +1 -0
  387. package/dist/services/frontend.service.js +2 -0
  388. package/dist/services/frontend.service.js.map +1 -1
  389. package/dist/wait-tracker.d.ts +6 -2
  390. package/dist/wait-tracker.js +94 -63
  391. package/dist/wait-tracker.js.map +1 -1
  392. package/dist/webhooks/live-webhooks.js +24 -18
  393. package/dist/webhooks/live-webhooks.js.map +1 -1
  394. package/dist/webhooks/test-webhooks.js +96 -78
  395. package/dist/webhooks/test-webhooks.js.map +1 -1
  396. package/dist/webhooks/waiting-webhooks.js +27 -21
  397. package/dist/webhooks/waiting-webhooks.js.map +1 -1
  398. package/dist/webhooks/webhook-helpers.js +21 -6
  399. package/dist/webhooks/webhook-helpers.js.map +1 -1
  400. package/dist/webhooks/webhook-last-node-response-extractor.d.ts +5 -2
  401. package/dist/webhooks/webhook-last-node-response-extractor.js +5 -8
  402. package/dist/webhooks/webhook-last-node-response-extractor.js.map +1 -1
  403. package/dist/workflows/workflow-creation.service.js +4 -0
  404. package/dist/workflows/workflow-creation.service.js.map +1 -1
  405. package/dist/workflows/workflow-execution.service.js +1 -1
  406. package/dist/workflows/workflow-execution.service.js.map +1 -1
  407. package/dist/workflows/workflow-history/workflow-history.service.js +1 -0
  408. package/dist/workflows/workflow-history/workflow-history.service.js.map +1 -1
  409. package/dist/workflows/workflow-validation.service.js +3 -3
  410. package/dist/workflows/workflow-validation.service.js.map +1 -1
  411. package/dist/workflows/workflow.service.js +12 -1
  412. package/dist/workflows/workflow.service.js.map +1 -1
  413. package/dist/workflows/workflows.controller.d.ts +2 -2
  414. package/package.json +28 -25
@@ -0,0 +1,853 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var TypeORMMemoryStorage_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.TypeORMMemoryStorage = void 0;
14
+ const node_crypto_1 = require("node:crypto");
15
+ const storage_1 = require("@mastra/core/storage");
16
+ const di_1 = require("@n8n/di");
17
+ const instance_ai_1 = require("@n8n/instance-ai");
18
+ const typeorm_1 = require("@n8n/typeorm");
19
+ const utils_1 = require("@n8n/utils");
20
+ const n8n_workflow_1 = require("n8n-workflow");
21
+ const instance_ai_message_repository_1 = require("../repositories/instance-ai-message.repository");
22
+ const instance_ai_observational_memory_repository_1 = require("../repositories/instance-ai-observational-memory.repository");
23
+ const instance_ai_resource_repository_1 = require("../repositories/instance-ai-resource.repository");
24
+ const instance_ai_thread_repository_1 = require("../repositories/instance-ai-thread.repository");
25
+ const PATCH_ONLY_METADATA_KEYS = ['instanceAiPlannedTasks'];
26
+ function countLines(value) {
27
+ return value === '' ? 0 : value.split(/\r?\n/u).length;
28
+ }
29
+ function buildResourceTraceMetadata(resourceId) {
30
+ const separatorIndex = resourceId.indexOf(':');
31
+ return {
32
+ resource_id: resourceId,
33
+ memory_scope: separatorIndex === -1 ? 'user' : 'user-role',
34
+ ...(separatorIndex !== -1 && separatorIndex < resourceId.length - 1
35
+ ? { memory_role: resourceId.slice(separatorIndex + 1) }
36
+ : {}),
37
+ };
38
+ }
39
+ function summarizeLoadedResource(resource) {
40
+ const workingMemory = resource?.workingMemory;
41
+ return {
42
+ found: resource !== null,
43
+ has_working_memory: typeof workingMemory === 'string' && workingMemory.length > 0,
44
+ working_memory_chars: typeof workingMemory === 'string' ? workingMemory.length : 0,
45
+ working_memory_lines: typeof workingMemory === 'string' ? countLines(workingMemory) : 0,
46
+ metadata_keys: resource?.metadata ? Object.keys(resource.metadata).length : 0,
47
+ };
48
+ }
49
+ let TypeORMMemoryStorage = TypeORMMemoryStorage_1 = class TypeORMMemoryStorage extends storage_1.MemoryStorage {
50
+ constructor(threadRepo, messageRepo, resourceRepo, omRepo) {
51
+ super();
52
+ this.threadRepo = threadRepo;
53
+ this.messageRepo = messageRepo;
54
+ this.resourceRepo = resourceRepo;
55
+ this.omRepo = omRepo;
56
+ this.supportsObservationalMemory = true;
57
+ }
58
+ async dangerouslyClearAll() {
59
+ await this.omRepo.clear();
60
+ await this.messageRepo.clear();
61
+ await this.threadRepo.clear();
62
+ await this.resourceRepo.clear();
63
+ }
64
+ async getThreadById({ threadId }) {
65
+ const entity = await this.threadRepo.findOneBy({ id: threadId });
66
+ if (!entity)
67
+ return null;
68
+ return this.toStorageThread(entity);
69
+ }
70
+ async listThreads(args) {
71
+ const page = args.page ?? 0;
72
+ const perPageInput = args.perPage;
73
+ const perPage = perPageInput === false ? Number.MAX_SAFE_INTEGER : (perPageInput ?? 100);
74
+ const { field, direction } = this.parseOrderBy(args.orderBy);
75
+ const where = {};
76
+ if (args.filter?.resourceId)
77
+ where.resourceId = args.filter.resourceId;
78
+ const metadataFilter = args.filter?.metadata;
79
+ const hasMetadataFilter = metadataFilter && Object.keys(metadataFilter).length > 0;
80
+ if (hasMetadataFilter) {
81
+ this.validateMetadataKeys(metadataFilter);
82
+ const allEntities = await this.threadRepo.find({
83
+ where,
84
+ order: { [field]: direction },
85
+ });
86
+ const allThreads = allEntities
87
+ .map((e) => ({
88
+ id: e.id,
89
+ title: e.title,
90
+ resourceId: e.resourceId,
91
+ metadata: e.metadata ?? undefined,
92
+ createdAt: e.createdAt,
93
+ updatedAt: e.updatedAt,
94
+ }))
95
+ .filter((t) => {
96
+ if (!t.metadata)
97
+ return false;
98
+ return Object.entries(args.filter.metadata).every(([k, v]) => t.metadata[k] === v);
99
+ });
100
+ const total = allThreads.length;
101
+ const offset = page * perPage;
102
+ const paged = allThreads.slice(offset, offset + perPage);
103
+ return {
104
+ threads: paged,
105
+ total,
106
+ page,
107
+ perPage: perPageInput ?? 100,
108
+ hasMore: offset + perPage < total,
109
+ };
110
+ }
111
+ const [entities, total] = await this.threadRepo.findAndCount({
112
+ where,
113
+ order: { [field]: direction },
114
+ skip: page * perPage,
115
+ take: perPage,
116
+ });
117
+ const threads = entities.map((e) => ({
118
+ id: e.id,
119
+ title: e.title,
120
+ resourceId: e.resourceId,
121
+ metadata: e.metadata ?? undefined,
122
+ createdAt: e.createdAt,
123
+ updatedAt: e.updatedAt,
124
+ }));
125
+ return {
126
+ threads,
127
+ total,
128
+ page,
129
+ perPage: perPageInput ?? 100,
130
+ hasMore: (page + 1) * perPage < total,
131
+ };
132
+ }
133
+ async saveThread({ thread, }) {
134
+ return await this.serializeThreadMutation(thread.id, async () => {
135
+ const existing = await this.threadRepo.findOneBy({ id: thread.id });
136
+ if (existing) {
137
+ const safeIncoming = { ...(thread.metadata ?? {}) };
138
+ for (const key of PATCH_ONLY_METADATA_KEYS) {
139
+ delete safeIncoming[key];
140
+ }
141
+ existing.title = thread.title ?? existing.title;
142
+ existing.resourceId = thread.resourceId ?? existing.resourceId;
143
+ existing.metadata = {
144
+ ...(existing.metadata ?? {}),
145
+ ...safeIncoming,
146
+ };
147
+ const saved = await this.threadRepo.save(existing);
148
+ return this.toStorageThread(saved);
149
+ }
150
+ const entity = this.threadRepo.create({
151
+ id: thread.id,
152
+ resourceId: thread.resourceId,
153
+ title: thread.title ?? '',
154
+ metadata: thread.metadata ?? null,
155
+ });
156
+ const saved = await this.threadRepo.save(entity);
157
+ return this.toStorageThread(saved);
158
+ });
159
+ }
160
+ async updateThread({ id, title, metadata, }) {
161
+ return await this.serializeThreadMutation(id, async () => {
162
+ const entity = await this.threadRepo.findOneByOrFail({ id });
163
+ const safeIncoming = { ...metadata };
164
+ for (const key of PATCH_ONLY_METADATA_KEYS) {
165
+ delete safeIncoming[key];
166
+ }
167
+ entity.title = title;
168
+ entity.metadata = {
169
+ ...(entity.metadata ?? {}),
170
+ ...safeIncoming,
171
+ };
172
+ const updated = await this.threadRepo.save(entity);
173
+ return this.toStorageThread(updated);
174
+ });
175
+ }
176
+ async patchThread({ threadId, update, }) {
177
+ return await this.serializeThreadMutation(threadId, async () => {
178
+ const entity = await this.threadRepo.findOneBy({ id: threadId });
179
+ if (!entity)
180
+ return null;
181
+ const current = this.toStorageThread(entity);
182
+ const patch = update({
183
+ ...current,
184
+ metadata: { ...(current.metadata ?? {}) },
185
+ });
186
+ if (!patch)
187
+ return current;
188
+ if (patch.title !== undefined) {
189
+ entity.title = patch.title;
190
+ }
191
+ if (patch.metadata !== undefined) {
192
+ entity.metadata = patch.metadata;
193
+ }
194
+ const updated = await this.threadRepo.save(entity);
195
+ return this.toStorageThread(updated);
196
+ });
197
+ }
198
+ async deleteThread({ threadId }) {
199
+ await this.threadRepo.delete(threadId);
200
+ }
201
+ toStorageThread(entity) {
202
+ return {
203
+ id: entity.id,
204
+ title: entity.title,
205
+ resourceId: entity.resourceId,
206
+ metadata: entity.metadata ?? undefined,
207
+ createdAt: entity.createdAt,
208
+ updatedAt: entity.updatedAt,
209
+ };
210
+ }
211
+ async serializeThreadMutation(threadId, mutation) {
212
+ const queues = TypeORMMemoryStorage_1.threadMutationQueues;
213
+ const previous = queues.get(threadId) ?? Promise.resolve();
214
+ const previousSettled = previous.catch(() => { });
215
+ let releaseCurrent;
216
+ const current = new Promise((resolve) => {
217
+ releaseCurrent = resolve;
218
+ });
219
+ const queued = previousSettled.then(async () => await current);
220
+ queues.set(threadId, queued);
221
+ await previousSettled;
222
+ try {
223
+ return await mutation();
224
+ }
225
+ finally {
226
+ releaseCurrent();
227
+ if (queues.get(threadId) === queued) {
228
+ queues.delete(threadId);
229
+ }
230
+ }
231
+ }
232
+ async listMessages(args) {
233
+ if (args.include?.length) {
234
+ const included = await this.getIncludedMessages(args);
235
+ return {
236
+ messages: included,
237
+ total: included.length,
238
+ page: 0,
239
+ perPage: false,
240
+ hasMore: false,
241
+ };
242
+ }
243
+ const threadIds = Array.isArray(args.threadId) ? args.threadId : [args.threadId];
244
+ const page = args.page ?? 0;
245
+ const perPageInput = args.perPage;
246
+ const perPage = perPageInput === false ? Number.MAX_SAFE_INTEGER : (perPageInput ?? 40);
247
+ const qb = this.messageRepo
248
+ .createQueryBuilder('m')
249
+ .where('m.threadId IN (:...threadIds)', { threadIds });
250
+ if (args.resourceId) {
251
+ qb.andWhere('m.resourceId = :resourceId', {
252
+ resourceId: args.resourceId,
253
+ });
254
+ }
255
+ if (args.filter?.dateRange?.start) {
256
+ const op = args.filter.dateRange.startExclusive ? '>' : '>=';
257
+ qb.andWhere(`m.createdAt ${op} :start`, {
258
+ start: args.filter.dateRange.start,
259
+ });
260
+ }
261
+ if (args.filter?.dateRange?.end) {
262
+ const op = args.filter.dateRange.endExclusive ? '<' : '<=';
263
+ qb.andWhere(`m.createdAt ${op} :end`, {
264
+ end: args.filter.dateRange.end,
265
+ });
266
+ }
267
+ const { field = 'createdAt', direction = 'ASC' } = args.orderBy ?? {};
268
+ qb.orderBy(`m.${field}`, direction);
269
+ const total = await qb.getCount();
270
+ qb.skip(page * perPage).take(perPage);
271
+ const entities = await qb.getMany();
272
+ const messages = entities.map((e) => this.entityToMessage(e));
273
+ return {
274
+ messages,
275
+ total,
276
+ page,
277
+ perPage: perPageInput ?? 40,
278
+ hasMore: (page + 1) * perPage < total,
279
+ };
280
+ }
281
+ async getIncludedMessages(args) {
282
+ const seen = new Set();
283
+ const result = [];
284
+ const threadIds = Array.isArray(args.threadId) ? args.threadId : [args.threadId];
285
+ for (const inc of args.include ?? []) {
286
+ const anchorThreadIds = inc.threadId ? [inc.threadId] : threadIds;
287
+ const anchor = await this.messageRepo.findOneBy({ id: inc.id });
288
+ if (!anchor)
289
+ continue;
290
+ const collected = [];
291
+ if (inc.withPreviousMessages && inc.withPreviousMessages > 0) {
292
+ const before = await this.messageRepo
293
+ .createQueryBuilder('m')
294
+ .where('m.threadId IN (:...threadIds)', { threadIds: anchorThreadIds })
295
+ .andWhere('m.createdAt < :anchorTime', { anchorTime: anchor.createdAt })
296
+ .orderBy('m.createdAt', 'DESC')
297
+ .take(inc.withPreviousMessages)
298
+ .getMany();
299
+ collected.push(...before.reverse().map((e) => this.entityToMessage(e)));
300
+ }
301
+ collected.push(this.entityToMessage(anchor));
302
+ if (inc.withNextMessages && inc.withNextMessages > 0) {
303
+ const after = await this.messageRepo
304
+ .createQueryBuilder('m')
305
+ .where('m.threadId IN (:...threadIds)', { threadIds: anchorThreadIds })
306
+ .andWhere('m.createdAt > :anchorTime', { anchorTime: anchor.createdAt })
307
+ .orderBy('m.createdAt', 'ASC')
308
+ .take(inc.withNextMessages)
309
+ .getMany();
310
+ collected.push(...after.map((e) => this.entityToMessage(e)));
311
+ }
312
+ for (const msg of collected) {
313
+ if (!seen.has(msg.id)) {
314
+ seen.add(msg.id);
315
+ result.push(msg);
316
+ }
317
+ }
318
+ }
319
+ result.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
320
+ return result;
321
+ }
322
+ async listMessagesByResourceId(args) {
323
+ const page = args.page ?? 0;
324
+ const perPageInput = args.perPage;
325
+ const perPage = perPageInput === false ? Number.MAX_SAFE_INTEGER : (perPageInput ?? 40);
326
+ const qb = this.messageRepo
327
+ .createQueryBuilder('m')
328
+ .where('m.resourceId = :resourceId', { resourceId: args.resourceId });
329
+ if (args.filter?.dateRange?.start) {
330
+ const op = args.filter.dateRange.startExclusive ? '>' : '>=';
331
+ qb.andWhere(`m.createdAt ${op} :start`, {
332
+ start: args.filter.dateRange.start,
333
+ });
334
+ }
335
+ if (args.filter?.dateRange?.end) {
336
+ const op = args.filter.dateRange.endExclusive ? '<' : '<=';
337
+ qb.andWhere(`m.createdAt ${op} :end`, {
338
+ end: args.filter.dateRange.end,
339
+ });
340
+ }
341
+ const { field = 'createdAt', direction = 'ASC' } = args.orderBy ?? {};
342
+ qb.orderBy(`m.${field}`, direction);
343
+ const total = await qb.getCount();
344
+ qb.skip(page * perPage).take(perPage);
345
+ const entities = await qb.getMany();
346
+ return {
347
+ messages: entities.map((e) => this.entityToMessage(e)),
348
+ total,
349
+ page,
350
+ perPage: perPageInput ?? 40,
351
+ hasMore: (page + 1) * perPage < total,
352
+ };
353
+ }
354
+ async listMessagesById({ messageIds, }) {
355
+ if (messageIds.length === 0)
356
+ return { messages: [] };
357
+ const entities = await this.messageRepo.findBy({ id: (0, typeorm_1.In)(messageIds) });
358
+ return { messages: entities.map((e) => this.entityToMessage(e)) };
359
+ }
360
+ async saveMessages({ messages, }) {
361
+ const entities = messages.map((m) => {
362
+ if (!m.threadId) {
363
+ throw new Error(`Message ${m.id} is missing required threadId`);
364
+ }
365
+ const entity = this.messageRepo.create({
366
+ id: m.id,
367
+ threadId: m.threadId,
368
+ content: JSON.stringify(m.content),
369
+ role: m.role,
370
+ type: m.type ?? null,
371
+ resourceId: m.resourceId ?? null,
372
+ });
373
+ if (m.createdAt) {
374
+ entity.createdAt = m.createdAt;
375
+ }
376
+ return entity;
377
+ });
378
+ const saved = await this.messageRepo.save(entities);
379
+ return { messages: saved.map((e) => this.entityToMessage(e)) };
380
+ }
381
+ async updateMessages({ messages, }) {
382
+ const result = [];
383
+ for (const msg of messages) {
384
+ const existing = await this.messageRepo.findOneBy({ id: msg.id });
385
+ if (!existing)
386
+ continue;
387
+ const updates = {};
388
+ if (msg.role)
389
+ updates.role = msg.role;
390
+ if (msg.type !== undefined)
391
+ updates.type = msg.type;
392
+ if (msg.content) {
393
+ const existingContent = (0, n8n_workflow_1.jsonParse)(existing.content);
394
+ if (msg.content.metadata !== undefined)
395
+ existingContent.metadata = msg.content.metadata;
396
+ if (msg.content.content !== undefined)
397
+ existingContent.content = msg.content.content;
398
+ updates.content = JSON.stringify(existingContent);
399
+ }
400
+ if (Object.keys(updates).length > 0) {
401
+ await this.messageRepo.update(msg.id, updates);
402
+ }
403
+ const updated = await this.messageRepo.findOneByOrFail({ id: msg.id });
404
+ result.push(this.entityToMessage(updated));
405
+ }
406
+ return result;
407
+ }
408
+ async deleteMessages(messageIds) {
409
+ if (messageIds.length === 0)
410
+ return;
411
+ await this.messageRepo.delete(messageIds);
412
+ }
413
+ async getResourceById({ resourceId, }) {
414
+ return await (0, instance_ai_1.withCurrentTraceSpan)({
415
+ name: 'memory_load',
416
+ tags: ['memory', 'internal'],
417
+ metadata: buildResourceTraceMetadata(resourceId),
418
+ inputs: { resource_id: resourceId },
419
+ processOutputs: summarizeLoadedResource,
420
+ }, async () => {
421
+ const entity = await this.resourceRepo.findOneBy({ id: resourceId });
422
+ if (!entity)
423
+ return null;
424
+ return {
425
+ id: entity.id,
426
+ workingMemory: entity.workingMemory ?? undefined,
427
+ metadata: entity.metadata ?? undefined,
428
+ createdAt: entity.createdAt,
429
+ updatedAt: entity.updatedAt,
430
+ };
431
+ });
432
+ }
433
+ async saveResource({ resource, }) {
434
+ const entity = this.resourceRepo.create({
435
+ id: resource.id,
436
+ workingMemory: resource.workingMemory ?? null,
437
+ metadata: resource.metadata ?? null,
438
+ });
439
+ const saved = await this.resourceRepo.save(entity);
440
+ return {
441
+ id: saved.id,
442
+ workingMemory: saved.workingMemory ?? undefined,
443
+ metadata: saved.metadata ?? undefined,
444
+ createdAt: saved.createdAt,
445
+ updatedAt: saved.updatedAt,
446
+ };
447
+ }
448
+ async updateResource({ resourceId, workingMemory, metadata, }) {
449
+ let existing = await this.resourceRepo.findOneBy({ id: resourceId });
450
+ if (!existing) {
451
+ existing = await this.resourceRepo.save(this.resourceRepo.create({
452
+ id: resourceId,
453
+ workingMemory: workingMemory ?? null,
454
+ metadata: metadata ?? null,
455
+ }));
456
+ }
457
+ else {
458
+ if (workingMemory !== undefined)
459
+ existing.workingMemory = workingMemory;
460
+ if (metadata !== undefined)
461
+ existing.metadata = metadata;
462
+ existing = await this.resourceRepo.save(existing);
463
+ }
464
+ return {
465
+ id: existing.id,
466
+ workingMemory: existing.workingMemory ?? undefined,
467
+ metadata: existing.metadata ?? undefined,
468
+ createdAt: existing.createdAt,
469
+ updatedAt: existing.updatedAt,
470
+ };
471
+ }
472
+ async cloneThread(args) {
473
+ const source = await this.getThreadById({
474
+ threadId: args.sourceThreadId,
475
+ });
476
+ if (!source)
477
+ throw new Error(`Source thread ${args.sourceThreadId} not found`);
478
+ const newThreadId = args.newThreadId ?? (0, node_crypto_1.randomUUID)();
479
+ const cloneMetadata = {
480
+ ...(source.metadata ?? {}),
481
+ ...(args.metadata ?? {}),
482
+ mastra: {
483
+ ...(source.metadata?.mastra ?? {}),
484
+ clone: {
485
+ sourceThreadId: args.sourceThreadId,
486
+ clonedAt: new Date(),
487
+ },
488
+ },
489
+ };
490
+ const newThread = await this.saveThread({
491
+ thread: {
492
+ id: newThreadId,
493
+ resourceId: args.resourceId ?? source.resourceId,
494
+ title: args.title ?? source.title,
495
+ metadata: cloneMetadata,
496
+ createdAt: new Date(),
497
+ updatedAt: new Date(),
498
+ },
499
+ });
500
+ const { messages: sourceMessages } = await this.listMessages({
501
+ threadId: args.sourceThreadId,
502
+ perPage: false,
503
+ orderBy: { field: 'createdAt', direction: 'ASC' },
504
+ });
505
+ let messagesToClone = sourceMessages;
506
+ if (args.options?.messageLimit) {
507
+ messagesToClone = messagesToClone.slice(-args.options.messageLimit);
508
+ }
509
+ const messageIdMap = {};
510
+ const clonedMessages = messagesToClone.map((m) => {
511
+ const newId = (0, utils_1.generateNanoId)();
512
+ messageIdMap[m.id] = newId;
513
+ return { ...m, id: newId, threadId: newThreadId };
514
+ });
515
+ if (clonedMessages.length > 0) {
516
+ await this.saveMessages({ messages: clonedMessages });
517
+ }
518
+ return { thread: newThread, clonedMessages, messageIdMap };
519
+ }
520
+ omLookupKey(scope, threadId, resourceId) {
521
+ return `${scope}:${threadId ?? 'null'}:${resourceId}`;
522
+ }
523
+ entityToOMRecord(entity) {
524
+ return {
525
+ id: entity.id,
526
+ scope: entity.scope,
527
+ threadId: entity.threadId,
528
+ resourceId: entity.resourceId,
529
+ createdAt: entity.createdAt,
530
+ updatedAt: entity.updatedAt,
531
+ lastObservedAt: entity.lastObservedAt ?? undefined,
532
+ originType: entity.originType,
533
+ generationCount: entity.generationCount,
534
+ activeObservations: entity.activeObservations,
535
+ bufferedObservationChunks: (entity.bufferedObservationChunks ??
536
+ undefined),
537
+ bufferedObservations: entity.bufferedObservations ?? undefined,
538
+ bufferedObservationTokens: entity.bufferedObservationTokens ?? undefined,
539
+ bufferedMessageIds: entity.bufferedMessageIds ?? undefined,
540
+ bufferedReflection: entity.bufferedReflection ?? undefined,
541
+ bufferedReflectionTokens: entity.bufferedReflectionTokens ?? undefined,
542
+ bufferedReflectionInputTokens: entity.bufferedReflectionInputTokens ?? undefined,
543
+ reflectedObservationLineCount: entity.reflectedObservationLineCount ?? undefined,
544
+ observedMessageIds: entity.observedMessageIds ?? undefined,
545
+ observedTimezone: entity.observedTimezone ?? undefined,
546
+ totalTokensObserved: entity.totalTokensObserved,
547
+ observationTokenCount: entity.observationTokenCount,
548
+ pendingMessageTokens: entity.pendingMessageTokens,
549
+ isReflecting: entity.isReflecting,
550
+ isObserving: entity.isObserving,
551
+ isBufferingObservation: entity.isBufferingObservation,
552
+ isBufferingReflection: entity.isBufferingReflection,
553
+ lastBufferedAtTokens: entity.lastBufferedAtTokens,
554
+ lastBufferedAtTime: entity.lastBufferedAtTime,
555
+ config: typeof entity.config === 'string' ? (0, n8n_workflow_1.jsonParse)(entity.config) : entity.config,
556
+ metadata: entity.metadata ?? undefined,
557
+ };
558
+ }
559
+ async getObservationalMemory(threadId, resourceId) {
560
+ const lookupKey = this.omLookupKey(threadId ? 'thread' : 'resource', threadId, resourceId);
561
+ const entity = await this.omRepo.findOne({
562
+ where: { lookupKey },
563
+ order: { generationCount: 'DESC' },
564
+ });
565
+ if (!entity)
566
+ return null;
567
+ return this.entityToOMRecord(entity);
568
+ }
569
+ async getObservationalMemoryHistory(threadId, resourceId, limit = 10) {
570
+ const scope = threadId ? 'thread' : 'resource';
571
+ const entities = await this.omRepo.find({
572
+ where: { scope, threadId: threadId ?? undefined, resourceId },
573
+ order: { generationCount: 'DESC' },
574
+ take: limit,
575
+ });
576
+ return entities.map((e) => this.entityToOMRecord(e));
577
+ }
578
+ async initializeObservationalMemory(input) {
579
+ const id = (0, utils_1.generateNanoId)();
580
+ const lookupKey = this.omLookupKey(input.scope, input.threadId, input.resourceId);
581
+ const entity = this.omRepo.create({
582
+ id,
583
+ lookupKey,
584
+ scope: input.scope,
585
+ threadId: input.threadId,
586
+ resourceId: input.resourceId,
587
+ originType: 'initial',
588
+ config: JSON.stringify(input.config),
589
+ observedTimezone: input.observedTimezone ?? null,
590
+ });
591
+ const saved = await this.omRepo.save(entity);
592
+ return this.entityToOMRecord(saved);
593
+ }
594
+ async insertObservationalMemoryRecord(record) {
595
+ const lookupKey = this.omLookupKey(record.scope, record.threadId, record.resourceId);
596
+ const entity = this.omRepo.create({
597
+ id: record.id,
598
+ lookupKey,
599
+ scope: record.scope,
600
+ threadId: record.threadId,
601
+ resourceId: record.resourceId,
602
+ activeObservations: record.activeObservations,
603
+ originType: record.originType,
604
+ config: JSON.stringify(record.config),
605
+ generationCount: record.generationCount,
606
+ lastObservedAt: record.lastObservedAt ?? null,
607
+ pendingMessageTokens: record.pendingMessageTokens,
608
+ totalTokensObserved: record.totalTokensObserved,
609
+ observationTokenCount: record.observationTokenCount,
610
+ isObserving: record.isObserving,
611
+ isReflecting: record.isReflecting,
612
+ observedMessageIds: record.observedMessageIds ?? null,
613
+ observedTimezone: record.observedTimezone ?? null,
614
+ bufferedObservations: record.bufferedObservations ?? null,
615
+ bufferedObservationTokens: record.bufferedObservationTokens ?? null,
616
+ bufferedMessageIds: record.bufferedMessageIds ?? null,
617
+ bufferedReflection: record.bufferedReflection ?? null,
618
+ bufferedReflectionTokens: record.bufferedReflectionTokens ?? null,
619
+ bufferedReflectionInputTokens: record.bufferedReflectionInputTokens ?? null,
620
+ reflectedObservationLineCount: record.reflectedObservationLineCount ?? null,
621
+ bufferedObservationChunks: (record.bufferedObservationChunks ?? null),
622
+ isBufferingObservation: record.isBufferingObservation,
623
+ isBufferingReflection: record.isBufferingReflection,
624
+ lastBufferedAtTokens: record.lastBufferedAtTokens,
625
+ lastBufferedAtTime: record.lastBufferedAtTime ?? null,
626
+ metadata: record.metadata ?? null,
627
+ });
628
+ await this.omRepo.save(entity);
629
+ }
630
+ async updateActiveObservations(input) {
631
+ const entity = await this.omRepo.findOneByOrFail({ id: input.id });
632
+ const existingIds = entity.observedMessageIds ?? [];
633
+ const mergedIds = [...new Set([...existingIds, ...(input.observedMessageIds ?? [])])];
634
+ await this.omRepo.update(input.id, {
635
+ activeObservations: input.observations,
636
+ observationTokenCount: input.tokenCount,
637
+ lastObservedAt: input.lastObservedAt,
638
+ observedMessageIds: mergedIds,
639
+ observedTimezone: input.observedTimezone ?? entity.observedTimezone,
640
+ totalTokensObserved: entity.totalTokensObserved + input.tokenCount,
641
+ });
642
+ }
643
+ async updateBufferedObservations(input) {
644
+ const entity = await this.omRepo.findOneByOrFail({ id: input.id });
645
+ const chunks = entity.bufferedObservationChunks ?? [];
646
+ chunks.push(input.chunk);
647
+ const updates = {
648
+ bufferedObservationChunks: chunks,
649
+ };
650
+ if (input.lastBufferedAtTime) {
651
+ updates.lastBufferedAtTime = input.lastBufferedAtTime;
652
+ }
653
+ await this.omRepo.update(input.id, updates);
654
+ }
655
+ async swapBufferedToActive(input) {
656
+ const entity = await this.omRepo.findOneByOrFail({ id: input.id });
657
+ const record = this.entityToOMRecord(entity);
658
+ const chunks = record.bufferedObservationChunks ?? [];
659
+ if (chunks.length === 0) {
660
+ return {
661
+ chunksActivated: 0,
662
+ messageTokensActivated: 0,
663
+ observationTokensActivated: 0,
664
+ messagesActivated: 0,
665
+ activatedCycleIds: [],
666
+ activatedMessageIds: [],
667
+ };
668
+ }
669
+ const retentionFloor = input.messageTokensThreshold * (1 - input.activationRatio);
670
+ const tokensToRemove = input.currentPendingTokens - retentionFloor;
671
+ let removedTokens = 0;
672
+ let activatedCount = 0;
673
+ const activated = [];
674
+ const remaining = [];
675
+ for (const chunk of chunks) {
676
+ if (removedTokens < tokensToRemove || (input.forceMaxActivation && remaining.length === 0)) {
677
+ activated.push(chunk);
678
+ removedTokens += chunk.messageTokens ?? 0;
679
+ activatedCount++;
680
+ }
681
+ else {
682
+ remaining.push(chunk);
683
+ }
684
+ }
685
+ let totalMessageTokens = 0;
686
+ let totalObsTokens = 0;
687
+ let totalMessages = 0;
688
+ const allMsgIds = [];
689
+ const cycleIds = [];
690
+ const observationParts = [];
691
+ for (const chunk of activated) {
692
+ totalMessageTokens += chunk.messageTokens ?? 0;
693
+ totalObsTokens += chunk.tokenCount ?? 0;
694
+ totalMessages += chunk.messageIds?.length ?? 0;
695
+ allMsgIds.push(...(chunk.messageIds ?? []));
696
+ if (chunk.cycleId)
697
+ cycleIds.push(chunk.cycleId);
698
+ if (chunk.observations)
699
+ observationParts.push(chunk.observations);
700
+ }
701
+ const newActive = record.activeObservations
702
+ ? record.activeObservations + '\n' + observationParts.join('\n')
703
+ : observationParts.join('\n');
704
+ const lastActivatedChunk = activated[activated.length - 1];
705
+ const newLastObservedAt = input.lastObservedAt ??
706
+ (lastActivatedChunk?.lastObservedAt
707
+ ? new Date(lastActivatedChunk.lastObservedAt)
708
+ : record.lastObservedAt);
709
+ const existingMsgIds = record.observedMessageIds ?? [];
710
+ const mergedMsgIds = [...new Set([...existingMsgIds, ...allMsgIds])];
711
+ await this.omRepo.update(input.id, {
712
+ activeObservations: newActive,
713
+ observationTokenCount: record.observationTokenCount + totalObsTokens,
714
+ bufferedObservationChunks: remaining.length > 0 ? remaining : null,
715
+ lastObservedAt: newLastObservedAt ?? null,
716
+ observedMessageIds: mergedMsgIds,
717
+ totalTokensObserved: record.totalTokensObserved + totalObsTokens,
718
+ isBufferingObservation: false,
719
+ });
720
+ return {
721
+ chunksActivated: activatedCount,
722
+ messageTokensActivated: totalMessageTokens,
723
+ observationTokensActivated: totalObsTokens,
724
+ messagesActivated: totalMessages,
725
+ activatedCycleIds: cycleIds,
726
+ activatedMessageIds: allMsgIds,
727
+ observations: observationParts.join('\n'),
728
+ };
729
+ }
730
+ async createReflectionGeneration(input) {
731
+ const { currentRecord, reflection, tokenCount } = input;
732
+ const newId = (0, utils_1.generateNanoId)();
733
+ const lookupKey = this.omLookupKey(currentRecord.scope, currentRecord.threadId, currentRecord.resourceId);
734
+ const entity = this.omRepo.create({
735
+ id: newId,
736
+ lookupKey,
737
+ scope: currentRecord.scope,
738
+ threadId: currentRecord.threadId,
739
+ resourceId: currentRecord.resourceId,
740
+ activeObservations: reflection,
741
+ originType: 'reflection',
742
+ config: JSON.stringify(currentRecord.config),
743
+ generationCount: currentRecord.generationCount + 1,
744
+ lastObservedAt: currentRecord.lastObservedAt ?? null,
745
+ observationTokenCount: tokenCount,
746
+ totalTokensObserved: currentRecord.totalTokensObserved,
747
+ pendingMessageTokens: currentRecord.pendingMessageTokens,
748
+ isObserving: false,
749
+ isReflecting: false,
750
+ isBufferingObservation: false,
751
+ isBufferingReflection: false,
752
+ lastBufferedAtTokens: 0,
753
+ lastBufferedAtTime: null,
754
+ observedTimezone: currentRecord.observedTimezone ?? null,
755
+ metadata: currentRecord.metadata ?? null,
756
+ });
757
+ const saved = await this.omRepo.save(entity);
758
+ return this.entityToOMRecord(saved);
759
+ }
760
+ async updateBufferedReflection(input) {
761
+ await this.omRepo.update(input.id, {
762
+ bufferedReflection: input.reflection,
763
+ bufferedReflectionTokens: input.tokenCount,
764
+ bufferedReflectionInputTokens: input.inputTokenCount,
765
+ reflectedObservationLineCount: input.reflectedObservationLineCount,
766
+ });
767
+ }
768
+ async swapBufferedReflectionToActive(input) {
769
+ const { currentRecord, tokenCount } = input;
770
+ const lines = currentRecord.activeObservations.split('\n');
771
+ const reflectedCount = currentRecord.reflectedObservationLineCount ?? lines.length;
772
+ const unreflected = lines.slice(reflectedCount).join('\n');
773
+ const newActive = currentRecord.bufferedReflection
774
+ ? unreflected
775
+ ? `${currentRecord.bufferedReflection}\n${unreflected}`
776
+ : currentRecord.bufferedReflection
777
+ : unreflected;
778
+ const newId = (0, utils_1.generateNanoId)();
779
+ const lookupKey = this.omLookupKey(currentRecord.scope, currentRecord.threadId, currentRecord.resourceId);
780
+ const entity = this.omRepo.create({
781
+ id: newId,
782
+ lookupKey,
783
+ scope: currentRecord.scope,
784
+ threadId: currentRecord.threadId,
785
+ resourceId: currentRecord.resourceId,
786
+ activeObservations: newActive,
787
+ originType: 'reflection',
788
+ config: JSON.stringify(currentRecord.config),
789
+ generationCount: currentRecord.generationCount + 1,
790
+ lastObservedAt: currentRecord.lastObservedAt ?? null,
791
+ observationTokenCount: tokenCount,
792
+ totalTokensObserved: currentRecord.totalTokensObserved,
793
+ pendingMessageTokens: currentRecord.pendingMessageTokens,
794
+ isObserving: false,
795
+ isReflecting: false,
796
+ isBufferingObservation: false,
797
+ isBufferingReflection: false,
798
+ lastBufferedAtTokens: 0,
799
+ lastBufferedAtTime: null,
800
+ observedTimezone: currentRecord.observedTimezone ?? null,
801
+ metadata: currentRecord.metadata ?? null,
802
+ });
803
+ const saved = await this.omRepo.save(entity);
804
+ return this.entityToOMRecord(saved);
805
+ }
806
+ async setReflectingFlag(id, isReflecting) {
807
+ await this.omRepo.update(id, { isReflecting });
808
+ }
809
+ async setObservingFlag(id, isObserving) {
810
+ await this.omRepo.update(id, { isObserving });
811
+ }
812
+ async setBufferingObservationFlag(id, isBuffering, lastBufferedAtTokens) {
813
+ const updates = {
814
+ isBufferingObservation: isBuffering,
815
+ };
816
+ if (isBuffering && lastBufferedAtTokens !== undefined) {
817
+ updates.lastBufferedAtTokens = lastBufferedAtTokens;
818
+ }
819
+ await this.omRepo.update(id, updates);
820
+ }
821
+ async setBufferingReflectionFlag(id, isBuffering) {
822
+ await this.omRepo.update(id, { isBufferingReflection: isBuffering });
823
+ }
824
+ async clearObservationalMemory(threadId, resourceId) {
825
+ const scope = threadId ? 'thread' : 'resource';
826
+ const lookupKey = this.omLookupKey(scope, threadId, resourceId);
827
+ await this.omRepo.delete({ lookupKey });
828
+ }
829
+ async setPendingMessageTokens(id, tokenCount) {
830
+ await this.omRepo.update(id, { pendingMessageTokens: tokenCount });
831
+ }
832
+ entityToMessage(entity) {
833
+ return {
834
+ id: entity.id,
835
+ role: entity.role,
836
+ createdAt: entity.createdAt,
837
+ threadId: entity.threadId,
838
+ resourceId: entity.resourceId ?? undefined,
839
+ type: entity.type ?? undefined,
840
+ content: (0, n8n_workflow_1.jsonParse)(entity.content),
841
+ };
842
+ }
843
+ };
844
+ exports.TypeORMMemoryStorage = TypeORMMemoryStorage;
845
+ TypeORMMemoryStorage.threadMutationQueues = new Map();
846
+ exports.TypeORMMemoryStorage = TypeORMMemoryStorage = TypeORMMemoryStorage_1 = __decorate([
847
+ (0, di_1.Service)(),
848
+ __metadata("design:paramtypes", [instance_ai_thread_repository_1.InstanceAiThreadRepository,
849
+ instance_ai_message_repository_1.InstanceAiMessageRepository,
850
+ instance_ai_resource_repository_1.InstanceAiResourceRepository,
851
+ instance_ai_observational_memory_repository_1.InstanceAiObservationalMemoryRepository])
852
+ ], TypeORMMemoryStorage);
853
+ //# sourceMappingURL=typeorm-memory-storage.js.map