@cnstra/core 2.5.0 → 3.0.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 +3 -4
- package/dist/CNS.d.ts +16 -12
- package/dist/CNS.d.ts.map +1 -1
- package/dist/CNSCollateral.d.ts +2 -2
- package/dist/CNSCollateral.d.ts.map +1 -1
- package/dist/CNSNetwork.d.ts +11 -10
- package/dist/CNSNetwork.d.ts.map +1 -1
- package/dist/CNSStimulation.d.ts +21 -48
- package/dist/CNSStimulation.d.ts.map +1 -1
- package/dist/factory/index.d.ts +45 -105
- package/dist/factory/index.d.ts.map +1 -1
- package/dist/index.cjs +44 -247
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +45 -243
- package/dist/index.js.map +1 -1
- package/dist/utils/CNSStimulationGate.d.ts +9 -9
- package/dist/utils/CNSStimulationGate.d.ts.map +1 -1
- package/package.json +5 -2
- package/dist/CNSPersistOptionsRegistry.d.ts +0 -28
- package/dist/CNSPersistOptionsRegistry.d.ts.map +0 -1
- package/dist/CNSStimulationContextStore.d.ts +0 -11
- package/dist/CNSStimulationContextStore.d.ts.map +0 -1
- package/dist/interfaces/ICNS.d.ts +0 -27
- package/dist/interfaces/ICNS.d.ts.map +0 -1
- package/dist/interfaces/ICNSCollateral.d.ts +0 -6
- package/dist/interfaces/ICNSCollateral.d.ts.map +0 -1
- package/dist/interfaces/ICNSStimulationContextStore.d.ts +0 -8
- package/dist/interfaces/ICNSStimulationContextStore.d.ts.map +0 -1
- package/dist/types/TCNSAfferentPath.d.ts +0 -4
- package/dist/types/TCNSAfferentPath.d.ts.map +0 -1
- package/dist/types/TCNSAxon.d.ts +0 -26
- package/dist/types/TCNSAxon.d.ts.map +0 -1
- package/dist/types/TCNSDendrite.d.ts +0 -9
- package/dist/types/TCNSDendrite.d.ts.map +0 -1
- package/dist/types/TCNSHandlerContext.d.ts +0 -24
- package/dist/types/TCNSHandlerContext.d.ts.map +0 -1
- package/dist/types/TCNSLocalContextValueStore.d.ts +0 -6
- package/dist/types/TCNSLocalContextValueStore.d.ts.map +0 -1
- package/dist/types/TCNSModality.d.ts +0 -5
- package/dist/types/TCNSModality.d.ts.map +0 -1
- package/dist/types/TCNSNeuron.d.ts +0 -12
- package/dist/types/TCNSNeuron.d.ts.map +0 -1
- package/dist/types/TCNSNeuronActivationTask.d.ts +0 -8
- package/dist/types/TCNSNeuronActivationTask.d.ts.map +0 -1
- package/dist/types/TCNSNeuronActivationTaskFailure.d.ts +0 -7
- package/dist/types/TCNSNeuronActivationTaskFailure.d.ts.map +0 -1
- package/dist/types/TCNSNeuronResponseReturn.d.ts +0 -9
- package/dist/types/TCNSNeuronResponseReturn.d.ts.map +0 -1
- package/dist/types/TCNSOptions.d.ts +0 -11
- package/dist/types/TCNSOptions.d.ts.map +0 -1
- package/dist/types/TCNSPersist.d.ts +0 -16
- package/dist/types/TCNSPersist.d.ts.map +0 -1
- package/dist/types/TCNSSignal.d.ts +0 -6
- package/dist/types/TCNSSignal.d.ts.map +0 -1
- package/dist/types/TCNSStimulationDrain.d.ts +0 -37
- package/dist/types/TCNSStimulationDrain.d.ts.map +0 -1
- package/dist/types/TCNSStimulationOptions.d.ts +0 -32
- package/dist/types/TCNSStimulationOptions.d.ts.map +0 -1
- package/dist/types/TCNSStimulationQueueItem.d.ts +0 -11
- package/dist/types/TCNSStimulationQueueItem.d.ts.map +0 -1
- package/dist/types/TCNSStimulationResponse.d.ts +0 -57
- package/dist/types/TCNSStimulationResponse.d.ts.map +0 -1
- package/dist/types/TCNSStimulationSerializedContextValue.d.ts +0 -4
- package/dist/types/TCNSStimulationSerializedContextValue.d.ts.map +0 -1
- package/dist/types/TCNSSubscriber.d.ts +0 -7
- package/dist/types/TCNSSubscriber.d.ts.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,58 +1,30 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
// src/CNSStimulationContextStore.ts
|
|
4
|
-
var CNSStimulationContextStore = class {
|
|
5
|
-
constructor(ctx) {
|
|
6
|
-
this.ctx = ctx;
|
|
7
|
-
}
|
|
8
|
-
get(key) {
|
|
9
|
-
return this.ctx?.get(key);
|
|
10
|
-
}
|
|
11
|
-
set(key, value) {
|
|
12
|
-
(this.ctx ?? (this.ctx = /* @__PURE__ */ new Map())).set(key, value);
|
|
13
|
-
}
|
|
14
|
-
getAll() {
|
|
15
|
-
return this.ctx ? new Map(this.ctx) : /* @__PURE__ */ new Map();
|
|
16
|
-
}
|
|
17
|
-
setAll(values) {
|
|
18
|
-
const ctx = this.ctx ?? (this.ctx = /* @__PURE__ */ new Map());
|
|
19
|
-
ctx.clear();
|
|
20
|
-
for (const [key, value] of values) ctx.set(key, value);
|
|
21
|
-
}
|
|
22
|
-
delete(key) {
|
|
23
|
-
this.ctx?.delete(key);
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
|
|
27
3
|
// src/CNSStimulation.ts
|
|
28
4
|
var TASK_DENDRITE = /* @__PURE__ */ Symbol("cnstra.taskDendrite");
|
|
29
5
|
var CNSDendriteContext = class {
|
|
30
|
-
constructor(stimulation,
|
|
6
|
+
constructor(stimulation, abortSignal, cns) {
|
|
31
7
|
this.stimulation = stimulation;
|
|
32
|
-
this.neuron = neuron2;
|
|
33
8
|
this.abortSignal = abortSignal;
|
|
34
9
|
this.cns = cns;
|
|
35
10
|
}
|
|
36
|
-
// Prototype getter, not a constructor field:
|
|
37
|
-
//
|
|
38
|
-
//
|
|
11
|
+
// Prototype getter, not a constructor field: you only pay a single `cns.global`
|
|
12
|
+
// read on the dendrites that actually reach for it. Value getter, so
|
|
13
|
+
// `{ global }` destructuring is safe.
|
|
39
14
|
get global() {
|
|
40
15
|
return this.cns.global;
|
|
41
16
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
delete() {
|
|
49
|
-
this.stimulation.getContext().delete(this.neuron);
|
|
17
|
+
// The caller-supplied per-stimulation context (`stimulate(sig, {stimulationContext})`),
|
|
18
|
+
// the same value on every hop — the environment-agnostic way to correlate logs to a
|
|
19
|
+
// run (pass `{ stimulationId, attemptNumber }`). Prototype getter like `global`:
|
|
20
|
+
// zero extra allocation, read only where a handler reaches for it.
|
|
21
|
+
get stimulationContext() {
|
|
22
|
+
return this.stimulation.options?.stimulationContext;
|
|
50
23
|
}
|
|
51
24
|
};
|
|
52
25
|
var CNSStimulationResponseImpl = class {
|
|
53
|
-
constructor(stimulation,
|
|
26
|
+
constructor(stimulation, inputSignal, outputSignal, queueLength, pendingActivations, activeActivations, hops, error, neuron2) {
|
|
54
27
|
this.stimulation = stimulation;
|
|
55
|
-
this.store = store;
|
|
56
28
|
this.inputSignal = inputSignal;
|
|
57
29
|
this.outputSignal = outputSignal;
|
|
58
30
|
this.queueLength = queueLength;
|
|
@@ -60,9 +32,7 @@ var CNSStimulationResponseImpl = class {
|
|
|
60
32
|
this.activeActivations = activeActivations;
|
|
61
33
|
this.hops = hops;
|
|
62
34
|
this.error = error;
|
|
63
|
-
|
|
64
|
-
get contextValue() {
|
|
65
|
-
return this.store ? this.store.getAll() : /* @__PURE__ */ new Map();
|
|
35
|
+
this.neuron = neuron2;
|
|
66
36
|
}
|
|
67
37
|
};
|
|
68
38
|
var CNSStimulation = class {
|
|
@@ -91,15 +61,11 @@ var CNSStimulation = class {
|
|
|
91
61
|
this.isCompleted = false;
|
|
92
62
|
this.completionRejected = false;
|
|
93
63
|
this.onDrain = onDrain;
|
|
94
|
-
this.ctxStore = options?.ctx;
|
|
95
64
|
this.instanceNeuronQueue = instanceNeuronQueue;
|
|
96
65
|
this.onResponse = onResponse;
|
|
97
66
|
if (this.options?.maxNeuronHops) {
|
|
98
67
|
this.neuronVisitMap = /* @__PURE__ */ new Map();
|
|
99
68
|
}
|
|
100
|
-
if (this.autoCleanupContextsEnabled) {
|
|
101
|
-
this.activeSccCounts = /* @__PURE__ */ new Map();
|
|
102
|
-
}
|
|
103
69
|
}
|
|
104
70
|
pushFailedTask(failure) {
|
|
105
71
|
(this.failedTasks ?? (this.failedTasks = [])).push(failure);
|
|
@@ -113,10 +79,6 @@ var CNSStimulation = class {
|
|
|
113
79
|
this.completionError = error;
|
|
114
80
|
this.rejectCompleted?.(error);
|
|
115
81
|
}
|
|
116
|
-
/** Lazily-created neuron context store (see {@link ctxStore}). */
|
|
117
|
-
get ctx() {
|
|
118
|
-
return this.ctxStore ?? (this.ctxStore = new CNSStimulationContextStore());
|
|
119
|
-
}
|
|
120
82
|
// ----- Inlined activation queue / pump -----
|
|
121
83
|
get canStartOperation() {
|
|
122
84
|
const limit = this.options?.concurrency ?? Infinity;
|
|
@@ -334,10 +296,17 @@ var CNSStimulation = class {
|
|
|
334
296
|
return this.failedTasks ? [...this.failedTasks] : [];
|
|
335
297
|
}
|
|
336
298
|
/**
|
|
337
|
-
*
|
|
299
|
+
* The current outstanding frontier — every task that has not completed:
|
|
300
|
+
* queued, active, and pending (awaiting an async onResponse), plus any
|
|
301
|
+
* failed/aborted tasks. This is the set to persist for resume: re-activating
|
|
302
|
+
* it re-runs exactly the not-yet-done work. Safe to call at any point during
|
|
303
|
+
* a run (for progress) or after it fails.
|
|
338
304
|
*/
|
|
339
|
-
|
|
340
|
-
return
|
|
305
|
+
getOutstandingTasks() {
|
|
306
|
+
return [
|
|
307
|
+
...this.getAllActivationTasks(),
|
|
308
|
+
...this.getFailedTasks().map((f) => f.task)
|
|
309
|
+
];
|
|
341
310
|
}
|
|
342
311
|
/**
|
|
343
312
|
* Enqueue activation tasks directly into the stimulation queue
|
|
@@ -356,67 +325,6 @@ var CNSStimulation = class {
|
|
|
356
325
|
get concurrencyEnabled() {
|
|
357
326
|
return this.options?.concurrency !== void 0 && this.options?.concurrency > 0;
|
|
358
327
|
}
|
|
359
|
-
get autoCleanupContextsEnabled() {
|
|
360
|
-
return this.cns?.options?.autoCleanupContexts ?? false;
|
|
361
|
-
}
|
|
362
|
-
/**
|
|
363
|
-
* Mark a neuron as active (being processed)
|
|
364
|
-
*/
|
|
365
|
-
markNeuronActive(neuron2) {
|
|
366
|
-
if (!this.autoCleanupContextsEnabled) return;
|
|
367
|
-
this.incrementSccCount(neuron2);
|
|
368
|
-
}
|
|
369
|
-
/**
|
|
370
|
-
* Mark a neuron as inactive (finished processing)
|
|
371
|
-
*/
|
|
372
|
-
markNeuronInactive(neuron2) {
|
|
373
|
-
if (!this.autoCleanupContextsEnabled) return;
|
|
374
|
-
this.decrementSccCount(neuron2);
|
|
375
|
-
}
|
|
376
|
-
/**
|
|
377
|
-
* Increment the active count for the SCC containing this neuron
|
|
378
|
-
*/
|
|
379
|
-
incrementSccCount(neuron2) {
|
|
380
|
-
const counts = this.activeSccCounts;
|
|
381
|
-
if (!counts) return;
|
|
382
|
-
const sccIndex = this.cns.network.getSccIndexByNeuron(neuron2);
|
|
383
|
-
if (sccIndex === void 0) return;
|
|
384
|
-
const currentCount = counts.get(sccIndex) || 0;
|
|
385
|
-
counts.set(sccIndex, currentCount + 1);
|
|
386
|
-
}
|
|
387
|
-
/**
|
|
388
|
-
* Decrement the active count for the SCC containing this neuron
|
|
389
|
-
*/
|
|
390
|
-
decrementSccCount(neuron2) {
|
|
391
|
-
const counts = this.activeSccCounts;
|
|
392
|
-
if (!counts) return;
|
|
393
|
-
const sccIndex = this.cns.network.getSccIndexByNeuron(neuron2);
|
|
394
|
-
if (sccIndex === void 0) return;
|
|
395
|
-
const currentCount = counts.get(sccIndex) || 0;
|
|
396
|
-
const nextCount = Math.max(0, currentCount - 1);
|
|
397
|
-
counts.set(sccIndex, nextCount);
|
|
398
|
-
if (currentCount === 0) {
|
|
399
|
-
console.warn(
|
|
400
|
-
`[CNSStimulation] Attempting to decrement SCC count below 0 for neuron`
|
|
401
|
-
);
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
/**
|
|
405
|
-
* Check if a neuron can be guaranteed not to be visited again
|
|
406
|
-
*/
|
|
407
|
-
canNeuronBeGuaranteedDone(neuron2) {
|
|
408
|
-
if (!this.autoCleanupContextsEnabled || !this.activeSccCounts)
|
|
409
|
-
return false;
|
|
410
|
-
return this.cns.network.canNeuronBeGuaranteedDone(
|
|
411
|
-
neuron2,
|
|
412
|
-
this.activeSccCounts
|
|
413
|
-
);
|
|
414
|
-
}
|
|
415
|
-
cleanupCtxIfNeeded(neuron2) {
|
|
416
|
-
if (this.autoCleanupContextsEnabled && this.canNeuronBeGuaranteedDone(neuron2)) {
|
|
417
|
-
this.ctxStore?.delete(neuron2);
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
328
|
createSubscriberQueueItem(subscriber, inputSignal) {
|
|
421
329
|
if (this.options?.maxNeuronHops) {
|
|
422
330
|
if ((this.neuronVisitMap?.get(subscriber.neuron) ?? 0) >= this.options?.maxNeuronHops) {
|
|
@@ -490,7 +398,6 @@ var CNSStimulation = class {
|
|
|
490
398
|
);
|
|
491
399
|
}
|
|
492
400
|
runStarter(neuron2, dendrite, inputSignal, neuronActivationTask) {
|
|
493
|
-
this.markNeuronActive(neuron2);
|
|
494
401
|
let response;
|
|
495
402
|
try {
|
|
496
403
|
response = dendrite.response(
|
|
@@ -498,13 +405,11 @@ var CNSStimulation = class {
|
|
|
498
405
|
neuron2.axon,
|
|
499
406
|
new CNSDendriteContext(
|
|
500
407
|
this,
|
|
501
|
-
neuron2,
|
|
502
408
|
this.options?.abortSignal,
|
|
503
409
|
this.cns
|
|
504
410
|
)
|
|
505
411
|
);
|
|
506
412
|
} catch (error) {
|
|
507
|
-
this.markNeuronInactive(neuron2);
|
|
508
413
|
const isAborted = this.options?.abortSignal?.aborted ?? false;
|
|
509
414
|
this.pushFailedTask({
|
|
510
415
|
task: neuronActivationTask,
|
|
@@ -544,7 +449,6 @@ var CNSStimulation = class {
|
|
|
544
449
|
return timedPromise.then(
|
|
545
450
|
(signal) => {
|
|
546
451
|
return () => {
|
|
547
|
-
this.markNeuronInactive(neuron2);
|
|
548
452
|
return this.processResponseOrResponses(
|
|
549
453
|
neuron2,
|
|
550
454
|
inputSignal,
|
|
@@ -554,7 +458,6 @@ var CNSStimulation = class {
|
|
|
554
458
|
},
|
|
555
459
|
(error) => {
|
|
556
460
|
return () => {
|
|
557
|
-
this.markNeuronInactive(neuron2);
|
|
558
461
|
const isAborted = this.options?.abortSignal?.aborted ?? false;
|
|
559
462
|
this.pushFailedTask({
|
|
560
463
|
task: neuronActivationTask,
|
|
@@ -572,7 +475,6 @@ var CNSStimulation = class {
|
|
|
572
475
|
);
|
|
573
476
|
} else {
|
|
574
477
|
return () => {
|
|
575
|
-
this.markNeuronInactive(neuron2);
|
|
576
478
|
return this.processResponseOrResponses(
|
|
577
479
|
neuron2,
|
|
578
480
|
inputSignal,
|
|
@@ -618,7 +520,6 @@ var CNSStimulation = class {
|
|
|
618
520
|
const onResponse = this.onResponse;
|
|
619
521
|
if (!onResponse) {
|
|
620
522
|
if (collateral2 && !error) {
|
|
621
|
-
if (emitter) this.cleanupCtxIfNeeded(emitter);
|
|
622
523
|
const n = subscribers.length;
|
|
623
524
|
if (n > 0) {
|
|
624
525
|
const tasks = new Array(n);
|
|
@@ -640,7 +541,6 @@ var CNSStimulation = class {
|
|
|
640
541
|
}
|
|
641
542
|
const subscriberActivationTasks = [];
|
|
642
543
|
if (collateral2 && !error) {
|
|
643
|
-
if (emitter) this.cleanupCtxIfNeeded(emitter);
|
|
644
544
|
const pending = this.pendingTasks ?? (this.pendingTasks = /* @__PURE__ */ new Set());
|
|
645
545
|
for (let i = 0; i < subscribers.length; i++) {
|
|
646
546
|
const task = this.createSubscriberQueueItem(
|
|
@@ -657,14 +557,14 @@ var CNSStimulation = class {
|
|
|
657
557
|
maybePromise = onResponse(
|
|
658
558
|
new CNSStimulationResponseImpl(
|
|
659
559
|
this,
|
|
660
|
-
this.ctxStore,
|
|
661
560
|
inputSignal,
|
|
662
561
|
outputSignal,
|
|
663
562
|
this.pendingActivations + this.activeOperations,
|
|
664
563
|
this.pendingActivations,
|
|
665
564
|
this.activeOperations,
|
|
666
565
|
this.options?.maxNeuronHops && emitter ? this.neuronVisitMap?.get(emitter) ?? 0 : void 0,
|
|
667
|
-
error
|
|
566
|
+
error,
|
|
567
|
+
emitter
|
|
668
568
|
)
|
|
669
569
|
);
|
|
670
570
|
} catch (e) {
|
|
@@ -802,8 +702,9 @@ var CNSNetwork = class {
|
|
|
802
702
|
* Strongly Connected Components of the neuron graph.
|
|
803
703
|
* Each component is a set of neuron objects that can reach each other.
|
|
804
704
|
*
|
|
805
|
-
* Computed lazily on first access: the SCC machinery
|
|
806
|
-
*
|
|
705
|
+
* Computed lazily on first access: the SCC machinery only drives graph
|
|
706
|
+
* introspection (`getSCCSetByNeuron`, `canNeuronBeGuaranteedDone`), so a
|
|
707
|
+
* network that never inspects reachability never pays for it.
|
|
807
708
|
*/
|
|
808
709
|
this._stronglyConnectedComponents = [];
|
|
809
710
|
this.sccBuilt = false;
|
|
@@ -1089,16 +990,20 @@ var CNS = class {
|
|
|
1089
990
|
this.network = new CNSNetwork(this.neurons);
|
|
1090
991
|
this.global = global;
|
|
1091
992
|
}
|
|
1092
|
-
|
|
1093
|
-
|
|
993
|
+
/** Push a listener onto a list; return an idempotent unsubscribe. */
|
|
994
|
+
addListener(list, listener) {
|
|
995
|
+
list.push(listener);
|
|
1094
996
|
let active = true;
|
|
1095
997
|
return () => {
|
|
1096
998
|
if (!active) return;
|
|
1097
999
|
active = false;
|
|
1098
|
-
const idx =
|
|
1099
|
-
if (idx >= 0)
|
|
1000
|
+
const idx = list.indexOf(listener);
|
|
1001
|
+
if (idx >= 0) list.splice(idx, 1);
|
|
1100
1002
|
};
|
|
1101
1003
|
}
|
|
1004
|
+
addResponseListener(listener) {
|
|
1005
|
+
return this.addListener(this.globalResponseListeners, listener);
|
|
1006
|
+
}
|
|
1102
1007
|
/**
|
|
1103
1008
|
* Register a listener called once at the end of every synchronous turn of
|
|
1104
1009
|
* every stimulation - see {@link TCNSStimulationDrain}. This is how an
|
|
@@ -1108,14 +1013,7 @@ var CNS = class {
|
|
|
1108
1013
|
* Returns an unsubscribe function.
|
|
1109
1014
|
*/
|
|
1110
1015
|
addDrainListener(listener) {
|
|
1111
|
-
this.globalDrainListeners
|
|
1112
|
-
let active = true;
|
|
1113
|
-
return () => {
|
|
1114
|
-
if (!active) return;
|
|
1115
|
-
active = false;
|
|
1116
|
-
const idx = this.globalDrainListeners.indexOf(listener);
|
|
1117
|
-
if (idx >= 0) this.globalDrainListeners.splice(idx, 1);
|
|
1118
|
-
};
|
|
1016
|
+
return this.addListener(this.globalDrainListeners, listener);
|
|
1119
1017
|
}
|
|
1120
1018
|
/**
|
|
1121
1019
|
* Fan a drain out to the local and global listeners, or return undefined when
|
|
@@ -1184,15 +1082,18 @@ var CNS = class {
|
|
|
1184
1082
|
}
|
|
1185
1083
|
};
|
|
1186
1084
|
}
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1085
|
+
/** Build a stimulation (wired listeners, unseeded). Shared by stimulate/activate. */
|
|
1086
|
+
createStimulation(options) {
|
|
1087
|
+
return new CNSStimulation(
|
|
1190
1088
|
this,
|
|
1191
1089
|
this.instanceNeuronQueue,
|
|
1192
1090
|
options,
|
|
1193
|
-
|
|
1091
|
+
this.wrapOnResponse(options?.onResponse),
|
|
1194
1092
|
this.wrapOnDrain(options?.onDrain)
|
|
1195
1093
|
);
|
|
1094
|
+
}
|
|
1095
|
+
stimulate(signalOrSignals, options) {
|
|
1096
|
+
const stimulation = this.createStimulation(options);
|
|
1196
1097
|
stimulation.responseToSignal(signalOrSignals);
|
|
1197
1098
|
return stimulation;
|
|
1198
1099
|
}
|
|
@@ -1200,85 +1101,12 @@ var CNS = class {
|
|
|
1200
1101
|
* Start a stimulation with activation tasks directly
|
|
1201
1102
|
*/
|
|
1202
1103
|
activate(tasks, options) {
|
|
1203
|
-
const
|
|
1204
|
-
const stimulation = new CNSStimulation(
|
|
1205
|
-
this,
|
|
1206
|
-
this.instanceNeuronQueue,
|
|
1207
|
-
options,
|
|
1208
|
-
wrapped,
|
|
1209
|
-
this.wrapOnDrain(options?.onDrain)
|
|
1210
|
-
);
|
|
1104
|
+
const stimulation = this.createStimulation(options);
|
|
1211
1105
|
stimulation.enqueueTasks(tasks);
|
|
1212
1106
|
return stimulation;
|
|
1213
1107
|
}
|
|
1214
1108
|
};
|
|
1215
1109
|
|
|
1216
|
-
// src/CNSPersistOptionsRegistry.ts
|
|
1217
|
-
var CNSPersistOptionsRegistry = class {
|
|
1218
|
-
constructor() {
|
|
1219
|
-
this.neurons = /* @__PURE__ */ new Map();
|
|
1220
|
-
this.neuronNames = /* @__PURE__ */ new WeakMap();
|
|
1221
|
-
this.collaterals = /* @__PURE__ */ new Map();
|
|
1222
|
-
this.stimulations = /* @__PURE__ */ new Map();
|
|
1223
|
-
}
|
|
1224
|
-
addNeuron(neuron2, options) {
|
|
1225
|
-
this.neurons.set(options.name, neuron2);
|
|
1226
|
-
this.neuronNames.set(neuron2, options.name);
|
|
1227
|
-
}
|
|
1228
|
-
getNeuron(name) {
|
|
1229
|
-
return this.neurons.get(name);
|
|
1230
|
-
}
|
|
1231
|
-
getNeuronName(neuron2) {
|
|
1232
|
-
return this.neuronNames.get(neuron2);
|
|
1233
|
-
}
|
|
1234
|
-
getNamedNeurons() {
|
|
1235
|
-
return this.neurons;
|
|
1236
|
-
}
|
|
1237
|
-
getCollateralName(collateral2) {
|
|
1238
|
-
for (const [name, col] of this.collaterals) {
|
|
1239
|
-
if (col === collateral2) return name;
|
|
1240
|
-
}
|
|
1241
|
-
return void 0;
|
|
1242
|
-
}
|
|
1243
|
-
removeNeuron(name) {
|
|
1244
|
-
const neuron2 = this.neurons.get(name);
|
|
1245
|
-
if (neuron2) this.neuronNames.delete(neuron2);
|
|
1246
|
-
this.neurons.delete(name);
|
|
1247
|
-
}
|
|
1248
|
-
addCollateral(collateral2, options) {
|
|
1249
|
-
this.collaterals.set(options.name, collateral2);
|
|
1250
|
-
}
|
|
1251
|
-
getCollateral(name) {
|
|
1252
|
-
return this.collaterals.get(name);
|
|
1253
|
-
}
|
|
1254
|
-
removeCollateral(name) {
|
|
1255
|
-
this.collaterals.delete(name);
|
|
1256
|
-
}
|
|
1257
|
-
addStimulation(stimulation, options) {
|
|
1258
|
-
this.stimulations.set(options.stimulationId, stimulation);
|
|
1259
|
-
}
|
|
1260
|
-
getStimulation(stimulationId) {
|
|
1261
|
-
return this.stimulations.get(stimulationId);
|
|
1262
|
-
}
|
|
1263
|
-
removeStimulation(stimulationId) {
|
|
1264
|
-
this.stimulations.delete(stimulationId);
|
|
1265
|
-
}
|
|
1266
|
-
register(name, neuron2, collateralNames) {
|
|
1267
|
-
this.addNeuron(neuron2, { name, neuron: neuron2 });
|
|
1268
|
-
for (const [key, col] of Object.entries(neuron2.axon)) {
|
|
1269
|
-
this.addCollateral(col, {
|
|
1270
|
-
name: collateralNames?.[key] ?? key,
|
|
1271
|
-
collateral: col
|
|
1272
|
-
});
|
|
1273
|
-
}
|
|
1274
|
-
return this;
|
|
1275
|
-
}
|
|
1276
|
-
registerCollateral(name, collateral2) {
|
|
1277
|
-
this.addCollateral(collateral2, { name, collateral: collateral2 });
|
|
1278
|
-
return this;
|
|
1279
|
-
}
|
|
1280
|
-
};
|
|
1281
|
-
|
|
1282
1110
|
// src/CNSCollateral.ts
|
|
1283
1111
|
var CNSCollateral = class {
|
|
1284
1112
|
createSignal(payload) {
|
|
@@ -1461,13 +1289,11 @@ var neuron = (axon) => {
|
|
|
1461
1289
|
};
|
|
1462
1290
|
var neuronFactory = () => {
|
|
1463
1291
|
const factory = {
|
|
1464
|
-
withCtx: () => factory,
|
|
1465
1292
|
withGlobal: () => factory,
|
|
1466
1293
|
neuron: (axon) => neuron(axon)
|
|
1467
1294
|
};
|
|
1468
1295
|
return factory;
|
|
1469
1296
|
};
|
|
1470
|
-
var withCtx = () => neuronFactory();
|
|
1471
1297
|
var withGlobal = () => neuronFactory();
|
|
1472
1298
|
var afferentPath = (parentAfferentPath) => {
|
|
1473
1299
|
return {
|
|
@@ -1481,44 +1307,15 @@ var modality = (afferentPaths) => {
|
|
|
1481
1307
|
afferentPaths
|
|
1482
1308
|
};
|
|
1483
1309
|
};
|
|
1484
|
-
var createPersistRegistry = (namedNeurons) => {
|
|
1485
|
-
const registry = new CNSPersistOptionsRegistry();
|
|
1486
|
-
for (const [name, entry] of Object.entries(namedNeurons)) {
|
|
1487
|
-
const isEntry = "neuron" in entry && !("axon" in entry);
|
|
1488
|
-
const neuron2 = isEntry ? entry.neuron : entry;
|
|
1489
|
-
const colNames = isEntry ? entry.collaterals ?? {} : {};
|
|
1490
|
-
registry.addNeuron(neuron2, { name, neuron: neuron2 });
|
|
1491
|
-
for (const [key, col] of Object.entries(neuron2.axon)) {
|
|
1492
|
-
registry.addCollateral(col, {
|
|
1493
|
-
name: colNames[key] ?? key,
|
|
1494
|
-
collateral: col
|
|
1495
|
-
});
|
|
1496
|
-
}
|
|
1497
|
-
}
|
|
1498
|
-
return registry;
|
|
1499
|
-
};
|
|
1500
|
-
var createCNS = (namedNeurons, options) => {
|
|
1501
|
-
const neurons = Object.values(namedNeurons).map(
|
|
1502
|
-
(entry) => entry && typeof entry === "object" && "neuron" in entry ? entry.neuron : entry
|
|
1503
|
-
);
|
|
1504
|
-
const cns = new CNS(neurons, options, options?.global);
|
|
1505
|
-
const registry = createPersistRegistry(namedNeurons);
|
|
1506
|
-
return { cns, registry };
|
|
1507
|
-
};
|
|
1508
1310
|
|
|
1509
1311
|
exports.CNS = CNS;
|
|
1510
1312
|
exports.CNSCollateral = CNSCollateral;
|
|
1511
|
-
exports.CNSPersistOptionsRegistry = CNSPersistOptionsRegistry;
|
|
1512
|
-
exports.CNSStimulationContextStore = CNSStimulationContextStore;
|
|
1513
1313
|
exports.CNSStimulationGate = CNSStimulationGate;
|
|
1514
1314
|
exports.afferentPath = afferentPath;
|
|
1515
1315
|
exports.collateral = collateral;
|
|
1516
|
-
exports.createCNS = createCNS;
|
|
1517
|
-
exports.createPersistRegistry = createPersistRegistry;
|
|
1518
1316
|
exports.modality = modality;
|
|
1519
1317
|
exports.neuron = neuron;
|
|
1520
1318
|
exports.neuronFactory = neuronFactory;
|
|
1521
|
-
exports.withCtx = withCtx;
|
|
1522
1319
|
exports.withGlobal = withGlobal;
|
|
1523
1320
|
//# sourceMappingURL=index.cjs.map
|
|
1524
1321
|
//# sourceMappingURL=index.cjs.map
|