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
|
@@ -16,12 +16,12 @@ 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
|
-
|
|
22
|
-
|
|
19
|
+
var automation_runner_exports = {};
|
|
20
|
+
__export(automation_runner_exports, {
|
|
21
|
+
AutomationRunner: () => AutomationRunner,
|
|
22
|
+
createAutomationRunner: () => createAutomationRunner
|
|
23
23
|
});
|
|
24
|
-
module.exports = __toCommonJS(
|
|
24
|
+
module.exports = __toCommonJS(automation_runner_exports);
|
|
25
25
|
var import_node_crypto = require("node:crypto");
|
|
26
26
|
var import_node_os = require("node:os");
|
|
27
27
|
var import_logger = require("../../../common/logger/index.js");
|
|
@@ -31,19 +31,21 @@ var import_agent = require("../../../harness/agent.js");
|
|
|
31
31
|
var import_loop = require("../../../loops/agi/loop.js");
|
|
32
32
|
var import_chats = require("../../chats/index.js");
|
|
33
33
|
var import_chat = require("../../chats/entities/chat.entity.js");
|
|
34
|
+
var import_event_message = require("../utils/event-message");
|
|
34
35
|
var import_settings = require("../utils/settings");
|
|
35
|
-
var
|
|
36
|
-
var
|
|
37
|
-
var
|
|
38
|
-
var
|
|
39
|
-
var
|
|
40
|
-
var
|
|
36
|
+
var import_claim_due_automations = require("../use-cases/claim-due-automations.use-case");
|
|
37
|
+
var import_claim_queued_automation_runs = require("../use-cases/claim-queued-automation-runs.use-case");
|
|
38
|
+
var import_start_automation_run = require("../use-cases/start-automation-run.use-case");
|
|
39
|
+
var import_finish_automation_run = require("../use-cases/finish-automation-run.use-case");
|
|
40
|
+
var import_attach_automation_run_chat = require("../use-cases/attach-automation-run-chat.use-case");
|
|
41
|
+
var import_renew_automation_lease = require("../use-cases/renew-automation-lease.use-case");
|
|
42
|
+
var import_sync_automation_runs = require("../use-cases/sync-automation-runs.use-case");
|
|
41
43
|
var import_tsyringe = require("tsyringe");
|
|
42
44
|
const DEFAULT_MAX_CONCURRENT_RUNS = 3;
|
|
43
45
|
const DEFAULT_STOP_TIMEOUT_MS = 3e4;
|
|
44
46
|
const PAUSED_STATUSES = ["awaiting_user_confirmation", "awaiting_user_input"];
|
|
45
47
|
const newWorkerId = () => `${(0, import_node_os.hostname)()}-${process.pid}-${(0, import_node_crypto.randomBytes)(3).toString("hex")}`;
|
|
46
|
-
class
|
|
48
|
+
class AutomationRunner {
|
|
47
49
|
constructor(options = {}) {
|
|
48
50
|
this.options = options;
|
|
49
51
|
this.workerId = options.workerId ?? newWorkerId();
|
|
@@ -55,16 +57,19 @@ class AgenticJobRunner {
|
|
|
55
57
|
running = false;
|
|
56
58
|
timer;
|
|
57
59
|
ticking;
|
|
58
|
-
|
|
60
|
+
resolveSleep;
|
|
59
61
|
start() {
|
|
60
62
|
if (this.running) return;
|
|
61
63
|
this.running = true;
|
|
62
64
|
void this.loop();
|
|
63
65
|
}
|
|
66
|
+
wake() {
|
|
67
|
+
this.resolveSleep?.();
|
|
68
|
+
}
|
|
64
69
|
async stop() {
|
|
65
70
|
this.running = false;
|
|
66
71
|
if (this.timer) clearTimeout(this.timer);
|
|
67
|
-
this.
|
|
72
|
+
this.resolveSleep?.();
|
|
68
73
|
await this.ticking;
|
|
69
74
|
const pending = Promise.allSettled([...this.inFlight]);
|
|
70
75
|
const timeoutMs = this.options.stopTimeoutMs ?? DEFAULT_STOP_TIMEOUT_MS;
|
|
@@ -77,82 +82,87 @@ class AgenticJobRunner {
|
|
|
77
82
|
async tick() {
|
|
78
83
|
const capacity = (this.options.maxConcurrentRuns ?? DEFAULT_MAX_CONCURRENT_RUNS) - this.inFlight.size;
|
|
79
84
|
try {
|
|
80
|
-
await import_tsyringe.container.resolve(
|
|
85
|
+
await import_tsyringe.container.resolve(import_sync_automation_runs.SyncAutomationRunsUseCase).execute({});
|
|
81
86
|
} catch (error) {
|
|
82
|
-
this.logger.error({ error: error?.message ?? error }, "[
|
|
87
|
+
this.logger.error({ error: error?.message ?? error }, "[AUTOMATIONS] Failed to sync the open runs");
|
|
83
88
|
}
|
|
84
89
|
if (capacity <= 0) return;
|
|
85
|
-
const { data } = await import_tsyringe.container.resolve(
|
|
86
|
-
for (const {
|
|
87
|
-
for (const {
|
|
90
|
+
const { data } = await import_tsyringe.container.resolve(import_claim_due_automations.ClaimDueAutomationsUseCase).execute({ workerId: this.workerId, limit: capacity, leaseMs: this.options.leaseMs ?? (0, import_settings.leaseMs)() });
|
|
91
|
+
for (const { automation, run } of data.skipped) await this.notify({ automation, run });
|
|
92
|
+
for (const { automation, run } of data.claimed) this.track(this.execute(automation, run));
|
|
93
|
+
const remaining = capacity - data.claimed.length;
|
|
94
|
+
if (remaining <= 0) return;
|
|
95
|
+
const { data: queued } = await import_tsyringe.container.resolve(import_claim_queued_automation_runs.ClaimQueuedAutomationRunsUseCase).execute({ workerId: this.workerId, limit: remaining, leaseMs: this.options.leaseMs ?? (0, import_settings.leaseMs)() });
|
|
96
|
+
for (const { automation, run } of queued.skipped) await this.notify({ automation, run });
|
|
97
|
+
for (const { automation, run } of queued.claimed) this.track(this.execute(automation, run));
|
|
88
98
|
}
|
|
89
99
|
async runNow(params) {
|
|
90
|
-
const { data } = await import_tsyringe.container.resolve(
|
|
91
|
-
this.track(this.execute(data.
|
|
100
|
+
const { data } = await import_tsyringe.container.resolve(import_start_automation_run.StartAutomationRunUseCase).execute({ automationId: params.automationId, workerId: this.workerId, leaseMs: this.options.leaseMs ?? (0, import_settings.leaseMs)() });
|
|
101
|
+
this.track(this.execute(data.automation, data.run));
|
|
92
102
|
return { run: data.run };
|
|
93
103
|
}
|
|
94
104
|
async loop() {
|
|
95
105
|
while (this.running) {
|
|
96
106
|
this.ticking = this.tick().catch((error) => {
|
|
97
|
-
this.logger.error({ error: error?.message ?? error }, "[
|
|
107
|
+
this.logger.error({ error: error?.message ?? error }, "[AUTOMATIONS] The worker failed to check the due automations");
|
|
98
108
|
});
|
|
99
109
|
await this.ticking;
|
|
100
110
|
if (!this.running) break;
|
|
101
111
|
await new Promise((resolve) => {
|
|
102
|
-
this.
|
|
112
|
+
this.resolveSleep = resolve;
|
|
103
113
|
this.timer = setTimeout(resolve, this.options.intervalMs ?? (0, import_settings.pollIntervalMs)());
|
|
104
114
|
});
|
|
105
115
|
}
|
|
106
116
|
}
|
|
107
117
|
track(execution) {
|
|
108
|
-
const tracked = execution.catch((error) => this.logger.error({ error: error?.message ?? error }, "[
|
|
118
|
+
const tracked = execution.catch((error) => this.logger.error({ error: error?.message ?? error }, "[AUTOMATIONS] A run could not be completed")).finally(() => this.inFlight.delete(tracked));
|
|
109
119
|
this.inFlight.add(tracked);
|
|
110
120
|
}
|
|
111
|
-
async execute(
|
|
121
|
+
async execute(automation, run) {
|
|
112
122
|
const leaseMs = this.options.leaseMs ?? (0, import_settings.leaseMs)();
|
|
113
|
-
const
|
|
123
|
+
const automationId = String(automation._id);
|
|
114
124
|
const runId = String(run._id);
|
|
115
125
|
const heartbeat = setInterval(() => {
|
|
116
|
-
import_tsyringe.container.resolve(
|
|
117
|
-
this.logger.error({ error: error2?.message ?? error2,
|
|
126
|
+
import_tsyringe.container.resolve(import_renew_automation_lease.RenewAutomationLeaseUseCase).execute({ automationId, workerId: this.workerId, leaseMs }).catch((error2) => {
|
|
127
|
+
this.logger.error({ error: error2?.message ?? error2, automationId }, "[AUTOMATIONS] Failed to renew the lease of an automation");
|
|
118
128
|
});
|
|
119
129
|
}, Math.max(Math.floor(leaseMs / 3), 1e3));
|
|
120
130
|
let status = "failed";
|
|
121
131
|
let error;
|
|
122
132
|
let chat;
|
|
123
133
|
try {
|
|
124
|
-
const outcome = await this.runAgent(
|
|
134
|
+
const outcome = await this.runAgent(automation, run);
|
|
125
135
|
status = outcome.status;
|
|
126
136
|
error = outcome.error;
|
|
127
137
|
chat = outcome.chat;
|
|
128
138
|
} catch (failure) {
|
|
129
139
|
error = { code: failure?.code ?? "RUNNER_ERROR", message: failure?.message ?? String(failure) };
|
|
130
|
-
this.logger.error({ error: error.message,
|
|
140
|
+
this.logger.error({ error: error.message, automationId, runId }, "[AUTOMATIONS] A run failed");
|
|
131
141
|
} finally {
|
|
132
142
|
clearInterval(heartbeat);
|
|
133
143
|
}
|
|
134
|
-
const { data } = await import_tsyringe.container.resolve(
|
|
135
|
-
await this.notify({
|
|
144
|
+
const { data } = await import_tsyringe.container.resolve(import_finish_automation_run.FinishAutomationRunUseCase).execute({ runId, workerId: this.workerId, status, error });
|
|
145
|
+
await this.notify({ automation, run: data ?? run, chat });
|
|
136
146
|
}
|
|
137
|
-
async runAgent(
|
|
138
|
-
const currentUser = await import_base.CurrentUser.asyncFromDB(String(
|
|
139
|
-
if (!currentUser) return { status: "failed", error: { code: "OWNER_NOT_FOUND", message: "The owner of the
|
|
140
|
-
const configured = typeof this.options.agent === "function" ? await this.options.agent({
|
|
147
|
+
async runAgent(automation, run) {
|
|
148
|
+
const currentUser = await import_base.CurrentUser.asyncFromDB(String(automation.ownerId));
|
|
149
|
+
if (!currentUser) return { status: "failed", error: { code: "OWNER_NOT_FOUND", message: "The owner of the automation does not exist" } };
|
|
150
|
+
const configured = typeof this.options.agent === "function" ? await this.options.agent({ automation, currentUser }) : this.options.agent ?? {};
|
|
141
151
|
const loop = configured.loop ?? new import_loop.AgiLoop();
|
|
142
152
|
const agent = new import_agent.Agent({ ...configured, loop });
|
|
143
|
-
const model =
|
|
153
|
+
const model = automation.modelProvider && automation.modelName ? { modelProvider: automation.modelProvider, modelName: automation.modelName } : {};
|
|
144
154
|
const draft = import_chat.Chat.withDefaults(loop.name);
|
|
145
155
|
draft.settings?.setExecutionMode("autonomous");
|
|
146
156
|
if (model.modelProvider) draft.settings?.setModelProvider(model.modelProvider);
|
|
147
157
|
if (model.modelName) draft.settings?.setModelName(model.modelName);
|
|
148
158
|
const { data: created } = await (0, import_chats.createChat)({ payload: draft.toJSON(), currentUser });
|
|
149
159
|
const chatId = String(created?._id);
|
|
150
|
-
await import_tsyringe.container.resolve(
|
|
160
|
+
await import_tsyringe.container.resolve(import_attach_automation_run_chat.AttachAutomationRunChatUseCase).execute({ runId: String(run._id), chatId });
|
|
151
161
|
const result = await agent.run({
|
|
152
|
-
input: { message:
|
|
162
|
+
input: { message: (0, import_event_message.buildMessage)(automation.instructions, run.payload), chatId },
|
|
153
163
|
options: { executionMode: "autonomous", ...model },
|
|
154
164
|
currentUser,
|
|
155
|
-
currentSession: import_base.CurrentSession.fromJSON({ location: { timezone:
|
|
165
|
+
currentSession: import_base.CurrentSession.fromJSON({ location: { timezone: automation.trigger?.timezone } }),
|
|
156
166
|
serviceToken: process.env.INTERNAL_MCP_TOKEN ? import_secret_manager.secretManager.get("INTERNAL_MCP_TOKEN") : void 0
|
|
157
167
|
});
|
|
158
168
|
const chat = result.data;
|
|
@@ -169,15 +179,15 @@ class AgenticJobRunner {
|
|
|
169
179
|
try {
|
|
170
180
|
await this.options.onRunFinished(event);
|
|
171
181
|
} catch (error) {
|
|
172
|
-
this.logger.error({ error: error?.message ?? error }, "[
|
|
182
|
+
this.logger.error({ error: error?.message ?? error }, "[AUTOMATIONS] The onRunFinished callback failed");
|
|
173
183
|
}
|
|
174
184
|
}
|
|
175
185
|
}
|
|
176
|
-
function
|
|
177
|
-
return new
|
|
186
|
+
function createAutomationRunner(options = {}) {
|
|
187
|
+
return new AutomationRunner(options);
|
|
178
188
|
}
|
|
179
189
|
// Annotate the CommonJS export names for ESM import in node:
|
|
180
190
|
0 && (module.exports = {
|
|
181
|
-
|
|
182
|
-
|
|
191
|
+
AutomationRunner,
|
|
192
|
+
createAutomationRunner
|
|
183
193
|
});
|
|
@@ -8,19 +8,21 @@ import { Agent } from "../../../harness/agent.js";
|
|
|
8
8
|
import { AgiLoop } from "../../../loops/agi/loop.js";
|
|
9
9
|
import { createChat } from "../../chats/index.js";
|
|
10
10
|
import { Chat } from "../../chats/entities/chat.entity.js";
|
|
11
|
+
import { buildMessage } from "../utils/event-message";
|
|
11
12
|
import { leaseMs as defaultLeaseMs, pollIntervalMs as defaultPollIntervalMs } from "../utils/settings";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
13
|
+
import { ClaimDueAutomationsUseCase } from "../use-cases/claim-due-automations.use-case";
|
|
14
|
+
import { ClaimQueuedAutomationRunsUseCase } from "../use-cases/claim-queued-automation-runs.use-case";
|
|
15
|
+
import { StartAutomationRunUseCase } from "../use-cases/start-automation-run.use-case";
|
|
16
|
+
import { FinishAutomationRunUseCase } from "../use-cases/finish-automation-run.use-case";
|
|
17
|
+
import { AttachAutomationRunChatUseCase } from "../use-cases/attach-automation-run-chat.use-case";
|
|
18
|
+
import { RenewAutomationLeaseUseCase } from "../use-cases/renew-automation-lease.use-case";
|
|
19
|
+
import { SyncAutomationRunsUseCase } from "../use-cases/sync-automation-runs.use-case";
|
|
18
20
|
import { container } from "tsyringe";
|
|
19
21
|
const DEFAULT_MAX_CONCURRENT_RUNS = 3;
|
|
20
22
|
const DEFAULT_STOP_TIMEOUT_MS = 3e4;
|
|
21
23
|
const PAUSED_STATUSES = ["awaiting_user_confirmation", "awaiting_user_input"];
|
|
22
24
|
const newWorkerId = () => `${hostname()}-${process.pid}-${randomBytes(3).toString("hex")}`;
|
|
23
|
-
class
|
|
25
|
+
class AutomationRunner {
|
|
24
26
|
constructor(options = {}) {
|
|
25
27
|
this.options = options;
|
|
26
28
|
this.workerId = options.workerId ?? newWorkerId();
|
|
@@ -32,16 +34,19 @@ class AgenticJobRunner {
|
|
|
32
34
|
running = false;
|
|
33
35
|
timer;
|
|
34
36
|
ticking;
|
|
35
|
-
|
|
37
|
+
resolveSleep;
|
|
36
38
|
start() {
|
|
37
39
|
if (this.running) return;
|
|
38
40
|
this.running = true;
|
|
39
41
|
void this.loop();
|
|
40
42
|
}
|
|
43
|
+
wake() {
|
|
44
|
+
this.resolveSleep?.();
|
|
45
|
+
}
|
|
41
46
|
async stop() {
|
|
42
47
|
this.running = false;
|
|
43
48
|
if (this.timer) clearTimeout(this.timer);
|
|
44
|
-
this.
|
|
49
|
+
this.resolveSleep?.();
|
|
45
50
|
await this.ticking;
|
|
46
51
|
const pending = Promise.allSettled([...this.inFlight]);
|
|
47
52
|
const timeoutMs = this.options.stopTimeoutMs ?? DEFAULT_STOP_TIMEOUT_MS;
|
|
@@ -54,82 +59,87 @@ class AgenticJobRunner {
|
|
|
54
59
|
async tick() {
|
|
55
60
|
const capacity = (this.options.maxConcurrentRuns ?? DEFAULT_MAX_CONCURRENT_RUNS) - this.inFlight.size;
|
|
56
61
|
try {
|
|
57
|
-
await container.resolve(
|
|
62
|
+
await container.resolve(SyncAutomationRunsUseCase).execute({});
|
|
58
63
|
} catch (error) {
|
|
59
|
-
this.logger.error({ error: error?.message ?? error }, "[
|
|
64
|
+
this.logger.error({ error: error?.message ?? error }, "[AUTOMATIONS] Failed to sync the open runs");
|
|
60
65
|
}
|
|
61
66
|
if (capacity <= 0) return;
|
|
62
|
-
const { data } = await container.resolve(
|
|
63
|
-
for (const {
|
|
64
|
-
for (const {
|
|
67
|
+
const { data } = await container.resolve(ClaimDueAutomationsUseCase).execute({ workerId: this.workerId, limit: capacity, leaseMs: this.options.leaseMs ?? defaultLeaseMs() });
|
|
68
|
+
for (const { automation, run } of data.skipped) await this.notify({ automation, run });
|
|
69
|
+
for (const { automation, run } of data.claimed) this.track(this.execute(automation, run));
|
|
70
|
+
const remaining = capacity - data.claimed.length;
|
|
71
|
+
if (remaining <= 0) return;
|
|
72
|
+
const { data: queued } = await container.resolve(ClaimQueuedAutomationRunsUseCase).execute({ workerId: this.workerId, limit: remaining, leaseMs: this.options.leaseMs ?? defaultLeaseMs() });
|
|
73
|
+
for (const { automation, run } of queued.skipped) await this.notify({ automation, run });
|
|
74
|
+
for (const { automation, run } of queued.claimed) this.track(this.execute(automation, run));
|
|
65
75
|
}
|
|
66
76
|
async runNow(params) {
|
|
67
|
-
const { data } = await container.resolve(
|
|
68
|
-
this.track(this.execute(data.
|
|
77
|
+
const { data } = await container.resolve(StartAutomationRunUseCase).execute({ automationId: params.automationId, workerId: this.workerId, leaseMs: this.options.leaseMs ?? defaultLeaseMs() });
|
|
78
|
+
this.track(this.execute(data.automation, data.run));
|
|
69
79
|
return { run: data.run };
|
|
70
80
|
}
|
|
71
81
|
async loop() {
|
|
72
82
|
while (this.running) {
|
|
73
83
|
this.ticking = this.tick().catch((error) => {
|
|
74
|
-
this.logger.error({ error: error?.message ?? error }, "[
|
|
84
|
+
this.logger.error({ error: error?.message ?? error }, "[AUTOMATIONS] The worker failed to check the due automations");
|
|
75
85
|
});
|
|
76
86
|
await this.ticking;
|
|
77
87
|
if (!this.running) break;
|
|
78
88
|
await new Promise((resolve) => {
|
|
79
|
-
this.
|
|
89
|
+
this.resolveSleep = resolve;
|
|
80
90
|
this.timer = setTimeout(resolve, this.options.intervalMs ?? defaultPollIntervalMs());
|
|
81
91
|
});
|
|
82
92
|
}
|
|
83
93
|
}
|
|
84
94
|
track(execution) {
|
|
85
|
-
const tracked = execution.catch((error) => this.logger.error({ error: error?.message ?? error }, "[
|
|
95
|
+
const tracked = execution.catch((error) => this.logger.error({ error: error?.message ?? error }, "[AUTOMATIONS] A run could not be completed")).finally(() => this.inFlight.delete(tracked));
|
|
86
96
|
this.inFlight.add(tracked);
|
|
87
97
|
}
|
|
88
|
-
async execute(
|
|
98
|
+
async execute(automation, run) {
|
|
89
99
|
const leaseMs = this.options.leaseMs ?? defaultLeaseMs();
|
|
90
|
-
const
|
|
100
|
+
const automationId = String(automation._id);
|
|
91
101
|
const runId = String(run._id);
|
|
92
102
|
const heartbeat = setInterval(() => {
|
|
93
|
-
container.resolve(
|
|
94
|
-
this.logger.error({ error: error2?.message ?? error2,
|
|
103
|
+
container.resolve(RenewAutomationLeaseUseCase).execute({ automationId, workerId: this.workerId, leaseMs }).catch((error2) => {
|
|
104
|
+
this.logger.error({ error: error2?.message ?? error2, automationId }, "[AUTOMATIONS] Failed to renew the lease of an automation");
|
|
95
105
|
});
|
|
96
106
|
}, Math.max(Math.floor(leaseMs / 3), 1e3));
|
|
97
107
|
let status = "failed";
|
|
98
108
|
let error;
|
|
99
109
|
let chat;
|
|
100
110
|
try {
|
|
101
|
-
const outcome = await this.runAgent(
|
|
111
|
+
const outcome = await this.runAgent(automation, run);
|
|
102
112
|
status = outcome.status;
|
|
103
113
|
error = outcome.error;
|
|
104
114
|
chat = outcome.chat;
|
|
105
115
|
} catch (failure) {
|
|
106
116
|
error = { code: failure?.code ?? "RUNNER_ERROR", message: failure?.message ?? String(failure) };
|
|
107
|
-
this.logger.error({ error: error.message,
|
|
117
|
+
this.logger.error({ error: error.message, automationId, runId }, "[AUTOMATIONS] A run failed");
|
|
108
118
|
} finally {
|
|
109
119
|
clearInterval(heartbeat);
|
|
110
120
|
}
|
|
111
|
-
const { data } = await container.resolve(
|
|
112
|
-
await this.notify({
|
|
121
|
+
const { data } = await container.resolve(FinishAutomationRunUseCase).execute({ runId, workerId: this.workerId, status, error });
|
|
122
|
+
await this.notify({ automation, run: data ?? run, chat });
|
|
113
123
|
}
|
|
114
|
-
async runAgent(
|
|
115
|
-
const currentUser = await CurrentUser.asyncFromDB(String(
|
|
116
|
-
if (!currentUser) return { status: "failed", error: { code: "OWNER_NOT_FOUND", message: "The owner of the
|
|
117
|
-
const configured = typeof this.options.agent === "function" ? await this.options.agent({
|
|
124
|
+
async runAgent(automation, run) {
|
|
125
|
+
const currentUser = await CurrentUser.asyncFromDB(String(automation.ownerId));
|
|
126
|
+
if (!currentUser) return { status: "failed", error: { code: "OWNER_NOT_FOUND", message: "The owner of the automation does not exist" } };
|
|
127
|
+
const configured = typeof this.options.agent === "function" ? await this.options.agent({ automation, currentUser }) : this.options.agent ?? {};
|
|
118
128
|
const loop = configured.loop ?? new AgiLoop();
|
|
119
129
|
const agent = new Agent({ ...configured, loop });
|
|
120
|
-
const model =
|
|
130
|
+
const model = automation.modelProvider && automation.modelName ? { modelProvider: automation.modelProvider, modelName: automation.modelName } : {};
|
|
121
131
|
const draft = Chat.withDefaults(loop.name);
|
|
122
132
|
draft.settings?.setExecutionMode("autonomous");
|
|
123
133
|
if (model.modelProvider) draft.settings?.setModelProvider(model.modelProvider);
|
|
124
134
|
if (model.modelName) draft.settings?.setModelName(model.modelName);
|
|
125
135
|
const { data: created } = await createChat({ payload: draft.toJSON(), currentUser });
|
|
126
136
|
const chatId = String(created?._id);
|
|
127
|
-
await container.resolve(
|
|
137
|
+
await container.resolve(AttachAutomationRunChatUseCase).execute({ runId: String(run._id), chatId });
|
|
128
138
|
const result = await agent.run({
|
|
129
|
-
input: { message:
|
|
139
|
+
input: { message: buildMessage(automation.instructions, run.payload), chatId },
|
|
130
140
|
options: { executionMode: "autonomous", ...model },
|
|
131
141
|
currentUser,
|
|
132
|
-
currentSession: CurrentSession.fromJSON({ location: { timezone:
|
|
142
|
+
currentSession: CurrentSession.fromJSON({ location: { timezone: automation.trigger?.timezone } }),
|
|
133
143
|
serviceToken: process.env.INTERNAL_MCP_TOKEN ? secretManager.get("INTERNAL_MCP_TOKEN") : void 0
|
|
134
144
|
});
|
|
135
145
|
const chat = result.data;
|
|
@@ -146,14 +156,14 @@ class AgenticJobRunner {
|
|
|
146
156
|
try {
|
|
147
157
|
await this.options.onRunFinished(event);
|
|
148
158
|
} catch (error) {
|
|
149
|
-
this.logger.error({ error: error?.message ?? error }, "[
|
|
159
|
+
this.logger.error({ error: error?.message ?? error }, "[AUTOMATIONS] The onRunFinished callback failed");
|
|
150
160
|
}
|
|
151
161
|
}
|
|
152
162
|
}
|
|
153
|
-
function
|
|
154
|
-
return new
|
|
163
|
+
function createAutomationRunner(options = {}) {
|
|
164
|
+
return new AutomationRunner(options);
|
|
155
165
|
}
|
|
156
166
|
export {
|
|
157
|
-
|
|
158
|
-
|
|
167
|
+
AutomationRunner,
|
|
168
|
+
createAutomationRunner
|
|
159
169
|
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { BaseUseCase, BaseUseCaseParams, BaseUseCaseOutput } from '../../../common/base/base.use-case.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { AutomationRunProps } from '../entities';
|
|
3
|
+
import { AutomationRunRepository } from '../repositories';
|
|
4
4
|
export interface Params extends BaseUseCaseParams {
|
|
5
5
|
runId: string;
|
|
6
6
|
chatId: string;
|
|
7
7
|
}
|
|
8
8
|
export interface Output extends BaseUseCaseOutput {
|
|
9
|
-
data:
|
|
9
|
+
data: AutomationRunProps | null;
|
|
10
10
|
}
|
|
11
|
-
export declare class
|
|
12
|
-
private readonly
|
|
13
|
-
constructor(
|
|
11
|
+
export declare class AttachAutomationRunChatUseCase extends BaseUseCase<Params, Output> {
|
|
12
|
+
private readonly automationRunRepository?;
|
|
13
|
+
constructor(automationRunRepository?: AutomationRunRepository | undefined);
|
|
14
14
|
execute(params: Params): Promise<Output>;
|
|
15
15
|
}
|
|
@@ -25,34 +25,34 @@ 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 attach_automation_run_chat_use_case_exports = {};
|
|
29
|
+
__export(attach_automation_run_chat_use_case_exports, {
|
|
30
|
+
AttachAutomationRunChatUseCase: () => AttachAutomationRunChatUseCase
|
|
31
31
|
});
|
|
32
|
-
module.exports = __toCommonJS(
|
|
32
|
+
module.exports = __toCommonJS(attach_automation_run_chat_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 AttachAutomationRunChatUseCase = class extends import_base.BaseUseCase {
|
|
38
|
+
constructor(automationRunRepository) {
|
|
39
39
|
super();
|
|
40
|
-
this.
|
|
40
|
+
this.automationRunRepository = automationRunRepository;
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
automationRunRepository;
|
|
43
43
|
async execute(params) {
|
|
44
44
|
const { runId, chatId } = params;
|
|
45
|
-
const run = await this.
|
|
45
|
+
const run = await this.automationRunRepository.findById(runId);
|
|
46
46
|
if (!run) return { data: null };
|
|
47
|
-
const saved = await this.
|
|
47
|
+
const saved = await this.automationRunRepository.update(import_entities.AutomationRun.fromJSON({ ...run, chatId }));
|
|
48
48
|
return { data: saved };
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
|
|
51
|
+
AttachAutomationRunChatUseCase = __decorateClass([
|
|
52
52
|
(0, import_tsyringe.autoInjectable)(),
|
|
53
|
-
__decorateParam(0, (0, import_tsyringe.inject)(import_repositories.
|
|
54
|
-
],
|
|
53
|
+
__decorateParam(0, (0, import_tsyringe.inject)(import_repositories.AutomationRunRepository))
|
|
54
|
+
], AttachAutomationRunChatUseCase);
|
|
55
55
|
// Annotate the CommonJS export names for ESM import in node:
|
|
56
56
|
0 && (module.exports = {
|
|
57
|
-
|
|
57
|
+
AttachAutomationRunChatUseCase
|
|
58
58
|
});
|
|
@@ -0,0 +1,29 @@
|
|
|
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 { AutomationRunRepository } from "../repositories";
|
|
9
|
+
let AttachAutomationRunChatUseCase = class extends BaseUseCase {
|
|
10
|
+
constructor(automationRunRepository) {
|
|
11
|
+
super();
|
|
12
|
+
this.automationRunRepository = automationRunRepository;
|
|
13
|
+
}
|
|
14
|
+
automationRunRepository;
|
|
15
|
+
async execute(params) {
|
|
16
|
+
const { runId, chatId } = params;
|
|
17
|
+
const run = await this.automationRunRepository.findById(runId);
|
|
18
|
+
if (!run) return { data: null };
|
|
19
|
+
const saved = await this.automationRunRepository.update(AutomationRun.fromJSON({ ...run, chatId }));
|
|
20
|
+
return { data: saved };
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
AttachAutomationRunChatUseCase = __decorateClass([
|
|
24
|
+
autoInjectable(),
|
|
25
|
+
__decorateParam(0, inject(AutomationRunRepository))
|
|
26
|
+
], AttachAutomationRunChatUseCase);
|
|
27
|
+
export {
|
|
28
|
+
AttachAutomationRunChatUseCase
|
|
29
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
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 ClaimDueAutomationsUseCase extends BaseUseCase<Params, Output> {
|
|
22
|
+
private readonly automationRepository?;
|
|
23
|
+
private readonly automationRunRepository?;
|
|
24
|
+
private readonly syncRun?;
|
|
25
|
+
private readonly log;
|
|
26
|
+
constructor(automationRepository?: AutomationRepository | undefined, automationRunRepository?: AutomationRunRepository | undefined, syncRun?: SyncAutomationRunUseCase | undefined);
|
|
27
|
+
execute(params: Params): Promise<Output>;
|
|
28
|
+
}
|