@axiom-lattice/protocols 2.1.7 → 2.1.8
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/.turbo/turbo-build.log +9 -9
- package/CHANGELOG.md +6 -0
- package/dist/index.d.mts +250 -42
- package/dist/index.d.ts +250 -42
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +18 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/AgentLatticeProtocol.ts +16 -0
- package/src/ScheduleLatticeProtocol.ts +331 -52
|
@@ -18,6 +18,17 @@ export enum AgentType {
|
|
|
18
18
|
SEQUENTIAL = "sequential",
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Runtime configuration that will be injected into LangGraphRunnableConfig.configurable
|
|
23
|
+
* Tools can access these values via config.configurable.runConfig
|
|
24
|
+
*/
|
|
25
|
+
export interface AgentRunConfig {
|
|
26
|
+
/** Database key for SQL tools (registered via sqlDatabaseManager) */
|
|
27
|
+
databaseKey?: string;
|
|
28
|
+
/** Any additional runtime configuration */
|
|
29
|
+
[key: string]: any;
|
|
30
|
+
}
|
|
31
|
+
|
|
21
32
|
/**
|
|
22
33
|
* Base agent configuration shared by all agent types
|
|
23
34
|
*/
|
|
@@ -28,6 +39,11 @@ interface BaseAgentConfig {
|
|
|
28
39
|
prompt: string; // Prompt
|
|
29
40
|
schema?: ZodObject<any, any, any, any, any>; // Input validation schema
|
|
30
41
|
modelKey?: string; // Model key to use
|
|
42
|
+
/**
|
|
43
|
+
* Runtime configuration to inject into tool execution context
|
|
44
|
+
* Will be available in tools via config.configurable.runConfig
|
|
45
|
+
*/
|
|
46
|
+
runConfig?: AgentRunConfig;
|
|
31
47
|
}
|
|
32
48
|
|
|
33
49
|
/**
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ScheduleLatticeProtocol
|
|
3
3
|
*
|
|
4
|
-
* Schedule Lattice protocol for delayed task execution management
|
|
4
|
+
* Schedule Lattice protocol for delayed and recurring task execution management
|
|
5
|
+
* Supports persistence and recovery after service restart
|
|
6
|
+
* Supports both one-time delayed tasks and cron-style recurring tasks
|
|
5
7
|
*/
|
|
6
8
|
|
|
7
9
|
import { BaseLatticeProtocol } from "./BaseLatticeProtocol";
|
|
@@ -11,87 +13,342 @@ import { BaseLatticeProtocol } from "./BaseLatticeProtocol";
|
|
|
11
13
|
*/
|
|
12
14
|
export enum ScheduleType {
|
|
13
15
|
MEMORY = "memory",
|
|
14
|
-
|
|
16
|
+
POSTGRES = "postgres",
|
|
17
|
+
REDIS = "redis",
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Schedule execution type - one-time or recurring
|
|
22
|
+
*/
|
|
23
|
+
export enum ScheduleExecutionType {
|
|
24
|
+
ONCE = "once", // Execute once at specified time
|
|
25
|
+
CRON = "cron", // Recurring based on cron expression
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Task status enumeration
|
|
30
|
+
*/
|
|
31
|
+
export enum ScheduledTaskStatus {
|
|
32
|
+
PENDING = "pending", // Waiting to be executed
|
|
33
|
+
RUNNING = "running", // Currently executing
|
|
34
|
+
COMPLETED = "completed", // Successfully completed (for ONCE type)
|
|
35
|
+
FAILED = "failed", // Execution failed
|
|
36
|
+
CANCELLED = "cancelled", // Manually cancelled
|
|
37
|
+
PAUSED = "paused", // Paused (for CRON type)
|
|
15
38
|
}
|
|
16
39
|
|
|
17
40
|
/**
|
|
18
41
|
* Schedule configuration interface
|
|
19
42
|
*/
|
|
20
43
|
export interface ScheduleConfig {
|
|
21
|
-
name: string;
|
|
22
|
-
description: string;
|
|
23
|
-
type: ScheduleType;
|
|
24
|
-
|
|
44
|
+
name: string;
|
|
45
|
+
description: string;
|
|
46
|
+
type: ScheduleType;
|
|
47
|
+
storage?: ScheduleStorage; // Optional storage for persistence
|
|
48
|
+
options?: Record<string, any>;
|
|
25
49
|
}
|
|
26
50
|
|
|
27
51
|
/**
|
|
28
|
-
* Scheduled task
|
|
52
|
+
* Scheduled task definition - fully serializable
|
|
53
|
+
* Supports both one-time and cron-style recurring tasks
|
|
29
54
|
*/
|
|
30
|
-
export interface
|
|
55
|
+
export interface ScheduledTaskDefinition {
|
|
31
56
|
taskId: string;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
57
|
+
taskType: string; // Maps to a registered handler
|
|
58
|
+
payload: Record<string, any>; // JSON-serializable data passed to handler
|
|
59
|
+
|
|
60
|
+
// Context fields for querying
|
|
61
|
+
assistantId?: string; // Which assistant created/owns this task
|
|
62
|
+
threadId?: string; // Which thread this task belongs to
|
|
63
|
+
|
|
64
|
+
// Execution configuration
|
|
65
|
+
executionType: ScheduleExecutionType;
|
|
66
|
+
|
|
67
|
+
// For ONCE type - execute at specific time or after delay
|
|
68
|
+
executeAt?: number; // Timestamp when to execute
|
|
69
|
+
delayMs?: number; // Original delay in milliseconds (for reference)
|
|
70
|
+
|
|
71
|
+
// For CRON type - recurring schedule
|
|
72
|
+
cronExpression?: string; // Cron format: "0 9 * * *" (min hour day month weekday)
|
|
73
|
+
timezone?: string; // Timezone: "Asia/Shanghai", defaults to system timezone
|
|
74
|
+
nextRunAt?: number; // Next calculated execution time
|
|
75
|
+
lastRunAt?: number; // Last execution time
|
|
76
|
+
|
|
77
|
+
// Execution tracking
|
|
78
|
+
status: ScheduledTaskStatus;
|
|
79
|
+
runCount: number; // How many times executed
|
|
80
|
+
maxRuns?: number; // Max executions (null/undefined = infinite for cron, 1 for once)
|
|
81
|
+
|
|
82
|
+
// Error handling
|
|
83
|
+
retryCount: number; // Current retry count
|
|
84
|
+
maxRetries: number; // Maximum retry attempts
|
|
85
|
+
lastError?: string; // Last error message if failed
|
|
86
|
+
|
|
87
|
+
// Timestamps
|
|
88
|
+
createdAt: number;
|
|
89
|
+
updatedAt: number;
|
|
90
|
+
expiresAt?: number; // When to stop (for cron, optional)
|
|
91
|
+
|
|
92
|
+
metadata?: Record<string, any>; // Additional metadata
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Task handler function type
|
|
97
|
+
*/
|
|
98
|
+
export type TaskHandler = (
|
|
99
|
+
payload: Record<string, any>,
|
|
100
|
+
taskInfo: ScheduledTaskDefinition
|
|
101
|
+
) => void | Promise<void>;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Options for scheduling a one-time task
|
|
105
|
+
*/
|
|
106
|
+
export interface ScheduleOnceOptions {
|
|
107
|
+
executeAt?: number; // Absolute timestamp to execute
|
|
108
|
+
delayMs?: number; // OR relative delay from now
|
|
109
|
+
maxRetries?: number; // Max retry attempts (default: 0)
|
|
110
|
+
assistantId?: string; // Which assistant created/owns this task
|
|
111
|
+
threadId?: string; // Which thread this task belongs to
|
|
112
|
+
metadata?: Record<string, any>;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Options for scheduling a cron task
|
|
117
|
+
*/
|
|
118
|
+
export interface ScheduleCronOptions {
|
|
119
|
+
cronExpression: string; // Cron expression: "0 9 * * *"
|
|
120
|
+
timezone?: string; // Timezone: "Asia/Shanghai"
|
|
121
|
+
maxRuns?: number; // Max executions (undefined = infinite)
|
|
122
|
+
expiresAt?: number; // Stop after this timestamp
|
|
123
|
+
maxRetries?: number; // Max retry attempts per run (default: 0)
|
|
124
|
+
assistantId?: string; // Which assistant created/owns this task
|
|
125
|
+
threadId?: string; // Which thread this task belongs to
|
|
126
|
+
metadata?: Record<string, any>;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Schedule storage interface for persistence
|
|
131
|
+
*/
|
|
132
|
+
export interface ScheduleStorage {
|
|
133
|
+
/**
|
|
134
|
+
* Save a new task
|
|
135
|
+
*/
|
|
136
|
+
save(task: ScheduledTaskDefinition): Promise<void>;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Get task by ID
|
|
140
|
+
*/
|
|
141
|
+
get(taskId: string): Promise<ScheduledTaskDefinition | null>;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Update task
|
|
145
|
+
*/
|
|
146
|
+
update(
|
|
147
|
+
taskId: string,
|
|
148
|
+
updates: Partial<ScheduledTaskDefinition>
|
|
149
|
+
): Promise<void>;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Delete task
|
|
153
|
+
*/
|
|
154
|
+
delete(taskId: string): Promise<void>;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Get all pending/active tasks (for recovery)
|
|
158
|
+
* Returns tasks with status: PENDING or PAUSED
|
|
159
|
+
*/
|
|
160
|
+
getActiveTasks(): Promise<ScheduledTaskDefinition[]>;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Get tasks by type
|
|
164
|
+
*/
|
|
165
|
+
getTasksByType(taskType: string): Promise<ScheduledTaskDefinition[]>;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Get tasks by status
|
|
169
|
+
*/
|
|
170
|
+
getTasksByStatus(
|
|
171
|
+
status: ScheduledTaskStatus
|
|
172
|
+
): Promise<ScheduledTaskDefinition[]>;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Get tasks by execution type
|
|
176
|
+
*/
|
|
177
|
+
getTasksByExecutionType(
|
|
178
|
+
executionType: ScheduleExecutionType
|
|
179
|
+
): Promise<ScheduledTaskDefinition[]>;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Get tasks by assistant ID
|
|
183
|
+
*/
|
|
184
|
+
getTasksByAssistantId(
|
|
185
|
+
assistantId: string
|
|
186
|
+
): Promise<ScheduledTaskDefinition[]>;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Get tasks by thread ID
|
|
190
|
+
*/
|
|
191
|
+
getTasksByThreadId(threadId: string): Promise<ScheduledTaskDefinition[]>;
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Get all tasks (with optional filters)
|
|
195
|
+
*/
|
|
196
|
+
getAllTasks(filters?: {
|
|
197
|
+
status?: ScheduledTaskStatus;
|
|
198
|
+
executionType?: ScheduleExecutionType;
|
|
199
|
+
taskType?: string;
|
|
200
|
+
assistantId?: string;
|
|
201
|
+
threadId?: string;
|
|
202
|
+
limit?: number;
|
|
203
|
+
offset?: number;
|
|
204
|
+
}): Promise<ScheduledTaskDefinition[]>;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Count tasks (with optional filters)
|
|
208
|
+
*/
|
|
209
|
+
countTasks(filters?: {
|
|
210
|
+
status?: ScheduledTaskStatus;
|
|
211
|
+
executionType?: ScheduleExecutionType;
|
|
212
|
+
taskType?: string;
|
|
213
|
+
assistantId?: string;
|
|
214
|
+
threadId?: string;
|
|
215
|
+
}): Promise<number>;
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Delete completed/cancelled tasks older than specified time
|
|
219
|
+
* Useful for cleanup
|
|
220
|
+
*/
|
|
221
|
+
deleteOldTasks(olderThanMs: number): Promise<number>;
|
|
35
222
|
}
|
|
36
223
|
|
|
37
224
|
/**
|
|
38
225
|
* Schedule client interface
|
|
39
226
|
*/
|
|
40
227
|
export interface ScheduleClient {
|
|
228
|
+
// ===== Handler Registration =====
|
|
229
|
+
|
|
41
230
|
/**
|
|
42
|
-
* Register a
|
|
231
|
+
* Register a handler for a task type
|
|
232
|
+
* Must be called before scheduling tasks of this type
|
|
233
|
+
*/
|
|
234
|
+
registerHandler(taskType: string, handler: TaskHandler): void;
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Unregister a handler
|
|
238
|
+
*/
|
|
239
|
+
unregisterHandler(taskType: string): boolean;
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Check if a handler is registered
|
|
243
|
+
*/
|
|
244
|
+
hasHandler(taskType: string): boolean;
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Get all registered handler types
|
|
248
|
+
*/
|
|
249
|
+
getHandlerTypes(): string[];
|
|
250
|
+
|
|
251
|
+
// ===== One-time Task Scheduling =====
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Schedule a one-time task
|
|
43
255
|
* @param taskId - Unique identifier for the task
|
|
44
|
-
* @param
|
|
45
|
-
* @param
|
|
46
|
-
* @
|
|
256
|
+
* @param taskType - Type of task (must have a registered handler)
|
|
257
|
+
* @param payload - Data to pass to the handler (must be JSON-serializable)
|
|
258
|
+
* @param options - Execution options (executeAt or delayMs required)
|
|
47
259
|
*/
|
|
48
|
-
|
|
260
|
+
scheduleOnce(
|
|
49
261
|
taskId: string,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
262
|
+
taskType: string,
|
|
263
|
+
payload: Record<string, any>,
|
|
264
|
+
options: ScheduleOnceOptions
|
|
265
|
+
): Promise<boolean>;
|
|
266
|
+
|
|
267
|
+
// ===== Cron Task Scheduling =====
|
|
53
268
|
|
|
54
269
|
/**
|
|
55
|
-
*
|
|
56
|
-
* @param taskId -
|
|
57
|
-
* @
|
|
270
|
+
* Schedule a recurring cron task
|
|
271
|
+
* @param taskId - Unique identifier for the task
|
|
272
|
+
* @param taskType - Type of task (must have a registered handler)
|
|
273
|
+
* @param payload - Data to pass to the handler (must be JSON-serializable)
|
|
274
|
+
* @param options - Cron options (cronExpression required)
|
|
58
275
|
*/
|
|
59
|
-
|
|
276
|
+
scheduleCron(
|
|
277
|
+
taskId: string,
|
|
278
|
+
taskType: string,
|
|
279
|
+
payload: Record<string, any>,
|
|
280
|
+
options: ScheduleCronOptions
|
|
281
|
+
): Promise<boolean>;
|
|
282
|
+
|
|
283
|
+
// ===== Task Management =====
|
|
60
284
|
|
|
61
285
|
/**
|
|
62
|
-
*
|
|
63
|
-
* @param taskId - The task identifier to check
|
|
286
|
+
* Cancel a scheduled task
|
|
64
287
|
*/
|
|
65
|
-
|
|
288
|
+
cancel(taskId: string): Promise<boolean>;
|
|
66
289
|
|
|
67
290
|
/**
|
|
68
|
-
*
|
|
69
|
-
* @param taskId - The task identifier
|
|
70
|
-
* @returns Remaining time in ms, or -1 if task not found
|
|
291
|
+
* Pause a cron task (only for CRON type)
|
|
71
292
|
*/
|
|
72
|
-
|
|
293
|
+
pause(taskId: string): Promise<boolean>;
|
|
73
294
|
|
|
74
295
|
/**
|
|
75
|
-
*
|
|
296
|
+
* Resume a paused cron task (only for CRON type)
|
|
76
297
|
*/
|
|
77
|
-
|
|
298
|
+
resume(taskId: string): Promise<boolean>;
|
|
78
299
|
|
|
79
300
|
/**
|
|
80
|
-
*
|
|
301
|
+
* Check if a task exists
|
|
81
302
|
*/
|
|
82
|
-
|
|
303
|
+
has(taskId: string): Promise<boolean>;
|
|
83
304
|
|
|
84
305
|
/**
|
|
85
|
-
*
|
|
306
|
+
* Get task information
|
|
86
307
|
*/
|
|
87
|
-
|
|
308
|
+
getTask(taskId: string): Promise<ScheduledTaskDefinition | null>;
|
|
88
309
|
|
|
89
310
|
/**
|
|
90
|
-
* Get
|
|
91
|
-
*
|
|
92
|
-
|
|
311
|
+
* Get remaining time until next execution
|
|
312
|
+
* Returns -1 if task not found or already executed
|
|
313
|
+
*/
|
|
314
|
+
getRemainingTime(taskId: string): Promise<number>;
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Get count of active tasks (pending + paused)
|
|
318
|
+
*/
|
|
319
|
+
getActiveTaskCount(): Promise<number>;
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Get all active task IDs
|
|
323
|
+
*/
|
|
324
|
+
getActiveTaskIds(): Promise<string[]>;
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Cancel all active tasks
|
|
328
|
+
*/
|
|
329
|
+
cancelAll(): Promise<void>;
|
|
330
|
+
|
|
331
|
+
// ===== Recovery =====
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Restore active tasks from storage (call on service startup)
|
|
335
|
+
* Re-schedules all pending tasks with their remaining time
|
|
336
|
+
* Re-schedules all cron tasks for their next run
|
|
337
|
+
* @returns Number of tasks restored
|
|
338
|
+
*/
|
|
339
|
+
restore(): Promise<number>;
|
|
340
|
+
|
|
341
|
+
// ===== Storage =====
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Set the storage backend
|
|
345
|
+
*/
|
|
346
|
+
setStorage(storage: ScheduleStorage): void;
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Get current storage backend
|
|
93
350
|
*/
|
|
94
|
-
|
|
351
|
+
getStorage(): ScheduleStorage | null;
|
|
95
352
|
}
|
|
96
353
|
|
|
97
354
|
/**
|
|
@@ -99,17 +356,39 @@ export interface ScheduleClient {
|
|
|
99
356
|
*/
|
|
100
357
|
export interface ScheduleLatticeProtocol
|
|
101
358
|
extends BaseLatticeProtocol<ScheduleConfig, ScheduleClient> {
|
|
102
|
-
//
|
|
103
|
-
|
|
359
|
+
// Handler registration
|
|
360
|
+
registerHandler: (taskType: string, handler: TaskHandler) => void;
|
|
361
|
+
unregisterHandler: (taskType: string) => boolean;
|
|
362
|
+
hasHandler: (taskType: string) => boolean;
|
|
363
|
+
getHandlerTypes: () => string[];
|
|
364
|
+
|
|
365
|
+
// One-time task scheduling
|
|
366
|
+
scheduleOnce: (
|
|
104
367
|
taskId: string,
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
368
|
+
taskType: string,
|
|
369
|
+
payload: Record<string, any>,
|
|
370
|
+
options: ScheduleOnceOptions
|
|
371
|
+
) => Promise<boolean>;
|
|
372
|
+
|
|
373
|
+
// Cron task scheduling
|
|
374
|
+
scheduleCron: (
|
|
375
|
+
taskId: string,
|
|
376
|
+
taskType: string,
|
|
377
|
+
payload: Record<string, any>,
|
|
378
|
+
options: ScheduleCronOptions
|
|
379
|
+
) => Promise<boolean>;
|
|
380
|
+
|
|
381
|
+
// Task management
|
|
382
|
+
cancel: (taskId: string) => Promise<boolean>;
|
|
383
|
+
pause: (taskId: string) => Promise<boolean>;
|
|
384
|
+
resume: (taskId: string) => Promise<boolean>;
|
|
385
|
+
has: (taskId: string) => Promise<boolean>;
|
|
386
|
+
getTask: (taskId: string) => Promise<ScheduledTaskDefinition | null>;
|
|
387
|
+
getRemainingTime: (taskId: string) => Promise<number>;
|
|
388
|
+
getActiveTaskCount: () => Promise<number>;
|
|
389
|
+
getActiveTaskIds: () => Promise<string[]>;
|
|
390
|
+
cancelAll: () => Promise<void>;
|
|
391
|
+
|
|
392
|
+
// Recovery
|
|
393
|
+
restore: () => Promise<number>;
|
|
115
394
|
}
|