@memorylayerai/sdk 0.1.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.
@@ -0,0 +1,492 @@
1
+ /**
2
+ * Configuration options for the MemoryLayer client
3
+ */
4
+ interface ClientConfig$1 {
5
+ /** API key for authentication (can also be set via MEMORYLAYER_API_KEY env var) */
6
+ apiKey?: string;
7
+ /** Base URL for the API (default: https://api.memorylayer.com) */
8
+ baseURL?: string;
9
+ /** Request timeout in milliseconds (default: 30000) */
10
+ timeout?: number;
11
+ /** Maximum number of retry attempts (default: 3) */
12
+ maxRetries?: number;
13
+ /** Initial retry delay in milliseconds (default: 1000) */
14
+ retryDelay?: number;
15
+ /** Custom headers to include in all requests */
16
+ headers?: Record<string, string>;
17
+ /** Logger for debugging */
18
+ logger?: {
19
+ debug(message: string, ...args: any[]): void;
20
+ info(message: string, ...args: any[]): void;
21
+ warn(message: string, ...args: any[]): void;
22
+ error(message: string, ...args: any[]): void;
23
+ };
24
+ }
25
+ /**
26
+ * Main MemoryLayer SDK client
27
+ */
28
+ declare class MemoryLayerClient {
29
+ private httpClient;
30
+ private _memories?;
31
+ private _search?;
32
+ private _ingest?;
33
+ private _router?;
34
+ constructor(config?: ClientConfig$1);
35
+ /**
36
+ * Access memory operations
37
+ */
38
+ get memories(): any;
39
+ /**
40
+ * Access search operations
41
+ */
42
+ get search(): any;
43
+ /**
44
+ * Access ingestion operations
45
+ */
46
+ get ingest(): any;
47
+ /**
48
+ * Access router operations
49
+ */
50
+ get router(): any;
51
+ }
52
+
53
+ /**
54
+ * Base error class for all MemoryLayer SDK errors
55
+ */
56
+ declare class MemoryLayerError extends Error {
57
+ statusCode?: number | undefined;
58
+ requestId?: string | undefined;
59
+ details?: any | undefined;
60
+ constructor(message: string, statusCode?: number | undefined, requestId?: string | undefined, details?: any | undefined);
61
+ }
62
+ /**
63
+ * Error thrown when authentication fails (401)
64
+ */
65
+ declare class AuthenticationError extends MemoryLayerError {
66
+ constructor(message: string, requestId?: string);
67
+ }
68
+ /**
69
+ * Error thrown when rate limit is exceeded (429)
70
+ */
71
+ declare class RateLimitError extends MemoryLayerError {
72
+ retryAfter: number;
73
+ constructor(message: string, retryAfter: number, requestId?: string);
74
+ }
75
+ /**
76
+ * Validation error detail
77
+ */
78
+ interface ValidationErrorDetail {
79
+ field: string;
80
+ message: string;
81
+ }
82
+ /**
83
+ * Error thrown when request validation fails (400)
84
+ */
85
+ declare class ValidationError extends MemoryLayerError {
86
+ errors: ValidationErrorDetail[];
87
+ constructor(message: string, errors: ValidationErrorDetail[], requestId?: string);
88
+ }
89
+ /**
90
+ * Error thrown when network request fails
91
+ */
92
+ declare class NetworkError extends MemoryLayerError {
93
+ cause: Error;
94
+ constructor(message: string, cause: Error);
95
+ }
96
+ /**
97
+ * Error thrown for other API errors
98
+ */
99
+ declare class APIError extends MemoryLayerError {
100
+ constructor(message: string, statusCode: number, requestId?: string, details?: any);
101
+ }
102
+
103
+ /**
104
+ * Memory object
105
+ */
106
+ interface Memory {
107
+ /** Unique identifier for the memory */
108
+ id: string;
109
+ /** Content of the memory */
110
+ content: string;
111
+ /** Optional metadata associated with the memory */
112
+ metadata?: Record<string, any>;
113
+ /** Project ID this memory belongs to */
114
+ projectId: string;
115
+ /** Timestamp when the memory was created */
116
+ createdAt: string;
117
+ /** Timestamp when the memory was last updated */
118
+ updatedAt: string;
119
+ }
120
+ /**
121
+ * Request to create a new memory
122
+ */
123
+ interface CreateMemoryRequest {
124
+ /** Content of the memory */
125
+ content: string;
126
+ /** Optional metadata to associate with the memory */
127
+ metadata?: Record<string, any>;
128
+ /** Project ID to create the memory in */
129
+ projectId: string;
130
+ }
131
+ /**
132
+ * Request to update an existing memory
133
+ */
134
+ interface UpdateMemoryRequest {
135
+ /** New content for the memory (optional) */
136
+ content?: string;
137
+ /** New metadata for the memory (optional) */
138
+ metadata?: Record<string, any>;
139
+ }
140
+ /**
141
+ * Request to list memories
142
+ */
143
+ interface ListMemoriesRequest {
144
+ /** Project ID to list memories from */
145
+ projectId: string;
146
+ /** Maximum number of memories to return (default: 100) */
147
+ limit?: number;
148
+ /** Number of memories to skip (default: 0) */
149
+ offset?: number;
150
+ /** Filter criteria for memories */
151
+ filter?: Record<string, any>;
152
+ }
153
+ /**
154
+ * Search request
155
+ */
156
+ interface SearchRequest {
157
+ /** Search query */
158
+ query: string;
159
+ /** Project ID to search in */
160
+ projectId: string;
161
+ /** Maximum number of results to return (default: 10) */
162
+ limit?: number;
163
+ /** Filter criteria for search */
164
+ filter?: Record<string, any>;
165
+ /** Minimum relevance score threshold (0-1) */
166
+ threshold?: number;
167
+ }
168
+ /**
169
+ * Search result
170
+ */
171
+ interface SearchResult {
172
+ /** The memory that matched the search */
173
+ memory: Memory;
174
+ /** Relevance score (0-1) */
175
+ score: number;
176
+ /** Highlighted text snippets */
177
+ highlights?: string[];
178
+ }
179
+ /**
180
+ * Search response
181
+ */
182
+ interface SearchResponse {
183
+ /** Array of search results */
184
+ results: SearchResult[];
185
+ /** Total number of results found */
186
+ total: number;
187
+ }
188
+ /**
189
+ * Request to ingest a file
190
+ */
191
+ interface IngestFileRequest {
192
+ /** File to ingest (Buffer, Blob, or File) */
193
+ file: Buffer | Blob | File;
194
+ /** Project ID to ingest into */
195
+ projectId: string;
196
+ /** Optional metadata to associate with ingested memories */
197
+ metadata?: Record<string, any>;
198
+ /** Chunk size for splitting the file (default: 1000) */
199
+ chunkSize?: number;
200
+ /** Overlap between chunks (default: 200) */
201
+ chunkOverlap?: number;
202
+ }
203
+ /**
204
+ * Request to ingest text
205
+ */
206
+ interface IngestTextRequest {
207
+ /** Text to ingest */
208
+ text: string;
209
+ /** Project ID to ingest into */
210
+ projectId: string;
211
+ /** Optional metadata to associate with ingested memories */
212
+ metadata?: Record<string, any>;
213
+ /** Chunk size for splitting the text (default: 1000) */
214
+ chunkSize?: number;
215
+ /** Overlap between chunks (default: 200) */
216
+ chunkOverlap?: number;
217
+ }
218
+ /**
219
+ * Ingestion response
220
+ */
221
+ interface IngestResponse {
222
+ /** IDs of the created memories */
223
+ memoryIds: string[];
224
+ /** Number of chunks created */
225
+ chunksCreated: number;
226
+ }
227
+ /**
228
+ * Message in a conversation
229
+ */
230
+ interface Message {
231
+ /** Role of the message sender */
232
+ role: 'user' | 'assistant' | 'system';
233
+ /** Content of the message */
234
+ content: string;
235
+ }
236
+ /**
237
+ * Router request
238
+ */
239
+ interface RouterRequest {
240
+ /** Array of messages in the conversation */
241
+ messages: Message[];
242
+ /** Project ID for memory context */
243
+ projectId: string;
244
+ /** Model to use (optional) */
245
+ model?: string;
246
+ /** Temperature for generation (0-2, default: 1) */
247
+ temperature?: number;
248
+ /** Maximum tokens to generate */
249
+ maxTokens?: number;
250
+ /** Whether to stream the response */
251
+ stream?: boolean;
252
+ }
253
+ /**
254
+ * Token usage information
255
+ */
256
+ interface Usage {
257
+ /** Number of tokens in the prompt */
258
+ promptTokens: number;
259
+ /** Number of tokens in the completion */
260
+ completionTokens: number;
261
+ /** Total number of tokens used */
262
+ totalTokens: number;
263
+ }
264
+ /**
265
+ * Choice in a router response
266
+ */
267
+ interface Choice {
268
+ /** The generated message */
269
+ message: Message;
270
+ /** Reason why generation finished */
271
+ finishReason: string;
272
+ }
273
+ /**
274
+ * Router response
275
+ */
276
+ interface RouterResponse {
277
+ /** Unique identifier for the response */
278
+ id: string;
279
+ /** Array of choices (usually one) */
280
+ choices: Choice[];
281
+ /** Token usage information */
282
+ usage: Usage;
283
+ }
284
+ /**
285
+ * Delta in a streaming choice
286
+ */
287
+ interface StreamDelta {
288
+ /** Role of the message (only in first chunk) */
289
+ role?: string;
290
+ /** Content chunk */
291
+ content?: string;
292
+ }
293
+ /**
294
+ * Choice in a streaming response
295
+ */
296
+ interface StreamChoice {
297
+ /** Delta containing the new content */
298
+ delta: StreamDelta;
299
+ /** Reason why generation finished (only in last chunk) */
300
+ finishReason?: string;
301
+ }
302
+ /**
303
+ * Streaming chunk from router
304
+ */
305
+ interface StreamChunk {
306
+ /** Unique identifier for the response */
307
+ id: string;
308
+ /** Array of streaming choices */
309
+ choices: StreamChoice[];
310
+ }
311
+
312
+ /**
313
+ * Configuration for the HTTP client
314
+ */
315
+ interface ClientConfig {
316
+ apiKey: string;
317
+ baseURL?: string;
318
+ timeout?: number;
319
+ maxRetries?: number;
320
+ retryDelay?: number;
321
+ headers?: Record<string, string>;
322
+ logger?: Logger;
323
+ }
324
+ /**
325
+ * Logger interface
326
+ */
327
+ interface Logger {
328
+ debug(message: string, ...args: any[]): void;
329
+ info(message: string, ...args: any[]): void;
330
+ warn(message: string, ...args: any[]): void;
331
+ error(message: string, ...args: any[]): void;
332
+ }
333
+ /**
334
+ * Retry configuration
335
+ */
336
+ interface RetryConfig {
337
+ maxRetries: number;
338
+ initialDelay: number;
339
+ maxDelay: number;
340
+ backoffMultiplier: number;
341
+ retryableStatusCodes: number[];
342
+ }
343
+ /**
344
+ * Request options
345
+ */
346
+ interface RequestOptions {
347
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
348
+ path: string;
349
+ body?: any;
350
+ query?: Record<string, string>;
351
+ headers?: Record<string, string>;
352
+ timeout?: number;
353
+ }
354
+ /**
355
+ * HTTP client with retry logic and error handling
356
+ */
357
+ declare class HTTPClient {
358
+ private config;
359
+ private retryConfig;
360
+ private baseURL;
361
+ constructor(config: ClientConfig, retryConfig?: Partial<RetryConfig>);
362
+ /**
363
+ * Make an HTTP request with retry logic
364
+ */
365
+ request<T>(options: RequestOptions): Promise<T>;
366
+ /**
367
+ * Make a streaming request
368
+ */
369
+ stream(options: RequestOptions): AsyncIterable<any>;
370
+ /**
371
+ * Make the actual HTTP request
372
+ */
373
+ private makeRequest;
374
+ /**
375
+ * Build the full URL with query parameters
376
+ */
377
+ private buildURL;
378
+ /**
379
+ * Build request headers
380
+ */
381
+ private buildHeaders;
382
+ /**
383
+ * Handle error responses from the API
384
+ */
385
+ private handleErrorResponse;
386
+ /**
387
+ * Determine if an error should be retried
388
+ */
389
+ private shouldRetry;
390
+ /**
391
+ * Calculate retry delay with exponential backoff
392
+ */
393
+ private getRetryDelay;
394
+ /**
395
+ * Sleep for a specified duration
396
+ */
397
+ private sleep;
398
+ }
399
+
400
+ /**
401
+ * Resource for memory operations
402
+ */
403
+ declare class MemoriesResource {
404
+ private httpClient;
405
+ constructor(httpClient: HTTPClient);
406
+ /**
407
+ * Add a new memory
408
+ * @param request - Memory creation request
409
+ * @returns The created memory
410
+ */
411
+ add(request: CreateMemoryRequest): Promise<Memory>;
412
+ /**
413
+ * Get a memory by ID
414
+ * @param id - Memory ID
415
+ * @returns The memory
416
+ */
417
+ get(id: string): Promise<Memory>;
418
+ /**
419
+ * Update a memory
420
+ * @param id - Memory ID
421
+ * @param request - Update request
422
+ * @returns The updated memory
423
+ */
424
+ update(id: string, request: UpdateMemoryRequest): Promise<Memory>;
425
+ /**
426
+ * Delete a memory
427
+ * @param id - Memory ID
428
+ */
429
+ delete(id: string): Promise<void>;
430
+ /**
431
+ * List memories
432
+ * @param request - List request with filters
433
+ * @returns Array of memories
434
+ */
435
+ list(request: ListMemoriesRequest): Promise<Memory[]>;
436
+ }
437
+
438
+ /**
439
+ * Resource for search operations
440
+ */
441
+ declare class SearchResource {
442
+ private httpClient;
443
+ constructor(httpClient: HTTPClient);
444
+ /**
445
+ * Search memories
446
+ * @param request - Search request
447
+ * @returns Search results
448
+ */
449
+ search(request: SearchRequest): Promise<SearchResponse>;
450
+ }
451
+
452
+ /**
453
+ * Resource for ingestion operations
454
+ */
455
+ declare class IngestResource {
456
+ private httpClient;
457
+ constructor(httpClient: HTTPClient);
458
+ /**
459
+ * Ingest a file
460
+ * @param request - File ingestion request
461
+ * @returns Ingestion response with created memory IDs
462
+ */
463
+ file(request: IngestFileRequest): Promise<IngestResponse>;
464
+ /**
465
+ * Ingest text
466
+ * @param request - Text ingestion request
467
+ * @returns Ingestion response with created memory IDs
468
+ */
469
+ text(request: IngestTextRequest): Promise<IngestResponse>;
470
+ }
471
+
472
+ /**
473
+ * Resource for router operations
474
+ */
475
+ declare class RouterResource {
476
+ private httpClient;
477
+ constructor(httpClient: HTTPClient);
478
+ /**
479
+ * Complete a router request (non-streaming)
480
+ * @param request - Router request
481
+ * @returns Router response
482
+ */
483
+ complete(request: RouterRequest): Promise<RouterResponse>;
484
+ /**
485
+ * Stream a router request
486
+ * @param request - Router request
487
+ * @returns Async iterable of stream chunks
488
+ */
489
+ stream(request: RouterRequest): AsyncIterable<StreamChunk>;
490
+ }
491
+
492
+ export { APIError, AuthenticationError, type Choice, type ClientConfig$1 as ClientConfig, type CreateMemoryRequest, type IngestFileRequest, IngestResource, type IngestResponse, type IngestTextRequest, type ListMemoriesRequest, MemoriesResource, type Memory, MemoryLayerClient, MemoryLayerError, type Message, NetworkError, RateLimitError, type RouterRequest, RouterResource, type RouterResponse, type SearchRequest, SearchResource, type SearchResponse, type SearchResult, type StreamChoice, type StreamChunk, type StreamDelta, type UpdateMemoryRequest, type Usage, ValidationError, type ValidationErrorDetail };