@functional-systems/memdrive 0.0.0-stage → 0.1.0-dev.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/LICENSE +201 -0
- package/README.md +232 -2
- package/dist/commonjs/chunking.d.ts +7 -0
- package/dist/commonjs/chunking.d.ts.map +1 -0
- package/dist/commonjs/chunking.js +46 -0
- package/dist/commonjs/chunking.js.map +1 -0
- package/dist/commonjs/errors.d.ts +17 -0
- package/dist/commonjs/errors.d.ts.map +1 -0
- package/dist/commonjs/errors.js +44 -0
- package/dist/commonjs/errors.js.map +1 -0
- package/dist/commonjs/filter.d.ts +30 -0
- package/dist/commonjs/filter.d.ts.map +1 -0
- package/dist/commonjs/filter.js +224 -0
- package/dist/commonjs/filter.js.map +1 -0
- package/dist/commonjs/index.d.ts +8 -0
- package/dist/commonjs/index.d.ts.map +1 -0
- package/dist/commonjs/index.js +343 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/commonjs/storage.d.ts +274 -0
- package/dist/commonjs/storage.d.ts.map +1 -0
- package/dist/commonjs/storage.js +861 -0
- package/dist/commonjs/storage.js.map +1 -0
- package/dist/commonjs/tools/definitions.d.ts +5 -0
- package/dist/commonjs/tools/definitions.d.ts.map +1 -0
- package/dist/commonjs/tools/definitions.js +129 -0
- package/dist/commonjs/tools/definitions.js.map +1 -0
- package/dist/commonjs/tools/index.d.ts +6 -0
- package/dist/commonjs/tools/index.d.ts.map +1 -0
- package/dist/commonjs/tools/index.js +104 -0
- package/dist/commonjs/tools/index.js.map +1 -0
- package/dist/commonjs/tools/types.d.ts +50 -0
- package/dist/commonjs/tools/types.d.ts.map +1 -0
- package/dist/commonjs/tools/types.js +3 -0
- package/dist/commonjs/tools/types.js.map +1 -0
- package/dist/commonjs/types.d.ts +277 -0
- package/dist/commonjs/types.d.ts.map +1 -0
- package/dist/commonjs/types.js +3 -0
- package/dist/commonjs/types.js.map +1 -0
- package/dist/commonjs/values.d.ts +17 -0
- package/dist/commonjs/values.d.ts.map +1 -0
- package/dist/commonjs/values.js +90 -0
- package/dist/commonjs/values.js.map +1 -0
- package/dist/esm/chunking.d.ts +7 -0
- package/dist/esm/chunking.d.ts.map +1 -0
- package/dist/esm/chunking.js +42 -0
- package/dist/esm/chunking.js.map +1 -0
- package/dist/esm/errors.d.ts +17 -0
- package/dist/esm/errors.d.ts.map +1 -0
- package/dist/esm/errors.js +36 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/filter.d.ts +30 -0
- package/dist/esm/filter.d.ts.map +1 -0
- package/dist/esm/filter.js +209 -0
- package/dist/esm/filter.js.map +1 -0
- package/dist/esm/index.d.ts +8 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +335 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/storage.d.ts +274 -0
- package/dist/esm/storage.d.ts.map +1 -0
- package/dist/esm/storage.js +845 -0
- package/dist/esm/storage.js.map +1 -0
- package/dist/esm/tools/definitions.d.ts +5 -0
- package/dist/esm/tools/definitions.d.ts.map +1 -0
- package/dist/esm/tools/definitions.js +126 -0
- package/dist/esm/tools/definitions.js.map +1 -0
- package/dist/esm/tools/index.d.ts +6 -0
- package/dist/esm/tools/index.d.ts.map +1 -0
- package/dist/esm/tools/index.js +101 -0
- package/dist/esm/tools/index.js.map +1 -0
- package/dist/esm/tools/types.d.ts +50 -0
- package/dist/esm/tools/types.d.ts.map +1 -0
- package/dist/esm/tools/types.js +2 -0
- package/dist/esm/tools/types.js.map +1 -0
- package/dist/esm/types.d.ts +277 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/values.d.ts +17 -0
- package/dist/esm/values.d.ts.map +1 -0
- package/dist/esm/values.js +87 -0
- package/dist/esm/values.js.map +1 -0
- package/docs/tools.md +163 -0
- package/package.json +99 -4
- package/src/chunking.ts +32 -0
- package/src/errors.ts +40 -0
- package/src/filter.ts +189 -0
- package/src/index.ts +323 -0
- package/src/storage.ts +765 -0
- package/src/tools/definitions.ts +156 -0
- package/src/tools/index.ts +97 -0
- package/src/tools/types.ts +45 -0
- package/src/types.ts +273 -0
- package/src/values.ts +103 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0-rc.1
|
|
4
|
+
|
|
5
|
+
First release candidate of the standalone MemDrive SDK, backed by the pinned
|
|
6
|
+
LambdaDB TypeScript client 0.12.0.
|
|
7
|
+
|
|
8
|
+
- Store original memories with automatic text chunking, or store caller-provided embeddings and metadata.
|
|
9
|
+
- Retrieve evidence through vector or hybrid search with optional native reranking; support structured metadata filters, exclusions and ordered batch results.
|
|
10
|
+
- Read complete originals, inspect schema descriptions and keyword distributions, and manage memories and branches.
|
|
11
|
+
- Expose portable agent tools through `@functional-systems/memdrive/tools`, with JSON Schema contracts, branch binding and optional writes. Applications own search orchestration and answer generation.
|
|
12
|
+
- Support ESM, CommonJS and TypeScript consumers on Node.js 20.12+ and browser bundlers.
|
|
13
|
+
- Validate installed release archives with bounded live integration checks and publish immutable versions with source identity through npm Trusted Publishing.
|
|
14
|
+
- Supply the required Bayesian candidate budget when hybrid recall disables reranking.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,233 @@
|
|
|
1
|
-
#
|
|
1
|
+
# MemDrive
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
TypeScript memory SDK backed by LambdaDB. Store original memories, retrieve
|
|
4
|
+
relevant evidence, inspect metadata distributions, and read complete originals.
|
|
5
|
+
Applications and their agents own query planning, repeated searches, evidence
|
|
6
|
+
selection, answer generation and presentation. The SDK accepts an initialized
|
|
7
|
+
LambdaDB client; the caller owns connection credentials and transport.
|
|
8
|
+
|
|
9
|
+
The package is `@functional-systems/memdrive`, licensed under Apache-2.0.
|
|
10
|
+
It builds ESM and CommonJS with TypeScript declarations and supports Node.js
|
|
11
|
+
20.12+ and browser bundlers. Install this release candidate and the LambdaDB client
|
|
12
|
+
used to initialize it:
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
npm install @functional-systems/memdrive@0.1.0-rc.1 @functional-systems/lambdadb@0.12.0
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Release candidates may change before a stable release. Use `@rc` to follow release
|
|
19
|
+
candidates, `@dev` for development builds, or an exact version for reproducibility.
|
|
20
|
+
To build locally, run `npm ci`, `npm run build`, and `npm pack`, then install the
|
|
21
|
+
resulting tarball in the consumer project. See [CONTRIBUTING.md](CONTRIBUTING.md)
|
|
22
|
+
for development and
|
|
23
|
+
[RELEASING.md](RELEASING.md) for the release policy.
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { LambdaDBClient } from '@functional-systems/lambdadb';
|
|
27
|
+
import { create } from '@functional-systems/memdrive';
|
|
28
|
+
|
|
29
|
+
const client = new LambdaDBClient({
|
|
30
|
+
baseUrl: 'https://your-lambdadb-endpoint',
|
|
31
|
+
projectName: 'your-project',
|
|
32
|
+
projectApiKey: 'your-project-api-key',
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const drive = await create({
|
|
36
|
+
client, name: 'story_memory',
|
|
37
|
+
description: 'Conversation memories for the example application',
|
|
38
|
+
metadataSchema: {
|
|
39
|
+
role: { type: 'string', description: 'Message author role: user or assistant' },
|
|
40
|
+
tags: { type: 'string[]', description: 'Application-defined topics' },
|
|
41
|
+
},
|
|
42
|
+
textSearch: { analyzers: ['english'] },
|
|
43
|
+
labels: { application: 'example', owner: 'account123' },
|
|
44
|
+
});
|
|
45
|
+
await drive.remember({ mems: [
|
|
46
|
+
{ id: 'message-1', content: 'The meeting is on Friday.',
|
|
47
|
+
timestamp: '2026-11-13T12:00:00Z', metadata: { role: 'user' } },
|
|
48
|
+
] });
|
|
49
|
+
const { matches, usage } = await drive.recall({ query: 'When is the meeting?' });
|
|
50
|
+
const { mems } = await drive.read({ ids: [...new Set(matches.map(match => match.memId))] });
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Public operations
|
|
54
|
+
|
|
55
|
+
| Operation | Contract |
|
|
56
|
+
| --- | --- |
|
|
57
|
+
| `create(options, {signal}?)` | Creates one collection and opens a handle. Existing names fail. |
|
|
58
|
+
| `open({client, name, branch?, ...}, {signal}?)` | Validates an existing MemDrive; embedding and analyzers come from storage. |
|
|
59
|
+
| `list({client, labels?, limit?, cursor?}, {signal}?)` | Returns `{drives, nextCursor?}` for one native collection page. Default limit 10, maximum 100. |
|
|
60
|
+
| `drive.describe({signal}?)` | Fresh `{name, description?, labels, metadataSchema, embedding, textSearch?}`. |
|
|
61
|
+
| `drive.remember({mems}, {signal}?)` | Appends generated IDs or fully replaces supplied IDs. Returns `{ids}` in input order. |
|
|
62
|
+
| `drive.recall(request, {signal}?)` | Returns `{matches, usage}`; no final answer is generated. Default limit 10. |
|
|
63
|
+
| `drive.recall({requests}, {signal}?)` | Returns `{results}` in input order, including individual error/usage entries. |
|
|
64
|
+
| `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. |
|
|
65
|
+
| `drive.read({ids}, {signal}?)` | Returns full original `{mems}`; absent IDs are omitted. |
|
|
66
|
+
| `drive.list({limit?, cursor?}, {signal}?)` | Returns original `{mems, nextCursor?}` from one committed physical document page. Default limit 100, maximum 1000. |
|
|
67
|
+
| `drive.forget({ids} or {filter}, {signal}?)` | Removes whole Mems and their chunks. Missing IDs are harmless. |
|
|
68
|
+
| `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. |
|
|
69
|
+
| `drive.at({branch})` | Returns a branch-bound data handle with the same data APIs. |
|
|
70
|
+
| `drive.branches.create({name, source:{branch}}, {signal}?)` | Creates a branch. Latest accepted-write inclusion depends on the LambdaDB server contract. |
|
|
71
|
+
| `drive.branches.list({signal}?)`, `.delete(name, {signal}?)` | Lists/deletes branches. The main branch cannot be deleted. |
|
|
72
|
+
| `drive.destroy({signal}?)` | Deletes the collection, including its branches. |
|
|
73
|
+
|
|
74
|
+
Both list APIs may return an empty logical page with `nextCursor`; keep paging
|
|
75
|
+
until the cursor is absent. Document listing is committed-state inventory.
|
|
76
|
+
`read` and `recall` request consistent reads. A write-dependent read starts after
|
|
77
|
+
the caller receives a successful write response. Concurrent writes to the same
|
|
78
|
+
Mem have no ordering guarantee.
|
|
79
|
+
|
|
80
|
+
`metadataSchema` is required at creation; use `{}` when no custom fields are needed.
|
|
81
|
+
Metadata types are `string`, `string[]`, `number`, `boolean`, and `datetime`.
|
|
82
|
+
Drive and metadata-field descriptions are optional strings, up to 255 UTF-16 code units,
|
|
83
|
+
stored in native collection/index descriptions. `configure` preserves omitted
|
|
84
|
+
descriptions; an empty string clears one. Descriptions are returned by `describe`
|
|
85
|
+
and the drive catalog. `describe()` is the schema inspection API; there is no
|
|
86
|
+
separate agent-specific schema response.
|
|
87
|
+
Only declared metadata is accepted. Filters use explicit `and`/`or` arrays and
|
|
88
|
+
leaves such as `{field:'metadata.role', op:'eq', value:'user'}`. Supported leaf
|
|
89
|
+
operators are `eq`, `neq`, `in`, `exists`, `gt`, `gte`, `lt`, `lte`; ranges apply
|
|
90
|
+
to numbers and datetimes. `id` and `timestamp` are also filterable.
|
|
91
|
+
|
|
92
|
+
Labels are native collection tags, with a total native limit of five. `memory.*`
|
|
93
|
+
is reserved: two internal tags leave three caller labels for managed stores;
|
|
94
|
+
three internal tags leave two for external-vector stores. Over-limit input fails
|
|
95
|
+
before a request is sent. Descriptions do not consume tag slots. Labels aid discovery,
|
|
96
|
+
not authorization. The caller verifies its expected ownership before mutations.
|
|
97
|
+
Incompatible stores are rejected by `open` and skipped by the catalog. There is
|
|
98
|
+
no automatic migration or legacy-store deletion. Snapshot retention is not a
|
|
99
|
+
MemDrive option: new collections omit the setting and use LambdaDB's default of
|
|
100
|
+
30 days. Opening an existing drive does not change its native retention setting.
|
|
101
|
+
|
|
102
|
+
## Storage and retrieval
|
|
103
|
+
|
|
104
|
+
Managed stores use native `text-embedding-3-small` embeddings. At creation,
|
|
105
|
+
omitting `embedding` and passing `embedding: { mode: 'managed' }` are equivalent.
|
|
106
|
+
The managed model settings are fixed; `open` recovers them from storage. Supplying
|
|
107
|
+
`textSearch.analyzers` enables hybrid retrieval; omission uses vector retrieval.
|
|
108
|
+
Managed text retrieval uses native Jev reranking by default in both cases.
|
|
109
|
+
`recall` accepts an optional boolean `rerank`, including on each item of a batch:
|
|
110
|
+
|
|
111
|
+
| Embedding configuration | Omitted | `false` | `true` |
|
|
112
|
+
| --- | --- | --- | --- |
|
|
113
|
+
| Managed | Enabled | Disabled | Enabled |
|
|
114
|
+
| External | Disabled | Disabled | Rejected |
|
|
115
|
+
|
|
116
|
+
```js
|
|
117
|
+
await drive.recall({ query: 'When is the meeting?', rerank: false });
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
This is a per-request execution option, not a stored setting or a
|
|
121
|
+
`create`/`open`/`configure` option. Disabling reranking preserves the existing
|
|
122
|
+
KNN `k`, filters and result limit; results retain search order.
|
|
123
|
+
Unsupported combinations fail before database requests.
|
|
124
|
+
|
|
125
|
+
Each `recall` performs one native search request. There is no retrieval `mode`,
|
|
126
|
+
internal model adapter, prompt, evidence-selection step or model loop. A caller
|
|
127
|
+
can issue multiple queries in a batch, inspect the returned matches, call `read`
|
|
128
|
+
for complete originals and search again. Optional text `context` and
|
|
129
|
+
`recentDialogue` still become part of the embedding/rerank query without an internal agent
|
|
130
|
+
call. The caller owns their relevance and size; the native 8 KiB query bound is
|
|
131
|
+
validated without silent truncation. `usage` reports `elapsedMs` and
|
|
132
|
+
`databaseRequests`; MemDrive does not report caller model token usage.
|
|
133
|
+
|
|
134
|
+
Optional `observe` and `record` callbacks expose retrieval diagnostics.
|
|
135
|
+
`observe` emits one `retrieved` event for each successful recall; there is no
|
|
136
|
+
selection event. Use `observe.matches[].memId` for canonical caller IDs;
|
|
137
|
+
`observe.ids` contains internal physical evidence IDs. `record` emits `query`
|
|
138
|
+
and `query_result` events, including bodies and memory text. Batch callbacks
|
|
139
|
+
include `requestIndex`. Callers control whether and where to retain these events.
|
|
140
|
+
|
|
141
|
+
Managed text uses the current 800-code-point splitter, Unicode-aware with UTF-16
|
|
142
|
+
source offsets and no overlap. Short full Mems store `content` once. Long Mems
|
|
143
|
+
store their original in unindexed `memContent` and searchable `content` chunks.
|
|
144
|
+
An overwrite replaces obsolete chunk slots with bodyless documents. Public
|
|
145
|
+
matches identify `kind: 'mem'` or `'chunk'`, `memId`, and the returned text span.
|
|
146
|
+
|
|
147
|
+
For caller-provided embeddings, create with:
|
|
148
|
+
|
|
149
|
+
```js
|
|
150
|
+
embedding: { mode: 'external', dimensions: 768,
|
|
151
|
+
similarity: 'cosine', identity: 'caller-model-v1' }
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Remember `{id?, embedding, timestamp?, metadata?}` and recall with
|
|
155
|
+
`{queryVector, filter?, excludeIds?, limit?}`. Text, chunking, keyword search,
|
|
156
|
+
and reranking are unavailable for external embeddings. Read/list/matches
|
|
157
|
+
return references and metadata without vectors or source text. The caller owns
|
|
158
|
+
embedding identity compatibility and reconstruction of the local original.
|
|
159
|
+
|
|
160
|
+
Remember packs complete Mem replacements into native requests up to 6,029,312
|
|
161
|
+
JSON bytes. One Mem is never split across write requests. The per-document bound
|
|
162
|
+
is 5 MiB. All replacements are validated before writes; subsequent requests are
|
|
163
|
+
sequential. Failure details distinguish `completedIds`, `uncertainIds`, and
|
|
164
|
+
`notAttemptedIds`. A multi-request remember is not atomic; do not blindly retry
|
|
165
|
+
the entire operation. The SDK does not serialize different writes or retry them.
|
|
166
|
+
|
|
167
|
+
Cancellation is a separate options argument and never enters stored JSON.
|
|
168
|
+
It removes queued requests and propagates to native requests. Cancellation does
|
|
169
|
+
not undo accepted writes.
|
|
170
|
+
Recalls share a default concurrency bound of five across branch views; the
|
|
171
|
+
caller may configure it. Batch request count is not artificially capped by the
|
|
172
|
+
SDK; a hosted MCP wrapper can impose its own exposed tool limit.
|
|
173
|
+
|
|
174
|
+
The development format stays `mems-v0` until release. Recreate disposable stores
|
|
175
|
+
after incompatible layout changes. MemDrive uses LambdaDB SDK 0.12.0. Build
|
|
176
|
+
artifacts are generated with `npm run build`; browser applications bundle the
|
|
177
|
+
public package entry point with their own build tools.
|
|
178
|
+
|
|
179
|
+
## Metadata distributions
|
|
180
|
+
|
|
181
|
+
Use `describe()` for field declarations and `countValues()` for stored values:
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
const { metadataSchema } = await drive.describe();
|
|
185
|
+
const distribution = await drive.countValues({
|
|
186
|
+
fields: ['metadata.role', 'metadata.tags'],
|
|
187
|
+
filter: { field: 'timestamp', op: 'gte', value: '2026-01-01T00:00:00Z' },
|
|
188
|
+
excludeIds: ['message-to-exclude'],
|
|
189
|
+
limit: 10,
|
|
190
|
+
});
|
|
191
|
+
// distribution.values['metadata.role']:
|
|
192
|
+
// { buckets: [{ value: 'user', count: 12 }], hasMore: false }
|
|
193
|
+
// distribution.asOf: ISO 8601 UTC fetch time
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Countable fields are `id` and declared `string`/`string[]` metadata fields.
|
|
197
|
+
Each request accepts one to five distinct fields, matching the native facet limit. Numeric, boolean and datetime fields can
|
|
198
|
+
filter the population but cannot be aggregated. Counts include each original
|
|
199
|
+
Mem once, regardless of its chunk count; obsolete chunk slots do not contribute.
|
|
200
|
+
An array may place a Mem in multiple buckets, so bucket sums are not the number
|
|
201
|
+
of memories. The active branch, filter and excluded IDs determine the population.
|
|
202
|
+
|
|
203
|
+
Value results are cached for 60 seconds per data handle; schema validation is
|
|
204
|
+
cached for five minutes internally. `describe()` itself remains a fresh lookup.
|
|
205
|
+
SDK mutations invalidate local counts across views of the same drive. Writes
|
|
206
|
+
through another independent handle or client may remain invisible in cached
|
|
207
|
+
counts until expiration. `asOf` is the result fetch time, not a database snapshot
|
|
208
|
+
identifier. `hasMore` is `true` when another bucket is observed, `false` when the
|
|
209
|
+
response is complete, and `null` when the native 100-bucket bound leaves
|
|
210
|
+
completeness unknown.
|
|
211
|
+
|
|
212
|
+
A hosted MCP service can expose these SDK operations and supply tool descriptions
|
|
213
|
+
and protocol handling. The service or calling agent owns orchestration; MemDrive
|
|
214
|
+
has no model-specific tool schemas, short evidence aliases or finish/report tool.
|
|
215
|
+
|
|
216
|
+
## Agent tools
|
|
217
|
+
|
|
218
|
+
Import `createTools` from `@functional-systems/memdrive/tools` to expose portable
|
|
219
|
+
memory operations to a calling agent. The common layer provides JSON Schema input
|
|
220
|
+
and output definitions, descriptions, effect annotations and SDK execution. It
|
|
221
|
+
contains no internal agent loop or MCP server. See [the tool contract](docs/tools.md)
|
|
222
|
+
for the catalog, branch binding, write opt-in, error outcomes and direct/MCP mapping.
|
|
223
|
+
|
|
224
|
+
## Consumers
|
|
225
|
+
|
|
226
|
+
The prototype was exercised by BEAM, LongMemEval and SillyMemory integrations.
|
|
227
|
+
Those applications and evaluation runners remain outside this SDK repository;
|
|
228
|
+
their existing local copies have not been switched to the standalone package.
|
|
229
|
+
Each caller owns dataset interpretation, recent-context partition, search
|
|
230
|
+
orchestration and final prompt assembly. The standalone API no longer accepts
|
|
231
|
+
`mode` or `agent`; consumers of the earlier prototype must remove those options
|
|
232
|
+
and move any agent loop to the application. SDK unit and package checks do not establish
|
|
233
|
+
benchmark answer quality or live service compatibility.
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CHUNKING_POLICY = void 0;
|
|
4
|
+
exports.chunkSpans = chunkSpans;
|
|
5
|
+
// Exact source partitions: UTF-16 offsets for slice(), a Unicode-code-point cap.
|
|
6
|
+
// 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.');
|
|
11
|
+
const offsets = [0];
|
|
12
|
+
for (const char of text)
|
|
13
|
+
offsets.push(offsets.at(-1) + char.length);
|
|
14
|
+
const paragraphs = [...text.matchAll(/\r?\n[\t ]*\r?\n(?:\s*\r?\n)*/gu)].map(m => m.index + m[0].length);
|
|
15
|
+
const sentences = typeof Intl.Segmenter === 'function'
|
|
16
|
+
? [...new Intl.Segmenter('en', { granularity: 'sentence' }).segment(text)].map(s => s.index + s.segment.length)
|
|
17
|
+
: [...text.matchAll(/[.!?]["'”’)\]]*(?:\s+|$)/gu)].map(m => m.index + m[0].length);
|
|
18
|
+
const words = [...text.matchAll(/\s+/gu)].map(m => m.index + m[0].length);
|
|
19
|
+
const lastBoundary = (boundaries, floor, ceiling) => {
|
|
20
|
+
let low = 0, high = boundaries.length;
|
|
21
|
+
while (low < high) {
|
|
22
|
+
const mid = (low + high) >>> 1;
|
|
23
|
+
if (boundaries[mid] <= ceiling)
|
|
24
|
+
low = mid + 1;
|
|
25
|
+
else
|
|
26
|
+
high = mid;
|
|
27
|
+
}
|
|
28
|
+
return boundaries[low - 1] >= floor ? boundaries[low - 1] : undefined;
|
|
29
|
+
};
|
|
30
|
+
const spans = [];
|
|
31
|
+
for (let point = 0; point < offsets.length - 1;) {
|
|
32
|
+
const last = Math.min(point + limit, offsets.length - 1), start = offsets[point];
|
|
33
|
+
let end = offsets[last];
|
|
34
|
+
if (last < offsets.length - 1) {
|
|
35
|
+
// Avoid tiny fragments caused by an early heading/short sentence.
|
|
36
|
+
const floor = offsets[point + Math.max(1, Math.floor(limit / 2))];
|
|
37
|
+
end = lastBoundary(paragraphs, floor, end) ?? lastBoundary(sentences, floor, end)
|
|
38
|
+
?? lastBoundary(words, floor, end) ?? end;
|
|
39
|
+
}
|
|
40
|
+
spans.push({ start, end, text: text.slice(start, end) });
|
|
41
|
+
while (offsets[point] < end)
|
|
42
|
+
point++;
|
|
43
|
+
}
|
|
44
|
+
return spans;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=chunking.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunking.js","sourceRoot":"","sources":["../../src/chunking.ts"],"names":[],"mappings":";;;AAGA,gCA4BC;AA/BD,iFAAiF;AACjF,+EAA+E;AAClE,QAAA,eAAe,GAAG,aAAa,CAAC;AAC7C,SAAgB,UAAU,CAAC,IAAY,EAAE,KAAK,GAAG,GAAG;IAChD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,yCAAyC,CAAC,CAAC;IAC3G,MAAM,OAAO,GAAG,CAAC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AE,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 { RequestOptions, Usage } from './types.js';
|
|
2
|
+
export declare class MemDriveError extends Error {
|
|
3
|
+
code: string;
|
|
4
|
+
details?: Record<string, unknown> | undefined;
|
|
5
|
+
usage?: Usage | undefined;
|
|
6
|
+
status?: number | undefined;
|
|
7
|
+
constructor(code: string, message: string, { cause, details, usage }?: {
|
|
8
|
+
cause?: unknown;
|
|
9
|
+
details?: Record<string, unknown> | undefined;
|
|
10
|
+
usage?: Usage | undefined;
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
export declare function requireInput(condition: unknown, message: string): asserts condition;
|
|
14
|
+
export declare function operationOptions(options?: RequestOptions): RequestOptions;
|
|
15
|
+
export declare function checkAbort(signal?: AbortSignal): void;
|
|
16
|
+
export declare function abortError(cause: unknown, signal?: AbortSignal): unknown;
|
|
17
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExD,qBAAa,aAAc,SAAQ,KAAK;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IAC9C,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;gBACxB,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,GAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;QAAC,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,CAAA;KAAO;CAO3K;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;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAKxE"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MemDriveError = void 0;
|
|
4
|
+
exports.requireInput = requireInput;
|
|
5
|
+
exports.operationOptions = operationOptions;
|
|
6
|
+
exports.checkAbort = checkAbort;
|
|
7
|
+
exports.abortError = abortError;
|
|
8
|
+
class MemDriveError extends Error {
|
|
9
|
+
constructor(code, message, { cause, details, usage } = {}) {
|
|
10
|
+
super(message, cause === undefined ? undefined : { cause });
|
|
11
|
+
this.name = 'MemDriveError';
|
|
12
|
+
this.code = code;
|
|
13
|
+
if (details !== undefined)
|
|
14
|
+
this.details = details;
|
|
15
|
+
if (usage !== undefined)
|
|
16
|
+
this.usage = usage;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.MemDriveError = MemDriveError;
|
|
20
|
+
function requireInput(condition, message) {
|
|
21
|
+
if (!condition)
|
|
22
|
+
throw new MemDriveError('INVALID_INPUT', message);
|
|
23
|
+
}
|
|
24
|
+
function operationOptions(options = {}) {
|
|
25
|
+
requireInput(options !== null && typeof options === 'object' && !Array.isArray(options)
|
|
26
|
+
&& Object.keys(options).every(key => key === 'signal'), 'Operation options accept only signal.');
|
|
27
|
+
const { signal } = options;
|
|
28
|
+
requireInput(signal === undefined || (signal !== null && typeof signal === 'object'
|
|
29
|
+
&& typeof signal.aborted === 'boolean' && typeof signal.addEventListener === 'function'
|
|
30
|
+
&& typeof signal.removeEventListener === 'function'), 'signal must be an AbortSignal.');
|
|
31
|
+
return { signal };
|
|
32
|
+
}
|
|
33
|
+
function checkAbort(signal) {
|
|
34
|
+
if (signal?.aborted)
|
|
35
|
+
throw new MemDriveError('ABORTED', 'Operation aborted.');
|
|
36
|
+
}
|
|
37
|
+
function abortError(cause, signal) {
|
|
38
|
+
const error = cause;
|
|
39
|
+
if (error?.code === 'ABORTED')
|
|
40
|
+
return cause;
|
|
41
|
+
return signal?.aborted || error?.name === 'AbortError'
|
|
42
|
+
? new MemDriveError('ABORTED', 'Operation aborted.', { cause }) : cause;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";;;AAgBA,oCAEC;AAED,4CAQC;AAED,gCAEC;AAED,gCAKC;AArCD,MAAa,aAAc,SAAQ,KAAK;IAKpC,YAAY,IAAY,EAAE,OAAe,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,KAAoG,EAAE;QACpK,KAAK,CAAC,OAAO,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAC5D,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,OAAO,KAAK,SAAS;YAAE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAClD,IAAI,KAAK,KAAK,SAAS;YAAE,IAA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,aAAa,CAAC,SAAS,EAAE,oBAAoB,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AAChF,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Filter, Metadata, MetadataSchema, MetadataType } from './types.js';
|
|
2
|
+
export declare const isObject: (value: unknown) => value is Record<string, unknown>;
|
|
3
|
+
export declare const matchAll: () => {
|
|
4
|
+
queryString: {
|
|
5
|
+
query: string;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export declare function dateValue(value: unknown): bigint | undefined;
|
|
9
|
+
export declare function validateDescription(description: unknown): string | undefined;
|
|
10
|
+
export declare function validateMetadataSchema(schema: unknown): MetadataSchema;
|
|
11
|
+
export declare function fieldType(field: unknown, schema: MetadataSchema): MetadataType | undefined;
|
|
12
|
+
export declare function validScalar(value: unknown, type: MetadataType | undefined): boolean;
|
|
13
|
+
export declare function validateFilter(filter: unknown, schema: MetadataSchema): Filter | undefined;
|
|
14
|
+
export interface NativeFilter {
|
|
15
|
+
queryString?: {
|
|
16
|
+
query: string;
|
|
17
|
+
defaultField?: string;
|
|
18
|
+
};
|
|
19
|
+
bool?: NativeFilter[];
|
|
20
|
+
occur?: string | undefined;
|
|
21
|
+
}
|
|
22
|
+
export declare function compileFilter(filter: unknown, schema: MetadataSchema): NativeFilter;
|
|
23
|
+
export declare function buildFilter(filters?: unknown[], excludeIds?: string[], schema?: MetadataSchema): NativeFilter;
|
|
24
|
+
export declare function buildSearchFilter(filters?: unknown[], excludeIds?: string[], seenChunkIds?: string[], schema?: MetadataSchema): NativeFilter;
|
|
25
|
+
export declare function matchesFilter(mem: {
|
|
26
|
+
id: string;
|
|
27
|
+
timestamp?: string | undefined;
|
|
28
|
+
metadata?: Metadata | undefined;
|
|
29
|
+
}, filter: Filter | undefined, schema: MetadataSchema): boolean;
|
|
30
|
+
//# sourceMappingURL=filter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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