@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.
Files changed (50) hide show
  1. package/LICENSE +44 -0
  2. package/dist/agent-controller.cjs +265 -0
  3. package/dist/agent-controller.d.cts +116 -0
  4. package/dist/agent-controller.d.ts +116 -0
  5. package/dist/agent-controller.js +241 -0
  6. package/dist/condition-engine.cjs +276 -0
  7. package/dist/condition-engine.d.cts +87 -0
  8. package/dist/condition-engine.d.ts +87 -0
  9. package/dist/condition-engine.js +252 -0
  10. package/dist/index.cjs +57 -0
  11. package/dist/index.d.cts +11 -0
  12. package/dist/index.d.ts +11 -0
  13. package/dist/index.js +32 -0
  14. package/dist/signal-bus.cjs +186 -0
  15. package/dist/signal-bus.d.cts +78 -0
  16. package/dist/signal-bus.d.ts +78 -0
  17. package/dist/signal-bus.js +162 -0
  18. package/dist/task-registry.cjs +345 -0
  19. package/dist/task-registry.d.cts +124 -0
  20. package/dist/task-registry.d.ts +124 -0
  21. package/dist/task-registry.js +321 -0
  22. package/dist/tools/check-task.cjs +65 -0
  23. package/dist/tools/check-task.d.cts +56 -0
  24. package/dist/tools/check-task.d.ts +56 -0
  25. package/dist/tools/check-task.js +40 -0
  26. package/dist/tools/index.cjs +51 -0
  27. package/dist/tools/index.d.cts +10 -0
  28. package/dist/tools/index.d.ts +10 -0
  29. package/dist/tools/index.js +19 -0
  30. package/dist/tools/list-tasks.cjs +80 -0
  31. package/dist/tools/list-tasks.d.cts +64 -0
  32. package/dist/tools/list-tasks.d.ts +64 -0
  33. package/dist/tools/list-tasks.js +55 -0
  34. package/dist/tools/start-task.cjs +149 -0
  35. package/dist/tools/start-task.d.cts +102 -0
  36. package/dist/tools/start-task.d.ts +102 -0
  37. package/dist/tools/start-task.js +123 -0
  38. package/dist/tools/types.cjs +16 -0
  39. package/dist/tools/types.d.cts +30 -0
  40. package/dist/tools/types.d.ts +30 -0
  41. package/dist/tools/types.js +0 -0
  42. package/dist/tools/wait-for.cjs +116 -0
  43. package/dist/tools/wait-for.d.cts +74 -0
  44. package/dist/tools/wait-for.d.ts +74 -0
  45. package/dist/tools/wait-for.js +91 -0
  46. package/dist/types.cjs +16 -0
  47. package/dist/types.d.cts +165 -0
  48. package/dist/types.d.ts +165 -0
  49. package/dist/types.js +0 -0
  50. package/package.json +38 -0
@@ -0,0 +1,102 @@
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
+ /**
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 };
@@ -0,0 +1,123 @@
1
+ import { z } from "zod";
2
+ const StartTaskInputSchema = z.object({
3
+ /** Task type to start */
4
+ type: z.enum(["agent", "process", "generic"]).describe("Type of task to start"),
5
+ // Agent task options
6
+ /** Task description for agent (required for type='agent') */
7
+ task: z.string().optional().describe("Task description for agent execution"),
8
+ /** Custom system prompt for agent */
9
+ systemPrompt: z.string().optional().describe("Custom system prompt for the agent"),
10
+ // Process task options
11
+ /** Command to run (required for type='process') */
12
+ command: z.string().optional().describe("Shell command to execute"),
13
+ // Generic task options
14
+ /** Description for generic task */
15
+ description: z.string().optional().describe("Description of the task"),
16
+ // Common options
17
+ /** Timeout in milliseconds */
18
+ timeout: z.number().positive().optional().describe("Task timeout in milliseconds"),
19
+ /** Auto-notify when complete (triggers agent turn) */
20
+ notify: z.boolean().default(false).describe("Auto-notify when task completes")
21
+ }).strict().superRefine((data, ctx) => {
22
+ if (data.type === "agent" && !data.task) {
23
+ ctx.addIssue({
24
+ code: z.ZodIssueCode.custom,
25
+ message: 'task is required when type is "agent"',
26
+ path: ["task"]
27
+ });
28
+ }
29
+ if (data.type === "process" && !data.command) {
30
+ ctx.addIssue({
31
+ code: z.ZodIssueCode.custom,
32
+ message: 'command is required when type is "process"',
33
+ path: ["command"]
34
+ });
35
+ }
36
+ });
37
+ function createStartTaskTool(starters) {
38
+ return {
39
+ id: "start_task",
40
+ description: "Start a background task without waiting for completion. Returns immediately with a task ID. Use wait_for or check_task to monitor progress.",
41
+ inputSchema: StartTaskInputSchema,
42
+ execute: async (rawInput, context) => {
43
+ const input = StartTaskInputSchema.parse(rawInput);
44
+ const starter = starters.get(input.type);
45
+ if (!starter) {
46
+ return {
47
+ success: false,
48
+ error: `No task starter registered for type '${input.type}'. Available types: ${Array.from(starters.keys()).join(", ") || "none"}`
49
+ };
50
+ }
51
+ try {
52
+ const { taskId, promise } = await starter.start(input);
53
+ const registerOptions = {
54
+ notify: input.notify,
55
+ ...input.timeout !== void 0 && { timeout: input.timeout }
56
+ };
57
+ if (input.type === "agent") {
58
+ context.taskRegistry.register(
59
+ {
60
+ type: "agent",
61
+ taskId,
62
+ agentId: taskId,
63
+ // Using taskId as agentId for now
64
+ taskDescription: input.task ?? "",
65
+ promise
66
+ },
67
+ registerOptions
68
+ );
69
+ } else if (input.type === "process") {
70
+ context.taskRegistry.register(
71
+ {
72
+ type: "process",
73
+ taskId,
74
+ processId: taskId,
75
+ command: input.command ?? "",
76
+ promise
77
+ },
78
+ registerOptions
79
+ );
80
+ } else {
81
+ context.taskRegistry.register(
82
+ {
83
+ type: "generic",
84
+ taskId,
85
+ description: input.description ?? "Generic task",
86
+ promise
87
+ },
88
+ registerOptions
89
+ );
90
+ }
91
+ return {
92
+ success: true,
93
+ taskId,
94
+ status: "running"
95
+ };
96
+ } catch (error) {
97
+ return {
98
+ success: false,
99
+ error: error instanceof Error ? error.message : String(error)
100
+ };
101
+ }
102
+ }
103
+ };
104
+ }
105
+ function createGenericTaskStarter() {
106
+ let taskCounter = 0;
107
+ return {
108
+ async start(input) {
109
+ const taskId = `generic-${++taskCounter}`;
110
+ const promise = new Promise((resolve) => {
111
+ setTimeout(() => {
112
+ resolve({ completed: true, description: input.description });
113
+ }, 1e3);
114
+ });
115
+ return { taskId, promise };
116
+ }
117
+ };
118
+ }
119
+ export {
120
+ StartTaskInputSchema,
121
+ createGenericTaskStarter,
122
+ createStartTaskTool
123
+ };
@@ -0,0 +1,16 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var types_exports = {};
16
+ module.exports = __toCommonJS(types_exports);
@@ -0,0 +1,30 @@
1
+ import { TaskRegistry } from '../task-registry.cjs';
2
+ import { ConditionEngine } from '../condition-engine.cjs';
3
+ import { SignalBus } from '../signal-bus.cjs';
4
+ import '../types.cjs';
5
+
6
+ /**
7
+ * Tool Types
8
+ *
9
+ * Shared types for orchestration tools.
10
+ */
11
+
12
+ /**
13
+ * Context provided to orchestration tools
14
+ */
15
+ interface OrchestrationToolContext {
16
+ taskRegistry: TaskRegistry;
17
+ conditionEngine: ConditionEngine;
18
+ signalBus: SignalBus;
19
+ }
20
+ /**
21
+ * Base tool interface matching @dexto/core InternalTool
22
+ */
23
+ interface OrchestrationTool {
24
+ id: string;
25
+ description: string;
26
+ inputSchema: unknown;
27
+ execute: (input: unknown, context: OrchestrationToolContext) => Promise<unknown>;
28
+ }
29
+
30
+ export type { OrchestrationTool, OrchestrationToolContext };
@@ -0,0 +1,30 @@
1
+ import { TaskRegistry } from '../task-registry.js';
2
+ import { ConditionEngine } from '../condition-engine.js';
3
+ import { SignalBus } from '../signal-bus.js';
4
+ import '../types.js';
5
+
6
+ /**
7
+ * Tool Types
8
+ *
9
+ * Shared types for orchestration tools.
10
+ */
11
+
12
+ /**
13
+ * Context provided to orchestration tools
14
+ */
15
+ interface OrchestrationToolContext {
16
+ taskRegistry: TaskRegistry;
17
+ conditionEngine: ConditionEngine;
18
+ signalBus: SignalBus;
19
+ }
20
+ /**
21
+ * Base tool interface matching @dexto/core InternalTool
22
+ */
23
+ interface OrchestrationTool {
24
+ id: string;
25
+ description: string;
26
+ inputSchema: unknown;
27
+ execute: (input: unknown, context: OrchestrationToolContext) => Promise<unknown>;
28
+ }
29
+
30
+ export type { OrchestrationTool, OrchestrationToolContext };
File without changes
@@ -0,0 +1,116 @@
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 wait_for_exports = {};
20
+ __export(wait_for_exports, {
21
+ WaitForInputSchema: () => WaitForInputSchema,
22
+ createWaitForTool: () => createWaitForTool
23
+ });
24
+ module.exports = __toCommonJS(wait_for_exports);
25
+ var import_zod = require("zod");
26
+ var import_crypto = require("crypto");
27
+ var import_condition_engine = require("../condition-engine.js");
28
+ const WaitForInputSchema = import_zod.z.object({
29
+ /** Wait for a single task */
30
+ taskId: import_zod.z.string().optional().describe("Task ID to wait for"),
31
+ /** Wait for multiple tasks */
32
+ taskIds: import_zod.z.array(import_zod.z.string()).optional().describe("Array of task IDs to wait for"),
33
+ /** Mode for multiple tasks: any = first to complete, all = wait for all */
34
+ mode: import_zod.z.enum(["any", "all"]).optional().default("all").describe('Wait mode: "any" returns when first completes, "all" waits for all'),
35
+ /** Timeout in milliseconds */
36
+ timeout: import_zod.z.number().positive().optional().describe("Maximum time to wait in milliseconds")
37
+ }).strict().refine(
38
+ (data) => data.taskId !== void 0 || data.taskIds !== void 0 && data.taskIds.length > 0,
39
+ { message: "Either taskId or taskIds must be provided" }
40
+ );
41
+ function buildCondition(input) {
42
+ const taskIds = input.taskId ? [input.taskId] : input.taskIds ?? [];
43
+ if (taskIds.length === 0) {
44
+ throw new Error("At least one taskId is required");
45
+ }
46
+ const firstTaskId = taskIds[0];
47
+ let baseCondition;
48
+ if (taskIds.length === 1) {
49
+ baseCondition = { type: "task", taskId: firstTaskId };
50
+ } else if (input.mode === "any") {
51
+ baseCondition = import_condition_engine.ConditionEngine.createAnyTask(taskIds);
52
+ } else {
53
+ baseCondition = import_condition_engine.ConditionEngine.createAllTasks(taskIds);
54
+ }
55
+ if (input.timeout !== void 0) {
56
+ return {
57
+ type: "race",
58
+ task: baseCondition,
59
+ timeout: {
60
+ type: "timeout",
61
+ ms: input.timeout,
62
+ conditionId: `timeout-${(0, import_crypto.randomUUID)().slice(0, 8)}`
63
+ }
64
+ };
65
+ }
66
+ return baseCondition;
67
+ }
68
+ function formatOutput(signal, allSignals) {
69
+ if (signal.type === "timeout") {
70
+ return {
71
+ taskId: signal.conditionId,
72
+ status: "timeout",
73
+ error: "Wait timed out"
74
+ };
75
+ }
76
+ const baseOutput = {
77
+ taskId: "taskId" in signal ? signal.taskId : "",
78
+ status: signal.type === "task:completed" ? "completed" : signal.type === "task:failed" ? "failed" : "cancelled"
79
+ };
80
+ if (signal.type === "task:completed") {
81
+ baseOutput.result = signal.result;
82
+ } else if (signal.type === "task:failed") {
83
+ baseOutput.error = signal.error;
84
+ }
85
+ if (allSignals && allSignals.length > 1) {
86
+ baseOutput.allResults = allSignals.map((s) => {
87
+ if (s.type === "task:completed") {
88
+ return { taskId: s.taskId, status: "completed", result: s.result };
89
+ } else if (s.type === "task:failed") {
90
+ return { taskId: s.taskId, status: "failed", error: s.error };
91
+ } else if (s.type === "task:cancelled") {
92
+ return { taskId: s.taskId, status: "cancelled" };
93
+ }
94
+ return { taskId: "", status: "failed", error: "Unknown signal type" };
95
+ });
96
+ }
97
+ return baseOutput;
98
+ }
99
+ function createWaitForTool() {
100
+ return {
101
+ id: "wait_for",
102
+ 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.",
103
+ inputSchema: WaitForInputSchema,
104
+ execute: async (rawInput, context) => {
105
+ const input = WaitForInputSchema.parse(rawInput);
106
+ const condition = buildCondition(input);
107
+ const { signal, allSignals } = await context.conditionEngine.wait(condition);
108
+ return formatOutput(signal, allSignals);
109
+ }
110
+ };
111
+ }
112
+ // Annotate the CommonJS export names for ESM import in node:
113
+ 0 && (module.exports = {
114
+ WaitForInputSchema,
115
+ createWaitForTool
116
+ });
@@ -0,0 +1,74 @@
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
+ * wait_for Tool
10
+ *
11
+ * Suspends agent execution until condition is met using a blocking promise.
12
+ * TurnExecutor naturally awaits tool execution, so this works seamlessly.
13
+ */
14
+
15
+ /**
16
+ * Input schema for wait_for tool
17
+ */
18
+ declare const WaitForInputSchema: z.ZodEffects<z.ZodObject<{
19
+ /** Wait for a single task */
20
+ taskId: z.ZodOptional<z.ZodString>;
21
+ /** Wait for multiple tasks */
22
+ taskIds: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
23
+ /** Mode for multiple tasks: any = first to complete, all = wait for all */
24
+ mode: z.ZodDefault<z.ZodOptional<z.ZodEnum<["any", "all"]>>>;
25
+ /** Timeout in milliseconds */
26
+ timeout: z.ZodOptional<z.ZodNumber>;
27
+ }, "strict", z.ZodTypeAny, {
28
+ mode: "any" | "all";
29
+ timeout?: number | undefined;
30
+ taskId?: string | undefined;
31
+ taskIds?: string[] | undefined;
32
+ }, {
33
+ timeout?: number | undefined;
34
+ taskId?: string | undefined;
35
+ taskIds?: string[] | undefined;
36
+ mode?: "any" | "all" | undefined;
37
+ }>, {
38
+ mode: "any" | "all";
39
+ timeout?: number | undefined;
40
+ taskId?: string | undefined;
41
+ taskIds?: string[] | undefined;
42
+ }, {
43
+ timeout?: number | undefined;
44
+ taskId?: string | undefined;
45
+ taskIds?: string[] | undefined;
46
+ mode?: "any" | "all" | undefined;
47
+ }>;
48
+ type WaitForInput = z.infer<typeof WaitForInputSchema>;
49
+ /**
50
+ * Output from wait_for tool
51
+ */
52
+ interface WaitForOutput {
53
+ /** Task ID that triggered the return (for 'any' mode) */
54
+ taskId: string;
55
+ /** Final status */
56
+ status: 'completed' | 'failed' | 'cancelled' | 'timeout';
57
+ /** Result if completed */
58
+ result?: unknown;
59
+ /** Error if failed */
60
+ error?: string;
61
+ /** All results for 'all' mode */
62
+ allResults?: Array<{
63
+ taskId: string;
64
+ status: 'completed' | 'failed' | 'cancelled';
65
+ result?: unknown;
66
+ error?: string;
67
+ }>;
68
+ }
69
+ /**
70
+ * Create the wait_for tool
71
+ */
72
+ declare function createWaitForTool(): OrchestrationTool;
73
+
74
+ export { type WaitForInput, WaitForInputSchema, type WaitForOutput, createWaitForTool };
@@ -0,0 +1,74 @@
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
+ /**
9
+ * wait_for Tool
10
+ *
11
+ * Suspends agent execution until condition is met using a blocking promise.
12
+ * TurnExecutor naturally awaits tool execution, so this works seamlessly.
13
+ */
14
+
15
+ /**
16
+ * Input schema for wait_for tool
17
+ */
18
+ declare const WaitForInputSchema: z.ZodEffects<z.ZodObject<{
19
+ /** Wait for a single task */
20
+ taskId: z.ZodOptional<z.ZodString>;
21
+ /** Wait for multiple tasks */
22
+ taskIds: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
23
+ /** Mode for multiple tasks: any = first to complete, all = wait for all */
24
+ mode: z.ZodDefault<z.ZodOptional<z.ZodEnum<["any", "all"]>>>;
25
+ /** Timeout in milliseconds */
26
+ timeout: z.ZodOptional<z.ZodNumber>;
27
+ }, "strict", z.ZodTypeAny, {
28
+ mode: "any" | "all";
29
+ timeout?: number | undefined;
30
+ taskId?: string | undefined;
31
+ taskIds?: string[] | undefined;
32
+ }, {
33
+ timeout?: number | undefined;
34
+ taskId?: string | undefined;
35
+ taskIds?: string[] | undefined;
36
+ mode?: "any" | "all" | undefined;
37
+ }>, {
38
+ mode: "any" | "all";
39
+ timeout?: number | undefined;
40
+ taskId?: string | undefined;
41
+ taskIds?: string[] | undefined;
42
+ }, {
43
+ timeout?: number | undefined;
44
+ taskId?: string | undefined;
45
+ taskIds?: string[] | undefined;
46
+ mode?: "any" | "all" | undefined;
47
+ }>;
48
+ type WaitForInput = z.infer<typeof WaitForInputSchema>;
49
+ /**
50
+ * Output from wait_for tool
51
+ */
52
+ interface WaitForOutput {
53
+ /** Task ID that triggered the return (for 'any' mode) */
54
+ taskId: string;
55
+ /** Final status */
56
+ status: 'completed' | 'failed' | 'cancelled' | 'timeout';
57
+ /** Result if completed */
58
+ result?: unknown;
59
+ /** Error if failed */
60
+ error?: string;
61
+ /** All results for 'all' mode */
62
+ allResults?: Array<{
63
+ taskId: string;
64
+ status: 'completed' | 'failed' | 'cancelled';
65
+ result?: unknown;
66
+ error?: string;
67
+ }>;
68
+ }
69
+ /**
70
+ * Create the wait_for tool
71
+ */
72
+ declare function createWaitForTool(): OrchestrationTool;
73
+
74
+ export { type WaitForInput, WaitForInputSchema, type WaitForOutput, createWaitForTool };
@@ -0,0 +1,91 @@
1
+ import { z } from "zod";
2
+ import { randomUUID } from "crypto";
3
+ import { ConditionEngine } from "../condition-engine.js";
4
+ const WaitForInputSchema = z.object({
5
+ /** Wait for a single task */
6
+ taskId: z.string().optional().describe("Task ID to wait for"),
7
+ /** Wait for multiple tasks */
8
+ taskIds: z.array(z.string()).optional().describe("Array of task IDs to wait for"),
9
+ /** Mode for multiple tasks: any = first to complete, all = wait for all */
10
+ mode: z.enum(["any", "all"]).optional().default("all").describe('Wait mode: "any" returns when first completes, "all" waits for all'),
11
+ /** Timeout in milliseconds */
12
+ timeout: z.number().positive().optional().describe("Maximum time to wait in milliseconds")
13
+ }).strict().refine(
14
+ (data) => data.taskId !== void 0 || data.taskIds !== void 0 && data.taskIds.length > 0,
15
+ { message: "Either taskId or taskIds must be provided" }
16
+ );
17
+ function buildCondition(input) {
18
+ const taskIds = input.taskId ? [input.taskId] : input.taskIds ?? [];
19
+ if (taskIds.length === 0) {
20
+ throw new Error("At least one taskId is required");
21
+ }
22
+ const firstTaskId = taskIds[0];
23
+ let baseCondition;
24
+ if (taskIds.length === 1) {
25
+ baseCondition = { type: "task", taskId: firstTaskId };
26
+ } else if (input.mode === "any") {
27
+ baseCondition = ConditionEngine.createAnyTask(taskIds);
28
+ } else {
29
+ baseCondition = ConditionEngine.createAllTasks(taskIds);
30
+ }
31
+ if (input.timeout !== void 0) {
32
+ return {
33
+ type: "race",
34
+ task: baseCondition,
35
+ timeout: {
36
+ type: "timeout",
37
+ ms: input.timeout,
38
+ conditionId: `timeout-${randomUUID().slice(0, 8)}`
39
+ }
40
+ };
41
+ }
42
+ return baseCondition;
43
+ }
44
+ function formatOutput(signal, allSignals) {
45
+ if (signal.type === "timeout") {
46
+ return {
47
+ taskId: signal.conditionId,
48
+ status: "timeout",
49
+ error: "Wait timed out"
50
+ };
51
+ }
52
+ const baseOutput = {
53
+ taskId: "taskId" in signal ? signal.taskId : "",
54
+ status: signal.type === "task:completed" ? "completed" : signal.type === "task:failed" ? "failed" : "cancelled"
55
+ };
56
+ if (signal.type === "task:completed") {
57
+ baseOutput.result = signal.result;
58
+ } else if (signal.type === "task:failed") {
59
+ baseOutput.error = signal.error;
60
+ }
61
+ if (allSignals && allSignals.length > 1) {
62
+ baseOutput.allResults = allSignals.map((s) => {
63
+ if (s.type === "task:completed") {
64
+ return { taskId: s.taskId, status: "completed", result: s.result };
65
+ } else if (s.type === "task:failed") {
66
+ return { taskId: s.taskId, status: "failed", error: s.error };
67
+ } else if (s.type === "task:cancelled") {
68
+ return { taskId: s.taskId, status: "cancelled" };
69
+ }
70
+ return { taskId: "", status: "failed", error: "Unknown signal type" };
71
+ });
72
+ }
73
+ return baseOutput;
74
+ }
75
+ function createWaitForTool() {
76
+ return {
77
+ id: "wait_for",
78
+ 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
+ inputSchema: WaitForInputSchema,
80
+ execute: async (rawInput, context) => {
81
+ const input = WaitForInputSchema.parse(rawInput);
82
+ const condition = buildCondition(input);
83
+ const { signal, allSignals } = await context.conditionEngine.wait(condition);
84
+ return formatOutput(signal, allSignals);
85
+ }
86
+ };
87
+ }
88
+ export {
89
+ WaitForInputSchema,
90
+ createWaitForTool
91
+ };
package/dist/types.cjs ADDED
@@ -0,0 +1,16 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var types_exports = {};
16
+ module.exports = __toCommonJS(types_exports);