@memoryintelligence/sdk 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/README.md +691 -0
- package/dist/index.d.mts +953 -0
- package/dist/index.d.ts +953 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +27 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +63 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,953 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enumerations for Memory Intelligence SDK
|
|
3
|
+
*
|
|
4
|
+
* These enums match the Python SDK exactly to ensure API compatibility.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Governance scope for memory isolation.
|
|
8
|
+
* Scopes are cryptographic boundaries—data in one scope is
|
|
9
|
+
* technically inaccessible from another.
|
|
10
|
+
*/
|
|
11
|
+
declare enum Scope {
|
|
12
|
+
USER = "user",
|
|
13
|
+
CLIENT = "client",
|
|
14
|
+
PROJECT = "project",
|
|
15
|
+
TEAM = "team",
|
|
16
|
+
ORGANIZATION = "org",
|
|
17
|
+
ALL = "all"
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* What to retain after processing.
|
|
21
|
+
* Privacy by design: MEANING_ONLY is the default.
|
|
22
|
+
*/
|
|
23
|
+
declare enum RetentionPolicy {
|
|
24
|
+
MEANING_ONLY = "meaning_only",
|
|
25
|
+
FULL = "full",
|
|
26
|
+
SUMMARY_ONLY = "summary_only"
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* How to handle detected PII.
|
|
30
|
+
*/
|
|
31
|
+
declare enum PIIHandling {
|
|
32
|
+
DETECT_ONLY = "detect_only",
|
|
33
|
+
EXTRACT_AND_REDACT = "extract_and_redact",
|
|
34
|
+
HASH = "hash",
|
|
35
|
+
REJECT = "reject"
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Provenance tracking level.
|
|
39
|
+
*/
|
|
40
|
+
declare enum ProvenanceMode {
|
|
41
|
+
STANDARD = "standard",
|
|
42
|
+
AUTHORSHIP = "authorship",
|
|
43
|
+
AUDIT = "audit"
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Level of explanation to include in responses.
|
|
47
|
+
*/
|
|
48
|
+
declare enum ExplainLevel {
|
|
49
|
+
NONE = "none",
|
|
50
|
+
HUMAN = "human",
|
|
51
|
+
AUDIT = "audit",
|
|
52
|
+
FULL = "full"
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Type definitions for Memory Intelligence SDK
|
|
57
|
+
*
|
|
58
|
+
* These types match the Python SDK models to ensure API compatibility.
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Entity extracted from content.
|
|
63
|
+
*/
|
|
64
|
+
interface Entity {
|
|
65
|
+
text: string;
|
|
66
|
+
type: string;
|
|
67
|
+
confidence?: number;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Topic extracted from content.
|
|
71
|
+
*/
|
|
72
|
+
interface Topic {
|
|
73
|
+
text: string;
|
|
74
|
+
relevance: number;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Embedding vector representation.
|
|
78
|
+
*/
|
|
79
|
+
interface Embedding {
|
|
80
|
+
vector: number[];
|
|
81
|
+
model: string;
|
|
82
|
+
dimensions: number;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Provenance information for a memory object.
|
|
86
|
+
*/
|
|
87
|
+
interface Provenance {
|
|
88
|
+
hash: string;
|
|
89
|
+
timestamp: string;
|
|
90
|
+
source?: string;
|
|
91
|
+
lineage?: string[];
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Meaning Object - Core data structure.
|
|
95
|
+
* Raw content is discarded by default (retention_policy=MEANING_ONLY).
|
|
96
|
+
*/
|
|
97
|
+
interface MeaningObject {
|
|
98
|
+
umoId: string;
|
|
99
|
+
userUlid: string;
|
|
100
|
+
orgUlid?: string;
|
|
101
|
+
entities: Entity[];
|
|
102
|
+
topics: Topic[];
|
|
103
|
+
embedding: Embedding;
|
|
104
|
+
summary?: string;
|
|
105
|
+
provenance: Provenance;
|
|
106
|
+
createdAt: string;
|
|
107
|
+
scope: Scope;
|
|
108
|
+
scopeId?: string;
|
|
109
|
+
metadata?: Record<string, unknown>;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Search result containing a meaning object and relevance score.
|
|
113
|
+
*/
|
|
114
|
+
interface SearchResult {
|
|
115
|
+
umo: MeaningObject;
|
|
116
|
+
score: number;
|
|
117
|
+
explain?: Explanation;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Response from search endpoint.
|
|
121
|
+
*/
|
|
122
|
+
interface SearchResponse {
|
|
123
|
+
results: SearchResult[];
|
|
124
|
+
total: number;
|
|
125
|
+
query: string;
|
|
126
|
+
explain?: Explanation;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Match result comparing two meaning objects.
|
|
130
|
+
*/
|
|
131
|
+
interface MatchResult {
|
|
132
|
+
umoId1: string;
|
|
133
|
+
umoId2: string;
|
|
134
|
+
score: number;
|
|
135
|
+
semantic: number;
|
|
136
|
+
temporal?: number;
|
|
137
|
+
graph?: number;
|
|
138
|
+
explain?: Explanation;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Explanation of results (human + audit).
|
|
142
|
+
*/
|
|
143
|
+
interface Explanation {
|
|
144
|
+
human?: {
|
|
145
|
+
summary: string;
|
|
146
|
+
keyReasons: string[];
|
|
147
|
+
impact?: string;
|
|
148
|
+
};
|
|
149
|
+
audit?: {
|
|
150
|
+
semantic: number;
|
|
151
|
+
temporal?: number;
|
|
152
|
+
graph?: number;
|
|
153
|
+
entities?: number;
|
|
154
|
+
drift?: number;
|
|
155
|
+
formula: string;
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Delete result response.
|
|
160
|
+
*/
|
|
161
|
+
interface DeleteResult {
|
|
162
|
+
deleted: number;
|
|
163
|
+
scope: Scope;
|
|
164
|
+
userUlid?: string;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Batch operation result for a single item.
|
|
168
|
+
*/
|
|
169
|
+
interface BatchItemResult {
|
|
170
|
+
index: number;
|
|
171
|
+
success: boolean;
|
|
172
|
+
umo?: MeaningObject;
|
|
173
|
+
error?: string;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Batch operation response.
|
|
177
|
+
*/
|
|
178
|
+
interface BatchResult {
|
|
179
|
+
results: BatchItemResult[];
|
|
180
|
+
totalProcessed: number;
|
|
181
|
+
totalSucceeded: number;
|
|
182
|
+
totalFailed: number;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Rate limit information from response headers.
|
|
186
|
+
*/
|
|
187
|
+
interface RateLimit {
|
|
188
|
+
limit?: number;
|
|
189
|
+
remaining?: number;
|
|
190
|
+
reset?: number;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* HTTP response wrapper.
|
|
194
|
+
*/
|
|
195
|
+
interface SDKResponse<T> {
|
|
196
|
+
data: T;
|
|
197
|
+
rateLimit?: RateLimit;
|
|
198
|
+
requestId?: string;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* HTTP client for Memory Intelligence SDK
|
|
203
|
+
*
|
|
204
|
+
* Provides fetch wrapper with:
|
|
205
|
+
* - Automatic retries
|
|
206
|
+
* - Rate limit handling
|
|
207
|
+
* - Error mapping
|
|
208
|
+
* - Request ID tracking
|
|
209
|
+
*/
|
|
210
|
+
|
|
211
|
+
interface HTTPClientConfig {
|
|
212
|
+
apiKey: string;
|
|
213
|
+
baseUrl: string;
|
|
214
|
+
timeout?: number;
|
|
215
|
+
maxRetries?: number;
|
|
216
|
+
}
|
|
217
|
+
interface RequestOptions {
|
|
218
|
+
method?: string;
|
|
219
|
+
body?: unknown;
|
|
220
|
+
signal?: AbortSignal;
|
|
221
|
+
headers?: Record<string, string>;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* HTTP client with retry logic and error handling.
|
|
225
|
+
*/
|
|
226
|
+
declare class HTTPClient {
|
|
227
|
+
private apiKey;
|
|
228
|
+
private baseUrl;
|
|
229
|
+
private timeout;
|
|
230
|
+
private maxRetries;
|
|
231
|
+
constructor(config: HTTPClientConfig);
|
|
232
|
+
/**
|
|
233
|
+
* Make HTTP request with retry logic.
|
|
234
|
+
*/
|
|
235
|
+
request<T>(endpoint: string, options?: RequestOptions): Promise<SDKResponse<T>>;
|
|
236
|
+
/**
|
|
237
|
+
* Make single HTTP request.
|
|
238
|
+
*/
|
|
239
|
+
private makeRequest;
|
|
240
|
+
/**
|
|
241
|
+
* Extract rate limit information from response headers.
|
|
242
|
+
*/
|
|
243
|
+
private extractRateLimit;
|
|
244
|
+
/**
|
|
245
|
+
* Handle error responses from API.
|
|
246
|
+
*/
|
|
247
|
+
private handleErrorResponse;
|
|
248
|
+
/**
|
|
249
|
+
* Sleep utility for retry backoff.
|
|
250
|
+
*/
|
|
251
|
+
private sleep;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* WebSocket connection manager for Memory Intelligence SDK
|
|
256
|
+
*
|
|
257
|
+
* Handles persistent connections, auto-reconnect, and subscription routing.
|
|
258
|
+
*/
|
|
259
|
+
interface WebSocketConfig {
|
|
260
|
+
url: string;
|
|
261
|
+
apiKey: string;
|
|
262
|
+
orgUlid?: string;
|
|
263
|
+
reconnectDelay?: number;
|
|
264
|
+
maxReconnectAttempts?: number;
|
|
265
|
+
pingInterval?: number;
|
|
266
|
+
}
|
|
267
|
+
interface SubscriptionMessage {
|
|
268
|
+
type: 'subscribe' | 'unsubscribe';
|
|
269
|
+
subscription_id: string;
|
|
270
|
+
stream: string;
|
|
271
|
+
filters?: Record<string, any>;
|
|
272
|
+
function_name?: string;
|
|
273
|
+
parameters?: Record<string, any>;
|
|
274
|
+
}
|
|
275
|
+
interface ServerMessage {
|
|
276
|
+
type: string;
|
|
277
|
+
subscription_id?: string;
|
|
278
|
+
[key: string]: any;
|
|
279
|
+
}
|
|
280
|
+
type MessageHandler = (message: ServerMessage) => void;
|
|
281
|
+
/**
|
|
282
|
+
* WebSocket connection manager with auto-reconnect and subscription routing.
|
|
283
|
+
*/
|
|
284
|
+
declare class WebSocketManager {
|
|
285
|
+
private ws;
|
|
286
|
+
private config;
|
|
287
|
+
private reconnectAttempts;
|
|
288
|
+
private reconnectTimeout;
|
|
289
|
+
private pingIntervalId;
|
|
290
|
+
private subscriptions;
|
|
291
|
+
private connectionPromise;
|
|
292
|
+
private isConnecting;
|
|
293
|
+
private isClosed;
|
|
294
|
+
private onConnectHandlers;
|
|
295
|
+
private onDisconnectHandlers;
|
|
296
|
+
private onErrorHandlers;
|
|
297
|
+
constructor(config: WebSocketConfig);
|
|
298
|
+
/**
|
|
299
|
+
* Connect to WebSocket server.
|
|
300
|
+
*/
|
|
301
|
+
connect(): Promise<void>;
|
|
302
|
+
/**
|
|
303
|
+
* Disconnect from WebSocket server.
|
|
304
|
+
*/
|
|
305
|
+
disconnect(): void;
|
|
306
|
+
/**
|
|
307
|
+
* Subscribe to a stream.
|
|
308
|
+
*/
|
|
309
|
+
subscribe(message: SubscriptionMessage, handler: MessageHandler): Promise<void>;
|
|
310
|
+
/**
|
|
311
|
+
* Unsubscribe from a stream.
|
|
312
|
+
*/
|
|
313
|
+
unsubscribe(subscriptionId: string): void;
|
|
314
|
+
/**
|
|
315
|
+
* Register connect event handler.
|
|
316
|
+
*/
|
|
317
|
+
onConnect(handler: () => void): void;
|
|
318
|
+
/**
|
|
319
|
+
* Register disconnect event handler.
|
|
320
|
+
*/
|
|
321
|
+
onDisconnect(handler: () => void): void;
|
|
322
|
+
/**
|
|
323
|
+
* Register error event handler.
|
|
324
|
+
*/
|
|
325
|
+
onError(handler: (error: Error) => void): void;
|
|
326
|
+
/**
|
|
327
|
+
* Check if connected.
|
|
328
|
+
*/
|
|
329
|
+
isConnected(): boolean;
|
|
330
|
+
/**
|
|
331
|
+
* Send message to server.
|
|
332
|
+
*/
|
|
333
|
+
private send;
|
|
334
|
+
/**
|
|
335
|
+
* Handle incoming message from server.
|
|
336
|
+
*/
|
|
337
|
+
private handleMessage;
|
|
338
|
+
/**
|
|
339
|
+
* Start ping interval to keep connection alive.
|
|
340
|
+
*/
|
|
341
|
+
private startPingInterval;
|
|
342
|
+
/**
|
|
343
|
+
* Stop ping interval.
|
|
344
|
+
*/
|
|
345
|
+
private stopPingInterval;
|
|
346
|
+
/**
|
|
347
|
+
* Attempt to reconnect with exponential backoff.
|
|
348
|
+
*/
|
|
349
|
+
private attemptReconnect;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Base subscription class for all WebSocket subscriptions.
|
|
354
|
+
*/
|
|
355
|
+
|
|
356
|
+
type EventHandler<T = any> = (data: T) => void;
|
|
357
|
+
/**
|
|
358
|
+
* Base class for WebSocket subscriptions.
|
|
359
|
+
*/
|
|
360
|
+
declare abstract class BaseSubscription<T = any> {
|
|
361
|
+
protected subscriptionId: string;
|
|
362
|
+
protected ws: WebSocketManager;
|
|
363
|
+
protected eventHandlers: Map<string, EventHandler<T>[]>;
|
|
364
|
+
protected isActive: boolean;
|
|
365
|
+
constructor(ws: WebSocketManager);
|
|
366
|
+
/**
|
|
367
|
+
* Start the subscription.
|
|
368
|
+
*/
|
|
369
|
+
abstract start(): Promise<void>;
|
|
370
|
+
/**
|
|
371
|
+
* Stop the subscription.
|
|
372
|
+
*/
|
|
373
|
+
stop(): void;
|
|
374
|
+
/**
|
|
375
|
+
* Register an event handler.
|
|
376
|
+
*/
|
|
377
|
+
on(event: string, handler: EventHandler<T>): this;
|
|
378
|
+
/**
|
|
379
|
+
* Remove an event handler.
|
|
380
|
+
*/
|
|
381
|
+
off(event: string, handler: EventHandler<T>): this;
|
|
382
|
+
/**
|
|
383
|
+
* Emit an event to all registered handlers.
|
|
384
|
+
*/
|
|
385
|
+
protected emit(event: string, data: T): void;
|
|
386
|
+
/**
|
|
387
|
+
* Handle incoming message from server.
|
|
388
|
+
*/
|
|
389
|
+
protected abstract handleMessage(message: ServerMessage): void;
|
|
390
|
+
/**
|
|
391
|
+
* Generate unique subscription ID.
|
|
392
|
+
*/
|
|
393
|
+
protected generateSubscriptionId(): string;
|
|
394
|
+
/**
|
|
395
|
+
* Check if subscription is active.
|
|
396
|
+
*/
|
|
397
|
+
isSubscribed(): boolean;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Drift subscription for real-time entity meaning change notifications.
|
|
402
|
+
*/
|
|
403
|
+
|
|
404
|
+
interface DriftUpdate {
|
|
405
|
+
entityUlid: string;
|
|
406
|
+
canonicalName: string;
|
|
407
|
+
driftEpoch: number;
|
|
408
|
+
driftMagnitude: number;
|
|
409
|
+
meaningStable: boolean;
|
|
410
|
+
updatedAt: string;
|
|
411
|
+
explainHuman: {
|
|
412
|
+
driftSummary: string;
|
|
413
|
+
whatChanged: {
|
|
414
|
+
summary: string;
|
|
415
|
+
changes: string[];
|
|
416
|
+
};
|
|
417
|
+
impactOnResults: string;
|
|
418
|
+
confidenceAssessment: string;
|
|
419
|
+
};
|
|
420
|
+
signals: Array<{
|
|
421
|
+
signal: string;
|
|
422
|
+
magnitude: number;
|
|
423
|
+
isAnomalous: boolean;
|
|
424
|
+
}>;
|
|
425
|
+
}
|
|
426
|
+
interface DriftSubscriptionOptions {
|
|
427
|
+
entityUlids?: string[];
|
|
428
|
+
orgUlid?: string;
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Subscription for drift updates on entities.
|
|
432
|
+
*
|
|
433
|
+
* Events:
|
|
434
|
+
* - 'update': (update: DriftUpdate) => void - New drift update received
|
|
435
|
+
* - 'connected': () => void - Subscription established
|
|
436
|
+
* - 'disconnected': () => void - Subscription closed
|
|
437
|
+
* - 'error': (error: Error) => void - Error occurred
|
|
438
|
+
*/
|
|
439
|
+
declare class DriftSubscription extends BaseSubscription<DriftUpdate> {
|
|
440
|
+
private options;
|
|
441
|
+
constructor(ws: WebSocketManager, options?: DriftSubscriptionOptions);
|
|
442
|
+
/**
|
|
443
|
+
* Start the drift subscription.
|
|
444
|
+
*/
|
|
445
|
+
start(): Promise<void>;
|
|
446
|
+
/**
|
|
447
|
+
* Handle incoming drift update message.
|
|
448
|
+
*/
|
|
449
|
+
protected handleMessage(message: ServerMessage): void;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Compute subscription for long-running operation progress and results.
|
|
454
|
+
*/
|
|
455
|
+
|
|
456
|
+
interface ComputeProgress {
|
|
457
|
+
status: 'analyzing' | 'processing' | 'finalizing';
|
|
458
|
+
progressPercent: number;
|
|
459
|
+
message: string;
|
|
460
|
+
}
|
|
461
|
+
interface ComputeResult<T = any> {
|
|
462
|
+
status: 'complete' | 'failed';
|
|
463
|
+
result?: T;
|
|
464
|
+
error?: string;
|
|
465
|
+
executionTimeMs: number;
|
|
466
|
+
explainHuman?: {
|
|
467
|
+
summary: string;
|
|
468
|
+
[key: string]: any;
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
type ComputeUpdate<T = any> = ComputeProgress | ComputeResult<T>;
|
|
472
|
+
/**
|
|
473
|
+
* Subscription for long-running compute operations.
|
|
474
|
+
*
|
|
475
|
+
* Events:
|
|
476
|
+
* - 'progress': (progress: ComputeProgress) => void - Progress update
|
|
477
|
+
* - 'result': (result: ComputeResult) => void - Final result
|
|
478
|
+
* - 'connected': () => void - Subscription established
|
|
479
|
+
* - 'disconnected': () => void - Subscription closed
|
|
480
|
+
* - 'error': (error: Error) => void - Error occurred
|
|
481
|
+
*/
|
|
482
|
+
declare class ComputeSubscription<T = any> extends BaseSubscription<ComputeUpdate<T>> {
|
|
483
|
+
private functionName;
|
|
484
|
+
private parameters;
|
|
485
|
+
constructor(ws: WebSocketManager, functionName: string, parameters?: Record<string, any>);
|
|
486
|
+
/**
|
|
487
|
+
* Start the compute subscription.
|
|
488
|
+
*/
|
|
489
|
+
start(): Promise<void>;
|
|
490
|
+
/**
|
|
491
|
+
* Handle incoming compute message.
|
|
492
|
+
*/
|
|
493
|
+
protected handleMessage(message: ServerMessage): void;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Main client for Memory Intelligence SDK
|
|
498
|
+
*
|
|
499
|
+
* Provides the MemoryClient class and UMONamespace for all memory operations.
|
|
500
|
+
*/
|
|
501
|
+
|
|
502
|
+
interface MemoryClientConfig {
|
|
503
|
+
apiKey: string;
|
|
504
|
+
baseUrl?: string;
|
|
505
|
+
wsUrl?: string;
|
|
506
|
+
userUlid?: string;
|
|
507
|
+
orgUlid?: string;
|
|
508
|
+
timeout?: number;
|
|
509
|
+
maxRetries?: number;
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* UMO Namespace - All memory operations under `mi.umo.*`
|
|
513
|
+
*/
|
|
514
|
+
declare class UMONamespace {
|
|
515
|
+
private client;
|
|
516
|
+
private http;
|
|
517
|
+
constructor(client: MemoryClient, http: HTTPClient);
|
|
518
|
+
/**
|
|
519
|
+
* Resolve user_ulid from explicit argument or client default.
|
|
520
|
+
*/
|
|
521
|
+
private resolveUserUlid;
|
|
522
|
+
/**
|
|
523
|
+
* Process content into a Meaning Object.
|
|
524
|
+
*
|
|
525
|
+
* @param content - Raw text content to process
|
|
526
|
+
* @param options - Processing options
|
|
527
|
+
* @returns Meaning Object with entities, topics, embedding
|
|
528
|
+
*/
|
|
529
|
+
process(content: string, options?: {
|
|
530
|
+
userUlid?: string;
|
|
531
|
+
retentionPolicy?: RetentionPolicy;
|
|
532
|
+
piiHandling?: PIIHandling;
|
|
533
|
+
provenanceMode?: ProvenanceMode;
|
|
534
|
+
scope?: Scope;
|
|
535
|
+
scopeId?: string;
|
|
536
|
+
source?: string;
|
|
537
|
+
metadata?: Record<string, unknown>;
|
|
538
|
+
}): Promise<MeaningObject>;
|
|
539
|
+
/**
|
|
540
|
+
* Search memories semantically.
|
|
541
|
+
*
|
|
542
|
+
* @param query - Natural language query
|
|
543
|
+
* @param options - Search options
|
|
544
|
+
* @returns Search results with relevance scores
|
|
545
|
+
*/
|
|
546
|
+
search(query: string, options?: {
|
|
547
|
+
userUlid?: string;
|
|
548
|
+
limit?: number;
|
|
549
|
+
scope?: Scope;
|
|
550
|
+
scopeId?: string;
|
|
551
|
+
explain?: ExplainLevel;
|
|
552
|
+
}): Promise<SearchResponse>;
|
|
553
|
+
/**
|
|
554
|
+
* Match two memories for relevance.
|
|
555
|
+
*
|
|
556
|
+
* @param umoId1 - First meaning object ID
|
|
557
|
+
* @param umoId2 - Second meaning object ID
|
|
558
|
+
* @param options - Match options
|
|
559
|
+
* @returns Match score and breakdown
|
|
560
|
+
*/
|
|
561
|
+
match(umoId1: string, umoId2: string, options?: {
|
|
562
|
+
explain?: ExplainLevel;
|
|
563
|
+
}): Promise<MatchResult>;
|
|
564
|
+
/**
|
|
565
|
+
* Get explanation for a memory.
|
|
566
|
+
*
|
|
567
|
+
* @param umoId - Meaning object ID
|
|
568
|
+
* @param level - Explanation detail level
|
|
569
|
+
* @returns Explanation with human and/or audit details
|
|
570
|
+
*/
|
|
571
|
+
explain(umoId: string, level?: ExplainLevel): Promise<Explanation>;
|
|
572
|
+
/**
|
|
573
|
+
* Delete memories.
|
|
574
|
+
*
|
|
575
|
+
* @param options - Deletion options
|
|
576
|
+
* @returns Number of memories deleted
|
|
577
|
+
*/
|
|
578
|
+
delete(options?: {
|
|
579
|
+
umoId?: string;
|
|
580
|
+
userUlid?: string;
|
|
581
|
+
scope?: Scope;
|
|
582
|
+
}): Promise<DeleteResult>;
|
|
583
|
+
/**
|
|
584
|
+
* Batch process multiple items.
|
|
585
|
+
*
|
|
586
|
+
* @param items - Array of items to process
|
|
587
|
+
* @returns Batch results with success/failure per item
|
|
588
|
+
*/
|
|
589
|
+
batch(items: Array<{
|
|
590
|
+
content: string;
|
|
591
|
+
userUlid?: string;
|
|
592
|
+
metadata?: Record<string, unknown>;
|
|
593
|
+
}>): Promise<BatchResult>;
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Drift Namespace - Real-time entity meaning change subscriptions
|
|
597
|
+
*/
|
|
598
|
+
declare class DriftNamespace {
|
|
599
|
+
private ws;
|
|
600
|
+
constructor(ws: WebSocketManager);
|
|
601
|
+
/**
|
|
602
|
+
* Watch for drift updates on specific entities.
|
|
603
|
+
*
|
|
604
|
+
* @param options - Subscription options (entity ULIDs, org filter)
|
|
605
|
+
* @returns DriftSubscription instance
|
|
606
|
+
*
|
|
607
|
+
* @example
|
|
608
|
+
* ```typescript
|
|
609
|
+
* const subscription = mi.drift.watch({
|
|
610
|
+
* entityUlids: ['01ARZ3NDEV5ARZ3ND']
|
|
611
|
+
* });
|
|
612
|
+
*
|
|
613
|
+
* subscription.on('update', (update) => {
|
|
614
|
+
* if (!update.meaningStable) {
|
|
615
|
+
* console.log('Meaning changed:', update.explainHuman.driftSummary);
|
|
616
|
+
* }
|
|
617
|
+
* });
|
|
618
|
+
*
|
|
619
|
+
* await subscription.start();
|
|
620
|
+
* ```
|
|
621
|
+
*/
|
|
622
|
+
watch(options?: DriftSubscriptionOptions): DriftSubscription;
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Compute Namespace - Long-running operation progress tracking
|
|
626
|
+
*/
|
|
627
|
+
declare class ComputeNamespace {
|
|
628
|
+
private ws;
|
|
629
|
+
constructor(ws: WebSocketManager);
|
|
630
|
+
/**
|
|
631
|
+
* Watch progress of a long-running compute operation.
|
|
632
|
+
*
|
|
633
|
+
* @param functionName - Name of compute function
|
|
634
|
+
* @param parameters - Function parameters
|
|
635
|
+
* @returns ComputeSubscription instance
|
|
636
|
+
*
|
|
637
|
+
* Disconnect WebSocket connections.
|
|
638
|
+
* Call this when shutting down the client.
|
|
639
|
+
*/
|
|
640
|
+
disconnect(): void;
|
|
641
|
+
/**
|
|
642
|
+
* @example
|
|
643
|
+
* ```typescript
|
|
644
|
+
* const subscription = mi.compute.watch('analyze_decision_process', {
|
|
645
|
+
* narrative_ulid: '01ARZ3NDFQ69G5FAVSV4RRFF'
|
|
646
|
+
* });
|
|
647
|
+
*
|
|
648
|
+
* subscription.on('progress', (progress) => {
|
|
649
|
+
* console.log(`${progress.progressPercent}%: ${progress.message}`);
|
|
650
|
+
* });
|
|
651
|
+
*
|
|
652
|
+
* subscription.on('result', (result) => {
|
|
653
|
+
* console.log('Complete:', result.result);
|
|
654
|
+
* });
|
|
655
|
+
*
|
|
656
|
+
* await subscription.start();
|
|
657
|
+
* ```
|
|
658
|
+
*/
|
|
659
|
+
watch<T = any>(functionName: string, parameters?: Record<string, any>): ComputeSubscription<T>;
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* Main Memory Intelligence Client
|
|
663
|
+
*
|
|
664
|
+
* Usage:
|
|
665
|
+
* ```typescript
|
|
666
|
+
* const mi = new MemoryClient({ apiKey: 'mi_sk_beta_...' });
|
|
667
|
+
*
|
|
668
|
+
* // Search
|
|
669
|
+
* const results = await mi.umo.search('project planning');
|
|
670
|
+
*
|
|
671
|
+
* // Process
|
|
672
|
+
* const umo = await mi.umo.process('Important meeting notes');
|
|
673
|
+
*
|
|
674
|
+
* // Watch drift
|
|
675
|
+
* const driftSub = mi.drift.watch({ entityUlids: ['01ARZ...'] });
|
|
676
|
+
* await driftSub.start();
|
|
677
|
+
* ```
|
|
678
|
+
*/
|
|
679
|
+
declare class MemoryClient {
|
|
680
|
+
readonly userUlid?: string;
|
|
681
|
+
readonly orgUlid?: string;
|
|
682
|
+
readonly umo: UMONamespace;
|
|
683
|
+
readonly drift: DriftNamespace;
|
|
684
|
+
readonly compute: ComputeNamespace;
|
|
685
|
+
private http;
|
|
686
|
+
private ws;
|
|
687
|
+
constructor(config: MemoryClientConfig);
|
|
688
|
+
/**
|
|
689
|
+
* Create a new client instance with a different user context.
|
|
690
|
+
* Useful for multi-user scenarios.
|
|
691
|
+
*
|
|
692
|
+
* @param userUlid - User ULID for the new context
|
|
693
|
+
* @returns New MemoryClient instance
|
|
694
|
+
*/
|
|
695
|
+
forUser(userUlid: string): MemoryClient;
|
|
696
|
+
/**
|
|
697
|
+
* Convenience alias for process (Batch 4.2)
|
|
698
|
+
*/
|
|
699
|
+
capture(content: string, userUlid?: string): Promise<MeaningObject>;
|
|
700
|
+
/**
|
|
701
|
+
* Convenience alias for search (Batch 4.2)
|
|
702
|
+
*/
|
|
703
|
+
search(query: string, limit?: number): Promise<SearchResponse>;
|
|
704
|
+
/**
|
|
705
|
+
* Convenience alias for explain (Batch 4.2)
|
|
706
|
+
*/
|
|
707
|
+
explain(umoId: string): Promise<Explanation>;
|
|
708
|
+
/**
|
|
709
|
+
* Convenience alias for delete (Batch 4.2)
|
|
710
|
+
*/
|
|
711
|
+
forget(umoId: string): Promise<DeleteResult>;
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
/**
|
|
715
|
+
* Streaming utilities for handling large datasets
|
|
716
|
+
*
|
|
717
|
+
* Provides:
|
|
718
|
+
* - Chunked response processing
|
|
719
|
+
* - Batch UMO processing
|
|
720
|
+
* - Memory-efficient iteration
|
|
721
|
+
* - Progress tracking
|
|
722
|
+
*/
|
|
723
|
+
|
|
724
|
+
interface StreamConfig {
|
|
725
|
+
/** Chunk size for batch operations */
|
|
726
|
+
chunkSize?: number;
|
|
727
|
+
/** Callback for progress updates */
|
|
728
|
+
onProgress?: (processed: number, total: number) => void;
|
|
729
|
+
/** Callback for chunk completion */
|
|
730
|
+
onChunk?: (chunk: any[], chunkIndex: number) => void;
|
|
731
|
+
/** Maximum concurrent operations */
|
|
732
|
+
concurrency?: number;
|
|
733
|
+
}
|
|
734
|
+
interface BatchProcessOptions {
|
|
735
|
+
/** Content items to process */
|
|
736
|
+
items: Array<{
|
|
737
|
+
content: string;
|
|
738
|
+
type?: string;
|
|
739
|
+
metadata?: Record<string, any>;
|
|
740
|
+
}>;
|
|
741
|
+
/** Streaming configuration */
|
|
742
|
+
config?: StreamConfig;
|
|
743
|
+
}
|
|
744
|
+
interface BatchSearchOptions {
|
|
745
|
+
/** Search queries to execute */
|
|
746
|
+
queries: string[];
|
|
747
|
+
/** Search options for each query */
|
|
748
|
+
searchOptions?: {
|
|
749
|
+
limit?: number;
|
|
750
|
+
filters?: Record<string, any>;
|
|
751
|
+
};
|
|
752
|
+
/** Streaming configuration */
|
|
753
|
+
config?: StreamConfig;
|
|
754
|
+
}
|
|
755
|
+
interface StreamIteratorOptions<T> {
|
|
756
|
+
/** Data source (array or async generator) */
|
|
757
|
+
source: T[] | AsyncGenerator<T>;
|
|
758
|
+
/** Chunk size for processing */
|
|
759
|
+
chunkSize: number;
|
|
760
|
+
/** Processing function for each chunk */
|
|
761
|
+
processor: (chunk: T[]) => Promise<void>;
|
|
762
|
+
/** Progress callback */
|
|
763
|
+
onProgress?: (processed: number) => void;
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Streaming helper for batch UMO processing
|
|
767
|
+
*/
|
|
768
|
+
declare class UMOStreamProcessor {
|
|
769
|
+
private client;
|
|
770
|
+
constructor(client: MemoryClient);
|
|
771
|
+
/**
|
|
772
|
+
* Process multiple content items in batches
|
|
773
|
+
* to avoid overwhelming the API or memory.
|
|
774
|
+
*/
|
|
775
|
+
processBatch(options: BatchProcessOptions): AsyncGenerator<MeaningObject, void, unknown>;
|
|
776
|
+
/**
|
|
777
|
+
* Process a chunk of items with concurrency control
|
|
778
|
+
*/
|
|
779
|
+
private processChunk;
|
|
780
|
+
/**
|
|
781
|
+
* Execute multiple search queries in sequence
|
|
782
|
+
*/
|
|
783
|
+
searchBatch(options: BatchSearchOptions): AsyncGenerator<{
|
|
784
|
+
query: string;
|
|
785
|
+
results: SearchResult[];
|
|
786
|
+
}, void, unknown>;
|
|
787
|
+
private sleep;
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* Generic streaming iterator for large datasets
|
|
791
|
+
*/
|
|
792
|
+
declare function streamLargeDataset<T>(options: StreamIteratorOptions<T>): AsyncGenerator<T[], void, unknown>;
|
|
793
|
+
/**
|
|
794
|
+
* Helper for processing search results in streaming fashion
|
|
795
|
+
*/
|
|
796
|
+
declare class SearchResultStream {
|
|
797
|
+
private client;
|
|
798
|
+
constructor(client: MemoryClient);
|
|
799
|
+
/**
|
|
800
|
+
* Stream search results with pagination
|
|
801
|
+
*/
|
|
802
|
+
paginate(query: string, options?: {
|
|
803
|
+
pageSize?: number;
|
|
804
|
+
maxResults?: number;
|
|
805
|
+
filters?: Record<string, any>;
|
|
806
|
+
}): AsyncGenerator<SearchResult[], void, unknown>;
|
|
807
|
+
}
|
|
808
|
+
/**
|
|
809
|
+
* Progress tracker for streaming operations
|
|
810
|
+
*/
|
|
811
|
+
declare class ProgressTracker {
|
|
812
|
+
private total;
|
|
813
|
+
private processed;
|
|
814
|
+
private startTime;
|
|
815
|
+
private onUpdate?;
|
|
816
|
+
constructor(total: number, onUpdate?: (progress: ProgressUpdate) => void);
|
|
817
|
+
update(count?: number): void;
|
|
818
|
+
getProgress(): ProgressUpdate;
|
|
819
|
+
}
|
|
820
|
+
interface ProgressUpdate {
|
|
821
|
+
processed: number;
|
|
822
|
+
total: number;
|
|
823
|
+
percentage: number;
|
|
824
|
+
elapsed: number;
|
|
825
|
+
rate: number;
|
|
826
|
+
eta?: number;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
/**
|
|
830
|
+
* React Native Compatibility Layer
|
|
831
|
+
*
|
|
832
|
+
* Ensures the SDK works correctly in React Native environments
|
|
833
|
+
* by detecting and polyfilling missing APIs.
|
|
834
|
+
*
|
|
835
|
+
* Usage:
|
|
836
|
+
* ```typescript
|
|
837
|
+
* import { checkReactNativeCompatibility, setupReactNativePolyfills } from '@memoryintelligence/sdk/react-native';
|
|
838
|
+
*
|
|
839
|
+
* // In your app entry point (App.tsx)
|
|
840
|
+
* const compatibility = checkReactNativeCompatibility();
|
|
841
|
+
* if (!compatibility.compatible) {
|
|
842
|
+
* console.warn('Missing APIs:', compatibility.missing);
|
|
843
|
+
* setupReactNativePolyfills(); // Auto-install available polyfills
|
|
844
|
+
* }
|
|
845
|
+
* ```
|
|
846
|
+
*/
|
|
847
|
+
interface CompatibilityCheck {
|
|
848
|
+
compatible: boolean;
|
|
849
|
+
missing: string[];
|
|
850
|
+
warnings: string[];
|
|
851
|
+
polyfillsAvailable: string[];
|
|
852
|
+
}
|
|
853
|
+
interface ReactNativeConfig {
|
|
854
|
+
/** Custom fetch implementation */
|
|
855
|
+
fetch?: typeof fetch;
|
|
856
|
+
/** Custom WebSocket implementation */
|
|
857
|
+
WebSocket?: typeof WebSocket;
|
|
858
|
+
/** Custom crypto implementation */
|
|
859
|
+
crypto?: any;
|
|
860
|
+
/** Custom Text encoder implementation */
|
|
861
|
+
TextEncoder?: typeof TextEncoder;
|
|
862
|
+
/** Custom Text decoder implementation */
|
|
863
|
+
TextDecoder?: typeof TextDecoder;
|
|
864
|
+
}
|
|
865
|
+
/**
|
|
866
|
+
* Check if the current environment is React Native compatible
|
|
867
|
+
*/
|
|
868
|
+
declare function checkReactNativeCompatibility(): CompatibilityCheck;
|
|
869
|
+
/**
|
|
870
|
+
* Automatically setup polyfills for React Native
|
|
871
|
+
*
|
|
872
|
+
* Note: This requires the polyfill packages to be installed:
|
|
873
|
+
* ```bash
|
|
874
|
+
* npm install whatwg-fetch react-native-get-random-values abortcontroller-polyfill text-encoding
|
|
875
|
+
* ```
|
|
876
|
+
*/
|
|
877
|
+
declare function setupReactNativePolyfills(): void;
|
|
878
|
+
/**
|
|
879
|
+
* Create a configured MemoryClient for React Native
|
|
880
|
+
*/
|
|
881
|
+
declare function createReactNativeClient(apiKey: string, options?: ReactNativeConfig & {
|
|
882
|
+
baseUrl?: string;
|
|
883
|
+
}): any;
|
|
884
|
+
/**
|
|
885
|
+
* React Native specific utilities
|
|
886
|
+
*/
|
|
887
|
+
declare const ReactNativeUtils: {
|
|
888
|
+
/**
|
|
889
|
+
* Check if running in React Native environment
|
|
890
|
+
*/
|
|
891
|
+
isReactNative(): boolean;
|
|
892
|
+
/**
|
|
893
|
+
* Get recommended polyfill packages for current environment
|
|
894
|
+
*/
|
|
895
|
+
getRecommendedPolyfills(): string[];
|
|
896
|
+
/**
|
|
897
|
+
* Generate installation command for missing polyfills
|
|
898
|
+
*/
|
|
899
|
+
getInstallCommand(): string | null;
|
|
900
|
+
};
|
|
901
|
+
/**
|
|
902
|
+
* Type guard to check if error is a polyfill error
|
|
903
|
+
*/
|
|
904
|
+
declare function isPolyfillError(error: unknown): boolean;
|
|
905
|
+
/**
|
|
906
|
+
* Helper to provide detailed polyfill error messages
|
|
907
|
+
*/
|
|
908
|
+
declare function getPolyfillErrorHelp(error: unknown): string | null;
|
|
909
|
+
|
|
910
|
+
/**
|
|
911
|
+
* Error classes for Memory Intelligence SDK
|
|
912
|
+
*
|
|
913
|
+
* All errors extend SDKError for consistency with Python SDK patterns.
|
|
914
|
+
*/
|
|
915
|
+
declare class SDKError extends Error {
|
|
916
|
+
code?: string | undefined;
|
|
917
|
+
constructor(message: string, code?: string | undefined);
|
|
918
|
+
}
|
|
919
|
+
declare class ConfigurationError extends SDKError {
|
|
920
|
+
constructor(message: string);
|
|
921
|
+
}
|
|
922
|
+
declare class AuthenticationError extends SDKError {
|
|
923
|
+
constructor(message: string);
|
|
924
|
+
}
|
|
925
|
+
declare class ValidationError extends SDKError {
|
|
926
|
+
field?: string | undefined;
|
|
927
|
+
constructor(message: string, field?: string | undefined);
|
|
928
|
+
}
|
|
929
|
+
declare class RateLimitError extends SDKError {
|
|
930
|
+
retryAfter?: number | undefined;
|
|
931
|
+
limit?: number | undefined;
|
|
932
|
+
remaining?: number | undefined;
|
|
933
|
+
constructor(message: string, retryAfter?: number | undefined, limit?: number | undefined, remaining?: number | undefined);
|
|
934
|
+
}
|
|
935
|
+
declare class APIError extends SDKError {
|
|
936
|
+
statusCode?: number | undefined;
|
|
937
|
+
requestId?: string | undefined;
|
|
938
|
+
details?: unknown | undefined;
|
|
939
|
+
constructor(message: string, statusCode?: number | undefined, requestId?: string | undefined, details?: unknown | undefined);
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
/**
|
|
943
|
+
* Memory Intelligence JavaScript/TypeScript SDK
|
|
944
|
+
*
|
|
945
|
+
* Official SDK for building web apps, Node.js services, and edge functions
|
|
946
|
+
* powered by Memory Intelligence.
|
|
947
|
+
*
|
|
948
|
+
* @packageDocumentation
|
|
949
|
+
*/
|
|
950
|
+
|
|
951
|
+
declare const VERSION = "2.0.0";
|
|
952
|
+
|
|
953
|
+
export { APIError, AuthenticationError, BaseSubscription, type BatchItemResult, type BatchProcessOptions, type BatchResult, type BatchSearchOptions, type CompatibilityCheck, ComputeNamespace, type ComputeProgress, type ComputeResult, ComputeSubscription, type ComputeUpdate, ConfigurationError, type DeleteResult, DriftNamespace, DriftSubscription, type DriftSubscriptionOptions, type DriftUpdate, type Embedding, type Entity, type EventHandler, ExplainLevel, type Explanation, type MatchResult, type MeaningObject, MemoryClient, type MemoryClientConfig, PIIHandling, ProgressTracker, type ProgressUpdate, type Provenance, ProvenanceMode, type RateLimit, RateLimitError, type ReactNativeConfig, ReactNativeUtils, RetentionPolicy, SDKError, type SDKResponse, Scope, type SearchResponse, type SearchResult, SearchResultStream, type ServerMessage, type StreamConfig, type StreamIteratorOptions, type SubscriptionMessage, type Topic, UMONamespace, UMOStreamProcessor, VERSION, ValidationError, type WebSocketConfig, WebSocketManager, checkReactNativeCompatibility, createReactNativeClient, getPolyfillErrorHelp, isPolyfillError, setupReactNativePolyfills, streamLargeDataset };
|