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