@lanonasis/memory-client 1.0.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -143,22 +143,50 @@ type UpdateMemoryRequest = z.infer<typeof updateMemorySchema>;
143
143
  type SearchMemoryRequest = z.infer<typeof searchMemorySchema>;
144
144
  type CreateTopicRequest = z.infer<typeof createTopicSchema>;
145
145
 
146
+ /**
147
+ * Core Memory Client - Pure Browser-Safe Implementation
148
+ *
149
+ * NO Node.js dependencies, NO CLI code, NO child_process
150
+ * Works in: Browser, React Native, Cloudflare Workers, Edge Functions, Deno, Bun
151
+ *
152
+ * Bundle size: ~15KB gzipped
153
+ */
154
+
146
155
  /**
147
156
  * Configuration options for the Memory Client
148
157
  */
149
- interface MemoryClientConfig {
158
+ interface CoreMemoryClientConfig {
150
159
  /** API endpoint URL */
151
160
  apiUrl: string;
152
161
  /** API key for authentication */
153
162
  apiKey?: string;
154
163
  /** Bearer token for authentication (alternative to API key) */
155
164
  authToken?: string;
156
- /** Request timeout in milliseconds */
165
+ /** Organization ID (optional - will be auto-resolved if not provided) */
166
+ organizationId?: string;
167
+ /** User ID (optional - used as fallback for organization ID) */
168
+ userId?: string;
169
+ /** Request timeout in milliseconds (default: 30000) */
157
170
  timeout?: number;
158
- /** Enable gateway mode for enhanced performance */
159
- useGateway?: boolean;
160
171
  /** Custom headers to include with requests */
161
172
  headers?: Record<string, string>;
173
+ /** Retry configuration */
174
+ retry?: {
175
+ maxRetries?: number;
176
+ retryDelay?: number;
177
+ backoff?: 'linear' | 'exponential';
178
+ };
179
+ /** Cache configuration (browser only) */
180
+ cache?: {
181
+ enabled?: boolean;
182
+ ttl?: number;
183
+ };
184
+ /** Called when an error occurs */
185
+ onError?: (error: ApiError$1) => void;
186
+ /** Called before each request */
187
+ onRequest?: (endpoint: string) => void;
188
+ /** Called after each response */
189
+ onResponse?: (endpoint: string, duration: number) => void;
162
190
  }
163
191
  /**
164
192
  * Standard API response wrapper
@@ -168,6 +196,15 @@ interface ApiResponse<T> {
168
196
  error?: string;
169
197
  message?: string;
170
198
  }
199
+ /**
200
+ * API error with details
201
+ */
202
+ interface ApiError$1 {
203
+ message: string;
204
+ code?: string;
205
+ statusCode?: number;
206
+ details?: unknown;
207
+ }
171
208
  /**
172
209
  * Paginated response for list operations
173
210
  */
@@ -181,12 +218,20 @@ interface PaginatedResponse<T> {
181
218
  };
182
219
  }
183
220
  /**
184
- * Memory Client class for interacting with the Memory as a Service API
221
+ * Core Memory Client class for interacting with the Memory as a Service API
222
+ *
223
+ * This is a pure browser-safe client with zero Node.js dependencies.
224
+ * It uses only standard web APIs (fetch, AbortController, etc.)
185
225
  */
186
- declare class MemoryClient {
226
+ declare class CoreMemoryClient {
187
227
  private config;
188
228
  private baseHeaders;
189
- constructor(config: MemoryClientConfig);
229
+ constructor(config: CoreMemoryClientConfig);
230
+ /**
231
+ * Enrich request body with organization context if configured
232
+ * This ensures the API has the organization_id even if not in auth token
233
+ */
234
+ private enrichWithOrgContext;
190
235
  /**
191
236
  * Make an HTTP request to the API
192
237
  */
@@ -282,375 +327,100 @@ declare class MemoryClient {
282
327
  /**
283
328
  * Update configuration
284
329
  */
285
- updateConfig(updates: Partial<MemoryClientConfig>): void;
330
+ updateConfig(updates: Partial<CoreMemoryClientConfig>): void;
286
331
  /**
287
332
  * Get current configuration (excluding sensitive data)
288
333
  */
289
- getConfig(): Omit<MemoryClientConfig, 'apiKey' | 'authToken'>;
334
+ getConfig(): Omit<CoreMemoryClientConfig, 'apiKey' | 'authToken'>;
290
335
  }
291
336
  /**
292
- * Factory function to create a new Memory Client instance
337
+ * Factory function to create a new Core Memory Client instance
293
338
  */
294
- declare function createMemoryClient(config: MemoryClientConfig): MemoryClient;
339
+ declare function createMemoryClient(config: CoreMemoryClientConfig): CoreMemoryClient;
295
340
 
296
341
  /**
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
342
+ * Error handling for Memory Client
343
+ * Browser-safe, no Node.js dependencies
301
344
  */
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
345
  /**
358
- * CLI Detection and Integration Service
346
+ * Base error class for Memory Client errors
359
347
  */
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>>;
372
- /**
373
- * Get preferred CLI command (onasis for Golden Contract, fallback to lanonasis)
374
- */
375
- private getPreferredCLICommand;
376
- /**
377
- * Memory operations via CLI
378
- */
379
- createMemoryViaCLI(title: string, content: string, options?: {
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?: {
391
- limit?: number;
392
- memoryTypes?: string[];
393
- }): Promise<ApiResponse<{
394
- results: MemorySearchResult[];
395
- total_results: number;
396
- search_time_ms: number;
397
- }>>;
398
- /**
399
- * Health check via CLI
400
- */
401
- healthCheckViaCLI(): Promise<ApiResponse<{
402
- status: string;
403
- timestamp: string;
404
- }>>;
405
- /**
406
- * MCP-specific operations
407
- */
408
- getMCPStatus(): Promise<ApiResponse<CLIMCPStatus>>;
409
- listMCPTools(): Promise<ApiResponse<{
410
- tools: CLIMCPTool[];
411
- }>>;
412
- /**
413
- * Authentication operations
414
- */
415
- getAuthStatus(): Promise<ApiResponse<CLIAuthStatus>>;
416
- /**
417
- * Check if specific CLI features are available
418
- */
419
- getCapabilities(): Promise<{
420
- cliAvailable: boolean;
421
- version?: string;
422
- mcpSupport: boolean;
423
- authenticated: boolean;
424
- goldenContract: boolean;
425
- }>;
426
- private isGoldenContractCompliant;
427
- /**
428
- * Force refresh CLI detection
429
- */
430
- refresh(): Promise<CLIInfo>;
431
- /**
432
- * Get cached CLI info without re-detection
433
- */
434
- getCachedInfo(): CLIInfo | null;
348
+ declare class MemoryClientError extends Error {
349
+ code?: string | undefined;
350
+ statusCode?: number | undefined;
351
+ details?: unknown | undefined;
352
+ constructor(message: string, code?: string | undefined, statusCode?: number | undefined, details?: unknown | undefined);
435
353
  }
436
-
437
354
  /**
438
- * Enhanced Memory Client with CLI Integration
439
- *
440
- * Intelligently routes requests through CLI v1.5.2+ when available,
441
- * with fallback to direct API for maximum compatibility and performance
355
+ * Network/API error
442
356
  */
443
-
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;
357
+ declare class ApiError extends MemoryClientError {
358
+ constructor(message: string, statusCode?: number, details?: unknown);
463
359
  }
464
360
  /**
465
- * Enhanced Memory Client with intelligent CLI/API routing
361
+ * Authentication error
466
362
  */
467
- declare class EnhancedMemoryClient {
468
- private directClient;
469
- private cliIntegration;
470
- private config;
471
- private capabilities;
472
- private createDefaultCapabilities;
473
- constructor(config: EnhancedMemoryClientConfig);
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
- };
363
+ declare class AuthenticationError extends MemoryClientError {
364
+ constructor(message?: string);
575
365
  }
576
366
  /**
577
- * Factory function to create an enhanced memory client
367
+ * Validation error
578
368
  */
579
- declare function createEnhancedMemoryClient(config: EnhancedMemoryClientConfig): Promise<EnhancedMemoryClient>;
580
-
581
- /**
582
- * Configuration utilities for Memory Client SDK
583
- * Provides smart defaults and environment detection for CLI/MCP integration
584
- */
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;
369
+ declare class ValidationError extends MemoryClientError {
370
+ constructor(message: string, details?: unknown);
599
371
  }
600
372
  /**
601
- * Environment detection utilities
373
+ * Timeout error
602
374
  */
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
- };
612
- /**
613
- * Create smart configuration with environment-aware defaults
614
- */
615
- declare function createSmartConfig(baseConfig: Partial<MemoryClientConfig>, options?: SmartConfigOptions): EnhancedMemoryClientConfig;
375
+ declare class TimeoutError extends MemoryClientError {
376
+ constructor(message?: string);
377
+ }
616
378
  /**
617
- * Preset configurations for common scenarios
379
+ * Rate limit error
618
380
  */
619
- declare const ConfigPresets: {
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
- };
381
+ declare class RateLimitError extends MemoryClientError {
382
+ constructor(message?: string);
383
+ }
641
384
  /**
642
- * Migration helper for existing MemoryClient users
385
+ * Not found error
643
386
  */
644
- declare function migrateToEnhanced(existingConfig: MemoryClientConfig, enhancementOptions?: SmartConfigOptions): EnhancedMemoryClientConfig;
387
+ declare class NotFoundError extends MemoryClientError {
388
+ constructor(resource: string);
389
+ }
645
390
 
646
391
  /**
647
392
  * @lanonasis/memory-client
648
393
  *
649
- * Memory as a Service (MaaS) Client SDK for Lanonasis
394
+ * Universal Memory as a Service (MaaS) Client SDK for Lanonasis
650
395
  * Intelligent memory management with semantic search capabilities
396
+ *
397
+ * v2.0.0 - Universal SDK Redesign
398
+ * "Drop In and Sleep" Architecture - Works everywhere with zero configuration
399
+ *
400
+ * @example Browser/Web App
401
+ * ```ts
402
+ * import { createMemoryClient } from '@lanonasis/memory-client/core';
403
+ * const client = createMemoryClient({ apiKey: 'your-key' });
404
+ * ```
405
+ *
406
+ * @example Node.js
407
+ * ```ts
408
+ * import { createNodeMemoryClient } from '@lanonasis/memory-client/node';
409
+ * const client = await createNodeMemoryClient({ apiKey: process.env.KEY });
410
+ * ```
411
+ *
412
+ * @example React
413
+ * ```tsx
414
+ * import { MemoryProvider, useMemories } from '@lanonasis/memory-client/react';
415
+ * ```
416
+ *
417
+ * @example Vue
418
+ * ```ts
419
+ * import { createMemoryPlugin, useMemories } from '@lanonasis/memory-client/vue';
420
+ * ```
651
421
  */
652
422
 
653
- declare const VERSION = "1.0.0";
423
+ declare const VERSION = "2.0.0";
654
424
  declare const CLIENT_NAME = "@lanonasis/memory-client";
655
425
  declare const isBrowser: boolean;
656
426
  declare const isNode: string | false;
@@ -658,19 +428,16 @@ declare const defaultConfigs: {
658
428
  readonly development: {
659
429
  readonly apiUrl: "http://localhost:3001";
660
430
  readonly timeout: 30000;
661
- readonly useGateway: false;
662
431
  };
663
432
  readonly production: {
664
433
  readonly apiUrl: "https://api.lanonasis.com";
665
434
  readonly timeout: 15000;
666
- readonly useGateway: true;
667
435
  };
668
- readonly gateway: {
436
+ readonly edge: {
669
437
  readonly apiUrl: "https://api.lanonasis.com";
670
- readonly timeout: 10000;
671
- readonly useGateway: true;
438
+ readonly timeout: 5000;
672
439
  };
673
440
  };
674
441
 
675
- export { CLIENT_NAME, CLIIntegration, ConfigPresets, EnhancedMemoryClient, Environment, MEMORY_STATUSES, MEMORY_TYPES, MemoryClient, VERSION, createEnhancedMemoryClient, createMemoryClient, createMemorySchema, createSmartConfig, createTopicSchema, defaultConfigs, isBrowser, isNode, migrateToEnhanced, searchMemorySchema, updateMemorySchema };
676
- export type { ApiResponse, CLICapabilities, CLICommand, CLIInfo, CreateMemoryRequest, CreateTopicRequest, EnhancedMemoryClientConfig, MCPChannel, MemoryClientConfig, MemoryEntry, MemorySearchResult, MemoryStatus, MemoryTopic, MemoryType, OperationResult, PaginatedResponse, RoutingStrategy, SearchMemoryRequest, SmartConfigOptions, UpdateMemoryRequest, UserMemoryStats };
442
+ export { ApiError as ApiErrorClass, AuthenticationError, CLIENT_NAME, CoreMemoryClient, MEMORY_STATUSES, MEMORY_TYPES, CoreMemoryClient as MemoryClient, MemoryClientError, NotFoundError, RateLimitError, TimeoutError, VERSION, ValidationError, createMemoryClient, createMemorySchema, createTopicSchema, defaultConfigs, isBrowser, isNode, searchMemorySchema, updateMemorySchema };
443
+ export type { ApiError$1 as ApiError, ApiResponse, CoreMemoryClientConfig, CreateMemoryRequest, CreateTopicRequest, CoreMemoryClientConfig as MemoryClientConfig, MemoryEntry, MemorySearchResult, MemoryStatus, MemoryTopic, MemoryType, PaginatedResponse, SearchMemoryRequest, UpdateMemoryRequest, UserMemoryStats };