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
|
@@ -0,0 +1,62 @@
|
|
|
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 next_run_exports = {};
|
|
20
|
+
__export(next_run_exports, {
|
|
21
|
+
assertTimezone: () => assertTimezone,
|
|
22
|
+
computeNextRun: () => computeNextRun,
|
|
23
|
+
previewNextRuns: () => previewNextRuns
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(next_run_exports);
|
|
26
|
+
var import_croner = require("croner");
|
|
27
|
+
var import_recurrence = require("../entities/recurrence");
|
|
28
|
+
const MAX_PREVIEW = 20;
|
|
29
|
+
function assertTimezone(timezone) {
|
|
30
|
+
if (typeof timezone !== "string" || !timezone.trim()) throw new Error("The timezone is required");
|
|
31
|
+
try {
|
|
32
|
+
new Intl.DateTimeFormat("en-US", { timeZone: timezone });
|
|
33
|
+
} catch {
|
|
34
|
+
throw new Error(`The timezone "${timezone}" is not a valid IANA timezone`);
|
|
35
|
+
}
|
|
36
|
+
return timezone;
|
|
37
|
+
}
|
|
38
|
+
function computeNextRun(recurrence, timezone, from = /* @__PURE__ */ new Date()) {
|
|
39
|
+
const pattern = recurrence.type === "once" ? `${recurrence.at}:00` : (0, import_recurrence.toCronPattern)(recurrence);
|
|
40
|
+
const cron = new import_croner.Cron(pattern, { timezone });
|
|
41
|
+
let next = cron.nextRun(from);
|
|
42
|
+
while (next && next.getTime() <= from.getTime()) next = cron.nextRun(next);
|
|
43
|
+
return next;
|
|
44
|
+
}
|
|
45
|
+
function previewNextRuns(recurrence, timezone, count, from = /* @__PURE__ */ new Date()) {
|
|
46
|
+
const runs = [];
|
|
47
|
+
const limit = Math.min(Math.max(Math.floor(count), 0), MAX_PREVIEW);
|
|
48
|
+
let cursor = from;
|
|
49
|
+
while (runs.length < limit) {
|
|
50
|
+
const next = computeNextRun(recurrence, timezone, cursor);
|
|
51
|
+
if (!next) break;
|
|
52
|
+
runs.push(next);
|
|
53
|
+
cursor = next;
|
|
54
|
+
}
|
|
55
|
+
return runs;
|
|
56
|
+
}
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
assertTimezone,
|
|
60
|
+
computeNextRun,
|
|
61
|
+
previewNextRuns
|
|
62
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import "../../../chunk-CF3WOMB3.mjs";
|
|
2
|
+
import { Cron } from "croner";
|
|
3
|
+
import { toCronPattern } from "../entities/recurrence";
|
|
4
|
+
const MAX_PREVIEW = 20;
|
|
5
|
+
function assertTimezone(timezone) {
|
|
6
|
+
if (typeof timezone !== "string" || !timezone.trim()) throw new Error("The timezone is required");
|
|
7
|
+
try {
|
|
8
|
+
new Intl.DateTimeFormat("en-US", { timeZone: timezone });
|
|
9
|
+
} catch {
|
|
10
|
+
throw new Error(`The timezone "${timezone}" is not a valid IANA timezone`);
|
|
11
|
+
}
|
|
12
|
+
return timezone;
|
|
13
|
+
}
|
|
14
|
+
function computeNextRun(recurrence, timezone, from = /* @__PURE__ */ new Date()) {
|
|
15
|
+
const pattern = recurrence.type === "once" ? `${recurrence.at}:00` : toCronPattern(recurrence);
|
|
16
|
+
const cron = new Cron(pattern, { timezone });
|
|
17
|
+
let next = cron.nextRun(from);
|
|
18
|
+
while (next && next.getTime() <= from.getTime()) next = cron.nextRun(next);
|
|
19
|
+
return next;
|
|
20
|
+
}
|
|
21
|
+
function previewNextRuns(recurrence, timezone, count, from = /* @__PURE__ */ new Date()) {
|
|
22
|
+
const runs = [];
|
|
23
|
+
const limit = Math.min(Math.max(Math.floor(count), 0), MAX_PREVIEW);
|
|
24
|
+
let cursor = from;
|
|
25
|
+
while (runs.length < limit) {
|
|
26
|
+
const next = computeNextRun(recurrence, timezone, cursor);
|
|
27
|
+
if (!next) break;
|
|
28
|
+
runs.push(next);
|
|
29
|
+
cursor = next;
|
|
30
|
+
}
|
|
31
|
+
return runs;
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
assertTimezone,
|
|
35
|
+
computeNextRun,
|
|
36
|
+
previewNextRuns
|
|
37
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AgenticJobProps, AgenticJobRun, AgenticJobRunStatus, AgenticJobRunTrigger } from '../entities';
|
|
2
|
+
import { AgenticJobRunRepository } from '../repositories';
|
|
3
|
+
export interface OpenRunParams {
|
|
4
|
+
job: AgenticJobProps;
|
|
5
|
+
trigger: AgenticJobRunTrigger;
|
|
6
|
+
status: Extract<AgenticJobRunStatus, 'running' | 'skipped'>;
|
|
7
|
+
workerId: string;
|
|
8
|
+
now: Date;
|
|
9
|
+
scheduledFor?: Date;
|
|
10
|
+
skipReason?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function openRun(repository: AgenticJobRunRepository, params: OpenRunParams): Promise<AgenticJobRun>;
|
|
@@ -0,0 +1,47 @@
|
|
|
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 open_run_exports = {};
|
|
20
|
+
__export(open_run_exports, {
|
|
21
|
+
openRun: () => openRun
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(open_run_exports);
|
|
24
|
+
var import_entities = require("../entities");
|
|
25
|
+
async function openRun(repository, params) {
|
|
26
|
+
const { job, trigger, status, workerId, now, scheduledFor, skipReason } = params;
|
|
27
|
+
const run = import_entities.AgenticJobRun.fromJSON({
|
|
28
|
+
jobId: job._id,
|
|
29
|
+
ownerId: job.ownerId,
|
|
30
|
+
trigger,
|
|
31
|
+
status,
|
|
32
|
+
scheduledFor,
|
|
33
|
+
startedAt: now,
|
|
34
|
+
...status === "skipped" ? { finishedAt: now, skipReason } : {},
|
|
35
|
+
instructions: job.instructions,
|
|
36
|
+
modelProvider: job.modelProvider,
|
|
37
|
+
modelName: job.modelName,
|
|
38
|
+
workerId,
|
|
39
|
+
createdAt: now
|
|
40
|
+
});
|
|
41
|
+
await repository.create(run);
|
|
42
|
+
return run;
|
|
43
|
+
}
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
openRun
|
|
47
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import "../../../chunk-CF3WOMB3.mjs";
|
|
2
|
+
import { AgenticJobRun } from "../entities";
|
|
3
|
+
async function openRun(repository, params) {
|
|
4
|
+
const { job, trigger, status, workerId, now, scheduledFor, skipReason } = params;
|
|
5
|
+
const run = AgenticJobRun.fromJSON({
|
|
6
|
+
jobId: job._id,
|
|
7
|
+
ownerId: job.ownerId,
|
|
8
|
+
trigger,
|
|
9
|
+
status,
|
|
10
|
+
scheduledFor,
|
|
11
|
+
startedAt: now,
|
|
12
|
+
...status === "skipped" ? { finishedAt: now, skipReason } : {},
|
|
13
|
+
instructions: job.instructions,
|
|
14
|
+
modelProvider: job.modelProvider,
|
|
15
|
+
modelName: job.modelName,
|
|
16
|
+
workerId,
|
|
17
|
+
createdAt: now
|
|
18
|
+
});
|
|
19
|
+
await repository.create(run);
|
|
20
|
+
return run;
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
openRun
|
|
24
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
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 settings_exports = {};
|
|
20
|
+
__export(settings_exports, {
|
|
21
|
+
leaseMs: () => leaseMs,
|
|
22
|
+
pollIntervalMs: () => pollIntervalMs
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(settings_exports);
|
|
25
|
+
var import_number_setting = require("../../../common/utils/number-setting.js");
|
|
26
|
+
const DEFAULT_LEASE_MS = 10 * 60 * 1e3;
|
|
27
|
+
const DEFAULT_POLL_INTERVAL_MS = 60 * 1e3;
|
|
28
|
+
const leaseMs = () => (0, import_number_setting.numberSetting)("AGENTIC_JOBS_LEASE_MS", DEFAULT_LEASE_MS);
|
|
29
|
+
const pollIntervalMs = () => (0, import_number_setting.numberSetting)("AGENTIC_JOBS_POLL_INTERVAL_MS", DEFAULT_POLL_INTERVAL_MS);
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
leaseMs,
|
|
33
|
+
pollIntervalMs
|
|
34
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import "../../../chunk-CF3WOMB3.mjs";
|
|
2
|
+
import { numberSetting } from "../../../common/utils/number-setting.js";
|
|
3
|
+
const DEFAULT_LEASE_MS = 10 * 60 * 1e3;
|
|
4
|
+
const DEFAULT_POLL_INTERVAL_MS = 60 * 1e3;
|
|
5
|
+
const leaseMs = () => numberSetting("AGENTIC_JOBS_LEASE_MS", DEFAULT_LEASE_MS);
|
|
6
|
+
const pollIntervalMs = () => numberSetting("AGENTIC_JOBS_POLL_INTERVAL_MS", DEFAULT_POLL_INTERVAL_MS);
|
|
7
|
+
export {
|
|
8
|
+
leaseMs,
|
|
9
|
+
pollIntervalMs
|
|
10
|
+
};
|
package/docs/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# openloops documentation
|
|
2
|
+
|
|
3
|
+
Start with the [README](../README.md) for what `openloops` is and how to run it. These pages go deeper, grouped by what you are trying to do.
|
|
4
|
+
|
|
5
|
+
## Start here
|
|
6
|
+
|
|
7
|
+
| Page | What it covers |
|
|
8
|
+
| --- | --- |
|
|
9
|
+
| [Integration guide](integration-guide.md) | What to write in a backend: which endpoint calls what, the authorization you own and a security checklist. |
|
|
10
|
+
|
|
11
|
+
## Run an agent
|
|
12
|
+
|
|
13
|
+
| Page | What it covers |
|
|
14
|
+
| --- | --- |
|
|
15
|
+
| [The `Agent` runtime](agent.md) | Options, running a turn, the result and its statuses, confirmations, autonomous mode, hooks and interruption. |
|
|
16
|
+
| [Configuration](configuration.md) | Environment variables, choosing the model and what is recorded. |
|
|
17
|
+
| [Agentic jobs](agentic-jobs.md) | Tasks that the agent runs by itself on a schedule: recurrence, the history of runs and the runner that executes them. |
|
|
18
|
+
| [Chats](chats.md) | The chat record, its messages and their `source`, listing, reading and deleting chats. |
|
|
19
|
+
|
|
20
|
+
## Shape how the agent works
|
|
21
|
+
|
|
22
|
+
| Page | What it covers |
|
|
23
|
+
| --- | --- |
|
|
24
|
+
| [Building an `AgentLoop`](loops.md) | `AgiLoop`, the contract of a loop, `RunContext`, `Harness` and tasks. |
|
|
25
|
+
| [Skills](skills.md) | Writing and running LLM-backed reasoning steps and their call modes. |
|
|
26
|
+
| [Tools](tools.md) | Writing tools, validation, built-in tools and how MCP tools differ. |
|
|
27
|
+
| [Guardrails](guardrails.md) | Blocking input before the model sees it, ready-made guards and writing your own. |
|
|
28
|
+
| [The harness](harness.md) | The tool pipeline, native tools, the workspace, discovery, approvals, language and limits. |
|
|
29
|
+
|
|
30
|
+
## Connect to the outside world
|
|
31
|
+
|
|
32
|
+
| Page | What it covers |
|
|
33
|
+
| --- | --- |
|
|
34
|
+
| [MCP servers](mcp-servers.md) | Registering servers, the trust flow, approving and blocking, and how the agent uses them. |
|
|
35
|
+
|
|
36
|
+
## Users and cost
|
|
37
|
+
|
|
38
|
+
| Page | What it covers |
|
|
39
|
+
| --- | --- |
|
|
40
|
+
| [User management](users.md) | `CurrentUser`, creating, listing, updating and deleting users. |
|
|
41
|
+
| [Authentication](authentication.md) | Login and tokens. |
|
|
42
|
+
| [LLM usage tracking](usage.md) | Tokens and cost per chat or answer, and per-user statistics. |
|
|
43
|
+
|
|
44
|
+
## Examples
|
|
45
|
+
|
|
46
|
+
Runnable examples for every page live in [`examples/`](../examples), organized by domain.
|
package/docs/agent.md
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# The `Agent` runtime
|
|
2
|
+
|
|
3
|
+
`Agent` is the runtime that drives an `AgentLoop`. It owns everything a loop shouldn't have to think about: loading and saving the chat, dispatching to the right node, running guardrails, resolving tools (native and MCP), asking for confirmation, handling interruption requests, and tracking usage.
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
import { Agent } from 'openloops/core'
|
|
7
|
+
import { AgiLoop } from 'openloops/loops'
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Creating an agent
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
const agent = new Agent({
|
|
14
|
+
loop: new AgiLoop(),
|
|
15
|
+
tools: [],
|
|
16
|
+
guards: [],
|
|
17
|
+
identity: {
|
|
18
|
+
name: 'Sofi',
|
|
19
|
+
gender: 'Female',
|
|
20
|
+
role: 'Personal assistant and daily companion',
|
|
21
|
+
},
|
|
22
|
+
maxInputLength: 100_000,
|
|
23
|
+
maxIterations: 50,
|
|
24
|
+
strictMode: false,
|
|
25
|
+
})
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
| Option | Required | Default | What it does |
|
|
29
|
+
| --- | --- | --- | --- |
|
|
30
|
+
| `loop` | yes | none | An instance of a class extending `AgentLoop`. Use `AgiLoop` unless you wrote your own. See [loops](loops.md). |
|
|
31
|
+
| `tools` | no | `[]` | Extra native `Tool` instances. See [tools](tools.md). |
|
|
32
|
+
| `guards` | no | `[]` | Input guards that run before the model sees a message. See [guardrails](guardrails.md). |
|
|
33
|
+
| `identity` | no | none | Name, gender and role injected into every skill. |
|
|
34
|
+
| `maxInputLength` | no | `100000` | Longest message accepted, in characters. Longer messages are blocked by a built-in guard. |
|
|
35
|
+
| `maxIterations` | no | `50` | Hard limit of loop iterations in one run. When reached, the run fails with `AGENT_MAX_ITERATIONS_REACHED`. |
|
|
36
|
+
| `strictMode` | no | `false` | When `true`, the user is always asked before the agent uses an MCP server whose tools changed after being approved. See [MCP servers](mcp-servers.md#how-the-agent-uses-the-servers). |
|
|
37
|
+
|
|
38
|
+
An `Agent` instance holds the state of the run it is executing, so run one conversation at a time per instance and create another instance for concurrent runs.
|
|
39
|
+
|
|
40
|
+
## Running a turn
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
const result = await agent.run({
|
|
44
|
+
input: {
|
|
45
|
+
message: 'hi, how are you?',
|
|
46
|
+
chatId: undefined,
|
|
47
|
+
},
|
|
48
|
+
options: {
|
|
49
|
+
notifyOnCompletion: true,
|
|
50
|
+
modelProvider: 'anthropic',
|
|
51
|
+
modelName: 'claude-haiku-5-5',
|
|
52
|
+
},
|
|
53
|
+
currentUser,
|
|
54
|
+
currentSession,
|
|
55
|
+
})
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Omit `chatId` to start a brand-new chat. Pass an existing `chatId` to continue a conversation: `openloops` loads it, appends the new message, and resumes the loop exactly where it left off, including mid-confirmation or mid-question.
|
|
59
|
+
|
|
60
|
+
`options` are stored in the chat settings, so they stick for the following turns of that chat:
|
|
61
|
+
|
|
62
|
+
| Option | What it does |
|
|
63
|
+
| --- | --- |
|
|
64
|
+
| `modelProvider`, `modelName` | Model used for this chat. Defaults to `anthropic` and `claude-haiku-5-5`. See [configuration](configuration.md#default-model). |
|
|
65
|
+
| `loopName` | Name of the loop driving the chat. Set automatically from the loop. |
|
|
66
|
+
| `executionMode` | `interactive` (default) or `autonomous`. See [Autonomous mode](#autonomous-mode). |
|
|
67
|
+
| `notifyOnCompletion` | Exposed as `agent.notifyOnCompletion` so a post execution hook can notify the user. |
|
|
68
|
+
| `isPrivateSession` | Stored in the chat settings for your application to use. |
|
|
69
|
+
|
|
70
|
+
`currentSession` is optional. It carries device, location and locale, which skills use to answer in the right time zone and language.
|
|
71
|
+
|
|
72
|
+
## Autonomous mode
|
|
73
|
+
|
|
74
|
+
An autonomous run is one where nobody is in the chat while the agent works, for example a scheduled task. Pass the mode in the run:
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
await agent.run({
|
|
78
|
+
input: { message: 'Every morning, summarize my open tickets' },
|
|
79
|
+
options: { executionMode: 'autonomous' },
|
|
80
|
+
currentUser,
|
|
81
|
+
})
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
`currentUser` is still required: it owns the chat and the MCP servers. What changes while a run is autonomous:
|
|
85
|
+
|
|
86
|
+
- The model is told that nobody is present, so it plans the whole task and writes a complete final answer.
|
|
87
|
+
- Questions the model sends with `ask_user` are answered by an automatic evaluator, a skill that only knows the context of the task. The model receives the answer marked as automatic and is told to use its judgment. The evaluator never grants permissions and says it cannot decide when the context does not settle the question. At most 3 questions per task are answered this way.
|
|
88
|
+
- Whatever needs the user (a destructive tool, an MCP server that was not approved or that changed in a way that needs review, a question the evaluator cannot answer) pauses the run. The chat stays in `awaiting_user_confirmation` or `awaiting_user_input` with the question as its last message. The user opens the chat and answers, and the task continues where it stopped.
|
|
89
|
+
- Small changes in an approved MCP server are still approved by the review skill, as in an interactive run. A server used for the first time, or any change with `strictMode: true`, always pauses the run.
|
|
90
|
+
|
|
91
|
+
The mode is saved in `chat.settings.executionMode` when the chat is created and is not changed later. Each run takes its mode only from its own `executionMode` option and is interactive when it is not given, so a user who continues an autonomous chat by hand is working interactively and the chat is still listed as autonomous. See [chats](chats.md#listing-a-users-chats).
|
|
92
|
+
|
|
93
|
+
- The first step of the loop, the one that answers conversation directly, is skipped: the task goes straight to the reasoning engine.
|
|
94
|
+
- Each question of the model and its automatic answer are saved in the chat history so the user can see them later, marked with `source` and excluded from the context of the model.
|
|
95
|
+
|
|
96
|
+
Only `AgiLoop` supports autonomous mode.
|
|
97
|
+
|
|
98
|
+
To run an agent on a schedule, see [agentic jobs](agentic-jobs.md).
|
|
99
|
+
|
|
100
|
+
## The result
|
|
101
|
+
|
|
102
|
+
`agent.run` does not throw for failures inside the run. It returns:
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
const { data, error } = await agent.run({ input, currentUser })
|
|
106
|
+
|
|
107
|
+
data?.lastAnswer
|
|
108
|
+
data?.messages
|
|
109
|
+
data?.tasks
|
|
110
|
+
data?.state?.status
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
- `data` is the `Chat` after the turn, or `undefined` if the chat could not even be created.
|
|
114
|
+
- `error` is a message you can show to the user, present only when the run failed. The chat is marked as `failed` and saved.
|
|
115
|
+
|
|
116
|
+
`data.state.status` tells you where the conversation is:
|
|
117
|
+
|
|
118
|
+
| Status | Meaning |
|
|
119
|
+
| --- | --- |
|
|
120
|
+
| `idle` | The task finished and the agent is ready for a new request. |
|
|
121
|
+
| `processing` | A run is in progress. |
|
|
122
|
+
| `awaiting_user_input` | The agent asked a question. Send the answer as the next message. |
|
|
123
|
+
| `awaiting_user_confirmation` | The agent asked the user to approve an action. Send the answer as the next message. |
|
|
124
|
+
| `failed` | The run failed. `data.state.lastError` has the code and message. |
|
|
125
|
+
|
|
126
|
+
## Confirmations
|
|
127
|
+
|
|
128
|
+
When the loop is about to run a tool that is destructive, or a tool from an MCP server the user has not approved yet, the agent stops, asks the user in the chat and leaves the status as `awaiting_user_confirmation`. The user's next message is read by the `confirmation_gate` skill:
|
|
129
|
+
|
|
130
|
+
- A yes runs the pending actions. For an MCP server, the harness records the approval on behalf of the user.
|
|
131
|
+
- A no cancels the task. For an MCP server, it is blocked.
|
|
132
|
+
- An unclear answer makes the agent ask again.
|
|
133
|
+
|
|
134
|
+
You do not implement any of this. See [harness](harness.md#approvals).
|
|
135
|
+
|
|
136
|
+
## Identity
|
|
137
|
+
|
|
138
|
+
Pass `identity` once when constructing the `Agent` and it is injected into every skill's context. This is how you reskin an agent (name, personality framing) without touching a single line of loop or skill code.
|
|
139
|
+
|
|
140
|
+
## Tools
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
agent.addTool(myCustomTool)
|
|
144
|
+
agent.tools
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Tools you add are available for the whole run, next to the tools of the user's MCP servers. `agent.tools` also includes the MCP tools that have been loaded so far in the current run. See [tools](tools.md) and [MCP servers](mcp-servers.md).
|
|
148
|
+
|
|
149
|
+
## MCP servers
|
|
150
|
+
|
|
151
|
+
You never call anything MCP-related on `Agent`. At the start of a turn the agent looks up the user's registered servers and shows them to the model as an index (name, description, state). It connects to a server only when the model asks for its tools, checks that its manifest is the one the user approved, and disconnects every session at the end of the turn, including when the turn fails.
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
agent.mcps
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
`agent.mcps` is the list of `McpServer` entities known during the current turn. See [MCP servers](mcp-servers.md).
|
|
158
|
+
|
|
159
|
+
## Guardrails
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
import { inputGuards } from 'openloops/guardrails'
|
|
163
|
+
|
|
164
|
+
agent.addGuard(inputGuards.blockCard)
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Guards run on the user message before any model call. See [guardrails](guardrails.md).
|
|
168
|
+
|
|
169
|
+
## Hooks
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
agent.addHook('pre_execution', () => {
|
|
173
|
+
// runs once, right before the loop starts
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
agent.addHook('post_execution', async () => {
|
|
177
|
+
if (agent.notifyOnCompletion) {
|
|
178
|
+
// send a push notification, etc.
|
|
179
|
+
}
|
|
180
|
+
})
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Hooks do not run when a guard blocks the message, because the loop never starts.
|
|
184
|
+
|
|
185
|
+
## Stopping a running turn
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
await Agent.interruptExecution(chatId, currentUser)
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Call it from a separate request while `agent.run()` is still executing, for example when the user presses stop. The running loop checks for the request before every node and stops cleanly. The next message in that chat starts again from the initial node of the loop.
|
|
192
|
+
|
|
193
|
+
`agent.stopAgent()` stops the loop of the same instance from your own code.
|
|
194
|
+
|
|
195
|
+
## What gets stored
|
|
196
|
+
|
|
197
|
+
For every chat, `openloops` persists the chat and its messages, the tasks, every action (tool call) with its result, the traces of each node and skill, and the workspace items that hold large tool outputs and notes. Every LLM call is recorded with its cost, see [usage](usage.md).
|
|
198
|
+
|
|
199
|
+
## Error handling
|
|
200
|
+
|
|
201
|
+
If a turn fails for any reason, `Agent` marks the chat as failed, saves it, closes any open MCP session and returns the error in `result.error`. LLM failures such as rate limits, exhausted quota or a model that does not answer in time (`LLM_TIMEOUT`) carry a user-facing message and a retryable flag in `data.state.lastError`.
|