openloops 0.3.5 → 0.4.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 (217) hide show
  1. package/README.md +9 -8
  2. package/dist/db/index.d.ts +1 -0
  3. package/dist/db/index.js +3 -1
  4. package/dist/db/index.mjs +1 -0
  5. package/dist/db/indexes/automation-runs.d.ts +2 -0
  6. package/dist/db/indexes/automation-runs.js +33 -0
  7. package/dist/db/indexes/automation-runs.mjs +10 -0
  8. package/dist/db/indexes/automations.d.ts +2 -0
  9. package/dist/db/indexes/{agentic-jobs.js → automations.js} +6 -6
  10. package/dist/db/indexes/{agentic-jobs.mjs → automations.mjs} +2 -2
  11. package/dist/db/indexes/index.js +6 -4
  12. package/dist/db/indexes/index.mjs +6 -4
  13. package/dist/db/indexes/revoked-tokens.d.ts +2 -0
  14. package/dist/db/indexes/{agentic-job-runs.js → revoked-tokens.js} +8 -9
  15. package/dist/db/indexes/revoked-tokens.mjs +8 -0
  16. package/dist/db/migrations/automations.d.ts +12 -0
  17. package/dist/db/migrations/automations.js +70 -0
  18. package/dist/db/migrations/automations.mjs +47 -0
  19. package/dist/services/authentication/entities/index.d.ts +1 -0
  20. package/dist/services/authentication/entities/index.js +22 -0
  21. package/dist/services/authentication/entities/index.mjs +1 -0
  22. package/dist/services/authentication/entities/revoked-token.entity.d.ts +17 -0
  23. package/dist/services/authentication/entities/revoked-token.entity.js +67 -0
  24. package/dist/services/authentication/entities/revoked-token.entity.mjs +44 -0
  25. package/dist/services/authentication/index.d.ts +1 -0
  26. package/dist/services/authentication/index.js +3 -1
  27. package/dist/services/authentication/index.mjs +1 -0
  28. package/dist/services/authentication/module.d.ts +4 -0
  29. package/dist/services/authentication/module.js +16 -2
  30. package/dist/services/authentication/module.mjs +13 -1
  31. package/dist/services/authentication/repositories/index.d.ts +1 -0
  32. package/dist/services/{agentic-jobs → authentication}/repositories/index.js +2 -4
  33. package/dist/services/authentication/repositories/index.mjs +1 -0
  34. package/dist/services/authentication/repositories/revoked-token.repository.d.ts +7 -0
  35. package/dist/services/authentication/repositories/revoked-token.repository.js +55 -0
  36. package/dist/services/authentication/repositories/revoked-token.repository.mjs +26 -0
  37. package/dist/services/authentication/use-cases/is-token-revoked.use-case.d.ts +15 -0
  38. package/dist/services/authentication/use-cases/is-token-revoked.use-case.js +55 -0
  39. package/dist/services/authentication/use-cases/is-token-revoked.use-case.mjs +26 -0
  40. package/dist/services/authentication/use-cases/revoke-token.use-case.d.ts +14 -0
  41. package/dist/services/authentication/use-cases/revoke-token.use-case.js +65 -0
  42. package/dist/services/authentication/use-cases/revoke-token.use-case.mjs +36 -0
  43. package/dist/services/automations/entities/automation-run.entity.d.ts +46 -0
  44. package/dist/services/{agentic-jobs/entities/agentic-job-run.entity.js → automations/entities/automation-run.entity.js} +22 -14
  45. package/dist/services/{agentic-jobs/entities/agentic-job-run.entity.mjs → automations/entities/automation-run.entity.mjs} +18 -10
  46. package/dist/services/automations/entities/automation.entity.d.ts +38 -0
  47. package/dist/services/{agentic-jobs/entities/agentic-job.entity.js → automations/entities/automation.entity.js} +17 -17
  48. package/dist/services/{agentic-jobs/entities/agentic-job.entity.mjs → automations/entities/automation.entity.mjs} +13 -13
  49. package/dist/services/automations/entities/index.d.ts +4 -0
  50. package/dist/services/{agentic-jobs → automations}/entities/index.js +6 -4
  51. package/dist/services/automations/entities/index.mjs +4 -0
  52. package/dist/services/automations/entities/trigger.d.ts +11 -0
  53. package/dist/services/automations/entities/trigger.js +49 -0
  54. package/dist/services/automations/entities/trigger.mjs +26 -0
  55. package/dist/services/automations/index.d.ts +5 -0
  56. package/dist/services/{agentic-jobs → automations}/index.js +9 -7
  57. package/dist/services/automations/index.mjs +5 -0
  58. package/dist/services/automations/module.d.ts +41 -0
  59. package/dist/services/automations/module.js +167 -0
  60. package/dist/services/automations/module.mjs +125 -0
  61. package/dist/services/automations/repositories/automation-run.repository.d.ts +14 -0
  62. package/dist/services/{agentic-jobs/repositories/agentic-job-run.repository.js → automations/repositories/automation-run.repository.js} +23 -11
  63. package/dist/services/{agentic-jobs/repositories/agentic-job-run.repository.mjs → automations/repositories/automation-run.repository.mjs} +19 -7
  64. package/dist/services/automations/repositories/automation.repository.d.ts +27 -0
  65. package/dist/services/{agentic-jobs/repositories/agentic-job.repository.js → automations/repositories/automation.repository.js} +17 -17
  66. package/dist/services/{agentic-jobs/repositories/agentic-job.repository.mjs → automations/repositories/automation.repository.mjs} +13 -13
  67. package/dist/services/automations/repositories/index.d.ts +2 -0
  68. package/dist/services/automations/repositories/index.js +24 -0
  69. package/dist/services/automations/repositories/index.mjs +2 -0
  70. package/dist/services/automations/runner/automation-runner.d.ts +49 -0
  71. package/dist/services/{agentic-jobs/runner/agentic-job-runner.js → automations/runner/automation-runner.js} +55 -45
  72. package/dist/services/{agentic-jobs/runner/agentic-job-runner.mjs → automations/runner/automation-runner.mjs} +50 -40
  73. package/dist/services/{agentic-jobs/use-cases/attach-agentic-job-run-chat.use-case.d.ts → automations/use-cases/attach-automation-run-chat.use-case.d.ts} +6 -6
  74. package/dist/services/{agentic-jobs/use-cases/attach-agentic-job-run-chat.use-case.js → automations/use-cases/attach-automation-run-chat.use-case.js} +14 -14
  75. package/dist/services/automations/use-cases/attach-automation-run-chat.use-case.mjs +29 -0
  76. package/dist/services/automations/use-cases/claim-due-automations.use-case.d.ts +28 -0
  77. package/dist/services/{agentic-jobs/use-cases/claim-due-agentic-jobs.use-case.js → automations/use-cases/claim-due-automations.use-case.js} +32 -43
  78. package/dist/services/automations/use-cases/claim-due-automations.use-case.mjs +70 -0
  79. package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.d.ts +27 -0
  80. package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.js +106 -0
  81. package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.mjs +77 -0
  82. package/dist/services/automations/use-cases/create-automation.use-case.d.ts +14 -0
  83. package/dist/services/{agentic-jobs/use-cases/create-agentic-job.use-case.js → automations/use-cases/create-automation.use-case.js} +24 -25
  84. package/dist/services/automations/use-cases/create-automation.use-case.mjs +43 -0
  85. package/dist/services/{agentic-jobs/use-cases/delete-agentic-job.use-case.d.ts → automations/use-cases/delete-automation.use-case.d.ts} +6 -6
  86. package/dist/services/{agentic-jobs/use-cases/delete-agentic-job.use-case.js → automations/use-cases/delete-automation.use-case.js} +17 -17
  87. package/dist/services/automations/use-cases/delete-automation.use-case.mjs +36 -0
  88. package/dist/services/{agentic-jobs/use-cases/finish-agentic-job-run.use-case.d.ts → automations/use-cases/finish-automation-run.use-case.d.ts} +8 -8
  89. package/dist/services/{agentic-jobs/use-cases/finish-agentic-job-run.use-case.js → automations/use-cases/finish-automation-run.use-case.js} +20 -20
  90. package/dist/services/automations/use-cases/finish-automation-run.use-case.mjs +46 -0
  91. package/dist/services/{agentic-jobs/use-cases/get-agentic-job-by-id.use-case.d.ts → automations/use-cases/get-automation-by-id.use-case.d.ts} +6 -6
  92. package/dist/services/{agentic-jobs/use-cases/get-agentic-job-by-id.use-case.js → automations/use-cases/get-automation-by-id.use-case.js} +13 -13
  93. package/dist/services/automations/use-cases/get-automation-by-id.use-case.mjs +26 -0
  94. package/dist/services/automations/use-cases/issue-automation-event-token.use-case.d.ts +17 -0
  95. package/dist/services/automations/use-cases/issue-automation-event-token.use-case.js +59 -0
  96. package/dist/services/automations/use-cases/issue-automation-event-token.use-case.mjs +30 -0
  97. package/dist/services/{agentic-jobs/use-cases/list-agentic-job-runs-by-job.use-case.d.ts → automations/use-cases/list-automation-runs-by-automation.use-case.d.ts} +7 -7
  98. package/dist/services/{agentic-jobs/use-cases/list-agentic-job-runs-by-job.use-case.js → automations/use-cases/list-automation-runs-by-automation.use-case.js} +15 -15
  99. package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.mjs +28 -0
  100. package/dist/services/{agentic-jobs/use-cases/list-agentic-job-runs-by-user.use-case.d.ts → automations/use-cases/list-automation-runs-by-user.use-case.d.ts} +7 -7
  101. package/dist/services/{agentic-jobs/use-cases/list-agentic-job-runs-by-user.use-case.js → automations/use-cases/list-automation-runs-by-user.use-case.js} +14 -14
  102. package/dist/services/{agentic-jobs/use-cases/list-agentic-job-runs-by-user.use-case.mjs → automations/use-cases/list-automation-runs-by-user.use-case.mjs} +11 -11
  103. package/dist/services/{agentic-jobs/use-cases/list-agentic-jobs-by-user.use-case.d.ts → automations/use-cases/list-automations-by-user.use-case.d.ts} +6 -6
  104. package/dist/services/{agentic-jobs/use-cases/list-agentic-jobs-by-user.use-case.js → automations/use-cases/list-automations-by-user.use-case.js} +14 -14
  105. package/dist/services/{agentic-jobs/use-cases/list-agentic-jobs-by-user.use-case.mjs → automations/use-cases/list-automations-by-user.use-case.mjs} +11 -11
  106. package/dist/services/{agentic-jobs/use-cases/preview-agentic-job-runs.use-case.d.ts → automations/use-cases/preview-automation-runs.use-case.d.ts} +1 -1
  107. package/dist/services/{agentic-jobs/use-cases/preview-agentic-job-runs.use-case.js → automations/use-cases/preview-automation-runs.use-case.js} +8 -8
  108. package/dist/services/{agentic-jobs/use-cases/preview-agentic-job-runs.use-case.mjs → automations/use-cases/preview-automation-runs.use-case.mjs} +4 -4
  109. package/dist/services/automations/use-cases/receive-automation-event.use-case.d.ts +23 -0
  110. package/dist/services/automations/use-cases/receive-automation-event.use-case.js +97 -0
  111. package/dist/services/automations/use-cases/receive-automation-event.use-case.mjs +68 -0
  112. package/dist/services/{agentic-jobs/use-cases/renew-agentic-job-lease.use-case.d.ts → automations/use-cases/renew-automation-lease.use-case.d.ts} +5 -5
  113. package/dist/services/{agentic-jobs/use-cases/renew-agentic-job-lease.use-case.js → automations/use-cases/renew-automation-lease.use-case.js} +15 -15
  114. package/dist/services/automations/use-cases/renew-automation-lease.use-case.mjs +29 -0
  115. package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.d.ts +16 -0
  116. package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.js +65 -0
  117. package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.mjs +36 -0
  118. package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.d.ts +14 -0
  119. package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.js +63 -0
  120. package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.mjs +34 -0
  121. package/dist/services/automations/use-cases/start-automation-run.use-case.d.ts +21 -0
  122. package/dist/services/{agentic-jobs/use-cases/start-agentic-job-run.use-case.js → automations/use-cases/start-automation-run.use-case.js} +24 -24
  123. package/dist/services/automations/use-cases/start-automation-run.use-case.mjs +38 -0
  124. package/dist/services/automations/use-cases/sync-automation-run.use-case.d.ts +20 -0
  125. package/dist/services/{agentic-jobs/use-cases/sync-agentic-job-run.use-case.js → automations/use-cases/sync-automation-run.use-case.js} +23 -23
  126. package/dist/services/{agentic-jobs/use-cases/sync-agentic-job-run.use-case.mjs → automations/use-cases/sync-automation-run.use-case.mjs} +21 -21
  127. package/dist/services/{agentic-jobs/use-cases/sync-agentic-job-runs.use-case.d.ts → automations/use-cases/sync-automation-runs.use-case.d.ts} +5 -5
  128. package/dist/services/{agentic-jobs/use-cases/sync-agentic-job-runs.use-case.js → automations/use-cases/sync-automation-runs.use-case.js} +16 -16
  129. package/dist/services/{agentic-jobs/use-cases/sync-agentic-job-runs.use-case.mjs → automations/use-cases/sync-automation-runs.use-case.mjs} +13 -13
  130. package/dist/services/automations/use-cases/update-automation.use-case.d.ts +15 -0
  131. package/dist/services/{agentic-jobs/use-cases/update-agentic-job.use-case.js → automations/use-cases/update-automation.use-case.js} +27 -27
  132. package/dist/services/automations/use-cases/update-automation.use-case.mjs +54 -0
  133. package/dist/services/automations/utils/automation-event-error.d.ts +6 -0
  134. package/dist/services/automations/utils/automation-event-error.js +37 -0
  135. package/dist/services/automations/utils/automation-event-error.mjs +14 -0
  136. package/dist/services/automations/utils/automation-fields.d.ts +14 -0
  137. package/dist/services/{agentic-jobs/utils/job-fields.js → automations/utils/automation-fields.js} +8 -10
  138. package/dist/services/{agentic-jobs/utils/job-fields.mjs → automations/utils/automation-fields.mjs} +4 -6
  139. package/dist/services/automations/utils/event-message.d.ts +1 -0
  140. package/dist/services/automations/utils/event-message.js +37 -0
  141. package/dist/services/automations/utils/event-message.mjs +14 -0
  142. package/dist/services/automations/utils/event-token.d.ts +18 -0
  143. package/dist/services/automations/utils/event-token.js +78 -0
  144. package/dist/services/automations/utils/event-token.mjs +43 -0
  145. package/dist/services/automations/utils/open-run.d.ts +14 -0
  146. package/dist/services/{agentic-jobs → automations}/utils/open-run.js +10 -8
  147. package/dist/services/automations/utils/open-run.mjs +26 -0
  148. package/dist/services/automations/utils/previous-run.d.ts +4 -0
  149. package/dist/services/automations/utils/previous-run.js +42 -0
  150. package/dist/services/automations/utils/previous-run.mjs +19 -0
  151. package/dist/services/{agentic-jobs → automations}/utils/settings.d.ts +1 -0
  152. package/dist/services/{agentic-jobs → automations}/utils/settings.js +6 -2
  153. package/dist/services/automations/utils/settings.mjs +13 -0
  154. package/docs/README.md +1 -1
  155. package/docs/agent.md +2 -2
  156. package/docs/authentication.md +18 -1
  157. package/docs/automations.md +341 -0
  158. package/docs/configuration.md +6 -5
  159. package/docs/harness.md +1 -1
  160. package/docs/integration-guide.md +22 -18
  161. package/docs/llms.txt +1 -1
  162. package/docs/mcp-servers.md +1 -1
  163. package/examples/{agentic-jobs/create-agentic-job.ts → automations/create-automation.ts} +10 -7
  164. package/examples/automations/create-event-automation.ts +24 -0
  165. package/examples/{agentic-jobs/list-agentic-job-runs.ts → automations/list-automation-runs.ts} +8 -8
  166. package/examples/automations/list-automations.ts +25 -0
  167. package/examples/{agentic-jobs/preview-agentic-job-runs.ts → automations/preview-automation-runs.ts} +2 -2
  168. package/examples/automations/receive-automation-event.ts +26 -0
  169. package/examples/automations/revoke-automation-event-token.ts +25 -0
  170. package/examples/{agentic-jobs/run-agentic-job-now.ts → automations/run-automation-now.ts} +3 -3
  171. package/examples/{agentic-jobs/run-agentic-job-worker.ts → automations/run-automation-worker.ts} +6 -6
  172. package/examples/{agentic-jobs/update-agentic-job.ts → automations/update-automation.ts} +10 -10
  173. package/package.json +14 -13
  174. package/dist/db/indexes/agentic-job-runs.d.ts +0 -2
  175. package/dist/db/indexes/agentic-job-runs.mjs +0 -9
  176. package/dist/db/indexes/agentic-jobs.d.ts +0 -2
  177. package/dist/services/agentic-jobs/entities/agentic-job-run.entity.d.ts +0 -42
  178. package/dist/services/agentic-jobs/entities/agentic-job.entity.d.ts +0 -39
  179. package/dist/services/agentic-jobs/entities/index.d.ts +0 -3
  180. package/dist/services/agentic-jobs/entities/index.mjs +0 -3
  181. package/dist/services/agentic-jobs/index.d.ts +0 -4
  182. package/dist/services/agentic-jobs/index.mjs +0 -4
  183. package/dist/services/agentic-jobs/module.d.ts +0 -31
  184. package/dist/services/agentic-jobs/module.js +0 -132
  185. package/dist/services/agentic-jobs/module.mjs +0 -95
  186. package/dist/services/agentic-jobs/repositories/agentic-job-run.repository.d.ts +0 -11
  187. package/dist/services/agentic-jobs/repositories/agentic-job.repository.d.ts +0 -27
  188. package/dist/services/agentic-jobs/repositories/index.d.ts +0 -2
  189. package/dist/services/agentic-jobs/repositories/index.mjs +0 -2
  190. package/dist/services/agentic-jobs/runner/agentic-job-runner.d.ts +0 -48
  191. package/dist/services/agentic-jobs/use-cases/attach-agentic-job-run-chat.use-case.mjs +0 -29
  192. package/dist/services/agentic-jobs/use-cases/claim-due-agentic-jobs.use-case.d.ts +0 -29
  193. package/dist/services/agentic-jobs/use-cases/claim-due-agentic-jobs.use-case.mjs +0 -81
  194. package/dist/services/agentic-jobs/use-cases/create-agentic-job.use-case.d.ts +0 -14
  195. package/dist/services/agentic-jobs/use-cases/create-agentic-job.use-case.mjs +0 -44
  196. package/dist/services/agentic-jobs/use-cases/delete-agentic-job.use-case.mjs +0 -36
  197. package/dist/services/agentic-jobs/use-cases/finish-agentic-job-run.use-case.mjs +0 -46
  198. package/dist/services/agentic-jobs/use-cases/get-agentic-job-by-id.use-case.mjs +0 -26
  199. package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-job.use-case.mjs +0 -28
  200. package/dist/services/agentic-jobs/use-cases/renew-agentic-job-lease.use-case.mjs +0 -29
  201. package/dist/services/agentic-jobs/use-cases/start-agentic-job-run.use-case.d.ts +0 -21
  202. package/dist/services/agentic-jobs/use-cases/start-agentic-job-run.use-case.mjs +0 -38
  203. package/dist/services/agentic-jobs/use-cases/sync-agentic-job-run.use-case.d.ts +0 -20
  204. package/dist/services/agentic-jobs/use-cases/update-agentic-job.use-case.d.ts +0 -15
  205. package/dist/services/agentic-jobs/use-cases/update-agentic-job.use-case.mjs +0 -54
  206. package/dist/services/agentic-jobs/utils/job-fields.d.ts +0 -14
  207. package/dist/services/agentic-jobs/utils/open-run.d.ts +0 -12
  208. package/dist/services/agentic-jobs/utils/open-run.mjs +0 -24
  209. package/dist/services/agentic-jobs/utils/settings.mjs +0 -10
  210. package/docs/agentic-jobs.md +0 -217
  211. package/examples/agentic-jobs/list-agentic-jobs.ts +0 -25
  212. /package/dist/services/{agentic-jobs → automations}/entities/recurrence.d.ts +0 -0
  213. /package/dist/services/{agentic-jobs → automations}/entities/recurrence.js +0 -0
  214. /package/dist/services/{agentic-jobs → automations}/entities/recurrence.mjs +0 -0
  215. /package/dist/services/{agentic-jobs → automations}/utils/next-run.d.ts +0 -0
  216. /package/dist/services/{agentic-jobs → automations}/utils/next-run.js +0 -0
  217. /package/dist/services/{agentic-jobs → automations}/utils/next-run.mjs +0 -0
@@ -1,217 +0,0 @@
1
- # Agentic jobs
2
-
3
- An agentic job is a task that your agent runs by itself, on a schedule, without anyone in the chat. You describe what it must do and when, and `openloops` runs it in [autonomous mode](agent.md#autonomous-mode), in a new chat each time, and keeps a history of every run.
4
-
5
- ```typescript
6
- import {
7
- createAgenticJob,
8
- updateAgenticJob,
9
- getAgenticJobById,
10
- listAgenticJobsByUser,
11
- deleteAgenticJob,
12
- previewAgenticJobRuns,
13
- listAgenticJobRunsByJob,
14
- listAgenticJobRunsByUser,
15
- createAgenticJobRunner,
16
- } from 'openloops/agentic-jobs'
17
- ```
18
-
19
- There are two parts. The use cases create and manage jobs and read their history, and are called from your API. The runner is a worker that you start in your backend and that executes what is due.
20
-
21
- ## Creating a job
22
-
23
- ```typescript
24
- const result = await createAgenticJob({
25
- payload: {
26
- name: 'Morning report',
27
- instructions: 'Summarize my open tickets and send the summary to my email',
28
- recurrence: { type: 'weekly', days: [1, 2, 3, 4, 5], time: '08:00' },
29
- timezone: 'America/Lima',
30
- modelProvider: 'anthropic',
31
- modelName: 'claude-haiku-5-5',
32
- },
33
- currentUser,
34
- })
35
-
36
- result.data.nextRunAt
37
- ```
38
-
39
- | Field | Required | What it is |
40
- | --- | --- | --- |
41
- | `name` | yes | A name to recognize the job. |
42
- | `instructions` | yes | What the agent must do. It is sent to the agent as the message of the user, so write it as you would write it in a chat. If the task needs to notify someone, say so here and give the agent a tool for it. |
43
- | `recurrence` | yes | When it runs. See below. |
44
- | `timezone` | yes | An IANA timezone. The local time of the recurrence and the days are those of this timezone, and daylight saving time is respected. |
45
- | `enabled` | no | `true` by default. A job that is off never runs, and can be turned on again. |
46
- | `modelProvider`, `modelName` | no | The model of the job, both or none. Without them, the default model of the owner is used, then the fallbacks. See [configuration](configuration.md#which-model-a-chat-uses). |
47
-
48
- `nextRunAt` is calculated when the job is created and it is what you show to the user. The fields that the system manages (`nextRunAt`, `lastRunAt`, `lastRunStatus`, `lockedBy`, `lockedUntil`, `activeRunId`) are ignored if they come in the payload.
49
-
50
- ### Recurrence
51
-
52
- The recurrence is stored as a structured value, so a screen can offer simple choices and nobody has to write a cron expression. The time is the local time of the timezone of the job, in 24 hours.
53
-
54
- | Type | Fields | Example |
55
- | --- | --- | --- |
56
- | `daily` | `time` | `{ type: 'daily', time: '08:00' }` |
57
- | `weekly` | `days` (1 is Monday, 7 is Sunday), `time` | `{ type: 'weekly', days: [1, 2, 3, 4, 5], time: '09:30' }` is Monday to Friday |
58
- | `monthly` | `day` (1 to 31 or `'last'`), `time` | `{ type: 'monthly', day: 15, time: '12:00' }` |
59
- | `once` | `at` (`YYYY-MM-DDTHH:mm`, local time) | `{ type: 'once', at: '2026-12-25T10:00' }` |
60
-
61
- - A monthly job on day 29, 30 or 31 is skipped in the months that do not have that day. Use `'last'` for the last day of every month.
62
- - A time that does not exist on a day because of daylight saving time runs at the first valid moment of that day, and a time that happens twice runs once.
63
- - A job of type `once` runs a single time and then has no next run.
64
-
65
- ### Previewing
66
-
67
- ```typescript
68
- const { data } = await previewAgenticJobRuns({
69
- recurrence: { type: 'weekly', days: [1, 5], time: '08:00' },
70
- timezone: 'America/Lima',
71
- count: 5,
72
- })
73
-
74
- data.runs
75
- ```
76
-
77
- It returns the next dates (at most 20) without saving anything, so a screen can show "it will run on Monday at 8:00, on Friday at 8:00...".
78
-
79
- ## Managing jobs
80
-
81
- ```typescript
82
- await updateAgenticJob({ id, payload: { enabled: false }, currentUser })
83
-
84
- await updateAgenticJob({ id, payload: { enabled: true }, currentUser })
85
-
86
- const job = await getAgenticJobById({ id, currentUser })
87
-
88
- const jobs = await listAgenticJobsByUser({ options: { page: 1, limit: 10 }, currentUser })
89
-
90
- await deleteAgenticJob({ id, currentUser })
91
- ```
92
-
93
- - **Turning a job off** is how the user pauses it for a while. It has no next run until it is turned on again. Turning it on counts the next run from that moment, it does not catch up with what was missed.
94
- - **Changing the recurrence, the timezone or turning it on** calculates `nextRunAt` again from now.
95
- - **A run that is in progress is not interrupted** by turning the job off or by deleting it.
96
- - **`__v`** in the payload works as in the other use cases: if the job changed since it was read, the update fails with a `VersionConflictError`.
97
- - **Deleting** is a soft delete. An admin can delete for good with `hardDelete: true`.
98
- - **The system never turns a job off by itself.** A job that fails keeps trying on every occurrence, so watch the history.
99
-
100
- ## The history
101
-
102
- Every execution is a run.
103
-
104
- ```typescript
105
- const byJob = await listAgenticJobRunsByJob({ jobId, options: { page: 1, limit: 20 } })
106
-
107
- const byUser = await listAgenticJobRunsByUser({ status: 'failed', currentUser })
108
- ```
109
-
110
- | Field | Meaning |
111
- | --- | --- |
112
- | `jobId`, `chatId` | The job and the chat of the run. Open the chat to read everything that the agent did. |
113
- | `trigger` | `schedule` or `manual`. |
114
- | `scheduledFor`, `startedAt`, `finishedAt` | When it was due, when it started and when it ended. |
115
- | `status` | See below. |
116
- | `error` | `code` and `message` when it failed. |
117
- | `skipReason` | Why a run was skipped. |
118
- | `instructions`, `modelProvider`, `modelName` | What was run, as it was when the run started, even if the job was edited later. |
119
-
120
- | Status | Meaning |
121
- | --- | --- |
122
- | `running` | In progress. |
123
- | `completed` | The agent finished its task. |
124
- | `paused` | The agent needs the user: it asked for the approval of a tool or an MCP server, or asked a question. The chat is waiting. When the user answers in the chat and it finishes, the run becomes `completed` or `failed`. |
125
- | `failed` | It failed. `error` says why: the model did not answer in time, a guardrail blocked the instructions, the owner no longer exists, or the worker was lost. |
126
- | `skipped` | It was due, but the previous run was still `paused`, so it was not started. It is recorded so you can notify the user. |
127
-
128
- ## The runner
129
-
130
- The runner is a worker that checks what is due and runs it. You create it once, with the agent that your jobs should use, and start it in your backend.
131
-
132
- ```typescript
133
- import { createAgenticJobRunner } from 'openloops/agentic-jobs'
134
- import { webSearchTool } from 'openloops/tools'
135
- import { inputGuards } from 'openloops/guardrails'
136
-
137
- const runner = createAgenticJobRunner({
138
- agent: {
139
- tools: [webSearchTool, sendEmailTool],
140
- guards: [inputGuards.blockCard],
141
- maxIterations: 30,
142
- },
143
- onRunFinished: async ({ job, run, chat }) => {
144
- if (run.status === 'failed' || run.status === 'skipped') await notifyTheOwner(job, run)
145
- },
146
- })
147
-
148
- runner.start()
149
-
150
- process.on('SIGTERM', async () => {
151
- await runner.stop()
152
- process.exit(0)
153
- })
154
- ```
155
-
156
- | Option | Default | What it does |
157
- | --- | --- | --- |
158
- | `agent` | `{}` | The options of the `Agent` used for every run: tools, guards, `maxIterations`, `strictMode`, `identity`... It can be a function `({ job, currentUser }) => options` when they depend on the job or on the user. The loop is `AgiLoop` unless you set `loop`. A custom loop must support autonomous mode (`harness.executionMode`). |
159
- | `intervalMs` | `60000` | How often it checks. Also set with `AGENTIC_JOBS_POLL_INTERVAL_MS`. |
160
- | `leaseMs` | `600000` | How long a job stays locked while it runs, renewed while the run lasts. Also set with `AGENTIC_JOBS_LEASE_MS`. |
161
- | `maxConcurrentRuns` | `3` | How many runs a runner executes at once. |
162
- | `stopTimeoutMs` | `30000` | How long `stop()` waits for the runs in progress. |
163
- | `workerId` | generated | An identifier of the worker, kept in the run. |
164
- | `onRunFinished` | none | Called with `{ job, run, chat }` when a run ends, is paused or is skipped. An error in it does not affect the run. |
165
-
166
- A new `Agent` is created for every run, so the options are the same but nothing is shared between runs.
167
-
168
- ### What every run does
169
-
170
- - It runs as the owner of the job, which must exist.
171
- - It starts a new chat, in autonomous mode, with the model of the job, and the instructions as the first message. The chat is recorded in the run as soon as it exists.
172
- - It gives the agent the timezone of the job, so the local time reaches the prompts.
173
- - Guards of the agent apply to the instructions. If one blocks them, the run is `failed`.
174
-
175
- ### Internal MCP servers in a job
176
-
177
- A job runs without the session of its owner, so there is no token of theirs to send to your [internal MCP servers](mcp-servers.md#internal-mcp-servers). For jobs, the runner uses one token for the whole deployment, taken from `INTERNAL_MCP_TOKEN`. It replaces `{{token}}` in the headers of every internal server, and the runner also sends the id of the owner of the job in the header `X-User-Id`, so your MCP server knows on whose behalf it acts.
178
-
179
- - Your MCP server must accept `X-User-Id` only together with this service token. Never trust it on a request that carries the token of a user.
180
- - The header is added only in jobs and only to internal servers that use `{{token}}`. It replaces any `X-User-Id` you configured. It is never sent to the servers added by the user.
181
- - Without `INTERNAL_MCP_TOKEN`, the internal servers that need a token are unavailable in the jobs, and the run continues without them.
182
- - The value is read with the secret manager, so it can be encrypted with the `ENC:` prefix.
183
- - One variable serves all the internal servers. If two of them need different credentials, that is not supported yet.
184
-
185
- ### Running by hand
186
-
187
- ```typescript
188
- const { run } = await runner.runNow({ jobId })
189
- ```
190
-
191
- 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 job is already running. Any process that has a runner can call it, it does not need to be the one that called `start()`.
192
-
193
- ### Several instances
194
-
195
- You can run the worker in as many pods as you want. A job is taken with a single atomic update in the database that only one worker wins, and the same update moves `nextRunAt` to the next occurrence. So:
196
-
197
- - A job is never started twice at the same time.
198
- - A run that fails, or whose worker dies, is **not repeated** until the next occurrence.
199
- - If the backend was down, a job that was due runs **once**, and the next run is counted from now.
200
- - The lease expires if a worker dies. The run it left in progress is marked as `failed` and the job keeps its schedule.
201
-
202
- If you prefer, start the runner in a single deployment and call `runNow` from the others.
203
-
204
- ### Settling the runs that wait for the user
205
-
206
- Someone answers a paused run in the chat, outside the runner. The runner checks the open runs on every pass and updates them from the state of their chat. If you want it faster, call `syncAgenticJobRun({ runId })` when your own events tell you that a chat ended.
207
-
208
- ## Indexes
209
-
210
- The collections are `agentic_jobs` and `agentic_job_runs`. `ensureIndexes` from `openloops/db` creates the indexes of the queries of the runner and of the lists (see [configuration](configuration.md#indexes)). They are:
211
-
212
- - `agentic_jobs`: `{ enabled: 1, nextRunAt: 1 }` and `{ ownerId: 1, createdAt: -1 }`.
213
- - `agentic_job_runs`: `{ jobId: 1, createdAt: -1 }`, `{ ownerId: 1, createdAt: -1 }` and `{ status: 1, createdAt: 1 }`.
214
-
215
- ## Limits
216
-
217
- How many jobs a user can have, how often they can run and how much they can spend is not decided here. That belongs to the module of usage limits.
@@ -1,25 +0,0 @@
1
- import { Logger } from 'openloops/common'
2
- import { CurrentUser } from 'openloops/base'
3
- import { listAgenticJobsByUser } from 'openloops/agentic-jobs'
4
-
5
- async function listJobs () {
6
- const logger = new Logger()
7
- const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
8
-
9
- const result = await listAgenticJobsByUser({
10
- options: {
11
- page: 1,
12
- limit: 20,
13
- },
14
- currentUser,
15
- })
16
-
17
- logger.info(result.data.map(job => ({
18
- name: job.name,
19
- enabled: job.enabled,
20
- nextRunAt: job.nextRunAt,
21
- lastRunStatus: job.lastRunStatus,
22
- })), '[Demo] Agentic jobs')
23
- }
24
-
25
- listJobs()