openloops 0.10.0 → 0.10.2
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 +12 -0
- package/dist/services/automations/entities/recurrence.d.ts +11 -0
- package/dist/services/automations/entities/recurrence.js +26 -6
- package/dist/services/automations/entities/recurrence.mjs +23 -6
- package/dist/services/automations/runner/automation-runner.js +1 -0
- package/dist/services/automations/runner/automation-runner.mjs +1 -0
- package/dist/services/automations/utils/next-run.js +9 -0
- package/dist/services/automations/utils/next-run.mjs +10 -1
- package/docs/automations.md +2 -0
- package/package.json +13 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to `openloops` are written here, newest first. The format follows [Keep a Changelog](https://keepachangelog.com) and the versions follow [semantic versioning](https://semver.org), where a minor version can still break the API while the package is in beta. Changes before 0.4.0 are not recorded here, see the commits and the tags.
|
|
4
4
|
|
|
5
|
+
## 0.10.1
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- `openloops/tasks`, `openloops/traces` and `openloops/workspaces` are exported, so a backend can read the tasks, actions, traces and workspace items of a chat (`listAgentTasksByChat`, `getAgentTaskById`, `listAgentActionsByTask`, `listAgentTracesByChat`, `listWorkspaceItems`, `getWorkspaceItem`, `searchWorkspaceItems`, `saveWorkspaceItem`, `deleteWorkspaceItem`). Their functions already existed and only the subpaths were missing.
|
|
10
|
+
|
|
11
|
+
- Recurrence of type `interval` for automations: every X minutes or hours counted from a `start` date and time (`{ type: 'interval', every, unit, start }`, `IntervalUnit` enum). It is an exact interval from `start`, not tied to the clock, and the shortest is 5 minutes. No migration needed.
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- The chat of an automation run takes the name of the automation as its title. Before, it took the first 80 characters of the instructions, or had none.
|
|
16
|
+
|
|
5
17
|
## 0.10.0
|
|
6
18
|
|
|
7
19
|
### Added
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
export declare const WEEKDAYS: readonly ["MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"];
|
|
2
|
+
export declare enum IntervalUnit {
|
|
3
|
+
MINUTES = "minutes",
|
|
4
|
+
HOURS = "hours"
|
|
5
|
+
}
|
|
6
|
+
export declare const MIN_INTERVAL_MINUTES = 5;
|
|
7
|
+
export declare const intervalToMinutes: (every: number, unit: IntervalUnit) => number;
|
|
2
8
|
export type Recurrence = {
|
|
3
9
|
type: 'daily';
|
|
4
10
|
time: string;
|
|
@@ -10,6 +16,11 @@ export type Recurrence = {
|
|
|
10
16
|
type: 'monthly';
|
|
11
17
|
day: number | 'last';
|
|
12
18
|
time: string;
|
|
19
|
+
} | {
|
|
20
|
+
type: 'interval';
|
|
21
|
+
every: number;
|
|
22
|
+
unit: IntervalUnit;
|
|
23
|
+
start: string;
|
|
13
24
|
} | {
|
|
14
25
|
type: 'once';
|
|
15
26
|
at: string;
|
|
@@ -18,12 +18,22 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var recurrence_exports = {};
|
|
20
20
|
__export(recurrence_exports, {
|
|
21
|
+
IntervalUnit: () => IntervalUnit,
|
|
22
|
+
MIN_INTERVAL_MINUTES: () => MIN_INTERVAL_MINUTES,
|
|
21
23
|
WEEKDAYS: () => WEEKDAYS,
|
|
24
|
+
intervalToMinutes: () => intervalToMinutes,
|
|
22
25
|
toCronPattern: () => toCronPattern,
|
|
23
26
|
validateRecurrence: () => validateRecurrence
|
|
24
27
|
});
|
|
25
28
|
module.exports = __toCommonJS(recurrence_exports);
|
|
26
29
|
const WEEKDAYS = ["MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"];
|
|
30
|
+
var IntervalUnit = /* @__PURE__ */ ((IntervalUnit2) => {
|
|
31
|
+
IntervalUnit2["MINUTES"] = "minutes";
|
|
32
|
+
IntervalUnit2["HOURS"] = "hours";
|
|
33
|
+
return IntervalUnit2;
|
|
34
|
+
})(IntervalUnit || {});
|
|
35
|
+
const MIN_INTERVAL_MINUTES = 5;
|
|
36
|
+
const intervalToMinutes = (every, unit) => unit === "hours" /* HOURS */ ? every * 60 : every;
|
|
27
37
|
const TIME = /^([01]\d|2[0-3]):([0-5]\d)$/;
|
|
28
38
|
const LOCAL_DATE_TIME = /^(\d{4})-(\d{2})-(\d{2})T([01]\d|2[0-3]):([0-5]\d)$/;
|
|
29
39
|
const isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
@@ -31,13 +41,13 @@ const assertTime = (value) => {
|
|
|
31
41
|
if (typeof value !== "string" || !TIME.test(value)) throw new Error("The time must be written as HH:mm, in 24 hours");
|
|
32
42
|
return value;
|
|
33
43
|
};
|
|
34
|
-
const assertLocalDateTime = (value) => {
|
|
44
|
+
const assertLocalDateTime = (value, type) => {
|
|
35
45
|
const match = typeof value === "string" ? LOCAL_DATE_TIME.exec(value) : null;
|
|
36
|
-
if (!match) throw new Error(
|
|
46
|
+
if (!match) throw new Error(`The date of a recurrence of type ${type} must be written as YYYY-MM-DDTHH:mm`);
|
|
37
47
|
const [, year, month, day] = match;
|
|
38
48
|
const parsed = new Date(Date.UTC(Number(year), Number(month) - 1, Number(day)));
|
|
39
49
|
if (parsed.getUTCFullYear() !== Number(year) || parsed.getUTCMonth() !== Number(month) - 1 || parsed.getUTCDate() !== Number(day)) {
|
|
40
|
-
throw new Error(
|
|
50
|
+
throw new Error(`The date of a recurrence of type ${type} does not exist`);
|
|
41
51
|
}
|
|
42
52
|
return value;
|
|
43
53
|
};
|
|
@@ -58,14 +68,21 @@ function validateRecurrence(value) {
|
|
|
58
68
|
if (!valid) throw new Error('The day of a monthly recurrence must be a number from 1 to 31 or "last"');
|
|
59
69
|
return { type: "monthly", day, time: assertTime(value.time) };
|
|
60
70
|
}
|
|
71
|
+
case "interval": {
|
|
72
|
+
const { every, unit } = value;
|
|
73
|
+
if (!Number.isInteger(every) || every < 1) throw new Error("The interval of a recurrence must be a whole number greater than zero");
|
|
74
|
+
if (!Object.values(IntervalUnit).includes(unit)) throw new Error("The unit of an interval must be minutes or hours");
|
|
75
|
+
if (intervalToMinutes(every, unit) < MIN_INTERVAL_MINUTES) throw new Error(`The interval of a recurrence cannot be shorter than ${MIN_INTERVAL_MINUTES} minutes`);
|
|
76
|
+
return { type: "interval", every, unit, start: assertLocalDateTime(value.start, "interval") };
|
|
77
|
+
}
|
|
61
78
|
case "once":
|
|
62
|
-
return { type: "once", at: assertLocalDateTime(value.at) };
|
|
79
|
+
return { type: "once", at: assertLocalDateTime(value.at, "once") };
|
|
63
80
|
default:
|
|
64
|
-
throw new Error("The type of the recurrence must be daily, weekly, monthly or once");
|
|
81
|
+
throw new Error("The type of the recurrence must be daily, weekly, monthly, interval or once");
|
|
65
82
|
}
|
|
66
83
|
}
|
|
67
84
|
function toCronPattern(recurrence) {
|
|
68
|
-
if (recurrence.type === "once") return void 0;
|
|
85
|
+
if (recurrence.type === "once" || recurrence.type === "interval") return void 0;
|
|
69
86
|
const [hour, minute] = recurrence.time.split(":").map(Number);
|
|
70
87
|
switch (recurrence.type) {
|
|
71
88
|
case "daily":
|
|
@@ -78,7 +95,10 @@ function toCronPattern(recurrence) {
|
|
|
78
95
|
}
|
|
79
96
|
// Annotate the CommonJS export names for ESM import in node:
|
|
80
97
|
0 && (module.exports = {
|
|
98
|
+
IntervalUnit,
|
|
99
|
+
MIN_INTERVAL_MINUTES,
|
|
81
100
|
WEEKDAYS,
|
|
101
|
+
intervalToMinutes,
|
|
82
102
|
toCronPattern,
|
|
83
103
|
validateRecurrence
|
|
84
104
|
});
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
const WEEKDAYS = ["MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"];
|
|
2
|
+
var IntervalUnit = /* @__PURE__ */ ((IntervalUnit2) => {
|
|
3
|
+
IntervalUnit2["MINUTES"] = "minutes";
|
|
4
|
+
IntervalUnit2["HOURS"] = "hours";
|
|
5
|
+
return IntervalUnit2;
|
|
6
|
+
})(IntervalUnit || {});
|
|
7
|
+
const MIN_INTERVAL_MINUTES = 5;
|
|
8
|
+
const intervalToMinutes = (every, unit) => unit === "hours" /* HOURS */ ? every * 60 : every;
|
|
2
9
|
const TIME = /^([01]\d|2[0-3]):([0-5]\d)$/;
|
|
3
10
|
const LOCAL_DATE_TIME = /^(\d{4})-(\d{2})-(\d{2})T([01]\d|2[0-3]):([0-5]\d)$/;
|
|
4
11
|
const isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
@@ -6,13 +13,13 @@ const assertTime = (value) => {
|
|
|
6
13
|
if (typeof value !== "string" || !TIME.test(value)) throw new Error("The time must be written as HH:mm, in 24 hours");
|
|
7
14
|
return value;
|
|
8
15
|
};
|
|
9
|
-
const assertLocalDateTime = (value) => {
|
|
16
|
+
const assertLocalDateTime = (value, type) => {
|
|
10
17
|
const match = typeof value === "string" ? LOCAL_DATE_TIME.exec(value) : null;
|
|
11
|
-
if (!match) throw new Error(
|
|
18
|
+
if (!match) throw new Error(`The date of a recurrence of type ${type} must be written as YYYY-MM-DDTHH:mm`);
|
|
12
19
|
const [, year, month, day] = match;
|
|
13
20
|
const parsed = new Date(Date.UTC(Number(year), Number(month) - 1, Number(day)));
|
|
14
21
|
if (parsed.getUTCFullYear() !== Number(year) || parsed.getUTCMonth() !== Number(month) - 1 || parsed.getUTCDate() !== Number(day)) {
|
|
15
|
-
throw new Error(
|
|
22
|
+
throw new Error(`The date of a recurrence of type ${type} does not exist`);
|
|
16
23
|
}
|
|
17
24
|
return value;
|
|
18
25
|
};
|
|
@@ -33,14 +40,21 @@ function validateRecurrence(value) {
|
|
|
33
40
|
if (!valid) throw new Error('The day of a monthly recurrence must be a number from 1 to 31 or "last"');
|
|
34
41
|
return { type: "monthly", day, time: assertTime(value.time) };
|
|
35
42
|
}
|
|
43
|
+
case "interval": {
|
|
44
|
+
const { every, unit } = value;
|
|
45
|
+
if (!Number.isInteger(every) || every < 1) throw new Error("The interval of a recurrence must be a whole number greater than zero");
|
|
46
|
+
if (!Object.values(IntervalUnit).includes(unit)) throw new Error("The unit of an interval must be minutes or hours");
|
|
47
|
+
if (intervalToMinutes(every, unit) < MIN_INTERVAL_MINUTES) throw new Error(`The interval of a recurrence cannot be shorter than ${MIN_INTERVAL_MINUTES} minutes`);
|
|
48
|
+
return { type: "interval", every, unit, start: assertLocalDateTime(value.start, "interval") };
|
|
49
|
+
}
|
|
36
50
|
case "once":
|
|
37
|
-
return { type: "once", at: assertLocalDateTime(value.at) };
|
|
51
|
+
return { type: "once", at: assertLocalDateTime(value.at, "once") };
|
|
38
52
|
default:
|
|
39
|
-
throw new Error("The type of the recurrence must be daily, weekly, monthly or once");
|
|
53
|
+
throw new Error("The type of the recurrence must be daily, weekly, monthly, interval or once");
|
|
40
54
|
}
|
|
41
55
|
}
|
|
42
56
|
function toCronPattern(recurrence) {
|
|
43
|
-
if (recurrence.type === "once") return void 0;
|
|
57
|
+
if (recurrence.type === "once" || recurrence.type === "interval") return void 0;
|
|
44
58
|
const [hour, minute] = recurrence.time.split(":").map(Number);
|
|
45
59
|
switch (recurrence.type) {
|
|
46
60
|
case "daily":
|
|
@@ -52,7 +66,10 @@ function toCronPattern(recurrence) {
|
|
|
52
66
|
}
|
|
53
67
|
}
|
|
54
68
|
export {
|
|
69
|
+
IntervalUnit,
|
|
70
|
+
MIN_INTERVAL_MINUTES,
|
|
55
71
|
WEEKDAYS,
|
|
72
|
+
intervalToMinutes,
|
|
56
73
|
toCronPattern,
|
|
57
74
|
validateRecurrence
|
|
58
75
|
};
|
|
@@ -154,6 +154,7 @@ class AutomationRunner {
|
|
|
154
154
|
const agent = new import_agent.Agent({ ...configured, loop });
|
|
155
155
|
const model = automation.modelProvider && automation.modelName ? { modelProvider: automation.modelProvider, modelName: automation.modelName } : {};
|
|
156
156
|
const draft = import_chat.Chat.withDefaults(loop.name);
|
|
157
|
+
draft.setTitle(automation.name);
|
|
157
158
|
draft.settings?.setExecutionMode("autonomous");
|
|
158
159
|
if (model.modelProvider) draft.settings?.setModelProvider(model.modelProvider);
|
|
159
160
|
if (model.modelName) draft.settings?.setModelName(model.modelName);
|
|
@@ -130,6 +130,7 @@ class AutomationRunner {
|
|
|
130
130
|
const agent = new Agent({ ...configured, loop });
|
|
131
131
|
const model = automation.modelProvider && automation.modelName ? { modelProvider: automation.modelProvider, modelName: automation.modelName } : {};
|
|
132
132
|
const draft = Chat.withDefaults(loop.name);
|
|
133
|
+
draft.setTitle(automation.name);
|
|
133
134
|
draft.settings?.setExecutionMode("autonomous");
|
|
134
135
|
if (model.modelProvider) draft.settings?.setModelProvider(model.modelProvider);
|
|
135
136
|
if (model.modelName) draft.settings?.setModelName(model.modelName);
|
|
@@ -35,7 +35,16 @@ function assertTimezone(timezone) {
|
|
|
35
35
|
}
|
|
36
36
|
return timezone;
|
|
37
37
|
}
|
|
38
|
+
function computeNextInterval(recurrence, timezone, from) {
|
|
39
|
+
const start = new import_croner.Cron(`${recurrence.start}:00`, { timezone }).nextRun(/* @__PURE__ */ new Date(0));
|
|
40
|
+
if (!start) return null;
|
|
41
|
+
const step = (0, import_recurrence.intervalToMinutes)(recurrence.every, recurrence.unit) * 60 * 1e3;
|
|
42
|
+
if (from.getTime() < start.getTime()) return start;
|
|
43
|
+
const elapsed = Math.floor((from.getTime() - start.getTime()) / step) + 1;
|
|
44
|
+
return new Date(start.getTime() + elapsed * step);
|
|
45
|
+
}
|
|
38
46
|
function computeNextRun(recurrence, timezone, from = /* @__PURE__ */ new Date()) {
|
|
47
|
+
if (recurrence.type === "interval") return computeNextInterval(recurrence, timezone, from);
|
|
39
48
|
const pattern = recurrence.type === "once" ? `${recurrence.at}:00` : (0, import_recurrence.toCronPattern)(recurrence);
|
|
40
49
|
const cron = new import_croner.Cron(pattern, { timezone });
|
|
41
50
|
let next = cron.nextRun(from);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Cron } from "croner";
|
|
2
|
-
import { toCronPattern } from "../entities/recurrence";
|
|
2
|
+
import { intervalToMinutes, toCronPattern } from "../entities/recurrence";
|
|
3
3
|
const MAX_PREVIEW = 20;
|
|
4
4
|
function assertTimezone(timezone) {
|
|
5
5
|
if (typeof timezone !== "string" || !timezone.trim()) throw new Error("The timezone is required");
|
|
@@ -10,7 +10,16 @@ function assertTimezone(timezone) {
|
|
|
10
10
|
}
|
|
11
11
|
return timezone;
|
|
12
12
|
}
|
|
13
|
+
function computeNextInterval(recurrence, timezone, from) {
|
|
14
|
+
const start = new Cron(`${recurrence.start}:00`, { timezone }).nextRun(/* @__PURE__ */ new Date(0));
|
|
15
|
+
if (!start) return null;
|
|
16
|
+
const step = intervalToMinutes(recurrence.every, recurrence.unit) * 60 * 1e3;
|
|
17
|
+
if (from.getTime() < start.getTime()) return start;
|
|
18
|
+
const elapsed = Math.floor((from.getTime() - start.getTime()) / step) + 1;
|
|
19
|
+
return new Date(start.getTime() + elapsed * step);
|
|
20
|
+
}
|
|
13
21
|
function computeNextRun(recurrence, timezone, from = /* @__PURE__ */ new Date()) {
|
|
22
|
+
if (recurrence.type === "interval") return computeNextInterval(recurrence, timezone, from);
|
|
14
23
|
const pattern = recurrence.type === "once" ? `${recurrence.at}:00` : toCronPattern(recurrence);
|
|
15
24
|
const cron = new Cron(pattern, { timezone });
|
|
16
25
|
let next = cron.nextRun(from);
|
package/docs/automations.md
CHANGED
|
@@ -92,10 +92,12 @@ The recurrence of a `schedule` trigger is stored as a structured value, so a scr
|
|
|
92
92
|
| `daily` | `time` | `{ type: 'daily', time: '08:00' }` |
|
|
93
93
|
| `weekly` | `days` (1 is Monday, 7 is Sunday), `time` | `{ type: 'weekly', days: [1, 2, 3, 4, 5], time: '09:30' }` is Monday to Friday |
|
|
94
94
|
| `monthly` | `day` (1 to 31 or `'last'`), `time` | `{ type: 'monthly', day: 15, time: '12:00' }` |
|
|
95
|
+
| `interval` | `every` (whole number), `unit` (`'minutes'` or `'hours'`), `start` (`YYYY-MM-DDTHH:mm`, local time) | `{ type: 'interval', every: 90, unit: 'minutes', start: '2026-10-14T08:00' }` |
|
|
95
96
|
| `once` | `at` (`YYYY-MM-DDTHH:mm`, local time) | `{ type: 'once', at: '2026-12-25T10:00' }` |
|
|
96
97
|
|
|
97
98
|
- A monthly automation on day 29, 30 or 31 is skipped in the months that do not have that day. Use `'last'` for the last day of every month.
|
|
98
99
|
- A time that does not exist on a day because of daylight saving time runs at the first valid moment of that day, and a time that happens twice runs once.
|
|
100
|
+
- An `interval` counts real minutes or hours from `start`: it runs at `start`, then every `every` units after it, with no drift and not tied to the clock, so every 7 hours from 08:00 runs at 08:00, 15:00, 22:00, 05:00... Daylight saving time does not move it. A `start` in the past is fine, the next run is the next moment of the grid. Changing `start`, `every`, `unit` or the timezone changes the grid. The shortest interval is 5 minutes (`MIN_INTERVAL_MINUTES`).
|
|
99
101
|
- An automation of type `once` runs a single time and then has no next run.
|
|
100
102
|
|
|
101
103
|
### Previewing
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openloops",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.2",
|
|
4
4
|
"description": "Open source harness for building multitenant AI agents for your SaaS: a TypeScript runtime with persistence, tools, MCP trust, approvals and autonomous automations",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Jose Barcos",
|
|
@@ -83,6 +83,18 @@
|
|
|
83
83
|
"types": "./dist/services/users/index.d.ts",
|
|
84
84
|
"default": "./dist/services/users/index.js"
|
|
85
85
|
},
|
|
86
|
+
"./tasks": {
|
|
87
|
+
"types": "./dist/services/tasks/index.d.ts",
|
|
88
|
+
"default": "./dist/services/tasks/index.js"
|
|
89
|
+
},
|
|
90
|
+
"./traces": {
|
|
91
|
+
"types": "./dist/services/traces/index.d.ts",
|
|
92
|
+
"default": "./dist/services/traces/index.js"
|
|
93
|
+
},
|
|
94
|
+
"./workspaces": {
|
|
95
|
+
"types": "./dist/services/workspaces/index.d.ts",
|
|
96
|
+
"default": "./dist/services/workspaces/index.js"
|
|
97
|
+
},
|
|
86
98
|
"./db": {
|
|
87
99
|
"types": "./dist/db/index.d.ts",
|
|
88
100
|
"default": "./dist/db/index.js"
|