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.
- package/README.md +9 -8
- 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/authentication/use-cases/is-token-revoked.use-case.js +55 -0
- 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/{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
- 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
- package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.mjs +28 -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} +7 -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} +14 -14
- 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
- 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
- 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
- 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
- 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/docs/README.md +1 -1
- package/docs/agent.md +2 -2
- package/docs/authentication.md +18 -1
- package/docs/automations.md +341 -0
- 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 +14 -13
- 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.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
|
@@ -25,30 +25,30 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
25
25
|
return result;
|
|
26
26
|
};
|
|
27
27
|
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
28
|
-
var
|
|
29
|
-
__export(
|
|
30
|
-
|
|
28
|
+
var claim_due_automations_use_case_exports = {};
|
|
29
|
+
__export(claim_due_automations_use_case_exports, {
|
|
30
|
+
ClaimDueAutomationsUseCase: () => ClaimDueAutomationsUseCase
|
|
31
31
|
});
|
|
32
|
-
module.exports = __toCommonJS(
|
|
32
|
+
module.exports = __toCommonJS(claim_due_automations_use_case_exports);
|
|
33
33
|
var import_tsyringe = require("tsyringe");
|
|
34
34
|
var import_logger = require("../../../common/logger/index.js");
|
|
35
35
|
var import_base = require("../../../common/base/base.use-case.js");
|
|
36
|
-
var import_entities = require("../entities");
|
|
37
36
|
var import_repositories = require("../repositories");
|
|
38
37
|
var import_next_run = require("../utils/next-run");
|
|
39
38
|
var import_open_run = require("../utils/open-run");
|
|
40
39
|
var import_settings = require("../utils/settings");
|
|
41
|
-
var
|
|
40
|
+
var import_previous_run = require("../utils/previous-run");
|
|
41
|
+
var import_sync_automation_run = require("./sync-automation-run.use-case");
|
|
42
42
|
const DEFAULT_LIMIT = 10;
|
|
43
|
-
let
|
|
44
|
-
constructor(
|
|
43
|
+
let ClaimDueAutomationsUseCase = class extends import_base.BaseUseCase {
|
|
44
|
+
constructor(automationRepository, automationRunRepository, syncRun) {
|
|
45
45
|
super();
|
|
46
|
-
this.
|
|
47
|
-
this.
|
|
46
|
+
this.automationRepository = automationRepository;
|
|
47
|
+
this.automationRunRepository = automationRunRepository;
|
|
48
48
|
this.syncRun = syncRun;
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
automationRepository;
|
|
51
|
+
automationRunRepository;
|
|
52
52
|
syncRun;
|
|
53
53
|
log = new import_logger.Logger();
|
|
54
54
|
async execute(params) {
|
|
@@ -56,55 +56,44 @@ let ClaimDueAgenticJobsUseCase = class extends import_base.BaseUseCase {
|
|
|
56
56
|
if (!workerId) throw new Error("The id of the worker is required");
|
|
57
57
|
const now = params.now ?? /* @__PURE__ */ new Date();
|
|
58
58
|
const leaseMs = params.leaseMs ?? (0, import_settings.leaseMs)();
|
|
59
|
-
const due = await this.
|
|
59
|
+
const due = await this.automationRepository.findDue(now, params.limit ?? DEFAULT_LIMIT);
|
|
60
60
|
const claimed = [];
|
|
61
61
|
const skipped = [];
|
|
62
62
|
for (const candidate of due) {
|
|
63
63
|
const id = String(candidate._id);
|
|
64
64
|
const scheduledFor = candidate.nextRunAt ? new Date(candidate.nextRunAt) : void 0;
|
|
65
|
+
const trigger = candidate.trigger;
|
|
66
|
+
if (trigger?.type !== "schedule") continue;
|
|
65
67
|
let nextRunAt = null;
|
|
66
68
|
try {
|
|
67
|
-
nextRunAt = (0, import_next_run.computeNextRun)(
|
|
69
|
+
nextRunAt = (0, import_next_run.computeNextRun)(trigger.recurrence, trigger.timezone, now);
|
|
68
70
|
} catch (error) {
|
|
69
|
-
this.log.error({ error: error?.message ?? error,
|
|
71
|
+
this.log.error({ error: error?.message ?? error, automationId: id }, "[AUTOMATIONS] The recurrence of an automation cannot be calculated, skipping it");
|
|
70
72
|
continue;
|
|
71
73
|
}
|
|
72
|
-
const
|
|
73
|
-
if (!
|
|
74
|
-
const pending = await this.
|
|
74
|
+
const automation = await this.automationRepository.claim({ id, workerId, now, leaseMs, nextRunAt: nextRunAt ?? void 0 });
|
|
75
|
+
if (!automation) continue;
|
|
76
|
+
const pending = await (0, import_previous_run.findPausedRun)(this.automationRunRepository, this.syncRun, automation, now);
|
|
75
77
|
if (pending) {
|
|
76
|
-
const run2 = await (0, import_open_run.openRun)(this.
|
|
77
|
-
await this.
|
|
78
|
-
skipped.push({
|
|
78
|
+
const run2 = await (0, import_open_run.openRun)(this.automationRunRepository, { automation, trigger: "schedule", status: "skipped", workerId, now, scheduledFor, skipReason: "The previous run is still waiting for the user" });
|
|
79
|
+
await this.automationRepository.release(id, workerId, { activeRunId: pending._id });
|
|
80
|
+
skipped.push({ automation, run: run2.toJSON() });
|
|
79
81
|
continue;
|
|
80
82
|
}
|
|
81
|
-
const run = await (0, import_open_run.openRun)(this.
|
|
82
|
-
await this.
|
|
83
|
-
claimed.push({
|
|
83
|
+
const run = await (0, import_open_run.openRun)(this.automationRunRepository, { automation, trigger: "schedule", status: "running", workerId, now, scheduledFor });
|
|
84
|
+
await this.automationRepository.setActiveRun(id, workerId, String(run._id));
|
|
85
|
+
claimed.push({ automation, run: run.toJSON() });
|
|
84
86
|
}
|
|
85
87
|
return { data: { claimed, skipped } };
|
|
86
88
|
}
|
|
87
|
-
async previousRun(job, now) {
|
|
88
|
-
if (!job.activeRunId) return null;
|
|
89
|
-
const previous = await this.agenticJobRunRepository.findById(String(job.activeRunId));
|
|
90
|
-
if (!previous) return null;
|
|
91
|
-
if (previous.status === "running") {
|
|
92
|
-
const lost = import_entities.AgenticJobRun.fromJSON({ ...previous, status: "failed", finishedAt: now, error: { code: "WORKER_LOST", message: import_sync_agentic_job_run.LOST_WORKER_MESSAGE } });
|
|
93
|
-
await this.agenticJobRunRepository.update(lost);
|
|
94
|
-
return null;
|
|
95
|
-
}
|
|
96
|
-
if (previous.status !== "paused") return null;
|
|
97
|
-
const { data } = await this.syncRun.execute({ runId: String(previous._id), now });
|
|
98
|
-
return data?.status === "paused" ? data : null;
|
|
99
|
-
}
|
|
100
89
|
};
|
|
101
|
-
|
|
90
|
+
ClaimDueAutomationsUseCase = __decorateClass([
|
|
102
91
|
(0, import_tsyringe.autoInjectable)(),
|
|
103
|
-
__decorateParam(0, (0, import_tsyringe.inject)(import_repositories.
|
|
104
|
-
__decorateParam(1, (0, import_tsyringe.inject)(import_repositories.
|
|
105
|
-
__decorateParam(2, (0, import_tsyringe.inject)(
|
|
106
|
-
],
|
|
92
|
+
__decorateParam(0, (0, import_tsyringe.inject)(import_repositories.AutomationRepository)),
|
|
93
|
+
__decorateParam(1, (0, import_tsyringe.inject)(import_repositories.AutomationRunRepository)),
|
|
94
|
+
__decorateParam(2, (0, import_tsyringe.inject)(import_sync_automation_run.SyncAutomationRunUseCase))
|
|
95
|
+
], ClaimDueAutomationsUseCase);
|
|
107
96
|
// Annotate the CommonJS export names for ESM import in node:
|
|
108
97
|
0 && (module.exports = {
|
|
109
|
-
|
|
98
|
+
ClaimDueAutomationsUseCase
|
|
110
99
|
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__decorateClass,
|
|
3
|
+
__decorateParam
|
|
4
|
+
} from "../../../chunk-CF3WOMB3.mjs";
|
|
5
|
+
import { autoInjectable, inject } from "tsyringe";
|
|
6
|
+
import { Logger } from "../../../common/logger/index.js";
|
|
7
|
+
import { BaseUseCase } from "../../../common/base/base.use-case.js";
|
|
8
|
+
import { AutomationRepository, AutomationRunRepository } from "../repositories";
|
|
9
|
+
import { computeNextRun } from "../utils/next-run";
|
|
10
|
+
import { openRun } from "../utils/open-run";
|
|
11
|
+
import { leaseMs as defaultLeaseMs } from "../utils/settings";
|
|
12
|
+
import { findPausedRun } from "../utils/previous-run";
|
|
13
|
+
import { SyncAutomationRunUseCase } from "./sync-automation-run.use-case";
|
|
14
|
+
const DEFAULT_LIMIT = 10;
|
|
15
|
+
let ClaimDueAutomationsUseCase = class extends BaseUseCase {
|
|
16
|
+
constructor(automationRepository, automationRunRepository, syncRun) {
|
|
17
|
+
super();
|
|
18
|
+
this.automationRepository = automationRepository;
|
|
19
|
+
this.automationRunRepository = automationRunRepository;
|
|
20
|
+
this.syncRun = syncRun;
|
|
21
|
+
}
|
|
22
|
+
automationRepository;
|
|
23
|
+
automationRunRepository;
|
|
24
|
+
syncRun;
|
|
25
|
+
log = new Logger();
|
|
26
|
+
async execute(params) {
|
|
27
|
+
const { workerId } = params;
|
|
28
|
+
if (!workerId) throw new Error("The id of the worker is required");
|
|
29
|
+
const now = params.now ?? /* @__PURE__ */ new Date();
|
|
30
|
+
const leaseMs = params.leaseMs ?? defaultLeaseMs();
|
|
31
|
+
const due = await this.automationRepository.findDue(now, params.limit ?? DEFAULT_LIMIT);
|
|
32
|
+
const claimed = [];
|
|
33
|
+
const skipped = [];
|
|
34
|
+
for (const candidate of due) {
|
|
35
|
+
const id = String(candidate._id);
|
|
36
|
+
const scheduledFor = candidate.nextRunAt ? new Date(candidate.nextRunAt) : void 0;
|
|
37
|
+
const trigger = candidate.trigger;
|
|
38
|
+
if (trigger?.type !== "schedule") continue;
|
|
39
|
+
let nextRunAt = null;
|
|
40
|
+
try {
|
|
41
|
+
nextRunAt = computeNextRun(trigger.recurrence, trigger.timezone, now);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
this.log.error({ error: error?.message ?? error, automationId: id }, "[AUTOMATIONS] The recurrence of an automation cannot be calculated, skipping it");
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const automation = await this.automationRepository.claim({ id, workerId, now, leaseMs, nextRunAt: nextRunAt ?? void 0 });
|
|
47
|
+
if (!automation) continue;
|
|
48
|
+
const pending = await findPausedRun(this.automationRunRepository, this.syncRun, automation, now);
|
|
49
|
+
if (pending) {
|
|
50
|
+
const run2 = await openRun(this.automationRunRepository, { automation, trigger: "schedule", status: "skipped", workerId, now, scheduledFor, skipReason: "The previous run is still waiting for the user" });
|
|
51
|
+
await this.automationRepository.release(id, workerId, { activeRunId: pending._id });
|
|
52
|
+
skipped.push({ automation, run: run2.toJSON() });
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const run = await openRun(this.automationRunRepository, { automation, trigger: "schedule", status: "running", workerId, now, scheduledFor });
|
|
56
|
+
await this.automationRepository.setActiveRun(id, workerId, String(run._id));
|
|
57
|
+
claimed.push({ automation, run: run.toJSON() });
|
|
58
|
+
}
|
|
59
|
+
return { data: { claimed, skipped } };
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
ClaimDueAutomationsUseCase = __decorateClass([
|
|
63
|
+
autoInjectable(),
|
|
64
|
+
__decorateParam(0, inject(AutomationRepository)),
|
|
65
|
+
__decorateParam(1, inject(AutomationRunRepository)),
|
|
66
|
+
__decorateParam(2, inject(SyncAutomationRunUseCase))
|
|
67
|
+
], ClaimDueAutomationsUseCase);
|
|
68
|
+
export {
|
|
69
|
+
ClaimDueAutomationsUseCase
|
|
70
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { BaseUseCase, BaseUseCaseParams, BaseUseCaseOutput } from '../../../common/base/base.use-case.js';
|
|
2
|
+
import { AutomationProps, AutomationRunProps } from '../entities';
|
|
3
|
+
import { AutomationRepository, AutomationRunRepository } from '../repositories';
|
|
4
|
+
import { SyncAutomationRunUseCase } from './sync-automation-run.use-case';
|
|
5
|
+
export interface Params extends BaseUseCaseParams {
|
|
6
|
+
workerId: string;
|
|
7
|
+
limit?: number;
|
|
8
|
+
leaseMs?: number;
|
|
9
|
+
now?: Date;
|
|
10
|
+
}
|
|
11
|
+
export interface ClaimedRun {
|
|
12
|
+
automation: AutomationProps;
|
|
13
|
+
run: AutomationRunProps;
|
|
14
|
+
}
|
|
15
|
+
export interface Output extends BaseUseCaseOutput {
|
|
16
|
+
data: {
|
|
17
|
+
claimed: ClaimedRun[];
|
|
18
|
+
skipped: ClaimedRun[];
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export declare class ClaimQueuedAutomationRunsUseCase extends BaseUseCase<Params, Output> {
|
|
22
|
+
private readonly automationRepository?;
|
|
23
|
+
private readonly automationRunRepository?;
|
|
24
|
+
private readonly syncRun?;
|
|
25
|
+
constructor(automationRepository?: AutomationRepository | undefined, automationRunRepository?: AutomationRunRepository | undefined, syncRun?: SyncAutomationRunUseCase | undefined);
|
|
26
|
+
execute(params: Params): Promise<Output>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
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 __decorateClass = (decorators, target, key, kind) => {
|
|
20
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
21
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
22
|
+
if (decorator = decorators[i])
|
|
23
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
24
|
+
if (kind && result) __defProp(target, key, result);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
28
|
+
var claim_queued_automation_runs_use_case_exports = {};
|
|
29
|
+
__export(claim_queued_automation_runs_use_case_exports, {
|
|
30
|
+
ClaimQueuedAutomationRunsUseCase: () => ClaimQueuedAutomationRunsUseCase
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(claim_queued_automation_runs_use_case_exports);
|
|
33
|
+
var import_tsyringe = require("tsyringe");
|
|
34
|
+
var import_base = require("../../../common/base/base.use-case.js");
|
|
35
|
+
var import_entities = require("../entities");
|
|
36
|
+
var import_repositories = require("../repositories");
|
|
37
|
+
var import_previous_run = require("../utils/previous-run");
|
|
38
|
+
var import_settings = require("../utils/settings");
|
|
39
|
+
var import_sync_automation_run = require("./sync-automation-run.use-case");
|
|
40
|
+
const SCAN_LIMIT = 200;
|
|
41
|
+
let ClaimQueuedAutomationRunsUseCase = class extends import_base.BaseUseCase {
|
|
42
|
+
constructor(automationRepository, automationRunRepository, syncRun) {
|
|
43
|
+
super();
|
|
44
|
+
this.automationRepository = automationRepository;
|
|
45
|
+
this.automationRunRepository = automationRunRepository;
|
|
46
|
+
this.syncRun = syncRun;
|
|
47
|
+
}
|
|
48
|
+
automationRepository;
|
|
49
|
+
automationRunRepository;
|
|
50
|
+
syncRun;
|
|
51
|
+
async execute(params) {
|
|
52
|
+
const { workerId } = params;
|
|
53
|
+
if (!workerId) throw new Error("The id of the worker is required");
|
|
54
|
+
const now = params.now ?? /* @__PURE__ */ new Date();
|
|
55
|
+
const leaseMs = params.leaseMs ?? (0, import_settings.leaseMs)();
|
|
56
|
+
const limit = params.limit ?? SCAN_LIMIT;
|
|
57
|
+
const queued = await this.automationRunRepository.findByStatus("queued", SCAN_LIMIT);
|
|
58
|
+
const claimed = [];
|
|
59
|
+
const skipped = [];
|
|
60
|
+
const seen = /* @__PURE__ */ new Set();
|
|
61
|
+
for (const run of queued) {
|
|
62
|
+
if (claimed.length >= limit) break;
|
|
63
|
+
const automationId = String(run.automationId);
|
|
64
|
+
if (seen.has(automationId)) continue;
|
|
65
|
+
seen.add(automationId);
|
|
66
|
+
const existing = await this.automationRepository.findById(automationId);
|
|
67
|
+
const reason = !existing ? "The automation no longer exists" : !existing.enabled ? "The automation is turned off" : void 0;
|
|
68
|
+
if (reason) {
|
|
69
|
+
const settled = await this.automationRunRepository.update(import_entities.AutomationRun.fromJSON({ ...run, status: "skipped", finishedAt: now, skipReason: reason }));
|
|
70
|
+
if (existing && settled) skipped.push({ automation: existing, run: settled });
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const automation = await this.automationRepository.claimManual({ id: automationId, workerId, now, leaseMs });
|
|
74
|
+
if (!automation) continue;
|
|
75
|
+
const paused = await (0, import_previous_run.findPausedRun)(this.automationRunRepository, this.syncRun, automation, now);
|
|
76
|
+
if (paused) {
|
|
77
|
+
await this.automationRepository.release(automationId, workerId, { activeRunId: paused._id });
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const started = await this.automationRunRepository.claimQueued(String(run._id), {
|
|
81
|
+
workerId,
|
|
82
|
+
startedAt: now,
|
|
83
|
+
instructions: automation.instructions,
|
|
84
|
+
modelProvider: automation.modelProvider,
|
|
85
|
+
modelName: automation.modelName
|
|
86
|
+
});
|
|
87
|
+
if (!started) {
|
|
88
|
+
await this.automationRepository.release(automationId, workerId, {});
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
await this.automationRepository.setActiveRun(automationId, workerId, String(started._id));
|
|
92
|
+
claimed.push({ automation, run: started });
|
|
93
|
+
}
|
|
94
|
+
return { data: { claimed, skipped } };
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
ClaimQueuedAutomationRunsUseCase = __decorateClass([
|
|
98
|
+
(0, import_tsyringe.autoInjectable)(),
|
|
99
|
+
__decorateParam(0, (0, import_tsyringe.inject)(import_repositories.AutomationRepository)),
|
|
100
|
+
__decorateParam(1, (0, import_tsyringe.inject)(import_repositories.AutomationRunRepository)),
|
|
101
|
+
__decorateParam(2, (0, import_tsyringe.inject)(import_sync_automation_run.SyncAutomationRunUseCase))
|
|
102
|
+
], ClaimQueuedAutomationRunsUseCase);
|
|
103
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
104
|
+
0 && (module.exports = {
|
|
105
|
+
ClaimQueuedAutomationRunsUseCase
|
|
106
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__decorateClass,
|
|
3
|
+
__decorateParam
|
|
4
|
+
} from "../../../chunk-CF3WOMB3.mjs";
|
|
5
|
+
import { autoInjectable, inject } from "tsyringe";
|
|
6
|
+
import { BaseUseCase } from "../../../common/base/base.use-case.js";
|
|
7
|
+
import { AutomationRun } from "../entities";
|
|
8
|
+
import { AutomationRepository, AutomationRunRepository } from "../repositories";
|
|
9
|
+
import { findPausedRun } from "../utils/previous-run";
|
|
10
|
+
import { leaseMs as defaultLeaseMs } from "../utils/settings";
|
|
11
|
+
import { SyncAutomationRunUseCase } from "./sync-automation-run.use-case";
|
|
12
|
+
const SCAN_LIMIT = 200;
|
|
13
|
+
let ClaimQueuedAutomationRunsUseCase = class extends BaseUseCase {
|
|
14
|
+
constructor(automationRepository, automationRunRepository, syncRun) {
|
|
15
|
+
super();
|
|
16
|
+
this.automationRepository = automationRepository;
|
|
17
|
+
this.automationRunRepository = automationRunRepository;
|
|
18
|
+
this.syncRun = syncRun;
|
|
19
|
+
}
|
|
20
|
+
automationRepository;
|
|
21
|
+
automationRunRepository;
|
|
22
|
+
syncRun;
|
|
23
|
+
async execute(params) {
|
|
24
|
+
const { workerId } = params;
|
|
25
|
+
if (!workerId) throw new Error("The id of the worker is required");
|
|
26
|
+
const now = params.now ?? /* @__PURE__ */ new Date();
|
|
27
|
+
const leaseMs = params.leaseMs ?? defaultLeaseMs();
|
|
28
|
+
const limit = params.limit ?? SCAN_LIMIT;
|
|
29
|
+
const queued = await this.automationRunRepository.findByStatus("queued", SCAN_LIMIT);
|
|
30
|
+
const claimed = [];
|
|
31
|
+
const skipped = [];
|
|
32
|
+
const seen = /* @__PURE__ */ new Set();
|
|
33
|
+
for (const run of queued) {
|
|
34
|
+
if (claimed.length >= limit) break;
|
|
35
|
+
const automationId = String(run.automationId);
|
|
36
|
+
if (seen.has(automationId)) continue;
|
|
37
|
+
seen.add(automationId);
|
|
38
|
+
const existing = await this.automationRepository.findById(automationId);
|
|
39
|
+
const reason = !existing ? "The automation no longer exists" : !existing.enabled ? "The automation is turned off" : void 0;
|
|
40
|
+
if (reason) {
|
|
41
|
+
const settled = await this.automationRunRepository.update(AutomationRun.fromJSON({ ...run, status: "skipped", finishedAt: now, skipReason: reason }));
|
|
42
|
+
if (existing && settled) skipped.push({ automation: existing, run: settled });
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const automation = await this.automationRepository.claimManual({ id: automationId, workerId, now, leaseMs });
|
|
46
|
+
if (!automation) continue;
|
|
47
|
+
const paused = await findPausedRun(this.automationRunRepository, this.syncRun, automation, now);
|
|
48
|
+
if (paused) {
|
|
49
|
+
await this.automationRepository.release(automationId, workerId, { activeRunId: paused._id });
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const started = await this.automationRunRepository.claimQueued(String(run._id), {
|
|
53
|
+
workerId,
|
|
54
|
+
startedAt: now,
|
|
55
|
+
instructions: automation.instructions,
|
|
56
|
+
modelProvider: automation.modelProvider,
|
|
57
|
+
modelName: automation.modelName
|
|
58
|
+
});
|
|
59
|
+
if (!started) {
|
|
60
|
+
await this.automationRepository.release(automationId, workerId, {});
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
await this.automationRepository.setActiveRun(automationId, workerId, String(started._id));
|
|
64
|
+
claimed.push({ automation, run: started });
|
|
65
|
+
}
|
|
66
|
+
return { data: { claimed, skipped } };
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
ClaimQueuedAutomationRunsUseCase = __decorateClass([
|
|
70
|
+
autoInjectable(),
|
|
71
|
+
__decorateParam(0, inject(AutomationRepository)),
|
|
72
|
+
__decorateParam(1, inject(AutomationRunRepository)),
|
|
73
|
+
__decorateParam(2, inject(SyncAutomationRunUseCase))
|
|
74
|
+
], ClaimQueuedAutomationRunsUseCase);
|
|
75
|
+
export {
|
|
76
|
+
ClaimQueuedAutomationRunsUseCase
|
|
77
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseUseCase, BaseUseCaseParams, BaseUseCaseOutput } from '../../../common/base/base.use-case.js';
|
|
2
|
+
import { AutomationProps } from '../entities';
|
|
3
|
+
import { AutomationRepository } from '../repositories';
|
|
4
|
+
export interface Params extends BaseUseCaseParams {
|
|
5
|
+
payload?: AutomationProps;
|
|
6
|
+
}
|
|
7
|
+
export interface Output extends BaseUseCaseOutput {
|
|
8
|
+
data: AutomationProps;
|
|
9
|
+
}
|
|
10
|
+
export declare class CreateAutomationUseCase extends BaseUseCase<Params, Output> {
|
|
11
|
+
private readonly automationRepository?;
|
|
12
|
+
constructor(automationRepository?: AutomationRepository | undefined);
|
|
13
|
+
execute(params: Params): Promise<Output>;
|
|
14
|
+
}
|
|
@@ -25,49 +25,48 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
25
25
|
return result;
|
|
26
26
|
};
|
|
27
27
|
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
28
|
-
var
|
|
29
|
-
__export(
|
|
30
|
-
|
|
28
|
+
var create_automation_use_case_exports = {};
|
|
29
|
+
__export(create_automation_use_case_exports, {
|
|
30
|
+
CreateAutomationUseCase: () => CreateAutomationUseCase
|
|
31
31
|
});
|
|
32
|
-
module.exports = __toCommonJS(
|
|
32
|
+
module.exports = __toCommonJS(create_automation_use_case_exports);
|
|
33
33
|
var import_tsyringe = require("tsyringe");
|
|
34
34
|
var import_base = require("../../../common/base/base.use-case.js");
|
|
35
35
|
var import_entities = require("../entities");
|
|
36
36
|
var import_repositories = require("../repositories");
|
|
37
|
-
var
|
|
38
|
-
let
|
|
39
|
-
constructor(
|
|
37
|
+
var import_automation_fields = require("../utils/automation-fields");
|
|
38
|
+
let CreateAutomationUseCase = class extends import_base.BaseUseCase {
|
|
39
|
+
constructor(automationRepository) {
|
|
40
40
|
super();
|
|
41
|
-
this.
|
|
41
|
+
this.automationRepository = automationRepository;
|
|
42
42
|
}
|
|
43
|
-
|
|
43
|
+
automationRepository;
|
|
44
44
|
async execute(params) {
|
|
45
45
|
const { payload, currentUser } = params;
|
|
46
|
-
if (!currentUser?.userId) throw new Error("CurrentUser is required to create an
|
|
47
|
-
const fields = (0,
|
|
48
|
-
(0,
|
|
49
|
-
const
|
|
46
|
+
if (!currentUser?.userId) throw new Error("CurrentUser is required to create an automation");
|
|
47
|
+
const fields = (0, import_automation_fields.readAutomationFields)(payload, { complete: true });
|
|
48
|
+
(0, import_automation_fields.assertModel)(fields.modelProvider, fields.modelName);
|
|
49
|
+
const automation = import_entities.Automation.fromJSON({
|
|
50
50
|
name: fields.name,
|
|
51
51
|
instructions: fields.instructions,
|
|
52
|
-
|
|
53
|
-
timezone: fields.timezone,
|
|
52
|
+
trigger: fields.trigger,
|
|
54
53
|
enabled: fields.enabled ?? true,
|
|
55
54
|
modelProvider: fields.modelProvider ?? void 0,
|
|
56
55
|
modelName: fields.modelName ?? void 0
|
|
57
56
|
});
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (
|
|
62
|
-
await this.
|
|
63
|
-
return { data:
|
|
57
|
+
automation.setCreatedBy(currentUser);
|
|
58
|
+
automation.setOwner(currentUser);
|
|
59
|
+
automation.scheduleNextRun();
|
|
60
|
+
if (automation.enabled && automation.isScheduled() && !automation.nextRunAt) throw new Error("The date of the recurrence has already passed");
|
|
61
|
+
await this.automationRepository?.create(automation);
|
|
62
|
+
return { data: automation.toJSON() };
|
|
64
63
|
}
|
|
65
64
|
};
|
|
66
|
-
|
|
65
|
+
CreateAutomationUseCase = __decorateClass([
|
|
67
66
|
(0, import_tsyringe.autoInjectable)(),
|
|
68
|
-
__decorateParam(0, (0, import_tsyringe.inject)(import_repositories.
|
|
69
|
-
],
|
|
67
|
+
__decorateParam(0, (0, import_tsyringe.inject)(import_repositories.AutomationRepository))
|
|
68
|
+
], CreateAutomationUseCase);
|
|
70
69
|
// Annotate the CommonJS export names for ESM import in node:
|
|
71
70
|
0 && (module.exports = {
|
|
72
|
-
|
|
71
|
+
CreateAutomationUseCase
|
|
73
72
|
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__decorateClass,
|
|
3
|
+
__decorateParam
|
|
4
|
+
} from "../../../chunk-CF3WOMB3.mjs";
|
|
5
|
+
import { autoInjectable, inject } from "tsyringe";
|
|
6
|
+
import { BaseUseCase } from "../../../common/base/base.use-case.js";
|
|
7
|
+
import { Automation } from "../entities";
|
|
8
|
+
import { AutomationRepository } from "../repositories";
|
|
9
|
+
import { readAutomationFields, assertModel } from "../utils/automation-fields";
|
|
10
|
+
let CreateAutomationUseCase = class extends BaseUseCase {
|
|
11
|
+
constructor(automationRepository) {
|
|
12
|
+
super();
|
|
13
|
+
this.automationRepository = automationRepository;
|
|
14
|
+
}
|
|
15
|
+
automationRepository;
|
|
16
|
+
async execute(params) {
|
|
17
|
+
const { payload, currentUser } = params;
|
|
18
|
+
if (!currentUser?.userId) throw new Error("CurrentUser is required to create an automation");
|
|
19
|
+
const fields = readAutomationFields(payload, { complete: true });
|
|
20
|
+
assertModel(fields.modelProvider, fields.modelName);
|
|
21
|
+
const automation = Automation.fromJSON({
|
|
22
|
+
name: fields.name,
|
|
23
|
+
instructions: fields.instructions,
|
|
24
|
+
trigger: fields.trigger,
|
|
25
|
+
enabled: fields.enabled ?? true,
|
|
26
|
+
modelProvider: fields.modelProvider ?? void 0,
|
|
27
|
+
modelName: fields.modelName ?? void 0
|
|
28
|
+
});
|
|
29
|
+
automation.setCreatedBy(currentUser);
|
|
30
|
+
automation.setOwner(currentUser);
|
|
31
|
+
automation.scheduleNextRun();
|
|
32
|
+
if (automation.enabled && automation.isScheduled() && !automation.nextRunAt) throw new Error("The date of the recurrence has already passed");
|
|
33
|
+
await this.automationRepository?.create(automation);
|
|
34
|
+
return { data: automation.toJSON() };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
CreateAutomationUseCase = __decorateClass([
|
|
38
|
+
autoInjectable(),
|
|
39
|
+
__decorateParam(0, inject(AutomationRepository))
|
|
40
|
+
], CreateAutomationUseCase);
|
|
41
|
+
export {
|
|
42
|
+
CreateAutomationUseCase
|
|
43
|
+
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { BaseUseCase, BaseUseCaseParams, BaseUseCaseOutput } from '../../../common/base/base.use-case.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { AutomationProps } from '../entities';
|
|
3
|
+
import { AutomationRepository } from '../repositories';
|
|
4
4
|
export interface Params extends BaseUseCaseParams {
|
|
5
5
|
id: string;
|
|
6
6
|
hardDelete?: boolean;
|
|
7
7
|
}
|
|
8
8
|
export interface Output extends BaseUseCaseOutput {
|
|
9
|
-
data:
|
|
9
|
+
data: AutomationProps | null | undefined;
|
|
10
10
|
}
|
|
11
|
-
export declare class
|
|
12
|
-
private readonly
|
|
13
|
-
constructor(
|
|
11
|
+
export declare class DeleteAutomationUseCase extends BaseUseCase<Params, Output> {
|
|
12
|
+
private readonly automationRepository?;
|
|
13
|
+
constructor(automationRepository?: AutomationRepository | undefined);
|
|
14
14
|
execute(params: Params): Promise<Output>;
|
|
15
15
|
}
|
|
@@ -25,41 +25,41 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
25
25
|
return result;
|
|
26
26
|
};
|
|
27
27
|
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
28
|
-
var
|
|
29
|
-
__export(
|
|
30
|
-
|
|
28
|
+
var delete_automation_use_case_exports = {};
|
|
29
|
+
__export(delete_automation_use_case_exports, {
|
|
30
|
+
DeleteAutomationUseCase: () => DeleteAutomationUseCase
|
|
31
31
|
});
|
|
32
|
-
module.exports = __toCommonJS(
|
|
32
|
+
module.exports = __toCommonJS(delete_automation_use_case_exports);
|
|
33
33
|
var import_tsyringe = require("tsyringe");
|
|
34
34
|
var import_base = require("../../../common/base/base.use-case.js");
|
|
35
35
|
var import_entities = require("../entities");
|
|
36
36
|
var import_repositories = require("../repositories");
|
|
37
|
-
let
|
|
38
|
-
constructor(
|
|
37
|
+
let DeleteAutomationUseCase = class extends import_base.BaseUseCase {
|
|
38
|
+
constructor(automationRepository) {
|
|
39
39
|
super();
|
|
40
|
-
this.
|
|
40
|
+
this.automationRepository = automationRepository;
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
automationRepository;
|
|
43
43
|
async execute(params) {
|
|
44
44
|
const { id, hardDelete, currentUser } = params;
|
|
45
45
|
if (!id) throw new Error("Missing id");
|
|
46
46
|
if (hardDelete) {
|
|
47
47
|
if (!currentUser?.isAdmin()) this.throwError403();
|
|
48
|
-
const result2 = await this.
|
|
48
|
+
const result2 = await this.automationRepository?.deleteById(id);
|
|
49
49
|
return { data: { deletedCount: result2 } };
|
|
50
50
|
}
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const result = await this.
|
|
51
|
+
const automation = import_entities.Automation.fromJSON({ _id: id });
|
|
52
|
+
automation.setDeletedBy(currentUser);
|
|
53
|
+
automation.unset(["nextRunAt"]);
|
|
54
|
+
const result = await this.automationRepository?.update(automation);
|
|
55
55
|
return { data: result };
|
|
56
56
|
}
|
|
57
57
|
};
|
|
58
|
-
|
|
58
|
+
DeleteAutomationUseCase = __decorateClass([
|
|
59
59
|
(0, import_tsyringe.autoInjectable)(),
|
|
60
|
-
__decorateParam(0, (0, import_tsyringe.inject)(import_repositories.
|
|
61
|
-
],
|
|
60
|
+
__decorateParam(0, (0, import_tsyringe.inject)(import_repositories.AutomationRepository))
|
|
61
|
+
], DeleteAutomationUseCase);
|
|
62
62
|
// Annotate the CommonJS export names for ESM import in node:
|
|
63
63
|
0 && (module.exports = {
|
|
64
|
-
|
|
64
|
+
DeleteAutomationUseCase
|
|
65
65
|
});
|