n8n 2.20.6 → 2.21.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 (580) hide show
  1. package/dist/abstract-server.d.ts +1 -0
  2. package/dist/abstract-server.js +10 -3
  3. package/dist/abstract-server.js.map +1 -1
  4. package/dist/agent-library-bundle.js +5989 -0
  5. package/dist/auth/auth.service.js +3 -3
  6. package/dist/auth/auth.service.js.map +1 -1
  7. package/dist/build.tsbuildinfo +1 -1
  8. package/dist/commands/execute-batch.d.ts +2 -2
  9. package/dist/commands/export/workflow.d.ts +2 -2
  10. package/dist/commands/import/workflow.d.ts +3 -0
  11. package/dist/commands/import/workflow.js +15 -1
  12. package/dist/commands/import/workflow.js.map +1 -1
  13. package/dist/commands/start.js +2 -0
  14. package/dist/commands/start.js.map +1 -1
  15. package/dist/constants.d.ts +1 -0
  16. package/dist/constants.js +6 -1
  17. package/dist/constants.js.map +1 -1
  18. package/dist/controller.registry.js +6 -0
  19. package/dist/controller.registry.js.map +1 -1
  20. package/dist/controllers/auth.controller.js +7 -2
  21. package/dist/controllers/auth.controller.js.map +1 -1
  22. package/dist/controllers/me.controller.d.ts +1 -0
  23. package/dist/controllers/me.controller.js +4 -1
  24. package/dist/controllers/me.controller.js.map +1 -1
  25. package/dist/controllers/users.controller.d.ts +2 -2
  26. package/dist/credentials/credentials.service.d.ts +1 -0
  27. package/dist/credentials/credentials.service.js +11 -4
  28. package/dist/credentials/credentials.service.js.map +1 -1
  29. package/dist/evaluation.ee/evaluation-api-error.d.ts +7 -0
  30. package/dist/evaluation.ee/evaluation-api-error.js +16 -0
  31. package/dist/evaluation.ee/evaluation-api-error.js.map +1 -0
  32. package/dist/evaluation.ee/evaluation-config-validator.d.ts +30 -0
  33. package/dist/evaluation.ee/evaluation-config-validator.js +236 -0
  34. package/dist/evaluation.ee/evaluation-config-validator.js.map +1 -0
  35. package/dist/evaluation.ee/evaluation-config.controller.d.ts +24 -0
  36. package/dist/evaluation.ee/evaluation-config.controller.js +94 -0
  37. package/dist/evaluation.ee/evaluation-config.controller.js.map +1 -0
  38. package/dist/evaluation.ee/evaluation-config.service.d.ts +18 -0
  39. package/dist/evaluation.ee/evaluation-config.service.js +74 -0
  40. package/dist/evaluation.ee/evaluation-config.service.js.map +1 -0
  41. package/dist/evaluation.ee/llm-judge-provider-registry.d.ts +13 -0
  42. package/dist/evaluation.ee/llm-judge-provider-registry.js +122 -0
  43. package/dist/evaluation.ee/llm-judge-provider-registry.js.map +1 -0
  44. package/dist/evaluation.ee/test-runner/test-runner.service.ee.d.ts +5 -0
  45. package/dist/evaluation.ee/test-runner/test-runner.service.ee.js +32 -10
  46. package/dist/evaluation.ee/test-runner/test-runner.service.ee.js.map +1 -1
  47. package/dist/evaluation.ee/test-runner/workflow-compiler.service.d.ts +22 -0
  48. package/dist/evaluation.ee/test-runner/workflow-compiler.service.js +285 -0
  49. package/dist/evaluation.ee/test-runner/workflow-compiler.service.js.map +1 -0
  50. package/dist/evaluation.ee/test-runs.controller.ee.d.ts +3 -0
  51. package/dist/evaluation.ee/test-runs.controller.ee.js +26 -9
  52. package/dist/evaluation.ee/test-runs.controller.ee.js.map +1 -1
  53. package/dist/evaluation.ee/test-runs.types.ee.d.ts +3 -0
  54. package/dist/eventbus/message-event-bus/message-event-bus.d.ts +2 -0
  55. package/dist/eventbus/message-event-bus/message-event-bus.js +54 -46
  56. package/dist/eventbus/message-event-bus/message-event-bus.js.map +1 -1
  57. package/dist/events/maps/relay.event-map.d.ts +3 -0
  58. package/dist/instance-settings-loader/instance-settings-loader.service.d.ts +4 -2
  59. package/dist/instance-settings-loader/instance-settings-loader.service.js +7 -3
  60. package/dist/instance-settings-loader/instance-settings-loader.service.js.map +1 -1
  61. package/dist/instance-settings-loader/loaders/community-packages.instance-settings-loader.d.ts +20 -0
  62. package/dist/instance-settings-loader/loaders/community-packages.instance-settings-loader.js +235 -0
  63. package/dist/instance-settings-loader/loaders/community-packages.instance-settings-loader.js.map +1 -0
  64. package/dist/instance-settings-loader/loaders/{sso.instance-settings-loader.d.ts → sso/oidc.instance-settings-loader.d.ts} +4 -10
  65. package/dist/instance-settings-loader/loaders/sso/oidc.instance-settings-loader.js +98 -0
  66. package/dist/instance-settings-loader/loaders/sso/oidc.instance-settings-loader.js.map +1 -0
  67. package/dist/instance-settings-loader/loaders/sso/provisioning.instance-settings-loader.d.ts +10 -0
  68. package/dist/instance-settings-loader/loaders/sso/provisioning.instance-settings-loader.js +65 -0
  69. package/dist/instance-settings-loader/loaders/sso/provisioning.instance-settings-loader.js.map +1 -0
  70. package/dist/instance-settings-loader/loaders/sso/saml.instance-settings-loader.d.ts +12 -0
  71. package/dist/instance-settings-loader/loaders/sso/saml.instance-settings-loader.js +75 -0
  72. package/dist/instance-settings-loader/loaders/sso/saml.instance-settings-loader.js.map +1 -0
  73. package/dist/instance-settings-loader/loaders/sso/sso.instance-settings-loader.d.ts +15 -0
  74. package/dist/instance-settings-loader/loaders/sso/sso.instance-settings-loader.js +75 -0
  75. package/dist/instance-settings-loader/loaders/sso/sso.instance-settings-loader.js.map +1 -0
  76. package/dist/load-nodes-and-credentials.d.ts +3 -3
  77. package/dist/load-nodes-and-credentials.js +25 -17
  78. package/dist/load-nodes-and-credentials.js.map +1 -1
  79. package/dist/modules/agents/adapters/agents-credential-provider.d.ts +12 -0
  80. package/dist/modules/agents/adapters/agents-credential-provider.js +63 -0
  81. package/dist/modules/agents/adapters/agents-credential-provider.js.map +1 -0
  82. package/dist/modules/agents/agent-execution.service.d.ts +42 -0
  83. package/dist/modules/agents/agent-execution.service.js +153 -0
  84. package/dist/modules/agents/agent-execution.service.js.map +1 -0
  85. package/dist/modules/agents/agent-message-mapper.d.ts +5 -0
  86. package/dist/modules/agents/agent-message-mapper.js +43 -0
  87. package/dist/modules/agents/agent-message-mapper.js.map +1 -0
  88. package/dist/modules/agents/agent-skills.service.d.ts +24 -0
  89. package/dist/modules/agents/agent-skills.service.js +166 -0
  90. package/dist/modules/agents/agent-skills.service.js.map +1 -0
  91. package/dist/modules/agents/agent-sse-stream.d.ts +15 -0
  92. package/dist/modules/agents/agent-sse-stream.js +194 -0
  93. package/dist/modules/agents/agent-sse-stream.js.map +1 -0
  94. package/dist/modules/agents/agents-tools.service.d.ts +18 -0
  95. package/dist/modules/agents/agents-tools.service.js +193 -0
  96. package/dist/modules/agents/agents-tools.service.js.map +1 -0
  97. package/dist/modules/agents/agents.controller.d.ts +260 -0
  98. package/dist/modules/agents/agents.controller.js +818 -0
  99. package/dist/modules/agents/agents.controller.js.map +1 -0
  100. package/dist/modules/agents/agents.module.d.ts +12 -0
  101. package/dist/modules/agents/agents.module.js +136 -0
  102. package/dist/modules/agents/agents.module.js.map +1 -0
  103. package/dist/modules/agents/agents.service.d.ts +151 -0
  104. package/dist/modules/agents/agents.service.js +1134 -0
  105. package/dist/modules/agents/agents.service.js.map +1 -0
  106. package/dist/modules/agents/builder/agents-builder-prompts.d.ts +27 -0
  107. package/dist/modules/agents/builder/agents-builder-prompts.js +584 -0
  108. package/dist/modules/agents/builder/agents-builder-prompts.js.map +1 -0
  109. package/dist/modules/agents/builder/agents-builder-settings.controller.d.ts +11 -0
  110. package/dist/modules/agents/builder/agents-builder-settings.controller.js +61 -0
  111. package/dist/modules/agents/builder/agents-builder-settings.controller.js.map +1 -0
  112. package/dist/modules/agents/builder/agents-builder-settings.service.d.ts +31 -0
  113. package/dist/modules/agents/builder/agents-builder-settings.service.js +199 -0
  114. package/dist/modules/agents/builder/agents-builder-settings.service.js.map +1 -0
  115. package/dist/modules/agents/builder/agents-builder-tools.service.d.ts +31 -0
  116. package/dist/modules/agents/builder/agents-builder-tools.service.js +420 -0
  117. package/dist/modules/agents/builder/agents-builder-tools.service.js.map +1 -0
  118. package/dist/modules/agents/builder/agents-builder.service.d.ts +26 -0
  119. package/dist/modules/agents/builder/agents-builder.service.js +164 -0
  120. package/dist/modules/agents/builder/agents-builder.service.js.map +1 -0
  121. package/dist/modules/agents/builder/builder-model-lookup.service.d.ts +17 -0
  122. package/dist/modules/agents/builder/builder-model-lookup.service.js +67 -0
  123. package/dist/modules/agents/builder/builder-model-lookup.service.js.map +1 -0
  124. package/dist/modules/agents/builder/builder-tool-names.d.ts +14 -0
  125. package/dist/modules/agents/builder/builder-tool-names.js +17 -0
  126. package/dist/modules/agents/builder/builder-tool-names.js.map +1 -0
  127. package/dist/modules/agents/builder/errors.d.ts +6 -0
  128. package/dist/modules/agents/builder/errors.js +13 -0
  129. package/dist/modules/agents/builder/errors.js.map +1 -0
  130. package/dist/modules/agents/builder/interactive/ask-credential.tool.d.ts +5 -0
  131. package/dist/modules/agents/builder/interactive/ask-credential.tool.js +29 -0
  132. package/dist/modules/agents/builder/interactive/ask-credential.tool.js.map +1 -0
  133. package/dist/modules/agents/builder/interactive/ask-llm.tool.d.ts +2 -0
  134. package/dist/modules/agents/builder/interactive/ask-llm.tool.js +27 -0
  135. package/dist/modules/agents/builder/interactive/ask-llm.tool.js.map +1 -0
  136. package/dist/modules/agents/builder/interactive/ask-question.tool.d.ts +2 -0
  137. package/dist/modules/agents/builder/interactive/ask-question.tool.js +26 -0
  138. package/dist/modules/agents/builder/interactive/ask-question.tool.js.map +1 -0
  139. package/dist/modules/agents/builder/interactive/index.d.ts +4 -0
  140. package/dist/modules/agents/builder/interactive/index.js +12 -0
  141. package/dist/modules/agents/builder/interactive/index.js.map +1 -0
  142. package/dist/modules/agents/builder/interactive/llm-provider-defaults.d.ts +17 -0
  143. package/dist/modules/agents/builder/interactive/llm-provider-defaults.js +60 -0
  144. package/dist/modules/agents/builder/interactive/llm-provider-defaults.js.map +1 -0
  145. package/dist/modules/agents/builder/interactive/resolve-llm.tool.d.ts +13 -0
  146. package/dist/modules/agents/builder/interactive/resolve-llm.tool.js +136 -0
  147. package/dist/modules/agents/builder/interactive/resolve-llm.tool.js.map +1 -0
  148. package/dist/modules/agents/entities/agent-checkpoint.entity.d.ts +9 -0
  149. package/dist/modules/agents/entities/agent-checkpoint.entity.js +43 -0
  150. package/dist/modules/agents/entities/agent-checkpoint.entity.js.map +1 -0
  151. package/dist/modules/agents/entities/agent-execution-thread.entity.d.ts +16 -0
  152. package/dist/modules/agents/entities/agent-execution-thread.entity.js +74 -0
  153. package/dist/modules/agents/entities/agent-execution-thread.entity.js.map +1 -0
  154. package/dist/modules/agents/entities/agent-execution.entity.d.ts +26 -0
  155. package/dist/modules/agents/entities/agent-execution.entity.js +100 -0
  156. package/dist/modules/agents/entities/agent-execution.entity.js.map +1 -0
  157. package/dist/modules/agents/entities/agent-message.entity.d.ts +10 -0
  158. package/dist/modules/agents/entities/agent-message.entity.js +47 -0
  159. package/dist/modules/agents/entities/agent-message.entity.js.map +1 -0
  160. package/dist/modules/agents/entities/agent-observation-cursor.entity.d.ts +8 -0
  161. package/dist/modules/agents/entities/agent-observation-cursor.entity.js +37 -0
  162. package/dist/modules/agents/entities/agent-observation-cursor.entity.js.map +1 -0
  163. package/dist/modules/agents/entities/agent-observation-lock.entity.d.ts +8 -0
  164. package/dist/modules/agents/entities/agent-observation-lock.entity.js +37 -0
  165. package/dist/modules/agents/entities/agent-observation-lock.entity.js.map +1 -0
  166. package/dist/modules/agents/entities/agent-observation.entity.d.ts +10 -0
  167. package/dist/modules/agents/entities/agent-observation.entity.js +47 -0
  168. package/dist/modules/agents/entities/agent-observation.entity.js.map +1 -0
  169. package/dist/modules/agents/entities/agent-published-version.entity.d.ts +22 -0
  170. package/dist/modules/agents/entities/agent-published-version.entity.js +67 -0
  171. package/dist/modules/agents/entities/agent-published-version.entity.js.map +1 -0
  172. package/dist/modules/agents/entities/agent-resource.entity.d.ts +5 -0
  173. package/dist/modules/agents/entities/agent-resource.entity.js +29 -0
  174. package/dist/modules/agents/entities/agent-resource.entity.js.map +1 -0
  175. package/dist/modules/agents/entities/agent-thread.entity.d.ts +6 -0
  176. package/dist/modules/agents/entities/agent-thread.entity.js +33 -0
  177. package/dist/modules/agents/entities/agent-thread.entity.js.map +1 -0
  178. package/dist/modules/agents/entities/agent.entity.d.ts +24 -0
  179. package/dist/modules/agents/entities/agent.entity.js +74 -0
  180. package/dist/modules/agents/entities/agent.entity.js.map +1 -0
  181. package/dist/modules/agents/execution-recorder.d.ts +82 -0
  182. package/dist/modules/agents/execution-recorder.js +272 -0
  183. package/dist/modules/agents/execution-recorder.js.map +1 -0
  184. package/dist/modules/agents/integrations/agent-chat-bridge.d.ts +62 -0
  185. package/dist/modules/agents/integrations/agent-chat-bridge.js +540 -0
  186. package/dist/modules/agents/integrations/agent-chat-bridge.js.map +1 -0
  187. package/dist/modules/agents/integrations/agent-chat-integration.d.ts +39 -0
  188. package/dist/modules/agents/integrations/agent-chat-integration.js +45 -0
  189. package/dist/modules/agents/integrations/agent-chat-integration.js.map +1 -0
  190. package/dist/modules/agents/integrations/agent-schedule.service.d.ts +30 -0
  191. package/dist/modules/agents/integrations/agent-schedule.service.js +327 -0
  192. package/dist/modules/agents/integrations/agent-schedule.service.js.map +1 -0
  193. package/dist/modules/agents/integrations/callback-store.d.ts +11 -0
  194. package/dist/modules/agents/integrations/callback-store.js +30 -0
  195. package/dist/modules/agents/integrations/callback-store.js.map +1 -0
  196. package/dist/modules/agents/integrations/chat-integration.service.d.ts +58 -0
  197. package/dist/modules/agents/integrations/chat-integration.service.js +397 -0
  198. package/dist/modules/agents/integrations/chat-integration.service.js.map +1 -0
  199. package/dist/modules/agents/integrations/component-mapper.d.ts +57 -0
  200. package/dist/modules/agents/integrations/component-mapper.js +223 -0
  201. package/dist/modules/agents/integrations/component-mapper.js.map +1 -0
  202. package/dist/modules/agents/integrations/cron-validation.d.ts +1 -0
  203. package/dist/modules/agents/integrations/cron-validation.js +8 -0
  204. package/dist/modules/agents/integrations/cron-validation.js.map +1 -0
  205. package/dist/modules/agents/integrations/esm-loader.d.ts +5 -0
  206. package/dist/modules/agents/integrations/esm-loader.js +24 -0
  207. package/dist/modules/agents/integrations/esm-loader.js.map +1 -0
  208. package/dist/modules/agents/integrations/integrations-sync.d.ts +4 -0
  209. package/dist/modules/agents/integrations/integrations-sync.js +78 -0
  210. package/dist/modules/agents/integrations/integrations-sync.js.map +1 -0
  211. package/dist/modules/agents/integrations/n8n-checkpoint-storage.d.ts +36 -0
  212. package/dist/modules/agents/integrations/n8n-checkpoint-storage.js +148 -0
  213. package/dist/modules/agents/integrations/n8n-checkpoint-storage.js.map +1 -0
  214. package/dist/modules/agents/integrations/n8n-memory.d.ts +76 -0
  215. package/dist/modules/agents/integrations/n8n-memory.js +383 -0
  216. package/dist/modules/agents/integrations/n8n-memory.js.map +1 -0
  217. package/dist/modules/agents/integrations/platforms/linear-integration.d.ts +14 -0
  218. package/dist/modules/agents/integrations/platforms/linear-integration.js +83 -0
  219. package/dist/modules/agents/integrations/platforms/linear-integration.js.map +1 -0
  220. package/dist/modules/agents/integrations/platforms/slack-integration.d.ts +12 -0
  221. package/dist/modules/agents/integrations/platforms/slack-integration.js +81 -0
  222. package/dist/modules/agents/integrations/platforms/slack-integration.js.map +1 -0
  223. package/dist/modules/agents/integrations/platforms/telegram-integration.d.ts +30 -0
  224. package/dist/modules/agents/integrations/platforms/telegram-integration.js +122 -0
  225. package/dist/modules/agents/integrations/platforms/telegram-integration.js.map +1 -0
  226. package/dist/modules/agents/integrations/rich-interaction-tool.d.ts +47 -0
  227. package/dist/modules/agents/integrations/rich-interaction-tool.js +109 -0
  228. package/dist/modules/agents/integrations/rich-interaction-tool.js.map +1 -0
  229. package/dist/modules/agents/integrations/types.d.ts +8 -0
  230. package/dist/modules/agents/integrations/types.js +12 -0
  231. package/dist/modules/agents/integrations/types.js.map +1 -0
  232. package/dist/modules/agents/json-config/agent-config-composition.d.ts +9 -0
  233. package/dist/modules/agents/json-config/agent-config-composition.js +27 -0
  234. package/dist/modules/agents/json-config/agent-config-composition.js.map +1 -0
  235. package/dist/modules/agents/json-config/agent-json-config.d.ts +1022 -0
  236. package/dist/modules/agents/json-config/agent-json-config.js +128 -0
  237. package/dist/modules/agents/json-config/agent-json-config.js.map +1 -0
  238. package/dist/modules/agents/json-config/credential-field-mapping.d.ts +4 -0
  239. package/dist/modules/agents/json-config/credential-field-mapping.js +41 -0
  240. package/dist/modules/agents/json-config/credential-field-mapping.js.map +1 -0
  241. package/dist/modules/agents/json-config/from-json-config.d.ts +18 -0
  242. package/dist/modules/agents/json-config/from-json-config.js +209 -0
  243. package/dist/modules/agents/json-config/from-json-config.js.map +1 -0
  244. package/dist/modules/agents/json-config/integration-config.d.ts +61 -0
  245. package/dist/modules/agents/json-config/integration-config.js +33 -0
  246. package/dist/modules/agents/json-config/integration-config.js.map +1 -0
  247. package/dist/modules/agents/json-config/provider-tool-aliases.d.ts +1 -0
  248. package/dist/modules/agents/json-config/provider-tool-aliases.js +15 -0
  249. package/dist/modules/agents/json-config/provider-tool-aliases.js.map +1 -0
  250. package/dist/modules/agents/json-config/schema-text-serializer.d.ts +2 -0
  251. package/dist/modules/agents/json-config/schema-text-serializer.js +205 -0
  252. package/dist/modules/agents/json-config/schema-text-serializer.js.map +1 -0
  253. package/dist/modules/agents/repositories/agent-checkpoint.repository.d.ts +6 -0
  254. package/dist/modules/agents/repositories/agent-checkpoint.repository.js +35 -0
  255. package/dist/modules/agents/repositories/agent-checkpoint.repository.js.map +1 -0
  256. package/dist/modules/agents/repositories/agent-execution-thread.repository.d.ts +18 -0
  257. package/dist/modules/agents/repositories/agent-execution-thread.repository.js +120 -0
  258. package/dist/modules/agents/repositories/agent-execution-thread.repository.js.map +1 -0
  259. package/dist/modules/agents/repositories/agent-execution.repository.d.ts +10 -0
  260. package/dist/modules/agents/repositories/agent-execution.repository.js +59 -0
  261. package/dist/modules/agents/repositories/agent-execution.repository.js.map +1 -0
  262. package/dist/modules/agents/repositories/agent-message.repository.d.ts +5 -0
  263. package/dist/modules/agents/repositories/agent-message.repository.js +26 -0
  264. package/dist/modules/agents/repositories/agent-message.repository.js.map +1 -0
  265. package/dist/modules/agents/repositories/agent-observation-cursor.repository.d.ts +5 -0
  266. package/dist/modules/agents/repositories/agent-observation-cursor.repository.js +26 -0
  267. package/dist/modules/agents/repositories/agent-observation-cursor.repository.js.map +1 -0
  268. package/dist/modules/agents/repositories/agent-observation-lock.repository.d.ts +5 -0
  269. package/dist/modules/agents/repositories/agent-observation-lock.repository.js +26 -0
  270. package/dist/modules/agents/repositories/agent-observation-lock.repository.js.map +1 -0
  271. package/dist/modules/agents/repositories/agent-observation.repository.d.ts +5 -0
  272. package/dist/modules/agents/repositories/agent-observation.repository.js +26 -0
  273. package/dist/modules/agents/repositories/agent-observation.repository.js.map +1 -0
  274. package/dist/modules/agents/repositories/agent-published-version.repository.d.ts +20 -0
  275. package/dist/modules/agents/repositories/agent-published-version.repository.js +35 -0
  276. package/dist/modules/agents/repositories/agent-published-version.repository.js.map +1 -0
  277. package/dist/modules/agents/repositories/agent-resource.repository.d.ts +5 -0
  278. package/dist/modules/agents/repositories/agent-resource.repository.js +26 -0
  279. package/dist/modules/agents/repositories/agent-resource.repository.js.map +1 -0
  280. package/dist/modules/agents/repositories/agent-thread.repository.d.ts +5 -0
  281. package/dist/modules/agents/repositories/agent-thread.repository.js +26 -0
  282. package/dist/modules/agents/repositories/agent-thread.repository.js.map +1 -0
  283. package/dist/modules/agents/repositories/agent.repository.d.ts +9 -0
  284. package/dist/modules/agents/repositories/agent.repository.js +50 -0
  285. package/dist/modules/agents/repositories/agent.repository.js.map +1 -0
  286. package/dist/modules/agents/runtime/agent-isolate-pool.d.ts +48 -0
  287. package/dist/modules/agents/runtime/agent-isolate-pool.js +246 -0
  288. package/dist/modules/agents/runtime/agent-isolate-pool.js.map +1 -0
  289. package/dist/modules/agents/runtime/agent-secure-runtime.d.ts +21 -0
  290. package/dist/modules/agents/runtime/agent-secure-runtime.js +281 -0
  291. package/dist/modules/agents/runtime/agent-secure-runtime.js.map +1 -0
  292. package/dist/modules/agents/runtime/sandbox-polyfills.d.ts +1 -0
  293. package/dist/modules/agents/runtime/sandbox-polyfills.js +74 -0
  294. package/dist/modules/agents/runtime/sandbox-polyfills.js.map +1 -0
  295. package/dist/modules/agents/tool-registry.d.ts +13 -0
  296. package/dist/modules/agents/tool-registry.js +42 -0
  297. package/dist/modules/agents/tool-registry.js.map +1 -0
  298. package/dist/modules/agents/tools/environment-tool.d.ts +3 -0
  299. package/dist/modules/agents/tools/environment-tool.js +26 -0
  300. package/dist/modules/agents/tools/environment-tool.js.map +1 -0
  301. package/dist/modules/agents/tools/node-tool-factory.d.ts +10 -0
  302. package/dist/modules/agents/tools/node-tool-factory.js +100 -0
  303. package/dist/modules/agents/tools/node-tool-factory.js.map +1 -0
  304. package/dist/modules/agents/tools/workflow-tool-factory.d.ts +43 -0
  305. package/dist/modules/agents/tools/workflow-tool-factory.js +404 -0
  306. package/dist/modules/agents/tools/workflow-tool-factory.js.map +1 -0
  307. package/dist/modules/agents/tracing/builder-telemetry.d.ts +12 -0
  308. package/dist/modules/agents/tracing/builder-telemetry.js +48 -0
  309. package/dist/modules/agents/tracing/builder-telemetry.js.map +1 -0
  310. package/dist/modules/agents/types/components.d.ts +71 -0
  311. package/dist/modules/agents/types/components.js +3 -0
  312. package/dist/modules/agents/types/components.js.map +1 -0
  313. package/dist/modules/agents/types/index.d.ts +1 -0
  314. package/dist/modules/agents/types/index.js +3 -0
  315. package/dist/modules/agents/types/index.js.map +1 -0
  316. package/dist/modules/agents/utils/agent-draft.utils.d.ts +2 -0
  317. package/dist/modules/agents/utils/agent-draft.utils.js +11 -0
  318. package/dist/modules/agents/utils/agent-draft.utils.js.map +1 -0
  319. package/dist/modules/agents/utils/agent-resource-id.d.ts +3 -0
  320. package/dist/modules/agents/utils/agent-resource-id.js +14 -0
  321. package/dist/modules/agents/utils/agent-resource-id.js.map +1 -0
  322. package/dist/modules/chat-hub/chat-hub.module.d.ts +2 -2
  323. package/dist/modules/chat-hub/chat-hub.settings.controller.d.ts +4 -4
  324. package/dist/modules/chat-hub/chat-hub.types.d.ts +2 -2
  325. package/dist/modules/chat-hub/dto/chat-models-request.dto.d.ts +1 -1
  326. package/dist/modules/community-packages/community-packages.config.js +2 -2
  327. package/dist/modules/community-packages/community-packages.config.js.map +1 -1
  328. package/dist/modules/community-packages/community-packages.lifecycle.service.d.ts +4 -1
  329. package/dist/modules/community-packages/community-packages.lifecycle.service.js +14 -2
  330. package/dist/modules/community-packages/community-packages.lifecycle.service.js.map +1 -1
  331. package/dist/modules/community-packages/community-packages.module.d.ts +1 -1
  332. package/dist/modules/community-packages/community-packages.module.js +10 -5
  333. package/dist/modules/community-packages/community-packages.module.js.map +1 -1
  334. package/dist/modules/data-table/data-table.service.js +6 -0
  335. package/dist/modules/data-table/data-table.service.js.map +1 -1
  336. package/dist/modules/dynamic-credentials.ee/credential-resolvers/identifiers/slack-signature-identifier.d.ts +1 -1
  337. package/dist/modules/dynamic-credentials.ee/dynamic-credentials.config.d.ts +2 -0
  338. package/dist/modules/dynamic-credentials.ee/dynamic-credentials.config.js +10 -0
  339. package/dist/modules/dynamic-credentials.ee/dynamic-credentials.config.js.map +1 -1
  340. package/dist/modules/dynamic-credentials.ee/dynamic-credentials.controller.d.ts +1 -1
  341. package/dist/modules/dynamic-credentials.ee/dynamic-credentials.controller.js +16 -4
  342. package/dist/modules/dynamic-credentials.ee/dynamic-credentials.controller.js.map +1 -1
  343. package/dist/modules/dynamic-credentials.ee/workflow-status.controller.d.ts +3 -3
  344. package/dist/modules/dynamic-credentials.ee/workflow-status.controller.js +11 -3
  345. package/dist/modules/dynamic-credentials.ee/workflow-status.controller.js.map +1 -1
  346. package/dist/modules/encryption-key-manager/encryption-bootstrap.service.js +4 -2
  347. package/dist/modules/encryption-key-manager/encryption-bootstrap.service.js.map +1 -1
  348. package/dist/modules/encryption-key-manager/encryption-key-manager.module.js +5 -2
  349. package/dist/modules/encryption-key-manager/encryption-key-manager.module.js.map +1 -1
  350. package/dist/modules/encryption-key-manager/encryption-key.controller.d.ts +3 -3
  351. package/dist/modules/encryption-key-manager/encryption-key.controller.js +8 -2
  352. package/dist/modules/encryption-key-manager/encryption-key.controller.js.map +1 -1
  353. package/dist/modules/encryption-key-manager/key-manager.service.d.ts +5 -1
  354. package/dist/modules/encryption-key-manager/key-manager.service.js +11 -4
  355. package/dist/modules/encryption-key-manager/key-manager.service.js.map +1 -1
  356. package/dist/modules/insights/insights-collection.service.js +1 -0
  357. package/dist/modules/insights/insights-collection.service.js.map +1 -1
  358. package/dist/modules/instance-ai/eval/mock-handler.js +17 -49
  359. package/dist/modules/instance-ai/eval/mock-handler.js.map +1 -1
  360. package/dist/modules/instance-ai/filesystem/local-gateway-registry.d.ts +1 -0
  361. package/dist/modules/instance-ai/filesystem/local-gateway-registry.js +21 -3
  362. package/dist/modules/instance-ai/filesystem/local-gateway-registry.js.map +1 -1
  363. package/dist/modules/instance-ai/instance-ai-settings.service.d.ts +3 -2
  364. package/dist/modules/instance-ai/instance-ai-settings.service.js +10 -9
  365. package/dist/modules/instance-ai/instance-ai-settings.service.js.map +1 -1
  366. package/dist/modules/instance-ai/instance-ai-test.controller.d.ts +21 -2
  367. package/dist/modules/instance-ai/instance-ai-test.controller.js +35 -3
  368. package/dist/modules/instance-ai/instance-ai-test.controller.js.map +1 -1
  369. package/dist/modules/instance-ai/instance-ai.adapter.service.js +72 -42
  370. package/dist/modules/instance-ai/instance-ai.adapter.service.js.map +1 -1
  371. package/dist/modules/instance-ai/instance-ai.controller.d.ts +2 -0
  372. package/dist/modules/instance-ai/instance-ai.controller.js +25 -1
  373. package/dist/modules/instance-ai/instance-ai.controller.js.map +1 -1
  374. package/dist/modules/instance-ai/instance-ai.module.d.ts +0 -1
  375. package/dist/modules/instance-ai/instance-ai.module.js +0 -2
  376. package/dist/modules/instance-ai/instance-ai.module.js.map +1 -1
  377. package/dist/modules/instance-ai/instance-ai.service.d.ts +34 -5
  378. package/dist/modules/instance-ai/instance-ai.service.js +723 -76
  379. package/dist/modules/instance-ai/instance-ai.service.js.map +1 -1
  380. package/dist/modules/instance-ai/liveness/index.d.ts +1 -0
  381. package/dist/modules/instance-ai/liveness/index.js +7 -0
  382. package/dist/modules/instance-ai/liveness/index.js.map +1 -0
  383. package/dist/modules/instance-ai/liveness/instance-ai-liveness.service.d.ts +72 -0
  384. package/dist/modules/instance-ai/liveness/instance-ai-liveness.service.js +123 -0
  385. package/dist/modules/instance-ai/liveness/instance-ai-liveness.service.js.map +1 -0
  386. package/dist/modules/instance-ai/message-parser.js +85 -6
  387. package/dist/modules/instance-ai/message-parser.js.map +1 -1
  388. package/dist/modules/instance-ai/storage/db-snapshot-storage.js +4 -0
  389. package/dist/modules/instance-ai/storage/db-snapshot-storage.js.map +1 -1
  390. package/dist/modules/instance-ai/storage/typeorm-memory-storage.js +1 -0
  391. package/dist/modules/instance-ai/storage/typeorm-memory-storage.js.map +1 -1
  392. package/dist/modules/instance-ai/web-research/fetch-and-extract.js +23 -7
  393. package/dist/modules/instance-ai/web-research/fetch-and-extract.js.map +1 -1
  394. package/dist/modules/mcp/mcp.service.d.ts +3 -3
  395. package/dist/modules/mcp/mcp.service.js +12 -9
  396. package/dist/modules/mcp/mcp.service.js.map +1 -1
  397. package/dist/modules/mcp/tools/get-execution.tool.js +6 -4
  398. package/dist/modules/mcp/tools/get-execution.tool.js.map +1 -1
  399. package/dist/modules/mcp/tools/list-credentials.tool.d.ts +40 -0
  400. package/dist/modules/mcp/tools/list-credentials.tool.js +148 -0
  401. package/dist/modules/mcp/tools/list-credentials.tool.js.map +1 -0
  402. package/dist/modules/mcp/tools/workflow-builder/create-workflow-from-code.tool.js +5 -4
  403. package/dist/modules/mcp/tools/workflow-builder/create-workflow-from-code.tool.js.map +1 -1
  404. package/dist/modules/mcp/tools/workflow-builder/get-suggested-workflow-nodes.tool.d.ts +2 -2
  405. package/dist/modules/mcp/tools/workflow-builder/get-suggested-workflow-nodes.tool.js +3 -3
  406. package/dist/modules/mcp/tools/workflow-builder/get-suggested-workflow-nodes.tool.js.map +1 -1
  407. package/dist/modules/mcp/tools/workflow-builder/get-workflow-node-types.tool.d.ts +2 -2
  408. package/dist/modules/mcp/tools/workflow-builder/get-workflow-node-types.tool.js +2 -2
  409. package/dist/modules/mcp/tools/workflow-builder/get-workflow-node-types.tool.js.map +1 -1
  410. package/dist/modules/mcp/tools/workflow-builder/get-workflow-sdk-reference.tool.js +3 -2
  411. package/dist/modules/mcp/tools/workflow-builder/get-workflow-sdk-reference.tool.js.map +1 -1
  412. package/dist/modules/mcp/tools/workflow-builder/mcp-instructions.js +3 -3
  413. package/dist/modules/mcp/tools/workflow-builder/mcp-instructions.js.map +1 -1
  414. package/dist/modules/mcp/tools/workflow-builder/sdk-reference-content.d.ts +1 -1
  415. package/dist/modules/mcp/tools/workflow-builder/sdk-reference-content.js +12 -4
  416. package/dist/modules/mcp/tools/workflow-builder/sdk-reference-content.js.map +1 -1
  417. package/dist/modules/mcp/tools/workflow-builder/search-workflow-nodes.tool.d.ts +2 -2
  418. package/dist/modules/mcp/tools/workflow-builder/search-workflow-nodes.tool.js +12 -5
  419. package/dist/modules/mcp/tools/workflow-builder/search-workflow-nodes.tool.js.map +1 -1
  420. package/dist/modules/mcp/tools/workflow-builder/update-workflow.tool.js +1 -2
  421. package/dist/modules/mcp/tools/workflow-builder/update-workflow.tool.js.map +1 -1
  422. package/dist/modules/mcp/tools/workflow-builder/validate-workflow-code.tool.js +1 -1
  423. package/dist/modules/mcp/tools/workflow-builder/validate-workflow-code.tool.js.map +1 -1
  424. package/dist/modules/mcp/tools/workflow-validation.utils.d.ts +5 -1
  425. package/dist/modules/mcp/tools/workflow-validation.utils.js +4 -2
  426. package/dist/modules/mcp/tools/workflow-validation.utils.js.map +1 -1
  427. package/dist/modules/mcp-registry/mcp-registry-node-loader.d.ts +27 -0
  428. package/dist/modules/mcp-registry/mcp-registry-node-loader.js +105 -0
  429. package/dist/modules/mcp-registry/mcp-registry-node-loader.js.map +1 -0
  430. package/dist/modules/mcp-registry/mcp-registry-node-loader.test.d.ts +1 -0
  431. package/dist/modules/mcp-registry/mcp-registry-node-loader.test.js +244 -0
  432. package/dist/modules/mcp-registry/mcp-registry-node-loader.test.js.map +1 -0
  433. package/dist/modules/mcp-registry/mcp-registry.module.d.ts +4 -0
  434. package/dist/modules/mcp-registry/mcp-registry.module.js +60 -0
  435. package/dist/modules/mcp-registry/mcp-registry.module.js.map +1 -0
  436. package/dist/modules/mcp-registry/node-description-transform.d.ts +8 -0
  437. package/dist/modules/mcp-registry/node-description-transform.js +133 -0
  438. package/dist/modules/mcp-registry/node-description-transform.js.map +1 -0
  439. package/dist/modules/mcp-registry/node-description-transform.test.d.ts +1 -0
  440. package/dist/modules/mcp-registry/node-description-transform.test.js +286 -0
  441. package/dist/modules/mcp-registry/node-description-transform.test.js.map +1 -0
  442. package/dist/modules/mcp-registry/registry/mcp-registry.service.d.ts +8 -0
  443. package/dist/modules/mcp-registry/registry/mcp-registry.service.js +31 -0
  444. package/dist/modules/mcp-registry/registry/mcp-registry.service.js.map +1 -0
  445. package/dist/modules/mcp-registry/registry/mcp-registry.service.test.d.ts +1 -0
  446. package/dist/modules/mcp-registry/registry/mcp-registry.service.test.js +41 -0
  447. package/dist/modules/mcp-registry/registry/mcp-registry.service.test.js.map +1 -0
  448. package/dist/modules/mcp-registry/registry/mcp-registry.types.d.ts +36 -0
  449. package/dist/modules/mcp-registry/registry/mcp-registry.types.js +3 -0
  450. package/dist/modules/mcp-registry/registry/mcp-registry.types.js.map +1 -0
  451. package/dist/modules/mcp-registry/registry/mock-servers.d.ts +3 -0
  452. package/dist/modules/mcp-registry/registry/mock-servers.js +80 -0
  453. package/dist/modules/mcp-registry/registry/mock-servers.js.map +1 -0
  454. package/dist/modules/otel/execution-level-tracer.d.ts +1 -1
  455. package/dist/modules/otel/execution-level-tracer.js +24 -9
  456. package/dist/modules/otel/execution-level-tracer.js.map +1 -1
  457. package/dist/modules/otel/execution-level-tracer.types.d.ts +9 -7
  458. package/dist/modules/otel/execution-level-tracer.types.js +14 -0
  459. package/dist/modules/otel/execution-level-tracer.types.js.map +1 -1
  460. package/dist/modules/quick-connect/quick-connect.config.d.ts +176 -0
  461. package/dist/modules/quick-connect/quick-connect.config.js +8 -0
  462. package/dist/modules/quick-connect/quick-connect.config.js.map +1 -1
  463. package/dist/modules/quick-connect/quick-connect.module.d.ts +15 -0
  464. package/dist/modules/redaction/executions/execution-redaction.service.d.ts +1 -3
  465. package/dist/modules/redaction/executions/execution-redaction.service.js +2 -6
  466. package/dist/modules/redaction/executions/execution-redaction.service.js.map +1 -1
  467. package/dist/modules/source-control.ee/source-control.controller.ee.d.ts +2 -2
  468. package/dist/modules/source-control.ee/source-control.service.ee.d.ts +1 -1
  469. package/dist/modules/sso-oidc/oidc.controller.ee.d.ts +3 -1
  470. package/dist/modules/sso-oidc/oidc.controller.ee.js +8 -1
  471. package/dist/modules/sso-oidc/oidc.controller.ee.js.map +1 -1
  472. package/dist/node-catalog/index.d.ts +1 -0
  473. package/dist/node-catalog/index.js +6 -0
  474. package/dist/node-catalog/index.js.map +1 -0
  475. package/dist/{modules/mcp/tools/workflow-builder/workflow-builder-tools.service.d.ts → node-catalog/node-catalog.service.d.ts} +9 -15
  476. package/dist/{modules/mcp/tools/workflow-builder/workflow-builder-tools.service.js → node-catalog/node-catalog.service.js} +38 -28
  477. package/dist/node-catalog/node-catalog.service.js.map +1 -0
  478. package/dist/node-execution/ephemeral-node-executor.d.ts +47 -0
  479. package/dist/node-execution/ephemeral-node-executor.js +289 -0
  480. package/dist/node-execution/ephemeral-node-executor.js.map +1 -0
  481. package/dist/node-execution/index.d.ts +2 -0
  482. package/dist/node-execution/index.js +8 -0
  483. package/dist/node-execution/index.js.map +1 -0
  484. package/dist/public-api/v1/handlers/audit/audit.handler.d.ts +5 -4
  485. package/dist/public-api/v1/handlers/audit/audit.handler.js +5 -9
  486. package/dist/public-api/v1/handlers/audit/audit.handler.js.map +1 -1
  487. package/dist/public-api/v1/handlers/community-packages/community-packages.handler.d.ts +20 -17
  488. package/dist/public-api/v1/handlers/community-packages/community-packages.handler.js +12 -39
  489. package/dist/public-api/v1/handlers/community-packages/community-packages.handler.js.map +1 -1
  490. package/dist/public-api/v1/handlers/credentials/credentials.handler.d.ts +12 -49
  491. package/dist/public-api/v1/handlers/credentials/credentials.handler.js +6 -5
  492. package/dist/public-api/v1/handlers/credentials/credentials.handler.js.map +1 -1
  493. package/dist/public-api/v1/handlers/data-tables/data-tables.columns.handler.d.ts +8 -19
  494. package/dist/public-api/v1/handlers/data-tables/data-tables.columns.handler.js +11 -11
  495. package/dist/public-api/v1/handlers/data-tables/data-tables.columns.handler.js.map +1 -1
  496. package/dist/public-api/v1/handlers/data-tables/data-tables.handler.d.ts +9 -17
  497. package/dist/public-api/v1/handlers/data-tables/data-tables.handler.js +19 -23
  498. package/dist/public-api/v1/handlers/data-tables/data-tables.handler.js.map +1 -1
  499. package/dist/public-api/v1/handlers/data-tables/data-tables.rows.handler.d.ts +9 -23
  500. package/dist/public-api/v1/handlers/data-tables/data-tables.rows.handler.js +17 -27
  501. package/dist/public-api/v1/handlers/data-tables/data-tables.rows.handler.js.map +1 -1
  502. package/dist/public-api/v1/handlers/discover/discover.handler.d.ts +11 -9
  503. package/dist/public-api/v1/handlers/discover/discover.handler.js +5 -3
  504. package/dist/public-api/v1/handlers/discover/discover.handler.js.map +1 -1
  505. package/dist/public-api/v1/handlers/executions/executions.handler.d.ts +12 -11
  506. package/dist/public-api/v1/handlers/executions/executions.handler.js +46 -80
  507. package/dist/public-api/v1/handlers/executions/executions.handler.js.map +1 -1
  508. package/dist/public-api/v1/handlers/folders/folders.handler.d.ts +12 -17
  509. package/dist/public-api/v1/handlers/folders/folders.handler.js +17 -20
  510. package/dist/public-api/v1/handlers/folders/folders.handler.js.map +1 -1
  511. package/dist/public-api/v1/handlers/insights/insights.handler.d.ts +5 -4
  512. package/dist/public-api/v1/handlers/insights/insights.handler.js +9 -5
  513. package/dist/public-api/v1/handlers/insights/insights.handler.js.map +1 -1
  514. package/dist/public-api/v1/handlers/projects/projects.handler.d.ts +28 -11
  515. package/dist/public-api/v1/handlers/projects/projects.handler.js +44 -75
  516. package/dist/public-api/v1/handlers/projects/projects.handler.js.map +1 -1
  517. package/dist/public-api/v1/handlers/source-control/source-control.handler.d.ts +5 -6
  518. package/dist/public-api/v1/handlers/source-control/source-control.handler.js +3 -2
  519. package/dist/public-api/v1/handlers/source-control/source-control.handler.js.map +1 -1
  520. package/dist/public-api/v1/handlers/tags/tags.handler.d.ts +9 -8
  521. package/dist/public-api/v1/handlers/tags/tags.handler.js +11 -8
  522. package/dist/public-api/v1/handlers/tags/tags.handler.js.map +1 -1
  523. package/dist/public-api/v1/handlers/users/users.handler.ee.d.ts +14 -11
  524. package/dist/public-api/v1/handlers/users/users.handler.ee.js +7 -8
  525. package/dist/public-api/v1/handlers/users/users.handler.ee.js.map +1 -1
  526. package/dist/public-api/v1/handlers/variables/variables.handler.d.ts +13 -7
  527. package/dist/public-api/v1/handlers/variables/variables.handler.js +5 -3
  528. package/dist/public-api/v1/handlers/variables/variables.handler.js.map +1 -1
  529. package/dist/public-api/v1/handlers/workflows/workflows.handler.d.ts +17 -49
  530. package/dist/public-api/v1/handlers/workflows/workflows.handler.js +27 -46
  531. package/dist/public-api/v1/handlers/workflows/workflows.handler.js.map +1 -1
  532. package/dist/public-api/v1/shared/handler.types.d.ts +7 -1
  533. package/dist/public-api/v1/shared/middlewares/global.middleware.d.ts +1 -2
  534. package/dist/public-api/v1/shared/middlewares/global.middleware.js +7 -6
  535. package/dist/public-api/v1/shared/middlewares/global.middleware.js.map +1 -1
  536. package/dist/scaling/constants.d.ts +2 -2
  537. package/dist/scaling/job-processor.js +2 -0
  538. package/dist/scaling/job-processor.js.map +1 -1
  539. package/dist/scaling/pubsub/pubsub.event-map.d.ts +9 -0
  540. package/dist/scaling/pubsub/pubsub.types.d.ts +3 -1
  541. package/dist/scaling/scaling.types.d.ts +1 -0
  542. package/dist/server.d.ts +2 -0
  543. package/dist/server.js +2 -0
  544. package/dist/server.js.map +1 -1
  545. package/dist/services/frontend.service.js +7 -14
  546. package/dist/services/frontend.service.js.map +1 -1
  547. package/dist/services/import.service.d.ts +9 -3
  548. package/dist/services/import.service.js +72 -5
  549. package/dist/services/import.service.js.map +1 -1
  550. package/dist/services/proxy-token-manager.js.map +1 -0
  551. package/dist/services/workflow-statistics.service.js +1 -0
  552. package/dist/services/workflow-statistics.service.js.map +1 -1
  553. package/dist/task-runners/task-broker/task-broker.service.d.ts +2 -0
  554. package/dist/task-runners/task-broker/task-broker.service.js +13 -1
  555. package/dist/task-runners/task-broker/task-broker.service.js.map +1 -1
  556. package/dist/utils/ttl-map.d.ts +17 -0
  557. package/dist/utils/ttl-map.js +80 -0
  558. package/dist/utils/ttl-map.js.map +1 -0
  559. package/dist/webhooks/test-webhooks.d.ts +3 -1
  560. package/dist/webhooks/test-webhooks.js +11 -3
  561. package/dist/webhooks/test-webhooks.js.map +1 -1
  562. package/dist/workflow-execute-additional-data.d.ts +2 -1
  563. package/dist/workflow-execute-additional-data.js +34 -0
  564. package/dist/workflow-execute-additional-data.js.map +1 -1
  565. package/dist/workflow-helpers.d.ts +1 -0
  566. package/dist/workflow-helpers.js +15 -0
  567. package/dist/workflow-helpers.js.map +1 -1
  568. package/dist/workflow-runner.js +2 -0
  569. package/dist/workflow-runner.js.map +1 -1
  570. package/dist/workflows/workflow-creation.service.js +1 -0
  571. package/dist/workflows/workflow-creation.service.js.map +1 -1
  572. package/dist/workflows/workflow.service.js +4 -0
  573. package/dist/workflows/workflow.service.js.map +1 -1
  574. package/package.json +40 -25
  575. package/dist/instance-settings-loader/loaders/sso.instance-settings-loader.js +0 -203
  576. package/dist/instance-settings-loader/loaders/sso.instance-settings-loader.js.map +0 -1
  577. package/dist/modules/instance-ai/proxy-token-manager.js.map +0 -1
  578. package/dist/modules/mcp/tools/workflow-builder/workflow-builder-tools.service.js.map +0 -1
  579. /package/dist/{modules/instance-ai → services}/proxy-token-manager.d.ts +0 -0
  580. /package/dist/{modules/instance-ai → services}/proxy-token-manager.js +0 -0
@@ -47,15 +47,18 @@ const api_types_1 = require("@n8n/api-types");
47
47
  const backend_common_1 = require("@n8n/backend-common");
48
48
  const config_1 = require("@n8n/config");
49
49
  const n8n_core_1 = require("n8n-core");
50
- const constants_1 = require("@n8n/constants");
50
+ const ssrf_protection_service_1 = require("../../services/ssrf/ssrf-protection.service");
51
51
  const db_1 = require("@n8n/db");
52
52
  const di_1 = require("@n8n/di");
53
+ const permissions_1 = require("@n8n/permissions");
53
54
  const url_service_1 = require("../../services/url.service");
54
55
  const instance_ai_1 = require("@n8n/instance-ai");
55
56
  const workflow_sdk_1 = require("@n8n/workflow-sdk");
56
57
  const nanoid_1 = require("nanoid");
58
+ const n8n_workflow_1 = require("n8n-workflow");
57
59
  const uuid_1 = require("uuid");
58
- const constants_2 = require("../../constants");
60
+ const constants_1 = require("../../constants");
61
+ const event_service_1 = require("../../events/event.service");
59
62
  const source_control_preferences_service_ee_1 = require("../../modules/source-control.ee/source-control-preferences.service.ee");
60
63
  const ai_service_1 = require("../../services/ai.service");
61
64
  const push_1 = require("../../push");
@@ -69,16 +72,80 @@ const typeorm_composite_store_1 = require("./storage/typeorm-composite-store");
69
72
  const db_snapshot_storage_1 = require("./storage/db-snapshot-storage");
70
73
  const db_iteration_log_storage_1 = require("./storage/db-iteration-log-storage");
71
74
  const compaction_service_1 = require("./compaction.service");
72
- const proxy_token_manager_1 = require("./proxy-token-manager");
75
+ const proxy_token_manager_1 = require("../../services/proxy-token-manager");
73
76
  const instance_ai_thread_repository_1 = require("./repositories/instance-ai-thread.repository");
74
77
  const trace_replay_state_1 = require("./trace-replay-state");
78
+ const liveness_1 = require("./liveness");
75
79
  function getErrorMessage(error) {
76
80
  return error instanceof Error ? error.message : String(error);
77
81
  }
82
+ const ORCHESTRATOR_AGENT_ID = 'agent-001';
83
+ function getUserFacingErrorMessage(error) {
84
+ if (error instanceof n8n_workflow_1.UserError) {
85
+ return error.message;
86
+ }
87
+ if (error instanceof n8n_workflow_1.OperationalError) {
88
+ return 'I hit an operational error before I could finish that response. Please try again.';
89
+ }
90
+ if (error instanceof n8n_workflow_1.UnexpectedError) {
91
+ return 'Something went wrong before I could finish that response. Please try again.';
92
+ }
93
+ return 'Something went wrong before I could finish that response. Please try again.';
94
+ }
95
+ function getBackgroundOutcomeResponseId(outcome) {
96
+ return `background-outcome:${outcome.id}`;
97
+ }
98
+ function createTerminalOutcomeAgentTree(outcome, responseId) {
99
+ return {
100
+ agentId: ORCHESTRATOR_AGENT_ID,
101
+ role: 'orchestrator',
102
+ status: outcome.status === 'cancelled'
103
+ ? 'cancelled'
104
+ : outcome.status === 'failed'
105
+ ? 'error'
106
+ : 'completed',
107
+ textContent: outcome.userFacingMessage,
108
+ reasoning: '',
109
+ toolCalls: [],
110
+ children: [],
111
+ timeline: [{ type: 'text', content: outcome.userFacingMessage, responseId }],
112
+ };
113
+ }
114
+ function appendTerminalOutcomeToAgentTree(tree, outcome, responseId) {
115
+ const text = outcome.userFacingMessage.trim();
116
+ if (!text)
117
+ return { tree, appended: false };
118
+ const alreadyInTimeline = tree.timeline.some((entry) => entry.type === 'text' && entry.responseId === responseId);
119
+ if (alreadyInTimeline) {
120
+ return { tree, appended: false };
121
+ }
122
+ return {
123
+ appended: true,
124
+ tree: {
125
+ ...tree,
126
+ textContent: tree.textContent ? `${tree.textContent}\n\n${outcome.userFacingMessage}` : text,
127
+ timeline: [
128
+ ...tree.timeline,
129
+ { type: 'text', content: outcome.userFacingMessage, responseId },
130
+ ],
131
+ },
132
+ };
133
+ }
78
134
  function createInertAbortSignal() {
79
135
  return new AbortController().signal;
80
136
  }
81
- const ORCHESTRATOR_AGENT_ID = 'agent-001';
137
+ function getAbortReason(signal) {
138
+ const reason = signal.reason;
139
+ if (typeof reason === 'object' &&
140
+ reason !== null &&
141
+ 'name' in reason &&
142
+ reason.name === 'AbortError') {
143
+ return 'user_cancelled';
144
+ }
145
+ if (reason instanceof Error)
146
+ return reason.message;
147
+ return typeof reason === 'string' ? reason : 'user_cancelled';
148
+ }
82
149
  const INSTANCE_AI_FEEDBACK_NAMESPACE = 'c5be4c87-5b6e-49ed-afe1-9c5c1f99a5c0';
83
150
  const MAX_CONCURRENT_BACKGROUND_TASKS_PER_THREAD = 5;
84
151
  function estimateTokens(text) {
@@ -176,7 +243,7 @@ function toConfirmationData(request) {
176
243
  }
177
244
  }
178
245
  let InstanceAiService = class InstanceAiService {
179
- constructor(logger, globalConfig, adapterService, eventBus, settingsService, compositeStore, compactionService, aiService, push, threadRepo, urlService, dbSnapshotStorage, dbIterationLogStorage, sourceControlPreferencesService, telemetry, userRepository, aiBuilderTemporaryWorkflowRepository, errorReporter) {
246
+ constructor(logger, globalConfig, adapterService, eventBus, settingsService, compositeStore, compactionService, aiService, push, threadRepo, urlService, dbSnapshotStorage, dbIterationLogStorage, sourceControlPreferencesService, telemetry, userRepository, aiBuilderTemporaryWorkflowRepository, errorReporter, ssrfProtectionConfig, ssrfProtectionService, eventService) {
180
247
  this.adapterService = adapterService;
181
248
  this.eventBus = eventBus;
182
249
  this.settingsService = settingsService;
@@ -193,7 +260,7 @@ let InstanceAiService = class InstanceAiService {
193
260
  this.userRepository = userRepository;
194
261
  this.aiBuilderTemporaryWorkflowRepository = aiBuilderTemporaryWorkflowRepository;
195
262
  this.errorReporter = errorReporter;
196
- this.mcpClientManager = new instance_ai_1.McpClientManager();
263
+ this.eventService = eventService;
197
264
  this.runState = new instance_ai_1.RunStateRegistry();
198
265
  this.backgroundTasks = new instance_ai_1.BackgroundTaskManager(MAX_CONCURRENT_BACKGROUND_TASKS_PER_THREAD);
199
266
  this.traceContextsByRunId = new Map();
@@ -203,35 +270,42 @@ let InstanceAiService = class InstanceAiService {
203
270
  this.threadPushRef = new Map();
204
271
  this.schedulerLocks = new Map();
205
272
  this.pendingCheckpointReentries = new Map();
273
+ this.pendingTerminalOutcomes = new Map();
206
274
  this.creditedThreads = new Set();
207
275
  this.traceReplay = new trace_replay_state_1.TraceReplayState();
208
276
  this.logger = logger.scoped('instance-ai');
209
277
  this.instanceAiConfig = globalConfig.instanceAi;
278
+ const livenessPolicyConfig = (0, instance_ai_1.createInstanceAiLivenessPolicyConfig)({
279
+ confirmationTimeoutMs: this.instanceAiConfig.confirmationTimeout,
280
+ });
281
+ this.liveness = new liveness_1.InstanceAiLivenessService({
282
+ policy: new instance_ai_1.InstanceAiLivenessPolicy(livenessPolicyConfig),
283
+ backgroundTaskIdleTimeoutMs: livenessPolicyConfig.backgroundTaskIdleTimeoutMs,
284
+ runState: this.runState,
285
+ backgroundTasks: this.backgroundTasks,
286
+ eventBus: this.eventBus,
287
+ logger: this.logger,
288
+ finalizeCancelledSuspendedRun: (suspended, reason) => {
289
+ void this.finalizeCancelledSuspendedRun(suspended, reason);
290
+ },
291
+ });
210
292
  this.builderSandboxSessions = new instance_ai_1.BuilderSandboxSessionRegistry(this.instanceAiConfig.builderSandboxTtlMs);
211
293
  this.defaultTimeZone = globalConfig.generic.timezone;
212
- const editorBaseUrl = globalConfig.editorBaseUrl || `http://localhost:${globalConfig.port}`;
213
294
  const restEndpoint = globalConfig.endpoints.rest;
214
- this.oauth2CallbackUrl = `${editorBaseUrl.replace(/\/$/, '')}/${restEndpoint}/oauth2-credential/callback`;
295
+ this.oauth2CallbackUrl = `${this.urlService.getInstanceBaseUrl()}/${restEndpoint}/oauth2-credential/callback`;
215
296
  this.webhookBaseUrl = `${this.urlService.getWebhookBaseUrl()}${globalConfig.endpoints.webhook}`;
216
- this.startConfirmationTimeoutSweep();
217
- }
218
- startConfirmationTimeoutSweep() {
219
- const timeoutMs = this.instanceAiConfig.confirmationTimeout;
220
- if (timeoutMs <= 0)
221
- return;
222
- this.confirmationTimeoutInterval = setInterval(() => {
223
- const { suspendedThreadIds, confirmationRequestIds } = this.runState.sweepTimedOut(timeoutMs);
224
- for (const threadId of suspendedThreadIds) {
225
- this.logger.debug('Auto-rejecting timed-out suspended run', { threadId });
226
- this.cancelRun(threadId);
227
- }
228
- for (const reqId of confirmationRequestIds) {
229
- this.logger.debug('Auto-rejecting timed-out sub-agent confirmation', {
230
- requestId: reqId,
297
+ this.formBaseUrl = `${this.urlService.getWebhookBaseUrl()}${globalConfig.endpoints.form}`;
298
+ this.mcpClientManager = new instance_ai_1.McpClientManager(ssrfProtectionConfig.enabled ? ssrfProtectionService : undefined);
299
+ this.eventService.on('instance-ai-settings-updated', ({ mcpSettingsChanged }) => {
300
+ if (!mcpSettingsChanged)
301
+ return;
302
+ this.mcpClientManager.disconnect().catch((error) => {
303
+ this.logger.warn('Failed to disconnect MCP clients after settings change', {
304
+ error: getErrorMessage(error),
231
305
  });
232
- this.runState.rejectPendingConfirmation(reqId);
233
- }
234
- }, constants_1.Time.minutes.toMilliseconds);
306
+ });
307
+ });
308
+ this.liveness.start();
235
309
  }
236
310
  getSandboxConfigFromEnv() {
237
311
  const { sandboxEnabled, sandboxProvider, daytonaApiUrl, daytonaApiKey, n8nSandboxServiceUrl, n8nSandboxServiceApiKey, sandboxImage, sandboxTimeout, } = this.instanceAiConfig;
@@ -253,7 +327,7 @@ let InstanceAiService = class InstanceAiService {
253
327
  daytonaApiUrl: daytonaApiUrl || undefined,
254
328
  daytonaApiKey: daytonaApiKey || undefined,
255
329
  image: sandboxImage || undefined,
256
- n8nVersion: constants_2.N8N_VERSION || undefined,
330
+ n8nVersion: constants_1.N8N_VERSION || undefined,
257
331
  timeout: sandboxTimeout,
258
332
  };
259
333
  }
@@ -382,7 +456,7 @@ let InstanceAiService = class InstanceAiService {
382
456
  for (const [k, v] of Object.entries(auth)) {
383
457
  headers.set(k, v);
384
458
  }
385
- for (const [k, v] of Object.entries((0, api_types_1.buildProxyHeaders)({ feature: 'instance-ai', n8nVersion: constants_2.N8N_VERSION }))) {
459
+ for (const [k, v] of Object.entries((0, api_types_1.buildProxyHeaders)({ feature: 'instance-ai', n8nVersion: constants_1.N8N_VERSION }))) {
386
460
  headers.set(k, v);
387
461
  }
388
462
  return await globalThis.fetch(input, { ...init, headers });
@@ -682,6 +756,7 @@ let InstanceAiService = class InstanceAiService {
682
756
  }
683
757
  }
684
758
  startRun(user, threadId, message, researchMode, attachments, timeZone, pushRef) {
759
+ this.liveness.clearThreadState(threadId);
685
760
  const { runId, abortController, messageGroupId } = this.runState.startRun({
686
761
  threadId,
687
762
  user,
@@ -708,7 +783,7 @@ let InstanceAiService = class InstanceAiService {
708
783
  getActiveRunId(threadId) {
709
784
  return this.runState.getActiveRunId(threadId);
710
785
  }
711
- cancelRun(threadId) {
786
+ cancelRun(threadId, reason = 'user_cancelled') {
712
787
  const cancelledTasks = this.backgroundTasks.cancelThread(threadId);
713
788
  const user = this.runState.getThreadUser(threadId);
714
789
  for (const task of cancelledTasks) {
@@ -717,9 +792,15 @@ let InstanceAiService = class InstanceAiService {
717
792
  type: 'agent-completed',
718
793
  runId: task.runId,
719
794
  agentId: task.agentId,
720
- payload: { role: task.role, result: '', error: 'Cancelled by user' },
795
+ payload: {
796
+ role: task.role,
797
+ result: '',
798
+ error: reason === liveness_1.INSTANCE_AI_RUN_TIMEOUT_REASON ? 'Timed out' : 'Cancelled by user',
799
+ },
800
+ });
801
+ void this.recordBackgroundTerminalOutcome(task).finally(() => {
802
+ void this.saveAgentTreeSnapshot(threadId, task.runId, this.dbSnapshotStorage, true, task.messageGroupId);
721
803
  });
722
- void this.saveAgentTreeSnapshot(threadId, task.runId, this.dbSnapshotStorage, true, task.messageGroupId);
723
804
  if (user) {
724
805
  void this.handlePlannedTaskSettlement(user, task, 'cancelled');
725
806
  }
@@ -727,12 +808,16 @@ let InstanceAiService = class InstanceAiService {
727
808
  void this.cancelAwaitingApprovalPlan(threadId);
728
809
  const { active, suspended } = this.runState.cancelThread(threadId);
729
810
  if (active) {
811
+ if (reason === liveness_1.INSTANCE_AI_RUN_TIMEOUT_REASON)
812
+ this.liveness.markRunTimedOut(active.runId);
730
813
  active.abortController.abort();
731
814
  return;
732
815
  }
733
816
  if (suspended) {
817
+ if (reason === liveness_1.INSTANCE_AI_RUN_TIMEOUT_REASON)
818
+ this.liveness.markRunTimedOut(suspended.runId);
734
819
  suspended.abortController.abort();
735
- void this.finalizeCancelledSuspendedRun(suspended);
820
+ void this.finalizeCancelledSuspendedRun(suspended, reason);
736
821
  }
737
822
  }
738
823
  sendCorrectionToTask(threadId, taskId, correction) {
@@ -749,12 +834,34 @@ let InstanceAiService = class InstanceAiService {
749
834
  agentId: task.agentId,
750
835
  payload: { role: task.role, result: '', error: 'Cancelled by user' },
751
836
  });
752
- void this.saveAgentTreeSnapshot(threadId, task.runId, this.dbSnapshotStorage, true, task.messageGroupId);
837
+ void this.recordBackgroundTerminalOutcome(task).finally(() => {
838
+ void this.saveAgentTreeSnapshot(threadId, task.runId, this.dbSnapshotStorage, true, task.messageGroupId);
839
+ });
753
840
  const user = this.runState.getThreadUser(threadId);
754
841
  if (user) {
755
842
  void this.handlePlannedTaskSettlement(user, task, 'cancelled');
756
843
  }
757
844
  }
845
+ async revalidateActiveUser(userId) {
846
+ try {
847
+ const user = await this.userRepository.findOne({
848
+ where: { id: userId },
849
+ relations: ['role'],
850
+ });
851
+ if (!user || user.disabled)
852
+ return null;
853
+ if (!(0, permissions_1.hasGlobalScope)(user, 'instanceAi:message'))
854
+ return null;
855
+ return user;
856
+ }
857
+ catch (error) {
858
+ this.logger.warn('Failed to revalidate user', {
859
+ userId,
860
+ error: getErrorMessage(error),
861
+ });
862
+ return null;
863
+ }
864
+ }
758
865
  cancelAllBackgroundTasks() {
759
866
  const cancelled = this.backgroundTasks.cancelAll();
760
867
  for (const task of cancelled) {
@@ -762,6 +869,111 @@ let InstanceAiService = class InstanceAiService {
762
869
  }
763
870
  return cancelled.length;
764
871
  }
872
+ async startStuckBackgroundTaskForTest(user, threadId) {
873
+ const messageId = `msg_${(0, nanoid_1.nanoid)()}`;
874
+ const messageText = 'I started a background workflow-builder task.';
875
+ const { runId, messageGroupId } = this.runState.startRun({ threadId, user });
876
+ if (!messageGroupId) {
877
+ throw new n8n_workflow_1.UnexpectedError('Failed to create message group for timeout simulation');
878
+ }
879
+ const taskId = `task_${(0, nanoid_1.nanoid)()}`;
880
+ const agentId = `agent_${(0, nanoid_1.nanoid)()}`;
881
+ this.eventBus.publish(threadId, {
882
+ type: 'run-start',
883
+ runId,
884
+ agentId: ORCHESTRATOR_AGENT_ID,
885
+ userId: user.id,
886
+ payload: { messageId, messageGroupId },
887
+ });
888
+ this.eventBus.publish(threadId, {
889
+ type: 'text-delta',
890
+ runId,
891
+ agentId: ORCHESTRATOR_AGENT_ID,
892
+ responseId: `test-background-start:${runId}`,
893
+ payload: { text: messageText },
894
+ });
895
+ this.eventBus.publish(threadId, {
896
+ type: 'agent-spawned',
897
+ runId,
898
+ agentId,
899
+ payload: {
900
+ parentId: ORCHESTRATOR_AGENT_ID,
901
+ role: 'workflow-builder',
902
+ tools: [],
903
+ taskId,
904
+ kind: 'builder',
905
+ title: 'Building workflow',
906
+ subtitle: 'Timeout simulation',
907
+ goal: 'Simulate a stuck background task timeout',
908
+ },
909
+ });
910
+ const memoryStorage = this.compositeStore.stores.memory;
911
+ await memoryStorage.saveMessages({
912
+ messages: [
913
+ {
914
+ id: messageId,
915
+ threadId,
916
+ resourceId: user.id,
917
+ role: 'assistant',
918
+ content: {
919
+ format: 2,
920
+ parts: [{ type: 'text', text: messageText }],
921
+ content: messageText,
922
+ },
923
+ createdAt: new Date(),
924
+ },
925
+ ],
926
+ });
927
+ const outcome = this.backgroundTasks.spawn({
928
+ taskId,
929
+ threadId,
930
+ runId,
931
+ role: 'workflow-builder',
932
+ agentId,
933
+ messageGroupId,
934
+ run: async (signal) => await new Promise((resolve) => {
935
+ signal.addEventListener('abort', () => resolve('aborted'), { once: true });
936
+ }),
937
+ onFailed: (task) => {
938
+ this.eventBus.publish(threadId, {
939
+ type: 'agent-completed',
940
+ runId,
941
+ agentId,
942
+ payload: {
943
+ role: task.role,
944
+ result: '',
945
+ error: task.error ?? 'Unknown error',
946
+ },
947
+ });
948
+ },
949
+ onSettled: async (task) => {
950
+ await this.recordBackgroundTerminalOutcome(task);
951
+ await this.saveAgentTreeSnapshot(threadId, runId, this.dbSnapshotStorage, true, messageGroupId);
952
+ },
953
+ });
954
+ if (outcome.status !== 'started') {
955
+ throw new n8n_workflow_1.UnexpectedError('Failed to start stuck background task simulation');
956
+ }
957
+ this.runState.clearActiveRun(threadId);
958
+ this.eventBus.publish(threadId, {
959
+ type: 'run-finish',
960
+ runId,
961
+ agentId: ORCHESTRATOR_AGENT_ID,
962
+ userId: user.id,
963
+ payload: { status: 'completed' },
964
+ });
965
+ return {
966
+ threadId,
967
+ runId,
968
+ messageGroupId,
969
+ taskId,
970
+ agentId,
971
+ timeoutAt: outcome.task.lastActivityAt + this.liveness.backgroundTaskIdleTimeoutMs + 1,
972
+ };
973
+ }
974
+ async runLivenessSweepForTest(now) {
975
+ await this.liveness.sweepTimedOutWork(now);
976
+ }
765
977
  loadTraceEvents(slug, events) {
766
978
  this.traceReplay.loadEvents(slug, events);
767
979
  }
@@ -780,6 +992,9 @@ let InstanceAiService = class InstanceAiService {
780
992
  generatePairingToken(userId) {
781
993
  return this.gatewayRegistry.generatePairingToken(userId);
782
994
  }
995
+ getGatewayApiKeyExpiresAt(userId, key) {
996
+ return this.gatewayRegistry.getApiKeyExpiresAt(userId, key);
997
+ }
783
998
  getPairingToken(userId) {
784
999
  return this.gatewayRegistry.getPairingToken(userId);
785
1000
  }
@@ -852,6 +1067,7 @@ let InstanceAiService = class InstanceAiService {
852
1067
  });
853
1068
  this.creditedThreads.delete(threadId);
854
1069
  this.schedulerLocks.delete(threadId);
1070
+ this.liveness.clearThreadState(threadId);
855
1071
  this.domainAccessTrackersByThread.delete(threadId);
856
1072
  this.threadPushRef.delete(threadId);
857
1073
  this.deleteTraceContextsForThread(threadId);
@@ -861,10 +1077,7 @@ let InstanceAiService = class InstanceAiService {
861
1077
  this.eventBus.clearThread(threadId);
862
1078
  }
863
1079
  async shutdown() {
864
- if (this.confirmationTimeoutInterval) {
865
- clearInterval(this.confirmationTimeoutInterval);
866
- this.confirmationTimeoutInterval = undefined;
867
- }
1080
+ this.liveness.shutdown();
868
1081
  const { activeRuns, suspendedRuns } = this.runState.shutdown();
869
1082
  for (const run of activeRuns) {
870
1083
  run.abortController.abort();
@@ -990,6 +1203,290 @@ let InstanceAiService = class InstanceAiService {
990
1203
  const plannedTaskService = new instance_ai_1.PlannedTaskCoordinator(plannedTaskStorage);
991
1204
  return { memory, taskStorage, plannedTaskService };
992
1205
  }
1206
+ evaluateTerminalResponse(threadId, runId, status, options = {}) {
1207
+ const guard = new instance_ai_1.InstanceAiTerminalResponseGuard({
1208
+ runId,
1209
+ rootAgentId: ORCHESTRATOR_AGENT_ID,
1210
+ messageGroupId: options.messageGroupId,
1211
+ correlationId: options.correlationId,
1212
+ });
1213
+ const decision = guard.evaluateTerminal(this.getTerminalGuardEvents(threadId, runId, options.messageGroupId), status, {
1214
+ workSummary: options.workSummary,
1215
+ errorMessage: options.errorMessage,
1216
+ });
1217
+ this.handleTerminalResponseDecision(threadId, runId, decision, options.messageGroupId);
1218
+ return decision;
1219
+ }
1220
+ evaluateWaitingResponse(threadId, runId, confirmationEvent, options = {}) {
1221
+ const guard = new instance_ai_1.InstanceAiTerminalResponseGuard({
1222
+ runId,
1223
+ rootAgentId: ORCHESTRATOR_AGENT_ID,
1224
+ messageGroupId: options.messageGroupId,
1225
+ correlationId: options.correlationId,
1226
+ });
1227
+ const decision = guard.evaluateWaiting(this.getTerminalGuardEvents(threadId, runId, options.messageGroupId), confirmationEvent);
1228
+ this.handleTerminalResponseDecision(threadId, runId, decision, options.messageGroupId);
1229
+ return decision;
1230
+ }
1231
+ getTerminalGuardEvents(threadId, runId, messageGroupId) {
1232
+ if (!messageGroupId)
1233
+ return this.eventBus.getEventsForRun(threadId, runId);
1234
+ const groupRunIds = this.getRunIdsForMessageGroup(messageGroupId);
1235
+ return groupRunIds.length > 0
1236
+ ? this.eventBus.getEventsForRuns(threadId, groupRunIds)
1237
+ : this.eventBus.getEventsForRun(threadId, runId);
1238
+ }
1239
+ handleTerminalResponseDecision(threadId, runId, decision, messageGroupId) {
1240
+ this.telemetry.track('instance_ai_terminal_response_decision', {
1241
+ thread_id: threadId,
1242
+ run_id: runId,
1243
+ message_group_id: messageGroupId,
1244
+ source: 'terminal_guard',
1245
+ status: decision.status,
1246
+ action: decision.action,
1247
+ reason: decision.reason,
1248
+ visibility_source: decision.visibilitySource,
1249
+ });
1250
+ if (decision.reason === 'completed-after-error') {
1251
+ this.logger.warn('completed_after_error_event', {
1252
+ threadId,
1253
+ runId,
1254
+ messageGroupId,
1255
+ });
1256
+ }
1257
+ if (decision.reason === 'confirmation-invalid') {
1258
+ this.logger.warn('invalid_confirmation_payload', {
1259
+ threadId,
1260
+ runId,
1261
+ messageGroupId,
1262
+ });
1263
+ }
1264
+ if (decision.action === 'emit' && decision.event) {
1265
+ this.eventBus.publish(threadId, decision.event);
1266
+ }
1267
+ }
1268
+ createTerminalOutcomeStorage() {
1269
+ this.terminalOutcomeStorage ??= new instance_ai_1.TerminalOutcomeStorage((0, instance_ai_1.createMemory)(this.createMemoryConfig()));
1270
+ return this.terminalOutcomeStorage;
1271
+ }
1272
+ async finishInvalidConfirmationRun(args) {
1273
+ this.runState.cancelThread(args.threadId);
1274
+ args.abortController.abort();
1275
+ await this.finalizeRunTracing(args.runId, args.tracing, {
1276
+ status: 'error',
1277
+ reason: 'invalid_confirmation_payload',
1278
+ });
1279
+ this.publishRunFinish(args.threadId, args.runId, 'errored', 'I need your input to continue, but I could not display the prompt. Please try again.');
1280
+ await this.saveAgentTreeSnapshot(args.threadId, args.runId, args.snapshotStorage);
1281
+ return {
1282
+ status: 'error',
1283
+ reason: 'invalid_confirmation_payload',
1284
+ metadata: { completion_source: 'orchestrator' },
1285
+ };
1286
+ }
1287
+ buildBackgroundTerminalOutcome(task) {
1288
+ const status = task.status === 'failed' ? 'failed' : task.status === 'cancelled' ? 'cancelled' : 'completed';
1289
+ const userFacingMessage = status === 'completed'
1290
+ ? `The background ${task.role} task finished.`
1291
+ : status === 'cancelled'
1292
+ ? `The background ${task.role} task was cancelled.`
1293
+ : `The background ${task.role} task failed before I could complete that part.`;
1294
+ return {
1295
+ id: `${task.messageGroupId ?? task.runId}:${task.taskId}:${status}`,
1296
+ threadId: task.threadId,
1297
+ runId: task.runId,
1298
+ messageGroupId: task.messageGroupId,
1299
+ correlationId: task.messageGroupId,
1300
+ taskId: task.taskId,
1301
+ agentId: task.agentId,
1302
+ status,
1303
+ userFacingMessage,
1304
+ createdAt: new Date().toISOString(),
1305
+ };
1306
+ }
1307
+ async replayUndeliveredTerminalOutcomes(threadId, options = {}) {
1308
+ const storage = this.createTerminalOutcomeStorage();
1309
+ const persistedOutcomes = await storage.getUndelivered(threadId).catch((error) => {
1310
+ this.logger.warn('Failed to load undelivered Instance AI terminal outcomes', {
1311
+ threadId,
1312
+ error: getErrorMessage(error),
1313
+ });
1314
+ return [];
1315
+ });
1316
+ const inMemoryOutcomes = [...this.pendingTerminalOutcomes.values()].filter((outcome) => outcome.threadId === threadId);
1317
+ const outcomes = new Map();
1318
+ for (const outcome of [...persistedOutcomes, ...inMemoryOutcomes]) {
1319
+ outcomes.set(outcome.id, outcome);
1320
+ }
1321
+ const persistedOutcomeIds = new Set(persistedOutcomes.map((outcome) => outcome.id));
1322
+ const delivery = options.delivery ?? 'snapshot';
1323
+ for (const outcome of outcomes.values()) {
1324
+ const responseId = getBackgroundOutcomeResponseId(outcome);
1325
+ let snapshotDelivered = false;
1326
+ try {
1327
+ snapshotDelivered = await this.persistTerminalOutcomeLineToSnapshot(outcome, responseId);
1328
+ }
1329
+ catch (error) {
1330
+ this.logger.warn('Failed to replay Instance AI terminal outcome', {
1331
+ threadId,
1332
+ runId: outcome.runId,
1333
+ taskId: outcome.taskId,
1334
+ error: getErrorMessage(error),
1335
+ });
1336
+ if (delivery === 'event') {
1337
+ const published = this.publishTerminalOutcomeLine(outcome, responseId);
1338
+ this.telemetry.track('instance_ai_terminal_response_decision', {
1339
+ thread_id: threadId,
1340
+ run_id: outcome.runId,
1341
+ message_group_id: outcome.messageGroupId,
1342
+ task_id: outcome.taskId,
1343
+ source: 'terminal_outcome_replay',
1344
+ status: outcome.status,
1345
+ action: published ? 'replay_event' : 'already-emitted',
1346
+ visibility_source: 'background-outcome',
1347
+ });
1348
+ }
1349
+ continue;
1350
+ }
1351
+ if (!snapshotDelivered)
1352
+ continue;
1353
+ let action = 'replay_snapshot';
1354
+ if (delivery === 'event') {
1355
+ const published = this.publishTerminalOutcomeLine(outcome, responseId);
1356
+ action = published ? 'replay_event' : 'already-emitted';
1357
+ }
1358
+ if (persistedOutcomeIds.has(outcome.id)) {
1359
+ await storage
1360
+ .markDelivered(threadId, outcome.id, new Date().toISOString())
1361
+ .catch((error) => {
1362
+ this.logger.warn('Failed to mark Instance AI terminal outcome as delivered', {
1363
+ threadId,
1364
+ runId: outcome.runId,
1365
+ taskId: outcome.taskId,
1366
+ error: getErrorMessage(error),
1367
+ });
1368
+ });
1369
+ }
1370
+ this.pendingTerminalOutcomes.delete(outcome.id);
1371
+ this.telemetry.track('instance_ai_terminal_response_decision', {
1372
+ thread_id: threadId,
1373
+ run_id: outcome.runId,
1374
+ message_group_id: outcome.messageGroupId,
1375
+ task_id: outcome.taskId,
1376
+ source: 'terminal_outcome_replay',
1377
+ status: outcome.status,
1378
+ action,
1379
+ visibility_source: 'background-outcome',
1380
+ });
1381
+ }
1382
+ }
1383
+ async persistTerminalOutcomeLineToSnapshot(outcome, responseId) {
1384
+ const snapshot = await this.dbSnapshotStorage.getLatest(outcome.threadId, {
1385
+ messageGroupId: outcome.messageGroupId,
1386
+ runId: outcome.runId,
1387
+ });
1388
+ if (!snapshot) {
1389
+ await this.dbSnapshotStorage.save(outcome.threadId, createTerminalOutcomeAgentTree(outcome, responseId), outcome.runId, {
1390
+ messageGroupId: outcome.messageGroupId,
1391
+ runIds: [outcome.runId],
1392
+ });
1393
+ return true;
1394
+ }
1395
+ const { tree } = appendTerminalOutcomeToAgentTree(snapshot.tree, outcome, responseId);
1396
+ const runIds = new Set(snapshot.runIds ?? [snapshot.runId]);
1397
+ runIds.add(outcome.runId);
1398
+ await this.dbSnapshotStorage.updateLast(outcome.threadId, tree, snapshot.runId, {
1399
+ messageGroupId: snapshot.messageGroupId ?? outcome.messageGroupId,
1400
+ runIds: [...runIds],
1401
+ langsmithRunId: snapshot.langsmithRunId,
1402
+ langsmithTraceId: snapshot.langsmithTraceId,
1403
+ });
1404
+ return true;
1405
+ }
1406
+ publishTerminalOutcomeLine(outcome, responseId) {
1407
+ const alreadyPublished = this.eventBus
1408
+ .getEventsForRun(outcome.threadId, outcome.runId)
1409
+ .some((event) => event.responseId === responseId);
1410
+ if (alreadyPublished)
1411
+ return false;
1412
+ this.eventBus.publish(outcome.threadId, {
1413
+ type: 'text-delta',
1414
+ runId: outcome.runId,
1415
+ agentId: ORCHESTRATOR_AGENT_ID,
1416
+ responseId,
1417
+ payload: { text: outcome.userFacingMessage },
1418
+ });
1419
+ return true;
1420
+ }
1421
+ async recordBackgroundTerminalOutcome(task) {
1422
+ const outcome = this.buildBackgroundTerminalOutcome(task);
1423
+ let persisted = false;
1424
+ try {
1425
+ await this.createTerminalOutcomeStorage().upsert(task.threadId, outcome);
1426
+ persisted = true;
1427
+ }
1428
+ catch (error) {
1429
+ this.pendingTerminalOutcomes.set(outcome.id, outcome);
1430
+ this.logger.warn('Failed to persist Instance AI terminal outcome', {
1431
+ threadId: task.threadId,
1432
+ runId: task.runId,
1433
+ taskId: task.taskId,
1434
+ error: getErrorMessage(error),
1435
+ });
1436
+ this.telemetry.track('instance_ai_terminal_outcome_persistence_failure', {
1437
+ thread_id: task.threadId,
1438
+ run_id: task.runId,
1439
+ task_id: task.taskId,
1440
+ status: outcome.status,
1441
+ phase: 'metadata',
1442
+ });
1443
+ }
1444
+ const responseId = getBackgroundOutcomeResponseId(outcome);
1445
+ const published = this.publishTerminalOutcomeLine(outcome, responseId);
1446
+ this.telemetry.track('instance_ai_terminal_response_decision', {
1447
+ thread_id: task.threadId,
1448
+ run_id: task.runId,
1449
+ message_group_id: task.messageGroupId,
1450
+ task_id: task.taskId,
1451
+ source: 'background_outcome',
1452
+ status: outcome.status,
1453
+ action: published ? 'emit' : 'already-emitted',
1454
+ visibility_source: 'background-outcome',
1455
+ });
1456
+ let snapshotDelivered = false;
1457
+ try {
1458
+ snapshotDelivered = await this.persistTerminalOutcomeLineToSnapshot(outcome, responseId);
1459
+ }
1460
+ catch (error) {
1461
+ this.logger.warn('Failed to persist Instance AI terminal outcome line to snapshot', {
1462
+ threadId: task.threadId,
1463
+ runId: task.runId,
1464
+ taskId: task.taskId,
1465
+ error: getErrorMessage(error),
1466
+ });
1467
+ this.telemetry.track('instance_ai_terminal_outcome_persistence_failure', {
1468
+ thread_id: task.threadId,
1469
+ run_id: task.runId,
1470
+ task_id: task.taskId,
1471
+ status: outcome.status,
1472
+ phase: 'snapshot',
1473
+ });
1474
+ }
1475
+ if (!persisted || !snapshotDelivered)
1476
+ return;
1477
+ try {
1478
+ await this.createTerminalOutcomeStorage().markDelivered(task.threadId, outcome.id, new Date().toISOString());
1479
+ this.pendingTerminalOutcomes.delete(outcome.id);
1480
+ }
1481
+ catch (error) {
1482
+ this.logger.warn('Failed to mark Instance AI terminal outcome as delivered', {
1483
+ threadId: task.threadId,
1484
+ runId: task.runId,
1485
+ taskId: task.taskId,
1486
+ error: getErrorMessage(error),
1487
+ });
1488
+ }
1489
+ }
993
1490
  async syncPlannedTasksToUi(threadId, graph) {
994
1491
  const { taskStorage } = await this.createPlannedTaskState();
995
1492
  const tasks = this.projectPlannedTaskList(graph);
@@ -1024,7 +1521,8 @@ let InstanceAiService = class InstanceAiService {
1024
1521
  }
1025
1522
  }
1026
1523
  async createExecutionEnvironment(user, threadId, runId, abortSignal, researchMode, messageGroupId, pushRef) {
1027
- const localGatewayDisabled = await this.settingsService.isLocalGatewayDisabledForUser(user.id);
1524
+ const localGatewayDisabledGlobally = this.settingsService.getAdminSettings().localGatewayDisabled;
1525
+ const localGatewayDisabledForUser = await this.settingsService.isLocalGatewayDisabledForUser(user.id);
1028
1526
  const userGateway = this.gatewayRegistry.findGateway(user.id);
1029
1527
  let searchProxyConfig;
1030
1528
  let tracingProxyConfig;
@@ -1039,7 +1537,7 @@ let InstanceAiService = class InstanceAiService {
1039
1537
  tokenManager = manager;
1040
1538
  const featureHeaders = (0, api_types_1.buildProxyHeaders)({
1041
1539
  feature: 'instance-ai',
1042
- n8nVersion: constants_2.N8N_VERSION,
1540
+ n8nVersion: constants_1.N8N_VERSION,
1043
1541
  });
1044
1542
  searchProxyConfig = {
1045
1543
  apiUrl: proxyBaseUrl + '/brave-search',
@@ -1061,7 +1559,7 @@ let InstanceAiService = class InstanceAiService {
1061
1559
  pushRef,
1062
1560
  threadId,
1063
1561
  });
1064
- if (!localGatewayDisabled && userGateway?.isConnected) {
1562
+ if (!localGatewayDisabledForUser && userGateway?.isConnected) {
1065
1563
  context.localMcpServer = userGateway;
1066
1564
  }
1067
1565
  context.permissions = this.settingsService.getPermissions();
@@ -1076,16 +1574,21 @@ let InstanceAiService = class InstanceAiService {
1076
1574
  }
1077
1575
  context.domainAccessTracker = domainTracker;
1078
1576
  context.runId = runId;
1079
- if (localGatewayDisabled) {
1080
- context.localGatewayStatus = { status: 'disabled' };
1577
+ if (localGatewayDisabledGlobally) {
1578
+ context.localGatewayStatus = { status: 'disabledGlobally' };
1081
1579
  }
1082
- else if (userGateway?.isConnected) {
1083
- context.localGatewayStatus = { status: 'connected' };
1580
+ else if (!localGatewayDisabledForUser && userGateway?.isConnected) {
1581
+ context.localGatewayStatus = {
1582
+ status: 'connected',
1583
+ capabilities: userGateway
1584
+ .getStatus()
1585
+ .toolCategories.filter(({ enabled }) => enabled)
1586
+ .map(({ name }) => name),
1587
+ };
1084
1588
  }
1085
1589
  else {
1086
1590
  context.localGatewayStatus = {
1087
- status: 'disconnected',
1088
- capabilities: ['filesystem', 'browser'],
1591
+ status: localGatewayDisabledForUser ? 'disabled' : 'disconnected',
1089
1592
  };
1090
1593
  }
1091
1594
  const modelId = proxyBaseUrl && tokenManager
@@ -1131,7 +1634,9 @@ let InstanceAiService = class InstanceAiService {
1131
1634
  localMcpServer: context.localMcpServer,
1132
1635
  oauth2CallbackUrl: this.oauth2CallbackUrl,
1133
1636
  webhookBaseUrl: this.webhookBaseUrl,
1637
+ formBaseUrl: this.formBaseUrl,
1134
1638
  waitForConfirmation: async (requestId) => {
1639
+ this.runState.touchActiveRun(threadId);
1135
1640
  return await new Promise((resolve) => {
1136
1641
  this.runState.registerPendingConfirmation(requestId, {
1137
1642
  resolve,
@@ -1146,6 +1651,8 @@ let InstanceAiService = class InstanceAiService {
1146
1651
  },
1147
1652
  cancelBackgroundTask: async (taskId) => this.cancelBackgroundTask(threadId, taskId),
1148
1653
  spawnBackgroundTask: (opts) => this.spawnBackgroundTask(runId, opts, snapshotStorage, messageGroupId),
1654
+ touchRun: () => this.runState.touchActiveRun(threadId),
1655
+ touchBackgroundTask: (taskId) => this.backgroundTasks.touchTask(threadId, taskId),
1149
1656
  plannedTaskService,
1150
1657
  schedulePlannedTasks: async () => await this.schedulePlannedTasks(user, threadId),
1151
1658
  iterationLog,
@@ -1313,6 +1820,16 @@ let InstanceAiService = class InstanceAiService {
1313
1820
  await current;
1314
1821
  }
1315
1822
  async doSchedulePlannedTasks(user, threadId) {
1823
+ const revalidated = await this.revalidateActiveUser(user.id);
1824
+ if (!revalidated) {
1825
+ this.logger.warn('Cancelling run: user no longer authorized for AI Assistant', {
1826
+ userId: user.id,
1827
+ threadId,
1828
+ });
1829
+ this.cancelRun(threadId);
1830
+ return;
1831
+ }
1832
+ const activeUser = revalidated;
1316
1833
  const { plannedTaskService } = await this.createPlannedTaskState();
1317
1834
  const graph = await plannedTaskService.getGraph(threadId);
1318
1835
  if (!graph)
@@ -1325,7 +1842,7 @@ let InstanceAiService = class InstanceAiService {
1325
1842
  return;
1326
1843
  if (action.type === 'replan') {
1327
1844
  await this.syncPlannedTasksToUi(threadId, action.graph);
1328
- const startedRunId = await this.startInternalFollowUpRun(user, threadId, this.buildPlannedTaskFollowUpMessage('replan', action.graph, {
1845
+ const startedRunId = await this.startInternalFollowUpRun(activeUser, threadId, this.buildPlannedTaskFollowUpMessage('replan', action.graph, {
1329
1846
  failedTask: action.failedTask,
1330
1847
  }), this.runState.getThreadResearchMode(threadId), action.graph.messageGroupId, true);
1331
1848
  if (!startedRunId) {
@@ -1335,7 +1852,7 @@ let InstanceAiService = class InstanceAiService {
1335
1852
  }
1336
1853
  if (action.type === 'synthesize') {
1337
1854
  await this.syncPlannedTasksToUi(threadId, action.graph);
1338
- const startedRunId = await this.startInternalFollowUpRun(user, threadId, this.buildPlannedTaskFollowUpMessage('synthesize', action.graph), this.runState.getThreadResearchMode(threadId), action.graph.messageGroupId);
1855
+ const startedRunId = await this.startInternalFollowUpRun(activeUser, threadId, this.buildPlannedTaskFollowUpMessage('synthesize', action.graph), this.runState.getThreadResearchMode(threadId), action.graph.messageGroupId);
1339
1856
  if (!startedRunId) {
1340
1857
  await plannedTaskService.revertToActive(threadId);
1341
1858
  }
@@ -1352,7 +1869,7 @@ let InstanceAiService = class InstanceAiService {
1352
1869
  const graphAfterMark = (await plannedTaskService.getGraph(threadId)) ?? action.graph;
1353
1870
  await this.syncPlannedTasksToUi(threadId, graphAfterMark);
1354
1871
  const checkpointRecord = graphAfterMark.tasks.find((t) => t.id === checkpoint.id) ?? checkpoint;
1355
- const startedRunId = await this.startInternalFollowUpRun(user, threadId, this.buildPlannedTaskFollowUpMessage('checkpoint', graphAfterMark, {
1872
+ const startedRunId = await this.startInternalFollowUpRun(activeUser, threadId, this.buildPlannedTaskFollowUpMessage('checkpoint', graphAfterMark, {
1356
1873
  checkpoint: checkpointRecord,
1357
1874
  }), this.runState.getThreadResearchMode(threadId), action.graph.messageGroupId, false, { isCheckpointFollowUp: true, checkpointTaskId: checkpoint.id });
1358
1875
  if (!startedRunId) {
@@ -1361,12 +1878,12 @@ let InstanceAiService = class InstanceAiService {
1361
1878
  }
1362
1879
  return;
1363
1880
  }
1364
- const environment = await this.createExecutionEnvironment(user, threadId, action.graph.planRunId, createInertAbortSignal(), this.runState.getThreadResearchMode(threadId), action.graph.messageGroupId);
1881
+ const environment = await this.createExecutionEnvironment(activeUser, threadId, action.graph.planRunId, createInertAbortSignal(), this.runState.getThreadResearchMode(threadId), action.graph.messageGroupId, this.threadPushRef.get(threadId));
1365
1882
  environment.orchestrationContext.tracing = this.getTraceContext(action.graph.planRunId);
1366
1883
  for (const task of action.tasks) {
1367
1884
  await this.dispatchPlannedTask(task, environment.orchestrationContext, action.graph);
1368
1885
  }
1369
- await this.doSchedulePlannedTasks(user, threadId);
1886
+ await this.doSchedulePlannedTasks(activeUser, threadId);
1370
1887
  }
1371
1888
  async executeRun(user, threadId, runId, message, abortController, researchMode, attachments, messageGroupId, timeZone, isReplanFollowUp = false, checkpoint) {
1372
1889
  const signal = abortController.signal;
@@ -1374,8 +1891,10 @@ let InstanceAiService = class InstanceAiService {
1374
1891
  let tracing;
1375
1892
  let messageTraceFinalization;
1376
1893
  let aiCreatedWorkflowIds;
1894
+ let activeSnapshotStorage;
1895
+ let messageId = '';
1377
1896
  try {
1378
- const messageId = (0, nanoid_1.nanoid)();
1897
+ messageId = (0, nanoid_1.nanoid)();
1379
1898
  this.eventBus.publish(threadId, {
1380
1899
  type: 'run-start',
1381
1900
  runId,
@@ -1384,6 +1903,10 @@ let InstanceAiService = class InstanceAiService {
1384
1903
  payload: { messageId, messageGroupId },
1385
1904
  });
1386
1905
  if (signal.aborted) {
1906
+ this.evaluateTerminalResponse(threadId, runId, 'cancelled', {
1907
+ messageGroupId,
1908
+ correlationId: messageId,
1909
+ });
1387
1910
  this.eventBus.publish(threadId, {
1388
1911
  type: 'run-finish',
1389
1912
  runId,
@@ -1394,7 +1917,9 @@ let InstanceAiService = class InstanceAiService {
1394
1917
  }
1395
1918
  const mcpServers = this.parseMcpServers(this.instanceAiConfig.mcpServers);
1396
1919
  const executionPushRef = this.threadPushRef.get(threadId);
1397
- const { context, memory, taskStorage, snapshotStorage, modelId, orchestrationContext } = await this.createExecutionEnvironment(user, threadId, runId, signal, researchMode, messageGroupId, executionPushRef);
1920
+ const environment = await this.createExecutionEnvironment(user, threadId, runId, signal, researchMode, messageGroupId, executionPushRef);
1921
+ activeSnapshotStorage = environment.snapshotStorage;
1922
+ const { context, memory, taskStorage, snapshotStorage, modelId, orchestrationContext } = environment;
1398
1923
  aiCreatedWorkflowIds = context.aiCreatedWorkflowIds ??= new Set();
1399
1924
  orchestrationContext.currentUserMessage = message;
1400
1925
  orchestrationContext.isReplanFollowUp = isReplanFollowUp;
@@ -1433,6 +1958,8 @@ let InstanceAiService = class InstanceAiService {
1433
1958
  userId: user.id,
1434
1959
  modelId,
1435
1960
  input: traceInput,
1961
+ n8nVersion: constants_1.N8N_VERSION,
1962
+ workflowSdkVersion: constants_1.WORKFLOW_SDK_VERSION,
1436
1963
  proxyConfig: orchestrationContext.tracingProxyConfig,
1437
1964
  });
1438
1965
  if (!tracing && process.env.E2E_TESTS === 'true') {
@@ -1466,18 +1993,19 @@ let InstanceAiService = class InstanceAiService {
1466
1993
  context,
1467
1994
  orchestrationContext,
1468
1995
  mcpServers,
1996
+ mcpManager: this.mcpClientManager,
1469
1997
  memoryConfig,
1470
1998
  memory,
1471
1999
  disableDeferredTools: true,
1472
2000
  timeZone: timeZone ?? this.defaultTimeZone,
1473
2001
  });
1474
2002
  const enrichedMessage = await this.buildMessageWithRunningTasks(threadId, message);
1475
- let nonStructuredAttachments = [];
2003
+ let multimodalAttachments = [];
1476
2004
  let attachmentManifest = '';
1477
2005
  let hasParseableAttachment = false;
1478
2006
  if (attachments && attachments.length > 0) {
1479
2007
  const classifiedAttachments = (0, instance_ai_1.classifyAttachments)(attachments);
1480
- nonStructuredAttachments = attachments.filter((attachment) => !(0, instance_ai_1.isStructuredAttachment)(attachment));
2008
+ multimodalAttachments = attachments.filter((attachment) => !(0, instance_ai_1.isParseableAttachment)(attachment) && attachment.mimeType.startsWith('image/'));
1481
2009
  hasParseableAttachment = classifiedAttachments.some((attachment) => attachment.parseable);
1482
2010
  attachmentManifest = (0, instance_ai_1.buildAttachmentManifest)(classifiedAttachments);
1483
2011
  }
@@ -1553,13 +2081,13 @@ let InstanceAiService = class InstanceAiService {
1553
2081
  const fullMessage = conversationSummary
1554
2082
  ? `${conversationSummary}\n\n${messageWithoutSummary}`
1555
2083
  : messageWithoutSummary;
1556
- if (nonStructuredAttachments.length > 0) {
2084
+ if (multimodalAttachments.length > 0) {
1557
2085
  streamInput = [
1558
2086
  {
1559
2087
  role: 'user',
1560
2088
  content: [
1561
2089
  { type: 'text', text: fullMessage },
1562
- ...nonStructuredAttachments.map((attachment) => ({
2090
+ ...multimodalAttachments.map((attachment) => ({
1563
2091
  type: 'file',
1564
2092
  data: attachment.data,
1565
2093
  mimeType: attachment.mimeType,
@@ -1577,7 +2105,7 @@ let InstanceAiService = class InstanceAiService {
1577
2105
  : {
1578
2106
  fullMessage,
1579
2107
  attachmentCount: attachments?.length ?? 0,
1580
- nonStructuredAttachmentCount: nonStructuredAttachments.length,
2108
+ multimodalAttachmentCount: multimodalAttachments.length,
1581
2109
  };
1582
2110
  await tracing.finishRun(promptBuildRun, {
1583
2111
  outputs: traceOutput,
@@ -1612,6 +2140,7 @@ let InstanceAiService = class InstanceAiService {
1612
2140
  signal,
1613
2141
  eventBus: this.eventBus,
1614
2142
  logger: this.logger,
2143
+ onActivity: () => this.runState.touchActiveRun(threadId),
1615
2144
  });
1616
2145
  })
1617
2146
  : await (0, instance_ai_1.streamAgentRun)(agent, streamInput, {
@@ -1631,6 +2160,7 @@ let InstanceAiService = class InstanceAiService {
1631
2160
  signal,
1632
2161
  eventBus: this.eventBus,
1633
2162
  logger: this.logger,
2163
+ onActivity: () => this.runState.touchActiveRun(threadId),
1634
2164
  });
1635
2165
  mastraRunId = result.mastraRunId;
1636
2166
  if (result.status === 'suspended') {
@@ -1658,6 +2188,20 @@ let InstanceAiService = class InstanceAiService {
1658
2188
  is_intermediate: true,
1659
2189
  });
1660
2190
  }
2191
+ const waitingDecision = this.evaluateWaitingResponse(threadId, runId, result.confirmationEvent, {
2192
+ messageGroupId,
2193
+ correlationId: messageId,
2194
+ });
2195
+ if (waitingDecision?.reason === 'confirmation-invalid') {
2196
+ messageTraceFinalization = await this.finishInvalidConfirmationRun({
2197
+ threadId,
2198
+ runId,
2199
+ abortController,
2200
+ snapshotStorage,
2201
+ tracing,
2202
+ });
2203
+ return;
2204
+ }
1661
2205
  if (result.confirmationEvent) {
1662
2206
  this.trackConfirmationRequest(threadId, result.confirmationEvent);
1663
2207
  this.eventBus.publish(threadId, result.confirmationEvent);
@@ -1666,6 +2210,11 @@ let InstanceAiService = class InstanceAiService {
1666
2210
  return;
1667
2211
  }
1668
2212
  const outputText = await (result.text ?? Promise.resolve(''));
2213
+ this.evaluateTerminalResponse(threadId, runId, result.status, {
2214
+ messageGroupId,
2215
+ correlationId: messageId,
2216
+ workSummary: result.workSummary,
2217
+ });
1669
2218
  const finalStatus = result.status === 'errored' ? 'error' : result.status;
1670
2219
  await this.finalizeRunTracing(runId, tracing, {
1671
2220
  status: finalStatus,
@@ -1697,25 +2246,44 @@ let InstanceAiService = class InstanceAiService {
1697
2246
  }
1698
2247
  catch (error) {
1699
2248
  if (signal.aborted) {
2249
+ const cancellationReason = this.liveness.consumeRunTimedOut(runId)
2250
+ ? liveness_1.INSTANCE_AI_RUN_TIMEOUT_REASON
2251
+ : getAbortReason(signal);
2252
+ if (cancellationReason === liveness_1.INSTANCE_AI_RUN_TIMEOUT_REASON) {
2253
+ this.liveness.publishRunTimeoutNotice(threadId, runId);
2254
+ }
2255
+ this.evaluateTerminalResponse(threadId, runId, 'cancelled', {
2256
+ messageGroupId,
2257
+ correlationId: messageId,
2258
+ });
1700
2259
  await this.finalizeRunTracing(runId, tracing, {
1701
2260
  status: 'cancelled',
1702
- reason: 'user_cancelled',
2261
+ reason: cancellationReason,
1703
2262
  });
1704
2263
  messageTraceFinalization = {
1705
2264
  status: 'cancelled',
1706
- reason: 'user_cancelled',
2265
+ reason: cancellationReason,
1707
2266
  metadata: { completion_source: 'orchestrator' },
1708
2267
  };
1709
2268
  const archivedWorkflowIds = await this.reapAiTemporaryFromRun(threadId, user, aiCreatedWorkflowIds);
1710
- this.publishRunFinish(threadId, runId, 'cancelled', 'user_cancelled', archivedWorkflowIds);
2269
+ this.publishRunFinish(threadId, runId, 'cancelled', cancellationReason, archivedWorkflowIds);
2270
+ if (activeSnapshotStorage) {
2271
+ await this.saveAgentTreeSnapshot(threadId, runId, activeSnapshotStorage);
2272
+ }
1711
2273
  return;
1712
2274
  }
1713
2275
  const errorMessage = getErrorMessage(error);
2276
+ const userFacingErrorMessage = getUserFacingErrorMessage(error);
1714
2277
  this.logger.error('Instance AI run error', {
1715
2278
  error: errorMessage,
1716
2279
  threadId,
1717
2280
  runId,
1718
2281
  });
2282
+ this.evaluateTerminalResponse(threadId, runId, 'errored', {
2283
+ messageGroupId,
2284
+ correlationId: messageId,
2285
+ errorMessage: userFacingErrorMessage,
2286
+ });
1719
2287
  await this.finalizeRunTracing(runId, tracing, {
1720
2288
  status: 'error',
1721
2289
  reason: errorMessage,
@@ -1732,14 +2300,16 @@ let InstanceAiService = class InstanceAiService {
1732
2300
  agentId: ORCHESTRATOR_AGENT_ID,
1733
2301
  payload: {
1734
2302
  status: 'error',
1735
- reason: errorMessage,
2303
+ reason: userFacingErrorMessage,
1736
2304
  ...(archivedWorkflowIds.length > 0 ? { archivedWorkflowIds } : {}),
1737
2305
  },
1738
2306
  });
2307
+ if (activeSnapshotStorage) {
2308
+ await this.saveAgentTreeSnapshot(threadId, runId, activeSnapshotStorage);
2309
+ }
1739
2310
  }
1740
2311
  finally {
1741
2312
  this.runState.clearActiveRun(threadId);
1742
- this.threadPushRef.delete(threadId);
1743
2313
  this.domainAccessTrackersByThread.get(threadId)?.clearRun(runId);
1744
2314
  if (messageTraceFinalization) {
1745
2315
  await this.maybeFinalizeRunTraceRoot(runId, messageTraceFinalization);
@@ -1866,6 +2436,19 @@ let InstanceAiService = class InstanceAiService {
1866
2436
  }
1867
2437
  async resolveConfirmation(requestingUserId, requestId, request) {
1868
2438
  const data = toConfirmationData(request);
2439
+ const revalidated = await this.revalidateActiveUser(requestingUserId);
2440
+ if (!revalidated) {
2441
+ this.logger.warn('Rejecting confirmation: user no longer authorized for AI Assistant', {
2442
+ userId: requestingUserId,
2443
+ requestId,
2444
+ });
2445
+ this.runState.rejectPendingConfirmation(requestId);
2446
+ const suspended = this.runState.findSuspendedByRequestId(requestId);
2447
+ if (suspended && suspended.user.id === requestingUserId) {
2448
+ this.cancelRun(suspended.threadId);
2449
+ }
2450
+ return false;
2451
+ }
1869
2452
  if (this.runState.resolvePendingConfirmation(requestingUserId, requestId, data)) {
1870
2453
  this.logger.debug('Resolved pending confirmation (sub-agent HITL)', {
1871
2454
  requestId,
@@ -1891,6 +2474,16 @@ let InstanceAiService = class InstanceAiService {
1891
2474
  const { agent, runId, mastraRunId, threadId, user, toolCallId, abortController, tracing, checkpoint, } = suspended;
1892
2475
  if (user.id !== requestingUserId)
1893
2476
  return false;
2477
+ const revalidated = await this.revalidateActiveUser(user.id);
2478
+ if (!revalidated) {
2479
+ this.logger.warn('Cancelling suspended run: user no longer authorized for AI Assistant', {
2480
+ userId: user.id,
2481
+ threadId,
2482
+ requestId,
2483
+ });
2484
+ this.cancelRun(threadId);
2485
+ return false;
2486
+ }
1894
2487
  this.runState.activateSuspendedRun(threadId);
1895
2488
  const credentialsPayload = data.nodeCredentials ?? data.credentials;
1896
2489
  const resumeData = {
@@ -1908,7 +2501,7 @@ let InstanceAiService = class InstanceAiService {
1908
2501
  runId,
1909
2502
  mastraRunId,
1910
2503
  threadId,
1911
- user,
2504
+ user: revalidated,
1912
2505
  toolCallId,
1913
2506
  signal: abortController.signal,
1914
2507
  abortController,
@@ -1935,6 +2528,7 @@ let InstanceAiService = class InstanceAiService {
1935
2528
  eventBus: this.eventBus,
1936
2529
  logger: this.logger,
1937
2530
  mastraRunId: opts.mastraRunId,
2531
+ onActivity: () => this.runState.touchActiveRun(opts.threadId),
1938
2532
  });
1939
2533
  })
1940
2534
  : await (0, instance_ai_1.resumeAgentRun)(agent, resumeData, {
@@ -1949,6 +2543,7 @@ let InstanceAiService = class InstanceAiService {
1949
2543
  eventBus: this.eventBus,
1950
2544
  logger: this.logger,
1951
2545
  mastraRunId: opts.mastraRunId,
2546
+ onActivity: () => this.runState.touchActiveRun(opts.threadId),
1952
2547
  });
1953
2548
  if (result.status === 'suspended') {
1954
2549
  if (result.suspension) {
@@ -1975,6 +2570,18 @@ let InstanceAiService = class InstanceAiService {
1975
2570
  is_intermediate: true,
1976
2571
  });
1977
2572
  }
2573
+ const messageGroupId = this.traceContextsByRunId.get(opts.runId)?.messageGroupId;
2574
+ const waitingDecision = this.evaluateWaitingResponse(opts.threadId, opts.runId, result.confirmationEvent, { messageGroupId });
2575
+ if (waitingDecision?.reason === 'confirmation-invalid') {
2576
+ messageTraceFinalization = await this.finishInvalidConfirmationRun({
2577
+ threadId: opts.threadId,
2578
+ runId: opts.runId,
2579
+ abortController: opts.abortController,
2580
+ snapshotStorage: opts.snapshotStorage,
2581
+ tracing: opts.tracing,
2582
+ });
2583
+ return;
2584
+ }
1978
2585
  if (result.confirmationEvent) {
1979
2586
  this.trackConfirmationRequest(opts.threadId, result.confirmationEvent);
1980
2587
  this.eventBus.publish(opts.threadId, result.confirmationEvent);
@@ -1983,6 +2590,11 @@ let InstanceAiService = class InstanceAiService {
1983
2590
  return;
1984
2591
  }
1985
2592
  const outputText = await (result.text ?? Promise.resolve(''));
2593
+ const messageGroupId = this.traceContextsByRunId.get(opts.runId)?.messageGroupId;
2594
+ this.evaluateTerminalResponse(opts.threadId, opts.runId, result.status, {
2595
+ messageGroupId,
2596
+ workSummary: result.workSummary,
2597
+ });
1986
2598
  const finalStatus = result.status === 'errored' ? 'error' : result.status;
1987
2599
  await this.finalizeRunTracing(opts.runId, opts.tracing, {
1988
2600
  status: finalStatus,
@@ -2009,6 +2621,10 @@ let InstanceAiService = class InstanceAiService {
2009
2621
  }
2010
2622
  catch (error) {
2011
2623
  if (opts.signal.aborted) {
2624
+ const messageGroupId = this.traceContextsByRunId.get(opts.runId)?.messageGroupId;
2625
+ this.evaluateTerminalResponse(opts.threadId, opts.runId, 'cancelled', {
2626
+ messageGroupId,
2627
+ });
2012
2628
  await this.finalizeRunTracing(opts.runId, opts.tracing, {
2013
2629
  status: 'cancelled',
2014
2630
  reason: 'user_cancelled',
@@ -2020,14 +2636,21 @@ let InstanceAiService = class InstanceAiService {
2020
2636
  };
2021
2637
  const archivedWorkflowIds = await this.reapAiTemporaryFromRun(opts.threadId, opts.user, undefined);
2022
2638
  this.publishRunFinish(opts.threadId, opts.runId, 'cancelled', 'user_cancelled', archivedWorkflowIds);
2639
+ await this.saveAgentTreeSnapshot(opts.threadId, opts.runId, opts.snapshotStorage);
2023
2640
  return;
2024
2641
  }
2025
2642
  const errorMessage = getErrorMessage(error);
2643
+ const userFacingErrorMessage = getUserFacingErrorMessage(error);
2026
2644
  this.logger.error('Instance AI resumed run error', {
2027
2645
  error: errorMessage,
2028
2646
  threadId: opts.threadId,
2029
2647
  runId: opts.runId,
2030
2648
  });
2649
+ const messageGroupId = this.traceContextsByRunId.get(opts.runId)?.messageGroupId;
2650
+ this.evaluateTerminalResponse(opts.threadId, opts.runId, 'errored', {
2651
+ messageGroupId,
2652
+ errorMessage: userFacingErrorMessage,
2653
+ });
2031
2654
  await this.finalizeRunTracing(opts.runId, opts.tracing, {
2032
2655
  status: 'error',
2033
2656
  reason: errorMessage,
@@ -2044,14 +2667,14 @@ let InstanceAiService = class InstanceAiService {
2044
2667
  agentId: ORCHESTRATOR_AGENT_ID,
2045
2668
  payload: {
2046
2669
  status: 'error',
2047
- reason: errorMessage,
2670
+ reason: userFacingErrorMessage,
2048
2671
  ...(archivedWorkflowIds.length > 0 ? { archivedWorkflowIds } : {}),
2049
2672
  },
2050
2673
  });
2674
+ await this.saveAgentTreeSnapshot(opts.threadId, opts.runId, opts.snapshotStorage);
2051
2675
  }
2052
2676
  finally {
2053
2677
  this.runState.clearActiveRun(opts.threadId);
2054
- this.threadPushRef.delete(opts.threadId);
2055
2678
  if (messageTraceFinalization) {
2056
2679
  await this.maybeFinalizeRunTraceRoot(opts.runId, messageTraceFinalization);
2057
2680
  }
@@ -2132,6 +2755,7 @@ let InstanceAiService = class InstanceAiService {
2132
2755
  }
2133
2756
  },
2134
2757
  onSettled: async (task) => {
2758
+ await this.recordBackgroundTerminalOutcome(task);
2135
2759
  await this.saveAgentTreeSnapshot(opts.threadId, runId, snapshotStorage, true, task.messageGroupId);
2136
2760
  if (task.plannedTaskId)
2137
2761
  return;
@@ -2152,6 +2776,13 @@ let InstanceAiService = class InstanceAiService {
2152
2776
  const hasActiveRun = !!this.runState.getActiveRunId(opts.threadId);
2153
2777
  const hasSuspendedRun = this.runState.hasSuspendedRun(opts.threadId);
2154
2778
  if (remaining.length === 0 && !hasActiveRun && !hasSuspendedRun) {
2779
+ if (this.liveness.hasTimedOutActiveRunThread(opts.threadId)) {
2780
+ this.logger.debug('Skipping background auto-follow-up after active run timeout', {
2781
+ threadId: opts.threadId,
2782
+ taskId: task.taskId,
2783
+ });
2784
+ return;
2785
+ }
2155
2786
  const user = this.runState.getThreadUser(opts.threadId);
2156
2787
  if (user) {
2157
2788
  const payload = JSON.stringify({
@@ -2302,20 +2933,23 @@ let InstanceAiService = class InstanceAiService {
2302
2933
  }
2303
2934
  return archived;
2304
2935
  }
2305
- async finalizeCancelledSuspendedRun(suspended) {
2936
+ async finalizeCancelledSuspendedRun(suspended, reason = 'user_cancelled') {
2937
+ if (reason === liveness_1.INSTANCE_AI_RUN_TIMEOUT_REASON) {
2938
+ this.liveness.publishRunTimeoutNotice(suspended.threadId, suspended.runId);
2939
+ }
2306
2940
  await this.finalizeRunTracing(suspended.runId, suspended.tracing, {
2307
2941
  status: 'cancelled',
2308
- reason: 'user_cancelled',
2942
+ reason,
2309
2943
  });
2310
2944
  const archivedWorkflowIds = await this.reapAiTemporaryFromRun(suspended.threadId, suspended.user, undefined);
2311
- this.publishRunFinish(suspended.threadId, suspended.runId, 'cancelled', 'user_cancelled', archivedWorkflowIds);
2945
+ this.publishRunFinish(suspended.threadId, suspended.runId, 'cancelled', reason, archivedWorkflowIds);
2312
2946
  await this.saveAgentTreeSnapshot(suspended.threadId, suspended.runId, this.dbSnapshotStorage, true);
2313
2947
  if (suspended.mastraRunId) {
2314
2948
  void this.cleanupMastraSnapshots(suspended.mastraRunId);
2315
2949
  }
2316
2950
  await this.maybeFinalizeRunTraceRoot(suspended.runId, {
2317
2951
  status: 'cancelled',
2318
- reason: 'user_cancelled',
2952
+ reason,
2319
2953
  metadata: { completion_source: 'orchestrator' },
2320
2954
  });
2321
2955
  }
@@ -2391,11 +3025,9 @@ let InstanceAiService = class InstanceAiService {
2391
3025
  }
2392
3026
  async finalizeRun(threadId, runId, status, snapshotStorage, options) {
2393
3027
  this.publishRunFinish(threadId, runId, status, undefined, options?.archivedWorkflowIds);
2394
- if (status === 'completed') {
2395
- await this.saveAgentTreeSnapshot(threadId, runId, snapshotStorage);
2396
- if (options?.userId && options?.modelId) {
2397
- void this.refineTitleIfNeeded(threadId, options.userId, options.modelId);
2398
- }
3028
+ await this.saveAgentTreeSnapshot(threadId, runId, snapshotStorage);
3029
+ if (status === 'completed' && options?.userId && options?.modelId) {
3030
+ void this.refineTitleIfNeeded(threadId, options.userId, options.modelId);
2399
3031
  }
2400
3032
  }
2401
3033
  async refineTitleIfNeeded(threadId, userId, modelId) {
@@ -2456,11 +3088,23 @@ let InstanceAiService = class InstanceAiService {
2456
3088
  let groupRunIds;
2457
3089
  if (messageGroupId) {
2458
3090
  groupRunIds = this.getRunIdsForMessageGroup(messageGroupId);
3091
+ if (groupRunIds.length === 0) {
3092
+ const snapshot = await snapshotStorage.getLatest(threadId, { messageGroupId, runId });
3093
+ groupRunIds = snapshot?.runIds?.length ? snapshot.runIds : [runId];
3094
+ }
2459
3095
  events = this.eventBus.getEventsForRuns(threadId, groupRunIds);
2460
3096
  }
2461
3097
  else {
2462
3098
  events = this.eventBus.getEventsForRun(threadId, runId);
2463
3099
  }
3100
+ if (isUpdate && events.length === 0) {
3101
+ this.logger.warn('Skipped updating empty Instance AI agent tree snapshot', {
3102
+ threadId,
3103
+ runId,
3104
+ messageGroupId,
3105
+ });
3106
+ return;
3107
+ }
2464
3108
  const agentTree = (0, instance_ai_1.buildAgentTreeFromEvents)(events);
2465
3109
  const tracing = this.traceContextsByRunId.get(runId)?.tracing;
2466
3110
  const saveOptions = {
@@ -2513,6 +3157,9 @@ exports.InstanceAiService = InstanceAiService = __decorate([
2513
3157
  telemetry_1.Telemetry,
2514
3158
  db_1.UserRepository,
2515
3159
  db_1.AiBuilderTemporaryWorkflowRepository,
2516
- n8n_core_1.ErrorReporter])
3160
+ n8n_core_1.ErrorReporter,
3161
+ config_1.SsrfProtectionConfig,
3162
+ ssrf_protection_service_1.SsrfProtectionService,
3163
+ event_service_1.EventService])
2517
3164
  ], InstanceAiService);
2518
3165
  //# sourceMappingURL=instance-ai.service.js.map