@positronic/core 0.0.1 → 0.0.3

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.
Files changed (79) hide show
  1. package/CLAUDE.md +141 -0
  2. package/dist/src/adapters/types.js +1 -16
  3. package/dist/src/clients/types.js +4 -1
  4. package/dist/src/dsl/brain-runner.js +487 -0
  5. package/dist/src/dsl/brain-runner.test.js +733 -0
  6. package/dist/src/dsl/brain.js +1128 -0
  7. package/dist/src/dsl/brain.test.js +4225 -0
  8. package/dist/src/dsl/constants.js +6 -6
  9. package/dist/src/dsl/json-patch.js +37 -9
  10. package/dist/src/index.js +11 -10
  11. package/dist/src/resources/resources.js +371 -0
  12. package/dist/src/test-utils.js +474 -0
  13. package/dist/src/testing.js +3 -0
  14. package/dist/types/adapters/types.d.ts +3 -8
  15. package/dist/types/adapters/types.d.ts.map +1 -1
  16. package/dist/types/clients/types.d.ts +46 -6
  17. package/dist/types/clients/types.d.ts.map +1 -1
  18. package/dist/types/dsl/brain-runner.d.ts +24 -0
  19. package/dist/types/dsl/brain-runner.d.ts.map +1 -0
  20. package/dist/types/dsl/brain.d.ts +136 -0
  21. package/dist/types/dsl/brain.d.ts.map +1 -0
  22. package/dist/types/dsl/constants.d.ts +5 -5
  23. package/dist/types/dsl/constants.d.ts.map +1 -1
  24. package/dist/types/dsl/json-patch.d.ts +2 -1
  25. package/dist/types/dsl/json-patch.d.ts.map +1 -1
  26. package/dist/types/index.d.ts +13 -11
  27. package/dist/types/index.d.ts.map +1 -1
  28. package/dist/types/resources/resource-loader.d.ts +6 -0
  29. package/dist/types/resources/resource-loader.d.ts.map +1 -0
  30. package/dist/types/resources/resources.d.ts +23 -0
  31. package/dist/types/resources/resources.d.ts.map +1 -0
  32. package/dist/types/test-utils.d.ts +94 -0
  33. package/dist/types/test-utils.d.ts.map +1 -0
  34. package/dist/types/testing.d.ts +2 -0
  35. package/dist/types/testing.d.ts.map +1 -0
  36. package/docs/core-testing-guide.md +289 -0
  37. package/package.json +26 -7
  38. package/src/adapters/types.ts +3 -22
  39. package/src/clients/types.ts +50 -10
  40. package/src/dsl/brain-runner.test.ts +384 -0
  41. package/src/dsl/brain-runner.ts +111 -0
  42. package/src/dsl/brain.test.ts +1981 -0
  43. package/src/dsl/brain.ts +740 -0
  44. package/src/dsl/constants.ts +6 -6
  45. package/src/dsl/json-patch.ts +24 -9
  46. package/src/dsl/types.ts +1 -1
  47. package/src/index.ts +30 -16
  48. package/src/resources/resource-loader.ts +8 -0
  49. package/src/resources/resources.ts +267 -0
  50. package/src/test-utils.ts +254 -0
  51. package/test/resources.test.ts +248 -0
  52. package/tsconfig.json +2 -2
  53. package/.swcrc +0 -31
  54. package/dist/src/dsl/extensions.js +0 -19
  55. package/dist/src/dsl/workflow-runner.js +0 -93
  56. package/dist/src/dsl/workflow.js +0 -308
  57. package/dist/src/file-stores/local-file-store.js +0 -12
  58. package/dist/src/utils/temp-files.js +0 -27
  59. package/dist/types/dsl/extensions.d.ts +0 -18
  60. package/dist/types/dsl/extensions.d.ts.map +0 -1
  61. package/dist/types/dsl/workflow-runner.d.ts +0 -28
  62. package/dist/types/dsl/workflow-runner.d.ts.map +0 -1
  63. package/dist/types/dsl/workflow.d.ts +0 -118
  64. package/dist/types/dsl/workflow.d.ts.map +0 -1
  65. package/dist/types/file-stores/local-file-store.d.ts +0 -7
  66. package/dist/types/file-stores/local-file-store.d.ts.map +0 -1
  67. package/dist/types/file-stores/types.d.ts +0 -4
  68. package/dist/types/file-stores/types.d.ts.map +0 -1
  69. package/dist/types/utils/temp-files.d.ts +0 -12
  70. package/dist/types/utils/temp-files.d.ts.map +0 -1
  71. package/src/dsl/extensions.ts +0 -58
  72. package/src/dsl/workflow-runner.test.ts +0 -203
  73. package/src/dsl/workflow-runner.ts +0 -146
  74. package/src/dsl/workflow.test.ts +0 -1435
  75. package/src/dsl/workflow.ts +0 -554
  76. package/src/file-stores/local-file-store.ts +0 -11
  77. package/src/file-stores/types.ts +0 -3
  78. package/src/utils/temp-files.ts +0 -46
  79. /package/dist/src/{file-stores/types.js → resources/resource-loader.js} +0 -0
@@ -1,13 +1,13 @@
1
- export const WORKFLOW_EVENTS = {
2
- START: 'workflow:start',
3
- RESTART: 'workflow:restart',
1
+ export var BRAIN_EVENTS = {
2
+ START: 'brain:start',
3
+ RESTART: 'brain:restart',
4
4
  STEP_START: 'step:start',
5
5
  STEP_COMPLETE: 'step:complete',
6
6
  STEP_STATUS: 'step:status',
7
- ERROR: 'workflow:error',
8
- COMPLETE: 'workflow:complete'
7
+ ERROR: 'brain:error',
8
+ COMPLETE: 'brain:complete'
9
9
  };
10
- export const STATUS = {
10
+ export var STATUS = {
11
11
  PENDING: 'pending',
12
12
  RUNNING: 'running',
13
13
  COMPLETE: 'complete',
@@ -1,30 +1,58 @@
1
+ function _define_property(obj, key, value) {
2
+ if (key in obj) {
3
+ Object.defineProperty(obj, key, {
4
+ value: value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ } else {
10
+ obj[key] = value;
11
+ }
12
+ return obj;
13
+ }
14
+ function _object_spread(target) {
15
+ for(var i = 1; i < arguments.length; i++){
16
+ var source = arguments[i] != null ? arguments[i] : {};
17
+ var ownKeys = Object.keys(source);
18
+ if (typeof Object.getOwnPropertySymbols === "function") {
19
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
20
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
21
+ }));
22
+ }
23
+ ownKeys.forEach(function(key) {
24
+ _define_property(target, key, source[key]);
25
+ });
26
+ }
27
+ return target;
28
+ }
1
29
  import pkg from 'fast-json-patch';
2
- const { compare, applyPatch } = pkg;
30
+ var compare = pkg.compare, applyPatch = pkg.applyPatch;
3
31
  /**
4
32
  * Creates a JSON Patch that describes the changes needed to transform prevState into nextState.
5
33
  */ export function createPatch(prevState, nextState) {
6
34
  // Filter out non-standard operations and ensure type safety
7
- return compare(prevState, nextState).filter((op)=>[
35
+ return compare(prevState, nextState).filter(function(op) {
36
+ return [
8
37
  'add',
9
38
  'remove',
10
39
  'replace',
11
40
  'move',
12
41
  'copy',
13
42
  'test'
14
- ].includes(op.op));
43
+ ].includes(op.op);
44
+ });
15
45
  }
16
46
  /**
17
47
  * Applies one or more JSON Patches to a state object and returns the resulting state.
18
48
  * If multiple patches are provided, they are applied in sequence.
19
49
  */ export function applyPatches(state, patches) {
20
- const patchArray = Array.isArray(patches[0]) ? patches : [
50
+ var patchArray = Array.isArray(patches[0]) ? patches : [
21
51
  patches
22
52
  ];
23
53
  // Apply patches in sequence, creating a new state object each time
24
- return patchArray.reduce((currentState, patch)=>{
25
- const { newDocument } = applyPatch(currentState, patch, true, false);
54
+ return patchArray.reduce(function(currentState, patch) {
55
+ var newDocument = applyPatch(currentState, patch, true, false).newDocument;
26
56
  return newDocument;
27
- }, {
28
- ...state
29
- });
57
+ }, _object_spread({}, state));
30
58
  }
package/dist/src/index.js CHANGED
@@ -1,10 +1,11 @@
1
- export { Workflow } from "./dsl/workflow.js";
2
- export { workflow } from "./dsl/workflow.js";
3
- export { WorkflowRunner } from "./dsl/workflow-runner.js";
4
- export { createExtension } from "./dsl/extensions.js";
5
- export { STATUS } from "./dsl/constants.js";
6
- export { WORKFLOW_EVENTS } from "./dsl/constants.js";
7
- export { Adapter } from "./adapters/types.js";
8
- export { createPatch } from "./dsl/json-patch.js";
9
- export { applyPatches } from "./dsl/json-patch.js";
10
- export { LocalFileStore } from "./file-stores/local-file-store.js";
1
+ export { Brain, brain } from './dsl/brain.js';
2
+ export { BrainRunner } from './dsl/brain-runner.js';
3
+ export { STATUS, BRAIN_EVENTS } from './dsl/constants.js';
4
+ export { createPatch, applyPatches } from './dsl/json-patch.js';
5
+ // Only needed for development to ensure that zod version numbers are the same, it's a peer
6
+ // dependency so when not using file://..path/to/package links the version numbers
7
+ // will match just fine if the user has the same version of zod installed.
8
+ // NOTE: Not 100% sure this is still needed - worth re-evaluating if we can remove this.
9
+ export { z } from 'zod';
10
+ export { createResources } from './resources/resources.js';
11
+ export { RESOURCE_TYPES } from './resources/resources.js';
@@ -0,0 +1,371 @@
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_without_holes(arr) {
7
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
8
+ }
9
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
10
+ try {
11
+ var info = gen[key](arg);
12
+ var value = info.value;
13
+ } catch (error) {
14
+ reject(error);
15
+ return;
16
+ }
17
+ if (info.done) {
18
+ resolve(value);
19
+ } else {
20
+ Promise.resolve(value).then(_next, _throw);
21
+ }
22
+ }
23
+ function _async_to_generator(fn) {
24
+ return function() {
25
+ var self = this, args = arguments;
26
+ return new Promise(function(resolve, reject) {
27
+ var gen = fn.apply(self, args);
28
+ function _next(value) {
29
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
30
+ }
31
+ function _throw(err) {
32
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
33
+ }
34
+ _next(undefined);
35
+ });
36
+ };
37
+ }
38
+ function _iterable_to_array(iter) {
39
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
40
+ }
41
+ function _non_iterable_spread() {
42
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
43
+ }
44
+ function _to_consumable_array(arr) {
45
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
46
+ }
47
+ function _type_of(obj) {
48
+ "@swc/helpers - typeof";
49
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
50
+ }
51
+ function _unsupported_iterable_to_array(o, minLen) {
52
+ if (!o) return;
53
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
54
+ var n = Object.prototype.toString.call(o).slice(8, -1);
55
+ if (n === "Object" && o.constructor) n = o.constructor.name;
56
+ if (n === "Map" || n === "Set") return Array.from(n);
57
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
58
+ }
59
+ function _ts_generator(thisArg, body) {
60
+ var f, y, t, _ = {
61
+ label: 0,
62
+ sent: function() {
63
+ if (t[0] & 1) throw t[1];
64
+ return t[1];
65
+ },
66
+ trys: [],
67
+ ops: []
68
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
69
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
70
+ return this;
71
+ }), g;
72
+ function verb(n) {
73
+ return function(v) {
74
+ return step([
75
+ n,
76
+ v
77
+ ]);
78
+ };
79
+ }
80
+ function step(op) {
81
+ if (f) throw new TypeError("Generator is already executing.");
82
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
83
+ 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;
84
+ if (y = 0, t) op = [
85
+ op[0] & 2,
86
+ t.value
87
+ ];
88
+ switch(op[0]){
89
+ case 0:
90
+ case 1:
91
+ t = op;
92
+ break;
93
+ case 4:
94
+ _.label++;
95
+ return {
96
+ value: op[1],
97
+ done: false
98
+ };
99
+ case 5:
100
+ _.label++;
101
+ y = op[1];
102
+ op = [
103
+ 0
104
+ ];
105
+ continue;
106
+ case 7:
107
+ op = _.ops.pop();
108
+ _.trys.pop();
109
+ continue;
110
+ default:
111
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
112
+ _ = 0;
113
+ continue;
114
+ }
115
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
116
+ _.label = op[1];
117
+ break;
118
+ }
119
+ if (op[0] === 6 && _.label < t[1]) {
120
+ _.label = t[1];
121
+ t = op;
122
+ break;
123
+ }
124
+ if (t && _.label < t[2]) {
125
+ _.label = t[2];
126
+ _.ops.push(op);
127
+ break;
128
+ }
129
+ if (t[2]) _.ops.pop();
130
+ _.trys.pop();
131
+ continue;
132
+ }
133
+ op = body.call(thisArg, _);
134
+ } catch (e) {
135
+ op = [
136
+ 6,
137
+ e
138
+ ];
139
+ y = 0;
140
+ } finally{
141
+ f = t = 0;
142
+ }
143
+ if (op[0] & 5) throw op[1];
144
+ return {
145
+ value: op[0] ? op[1] : void 0,
146
+ done: true
147
+ };
148
+ }
149
+ }
150
+ // Runtime array of valid resource types
151
+ export var RESOURCE_TYPES = [
152
+ 'text',
153
+ 'binary'
154
+ ];
155
+ function isResourceEntry(entry) {
156
+ return typeof entry.type === 'string';
157
+ }
158
+ export function createResources(loader, initialManifest) {
159
+ // Helper function to find a resource entry by path in the manifest
160
+ function findResourceByPath(manifest, path) {
161
+ var _loop = function(i) {
162
+ var part = parts[i];
163
+ if (isResourceEntry(current)) {
164
+ // We hit a resource entry before consuming all parts
165
+ return {
166
+ v: null
167
+ };
168
+ }
169
+ var currentManifest = current;
170
+ var next = currentManifest[part];
171
+ if (!next) {
172
+ // If exact match not found and this is the last part, try without extension
173
+ if (i === parts.length - 1) {
174
+ var partWithoutExt = part.replace(/\.[^/.]+$/, '');
175
+ var currentManifest1 = current; // We know it's a Manifest since we checked isResourceEntry above
176
+ var matches = Object.keys(currentManifest1).filter(function(key) {
177
+ var keyWithoutExt = key.replace(/\.[^/.]+$/, '');
178
+ return keyWithoutExt === partWithoutExt && isResourceEntry(currentManifest1[key]);
179
+ });
180
+ if (matches.length === 1) {
181
+ return {
182
+ v: currentManifest1[matches[0]]
183
+ };
184
+ } else if (matches.length > 1) {
185
+ throw new Error("Ambiguous resource path '".concat(path, "': found ").concat(matches.join(', '), ". ") + "Please specify the full filename with extension.");
186
+ }
187
+ }
188
+ return {
189
+ v: null
190
+ };
191
+ }
192
+ if (i === parts.length - 1 && isResourceEntry(next)) {
193
+ // Found the resource
194
+ return {
195
+ v: next
196
+ };
197
+ }
198
+ current = next;
199
+ };
200
+ var parts = path.split('/');
201
+ var current = manifest;
202
+ for(var i = 0; i < parts.length; i++){
203
+ var _ret = _loop(i);
204
+ if (_type_of(_ret) === "object") return _ret.v;
205
+ }
206
+ return null;
207
+ }
208
+ function createProxiedResources(manifestNode) {
209
+ // Create methods that will be shared across all instances
210
+ var loadText = function(path) {
211
+ return _async_to_generator(function() {
212
+ var entry;
213
+ return _ts_generator(this, function(_state) {
214
+ entry = findResourceByPath(manifestNode, path);
215
+ if (!entry) {
216
+ throw new Error("Resource not found: ".concat(path));
217
+ }
218
+ if (entry.type !== 'text') {
219
+ throw new Error('Resource "'.concat(path, '" is of type "').concat(entry.type, '", but was accessed with loadText().'));
220
+ }
221
+ return [
222
+ 2,
223
+ loader.load(entry.key, 'text')
224
+ ];
225
+ });
226
+ })();
227
+ };
228
+ var loadBinary = function(path) {
229
+ return _async_to_generator(function() {
230
+ var entry;
231
+ return _ts_generator(this, function(_state) {
232
+ entry = findResourceByPath(manifestNode, path);
233
+ if (!entry) {
234
+ throw new Error("Resource not found: ".concat(path));
235
+ }
236
+ if (entry.type !== 'binary') {
237
+ throw new Error('Resource "'.concat(path, '" is of type "').concat(entry.type, '", but was accessed with loadBinary().'));
238
+ }
239
+ return [
240
+ 2,
241
+ loader.load(entry.key, 'binary')
242
+ ];
243
+ });
244
+ })();
245
+ };
246
+ var resultProxy = new Proxy({}, {
247
+ get: function(target, prop, receiver) {
248
+ if (prop === 'loadText') {
249
+ return loadText;
250
+ }
251
+ if (prop === 'loadBinary') {
252
+ return loadBinary;
253
+ }
254
+ // Handle dynamic resource properties
255
+ if (typeof prop !== 'string') {
256
+ return Reflect.get(target, prop, receiver);
257
+ }
258
+ // Check if the property exists directly (with extension)
259
+ if (prop in manifestNode) {
260
+ var manifestEntry = manifestNode[prop];
261
+ if (isResourceEntry(manifestEntry)) {
262
+ var key = manifestEntry.key, type = manifestEntry.type;
263
+ var apiObject = {
264
+ load: function() {
265
+ return manifestEntry.type === 'text' ? loader.load(key, 'text') : loader.load(key, 'binary');
266
+ },
267
+ loadText: function() {
268
+ if (type !== 'text') {
269
+ throw new Error('Resource "'.concat(prop, '" is of type "').concat(type, '", but was accessed with loadText().'));
270
+ }
271
+ return loader.load(key, 'text');
272
+ },
273
+ loadBinary: function() {
274
+ if (type !== 'binary') {
275
+ throw new Error('Resource "'.concat(prop, '" is of type "').concat(type, '", but was accessed with loadBinary().'));
276
+ }
277
+ return loader.load(key, 'binary');
278
+ }
279
+ };
280
+ return apiObject;
281
+ } else {
282
+ // manifestEntry is a nested Manifest
283
+ var nestedResources = createProxiedResources(manifestEntry);
284
+ return nestedResources;
285
+ }
286
+ }
287
+ // If not found directly, check for files without extension
288
+ // Find all keys that match when extension is removed
289
+ var matches = Object.keys(manifestNode).filter(function(key) {
290
+ var keyWithoutExt = key.replace(/\.[^/.]+$/, '');
291
+ return keyWithoutExt === prop && isResourceEntry(manifestNode[key]);
292
+ });
293
+ if (matches.length === 0) {
294
+ // No matches - might be a nested directory
295
+ if (prop in manifestNode && !isResourceEntry(manifestNode[prop])) {
296
+ return createProxiedResources(manifestNode[prop]);
297
+ }
298
+ return undefined;
299
+ }
300
+ if (matches.length === 1) {
301
+ // Single match - return it
302
+ var manifestEntry1 = manifestNode[matches[0]];
303
+ var key1 = manifestEntry1.key, type1 = manifestEntry1.type;
304
+ var apiObject1 = {
305
+ load: function() {
306
+ return type1 === 'text' ? loader.load(key1, 'text') : loader.load(key1, 'binary');
307
+ },
308
+ loadText: function() {
309
+ if (type1 !== 'text') {
310
+ throw new Error('Resource "'.concat(matches[0], '" is of type "').concat(type1, '", but was accessed with loadText().'));
311
+ }
312
+ return loader.load(key1, 'text');
313
+ },
314
+ loadBinary: function() {
315
+ if (type1 !== 'binary') {
316
+ throw new Error('Resource "'.concat(matches[0], '" is of type "').concat(type1, '", but was accessed with loadBinary().'));
317
+ }
318
+ return loader.load(key1, 'binary');
319
+ }
320
+ };
321
+ return apiObject1;
322
+ }
323
+ // Multiple matches - throw helpful error
324
+ throw new Error("Ambiguous resource name '".concat(prop, "': found ").concat(matches.join(', '), ". ") + "Please use resources.loadText('".concat(matches[0], "') or resources.loadBinary('").concat(matches[1], "') instead."));
325
+ },
326
+ has: function(target, prop) {
327
+ // Check for special methods
328
+ if (prop === 'loadText' || prop === 'loadBinary') {
329
+ return true;
330
+ }
331
+ // Then check manifest
332
+ if (typeof prop === 'string') {
333
+ return prop in manifestNode;
334
+ }
335
+ return Reflect.has(target, prop);
336
+ },
337
+ ownKeys: function(target) {
338
+ // Combine special methods with manifest keys
339
+ return [
340
+ 'loadText',
341
+ 'loadBinary'
342
+ ].concat(_to_consumable_array(Object.keys(manifestNode)));
343
+ },
344
+ getOwnPropertyDescriptor: function(target, prop) {
345
+ if (prop === 'loadText' || prop === 'loadBinary') {
346
+ return {
347
+ value: prop === 'loadText' ? loadText : loadBinary,
348
+ writable: false,
349
+ enumerable: true,
350
+ configurable: true
351
+ };
352
+ }
353
+ if (typeof prop === 'string' && prop in manifestNode) {
354
+ var value = resultProxy[prop];
355
+ if (value === undefined) {
356
+ return undefined;
357
+ }
358
+ return {
359
+ value: value,
360
+ writable: false,
361
+ enumerable: true,
362
+ configurable: true
363
+ };
364
+ }
365
+ return Reflect.getOwnPropertyDescriptor(target, prop);
366
+ }
367
+ });
368
+ return resultProxy;
369
+ }
370
+ return createProxiedResources(initialManifest);
371
+ }