openloops 0.3.5 → 0.4.1
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.
- package/CHANGELOG.md +34 -0
- package/README.md +10 -8
- package/dist/common/repositories/mongo-db.repository.d.ts +6 -1
- package/dist/common/repositories/mongo-db.repository.js +13 -5
- package/dist/common/repositories/mongo-db.repository.mjs +13 -5
- package/dist/db/index.d.ts +1 -0
- package/dist/db/index.js +3 -1
- package/dist/db/index.mjs +1 -0
- package/dist/db/indexes/automation-runs.d.ts +2 -0
- package/dist/db/indexes/automation-runs.js +33 -0
- package/dist/db/indexes/automation-runs.mjs +10 -0
- package/dist/db/indexes/automations.d.ts +2 -0
- package/dist/db/indexes/{agentic-jobs.js → automations.js} +6 -6
- package/dist/db/indexes/{agentic-jobs.mjs → automations.mjs} +2 -2
- package/dist/db/indexes/index.js +6 -4
- package/dist/db/indexes/index.mjs +6 -4
- package/dist/db/indexes/revoked-tokens.d.ts +2 -0
- package/dist/db/indexes/{agentic-job-runs.js → revoked-tokens.js} +8 -9
- package/dist/db/indexes/revoked-tokens.mjs +8 -0
- package/dist/db/migrations/automations.d.ts +12 -0
- package/dist/db/migrations/automations.js +70 -0
- package/dist/db/migrations/automations.mjs +47 -0
- package/dist/services/authentication/entities/index.d.ts +1 -0
- package/dist/services/authentication/entities/index.js +22 -0
- package/dist/services/authentication/entities/index.mjs +1 -0
- package/dist/services/authentication/entities/revoked-token.entity.d.ts +17 -0
- package/dist/services/authentication/entities/revoked-token.entity.js +67 -0
- package/dist/services/authentication/entities/revoked-token.entity.mjs +44 -0
- package/dist/services/authentication/index.d.ts +1 -0
- package/dist/services/authentication/index.js +3 -1
- package/dist/services/authentication/index.mjs +1 -0
- package/dist/services/authentication/module.d.ts +4 -0
- package/dist/services/authentication/module.js +16 -2
- package/dist/services/authentication/module.mjs +13 -1
- package/dist/services/authentication/repositories/index.d.ts +1 -0
- package/dist/services/{agentic-jobs → authentication}/repositories/index.js +2 -4
- package/dist/services/authentication/repositories/index.mjs +1 -0
- package/dist/services/authentication/repositories/revoked-token.repository.d.ts +7 -0
- package/dist/services/authentication/repositories/revoked-token.repository.js +55 -0
- package/dist/services/authentication/repositories/revoked-token.repository.mjs +26 -0
- package/dist/services/authentication/use-cases/is-token-revoked.use-case.d.ts +15 -0
- package/dist/services/{agentic-jobs/use-cases/list-agentic-job-runs-by-job.use-case.js → authentication/use-cases/is-token-revoked.use-case.js} +16 -18
- package/dist/services/authentication/use-cases/is-token-revoked.use-case.mjs +26 -0
- package/dist/services/authentication/use-cases/revoke-token.use-case.d.ts +14 -0
- package/dist/services/authentication/use-cases/revoke-token.use-case.js +65 -0
- package/dist/services/authentication/use-cases/revoke-token.use-case.mjs +36 -0
- package/dist/services/automations/entities/automation-run.entity.d.ts +46 -0
- package/dist/services/{agentic-jobs/entities/agentic-job-run.entity.js → automations/entities/automation-run.entity.js} +22 -14
- package/dist/services/{agentic-jobs/entities/agentic-job-run.entity.mjs → automations/entities/automation-run.entity.mjs} +18 -10
- package/dist/services/automations/entities/automation.entity.d.ts +38 -0
- package/dist/services/{agentic-jobs/entities/agentic-job.entity.js → automations/entities/automation.entity.js} +17 -17
- package/dist/services/{agentic-jobs/entities/agentic-job.entity.mjs → automations/entities/automation.entity.mjs} +13 -13
- package/dist/services/automations/entities/index.d.ts +4 -0
- package/dist/services/{agentic-jobs → automations}/entities/index.js +6 -4
- package/dist/services/automations/entities/index.mjs +4 -0
- package/dist/services/automations/entities/trigger.d.ts +11 -0
- package/dist/services/automations/entities/trigger.js +49 -0
- package/dist/services/automations/entities/trigger.mjs +26 -0
- package/dist/services/automations/index.d.ts +5 -0
- package/dist/services/{agentic-jobs → automations}/index.js +9 -7
- package/dist/services/automations/index.mjs +5 -0
- package/dist/services/automations/module.d.ts +41 -0
- package/dist/services/automations/module.js +167 -0
- package/dist/services/automations/module.mjs +125 -0
- package/dist/services/automations/repositories/automation-run.repository.d.ts +14 -0
- package/dist/services/{agentic-jobs/repositories/agentic-job-run.repository.js → automations/repositories/automation-run.repository.js} +23 -11
- package/dist/services/{agentic-jobs/repositories/agentic-job-run.repository.mjs → automations/repositories/automation-run.repository.mjs} +19 -7
- package/dist/services/automations/repositories/automation.repository.d.ts +27 -0
- package/dist/services/{agentic-jobs/repositories/agentic-job.repository.js → automations/repositories/automation.repository.js} +17 -17
- package/dist/services/{agentic-jobs/repositories/agentic-job.repository.mjs → automations/repositories/automation.repository.mjs} +13 -13
- package/dist/services/automations/repositories/index.d.ts +2 -0
- package/dist/services/automations/repositories/index.js +24 -0
- package/dist/services/automations/repositories/index.mjs +2 -0
- package/dist/services/automations/runner/automation-runner.d.ts +49 -0
- package/dist/services/{agentic-jobs/runner/agentic-job-runner.js → automations/runner/automation-runner.js} +55 -45
- package/dist/services/{agentic-jobs/runner/agentic-job-runner.mjs → automations/runner/automation-runner.mjs} +50 -40
- 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
- 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
- package/dist/services/automations/use-cases/attach-automation-run-chat.use-case.mjs +29 -0
- package/dist/services/automations/use-cases/claim-due-automations.use-case.d.ts +28 -0
- 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
- package/dist/services/automations/use-cases/claim-due-automations.use-case.mjs +70 -0
- package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.d.ts +27 -0
- package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.js +106 -0
- package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.mjs +77 -0
- package/dist/services/automations/use-cases/create-automation.use-case.d.ts +14 -0
- package/dist/services/{agentic-jobs/use-cases/create-agentic-job.use-case.js → automations/use-cases/create-automation.use-case.js} +24 -25
- package/dist/services/automations/use-cases/create-automation.use-case.mjs +43 -0
- 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
- package/dist/services/{agentic-jobs/use-cases/delete-agentic-job.use-case.js → automations/use-cases/delete-automation.use-case.js} +17 -17
- package/dist/services/automations/use-cases/delete-automation.use-case.mjs +36 -0
- 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
- 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
- package/dist/services/automations/use-cases/finish-automation-run.use-case.mjs +46 -0
- 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
- 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
- package/dist/services/automations/use-cases/get-automation-by-id.use-case.mjs +26 -0
- package/dist/services/automations/use-cases/issue-automation-event-token.use-case.d.ts +17 -0
- package/dist/services/automations/use-cases/issue-automation-event-token.use-case.js +59 -0
- package/dist/services/automations/use-cases/issue-automation-event-token.use-case.mjs +30 -0
- package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.d.ts +17 -0
- package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.js +61 -0
- package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.mjs +32 -0
- 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} +8 -7
- 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} +19 -15
- package/dist/services/automations/use-cases/list-automation-runs-by-user.use-case.mjs +32 -0
- 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} +7 -6
- 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} +19 -15
- package/dist/services/automations/use-cases/list-automations-by-user.use-case.mjs +32 -0
- 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
- 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
- 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
- package/dist/services/automations/use-cases/receive-automation-event.use-case.d.ts +23 -0
- package/dist/services/automations/use-cases/receive-automation-event.use-case.js +97 -0
- package/dist/services/automations/use-cases/receive-automation-event.use-case.mjs +68 -0
- 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
- 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
- package/dist/services/automations/use-cases/renew-automation-lease.use-case.mjs +29 -0
- package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.d.ts +16 -0
- package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.js +65 -0
- package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.mjs +36 -0
- package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.d.ts +14 -0
- package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.js +63 -0
- package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.mjs +34 -0
- package/dist/services/automations/use-cases/start-automation-run.use-case.d.ts +21 -0
- 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
- package/dist/services/automations/use-cases/start-automation-run.use-case.mjs +38 -0
- package/dist/services/automations/use-cases/sync-automation-run.use-case.d.ts +20 -0
- 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
- 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
- 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
- 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
- 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
- package/dist/services/automations/use-cases/update-automation.use-case.d.ts +15 -0
- package/dist/services/{agentic-jobs/use-cases/update-agentic-job.use-case.js → automations/use-cases/update-automation.use-case.js} +27 -27
- package/dist/services/automations/use-cases/update-automation.use-case.mjs +54 -0
- package/dist/services/automations/utils/automation-event-error.d.ts +6 -0
- package/dist/services/automations/utils/automation-event-error.js +37 -0
- package/dist/services/automations/utils/automation-event-error.mjs +14 -0
- package/dist/services/automations/utils/automation-fields.d.ts +14 -0
- package/dist/services/{agentic-jobs/utils/job-fields.js → automations/utils/automation-fields.js} +8 -10
- package/dist/services/{agentic-jobs/utils/job-fields.mjs → automations/utils/automation-fields.mjs} +4 -6
- package/dist/services/automations/utils/event-message.d.ts +1 -0
- package/dist/services/automations/utils/event-message.js +37 -0
- package/dist/services/automations/utils/event-message.mjs +14 -0
- package/dist/services/automations/utils/event-token.d.ts +18 -0
- package/dist/services/automations/utils/event-token.js +78 -0
- package/dist/services/automations/utils/event-token.mjs +43 -0
- package/dist/services/automations/utils/open-run.d.ts +14 -0
- package/dist/services/{agentic-jobs → automations}/utils/open-run.js +10 -8
- package/dist/services/automations/utils/open-run.mjs +26 -0
- package/dist/services/automations/utils/previous-run.d.ts +4 -0
- package/dist/services/automations/utils/previous-run.js +42 -0
- package/dist/services/automations/utils/previous-run.mjs +19 -0
- package/dist/services/{agentic-jobs → automations}/utils/settings.d.ts +1 -0
- package/dist/services/{agentic-jobs → automations}/utils/settings.js +6 -2
- package/dist/services/automations/utils/settings.mjs +13 -0
- package/dist/services/chats/use-cases/list-chats-by-user.use-case.d.ts +1 -0
- package/dist/services/chats/use-cases/list-chats-by-user.use-case.js +2 -2
- package/dist/services/chats/use-cases/list-chats-by-user.use-case.mjs +2 -2
- package/dist/services/mcp-servers/use-cases/list-mcpservers-by-user.use-case.d.ts +1 -0
- package/dist/services/mcp-servers/use-cases/list-mcpservers-by-user.use-case.js +2 -2
- package/dist/services/mcp-servers/use-cases/list-mcpservers-by-user.use-case.mjs +2 -2
- package/docs/README.md +1 -1
- package/docs/agent.md +2 -2
- package/docs/authentication.md +18 -1
- package/docs/automations.md +388 -0
- package/docs/chats.md +1 -1
- package/docs/configuration.md +6 -5
- package/docs/harness.md +1 -1
- package/docs/integration-guide.md +22 -18
- package/docs/llms.txt +1 -1
- package/docs/mcp-servers.md +1 -1
- package/examples/{agentic-jobs/create-agentic-job.ts → automations/create-automation.ts} +10 -7
- package/examples/automations/create-event-automation.ts +24 -0
- package/examples/{agentic-jobs/list-agentic-job-runs.ts → automations/list-automation-runs.ts} +8 -8
- package/examples/automations/list-automations.ts +25 -0
- package/examples/{agentic-jobs/preview-agentic-job-runs.ts → automations/preview-automation-runs.ts} +2 -2
- package/examples/automations/receive-automation-event.ts +26 -0
- package/examples/automations/revoke-automation-event-token.ts +25 -0
- package/examples/{agentic-jobs/run-agentic-job-now.ts → automations/run-automation-now.ts} +3 -3
- package/examples/{agentic-jobs/run-agentic-job-worker.ts → automations/run-automation-worker.ts} +6 -6
- package/examples/{agentic-jobs/update-agentic-job.ts → automations/update-automation.ts} +10 -10
- package/package.json +16 -14
- package/dist/db/indexes/agentic-job-runs.d.ts +0 -2
- package/dist/db/indexes/agentic-job-runs.mjs +0 -9
- package/dist/db/indexes/agentic-jobs.d.ts +0 -2
- package/dist/services/agentic-jobs/entities/agentic-job-run.entity.d.ts +0 -42
- package/dist/services/agentic-jobs/entities/agentic-job.entity.d.ts +0 -39
- package/dist/services/agentic-jobs/entities/index.d.ts +0 -3
- package/dist/services/agentic-jobs/entities/index.mjs +0 -3
- package/dist/services/agentic-jobs/index.d.ts +0 -4
- package/dist/services/agentic-jobs/index.mjs +0 -4
- package/dist/services/agentic-jobs/module.d.ts +0 -31
- package/dist/services/agentic-jobs/module.js +0 -132
- package/dist/services/agentic-jobs/module.mjs +0 -95
- package/dist/services/agentic-jobs/repositories/agentic-job-run.repository.d.ts +0 -11
- package/dist/services/agentic-jobs/repositories/agentic-job.repository.d.ts +0 -27
- package/dist/services/agentic-jobs/repositories/index.d.ts +0 -2
- package/dist/services/agentic-jobs/repositories/index.mjs +0 -2
- package/dist/services/agentic-jobs/runner/agentic-job-runner.d.ts +0 -48
- package/dist/services/agentic-jobs/use-cases/attach-agentic-job-run-chat.use-case.mjs +0 -29
- package/dist/services/agentic-jobs/use-cases/claim-due-agentic-jobs.use-case.d.ts +0 -29
- package/dist/services/agentic-jobs/use-cases/claim-due-agentic-jobs.use-case.mjs +0 -81
- package/dist/services/agentic-jobs/use-cases/create-agentic-job.use-case.d.ts +0 -14
- package/dist/services/agentic-jobs/use-cases/create-agentic-job.use-case.mjs +0 -44
- package/dist/services/agentic-jobs/use-cases/delete-agentic-job.use-case.mjs +0 -36
- package/dist/services/agentic-jobs/use-cases/finish-agentic-job-run.use-case.mjs +0 -46
- package/dist/services/agentic-jobs/use-cases/get-agentic-job-by-id.use-case.mjs +0 -26
- package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-job.use-case.d.ts +0 -16
- package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-job.use-case.mjs +0 -28
- package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-user.use-case.mjs +0 -28
- package/dist/services/agentic-jobs/use-cases/list-agentic-jobs-by-user.use-case.mjs +0 -28
- package/dist/services/agentic-jobs/use-cases/renew-agentic-job-lease.use-case.mjs +0 -29
- package/dist/services/agentic-jobs/use-cases/start-agentic-job-run.use-case.d.ts +0 -21
- package/dist/services/agentic-jobs/use-cases/start-agentic-job-run.use-case.mjs +0 -38
- package/dist/services/agentic-jobs/use-cases/sync-agentic-job-run.use-case.d.ts +0 -20
- package/dist/services/agentic-jobs/use-cases/update-agentic-job.use-case.d.ts +0 -15
- package/dist/services/agentic-jobs/use-cases/update-agentic-job.use-case.mjs +0 -54
- package/dist/services/agentic-jobs/utils/job-fields.d.ts +0 -14
- package/dist/services/agentic-jobs/utils/open-run.d.ts +0 -12
- package/dist/services/agentic-jobs/utils/open-run.mjs +0 -24
- package/dist/services/agentic-jobs/utils/settings.mjs +0 -10
- package/docs/agentic-jobs.md +0 -217
- package/examples/agentic-jobs/list-agentic-jobs.ts +0 -25
- /package/dist/services/{agentic-jobs → automations}/entities/recurrence.d.ts +0 -0
- /package/dist/services/{agentic-jobs → automations}/entities/recurrence.js +0 -0
- /package/dist/services/{agentic-jobs → automations}/entities/recurrence.mjs +0 -0
- /package/dist/services/{agentic-jobs → automations}/utils/next-run.d.ts +0 -0
- /package/dist/services/{agentic-jobs → automations}/utils/next-run.js +0 -0
- /package/dist/services/{agentic-jobs → automations}/utils/next-run.mjs +0 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `openloops` are written here, newest first. The format follows [Keep a Changelog](https://keepachangelog.com) and the versions follow [semantic versioning](https://semver.org), where a minor version can still break the API while the package is in beta. Changes before 0.4.0 are not recorded here, see the commits and the tags.
|
|
4
|
+
|
|
5
|
+
## Unreleased
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- `hasMore` in the output of `listChatsByUser`, `listMcpServersByUser`, `listAutomationsByUser`, `listAutomationRunsByUser` and `listAutomationRunsByAutomation`. It is `true` when there is a next page, so the client does not need to guess from the size of the last one. It is computed by reading one extra item, without a count query.
|
|
10
|
+
- `MongoRepository.findManyPaginated`, which returns `{ items, hasMore }`. `findMany` is unchanged.
|
|
11
|
+
|
|
12
|
+
## 0.4.0
|
|
13
|
+
|
|
14
|
+
This version breaks the API of the former agentic jobs. Follow the [migration steps](docs/automations.md#migrating-from-agentic-jobs) when you update.
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- Automations with an event trigger: another system sends an event, it becomes a queued run with its payload, and the runner executes the events of an automation one at a time and in order. See [automations](docs/automations.md#events).
|
|
19
|
+
- Tokens for those events, signed and not stored, that can be issued again, revoked one by one or rotated all at once (`issueAutomationEventToken`, `revokeAutomationEventToken`, `rotateAutomationEventTokens`).
|
|
20
|
+
- `receiveAutomationEvent`, with idempotency keys, a limit on the payload and a limit on the queue (`AUTOMATIONS_MAX_QUEUED_RUNS`).
|
|
21
|
+
- `runner.wake()` to make the runner check right away.
|
|
22
|
+
- `revokeToken` and `isTokenRevoked` in `openloops/authentication`, over the new generic collection `revoked_tokens`.
|
|
23
|
+
- `migrateAutomations` in `openloops/db` and `yarn migrate:automations` to move the data of the former agentic jobs.
|
|
24
|
+
|
|
25
|
+
### Changed
|
|
26
|
+
|
|
27
|
+
- Agentic jobs are now automations. The import is `openloops/automations`, the collections are `automations` and `automation_runs`, the runs use `automationId` and the variables are `AUTOMATIONS_POLL_INTERVAL_MS` and `AUTOMATIONS_LEASE_MS`. The old variables are not read anymore.
|
|
28
|
+
- `recurrence` and `timezone` of an automation now live inside its `trigger`, which is either a `schedule` or an `event`. The type of the trigger cannot be changed after the automation is created.
|
|
29
|
+
- A run can now have the status `queued` and the trigger `event`, and keeps the `payload` and `idempotencyKey` of the event.
|
|
30
|
+
- `JWT_SECRET` is also needed to sign the tokens of event automations.
|
|
31
|
+
|
|
32
|
+
### Removed
|
|
33
|
+
|
|
34
|
+
- The `openloops/agentic-jobs` export and every name that had `AgenticJob` in it. There are no aliases.
|
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ A model alone only chats. The harness is what lets it act, safely, for many user
|
|
|
40
40
|
| **Transmission** | Takes the model to the outside world | Your tools and MCP servers, found on demand and validated before they run. See [tools](docs/tools.md) and [MCP servers](docs/mcp-servers.md) |
|
|
41
41
|
| **Brakes** | Stops the agent when it should stop | Confirmation of destructive tools, approval of MCP servers, input guardrails, timeouts and a budget per task. See [guardrails](docs/guardrails.md) and [the harness](docs/harness.md) |
|
|
42
42
|
| **Logbook** | Remembers and records everything | Chats, tasks, every tool call, traces, and usage and cost per call. See [chats](docs/chats.md) and [usage](docs/usage.md) |
|
|
43
|
-
| **Steering** | Decides how the agent is driven | Interactive and autonomous runs, scheduled
|
|
43
|
+
| **Steering** | Decides how the agent is driven | Interactive and autonomous runs, scheduled automations, stopping a run, and the model per chat and per user. See [the Agent](docs/agent.md), [automations](docs/automations.md) and [configuration](docs/configuration.md) |
|
|
44
44
|
|
|
45
45
|
## Why it is a good harness
|
|
46
46
|
|
|
@@ -56,7 +56,7 @@ Not adjectives, mechanisms that you can read in the code and in the tests:
|
|
|
56
56
|
|
|
57
57
|
## Building a backend with it
|
|
58
58
|
|
|
59
|
-
If you or your coding agent are going to build the backend that uses `openloops`, start with the [integration guide](docs/integration-guide.md). It lists which endpoint calls which use case, what authorization is left to you (the package has no HTTP layer), how to run agents and scheduled
|
|
59
|
+
If you or your coding agent are going to build the backend that uses `openloops`, start with the [integration guide](docs/integration-guide.md). It lists which endpoint calls which use case, what authorization is left to you (the package has no HTTP layer), how to run agents and scheduled automations, and a security checklist. The whole documentation is also shipped inside the package, in `node_modules/openloops/docs`, with an index for tools in [`docs/llms.txt`](docs/llms.txt).
|
|
60
60
|
|
|
61
61
|
To make sure that your coding agent reads it in every session, add this to the `CLAUDE.md` or `AGENTS.md` of your backend:
|
|
62
62
|
|
|
@@ -104,7 +104,7 @@ You know the pattern: before you write a single line of what your agent actually
|
|
|
104
104
|
- **Safe tool execution.** Arguments are validated against the tool's schema, destructive tools wait for the user's confirmation, identical failing calls are blocked, identifiers the model invented are rejected before they reach a real system, and large outputs are kept out of the prompt. LLM calls retry with backoff and wait out rate limits.
|
|
105
105
|
- **Native MCP support with a trust flow.** Connect any MCP server and its tools become regular tools. Each server must be approved by the user before its first tool runs, and a server that changes its tools is reviewed again, so a third party cannot quietly change what your agent does.
|
|
106
106
|
- **Autonomous runs.** The same agent can work without a person in the chat, for scheduled tasks. Whatever needs the user pauses the run in the chat, and the user answers there to continue. See [autonomous mode](docs/agent.md#autonomous-mode).
|
|
107
|
-
- **
|
|
107
|
+
- **Automations.** Tasks that the agent runs by itself, on a schedule (daily, weekly, monthly or once, in the timezone of the user) or when another system sends an event, with signed tokens that can be revoked and a queue per automation. A worker runs what is due, safely across several instances, and keeps a history of every run with its chat. See [automations](docs/automations.md).
|
|
108
108
|
- **Guardrails.** Input guards block messages with card numbers, emails, code or anything you define, before the model sees them. See [guardrails](docs/guardrails.md).
|
|
109
109
|
- **Usage and cost tracking.** Every LLM call is recorded. Get the tokens and cost of a chat or an answer, and per-user statistics by model and by period. See [usage](docs/usage.md).
|
|
110
110
|
- **Users and authentication included.** User management and login with tokens, so you don't need a parallel system just to have an identity to hand the `Agent`.
|
|
@@ -219,8 +219,9 @@ LLM_FALLBACK_PROVIDER=
|
|
|
219
219
|
LLM_FALLBACK_MODEL=
|
|
220
220
|
|
|
221
221
|
# Optional, in milliseconds
|
|
222
|
-
|
|
223
|
-
|
|
222
|
+
AUTOMATIONS_POLL_INTERVAL_MS=
|
|
223
|
+
AUTOMATIONS_LEASE_MS=
|
|
224
|
+
AUTOMATIONS_MAX_QUEUED_RUNS=
|
|
224
225
|
LLM_CALL_TIMEOUT_MS=
|
|
225
226
|
MCP_TOOL_TIMEOUT_MS=
|
|
226
227
|
|
|
@@ -261,7 +262,7 @@ Neither requires any code changes. They're opt-in purely through environment var
|
|
|
261
262
|
|
|
262
263
|
## More examples
|
|
263
264
|
|
|
264
|
-
Every pattern above, and a lot more, lives as a runnable example in [`examples/`](examples), organized by domain: `run-agent`, `loops`, `tools`, `guardrails`, `
|
|
265
|
+
Every pattern above, and a lot more, lives as a runnable example in [`examples/`](examples), organized by domain: `run-agent`, `loops`, `tools`, `guardrails`, `automations`, `mcps`, `chats`, `usage`, `users`, and `authentication`.
|
|
265
266
|
|
|
266
267
|
## Package structure
|
|
267
268
|
|
|
@@ -275,7 +276,7 @@ Every pattern above, and a lot more, lives as a runnable example in [`examples/`
|
|
|
275
276
|
| `openloops/skills` | `Skill`, for writing LLM-backed reasoning steps inside a loop |
|
|
276
277
|
| `openloops/guardrails` | `Guard` and the ready-made input guards |
|
|
277
278
|
| `openloops/mcps` | MCP server management, connection check and trust decisions |
|
|
278
|
-
| `openloops/
|
|
279
|
+
| `openloops/automations` | Scheduled and event tasks, their runs and the runner that executes them |
|
|
279
280
|
| `openloops/chats` | Chats and their messages: list, read, update, delete |
|
|
280
281
|
| `openloops/users` | User management |
|
|
281
282
|
| `openloops/authentication` | Login and token issuing |
|
|
@@ -295,12 +296,13 @@ Every pattern above, and a lot more, lives as a runnable example in [`examples/`
|
|
|
295
296
|
- [Skills](docs/skills.md)
|
|
296
297
|
- [Guardrails](docs/guardrails.md)
|
|
297
298
|
- [MCP servers](docs/mcp-servers.md)
|
|
298
|
-
- [
|
|
299
|
+
- [Automations](docs/automations.md)
|
|
299
300
|
- [Chats](docs/chats.md)
|
|
300
301
|
- [User management](docs/users.md)
|
|
301
302
|
- [Authentication](docs/authentication.md)
|
|
302
303
|
- [LLM usage tracking](docs/usage.md)
|
|
303
304
|
- [Configuration](docs/configuration.md)
|
|
305
|
+
- [Changelog](CHANGELOG.md)
|
|
304
306
|
|
|
305
307
|
## License
|
|
306
308
|
|
|
@@ -19,7 +19,12 @@ export declare class MongoRepository<T> {
|
|
|
19
19
|
cleanInput(value: string): string;
|
|
20
20
|
private clampLimit;
|
|
21
21
|
findOne({ where, select, options }: QueryParams<T>): Promise<T | null>;
|
|
22
|
-
findMany(
|
|
22
|
+
findMany(params: QueryParams<T>): Promise<T[]>;
|
|
23
|
+
findManyPaginated(params: QueryParams<T>): Promise<{
|
|
24
|
+
items: T[];
|
|
25
|
+
hasMore: boolean;
|
|
26
|
+
}>;
|
|
27
|
+
private query;
|
|
23
28
|
findAll({ where, select, options }: QueryParams<T>): Promise<T[]>;
|
|
24
29
|
createOne({ payload }: CommandParams<T>): Promise<ObjectId>;
|
|
25
30
|
createMany({ payload }: CommandParams<T>): Promise<CreateManyResponse>;
|
|
@@ -76,14 +76,22 @@ class MongoRepository {
|
|
|
76
76
|
throw error;
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
|
-
async findMany(
|
|
79
|
+
async findMany(params) {
|
|
80
|
+
const _limit = this.clampLimit(params.options?.limit);
|
|
81
|
+
return this.query(params, _limit, _limit);
|
|
82
|
+
}
|
|
83
|
+
async findManyPaginated(params) {
|
|
84
|
+
const _limit = this.clampLimit(params.options?.limit);
|
|
85
|
+
const results = await this.query(params, _limit, _limit + 1);
|
|
86
|
+
return { items: results.slice(0, _limit), hasMore: results.length > _limit };
|
|
87
|
+
}
|
|
88
|
+
async query({ where, select, options }, pageSize, fetchSize) {
|
|
80
89
|
try {
|
|
81
90
|
const db = await this.dbClient.db(this.database);
|
|
82
91
|
const collection = db.collection(this.collection);
|
|
83
|
-
const { page = 1
|
|
84
|
-
const
|
|
85
|
-
const
|
|
86
|
-
const result = await collection.find({ ...where, ...this._where }, { projection: select }).sort(options?.sortBy || { _id: -1 }).skip(_skip).limit(_limit).toArray();
|
|
92
|
+
const { page = 1 } = options || {};
|
|
93
|
+
const _skip = +page > 0 ? (+page - 1) * pageSize : 0;
|
|
94
|
+
const result = await collection.find({ ...where, ...this._where }, { projection: select }).sort(options?.sortBy || { _id: -1 }).skip(_skip).limit(fetchSize).toArray();
|
|
87
95
|
return result;
|
|
88
96
|
} catch (error) {
|
|
89
97
|
await this.report(error);
|
|
@@ -53,14 +53,22 @@ class MongoRepository {
|
|
|
53
53
|
throw error;
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
async findMany(
|
|
56
|
+
async findMany(params) {
|
|
57
|
+
const _limit = this.clampLimit(params.options?.limit);
|
|
58
|
+
return this.query(params, _limit, _limit);
|
|
59
|
+
}
|
|
60
|
+
async findManyPaginated(params) {
|
|
61
|
+
const _limit = this.clampLimit(params.options?.limit);
|
|
62
|
+
const results = await this.query(params, _limit, _limit + 1);
|
|
63
|
+
return { items: results.slice(0, _limit), hasMore: results.length > _limit };
|
|
64
|
+
}
|
|
65
|
+
async query({ where, select, options }, pageSize, fetchSize) {
|
|
57
66
|
try {
|
|
58
67
|
const db = await this.dbClient.db(this.database);
|
|
59
68
|
const collection = db.collection(this.collection);
|
|
60
|
-
const { page = 1
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
const result = await collection.find({ ...where, ...this._where }, { projection: select }).sort(options?.sortBy || { _id: -1 }).skip(_skip).limit(_limit).toArray();
|
|
69
|
+
const { page = 1 } = options || {};
|
|
70
|
+
const _skip = +page > 0 ? (+page - 1) * pageSize : 0;
|
|
71
|
+
const result = await collection.find({ ...where, ...this._where }, { projection: select }).sort(options?.sortBy || { _id: -1 }).skip(_skip).limit(fetchSize).toArray();
|
|
64
72
|
return result;
|
|
65
73
|
} catch (error) {
|
|
66
74
|
await this.report(error);
|
package/dist/db/index.d.ts
CHANGED
package/dist/db/index.js
CHANGED
|
@@ -16,7 +16,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
16
16
|
var db_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(db_exports);
|
|
18
18
|
__reExport(db_exports, require("./indexes"), module.exports);
|
|
19
|
+
__reExport(db_exports, require("./migrations/automations"), module.exports);
|
|
19
20
|
// Annotate the CommonJS export names for ESM import in node:
|
|
20
21
|
0 && (module.exports = {
|
|
21
|
-
...require("./indexes")
|
|
22
|
+
...require("./indexes"),
|
|
23
|
+
...require("./migrations/automations")
|
|
22
24
|
});
|
package/dist/db/index.mjs
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var automation_runs_exports = {};
|
|
20
|
+
__export(automation_runs_exports, {
|
|
21
|
+
automationRuns: () => automationRuns
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(automation_runs_exports);
|
|
24
|
+
const automationRuns = [
|
|
25
|
+
{ key: { automationId: 1, createdAt: -1 } },
|
|
26
|
+
{ key: { ownerId: 1, createdAt: -1 } },
|
|
27
|
+
{ key: { status: 1, createdAt: 1 } },
|
|
28
|
+
{ key: { automationId: 1, idempotencyKey: 1 }, unique: true, partialFilterExpression: { idempotencyKey: { $exists: true } } }
|
|
29
|
+
];
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
automationRuns
|
|
33
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import "../../chunk-CF3WOMB3.mjs";
|
|
2
|
+
const automationRuns = [
|
|
3
|
+
{ key: { automationId: 1, createdAt: -1 } },
|
|
4
|
+
{ key: { ownerId: 1, createdAt: -1 } },
|
|
5
|
+
{ key: { status: 1, createdAt: 1 } },
|
|
6
|
+
{ key: { automationId: 1, idempotencyKey: 1 }, unique: true, partialFilterExpression: { idempotencyKey: { $exists: true } } }
|
|
7
|
+
];
|
|
8
|
+
export {
|
|
9
|
+
automationRuns
|
|
10
|
+
};
|
|
@@ -16,16 +16,16 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
21
|
-
|
|
19
|
+
var automations_exports = {};
|
|
20
|
+
__export(automations_exports, {
|
|
21
|
+
automations: () => automations
|
|
22
22
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
24
|
-
const
|
|
23
|
+
module.exports = __toCommonJS(automations_exports);
|
|
24
|
+
const automations = [
|
|
25
25
|
{ key: { enabled: 1, nextRunAt: 1 } },
|
|
26
26
|
{ key: { ownerId: 1, createdAt: -1 } }
|
|
27
27
|
];
|
|
28
28
|
// Annotate the CommonJS export names for ESM import in node:
|
|
29
29
|
0 && (module.exports = {
|
|
30
|
-
|
|
30
|
+
automations
|
|
31
31
|
});
|
package/dist/db/indexes/index.js
CHANGED
|
@@ -29,8 +29,9 @@ var import_agent_actions = require("./agent-actions");
|
|
|
29
29
|
var import_agent_traces = require("./agent-traces");
|
|
30
30
|
var import_workspace_items = require("./workspace-items");
|
|
31
31
|
var import_mcp_servers = require("./mcp-servers");
|
|
32
|
-
var
|
|
33
|
-
var
|
|
32
|
+
var import_automations = require("./automations");
|
|
33
|
+
var import_automation_runs = require("./automation-runs");
|
|
34
|
+
var import_revoked_tokens = require("./revoked-tokens");
|
|
34
35
|
const indexes = {
|
|
35
36
|
llm_calls: import_llm_calls.llmCalls,
|
|
36
37
|
chats: import_chats.chats,
|
|
@@ -39,8 +40,9 @@ const indexes = {
|
|
|
39
40
|
agent_traces: import_agent_traces.agentTraces,
|
|
40
41
|
workspace_items: import_workspace_items.workspaceItems,
|
|
41
42
|
mcp_servers: import_mcp_servers.mcpServers,
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
automations: import_automations.automations,
|
|
44
|
+
automation_runs: import_automation_runs.automationRuns,
|
|
45
|
+
revoked_tokens: import_revoked_tokens.revokedTokens
|
|
44
46
|
};
|
|
45
47
|
async function ensureIndexes(db) {
|
|
46
48
|
const created = {};
|
|
@@ -6,8 +6,9 @@ import { agentActions } from "./agent-actions";
|
|
|
6
6
|
import { agentTraces } from "./agent-traces";
|
|
7
7
|
import { workspaceItems } from "./workspace-items";
|
|
8
8
|
import { mcpServers } from "./mcp-servers";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { automations } from "./automations";
|
|
10
|
+
import { automationRuns } from "./automation-runs";
|
|
11
|
+
import { revokedTokens } from "./revoked-tokens";
|
|
11
12
|
const indexes = {
|
|
12
13
|
llm_calls: llmCalls,
|
|
13
14
|
chats,
|
|
@@ -16,8 +17,9 @@ const indexes = {
|
|
|
16
17
|
agent_traces: agentTraces,
|
|
17
18
|
workspace_items: workspaceItems,
|
|
18
19
|
mcp_servers: mcpServers,
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
automations,
|
|
21
|
+
automation_runs: automationRuns,
|
|
22
|
+
revoked_tokens: revokedTokens
|
|
21
23
|
};
|
|
22
24
|
async function ensureIndexes(db) {
|
|
23
25
|
const created = {};
|
|
@@ -16,17 +16,16 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
21
|
-
|
|
19
|
+
var revoked_tokens_exports = {};
|
|
20
|
+
__export(revoked_tokens_exports, {
|
|
21
|
+
revokedTokens: () => revokedTokens
|
|
22
22
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
24
|
-
const
|
|
25
|
-
{ key: {
|
|
26
|
-
{ key: {
|
|
27
|
-
{ key: { status: 1, createdAt: 1 } }
|
|
23
|
+
module.exports = __toCommonJS(revoked_tokens_exports);
|
|
24
|
+
const revokedTokens = [
|
|
25
|
+
{ key: { jti: 1 }, unique: true },
|
|
26
|
+
{ key: { expiresAt: 1 }, expireAfterSeconds: 0 }
|
|
28
27
|
];
|
|
29
28
|
// Annotate the CommonJS export names for ESM import in node:
|
|
30
29
|
0 && (module.exports = {
|
|
31
|
-
|
|
30
|
+
revokedTokens
|
|
32
31
|
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Db } from 'mongodb';
|
|
2
|
+
export interface AutomationsMigrationOptions {
|
|
3
|
+
dryRun?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export interface AutomationsMigrationReport {
|
|
6
|
+
dryRun: boolean;
|
|
7
|
+
renamedCollections: string[];
|
|
8
|
+
triggersCreated: number;
|
|
9
|
+
runsUpdated: number;
|
|
10
|
+
droppedIndexes: string[];
|
|
11
|
+
}
|
|
12
|
+
export declare function migrateAutomations(db: Db, options?: AutomationsMigrationOptions): Promise<AutomationsMigrationReport>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var automations_exports = {};
|
|
20
|
+
__export(automations_exports, {
|
|
21
|
+
migrateAutomations: () => migrateAutomations
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(automations_exports);
|
|
24
|
+
var import_indexes = require("../indexes");
|
|
25
|
+
const RENAMES = [
|
|
26
|
+
["agentic_jobs", "automations"],
|
|
27
|
+
["agentic_job_runs", "automation_runs"]
|
|
28
|
+
];
|
|
29
|
+
const OLD_RUN_INDEX = "jobId_1_createdAt_-1";
|
|
30
|
+
const exists = async (db, name) => (await db.listCollections({ name }).toArray()).length > 0;
|
|
31
|
+
async function migrateAutomations(db, options = {}) {
|
|
32
|
+
const dryRun = Boolean(options.dryRun);
|
|
33
|
+
const report = { dryRun, renamedCollections: [], triggersCreated: 0, runsUpdated: 0, droppedIndexes: [] };
|
|
34
|
+
for (const [from, to] of RENAMES) {
|
|
35
|
+
if (!await exists(db, from)) continue;
|
|
36
|
+
if (await exists(db, to)) throw new Error(`Cannot rename ${from} to ${to} because ${to} already exists`);
|
|
37
|
+
if (!dryRun) await db.renameCollection(from, to);
|
|
38
|
+
report.renamedCollections.push(`${from} -> ${to}`);
|
|
39
|
+
}
|
|
40
|
+
const automations = db.collection(dryRun && report.renamedCollections.length ? "agentic_jobs" : "automations");
|
|
41
|
+
const runs = db.collection(dryRun && report.renamedCollections.length ? "agentic_job_runs" : "automation_runs");
|
|
42
|
+
const withoutTrigger = { trigger: { $exists: false }, recurrence: { $exists: true } };
|
|
43
|
+
const withJobId = { jobId: { $exists: true } };
|
|
44
|
+
if (dryRun) {
|
|
45
|
+
report.triggersCreated = await automations.countDocuments(withoutTrigger);
|
|
46
|
+
report.runsUpdated = await runs.countDocuments(withJobId);
|
|
47
|
+
} else {
|
|
48
|
+
const triggers = await automations.updateMany(withoutTrigger, [
|
|
49
|
+
{ $set: { trigger: { type: "schedule", recurrence: "$recurrence", timezone: "$timezone" } } },
|
|
50
|
+
{ $unset: ["recurrence", "timezone"] }
|
|
51
|
+
]);
|
|
52
|
+
const moved = await runs.updateMany(withJobId, [
|
|
53
|
+
{ $set: { automationId: "$jobId" } },
|
|
54
|
+
{ $unset: "jobId" }
|
|
55
|
+
]);
|
|
56
|
+
report.triggersCreated = triggers.modifiedCount;
|
|
57
|
+
report.runsUpdated = moved.modifiedCount;
|
|
58
|
+
}
|
|
59
|
+
const indexes = await runs.indexes().catch(() => []);
|
|
60
|
+
if (indexes.some((index) => index.name === OLD_RUN_INDEX)) {
|
|
61
|
+
if (!dryRun) await runs.dropIndex(OLD_RUN_INDEX);
|
|
62
|
+
report.droppedIndexes.push(OLD_RUN_INDEX);
|
|
63
|
+
}
|
|
64
|
+
if (!dryRun) await (0, import_indexes.ensureIndexes)(db);
|
|
65
|
+
return report;
|
|
66
|
+
}
|
|
67
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
68
|
+
0 && (module.exports = {
|
|
69
|
+
migrateAutomations
|
|
70
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import "../../chunk-CF3WOMB3.mjs";
|
|
2
|
+
import { ensureIndexes } from "../indexes";
|
|
3
|
+
const RENAMES = [
|
|
4
|
+
["agentic_jobs", "automations"],
|
|
5
|
+
["agentic_job_runs", "automation_runs"]
|
|
6
|
+
];
|
|
7
|
+
const OLD_RUN_INDEX = "jobId_1_createdAt_-1";
|
|
8
|
+
const exists = async (db, name) => (await db.listCollections({ name }).toArray()).length > 0;
|
|
9
|
+
async function migrateAutomations(db, options = {}) {
|
|
10
|
+
const dryRun = Boolean(options.dryRun);
|
|
11
|
+
const report = { dryRun, renamedCollections: [], triggersCreated: 0, runsUpdated: 0, droppedIndexes: [] };
|
|
12
|
+
for (const [from, to] of RENAMES) {
|
|
13
|
+
if (!await exists(db, from)) continue;
|
|
14
|
+
if (await exists(db, to)) throw new Error(`Cannot rename ${from} to ${to} because ${to} already exists`);
|
|
15
|
+
if (!dryRun) await db.renameCollection(from, to);
|
|
16
|
+
report.renamedCollections.push(`${from} -> ${to}`);
|
|
17
|
+
}
|
|
18
|
+
const automations = db.collection(dryRun && report.renamedCollections.length ? "agentic_jobs" : "automations");
|
|
19
|
+
const runs = db.collection(dryRun && report.renamedCollections.length ? "agentic_job_runs" : "automation_runs");
|
|
20
|
+
const withoutTrigger = { trigger: { $exists: false }, recurrence: { $exists: true } };
|
|
21
|
+
const withJobId = { jobId: { $exists: true } };
|
|
22
|
+
if (dryRun) {
|
|
23
|
+
report.triggersCreated = await automations.countDocuments(withoutTrigger);
|
|
24
|
+
report.runsUpdated = await runs.countDocuments(withJobId);
|
|
25
|
+
} else {
|
|
26
|
+
const triggers = await automations.updateMany(withoutTrigger, [
|
|
27
|
+
{ $set: { trigger: { type: "schedule", recurrence: "$recurrence", timezone: "$timezone" } } },
|
|
28
|
+
{ $unset: ["recurrence", "timezone"] }
|
|
29
|
+
]);
|
|
30
|
+
const moved = await runs.updateMany(withJobId, [
|
|
31
|
+
{ $set: { automationId: "$jobId" } },
|
|
32
|
+
{ $unset: "jobId" }
|
|
33
|
+
]);
|
|
34
|
+
report.triggersCreated = triggers.modifiedCount;
|
|
35
|
+
report.runsUpdated = moved.modifiedCount;
|
|
36
|
+
}
|
|
37
|
+
const indexes = await runs.indexes().catch(() => []);
|
|
38
|
+
if (indexes.some((index) => index.name === OLD_RUN_INDEX)) {
|
|
39
|
+
if (!dryRun) await runs.dropIndex(OLD_RUN_INDEX);
|
|
40
|
+
report.droppedIndexes.push(OLD_RUN_INDEX);
|
|
41
|
+
}
|
|
42
|
+
if (!dryRun) await ensureIndexes(db);
|
|
43
|
+
return report;
|
|
44
|
+
}
|
|
45
|
+
export {
|
|
46
|
+
migrateAutomations
|
|
47
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './revoked-token.entity';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var entities_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(entities_exports);
|
|
18
|
+
__reExport(entities_exports, require("./revoked-token.entity"), module.exports);
|
|
19
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
+
0 && (module.exports = {
|
|
21
|
+
...require("./revoked-token.entity")
|
|
22
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./revoked-token.entity";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BaseEntity, BaseEntityProps } from '../../../common/base/base.entity.js';
|
|
2
|
+
export interface RevokedTokenProps extends BaseEntityProps {
|
|
3
|
+
jti?: string;
|
|
4
|
+
audience?: string;
|
|
5
|
+
subject?: string;
|
|
6
|
+
expiresAt?: string | Date;
|
|
7
|
+
}
|
|
8
|
+
export declare class RevokedToken extends BaseEntity {
|
|
9
|
+
private readonly props;
|
|
10
|
+
jti?: string | undefined;
|
|
11
|
+
audience?: string | undefined;
|
|
12
|
+
subject?: string | undefined;
|
|
13
|
+
expiresAt?: Date | undefined;
|
|
14
|
+
static fromJSON(props: RevokedTokenProps): RevokedToken;
|
|
15
|
+
constructor(props: RevokedTokenProps, jti?: string | undefined, audience?: string | undefined, subject?: string | undefined, expiresAt?: Date | undefined);
|
|
16
|
+
toJSON(): RevokedTokenProps;
|
|
17
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var revoked_token_entity_exports = {};
|
|
20
|
+
__export(revoked_token_entity_exports, {
|
|
21
|
+
RevokedToken: () => RevokedToken
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(revoked_token_entity_exports);
|
|
24
|
+
var import_base = require("../../../common/base/base.entity.js");
|
|
25
|
+
const toDate = (value) => {
|
|
26
|
+
if (!value) return void 0;
|
|
27
|
+
const date = new Date(value);
|
|
28
|
+
if (Number.isNaN(date.getTime())) throw new Error("{{value_must_be_a_date}}");
|
|
29
|
+
return date;
|
|
30
|
+
};
|
|
31
|
+
class RevokedToken extends import_base.BaseEntity {
|
|
32
|
+
constructor(props, jti, audience, subject, expiresAt) {
|
|
33
|
+
super(props);
|
|
34
|
+
this.props = props;
|
|
35
|
+
this.jti = jti;
|
|
36
|
+
this.audience = audience;
|
|
37
|
+
this.subject = subject;
|
|
38
|
+
this.expiresAt = expiresAt;
|
|
39
|
+
}
|
|
40
|
+
props;
|
|
41
|
+
jti;
|
|
42
|
+
audience;
|
|
43
|
+
subject;
|
|
44
|
+
expiresAt;
|
|
45
|
+
static fromJSON(props) {
|
|
46
|
+
return new RevokedToken(
|
|
47
|
+
props,
|
|
48
|
+
props.jti || void 0,
|
|
49
|
+
props.audience || void 0,
|
|
50
|
+
props.subject || void 0,
|
|
51
|
+
toDate(props.expiresAt)
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
toJSON() {
|
|
55
|
+
return {
|
|
56
|
+
...super.toJSON(),
|
|
57
|
+
jti: this.jti,
|
|
58
|
+
audience: this.audience,
|
|
59
|
+
subject: this.subject,
|
|
60
|
+
expiresAt: this.expiresAt
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
65
|
+
0 && (module.exports = {
|
|
66
|
+
RevokedToken
|
|
67
|
+
});
|