@positronic/cloudflare 0.0.64 → 0.0.66
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/brain-runner-do.js +112 -12
- package/dist/src/timeout-adapter.js +205 -0
- package/dist/types/brain-runner-do.d.ts +8 -0
- package/dist/types/brain-runner-do.d.ts.map +1 -1
- package/dist/types/timeout-adapter.d.ts +13 -0
- package/dist/types/timeout-adapter.d.ts.map +1 -0
- package/package.json +4 -4
|
@@ -294,6 +294,7 @@ import { DurableObject } from 'cloudflare:workers';
|
|
|
294
294
|
import { CloudflareSignalProvider } from './signal-provider.js';
|
|
295
295
|
import { BrainRunSQLiteAdapter } from './sqlite-adapter.js';
|
|
296
296
|
import { WebhookAdapter } from './webhook-adapter.js';
|
|
297
|
+
import { TimeoutAdapter } from './timeout-adapter.js';
|
|
297
298
|
import { PageAdapter } from './page-adapter.js';
|
|
298
299
|
import { EventLoader } from './event-loader.js';
|
|
299
300
|
import { createPagesService } from './pages-service.js';
|
|
@@ -504,6 +505,8 @@ var ScheduleAdapter = /*#__PURE__*/ function() {
|
|
|
504
505
|
}();
|
|
505
506
|
// SQL to initialize the signals table
|
|
506
507
|
var signalsTableSQL = "\nCREATE TABLE IF NOT EXISTS brain_signals (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n signal_type TEXT NOT NULL,\n content TEXT,\n queued_at INTEGER NOT NULL\n);\n";
|
|
508
|
+
// SQL to initialize the wait timeout table
|
|
509
|
+
var waitTimeoutTableSQL = "\nCREATE TABLE IF NOT EXISTS wait_timeout (\n brain_run_id TEXT PRIMARY KEY,\n timeout_at INTEGER NOT NULL\n);\n";
|
|
507
510
|
export var BrainRunnerDO = /*#__PURE__*/ function(DurableObject) {
|
|
508
511
|
"use strict";
|
|
509
512
|
_inherits(BrainRunnerDO, DurableObject);
|
|
@@ -513,7 +516,7 @@ export var BrainRunnerDO = /*#__PURE__*/ function(DurableObject) {
|
|
|
513
516
|
_this = _call_super(this, BrainRunnerDO, [
|
|
514
517
|
state,
|
|
515
518
|
env
|
|
516
|
-
]), _define_property(_this, "sql", void 0), _define_property(_this, "brainRunId", void 0), _define_property(_this, "eventStreamAdapter", new EventStreamAdapter()), _define_property(_this, "abortController", null), _define_property(_this, "pageAdapter", null), _define_property(_this, "signalsTableInitialized", false);
|
|
519
|
+
]), _define_property(_this, "sql", void 0), _define_property(_this, "brainRunId", void 0), _define_property(_this, "eventStreamAdapter", new EventStreamAdapter()), _define_property(_this, "abortController", null), _define_property(_this, "pageAdapter", null), _define_property(_this, "signalsTableInitialized", false), _define_property(_this, "waitTimeoutTableInitialized", false);
|
|
517
520
|
_this.sql = state.storage.sql;
|
|
518
521
|
_this.brainRunId = state.id.toString();
|
|
519
522
|
_this.env = env;
|
|
@@ -529,6 +532,41 @@ export var BrainRunnerDO = /*#__PURE__*/ function(DurableObject) {
|
|
|
529
532
|
}
|
|
530
533
|
}
|
|
531
534
|
},
|
|
535
|
+
{
|
|
536
|
+
key: "initializeWaitTimeoutTable",
|
|
537
|
+
value: function initializeWaitTimeoutTable() {
|
|
538
|
+
if (!this.waitTimeoutTableInitialized) {
|
|
539
|
+
this.sql.exec(waitTimeoutTableSQL);
|
|
540
|
+
this.waitTimeoutTableInitialized = true;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
},
|
|
544
|
+
{
|
|
545
|
+
key: "storeWaitTimeout",
|
|
546
|
+
value: function storeWaitTimeout(brainRunId, timeoutAt) {
|
|
547
|
+
this.initializeWaitTimeoutTable();
|
|
548
|
+
this.sql.exec("INSERT OR REPLACE INTO wait_timeout (brain_run_id, timeout_at) VALUES (?, ?)", brainRunId, timeoutAt);
|
|
549
|
+
}
|
|
550
|
+
},
|
|
551
|
+
{
|
|
552
|
+
key: "clearWaitTimeout",
|
|
553
|
+
value: function clearWaitTimeout(brainRunId) {
|
|
554
|
+
this.initializeWaitTimeoutTable();
|
|
555
|
+
this.sql.exec("DELETE FROM wait_timeout WHERE brain_run_id = ?", brainRunId);
|
|
556
|
+
}
|
|
557
|
+
},
|
|
558
|
+
{
|
|
559
|
+
key: "getWaitTimeout",
|
|
560
|
+
value: function getWaitTimeout() {
|
|
561
|
+
this.initializeWaitTimeoutTable();
|
|
562
|
+
var results = this.sql.exec("SELECT brain_run_id, timeout_at FROM wait_timeout LIMIT 1").toArray();
|
|
563
|
+
if (results.length === 0) return null;
|
|
564
|
+
return {
|
|
565
|
+
brainRunId: results[0].brain_run_id,
|
|
566
|
+
timeoutAt: results[0].timeout_at
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
},
|
|
532
570
|
{
|
|
533
571
|
key: "queueSignal",
|
|
534
572
|
value: /**
|
|
@@ -787,7 +825,7 @@ export var BrainRunnerDO = /*#__PURE__*/ function(DurableObject) {
|
|
|
787
825
|
* SQLite state is missing (zombie brain scenario).
|
|
788
826
|
*/ function kill(brainRunId, brainTitle) {
|
|
789
827
|
return _async_to_generator(function() {
|
|
790
|
-
var monitorStub, actualBrainRunId, actualBrainTitle, startEvent, eventLoader, err, existingRun, activeStatuses, cancelledEvent, _this_pageAdapter, pageAdapter;
|
|
828
|
+
var monitorStub, actualBrainRunId, actualBrainTitle, startEvent, eventLoader, err, existingRun, activeStatuses, cancelledEvent, pendingTimeout, _this_pageAdapter, pageAdapter;
|
|
791
829
|
return _ts_generator(this, function(_state) {
|
|
792
830
|
switch(_state.label){
|
|
793
831
|
case 0:
|
|
@@ -895,6 +933,22 @@ export var BrainRunnerDO = /*#__PURE__*/ function(DurableObject) {
|
|
|
895
933
|
brainRunId: actualBrainRunId,
|
|
896
934
|
options: (startEvent === null || startEvent === void 0 ? void 0 : startEvent.options) || {}
|
|
897
935
|
};
|
|
936
|
+
// Clean up any pending wait timeout and alarm to prevent spurious
|
|
937
|
+
// alarm fires after the brain has been manually cancelled.
|
|
938
|
+
pendingTimeout = this.getWaitTimeout();
|
|
939
|
+
if (!pendingTimeout) return [
|
|
940
|
+
3,
|
|
941
|
+
7
|
|
942
|
+
];
|
|
943
|
+
this.clearWaitTimeout(pendingTimeout.brainRunId);
|
|
944
|
+
return [
|
|
945
|
+
4,
|
|
946
|
+
this.ctx.storage.deleteAlarm()
|
|
947
|
+
];
|
|
948
|
+
case 6:
|
|
949
|
+
_state.sent();
|
|
950
|
+
_state.label = 7;
|
|
951
|
+
case 7:
|
|
898
952
|
// Dispatch to PageAdapter for cleanup (deletes non-persistent pages from R2)
|
|
899
953
|
// This is needed because when a brain is paused (waiting for webhook), the BrainRunner
|
|
900
954
|
// has already returned and adapters aren't receiving events through the normal pipeline.
|
|
@@ -904,13 +958,13 @@ export var BrainRunnerDO = /*#__PURE__*/ function(DurableObject) {
|
|
|
904
958
|
4,
|
|
905
959
|
pageAdapter.dispatch(cancelledEvent)
|
|
906
960
|
];
|
|
907
|
-
case
|
|
961
|
+
case 8:
|
|
908
962
|
_state.sent();
|
|
909
963
|
return [
|
|
910
964
|
4,
|
|
911
965
|
monitorStub.handleBrainEvent(cancelledEvent)
|
|
912
966
|
];
|
|
913
|
-
case
|
|
967
|
+
case 9:
|
|
914
968
|
_state.sent();
|
|
915
969
|
return [
|
|
916
970
|
2,
|
|
@@ -928,14 +982,31 @@ export var BrainRunnerDO = /*#__PURE__*/ function(DurableObject) {
|
|
|
928
982
|
key: "alarm",
|
|
929
983
|
value: function alarm() {
|
|
930
984
|
return _async_to_generator(function() {
|
|
985
|
+
var timeout;
|
|
931
986
|
return _ts_generator(this, function(_state) {
|
|
932
987
|
switch(_state.label){
|
|
933
988
|
case 0:
|
|
989
|
+
timeout = this.getWaitTimeout();
|
|
990
|
+
if (!(timeout && Date.now() >= timeout.timeoutAt)) return [
|
|
991
|
+
3,
|
|
992
|
+
2
|
|
993
|
+
];
|
|
994
|
+
this.clearWaitTimeout(timeout.brainRunId);
|
|
934
995
|
return [
|
|
935
996
|
4,
|
|
936
|
-
this.
|
|
997
|
+
this.queueSignal({
|
|
998
|
+
type: 'KILL'
|
|
999
|
+
})
|
|
937
1000
|
];
|
|
938
1001
|
case 1:
|
|
1002
|
+
_state.sent();
|
|
1003
|
+
_state.label = 2;
|
|
1004
|
+
case 2:
|
|
1005
|
+
return [
|
|
1006
|
+
4,
|
|
1007
|
+
this.wakeUp(this.brainRunId)
|
|
1008
|
+
];
|
|
1009
|
+
case 3:
|
|
939
1010
|
_state.sent();
|
|
940
1011
|
return [
|
|
941
1012
|
2
|
|
@@ -949,7 +1020,7 @@ export var BrainRunnerDO = /*#__PURE__*/ function(DurableObject) {
|
|
|
949
1020
|
key: "start",
|
|
950
1021
|
value: function start(brainTitle, brainRunId, initialData) {
|
|
951
1022
|
return _async_to_generator(function() {
|
|
952
|
-
var _this, sql, resolution, brainToRun, sqliteAdapter, eventStreamAdapter, monitorDOStub, monitorAdapter, scheduleAdapter, webhookAdapter, env, pagesService, r2Resources, runnerWithResources, signalProvider, options, initialState, batchChunkAdapter;
|
|
1023
|
+
var _this, sql, resolution, brainToRun, sqliteAdapter, eventStreamAdapter, monitorDOStub, monitorAdapter, scheduleAdapter, webhookAdapter, env, pagesService, r2Resources, runnerWithResources, signalProvider, options, initialState, batchChunkAdapter, timeoutAdapter;
|
|
953
1024
|
return _ts_generator(this, function(_state) {
|
|
954
1025
|
switch(_state.label){
|
|
955
1026
|
case 0:
|
|
@@ -1016,6 +1087,11 @@ export var BrainRunnerDO = /*#__PURE__*/ function(DurableObject) {
|
|
|
1016
1087
|
}, function(time) {
|
|
1017
1088
|
return _this.ctx.storage.setAlarm(time);
|
|
1018
1089
|
});
|
|
1090
|
+
timeoutAdapter = new TimeoutAdapter(function(brainRunId, timeoutAt) {
|
|
1091
|
+
return _this.storeWaitTimeout(brainRunId, timeoutAt);
|
|
1092
|
+
}, function(time) {
|
|
1093
|
+
return _this.ctx.storage.setAlarm(time);
|
|
1094
|
+
});
|
|
1019
1095
|
runnerWithResources.withAdapters([
|
|
1020
1096
|
sqliteAdapter,
|
|
1021
1097
|
eventStreamAdapter,
|
|
@@ -1023,7 +1099,8 @@ export var BrainRunnerDO = /*#__PURE__*/ function(DurableObject) {
|
|
|
1023
1099
|
scheduleAdapter,
|
|
1024
1100
|
webhookAdapter,
|
|
1025
1101
|
this.pageAdapter,
|
|
1026
|
-
batchChunkAdapter
|
|
1102
|
+
batchChunkAdapter,
|
|
1103
|
+
timeoutAdapter
|
|
1027
1104
|
]).run(brainToRun, _object_spread_props(_object_spread({
|
|
1028
1105
|
initialState: initialState,
|
|
1029
1106
|
brainRunId: brainRunId
|
|
@@ -1054,12 +1131,29 @@ export var BrainRunnerDO = /*#__PURE__*/ function(DurableObject) {
|
|
|
1054
1131
|
* This method reconstructs state and calls BrainRunner.resume().
|
|
1055
1132
|
*/ function wakeUp(brainRunId) {
|
|
1056
1133
|
return _async_to_generator(function() {
|
|
1057
|
-
var _this, sql, eventLoader, startEvent, brainTitle, initialState, originalBrainRunId, resolution, brainToRun, allEvents, machine, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, event, sqliteAdapter, eventStreamAdapter, monitorDOStub, monitorAdapter, scheduleAdapter, webhookAdapter, env, pagesService, r2Resources, runnerWithResources, signalProvider, batchChunkAdapter;
|
|
1134
|
+
var _this, sql, pendingTimeout, eventLoader, startEvent, brainTitle, initialState, originalBrainRunId, resolution, brainToRun, allEvents, machine, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, event, sqliteAdapter, eventStreamAdapter, monitorDOStub, monitorAdapter, scheduleAdapter, webhookAdapter, env, pagesService, r2Resources, runnerWithResources, signalProvider, batchChunkAdapter, timeoutAdapter;
|
|
1058
1135
|
return _ts_generator(this, function(_state) {
|
|
1059
1136
|
switch(_state.label){
|
|
1060
1137
|
case 0:
|
|
1061
1138
|
_this = this;
|
|
1062
1139
|
sql = this.sql;
|
|
1140
|
+
// Clear any pending timeout and cancel the alarm to prevent spurious alarm
|
|
1141
|
+
// fires after explicit resume. Safe because wakeUp() is only called when a
|
|
1142
|
+
// brain is suspended (waiting/paused), never during active batch execution.
|
|
1143
|
+
pendingTimeout = this.getWaitTimeout();
|
|
1144
|
+
if (!pendingTimeout) return [
|
|
1145
|
+
3,
|
|
1146
|
+
2
|
|
1147
|
+
];
|
|
1148
|
+
this.clearWaitTimeout(pendingTimeout.brainRunId);
|
|
1149
|
+
return [
|
|
1150
|
+
4,
|
|
1151
|
+
this.ctx.storage.deleteAlarm()
|
|
1152
|
+
];
|
|
1153
|
+
case 1:
|
|
1154
|
+
_state.sent();
|
|
1155
|
+
_state.label = 2;
|
|
1156
|
+
case 2:
|
|
1063
1157
|
if (!manifest) {
|
|
1064
1158
|
throw new Error('Runtime manifest not initialized');
|
|
1065
1159
|
}
|
|
@@ -1069,7 +1163,7 @@ export var BrainRunnerDO = /*#__PURE__*/ function(DurableObject) {
|
|
|
1069
1163
|
4,
|
|
1070
1164
|
eventLoader.loadEventByType(BRAIN_EVENTS.START, 'ASC')
|
|
1071
1165
|
];
|
|
1072
|
-
case
|
|
1166
|
+
case 3:
|
|
1073
1167
|
startEvent = _state.sent();
|
|
1074
1168
|
if (!startEvent) {
|
|
1075
1169
|
throw new Error("No START event found for brain run ".concat(brainRunId));
|
|
@@ -1102,7 +1196,7 @@ export var BrainRunnerDO = /*#__PURE__*/ function(DurableObject) {
|
|
|
1102
1196
|
4,
|
|
1103
1197
|
eventLoader.loadAllEvents()
|
|
1104
1198
|
];
|
|
1105
|
-
case
|
|
1199
|
+
case 4:
|
|
1106
1200
|
allEvents = _state.sent();
|
|
1107
1201
|
// Create state machine and feed all historical events to reconstruct execution state
|
|
1108
1202
|
machine = createBrainExecutionMachine({
|
|
@@ -1146,7 +1240,7 @@ export var BrainRunnerDO = /*#__PURE__*/ function(DurableObject) {
|
|
|
1146
1240
|
4,
|
|
1147
1241
|
this.loadResourcesFromR2()
|
|
1148
1242
|
];
|
|
1149
|
-
case
|
|
1243
|
+
case 5:
|
|
1150
1244
|
r2Resources = _state.sent();
|
|
1151
1245
|
runnerWithResources = brainRunner;
|
|
1152
1246
|
if (r2Resources) {
|
|
@@ -1167,6 +1261,11 @@ export var BrainRunnerDO = /*#__PURE__*/ function(DurableObject) {
|
|
|
1167
1261
|
}, function(time) {
|
|
1168
1262
|
return _this.ctx.storage.setAlarm(time);
|
|
1169
1263
|
});
|
|
1264
|
+
timeoutAdapter = new TimeoutAdapter(function(brainRunId, timeoutAt) {
|
|
1265
|
+
return _this.storeWaitTimeout(brainRunId, timeoutAt);
|
|
1266
|
+
}, function(time) {
|
|
1267
|
+
return _this.ctx.storage.setAlarm(time);
|
|
1268
|
+
});
|
|
1170
1269
|
runnerWithResources.withAdapters([
|
|
1171
1270
|
sqliteAdapter,
|
|
1172
1271
|
eventStreamAdapter,
|
|
@@ -1174,7 +1273,8 @@ export var BrainRunnerDO = /*#__PURE__*/ function(DurableObject) {
|
|
|
1174
1273
|
scheduleAdapter,
|
|
1175
1274
|
webhookAdapter,
|
|
1176
1275
|
this.pageAdapter,
|
|
1177
|
-
batchChunkAdapter
|
|
1276
|
+
batchChunkAdapter,
|
|
1277
|
+
timeoutAdapter
|
|
1178
1278
|
]).resume(brainToRun, {
|
|
1179
1279
|
machine: machine,
|
|
1180
1280
|
brainRunId: originalBrainRunId,
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
+
try {
|
|
3
|
+
var info = gen[key](arg);
|
|
4
|
+
var value = info.value;
|
|
5
|
+
} catch (error) {
|
|
6
|
+
reject(error);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (info.done) {
|
|
10
|
+
resolve(value);
|
|
11
|
+
} else {
|
|
12
|
+
Promise.resolve(value).then(_next, _throw);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _async_to_generator(fn) {
|
|
16
|
+
return function() {
|
|
17
|
+
var self = this, args = arguments;
|
|
18
|
+
return new Promise(function(resolve, reject) {
|
|
19
|
+
var gen = fn.apply(self, args);
|
|
20
|
+
function _next(value) {
|
|
21
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
+
}
|
|
23
|
+
function _throw(err) {
|
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
+
}
|
|
26
|
+
_next(undefined);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function _class_call_check(instance, Constructor) {
|
|
31
|
+
if (!(instance instanceof Constructor)) {
|
|
32
|
+
throw new TypeError("Cannot call a class as a function");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function _defineProperties(target, props) {
|
|
36
|
+
for(var i = 0; i < props.length; i++){
|
|
37
|
+
var descriptor = props[i];
|
|
38
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
39
|
+
descriptor.configurable = true;
|
|
40
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
41
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
45
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
46
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
47
|
+
return Constructor;
|
|
48
|
+
}
|
|
49
|
+
function _define_property(obj, key, value) {
|
|
50
|
+
if (key in obj) {
|
|
51
|
+
Object.defineProperty(obj, key, {
|
|
52
|
+
value: value,
|
|
53
|
+
enumerable: true,
|
|
54
|
+
configurable: true,
|
|
55
|
+
writable: true
|
|
56
|
+
});
|
|
57
|
+
} else {
|
|
58
|
+
obj[key] = value;
|
|
59
|
+
}
|
|
60
|
+
return obj;
|
|
61
|
+
}
|
|
62
|
+
function _ts_generator(thisArg, body) {
|
|
63
|
+
var f, y, t, _ = {
|
|
64
|
+
label: 0,
|
|
65
|
+
sent: function() {
|
|
66
|
+
if (t[0] & 1) throw t[1];
|
|
67
|
+
return t[1];
|
|
68
|
+
},
|
|
69
|
+
trys: [],
|
|
70
|
+
ops: []
|
|
71
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
72
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
73
|
+
return this;
|
|
74
|
+
}), g;
|
|
75
|
+
function verb(n) {
|
|
76
|
+
return function(v) {
|
|
77
|
+
return step([
|
|
78
|
+
n,
|
|
79
|
+
v
|
|
80
|
+
]);
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function step(op) {
|
|
84
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
85
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
86
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
87
|
+
if (y = 0, t) op = [
|
|
88
|
+
op[0] & 2,
|
|
89
|
+
t.value
|
|
90
|
+
];
|
|
91
|
+
switch(op[0]){
|
|
92
|
+
case 0:
|
|
93
|
+
case 1:
|
|
94
|
+
t = op;
|
|
95
|
+
break;
|
|
96
|
+
case 4:
|
|
97
|
+
_.label++;
|
|
98
|
+
return {
|
|
99
|
+
value: op[1],
|
|
100
|
+
done: false
|
|
101
|
+
};
|
|
102
|
+
case 5:
|
|
103
|
+
_.label++;
|
|
104
|
+
y = op[1];
|
|
105
|
+
op = [
|
|
106
|
+
0
|
|
107
|
+
];
|
|
108
|
+
continue;
|
|
109
|
+
case 7:
|
|
110
|
+
op = _.ops.pop();
|
|
111
|
+
_.trys.pop();
|
|
112
|
+
continue;
|
|
113
|
+
default:
|
|
114
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
115
|
+
_ = 0;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
119
|
+
_.label = op[1];
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
123
|
+
_.label = t[1];
|
|
124
|
+
t = op;
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
if (t && _.label < t[2]) {
|
|
128
|
+
_.label = t[2];
|
|
129
|
+
_.ops.push(op);
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
if (t[2]) _.ops.pop();
|
|
133
|
+
_.trys.pop();
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
op = body.call(thisArg, _);
|
|
137
|
+
} catch (e) {
|
|
138
|
+
op = [
|
|
139
|
+
6,
|
|
140
|
+
e
|
|
141
|
+
];
|
|
142
|
+
y = 0;
|
|
143
|
+
} finally{
|
|
144
|
+
f = t = 0;
|
|
145
|
+
}
|
|
146
|
+
if (op[0] & 5) throw op[1];
|
|
147
|
+
return {
|
|
148
|
+
value: op[0] ? op[1] : void 0,
|
|
149
|
+
done: true
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
import { BRAIN_EVENTS } from '@positronic/core';
|
|
154
|
+
/**
|
|
155
|
+
* Adapter that handles WEBHOOK events with a timeout by storing the
|
|
156
|
+
* timeout and scheduling a DO alarm. When the alarm fires and the
|
|
157
|
+
* brain is still waiting, it queues a KILL signal to cancel the brain.
|
|
158
|
+
*/ export var TimeoutAdapter = /*#__PURE__*/ function() {
|
|
159
|
+
"use strict";
|
|
160
|
+
function TimeoutAdapter(storeTimeout, setAlarm) {
|
|
161
|
+
_class_call_check(this, TimeoutAdapter);
|
|
162
|
+
_define_property(this, "storeTimeout", void 0);
|
|
163
|
+
_define_property(this, "setAlarm", void 0);
|
|
164
|
+
this.storeTimeout = storeTimeout;
|
|
165
|
+
this.setAlarm = setAlarm;
|
|
166
|
+
}
|
|
167
|
+
_create_class(TimeoutAdapter, [
|
|
168
|
+
{
|
|
169
|
+
key: "dispatch",
|
|
170
|
+
value: function dispatch(event) {
|
|
171
|
+
return _async_to_generator(function() {
|
|
172
|
+
var timeout, timeoutAt;
|
|
173
|
+
return _ts_generator(this, function(_state) {
|
|
174
|
+
switch(_state.label){
|
|
175
|
+
case 0:
|
|
176
|
+
if (event.type !== BRAIN_EVENTS.WEBHOOK) {
|
|
177
|
+
return [
|
|
178
|
+
2
|
|
179
|
+
];
|
|
180
|
+
}
|
|
181
|
+
timeout = event.timeout;
|
|
182
|
+
if (timeout === undefined) {
|
|
183
|
+
return [
|
|
184
|
+
2
|
|
185
|
+
];
|
|
186
|
+
}
|
|
187
|
+
timeoutAt = Date.now() + timeout;
|
|
188
|
+
this.storeTimeout(event.brainRunId, timeoutAt);
|
|
189
|
+
return [
|
|
190
|
+
4,
|
|
191
|
+
this.setAlarm(timeoutAt)
|
|
192
|
+
];
|
|
193
|
+
case 1:
|
|
194
|
+
_state.sent();
|
|
195
|
+
return [
|
|
196
|
+
2
|
|
197
|
+
];
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}).call(this);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
]);
|
|
204
|
+
return TimeoutAdapter;
|
|
205
|
+
}();
|
|
@@ -23,8 +23,16 @@ export declare class BrainRunnerDO extends DurableObject<Env> {
|
|
|
23
23
|
private abortController;
|
|
24
24
|
private pageAdapter;
|
|
25
25
|
private signalsTableInitialized;
|
|
26
|
+
private waitTimeoutTableInitialized;
|
|
26
27
|
constructor(state: DurableObjectState, env: Env);
|
|
27
28
|
private initializeSignalsTable;
|
|
29
|
+
private initializeWaitTimeoutTable;
|
|
30
|
+
storeWaitTimeout(brainRunId: string, timeoutAt: number): void;
|
|
31
|
+
clearWaitTimeout(brainRunId: string): void;
|
|
32
|
+
getWaitTimeout(): {
|
|
33
|
+
brainRunId: string;
|
|
34
|
+
timeoutAt: number;
|
|
35
|
+
} | null;
|
|
28
36
|
/**
|
|
29
37
|
* Queue a signal for this brain run.
|
|
30
38
|
* Returns the queued signal with timestamp.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"brain-runner-do.d.ts","sourceRoot":"","sources":["../../src/brain-runner-do.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAiG,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAChK,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"brain-runner-do.d.ts","sourceRoot":"","sources":["../../src/brain-runner-do.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAiG,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAChK,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAUnD,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,CAAC,CAExD;AAED,MAAM,WAAW,GAAG;IAClB,eAAe,EAAE,sBAAsB,CAAC;IACxC,UAAU,EAAE,sBAAsB,CAAC,SAAS,CAAC,CAAC;IAC9C,WAAW,EAAE,sBAAsB,CAAC,UAAU,CAAC,CAAC;IAChD,gBAAgB,EAAE,QAAQ,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAsGD,qBAAa,aAAc,SAAQ,aAAa,CAAC,GAAG,CAAC;IACnD,OAAO,CAAC,GAAG,CAAa;IACxB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,kBAAkB,CAA4B;IACtD,OAAO,CAAC,eAAe,CAAgC;IACvD,OAAO,CAAC,WAAW,CAA4B;IAC/C,OAAO,CAAC,uBAAuB,CAAS;IACxC,OAAO,CAAC,2BAA2B,CAAS;gBAEhC,KAAK,EAAE,kBAAkB,EAAE,GAAG,EAAE,GAAG;IAO/C,OAAO,CAAC,sBAAsB;IAO9B,OAAO,CAAC,0BAA0B;IAOlC,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAStD,gBAAgB,CAAC,UAAU,EAAE,MAAM;IAQnC,cAAc,IAAI;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;IAWlE;;;;OAIG;IACG,WAAW,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IAmB9I;;;;OAIG;IACH,oBAAoB,CAAC,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,KAAK,GAAG,WAAW,EAAE;YA+C5D,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;IAkF9F,KAAK;IASL,KAAK,CACT,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAyHnC;;;;OAIG;IACG,MAAM,CAAC,UAAU,EAAE,MAAM;IAyJzB,KAAK,CAAC,OAAO,EAAE,OAAO;CAkE7B"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Adapter, BrainEvent } from '@positronic/core';
|
|
2
|
+
/**
|
|
3
|
+
* Adapter that handles WEBHOOK events with a timeout by storing the
|
|
4
|
+
* timeout and scheduling a DO alarm. When the alarm fires and the
|
|
5
|
+
* brain is still waiting, it queues a KILL signal to cancel the brain.
|
|
6
|
+
*/
|
|
7
|
+
export declare class TimeoutAdapter implements Adapter {
|
|
8
|
+
private storeTimeout;
|
|
9
|
+
private setAlarm;
|
|
10
|
+
constructor(storeTimeout: (brainRunId: string, timeoutAt: number) => void, setAlarm: (time: number) => Promise<void>);
|
|
11
|
+
dispatch(event: BrainEvent): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=timeout-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeout-adapter.d.ts","sourceRoot":"","sources":["../../src/timeout-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG5D;;;;GAIG;AACH,qBAAa,cAAe,YAAW,OAAO;IAE1C,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,QAAQ;gBADR,YAAY,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,EAC7D,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC;IAG7C,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;CAcjD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@positronic/cloudflare",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.66",
|
|
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.66",
|
|
35
|
+
"@positronic/spec": "^0.0.66",
|
|
36
|
+
"@positronic/template-new-project": "^0.0.66",
|
|
37
37
|
"aws4fetch": "^1.0.18",
|
|
38
38
|
"caz": "^2.0.0",
|
|
39
39
|
"cron-schedule": "^5.0.4",
|