@hexabot-ai/agentic 3.0.1-alpha.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 (176) hide show
  1. package/LICENSE.md +120 -0
  2. package/README.md +231 -0
  3. package/dist/cjs/action/abstract-action.js +141 -0
  4. package/dist/cjs/action/action.js +47 -0
  5. package/dist/cjs/action/action.types.js +7 -0
  6. package/dist/cjs/bindings/base-binding.js +278 -0
  7. package/dist/cjs/context.js +79 -0
  8. package/dist/cjs/dsl.types.js +318 -0
  9. package/dist/cjs/index.js +52 -0
  10. package/dist/cjs/runner-runtime-control.js +343 -0
  11. package/dist/cjs/step-executors/conditional-executor.js +63 -0
  12. package/dist/cjs/step-executors/loop-executor.js +187 -0
  13. package/dist/cjs/step-executors/parallel-executor.js +51 -0
  14. package/dist/cjs/step-executors/skip-helpers.js +29 -0
  15. package/dist/cjs/step-executors/task-executor.js +155 -0
  16. package/dist/cjs/step-executors/types.js +7 -0
  17. package/dist/cjs/suspension-rebuilder.js +301 -0
  18. package/dist/cjs/utils/deferred.js +17 -0
  19. package/dist/cjs/utils/naming.js +48 -0
  20. package/dist/cjs/utils/timeout.js +42 -0
  21. package/dist/cjs/utils/workflow-definition.js +102 -0
  22. package/dist/cjs/workflow-compiler.js +212 -0
  23. package/dist/cjs/workflow-event-emitter.js +40 -0
  24. package/dist/cjs/workflow-runner.js +448 -0
  25. package/dist/cjs/workflow-types.js +7 -0
  26. package/dist/cjs/workflow-values.js +99 -0
  27. package/dist/cjs/workflow.js +243 -0
  28. package/dist/esm/action/abstract-action.js +137 -0
  29. package/dist/esm/action/action.js +44 -0
  30. package/dist/esm/action/action.types.js +6 -0
  31. package/dist/esm/bindings/base-binding.js +273 -0
  32. package/dist/esm/context.js +75 -0
  33. package/dist/esm/dsl.types.js +309 -0
  34. package/dist/esm/index.js +16 -0
  35. package/dist/esm/runner-runtime-control.js +338 -0
  36. package/dist/esm/step-executors/conditional-executor.js +60 -0
  37. package/dist/esm/step-executors/loop-executor.js +182 -0
  38. package/dist/esm/step-executors/parallel-executor.js +48 -0
  39. package/dist/esm/step-executors/skip-helpers.js +25 -0
  40. package/dist/esm/step-executors/task-executor.js +152 -0
  41. package/dist/esm/step-executors/types.js +6 -0
  42. package/dist/esm/suspension-rebuilder.js +296 -0
  43. package/dist/esm/utils/deferred.js +14 -0
  44. package/dist/esm/utils/naming.js +42 -0
  45. package/dist/esm/utils/timeout.js +37 -0
  46. package/dist/esm/utils/workflow-definition.js +98 -0
  47. package/dist/esm/workflow-compiler.js +208 -0
  48. package/dist/esm/workflow-event-emitter.js +36 -0
  49. package/dist/esm/workflow-runner.js +444 -0
  50. package/dist/esm/workflow-types.js +6 -0
  51. package/dist/esm/workflow-values.js +89 -0
  52. package/dist/esm/workflow.js +236 -0
  53. package/dist/types/action/abstract-action.d.ts +54 -0
  54. package/dist/types/action/abstract-action.d.ts.map +1 -0
  55. package/dist/types/action/action.d.ts +23 -0
  56. package/dist/types/action/action.d.ts.map +1 -0
  57. package/dist/types/action/action.types.d.ts +55 -0
  58. package/dist/types/action/action.types.d.ts.map +1 -0
  59. package/dist/types/bindings/base-binding.d.ts +52 -0
  60. package/dist/types/bindings/base-binding.d.ts.map +1 -0
  61. package/dist/types/context.d.ts +105 -0
  62. package/dist/types/context.d.ts.map +1 -0
  63. package/dist/types/dsl.types.d.ts +220 -0
  64. package/dist/types/dsl.types.d.ts.map +1 -0
  65. package/dist/types/index.d.ts +18 -0
  66. package/dist/types/index.d.ts.map +1 -0
  67. package/dist/types/runner-runtime-control.d.ts +64 -0
  68. package/dist/types/runner-runtime-control.d.ts.map +1 -0
  69. package/dist/types/step-executors/conditional-executor.d.ts +13 -0
  70. package/dist/types/step-executors/conditional-executor.d.ts.map +1 -0
  71. package/dist/types/step-executors/loop-executor.d.ts +33 -0
  72. package/dist/types/step-executors/loop-executor.d.ts.map +1 -0
  73. package/dist/types/step-executors/parallel-executor.d.ts +14 -0
  74. package/dist/types/step-executors/parallel-executor.d.ts.map +1 -0
  75. package/dist/types/step-executors/skip-helpers.d.ts +12 -0
  76. package/dist/types/step-executors/skip-helpers.d.ts.map +1 -0
  77. package/dist/types/step-executors/task-executor.d.ts +13 -0
  78. package/dist/types/step-executors/task-executor.d.ts.map +1 -0
  79. package/dist/types/step-executors/types.d.ts +24 -0
  80. package/dist/types/step-executors/types.d.ts.map +1 -0
  81. package/dist/types/suspension-rebuilder.d.ts +67 -0
  82. package/dist/types/suspension-rebuilder.d.ts.map +1 -0
  83. package/dist/types/utils/deferred.d.ts +7 -0
  84. package/dist/types/utils/deferred.d.ts.map +1 -0
  85. package/dist/types/utils/naming.d.ts +24 -0
  86. package/dist/types/utils/naming.d.ts.map +1 -0
  87. package/dist/types/utils/timeout.d.ts +17 -0
  88. package/dist/types/utils/timeout.d.ts.map +1 -0
  89. package/dist/types/utils/workflow-definition.d.ts +3 -0
  90. package/dist/types/utils/workflow-definition.d.ts.map +1 -0
  91. package/dist/types/workflow-compiler.d.ts +12 -0
  92. package/dist/types/workflow-compiler.d.ts.map +1 -0
  93. package/dist/types/workflow-event-emitter.d.ts +70 -0
  94. package/dist/types/workflow-event-emitter.d.ts.map +1 -0
  95. package/dist/types/workflow-runner.d.ts +179 -0
  96. package/dist/types/workflow-runner.d.ts.map +1 -0
  97. package/dist/types/workflow-types.d.ts +195 -0
  98. package/dist/types/workflow-types.d.ts.map +1 -0
  99. package/dist/types/workflow-values.d.ts +34 -0
  100. package/dist/types/workflow-values.d.ts.map +1 -0
  101. package/dist/types/workflow.d.ts +75 -0
  102. package/dist/types/workflow.d.ts.map +1 -0
  103. package/examples/defs-bindings-agent/actions/ai-agent.ts +110 -0
  104. package/examples/defs-bindings-agent/actions/caculate-score.ts +49 -0
  105. package/examples/defs-bindings-agent/actions/index.ts +15 -0
  106. package/examples/defs-bindings-agent/bindings.ts +20 -0
  107. package/examples/defs-bindings-agent/context.ts +32 -0
  108. package/examples/defs-bindings-agent/workflow.ts +67 -0
  109. package/examples/defs-bindings-agent/workflow.yml +28 -0
  110. package/examples/full/actions/await-user-input.ts +46 -0
  111. package/examples/full/actions/call-llm.ts +133 -0
  112. package/examples/full/actions/create-ticket.ts +46 -0
  113. package/examples/full/actions/decision-router.ts +83 -0
  114. package/examples/full/actions/get-calendar-events.ts +55 -0
  115. package/examples/full/actions/get-user-profile.ts +72 -0
  116. package/examples/full/actions/index.ts +33 -0
  117. package/examples/full/actions/query-memory.ts +45 -0
  118. package/examples/full/actions/search-web.ts +53 -0
  119. package/examples/full/actions/send-email.ts +50 -0
  120. package/examples/full/context.ts +41 -0
  121. package/examples/full/workflow.ts +75 -0
  122. package/examples/full/workflow.yml +359 -0
  123. package/examples/loop/actions/await-reply.ts +47 -0
  124. package/examples/loop/actions/index.ts +19 -0
  125. package/examples/loop/actions/send-text-message.ts +40 -0
  126. package/examples/loop/context.ts +32 -0
  127. package/examples/loop/workflow.ts +66 -0
  128. package/examples/loop/workflow.yml +66 -0
  129. package/examples/suspend-resume/actions/format-reply.ts +43 -0
  130. package/examples/suspend-resume/actions/index.ts +13 -0
  131. package/examples/suspend-resume/actions/wait-for-user.ts +51 -0
  132. package/examples/suspend-resume/context.ts +32 -0
  133. package/examples/suspend-resume/workflow.ts +79 -0
  134. package/examples/suspend-resume/workflow.yml +29 -0
  135. package/package.json +60 -0
  136. package/src/__tests__/parser.test.ts +95 -0
  137. package/src/__tests__/suspension-rebuilder.test.ts +361 -0
  138. package/src/__tests__/test-helpers.ts +36 -0
  139. package/src/__tests__/validation.test.ts +526 -0
  140. package/src/__tests__/workflow-compiler.test.ts +715 -0
  141. package/src/__tests__/workflow-definition-path.test.ts +381 -0
  142. package/src/__tests__/workflow-event-emitter.test.ts +50 -0
  143. package/src/__tests__/workflow-runner.test.ts +1397 -0
  144. package/src/__tests__/workflow-values.test.ts +132 -0
  145. package/src/__tests__/workflow.test.ts +320 -0
  146. package/src/action/__tests__/abstract-action-timing.test.ts +183 -0
  147. package/src/action/__tests__/action.test.ts +473 -0
  148. package/src/action/abstract-action.ts +215 -0
  149. package/src/action/action.ts +83 -0
  150. package/src/action/action.types.ts +93 -0
  151. package/src/bindings/base-binding.ts +508 -0
  152. package/src/context.ts +179 -0
  153. package/src/dsl.types.ts +473 -0
  154. package/src/index.ts +114 -0
  155. package/src/runner-runtime-control.ts +544 -0
  156. package/src/step-executors/conditional-executor.test.ts +192 -0
  157. package/src/step-executors/conditional-executor.ts +83 -0
  158. package/src/step-executors/loop-executor.test.ts +303 -0
  159. package/src/step-executors/loop-executor.ts +299 -0
  160. package/src/step-executors/parallel-executor.test.ts +182 -0
  161. package/src/step-executors/parallel-executor.ts +77 -0
  162. package/src/step-executors/skip-helpers.ts +68 -0
  163. package/src/step-executors/task-executor.test.ts +257 -0
  164. package/src/step-executors/task-executor.ts +248 -0
  165. package/src/step-executors/types.ts +70 -0
  166. package/src/suspension-rebuilder.ts +504 -0
  167. package/src/utils/deferred.ts +23 -0
  168. package/src/utils/naming.ts +55 -0
  169. package/src/utils/timeout.ts +48 -0
  170. package/src/utils/workflow-definition.ts +173 -0
  171. package/src/workflow-compiler.ts +317 -0
  172. package/src/workflow-event-emitter.ts +86 -0
  173. package/src/workflow-runner.ts +603 -0
  174. package/src/workflow-types.ts +207 -0
  175. package/src/workflow-values.ts +159 -0
  176. package/src/workflow.ts +387 -0
@@ -0,0 +1,89 @@
1
+ /*
2
+ * Hexabot — Fair Core License (FCL-1.0-ALv2)
3
+ * Copyright (c) 2025 Hexastack.
4
+ * Full terms: see LICENSE.md.
5
+ */
6
+ import jsonata from 'jsonata';
7
+ /** Basic object guard that rejects arrays and null. */
8
+ const isPlainObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
9
+ const registerJsonataFunctions = (expression, registry) => {
10
+ if (!registry) {
11
+ return;
12
+ }
13
+ for (const [name, config] of Object.entries(registry)) {
14
+ if (typeof config === 'function') {
15
+ expression.registerFunction(name, config);
16
+ continue;
17
+ }
18
+ if (config && typeof config.implementation === 'function') {
19
+ expression.registerFunction(name, config.implementation, config.signature);
20
+ continue;
21
+ }
22
+ throw new Error(`Invalid JSONata function config for "${name}"`);
23
+ }
24
+ };
25
+ /**
26
+ * Prepares a workflow value for evaluation.
27
+ * Strings prefixed with `=` are treated as JSONata expressions; everything else is a literal.
28
+ */
29
+ export const compileValue = (value, options) => {
30
+ if (typeof value === 'string' && value.startsWith('=')) {
31
+ const expression = jsonata(value.slice(1));
32
+ registerJsonataFunctions(expression, options?.jsonataFunctions);
33
+ return { kind: 'expression', source: value, expression };
34
+ }
35
+ return { kind: 'literal', value };
36
+ };
37
+ /**
38
+ * Evaluate a compiled value against the current workflow scope.
39
+ * Expressions are executed via JSONata with the scope exposed as variables; `context`
40
+ * represents the workflow context state, not the context instance itself.
41
+ */
42
+ export const evaluateValue = async (compiled, scope) => {
43
+ if (compiled.kind === 'literal') {
44
+ return compiled.value;
45
+ }
46
+ return compiled.expression.evaluate({}, {
47
+ input: scope.input,
48
+ context: scope.context,
49
+ output: scope.output,
50
+ iteration: scope.iteration,
51
+ accumulator: scope.accumulator,
52
+ result: scope.result,
53
+ });
54
+ };
55
+ /**
56
+ * Evaluate all entries of a compiled mapping, returning a plain object.
57
+ * Missing mappings resolve to an empty object.
58
+ */
59
+ export const evaluateMapping = async (mapping, scope) => {
60
+ if (!mapping) {
61
+ return {};
62
+ }
63
+ const result = {};
64
+ for (const [key, compiled] of Object.entries(mapping)) {
65
+ result[key] = await evaluateValue(compiled, scope);
66
+ }
67
+ return result;
68
+ };
69
+ /**
70
+ * Deep-merge workflow settings, preferring non-undefined overrides.
71
+ * Nested objects are merged recursively to preserve defaults.
72
+ */
73
+ export const mergeSettings = (base, override) => {
74
+ const merged = { ...(base ?? {}) };
75
+ if (!override) {
76
+ return merged;
77
+ }
78
+ for (const key of Object.keys(override)) {
79
+ const value = override[key];
80
+ const previous = merged[key];
81
+ if (isPlainObject(previous) && isPlainObject(value)) {
82
+ merged[key] = mergeSettings(previous, value);
83
+ }
84
+ else if (value !== undefined) {
85
+ merged[key] = value;
86
+ }
87
+ }
88
+ return merged;
89
+ };
@@ -0,0 +1,236 @@
1
+ /*
2
+ * Hexabot — Fair Core License (FCL-1.0-ALv2)
3
+ * Copyright (c) 2025 Hexastack.
4
+ * Full terms: see LICENSE.md.
5
+ */
6
+ import { stringify as stringifyYaml } from 'yaml';
7
+ import { TASK_KIND, WorkflowDefinitionSchema, validateWorkflow, } from './dsl.types';
8
+ import { safeRenameTaskInDefinition as safeRenameTaskInDefinitionHelper } from './utils/workflow-definition';
9
+ import { compileWorkflow, } from './workflow-compiler';
10
+ import { WorkflowRunner } from './workflow-runner';
11
+ export { compileWorkflow } from './workflow-compiler';
12
+ export { WorkflowEventEmitter } from './workflow-event-emitter';
13
+ export { WorkflowRunner } from './workflow-runner';
14
+ class WorkflowRunSuspendedError extends Error {
15
+ constructor(stepId, options) {
16
+ super(`Workflow run suspended at step ${stepId}${options?.reason ? `: ${options.reason}` : ''}`);
17
+ this.name = 'WorkflowRunSuspendedError';
18
+ this.stepId = stepId;
19
+ this.reason = options?.reason;
20
+ this.data = options?.data;
21
+ }
22
+ }
23
+ const getTaskNameFromStep = (step) => {
24
+ if (!step || typeof step !== 'object') {
25
+ return null;
26
+ }
27
+ const taskName = step.do;
28
+ return typeof taskName === 'string' ? taskName : null;
29
+ };
30
+ const hasTaskReference = (steps, taskName) => {
31
+ return steps.some((step) => {
32
+ if ('do' in step) {
33
+ return step.do === taskName;
34
+ }
35
+ if ('parallel' in step) {
36
+ return hasTaskReference(step.parallel.steps, taskName);
37
+ }
38
+ if ('conditional' in step) {
39
+ return step.conditional.when.some((branch) => hasTaskReference(branch.steps, taskName));
40
+ }
41
+ if ('loop' in step) {
42
+ return hasTaskReference(step.loop.steps, taskName);
43
+ }
44
+ return false;
45
+ });
46
+ };
47
+ /**
48
+ * Entry point for preparing and executing workflows from YAML or object definitions.
49
+ * Instances are thin wrappers around a compiled workflow graph.
50
+ */
51
+ export class Workflow {
52
+ constructor(compiled) {
53
+ this.compiled = compiled;
54
+ }
55
+ /**
56
+ * Create a workflow from an already parsed definition.
57
+ * The definition is validated before compilation to catch schema issues early.
58
+ */
59
+ static fromDefinition(definition, options) {
60
+ const validation = validateWorkflow(definition, {
61
+ bindingKinds: options.bindingKinds,
62
+ actions: options.actions,
63
+ });
64
+ if (!validation.success) {
65
+ throw new Error(`Workflow validation failed: ${validation.errors.join('; ')}`);
66
+ }
67
+ const compiled = compileWorkflow(validation.data, options);
68
+ return new Workflow(compiled);
69
+ }
70
+ /**
71
+ * Create a workflow from YAML source.
72
+ * YAML is validated and compiled before being wrapped in a {@link Workflow} instance.
73
+ */
74
+ static fromYaml(yaml, options) {
75
+ const validation = validateWorkflow(yaml, {
76
+ bindingKinds: options.bindingKinds,
77
+ actions: options.actions,
78
+ });
79
+ if (!validation.success) {
80
+ throw new Error(`Workflow validation failed: ${validation.errors.join('; ')}`);
81
+ }
82
+ const compiled = compileWorkflow(validation.data, options);
83
+ return new Workflow(compiled);
84
+ }
85
+ /**
86
+ * Convert a workflow definition to YAML.
87
+ * The definition is validated before serialization.
88
+ */
89
+ static stringifyDefinition(definition) {
90
+ const parsed = WorkflowDefinitionSchema.parse(definition);
91
+ return stringifyYaml(parsed);
92
+ }
93
+ /**
94
+ * Resolve a nested value from a workflow definition by path.
95
+ */
96
+ static getValueAtPath(value, path) {
97
+ return path.reduce((acc, key) => {
98
+ if (acc === null || acc === undefined) {
99
+ return undefined;
100
+ }
101
+ if (Array.isArray(acc)) {
102
+ return typeof key === 'number' ? acc[key] : undefined;
103
+ }
104
+ if (typeof acc === 'object') {
105
+ return acc[String(key)];
106
+ }
107
+ return undefined;
108
+ }, value);
109
+ }
110
+ /**
111
+ * Create a new value with a nested path updated immutably.
112
+ */
113
+ static setValueAtPath(value, path, nextValue) {
114
+ if (path.length === 0) {
115
+ return nextValue;
116
+ }
117
+ const [key, ...rest] = path;
118
+ if (Array.isArray(value)) {
119
+ if (typeof key !== 'number') {
120
+ return value;
121
+ }
122
+ const nextArray = [...value];
123
+ nextArray[key] = Workflow.setValueAtPath(value[key], rest, nextValue);
124
+ return nextArray;
125
+ }
126
+ if (value && typeof value === 'object') {
127
+ return {
128
+ ...value,
129
+ [String(key)]: Workflow.setValueAtPath(value[String(key)], rest, nextValue),
130
+ };
131
+ }
132
+ return value;
133
+ }
134
+ /**
135
+ * Remove a flow step from the definition at the given path, if valid.
136
+ */
137
+ static removeStepAtPath(definition, stepPath) {
138
+ if (!stepPath.length) {
139
+ return null;
140
+ }
141
+ const removeIndex = stepPath[stepPath.length - 1];
142
+ if (typeof removeIndex !== 'number') {
143
+ return null;
144
+ }
145
+ const stepsPath = stepPath.slice(0, -1);
146
+ const steps = Workflow.getValueAtPath(definition, stepsPath);
147
+ if (!Array.isArray(steps)) {
148
+ return null;
149
+ }
150
+ if (removeIndex < 0 || removeIndex >= steps.length) {
151
+ return null;
152
+ }
153
+ const removedTaskName = getTaskNameFromStep(steps[removeIndex]);
154
+ const nextSteps = [...steps];
155
+ nextSteps.splice(removeIndex, 1);
156
+ const nextDefinition = Workflow.setValueAtPath(definition, stepsPath, nextSteps);
157
+ if (!removedTaskName ||
158
+ !Object.prototype.hasOwnProperty.call(nextDefinition.defs, removedTaskName)) {
159
+ return nextDefinition;
160
+ }
161
+ if (nextDefinition.defs[removedTaskName]?.kind !== TASK_KIND) {
162
+ return nextDefinition;
163
+ }
164
+ if (hasTaskReference(nextDefinition.flow, removedTaskName)) {
165
+ return nextDefinition;
166
+ }
167
+ const { [removedTaskName]: _removedTask, ...remainingDefs } = nextDefinition.defs;
168
+ return {
169
+ ...nextDefinition,
170
+ defs: remainingDefs,
171
+ };
172
+ }
173
+ /**
174
+ * Insert a flow step into the definition at the given path, if valid.
175
+ */
176
+ static insertStepAtPath(definition, insertPath, step) {
177
+ if (!insertPath.length) {
178
+ return null;
179
+ }
180
+ const insertIndex = insertPath[insertPath.length - 1];
181
+ if (typeof insertIndex !== 'number') {
182
+ return null;
183
+ }
184
+ const stepsPath = insertPath.slice(0, -1);
185
+ const steps = Workflow.getValueAtPath(definition, stepsPath);
186
+ if (!Array.isArray(steps)) {
187
+ return null;
188
+ }
189
+ const nextSteps = [...steps];
190
+ const safeIndex = Math.min(Math.max(insertIndex, 0), nextSteps.length);
191
+ nextSteps.splice(safeIndex, 0, step);
192
+ return Workflow.setValueAtPath(definition, stepsPath, nextSteps);
193
+ }
194
+ /**
195
+ * Rename a task key and update references in flow steps and output expressions.
196
+ */
197
+ static safeRenameTaskInDefinition(definition, currentTaskName, nextTaskName) {
198
+ return safeRenameTaskInDefinitionHelper(definition, currentTaskName, nextTaskName);
199
+ }
200
+ /**
201
+ * Run the workflow until completion or suspension.
202
+ * Throws when a task suspends so callers can capture the state.
203
+ */
204
+ async run(inputData, context, options) {
205
+ const runner = new WorkflowRunner(this.compiled, options);
206
+ const result = await runner.start({
207
+ inputData,
208
+ context,
209
+ });
210
+ if (result.status === 'finished') {
211
+ return result.output;
212
+ }
213
+ if (result.status === 'failed') {
214
+ throw result.error instanceof Error
215
+ ? result.error
216
+ : new Error(String(result.error));
217
+ }
218
+ context.attachWorkflowRuntime(undefined);
219
+ throw new WorkflowRunSuspendedError(result.step.id, {
220
+ reason: result.reason,
221
+ data: result.data,
222
+ });
223
+ }
224
+ /**
225
+ * Construct a runner without executing, allowing hosts to manage start/resume manually.
226
+ */
227
+ async buildAsyncRunner(options) {
228
+ return new WorkflowRunner(this.compiled, options);
229
+ }
230
+ /**
231
+ * Rebuild a runner from persisted state and snapshot, useful after restarts.
232
+ */
233
+ async buildRunnerFromState(options) {
234
+ return WorkflowRunner.fromPersistedState(this.compiled, options);
235
+ }
236
+ }
@@ -0,0 +1,54 @@
1
+ import { ZodType } from 'zod';
2
+ import { BaseWorkflowContext } from '../context';
3
+ import { Action, ActionExecutionArgs, ActionMetadata, AnyRuntimeBindings, RuntimeSettings } from './action.types';
4
+ /**
5
+ * Base implementation that enforces schema-validated input/output.
6
+ */
7
+ export declare abstract class AbstractAction<I, O, C extends BaseWorkflowContext, S, B extends AnyRuntimeBindings = AnyRuntimeBindings> implements Action<I, O, C, S, B> {
8
+ readonly name: string;
9
+ readonly description: string;
10
+ readonly inputSchema: ZodType<I>;
11
+ readonly outputSchema: ZodType<O>;
12
+ readonly settingSchema: ZodType<S>;
13
+ readonly supportedBindings: readonly string[];
14
+ /**
15
+ * Sets up core metadata and schemas for the action.
16
+ *
17
+ * @param metadata - Describes the action name, description, and schemas.
18
+ * @param options - Optional configuration or definition override.
19
+ */
20
+ protected constructor(metadata: ActionMetadata<I, O, S>);
21
+ /**
22
+ * Parses incoming payloads using the input schema.
23
+ *
24
+ * @param payload - Raw input received by the action.
25
+ * @returns Validated input typed as `I`.
26
+ */
27
+ parseInput(payload: unknown): I;
28
+ /**
29
+ * Validates and returns the raw action output.
30
+ *
31
+ * @param payload - Raw output produced by {@link execute}.
32
+ * @returns Output typed as `O` after schema validation.
33
+ */
34
+ parseOutput(payload: unknown): O;
35
+ /**
36
+ * Executes the action with retry, timeout, and schema safety.
37
+ *
38
+ * @param payload - Raw input being provided to the action.
39
+ * @param context - Workflow context used during execution.
40
+ * @returns Validated output produced by the action.
41
+ * @throws Error when retries are exhausted or validation fails.
42
+ */
43
+ parseSettings(payload: unknown): RuntimeSettings<S>;
44
+ run(payload: unknown, context: C, settings?: Partial<RuntimeSettings<S>>, bindings?: B): Promise<O>;
45
+ private assertSupportedBindings;
46
+ /**
47
+ * Runs the core business logic for the action.
48
+ *
49
+ * @param args - Strongly typed input and context for the action.
50
+ * @returns Action output wrapped in a promise.
51
+ */
52
+ abstract execute(args: ActionExecutionArgs<I, C, S, B>): Promise<O>;
53
+ }
54
+ //# sourceMappingURL=abstract-action.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abstract-action.d.ts","sourceRoot":"","sources":["../../../src/action/abstract-action.ts"],"names":[],"mappings":"AAMA,OAAO,EAAK,OAAO,EAAE,MAAM,KAAK,CAAC;AAEjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;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,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CACpE"}
@@ -0,0 +1,23 @@
1
+ import { ZodType } from 'zod';
2
+ import { BaseWorkflowContext } from '../context';
3
+ import type { Action, ActionExecutionArgs, AnyRuntimeBindings } from './action.types';
4
+ export type DefineActionParams<I, O, Ctx extends BaseWorkflowContext, S, B extends AnyRuntimeBindings = AnyRuntimeBindings> = {
5
+ name: string;
6
+ description?: string;
7
+ supportedBindings?: readonly string[];
8
+ inputSchema?: ZodType<I>;
9
+ outputSchema?: ZodType<O>;
10
+ settingSchema?: ZodType<S>;
11
+ execute: (args: ActionExecutionArgs<I, Ctx, S, B>) => Promise<O> | O;
12
+ };
13
+ /**
14
+ * Builds an {@link AbstractAction} subclass from simple configuration.
15
+ *
16
+ * @param params - Action definition containing metadata and runtime logic.
17
+ * @returns Instantiated action ready to be used by a workflow.
18
+ * @typeParam I - Action input type.
19
+ * @typeParam O - Action output type.
20
+ * @typeParam Ctx - Workflow context type.
21
+ */
22
+ export declare function defineAction<I, O, Ctx extends BaseWorkflowContext, S, B extends AnyRuntimeBindings = AnyRuntimeBindings>(params: DefineActionParams<I, O, Ctx, S, B>): Action<I, O, Ctx, S, B>;
23
+ //# sourceMappingURL=action.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../../../src/action/action.ts"],"names":[],"mappings":"AAMA,OAAO,EAAK,OAAO,EAAE,MAAM,KAAK,CAAC;AAEjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAGjD,OAAO,KAAK,EACV,MAAM,EACN,mBAAmB,EAEnB,kBAAkB,EACnB,MAAM,gBAAgB,CAAC;AAExB,MAAM,MAAM,kBAAkB,CAC5B,CAAC,EACD,CAAC,EACD,GAAG,SAAS,mBAAmB,EAC/B,CAAC,EACD,CAAC,SAAS,kBAAkB,GAAG,kBAAkB,IAC/C;IACF,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iBAAiB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,WAAW,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACzB,YAAY,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAC1B,aAAa,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAC3B,OAAO,EAAE,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;CACtE,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC1B,CAAC,EACD,CAAC,EACD,GAAG,SAAS,mBAAmB,EAC/B,CAAC,EACD,CAAC,SAAS,kBAAkB,GAAG,kBAAkB,EACjD,MAAM,EAAE,kBAAkB,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAiCtE"}
@@ -0,0 +1,55 @@
1
+ import { ZodType } from 'zod';
2
+ import type { InferWorkflowBindings } from '../bindings/base-binding';
3
+ import { BaseWorkflowContext } from '../context';
4
+ import { Settings } from '../dsl.types';
5
+ import { Deferred } from '../utils/deferred';
6
+ export type RuntimeSettings<S = unknown> = Settings & S;
7
+ export type AnyRuntimeBindings = InferWorkflowBindings;
8
+ export interface ActionMetadata<I, O, S> {
9
+ name: string;
10
+ description: string;
11
+ inputSchema: ZodType<I>;
12
+ outputSchema: ZodType<O>;
13
+ settingsSchema: ZodType<S>;
14
+ supportedBindings?: readonly string[];
15
+ }
16
+ export interface ActionExecutionArgs<I, C extends BaseWorkflowContext = BaseWorkflowContext, S = unknown, B extends AnyRuntimeBindings = AnyRuntimeBindings> {
17
+ input: I;
18
+ context: C;
19
+ settings: RuntimeSettings<S>;
20
+ bindings: B;
21
+ }
22
+ export interface Action<I = unknown, O = unknown, C extends BaseWorkflowContext = BaseWorkflowContext, S = unknown, B extends AnyRuntimeBindings = AnyRuntimeBindings> {
23
+ readonly name: string;
24
+ readonly description: string;
25
+ readonly inputSchema: ZodType<I>;
26
+ readonly outputSchema: ZodType<O>;
27
+ readonly settingSchema?: ZodType<S>;
28
+ readonly supportedBindings?: readonly string[];
29
+ execute(args: ActionExecutionArgs<I, C, S, B>): Promise<O>;
30
+ parseInput(payload: unknown): I;
31
+ parseOutput(payload: unknown): O;
32
+ parseSettings(payload: unknown): RuntimeSettings<S>;
33
+ run(payload: unknown, context: C, settings?: Partial<RuntimeSettings<S>>, bindings?: B): Promise<O>;
34
+ }
35
+ export type Actions = Record<string, Action>;
36
+ export type InferActionArgs<A extends Action> = Parameters<A['execute']>[0];
37
+ export type InferActionInput<A extends Action> = InferActionArgs<A>['input'];
38
+ export type InferActionContext<A extends Action> = InferActionArgs<A>['context'];
39
+ export type InferActionOutput<A extends Action> = Awaited<ReturnType<A['execute']>>;
40
+ export type InferActionSettings<S extends Action> = InferActionArgs<S>['settings'];
41
+ export type InferActionBindings<S extends Action> = InferActionArgs<S>['bindings'];
42
+ export interface SuspensionNotice {
43
+ stepId: string;
44
+ reason?: string;
45
+ data?: unknown;
46
+ resume: Deferred<unknown>;
47
+ }
48
+ export type ActionExecutionOutcome<T> = {
49
+ type: 'completed';
50
+ value: T;
51
+ } | {
52
+ type: 'suspended';
53
+ notice: SuspensionNotice;
54
+ };
55
+ //# sourceMappingURL=action.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action.types.d.ts","sourceRoot":"","sources":["../../../src/action/action.types.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAE9B,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAA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AAe,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;AAEjC,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,MAAM,IAC9C,eAAe,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;AAEjC,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;CAC3B;AAED,MAAM,MAAM,sBAAsB,CAAC,CAAC,IAChC;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,gBAAgB,CAAA;CAAE,CAAC"}
@@ -0,0 +1,52 @@
1
+ import { z } from 'zod';
2
+ export type BindingKindSchema = z.ZodTypeAny;
3
+ export type BindingActionPolicy = 'forbidden' | 'optional' | 'required';
4
+ export type BindingValidationActionMetadata = {
5
+ supportedBindings?: readonly string[];
6
+ };
7
+ export type BindingKindDescriptor<TSchema extends z.ZodTypeAny = BindingKindSchema, TMultiple extends boolean = boolean> = {
8
+ schema: TSchema;
9
+ multiple: TMultiple;
10
+ supportedBindings?: readonly string[];
11
+ actionPolicy?: BindingActionPolicy;
12
+ };
13
+ export type BindingKindSchemas = Record<string, BindingKindDescriptor>;
14
+ export type MountedBindingPayload<TBindingKind extends BindingKindDescriptor = BindingKindDescriptor, TBindingKinds extends BindingKindSchemas = BindingKindSchemas> = {
15
+ settings: z.infer<TBindingKind['schema']>;
16
+ action?: string;
17
+ bindings?: InferWorkflowBindings<TBindingKinds>;
18
+ };
19
+ export type InferMountedBindingValue<TBindingKind extends BindingKindDescriptor = BindingKindDescriptor, TBindingKinds extends BindingKindSchemas = BindingKindSchemas> = TBindingKind['multiple'] extends true ? Record<string, MountedBindingPayload<TBindingKind, TBindingKinds>> : TBindingKind['multiple'] extends false ? MountedBindingPayload<TBindingKind, TBindingKinds> : MountedBindingPayload<TBindingKind, TBindingKinds> | Record<string, MountedBindingPayload<TBindingKind, TBindingKinds>>;
20
+ export type InferWorkflowBindings<TBindingKinds extends BindingKindSchemas = BindingKindSchemas> = Partial<{
21
+ [K in keyof TBindingKinds & string]: InferMountedBindingValue<TBindingKinds[K], TBindingKinds>;
22
+ }>;
23
+ export type CompiledTaskBindings = InferWorkflowBindings;
24
+ export type TaskBindingReferences = Record<string, string | string[]>;
25
+ export type DefLike = {
26
+ kind: string;
27
+ description?: string;
28
+ action?: string;
29
+ settings?: unknown;
30
+ bindings?: TaskBindingReferences;
31
+ [key: string]: unknown;
32
+ };
33
+ export type BindingAwareWorkflowLike = {
34
+ defs: Record<string, DefLike>;
35
+ };
36
+ export type ResolvedBindingDef = {
37
+ kind: string;
38
+ payload: MountedBindingPayload;
39
+ };
40
+ export type ResolvedBindingDefs = Record<string, ResolvedBindingDef>;
41
+ export type ValidateAndResolveBindingsOptions = {
42
+ bindingKinds?: BindingKindSchemas;
43
+ actions?: Record<string, BindingValidationActionMetadata>;
44
+ };
45
+ type BindingValidationResult = {
46
+ errors: string[];
47
+ resolvedDefs: ResolvedBindingDefs;
48
+ };
49
+ export declare const validateAndResolveBindings: (workflow: BindingAwareWorkflowLike, options?: BindingKindSchemas | ValidateAndResolveBindingsOptions) => BindingValidationResult;
50
+ export declare const mountTaskBindings: (taskBindings: TaskBindingReferences | undefined, resolvedDefs: ResolvedBindingDefs, bindingKinds?: BindingKindSchemas, resolveDef?: (defName: string) => MountedBindingPayload | undefined) => CompiledTaskBindings;
51
+ export {};
52
+ //# sourceMappingURL=base-binding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-binding.d.ts","sourceRoot":"","sources":["../../../src/bindings/base-binding.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,CAAC,EAAiB,MAAM,KAAK,CAAC;AAIvC,MAAM,MAAM,iBAAiB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,CAAC;AAsJF,eAAO,MAAM,0BAA0B,GACrC,UAAU,wBAAwB,EAClC,UAAU,kBAAkB,GAAG,iCAAiC,KAC/D,uBA8MF,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,cAAc,qBAAqB,GAAG,SAAS,EAC/C,cAAc,mBAAmB,EACjC,eAAe,kBAAkB,EACjC,aAAa,CAAC,OAAO,EAAE,MAAM,KAAK,qBAAqB,GAAG,SAAS,KAClE,oBAkDF,CAAC"}
@@ -0,0 +1,105 @@
1
+ import type { EventEmitterLike, WorkflowEventEmitterLike } from './workflow-event-emitter';
2
+ /**
3
+ * Lifecycle of a workflow run:
4
+ * - idle: runner constructed but `start` not invoked.
5
+ * - running: set when `start` or `resume` begins executing steps.
6
+ * - suspended: an action awaited `workflow.suspend`; `resume` moves back to running.
7
+ * - finished: all steps completed and outputs were evaluated successfully.
8
+ * - failed: an uncaught error bubbled out of a step or continuation.
9
+ */
10
+ export type WorkflowRunStatus = 'idle' | 'running' | 'suspended' | 'finished' | 'failed';
11
+ /**
12
+ * Lifecycle of an individual action/step captured in snapshots:
13
+ * - pending: defined but not yet executed (default before runner touches the step).
14
+ * - running: inputs evaluated and action invoked.
15
+ * - suspended: action paused via `workflow.suspend`; resumes to completed.
16
+ * - completed: action resolved (either immediately or after resume).
17
+ * - failed: action threw an error.
18
+ * - skipped: control flow bypassed the step (e.g., alternate branch or wait_any short-circuit).
19
+ */
20
+ export type ActionStatus = 'pending' | 'running' | 'suspended' | 'completed' | 'failed' | 'skipped';
21
+ export interface SuspensionOptions {
22
+ key?: string;
23
+ reason?: string;
24
+ data?: unknown;
25
+ }
26
+ export interface ActionSnapshot {
27
+ id: string;
28
+ name: string;
29
+ status: ActionStatus;
30
+ reason?: string;
31
+ }
32
+ export type StepExecutionRecord = {
33
+ id: string;
34
+ name: string;
35
+ action?: string;
36
+ status: ActionStatus;
37
+ startedAt?: number;
38
+ endedAt?: number;
39
+ input?: unknown;
40
+ output?: unknown;
41
+ context?: {
42
+ before?: Record<string, unknown>;
43
+ after?: Record<string, unknown>;
44
+ };
45
+ error?: {
46
+ message: string;
47
+ stack?: string;
48
+ };
49
+ reason?: string;
50
+ };
51
+ export interface WorkflowSnapshot {
52
+ status: WorkflowRunStatus;
53
+ actions: Record<string, ActionSnapshot>;
54
+ }
55
+ export interface WorkflowRuntimeControl {
56
+ readonly status: WorkflowRunStatus;
57
+ readonly resumeData: unknown;
58
+ /**
59
+ * Suspends the currently running action and returns a promise that settles when the workflow resumes.
60
+ *
61
+ * @param options - Optional metadata describing why the suspension occurred.
62
+ * @returns Promise resolved with the data supplied to {@link resume}.
63
+ */
64
+ suspend<T = unknown>(options?: SuspensionOptions): Promise<T>;
65
+ resume(data?: unknown): void;
66
+ getSnapshot(): WorkflowSnapshot;
67
+ }
68
+ /**
69
+ * Base context that is threaded through every workflow execution.
70
+ *
71
+ * Extend this class in user-land to expose shared services such as loggers,
72
+ * event emitters, database connections, or feature flags.
73
+ */
74
+ export declare abstract class BaseWorkflowContext<S extends Record<string, unknown> = Record<string, unknown>, E = EventEmitterLike> {
75
+ state: S;
76
+ private _workflowControl?;
77
+ abstract eventEmitter: WorkflowEventEmitterLike<E>;
78
+ /**
79
+ * Sets up the context and copies any initial state onto the instance.
80
+ *
81
+ * @param initialState - Optional properties to assign to the context instance.
82
+ * @param eventEmitter - Optional workflow event emitter to expose to actions.
83
+ */
84
+ constructor(initialState: S);
85
+ /**
86
+ * Snapshot the context state for telemetry or UI rendering.
87
+ * Override to filter or reshape the exposed state.
88
+ */
89
+ snapshot(): Record<string, unknown>;
90
+ /**
91
+ * Provides access to the workflow runtime API for the current execution.
92
+ *
93
+ * @returns Runtime control methods that allow suspension and inspection.
94
+ * @throws Error when the context is not currently attached to a runner.
95
+ */
96
+ get workflow(): WorkflowRuntimeControl;
97
+ /**
98
+ * Attaches or detaches the runtime control object.
99
+ *
100
+ * @param control - Runtime control instance or `undefined` to detach.
101
+ * @returns Nothing; the method mutates internal state.
102
+ */
103
+ attachWorkflowRuntime(control: WorkflowRuntimeControl | undefined): void;
104
+ }
105
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,gBAAgB,EAChB,wBAAwB,EACzB,MAAM,0BAA0B,CAAC;AAElC;;;;;;;GAOG;AACH,MAAM,MAAM,iBAAiB,GACzB,MAAM,GACN,SAAS,GACT,WAAW,GACX,UAAU,GACV,QAAQ,CAAC;AAEb;;;;;;;;GAQG;AACH,MAAM,MAAM,YAAY,GACpB,SAAS,GACT,SAAS,GACT,WAAW,GACX,WAAW,GACX,QAAQ,GACR,SAAS,CAAC;AAEd,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,YAAY,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,mBAAmB,GAAG;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,YAAY,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE;QACR,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACjC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACjC,CAAC;IACF,KAAK,CAAC,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