openloops 0.6.0 → 0.7.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 (505) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +1 -1
  3. package/dist/clients/llm/llm-client.mjs +0 -1
  4. package/dist/clients/llm/llm-error.mjs +0 -1
  5. package/dist/clients/llm/llm-types.mjs +0 -1
  6. package/dist/clients/llm/model-resolution.mjs +0 -1
  7. package/dist/clients/llm/pi-ai-adapter.mjs +0 -1
  8. package/dist/clients/llm/sampling-rules.mjs +0 -1
  9. package/dist/clients/serper/serper-client.mjs +0 -1
  10. package/dist/clients/slack/slack-client.mjs +0 -1
  11. package/dist/common/base/base.app.d.ts +3 -3
  12. package/dist/common/base/base.app.mjs +0 -1
  13. package/dist/common/base/base.entity.d.ts +4 -16
  14. package/dist/common/base/base.entity.js +11 -39
  15. package/dist/common/base/base.entity.mjs +11 -40
  16. package/dist/common/base/base.use-case.d.ts +1 -7
  17. package/dist/common/base/base.use-case.mjs +0 -1
  18. package/dist/common/base/current-session.mjs +0 -1
  19. package/dist/common/base/current-user.mjs +0 -1
  20. package/dist/common/base/share.mjs +0 -1
  21. package/dist/common/base/utils/index.d.ts +1 -2
  22. package/dist/common/base/utils/index.js +2 -4
  23. package/dist/common/base/utils/index.mjs +1 -2
  24. package/dist/common/base/utils/is-plain-object.mjs +0 -1
  25. package/dist/common/base/utils/to-patch.d.ts +9 -0
  26. package/dist/common/base/utils/to-patch.js +46 -0
  27. package/dist/common/base/utils/to-patch.mjs +21 -0
  28. package/dist/common/constants/harness.mjs +0 -1
  29. package/dist/common/error/http-error.mjs +0 -1
  30. package/dist/common/error/reportError.mjs +0 -1
  31. package/dist/common/error/sentry-client.mjs +0 -1
  32. package/dist/common/helpers/escape-regex.mjs +0 -1
  33. package/dist/common/helpers/extract-json-from-text.mjs +0 -1
  34. package/dist/common/helpers/sanitize-string.mjs +0 -1
  35. package/dist/common/logger/pino.mjs +0 -1
  36. package/dist/common/repositories/mongo-db.client.mjs +0 -1
  37. package/dist/common/repositories/mongo-db.repository.d.ts +15 -4
  38. package/dist/common/repositories/mongo-db.repository.js +44 -15
  39. package/dist/common/repositories/mongo-db.repository.mjs +44 -16
  40. package/dist/common/repositories/scope.mjs +0 -1
  41. package/dist/common/utils/database-name.mjs +0 -1
  42. package/dist/common/utils/number-setting.mjs +0 -1
  43. package/dist/common/utils/secret-manager.mjs +0 -1
  44. package/dist/db/indexes/agent-actions.mjs +0 -1
  45. package/dist/db/indexes/agent-tasks.mjs +0 -1
  46. package/dist/db/indexes/agent-traces.mjs +0 -1
  47. package/dist/db/indexes/automation-runs.mjs +0 -1
  48. package/dist/db/indexes/automations.mjs +0 -1
  49. package/dist/db/indexes/chats.mjs +0 -1
  50. package/dist/db/indexes/index.js +3 -1
  51. package/dist/db/indexes/index.mjs +3 -2
  52. package/dist/db/indexes/llm-calls.mjs +0 -1
  53. package/dist/db/indexes/mcp-servers.mjs +0 -1
  54. package/dist/db/indexes/refresh-tokens.d.ts +2 -0
  55. package/dist/{common/decorators/mask-in-logs/index.js → db/indexes/refresh-tokens.js} +16 -5
  56. package/dist/db/indexes/refresh-tokens.mjs +9 -0
  57. package/dist/db/indexes/revoked-tokens.mjs +0 -1
  58. package/dist/db/indexes/workspace-items.mjs +0 -1
  59. package/dist/db/migrations/automations.mjs +0 -1
  60. package/dist/guardrails/guard.mjs +0 -1
  61. package/dist/guardrails/index.mjs +0 -1
  62. package/dist/guardrails/input/block-card.mjs +0 -1
  63. package/dist/guardrails/input/block-code.mjs +0 -1
  64. package/dist/guardrails/input/block-email.mjs +0 -1
  65. package/dist/guardrails/input/create-block-input-oversize.mjs +0 -1
  66. package/dist/guardrails/input/diagnostic-sanity.mjs +0 -1
  67. package/dist/guardrails/input/input-check.mjs +0 -1
  68. package/dist/harness/agent-loop.mjs +0 -1
  69. package/dist/harness/agent-state.mjs +0 -1
  70. package/dist/harness/agent.d.ts +0 -1
  71. package/dist/harness/agent.js +14 -14
  72. package/dist/harness/agent.mjs +14 -15
  73. package/dist/harness/native-tools.mjs +0 -1
  74. package/dist/harness/skills/approval-request.mjs +0 -1
  75. package/dist/harness/skills/autonomous-answer.mjs +0 -1
  76. package/dist/harness/skills/confirmation-gate.mjs +0 -1
  77. package/dist/harness/skills/mcp-change-review.mjs +0 -1
  78. package/dist/harness/tool-catalog.mjs +0 -1
  79. package/dist/harness/tool-pipeline.mjs +0 -1
  80. package/dist/harness/utils/activity.mjs +0 -1
  81. package/dist/harness/utils/describe-shape.mjs +0 -1
  82. package/dist/harness/utils/grounding.mjs +0 -1
  83. package/dist/harness/utils/rank-tools-by-keywords.mjs +0 -1
  84. package/dist/harness/workspace.js +7 -7
  85. package/dist/harness/workspace.mjs +7 -8
  86. package/dist/loops/agi/loop.mjs +0 -1
  87. package/dist/loops/agi/skills/reasoning-engine.mjs +0 -1
  88. package/dist/loops/shared/skills/fast-responder.mjs +0 -1
  89. package/dist/services/authentication/entities/index.d.ts +1 -0
  90. package/dist/services/authentication/entities/index.js +3 -1
  91. package/dist/services/authentication/entities/index.mjs +1 -0
  92. package/dist/services/authentication/entities/refresh-token.entity.d.ts +25 -0
  93. package/dist/services/authentication/entities/refresh-token.entity.js +75 -0
  94. package/dist/services/authentication/entities/refresh-token.entity.mjs +51 -0
  95. package/dist/services/authentication/entities/revoked-token.entity.mjs +0 -1
  96. package/dist/services/authentication/helpers/auth-config.d.ts +9 -0
  97. package/dist/{common/decorators/index.js → services/authentication/helpers/auth-config.js} +19 -5
  98. package/dist/services/authentication/helpers/auth-config.mjs +12 -0
  99. package/dist/services/authentication/helpers/session-tokens.d.ts +16 -0
  100. package/dist/services/authentication/helpers/session-tokens.js +60 -0
  101. package/dist/services/authentication/helpers/session-tokens.mjs +35 -0
  102. package/dist/services/authentication/helpers/tokens.d.ts +43 -0
  103. package/dist/services/authentication/helpers/tokens.js +113 -0
  104. package/dist/services/authentication/helpers/tokens.mjs +71 -0
  105. package/dist/services/authentication/index.d.ts +3 -0
  106. package/dist/services/authentication/index.js +23 -0
  107. package/dist/services/authentication/index.mjs +11 -0
  108. package/dist/services/authentication/module.d.ts +12 -3
  109. package/dist/services/authentication/module.js +40 -7
  110. package/dist/services/authentication/module.mjs +34 -7
  111. package/dist/services/authentication/repositories/index.d.ts +1 -0
  112. package/dist/services/authentication/repositories/index.js +3 -1
  113. package/dist/services/authentication/repositories/index.mjs +1 -0
  114. package/dist/services/authentication/repositories/refresh-token.repository.d.ts +10 -0
  115. package/dist/services/authentication/repositories/refresh-token.repository.js +60 -0
  116. package/dist/services/authentication/repositories/refresh-token.repository.mjs +36 -0
  117. package/dist/services/authentication/repositories/revoked-token.repository.js +3 -15
  118. package/dist/services/authentication/repositories/revoked-token.repository.mjs +3 -10
  119. package/dist/services/authentication/use-cases/claim-refresh-token.use-case.d.ts +12 -0
  120. package/dist/services/authentication/use-cases/claim-refresh-token.use-case.js +40 -0
  121. package/dist/services/authentication/use-cases/claim-refresh-token.use-case.mjs +16 -0
  122. package/dist/services/authentication/use-cases/create-refresh-token.use-case.d.ts +11 -0
  123. package/dist/services/authentication/use-cases/create-refresh-token.use-case.js +43 -0
  124. package/dist/services/authentication/use-cases/create-refresh-token.use-case.mjs +19 -0
  125. package/dist/services/authentication/use-cases/find-refresh-token-by-hash.use-case.d.ts +11 -0
  126. package/dist/services/authentication/use-cases/find-refresh-token-by-hash.use-case.js +40 -0
  127. package/dist/services/authentication/use-cases/find-refresh-token-by-hash.use-case.mjs +16 -0
  128. package/dist/services/authentication/use-cases/is-token-revoked.use-case.d.ts +6 -8
  129. package/dist/services/authentication/use-cases/is-token-revoked.use-case.js +4 -18
  130. package/dist/services/authentication/use-cases/is-token-revoked.use-case.mjs +4 -13
  131. package/dist/services/authentication/use-cases/issue-password-reset-token.use-case.d.ts +18 -0
  132. package/dist/services/authentication/use-cases/issue-password-reset-token.use-case.js +49 -0
  133. package/dist/services/authentication/use-cases/issue-password-reset-token.use-case.mjs +25 -0
  134. package/dist/services/authentication/use-cases/issue-session.use-case.d.ts +13 -0
  135. package/dist/services/authentication/use-cases/issue-session.use-case.js +48 -0
  136. package/dist/services/authentication/use-cases/issue-session.use-case.mjs +24 -0
  137. package/dist/services/authentication/use-cases/login.use-case.d.ts +11 -11
  138. package/dist/services/authentication/use-cases/login.use-case.js +18 -54
  139. package/dist/services/authentication/use-cases/login.use-case.mjs +17 -38
  140. package/dist/services/authentication/use-cases/logout.use-case.d.ts +14 -0
  141. package/dist/services/authentication/use-cases/logout.use-case.js +48 -0
  142. package/dist/services/authentication/use-cases/logout.use-case.mjs +24 -0
  143. package/dist/services/authentication/use-cases/refresh.use-case.d.ts +23 -0
  144. package/dist/services/authentication/use-cases/refresh.use-case.js +84 -0
  145. package/dist/services/authentication/use-cases/refresh.use-case.mjs +60 -0
  146. package/dist/services/authentication/use-cases/reset-password.use-case.d.ts +15 -0
  147. package/dist/services/authentication/use-cases/reset-password.use-case.js +61 -0
  148. package/dist/services/authentication/use-cases/reset-password.use-case.mjs +37 -0
  149. package/dist/services/authentication/use-cases/revoke-refresh-token-family.use-case.d.ts +11 -0
  150. package/dist/services/authentication/use-cases/revoke-refresh-token-family.use-case.js +40 -0
  151. package/dist/services/authentication/use-cases/revoke-refresh-token-family.use-case.mjs +16 -0
  152. package/dist/services/authentication/use-cases/revoke-token.use-case.d.ts +4 -6
  153. package/dist/services/authentication/use-cases/revoke-token.use-case.js +12 -26
  154. package/dist/services/authentication/use-cases/revoke-token.use-case.mjs +10 -19
  155. package/dist/services/authentication/use-cases/revoke-user-refresh-tokens.use-case.d.ts +13 -0
  156. package/dist/services/authentication/use-cases/revoke-user-refresh-tokens.use-case.js +40 -0
  157. package/dist/services/authentication/use-cases/revoke-user-refresh-tokens.use-case.mjs +16 -0
  158. package/dist/services/automations/entities/automation-run.entity.mjs +0 -1
  159. package/dist/services/automations/entities/automation.entity.d.ts +1 -0
  160. package/dist/services/automations/entities/automation.entity.js +2 -1
  161. package/dist/services/automations/entities/automation.entity.mjs +2 -2
  162. package/dist/services/automations/entities/recurrence.mjs +0 -1
  163. package/dist/services/automations/entities/trigger.mjs +0 -1
  164. package/dist/services/automations/module.d.ts +0 -1
  165. package/dist/services/automations/module.js +20 -22
  166. package/dist/services/automations/module.mjs +20 -23
  167. package/dist/services/automations/repositories/automation-run.repository.js +7 -22
  168. package/dist/services/automations/repositories/automation-run.repository.mjs +7 -17
  169. package/dist/services/automations/repositories/automation.repository.js +25 -39
  170. package/dist/services/automations/repositories/automation.repository.mjs +25 -34
  171. package/dist/services/automations/runner/automation-runner.js +8 -9
  172. package/dist/services/automations/runner/automation-runner.mjs +8 -10
  173. package/dist/services/automations/use-cases/attach-automation-run-chat.use-case.d.ts +4 -6
  174. package/dist/services/automations/use-cases/attach-automation-run-chat.use-case.js +5 -19
  175. package/dist/services/automations/use-cases/attach-automation-run-chat.use-case.mjs +5 -14
  176. package/dist/services/automations/use-cases/claim-due-automations.use-case.d.ts +9 -11
  177. package/dist/services/automations/use-cases/claim-due-automations.use-case.js +4 -20
  178. package/dist/services/automations/use-cases/claim-due-automations.use-case.mjs +4 -15
  179. package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.d.ts +9 -11
  180. package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.js +4 -20
  181. package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.mjs +4 -15
  182. package/dist/services/automations/use-cases/create-automation.use-case.d.ts +4 -6
  183. package/dist/services/automations/use-cases/create-automation.use-case.js +5 -19
  184. package/dist/services/automations/use-cases/create-automation.use-case.mjs +5 -14
  185. package/dist/services/automations/use-cases/delete-automation.use-case.d.ts +6 -6
  186. package/dist/services/automations/use-cases/delete-automation.use-case.js +8 -22
  187. package/dist/services/automations/use-cases/delete-automation.use-case.mjs +8 -17
  188. package/dist/services/automations/use-cases/finish-automation-run.use-case.d.ts +5 -7
  189. package/dist/services/automations/use-cases/finish-automation-run.use-case.js +5 -20
  190. package/dist/services/automations/use-cases/finish-automation-run.use-case.mjs +5 -15
  191. package/dist/services/automations/use-cases/get-automation-by-id.use-case.d.ts +4 -6
  192. package/dist/services/automations/use-cases/get-automation-by-id.use-case.js +5 -19
  193. package/dist/services/automations/use-cases/get-automation-by-id.use-case.mjs +5 -14
  194. package/dist/services/automations/use-cases/issue-automation-event-token.use-case.d.ts +7 -9
  195. package/dist/services/automations/use-cases/issue-automation-event-token.use-case.js +6 -20
  196. package/dist/services/automations/use-cases/issue-automation-event-token.use-case.mjs +6 -15
  197. package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.d.ts +6 -6
  198. package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.js +5 -19
  199. package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.mjs +5 -14
  200. package/dist/services/automations/use-cases/list-automation-runs-by-user.use-case.d.ts +6 -6
  201. package/dist/services/automations/use-cases/list-automation-runs-by-user.use-case.js +5 -19
  202. package/dist/services/automations/use-cases/list-automation-runs-by-user.use-case.mjs +5 -14
  203. package/dist/services/automations/use-cases/list-automations-by-user.use-case.d.ts +6 -6
  204. package/dist/services/automations/use-cases/list-automations-by-user.use-case.js +5 -19
  205. package/dist/services/automations/use-cases/list-automations-by-user.use-case.mjs +5 -14
  206. package/dist/services/automations/use-cases/preview-automation-runs.use-case.d.ts +4 -6
  207. package/dist/services/automations/use-cases/preview-automation-runs.use-case.js +3 -15
  208. package/dist/services/automations/use-cases/preview-automation-runs.use-case.mjs +3 -10
  209. package/dist/services/automations/use-cases/receive-automation-event.use-case.d.ts +8 -10
  210. package/dist/services/automations/use-cases/receive-automation-event.use-case.js +8 -23
  211. package/dist/services/automations/use-cases/receive-automation-event.use-case.mjs +8 -18
  212. package/dist/services/automations/use-cases/renew-automation-lease.use-case.d.ts +6 -8
  213. package/dist/services/automations/use-cases/renew-automation-lease.use-case.js +4 -18
  214. package/dist/services/automations/use-cases/renew-automation-lease.use-case.mjs +4 -13
  215. package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.d.ts +6 -8
  216. package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.js +8 -21
  217. package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.mjs +9 -17
  218. package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.d.ts +4 -6
  219. package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.js +8 -22
  220. package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.mjs +8 -17
  221. package/dist/services/automations/use-cases/start-automation-run.use-case.d.ts +8 -10
  222. package/dist/services/automations/use-cases/start-automation-run.use-case.js +5 -20
  223. package/dist/services/automations/use-cases/start-automation-run.use-case.mjs +5 -15
  224. package/dist/services/automations/use-cases/sync-automation-run.use-case.d.ts +5 -7
  225. package/dist/services/automations/use-cases/sync-automation-run.use-case.js +12 -27
  226. package/dist/services/automations/use-cases/sync-automation-run.use-case.mjs +12 -22
  227. package/dist/services/automations/use-cases/sync-automation-runs.use-case.d.ts +8 -10
  228. package/dist/services/automations/use-cases/sync-automation-runs.use-case.js +7 -22
  229. package/dist/services/automations/use-cases/sync-automation-runs.use-case.mjs +7 -17
  230. package/dist/services/automations/use-cases/update-automation.use-case.d.ts +4 -6
  231. package/dist/services/automations/use-cases/update-automation.use-case.js +10 -24
  232. package/dist/services/automations/use-cases/update-automation.use-case.mjs +10 -19
  233. package/dist/services/automations/utils/automation-event-error.mjs +0 -1
  234. package/dist/services/automations/utils/automation-fields.mjs +0 -1
  235. package/dist/services/automations/utils/event-message.mjs +0 -1
  236. package/dist/services/automations/utils/event-token.d.ts +1 -2
  237. package/dist/services/automations/utils/event-token.js +9 -35
  238. package/dist/services/automations/utils/event-token.mjs +9 -25
  239. package/dist/services/automations/utils/next-run.mjs +0 -1
  240. package/dist/services/automations/utils/open-run.mjs +0 -1
  241. package/dist/services/automations/utils/previous-run.js +1 -1
  242. package/dist/services/automations/utils/previous-run.mjs +1 -2
  243. package/dist/services/automations/utils/runner-scope.mjs +0 -1
  244. package/dist/services/automations/utils/settings.mjs +0 -1
  245. package/dist/services/chats/entities/chat-message.entity.mjs +0 -1
  246. package/dist/services/chats/entities/chat-settings.entity.mjs +0 -1
  247. package/dist/services/chats/entities/chat.entity.d.ts +1 -0
  248. package/dist/services/chats/entities/chat.entity.js +3 -2
  249. package/dist/services/chats/entities/chat.entity.mjs +3 -3
  250. package/dist/services/chats/module.d.ts +0 -1
  251. package/dist/services/chats/module.js +5 -7
  252. package/dist/services/chats/module.mjs +5 -8
  253. package/dist/services/chats/repositories/chat.repository.js +5 -20
  254. package/dist/services/chats/repositories/chat.repository.mjs +5 -15
  255. package/dist/services/chats/use-cases/create-chat.use-case.d.ts +4 -6
  256. package/dist/services/chats/use-cases/create-chat.use-case.js +5 -19
  257. package/dist/services/chats/use-cases/create-chat.use-case.mjs +5 -14
  258. package/dist/services/chats/use-cases/delete-chat.use-case.d.ts +6 -6
  259. package/dist/services/chats/use-cases/delete-chat.use-case.js +8 -22
  260. package/dist/services/chats/use-cases/delete-chat.use-case.mjs +8 -17
  261. package/dist/services/chats/use-cases/get-chat-by-id.use-case.d.ts +4 -6
  262. package/dist/services/chats/use-cases/get-chat-by-id.use-case.js +6 -20
  263. package/dist/services/chats/use-cases/get-chat-by-id.use-case.mjs +6 -15
  264. package/dist/services/chats/use-cases/interrupt-execution.use-case.d.ts +4 -6
  265. package/dist/services/chats/use-cases/interrupt-execution.use-case.js +6 -20
  266. package/dist/services/chats/use-cases/interrupt-execution.use-case.mjs +6 -15
  267. package/dist/services/chats/use-cases/list-chats-by-props.use-case.d.ts +6 -6
  268. package/dist/services/chats/use-cases/list-chats-by-props.use-case.js +5 -19
  269. package/dist/services/chats/use-cases/list-chats-by-props.use-case.mjs +5 -14
  270. package/dist/services/chats/use-cases/list-chats-by-user.use-case.d.ts +6 -6
  271. package/dist/services/chats/use-cases/list-chats-by-user.use-case.js +5 -19
  272. package/dist/services/chats/use-cases/list-chats-by-user.use-case.mjs +5 -14
  273. package/dist/services/chats/use-cases/update-chat.use-case.d.ts +5 -6
  274. package/dist/services/chats/use-cases/update-chat.use-case.js +8 -26
  275. package/dist/services/chats/use-cases/update-chat.use-case.mjs +8 -21
  276. package/dist/services/chats/utils/deprecated-activity.mjs +0 -1
  277. package/dist/services/llmcalls/entities/llmcall.entity.mjs +0 -1
  278. package/dist/services/llmcalls/module.d.ts +0 -1
  279. package/dist/services/llmcalls/module.js +4 -6
  280. package/dist/services/llmcalls/module.mjs +4 -7
  281. package/dist/services/llmcalls/repositories/llmcall.repository.js +5 -20
  282. package/dist/services/llmcalls/repositories/llmcall.repository.mjs +5 -15
  283. package/dist/services/llmcalls/use-cases/create-llmcall.use-case.d.ts +4 -6
  284. package/dist/services/llmcalls/use-cases/create-llmcall.use-case.js +5 -19
  285. package/dist/services/llmcalls/use-cases/create-llmcall.use-case.mjs +5 -14
  286. package/dist/services/llmcalls/use-cases/delete-llmcall.use-case.d.ts +6 -6
  287. package/dist/services/llmcalls/use-cases/delete-llmcall.use-case.js +8 -22
  288. package/dist/services/llmcalls/use-cases/delete-llmcall.use-case.mjs +8 -17
  289. package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.d.ts +4 -6
  290. package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.js +5 -19
  291. package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.mjs +5 -14
  292. package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.d.ts +4 -6
  293. package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.js +5 -19
  294. package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.mjs +5 -14
  295. package/dist/services/llmcalls/use-cases/get-llm-usage-stats.use-case.d.ts +4 -6
  296. package/dist/services/llmcalls/use-cases/get-llm-usage-stats.use-case.js +5 -19
  297. package/dist/services/llmcalls/use-cases/get-llm-usage-stats.use-case.mjs +5 -14
  298. package/dist/services/llmcalls/use-cases/get-llmcall-by-id.use-case.d.ts +4 -6
  299. package/dist/services/llmcalls/use-cases/get-llmcall-by-id.use-case.js +6 -20
  300. package/dist/services/llmcalls/use-cases/get-llmcall-by-id.use-case.mjs +6 -15
  301. package/dist/services/llmcalls/use-cases/list-llmcalls-by-props.use-case.d.ts +6 -6
  302. package/dist/services/llmcalls/use-cases/list-llmcalls-by-props.use-case.js +5 -19
  303. package/dist/services/llmcalls/use-cases/list-llmcalls-by-props.use-case.mjs +5 -14
  304. package/dist/services/llmcalls/use-cases/update-llmcall.use-case.d.ts +4 -6
  305. package/dist/services/llmcalls/use-cases/update-llmcall.use-case.js +7 -21
  306. package/dist/services/llmcalls/use-cases/update-llmcall.use-case.mjs +7 -16
  307. package/dist/services/llmcalls/utils/usage-periods.mjs +0 -1
  308. package/dist/services/llmcalls/utils/usage-totals.mjs +0 -1
  309. package/dist/services/mcp-servers/entities/mcp-manifest.mjs +0 -1
  310. package/dist/services/mcp-servers/entities/mcpserver.entity.mjs +0 -1
  311. package/dist/services/mcp-servers/module.d.ts +0 -1
  312. package/dist/services/mcp-servers/module.js +8 -10
  313. package/dist/services/mcp-servers/module.mjs +8 -11
  314. package/dist/services/mcp-servers/repositories/mcpserver.repository.js +5 -21
  315. package/dist/services/mcp-servers/repositories/mcpserver.repository.mjs +5 -16
  316. package/dist/services/mcp-servers/use-cases/create-mcpserver.use-case.d.ts +5 -7
  317. package/dist/services/mcp-servers/use-cases/create-mcpserver.use-case.js +5 -21
  318. package/dist/services/mcp-servers/use-cases/create-mcpserver.use-case.mjs +5 -16
  319. package/dist/services/mcp-servers/use-cases/decide-mcpserver-trust.use-case.d.ts +4 -6
  320. package/dist/services/mcp-servers/use-cases/decide-mcpserver-trust.use-case.js +7 -21
  321. package/dist/services/mcp-servers/use-cases/decide-mcpserver-trust.use-case.mjs +7 -16
  322. package/dist/services/mcp-servers/use-cases/delete-mcpserver.use-case.d.ts +6 -6
  323. package/dist/services/mcp-servers/use-cases/delete-mcpserver.use-case.js +8 -22
  324. package/dist/services/mcp-servers/use-cases/delete-mcpserver.use-case.mjs +8 -17
  325. package/dist/services/mcp-servers/use-cases/get-mcpserver-by-id.use-case.d.ts +4 -6
  326. package/dist/services/mcp-servers/use-cases/get-mcpserver-by-id.use-case.js +5 -19
  327. package/dist/services/mcp-servers/use-cases/get-mcpserver-by-id.use-case.mjs +5 -14
  328. package/dist/services/mcp-servers/use-cases/list-all-mcpservers-by-user.use-case.d.ts +6 -6
  329. package/dist/services/mcp-servers/use-cases/list-all-mcpservers-by-user.use-case.js +5 -19
  330. package/dist/services/mcp-servers/use-cases/list-all-mcpservers-by-user.use-case.mjs +5 -14
  331. package/dist/services/mcp-servers/use-cases/list-mcpservers-by-user.use-case.d.ts +6 -6
  332. package/dist/services/mcp-servers/use-cases/list-mcpservers-by-user.use-case.js +5 -19
  333. package/dist/services/mcp-servers/use-cases/list-mcpservers-by-user.use-case.mjs +5 -14
  334. package/dist/services/mcp-servers/use-cases/update-mcpserver.use-case.d.ts +5 -7
  335. package/dist/services/mcp-servers/use-cases/update-mcpserver.use-case.js +9 -25
  336. package/dist/services/mcp-servers/use-cases/update-mcpserver.use-case.mjs +9 -20
  337. package/dist/services/mcp-servers/use-cases/verify-mcpserver-connection.use-case.d.ts +4 -6
  338. package/dist/services/mcp-servers/use-cases/verify-mcpserver-connection.use-case.js +9 -23
  339. package/dist/services/mcp-servers/use-cases/verify-mcpserver-connection.use-case.mjs +9 -18
  340. package/dist/services/tasks/entities/agent-action.entity.mjs +0 -1
  341. package/dist/services/tasks/entities/agent-task.entity.mjs +0 -1
  342. package/dist/services/tasks/module.d.ts +0 -1
  343. package/dist/services/tasks/module.js +7 -9
  344. package/dist/services/tasks/module.mjs +7 -10
  345. package/dist/services/tasks/repositories/agent-action.repository.js +5 -21
  346. package/dist/services/tasks/repositories/agent-action.repository.mjs +5 -16
  347. package/dist/services/tasks/repositories/agent-task.repository.js +5 -21
  348. package/dist/services/tasks/repositories/agent-task.repository.mjs +5 -16
  349. package/dist/services/tasks/use-cases/create-agent-action.use-case.d.ts +4 -6
  350. package/dist/services/tasks/use-cases/create-agent-action.use-case.js +5 -19
  351. package/dist/services/tasks/use-cases/create-agent-action.use-case.mjs +5 -14
  352. package/dist/services/tasks/use-cases/create-agent-task.use-case.d.ts +4 -6
  353. package/dist/services/tasks/use-cases/create-agent-task.use-case.js +5 -19
  354. package/dist/services/tasks/use-cases/create-agent-task.use-case.mjs +5 -14
  355. package/dist/services/tasks/use-cases/get-agent-task-by-id.use-case.d.ts +4 -6
  356. package/dist/services/tasks/use-cases/get-agent-task-by-id.use-case.js +5 -19
  357. package/dist/services/tasks/use-cases/get-agent-task-by-id.use-case.mjs +5 -14
  358. package/dist/services/tasks/use-cases/list-agent-actions-by-task.use-case.d.ts +6 -6
  359. package/dist/services/tasks/use-cases/list-agent-actions-by-task.use-case.js +5 -19
  360. package/dist/services/tasks/use-cases/list-agent-actions-by-task.use-case.mjs +5 -14
  361. package/dist/services/tasks/use-cases/list-agent-tasks-by-chat.use-case.d.ts +6 -6
  362. package/dist/services/tasks/use-cases/list-agent-tasks-by-chat.use-case.js +5 -19
  363. package/dist/services/tasks/use-cases/list-agent-tasks-by-chat.use-case.mjs +5 -14
  364. package/dist/services/tasks/use-cases/update-agent-action.use-case.d.ts +4 -6
  365. package/dist/services/tasks/use-cases/update-agent-action.use-case.js +6 -20
  366. package/dist/services/tasks/use-cases/update-agent-action.use-case.mjs +6 -15
  367. package/dist/services/tasks/use-cases/update-agent-task.use-case.d.ts +4 -6
  368. package/dist/services/tasks/use-cases/update-agent-task.use-case.js +6 -20
  369. package/dist/services/tasks/use-cases/update-agent-task.use-case.mjs +6 -15
  370. package/dist/services/traces/entities/agent-trace-entry.entity.mjs +0 -1
  371. package/dist/services/traces/module.d.ts +0 -1
  372. package/dist/services/traces/module.js +2 -4
  373. package/dist/services/traces/module.mjs +2 -5
  374. package/dist/services/traces/repositories/agent-trace.repository.js +3 -15
  375. package/dist/services/traces/repositories/agent-trace.repository.mjs +3 -10
  376. package/dist/services/traces/use-cases/create-agent-traces.use-case.d.ts +6 -8
  377. package/dist/services/traces/use-cases/create-agent-traces.use-case.js +5 -19
  378. package/dist/services/traces/use-cases/create-agent-traces.use-case.mjs +5 -14
  379. package/dist/services/traces/use-cases/list-agent-traces-by-chat.use-case.d.ts +6 -6
  380. package/dist/services/traces/use-cases/list-agent-traces-by-chat.use-case.js +5 -19
  381. package/dist/services/traces/use-cases/list-agent-traces-by-chat.use-case.mjs +5 -14
  382. package/dist/services/users/entities/user-acquisition.js +2 -2
  383. package/dist/services/users/entities/user-acquisition.mjs +2 -3
  384. package/dist/services/users/entities/user-country.js +2 -2
  385. package/dist/services/users/entities/user-country.mjs +2 -3
  386. package/dist/services/users/entities/user-currency.js +2 -2
  387. package/dist/services/users/entities/user-currency.mjs +2 -3
  388. package/dist/services/users/entities/user-default-model.js +2 -2
  389. package/dist/services/users/entities/user-default-model.mjs +2 -3
  390. package/dist/services/users/entities/user-email.value-object.mjs +0 -1
  391. package/dist/services/users/entities/user-language.js +2 -2
  392. package/dist/services/users/entities/user-language.mjs +2 -3
  393. package/dist/services/users/entities/user-marketing.js +2 -2
  394. package/dist/services/users/entities/user-marketing.mjs +2 -3
  395. package/dist/services/users/entities/user-notification-preferences.mjs +0 -1
  396. package/dist/services/users/entities/user-password.value-object.mjs +0 -1
  397. package/dist/services/users/entities/user-permissions.mjs +0 -1
  398. package/dist/services/users/entities/user-preferences.mjs +0 -1
  399. package/dist/services/users/entities/user-report-preferences.mjs +0 -1
  400. package/dist/services/users/entities/user-report-schedule.mjs +0 -1
  401. package/dist/services/users/entities/user-timezone.js +2 -2
  402. package/dist/services/users/entities/user-timezone.mjs +2 -3
  403. package/dist/services/users/entities/user.entity.d.ts +1 -0
  404. package/dist/services/users/entities/user.entity.js +9 -22
  405. package/dist/services/users/entities/user.entity.mjs +9 -17
  406. package/dist/services/users/module.d.ts +2 -1
  407. package/dist/services/users/module.js +12 -7
  408. package/dist/services/users/module.mjs +11 -8
  409. package/dist/services/users/repositories/user.repository.d.ts +2 -0
  410. package/dist/services/users/repositories/user.repository.js +11 -20
  411. package/dist/services/users/repositories/user.repository.mjs +11 -15
  412. package/dist/services/users/use-cases/change-password.use-case.d.ts +15 -0
  413. package/dist/services/users/use-cases/change-password.use-case.js +52 -0
  414. package/dist/services/users/use-cases/change-password.use-case.mjs +28 -0
  415. package/dist/services/users/use-cases/create-user.use-case.d.ts +4 -6
  416. package/dist/services/users/use-cases/create-user.use-case.js +5 -19
  417. package/dist/services/users/use-cases/create-user.use-case.mjs +5 -14
  418. package/dist/services/users/use-cases/delete-user.use-case.d.ts +6 -6
  419. package/dist/services/users/use-cases/delete-user.use-case.js +8 -22
  420. package/dist/services/users/use-cases/delete-user.use-case.mjs +8 -17
  421. package/dist/services/users/use-cases/get-user-by-id.use-case.d.ts +4 -6
  422. package/dist/services/users/use-cases/get-user-by-id.use-case.js +6 -20
  423. package/dist/services/users/use-cases/get-user-by-id.use-case.mjs +6 -15
  424. package/dist/services/users/use-cases/list-users-by-props.use-case.d.ts +6 -6
  425. package/dist/services/users/use-cases/list-users-by-props.use-case.js +5 -19
  426. package/dist/services/users/use-cases/list-users-by-props.use-case.mjs +5 -14
  427. package/dist/services/users/use-cases/update-user.use-case.d.ts +4 -6
  428. package/dist/services/users/use-cases/update-user.use-case.js +9 -22
  429. package/dist/services/users/use-cases/update-user.use-case.mjs +9 -17
  430. package/dist/services/users/utils/default-model.mjs +0 -1
  431. package/dist/services/workspaces/entities/workspace-item.entity.mjs +0 -1
  432. package/dist/services/workspaces/module.d.ts +0 -1
  433. package/dist/services/workspaces/module.js +5 -7
  434. package/dist/services/workspaces/module.mjs +5 -8
  435. package/dist/services/workspaces/repositories/workspace-item.repository.js +5 -20
  436. package/dist/services/workspaces/repositories/workspace-item.repository.mjs +5 -15
  437. package/dist/services/workspaces/use-cases/delete-workspace-item.use-case.d.ts +6 -8
  438. package/dist/services/workspaces/use-cases/delete-workspace-item.use-case.js +7 -21
  439. package/dist/services/workspaces/use-cases/delete-workspace-item.use-case.mjs +7 -16
  440. package/dist/services/workspaces/use-cases/get-workspace-item.use-case.d.ts +4 -6
  441. package/dist/services/workspaces/use-cases/get-workspace-item.use-case.js +6 -20
  442. package/dist/services/workspaces/use-cases/get-workspace-item.use-case.mjs +6 -15
  443. package/dist/services/workspaces/use-cases/list-workspace-items.use-case.d.ts +6 -6
  444. package/dist/services/workspaces/use-cases/list-workspace-items.use-case.js +5 -19
  445. package/dist/services/workspaces/use-cases/list-workspace-items.use-case.mjs +5 -14
  446. package/dist/services/workspaces/use-cases/save-workspace-item.use-case.d.ts +4 -6
  447. package/dist/services/workspaces/use-cases/save-workspace-item.use-case.js +10 -24
  448. package/dist/services/workspaces/use-cases/save-workspace-item.use-case.mjs +10 -19
  449. package/dist/services/workspaces/use-cases/search-workspace-items.use-case.d.ts +6 -6
  450. package/dist/services/workspaces/use-cases/search-workspace-items.use-case.js +5 -19
  451. package/dist/services/workspaces/use-cases/search-workspace-items.use-case.mjs +5 -14
  452. package/dist/skills/call-modes.mjs +0 -1
  453. package/dist/skills/runtime-context.mjs +0 -1
  454. package/dist/skills/shared/shared-rules.mjs +0 -1
  455. package/dist/skills/skill.js +1 -2
  456. package/dist/skills/skill.mjs +1 -3
  457. package/dist/tools/core/call-ai/call-ai.skill.mjs +0 -1
  458. package/dist/tools/core/call-ai/call-ai.tool.mjs +0 -1
  459. package/dist/tools/core/slack/send-slack-message.tool.mjs +0 -1
  460. package/dist/tools/core/web-search/web-search.tool.mjs +0 -1
  461. package/dist/tools/tool.mjs +0 -1
  462. package/docs/authentication.md +95 -16
  463. package/docs/authorization.md +1 -1
  464. package/docs/automations.md +6 -5
  465. package/docs/chats.md +1 -1
  466. package/docs/configuration.md +1 -1
  467. package/docs/integration-guide.md +2 -2
  468. package/docs/mcp-servers.md +1 -1
  469. package/docs/usage.md +5 -5
  470. package/docs/users.md +1 -1
  471. package/examples/authentication/login.ts +1 -1
  472. package/examples/automations/create-automation.ts +1 -1
  473. package/examples/automations/create-event-automation.ts +2 -2
  474. package/examples/automations/list-automation-runs.ts +2 -2
  475. package/examples/automations/list-automations.ts +1 -1
  476. package/examples/automations/preview-automation-runs.ts +1 -1
  477. package/examples/automations/receive-automation-event.ts +1 -1
  478. package/examples/automations/revoke-automation-event-token.ts +2 -2
  479. package/examples/automations/update-automation.ts +2 -2
  480. package/examples/chats/get-chat-by-id.ts +2 -2
  481. package/examples/chats/list-autonomous-chats.ts +1 -1
  482. package/examples/chats/list-chats.ts +1 -1
  483. package/examples/mcps/decide-mcp.ts +3 -3
  484. package/examples/mcps/list-all-mcps.ts +1 -1
  485. package/examples/mcps/verify-mcp.ts +1 -1
  486. package/examples/usage/get-chat-usage.ts +2 -2
  487. package/examples/usage/get-message-usage.ts +2 -2
  488. package/examples/usage/get-usage-stats-by-range.ts +1 -1
  489. package/examples/usage/get-usage-stats.ts +3 -3
  490. package/examples/users/set-default-model.ts +1 -1
  491. package/package.json +2 -4
  492. package/dist/chunk-CF3WOMB3.mjs +0 -16
  493. package/dist/common/base/utils/delete-empty-fields.d.ts +0 -1
  494. package/dist/common/base/utils/delete-empty-fields.js +0 -66
  495. package/dist/common/base/utils/delete-empty-fields.mjs +0 -43
  496. package/dist/common/base/utils/flatten-object.d.ts +0 -1
  497. package/dist/common/base/utils/flatten-object.js +0 -45
  498. package/dist/common/base/utils/flatten-object.mjs +0 -22
  499. package/dist/common/decorators/index.d.ts +0 -1
  500. package/dist/common/decorators/index.mjs +0 -1
  501. package/dist/common/decorators/mask-in-logs/index.d.ts +0 -1
  502. package/dist/common/decorators/mask-in-logs/index.mjs +0 -1
  503. package/dist/common/decorators/mask-in-logs/mask-in-logs.d.ts +0 -2
  504. package/dist/common/decorators/mask-in-logs/mask-in-logs.js +0 -53
  505. package/dist/common/decorators/mask-in-logs/mask-in-logs.mjs +0 -29
@@ -27,6 +27,7 @@ var import_error = require("../error/index.js");
27
27
  var import_mongo_db = require("./mongo-db.client");
28
28
  const DEFAULT_LIMIT = 10;
29
29
  const PROTECTED_FIELDS = ["__v", "ownerId", "sharedWith", "createdAt", "createdBy", "updatedAt", "updatedBy", "deletedAt", "deletedBy", "archivedAt", "archivedBy"];
30
+ const IMMUTABLE_FIELDS = ["_id", "__v", "createdAt", "createdBy"];
30
31
  class VersionConflictError extends Error {
31
32
  code = "VERSION_CONFLICT";
32
33
  statusCode = 409;
@@ -170,7 +171,7 @@ class MongoRepository {
170
171
  try {
171
172
  const db = await this.dbClient.db(this.database);
172
173
  const collection = db.collection(this.collection);
173
- const { insertedId } = await collection.insertOne({ ...document, __v: 1 });
174
+ const { insertedId } = await collection.insertOne({ ...document, __v: 1 }, { ignoreUndefined: true });
174
175
  return { ...document, _id: insertedId, __v: 1 };
175
176
  } catch (error) {
176
177
  await this.report(error);
@@ -182,35 +183,63 @@ class MongoRepository {
182
183
  try {
183
184
  const db = await this.dbClient.db(this.database);
184
185
  const collection = db.collection(this.collection);
185
- const { insertedIds } = await collection.insertMany(documents);
186
+ const { insertedIds } = await collection.insertMany(documents.map((document) => ({ ...document, __v: 1 })), { ignoreUndefined: true });
186
187
  return insertedIds;
187
188
  } catch (error) {
188
189
  await this.report(error);
189
190
  throw error;
190
191
  }
191
192
  }
192
- async updateOne({ where, payload, expectedVersion, scope }) {
193
- if (!where || Object.keys(where).length === 0) throw new Error("[Mongo Repository] Where is required for updateOne operation");
194
- if (!payload || Object.keys(payload).length === 0) throw new Error("[Mongo Repository] Payload is required for updateOne operation");
193
+ async patchOne({ where, set, unset, expectedVersion, scope }) {
194
+ return this.applyPatch({ where, set, unset, expectedVersion, scope });
195
+ }
196
+ async archiveByPatch(params) {
197
+ const actor = this.actorId(params.scope);
198
+ return this.applyPatch(params, { archivedAt: /* @__PURE__ */ new Date(), ...actor ? { archivedBy: actor } : {} });
199
+ }
200
+ async applyPatch({ where, set, unset, expectedVersion, scope }, stamps = {}) {
201
+ if (!where || Object.keys(where).length === 0) throw new Error("[Mongo Repository] Where is required for patchOne operation");
195
202
  const actor = this.actorId(scope);
196
- const { _id, __v, createdAt, createdBy, toUnset, ...rest } = payload;
197
203
  const toSet = {
198
- ...this.withoutProtected(rest, scope),
199
- ...scope ? { updatedAt: /* @__PURE__ */ new Date(), ...actor ? { updatedBy: actor } : {} } : {}
204
+ ...this.withoutProtectedPaths(set ?? {}, scope),
205
+ ...scope ? { updatedAt: /* @__PURE__ */ new Date(), ...actor ? { updatedBy: actor } : {} } : {},
206
+ ...stamps
200
207
  };
208
+ const toUnset = this.withoutProtectedPaths(unset ?? {}, scope);
201
209
  return this.modifyOne(where, {
202
- ...toSet ? { $set: toSet } : {},
203
- ...toUnset ? { $unset: toUnset } : {}
210
+ $set: toSet,
211
+ ...Object.keys(toUnset).length ? { $unset: toUnset } : {}
204
212
  }, scope, expectedVersion);
205
213
  }
206
- async softDelete({ where, payload, scope }) {
214
+ async claimOne({ where, set, scope }) {
215
+ const filter = this.withScope({ ...where, ...this._where }, scope);
216
+ try {
217
+ const db = await this.dbClient.db(this.database);
218
+ const collection = db.collection(this.collection);
219
+ const result = await collection.findOneAndUpdate(
220
+ filter,
221
+ { $set: this.withoutProtectedPaths(set ?? {}, scope) },
222
+ { returnDocument: "before", ignoreUndefined: true }
223
+ );
224
+ return result;
225
+ } catch (error) {
226
+ await this.report(error);
227
+ throw error;
228
+ }
229
+ }
230
+ withoutProtectedPaths(fields, scope) {
231
+ const guarded = scope && !scope.trusted;
232
+ const isProtected = (key) => this.protectedFields.some((field) => key === field || key.startsWith(`${field}.`) || field.startsWith(`${key}.`));
233
+ return Object.fromEntries(Object.entries(fields).filter(([key]) => !IMMUTABLE_FIELDS.includes(key) && !(guarded && isProtected(key))));
234
+ }
235
+ async softDelete({ where, payload, unset, scope }) {
207
236
  if (!where || Object.keys(where).length === 0) throw new Error("[Mongo Repository] Where is required for softDelete operation");
208
237
  const actor = this.actorId(scope);
209
- const { toUnset, ...rest } = payload ?? {};
210
- const extra = this.withoutProtected(rest, scope);
238
+ const extra = this.withoutProtected(payload ?? {}, scope);
239
+ const toUnset = this.withoutProtectedPaths(unset ?? {}, scope);
211
240
  return this.modifyOne(where, {
212
241
  $set: { ...extra, deletedAt: /* @__PURE__ */ new Date(), ...actor ? { deletedBy: actor } : {} },
213
- ...toUnset ? { $unset: toUnset } : {}
242
+ ...Object.keys(toUnset).length ? { $unset: toUnset } : {}
214
243
  }, scope);
215
244
  }
216
245
  async modifyOne(where, update, scope, expectedVersion) {
@@ -222,7 +251,7 @@ class MongoRepository {
222
251
  const result = await collection.findOneAndUpdate(
223
252
  filter,
224
253
  { $inc: { __v: 1 }, ...update },
225
- { returnDocument: "after" }
254
+ { returnDocument: "after", ignoreUndefined: true }
226
255
  );
227
256
  if (!result && checkVersion) {
228
257
  const exists = await collection.findOne(this.withScope({ ...where, ...this._where }, scope), { projection: { _id: 1 } });
@@ -1,9 +1,9 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  import { ObjectId } from "mongodb";
3
2
  import { reportError } from "../error/index.js";
4
3
  import { getMongoDBClient } from "./mongo-db.client";
5
4
  const DEFAULT_LIMIT = 10;
6
5
  const PROTECTED_FIELDS = ["__v", "ownerId", "sharedWith", "createdAt", "createdBy", "updatedAt", "updatedBy", "deletedAt", "deletedBy", "archivedAt", "archivedBy"];
6
+ const IMMUTABLE_FIELDS = ["_id", "__v", "createdAt", "createdBy"];
7
7
  class VersionConflictError extends Error {
8
8
  code = "VERSION_CONFLICT";
9
9
  statusCode = 409;
@@ -147,7 +147,7 @@ class MongoRepository {
147
147
  try {
148
148
  const db = await this.dbClient.db(this.database);
149
149
  const collection = db.collection(this.collection);
150
- const { insertedId } = await collection.insertOne({ ...document, __v: 1 });
150
+ const { insertedId } = await collection.insertOne({ ...document, __v: 1 }, { ignoreUndefined: true });
151
151
  return { ...document, _id: insertedId, __v: 1 };
152
152
  } catch (error) {
153
153
  await this.report(error);
@@ -159,35 +159,63 @@ class MongoRepository {
159
159
  try {
160
160
  const db = await this.dbClient.db(this.database);
161
161
  const collection = db.collection(this.collection);
162
- const { insertedIds } = await collection.insertMany(documents);
162
+ const { insertedIds } = await collection.insertMany(documents.map((document) => ({ ...document, __v: 1 })), { ignoreUndefined: true });
163
163
  return insertedIds;
164
164
  } catch (error) {
165
165
  await this.report(error);
166
166
  throw error;
167
167
  }
168
168
  }
169
- async updateOne({ where, payload, expectedVersion, scope }) {
170
- if (!where || Object.keys(where).length === 0) throw new Error("[Mongo Repository] Where is required for updateOne operation");
171
- if (!payload || Object.keys(payload).length === 0) throw new Error("[Mongo Repository] Payload is required for updateOne operation");
169
+ async patchOne({ where, set, unset, expectedVersion, scope }) {
170
+ return this.applyPatch({ where, set, unset, expectedVersion, scope });
171
+ }
172
+ async archiveByPatch(params) {
173
+ const actor = this.actorId(params.scope);
174
+ return this.applyPatch(params, { archivedAt: /* @__PURE__ */ new Date(), ...actor ? { archivedBy: actor } : {} });
175
+ }
176
+ async applyPatch({ where, set, unset, expectedVersion, scope }, stamps = {}) {
177
+ if (!where || Object.keys(where).length === 0) throw new Error("[Mongo Repository] Where is required for patchOne operation");
172
178
  const actor = this.actorId(scope);
173
- const { _id, __v, createdAt, createdBy, toUnset, ...rest } = payload;
174
179
  const toSet = {
175
- ...this.withoutProtected(rest, scope),
176
- ...scope ? { updatedAt: /* @__PURE__ */ new Date(), ...actor ? { updatedBy: actor } : {} } : {}
180
+ ...this.withoutProtectedPaths(set ?? {}, scope),
181
+ ...scope ? { updatedAt: /* @__PURE__ */ new Date(), ...actor ? { updatedBy: actor } : {} } : {},
182
+ ...stamps
177
183
  };
184
+ const toUnset = this.withoutProtectedPaths(unset ?? {}, scope);
178
185
  return this.modifyOne(where, {
179
- ...toSet ? { $set: toSet } : {},
180
- ...toUnset ? { $unset: toUnset } : {}
186
+ $set: toSet,
187
+ ...Object.keys(toUnset).length ? { $unset: toUnset } : {}
181
188
  }, scope, expectedVersion);
182
189
  }
183
- async softDelete({ where, payload, scope }) {
190
+ async claimOne({ where, set, scope }) {
191
+ const filter = this.withScope({ ...where, ...this._where }, scope);
192
+ try {
193
+ const db = await this.dbClient.db(this.database);
194
+ const collection = db.collection(this.collection);
195
+ const result = await collection.findOneAndUpdate(
196
+ filter,
197
+ { $set: this.withoutProtectedPaths(set ?? {}, scope) },
198
+ { returnDocument: "before", ignoreUndefined: true }
199
+ );
200
+ return result;
201
+ } catch (error) {
202
+ await this.report(error);
203
+ throw error;
204
+ }
205
+ }
206
+ withoutProtectedPaths(fields, scope) {
207
+ const guarded = scope && !scope.trusted;
208
+ const isProtected = (key) => this.protectedFields.some((field) => key === field || key.startsWith(`${field}.`) || field.startsWith(`${key}.`));
209
+ return Object.fromEntries(Object.entries(fields).filter(([key]) => !IMMUTABLE_FIELDS.includes(key) && !(guarded && isProtected(key))));
210
+ }
211
+ async softDelete({ where, payload, unset, scope }) {
184
212
  if (!where || Object.keys(where).length === 0) throw new Error("[Mongo Repository] Where is required for softDelete operation");
185
213
  const actor = this.actorId(scope);
186
- const { toUnset, ...rest } = payload ?? {};
187
- const extra = this.withoutProtected(rest, scope);
214
+ const extra = this.withoutProtected(payload ?? {}, scope);
215
+ const toUnset = this.withoutProtectedPaths(unset ?? {}, scope);
188
216
  return this.modifyOne(where, {
189
217
  $set: { ...extra, deletedAt: /* @__PURE__ */ new Date(), ...actor ? { deletedBy: actor } : {} },
190
- ...toUnset ? { $unset: toUnset } : {}
218
+ ...Object.keys(toUnset).length ? { $unset: toUnset } : {}
191
219
  }, scope);
192
220
  }
193
221
  async modifyOne(where, update, scope, expectedVersion) {
@@ -199,7 +227,7 @@ class MongoRepository {
199
227
  const result = await collection.findOneAndUpdate(
200
228
  filter,
201
229
  { $inc: { __v: 1 }, ...update },
202
- { returnDocument: "after" }
230
+ { returnDocument: "after", ignoreUndefined: true }
203
231
  );
204
232
  if (!result && checkVersion) {
205
233
  const exists = await collection.findOne(this.withScope({ ...where, ...this._where }, scope), { projection: { _id: 1 } });
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  import { HttpError } from "../error/index.js";
3
2
  class Scope {
4
3
  constructor(kind, userId, reason) {
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  import { secretManager } from "./secret-manager";
3
2
  const DEFAULT_DATABASE_NAME = "openloops";
4
3
  const getDatabaseName = () => secretManager.get("OPENLOOPS_DB_NAME") || DEFAULT_DATABASE_NAME;
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  import { secretManager } from "./secret-manager";
3
2
  const numberSetting = (key, fallback) => {
4
3
  const value = Number(secretManager.get(key));
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  import "dotenv/config";
3
2
  import Cryptr from "cryptr";
4
3
  import { logger } from "../logger/index.js";
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  const agentActions = [
3
2
  { key: { ownerId: 1, taskId: 1 } }
4
3
  ];
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  const agentTasks = [
3
2
  { key: { ownerId: 1, chatId: 1 } }
4
3
  ];
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  const agentTraces = [
3
2
  { key: { ownerId: 1, chatId: 1 } }
4
3
  ];
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  const automationRuns = [
3
2
  { key: { automationId: 1, createdAt: -1 } },
4
3
  { key: { ownerId: 1, createdAt: -1 } },
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  const automations = [
3
2
  { key: { "triggers.schedule.enabled": 1, "triggers.schedule.nextRunAt": 1 } },
4
3
  { key: { ownerId: 1, createdAt: -1 } }
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  const chats = [
3
2
  { key: { ownerId: 1, updatedAt: -1 } }
4
3
  ];
@@ -32,6 +32,7 @@ var import_mcp_servers = require("./mcp-servers");
32
32
  var import_automations = require("./automations");
33
33
  var import_automation_runs = require("./automation-runs");
34
34
  var import_revoked_tokens = require("./revoked-tokens");
35
+ var import_refresh_tokens = require("./refresh-tokens");
35
36
  const indexes = {
36
37
  llm_calls: import_llm_calls.llmCalls,
37
38
  chats: import_chats.chats,
@@ -42,7 +43,8 @@ const indexes = {
42
43
  mcp_servers: import_mcp_servers.mcpServers,
43
44
  automations: import_automations.automations,
44
45
  automation_runs: import_automation_runs.automationRuns,
45
- revoked_tokens: import_revoked_tokens.revokedTokens
46
+ revoked_tokens: import_revoked_tokens.revokedTokens,
47
+ refresh_tokens: import_refresh_tokens.refreshTokens
46
48
  };
47
49
  async function ensureIndexes(db) {
48
50
  const created = {};
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  import { llmCalls } from "./llm-calls";
3
2
  import { chats } from "./chats";
4
3
  import { agentTasks } from "./agent-tasks";
@@ -9,6 +8,7 @@ import { mcpServers } from "./mcp-servers";
9
8
  import { automations } from "./automations";
10
9
  import { automationRuns } from "./automation-runs";
11
10
  import { revokedTokens } from "./revoked-tokens";
11
+ import { refreshTokens } from "./refresh-tokens";
12
12
  const indexes = {
13
13
  llm_calls: llmCalls,
14
14
  chats,
@@ -19,7 +19,8 @@ const indexes = {
19
19
  mcp_servers: mcpServers,
20
20
  automations,
21
21
  automation_runs: automationRuns,
22
- revoked_tokens: revokedTokens
22
+ revoked_tokens: revokedTokens,
23
+ refresh_tokens: refreshTokens
23
24
  };
24
25
  async function ensureIndexes(db) {
25
26
  const created = {};
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  const llmCalls = [
3
2
  { key: { ownerId: 1, createdAt: -1 } },
4
3
  { key: { sessionId: 1 } },
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  const mcpServers = [
3
2
  { key: { ownerId: 1 } }
4
3
  ];
@@ -0,0 +1,2 @@
1
+ import { IndexDescription } from 'mongodb';
2
+ export declare const refreshTokens: IndexDescription[];
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
6
10
  var __copyProps = (to, from, except, desc) => {
7
11
  if (from && typeof from === "object" || typeof from === "function") {
8
12
  for (let key of __getOwnPropNames(from))
@@ -11,12 +15,19 @@ var __copyProps = (to, from, except, desc) => {
11
15
  }
12
16
  return to;
13
17
  };
14
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
- var mask_in_logs_exports = {};
17
- module.exports = __toCommonJS(mask_in_logs_exports);
18
- __reExport(mask_in_logs_exports, require("./mask-in-logs"), module.exports);
19
+ var refresh_tokens_exports = {};
20
+ __export(refresh_tokens_exports, {
21
+ refreshTokens: () => refreshTokens
22
+ });
23
+ module.exports = __toCommonJS(refresh_tokens_exports);
24
+ const refreshTokens = [
25
+ { key: { tokenHash: 1 }, unique: true },
26
+ { key: { familyId: 1 } },
27
+ { key: { userId: 1 } },
28
+ { key: { expiresAt: 1 }, expireAfterSeconds: 24 * 60 * 60 }
29
+ ];
19
30
  // Annotate the CommonJS export names for ESM import in node:
20
31
  0 && (module.exports = {
21
- ...require("./mask-in-logs")
32
+ refreshTokens
22
33
  });
@@ -0,0 +1,9 @@
1
+ const refreshTokens = [
2
+ { key: { tokenHash: 1 }, unique: true },
3
+ { key: { familyId: 1 } },
4
+ { key: { userId: 1 } },
5
+ { key: { expiresAt: 1 }, expireAfterSeconds: 24 * 60 * 60 }
6
+ ];
7
+ export {
8
+ refreshTokens
9
+ };
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  const revokedTokens = [
3
2
  { key: { jti: 1 }, unique: true },
4
3
  { key: { expiresAt: 1 }, expireAfterSeconds: 0 }
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  const workspaceItems = [
3
2
  { key: { ownerId: 1, chatId: 1 } }
4
3
  ];
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  import { ensureIndexes } from "../indexes";
3
2
  const RENAMES = [
4
3
  ["agentic_jobs", "automations"],
@@ -1,4 +1,3 @@
1
- import "../chunk-CF3WOMB3.mjs";
2
1
  import { createHash } from "crypto";
3
2
  class Guard {
4
3
  name;
@@ -1,4 +1,3 @@
1
- import "../chunk-CF3WOMB3.mjs";
2
1
  export * from "./guard";
3
2
  import * as inputGuards from "./input";
4
3
  export {
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  import { Guard } from "../guard";
3
2
  const CANDIDATE = /\b(?:\d[ -]?){13,19}\b/g;
4
3
  function passesLuhn(digits) {
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  import { Guard } from "../guard";
3
2
  const FENCED = /(^|\n)[ \t]*(```|~~~)/;
4
3
  const blockCode = new Guard({
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  import { Guard } from "../guard";
3
2
  const EMAIL = /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}/i;
4
3
  const blockEmail = new Guard({
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  import { Guard } from "../guard";
3
2
  function createBlockInputOversize(max) {
4
3
  return new Guard({
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  import { Guard } from "../guard";
3
2
  const SEQUENCES = Buffer.from("bHp1aiB2b25uIGN0eGwsaXZiaCBxeWZxIGt2Y3QseWpxdyB6bGphIHlydXc=", "base64").toString().split(",").map((sequence) => sequence.split(" "));
4
3
  const WORDS = new RegExp(`\\b(?:${SEQUENCES.flat().join("|")})\\b`, "gi");
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  import { SIGNATURE } from "../../common/constants/index.js";
3
2
  import { Guard } from "../guard";
4
3
  const read = (value) => Buffer.from(value, "base64").toString();
@@ -1,4 +1,3 @@
1
- import "../chunk-CF3WOMB3.mjs";
2
1
  class AgentLoop {
3
2
  }
4
3
  export {
@@ -1,4 +1,3 @@
1
- import "../chunk-CF3WOMB3.mjs";
2
1
  var AgentStatus = /* @__PURE__ */ ((AgentStatus2) => {
3
2
  AgentStatus2["IDLE"] = "idle";
4
3
  AgentStatus2["FAILED"] = "failed";
@@ -1,4 +1,3 @@
1
- import 'reflect-metadata';
2
1
  import { CurrentUser, CurrentSession } from '../common/base/index.js';
3
2
  import { McpServer } from '../services/mcp-servers/entities/index.js';
4
3
  import { Chat } from '../services/chats/entities/chat.entity.js';
@@ -22,7 +22,6 @@ __export(agent_exports, {
22
22
  Agent: () => Agent
23
23
  });
24
24
  module.exports = __toCommonJS(agent_exports);
25
- var import_reflect_metadata = require("reflect-metadata");
26
25
  var import_mongodb = require("mongodb");
27
26
  var import_logger = require("../common/logger/index.js");
28
27
  var import_entities = require("../services/mcp-servers/entities/index.js");
@@ -108,7 +107,7 @@ class Agent {
108
107
  static async createChatSession(currentUser, loop) {
109
108
  if (!currentUser) throw new Error("[AGENT] CurrentUser is required to create a new chat");
110
109
  const newChat = import_chat.Chat.withDefaults(loop?.name);
111
- const { data } = await (0, import_chats.createChat)({
110
+ const data = await (0, import_chats.createChat)({
112
111
  payload: newChat.toJSON(),
113
112
  currentUser
114
113
  });
@@ -232,7 +231,7 @@ class Agent {
232
231
  async preRunner(chatId) {
233
232
  let chatData;
234
233
  if (chatId) {
235
- const { data } = await (0, import_chats.getChatById)({ id: chatId, currentUser: this.currentUser });
234
+ const data = await (0, import_chats.getChatById)({ id: chatId, currentUser: this.currentUser });
236
235
  chatData = data?._id ? data : void 0;
237
236
  }
238
237
  if (!chatData) {
@@ -394,16 +393,16 @@ Ref: ${guard.ref}`, { source: "harness", excludeFromContext: true });
394
393
  }
395
394
  }
396
395
  fingerprint(entity) {
397
- return JSON.stringify(entity.toDocument());
396
+ return JSON.stringify(entity.toJSON());
398
397
  }
399
398
  async loadTasks() {
400
399
  const chatId = this.currentChat._id?.toString();
401
400
  if (!chatId) return;
402
- const { data: taskDocs } = await (0, import_tasks.listAgentTasksByChat)({ chatId, currentUser: this.currentUser });
401
+ const { items: taskDocs } = await (0, import_tasks.listAgentTasksByChat)({ chatId, currentUser: this.currentUser });
403
402
  const tasks = taskDocs.map((doc) => import_agent_task.AgentTask.fromJSON(doc)).reverse();
404
403
  const activeTaskId = this.currentChat.state?.activeTaskId;
405
404
  if (activeTaskId && !tasks.some((task) => task.id === activeTaskId)) {
406
- const { data } = await (0, import_tasks.getAgentTaskById)({ id: activeTaskId, currentUser: this.currentUser });
405
+ const data = await (0, import_tasks.getAgentTaskById)({ id: activeTaskId, currentUser: this.currentUser });
407
406
  if (data) tasks.push(import_agent_task.AgentTask.fromJSON(data));
408
407
  }
409
408
  for (const task of tasks) {
@@ -418,8 +417,8 @@ Ref: ${guard.ref}`, { source: "harness", excludeFromContext: true });
418
417
  }
419
418
  async hydrateTask(task) {
420
419
  if (task.hydrated) return;
421
- const { data } = await (0, import_tasks.listAgentActionsByTask)({ taskId: task.id, currentUser: this.currentUser });
422
- const actions = data.map((doc) => import_agent_action.AgentAction.fromJSON(doc));
420
+ const { items } = await (0, import_tasks.listAgentActionsByTask)({ taskId: task.id, currentUser: this.currentUser });
421
+ const actions = items.map((doc) => import_agent_action.AgentAction.fromJSON(doc));
423
422
  for (const action of actions) this.snapshots.set(`action:${action.id}`, this.fingerprint(action));
424
423
  task.setActions(actions);
425
424
  }
@@ -493,7 +492,7 @@ Ref: ${guard.ref}`, { source: "harness", excludeFromContext: true });
493
492
  try {
494
493
  const response = await (0, import_mcp_servers.listAllMcpServersByUser)({ currentUser: this.currentUser });
495
494
  const reserved = new Set(this._internalMcps.map((mcp) => mcp.name));
496
- const stored = (response?.data ?? []).filter((props) => {
495
+ const stored = response.items.filter((props) => {
497
496
  if (!reserved.has(props.name)) return true;
498
497
  this.logger.error({ mcpServer: props.name }, "[AGENT] A server of the user was ignored because its name belongs to an internal MCP");
499
498
  this.currentChat?.addTrace({ node: "agent", kind: "agent", reasoning: `A server of the user was ignored because its name belongs to an internal MCP: ${props.name}` });
@@ -598,7 +597,7 @@ Ref: ${guard.ref}`, { source: "harness", excludeFromContext: true });
598
597
  entry.hash = live.hash;
599
598
  if (entry.server.latest?.hash !== live.hash) {
600
599
  try {
601
- const { data } = await (0, import_mcp_servers.verifyMcpServerConnection)({ id: entry.id, currentUser: this.currentUser });
600
+ const data = await (0, import_mcp_servers.verifyMcpServerConnection)({ id: entry.id, currentUser: this.currentUser });
602
601
  this.refreshMcpServer(entry, data);
603
602
  } catch (error) {
604
603
  this.logger.error({ error: error?.message ?? error, mcpServer: entry.name }, "[AGENT] Failed to verify MCP server");
@@ -680,7 +679,7 @@ Ref: ${guard.ref}`, { source: "harness", excludeFromContext: true });
680
679
  }
681
680
  async decideMcp(entry, decision, manifestHash) {
682
681
  try {
683
- const { data } = await (0, import_mcp_servers.decideMcpServerTrust)({ id: entry.id, decision, manifestHash, currentUser: this.currentUser });
682
+ const data = await (0, import_mcp_servers.decideMcpServerTrust)({ id: entry.id, decision, manifestHash, currentUser: this.currentUser });
684
683
  this.refreshMcpServer(entry, data);
685
684
  return true;
686
685
  } catch (error) {
@@ -727,17 +726,18 @@ Ref: ${guard.ref}`, { source: "harness", excludeFromContext: true });
727
726
  }
728
727
  const id = this.currentChat._id.toString();
729
728
  const payload = this.currentChat.toJSON();
729
+ const unset = { ...this.currentChat.clearedFields };
730
730
  const key = `chat:${id}`;
731
- const current = JSON.stringify(payload);
731
+ const current = JSON.stringify({ payload, unset });
732
732
  if (this.snapshots.get(key) === current) return;
733
733
  this.logger.debug("[AGENT] Updating chat...");
734
- await (0, import_chats.updateChat)({ id, payload, currentUser: this.currentUser });
734
+ await (0, import_chats.updateChat)({ id, payload, unset, currentUser: this.currentUser });
735
735
  this.snapshots.set(key, current);
736
736
  }
737
737
  async checkInterruptionRequest() {
738
738
  const chatId = this.currentChat?._id?.toString();
739
739
  if (!chatId) return;
740
- const { data } = await (0, import_chats.getChatById)({ id: chatId, select: { state: 1 }, currentUser: this.currentUser });
740
+ const data = await (0, import_chats.getChatById)({ id: chatId, select: { state: 1 }, currentUser: this.currentUser });
741
741
  if (data?.state?.stopRequested) this.stopRequested = true;
742
742
  }
743
743
  async runLoop() {