@framers/agentos 0.1.46 → 0.1.47

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 (211) hide show
  1. package/README.md +7 -7
  2. package/dist/cognitive_substrate/IGMI.d.ts +2 -0
  3. package/dist/cognitive_substrate/IGMI.d.ts.map +1 -1
  4. package/dist/cognitive_substrate/IGMI.js.map +1 -1
  5. package/dist/cognitive_substrate/personas/IPersonaDefinition.d.ts +2 -0
  6. package/dist/cognitive_substrate/personas/IPersonaDefinition.d.ts.map +1 -1
  7. package/dist/core/audio/AdaptiveVAD.d.ts +147 -0
  8. package/dist/core/audio/AdaptiveVAD.d.ts.map +1 -0
  9. package/dist/core/audio/AdaptiveVAD.js +239 -0
  10. package/dist/core/audio/AdaptiveVAD.js.map +1 -0
  11. package/dist/core/audio/AudioProcessor.d.ts +121 -0
  12. package/dist/core/audio/AudioProcessor.d.ts.map +1 -0
  13. package/dist/core/audio/AudioProcessor.js +299 -0
  14. package/dist/core/audio/AudioProcessor.js.map +1 -0
  15. package/dist/core/audio/EnvironmentalCalibrator.d.ts +187 -0
  16. package/dist/core/audio/EnvironmentalCalibrator.d.ts.map +1 -0
  17. package/dist/core/audio/EnvironmentalCalibrator.js +360 -0
  18. package/dist/core/audio/EnvironmentalCalibrator.js.map +1 -0
  19. package/dist/core/audio/SilenceDetector.d.ts +111 -0
  20. package/dist/core/audio/SilenceDetector.d.ts.map +1 -0
  21. package/dist/core/audio/SilenceDetector.js +178 -0
  22. package/dist/core/audio/SilenceDetector.js.map +1 -0
  23. package/dist/core/llm/IPromptEngine.d.ts +2 -0
  24. package/dist/core/llm/IPromptEngine.d.ts.map +1 -1
  25. package/dist/core/llm/IPromptEngine.js.map +1 -1
  26. package/dist/core/llm/providers/implementations/OpenAIProvider.d.ts.map +1 -1
  27. package/dist/core/llm/providers/implementations/OpenAIProvider.js +8 -1
  28. package/dist/core/llm/providers/implementations/OpenAIProvider.js.map +1 -1
  29. package/dist/extensions/ExtensionManager.d.ts.map +1 -1
  30. package/dist/extensions/ExtensionManager.js +9 -1
  31. package/dist/extensions/ExtensionManager.js.map +1 -1
  32. package/dist/extensions/types.d.ts +20 -2
  33. package/dist/extensions/types.d.ts.map +1 -1
  34. package/dist/extensions/types.js +4 -0
  35. package/dist/extensions/types.js.map +1 -1
  36. package/dist/index.d.ts +2 -0
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +4 -0
  39. package/dist/index.js.map +1 -1
  40. package/dist/memory/CognitiveMemoryManager.d.ts +133 -0
  41. package/dist/memory/CognitiveMemoryManager.d.ts.map +1 -0
  42. package/dist/memory/CognitiveMemoryManager.js +519 -0
  43. package/dist/memory/CognitiveMemoryManager.js.map +1 -0
  44. package/dist/memory/config.d.ts +135 -0
  45. package/dist/memory/config.d.ts.map +1 -0
  46. package/dist/memory/config.js +28 -0
  47. package/dist/memory/config.js.map +1 -0
  48. package/dist/memory/consolidation/ConsolidationPipeline.d.ts +70 -0
  49. package/dist/memory/consolidation/ConsolidationPipeline.d.ts.map +1 -0
  50. package/dist/memory/consolidation/ConsolidationPipeline.js +301 -0
  51. package/dist/memory/consolidation/ConsolidationPipeline.js.map +1 -0
  52. package/dist/memory/context/CompactionEngine.d.ts +21 -0
  53. package/dist/memory/context/CompactionEngine.d.ts.map +1 -0
  54. package/dist/memory/context/CompactionEngine.js +35 -0
  55. package/dist/memory/context/CompactionEngine.js.map +1 -0
  56. package/dist/memory/context/CompactionLog.d.ts +50 -0
  57. package/dist/memory/context/CompactionLog.d.ts.map +1 -0
  58. package/dist/memory/context/CompactionLog.js +139 -0
  59. package/dist/memory/context/CompactionLog.js.map +1 -0
  60. package/dist/memory/context/ContextWindowManager.d.ts +114 -0
  61. package/dist/memory/context/ContextWindowManager.d.ts.map +1 -0
  62. package/dist/memory/context/ContextWindowManager.js +225 -0
  63. package/dist/memory/context/ContextWindowManager.js.map +1 -0
  64. package/dist/memory/context/RollingSummaryChain.d.ts +53 -0
  65. package/dist/memory/context/RollingSummaryChain.d.ts.map +1 -0
  66. package/dist/memory/context/RollingSummaryChain.js +193 -0
  67. package/dist/memory/context/RollingSummaryChain.js.map +1 -0
  68. package/dist/memory/context/index.d.ts +15 -0
  69. package/dist/memory/context/index.d.ts.map +1 -0
  70. package/dist/memory/context/index.js +14 -0
  71. package/dist/memory/context/index.js.map +1 -0
  72. package/dist/memory/context/strategies/HierarchicalStrategy.d.ts +25 -0
  73. package/dist/memory/context/strategies/HierarchicalStrategy.d.ts.map +1 -0
  74. package/dist/memory/context/strategies/HierarchicalStrategy.js +240 -0
  75. package/dist/memory/context/strategies/HierarchicalStrategy.js.map +1 -0
  76. package/dist/memory/context/strategies/HybridStrategy.d.ts +26 -0
  77. package/dist/memory/context/strategies/HybridStrategy.d.ts.map +1 -0
  78. package/dist/memory/context/strategies/HybridStrategy.js +245 -0
  79. package/dist/memory/context/strategies/HybridStrategy.js.map +1 -0
  80. package/dist/memory/context/strategies/SlidingSummaryStrategy.d.ts +22 -0
  81. package/dist/memory/context/strategies/SlidingSummaryStrategy.d.ts.map +1 -0
  82. package/dist/memory/context/strategies/SlidingSummaryStrategy.js +203 -0
  83. package/dist/memory/context/strategies/SlidingSummaryStrategy.js.map +1 -0
  84. package/dist/memory/context/types.d.ts +120 -0
  85. package/dist/memory/context/types.d.ts.map +1 -0
  86. package/dist/memory/context/types.js +17 -0
  87. package/dist/memory/context/types.js.map +1 -0
  88. package/dist/memory/decay/DecayModel.d.ts +87 -0
  89. package/dist/memory/decay/DecayModel.d.ts.map +1 -0
  90. package/dist/memory/decay/DecayModel.js +117 -0
  91. package/dist/memory/decay/DecayModel.js.map +1 -0
  92. package/dist/memory/decay/RetrievalPriorityScorer.d.ts +63 -0
  93. package/dist/memory/decay/RetrievalPriorityScorer.d.ts.map +1 -0
  94. package/dist/memory/decay/RetrievalPriorityScorer.js +110 -0
  95. package/dist/memory/decay/RetrievalPriorityScorer.js.map +1 -0
  96. package/dist/memory/encoding/ContentFeatureDetector.d.ts +37 -0
  97. package/dist/memory/encoding/ContentFeatureDetector.d.ts.map +1 -0
  98. package/dist/memory/encoding/ContentFeatureDetector.js +176 -0
  99. package/dist/memory/encoding/ContentFeatureDetector.js.map +1 -0
  100. package/dist/memory/encoding/EncodingModel.d.ts +67 -0
  101. package/dist/memory/encoding/EncodingModel.d.ts.map +1 -0
  102. package/dist/memory/encoding/EncodingModel.js +171 -0
  103. package/dist/memory/encoding/EncodingModel.js.map +1 -0
  104. package/dist/memory/extension/CognitiveMemoryExtension.d.ts +18 -0
  105. package/dist/memory/extension/CognitiveMemoryExtension.d.ts.map +1 -0
  106. package/dist/memory/extension/CognitiveMemoryExtension.js +131 -0
  107. package/dist/memory/extension/CognitiveMemoryExtension.js.map +1 -0
  108. package/dist/memory/graph/GraphologyMemoryGraph.d.ts +29 -0
  109. package/dist/memory/graph/GraphologyMemoryGraph.d.ts.map +1 -0
  110. package/dist/memory/graph/GraphologyMemoryGraph.js +224 -0
  111. package/dist/memory/graph/GraphologyMemoryGraph.js.map +1 -0
  112. package/dist/memory/graph/IMemoryGraph.d.ts +70 -0
  113. package/dist/memory/graph/IMemoryGraph.d.ts.map +1 -0
  114. package/dist/memory/graph/IMemoryGraph.js +15 -0
  115. package/dist/memory/graph/IMemoryGraph.js.map +1 -0
  116. package/dist/memory/graph/KnowledgeGraphMemoryGraph.d.ts +38 -0
  117. package/dist/memory/graph/KnowledgeGraphMemoryGraph.d.ts.map +1 -0
  118. package/dist/memory/graph/KnowledgeGraphMemoryGraph.js +264 -0
  119. package/dist/memory/graph/KnowledgeGraphMemoryGraph.js.map +1 -0
  120. package/dist/memory/graph/SpreadingActivation.d.ts +36 -0
  121. package/dist/memory/graph/SpreadingActivation.d.ts.map +1 -0
  122. package/dist/memory/graph/SpreadingActivation.js +100 -0
  123. package/dist/memory/graph/SpreadingActivation.js.map +1 -0
  124. package/dist/memory/index.d.ts +52 -0
  125. package/dist/memory/index.d.ts.map +1 -0
  126. package/dist/memory/index.js +43 -0
  127. package/dist/memory/index.js.map +1 -0
  128. package/dist/memory/observation/MemoryObserver.d.ts +59 -0
  129. package/dist/memory/observation/MemoryObserver.d.ts.map +1 -0
  130. package/dist/memory/observation/MemoryObserver.js +136 -0
  131. package/dist/memory/observation/MemoryObserver.js.map +1 -0
  132. package/dist/memory/observation/MemoryReflector.d.ts +51 -0
  133. package/dist/memory/observation/MemoryReflector.d.ts.map +1 -0
  134. package/dist/memory/observation/MemoryReflector.js +184 -0
  135. package/dist/memory/observation/MemoryReflector.js.map +1 -0
  136. package/dist/memory/observation/ObservationBuffer.d.ts +51 -0
  137. package/dist/memory/observation/ObservationBuffer.d.ts.map +1 -0
  138. package/dist/memory/observation/ObservationBuffer.js +81 -0
  139. package/dist/memory/observation/ObservationBuffer.js.map +1 -0
  140. package/dist/memory/prompt/MemoryFormatters.d.ts +22 -0
  141. package/dist/memory/prompt/MemoryFormatters.d.ts.map +1 -0
  142. package/dist/memory/prompt/MemoryFormatters.js +113 -0
  143. package/dist/memory/prompt/MemoryFormatters.js.map +1 -0
  144. package/dist/memory/prompt/MemoryPromptAssembler.d.ts +40 -0
  145. package/dist/memory/prompt/MemoryPromptAssembler.d.ts.map +1 -0
  146. package/dist/memory/prompt/MemoryPromptAssembler.js +180 -0
  147. package/dist/memory/prompt/MemoryPromptAssembler.js.map +1 -0
  148. package/dist/memory/prospective/ProspectiveMemoryManager.d.ts +83 -0
  149. package/dist/memory/prospective/ProspectiveMemoryManager.d.ts.map +1 -0
  150. package/dist/memory/prospective/ProspectiveMemoryManager.js +128 -0
  151. package/dist/memory/prospective/ProspectiveMemoryManager.js.map +1 -0
  152. package/dist/memory/store/MemoryStore.d.ts +76 -0
  153. package/dist/memory/store/MemoryStore.d.ts.map +1 -0
  154. package/dist/memory/store/MemoryStore.js +320 -0
  155. package/dist/memory/store/MemoryStore.js.map +1 -0
  156. package/dist/memory/types.d.ts +184 -0
  157. package/dist/memory/types.d.ts.map +1 -0
  158. package/dist/memory/types.js +14 -0
  159. package/dist/memory/types.js.map +1 -0
  160. package/dist/memory/working/CognitiveWorkingMemory.d.ts +87 -0
  161. package/dist/memory/working/CognitiveWorkingMemory.d.ts.map +1 -0
  162. package/dist/memory/working/CognitiveWorkingMemory.js +230 -0
  163. package/dist/memory/working/CognitiveWorkingMemory.js.map +1 -0
  164. package/dist/rag/EmbeddingManager.d.ts.map +1 -1
  165. package/dist/rag/EmbeddingManager.js +8 -1
  166. package/dist/rag/EmbeddingManager.js.map +1 -1
  167. package/dist/speech/SpeechProviderRegistry.d.ts +17 -0
  168. package/dist/speech/SpeechProviderRegistry.d.ts.map +1 -0
  169. package/dist/speech/SpeechProviderRegistry.js +47 -0
  170. package/dist/speech/SpeechProviderRegistry.js.map +1 -0
  171. package/dist/speech/SpeechRuntime.d.ts +28 -0
  172. package/dist/speech/SpeechRuntime.d.ts.map +1 -0
  173. package/dist/speech/SpeechRuntime.js +138 -0
  174. package/dist/speech/SpeechRuntime.js.map +1 -0
  175. package/dist/speech/SpeechSession.d.ts +37 -0
  176. package/dist/speech/SpeechSession.d.ts.map +1 -0
  177. package/dist/speech/SpeechSession.js +285 -0
  178. package/dist/speech/SpeechSession.js.map +1 -0
  179. package/dist/speech/audio.d.ts +3 -0
  180. package/dist/speech/audio.d.ts.map +1 -0
  181. package/dist/speech/audio.js +39 -0
  182. package/dist/speech/audio.js.map +1 -0
  183. package/dist/speech/index.d.ts +11 -0
  184. package/dist/speech/index.d.ts.map +1 -0
  185. package/dist/speech/index.js +11 -0
  186. package/dist/speech/index.js.map +1 -0
  187. package/dist/speech/providerCatalog.d.ts +7 -0
  188. package/dist/speech/providerCatalog.d.ts.map +1 -0
  189. package/dist/speech/providerCatalog.js +243 -0
  190. package/dist/speech/providerCatalog.js.map +1 -0
  191. package/dist/speech/providers/BuiltInAdaptiveVadProvider.d.ts +20 -0
  192. package/dist/speech/providers/BuiltInAdaptiveVadProvider.d.ts.map +1 -0
  193. package/dist/speech/providers/BuiltInAdaptiveVadProvider.js +29 -0
  194. package/dist/speech/providers/BuiltInAdaptiveVadProvider.js.map +1 -0
  195. package/dist/speech/providers/ElevenLabsTextToSpeechProvider.d.ts +20 -0
  196. package/dist/speech/providers/ElevenLabsTextToSpeechProvider.d.ts.map +1 -0
  197. package/dist/speech/providers/ElevenLabsTextToSpeechProvider.js +95 -0
  198. package/dist/speech/providers/ElevenLabsTextToSpeechProvider.js.map +1 -0
  199. package/dist/speech/providers/OpenAITextToSpeechProvider.d.ts +20 -0
  200. package/dist/speech/providers/OpenAITextToSpeechProvider.d.ts.map +1 -0
  201. package/dist/speech/providers/OpenAITextToSpeechProvider.js +75 -0
  202. package/dist/speech/providers/OpenAITextToSpeechProvider.js.map +1 -0
  203. package/dist/speech/providers/OpenAIWhisperSpeechToTextProvider.d.ts +18 -0
  204. package/dist/speech/providers/OpenAIWhisperSpeechToTextProvider.d.ts.map +1 -0
  205. package/dist/speech/providers/OpenAIWhisperSpeechToTextProvider.js +109 -0
  206. package/dist/speech/providers/OpenAIWhisperSpeechToTextProvider.js.map +1 -0
  207. package/dist/speech/types.d.ts +270 -0
  208. package/dist/speech/types.d.ts.map +1 -0
  209. package/dist/speech/types.js +2 -0
  210. package/dist/speech/types.js.map +1 -0
  211. package/package.json +22 -2
@@ -0,0 +1,67 @@
1
+ /**
2
+ * @fileoverview Personality-modulated memory encoding.
3
+ *
4
+ * Cognitive science foundations:
5
+ * - **Yerkes-Dodson law**: Encoding quality peaks at moderate arousal
6
+ * (inverted U). Very low or very high arousal impairs encoding.
7
+ * - **Flashbulb memories**: Highly emotional events create vivid,
8
+ * persistent memory traces (Brown & Kulik, 1977).
9
+ * - **Mood-congruent encoding**: Content whose emotional valence matches
10
+ * the current mood is encoded more strongly.
11
+ * - **HEXACO → attention weights**: Personality traits modulate *what*
12
+ * features of the input are noticed and how strongly they are encoded.
13
+ *
14
+ * @module agentos/memory/encoding/EncodingModel
15
+ */
16
+ import type { EncodingWeights, EncodingResult, ContentFeatures, EmotionalContext } from '../types.js';
17
+ import type { HexacoTraits, PADState, EncodingConfig } from '../config.js';
18
+ /**
19
+ * Derive per-feature attention weights from HEXACO personality traits.
20
+ * Each weight is in [0, 1] and modulates how much a given content feature
21
+ * contributes to encoding strength.
22
+ */
23
+ export declare function computeEncodingWeights(traits: HexacoTraits): EncodingWeights;
24
+ /**
25
+ * Encoding quality modifier based on arousal level.
26
+ * Returns a multiplier in [0.3, 1.0], peaking at arousal = 0.5 (moderate).
27
+ *
28
+ * f(a) = 1 - 4 * (a - 0.5)^2
29
+ *
30
+ * @param arousal01 Arousal normalised to 0..1 range.
31
+ */
32
+ export declare function yerksDodson(arousal01: number): number;
33
+ /**
34
+ * Compute a composite attention multiplier from content features weighted
35
+ * by personality-derived encoding weights.
36
+ */
37
+ export declare function computeAttentionMultiplier(weights: EncodingWeights, features: ContentFeatures): number;
38
+ /**
39
+ * Boost factor when content emotional valence matches current mood.
40
+ *
41
+ * Positive product means mood and content are congruent
42
+ * (both positive or both negative).
43
+ */
44
+ export declare function moodCongruenceBoost(currentValence: number, contentValence: number, emotionalSensitivity: number): number;
45
+ /**
46
+ * Determine whether this memory qualifies as a flashbulb memory.
47
+ * Flashbulb criteria: emotional intensity > threshold.
48
+ */
49
+ export declare function isFlashbulbMemory(emotionalIntensity: number, threshold?: number): boolean;
50
+ /**
51
+ * Create the EmotionalContext snapshot for a memory trace.
52
+ * Blends content sentiment with current mood (70/30 split).
53
+ *
54
+ * @param currentMood Current PAD state from MoodEngine.
55
+ * @param contentSentiment Estimated sentiment of the content (-1..1). Defaults to 0.
56
+ * @param gmiMood Current GMI mood enum string.
57
+ */
58
+ export declare function buildEmotionalContext(currentMood: PADState, gmiMood: string, contentSentiment?: number): EmotionalContext;
59
+ /**
60
+ * Compute encoding parameters for a new memory trace.
61
+ *
62
+ * Combines personality-modulated attention, Yerkes-Dodson arousal curve,
63
+ * mood-congruent encoding bias, and flashbulb detection into a single
64
+ * encoding result.
65
+ */
66
+ export declare function computeEncodingStrength(currentMood: PADState, traits: HexacoTraits, contentFeatures: ContentFeatures, contentSentiment?: number, config?: EncodingConfig): EncodingResult;
67
+ //# sourceMappingURL=EncodingModel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EncodingModel.d.ts","sourceRoot":"","sources":["../../../src/memory/encoding/EncodingModel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,eAAe,EACf,gBAAgB,EACjB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAU3E;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,YAAY,GAAG,eAAe,CAgB5E;AAMD;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAGrD;AAMD;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,eAAe,EACxB,QAAQ,EAAE,eAAe,GACxB,MAAM,CAaR;AAMD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,cAAc,EAAE,MAAM,EACtB,cAAc,EAAE,MAAM,EACtB,oBAAoB,EAAE,MAAM,GAC3B,MAAM,CAGR;AAMD;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,kBAAkB,EAAE,MAAM,EAC1B,SAAS,GAAE,MAAmD,GAC7D,OAAO,CAET;AAMD;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,QAAQ,EACrB,OAAO,EAAE,MAAM,EACf,gBAAgB,GAAE,MAAU,GAC3B,gBAAgB,CAalB;AAMD;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,WAAW,EAAE,QAAQ,EACrB,MAAM,EAAE,YAAY,EACpB,eAAe,EAAE,eAAe,EAChC,gBAAgB,GAAE,MAAU,EAC5B,MAAM,GAAE,cAAwC,GAC/C,cAAc,CA8ChB"}
@@ -0,0 +1,171 @@
1
+ /**
2
+ * @fileoverview Personality-modulated memory encoding.
3
+ *
4
+ * Cognitive science foundations:
5
+ * - **Yerkes-Dodson law**: Encoding quality peaks at moderate arousal
6
+ * (inverted U). Very low or very high arousal impairs encoding.
7
+ * - **Flashbulb memories**: Highly emotional events create vivid,
8
+ * persistent memory traces (Brown & Kulik, 1977).
9
+ * - **Mood-congruent encoding**: Content whose emotional valence matches
10
+ * the current mood is encoded more strongly.
11
+ * - **HEXACO → attention weights**: Personality traits modulate *what*
12
+ * features of the input are noticed and how strongly they are encoded.
13
+ *
14
+ * @module agentos/memory/encoding/EncodingModel
15
+ */
16
+ import { DEFAULT_ENCODING_CONFIG } from '../config.js';
17
+ // ---------------------------------------------------------------------------
18
+ // HEXACO → Encoding attention weights
19
+ // ---------------------------------------------------------------------------
20
+ const clamp01 = (v) => v == null ? 0.5 : Math.max(0, Math.min(1, v));
21
+ /**
22
+ * Derive per-feature attention weights from HEXACO personality traits.
23
+ * Each weight is in [0, 1] and modulates how much a given content feature
24
+ * contributes to encoding strength.
25
+ */
26
+ export function computeEncodingWeights(traits) {
27
+ const o = clamp01(traits.openness);
28
+ const c = clamp01(traits.conscientiousness);
29
+ const e = clamp01(traits.emotionality);
30
+ const x = clamp01(traits.extraversion);
31
+ const a = clamp01(traits.agreeableness);
32
+ const h = clamp01(traits.honesty);
33
+ return {
34
+ noveltyAttention: 0.3 + o * 0.7,
35
+ proceduralAttention: 0.3 + c * 0.7,
36
+ emotionalSensitivity: 0.2 + e * 0.8,
37
+ socialAttention: 0.2 + x * 0.8,
38
+ cooperativeAttention: 0.2 + a * 0.8,
39
+ ethicalAttention: 0.2 + h * 0.8,
40
+ };
41
+ }
42
+ // ---------------------------------------------------------------------------
43
+ // Yerkes-Dodson inverted U
44
+ // ---------------------------------------------------------------------------
45
+ /**
46
+ * Encoding quality modifier based on arousal level.
47
+ * Returns a multiplier in [0.3, 1.0], peaking at arousal = 0.5 (moderate).
48
+ *
49
+ * f(a) = 1 - 4 * (a - 0.5)^2
50
+ *
51
+ * @param arousal01 Arousal normalised to 0..1 range.
52
+ */
53
+ export function yerksDodson(arousal01) {
54
+ const centered = arousal01 - 0.5;
55
+ return Math.max(0.3, 1.0 - 4 * centered * centered);
56
+ }
57
+ // ---------------------------------------------------------------------------
58
+ // Content-type attention multiplier
59
+ // ---------------------------------------------------------------------------
60
+ /**
61
+ * Compute a composite attention multiplier from content features weighted
62
+ * by personality-derived encoding weights.
63
+ */
64
+ export function computeAttentionMultiplier(weights, features) {
65
+ let m = 0.5; // base attention
66
+ if (features.hasNovelty)
67
+ m += weights.noveltyAttention * 0.15;
68
+ if (features.hasProcedure)
69
+ m += weights.proceduralAttention * 0.15;
70
+ if (features.hasEmotion)
71
+ m += weights.emotionalSensitivity * 0.10;
72
+ if (features.hasSocialContent)
73
+ m += weights.socialAttention * 0.10;
74
+ if (features.hasCooperation)
75
+ m += weights.cooperativeAttention * 0.10;
76
+ if (features.hasEthicalContent)
77
+ m += weights.ethicalAttention * 0.10;
78
+ if (features.hasContradiction)
79
+ m += 0.15; // contradictions always draw attention
80
+ m += features.topicRelevance * 0.15;
81
+ return Math.min(1.0, m);
82
+ }
83
+ // ---------------------------------------------------------------------------
84
+ // Mood-congruent encoding bias
85
+ // ---------------------------------------------------------------------------
86
+ /**
87
+ * Boost factor when content emotional valence matches current mood.
88
+ *
89
+ * Positive product means mood and content are congruent
90
+ * (both positive or both negative).
91
+ */
92
+ export function moodCongruenceBoost(currentValence, contentValence, emotionalSensitivity) {
93
+ const congruence = Math.max(0, currentValence * contentValence);
94
+ return 1 + congruence * emotionalSensitivity * 0.3;
95
+ }
96
+ // ---------------------------------------------------------------------------
97
+ // Flashbulb detection
98
+ // ---------------------------------------------------------------------------
99
+ /**
100
+ * Determine whether this memory qualifies as a flashbulb memory.
101
+ * Flashbulb criteria: emotional intensity > threshold.
102
+ */
103
+ export function isFlashbulbMemory(emotionalIntensity, threshold = DEFAULT_ENCODING_CONFIG.flashbulbThreshold) {
104
+ return emotionalIntensity > threshold;
105
+ }
106
+ // ---------------------------------------------------------------------------
107
+ // Build emotional context from PAD state + content sentiment
108
+ // ---------------------------------------------------------------------------
109
+ /**
110
+ * Create the EmotionalContext snapshot for a memory trace.
111
+ * Blends content sentiment with current mood (70/30 split).
112
+ *
113
+ * @param currentMood Current PAD state from MoodEngine.
114
+ * @param contentSentiment Estimated sentiment of the content (-1..1). Defaults to 0.
115
+ * @param gmiMood Current GMI mood enum string.
116
+ */
117
+ export function buildEmotionalContext(currentMood, gmiMood, contentSentiment = 0) {
118
+ const valence = contentSentiment * 0.7 + currentMood.valence * 0.3;
119
+ // Normalise arousal from PAD range (-1..1) to (0..1)
120
+ const arousal = (currentMood.arousal + 1) / 2;
121
+ const intensity = Math.abs(valence) * arousal;
122
+ return {
123
+ valence,
124
+ arousal,
125
+ dominance: currentMood.dominance,
126
+ intensity,
127
+ gmiMood,
128
+ };
129
+ }
130
+ // ---------------------------------------------------------------------------
131
+ // Main encoding function
132
+ // ---------------------------------------------------------------------------
133
+ /**
134
+ * Compute encoding parameters for a new memory trace.
135
+ *
136
+ * Combines personality-modulated attention, Yerkes-Dodson arousal curve,
137
+ * mood-congruent encoding bias, and flashbulb detection into a single
138
+ * encoding result.
139
+ */
140
+ export function computeEncodingStrength(currentMood, traits, contentFeatures, contentSentiment = 0, config = DEFAULT_ENCODING_CONFIG) {
141
+ const weights = computeEncodingWeights(traits);
142
+ const base = config.baseStrength;
143
+ // Arousal boost via Yerkes-Dodson (normalise -1..1 → 0..1)
144
+ const arousal01 = (currentMood.arousal + 1) / 2;
145
+ const arousalBoost = yerksDodson(arousal01);
146
+ // Emotional intensity
147
+ const valence = contentSentiment * 0.7 + currentMood.valence * 0.3;
148
+ const emotionalIntensity = Math.abs(valence) * arousal01;
149
+ const emotionalBoost = 1 + emotionalIntensity * weights.emotionalSensitivity * 0.5;
150
+ // Content-type attention multiplier
151
+ const attentionMultiplier = computeAttentionMultiplier(weights, contentFeatures);
152
+ // Mood-congruent encoding
153
+ const congruenceBoost = moodCongruenceBoost(currentMood.valence, contentSentiment, weights.emotionalSensitivity);
154
+ // Flashbulb detection
155
+ const flashbulb = isFlashbulbMemory(emotionalIntensity, config.flashbulbThreshold);
156
+ const flashbulbBoost = flashbulb ? config.flashbulbStrengthMultiplier : 1.0;
157
+ // Composite initial strength
158
+ const strength = Math.min(1.0, base * arousalBoost * emotionalBoost * attentionMultiplier * congruenceBoost * flashbulbBoost);
159
+ // Stability: higher strength → more stable; flashbulb → much more stable
160
+ const stabilityMultiplier = flashbulb ? config.flashbulbStabilityMultiplier : 1.0;
161
+ const stability = config.baseStabilityMs * (1 + strength * 6) * stabilityMultiplier;
162
+ // Importance: blend of strength and content relevance
163
+ const importance = Math.min(1.0, strength * 0.6 + attentionMultiplier * 0.4);
164
+ return {
165
+ initialStrength: strength,
166
+ stability,
167
+ importance,
168
+ isFlashbulb: flashbulb,
169
+ };
170
+ }
171
+ //# sourceMappingURL=EncodingModel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EncodingModel.js","sourceRoot":"","sources":["../../../src/memory/encoding/EncodingModel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AASH,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAEvD,8EAA8E;AAC9E,sCAAsC;AACtC,8EAA8E;AAE9E,MAAM,OAAO,GAAG,CAAC,CAAqB,EAAU,EAAE,CAChD,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAEhD;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAAoB;IACzD,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACnC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,iBAAiB,C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,CAC7B,CAAC;IAEF,sBAAsB;IACtB,MAAM,SAAS,GAAG,iBAAiB,CAAC,kBAAkB,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAC;IACnF,MAAM,cAAc,GAAG,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,2BAA2B,CAAC,CAAC,CAAC,GAAG,CAAC;IAE5E,6BAA6B;IAC7B,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CACvB,GAAG,EACH,IAAI,GAAG,YAAY,GAAG,cAAc,GAAG,mBAAmB,GAAG,eAAe,GAAG,cAAc,CAC9F,CAAC;IAEF,yEAAyE;IACzE,MAAM,mBAAmB,GAAG,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,4BAA4B,CAAC,CAAC,CAAC,GAAG,CAAC;IAClF,MAAM,SAAS,GAAG,MAAM,CAAC,eAAe,GAAG,CAAC,CAAC,GAAG,QAAQ,GAAG,CAAC,CAAC,GAAG,mBAAmB,CAAC;IAEpF,sDAAsD;IACtD,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,GAAG,GAAG,GAAG,mBAAmB,GAAG,GAAG,CAAC,CAAC;IAE7E,OAAO;QACL,eAAe,EAAE,QAAQ;QACzB,SAAS;QACT,UAAU;QACV,WAAW,EAAE,SAAS;KACvB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @fileoverview Extension registration for the Cognitive Memory System.
3
+ *
4
+ * Registers the CognitiveMemoryManager as a MemoryProviderDescriptor
5
+ * in the AgentOS extension system, making it discoverable and configurable.
6
+ *
7
+ * @module agentos/memory/extension/CognitiveMemoryExtension
8
+ */
9
+ import { type MemoryProviderPayload, type MemoryProviderDescriptor } from '../../extensions/types.js';
10
+ /**
11
+ * Create a MemoryProviderDescriptor for the cognitive memory system.
12
+ *
13
+ * This is a factory function rather than a static constant because
14
+ * the provider needs runtime dependencies (vector store, embedding
15
+ * manager, etc.) injected at activation time.
16
+ */
17
+ export declare function createCognitiveMemoryDescriptor(overrides?: Partial<MemoryProviderPayload>): MemoryProviderDescriptor;
18
+ //# sourceMappingURL=CognitiveMemoryExtension.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CognitiveMemoryExtension.d.ts","sourceRoot":"","sources":["../../../src/memory/extension/CognitiveMemoryExtension.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,wBAAwB,EAC9B,MAAM,2BAA2B,CAAC;AAiFnC;;;;;;GAMG;AACH,wBAAgB,+BAA+B,CAC7C,SAAS,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,GACzC,wBAAwB,CAgF1B"}
@@ -0,0 +1,131 @@
1
+ /**
2
+ * @fileoverview Extension registration for the Cognitive Memory System.
3
+ *
4
+ * Registers the CognitiveMemoryManager as a MemoryProviderDescriptor
5
+ * in the AgentOS extension system, making it discoverable and configurable.
6
+ *
7
+ * @module agentos/memory/extension/CognitiveMemoryExtension
8
+ */
9
+ import { EXTENSION_KIND_MEMORY_PROVIDER, } from '../../extensions/types.js';
10
+ const NEUTRAL_PAD = {
11
+ valence: 0,
12
+ arousal: 0,
13
+ dominance: 0,
14
+ };
15
+ function isRuntimeManager(value) {
16
+ return (typeof value === 'object' &&
17
+ value !== null &&
18
+ typeof value.encode === 'function' &&
19
+ typeof value.retrieve === 'function');
20
+ }
21
+ function parseStoreInput(data) {
22
+ if (typeof data === 'string') {
23
+ return { input: data };
24
+ }
25
+ if (typeof data !== 'object' || data === null) {
26
+ throw new Error('Cognitive memory store() expects a string or { input, mood?, gmiMood?, options? }.');
27
+ }
28
+ const parsed = data;
29
+ if (typeof parsed.input !== 'string' || !parsed.input.trim()) {
30
+ throw new Error('Cognitive memory store() requires a non-empty input string.');
31
+ }
32
+ return {
33
+ input: parsed.input,
34
+ mood: parsed.mood,
35
+ gmiMood: parsed.gmiMood,
36
+ options: parsed.options,
37
+ };
38
+ }
39
+ function parseQueryInput(query) {
40
+ if (typeof query === 'string') {
41
+ return { text: query, mood: NEUTRAL_PAD };
42
+ }
43
+ if (typeof query !== 'object' || query === null) {
44
+ throw new Error('Cognitive memory query() expects a string or { text|query, mood? }.');
45
+ }
46
+ const parsed = query;
47
+ const text = parsed.text ?? parsed.query;
48
+ if (typeof text !== 'string' || !text.trim()) {
49
+ throw new Error('Cognitive memory query() requires a non-empty query string.');
50
+ }
51
+ return {
52
+ text,
53
+ mood: parsed.mood ?? NEUTRAL_PAD,
54
+ };
55
+ }
56
+ /**
57
+ * Create a MemoryProviderDescriptor for the cognitive memory system.
58
+ *
59
+ * This is a factory function rather than a static constant because
60
+ * the provider needs runtime dependencies (vector store, embedding
61
+ * manager, etc.) injected at activation time.
62
+ */
63
+ export function createCognitiveMemoryDescriptor(overrides) {
64
+ let manager = null;
65
+ const payload = {
66
+ name: 'cognitive-memory',
67
+ description: 'Cognitive science-grounded memory system with personality-affected ' +
68
+ 'encoding/retrieval, Ebbinghaus decay, mood-congruent recall, and ' +
69
+ 'Baddeley working memory slots.',
70
+ supportedTypes: ['episodic', 'semantic', 'procedural', 'prospective'],
71
+ initialize: async (config) => {
72
+ const candidate = config.manager;
73
+ if (!isRuntimeManager(candidate)) {
74
+ throw new Error('Cognitive memory provider requires initialize({ manager }) with encode()/retrieve() methods.');
75
+ }
76
+ manager = candidate;
77
+ },
78
+ store: async (_collectionId, data) => {
79
+ if (!manager) {
80
+ throw new Error('Cognitive memory provider not initialized.');
81
+ }
82
+ const input = parseStoreInput(data);
83
+ const trace = await manager.encode(input.input, input.mood ?? NEUTRAL_PAD, input.gmiMood ?? '', input.options);
84
+ return trace.id;
85
+ },
86
+ query: async (_collectionId, query, options) => {
87
+ if (!manager) {
88
+ throw new Error('Cognitive memory provider not initialized.');
89
+ }
90
+ const input = parseQueryInput(query);
91
+ const result = await manager.retrieve(input.text, input.mood, options ?? {});
92
+ return result.retrieved;
93
+ },
94
+ delete: async (_collectionId, ids) => {
95
+ if (!manager) {
96
+ throw new Error('Cognitive memory provider not initialized.');
97
+ }
98
+ const store = manager.getStore?.();
99
+ if (!store?.softDelete) {
100
+ throw new Error('Cognitive memory provider does not expose delete support.');
101
+ }
102
+ await Promise.all(ids.map((id) => Promise.resolve(store.softDelete?.(id))));
103
+ },
104
+ shutdown: async () => {
105
+ if (!manager)
106
+ return;
107
+ await manager.shutdown();
108
+ manager = null;
109
+ },
110
+ ...overrides,
111
+ };
112
+ return {
113
+ id: 'agentos-cognitive-memory',
114
+ kind: EXTENSION_KIND_MEMORY_PROVIDER,
115
+ priority: 100,
116
+ enableByDefault: true,
117
+ payload,
118
+ metadata: {
119
+ version: '1.0.0',
120
+ cognitiveModels: [
121
+ 'atkinson-shiffrin',
122
+ 'baddeley-working-memory',
123
+ 'ebbinghaus-forgetting',
124
+ 'yerkes-dodson',
125
+ 'tulving-episodic-semantic',
126
+ 'anderson-spreading-activation',
127
+ ],
128
+ },
129
+ };
130
+ }
131
+ //# sourceMappingURL=CognitiveMemoryExtension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CognitiveMemoryExtension.js","sourceRoot":"","sources":["../../../src/memory/extension/CognitiveMemoryExtension.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,8BAA8B,GAG/B,MAAM,2BAA2B,CAAC;AA2BnC,MAAM,WAAW,GAAa;IAC5B,OAAO,EAAE,CAAC;IACV,OAAO,EAAE,CAAC;IACV,SAAS,EAAE,CAAC;CACb,CAAC;AAEF,SAAS,gBAAgB,CAAC,KAAc;IACtC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,OAAQ,KAAuC,CAAC,MAAM,KAAK,UAAU;QACrE,OAAQ,KAAuC,CAAC,QAAQ,KAAK,UAAU,CACxE,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,IAAa;IACpC,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,OAA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
+ * Follows the CapabilityGraph pattern: lazy-loaded graphology,
5
+ * O(1) neighbor lookups, sub-ms traversal for typical memory counts.
6
+ *
7
+ * @module agentos/memory/graph/GraphologyMemoryGraph
8
+ */
9
+ import type { IMemoryGraph, MemoryGraphNodeMeta, MemoryEdge, MemoryEdgeType, SpreadingActivationConfig, ActivatedNode, MemoryCluster } from './IMemoryGraph.js';
10
+ export declare class GraphologyMemoryGraph implements IMemoryGraph {
11
+ private graph;
12
+ initialize(): Promise<void>;
13
+ private ensureGraph;
14
+ addNode(memoryId: string, metadata: MemoryGraphNodeMeta): Promise<void>;
15
+ removeNode(memoryId: string): Promise<void>;
16
+ hasNode(memoryId: string): boolean;
17
+ addEdge(edge: MemoryEdge): Promise<void>;
18
+ getEdges(memoryId: string, type?: MemoryEdgeType): MemoryEdge[];
19
+ removeEdge(sourceId: string, targetId: string): Promise<void>;
20
+ spreadingActivation(seedIds: string[], config?: SpreadingActivationConfig): Promise<ActivatedNode[]>;
21
+ recordCoActivation(memoryIds: string[], learningRate?: number): Promise<void>;
22
+ getConflicts(memoryId: string): MemoryEdge[];
23
+ detectClusters(minSize?: number): Promise<MemoryCluster[]>;
24
+ nodeCount(): number;
25
+ edgeCount(): number;
26
+ clear(): void;
27
+ shutdown(): Promise<void>;
28
+ }
29
+ //# sourceMappingURL=GraphologyMemoryGraph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GraphologyMemoryGraph.d.ts","sourceRoot":"","sources":["../../../src/memory/graph/GraphologyMemoryGraph.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,mBAAmB,EACnB,UAAU,EACV,cAAc,EACd,yBAAyB,EACzB,aAAa,EACb,aAAa,EACd,MAAM,mBAAmB,CAAC;AA4B3B,qBAAa,qBAAsB,YAAW,YAAY;IACxD,OAAO,CAAC,KAAK,CAA2B;IAElC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAKjC,OAAO,CAAC,WAAW;IAOb,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IASvE,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOjD,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAM5B,OAAO,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAyB9C,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,cAAc,GAAG,UAAU,EAAE;IAoBzD,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAU7D,mBAAmB,CACvB,OAAO,EAAE,MAAM,EAAE,EACjB,MAAM,CAAC,EAAE,yBAAyB,GACjC,OAAO,CAAC,aAAa,EAAE,CAAC;IAqBrB,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,YAAY,GAAE,MAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IA2BxF,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,EAAE;IAMtC,cAAc,CAAC,OAAO,GAAE,MAAU,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAuDnE,SAAS,IAAI,MAAM;IAInB,SAAS,IAAI,MAAM;IAInB,KAAK,IAAI,IAAI;IAIP,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAIhC"}
@@ -0,0 +1,224 @@
1
+ /**
2
+ * @fileoverview In-memory graphology-based memory graph (dev/testing).
3
+ *
4
+ * Follows the CapabilityGraph pattern: lazy-loaded graphology,
5
+ * O(1) neighbor lookups, sub-ms traversal for typical memory counts.
6
+ *
7
+ * @module agentos/memory/graph/GraphologyMemoryGraph
8
+ */
9
+ import { spreadActivation } from './SpreadingActivation.js';
10
+ let _GraphCtor;
11
+ async function resolveGraphology() {
12
+ if (_GraphCtor)
13
+ return _GraphCtor;
14
+ try {
15
+ const mod = await import('graphology');
16
+ _GraphCtor = (mod.default ?? mod);
17
+ return _GraphCtor;
18
+ }
19
+ catch {
20
+ throw new Error('graphology is required for GraphologyMemoryGraph but was not found. ' +
21
+ 'Install it: npm install graphology graphology-types');
22
+ }
23
+ }
24
+ // ---------------------------------------------------------------------------
25
+ // Implementation
26
+ // ---------------------------------------------------------------------------
27
+ export class GraphologyMemoryGraph {
28
+ constructor() {
29
+ this.graph = null;
30
+ }
31
+ async initialize() {
32
+ const GraphCtor = await resolveGraphology();
33
+ this.graph = new GraphCtor({ multi: false, type: 'undirected' });
34
+ }
35
+ ensureGraph() {
36
+ if (!this.graph)
37
+ throw new Error('GraphologyMemoryGraph not initialized.');
38
+ return this.graph;
39
+ }
40
+ // --- Node operations ---
41
+ async addNode(memoryId, metadata) {
42
+ const g = this.ensureGraph();
43
+ if (g.hasNode(memoryId)) {
44
+ g.replaceNodeAttributes(memoryId, metadata);
45
+ }
46
+ else {
47
+ g.addNode(memoryId, metadata);
48
+ }
49
+ }
50
+ async removeNode(memoryId) {
51
+ const g = this.ensureGraph();
52
+ if (g.hasNode(memoryId)) {
53
+ g.dropNode(memoryId);
54
+ }
55
+ }
56
+ hasNode(memoryId) {
57
+ return this.graph?.hasNode(memoryId) ?? false;
58
+ }
59
+ // --- Edge operations ---
60
+ async addEdge(edge) {
61
+ const g = this.ensureGraph();
62
+ if (!g.hasNode(edge.sourceId) || !g.hasNode(edge.targetId))
63
+ return;
64
+ if (edge.sourceId === edge.targetId)
65
+ return;
66
+ try {
67
+ const existing = g.edge(edge.sourceId, edge.targetId);
68
+ if (existing) {
69
+ const attrs = g.getEdgeAttributes(existing);
70
+ if (edge.weight > attrs.weight) {
71
+ g.setEdgeAttribute(existing, 'weight', edge.weight);
72
+ g.setEdgeAttribute(existing, 'type', edge.type);
73
+ }
74
+ }
75
+ else {
76
+ g.addEdge(edge.sourceId, edge.targetId, {
77
+ type: edge.type,
78
+ weight: edge.weight,
79
+ createdAt: edge.createdAt,
80
+ });
81
+ }
82
+ }
83
+ catch {
84
+ // Edge already exists in other direction (undirected)
85
+ }
86
+ }
87
+ getEdges(memoryId, type) {
88
+ const g = this.ensureGraph();
89
+ if (!g.hasNode(memoryId))
90
+ return [];
91
+ const edges = [];
92
+ g.forEachEdge(memoryId, (_edge, attrs, source, target) => {
93
+ const edgeType = attrs.type;
94
+ if (!type || edgeType === type) {
95
+ edges.push({
96
+ sourceId: source,
97
+ targetId: target,
98
+ type: edgeType,
99
+ weight: attrs.weight,
100
+ createdAt: attrs.createdAt,
101
+ });
102
+ }
103
+ });
104
+ return edges;
105
+ }
106
+ async removeEdge(sourceId, targetId) {
107
+ const g = this.ensureGraph();
108
+ try {
109
+ const edge = g.edge(sourceId, targetId);
110
+ if (edge)
111
+ g.dropEdge(edge);
112
+ }
113
+ catch { /* no-op */ }
114
+ }
115
+ // --- Spreading activation ---
116
+ async spreadingActivation(seedIds, config) {
117
+ const g = this.ensureGraph();
118
+ // Delegate to pure-function implementation
119
+ return spreadActivation({
120
+ seedIds,
121
+ getNeighbors: (nodeId) => {
122
+ if (!g.hasNode(nodeId))
123
+ return [];
124
+ const neighbors = [];
125
+ g.forEachEdge(nodeId, (_edge, attrs, source, target) => {
126
+ const neighborId = source === nodeId ? target : source;
127
+ neighbors.push({ id: neighborId, weight: attrs.weight });
128
+ });
129
+ return neighbors;
130
+ },
131
+ config,
132
+ });
133
+ }
134
+ // --- Co-activation (Hebbian learning) ---
135
+ async recordCoActivation(memoryIds, learningRate = 0.1) {
136
+ const g = this.ensureGraph();
137
+ const validIds = memoryIds.filter((id) => g.hasNode(id));
138
+ const now = Date.now();
139
+ for (let i = 0; i < validIds.length; i++) {
140
+ for (let j = i + 1; j < validIds.length; j++) {
141
+ try {
142
+ const existing = g.edge(validIds[i], validIds[j]);
143
+ if (existing) {
144
+ const attrs = g.getEdgeAttributes(existing);
145
+ // Hebbian: strengthen existing connection
146
+ g.setEdgeAttribute(existing, 'weight', Math.min(1.0, attrs.weight + learningRate));
147
+ }
148
+ else {
149
+ g.addEdge(validIds[i], validIds[j], {
150
+ type: 'CO_ACTIVATED',
151
+ weight: learningRate,
152
+ createdAt: now,
153
+ });
154
+ }
155
+ }
156
+ catch { /* edge already exists */ }
157
+ }
158
+ }
159
+ }
160
+ // --- Conflict detection ---
161
+ getConflicts(memoryId) {
162
+ return this.getEdges(memoryId, 'CONTRADICTS');
163
+ }
164
+ // --- Clustering ---
165
+ async detectClusters(minSize = 3) {
166
+ const g = this.ensureGraph();
167
+ if (g.order < minSize)
168
+ return [];
169
+ // Simple connected-component clustering (upgrade to Louvain when graphology-communities is available)
170
+ const visited = new Set();
171
+ const clusters = [];
172
+ let clusterIdx = 0;
173
+ g.forEachNode((nodeId) => {
174
+ if (visited.has(nodeId))
175
+ return;
176
+ // BFS from this node
177
+ const component = [];
178
+ const queue = [nodeId];
179
+ visited.add(nodeId);
180
+ while (queue.length > 0) {
181
+ const current = queue.shift();
182
+ component.push(current);
183
+ g.forEachEdge(current, (_edge, _attrs, source, target) => {
184
+ const neighbor = source === current ? target : source;
185
+ if (!visited.has(neighbor)) {
186
+ visited.add(neighbor);
187
+ queue.push(neighbor);
188
+ }
189
+ });
190
+ }
191
+ if (component.length >= minSize) {
192
+ // Density = actual edges / possible edges
193
+ let edgeCount = 0;
194
+ for (const id of component) {
195
+ const nodeEdges = this.getEdges(id);
196
+ edgeCount += nodeEdges.filter((e) => component.includes(e.sourceId === id ? e.targetId : e.sourceId)).length;
197
+ }
198
+ edgeCount /= 2; // undirected
199
+ const possibleEdges = (component.length * (component.length - 1)) / 2;
200
+ clusters.push({
201
+ clusterId: `cluster_${clusterIdx++}`,
202
+ memberIds: component,
203
+ density: possibleEdges > 0 ? edgeCount / possibleEdges : 0,
204
+ });
205
+ }
206
+ });
207
+ return clusters;
208
+ }
209
+ // --- Lifecycle ---
210
+ nodeCount() {
211
+ return this.graph?.order ?? 0;
212
+ }
213
+ edgeCount() {
214
+ return this.graph?.size ?? 0;
215
+ }
216
+ clear() {
217
+ this.graph?.clear();
218
+ }
219
+ async shutdown() {
220
+ this.graph?.clear();
221
+ this.graph = null;
222
+ }
223
+ }
224
+ //# sourceMappingURL=GraphologyMemoryGraph.js.map