@positronic/cloudflare 0.0.15 → 0.0.17

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.
@@ -0,0 +1,232 @@
1
+ function _array_like_to_array(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _array_with_holes(arr) {
7
+ if (Array.isArray(arr)) return arr;
8
+ }
9
+ function _class_call_check(instance, Constructor) {
10
+ if (!(instance instanceof Constructor)) {
11
+ throw new TypeError("Cannot call a class as a function");
12
+ }
13
+ }
14
+ function _defineProperties(target, props) {
15
+ for(var i = 0; i < props.length; i++){
16
+ var descriptor = props[i];
17
+ descriptor.enumerable = descriptor.enumerable || false;
18
+ descriptor.configurable = true;
19
+ if ("value" in descriptor) descriptor.writable = true;
20
+ Object.defineProperty(target, descriptor.key, descriptor);
21
+ }
22
+ }
23
+ function _create_class(Constructor, protoProps, staticProps) {
24
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
25
+ if (staticProps) _defineProperties(Constructor, staticProps);
26
+ return Constructor;
27
+ }
28
+ function _define_property(obj, key, value) {
29
+ if (key in obj) {
30
+ Object.defineProperty(obj, key, {
31
+ value: value,
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true
35
+ });
36
+ } else {
37
+ obj[key] = value;
38
+ }
39
+ return obj;
40
+ }
41
+ function _iterable_to_array_limit(arr, i) {
42
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
43
+ if (_i == null) return;
44
+ var _arr = [];
45
+ var _n = true;
46
+ var _d = false;
47
+ var _s, _e;
48
+ try {
49
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
50
+ _arr.push(_s.value);
51
+ if (i && _arr.length === i) break;
52
+ }
53
+ } catch (err) {
54
+ _d = true;
55
+ _e = err;
56
+ } finally{
57
+ try {
58
+ if (!_n && _i["return"] != null) _i["return"]();
59
+ } finally{
60
+ if (_d) throw _e;
61
+ }
62
+ }
63
+ return _arr;
64
+ }
65
+ function _non_iterable_rest() {
66
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
67
+ }
68
+ function _sliced_to_array(arr, i) {
69
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
70
+ }
71
+ function _unsupported_iterable_to_array(o, minLen) {
72
+ if (!o) return;
73
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
74
+ var n = Object.prototype.toString.call(o).slice(8, -1);
75
+ if (n === "Object" && o.constructor) n = o.constructor.name;
76
+ if (n === "Map" || n === "Set") return Array.from(n);
77
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
78
+ }
79
+ export var BrainResolver = /*#__PURE__*/ function() {
80
+ "use strict";
81
+ function BrainResolver(enhancedManifest) {
82
+ _class_call_check(this, BrainResolver);
83
+ _define_property(this, "enhancedManifest", void 0);
84
+ _define_property(this, "metadataCache", void 0);
85
+ this.enhancedManifest = enhancedManifest;
86
+ this.metadataCache = new Map();
87
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
88
+ try {
89
+ // Pre-cache brain titles and descriptions
90
+ for(var _iterator = Object.entries(enhancedManifest)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
91
+ var _step_value = _sliced_to_array(_step.value, 2), filename = _step_value[0], metadata = _step_value[1];
92
+ var brain = metadata.brain;
93
+ // Access brain structure to get title and description
94
+ var structure = brain.structure;
95
+ this.metadataCache.set(filename, {
96
+ title: structure.title || filename,
97
+ description: structure.description
98
+ });
99
+ }
100
+ } catch (err) {
101
+ _didIteratorError = true;
102
+ _iteratorError = err;
103
+ } finally{
104
+ try {
105
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
106
+ _iterator.return();
107
+ }
108
+ } finally{
109
+ if (_didIteratorError) {
110
+ throw _iteratorError;
111
+ }
112
+ }
113
+ }
114
+ }
115
+ _create_class(BrainResolver, [
116
+ {
117
+ key: "resolve",
118
+ value: function resolve(identifier) {
119
+ var candidates = [];
120
+ // Normalize identifier for comparison
121
+ var normalizedIdentifier = identifier.toLowerCase().trim();
122
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
123
+ try {
124
+ // Check each brain in the manifest
125
+ for(var _iterator = Object.entries(this.enhancedManifest)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
126
+ var _step_value = _sliced_to_array(_step.value, 2), filename = _step_value[0], metadata = _step_value[1];
127
+ var cached = this.metadataCache.get(filename);
128
+ var title = cached.title;
129
+ var description = cached.description;
130
+ // 1. Exact title match (case-insensitive)
131
+ if (title.toLowerCase() === normalizedIdentifier) {
132
+ return {
133
+ matchType: 'exact',
134
+ brain: metadata.brain
135
+ };
136
+ }
137
+ // 2. Exact filename match (case-insensitive)
138
+ if (filename.toLowerCase() === normalizedIdentifier) {
139
+ return {
140
+ matchType: 'exact',
141
+ brain: metadata.brain
142
+ };
143
+ }
144
+ // 3. Exact path match (case-insensitive)
145
+ if (metadata.path.toLowerCase() === normalizedIdentifier) {
146
+ return {
147
+ matchType: 'exact',
148
+ brain: metadata.brain
149
+ };
150
+ }
151
+ // Collect candidates for partial matching
152
+ var candidate = {
153
+ title: title,
154
+ filename: filename,
155
+ path: metadata.path,
156
+ description: description
157
+ };
158
+ // 4. Partial path match
159
+ if (metadata.path.toLowerCase().includes(normalizedIdentifier)) {
160
+ candidates.push(candidate);
161
+ continue;
162
+ }
163
+ // 5. Title contains identifier
164
+ if (title.toLowerCase().includes(normalizedIdentifier)) {
165
+ candidates.push(candidate);
166
+ continue;
167
+ }
168
+ // 6. Filename contains identifier
169
+ if (filename.toLowerCase().includes(normalizedIdentifier)) {
170
+ candidates.push(candidate);
171
+ continue;
172
+ }
173
+ // 7. Description contains identifier (if exists)
174
+ if (description && description.toLowerCase().includes(normalizedIdentifier)) {
175
+ candidates.push(candidate);
176
+ }
177
+ }
178
+ } catch (err) {
179
+ _didIteratorError = true;
180
+ _iteratorError = err;
181
+ } finally{
182
+ try {
183
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
184
+ _iterator.return();
185
+ }
186
+ } finally{
187
+ if (_didIteratorError) {
188
+ throw _iteratorError;
189
+ }
190
+ }
191
+ }
192
+ // Handle results
193
+ if (candidates.length === 0) {
194
+ return {
195
+ matchType: 'none'
196
+ };
197
+ } else if (candidates.length === 1) {
198
+ // Single match found through partial matching
199
+ var match = this.enhancedManifest[candidates[0].filename];
200
+ return {
201
+ matchType: 'exact',
202
+ brain: match.brain
203
+ };
204
+ } else {
205
+ // Multiple matches found
206
+ return {
207
+ matchType: 'multiple',
208
+ candidates: candidates
209
+ };
210
+ }
211
+ }
212
+ },
213
+ {
214
+ /**
215
+ * Get a brain by exact filename (used for backward compatibility)
216
+ */ key: "getByFilename",
217
+ value: function getByFilename(filename) {
218
+ var metadata = this.enhancedManifest[filename];
219
+ return metadata === null || metadata === void 0 ? void 0 : metadata.brain;
220
+ }
221
+ },
222
+ {
223
+ /**
224
+ * List all available brains
225
+ */ key: "list",
226
+ value: function list() {
227
+ return Object.keys(this.enhancedManifest);
228
+ }
229
+ }
230
+ ]);
231
+ return BrainResolver;
232
+ }();
@@ -504,7 +504,7 @@ export var BrainRunnerDO = /*#__PURE__*/ function(DurableObject) {
504
504
  },
505
505
  {
506
506
  key: "start",
507
- value: function start(brainName, brainRunId, initialData) {
507
+ value: function start(brainTitle, brainRunId, initialData) {
508
508
  return _async_to_generator(function() {
509
509
  var sql, brainToRun, sqliteAdapter, eventStreamAdapter, monitorAdapter, scheduleAdapter, r2Resources, runnerWithResources, options, initialState;
510
510
  return _ts_generator(this, function(_state) {
@@ -516,14 +516,14 @@ export var BrainRunnerDO = /*#__PURE__*/ function(DurableObject) {
516
516
  }
517
517
  return [
518
518
  4,
519
- manifest.import(brainName)
519
+ manifest.import(brainTitle)
520
520
  ];
521
521
  case 1:
522
522
  brainToRun = _state.sent();
523
523
  if (!brainToRun) {
524
- console.error("[DO ".concat(brainRunId, "] Brain ").concat(brainName, " not found in manifest."));
524
+ console.error("[DO ".concat(brainRunId, "] Brain ").concat(brainTitle, " not found in manifest."));
525
525
  console.error(JSON.stringify(manifest, null, 2));
526
- throw new Error("Brain ".concat(brainName, " not found"));
526
+ throw new Error("Brain ".concat(brainTitle, " not found"));
527
527
  }
528
528
  sqliteAdapter = new BrainRunSQLiteAdapter(sql);
529
529
  eventStreamAdapter = this.eventStreamAdapter;
@@ -254,6 +254,7 @@ import * as os from 'os';
254
254
  import { spawn } from 'child_process';
255
255
  import * as dotenv from 'dotenv';
256
256
  import caz from 'caz';
257
+ import { createRequire } from 'module';
257
258
  /**
258
259
  * Implementation of ServerHandle that wraps a ChildProcess
259
260
  */ var ProcessServerHandle = /*#__PURE__*/ function() {
@@ -408,7 +409,7 @@ import caz from 'caz';
408
409
  }();
409
410
  function generateProject(projectName, projectDir, onSuccess) {
410
411
  return _async_to_generator(function() {
411
- var devPath, newProjectTemplatePath, cazOptions, originalNewProjectPkg, copiedNewProjectPkg;
412
+ var devPath, newProjectTemplatePath, cazOptions, templateSourcePath, require, templatePackageJsonPath, copiedNewProjectPkg;
412
413
  return _ts_generator(this, function(_state) {
413
414
  switch(_state.label){
414
415
  case 0:
@@ -434,19 +435,29 @@ function generateProject(projectName, projectDir, onSuccess) {
434
435
  // monorepo which then causes the tests to fail. Also any time I was generating a new
435
436
  // project it was a pain to have to run npm install over and over again just
436
437
  // to get back to a good state.
437
- originalNewProjectPkg = path.resolve(devPath, 'packages', 'template-new-project');
438
- copiedNewProjectPkg = fs.mkdtempSync(path.join(os.tmpdir(), 'positronic-newproj-'));
439
- fs.cpSync(originalNewProjectPkg, copiedNewProjectPkg, {
440
- recursive: true
441
- });
442
- newProjectTemplatePath = copiedNewProjectPkg;
443
- cazOptions = {
444
- name: projectName,
445
- backend: 'cloudflare',
446
- install: true,
447
- pm: 'npm'
448
- };
438
+ templateSourcePath = path.resolve(devPath, 'packages', 'template-new-project');
439
+ } else {
440
+ // Resolve the installed template package location
441
+ require = createRequire(import.meta.url);
442
+ templatePackageJsonPath = require.resolve('@positronic/template-new-project/package.json');
443
+ templateSourcePath = path.dirname(templatePackageJsonPath);
449
444
  }
445
+ // Always copy to a temporary directory to avoid CAZ modifying our source
446
+ // CAZ only supports local paths, GitHub repos, or ZIP URLs - not npm package names
447
+ // Additionally, CAZ runs 'npm install --production' in the template directory,
448
+ // which would modify our installed node_modules if we passed the path directly
449
+ copiedNewProjectPkg = fs.mkdtempSync(path.join(os.tmpdir(), 'positronic-newproj-'));
450
+ fs.cpSync(templateSourcePath, copiedNewProjectPkg, {
451
+ recursive: true
452
+ });
453
+ newProjectTemplatePath = copiedNewProjectPkg;
454
+ // Set CAZ options for cloudflare backend
455
+ cazOptions = {
456
+ name: projectName,
457
+ backend: 'cloudflare',
458
+ install: true,
459
+ pm: 'npm'
460
+ };
450
461
  return [
451
462
  4,
452
463
  caz.default(newProjectTemplatePath, projectDir, _object_spread_props(_object_spread({}, cazOptions), {
@@ -467,13 +478,11 @@ function generateProject(projectName, projectDir, onSuccess) {
467
478
  ];
468
479
  case 4:
469
480
  // Clean up the temporary copied new project package
470
- if (devPath) {
471
- fs.rmSync(newProjectTemplatePath, {
472
- recursive: true,
473
- force: true,
474
- maxRetries: 3
475
- });
476
- }
481
+ fs.rmSync(newProjectTemplatePath, {
482
+ recursive: true,
483
+ force: true,
484
+ maxRetries: 3
485
+ });
477
486
  return [
478
487
  7
479
488
  ];
@@ -527,7 +536,12 @@ function regenerateManifestFile(projectRootPath, targetSrcDir) {
527
536
  importPath = "../../brains/".concat(brainName, ".js");
528
537
  importAlias = "brain_".concat(brainName.replace(/[^a-zA-Z0-9_]/g, '_'));
529
538
  importStatements += "import * as ".concat(importAlias, " from '").concat(importPath, "';\n");
530
- manifestEntries += " ".concat(JSON.stringify(brainName), ": ").concat(importAlias, ".default as Brain,\n");
539
+ // Create manifest entry with metadata
540
+ manifestEntries += " ".concat(JSON.stringify(brainName), ": {\n");
541
+ manifestEntries += " filename: ".concat(JSON.stringify(brainName), ",\n");
542
+ manifestEntries += " path: ".concat(JSON.stringify("brains/".concat(file)), ",\n");
543
+ manifestEntries += " brain: ".concat(importAlias, ".default as Brain,\n");
544
+ manifestEntries += " },\n";
531
545
  }
532
546
  } catch (err) {
533
547
  _didIteratorError = true;
@@ -545,7 +559,7 @@ function regenerateManifestFile(projectRootPath, targetSrcDir) {
545
559
  }
546
560
  _state.label = 3;
547
561
  case 3:
548
- manifestContent = "// This file is generated automatically. Do not edit directly.\n".concat(importStatements, "\nexport const staticManifest: Record<string, Brain> = {\n").concat(manifestEntries, "};\n");
562
+ manifestContent = "// This file is generated automatically. Do not edit directly.\n".concat(importStatements, "\nimport type { BrainMetadata } from '@positronic/cloudflare';\n\nexport const manifest: Record<string, BrainMetadata> = {\n").concat(manifestEntries, "};\n");
549
563
  return [
550
564
  4,
551
565
  fsPromises.readFile(runnerPath, 'utf-8')
@@ -150,27 +150,37 @@ function _ts_generator(thisArg, body) {
150
150
  };
151
151
  }
152
152
  }
153
+ import { BrainResolver } from './brain-resolver.js';
153
154
  var StaticManifestStrategy = /*#__PURE__*/ function() {
154
155
  "use strict";
155
156
  function StaticManifestStrategy(manifest) {
156
157
  _class_call_check(this, StaticManifestStrategy);
157
158
  _define_property(this, "manifest", void 0);
159
+ _define_property(this, "resolver", void 0);
158
160
  this.manifest = manifest;
161
+ this.resolver = new BrainResolver(manifest);
159
162
  }
160
163
  _create_class(StaticManifestStrategy, [
161
164
  {
162
165
  key: "import",
163
- value: function _import(name) {
166
+ value: function _import(filename) {
164
167
  return _async_to_generator(function() {
168
+ var _this_manifest_filename;
165
169
  return _ts_generator(this, function(_state) {
166
170
  return [
167
171
  2,
168
- this.manifest[name]
172
+ (_this_manifest_filename = this.manifest[filename]) === null || _this_manifest_filename === void 0 ? void 0 : _this_manifest_filename.brain
169
173
  ];
170
174
  });
171
175
  }).call(this);
172
176
  }
173
177
  },
178
+ {
179
+ key: "resolve",
180
+ value: function resolve(identifier) {
181
+ return this.resolver.resolve(identifier);
182
+ }
183
+ },
174
184
  {
175
185
  key: "list",
176
186
  value: function list() {
@@ -190,7 +200,7 @@ var DynamicImportStrategy = /*#__PURE__*/ function() {
190
200
  _create_class(DynamicImportStrategy, [
191
201
  {
192
202
  key: "import",
193
- value: function _import(name) {
203
+ value: function _import(filename) {
194
204
  return _async_to_generator(function() {
195
205
  var module, e;
196
206
  return _ts_generator(this, function(_state) {
@@ -204,7 +214,7 @@ var DynamicImportStrategy = /*#__PURE__*/ function() {
204
214
  ]);
205
215
  return [
206
216
  4,
207
- import("".concat(this.brainsDir, "/").concat(name, ".ts"))
217
+ import("".concat(this.brainsDir, "/").concat(filename, ".ts"))
208
218
  ];
209
219
  case 1:
210
220
  module = _state.sent();
@@ -214,7 +224,7 @@ var DynamicImportStrategy = /*#__PURE__*/ function() {
214
224
  ];
215
225
  case 2:
216
226
  e = _state.sent();
217
- console.error("Failed to import brain ".concat(name, ":"), e);
227
+ console.error("Failed to import brain ".concat(filename, ":"), e);
218
228
  return [
219
229
  2,
220
230
  undefined
@@ -228,6 +238,20 @@ var DynamicImportStrategy = /*#__PURE__*/ function() {
228
238
  }).call(this);
229
239
  }
230
240
  },
241
+ {
242
+ key: "resolve",
243
+ value: function resolve(identifier) {
244
+ // For dynamic imports, we can only do simple filename matching
245
+ return this.import(identifier).then(function(brain) {
246
+ return brain ? {
247
+ matchType: 'exact',
248
+ brain: brain
249
+ } : {
250
+ matchType: 'none'
251
+ };
252
+ }); // Type assertion needed due to async
253
+ }
254
+ },
231
255
  {
232
256
  key: "list",
233
257
  value: function list() {
@@ -245,28 +269,34 @@ export var PositronicManifest = /*#__PURE__*/ function() {
245
269
  function PositronicManifest(options) {
246
270
  _class_call_check(this, PositronicManifest);
247
271
  _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');
272
+ if (options.manifest && options.brainsDir) {
273
+ throw new Error('Cannot provide both manifest and brainsDir - choose one import strategy');
250
274
  }
251
- if (!options.staticManifest && !options.brainsDir) {
252
- throw new Error('Must provide either staticManifest or brainsDir');
275
+ if (!options.manifest && !options.brainsDir) {
276
+ throw new Error('Must provide either manifest or brainsDir');
253
277
  }
254
- this.importStrategy = options.staticManifest ? new StaticManifestStrategy(options.staticManifest) : new DynamicImportStrategy(options.brainsDir);
278
+ this.importStrategy = options.manifest ? new StaticManifestStrategy(options.manifest) : new DynamicImportStrategy(options.brainsDir);
255
279
  }
256
280
  _create_class(PositronicManifest, [
257
281
  {
258
282
  key: "import",
259
- value: function _import(name) {
283
+ value: function _import(filename) {
260
284
  return _async_to_generator(function() {
261
285
  return _ts_generator(this, function(_state) {
262
286
  return [
263
287
  2,
264
- this.importStrategy.import(name)
288
+ this.importStrategy.import(filename)
265
289
  ];
266
290
  });
267
291
  }).call(this);
268
292
  }
269
293
  },
294
+ {
295
+ key: "resolve",
296
+ value: function resolve(identifier) {
297
+ return this.importStrategy.resolve(identifier);
298
+ }
299
+ },
270
300
  {
271
301
  key: "list",
272
302
  value: function list() {
@@ -253,13 +253,13 @@ export var ScheduleDO = /*#__PURE__*/ function(DurableObject) {
253
253
  ]), _define_property(_this, "storage", void 0);
254
254
  _this.storage = state.storage.sql;
255
255
  // Initialize database schema
256
- _this.storage.exec("\n CREATE TABLE IF NOT EXISTS schedules (\n id TEXT PRIMARY KEY,\n brain_name TEXT NOT NULL,\n cron_expression TEXT NOT NULL,\n enabled INTEGER NOT NULL DEFAULT 1,\n created_at INTEGER NOT NULL,\n next_run_at INTEGER\n );\n\n CREATE INDEX IF NOT EXISTS idx_schedules_brain\n ON schedules(brain_name);\n\n CREATE INDEX IF NOT EXISTS idx_schedules_enabled\n ON schedules(enabled);\n\n CREATE TABLE IF NOT EXISTS scheduled_runs (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n schedule_id TEXT NOT NULL,\n brain_run_id TEXT UNIQUE,\n status TEXT NOT NULL CHECK(status IN ('triggered', 'failed', 'complete')),\n ran_at INTEGER NOT NULL,\n completed_at INTEGER,\n error TEXT,\n FOREIGN KEY (schedule_id) REFERENCES schedules(id) ON DELETE CASCADE\n );\n\n CREATE INDEX IF NOT EXISTS idx_runs_schedule\n ON scheduled_runs(schedule_id, ran_at DESC);\n ");
256
+ _this.storage.exec("\n CREATE TABLE IF NOT EXISTS schedules (\n id TEXT PRIMARY KEY,\n brain_title TEXT NOT NULL,\n cron_expression TEXT NOT NULL,\n enabled INTEGER NOT NULL DEFAULT 1,\n created_at INTEGER NOT NULL,\n next_run_at INTEGER\n );\n\n CREATE INDEX IF NOT EXISTS idx_schedules_brain\n ON schedules(brain_title);\n\n CREATE INDEX IF NOT EXISTS idx_schedules_enabled\n ON schedules(enabled);\n\n CREATE TABLE IF NOT EXISTS scheduled_runs (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n schedule_id TEXT NOT NULL,\n brain_run_id TEXT UNIQUE,\n status TEXT NOT NULL CHECK(status IN ('triggered', 'failed', 'complete')),\n ran_at INTEGER NOT NULL,\n completed_at INTEGER,\n error TEXT,\n FOREIGN KEY (schedule_id) REFERENCES schedules(id) ON DELETE CASCADE\n );\n\n CREATE INDEX IF NOT EXISTS idx_runs_schedule\n ON scheduled_runs(schedule_id, ran_at DESC);\n ");
257
257
  return _this;
258
258
  }
259
259
  _create_class(ScheduleDO, [
260
260
  {
261
261
  key: "createSchedule",
262
- value: function createSchedule(brainName, cronExpression) {
262
+ value: function createSchedule(brainTitle, cronExpression) {
263
263
  return _async_to_generator(function() {
264
264
  var id, createdAt, alarm, cron, nextRunAt;
265
265
  return _ts_generator(this, function(_state) {
@@ -293,12 +293,12 @@ export var ScheduleDO = /*#__PURE__*/ function(DurableObject) {
293
293
  // Calculate next run time
294
294
  cron = parseCronExpression(cronExpression);
295
295
  nextRunAt = this.calculateNextRunTime(cron, createdAt);
296
- this.storage.exec("INSERT INTO schedules (id, brain_name, cron_expression, enabled, created_at, next_run_at)\n VALUES (?, ?, ?, 1, ?, ?)", id, brainName, cronExpression, createdAt, nextRunAt);
296
+ this.storage.exec("INSERT INTO schedules (id, brain_title, cron_expression, enabled, created_at, next_run_at)\n VALUES (?, ?, ?, 1, ?, ?)", id, brainTitle, cronExpression, createdAt, nextRunAt);
297
297
  return [
298
298
  2,
299
299
  {
300
300
  id: id,
301
- brainName: brainName,
301
+ brainTitle: brainTitle,
302
302
  cronExpression: cronExpression,
303
303
  enabled: true,
304
304
  createdAt: createdAt,
@@ -316,7 +316,7 @@ export var ScheduleDO = /*#__PURE__*/ function(DurableObject) {
316
316
  return _async_to_generator(function() {
317
317
  var results, result;
318
318
  return _ts_generator(this, function(_state) {
319
- results = this.storage.exec("SELECT id, brain_name, cron_expression, enabled, created_at, next_run_at\n FROM schedules WHERE id = ?", scheduleId).toArray();
319
+ results = this.storage.exec("SELECT id, brain_title, cron_expression, enabled, created_at, next_run_at\n FROM schedules WHERE id = ?", scheduleId).toArray();
320
320
  if (results.length === 0) {
321
321
  return [
322
322
  2,
@@ -328,7 +328,7 @@ export var ScheduleDO = /*#__PURE__*/ function(DurableObject) {
328
328
  2,
329
329
  {
330
330
  id: result.id,
331
- brainName: result.brain_name,
331
+ brainTitle: result.brain_title,
332
332
  cronExpression: result.cron_expression,
333
333
  enabled: result.enabled === 1,
334
334
  createdAt: result.created_at,
@@ -408,10 +408,10 @@ export var ScheduleDO = /*#__PURE__*/ function(DurableObject) {
408
408
  _state.sent();
409
409
  _state.label = 4;
410
410
  case 4:
411
- schedules = this.storage.exec("SELECT id, brain_name, cron_expression, enabled, created_at, next_run_at\n FROM schedules\n ORDER BY created_at DESC").toArray().map(function(row) {
411
+ schedules = this.storage.exec("SELECT id, brain_title, cron_expression, enabled, created_at, next_run_at\n FROM schedules\n ORDER BY created_at DESC").toArray().map(function(row) {
412
412
  return {
413
413
  id: row.id,
414
- brainName: row.brain_name,
414
+ brainTitle: row.brain_title,
415
415
  cronExpression: row.cron_expression,
416
416
  enabled: row.enabled === 1,
417
417
  createdAt: row.created_at,
@@ -485,7 +485,7 @@ export var ScheduleDO = /*#__PURE__*/ function(DurableObject) {
485
485
  value: // Handle the alarm trigger - runs every minute in a perpetual cycle
486
486
  function alarm() {
487
487
  return _async_to_generator(function() {
488
- var now, dueSchedules, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, schedule, scheduleId, brainName, cronExpression, brainRunId, error, errorMessage, cron, nextRunAt, err;
488
+ var now, dueSchedules, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, schedule, scheduleId, brainTitle, cronExpression, brainRunId, error, errorMessage, cron, nextRunAt, err;
489
489
  return _ts_generator(this, function(_state) {
490
490
  switch(_state.label){
491
491
  case 0:
@@ -500,7 +500,7 @@ export var ScheduleDO = /*#__PURE__*/ function(DurableObject) {
500
500
  // checking every minute ensures we never miss a scheduled run.
501
501
  // Get all enabled schedules that are due
502
502
  now = Date.now();
503
- dueSchedules = this.storage.exec("SELECT id, brain_name, cron_expression\n FROM schedules\n WHERE enabled = 1 AND next_run_at <= ?", now).toArray();
503
+ dueSchedules = this.storage.exec("SELECT id, brain_title, cron_expression\n FROM schedules\n WHERE enabled = 1 AND next_run_at <= ?", now).toArray();
504
504
  _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
505
505
  _state.label = 1;
506
506
  case 1:
@@ -519,7 +519,7 @@ export var ScheduleDO = /*#__PURE__*/ function(DurableObject) {
519
519
  ];
520
520
  schedule = _step.value;
521
521
  scheduleId = schedule.id;
522
- brainName = schedule.brain_name;
522
+ brainTitle = schedule.brain_title;
523
523
  cronExpression = schedule.cron_expression;
524
524
  _state.label = 3;
525
525
  case 3:
@@ -531,7 +531,7 @@ export var ScheduleDO = /*#__PURE__*/ function(DurableObject) {
531
531
  ]);
532
532
  return [
533
533
  4,
534
- this.triggerBrainRun(brainName)
534
+ this.triggerBrainRun(brainTitle)
535
535
  ];
536
536
  case 4:
537
537
  brainRunId = _state.sent();
@@ -546,7 +546,7 @@ export var ScheduleDO = /*#__PURE__*/ function(DurableObject) {
546
546
  // Record failed run
547
547
  errorMessage = _instanceof(error, Error) ? error.message : 'Unknown error';
548
548
  this.storage.exec("INSERT INTO scheduled_runs (schedule_id, status, ran_at, error)\n VALUES (?, 'failed', ?, ?)", scheduleId, now, errorMessage);
549
- console.error("[ScheduleDO] Failed to trigger brain ".concat(brainName, ":"), error);
549
+ console.error("[ScheduleDO] Failed to trigger brain ".concat(brainTitle, ":"), error);
550
550
  return [
551
551
  3,
552
552
  6
@@ -621,7 +621,7 @@ export var ScheduleDO = /*#__PURE__*/ function(DurableObject) {
621
621
  },
622
622
  {
623
623
  key: "triggerBrainRun",
624
- value: function triggerBrainRun(brainName) {
624
+ value: function triggerBrainRun(brainTitle) {
625
625
  return _async_to_generator(function() {
626
626
  var brainRunId, namespace, doId, stub;
627
627
  return _ts_generator(this, function(_state) {
@@ -631,10 +631,10 @@ export var ScheduleDO = /*#__PURE__*/ function(DurableObject) {
631
631
  namespace = this.env.BRAIN_RUNNER_DO;
632
632
  doId = namespace.idFromName(brainRunId);
633
633
  stub = namespace.get(doId);
634
- console.log("[ScheduleDO] Triggering brain run ".concat(brainName, " with id ").concat(brainRunId));
634
+ console.log("[ScheduleDO] Triggering brain run ".concat(brainTitle, " with id ").concat(brainRunId));
635
635
  return [
636
636
  4,
637
- stub.start(brainName, brainRunId)
637
+ stub.start(brainTitle, brainRunId)
638
638
  ];
639
639
  case 1:
640
640
  _state.sent();
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAgB,MAAM,MAAM,CAAC;AAI1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAY,MAAM,2BAA2B,CAAC;AAGpE,KAAK,QAAQ,GAAG;IACd,eAAe,EAAE,sBAAsB,CAAC,aAAa,CAAC,CAAC;IACvD,UAAU,EAAE,sBAAsB,CAAC,SAAS,CAAC,CAAC;IAC9C,WAAW,EAAE,sBAAsB,CAAC,UAAU,CAAC,CAAC;IAChD,gBAAgB,EAAE,QAAQ,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAmBF,QAAA,MAAM,GAAG;cAAwB,QAAQ;yCAAK,CAAC;AA+hB/C,eAAe,GAAG,CAAC"}
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAgB,MAAM,MAAM,CAAC;AAI1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAY,MAAM,2BAA2B,CAAC;AAGpE,KAAK,QAAQ,GAAG;IACd,eAAe,EAAE,sBAAsB,CAAC,aAAa,CAAC,CAAC;IACvD,UAAU,EAAE,sBAAsB,CAAC,SAAS,CAAC,CAAC;IAC9C,WAAW,EAAE,sBAAsB,CAAC,UAAU,CAAC,CAAC;IAChD,gBAAgB,EAAE,QAAQ,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAmBF,QAAA,MAAM,GAAG;cAAwB,QAAQ;yCAAK,CAAC;AAupB/C,eAAe,GAAG,CAAC"}
@@ -0,0 +1,32 @@
1
+ import type { Brain } from '@positronic/core';
2
+ export interface BrainMetadata {
3
+ filename: string;
4
+ path: string;
5
+ brain: Brain;
6
+ }
7
+ export interface BrainCandidate {
8
+ title: string;
9
+ filename: string;
10
+ path: string;
11
+ description?: string;
12
+ }
13
+ export interface ResolutionResult {
14
+ matchType: 'exact' | 'multiple' | 'none';
15
+ brain?: Brain;
16
+ candidates?: BrainCandidate[];
17
+ }
18
+ export declare class BrainResolver {
19
+ private enhancedManifest;
20
+ private metadataCache;
21
+ constructor(enhancedManifest: Record<string, BrainMetadata>);
22
+ resolve(identifier: string): ResolutionResult;
23
+ /**
24
+ * Get a brain by exact filename (used for backward compatibility)
25
+ */
26
+ getByFilename(filename: string): Brain | undefined;
27
+ /**
28
+ * List all available brains
29
+ */
30
+ list(): string[];
31
+ }
32
+ //# sourceMappingURL=brain-resolver.d.ts.map