@dexto/orchestration 1.5.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/LICENSE +44 -0
- package/dist/agent-controller.cjs +265 -0
- package/dist/agent-controller.d.cts +116 -0
- package/dist/agent-controller.d.ts +116 -0
- package/dist/agent-controller.js +241 -0
- package/dist/condition-engine.cjs +276 -0
- package/dist/condition-engine.d.cts +87 -0
- package/dist/condition-engine.d.ts +87 -0
- package/dist/condition-engine.js +252 -0
- package/dist/index.cjs +57 -0
- package/dist/index.d.cts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +32 -0
- package/dist/signal-bus.cjs +186 -0
- package/dist/signal-bus.d.cts +78 -0
- package/dist/signal-bus.d.ts +78 -0
- package/dist/signal-bus.js +162 -0
- package/dist/task-registry.cjs +345 -0
- package/dist/task-registry.d.cts +124 -0
- package/dist/task-registry.d.ts +124 -0
- package/dist/task-registry.js +321 -0
- package/dist/tools/check-task.cjs +65 -0
- package/dist/tools/check-task.d.cts +56 -0
- package/dist/tools/check-task.d.ts +56 -0
- package/dist/tools/check-task.js +40 -0
- package/dist/tools/index.cjs +51 -0
- package/dist/tools/index.d.cts +10 -0
- package/dist/tools/index.d.ts +10 -0
- package/dist/tools/index.js +19 -0
- package/dist/tools/list-tasks.cjs +80 -0
- package/dist/tools/list-tasks.d.cts +64 -0
- package/dist/tools/list-tasks.d.ts +64 -0
- package/dist/tools/list-tasks.js +55 -0
- package/dist/tools/start-task.cjs +149 -0
- package/dist/tools/start-task.d.cts +102 -0
- package/dist/tools/start-task.d.ts +102 -0
- package/dist/tools/start-task.js +123 -0
- package/dist/tools/types.cjs +16 -0
- package/dist/tools/types.d.cts +30 -0
- package/dist/tools/types.d.ts +30 -0
- package/dist/tools/types.js +0 -0
- package/dist/tools/wait-for.cjs +116 -0
- package/dist/tools/wait-for.d.cts +74 -0
- package/dist/tools/wait-for.d.ts +74 -0
- package/dist/tools/wait-for.js +91 -0
- package/dist/types.cjs +16 -0
- package/dist/types.d.cts +165 -0
- package/dist/types.d.ts +165 -0
- package/dist/types.js +0 -0
- package/package.json +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
Elastic License 2.0 (ELv2)
|
|
2
|
+
|
|
3
|
+
**Acceptance**
|
|
4
|
+
By using the software, you agree to all of the terms and conditions below.
|
|
5
|
+
|
|
6
|
+
**Copyright License**
|
|
7
|
+
The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below
|
|
8
|
+
|
|
9
|
+
**Limitations**
|
|
10
|
+
You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
|
|
11
|
+
|
|
12
|
+
You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
|
|
13
|
+
|
|
14
|
+
You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
|
|
15
|
+
|
|
16
|
+
**Patents**
|
|
17
|
+
The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
|
|
18
|
+
|
|
19
|
+
**Notices**
|
|
20
|
+
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
|
|
21
|
+
|
|
22
|
+
If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
|
|
23
|
+
|
|
24
|
+
**No Other Rights**
|
|
25
|
+
These terms do not imply any licenses other than those expressly granted in these terms.
|
|
26
|
+
|
|
27
|
+
**Termination**
|
|
28
|
+
If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
|
|
29
|
+
|
|
30
|
+
**No Liability**
|
|
31
|
+
As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
|
|
32
|
+
|
|
33
|
+
**Definitions**
|
|
34
|
+
The _licensor_ is the entity offering these terms, and the _software_ is the software the licensor makes available under these terms, including any portion of it.
|
|
35
|
+
|
|
36
|
+
_you_ refers to the individual or entity agreeing to these terms.
|
|
37
|
+
|
|
38
|
+
_your company_ is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. _control_ means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
|
|
39
|
+
|
|
40
|
+
_your licenses_ are all the licenses granted to you for the software under these terms.
|
|
41
|
+
|
|
42
|
+
_use_ means anything you do with the software requiring one of your licenses.
|
|
43
|
+
|
|
44
|
+
_trademark_ means trademarks, service marks, and similar rights.
|
|
@@ -0,0 +1,265 @@
|
|
|
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 agent_controller_exports = {};
|
|
20
|
+
__export(agent_controller_exports, {
|
|
21
|
+
AgentController: () => AgentController
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(agent_controller_exports);
|
|
24
|
+
var import_signal_bus = require("./signal-bus.js");
|
|
25
|
+
var import_task_registry = require("./task-registry.js");
|
|
26
|
+
var import_condition_engine = require("./condition-engine.js");
|
|
27
|
+
class AgentController {
|
|
28
|
+
agent;
|
|
29
|
+
logger;
|
|
30
|
+
state = "idle";
|
|
31
|
+
sessionId;
|
|
32
|
+
/** Signal bus for event routing */
|
|
33
|
+
signalBus;
|
|
34
|
+
/** Task registry for tracking background tasks */
|
|
35
|
+
taskRegistry;
|
|
36
|
+
/** Condition engine for evaluating wait conditions */
|
|
37
|
+
conditionEngine;
|
|
38
|
+
/** Signals that arrived while agent was busy */
|
|
39
|
+
pendingSignals = [];
|
|
40
|
+
/** Unsubscribe function for notify listener */
|
|
41
|
+
notifyUnsubscribe;
|
|
42
|
+
constructor(config) {
|
|
43
|
+
this.agent = config.agent;
|
|
44
|
+
if (config.logger) {
|
|
45
|
+
this.logger = config.logger;
|
|
46
|
+
}
|
|
47
|
+
this.sessionId = config.sessionId ?? `session-${Date.now()}`;
|
|
48
|
+
this.signalBus = new import_signal_bus.SignalBus();
|
|
49
|
+
this.taskRegistry = new import_task_registry.TaskRegistry(this.signalBus, config.taskRegistry);
|
|
50
|
+
this.conditionEngine = new import_condition_engine.ConditionEngine(this.taskRegistry, this.signalBus, this.logger);
|
|
51
|
+
this.setupNotifyListener();
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Set up listener for tasks with notify=true
|
|
55
|
+
*/
|
|
56
|
+
setupNotifyListener() {
|
|
57
|
+
this.notifyUnsubscribe = this.signalBus.onAny((signal) => {
|
|
58
|
+
if (signal.type === "task:completed" || signal.type === "task:failed" || signal.type === "task:cancelled") {
|
|
59
|
+
const entry = this.taskRegistry.get(signal.taskId);
|
|
60
|
+
if (entry?.notify) {
|
|
61
|
+
if (this.state === "idle") {
|
|
62
|
+
this.logger?.debug(`Auto-notify triggered for task ${signal.taskId}`);
|
|
63
|
+
void this.processNotify(signal).catch((error) => {
|
|
64
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
65
|
+
const signalContext = `signal.type=${signal.type} taskId=${signal.taskId}`;
|
|
66
|
+
this.logger?.error?.(
|
|
67
|
+
`AgentController.processNotify failed for ${signalContext}: ${message}`
|
|
68
|
+
);
|
|
69
|
+
});
|
|
70
|
+
} else {
|
|
71
|
+
this.pendingSignals.push(signal);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Process an auto-notify task completion
|
|
79
|
+
*/
|
|
80
|
+
async processNotify(signal) {
|
|
81
|
+
if (this.state !== "idle") {
|
|
82
|
+
this.pendingSignals.push(signal);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
this.state = "processing";
|
|
87
|
+
const taskInfo = signal.type === "task:completed" || signal.type === "task:failed" || signal.type === "task:cancelled" ? this.taskRegistry.getInfo(signal.taskId) : void 0;
|
|
88
|
+
const contextMessage = this.buildNotifyContext(signal, taskInfo);
|
|
89
|
+
await this.agent.generate(contextMessage, this.sessionId);
|
|
90
|
+
if (taskInfo) {
|
|
91
|
+
this.taskRegistry.acknowledgeNotify([taskInfo.taskId]);
|
|
92
|
+
}
|
|
93
|
+
} finally {
|
|
94
|
+
this.state = "idle";
|
|
95
|
+
this.processPendingSignals();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Build context message for auto-notify
|
|
100
|
+
*/
|
|
101
|
+
buildNotifyContext(signal, taskInfo) {
|
|
102
|
+
if (signal.type === "task:completed" && taskInfo) {
|
|
103
|
+
const resultStr = typeof taskInfo.result === "string" ? taskInfo.result : JSON.stringify(taskInfo.result, null, 2);
|
|
104
|
+
const durationLine = taskInfo.duration !== void 0 ? `Duration: ${taskInfo.duration}ms
|
|
105
|
+
` : "";
|
|
106
|
+
return `[Background Task Completed]
|
|
107
|
+
Task ID: ${taskInfo.taskId}
|
|
108
|
+
Type: ${taskInfo.type}
|
|
109
|
+
Description: ${taskInfo.description}
|
|
110
|
+
` + durationLine + `Result:
|
|
111
|
+
${resultStr}`;
|
|
112
|
+
}
|
|
113
|
+
if (signal.type === "task:failed" && taskInfo) {
|
|
114
|
+
return `[Background Task Failed]
|
|
115
|
+
Task ID: ${taskInfo.taskId}
|
|
116
|
+
Type: ${taskInfo.type}
|
|
117
|
+
Description: ${taskInfo.description}
|
|
118
|
+
Error: ${taskInfo.error}`;
|
|
119
|
+
}
|
|
120
|
+
if (signal.type === "task:cancelled" && taskInfo) {
|
|
121
|
+
const cancelReason = taskInfo.error ?? "Cancelled";
|
|
122
|
+
return `[Background Task Cancelled]
|
|
123
|
+
Task ID: ${taskInfo.taskId}
|
|
124
|
+
Type: ${taskInfo.type}
|
|
125
|
+
Description: ${taskInfo.description}
|
|
126
|
+
Reason: ${cancelReason}`;
|
|
127
|
+
}
|
|
128
|
+
return `[Background Signal]
|
|
129
|
+
${JSON.stringify(signal, null, 2)}`;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Process any pending signals
|
|
133
|
+
*/
|
|
134
|
+
processPendingSignals() {
|
|
135
|
+
while (this.pendingSignals.length > 0 && this.state === "idle") {
|
|
136
|
+
const signal = this.pendingSignals.shift();
|
|
137
|
+
if (signal) {
|
|
138
|
+
void this.processNotify(signal).catch((error) => {
|
|
139
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
140
|
+
const signalContext = signal.type === "task:completed" || signal.type === "task:failed" || signal.type === "task:cancelled" ? `signal.type=${signal.type} taskId=${signal.taskId}` : `signal.type=${signal.type}`;
|
|
141
|
+
this.logger?.error?.(
|
|
142
|
+
`AgentController.processNotify failed for ${signalContext}: ${message}`
|
|
143
|
+
);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Process user input and generate response
|
|
150
|
+
* @param content User message content
|
|
151
|
+
* @returns Agent response
|
|
152
|
+
*/
|
|
153
|
+
async process(content) {
|
|
154
|
+
if (this.state !== "idle") {
|
|
155
|
+
throw new Error(`Cannot process while agent is ${this.state}`);
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
this.state = "processing";
|
|
159
|
+
const { contextPrefix, notifyTaskIds } = this.buildTaskContext();
|
|
160
|
+
const fullContent = contextPrefix ? `${contextPrefix}
|
|
161
|
+
|
|
162
|
+
${content}` : content;
|
|
163
|
+
const response = await this.agent.generate(fullContent, this.sessionId);
|
|
164
|
+
if (notifyTaskIds.length > 0) {
|
|
165
|
+
this.taskRegistry.acknowledgeNotify(notifyTaskIds);
|
|
166
|
+
}
|
|
167
|
+
return response.content;
|
|
168
|
+
} finally {
|
|
169
|
+
this.state = "idle";
|
|
170
|
+
this.processPendingSignals();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Process a signal trigger (e.g., from external source)
|
|
175
|
+
*/
|
|
176
|
+
async processSignal(signal) {
|
|
177
|
+
if (this.state !== "idle") {
|
|
178
|
+
this.pendingSignals.push(signal);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
await this.processNotify(signal);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Build context about pending/completed tasks
|
|
185
|
+
*/
|
|
186
|
+
buildTaskContext() {
|
|
187
|
+
const running = this.taskRegistry.list({ status: "running" });
|
|
188
|
+
const notifyPending = this.taskRegistry.getNotifyPending();
|
|
189
|
+
if (running.length === 0 && notifyPending.length === 0) {
|
|
190
|
+
return { contextPrefix: "", notifyTaskIds: [] };
|
|
191
|
+
}
|
|
192
|
+
const parts = [];
|
|
193
|
+
if (running.length > 0) {
|
|
194
|
+
parts.push(
|
|
195
|
+
`[Background Tasks Running: ${running.length}]
|
|
196
|
+
` + running.map((t) => `- ${t.taskId}: ${t.description}`).join("\n")
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
if (notifyPending.length > 0) {
|
|
200
|
+
parts.push(
|
|
201
|
+
`[Background Tasks Completed: ${notifyPending.length}]
|
|
202
|
+
` + notifyPending.map((t) => {
|
|
203
|
+
const status = t.error ? `FAILED: ${t.error}` : t.status === "cancelled" ? "CANCELLED" : "SUCCESS";
|
|
204
|
+
return `- ${t.taskId}: ${t.description} [${status}]`;
|
|
205
|
+
}).join("\n")
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
return {
|
|
209
|
+
contextPrefix: parts.join("\n\n"),
|
|
210
|
+
notifyTaskIds: notifyPending.map((task) => task.taskId)
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Get current agent state
|
|
215
|
+
*/
|
|
216
|
+
getState() {
|
|
217
|
+
return this.state;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Get the wrapped agent
|
|
221
|
+
*/
|
|
222
|
+
getAgent() {
|
|
223
|
+
return this.agent;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Get session ID
|
|
227
|
+
*/
|
|
228
|
+
getSessionId() {
|
|
229
|
+
return this.sessionId;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Inject a signal for processing
|
|
233
|
+
*/
|
|
234
|
+
injectSignal(signal) {
|
|
235
|
+
this.signalBus.emit(signal);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Clean up resources
|
|
239
|
+
*/
|
|
240
|
+
cleanup() {
|
|
241
|
+
if (this.notifyUnsubscribe) {
|
|
242
|
+
this.notifyUnsubscribe();
|
|
243
|
+
}
|
|
244
|
+
this.pendingSignals = [];
|
|
245
|
+
this.signalBus.clear();
|
|
246
|
+
this.taskRegistry.clear();
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Start the agent (delegates to wrapped agent)
|
|
250
|
+
*/
|
|
251
|
+
async start() {
|
|
252
|
+
await this.agent.start();
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Stop the agent (delegates to wrapped agent)
|
|
256
|
+
*/
|
|
257
|
+
async stop() {
|
|
258
|
+
this.cleanup();
|
|
259
|
+
await this.agent.stop();
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
263
|
+
0 && (module.exports = {
|
|
264
|
+
AgentController
|
|
265
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Signal, AgentState } from './types.cjs';
|
|
2
|
+
import { SignalBus } from './signal-bus.cjs';
|
|
3
|
+
import { TaskRegistryConfig, TaskRegistry } from './task-registry.cjs';
|
|
4
|
+
import { ConditionEngine } from './condition-engine.cjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* AgentController
|
|
8
|
+
*
|
|
9
|
+
* Wraps DextoAgent and manages orchestration state.
|
|
10
|
+
* Handles background task execution, state transitions, and context injection.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
type AgentLike = {
|
|
14
|
+
generate: (content: string, sessionId?: string) => Promise<{
|
|
15
|
+
content: string;
|
|
16
|
+
}>;
|
|
17
|
+
start: () => Promise<void>;
|
|
18
|
+
stop: () => Promise<void>;
|
|
19
|
+
};
|
|
20
|
+
type LoggerLike = {
|
|
21
|
+
debug: (message: string) => void;
|
|
22
|
+
error?: (message: string) => void;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Configuration for AgentController
|
|
26
|
+
*/
|
|
27
|
+
interface AgentControllerConfig {
|
|
28
|
+
/** The agent to wrap */
|
|
29
|
+
agent: AgentLike;
|
|
30
|
+
/** Optional logger instance */
|
|
31
|
+
logger?: LoggerLike;
|
|
32
|
+
/** Task registry configuration */
|
|
33
|
+
taskRegistry?: TaskRegistryConfig;
|
|
34
|
+
/** Session ID to use (defaults to a generated one) */
|
|
35
|
+
sessionId?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* AgentController - Orchestration wrapper for DextoAgent
|
|
39
|
+
*/
|
|
40
|
+
declare class AgentController {
|
|
41
|
+
private agent;
|
|
42
|
+
private logger?;
|
|
43
|
+
private state;
|
|
44
|
+
private sessionId;
|
|
45
|
+
/** Signal bus for event routing */
|
|
46
|
+
readonly signalBus: SignalBus;
|
|
47
|
+
/** Task registry for tracking background tasks */
|
|
48
|
+
readonly taskRegistry: TaskRegistry;
|
|
49
|
+
/** Condition engine for evaluating wait conditions */
|
|
50
|
+
readonly conditionEngine: ConditionEngine;
|
|
51
|
+
/** Signals that arrived while agent was busy */
|
|
52
|
+
private pendingSignals;
|
|
53
|
+
/** Unsubscribe function for notify listener */
|
|
54
|
+
private notifyUnsubscribe?;
|
|
55
|
+
constructor(config: AgentControllerConfig);
|
|
56
|
+
/**
|
|
57
|
+
* Set up listener for tasks with notify=true
|
|
58
|
+
*/
|
|
59
|
+
private setupNotifyListener;
|
|
60
|
+
/**
|
|
61
|
+
* Process an auto-notify task completion
|
|
62
|
+
*/
|
|
63
|
+
private processNotify;
|
|
64
|
+
/**
|
|
65
|
+
* Build context message for auto-notify
|
|
66
|
+
*/
|
|
67
|
+
private buildNotifyContext;
|
|
68
|
+
/**
|
|
69
|
+
* Process any pending signals
|
|
70
|
+
*/
|
|
71
|
+
private processPendingSignals;
|
|
72
|
+
/**
|
|
73
|
+
* Process user input and generate response
|
|
74
|
+
* @param content User message content
|
|
75
|
+
* @returns Agent response
|
|
76
|
+
*/
|
|
77
|
+
process(content: string): Promise<string>;
|
|
78
|
+
/**
|
|
79
|
+
* Process a signal trigger (e.g., from external source)
|
|
80
|
+
*/
|
|
81
|
+
processSignal(signal: Signal): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Build context about pending/completed tasks
|
|
84
|
+
*/
|
|
85
|
+
private buildTaskContext;
|
|
86
|
+
/**
|
|
87
|
+
* Get current agent state
|
|
88
|
+
*/
|
|
89
|
+
getState(): AgentState;
|
|
90
|
+
/**
|
|
91
|
+
* Get the wrapped agent
|
|
92
|
+
*/
|
|
93
|
+
getAgent(): AgentLike;
|
|
94
|
+
/**
|
|
95
|
+
* Get session ID
|
|
96
|
+
*/
|
|
97
|
+
getSessionId(): string;
|
|
98
|
+
/**
|
|
99
|
+
* Inject a signal for processing
|
|
100
|
+
*/
|
|
101
|
+
injectSignal(signal: Signal): void;
|
|
102
|
+
/**
|
|
103
|
+
* Clean up resources
|
|
104
|
+
*/
|
|
105
|
+
cleanup(): void;
|
|
106
|
+
/**
|
|
107
|
+
* Start the agent (delegates to wrapped agent)
|
|
108
|
+
*/
|
|
109
|
+
start(): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Stop the agent (delegates to wrapped agent)
|
|
112
|
+
*/
|
|
113
|
+
stop(): Promise<void>;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export { AgentController, type AgentControllerConfig };
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Signal, AgentState } from './types.js';
|
|
2
|
+
import { SignalBus } from './signal-bus.js';
|
|
3
|
+
import { TaskRegistryConfig, TaskRegistry } from './task-registry.js';
|
|
4
|
+
import { ConditionEngine } from './condition-engine.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* AgentController
|
|
8
|
+
*
|
|
9
|
+
* Wraps DextoAgent and manages orchestration state.
|
|
10
|
+
* Handles background task execution, state transitions, and context injection.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
type AgentLike = {
|
|
14
|
+
generate: (content: string, sessionId?: string) => Promise<{
|
|
15
|
+
content: string;
|
|
16
|
+
}>;
|
|
17
|
+
start: () => Promise<void>;
|
|
18
|
+
stop: () => Promise<void>;
|
|
19
|
+
};
|
|
20
|
+
type LoggerLike = {
|
|
21
|
+
debug: (message: string) => void;
|
|
22
|
+
error?: (message: string) => void;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Configuration for AgentController
|
|
26
|
+
*/
|
|
27
|
+
interface AgentControllerConfig {
|
|
28
|
+
/** The agent to wrap */
|
|
29
|
+
agent: AgentLike;
|
|
30
|
+
/** Optional logger instance */
|
|
31
|
+
logger?: LoggerLike;
|
|
32
|
+
/** Task registry configuration */
|
|
33
|
+
taskRegistry?: TaskRegistryConfig;
|
|
34
|
+
/** Session ID to use (defaults to a generated one) */
|
|
35
|
+
sessionId?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* AgentController - Orchestration wrapper for DextoAgent
|
|
39
|
+
*/
|
|
40
|
+
declare class AgentController {
|
|
41
|
+
private agent;
|
|
42
|
+
private logger?;
|
|
43
|
+
private state;
|
|
44
|
+
private sessionId;
|
|
45
|
+
/** Signal bus for event routing */
|
|
46
|
+
readonly signalBus: SignalBus;
|
|
47
|
+
/** Task registry for tracking background tasks */
|
|
48
|
+
readonly taskRegistry: TaskRegistry;
|
|
49
|
+
/** Condition engine for evaluating wait conditions */
|
|
50
|
+
readonly conditionEngine: ConditionEngine;
|
|
51
|
+
/** Signals that arrived while agent was busy */
|
|
52
|
+
private pendingSignals;
|
|
53
|
+
/** Unsubscribe function for notify listener */
|
|
54
|
+
private notifyUnsubscribe?;
|
|
55
|
+
constructor(config: AgentControllerConfig);
|
|
56
|
+
/**
|
|
57
|
+
* Set up listener for tasks with notify=true
|
|
58
|
+
*/
|
|
59
|
+
private setupNotifyListener;
|
|
60
|
+
/**
|
|
61
|
+
* Process an auto-notify task completion
|
|
62
|
+
*/
|
|
63
|
+
private processNotify;
|
|
64
|
+
/**
|
|
65
|
+
* Build context message for auto-notify
|
|
66
|
+
*/
|
|
67
|
+
private buildNotifyContext;
|
|
68
|
+
/**
|
|
69
|
+
* Process any pending signals
|
|
70
|
+
*/
|
|
71
|
+
private processPendingSignals;
|
|
72
|
+
/**
|
|
73
|
+
* Process user input and generate response
|
|
74
|
+
* @param content User message content
|
|
75
|
+
* @returns Agent response
|
|
76
|
+
*/
|
|
77
|
+
process(content: string): Promise<string>;
|
|
78
|
+
/**
|
|
79
|
+
* Process a signal trigger (e.g., from external source)
|
|
80
|
+
*/
|
|
81
|
+
processSignal(signal: Signal): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Build context about pending/completed tasks
|
|
84
|
+
*/
|
|
85
|
+
private buildTaskContext;
|
|
86
|
+
/**
|
|
87
|
+
* Get current agent state
|
|
88
|
+
*/
|
|
89
|
+
getState(): AgentState;
|
|
90
|
+
/**
|
|
91
|
+
* Get the wrapped agent
|
|
92
|
+
*/
|
|
93
|
+
getAgent(): AgentLike;
|
|
94
|
+
/**
|
|
95
|
+
* Get session ID
|
|
96
|
+
*/
|
|
97
|
+
getSessionId(): string;
|
|
98
|
+
/**
|
|
99
|
+
* Inject a signal for processing
|
|
100
|
+
*/
|
|
101
|
+
injectSignal(signal: Signal): void;
|
|
102
|
+
/**
|
|
103
|
+
* Clean up resources
|
|
104
|
+
*/
|
|
105
|
+
cleanup(): void;
|
|
106
|
+
/**
|
|
107
|
+
* Start the agent (delegates to wrapped agent)
|
|
108
|
+
*/
|
|
109
|
+
start(): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Stop the agent (delegates to wrapped agent)
|
|
112
|
+
*/
|
|
113
|
+
stop(): Promise<void>;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export { AgentController, type AgentControllerConfig };
|