openloops 0.9.1 → 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 +24 -0
- package/README.md +2 -0
- package/dist/clients/llm/llm-client.d.ts +1 -0
- package/dist/clients/llm/llm-client.js +6 -3
- package/dist/clients/llm/llm-client.mjs +6 -3
- package/dist/common/base/current-user.js +2 -1
- package/dist/common/base/current-user.mjs +2 -1
- package/dist/common/index.d.ts +3 -0
- package/dist/common/index.js +6 -0
- package/dist/common/index.mjs +4 -0
- package/dist/common/repositories/mongo-db.client.d.ts +1 -1
- package/dist/common/repositories/mongo-db.client.js +7 -6
- package/dist/common/repositories/mongo-db.client.mjs +7 -6
- package/dist/common/repositories/mongo-db.repository.d.ts +3 -2
- package/dist/common/repositories/mongo-db.repository.js +20 -16
- package/dist/common/repositories/mongo-db.repository.mjs +20 -16
- package/dist/common/utils/config-context.d.ts +3 -0
- package/dist/common/utils/config-context.js +33 -0
- package/dist/common/utils/config-context.mjs +8 -0
- package/dist/common/utils/secret-manager.d.ts +7 -5
- package/dist/common/utils/secret-manager.js +41 -28
- package/dist/common/utils/secret-manager.mjs +41 -28
- package/dist/services/authentication/repositories/refresh-token.repository.js +1 -1
- package/dist/services/authentication/repositories/refresh-token.repository.mjs +1 -1
- package/dist/services/authentication/repositories/revoked-token.repository.js +1 -1
- package/dist/services/authentication/repositories/revoked-token.repository.mjs +1 -1
- 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/repositories/automation-run.repository.js +1 -1
- package/dist/services/automations/repositories/automation-run.repository.mjs +1 -1
- package/dist/services/automations/repositories/automation.repository.js +1 -1
- package/dist/services/automations/repositories/automation.repository.mjs +1 -1
- 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/dist/services/chats/repositories/chat.repository.js +1 -1
- package/dist/services/chats/repositories/chat.repository.mjs +1 -1
- package/dist/services/llmcalls/repositories/llmcall.repository.js +1 -1
- package/dist/services/llmcalls/repositories/llmcall.repository.mjs +1 -1
- package/dist/services/mcp-servers/repositories/mcpserver.repository.js +1 -1
- package/dist/services/mcp-servers/repositories/mcpserver.repository.mjs +1 -1
- package/dist/services/tasks/repositories/agent-action.repository.js +1 -1
- package/dist/services/tasks/repositories/agent-action.repository.mjs +1 -1
- package/dist/services/tasks/repositories/agent-task.repository.js +1 -1
- package/dist/services/tasks/repositories/agent-task.repository.mjs +1 -1
- package/dist/services/traces/repositories/agent-trace.repository.js +1 -1
- package/dist/services/traces/repositories/agent-trace.repository.mjs +1 -1
- package/dist/services/users/repositories/user.repository.js +1 -1
- package/dist/services/users/repositories/user.repository.mjs +1 -1
- package/dist/services/workspaces/repositories/workspace-item.repository.js +1 -1
- package/dist/services/workspaces/repositories/workspace-item.repository.mjs +1 -1
- package/docs/README.md +1 -1
- package/docs/automations.md +2 -0
- package/docs/configuration.md +30 -1
- package/docs/integration-guide.md +1 -1
- package/docs/llms.txt +1 -1
- package/examples/run-agent/run-agent-multi-tenant.ts +52 -0
- package/package.json +13 -1
|
@@ -35,43 +35,65 @@ module.exports = __toCommonJS(secret_manager_exports);
|
|
|
35
35
|
var import_config = require("dotenv/config");
|
|
36
36
|
var import_cryptr = __toESM(require("cryptr"));
|
|
37
37
|
var import_logger = require("../logger/index.js");
|
|
38
|
+
var import_config_context = require("./config-context");
|
|
39
|
+
const VERSIONED = /^ENC:v(\d+):/;
|
|
38
40
|
class SecretManager {
|
|
39
41
|
static instance;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
envCache = /* @__PURE__ */ new Map();
|
|
43
|
+
contextCache = /* @__PURE__ */ new WeakMap();
|
|
44
|
+
cryptrs = /* @__PURE__ */ new Map();
|
|
42
45
|
static getInstance() {
|
|
43
46
|
if (!SecretManager.instance) {
|
|
44
47
|
SecretManager.instance = new SecretManager();
|
|
45
48
|
}
|
|
46
49
|
return SecretManager.instance;
|
|
47
50
|
}
|
|
48
|
-
static encrypt(value) {
|
|
51
|
+
static encrypt(value, version) {
|
|
49
52
|
if (!value) throw new Error("[Secret manager] Value to encrypt cannot be empty");
|
|
50
|
-
|
|
53
|
+
const manager = SecretManager.getInstance();
|
|
54
|
+
if (!version) return `ENC:${manager.cryptr().encrypt(value)}`;
|
|
55
|
+
return `ENC:v${version}:${manager.cryptr(version).encrypt(value)}`;
|
|
51
56
|
}
|
|
52
57
|
constructor() {
|
|
53
|
-
|
|
58
|
+
this.cryptr();
|
|
59
|
+
}
|
|
60
|
+
cryptr(version) {
|
|
61
|
+
const envName = version ? `SECRET_MANAGER_KEY_V${version}` : "SECRET_MANAGER_KEY";
|
|
62
|
+
const cached = this.cryptrs.get(envName);
|
|
63
|
+
if (cached) return cached;
|
|
64
|
+
const secretKey = process.env[envName];
|
|
54
65
|
if (!secretKey) {
|
|
55
|
-
throw new Error(
|
|
66
|
+
throw new Error(`[Secret manager] ${envName} environment variable is not set`);
|
|
56
67
|
}
|
|
57
|
-
|
|
68
|
+
const cryptr = new import_cryptr.default(secretKey, {
|
|
58
69
|
pbkdf2Iterations: 1e3,
|
|
59
70
|
saltLength: 16
|
|
60
71
|
});
|
|
72
|
+
this.cryptrs.set(envName, cryptr);
|
|
73
|
+
return cryptr;
|
|
61
74
|
}
|
|
62
75
|
get(key) {
|
|
63
76
|
const startTime = process.hrtime.bigint();
|
|
64
|
-
|
|
65
|
-
|
|
77
|
+
const configs = (0, import_config_context.getContextConfigs)();
|
|
78
|
+
const cache = configs ? this.cacheOf(configs) : this.envCache;
|
|
79
|
+
if (cache.has(key)) {
|
|
66
80
|
this.logElapsed(key, startTime, true);
|
|
67
|
-
return
|
|
81
|
+
return cache.get(key);
|
|
68
82
|
}
|
|
69
|
-
const
|
|
70
|
-
const decryptedValue = this.
|
|
71
|
-
|
|
83
|
+
const raw = configs ? configs[key] : this.getEnvVar(key);
|
|
84
|
+
const decryptedValue = this.decrypt(raw);
|
|
85
|
+
cache.set(key, decryptedValue);
|
|
72
86
|
this.logElapsed(key, startTime, false);
|
|
73
87
|
return decryptedValue;
|
|
74
88
|
}
|
|
89
|
+
cacheOf(configs) {
|
|
90
|
+
let cache = this.contextCache.get(configs);
|
|
91
|
+
if (!cache) {
|
|
92
|
+
cache = /* @__PURE__ */ new Map();
|
|
93
|
+
this.contextCache.set(configs, cache);
|
|
94
|
+
}
|
|
95
|
+
return cache;
|
|
96
|
+
}
|
|
75
97
|
getEnvVar(key) {
|
|
76
98
|
const value = process.env[key];
|
|
77
99
|
if (!value) {
|
|
@@ -80,21 +102,12 @@ class SecretManager {
|
|
|
80
102
|
}
|
|
81
103
|
return value;
|
|
82
104
|
}
|
|
83
|
-
|
|
84
|
-
if (!
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
import_logger.logger.debug("[Secret Manager] Value is not encrypted");
|
|
90
|
-
return encryptedValue;
|
|
91
|
-
}
|
|
92
|
-
const valueWithoutPrefix = encryptedValue.replace(/^ENC:/, "");
|
|
93
|
-
return this.cryptr.decrypt(valueWithoutPrefix);
|
|
94
|
-
}
|
|
95
|
-
isStringEncrypted(value) {
|
|
96
|
-
if (!value) return false;
|
|
97
|
-
return value.startsWith("ENC:");
|
|
105
|
+
decrypt(value) {
|
|
106
|
+
if (!value) return "";
|
|
107
|
+
if (!value.startsWith("ENC:")) return value;
|
|
108
|
+
const versioned = VERSIONED.exec(value);
|
|
109
|
+
if (versioned) return this.cryptr(Number(versioned[1])).decrypt(value.slice(versioned[0].length));
|
|
110
|
+
return this.cryptr().decrypt(value.replace(/^ENC:/, ""));
|
|
98
111
|
}
|
|
99
112
|
logElapsed(key, startTime, cached) {
|
|
100
113
|
const endTime = process.hrtime.bigint();
|
|
@@ -1,43 +1,65 @@
|
|
|
1
1
|
import "dotenv/config";
|
|
2
2
|
import Cryptr from "cryptr";
|
|
3
3
|
import { logger } from "../logger/index.js";
|
|
4
|
+
import { getContextConfigs } from "./config-context";
|
|
5
|
+
const VERSIONED = /^ENC:v(\d+):/;
|
|
4
6
|
class SecretManager {
|
|
5
7
|
static instance;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
envCache = /* @__PURE__ */ new Map();
|
|
9
|
+
contextCache = /* @__PURE__ */ new WeakMap();
|
|
10
|
+
cryptrs = /* @__PURE__ */ new Map();
|
|
8
11
|
static getInstance() {
|
|
9
12
|
if (!SecretManager.instance) {
|
|
10
13
|
SecretManager.instance = new SecretManager();
|
|
11
14
|
}
|
|
12
15
|
return SecretManager.instance;
|
|
13
16
|
}
|
|
14
|
-
static encrypt(value) {
|
|
17
|
+
static encrypt(value, version) {
|
|
15
18
|
if (!value) throw new Error("[Secret manager] Value to encrypt cannot be empty");
|
|
16
|
-
|
|
19
|
+
const manager = SecretManager.getInstance();
|
|
20
|
+
if (!version) return `ENC:${manager.cryptr().encrypt(value)}`;
|
|
21
|
+
return `ENC:v${version}:${manager.cryptr(version).encrypt(value)}`;
|
|
17
22
|
}
|
|
18
23
|
constructor() {
|
|
19
|
-
|
|
24
|
+
this.cryptr();
|
|
25
|
+
}
|
|
26
|
+
cryptr(version) {
|
|
27
|
+
const envName = version ? `SECRET_MANAGER_KEY_V${version}` : "SECRET_MANAGER_KEY";
|
|
28
|
+
const cached = this.cryptrs.get(envName);
|
|
29
|
+
if (cached) return cached;
|
|
30
|
+
const secretKey = process.env[envName];
|
|
20
31
|
if (!secretKey) {
|
|
21
|
-
throw new Error(
|
|
32
|
+
throw new Error(`[Secret manager] ${envName} environment variable is not set`);
|
|
22
33
|
}
|
|
23
|
-
|
|
34
|
+
const cryptr = new Cryptr(secretKey, {
|
|
24
35
|
pbkdf2Iterations: 1e3,
|
|
25
36
|
saltLength: 16
|
|
26
37
|
});
|
|
38
|
+
this.cryptrs.set(envName, cryptr);
|
|
39
|
+
return cryptr;
|
|
27
40
|
}
|
|
28
41
|
get(key) {
|
|
29
42
|
const startTime = process.hrtime.bigint();
|
|
30
|
-
|
|
31
|
-
|
|
43
|
+
const configs = getContextConfigs();
|
|
44
|
+
const cache = configs ? this.cacheOf(configs) : this.envCache;
|
|
45
|
+
if (cache.has(key)) {
|
|
32
46
|
this.logElapsed(key, startTime, true);
|
|
33
|
-
return
|
|
47
|
+
return cache.get(key);
|
|
34
48
|
}
|
|
35
|
-
const
|
|
36
|
-
const decryptedValue = this.
|
|
37
|
-
|
|
49
|
+
const raw = configs ? configs[key] : this.getEnvVar(key);
|
|
50
|
+
const decryptedValue = this.decrypt(raw);
|
|
51
|
+
cache.set(key, decryptedValue);
|
|
38
52
|
this.logElapsed(key, startTime, false);
|
|
39
53
|
return decryptedValue;
|
|
40
54
|
}
|
|
55
|
+
cacheOf(configs) {
|
|
56
|
+
let cache = this.contextCache.get(configs);
|
|
57
|
+
if (!cache) {
|
|
58
|
+
cache = /* @__PURE__ */ new Map();
|
|
59
|
+
this.contextCache.set(configs, cache);
|
|
60
|
+
}
|
|
61
|
+
return cache;
|
|
62
|
+
}
|
|
41
63
|
getEnvVar(key) {
|
|
42
64
|
const value = process.env[key];
|
|
43
65
|
if (!value) {
|
|
@@ -46,21 +68,12 @@ class SecretManager {
|
|
|
46
68
|
}
|
|
47
69
|
return value;
|
|
48
70
|
}
|
|
49
|
-
|
|
50
|
-
if (!
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
logger.debug("[Secret Manager] Value is not encrypted");
|
|
56
|
-
return encryptedValue;
|
|
57
|
-
}
|
|
58
|
-
const valueWithoutPrefix = encryptedValue.replace(/^ENC:/, "");
|
|
59
|
-
return this.cryptr.decrypt(valueWithoutPrefix);
|
|
60
|
-
}
|
|
61
|
-
isStringEncrypted(value) {
|
|
62
|
-
if (!value) return false;
|
|
63
|
-
return value.startsWith("ENC:");
|
|
71
|
+
decrypt(value) {
|
|
72
|
+
if (!value) return "";
|
|
73
|
+
if (!value.startsWith("ENC:")) return value;
|
|
74
|
+
const versioned = VERSIONED.exec(value);
|
|
75
|
+
if (versioned) return this.cryptr(Number(versioned[1])).decrypt(value.slice(versioned[0].length));
|
|
76
|
+
return this.cryptr().decrypt(value.replace(/^ENC:/, ""));
|
|
64
77
|
}
|
|
65
78
|
logElapsed(key, startTime, cached) {
|
|
66
79
|
const endTime = process.hrtime.bigint();
|
|
@@ -25,7 +25,7 @@ var import_repositories = require("../../../common/repositories/index.js");
|
|
|
25
25
|
var import_database_name = require("../../../common/utils/database-name.js");
|
|
26
26
|
class RefreshTokenRepository {
|
|
27
27
|
_ = new import_repositories.MongoRepository({
|
|
28
|
-
database:
|
|
28
|
+
database: import_database_name.getDatabaseName,
|
|
29
29
|
collection: "refresh_tokens",
|
|
30
30
|
scoped: true,
|
|
31
31
|
ownerField: "userId"
|
|
@@ -2,7 +2,7 @@ import { MongoRepository } from "../../../common/repositories/index.js";
|
|
|
2
2
|
import { getDatabaseName } from "../../../common/utils/database-name.js";
|
|
3
3
|
class RefreshTokenRepository {
|
|
4
4
|
_ = new MongoRepository({
|
|
5
|
-
database: getDatabaseName
|
|
5
|
+
database: getDatabaseName,
|
|
6
6
|
collection: "refresh_tokens",
|
|
7
7
|
scoped: true,
|
|
8
8
|
ownerField: "userId"
|
|
@@ -25,7 +25,7 @@ var import_repositories = require("../../../common/repositories/index.js");
|
|
|
25
25
|
var import_database_name = require("../../../common/utils/database-name.js");
|
|
26
26
|
class RevokedTokenRepository {
|
|
27
27
|
_ = new import_repositories.MongoRepository({
|
|
28
|
-
database:
|
|
28
|
+
database: import_database_name.getDatabaseName,
|
|
29
29
|
collection: "revoked_tokens",
|
|
30
30
|
scoped: true
|
|
31
31
|
});
|
|
@@ -2,7 +2,7 @@ import { MongoRepository } from "../../../common/repositories/index.js";
|
|
|
2
2
|
import { getDatabaseName } from "../../../common/utils/database-name.js";
|
|
3
3
|
class RevokedTokenRepository {
|
|
4
4
|
_ = new MongoRepository({
|
|
5
|
-
database: getDatabaseName
|
|
5
|
+
database: getDatabaseName,
|
|
6
6
|
collection: "revoked_tokens",
|
|
7
7
|
scoped: true
|
|
8
8
|
});
|
|
@@ -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
|
};
|
|
@@ -27,7 +27,7 @@ var import_repositories = require("../../../common/repositories/index.js");
|
|
|
27
27
|
var import_database_name = require("../../../common/utils/database-name.js");
|
|
28
28
|
class AutomationRunRepository {
|
|
29
29
|
_ = new import_repositories.MongoRepository({
|
|
30
|
-
database:
|
|
30
|
+
database: import_database_name.getDatabaseName,
|
|
31
31
|
collection: "automation_runs",
|
|
32
32
|
scoped: true
|
|
33
33
|
});
|
|
@@ -4,7 +4,7 @@ import { MongoRepository } from "../../../common/repositories/index.js";
|
|
|
4
4
|
import { getDatabaseName } from "../../../common/utils/database-name.js";
|
|
5
5
|
class AutomationRunRepository {
|
|
6
6
|
_ = new MongoRepository({
|
|
7
|
-
database: getDatabaseName
|
|
7
|
+
database: getDatabaseName,
|
|
8
8
|
collection: "automation_runs",
|
|
9
9
|
scoped: true
|
|
10
10
|
});
|
|
@@ -27,7 +27,7 @@ var import_repositories = require("../../../common/repositories/index.js");
|
|
|
27
27
|
var import_database_name = require("../../../common/utils/database-name.js");
|
|
28
28
|
class AutomationRepository {
|
|
29
29
|
_ = new import_repositories.MongoRepository({
|
|
30
|
-
database:
|
|
30
|
+
database: import_database_name.getDatabaseName,
|
|
31
31
|
collection: "automations",
|
|
32
32
|
scoped: true
|
|
33
33
|
});
|
|
@@ -4,7 +4,7 @@ import { MongoRepository } from "../../../common/repositories/index.js";
|
|
|
4
4
|
import { getDatabaseName } from "../../../common/utils/database-name.js";
|
|
5
5
|
class AutomationRepository {
|
|
6
6
|
_ = new MongoRepository({
|
|
7
|
-
database: getDatabaseName
|
|
7
|
+
database: getDatabaseName,
|
|
8
8
|
collection: "automations",
|
|
9
9
|
scoped: true
|
|
10
10
|
});
|
|
@@ -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);
|
|
@@ -26,7 +26,7 @@ var import_repositories = require("../../../common/repositories/index.js");
|
|
|
26
26
|
var import_database_name = require("../../../common/utils/database-name.js");
|
|
27
27
|
class ChatRepository {
|
|
28
28
|
_ = new import_repositories.MongoRepository({
|
|
29
|
-
database:
|
|
29
|
+
database: import_database_name.getDatabaseName,
|
|
30
30
|
collection: "chats",
|
|
31
31
|
scoped: true
|
|
32
32
|
});
|
|
@@ -3,7 +3,7 @@ import { MongoRepository } from "../../../common/repositories/index.js";
|
|
|
3
3
|
import { getDatabaseName } from "../../../common/utils/database-name.js";
|
|
4
4
|
class ChatRepository {
|
|
5
5
|
_ = new MongoRepository({
|
|
6
|
-
database: getDatabaseName
|
|
6
|
+
database: getDatabaseName,
|
|
7
7
|
collection: "chats",
|
|
8
8
|
scoped: true
|
|
9
9
|
});
|
|
@@ -26,7 +26,7 @@ var import_repositories = require("../../../common/repositories/index.js");
|
|
|
26
26
|
var import_database_name = require("../../../common/utils/database-name.js");
|
|
27
27
|
class LLMCallRepository {
|
|
28
28
|
_ = new import_repositories.MongoRepository({
|
|
29
|
-
database:
|
|
29
|
+
database: import_database_name.getDatabaseName,
|
|
30
30
|
collection: "llm_calls",
|
|
31
31
|
scoped: true
|
|
32
32
|
});
|
|
@@ -3,7 +3,7 @@ import { MongoRepository } from "../../../common/repositories/index.js";
|
|
|
3
3
|
import { getDatabaseName } from "../../../common/utils/database-name.js";
|
|
4
4
|
class LLMCallRepository {
|
|
5
5
|
_ = new MongoRepository({
|
|
6
|
-
database: getDatabaseName
|
|
6
|
+
database: getDatabaseName,
|
|
7
7
|
collection: "llm_calls",
|
|
8
8
|
scoped: true
|
|
9
9
|
});
|
|
@@ -28,7 +28,7 @@ var import_database_name = require("../../../common/utils/database-name.js");
|
|
|
28
28
|
const external = (where) => ({ ...where, internal: { $ne: true } });
|
|
29
29
|
class McpServerRepository {
|
|
30
30
|
_ = new import_repositories.MongoRepository({
|
|
31
|
-
database:
|
|
31
|
+
database: import_database_name.getDatabaseName,
|
|
32
32
|
collection: "mcp_servers",
|
|
33
33
|
scoped: true
|
|
34
34
|
});
|
|
@@ -5,7 +5,7 @@ import { getDatabaseName } from "../../../common/utils/database-name.js";
|
|
|
5
5
|
const external = (where) => ({ ...where, internal: { $ne: true } });
|
|
6
6
|
class McpServerRepository {
|
|
7
7
|
_ = new MongoRepository({
|
|
8
|
-
database: getDatabaseName
|
|
8
|
+
database: getDatabaseName,
|
|
9
9
|
collection: "mcp_servers",
|
|
10
10
|
scoped: true
|
|
11
11
|
});
|
|
@@ -26,7 +26,7 @@ var import_repositories = require("../../../common/repositories/index.js");
|
|
|
26
26
|
var import_database_name = require("../../../common/utils/database-name.js");
|
|
27
27
|
class AgentActionRepository {
|
|
28
28
|
_ = new import_repositories.MongoRepository({
|
|
29
|
-
database:
|
|
29
|
+
database: import_database_name.getDatabaseName,
|
|
30
30
|
collection: "agent_actions",
|
|
31
31
|
scoped: true
|
|
32
32
|
});
|
|
@@ -3,7 +3,7 @@ import { MongoRepository } from "../../../common/repositories/index.js";
|
|
|
3
3
|
import { getDatabaseName } from "../../../common/utils/database-name.js";
|
|
4
4
|
class AgentActionRepository {
|
|
5
5
|
_ = new MongoRepository({
|
|
6
|
-
database: getDatabaseName
|
|
6
|
+
database: getDatabaseName,
|
|
7
7
|
collection: "agent_actions",
|
|
8
8
|
scoped: true
|
|
9
9
|
});
|
|
@@ -26,7 +26,7 @@ var import_repositories = require("../../../common/repositories/index.js");
|
|
|
26
26
|
var import_database_name = require("../../../common/utils/database-name.js");
|
|
27
27
|
class AgentTaskRepository {
|
|
28
28
|
_ = new import_repositories.MongoRepository({
|
|
29
|
-
database:
|
|
29
|
+
database: import_database_name.getDatabaseName,
|
|
30
30
|
collection: "agent_tasks",
|
|
31
31
|
scoped: true
|
|
32
32
|
});
|
|
@@ -3,7 +3,7 @@ import { MongoRepository } from "../../../common/repositories/index.js";
|
|
|
3
3
|
import { getDatabaseName } from "../../../common/utils/database-name.js";
|
|
4
4
|
class AgentTaskRepository {
|
|
5
5
|
_ = new MongoRepository({
|
|
6
|
-
database: getDatabaseName
|
|
6
|
+
database: getDatabaseName,
|
|
7
7
|
collection: "agent_tasks",
|
|
8
8
|
scoped: true
|
|
9
9
|
});
|
|
@@ -25,7 +25,7 @@ var import_repositories = require("../../../common/repositories/index.js");
|
|
|
25
25
|
var import_database_name = require("../../../common/utils/database-name.js");
|
|
26
26
|
class AgentTraceRepository {
|
|
27
27
|
_ = new import_repositories.MongoRepository({
|
|
28
|
-
database:
|
|
28
|
+
database: import_database_name.getDatabaseName,
|
|
29
29
|
collection: "agent_traces",
|
|
30
30
|
scoped: true
|
|
31
31
|
});
|
|
@@ -2,7 +2,7 @@ import { MongoRepository } from "../../../common/repositories/index.js";
|
|
|
2
2
|
import { getDatabaseName } from "../../../common/utils/database-name.js";
|
|
3
3
|
class AgentTraceRepository {
|
|
4
4
|
_ = new MongoRepository({
|
|
5
|
-
database: getDatabaseName
|
|
5
|
+
database: getDatabaseName,
|
|
6
6
|
collection: "agent_traces",
|
|
7
7
|
scoped: true
|
|
8
8
|
});
|