@cnstra/core 2.5.0 → 2.6.0

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 (67) hide show
  1. package/dist/CNS.d.ts +11 -11
  2. package/dist/CNS.d.ts.map +1 -1
  3. package/dist/CNSCollateral.d.ts +2 -2
  4. package/dist/CNSCollateral.d.ts.map +1 -1
  5. package/dist/CNSNetwork.d.ts +7 -7
  6. package/dist/CNSNetwork.d.ts.map +1 -1
  7. package/dist/CNSStimulation.d.ts +23 -15
  8. package/dist/CNSStimulation.d.ts.map +1 -1
  9. package/dist/CNSStimulationContextStore.d.ts +1 -1
  10. package/dist/CNSStimulationContextStore.d.ts.map +1 -1
  11. package/dist/factory/index.d.ts +26 -82
  12. package/dist/factory/index.d.ts.map +1 -1
  13. package/dist/index.cjs +24 -95
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.ts +1 -16
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +25 -93
  18. package/dist/index.js.map +1 -1
  19. package/dist/utils/CNSStimulationGate.d.ts +7 -7
  20. package/dist/utils/CNSStimulationGate.d.ts.map +1 -1
  21. package/package.json +4 -1
  22. package/dist/CNSPersistOptionsRegistry.d.ts +0 -28
  23. package/dist/CNSPersistOptionsRegistry.d.ts.map +0 -1
  24. package/dist/interfaces/ICNS.d.ts +0 -27
  25. package/dist/interfaces/ICNS.d.ts.map +0 -1
  26. package/dist/interfaces/ICNSCollateral.d.ts +0 -6
  27. package/dist/interfaces/ICNSCollateral.d.ts.map +0 -1
  28. package/dist/interfaces/ICNSStimulationContextStore.d.ts +0 -8
  29. package/dist/interfaces/ICNSStimulationContextStore.d.ts.map +0 -1
  30. package/dist/types/TCNSAfferentPath.d.ts +0 -4
  31. package/dist/types/TCNSAfferentPath.d.ts.map +0 -1
  32. package/dist/types/TCNSAxon.d.ts +0 -26
  33. package/dist/types/TCNSAxon.d.ts.map +0 -1
  34. package/dist/types/TCNSDendrite.d.ts +0 -9
  35. package/dist/types/TCNSDendrite.d.ts.map +0 -1
  36. package/dist/types/TCNSHandlerContext.d.ts +0 -24
  37. package/dist/types/TCNSHandlerContext.d.ts.map +0 -1
  38. package/dist/types/TCNSLocalContextValueStore.d.ts +0 -6
  39. package/dist/types/TCNSLocalContextValueStore.d.ts.map +0 -1
  40. package/dist/types/TCNSModality.d.ts +0 -5
  41. package/dist/types/TCNSModality.d.ts.map +0 -1
  42. package/dist/types/TCNSNeuron.d.ts +0 -12
  43. package/dist/types/TCNSNeuron.d.ts.map +0 -1
  44. package/dist/types/TCNSNeuronActivationTask.d.ts +0 -8
  45. package/dist/types/TCNSNeuronActivationTask.d.ts.map +0 -1
  46. package/dist/types/TCNSNeuronActivationTaskFailure.d.ts +0 -7
  47. package/dist/types/TCNSNeuronActivationTaskFailure.d.ts.map +0 -1
  48. package/dist/types/TCNSNeuronResponseReturn.d.ts +0 -9
  49. package/dist/types/TCNSNeuronResponseReturn.d.ts.map +0 -1
  50. package/dist/types/TCNSOptions.d.ts +0 -11
  51. package/dist/types/TCNSOptions.d.ts.map +0 -1
  52. package/dist/types/TCNSPersist.d.ts +0 -16
  53. package/dist/types/TCNSPersist.d.ts.map +0 -1
  54. package/dist/types/TCNSSignal.d.ts +0 -6
  55. package/dist/types/TCNSSignal.d.ts.map +0 -1
  56. package/dist/types/TCNSStimulationDrain.d.ts +0 -37
  57. package/dist/types/TCNSStimulationDrain.d.ts.map +0 -1
  58. package/dist/types/TCNSStimulationOptions.d.ts +0 -32
  59. package/dist/types/TCNSStimulationOptions.d.ts.map +0 -1
  60. package/dist/types/TCNSStimulationQueueItem.d.ts +0 -11
  61. package/dist/types/TCNSStimulationQueueItem.d.ts.map +0 -1
  62. package/dist/types/TCNSStimulationResponse.d.ts +0 -57
  63. package/dist/types/TCNSStimulationResponse.d.ts.map +0 -1
  64. package/dist/types/TCNSStimulationSerializedContextValue.d.ts +0 -4
  65. package/dist/types/TCNSStimulationSerializedContextValue.d.ts.map +0 -1
  66. package/dist/types/TCNSSubscriber.d.ts +0 -7
  67. package/dist/types/TCNSSubscriber.d.ts.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,23 +1,8 @@
1
1
  export { CNS } from './CNS';
2
- export { CNSPersistOptionsRegistry } from './CNSPersistOptionsRegistry';
3
2
  export { CNSCollateral } from './CNSCollateral';
4
3
  export { CNSStimulationContextStore } from './CNSStimulationContextStore';
5
4
  export { CNSStimulationGate } from './utils/CNSStimulationGate';
6
- export type { ICNS } from './interfaces/ICNS';
7
- export type { TCNSNeuron } from './types/TCNSNeuron';
8
- export type { TCNSAxon } from './types/TCNSAxon';
9
- export type { TCNSDendrite } from './types/TCNSDendrite';
10
- export type { TCNSHandlerContext } from './types/TCNSHandlerContext';
11
- export type { TCNSSignal } from './types/TCNSSignal';
12
- export type { TCNSNeuronActivationTask } from './types/TCNSNeuronActivationTask';
13
- export type { TCNSStimulationOptions } from './types/TCNSStimulationOptions';
14
- export type { TCNSStimulationResponse } from './types/TCNSStimulationResponse';
15
- export type { TCNSStimulationDrain } from './types/TCNSStimulationDrain';
16
- export type { TCNSModality } from './types/TCNSModality';
17
- export type { TCNSAfferentPath } from './types/TCNSAfferentPath';
18
- export type { TCNSNeuronActivationTaskFailure } from './types/TCNSNeuronActivationTaskFailure';
19
- export type { TCNSNeuronPersistOptions, TCNSCollateralPersistOptions, TCNSStimulationPersistOptions } from './types/TCNSPersist';
20
5
  export type { TCNSStimulationGateOptions, TCNSStimulationGateSignal } from './utils/CNSStimulationGate';
21
- export { collateral, neuron, neuronFactory, withCtx, withGlobal, afferentPath, modality, createPersistRegistry, createCNS, } from './factory/index';
6
+ export { collateral, neuron, neuronFactory, withCtx, withGlobal, afferentPath, modality, } from './factory/index';
22
7
  export type { TNeuronFactory } from './factory/index';
23
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE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E,cAAc,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAG5B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAKhE,YAAY,EAAE,0BAA0B,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAGxG,OAAO,EACH,UAAU,EACV,MAAM,EACN,aAAa,EACb,OAAO,EACP,UAAU,EACV,YAAY,EACZ,QAAQ,GACX,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC"}
package/dist/index.js CHANGED
@@ -37,6 +37,13 @@ var CNSDendriteContext = class {
37
37
  get global() {
38
38
  return this.cns.global;
39
39
  }
40
+ // The caller-supplied per-stimulation context (`stimulate(sig, {stimulationContext})`),
41
+ // the same value on every hop — the environment-agnostic way to correlate logs to a
42
+ // run (pass `{ stimulationId, attemptNumber }`). Prototype getter like `global`:
43
+ // zero extra allocation, read only where a handler reaches for it.
44
+ get stimulationContext() {
45
+ return this.stimulation.options?.stimulationContext;
46
+ }
40
47
  get() {
41
48
  return this.stimulation.getContext().get(this.neuron);
42
49
  }
@@ -48,7 +55,7 @@ var CNSDendriteContext = class {
48
55
  }
49
56
  };
50
57
  var CNSStimulationResponseImpl = class {
51
- constructor(stimulation, store, inputSignal, outputSignal, queueLength, pendingActivations, activeActivations, hops, error) {
58
+ constructor(stimulation, store, inputSignal, outputSignal, queueLength, pendingActivations, activeActivations, hops, error, neuron2) {
52
59
  this.stimulation = stimulation;
53
60
  this.store = store;
54
61
  this.inputSignal = inputSignal;
@@ -58,6 +65,7 @@ var CNSStimulationResponseImpl = class {
58
65
  this.activeActivations = activeActivations;
59
66
  this.hops = hops;
60
67
  this.error = error;
68
+ this.neuron = neuron2;
61
69
  }
62
70
  get contextValue() {
63
71
  return this.store ? this.store.getAll() : /* @__PURE__ */ new Map();
@@ -331,6 +339,19 @@ var CNSStimulation = class {
331
339
  getFailedTasks() {
332
340
  return this.failedTasks ? [...this.failedTasks] : [];
333
341
  }
342
+ /**
343
+ * The current outstanding frontier — every task that has not completed:
344
+ * queued, active, and pending (awaiting an async onResponse), plus any
345
+ * failed/aborted tasks. This is the set to persist for resume: re-activating
346
+ * it re-runs exactly the not-yet-done work. Safe to call at any point during
347
+ * a run (for progress) or after it fails.
348
+ */
349
+ getOutstandingTasks() {
350
+ return [
351
+ ...this.getAllActivationTasks(),
352
+ ...this.getFailedTasks().map((f) => f.task)
353
+ ];
354
+ }
334
355
  /**
335
356
  * Get the context store for this stimulation
336
357
  */
@@ -662,7 +683,8 @@ var CNSStimulation = class {
662
683
  this.pendingActivations,
663
684
  this.activeOperations,
664
685
  this.options?.maxNeuronHops && emitter ? this.neuronVisitMap?.get(emitter) ?? 0 : void 0,
665
- error
686
+ error,
687
+ emitter
666
688
  )
667
689
  );
668
690
  } catch (e) {
@@ -1211,72 +1233,6 @@ var CNS = class {
1211
1233
  }
1212
1234
  };
1213
1235
 
1214
- // src/CNSPersistOptionsRegistry.ts
1215
- var CNSPersistOptionsRegistry = class {
1216
- constructor() {
1217
- this.neurons = /* @__PURE__ */ new Map();
1218
- this.neuronNames = /* @__PURE__ */ new WeakMap();
1219
- this.collaterals = /* @__PURE__ */ new Map();
1220
- this.stimulations = /* @__PURE__ */ new Map();
1221
- }
1222
- addNeuron(neuron2, options) {
1223
- this.neurons.set(options.name, neuron2);
1224
- this.neuronNames.set(neuron2, options.name);
1225
- }
1226
- getNeuron(name) {
1227
- return this.neurons.get(name);
1228
- }
1229
- getNeuronName(neuron2) {
1230
- return this.neuronNames.get(neuron2);
1231
- }
1232
- getNamedNeurons() {
1233
- return this.neurons;
1234
- }
1235
- getCollateralName(collateral2) {
1236
- for (const [name, col] of this.collaterals) {
1237
- if (col === collateral2) return name;
1238
- }
1239
- return void 0;
1240
- }
1241
- removeNeuron(name) {
1242
- const neuron2 = this.neurons.get(name);
1243
- if (neuron2) this.neuronNames.delete(neuron2);
1244
- this.neurons.delete(name);
1245
- }
1246
- addCollateral(collateral2, options) {
1247
- this.collaterals.set(options.name, collateral2);
1248
- }
1249
- getCollateral(name) {
1250
- return this.collaterals.get(name);
1251
- }
1252
- removeCollateral(name) {
1253
- this.collaterals.delete(name);
1254
- }
1255
- addStimulation(stimulation, options) {
1256
- this.stimulations.set(options.stimulationId, stimulation);
1257
- }
1258
- getStimulation(stimulationId) {
1259
- return this.stimulations.get(stimulationId);
1260
- }
1261
- removeStimulation(stimulationId) {
1262
- this.stimulations.delete(stimulationId);
1263
- }
1264
- register(name, neuron2, collateralNames) {
1265
- this.addNeuron(neuron2, { name, neuron: neuron2 });
1266
- for (const [key, col] of Object.entries(neuron2.axon)) {
1267
- this.addCollateral(col, {
1268
- name: collateralNames?.[key] ?? key,
1269
- collateral: col
1270
- });
1271
- }
1272
- return this;
1273
- }
1274
- registerCollateral(name, collateral2) {
1275
- this.addCollateral(collateral2, { name, collateral: collateral2 });
1276
- return this;
1277
- }
1278
- };
1279
-
1280
1236
  // src/CNSCollateral.ts
1281
1237
  var CNSCollateral = class {
1282
1238
  createSignal(payload) {
@@ -1479,31 +1435,7 @@ var modality = (afferentPaths) => {
1479
1435
  afferentPaths
1480
1436
  };
1481
1437
  };
1482
- var createPersistRegistry = (namedNeurons) => {
1483
- const registry = new CNSPersistOptionsRegistry();
1484
- for (const [name, entry] of Object.entries(namedNeurons)) {
1485
- const isEntry = "neuron" in entry && !("axon" in entry);
1486
- const neuron2 = isEntry ? entry.neuron : entry;
1487
- const colNames = isEntry ? entry.collaterals ?? {} : {};
1488
- registry.addNeuron(neuron2, { name, neuron: neuron2 });
1489
- for (const [key, col] of Object.entries(neuron2.axon)) {
1490
- registry.addCollateral(col, {
1491
- name: colNames[key] ?? key,
1492
- collateral: col
1493
- });
1494
- }
1495
- }
1496
- return registry;
1497
- };
1498
- var createCNS = (namedNeurons, options) => {
1499
- const neurons = Object.values(namedNeurons).map(
1500
- (entry) => entry && typeof entry === "object" && "neuron" in entry ? entry.neuron : entry
1501
- );
1502
- const cns = new CNS(neurons, options, options?.global);
1503
- const registry = createPersistRegistry(namedNeurons);
1504
- return { cns, registry };
1505
- };
1506
1438
 
1507
- export { CNS, CNSCollateral, CNSPersistOptionsRegistry, CNSStimulationContextStore, CNSStimulationGate, afferentPath, collateral, createCNS, createPersistRegistry, modality, neuron, neuronFactory, withCtx, withGlobal };
1439
+ export { CNS, CNSCollateral, CNSStimulationContextStore, CNSStimulationGate, afferentPath, collateral, modality, neuron, neuronFactory, withCtx, withGlobal };
1508
1440
  //# sourceMappingURL=index.js.map
1509
1441
  //# sourceMappingURL=index.js.map