@agentium/queue 4.1.0 → 4.5.0
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/dist/connection.d.cts +27 -0
- package/dist/durable.d.cts +58 -0
- package/dist/index.d.cts +9 -0
- package/dist/job-producer.d.cts +132 -0
- package/dist/job-types.d.cts +43 -0
- package/dist/job-worker.d.cts +22 -0
- package/dist/progress.d.cts +3 -0
- package/package.json +11 -6
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare function queueConnection(value: string | {
|
|
2
|
+
host: string;
|
|
3
|
+
port: number;
|
|
4
|
+
password?: string;
|
|
5
|
+
db?: number;
|
|
6
|
+
tls?: boolean;
|
|
7
|
+
}): {
|
|
8
|
+
tls: {};
|
|
9
|
+
host: string;
|
|
10
|
+
port: number;
|
|
11
|
+
password?: string;
|
|
12
|
+
db?: number;
|
|
13
|
+
} | {
|
|
14
|
+
tls: undefined;
|
|
15
|
+
host: string;
|
|
16
|
+
port: number;
|
|
17
|
+
password?: string;
|
|
18
|
+
db?: number;
|
|
19
|
+
} | {
|
|
20
|
+
tls?: {} | undefined;
|
|
21
|
+
password?: string | undefined;
|
|
22
|
+
username?: string | undefined;
|
|
23
|
+
host: string;
|
|
24
|
+
port: number;
|
|
25
|
+
db: number;
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=connection.d.ts.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type DurableTaskHandler, type DurableTaskInput, type DurableTaskKey, type DurableTaskRecord, type DurableTaskSupervisor } from "@agentium/core";
|
|
2
|
+
import type { QueueConfig } from "./job-producer.cjs";
|
|
3
|
+
export interface DurableJobEnvelope {
|
|
4
|
+
schemaVersion: 1;
|
|
5
|
+
type: "durable";
|
|
6
|
+
tenantId: string;
|
|
7
|
+
taskId: string;
|
|
8
|
+
inputDigest: string;
|
|
9
|
+
}
|
|
10
|
+
export interface DurableDriverRegistration {
|
|
11
|
+
id: string;
|
|
12
|
+
version: number;
|
|
13
|
+
/** Explicit host assertion: resumes use stable action IDs and reconcile uncertain effects. */
|
|
14
|
+
recoverable: true;
|
|
15
|
+
execute: DurableTaskHandler;
|
|
16
|
+
}
|
|
17
|
+
export interface DurableQueueConfig extends QueueConfig {
|
|
18
|
+
supervisor: DurableTaskSupervisor;
|
|
19
|
+
/** Verify identity, definition, policy and grants before writing any task/queue record. */
|
|
20
|
+
admit: (task: Readonly<DurableTaskInput>) => Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
/** Queue delivery is a hint; Mongo/another atomic task store owns authoritative state.
|
|
23
|
+
* Persistence precedes enqueue. If Redis fails, call wake() after retrying admission.
|
|
24
|
+
* The stable task key prevents a delivery retry from creating a second execution.
|
|
25
|
+
*/
|
|
26
|
+
export declare class DurableAgentQueue {
|
|
27
|
+
private readonly config;
|
|
28
|
+
private queue;
|
|
29
|
+
constructor(config: DurableQueueConfig);
|
|
30
|
+
enqueue(task: DurableTaskInput): Promise<{
|
|
31
|
+
taskId: string;
|
|
32
|
+
deliveryId: string;
|
|
33
|
+
}>;
|
|
34
|
+
/** Explicit re-delivery after approval, reconciliation, or a failed initial enqueue. */
|
|
35
|
+
wake(key: DurableTaskKey): Promise<{
|
|
36
|
+
taskId: string;
|
|
37
|
+
deliveryId: string;
|
|
38
|
+
}>;
|
|
39
|
+
cancel(key: DurableTaskKey, reason?: string): Promise<void>;
|
|
40
|
+
close(): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
export interface DurableWorkerConfig extends Omit<QueueConfig, "defaultJobOptions"> {
|
|
43
|
+
supervisor: DurableTaskSupervisor;
|
|
44
|
+
workerId?: string;
|
|
45
|
+
concurrency?: number;
|
|
46
|
+
drivers: readonly DurableDriverRegistration[];
|
|
47
|
+
/** Revalidate policy/grants from authoritative host state; a payload is not authentication. */
|
|
48
|
+
admit: (task: Readonly<DurableTaskRecord>) => Promise<void>;
|
|
49
|
+
/** Observe delivery failures; durable task outcome remains available from the store. */
|
|
50
|
+
onError?: (error: Error) => void;
|
|
51
|
+
}
|
|
52
|
+
export declare class DurableAgentWorker {
|
|
53
|
+
private worker;
|
|
54
|
+
constructor(config: DurableWorkerConfig);
|
|
55
|
+
/** Drains owned work. Active durable cancellation is explicit through queue.cancel(). */
|
|
56
|
+
stop(): Promise<void>;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=durable.d.ts.map
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type { DurableDriverRegistration, DurableJobEnvelope, DurableQueueConfig, DurableWorkerConfig, } from "./durable.cjs";
|
|
2
|
+
export { DurableAgentQueue, DurableAgentWorker } from "./durable.cjs";
|
|
3
|
+
export type { QueueConfig, ScheduleOptions } from "./job-producer.cjs";
|
|
4
|
+
export { AgentQueue } from "./job-producer.cjs";
|
|
5
|
+
export type { AgentJobPayload, JobPayload, JobStatus, ScheduleInfo, TeamJobPayload, WorkflowJobPayload, } from "./job-types.cjs";
|
|
6
|
+
export type { WorkerConfig } from "./job-worker.cjs";
|
|
7
|
+
export { AgentWorker } from "./job-worker.cjs";
|
|
8
|
+
export { bridgeEventBusToJob } from "./progress.cjs";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { RunOutput } from "@agentium/core";
|
|
2
|
+
import type { JobStatus, ScheduleInfo } from "./job-types.cjs";
|
|
3
|
+
export interface ScheduleOptions {
|
|
4
|
+
id: string;
|
|
5
|
+
cron: string;
|
|
6
|
+
timezone?: string;
|
|
7
|
+
agent?: {
|
|
8
|
+
name: string;
|
|
9
|
+
input: string;
|
|
10
|
+
sessionId?: string;
|
|
11
|
+
userId?: string;
|
|
12
|
+
tenantId?: string;
|
|
13
|
+
};
|
|
14
|
+
workflow?: {
|
|
15
|
+
name: string;
|
|
16
|
+
initialState?: Record<string, unknown>;
|
|
17
|
+
sessionId?: string;
|
|
18
|
+
userId?: string;
|
|
19
|
+
tenantId?: string;
|
|
20
|
+
};
|
|
21
|
+
team?: {
|
|
22
|
+
name: string;
|
|
23
|
+
input: string;
|
|
24
|
+
sessionId?: string;
|
|
25
|
+
userId?: string;
|
|
26
|
+
tenantId?: string;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export interface QueueConfig {
|
|
30
|
+
connection: {
|
|
31
|
+
host: string;
|
|
32
|
+
port: number;
|
|
33
|
+
password?: string;
|
|
34
|
+
db?: number;
|
|
35
|
+
tls?: boolean;
|
|
36
|
+
} | string;
|
|
37
|
+
queueName?: string;
|
|
38
|
+
defaultJobOptions?: Record<string, unknown>;
|
|
39
|
+
}
|
|
40
|
+
export declare class AgentQueue {
|
|
41
|
+
private queue;
|
|
42
|
+
private queueEvents;
|
|
43
|
+
private queueName;
|
|
44
|
+
constructor(config: QueueConfig);
|
|
45
|
+
enqueueAgentRun(opts: {
|
|
46
|
+
agentName: string;
|
|
47
|
+
input: string;
|
|
48
|
+
sessionId?: string;
|
|
49
|
+
tenantId?: string;
|
|
50
|
+
userId?: string;
|
|
51
|
+
priority?: number;
|
|
52
|
+
delay?: number;
|
|
53
|
+
attempts?: number;
|
|
54
|
+
backoff?: {
|
|
55
|
+
type: "exponential" | "fixed";
|
|
56
|
+
delay: number;
|
|
57
|
+
};
|
|
58
|
+
repeat?: {
|
|
59
|
+
pattern: string;
|
|
60
|
+
timezone?: string;
|
|
61
|
+
};
|
|
62
|
+
}): Promise<{
|
|
63
|
+
jobId: string;
|
|
64
|
+
}>;
|
|
65
|
+
enqueueWorkflow(opts: {
|
|
66
|
+
workflowName: string;
|
|
67
|
+
userId?: string;
|
|
68
|
+
initialState?: Record<string, unknown>;
|
|
69
|
+
sessionId?: string;
|
|
70
|
+
tenantId?: string;
|
|
71
|
+
priority?: number;
|
|
72
|
+
delay?: number;
|
|
73
|
+
attempts?: number;
|
|
74
|
+
backoff?: {
|
|
75
|
+
type: "exponential" | "fixed";
|
|
76
|
+
delay: number;
|
|
77
|
+
};
|
|
78
|
+
repeat?: {
|
|
79
|
+
pattern: string;
|
|
80
|
+
timezone?: string;
|
|
81
|
+
};
|
|
82
|
+
}): Promise<{
|
|
83
|
+
jobId: string;
|
|
84
|
+
}>;
|
|
85
|
+
enqueueTeamRun(opts: {
|
|
86
|
+
teamName: string;
|
|
87
|
+
input: string;
|
|
88
|
+
sessionId?: string;
|
|
89
|
+
tenantId?: string;
|
|
90
|
+
userId?: string;
|
|
91
|
+
priority?: number;
|
|
92
|
+
delay?: number;
|
|
93
|
+
attempts?: number;
|
|
94
|
+
backoff?: {
|
|
95
|
+
type: "exponential" | "fixed";
|
|
96
|
+
delay: number;
|
|
97
|
+
};
|
|
98
|
+
repeat?: {
|
|
99
|
+
pattern: string;
|
|
100
|
+
timezone?: string;
|
|
101
|
+
};
|
|
102
|
+
}): Promise<{
|
|
103
|
+
jobId: string;
|
|
104
|
+
}>;
|
|
105
|
+
getJobStatus(jobId: string): Promise<JobStatus>;
|
|
106
|
+
cancelJob(jobId: string): Promise<void>;
|
|
107
|
+
onCompleted(handler: (jobId: string, result: RunOutput) => void): void;
|
|
108
|
+
onFailed(handler: (jobId: string, error: Error) => void): void;
|
|
109
|
+
private enqueueRecurring;
|
|
110
|
+
private schedulerRecords;
|
|
111
|
+
private hasLegacyMaintenance;
|
|
112
|
+
private assertNoLegacySchedule;
|
|
113
|
+
schedule(opts: ScheduleOptions): Promise<{
|
|
114
|
+
jobId: string;
|
|
115
|
+
}>;
|
|
116
|
+
unschedule(id: string): Promise<void>;
|
|
117
|
+
listSchedules(): Promise<ScheduleInfo[]>;
|
|
118
|
+
/** BullMQ v5 maintenance only. Never silently converts persisted legacy repeat records. */
|
|
119
|
+
listLegacySchedules(): Promise<Array<{
|
|
120
|
+
key: string;
|
|
121
|
+
name: string;
|
|
122
|
+
pattern?: string;
|
|
123
|
+
timezone?: string;
|
|
124
|
+
next: number;
|
|
125
|
+
}>>;
|
|
126
|
+
pause(): Promise<void>;
|
|
127
|
+
resume(): Promise<void>;
|
|
128
|
+
/** Maintenance-only removal: callers retain inventory/payload backups and stop concurrent schedule writers. */
|
|
129
|
+
removeLegacySchedule(key: string): Promise<void>;
|
|
130
|
+
close(): Promise<void>;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=job-producer.d.ts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { RunOutput } from "@agentium/core";
|
|
2
|
+
export type AgentJobPayload = {
|
|
3
|
+
type: "agent";
|
|
4
|
+
agentName: string;
|
|
5
|
+
input: string;
|
|
6
|
+
sessionId?: string;
|
|
7
|
+
tenantId?: string;
|
|
8
|
+
userId?: string;
|
|
9
|
+
};
|
|
10
|
+
export type WorkflowJobPayload = {
|
|
11
|
+
type: "workflow";
|
|
12
|
+
workflowName: string;
|
|
13
|
+
initialState?: Record<string, unknown>;
|
|
14
|
+
userId?: string;
|
|
15
|
+
sessionId?: string;
|
|
16
|
+
tenantId?: string;
|
|
17
|
+
};
|
|
18
|
+
export type TeamJobPayload = {
|
|
19
|
+
type: "team";
|
|
20
|
+
teamName: string;
|
|
21
|
+
input: string;
|
|
22
|
+
sessionId?: string;
|
|
23
|
+
tenantId?: string;
|
|
24
|
+
userId?: string;
|
|
25
|
+
};
|
|
26
|
+
export type JobPayload = AgentJobPayload | WorkflowJobPayload | TeamJobPayload;
|
|
27
|
+
export type ScheduleInfo = {
|
|
28
|
+
id: string;
|
|
29
|
+
pattern: string;
|
|
30
|
+
timezone?: string;
|
|
31
|
+
next: Date;
|
|
32
|
+
};
|
|
33
|
+
export type JobStatus = {
|
|
34
|
+
jobId: string;
|
|
35
|
+
state: "waiting" | "active" | "completed" | "failed" | "delayed";
|
|
36
|
+
progress?: number;
|
|
37
|
+
result?: RunOutput;
|
|
38
|
+
error?: string;
|
|
39
|
+
createdAt: Date;
|
|
40
|
+
processedAt?: Date;
|
|
41
|
+
finishedAt?: Date;
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=job-types.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Agent, Workflow } from "@agentium/core";
|
|
2
|
+
export interface WorkerConfig {
|
|
3
|
+
connection: {
|
|
4
|
+
host: string;
|
|
5
|
+
port: number;
|
|
6
|
+
password?: string;
|
|
7
|
+
db?: number;
|
|
8
|
+
tls?: boolean;
|
|
9
|
+
} | string;
|
|
10
|
+
queueName?: string;
|
|
11
|
+
concurrency?: number;
|
|
12
|
+
agentRegistry: Record<string, Agent>;
|
|
13
|
+
workflowRegistry?: Record<string, Workflow<any>>;
|
|
14
|
+
teamRegistry?: Record<string, import("@agentium/core").Team>;
|
|
15
|
+
}
|
|
16
|
+
export declare class AgentWorker {
|
|
17
|
+
private worker;
|
|
18
|
+
constructor(config: WorkerConfig);
|
|
19
|
+
start(): void;
|
|
20
|
+
stop(timeoutMs?: number): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=job-worker.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentium/queue",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.0",
|
|
4
4
|
"description": "Background job processing for Agentium agents using BullMQ",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -25,9 +25,14 @@
|
|
|
25
25
|
"types": "./dist/index.d.ts",
|
|
26
26
|
"exports": {
|
|
27
27
|
".": {
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
"import": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"default": "./dist/index.js"
|
|
31
|
+
},
|
|
32
|
+
"require": {
|
|
33
|
+
"types": "./dist/index.d.cts",
|
|
34
|
+
"default": "./dist/index.cjs"
|
|
35
|
+
},
|
|
31
36
|
"default": "./dist/index.js"
|
|
32
37
|
}
|
|
33
38
|
},
|
|
@@ -35,7 +40,7 @@
|
|
|
35
40
|
"dist"
|
|
36
41
|
],
|
|
37
42
|
"scripts": {
|
|
38
|
-
"build": "tsdown --config ../../tsdown.config.ts && tsc -p tsconfig.build.json --emitDeclarationOnly --declaration --pretty false",
|
|
43
|
+
"build": "tsdown --config ../../tsdown.config.ts && tsc -p tsconfig.build.json --emitDeclarationOnly --declaration --pretty false && node ../../scripts/cjs-declarations.mjs",
|
|
39
44
|
"dev": "tsdown --config ../../tsdown.config.ts --watch",
|
|
40
45
|
"prepublishOnly": "npm run build"
|
|
41
46
|
},
|
|
@@ -45,7 +50,7 @@
|
|
|
45
50
|
"tsdown": "0.23.0"
|
|
46
51
|
},
|
|
47
52
|
"peerDependencies": {
|
|
48
|
-
"@agentium/core": "^4.
|
|
53
|
+
"@agentium/core": "^4.5.0",
|
|
49
54
|
"bullmq": "^5.81.5 || ^6.3.11",
|
|
50
55
|
"ioredis": "^5.0.0"
|
|
51
56
|
},
|