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,98 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__decorateClass
|
|
3
|
+
} from "../../../chunk-CF3WOMB3.mjs";
|
|
4
|
+
import { autoInjectable } from "tsyringe";
|
|
5
|
+
import { ObjectId } from "mongodb";
|
|
6
|
+
import { MongoRepository } from "../../../common/repositories/index.js";
|
|
7
|
+
import { getDatabaseName } from "../../../common/utils/database-name.js";
|
|
8
|
+
let AgenticJobRepository = class {
|
|
9
|
+
_ = new MongoRepository({
|
|
10
|
+
database: getDatabaseName(),
|
|
11
|
+
collection: "agentic_jobs"
|
|
12
|
+
});
|
|
13
|
+
async create(job) {
|
|
14
|
+
const id = await this._.createOne({ payload: job.toDocument() });
|
|
15
|
+
id && job.setId(id);
|
|
16
|
+
return job;
|
|
17
|
+
}
|
|
18
|
+
async update(job, options) {
|
|
19
|
+
if (options && typeof options.expectedVersion !== "number") throw new Error("[AgenticJobRepository] The expected version is required to check for conflicts");
|
|
20
|
+
return await this._.updateOne({
|
|
21
|
+
where: { _id: job._id },
|
|
22
|
+
payload: job.toFlatDocument(),
|
|
23
|
+
expectedVersion: options?.expectedVersion
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
async findById(id) {
|
|
27
|
+
return await this._.findOne({ where: { _id: this._.parseId(id) } });
|
|
28
|
+
}
|
|
29
|
+
async findByOwner(ownerId, options) {
|
|
30
|
+
return await this._.findMany({ where: { ownerId: new ObjectId(ownerId) }, options });
|
|
31
|
+
}
|
|
32
|
+
async deleteById(id) {
|
|
33
|
+
return await this._.deleteOne({ where: { _id: this._.parseId(id) } });
|
|
34
|
+
}
|
|
35
|
+
async findDue(now, limit) {
|
|
36
|
+
return await this._.findMany({
|
|
37
|
+
where: { enabled: true, nextRunAt: { $lte: now }, ...this.unlocked(now) },
|
|
38
|
+
options: { page: 1, limit, sortBy: { nextRunAt: 1 } }
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async claim(params) {
|
|
42
|
+
const { id, workerId, now, leaseMs, nextRunAt } = params;
|
|
43
|
+
return await this._.updateOne({
|
|
44
|
+
where: { _id: this._.parseId(id), enabled: true, nextRunAt: { $lte: now }, ...this.unlocked(now) },
|
|
45
|
+
payload: {
|
|
46
|
+
lockedBy: workerId,
|
|
47
|
+
lockedUntil: new Date(now.getTime() + leaseMs),
|
|
48
|
+
...nextRunAt ? { nextRunAt } : { toUnset: { nextRunAt: "" } }
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
async claimManual(params) {
|
|
53
|
+
const { id, workerId, now, leaseMs } = params;
|
|
54
|
+
return await this._.updateOne({
|
|
55
|
+
where: { _id: this._.parseId(id), ...this.unlocked(now) },
|
|
56
|
+
payload: { lockedBy: workerId, lockedUntil: new Date(now.getTime() + leaseMs) }
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async setActiveRun(id, workerId, runId) {
|
|
60
|
+
return await this._.updateOne({
|
|
61
|
+
where: { _id: this._.parseId(id), lockedBy: workerId },
|
|
62
|
+
payload: { activeRunId: this._.parseId(runId) }
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
async settleRun(id, runId, status, at) {
|
|
66
|
+
return await this._.updateOne({
|
|
67
|
+
where: { _id: this._.parseId(id), activeRunId: this._.parseId(runId) },
|
|
68
|
+
payload: { lastRunStatus: status, lastRunAt: at, toUnset: { activeRunId: "" } }
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
async renewLease(id, workerId, until) {
|
|
72
|
+
return await this._.updateOne({
|
|
73
|
+
where: { _id: this._.parseId(id), lockedBy: workerId },
|
|
74
|
+
payload: { lockedUntil: until }
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
async release(id, workerId, result) {
|
|
78
|
+
const { activeRunId, lastRunAt, lastRunStatus } = result;
|
|
79
|
+
return await this._.updateOne({
|
|
80
|
+
where: { _id: this._.parseId(id), lockedBy: workerId },
|
|
81
|
+
payload: {
|
|
82
|
+
...lastRunAt ? { lastRunAt } : {},
|
|
83
|
+
...lastRunStatus ? { lastRunStatus } : {},
|
|
84
|
+
...activeRunId ? { activeRunId } : {},
|
|
85
|
+
toUnset: { lockedBy: "", lockedUntil: "", ...activeRunId ? {} : { activeRunId: "" } }
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
unlocked(now) {
|
|
90
|
+
return { $or: [{ lockedUntil: { $exists: false } }, { lockedUntil: null }, { lockedUntil: { $lte: now } }] };
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
AgenticJobRepository = __decorateClass([
|
|
94
|
+
autoInjectable()
|
|
95
|
+
], AgenticJobRepository);
|
|
96
|
+
export {
|
|
97
|
+
AgenticJobRepository
|
|
98
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
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 repositories_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(repositories_exports);
|
|
18
|
+
__reExport(repositories_exports, require("./agentic-job.repository"), module.exports);
|
|
19
|
+
__reExport(repositories_exports, require("./agentic-job-run.repository"), module.exports);
|
|
20
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
21
|
+
0 && (module.exports = {
|
|
22
|
+
...require("./agentic-job.repository"),
|
|
23
|
+
...require("./agentic-job-run.repository")
|
|
24
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { CurrentUser } from '../../../common/base/index.js';
|
|
2
|
+
import { AgentOptions } from '../../../harness/agent.js';
|
|
3
|
+
import { Chat } from '../../chats/entities/chat.entity.js';
|
|
4
|
+
import { AgenticJobProps, AgenticJobRunProps } from '../entities';
|
|
5
|
+
export interface AgenticJobContext {
|
|
6
|
+
job: AgenticJobProps;
|
|
7
|
+
currentUser: CurrentUser;
|
|
8
|
+
}
|
|
9
|
+
export type AgenticJobAgentConfig = Partial<AgentOptions> | ((context: AgenticJobContext) => Partial<AgentOptions> | Promise<Partial<AgentOptions>>);
|
|
10
|
+
export interface AgenticJobRunFinished {
|
|
11
|
+
job: AgenticJobProps;
|
|
12
|
+
run: AgenticJobRunProps;
|
|
13
|
+
chat?: Chat;
|
|
14
|
+
}
|
|
15
|
+
export interface AgenticJobRunnerOptions {
|
|
16
|
+
agent?: AgenticJobAgentConfig;
|
|
17
|
+
intervalMs?: number;
|
|
18
|
+
leaseMs?: number;
|
|
19
|
+
maxConcurrentRuns?: number;
|
|
20
|
+
stopTimeoutMs?: number;
|
|
21
|
+
workerId?: string;
|
|
22
|
+
onRunFinished?: (event: AgenticJobRunFinished) => void | Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export declare class AgenticJobRunner {
|
|
25
|
+
private readonly options;
|
|
26
|
+
readonly workerId: string;
|
|
27
|
+
private readonly logger;
|
|
28
|
+
private readonly inFlight;
|
|
29
|
+
private running;
|
|
30
|
+
private timer?;
|
|
31
|
+
private ticking?;
|
|
32
|
+
private wake?;
|
|
33
|
+
constructor(options?: AgenticJobRunnerOptions);
|
|
34
|
+
start(): void;
|
|
35
|
+
stop(): Promise<void>;
|
|
36
|
+
tick(): Promise<void>;
|
|
37
|
+
runNow(params: {
|
|
38
|
+
jobId: string;
|
|
39
|
+
}): Promise<{
|
|
40
|
+
run: AgenticJobRunProps;
|
|
41
|
+
}>;
|
|
42
|
+
private loop;
|
|
43
|
+
private track;
|
|
44
|
+
private execute;
|
|
45
|
+
private runAgent;
|
|
46
|
+
private notify;
|
|
47
|
+
}
|
|
48
|
+
export declare function createAgenticJobRunner(options?: AgenticJobRunnerOptions): AgenticJobRunner;
|
|
@@ -0,0 +1,181 @@
|
|
|
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_runner_exports = {};
|
|
20
|
+
__export(agentic_job_runner_exports, {
|
|
21
|
+
AgenticJobRunner: () => AgenticJobRunner,
|
|
22
|
+
createAgenticJobRunner: () => createAgenticJobRunner
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(agentic_job_runner_exports);
|
|
25
|
+
var import_node_crypto = require("node:crypto");
|
|
26
|
+
var import_node_os = require("node:os");
|
|
27
|
+
var import_logger = require("../../../common/logger/index.js");
|
|
28
|
+
var import_base = require("../../../common/base/index.js");
|
|
29
|
+
var import_agent = require("../../../harness/agent.js");
|
|
30
|
+
var import_loop = require("../../../loops/agi/loop.js");
|
|
31
|
+
var import_chats = require("../../chats/index.js");
|
|
32
|
+
var import_chat = require("../../chats/entities/chat.entity.js");
|
|
33
|
+
var import_settings = require("../utils/settings");
|
|
34
|
+
var import_claim_due_agentic_jobs = require("../use-cases/claim-due-agentic-jobs.use-case");
|
|
35
|
+
var import_start_agentic_job_run = require("../use-cases/start-agentic-job-run.use-case");
|
|
36
|
+
var import_finish_agentic_job_run = require("../use-cases/finish-agentic-job-run.use-case");
|
|
37
|
+
var import_attach_agentic_job_run_chat = require("../use-cases/attach-agentic-job-run-chat.use-case");
|
|
38
|
+
var import_renew_agentic_job_lease = require("../use-cases/renew-agentic-job-lease.use-case");
|
|
39
|
+
var import_sync_agentic_job_runs = require("../use-cases/sync-agentic-job-runs.use-case");
|
|
40
|
+
var import_tsyringe = require("tsyringe");
|
|
41
|
+
const DEFAULT_MAX_CONCURRENT_RUNS = 3;
|
|
42
|
+
const DEFAULT_STOP_TIMEOUT_MS = 3e4;
|
|
43
|
+
const PAUSED_STATUSES = ["awaiting_user_confirmation", "awaiting_user_input"];
|
|
44
|
+
const newWorkerId = () => `${(0, import_node_os.hostname)()}-${process.pid}-${(0, import_node_crypto.randomBytes)(3).toString("hex")}`;
|
|
45
|
+
class AgenticJobRunner {
|
|
46
|
+
constructor(options = {}) {
|
|
47
|
+
this.options = options;
|
|
48
|
+
this.workerId = options.workerId ?? newWorkerId();
|
|
49
|
+
}
|
|
50
|
+
options;
|
|
51
|
+
workerId;
|
|
52
|
+
logger = new import_logger.Logger();
|
|
53
|
+
inFlight = /* @__PURE__ */ new Set();
|
|
54
|
+
running = false;
|
|
55
|
+
timer;
|
|
56
|
+
ticking;
|
|
57
|
+
wake;
|
|
58
|
+
start() {
|
|
59
|
+
if (this.running) return;
|
|
60
|
+
this.running = true;
|
|
61
|
+
void this.loop();
|
|
62
|
+
}
|
|
63
|
+
async stop() {
|
|
64
|
+
this.running = false;
|
|
65
|
+
if (this.timer) clearTimeout(this.timer);
|
|
66
|
+
this.wake?.();
|
|
67
|
+
await this.ticking;
|
|
68
|
+
const pending = Promise.allSettled([...this.inFlight]);
|
|
69
|
+
const timeoutMs = this.options.stopTimeoutMs ?? DEFAULT_STOP_TIMEOUT_MS;
|
|
70
|
+
let timer;
|
|
71
|
+
await Promise.race([pending, new Promise((resolve) => {
|
|
72
|
+
timer = setTimeout(resolve, timeoutMs);
|
|
73
|
+
})]);
|
|
74
|
+
clearTimeout(timer);
|
|
75
|
+
}
|
|
76
|
+
async tick() {
|
|
77
|
+
const capacity = (this.options.maxConcurrentRuns ?? DEFAULT_MAX_CONCURRENT_RUNS) - this.inFlight.size;
|
|
78
|
+
try {
|
|
79
|
+
await import_tsyringe.container.resolve(import_sync_agentic_job_runs.SyncAgenticJobRunsUseCase).execute({});
|
|
80
|
+
} catch (error) {
|
|
81
|
+
this.logger.error({ error: error?.message ?? error }, "[AGENTIC JOBS] Failed to sync the open runs");
|
|
82
|
+
}
|
|
83
|
+
if (capacity <= 0) return;
|
|
84
|
+
const { data } = await import_tsyringe.container.resolve(import_claim_due_agentic_jobs.ClaimDueAgenticJobsUseCase).execute({ workerId: this.workerId, limit: capacity, leaseMs: this.options.leaseMs ?? (0, import_settings.leaseMs)() });
|
|
85
|
+
for (const { job, run } of data.skipped) await this.notify({ job, run });
|
|
86
|
+
for (const { job, run } of data.claimed) this.track(this.execute(job, run));
|
|
87
|
+
}
|
|
88
|
+
async runNow(params) {
|
|
89
|
+
const { data } = await import_tsyringe.container.resolve(import_start_agentic_job_run.StartAgenticJobRunUseCase).execute({ jobId: params.jobId, workerId: this.workerId, leaseMs: this.options.leaseMs ?? (0, import_settings.leaseMs)() });
|
|
90
|
+
this.track(this.execute(data.job, data.run));
|
|
91
|
+
return { run: data.run };
|
|
92
|
+
}
|
|
93
|
+
async loop() {
|
|
94
|
+
while (this.running) {
|
|
95
|
+
this.ticking = this.tick().catch((error) => {
|
|
96
|
+
this.logger.error({ error: error?.message ?? error }, "[AGENTIC JOBS] The worker failed to check the due jobs");
|
|
97
|
+
});
|
|
98
|
+
await this.ticking;
|
|
99
|
+
if (!this.running) break;
|
|
100
|
+
await new Promise((resolve) => {
|
|
101
|
+
this.wake = resolve;
|
|
102
|
+
this.timer = setTimeout(resolve, this.options.intervalMs ?? (0, import_settings.pollIntervalMs)());
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
track(execution) {
|
|
107
|
+
const tracked = execution.catch((error) => this.logger.error({ error: error?.message ?? error }, "[AGENTIC JOBS] A run could not be completed")).finally(() => this.inFlight.delete(tracked));
|
|
108
|
+
this.inFlight.add(tracked);
|
|
109
|
+
}
|
|
110
|
+
async execute(job, run) {
|
|
111
|
+
const leaseMs = this.options.leaseMs ?? (0, import_settings.leaseMs)();
|
|
112
|
+
const jobId = String(job._id);
|
|
113
|
+
const runId = String(run._id);
|
|
114
|
+
const heartbeat = setInterval(() => {
|
|
115
|
+
import_tsyringe.container.resolve(import_renew_agentic_job_lease.RenewAgenticJobLeaseUseCase).execute({ jobId, workerId: this.workerId, leaseMs }).catch((error2) => {
|
|
116
|
+
this.logger.error({ error: error2?.message ?? error2, jobId }, "[AGENTIC JOBS] Failed to renew the lease of a job");
|
|
117
|
+
});
|
|
118
|
+
}, Math.max(Math.floor(leaseMs / 3), 1e3));
|
|
119
|
+
let status = "failed";
|
|
120
|
+
let error;
|
|
121
|
+
let chat;
|
|
122
|
+
try {
|
|
123
|
+
const outcome = await this.runAgent(job, runId);
|
|
124
|
+
status = outcome.status;
|
|
125
|
+
error = outcome.error;
|
|
126
|
+
chat = outcome.chat;
|
|
127
|
+
} catch (failure) {
|
|
128
|
+
error = { code: failure?.code ?? "RUNNER_ERROR", message: failure?.message ?? String(failure) };
|
|
129
|
+
this.logger.error({ error: error.message, jobId, runId }, "[AGENTIC JOBS] A run failed");
|
|
130
|
+
} finally {
|
|
131
|
+
clearInterval(heartbeat);
|
|
132
|
+
}
|
|
133
|
+
const { data } = await import_tsyringe.container.resolve(import_finish_agentic_job_run.FinishAgenticJobRunUseCase).execute({ runId, workerId: this.workerId, status, error });
|
|
134
|
+
await this.notify({ job, run: data ?? run, chat });
|
|
135
|
+
}
|
|
136
|
+
async runAgent(job, runId) {
|
|
137
|
+
const currentUser = await import_base.CurrentUser.asyncFromDB(String(job.ownerId));
|
|
138
|
+
if (!currentUser) return { status: "failed", error: { code: "OWNER_NOT_FOUND", message: "The owner of the job does not exist" } };
|
|
139
|
+
const configured = typeof this.options.agent === "function" ? await this.options.agent({ job, currentUser }) : this.options.agent ?? {};
|
|
140
|
+
const loop = configured.loop ?? new import_loop.AgiLoop();
|
|
141
|
+
const agent = new import_agent.Agent({ ...configured, loop });
|
|
142
|
+
const model = job.modelProvider && job.modelName ? { modelProvider: job.modelProvider, modelName: job.modelName } : {};
|
|
143
|
+
const draft = import_chat.Chat.withDefaults(loop.name);
|
|
144
|
+
draft.settings?.setExecutionMode("autonomous");
|
|
145
|
+
if (model.modelProvider) draft.settings?.setModelProvider(model.modelProvider);
|
|
146
|
+
if (model.modelName) draft.settings?.setModelName(model.modelName);
|
|
147
|
+
const { data: created } = await (0, import_chats.createChat)({ payload: draft.toJSON(), currentUser });
|
|
148
|
+
const chatId = String(created?._id);
|
|
149
|
+
await import_tsyringe.container.resolve(import_attach_agentic_job_run_chat.AttachAgenticJobRunChatUseCase).execute({ runId, chatId });
|
|
150
|
+
const result = await agent.run({
|
|
151
|
+
input: { message: job.instructions, chatId },
|
|
152
|
+
options: { executionMode: "autonomous", ...model },
|
|
153
|
+
currentUser,
|
|
154
|
+
currentSession: import_base.CurrentSession.fromJSON({ location: { timezone: job.timezone } })
|
|
155
|
+
});
|
|
156
|
+
const chat = result.data;
|
|
157
|
+
const state = chat?.state;
|
|
158
|
+
if (result.error) return { status: "failed", error: { code: state?.lastError?.code ?? "AGENT_RUN_FAILED", message: result.error }, chat };
|
|
159
|
+
if (state?.status === "failed") return { status: "failed", error: { code: state.lastError?.code ?? "AGENT_RUN_FAILED", message: state.lastError?.message ?? "The run failed" }, chat };
|
|
160
|
+
if (state?.status && PAUSED_STATUSES.includes(state.status)) return { status: "paused", chat };
|
|
161
|
+
const blocked = (chat?.tasks.length ?? 0) === 0 && chat?.messages?.at(-1)?.source === "harness";
|
|
162
|
+
if (blocked) return { status: "failed", error: { code: "BLOCKED_BY_GUARDRAIL", message: chat?.lastAnswer ?? "The instructions were blocked by a guardrail" }, chat };
|
|
163
|
+
return { status: "completed", chat };
|
|
164
|
+
}
|
|
165
|
+
async notify(event) {
|
|
166
|
+
if (!this.options.onRunFinished) return;
|
|
167
|
+
try {
|
|
168
|
+
await this.options.onRunFinished(event);
|
|
169
|
+
} catch (error) {
|
|
170
|
+
this.logger.error({ error: error?.message ?? error }, "[AGENTIC JOBS] The onRunFinished callback failed");
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function createAgenticJobRunner(options = {}) {
|
|
175
|
+
return new AgenticJobRunner(options);
|
|
176
|
+
}
|
|
177
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
178
|
+
0 && (module.exports = {
|
|
179
|
+
AgenticJobRunner,
|
|
180
|
+
createAgenticJobRunner
|
|
181
|
+
});
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import "../../../chunk-CF3WOMB3.mjs";
|
|
2
|
+
import { randomBytes } from "node:crypto";
|
|
3
|
+
import { hostname } from "node:os";
|
|
4
|
+
import { Logger } from "../../../common/logger/index.js";
|
|
5
|
+
import { CurrentUser, CurrentSession } from "../../../common/base/index.js";
|
|
6
|
+
import { Agent } from "../../../harness/agent.js";
|
|
7
|
+
import { AgiLoop } from "../../../loops/agi/loop.js";
|
|
8
|
+
import { createChat } from "../../chats/index.js";
|
|
9
|
+
import { Chat } from "../../chats/entities/chat.entity.js";
|
|
10
|
+
import { leaseMs as defaultLeaseMs, pollIntervalMs as defaultPollIntervalMs } from "../utils/settings";
|
|
11
|
+
import { ClaimDueAgenticJobsUseCase } from "../use-cases/claim-due-agentic-jobs.use-case";
|
|
12
|
+
import { StartAgenticJobRunUseCase } from "../use-cases/start-agentic-job-run.use-case";
|
|
13
|
+
import { FinishAgenticJobRunUseCase } from "../use-cases/finish-agentic-job-run.use-case";
|
|
14
|
+
import { AttachAgenticJobRunChatUseCase } from "../use-cases/attach-agentic-job-run-chat.use-case";
|
|
15
|
+
import { RenewAgenticJobLeaseUseCase } from "../use-cases/renew-agentic-job-lease.use-case";
|
|
16
|
+
import { SyncAgenticJobRunsUseCase } from "../use-cases/sync-agentic-job-runs.use-case";
|
|
17
|
+
import { container } from "tsyringe";
|
|
18
|
+
const DEFAULT_MAX_CONCURRENT_RUNS = 3;
|
|
19
|
+
const DEFAULT_STOP_TIMEOUT_MS = 3e4;
|
|
20
|
+
const PAUSED_STATUSES = ["awaiting_user_confirmation", "awaiting_user_input"];
|
|
21
|
+
const newWorkerId = () => `${hostname()}-${process.pid}-${randomBytes(3).toString("hex")}`;
|
|
22
|
+
class AgenticJobRunner {
|
|
23
|
+
constructor(options = {}) {
|
|
24
|
+
this.options = options;
|
|
25
|
+
this.workerId = options.workerId ?? newWorkerId();
|
|
26
|
+
}
|
|
27
|
+
options;
|
|
28
|
+
workerId;
|
|
29
|
+
logger = new Logger();
|
|
30
|
+
inFlight = /* @__PURE__ */ new Set();
|
|
31
|
+
running = false;
|
|
32
|
+
timer;
|
|
33
|
+
ticking;
|
|
34
|
+
wake;
|
|
35
|
+
start() {
|
|
36
|
+
if (this.running) return;
|
|
37
|
+
this.running = true;
|
|
38
|
+
void this.loop();
|
|
39
|
+
}
|
|
40
|
+
async stop() {
|
|
41
|
+
this.running = false;
|
|
42
|
+
if (this.timer) clearTimeout(this.timer);
|
|
43
|
+
this.wake?.();
|
|
44
|
+
await this.ticking;
|
|
45
|
+
const pending = Promise.allSettled([...this.inFlight]);
|
|
46
|
+
const timeoutMs = this.options.stopTimeoutMs ?? DEFAULT_STOP_TIMEOUT_MS;
|
|
47
|
+
let timer;
|
|
48
|
+
await Promise.race([pending, new Promise((resolve) => {
|
|
49
|
+
timer = setTimeout(resolve, timeoutMs);
|
|
50
|
+
})]);
|
|
51
|
+
clearTimeout(timer);
|
|
52
|
+
}
|
|
53
|
+
async tick() {
|
|
54
|
+
const capacity = (this.options.maxConcurrentRuns ?? DEFAULT_MAX_CONCURRENT_RUNS) - this.inFlight.size;
|
|
55
|
+
try {
|
|
56
|
+
await container.resolve(SyncAgenticJobRunsUseCase).execute({});
|
|
57
|
+
} catch (error) {
|
|
58
|
+
this.logger.error({ error: error?.message ?? error }, "[AGENTIC JOBS] Failed to sync the open runs");
|
|
59
|
+
}
|
|
60
|
+
if (capacity <= 0) return;
|
|
61
|
+
const { data } = await container.resolve(ClaimDueAgenticJobsUseCase).execute({ workerId: this.workerId, limit: capacity, leaseMs: this.options.leaseMs ?? defaultLeaseMs() });
|
|
62
|
+
for (const { job, run } of data.skipped) await this.notify({ job, run });
|
|
63
|
+
for (const { job, run } of data.claimed) this.track(this.execute(job, run));
|
|
64
|
+
}
|
|
65
|
+
async runNow(params) {
|
|
66
|
+
const { data } = await container.resolve(StartAgenticJobRunUseCase).execute({ jobId: params.jobId, workerId: this.workerId, leaseMs: this.options.leaseMs ?? defaultLeaseMs() });
|
|
67
|
+
this.track(this.execute(data.job, data.run));
|
|
68
|
+
return { run: data.run };
|
|
69
|
+
}
|
|
70
|
+
async loop() {
|
|
71
|
+
while (this.running) {
|
|
72
|
+
this.ticking = this.tick().catch((error) => {
|
|
73
|
+
this.logger.error({ error: error?.message ?? error }, "[AGENTIC JOBS] The worker failed to check the due jobs");
|
|
74
|
+
});
|
|
75
|
+
await this.ticking;
|
|
76
|
+
if (!this.running) break;
|
|
77
|
+
await new Promise((resolve) => {
|
|
78
|
+
this.wake = resolve;
|
|
79
|
+
this.timer = setTimeout(resolve, this.options.intervalMs ?? defaultPollIntervalMs());
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
track(execution) {
|
|
84
|
+
const tracked = execution.catch((error) => this.logger.error({ error: error?.message ?? error }, "[AGENTIC JOBS] A run could not be completed")).finally(() => this.inFlight.delete(tracked));
|
|
85
|
+
this.inFlight.add(tracked);
|
|
86
|
+
}
|
|
87
|
+
async execute(job, run) {
|
|
88
|
+
const leaseMs = this.options.leaseMs ?? defaultLeaseMs();
|
|
89
|
+
const jobId = String(job._id);
|
|
90
|
+
const runId = String(run._id);
|
|
91
|
+
const heartbeat = setInterval(() => {
|
|
92
|
+
container.resolve(RenewAgenticJobLeaseUseCase).execute({ jobId, workerId: this.workerId, leaseMs }).catch((error2) => {
|
|
93
|
+
this.logger.error({ error: error2?.message ?? error2, jobId }, "[AGENTIC JOBS] Failed to renew the lease of a job");
|
|
94
|
+
});
|
|
95
|
+
}, Math.max(Math.floor(leaseMs / 3), 1e3));
|
|
96
|
+
let status = "failed";
|
|
97
|
+
let error;
|
|
98
|
+
let chat;
|
|
99
|
+
try {
|
|
100
|
+
const outcome = await this.runAgent(job, runId);
|
|
101
|
+
status = outcome.status;
|
|
102
|
+
error = outcome.error;
|
|
103
|
+
chat = outcome.chat;
|
|
104
|
+
} catch (failure) {
|
|
105
|
+
error = { code: failure?.code ?? "RUNNER_ERROR", message: failure?.message ?? String(failure) };
|
|
106
|
+
this.logger.error({ error: error.message, jobId, runId }, "[AGENTIC JOBS] A run failed");
|
|
107
|
+
} finally {
|
|
108
|
+
clearInterval(heartbeat);
|
|
109
|
+
}
|
|
110
|
+
const { data } = await container.resolve(FinishAgenticJobRunUseCase).execute({ runId, workerId: this.workerId, status, error });
|
|
111
|
+
await this.notify({ job, run: data ?? run, chat });
|
|
112
|
+
}
|
|
113
|
+
async runAgent(job, runId) {
|
|
114
|
+
const currentUser = await CurrentUser.asyncFromDB(String(job.ownerId));
|
|
115
|
+
if (!currentUser) return { status: "failed", error: { code: "OWNER_NOT_FOUND", message: "The owner of the job does not exist" } };
|
|
116
|
+
const configured = typeof this.options.agent === "function" ? await this.options.agent({ job, currentUser }) : this.options.agent ?? {};
|
|
117
|
+
const loop = configured.loop ?? new AgiLoop();
|
|
118
|
+
const agent = new Agent({ ...configured, loop });
|
|
119
|
+
const model = job.modelProvider && job.modelName ? { modelProvider: job.modelProvider, modelName: job.modelName } : {};
|
|
120
|
+
const draft = Chat.withDefaults(loop.name);
|
|
121
|
+
draft.settings?.setExecutionMode("autonomous");
|
|
122
|
+
if (model.modelProvider) draft.settings?.setModelProvider(model.modelProvider);
|
|
123
|
+
if (model.modelName) draft.settings?.setModelName(model.modelName);
|
|
124
|
+
const { data: created } = await createChat({ payload: draft.toJSON(), currentUser });
|
|
125
|
+
const chatId = String(created?._id);
|
|
126
|
+
await container.resolve(AttachAgenticJobRunChatUseCase).execute({ runId, chatId });
|
|
127
|
+
const result = await agent.run({
|
|
128
|
+
input: { message: job.instructions, chatId },
|
|
129
|
+
options: { executionMode: "autonomous", ...model },
|
|
130
|
+
currentUser,
|
|
131
|
+
currentSession: CurrentSession.fromJSON({ location: { timezone: job.timezone } })
|
|
132
|
+
});
|
|
133
|
+
const chat = result.data;
|
|
134
|
+
const state = chat?.state;
|
|
135
|
+
if (result.error) return { status: "failed", error: { code: state?.lastError?.code ?? "AGENT_RUN_FAILED", message: result.error }, chat };
|
|
136
|
+
if (state?.status === "failed") return { status: "failed", error: { code: state.lastError?.code ?? "AGENT_RUN_FAILED", message: state.lastError?.message ?? "The run failed" }, chat };
|
|
137
|
+
if (state?.status && PAUSED_STATUSES.includes(state.status)) return { status: "paused", chat };
|
|
138
|
+
const blocked = (chat?.tasks.length ?? 0) === 0 && chat?.messages?.at(-1)?.source === "harness";
|
|
139
|
+
if (blocked) return { status: "failed", error: { code: "BLOCKED_BY_GUARDRAIL", message: chat?.lastAnswer ?? "The instructions were blocked by a guardrail" }, chat };
|
|
140
|
+
return { status: "completed", chat };
|
|
141
|
+
}
|
|
142
|
+
async notify(event) {
|
|
143
|
+
if (!this.options.onRunFinished) return;
|
|
144
|
+
try {
|
|
145
|
+
await this.options.onRunFinished(event);
|
|
146
|
+
} catch (error) {
|
|
147
|
+
this.logger.error({ error: error?.message ?? error }, "[AGENTIC JOBS] The onRunFinished callback failed");
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function createAgenticJobRunner(options = {}) {
|
|
152
|
+
return new AgenticJobRunner(options);
|
|
153
|
+
}
|
|
154
|
+
export {
|
|
155
|
+
AgenticJobRunner,
|
|
156
|
+
createAgenticJobRunner
|
|
157
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseUseCase, BaseUseCaseParams, BaseUseCaseOutput } from '../../../common/base/base.use-case.js';
|
|
2
|
+
import { AgenticJobRunProps } from '../entities';
|
|
3
|
+
import { AgenticJobRunRepository } from '../repositories';
|
|
4
|
+
export interface Params extends BaseUseCaseParams {
|
|
5
|
+
runId: string;
|
|
6
|
+
chatId: string;
|
|
7
|
+
}
|
|
8
|
+
export interface Output extends BaseUseCaseOutput {
|
|
9
|
+
data: AgenticJobRunProps | null;
|
|
10
|
+
}
|
|
11
|
+
export declare class AttachAgenticJobRunChatUseCase extends BaseUseCase<Params, Output> {
|
|
12
|
+
private readonly agenticJobRunRepository?;
|
|
13
|
+
constructor(agenticJobRunRepository?: AgenticJobRunRepository | undefined);
|
|
14
|
+
execute(params: Params): Promise<Output>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
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 __decorateClass = (decorators, target, key, kind) => {
|
|
20
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
21
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
22
|
+
if (decorator = decorators[i])
|
|
23
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
24
|
+
if (kind && result) __defProp(target, key, result);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
28
|
+
var attach_agentic_job_run_chat_use_case_exports = {};
|
|
29
|
+
__export(attach_agentic_job_run_chat_use_case_exports, {
|
|
30
|
+
AttachAgenticJobRunChatUseCase: () => AttachAgenticJobRunChatUseCase
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(attach_agentic_job_run_chat_use_case_exports);
|
|
33
|
+
var import_tsyringe = require("tsyringe");
|
|
34
|
+
var import_base = require("../../../common/base/base.use-case.js");
|
|
35
|
+
var import_entities = require("../entities");
|
|
36
|
+
var import_repositories = require("../repositories");
|
|
37
|
+
let AttachAgenticJobRunChatUseCase = class extends import_base.BaseUseCase {
|
|
38
|
+
constructor(agenticJobRunRepository) {
|
|
39
|
+
super();
|
|
40
|
+
this.agenticJobRunRepository = agenticJobRunRepository;
|
|
41
|
+
}
|
|
42
|
+
agenticJobRunRepository;
|
|
43
|
+
async execute(params) {
|
|
44
|
+
const { runId, chatId } = params;
|
|
45
|
+
const run = await this.agenticJobRunRepository.findById(runId);
|
|
46
|
+
if (!run) return { data: null };
|
|
47
|
+
const saved = await this.agenticJobRunRepository.update(import_entities.AgenticJobRun.fromJSON({ ...run, chatId }));
|
|
48
|
+
return { data: saved };
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
AttachAgenticJobRunChatUseCase = __decorateClass([
|
|
52
|
+
(0, import_tsyringe.autoInjectable)(),
|
|
53
|
+
__decorateParam(0, (0, import_tsyringe.inject)(import_repositories.AgenticJobRunRepository))
|
|
54
|
+
], AttachAgenticJobRunChatUseCase);
|
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
+
0 && (module.exports = {
|
|
57
|
+
AttachAgenticJobRunChatUseCase
|
|
58
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__decorateClass,
|
|
3
|
+
__decorateParam
|
|
4
|
+
} from "../../../chunk-CF3WOMB3.mjs";
|
|
5
|
+
import { autoInjectable, inject } from "tsyringe";
|
|
6
|
+
import { BaseUseCase } from "../../../common/base/base.use-case.js";
|
|
7
|
+
import { AgenticJobRun } from "../entities";
|
|
8
|
+
import { AgenticJobRunRepository } from "../repositories";
|
|
9
|
+
let AttachAgenticJobRunChatUseCase = class extends BaseUseCase {
|
|
10
|
+
constructor(agenticJobRunRepository) {
|
|
11
|
+
super();
|
|
12
|
+
this.agenticJobRunRepository = agenticJobRunRepository;
|
|
13
|
+
}
|
|
14
|
+
agenticJobRunRepository;
|
|
15
|
+
async execute(params) {
|
|
16
|
+
const { runId, chatId } = params;
|
|
17
|
+
const run = await this.agenticJobRunRepository.findById(runId);
|
|
18
|
+
if (!run) return { data: null };
|
|
19
|
+
const saved = await this.agenticJobRunRepository.update(AgenticJobRun.fromJSON({ ...run, chatId }));
|
|
20
|
+
return { data: saved };
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
AttachAgenticJobRunChatUseCase = __decorateClass([
|
|
24
|
+
autoInjectable(),
|
|
25
|
+
__decorateParam(0, inject(AgenticJobRunRepository))
|
|
26
|
+
], AttachAgenticJobRunChatUseCase);
|
|
27
|
+
export {
|
|
28
|
+
AttachAgenticJobRunChatUseCase
|
|
29
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { BaseUseCase, BaseUseCaseParams, BaseUseCaseOutput } from '../../../common/base/base.use-case.js';
|
|
2
|
+
import { AgenticJobProps, AgenticJobRunProps } from '../entities';
|
|
3
|
+
import { AgenticJobRepository, AgenticJobRunRepository } from '../repositories';
|
|
4
|
+
import { SyncAgenticJobRunUseCase } from './sync-agentic-job-run.use-case';
|
|
5
|
+
export interface Params extends BaseUseCaseParams {
|
|
6
|
+
workerId: string;
|
|
7
|
+
limit?: number;
|
|
8
|
+
leaseMs?: number;
|
|
9
|
+
now?: Date;
|
|
10
|
+
}
|
|
11
|
+
export interface ClaimedRun {
|
|
12
|
+
job: AgenticJobProps;
|
|
13
|
+
run: AgenticJobRunProps;
|
|
14
|
+
}
|
|
15
|
+
export interface Output extends BaseUseCaseOutput {
|
|
16
|
+
data: {
|
|
17
|
+
claimed: ClaimedRun[];
|
|
18
|
+
skipped: ClaimedRun[];
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export declare class ClaimDueAgenticJobsUseCase extends BaseUseCase<Params, Output> {
|
|
22
|
+
private readonly agenticJobRepository?;
|
|
23
|
+
private readonly agenticJobRunRepository?;
|
|
24
|
+
private readonly syncRun?;
|
|
25
|
+
private readonly log;
|
|
26
|
+
constructor(agenticJobRepository?: AgenticJobRepository | undefined, agenticJobRunRepository?: AgenticJobRunRepository | undefined, syncRun?: SyncAgenticJobRunUseCase | undefined);
|
|
27
|
+
execute(params: Params): Promise<Output>;
|
|
28
|
+
private previousRun;
|
|
29
|
+
}
|