@dexto/orchestration 1.5.8 → 1.6.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/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 +1 -3
- 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 +4 -4
- package/dist/tools/check-task.d.cts +3 -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 +4 -4
- package/dist/tools/index.cjs +0 -8
- package/dist/tools/index.d.cts +4 -5
- 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 +5 -5
- package/dist/tools/list-tasks.d.cts +3 -4
- 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 +5 -5
- package/dist/tools/wait-for.cjs +4 -4
- package/dist/tools/wait-for.d.cts +5 -5
- 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 +4 -4
- package/dist/types.d.ts +14 -15
- package/dist/types.d.ts.map +1 -0
- package/package.json +3 -2
- 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/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
|
@@ -1,116 +0,0 @@
|
|
|
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 };
|
package/dist/agent-controller.js
DELETED
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
import { SignalBus } from "./signal-bus.js";
|
|
2
|
-
import { TaskRegistry } from "./task-registry.js";
|
|
3
|
-
import { ConditionEngine } from "./condition-engine.js";
|
|
4
|
-
class AgentController {
|
|
5
|
-
agent;
|
|
6
|
-
logger;
|
|
7
|
-
state = "idle";
|
|
8
|
-
sessionId;
|
|
9
|
-
/** Signal bus for event routing */
|
|
10
|
-
signalBus;
|
|
11
|
-
/** Task registry for tracking background tasks */
|
|
12
|
-
taskRegistry;
|
|
13
|
-
/** Condition engine for evaluating wait conditions */
|
|
14
|
-
conditionEngine;
|
|
15
|
-
/** Signals that arrived while agent was busy */
|
|
16
|
-
pendingSignals = [];
|
|
17
|
-
/** Unsubscribe function for notify listener */
|
|
18
|
-
notifyUnsubscribe;
|
|
19
|
-
constructor(config) {
|
|
20
|
-
this.agent = config.agent;
|
|
21
|
-
if (config.logger) {
|
|
22
|
-
this.logger = config.logger;
|
|
23
|
-
}
|
|
24
|
-
this.sessionId = config.sessionId ?? `session-${Date.now()}`;
|
|
25
|
-
this.signalBus = new SignalBus();
|
|
26
|
-
this.taskRegistry = new TaskRegistry(this.signalBus, config.taskRegistry);
|
|
27
|
-
this.conditionEngine = new ConditionEngine(this.taskRegistry, this.signalBus, this.logger);
|
|
28
|
-
this.setupNotifyListener();
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Set up listener for tasks with notify=true
|
|
32
|
-
*/
|
|
33
|
-
setupNotifyListener() {
|
|
34
|
-
this.notifyUnsubscribe = this.signalBus.onAny((signal) => {
|
|
35
|
-
if (signal.type === "task:completed" || signal.type === "task:failed" || signal.type === "task:cancelled") {
|
|
36
|
-
const entry = this.taskRegistry.get(signal.taskId);
|
|
37
|
-
if (entry?.notify) {
|
|
38
|
-
if (this.state === "idle") {
|
|
39
|
-
this.logger?.debug(`Auto-notify triggered for task ${signal.taskId}`);
|
|
40
|
-
void this.processNotify(signal).catch((error) => {
|
|
41
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
42
|
-
const signalContext = `signal.type=${signal.type} taskId=${signal.taskId}`;
|
|
43
|
-
this.logger?.error?.(
|
|
44
|
-
`AgentController.processNotify failed for ${signalContext}: ${message}`
|
|
45
|
-
);
|
|
46
|
-
});
|
|
47
|
-
} else {
|
|
48
|
-
this.pendingSignals.push(signal);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Process an auto-notify task completion
|
|
56
|
-
*/
|
|
57
|
-
async processNotify(signal) {
|
|
58
|
-
if (this.state !== "idle") {
|
|
59
|
-
this.pendingSignals.push(signal);
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
try {
|
|
63
|
-
this.state = "processing";
|
|
64
|
-
const taskInfo = signal.type === "task:completed" || signal.type === "task:failed" || signal.type === "task:cancelled" ? this.taskRegistry.getInfo(signal.taskId) : void 0;
|
|
65
|
-
const contextMessage = this.buildNotifyContext(signal, taskInfo);
|
|
66
|
-
await this.agent.generate(contextMessage, this.sessionId);
|
|
67
|
-
if (taskInfo) {
|
|
68
|
-
this.taskRegistry.acknowledgeNotify([taskInfo.taskId]);
|
|
69
|
-
}
|
|
70
|
-
} finally {
|
|
71
|
-
this.state = "idle";
|
|
72
|
-
this.processPendingSignals();
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Build context message for auto-notify
|
|
77
|
-
*/
|
|
78
|
-
buildNotifyContext(signal, taskInfo) {
|
|
79
|
-
if (signal.type === "task:completed" && taskInfo) {
|
|
80
|
-
const resultStr = typeof taskInfo.result === "string" ? taskInfo.result : JSON.stringify(taskInfo.result, null, 2);
|
|
81
|
-
const durationLine = taskInfo.duration !== void 0 ? `Duration: ${taskInfo.duration}ms
|
|
82
|
-
` : "";
|
|
83
|
-
return `[Background Task Completed]
|
|
84
|
-
Task ID: ${taskInfo.taskId}
|
|
85
|
-
Type: ${taskInfo.type}
|
|
86
|
-
Description: ${taskInfo.description}
|
|
87
|
-
` + durationLine + `Result:
|
|
88
|
-
${resultStr}`;
|
|
89
|
-
}
|
|
90
|
-
if (signal.type === "task:failed" && taskInfo) {
|
|
91
|
-
return `[Background Task Failed]
|
|
92
|
-
Task ID: ${taskInfo.taskId}
|
|
93
|
-
Type: ${taskInfo.type}
|
|
94
|
-
Description: ${taskInfo.description}
|
|
95
|
-
Error: ${taskInfo.error}`;
|
|
96
|
-
}
|
|
97
|
-
if (signal.type === "task:cancelled" && taskInfo) {
|
|
98
|
-
const cancelReason = taskInfo.error ?? "Cancelled";
|
|
99
|
-
return `[Background Task Cancelled]
|
|
100
|
-
Task ID: ${taskInfo.taskId}
|
|
101
|
-
Type: ${taskInfo.type}
|
|
102
|
-
Description: ${taskInfo.description}
|
|
103
|
-
Reason: ${cancelReason}`;
|
|
104
|
-
}
|
|
105
|
-
return `[Background Signal]
|
|
106
|
-
${JSON.stringify(signal, null, 2)}`;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Process any pending signals
|
|
110
|
-
*/
|
|
111
|
-
processPendingSignals() {
|
|
112
|
-
while (this.pendingSignals.length > 0 && this.state === "idle") {
|
|
113
|
-
const signal = this.pendingSignals.shift();
|
|
114
|
-
if (signal) {
|
|
115
|
-
void this.processNotify(signal).catch((error) => {
|
|
116
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
117
|
-
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}`;
|
|
118
|
-
this.logger?.error?.(
|
|
119
|
-
`AgentController.processNotify failed for ${signalContext}: ${message}`
|
|
120
|
-
);
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Process user input and generate response
|
|
127
|
-
* @param content User message content
|
|
128
|
-
* @returns Agent response
|
|
129
|
-
*/
|
|
130
|
-
async process(content) {
|
|
131
|
-
if (this.state !== "idle") {
|
|
132
|
-
throw new Error(`Cannot process while agent is ${this.state}`);
|
|
133
|
-
}
|
|
134
|
-
try {
|
|
135
|
-
this.state = "processing";
|
|
136
|
-
const { contextPrefix, notifyTaskIds } = this.buildTaskContext();
|
|
137
|
-
const fullContent = contextPrefix ? `${contextPrefix}
|
|
138
|
-
|
|
139
|
-
${content}` : content;
|
|
140
|
-
const response = await this.agent.generate(fullContent, this.sessionId);
|
|
141
|
-
if (notifyTaskIds.length > 0) {
|
|
142
|
-
this.taskRegistry.acknowledgeNotify(notifyTaskIds);
|
|
143
|
-
}
|
|
144
|
-
return response.content;
|
|
145
|
-
} finally {
|
|
146
|
-
this.state = "idle";
|
|
147
|
-
this.processPendingSignals();
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Process a signal trigger (e.g., from external source)
|
|
152
|
-
*/
|
|
153
|
-
async processSignal(signal) {
|
|
154
|
-
if (this.state !== "idle") {
|
|
155
|
-
this.pendingSignals.push(signal);
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
await this.processNotify(signal);
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Build context about pending/completed tasks
|
|
162
|
-
*/
|
|
163
|
-
buildTaskContext() {
|
|
164
|
-
const running = this.taskRegistry.list({ status: "running" });
|
|
165
|
-
const notifyPending = this.taskRegistry.getNotifyPending();
|
|
166
|
-
if (running.length === 0 && notifyPending.length === 0) {
|
|
167
|
-
return { contextPrefix: "", notifyTaskIds: [] };
|
|
168
|
-
}
|
|
169
|
-
const parts = [];
|
|
170
|
-
if (running.length > 0) {
|
|
171
|
-
parts.push(
|
|
172
|
-
`[Background Tasks Running: ${running.length}]
|
|
173
|
-
` + running.map((t) => `- ${t.taskId}: ${t.description}`).join("\n")
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
if (notifyPending.length > 0) {
|
|
177
|
-
parts.push(
|
|
178
|
-
`[Background Tasks Completed: ${notifyPending.length}]
|
|
179
|
-
` + notifyPending.map((t) => {
|
|
180
|
-
const status = t.error ? `FAILED: ${t.error}` : t.status === "cancelled" ? "CANCELLED" : "SUCCESS";
|
|
181
|
-
return `- ${t.taskId}: ${t.description} [${status}]`;
|
|
182
|
-
}).join("\n")
|
|
183
|
-
);
|
|
184
|
-
}
|
|
185
|
-
return {
|
|
186
|
-
contextPrefix: parts.join("\n\n"),
|
|
187
|
-
notifyTaskIds: notifyPending.map((task) => task.taskId)
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Get current agent state
|
|
192
|
-
*/
|
|
193
|
-
getState() {
|
|
194
|
-
return this.state;
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Get the wrapped agent
|
|
198
|
-
*/
|
|
199
|
-
getAgent() {
|
|
200
|
-
return this.agent;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Get session ID
|
|
204
|
-
*/
|
|
205
|
-
getSessionId() {
|
|
206
|
-
return this.sessionId;
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Inject a signal for processing
|
|
210
|
-
*/
|
|
211
|
-
injectSignal(signal) {
|
|
212
|
-
this.signalBus.emit(signal);
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Clean up resources
|
|
216
|
-
*/
|
|
217
|
-
cleanup() {
|
|
218
|
-
if (this.notifyUnsubscribe) {
|
|
219
|
-
this.notifyUnsubscribe();
|
|
220
|
-
}
|
|
221
|
-
this.pendingSignals = [];
|
|
222
|
-
this.signalBus.clear();
|
|
223
|
-
this.taskRegistry.clear();
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Start the agent (delegates to wrapped agent)
|
|
227
|
-
*/
|
|
228
|
-
async start() {
|
|
229
|
-
await this.agent.start();
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Stop the agent (delegates to wrapped agent)
|
|
233
|
-
*/
|
|
234
|
-
async stop() {
|
|
235
|
-
this.cleanup();
|
|
236
|
-
await this.agent.stop();
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
export {
|
|
240
|
-
AgentController
|
|
241
|
-
};
|
|
@@ -1,149 +0,0 @@
|
|
|
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 start_task_exports = {};
|
|
20
|
-
__export(start_task_exports, {
|
|
21
|
-
StartTaskInputSchema: () => StartTaskInputSchema,
|
|
22
|
-
createGenericTaskStarter: () => createGenericTaskStarter,
|
|
23
|
-
createStartTaskTool: () => createStartTaskTool
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(start_task_exports);
|
|
26
|
-
var import_zod = require("zod");
|
|
27
|
-
const StartTaskInputSchema = import_zod.z.object({
|
|
28
|
-
/** Task type to start */
|
|
29
|
-
type: import_zod.z.enum(["agent", "process", "generic"]).describe("Type of task to start"),
|
|
30
|
-
// Agent task options
|
|
31
|
-
/** Task description for agent (required for type='agent') */
|
|
32
|
-
task: import_zod.z.string().optional().describe("Task description for agent execution"),
|
|
33
|
-
/** Custom system prompt for agent */
|
|
34
|
-
systemPrompt: import_zod.z.string().optional().describe("Custom system prompt for the agent"),
|
|
35
|
-
// Process task options
|
|
36
|
-
/** Command to run (required for type='process') */
|
|
37
|
-
command: import_zod.z.string().optional().describe("Shell command to execute"),
|
|
38
|
-
// Generic task options
|
|
39
|
-
/** Description for generic task */
|
|
40
|
-
description: import_zod.z.string().optional().describe("Description of the task"),
|
|
41
|
-
// Common options
|
|
42
|
-
/** Timeout in milliseconds */
|
|
43
|
-
timeout: import_zod.z.number().positive().optional().describe("Task timeout in milliseconds"),
|
|
44
|
-
/** Auto-notify when complete (triggers agent turn) */
|
|
45
|
-
notify: import_zod.z.boolean().default(false).describe("Auto-notify when task completes")
|
|
46
|
-
}).strict().superRefine((data, ctx) => {
|
|
47
|
-
if (data.type === "agent" && !data.task) {
|
|
48
|
-
ctx.addIssue({
|
|
49
|
-
code: import_zod.z.ZodIssueCode.custom,
|
|
50
|
-
message: 'task is required when type is "agent"',
|
|
51
|
-
path: ["task"]
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
if (data.type === "process" && !data.command) {
|
|
55
|
-
ctx.addIssue({
|
|
56
|
-
code: import_zod.z.ZodIssueCode.custom,
|
|
57
|
-
message: 'command is required when type is "process"',
|
|
58
|
-
path: ["command"]
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
function createStartTaskTool(starters) {
|
|
63
|
-
return {
|
|
64
|
-
id: "start_task",
|
|
65
|
-
description: "Start a background task without waiting for completion. Returns immediately with a task ID. Use wait_for or check_task to monitor progress.",
|
|
66
|
-
inputSchema: StartTaskInputSchema,
|
|
67
|
-
execute: async (rawInput, context) => {
|
|
68
|
-
const input = StartTaskInputSchema.parse(rawInput);
|
|
69
|
-
const starter = starters.get(input.type);
|
|
70
|
-
if (!starter) {
|
|
71
|
-
return {
|
|
72
|
-
success: false,
|
|
73
|
-
error: `No task starter registered for type '${input.type}'. Available types: ${Array.from(starters.keys()).join(", ") || "none"}`
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
try {
|
|
77
|
-
const { taskId, promise } = await starter.start(input);
|
|
78
|
-
const registerOptions = {
|
|
79
|
-
notify: input.notify,
|
|
80
|
-
...input.timeout !== void 0 && { timeout: input.timeout }
|
|
81
|
-
};
|
|
82
|
-
if (input.type === "agent") {
|
|
83
|
-
context.taskRegistry.register(
|
|
84
|
-
{
|
|
85
|
-
type: "agent",
|
|
86
|
-
taskId,
|
|
87
|
-
agentId: taskId,
|
|
88
|
-
// Using taskId as agentId for now
|
|
89
|
-
taskDescription: input.task ?? "",
|
|
90
|
-
promise
|
|
91
|
-
},
|
|
92
|
-
registerOptions
|
|
93
|
-
);
|
|
94
|
-
} else if (input.type === "process") {
|
|
95
|
-
context.taskRegistry.register(
|
|
96
|
-
{
|
|
97
|
-
type: "process",
|
|
98
|
-
taskId,
|
|
99
|
-
processId: taskId,
|
|
100
|
-
command: input.command ?? "",
|
|
101
|
-
promise
|
|
102
|
-
},
|
|
103
|
-
registerOptions
|
|
104
|
-
);
|
|
105
|
-
} else {
|
|
106
|
-
context.taskRegistry.register(
|
|
107
|
-
{
|
|
108
|
-
type: "generic",
|
|
109
|
-
taskId,
|
|
110
|
-
description: input.description ?? "Generic task",
|
|
111
|
-
promise
|
|
112
|
-
},
|
|
113
|
-
registerOptions
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
return {
|
|
117
|
-
success: true,
|
|
118
|
-
taskId,
|
|
119
|
-
status: "running"
|
|
120
|
-
};
|
|
121
|
-
} catch (error) {
|
|
122
|
-
return {
|
|
123
|
-
success: false,
|
|
124
|
-
error: error instanceof Error ? error.message : String(error)
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
function createGenericTaskStarter() {
|
|
131
|
-
let taskCounter = 0;
|
|
132
|
-
return {
|
|
133
|
-
async start(input) {
|
|
134
|
-
const taskId = `generic-${++taskCounter}`;
|
|
135
|
-
const promise = new Promise((resolve) => {
|
|
136
|
-
setTimeout(() => {
|
|
137
|
-
resolve({ completed: true, description: input.description });
|
|
138
|
-
}, 1e3);
|
|
139
|
-
});
|
|
140
|
-
return { taskId, promise };
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
145
|
-
0 && (module.exports = {
|
|
146
|
-
StartTaskInputSchema,
|
|
147
|
-
createGenericTaskStarter,
|
|
148
|
-
createStartTaskTool
|
|
149
|
-
});
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { OrchestrationTool } from './types.cjs';
|
|
3
|
-
import '../task-registry.cjs';
|
|
4
|
-
import '../types.cjs';
|
|
5
|
-
import '../signal-bus.cjs';
|
|
6
|
-
import '../condition-engine.cjs';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* start_task Tool
|
|
10
|
-
*
|
|
11
|
-
* Starts a background task without blocking.
|
|
12
|
-
* This is a higher-level tool that delegates to task-specific providers.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Input schema for start_task tool
|
|
17
|
-
*/
|
|
18
|
-
declare const StartTaskInputSchema: z.ZodEffects<z.ZodObject<{
|
|
19
|
-
/** Task type to start */
|
|
20
|
-
type: z.ZodEnum<["agent", "process", "generic"]>;
|
|
21
|
-
/** Task description for agent (required for type='agent') */
|
|
22
|
-
task: z.ZodOptional<z.ZodString>;
|
|
23
|
-
/** Custom system prompt for agent */
|
|
24
|
-
systemPrompt: z.ZodOptional<z.ZodString>;
|
|
25
|
-
/** Command to run (required for type='process') */
|
|
26
|
-
command: z.ZodOptional<z.ZodString>;
|
|
27
|
-
/** Description for generic task */
|
|
28
|
-
description: z.ZodOptional<z.ZodString>;
|
|
29
|
-
/** Timeout in milliseconds */
|
|
30
|
-
timeout: z.ZodOptional<z.ZodNumber>;
|
|
31
|
-
/** Auto-notify when complete (triggers agent turn) */
|
|
32
|
-
notify: z.ZodDefault<z.ZodBoolean>;
|
|
33
|
-
}, "strict", z.ZodTypeAny, {
|
|
34
|
-
type: "agent" | "process" | "generic";
|
|
35
|
-
notify: boolean;
|
|
36
|
-
timeout?: number | undefined;
|
|
37
|
-
task?: string | undefined;
|
|
38
|
-
command?: string | undefined;
|
|
39
|
-
description?: string | undefined;
|
|
40
|
-
systemPrompt?: string | undefined;
|
|
41
|
-
}, {
|
|
42
|
-
type: "agent" | "process" | "generic";
|
|
43
|
-
timeout?: number | undefined;
|
|
44
|
-
task?: string | undefined;
|
|
45
|
-
command?: string | undefined;
|
|
46
|
-
description?: string | undefined;
|
|
47
|
-
systemPrompt?: string | undefined;
|
|
48
|
-
notify?: boolean | undefined;
|
|
49
|
-
}>, {
|
|
50
|
-
type: "agent" | "process" | "generic";
|
|
51
|
-
notify: boolean;
|
|
52
|
-
timeout?: number | undefined;
|
|
53
|
-
task?: string | undefined;
|
|
54
|
-
command?: string | undefined;
|
|
55
|
-
description?: string | undefined;
|
|
56
|
-
systemPrompt?: string | undefined;
|
|
57
|
-
}, {
|
|
58
|
-
type: "agent" | "process" | "generic";
|
|
59
|
-
timeout?: number | undefined;
|
|
60
|
-
task?: string | undefined;
|
|
61
|
-
command?: string | undefined;
|
|
62
|
-
description?: string | undefined;
|
|
63
|
-
systemPrompt?: string | undefined;
|
|
64
|
-
notify?: boolean | undefined;
|
|
65
|
-
}>;
|
|
66
|
-
type StartTaskInput = z.infer<typeof StartTaskInputSchema>;
|
|
67
|
-
/**
|
|
68
|
-
* Output from start_task tool
|
|
69
|
-
*/
|
|
70
|
-
interface StartTaskOutput {
|
|
71
|
-
/** Whether task was started successfully */
|
|
72
|
-
success: boolean;
|
|
73
|
-
/** Task ID for tracking */
|
|
74
|
-
taskId?: string;
|
|
75
|
-
/** Error message if failed to start */
|
|
76
|
-
error?: string;
|
|
77
|
-
/** Status */
|
|
78
|
-
status?: 'running';
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Task starter interface - implemented by agent-spawner, process-tools, etc.
|
|
82
|
-
*/
|
|
83
|
-
interface TaskStarter {
|
|
84
|
-
/** Start a task and return the promise */
|
|
85
|
-
start(input: StartTaskInput): Promise<{
|
|
86
|
-
taskId: string;
|
|
87
|
-
promise: Promise<unknown>;
|
|
88
|
-
}>;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Create the start_task tool
|
|
92
|
-
*
|
|
93
|
-
* Note: This tool requires task starters to be registered for each task type.
|
|
94
|
-
* Use `registerTaskStarter` to add support for agent/process/generic tasks.
|
|
95
|
-
*/
|
|
96
|
-
declare function createStartTaskTool(starters: Map<string, TaskStarter>): OrchestrationTool;
|
|
97
|
-
/**
|
|
98
|
-
* Create a simple generic task starter for testing
|
|
99
|
-
*/
|
|
100
|
-
declare function createGenericTaskStarter(): TaskStarter;
|
|
101
|
-
|
|
102
|
-
export { type StartTaskInput, StartTaskInputSchema, type StartTaskOutput, type TaskStarter, createGenericTaskStarter, createStartTaskTool };
|