@hazeljs/memory 0.2.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/LICENSE +192 -0
  2. package/README.md +121 -0
  3. package/dist/__tests__/composite.store.test.d.ts +2 -0
  4. package/dist/__tests__/composite.store.test.d.ts.map +1 -0
  5. package/dist/__tests__/composite.store.test.js +216 -0
  6. package/dist/__tests__/composite.store.test.js.map +1 -0
  7. package/dist/__tests__/create-memory-store.test.d.ts +2 -0
  8. package/dist/__tests__/create-memory-store.test.d.ts.map +1 -0
  9. package/dist/__tests__/create-memory-store.test.js +85 -0
  10. package/dist/__tests__/create-memory-store.test.js.map +1 -0
  11. package/dist/__tests__/in-memory.store.test.d.ts +2 -0
  12. package/dist/__tests__/in-memory.store.test.d.ts.map +1 -0
  13. package/dist/__tests__/in-memory.store.test.js +336 -0
  14. package/dist/__tests__/in-memory.store.test.js.map +1 -0
  15. package/dist/__tests__/memory.config.test.d.ts +2 -0
  16. package/dist/__tests__/memory.config.test.d.ts.map +1 -0
  17. package/dist/__tests__/memory.config.test.js +39 -0
  18. package/dist/__tests__/memory.config.test.js.map +1 -0
  19. package/dist/__tests__/memory.service.test.d.ts +2 -0
  20. package/dist/__tests__/memory.service.test.d.ts.map +1 -0
  21. package/dist/__tests__/memory.service.test.js +231 -0
  22. package/dist/__tests__/memory.service.test.js.map +1 -0
  23. package/dist/config/memory.config.d.ts +17 -0
  24. package/dist/config/memory.config.d.ts.map +1 -0
  25. package/dist/config/memory.config.js +20 -0
  26. package/dist/config/memory.config.js.map +1 -0
  27. package/dist/generated/prisma/client.d.ts +1 -0
  28. package/dist/generated/prisma/client.js +5 -0
  29. package/dist/generated/prisma/default.d.ts +1 -0
  30. package/dist/generated/prisma/default.js +5 -0
  31. package/dist/generated/prisma/edge.d.ts +1 -0
  32. package/dist/generated/prisma/edge.js +213 -0
  33. package/dist/generated/prisma/index-browser.js +199 -0
  34. package/dist/generated/prisma/index.d.ts +2874 -0
  35. package/dist/generated/prisma/index.js +234 -0
  36. package/dist/generated/prisma/libquery_engine-debian-openssl-3.0.x.so.node +0 -0
  37. package/dist/generated/prisma/package.json +183 -0
  38. package/dist/generated/prisma/query_engine_bg.js +2 -0
  39. package/dist/generated/prisma/query_engine_bg.wasm +0 -0
  40. package/dist/generated/prisma/runtime/edge-esm.js +35 -0
  41. package/dist/generated/prisma/runtime/edge.js +35 -0
  42. package/dist/generated/prisma/runtime/index-browser.d.ts +370 -0
  43. package/dist/generated/prisma/runtime/index-browser.js +17 -0
  44. package/dist/generated/prisma/runtime/library.d.ts +3982 -0
  45. package/dist/generated/prisma/runtime/library.js +147 -0
  46. package/dist/generated/prisma/runtime/react-native.js +84 -0
  47. package/dist/generated/prisma/runtime/wasm-compiler-edge.js +85 -0
  48. package/dist/generated/prisma/runtime/wasm-engine-edge.js +38 -0
  49. package/dist/generated/prisma/schema.prisma +32 -0
  50. package/dist/generated/prisma/wasm-edge-light-loader.mjs +5 -0
  51. package/dist/generated/prisma/wasm-worker-loader.mjs +5 -0
  52. package/dist/generated/prisma/wasm.d.ts +1 -0
  53. package/dist/generated/prisma/wasm.js +220 -0
  54. package/dist/index.d.ts +16 -0
  55. package/dist/index.d.ts.map +1 -0
  56. package/dist/index.js +50 -0
  57. package/dist/index.js.map +1 -0
  58. package/dist/prisma-client.d.ts +13 -0
  59. package/dist/prisma-client.d.ts.map +1 -0
  60. package/dist/prisma-client.js +37 -0
  61. package/dist/prisma-client.js.map +1 -0
  62. package/dist/prisma.d.ts +12 -0
  63. package/dist/prisma.d.ts.map +1 -0
  64. package/dist/prisma.js +20 -0
  65. package/dist/prisma.js.map +1 -0
  66. package/dist/service/memory.service.d.ts +63 -0
  67. package/dist/service/memory.service.d.ts.map +1 -0
  68. package/dist/service/memory.service.js +134 -0
  69. package/dist/service/memory.service.js.map +1 -0
  70. package/dist/store/adapters/postgres.store.d.ts +55 -0
  71. package/dist/store/adapters/postgres.store.d.ts.map +1 -0
  72. package/dist/store/adapters/postgres.store.js +263 -0
  73. package/dist/store/adapters/postgres.store.js.map +1 -0
  74. package/dist/store/adapters/prisma.store.d.ts +88 -0
  75. package/dist/store/adapters/prisma.store.d.ts.map +1 -0
  76. package/dist/store/adapters/prisma.store.js +202 -0
  77. package/dist/store/adapters/prisma.store.js.map +1 -0
  78. package/dist/store/adapters/redis.store.d.ts +44 -0
  79. package/dist/store/adapters/redis.store.d.ts.map +1 -0
  80. package/dist/store/adapters/redis.store.js +261 -0
  81. package/dist/store/adapters/redis.store.js.map +1 -0
  82. package/dist/store/adapters/vector-episodic.store.d.ts +55 -0
  83. package/dist/store/adapters/vector-episodic.store.d.ts.map +1 -0
  84. package/dist/store/adapters/vector-episodic.store.js +253 -0
  85. package/dist/store/adapters/vector-episodic.store.js.map +1 -0
  86. package/dist/store/composite.store.d.ts +37 -0
  87. package/dist/store/composite.store.d.ts.map +1 -0
  88. package/dist/store/composite.store.js +151 -0
  89. package/dist/store/composite.store.js.map +1 -0
  90. package/dist/store/create-memory-store.d.ts +26 -0
  91. package/dist/store/create-memory-store.d.ts.map +1 -0
  92. package/dist/store/create-memory-store.js +29 -0
  93. package/dist/store/create-memory-store.js.map +1 -0
  94. package/dist/store/in-memory.store.d.ts +45 -0
  95. package/dist/store/in-memory.store.d.ts.map +1 -0
  96. package/dist/store/in-memory.store.js +316 -0
  97. package/dist/store/in-memory.store.js.map +1 -0
  98. package/dist/store/memory-store.interface.d.ts +56 -0
  99. package/dist/store/memory-store.interface.d.ts.map +1 -0
  100. package/dist/store/memory-store.interface.js +6 -0
  101. package/dist/store/memory-store.interface.js.map +1 -0
  102. package/dist/types/category.types.d.ts +29 -0
  103. package/dist/types/category.types.d.ts.map +1 -0
  104. package/dist/types/category.types.js +44 -0
  105. package/dist/types/category.types.js.map +1 -0
  106. package/dist/types/memory-item.types.d.ts +32 -0
  107. package/dist/types/memory-item.types.d.ts.map +1 -0
  108. package/dist/types/memory-item.types.js +6 -0
  109. package/dist/types/memory-item.types.js.map +1 -0
  110. package/dist/types/store.types.d.ts +36 -0
  111. package/dist/types/store.types.d.ts.map +1 -0
  112. package/dist/types/store.types.js +6 -0
  113. package/dist/types/store.types.js.map +1 -0
  114. package/package.json +77 -0
package/LICENSE ADDED
@@ -0,0 +1,192 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ Copyright 2024 HazelJS Team
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
18
+
19
+ ---
20
+
21
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
22
+
23
+ 1. Definitions.
24
+
25
+ "License" shall mean the terms and conditions for use, reproduction,
26
+ and distribution as defined by Sections 1 through 9 of this document.
27
+
28
+ "Licensor" shall mean the copyright owner or entity authorized by
29
+ the copyright owner that is granting the License.
30
+
31
+ "Legal Entity" shall mean the union of the acting entity and all
32
+ other entities that control, are controlled by, or are under common
33
+ control with that entity. For the purposes of this definition,
34
+ "control" means (i) the power, direct or indirect, to cause the
35
+ direction or management of such entity, whether by contract or
36
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
37
+ outstanding shares, or (iii) beneficial ownership of such entity.
38
+
39
+ "You" (or "Your") shall mean an individual or Legal Entity
40
+ exercising permissions granted by this License.
41
+
42
+ "Source" form shall mean the preferred form for making modifications,
43
+ including but not limited to software source code, documentation
44
+ source, and configuration files.
45
+
46
+ "Object" form shall mean any form resulting from mechanical
47
+ transformation or translation of a Source form, including but
48
+ not limited to compiled object code, generated documentation,
49
+ and conversions to other media types.
50
+
51
+ "Work" shall mean the work of authorship, whether in Source or
52
+ Object form, made available under the License, as indicated by a
53
+ copyright notice that is included in or attached to the work
54
+ (an example is provided in the Appendix below).
55
+
56
+ "Derivative Works" shall mean any work, whether in Source or Object
57
+ form, that is based on (or derived from) the Work and for which the
58
+ editorial revisions, annotations, elaborations, or other modifications
59
+ represent, as a whole, an original work of authorship. For the purposes
60
+ of this License, Derivative Works shall not include works that remain
61
+ separable from, or merely link (or bind by name) to the interfaces of,
62
+ the Work and Derivative Works thereof.
63
+
64
+ "Contribution" shall mean any work of authorship, including
65
+ the original version of the Work and any modifications or additions
66
+ to that Work or Derivative Works thereof, that is intentionally
67
+ submitted to Licensor for inclusion in the Work by the copyright owner
68
+ or by an individual or Legal Entity authorized to submit on behalf of
69
+ the copyright owner. For the purposes of this definition, "submitted"
70
+ means any form of electronic, verbal, or written communication sent
71
+ to the Licensor or its representatives, including but not limited to
72
+ communication on electronic mailing lists, source code control systems,
73
+ and issue tracking systems that are managed by, or on behalf of, the
74
+ Licensor for the purpose of discussing and improving the Work, but
75
+ excluding communication that is conspicuously marked or otherwise
76
+ designated in writing by the copyright owner as "Not a Contribution."
77
+
78
+ "Contributor" shall mean Licensor and any individual or Legal Entity
79
+ on behalf of whom a Contribution has been received by Licensor and
80
+ subsequently incorporated within the Work.
81
+
82
+ 2. Grant of Copyright License. Subject to the terms and conditions of
83
+ this License, each Contributor hereby grants to You a perpetual,
84
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
85
+ copyright license to reproduce, prepare Derivative Works of,
86
+ publicly display, publicly perform, sublicense, and distribute the
87
+ Work and such Derivative Works in Source or Object form.
88
+
89
+ 3. Grant of Patent License. Subject to the terms and conditions of
90
+ this License, each Contributor hereby grants to You a perpetual,
91
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
92
+ (except as stated in this section) patent license to make, have made,
93
+ use, offer to sell, sell, import, and otherwise transfer the Work,
94
+ where such license applies only to those patent claims licensable
95
+ by such Contributor that are necessarily infringed by their
96
+ Contribution(s) alone or by combination of their Contribution(s)
97
+ with the Work to which such Contribution(s) was submitted. If You
98
+ institute patent litigation against any entity (including a
99
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
100
+ or a Contribution incorporated within the Work constitutes direct
101
+ or contributory patent infringement, then any patent licenses
102
+ granted to You under this License for that Work shall terminate
103
+ as of the date such litigation is filed.
104
+
105
+ 4. Redistribution. You may reproduce and distribute copies of the
106
+ Work or Derivative Works thereof in any medium, with or without
107
+ modifications, and in Source or Object form, provided that You
108
+ meet the following conditions:
109
+
110
+ (a) You must give any other recipients of the Work or
111
+ Derivative Works a copy of this License; and
112
+
113
+ (b) You must cause any modified files to carry prominent notices
114
+ stating that You changed the files; and
115
+
116
+ (c) You must retain, in the Source form of any Derivative Works
117
+ that You distribute, all copyright, patent, trademark, and
118
+ attribution notices from the Source form of the Work,
119
+ excluding those notices that do not pertain to any part of
120
+ the Derivative Works; and
121
+
122
+ (d) If the Work includes a "NOTICE" text file as part of its
123
+ distribution, then any Derivative Works that You distribute must
124
+ include a readable copy of the attribution notices contained
125
+ within such NOTICE file, excluding those notices that do not
126
+ pertain to any part of the Derivative Works, in at least one
127
+ of the following places: within a NOTICE text file distributed
128
+ as part of the Derivative Works; within the Source form or
129
+ documentation, if provided along with the Derivative Works; or,
130
+ within a display generated by the Derivative Works, if and
131
+ wherever such third-party notices normally appear. The contents
132
+ of the NOTICE file are for informational purposes only and
133
+ do not modify the License. You may add Your own attribution
134
+ notices within Derivative Works that You distribute, alongside
135
+ or as an addendum to the NOTICE text from the Work, provided
136
+ that such additional attribution notices cannot be construed
137
+ as modifying the License.
138
+
139
+ You may add Your own copyright statement to Your modifications and
140
+ may provide additional or different license terms and conditions
141
+ for use, reproduction, or distribution of Your modifications, or
142
+ for any such Derivative Works as a whole, provided Your use,
143
+ reproduction, and distribution of the Work otherwise complies with
144
+ the conditions stated in this License.
145
+
146
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
147
+ any Contribution intentionally submitted for inclusion in the Work
148
+ by You to the Licensor shall be under the terms and conditions of
149
+ this License, without any additional terms or conditions.
150
+ Notwithstanding the above, nothing herein shall supersede or modify
151
+ the terms of any separate license agreement you may have executed
152
+ with Licensor regarding such Contributions.
153
+
154
+ 6. Trademarks. This License does not grant permission to use the trade
155
+ names, trademarks, service marks, or product names of the Licensor,
156
+ except as required for reasonable and customary use in describing the
157
+ origin of the Work and reproducing the content of the NOTICE file.
158
+
159
+ 7. Disclaimer of Warranty. Unless required by applicable law or
160
+ agreed to in writing, Licensor provides the Work (and each
161
+ Contributor provides its Contributions) on an "AS IS" BASIS,
162
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
163
+ implied, including, without limitation, any warranties or conditions
164
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
165
+ PARTICULAR PURPOSE. You are solely responsible for determining the
166
+ appropriateness of using or redistributing the Work and assume any
167
+ risks associated with Your exercise of permissions under this License.
168
+
169
+ 8. Limitation of Liability. In no event and under no legal theory,
170
+ whether in tort (including negligence), contract, or otherwise,
171
+ unless required by applicable law (such as deliberate and grossly
172
+ negligent acts) or agreed to in writing, shall any Contributor be
173
+ liable to You for damages, including any direct, indirect, special,
174
+ incidental, or consequential damages of any character arising as a
175
+ result of this License or out of the use or inability to use the
176
+ Work (including but not limited to damages for loss of goodwill,
177
+ work stoppage, computer failure or malfunction, or any and all
178
+ other commercial damages or losses), even if such Contributor
179
+ has been advised of the possibility of such damages.
180
+
181
+ 9. Accepting Warranty or Additional Liability. While redistributing
182
+ the Work or Derivative Works thereof, You may choose to offer,
183
+ and charge a fee for, acceptance of support, warranty, indemnity,
184
+ or other liability obligations and/or rights consistent with this
185
+ License. However, in accepting such obligations, You may act only
186
+ on Your own behalf and on Your sole responsibility, not on behalf
187
+ of any other Contributor, and only if You agree to indemnify,
188
+ defend, and hold each Contributor harmless for any liability
189
+ incurred by, or claims asserted against, such Contributor by reason
190
+ of your accepting any such warranty or additional liability.
191
+
192
+ END OF TERMS AND CONDITIONS
package/README.md ADDED
@@ -0,0 +1,121 @@
1
+ # @hazeljs/memory
2
+
3
+ **Pluggable user memory for HazelJS.** Profile, preferences, behavioral patterns, emotional state, episodic and semantic memory — one interface, multiple backends. Share the same store between RAG and agents in-process.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@hazeljs/memory.svg)](https://www.npmjs.com/package/@hazeljs/memory)
6
+ [![npm downloads](https://img.shields.io/npm/dm/@hazeljs/memory)](https://www.npmjs.com/package/@hazeljs/memory)
7
+ [![License: Apache-2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
8
+
9
+ **Storage:** By default the package uses **in-memory storage** (no dependencies). For durable persistence, use the Prisma store (same pattern as `@hazeljs/flow`) or plug in Postgres, Redis, or vector backends.
10
+
11
+ ## Features
12
+
13
+ - **One interface, multiple backends** — In-memory (default), Postgres (raw or Prisma), Redis, vector episodic, composite
14
+ - **Memory categories** — Profile, preference, behavioral, emotional, episodic, semantic_summary
15
+ - **Explicit vs inferred** — Store user-stated facts and system-inferred patterns separately
16
+ - **Optional TTL** — e.g. for emotional state or short-lived context
17
+ - **Composite store** — Route by category to primary + optional episodic/vector store
18
+ - **RAG & agent integration** — Use `createHazelMemoryStoreAdapter` from `@hazeljs/rag/memory-hazel` to back `MemoryManager`; share one store across `RAGPipelineWithMemory` and `AgentRuntime`
19
+
20
+ ## Installation
21
+
22
+ ```bash
23
+ pnpm add @hazeljs/memory
24
+ ```
25
+
26
+ No database or env vars are required for the default in-memory mode.
27
+
28
+ ## Quick Start
29
+
30
+ ### In-memory (default, no dependencies)
31
+
32
+ ```typescript
33
+ import { createDefaultMemoryStore, MemoryService } from '@hazeljs/memory';
34
+
35
+ const store = createDefaultMemoryStore();
36
+ const service = new MemoryService(store);
37
+ await service.initialize();
38
+
39
+ // Use service to get/set memory by userId, category, etc.
40
+ ```
41
+
42
+ ### PostgreSQL with Prisma
43
+
44
+ When you use Prisma in your app (e.g. like `@hazeljs/flow` and `@hazeljs/flow-runtime`), use the Prisma store:
45
+
46
+ ```typescript
47
+ import { createPrismaMemoryStore, getMemoryPrismaClient } from '@hazeljs/memory/prisma';
48
+ import { MemoryService } from '@hazeljs/memory';
49
+
50
+ const prisma = getMemoryPrismaClient(process.env.DATABASE_URL);
51
+ const store = createPrismaMemoryStore(prisma);
52
+ const service = new MemoryService(store);
53
+ await service.initialize();
54
+ ```
55
+
56
+ **Build:** Run `pnpm prisma:generate` (or `prisma generate`) before `pnpm build` so the Prisma client is generated. Migrate with `pnpm prisma:migrate` from the package directory.
57
+
58
+ ## Persistence
59
+
60
+ | Backend | Module / Factory | Use case |
61
+ |--------|-------------------|----------|
62
+ | **In-memory** | `createDefaultMemoryStore()` | Development, tests, no DB |
63
+ | **Prisma** | `createPrismaMemoryStore(prisma)` from `@hazeljs/memory/prisma` | Production, same app DB as flow/core |
64
+ | **Postgres (raw)** | `PostgresStore` — pass a `pg` pool with a `query` method (see `postgres.store.ts`) | Existing Postgres without Prisma |
65
+ | **Redis** | `RedisStore` — pass an ioredis-style client | High-throughput, shared across processes |
66
+ | **Vector episodic** | `VectorEpisodicStore` | Episodic/semantic vector search |
67
+ | **Composite** | `CompositeMemoryStore` | Route by category to primary + optional episodic store |
68
+
69
+ ## Memory categories
70
+
71
+ | Category | Description |
72
+ |----------|-------------|
73
+ | `profile` | User identity and static attributes |
74
+ | `preference` | Stated preferences (e.g. language, theme) |
75
+ | `behavioral` | Inferred behavior patterns |
76
+ | `emotional` | Emotional state (often with TTL) |
77
+ | `episodic` | Event-based memories (what happened when) |
78
+ | `semantic_summary` | Summarized or semantic facts |
79
+
80
+ See types in `src/types/`.
81
+
82
+ ## Integration with @hazeljs/rag and @hazeljs/agent
83
+
84
+ To back RAG (and agent) memory with `@hazeljs/memory` so RAG and agents share the same user context in-process:
85
+
86
+ ```bash
87
+ pnpm add @hazeljs/rag @hazeljs/memory
88
+ ```
89
+
90
+ ```typescript
91
+ import { MemoryManager, RAGPipelineWithMemory } from '@hazeljs/rag';
92
+ import { createHazelMemoryStoreAdapter } from '@hazeljs/rag/memory-hazel';
93
+ import { MemoryService, createDefaultMemoryStore } from '@hazeljs/memory';
94
+
95
+ const hazelStore = createDefaultMemoryStore();
96
+ const memoryService = new MemoryService(hazelStore);
97
+ const ragStore = createHazelMemoryStoreAdapter(memoryService);
98
+ const memoryManager = new MemoryManager(ragStore);
99
+
100
+ // Pass the same MemoryManager to RAG and to every AgentRuntime
101
+ const rag = new RAGPipelineWithMemory(config, memoryManager, llmFunction);
102
+ // agentRuntime = new AgentRuntime({ ..., memoryManager });
103
+ ```
104
+
105
+ See [@hazeljs/rag README](../rag/README.md) (Memory System / Using @hazeljs/memory as the backend) for full details.
106
+
107
+ ## Scripts
108
+
109
+ - `prisma:generate` — Generate Prisma client
110
+ - `prisma:migrate` — Run migrations (dev)
111
+ - `prisma:deploy` — Deploy migrations (prod)
112
+ - `prisma:studio` — Open Prisma Studio (when using Prisma store)
113
+ - `test` — Run tests
114
+
115
+ ## License
116
+
117
+ Apache 2.0 © [HazelJS](https://hazeljs.com)
118
+
119
+ ## Contributing
120
+
121
+ Contributions are welcome! See [CONTRIBUTING.md](../../CONTRIBUTING.md) for details.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=composite.store.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"composite.store.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/composite.store.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,216 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const composite_store_1 = require("../store/composite.store");
4
+ const in_memory_store_1 = require("../store/in-memory.store");
5
+ const category_types_1 = require("../types/category.types");
6
+ function makeItem(overrides = {}) {
7
+ return {
8
+ id: 'id-' + Math.random().toString(36).slice(2),
9
+ userId: 'user-1',
10
+ category: category_types_1.MemoryCategory.PREFERENCE,
11
+ key: 'key-' + Math.random().toString(36).slice(2),
12
+ value: 'value',
13
+ confidence: 0.9,
14
+ source: 'explicit',
15
+ evidence: [],
16
+ createdAt: new Date(),
17
+ updatedAt: new Date(),
18
+ accessCount: 0,
19
+ ...overrides,
20
+ };
21
+ }
22
+ describe('CompositeMemoryStore', () => {
23
+ let primary;
24
+ let episodic;
25
+ let composite;
26
+ beforeEach(async () => {
27
+ primary = (0, in_memory_store_1.createDefaultMemoryStore)();
28
+ episodic = (0, in_memory_store_1.createDefaultMemoryStore)();
29
+ composite = new composite_store_1.CompositeMemoryStore({
30
+ primary,
31
+ episodic,
32
+ episodicCategories: [category_types_1.MemoryCategory.EPISODIC, category_types_1.MemoryCategory.SEMANTIC_SUMMARY],
33
+ });
34
+ await composite.initialize();
35
+ });
36
+ describe('initialize', () => {
37
+ it('initializes both stores', async () => {
38
+ await expect(composite.initialize()).resolves.toBeUndefined();
39
+ });
40
+ });
41
+ describe('save and get', () => {
42
+ it('routes PREFERENCE to primary', async () => {
43
+ const item = makeItem({ category: category_types_1.MemoryCategory.PREFERENCE });
44
+ const id = await composite.save(item);
45
+ expect(id).toBeDefined();
46
+ const fromComposite = await composite.get(id);
47
+ expect(fromComposite).not.toBeNull();
48
+ const fromPrimary = await primary.get(id);
49
+ expect(fromPrimary).not.toBeNull();
50
+ expect(await episodic.get(id)).toBeNull();
51
+ });
52
+ it('routes EPISODIC to episodic when episodic store present', async () => {
53
+ const item = makeItem({ category: category_types_1.MemoryCategory.EPISODIC });
54
+ const id = await composite.save(item);
55
+ expect(id).toBeDefined();
56
+ const fromComposite = await composite.get(id);
57
+ expect(fromComposite).not.toBeNull();
58
+ const fromEpisodic = await episodic.get(id);
59
+ expect(fromEpisodic).not.toBeNull();
60
+ });
61
+ });
62
+ describe('saveBatch', () => {
63
+ it('saves to correct stores by category', async () => {
64
+ const items = [
65
+ makeItem({ category: category_types_1.MemoryCategory.PREFERENCE, key: 'p1' }),
66
+ makeItem({ category: category_types_1.MemoryCategory.EPISODIC, key: 'e1' }),
67
+ ];
68
+ const ids = await composite.saveBatch(items);
69
+ expect(ids).toHaveLength(2);
70
+ });
71
+ });
72
+ describe('get', () => {
73
+ it('checks primary then episodic', async () => {
74
+ const id = await primary.save(makeItem({ category: category_types_1.MemoryCategory.PREFERENCE }));
75
+ const got = await composite.get(id);
76
+ expect(got).not.toBeNull();
77
+ });
78
+ it('returns from episodic when not in primary', async () => {
79
+ const item = makeItem({ category: category_types_1.MemoryCategory.EPISODIC, key: 'ep-only' });
80
+ const id = await composite.save(item);
81
+ const got = await composite.get(id);
82
+ expect(got).not.toBeNull();
83
+ expect(got.id).toBe(id);
84
+ });
85
+ it('returns null when not in either store', async () => {
86
+ expect(await composite.get('nonexistent')).toBeNull();
87
+ });
88
+ });
89
+ describe('update', () => {
90
+ it('updates item in primary', async () => {
91
+ const item = makeItem({ category: category_types_1.MemoryCategory.PREFERENCE, value: 'v1' });
92
+ const id = await composite.save(item);
93
+ await composite.update(id, { value: 'v2' });
94
+ const got = await composite.get(id);
95
+ expect(got.value).toBe('v2');
96
+ });
97
+ it('updates item in episodic when id is in episodic store', async () => {
98
+ const item = makeItem({ category: category_types_1.MemoryCategory.EPISODIC, value: 'v1' });
99
+ const id = await composite.save(item);
100
+ await composite.update(id, { value: 'v2' });
101
+ const got = await composite.get(id);
102
+ expect(got.value).toBe('v2');
103
+ });
104
+ });
105
+ describe('delete', () => {
106
+ it('deletes from both stores', async () => {
107
+ const id = await composite.save(makeItem({ category: category_types_1.MemoryCategory.PREFERENCE }));
108
+ await composite.delete(id);
109
+ expect(await composite.get(id)).toBeNull();
110
+ });
111
+ it('deletes from episodic when id only in episodic', async () => {
112
+ const id = await composite.save(makeItem({ category: category_types_1.MemoryCategory.EPISODIC }));
113
+ await composite.delete(id);
114
+ expect(await composite.get(id)).toBeNull();
115
+ });
116
+ });
117
+ describe('deleteBatch', () => {
118
+ it('deletes from both primary and episodic', async () => {
119
+ const id1 = await composite.save(makeItem({ category: category_types_1.MemoryCategory.PREFERENCE, key: 'pb1' }));
120
+ const id2 = await composite.save(makeItem({ category: category_types_1.MemoryCategory.EPISODIC, key: 'eb1' }));
121
+ await composite.deleteBatch([id1, id2]);
122
+ expect(await composite.get(id1)).toBeNull();
123
+ expect(await composite.get(id2)).toBeNull();
124
+ });
125
+ });
126
+ describe('query', () => {
127
+ it('returns merged results from both stores', async () => {
128
+ await composite.save(makeItem({ category: category_types_1.MemoryCategory.PREFERENCE, key: 'pk' }));
129
+ await composite.save(makeItem({ category: category_types_1.MemoryCategory.EPISODIC, key: 'ek' }));
130
+ const results = await composite.query({
131
+ userId: 'user-1',
132
+ limit: 10,
133
+ });
134
+ expect(results.length).toBeGreaterThanOrEqual(2);
135
+ });
136
+ it('sorts and applies limit', async () => {
137
+ const results = await composite.query({
138
+ userId: 'user-1',
139
+ orderBy: 'updatedAt',
140
+ order: 'desc',
141
+ limit: 5,
142
+ offset: 0,
143
+ });
144
+ expect(Array.isArray(results)).toBe(true);
145
+ });
146
+ });
147
+ describe('search', () => {
148
+ it('uses episodic search when episodic store has search', async () => {
149
+ const results = await composite.search('query', { userId: 'user-1' });
150
+ expect(Array.isArray(results)).toBe(true);
151
+ });
152
+ it('falls back to primary search when episodic has no search', async () => {
153
+ const primaryWithSearch = (0, in_memory_store_1.createDefaultMemoryStore)();
154
+ const episodicNoSearch = (0, in_memory_store_1.createDefaultMemoryStore)();
155
+ const ep = episodicNoSearch;
156
+ ep.search = undefined;
157
+ const comp = new composite_store_1.CompositeMemoryStore({
158
+ primary: primaryWithSearch,
159
+ episodic: ep,
160
+ episodicCategories: [category_types_1.MemoryCategory.EPISODIC],
161
+ });
162
+ await comp.initialize();
163
+ const results = await comp.search('q', { userId: 'user-1' });
164
+ expect(Array.isArray(results)).toBe(true);
165
+ });
166
+ it('returns empty when neither store has search', async () => {
167
+ const primaryNoSearch = (0, in_memory_store_1.createDefaultMemoryStore)();
168
+ primaryNoSearch.search = undefined;
169
+ const comp = new composite_store_1.CompositeMemoryStore({ primary: primaryNoSearch });
170
+ await comp.initialize();
171
+ const results = await comp.search('q', { userId: 'user-1' });
172
+ expect(results).toEqual([]);
173
+ });
174
+ });
175
+ describe('getStats', () => {
176
+ it('merges stats from primary and episodic', async () => {
177
+ await composite.save(makeItem({ category: category_types_1.MemoryCategory.PREFERENCE }));
178
+ await composite.save(makeItem({ category: category_types_1.MemoryCategory.EPISODIC }));
179
+ const stats = await composite.getStats('user-1');
180
+ expect(stats.total).toBeGreaterThanOrEqual(2);
181
+ expect(stats.byCategory).toBeDefined();
182
+ });
183
+ it('returns primary stats when no episodic', async () => {
184
+ const primaryOnly = new composite_store_1.CompositeMemoryStore({ primary: (0, in_memory_store_1.createDefaultMemoryStore)() });
185
+ await primaryOnly.initialize();
186
+ const stats = await primaryOnly.getStats('user-1');
187
+ expect(stats).toBeDefined();
188
+ expect(stats.total).toBeDefined();
189
+ });
190
+ });
191
+ describe('prune', () => {
192
+ it('prunes both stores', async () => {
193
+ const removed = await composite.prune();
194
+ expect(typeof removed).toBe('number');
195
+ });
196
+ });
197
+ });
198
+ describe('CompositeMemoryStore without episodic', () => {
199
+ it('routes all to primary', async () => {
200
+ const primary = (0, in_memory_store_1.createDefaultMemoryStore)();
201
+ const composite = new composite_store_1.CompositeMemoryStore({ primary });
202
+ await composite.initialize();
203
+ const item = makeItem({ category: category_types_1.MemoryCategory.EPISODIC });
204
+ const id = await composite.save(item);
205
+ expect(id).toBeDefined();
206
+ const got = await composite.get(id);
207
+ expect(got).not.toBeNull();
208
+ });
209
+ it('get returns null when not in primary and no episodic', async () => {
210
+ const primary = (0, in_memory_store_1.createDefaultMemoryStore)();
211
+ const composite = new composite_store_1.CompositeMemoryStore({ primary });
212
+ await composite.initialize();
213
+ expect(await composite.get('nonexistent')).toBeNull();
214
+ });
215
+ });
216
+ //# sourceMappingURL=composite.store.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"composite.store.test.js","sourceRoot":"","sources":["../../src/__tests__/composite.store.test.ts"],"names":[],"mappings":";;AAAA,8DAAgE;AAChE,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AAM,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACpC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;IAC7B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sDAAsD,EAAE,KAAK,IAAI,EAAE;QACpE,MAAM,OAAO,GAAG,IAAA,0CAAwB,GAAE,CAAC;QAC3C,MAAM,SAAS,GAAG,IAAI,sCAAoB,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;QACxD,MAAM,SAAS,CAAC,UAAU,EAAE,CAAC;QAC7B,MAAM,CAAC,MAAM,SAAS,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IACxD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=create-memory-store.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-memory-store.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/create-memory-store.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const create_memory_store_1 = require("../store/create-memory-store");
4
+ const in_memory_store_1 = require("../store/in-memory.store");
5
+ const category_types_1 = require("../types/category.types");
6
+ function makeItem(overrides = {}) {
7
+ return {
8
+ id: 'id-' + Math.random().toString(36).slice(2),
9
+ userId: 'user-1',
10
+ category: category_types_1.MemoryCategory.PREFERENCE,
11
+ key: 'key-' + Math.random().toString(36).slice(2),
12
+ value: 'value',
13
+ confidence: 0.9,
14
+ source: 'explicit',
15
+ evidence: [],
16
+ createdAt: new Date(),
17
+ updatedAt: new Date(),
18
+ accessCount: 0,
19
+ ...overrides,
20
+ };
21
+ }
22
+ describe('createMemoryStore', () => {
23
+ it('returns in-memory store when no config', () => {
24
+ const store = (0, create_memory_store_1.createMemoryStore)();
25
+ expect(store).toBeDefined();
26
+ expect(store.initialize).toBeDefined();
27
+ expect(store.save).toBeDefined();
28
+ });
29
+ it('returns in-memory store when type is in-memory', () => {
30
+ const store = (0, create_memory_store_1.createMemoryStore)({ type: 'in-memory' });
31
+ expect(store).toBeDefined();
32
+ });
33
+ it('returns in-memory store with options when type is in-memory and options provided', async () => {
34
+ const store = (0, create_memory_store_1.createMemoryStore)({
35
+ type: 'in-memory',
36
+ options: { maxTotalItems: 50 },
37
+ });
38
+ await store.initialize();
39
+ const id = await store.save(makeItem());
40
+ expect(id).toBeDefined();
41
+ });
42
+ it('returns composite store when type is composite', async () => {
43
+ const primary = (0, in_memory_store_1.createDefaultMemoryStore)();
44
+ const store = (0, create_memory_store_1.createMemoryStore)({
45
+ type: 'composite',
46
+ options: { primary },
47
+ });
48
+ expect(store).toBeDefined();
49
+ await store.initialize();
50
+ const id = await store.save(makeItem());
51
+ expect(id).toBeDefined();
52
+ });
53
+ it('throws or returns postgres store when type is postgres (requires pool)', () => {
54
+ expect(() => (0, create_memory_store_1.createMemoryStore)({
55
+ type: 'postgres',
56
+ options: {
57
+ pool: {
58
+ query: async () => ({ rows: [], rowCount: 0 }),
59
+ },
60
+ },
61
+ })).not.toThrow();
62
+ });
63
+ it('throws or returns redis store when type is redis (requires client)', () => {
64
+ const mockClient = {
65
+ get: async () => null,
66
+ set: async () => undefined,
67
+ del: async () => 0,
68
+ sadd: async () => 0,
69
+ smembers: async () => [],
70
+ srem: async () => 0,
71
+ mget: async () => [],
72
+ keys: async () => [],
73
+ };
74
+ expect(() => (0, create_memory_store_1.createMemoryStore)({
75
+ type: 'redis',
76
+ options: { client: mockClient },
77
+ })).not.toThrow();
78
+ });
79
+ it('returns default store when config type is unknown (fallback)', () => {
80
+ const store = (0, create_memory_store_1.createMemoryStore)({ type: 'unknown', options: undefined });
81
+ expect(store).toBeDefined();
82
+ expect(store.initialize).toBeDefined();
83
+ });
84
+ });
85
+ //# sourceMappingURL=create-memory-store.test.js.map
@@ -0,0 +1 @@
1
+ {"version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