@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.
@@ -0,0 +1,948 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * Memory types supported by the service
5
+ */
6
+ declare const MEMORY_TYPES: readonly ["context", "project", "knowledge", "reference", "personal", "workflow"];
7
+ type MemoryType = typeof MEMORY_TYPES[number];
8
+ /**
9
+ * Memory status values
10
+ */
11
+ declare const MEMORY_STATUSES: readonly ["active", "archived", "draft", "deleted"];
12
+ type MemoryStatus = typeof MEMORY_STATUSES[number];
13
+ /**
14
+ * Core memory entry interface
15
+ */
16
+ interface MemoryEntry {
17
+ id: string;
18
+ title: string;
19
+ content: string;
20
+ summary?: string;
21
+ memory_type: MemoryType;
22
+ status: MemoryStatus;
23
+ relevance_score?: number;
24
+ access_count: number;
25
+ last_accessed?: string;
26
+ user_id: string;
27
+ topic_id?: string;
28
+ project_ref?: string;
29
+ tags: string[];
30
+ metadata?: Record<string, unknown>;
31
+ created_at: string;
32
+ updated_at: string;
33
+ }
34
+ /**
35
+ * Memory topic for organization
36
+ */
37
+ interface MemoryTopic {
38
+ id: string;
39
+ name: string;
40
+ description?: string;
41
+ color?: string;
42
+ icon?: string;
43
+ user_id: string;
44
+ parent_topic_id?: string;
45
+ is_system: boolean;
46
+ metadata?: Record<string, unknown>;
47
+ created_at: string;
48
+ updated_at: string;
49
+ }
50
+ /**
51
+ * Memory search result with similarity score
52
+ */
53
+ interface MemorySearchResult extends MemoryEntry {
54
+ similarity_score: number;
55
+ }
56
+ /**
57
+ * User memory statistics
58
+ */
59
+ interface UserMemoryStats {
60
+ total_memories: number;
61
+ memories_by_type: Record<MemoryType, number>;
62
+ total_topics: number;
63
+ most_accessed_memory?: string;
64
+ recent_memories: string[];
65
+ }
66
+ /**
67
+ * Validation schemas using Zod
68
+ */
69
+ declare const createMemorySchema: z.ZodObject<{
70
+ title: z.ZodString;
71
+ content: z.ZodString;
72
+ summary: z.ZodOptional<z.ZodString>;
73
+ memory_type: z.ZodDefault<z.ZodEnum<{
74
+ context: "context";
75
+ project: "project";
76
+ knowledge: "knowledge";
77
+ reference: "reference";
78
+ personal: "personal";
79
+ workflow: "workflow";
80
+ }>>;
81
+ topic_id: z.ZodOptional<z.ZodString>;
82
+ project_ref: z.ZodOptional<z.ZodString>;
83
+ tags: z.ZodDefault<z.ZodArray<z.ZodString>>;
84
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
85
+ }, z.core.$strip>;
86
+ declare const updateMemorySchema: z.ZodObject<{
87
+ title: z.ZodOptional<z.ZodString>;
88
+ content: z.ZodOptional<z.ZodString>;
89
+ summary: z.ZodOptional<z.ZodString>;
90
+ memory_type: z.ZodOptional<z.ZodEnum<{
91
+ context: "context";
92
+ project: "project";
93
+ knowledge: "knowledge";
94
+ reference: "reference";
95
+ personal: "personal";
96
+ workflow: "workflow";
97
+ }>>;
98
+ status: z.ZodOptional<z.ZodEnum<{
99
+ active: "active";
100
+ archived: "archived";
101
+ draft: "draft";
102
+ deleted: "deleted";
103
+ }>>;
104
+ topic_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
105
+ project_ref: z.ZodOptional<z.ZodNullable<z.ZodString>>;
106
+ tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
107
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
108
+ }, z.core.$strip>;
109
+ declare const searchMemorySchema: z.ZodObject<{
110
+ query: z.ZodString;
111
+ memory_types: z.ZodOptional<z.ZodArray<z.ZodEnum<{
112
+ context: "context";
113
+ project: "project";
114
+ knowledge: "knowledge";
115
+ reference: "reference";
116
+ personal: "personal";
117
+ workflow: "workflow";
118
+ }>>>;
119
+ tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
120
+ topic_id: z.ZodOptional<z.ZodString>;
121
+ project_ref: z.ZodOptional<z.ZodString>;
122
+ status: z.ZodDefault<z.ZodEnum<{
123
+ active: "active";
124
+ archived: "archived";
125
+ draft: "draft";
126
+ deleted: "deleted";
127
+ }>>;
128
+ limit: z.ZodDefault<z.ZodNumber>;
129
+ threshold: z.ZodDefault<z.ZodNumber>;
130
+ }, z.core.$strip>;
131
+ declare const createTopicSchema: z.ZodObject<{
132
+ name: z.ZodString;
133
+ description: z.ZodOptional<z.ZodString>;
134
+ color: z.ZodOptional<z.ZodString>;
135
+ icon: z.ZodOptional<z.ZodString>;
136
+ parent_topic_id: z.ZodOptional<z.ZodString>;
137
+ }, z.core.$strip>;
138
+ /**
139
+ * Inferred types from schemas
140
+ */
141
+ type CreateMemoryRequest = z.infer<typeof createMemorySchema>;
142
+ type UpdateMemoryRequest = z.infer<typeof updateMemorySchema>;
143
+ type SearchMemoryRequest = z.infer<typeof searchMemorySchema>;
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
+ */
562
+
563
+ /**
564
+ * Configuration options for the Memory Client
565
+ */
566
+ interface CoreMemoryClientConfig {
567
+ /** API endpoint URL */
568
+ apiUrl: string;
569
+ /** API key for authentication */
570
+ apiKey?: string;
571
+ /** Bearer token for authentication (alternative to API key) */
572
+ authToken?: string;
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) */
578
+ timeout?: number;
579
+ /** Custom headers to include with requests */
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;
598
+ }
599
+ /**
600
+ * Standard API response wrapper with typed errors
601
+ * Replaces string errors with structured ApiErrorResponse
602
+ */
603
+ interface ApiResponse<T> {
604
+ data?: T;
605
+ /** Structured error response for programmatic handling */
606
+ error?: ApiErrorResponse;
607
+ /** Optional success message */
608
+ message?: string;
609
+ /** Request metadata */
610
+ meta?: {
611
+ requestId?: string;
612
+ duration?: number;
613
+ retries?: number;
614
+ };
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
+ };
628
+ /**
629
+ * Paginated response for list operations
630
+ */
631
+ interface PaginatedResponse<T> {
632
+ data: T[];
633
+ pagination: {
634
+ page: number;
635
+ limit: number;
636
+ total: number;
637
+ pages: number;
638
+ };
639
+ }
640
+ /**
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.)
645
+ */
646
+ declare class CoreMemoryClient {
647
+ private config;
648
+ private baseHeaders;
649
+ constructor(config: CoreMemoryClientConfig);
650
+ /**
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
657
+ */
658
+ private request;
659
+ /**
660
+ * Validate input using Zod schema and return validation error if invalid
661
+ */
662
+ private validateInput;
663
+ /**
664
+ * Test the API connection and authentication
665
+ */
666
+ healthCheck(): Promise<ApiResponse<{
667
+ status: string;
668
+ timestamp: string;
669
+ }>>;
670
+ /**
671
+ * Create a new memory with validation
672
+ */
673
+ createMemory(memory: CreateMemoryRequest): Promise<ApiResponse<MemoryEntry>>;
674
+ /**
675
+ * Get a memory by ID
676
+ */
677
+ getMemory(id: string): Promise<ApiResponse<MemoryEntry>>;
678
+ /**
679
+ * Update an existing memory with validation
680
+ */
681
+ updateMemory(id: string, updates: UpdateMemoryRequest): Promise<ApiResponse<MemoryEntry>>;
682
+ /**
683
+ * Delete a memory
684
+ */
685
+ deleteMemory(id: string): Promise<ApiResponse<void>>;
686
+ /**
687
+ * List memories with optional filtering and pagination
688
+ */
689
+ listMemories(options?: {
690
+ page?: number;
691
+ limit?: number;
692
+ memory_type?: string;
693
+ topic_id?: string;
694
+ project_ref?: string;
695
+ status?: string;
696
+ tags?: string[];
697
+ sort?: string;
698
+ order?: 'asc' | 'desc';
699
+ }): Promise<ApiResponse<PaginatedResponse<MemoryEntry>>>;
700
+ /**
701
+ * Search memories using semantic search with validation
702
+ */
703
+ searchMemories(request: SearchMemoryRequest): Promise<ApiResponse<{
704
+ results: MemorySearchResult[];
705
+ total_results: number;
706
+ search_time_ms: number;
707
+ }>>;
708
+ /**
709
+ * Bulk delete multiple memories
710
+ */
711
+ bulkDeleteMemories(memoryIds: string[]): Promise<ApiResponse<{
712
+ deleted_count: number;
713
+ failed_ids: string[];
714
+ }>>;
715
+ /**
716
+ * Create a new topic with validation
717
+ */
718
+ createTopic(topic: CreateTopicRequest): Promise<ApiResponse<MemoryTopic>>;
719
+ /**
720
+ * Get all topics
721
+ */
722
+ getTopics(): Promise<ApiResponse<MemoryTopic[]>>;
723
+ /**
724
+ * Get a topic by ID
725
+ */
726
+ getTopic(id: string): Promise<ApiResponse<MemoryTopic>>;
727
+ /**
728
+ * Update a topic
729
+ */
730
+ updateTopic(id: string, updates: Partial<CreateTopicRequest>): Promise<ApiResponse<MemoryTopic>>;
731
+ /**
732
+ * Delete a topic
733
+ */
734
+ deleteTopic(id: string): Promise<ApiResponse<void>>;
735
+ /**
736
+ * Get user memory statistics
737
+ */
738
+ getMemoryStats(): Promise<ApiResponse<UserMemoryStats>>;
739
+ /**
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
+ * ```
754
+ */
755
+ createMemoryWithPreprocessing(memory: CreateMemoryWithPreprocessingRequest): Promise<ApiResponse<MemoryEntry>>;
756
+ /**
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
+ * ```
767
+ */
768
+ updateMemoryWithPreprocessing(id: string, updates: UpdateMemoryWithPreprocessingRequest): Promise<ApiResponse<MemoryEntry>>;
769
+ /**
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
+ * ```
781
+ */
782
+ enhancedSearch(request: EnhancedSearchRequest): Promise<ApiResponse<EnhancedSearchResponse>>;
783
+ /**
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
+ * ```
794
+ */
795
+ getSearchAnalytics(options?: AnalyticsDateRange): Promise<ApiResponse<SearchAnalytics>>;
796
+ /**
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
+ * ```
807
+ */
808
+ getAccessPatterns(options?: AnalyticsDateRange): Promise<ApiResponse<AccessPatterns>>;
809
+ /**
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
+ * ```
818
+ */
819
+ getExtendedStats(): Promise<ApiResponse<ExtendedMemoryStats>>;
820
+ /**
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
+ * ```
828
+ */
829
+ getTopicWithMemories(topicId: string, options?: {
830
+ limit?: number;
831
+ offset?: number;
832
+ }): Promise<ApiResponse<{
833
+ topic: MemoryTopic;
834
+ memories: MemoryEntry[];
835
+ total_memories: number;
836
+ subtopics: Array<{
837
+ id: string;
838
+ name: string;
839
+ memory_count: number;
840
+ }>;
841
+ }>>;
842
+ /**
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
+ * ```
850
+ */
851
+ getTopicsHierarchy(): Promise<ApiResponse<Array<MemoryTopic & {
852
+ children: MemoryTopic[];
853
+ memory_count: number;
854
+ }>>>;
855
+ /**
856
+ * Update authentication token
857
+ */
858
+ setAuthToken(token: string): void;
859
+ /**
860
+ * Update API key
861
+ */
862
+ setApiKey(apiKey: string): void;
863
+ /**
864
+ * Clear authentication
865
+ */
866
+ clearAuth(): void;
867
+ /**
868
+ * Update configuration
869
+ */
870
+ updateConfig(updates: Partial<CoreMemoryClientConfig>): void;
871
+ /**
872
+ * Get current configuration (excluding sensitive data)
873
+ */
874
+ getConfig(): Omit<CoreMemoryClientConfig, 'apiKey' | 'authToken'>;
875
+ }
876
+ /**
877
+ * Factory function to create a new Core Memory Client instance
878
+ */
879
+ declare function createMemoryClient(config: CoreMemoryClientConfig): CoreMemoryClient;
880
+
881
+ /**
882
+ * Core Utilities for Memory Client
883
+ * Browser-safe, no Node.js dependencies
884
+ */
885
+
886
+ /**
887
+ * Safe JSON parse result - discriminated union for type-safe error handling
888
+ */
889
+ type SafeJsonResult<T> = {
890
+ success: true;
891
+ data: T;
892
+ } | {
893
+ success: false;
894
+ error: string;
895
+ };
896
+ /**
897
+ * Safely parse JSON with detailed error reporting
898
+ * Prevents scattered try/catch blocks throughout the codebase
899
+ */
900
+ declare function safeJsonParse<T = unknown>(input: string): SafeJsonResult<T>;
901
+ /**
902
+ * HTTP status code to error code mapping
903
+ */
904
+ declare function httpStatusToErrorCode(status: number): ErrorCode;
905
+ /**
906
+ * Create a standardized error response from various error sources
907
+ */
908
+ declare function createErrorResponse(message: string, code?: ErrorCode, statusCode?: number, details?: unknown): ApiErrorResponse;
909
+ /**
910
+ * Calculate retry delay with exponential backoff and jitter
911
+ */
912
+ declare function calculateRetryDelay(attempt: number, baseDelay?: number, backoff?: 'linear' | 'exponential', maxDelay?: number): number;
913
+ /**
914
+ * Check if an error is retryable based on status code
915
+ */
916
+ declare function isRetryableError(statusCode?: number): boolean;
917
+
918
+ /**
919
+ * @lanonasis/memory-client/core
920
+ *
921
+ * Pure browser-safe Memory Client
922
+ * NO Node.js dependencies, NO CLI code, NO child_process
923
+ * Works in: Browser, React Native, Cloudflare Workers, Edge Functions, Deno, Bun
924
+ *
925
+ * Bundle size: ~15KB gzipped
926
+ */
927
+
928
+ declare const VERSION = "2.0.0";
929
+ declare const CLIENT_NAME = "@lanonasis/memory-client";
930
+ declare const isBrowser: boolean;
931
+ declare const isNode: string | false;
932
+ declare const defaultConfigs: {
933
+ readonly development: {
934
+ readonly apiUrl: "http://localhost:3001";
935
+ readonly timeout: 30000;
936
+ };
937
+ readonly production: {
938
+ readonly apiUrl: "https://api.lanonasis.com";
939
+ readonly timeout: 15000;
940
+ };
941
+ readonly edge: {
942
+ readonly apiUrl: "https://api.lanonasis.com";
943
+ readonly timeout: 5000;
944
+ };
945
+ };
946
+
947
+ export { ApiError, AuthenticationError, CHUNKING_STRATEGIES, CLIENT_NAME, CONTENT_TYPES, CoreMemoryClient, ERROR_CODES, MEMORY_STATUSES, MEMORY_TYPES, MemoryClientError, NetworkError, NotFoundError, RateLimitError, SEARCH_MODES, ServerError, TimeoutError, VERSION, ValidationError, analyticsDateRangeSchema, calculateRetryDelay, createErrorFromStatus, createErrorResponse, createMemoryClient, createMemorySchema, createTopicSchema, defaultConfigs, enhancedSearchSchema, hasData, hasError, httpStatusToErrorCode, isApiErrorResponse, isBrowser, isNode, isRetryableError, preprocessingOptionsSchema, safeJsonParse, searchMemorySchema, updateMemorySchema };
948
+ export type { AccessPatterns, AnalyticsDateRange, ApiErrorResponse, ApiResponse, ChunkingStrategy, ContentChunk, ContentType, CoreMemoryClientConfig, CreateMemoryRequest, CreateMemoryWithPreprocessingRequest, CreateTopicRequest, EnhancedMemorySearchResult, EnhancedSearchRequest, EnhancedSearchResponse, ErrorCode, ExtendedMemoryStats, HourlyAccess, IntelligentMetadata, MatchingChunk, MemoryEntry, MemoryIntelligence, MemorySearchResult, MemoryStatus, MemoryTopic, MemoryType, MostAccessedMemory, PaginatedResponse, PopularQuery, PreprocessingOptions, ProjectMemoryCount, SafeJsonResult, SearchAnalytics, SearchAnalyticsDataPoint, SearchFilters, SearchMemoryRequest, SearchMode, TagCount, UpdateMemoryRequest, UpdateMemoryWithPreprocessingRequest, UserMemoryStats };