openloops 0.1.38 → 0.1.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -2
- package/dist/services/agentic-jobs/entities/agentic-job-run.entity.d.ts +42 -0
- package/dist/services/agentic-jobs/entities/agentic-job-run.entity.js +103 -0
- package/dist/services/agentic-jobs/entities/agentic-job-run.entity.mjs +80 -0
- package/dist/services/agentic-jobs/entities/agentic-job.entity.d.ts +39 -0
- package/dist/services/agentic-jobs/entities/agentic-job.entity.js +113 -0
- package/dist/services/agentic-jobs/entities/agentic-job.entity.mjs +90 -0
- package/dist/services/agentic-jobs/entities/index.d.ts +3 -0
- package/dist/services/agentic-jobs/entities/index.js +26 -0
- package/dist/services/agentic-jobs/entities/index.mjs +3 -0
- package/dist/services/agentic-jobs/entities/recurrence.d.ts +18 -0
- package/dist/services/agentic-jobs/entities/recurrence.js +84 -0
- package/dist/services/agentic-jobs/entities/recurrence.mjs +59 -0
- package/dist/services/agentic-jobs/index.d.ts +4 -0
- package/dist/services/agentic-jobs/index.js +28 -0
- package/dist/services/agentic-jobs/index.mjs +4 -0
- package/dist/services/agentic-jobs/module.d.ts +31 -0
- package/dist/services/agentic-jobs/module.js +132 -0
- package/dist/services/agentic-jobs/module.mjs +95 -0
- package/dist/services/agentic-jobs/repositories/agentic-job-run.repository.d.ts +11 -0
- package/dist/services/agentic-jobs/repositories/agentic-job-run.repository.js +71 -0
- package/dist/services/agentic-jobs/repositories/agentic-job-run.repository.mjs +42 -0
- package/dist/services/agentic-jobs/repositories/agentic-job.repository.d.ts +27 -0
- package/dist/services/agentic-jobs/repositories/agentic-job.repository.js +127 -0
- package/dist/services/agentic-jobs/repositories/agentic-job.repository.mjs +98 -0
- package/dist/services/agentic-jobs/repositories/index.d.ts +2 -0
- package/dist/services/agentic-jobs/repositories/index.js +24 -0
- package/dist/services/agentic-jobs/repositories/index.mjs +2 -0
- package/dist/services/agentic-jobs/runner/agentic-job-runner.d.ts +48 -0
- package/dist/services/agentic-jobs/runner/agentic-job-runner.js +181 -0
- package/dist/services/agentic-jobs/runner/agentic-job-runner.mjs +157 -0
- package/dist/services/agentic-jobs/use-cases/attach-agentic-job-run-chat.use-case.d.ts +15 -0
- package/dist/services/agentic-jobs/use-cases/attach-agentic-job-run-chat.use-case.js +58 -0
- package/dist/services/agentic-jobs/use-cases/attach-agentic-job-run-chat.use-case.mjs +29 -0
- package/dist/services/agentic-jobs/use-cases/claim-due-agentic-jobs.use-case.d.ts +29 -0
- package/dist/services/agentic-jobs/use-cases/claim-due-agentic-jobs.use-case.js +110 -0
- package/dist/services/agentic-jobs/use-cases/claim-due-agentic-jobs.use-case.mjs +81 -0
- package/dist/services/agentic-jobs/use-cases/create-agentic-job.use-case.d.ts +14 -0
- package/dist/services/agentic-jobs/use-cases/create-agentic-job.use-case.js +73 -0
- package/dist/services/agentic-jobs/use-cases/create-agentic-job.use-case.mjs +44 -0
- package/dist/services/agentic-jobs/use-cases/delete-agentic-job.use-case.d.ts +15 -0
- package/dist/services/agentic-jobs/use-cases/delete-agentic-job.use-case.js +65 -0
- package/dist/services/agentic-jobs/use-cases/delete-agentic-job.use-case.mjs +36 -0
- package/dist/services/agentic-jobs/use-cases/finish-agentic-job-run.use-case.d.ts +19 -0
- package/dist/services/agentic-jobs/use-cases/finish-agentic-job-run.use-case.js +75 -0
- package/dist/services/agentic-jobs/use-cases/finish-agentic-job-run.use-case.mjs +46 -0
- package/dist/services/agentic-jobs/use-cases/get-agentic-job-by-id.use-case.d.ts +14 -0
- package/dist/services/agentic-jobs/use-cases/get-agentic-job-by-id.use-case.js +55 -0
- package/dist/services/agentic-jobs/use-cases/get-agentic-job-by-id.use-case.mjs +26 -0
- package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-job.use-case.d.ts +16 -0
- package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-job.use-case.js +57 -0
- package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-job.use-case.mjs +28 -0
- package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-user.use-case.d.ts +16 -0
- package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-user.use-case.js +57 -0
- package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-user.use-case.mjs +28 -0
- package/dist/services/agentic-jobs/use-cases/list-agentic-jobs-by-user.use-case.d.ts +15 -0
- package/dist/services/agentic-jobs/use-cases/list-agentic-jobs-by-user.use-case.js +57 -0
- package/dist/services/agentic-jobs/use-cases/list-agentic-jobs-by-user.use-case.mjs +28 -0
- package/dist/services/agentic-jobs/use-cases/preview-agentic-job-runs.use-case.d.ts +15 -0
- package/dist/services/agentic-jobs/use-cases/preview-agentic-job-runs.use-case.js +52 -0
- package/dist/services/agentic-jobs/use-cases/preview-agentic-job-runs.use-case.mjs +23 -0
- package/dist/services/agentic-jobs/use-cases/renew-agentic-job-lease.use-case.d.ts +18 -0
- package/dist/services/agentic-jobs/use-cases/renew-agentic-job-lease.use-case.js +58 -0
- package/dist/services/agentic-jobs/use-cases/renew-agentic-job-lease.use-case.mjs +29 -0
- package/dist/services/agentic-jobs/use-cases/start-agentic-job-run.use-case.d.ts +21 -0
- package/dist/services/agentic-jobs/use-cases/start-agentic-job-run.use-case.js +67 -0
- package/dist/services/agentic-jobs/use-cases/start-agentic-job-run.use-case.mjs +38 -0
- package/dist/services/agentic-jobs/use-cases/sync-agentic-job-run.use-case.d.ts +20 -0
- package/dist/services/agentic-jobs/use-cases/sync-agentic-job-run.use-case.js +86 -0
- package/dist/services/agentic-jobs/use-cases/sync-agentic-job-run.use-case.mjs +56 -0
- package/dist/services/agentic-jobs/use-cases/sync-agentic-job-runs.use-case.d.ts +19 -0
- package/dist/services/agentic-jobs/use-cases/sync-agentic-job-runs.use-case.js +68 -0
- package/dist/services/agentic-jobs/use-cases/sync-agentic-job-runs.use-case.mjs +39 -0
- package/dist/services/agentic-jobs/use-cases/update-agentic-job.use-case.d.ts +15 -0
- package/dist/services/agentic-jobs/use-cases/update-agentic-job.use-case.js +83 -0
- package/dist/services/agentic-jobs/use-cases/update-agentic-job.use-case.mjs +54 -0
- package/dist/services/agentic-jobs/utils/job-fields.d.ts +14 -0
- package/dist/services/agentic-jobs/utils/job-fields.js +61 -0
- package/dist/services/agentic-jobs/utils/job-fields.mjs +37 -0
- package/dist/services/agentic-jobs/utils/next-run.d.ts +4 -0
- package/dist/services/agentic-jobs/utils/next-run.js +62 -0
- package/dist/services/agentic-jobs/utils/next-run.mjs +37 -0
- package/dist/services/agentic-jobs/utils/open-run.d.ts +12 -0
- package/dist/services/agentic-jobs/utils/open-run.js +47 -0
- package/dist/services/agentic-jobs/utils/open-run.mjs +24 -0
- package/dist/services/agentic-jobs/utils/settings.d.ts +2 -0
- package/dist/services/agentic-jobs/utils/settings.js +34 -0
- package/dist/services/agentic-jobs/utils/settings.mjs +10 -0
- package/docs/README.md +46 -0
- package/docs/agent.md +201 -0
- package/docs/agentic-jobs.md +207 -0
- package/docs/authentication.md +40 -0
- package/docs/chats.md +88 -0
- package/docs/configuration.md +69 -0
- package/docs/guardrails.md +71 -0
- package/docs/harness.md +81 -0
- package/docs/integration-guide.md +138 -0
- package/docs/llms.txt +35 -0
- package/docs/loops.md +147 -0
- package/docs/mcp-servers.md +148 -0
- package/docs/skills.md +104 -0
- package/docs/tools.md +90 -0
- package/docs/usage.md +86 -0
- package/docs/users.md +85 -0
- package/examples/agentic-jobs/create-agentic-job.ts +24 -0
- package/examples/agentic-jobs/list-agentic-job-runs.ts +28 -0
- package/examples/agentic-jobs/list-agentic-jobs.ts +25 -0
- package/examples/agentic-jobs/preview-agentic-job-runs.ts +16 -0
- package/examples/agentic-jobs/run-agentic-job-now.ts +19 -0
- package/examples/agentic-jobs/run-agentic-job-worker.ts +29 -0
- package/examples/agentic-jobs/update-agentic-job.ts +36 -0
- package/examples/authentication/login.ts +17 -0
- package/examples/chats/delete-chat.ts +32 -0
- package/examples/chats/get-chat-by-id.ts +32 -0
- package/examples/chats/list-autonomous-chats.ts +23 -0
- package/examples/chats/list-chats.ts +20 -0
- package/examples/guardrails/custom-guard.ts +11 -0
- package/examples/loops/custom-loop.ts +50 -0
- package/examples/mcps/create-mcp.ts +24 -0
- package/examples/mcps/decide-mcp.ts +40 -0
- package/examples/mcps/delete-mcp.ts +32 -0
- package/examples/mcps/get-mcp-by-id.ts +17 -0
- package/examples/mcps/list-all-mcps.ts +14 -0
- package/examples/mcps/list-user-mcps.ts +23 -0
- package/examples/mcps/update-mcp.ts +23 -0
- package/examples/mcps/verify-mcp.ts +17 -0
- package/examples/run-agent/interrupt-agent.ts +16 -0
- package/examples/run-agent/run-agent-autonomous.ts +34 -0
- package/examples/run-agent/run-agent-strict-mode.ts +30 -0
- package/examples/run-agent/run-agent-with-confirmation.ts +49 -0
- package/examples/run-agent/run-agent-with-guards.ts +33 -0
- package/examples/run-agent/run-agent-with-hooks.ts +55 -0
- package/examples/run-agent/run-agent-with-identity.ts +36 -0
- package/examples/run-agent/run-agent-with-model.ts +33 -0
- package/examples/run-agent/run-agent-with-tools.ts +31 -0
- package/examples/tools/basic-tool.ts +35 -0
- package/examples/tools/destructive-tool.ts +34 -0
- package/examples/tools/web-search-tool.ts +37 -0
- package/examples/usage/get-chat-usage.ts +22 -0
- package/examples/usage/get-message-usage.ts +22 -0
- package/examples/usage/get-usage-stats-by-range.ts +23 -0
- package/examples/usage/get-usage-stats.ts +18 -0
- package/examples/users/create-user.ts +19 -0
- package/examples/users/delete-user.ts +36 -0
- package/examples/users/get-user-by-id.ts +18 -0
- package/examples/users/list-users.ts +18 -0
- package/examples/users/update-user.ts +22 -0
- package/package.json +9 -2
package/README.md
CHANGED
|
@@ -22,6 +22,19 @@ logger.info(result.data.lastAnswer, '[Demo] Result')
|
|
|
22
22
|
|
|
23
23
|
That's it. The agent is persisted, resumable, and scoped to that one user, with tool execution, guardrails, and observability already wired in. No message table to design, no state machine to debug by hand, no MCP adapter to write.
|
|
24
24
|
|
|
25
|
+
## Building a backend with it
|
|
26
|
+
|
|
27
|
+
If you or your coding agent are going to build the backend that uses `openloops`, start with the [integration guide](docs/integration-guide.md). It lists which endpoint calls which use case, what authorization is left to you (the package has no HTTP layer), how to run agents and scheduled jobs, and a security checklist. The whole documentation is also shipped inside the package, in `node_modules/openloops/docs`, with an index for tools in [`docs/llms.txt`](docs/llms.txt).
|
|
28
|
+
|
|
29
|
+
To make sure that your coding agent reads it in every session, add this to the `CLAUDE.md` or `AGENTS.md` of your backend:
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
This project uses the `openloops` package. Before writing code that uses it, read
|
|
33
|
+
`node_modules/openloops/docs/integration-guide.md`. Its full documentation is in
|
|
34
|
+
`node_modules/openloops/docs` and its examples are in `node_modules/openloops/examples`.
|
|
35
|
+
The package has no controllers: the authorization of every endpoint is the responsibility of this backend.
|
|
36
|
+
```
|
|
37
|
+
|
|
25
38
|
## Pick a loop, or write your own
|
|
26
39
|
|
|
27
40
|
The logic that makes your agent *your* agent (how it reasons, when it asks for confirmation, whether it answers in one shot or works through a sequence of tools) lives in an `AgentLoop`. `openloops` ships `AgiLoop`, a reasoning loop that answers directly when it can and otherwise works in cycles of think, act and observe until it has a final answer. Any loop, yours or someone else's, is interchangeable.
|
|
@@ -59,6 +72,7 @@ You know the pattern: before you write a single line of what your agent actually
|
|
|
59
72
|
- **Safe tool execution.** Arguments are validated against the tool's schema, destructive tools wait for the user's confirmation, identical failing calls are blocked, identifiers the model invented are rejected before they reach a real system, and large outputs are kept out of the prompt. LLM calls retry with backoff and wait out rate limits.
|
|
60
73
|
- **Native MCP support with a trust flow.** Connect any MCP server and its tools become regular tools. Each server must be approved by the user before its first tool runs, and a server that changes its tools is reviewed again, so a third party cannot quietly change what your agent does.
|
|
61
74
|
- **Autonomous runs.** The same agent can work without a person in the chat, for scheduled tasks. Whatever needs the user pauses the run in the chat, and the user answers there to continue. See [autonomous mode](docs/agent.md#autonomous-mode).
|
|
75
|
+
- **Agentic jobs.** Schedule tasks that the agent runs by itself, daily, weekly, monthly or once, in the timezone of the user. A worker runs what is due, safely across several instances, and keeps a history of every run with its chat. See [agentic jobs](docs/agentic-jobs.md).
|
|
62
76
|
- **Guardrails.** Input guards block messages with card numbers, emails, code or anything you define, before the model sees them. See [guardrails](docs/guardrails.md).
|
|
63
77
|
- **Usage and cost tracking.** Every LLM call is recorded. Get the tokens and cost of a chat or an answer, and per-user statistics by model and by period. See [usage](docs/usage.md).
|
|
64
78
|
- **Users and authentication included.** User management and login with tokens, so you don't need a parallel system just to have an identity to hand the `Agent`.
|
|
@@ -166,7 +180,9 @@ GEMINI_API_KEY=
|
|
|
166
180
|
# Required for login
|
|
167
181
|
JWT_SECRET=
|
|
168
182
|
|
|
169
|
-
# Optional
|
|
183
|
+
# Optional, in milliseconds, see docs/configuration.md
|
|
184
|
+
AGENTIC_JOBS_POLL_INTERVAL_MS=
|
|
185
|
+
AGENTIC_JOBS_LEASE_MS=
|
|
170
186
|
LLM_CALL_TIMEOUT_MS=
|
|
171
187
|
MCP_TOOL_TIMEOUT_MS=
|
|
172
188
|
|
|
@@ -199,7 +215,7 @@ Neither requires any code changes. They're opt-in purely through environment var
|
|
|
199
215
|
|
|
200
216
|
## More examples
|
|
201
217
|
|
|
202
|
-
Every pattern above, and a lot more, lives as a runnable example in [`examples/`](examples), organized by domain: `run-agent`, `loops`, `tools`, `guardrails`, `mcps`, `chats`, `usage`, `users`, and `authentication`.
|
|
218
|
+
Every pattern above, and a lot more, lives as a runnable example in [`examples/`](examples), organized by domain: `run-agent`, `loops`, `tools`, `guardrails`, `agentic-jobs`, `mcps`, `chats`, `usage`, `users`, and `authentication`.
|
|
203
219
|
|
|
204
220
|
## Package structure
|
|
205
221
|
|
|
@@ -213,6 +229,7 @@ Every pattern above, and a lot more, lives as a runnable example in [`examples/`
|
|
|
213
229
|
| `openloops/skills` | `Skill`, for writing LLM-backed reasoning steps inside a loop |
|
|
214
230
|
| `openloops/guardrails` | `Guard` and the ready-made input guards |
|
|
215
231
|
| `openloops/mcps` | MCP server management, connection check and trust decisions |
|
|
232
|
+
| `openloops/agentic-jobs` | Scheduled tasks, their runs and the runner that executes them |
|
|
216
233
|
| `openloops/chats` | Chats and their messages: list, read, update, delete |
|
|
217
234
|
| `openloops/users` | User management |
|
|
218
235
|
| `openloops/authentication` | Login and token issuing |
|
|
@@ -223,6 +240,7 @@ Every pattern above, and a lot more, lives as a runnable example in [`examples/`
|
|
|
223
240
|
|
|
224
241
|
## Learn more
|
|
225
242
|
|
|
243
|
+
- [Integration guide](docs/integration-guide.md)
|
|
226
244
|
- [Documentation index](docs/README.md)
|
|
227
245
|
- [The `Agent` runtime](docs/agent.md)
|
|
228
246
|
- [Building an `AgentLoop`](docs/loops.md)
|
|
@@ -231,6 +249,7 @@ Every pattern above, and a lot more, lives as a runnable example in [`examples/`
|
|
|
231
249
|
- [Skills](docs/skills.md)
|
|
232
250
|
- [Guardrails](docs/guardrails.md)
|
|
233
251
|
- [MCP servers](docs/mcp-servers.md)
|
|
252
|
+
- [Agentic jobs](docs/agentic-jobs.md)
|
|
234
253
|
- [Chats](docs/chats.md)
|
|
235
254
|
- [User management](docs/users.md)
|
|
236
255
|
- [Authentication](docs/authentication.md)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ObjectId } from 'mongodb';
|
|
2
|
+
import { BaseEntity, BaseEntityProps } from '../../../common/base/base.entity.js';
|
|
3
|
+
export type AgenticJobRunStatus = 'running' | 'completed' | 'paused' | 'failed' | 'skipped';
|
|
4
|
+
export type AgenticJobRunTrigger = 'schedule' | 'manual';
|
|
5
|
+
export interface AgenticJobRunError {
|
|
6
|
+
code?: string;
|
|
7
|
+
message: string;
|
|
8
|
+
}
|
|
9
|
+
export interface AgenticJobRunProps extends BaseEntityProps {
|
|
10
|
+
jobId?: string | ObjectId;
|
|
11
|
+
chatId?: string | ObjectId;
|
|
12
|
+
trigger?: AgenticJobRunTrigger;
|
|
13
|
+
status?: AgenticJobRunStatus;
|
|
14
|
+
scheduledFor?: string | Date;
|
|
15
|
+
startedAt?: string | Date;
|
|
16
|
+
finishedAt?: string | Date;
|
|
17
|
+
instructions?: string;
|
|
18
|
+
modelProvider?: string;
|
|
19
|
+
modelName?: string;
|
|
20
|
+
error?: AgenticJobRunError;
|
|
21
|
+
skipReason?: string;
|
|
22
|
+
workerId?: string;
|
|
23
|
+
}
|
|
24
|
+
export declare class AgenticJobRun extends BaseEntity {
|
|
25
|
+
private readonly props;
|
|
26
|
+
jobId?: ObjectId | undefined;
|
|
27
|
+
chatId?: ObjectId | undefined;
|
|
28
|
+
trigger?: AgenticJobRunTrigger | undefined;
|
|
29
|
+
status?: AgenticJobRunStatus | undefined;
|
|
30
|
+
scheduledFor?: Date | undefined;
|
|
31
|
+
startedAt?: Date | undefined;
|
|
32
|
+
finishedAt?: Date | undefined;
|
|
33
|
+
instructions?: string | undefined;
|
|
34
|
+
modelProvider?: string | undefined;
|
|
35
|
+
modelName?: string | undefined;
|
|
36
|
+
error?: AgenticJobRunError | undefined;
|
|
37
|
+
skipReason?: string | undefined;
|
|
38
|
+
workerId?: string | undefined;
|
|
39
|
+
static fromJSON(props: AgenticJobRunProps): AgenticJobRun;
|
|
40
|
+
constructor(props: AgenticJobRunProps, jobId?: ObjectId | undefined, chatId?: ObjectId | undefined, trigger?: AgenticJobRunTrigger | undefined, status?: AgenticJobRunStatus | undefined, scheduledFor?: Date | undefined, startedAt?: Date | undefined, finishedAt?: Date | undefined, instructions?: string | undefined, modelProvider?: string | undefined, modelName?: string | undefined, error?: AgenticJobRunError | undefined, skipReason?: string | undefined, workerId?: string | undefined);
|
|
41
|
+
toJSON(): AgenticJobRunProps;
|
|
42
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var agentic_job_run_entity_exports = {};
|
|
20
|
+
__export(agentic_job_run_entity_exports, {
|
|
21
|
+
AgenticJobRun: () => AgenticJobRun
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(agentic_job_run_entity_exports);
|
|
24
|
+
var import_base = require("../../../common/base/base.entity.js");
|
|
25
|
+
const toDate = (value) => {
|
|
26
|
+
if (!value) return void 0;
|
|
27
|
+
const date = new Date(value);
|
|
28
|
+
if (Number.isNaN(date.getTime())) throw new Error("{{value_must_be_a_date}}");
|
|
29
|
+
return date;
|
|
30
|
+
};
|
|
31
|
+
class AgenticJobRun extends import_base.BaseEntity {
|
|
32
|
+
constructor(props, jobId, chatId, trigger, status, scheduledFor, startedAt, finishedAt, instructions, modelProvider, modelName, error, skipReason, workerId) {
|
|
33
|
+
super(props);
|
|
34
|
+
this.props = props;
|
|
35
|
+
this.jobId = jobId;
|
|
36
|
+
this.chatId = chatId;
|
|
37
|
+
this.trigger = trigger;
|
|
38
|
+
this.status = status;
|
|
39
|
+
this.scheduledFor = scheduledFor;
|
|
40
|
+
this.startedAt = startedAt;
|
|
41
|
+
this.finishedAt = finishedAt;
|
|
42
|
+
this.instructions = instructions;
|
|
43
|
+
this.modelProvider = modelProvider;
|
|
44
|
+
this.modelName = modelName;
|
|
45
|
+
this.error = error;
|
|
46
|
+
this.skipReason = skipReason;
|
|
47
|
+
this.workerId = workerId;
|
|
48
|
+
}
|
|
49
|
+
props;
|
|
50
|
+
jobId;
|
|
51
|
+
chatId;
|
|
52
|
+
trigger;
|
|
53
|
+
status;
|
|
54
|
+
scheduledFor;
|
|
55
|
+
startedAt;
|
|
56
|
+
finishedAt;
|
|
57
|
+
instructions;
|
|
58
|
+
modelProvider;
|
|
59
|
+
modelName;
|
|
60
|
+
error;
|
|
61
|
+
skipReason;
|
|
62
|
+
workerId;
|
|
63
|
+
static fromJSON(props) {
|
|
64
|
+
return new AgenticJobRun(
|
|
65
|
+
props,
|
|
66
|
+
import_base.BaseEntity.toObjectId(props.jobId),
|
|
67
|
+
import_base.BaseEntity.toObjectId(props.chatId),
|
|
68
|
+
props.trigger,
|
|
69
|
+
props.status,
|
|
70
|
+
toDate(props.scheduledFor),
|
|
71
|
+
toDate(props.startedAt),
|
|
72
|
+
toDate(props.finishedAt),
|
|
73
|
+
props.instructions || void 0,
|
|
74
|
+
props.modelProvider || void 0,
|
|
75
|
+
props.modelName || void 0,
|
|
76
|
+
props.error,
|
|
77
|
+
props.skipReason || void 0,
|
|
78
|
+
props.workerId || void 0
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
toJSON() {
|
|
82
|
+
return {
|
|
83
|
+
...super.toJSON(),
|
|
84
|
+
jobId: this.jobId,
|
|
85
|
+
chatId: this.chatId,
|
|
86
|
+
trigger: this.trigger,
|
|
87
|
+
status: this.status,
|
|
88
|
+
scheduledFor: this.scheduledFor,
|
|
89
|
+
startedAt: this.startedAt,
|
|
90
|
+
finishedAt: this.finishedAt,
|
|
91
|
+
instructions: this.instructions,
|
|
92
|
+
modelProvider: this.modelProvider,
|
|
93
|
+
modelName: this.modelName,
|
|
94
|
+
error: this.error,
|
|
95
|
+
skipReason: this.skipReason,
|
|
96
|
+
workerId: this.workerId
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
101
|
+
0 && (module.exports = {
|
|
102
|
+
AgenticJobRun
|
|
103
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import "../../../chunk-CF3WOMB3.mjs";
|
|
2
|
+
import { BaseEntity } from "../../../common/base/base.entity.js";
|
|
3
|
+
const toDate = (value) => {
|
|
4
|
+
if (!value) return void 0;
|
|
5
|
+
const date = new Date(value);
|
|
6
|
+
if (Number.isNaN(date.getTime())) throw new Error("{{value_must_be_a_date}}");
|
|
7
|
+
return date;
|
|
8
|
+
};
|
|
9
|
+
class AgenticJobRun extends BaseEntity {
|
|
10
|
+
constructor(props, jobId, chatId, trigger, status, scheduledFor, startedAt, finishedAt, instructions, modelProvider, modelName, error, skipReason, workerId) {
|
|
11
|
+
super(props);
|
|
12
|
+
this.props = props;
|
|
13
|
+
this.jobId = jobId;
|
|
14
|
+
this.chatId = chatId;
|
|
15
|
+
this.trigger = trigger;
|
|
16
|
+
this.status = status;
|
|
17
|
+
this.scheduledFor = scheduledFor;
|
|
18
|
+
this.startedAt = startedAt;
|
|
19
|
+
this.finishedAt = finishedAt;
|
|
20
|
+
this.instructions = instructions;
|
|
21
|
+
this.modelProvider = modelProvider;
|
|
22
|
+
this.modelName = modelName;
|
|
23
|
+
this.error = error;
|
|
24
|
+
this.skipReason = skipReason;
|
|
25
|
+
this.workerId = workerId;
|
|
26
|
+
}
|
|
27
|
+
props;
|
|
28
|
+
jobId;
|
|
29
|
+
chatId;
|
|
30
|
+
trigger;
|
|
31
|
+
status;
|
|
32
|
+
scheduledFor;
|
|
33
|
+
startedAt;
|
|
34
|
+
finishedAt;
|
|
35
|
+
instructions;
|
|
36
|
+
modelProvider;
|
|
37
|
+
modelName;
|
|
38
|
+
error;
|
|
39
|
+
skipReason;
|
|
40
|
+
workerId;
|
|
41
|
+
static fromJSON(props) {
|
|
42
|
+
return new AgenticJobRun(
|
|
43
|
+
props,
|
|
44
|
+
BaseEntity.toObjectId(props.jobId),
|
|
45
|
+
BaseEntity.toObjectId(props.chatId),
|
|
46
|
+
props.trigger,
|
|
47
|
+
props.status,
|
|
48
|
+
toDate(props.scheduledFor),
|
|
49
|
+
toDate(props.startedAt),
|
|
50
|
+
toDate(props.finishedAt),
|
|
51
|
+
props.instructions || void 0,
|
|
52
|
+
props.modelProvider || void 0,
|
|
53
|
+
props.modelName || void 0,
|
|
54
|
+
props.error,
|
|
55
|
+
props.skipReason || void 0,
|
|
56
|
+
props.workerId || void 0
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
toJSON() {
|
|
60
|
+
return {
|
|
61
|
+
...super.toJSON(),
|
|
62
|
+
jobId: this.jobId,
|
|
63
|
+
chatId: this.chatId,
|
|
64
|
+
trigger: this.trigger,
|
|
65
|
+
status: this.status,
|
|
66
|
+
scheduledFor: this.scheduledFor,
|
|
67
|
+
startedAt: this.startedAt,
|
|
68
|
+
finishedAt: this.finishedAt,
|
|
69
|
+
instructions: this.instructions,
|
|
70
|
+
modelProvider: this.modelProvider,
|
|
71
|
+
modelName: this.modelName,
|
|
72
|
+
error: this.error,
|
|
73
|
+
skipReason: this.skipReason,
|
|
74
|
+
workerId: this.workerId
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
export {
|
|
79
|
+
AgenticJobRun
|
|
80
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ObjectId } from 'mongodb';
|
|
2
|
+
import { BaseEntity, BaseEntityProps } from '../../../common/base/base.entity.js';
|
|
3
|
+
import { Recurrence } from './recurrence';
|
|
4
|
+
import type { AgenticJobRunStatus } from './agentic-job-run.entity';
|
|
5
|
+
export interface AgenticJobProps extends BaseEntityProps {
|
|
6
|
+
name?: string;
|
|
7
|
+
instructions?: string;
|
|
8
|
+
enabled?: boolean;
|
|
9
|
+
recurrence?: Recurrence;
|
|
10
|
+
timezone?: string;
|
|
11
|
+
modelProvider?: string;
|
|
12
|
+
modelName?: string;
|
|
13
|
+
nextRunAt?: string | Date | null;
|
|
14
|
+
lastRunAt?: string | Date | null;
|
|
15
|
+
lastRunStatus?: AgenticJobRunStatus;
|
|
16
|
+
lockedBy?: string | null;
|
|
17
|
+
lockedUntil?: string | Date | null;
|
|
18
|
+
activeRunId?: string | ObjectId | null;
|
|
19
|
+
}
|
|
20
|
+
export declare class AgenticJob extends BaseEntity {
|
|
21
|
+
private readonly props;
|
|
22
|
+
name?: string | undefined;
|
|
23
|
+
instructions?: string | undefined;
|
|
24
|
+
enabled?: boolean | undefined;
|
|
25
|
+
recurrence?: Recurrence | undefined;
|
|
26
|
+
timezone?: string | undefined;
|
|
27
|
+
modelProvider?: string | undefined;
|
|
28
|
+
modelName?: string | undefined;
|
|
29
|
+
nextRunAt?: Date | undefined;
|
|
30
|
+
lastRunAt?: Date | undefined;
|
|
31
|
+
lastRunStatus?: AgenticJobRunStatus | undefined;
|
|
32
|
+
lockedBy?: string | undefined;
|
|
33
|
+
lockedUntil?: Date | undefined;
|
|
34
|
+
activeRunId?: ObjectId | undefined;
|
|
35
|
+
static fromJSON(props: AgenticJobProps): AgenticJob;
|
|
36
|
+
constructor(props: AgenticJobProps, name?: string | undefined, instructions?: string | undefined, enabled?: boolean | undefined, recurrence?: Recurrence | undefined, timezone?: string | undefined, modelProvider?: string | undefined, modelName?: string | undefined, nextRunAt?: Date | undefined, lastRunAt?: Date | undefined, lastRunStatus?: AgenticJobRunStatus | undefined, lockedBy?: string | undefined, lockedUntil?: Date | undefined, activeRunId?: ObjectId | undefined);
|
|
37
|
+
toJSON(): AgenticJobProps;
|
|
38
|
+
scheduleNextRun(from?: Date): this;
|
|
39
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var agentic_job_entity_exports = {};
|
|
20
|
+
__export(agentic_job_entity_exports, {
|
|
21
|
+
AgenticJob: () => AgenticJob
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(agentic_job_entity_exports);
|
|
24
|
+
var import_base = require("../../../common/base/base.entity.js");
|
|
25
|
+
var import_next_run = require("../utils/next-run");
|
|
26
|
+
const toDate = (value) => {
|
|
27
|
+
if (!value) return void 0;
|
|
28
|
+
const date = new Date(value);
|
|
29
|
+
if (Number.isNaN(date.getTime())) throw new Error("{{value_must_be_a_date}}");
|
|
30
|
+
return date;
|
|
31
|
+
};
|
|
32
|
+
class AgenticJob extends import_base.BaseEntity {
|
|
33
|
+
constructor(props, name, instructions, enabled, recurrence, timezone, modelProvider, modelName, nextRunAt, lastRunAt, lastRunStatus, lockedBy, lockedUntil, activeRunId) {
|
|
34
|
+
super(props);
|
|
35
|
+
this.props = props;
|
|
36
|
+
this.name = name;
|
|
37
|
+
this.instructions = instructions;
|
|
38
|
+
this.enabled = enabled;
|
|
39
|
+
this.recurrence = recurrence;
|
|
40
|
+
this.timezone = timezone;
|
|
41
|
+
this.modelProvider = modelProvider;
|
|
42
|
+
this.modelName = modelName;
|
|
43
|
+
this.nextRunAt = nextRunAt;
|
|
44
|
+
this.lastRunAt = lastRunAt;
|
|
45
|
+
this.lastRunStatus = lastRunStatus;
|
|
46
|
+
this.lockedBy = lockedBy;
|
|
47
|
+
this.lockedUntil = lockedUntil;
|
|
48
|
+
this.activeRunId = activeRunId;
|
|
49
|
+
}
|
|
50
|
+
props;
|
|
51
|
+
name;
|
|
52
|
+
instructions;
|
|
53
|
+
enabled;
|
|
54
|
+
recurrence;
|
|
55
|
+
timezone;
|
|
56
|
+
modelProvider;
|
|
57
|
+
modelName;
|
|
58
|
+
nextRunAt;
|
|
59
|
+
lastRunAt;
|
|
60
|
+
lastRunStatus;
|
|
61
|
+
lockedBy;
|
|
62
|
+
lockedUntil;
|
|
63
|
+
activeRunId;
|
|
64
|
+
static fromJSON(props) {
|
|
65
|
+
return new AgenticJob(
|
|
66
|
+
props,
|
|
67
|
+
props.name || void 0,
|
|
68
|
+
props.instructions || void 0,
|
|
69
|
+
props.enabled,
|
|
70
|
+
props.recurrence,
|
|
71
|
+
props.timezone || void 0,
|
|
72
|
+
props.modelProvider || void 0,
|
|
73
|
+
props.modelName || void 0,
|
|
74
|
+
toDate(props.nextRunAt),
|
|
75
|
+
toDate(props.lastRunAt),
|
|
76
|
+
props.lastRunStatus,
|
|
77
|
+
props.lockedBy || void 0,
|
|
78
|
+
toDate(props.lockedUntil),
|
|
79
|
+
props.activeRunId ? import_base.BaseEntity.toObjectId(props.activeRunId) : void 0
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
toJSON() {
|
|
83
|
+
return {
|
|
84
|
+
...super.toJSON(),
|
|
85
|
+
name: this.name,
|
|
86
|
+
instructions: this.instructions,
|
|
87
|
+
enabled: this.enabled,
|
|
88
|
+
recurrence: this.recurrence,
|
|
89
|
+
timezone: this.timezone,
|
|
90
|
+
modelProvider: this.modelProvider,
|
|
91
|
+
modelName: this.modelName,
|
|
92
|
+
nextRunAt: this.nextRunAt,
|
|
93
|
+
lastRunAt: this.lastRunAt,
|
|
94
|
+
lastRunStatus: this.lastRunStatus,
|
|
95
|
+
lockedBy: this.lockedBy,
|
|
96
|
+
lockedUntil: this.lockedUntil,
|
|
97
|
+
activeRunId: this.activeRunId
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
scheduleNextRun(from = /* @__PURE__ */ new Date()) {
|
|
101
|
+
const next = this.enabled && this.recurrence && this.timezone ? (0, import_next_run.computeNextRun)(this.recurrence, this.timezone, from) : null;
|
|
102
|
+
if (next) {
|
|
103
|
+
this.nextRunAt = next;
|
|
104
|
+
} else {
|
|
105
|
+
this.unset(["nextRunAt"]);
|
|
106
|
+
}
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
111
|
+
0 && (module.exports = {
|
|
112
|
+
AgenticJob
|
|
113
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import "../../../chunk-CF3WOMB3.mjs";
|
|
2
|
+
import { BaseEntity } from "../../../common/base/base.entity.js";
|
|
3
|
+
import { computeNextRun } from "../utils/next-run";
|
|
4
|
+
const toDate = (value) => {
|
|
5
|
+
if (!value) return void 0;
|
|
6
|
+
const date = new Date(value);
|
|
7
|
+
if (Number.isNaN(date.getTime())) throw new Error("{{value_must_be_a_date}}");
|
|
8
|
+
return date;
|
|
9
|
+
};
|
|
10
|
+
class AgenticJob extends BaseEntity {
|
|
11
|
+
constructor(props, name, instructions, enabled, recurrence, timezone, modelProvider, modelName, nextRunAt, lastRunAt, lastRunStatus, lockedBy, lockedUntil, activeRunId) {
|
|
12
|
+
super(props);
|
|
13
|
+
this.props = props;
|
|
14
|
+
this.name = name;
|
|
15
|
+
this.instructions = instructions;
|
|
16
|
+
this.enabled = enabled;
|
|
17
|
+
this.recurrence = recurrence;
|
|
18
|
+
this.timezone = timezone;
|
|
19
|
+
this.modelProvider = modelProvider;
|
|
20
|
+
this.modelName = modelName;
|
|
21
|
+
this.nextRunAt = nextRunAt;
|
|
22
|
+
this.lastRunAt = lastRunAt;
|
|
23
|
+
this.lastRunStatus = lastRunStatus;
|
|
24
|
+
this.lockedBy = lockedBy;
|
|
25
|
+
this.lockedUntil = lockedUntil;
|
|
26
|
+
this.activeRunId = activeRunId;
|
|
27
|
+
}
|
|
28
|
+
props;
|
|
29
|
+
name;
|
|
30
|
+
instructions;
|
|
31
|
+
enabled;
|
|
32
|
+
recurrence;
|
|
33
|
+
timezone;
|
|
34
|
+
modelProvider;
|
|
35
|
+
modelName;
|
|
36
|
+
nextRunAt;
|
|
37
|
+
lastRunAt;
|
|
38
|
+
lastRunStatus;
|
|
39
|
+
lockedBy;
|
|
40
|
+
lockedUntil;
|
|
41
|
+
activeRunId;
|
|
42
|
+
static fromJSON(props) {
|
|
43
|
+
return new AgenticJob(
|
|
44
|
+
props,
|
|
45
|
+
props.name || void 0,
|
|
46
|
+
props.instructions || void 0,
|
|
47
|
+
props.enabled,
|
|
48
|
+
props.recurrence,
|
|
49
|
+
props.timezone || void 0,
|
|
50
|
+
props.modelProvider || void 0,
|
|
51
|
+
props.modelName || void 0,
|
|
52
|
+
toDate(props.nextRunAt),
|
|
53
|
+
toDate(props.lastRunAt),
|
|
54
|
+
props.lastRunStatus,
|
|
55
|
+
props.lockedBy || void 0,
|
|
56
|
+
toDate(props.lockedUntil),
|
|
57
|
+
props.activeRunId ? BaseEntity.toObjectId(props.activeRunId) : void 0
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
toJSON() {
|
|
61
|
+
return {
|
|
62
|
+
...super.toJSON(),
|
|
63
|
+
name: this.name,
|
|
64
|
+
instructions: this.instructions,
|
|
65
|
+
enabled: this.enabled,
|
|
66
|
+
recurrence: this.recurrence,
|
|
67
|
+
timezone: this.timezone,
|
|
68
|
+
modelProvider: this.modelProvider,
|
|
69
|
+
modelName: this.modelName,
|
|
70
|
+
nextRunAt: this.nextRunAt,
|
|
71
|
+
lastRunAt: this.lastRunAt,
|
|
72
|
+
lastRunStatus: this.lastRunStatus,
|
|
73
|
+
lockedBy: this.lockedBy,
|
|
74
|
+
lockedUntil: this.lockedUntil,
|
|
75
|
+
activeRunId: this.activeRunId
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
scheduleNextRun(from = /* @__PURE__ */ new Date()) {
|
|
79
|
+
const next = this.enabled && this.recurrence && this.timezone ? computeNextRun(this.recurrence, this.timezone, from) : null;
|
|
80
|
+
if (next) {
|
|
81
|
+
this.nextRunAt = next;
|
|
82
|
+
} else {
|
|
83
|
+
this.unset(["nextRunAt"]);
|
|
84
|
+
}
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export {
|
|
89
|
+
AgenticJob
|
|
90
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var entities_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(entities_exports);
|
|
18
|
+
__reExport(entities_exports, require("./recurrence"), module.exports);
|
|
19
|
+
__reExport(entities_exports, require("./agentic-job.entity"), module.exports);
|
|
20
|
+
__reExport(entities_exports, require("./agentic-job-run.entity"), module.exports);
|
|
21
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
22
|
+
0 && (module.exports = {
|
|
23
|
+
...require("./recurrence"),
|
|
24
|
+
...require("./agentic-job.entity"),
|
|
25
|
+
...require("./agentic-job-run.entity")
|
|
26
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const WEEKDAYS: readonly ["MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"];
|
|
2
|
+
export type Recurrence = {
|
|
3
|
+
type: 'daily';
|
|
4
|
+
time: string;
|
|
5
|
+
} | {
|
|
6
|
+
type: 'weekly';
|
|
7
|
+
days: number[];
|
|
8
|
+
time: string;
|
|
9
|
+
} | {
|
|
10
|
+
type: 'monthly';
|
|
11
|
+
day: number | 'last';
|
|
12
|
+
time: string;
|
|
13
|
+
} | {
|
|
14
|
+
type: 'once';
|
|
15
|
+
at: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function validateRecurrence(value: unknown): Recurrence;
|
|
18
|
+
export declare function toCronPattern(recurrence: Recurrence): string | undefined;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var recurrence_exports = {};
|
|
20
|
+
__export(recurrence_exports, {
|
|
21
|
+
WEEKDAYS: () => WEEKDAYS,
|
|
22
|
+
toCronPattern: () => toCronPattern,
|
|
23
|
+
validateRecurrence: () => validateRecurrence
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(recurrence_exports);
|
|
26
|
+
const WEEKDAYS = ["MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"];
|
|
27
|
+
const TIME = /^([01]\d|2[0-3]):([0-5]\d)$/;
|
|
28
|
+
const LOCAL_DATE_TIME = /^(\d{4})-(\d{2})-(\d{2})T([01]\d|2[0-3]):([0-5]\d)$/;
|
|
29
|
+
const isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
30
|
+
const assertTime = (value) => {
|
|
31
|
+
if (typeof value !== "string" || !TIME.test(value)) throw new Error("The time must be written as HH:mm, in 24 hours");
|
|
32
|
+
return value;
|
|
33
|
+
};
|
|
34
|
+
const assertLocalDateTime = (value) => {
|
|
35
|
+
const match = typeof value === "string" ? LOCAL_DATE_TIME.exec(value) : null;
|
|
36
|
+
if (!match) throw new Error("The date of a recurrence of type once must be written as YYYY-MM-DDTHH:mm");
|
|
37
|
+
const [, year, month, day] = match;
|
|
38
|
+
const parsed = new Date(Date.UTC(Number(year), Number(month) - 1, Number(day)));
|
|
39
|
+
if (parsed.getUTCFullYear() !== Number(year) || parsed.getUTCMonth() !== Number(month) - 1 || parsed.getUTCDate() !== Number(day)) {
|
|
40
|
+
throw new Error("The date of a recurrence of type once does not exist");
|
|
41
|
+
}
|
|
42
|
+
return value;
|
|
43
|
+
};
|
|
44
|
+
function validateRecurrence(value) {
|
|
45
|
+
if (!isRecord(value)) throw new Error("The recurrence is required");
|
|
46
|
+
switch (value.type) {
|
|
47
|
+
case "daily":
|
|
48
|
+
return { type: "daily", time: assertTime(value.time) };
|
|
49
|
+
case "weekly": {
|
|
50
|
+
const days = value.days;
|
|
51
|
+
const valid = Array.isArray(days) && days.length > 0 && days.every((day) => Number.isInteger(day) && day >= 1 && day <= 7);
|
|
52
|
+
if (!valid) throw new Error("The days of a weekly recurrence must be a list of numbers from 1 (Monday) to 7 (Sunday)");
|
|
53
|
+
return { type: "weekly", days: Array.from(new Set(days)).sort((a, b) => a - b), time: assertTime(value.time) };
|
|
54
|
+
}
|
|
55
|
+
case "monthly": {
|
|
56
|
+
const day = value.day;
|
|
57
|
+
const valid = day === "last" || Number.isInteger(day) && day >= 1 && day <= 31;
|
|
58
|
+
if (!valid) throw new Error('The day of a monthly recurrence must be a number from 1 to 31 or "last"');
|
|
59
|
+
return { type: "monthly", day, time: assertTime(value.time) };
|
|
60
|
+
}
|
|
61
|
+
case "once":
|
|
62
|
+
return { type: "once", at: assertLocalDateTime(value.at) };
|
|
63
|
+
default:
|
|
64
|
+
throw new Error("The type of the recurrence must be daily, weekly, monthly or once");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function toCronPattern(recurrence) {
|
|
68
|
+
if (recurrence.type === "once") return void 0;
|
|
69
|
+
const [hour, minute] = recurrence.time.split(":").map(Number);
|
|
70
|
+
switch (recurrence.type) {
|
|
71
|
+
case "daily":
|
|
72
|
+
return `${minute} ${hour} * * *`;
|
|
73
|
+
case "weekly":
|
|
74
|
+
return `${minute} ${hour} * * ${recurrence.days.map((day) => WEEKDAYS[day - 1]).join(",")}`;
|
|
75
|
+
case "monthly":
|
|
76
|
+
return `${minute} ${hour} ${recurrence.day === "last" ? "L" : recurrence.day} * *`;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
80
|
+
0 && (module.exports = {
|
|
81
|
+
WEEKDAYS,
|
|
82
|
+
toCronPattern,
|
|
83
|
+
validateRecurrence
|
|
84
|
+
});
|