@papr/memory 1.20.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +61 -0
- package/LICENSE +1 -1
- package/README.md +13 -1
- package/client.d.mts +37 -9
- package/client.d.mts.map +1 -1
- package/client.d.ts +37 -9
- package/client.d.ts.map +1 -1
- package/client.js +17 -2
- package/client.js.map +1 -1
- package/client.mjs +17 -2
- package/client.mjs.map +1 -1
- package/internal/parse.d.mts.map +1 -1
- package/internal/parse.d.ts.map +1 -1
- package/internal/parse.js +5 -0
- package/internal/parse.js.map +1 -1
- package/internal/parse.mjs +5 -0
- package/internal/parse.mjs.map +1 -1
- package/internal/tslib.js +22 -22
- package/package.json +1 -1
- package/resources/document.d.mts +16 -3
- package/resources/document.d.mts.map +1 -1
- package/resources/document.d.ts +16 -3
- package/resources/document.d.ts.map +1 -1
- package/resources/index.d.mts +6 -3
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +6 -3
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +7 -1
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +3 -0
- package/resources/index.mjs.map +1 -1
- package/resources/memory.d.mts +498 -119
- package/resources/memory.d.mts.map +1 -1
- package/resources/memory.d.ts +498 -119
- package/resources/memory.d.ts.map +1 -1
- package/resources/memory.js +8 -4
- package/resources/memory.js.map +1 -1
- package/resources/memory.mjs +8 -4
- package/resources/memory.mjs.map +1 -1
- package/resources/messages/index.d.mts +3 -0
- package/resources/messages/index.d.mts.map +1 -0
- package/resources/messages/index.d.ts +3 -0
- package/resources/messages/index.d.ts.map +1 -0
- package/resources/messages/index.js +9 -0
- package/resources/messages/index.js.map +1 -0
- package/resources/messages/index.mjs +4 -0
- package/resources/messages/index.mjs.map +1 -0
- package/resources/messages/messages.d.mts +160 -0
- package/resources/messages/messages.d.mts.map +1 -0
- package/resources/messages/messages.d.ts +160 -0
- package/resources/messages/messages.d.ts.map +1 -0
- package/resources/messages/messages.js +54 -0
- package/resources/messages/messages.js.map +1 -0
- package/resources/messages/messages.mjs +49 -0
- package/resources/messages/messages.mjs.map +1 -0
- package/resources/messages/sessions.d.mts +262 -0
- package/resources/messages/sessions.d.mts.map +1 -0
- package/resources/messages/sessions.d.ts +262 -0
- package/resources/messages/sessions.d.ts.map +1 -0
- package/resources/messages/sessions.js +122 -0
- package/resources/messages/sessions.js.map +1 -0
- package/resources/messages/sessions.mjs +118 -0
- package/resources/messages/sessions.mjs.map +1 -0
- package/resources/messages.d.mts +2 -0
- package/resources/messages.d.mts.map +1 -0
- package/resources/messages.d.ts +2 -0
- package/resources/messages.d.ts.map +1 -0
- package/resources/messages.js +6 -0
- package/resources/messages.js.map +1 -0
- package/resources/messages.mjs +3 -0
- package/resources/messages.mjs.map +1 -0
- package/resources/omo.d.mts +98 -0
- package/resources/omo.d.mts.map +1 -0
- package/resources/omo.d.ts +98 -0
- package/resources/omo.d.ts.map +1 -0
- package/resources/omo.js +36 -0
- package/resources/omo.js.map +1 -0
- package/resources/omo.mjs +32 -0
- package/resources/omo.mjs.map +1 -0
- package/resources/schemas.d.mts +667 -76
- package/resources/schemas.d.mts.map +1 -1
- package/resources/schemas.d.ts +667 -76
- package/resources/schemas.d.ts.map +1 -1
- package/resources/schemas.js.map +1 -1
- package/resources/schemas.mjs.map +1 -1
- package/resources/shared.d.mts +671 -0
- package/resources/shared.d.mts.map +1 -1
- package/resources/shared.d.ts +671 -0
- package/resources/shared.d.ts.map +1 -1
- package/resources/sync.d.mts +142 -0
- package/resources/sync.d.mts.map +1 -0
- package/resources/sync.d.ts +142 -0
- package/resources/sync.d.ts.map +1 -0
- package/resources/sync.js +36 -0
- package/resources/sync.js.map +1 -0
- package/resources/sync.mjs +32 -0
- package/resources/sync.mjs.map +1 -0
- package/resources/user.d.mts +18 -1
- package/resources/user.d.mts.map +1 -1
- package/resources/user.d.ts +18 -1
- package/resources/user.d.ts.map +1 -1
- package/resources/user.js +11 -0
- package/resources/user.js.map +1 -1
- package/resources/user.mjs +11 -0
- package/resources/user.mjs.map +1 -1
- package/src/client.ts +80 -8
- package/src/internal/parse.ts +6 -0
- package/src/resources/document.ts +17 -4
- package/src/resources/index.ts +21 -0
- package/src/resources/memory.ts +548 -163
- package/src/resources/messages/index.ts +11 -0
- package/src/resources/messages/messages.ts +193 -0
- package/src/resources/messages/sessions.ts +315 -0
- package/src/resources/messages.ts +3 -0
- package/src/resources/omo.ts +132 -0
- package/src/resources/schemas.ts +701 -95
- package/src/resources/shared.ts +752 -0
- package/src/resources/sync.ts +179 -0
- package/src/resources/user.ts +23 -0
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.mts.map +1 -1
- package/version.d.ts +1 -1
- package/version.d.ts.map +1 -1
- package/version.js +1 -1
- package/version.js.map +1 -1
- package/version.mjs +1 -1
- package/version.mjs.map +1 -1
package/resources/shared.d.mts
CHANGED
|
@@ -1,3 +1,53 @@
|
|
|
1
|
+
import * as MemoryAPI from "./memory.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Simplified Access Control List configuration.
|
|
4
|
+
*
|
|
5
|
+
* Aligned with Open Memory Object (OMO) standard. See:
|
|
6
|
+
* https://github.com/anthropics/open-memory-object
|
|
7
|
+
*
|
|
8
|
+
* **Supported Entity Prefixes:**
|
|
9
|
+
*
|
|
10
|
+
* | Prefix | Description | Validation |
|
|
11
|
+
* | ---------------- | --------------------- | ------------------------------------ |
|
|
12
|
+
* | `user:` | Internal Papr user ID | Validated against Parse users |
|
|
13
|
+
* | `external_user:` | Your app's user ID | Not validated (your responsibility) |
|
|
14
|
+
* | `organization:` | Organization ID | Validated against your organizations |
|
|
15
|
+
* | `namespace:` | Namespace ID | Validated against your namespaces |
|
|
16
|
+
* | `workspace:` | Workspace ID | Validated against your workspaces |
|
|
17
|
+
* | `role:` | Parse role ID | Validated against your roles |
|
|
18
|
+
*
|
|
19
|
+
* **Examples:**
|
|
20
|
+
*
|
|
21
|
+
* ```python
|
|
22
|
+
* acl = ACLConfig(
|
|
23
|
+
* read=["external_user:alice_123", "organization:org_acme"],
|
|
24
|
+
* write=["external_user:alice_123"]
|
|
25
|
+
* )
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* **Validation Rules:**
|
|
29
|
+
*
|
|
30
|
+
* - Internal entities (user, organization, namespace, workspace, role) are
|
|
31
|
+
* validated
|
|
32
|
+
* - External entities (external_user) are NOT validated - your app is responsible
|
|
33
|
+
* - Invalid internal entities will return an error
|
|
34
|
+
* - Unprefixed values default to `external_user:` for backwards compatibility
|
|
35
|
+
*/
|
|
36
|
+
export interface ACLConfig {
|
|
37
|
+
/**
|
|
38
|
+
* Entity IDs that can read this memory. Format: 'prefix:id' (e.g.,
|
|
39
|
+
* 'external_user:alice', 'organization:org_123'). Supported prefixes: user,
|
|
40
|
+
* external_user, organization, namespace, workspace, role. Unprefixed values
|
|
41
|
+
* treated as external_user for backwards compatibility.
|
|
42
|
+
*/
|
|
43
|
+
read?: Array<string>;
|
|
44
|
+
/**
|
|
45
|
+
* Entity IDs that can write/modify this memory. Format: 'prefix:id' (e.g.,
|
|
46
|
+
* 'external_user:alice'). Supported prefixes: user, external_user, organization,
|
|
47
|
+
* namespace, workspace, role.
|
|
48
|
+
*/
|
|
49
|
+
write?: Array<string>;
|
|
50
|
+
}
|
|
1
51
|
/**
|
|
2
52
|
* Response model for a single memory item in add_memory response
|
|
3
53
|
*/
|
|
@@ -7,4 +57,625 @@ export interface AddMemoryItem {
|
|
|
7
57
|
objectId: string;
|
|
8
58
|
memoryChunkIds?: Array<string>;
|
|
9
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Policy for how edges/relationships of a specific type should be handled.
|
|
62
|
+
*
|
|
63
|
+
* Used in two places:
|
|
64
|
+
*
|
|
65
|
+
* 1. **Schema level**: Inside `UserRelationshipType.constraint` - `edge_type` is
|
|
66
|
+
* implicit from parent
|
|
67
|
+
* 2. **Memory level**: In `memory_policy.edge_constraints[]` - `edge_type` is
|
|
68
|
+
* required
|
|
69
|
+
*
|
|
70
|
+
* Edge constraints allow developers to control:
|
|
71
|
+
*
|
|
72
|
+
* - Which edge types can be created vs. linked to existing targets
|
|
73
|
+
* - How to find/select target nodes (via `search`)
|
|
74
|
+
* - What edge property values to set (exact or auto-extracted)
|
|
75
|
+
* - When to apply the constraint (conditional with logical operators)
|
|
76
|
+
* - Filter by source/target node types
|
|
77
|
+
*
|
|
78
|
+
* **The `search` field** handles target node selection:
|
|
79
|
+
*
|
|
80
|
+
* - Uses SearchConfig to define how to find existing target nodes
|
|
81
|
+
* - Example: `{"properties": [{"name": "name", "mode": "semantic"}]}`
|
|
82
|
+
* - For controlled vocabulary: find existing target, don't create new
|
|
83
|
+
*
|
|
84
|
+
* **The `set` field** controls edge property values:
|
|
85
|
+
*
|
|
86
|
+
* - Exact value: `{"weight": 1.0}` - sets exact value
|
|
87
|
+
* - Auto-extract: `{"reason": {"mode": "auto"}}` - LLM extracts from content
|
|
88
|
+
*
|
|
89
|
+
* **The `when` field** supports logical operators (same as NodeConstraint):
|
|
90
|
+
*
|
|
91
|
+
* - Simple: `{"severity": "high"}`
|
|
92
|
+
* - AND: `{"_and": [{"severity": "high"}, {"confirmed": true}]}`
|
|
93
|
+
* - OR: `{"_or": [{"type": "MITIGATES"}, {"type": "PREVENTS"}]}`
|
|
94
|
+
* - NOT: `{"_not": {"status": "deprecated"}}`
|
|
95
|
+
*/
|
|
96
|
+
export interface EdgeConstraintInput {
|
|
97
|
+
/**
|
|
98
|
+
* 'upsert': Create target node if not found via search (default). 'lookup': Only
|
|
99
|
+
* link to existing target nodes (controlled vocabulary). When 'lookup', edges to
|
|
100
|
+
* non-existing targets are skipped. Deprecated aliases: 'auto' -> 'upsert',
|
|
101
|
+
* 'never' -> 'lookup'.
|
|
102
|
+
*/
|
|
103
|
+
create?: 'upsert' | 'lookup' | 'auto' | 'never';
|
|
104
|
+
/**
|
|
105
|
+
* Direction of edges this constraint applies to. 'outgoing': edges where current
|
|
106
|
+
* node is source (default). 'incoming': edges where current node is target.
|
|
107
|
+
* 'both': applies in either direction.
|
|
108
|
+
*/
|
|
109
|
+
direction?: 'outgoing' | 'incoming' | 'both';
|
|
110
|
+
/**
|
|
111
|
+
* Edge/relationship type this constraint applies to (e.g., 'MITIGATES',
|
|
112
|
+
* 'ASSIGNED_TO'). Optional at schema level (implicit from parent
|
|
113
|
+
* UserRelationshipType), required at memory level (in
|
|
114
|
+
* memory_policy.edge_constraints).
|
|
115
|
+
*/
|
|
116
|
+
edge_type?: string | null;
|
|
117
|
+
/**
|
|
118
|
+
* DEPRECATED: Use create='lookup' instead. Shorthand for create='lookup'. When
|
|
119
|
+
* True, only links to existing target nodes. Equivalent to @lookup decorator in
|
|
120
|
+
* schema definitions.
|
|
121
|
+
*/
|
|
122
|
+
link_only?: boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Explicit behavior when no target match found via search. 'create': create new
|
|
125
|
+
* target node (same as upsert). 'ignore': skip edge creation (same as lookup).
|
|
126
|
+
* 'error': raise error if target not found. If specified, overrides 'create'
|
|
127
|
+
* field.
|
|
128
|
+
*/
|
|
129
|
+
on_miss?: 'create' | 'ignore' | 'error' | null;
|
|
130
|
+
/**
|
|
131
|
+
* Configuration for finding/selecting existing nodes.
|
|
132
|
+
*
|
|
133
|
+
* Defines which properties to match on and how, in priority order. The first
|
|
134
|
+
* matching property wins.
|
|
135
|
+
*
|
|
136
|
+
* **String Shorthand** (simple cases - converts to exact match):
|
|
137
|
+
* SearchConfig(properties=["id", "email"]) # Equivalent to:
|
|
138
|
+
* SearchConfig(properties=[PropertyMatch.exact("id"),
|
|
139
|
+
* PropertyMatch.exact("email")])
|
|
140
|
+
*
|
|
141
|
+
* **Mixed Form** (combine strings and PropertyMatch): SearchConfig(properties=[
|
|
142
|
+
* "id", # String -> exact match PropertyMatch.semantic("title", 0.9) # Full
|
|
143
|
+
* control ])
|
|
144
|
+
*
|
|
145
|
+
* **Full Form** (maximum control): SearchConfig(properties=[
|
|
146
|
+
* PropertyMatch(name="id", mode="exact"), PropertyMatch(name="title",
|
|
147
|
+
* mode="semantic", threshold=0.85) ])
|
|
148
|
+
*
|
|
149
|
+
* **To select a specific node by ID**:
|
|
150
|
+
* SearchConfig(properties=[PropertyMatch.exact("id", "TASK-123")])
|
|
151
|
+
*/
|
|
152
|
+
search?: SearchConfigInput | null;
|
|
153
|
+
/**
|
|
154
|
+
* Set property values on edges. Supports: 1. Exact value: {'weight': 1.0} - sets
|
|
155
|
+
* exact value. 2. Auto-extract: {'reason': {'mode': 'auto'}} - LLM extracts from
|
|
156
|
+
* content. Edge properties are useful for relationship metadata (weight,
|
|
157
|
+
* timestamp, reason, etc.).
|
|
158
|
+
*/
|
|
159
|
+
set?: {
|
|
160
|
+
[key: string]: string | number | boolean | Array<unknown> | {
|
|
161
|
+
[key: string]: unknown;
|
|
162
|
+
} | PropertyValue;
|
|
163
|
+
} | null;
|
|
164
|
+
/**
|
|
165
|
+
* Filter: only apply when source node is of this type. Example:
|
|
166
|
+
* source_type='SecurityBehavior' - only applies to edges from SecurityBehavior
|
|
167
|
+
* nodes.
|
|
168
|
+
*/
|
|
169
|
+
source_type?: string | null;
|
|
170
|
+
/**
|
|
171
|
+
* Filter: only apply when target node is of this type. Example:
|
|
172
|
+
* target_type='TacticDef' - only applies to edges targeting TacticDef nodes.
|
|
173
|
+
*/
|
|
174
|
+
target_type?: string | null;
|
|
175
|
+
/**
|
|
176
|
+
* Condition for when this constraint applies. Supports logical operators: '\_and',
|
|
177
|
+
* '\_or', '\_not'. Applied to edge properties or context. Example: {'\_and':
|
|
178
|
+
* [{'severity': 'high'}, {'_not': {'status': 'deprecated'}}]}
|
|
179
|
+
*/
|
|
180
|
+
when?: {
|
|
181
|
+
[key: string]: unknown;
|
|
182
|
+
} | null;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* A memory item in the knowledge base
|
|
186
|
+
*/
|
|
187
|
+
export interface Memory {
|
|
188
|
+
id: string;
|
|
189
|
+
acl: {
|
|
190
|
+
[key: string]: {
|
|
191
|
+
[key: string]: boolean;
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
content: string;
|
|
195
|
+
type: string;
|
|
196
|
+
user_id: string;
|
|
197
|
+
/**
|
|
198
|
+
* Memory category based on role
|
|
199
|
+
*/
|
|
200
|
+
category?: string | null;
|
|
201
|
+
context?: Array<MemoryAPI.ContextItem> | null;
|
|
202
|
+
conversation_id?: string;
|
|
203
|
+
createdAt?: string | null;
|
|
204
|
+
current_step?: string | null;
|
|
205
|
+
customMetadata?: {
|
|
206
|
+
[key: string]: unknown;
|
|
207
|
+
} | null;
|
|
208
|
+
/**
|
|
209
|
+
* Full precision (float32) embedding vector from Qdrant. Typically 2560 dimensions
|
|
210
|
+
* for Qwen4B. Used for CoreML/ANE fp16 models.
|
|
211
|
+
*/
|
|
212
|
+
embedding?: Array<number> | null;
|
|
213
|
+
/**
|
|
214
|
+
* Quantized INT8 embedding vector (values -128 to 127). 4x smaller than float32.
|
|
215
|
+
* Default format for efficiency.
|
|
216
|
+
*/
|
|
217
|
+
embedding_int8?: Array<number> | null;
|
|
218
|
+
external_user_id?: string | null;
|
|
219
|
+
external_user_read_access?: Array<string> | null;
|
|
220
|
+
external_user_write_access?: Array<string> | null;
|
|
221
|
+
file_url?: string | null;
|
|
222
|
+
filename?: string | null;
|
|
223
|
+
hierarchical_structures?: string;
|
|
224
|
+
location?: string | null;
|
|
225
|
+
metadata?: string | {
|
|
226
|
+
[key: string]: unknown;
|
|
227
|
+
} | null;
|
|
228
|
+
metrics?: {
|
|
229
|
+
[key: string]: unknown;
|
|
230
|
+
} | null;
|
|
231
|
+
/**
|
|
232
|
+
* Namespace ID this memory belongs to
|
|
233
|
+
*/
|
|
234
|
+
namespace_id?: string | null;
|
|
235
|
+
namespace_read_access?: Array<string> | null;
|
|
236
|
+
namespace_write_access?: Array<string> | null;
|
|
237
|
+
/**
|
|
238
|
+
* Organization ID that owns this memory
|
|
239
|
+
*/
|
|
240
|
+
organization_id?: string | null;
|
|
241
|
+
organization_read_access?: Array<string> | null;
|
|
242
|
+
organization_write_access?: Array<string> | null;
|
|
243
|
+
page?: string | null;
|
|
244
|
+
page_number?: number | null;
|
|
245
|
+
/**
|
|
246
|
+
* Popularity signal (0-1): 0.5*cacheConfidenceWeighted30d +
|
|
247
|
+
* 0.5*citationConfidenceWeighted30d. Uses stored EMA fields.
|
|
248
|
+
*/
|
|
249
|
+
popularity_score?: number | null;
|
|
250
|
+
/**
|
|
251
|
+
* Recency signal (0-1): exp(-0.05 \* days_since_last_access). Half-life ~14 days.
|
|
252
|
+
*/
|
|
253
|
+
recency_score?: number | null;
|
|
254
|
+
/**
|
|
255
|
+
* Final relevance (0-1). rank_results=False: 0.6*sim + 0.25*pop + 0.15\*recency.
|
|
256
|
+
* rank_results=True: RRF-based fusion.
|
|
257
|
+
*/
|
|
258
|
+
relevance_score?: number | null;
|
|
259
|
+
/**
|
|
260
|
+
* Reranker confidence (0-1). Meaningful for LLM reranking; equals reranker_score
|
|
261
|
+
* for cross-encoders.
|
|
262
|
+
*/
|
|
263
|
+
reranker_confidence?: number | null;
|
|
264
|
+
/**
|
|
265
|
+
* Reranker relevance (0-1). From cross-encoder (Cohere/Qwen3/BGE) or LLM
|
|
266
|
+
* (GPT-5-nano).
|
|
267
|
+
*/
|
|
268
|
+
reranker_score?: number | null;
|
|
269
|
+
/**
|
|
270
|
+
* Reranker type: 'cross_encoder' (Cohere/Qwen3/BGE) or 'llm'
|
|
271
|
+
* (GPT-5-nano/GPT-4o-mini).
|
|
272
|
+
*/
|
|
273
|
+
reranker_type?: string | null;
|
|
274
|
+
/**
|
|
275
|
+
* Role that generated this memory (user or assistant)
|
|
276
|
+
*/
|
|
277
|
+
role?: string | null;
|
|
278
|
+
role_read_access?: Array<string> | null;
|
|
279
|
+
role_write_access?: Array<string> | null;
|
|
280
|
+
/**
|
|
281
|
+
* Cosine similarity from vector search (0-1). Measures semantic relevance to
|
|
282
|
+
* query.
|
|
283
|
+
*/
|
|
284
|
+
similarity_score?: number | null;
|
|
285
|
+
source_document_id?: string | null;
|
|
286
|
+
source_message_id?: string | null;
|
|
287
|
+
source_type?: string;
|
|
288
|
+
source_url?: string;
|
|
289
|
+
steps?: Array<string>;
|
|
290
|
+
tags?: Array<string>;
|
|
291
|
+
title?: string | null;
|
|
292
|
+
topics?: Array<string>;
|
|
293
|
+
total_pages?: number | null;
|
|
294
|
+
totalProcessingCost?: number | null;
|
|
295
|
+
updatedAt?: string | null;
|
|
296
|
+
user_read_access?: Array<string> | null;
|
|
297
|
+
user_write_access?: Array<string> | null;
|
|
298
|
+
workspace_id?: string | null;
|
|
299
|
+
workspace_read_access?: Array<string> | null;
|
|
300
|
+
workspace_write_access?: Array<string> | null;
|
|
301
|
+
[k: string]: unknown;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Unified memory processing policy.
|
|
305
|
+
*
|
|
306
|
+
* This is the SINGLE source of truth for how a memory should be processed,
|
|
307
|
+
* combining graph generation control AND OMO (Open Memory Object) safety
|
|
308
|
+
* standards.
|
|
309
|
+
*
|
|
310
|
+
* **Graph Generation Modes:**
|
|
311
|
+
*
|
|
312
|
+
* - auto: LLM extracts entities freely (default)
|
|
313
|
+
* - manual: Developer provides exact nodes (no LLM extraction)
|
|
314
|
+
*
|
|
315
|
+
* **OMO Safety Standards:**
|
|
316
|
+
*
|
|
317
|
+
* - consent: How data owner allowed storage (explicit, implicit, terms, none)
|
|
318
|
+
* - risk: Safety assessment (none, sensitive, flagged)
|
|
319
|
+
* - acl: Access control list for read/write permissions
|
|
320
|
+
*
|
|
321
|
+
* **Schema Integration:**
|
|
322
|
+
*
|
|
323
|
+
* - schema_id: Reference a schema that may have its own default memory_policy
|
|
324
|
+
* - Schema-level policies are merged with request-level (request takes precedence)
|
|
325
|
+
*/
|
|
326
|
+
export interface MemoryPolicy {
|
|
327
|
+
/**
|
|
328
|
+
* Simplified Access Control List configuration.
|
|
329
|
+
*
|
|
330
|
+
* Aligned with Open Memory Object (OMO) standard. See:
|
|
331
|
+
* https://github.com/anthropics/open-memory-object
|
|
332
|
+
*
|
|
333
|
+
* **Supported Entity Prefixes:**
|
|
334
|
+
*
|
|
335
|
+
* | Prefix | Description | Validation |
|
|
336
|
+
* | ---------------- | --------------------- | ------------------------------------ |
|
|
337
|
+
* | `user:` | Internal Papr user ID | Validated against Parse users |
|
|
338
|
+
* | `external_user:` | Your app's user ID | Not validated (your responsibility) |
|
|
339
|
+
* | `organization:` | Organization ID | Validated against your organizations |
|
|
340
|
+
* | `namespace:` | Namespace ID | Validated against your namespaces |
|
|
341
|
+
* | `workspace:` | Workspace ID | Validated against your workspaces |
|
|
342
|
+
* | `role:` | Parse role ID | Validated against your roles |
|
|
343
|
+
*
|
|
344
|
+
* **Examples:**
|
|
345
|
+
*
|
|
346
|
+
* ```python
|
|
347
|
+
* acl = ACLConfig(
|
|
348
|
+
* read=["external_user:alice_123", "organization:org_acme"],
|
|
349
|
+
* write=["external_user:alice_123"]
|
|
350
|
+
* )
|
|
351
|
+
* ```
|
|
352
|
+
*
|
|
353
|
+
* **Validation Rules:**
|
|
354
|
+
*
|
|
355
|
+
* - Internal entities (user, organization, namespace, workspace, role) are
|
|
356
|
+
* validated
|
|
357
|
+
* - External entities (external_user) are NOT validated - your app is responsible
|
|
358
|
+
* - Invalid internal entities will return an error
|
|
359
|
+
* - Unprefixed values default to `external_user:` for backwards compatibility
|
|
360
|
+
*/
|
|
361
|
+
acl?: ACLConfig | null;
|
|
362
|
+
/**
|
|
363
|
+
* How the data owner allowed this memory to be stored/used. 'explicit': User
|
|
364
|
+
* explicitly agreed. 'implicit': Inferred from context (default). 'terms': Covered
|
|
365
|
+
* by Terms of Service. 'none': No consent - graph extraction will be SKIPPED.
|
|
366
|
+
*/
|
|
367
|
+
consent?: 'explicit' | 'implicit' | 'terms' | 'none';
|
|
368
|
+
/**
|
|
369
|
+
* Rules for how LLM-extracted edges/relationships should be created/handled. Used
|
|
370
|
+
* in 'auto' mode when present. Controls: - create: 'auto' (create target if not
|
|
371
|
+
* found) or 'never' (controlled vocabulary) - search: How to find existing target
|
|
372
|
+
* nodes - set: Edge property values (exact or auto-extracted) -
|
|
373
|
+
* source_type/target_type: Filter by connected node types Example: {edge_type:
|
|
374
|
+
* 'MITIGATES', create: 'never', search: {properties: ['name']}}
|
|
375
|
+
*/
|
|
376
|
+
edge_constraints?: Array<EdgeConstraintInput> | null;
|
|
377
|
+
/**
|
|
378
|
+
* How to generate graph from this memory. 'auto': LLM extracts entities freely.
|
|
379
|
+
* 'manual': You provide exact nodes (no LLM). Note: 'structured' is accepted as
|
|
380
|
+
* deprecated alias for 'manual'.
|
|
381
|
+
*/
|
|
382
|
+
mode?: 'auto' | 'manual';
|
|
383
|
+
/**
|
|
384
|
+
* Rules for how LLM-extracted nodes should be created/updated. Used in 'auto' mode
|
|
385
|
+
* when present. Controls creation policy, property forcing, and merge behavior.
|
|
386
|
+
*/
|
|
387
|
+
node_constraints?: Array<NodeConstraintInput> | null;
|
|
388
|
+
/**
|
|
389
|
+
* For manual mode: Exact nodes to create (no LLM extraction). Required when
|
|
390
|
+
* mode='manual'. Each node needs id, type, and properties.
|
|
391
|
+
*/
|
|
392
|
+
nodes?: Array<NodeSpec> | null;
|
|
393
|
+
/**
|
|
394
|
+
* Relationships between nodes. Supports special placeholders:
|
|
395
|
+
* '$this' = the Memory node being created, '$previous' = the user's most recent
|
|
396
|
+
* memory. Examples: {source: '$this', target: '$previous', type: 'FOLLOWS'} links
|
|
397
|
+
* to previous memory. {source: '$this', target: 'mem_abc', type: 'REFERENCES'}
|
|
398
|
+
* links to specific memory.
|
|
399
|
+
*/
|
|
400
|
+
relationships?: Array<RelationshipSpec> | null;
|
|
401
|
+
/**
|
|
402
|
+
* Safety assessment for this memory. 'none': Safe content (default). 'sensitive':
|
|
403
|
+
* Contains PII or sensitive info. 'flagged': Requires review - ACL will be
|
|
404
|
+
* restricted to owner only.
|
|
405
|
+
*/
|
|
406
|
+
risk?: 'none' | 'sensitive' | 'flagged';
|
|
407
|
+
/**
|
|
408
|
+
* Reference a UserGraphSchema by ID. The schema's memory_policy (if defined) will
|
|
409
|
+
* be used as defaults, with this request's settings taking precedence.
|
|
410
|
+
*/
|
|
411
|
+
schema_id?: string | null;
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Policy for how nodes of a specific type should be handled.
|
|
415
|
+
*
|
|
416
|
+
* Used in two places:
|
|
417
|
+
*
|
|
418
|
+
* 1. **Schema level**: Inside `UserNodeType.constraint` - `node_type` is implicit
|
|
419
|
+
* from parent
|
|
420
|
+
* 2. **Memory level**: In `memory_policy.node_constraints[]` - `node_type` is
|
|
421
|
+
* required
|
|
422
|
+
*
|
|
423
|
+
* Node constraints allow developers to control:
|
|
424
|
+
*
|
|
425
|
+
* - Which node types can be created vs. linked
|
|
426
|
+
* - How to find/select existing nodes (via `search`)
|
|
427
|
+
* - What property values to set (exact or auto-extracted)
|
|
428
|
+
* - When to apply the constraint (conditional with logical operators)
|
|
429
|
+
*
|
|
430
|
+
* **The `search` field** handles node selection:
|
|
431
|
+
*
|
|
432
|
+
* - Uses PropertyMatch list to define unique identifiers and matching strategy
|
|
433
|
+
* - Example:
|
|
434
|
+
* `{"properties": [{"name": "id", "mode": "exact"}, {"name": "title", "mode": "semantic"}]}`
|
|
435
|
+
* - For direct selection, use PropertyMatch with value:
|
|
436
|
+
* `{"name": "id", "mode": "exact", "value": "proj_123"}`
|
|
437
|
+
*
|
|
438
|
+
* **The `set` field** controls property values:
|
|
439
|
+
*
|
|
440
|
+
* - Exact value: `{"status": "done"}` - sets exact value
|
|
441
|
+
* - Auto-extract: `{"status": {"mode": "auto"}}` - LLM extracts from content
|
|
442
|
+
*
|
|
443
|
+
* **The `when` field** supports logical operators:
|
|
444
|
+
*
|
|
445
|
+
* - Simple: `{"priority": "high"}`
|
|
446
|
+
* - AND: `{"_and": [{"priority": "high"}, {"status": "active"}]}`
|
|
447
|
+
* - OR: `{"_or": [{"status": "active"}, {"status": "pending"}]}`
|
|
448
|
+
* - NOT: `{"_not": {"status": "completed"}}`
|
|
449
|
+
* - Complex:
|
|
450
|
+
* `{"_and": [{"priority": "high"}, {"_or": [{"status": "active"}, {"urgent": true}]}]}`
|
|
451
|
+
*/
|
|
452
|
+
export interface NodeConstraintInput {
|
|
453
|
+
/**
|
|
454
|
+
* 'upsert': Create if not found via search (default). 'lookup': Only link to
|
|
455
|
+
* existing nodes (controlled vocabulary). Deprecated aliases: 'auto' -> 'upsert',
|
|
456
|
+
* 'never' -> 'lookup'.
|
|
457
|
+
*/
|
|
458
|
+
create?: 'upsert' | 'lookup' | 'auto' | 'never';
|
|
459
|
+
/**
|
|
460
|
+
* DEPRECATED: Use create='lookup' instead. Shorthand for create='lookup'. When
|
|
461
|
+
* True, only links to existing nodes (controlled vocabulary). Equivalent to
|
|
462
|
+
* @lookup decorator in schema definitions.
|
|
463
|
+
*/
|
|
464
|
+
link_only?: boolean;
|
|
465
|
+
/**
|
|
466
|
+
* Node type this constraint applies to (e.g., 'Task', 'Project', 'Person').
|
|
467
|
+
* Optional at schema level (implicit from parent UserNodeType), required at memory
|
|
468
|
+
* level (in memory_policy.node_constraints).
|
|
469
|
+
*/
|
|
470
|
+
node_type?: string | null;
|
|
471
|
+
/**
|
|
472
|
+
* Explicit behavior when no match found via search. 'create': create new node
|
|
473
|
+
* (same as upsert). 'ignore': skip node creation (same as lookup). 'error': raise
|
|
474
|
+
* error if node not found. If specified, overrides 'create' field.
|
|
475
|
+
*/
|
|
476
|
+
on_miss?: 'create' | 'ignore' | 'error' | null;
|
|
477
|
+
/**
|
|
478
|
+
* Configuration for finding/selecting existing nodes.
|
|
479
|
+
*
|
|
480
|
+
* Defines which properties to match on and how, in priority order. The first
|
|
481
|
+
* matching property wins.
|
|
482
|
+
*
|
|
483
|
+
* **String Shorthand** (simple cases - converts to exact match):
|
|
484
|
+
* SearchConfig(properties=["id", "email"]) # Equivalent to:
|
|
485
|
+
* SearchConfig(properties=[PropertyMatch.exact("id"),
|
|
486
|
+
* PropertyMatch.exact("email")])
|
|
487
|
+
*
|
|
488
|
+
* **Mixed Form** (combine strings and PropertyMatch): SearchConfig(properties=[
|
|
489
|
+
* "id", # String -> exact match PropertyMatch.semantic("title", 0.9) # Full
|
|
490
|
+
* control ])
|
|
491
|
+
*
|
|
492
|
+
* **Full Form** (maximum control): SearchConfig(properties=[
|
|
493
|
+
* PropertyMatch(name="id", mode="exact"), PropertyMatch(name="title",
|
|
494
|
+
* mode="semantic", threshold=0.85) ])
|
|
495
|
+
*
|
|
496
|
+
* **To select a specific node by ID**:
|
|
497
|
+
* SearchConfig(properties=[PropertyMatch.exact("id", "TASK-123")])
|
|
498
|
+
*/
|
|
499
|
+
search?: SearchConfigInput | null;
|
|
500
|
+
/**
|
|
501
|
+
* Set property values on nodes. Supports: 1. Exact value: {'status': 'done'} -
|
|
502
|
+
* sets exact value. 2. Auto-extract: {'status': {'mode': 'auto'}} - LLM extracts
|
|
503
|
+
* from content. 3. Text mode: {'summary': {'mode': 'auto', 'text_mode':
|
|
504
|
+
* 'merge'}} - controls text updates. For text properties, text_mode can be
|
|
505
|
+
* 'replace', 'append', or 'merge'.
|
|
506
|
+
*/
|
|
507
|
+
set?: {
|
|
508
|
+
[key: string]: string | number | boolean | Array<unknown> | {
|
|
509
|
+
[key: string]: unknown;
|
|
510
|
+
} | PropertyValue;
|
|
511
|
+
} | null;
|
|
512
|
+
/**
|
|
513
|
+
* Condition for when this constraint applies. Supports logical operators: '\_and',
|
|
514
|
+
* '\_or', '\_not'. Examples: Simple: {'priority': 'high'} - matches when priority
|
|
515
|
+
* equals 'high'. AND: {'\_and': [{'priority': 'high'}, {'status': 'active'}]} -
|
|
516
|
+
* all must match. OR: {'\_or': [{'status': 'active'}, {'status': 'pending'}]} -
|
|
517
|
+
* any must match. NOT: {'\_not': {'status': 'completed'}} - negation. Complex:
|
|
518
|
+
* {'\_and': [{'priority': 'high'}, {'\_or': [{'status': 'active'}, {'urgent':
|
|
519
|
+
* true}]}]}
|
|
520
|
+
*/
|
|
521
|
+
when?: {
|
|
522
|
+
[key: string]: unknown;
|
|
523
|
+
} | null;
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Specification for a node in manual mode.
|
|
527
|
+
*
|
|
528
|
+
* Used when mode='manual' to define exact nodes to create.
|
|
529
|
+
*/
|
|
530
|
+
export interface NodeSpec {
|
|
531
|
+
/**
|
|
532
|
+
* Unique identifier for this node
|
|
533
|
+
*/
|
|
534
|
+
id: string;
|
|
535
|
+
/**
|
|
536
|
+
* Node type/label (e.g., 'Transaction', 'Product', 'Person')
|
|
537
|
+
*/
|
|
538
|
+
type: string;
|
|
539
|
+
/**
|
|
540
|
+
* Properties for this node
|
|
541
|
+
*/
|
|
542
|
+
properties?: {
|
|
543
|
+
[key: string]: unknown;
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Configuration for a property value in NodeConstraint.set.
|
|
548
|
+
*
|
|
549
|
+
* Supports two modes:
|
|
550
|
+
*
|
|
551
|
+
* 1. Exact value: Just pass the value directly (e.g., "done", 123, True)
|
|
552
|
+
* 2. Auto-extract: {"mode": "auto"} - LLM extracts from memory content
|
|
553
|
+
*
|
|
554
|
+
* For text properties, use text_mode to control how updates are applied.
|
|
555
|
+
*/
|
|
556
|
+
export interface PropertyValue {
|
|
557
|
+
/**
|
|
558
|
+
* 'auto': LLM extracts value from memory content.
|
|
559
|
+
*/
|
|
560
|
+
mode?: 'auto';
|
|
561
|
+
/**
|
|
562
|
+
* For text properties: 'replace' (overwrite), 'append' (add to), 'merge' (LLM
|
|
563
|
+
* combines existing + new).
|
|
564
|
+
*/
|
|
565
|
+
text_mode?: 'replace' | 'append' | 'merge';
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Specification for a relationship in manual mode.
|
|
569
|
+
*
|
|
570
|
+
* Used when mode='manual' to define exact relationships between nodes.
|
|
571
|
+
*/
|
|
572
|
+
export interface RelationshipSpec {
|
|
573
|
+
/**
|
|
574
|
+
* ID of the source node
|
|
575
|
+
*/
|
|
576
|
+
source: string;
|
|
577
|
+
/**
|
|
578
|
+
* ID of the target node
|
|
579
|
+
*/
|
|
580
|
+
target: string;
|
|
581
|
+
/**
|
|
582
|
+
* Relationship type (e.g., 'PURCHASED', 'WORKS_AT', 'ASSIGNED_TO')
|
|
583
|
+
*/
|
|
584
|
+
type: string;
|
|
585
|
+
/**
|
|
586
|
+
* Optional properties for this relationship
|
|
587
|
+
*/
|
|
588
|
+
properties?: {
|
|
589
|
+
[key: string]: unknown;
|
|
590
|
+
} | null;
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* Configuration for finding/selecting existing nodes.
|
|
594
|
+
*
|
|
595
|
+
* Defines which properties to match on and how, in priority order. The first
|
|
596
|
+
* matching property wins.
|
|
597
|
+
*
|
|
598
|
+
* **String Shorthand** (simple cases - converts to exact match):
|
|
599
|
+
* SearchConfig(properties=["id", "email"]) # Equivalent to:
|
|
600
|
+
* SearchConfig(properties=[PropertyMatch.exact("id"),
|
|
601
|
+
* PropertyMatch.exact("email")])
|
|
602
|
+
*
|
|
603
|
+
* **Mixed Form** (combine strings and PropertyMatch): SearchConfig(properties=[
|
|
604
|
+
* "id", # String -> exact match PropertyMatch.semantic("title", 0.9) # Full
|
|
605
|
+
* control ])
|
|
606
|
+
*
|
|
607
|
+
* **Full Form** (maximum control): SearchConfig(properties=[
|
|
608
|
+
* PropertyMatch(name="id", mode="exact"), PropertyMatch(name="title",
|
|
609
|
+
* mode="semantic", threshold=0.85) ])
|
|
610
|
+
*
|
|
611
|
+
* **To select a specific node by ID**:
|
|
612
|
+
* SearchConfig(properties=[PropertyMatch.exact("id", "TASK-123")])
|
|
613
|
+
*/
|
|
614
|
+
export interface SearchConfigInput {
|
|
615
|
+
/**
|
|
616
|
+
* Default search mode when property doesn't specify one. 'semantic' (vector
|
|
617
|
+
* similarity), 'exact' (property match), 'fuzzy' (partial match).
|
|
618
|
+
*/
|
|
619
|
+
mode?: 'semantic' | 'exact' | 'fuzzy';
|
|
620
|
+
/**
|
|
621
|
+
* Properties to match on, in priority order (first match wins). Accepts strings
|
|
622
|
+
* (converted to exact match) or PropertyMatch objects. Use PropertyMatch with
|
|
623
|
+
* 'value' field for specific node selection.
|
|
624
|
+
*/
|
|
625
|
+
properties?: Array<SearchConfigInput.Property> | null;
|
|
626
|
+
/**
|
|
627
|
+
* Default similarity threshold for semantic/fuzzy matching (0.0-1.0). Used when
|
|
628
|
+
* property doesn't specify its own threshold.
|
|
629
|
+
*/
|
|
630
|
+
threshold?: number;
|
|
631
|
+
/**
|
|
632
|
+
* Search for nodes via their relationships. Example: Find tasks assigned to a
|
|
633
|
+
* specific person. Each RelationshipMatch specifies edge_type, target_type, and
|
|
634
|
+
* target_search. Multiple relationship matches are ANDed together.
|
|
635
|
+
*/
|
|
636
|
+
via_relationship?: Array<unknown> | null;
|
|
637
|
+
}
|
|
638
|
+
export declare namespace SearchConfigInput {
|
|
639
|
+
/**
|
|
640
|
+
* Property matching configuration.
|
|
641
|
+
*
|
|
642
|
+
* Defines which property to match on and how. When listed in search.properties,
|
|
643
|
+
* this property becomes a unique identifier.
|
|
644
|
+
*
|
|
645
|
+
* **Shorthand Helpers** (recommended for common cases):
|
|
646
|
+
* PropertyMatch.exact("id") # Exact match on id PropertyMatch.exact("id",
|
|
647
|
+
* "TASK-123") # Exact match with specific value PropertyMatch.semantic("title") #
|
|
648
|
+
* Semantic match with default threshold PropertyMatch.semantic("title", 0.9) #
|
|
649
|
+
* Semantic match with custom threshold PropertyMatch.semantic("title",
|
|
650
|
+
* value="bug") # Semantic search for "bug" PropertyMatch.fuzzy("name", 0.8) #
|
|
651
|
+
* Fuzzy match
|
|
652
|
+
*
|
|
653
|
+
* **Full Form** (when you need all options): PropertyMatch(name="title",
|
|
654
|
+
* mode="semantic", threshold=0.9, value="auth bug")
|
|
655
|
+
*
|
|
656
|
+
* **String Shorthand** (in SearchConfig.properties): properties=["id", "email"] #
|
|
657
|
+
* Equivalent to [PropertyMatch.exact("id"), PropertyMatch.exact("email")]
|
|
658
|
+
*/
|
|
659
|
+
interface Property {
|
|
660
|
+
/**
|
|
661
|
+
* Property name to match on (e.g., 'id', 'email', 'title')
|
|
662
|
+
*/
|
|
663
|
+
name: string;
|
|
664
|
+
/**
|
|
665
|
+
* Matching mode: 'exact' (string match), 'semantic' (embedding similarity),
|
|
666
|
+
* 'fuzzy' (Levenshtein distance)
|
|
667
|
+
*/
|
|
668
|
+
mode?: 'semantic' | 'exact' | 'fuzzy';
|
|
669
|
+
/**
|
|
670
|
+
* Similarity threshold for semantic/fuzzy modes (0.0-1.0). Ignored for exact mode.
|
|
671
|
+
*/
|
|
672
|
+
threshold?: number;
|
|
673
|
+
/**
|
|
674
|
+
* Runtime value override. If set, use this value for matching instead of
|
|
675
|
+
* extracting from content. Useful for memory-level overrides when you know the
|
|
676
|
+
* exact value to search for.
|
|
677
|
+
*/
|
|
678
|
+
value?: unknown;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
10
681
|
//# sourceMappingURL=shared.d.mts.map
|