@positronic/cloudflare 0.0.46 → 0.0.47
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,9 +6,6 @@ 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
|
-
}
|
|
12
9
|
function _assert_this_initialized(self) {
|
|
13
10
|
if (self === void 0) {
|
|
14
11
|
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
@@ -99,9 +96,6 @@ function _inherits(subClass, superClass) {
|
|
|
99
96
|
});
|
|
100
97
|
if (superClass) _set_prototype_of(subClass, superClass);
|
|
101
98
|
}
|
|
102
|
-
function _iterable_to_array(iter) {
|
|
103
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
104
|
-
}
|
|
105
99
|
function _iterable_to_array_limit(arr, i) {
|
|
106
100
|
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
107
101
|
if (_i == null) return;
|
|
@@ -129,9 +123,6 @@ function _iterable_to_array_limit(arr, i) {
|
|
|
129
123
|
function _non_iterable_rest() {
|
|
130
124
|
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
131
125
|
}
|
|
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
|
-
}
|
|
135
126
|
function _object_spread(target) {
|
|
136
127
|
for(var i = 1; i < arguments.length; i++){
|
|
137
128
|
var source = arguments[i] != null ? arguments[i] : {};
|
|
@@ -187,9 +178,6 @@ function _set_prototype_of(o, p) {
|
|
|
187
178
|
function _sliced_to_array(arr, i) {
|
|
188
179
|
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
189
180
|
}
|
|
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
|
-
}
|
|
193
181
|
function _type_of(obj) {
|
|
194
182
|
"@swc/helpers - typeof";
|
|
195
183
|
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
@@ -301,7 +289,7 @@ function _ts_generator(thisArg, body) {
|
|
|
301
289
|
};
|
|
302
290
|
}
|
|
303
291
|
}
|
|
304
|
-
import { STATUS, BRAIN_EVENTS } from '@positronic/core';
|
|
292
|
+
import { STATUS, BRAIN_EVENTS, createBrainExecutionMachine, sendEvent, getCompletedSteps } from '@positronic/core';
|
|
305
293
|
import { DurableObject } from 'cloudflare:workers';
|
|
306
294
|
import { BrainRunSQLiteAdapter } from './sqlite-adapter.js';
|
|
307
295
|
import { WebhookAdapter } from './webhook-adapter.js';
|
|
@@ -837,7 +825,7 @@ export var BrainRunnerDO = /*#__PURE__*/ function(DurableObject) {
|
|
|
837
825
|
key: "resume",
|
|
838
826
|
value: function resume(brainRunId, webhookResponse) {
|
|
839
827
|
return _async_to_generator(function() {
|
|
840
|
-
var _this, sql, startEventResult, startEvent, brainTitle, initialState, resolution, brainToRun, allEventsResult,
|
|
828
|
+
var _this, sql, startEventResult, startEvent, brainTitle, initialState, resolution, brainToRun, allEventsResult, machine, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, row, event, initialCompletedSteps, loopEventsResult, loopEvents, sqliteAdapter, eventStreamAdapter, monitorDOStub, monitorAdapter, scheduleAdapter, webhookAdapter, pageAdapter, env, pagesService, r2Resources, runnerWithResources;
|
|
841
829
|
return _ts_generator(this, function(_state) {
|
|
842
830
|
switch(_state.label){
|
|
843
831
|
case 0:
|
|
@@ -872,71 +860,18 @@ export var BrainRunnerDO = /*#__PURE__*/ function(DurableObject) {
|
|
|
872
860
|
if (!brainToRun) {
|
|
873
861
|
throw new Error("Brain ".concat(brainTitle, " resolved but brain object is missing"));
|
|
874
862
|
}
|
|
875
|
-
// Load all events to build nested initialCompletedSteps
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
pendingBrainStep = null;
|
|
863
|
+
// Load all events and feed them to the state machine to build nested initialCompletedSteps
|
|
864
|
+
allEventsResult = sql.exec("SELECT serialized_event FROM brain_events ORDER BY event_id ASC").toArray();
|
|
865
|
+
// Create state machine and feed all historical events to reconstruct step hierarchy
|
|
866
|
+
machine = createBrainExecutionMachine({
|
|
867
|
+
initialState: initialState
|
|
868
|
+
});
|
|
882
869
|
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
883
870
|
try {
|
|
884
871
|
for(_iterator = allEventsResult[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
885
872
|
row = _step.value;
|
|
886
873
|
event = JSON.parse(row.serialized_event);
|
|
887
|
-
|
|
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
|
-
}
|
|
874
|
+
sendEvent(machine, event);
|
|
940
875
|
}
|
|
941
876
|
} catch (err) {
|
|
942
877
|
_didIteratorError = true;
|
|
@@ -952,34 +887,8 @@ export var BrainRunnerDO = /*#__PURE__*/ function(DurableObject) {
|
|
|
952
887
|
}
|
|
953
888
|
}
|
|
954
889
|
}
|
|
955
|
-
//
|
|
956
|
-
|
|
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
|
-
}
|
|
890
|
+
// Get the reconstructed step hierarchy from the state machine
|
|
891
|
+
initialCompletedSteps = getCompletedSteps(machine);
|
|
983
892
|
// Load LOOP_* events for potential loop resume
|
|
984
893
|
loopEventsResult = sql.exec("SELECT serialized_event FROM brain_events WHERE event_type LIKE 'loop:%' ORDER BY event_id ASC").toArray();
|
|
985
894
|
loopEvents = loopEventsResult.map(function(row) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"brain-runner-do.d.ts","sourceRoot":"","sources":["../../src/brain-runner-do.ts"],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AAG,EAAE,GAAG;YAOjC,mBAAmB;IAqEjC;;;OAGG;IACH,OAAO,CAAC,eAAe;IAiBvB;;;;;;;;OAQG;IACG,IAAI,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAuE9F,KAAK,CACT,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAuG7B,MAAM,CACV,UAAU,EAAE,MAAM,EAClB,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAmJhC,KAAK,CAAC,OAAO,EAAE,OAAO;CA4E7B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@positronic/cloudflare",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.47",
|
|
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.47",
|
|
35
|
+
"@positronic/spec": "^0.0.47",
|
|
36
|
+
"@positronic/template-new-project": "^0.0.47",
|
|
37
37
|
"aws4fetch": "^1.0.18",
|
|
38
38
|
"caz": "^2.0.0",
|
|
39
39
|
"cron-schedule": "^5.0.4",
|