@cnstra/core 2.2.1 → 2.4.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.
- package/README.md +28 -6
- package/dist/CNS.d.ts +7 -1
- package/dist/CNS.d.ts.map +1 -1
- package/dist/CNSNetwork.d.ts +8 -15
- package/dist/CNSNetwork.d.ts.map +1 -1
- package/dist/CNSStimulation.d.ts +1 -1
- package/dist/CNSStimulation.d.ts.map +1 -1
- package/dist/factory/index.d.ts +94 -67
- package/dist/factory/index.d.ts.map +1 -1
- package/dist/index.cjs +103 -70
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +101 -71
- package/dist/index.js.map +1 -1
- package/dist/types/TCNSDendrite.d.ts +3 -8
- package/dist/types/TCNSDendrite.d.ts.map +1 -1
- package/dist/types/TCNSHandlerContext.d.ts +24 -0
- package/dist/types/TCNSHandlerContext.d.ts.map +1 -0
- package/dist/types/TCNSNeuron.d.ts +1 -1
- package/dist/types/TCNSNeuron.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/CNSTaskQueue.d.ts +0 -12
- package/dist/CNSTaskQueue.d.ts.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export type { ICNS } from './interfaces/ICNS';
|
|
|
7
7
|
export type { TCNSNeuron } from './types/TCNSNeuron';
|
|
8
8
|
export type { TCNSAxon } from './types/TCNSAxon';
|
|
9
9
|
export type { TCNSDendrite } from './types/TCNSDendrite';
|
|
10
|
+
export type { TCNSHandlerContext } from './types/TCNSHandlerContext';
|
|
10
11
|
export type { TCNSSignal } from './types/TCNSSignal';
|
|
11
12
|
export type { TCNSNeuronActivationTask } from './types/TCNSNeuronActivationTask';
|
|
12
13
|
export type { TCNSStimulationOptions } from './types/TCNSStimulationOptions';
|
|
@@ -15,5 +16,6 @@ export type { TCNSAfferentPath } from './types/TCNSAfferentPath';
|
|
|
15
16
|
export type { TCNSNeuronActivationTaskFailure } from './types/TCNSNeuronActivationTaskFailure';
|
|
16
17
|
export type { TCNSNeuronPersistOptions, TCNSCollateralPersistOptions, TCNSStimulationPersistOptions } from './types/TCNSPersist';
|
|
17
18
|
export type { TCNSStimulationGateOptions, TCNSStimulationGateSignal } from './utils/CNSStimulationGate';
|
|
18
|
-
export { collateral, neuron, withCtx, afferentPath, modality, createPersistRegistry, } from './factory/index';
|
|
19
|
+
export { collateral, neuron, neuronFactory, withCtx, withGlobal, afferentPath, modality, createPersistRegistry, createCNS, } from './factory/index';
|
|
20
|
+
export type { TNeuronFactory } from './factory/index';
|
|
19
21
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAEhE,YAAY,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAE9C,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,YAAY,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,YAAY,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,YAAY,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AACjF,YAAY,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAC7E,YAAY,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,YAAY,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACjE,YAAY,EAAE,+BAA+B,EAAE,MAAM,yCAAyC,CAAC;AAC/F,YAAY,EAAE,wBAAwB,EAAE,4BAA4B,EAAE,6BAA6B,EAAE,MAAM,qBAAqB,CAAC;AACjI,YAAY,EAAE,0BAA0B,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAGxG,OAAO,EACH,UAAU,EACV,MAAM,EACN,OAAO,EACP,YAAY,EACZ,QAAQ,EACR,qBAAqB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAEhE,YAAY,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAE9C,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,YAAY,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,YAAY,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,YAAY,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACrE,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,YAAY,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AACjF,YAAY,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAC7E,YAAY,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,YAAY,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACjE,YAAY,EAAE,+BAA+B,EAAE,MAAM,yCAAyC,CAAC;AAC/F,YAAY,EAAE,wBAAwB,EAAE,4BAA4B,EAAE,6BAA6B,EAAE,MAAM,qBAAqB,CAAC;AACjI,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,EACR,qBAAqB,EACrB,SAAS,GACZ,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ var CNSStimulationContextStore = class {
|
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
// src/CNSStimulation.ts
|
|
26
|
+
var TASK_DENDRITE = /* @__PURE__ */ Symbol("cnstra.taskDendrite");
|
|
26
27
|
var CNSDendriteContext = class {
|
|
27
28
|
constructor(stimulation, neuron2, abortSignal, cns) {
|
|
28
29
|
this.stimulation = stimulation;
|
|
@@ -30,6 +31,12 @@ var CNSDendriteContext = class {
|
|
|
30
31
|
this.abortSignal = abortSignal;
|
|
31
32
|
this.cns = cns;
|
|
32
33
|
}
|
|
34
|
+
// Prototype getter, not a constructor field: the per-activation allocation is
|
|
35
|
+
// unchanged (still 4 fields) and you only pay a single `cns.global` read on the
|
|
36
|
+
// dendrites that actually reach for it. Value getter, so `{ global }` destructuring is safe.
|
|
37
|
+
get global() {
|
|
38
|
+
return this.cns.global;
|
|
39
|
+
}
|
|
33
40
|
get() {
|
|
34
41
|
return this.stimulation.getContext().get(this.neuron);
|
|
35
42
|
}
|
|
@@ -73,7 +80,7 @@ var CNSStimulation = class {
|
|
|
73
80
|
this.instanceNeuronQueue = instanceNeuronQueue;
|
|
74
81
|
this.onResponse = onResponse;
|
|
75
82
|
if (this.options?.maxNeuronHops) {
|
|
76
|
-
this.
|
|
83
|
+
this.neuronVisitMap = /* @__PURE__ */ new Map();
|
|
77
84
|
}
|
|
78
85
|
if (this.autoCleanupContextsEnabled) {
|
|
79
86
|
this.activeSccCounts = /* @__PURE__ */ new Map();
|
|
@@ -338,14 +345,14 @@ var CNSStimulation = class {
|
|
|
338
345
|
}
|
|
339
346
|
createSubscriberQueueItem(subscriber, inputSignal) {
|
|
340
347
|
if (this.options?.maxNeuronHops) {
|
|
341
|
-
if ((this.
|
|
348
|
+
if ((this.neuronVisitMap?.get(subscriber.neuron) ?? 0) >= this.options?.maxNeuronHops) {
|
|
342
349
|
throw new Error(
|
|
343
350
|
`Max neuron hops reached when trying to enqueue subscriber`
|
|
344
351
|
);
|
|
345
352
|
} else {
|
|
346
|
-
this.
|
|
353
|
+
this.neuronVisitMap?.set(
|
|
347
354
|
subscriber.neuron,
|
|
348
|
-
(this.
|
|
355
|
+
(this.neuronVisitMap?.get(subscriber.neuron) ?? 0) + 1
|
|
349
356
|
);
|
|
350
357
|
}
|
|
351
358
|
}
|
|
@@ -354,17 +361,20 @@ var CNSStimulation = class {
|
|
|
354
361
|
dendriteCollateral: subscriber.dendrite.collateral,
|
|
355
362
|
input: inputSignal
|
|
356
363
|
};
|
|
364
|
+
neuronActivationTask[TASK_DENDRITE] = subscriber;
|
|
357
365
|
return neuronActivationTask;
|
|
358
366
|
}
|
|
359
367
|
executeActivationTask(neuronActivationTask) {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
+
let subscriber = neuronActivationTask[TASK_DENDRITE];
|
|
369
|
+
if (!subscriber) {
|
|
370
|
+
const subscribers = this.cns.network.getSubscribers(
|
|
371
|
+
neuronActivationTask.dendriteCollateral
|
|
372
|
+
);
|
|
373
|
+
for (let i = 0; i < subscribers.length; i++) {
|
|
374
|
+
if (subscribers[i].neuron === neuronActivationTask.neuron) {
|
|
375
|
+
subscriber = subscribers[i];
|
|
376
|
+
break;
|
|
377
|
+
}
|
|
368
378
|
}
|
|
369
379
|
}
|
|
370
380
|
if (!subscriber) {
|
|
@@ -554,7 +564,7 @@ var CNSStimulation = class {
|
|
|
554
564
|
inputSignal,
|
|
555
565
|
outputSignal,
|
|
556
566
|
this.qSize + this.scheduledCount,
|
|
557
|
-
this.options?.maxNeuronHops && emitter ? this.
|
|
567
|
+
this.options?.maxNeuronHops && emitter ? this.neuronVisitMap?.get(emitter) ?? 0 : void 0,
|
|
558
568
|
error
|
|
559
569
|
)
|
|
560
570
|
);
|
|
@@ -669,8 +679,12 @@ var CNSNetwork = class {
|
|
|
669
679
|
/**
|
|
670
680
|
* Strongly Connected Components of the neuron graph.
|
|
671
681
|
* Each component is a set of neuron objects that can reach each other.
|
|
682
|
+
*
|
|
683
|
+
* Computed lazily on first access: the SCC machinery is only needed for
|
|
684
|
+
* `autoCleanupContexts` (off by default), so most networks never pay for it.
|
|
672
685
|
*/
|
|
673
|
-
this.
|
|
686
|
+
this._stronglyConnectedComponents = [];
|
|
687
|
+
this.sccBuilt = false;
|
|
674
688
|
/**
|
|
675
689
|
* Quick lookup: neuron -> SCC index for fast reachability checks.
|
|
676
690
|
*/
|
|
@@ -688,21 +702,18 @@ var CNSNetwork = class {
|
|
|
688
702
|
* Built once at construction time.
|
|
689
703
|
*/
|
|
690
704
|
this.subIndex = /* @__PURE__ */ new Map();
|
|
691
|
-
this.dendriteIndex = /* @__PURE__ */ new Map();
|
|
692
|
-
this.collateralIndex = /* @__PURE__ */ new Set();
|
|
693
705
|
this.parentNeuronByCollateral = /* @__PURE__ */ new Map();
|
|
694
|
-
this.validateUniqueIdentifiers();
|
|
695
706
|
this.buildIndexes();
|
|
696
|
-
this.buildSCC();
|
|
697
707
|
}
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
708
|
+
get stronglyConnectedComponents() {
|
|
709
|
+
this.ensureSCC();
|
|
710
|
+
return this._stronglyConnectedComponents;
|
|
711
|
+
}
|
|
712
|
+
/** Build the SCC analysis the first time anything needs it. */
|
|
713
|
+
ensureSCC() {
|
|
714
|
+
if (this.sccBuilt) return;
|
|
715
|
+
this.sccBuilt = true;
|
|
716
|
+
this.buildSCC();
|
|
706
717
|
}
|
|
707
718
|
/**
|
|
708
719
|
* Build the neuron graph where neurons are connected if one can stimulate the other.
|
|
@@ -777,7 +788,7 @@ var CNSNetwork = class {
|
|
|
777
788
|
strongConnect(neuron2);
|
|
778
789
|
}
|
|
779
790
|
}
|
|
780
|
-
this.
|
|
791
|
+
this._stronglyConnectedComponents = components;
|
|
781
792
|
for (let i = 0; i < components.length; i++) {
|
|
782
793
|
for (const neuronId of Array.from(components[i])) {
|
|
783
794
|
this.neuronToSCC.set(neuronId, i);
|
|
@@ -791,11 +802,11 @@ var CNSNetwork = class {
|
|
|
791
802
|
*/
|
|
792
803
|
buildSCCDAG(neuronGraph) {
|
|
793
804
|
this.sccDag.clear();
|
|
794
|
-
for (let i = 0; i < this.
|
|
805
|
+
for (let i = 0; i < this._stronglyConnectedComponents.length; i++) {
|
|
795
806
|
this.sccDag.set(i, /* @__PURE__ */ new Set());
|
|
796
807
|
}
|
|
797
|
-
for (let i = 0; i < this.
|
|
798
|
-
const scc = this.
|
|
808
|
+
for (let i = 0; i < this._stronglyConnectedComponents.length; i++) {
|
|
809
|
+
const scc = this._stronglyConnectedComponents[i];
|
|
799
810
|
for (const neuron2 of Array.from(scc)) {
|
|
800
811
|
const neighbors = neuronGraph.get(neuron2) || /* @__PURE__ */ new Set();
|
|
801
812
|
for (const neighbor of Array.from(neighbors)) {
|
|
@@ -813,25 +824,27 @@ var CNSNetwork = class {
|
|
|
813
824
|
*/
|
|
814
825
|
buildSCCAncestors() {
|
|
815
826
|
this.sccAncestors.clear();
|
|
816
|
-
for (let i = 0; i < this.
|
|
827
|
+
for (let i = 0; i < this._stronglyConnectedComponents.length; i++) {
|
|
817
828
|
this.sccAncestors.set(i, /* @__PURE__ */ new Set());
|
|
818
829
|
}
|
|
830
|
+
const n = this._stronglyConnectedComponents.length;
|
|
831
|
+
const forward = Array.from({ length: n }, () => []);
|
|
819
832
|
const inDegree = /* @__PURE__ */ new Map();
|
|
820
833
|
const queue = [];
|
|
821
|
-
for (let
|
|
822
|
-
const
|
|
823
|
-
inDegree.set(
|
|
824
|
-
if (
|
|
825
|
-
|
|
834
|
+
for (let target = 0; target < n; target++) {
|
|
835
|
+
const sources = this.sccDag.get(target) || /* @__PURE__ */ new Set();
|
|
836
|
+
inDegree.set(target, sources.size);
|
|
837
|
+
if (sources.size === 0) queue.push(target);
|
|
838
|
+
for (const source of Array.from(sources)) {
|
|
839
|
+
forward[source].push(target);
|
|
826
840
|
}
|
|
827
841
|
}
|
|
828
842
|
while (queue.length > 0) {
|
|
829
843
|
const current = queue.shift();
|
|
830
|
-
const
|
|
831
|
-
for (const neighbor of
|
|
844
|
+
const currentAncestors = this.sccAncestors.get(current);
|
|
845
|
+
for (const neighbor of forward[current]) {
|
|
832
846
|
const neighborAncestors = this.sccAncestors.get(neighbor);
|
|
833
847
|
neighborAncestors.add(current);
|
|
834
|
-
const currentAncestors = this.sccAncestors.get(current);
|
|
835
848
|
for (const ancestor of Array.from(currentAncestors)) {
|
|
836
849
|
neighborAncestors.add(ancestor);
|
|
837
850
|
}
|
|
@@ -843,32 +856,22 @@ var CNSNetwork = class {
|
|
|
843
856
|
}
|
|
844
857
|
}
|
|
845
858
|
}
|
|
846
|
-
/**
|
|
847
|
-
* Get outgoing edges for a given SCC index
|
|
848
|
-
*/
|
|
849
|
-
getOutgoingEdges(sccIndex) {
|
|
850
|
-
const outgoing = /* @__PURE__ */ new Set();
|
|
851
|
-
for (const [targetScc, incomingEdges] of Array.from(this.sccDag)) {
|
|
852
|
-
if (incomingEdges.has(sccIndex)) {
|
|
853
|
-
outgoing.add(targetScc);
|
|
854
|
-
}
|
|
855
|
-
}
|
|
856
|
-
return outgoing;
|
|
857
|
-
}
|
|
858
859
|
/**
|
|
859
860
|
* Check if a neuron can be reached again (including self-calling).
|
|
860
861
|
* Returns true if the neuron is in a strongly connected component with more than one member,
|
|
861
862
|
* or if it's in a single-member SCC that can reach itself.
|
|
862
863
|
*/
|
|
863
864
|
getSCCSetByNeuron(neuron2) {
|
|
865
|
+
this.ensureSCC();
|
|
864
866
|
const sccIndex = this.neuronToSCC.get(neuron2);
|
|
865
867
|
if (sccIndex === void 0) return;
|
|
866
|
-
return this.
|
|
868
|
+
return this._stronglyConnectedComponents[sccIndex];
|
|
867
869
|
}
|
|
868
870
|
/**
|
|
869
871
|
* Get the SCC index for a given neuron
|
|
870
872
|
*/
|
|
871
873
|
getSccIndexByNeuron(neuron2) {
|
|
874
|
+
this.ensureSCC();
|
|
872
875
|
return this.neuronToSCC.get(neuron2);
|
|
873
876
|
}
|
|
874
877
|
/**
|
|
@@ -876,6 +879,7 @@ var CNSNetwork = class {
|
|
|
876
879
|
* This is the core logic for safe context cleanup.
|
|
877
880
|
*/
|
|
878
881
|
canNeuronBeGuaranteedDone(neuron2, activeSccCounts) {
|
|
882
|
+
this.ensureSCC();
|
|
879
883
|
const sccIndex = this.neuronToSCC.get(neuron2);
|
|
880
884
|
if (sccIndex === void 0) return true;
|
|
881
885
|
if (activeSccCounts.get(sccIndex) && activeSccCounts.get(sccIndex) > 0) {
|
|
@@ -893,8 +897,6 @@ var CNSNetwork = class {
|
|
|
893
897
|
buildIndexes() {
|
|
894
898
|
this.subIndex.clear();
|
|
895
899
|
this.parentNeuronByCollateral.clear();
|
|
896
|
-
this.dendriteIndex.clear();
|
|
897
|
-
this.collateralIndex.clear();
|
|
898
900
|
for (const neuron2 of this.neurons) {
|
|
899
901
|
for (const dendrite of neuron2.dendrites) {
|
|
900
902
|
const key = dendrite.collateral;
|
|
@@ -904,25 +906,40 @@ var CNSNetwork = class {
|
|
|
904
906
|
key,
|
|
905
907
|
arr
|
|
906
908
|
);
|
|
907
|
-
this.dendriteIndex.set(key, dendrite);
|
|
908
909
|
}
|
|
909
910
|
Object.values(neuron2.axon).forEach((collateral2) => {
|
|
910
911
|
this.parentNeuronByCollateral.set(
|
|
911
912
|
collateral2,
|
|
912
913
|
neuron2
|
|
913
914
|
);
|
|
914
|
-
this.collateralIndex.add(collateral2);
|
|
915
915
|
});
|
|
916
916
|
}
|
|
917
917
|
}
|
|
918
918
|
getParentNeuronByCollateral(collateral2) {
|
|
919
919
|
return this.parentNeuronByCollateral.get(collateral2);
|
|
920
920
|
}
|
|
921
|
+
// Computed on demand (rarely used): one dendrite per collateral, last wins —
|
|
922
|
+
// preserving the previous index semantics without building it every construct.
|
|
921
923
|
getDendrites() {
|
|
922
|
-
|
|
924
|
+
const byCollateral = /* @__PURE__ */ new Map();
|
|
925
|
+
for (const neuron2 of this.neurons) {
|
|
926
|
+
for (const dendrite of neuron2.dendrites) {
|
|
927
|
+
byCollateral.set(
|
|
928
|
+
dendrite.collateral,
|
|
929
|
+
dendrite
|
|
930
|
+
);
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
return Array.from(byCollateral.values());
|
|
923
934
|
}
|
|
924
935
|
getCollaterals() {
|
|
925
|
-
|
|
936
|
+
const collaterals = /* @__PURE__ */ new Set();
|
|
937
|
+
for (const neuron2 of this.neurons) {
|
|
938
|
+
for (const collateral2 of Object.values(neuron2.axon)) {
|
|
939
|
+
collaterals.add(collateral2);
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
return Array.from(collaterals);
|
|
926
943
|
}
|
|
927
944
|
getSubscribers(collateral2) {
|
|
928
945
|
return this.subIndex.get(collateral2) ?? [];
|
|
@@ -931,7 +948,7 @@ var CNSNetwork = class {
|
|
|
931
948
|
|
|
932
949
|
// src/CNS.ts
|
|
933
950
|
var CNS = class {
|
|
934
|
-
constructor(neurons, options) {
|
|
951
|
+
constructor(neurons, options, global) {
|
|
935
952
|
this.neurons = neurons;
|
|
936
953
|
this.options = options;
|
|
937
954
|
/**
|
|
@@ -944,6 +961,7 @@ var CNS = class {
|
|
|
944
961
|
*/
|
|
945
962
|
this.globalResponseListeners = [];
|
|
946
963
|
this.network = new CNSNetwork(this.neurons);
|
|
964
|
+
this.global = global;
|
|
947
965
|
}
|
|
948
966
|
addResponseListener(listener) {
|
|
949
967
|
this.globalResponseListeners.push(listener);
|
|
@@ -1196,27 +1214,26 @@ var neuron = (axon) => {
|
|
|
1196
1214
|
modality: singleModality,
|
|
1197
1215
|
modalities: multipleModalities,
|
|
1198
1216
|
afferentPaths: singleAfferentPaths,
|
|
1199
|
-
default:
|
|
1200
|
-
default: globalDefaultHandler,
|
|
1217
|
+
default: defaultHandler,
|
|
1201
1218
|
output
|
|
1202
1219
|
} = s;
|
|
1203
1220
|
const modalityConfigs = multipleModalities ? multipleModalities : singleModality ? [
|
|
1204
1221
|
{
|
|
1205
1222
|
modality: singleModality,
|
|
1206
1223
|
afferentPaths: singleAfferentPaths,
|
|
1207
|
-
default:
|
|
1224
|
+
default: defaultHandler
|
|
1208
1225
|
}
|
|
1209
1226
|
] : [];
|
|
1210
1227
|
const response = (payload, axon2, ctx) => {
|
|
1211
1228
|
const stimulation = ctx.stimulation;
|
|
1212
1229
|
const stimOptions = stimulation?.options;
|
|
1213
1230
|
const runGlobalDefault = () => {
|
|
1214
|
-
if (!
|
|
1231
|
+
if (!defaultHandler) {
|
|
1215
1232
|
throw new Error(
|
|
1216
1233
|
`modalityDendrite: No handler found for modality and no default handler provided`
|
|
1217
1234
|
);
|
|
1218
1235
|
}
|
|
1219
|
-
const res =
|
|
1236
|
+
const res = defaultHandler(payload, axon2, ctx);
|
|
1220
1237
|
if (res && typeof res.then === "function") {
|
|
1221
1238
|
return res.then(
|
|
1222
1239
|
(result) => output(result, axon2, ctx)
|
|
@@ -1235,7 +1252,7 @@ var neuron = (axon) => {
|
|
|
1235
1252
|
}
|
|
1236
1253
|
const stimAfferentPath = stimOptions.afferentPath;
|
|
1237
1254
|
const handler = stimAfferentPath && matchingConfig.afferentPaths ? matchingConfig.afferentPaths.get(stimAfferentPath) : void 0;
|
|
1238
|
-
const effectiveHandler = handler ?? matchingConfig.default ??
|
|
1255
|
+
const effectiveHandler = handler ?? matchingConfig.default ?? defaultHandler;
|
|
1239
1256
|
if (!effectiveHandler) {
|
|
1240
1257
|
throw new Error(
|
|
1241
1258
|
`modalityDendrite: No handler found for afferent path in modality and no default handler provided`
|
|
@@ -1270,11 +1287,16 @@ var neuron = (axon) => {
|
|
|
1270
1287
|
};
|
|
1271
1288
|
return api;
|
|
1272
1289
|
};
|
|
1273
|
-
var
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1290
|
+
var neuronFactory = () => {
|
|
1291
|
+
const factory = {
|
|
1292
|
+
withCtx: () => factory,
|
|
1293
|
+
withGlobal: () => factory,
|
|
1294
|
+
neuron: (axon) => neuron(axon)
|
|
1295
|
+
};
|
|
1296
|
+
return factory;
|
|
1297
|
+
};
|
|
1298
|
+
var withCtx = () => neuronFactory();
|
|
1299
|
+
var withGlobal = () => neuronFactory();
|
|
1278
1300
|
var afferentPath = (parentAfferentPath) => {
|
|
1279
1301
|
return {
|
|
1280
1302
|
...parentAfferentPath !== void 0 && {
|
|
@@ -1303,7 +1325,15 @@ var createPersistRegistry = (namedNeurons) => {
|
|
|
1303
1325
|
}
|
|
1304
1326
|
return registry;
|
|
1305
1327
|
};
|
|
1328
|
+
var createCNS = (namedNeurons, options) => {
|
|
1329
|
+
const neurons = Object.values(namedNeurons).map(
|
|
1330
|
+
(entry) => entry && typeof entry === "object" && "neuron" in entry ? entry.neuron : entry
|
|
1331
|
+
);
|
|
1332
|
+
const cns = new CNS(neurons, options, options?.global);
|
|
1333
|
+
const registry = createPersistRegistry(namedNeurons);
|
|
1334
|
+
return { cns, registry };
|
|
1335
|
+
};
|
|
1306
1336
|
|
|
1307
|
-
export { CNS, CNSCollateral, CNSPersistOptionsRegistry, CNSStimulationContextStore, CNSStimulationGate, afferentPath, collateral, createPersistRegistry, modality, neuron, withCtx };
|
|
1337
|
+
export { CNS, CNSCollateral, CNSPersistOptionsRegistry, CNSStimulationContextStore, CNSStimulationGate, afferentPath, collateral, createCNS, createPersistRegistry, modality, neuron, neuronFactory, withCtx, withGlobal };
|
|
1308
1338
|
//# sourceMappingURL=index.js.map
|
|
1309
1339
|
//# sourceMappingURL=index.js.map
|