@functional-systems/memdrive 0.1.1-dev.2 → 0.1.1-dev.4

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 (189) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +20 -279
  3. package/dist/commonjs/chunking.d.ts +1 -2
  4. package/dist/commonjs/chunking.d.ts.map +1 -1
  5. package/dist/commonjs/chunking.js +2 -5
  6. package/dist/commonjs/chunking.js.map +1 -1
  7. package/dist/commonjs/config.d.ts +17 -0
  8. package/dist/commonjs/config.d.ts.map +1 -0
  9. package/dist/commonjs/config.js +116 -0
  10. package/dist/commonjs/config.js.map +1 -0
  11. package/dist/commonjs/errors.d.ts +10 -6
  12. package/dist/commonjs/errors.d.ts.map +1 -1
  13. package/dist/commonjs/errors.js +25 -5
  14. package/dist/commonjs/errors.js.map +1 -1
  15. package/dist/commonjs/index.d.ts +15 -5
  16. package/dist/commonjs/index.d.ts.map +1 -1
  17. package/dist/commonjs/index.js +332 -280
  18. package/dist/commonjs/index.js.map +1 -1
  19. package/dist/commonjs/records.d.ts +44 -0
  20. package/dist/commonjs/records.d.ts.map +1 -0
  21. package/dist/commonjs/records.js +88 -0
  22. package/dist/commonjs/records.js.map +1 -0
  23. package/dist/commonjs/search.d.ts +8 -0
  24. package/dist/commonjs/search.d.ts.map +1 -0
  25. package/dist/commonjs/search.js +56 -0
  26. package/dist/commonjs/search.js.map +1 -0
  27. package/dist/commonjs/types.d.ts +84 -252
  28. package/dist/commonjs/types.d.ts.map +1 -1
  29. package/dist/esm/chunking.d.ts +1 -2
  30. package/dist/esm/chunking.d.ts.map +1 -1
  31. package/dist/esm/chunking.js +2 -4
  32. package/dist/esm/chunking.js.map +1 -1
  33. package/dist/esm/config.d.ts +17 -0
  34. package/dist/esm/config.d.ts.map +1 -0
  35. package/dist/esm/config.js +107 -0
  36. package/dist/esm/config.js.map +1 -0
  37. package/dist/esm/errors.d.ts +10 -6
  38. package/dist/esm/errors.d.ts.map +1 -1
  39. package/dist/esm/errors.js +22 -4
  40. package/dist/esm/errors.js.map +1 -1
  41. package/dist/esm/index.d.ts +15 -5
  42. package/dist/esm/index.d.ts.map +1 -1
  43. package/dist/esm/index.js +332 -278
  44. package/dist/esm/index.js.map +1 -1
  45. package/dist/esm/records.d.ts +44 -0
  46. package/dist/esm/records.d.ts.map +1 -0
  47. package/dist/esm/records.js +77 -0
  48. package/dist/esm/records.js.map +1 -0
  49. package/dist/esm/search.d.ts +8 -0
  50. package/dist/esm/search.d.ts.map +1 -0
  51. package/dist/esm/search.js +52 -0
  52. package/dist/esm/search.js.map +1 -0
  53. package/dist/esm/types.d.ts +84 -252
  54. package/dist/esm/types.d.ts.map +1 -1
  55. package/package.json +7 -42
  56. package/src/chunking.ts +2 -3
  57. package/src/config.ts +121 -0
  58. package/src/errors.ts +20 -6
  59. package/src/index.ts +352 -260
  60. package/src/records.ts +83 -0
  61. package/src/search.ts +57 -0
  62. package/src/types.ts +74 -253
  63. package/dist/commonjs/filter.d.ts +0 -30
  64. package/dist/commonjs/filter.d.ts.map +0 -1
  65. package/dist/commonjs/filter.js +0 -224
  66. package/dist/commonjs/filter.js.map +0 -1
  67. package/dist/commonjs/recall-input.d.ts +0 -8
  68. package/dist/commonjs/recall-input.d.ts.map +0 -1
  69. package/dist/commonjs/recall-input.js +0 -45
  70. package/dist/commonjs/recall-input.js.map +0 -1
  71. package/dist/commonjs/retriever/index.d.ts +0 -7
  72. package/dist/commonjs/retriever/index.d.ts.map +0 -1
  73. package/dist/commonjs/retriever/index.js +0 -167
  74. package/dist/commonjs/retriever/index.js.map +0 -1
  75. package/dist/commonjs/retriever/scope.d.ts +0 -5
  76. package/dist/commonjs/retriever/scope.d.ts.map +0 -1
  77. package/dist/commonjs/retriever/scope.js +0 -69
  78. package/dist/commonjs/retriever/scope.js.map +0 -1
  79. package/dist/commonjs/retriever/types.d.ts +0 -89
  80. package/dist/commonjs/retriever/types.d.ts.map +0 -1
  81. package/dist/commonjs/retriever/types.js +0 -3
  82. package/dist/commonjs/retriever/types.js.map +0 -1
  83. package/dist/commonjs/storage.d.ts +0 -274
  84. package/dist/commonjs/storage.d.ts.map +0 -1
  85. package/dist/commonjs/storage.js +0 -861
  86. package/dist/commonjs/storage.js.map +0 -1
  87. package/dist/commonjs/tools/definitions.d.ts +0 -5
  88. package/dist/commonjs/tools/definitions.d.ts.map +0 -1
  89. package/dist/commonjs/tools/definitions.js +0 -147
  90. package/dist/commonjs/tools/definitions.js.map +0 -1
  91. package/dist/commonjs/tools/evidence-ids.d.ts +0 -7
  92. package/dist/commonjs/tools/evidence-ids.d.ts.map +0 -1
  93. package/dist/commonjs/tools/evidence-ids.js +0 -71
  94. package/dist/commonjs/tools/evidence-ids.js.map +0 -1
  95. package/dist/commonjs/tools/factory.d.ts +0 -7
  96. package/dist/commonjs/tools/factory.d.ts.map +0 -1
  97. package/dist/commonjs/tools/factory.js +0 -169
  98. package/dist/commonjs/tools/factory.js.map +0 -1
  99. package/dist/commonjs/tools/index.d.ts +0 -6
  100. package/dist/commonjs/tools/index.d.ts.map +0 -1
  101. package/dist/commonjs/tools/index.js +0 -25
  102. package/dist/commonjs/tools/index.js.map +0 -1
  103. package/dist/commonjs/tools/internal-types.d.ts +0 -18
  104. package/dist/commonjs/tools/internal-types.d.ts.map +0 -1
  105. package/dist/commonjs/tools/internal-types.js +0 -3
  106. package/dist/commonjs/tools/internal-types.js.map +0 -1
  107. package/dist/commonjs/tools/short-ids.d.ts +0 -8
  108. package/dist/commonjs/tools/short-ids.d.ts.map +0 -1
  109. package/dist/commonjs/tools/short-ids.js +0 -81
  110. package/dist/commonjs/tools/short-ids.js.map +0 -1
  111. package/dist/commonjs/tools/types.d.ts +0 -53
  112. package/dist/commonjs/tools/types.d.ts.map +0 -1
  113. package/dist/commonjs/tools/types.js +0 -3
  114. package/dist/commonjs/tools/types.js.map +0 -1
  115. package/dist/commonjs/values.d.ts +0 -17
  116. package/dist/commonjs/values.d.ts.map +0 -1
  117. package/dist/commonjs/values.js +0 -90
  118. package/dist/commonjs/values.js.map +0 -1
  119. package/dist/esm/filter.d.ts +0 -30
  120. package/dist/esm/filter.d.ts.map +0 -1
  121. package/dist/esm/filter.js +0 -209
  122. package/dist/esm/filter.js.map +0 -1
  123. package/dist/esm/recall-input.d.ts +0 -8
  124. package/dist/esm/recall-input.d.ts.map +0 -1
  125. package/dist/esm/recall-input.js +0 -40
  126. package/dist/esm/recall-input.js.map +0 -1
  127. package/dist/esm/retriever/index.d.ts +0 -7
  128. package/dist/esm/retriever/index.d.ts.map +0 -1
  129. package/dist/esm/retriever/index.js +0 -163
  130. package/dist/esm/retriever/index.js.map +0 -1
  131. package/dist/esm/retriever/scope.d.ts +0 -5
  132. package/dist/esm/retriever/scope.d.ts.map +0 -1
  133. package/dist/esm/retriever/scope.js +0 -66
  134. package/dist/esm/retriever/scope.js.map +0 -1
  135. package/dist/esm/retriever/types.d.ts +0 -89
  136. package/dist/esm/retriever/types.d.ts.map +0 -1
  137. package/dist/esm/retriever/types.js +0 -2
  138. package/dist/esm/retriever/types.js.map +0 -1
  139. package/dist/esm/storage.d.ts +0 -274
  140. package/dist/esm/storage.d.ts.map +0 -1
  141. package/dist/esm/storage.js +0 -845
  142. package/dist/esm/storage.js.map +0 -1
  143. package/dist/esm/tools/definitions.d.ts +0 -5
  144. package/dist/esm/tools/definitions.d.ts.map +0 -1
  145. package/dist/esm/tools/definitions.js +0 -144
  146. package/dist/esm/tools/definitions.js.map +0 -1
  147. package/dist/esm/tools/evidence-ids.d.ts +0 -7
  148. package/dist/esm/tools/evidence-ids.d.ts.map +0 -1
  149. package/dist/esm/tools/evidence-ids.js +0 -68
  150. package/dist/esm/tools/evidence-ids.js.map +0 -1
  151. package/dist/esm/tools/factory.d.ts +0 -7
  152. package/dist/esm/tools/factory.d.ts.map +0 -1
  153. package/dist/esm/tools/factory.js +0 -166
  154. package/dist/esm/tools/factory.js.map +0 -1
  155. package/dist/esm/tools/index.d.ts +0 -6
  156. package/dist/esm/tools/index.d.ts.map +0 -1
  157. package/dist/esm/tools/index.js +0 -22
  158. package/dist/esm/tools/index.js.map +0 -1
  159. package/dist/esm/tools/internal-types.d.ts +0 -18
  160. package/dist/esm/tools/internal-types.d.ts.map +0 -1
  161. package/dist/esm/tools/internal-types.js +0 -2
  162. package/dist/esm/tools/internal-types.js.map +0 -1
  163. package/dist/esm/tools/short-ids.d.ts +0 -8
  164. package/dist/esm/tools/short-ids.d.ts.map +0 -1
  165. package/dist/esm/tools/short-ids.js +0 -78
  166. package/dist/esm/tools/short-ids.js.map +0 -1
  167. package/dist/esm/tools/types.d.ts +0 -53
  168. package/dist/esm/tools/types.d.ts.map +0 -1
  169. package/dist/esm/tools/types.js +0 -2
  170. package/dist/esm/tools/types.js.map +0 -1
  171. package/dist/esm/values.d.ts +0 -17
  172. package/dist/esm/values.d.ts.map +0 -1
  173. package/dist/esm/values.js +0 -87
  174. package/dist/esm/values.js.map +0 -1
  175. package/docs/tools.md +0 -264
  176. package/src/filter.ts +0 -189
  177. package/src/recall-input.ts +0 -46
  178. package/src/retriever/index.ts +0 -142
  179. package/src/retriever/scope.ts +0 -56
  180. package/src/retriever/types.ts +0 -68
  181. package/src/storage.ts +0 -765
  182. package/src/tools/definitions.ts +0 -175
  183. package/src/tools/evidence-ids.ts +0 -57
  184. package/src/tools/factory.ts +0 -153
  185. package/src/tools/index.ts +0 -25
  186. package/src/tools/internal-types.ts +0 -12
  187. package/src/tools/short-ids.ts +0 -58
  188. package/src/tools/types.ts +0 -48
  189. package/src/values.ts +0 -103
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ - Replace the memory SDK entry points with a file SDK for fresh stores, read-only main, and working forks.
6
+ - Create files in batches and read exact originals by path or stable file ID. Search indexed chunks with hybrid retrieval, optional reranking and verified source ranges.
7
+ - Run LongMemEval against the public file SDK. The file-based corpus and run formats bind each evidence span to its original file and keep prior benchmark results on their original protocol.
8
+
3
9
  ## 0.1.0
4
10
 
5
11
  First stable release of the standalone MemDrive SDK. The public API and storage
package/README.md CHANGED
@@ -1,293 +1,34 @@
1
1
  # MemDrive
2
2
 
3
- TypeScript memory SDK backed by LambdaDB. Store original memories, retrieve
4
- relevant evidence, inspect metadata distributions, and read complete originals.
5
- Base recall is a single data operation. Optional SDK orchestration can plan searches
6
- and select evidence using an injected model adapter. Applications own answer
7
- generation and presentation. The SDK accepts an initialized
8
- LambdaDB client; the caller owns connection credentials and transport.
3
+ TypeScript file SDK backed by LambdaDB. MemDrive accepts an initialized LambdaDB client. The application owns connection credentials and transport.
9
4
 
10
- The package is `@functional-systems/memdrive`, licensed under Apache-2.0.
11
- It builds ESM and CommonJS with TypeScript declarations and supports Node.js
12
- 20.12+ and browser bundlers.
5
+ The package is `@functional-systems/memdrive`, licensed under Apache-2.0. It supports ESM, CommonJS, TypeScript, Node.js 20.12+, and browser bundlers.
13
6
 
14
- ## Quick start
7
+ ## File stores
15
8
 
16
- ### 1. Set up LambdaDB
17
-
18
- 1. [Create a LambdaDB account](https://app.lambdadb.ai/auth/signup), or sign in
19
- to [LambdaDB Cloud](https://app.lambdadb.ai) if you already have one.
20
- 2. Create a project and choose an AWS region for your data.
21
- 3. Open the project's **API Keys** tab, select **Create key** (or
22
- **Create your first key**), enter a name, and create the key. Creating a
23
- project does not automatically issue an API key.
24
- 4. Save the key securely when it appears; the full value is shown only once.
25
- Copy the project's region-specific **base URL** and **project name** from
26
- the console as well.
27
-
28
- In the example below, use the base URL as `baseUrl`, the project name as
29
- `projectName`, and the API key as `projectApiKey`. Keep the API key out of source
30
- control and load it from your application's secret configuration. See the
31
- [LambdaDB setup guide](https://docs.lambdadb.ai/guides/get-started/quickstart)
32
- for account setup and API key management details.
33
-
34
- ### 2. Install the packages
35
-
36
- Install this stable release and the LambdaDB client used to initialize it:
37
-
38
- ```sh
39
- npm install @functional-systems/memdrive@0.1.0 @functional-systems/lambdadb@0.12.0
40
- ```
41
-
42
- An unqualified install follows the stable `latest` channel. Use `@rc` to follow
43
- release candidates, `@dev` for development builds, or an exact version for
44
- reproducibility.
45
-
46
- ### 3. Store and recall a memory
47
-
48
- Replace the connection placeholders below with your project's values.
49
- The `create` call sets up the MemDrive collection; no manual collection setup
50
- is needed in the console.
9
+ Use `@functional-systems/memdrive` to create a text file store and save exact originals on a working fork. These stores use a dedicated layout and require a fresh collection name.
51
10
 
52
11
  ```ts
53
- import { LambdaDBClient } from '@functional-systems/lambdadb';
54
- import { create } from '@functional-systems/memdrive';
55
-
56
- const client = new LambdaDBClient({
57
- baseUrl: 'https://your-lambdadb-endpoint',
58
- projectName: 'your-project',
59
- projectApiKey: 'your-project-api-key',
12
+ import { MemDrive } from '@functional-systems/memdrive';
13
+
14
+ const main = await MemDrive.create({ client, name: 'workspace' });
15
+ const work = await main.fork({ name: 'research' });
16
+ const file = await work.write({
17
+ op: 'create',
18
+ path: '/notes/context.md',
19
+ content: '# Task context\r\n',
60
20
  });
61
21
 
62
- const drive = await create({
63
- client, name: 'story_memory',
64
- description: 'Conversation memories for the example application',
65
- metadataSchema: {
66
- role: { type: 'string', description: 'Message author role: user or assistant' },
67
- tags: { type: 'string[]', description: 'Application-defined topics' },
68
- },
69
- textSearch: { analyzers: ['english'] },
70
- labels: { application: 'example', owner: 'account123' },
71
- });
72
- await drive.remember({ mems: [
73
- { id: 'message-1', content: 'The meeting is on Friday.',
74
- timestamp: '2026-11-13T12:00:00Z', metadata: { role: 'user' } },
75
- ] });
76
- const { matches, usage } = await drive.recall({ query: 'When is the meeting?' });
77
- const { mems } = await drive.read({ ids: [...new Set(matches.map(match => match.memId))] });
78
- ```
79
-
80
- ## Public operations
81
-
82
- | Operation | Contract |
83
- | --- | --- |
84
- | `create(options, {signal}?)` | Creates one collection and opens a handle. Existing names fail. |
85
- | `open({client, name, branch?, ...}, {signal}?)` | Validates an existing MemDrive; embedding and analyzers come from storage. |
86
- | `list({client, labels?, limit?, cursor?}, {signal}?)` | Returns `{drives, nextCursor?}` for one native collection page. Default limit 10, maximum 100. |
87
- | `drive.describe({signal}?)` | Fresh `{name, description?, labels, metadataSchema, embedding, textSearch?}`. |
88
- | `drive.remember({mems}, {signal}?)` | Appends generated IDs or fully replaces supplied IDs. Returns `{ids}` in input order. |
89
- | `drive.recall(request, {signal}?)` | Returns `{matches, usage}`; no final answer is generated. Default limit 10. |
90
- | `drive.recall({requests}, {signal}?)` | Returns `{results}` in input order, including individual error/usage entries. |
91
- | `drive.countValues({fields, filter?, excludeIds?, limit?}, {signal}?)` | Returns keyword value buckets and counts over original memories, with `asOf` and per-field `hasMore`. Default limit 10, maximum 100. |
92
- | `drive.read({ids}, {signal}?)` | Returns full original `{mems}`; absent IDs are omitted. |
93
- | `drive.list({limit?, cursor?}, {signal}?)` | Returns original `{mems, nextCursor?}` from one committed physical document page. Default limit 100, maximum 1000. |
94
- | `drive.forget({ids} or {filter}, {signal}?)` | Removes whole Mems and their chunks. Missing IDs are harmless. |
95
- | `drive.configure({metadataSchema?, description?}, {signal}?)` | Updates the drive description and/or metadata declaration. A supplied schema must retain all existing fields and their types; additions and field-description changes are allowed. |
96
- | `drive.at({branch})` | Returns a branch-bound data handle with the same data APIs. |
97
- | `drive.branches.create({name, source:{branch}}, {signal}?)` | Creates a branch. Latest accepted-write inclusion depends on the LambdaDB server contract. |
98
- | `drive.branches.list({signal}?)`, `.delete(name, {signal}?)` | Lists/deletes branches. The main branch cannot be deleted. |
99
- | `drive.destroy({signal}?)` | Deletes the collection, including its branches. |
100
-
101
- Both list APIs may return an empty logical page with `nextCursor`; keep paging
102
- until the cursor is absent. Document listing is committed-state inventory.
103
- `read` and `recall` request consistent reads. A write-dependent read starts after
104
- the caller receives a successful write response. Concurrent writes to the same
105
- Mem have no ordering guarantee.
106
-
107
- `metadataSchema` is required at creation; use `{}` when no custom fields are needed.
108
- Metadata types are `string`, `string[]`, `number`, `boolean`, and `datetime`.
109
- Drive and metadata-field descriptions are optional strings, up to 255 UTF-16 code units,
110
- stored in native collection/index descriptions. `configure` preserves omitted
111
- descriptions; an empty string clears one. Descriptions are returned by `describe`
112
- and the drive catalog. `describe()` is the schema inspection API; there is no
113
- separate agent-specific schema response.
114
- Only declared metadata is accepted. Filters use explicit `and`/`or` arrays and
115
- leaves such as `{field:'metadata.role', op:'eq', value:'user'}`. Supported leaf
116
- operators are `eq`, `neq`, `in`, `exists`, `gt`, `gte`, `lt`, `lte`; ranges apply
117
- to numbers and datetimes. `id` and `timestamp` are also filterable.
118
-
119
- Labels are native collection tags, with a total native limit of five. `memory.*`
120
- is reserved: two internal tags leave three caller labels for managed stores;
121
- three internal tags leave two for external-vector stores. Over-limit input fails
122
- before a request is sent. Descriptions do not consume tag slots. Labels aid discovery,
123
- not authorization. The caller verifies its expected ownership before mutations.
124
- Incompatible stores are rejected by `open` and skipped by the catalog. There is
125
- no automatic migration or legacy-store deletion. Snapshot retention is not a
126
- MemDrive option: new collections omit the setting and use LambdaDB's default of
127
- 30 days. Opening an existing drive does not change its native retention setting.
128
-
129
- ## Storage and retrieval
130
-
131
- Managed stores use native `text-embedding-3-small` embeddings. At creation,
132
- omitting `embedding` and passing `embedding: { mode: 'managed' }` are equivalent.
133
- The managed model settings are fixed; `open` recovers them from storage. Supplying
134
- `textSearch.analyzers` enables hybrid retrieval; omission uses vector retrieval.
135
- Managed text retrieval uses native Jev reranking by default in both cases.
136
- `recall` accepts an optional boolean `rerank`, including on each item of a batch:
137
-
138
- | Embedding configuration | Omitted | `false` | `true` |
139
- | --- | --- | --- | --- |
140
- | Managed | Enabled | Disabled | Enabled |
141
- | External | Disabled | Disabled | Rejected |
142
-
143
- ```js
144
- await drive.recall({ query: 'When is the meeting?', rerank: false });
22
+ const reopened = await MemDrive.open({ client, name: 'workspace', at: { fork: 'research' } });
23
+ const saved = await reopened.read({ fileId: file.fileId });
24
+ const { hits, reranked } = await reopened.search({ query: 'Task context', limit: 5 });
25
+ // The same file is available through { path: '/notes/context.md' }.
145
26
  ```
146
27
 
147
- This is a per-request execution option, not a stored setting or a
148
- `create`/`open`/`configure` option. Disabling reranking preserves the existing
149
- KNN `k`, filters and result limit; results retain search order.
150
- Unsupported combinations fail before database requests.
151
-
152
- Each `recall` performs one native search request. There is no retrieval `mode`,
153
- internal model adapter, prompt, evidence-selection step or model loop. A caller
154
- can issue multiple queries in a batch, inspect the returned matches, call `read`
155
- for complete originals and search again. Optional text `context` and
156
- `recentDialogue` still become part of the embedding/rerank query without an internal agent
157
- call. The caller owns their relevance and size; the native 8 KiB query bound is
158
- validated without silent truncation. `usage` reports `elapsedMs` and
159
- `databaseRequests`; MemDrive does not report caller model token usage.
160
-
161
- Optional `observe` and `record` callbacks expose retrieval diagnostics.
162
- `observe` emits one `retrieved` event for each successful recall; there is no
163
- selection event. Use `observe.matches[].memId` for canonical caller IDs;
164
- `observe.ids` contains internal physical evidence IDs. `record` emits `query`
165
- and `query_result` events, including bodies and memory text. Batch callbacks
166
- include `requestIndex`. Callers control whether and where to retain these events.
167
-
168
- Managed text uses the current 800-code-point splitter, Unicode-aware with UTF-16
169
- source offsets and no overlap. Short full Mems store `content` once. Long Mems
170
- store their original in unindexed `memContent` and searchable `content` chunks.
171
- An overwrite replaces obsolete chunk slots with bodyless documents. Public
172
- matches identify `kind: 'mem'` or `'chunk'`, `memId`, and the returned text span.
173
-
174
- For caller-provided embeddings, create with:
175
-
176
- ```js
177
- embedding: { mode: 'external', dimensions: 768,
178
- similarity: 'cosine', identity: 'caller-model-v1' }
179
- ```
180
-
181
- Remember `{id?, embedding, timestamp?, metadata?}` and recall with
182
- `{queryVector, filter?, excludeIds?, limit?}`. Text, chunking, keyword search,
183
- and reranking are unavailable for external embeddings. Read/list/matches
184
- return references and metadata without vectors or source text. The caller owns
185
- embedding identity compatibility and reconstruction of the local original.
186
-
187
- Remember packs complete Mem replacements into native requests up to 6,029,312
188
- JSON bytes. One Mem is never split across write requests. The per-document bound
189
- is 5 MiB. All replacements are validated before writes; subsequent requests are
190
- sequential. Failure details distinguish `completedIds`, `uncertainIds`, and
191
- `notAttemptedIds`. A multi-request remember is not atomic; do not blindly retry
192
- the entire operation. The SDK does not serialize different writes or retry them.
193
-
194
- Cancellation is a separate options argument and never enters stored JSON.
195
- It removes queued requests and propagates to native requests. Cancellation does
196
- not undo accepted writes.
197
- Recalls share a default concurrency bound of five across branch views; the
198
- caller may configure it. Batch request count is not artificially capped by the
199
- SDK; a hosted MCP wrapper can impose its own exposed tool limit.
200
-
201
- The storage format is `mems-v0`. MemDrive uses LambdaDB SDK 0.12.0. Build
202
- artifacts are generated with `npm run build`; browser applications bundle the
203
- public package entry point with their own build tools.
204
-
205
- ## Metadata distributions
206
-
207
- Use `describe()` for field declarations and `countValues()` for stored values:
208
-
209
- ```ts
210
- const { metadataSchema } = await drive.describe();
211
- const distribution = await drive.countValues({
212
- fields: ['metadata.role', 'metadata.tags'],
213
- filter: { field: 'timestamp', op: 'gte', value: '2026-01-01T00:00:00Z' },
214
- excludeIds: ['message-to-exclude'],
215
- limit: 10,
216
- });
217
- // distribution.values['metadata.role']:
218
- // { buckets: [{ value: 'user', count: 12 }], hasMore: false }
219
- // distribution.asOf: ISO 8601 UTC fetch time
220
- ```
221
-
222
- Countable fields are `id` and declared `string`/`string[]` metadata fields.
223
- Each request accepts one to five distinct fields, matching the native facet limit. Numeric, boolean and datetime fields can
224
- filter the population but cannot be aggregated. Counts include each original
225
- Mem once, regardless of its chunk count; obsolete chunk slots do not contribute.
226
- An array may place a Mem in multiple buckets, so bucket sums are not the number
227
- of memories. The active branch, filter and excluded IDs determine the population.
228
-
229
- Value results are cached for 60 seconds per data handle; schema validation is
230
- cached for five minutes internally. `describe()` itself remains a fresh lookup.
231
- SDK mutations invalidate local counts across views of the same drive. Writes
232
- through another independent handle or client may remain invisible in cached
233
- counts until expiration. `asOf` is the result fetch time, not a database snapshot
234
- identifier. `hasMore` is `true` when another bucket is observed, `false` when the
235
- response is complete, and `null` when the native 100-bucket bound leaves
236
- completeness unknown.
237
-
238
- A hosted MCP service can expose these SDK operations and supply tool descriptions
239
- and protocol handling. A service can use basic tools or the optional retriever
240
- for orchestration. MemDrive bundles no provider client, MCP server or finish/report tool.
241
-
242
- ## Agent tools
243
-
244
- Import `createTools` from `@functional-systems/memdrive/tools` to expose portable
245
- memory operations to a calling agent. The common layer provides JSON Schema input
246
- and output definitions, descriptions, effect annotations and SDK execution. It
247
- defaults to primitive SDK operations. Optional retrieval configuration delegates
248
- planning and evidence selection to the SDK retriever; no model client or MCP
249
- server is bundled. See [the tool contract](docs/tools.md)
250
- for the catalog, branch binding, write opt-in, error outcomes and direct/MCP mapping.
251
-
252
- ## Optional retrieval orchestration
253
-
254
- ```ts
255
- import { createRetriever } from '@functional-systems/memdrive/retriever';
256
-
257
- const retriever = await createRetriever({ drive }); // single_pass by default
258
- const result = await retriever.recall({ query: 'What did we agree?', limit: 10 });
259
-
260
- // Agentic retrieval requires a host-owned, provider-neutral model adapter.
261
- const agentic = await createRetriever({ drive, strategy: 'agentic',
262
- agent: { model, countTokens } });
263
- const evidence = await agentic.recall({ query: 'What changed?', limit: 10 }, { signal });
264
- if (evidence.completion.status === 'completed') useEvidence(evidence.matches);
265
- ```
266
-
267
- The optional loop returns canonical source evidence, never a final answer.
268
- Configure `createTools({ drive, retrieval: { strategy: 'agentic', agent: { model, countTokens } } })`
269
- to use it behind the existing `memdrive_recall` tool. The full tool inventory and
270
- `{requests: [...]}` batch input stay unchanged. See [the adapter and budget contract](docs/tools.md#optional-retriever)
271
- for model state, scope, cancellation and incomplete outcomes.
272
-
273
- ## Consumers
274
-
275
- The [LongMemEval benchmark](benchmark/longmemeval/README.md) lives in this repository
276
- and compares `single_pass` search with `agentic` use of the public memory tools.
277
- It reuses ingested per-question collections across independent retrieval runs;
278
- answer generation, judging and explicit corpus cleanup are separate stages.
279
- It owns dataset preparation, provider adapters, answer generation and judging;
280
- these remain outside the SDK runtime and npm archive. It can compare its external
281
- collector with the same public SDK retriever. Future suites, including BEAM,
282
- can live alongside it under `benchmark/`.
28
+ `read` returns the original file or `null` when absent. Content can be empty and the SDK preserves whitespace and line endings. Paths are case-sensitive, absolute and slash-separated. Pass an array of up to 100 operations to create files in batches. Pass up to 100 distinct paths in `read({ paths })` to read existing files in request order. An existing path in the same fork rejects creation with `PATH_EXISTS`. Main is read-only and supplies the starting view for creating a fork. Working edits are scoped to that fork. A store can declare scalar metadata fields with `metadataSchema` and carry collection labels. File writes attach optional `metadata` and record the modification time.
283
29
 
284
- SillyMemory and earlier BEAM/LongMemEval prototypes are separate consumers. Their
285
- historical results do not establish the standalone package's answer quality.
286
- Applications own recent-context partitioning, model transport and final prompt assembly.
287
- SDK unit and package checks do not establish benchmark quality or live compatibility.
30
+ Search ranks file chunks with Bayesian lexical and vector retrieval. The store defaults to LambdaDB's `standard` analyzer and OpenAI's managed `text-embedding-3-small` embeddings. Set `textSearch.analyzers` when creating a store to select other supported analyzers. Text is currently split at paragraph, sentence or whitespace boundaries using an 800-code-point cap. Each hit carries the stable file ID, path, metadata and a chunk preview. When the chunk's location is verified against the exact original, the hit also includes a UTF-16 `range` that can be passed to JavaScript's `slice`.
288
31
 
289
- ## Development
32
+ Search enables native reranking by default. Use `rerank: false` for fused order or `rerank: { onFailure: 'returnOriginal' }` to allow native provider fallback. The result's `reranked` flag reports whether reranking was applied. An optional `embeddingQuery` supplies separate semantic context while preserving `query` for lexical matching.
290
33
 
291
- To build locally, run `npm ci`, `npm run build`, and `npm pack`, then install the
292
- resulting tarball in the consumer project. See [CONTRIBUTING.md](CONTRIBUTING.md)
293
- for development and [RELEASING.md](RELEASING.md) for the release policy.
34
+ Use one writer per fork across runtimes and LambdaDB client instances. The SDK serializes writes to a fork within one client instance. It confirms the original and chunks with a consistent branch read before returning success. Batch writes can apply in parts. A file whose chunks require multiple requests becomes visible when its original is written after the earlier chunk requests are confirmed. If the request may have been accepted but the SDK cannot confirm it, the error code is `WRITE_UNCONFIRMED`. Its details identify the attempted files and any earlier confirmed files so the caller can inspect the fork. The handle blocks another create at that path until it observes an existing file there. This protection is local to the client instance. A replacement writer must confirm that the earlier request has settled before using that path.
@@ -1,5 +1,4 @@
1
- export declare const CHUNKING_POLICY = "boundary-v1";
2
- export declare function chunkSpans(text: string, limit?: number): Array<{
1
+ export declare function chunkSpans(text: string): Array<{
3
2
  start: number;
4
3
  end: number;
5
4
  text: string;
@@ -1 +1 @@
1
- {"version":3,"file":"chunking.d.ts","sourceRoot":"","sources":["../../src/chunking.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe,gBAAgB,CAAC;AAC7C,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,SAAM,GAAG,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,CAAC,CA4BvG"}
1
+ {"version":3,"file":"chunking.d.ts","sourceRoot":"","sources":["../../src/chunking.ts"],"names":[],"mappings":"AAEA,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,CAAC,CA4B1F"}
@@ -1,13 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CHUNKING_POLICY = void 0;
4
3
  exports.chunkSpans = chunkSpans;
5
4
  // Exact source partitions: UTF-16 offsets for slice(), a Unicode-code-point cap.
6
5
  // English sentence detection is deliberate; other languages are not optimized.
7
- exports.CHUNKING_POLICY = 'boundary-v1';
8
- function chunkSpans(text, limit = 800) {
9
- if (!Number.isInteger(limit) || limit < 1)
10
- throw new RangeError('Chunk limit must be a positive integer.');
6
+ function chunkSpans(text) {
7
+ const limit = 800;
11
8
  const offsets = [0];
12
9
  for (const char of text)
13
10
  offsets.push(offsets.at(-1) + char.length);
@@ -1 +1 @@
1
- {"version":3,"file":"chunking.js","sour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GAAG,CAAC,GAAG,CAAC;QAC9C,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,KAAK,EAAE,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC,KAAK,CAAE,CAAC;QAClF,IAAI,GAAG,GAAG,OAAO,CAAC,IAAI,CAAE,CAAC;QACzB,IAAI,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC5B,kEAAkE;YAClE,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAE,CAAC;YACnE,GAAG,GAAG,YAAY,CAAC,UAAU,EAAE,KAAK,EAAE,GAAG,CAAC,IAAI,YAAY,CAAC,SAAS,EAAE,KAAK,EAAE,GAAG,CAAC;mBAC1E,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,IAAI,GAAG,CAAC;QAClD,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;QACzD,OAAO,OAAO,CAAC,KAAK,CAAE,GAAG,GAAG;YAAE,KAAK,EAAE,CAAC;IAC1C,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { type IndexConfigsUnion } from '@functional-systems/lambdadb/models/indexconfigsunion.js';
2
+ import type { CreateFileStoreOptions, FileStoreDescription, Metadata, MetadataSchema } from './types.js';
3
+ export declare const isObject: (value: unknown) => value is Record<string, unknown>;
4
+ export declare const keysOnly: (value: unknown, keys: string[]) => value is Record<string, unknown>;
5
+ export declare const formatTag = "memdrive.format";
6
+ export declare const format = "files-v0";
7
+ export declare const validDate: (value: unknown) => value is string;
8
+ export declare function metadataValues(value: unknown, schema: MetadataSchema): Metadata | undefined;
9
+ export declare function storeConfiguration(options: CreateFileStoreOptions): {
10
+ indexConfigs: Record<string, IndexConfigsUnion>;
11
+ tags: {
12
+ "memdrive.format": string;
13
+ };
14
+ description: FileStoreDescription;
15
+ };
16
+ export declare function parseStore(collection: unknown, name: string): FileStoreDescription;
17
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,iBAAiB,EAAE,MAAM,0DAA0D,CAAC;AAC5G,OAAO,KAAK,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAGzG,eAAO,MAAM,QAAQ,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CACsB,CAAC;AAChG,eAAO,MAAM,QAAQ,GAAI,OAAO,OAAO,EAAE,MAAM,MAAM,EAAE,KAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CACf,CAAC;AAE3E,eAAO,MAAM,SAAS,oBAAoB,CAAC;AAC3C,eAAO,MAAM,MAAM,aAAa,CAAC;AAcjC,eAAO,MAAM,SAAS,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,MAE8B,CAAC;AA4BnF,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,cAAc,GAAG,QAAQ,GAAG,SAAS,CAY3F;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,sBAAsB;;;;;;EAkBjE;AAED,wBAAgB,UAAU,CAAC,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,oBAAoB,CAgClF"}
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validDate = exports.format = exports.formatTag = exports.keysOnly = exports.isObject = void 0;
4
+ exports.metadataValues = metadataValues;
5
+ exports.storeConfiguration = storeConfiguration;
6
+ exports.parseStore = parseStore;
7
+ const indexconfigsunion_js_1 = require("@functional-systems/lambdadb/models/indexconfigsunion.js");
8
+ const errors_js_1 = require("./errors.js");
9
+ const isObject = (value) => value !== null && typeof value === 'object'
10
+ && !Array.isArray(value) && [Object.prototype, null].includes(Object.getPrototypeOf(value));
11
+ exports.isObject = isObject;
12
+ const keysOnly = (value, keys) => (0, exports.isObject)(value) && Object.keys(value).every(key => keys.includes(key));
13
+ exports.keysOnly = keysOnly;
14
+ exports.formatTag = 'memdrive.format';
15
+ exports.format = 'files-v0';
16
+ const managedEmbedding = { mode: 'managed', provider: 'openai', model: 'text-embedding-3-small',
17
+ dimensions: 1536, similarity: 'cosine' };
18
+ const fileIndexes = {
19
+ kind: { type: 'keyword' },
20
+ path: { type: 'keyword' },
21
+ fileName: { type: 'keyword' },
22
+ ancestorPaths: { type: 'keyword' },
23
+ changed: { type: 'boolean' },
24
+ modifiedAt: { type: 'datetime' },
25
+ };
26
+ const indexTypes = { string: 'keyword', number: 'double', boolean: 'boolean', datetime: 'datetime' };
27
+ const supportedAnalyzers = new Set(Object.values(indexconfigsunion_js_1.Analyzer));
28
+ const validDate = (value) => typeof value === 'string'
29
+ && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(value)
30
+ && !Number.isNaN(Date.parse(value)) && new Date(value).toISOString() === value;
31
+ exports.validDate = validDate;
32
+ function labelEntries(value = {}) {
33
+ // Match the native tag restrictions, including Java's definition of whitespace.
34
+ // eslint-disable-next-line no-control-regex
35
+ const blank = /^[\u0009-\u000d\u001c-\u0020\u1680\u2000-\u2006\u2008-\u200a\u2028\u2029\u205f\u3000]*$/u;
36
+ (0, errors_js_1.requireInput)((0, exports.isObject)(value) && Object.keys(value).length <= 4 && Object.entries(value).every(([key, item]) => /^[A-Za-z0-9_.-]{1,63}$/.test(key) && !key.startsWith('memdrive.') && typeof item === 'string'
37
+ && item.length <= 127 && !/[:#,]/.test(item) && !blank.test(item)), 'Labels must use native-safe names and values. memdrive.* names are reserved.');
38
+ return { ...value };
39
+ }
40
+ function schemaEntries(value = {}) {
41
+ (0, errors_js_1.requireInput)((0, exports.isObject)(value) && Object.entries(value).every(([key, entry]) => /^[A-Za-z_][A-Za-z0-9_]*$/.test(key) && !['id', 'constructor', 'prototype', '__proto__'].includes(key)
42
+ && (0, exports.keysOnly)(entry, ['type', 'description']) && typeof entry.type === 'string' && Object.hasOwn(indexTypes, entry.type)
43
+ && (entry.description === undefined || (typeof entry.description === 'string' && entry.description.length <= 255))), 'Metadata schema requires named scalar types and optional field descriptions.');
44
+ return structuredClone(value);
45
+ }
46
+ function textAnalyzers(value = { analyzers: ['standard'] }) {
47
+ (0, errors_js_1.requireInput)((0, exports.keysOnly)(value, ['analyzers']) && Array.isArray(value.analyzers) && value.analyzers.length > 0
48
+ && new Set(value.analyzers).size === value.analyzers.length && [...value.analyzers].every(item => supportedAnalyzers.has(item)), 'Set a nonempty array of distinct supported text analyzers.');
49
+ return [...value.analyzers];
50
+ }
51
+ function metadataValues(value, schema) {
52
+ if (value === undefined)
53
+ return undefined;
54
+ (0, errors_js_1.requireInput)((0, exports.isObject)(value) && Object.entries(value).every(([key, item]) => {
55
+ if (!Object.hasOwn(schema, key))
56
+ return false;
57
+ switch (schema[key].type) {
58
+ case 'string': return typeof item === 'string' && item.length <= 4096 && !/\p{Surrogate}/u.test(item);
59
+ case 'number': return typeof item === 'number' && Number.isFinite(item);
60
+ case 'boolean': return typeof item === 'boolean';
61
+ case 'datetime': return (0, exports.validDate)(item);
62
+ }
63
+ }), 'Metadata values must match their declared scalar types. Datetimes use ISO UTC with milliseconds.');
64
+ return { ...value };
65
+ }
66
+ function storeConfiguration(options) {
67
+ const name = options.name;
68
+ const metadataSchema = schemaEntries(options.metadataSchema);
69
+ const labels = labelEntries(options.labels);
70
+ const analyzers = textAnalyzers(options.textSearch);
71
+ const indexConfigs = {
72
+ ...fileIndexes,
73
+ body: { type: 'text', analyzers },
74
+ content: { type: 'text', analyzers },
75
+ embedding: { type: 'vector', managedEmbedding: true, embedding: {
76
+ provider: managedEmbedding.provider, model: managedEmbedding.model, dimensions: managedEmbedding.dimensions,
77
+ similarity: managedEmbedding.similarity, sourceField: 'content',
78
+ } },
79
+ };
80
+ if (Object.keys(metadataSchema).length)
81
+ indexConfigs.metadata = { type: 'object', objectIndexConfigs: Object.fromEntries(Object.entries(metadataSchema).map(([key, value]) => [key, { ...value, type: indexTypes[value.type] }])) };
82
+ const description = { name, labels, metadataSchema, textSearch: { analyzers }, embedding: { ...managedEmbedding } };
83
+ return { indexConfigs, tags: { ...labels, [exports.formatTag]: exports.format }, description };
84
+ }
85
+ function parseStore(collection, name) {
86
+ try {
87
+ (0, errors_js_1.requireInput)((0, exports.isObject)(collection) && collection.collectionName === name && collection.defaultBranchName === 'main'
88
+ && (0, exports.isObject)(collection.tags) && collection.tags[exports.formatTag] === exports.format && (0, exports.isObject)(collection.indexConfigs), 'Collection format or main branch is incompatible.');
89
+ const { tags, indexConfigs } = collection;
90
+ const labels = labelEntries(Object.fromEntries(Object.entries(tags).filter(([key]) => key !== exports.formatTag)));
91
+ (0, errors_js_1.requireInput)(Object.entries(fileIndexes).every(([field, config]) => (0, exports.isObject)(indexConfigs[field])
92
+ && indexConfigs[field].type === config.type), 'Required file indexes are missing.');
93
+ const { embedding, content, body, metadata } = indexConfigs;
94
+ (0, errors_js_1.requireInput)((0, exports.isObject)(embedding) && embedding.type === 'vector' && embedding.managedEmbedding !== false && (0, exports.isObject)(embedding.embedding)
95
+ && embedding.embedding.provider === managedEmbedding.provider && embedding.embedding.model === managedEmbedding.model
96
+ && embedding.embedding.dimensions === managedEmbedding.dimensions && embedding.embedding.similarity === managedEmbedding.similarity
97
+ && embedding.embedding.sourceField === 'content', 'Managed chunk embedding index is incompatible.');
98
+ (0, errors_js_1.requireInput)((0, exports.isObject)(content) && content.type === 'text' && (0, exports.isObject)(body) && body.type === 'text', 'Text indexes are missing.');
99
+ const analyzers = textAnalyzers({ analyzers: content.analyzers ?? ['standard'] });
100
+ (0, errors_js_1.requireInput)(JSON.stringify(analyzers) === JSON.stringify(textAnalyzers({ analyzers: body.analyzers ?? ['standard'] })), 'Original and chunk analyzers must match.');
101
+ let metadataSchema = {};
102
+ if (metadata !== undefined) {
103
+ (0, errors_js_1.requireInput)((0, exports.isObject)(metadata) && metadata.type === 'object' && (0, exports.isObject)(metadata.objectIndexConfigs), 'Metadata index is incompatible.');
104
+ metadataSchema = schemaEntries(Object.fromEntries(Object.entries(metadata.objectIndexConfigs).map(([key, value]) => {
105
+ (0, errors_js_1.requireInput)((0, exports.isObject)(value), 'Invalid metadata field index.');
106
+ return [key, { type: Object.entries(indexTypes).find(([, native]) => native === value.type)?.[0],
107
+ ...(value.description === undefined ? {} : { description: value.description }) }];
108
+ })));
109
+ }
110
+ return { name, labels, metadataSchema, textSearch: { analyzers }, embedding: { ...managedEmbedding } };
111
+ }
112
+ catch (cause) {
113
+ throw new errors_js_1.MemDriveError('INCOMPATIBLE_STORE', 'The collection is not a compatible MemDrive file store.', { cause });
114
+ }
115
+ }
116
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":";;;AAsDA,wCAYC;AAED,gDAkBC;AAED,gCAgCC;AAxHD,mGAA4G;AAE5G,2CAA0D;AAEnD,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE,CAAC,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;OAClH,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;AADnF,QAAA,QAAQ,YAC2E;AACz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AC,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC,CAAC;YAC1F,CAAC,CAAC,CAAC,CAAC,CAAC;QACT,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,EAAE,SAAS,EAAE,EAAE,SAAS,EAAE,EAAE,GAAG,gBAAgB,EAAE,EAAE,CAAC;IAC3G,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,MAAM,IAAI,yBAAa,CAAC,oBAAoB,EAAE,yDAAyD,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IACxH,CAAC;AACL,CAAC"}
@@ -1,17 +1,21 @@
1
- import type { RequestOptions, Usage } from './types.js';
1
+ import type { RequestOptions } from './types.js';
2
2
  export declare class MemDriveError extends Error {
3
3
  code: string;
4
- details?: Record<string, unknown> | undefined;
5
- usage?: Usage | undefined;
4
+ readonly details?: Record<string, unknown> | undefined;
6
5
  status?: number | undefined;
7
- constructor(code: string, message: string, { cause, details, usage }?: {
6
+ constructor(code: string, message: string, { cause, details }?: {
8
7
  cause?: unknown;
9
8
  details?: Record<string, unknown> | undefined;
10
- usage?: Usage | undefined;
11
9
  });
12
10
  }
13
11
  export declare function requireInput(condition: unknown, message: string): asserts condition;
14
12
  export declare function operationOptions(options?: RequestOptions): RequestOptions;
15
13
  export declare function checkAbort(signal?: AbortSignal): void;
16
- export declare function abortError(cause: unknown, signal?: AbortSignal): unknown;
14
+ export declare function databaseError(error: unknown, message: string): MemDriveError;
15
+ export declare function nativeRequest<T>(operation: () => Promise<T>, signal?: AbortSignal): Promise<T>;
16
+ export declare const nativeOptions: (signal?: AbortSignal) => {
17
+ signal?: never;
18
+ } | {
19
+ signal: AbortSignal;
20
+ };
17
21
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EA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E,OAAO,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,GAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAA;KAAO;CAMzI;AAED,wBAAgB,YAAY,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAEnF;AAED,wBAAgB,gBAAgB,CAAC,OAAO,GAAE,cAAmB,GAAG,cAAc,CAQ7E;AAED,wBAAgB,UAAU,CAAC,MAAM,CAAC,EAAE,WAAW,QAE9C;AASD,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,aAAa,CAO5E;AAED,wBAAsB,aAAa,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAIpG;AACD,eAAO,MAAM,aAAa,GAAI,SAAS,WAAW;;;;CAA2C,CAAC"}
@@ -1,19 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MemDriveError = void 0;
3
+ exports.nativeOptions = exports.MemDriveError = void 0;
4
4
  exports.requireInput = requireInput;
5
5
  exports.operationOptions = operationOptions;
6
6
  exports.checkAbort = checkAbort;
7
- exports.abortError = abortError;
7
+ exports.databaseError = databaseError;
8
+ exports.nativeRequest = nativeRequest;
8
9
  class MemDriveError extends Error {
9
- constructor(code, message, { cause, details, usage } = {}) {
10
+ constructor(code, message, { cause, details } = {}) {
10
11
  super(message, cause === undefined ? undefined : { cause });
11
12
  this.name = 'MemDriveError';
12
13
  this.code = code;
13
14
  if (details !== undefined)
14
15
  this.details = details;
15
- if (usage !== undefined)
16
- this.usage = usage;
17
16
  }
18
17
  }
19
18
  exports.MemDriveError = MemDriveError;
@@ -41,4 +40,25 @@ function abortError(cause, signal) {
41
40
  return signal?.aborted || error?.name === 'AbortError'
42
41
  ? new MemDriveError('ABORTED', 'Operation aborted.', { cause }) : cause;
43
42
  }
43
+ function databaseError(error, message) {
44
+ if (error instanceof MemDriveError)
45
+ return error;
46
+ const result = new MemDriveError('DATABASE_ERROR', message, { cause: error });
47
+ const remote = error;
48
+ const status = remote?.statusCode ?? remote?.status ?? remote?.httpStatus;
49
+ if (typeof status === 'number' && Number.isInteger(status))
50
+ result.status = status;
51
+ return result;
52
+ }
53
+ async function nativeRequest(operation, signal) {
54
+ checkAbort(signal);
55
+ try {
56
+ return await operation();
57
+ }
58
+ catch (cause) {
59
+ throw abortError(cause, signal);
60
+ }
61
+ }
62
+ const nativeOptions = (signal) => signal === undefined ? {} : { signal };
63
+ exports.nativeOptions = nativeOptions;
44
64
  //# sourceMappingURL=errors.js.map