openloops 0.5.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 (547) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/README.md +3 -2
  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 +7 -25
  14. package/dist/common/base/base.entity.js +26 -133
  15. package/dist/common/base/base.entity.mjs +26 -128
  16. package/dist/common/base/base.use-case.d.ts +3 -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/index.d.ts +1 -0
  21. package/dist/common/base/index.js +3 -1
  22. package/dist/common/base/index.mjs +1 -0
  23. package/dist/common/base/share.d.ts +12 -0
  24. package/dist/common/base/share.js +45 -0
  25. package/dist/common/base/share.mjs +20 -0
  26. package/dist/common/base/utils/index.d.ts +1 -2
  27. package/dist/common/base/utils/index.js +2 -4
  28. package/dist/common/base/utils/index.mjs +1 -2
  29. package/dist/common/base/utils/is-plain-object.mjs +0 -1
  30. package/dist/common/base/utils/to-patch.d.ts +9 -0
  31. package/dist/common/base/utils/to-patch.js +46 -0
  32. package/dist/common/base/utils/to-patch.mjs +21 -0
  33. package/dist/common/constants/harness.mjs +0 -1
  34. package/dist/common/error/http-error.mjs +0 -1
  35. package/dist/common/error/reportError.mjs +0 -1
  36. package/dist/common/error/sentry-client.mjs +0 -1
  37. package/dist/common/helpers/escape-regex.mjs +0 -1
  38. package/dist/common/helpers/extract-json-from-text.mjs +0 -1
  39. package/dist/common/helpers/sanitize-string.mjs +0 -1
  40. package/dist/common/logger/pino.mjs +0 -1
  41. package/dist/common/repositories/index.d.ts +1 -0
  42. package/dist/common/repositories/index.js +3 -1
  43. package/dist/common/repositories/index.mjs +1 -0
  44. package/dist/common/repositories/mongo-db.client.mjs +0 -1
  45. package/dist/common/repositories/mongo-db.repository.d.ts +42 -11
  46. package/dist/common/repositories/mongo-db.repository.js +152 -42
  47. package/dist/common/repositories/mongo-db.repository.mjs +152 -43
  48. package/dist/common/repositories/scope.d.ts +19 -0
  49. package/dist/common/repositories/scope.js +63 -0
  50. package/dist/common/repositories/scope.mjs +39 -0
  51. package/dist/common/utils/database-name.mjs +0 -1
  52. package/dist/common/utils/number-setting.mjs +0 -1
  53. package/dist/common/utils/secret-manager.mjs +0 -1
  54. package/dist/db/indexes/agent-actions.mjs +0 -1
  55. package/dist/db/indexes/agent-tasks.mjs +0 -1
  56. package/dist/db/indexes/agent-traces.mjs +0 -1
  57. package/dist/db/indexes/automation-runs.mjs +0 -1
  58. package/dist/db/indexes/automations.mjs +0 -1
  59. package/dist/db/indexes/chats.mjs +0 -1
  60. package/dist/db/indexes/index.js +3 -1
  61. package/dist/db/indexes/index.mjs +3 -2
  62. package/dist/db/indexes/llm-calls.mjs +0 -1
  63. package/dist/db/indexes/mcp-servers.mjs +0 -1
  64. package/dist/db/indexes/refresh-tokens.d.ts +2 -0
  65. package/dist/{common/decorators/admin-only/index.js → db/indexes/refresh-tokens.js} +16 -5
  66. package/dist/db/indexes/refresh-tokens.mjs +9 -0
  67. package/dist/db/indexes/revoked-tokens.mjs +0 -1
  68. package/dist/db/indexes/workspace-items.mjs +0 -1
  69. package/dist/db/migrations/automations.mjs +0 -1
  70. package/dist/guardrails/guard.mjs +0 -1
  71. package/dist/guardrails/index.mjs +0 -1
  72. package/dist/guardrails/input/block-card.mjs +0 -1
  73. package/dist/guardrails/input/block-code.mjs +0 -1
  74. package/dist/guardrails/input/block-email.mjs +0 -1
  75. package/dist/guardrails/input/create-block-input-oversize.mjs +0 -1
  76. package/dist/guardrails/input/diagnostic-sanity.mjs +0 -1
  77. package/dist/guardrails/input/input-check.mjs +0 -1
  78. package/dist/harness/agent-loop.mjs +0 -1
  79. package/dist/harness/agent-state.mjs +0 -1
  80. package/dist/harness/agent.d.ts +0 -1
  81. package/dist/harness/agent.js +14 -14
  82. package/dist/harness/agent.mjs +14 -15
  83. package/dist/harness/native-tools.mjs +0 -1
  84. package/dist/harness/skills/approval-request.mjs +0 -1
  85. package/dist/harness/skills/autonomous-answer.mjs +0 -1
  86. package/dist/harness/skills/confirmation-gate.mjs +0 -1
  87. package/dist/harness/skills/mcp-change-review.mjs +0 -1
  88. package/dist/harness/tool-catalog.mjs +0 -1
  89. package/dist/harness/tool-pipeline.mjs +0 -1
  90. package/dist/harness/utils/activity.mjs +0 -1
  91. package/dist/harness/utils/describe-shape.mjs +0 -1
  92. package/dist/harness/utils/grounding.mjs +0 -1
  93. package/dist/harness/utils/rank-tools-by-keywords.mjs +0 -1
  94. package/dist/harness/workspace.js +7 -7
  95. package/dist/harness/workspace.mjs +7 -8
  96. package/dist/loops/agi/loop.mjs +0 -1
  97. package/dist/loops/agi/skills/reasoning-engine.mjs +0 -1
  98. package/dist/loops/shared/skills/fast-responder.mjs +0 -1
  99. package/dist/services/authentication/entities/index.d.ts +1 -0
  100. package/dist/services/authentication/entities/index.js +3 -1
  101. package/dist/services/authentication/entities/index.mjs +1 -0
  102. package/dist/services/authentication/entities/refresh-token.entity.d.ts +25 -0
  103. package/dist/services/authentication/entities/refresh-token.entity.js +75 -0
  104. package/dist/services/authentication/entities/refresh-token.entity.mjs +51 -0
  105. package/dist/services/authentication/entities/revoked-token.entity.mjs +0 -1
  106. package/dist/services/authentication/helpers/auth-config.d.ts +9 -0
  107. package/dist/{common/decorators/owner-only/index.js → services/authentication/helpers/auth-config.js} +19 -5
  108. package/dist/services/authentication/helpers/auth-config.mjs +12 -0
  109. package/dist/services/authentication/helpers/session-tokens.d.ts +16 -0
  110. package/dist/services/authentication/helpers/session-tokens.js +60 -0
  111. package/dist/services/authentication/helpers/session-tokens.mjs +35 -0
  112. package/dist/services/authentication/helpers/tokens.d.ts +43 -0
  113. package/dist/services/authentication/helpers/tokens.js +113 -0
  114. package/dist/services/authentication/helpers/tokens.mjs +71 -0
  115. package/dist/services/authentication/index.d.ts +3 -0
  116. package/dist/services/authentication/index.js +23 -0
  117. package/dist/services/authentication/index.mjs +11 -0
  118. package/dist/services/authentication/module.d.ts +12 -3
  119. package/dist/services/authentication/module.js +40 -7
  120. package/dist/services/authentication/module.mjs +34 -7
  121. package/dist/services/authentication/repositories/index.d.ts +1 -0
  122. package/dist/services/authentication/repositories/index.js +3 -1
  123. package/dist/services/authentication/repositories/index.mjs +1 -0
  124. package/dist/services/authentication/repositories/refresh-token.repository.d.ts +10 -0
  125. package/dist/services/authentication/repositories/refresh-token.repository.js +60 -0
  126. package/dist/services/authentication/repositories/refresh-token.repository.mjs +36 -0
  127. package/dist/services/authentication/repositories/revoked-token.repository.d.ts +3 -3
  128. package/dist/services/authentication/repositories/revoked-token.repository.js +9 -20
  129. package/dist/services/authentication/repositories/revoked-token.repository.mjs +9 -15
  130. package/dist/services/authentication/use-cases/claim-refresh-token.use-case.d.ts +12 -0
  131. package/dist/services/authentication/use-cases/claim-refresh-token.use-case.js +40 -0
  132. package/dist/services/authentication/use-cases/claim-refresh-token.use-case.mjs +16 -0
  133. package/dist/services/authentication/use-cases/create-refresh-token.use-case.d.ts +11 -0
  134. package/dist/services/authentication/use-cases/create-refresh-token.use-case.js +43 -0
  135. package/dist/services/authentication/use-cases/create-refresh-token.use-case.mjs +19 -0
  136. package/dist/services/authentication/use-cases/find-refresh-token-by-hash.use-case.d.ts +11 -0
  137. package/dist/services/authentication/use-cases/find-refresh-token-by-hash.use-case.js +40 -0
  138. package/dist/services/authentication/use-cases/find-refresh-token-by-hash.use-case.mjs +16 -0
  139. package/dist/services/authentication/use-cases/is-token-revoked.use-case.d.ts +6 -8
  140. package/dist/services/authentication/use-cases/is-token-revoked.use-case.js +6 -19
  141. package/dist/services/authentication/use-cases/is-token-revoked.use-case.mjs +6 -14
  142. package/dist/services/authentication/use-cases/issue-password-reset-token.use-case.d.ts +18 -0
  143. package/dist/services/authentication/use-cases/issue-password-reset-token.use-case.js +49 -0
  144. package/dist/services/authentication/use-cases/issue-password-reset-token.use-case.mjs +25 -0
  145. package/dist/services/authentication/use-cases/issue-session.use-case.d.ts +13 -0
  146. package/dist/services/authentication/use-cases/issue-session.use-case.js +48 -0
  147. package/dist/services/authentication/use-cases/issue-session.use-case.mjs +24 -0
  148. package/dist/services/authentication/use-cases/login.use-case.d.ts +11 -11
  149. package/dist/services/authentication/use-cases/login.use-case.js +18 -53
  150. package/dist/services/authentication/use-cases/login.use-case.mjs +18 -38
  151. package/dist/services/authentication/use-cases/logout.use-case.d.ts +14 -0
  152. package/dist/services/authentication/use-cases/logout.use-case.js +48 -0
  153. package/dist/services/authentication/use-cases/logout.use-case.mjs +24 -0
  154. package/dist/services/authentication/use-cases/refresh.use-case.d.ts +23 -0
  155. package/dist/services/authentication/use-cases/refresh.use-case.js +84 -0
  156. package/dist/services/authentication/use-cases/refresh.use-case.mjs +60 -0
  157. package/dist/services/authentication/use-cases/reset-password.use-case.d.ts +15 -0
  158. package/dist/services/authentication/use-cases/reset-password.use-case.js +61 -0
  159. package/dist/services/authentication/use-cases/reset-password.use-case.mjs +37 -0
  160. package/dist/services/authentication/use-cases/revoke-refresh-token-family.use-case.d.ts +11 -0
  161. package/dist/services/authentication/use-cases/revoke-refresh-token-family.use-case.js +40 -0
  162. package/dist/services/authentication/use-cases/revoke-refresh-token-family.use-case.mjs +16 -0
  163. package/dist/services/authentication/use-cases/revoke-token.use-case.d.ts +4 -6
  164. package/dist/services/authentication/use-cases/revoke-token.use-case.js +12 -25
  165. package/dist/services/authentication/use-cases/revoke-token.use-case.mjs +11 -19
  166. package/dist/services/authentication/use-cases/revoke-user-refresh-tokens.use-case.d.ts +13 -0
  167. package/dist/services/authentication/use-cases/revoke-user-refresh-tokens.use-case.js +40 -0
  168. package/dist/services/authentication/use-cases/revoke-user-refresh-tokens.use-case.mjs +16 -0
  169. package/dist/services/automations/entities/automation-run.entity.mjs +0 -1
  170. package/dist/services/automations/entities/automation.entity.d.ts +1 -0
  171. package/dist/services/automations/entities/automation.entity.js +2 -1
  172. package/dist/services/automations/entities/automation.entity.mjs +2 -2
  173. package/dist/services/automations/entities/recurrence.mjs +0 -1
  174. package/dist/services/automations/entities/trigger.mjs +0 -1
  175. package/dist/services/automations/module.d.ts +0 -1
  176. package/dist/services/automations/module.js +20 -22
  177. package/dist/services/automations/module.mjs +20 -23
  178. package/dist/services/automations/repositories/automation-run.repository.d.ts +10 -10
  179. package/dist/services/automations/repositories/automation-run.repository.js +26 -38
  180. package/dist/services/automations/repositories/automation-run.repository.mjs +26 -33
  181. package/dist/services/automations/repositories/automation.repository.d.ts +14 -13
  182. package/dist/services/automations/repositories/automation.repository.js +52 -54
  183. package/dist/services/automations/repositories/automation.repository.mjs +52 -49
  184. package/dist/services/automations/runner/automation-runner.d.ts +3 -0
  185. package/dist/services/automations/runner/automation-runner.js +8 -9
  186. package/dist/services/automations/runner/automation-runner.mjs +8 -10
  187. package/dist/services/automations/use-cases/attach-automation-run-chat.use-case.d.ts +4 -6
  188. package/dist/services/automations/use-cases/attach-automation-run-chat.use-case.js +8 -21
  189. package/dist/services/automations/use-cases/attach-automation-run-chat.use-case.mjs +8 -16
  190. package/dist/services/automations/use-cases/claim-due-automations.use-case.d.ts +9 -11
  191. package/dist/services/automations/use-cases/claim-due-automations.use-case.js +11 -26
  192. package/dist/services/automations/use-cases/claim-due-automations.use-case.mjs +11 -21
  193. package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.d.ts +9 -11
  194. package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.js +13 -28
  195. package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.mjs +13 -23
  196. package/dist/services/automations/use-cases/create-automation.use-case.d.ts +4 -6
  197. package/dist/services/automations/use-cases/create-automation.use-case.js +7 -22
  198. package/dist/services/automations/use-cases/create-automation.use-case.mjs +6 -16
  199. package/dist/services/automations/use-cases/delete-automation.use-case.d.ts +6 -6
  200. package/dist/services/automations/use-cases/delete-automation.use-case.js +10 -27
  201. package/dist/services/automations/use-cases/delete-automation.use-case.mjs +9 -21
  202. package/dist/services/automations/use-cases/finish-automation-run.use-case.d.ts +5 -7
  203. package/dist/services/automations/use-cases/finish-automation-run.use-case.js +9 -23
  204. package/dist/services/automations/use-cases/finish-automation-run.use-case.mjs +9 -18
  205. package/dist/services/automations/use-cases/get-automation-by-id.use-case.d.ts +4 -6
  206. package/dist/services/automations/use-cases/get-automation-by-id.use-case.js +8 -21
  207. package/dist/services/automations/use-cases/get-automation-by-id.use-case.mjs +7 -15
  208. package/dist/services/automations/use-cases/issue-automation-event-token.use-case.d.ts +7 -9
  209. package/dist/services/automations/use-cases/issue-automation-event-token.use-case.js +8 -22
  210. package/dist/services/automations/use-cases/issue-automation-event-token.use-case.mjs +7 -16
  211. package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.d.ts +6 -6
  212. package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.js +8 -20
  213. package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.mjs +8 -15
  214. package/dist/services/automations/use-cases/list-automation-runs-by-user.use-case.d.ts +6 -6
  215. package/dist/services/automations/use-cases/list-automation-runs-by-user.use-case.js +7 -19
  216. package/dist/services/automations/use-cases/list-automation-runs-by-user.use-case.mjs +7 -14
  217. package/dist/services/automations/use-cases/list-automations-by-user.use-case.d.ts +6 -6
  218. package/dist/services/automations/use-cases/list-automations-by-user.use-case.js +7 -19
  219. package/dist/services/automations/use-cases/list-automations-by-user.use-case.mjs +7 -14
  220. package/dist/services/automations/use-cases/preview-automation-runs.use-case.d.ts +4 -6
  221. package/dist/services/automations/use-cases/preview-automation-runs.use-case.js +3 -15
  222. package/dist/services/automations/use-cases/preview-automation-runs.use-case.mjs +3 -10
  223. package/dist/services/automations/use-cases/receive-automation-event.use-case.d.ts +8 -10
  224. package/dist/services/automations/use-cases/receive-automation-event.use-case.js +15 -29
  225. package/dist/services/automations/use-cases/receive-automation-event.use-case.mjs +15 -24
  226. package/dist/services/automations/use-cases/renew-automation-lease.use-case.d.ts +6 -8
  227. package/dist/services/automations/use-cases/renew-automation-lease.use-case.js +6 -19
  228. package/dist/services/automations/use-cases/renew-automation-lease.use-case.mjs +6 -14
  229. package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.d.ts +6 -8
  230. package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.js +10 -23
  231. package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.mjs +10 -18
  232. package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.d.ts +4 -6
  233. package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.js +11 -25
  234. package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.mjs +10 -19
  235. package/dist/services/automations/use-cases/start-automation-run.use-case.d.ts +8 -10
  236. package/dist/services/automations/use-cases/start-automation-run.use-case.js +12 -25
  237. package/dist/services/automations/use-cases/start-automation-run.use-case.mjs +12 -20
  238. package/dist/services/automations/use-cases/sync-automation-run.use-case.d.ts +5 -7
  239. package/dist/services/automations/use-cases/sync-automation-run.use-case.js +13 -27
  240. package/dist/services/automations/use-cases/sync-automation-run.use-case.mjs +13 -22
  241. package/dist/services/automations/use-cases/sync-automation-runs.use-case.d.ts +8 -10
  242. package/dist/services/automations/use-cases/sync-automation-runs.use-case.js +8 -22
  243. package/dist/services/automations/use-cases/sync-automation-runs.use-case.mjs +8 -17
  244. package/dist/services/automations/use-cases/update-automation.use-case.d.ts +4 -6
  245. package/dist/services/automations/use-cases/update-automation.use-case.js +13 -26
  246. package/dist/services/automations/use-cases/update-automation.use-case.mjs +12 -20
  247. package/dist/services/automations/utils/automation-event-error.mjs +0 -1
  248. package/dist/services/automations/utils/automation-fields.mjs +0 -1
  249. package/dist/services/automations/utils/event-message.mjs +0 -1
  250. package/dist/services/automations/utils/event-token.d.ts +1 -2
  251. package/dist/services/automations/utils/event-token.js +9 -35
  252. package/dist/services/automations/utils/event-token.mjs +9 -25
  253. package/dist/services/automations/utils/next-run.mjs +0 -1
  254. package/dist/services/automations/utils/open-run.d.ts +2 -0
  255. package/dist/services/automations/utils/open-run.js +2 -2
  256. package/dist/services/automations/utils/open-run.mjs +2 -3
  257. package/dist/services/automations/utils/previous-run.js +4 -3
  258. package/dist/services/automations/utils/previous-run.mjs +4 -4
  259. package/dist/services/automations/utils/runner-scope.d.ts +3 -0
  260. package/dist/{common/base/utils/flatten-object.js → services/automations/utils/runner-scope.js} +10 -23
  261. package/dist/services/automations/utils/runner-scope.mjs +7 -0
  262. package/dist/services/automations/utils/settings.mjs +0 -1
  263. package/dist/services/chats/entities/chat-message.entity.mjs +0 -1
  264. package/dist/services/chats/entities/chat-settings.entity.mjs +0 -1
  265. package/dist/services/chats/entities/chat.entity.d.ts +1 -0
  266. package/dist/services/chats/entities/chat.entity.js +3 -2
  267. package/dist/services/chats/entities/chat.entity.mjs +3 -3
  268. package/dist/services/chats/module.d.ts +0 -1
  269. package/dist/services/chats/module.js +5 -7
  270. package/dist/services/chats/module.mjs +5 -8
  271. package/dist/services/chats/repositories/chat.repository.d.ts +7 -6
  272. package/dist/services/chats/repositories/chat.repository.js +19 -29
  273. package/dist/services/chats/repositories/chat.repository.mjs +19 -24
  274. package/dist/services/chats/use-cases/create-chat.use-case.d.ts +4 -6
  275. package/dist/services/chats/use-cases/create-chat.use-case.js +7 -22
  276. package/dist/services/chats/use-cases/create-chat.use-case.mjs +6 -16
  277. package/dist/services/chats/use-cases/delete-chat.use-case.d.ts +6 -6
  278. package/dist/services/chats/use-cases/delete-chat.use-case.js +10 -26
  279. package/dist/services/chats/use-cases/delete-chat.use-case.mjs +9 -20
  280. package/dist/services/chats/use-cases/get-chat-by-id.use-case.d.ts +4 -6
  281. package/dist/services/chats/use-cases/get-chat-by-id.use-case.js +8 -21
  282. package/dist/services/chats/use-cases/get-chat-by-id.use-case.mjs +8 -16
  283. package/dist/services/chats/use-cases/interrupt-execution.use-case.d.ts +4 -6
  284. package/dist/services/chats/use-cases/interrupt-execution.use-case.js +8 -24
  285. package/dist/services/chats/use-cases/interrupt-execution.use-case.mjs +7 -18
  286. package/dist/services/chats/use-cases/list-chats-by-props.use-case.d.ts +6 -6
  287. package/dist/services/chats/use-cases/list-chats-by-props.use-case.js +7 -20
  288. package/dist/services/chats/use-cases/list-chats-by-props.use-case.mjs +7 -15
  289. package/dist/services/chats/use-cases/list-chats-by-user.use-case.d.ts +6 -6
  290. package/dist/services/chats/use-cases/list-chats-by-user.use-case.js +7 -19
  291. package/dist/services/chats/use-cases/list-chats-by-user.use-case.mjs +7 -14
  292. package/dist/services/chats/use-cases/update-chat.use-case.d.ts +5 -6
  293. package/dist/services/chats/use-cases/update-chat.use-case.js +10 -30
  294. package/dist/services/chats/use-cases/update-chat.use-case.mjs +9 -24
  295. package/dist/services/chats/utils/deprecated-activity.mjs +0 -1
  296. package/dist/services/llmcalls/entities/llmcall.entity.mjs +0 -1
  297. package/dist/services/llmcalls/module.d.ts +0 -1
  298. package/dist/services/llmcalls/module.js +4 -6
  299. package/dist/services/llmcalls/module.mjs +4 -7
  300. package/dist/services/llmcalls/repositories/llmcall.repository.d.ts +7 -6
  301. package/dist/services/llmcalls/repositories/llmcall.repository.js +19 -29
  302. package/dist/services/llmcalls/repositories/llmcall.repository.mjs +19 -24
  303. package/dist/services/llmcalls/use-cases/create-llmcall.use-case.d.ts +4 -6
  304. package/dist/services/llmcalls/use-cases/create-llmcall.use-case.js +7 -22
  305. package/dist/services/llmcalls/use-cases/create-llmcall.use-case.mjs +6 -16
  306. package/dist/services/llmcalls/use-cases/delete-llmcall.use-case.d.ts +6 -6
  307. package/dist/services/llmcalls/use-cases/delete-llmcall.use-case.js +10 -26
  308. package/dist/services/llmcalls/use-cases/delete-llmcall.use-case.mjs +9 -20
  309. package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.d.ts +4 -6
  310. package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.js +8 -21
  311. package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.mjs +7 -15
  312. package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.d.ts +4 -6
  313. package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.js +8 -21
  314. package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.mjs +7 -15
  315. package/dist/services/llmcalls/use-cases/get-llm-usage-stats.use-case.d.ts +4 -6
  316. package/dist/services/llmcalls/use-cases/get-llm-usage-stats.use-case.js +6 -19
  317. package/dist/services/llmcalls/use-cases/get-llm-usage-stats.use-case.mjs +6 -14
  318. package/dist/services/llmcalls/use-cases/get-llmcall-by-id.use-case.d.ts +4 -6
  319. package/dist/services/llmcalls/use-cases/get-llmcall-by-id.use-case.js +9 -21
  320. package/dist/services/llmcalls/use-cases/get-llmcall-by-id.use-case.mjs +8 -15
  321. package/dist/services/llmcalls/use-cases/list-llmcalls-by-props.use-case.d.ts +6 -6
  322. package/dist/services/llmcalls/use-cases/list-llmcalls-by-props.use-case.js +7 -20
  323. package/dist/services/llmcalls/use-cases/list-llmcalls-by-props.use-case.mjs +7 -15
  324. package/dist/services/llmcalls/use-cases/update-llmcall.use-case.d.ts +4 -6
  325. package/dist/services/llmcalls/use-cases/update-llmcall.use-case.js +9 -25
  326. package/dist/services/llmcalls/use-cases/update-llmcall.use-case.mjs +8 -19
  327. package/dist/services/llmcalls/utils/usage-periods.mjs +0 -1
  328. package/dist/services/llmcalls/utils/usage-totals.mjs +0 -1
  329. package/dist/services/mcp-servers/entities/mcp-manifest.mjs +0 -1
  330. package/dist/services/mcp-servers/entities/mcpserver.entity.mjs +0 -1
  331. package/dist/services/mcp-servers/module.d.ts +0 -1
  332. package/dist/services/mcp-servers/module.js +8 -10
  333. package/dist/services/mcp-servers/module.mjs +8 -11
  334. package/dist/services/mcp-servers/repositories/mcpserver.repository.d.ts +8 -7
  335. package/dist/services/mcp-servers/repositories/mcpserver.repository.js +21 -31
  336. package/dist/services/mcp-servers/repositories/mcpserver.repository.mjs +21 -26
  337. package/dist/services/mcp-servers/use-cases/create-mcpserver.use-case.d.ts +5 -7
  338. package/dist/services/mcp-servers/use-cases/create-mcpserver.use-case.js +7 -24
  339. package/dist/services/mcp-servers/use-cases/create-mcpserver.use-case.mjs +6 -18
  340. package/dist/services/mcp-servers/use-cases/decide-mcpserver-trust.use-case.d.ts +4 -6
  341. package/dist/services/mcp-servers/use-cases/decide-mcpserver-trust.use-case.js +11 -26
  342. package/dist/services/mcp-servers/use-cases/decide-mcpserver-trust.use-case.mjs +10 -20
  343. package/dist/services/mcp-servers/use-cases/delete-mcpserver.use-case.d.ts +6 -6
  344. package/dist/services/mcp-servers/use-cases/delete-mcpserver.use-case.js +10 -26
  345. package/dist/services/mcp-servers/use-cases/delete-mcpserver.use-case.mjs +9 -20
  346. package/dist/services/mcp-servers/use-cases/get-mcpserver-by-id.use-case.d.ts +4 -6
  347. package/dist/services/mcp-servers/use-cases/get-mcpserver-by-id.use-case.js +8 -21
  348. package/dist/services/mcp-servers/use-cases/get-mcpserver-by-id.use-case.mjs +7 -15
  349. package/dist/services/mcp-servers/use-cases/list-all-mcpservers-by-user.use-case.d.ts +6 -6
  350. package/dist/services/mcp-servers/use-cases/list-all-mcpservers-by-user.use-case.js +7 -20
  351. package/dist/services/mcp-servers/use-cases/list-all-mcpservers-by-user.use-case.mjs +6 -14
  352. package/dist/services/mcp-servers/use-cases/list-mcpservers-by-user.use-case.d.ts +6 -6
  353. package/dist/services/mcp-servers/use-cases/list-mcpservers-by-user.use-case.js +5 -19
  354. package/dist/services/mcp-servers/use-cases/list-mcpservers-by-user.use-case.mjs +5 -14
  355. package/dist/services/mcp-servers/use-cases/update-mcpserver.use-case.d.ts +5 -7
  356. package/dist/services/mcp-servers/use-cases/update-mcpserver.use-case.js +12 -31
  357. package/dist/services/mcp-servers/use-cases/update-mcpserver.use-case.mjs +11 -25
  358. package/dist/services/mcp-servers/use-cases/verify-mcpserver-connection.use-case.d.ts +4 -6
  359. package/dist/services/mcp-servers/use-cases/verify-mcpserver-connection.use-case.js +13 -27
  360. package/dist/services/mcp-servers/use-cases/verify-mcpserver-connection.use-case.mjs +12 -21
  361. package/dist/services/tasks/entities/agent-action.entity.mjs +0 -1
  362. package/dist/services/tasks/entities/agent-task.entity.mjs +0 -1
  363. package/dist/services/tasks/module.d.ts +0 -1
  364. package/dist/services/tasks/module.js +7 -9
  365. package/dist/services/tasks/module.mjs +7 -10
  366. package/dist/services/tasks/repositories/agent-action.repository.d.ts +4 -4
  367. package/dist/services/tasks/repositories/agent-action.repository.js +12 -26
  368. package/dist/services/tasks/repositories/agent-action.repository.mjs +12 -21
  369. package/dist/services/tasks/repositories/agent-task.repository.d.ts +5 -5
  370. package/dist/services/tasks/repositories/agent-task.repository.js +14 -28
  371. package/dist/services/tasks/repositories/agent-task.repository.mjs +14 -23
  372. package/dist/services/tasks/use-cases/create-agent-action.use-case.d.ts +4 -6
  373. package/dist/services/tasks/use-cases/create-agent-action.use-case.js +7 -22
  374. package/dist/services/tasks/use-cases/create-agent-action.use-case.mjs +6 -16
  375. package/dist/services/tasks/use-cases/create-agent-task.use-case.d.ts +4 -6
  376. package/dist/services/tasks/use-cases/create-agent-task.use-case.js +7 -22
  377. package/dist/services/tasks/use-cases/create-agent-task.use-case.mjs +6 -16
  378. package/dist/services/tasks/use-cases/get-agent-task-by-id.use-case.d.ts +4 -6
  379. package/dist/services/tasks/use-cases/get-agent-task-by-id.use-case.js +8 -21
  380. package/dist/services/tasks/use-cases/get-agent-task-by-id.use-case.mjs +7 -15
  381. package/dist/services/tasks/use-cases/list-agent-actions-by-task.use-case.d.ts +6 -6
  382. package/dist/services/tasks/use-cases/list-agent-actions-by-task.use-case.js +8 -20
  383. package/dist/services/tasks/use-cases/list-agent-actions-by-task.use-case.mjs +8 -15
  384. package/dist/services/tasks/use-cases/list-agent-tasks-by-chat.use-case.d.ts +6 -6
  385. package/dist/services/tasks/use-cases/list-agent-tasks-by-chat.use-case.js +8 -20
  386. package/dist/services/tasks/use-cases/list-agent-tasks-by-chat.use-case.mjs +8 -15
  387. package/dist/services/tasks/use-cases/update-agent-action.use-case.d.ts +4 -6
  388. package/dist/services/tasks/use-cases/update-agent-action.use-case.js +8 -24
  389. package/dist/services/tasks/use-cases/update-agent-action.use-case.mjs +7 -18
  390. package/dist/services/tasks/use-cases/update-agent-task.use-case.d.ts +4 -6
  391. package/dist/services/tasks/use-cases/update-agent-task.use-case.js +8 -24
  392. package/dist/services/tasks/use-cases/update-agent-task.use-case.mjs +7 -18
  393. package/dist/services/traces/entities/agent-trace-entry.entity.mjs +0 -1
  394. package/dist/services/traces/module.d.ts +0 -1
  395. package/dist/services/traces/module.js +2 -4
  396. package/dist/services/traces/module.mjs +2 -5
  397. package/dist/services/traces/repositories/agent-trace.repository.d.ts +3 -3
  398. package/dist/services/traces/repositories/agent-trace.repository.js +8 -19
  399. package/dist/services/traces/repositories/agent-trace.repository.mjs +8 -14
  400. package/dist/services/traces/use-cases/create-agent-traces.use-case.d.ts +6 -8
  401. package/dist/services/traces/use-cases/create-agent-traces.use-case.js +8 -26
  402. package/dist/services/traces/use-cases/create-agent-traces.use-case.mjs +7 -20
  403. package/dist/services/traces/use-cases/list-agent-traces-by-chat.use-case.d.ts +6 -6
  404. package/dist/services/traces/use-cases/list-agent-traces-by-chat.use-case.js +8 -20
  405. package/dist/services/traces/use-cases/list-agent-traces-by-chat.use-case.mjs +8 -15
  406. package/dist/services/users/entities/user-acquisition.js +4 -17
  407. package/dist/services/users/entities/user-acquisition.mjs +4 -12
  408. package/dist/services/users/entities/user-country.js +2 -2
  409. package/dist/services/users/entities/user-country.mjs +2 -3
  410. package/dist/services/users/entities/user-currency.js +2 -2
  411. package/dist/services/users/entities/user-currency.mjs +2 -3
  412. package/dist/services/users/entities/user-default-model.js +2 -2
  413. package/dist/services/users/entities/user-default-model.mjs +2 -3
  414. package/dist/services/users/entities/user-email.value-object.mjs +0 -1
  415. package/dist/services/users/entities/user-language.js +2 -2
  416. package/dist/services/users/entities/user-language.mjs +2 -3
  417. package/dist/services/users/entities/user-marketing.js +4 -17
  418. package/dist/services/users/entities/user-marketing.mjs +4 -12
  419. package/dist/services/users/entities/user-notification-preferences.mjs +0 -1
  420. package/dist/services/users/entities/user-password.value-object.mjs +0 -1
  421. package/dist/services/users/entities/user-permissions.mjs +0 -1
  422. package/dist/services/users/entities/user-preferences.mjs +0 -1
  423. package/dist/services/users/entities/user-report-preferences.mjs +0 -1
  424. package/dist/services/users/entities/user-report-schedule.mjs +0 -1
  425. package/dist/services/users/entities/user-timezone.js +2 -2
  426. package/dist/services/users/entities/user-timezone.mjs +2 -3
  427. package/dist/services/users/entities/user.entity.d.ts +1 -0
  428. package/dist/services/users/entities/user.entity.js +9 -25
  429. package/dist/services/users/entities/user.entity.mjs +9 -20
  430. package/dist/services/users/module.d.ts +2 -1
  431. package/dist/services/users/module.js +12 -7
  432. package/dist/services/users/module.mjs +11 -8
  433. package/dist/services/users/repositories/user.repository.d.ts +10 -7
  434. package/dist/services/users/repositories/user.repository.js +34 -29
  435. package/dist/services/users/repositories/user.repository.mjs +34 -24
  436. package/dist/services/users/use-cases/change-password.use-case.d.ts +15 -0
  437. package/dist/services/users/use-cases/change-password.use-case.js +52 -0
  438. package/dist/services/users/use-cases/change-password.use-case.mjs +28 -0
  439. package/dist/services/users/use-cases/create-user.use-case.d.ts +4 -7
  440. package/dist/services/users/use-cases/create-user.use-case.js +8 -22
  441. package/dist/services/users/use-cases/create-user.use-case.mjs +7 -16
  442. package/dist/services/users/use-cases/delete-user.use-case.d.ts +6 -6
  443. package/dist/services/users/use-cases/delete-user.use-case.js +10 -26
  444. package/dist/services/users/use-cases/delete-user.use-case.mjs +9 -20
  445. package/dist/services/users/use-cases/get-user-by-id.use-case.d.ts +4 -6
  446. package/dist/services/users/use-cases/get-user-by-id.use-case.js +9 -21
  447. package/dist/services/users/use-cases/get-user-by-id.use-case.mjs +8 -15
  448. package/dist/services/users/use-cases/list-users-by-props.use-case.d.ts +6 -6
  449. package/dist/services/users/use-cases/list-users-by-props.use-case.js +7 -20
  450. package/dist/services/users/use-cases/list-users-by-props.use-case.mjs +7 -15
  451. package/dist/services/users/use-cases/update-user.use-case.d.ts +4 -6
  452. package/dist/services/users/use-cases/update-user.use-case.js +11 -26
  453. package/dist/services/users/use-cases/update-user.use-case.mjs +10 -20
  454. package/dist/services/users/utils/default-model.mjs +0 -1
  455. package/dist/services/workspaces/entities/workspace-item.entity.mjs +0 -1
  456. package/dist/services/workspaces/module.d.ts +0 -1
  457. package/dist/services/workspaces/module.js +5 -7
  458. package/dist/services/workspaces/module.mjs +5 -8
  459. package/dist/services/workspaces/repositories/workspace-item.repository.d.ts +8 -8
  460. package/dist/services/workspaces/repositories/workspace-item.repository.js +20 -32
  461. package/dist/services/workspaces/repositories/workspace-item.repository.mjs +20 -27
  462. package/dist/services/workspaces/use-cases/delete-workspace-item.use-case.d.ts +6 -8
  463. package/dist/services/workspaces/use-cases/delete-workspace-item.use-case.js +11 -22
  464. package/dist/services/workspaces/use-cases/delete-workspace-item.use-case.mjs +10 -16
  465. package/dist/services/workspaces/use-cases/get-workspace-item.use-case.d.ts +4 -6
  466. package/dist/services/workspaces/use-cases/get-workspace-item.use-case.js +8 -21
  467. package/dist/services/workspaces/use-cases/get-workspace-item.use-case.mjs +7 -15
  468. package/dist/services/workspaces/use-cases/list-workspace-items.use-case.d.ts +6 -6
  469. package/dist/services/workspaces/use-cases/list-workspace-items.use-case.js +7 -19
  470. package/dist/services/workspaces/use-cases/list-workspace-items.use-case.mjs +7 -14
  471. package/dist/services/workspaces/use-cases/save-workspace-item.use-case.d.ts +4 -6
  472. package/dist/services/workspaces/use-cases/save-workspace-item.use-case.js +14 -28
  473. package/dist/services/workspaces/use-cases/save-workspace-item.use-case.mjs +13 -22
  474. package/dist/services/workspaces/use-cases/search-workspace-items.use-case.d.ts +6 -6
  475. package/dist/services/workspaces/use-cases/search-workspace-items.use-case.js +7 -19
  476. package/dist/services/workspaces/use-cases/search-workspace-items.use-case.mjs +7 -14
  477. package/dist/skills/call-modes.mjs +0 -1
  478. package/dist/skills/runtime-context.mjs +0 -1
  479. package/dist/skills/shared/shared-rules.mjs +0 -1
  480. package/dist/skills/skill.js +1 -2
  481. package/dist/skills/skill.mjs +1 -3
  482. package/dist/tools/core/call-ai/call-ai.skill.mjs +0 -1
  483. package/dist/tools/core/call-ai/call-ai.tool.mjs +0 -1
  484. package/dist/tools/core/slack/send-slack-message.tool.mjs +0 -1
  485. package/dist/tools/core/web-search/web-search.tool.mjs +0 -1
  486. package/dist/tools/tool.mjs +0 -1
  487. package/docs/README.md +2 -1
  488. package/docs/authentication.md +95 -16
  489. package/docs/authorization.md +77 -0
  490. package/docs/automations.md +10 -9
  491. package/docs/chats.md +1 -1
  492. package/docs/configuration.md +1 -1
  493. package/docs/integration-guide.md +9 -11
  494. package/docs/llms.txt +1 -0
  495. package/docs/mcp-servers.md +1 -1
  496. package/docs/usage.md +5 -5
  497. package/docs/users.md +7 -5
  498. package/examples/authentication/login.ts +1 -1
  499. package/examples/automations/create-automation.ts +1 -1
  500. package/examples/automations/create-event-automation.ts +2 -2
  501. package/examples/automations/list-automation-runs.ts +4 -2
  502. package/examples/automations/list-automations.ts +1 -1
  503. package/examples/automations/preview-automation-runs.ts +1 -1
  504. package/examples/automations/receive-automation-event.ts +1 -1
  505. package/examples/automations/revoke-automation-event-token.ts +2 -2
  506. package/examples/automations/run-automation-now.ts +3 -1
  507. package/examples/automations/update-automation.ts +2 -2
  508. package/examples/chats/delete-chat.ts +1 -1
  509. package/examples/chats/get-chat-by-id.ts +2 -2
  510. package/examples/chats/list-autonomous-chats.ts +1 -1
  511. package/examples/chats/list-chats.ts +1 -1
  512. package/examples/mcps/decide-mcp.ts +3 -3
  513. package/examples/mcps/list-all-mcps.ts +1 -1
  514. package/examples/mcps/verify-mcp.ts +1 -1
  515. package/examples/usage/get-chat-usage.ts +2 -2
  516. package/examples/usage/get-message-usage.ts +2 -2
  517. package/examples/usage/get-usage-stats-by-range.ts +1 -1
  518. package/examples/usage/get-usage-stats.ts +3 -3
  519. package/examples/users/create-user.ts +2 -1
  520. package/examples/users/list-users.ts +1 -0
  521. package/examples/users/set-default-model.ts +1 -1
  522. package/package.json +2 -4
  523. package/dist/chunk-CF3WOMB3.mjs +0 -16
  524. package/dist/common/base/utils/delete-empty-fields.d.ts +0 -1
  525. package/dist/common/base/utils/delete-empty-fields.js +0 -66
  526. package/dist/common/base/utils/delete-empty-fields.mjs +0 -43
  527. package/dist/common/base/utils/flatten-object.d.ts +0 -1
  528. package/dist/common/base/utils/flatten-object.mjs +0 -22
  529. package/dist/common/decorators/admin-only/admin-only.d.ts +0 -2
  530. package/dist/common/decorators/admin-only/admin-only.js +0 -52
  531. package/dist/common/decorators/admin-only/admin-only.mjs +0 -28
  532. package/dist/common/decorators/admin-only/index.d.ts +0 -1
  533. package/dist/common/decorators/admin-only/index.mjs +0 -1
  534. package/dist/common/decorators/index.d.ts +0 -3
  535. package/dist/common/decorators/index.js +0 -26
  536. package/dist/common/decorators/index.mjs +0 -3
  537. package/dist/common/decorators/mask-in-logs/index.d.ts +0 -1
  538. package/dist/common/decorators/mask-in-logs/index.js +0 -22
  539. package/dist/common/decorators/mask-in-logs/index.mjs +0 -1
  540. package/dist/common/decorators/mask-in-logs/mask-in-logs.d.ts +0 -2
  541. package/dist/common/decorators/mask-in-logs/mask-in-logs.js +0 -53
  542. package/dist/common/decorators/mask-in-logs/mask-in-logs.mjs +0 -29
  543. package/dist/common/decorators/owner-only/index.d.ts +0 -1
  544. package/dist/common/decorators/owner-only/index.mjs +0 -1
  545. package/dist/common/decorators/owner-only/owner-only.d.ts +0 -2
  546. package/dist/common/decorators/owner-only/owner-only.js +0 -52
  547. package/dist/common/decorators/owner-only/owner-only.mjs +0 -28
@@ -23,7 +23,6 @@ __export(skill_exports, {
23
23
  SkillMode: () => import_call_modes2.SkillMode
24
24
  });
25
25
  module.exports = __toCommonJS(skill_exports);
26
- var import_tsyringe = require("tsyringe");
27
26
  var import_helpers = require("../common/helpers/index.js");
28
27
  var import_llm_client = require("../clients/llm/llm-client.js");
29
28
  var import_logger = require("../common/logger/index.js");
@@ -58,7 +57,7 @@ class Skill {
58
57
  if (misplaced.length) throw new Error(`[SKILL:${this.name}] ${misplaced.join(", ")} must be passed as run options, not inside contextInjection`);
59
58
  if (history.length && chatHistory.length) throw new Error(`[SKILL:${this.name}] history and chatHistory cannot be used together`);
60
59
  try {
61
- const llmClient = import_tsyringe.container.resolve(import_llm_client.LLMClient);
60
+ const llmClient = new import_llm_client.LLMClient();
62
61
  const context = {
63
62
  ...(0, import_runtime_context.buildRuntimeContext)({ currentUser, currentSession, chat }),
64
63
  ...contextInjection
@@ -1,5 +1,3 @@
1
- import "../chunk-CF3WOMB3.mjs";
2
- import { container } from "tsyringe";
3
1
  import { extractJSON } from "../common/helpers/index.js";
4
2
  import { LLMClient } from "../clients/llm/llm-client.js";
5
3
  import { Logger } from "../common/logger/index.js";
@@ -34,7 +32,7 @@ class Skill {
34
32
  if (misplaced.length) throw new Error(`[SKILL:${this.name}] ${misplaced.join(", ")} must be passed as run options, not inside contextInjection`);
35
33
  if (history.length && chatHistory.length) throw new Error(`[SKILL:${this.name}] history and chatHistory cannot be used together`);
36
34
  try {
37
- const llmClient = container.resolve(LLMClient);
35
+ const llmClient = new LLMClient();
38
36
  const context = {
39
37
  ...buildRuntimeContext({ currentUser, currentSession, chat }),
40
38
  ...contextInjection
@@ -1,4 +1,3 @@
1
- import "../../../chunk-CF3WOMB3.mjs";
2
1
  import { Skill } from "../../../skills/skill.js";
3
2
  import { FORMATTING, LATEX_FORMATTING, CITATION_FORMATTING } from "../../../skills/shared/shared-rules.js";
4
3
  const callAiSkill = new Skill({
@@ -1,4 +1,3 @@
1
- import "../../../chunk-CF3WOMB3.mjs";
2
1
  import { callAiSkill } from "./call-ai.skill";
3
2
  import { Tool } from "../../tool";
4
3
  const callAiTool = new Tool({
@@ -1,4 +1,3 @@
1
- import "../../../chunk-CF3WOMB3.mjs";
2
1
  import { Tool } from "../../tool";
3
2
  import { SlackClient } from "../../../clients/slack/slack-client.js";
4
3
  const sendSlackMessageTool = new Tool({
@@ -1,4 +1,3 @@
1
- import "../../../chunk-CF3WOMB3.mjs";
2
1
  import { Tool } from "../../tool";
3
2
  import {
4
3
  SerperClient
@@ -1,4 +1,3 @@
1
- import "../chunk-CF3WOMB3.mjs";
2
1
  import { numberSetting } from "../common/utils/number-setting.js";
3
2
  function schemaTypes(node) {
4
3
  if (!node) return [];
package/docs/README.md CHANGED
@@ -6,7 +6,8 @@ Start with the [README](../README.md) for what `openloops` is and how to run it.
6
6
 
7
7
  | Page | What it covers |
8
8
  | --- | --- |
9
- | [Integration guide](integration-guide.md) | What to write in a backend: which endpoint calls what, the authorization you own and a security checklist. |
9
+ | [Integration guide](integration-guide.md) | What to write in a backend: which endpoint calls what, what you still own and a security checklist. |
10
+ | [Authorization](authorization.md) | How the use cases check who owns a record, the scopes and how to migrate from 0.5. |
10
11
 
11
12
  ## Run an agent
12
13
 
@@ -1,11 +1,36 @@
1
1
  # Authentication
2
2
 
3
- `openloops` can log a user in against its own user records and issue a token. Verifying that token on each request, and deciding who may call what, is up to your backend.
3
+ `openloops` logs a user in against its own user records and issues the tokens of the session. It also issues the tokens to reset a password and the tokens of [event automations](automations.md#the-token), all with the same convention. Verifying the token on each request and deciding who may call what is up to your backend, with `verifySessionToken` to read it.
4
4
 
5
5
  ```typescript
6
- import { login, revokeToken, isTokenRevoked } from 'openloops/authentication'
6
+ import { login, refreshSession, logout, issuePasswordResetToken, resetPassword, revokeUserSessions, revokeToken, isTokenRevoked, verifySessionToken } from 'openloops/authentication'
7
+ import { changePassword } from 'openloops/users'
7
8
  ```
8
9
 
10
+ `JWT_SECRET` must be set. See [configuration](configuration.md).
11
+
12
+ **Rate limit is yours.** `openloops` does not limit the attempts to log in, to ask for a reset or to use a token. Your backend must do it before it calls `login` and `issuePasswordResetToken`, by account and by address, and answer 429 when the limit is reached.
13
+
14
+ ## The tokens
15
+
16
+ Every token is a JWT signed with `HS256` and `JWT_SECRET`, and carries the same claims:
17
+
18
+ | Claim | Value |
19
+ | --- | --- |
20
+ | `iss` | `openloops`. A token without it, or with another one, is refused. |
21
+ | `aud` | What the token is for: `session`, `password-reset` or `automation-event`. A token is only valid for its own audience. |
22
+ | `sub` | The id of the user, or the id of the automation for an event token. |
23
+ | `jti` | A unique id, only in the tokens that can be revoked one by one: reset and event tokens. |
24
+ | `exp` | When it stops working. |
25
+
26
+ | Token | Audience | Duration | Extra claims |
27
+ | --- | --- | --- | --- |
28
+ | Access of a session | `session` | 1 hour | `email`, `firstName`, `lastName`, `sid` (the id of the session) |
29
+ | Reset of the password | `password-reset` | 15 minutes | `jti` |
30
+ | Event of an automation | `automation-event` | The one you choose, or none | `jti`, `v` |
31
+
32
+ The refresh token is not a JWT: it is a random string, and only its hash is stored.
33
+
9
34
  ## Logging in
10
35
 
11
36
  ```typescript
@@ -16,42 +41,96 @@ const result = await login({
16
41
  },
17
42
  })
18
43
 
19
- result.data.token
20
- result.data.user
44
+ result.accessToken
45
+ result.refreshToken
46
+ result.expiresIn
47
+ result.refreshExpiresAt
48
+ result.user
21
49
  ```
22
50
 
23
- - `token` is a JWT signed with `JWT_SECRET`. Its payload carries `userId`, `email`, `firstName` and `lastName`.
24
- - Tokens last 1 hour for admins and 7 days for everyone else.
51
+ - `accessToken` lasts 1 hour. `refreshToken` lasts 30 days for a user and 7 days for an admin, and a session cannot be extended beyond 90 days (7 for an admin), no matter how often it is refreshed.
25
52
  - `user` is the user record without the password.
26
- - An unknown user fails with a 404 and a wrong password with a 401.
53
+ - A missing field fails with 400. An unknown user and a wrong password fail with the same 401, so the answer does not tell which accounts exist.
27
54
 
28
- `JWT_SECRET` must be set. See [configuration](configuration.md).
55
+ ## Keeping the session
56
+
57
+ ```typescript
58
+ const next = await refreshSession({ refreshToken })
59
+ ```
60
+
61
+ - It gives a new access token and a new refresh token, and the old refresh token cannot be used again. All of them belong to one session.
62
+ - A refresh token that was used is accepted again for 10 seconds, to survive a retry of the client. Later than that, it is taken as stolen: the whole session is closed and the next refresh fails with 401.
63
+ - It fails with 401 for an unknown, expired or revoked token, and when the user no longer exists.
64
+ - Two refreshes at the same time with the same token do not create two sessions.
65
+
66
+ ```typescript
67
+ await logout({ refreshToken })
68
+ ```
69
+
70
+ Closes the session of that refresh token. An unknown or missing token is ignored.
71
+
72
+ ```typescript
73
+ await revokeUserSessions({ userId, now: new Date(), exceptFamilyId })
74
+ ```
75
+
76
+ Closes every session of the user, except the one you name. `changePassword` and `resetPassword` do it for you.
29
77
 
30
78
  ## From a token to a `CurrentUser`
31
79
 
32
- After your backend verifies the token, build the `CurrentUser` that every other call needs:
80
+ Your backend reads the access token, and builds the `CurrentUser` that every other call needs:
33
81
 
34
82
  ```typescript
83
+ import { verifySessionToken } from 'openloops/authentication'
35
84
  import { CurrentUser } from 'openloops/base'
36
85
 
37
- const currentUser = await CurrentUser.asyncFromDB(payload.userId)
86
+ const claims = verifySessionToken(token)
87
+ const currentUser = await CurrentUser.asyncFromDB(claims.userId)
88
+ ```
89
+
90
+ `verifySessionToken` throws a `TokenError` whose `reason` is `invalid` or `expired`. It refuses a token of another audience, so a reset token or an event token cannot be used as a session. See [users](users.md).
91
+
92
+ ## Resetting a password
93
+
94
+ `openloops` does not send emails. It issues the token, and your backend sends the link:
95
+
96
+ ```typescript
97
+ const issued = await issuePasswordResetToken({ payload: { emailOrUsername } })
98
+
99
+ if (issued) await sendEmail(issued.user.email, `https://example.com/reset?token=${issued.token}`)
38
100
  ```
39
101
 
40
- See [users](users.md).
102
+ - It answers `null` when the user does not exist. Answer the same to the client in both cases, so nobody can learn which accounts exist.
103
+ - The token lasts 15 minutes and works once.
104
+
105
+ ```typescript
106
+ await resetPassword({ token, password })
107
+ ```
108
+
109
+ - It fails with 401 for a token that is invalid, expired, already used, or that is not a reset token, and with 400 if there is no password.
110
+ - It changes the password and closes every session of the user.
111
+
112
+ ```typescript
113
+ await changePassword({ id, password, sessionId, currentUser })
114
+ ```
115
+
116
+ For a user that changes their own password while logged in. It closes the other sessions and keeps the one in `sessionId` (the `sessionId` that `verifySessionToken` gives). `updateUser` refuses a `password`: this is the only way to change it.
41
117
 
42
118
  ## Revoked tokens
43
119
 
44
120
  A signed token cannot be taken back, so `openloops` keeps a list of the ids (`jti`) of the tokens that must stop working, in the collection `revoked_tokens`.
45
121
 
46
122
  ```typescript
47
- await revokeToken({ payload: { jti, audience: 'automation-event', subject: automationId, expiresAt }, currentUser })
123
+ const isFirstTime = await revokeToken({ payload: { jti, audience: 'automation-event', subject: automationId, expiresAt } })
48
124
 
49
- const { data } = await isTokenRevoked({ jti })
125
+ const data = await isTokenRevoked({ jti })
50
126
 
51
127
  data.revoked
52
128
  ```
53
129
 
54
- - Revoking the same `jti` twice does nothing. `expiresAt` is optional: when it is set, the entry is deleted by itself on that date, which is when the token would have stopped working anyway.
55
- - Today only the tokens of [event automations](automations.md#the-token) use it, through `revokeAutomationEventToken`, and the use case of events checks the list for you.
56
- - The tokens of `login` carry no `jti`, and `openloops` does not verify them, your backend does. To revoke sessions you would add a `jti` when the token is signed and call `isTokenRevoked` in the middleware of your backend. That is not done by the package.
130
+ - Revoking the same `jti` twice does nothing and answers `false`. `expiresAt` is optional: when it is set, the entry is deleted by itself on that date, which is when the token would have stopped working anyway.
131
+ - Reset tokens use it so they work once, and event tokens use it through `revokeAutomationEventToken`.
132
+ - The access token of a session has no `jti`: to cut a session, close it with `logout` or `revokeUserSessions`. The access token still works until it expires, at most one hour.
133
+
134
+ ## Collections
57
135
 
136
+ `refresh_tokens` and `revoked_tokens` are created by `ensureIndexes` (see [configuration](configuration.md)). If another backend shares the database and uses the same convention, both read and write the same documents.
@@ -0,0 +1,77 @@
1
+ # Authorization
2
+
3
+ > **Breaking change.** Since this version every call that creates, reads or writes a record needs the `currentUser`, or a `scope` you build yourself. The calls that worked without one, or that created a record for the user in the payload, now fail with 401. Read [what changes when you create records](#creating-records) and the [migration steps](#migrating-from-05).
4
+
5
+ Every use case that reads or writes a record of a user checks who owns it. The check is not in a controller, it is in the repository, inside the same query that reads or writes the record, so it does not cost an extra read and cannot be forgotten.
6
+
7
+ ## The scope
8
+
9
+ A `Scope` tells the repository on whose behalf it works. Use cases build one from the `currentUser` you pass:
10
+
11
+ | Scope | Used for | Reaches |
12
+ | --- | --- | --- |
13
+ | `Scope.canView(currentUser)` | Reading. | The records of the user. |
14
+ | `Scope.canEdit(currentUser)` | Creating and updating. | The records of the user. |
15
+ | `Scope.canManage(currentUser)` | Deleting, issuing and revoking tokens. | The records of the user. |
16
+ | `Scope.asAdmin(currentUser)` | Actions of an administrator. | Every record. It fails with 403 if the user is not an admin. |
17
+ | `Scope.system('reason')` | Workers, webhooks and flows without a user. | Every record. The reason is required. |
18
+
19
+ An admin does not get more access by being an admin. A use case called with an admin as `currentUser` still works on the records of that admin. To work on any record, build the scope yourself and pass it:
20
+
21
+ ```typescript
22
+ import { Scope } from 'openloops/base'
23
+
24
+ await deleteChat({ id, currentUser, scope: Scope.asAdmin(currentUser) })
25
+ ```
26
+
27
+ Every use case accepts `scope`. Use it only from code you wrote, never from a value that comes from a request.
28
+
29
+ ## Creating records
30
+
31
+ Every `create...` use case (`createChat`, `createMcpServer`, `createAutomation`, `createUser`, `createLLMCall`, `createAgentTask`, `createAgentAction`, `createAgentTraces`, `saveWorkspaceItem`) now takes the owner and the author from the scope, not from the payload:
32
+
33
+ - With a user scope, the new record belongs to the `currentUser`. `ownerId`, `createdBy`, `createdAt` and the other fields of control are set by the repository, and the ones you put in the payload are discarded. You cannot create a record for another user by sending his `ownerId`.
34
+ - To create a record for someone else, or without a user (a sign up, a webhook, a worker), pass a trusted scope: `Scope.system('reason')` or `Scope.asAdmin(currentUser)`. The payload is kept as you send it, and `ownerId` is the one you send. With `system` there is no `createdBy`, unless you send it.
35
+ - Without `currentUser` and without `scope` the call fails with 401. Before, `createChat` and the others created the record without an owner.
36
+ - The record that returns has its `_id`, `ownerId`, `createdAt` and `createdBy`.
37
+
38
+ ```typescript
39
+ await createChat({ payload, currentUser })
40
+
41
+ await createUser({ payload, scope: Scope.system('sign up') })
42
+
43
+ await createAutomation({ payload: { ...payload, ownerId: otherUserId }, scope: Scope.asAdmin(currentUser) })
44
+ ```
45
+
46
+ ## What changes in your endpoints
47
+
48
+ - A record that is not the user's is answered as if it did not exist. The functions that update or delete throw a 404 `HttpError` with the message `{{resource_not_found}}`, and the getters return `null` or throw the same 404. Nobody can learn that an id exists by getting a 403.
49
+ - A call without `currentUser` and without `scope` fails with 401, it does not read everything.
50
+ - You do not need to load the record to check `ownerId` before calling a function that takes an id.
51
+
52
+ ## What the repository does with the fields of control
53
+
54
+ When a user writes, the repository removes `ownerId`, `sharedWith`, `createdAt`, `createdBy`, `updatedAt`, `updatedBy`, `deletedAt`, `deletedBy`, `archivedAt`, `archivedBy` and `__v` from the payload, and fills them in itself with the user of the scope. In the users collection it also removes `role`, `marketing.drawNumber` and `acquisition.referrerCode`. A `system` or `admin` scope keeps the payload as it is, because the code that uses it is trusted.
55
+
56
+ So `createUser` no longer has `sanitize`. Pass the scope that says who is creating the account:
57
+
58
+ ```typescript
59
+ await createUser({ payload, scope: Scope.system('sign up') })
60
+ ```
61
+
62
+ ## Sharing
63
+
64
+ `sharedWith` is a list of `{ userId, permission }` where `permission` is `read`, `write` or `manage`. Nothing reads it yet: while no one is shared, the three user scopes only reach the records of the owner.
65
+
66
+ ## Migrating from 0.5
67
+
68
+ - Pass `currentUser`, or a `scope`, to every function that reads or writes the records of a user: the ones that take an id (`getChatById`, `updateChat`, `deleteChat`, `getMcpServerById`, `updateMcpServer`, `deleteMcpServer`, `decideMcpServerTrust`, `verifyMcpServerConnection`, `getUserById`, `updateUser`, `deleteUser`, `updateAutomation`, `deleteAutomation`), the ones that create (see [creating records](#creating-records)), the ones that list and the usage reports (`getLLMUsageByChat`, `getLLMUsageByMessage` and `getLLMUsageStats`). Many of them accepted a call without a user before and did not check the owner. `getAutomationById`, `listAutomationRunsByAutomation`, `startAutomationRun` and `runner.runNow` did not read the user at all.
69
+ - You do not need to pass anything to `login`, `revokeToken`, `isTokenRevoked`, `previewAutomationRuns` and `receiveAutomationEvent`, which do not belong to a user, nor to the functions of the runner (`claimDueAutomations`, `claimQueuedAutomationRuns`, `finishAutomationRun`, `syncAutomationRun`, `syncAutomationRuns`, `attachAutomationRunChat` and `renewAutomationLease`), which use their own system scope.
70
+ - Pass `currentUser` to `getAutomationById`, `listAutomationRunsByAutomation`, `startAutomationRun` and `runner.runNow`. They did not need it before.
71
+ - Replace `sanitize: false` in `createUser` with a `scope`, as shown above.
72
+ - Where an admin used to act on the record of another user, pass `scope: Scope.asAdmin(currentUser)`.
73
+ - `issueAutomationEventToken`, `revokeAutomationEventToken` and `rotateAutomationEventTokens` are for the owner. They used to accept an admin.
74
+ - Expect a 404 where you got a 403 for the records of other users, and remove the ownership checks you wrote before calling a function with an id.
75
+ - Hard delete is for `Scope.asAdmin` or `Scope.system` only.
76
+ - `BaseEntity` no longer has `setOwner`, `setCreatedBy`, `setUpdatedBy`, `setDeletedBy` or `setArchivedBy`, and the `AdminOnly` and `OwnerOnly` decorators are gone. The repository does that work.
77
+ - `sharedWith` is now a list of `{ userId, permission }` and not a list of ids.
@@ -41,7 +41,7 @@ const result = await createAutomation({
41
41
  currentUser,
42
42
  })
43
43
 
44
- result.data.triggers.schedule.nextRunAt
44
+ result.triggers.schedule.nextRunAt
45
45
  ```
46
46
 
47
47
  | Field | Required | What it is |
@@ -101,7 +101,7 @@ The recurrence of a `schedule` trigger is stored as a structured value, so a scr
101
101
  ### Previewing
102
102
 
103
103
  ```typescript
104
- const { data } = await previewAutomationRuns({
104
+ const data = await previewAutomationRuns({
105
105
  recurrence: { type: 'weekly', days: [1, 5], time: '08:00' },
106
106
  timezone: 'America/New_York',
107
107
  count: 5,
@@ -145,7 +145,7 @@ await deleteAutomation({ id, currentUser })
145
145
  An automation with an event trigger runs when another system sends it an event, for example an alarm of AWS that reaches a Lambda, which calls your backend. The event becomes a run in a queue and the runner executes it as soon as it can.
146
146
 
147
147
  ```typescript
148
- const { data: automation } = await createAutomation({
148
+ const automation = await createAutomation({
149
149
  payload: {
150
150
  name: 'Cost anomaly analysis',
151
151
  instructions: 'Find the cause of the cost alert in AWS and send a summary to the channel #costs',
@@ -154,7 +154,7 @@ const { data: automation } = await createAutomation({
154
154
  currentUser,
155
155
  })
156
156
 
157
- const { data } = await issueAutomationEventToken({ id: String(automation._id), expiresIn: '90d', currentUser })
157
+ const data = await issueAutomationEventToken({ id: String(automation._id), expiresIn: '90d', currentUser })
158
158
 
159
159
  data.token
160
160
  data.expiresAt
@@ -167,7 +167,7 @@ import { AutomationEventError, receiveAutomationEvent } from 'openloops/automati
167
167
 
168
168
  app.post('/automations/events/:automationId', async (req, res) => {
169
169
  try {
170
- const { data } = await receiveAutomationEvent({
170
+ const data = await receiveAutomationEvent({
171
171
  automationId: req.params.automationId,
172
172
  token: req.headers.authorization?.replace(/^Bearer /, ''),
173
173
  payload: req.body,
@@ -211,10 +211,11 @@ The instructions are the first message, as in any run. When the run comes from a
211
211
 
212
212
  ### The token
213
213
 
214
- The token is a JWT signed with `JWT_SECRET`. It is not stored: the owner or an admin can ask for it as many times as they want, and every one is different and valid.
214
+ The token is a JWT signed with `JWT_SECRET`. It is not stored: the owner can ask for it as many times as they want, and every one is different and valid.
215
215
 
216
216
  | Claim | Value |
217
217
  | --- | --- |
218
+ | `iss` | `openloops`, like every token of the package (see [authentication](authentication.md#the-tokens)). |
218
219
  | `aud` | `automation-event`. A session token of a user is refused, and this one does not log anybody in. |
219
220
  | `sub` | The id of the automation. It must be the one of the URL. |
220
221
  | `v` | The `eventTokenVersion` of the automation when the token was issued. |
@@ -245,7 +246,7 @@ A revoked token is checked after its signature, so an invalid token never reache
245
246
  Every execution is a run.
246
247
 
247
248
  ```typescript
248
- const byAutomation = await listAutomationRunsByAutomation({ automationId, options: { page: 1, limit: 20 } })
249
+ const byAutomation = await listAutomationRunsByAutomation({ automationId, options: { page: 1, limit: 20 }, currentUser })
249
250
 
250
251
  const byUser = await listAutomationRunsByUser({ status: 'failed', currentUser })
251
252
  ```
@@ -330,10 +331,10 @@ An automation runs without the session of its owner, so there is no token of the
330
331
  ### Running by hand
331
332
 
332
333
  ```typescript
333
- const { run } = await runner.runNow({ automationId })
334
+ const { run } = await runner.runNow({ automationId, currentUser })
334
335
  ```
335
336
 
336
- It starts the run at once and returns while it keeps running in the background. It does not change the next scheduled run. It is refused if the automation is already running. Any process that has a runner can call it, it does not need to be the one that called `start()`.
337
+ It starts the run at once, only if the automation is of `currentUser`, and returns while it keeps running in the background. It does not change the next scheduled run. It is refused if the automation is already running. Any process that has a runner can call it, it does not need to be the one that called `start()`.
337
338
 
338
339
  ### Several instances
339
340
 
package/docs/chats.md CHANGED
@@ -43,7 +43,7 @@ const result = await listChatsByUser({
43
43
  })
44
44
  ```
45
45
 
46
- Sorted by last update, newest first. Defaults to page 1 and 10 chats. The result has `data` and `hasMore`, which is `true` when there is a next page.
46
+ Sorted by last update, newest first. Defaults to page 1 and 10 chats. The result has `items` and `hasMore`, which is `true` when there is a next page.
47
47
 
48
48
  ```typescript
49
49
  const autonomous = await listChatsByUser({ executionMode: 'autonomous', currentUser })
@@ -10,7 +10,7 @@
10
10
  | `SECRET_MANAGER_KEY` | yes | Key used to decrypt values that start with `ENC:`. The library throws when it loads without it. |
11
11
  | `ANTHROPIC_API_KEY` | for the default model | API key of the default provider, `anthropic`. |
12
12
  | `OPENAI_API_KEY`, `GEMINI_API_KEY` | for those providers | API keys of the other providers you choose per chat. |
13
- | `JWT_SECRET` | for `login` and for event automations | Secret that signs the tokens of the users and the tokens of [event automations](automations.md#the-token). See [authentication](authentication.md). |
13
+ | `JWT_SECRET` | for `login` and for event automations | Secret that signs the tokens of the sessions, of the reset of a password and of [event automations](automations.md#the-token). See [authentication](authentication.md). |
14
14
  | `SERPER_API_KEY` | for `webSearchTool` | See [tools](tools.md#built-in-tools). |
15
15
  | `SLACK_BOT_TOKEN` | for `sendSlackMessageTool` | See [tools](tools.md#built-in-tools). |
16
16
  | `INTERNAL_MCP_TOKEN` | for internal MCP servers in automations | Token sent to the internal MCP servers when an automation runs without the session of its owner. See [automations](automations.md#internal-mcp-servers-in-a-automation). |
@@ -19,16 +19,13 @@ This project uses the `openloops` package. Before writing code that uses it, rea
19
19
  The package has no controllers: the authorization of every endpoint is the responsibility of this backend.
20
20
  ```
21
21
 
22
- ## The rule that matters most: authorization is yours
22
+ ## The rule that matters most: always pass the user
23
23
 
24
- The use cases trust the `currentUser` you pass and the ids you give them.
24
+ The use cases check who owns every record, in the repository, with the `currentUser` you pass. Read [authorization](authorization.md) once.
25
25
 
26
- - Functions that list by user (`listChatsByUser`, `listMcpServersByUser`, `listAutomationsByUser`, `listAutomationRunsByUser`) only return records of that user.
27
- - Functions that take an **id** (`getChatById`, `updateChat`, `deleteChat`, `getMcpServerById`, `updateMcpServer`, `deleteMcpServer`, `decideMcpServerTrust`, `getAutomationById`, `updateAutomation`, `deleteAutomation`, `listAutomationRunsByAutomation`, `runner.runNow`) **do not check who owns the record**. The use cases that issue, revoke or rotate the tokens of an automation do check that the user is the owner or an admin.
28
-
29
- So, before calling any of the second kind, load the record and check that `ownerId` is the user of the request. Do it in one place, a middleware or a helper, and never pass an id from a request straight to a use case.
30
-
31
- Also note that `getChatById` returns `{}` in `data` when the chat does not exist, so check for `data._id`.
26
+ - A record that is not the user's is answered as if it did not exist: a 404 `HttpError` from the functions that update or delete, and `null` from the getters, `getChatById` included.
27
+ - A call without `currentUser` fails with 401. Your endpoint is still the one that authenticates the request and builds the `currentUser` from the token.
28
+ - An administrator acts on the records of other users only with `scope: Scope.asAdmin(currentUser)`, and a worker or a webhook with `Scope.system('reason')`. Never build a scope from a value that comes from a request.
32
29
 
33
30
  ## Which endpoint calls what
34
31
 
@@ -46,8 +43,8 @@ Also note that `getChatById` returns `{}` in `data` when the chat does not exist
46
43
  | Receive an event from another system | `receiveAutomationEvent`, public endpoint, authenticated only by the token of the automation |
47
44
  | Tokens of an event automation | `issueAutomationEventToken`, `revokeAutomationEventToken`, `rotateAutomationEventTokens` |
48
45
  | History of runs | `listAutomationRunsByAutomation`, `listAutomationRunsByUser` |
49
- | "Run now" | `runner.runNow({ automationId })` |
50
- | Sign in, users | `login`, `createUser`, `getUserById`, `updateUser`, `deleteUser` |
46
+ | "Run now" | `runner.runNow({ automationId, currentUser })` |
47
+ | Sign in, sessions, users | `login`, `refreshSession`, `logout`, `issuePasswordResetToken`, `resetPassword`, `changePassword`, `createUser`, `getUserById`, `updateUser`, `deleteUser` |
51
48
 
52
49
  ## Running the agent for a message
53
50
 
@@ -123,7 +120,8 @@ runner.start()
123
120
 
124
121
  ## Security checklist
125
122
 
126
- - Check ownership before every call that takes an id.
123
+ - Pass the `currentUser` of the request to every call, and build it from the verified token.
124
+ - Never take a `scope` from the body or the query of a request.
127
125
  - Mask `headers` and `history` of MCP servers.
128
126
  - Add input guards for what your product must never receive, such as card numbers.
129
127
  - Mark your own destructive tools with `destructive: true`. The agent asks for confirmation before running them. Do not rely on a tool being treated as destructive by default, because it is not.
package/docs/llms.txt CHANGED
@@ -7,6 +7,7 @@ Start with the integration guide, then read only the pages you need. All pages a
7
7
  ## Start here
8
8
 
9
9
  - [Integration guide](integration-guide.md): what to write in a backend, which endpoint calls what, and the security checklist
10
+ - [Authorization](authorization.md): the scope that every use case uses to check who owns a record, and how to migrate from 0.5
10
11
  - [README](../README.md): what it is, the quick start and the package structure
11
12
 
12
13
  ## Run an agent
@@ -118,7 +118,7 @@ Connects, reads the manifest and stores it in `history` if it is new, or stores
118
118
  await decideMcpServerTrust({
119
119
  id: mcpServerId,
120
120
  decision: 'approve',
121
- manifestHash: result.data.history[0].hash,
121
+ manifestHash: result.history[0].hash,
122
122
  currentUser,
123
123
  })
124
124
 
package/docs/usage.md CHANGED
@@ -29,10 +29,10 @@ const chat = await getLLMUsageByChat({
29
29
  `messageId` is the `answerId` of the assistant message, and everything the agent spent to produce that answer is added together. Both functions only count the calls of `currentUser`, and both return the same shape:
30
30
 
31
31
  ```typescript
32
- result.data.summary
32
+ result.summary
33
33
  // { calls, input, output, cacheRead, cacheWrite, reasoning, totalTokens, totalCost }
34
34
 
35
- result.data.models
35
+ result.models
36
36
  // [{ provider, model, calls, input, output, cacheRead, cacheWrite, reasoning, totalTokens, totalCost }]
37
37
  ```
38
38
 
@@ -77,13 +77,13 @@ Days and periods are calculated in the time zone of the user (UTC when the user
77
77
  ### The result
78
78
 
79
79
  ```typescript
80
- result.data.summary
80
+ result.summary
81
81
  // { calls, totalTokens, totalCost }
82
82
 
83
- result.data.models
83
+ result.models
84
84
  // [{ provider, model, calls, totalTokens, totalCost, tokensPercentage, costPercentage }]
85
85
 
86
- result.data.series
86
+ result.series
87
87
  // [{ period, input, output, cacheRead, cacheWrite, reasoning, totalTokens, totalCost }]
88
88
  ```
89
89
 
package/docs/users.md CHANGED
@@ -30,17 +30,17 @@ const result = await createUser({
30
30
  password: 'a-real-password',
31
31
  role: UserRole.USER,
32
32
  },
33
- sanitize: false,
33
+ scope: Scope.system('sign up'),
34
34
  })
35
35
  ```
36
36
 
37
- `email` and `password` are required. Passwords are hashed before being stored and are never returned.
37
+ `email` and `password` are required. Passwords are hashed before being stored and are never returned. To change it later use `changePassword` (see [authentication](authentication.md#resetting-a-password)): `updateUser` refuses a `password`.
38
38
 
39
- ### `sanitize`
39
+ ### The scope
40
40
 
41
- By default `createUser` removes the fields only admins can set, such as `role`, unless the `currentUser` is an admin. This is what protects you from someone escalating privileges through the payload.
41
+ When a user creates the account, `createUser` removes the fields only a trusted scope can set, such as `role`. This is what protects you from someone escalating privileges through the payload.
42
42
 
43
- If you send `role`, pass `sanitize: false`, otherwise it is discarded. Do it only when your code builds the payload itself, with the fields you choose. Never pass the raw body of a request from an API.
43
+ If you send `role`, pass a trusted scope, otherwise it is discarded. Do it only when your code builds the payload itself, with the fields you choose, and never with the raw body of a request. See [authorization](authorization.md).
44
44
 
45
45
  ## Getting a user
46
46
 
@@ -60,6 +60,8 @@ const result = await ListUsersByProps({
60
60
  })
61
61
  ```
62
62
 
63
+ `ListUsersByProps` is for admins. The `currentUser` must be an admin, or you pass your own `scope`, because it reads the users of other people.
64
+
63
65
  ## Updating a user
64
66
 
65
67
  ```typescript
@@ -11,7 +11,7 @@ async function loginExample () {
11
11
  },
12
12
  })
13
13
 
14
- logger.info({ user: result.data.user, token: result.data.token }, '[Demo] Logged in')
14
+ logger.info({ user: result.user, accessToken: result.accessToken, refreshToken: result.refreshToken }, '[Demo] Logged in')
15
15
  }
16
16
 
17
17
  loginExample()
@@ -22,7 +22,7 @@ async function createSchedule () {
22
22
  currentUser,
23
23
  })
24
24
 
25
- logger.info({ id: result.data._id, nextRunAt: result.data.triggers?.schedule?.nextRunAt }, '[Demo] Created automation')
25
+ logger.info({ id: result._id, nextRunAt: result.triggers?.schedule?.nextRunAt }, '[Demo] Created automation')
26
26
  }
27
27
 
28
28
  createSchedule()
@@ -15,10 +15,10 @@ async function createEventAutomation () {
15
15
  currentUser,
16
16
  })
17
17
 
18
- const id = String(created.data._id)
18
+ const id = String(created._id)
19
19
  const issued = await issueAutomationEventToken({ id, expiresIn: '90d', currentUser })
20
20
 
21
- logger.info({ id, token: issued.data.token, expiresAt: issued.data.expiresAt }, '[Demo] Created automation, send events to it with this token')
21
+ logger.info({ id, token: issued.token, expiresAt: issued.expiresAt }, '[Demo] Created automation, send events to it with this token')
22
22
  }
23
23
 
24
24
  createEventAutomation()
@@ -4,13 +4,15 @@ import { listAutomationRunsByAutomation, listAutomationRunsByUser } from 'openlo
4
4
 
5
5
  async function listRunsOfAnAutomation () {
6
6
  const logger = new Logger()
7
+ const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
7
8
 
8
9
  const result = await listAutomationRunsByAutomation({
9
10
  automationId: '6ad0c9a6d3ea4199c9b7ba10',
10
11
  options: { page: 1, limit: 20 },
12
+ currentUser,
11
13
  })
12
14
 
13
- logger.info(result.data.map(run => ({ status: run.status, startedAt: run.startedAt, chatId: run.chatId, error: run.error })), '[Demo] Runs of the automation')
15
+ logger.info(result.items.map(run => ({ status: run.status, startedAt: run.startedAt, chatId: run.chatId, error: run.error })), '[Demo] Runs of the automation')
14
16
  }
15
17
 
16
18
  async function listRunsThatNeedAttention () {
@@ -20,7 +22,7 @@ async function listRunsThatNeedAttention () {
20
22
  const paused = await listAutomationRunsByUser({ status: 'paused', currentUser })
21
23
  const failed = await listAutomationRunsByUser({ status: 'failed', currentUser })
22
24
 
23
- logger.info({ paused: paused.data.length, failed: failed.data.length }, '[Demo] Runs that need attention')
25
+ logger.info({ paused: paused.items.length, failed: failed.items.length }, '[Demo] Runs that need attention')
24
26
  }
25
27
 
26
28
  listRunsOfAnAutomation()
@@ -14,7 +14,7 @@ async function listAutomations () {
14
14
  currentUser,
15
15
  })
16
16
 
17
- logger.info(result.data.map(automation => ({
17
+ logger.info(result.items.map(automation => ({
18
18
  name: automation.name,
19
19
  scheduleEnabled: automation.triggers?.schedule?.enabled,
20
20
  eventEnabled: automation.triggers?.event?.enabled,
@@ -10,7 +10,7 @@ async function previewRuns () {
10
10
  count: 5,
11
11
  })
12
12
 
13
- logger.info(result.data.runs, '[Demo] Next runs')
13
+ logger.info(result.runs, '[Demo] Next runs')
14
14
  }
15
15
 
16
16
  previewRuns()
@@ -5,7 +5,7 @@ async function receive (automationId: string, authorization: string, body: unkno
5
5
  const logger = new Logger()
6
6
 
7
7
  try {
8
- const { data } = await receiveAutomationEvent({
8
+ const data = await receiveAutomationEvent({
9
9
  automationId,
10
10
  token: authorization.replace(/^Bearer /, ''),
11
11
  payload: body,