@positronic/core 0.0.61 → 0.0.62
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 +33 -121
- package/dist/src/dsl/constants.js +4 -1
- package/dist/src/dsl/execution/event-stream.js +546 -89
- 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 +7 -4
- 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 +20 -1
- 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/execution/event-stream.d.ts +9 -0
- 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/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,8 @@ 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, "stopped", false);
|
|
472
503
|
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
504
|
// Check if this is a resume run or fresh start
|
|
474
505
|
var resumeParams = params;
|
|
@@ -491,10 +522,32 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
491
522
|
if (memoryProvider) {
|
|
492
523
|
this.scopedMemory = createScopedMemory(memoryProvider, title);
|
|
493
524
|
}
|
|
494
|
-
// Initialize steps -
|
|
495
|
-
this.steps =
|
|
496
|
-
|
|
497
|
-
|
|
525
|
+
// Initialize steps - track guard blocks by index
|
|
526
|
+
this.steps = [];
|
|
527
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
528
|
+
try {
|
|
529
|
+
for(var _iterator = blocks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
530
|
+
var block = _step.value;
|
|
531
|
+
if (block.type === 'guard') {
|
|
532
|
+
var guardBlock = block;
|
|
533
|
+
this.guards.set(this.steps.length, guardBlock);
|
|
534
|
+
}
|
|
535
|
+
this.steps.push(new Step(block));
|
|
536
|
+
}
|
|
537
|
+
} catch (err) {
|
|
538
|
+
_didIteratorError = true;
|
|
539
|
+
_iteratorError = err;
|
|
540
|
+
} finally{
|
|
541
|
+
try {
|
|
542
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
543
|
+
_iterator.return();
|
|
544
|
+
}
|
|
545
|
+
} finally{
|
|
546
|
+
if (_didIteratorError) {
|
|
547
|
+
throw _iteratorError;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
}
|
|
498
551
|
if (resumeContext) {
|
|
499
552
|
// Resume: use state and stepIndex directly from resumeContext
|
|
500
553
|
this.currentState = clone(resumeContext.state);
|
|
@@ -533,7 +586,7 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
533
586
|
key: "next",
|
|
534
587
|
value: function next() {
|
|
535
588
|
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;
|
|
589
|
+
var _this, steps, brainTitle, brainDescription, currentState, options, brainRunId, webhookResponse, signals, webhookSignal, deepest, signals1, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, signal, err, step, guard, err1, error, currentStep;
|
|
537
590
|
return _ts_generator(this, function(_state) {
|
|
538
591
|
switch(_state.label){
|
|
539
592
|
case 0:
|
|
@@ -542,9 +595,9 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
542
595
|
case 1:
|
|
543
596
|
_state.trys.push([
|
|
544
597
|
1,
|
|
545
|
-
|
|
598
|
+
31,
|
|
546
599
|
,
|
|
547
|
-
|
|
600
|
+
34
|
|
548
601
|
]);
|
|
549
602
|
if (!!this.resumeContext) return [
|
|
550
603
|
3,
|
|
@@ -664,7 +717,7 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
664
717
|
case 11:
|
|
665
718
|
if (!(this.currentStepIndex < steps.length)) return [
|
|
666
719
|
3,
|
|
667
|
-
|
|
720
|
+
29
|
|
668
721
|
];
|
|
669
722
|
if (!this.signalProvider) return [
|
|
670
723
|
3,
|
|
@@ -768,14 +821,31 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
768
821
|
];
|
|
769
822
|
case 22:
|
|
770
823
|
step = steps[this.currentStepIndex];
|
|
771
|
-
// Skip completed steps
|
|
772
|
-
if (step.serialized.status === STATUS.COMPLETE) {
|
|
824
|
+
// Skip completed or skipped steps
|
|
825
|
+
if (step.serialized.status === STATUS.COMPLETE || step.serialized.status === STATUS.HALTED) {
|
|
773
826
|
this.currentStepIndex++;
|
|
774
827
|
return [
|
|
775
828
|
3,
|
|
776
829
|
11
|
|
777
830
|
];
|
|
778
831
|
}
|
|
832
|
+
// Handle guard blocks
|
|
833
|
+
guard = this.guards.get(this.currentStepIndex);
|
|
834
|
+
if (!guard) return [
|
|
835
|
+
3,
|
|
836
|
+
24
|
|
837
|
+
];
|
|
838
|
+
return [
|
|
839
|
+
5,
|
|
840
|
+
_ts_values(_async_generator_delegate(_async_iterator(this.executeGuard(step, guard))))
|
|
841
|
+
];
|
|
842
|
+
case 23:
|
|
843
|
+
_state.sent();
|
|
844
|
+
return [
|
|
845
|
+
3,
|
|
846
|
+
11
|
|
847
|
+
];
|
|
848
|
+
case 24:
|
|
779
849
|
// Step start event
|
|
780
850
|
return [
|
|
781
851
|
4,
|
|
@@ -789,7 +859,7 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
789
859
|
brainRunId: brainRunId
|
|
790
860
|
}
|
|
791
861
|
];
|
|
792
|
-
case
|
|
862
|
+
case 25:
|
|
793
863
|
_state.sent();
|
|
794
864
|
step.withStatus(STATUS.RUNNING);
|
|
795
865
|
// Step Status Event to indicate that the step is running
|
|
@@ -807,7 +877,7 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
807
877
|
brainRunId: brainRunId
|
|
808
878
|
}
|
|
809
879
|
];
|
|
810
|
-
case
|
|
880
|
+
case 26:
|
|
811
881
|
_state.sent();
|
|
812
882
|
// Execute step and yield the STEP_COMPLETE event and
|
|
813
883
|
// all events from inner brains if any
|
|
@@ -815,8 +885,14 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
815
885
|
5,
|
|
816
886
|
_ts_values(_async_generator_delegate(_async_iterator(this.executeStep(step))))
|
|
817
887
|
];
|
|
818
|
-
case
|
|
888
|
+
case 27:
|
|
819
889
|
_state.sent();
|
|
890
|
+
// Backend requested a stop (e.g. batch chunk pause for DO restart)
|
|
891
|
+
if (this.stopped) {
|
|
892
|
+
return [
|
|
893
|
+
2
|
|
894
|
+
];
|
|
895
|
+
}
|
|
820
896
|
// Step Status Event
|
|
821
897
|
return [
|
|
822
898
|
4,
|
|
@@ -832,14 +908,14 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
832
908
|
brainRunId: brainRunId
|
|
833
909
|
}
|
|
834
910
|
];
|
|
835
|
-
case
|
|
911
|
+
case 28:
|
|
836
912
|
_state.sent();
|
|
837
913
|
this.currentStepIndex++;
|
|
838
914
|
return [
|
|
839
915
|
3,
|
|
840
916
|
11
|
|
841
917
|
];
|
|
842
|
-
case
|
|
918
|
+
case 29:
|
|
843
919
|
return [
|
|
844
920
|
4,
|
|
845
921
|
{
|
|
@@ -851,13 +927,13 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
851
927
|
options: options
|
|
852
928
|
}
|
|
853
929
|
];
|
|
854
|
-
case
|
|
930
|
+
case 30:
|
|
855
931
|
_state.sent();
|
|
856
932
|
return [
|
|
857
933
|
3,
|
|
858
|
-
|
|
934
|
+
34
|
|
859
935
|
];
|
|
860
|
-
case
|
|
936
|
+
case 31:
|
|
861
937
|
err1 = _state.sent();
|
|
862
938
|
error = err1;
|
|
863
939
|
currentStep = steps[this.currentStepIndex];
|
|
@@ -878,7 +954,7 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
878
954
|
options: options
|
|
879
955
|
}
|
|
880
956
|
];
|
|
881
|
-
case
|
|
957
|
+
case 32:
|
|
882
958
|
_state.sent();
|
|
883
959
|
// Step Status Event
|
|
884
960
|
return [
|
|
@@ -895,10 +971,10 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
895
971
|
brainRunId: brainRunId
|
|
896
972
|
}
|
|
897
973
|
];
|
|
898
|
-
case
|
|
974
|
+
case 33:
|
|
899
975
|
_state.sent();
|
|
900
976
|
throw error;
|
|
901
|
-
case
|
|
977
|
+
case 34:
|
|
902
978
|
return [
|
|
903
979
|
2
|
|
904
980
|
];
|
|
@@ -918,7 +994,7 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
918
994
|
block = step.block;
|
|
919
995
|
if (!(block.type === 'step')) return [
|
|
920
996
|
3,
|
|
921
|
-
|
|
997
|
+
4
|
|
922
998
|
];
|
|
923
999
|
stepBlock = block;
|
|
924
1000
|
if (!stepBlock.isUIStep) return [
|
|
@@ -935,9 +1011,23 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
935
1011
|
2
|
|
936
1012
|
];
|
|
937
1013
|
case 2:
|
|
1014
|
+
if (!stepBlock.batchConfig) return [
|
|
1015
|
+
3,
|
|
1016
|
+
4
|
|
1017
|
+
];
|
|
1018
|
+
return [
|
|
1019
|
+
5,
|
|
1020
|
+
_ts_values(_async_generator_delegate(_async_iterator(this.executeBatchPrompt(step))))
|
|
1021
|
+
];
|
|
1022
|
+
case 3:
|
|
1023
|
+
_state.sent();
|
|
1024
|
+
return [
|
|
1025
|
+
2
|
|
1026
|
+
];
|
|
1027
|
+
case 4:
|
|
938
1028
|
if (!(block.type === 'brain')) return [
|
|
939
1029
|
3,
|
|
940
|
-
|
|
1030
|
+
20
|
|
941
1031
|
];
|
|
942
1032
|
brainBlock = block;
|
|
943
1033
|
initialState = typeof brainBlock.initialState === 'function' ? brainBlock.initialState(this.currentState) : brainBlock.initialState;
|
|
@@ -965,25 +1055,25 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
965
1055
|
brainRunId: this.brainRunId
|
|
966
1056
|
});
|
|
967
1057
|
_iteratorAbruptCompletion = false, _didIteratorError = false;
|
|
968
|
-
_state.label =
|
|
969
|
-
case
|
|
1058
|
+
_state.label = 5;
|
|
1059
|
+
case 5:
|
|
970
1060
|
_state.trys.push([
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
1061
|
+
5,
|
|
1062
|
+
11,
|
|
1063
|
+
12,
|
|
1064
|
+
17
|
|
975
1065
|
]);
|
|
976
1066
|
_iterator = _async_iterator(innerRun);
|
|
977
|
-
_state.label =
|
|
978
|
-
case
|
|
1067
|
+
_state.label = 6;
|
|
1068
|
+
case 6:
|
|
979
1069
|
return [
|
|
980
1070
|
4,
|
|
981
1071
|
_await_async_generator(_iterator.next())
|
|
982
1072
|
];
|
|
983
|
-
case
|
|
1073
|
+
case 7:
|
|
984
1074
|
if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
|
|
985
1075
|
3,
|
|
986
|
-
|
|
1076
|
+
10
|
|
987
1077
|
];
|
|
988
1078
|
_value = _step.value;
|
|
989
1079
|
event = _value;
|
|
@@ -991,7 +1081,7 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
991
1081
|
4,
|
|
992
1082
|
event
|
|
993
1083
|
];
|
|
994
|
-
case
|
|
1084
|
+
case 8:
|
|
995
1085
|
_state.sent(); // Forward all inner brain events
|
|
996
1086
|
if (event.type === BRAIN_EVENTS.STEP_COMPLETE) {
|
|
997
1087
|
patches.push(event.patch);
|
|
@@ -1004,64 +1094,64 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
1004
1094
|
if (event.type === BRAIN_EVENTS.COMPLETE) {
|
|
1005
1095
|
return [
|
|
1006
1096
|
3,
|
|
1007
|
-
|
|
1097
|
+
10
|
|
1008
1098
|
];
|
|
1009
1099
|
}
|
|
1010
|
-
_state.label =
|
|
1011
|
-
case
|
|
1100
|
+
_state.label = 9;
|
|
1101
|
+
case 9:
|
|
1012
1102
|
_iteratorAbruptCompletion = false;
|
|
1013
1103
|
return [
|
|
1014
1104
|
3,
|
|
1015
|
-
|
|
1105
|
+
6
|
|
1016
1106
|
];
|
|
1017
|
-
case
|
|
1107
|
+
case 10:
|
|
1018
1108
|
return [
|
|
1019
1109
|
3,
|
|
1020
|
-
|
|
1110
|
+
17
|
|
1021
1111
|
];
|
|
1022
|
-
case
|
|
1112
|
+
case 11:
|
|
1023
1113
|
err = _state.sent();
|
|
1024
1114
|
_didIteratorError = true;
|
|
1025
1115
|
_iteratorError = err;
|
|
1026
1116
|
return [
|
|
1027
1117
|
3,
|
|
1028
|
-
|
|
1118
|
+
17
|
|
1029
1119
|
];
|
|
1030
|
-
case
|
|
1120
|
+
case 12:
|
|
1031
1121
|
_state.trys.push([
|
|
1032
|
-
|
|
1122
|
+
12,
|
|
1033
1123
|
,
|
|
1034
|
-
|
|
1035
|
-
|
|
1124
|
+
15,
|
|
1125
|
+
16
|
|
1036
1126
|
]);
|
|
1037
1127
|
if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
|
|
1038
1128
|
3,
|
|
1039
|
-
|
|
1129
|
+
14
|
|
1040
1130
|
];
|
|
1041
1131
|
return [
|
|
1042
1132
|
4,
|
|
1043
1133
|
_await_async_generator(_iterator.return())
|
|
1044
1134
|
];
|
|
1045
|
-
case
|
|
1135
|
+
case 13:
|
|
1046
1136
|
_state.sent();
|
|
1047
|
-
_state.label =
|
|
1048
|
-
case
|
|
1137
|
+
_state.label = 14;
|
|
1138
|
+
case 14:
|
|
1049
1139
|
return [
|
|
1050
1140
|
3,
|
|
1051
|
-
|
|
1141
|
+
16
|
|
1052
1142
|
];
|
|
1053
|
-
case
|
|
1143
|
+
case 15:
|
|
1054
1144
|
if (_didIteratorError) {
|
|
1055
1145
|
throw _iteratorError;
|
|
1056
1146
|
}
|
|
1057
1147
|
return [
|
|
1058
1148
|
7
|
|
1059
1149
|
];
|
|
1060
|
-
case
|
|
1150
|
+
case 16:
|
|
1061
1151
|
return [
|
|
1062
1152
|
7
|
|
1063
1153
|
];
|
|
1064
|
-
case
|
|
1154
|
+
case 17:
|
|
1065
1155
|
// If inner brain paused for webhook, don't complete the outer brain step
|
|
1066
1156
|
// The outer brain should also pause
|
|
1067
1157
|
if (innerBrainPaused) {
|
|
@@ -1081,52 +1171,52 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
1081
1171
|
4,
|
|
1082
1172
|
_await_async_generator(brainBlock.action(this.currentState, innerState, this.services))
|
|
1083
1173
|
];
|
|
1084
|
-
case
|
|
1174
|
+
case 18:
|
|
1085
1175
|
_.currentState = _state.sent();
|
|
1086
1176
|
return [
|
|
1087
1177
|
5,
|
|
1088
1178
|
_ts_values(_async_generator_delegate(_async_iterator(this.completeStep(step, prevState))))
|
|
1089
1179
|
];
|
|
1090
|
-
case
|
|
1180
|
+
case 19:
|
|
1091
1181
|
_state.sent();
|
|
1092
1182
|
return [
|
|
1093
1183
|
3,
|
|
1094
|
-
|
|
1184
|
+
35
|
|
1095
1185
|
];
|
|
1096
|
-
case
|
|
1186
|
+
case 20:
|
|
1097
1187
|
if (!(block.type === 'agent')) return [
|
|
1098
1188
|
3,
|
|
1099
|
-
|
|
1189
|
+
22
|
|
1100
1190
|
];
|
|
1101
1191
|
return [
|
|
1102
1192
|
5,
|
|
1103
1193
|
_ts_values(_async_generator_delegate(_async_iterator(this.executeAgent(step))))
|
|
1104
1194
|
];
|
|
1105
|
-
case
|
|
1195
|
+
case 21:
|
|
1106
1196
|
_state.sent();
|
|
1107
1197
|
return [
|
|
1108
1198
|
3,
|
|
1109
|
-
|
|
1199
|
+
35
|
|
1110
1200
|
];
|
|
1111
|
-
case
|
|
1201
|
+
case 22:
|
|
1112
1202
|
// Get previous state before action
|
|
1113
1203
|
prevState1 = this.currentState;
|
|
1114
1204
|
stepBlock1 = block;
|
|
1115
1205
|
// Execute step with automatic retry on failure
|
|
1116
1206
|
retries = 0;
|
|
1117
|
-
_state.label =
|
|
1118
|
-
case
|
|
1207
|
+
_state.label = 23;
|
|
1208
|
+
case 23:
|
|
1119
1209
|
if (!true) return [
|
|
1120
1210
|
3,
|
|
1121
|
-
|
|
1211
|
+
31
|
|
1122
1212
|
];
|
|
1123
|
-
_state.label =
|
|
1124
|
-
case
|
|
1213
|
+
_state.label = 24;
|
|
1214
|
+
case 24:
|
|
1125
1215
|
_state.trys.push([
|
|
1126
|
-
22,
|
|
1127
1216
|
24,
|
|
1217
|
+
26,
|
|
1128
1218
|
,
|
|
1129
|
-
|
|
1219
|
+
30
|
|
1130
1220
|
]);
|
|
1131
1221
|
actionPromise = Promise.resolve(stepBlock1.action(_object_spread({
|
|
1132
1222
|
state: this.currentState,
|
|
@@ -1143,17 +1233,17 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
1143
1233
|
4,
|
|
1144
1234
|
_await_async_generator(actionPromise)
|
|
1145
1235
|
];
|
|
1146
|
-
case
|
|
1236
|
+
case 25:
|
|
1147
1237
|
result = _state.sent();
|
|
1148
1238
|
return [
|
|
1149
1239
|
3,
|
|
1150
|
-
|
|
1240
|
+
31
|
|
1151
1241
|
]; // Success
|
|
1152
|
-
case
|
|
1242
|
+
case 26:
|
|
1153
1243
|
error = _state.sent();
|
|
1154
1244
|
if (!(retries < MAX_RETRIES)) return [
|
|
1155
1245
|
3,
|
|
1156
|
-
|
|
1246
|
+
28
|
|
1157
1247
|
];
|
|
1158
1248
|
retries++;
|
|
1159
1249
|
return [
|
|
@@ -1172,25 +1262,25 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
1172
1262
|
brainRunId: this.brainRunId
|
|
1173
1263
|
}
|
|
1174
1264
|
];
|
|
1175
|
-
case
|
|
1265
|
+
case 27:
|
|
1176
1266
|
_state.sent();
|
|
1177
1267
|
return [
|
|
1178
1268
|
3,
|
|
1179
|
-
|
|
1269
|
+
29
|
|
1180
1270
|
];
|
|
1181
|
-
case
|
|
1271
|
+
case 28:
|
|
1182
1272
|
throw error;
|
|
1183
|
-
case
|
|
1273
|
+
case 29:
|
|
1184
1274
|
return [
|
|
1185
1275
|
3,
|
|
1186
|
-
|
|
1276
|
+
30
|
|
1187
1277
|
];
|
|
1188
|
-
case
|
|
1278
|
+
case 30:
|
|
1189
1279
|
return [
|
|
1190
1280
|
3,
|
|
1191
|
-
|
|
1281
|
+
23
|
|
1192
1282
|
];
|
|
1193
|
-
case
|
|
1283
|
+
case 31:
|
|
1194
1284
|
// Extract state from result (handles waitFor and promptResponse cases)
|
|
1195
1285
|
if (result && (typeof result === "undefined" ? "undefined" : _type_of(result)) === 'object' && ('waitFor' in result || 'promptResponse' in result)) {
|
|
1196
1286
|
this.currentState = result.state;
|
|
@@ -1201,11 +1291,11 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
1201
1291
|
5,
|
|
1202
1292
|
_ts_values(_async_generator_delegate(_async_iterator(this.completeStep(step, prevState1))))
|
|
1203
1293
|
];
|
|
1204
|
-
case
|
|
1294
|
+
case 32:
|
|
1205
1295
|
_state.sent();
|
|
1206
1296
|
if (!(result && (typeof result === "undefined" ? "undefined" : _type_of(result)) === 'object' && 'waitFor' in result)) return [
|
|
1207
1297
|
3,
|
|
1208
|
-
|
|
1298
|
+
34
|
|
1209
1299
|
];
|
|
1210
1300
|
// Serialize webhook registrations (remove Zod schemas for event serializability)
|
|
1211
1301
|
serializedWaitFor = result.waitFor.map(function(registration) {
|
|
@@ -1223,18 +1313,18 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
1223
1313
|
brainRunId: this.brainRunId
|
|
1224
1314
|
}
|
|
1225
1315
|
];
|
|
1226
|
-
case
|
|
1316
|
+
case 33:
|
|
1227
1317
|
_state.sent();
|
|
1228
|
-
_state.label =
|
|
1229
|
-
case
|
|
1318
|
+
_state.label = 34;
|
|
1319
|
+
case 34:
|
|
1230
1320
|
// Handle promptResponse - set currentResponse for next step
|
|
1231
1321
|
if (result && (typeof result === "undefined" ? "undefined" : _type_of(result)) === 'object' && 'promptResponse' in result) {
|
|
1232
1322
|
this.currentResponse = result.promptResponse;
|
|
1233
1323
|
}
|
|
1234
1324
|
// Reset currentPage after step consumes it (page is ephemeral)
|
|
1235
1325
|
this.currentPage = undefined;
|
|
1236
|
-
_state.label =
|
|
1237
|
-
case
|
|
1326
|
+
_state.label = 35;
|
|
1327
|
+
case 35:
|
|
1238
1328
|
return [
|
|
1239
1329
|
2
|
|
1240
1330
|
];
|
|
@@ -1675,7 +1765,8 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
1675
1765
|
system: systemPrompt,
|
|
1676
1766
|
messages: initialMessages,
|
|
1677
1767
|
responseMessages: responseMessages,
|
|
1678
|
-
tools: toolsForClient
|
|
1768
|
+
tools: toolsForClient,
|
|
1769
|
+
toolChoice: config.toolChoice
|
|
1679
1770
|
}))
|
|
1680
1771
|
];
|
|
1681
1772
|
case 30:
|
|
@@ -2070,6 +2161,246 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
2070
2161
|
}).call(this);
|
|
2071
2162
|
}
|
|
2072
2163
|
},
|
|
2164
|
+
{
|
|
2165
|
+
key: "executeBatchPrompt",
|
|
2166
|
+
value: /**
|
|
2167
|
+
* Execute a batch prompt step in chunks, yielding one BATCH_CHUNK_COMPLETE
|
|
2168
|
+
* event per chunk. Between chunks, checks for PAUSE/KILL signals so
|
|
2169
|
+
* Cloudflare backends can restart the DO to reclaim memory.
|
|
2170
|
+
*/ function executeBatchPrompt(step) {
|
|
2171
|
+
return _wrap_async_generator(function() {
|
|
2172
|
+
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;
|
|
2173
|
+
return _ts_generator(this, function(_state) {
|
|
2174
|
+
switch(_state.label){
|
|
2175
|
+
case 0:
|
|
2176
|
+
_this = this;
|
|
2177
|
+
block = step.block;
|
|
2178
|
+
batchConfig = block.batchConfig;
|
|
2179
|
+
prevState = this.currentState;
|
|
2180
|
+
client = (_batchConfig_client = batchConfig.client) !== null && _batchConfig_client !== void 0 ? _batchConfig_client : this.client;
|
|
2181
|
+
items = batchConfig.over(this.currentState);
|
|
2182
|
+
totalItems = items.length;
|
|
2183
|
+
chunkSize = (_batchConfig_chunkSize = batchConfig.chunkSize) !== null && _batchConfig_chunkSize !== void 0 ? _batchConfig_chunkSize : 10;
|
|
2184
|
+
// Resume support: pick up from where we left off
|
|
2185
|
+
batchProgress = (_this_resumeContext = this.resumeContext) === null || _this_resumeContext === void 0 ? void 0 : _this_resumeContext.batchProgress;
|
|
2186
|
+
startIndex = (_batchProgress_processedCount = batchProgress === null || batchProgress === void 0 ? void 0 : batchProgress.processedCount) !== null && _batchProgress_processedCount !== void 0 ? _batchProgress_processedCount : 0;
|
|
2187
|
+
results = (batchProgress === null || batchProgress === void 0 ? void 0 : batchProgress.accumulatedResults) ? _to_consumable_array(batchProgress.accumulatedResults) : new Array(totalItems);
|
|
2188
|
+
// Clear resumeContext after consuming batchProgress
|
|
2189
|
+
if (batchProgress) {
|
|
2190
|
+
this.resumeContext = undefined;
|
|
2191
|
+
}
|
|
2192
|
+
chunkStart = startIndex;
|
|
2193
|
+
_state.label = 1;
|
|
2194
|
+
case 1:
|
|
2195
|
+
if (!(chunkStart < totalItems)) return [
|
|
2196
|
+
3,
|
|
2197
|
+
15
|
|
2198
|
+
];
|
|
2199
|
+
if (!this.signalProvider) return [
|
|
2200
|
+
3,
|
|
2201
|
+
11
|
|
2202
|
+
];
|
|
2203
|
+
return [
|
|
2204
|
+
4,
|
|
2205
|
+
_await_async_generator(this.signalProvider.getSignals('CONTROL'))
|
|
2206
|
+
];
|
|
2207
|
+
case 2:
|
|
2208
|
+
signals = _state.sent();
|
|
2209
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
2210
|
+
_state.label = 3;
|
|
2211
|
+
case 3:
|
|
2212
|
+
_state.trys.push([
|
|
2213
|
+
3,
|
|
2214
|
+
9,
|
|
2215
|
+
10,
|
|
2216
|
+
11
|
|
2217
|
+
]);
|
|
2218
|
+
_iterator = signals[Symbol.iterator]();
|
|
2219
|
+
_state.label = 4;
|
|
2220
|
+
case 4:
|
|
2221
|
+
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
|
|
2222
|
+
3,
|
|
2223
|
+
8
|
|
2224
|
+
];
|
|
2225
|
+
signal = _step.value;
|
|
2226
|
+
if (!(signal.type === 'KILL')) return [
|
|
2227
|
+
3,
|
|
2228
|
+
6
|
|
2229
|
+
];
|
|
2230
|
+
return [
|
|
2231
|
+
4,
|
|
2232
|
+
{
|
|
2233
|
+
type: BRAIN_EVENTS.CANCELLED,
|
|
2234
|
+
status: STATUS.CANCELLED,
|
|
2235
|
+
brainTitle: this.title,
|
|
2236
|
+
brainDescription: this.description,
|
|
2237
|
+
brainRunId: this.brainRunId,
|
|
2238
|
+
options: (_this_options = this.options) !== null && _this_options !== void 0 ? _this_options : {}
|
|
2239
|
+
}
|
|
2240
|
+
];
|
|
2241
|
+
case 5:
|
|
2242
|
+
_state.sent();
|
|
2243
|
+
return [
|
|
2244
|
+
2
|
|
2245
|
+
];
|
|
2246
|
+
case 6:
|
|
2247
|
+
if (signal.type === 'PAUSE') {
|
|
2248
|
+
// Don't yield PAUSED - pausing between batch chunks is a backend
|
|
2249
|
+
// implementation detail (e.g. Cloudflare DO restart for memory).
|
|
2250
|
+
// Just stop execution silently; the backend handles resume.
|
|
2251
|
+
this.stopped = true;
|
|
2252
|
+
return [
|
|
2253
|
+
2
|
|
2254
|
+
];
|
|
2255
|
+
}
|
|
2256
|
+
_state.label = 7;
|
|
2257
|
+
case 7:
|
|
2258
|
+
_iteratorNormalCompletion = true;
|
|
2259
|
+
return [
|
|
2260
|
+
3,
|
|
2261
|
+
4
|
|
2262
|
+
];
|
|
2263
|
+
case 8:
|
|
2264
|
+
return [
|
|
2265
|
+
3,
|
|
2266
|
+
11
|
|
2267
|
+
];
|
|
2268
|
+
case 9:
|
|
2269
|
+
err = _state.sent();
|
|
2270
|
+
_didIteratorError = true;
|
|
2271
|
+
_iteratorError = err;
|
|
2272
|
+
return [
|
|
2273
|
+
3,
|
|
2274
|
+
11
|
|
2275
|
+
];
|
|
2276
|
+
case 10:
|
|
2277
|
+
try {
|
|
2278
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
2279
|
+
_iterator.return();
|
|
2280
|
+
}
|
|
2281
|
+
} finally{
|
|
2282
|
+
if (_didIteratorError) {
|
|
2283
|
+
throw _iteratorError;
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2286
|
+
return [
|
|
2287
|
+
7
|
|
2288
|
+
];
|
|
2289
|
+
case 11:
|
|
2290
|
+
chunkEnd = Math.min(chunkStart + chunkSize, totalItems);
|
|
2291
|
+
chunk = items.slice(chunkStart, chunkEnd);
|
|
2292
|
+
return [
|
|
2293
|
+
4,
|
|
2294
|
+
_await_async_generator(Promise.all(chunk.map(function(item) {
|
|
2295
|
+
return _async_to_generator(function() {
|
|
2296
|
+
var promptText, output, error, fallback;
|
|
2297
|
+
return _ts_generator(this, function(_state) {
|
|
2298
|
+
switch(_state.label){
|
|
2299
|
+
case 0:
|
|
2300
|
+
_state.trys.push([
|
|
2301
|
+
0,
|
|
2302
|
+
3,
|
|
2303
|
+
,
|
|
2304
|
+
4
|
|
2305
|
+
]);
|
|
2306
|
+
return [
|
|
2307
|
+
4,
|
|
2308
|
+
batchConfig.template(item, this.resources)
|
|
2309
|
+
];
|
|
2310
|
+
case 1:
|
|
2311
|
+
promptText = _state.sent();
|
|
2312
|
+
return [
|
|
2313
|
+
4,
|
|
2314
|
+
client.generateObject(_object_spread({
|
|
2315
|
+
schema: batchConfig.schema,
|
|
2316
|
+
schemaName: batchConfig.schemaName,
|
|
2317
|
+
prompt: promptText
|
|
2318
|
+
}, batchConfig.maxRetries !== undefined && {
|
|
2319
|
+
maxRetries: batchConfig.maxRetries
|
|
2320
|
+
}))
|
|
2321
|
+
];
|
|
2322
|
+
case 2:
|
|
2323
|
+
output = _state.sent();
|
|
2324
|
+
return [
|
|
2325
|
+
2,
|
|
2326
|
+
[
|
|
2327
|
+
item,
|
|
2328
|
+
output
|
|
2329
|
+
]
|
|
2330
|
+
];
|
|
2331
|
+
case 3:
|
|
2332
|
+
error = _state.sent();
|
|
2333
|
+
if (batchConfig.error) {
|
|
2334
|
+
fallback = batchConfig.error(item, error);
|
|
2335
|
+
return [
|
|
2336
|
+
2,
|
|
2337
|
+
fallback !== null ? [
|
|
2338
|
+
item,
|
|
2339
|
+
fallback
|
|
2340
|
+
] : undefined
|
|
2341
|
+
];
|
|
2342
|
+
}
|
|
2343
|
+
throw error;
|
|
2344
|
+
case 4:
|
|
2345
|
+
return [
|
|
2346
|
+
2
|
|
2347
|
+
];
|
|
2348
|
+
}
|
|
2349
|
+
});
|
|
2350
|
+
}).call(_this);
|
|
2351
|
+
})))
|
|
2352
|
+
];
|
|
2353
|
+
case 12:
|
|
2354
|
+
chunkResults = _state.sent();
|
|
2355
|
+
// Store chunk results at correct indices
|
|
2356
|
+
for(i = 0; i < chunkResults.length; i++){
|
|
2357
|
+
results[chunkStart + i] = chunkResults[i];
|
|
2358
|
+
}
|
|
2359
|
+
// Yield ONE event per chunk
|
|
2360
|
+
return [
|
|
2361
|
+
4,
|
|
2362
|
+
{
|
|
2363
|
+
type: BRAIN_EVENTS.BATCH_CHUNK_COMPLETE,
|
|
2364
|
+
stepTitle: step.block.title,
|
|
2365
|
+
stepId: step.id,
|
|
2366
|
+
chunkStartIndex: chunkStart,
|
|
2367
|
+
processedCount: chunkEnd,
|
|
2368
|
+
totalItems: totalItems,
|
|
2369
|
+
chunkResults: chunkResults,
|
|
2370
|
+
schemaName: batchConfig.schemaName,
|
|
2371
|
+
options: (_this_options1 = this.options) !== null && _this_options1 !== void 0 ? _this_options1 : {},
|
|
2372
|
+
brainRunId: this.brainRunId
|
|
2373
|
+
}
|
|
2374
|
+
];
|
|
2375
|
+
case 13:
|
|
2376
|
+
_state.sent();
|
|
2377
|
+
_state.label = 14;
|
|
2378
|
+
case 14:
|
|
2379
|
+
chunkStart += chunkSize;
|
|
2380
|
+
return [
|
|
2381
|
+
3,
|
|
2382
|
+
1
|
|
2383
|
+
];
|
|
2384
|
+
case 15:
|
|
2385
|
+
// All chunks done - update state and complete step
|
|
2386
|
+
finalResults = results.filter(function(r) {
|
|
2387
|
+
return r != null;
|
|
2388
|
+
});
|
|
2389
|
+
this.currentState = _object_spread_props(_object_spread({}, this.currentState), _define_property({}, batchConfig.schemaName, finalResults));
|
|
2390
|
+
return [
|
|
2391
|
+
5,
|
|
2392
|
+
_ts_values(_async_generator_delegate(_async_iterator(this.completeStep(step, prevState))))
|
|
2393
|
+
];
|
|
2394
|
+
case 16:
|
|
2395
|
+
_state.sent();
|
|
2396
|
+
return [
|
|
2397
|
+
2
|
|
2398
|
+
];
|
|
2399
|
+
}
|
|
2400
|
+
});
|
|
2401
|
+
}).call(this);
|
|
2402
|
+
}
|
|
2403
|
+
},
|
|
2073
2404
|
{
|
|
2074
2405
|
key: "executeUIStep",
|
|
2075
2406
|
value: /**
|
|
@@ -2168,6 +2499,132 @@ export var BrainEventStream = /*#__PURE__*/ function() {
|
|
|
2168
2499
|
}).call(this);
|
|
2169
2500
|
}
|
|
2170
2501
|
},
|
|
2502
|
+
{
|
|
2503
|
+
key: "executeGuard",
|
|
2504
|
+
value: function executeGuard(step, guard) {
|
|
2505
|
+
var _this, steps, options, brainRunId, predicateResult, skipStep;
|
|
2506
|
+
return _ts_generator(this, function(_state) {
|
|
2507
|
+
switch(_state.label){
|
|
2508
|
+
case 0:
|
|
2509
|
+
_this = this, steps = _this.steps, options = _this.options, brainRunId = _this.brainRunId;
|
|
2510
|
+
predicateResult = guard.predicate({
|
|
2511
|
+
state: this.currentState,
|
|
2512
|
+
options: this.options
|
|
2513
|
+
});
|
|
2514
|
+
// Emit STEP_START for the guard
|
|
2515
|
+
return [
|
|
2516
|
+
4,
|
|
2517
|
+
{
|
|
2518
|
+
type: BRAIN_EVENTS.STEP_START,
|
|
2519
|
+
status: STATUS.RUNNING,
|
|
2520
|
+
stepTitle: step.block.title,
|
|
2521
|
+
stepId: step.id,
|
|
2522
|
+
stepIndex: this.currentStepIndex,
|
|
2523
|
+
options: options,
|
|
2524
|
+
brainRunId: brainRunId
|
|
2525
|
+
}
|
|
2526
|
+
];
|
|
2527
|
+
case 1:
|
|
2528
|
+
_state.sent();
|
|
2529
|
+
step.withStatus(STATUS.RUNNING);
|
|
2530
|
+
return [
|
|
2531
|
+
4,
|
|
2532
|
+
{
|
|
2533
|
+
type: BRAIN_EVENTS.STEP_STATUS,
|
|
2534
|
+
steps: steps.map(function(s) {
|
|
2535
|
+
var _s_serialized = s.serialized, patch = _s_serialized.patch, rest = _object_without_properties(_s_serialized, [
|
|
2536
|
+
"patch"
|
|
2537
|
+
]);
|
|
2538
|
+
return rest;
|
|
2539
|
+
}),
|
|
2540
|
+
options: options,
|
|
2541
|
+
brainRunId: brainRunId
|
|
2542
|
+
}
|
|
2543
|
+
];
|
|
2544
|
+
case 2:
|
|
2545
|
+
_state.sent();
|
|
2546
|
+
// Complete the guard step (state unchanged, empty patch)
|
|
2547
|
+
return [
|
|
2548
|
+
5,
|
|
2549
|
+
_ts_values(this.completeStep(step, this.currentState))
|
|
2550
|
+
];
|
|
2551
|
+
case 3:
|
|
2552
|
+
_state.sent();
|
|
2553
|
+
return [
|
|
2554
|
+
4,
|
|
2555
|
+
{
|
|
2556
|
+
type: BRAIN_EVENTS.STEP_STATUS,
|
|
2557
|
+
steps: steps.map(function(s) {
|
|
2558
|
+
var _s_serialized = s.serialized, patch = _s_serialized.patch, rest = _object_without_properties(_s_serialized, [
|
|
2559
|
+
"patch"
|
|
2560
|
+
]);
|
|
2561
|
+
return rest;
|
|
2562
|
+
}),
|
|
2563
|
+
options: options,
|
|
2564
|
+
brainRunId: brainRunId
|
|
2565
|
+
}
|
|
2566
|
+
];
|
|
2567
|
+
case 4:
|
|
2568
|
+
_state.sent();
|
|
2569
|
+
this.currentStepIndex++;
|
|
2570
|
+
if (!!predicateResult) return [
|
|
2571
|
+
3,
|
|
2572
|
+
9
|
|
2573
|
+
];
|
|
2574
|
+
_state.label = 5;
|
|
2575
|
+
case 5:
|
|
2576
|
+
if (!(this.currentStepIndex < steps.length)) return [
|
|
2577
|
+
3,
|
|
2578
|
+
7
|
|
2579
|
+
];
|
|
2580
|
+
skipStep = steps[this.currentStepIndex];
|
|
2581
|
+
skipStep.withStatus(STATUS.HALTED);
|
|
2582
|
+
return [
|
|
2583
|
+
4,
|
|
2584
|
+
{
|
|
2585
|
+
type: BRAIN_EVENTS.STEP_COMPLETE,
|
|
2586
|
+
status: STATUS.RUNNING,
|
|
2587
|
+
stepTitle: skipStep.block.title,
|
|
2588
|
+
stepId: skipStep.id,
|
|
2589
|
+
patch: [],
|
|
2590
|
+
halted: true,
|
|
2591
|
+
options: options,
|
|
2592
|
+
brainRunId: brainRunId
|
|
2593
|
+
}
|
|
2594
|
+
];
|
|
2595
|
+
case 6:
|
|
2596
|
+
_state.sent();
|
|
2597
|
+
this.currentStepIndex++;
|
|
2598
|
+
return [
|
|
2599
|
+
3,
|
|
2600
|
+
5
|
|
2601
|
+
];
|
|
2602
|
+
case 7:
|
|
2603
|
+
return [
|
|
2604
|
+
4,
|
|
2605
|
+
{
|
|
2606
|
+
type: BRAIN_EVENTS.STEP_STATUS,
|
|
2607
|
+
steps: steps.map(function(s) {
|
|
2608
|
+
var _s_serialized = s.serialized, patch = _s_serialized.patch, rest = _object_without_properties(_s_serialized, [
|
|
2609
|
+
"patch"
|
|
2610
|
+
]);
|
|
2611
|
+
return rest;
|
|
2612
|
+
}),
|
|
2613
|
+
options: options,
|
|
2614
|
+
brainRunId: brainRunId
|
|
2615
|
+
}
|
|
2616
|
+
];
|
|
2617
|
+
case 8:
|
|
2618
|
+
_state.sent();
|
|
2619
|
+
_state.label = 9;
|
|
2620
|
+
case 9:
|
|
2621
|
+
return [
|
|
2622
|
+
2
|
|
2623
|
+
];
|
|
2624
|
+
}
|
|
2625
|
+
});
|
|
2626
|
+
}
|
|
2627
|
+
},
|
|
2171
2628
|
{
|
|
2172
2629
|
key: "completeStep",
|
|
2173
2630
|
value: function completeStep(step, prevState) {
|