@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.
Files changed (46) hide show
  1. package/dist/condition-engine.d.ts +6 -8
  2. package/dist/condition-engine.d.ts.map +1 -0
  3. package/dist/index.cjs +0 -9
  4. package/dist/index.d.cts +1 -3
  5. package/dist/index.d.ts +41 -10
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +2 -18
  8. package/dist/signal-bus.d.ts +5 -8
  9. package/dist/signal-bus.d.ts.map +1 -0
  10. package/dist/task-registry.d.ts +5 -8
  11. package/dist/task-registry.d.ts.map +1 -0
  12. package/dist/tools/check-task.cjs +4 -4
  13. package/dist/tools/check-task.d.cts +3 -4
  14. package/dist/tools/check-task.d.ts +8 -14
  15. package/dist/tools/check-task.d.ts.map +1 -0
  16. package/dist/tools/check-task.js +4 -4
  17. package/dist/tools/index.cjs +0 -8
  18. package/dist/tools/index.d.cts +4 -5
  19. package/dist/tools/index.d.ts +15 -10
  20. package/dist/tools/index.d.ts.map +1 -0
  21. package/dist/tools/index.js +0 -5
  22. package/dist/tools/list-tasks.cjs +5 -5
  23. package/dist/tools/list-tasks.d.cts +3 -4
  24. package/dist/tools/list-tasks.d.ts +10 -15
  25. package/dist/tools/list-tasks.d.ts.map +1 -0
  26. package/dist/tools/list-tasks.js +5 -5
  27. package/dist/tools/wait-for.cjs +4 -4
  28. package/dist/tools/wait-for.d.cts +5 -5
  29. package/dist/tools/wait-for.d.ts +8 -14
  30. package/dist/tools/wait-for.d.ts.map +1 -0
  31. package/dist/tools/wait-for.js +4 -4
  32. package/dist/types.d.ts +14 -15
  33. package/dist/types.d.ts.map +1 -0
  34. package/package.json +3 -2
  35. package/dist/agent-controller.cjs +0 -265
  36. package/dist/agent-controller.d.cts +0 -116
  37. package/dist/agent-controller.d.ts +0 -116
  38. package/dist/agent-controller.js +0 -241
  39. package/dist/tools/start-task.cjs +0 -149
  40. package/dist/tools/start-task.d.cts +0 -102
  41. package/dist/tools/start-task.d.ts +0 -102
  42. package/dist/tools/start-task.js +0 -123
  43. package/dist/tools/types.cjs +0 -16
  44. package/dist/tools/types.d.cts +0 -30
  45. package/dist/tools/types.d.ts +0 -30
  46. package/dist/tools/types.js +0 -0
@@ -1,9 +1,9 @@
1
1
  import { z } from 'zod';
2
- import { OrchestrationTool } from './types.cjs';
3
- import '../task-registry.cjs';
2
+ import { ConditionEngine } from '../condition-engine.cjs';
3
+ import { Tool } from '@dexto/core';
4
4
  import '../types.cjs';
5
5
  import '../signal-bus.cjs';
6
- import '../condition-engine.cjs';
6
+ import '../task-registry.cjs';
7
7
 
8
8
  /**
9
9
  * wait_for Tool
@@ -45,7 +45,7 @@ declare const WaitForInputSchema: z.ZodEffects<z.ZodObject<{
45
45
  taskIds?: string[] | undefined;
46
46
  mode?: "any" | "all" | undefined;
47
47
  }>;
48
- type WaitForInput = z.infer<typeof WaitForInputSchema>;
48
+ type WaitForInput = z.output<typeof WaitForInputSchema>;
49
49
  /**
50
50
  * Output from wait_for tool
51
51
  */
@@ -69,6 +69,6 @@ interface WaitForOutput {
69
69
  /**
70
70
  * Create the wait_for tool
71
71
  */
72
- declare function createWaitForTool(): OrchestrationTool;
72
+ declare function createWaitForTool(conditionEngine: ConditionEngine): Tool<typeof WaitForInputSchema>;
73
73
 
74
74
  export { type WaitForInput, WaitForInputSchema, type WaitForOutput, createWaitForTool };
@@ -1,21 +1,16 @@
1
- import { z } from 'zod';
2
- import { OrchestrationTool } from './types.js';
3
- import '../task-registry.js';
4
- import '../types.js';
5
- import '../signal-bus.js';
6
- import '../condition-engine.js';
7
-
8
1
  /**
9
2
  * wait_for Tool
10
3
  *
11
4
  * Suspends agent execution until condition is met using a blocking promise.
12
5
  * TurnExecutor naturally awaits tool execution, so this works seamlessly.
13
6
  */
14
-
7
+ import { z } from 'zod';
8
+ import { ConditionEngine } from '../condition-engine.js';
9
+ import type { Tool } from '@dexto/core';
15
10
  /**
16
11
  * Input schema for wait_for tool
17
12
  */
18
- declare const WaitForInputSchema: z.ZodEffects<z.ZodObject<{
13
+ export declare const WaitForInputSchema: z.ZodEffects<z.ZodObject<{
19
14
  /** Wait for a single task */
20
15
  taskId: z.ZodOptional<z.ZodString>;
21
16
  /** Wait for multiple tasks */
@@ -45,11 +40,11 @@ declare const WaitForInputSchema: z.ZodEffects<z.ZodObject<{
45
40
  taskIds?: string[] | undefined;
46
41
  mode?: "any" | "all" | undefined;
47
42
  }>;
48
- type WaitForInput = z.infer<typeof WaitForInputSchema>;
43
+ export type WaitForInput = z.output<typeof WaitForInputSchema>;
49
44
  /**
50
45
  * Output from wait_for tool
51
46
  */
52
- interface WaitForOutput {
47
+ export interface WaitForOutput {
53
48
  /** Task ID that triggered the return (for 'any' mode) */
54
49
  taskId: string;
55
50
  /** Final status */
@@ -69,6 +64,5 @@ interface WaitForOutput {
69
64
  /**
70
65
  * Create the wait_for tool
71
66
  */
72
- declare function createWaitForTool(): OrchestrationTool;
73
-
74
- export { type WaitForInput, WaitForInputSchema, type WaitForOutput, createWaitForTool };
67
+ export declare function createWaitForTool(conditionEngine: ConditionEngine): Tool<typeof WaitForInputSchema>;
68
+ //# sourceMappingURL=wait-for.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wait-for.d.ts","sourceRoot":"","sources":["../../src/tools/wait-for.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAExC;;GAEG;AACH,eAAO,MAAM,kBAAkB;IAEvB,6BAA6B;;IAG7B,8BAA8B;;IAG9B,2EAA2E;;IAO3E,8BAA8B;;;;;;;;;;;;;;;;;;;;;;EAQjC,CAAC;AAEN,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE/D;;GAEG;AACH,MAAM,WAAW,aAAa;IAC1B,yDAAyD;IACzD,MAAM,EAAE,MAAM,CAAC;IACf,mBAAmB;IACnB,MAAM,EAAE,WAAW,GAAG,QAAQ,GAAG,WAAW,GAAG,SAAS,CAAC;IACzD,0BAA0B;IAC1B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,sBAAsB;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iCAAiC;IACjC,UAAU,CAAC,EAAE,KAAK,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;QAC7C,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC,CAAC;CACN;AAoFD;;GAEG;AACH,wBAAgB,iBAAiB,CAC7B,eAAe,EAAE,eAAe,GACjC,IAAI,CAAC,OAAO,kBAAkB,CAAC,CAkBjC"}
@@ -72,15 +72,15 @@ function formatOutput(signal, allSignals) {
72
72
  }
73
73
  return baseOutput;
74
74
  }
75
- function createWaitForTool() {
75
+ function createWaitForTool(conditionEngine) {
76
76
  return {
77
77
  id: "wait_for",
78
+ displayName: "Wait",
78
79
  description: "Wait for background task(s) to complete. Blocks execution until the condition is met. Use taskId for a single task, or taskIds with mode for multiple tasks.",
79
80
  inputSchema: WaitForInputSchema,
80
- execute: async (rawInput, context) => {
81
- const input = WaitForInputSchema.parse(rawInput);
81
+ execute: async (input, _context) => {
82
82
  const condition = buildCondition(input);
83
- const { signal, allSignals } = await context.conditionEngine.wait(condition);
83
+ const { signal, allSignals } = await conditionEngine.wait(condition);
84
84
  return formatOutput(signal, allSignals);
85
85
  }
86
86
  };
package/dist/types.d.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  /**
8
8
  * Task result from agent or process execution
9
9
  */
10
- interface TaskResult {
10
+ export interface TaskResult {
11
11
  success: boolean;
12
12
  response?: string;
13
13
  error?: string;
@@ -21,7 +21,7 @@ interface TaskResult {
21
21
  /**
22
22
  * Process result from shell command execution
23
23
  */
24
- interface ProcessResult {
24
+ export interface ProcessResult {
25
25
  stdout: string;
26
26
  stderr: string;
27
27
  exitCode: number;
@@ -30,7 +30,7 @@ interface ProcessResult {
30
30
  /**
31
31
  * Task types - discriminated union of different background task kinds
32
32
  */
33
- type Task = {
33
+ export type Task = {
34
34
  type: 'agent';
35
35
  taskId: string;
36
36
  agentId: string;
@@ -51,11 +51,11 @@ type Task = {
51
51
  /**
52
52
  * Task lifecycle status
53
53
  */
54
- type TaskStatus = 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
54
+ export type TaskStatus = 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
55
55
  /**
56
56
  * Entry in the task registry tracking a background task
57
57
  */
58
- interface TaskEntry {
58
+ export interface TaskEntry {
59
59
  task: Task;
60
60
  status: TaskStatus;
61
61
  startedAt: Date;
@@ -70,7 +70,7 @@ interface TaskEntry {
70
70
  /**
71
71
  * Signal types - events that trigger state transitions
72
72
  */
73
- type Signal = {
73
+ export type Signal = {
74
74
  type: 'task:completed';
75
75
  taskId: string;
76
76
  result: unknown;
@@ -96,11 +96,11 @@ type Signal = {
96
96
  /**
97
97
  * Extract signal type string
98
98
  */
99
- type SignalType = Signal['type'];
99
+ export type SignalType = Signal['type'];
100
100
  /**
101
101
  * Wait conditions - composable conditions for suspension
102
102
  */
103
- type WaitCondition = {
103
+ export type WaitCondition = {
104
104
  type: 'task';
105
105
  taskId: string;
106
106
  } | {
@@ -121,11 +121,11 @@ type WaitCondition = {
121
121
  /**
122
122
  * Agent loop states
123
123
  */
124
- type AgentState = 'idle' | 'processing' | 'waiting';
124
+ export type AgentState = 'idle' | 'processing' | 'waiting';
125
125
  /**
126
126
  * Task info returned by list/check operations (without internal promise)
127
127
  */
128
- interface TaskInfo {
128
+ export interface TaskInfo {
129
129
  taskId: string;
130
130
  type: Task['type'];
131
131
  status: TaskStatus;
@@ -140,14 +140,14 @@ interface TaskInfo {
140
140
  /**
141
141
  * Filter options for listing tasks
142
142
  */
143
- interface TaskFilter {
143
+ export interface TaskFilter {
144
144
  status?: TaskStatus | TaskStatus[];
145
145
  type?: Task['type'];
146
146
  }
147
147
  /**
148
148
  * Result from waiting on a condition
149
149
  */
150
- interface WaitResult {
150
+ export interface WaitResult {
151
151
  signal: Signal;
152
152
  /** For 'all' conditions, contains all signals */
153
153
  allSignals?: Signal[];
@@ -155,11 +155,10 @@ interface WaitResult {
155
155
  /**
156
156
  * Options for registering a task
157
157
  */
158
- interface RegisterTaskOptions {
158
+ export interface RegisterTaskOptions {
159
159
  /** Auto-trigger agent turn on completion */
160
160
  notify?: boolean;
161
161
  /** Timeout in milliseconds */
162
162
  timeout?: number;
163
163
  }
164
-
165
- export type { AgentState, ProcessResult, RegisterTaskOptions, Signal, SignalType, Task, TaskEntry, TaskFilter, TaskInfo, TaskResult, TaskStatus, WaitCondition, WaitResult };
164
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,UAAU;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE;QACT,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;KACjB,CAAC;CACL;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM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,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACvB,MAAM,CAAC,EAAE,UAAU,GAAG,UAAU,EAAE,CAAC;IACnC,IAAI,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,iDAAiD;IACjD,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAChC,4CAA4C;IAC5C,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,8BAA8B;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dexto/orchestration",
3
- "version": "1.5.8",
3
+ "version": "1.6.0",
4
4
  "description": "Agent orchestration layer for background task management, event-driven completion handling, and async workflows",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -20,7 +20,8 @@
20
20
  "workflow"
21
21
  ],
22
22
  "dependencies": {
23
- "zod": "^3.25.0"
23
+ "zod": "^3.25.0",
24
+ "@dexto/core": "1.6.0"
24
25
  },
25
26
  "devDependencies": {
26
27
  "tsup": "^8.0.0",
@@ -1,265 +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 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
- });
@@ -1,116 +0,0 @@
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 };