@lanonasis/memory-client 1.0.0 → 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.
@@ -0,0 +1,490 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * Core Memory Client - Pure Browser-Safe Implementation
5
+ *
6
+ * NO Node.js dependencies, NO CLI code, NO child_process
7
+ * Works in: Browser, React Native, Cloudflare Workers, Edge Functions, Deno, Bun
8
+ *
9
+ * Bundle size: ~15KB gzipped
10
+ */
11
+ /**
12
+ * Core Memory Client class for interacting with the Memory as a Service API
13
+ *
14
+ * This is a pure browser-safe client with zero Node.js dependencies.
15
+ * It uses only standard web APIs (fetch, AbortController, etc.)
16
+ */
17
+ class CoreMemoryClient {
18
+ constructor(config) {
19
+ this.config = {
20
+ timeout: 30000,
21
+ ...config
22
+ };
23
+ this.baseHeaders = {
24
+ 'Content-Type': 'application/json',
25
+ 'User-Agent': '@lanonasis/memory-client/2.0.0',
26
+ ...config.headers
27
+ };
28
+ // Set authentication headers
29
+ if (config.authToken) {
30
+ this.baseHeaders['Authorization'] = `Bearer ${config.authToken}`;
31
+ }
32
+ else if (config.apiKey) {
33
+ this.baseHeaders['X-API-Key'] = config.apiKey;
34
+ }
35
+ // Add organization ID header if provided
36
+ if (config.organizationId) {
37
+ this.baseHeaders['X-Organization-ID'] = config.organizationId;
38
+ }
39
+ }
40
+ /**
41
+ * Enrich request body with organization context if configured
42
+ * This ensures the API has the organization_id even if not in auth token
43
+ */
44
+ enrichWithOrgContext(body) {
45
+ // If organizationId is configured, include it in the request body
46
+ if (this.config.organizationId && !body.organization_id) {
47
+ return {
48
+ ...body,
49
+ organization_id: this.config.organizationId
50
+ };
51
+ }
52
+ // Fallback to userId if no organizationId configured
53
+ if (!this.config.organizationId && this.config.userId && !body.organization_id) {
54
+ return {
55
+ ...body,
56
+ organization_id: this.config.userId
57
+ };
58
+ }
59
+ return body;
60
+ }
61
+ /**
62
+ * Make an HTTP request to the API
63
+ */
64
+ async request(endpoint, options = {}) {
65
+ const startTime = Date.now();
66
+ // Call onRequest hook if provided
67
+ if (this.config.onRequest) {
68
+ try {
69
+ this.config.onRequest(endpoint);
70
+ }
71
+ catch (error) {
72
+ console.warn('onRequest hook error:', error);
73
+ }
74
+ }
75
+ // Handle gateway vs direct API URL formatting
76
+ const baseUrl = this.config.apiUrl.includes('/api')
77
+ ? this.config.apiUrl.replace('/api', '')
78
+ : this.config.apiUrl;
79
+ const url = `${baseUrl}/api/v1${endpoint}`;
80
+ try {
81
+ const controller = new AbortController();
82
+ const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
83
+ const response = await fetch(url, {
84
+ headers: { ...this.baseHeaders, ...options.headers },
85
+ signal: controller.signal,
86
+ ...options,
87
+ });
88
+ clearTimeout(timeoutId);
89
+ let data;
90
+ const contentType = response.headers.get('content-type');
91
+ if (contentType && contentType.includes('application/json')) {
92
+ data = await response.json();
93
+ }
94
+ else {
95
+ data = await response.text();
96
+ }
97
+ if (!response.ok) {
98
+ const error = {
99
+ message: data?.error || `HTTP ${response.status}: ${response.statusText}`,
100
+ statusCode: response.status,
101
+ code: 'API_ERROR'
102
+ };
103
+ // Call onError hook if provided
104
+ if (this.config.onError) {
105
+ try {
106
+ this.config.onError(error);
107
+ }
108
+ catch (hookError) {
109
+ console.warn('onError hook error:', hookError);
110
+ }
111
+ }
112
+ return { error: error.message };
113
+ }
114
+ // Call onResponse hook if provided
115
+ if (this.config.onResponse) {
116
+ try {
117
+ const duration = Date.now() - startTime;
118
+ this.config.onResponse(endpoint, duration);
119
+ }
120
+ catch (error) {
121
+ console.warn('onResponse hook error:', error);
122
+ }
123
+ }
124
+ return { data };
125
+ }
126
+ catch (error) {
127
+ if (error instanceof Error && error.name === 'AbortError') {
128
+ const timeoutError = {
129
+ message: 'Request timeout',
130
+ code: 'TIMEOUT_ERROR',
131
+ statusCode: 408
132
+ };
133
+ if (this.config.onError) {
134
+ try {
135
+ this.config.onError(timeoutError);
136
+ }
137
+ catch (hookError) {
138
+ console.warn('onError hook error:', hookError);
139
+ }
140
+ }
141
+ return { error: 'Request timeout' };
142
+ }
143
+ const networkError = {
144
+ message: error instanceof Error ? error.message : 'Network error',
145
+ code: 'NETWORK_ERROR'
146
+ };
147
+ if (this.config.onError) {
148
+ try {
149
+ this.config.onError(networkError);
150
+ }
151
+ catch (hookError) {
152
+ console.warn('onError hook error:', hookError);
153
+ }
154
+ }
155
+ return {
156
+ error: error instanceof Error ? error.message : 'Network error'
157
+ };
158
+ }
159
+ }
160
+ /**
161
+ * Test the API connection and authentication
162
+ */
163
+ async healthCheck() {
164
+ return this.request('/health');
165
+ }
166
+ // Memory Operations
167
+ /**
168
+ * Create a new memory
169
+ */
170
+ async createMemory(memory) {
171
+ const enrichedMemory = this.enrichWithOrgContext(memory);
172
+ return this.request('/memory', {
173
+ method: 'POST',
174
+ body: JSON.stringify(enrichedMemory)
175
+ });
176
+ }
177
+ /**
178
+ * Get a memory by ID
179
+ */
180
+ async getMemory(id) {
181
+ return this.request(`/memory/${encodeURIComponent(id)}`);
182
+ }
183
+ /**
184
+ * Update an existing memory
185
+ */
186
+ async updateMemory(id, updates) {
187
+ return this.request(`/memory/${encodeURIComponent(id)}`, {
188
+ method: 'PUT',
189
+ body: JSON.stringify(updates)
190
+ });
191
+ }
192
+ /**
193
+ * Delete a memory
194
+ */
195
+ async deleteMemory(id) {
196
+ return this.request(`/memory/${encodeURIComponent(id)}`, {
197
+ method: 'DELETE'
198
+ });
199
+ }
200
+ /**
201
+ * List memories with optional filtering and pagination
202
+ */
203
+ async listMemories(options = {}) {
204
+ const params = new URLSearchParams();
205
+ Object.entries(options).forEach(([key, value]) => {
206
+ if (value !== undefined && value !== null) {
207
+ if (Array.isArray(value)) {
208
+ params.append(key, value.join(','));
209
+ }
210
+ else {
211
+ params.append(key, String(value));
212
+ }
213
+ }
214
+ });
215
+ const queryString = params.toString();
216
+ const endpoint = queryString ? `/memory?${queryString}` : '/memory';
217
+ return this.request(endpoint);
218
+ }
219
+ /**
220
+ * Search memories using semantic search
221
+ */
222
+ async searchMemories(request) {
223
+ const enrichedRequest = this.enrichWithOrgContext(request);
224
+ return this.request('/memory/search', {
225
+ method: 'POST',
226
+ body: JSON.stringify(enrichedRequest)
227
+ });
228
+ }
229
+ /**
230
+ * Bulk delete multiple memories
231
+ */
232
+ async bulkDeleteMemories(memoryIds) {
233
+ const enrichedRequest = this.enrichWithOrgContext({ memory_ids: memoryIds });
234
+ return this.request('/memory/bulk/delete', {
235
+ method: 'POST',
236
+ body: JSON.stringify(enrichedRequest)
237
+ });
238
+ }
239
+ // Topic Operations
240
+ /**
241
+ * Create a new topic
242
+ */
243
+ async createTopic(topic) {
244
+ const enrichedTopic = this.enrichWithOrgContext(topic);
245
+ return this.request('/topics', {
246
+ method: 'POST',
247
+ body: JSON.stringify(enrichedTopic)
248
+ });
249
+ }
250
+ /**
251
+ * Get all topics
252
+ */
253
+ async getTopics() {
254
+ return this.request('/topics');
255
+ }
256
+ /**
257
+ * Get a topic by ID
258
+ */
259
+ async getTopic(id) {
260
+ return this.request(`/topics/${encodeURIComponent(id)}`);
261
+ }
262
+ /**
263
+ * Update a topic
264
+ */
265
+ async updateTopic(id, updates) {
266
+ return this.request(`/topics/${encodeURIComponent(id)}`, {
267
+ method: 'PUT',
268
+ body: JSON.stringify(updates)
269
+ });
270
+ }
271
+ /**
272
+ * Delete a topic
273
+ */
274
+ async deleteTopic(id) {
275
+ return this.request(`/topics/${encodeURIComponent(id)}`, {
276
+ method: 'DELETE'
277
+ });
278
+ }
279
+ /**
280
+ * Get user memory statistics
281
+ */
282
+ async getMemoryStats() {
283
+ return this.request('/memory/stats');
284
+ }
285
+ // Utility Methods
286
+ /**
287
+ * Update authentication token
288
+ */
289
+ setAuthToken(token) {
290
+ this.baseHeaders['Authorization'] = `Bearer ${token}`;
291
+ delete this.baseHeaders['X-API-Key'];
292
+ }
293
+ /**
294
+ * Update API key
295
+ */
296
+ setApiKey(apiKey) {
297
+ this.baseHeaders['X-API-Key'] = apiKey;
298
+ delete this.baseHeaders['Authorization'];
299
+ }
300
+ /**
301
+ * Clear authentication
302
+ */
303
+ clearAuth() {
304
+ delete this.baseHeaders['Authorization'];
305
+ delete this.baseHeaders['X-API-Key'];
306
+ }
307
+ /**
308
+ * Update configuration
309
+ */
310
+ updateConfig(updates) {
311
+ this.config = { ...this.config, ...updates };
312
+ if (updates.headers) {
313
+ this.baseHeaders = { ...this.baseHeaders, ...updates.headers };
314
+ }
315
+ }
316
+ /**
317
+ * Get current configuration (excluding sensitive data)
318
+ */
319
+ getConfig() {
320
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
321
+ const { apiKey, authToken, ...safeConfig } = this.config;
322
+ return safeConfig;
323
+ }
324
+ }
325
+ /**
326
+ * Factory function to create a new Core Memory Client instance
327
+ */
328
+ function createMemoryClient(config) {
329
+ return new CoreMemoryClient(config);
330
+ }
331
+
332
+ /**
333
+ * Memory types supported by the service
334
+ */
335
+ const MEMORY_TYPES = ['context', 'project', 'knowledge', 'reference', 'personal', 'workflow'];
336
+ /**
337
+ * Memory status values
338
+ */
339
+ const MEMORY_STATUSES = ['active', 'archived', 'draft', 'deleted'];
340
+ /**
341
+ * Validation schemas using Zod
342
+ */
343
+ const createMemorySchema = z.object({
344
+ title: z.string().min(1).max(500),
345
+ content: z.string().min(1).max(50000),
346
+ summary: z.string().max(1000).optional(),
347
+ memory_type: z.enum(MEMORY_TYPES).default('context'),
348
+ topic_id: z.string().uuid().optional(),
349
+ project_ref: z.string().max(100).optional(),
350
+ tags: z.array(z.string().min(1).max(50)).max(20).default([]),
351
+ metadata: z.record(z.string(), z.unknown()).optional()
352
+ });
353
+ const updateMemorySchema = z.object({
354
+ title: z.string().min(1).max(500).optional(),
355
+ content: z.string().min(1).max(50000).optional(),
356
+ summary: z.string().max(1000).optional(),
357
+ memory_type: z.enum(MEMORY_TYPES).optional(),
358
+ status: z.enum(MEMORY_STATUSES).optional(),
359
+ topic_id: z.string().uuid().nullable().optional(),
360
+ project_ref: z.string().max(100).nullable().optional(),
361
+ tags: z.array(z.string().min(1).max(50)).max(20).optional(),
362
+ metadata: z.record(z.string(), z.unknown()).optional()
363
+ });
364
+ const searchMemorySchema = z.object({
365
+ query: z.string().min(1).max(1000),
366
+ memory_types: z.array(z.enum(MEMORY_TYPES)).optional(),
367
+ tags: z.array(z.string()).optional(),
368
+ topic_id: z.string().uuid().optional(),
369
+ project_ref: z.string().optional(),
370
+ status: z.enum(MEMORY_STATUSES).default('active'),
371
+ limit: z.number().int().min(1).max(100).default(20),
372
+ threshold: z.number().min(0).max(1).default(0.7)
373
+ });
374
+ const createTopicSchema = z.object({
375
+ name: z.string().min(1).max(100),
376
+ description: z.string().max(500).optional(),
377
+ color: z.string().regex(/^#[0-9A-Fa-f]{6}$/).optional(),
378
+ icon: z.string().max(50).optional(),
379
+ parent_topic_id: z.string().uuid().optional()
380
+ });
381
+
382
+ /**
383
+ * Error handling for Memory Client
384
+ * Browser-safe, no Node.js dependencies
385
+ */
386
+ /**
387
+ * Base error class for Memory Client errors
388
+ */
389
+ class MemoryClientError extends Error {
390
+ constructor(message, code, statusCode, details) {
391
+ super(message);
392
+ this.code = code;
393
+ this.statusCode = statusCode;
394
+ this.details = details;
395
+ this.name = 'MemoryClientError';
396
+ // Maintains proper stack trace for where our error was thrown (only available on V8)
397
+ if (Error.captureStackTrace) {
398
+ Error.captureStackTrace(this, MemoryClientError);
399
+ }
400
+ }
401
+ }
402
+ /**
403
+ * Network/API error
404
+ */
405
+ class ApiError extends MemoryClientError {
406
+ constructor(message, statusCode, details) {
407
+ super(message, 'API_ERROR', statusCode, details);
408
+ this.name = 'ApiError';
409
+ }
410
+ }
411
+ /**
412
+ * Authentication error
413
+ */
414
+ class AuthenticationError extends MemoryClientError {
415
+ constructor(message = 'Authentication required') {
416
+ super(message, 'AUTH_ERROR', 401);
417
+ this.name = 'AuthenticationError';
418
+ }
419
+ }
420
+ /**
421
+ * Validation error
422
+ */
423
+ class ValidationError extends MemoryClientError {
424
+ constructor(message, details) {
425
+ super(message, 'VALIDATION_ERROR', 400, details);
426
+ this.name = 'ValidationError';
427
+ }
428
+ }
429
+ /**
430
+ * Timeout error
431
+ */
432
+ class TimeoutError extends MemoryClientError {
433
+ constructor(message = 'Request timeout') {
434
+ super(message, 'TIMEOUT_ERROR', 408);
435
+ this.name = 'TimeoutError';
436
+ }
437
+ }
438
+ /**
439
+ * Rate limit error
440
+ */
441
+ class RateLimitError extends MemoryClientError {
442
+ constructor(message = 'Rate limit exceeded') {
443
+ super(message, 'RATE_LIMIT_ERROR', 429);
444
+ this.name = 'RateLimitError';
445
+ }
446
+ }
447
+ /**
448
+ * Not found error
449
+ */
450
+ class NotFoundError extends MemoryClientError {
451
+ constructor(resource) {
452
+ super(`${resource} not found`, 'NOT_FOUND', 404);
453
+ this.name = 'NotFoundError';
454
+ }
455
+ }
456
+
457
+ /**
458
+ * @lanonasis/memory-client/core
459
+ *
460
+ * Pure browser-safe Memory Client
461
+ * NO Node.js dependencies, NO CLI code, NO child_process
462
+ * Works in: Browser, React Native, Cloudflare Workers, Edge Functions, Deno, Bun
463
+ *
464
+ * Bundle size: ~15KB gzipped
465
+ */
466
+ // Client
467
+ // Constants
468
+ const VERSION = '2.0.0';
469
+ const CLIENT_NAME = '@lanonasis/memory-client';
470
+ // Environment detection (browser-safe)
471
+ const isBrowser = typeof window !== 'undefined';
472
+ const isNode = typeof globalThis !== 'undefined' && 'process' in globalThis && globalThis.process?.versions?.node;
473
+ // Default configurations for different environments
474
+ const defaultConfigs = {
475
+ development: {
476
+ apiUrl: 'http://localhost:3001',
477
+ timeout: 30000,
478
+ },
479
+ production: {
480
+ apiUrl: 'https://api.lanonasis.com',
481
+ timeout: 15000,
482
+ },
483
+ edge: {
484
+ apiUrl: 'https://api.lanonasis.com',
485
+ timeout: 5000, // Lower timeout for edge environments
486
+ }
487
+ };
488
+
489
+ export { ApiError as ApiErrorClass, AuthenticationError, CLIENT_NAME, CoreMemoryClient, MEMORY_STATUSES, MEMORY_TYPES, MemoryClientError, NotFoundError, RateLimitError, TimeoutError, VERSION, ValidationError, createMemoryClient, createMemorySchema, createTopicSchema, defaultConfigs, isBrowser, isNode, searchMemorySchema, updateMemorySchema };
490
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/core/client.ts","../../src/core/types.ts","../../src/core/errors.ts","../../src/core/index.ts"],"sourcesContent":["/**\n * Core Memory Client - Pure Browser-Safe Implementation\n *\n * NO Node.js dependencies, NO CLI code, NO child_process\n * Works in: Browser, React Native, Cloudflare Workers, Edge Functions, Deno, Bun\n *\n * Bundle size: ~15KB gzipped\n */\n\nimport type {\n MemoryEntry,\n MemoryTopic,\n CreateMemoryRequest,\n UpdateMemoryRequest,\n SearchMemoryRequest,\n CreateTopicRequest,\n MemorySearchResult,\n UserMemoryStats\n} from './types';\n\n/**\n * Configuration options for the Memory Client\n */\nexport interface CoreMemoryClientConfig {\n /** API endpoint URL */\n apiUrl: string;\n /** API key for authentication */\n apiKey?: string;\n /** Bearer token for authentication (alternative to API key) */\n authToken?: string;\n /** Organization ID (optional - will be auto-resolved if not provided) */\n organizationId?: string;\n /** User ID (optional - used as fallback for organization ID) */\n userId?: string;\n /** Request timeout in milliseconds (default: 30000) */\n timeout?: number;\n /** Custom headers to include with requests */\n headers?: Record<string, string>;\n\n // Advanced options (all optional)\n /** Retry configuration */\n retry?: {\n maxRetries?: number;\n retryDelay?: number;\n backoff?: 'linear' | 'exponential';\n };\n /** Cache configuration (browser only) */\n cache?: {\n enabled?: boolean;\n ttl?: number;\n };\n\n // Hooks for custom behavior\n /** Called when an error occurs */\n onError?: (error: ApiError) => void;\n /** Called before each request */\n onRequest?: (endpoint: string) => void;\n /** Called after each response */\n onResponse?: (endpoint: string, duration: number) => void;\n}\n\n/**\n * Standard API response wrapper\n */\nexport interface ApiResponse<T> {\n data?: T;\n error?: string;\n message?: string;\n}\n\n/**\n * API error with details\n */\nexport interface ApiError {\n message: string;\n code?: string;\n statusCode?: number;\n details?: unknown;\n}\n\n/**\n * Paginated response for list operations\n */\nexport interface PaginatedResponse<T> {\n data: T[];\n pagination: {\n page: number;\n limit: number;\n total: number;\n pages: number;\n };\n}\n\n/**\n * Core Memory Client class for interacting with the Memory as a Service API\n *\n * This is a pure browser-safe client with zero Node.js dependencies.\n * It uses only standard web APIs (fetch, AbortController, etc.)\n */\nexport class CoreMemoryClient {\n private config: Required<Omit<CoreMemoryClientConfig, 'apiKey' | 'authToken' | 'organizationId' | 'userId' | 'headers' | 'retry' | 'cache' | 'onError' | 'onRequest' | 'onResponse'>> &\n Pick<CoreMemoryClientConfig, 'apiKey' | 'authToken' | 'organizationId' | 'userId' | 'headers' | 'retry' | 'cache' | 'onError' | 'onRequest' | 'onResponse'>;\n private baseHeaders: Record<string, string>;\n\n constructor(config: CoreMemoryClientConfig) {\n this.config = {\n timeout: 30000,\n ...config\n };\n\n this.baseHeaders = {\n 'Content-Type': 'application/json',\n 'User-Agent': '@lanonasis/memory-client/2.0.0',\n ...config.headers\n };\n\n // Set authentication headers\n if (config.authToken) {\n this.baseHeaders['Authorization'] = `Bearer ${config.authToken}`;\n } else if (config.apiKey) {\n this.baseHeaders['X-API-Key'] = config.apiKey;\n }\n\n // Add organization ID header if provided\n if (config.organizationId) {\n this.baseHeaders['X-Organization-ID'] = config.organizationId;\n }\n }\n\n /**\n * Enrich request body with organization context if configured\n * This ensures the API has the organization_id even if not in auth token\n */\n private enrichWithOrgContext<T extends Record<string, unknown>>(body: T): T {\n // If organizationId is configured, include it in the request body\n if (this.config.organizationId && !body.organization_id) {\n return {\n ...body,\n organization_id: this.config.organizationId\n };\n }\n // Fallback to userId if no organizationId configured\n if (!this.config.organizationId && this.config.userId && !body.organization_id) {\n return {\n ...body,\n organization_id: this.config.userId\n };\n }\n return body;\n }\n\n /**\n * Make an HTTP request to the API\n */\n private async request<T>(\n endpoint: string,\n options: RequestInit = {}\n ): Promise<ApiResponse<T>> {\n const startTime = Date.now();\n\n // Call onRequest hook if provided\n if (this.config.onRequest) {\n try {\n this.config.onRequest(endpoint);\n } catch (error) {\n console.warn('onRequest hook error:', error);\n }\n }\n\n // Handle gateway vs direct API URL formatting\n const baseUrl = this.config.apiUrl.includes('/api')\n ? this.config.apiUrl.replace('/api', '')\n : this.config.apiUrl;\n\n const url = `${baseUrl}/api/v1${endpoint}`;\n\n try {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);\n\n const response = await fetch(url, {\n headers: { ...this.baseHeaders, ...options.headers },\n signal: controller.signal,\n ...options,\n });\n\n clearTimeout(timeoutId);\n\n let data: T;\n const contentType = response.headers.get('content-type');\n\n if (contentType && contentType.includes('application/json')) {\n data = await response.json() as T;\n } else {\n data = await response.text() as unknown as T;\n }\n\n if (!response.ok) {\n const error: ApiError = {\n message: (data as Record<string, unknown>)?.error as string || `HTTP ${response.status}: ${response.statusText}`,\n statusCode: response.status,\n code: 'API_ERROR'\n };\n\n // Call onError hook if provided\n if (this.config.onError) {\n try {\n this.config.onError(error);\n } catch (hookError) {\n console.warn('onError hook error:', hookError);\n }\n }\n\n return { error: error.message };\n }\n\n // Call onResponse hook if provided\n if (this.config.onResponse) {\n try {\n const duration = Date.now() - startTime;\n this.config.onResponse(endpoint, duration);\n } catch (error) {\n console.warn('onResponse hook error:', error);\n }\n }\n\n return { data };\n } catch (error) {\n if (error instanceof Error && error.name === 'AbortError') {\n const timeoutError: ApiError = {\n message: 'Request timeout',\n code: 'TIMEOUT_ERROR',\n statusCode: 408\n };\n\n if (this.config.onError) {\n try {\n this.config.onError(timeoutError);\n } catch (hookError) {\n console.warn('onError hook error:', hookError);\n }\n }\n\n return { error: 'Request timeout' };\n }\n\n const networkError: ApiError = {\n message: error instanceof Error ? error.message : 'Network error',\n code: 'NETWORK_ERROR'\n };\n\n if (this.config.onError) {\n try {\n this.config.onError(networkError);\n } catch (hookError) {\n console.warn('onError hook error:', hookError);\n }\n }\n\n return {\n error: error instanceof Error ? error.message : 'Network error'\n };\n }\n }\n\n /**\n * Test the API connection and authentication\n */\n async healthCheck(): Promise<ApiResponse<{ status: string; timestamp: string }>> {\n return this.request('/health');\n }\n\n // Memory Operations\n\n /**\n * Create a new memory\n */\n async createMemory(memory: CreateMemoryRequest): Promise<ApiResponse<MemoryEntry>> {\n const enrichedMemory = this.enrichWithOrgContext(memory as Record<string, unknown>);\n return this.request<MemoryEntry>('/memory', {\n method: 'POST',\n body: JSON.stringify(enrichedMemory)\n });\n }\n\n /**\n * Get a memory by ID\n */\n async getMemory(id: string): Promise<ApiResponse<MemoryEntry>> {\n return this.request<MemoryEntry>(`/memory/${encodeURIComponent(id)}`);\n }\n\n /**\n * Update an existing memory\n */\n async updateMemory(id: string, updates: UpdateMemoryRequest): Promise<ApiResponse<MemoryEntry>> {\n return this.request<MemoryEntry>(`/memory/${encodeURIComponent(id)}`, {\n method: 'PUT',\n body: JSON.stringify(updates)\n });\n }\n\n /**\n * Delete a memory\n */\n async deleteMemory(id: string): Promise<ApiResponse<void>> {\n return this.request<void>(`/memory/${encodeURIComponent(id)}`, {\n method: 'DELETE'\n });\n }\n\n /**\n * List memories with optional filtering and pagination\n */\n async listMemories(options: {\n page?: number;\n limit?: number;\n memory_type?: string;\n topic_id?: string;\n project_ref?: string;\n status?: string;\n tags?: string[];\n sort?: string;\n order?: 'asc' | 'desc';\n } = {}): Promise<ApiResponse<PaginatedResponse<MemoryEntry>>> {\n const params = new URLSearchParams();\n\n Object.entries(options).forEach(([key, value]) => {\n if (value !== undefined && value !== null) {\n if (Array.isArray(value)) {\n params.append(key, value.join(','));\n } else {\n params.append(key, String(value));\n }\n }\n });\n\n const queryString = params.toString();\n const endpoint = queryString ? `/memory?${queryString}` : '/memory';\n\n return this.request<PaginatedResponse<MemoryEntry>>(endpoint);\n }\n\n /**\n * Search memories using semantic search\n */\n async searchMemories(request: SearchMemoryRequest): Promise<ApiResponse<{\n results: MemorySearchResult[];\n total_results: number;\n search_time_ms: number;\n }>> {\n const enrichedRequest = this.enrichWithOrgContext(request as Record<string, unknown>);\n return this.request('/memory/search', {\n method: 'POST',\n body: JSON.stringify(enrichedRequest)\n });\n }\n\n /**\n * Bulk delete multiple memories\n */\n async bulkDeleteMemories(memoryIds: string[]): Promise<ApiResponse<{\n deleted_count: number;\n failed_ids: string[];\n }>> {\n const enrichedRequest = this.enrichWithOrgContext({ memory_ids: memoryIds });\n return this.request('/memory/bulk/delete', {\n method: 'POST',\n body: JSON.stringify(enrichedRequest)\n });\n }\n\n // Topic Operations\n\n /**\n * Create a new topic\n */\n async createTopic(topic: CreateTopicRequest): Promise<ApiResponse<MemoryTopic>> {\n const enrichedTopic = this.enrichWithOrgContext(topic as Record<string, unknown>);\n return this.request<MemoryTopic>('/topics', {\n method: 'POST',\n body: JSON.stringify(enrichedTopic)\n });\n }\n\n /**\n * Get all topics\n */\n async getTopics(): Promise<ApiResponse<MemoryTopic[]>> {\n return this.request<MemoryTopic[]>('/topics');\n }\n\n /**\n * Get a topic by ID\n */\n async getTopic(id: string): Promise<ApiResponse<MemoryTopic>> {\n return this.request<MemoryTopic>(`/topics/${encodeURIComponent(id)}`);\n }\n\n /**\n * Update a topic\n */\n async updateTopic(id: string, updates: Partial<CreateTopicRequest>): Promise<ApiResponse<MemoryTopic>> {\n return this.request<MemoryTopic>(`/topics/${encodeURIComponent(id)}`, {\n method: 'PUT',\n body: JSON.stringify(updates)\n });\n }\n\n /**\n * Delete a topic\n */\n async deleteTopic(id: string): Promise<ApiResponse<void>> {\n return this.request<void>(`/topics/${encodeURIComponent(id)}`, {\n method: 'DELETE'\n });\n }\n\n /**\n * Get user memory statistics\n */\n async getMemoryStats(): Promise<ApiResponse<UserMemoryStats>> {\n return this.request<UserMemoryStats>('/memory/stats');\n }\n\n // Utility Methods\n\n /**\n * Update authentication token\n */\n setAuthToken(token: string): void {\n this.baseHeaders['Authorization'] = `Bearer ${token}`;\n delete this.baseHeaders['X-API-Key'];\n }\n\n /**\n * Update API key\n */\n setApiKey(apiKey: string): void {\n this.baseHeaders['X-API-Key'] = apiKey;\n delete this.baseHeaders['Authorization'];\n }\n\n /**\n * Clear authentication\n */\n clearAuth(): void {\n delete this.baseHeaders['Authorization'];\n delete this.baseHeaders['X-API-Key'];\n }\n\n /**\n * Update configuration\n */\n updateConfig(updates: Partial<CoreMemoryClientConfig>): void {\n this.config = { ...this.config, ...updates };\n\n if (updates.headers) {\n this.baseHeaders = { ...this.baseHeaders, ...updates.headers };\n }\n }\n\n /**\n * Get current configuration (excluding sensitive data)\n */\n getConfig(): Omit<CoreMemoryClientConfig, 'apiKey' | 'authToken'> {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { apiKey, authToken, ...safeConfig } = this.config;\n return safeConfig;\n }\n}\n\n/**\n * Factory function to create a new Core Memory Client instance\n */\nexport function createMemoryClient(config: CoreMemoryClientConfig): CoreMemoryClient {\n return new CoreMemoryClient(config);\n}\n","import { z } from 'zod';\n\n/**\n * Memory types supported by the service\n */\nexport const MEMORY_TYPES = ['context', 'project', 'knowledge', 'reference', 'personal', 'workflow'] as const;\nexport type MemoryType = typeof MEMORY_TYPES[number];\n\n/**\n * Memory status values\n */\nexport const MEMORY_STATUSES = ['active', 'archived', 'draft', 'deleted'] as const;\nexport type MemoryStatus = typeof MEMORY_STATUSES[number];\n\n/**\n * Core memory entry interface\n */\nexport interface MemoryEntry {\n id: string;\n title: string;\n content: string;\n summary?: string;\n memory_type: MemoryType;\n status: MemoryStatus;\n relevance_score?: number;\n access_count: number;\n last_accessed?: string;\n user_id: string;\n topic_id?: string;\n project_ref?: string;\n tags: string[];\n metadata?: Record<string, unknown>;\n created_at: string;\n updated_at: string;\n}\n\n/**\n * Memory topic for organization\n */\nexport interface MemoryTopic {\n id: string;\n name: string;\n description?: string;\n color?: string;\n icon?: string;\n user_id: string;\n parent_topic_id?: string;\n is_system: boolean;\n metadata?: Record<string, unknown>;\n created_at: string;\n updated_at: string;\n}\n\n/**\n * Memory search result with similarity score\n */\nexport interface MemorySearchResult extends MemoryEntry {\n similarity_score: number;\n}\n\n/**\n * User memory statistics\n */\nexport interface UserMemoryStats {\n total_memories: number;\n memories_by_type: Record<MemoryType, number>;\n total_topics: number;\n most_accessed_memory?: string;\n recent_memories: string[];\n}\n\n/**\n * Validation schemas using Zod\n */\n\nexport const createMemorySchema = z.object({\n title: z.string().min(1).max(500),\n content: z.string().min(1).max(50000),\n summary: z.string().max(1000).optional(),\n memory_type: z.enum(MEMORY_TYPES).default('context'),\n topic_id: z.string().uuid().optional(),\n project_ref: z.string().max(100).optional(),\n tags: z.array(z.string().min(1).max(50)).max(20).default([]),\n metadata: z.record(z.string(), z.unknown()).optional()\n});\n\nexport const updateMemorySchema = z.object({\n title: z.string().min(1).max(500).optional(),\n content: z.string().min(1).max(50000).optional(),\n summary: z.string().max(1000).optional(),\n memory_type: z.enum(MEMORY_TYPES).optional(),\n status: z.enum(MEMORY_STATUSES).optional(),\n topic_id: z.string().uuid().nullable().optional(),\n project_ref: z.string().max(100).nullable().optional(),\n tags: z.array(z.string().min(1).max(50)).max(20).optional(),\n metadata: z.record(z.string(), z.unknown()).optional()\n});\n\nexport const searchMemorySchema = z.object({\n query: z.string().min(1).max(1000),\n memory_types: z.array(z.enum(MEMORY_TYPES)).optional(),\n tags: z.array(z.string()).optional(),\n topic_id: z.string().uuid().optional(),\n project_ref: z.string().optional(),\n status: z.enum(MEMORY_STATUSES).default('active'),\n limit: z.number().int().min(1).max(100).default(20),\n threshold: z.number().min(0).max(1).default(0.7)\n});\n\nexport const createTopicSchema = z.object({\n name: z.string().min(1).max(100),\n description: z.string().max(500).optional(),\n color: z.string().regex(/^#[0-9A-Fa-f]{6}$/).optional(),\n icon: z.string().max(50).optional(),\n parent_topic_id: z.string().uuid().optional()\n});\n\n/**\n * Inferred types from schemas\n */\nexport type CreateMemoryRequest = z.infer<typeof createMemorySchema>;\nexport type UpdateMemoryRequest = z.infer<typeof updateMemorySchema>;\nexport type SearchMemoryRequest = z.infer<typeof searchMemorySchema>;\nexport type CreateTopicRequest = z.infer<typeof createTopicSchema>;\n","/**\n * Error handling for Memory Client\n * Browser-safe, no Node.js dependencies\n */\n\n/**\n * Base error class for Memory Client errors\n */\nexport class MemoryClientError extends Error {\n constructor(\n message: string,\n public code?: string,\n public statusCode?: number,\n public details?: unknown\n ) {\n super(message);\n this.name = 'MemoryClientError';\n\n // Maintains proper stack trace for where our error was thrown (only available on V8)\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, MemoryClientError);\n }\n }\n}\n\n/**\n * Network/API error\n */\nexport class ApiError extends MemoryClientError {\n constructor(message: string, statusCode?: number, details?: unknown) {\n super(message, 'API_ERROR', statusCode, details);\n this.name = 'ApiError';\n }\n}\n\n/**\n * Authentication error\n */\nexport class AuthenticationError extends MemoryClientError {\n constructor(message: string = 'Authentication required') {\n super(message, 'AUTH_ERROR', 401);\n this.name = 'AuthenticationError';\n }\n}\n\n/**\n * Validation error\n */\nexport class ValidationError extends MemoryClientError {\n constructor(message: string, details?: unknown) {\n super(message, 'VALIDATION_ERROR', 400, details);\n this.name = 'ValidationError';\n }\n}\n\n/**\n * Timeout error\n */\nexport class TimeoutError extends MemoryClientError {\n constructor(message: string = 'Request timeout') {\n super(message, 'TIMEOUT_ERROR', 408);\n this.name = 'TimeoutError';\n }\n}\n\n/**\n * Rate limit error\n */\nexport class RateLimitError extends MemoryClientError {\n constructor(message: string = 'Rate limit exceeded') {\n super(message, 'RATE_LIMIT_ERROR', 429);\n this.name = 'RateLimitError';\n }\n}\n\n/**\n * Not found error\n */\nexport class NotFoundError extends MemoryClientError {\n constructor(resource: string) {\n super(`${resource} not found`, 'NOT_FOUND', 404);\n this.name = 'NotFoundError';\n }\n}\n","/**\n * @lanonasis/memory-client/core\n *\n * Pure browser-safe Memory Client\n * NO Node.js dependencies, NO CLI code, NO child_process\n * Works in: Browser, React Native, Cloudflare Workers, Edge Functions, Deno, Bun\n *\n * Bundle size: ~15KB gzipped\n */\n\n// Client\nexport {\n CoreMemoryClient,\n createMemoryClient\n} from './client';\n\nexport type {\n CoreMemoryClientConfig,\n ApiResponse,\n ApiError,\n PaginatedResponse\n} from './client';\n\n// Types\nexport type {\n MemoryEntry,\n MemoryTopic,\n CreateMemoryRequest,\n UpdateMemoryRequest,\n SearchMemoryRequest,\n CreateTopicRequest,\n MemorySearchResult,\n UserMemoryStats,\n MemoryType,\n MemoryStatus\n} from './types';\n\nexport {\n MEMORY_TYPES,\n MEMORY_STATUSES,\n createMemorySchema,\n updateMemorySchema,\n searchMemorySchema,\n createTopicSchema\n} from './types';\n\n// Errors\nexport {\n MemoryClientError,\n ApiError as ApiErrorClass,\n AuthenticationError,\n ValidationError,\n TimeoutError,\n RateLimitError,\n NotFoundError\n} from './errors';\n\n// Constants\nexport const VERSION = '2.0.0';\nexport const CLIENT_NAME = '@lanonasis/memory-client';\n\n// Environment detection (browser-safe)\nexport const isBrowser = typeof window !== 'undefined';\nexport const isNode = typeof globalThis !== 'undefined' && 'process' in globalThis && globalThis.process?.versions?.node;\n\n// Default configurations for different environments\nexport const defaultConfigs = {\n development: {\n apiUrl: 'http://localhost:3001',\n timeout: 30000,\n },\n production: {\n apiUrl: 'https://api.lanonasis.com',\n timeout: 15000,\n },\n edge: {\n apiUrl: 'https://api.lanonasis.com',\n timeout: 5000, // Lower timeout for edge environments\n }\n} as const;\n"],"names":[],"mappings":";;AAAA;;;;;;;AAOG;AAsFH;;;;;AAKG;MACU,gBAAgB,CAAA;AAK3B,IAAA,WAAA,CAAY,MAA8B,EAAA;QACxC,IAAI,CAAC,MAAM,GAAG;AACZ,YAAA,OAAO,EAAE,KAAK;AACd,YAAA,GAAG;SACJ;QAED,IAAI,CAAC,WAAW,GAAG;AACjB,YAAA,cAAc,EAAE,kBAAkB;AAClC,YAAA,YAAY,EAAE,gCAAgC;YAC9C,GAAG,MAAM,CAAC;SACX;;AAGD,QAAA,IAAI,MAAM,CAAC,SAAS,EAAE;YACpB,IAAI,CAAC,WAA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