@positronic/cloudflare 0.0.45 → 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.
|
@@ -289,7 +289,7 @@ function _ts_generator(thisArg, body) {
|
|
|
289
289
|
};
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
|
-
import { STATUS, BRAIN_EVENTS } from '@positronic/core';
|
|
292
|
+
import { STATUS, BRAIN_EVENTS, createBrainExecutionMachine, sendEvent, getCompletedSteps } from '@positronic/core';
|
|
293
293
|
import { DurableObject } from 'cloudflare:workers';
|
|
294
294
|
import { BrainRunSQLiteAdapter } from './sqlite-adapter.js';
|
|
295
295
|
import { WebhookAdapter } from './webhook-adapter.js';
|
|
@@ -825,7 +825,7 @@ export var BrainRunnerDO = /*#__PURE__*/ function(DurableObject) {
|
|
|
825
825
|
key: "resume",
|
|
826
826
|
value: function resume(brainRunId, webhookResponse) {
|
|
827
827
|
return _async_to_generator(function() {
|
|
828
|
-
var _this, sql, startEventResult, startEvent, brainTitle, initialState, resolution, brainToRun,
|
|
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;
|
|
829
829
|
return _ts_generator(this, function(_state) {
|
|
830
830
|
switch(_state.label){
|
|
831
831
|
case 0:
|
|
@@ -834,8 +834,9 @@ export var BrainRunnerDO = /*#__PURE__*/ function(DurableObject) {
|
|
|
834
834
|
if (!manifest) {
|
|
835
835
|
throw new Error('Runtime manifest not initialized');
|
|
836
836
|
}
|
|
837
|
-
// Get the initial state and brain title by loading the START or RESTART event
|
|
838
|
-
|
|
837
|
+
// Get the initial state and brain title by loading the FIRST START or RESTART event
|
|
838
|
+
// (the outer brain's event, not an inner brain's)
|
|
839
|
+
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
840
|
if (startEventResult.length === 0) {
|
|
840
841
|
throw new Error("No START or RESTART event found for brain run ".concat(brainRunId));
|
|
841
842
|
}
|
|
@@ -859,17 +860,35 @@ export var BrainRunnerDO = /*#__PURE__*/ function(DurableObject) {
|
|
|
859
860
|
if (!brainToRun) {
|
|
860
861
|
throw new Error("Brain ".concat(brainTitle, " resolved but brain object is missing"));
|
|
861
862
|
}
|
|
862
|
-
// Load
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
id: event.stepId,
|
|
868
|
-
title: event.stepTitle,
|
|
869
|
-
status: STATUS.COMPLETE,
|
|
870
|
-
patch: event.patch
|
|
871
|
-
};
|
|
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
|
|
872
868
|
});
|
|
869
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
870
|
+
try {
|
|
871
|
+
for(_iterator = allEventsResult[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
872
|
+
row = _step.value;
|
|
873
|
+
event = JSON.parse(row.serialized_event);
|
|
874
|
+
sendEvent(machine, event);
|
|
875
|
+
}
|
|
876
|
+
} catch (err) {
|
|
877
|
+
_didIteratorError = true;
|
|
878
|
+
_iteratorError = err;
|
|
879
|
+
} finally{
|
|
880
|
+
try {
|
|
881
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
882
|
+
_iterator.return();
|
|
883
|
+
}
|
|
884
|
+
} finally{
|
|
885
|
+
if (_didIteratorError) {
|
|
886
|
+
throw _iteratorError;
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
// Get the reconstructed step hierarchy from the state machine
|
|
891
|
+
initialCompletedSteps = getCompletedSteps(machine);
|
|
873
892
|
// Load LOOP_* events for potential loop resume
|
|
874
893
|
loopEventsResult = sql.exec("SELECT serialized_event FROM brain_events WHERE event_type LIKE 'loop:%' ORDER BY event_id ASC").toArray();
|
|
875
894
|
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,EAAyI,MAAM,kBAAkB,CAAC;AACtL,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,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,QAE/D;AAED,wBAAgB,kBAAkB,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,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-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",
|