@positronic/cloudflare 0.0.3 → 0.0.5
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/api.js +1270 -0
- package/dist/src/brain-runner-do.js +654 -0
- package/dist/src/dev-server.js +1357 -0
- package/{src/index.ts → dist/src/index.js} +1 -6
- package/dist/src/manifest.js +278 -0
- package/dist/src/monitor-do.js +408 -0
- package/{src/node-index.ts → dist/src/node-index.js} +3 -7
- package/dist/src/r2-loader.js +207 -0
- package/dist/src/schedule-do.js +705 -0
- package/dist/src/sqlite-adapter.js +69 -0
- package/dist/types/api.d.ts +21 -0
- package/dist/types/api.d.ts.map +1 -0
- package/dist/types/brain-runner-do.d.ts +25 -0
- package/dist/types/brain-runner-do.d.ts.map +1 -0
- package/dist/types/dev-server.d.ts +45 -0
- package/dist/types/dev-server.d.ts.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/manifest.d.ts +11 -0
- package/dist/types/manifest.d.ts.map +1 -0
- package/dist/types/monitor-do.d.ts +16 -0
- package/dist/types/monitor-do.d.ts.map +1 -0
- package/dist/types/node-index.d.ts +10 -0
- package/dist/types/node-index.d.ts.map +1 -0
- package/dist/types/r2-loader.d.ts +10 -0
- package/dist/types/r2-loader.d.ts.map +1 -0
- package/dist/types/schedule-do.d.ts +47 -0
- package/dist/types/schedule-do.d.ts.map +1 -0
- package/dist/types/sqlite-adapter.d.ts +10 -0
- package/dist/types/sqlite-adapter.d.ts.map +1 -0
- package/package.json +5 -1
- package/src/api.ts +0 -579
- package/src/brain-runner-do.ts +0 -309
- package/src/dev-server.ts +0 -776
- package/src/manifest.ts +0 -69
- package/src/monitor-do.ts +0 -268
- package/src/r2-loader.ts +0 -27
- package/src/schedule-do.ts +0 -377
- package/src/sqlite-adapter.ts +0 -50
- package/test-project/package-lock.json +0 -3010
- package/test-project/package.json +0 -21
- package/test-project/src/index.ts +0 -70
- package/test-project/src/runner.ts +0 -24
- package/test-project/tests/api.test.ts +0 -1005
- package/test-project/tests/r2loader.test.ts +0 -73
- package/test-project/tests/resources-api.test.ts +0 -671
- package/test-project/tests/spec.test.ts +0 -135
- package/test-project/tests/tsconfig.json +0 -7
- package/test-project/tsconfig.json +0 -20
- package/test-project/vitest.config.ts +0 -12
- package/test-project/wrangler.jsonc +0 -53
- package/tsconfig.json +0 -11
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
BrainRunnerDO,
|
|
3
|
-
setBrainRunner,
|
|
4
|
-
setManifest,
|
|
5
|
-
getManifest,
|
|
6
|
-
} from './brain-runner-do.js';
|
|
1
|
+
export { BrainRunnerDO, setBrainRunner, setManifest, getManifest } from './brain-runner-do.js';
|
|
7
2
|
export { MonitorDO } from './monitor-do.js';
|
|
8
3
|
export { ScheduleDO } from './schedule-do.js';
|
|
9
4
|
export { PositronicManifest } from './manifest.js';
|
|
@@ -0,0 +1,278 @@
|
|
|
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
|
+
var StaticManifestStrategy = /*#__PURE__*/ function() {
|
|
154
|
+
"use strict";
|
|
155
|
+
function StaticManifestStrategy(manifest) {
|
|
156
|
+
_class_call_check(this, StaticManifestStrategy);
|
|
157
|
+
_define_property(this, "manifest", void 0);
|
|
158
|
+
this.manifest = manifest;
|
|
159
|
+
}
|
|
160
|
+
_create_class(StaticManifestStrategy, [
|
|
161
|
+
{
|
|
162
|
+
key: "import",
|
|
163
|
+
value: function _import(name) {
|
|
164
|
+
return _async_to_generator(function() {
|
|
165
|
+
return _ts_generator(this, function(_state) {
|
|
166
|
+
return [
|
|
167
|
+
2,
|
|
168
|
+
this.manifest[name]
|
|
169
|
+
];
|
|
170
|
+
});
|
|
171
|
+
}).call(this);
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
key: "list",
|
|
176
|
+
value: function list() {
|
|
177
|
+
return Object.keys(this.manifest);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
]);
|
|
181
|
+
return StaticManifestStrategy;
|
|
182
|
+
}();
|
|
183
|
+
var DynamicImportStrategy = /*#__PURE__*/ function() {
|
|
184
|
+
"use strict";
|
|
185
|
+
function DynamicImportStrategy(brainsDir) {
|
|
186
|
+
_class_call_check(this, DynamicImportStrategy);
|
|
187
|
+
_define_property(this, "brainsDir", void 0);
|
|
188
|
+
this.brainsDir = brainsDir;
|
|
189
|
+
}
|
|
190
|
+
_create_class(DynamicImportStrategy, [
|
|
191
|
+
{
|
|
192
|
+
key: "import",
|
|
193
|
+
value: function _import(name) {
|
|
194
|
+
return _async_to_generator(function() {
|
|
195
|
+
var module, e;
|
|
196
|
+
return _ts_generator(this, function(_state) {
|
|
197
|
+
switch(_state.label){
|
|
198
|
+
case 0:
|
|
199
|
+
_state.trys.push([
|
|
200
|
+
0,
|
|
201
|
+
2,
|
|
202
|
+
,
|
|
203
|
+
3
|
|
204
|
+
]);
|
|
205
|
+
return [
|
|
206
|
+
4,
|
|
207
|
+
import("".concat(this.brainsDir, "/").concat(name, ".ts"))
|
|
208
|
+
];
|
|
209
|
+
case 1:
|
|
210
|
+
module = _state.sent();
|
|
211
|
+
return [
|
|
212
|
+
2,
|
|
213
|
+
module.default
|
|
214
|
+
];
|
|
215
|
+
case 2:
|
|
216
|
+
e = _state.sent();
|
|
217
|
+
console.error("Failed to import brain ".concat(name, ":"), e);
|
|
218
|
+
return [
|
|
219
|
+
2,
|
|
220
|
+
undefined
|
|
221
|
+
];
|
|
222
|
+
case 3:
|
|
223
|
+
return [
|
|
224
|
+
2
|
|
225
|
+
];
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}).call(this);
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
key: "list",
|
|
233
|
+
value: function list() {
|
|
234
|
+
// For dynamic imports, we can't easily list files at runtime in a worker environment
|
|
235
|
+
// This would need to be handled differently, perhaps by generating a list at build time
|
|
236
|
+
console.warn('DynamicImportStrategy.list() is not implemented - returning empty array');
|
|
237
|
+
return [];
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
]);
|
|
241
|
+
return DynamicImportStrategy;
|
|
242
|
+
}();
|
|
243
|
+
export var PositronicManifest = /*#__PURE__*/ function() {
|
|
244
|
+
"use strict";
|
|
245
|
+
function PositronicManifest(options) {
|
|
246
|
+
_class_call_check(this, PositronicManifest);
|
|
247
|
+
_define_property(this, "importStrategy", void 0);
|
|
248
|
+
if (options.staticManifest && options.brainsDir) {
|
|
249
|
+
throw new Error('Cannot provide both staticManifest and brainsDir - choose one import strategy');
|
|
250
|
+
}
|
|
251
|
+
if (!options.staticManifest && !options.brainsDir) {
|
|
252
|
+
throw new Error('Must provide either staticManifest or brainsDir');
|
|
253
|
+
}
|
|
254
|
+
this.importStrategy = options.staticManifest ? new StaticManifestStrategy(options.staticManifest) : new DynamicImportStrategy(options.brainsDir);
|
|
255
|
+
}
|
|
256
|
+
_create_class(PositronicManifest, [
|
|
257
|
+
{
|
|
258
|
+
key: "import",
|
|
259
|
+
value: function _import(name) {
|
|
260
|
+
return _async_to_generator(function() {
|
|
261
|
+
return _ts_generator(this, function(_state) {
|
|
262
|
+
return [
|
|
263
|
+
2,
|
|
264
|
+
this.importStrategy.import(name)
|
|
265
|
+
];
|
|
266
|
+
});
|
|
267
|
+
}).call(this);
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
key: "list",
|
|
272
|
+
value: function list() {
|
|
273
|
+
return this.importStrategy.list();
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
]);
|
|
277
|
+
return PositronicManifest;
|
|
278
|
+
}();
|
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
function _assert_this_initialized(self) {
|
|
2
|
+
if (self === void 0) {
|
|
3
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
4
|
+
}
|
|
5
|
+
return self;
|
|
6
|
+
}
|
|
7
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
8
|
+
try {
|
|
9
|
+
var info = gen[key](arg);
|
|
10
|
+
var value = info.value;
|
|
11
|
+
} catch (error) {
|
|
12
|
+
reject(error);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (info.done) {
|
|
16
|
+
resolve(value);
|
|
17
|
+
} else {
|
|
18
|
+
Promise.resolve(value).then(_next, _throw);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function _async_to_generator(fn) {
|
|
22
|
+
return function() {
|
|
23
|
+
var self = this, args = arguments;
|
|
24
|
+
return new Promise(function(resolve, reject) {
|
|
25
|
+
var gen = fn.apply(self, args);
|
|
26
|
+
function _next(value) {
|
|
27
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
28
|
+
}
|
|
29
|
+
function _throw(err) {
|
|
30
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
31
|
+
}
|
|
32
|
+
_next(undefined);
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function _call_super(_this, derived, args) {
|
|
37
|
+
derived = _get_prototype_of(derived);
|
|
38
|
+
return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
|
|
39
|
+
}
|
|
40
|
+
function _class_call_check(instance, Constructor) {
|
|
41
|
+
if (!(instance instanceof Constructor)) {
|
|
42
|
+
throw new TypeError("Cannot call a class as a function");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function _defineProperties(target, props) {
|
|
46
|
+
for(var i = 0; i < props.length; i++){
|
|
47
|
+
var descriptor = props[i];
|
|
48
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
49
|
+
descriptor.configurable = true;
|
|
50
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
51
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
55
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
56
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
57
|
+
return Constructor;
|
|
58
|
+
}
|
|
59
|
+
function _define_property(obj, key, value) {
|
|
60
|
+
if (key in obj) {
|
|
61
|
+
Object.defineProperty(obj, key, {
|
|
62
|
+
value: value,
|
|
63
|
+
enumerable: true,
|
|
64
|
+
configurable: true,
|
|
65
|
+
writable: true
|
|
66
|
+
});
|
|
67
|
+
} else {
|
|
68
|
+
obj[key] = value;
|
|
69
|
+
}
|
|
70
|
+
return obj;
|
|
71
|
+
}
|
|
72
|
+
function _get_prototype_of(o) {
|
|
73
|
+
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
74
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
75
|
+
};
|
|
76
|
+
return _get_prototype_of(o);
|
|
77
|
+
}
|
|
78
|
+
function _inherits(subClass, superClass) {
|
|
79
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
80
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
81
|
+
}
|
|
82
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
83
|
+
constructor: {
|
|
84
|
+
value: subClass,
|
|
85
|
+
writable: true,
|
|
86
|
+
configurable: true
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
90
|
+
}
|
|
91
|
+
function _possible_constructor_return(self, call) {
|
|
92
|
+
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
93
|
+
return call;
|
|
94
|
+
}
|
|
95
|
+
return _assert_this_initialized(self);
|
|
96
|
+
}
|
|
97
|
+
function _set_prototype_of(o, p) {
|
|
98
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
99
|
+
o.__proto__ = p;
|
|
100
|
+
return o;
|
|
101
|
+
};
|
|
102
|
+
return _set_prototype_of(o, p);
|
|
103
|
+
}
|
|
104
|
+
function _type_of(obj) {
|
|
105
|
+
"@swc/helpers - typeof";
|
|
106
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
107
|
+
}
|
|
108
|
+
function _is_native_reflect_construct() {
|
|
109
|
+
try {
|
|
110
|
+
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
111
|
+
} catch (_) {}
|
|
112
|
+
return (_is_native_reflect_construct = function() {
|
|
113
|
+
return !!result;
|
|
114
|
+
})();
|
|
115
|
+
}
|
|
116
|
+
function _ts_generator(thisArg, body) {
|
|
117
|
+
var f, y, t, _ = {
|
|
118
|
+
label: 0,
|
|
119
|
+
sent: function() {
|
|
120
|
+
if (t[0] & 1) throw t[1];
|
|
121
|
+
return t[1];
|
|
122
|
+
},
|
|
123
|
+
trys: [],
|
|
124
|
+
ops: []
|
|
125
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
126
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
127
|
+
return this;
|
|
128
|
+
}), g;
|
|
129
|
+
function verb(n) {
|
|
130
|
+
return function(v) {
|
|
131
|
+
return step([
|
|
132
|
+
n,
|
|
133
|
+
v
|
|
134
|
+
]);
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function step(op) {
|
|
138
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
139
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
140
|
+
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;
|
|
141
|
+
if (y = 0, t) op = [
|
|
142
|
+
op[0] & 2,
|
|
143
|
+
t.value
|
|
144
|
+
];
|
|
145
|
+
switch(op[0]){
|
|
146
|
+
case 0:
|
|
147
|
+
case 1:
|
|
148
|
+
t = op;
|
|
149
|
+
break;
|
|
150
|
+
case 4:
|
|
151
|
+
_.label++;
|
|
152
|
+
return {
|
|
153
|
+
value: op[1],
|
|
154
|
+
done: false
|
|
155
|
+
};
|
|
156
|
+
case 5:
|
|
157
|
+
_.label++;
|
|
158
|
+
y = op[1];
|
|
159
|
+
op = [
|
|
160
|
+
0
|
|
161
|
+
];
|
|
162
|
+
continue;
|
|
163
|
+
case 7:
|
|
164
|
+
op = _.ops.pop();
|
|
165
|
+
_.trys.pop();
|
|
166
|
+
continue;
|
|
167
|
+
default:
|
|
168
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
169
|
+
_ = 0;
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
173
|
+
_.label = op[1];
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
177
|
+
_.label = t[1];
|
|
178
|
+
t = op;
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
if (t && _.label < t[2]) {
|
|
182
|
+
_.label = t[2];
|
|
183
|
+
_.ops.push(op);
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
if (t[2]) _.ops.pop();
|
|
187
|
+
_.trys.pop();
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
op = body.call(thisArg, _);
|
|
191
|
+
} catch (e) {
|
|
192
|
+
op = [
|
|
193
|
+
6,
|
|
194
|
+
e
|
|
195
|
+
];
|
|
196
|
+
y = 0;
|
|
197
|
+
} finally{
|
|
198
|
+
f = t = 0;
|
|
199
|
+
}
|
|
200
|
+
if (op[0] & 5) throw op[1];
|
|
201
|
+
return {
|
|
202
|
+
value: op[0] ? op[1] : void 0,
|
|
203
|
+
done: true
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
import { DurableObject } from 'cloudflare:workers';
|
|
208
|
+
import { BRAIN_EVENTS, STATUS } from '@positronic/core';
|
|
209
|
+
export var MonitorDO = /*#__PURE__*/ function(DurableObject) {
|
|
210
|
+
"use strict";
|
|
211
|
+
_inherits(MonitorDO, DurableObject);
|
|
212
|
+
function MonitorDO(state, env) {
|
|
213
|
+
_class_call_check(this, MonitorDO);
|
|
214
|
+
var _this;
|
|
215
|
+
_this = _call_super(this, MonitorDO, [
|
|
216
|
+
state,
|
|
217
|
+
env
|
|
218
|
+
]), _define_property(_this, "storage", void 0), _define_property(_this, "eventStreamHandler", new EventStreamHandler());
|
|
219
|
+
_this.storage = state.storage.sql;
|
|
220
|
+
// Update table schema and indexes
|
|
221
|
+
_this.storage.exec("\n CREATE TABLE IF NOT EXISTS brain_runs (\n run_id TEXT PRIMARY KEY,\n brain_title TEXT NOT NULL, -- Renamed column\n brain_description TEXT, -- Renamed column\n type TEXT NOT NULL,\n status TEXT NOT NULL,\n options TEXT,\n error TEXT,\n created_at INTEGER NOT NULL,\n started_at INTEGER,\n completed_at INTEGER\n );\n\n CREATE INDEX IF NOT EXISTS idx_brain_status -- Renamed index\n ON brain_runs(brain_title, status);\n\n CREATE INDEX IF NOT EXISTS idx_brain_time -- Renamed index\n ON brain_runs(created_at DESC);\n ");
|
|
222
|
+
return _this;
|
|
223
|
+
}
|
|
224
|
+
_create_class(MonitorDO, [
|
|
225
|
+
{
|
|
226
|
+
key: "handleBrainEvent",
|
|
227
|
+
value: function handleBrainEvent(event) {
|
|
228
|
+
if (event.type === BRAIN_EVENTS.START || event.type === BRAIN_EVENTS.RESTART || event.type === BRAIN_EVENTS.COMPLETE || event.type === BRAIN_EVENTS.ERROR) {
|
|
229
|
+
var currentTime = Date.now();
|
|
230
|
+
var startTime = event.type === BRAIN_EVENTS.START || event.type === BRAIN_EVENTS.RESTART ? currentTime : null;
|
|
231
|
+
var completeTime = event.type === BRAIN_EVENTS.COMPLETE || event.type === BRAIN_EVENTS.ERROR ? currentTime : null;
|
|
232
|
+
var error = event.type === BRAIN_EVENTS.ERROR ? JSON.stringify(event.error) : null;
|
|
233
|
+
// Update SQL insert/update with new column names, read from existing event fields
|
|
234
|
+
this.storage.exec("\n INSERT INTO brain_runs (\n run_id, brain_title, brain_description, type, status,\n options, error, created_at, started_at, completed_at\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\n ON CONFLICT(run_id) DO UPDATE SET\n type = excluded.type,\n status = excluded.status,\n error = excluded.error,\n completed_at = excluded.completed_at\n ", event.brainRunId, event.brainTitle, event.brainDescription || null, event.type, event.status, JSON.stringify(event.options || {}), error, currentTime, startTime, completeTime);
|
|
235
|
+
this.broadcastRunningBrains();
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
key: "broadcastRunningBrains",
|
|
241
|
+
value: function broadcastRunningBrains() {
|
|
242
|
+
return _async_to_generator(function() {
|
|
243
|
+
var runningBrains;
|
|
244
|
+
return _ts_generator(this, function(_state) {
|
|
245
|
+
switch(_state.label){
|
|
246
|
+
case 0:
|
|
247
|
+
return [
|
|
248
|
+
4,
|
|
249
|
+
this.storage.exec("\n SELECT\n run_id as brainRunId,\n brain_title as brainTitle,\n brain_description as brainDescription,\n type,\n status,\n options,\n error,\n created_at as createdAt,\n started_at as startedAt,\n completed_at as completedAt\n FROM brain_runs\n WHERE status = ?\n ORDER BY created_at DESC\n ", STATUS.RUNNING).toArray()
|
|
250
|
+
];
|
|
251
|
+
case 1:
|
|
252
|
+
runningBrains = _state.sent();
|
|
253
|
+
this.eventStreamHandler.broadcast({
|
|
254
|
+
runningBrains: runningBrains
|
|
255
|
+
});
|
|
256
|
+
return [
|
|
257
|
+
2
|
|
258
|
+
];
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
}).call(this);
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
key: "fetch",
|
|
266
|
+
value: function fetch(request) {
|
|
267
|
+
return _async_to_generator(function() {
|
|
268
|
+
var _this, url, encoder, stream;
|
|
269
|
+
return _ts_generator(this, function(_state) {
|
|
270
|
+
_this = this;
|
|
271
|
+
url = new URL(request.url);
|
|
272
|
+
encoder = new TextEncoder();
|
|
273
|
+
if (url.pathname === '/watch') {
|
|
274
|
+
stream = new ReadableStream({
|
|
275
|
+
start: function(controller) {
|
|
276
|
+
return _async_to_generator(function() {
|
|
277
|
+
var runningBrains, err;
|
|
278
|
+
return _ts_generator(this, function(_state) {
|
|
279
|
+
switch(_state.label){
|
|
280
|
+
case 0:
|
|
281
|
+
_state.trys.push([
|
|
282
|
+
0,
|
|
283
|
+
2,
|
|
284
|
+
,
|
|
285
|
+
3
|
|
286
|
+
]);
|
|
287
|
+
return [
|
|
288
|
+
4,
|
|
289
|
+
this.storage.exec("\n SELECT\n run_id as brainRunId,\n brain_title as brainTitle,\n brain_description as brainDescription,\n type,\n status,\n options,\n error,\n created_at as createdAt,\n started_at as startedAt,\n completed_at as completedAt\n FROM brain_runs\n WHERE status = ?\n ORDER BY created_at DESC\n ", STATUS.RUNNING).toArray()
|
|
290
|
+
];
|
|
291
|
+
case 1:
|
|
292
|
+
runningBrains = _state.sent();
|
|
293
|
+
controller.enqueue(encoder.encode("data: ".concat(JSON.stringify({
|
|
294
|
+
runningBrains: runningBrains
|
|
295
|
+
}), "\n\n")));
|
|
296
|
+
this.eventStreamHandler.subscribe(controller);
|
|
297
|
+
return [
|
|
298
|
+
3,
|
|
299
|
+
3
|
|
300
|
+
];
|
|
301
|
+
case 2:
|
|
302
|
+
err = _state.sent();
|
|
303
|
+
console.error('[MONITOR_DO] Error during stream start:', err);
|
|
304
|
+
controller.close();
|
|
305
|
+
this.eventStreamHandler.unsubscribe(controller);
|
|
306
|
+
return [
|
|
307
|
+
3,
|
|
308
|
+
3
|
|
309
|
+
];
|
|
310
|
+
case 3:
|
|
311
|
+
return [
|
|
312
|
+
2
|
|
313
|
+
];
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
}).call(_this);
|
|
317
|
+
},
|
|
318
|
+
cancel: function(controller) {
|
|
319
|
+
_this.eventStreamHandler.unsubscribe(controller);
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
return [
|
|
323
|
+
2,
|
|
324
|
+
new Response(stream, {
|
|
325
|
+
headers: {
|
|
326
|
+
'Content-Type': 'text/event-stream',
|
|
327
|
+
'Cache-Control': 'no-cache',
|
|
328
|
+
Connection: 'keep-alive'
|
|
329
|
+
}
|
|
330
|
+
})
|
|
331
|
+
];
|
|
332
|
+
}
|
|
333
|
+
return [
|
|
334
|
+
2,
|
|
335
|
+
new Response('Not found', {
|
|
336
|
+
status: 404
|
|
337
|
+
})
|
|
338
|
+
];
|
|
339
|
+
});
|
|
340
|
+
}).call(this);
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
// No changes needed for getLastEvent, uses run_id
|
|
345
|
+
key: "getLastEvent",
|
|
346
|
+
value: function getLastEvent(brainRunId) {
|
|
347
|
+
return this.storage.exec("\n SELECT * FROM brain_runs WHERE run_id = ?\n ", brainRunId).one();
|
|
348
|
+
}
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
// Update history method parameter and query
|
|
352
|
+
key: "history",
|
|
353
|
+
value: function history(brainTitle) {
|
|
354
|
+
var limit = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 10;
|
|
355
|
+
// Renamed parameter
|
|
356
|
+
// Update select query with aliases and filter by brain_title
|
|
357
|
+
return this.storage.exec("\n SELECT\n run_id as brainRunId,\n brain_title as brainTitle,\n brain_description as brainDescription,\n type,\n status,\n options,\n error,\n created_at as createdAt,\n started_at as startedAt,\n completed_at as completedAt\n FROM brain_runs\n WHERE brain_title = ? -- Filter by new column name\n ORDER BY created_at DESC\n LIMIT ?\n ", brainTitle, limit).toArray(); // Use renamed parameter
|
|
358
|
+
}
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
// Get active/running brain runs for a specific brain
|
|
362
|
+
key: "activeRuns",
|
|
363
|
+
value: function activeRuns(brainTitle) {
|
|
364
|
+
return this.storage.exec("\n SELECT\n run_id as brainRunId,\n brain_title as brainTitle,\n brain_description as brainDescription,\n type,\n status,\n options,\n error,\n created_at as createdAt,\n started_at as startedAt,\n completed_at as completedAt\n FROM brain_runs\n WHERE brain_title = ? AND status = ?\n ORDER BY created_at DESC\n ", brainTitle, STATUS.RUNNING).toArray();
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
]);
|
|
368
|
+
return MonitorDO;
|
|
369
|
+
}(DurableObject);
|
|
370
|
+
var EventStreamHandler = /*#__PURE__*/ function() {
|
|
371
|
+
"use strict";
|
|
372
|
+
function EventStreamHandler() {
|
|
373
|
+
_class_call_check(this, EventStreamHandler);
|
|
374
|
+
_define_property(this, "subscribers", new Set());
|
|
375
|
+
_define_property(this, "encoder", new TextEncoder());
|
|
376
|
+
}
|
|
377
|
+
_create_class(EventStreamHandler, [
|
|
378
|
+
{
|
|
379
|
+
key: "subscribe",
|
|
380
|
+
value: function subscribe(controller) {
|
|
381
|
+
this.subscribers.add(controller);
|
|
382
|
+
}
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
key: "unsubscribe",
|
|
386
|
+
value: function unsubscribe(controller) {
|
|
387
|
+
this.subscribers.delete(controller);
|
|
388
|
+
}
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
key: "broadcast",
|
|
392
|
+
value: function broadcast(data) {
|
|
393
|
+
var _this = this;
|
|
394
|
+
var message = "data: ".concat(JSON.stringify(data), "\n\n");
|
|
395
|
+
var encodedMessage = this.encoder.encode(message);
|
|
396
|
+
this.subscribers.forEach(function(controller) {
|
|
397
|
+
try {
|
|
398
|
+
controller.enqueue(encodedMessage);
|
|
399
|
+
} catch (e) {
|
|
400
|
+
console.error('[MONITOR_DO_SSE] Failed to send message to subscriber, removing.', e);
|
|
401
|
+
_this.unsubscribe(controller);
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
]);
|
|
407
|
+
return EventStreamHandler;
|
|
408
|
+
}();
|