@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.
@@ -0,0 +1,421 @@
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
+ /**
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
+
155
+ /**
156
+ * Configuration options for the Memory Client
157
+ */
158
+ interface CoreMemoryClientConfig {
159
+ /** API endpoint URL */
160
+ apiUrl: string;
161
+ /** API key for authentication */
162
+ apiKey?: string;
163
+ /** Bearer token for authentication (alternative to API key) */
164
+ authToken?: string;
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) */
170
+ timeout?: number;
171
+ /** Custom headers to include with requests */
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;
190
+ }
191
+ /**
192
+ * Standard API response wrapper
193
+ */
194
+ interface ApiResponse<T> {
195
+ data?: T;
196
+ error?: string;
197
+ message?: string;
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
+ }
208
+ /**
209
+ * Paginated response for list operations
210
+ */
211
+ interface PaginatedResponse<T> {
212
+ data: T[];
213
+ pagination: {
214
+ page: number;
215
+ limit: number;
216
+ total: number;
217
+ pages: number;
218
+ };
219
+ }
220
+ /**
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.)
225
+ */
226
+ declare class CoreMemoryClient {
227
+ private config;
228
+ private baseHeaders;
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;
235
+ /**
236
+ * Make an HTTP request to the API
237
+ */
238
+ private request;
239
+ /**
240
+ * Test the API connection and authentication
241
+ */
242
+ healthCheck(): Promise<ApiResponse<{
243
+ status: string;
244
+ timestamp: string;
245
+ }>>;
246
+ /**
247
+ * Create a new memory
248
+ */
249
+ createMemory(memory: CreateMemoryRequest): Promise<ApiResponse<MemoryEntry>>;
250
+ /**
251
+ * Get a memory by ID
252
+ */
253
+ getMemory(id: string): Promise<ApiResponse<MemoryEntry>>;
254
+ /**
255
+ * Update an existing memory
256
+ */
257
+ updateMemory(id: string, updates: UpdateMemoryRequest): Promise<ApiResponse<MemoryEntry>>;
258
+ /**
259
+ * Delete a memory
260
+ */
261
+ deleteMemory(id: string): Promise<ApiResponse<void>>;
262
+ /**
263
+ * List memories with optional filtering and pagination
264
+ */
265
+ listMemories(options?: {
266
+ page?: number;
267
+ limit?: number;
268
+ memory_type?: string;
269
+ topic_id?: string;
270
+ project_ref?: string;
271
+ status?: string;
272
+ tags?: string[];
273
+ sort?: string;
274
+ order?: 'asc' | 'desc';
275
+ }): Promise<ApiResponse<PaginatedResponse<MemoryEntry>>>;
276
+ /**
277
+ * Search memories using semantic search
278
+ */
279
+ searchMemories(request: SearchMemoryRequest): Promise<ApiResponse<{
280
+ results: MemorySearchResult[];
281
+ total_results: number;
282
+ search_time_ms: number;
283
+ }>>;
284
+ /**
285
+ * Bulk delete multiple memories
286
+ */
287
+ bulkDeleteMemories(memoryIds: string[]): Promise<ApiResponse<{
288
+ deleted_count: number;
289
+ failed_ids: string[];
290
+ }>>;
291
+ /**
292
+ * Create a new topic
293
+ */
294
+ createTopic(topic: CreateTopicRequest): Promise<ApiResponse<MemoryTopic>>;
295
+ /**
296
+ * Get all topics
297
+ */
298
+ getTopics(): Promise<ApiResponse<MemoryTopic[]>>;
299
+ /**
300
+ * Get a topic by ID
301
+ */
302
+ getTopic(id: string): Promise<ApiResponse<MemoryTopic>>;
303
+ /**
304
+ * Update a topic
305
+ */
306
+ updateTopic(id: string, updates: Partial<CreateTopicRequest>): Promise<ApiResponse<MemoryTopic>>;
307
+ /**
308
+ * Delete a topic
309
+ */
310
+ deleteTopic(id: string): Promise<ApiResponse<void>>;
311
+ /**
312
+ * Get user memory statistics
313
+ */
314
+ getMemoryStats(): Promise<ApiResponse<UserMemoryStats>>;
315
+ /**
316
+ * Update authentication token
317
+ */
318
+ setAuthToken(token: string): void;
319
+ /**
320
+ * Update API key
321
+ */
322
+ setApiKey(apiKey: string): void;
323
+ /**
324
+ * Clear authentication
325
+ */
326
+ clearAuth(): void;
327
+ /**
328
+ * Update configuration
329
+ */
330
+ updateConfig(updates: Partial<CoreMemoryClientConfig>): void;
331
+ /**
332
+ * Get current configuration (excluding sensitive data)
333
+ */
334
+ getConfig(): Omit<CoreMemoryClientConfig, 'apiKey' | 'authToken'>;
335
+ }
336
+ /**
337
+ * Factory function to create a new Core Memory Client instance
338
+ */
339
+ declare function createMemoryClient(config: CoreMemoryClientConfig): CoreMemoryClient;
340
+
341
+ /**
342
+ * Error handling for Memory Client
343
+ * Browser-safe, no Node.js dependencies
344
+ */
345
+ /**
346
+ * Base error class for Memory Client errors
347
+ */
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);
353
+ }
354
+ /**
355
+ * Network/API error
356
+ */
357
+ declare class ApiError extends MemoryClientError {
358
+ constructor(message: string, statusCode?: number, details?: unknown);
359
+ }
360
+ /**
361
+ * Authentication error
362
+ */
363
+ declare class AuthenticationError extends MemoryClientError {
364
+ constructor(message?: string);
365
+ }
366
+ /**
367
+ * Validation error
368
+ */
369
+ declare class ValidationError extends MemoryClientError {
370
+ constructor(message: string, details?: unknown);
371
+ }
372
+ /**
373
+ * Timeout error
374
+ */
375
+ declare class TimeoutError extends MemoryClientError {
376
+ constructor(message?: string);
377
+ }
378
+ /**
379
+ * Rate limit error
380
+ */
381
+ declare class RateLimitError extends MemoryClientError {
382
+ constructor(message?: string);
383
+ }
384
+ /**
385
+ * Not found error
386
+ */
387
+ declare class NotFoundError extends MemoryClientError {
388
+ constructor(resource: string);
389
+ }
390
+
391
+ /**
392
+ * @lanonasis/memory-client/core
393
+ *
394
+ * Pure browser-safe Memory Client
395
+ * NO Node.js dependencies, NO CLI code, NO child_process
396
+ * Works in: Browser, React Native, Cloudflare Workers, Edge Functions, Deno, Bun
397
+ *
398
+ * Bundle size: ~15KB gzipped
399
+ */
400
+
401
+ declare const VERSION = "2.0.0";
402
+ declare const CLIENT_NAME = "@lanonasis/memory-client";
403
+ declare const isBrowser: boolean;
404
+ declare const isNode: string | false;
405
+ declare const defaultConfigs: {
406
+ readonly development: {
407
+ readonly apiUrl: "http://localhost:3001";
408
+ readonly timeout: 30000;
409
+ };
410
+ readonly production: {
411
+ readonly apiUrl: "https://api.lanonasis.com";
412
+ readonly timeout: 15000;
413
+ };
414
+ readonly edge: {
415
+ readonly apiUrl: "https://api.lanonasis.com";
416
+ readonly timeout: 5000;
417
+ };
418
+ };
419
+
420
+ 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 };
421
+ export type { ApiError$1 as ApiError, ApiResponse, CoreMemoryClientConfig, CreateMemoryRequest, CreateTopicRequest, MemoryEntry, MemorySearchResult, MemoryStatus, MemoryTopic, MemoryType, PaginatedResponse, SearchMemoryRequest, UpdateMemoryRequest, UserMemoryStats };