@dexto/orchestration 1.5.8 → 1.6.1
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/condition-engine.d.ts +6 -8
- package/dist/condition-engine.d.ts.map +1 -0
- package/dist/index.cjs +0 -9
- package/dist/index.d.cts +615 -11
- package/dist/index.d.ts +41 -10
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -18
- package/dist/signal-bus.d.ts +5 -8
- package/dist/signal-bus.d.ts.map +1 -0
- package/dist/task-registry.d.ts +5 -8
- package/dist/task-registry.d.ts.map +1 -0
- package/dist/tools/check-task.cjs +10 -4
- package/dist/tools/check-task.d.ts +8 -14
- package/dist/tools/check-task.d.ts.map +1 -0
- package/dist/tools/check-task.js +10 -4
- package/dist/tools/index.cjs +0 -8
- package/dist/tools/index.d.ts +15 -10
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +0 -5
- package/dist/tools/list-tasks.cjs +17 -5
- package/dist/tools/list-tasks.d.ts +10 -15
- package/dist/tools/list-tasks.d.ts.map +1 -0
- package/dist/tools/list-tasks.js +17 -5
- package/dist/tools/wait-for.cjs +13 -4
- package/dist/tools/wait-for.d.ts +8 -14
- package/dist/tools/wait-for.d.ts.map +1 -0
- package/dist/tools/wait-for.js +13 -4
- package/dist/types.d.ts +14 -15
- package/dist/types.d.ts.map +1 -0
- package/package.json +4 -3
- package/dist/agent-controller.cjs +0 -265
- package/dist/agent-controller.d.cts +0 -116
- package/dist/agent-controller.d.ts +0 -116
- package/dist/agent-controller.js +0 -241
- package/dist/condition-engine.d.cts +0 -87
- package/dist/signal-bus.d.cts +0 -78
- package/dist/task-registry.d.cts +0 -124
- package/dist/tools/check-task.d.cts +0 -56
- package/dist/tools/index.d.cts +0 -10
- package/dist/tools/list-tasks.d.cts +0 -64
- package/dist/tools/start-task.cjs +0 -149
- package/dist/tools/start-task.d.cts +0 -102
- package/dist/tools/start-task.d.ts +0 -102
- package/dist/tools/start-task.js +0 -123
- package/dist/tools/types.cjs +0 -16
- package/dist/tools/types.d.cts +0 -30
- package/dist/tools/types.d.ts +0 -30
- package/dist/tools/types.js +0 -0
- package/dist/tools/wait-for.d.cts +0 -74
- package/dist/types.d.cts +0 -165
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import { WaitCondition, WaitResult } from './types.js';
|
|
2
|
-
import { SignalBus } from './signal-bus.js';
|
|
3
|
-
import { TaskRegistry } from './task-registry.js';
|
|
4
|
-
|
|
5
1
|
/**
|
|
6
2
|
* ConditionEngine
|
|
7
3
|
*
|
|
8
4
|
* Evaluates wait conditions and resolves when met.
|
|
9
5
|
* Supports single task, any/all of multiple tasks, timeouts, and races.
|
|
10
6
|
*/
|
|
11
|
-
|
|
7
|
+
import type { WaitCondition, WaitResult } from './types.js';
|
|
8
|
+
import type { SignalBus } from './signal-bus.js';
|
|
9
|
+
import type { TaskRegistry } from './task-registry.js';
|
|
12
10
|
type LoggerLike = {
|
|
13
11
|
debug: (message: string) => void;
|
|
14
12
|
};
|
|
15
13
|
/**
|
|
16
14
|
* ConditionEngine - Evaluates composable wait conditions
|
|
17
15
|
*/
|
|
18
|
-
declare class ConditionEngine {
|
|
16
|
+
export declare class ConditionEngine {
|
|
19
17
|
private taskRegistry;
|
|
20
18
|
private signalBus;
|
|
21
19
|
private logger?;
|
|
@@ -83,5 +81,5 @@ declare class ConditionEngine {
|
|
|
83
81
|
*/
|
|
84
82
|
static createAllTasks(taskIds: string[]): WaitCondition;
|
|
85
83
|
}
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
export {};
|
|
85
|
+
//# sourceMappingURL=condition-engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"condition-engine.d.ts","sourceRoot":"","sources":["../src/condition-engine.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAU,UAAU,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,KAAK,UAAU,GAAG;IACd,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC,CAAC;AAEF;;GAEG;AACH,qBAAa,eAAe;IAEpB,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,MAAM,CAAC;gBAFP,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAE,SAAS,EACpB,MAAM,CAAC,EAAE,UAAU,YAAA;IAG/B;;;;OAIG;IACG,IAAI,CAAC,SAAS,EAAE,aAAa,GAAG,OAAO,CAAC,UAAU,CAAC;IAWzD;;;OAGG;IACH,KAAK,CAAC,SAAS,EAAE,aAAa,GAAG,UAAU,GAAG,IAAI;IAqBlD;;OAEG;IACH,OAAO,CAAC,SAAS;IAuCjB;;OAEG;IACH,OAAO,CAAC,QAAQ;IAUhB;;OAEG;IACH,OAAO,CAAC,QAAQ;IAsBhB;;OAEG;YACW,QAAQ;IAmBtB;;;;;OAKG;YACW,YAAY;IA0C1B;;OAEG;YACW,WAAW;IAgBzB;;OAEG;YACW,WAAW;IAsBzB;;OAEG;YACW,eAAe;IAc7B;;OAEG;YACW,YAAY;IAmB1B;;OAEG;IACH,MAAM,CAAC,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,aAAa;IAY9E;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,aAAa;IAOtD;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,aAAa;CAM1D"}
|
package/dist/index.cjs
CHANGED
|
@@ -18,22 +18,17 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var index_exports = {};
|
|
20
20
|
__export(index_exports, {
|
|
21
|
-
AgentController: () => import_agent_controller.AgentController,
|
|
22
21
|
CheckTaskInputSchema: () => import_tools2.CheckTaskInputSchema,
|
|
23
22
|
ConditionEngine: () => import_condition_engine.ConditionEngine,
|
|
24
23
|
ListTasksInputSchema: () => import_tools2.ListTasksInputSchema,
|
|
25
24
|
SignalBus: () => import_signal_bus.SignalBus,
|
|
26
|
-
StartTaskInputSchema: () => import_tools2.StartTaskInputSchema,
|
|
27
25
|
TaskRegistry: () => import_task_registry.TaskRegistry,
|
|
28
26
|
WaitForInputSchema: () => import_tools2.WaitForInputSchema,
|
|
29
27
|
createCheckTaskTool: () => import_tools.createCheckTaskTool,
|
|
30
|
-
createGenericTaskStarter: () => import_tools.createGenericTaskStarter,
|
|
31
28
|
createListTasksTool: () => import_tools.createListTasksTool,
|
|
32
|
-
createStartTaskTool: () => import_tools.createStartTaskTool,
|
|
33
29
|
createWaitForTool: () => import_tools.createWaitForTool
|
|
34
30
|
});
|
|
35
31
|
module.exports = __toCommonJS(index_exports);
|
|
36
|
-
var import_agent_controller = require("./agent-controller.js");
|
|
37
32
|
var import_signal_bus = require("./signal-bus.js");
|
|
38
33
|
var import_task_registry = require("./task-registry.js");
|
|
39
34
|
var import_condition_engine = require("./condition-engine.js");
|
|
@@ -41,17 +36,13 @@ var import_tools = require("./tools/index.js");
|
|
|
41
36
|
var import_tools2 = require("./tools/index.js");
|
|
42
37
|
// Annotate the CommonJS export names for ESM import in node:
|
|
43
38
|
0 && (module.exports = {
|
|
44
|
-
AgentController,
|
|
45
39
|
CheckTaskInputSchema,
|
|
46
40
|
ConditionEngine,
|
|
47
41
|
ListTasksInputSchema,
|
|
48
42
|
SignalBus,
|
|
49
|
-
StartTaskInputSchema,
|
|
50
43
|
TaskRegistry,
|
|
51
44
|
WaitForInputSchema,
|
|
52
45
|
createCheckTaskTool,
|
|
53
|
-
createGenericTaskStarter,
|
|
54
46
|
createListTasksTool,
|
|
55
|
-
createStartTaskTool,
|
|
56
47
|
createWaitForTool
|
|
57
48
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,11 +1,615 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Tool } from '@dexto/core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Orchestration Types
|
|
6
|
+
*
|
|
7
|
+
* Core type definitions for the agent orchestration layer.
|
|
8
|
+
* Defines tasks, signals, wait conditions, and agent states.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Task result from agent or process execution
|
|
12
|
+
*/
|
|
13
|
+
interface TaskResult {
|
|
14
|
+
success: boolean;
|
|
15
|
+
response?: string;
|
|
16
|
+
error?: string;
|
|
17
|
+
agentId?: string;
|
|
18
|
+
tokenUsage?: {
|
|
19
|
+
input: number;
|
|
20
|
+
output: number;
|
|
21
|
+
total: number;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Process result from shell command execution
|
|
26
|
+
*/
|
|
27
|
+
interface ProcessResult {
|
|
28
|
+
stdout: string;
|
|
29
|
+
stderr: string;
|
|
30
|
+
exitCode: number;
|
|
31
|
+
duration?: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Task types - discriminated union of different background task kinds
|
|
35
|
+
*/
|
|
36
|
+
type Task = {
|
|
37
|
+
type: 'agent';
|
|
38
|
+
taskId: string;
|
|
39
|
+
agentId: string;
|
|
40
|
+
taskDescription: string;
|
|
41
|
+
promise: Promise<TaskResult>;
|
|
42
|
+
} | {
|
|
43
|
+
type: 'process';
|
|
44
|
+
taskId: string;
|
|
45
|
+
processId: string;
|
|
46
|
+
command: string;
|
|
47
|
+
promise: Promise<ProcessResult>;
|
|
48
|
+
} | {
|
|
49
|
+
type: 'generic';
|
|
50
|
+
taskId: string;
|
|
51
|
+
description: string;
|
|
52
|
+
promise: Promise<unknown>;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Task lifecycle status
|
|
56
|
+
*/
|
|
57
|
+
type TaskStatus = 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
|
|
58
|
+
/**
|
|
59
|
+
* Entry in the task registry tracking a background task
|
|
60
|
+
*/
|
|
61
|
+
interface TaskEntry {
|
|
62
|
+
task: Task;
|
|
63
|
+
status: TaskStatus;
|
|
64
|
+
startedAt: Date;
|
|
65
|
+
completedAt?: Date;
|
|
66
|
+
result?: unknown;
|
|
67
|
+
error?: string;
|
|
68
|
+
/** If true, auto-trigger agent turn on completion */
|
|
69
|
+
notify?: boolean;
|
|
70
|
+
/** Timeout handle for this task (if set) */
|
|
71
|
+
timeoutHandle: ReturnType<typeof setTimeout> | undefined;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Signal types - events that trigger state transitions
|
|
75
|
+
*/
|
|
76
|
+
type Signal = {
|
|
77
|
+
type: 'task:completed';
|
|
78
|
+
taskId: string;
|
|
79
|
+
result: unknown;
|
|
80
|
+
} | {
|
|
81
|
+
type: 'task:failed';
|
|
82
|
+
taskId: string;
|
|
83
|
+
error: string;
|
|
84
|
+
} | {
|
|
85
|
+
type: 'task:cancelled';
|
|
86
|
+
taskId: string;
|
|
87
|
+
} | {
|
|
88
|
+
type: 'timeout';
|
|
89
|
+
conditionId: string;
|
|
90
|
+
} | {
|
|
91
|
+
type: 'user:input';
|
|
92
|
+
content: string;
|
|
93
|
+
sessionId: string;
|
|
94
|
+
} | {
|
|
95
|
+
type: 'external';
|
|
96
|
+
source: string;
|
|
97
|
+
data: unknown;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Extract signal type string
|
|
101
|
+
*/
|
|
102
|
+
type SignalType = Signal['type'];
|
|
103
|
+
/**
|
|
104
|
+
* Wait conditions - composable conditions for suspension
|
|
105
|
+
*/
|
|
106
|
+
type WaitCondition = {
|
|
107
|
+
type: 'task';
|
|
108
|
+
taskId: string;
|
|
109
|
+
} | {
|
|
110
|
+
type: 'any';
|
|
111
|
+
conditions: WaitCondition[];
|
|
112
|
+
} | {
|
|
113
|
+
type: 'all';
|
|
114
|
+
conditions: WaitCondition[];
|
|
115
|
+
} | {
|
|
116
|
+
type: 'timeout';
|
|
117
|
+
ms: number;
|
|
118
|
+
conditionId: string;
|
|
119
|
+
} | {
|
|
120
|
+
type: 'race';
|
|
121
|
+
task: WaitCondition;
|
|
122
|
+
timeout: WaitCondition;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Agent loop states
|
|
126
|
+
*/
|
|
127
|
+
type AgentState = 'idle' | 'processing' | 'waiting';
|
|
128
|
+
/**
|
|
129
|
+
* Task info returned by list/check operations (without internal promise)
|
|
130
|
+
*/
|
|
131
|
+
interface TaskInfo {
|
|
132
|
+
taskId: string;
|
|
133
|
+
type: Task['type'];
|
|
134
|
+
status: TaskStatus;
|
|
135
|
+
startedAt: Date;
|
|
136
|
+
completedAt?: Date;
|
|
137
|
+
duration?: number;
|
|
138
|
+
description?: string;
|
|
139
|
+
result?: unknown;
|
|
140
|
+
error?: string;
|
|
141
|
+
cancelReason?: string;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Filter options for listing tasks
|
|
145
|
+
*/
|
|
146
|
+
interface TaskFilter {
|
|
147
|
+
status?: TaskStatus | TaskStatus[];
|
|
148
|
+
type?: Task['type'];
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Result from waiting on a condition
|
|
152
|
+
*/
|
|
153
|
+
interface WaitResult {
|
|
154
|
+
signal: Signal;
|
|
155
|
+
/** For 'all' conditions, contains all signals */
|
|
156
|
+
allSignals?: Signal[];
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Options for registering a task
|
|
160
|
+
*/
|
|
161
|
+
interface RegisterTaskOptions {
|
|
162
|
+
/** Auto-trigger agent turn on completion */
|
|
163
|
+
notify?: boolean;
|
|
164
|
+
/** Timeout in milliseconds */
|
|
165
|
+
timeout?: number;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* SignalBus
|
|
170
|
+
*
|
|
171
|
+
* Event emitter for routing orchestration signals.
|
|
172
|
+
* Supports typed subscriptions and promise-based waiting.
|
|
173
|
+
*/
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Handler function for signal subscriptions
|
|
177
|
+
*/
|
|
178
|
+
type SignalHandler<T extends Signal = Signal> = (signal: T) => void;
|
|
179
|
+
/**
|
|
180
|
+
* Predicate function for filtering signals
|
|
181
|
+
*/
|
|
182
|
+
type SignalPredicate = (signal: Signal) => boolean;
|
|
183
|
+
/**
|
|
184
|
+
* SignalBus - Routes signals between orchestration components
|
|
185
|
+
*/
|
|
186
|
+
declare class SignalBus {
|
|
187
|
+
private emitter;
|
|
188
|
+
constructor();
|
|
189
|
+
/**
|
|
190
|
+
* Emit a signal to all subscribers
|
|
191
|
+
*/
|
|
192
|
+
emit(signal: Signal): void;
|
|
193
|
+
/**
|
|
194
|
+
* Subscribe to signals of a specific type
|
|
195
|
+
* @returns Unsubscribe function
|
|
196
|
+
*/
|
|
197
|
+
on<T extends SignalType>(type: T, handler: SignalHandler<Extract<Signal, {
|
|
198
|
+
type: T;
|
|
199
|
+
}>>): () => void;
|
|
200
|
+
/**
|
|
201
|
+
* Subscribe to all signals
|
|
202
|
+
* @returns Unsubscribe function
|
|
203
|
+
*/
|
|
204
|
+
onAny(handler: SignalHandler): () => void;
|
|
205
|
+
/**
|
|
206
|
+
* Subscribe to a signal type once
|
|
207
|
+
*/
|
|
208
|
+
once<T extends SignalType>(type: T, handler: SignalHandler<Extract<Signal, {
|
|
209
|
+
type: T;
|
|
210
|
+
}>>): void;
|
|
211
|
+
/**
|
|
212
|
+
* Remove a specific handler
|
|
213
|
+
*/
|
|
214
|
+
off<T extends SignalType>(type: T, handler: SignalHandler<Extract<Signal, {
|
|
215
|
+
type: T;
|
|
216
|
+
}>>): void;
|
|
217
|
+
/**
|
|
218
|
+
* Wait for a signal matching the predicate
|
|
219
|
+
* @param predicate Function to test signals
|
|
220
|
+
* @param timeout Optional timeout in milliseconds
|
|
221
|
+
* @returns Promise that resolves with the matching signal
|
|
222
|
+
*/
|
|
223
|
+
waitFor(predicate: SignalPredicate, timeout?: number): Promise<Signal>;
|
|
224
|
+
/**
|
|
225
|
+
* Wait for a signal for a specific task
|
|
226
|
+
*/
|
|
227
|
+
waitForTask(taskId: string, timeout?: number): Promise<Signal>;
|
|
228
|
+
/**
|
|
229
|
+
* Wait for any of multiple tasks to complete
|
|
230
|
+
*/
|
|
231
|
+
waitForAnyTask(taskIds: string[], timeout?: number): Promise<Signal>;
|
|
232
|
+
/**
|
|
233
|
+
* Wait for all tasks to complete
|
|
234
|
+
* @returns Promise that resolves with all signals
|
|
235
|
+
*/
|
|
236
|
+
waitForAllTasks(taskIds: string[], timeout?: number, resolveInitial?: (taskId: string) => Signal | undefined): Promise<Signal[]>;
|
|
237
|
+
/**
|
|
238
|
+
* Remove all listeners
|
|
239
|
+
*/
|
|
240
|
+
clear(): void;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* TaskRegistry
|
|
245
|
+
*
|
|
246
|
+
* Tracks all background tasks and their results.
|
|
247
|
+
* Emits signals on task completion for the ConditionEngine.
|
|
248
|
+
*/
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Configuration for TaskRegistry
|
|
252
|
+
*/
|
|
253
|
+
interface TaskRegistryConfig {
|
|
254
|
+
/** Maximum number of concurrent tasks (default: 20) */
|
|
255
|
+
maxTasks?: number;
|
|
256
|
+
/** TTL for completed task results in ms (default: 5 minutes) */
|
|
257
|
+
resultTTL?: number;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* TaskRegistry - Manages background task lifecycle
|
|
261
|
+
*/
|
|
262
|
+
declare class TaskRegistry {
|
|
263
|
+
private tasks;
|
|
264
|
+
private signalBus;
|
|
265
|
+
private config;
|
|
266
|
+
constructor(signalBus: SignalBus, config?: TaskRegistryConfig);
|
|
267
|
+
/**
|
|
268
|
+
* Generate a unique task ID
|
|
269
|
+
*/
|
|
270
|
+
private generateTaskId;
|
|
271
|
+
/**
|
|
272
|
+
* Get description from task for display
|
|
273
|
+
*/
|
|
274
|
+
private getTaskDescription;
|
|
275
|
+
/**
|
|
276
|
+
* Register a new task and start tracking it
|
|
277
|
+
* @param task Task to register (must include promise)
|
|
278
|
+
* @param options Registration options
|
|
279
|
+
* @returns Task ID
|
|
280
|
+
*/
|
|
281
|
+
register(task: Task, options?: RegisterTaskOptions): string;
|
|
282
|
+
/**
|
|
283
|
+
* Create and register an agent task
|
|
284
|
+
*
|
|
285
|
+
* Note: Uses agentId as the taskId so the caller can use the same ID
|
|
286
|
+
* for wait_for/check_task operations.
|
|
287
|
+
*/
|
|
288
|
+
registerAgentTask(agentId: string, taskDescription: string, promise: Promise<unknown>, options?: RegisterTaskOptions): string;
|
|
289
|
+
/**
|
|
290
|
+
* Create and register a process task
|
|
291
|
+
*/
|
|
292
|
+
registerProcessTask(processId: string, command: string, promise: Promise<unknown>, options?: RegisterTaskOptions): string;
|
|
293
|
+
/**
|
|
294
|
+
* Create and register a generic task
|
|
295
|
+
*/
|
|
296
|
+
registerGenericTask(description: string, promise: Promise<unknown>, options?: RegisterTaskOptions): string;
|
|
297
|
+
/**
|
|
298
|
+
* Called when a task completes successfully
|
|
299
|
+
*/
|
|
300
|
+
private onTaskComplete;
|
|
301
|
+
/**
|
|
302
|
+
* Called when a task fails
|
|
303
|
+
*/
|
|
304
|
+
private onTaskFailed;
|
|
305
|
+
/**
|
|
306
|
+
* Cancel a running task
|
|
307
|
+
*/
|
|
308
|
+
cancel(taskId: string): void;
|
|
309
|
+
/**
|
|
310
|
+
* Get task entry by ID
|
|
311
|
+
*/
|
|
312
|
+
get(taskId: string): TaskEntry | undefined;
|
|
313
|
+
/**
|
|
314
|
+
* Get task status
|
|
315
|
+
*/
|
|
316
|
+
getStatus(taskId: string): TaskStatus | undefined;
|
|
317
|
+
/**
|
|
318
|
+
* Get task result (if completed)
|
|
319
|
+
*/
|
|
320
|
+
getResult(taskId: string): {
|
|
321
|
+
status: TaskStatus;
|
|
322
|
+
result?: unknown;
|
|
323
|
+
error?: string;
|
|
324
|
+
} | undefined;
|
|
325
|
+
/**
|
|
326
|
+
* Get task info (safe for serialization - no promise)
|
|
327
|
+
*/
|
|
328
|
+
getInfo(taskId: string): TaskInfo | undefined;
|
|
329
|
+
/**
|
|
330
|
+
* List tasks matching filter
|
|
331
|
+
*/
|
|
332
|
+
list(filter?: TaskFilter): TaskInfo[];
|
|
333
|
+
/**
|
|
334
|
+
* Get count of running tasks
|
|
335
|
+
*/
|
|
336
|
+
getRunningCount(): number;
|
|
337
|
+
/**
|
|
338
|
+
* Get tasks that completed with notify=true and haven't been acknowledged
|
|
339
|
+
*/
|
|
340
|
+
getNotifyPending(): TaskInfo[];
|
|
341
|
+
/**
|
|
342
|
+
* Mark notify tasks as acknowledged (clear notify flag)
|
|
343
|
+
*/
|
|
344
|
+
acknowledgeNotify(taskIds: string[]): void;
|
|
345
|
+
/**
|
|
346
|
+
* Clean up old completed tasks
|
|
347
|
+
*/
|
|
348
|
+
cleanup(olderThan?: Date): number;
|
|
349
|
+
/**
|
|
350
|
+
* Clear all tasks
|
|
351
|
+
*/
|
|
352
|
+
clear(): void;
|
|
353
|
+
/**
|
|
354
|
+
* Check if a task exists
|
|
355
|
+
*/
|
|
356
|
+
has(taskId: string): boolean;
|
|
357
|
+
/**
|
|
358
|
+
* Get total task count
|
|
359
|
+
*/
|
|
360
|
+
get size(): number;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* ConditionEngine
|
|
365
|
+
*
|
|
366
|
+
* Evaluates wait conditions and resolves when met.
|
|
367
|
+
* Supports single task, any/all of multiple tasks, timeouts, and races.
|
|
368
|
+
*/
|
|
369
|
+
|
|
370
|
+
type LoggerLike = {
|
|
371
|
+
debug: (message: string) => void;
|
|
372
|
+
};
|
|
373
|
+
/**
|
|
374
|
+
* ConditionEngine - Evaluates composable wait conditions
|
|
375
|
+
*/
|
|
376
|
+
declare class ConditionEngine {
|
|
377
|
+
private taskRegistry;
|
|
378
|
+
private signalBus;
|
|
379
|
+
private logger?;
|
|
380
|
+
constructor(taskRegistry: TaskRegistry, signalBus: SignalBus, logger?: LoggerLike | undefined);
|
|
381
|
+
/**
|
|
382
|
+
* Wait for a condition to be met
|
|
383
|
+
* @param condition Wait condition to evaluate
|
|
384
|
+
* @returns Promise resolving to the signal(s) that satisfied the condition
|
|
385
|
+
*/
|
|
386
|
+
wait(condition: WaitCondition): Promise<WaitResult>;
|
|
387
|
+
/**
|
|
388
|
+
* Check if a condition is already satisfied (non-blocking)
|
|
389
|
+
* @returns WaitResult if satisfied, null if not
|
|
390
|
+
*/
|
|
391
|
+
check(condition: WaitCondition): WaitResult | null;
|
|
392
|
+
/**
|
|
393
|
+
* Check if a single task is completed
|
|
394
|
+
*/
|
|
395
|
+
private checkTask;
|
|
396
|
+
/**
|
|
397
|
+
* Check if any of the conditions is satisfied
|
|
398
|
+
*/
|
|
399
|
+
private checkAny;
|
|
400
|
+
/**
|
|
401
|
+
* Check if all conditions are satisfied
|
|
402
|
+
*/
|
|
403
|
+
private checkAll;
|
|
404
|
+
/**
|
|
405
|
+
* Evaluate a condition asynchronously
|
|
406
|
+
*/
|
|
407
|
+
private evaluate;
|
|
408
|
+
/**
|
|
409
|
+
* Wait for a single task to complete
|
|
410
|
+
*
|
|
411
|
+
* Uses subscribe-then-check pattern to avoid race conditions where
|
|
412
|
+
* the task completes between checking and subscribing.
|
|
413
|
+
*/
|
|
414
|
+
private evaluateTask;
|
|
415
|
+
/**
|
|
416
|
+
* Wait for any of the conditions to be satisfied
|
|
417
|
+
*/
|
|
418
|
+
private evaluateAny;
|
|
419
|
+
/**
|
|
420
|
+
* Wait for all conditions to be satisfied
|
|
421
|
+
*/
|
|
422
|
+
private evaluateAll;
|
|
423
|
+
/**
|
|
424
|
+
* Wait for a timeout
|
|
425
|
+
*/
|
|
426
|
+
private evaluateTimeout;
|
|
427
|
+
/**
|
|
428
|
+
* Race a task condition against a timeout
|
|
429
|
+
*/
|
|
430
|
+
private evaluateRace;
|
|
431
|
+
/**
|
|
432
|
+
* Helper to create a race condition with timeout
|
|
433
|
+
*/
|
|
434
|
+
static createRaceWithTimeout(taskId: string, timeoutMs: number): WaitCondition;
|
|
435
|
+
/**
|
|
436
|
+
* Helper to create an 'any' condition from task IDs
|
|
437
|
+
*/
|
|
438
|
+
static createAnyTask(taskIds: string[]): WaitCondition;
|
|
439
|
+
/**
|
|
440
|
+
* Helper to create an 'all' condition from task IDs
|
|
441
|
+
*/
|
|
442
|
+
static createAllTasks(taskIds: string[]): WaitCondition;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* wait_for Tool
|
|
447
|
+
*
|
|
448
|
+
* Suspends agent execution until condition is met using a blocking promise.
|
|
449
|
+
* TurnExecutor naturally awaits tool execution, so this works seamlessly.
|
|
450
|
+
*/
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Input schema for wait_for tool
|
|
454
|
+
*/
|
|
455
|
+
declare const WaitForInputSchema: z.ZodEffects<z.ZodObject<{
|
|
456
|
+
/** Wait for a single task */
|
|
457
|
+
taskId: z.ZodOptional<z.ZodString>;
|
|
458
|
+
/** Wait for multiple tasks */
|
|
459
|
+
taskIds: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
460
|
+
/** Mode for multiple tasks: any = first to complete, all = wait for all */
|
|
461
|
+
mode: z.ZodDefault<z.ZodOptional<z.ZodEnum<["any", "all"]>>>;
|
|
462
|
+
/** Timeout in milliseconds */
|
|
463
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
464
|
+
}, "strict", z.ZodTypeAny, {
|
|
465
|
+
mode: "any" | "all";
|
|
466
|
+
timeout?: number | undefined;
|
|
467
|
+
taskId?: string | undefined;
|
|
468
|
+
taskIds?: string[] | undefined;
|
|
469
|
+
}, {
|
|
470
|
+
timeout?: number | undefined;
|
|
471
|
+
taskId?: string | undefined;
|
|
472
|
+
taskIds?: string[] | undefined;
|
|
473
|
+
mode?: "any" | "all" | undefined;
|
|
474
|
+
}>, {
|
|
475
|
+
mode: "any" | "all";
|
|
476
|
+
timeout?: number | undefined;
|
|
477
|
+
taskId?: string | undefined;
|
|
478
|
+
taskIds?: string[] | undefined;
|
|
479
|
+
}, {
|
|
480
|
+
timeout?: number | undefined;
|
|
481
|
+
taskId?: string | undefined;
|
|
482
|
+
taskIds?: string[] | undefined;
|
|
483
|
+
mode?: "any" | "all" | undefined;
|
|
484
|
+
}>;
|
|
485
|
+
type WaitForInput = z.output<typeof WaitForInputSchema>;
|
|
486
|
+
/**
|
|
487
|
+
* Output from wait_for tool
|
|
488
|
+
*/
|
|
489
|
+
interface WaitForOutput {
|
|
490
|
+
/** Task ID that triggered the return (for 'any' mode) */
|
|
491
|
+
taskId: string;
|
|
492
|
+
/** Final status */
|
|
493
|
+
status: 'completed' | 'failed' | 'cancelled' | 'timeout';
|
|
494
|
+
/** Result if completed */
|
|
495
|
+
result?: unknown;
|
|
496
|
+
/** Error if failed */
|
|
497
|
+
error?: string;
|
|
498
|
+
/** All results for 'all' mode */
|
|
499
|
+
allResults?: Array<{
|
|
500
|
+
taskId: string;
|
|
501
|
+
status: 'completed' | 'failed' | 'cancelled';
|
|
502
|
+
result?: unknown;
|
|
503
|
+
error?: string;
|
|
504
|
+
}>;
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Create the wait_for tool
|
|
508
|
+
*/
|
|
509
|
+
declare function createWaitForTool(conditionEngine: ConditionEngine): Tool<typeof WaitForInputSchema>;
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* check_task Tool
|
|
513
|
+
*
|
|
514
|
+
* Non-blocking status check for a background task.
|
|
515
|
+
*/
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* Input schema for check_task tool
|
|
519
|
+
*/
|
|
520
|
+
declare const CheckTaskInputSchema: z.ZodObject<{
|
|
521
|
+
/** Task ID to check */
|
|
522
|
+
taskId: z.ZodString;
|
|
523
|
+
}, "strict", z.ZodTypeAny, {
|
|
524
|
+
taskId: string;
|
|
525
|
+
}, {
|
|
526
|
+
taskId: string;
|
|
527
|
+
}>;
|
|
528
|
+
type CheckTaskInput = z.output<typeof CheckTaskInputSchema>;
|
|
529
|
+
/**
|
|
530
|
+
* Output from check_task tool
|
|
531
|
+
*/
|
|
532
|
+
interface CheckTaskOutput {
|
|
533
|
+
/** Task ID */
|
|
534
|
+
taskId: string;
|
|
535
|
+
/** Whether task was found */
|
|
536
|
+
found: boolean;
|
|
537
|
+
/** Task type */
|
|
538
|
+
type?: 'agent' | 'process' | 'generic';
|
|
539
|
+
/** Current status */
|
|
540
|
+
status?: 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
|
|
541
|
+
/** Description of what the task is doing */
|
|
542
|
+
description?: string;
|
|
543
|
+
/** When the task started */
|
|
544
|
+
startedAt?: string;
|
|
545
|
+
/** When the task completed (if done) */
|
|
546
|
+
completedAt?: string;
|
|
547
|
+
/** Duration in milliseconds (if completed) */
|
|
548
|
+
duration?: number;
|
|
549
|
+
/** Result (if completed successfully) */
|
|
550
|
+
result?: unknown;
|
|
551
|
+
/** Error message (if failed) */
|
|
552
|
+
error?: string;
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Create the check_task tool
|
|
556
|
+
*/
|
|
557
|
+
declare function createCheckTaskTool(taskRegistry: TaskRegistry): Tool<typeof CheckTaskInputSchema>;
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* list_tasks Tool
|
|
561
|
+
*
|
|
562
|
+
* List all tracked background tasks with optional filtering.
|
|
563
|
+
*/
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* Input schema for list_tasks tool
|
|
567
|
+
*/
|
|
568
|
+
declare const ListTasksInputSchema: z.ZodObject<{
|
|
569
|
+
/** Filter by status */
|
|
570
|
+
status: z.ZodDefault<z.ZodOptional<z.ZodEnum<["pending", "running", "completed", "failed", "cancelled", "all"]>>>;
|
|
571
|
+
/** Filter by type */
|
|
572
|
+
type: z.ZodOptional<z.ZodEnum<["agent", "process", "generic"]>>;
|
|
573
|
+
}, "strict", z.ZodTypeAny, {
|
|
574
|
+
status: "pending" | "running" | "completed" | "failed" | "cancelled" | "all";
|
|
575
|
+
type?: "agent" | "process" | "generic" | undefined;
|
|
576
|
+
}, {
|
|
577
|
+
type?: "agent" | "process" | "generic" | undefined;
|
|
578
|
+
status?: "pending" | "running" | "completed" | "failed" | "cancelled" | "all" | undefined;
|
|
579
|
+
}>;
|
|
580
|
+
type ListTasksInput = z.output<typeof ListTasksInputSchema>;
|
|
581
|
+
/**
|
|
582
|
+
* Task info in list output
|
|
583
|
+
*/
|
|
584
|
+
interface TaskListItem {
|
|
585
|
+
taskId: string;
|
|
586
|
+
type: 'agent' | 'process' | 'generic';
|
|
587
|
+
status: TaskStatus;
|
|
588
|
+
description?: string;
|
|
589
|
+
startedAt: string;
|
|
590
|
+
completedAt?: string;
|
|
591
|
+
duration?: number;
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* Output from list_tasks tool
|
|
595
|
+
*/
|
|
596
|
+
interface ListTasksOutput {
|
|
597
|
+
/** List of tasks matching filter */
|
|
598
|
+
tasks: TaskListItem[];
|
|
599
|
+
/** Total count */
|
|
600
|
+
count: number;
|
|
601
|
+
/** Counts by status */
|
|
602
|
+
counts: {
|
|
603
|
+
running: number;
|
|
604
|
+
completed: number;
|
|
605
|
+
failed: number;
|
|
606
|
+
cancelled: number;
|
|
607
|
+
pending: number;
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Create the list_tasks tool
|
|
612
|
+
*/
|
|
613
|
+
declare function createListTasksTool(taskRegistry: TaskRegistry): Tool<typeof ListTasksInputSchema>;
|
|
614
|
+
|
|
615
|
+
export { type AgentState, type CheckTaskInput, CheckTaskInputSchema, type CheckTaskOutput, ConditionEngine, type ListTasksInput, ListTasksInputSchema, type ListTasksOutput, type ProcessResult, type RegisterTaskOptions, type Signal, SignalBus, type SignalHandler, type SignalPredicate, type SignalType, type Task, type TaskEntry, type TaskFilter, type TaskInfo, type TaskListItem, TaskRegistry, type TaskRegistryConfig, type TaskResult, type TaskStatus, type WaitCondition, type WaitForInput, WaitForInputSchema, type WaitForOutput, type WaitResult, createCheckTaskTool, createListTasksTool, createWaitForTool };
|