@positronic/cloudflare 0.0.44 → 0.0.46
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.
|
@@ -6,6 +6,9 @@ function _array_like_to_array(arr, len) {
|
|
|
6
6
|
function _array_with_holes(arr) {
|
|
7
7
|
if (Array.isArray(arr)) return arr;
|
|
8
8
|
}
|
|
9
|
+
function _array_without_holes(arr) {
|
|
10
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
11
|
+
}
|
|
9
12
|
function _assert_this_initialized(self) {
|
|
10
13
|
if (self === void 0) {
|
|
11
14
|
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
@@ -96,6 +99,9 @@ function _inherits(subClass, superClass) {
|
|
|
96
99
|
});
|
|
97
100
|
if (superClass) _set_prototype_of(subClass, superClass);
|
|
98
101
|
}
|
|
102
|
+
function _iterable_to_array(iter) {
|
|
103
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
104
|
+
}
|
|
99
105
|
function _iterable_to_array_limit(arr, i) {
|
|
100
106
|
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
101
107
|
if (_i == null) return;
|
|
@@ -123,6 +129,9 @@ function _iterable_to_array_limit(arr, i) {
|
|
|
123
129
|
function _non_iterable_rest() {
|
|
124
130
|
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
125
131
|
}
|
|
132
|
+
function _non_iterable_spread() {
|
|
133
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
134
|
+
}
|
|
126
135
|
function _object_spread(target) {
|
|
127
136
|
for(var i = 1; i < arguments.length; i++){
|
|
128
137
|
var source = arguments[i] != null ? arguments[i] : {};
|
|
@@ -178,6 +187,9 @@ function _set_prototype_of(o, p) {
|
|
|
178
187
|
function _sliced_to_array(arr, i) {
|
|
179
188
|
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
180
189
|
}
|
|
190
|
+
function _to_consumable_array(arr) {
|
|
191
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
192
|
+
}
|
|
181
193
|
function _type_of(obj) {
|
|
182
194
|
"@swc/helpers - typeof";
|
|
183
195
|
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
@@ -825,7 +837,7 @@ export var BrainRunnerDO = /*#__PURE__*/ function(DurableObject) {
|
|
|
825
837
|
key: "resume",
|
|
826
838
|
value: function resume(brainRunId, webhookResponse) {
|
|
827
839
|
return _async_to_generator(function() {
|
|
828
|
-
var _this, sql, startEventResult, startEvent, brainTitle, initialState, resolution, brainToRun,
|
|
840
|
+
var _this, sql, startEventResult, startEvent, brainTitle, initialState, resolution, brainToRun, allEventsResult, initialCompletedSteps, brainStack, pendingBrainStep, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, row, event, parentBrain, step, completedBrain, parentBrain1, parentStep, _initialCompletedSteps, outerBrain, innerBrain, parentBrain2, parentStep1, loopEventsResult, loopEvents, sqliteAdapter, eventStreamAdapter, monitorDOStub, monitorAdapter, scheduleAdapter, webhookAdapter, pageAdapter, env, pagesService, r2Resources, runnerWithResources;
|
|
829
841
|
return _ts_generator(this, function(_state) {
|
|
830
842
|
switch(_state.label){
|
|
831
843
|
case 0:
|
|
@@ -834,8 +846,9 @@ export var BrainRunnerDO = /*#__PURE__*/ function(DurableObject) {
|
|
|
834
846
|
if (!manifest) {
|
|
835
847
|
throw new Error('Runtime manifest not initialized');
|
|
836
848
|
}
|
|
837
|
-
// Get the initial state and brain title by loading the START or RESTART event
|
|
838
|
-
|
|
849
|
+
// Get the initial state and brain title by loading the FIRST START or RESTART event
|
|
850
|
+
// (the outer brain's event, not an inner brain's)
|
|
851
|
+
startEventResult = sql.exec("SELECT serialized_event FROM brain_events WHERE event_type IN (?, ?) ORDER BY event_id ASC LIMIT 1", BRAIN_EVENTS.START, BRAIN_EVENTS.RESTART).toArray();
|
|
839
852
|
if (startEventResult.length === 0) {
|
|
840
853
|
throw new Error("No START or RESTART event found for brain run ".concat(brainRunId));
|
|
841
854
|
}
|
|
@@ -859,17 +872,114 @@ export var BrainRunnerDO = /*#__PURE__*/ function(DurableObject) {
|
|
|
859
872
|
if (!brainToRun) {
|
|
860
873
|
throw new Error("Brain ".concat(brainTitle, " resolved but brain object is missing"));
|
|
861
874
|
}
|
|
862
|
-
// Load
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
875
|
+
// Load all events to build nested initialCompletedSteps
|
|
876
|
+
// We need START, STEP_START, STEP_COMPLETE events to track brain nesting
|
|
877
|
+
allEventsResult = sql.exec("SELECT serialized_event, event_type FROM brain_events\n WHERE event_type IN (?, ?, ?, ?, ?)\n ORDER BY event_id ASC", BRAIN_EVENTS.START, BRAIN_EVENTS.RESTART, BRAIN_EVENTS.STEP_START, BRAIN_EVENTS.STEP_COMPLETE, BRAIN_EVENTS.COMPLETE).toArray();
|
|
878
|
+
// Build nested initialCompletedSteps by tracking brain levels
|
|
879
|
+
initialCompletedSteps = [];
|
|
880
|
+
brainStack = [];
|
|
881
|
+
pendingBrainStep = null;
|
|
882
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
883
|
+
try {
|
|
884
|
+
for(_iterator = allEventsResult[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
885
|
+
row = _step.value;
|
|
886
|
+
event = JSON.parse(row.serialized_event);
|
|
887
|
+
if (row.event_type === BRAIN_EVENTS.START || row.event_type === BRAIN_EVENTS.RESTART) {
|
|
888
|
+
// If we have a pending brain step (step that started an inner brain),
|
|
889
|
+
// add a placeholder for it before pushing the inner brain
|
|
890
|
+
if (pendingBrainStep && brainStack.length > 0) {
|
|
891
|
+
parentBrain = brainStack[brainStack.length - 1];
|
|
892
|
+
parentBrain.steps.push({
|
|
893
|
+
id: pendingBrainStep.stepId,
|
|
894
|
+
title: pendingBrainStep.stepTitle,
|
|
895
|
+
status: STATUS.RUNNING
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
// Push a new brain level
|
|
899
|
+
brainStack.push({
|
|
900
|
+
title: event.brainTitle,
|
|
901
|
+
steps: []
|
|
902
|
+
});
|
|
903
|
+
pendingBrainStep = null;
|
|
904
|
+
} else if (row.event_type === BRAIN_EVENTS.STEP_START) {
|
|
905
|
+
// Track the current step being started (might be a brain step)
|
|
906
|
+
pendingBrainStep = {
|
|
907
|
+
stepId: event.stepId,
|
|
908
|
+
stepTitle: event.stepTitle
|
|
909
|
+
};
|
|
910
|
+
} else if (row.event_type === BRAIN_EVENTS.STEP_COMPLETE) {
|
|
911
|
+
step = {
|
|
912
|
+
id: event.stepId,
|
|
913
|
+
title: event.stepTitle,
|
|
914
|
+
status: STATUS.COMPLETE,
|
|
915
|
+
patch: event.patch
|
|
916
|
+
};
|
|
917
|
+
if (brainStack.length > 0) {
|
|
918
|
+
// Check if this completes the pending brain step
|
|
919
|
+
if (pendingBrainStep && pendingBrainStep.stepId === event.stepId) {
|
|
920
|
+
// This is the completion of the current pending step
|
|
921
|
+
pendingBrainStep = null;
|
|
922
|
+
}
|
|
923
|
+
// Add to the current brain's steps
|
|
924
|
+
brainStack[brainStack.length - 1].steps.push(step);
|
|
925
|
+
}
|
|
926
|
+
} else if (row.event_type === BRAIN_EVENTS.COMPLETE) {
|
|
927
|
+
// Pop the completed brain
|
|
928
|
+
completedBrain = brainStack.pop();
|
|
929
|
+
if (brainStack.length > 0 && completedBrain) {
|
|
930
|
+
// This inner brain completed - find its parent step and add innerSteps
|
|
931
|
+
parentBrain1 = brainStack[brainStack.length - 1];
|
|
932
|
+
// The last step in parent brain is the brain step that ran the inner brain
|
|
933
|
+
parentStep = parentBrain1.steps[parentBrain1.steps.length - 1];
|
|
934
|
+
if (parentStep) {
|
|
935
|
+
parentStep.innerSteps = completedBrain.steps;
|
|
936
|
+
parentStep.status = STATUS.COMPLETE; // Mark as complete now
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
} catch (err) {
|
|
942
|
+
_didIteratorError = true;
|
|
943
|
+
_iteratorError = err;
|
|
944
|
+
} finally{
|
|
945
|
+
try {
|
|
946
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
947
|
+
_iterator.return();
|
|
948
|
+
}
|
|
949
|
+
} finally{
|
|
950
|
+
if (_didIteratorError) {
|
|
951
|
+
throw _iteratorError;
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
// The outer brain is still running (waiting for webhook), so get its steps
|
|
956
|
+
// If there's still a brain on the stack, it's the outer brain that's paused
|
|
957
|
+
if (brainStack.length > 0) {
|
|
958
|
+
;
|
|
959
|
+
outerBrain = brainStack[0];
|
|
960
|
+
// If there's an inner brain still on the stack (brainStack.length > 1),
|
|
961
|
+
// the current inner brain is paused, and we need to attach its steps
|
|
962
|
+
// to the parent's last step as innerSteps
|
|
963
|
+
if (brainStack.length > 1) {
|
|
964
|
+
innerBrain = brainStack[brainStack.length - 1];
|
|
965
|
+
parentBrain2 = brainStack[brainStack.length - 2];
|
|
966
|
+
parentStep1 = parentBrain2.steps[parentBrain2.steps.length - 1];
|
|
967
|
+
if (parentStep1) {
|
|
968
|
+
parentStep1.innerSteps = innerBrain.steps;
|
|
969
|
+
parentStep1.status = STATUS.RUNNING; // Mark as still running (waiting)
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
// If there's a pending step (e.g., loop step paused on webhook),
|
|
973
|
+
// add it with RUNNING status so the brain knows it's resuming this step
|
|
974
|
+
if (pendingBrainStep && brainStack.length === 1) {
|
|
975
|
+
outerBrain.steps.push({
|
|
976
|
+
id: pendingBrainStep.stepId,
|
|
977
|
+
title: pendingBrainStep.stepTitle,
|
|
978
|
+
status: STATUS.RUNNING
|
|
979
|
+
});
|
|
980
|
+
}
|
|
981
|
+
(_initialCompletedSteps = initialCompletedSteps).push.apply(_initialCompletedSteps, _to_consumable_array(outerBrain.steps));
|
|
982
|
+
}
|
|
873
983
|
// Load LOOP_* events for potential loop resume
|
|
874
984
|
loopEventsResult = sql.exec("SELECT serialized_event FROM brain_events WHERE event_type LIKE 'loop:%' ORDER BY event_id ASC").toArray();
|
|
875
985
|
loopEvents = loopEventsResult.map(function(row) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"brain-runner-do.d.ts","sourceRoot":"","sources":["../../src/brain-runner-do.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"brain-runner-do.d.ts","sourceRoot":"","sources":["../../src/brain-runner-do.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA8E,MAAM,kBAAkB,CAAC;AAC3H,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAOnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAG1D,wBAAgB,WAAW,CAAC,iBAAiB,EAAE,kBAAkB,QAEhE;AAED,wBAAgB,WAAW,IAAI,kBAAkB,GAAG,IAAI,CAEvD;AAGD,wBAAgB,cAAc,CAAC,MAAM,EAAE,WAAW,QAEjD;AAGD,wBAAgB,kBAAkB,CAAC,Q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0.0.46",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"clean": "rm -rf tsconfig.tsbuildinfo dist"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@positronic/core": "^0.0.
|
|
35
|
-
"@positronic/spec": "^0.0.
|
|
36
|
-
"@positronic/template-new-project": "^0.0.
|
|
34
|
+
"@positronic/core": "^0.0.46",
|
|
35
|
+
"@positronic/spec": "^0.0.46",
|
|
36
|
+
"@positronic/template-new-project": "^0.0.46",
|
|
37
37
|
"aws4fetch": "^1.0.18",
|
|
38
38
|
"caz": "^2.0.0",
|
|
39
39
|
"cron-schedule": "^5.0.4",
|