@lanonasis/memory-client 1.0.1 → 2.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.
- package/dist/core/index.d.ts +948 -0
- package/dist/core/index.js +1027 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/tsconfig.tsbuildinfo +1 -0
- package/dist/index.d.ts +703 -352
- package/dist/index.esm.js +1070 -277
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1098 -283
- package/dist/index.js.map +1 -1
- package/dist/node/index.d.ts +329 -0
- package/dist/node/index.js +647 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/tsconfig.tsbuildinfo +1 -0
- package/dist/presets/index.d.ts +146 -0
- package/dist/presets/index.js +234 -0
- package/dist/presets/index.js.map +1 -0
- package/dist/presets/tsconfig.tsbuildinfo +1 -0
- package/dist/react/index.d.ts +235 -0
- package/dist/react/index.js +333 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/tsconfig.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/vue/index.d.ts +316 -0
- package/dist/vue/index.js +341 -0
- package/dist/vue/index.js.map +1 -0
- package/dist/vue/tsconfig.tsbuildinfo +1 -0
- package/package.json +67 -13
package/dist/index.d.ts
CHANGED
|
@@ -142,32 +142,489 @@ type CreateMemoryRequest = z.infer<typeof createMemorySchema>;
|
|
|
142
142
|
type UpdateMemoryRequest = z.infer<typeof updateMemorySchema>;
|
|
143
143
|
type SearchMemoryRequest = z.infer<typeof searchMemorySchema>;
|
|
144
144
|
type CreateTopicRequest = z.infer<typeof createTopicSchema>;
|
|
145
|
+
/**
|
|
146
|
+
* Chunking strategies for content preprocessing
|
|
147
|
+
*/
|
|
148
|
+
declare const CHUNKING_STRATEGIES: readonly ["semantic", "fixed-size", "paragraph", "sentence", "code-block"];
|
|
149
|
+
type ChunkingStrategy = typeof CHUNKING_STRATEGIES[number];
|
|
150
|
+
/**
|
|
151
|
+
* Content types detected or specified
|
|
152
|
+
*/
|
|
153
|
+
declare const CONTENT_TYPES: readonly ["text", "code", "markdown", "json", "yaml"];
|
|
154
|
+
type ContentType = typeof CONTENT_TYPES[number];
|
|
155
|
+
/**
|
|
156
|
+
* A chunk of content from a memory entry
|
|
157
|
+
*/
|
|
158
|
+
interface ContentChunk {
|
|
159
|
+
index: number;
|
|
160
|
+
content: string;
|
|
161
|
+
startChar: number;
|
|
162
|
+
endChar: number;
|
|
163
|
+
tokens: number;
|
|
164
|
+
metadata?: {
|
|
165
|
+
type: 'paragraph' | 'sentence' | 'code' | 'section';
|
|
166
|
+
isComplete: boolean;
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Extracted intelligence from memory content
|
|
171
|
+
*/
|
|
172
|
+
interface MemoryIntelligence {
|
|
173
|
+
entities: string[];
|
|
174
|
+
keywords: string[];
|
|
175
|
+
language: string;
|
|
176
|
+
topics?: string[];
|
|
177
|
+
sentiment?: 'positive' | 'neutral' | 'negative';
|
|
178
|
+
complexity?: 'low' | 'medium' | 'high';
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Extended metadata with intelligence features
|
|
182
|
+
*/
|
|
183
|
+
interface IntelligentMetadata extends Record<string, unknown> {
|
|
184
|
+
chunks?: ContentChunk[];
|
|
185
|
+
total_chunks?: number;
|
|
186
|
+
chunking_strategy?: ChunkingStrategy;
|
|
187
|
+
last_rechunked_at?: string;
|
|
188
|
+
intelligence?: MemoryIntelligence;
|
|
189
|
+
content_type?: ContentType;
|
|
190
|
+
language?: string;
|
|
191
|
+
tokens?: number;
|
|
192
|
+
source?: string;
|
|
193
|
+
priority?: 'high' | 'medium' | 'low';
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Preprocessing options for memory creation/update
|
|
197
|
+
*/
|
|
198
|
+
interface PreprocessingOptions {
|
|
199
|
+
chunking?: {
|
|
200
|
+
strategy?: ChunkingStrategy;
|
|
201
|
+
maxChunkSize?: number;
|
|
202
|
+
overlap?: number;
|
|
203
|
+
};
|
|
204
|
+
cleanContent?: boolean;
|
|
205
|
+
extractMetadata?: boolean;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Extended create memory request with preprocessing
|
|
209
|
+
*/
|
|
210
|
+
interface CreateMemoryWithPreprocessingRequest extends CreateMemoryRequest {
|
|
211
|
+
preprocessing?: PreprocessingOptions;
|
|
212
|
+
metadata?: IntelligentMetadata;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Extended update memory request with re-chunking
|
|
216
|
+
*/
|
|
217
|
+
interface UpdateMemoryWithPreprocessingRequest extends UpdateMemoryRequest {
|
|
218
|
+
rechunk?: boolean;
|
|
219
|
+
regenerate_embedding?: boolean;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Search modes for memory queries
|
|
223
|
+
*/
|
|
224
|
+
declare const SEARCH_MODES: readonly ["vector", "text", "hybrid"];
|
|
225
|
+
type SearchMode = typeof SEARCH_MODES[number];
|
|
226
|
+
/**
|
|
227
|
+
* A matching chunk from search results
|
|
228
|
+
*/
|
|
229
|
+
interface MatchingChunk {
|
|
230
|
+
index: number;
|
|
231
|
+
content: string;
|
|
232
|
+
similarity: number;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Enhanced search filters
|
|
236
|
+
*/
|
|
237
|
+
interface SearchFilters {
|
|
238
|
+
tags?: string[];
|
|
239
|
+
project_id?: string;
|
|
240
|
+
topic_id?: string;
|
|
241
|
+
date_range?: {
|
|
242
|
+
from?: string;
|
|
243
|
+
to?: string;
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Enhanced search request with hybrid mode
|
|
248
|
+
*/
|
|
249
|
+
interface EnhancedSearchRequest {
|
|
250
|
+
query: string;
|
|
251
|
+
type?: MemoryType;
|
|
252
|
+
threshold?: number;
|
|
253
|
+
limit?: number;
|
|
254
|
+
search_mode?: SearchMode;
|
|
255
|
+
filters?: SearchFilters;
|
|
256
|
+
include_chunks?: boolean;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Enhanced search result with chunk matching
|
|
260
|
+
*/
|
|
261
|
+
interface EnhancedMemorySearchResult extends MemorySearchResult {
|
|
262
|
+
text_rank?: number;
|
|
263
|
+
combined_score?: number;
|
|
264
|
+
matching_chunks?: MatchingChunk[];
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Enhanced search response
|
|
268
|
+
*/
|
|
269
|
+
interface EnhancedSearchResponse {
|
|
270
|
+
results: EnhancedMemorySearchResult[];
|
|
271
|
+
total: number;
|
|
272
|
+
query: string;
|
|
273
|
+
search_mode: SearchMode;
|
|
274
|
+
threshold: number;
|
|
275
|
+
execution_time_ms: number;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Search analytics data point
|
|
279
|
+
*/
|
|
280
|
+
interface SearchAnalyticsDataPoint {
|
|
281
|
+
date: string;
|
|
282
|
+
searches: number;
|
|
283
|
+
avg_results: number;
|
|
284
|
+
avg_time_ms: number;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Popular query entry
|
|
288
|
+
*/
|
|
289
|
+
interface PopularQuery {
|
|
290
|
+
query: string;
|
|
291
|
+
count: number;
|
|
292
|
+
avg_results: number;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Search analytics response
|
|
296
|
+
*/
|
|
297
|
+
interface SearchAnalytics {
|
|
298
|
+
total_searches: number;
|
|
299
|
+
avg_results_count: number;
|
|
300
|
+
avg_execution_time_ms: number;
|
|
301
|
+
search_types: {
|
|
302
|
+
vector: number;
|
|
303
|
+
text: number;
|
|
304
|
+
hybrid: number;
|
|
305
|
+
};
|
|
306
|
+
by_date: SearchAnalyticsDataPoint[];
|
|
307
|
+
popular_queries: PopularQuery[];
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Most accessed memory entry
|
|
311
|
+
*/
|
|
312
|
+
interface MostAccessedMemory {
|
|
313
|
+
memory_id: string;
|
|
314
|
+
title: string;
|
|
315
|
+
access_count: number;
|
|
316
|
+
last_accessed: string;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Hourly access data
|
|
320
|
+
*/
|
|
321
|
+
interface HourlyAccess {
|
|
322
|
+
hour: number;
|
|
323
|
+
count: number;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Access patterns response
|
|
327
|
+
*/
|
|
328
|
+
interface AccessPatterns {
|
|
329
|
+
total_accesses: number;
|
|
330
|
+
by_type: {
|
|
331
|
+
read: number;
|
|
332
|
+
update: number;
|
|
333
|
+
delete: number;
|
|
334
|
+
};
|
|
335
|
+
by_method: {
|
|
336
|
+
api: number;
|
|
337
|
+
search: number;
|
|
338
|
+
direct: number;
|
|
339
|
+
};
|
|
340
|
+
most_accessed: MostAccessedMemory[];
|
|
341
|
+
access_by_hour: HourlyAccess[];
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Project memory count
|
|
345
|
+
*/
|
|
346
|
+
interface ProjectMemoryCount {
|
|
347
|
+
project_id: string;
|
|
348
|
+
project_name: string;
|
|
349
|
+
count: number;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Tag count entry
|
|
353
|
+
*/
|
|
354
|
+
interface TagCount {
|
|
355
|
+
tag: string;
|
|
356
|
+
count: number;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Extended memory statistics
|
|
360
|
+
*/
|
|
361
|
+
interface ExtendedMemoryStats {
|
|
362
|
+
total_memories: number;
|
|
363
|
+
by_type: Record<MemoryType, number>;
|
|
364
|
+
by_project: ProjectMemoryCount[];
|
|
365
|
+
storage: {
|
|
366
|
+
total_size_mb: number;
|
|
367
|
+
avg_memory_size_kb: number;
|
|
368
|
+
total_chunks: number;
|
|
369
|
+
};
|
|
370
|
+
activity: {
|
|
371
|
+
created_today: number;
|
|
372
|
+
updated_today: number;
|
|
373
|
+
searched_today: number;
|
|
374
|
+
};
|
|
375
|
+
top_tags: TagCount[];
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Analytics date range filter
|
|
379
|
+
*/
|
|
380
|
+
interface AnalyticsDateRange {
|
|
381
|
+
from?: string;
|
|
382
|
+
to?: string;
|
|
383
|
+
group_by?: 'day' | 'week' | 'month';
|
|
384
|
+
}
|
|
385
|
+
declare const preprocessingOptionsSchema: z.ZodOptional<z.ZodObject<{
|
|
386
|
+
chunking: z.ZodOptional<z.ZodObject<{
|
|
387
|
+
strategy: z.ZodOptional<z.ZodEnum<{
|
|
388
|
+
semantic: "semantic";
|
|
389
|
+
"fixed-size": "fixed-size";
|
|
390
|
+
paragraph: "paragraph";
|
|
391
|
+
sentence: "sentence";
|
|
392
|
+
"code-block": "code-block";
|
|
393
|
+
}>>;
|
|
394
|
+
maxChunkSize: z.ZodOptional<z.ZodNumber>;
|
|
395
|
+
overlap: z.ZodOptional<z.ZodNumber>;
|
|
396
|
+
}, z.core.$strip>>;
|
|
397
|
+
cleanContent: z.ZodOptional<z.ZodBoolean>;
|
|
398
|
+
extractMetadata: z.ZodOptional<z.ZodBoolean>;
|
|
399
|
+
}, z.core.$strip>>;
|
|
400
|
+
declare const enhancedSearchSchema: z.ZodObject<{
|
|
401
|
+
query: z.ZodString;
|
|
402
|
+
type: z.ZodOptional<z.ZodEnum<{
|
|
403
|
+
context: "context";
|
|
404
|
+
project: "project";
|
|
405
|
+
knowledge: "knowledge";
|
|
406
|
+
reference: "reference";
|
|
407
|
+
personal: "personal";
|
|
408
|
+
workflow: "workflow";
|
|
409
|
+
}>>;
|
|
410
|
+
threshold: z.ZodDefault<z.ZodNumber>;
|
|
411
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
412
|
+
search_mode: z.ZodDefault<z.ZodEnum<{
|
|
413
|
+
text: "text";
|
|
414
|
+
vector: "vector";
|
|
415
|
+
hybrid: "hybrid";
|
|
416
|
+
}>>;
|
|
417
|
+
filters: z.ZodOptional<z.ZodObject<{
|
|
418
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
419
|
+
project_id: z.ZodOptional<z.ZodString>;
|
|
420
|
+
topic_id: z.ZodOptional<z.ZodString>;
|
|
421
|
+
date_range: z.ZodOptional<z.ZodObject<{
|
|
422
|
+
from: z.ZodOptional<z.ZodString>;
|
|
423
|
+
to: z.ZodOptional<z.ZodString>;
|
|
424
|
+
}, z.core.$strip>>;
|
|
425
|
+
}, z.core.$strip>>;
|
|
426
|
+
include_chunks: z.ZodDefault<z.ZodBoolean>;
|
|
427
|
+
}, z.core.$strip>;
|
|
428
|
+
declare const analyticsDateRangeSchema: z.ZodObject<{
|
|
429
|
+
from: z.ZodOptional<z.ZodString>;
|
|
430
|
+
to: z.ZodOptional<z.ZodString>;
|
|
431
|
+
group_by: z.ZodDefault<z.ZodEnum<{
|
|
432
|
+
day: "day";
|
|
433
|
+
week: "week";
|
|
434
|
+
month: "month";
|
|
435
|
+
}>>;
|
|
436
|
+
}, z.core.$strip>;
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Error handling for Memory Client
|
|
440
|
+
* Browser-safe, no Node.js dependencies
|
|
441
|
+
*/
|
|
442
|
+
/**
|
|
443
|
+
* Standardized error codes for programmatic error handling
|
|
444
|
+
*/
|
|
445
|
+
declare const ERROR_CODES: readonly ["API_ERROR", "AUTH_ERROR", "VALIDATION_ERROR", "TIMEOUT_ERROR", "RATE_LIMIT_ERROR", "NOT_FOUND", "NETWORK_ERROR", "FORBIDDEN", "CONFLICT", "SERVER_ERROR"];
|
|
446
|
+
type ErrorCode = typeof ERROR_CODES[number];
|
|
447
|
+
/**
|
|
448
|
+
* Structured API error response - replaces plain string errors
|
|
449
|
+
* Enables programmatic error handling with typed codes
|
|
450
|
+
*/
|
|
451
|
+
interface ApiErrorResponse {
|
|
452
|
+
/** Machine-readable error code for programmatic handling */
|
|
453
|
+
code: ErrorCode;
|
|
454
|
+
/** Human-readable error message */
|
|
455
|
+
message: string;
|
|
456
|
+
/** HTTP status code if from API response */
|
|
457
|
+
statusCode?: number;
|
|
458
|
+
/** Additional error details (validation errors, etc.) */
|
|
459
|
+
details?: unknown;
|
|
460
|
+
/** Request ID for debugging/support */
|
|
461
|
+
requestId?: string;
|
|
462
|
+
/** Timestamp when error occurred */
|
|
463
|
+
timestamp?: string;
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Type guard to check if an object is an ApiErrorResponse
|
|
467
|
+
*/
|
|
468
|
+
declare function isApiErrorResponse(value: unknown): value is ApiErrorResponse;
|
|
469
|
+
/**
|
|
470
|
+
* Base error class for Memory Client errors
|
|
471
|
+
*/
|
|
472
|
+
declare class MemoryClientError extends Error {
|
|
473
|
+
code: ErrorCode;
|
|
474
|
+
statusCode?: number | undefined;
|
|
475
|
+
details?: unknown | undefined;
|
|
476
|
+
constructor(message: string, code?: ErrorCode, statusCode?: number | undefined, details?: unknown | undefined);
|
|
477
|
+
/**
|
|
478
|
+
* Convert to ApiErrorResponse for consistent API responses
|
|
479
|
+
*/
|
|
480
|
+
toResponse(): ApiErrorResponse;
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Network/API error
|
|
484
|
+
*/
|
|
485
|
+
declare class ApiError extends MemoryClientError {
|
|
486
|
+
constructor(message: string, statusCode?: number, details?: unknown);
|
|
487
|
+
/**
|
|
488
|
+
* Create from an HTTP response
|
|
489
|
+
*/
|
|
490
|
+
static fromResponse(status: number, statusText: string, body?: unknown): ApiError;
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Authentication error
|
|
494
|
+
*/
|
|
495
|
+
declare class AuthenticationError extends MemoryClientError {
|
|
496
|
+
constructor(message?: string);
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Validation error with field-level details
|
|
500
|
+
*/
|
|
501
|
+
declare class ValidationError extends MemoryClientError {
|
|
502
|
+
readonly validationErrors: Array<{
|
|
503
|
+
field: string;
|
|
504
|
+
message: string;
|
|
505
|
+
}>;
|
|
506
|
+
constructor(message: string, details?: unknown);
|
|
507
|
+
/**
|
|
508
|
+
* Create from Zod error
|
|
509
|
+
*/
|
|
510
|
+
static fromZodError(error: {
|
|
511
|
+
issues: Array<{
|
|
512
|
+
path: (string | number)[];
|
|
513
|
+
message: string;
|
|
514
|
+
}>;
|
|
515
|
+
}): ValidationError;
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Timeout error
|
|
519
|
+
*/
|
|
520
|
+
declare class TimeoutError extends MemoryClientError {
|
|
521
|
+
constructor(message?: string);
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Rate limit error with retry-after info
|
|
525
|
+
*/
|
|
526
|
+
declare class RateLimitError extends MemoryClientError {
|
|
527
|
+
readonly retryAfter?: number;
|
|
528
|
+
constructor(message?: string, retryAfter?: number);
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Not found error
|
|
532
|
+
*/
|
|
533
|
+
declare class NotFoundError extends MemoryClientError {
|
|
534
|
+
readonly resource: string;
|
|
535
|
+
constructor(resource: string);
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* Network error (no response received)
|
|
539
|
+
*/
|
|
540
|
+
declare class NetworkError extends MemoryClientError {
|
|
541
|
+
constructor(message?: string);
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Server error (5xx responses)
|
|
545
|
+
*/
|
|
546
|
+
declare class ServerError extends MemoryClientError {
|
|
547
|
+
constructor(message: string, statusCode?: number);
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Create appropriate error class from status code
|
|
551
|
+
*/
|
|
552
|
+
declare function createErrorFromStatus(status: number, message: string, details?: unknown): MemoryClientError;
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Core Memory Client - Pure Browser-Safe Implementation
|
|
556
|
+
*
|
|
557
|
+
* NO Node.js dependencies, NO CLI code, NO child_process
|
|
558
|
+
* Works in: Browser, React Native, Cloudflare Workers, Edge Functions, Deno, Bun
|
|
559
|
+
*
|
|
560
|
+
* Bundle size: ~15KB gzipped
|
|
561
|
+
*/
|
|
145
562
|
|
|
146
563
|
/**
|
|
147
564
|
* Configuration options for the Memory Client
|
|
148
565
|
*/
|
|
149
|
-
interface
|
|
566
|
+
interface CoreMemoryClientConfig {
|
|
150
567
|
/** API endpoint URL */
|
|
151
568
|
apiUrl: string;
|
|
152
569
|
/** API key for authentication */
|
|
153
570
|
apiKey?: string;
|
|
154
571
|
/** Bearer token for authentication (alternative to API key) */
|
|
155
572
|
authToken?: string;
|
|
156
|
-
/**
|
|
573
|
+
/** Organization ID (optional - will be auto-resolved if not provided) */
|
|
574
|
+
organizationId?: string;
|
|
575
|
+
/** User ID (optional - used as fallback for organization ID) */
|
|
576
|
+
userId?: string;
|
|
577
|
+
/** Request timeout in milliseconds (default: 30000) */
|
|
157
578
|
timeout?: number;
|
|
158
|
-
/** Enable gateway mode for enhanced performance */
|
|
159
|
-
useGateway?: boolean;
|
|
160
579
|
/** Custom headers to include with requests */
|
|
161
580
|
headers?: Record<string, string>;
|
|
581
|
+
/** Retry configuration */
|
|
582
|
+
retry?: {
|
|
583
|
+
maxRetries?: number;
|
|
584
|
+
retryDelay?: number;
|
|
585
|
+
backoff?: 'linear' | 'exponential';
|
|
586
|
+
};
|
|
587
|
+
/** Cache configuration (browser only) */
|
|
588
|
+
cache?: {
|
|
589
|
+
enabled?: boolean;
|
|
590
|
+
ttl?: number;
|
|
591
|
+
};
|
|
592
|
+
/** Called when an error occurs */
|
|
593
|
+
onError?: (error: ApiErrorResponse) => void;
|
|
594
|
+
/** Called before each request */
|
|
595
|
+
onRequest?: (endpoint: string) => void;
|
|
596
|
+
/** Called after each response */
|
|
597
|
+
onResponse?: (endpoint: string, duration: number) => void;
|
|
162
598
|
}
|
|
163
599
|
/**
|
|
164
|
-
* Standard API response wrapper
|
|
600
|
+
* Standard API response wrapper with typed errors
|
|
601
|
+
* Replaces string errors with structured ApiErrorResponse
|
|
165
602
|
*/
|
|
166
603
|
interface ApiResponse<T> {
|
|
167
604
|
data?: T;
|
|
168
|
-
error
|
|
605
|
+
/** Structured error response for programmatic handling */
|
|
606
|
+
error?: ApiErrorResponse;
|
|
607
|
+
/** Optional success message */
|
|
169
608
|
message?: string;
|
|
609
|
+
/** Request metadata */
|
|
610
|
+
meta?: {
|
|
611
|
+
requestId?: string;
|
|
612
|
+
duration?: number;
|
|
613
|
+
retries?: number;
|
|
614
|
+
};
|
|
170
615
|
}
|
|
616
|
+
/**
|
|
617
|
+
* Helper to check if response has error
|
|
618
|
+
*/
|
|
619
|
+
declare function hasError<T>(response: ApiResponse<T>): response is ApiResponse<T> & {
|
|
620
|
+
error: ApiErrorResponse;
|
|
621
|
+
};
|
|
622
|
+
/**
|
|
623
|
+
* Helper to check if response has data
|
|
624
|
+
*/
|
|
625
|
+
declare function hasData<T>(response: ApiResponse<T>): response is ApiResponse<T> & {
|
|
626
|
+
data: T;
|
|
627
|
+
};
|
|
171
628
|
/**
|
|
172
629
|
* Paginated response for list operations
|
|
173
630
|
*/
|
|
@@ -181,16 +638,28 @@ interface PaginatedResponse<T> {
|
|
|
181
638
|
};
|
|
182
639
|
}
|
|
183
640
|
/**
|
|
184
|
-
* Memory Client class for interacting with the Memory as a Service API
|
|
641
|
+
* Core Memory Client class for interacting with the Memory as a Service API
|
|
642
|
+
*
|
|
643
|
+
* This is a pure browser-safe client with zero Node.js dependencies.
|
|
644
|
+
* It uses only standard web APIs (fetch, AbortController, etc.)
|
|
185
645
|
*/
|
|
186
|
-
declare class
|
|
646
|
+
declare class CoreMemoryClient {
|
|
187
647
|
private config;
|
|
188
648
|
private baseHeaders;
|
|
189
|
-
constructor(config:
|
|
649
|
+
constructor(config: CoreMemoryClientConfig);
|
|
190
650
|
/**
|
|
191
|
-
*
|
|
651
|
+
* Enrich request body with organization context if configured
|
|
652
|
+
* This ensures the API has the organization_id even if not in auth token
|
|
653
|
+
*/
|
|
654
|
+
private enrichWithOrgContext;
|
|
655
|
+
/**
|
|
656
|
+
* Make an HTTP request to the API with retry support
|
|
192
657
|
*/
|
|
193
658
|
private request;
|
|
659
|
+
/**
|
|
660
|
+
* Validate input using Zod schema and return validation error if invalid
|
|
661
|
+
*/
|
|
662
|
+
private validateInput;
|
|
194
663
|
/**
|
|
195
664
|
* Test the API connection and authentication
|
|
196
665
|
*/
|
|
@@ -199,7 +668,7 @@ declare class MemoryClient {
|
|
|
199
668
|
timestamp: string;
|
|
200
669
|
}>>;
|
|
201
670
|
/**
|
|
202
|
-
* Create a new memory
|
|
671
|
+
* Create a new memory with validation
|
|
203
672
|
*/
|
|
204
673
|
createMemory(memory: CreateMemoryRequest): Promise<ApiResponse<MemoryEntry>>;
|
|
205
674
|
/**
|
|
@@ -207,7 +676,7 @@ declare class MemoryClient {
|
|
|
207
676
|
*/
|
|
208
677
|
getMemory(id: string): Promise<ApiResponse<MemoryEntry>>;
|
|
209
678
|
/**
|
|
210
|
-
* Update an existing memory
|
|
679
|
+
* Update an existing memory with validation
|
|
211
680
|
*/
|
|
212
681
|
updateMemory(id: string, updates: UpdateMemoryRequest): Promise<ApiResponse<MemoryEntry>>;
|
|
213
682
|
/**
|
|
@@ -229,7 +698,7 @@ declare class MemoryClient {
|
|
|
229
698
|
order?: 'asc' | 'desc';
|
|
230
699
|
}): Promise<ApiResponse<PaginatedResponse<MemoryEntry>>>;
|
|
231
700
|
/**
|
|
232
|
-
* Search memories using semantic search
|
|
701
|
+
* Search memories using semantic search with validation
|
|
233
702
|
*/
|
|
234
703
|
searchMemories(request: SearchMemoryRequest): Promise<ApiResponse<{
|
|
235
704
|
results: MemorySearchResult[];
|
|
@@ -244,7 +713,7 @@ declare class MemoryClient {
|
|
|
244
713
|
failed_ids: string[];
|
|
245
714
|
}>>;
|
|
246
715
|
/**
|
|
247
|
-
* Create a new topic
|
|
716
|
+
* Create a new topic with validation
|
|
248
717
|
*/
|
|
249
718
|
createTopic(topic: CreateTopicRequest): Promise<ApiResponse<MemoryTopic>>;
|
|
250
719
|
/**
|
|
@@ -268,409 +737,291 @@ declare class MemoryClient {
|
|
|
268
737
|
*/
|
|
269
738
|
getMemoryStats(): Promise<ApiResponse<UserMemoryStats>>;
|
|
270
739
|
/**
|
|
271
|
-
*
|
|
740
|
+
* Create a memory with preprocessing options (chunking, intelligence extraction)
|
|
741
|
+
*
|
|
742
|
+
* @example
|
|
743
|
+
* ```typescript
|
|
744
|
+
* const result = await client.createMemoryWithPreprocessing({
|
|
745
|
+
* title: 'Auth System Docs',
|
|
746
|
+
* content: 'Long content...',
|
|
747
|
+
* memory_type: 'knowledge',
|
|
748
|
+
* preprocessing: {
|
|
749
|
+
* chunking: { strategy: 'semantic', maxChunkSize: 1000 },
|
|
750
|
+
* extractMetadata: true
|
|
751
|
+
* }
|
|
752
|
+
* });
|
|
753
|
+
* ```
|
|
272
754
|
*/
|
|
273
|
-
|
|
755
|
+
createMemoryWithPreprocessing(memory: CreateMemoryWithPreprocessingRequest): Promise<ApiResponse<MemoryEntry>>;
|
|
274
756
|
/**
|
|
275
|
-
* Update
|
|
757
|
+
* Update a memory with re-chunking and embedding regeneration
|
|
758
|
+
*
|
|
759
|
+
* @example
|
|
760
|
+
* ```typescript
|
|
761
|
+
* const result = await client.updateMemoryWithPreprocessing('mem_123', {
|
|
762
|
+
* content: 'Updated content...',
|
|
763
|
+
* rechunk: true,
|
|
764
|
+
* regenerate_embedding: true
|
|
765
|
+
* });
|
|
766
|
+
* ```
|
|
276
767
|
*/
|
|
277
|
-
|
|
768
|
+
updateMemoryWithPreprocessing(id: string, updates: UpdateMemoryWithPreprocessingRequest): Promise<ApiResponse<MemoryEntry>>;
|
|
278
769
|
/**
|
|
279
|
-
*
|
|
770
|
+
* Enhanced semantic search with hybrid mode (vector + text)
|
|
771
|
+
*
|
|
772
|
+
* @example
|
|
773
|
+
* ```typescript
|
|
774
|
+
* const result = await client.enhancedSearch({
|
|
775
|
+
* query: 'authentication flow',
|
|
776
|
+
* search_mode: 'hybrid',
|
|
777
|
+
* filters: { tags: ['auth'], project_id: 'proj_123' },
|
|
778
|
+
* include_chunks: true
|
|
779
|
+
* });
|
|
780
|
+
* ```
|
|
280
781
|
*/
|
|
281
|
-
|
|
782
|
+
enhancedSearch(request: EnhancedSearchRequest): Promise<ApiResponse<EnhancedSearchResponse>>;
|
|
282
783
|
/**
|
|
283
|
-
*
|
|
784
|
+
* Get search analytics data
|
|
785
|
+
*
|
|
786
|
+
* @example
|
|
787
|
+
* ```typescript
|
|
788
|
+
* const analytics = await client.getSearchAnalytics({
|
|
789
|
+
* from: '2025-01-01',
|
|
790
|
+
* to: '2025-12-31',
|
|
791
|
+
* group_by: 'day'
|
|
792
|
+
* });
|
|
793
|
+
* ```
|
|
284
794
|
*/
|
|
285
|
-
|
|
795
|
+
getSearchAnalytics(options?: AnalyticsDateRange): Promise<ApiResponse<SearchAnalytics>>;
|
|
286
796
|
/**
|
|
287
|
-
* Get
|
|
797
|
+
* Get memory access patterns
|
|
798
|
+
*
|
|
799
|
+
* @example
|
|
800
|
+
* ```typescript
|
|
801
|
+
* const patterns = await client.getAccessPatterns({
|
|
802
|
+
* from: '2025-01-01',
|
|
803
|
+
* to: '2025-12-31'
|
|
804
|
+
* });
|
|
805
|
+
* console.log(patterns.data?.most_accessed);
|
|
806
|
+
* ```
|
|
288
807
|
*/
|
|
289
|
-
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Factory function to create a new Memory Client instance
|
|
293
|
-
*/
|
|
294
|
-
declare function createMemoryClient(config: MemoryClientConfig): MemoryClient;
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* CLI Integration Module for Memory Client SDK
|
|
298
|
-
*
|
|
299
|
-
* Provides intelligent CLI detection and MCP channel utilization
|
|
300
|
-
* when @lanonasis/cli v1.5.2+ is available in the environment
|
|
301
|
-
*/
|
|
302
|
-
|
|
303
|
-
interface CLIInfo {
|
|
304
|
-
available: boolean;
|
|
305
|
-
version?: string;
|
|
306
|
-
mcpAvailable?: boolean;
|
|
307
|
-
authenticated?: boolean;
|
|
308
|
-
}
|
|
309
|
-
interface CLIExecutionOptions {
|
|
310
|
-
timeout?: number;
|
|
311
|
-
verbose?: boolean;
|
|
312
|
-
outputFormat?: 'json' | 'table' | 'yaml';
|
|
313
|
-
}
|
|
314
|
-
interface CLICommand {
|
|
315
|
-
command: string;
|
|
316
|
-
args: string[];
|
|
317
|
-
options?: CLIExecutionOptions;
|
|
318
|
-
}
|
|
319
|
-
interface MCPChannel {
|
|
320
|
-
available: boolean;
|
|
321
|
-
version?: string;
|
|
322
|
-
capabilities?: string[];
|
|
323
|
-
}
|
|
324
|
-
interface CLICapabilities {
|
|
325
|
-
cliAvailable: boolean;
|
|
326
|
-
mcpSupport: boolean;
|
|
327
|
-
authenticated: boolean;
|
|
328
|
-
goldenContract: boolean;
|
|
329
|
-
version?: string;
|
|
330
|
-
}
|
|
331
|
-
type RoutingStrategy = 'cli-first' | 'api-first' | 'cli-only' | 'api-only' | 'auto';
|
|
332
|
-
interface CLIAuthStatus {
|
|
333
|
-
authenticated: boolean;
|
|
334
|
-
user?: {
|
|
335
|
-
id?: string;
|
|
336
|
-
email?: string;
|
|
337
|
-
name?: string;
|
|
338
|
-
[key: string]: unknown;
|
|
339
|
-
};
|
|
340
|
-
scopes?: string[];
|
|
341
|
-
expiresAt?: string;
|
|
342
|
-
[key: string]: unknown;
|
|
343
|
-
}
|
|
344
|
-
interface CLIMCPStatus {
|
|
345
|
-
connected: boolean;
|
|
346
|
-
channel?: string;
|
|
347
|
-
endpoint?: string;
|
|
348
|
-
details?: Record<string, unknown>;
|
|
349
|
-
[key: string]: unknown;
|
|
350
|
-
}
|
|
351
|
-
interface CLIMCPTool {
|
|
352
|
-
name: string;
|
|
353
|
-
title?: string;
|
|
354
|
-
description?: string;
|
|
355
|
-
[key: string]: unknown;
|
|
356
|
-
}
|
|
357
|
-
/**
|
|
358
|
-
* CLI Detection and Integration Service
|
|
359
|
-
*/
|
|
360
|
-
declare class CLIIntegration {
|
|
361
|
-
private cliInfo;
|
|
362
|
-
private detectionPromise;
|
|
363
|
-
/**
|
|
364
|
-
* Detect if CLI is available and get its capabilities
|
|
365
|
-
*/
|
|
366
|
-
detectCLI(): Promise<CLIInfo>;
|
|
367
|
-
private performDetection;
|
|
368
|
-
/**
|
|
369
|
-
* Execute CLI command and return parsed JSON result
|
|
370
|
-
*/
|
|
371
|
-
executeCLICommand<T = unknown>(command: string, options?: CLIExecutionOptions): Promise<ApiResponse<T>>;
|
|
808
|
+
getAccessPatterns(options?: AnalyticsDateRange): Promise<ApiResponse<AccessPatterns>>;
|
|
372
809
|
/**
|
|
373
|
-
* Get
|
|
810
|
+
* Get extended memory statistics with storage and activity metrics
|
|
811
|
+
*
|
|
812
|
+
* @example
|
|
813
|
+
* ```typescript
|
|
814
|
+
* const stats = await client.getExtendedStats();
|
|
815
|
+
* console.log(`Total chunks: ${stats.data?.storage.total_chunks}`);
|
|
816
|
+
* console.log(`Created today: ${stats.data?.activity.created_today}`);
|
|
817
|
+
* ```
|
|
374
818
|
*/
|
|
375
|
-
|
|
819
|
+
getExtendedStats(): Promise<ApiResponse<ExtendedMemoryStats>>;
|
|
376
820
|
/**
|
|
377
|
-
*
|
|
821
|
+
* Get topic with its memories
|
|
822
|
+
*
|
|
823
|
+
* @example
|
|
824
|
+
* ```typescript
|
|
825
|
+
* const topic = await client.getTopicWithMemories('topic_123');
|
|
826
|
+
* console.log(topic.data?.memories);
|
|
827
|
+
* ```
|
|
378
828
|
*/
|
|
379
|
-
|
|
380
|
-
memoryType?: string;
|
|
381
|
-
tags?: string[];
|
|
382
|
-
topicId?: string;
|
|
383
|
-
}): Promise<ApiResponse<MemoryEntry>>;
|
|
384
|
-
listMemoriesViaCLI(options?: {
|
|
385
|
-
limit?: number;
|
|
386
|
-
memoryType?: string;
|
|
387
|
-
tags?: string[];
|
|
388
|
-
sortBy?: string;
|
|
389
|
-
}): Promise<ApiResponse<PaginatedResponse<MemoryEntry>>>;
|
|
390
|
-
searchMemoriesViaCLI(query: string, options?: {
|
|
829
|
+
getTopicWithMemories(topicId: string, options?: {
|
|
391
830
|
limit?: number;
|
|
392
|
-
|
|
831
|
+
offset?: number;
|
|
393
832
|
}): Promise<ApiResponse<{
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
833
|
+
topic: MemoryTopic;
|
|
834
|
+
memories: MemoryEntry[];
|
|
835
|
+
total_memories: number;
|
|
836
|
+
subtopics: Array<{
|
|
837
|
+
id: string;
|
|
838
|
+
name: string;
|
|
839
|
+
memory_count: number;
|
|
840
|
+
}>;
|
|
397
841
|
}>>;
|
|
398
842
|
/**
|
|
399
|
-
*
|
|
843
|
+
* Get topics in hierarchical structure
|
|
844
|
+
*
|
|
845
|
+
* @example
|
|
846
|
+
* ```typescript
|
|
847
|
+
* const topics = await client.getTopicsHierarchy();
|
|
848
|
+
* // Returns nested topic tree with children
|
|
849
|
+
* ```
|
|
400
850
|
*/
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
}
|
|
851
|
+
getTopicsHierarchy(): Promise<ApiResponse<Array<MemoryTopic & {
|
|
852
|
+
children: MemoryTopic[];
|
|
853
|
+
memory_count: number;
|
|
854
|
+
}>>>;
|
|
405
855
|
/**
|
|
406
|
-
*
|
|
856
|
+
* Update authentication token
|
|
407
857
|
*/
|
|
408
|
-
|
|
409
|
-
listMCPTools(): Promise<ApiResponse<{
|
|
410
|
-
tools: CLIMCPTool[];
|
|
411
|
-
}>>;
|
|
858
|
+
setAuthToken(token: string): void;
|
|
412
859
|
/**
|
|
413
|
-
*
|
|
860
|
+
* Update API key
|
|
414
861
|
*/
|
|
415
|
-
|
|
862
|
+
setApiKey(apiKey: string): void;
|
|
416
863
|
/**
|
|
417
|
-
*
|
|
864
|
+
* Clear authentication
|
|
418
865
|
*/
|
|
419
|
-
|
|
420
|
-
cliAvailable: boolean;
|
|
421
|
-
version?: string;
|
|
422
|
-
mcpSupport: boolean;
|
|
423
|
-
authenticated: boolean;
|
|
424
|
-
goldenContract: boolean;
|
|
425
|
-
}>;
|
|
426
|
-
private isGoldenContractCompliant;
|
|
866
|
+
clearAuth(): void;
|
|
427
867
|
/**
|
|
428
|
-
*
|
|
868
|
+
* Update configuration
|
|
429
869
|
*/
|
|
430
|
-
|
|
870
|
+
updateConfig(updates: Partial<CoreMemoryClientConfig>): void;
|
|
431
871
|
/**
|
|
432
|
-
* Get
|
|
872
|
+
* Get current configuration (excluding sensitive data)
|
|
433
873
|
*/
|
|
434
|
-
|
|
874
|
+
getConfig(): Omit<CoreMemoryClientConfig, 'apiKey' | 'authToken'>;
|
|
435
875
|
}
|
|
876
|
+
/**
|
|
877
|
+
* Factory function to create a new Core Memory Client instance
|
|
878
|
+
*/
|
|
879
|
+
declare function createMemoryClient(config: CoreMemoryClientConfig): CoreMemoryClient;
|
|
436
880
|
|
|
437
881
|
/**
|
|
438
|
-
*
|
|
439
|
-
*
|
|
440
|
-
* Intelligently routes requests through CLI v1.5.2+ when available,
|
|
441
|
-
* with fallback to direct API for maximum compatibility and performance
|
|
882
|
+
* Core Utilities for Memory Client
|
|
883
|
+
* Browser-safe, no Node.js dependencies
|
|
442
884
|
*/
|
|
443
885
|
|
|
444
|
-
interface EnhancedMemoryClientConfig extends MemoryClientConfig {
|
|
445
|
-
/** Prefer CLI when available (default: true) */
|
|
446
|
-
preferCLI?: boolean;
|
|
447
|
-
/** Enable MCP channels when available (default: true) */
|
|
448
|
-
enableMCP?: boolean;
|
|
449
|
-
/** CLI detection timeout in ms (default: 5000) */
|
|
450
|
-
cliDetectionTimeout?: number;
|
|
451
|
-
/** Fallback to direct API on CLI failure (default: true) */
|
|
452
|
-
fallbackToAPI?: boolean;
|
|
453
|
-
/** Minimum CLI version required for Golden Contract compliance (default: 1.5.2) */
|
|
454
|
-
minCLIVersion?: string;
|
|
455
|
-
/** Enable verbose logging for troubleshooting (default: false) */
|
|
456
|
-
verbose?: boolean;
|
|
457
|
-
}
|
|
458
|
-
interface OperationResult<T> {
|
|
459
|
-
data?: T;
|
|
460
|
-
error?: string;
|
|
461
|
-
source: 'cli' | 'api';
|
|
462
|
-
mcpUsed?: boolean;
|
|
463
|
-
}
|
|
464
886
|
/**
|
|
465
|
-
*
|
|
887
|
+
* Safe JSON parse result - discriminated union for type-safe error handling
|
|
466
888
|
*/
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
/**
|
|
475
|
-
* Initialize the client and detect capabilities
|
|
476
|
-
*/
|
|
477
|
-
initialize(): Promise<void>;
|
|
478
|
-
/**
|
|
479
|
-
* Get current capabilities
|
|
480
|
-
*/
|
|
481
|
-
getCapabilities(): Promise<Awaited<ReturnType<CLIIntegration['getCapabilities']>>>;
|
|
482
|
-
/**
|
|
483
|
-
* Determine if operation should use CLI
|
|
484
|
-
*/
|
|
485
|
-
private shouldUseCLI;
|
|
486
|
-
/**
|
|
487
|
-
* Execute operation with intelligent routing
|
|
488
|
-
*/
|
|
489
|
-
private executeOperation;
|
|
490
|
-
/**
|
|
491
|
-
* Health check with intelligent routing
|
|
492
|
-
*/
|
|
493
|
-
healthCheck(): Promise<OperationResult<{
|
|
494
|
-
status: string;
|
|
495
|
-
timestamp: string;
|
|
496
|
-
}>>;
|
|
497
|
-
/**
|
|
498
|
-
* Create memory with CLI/API routing
|
|
499
|
-
*/
|
|
500
|
-
createMemory(memory: CreateMemoryRequest): Promise<OperationResult<MemoryEntry>>;
|
|
501
|
-
/**
|
|
502
|
-
* List memories with intelligent routing
|
|
503
|
-
*/
|
|
504
|
-
listMemories(options?: {
|
|
505
|
-
page?: number;
|
|
506
|
-
limit?: number;
|
|
507
|
-
memory_type?: string;
|
|
508
|
-
topic_id?: string;
|
|
509
|
-
project_ref?: string;
|
|
510
|
-
status?: string;
|
|
511
|
-
tags?: string[];
|
|
512
|
-
sort?: string;
|
|
513
|
-
order?: 'asc' | 'desc';
|
|
514
|
-
}): Promise<OperationResult<PaginatedResponse<MemoryEntry>>>;
|
|
515
|
-
/**
|
|
516
|
-
* Search memories with MCP enhancement when available
|
|
517
|
-
*/
|
|
518
|
-
searchMemories(request: SearchMemoryRequest): Promise<OperationResult<{
|
|
519
|
-
results: MemorySearchResult[];
|
|
520
|
-
total_results: number;
|
|
521
|
-
search_time_ms: number;
|
|
522
|
-
}>>;
|
|
523
|
-
/**
|
|
524
|
-
* Get memory by ID (API only for now)
|
|
525
|
-
*/
|
|
526
|
-
getMemory(id: string): Promise<OperationResult<MemoryEntry>>;
|
|
527
|
-
/**
|
|
528
|
-
* Update memory (API only for now)
|
|
529
|
-
*/
|
|
530
|
-
updateMemory(id: string, updates: UpdateMemoryRequest): Promise<OperationResult<MemoryEntry>>;
|
|
531
|
-
/**
|
|
532
|
-
* Delete memory (API only for now)
|
|
533
|
-
*/
|
|
534
|
-
deleteMemory(id: string): Promise<OperationResult<void>>;
|
|
535
|
-
createTopic(topic: CreateTopicRequest): Promise<OperationResult<MemoryTopic>>;
|
|
536
|
-
getTopics(): Promise<OperationResult<MemoryTopic[]>>;
|
|
537
|
-
getTopic(id: string): Promise<OperationResult<MemoryTopic>>;
|
|
538
|
-
updateTopic(id: string, updates: Partial<CreateTopicRequest>): Promise<OperationResult<MemoryTopic>>;
|
|
539
|
-
deleteTopic(id: string): Promise<OperationResult<void>>;
|
|
540
|
-
/**
|
|
541
|
-
* Get memory statistics
|
|
542
|
-
*/
|
|
543
|
-
getMemoryStats(): Promise<OperationResult<UserMemoryStats>>;
|
|
544
|
-
/**
|
|
545
|
-
* Force CLI re-detection
|
|
546
|
-
*/
|
|
547
|
-
refreshCLIDetection(): Promise<void>;
|
|
548
|
-
/**
|
|
549
|
-
* Get authentication status from CLI
|
|
550
|
-
*/
|
|
551
|
-
getAuthStatus(): Promise<OperationResult<CLIAuthStatus>>;
|
|
552
|
-
/**
|
|
553
|
-
* Get MCP status when available
|
|
554
|
-
*/
|
|
555
|
-
getMCPStatus(): Promise<OperationResult<CLIMCPStatus>>;
|
|
556
|
-
/**
|
|
557
|
-
* Update authentication for both CLI and API client
|
|
558
|
-
*/
|
|
559
|
-
setAuthToken(token: string): void;
|
|
560
|
-
setApiKey(apiKey: string): void;
|
|
561
|
-
clearAuth(): void;
|
|
562
|
-
/**
|
|
563
|
-
* Update configuration
|
|
564
|
-
*/
|
|
565
|
-
updateConfig(updates: Partial<EnhancedMemoryClientConfig>): void;
|
|
566
|
-
/**
|
|
567
|
-
* Get configuration summary
|
|
568
|
-
*/
|
|
569
|
-
getConfigSummary(): {
|
|
570
|
-
apiUrl: string;
|
|
571
|
-
preferCLI: boolean;
|
|
572
|
-
enableMCP: boolean;
|
|
573
|
-
capabilities?: Awaited<ReturnType<CLIIntegration['getCapabilities']>>;
|
|
574
|
-
};
|
|
575
|
-
}
|
|
889
|
+
type SafeJsonResult<T> = {
|
|
890
|
+
success: true;
|
|
891
|
+
data: T;
|
|
892
|
+
} | {
|
|
893
|
+
success: false;
|
|
894
|
+
error: string;
|
|
895
|
+
};
|
|
576
896
|
/**
|
|
577
|
-
*
|
|
897
|
+
* Safely parse JSON with detailed error reporting
|
|
898
|
+
* Prevents scattered try/catch blocks throughout the codebase
|
|
578
899
|
*/
|
|
579
|
-
declare function
|
|
580
|
-
|
|
900
|
+
declare function safeJsonParse<T = unknown>(input: string): SafeJsonResult<T>;
|
|
581
901
|
/**
|
|
582
|
-
*
|
|
583
|
-
* Provides smart defaults and environment detection for CLI/MCP integration
|
|
902
|
+
* HTTP status code to error code mapping
|
|
584
903
|
*/
|
|
585
|
-
|
|
586
|
-
interface SmartConfigOptions {
|
|
587
|
-
/** Prefer CLI integration when available (default: true in Node.js environments) */
|
|
588
|
-
preferCLI?: boolean;
|
|
589
|
-
/** Minimum CLI version required for Golden Contract compliance (default: 1.5.2) */
|
|
590
|
-
minCLIVersion?: string;
|
|
591
|
-
/** Enable MCP channel detection (default: true) */
|
|
592
|
-
enableMCP?: boolean;
|
|
593
|
-
/** API fallback configuration */
|
|
594
|
-
apiConfig?: Partial<MemoryClientConfig>;
|
|
595
|
-
/** Timeout for CLI detection in milliseconds (default: 3000) */
|
|
596
|
-
cliDetectionTimeout?: number;
|
|
597
|
-
/** Enable verbose logging for troubleshooting (default: false) */
|
|
598
|
-
verbose?: boolean;
|
|
599
|
-
}
|
|
600
|
-
/**
|
|
601
|
-
* Environment detection utilities
|
|
602
|
-
*/
|
|
603
|
-
declare const Environment: {
|
|
604
|
-
isNode: string | false;
|
|
605
|
-
isBrowser: boolean;
|
|
606
|
-
isVSCode: boolean;
|
|
607
|
-
isCursor: boolean;
|
|
608
|
-
isWindsurf: boolean;
|
|
609
|
-
readonly isIDE: boolean;
|
|
610
|
-
readonly supportsCLI: boolean;
|
|
611
|
-
};
|
|
904
|
+
declare function httpStatusToErrorCode(status: number): ErrorCode;
|
|
612
905
|
/**
|
|
613
|
-
* Create
|
|
906
|
+
* Create a standardized error response from various error sources
|
|
614
907
|
*/
|
|
615
|
-
declare function
|
|
908
|
+
declare function createErrorResponse(message: string, code?: ErrorCode, statusCode?: number, details?: unknown): ApiErrorResponse;
|
|
616
909
|
/**
|
|
617
|
-
*
|
|
910
|
+
* Calculate retry delay with exponential backoff and jitter
|
|
618
911
|
*/
|
|
619
|
-
declare
|
|
620
|
-
/**
|
|
621
|
-
* Development configuration with local API and CLI preference
|
|
622
|
-
*/
|
|
623
|
-
development: (apiKey?: string) => EnhancedMemoryClientConfig;
|
|
624
|
-
/**
|
|
625
|
-
* Production configuration optimized for performance
|
|
626
|
-
*/
|
|
627
|
-
production: (apiKey?: string) => EnhancedMemoryClientConfig;
|
|
628
|
-
/**
|
|
629
|
-
* IDE extension configuration with MCP prioritization
|
|
630
|
-
*/
|
|
631
|
-
ideExtension: (apiKey?: string) => EnhancedMemoryClientConfig;
|
|
632
|
-
/**
|
|
633
|
-
* Browser-only configuration (no CLI support)
|
|
634
|
-
*/
|
|
635
|
-
browserOnly: (apiKey?: string) => EnhancedMemoryClientConfig;
|
|
636
|
-
/**
|
|
637
|
-
* CLI-first configuration for server environments
|
|
638
|
-
*/
|
|
639
|
-
serverCLI: (apiKey?: string) => EnhancedMemoryClientConfig;
|
|
640
|
-
};
|
|
912
|
+
declare function calculateRetryDelay(attempt: number, baseDelay?: number, backoff?: 'linear' | 'exponential', maxDelay?: number): number;
|
|
641
913
|
/**
|
|
642
|
-
*
|
|
914
|
+
* Check if an error is retryable based on status code
|
|
643
915
|
*/
|
|
644
|
-
declare function
|
|
916
|
+
declare function isRetryableError(statusCode?: number): boolean;
|
|
645
917
|
|
|
646
918
|
/**
|
|
647
919
|
* @lanonasis/memory-client
|
|
648
920
|
*
|
|
649
|
-
* Memory as a Service (MaaS) Client SDK for Lanonasis
|
|
921
|
+
* Universal Memory as a Service (MaaS) Client SDK for Lanonasis
|
|
650
922
|
* Intelligent memory management with semantic search capabilities
|
|
923
|
+
*
|
|
924
|
+
* v2.0.0 - Universal SDK Redesign
|
|
925
|
+
* "Drop In and Sleep" Architecture - Works everywhere with zero configuration
|
|
926
|
+
*
|
|
927
|
+
* @example Browser/Web App
|
|
928
|
+
* ```ts
|
|
929
|
+
* import { createMemoryClient } from '@lanonasis/memory-client/core';
|
|
930
|
+
* const client = createMemoryClient({ apiKey: 'your-key' });
|
|
931
|
+
* ```
|
|
932
|
+
*
|
|
933
|
+
* @example Node.js
|
|
934
|
+
* ```ts
|
|
935
|
+
* import { createNodeMemoryClient } from '@lanonasis/memory-client/node';
|
|
936
|
+
* const client = await createNodeMemoryClient({ apiKey: process.env.KEY });
|
|
937
|
+
* ```
|
|
938
|
+
*
|
|
939
|
+
* @example React
|
|
940
|
+
* ```tsx
|
|
941
|
+
* import { MemoryProvider, useMemories } from '@lanonasis/memory-client/react';
|
|
942
|
+
* ```
|
|
943
|
+
*
|
|
944
|
+
* @example Vue
|
|
945
|
+
* ```ts
|
|
946
|
+
* import { createMemoryPlugin, useMemories } from '@lanonasis/memory-client/vue';
|
|
947
|
+
* ```
|
|
651
948
|
*/
|
|
652
949
|
|
|
653
|
-
declare const VERSION = "
|
|
950
|
+
declare const VERSION = "2.0.0";
|
|
654
951
|
declare const CLIENT_NAME = "@lanonasis/memory-client";
|
|
655
952
|
declare const isBrowser: boolean;
|
|
656
953
|
declare const isNode: string | false;
|
|
954
|
+
declare const isEdge: boolean;
|
|
955
|
+
/**
|
|
956
|
+
* Detected runtime environment
|
|
957
|
+
*/
|
|
958
|
+
type RuntimeEnvironment = 'browser' | 'node' | 'edge';
|
|
959
|
+
/**
|
|
960
|
+
* Get the current runtime environment
|
|
961
|
+
*/
|
|
962
|
+
declare function getEnvironment(): RuntimeEnvironment;
|
|
963
|
+
/**
|
|
964
|
+
* Configuration for the auto-detecting client factory
|
|
965
|
+
*/
|
|
966
|
+
interface AutoClientConfig {
|
|
967
|
+
/** API endpoint URL (required) */
|
|
968
|
+
apiUrl: string;
|
|
969
|
+
/** API key for authentication */
|
|
970
|
+
apiKey?: string;
|
|
971
|
+
/** Bearer token for authentication */
|
|
972
|
+
authToken?: string;
|
|
973
|
+
/** Organization ID */
|
|
974
|
+
organizationId?: string;
|
|
975
|
+
/** Request timeout in milliseconds */
|
|
976
|
+
timeout?: number;
|
|
977
|
+
/** Custom headers */
|
|
978
|
+
headers?: Record<string, string>;
|
|
979
|
+
/** Retry configuration */
|
|
980
|
+
retry?: {
|
|
981
|
+
maxRetries?: number;
|
|
982
|
+
retryDelay?: number;
|
|
983
|
+
backoff?: 'linear' | 'exponential';
|
|
984
|
+
};
|
|
985
|
+
/** Node.js specific: prefer CLI when available */
|
|
986
|
+
preferCLI?: boolean;
|
|
987
|
+
/** Node.js specific: enable MCP channels */
|
|
988
|
+
enableMCP?: boolean;
|
|
989
|
+
}
|
|
990
|
+
/**
|
|
991
|
+
* Auto-detecting client factory - "Drop In and Sleep" architecture
|
|
992
|
+
*
|
|
993
|
+
* Automatically detects the runtime environment and returns the appropriate client:
|
|
994
|
+
* - Browser/Edge: Returns CoreMemoryClient (lightweight, browser-safe)
|
|
995
|
+
* - Node.js: Returns EnhancedMemoryClient (with CLI/MCP support)
|
|
996
|
+
*
|
|
997
|
+
* @example
|
|
998
|
+
* ```typescript
|
|
999
|
+
* import { createClient } from '@lanonasis/memory-client';
|
|
1000
|
+
*
|
|
1001
|
+
* // Works in any environment!
|
|
1002
|
+
* const client = await createClient({
|
|
1003
|
+
* apiUrl: 'https://api.lanonasis.com',
|
|
1004
|
+
* apiKey: 'your-key'
|
|
1005
|
+
* });
|
|
1006
|
+
*
|
|
1007
|
+
* const memories = await client.listMemories();
|
|
1008
|
+
* ```
|
|
1009
|
+
*/
|
|
1010
|
+
declare function createClient(config: AutoClientConfig): Promise<CoreMemoryClient>;
|
|
657
1011
|
declare const defaultConfigs: {
|
|
658
1012
|
readonly development: {
|
|
659
1013
|
readonly apiUrl: "http://localhost:3001";
|
|
660
1014
|
readonly timeout: 30000;
|
|
661
|
-
readonly useGateway: false;
|
|
662
1015
|
};
|
|
663
1016
|
readonly production: {
|
|
664
1017
|
readonly apiUrl: "https://api.lanonasis.com";
|
|
665
1018
|
readonly timeout: 15000;
|
|
666
|
-
readonly useGateway: true;
|
|
667
1019
|
};
|
|
668
|
-
readonly
|
|
1020
|
+
readonly edge: {
|
|
669
1021
|
readonly apiUrl: "https://api.lanonasis.com";
|
|
670
|
-
readonly timeout:
|
|
671
|
-
readonly useGateway: true;
|
|
1022
|
+
readonly timeout: 5000;
|
|
672
1023
|
};
|
|
673
1024
|
};
|
|
674
1025
|
|
|
675
|
-
export {
|
|
676
|
-
export type { ApiResponse,
|
|
1026
|
+
export { ApiError, AuthenticationError, CHUNKING_STRATEGIES, CLIENT_NAME, CONTENT_TYPES, CoreMemoryClient, ERROR_CODES, MEMORY_STATUSES, MEMORY_TYPES, CoreMemoryClient as MemoryClient, MemoryClientError, NetworkError, NotFoundError, RateLimitError, SEARCH_MODES, ServerError, TimeoutError, VERSION, ValidationError, analyticsDateRangeSchema, calculateRetryDelay, createClient, createErrorFromStatus, createErrorResponse, createMemoryClient, createMemorySchema, createTopicSchema, defaultConfigs, enhancedSearchSchema, getEnvironment, hasData, hasError, httpStatusToErrorCode, isApiErrorResponse, isBrowser, isEdge, isNode, isRetryableError, preprocessingOptionsSchema, safeJsonParse, searchMemorySchema, updateMemorySchema };
|
|
1027
|
+
export type { AccessPatterns, AnalyticsDateRange, ApiErrorResponse, ApiResponse, AutoClientConfig, ChunkingStrategy, ContentChunk, ContentType, CoreMemoryClientConfig, CreateMemoryRequest, CreateMemoryWithPreprocessingRequest, CreateTopicRequest, EnhancedMemorySearchResult, EnhancedSearchRequest, EnhancedSearchResponse, ErrorCode, ExtendedMemoryStats, HourlyAccess, IntelligentMetadata, MatchingChunk, CoreMemoryClientConfig as MemoryClientConfig, MemoryEntry, MemoryIntelligence, MemorySearchResult, MemoryStatus, MemoryTopic, MemoryType, MostAccessedMemory, PaginatedResponse, PopularQuery, PreprocessingOptions, ProjectMemoryCount, RuntimeEnvironment, SafeJsonResult, SearchAnalytics, SearchAnalyticsDataPoint, SearchFilters, SearchMemoryRequest, SearchMode, TagCount, UpdateMemoryRequest, UpdateMemoryWithPreprocessingRequest, UserMemoryStats };
|