@positronic/core 0.0.61 → 0.0.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/dsl/brain-runner.js +7 -6
- package/dist/src/dsl/brain-state-machine.js +42 -9
- package/dist/src/dsl/builder/brain.js +55 -127
- package/dist/src/dsl/constants.js +4 -1
- package/dist/src/dsl/example-webhook.js +8 -9
- package/dist/src/dsl/execution/event-stream.js +674 -108
- package/dist/src/dsl/execution/retry.js +0 -291
- package/dist/src/ui/generate-ui.js +2 -1
- package/dist/types/clients/types.d.ts +28 -0
- package/dist/types/clients/types.d.ts.map +1 -1
- package/dist/types/dsl/brain-runner.d.ts.map +1 -1
- package/dist/types/dsl/brain-state-machine.d.ts +12 -0
- package/dist/types/dsl/brain-state-machine.d.ts.map +1 -1
- package/dist/types/dsl/brain.d.ts +1 -1
- package/dist/types/dsl/brain.d.ts.map +1 -1
- package/dist/types/dsl/builder/brain.d.ts +15 -18
- package/dist/types/dsl/builder/brain.d.ts.map +1 -1
- package/dist/types/dsl/constants.d.ts +2 -0
- package/dist/types/dsl/constants.d.ts.map +1 -1
- package/dist/types/dsl/definitions/blocks.d.ts +37 -10
- package/dist/types/dsl/definitions/blocks.d.ts.map +1 -1
- package/dist/types/dsl/definitions/events.d.ts +12 -1
- package/dist/types/dsl/definitions/events.d.ts.map +1 -1
- package/dist/types/dsl/definitions/run-params.d.ts +6 -0
- package/dist/types/dsl/definitions/run-params.d.ts.map +1 -1
- package/dist/types/dsl/definitions/steps.d.ts +1 -1
- package/dist/types/dsl/definitions/steps.d.ts.map +1 -1
- package/dist/types/dsl/example-webhook.d.ts +1 -1
- package/dist/types/dsl/example-webhook.d.ts.map +1 -1
- package/dist/types/dsl/execution/event-stream.d.ts +12 -1
- package/dist/types/dsl/execution/event-stream.d.ts.map +1 -1
- package/dist/types/dsl/execution/retry.d.ts +0 -25
- package/dist/types/dsl/execution/retry.d.ts.map +1 -1
- package/dist/types/dsl/types.d.ts +8 -14
- package/dist/types/dsl/types.d.ts.map +1 -1
- package/dist/types/dsl/webhook.d.ts +1 -0
- package/dist/types/dsl/webhook.d.ts.map +1 -1
- package/dist/types/index.d.ts +4 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/ui/generate-ui.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -166,6 +166,35 @@ function AsyncFromSyncIterator(s) {
|
|
|
166
166
|
}
|
|
167
167
|
}, new AsyncFromSyncIterator(s);
|
|
168
168
|
}
|
|
169
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
170
|
+
try {
|
|
171
|
+
var info = gen[key](arg);
|
|
172
|
+
var value = info.value;
|
|
173
|
+
} catch (error) {
|
|
174
|
+
reject(error);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (info.done) {
|
|
178
|
+
resolve(value);
|
|
179
|
+
} else {
|
|
180
|
+
Promise.resolve(value).then(_next, _throw);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function _async_to_generator(fn) {
|
|
184
|
+
return function() {
|
|
185
|
+
var self = this, args = arguments;
|
|
186
|
+
return new Promise(function(resolve, reject) {
|
|
187
|
+
var gen = fn.apply(self, args);
|
|
188
|
+
function _next(value) {
|
|
189
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
190
|
+
}
|
|
191
|
+
function _throw(err) {
|
|
192
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
193
|
+
}
|
|
194
|
+
_next(undefined);
|
|
195
|
+
});
|
|
196
|
+
};
|
|
197
|
+
}
|
|
169
198
|
function _await_async_generator(value) {
|
|
170
199
|
return new _overload_yield(value, 0);
|
|
171
200
|
}
|
|
@@ -469,6 +498,9 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
469
498
|
_define_property(this, "signalProvider", void 0);
|
|
470
499
|
_define_property(this, "memoryProvider", void 0);
|
|
471
500
|
_define_property(this, "scopedMemory", void 0);
|
|
501
|
+
_define_property(this, "guards", new Map());
|
|
502
|
+
_define_property(this, "waits", new Map());
|
|
503
|
+
_define_property(this, "stopped", false);
|
|
472
504
|
var blocks = params.blocks, title = params.title, description = params.description, providedBrainRunId = params.brainRunId, _params_options = params.options, options = _params_options === void 0 ? {} : _params_options, client = params.client, services = params.services, _params_resources = params.resources, resources = _params_resources === void 0 ? {} : _params_resources, pages = params.pages, env = params.env, components = params.components, defaultTools = params.defaultTools, signalProvider = params.signalProvider, memoryProvider = params.memoryProvider;
|
|
473
505
|
// Check if this is a resume run or fresh start
|
|
474
506
|
var resumeParams = params;
|
|
@@ -491,10 +523,35 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
491
523
|
if (memoryProvider) {
|
|
492
524
|
this.scopedMemory = createScopedMemory(memoryProvider, title);
|
|
493
525
|
}
|
|
494
|
-
// Initialize steps -
|
|
495
|
-
this.steps =
|
|
496
|
-
|
|
497
|
-
|
|
526
|
+
// Initialize steps - track guard and wait blocks by index
|
|
527
|
+
this.steps = [];
|
|
528
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
529
|
+
try {
|
|
530
|
+
for(var _iterator = blocks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
531
|
+
var block = _step.value;
|
|
532
|
+
if (block.type === 'guard') {
|
|
533
|
+
var guardBlock = block;
|
|
534
|
+
this.guards.set(this.steps.length, guardBlock);
|
|
535
|
+
} else if (block.type === 'wait') {
|
|
536
|
+
var waitBlock = block;
|
|
537
|
+
this.waits.set(this.steps.length, waitBlock);
|
|
538
|
+
}
|
|
539
|
+
this.steps.push(new Step(block));
|
|
540
|
+
}
|
|
541
|
+
} catch (err) {
|
|
542
|
+
_didIteratorError = true;
|
|
543
|
+
_iteratorError = err;
|
|
544
|
+
} finally{
|
|
545
|
+
try {
|
|
546
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
547
|
+
_iterator.return();
|
|
548
|
+
}
|
|
549
|
+
} finally{
|
|
550
|
+
if (_didIteratorError) {
|
|
551
|
+
throw _iteratorError;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}
|
|
498
555
|
if (resumeContext) {
|
|
499
556
|
// Resume: use state and stepIndex directly from resumeContext
|
|
500
557
|
this.currentState = clone(resumeContext.state);
|
|
@@ -533,7 +590,7 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
533
590
|
key: "next",
|
|
534
591
|
value: function next() {
|
|
535
592
|
return _wrap_async_generator(function() {
|
|
536
|
-
var _this, steps, brainTitle, brainDescription, currentState, options, brainRunId, webhookResponse, signals, webhookSignal, deepest, signals1, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, signal, err, step, err1, error, currentStep;
|
|
593
|
+
var _this, steps, brainTitle, brainDescription, currentState, options, brainRunId, webhookResponse, signals, webhookSignal, deepest, signals1, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, signal, err, step, guard, waitBlock, err1, error, currentStep;
|
|
537
594
|
return _ts_generator(this, function(_state) {
|
|
538
595
|
switch(_state.label){
|
|
539
596
|
case 0:
|
|
@@ -542,9 +599,9 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
542
599
|
case 1:
|
|
543
600
|
_state.trys.push([
|
|
544
601
|
1,
|
|
545
|
-
|
|
602
|
+
33,
|
|
546
603
|
,
|
|
547
|
-
|
|
604
|
+
36
|
|
548
605
|
]);
|
|
549
606
|
if (!!this.resumeContext) return [
|
|
550
607
|
3,
|
|
@@ -664,7 +721,7 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
664
721
|
case 11:
|
|
665
722
|
if (!(this.currentStepIndex < steps.length)) return [
|
|
666
723
|
3,
|
|
667
|
-
|
|
724
|
+
31
|
|
668
725
|
];
|
|
669
726
|
if (!this.signalProvider) return [
|
|
670
727
|
3,
|
|
@@ -768,14 +825,49 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
768
825
|
];
|
|
769
826
|
case 22:
|
|
770
827
|
step = steps[this.currentStepIndex];
|
|
771
|
-
// Skip completed steps
|
|
772
|
-
if (step.serialized.status === STATUS.COMPLETE) {
|
|
828
|
+
// Skip completed or skipped steps
|
|
829
|
+
if (step.serialized.status === STATUS.COMPLETE || step.serialized.status === STATUS.HALTED) {
|
|
773
830
|
this.currentStepIndex++;
|
|
774
831
|
return [
|
|
775
832
|
3,
|
|
776
833
|
11
|
|
777
834
|
];
|
|
778
835
|
}
|
|
836
|
+
// Handle guard blocks
|
|
837
|
+
guard = this.guards.get(this.currentStepIndex);
|
|
838
|
+
if (!guard) return [
|
|
839
|
+
3,
|
|
840
|
+
24
|
|
841
|
+
];
|
|
842
|
+
return [
|
|
843
|
+
5,
|
|
844
|
+
_ts_values(_async_generator_delegate(_async_iterator(this.executeGuard(step, guard))))
|
|
845
|
+
];
|
|
846
|
+
case 23:
|
|
847
|
+
_state.sent();
|
|
848
|
+
return [
|
|
849
|
+
3,
|
|
850
|
+
11
|
|
851
|
+
];
|
|
852
|
+
case 24:
|
|
853
|
+
// Handle wait blocks
|
|
854
|
+
waitBlock = this.waits.get(this.currentStepIndex);
|
|
855
|
+
if (!waitBlock) return [
|
|
856
|
+
3,
|
|
857
|
+
26
|
|
858
|
+
];
|
|
859
|
+
return [
|
|
860
|
+
5,
|
|
861
|
+
_ts_values(_async_generator_delegate(_async_iterator(this.executeWait(step, waitBlock))))
|
|
862
|
+
];
|
|
863
|
+
case 25:
|
|
864
|
+
_state.sent();
|
|
865
|
+
this.currentStepIndex++;
|
|
866
|
+
return [
|
|
867
|
+
3,
|
|
868
|
+
11
|
|
869
|
+
];
|
|
870
|
+
case 26:
|
|
779
871
|
// Step start event
|
|
780
872
|
return [
|
|
781
873
|
4,
|
|
@@ -789,7 +881,7 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
789
881
|
brainRunId: brainRunId
|
|
790
882
|
}
|
|
791
883
|
];
|
|
792
|
-
case
|
|
884
|
+
case 27:
|
|
793
885
|
_state.sent();
|
|
794
886
|
step.withStatus(STATUS.RUNNING);
|
|
795
887
|
// Step Status Event to indicate that the step is running
|
|
@@ -807,7 +899,7 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
807
899
|
brainRunId: brainRunId
|
|
808
900
|
}
|
|
809
901
|
];
|
|
810
|
-
case
|
|
902
|
+
case 28:
|
|
811
903
|
_state.sent();
|
|
812
904
|
// Execute step and yield the STEP_COMPLETE event and
|
|
813
905
|
// all events from inner brains if any
|
|
@@ -815,8 +907,14 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
815
907
|
5,
|
|
816
908
|
_ts_values(_async_generator_delegate(_async_iterator(this.executeStep(step))))
|
|
817
909
|
];
|
|
818
|
-
case
|
|
910
|
+
case 29:
|
|
819
911
|
_state.sent();
|
|
912
|
+
// Backend requested a stop (e.g. batch chunk pause for DO restart)
|
|
913
|
+
if (this.stopped) {
|
|
914
|
+
return [
|
|
915
|
+
2
|
|
916
|
+
];
|
|
917
|
+
}
|
|
820
918
|
// Step Status Event
|
|
821
919
|
return [
|
|
822
920
|
4,
|
|
@@ -832,14 +930,14 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
832
930
|
brainRunId: brainRunId
|
|
833
931
|
}
|
|
834
932
|
];
|
|
835
|
-
case
|
|
933
|
+
case 30:
|
|
836
934
|
_state.sent();
|
|
837
935
|
this.currentStepIndex++;
|
|
838
936
|
return [
|
|
839
937
|
3,
|
|
840
938
|
11
|
|
841
939
|
];
|
|
842
|
-
case
|
|
940
|
+
case 31:
|
|
843
941
|
return [
|
|
844
942
|
4,
|
|
845
943
|
{
|
|
@@ -851,13 +949,13 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
851
949
|
options: options
|
|
852
950
|
}
|
|
853
951
|
];
|
|
854
|
-
case
|
|
952
|
+
case 32:
|
|
855
953
|
_state.sent();
|
|
856
954
|
return [
|
|
857
955
|
3,
|
|
858
|
-
|
|
956
|
+
36
|
|
859
957
|
];
|
|
860
|
-
case
|
|
958
|
+
case 33:
|
|
861
959
|
err1 = _state.sent();
|
|
862
960
|
error = err1;
|
|
863
961
|
currentStep = steps[this.currentStepIndex];
|
|
@@ -878,7 +976,7 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
878
976
|
options: options
|
|
879
977
|
}
|
|
880
978
|
];
|
|
881
|
-
case
|
|
979
|
+
case 34:
|
|
882
980
|
_state.sent();
|
|
883
981
|
// Step Status Event
|
|
884
982
|
return [
|
|
@@ -895,10 +993,10 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
895
993
|
brainRunId: brainRunId
|
|
896
994
|
}
|
|
897
995
|
];
|
|
898
|
-
case
|
|
996
|
+
case 35:
|
|
899
997
|
_state.sent();
|
|
900
998
|
throw error;
|
|
901
|
-
case
|
|
999
|
+
case 36:
|
|
902
1000
|
return [
|
|
903
1001
|
2
|
|
904
1002
|
];
|
|
@@ -911,14 +1009,14 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
911
1009
|
key: "executeStep",
|
|
912
1010
|
value: function executeStep(step) {
|
|
913
1011
|
return _wrap_async_generator(function() {
|
|
914
|
-
var block, stepBlock, _this_resumeContext, brainBlock, initialState, innerResumeContext, patches, innerBrainPaused, _this_options, _this_options1, innerRun, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, event, err, _innerResumeContext_state, baseState, innerState, prevState, _, prevState1, stepBlock1, retries, result, _this_options2, actionPromise, error, _this_options3
|
|
1012
|
+
var block, stepBlock, _this_resumeContext, brainBlock, initialState, innerResumeContext, patches, innerBrainPaused, _this_options, _this_options1, innerRun, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, event, err, _innerResumeContext_state, baseState, innerState, prevState, _, prevState1, stepBlock1, retries, result, _this_options2, actionPromise, error, _this_options3;
|
|
915
1013
|
return _ts_generator(this, function(_state) {
|
|
916
1014
|
switch(_state.label){
|
|
917
1015
|
case 0:
|
|
918
1016
|
block = step.block;
|
|
919
1017
|
if (!(block.type === 'step')) return [
|
|
920
1018
|
3,
|
|
921
|
-
|
|
1019
|
+
4
|
|
922
1020
|
];
|
|
923
1021
|
stepBlock = block;
|
|
924
1022
|
if (!stepBlock.isUIStep) return [
|
|
@@ -935,9 +1033,23 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
935
1033
|
2
|
|
936
1034
|
];
|
|
937
1035
|
case 2:
|
|
1036
|
+
if (!stepBlock.batchConfig) return [
|
|
1037
|
+
3,
|
|
1038
|
+
4
|
|
1039
|
+
];
|
|
1040
|
+
return [
|
|
1041
|
+
5,
|
|
1042
|
+
_ts_values(_async_generator_delegate(_async_iterator(this.executeBatchPrompt(step))))
|
|
1043
|
+
];
|
|
1044
|
+
case 3:
|
|
1045
|
+
_state.sent();
|
|
1046
|
+
return [
|
|
1047
|
+
2
|
|
1048
|
+
];
|
|
1049
|
+
case 4:
|
|
938
1050
|
if (!(block.type === 'brain')) return [
|
|
939
1051
|
3,
|
|
940
|
-
|
|
1052
|
+
20
|
|
941
1053
|
];
|
|
942
1054
|
brainBlock = block;
|
|
943
1055
|
initialState = typeof brainBlock.initialState === 'function' ? brainBlock.initialState(this.currentState) : brainBlock.initialState;
|
|
@@ -965,25 +1077,25 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
965
1077
|
brainRunId: this.brainRunId
|
|
966
1078
|
});
|
|
967
1079
|
_iteratorAbruptCompletion = false, _didIteratorError = false;
|
|
968
|
-
_state.label =
|
|
969
|
-
case
|
|
1080
|
+
_state.label = 5;
|
|
1081
|
+
case 5:
|
|
970
1082
|
_state.trys.push([
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
1083
|
+
5,
|
|
1084
|
+
11,
|
|
1085
|
+
12,
|
|
1086
|
+
17
|
|
975
1087
|
]);
|
|
976
1088
|
_iterator = _async_iterator(innerRun);
|
|
977
|
-
_state.label =
|
|
978
|
-
case
|
|
1089
|
+
_state.label = 6;
|
|
1090
|
+
case 6:
|
|
979
1091
|
return [
|
|
980
1092
|
4,
|
|
981
1093
|
_await_async_generator(_iterator.next())
|
|
982
1094
|
];
|
|
983
|
-
case
|
|
1095
|
+
case 7:
|
|
984
1096
|
if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
|
|
985
1097
|
3,
|
|
986
|
-
|
|
1098
|
+
10
|
|
987
1099
|
];
|
|
988
1100
|
_value = _step.value;
|
|
989
1101
|
event = _value;
|
|
@@ -991,7 +1103,7 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
991
1103
|
4,
|
|
992
1104
|
event
|
|
993
1105
|
];
|
|
994
|
-
case
|
|
1106
|
+
case 8:
|
|
995
1107
|
_state.sent(); // Forward all inner brain events
|
|
996
1108
|
if (event.type === BRAIN_EVENTS.STEP_COMPLETE) {
|
|
997
1109
|
patches.push(event.patch);
|
|
@@ -1004,64 +1116,64 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
1004
1116
|
if (event.type === BRAIN_EVENTS.COMPLETE) {
|
|
1005
1117
|
return [
|
|
1006
1118
|
3,
|
|
1007
|
-
|
|
1119
|
+
10
|
|
1008
1120
|
];
|
|
1009
1121
|
}
|
|
1010
|
-
_state.label =
|
|
1011
|
-
case
|
|
1122
|
+
_state.label = 9;
|
|
1123
|
+
case 9:
|
|
1012
1124
|
_iteratorAbruptCompletion = false;
|
|
1013
1125
|
return [
|
|
1014
1126
|
3,
|
|
1015
|
-
|
|
1127
|
+
6
|
|
1016
1128
|
];
|
|
1017
|
-
case
|
|
1129
|
+
case 10:
|
|
1018
1130
|
return [
|
|
1019
1131
|
3,
|
|
1020
|
-
|
|
1132
|
+
17
|
|
1021
1133
|
];
|
|
1022
|
-
case
|
|
1134
|
+
case 11:
|
|
1023
1135
|
err = _state.sent();
|
|
1024
1136
|
_didIteratorError = true;
|
|
1025
1137
|
_iteratorError = err;
|
|
1026
1138
|
return [
|
|
1027
1139
|
3,
|
|
1028
|
-
|
|
1140
|
+
17
|
|
1029
1141
|
];
|
|
1030
|
-
case
|
|
1142
|
+
case 12:
|
|
1031
1143
|
_state.trys.push([
|
|
1032
|
-
|
|
1144
|
+
12,
|
|
1033
1145
|
,
|
|
1034
|
-
|
|
1035
|
-
|
|
1146
|
+
15,
|
|
1147
|
+
16
|
|
1036
1148
|
]);
|
|
1037
1149
|
if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
|
|
1038
1150
|
3,
|
|
1039
|
-
|
|
1151
|
+
14
|
|
1040
1152
|
];
|
|
1041
1153
|
return [
|
|
1042
1154
|
4,
|
|
1043
1155
|
_await_async_generator(_iterator.return())
|
|
1044
1156
|
];
|
|
1045
|
-
case
|
|
1157
|
+
case 13:
|
|
1046
1158
|
_state.sent();
|
|
1047
|
-
_state.label =
|
|
1048
|
-
case
|
|
1159
|
+
_state.label = 14;
|
|
1160
|
+
case 14:
|
|
1049
1161
|
return [
|
|
1050
1162
|
3,
|
|
1051
|
-
|
|
1163
|
+
16
|
|
1052
1164
|
];
|
|
1053
|
-
case
|
|
1165
|
+
case 15:
|
|
1054
1166
|
if (_didIteratorError) {
|
|
1055
1167
|
throw _iteratorError;
|
|
1056
1168
|
}
|
|
1057
1169
|
return [
|
|
1058
1170
|
7
|
|
1059
1171
|
];
|
|
1060
|
-
case
|
|
1172
|
+
case 16:
|
|
1061
1173
|
return [
|
|
1062
1174
|
7
|
|
1063
1175
|
];
|
|
1064
|
-
case
|
|
1176
|
+
case 17:
|
|
1065
1177
|
// If inner brain paused for webhook, don't complete the outer brain step
|
|
1066
1178
|
// The outer brain should also pause
|
|
1067
1179
|
if (innerBrainPaused) {
|
|
@@ -1081,52 +1193,52 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
1081
1193
|
4,
|
|
1082
1194
|
_await_async_generator(brainBlock.action(this.currentState, innerState, this.services))
|
|
1083
1195
|
];
|
|
1084
|
-
case
|
|
1196
|
+
case 18:
|
|
1085
1197
|
_.currentState = _state.sent();
|
|
1086
1198
|
return [
|
|
1087
1199
|
5,
|
|
1088
1200
|
_ts_values(_async_generator_delegate(_async_iterator(this.completeStep(step, prevState))))
|
|
1089
1201
|
];
|
|
1090
|
-
case
|
|
1202
|
+
case 19:
|
|
1091
1203
|
_state.sent();
|
|
1092
1204
|
return [
|
|
1093
1205
|
3,
|
|
1094
1206
|
33
|
|
1095
1207
|
];
|
|
1096
|
-
case
|
|
1208
|
+
case 20:
|
|
1097
1209
|
if (!(block.type === 'agent')) return [
|
|
1098
1210
|
3,
|
|
1099
|
-
|
|
1211
|
+
22
|
|
1100
1212
|
];
|
|
1101
1213
|
return [
|
|
1102
1214
|
5,
|
|
1103
1215
|
_ts_values(_async_generator_delegate(_async_iterator(this.executeAgent(step))))
|
|
1104
1216
|
];
|
|
1105
|
-
case
|
|
1217
|
+
case 21:
|
|
1106
1218
|
_state.sent();
|
|
1107
1219
|
return [
|
|
1108
1220
|
3,
|
|
1109
1221
|
33
|
|
1110
1222
|
];
|
|
1111
|
-
case
|
|
1223
|
+
case 22:
|
|
1112
1224
|
// Get previous state before action
|
|
1113
1225
|
prevState1 = this.currentState;
|
|
1114
1226
|
stepBlock1 = block;
|
|
1115
1227
|
// Execute step with automatic retry on failure
|
|
1116
1228
|
retries = 0;
|
|
1117
|
-
_state.label =
|
|
1118
|
-
case
|
|
1229
|
+
_state.label = 23;
|
|
1230
|
+
case 23:
|
|
1119
1231
|
if (!true) return [
|
|
1120
1232
|
3,
|
|
1121
|
-
|
|
1233
|
+
31
|
|
1122
1234
|
];
|
|
1123
|
-
_state.label =
|
|
1124
|
-
case
|
|
1235
|
+
_state.label = 24;
|
|
1236
|
+
case 24:
|
|
1125
1237
|
_state.trys.push([
|
|
1126
|
-
22,
|
|
1127
1238
|
24,
|
|
1239
|
+
26,
|
|
1128
1240
|
,
|
|
1129
|
-
|
|
1241
|
+
30
|
|
1130
1242
|
]);
|
|
1131
1243
|
actionPromise = Promise.resolve(stepBlock1.action(_object_spread({
|
|
1132
1244
|
state: this.currentState,
|
|
@@ -1143,17 +1255,17 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
1143
1255
|
4,
|
|
1144
1256
|
_await_async_generator(actionPromise)
|
|
1145
1257
|
];
|
|
1146
|
-
case
|
|
1258
|
+
case 25:
|
|
1147
1259
|
result = _state.sent();
|
|
1148
1260
|
return [
|
|
1149
1261
|
3,
|
|
1150
|
-
|
|
1262
|
+
31
|
|
1151
1263
|
]; // Success
|
|
1152
|
-
case
|
|
1264
|
+
case 26:
|
|
1153
1265
|
error = _state.sent();
|
|
1154
1266
|
if (!(retries < MAX_RETRIES)) return [
|
|
1155
1267
|
3,
|
|
1156
|
-
|
|
1268
|
+
28
|
|
1157
1269
|
];
|
|
1158
1270
|
retries++;
|
|
1159
1271
|
return [
|
|
@@ -1172,27 +1284,27 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
1172
1284
|
brainRunId: this.brainRunId
|
|
1173
1285
|
}
|
|
1174
1286
|
];
|
|
1175
|
-
case
|
|
1287
|
+
case 27:
|
|
1176
1288
|
_state.sent();
|
|
1177
1289
|
return [
|
|
1178
1290
|
3,
|
|
1179
|
-
|
|
1291
|
+
29
|
|
1180
1292
|
];
|
|
1181
|
-
case
|
|
1293
|
+
case 28:
|
|
1182
1294
|
throw error;
|
|
1183
|
-
case
|
|
1295
|
+
case 29:
|
|
1184
1296
|
return [
|
|
1185
1297
|
3,
|
|
1186
|
-
|
|
1298
|
+
30
|
|
1187
1299
|
];
|
|
1188
|
-
case
|
|
1300
|
+
case 30:
|
|
1189
1301
|
return [
|
|
1190
1302
|
3,
|
|
1191
|
-
|
|
1303
|
+
23
|
|
1192
1304
|
];
|
|
1193
|
-
case
|
|
1194
|
-
// Extract state from result (handles
|
|
1195
|
-
if (result && (typeof result === "undefined" ? "undefined" : _type_of(result)) === 'object' &&
|
|
1305
|
+
case 31:
|
|
1306
|
+
// Extract state from result (handles promptResponse case)
|
|
1307
|
+
if (result && (typeof result === "undefined" ? "undefined" : _type_of(result)) === 'object' && 'promptResponse' in result) {
|
|
1196
1308
|
this.currentState = result.state;
|
|
1197
1309
|
} else {
|
|
1198
1310
|
this.currentState = result;
|
|
@@ -1201,32 +1313,8 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
1201
1313
|
5,
|
|
1202
1314
|
_ts_values(_async_generator_delegate(_async_iterator(this.completeStep(step, prevState1))))
|
|
1203
1315
|
];
|
|
1204
|
-
case 30:
|
|
1205
|
-
_state.sent();
|
|
1206
|
-
if (!(result && (typeof result === "undefined" ? "undefined" : _type_of(result)) === 'object' && 'waitFor' in result)) return [
|
|
1207
|
-
3,
|
|
1208
|
-
32
|
|
1209
|
-
];
|
|
1210
|
-
// Serialize webhook registrations (remove Zod schemas for event serializability)
|
|
1211
|
-
serializedWaitFor = result.waitFor.map(function(registration) {
|
|
1212
|
-
return {
|
|
1213
|
-
slug: registration.slug,
|
|
1214
|
-
identifier: registration.identifier
|
|
1215
|
-
};
|
|
1216
|
-
});
|
|
1217
|
-
return [
|
|
1218
|
-
4,
|
|
1219
|
-
{
|
|
1220
|
-
type: BRAIN_EVENTS.WEBHOOK,
|
|
1221
|
-
waitFor: serializedWaitFor,
|
|
1222
|
-
options: this.options,
|
|
1223
|
-
brainRunId: this.brainRunId
|
|
1224
|
-
}
|
|
1225
|
-
];
|
|
1226
|
-
case 31:
|
|
1227
|
-
_state.sent();
|
|
1228
|
-
_state.label = 32;
|
|
1229
1316
|
case 32:
|
|
1317
|
+
_state.sent();
|
|
1230
1318
|
// Handle promptResponse - set currentResponse for next step
|
|
1231
1319
|
if (result && (typeof result === "undefined" ? "undefined" : _type_of(result)) === 'object' && 'promptResponse' in result) {
|
|
1232
1320
|
this.currentResponse = result.promptResponse;
|
|
@@ -1675,7 +1763,8 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
1675
1763
|
system: systemPrompt,
|
|
1676
1764
|
messages: initialMessages,
|
|
1677
1765
|
responseMessages: responseMessages,
|
|
1678
|
-
tools: toolsForClient
|
|
1766
|
+
tools: toolsForClient,
|
|
1767
|
+
toolChoice: config.toolChoice
|
|
1679
1768
|
}))
|
|
1680
1769
|
];
|
|
1681
1770
|
case 30:
|
|
@@ -2070,6 +2159,246 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
2070
2159
|
}).call(this);
|
|
2071
2160
|
}
|
|
2072
2161
|
},
|
|
2162
|
+
{
|
|
2163
|
+
key: "executeBatchPrompt",
|
|
2164
|
+
value: /**
|
|
2165
|
+
* Execute a batch prompt step in chunks, yielding one BATCH_CHUNK_COMPLETE
|
|
2166
|
+
* event per chunk. Between chunks, checks for PAUSE/KILL signals so
|
|
2167
|
+
* Cloudflare backends can restart the DO to reclaim memory.
|
|
2168
|
+
*/ function executeBatchPrompt(step) {
|
|
2169
|
+
return _wrap_async_generator(function() {
|
|
2170
|
+
var _this, _this_resumeContext, block, batchConfig, prevState, _batchConfig_client, client, items, totalItems, _batchConfig_chunkSize, chunkSize, batchProgress, _batchProgress_processedCount, startIndex, results, chunkStart, signals, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, signal, _this_options, err, chunkEnd, chunk, chunkResults, i, _this_options1, finalResults;
|
|
2171
|
+
return _ts_generator(this, function(_state) {
|
|
2172
|
+
switch(_state.label){
|
|
2173
|
+
case 0:
|
|
2174
|
+
_this = this;
|
|
2175
|
+
block = step.block;
|
|
2176
|
+
batchConfig = block.batchConfig;
|
|
2177
|
+
prevState = this.currentState;
|
|
2178
|
+
client = (_batchConfig_client = batchConfig.client) !== null && _batchConfig_client !== void 0 ? _batchConfig_client : this.client;
|
|
2179
|
+
items = batchConfig.over(this.currentState);
|
|
2180
|
+
totalItems = items.length;
|
|
2181
|
+
chunkSize = (_batchConfig_chunkSize = batchConfig.chunkSize) !== null && _batchConfig_chunkSize !== void 0 ? _batchConfig_chunkSize : 10;
|
|
2182
|
+
// Resume support: pick up from where we left off
|
|
2183
|
+
batchProgress = (_this_resumeContext = this.resumeContext) === null || _this_resumeContext === void 0 ? void 0 : _this_resumeContext.batchProgress;
|
|
2184
|
+
startIndex = (_batchProgress_processedCount = batchProgress === null || batchProgress === void 0 ? void 0 : batchProgress.processedCount) !== null && _batchProgress_processedCount !== void 0 ? _batchProgress_processedCount : 0;
|
|
2185
|
+
results = (batchProgress === null || batchProgress === void 0 ? void 0 : batchProgress.accumulatedResults) ? _to_consumable_array(batchProgress.accumulatedResults) : new Array(totalItems);
|
|
2186
|
+
// Clear resumeContext after consuming batchProgress
|
|
2187
|
+
if (batchProgress) {
|
|
2188
|
+
this.resumeContext = undefined;
|
|
2189
|
+
}
|
|
2190
|
+
chunkStart = startIndex;
|
|
2191
|
+
_state.label = 1;
|
|
2192
|
+
case 1:
|
|
2193
|
+
if (!(chunkStart < totalItems)) return [
|
|
2194
|
+
3,
|
|
2195
|
+
15
|
|
2196
|
+
];
|
|
2197
|
+
if (!this.signalProvider) return [
|
|
2198
|
+
3,
|
|
2199
|
+
11
|
|
2200
|
+
];
|
|
2201
|
+
return [
|
|
2202
|
+
4,
|
|
2203
|
+
_await_async_generator(this.signalProvider.getSignals('CONTROL'))
|
|
2204
|
+
];
|
|
2205
|
+
case 2:
|
|
2206
|
+
signals = _state.sent();
|
|
2207
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
2208
|
+
_state.label = 3;
|
|
2209
|
+
case 3:
|
|
2210
|
+
_state.trys.push([
|
|
2211
|
+
3,
|
|
2212
|
+
9,
|
|
2213
|
+
10,
|
|
2214
|
+
11
|
|
2215
|
+
]);
|
|
2216
|
+
_iterator = signals[Symbol.iterator]();
|
|
2217
|
+
_state.label = 4;
|
|
2218
|
+
case 4:
|
|
2219
|
+
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
|
|
2220
|
+
3,
|
|
2221
|
+
8
|
|
2222
|
+
];
|
|
2223
|
+
signal = _step.value;
|
|
2224
|
+
if (!(signal.type === 'KILL')) return [
|
|
2225
|
+
3,
|
|
2226
|
+
6
|
|
2227
|
+
];
|
|
2228
|
+
return [
|
|
2229
|
+
4,
|
|
2230
|
+
{
|
|
2231
|
+
type: BRAIN_EVENTS.CANCELLED,
|
|
2232
|
+
status: STATUS.CANCELLED,
|
|
2233
|
+
brainTitle: this.title,
|
|
2234
|
+
brainDescription: this.description,
|
|
2235
|
+
brainRunId: this.brainRunId,
|
|
2236
|
+
options: (_this_options = this.options) !== null && _this_options !== void 0 ? _this_options : {}
|
|
2237
|
+
}
|
|
2238
|
+
];
|
|
2239
|
+
case 5:
|
|
2240
|
+
_state.sent();
|
|
2241
|
+
return [
|
|
2242
|
+
2
|
|
2243
|
+
];
|
|
2244
|
+
case 6:
|
|
2245
|
+
if (signal.type === 'PAUSE') {
|
|
2246
|
+
// Don't yield PAUSED - pausing between batch chunks is a backend
|
|
2247
|
+
// implementation detail (e.g. Cloudflare DO restart for memory).
|
|
2248
|
+
// Just stop execution silently; the backend handles resume.
|
|
2249
|
+
this.stopped = true;
|
|
2250
|
+
return [
|
|
2251
|
+
2
|
|
2252
|
+
];
|
|
2253
|
+
}
|
|
2254
|
+
_state.label = 7;
|
|
2255
|
+
case 7:
|
|
2256
|
+
_iteratorNormalCompletion = true;
|
|
2257
|
+
return [
|
|
2258
|
+
3,
|
|
2259
|
+
4
|
|
2260
|
+
];
|
|
2261
|
+
case 8:
|
|
2262
|
+
return [
|
|
2263
|
+
3,
|
|
2264
|
+
11
|
|
2265
|
+
];
|
|
2266
|
+
case 9:
|
|
2267
|
+
err = _state.sent();
|
|
2268
|
+
_didIteratorError = true;
|
|
2269
|
+
_iteratorError = err;
|
|
2270
|
+
return [
|
|
2271
|
+
3,
|
|
2272
|
+
11
|
|
2273
|
+
];
|
|
2274
|
+
case 10:
|
|
2275
|
+
try {
|
|
2276
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
2277
|
+
_iterator.return();
|
|
2278
|
+
}
|
|
2279
|
+
} finally{
|
|
2280
|
+
if (_didIteratorError) {
|
|
2281
|
+
throw _iteratorError;
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
2284
|
+
return [
|
|
2285
|
+
7
|
|
2286
|
+
];
|
|
2287
|
+
case 11:
|
|
2288
|
+
chunkEnd = Math.min(chunkStart + chunkSize, totalItems);
|
|
2289
|
+
chunk = items.slice(chunkStart, chunkEnd);
|
|
2290
|
+
return [
|
|
2291
|
+
4,
|
|
2292
|
+
_await_async_generator(Promise.all(chunk.map(function(item) {
|
|
2293
|
+
return _async_to_generator(function() {
|
|
2294
|
+
var promptText, output, error, fallback;
|
|
2295
|
+
return _ts_generator(this, function(_state) {
|
|
2296
|
+
switch(_state.label){
|
|
2297
|
+
case 0:
|
|
2298
|
+
_state.trys.push([
|
|
2299
|
+
0,
|
|
2300
|
+
3,
|
|
2301
|
+
,
|
|
2302
|
+
4
|
|
2303
|
+
]);
|
|
2304
|
+
return [
|
|
2305
|
+
4,
|
|
2306
|
+
batchConfig.template(item, this.resources)
|
|
2307
|
+
];
|
|
2308
|
+
case 1:
|
|
2309
|
+
promptText = _state.sent();
|
|
2310
|
+
return [
|
|
2311
|
+
4,
|
|
2312
|
+
client.generateObject(_object_spread({
|
|
2313
|
+
schema: batchConfig.schema,
|
|
2314
|
+
schemaName: batchConfig.schemaName,
|
|
2315
|
+
prompt: promptText
|
|
2316
|
+
}, batchConfig.maxRetries !== undefined && {
|
|
2317
|
+
maxRetries: batchConfig.maxRetries
|
|
2318
|
+
}))
|
|
2319
|
+
];
|
|
2320
|
+
case 2:
|
|
2321
|
+
output = _state.sent();
|
|
2322
|
+
return [
|
|
2323
|
+
2,
|
|
2324
|
+
[
|
|
2325
|
+
item,
|
|
2326
|
+
output
|
|
2327
|
+
]
|
|
2328
|
+
];
|
|
2329
|
+
case 3:
|
|
2330
|
+
error = _state.sent();
|
|
2331
|
+
if (batchConfig.error) {
|
|
2332
|
+
fallback = batchConfig.error(item, error);
|
|
2333
|
+
return [
|
|
2334
|
+
2,
|
|
2335
|
+
fallback !== null ? [
|
|
2336
|
+
item,
|
|
2337
|
+
fallback
|
|
2338
|
+
] : undefined
|
|
2339
|
+
];
|
|
2340
|
+
}
|
|
2341
|
+
throw error;
|
|
2342
|
+
case 4:
|
|
2343
|
+
return [
|
|
2344
|
+
2
|
|
2345
|
+
];
|
|
2346
|
+
}
|
|
2347
|
+
});
|
|
2348
|
+
}).call(_this);
|
|
2349
|
+
})))
|
|
2350
|
+
];
|
|
2351
|
+
case 12:
|
|
2352
|
+
chunkResults = _state.sent();
|
|
2353
|
+
// Store chunk results at correct indices
|
|
2354
|
+
for(i = 0; i < chunkResults.length; i++){
|
|
2355
|
+
results[chunkStart + i] = chunkResults[i];
|
|
2356
|
+
}
|
|
2357
|
+
// Yield ONE event per chunk
|
|
2358
|
+
return [
|
|
2359
|
+
4,
|
|
2360
|
+
{
|
|
2361
|
+
type: BRAIN_EVENTS.BATCH_CHUNK_COMPLETE,
|
|
2362
|
+
stepTitle: step.block.title,
|
|
2363
|
+
stepId: step.id,
|
|
2364
|
+
chunkStartIndex: chunkStart,
|
|
2365
|
+
processedCount: chunkEnd,
|
|
2366
|
+
totalItems: totalItems,
|
|
2367
|
+
chunkResults: chunkResults,
|
|
2368
|
+
schemaName: batchConfig.schemaName,
|
|
2369
|
+
options: (_this_options1 = this.options) !== null && _this_options1 !== void 0 ? _this_options1 : {},
|
|
2370
|
+
brainRunId: this.brainRunId
|
|
2371
|
+
}
|
|
2372
|
+
];
|
|
2373
|
+
case 13:
|
|
2374
|
+
_state.sent();
|
|
2375
|
+
_state.label = 14;
|
|
2376
|
+
case 14:
|
|
2377
|
+
chunkStart += chunkSize;
|
|
2378
|
+
return [
|
|
2379
|
+
3,
|
|
2380
|
+
1
|
|
2381
|
+
];
|
|
2382
|
+
case 15:
|
|
2383
|
+
// All chunks done - update state and complete step
|
|
2384
|
+
finalResults = results.filter(function(r) {
|
|
2385
|
+
return r != null;
|
|
2386
|
+
});
|
|
2387
|
+
this.currentState = _object_spread_props(_object_spread({}, this.currentState), _define_property({}, batchConfig.schemaName, finalResults));
|
|
2388
|
+
return [
|
|
2389
|
+
5,
|
|
2390
|
+
_ts_values(_async_generator_delegate(_async_iterator(this.completeStep(step, prevState))))
|
|
2391
|
+
];
|
|
2392
|
+
case 16:
|
|
2393
|
+
_state.sent();
|
|
2394
|
+
return [
|
|
2395
|
+
2
|
|
2396
|
+
];
|
|
2397
|
+
}
|
|
2398
|
+
});
|
|
2399
|
+
}).call(this);
|
|
2400
|
+
}
|
|
2401
|
+
},
|
|
2073
2402
|
{
|
|
2074
2403
|
key: "executeUIStep",
|
|
2075
2404
|
value: /**
|
|
@@ -2168,6 +2497,243 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
2168
2497
|
}).call(this);
|
|
2169
2498
|
}
|
|
2170
2499
|
},
|
|
2500
|
+
{
|
|
2501
|
+
key: "executeWait",
|
|
2502
|
+
value: function executeWait(step, waitBlock) {
|
|
2503
|
+
return _wrap_async_generator(function() {
|
|
2504
|
+
var _this, steps, options, brainRunId, _this_options, result, webhooks, serializedWaitFor;
|
|
2505
|
+
return _ts_generator(this, function(_state) {
|
|
2506
|
+
switch(_state.label){
|
|
2507
|
+
case 0:
|
|
2508
|
+
_this = this, steps = _this.steps, options = _this.options, brainRunId = _this.brainRunId;
|
|
2509
|
+
// Emit STEP_START for the wait block
|
|
2510
|
+
return [
|
|
2511
|
+
4,
|
|
2512
|
+
{
|
|
2513
|
+
type: BRAIN_EVENTS.STEP_START,
|
|
2514
|
+
status: STATUS.RUNNING,
|
|
2515
|
+
stepTitle: step.block.title,
|
|
2516
|
+
stepId: step.id,
|
|
2517
|
+
stepIndex: this.currentStepIndex,
|
|
2518
|
+
options: options,
|
|
2519
|
+
brainRunId: brainRunId
|
|
2520
|
+
}
|
|
2521
|
+
];
|
|
2522
|
+
case 1:
|
|
2523
|
+
_state.sent();
|
|
2524
|
+
step.withStatus(STATUS.RUNNING);
|
|
2525
|
+
return [
|
|
2526
|
+
4,
|
|
2527
|
+
{
|
|
2528
|
+
type: BRAIN_EVENTS.STEP_STATUS,
|
|
2529
|
+
steps: steps.map(function(s) {
|
|
2530
|
+
var _s_serialized = s.serialized, patch = _s_serialized.patch, rest = _object_without_properties(_s_serialized, [
|
|
2531
|
+
"patch"
|
|
2532
|
+
]);
|
|
2533
|
+
return rest;
|
|
2534
|
+
}),
|
|
2535
|
+
options: options,
|
|
2536
|
+
brainRunId: brainRunId
|
|
2537
|
+
}
|
|
2538
|
+
];
|
|
2539
|
+
case 2:
|
|
2540
|
+
_state.sent();
|
|
2541
|
+
return [
|
|
2542
|
+
4,
|
|
2543
|
+
_await_async_generator(waitBlock.action(_object_spread({
|
|
2544
|
+
state: this.currentState,
|
|
2545
|
+
options: (_this_options = this.options) !== null && _this_options !== void 0 ? _this_options : {},
|
|
2546
|
+
client: this.client,
|
|
2547
|
+
resources: this.resources,
|
|
2548
|
+
page: this.currentPage,
|
|
2549
|
+
pages: this.pages,
|
|
2550
|
+
env: this.env
|
|
2551
|
+
}, this.services)))
|
|
2552
|
+
];
|
|
2553
|
+
case 3:
|
|
2554
|
+
result = _state.sent();
|
|
2555
|
+
// Complete step (state unchanged, generates empty patch)
|
|
2556
|
+
return [
|
|
2557
|
+
5,
|
|
2558
|
+
_ts_values(_async_generator_delegate(_async_iterator(this.completeStep(step, this.currentState))))
|
|
2559
|
+
];
|
|
2560
|
+
case 4:
|
|
2561
|
+
_state.sent();
|
|
2562
|
+
return [
|
|
2563
|
+
4,
|
|
2564
|
+
{
|
|
2565
|
+
type: BRAIN_EVENTS.STEP_STATUS,
|
|
2566
|
+
steps: steps.map(function(s) {
|
|
2567
|
+
var _s_serialized = s.serialized, patch = _s_serialized.patch, rest = _object_without_properties(_s_serialized, [
|
|
2568
|
+
"patch"
|
|
2569
|
+
]);
|
|
2570
|
+
return rest;
|
|
2571
|
+
}),
|
|
2572
|
+
options: options,
|
|
2573
|
+
brainRunId: brainRunId
|
|
2574
|
+
}
|
|
2575
|
+
];
|
|
2576
|
+
case 5:
|
|
2577
|
+
_state.sent();
|
|
2578
|
+
// Normalize result to array (handle single webhook case)
|
|
2579
|
+
webhooks = Array.isArray(result) ? result : [
|
|
2580
|
+
result
|
|
2581
|
+
];
|
|
2582
|
+
// Serialize webhooks (strip Zod schemas)
|
|
2583
|
+
serializedWaitFor = webhooks.map(function(registration) {
|
|
2584
|
+
return {
|
|
2585
|
+
slug: registration.slug,
|
|
2586
|
+
identifier: registration.identifier
|
|
2587
|
+
};
|
|
2588
|
+
});
|
|
2589
|
+
// Emit WEBHOOK event
|
|
2590
|
+
return [
|
|
2591
|
+
4,
|
|
2592
|
+
{
|
|
2593
|
+
type: BRAIN_EVENTS.WEBHOOK,
|
|
2594
|
+
waitFor: serializedWaitFor,
|
|
2595
|
+
options: this.options,
|
|
2596
|
+
brainRunId: this.brainRunId
|
|
2597
|
+
}
|
|
2598
|
+
];
|
|
2599
|
+
case 6:
|
|
2600
|
+
_state.sent();
|
|
2601
|
+
// Reset currentPage after wait consumes it (page is ephemeral)
|
|
2602
|
+
this.currentPage = undefined;
|
|
2603
|
+
return [
|
|
2604
|
+
2
|
|
2605
|
+
];
|
|
2606
|
+
}
|
|
2607
|
+
});
|
|
2608
|
+
}).call(this);
|
|
2609
|
+
}
|
|
2610
|
+
},
|
|
2611
|
+
{
|
|
2612
|
+
key: "executeGuard",
|
|
2613
|
+
value: function executeGuard(step, guard) {
|
|
2614
|
+
var _this, steps, options, brainRunId, predicateResult, skipStep;
|
|
2615
|
+
return _ts_generator(this, function(_state) {
|
|
2616
|
+
switch(_state.label){
|
|
2617
|
+
case 0:
|
|
2618
|
+
_this = this, steps = _this.steps, options = _this.options, brainRunId = _this.brainRunId;
|
|
2619
|
+
predicateResult = guard.predicate({
|
|
2620
|
+
state: this.currentState,
|
|
2621
|
+
options: this.options
|
|
2622
|
+
});
|
|
2623
|
+
// Emit STEP_START for the guard
|
|
2624
|
+
return [
|
|
2625
|
+
4,
|
|
2626
|
+
{
|
|
2627
|
+
type: BRAIN_EVENTS.STEP_START,
|
|
2628
|
+
status: STATUS.RUNNING,
|
|
2629
|
+
stepTitle: step.block.title,
|
|
2630
|
+
stepId: step.id,
|
|
2631
|
+
stepIndex: this.currentStepIndex,
|
|
2632
|
+
options: options,
|
|
2633
|
+
brainRunId: brainRunId
|
|
2634
|
+
}
|
|
2635
|
+
];
|
|
2636
|
+
case 1:
|
|
2637
|
+
_state.sent();
|
|
2638
|
+
step.withStatus(STATUS.RUNNING);
|
|
2639
|
+
return [
|
|
2640
|
+
4,
|
|
2641
|
+
{
|
|
2642
|
+
type: BRAIN_EVENTS.STEP_STATUS,
|
|
2643
|
+
steps: steps.map(function(s) {
|
|
2644
|
+
var _s_serialized = s.serialized, patch = _s_serialized.patch, rest = _object_without_properties(_s_serialized, [
|
|
2645
|
+
"patch"
|
|
2646
|
+
]);
|
|
2647
|
+
return rest;
|
|
2648
|
+
}),
|
|
2649
|
+
options: options,
|
|
2650
|
+
brainRunId: brainRunId
|
|
2651
|
+
}
|
|
2652
|
+
];
|
|
2653
|
+
case 2:
|
|
2654
|
+
_state.sent();
|
|
2655
|
+
// Complete the guard step (state unchanged, empty patch)
|
|
2656
|
+
return [
|
|
2657
|
+
5,
|
|
2658
|
+
_ts_values(this.completeStep(step, this.currentState))
|
|
2659
|
+
];
|
|
2660
|
+
case 3:
|
|
2661
|
+
_state.sent();
|
|
2662
|
+
return [
|
|
2663
|
+
4,
|
|
2664
|
+
{
|
|
2665
|
+
type: BRAIN_EVENTS.STEP_STATUS,
|
|
2666
|
+
steps: steps.map(function(s) {
|
|
2667
|
+
var _s_serialized = s.serialized, patch = _s_serialized.patch, rest = _object_without_properties(_s_serialized, [
|
|
2668
|
+
"patch"
|
|
2669
|
+
]);
|
|
2670
|
+
return rest;
|
|
2671
|
+
}),
|
|
2672
|
+
options: options,
|
|
2673
|
+
brainRunId: brainRunId
|
|
2674
|
+
}
|
|
2675
|
+
];
|
|
2676
|
+
case 4:
|
|
2677
|
+
_state.sent();
|
|
2678
|
+
this.currentStepIndex++;
|
|
2679
|
+
if (!!predicateResult) return [
|
|
2680
|
+
3,
|
|
2681
|
+
9
|
|
2682
|
+
];
|
|
2683
|
+
_state.label = 5;
|
|
2684
|
+
case 5:
|
|
2685
|
+
if (!(this.currentStepIndex < steps.length)) return [
|
|
2686
|
+
3,
|
|
2687
|
+
7
|
|
2688
|
+
];
|
|
2689
|
+
skipStep = steps[this.currentStepIndex];
|
|
2690
|
+
skipStep.withStatus(STATUS.HALTED);
|
|
2691
|
+
return [
|
|
2692
|
+
4,
|
|
2693
|
+
{
|
|
2694
|
+
type: BRAIN_EVENTS.STEP_COMPLETE,
|
|
2695
|
+
status: STATUS.RUNNING,
|
|
2696
|
+
stepTitle: skipStep.block.title,
|
|
2697
|
+
stepId: skipStep.id,
|
|
2698
|
+
patch: [],
|
|
2699
|
+
halted: true,
|
|
2700
|
+
options: options,
|
|
2701
|
+
brainRunId: brainRunId
|
|
2702
|
+
}
|
|
2703
|
+
];
|
|
2704
|
+
case 6:
|
|
2705
|
+
_state.sent();
|
|
2706
|
+
this.currentStepIndex++;
|
|
2707
|
+
return [
|
|
2708
|
+
3,
|
|
2709
|
+
5
|
|
2710
|
+
];
|
|
2711
|
+
case 7:
|
|
2712
|
+
return [
|
|
2713
|
+
4,
|
|
2714
|
+
{
|
|
2715
|
+
type: BRAIN_EVENTS.STEP_STATUS,
|
|
2716
|
+
steps: steps.map(function(s) {
|
|
2717
|
+
var _s_serialized = s.serialized, patch = _s_serialized.patch, rest = _object_without_properties(_s_serialized, [
|
|
2718
|
+
"patch"
|
|
2719
|
+
]);
|
|
2720
|
+
return rest;
|
|
2721
|
+
}),
|
|
2722
|
+
options: options,
|
|
2723
|
+
brainRunId: brainRunId
|
|
2724
|
+
}
|
|
2725
|
+
];
|
|
2726
|
+
case 8:
|
|
2727
|
+
_state.sent();
|
|
2728
|
+
_state.label = 9;
|
|
2729
|
+
case 9:
|
|
2730
|
+
return [
|
|
2731
|
+
2
|
|
2732
|
+
];
|
|
2733
|
+
}
|
|
2734
|
+
});
|
|
2735
|
+
}
|
|
2736
|
+
},
|
|
2171
2737
|
{
|
|
2172
2738
|
key: "completeStep",
|
|
2173
2739
|
value: function completeStep(step, prevState) {
|