@usetransactional/memory 1.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 +300 -0
- package/dist/index.cjs +607 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +914 -0
- package/dist/index.d.ts +914 -0
- package/dist/index.js +592 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,914 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transactional Memory SDK - Type Definitions
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for MemoryClient.
|
|
6
|
+
*/
|
|
7
|
+
interface MemoryClientConfig {
|
|
8
|
+
/** API key for authentication */
|
|
9
|
+
apiKey: string;
|
|
10
|
+
/** Base URL for the API (default: https://api.usetransactional.com) */
|
|
11
|
+
baseUrl?: string;
|
|
12
|
+
/** Request timeout in milliseconds (default: 30000) */
|
|
13
|
+
timeout?: number;
|
|
14
|
+
/** Maximum number of retries for failed requests (default: 3) */
|
|
15
|
+
maxRetries?: number;
|
|
16
|
+
/** Custom headers to include in all requests */
|
|
17
|
+
headers?: Record<string, string>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Memory entity types.
|
|
21
|
+
*/
|
|
22
|
+
declare enum MemoryEntityType {
|
|
23
|
+
USER = "user",
|
|
24
|
+
FACT = "fact",
|
|
25
|
+
TOPIC = "topic",
|
|
26
|
+
PREFERENCE = "preference",
|
|
27
|
+
EVENT = "event",
|
|
28
|
+
MESSAGE = "message",
|
|
29
|
+
SUMMARY = "summary",
|
|
30
|
+
ORGANIZATION = "organization"
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Memory edge types (relationships).
|
|
34
|
+
*/
|
|
35
|
+
declare enum MemoryEdgeType {
|
|
36
|
+
PREFERS = "prefers",
|
|
37
|
+
MENTIONED = "mentioned",
|
|
38
|
+
DISCUSSED = "discussed",
|
|
39
|
+
ASKED_ABOUT = "asked_about",
|
|
40
|
+
RELATES_TO = "relates_to",
|
|
41
|
+
FOLLOWS_UP = "follows_up",
|
|
42
|
+
SUMMARIZES = "summarizes",
|
|
43
|
+
EXTRACTED_FROM = "extracted_from",
|
|
44
|
+
WORKS_AT = "works_at",
|
|
45
|
+
INTERESTED_IN = "interested_in"
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Source of a memory fact.
|
|
49
|
+
*/
|
|
50
|
+
declare enum MemoryFactSource {
|
|
51
|
+
EXTRACTED = "extracted",
|
|
52
|
+
EXPLICIT = "explicit",
|
|
53
|
+
INFERRED = "inferred"
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Session status.
|
|
57
|
+
*/
|
|
58
|
+
declare enum MemorySessionStatus {
|
|
59
|
+
ACTIVE = "ACTIVE",
|
|
60
|
+
EXPIRED = "EXPIRED",
|
|
61
|
+
DELETED = "DELETED"
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Message role.
|
|
65
|
+
*/
|
|
66
|
+
declare enum MemoryMessageRole {
|
|
67
|
+
USER = "user",
|
|
68
|
+
ASSISTANT = "assistant",
|
|
69
|
+
SYSTEM = "system"
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* A memory entity.
|
|
73
|
+
*/
|
|
74
|
+
interface Memory {
|
|
75
|
+
/** Unique entity ID */
|
|
76
|
+
id: string;
|
|
77
|
+
/** Session this entity belongs to */
|
|
78
|
+
sessionId: string;
|
|
79
|
+
/** Entity type */
|
|
80
|
+
type: MemoryEntityType;
|
|
81
|
+
/** Entity name/key */
|
|
82
|
+
name: string;
|
|
83
|
+
/** Additional properties */
|
|
84
|
+
properties: Record<string, unknown>;
|
|
85
|
+
/** Confidence score (0-1) */
|
|
86
|
+
confidence: number;
|
|
87
|
+
/** How the entity was created */
|
|
88
|
+
source: MemoryFactSource;
|
|
89
|
+
/** Relevance score */
|
|
90
|
+
score?: number;
|
|
91
|
+
/** Whether entity has embeddings */
|
|
92
|
+
hasEmbedding?: boolean;
|
|
93
|
+
/** Creation timestamp */
|
|
94
|
+
createdAt: string;
|
|
95
|
+
/** Last update timestamp */
|
|
96
|
+
updatedAt: string;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* A memory edge (relationship).
|
|
100
|
+
*/
|
|
101
|
+
interface MemoryEdge {
|
|
102
|
+
/** Unique edge ID */
|
|
103
|
+
id: string;
|
|
104
|
+
/** Source entity ID */
|
|
105
|
+
from: string;
|
|
106
|
+
/** Target entity ID */
|
|
107
|
+
to: string;
|
|
108
|
+
/** Relationship type */
|
|
109
|
+
type: MemoryEdgeType;
|
|
110
|
+
/** Relationship strength (0-1) */
|
|
111
|
+
weight: number;
|
|
112
|
+
/** Additional properties */
|
|
113
|
+
properties: Record<string, unknown>;
|
|
114
|
+
/** Creation timestamp */
|
|
115
|
+
createdAt: string;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* A memory session.
|
|
119
|
+
*/
|
|
120
|
+
interface Session {
|
|
121
|
+
/** Session ID */
|
|
122
|
+
id: string;
|
|
123
|
+
/** External reference ID */
|
|
124
|
+
externalId: string | null;
|
|
125
|
+
/** Agent/bot ID */
|
|
126
|
+
agentId: string | null;
|
|
127
|
+
/** User ID */
|
|
128
|
+
userId: string | null;
|
|
129
|
+
/** Session status */
|
|
130
|
+
status: MemorySessionStatus;
|
|
131
|
+
/** Session configuration */
|
|
132
|
+
config?: SessionConfig;
|
|
133
|
+
/** Session statistics */
|
|
134
|
+
stats?: {
|
|
135
|
+
entityCount: number;
|
|
136
|
+
edgeCount: number;
|
|
137
|
+
messageCount: number;
|
|
138
|
+
lastActivityAt?: string;
|
|
139
|
+
};
|
|
140
|
+
/** Creation timestamp */
|
|
141
|
+
createdAt: string;
|
|
142
|
+
/** Last update timestamp */
|
|
143
|
+
updatedAt: string;
|
|
144
|
+
/** Expiration timestamp */
|
|
145
|
+
expiresAt: string | null;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Session configuration.
|
|
149
|
+
*/
|
|
150
|
+
interface SessionConfig {
|
|
151
|
+
/** Embedding provider */
|
|
152
|
+
embeddingProvider?: string;
|
|
153
|
+
/** Embedding model */
|
|
154
|
+
embeddingModel?: string;
|
|
155
|
+
/** Auto-extract entities */
|
|
156
|
+
autoExtract?: boolean;
|
|
157
|
+
/** Auto-summarize conversations */
|
|
158
|
+
autoSummarize?: boolean;
|
|
159
|
+
/** Message count threshold for summarization */
|
|
160
|
+
summarizeThreshold?: number;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Parameters for creating a session.
|
|
164
|
+
*/
|
|
165
|
+
interface CreateSessionParams {
|
|
166
|
+
/** External reference ID */
|
|
167
|
+
externalId?: string;
|
|
168
|
+
/** Agent/bot ID */
|
|
169
|
+
agentId?: string;
|
|
170
|
+
/** User ID */
|
|
171
|
+
userId?: string;
|
|
172
|
+
/** Time-to-live in seconds (default: 24 hours) */
|
|
173
|
+
ttl?: number;
|
|
174
|
+
/** Session configuration */
|
|
175
|
+
config?: SessionConfig;
|
|
176
|
+
/** Additional metadata */
|
|
177
|
+
metadata?: Record<string, unknown>;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Parameters for updating a session.
|
|
181
|
+
*/
|
|
182
|
+
interface UpdateSessionParams {
|
|
183
|
+
/** New TTL in seconds */
|
|
184
|
+
ttl?: number;
|
|
185
|
+
/** Configuration updates */
|
|
186
|
+
config?: Partial<SessionConfig>;
|
|
187
|
+
/** Metadata updates */
|
|
188
|
+
metadata?: Record<string, unknown>;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Parameters for listing sessions.
|
|
192
|
+
*/
|
|
193
|
+
interface ListSessionsParams {
|
|
194
|
+
/** Filter by status */
|
|
195
|
+
status?: MemorySessionStatus;
|
|
196
|
+
/** Filter by agent ID */
|
|
197
|
+
agentId?: string;
|
|
198
|
+
/** Filter by user ID */
|
|
199
|
+
userId?: string;
|
|
200
|
+
/** Search in external ID or agent ID */
|
|
201
|
+
search?: string;
|
|
202
|
+
/** Page number (1-based) */
|
|
203
|
+
page?: number;
|
|
204
|
+
/** Results per page (default: 20, max: 100) */
|
|
205
|
+
limit?: number;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Parameters for adding a memory.
|
|
209
|
+
*/
|
|
210
|
+
interface AddMemoryParams {
|
|
211
|
+
/** Content to add */
|
|
212
|
+
content: string;
|
|
213
|
+
/** Session ID */
|
|
214
|
+
sessionId?: string;
|
|
215
|
+
/** User ID */
|
|
216
|
+
userId?: string;
|
|
217
|
+
/** Entity type */
|
|
218
|
+
type?: MemoryEntityType;
|
|
219
|
+
/** Additional metadata */
|
|
220
|
+
metadata?: Record<string, unknown>;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Result from adding a memory.
|
|
224
|
+
*/
|
|
225
|
+
interface AddMemoryResult {
|
|
226
|
+
/** Created entity ID */
|
|
227
|
+
id: string;
|
|
228
|
+
/** Session ID */
|
|
229
|
+
sessionId: string;
|
|
230
|
+
/** Processing status */
|
|
231
|
+
status: 'processing' | 'completed';
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Parameters for updating a memory.
|
|
235
|
+
*/
|
|
236
|
+
interface UpdateMemoryParams {
|
|
237
|
+
/** New name */
|
|
238
|
+
name?: string;
|
|
239
|
+
/** New properties */
|
|
240
|
+
properties?: Record<string, unknown>;
|
|
241
|
+
/** New confidence */
|
|
242
|
+
confidence?: number;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Search strategy.
|
|
246
|
+
*/
|
|
247
|
+
type SearchStrategy = 'auto' | 'keyword' | 'semantic' | 'hybrid';
|
|
248
|
+
/**
|
|
249
|
+
* Parameters for searching memories.
|
|
250
|
+
*/
|
|
251
|
+
interface SearchParams {
|
|
252
|
+
/** Search query */
|
|
253
|
+
query: string;
|
|
254
|
+
/** Scope to specific session */
|
|
255
|
+
sessionId?: string;
|
|
256
|
+
/** Scope to specific sessions */
|
|
257
|
+
sessionIds?: string[];
|
|
258
|
+
/** Filter by user ID */
|
|
259
|
+
userId?: string;
|
|
260
|
+
/** Filter by entity types */
|
|
261
|
+
types?: MemoryEntityType[];
|
|
262
|
+
/** Search strategy */
|
|
263
|
+
strategy?: SearchStrategy;
|
|
264
|
+
/** Minimum similarity threshold (0-1, default: 0.7) */
|
|
265
|
+
threshold?: number;
|
|
266
|
+
/** Maximum results (default: 10, max: 50) */
|
|
267
|
+
limit?: number;
|
|
268
|
+
/** Include related entities */
|
|
269
|
+
includeRelated?: boolean;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* A search hit.
|
|
273
|
+
*/
|
|
274
|
+
interface SearchHit {
|
|
275
|
+
/** The matching entity */
|
|
276
|
+
entity: Memory;
|
|
277
|
+
/** Relevance score (0-1) */
|
|
278
|
+
score: number;
|
|
279
|
+
/** How the match was found */
|
|
280
|
+
matchType: 'keyword' | 'semantic' | 'hybrid';
|
|
281
|
+
/** Text highlights */
|
|
282
|
+
highlights: string[];
|
|
283
|
+
/** Related entities */
|
|
284
|
+
relatedEntities?: Array<{
|
|
285
|
+
id: string;
|
|
286
|
+
type: MemoryEntityType;
|
|
287
|
+
name: string;
|
|
288
|
+
}>;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Search result.
|
|
292
|
+
*/
|
|
293
|
+
interface SearchResult {
|
|
294
|
+
/** Search hits */
|
|
295
|
+
results: SearchHit[];
|
|
296
|
+
/** Query information */
|
|
297
|
+
query: {
|
|
298
|
+
original: string;
|
|
299
|
+
tokens: number;
|
|
300
|
+
};
|
|
301
|
+
/** Metadata */
|
|
302
|
+
meta: {
|
|
303
|
+
strategy: SearchStrategy;
|
|
304
|
+
searchTime: number;
|
|
305
|
+
totalMatches: number;
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Parameters for getting context.
|
|
310
|
+
*/
|
|
311
|
+
interface GetContextParams {
|
|
312
|
+
/** User ID */
|
|
313
|
+
userId: string;
|
|
314
|
+
/** Session ID */
|
|
315
|
+
sessionId?: string;
|
|
316
|
+
/** Focus query */
|
|
317
|
+
query?: string;
|
|
318
|
+
/** Maximum tokens (default: 4000) */
|
|
319
|
+
maxTokens?: number;
|
|
320
|
+
/** Include user profile */
|
|
321
|
+
includeProfile?: boolean;
|
|
322
|
+
/** Include facts */
|
|
323
|
+
includeFacts?: boolean;
|
|
324
|
+
/** Include preferences */
|
|
325
|
+
includePreferences?: boolean;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Context result.
|
|
329
|
+
*/
|
|
330
|
+
interface ContextResult {
|
|
331
|
+
/** Formatted context string for LLM */
|
|
332
|
+
context: string;
|
|
333
|
+
/** Token count */
|
|
334
|
+
tokenCount: number;
|
|
335
|
+
/** User profile */
|
|
336
|
+
profile?: {
|
|
337
|
+
userId: string;
|
|
338
|
+
name?: string;
|
|
339
|
+
preferences: Record<string, unknown>;
|
|
340
|
+
};
|
|
341
|
+
/** Facts */
|
|
342
|
+
facts: Array<{
|
|
343
|
+
key: string;
|
|
344
|
+
value: unknown;
|
|
345
|
+
confidence: number;
|
|
346
|
+
}>;
|
|
347
|
+
/** Preferences */
|
|
348
|
+
preferences: Array<{
|
|
349
|
+
name: string;
|
|
350
|
+
value: unknown;
|
|
351
|
+
}>;
|
|
352
|
+
/** Recent topics */
|
|
353
|
+
recentTopics: Array<{
|
|
354
|
+
name: string;
|
|
355
|
+
sentiment?: string;
|
|
356
|
+
lastDiscussed: string;
|
|
357
|
+
}>;
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Parameters for URL ingestion.
|
|
361
|
+
*/
|
|
362
|
+
interface IngestUrlParams {
|
|
363
|
+
/** URL to ingest */
|
|
364
|
+
url: string;
|
|
365
|
+
/** Session ID */
|
|
366
|
+
sessionId?: string;
|
|
367
|
+
/** User ID */
|
|
368
|
+
userId?: string;
|
|
369
|
+
/** Additional metadata */
|
|
370
|
+
metadata?: Record<string, unknown>;
|
|
371
|
+
/** Options */
|
|
372
|
+
options?: {
|
|
373
|
+
extractEntities?: boolean;
|
|
374
|
+
generateEmbeddings?: boolean;
|
|
375
|
+
chunkSize?: number;
|
|
376
|
+
chunkOverlap?: number;
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Result from URL ingestion.
|
|
381
|
+
*/
|
|
382
|
+
interface IngestUrlResult {
|
|
383
|
+
/** Memory ID */
|
|
384
|
+
memoryId: string;
|
|
385
|
+
/** Job ID (for async tracking) */
|
|
386
|
+
jobId?: string;
|
|
387
|
+
/** Final URL after redirects */
|
|
388
|
+
url: string;
|
|
389
|
+
/** Page title */
|
|
390
|
+
title: string;
|
|
391
|
+
/** Page description */
|
|
392
|
+
description?: string;
|
|
393
|
+
/** Author */
|
|
394
|
+
author?: string;
|
|
395
|
+
/** Published date */
|
|
396
|
+
publishedDate?: string;
|
|
397
|
+
/** Site name */
|
|
398
|
+
siteName?: string;
|
|
399
|
+
/** Content length */
|
|
400
|
+
contentLength: number;
|
|
401
|
+
/** Number of chunks */
|
|
402
|
+
chunks: number;
|
|
403
|
+
/** Extracted entities */
|
|
404
|
+
entities: Array<{
|
|
405
|
+
type: MemoryEntityType;
|
|
406
|
+
name: string;
|
|
407
|
+
value?: string;
|
|
408
|
+
confidence: number;
|
|
409
|
+
}>;
|
|
410
|
+
/** Processing time in ms */
|
|
411
|
+
processingTime: number;
|
|
412
|
+
/** Status */
|
|
413
|
+
status: 'processing' | 'completed';
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Parameters for PDF ingestion.
|
|
417
|
+
*/
|
|
418
|
+
interface IngestPdfParams {
|
|
419
|
+
/** PDF file (Buffer or Blob) */
|
|
420
|
+
file: Buffer | Blob;
|
|
421
|
+
/** Filename */
|
|
422
|
+
filename: string;
|
|
423
|
+
/** Session ID */
|
|
424
|
+
sessionId?: string;
|
|
425
|
+
/** User ID */
|
|
426
|
+
userId?: string;
|
|
427
|
+
/** Additional metadata */
|
|
428
|
+
metadata?: Record<string, unknown>;
|
|
429
|
+
/** Options */
|
|
430
|
+
options?: {
|
|
431
|
+
extractEntities?: boolean;
|
|
432
|
+
generateEmbeddings?: boolean;
|
|
433
|
+
ocrFallback?: boolean;
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Result from PDF ingestion.
|
|
438
|
+
*/
|
|
439
|
+
interface IngestPdfResult {
|
|
440
|
+
/** Memory ID */
|
|
441
|
+
memoryId: string;
|
|
442
|
+
/** Job ID */
|
|
443
|
+
jobId: string;
|
|
444
|
+
/** Filename */
|
|
445
|
+
filename: string;
|
|
446
|
+
/** Document title */
|
|
447
|
+
title: string;
|
|
448
|
+
/** Author */
|
|
449
|
+
author?: string;
|
|
450
|
+
/** Creation date */
|
|
451
|
+
createdDate?: string;
|
|
452
|
+
/** Page count */
|
|
453
|
+
pageCount: number;
|
|
454
|
+
/** Content length */
|
|
455
|
+
contentLength: number;
|
|
456
|
+
/** Number of chunks */
|
|
457
|
+
chunks: number;
|
|
458
|
+
/** Extracted entities */
|
|
459
|
+
entities: Array<{
|
|
460
|
+
type: MemoryEntityType;
|
|
461
|
+
name: string;
|
|
462
|
+
value?: string;
|
|
463
|
+
confidence: number;
|
|
464
|
+
}>;
|
|
465
|
+
/** Has images */
|
|
466
|
+
hasImages: boolean;
|
|
467
|
+
/** Has tables */
|
|
468
|
+
hasTables: boolean;
|
|
469
|
+
/** Processing time in ms */
|
|
470
|
+
processingTime: number;
|
|
471
|
+
/** Status */
|
|
472
|
+
status: 'processing' | 'completed';
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Parameters for text ingestion.
|
|
476
|
+
*/
|
|
477
|
+
interface IngestTextParams {
|
|
478
|
+
/** Text content */
|
|
479
|
+
content: string;
|
|
480
|
+
/** Content type */
|
|
481
|
+
contentType?: 'text' | 'json' | 'markdown' | 'code';
|
|
482
|
+
/** Session ID */
|
|
483
|
+
sessionId?: string;
|
|
484
|
+
/** Additional metadata */
|
|
485
|
+
metadata?: Record<string, unknown>;
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Result from text ingestion.
|
|
489
|
+
*/
|
|
490
|
+
interface IngestTextResult {
|
|
491
|
+
/** Session ID */
|
|
492
|
+
sessionId: string;
|
|
493
|
+
/** Message ID */
|
|
494
|
+
messageId: string;
|
|
495
|
+
/** Content type */
|
|
496
|
+
contentType: string;
|
|
497
|
+
/** Status */
|
|
498
|
+
status: 'processing' | 'completed';
|
|
499
|
+
/** Whether a new session was created */
|
|
500
|
+
isNewSession: boolean;
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* User profile.
|
|
504
|
+
*/
|
|
505
|
+
interface UserProfile {
|
|
506
|
+
/** Profile ID */
|
|
507
|
+
id: number;
|
|
508
|
+
/** User ID */
|
|
509
|
+
userId: string;
|
|
510
|
+
/** Static facts */
|
|
511
|
+
staticFacts: {
|
|
512
|
+
name?: string;
|
|
513
|
+
role?: string;
|
|
514
|
+
company?: string;
|
|
515
|
+
timezone?: string;
|
|
516
|
+
language?: string;
|
|
517
|
+
email?: string;
|
|
518
|
+
preferences?: Record<string, unknown>;
|
|
519
|
+
[key: string]: unknown;
|
|
520
|
+
};
|
|
521
|
+
/** Dynamic facts */
|
|
522
|
+
dynamicFacts: {
|
|
523
|
+
recentTopics?: string[];
|
|
524
|
+
interests?: string[];
|
|
525
|
+
painPoints?: string[];
|
|
526
|
+
goals?: string[];
|
|
527
|
+
expertise?: string[];
|
|
528
|
+
sentimentHistory?: Array<{
|
|
529
|
+
date: string;
|
|
530
|
+
sentiment: string;
|
|
531
|
+
}>;
|
|
532
|
+
[key: string]: unknown;
|
|
533
|
+
};
|
|
534
|
+
/** Total fact count */
|
|
535
|
+
factCount: number;
|
|
536
|
+
/** Total session count */
|
|
537
|
+
sessionCount: number;
|
|
538
|
+
/** Last session ID */
|
|
539
|
+
lastSessionId: string | null;
|
|
540
|
+
/** Creation timestamp */
|
|
541
|
+
createdAt: string;
|
|
542
|
+
/** Last update timestamp */
|
|
543
|
+
updatedAt: string;
|
|
544
|
+
/** Last activity timestamp */
|
|
545
|
+
lastActiveAt: string | null;
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* Parameters for upserting a profile.
|
|
549
|
+
*/
|
|
550
|
+
interface UpsertProfileParams {
|
|
551
|
+
/** Static facts to set/update */
|
|
552
|
+
staticFacts?: Partial<UserProfile['staticFacts']>;
|
|
553
|
+
/** Dynamic facts to set/update */
|
|
554
|
+
dynamicFacts?: Partial<UserProfile['dynamicFacts']>;
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Graph node.
|
|
558
|
+
*/
|
|
559
|
+
interface GraphNode {
|
|
560
|
+
/** Node ID */
|
|
561
|
+
id: string;
|
|
562
|
+
/** Entity type */
|
|
563
|
+
type: MemoryEntityType;
|
|
564
|
+
/** Display name */
|
|
565
|
+
name: string;
|
|
566
|
+
/** Properties */
|
|
567
|
+
properties: Record<string, unknown>;
|
|
568
|
+
/** Score */
|
|
569
|
+
score: number;
|
|
570
|
+
/** Confidence */
|
|
571
|
+
confidence: number;
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Graph edge.
|
|
575
|
+
*/
|
|
576
|
+
interface GraphEdge {
|
|
577
|
+
/** Edge ID */
|
|
578
|
+
id: string;
|
|
579
|
+
/** Source node ID */
|
|
580
|
+
source: string;
|
|
581
|
+
/** Target node ID */
|
|
582
|
+
target: string;
|
|
583
|
+
/** Relationship type */
|
|
584
|
+
type: MemoryEdgeType;
|
|
585
|
+
/** Weight */
|
|
586
|
+
weight: number;
|
|
587
|
+
/** Properties */
|
|
588
|
+
properties: Record<string, unknown>;
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* Graph result.
|
|
592
|
+
*/
|
|
593
|
+
interface GraphResult {
|
|
594
|
+
/** Nodes */
|
|
595
|
+
nodes: GraphNode[];
|
|
596
|
+
/** Edges */
|
|
597
|
+
edges: GraphEdge[];
|
|
598
|
+
/** Stats */
|
|
599
|
+
stats: {
|
|
600
|
+
totalNodes: number;
|
|
601
|
+
totalEdges: number;
|
|
602
|
+
depth: number;
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* Parameters for getting graph.
|
|
607
|
+
*/
|
|
608
|
+
interface GetGraphParams {
|
|
609
|
+
/** Session ID */
|
|
610
|
+
sessionId?: string;
|
|
611
|
+
/** Center entity ID */
|
|
612
|
+
centerEntityId?: string;
|
|
613
|
+
/** Traversal depth */
|
|
614
|
+
depth?: number;
|
|
615
|
+
/** Filter by entity types */
|
|
616
|
+
entityTypes?: MemoryEntityType[];
|
|
617
|
+
/** Filter by edge types */
|
|
618
|
+
edgeTypes?: MemoryEdgeType[];
|
|
619
|
+
/** Minimum edge weight */
|
|
620
|
+
minWeight?: number;
|
|
621
|
+
/** Maximum nodes */
|
|
622
|
+
limit?: number;
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Parameters for graph traversal.
|
|
626
|
+
*/
|
|
627
|
+
interface TraverseParams {
|
|
628
|
+
/** Starting entity ID */
|
|
629
|
+
startEntityId: string;
|
|
630
|
+
/** Traversal depth */
|
|
631
|
+
depth?: number;
|
|
632
|
+
/** Direction */
|
|
633
|
+
direction?: 'outbound' | 'inbound' | 'any';
|
|
634
|
+
/** Filter by entity types */
|
|
635
|
+
entityTypes?: MemoryEntityType[];
|
|
636
|
+
/** Filter by edge types */
|
|
637
|
+
edgeTypes?: MemoryEdgeType[];
|
|
638
|
+
/** Minimum edge weight */
|
|
639
|
+
minWeight?: number;
|
|
640
|
+
/** Maximum nodes */
|
|
641
|
+
limit?: number;
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* Paginated list response.
|
|
645
|
+
*/
|
|
646
|
+
interface PaginatedResponse<T> {
|
|
647
|
+
/** Data items */
|
|
648
|
+
data: T[];
|
|
649
|
+
/** Pagination metadata */
|
|
650
|
+
meta: {
|
|
651
|
+
page: number;
|
|
652
|
+
limit: number;
|
|
653
|
+
total: number;
|
|
654
|
+
totalPages: number;
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Job status response.
|
|
659
|
+
*/
|
|
660
|
+
interface JobStatus {
|
|
661
|
+
/** Job ID */
|
|
662
|
+
jobId: string;
|
|
663
|
+
/** Status */
|
|
664
|
+
status: 'pending' | 'processing' | 'completed' | 'failed';
|
|
665
|
+
/** Progress (0-100) */
|
|
666
|
+
progress?: number;
|
|
667
|
+
/** Result data */
|
|
668
|
+
result?: unknown;
|
|
669
|
+
/** Error message */
|
|
670
|
+
error?: string;
|
|
671
|
+
/** Created at */
|
|
672
|
+
createdAt: string;
|
|
673
|
+
/** Completed at */
|
|
674
|
+
completedAt?: string;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* Transactional Memory SDK - Client Implementation
|
|
679
|
+
*/
|
|
680
|
+
|
|
681
|
+
interface RequestOptions {
|
|
682
|
+
method: 'GET' | 'POST' | 'PATCH' | 'DELETE';
|
|
683
|
+
path: string;
|
|
684
|
+
body?: unknown;
|
|
685
|
+
headers?: Record<string, string>;
|
|
686
|
+
timeout?: number;
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* Transactional Memory API Client.
|
|
690
|
+
*
|
|
691
|
+
* @example
|
|
692
|
+
* ```typescript
|
|
693
|
+
* import { MemoryClient } from '@transactional/memory-sdk';
|
|
694
|
+
*
|
|
695
|
+
* const client = new MemoryClient({
|
|
696
|
+
* apiKey: 'your-api-key',
|
|
697
|
+
* });
|
|
698
|
+
*
|
|
699
|
+
* // Add a memory
|
|
700
|
+
* const result = await client.add({
|
|
701
|
+
* content: 'User prefers TypeScript',
|
|
702
|
+
* userId: 'user_123',
|
|
703
|
+
* });
|
|
704
|
+
*
|
|
705
|
+
* // Search memories
|
|
706
|
+
* const searchResult = await client.search({
|
|
707
|
+
* query: 'programming language preferences',
|
|
708
|
+
* userId: 'user_123',
|
|
709
|
+
* });
|
|
710
|
+
* ```
|
|
711
|
+
*/
|
|
712
|
+
declare class MemoryClient {
|
|
713
|
+
private readonly apiKey;
|
|
714
|
+
private readonly baseUrl;
|
|
715
|
+
private readonly timeout;
|
|
716
|
+
private readonly maxRetries;
|
|
717
|
+
private readonly customHeaders;
|
|
718
|
+
/** Session operations */
|
|
719
|
+
readonly sessions: SessionOperations;
|
|
720
|
+
/** Profile operations */
|
|
721
|
+
readonly profiles: ProfileOperations;
|
|
722
|
+
/** Graph operations */
|
|
723
|
+
readonly graph: GraphOperations;
|
|
724
|
+
/** Ingest operations */
|
|
725
|
+
readonly ingest: IngestOperations;
|
|
726
|
+
constructor(config: MemoryClientConfig);
|
|
727
|
+
/**
|
|
728
|
+
* Make an HTTP request to the API.
|
|
729
|
+
*/
|
|
730
|
+
request<T>(options: RequestOptions): Promise<T>;
|
|
731
|
+
private sleep;
|
|
732
|
+
/**
|
|
733
|
+
* Add a memory.
|
|
734
|
+
*/
|
|
735
|
+
add(params: AddMemoryParams): Promise<AddMemoryResult>;
|
|
736
|
+
/**
|
|
737
|
+
* Search memories.
|
|
738
|
+
*/
|
|
739
|
+
search(params: SearchParams): Promise<SearchResult>;
|
|
740
|
+
/**
|
|
741
|
+
* Get a specific memory by ID.
|
|
742
|
+
*/
|
|
743
|
+
get(sessionId: string, memoryId: string): Promise<Memory>;
|
|
744
|
+
/**
|
|
745
|
+
* Update a memory.
|
|
746
|
+
*/
|
|
747
|
+
update(sessionId: string, memoryId: string, params: UpdateMemoryParams): Promise<Memory>;
|
|
748
|
+
/**
|
|
749
|
+
* Delete a memory.
|
|
750
|
+
*/
|
|
751
|
+
delete(sessionId: string, memoryId: string): Promise<void>;
|
|
752
|
+
/**
|
|
753
|
+
* Get context for LLM prompts.
|
|
754
|
+
*/
|
|
755
|
+
getContext(params: GetContextParams): Promise<ContextResult>;
|
|
756
|
+
/**
|
|
757
|
+
* Get job status.
|
|
758
|
+
*/
|
|
759
|
+
getJobStatus(jobId: string): Promise<JobStatus>;
|
|
760
|
+
}
|
|
761
|
+
declare class SessionOperations {
|
|
762
|
+
private client;
|
|
763
|
+
constructor(client: MemoryClient);
|
|
764
|
+
/**
|
|
765
|
+
* Create a new session.
|
|
766
|
+
*/
|
|
767
|
+
create(params?: CreateSessionParams): Promise<Session>;
|
|
768
|
+
/**
|
|
769
|
+
* Get a session by ID.
|
|
770
|
+
*/
|
|
771
|
+
get(sessionId: string): Promise<Session>;
|
|
772
|
+
/**
|
|
773
|
+
* List sessions.
|
|
774
|
+
*/
|
|
775
|
+
list(params?: ListSessionsParams): Promise<PaginatedResponse<Session>>;
|
|
776
|
+
/**
|
|
777
|
+
* Update a session.
|
|
778
|
+
*/
|
|
779
|
+
update(sessionId: string, params: UpdateSessionParams): Promise<Session>;
|
|
780
|
+
/**
|
|
781
|
+
* Delete a session.
|
|
782
|
+
*/
|
|
783
|
+
delete(sessionId: string): Promise<void>;
|
|
784
|
+
}
|
|
785
|
+
declare class ProfileOperations {
|
|
786
|
+
private client;
|
|
787
|
+
constructor(client: MemoryClient);
|
|
788
|
+
/**
|
|
789
|
+
* Get a user profile.
|
|
790
|
+
*/
|
|
791
|
+
get(userId: string): Promise<UserProfile>;
|
|
792
|
+
/**
|
|
793
|
+
* Create or update a user profile.
|
|
794
|
+
*/
|
|
795
|
+
upsert(userId: string, params: UpsertProfileParams): Promise<UserProfile>;
|
|
796
|
+
/**
|
|
797
|
+
* Delete a user profile.
|
|
798
|
+
*/
|
|
799
|
+
delete(userId: string): Promise<void>;
|
|
800
|
+
}
|
|
801
|
+
declare class GraphOperations {
|
|
802
|
+
private client;
|
|
803
|
+
constructor(client: MemoryClient);
|
|
804
|
+
/**
|
|
805
|
+
* Get the knowledge graph.
|
|
806
|
+
*/
|
|
807
|
+
get(params?: GetGraphParams): Promise<GraphResult>;
|
|
808
|
+
/**
|
|
809
|
+
* Traverse the graph from a starting entity.
|
|
810
|
+
*/
|
|
811
|
+
traverse(params: TraverseParams): Promise<GraphResult>;
|
|
812
|
+
}
|
|
813
|
+
declare class IngestOperations {
|
|
814
|
+
private client;
|
|
815
|
+
constructor(client: MemoryClient);
|
|
816
|
+
/**
|
|
817
|
+
* Ingest URL content.
|
|
818
|
+
*/
|
|
819
|
+
url(params: IngestUrlParams): Promise<IngestUrlResult>;
|
|
820
|
+
/**
|
|
821
|
+
* Ingest PDF content.
|
|
822
|
+
*/
|
|
823
|
+
pdf(params: IngestPdfParams): Promise<IngestPdfResult>;
|
|
824
|
+
/**
|
|
825
|
+
* Ingest text content.
|
|
826
|
+
*/
|
|
827
|
+
text(params: IngestTextParams): Promise<IngestTextResult>;
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
/**
|
|
831
|
+
* Transactional Memory SDK - Error Classes
|
|
832
|
+
*/
|
|
833
|
+
/**
|
|
834
|
+
* Base error class for Memory SDK errors.
|
|
835
|
+
*/
|
|
836
|
+
declare class MemoryError extends Error {
|
|
837
|
+
/** Error code */
|
|
838
|
+
readonly code: string;
|
|
839
|
+
/** HTTP status code */
|
|
840
|
+
readonly status: number;
|
|
841
|
+
/** Additional error details */
|
|
842
|
+
readonly details?: unknown;
|
|
843
|
+
constructor(message: string, code: string, status: number, details?: unknown);
|
|
844
|
+
}
|
|
845
|
+
/**
|
|
846
|
+
* Authentication error (invalid or missing API key).
|
|
847
|
+
*/
|
|
848
|
+
declare class AuthenticationError extends MemoryError {
|
|
849
|
+
constructor(message?: string);
|
|
850
|
+
}
|
|
851
|
+
/**
|
|
852
|
+
* Validation error (invalid request parameters).
|
|
853
|
+
*/
|
|
854
|
+
declare class ValidationError extends MemoryError {
|
|
855
|
+
/** Field-level errors */
|
|
856
|
+
readonly fieldErrors?: Array<{
|
|
857
|
+
field: string;
|
|
858
|
+
message: string;
|
|
859
|
+
}>;
|
|
860
|
+
constructor(message: string, fieldErrors?: Array<{
|
|
861
|
+
field: string;
|
|
862
|
+
message: string;
|
|
863
|
+
}>);
|
|
864
|
+
}
|
|
865
|
+
/**
|
|
866
|
+
* Not found error (resource doesn't exist).
|
|
867
|
+
*/
|
|
868
|
+
declare class NotFoundError extends MemoryError {
|
|
869
|
+
/** Resource type */
|
|
870
|
+
readonly resourceType: string;
|
|
871
|
+
/** Resource ID */
|
|
872
|
+
readonly resourceId?: string;
|
|
873
|
+
constructor(resourceType: string, resourceId?: string);
|
|
874
|
+
}
|
|
875
|
+
/**
|
|
876
|
+
* Rate limit error (too many requests).
|
|
877
|
+
*/
|
|
878
|
+
declare class RateLimitError extends MemoryError {
|
|
879
|
+
/** Time to wait before retrying (seconds) */
|
|
880
|
+
readonly retryAfter: number;
|
|
881
|
+
/** Rate limit */
|
|
882
|
+
readonly limit?: number;
|
|
883
|
+
/** Remaining requests */
|
|
884
|
+
readonly remaining?: number;
|
|
885
|
+
/** Reset timestamp */
|
|
886
|
+
readonly reset?: number;
|
|
887
|
+
constructor(retryAfter: number, options?: {
|
|
888
|
+
limit?: number;
|
|
889
|
+
remaining?: number;
|
|
890
|
+
reset?: number;
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
/**
|
|
894
|
+
* Server error (internal server error).
|
|
895
|
+
*/
|
|
896
|
+
declare class ServerError extends MemoryError {
|
|
897
|
+
constructor(message?: string, details?: unknown);
|
|
898
|
+
}
|
|
899
|
+
/**
|
|
900
|
+
* Timeout error (request timed out).
|
|
901
|
+
*/
|
|
902
|
+
declare class TimeoutError extends MemoryError {
|
|
903
|
+
/** Timeout duration in ms */
|
|
904
|
+
readonly timeout: number;
|
|
905
|
+
constructor(timeout: number);
|
|
906
|
+
}
|
|
907
|
+
/**
|
|
908
|
+
* Network error (connection failed).
|
|
909
|
+
*/
|
|
910
|
+
declare class NetworkError extends MemoryError {
|
|
911
|
+
constructor(message?: string, details?: unknown);
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
export { type AddMemoryParams, type AddMemoryResult, AuthenticationError, type ContextResult, type CreateSessionParams, type GetContextParams, type GetGraphParams, type GraphEdge, type GraphNode, type GraphResult, type IngestPdfParams, type IngestPdfResult, type IngestTextParams, type IngestTextResult, type IngestUrlParams, type IngestUrlResult, type JobStatus, type ListSessionsParams, type Memory, MemoryClient, type MemoryClientConfig, type MemoryEdge, MemoryEdgeType, MemoryEntityType, MemoryError, MemoryFactSource, MemoryMessageRole, MemorySessionStatus, NetworkError, NotFoundError, type PaginatedResponse, RateLimitError, type SearchHit, type SearchParams, type SearchResult, type SearchStrategy, ServerError, type Session, type SessionConfig, TimeoutError, type TraverseParams, type UpdateMemoryParams, type UpdateSessionParams, type UpsertProfileParams, type UserProfile, ValidationError };
|