@mastra/core 0.1.27-alpha.26 → 0.1.27-alpha.27

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.
@@ -3671,7 +3671,7 @@ function isTransitionEvent(stateEvent) {
3671
3671
  return stateEvent.type.startsWith('xstate.done.actor.');
3672
3672
  }
3673
3673
  function isVariableReference(value) {
3674
- return typeof value === 'object' && 'stepId' in value && 'path' in value;
3674
+ return typeof value === 'object' && 'step' in value && 'path' in value;
3675
3675
  }
3676
3676
  function getStepResult(result) {
3677
3677
  if ((result == null ? void 0 : result.status) === 'success') return result.payload;
@@ -3680,8 +3680,6 @@ function getStepResult(result) {
3680
3680
 
3681
3681
  var _logger = /*#__PURE__*/_classPrivateFieldLooseKey("logger");
3682
3682
  var _triggerSchema = /*#__PURE__*/_classPrivateFieldLooseKey("triggerSchema");
3683
- var _steps = /*#__PURE__*/_classPrivateFieldLooseKey("steps");
3684
- var _stepConfiguration = /*#__PURE__*/_classPrivateFieldLooseKey("stepConfiguration");
3685
3683
  var _machine = /*#__PURE__*/_classPrivateFieldLooseKey("machine");
3686
3684
  var _actor = /*#__PURE__*/_classPrivateFieldLooseKey("actor");
3687
3685
  var _runId = /*#__PURE__*/_classPrivateFieldLooseKey("runId");
@@ -3690,6 +3688,12 @@ var _engine = /*#__PURE__*/_classPrivateFieldLooseKey("engine");
3690
3688
  var _connectionId = /*#__PURE__*/_classPrivateFieldLooseKey("connectionId");
3691
3689
  var _entityName = /*#__PURE__*/_classPrivateFieldLooseKey("entityName");
3692
3690
  var _telemetry = /*#__PURE__*/_classPrivateFieldLooseKey("telemetry");
3691
+ var _lastStepStack = /*#__PURE__*/_classPrivateFieldLooseKey("lastStepStack");
3692
+ var _stepGraph = /*#__PURE__*/_classPrivateFieldLooseKey("stepGraph");
3693
+ var _steps = /*#__PURE__*/_classPrivateFieldLooseKey("steps");
3694
+ var _recursivelyCheckForFinalState = /*#__PURE__*/_classPrivateFieldLooseKey("recursivelyCheckForFinalState");
3695
+ var _buildBaseState = /*#__PURE__*/_classPrivateFieldLooseKey("buildBaseState");
3696
+ var _makeStepKey = /*#__PURE__*/_classPrivateFieldLooseKey("makeStepKey");
3693
3697
  var _buildStateHierarchy = /*#__PURE__*/_classPrivateFieldLooseKey("buildStateHierarchy");
3694
3698
  var _persistWorkflowSnapshot = /*#__PURE__*/_classPrivateFieldLooseKey("persistWorkflowSnapshot");
3695
3699
  var _loadWorkflowSnapshot = /*#__PURE__*/_classPrivateFieldLooseKey("loadWorkflowSnapshot");
@@ -3706,9 +3710,7 @@ var Workflow = /*#__PURE__*/function () {
3706
3710
  * @param logger - Optional logger instance
3707
3711
  */
3708
3712
  function Workflow(_ref) {
3709
- var _this = this;
3710
3713
  var name = _ref.name,
3711
- steps = _ref.steps,
3712
3714
  logger = _ref.logger,
3713
3715
  engine = _ref.engine,
3714
3716
  triggerSchema = _ref.triggerSchema,
@@ -3771,6 +3773,15 @@ var Workflow = /*#__PURE__*/function () {
3771
3773
  Object.defineProperty(this, _buildStateHierarchy, {
3772
3774
  value: _buildStateHierarchy2
3773
3775
  });
3776
+ Object.defineProperty(this, _makeStepKey, {
3777
+ value: _makeStepKey2
3778
+ });
3779
+ Object.defineProperty(this, _buildBaseState, {
3780
+ value: _buildBaseState2
3781
+ });
3782
+ Object.defineProperty(this, _recursivelyCheckForFinalState, {
3783
+ value: _recursivelyCheckForFinalState2
3784
+ });
3774
3785
  this.name = void 0;
3775
3786
  Object.defineProperty(this, _logger, {
3776
3787
  writable: true,
@@ -3780,14 +3791,6 @@ var Workflow = /*#__PURE__*/function () {
3780
3791
  writable: true,
3781
3792
  value: void 0
3782
3793
  });
3783
- Object.defineProperty(this, _steps, {
3784
- writable: true,
3785
- value: void 0
3786
- });
3787
- Object.defineProperty(this, _stepConfiguration, {
3788
- writable: true,
3789
- value: {}
3790
- });
3791
3794
  /** XState machine instance that orchestrates the workflow execution */
3792
3795
  Object.defineProperty(this, _machine, {
3793
3796
  writable: true,
@@ -3822,9 +3825,25 @@ var Workflow = /*#__PURE__*/function () {
3822
3825
  writable: true,
3823
3826
  value: void 0
3824
3827
  });
3828
+ // registers stepIds on `after` calls
3829
+ // #afterStepStack: string[] = [];
3830
+ Object.defineProperty(this, _lastStepStack, {
3831
+ writable: true,
3832
+ value: []
3833
+ });
3834
+ Object.defineProperty(this, _stepGraph, {
3835
+ writable: true,
3836
+ value: {
3837
+ initial: []
3838
+ }
3839
+ });
3840
+ // #delimiter = '-([-]::[-])-';
3841
+ Object.defineProperty(this, _steps, {
3842
+ writable: true,
3843
+ value: {}
3844
+ });
3825
3845
  this.name = name;
3826
3846
  _classPrivateFieldLooseBase(this, _logger)[_logger] = logger;
3827
- _classPrivateFieldLooseBase(this, _steps)[_steps] = steps;
3828
3847
  _classPrivateFieldLooseBase(this, _retryConfig)[_retryConfig] = retryConfig || {
3829
3848
  attempts: 3,
3830
3849
  delay: 1000
@@ -3834,10 +3853,6 @@ var Workflow = /*#__PURE__*/function () {
3834
3853
  _classPrivateFieldLooseBase(this, _telemetry)[_telemetry] = telemetry;
3835
3854
  _classPrivateFieldLooseBase(this, _engine)[_engine] = engine;
3836
3855
  this.initializeMachine();
3837
- // Initialize step definitions
3838
- steps.forEach(function (step) {
3839
- _classPrivateFieldLooseBase(_this, _stepConfiguration)[_stepConfiguration][step.id] = _extends({}, _classPrivateFieldLooseBase(_this, _makeStepDef)[_makeStepDef](step.id));
3840
- });
3841
3856
  }
3842
3857
  /**
3843
3858
  * Initializes the XState machine for the workflow
@@ -3847,7 +3862,7 @@ var Workflow = /*#__PURE__*/function () {
3847
3862
  */
3848
3863
  var _proto = Workflow.prototype;
3849
3864
  _proto.initializeMachine = function initializeMachine() {
3850
- var _this2 = this;
3865
+ var _this = this;
3851
3866
  var machine = xstate.setup({
3852
3867
  types: {},
3853
3868
  delays: _classPrivateFieldLooseBase(this, _makeDelayMap)[_makeDelayMap](),
@@ -3883,7 +3898,7 @@ var Workflow = /*#__PURE__*/function () {
3883
3898
  }),
3884
3899
  notifyStepCompletion: function notifyStepCompletion(_, params) {
3885
3900
  var stepId = params.stepId;
3886
- _classPrivateFieldLooseBase(_this2, _log)[_log](LogLevel.INFO, "Step " + stepId + " completed");
3901
+ _classPrivateFieldLooseBase(_this, _log)[_log](LogLevel.INFO, "Step " + stepId + " completed");
3887
3902
  },
3888
3903
  decrementAttemptCount: xstate.assign({
3889
3904
  attempts: function attempts(_ref4, params) {
@@ -3901,25 +3916,27 @@ var Workflow = /*#__PURE__*/function () {
3901
3916
  actors: {
3902
3917
  resolverFunction: xstate.fromPromise(/*#__PURE__*/function () {
3903
3918
  var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref5) {
3904
- var input, step, context, stepId, resolvedData, result;
3919
+ var input, stepNode, context, resolvedData, result;
3905
3920
  return _regeneratorRuntime().wrap(function _callee$(_context) {
3906
3921
  while (1) switch (_context.prev = _context.next) {
3907
3922
  case 0:
3908
3923
  input = _ref5.input;
3909
- step = input.step, context = input.context, stepId = input.stepId;
3910
- resolvedData = _classPrivateFieldLooseBase(_this2, _resolveVariables)[_resolveVariables]({
3911
- stepConfig: step,
3924
+ stepNode = input.stepNode, context = input.context;
3925
+ resolvedData = _classPrivateFieldLooseBase(_this, _resolveVariables)[_resolveVariables]({
3926
+ stepConfig: stepNode.config,
3912
3927
  context: context
3913
3928
  });
3914
3929
  _context.next = 5;
3915
- return step == null ? void 0 : step.handler({
3916
- data: resolvedData,
3917
- runId: _classPrivateFieldLooseBase(_this2, _runId)[_runId]
3930
+ return stepNode.config.handler({
3931
+ context: _extends({
3932
+ stepResults: context.stepResults
3933
+ }, resolvedData),
3934
+ runId: _classPrivateFieldLooseBase(_this, _runId)[_runId]
3918
3935
  });
3919
3936
  case 5:
3920
3937
  result = _context.sent;
3921
3938
  return _context.abrupt("return", {
3922
- stepId: stepId,
3939
+ stepId: stepNode.step.id,
3923
3940
  result: result
3924
3941
  });
3925
3942
  case 7:
@@ -3934,14 +3951,14 @@ var Workflow = /*#__PURE__*/function () {
3934
3951
  }()),
3935
3952
  dependencyCheck: xstate.fromPromise(/*#__PURE__*/function () {
3936
3953
  var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref7) {
3937
- var input, context, stepId, stepConfig, attemptCount, missingDeps, suspendedDeps, failedDeps, conditionMet, _conditionMet;
3954
+ var input, context, stepNode, stepConfig, attemptCount, conditionMet, _conditionMet;
3938
3955
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
3939
3956
  while (1) switch (_context2.prev = _context2.next) {
3940
3957
  case 0:
3941
3958
  input = _ref7.input;
3942
- context = input.context, stepId = input.stepId;
3943
- stepConfig = _classPrivateFieldLooseBase(_this2, _stepConfiguration)[_stepConfiguration][stepId];
3944
- attemptCount = context.attempts[stepId];
3959
+ context = input.context, stepNode = input.stepNode;
3960
+ stepConfig = stepNode.config; // TODO: Need a way to create unique ids for steps
3961
+ attemptCount = context.attempts[stepNode.step.id];
3945
3962
  if (!(!attemptCount || attemptCount < 0)) {
3946
3963
  _context2.next = 8;
3947
3964
  break;
@@ -3952,90 +3969,58 @@ var Workflow = /*#__PURE__*/function () {
3952
3969
  }
3953
3970
  return _context2.abrupt("return", {
3954
3971
  type: 'SUSPENDED',
3955
- stepId: stepId
3972
+ stepId: stepNode.step.id
3956
3973
  });
3957
3974
  case 7:
3958
3975
  return _context2.abrupt("return", {
3959
3976
  type: 'TIMED_OUT',
3960
- error: "Step:" + stepId + " timed out"
3977
+ error: "Step:" + stepNode.step.id + " timed out"
3961
3978
  });
3962
3979
  case 8:
3963
- // Check dependencies are present and valid
3964
- missingDeps = stepConfig == null ? void 0 : stepConfig.dependsOn.filter(function (depId) {
3965
- return !(depId in context.stepResults);
3966
- });
3967
- suspendedDeps = stepConfig == null ? void 0 : stepConfig.dependsOn.filter(function (depId) {
3968
- var _context$stepResults$;
3969
- return ((_context$stepResults$ = context.stepResults[depId]) == null ? void 0 : _context$stepResults$.status) === 'suspended';
3970
- });
3971
- if (!(suspendedDeps != null && suspendedDeps.length && suspendedDeps.length > 0)) {
3972
- _context2.next = 12;
3980
+ if (stepConfig != null && stepConfig.when) {
3981
+ _context2.next = 10;
3973
3982
  break;
3974
3983
  }
3975
3984
  return _context2.abrupt("return", {
3976
- type: 'SUSPENDED',
3977
- stepId: stepId,
3978
- missingDeps: suspendedDeps
3979
- });
3980
- case 12:
3981
- if (!(missingDeps != null && missingDeps.length && missingDeps.length > 0)) {
3982
- _context2.next = 14;
3983
- break;
3984
- }
3985
- return _context2.abrupt("return", {
3986
- type: 'DEPENDENCIES_NOT_MET'
3987
- });
3988
- case 14:
3989
- failedDeps = stepConfig == null ? void 0 : stepConfig.dependsOn.filter(function (depId) {
3990
- var _context$stepResults$2, _context$stepResults$3;
3991
- return ((_context$stepResults$2 = context.stepResults[depId]) == null ? void 0 : _context$stepResults$2.status) === 'failed' || ((_context$stepResults$3 = context.stepResults[depId]) == null ? void 0 : _context$stepResults$3.status) === 'skipped';
3985
+ type: 'DEPENDENCIES_MET'
3992
3986
  });
3993
- if (!(failedDeps != null && failedDeps.length && failedDeps.length > 0)) {
3994
- _context2.next = 17;
3987
+ case 10:
3988
+ if (!(typeof (stepConfig == null ? void 0 : stepConfig.when) === 'function')) {
3989
+ _context2.next = 18;
3995
3990
  break;
3996
3991
  }
3997
- return _context2.abrupt("return", {
3998
- type: 'SKIP_STEP',
3999
- missingDeps: failedDeps
3992
+ _context2.next = 13;
3993
+ return stepConfig.when({
3994
+ context: context
4000
3995
  });
4001
- case 17:
4002
- if (!(stepConfig != null && stepConfig.condition)) {
4003
- _context2.next = 21;
4004
- break;
4005
- }
4006
- conditionMet = _classPrivateFieldLooseBase(_this2, _evaluateCondition)[_evaluateCondition](stepConfig.condition, context);
3996
+ case 13:
3997
+ conditionMet = _context2.sent;
4007
3998
  if (conditionMet) {
4008
- _context2.next = 21;
3999
+ _context2.next = 16;
4009
4000
  break;
4010
4001
  }
4011
4002
  return _context2.abrupt("return", {
4012
4003
  type: 'CONDITION_FAILED',
4013
- error: "Step:" + stepId + " condition check failed"
4014
- });
4015
- case 21:
4016
- if (!(stepConfig != null && stepConfig.conditionFn)) {
4017
- _context2.next = 27;
4018
- break;
4019
- }
4020
- _context2.next = 24;
4021
- return stepConfig.conditionFn({
4022
- context: context
4004
+ error: "Step:" + stepNode.step.id + " condition function check failed"
4023
4005
  });
4024
- case 24:
4025
- _conditionMet = _context2.sent;
4006
+ case 16:
4007
+ _context2.next = 21;
4008
+ break;
4009
+ case 18:
4010
+ _conditionMet = _classPrivateFieldLooseBase(_this, _evaluateCondition)[_evaluateCondition](stepConfig.when, context);
4026
4011
  if (_conditionMet) {
4027
- _context2.next = 27;
4012
+ _context2.next = 21;
4028
4013
  break;
4029
4014
  }
4030
4015
  return _context2.abrupt("return", {
4031
4016
  type: 'CONDITION_FAILED',
4032
- error: "Step:" + stepId + " condition function check failed"
4017
+ error: "Step:" + stepNode.step.id + " condition check failed"
4033
4018
  });
4034
- case 27:
4019
+ case 21:
4035
4020
  return _context2.abrupt("return", {
4036
4021
  type: 'DEPENDENCIES_MET'
4037
4022
  });
4038
- case 28:
4023
+ case 22:
4039
4024
  case "end":
4040
4025
  return _context2.stop();
4041
4026
  }
@@ -4057,19 +4042,11 @@ var Workflow = /*#__PURE__*/function () {
4057
4042
  });
4058
4043
  _classPrivateFieldLooseBase(this, _machine)[_machine] = machine;
4059
4044
  return machine;
4060
- }
4061
- /**
4062
- * Configures a step in the workflow
4063
- * @param id - Unique identifier for the step
4064
- * @param config - Step configuration including handler, schema, variables, and payload
4065
- * @returns this instance for method chaining
4066
- */;
4067
- _proto.config = function config(id, _config) {
4068
- var _config$variables = _config.variables,
4069
- variables = _config$variables === void 0 ? {} : _config$variables,
4070
- dependsOn = _config.dependsOn,
4071
- condition = _config.condition,
4072
- conditionFn = _config.conditionFn;
4045
+ };
4046
+ _proto.step = function step(_step, config) {
4047
+ var _ref10 = config || {},
4048
+ _ref10$variables = _ref10.variables,
4049
+ variables = _ref10$variables === void 0 ? {} : _ref10$variables;
4073
4050
  var requiredData = {};
4074
4051
  // Add valid variables to requiredData
4075
4052
  for (var _i = 0, _Object$entries = Object.entries(variables); _i < _Object$entries.length; _i++) {
@@ -4080,12 +4057,48 @@ var Workflow = /*#__PURE__*/function () {
4080
4057
  requiredData[key] = variable;
4081
4058
  }
4082
4059
  }
4083
- _classPrivateFieldLooseBase(this, _stepConfiguration)[_stepConfiguration][id] = _extends({}, _classPrivateFieldLooseBase(this, _makeStepDef)[_makeStepDef](id), {
4084
- dependsOn: dependsOn,
4085
- condition: condition,
4086
- conditionFn: conditionFn,
4087
- data: requiredData
4088
- });
4060
+ var stepKey = _classPrivateFieldLooseBase(this, _makeStepKey)[_makeStepKey](_step);
4061
+ var graphEntry = {
4062
+ step: _step,
4063
+ config: _extends({}, _classPrivateFieldLooseBase(this, _makeStepDef)[_makeStepDef](stepKey), config, {
4064
+ data: requiredData
4065
+ })
4066
+ };
4067
+ _classPrivateFieldLooseBase(this, _steps)[_steps][stepKey] = _step;
4068
+ if (!_classPrivateFieldLooseBase(this, _stepGraph)[_stepGraph][stepKey]) _classPrivateFieldLooseBase(this, _stepGraph)[_stepGraph][stepKey] = [];
4069
+ _classPrivateFieldLooseBase(this, _stepGraph)[_stepGraph].initial.push(graphEntry);
4070
+ _classPrivateFieldLooseBase(this, _lastStepStack)[_lastStepStack].push(stepKey);
4071
+ return this;
4072
+ };
4073
+ _proto.then = function then(step, config) {
4074
+ var _ref11 = config || {},
4075
+ _ref11$variables = _ref11.variables,
4076
+ variables = _ref11$variables === void 0 ? {} : _ref11$variables;
4077
+ var requiredData = {};
4078
+ // Add valid variables to requiredData
4079
+ for (var _i2 = 0, _Object$entries2 = Object.entries(variables); _i2 < _Object$entries2.length; _i2++) {
4080
+ var _Object$entries2$_i = _Object$entries2[_i2],
4081
+ key = _Object$entries2$_i[0],
4082
+ variable = _Object$entries2$_i[1];
4083
+ if (variable && isVariableReference(variable)) {
4084
+ requiredData[key] = variable;
4085
+ }
4086
+ }
4087
+ var lastStepKey = _classPrivateFieldLooseBase(this, _lastStepStack)[_lastStepStack][_classPrivateFieldLooseBase(this, _lastStepStack)[_lastStepStack].length - 1];
4088
+ var stepKey = _classPrivateFieldLooseBase(this, _makeStepKey)[_makeStepKey](step);
4089
+ var graphEntry = {
4090
+ step: step,
4091
+ config: _extends({}, _classPrivateFieldLooseBase(this, _makeStepDef)[_makeStepDef](stepKey), config, {
4092
+ data: requiredData
4093
+ })
4094
+ };
4095
+ _classPrivateFieldLooseBase(this, _steps)[_steps][stepKey] = step;
4096
+ // if then is called without a step, we are done
4097
+ if (!lastStepKey) return this;
4098
+ // add the step to the graph if not already there.. it should be there though, unless magic
4099
+ if (!_classPrivateFieldLooseBase(this, _stepGraph)[_stepGraph][lastStepKey]) _classPrivateFieldLooseBase(this, _stepGraph)[_stepGraph][lastStepKey] = [];
4100
+ // add the step to the graph
4101
+ _classPrivateFieldLooseBase(this, _stepGraph)[_stepGraph][lastStepKey].push(graphEntry);
4089
4102
  return this;
4090
4103
  }
4091
4104
  /**
@@ -4098,12 +4111,12 @@ var Workflow = /*#__PURE__*/function () {
4098
4111
  /*#__PURE__*/
4099
4112
  function () {
4100
4113
  var _execute = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_temp) {
4101
- var _this3 = this;
4102
- var _ref10, triggerData, loadSnapshot, snapshot;
4114
+ var _this2 = this;
4115
+ var _ref12, triggerData, loadSnapshot, snapshot;
4103
4116
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
4104
4117
  while (1) switch (_context3.prev = _context3.next) {
4105
4118
  case 0:
4106
- _ref10 = _temp === void 0 ? {} : _temp, triggerData = _ref10.triggerData, loadSnapshot = _ref10.loadSnapshot;
4119
+ _ref12 = _temp === void 0 ? {} : _temp, triggerData = _ref12.triggerData, loadSnapshot = _ref12.loadSnapshot;
4107
4120
  if (!(loadSnapshot && loadSnapshot.runId)) {
4108
4121
  _context3.next = 7;
4109
4122
  break;
@@ -4150,9 +4163,9 @@ var Workflow = /*#__PURE__*/function () {
4150
4163
  input: {
4151
4164
  stepResults: {},
4152
4165
  triggerData: triggerData || {},
4153
- attempts: _classPrivateFieldLooseBase(this, _steps)[_steps].reduce(function (acc, step) {
4154
- var _step$retryConfig, _classPrivateFieldLoo;
4155
- acc[step.id] = ((_step$retryConfig = step.retryConfig) == null ? void 0 : _step$retryConfig.attempts) || ((_classPrivateFieldLoo = _classPrivateFieldLooseBase(_this3, _retryConfig)[_retryConfig]) == null ? void 0 : _classPrivateFieldLoo.attempts) || 3;
4166
+ attempts: Object.keys(_classPrivateFieldLooseBase(this, _steps)[_steps]).reduce(function (acc, stepKey) {
4167
+ var _classPrivateFieldLoo, _classPrivateFieldLoo2;
4168
+ acc[stepKey] = ((_classPrivateFieldLoo = _classPrivateFieldLooseBase(_this2, _steps)[_steps][stepKey]) == null || (_classPrivateFieldLoo = _classPrivateFieldLoo.retryConfig) == null ? void 0 : _classPrivateFieldLoo.attempts) || ((_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(_this2, _retryConfig)[_retryConfig]) == null ? void 0 : _classPrivateFieldLoo2.attempts) || 3;
4156
4169
  return acc;
4157
4170
  }, {})
4158
4171
  },
@@ -4160,16 +4173,14 @@ var Workflow = /*#__PURE__*/function () {
4160
4173
  });
4161
4174
  _classPrivateFieldLooseBase(this, _actor)[_actor].start();
4162
4175
  return _context3.abrupt("return", new Promise(function (resolve, reject) {
4163
- if (!_classPrivateFieldLooseBase(_this3, _actor)[_actor]) {
4176
+ if (!_classPrivateFieldLooseBase(_this2, _actor)[_actor]) {
4164
4177
  reject(new Error('Actor not initialized'));
4165
4178
  return;
4166
4179
  }
4167
- _classPrivateFieldLooseBase(_this3, _actor)[_actor].subscribe(function (state) {
4180
+ _classPrivateFieldLooseBase(_this2, _actor)[_actor].subscribe(function (state) {
4168
4181
  // Check if all parallel states are in a final state
4169
4182
  var allStatesValue = state.value;
4170
- var allStatesComplete = Object.values(allStatesValue).every(function (value) {
4171
- return ['completed', 'failed', 'skipped', 'suspended'].includes(value);
4172
- });
4183
+ var allStatesComplete = _classPrivateFieldLooseBase(_this2, _recursivelyCheckForFinalState)[_recursivelyCheckForFinalState](allStatesValue);
4173
4184
  if (allStatesComplete) {
4174
4185
  // Check if any steps failed
4175
4186
  var hasFailures = Object.values(state.context.stepResults).some(function (result) {
@@ -4179,27 +4190,27 @@ var Workflow = /*#__PURE__*/function () {
4179
4190
  return result.status === 'suspended';
4180
4191
  });
4181
4192
  if (hasSuspended) {
4182
- _classPrivateFieldLooseBase(_this3, _persistWorkflowSnapshot)[_persistWorkflowSnapshot]();
4193
+ _classPrivateFieldLooseBase(_this2, _persistWorkflowSnapshot)[_persistWorkflowSnapshot]();
4183
4194
  }
4184
4195
  if (hasFailures) {
4185
- _classPrivateFieldLooseBase(_this3, _log)[_log](LogLevel.ERROR, 'Workflow failed', {
4196
+ _classPrivateFieldLooseBase(_this2, _log)[_log](LogLevel.ERROR, 'Workflow failed', {
4186
4197
  results: state.context.stepResults
4187
4198
  });
4188
- _classPrivateFieldLooseBase(_this3, _cleanup)[_cleanup]();
4199
+ _classPrivateFieldLooseBase(_this2, _cleanup)[_cleanup]();
4189
4200
  resolve({
4190
4201
  triggerData: triggerData,
4191
4202
  results: state.context.stepResults,
4192
- runId: _classPrivateFieldLooseBase(_this3, _runId)[_runId]
4203
+ runId: _classPrivateFieldLooseBase(_this2, _runId)[_runId]
4193
4204
  });
4194
4205
  } else {
4195
- _classPrivateFieldLooseBase(_this3, _log)[_log](LogLevel.INFO, 'Workflow completed', {
4206
+ _classPrivateFieldLooseBase(_this2, _log)[_log](LogLevel.INFO, 'Workflow completed', {
4196
4207
  results: state.context.stepResults
4197
4208
  });
4198
- _classPrivateFieldLooseBase(_this3, _cleanup)[_cleanup]();
4209
+ _classPrivateFieldLooseBase(_this2, _cleanup)[_cleanup]();
4199
4210
  resolve({
4200
4211
  triggerData: triggerData,
4201
4212
  results: state.context.stepResults,
4202
- runId: _classPrivateFieldLooseBase(_this3, _runId)[_runId]
4213
+ runId: _classPrivateFieldLooseBase(_this2, _runId)[_runId]
4203
4214
  });
4204
4215
  }
4205
4216
  }
@@ -4239,204 +4250,219 @@ var Workflow = /*#__PURE__*/function () {
4239
4250
  _proto.__registerTelemetry = function __registerTelemetry(telemetry) {
4240
4251
  _classPrivateFieldLooseBase(this, _telemetry)[_telemetry] = telemetry;
4241
4252
  };
4242
- return Workflow;
4253
+ return _createClass(Workflow, [{
4254
+ key: "stepGraph",
4255
+ get: function get() {
4256
+ return _classPrivateFieldLooseBase(this, _stepGraph)[_stepGraph];
4257
+ }
4258
+ }]);
4243
4259
  }();
4244
- function _buildStateHierarchy2() {
4245
- var _this4 = this;
4246
- var states = {};
4247
- _classPrivateFieldLooseBase(this, _steps)[_steps].forEach(function (step) {
4248
- var _after;
4249
- states[step.id] = {
4250
- initial: 'pending',
4251
- states: {
4252
- pending: {
4253
- invoke: {
4254
- src: 'dependencyCheck',
4255
- input: function input(_ref11) {
4256
- var context = _ref11.context;
4257
- return {
4258
- context: context,
4259
- stepId: step.id
4260
- };
4260
+ function _recursivelyCheckForFinalState2(value) {
4261
+ var _this3 = this;
4262
+ if (typeof value === 'string') {
4263
+ return ['completed', 'failed', 'suspended'].includes(value);
4264
+ }
4265
+ return Object.values(value).every(function (val) {
4266
+ return _classPrivateFieldLooseBase(_this3, _recursivelyCheckForFinalState)[_recursivelyCheckForFinalState](val);
4267
+ });
4268
+ }
4269
+ function _buildBaseState2(stepNode, nextSteps) {
4270
+ var _this4 = this,
4271
+ _after,
4272
+ _ref25;
4273
+ if (nextSteps === void 0) {
4274
+ nextSteps = [];
4275
+ }
4276
+ // NOTE: THIS CLEARS THE STEPGRAPH :: no concequences for now
4277
+ var nextStep = nextSteps.shift();
4278
+ return {
4279
+ initial: 'pending',
4280
+ entry: function entry(_ref13) {
4281
+ var context = _ref13.context;
4282
+ console.log({
4283
+ stepNode: stepNode,
4284
+ context: context
4285
+ }, 'entry pending =============================');
4286
+ },
4287
+ exit: function exit(_ref14) {
4288
+ var context = _ref14.context;
4289
+ console.log({
4290
+ stepNode: stepNode,
4291
+ context: context
4292
+ }, 'exit pending =============================');
4293
+ },
4294
+ states: _extends({
4295
+ pending: {
4296
+ invoke: {
4297
+ src: 'dependencyCheck',
4298
+ input: function input(_ref15) {
4299
+ var context = _ref15.context;
4300
+ return {
4301
+ context: context,
4302
+ stepNode: stepNode
4303
+ };
4304
+ },
4305
+ onDone: [{
4306
+ guard: function guard(_ref16) {
4307
+ var event = _ref16.event;
4308
+ return event.output.type === 'SUSPENDED';
4261
4309
  },
4262
- onDone: [{
4263
- guard: function guard(_ref12) {
4264
- var event = _ref12.event;
4265
- return event.output.type === 'SUSPENDED';
4266
- },
4267
- target: 'suspended',
4268
- actions: xstate.assign({
4269
- stepResults: function stepResults(_ref13) {
4270
- var _extends5;
4271
- var context = _ref13.context,
4272
- event = _ref13.event;
4273
- if (event.output.type !== 'SUSPENDED') return context.stepResults;
4274
- return _extends({}, context.stepResults, (_extends5 = {}, _extends5[step.id] = {
4275
- status: 'suspended'
4276
- }, _extends5));
4277
- }
4278
- })
4279
- }, {
4280
- guard: function guard(_ref14) {
4281
- var event = _ref14.event;
4282
- return event.output.type === 'DEPENDENCIES_MET';
4283
- },
4284
- target: 'executing'
4285
- }, {
4286
- guard: function guard(_ref15) {
4287
- var event = _ref15.event;
4288
- return event.output.type === 'DEPENDENCIES_NOT_MET';
4289
- },
4290
- target: 'waiting',
4291
- actions: [{
4292
- type: 'decrementAttemptCount',
4293
- params: {
4294
- stepId: step.id
4295
- }
4296
- }]
4297
- }, {
4298
- guard: function guard(_ref16) {
4299
- var event = _ref16.event;
4300
- return event.output.type === 'SKIP_STEP';
4301
- },
4302
- target: 'skipped',
4303
- actions: xstate.assign({
4304
- stepResults: function stepResults(_ref17) {
4305
- var _extends6;
4306
- var context = _ref17.context,
4307
- event = _ref17.event;
4308
- if (event.output.type !== 'SKIP_STEP') return context.stepResults;
4309
- return _extends({}, context.stepResults, (_extends6 = {}, _extends6[step.id] = {
4310
- status: 'skipped',
4311
- missingDeps: event.output.missingDeps
4312
- }, _extends6));
4313
- }
4314
- })
4315
- }, {
4316
- guard: function guard(_ref18) {
4317
- var event = _ref18.event;
4318
- return event.output.type === 'TIMED_OUT';
4319
- },
4320
- target: 'failed',
4321
- actions: xstate.assign({
4322
- stepResults: function stepResults(_ref19) {
4323
- var _extends7;
4324
- var context = _ref19.context,
4325
- event = _ref19.event;
4326
- if (event.output.type !== 'TIMED_OUT') return context.stepResults;
4327
- _classPrivateFieldLooseBase(_this4, _log)[_log](LogLevel.ERROR, "Step:" + step.id + " timed out", {
4328
- error: event.output.error
4329
- });
4330
- return _extends({}, context.stepResults, (_extends7 = {}, _extends7[step.id] = {
4331
- status: 'failed',
4332
- error: event.output.error
4333
- }, _extends7));
4334
- }
4335
- })
4336
- }, {
4337
- guard: function guard(_ref20) {
4338
- var event = _ref20.event;
4339
- return event.output.type === 'CONDITION_FAILED';
4340
- },
4341
- target: 'failed',
4342
- actions: xstate.assign({
4343
- stepResults: function stepResults(_ref21) {
4344
- var _extends8;
4345
- var context = _ref21.context,
4346
- event = _ref21.event;
4347
- if (event.output.type !== 'CONDITION_FAILED') return context.stepResults;
4348
- _classPrivateFieldLooseBase(_this4, _log)[_log](LogLevel.ERROR, "workflow condition check failed", {
4349
- error: event.output.error,
4350
- stepId: step.id
4351
- });
4352
- return _extends({}, context.stepResults, (_extends8 = {}, _extends8[step.id] = {
4353
- status: 'failed',
4354
- error: event.output.error
4355
- }, _extends8));
4356
- }
4357
- })
4310
+ target: 'suspended',
4311
+ actions: xstate.assign({
4312
+ stepResults: function stepResults(_ref17) {
4313
+ var _extends5;
4314
+ var context = _ref17.context,
4315
+ event = _ref17.event;
4316
+ if (event.output.type !== 'SUSPENDED') return context.stepResults;
4317
+ return _extends({}, context.stepResults, (_extends5 = {}, _extends5[stepNode.step.id] = {
4318
+ status: 'suspended'
4319
+ }, _extends5));
4320
+ }
4321
+ })
4322
+ }, {
4323
+ guard: function guard(_ref18) {
4324
+ var event = _ref18.event;
4325
+ return event.output.type === 'DEPENDENCIES_MET';
4326
+ },
4327
+ target: 'executing'
4328
+ }, {
4329
+ guard: function guard(_ref19) {
4330
+ var event = _ref19.event;
4331
+ return event.output.type === 'DEPENDENCIES_NOT_MET';
4332
+ },
4333
+ target: 'waiting',
4334
+ actions: [{
4335
+ type: 'decrementAttemptCount',
4336
+ params: {
4337
+ stepId: stepNode.step.id
4338
+ }
4358
4339
  }]
4359
- }
4360
- },
4361
- waiting: {
4362
- entry: function entry() {
4363
- _classPrivateFieldLooseBase(_this4, _log)[_log](LogLevel.INFO, "Step " + step.id + " waiting " + new Date().toISOString());
4364
- },
4365
- exit: function exit() {
4366
- _classPrivateFieldLooseBase(_this4, _log)[_log](LogLevel.INFO, "Step " + step.id + " finished waiting " + new Date().toISOString());
4367
- },
4368
- after: (_after = {}, _after[step.id] = {
4369
- target: 'pending'
4370
- }, _after)
4371
- },
4372
- executing: {
4373
- invoke: {
4374
- src: 'resolverFunction',
4375
- input: function input(_ref22) {
4376
- var context = _ref22.context;
4377
- return {
4378
- context: context,
4379
- stepId: step.id,
4380
- step: _classPrivateFieldLooseBase(_this4, _stepConfiguration)[_stepConfiguration][step.id]
4381
- };
4340
+ }, {
4341
+ guard: function guard(_ref20) {
4342
+ var event = _ref20.event;
4343
+ return event.output.type === 'TIMED_OUT';
4382
4344
  },
4383
- onDone: {
4384
- target: 'completed',
4385
- actions: [{
4386
- type: 'updateStepResult',
4387
- params: {
4388
- stepId: step.id
4389
- }
4390
- }]
4345
+ target: 'failed',
4346
+ actions: xstate.assign({
4347
+ stepResults: function stepResults(_ref21) {
4348
+ var _extends6;
4349
+ var context = _ref21.context,
4350
+ event = _ref21.event;
4351
+ if (event.output.type !== 'TIMED_OUT') return context.stepResults;
4352
+ _classPrivateFieldLooseBase(_this4, _log)[_log](LogLevel.ERROR, "Step:" + stepNode.step.id + " timed out", {
4353
+ error: event.output.error
4354
+ });
4355
+ return _extends({}, context.stepResults, (_extends6 = {}, _extends6[stepNode.step.id] = {
4356
+ status: 'failed',
4357
+ error: event.output.error
4358
+ }, _extends6));
4359
+ }
4360
+ })
4361
+ }, {
4362
+ guard: function guard(_ref22) {
4363
+ var event = _ref22.event;
4364
+ return event.output.type === 'CONDITION_FAILED';
4391
4365
  },
4392
- onError: {
4393
- target: 'failed',
4394
- actions: [{
4395
- type: 'setStepError',
4396
- params: {
4397
- stepId: step.id
4398
- }
4399
- }]
4400
- }
4401
- }
4402
- },
4403
- completed: {
4404
- type: 'final',
4405
- entry: [{
4406
- type: 'notifyStepCompletion',
4407
- params: {
4408
- stepId: step.id
4409
- }
4366
+ target: 'failed',
4367
+ actions: xstate.assign({
4368
+ stepResults: function stepResults(_ref23) {
4369
+ var _extends7;
4370
+ var context = _ref23.context,
4371
+ event = _ref23.event;
4372
+ if (event.output.type !== 'CONDITION_FAILED') return context.stepResults;
4373
+ _classPrivateFieldLooseBase(_this4, _log)[_log](LogLevel.ERROR, "workflow condition check failed", {
4374
+ error: event.output.error,
4375
+ stepId: stepNode.step.id
4376
+ });
4377
+ return _extends({}, context.stepResults, (_extends7 = {}, _extends7[stepNode.step.id] = {
4378
+ status: 'failed',
4379
+ error: event.output.error
4380
+ }, _extends7));
4381
+ }
4382
+ })
4410
4383
  }]
4384
+ }
4385
+ },
4386
+ waiting: {
4387
+ entry: function entry() {
4388
+ _classPrivateFieldLooseBase(_this4, _log)[_log](LogLevel.INFO, "Step " + stepNode.step.id + " waiting " + new Date().toISOString());
4411
4389
  },
4412
- failed: {
4413
- type: 'final',
4414
- entry: [{
4415
- type: 'notifyStepCompletion',
4416
- params: {
4417
- stepId: step.id
4418
- }
4419
- }]
4390
+ exit: function exit() {
4391
+ _classPrivateFieldLooseBase(_this4, _log)[_log](LogLevel.INFO, "Step " + stepNode.step.id + " finished waiting " + new Date().toISOString());
4420
4392
  },
4421
- skipped: {
4422
- type: 'final',
4423
- entry: [{
4424
- type: 'notifyStepCompletion',
4425
- params: {
4426
- stepId: step.id
4427
- }
4428
- }]
4429
- },
4430
- suspended: {
4431
- entry: [{
4432
- type: 'notifyStepCompletion',
4433
- params: {
4434
- stepId: step.id
4435
- }
4436
- }]
4393
+ after: (_after = {}, _after[stepNode.step.id] = {
4394
+ target: 'pending'
4395
+ }, _after)
4396
+ },
4397
+ executing: {
4398
+ invoke: {
4399
+ src: 'resolverFunction',
4400
+ input: function input(_ref24) {
4401
+ var context = _ref24.context;
4402
+ return {
4403
+ context: context,
4404
+ stepNode: stepNode
4405
+ };
4406
+ },
4407
+ onDone: {
4408
+ target: nextStep ? nextStep.step.id : 'completed',
4409
+ actions: [{
4410
+ type: 'updateStepResult',
4411
+ params: {
4412
+ stepId: stepNode.step.id
4413
+ }
4414
+ }]
4415
+ },
4416
+ onError: {
4417
+ target: 'failed',
4418
+ actions: [{
4419
+ type: 'setStepError',
4420
+ params: {
4421
+ stepId: stepNode.step.id
4422
+ }
4423
+ }]
4424
+ }
4437
4425
  }
4426
+ },
4427
+ completed: {
4428
+ type: 'final',
4429
+ entry: [{
4430
+ type: 'notifyStepCompletion',
4431
+ params: {
4432
+ stepId: stepNode.step.id
4433
+ }
4434
+ }]
4435
+ },
4436
+ failed: {
4437
+ type: 'final',
4438
+ entry: [{
4439
+ type: 'notifyStepCompletion',
4440
+ params: {
4441
+ stepId: stepNode.step.id
4442
+ }
4443
+ }]
4444
+ },
4445
+ suspended: {
4446
+ entry: [{
4447
+ type: 'notifyStepCompletion',
4448
+ params: {
4449
+ stepId: stepNode.step.id
4450
+ }
4451
+ }]
4438
4452
  }
4439
- };
4453
+ }, nextStep ? (_ref25 = {}, _ref25[nextStep.step.id] = _extends({}, _classPrivateFieldLooseBase(this, _buildBaseState)[_buildBaseState](nextStep, nextSteps)), _ref25) : {})
4454
+ };
4455
+ }
4456
+ function _makeStepKey2(step) {
4457
+ // return `${step.id}${this.#delimiter}${Object.keys(this.#steps2).length}`;
4458
+ return "" + step.id;
4459
+ }
4460
+ function _buildStateHierarchy2() {
4461
+ var _this5 = this;
4462
+ var states = {};
4463
+ _classPrivateFieldLooseBase(this, _stepGraph)[_stepGraph].initial.forEach(function (stepNode) {
4464
+ // TODO: For identical steps, use index to create unique key
4465
+ states[stepNode.step.id] = _extends({}, _classPrivateFieldLooseBase(_this5, _buildBaseState)[_buildBaseState](stepNode, _classPrivateFieldLooseBase(_this5, _stepGraph)[_stepGraph][stepNode.step.id]));
4440
4466
  });
4441
4467
  return states;
4442
4468
  }
@@ -4445,7 +4471,7 @@ function _persistWorkflowSnapshot2() {
4445
4471
  }
4446
4472
  function _persistWorkflowSnapshot3() {
4447
4473
  _persistWorkflowSnapshot3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
4448
- var _classPrivateFieldLoo3;
4474
+ var _classPrivateFieldLoo5;
4449
4475
  var snapshot;
4450
4476
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
4451
4477
  while (1) switch (_context5.prev = _context5.next) {
@@ -4456,7 +4482,7 @@ function _persistWorkflowSnapshot3() {
4456
4482
  }
4457
4483
  return _context5.abrupt("return");
4458
4484
  case 2:
4459
- snapshot = (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(this, _actor)[_actor]) == null ? void 0 : _classPrivateFieldLoo3.getPersistedSnapshot();
4485
+ snapshot = (_classPrivateFieldLoo5 = _classPrivateFieldLooseBase(this, _actor)[_actor]) == null ? void 0 : _classPrivateFieldLoo5.getPersistedSnapshot();
4460
4486
  if (snapshot) {
4461
4487
  _context5.next = 5;
4462
4488
  break;
@@ -4523,17 +4549,17 @@ function _loadWorkflowSnapshot3() {
4523
4549
  }));
4524
4550
  return _loadWorkflowSnapshot3.apply(this, arguments);
4525
4551
  }
4526
- function _resolveVariables2(_ref23) {
4527
- var stepConfig = _ref23.stepConfig,
4528
- context = _ref23.context;
4552
+ function _resolveVariables2(_ref26) {
4553
+ var stepConfig = _ref26.stepConfig,
4554
+ context = _ref26.context;
4529
4555
  var resolvedData = {};
4530
- for (var _i2 = 0, _Object$entries2 = Object.entries(stepConfig.data); _i2 < _Object$entries2.length; _i2++) {
4531
- var _Object$entries2$_i = _Object$entries2[_i2],
4532
- key = _Object$entries2$_i[0],
4533
- variable = _Object$entries2$_i[1];
4556
+ for (var _i3 = 0, _Object$entries3 = Object.entries(stepConfig.data); _i3 < _Object$entries3.length; _i3++) {
4557
+ var _Object$entries3$_i = _Object$entries3[_i3],
4558
+ key = _Object$entries3$_i[0],
4559
+ variable = _Object$entries3$_i[1];
4534
4560
  // Check if variable comes from trigger data or a previous step's result
4535
- var sourceData = variable.stepId === 'trigger' ? context.triggerData : getStepResult(context.stepResults[variable.stepId]);
4536
- if (!sourceData && variable.stepId !== 'trigger') {
4561
+ var sourceData = variable.step === 'trigger' ? context.triggerData : getStepResult(context.stepResults[variable.step.id]);
4562
+ if (!sourceData && variable.step !== 'trigger') {
4537
4563
  resolvedData[key] = undefined;
4538
4564
  continue;
4539
4565
  }
@@ -4544,7 +4570,7 @@ function _resolveVariables2(_ref23) {
4544
4570
  return resolvedData;
4545
4571
  }
4546
4572
  function _evaluateCondition2(condition, context) {
4547
- var _this5 = this;
4573
+ var _this6 = this;
4548
4574
  var andBranchResult = true;
4549
4575
  var baseResult = true;
4550
4576
  var orBranchResult = true;
@@ -4552,7 +4578,7 @@ function _evaluateCondition2(condition, context) {
4552
4578
  if ('ref' in condition) {
4553
4579
  var ref = condition.ref,
4554
4580
  query = condition.query;
4555
- var sourceData = ref.stepId === 'trigger' ? context.triggerData : getStepResult(context.stepResults[ref.stepId]);
4581
+ var sourceData = ref.step === 'trigger' ? context.triggerData : getStepResult(context.stepResults[ref.step.id]);
4556
4582
  if (!sourceData) {
4557
4583
  return false;
4558
4584
  }
@@ -4562,13 +4588,13 @@ function _evaluateCondition2(condition, context) {
4562
4588
  // AND condition
4563
4589
  if ('and' in condition) {
4564
4590
  andBranchResult = condition.and.every(function (cond) {
4565
- return _classPrivateFieldLooseBase(_this5, _evaluateCondition)[_evaluateCondition](cond, context);
4591
+ return _classPrivateFieldLooseBase(_this6, _evaluateCondition)[_evaluateCondition](cond, context);
4566
4592
  });
4567
4593
  }
4568
4594
  // OR condition
4569
4595
  if ('or' in condition) {
4570
4596
  orBranchResult = condition.or.some(function (cond) {
4571
- return _classPrivateFieldLooseBase(_this5, _evaluateCondition)[_evaluateCondition](cond, context);
4597
+ return _classPrivateFieldLooseBase(_this6, _evaluateCondition)[_evaluateCondition](cond, context);
4572
4598
  });
4573
4599
  }
4574
4600
  var finalResult = baseResult && andBranchResult && orBranchResult;
@@ -4579,7 +4605,7 @@ function _log2(_x5, _x6, _x7, _x8) {
4579
4605
  }
4580
4606
  function _log3() {
4581
4607
  _log3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(level, message, data, stepId) {
4582
- var _classPrivateFieldLoo4, _classPrivateFieldLoo5;
4608
+ var _classPrivateFieldLoo6, _classPrivateFieldLoo7;
4583
4609
  var logMessage, logMethod;
4584
4610
  return _regeneratorRuntime().wrap(function _callee7$(_context7) {
4585
4611
  while (1) switch (_context7.prev = _context7.next) {
@@ -4601,7 +4627,7 @@ function _log3() {
4601
4627
  };
4602
4628
  logMethod = level.toLowerCase();
4603
4629
  _context7.next = 6;
4604
- return (_classPrivateFieldLoo4 = (_classPrivateFieldLoo5 = _classPrivateFieldLooseBase(this, _logger)[_logger])[logMethod]) == null ? void 0 : _classPrivateFieldLoo4.call(_classPrivateFieldLoo5, logMessage);
4630
+ return (_classPrivateFieldLoo6 = (_classPrivateFieldLoo7 = _classPrivateFieldLooseBase(this, _logger)[_logger])[logMethod]) == null ? void 0 : _classPrivateFieldLoo6.call(_classPrivateFieldLoo7, logMessage);
4605
4631
  case 6:
4606
4632
  case "end":
4607
4633
  return _context7.stop();
@@ -4611,55 +4637,52 @@ function _log3() {
4611
4637
  return _log3.apply(this, arguments);
4612
4638
  }
4613
4639
  function _makeStepDef2(stepId) {
4614
- var _this6 = this;
4640
+ var _this7 = this;
4615
4641
  var handler = /*#__PURE__*/function () {
4616
- var _ref25 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref24) {
4617
- var data, runId, targetStep, inputSchema, payload, action, mergedData, validatedData, finalAction;
4642
+ var _ref28 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref27) {
4643
+ var context, runId, targetStep, payload, action, mergedData, finalAction;
4618
4644
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
4619
4645
  while (1) switch (_context4.prev = _context4.next) {
4620
4646
  case 0:
4621
- data = _ref24.data, runId = _ref24.runId;
4622
- targetStep = _classPrivateFieldLooseBase(_this6, _steps)[_steps].find(function (s) {
4623
- return s.id === stepId;
4624
- });
4647
+ context = _ref27.context, runId = _ref27.runId;
4648
+ targetStep = _classPrivateFieldLooseBase(_this7, _steps)[_steps][stepId];
4625
4649
  if (targetStep) {
4626
4650
  _context4.next = 4;
4627
4651
  break;
4628
4652
  }
4629
4653
  throw new Error("Step not found");
4630
4654
  case 4:
4631
- inputSchema = targetStep.inputSchema, payload = targetStep.payload, action = targetStep.action; // Merge static payload with dynamically resolved variables
4655
+ payload = targetStep.payload, action = targetStep.action; // Merge static payload with dynamically resolved variables
4632
4656
  // Variables take precedence over payload values
4633
- mergedData = _extends({}, payload, data); // Validate complete input data
4634
- validatedData = inputSchema ? inputSchema.parse(mergedData) : mergedData; // Only trace if telemetry is available and action exists
4635
- finalAction = action && _classPrivateFieldLooseBase(_this6, _telemetry)[_telemetry] ? _classPrivateFieldLooseBase(_this6, _telemetry)[_telemetry].traceMethod(action, {
4636
- spanName: "workflow." + _this6.name + ".action." + stepId
4657
+ mergedData = _extends({}, payload, context); // Only trace if telemetry is available and action exists
4658
+ finalAction = action && _classPrivateFieldLooseBase(_this7, _telemetry)[_telemetry] ? _classPrivateFieldLooseBase(_this7, _telemetry)[_telemetry].traceMethod(action, {
4659
+ spanName: "workflow." + _this7.name + ".action." + stepId
4637
4660
  }) : action;
4638
4661
  if (!finalAction) {
4639
- _context4.next = 14;
4662
+ _context4.next = 13;
4640
4663
  break;
4641
4664
  }
4642
- _context4.next = 11;
4665
+ _context4.next = 10;
4643
4666
  return finalAction({
4644
- data: validatedData,
4667
+ context: mergedData,
4645
4668
  runId: runId
4646
4669
  });
4647
- case 11:
4670
+ case 10:
4648
4671
  _context4.t0 = _context4.sent;
4649
- _context4.next = 15;
4672
+ _context4.next = 14;
4650
4673
  break;
4651
- case 14:
4674
+ case 13:
4652
4675
  _context4.t0 = {};
4653
- case 15:
4676
+ case 14:
4654
4677
  return _context4.abrupt("return", _context4.t0);
4655
- case 16:
4678
+ case 15:
4656
4679
  case "end":
4657
4680
  return _context4.stop();
4658
4681
  }
4659
4682
  }, _callee4);
4660
4683
  }));
4661
4684
  return function handler(_x9) {
4662
- return _ref25.apply(this, arguments);
4685
+ return _ref28.apply(this, arguments);
4663
4686
  };
4664
4687
  }();
4665
4688
  // Only trace handler if telemetry is available
@@ -4667,17 +4690,16 @@ function _makeStepDef2(stepId) {
4667
4690
  spanName: "workflow." + this.name + ".step." + stepId
4668
4691
  }) : handler;
4669
4692
  return {
4670
- dependsOn: [],
4671
4693
  handler: finalHandler,
4672
4694
  data: {}
4673
4695
  };
4674
4696
  }
4675
4697
  function _makeDelayMap2() {
4676
- var _this7 = this;
4698
+ var _this8 = this;
4677
4699
  var delayMap = {};
4678
- _classPrivateFieldLooseBase(this, _steps)[_steps].forEach(function (step) {
4679
- var _step$retryConfig2, _classPrivateFieldLoo2;
4680
- delayMap[step.id] = (step == null || (_step$retryConfig2 = step.retryConfig) == null ? void 0 : _step$retryConfig2.delay) || ((_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(_this7, _retryConfig)[_retryConfig]) == null ? void 0 : _classPrivateFieldLoo2.delay) || 1000;
4700
+ Object.keys(_classPrivateFieldLooseBase(this, _steps)[_steps]).forEach(function (stepId) {
4701
+ var _classPrivateFieldLoo3, _classPrivateFieldLoo4;
4702
+ delayMap[stepId] = ((_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(_this8, _steps)[_steps][stepId]) == null || (_classPrivateFieldLoo3 = _classPrivateFieldLoo3.retryConfig) == null ? void 0 : _classPrivateFieldLoo3.delay) || ((_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(_this8, _retryConfig)[_retryConfig]) == null ? void 0 : _classPrivateFieldLoo4.delay) || 1000;
4681
4703
  });
4682
4704
  return delayMap;
4683
4705
  }