openloops 0.4.5 → 0.5.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/CHANGELOG.md +25 -0
- package/dist/db/indexes/automations.js +1 -1
- package/dist/db/indexes/automations.mjs +1 -1
- package/dist/db/migrations/automations.d.ts +1 -0
- package/dist/db/migrations/automations.js +32 -5
- package/dist/db/migrations/automations.mjs +32 -5
- package/dist/services/automations/entities/automation.entity.d.ts +9 -9
- package/dist/services/automations/entities/automation.entity.js +21 -20
- package/dist/services/automations/entities/automation.entity.mjs +21 -20
- package/dist/services/automations/entities/trigger.d.ts +16 -8
- package/dist/services/automations/entities/trigger.js +28 -17
- package/dist/services/automations/entities/trigger.mjs +27 -16
- package/dist/services/automations/repositories/automation.repository.js +4 -4
- package/dist/services/automations/repositories/automation.repository.mjs +4 -4
- package/dist/services/automations/runner/automation-runner.js +1 -1
- package/dist/services/automations/runner/automation-runner.mjs +1 -1
- package/dist/services/automations/use-cases/claim-due-automations.use-case.js +4 -4
- package/dist/services/automations/use-cases/claim-due-automations.use-case.mjs +4 -4
- package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.js +1 -1
- package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.mjs +1 -1
- package/dist/services/automations/use-cases/create-automation.use-case.d.ts +2 -2
- package/dist/services/automations/use-cases/create-automation.use-case.js +4 -3
- package/dist/services/automations/use-cases/create-automation.use-case.mjs +4 -3
- package/dist/services/automations/use-cases/delete-automation.use-case.js +1 -1
- package/dist/services/automations/use-cases/delete-automation.use-case.mjs +1 -1
- package/dist/services/automations/use-cases/issue-automation-event-token.use-case.js +2 -2
- package/dist/services/automations/use-cases/issue-automation-event-token.use-case.mjs +2 -2
- package/dist/services/automations/use-cases/receive-automation-event.use-case.js +3 -2
- package/dist/services/automations/use-cases/receive-automation-event.use-case.mjs +3 -2
- package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.js +2 -2
- package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.mjs +2 -2
- package/dist/services/automations/use-cases/update-automation.use-case.d.ts +2 -2
- package/dist/services/automations/use-cases/update-automation.use-case.js +8 -5
- package/dist/services/automations/use-cases/update-automation.use-case.mjs +8 -5
- package/dist/services/automations/utils/automation-fields.d.ts +3 -4
- package/dist/services/automations/utils/automation-fields.js +3 -5
- package/dist/services/automations/utils/automation-fields.mjs +4 -6
- package/docs/README.md +1 -1
- package/docs/agent.md +2 -2
- package/docs/automations.md +139 -37
- package/docs/mcp-servers.md +4 -4
- package/examples/automations/create-automation.ts +6 -5
- package/examples/automations/create-event-automation.ts +1 -1
- package/examples/automations/list-automations.ts +3 -2
- package/examples/automations/preview-automation-runs.ts +1 -1
- package/examples/automations/revoke-automation-event-token.ts +1 -1
- package/examples/automations/update-automation.ts +4 -5
- package/examples/mcps/internal-mcp.ts +3 -3
- package/examples/run-agent/run-agent-with-identity.ts +1 -1
- package/package.json +1 -1
|
@@ -61,12 +61,12 @@ let ClaimDueAutomationsUseCase = class extends import_base.BaseUseCase {
|
|
|
61
61
|
const skipped = [];
|
|
62
62
|
for (const candidate of due) {
|
|
63
63
|
const id = String(candidate._id);
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
const schedule = candidate.triggers?.schedule;
|
|
65
|
+
if (!schedule) continue;
|
|
66
|
+
const scheduledFor = schedule.nextRunAt ? new Date(schedule.nextRunAt) : void 0;
|
|
67
67
|
let nextRunAt = null;
|
|
68
68
|
try {
|
|
69
|
-
nextRunAt = (0, import_next_run.computeNextRun)(
|
|
69
|
+
nextRunAt = (0, import_next_run.computeNextRun)(schedule.recurrence, schedule.timezone, now);
|
|
70
70
|
} catch (error) {
|
|
71
71
|
this.log.error({ error: error?.message ?? error, automationId: id }, "[AUTOMATIONS] The recurrence of an automation cannot be calculated, skipping it");
|
|
72
72
|
continue;
|
|
@@ -33,12 +33,12 @@ let ClaimDueAutomationsUseCase = class extends BaseUseCase {
|
|
|
33
33
|
const skipped = [];
|
|
34
34
|
for (const candidate of due) {
|
|
35
35
|
const id = String(candidate._id);
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
const schedule = candidate.triggers?.schedule;
|
|
37
|
+
if (!schedule) continue;
|
|
38
|
+
const scheduledFor = schedule.nextRunAt ? new Date(schedule.nextRunAt) : void 0;
|
|
39
39
|
let nextRunAt = null;
|
|
40
40
|
try {
|
|
41
|
-
nextRunAt = computeNextRun(
|
|
41
|
+
nextRunAt = computeNextRun(schedule.recurrence, schedule.timezone, now);
|
|
42
42
|
} catch (error) {
|
|
43
43
|
this.log.error({ error: error?.message ?? error, automationId: id }, "[AUTOMATIONS] The recurrence of an automation cannot be calculated, skipping it");
|
|
44
44
|
continue;
|
|
@@ -64,7 +64,7 @@ let ClaimQueuedAutomationRunsUseCase = class extends import_base.BaseUseCase {
|
|
|
64
64
|
if (seen.has(automationId)) continue;
|
|
65
65
|
seen.add(automationId);
|
|
66
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;
|
|
67
|
+
const reason = !existing ? "The automation no longer exists" : !existing.triggers?.event?.enabled ? "The event trigger of the automation is turned off" : void 0;
|
|
68
68
|
if (reason) {
|
|
69
69
|
const settled = await this.automationRunRepository.update(import_entities.AutomationRun.fromJSON({ ...run, status: "skipped", finishedAt: now, skipReason: reason }));
|
|
70
70
|
if (existing && settled) skipped.push({ automation: existing, run: settled });
|
|
@@ -36,7 +36,7 @@ let ClaimQueuedAutomationRunsUseCase = class extends BaseUseCase {
|
|
|
36
36
|
if (seen.has(automationId)) continue;
|
|
37
37
|
seen.add(automationId);
|
|
38
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;
|
|
39
|
+
const reason = !existing ? "The automation no longer exists" : !existing.triggers?.event?.enabled ? "The event trigger of the automation is turned off" : void 0;
|
|
40
40
|
if (reason) {
|
|
41
41
|
const settled = await this.automationRunRepository.update(AutomationRun.fromJSON({ ...run, status: "skipped", finishedAt: now, skipReason: reason }));
|
|
42
42
|
if (existing && settled) skipped.push({ automation: existing, run: settled });
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BaseUseCase, BaseUseCaseParams, BaseUseCaseOutput } from '../../../common/base/base.use-case.js';
|
|
2
|
-
import { AutomationProps } from '../entities';
|
|
2
|
+
import { AutomationPayload, AutomationProps } from '../entities';
|
|
3
3
|
import { AutomationRepository } from '../repositories';
|
|
4
4
|
export interface Params extends BaseUseCaseParams {
|
|
5
|
-
payload?:
|
|
5
|
+
payload?: AutomationPayload;
|
|
6
6
|
}
|
|
7
7
|
export interface Output extends BaseUseCaseOutput {
|
|
8
8
|
data: AutomationProps;
|
|
@@ -49,15 +49,16 @@ let CreateAutomationUseCase = class extends import_base.BaseUseCase {
|
|
|
49
49
|
const automation = import_entities.Automation.fromJSON({
|
|
50
50
|
name: fields.name,
|
|
51
51
|
instructions: fields.instructions,
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
triggers: fields.triggers,
|
|
53
|
+
eventTokenVersion: 1,
|
|
54
54
|
modelProvider: fields.modelProvider ?? void 0,
|
|
55
55
|
modelName: fields.modelName ?? void 0
|
|
56
56
|
});
|
|
57
57
|
automation.setCreatedBy(currentUser);
|
|
58
58
|
automation.setOwner(currentUser);
|
|
59
59
|
automation.scheduleNextRun();
|
|
60
|
-
|
|
60
|
+
const schedule = automation.triggers?.schedule;
|
|
61
|
+
if (schedule?.enabled && !schedule.nextRunAt) throw new Error("The date of the recurrence has already passed");
|
|
61
62
|
await this.automationRepository?.create(automation);
|
|
62
63
|
return { data: automation.toJSON() };
|
|
63
64
|
}
|
|
@@ -21,15 +21,16 @@ let CreateAutomationUseCase = class extends BaseUseCase {
|
|
|
21
21
|
const automation = Automation.fromJSON({
|
|
22
22
|
name: fields.name,
|
|
23
23
|
instructions: fields.instructions,
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
triggers: fields.triggers,
|
|
25
|
+
eventTokenVersion: 1,
|
|
26
26
|
modelProvider: fields.modelProvider ?? void 0,
|
|
27
27
|
modelName: fields.modelName ?? void 0
|
|
28
28
|
});
|
|
29
29
|
automation.setCreatedBy(currentUser);
|
|
30
30
|
automation.setOwner(currentUser);
|
|
31
31
|
automation.scheduleNextRun();
|
|
32
|
-
|
|
32
|
+
const schedule = automation.triggers?.schedule;
|
|
33
|
+
if (schedule?.enabled && !schedule.nextRunAt) throw new Error("The date of the recurrence has already passed");
|
|
33
34
|
await this.automationRepository?.create(automation);
|
|
34
35
|
return { data: automation.toJSON() };
|
|
35
36
|
}
|
|
@@ -50,7 +50,7 @@ let DeleteAutomationUseCase = class extends import_base.BaseUseCase {
|
|
|
50
50
|
}
|
|
51
51
|
const automation = import_entities.Automation.fromJSON({ _id: id });
|
|
52
52
|
automation.setDeletedBy(currentUser);
|
|
53
|
-
automation.unset(["nextRunAt"]);
|
|
53
|
+
automation.unset(["triggers.schedule.nextRunAt"]);
|
|
54
54
|
const result = await this.automationRepository?.update(automation);
|
|
55
55
|
return { data: result };
|
|
56
56
|
}
|
|
@@ -22,7 +22,7 @@ let DeleteAutomationUseCase = class extends BaseUseCase {
|
|
|
22
22
|
}
|
|
23
23
|
const automation = Automation.fromJSON({ _id: id });
|
|
24
24
|
automation.setDeletedBy(currentUser);
|
|
25
|
-
automation.unset(["nextRunAt"]);
|
|
25
|
+
automation.unset(["triggers.schedule.nextRunAt"]);
|
|
26
26
|
const result = await this.automationRepository?.update(automation);
|
|
27
27
|
return { data: result };
|
|
28
28
|
}
|
|
@@ -45,8 +45,8 @@ let IssueAutomationEventTokenUseCase = class extends import_base.BaseUseCase {
|
|
|
45
45
|
const automation = await this.automationRepository?.findById(id);
|
|
46
46
|
if (!automation) throw new Error("Automation not found");
|
|
47
47
|
if (!currentUser?.isAdmin() && String(automation.ownerId) !== currentUser?.userId) this.throwError403();
|
|
48
|
-
if (automation.
|
|
49
|
-
return { data: (0, import_event_token.signEventToken)({ automationId: id, tokenVersion: automation.
|
|
48
|
+
if (!automation.triggers?.event) throw new Error("Only an automation with an event trigger has a token");
|
|
49
|
+
return { data: (0, import_event_token.signEventToken)({ automationId: id, tokenVersion: automation.eventTokenVersion, expiresIn }) };
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
52
|
IssueAutomationEventTokenUseCase = __decorateClass([
|
|
@@ -17,8 +17,8 @@ let IssueAutomationEventTokenUseCase = class extends BaseUseCase {
|
|
|
17
17
|
const automation = await this.automationRepository?.findById(id);
|
|
18
18
|
if (!automation) throw new Error("Automation not found");
|
|
19
19
|
if (!currentUser?.isAdmin() && String(automation.ownerId) !== currentUser?.userId) this.throwError403();
|
|
20
|
-
if (automation.
|
|
21
|
-
return { data: signEventToken({ automationId: id, tokenVersion: automation.
|
|
20
|
+
if (!automation.triggers?.event) throw new Error("Only an automation with an event trigger has a token");
|
|
21
|
+
return { data: signEventToken({ automationId: id, tokenVersion: automation.eventTokenVersion, expiresIn }) };
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
24
|
IssueAutomationEventTokenUseCase = __decorateClass([
|
|
@@ -59,8 +59,9 @@ let ReceiveAutomationEventUseCase = class extends import_base.BaseUseCase {
|
|
|
59
59
|
if (claims.sub !== automationId) throw new import_automation_event_error.AutomationEventError("invalid");
|
|
60
60
|
const automation = await this.automationRepository.findById(automationId);
|
|
61
61
|
if (!automation) throw new import_automation_event_error.AutomationEventError("not_found");
|
|
62
|
-
|
|
63
|
-
if (!automation.
|
|
62
|
+
const event = automation.triggers?.event;
|
|
63
|
+
if (!event || automation.eventTokenVersion !== claims.v) throw new import_automation_event_error.AutomationEventError("invalid");
|
|
64
|
+
if (!event.enabled) throw new import_automation_event_error.AutomationEventError("disabled");
|
|
64
65
|
const { data: { revoked } } = await (0, import_authentication.isTokenRevoked)({ jti: claims.jti });
|
|
65
66
|
if (revoked) throw new import_automation_event_error.AutomationEventError("revoked");
|
|
66
67
|
const payload = serialize(params.payload);
|
|
@@ -31,8 +31,9 @@ let ReceiveAutomationEventUseCase = class extends BaseUseCase {
|
|
|
31
31
|
if (claims.sub !== automationId) throw new AutomationEventError("invalid");
|
|
32
32
|
const automation = await this.automationRepository.findById(automationId);
|
|
33
33
|
if (!automation) throw new AutomationEventError("not_found");
|
|
34
|
-
|
|
35
|
-
if (!automation.
|
|
34
|
+
const event = automation.triggers?.event;
|
|
35
|
+
if (!event || automation.eventTokenVersion !== claims.v) throw new AutomationEventError("invalid");
|
|
36
|
+
if (!event.enabled) throw new AutomationEventError("disabled");
|
|
36
37
|
const { data: { revoked } } = await isTokenRevoked({ jti: claims.jti });
|
|
37
38
|
if (revoked) throw new AutomationEventError("revoked");
|
|
38
39
|
const payload = serialize(params.payload);
|
|
@@ -45,8 +45,8 @@ let RotateAutomationEventTokensUseCase = class extends import_base.BaseUseCase {
|
|
|
45
45
|
const existing = await this.automationRepository?.findById(id);
|
|
46
46
|
if (!existing) throw new Error("Automation not found");
|
|
47
47
|
if (!currentUser?.isAdmin() && String(existing.ownerId) !== currentUser?.userId) this.throwError403();
|
|
48
|
-
if (existing.
|
|
49
|
-
const automation = import_entities.Automation.fromJSON({ ...existing,
|
|
48
|
+
if (!existing.triggers?.event) throw new Error("Only an automation with an event trigger has tokens");
|
|
49
|
+
const automation = import_entities.Automation.fromJSON({ ...existing, eventTokenVersion: existing.eventTokenVersion + 1 });
|
|
50
50
|
automation.setUpdatedBy(currentUser);
|
|
51
51
|
const result = await this.automationRepository?.update(automation, { expectedVersion: existing.__v });
|
|
52
52
|
if (!result) throw new Error("Automation not found or update failed");
|
|
@@ -17,8 +17,8 @@ let RotateAutomationEventTokensUseCase = class extends BaseUseCase {
|
|
|
17
17
|
const existing = await this.automationRepository?.findById(id);
|
|
18
18
|
if (!existing) throw new Error("Automation not found");
|
|
19
19
|
if (!currentUser?.isAdmin() && String(existing.ownerId) !== currentUser?.userId) this.throwError403();
|
|
20
|
-
if (existing.
|
|
21
|
-
const automation = Automation.fromJSON({ ...existing,
|
|
20
|
+
if (!existing.triggers?.event) throw new Error("Only an automation with an event trigger has tokens");
|
|
21
|
+
const automation = Automation.fromJSON({ ...existing, eventTokenVersion: existing.eventTokenVersion + 1 });
|
|
22
22
|
automation.setUpdatedBy(currentUser);
|
|
23
23
|
const result = await this.automationRepository?.update(automation, { expectedVersion: existing.__v });
|
|
24
24
|
if (!result) throw new Error("Automation not found or update failed");
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BaseUseCase, BaseUseCaseParams, BaseUseCaseOutput } from '../../../common/base/base.use-case.js';
|
|
2
|
-
import { AutomationProps } from '../entities';
|
|
2
|
+
import { AutomationPayload, AutomationProps } from '../entities';
|
|
3
3
|
import { AutomationRepository } from '../repositories';
|
|
4
4
|
export interface Params extends BaseUseCaseParams {
|
|
5
5
|
id: string;
|
|
6
|
-
payload?:
|
|
6
|
+
payload?: AutomationPayload;
|
|
7
7
|
}
|
|
8
8
|
export interface Output extends BaseUseCaseOutput {
|
|
9
9
|
data: AutomationProps;
|
|
@@ -48,7 +48,7 @@ let UpdateAutomationUseCase = class extends import_base.BaseUseCase {
|
|
|
48
48
|
const existing = await this.automationRepository?.findById(id);
|
|
49
49
|
if (!existing) throw new Error("Automation not found or update failed");
|
|
50
50
|
if (payload.__v !== void 0 && payload.__v !== existing.__v) throw new import_mongo_db.VersionConflictError();
|
|
51
|
-
const changes = (0, import_automation_fields.readAutomationFields)(payload, { complete: false,
|
|
51
|
+
const changes = (0, import_automation_fields.readAutomationFields)(payload, { complete: false, triggers: existing.triggers });
|
|
52
52
|
const { modelProvider, modelName, ...rest } = changes;
|
|
53
53
|
const provider = modelProvider === void 0 ? existing.modelProvider : modelProvider;
|
|
54
54
|
const name = modelName === void 0 ? existing.modelName : modelName;
|
|
@@ -62,11 +62,14 @@ let UpdateAutomationUseCase = class extends import_base.BaseUseCase {
|
|
|
62
62
|
});
|
|
63
63
|
automation.setUpdatedBy(currentUser);
|
|
64
64
|
if (!provider) automation.unset(["modelProvider", "modelName"]);
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
if (
|
|
65
|
+
const removed = ["schedule", "event"].filter((key) => existing.triggers?.[key] && !automation.triggers?.[key]);
|
|
66
|
+
if (removed.length) automation.toUnset = Object.fromEntries(removed.map((key) => [`triggers.${key}`, ""]));
|
|
67
|
+
if (removed.includes("event")) automation.eventTokenVersion = existing.eventTokenVersion + 1;
|
|
68
|
+
const schedule = automation.triggers?.schedule;
|
|
69
|
+
const scheduleChanged = payload.triggers?.schedule !== void 0;
|
|
70
|
+
if (schedule && (scheduleChanged || schedule.enabled && !schedule.nextRunAt)) {
|
|
68
71
|
automation.scheduleNextRun();
|
|
69
|
-
if (
|
|
72
|
+
if (schedule.enabled && !schedule.nextRunAt) throw new Error("The date of the recurrence has already passed");
|
|
70
73
|
}
|
|
71
74
|
const result = await this.automationRepository?.update(automation, { expectedVersion: existing.__v });
|
|
72
75
|
if (!result) throw new Error("Automation not found or update failed");
|
|
@@ -20,7 +20,7 @@ let UpdateAutomationUseCase = class extends BaseUseCase {
|
|
|
20
20
|
const existing = await this.automationRepository?.findById(id);
|
|
21
21
|
if (!existing) throw new Error("Automation not found or update failed");
|
|
22
22
|
if (payload.__v !== void 0 && payload.__v !== existing.__v) throw new VersionConflictError();
|
|
23
|
-
const changes = readAutomationFields(payload, { complete: false,
|
|
23
|
+
const changes = readAutomationFields(payload, { complete: false, triggers: existing.triggers });
|
|
24
24
|
const { modelProvider, modelName, ...rest } = changes;
|
|
25
25
|
const provider = modelProvider === void 0 ? existing.modelProvider : modelProvider;
|
|
26
26
|
const name = modelName === void 0 ? existing.modelName : modelName;
|
|
@@ -34,11 +34,14 @@ let UpdateAutomationUseCase = class extends BaseUseCase {
|
|
|
34
34
|
});
|
|
35
35
|
automation.setUpdatedBy(currentUser);
|
|
36
36
|
if (!provider) automation.unset(["modelProvider", "modelName"]);
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
if (
|
|
37
|
+
const removed = ["schedule", "event"].filter((key) => existing.triggers?.[key] && !automation.triggers?.[key]);
|
|
38
|
+
if (removed.length) automation.toUnset = Object.fromEntries(removed.map((key) => [`triggers.${key}`, ""]));
|
|
39
|
+
if (removed.includes("event")) automation.eventTokenVersion = existing.eventTokenVersion + 1;
|
|
40
|
+
const schedule = automation.triggers?.schedule;
|
|
41
|
+
const scheduleChanged = payload.triggers?.schedule !== void 0;
|
|
42
|
+
if (schedule && (scheduleChanged || schedule.enabled && !schedule.nextRunAt)) {
|
|
40
43
|
automation.scheduleNextRun();
|
|
41
|
-
if (
|
|
44
|
+
if (schedule.enabled && !schedule.nextRunAt) throw new Error("The date of the recurrence has already passed");
|
|
42
45
|
}
|
|
43
46
|
const result = await this.automationRepository?.update(automation, { expectedVersion: existing.__v });
|
|
44
47
|
if (!result) throw new Error("Automation not found or update failed");
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AutomationTriggers } from '../entities/trigger';
|
|
2
2
|
export interface AutomationFields {
|
|
3
3
|
name?: string;
|
|
4
4
|
instructions?: string;
|
|
5
|
-
|
|
6
|
-
trigger?: AutomationTrigger;
|
|
5
|
+
triggers?: AutomationTriggers;
|
|
7
6
|
modelProvider?: string | null;
|
|
8
7
|
modelName?: string | null;
|
|
9
8
|
}
|
|
10
9
|
export declare function readAutomationFields(payload: Record<string, any> | undefined, options: {
|
|
11
10
|
complete: boolean;
|
|
12
|
-
|
|
11
|
+
triggers?: AutomationTriggers;
|
|
13
12
|
}): AutomationFields;
|
|
14
13
|
export declare function assertModel(provider?: string | null, name?: string | null): void;
|
|
@@ -40,11 +40,9 @@ function readAutomationFields(payload, options) {
|
|
|
40
40
|
const has = (key) => input[key] !== void 0;
|
|
41
41
|
if (options.complete || has("name")) fields.name = text(input.name, "name", MAX_NAME_CHARS);
|
|
42
42
|
if (options.complete || has("instructions")) fields.instructions = text(input.instructions, "instructions", MAX_INSTRUCTIONS_CHARS);
|
|
43
|
-
if (
|
|
44
|
-
if (has("enabled"))
|
|
45
|
-
|
|
46
|
-
fields.enabled = input.enabled;
|
|
47
|
-
}
|
|
43
|
+
if (has("trigger")) throw new Error("The field trigger was replaced by triggers");
|
|
44
|
+
if (has("enabled")) throw new Error("The field enabled belongs to each trigger, send it inside triggers.schedule or triggers.event");
|
|
45
|
+
if (options.complete || has("triggers")) fields.triggers = (0, import_trigger.readTriggers)(input.triggers, options.triggers);
|
|
48
46
|
if (has("modelProvider")) fields.modelProvider = optionalText(input.modelProvider, "model provider");
|
|
49
47
|
if (has("modelName")) fields.modelName = optionalText(input.modelName, "model name");
|
|
50
48
|
return fields;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "../../../chunk-CF3WOMB3.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { readTriggers } from "../entities/trigger";
|
|
3
3
|
const MAX_NAME_CHARS = 200;
|
|
4
4
|
const MAX_INSTRUCTIONS_CHARS = 2e4;
|
|
5
5
|
const text = (value, label, max) => {
|
|
@@ -17,11 +17,9 @@ function readAutomationFields(payload, options) {
|
|
|
17
17
|
const has = (key) => input[key] !== void 0;
|
|
18
18
|
if (options.complete || has("name")) fields.name = text(input.name, "name", MAX_NAME_CHARS);
|
|
19
19
|
if (options.complete || has("instructions")) fields.instructions = text(input.instructions, "instructions", MAX_INSTRUCTIONS_CHARS);
|
|
20
|
-
if (
|
|
21
|
-
if (has("enabled"))
|
|
22
|
-
|
|
23
|
-
fields.enabled = input.enabled;
|
|
24
|
-
}
|
|
20
|
+
if (has("trigger")) throw new Error("The field trigger was replaced by triggers");
|
|
21
|
+
if (has("enabled")) throw new Error("The field enabled belongs to each trigger, send it inside triggers.schedule or triggers.event");
|
|
22
|
+
if (options.complete || has("triggers")) fields.triggers = readTriggers(input.triggers, options.triggers);
|
|
25
23
|
if (has("modelProvider")) fields.modelProvider = optionalText(input.modelProvider, "model provider");
|
|
26
24
|
if (has("modelName")) fields.modelName = optionalText(input.modelName, "model name");
|
|
27
25
|
return fields;
|
package/docs/README.md
CHANGED
|
@@ -14,7 +14,7 @@ Start with the [README](../README.md) for what `openloops` is and how to run it.
|
|
|
14
14
|
| --- | --- |
|
|
15
15
|
| [The `Agent`](agent.md) | Options, running a turn, the result and its statuses, confirmations, autonomous mode, hooks and interruption. |
|
|
16
16
|
| [Configuration](configuration.md) | Environment variables, choosing the model and what is recorded. |
|
|
17
|
-
| [Automations](automations.md) | Tasks that the agent runs by itself, on a schedule
|
|
17
|
+
| [Automations](automations.md) | Tasks that the agent runs by itself, on a schedule, when an event arrives or both: triggers, tokens, the queue, the history of runs and the runner that executes them. If you used `agentic-jobs`, read [the migration steps](automations.md#migrating-from-agentic-jobs). Updating to 0.5.0 breaks the shape of the triggers, read [the migration to 0.5.0](automations.md#migrating-to-050). |
|
|
18
18
|
| [Chats](chats.md) | The chat record, its messages and their `source`, listing, reading and deleting chats. |
|
|
19
19
|
|
|
20
20
|
## Shape how the agent works
|
package/docs/agent.md
CHANGED
|
@@ -15,7 +15,7 @@ const agent = new Agent({
|
|
|
15
15
|
tools: [],
|
|
16
16
|
guards: [],
|
|
17
17
|
identity: {
|
|
18
|
-
name: '
|
|
18
|
+
name: 'Ava',
|
|
19
19
|
gender: 'Female',
|
|
20
20
|
role: 'Personal assistant and daily companion',
|
|
21
21
|
},
|
|
@@ -199,7 +199,7 @@ await agent.run({ input: { chatId, message }, currentUser })
|
|
|
199
199
|
stop()
|
|
200
200
|
```
|
|
201
201
|
|
|
202
|
-
The listener receives every change of the activity of the run while it is in progress. It gets no start or end marker: the run is over when `agent.run()` resolves. This is the only place where the real activity is available: since 0.3.0 it is not saved with the chat, and `state.currentActivity` is deprecated (see [chats](chats.md#statecurrentactivity-is-deprecated)). It does not receive a value that repeats the previous one. With `AgiLoop` the value is a short sentence written by the model in the language of the conversation, such as `
|
|
202
|
+
The listener receives every change of the activity of the run while it is in progress. It gets no start or end marker: the run is over when `agent.run()` resolves. This is the only place where the real activity is available: since 0.3.0 it is not saved with the chat, and `state.currentActivity` is deprecated (see [chats](chats.md#statecurrentactivity-is-deprecated)). It does not receive a value that repeats the previous one. With `AgiLoop` the value is a short sentence written by the model in the language of the conversation, such as `Searching your flight expenses for August`, shown from the answer that asked for the actions until the next answer. When the model gives none, the listener hears nothing and the client keeps what it shows. See [loops](loops.md#agiloop).
|
|
203
203
|
|
|
204
204
|
- The listener belongs to that `Agent` instance and to the chat of its current run. Nothing is shared between instances, so concurrent runs in the same process, even of different users, never hear each other. As always, create one `Agent` per run and do not share it between concurrent requests.
|
|
205
205
|
- It is called synchronously from the loop, so keep it fast and do not await inside it. An error thrown by a listener is logged and ignored, the run goes on and the other listeners still run.
|