@lanonasis/memory-client 1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Lanonasis Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,387 @@
1
+ # @lanonasis/memory-client
2
+
3
+ [![npm version](https://badge.fury.io/js/@lanonasis%2Fmemory-client.svg)](https://www.npmjs.com/package/@lanonasis/memory-client)
4
+ [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ **Memory as a Service (MaaS) Client SDK** - Intelligent memory management with semantic search capabilities for JavaScript/TypeScript applications.
8
+
9
+ ## 🚀 Features
10
+
11
+ - **🧠 Semantic Search** - Find memories by meaning, not just keywords
12
+ - **🏷️ Smart Tagging** - Organize memories with tags and topics
13
+ - **📊 Analytics** - Track memory usage and access patterns
14
+ - **🔐 Secure** - API key and token-based authentication
15
+ - **⚡ Performance** - Optimized with gateway routing and caching
16
+ - **📱 Universal** - Works in Node.js, browsers, and React applications
17
+ - **🎯 TypeScript** - Full type safety with comprehensive type definitions
18
+
19
+ ## 📦 Installation
20
+
21
+ ```bash
22
+ npm install @lanonasis/memory-client
23
+ ```
24
+
25
+ ```bash
26
+ yarn add @lanonasis/memory-client
27
+ ```
28
+
29
+ ```bash
30
+ pnpm add @lanonasis/memory-client
31
+ ```
32
+
33
+ ## 🏁 Quick Start
34
+
35
+ ### Basic Usage
36
+
37
+ ```typescript
38
+ import { createMemoryClient } from '@lanonasis/memory-client';
39
+
40
+ // Initialize the client
41
+ const memoryClient = createMemoryClient({
42
+ apiUrl: 'https://api.lanonasis.com',
43
+ apiKey: 'your-api-key-here'
44
+ });
45
+
46
+ // Create a memory
47
+ const memory = await memoryClient.createMemory({
48
+ title: 'Important Code Pattern',
49
+ content: 'Use React.memo() for expensive components to prevent unnecessary re-renders',
50
+ memory_type: 'knowledge',
51
+ tags: ['react', 'performance', 'optimization']
52
+ });
53
+
54
+ // Search memories
55
+ const results = await memoryClient.searchMemories({
56
+ query: 'React performance optimization',
57
+ limit: 10
58
+ });
59
+
60
+ console.log('Found memories:', results.data?.results);
61
+ ```
62
+
63
+ ### Production Setup
64
+
65
+ ```typescript
66
+ import { createProductionClient } from '@lanonasis/memory-client';
67
+
68
+ const client = createProductionClient(process.env.LANONASIS_API_KEY!);
69
+
70
+ // Test connection
71
+ const health = await client.healthCheck();
72
+ console.log('Service health:', health.data?.status);
73
+ ```
74
+
75
+ ### Development Setup
76
+
77
+ ```typescript
78
+ import { createDevelopmentClient } from '@lanonasis/memory-client';
79
+
80
+ const client = createDevelopmentClient('dev-api-key');
81
+ ```
82
+
83
+ ## 🛠️ API Reference
84
+
85
+ ### Client Configuration
86
+
87
+ ```typescript
88
+ interface MemoryClientConfig {
89
+ apiUrl: string; // API endpoint URL
90
+ apiKey?: string; // API key for authentication
91
+ authToken?: string; // Bearer token (alternative to API key)
92
+ timeout?: number; // Request timeout in milliseconds (default: 30000)
93
+ useGateway?: boolean; // Enable gateway mode (default: true)
94
+ headers?: Record<string, string>; // Custom headers
95
+ }
96
+ ```
97
+
98
+ ### Memory Operations
99
+
100
+ #### Create Memory
101
+
102
+ ```typescript
103
+ const memory = await client.createMemory({
104
+ title: 'Memory Title',
105
+ content: 'Memory content goes here...',
106
+ memory_type: 'context', // 'context' | 'project' | 'knowledge' | 'reference' | 'personal' | 'workflow'
107
+ tags: ['tag1', 'tag2'],
108
+ metadata: { source: 'api', version: '1.0' }
109
+ });
110
+ ```
111
+
112
+ #### Search Memories
113
+
114
+ ```typescript
115
+ const results = await client.searchMemories({
116
+ query: 'search terms',
117
+ memory_types: ['knowledge', 'reference'],
118
+ tags: ['important'],
119
+ limit: 20,
120
+ threshold: 0.7 // Similarity threshold (0-1)
121
+ });
122
+ ```
123
+
124
+ #### List Memories
125
+
126
+ ```typescript
127
+ const memories = await client.listMemories({
128
+ page: 1,
129
+ limit: 50,
130
+ memory_type: 'project',
131
+ tags: ['work', 'important'],
132
+ sort: 'updated_at',
133
+ order: 'desc'
134
+ });
135
+ ```
136
+
137
+ #### Update Memory
138
+
139
+ ```typescript
140
+ const updated = await client.updateMemory('memory-id', {
141
+ title: 'Updated Title',
142
+ tags: ['new-tag']
143
+ });
144
+ ```
145
+
146
+ #### Delete Memory
147
+
148
+ ```typescript
149
+ await client.deleteMemory('memory-id');
150
+ ```
151
+
152
+ ### Topic Operations
153
+
154
+ #### Create Topic
155
+
156
+ ```typescript
157
+ const topic = await client.createTopic({
158
+ name: 'Project Alpha',
159
+ description: 'Memories related to Project Alpha',
160
+ color: '#3B82F6',
161
+ icon: 'project'
162
+ });
163
+ ```
164
+
165
+ #### Get Topics
166
+
167
+ ```typescript
168
+ const topics = await client.getTopics();
169
+ ```
170
+
171
+ ### Statistics
172
+
173
+ ```typescript
174
+ const stats = await client.getMemoryStats();
175
+ console.log('Total memories:', stats.data?.total_memories);
176
+ console.log('By type:', stats.data?.memories_by_type);
177
+ ```
178
+
179
+ ## 🎯 Memory Types
180
+
181
+ - **`context`** - General contextual information
182
+ - **`project`** - Project-specific knowledge
183
+ - **`knowledge`** - Educational or reference material
184
+ - **`reference`** - Quick reference information
185
+ - **`personal`** - User-specific private memories
186
+ - **`workflow`** - Process and procedure documentation
187
+
188
+ ## 🔐 Authentication
189
+
190
+ ### API Key (Recommended)
191
+
192
+ ```typescript
193
+ const client = createMemoryClient({
194
+ apiUrl: 'https://api.lanonasis.com',
195
+ apiKey: 'your-api-key'
196
+ });
197
+ ```
198
+
199
+ ### Bearer Token
200
+
201
+ ```typescript
202
+ const client = createMemoryClient({
203
+ apiUrl: 'https://api.lanonasis.com',
204
+ authToken: 'your-bearer-token'
205
+ });
206
+ ```
207
+
208
+ ### Runtime Authentication Updates
209
+
210
+ ```typescript
211
+ // Update API key
212
+ client.setApiKey('new-api-key');
213
+
214
+ // Update auth token
215
+ client.setAuthToken('new-token');
216
+
217
+ // Clear authentication
218
+ client.clearAuth();
219
+ ```
220
+
221
+ ## ⚙️ Gateway Mode
222
+
223
+ Gateway mode provides enhanced performance through optimized routing and caching:
224
+
225
+ ```typescript
226
+ // Enable gateway mode (default)
227
+ const client = createMemoryClient({
228
+ apiUrl: 'https://api.lanonasis.com',
229
+ apiKey: 'your-key',
230
+ useGateway: true
231
+ });
232
+
233
+ // Direct API mode (for debugging)
234
+ const directClient = createMemoryClient({
235
+ apiUrl: 'https://api.lanonasis.com',
236
+ apiKey: 'your-key',
237
+ useGateway: false
238
+ });
239
+ ```
240
+
241
+ ## ⚛️ React Integration
242
+
243
+ ### Custom Hook
244
+
245
+ ```typescript
246
+ import { useMemoryClient } from '@lanonasis/memory-client';
247
+
248
+ function MyComponent() {
249
+ const client = useMemoryClient({
250
+ apiUrl: process.env.NEXT_PUBLIC_API_URL!,
251
+ apiKey: process.env.NEXT_PUBLIC_API_KEY!
252
+ });
253
+
254
+ const [memories, setMemories] = useState([]);
255
+
256
+ useEffect(() => {
257
+ const loadMemories = async () => {
258
+ const result = await client.listMemories({ limit: 10 });
259
+ if (result.data) {
260
+ setMemories(result.data.data);
261
+ }
262
+ };
263
+ loadMemories();
264
+ }, [client]);
265
+
266
+ return <div>{/* Your component */}</div>;
267
+ }
268
+ ```
269
+
270
+ ## 🚨 Error Handling
271
+
272
+ All methods return a standardized response format:
273
+
274
+ ```typescript
275
+ interface ApiResponse<T> {
276
+ data?: T; // Success data
277
+ error?: string; // Error message
278
+ message?: string; // Additional info
279
+ }
280
+
281
+ // Example error handling
282
+ const result = await client.getMemory('invalid-id');
283
+ if (result.error) {
284
+ console.error('Failed to get memory:', result.error);
285
+ } else {
286
+ console.log('Memory:', result.data);
287
+ }
288
+ ```
289
+
290
+ ## 🔧 Configuration Examples
291
+
292
+ ### Environment-specific Configs
293
+
294
+ ```typescript
295
+ // Production
296
+ const prodClient = createMemoryClient({
297
+ apiUrl: 'https://api.lanonasis.com',
298
+ apiKey: process.env.LANONASIS_API_KEY,
299
+ timeout: 10000,
300
+ useGateway: true
301
+ });
302
+
303
+ // Development
304
+ const devClient = createMemoryClient({
305
+ apiUrl: 'http://localhost:3001',
306
+ apiKey: 'dev-key',
307
+ timeout: 30000,
308
+ useGateway: false
309
+ });
310
+
311
+ // Custom headers
312
+ const customClient = createMemoryClient({
313
+ apiUrl: 'https://api.lanonasis.com',
314
+ apiKey: 'your-key',
315
+ headers: {
316
+ 'X-Client-Version': '1.0.0',
317
+ 'X-Environment': 'production'
318
+ }
319
+ });
320
+ ```
321
+
322
+ ## 📋 TypeScript Support
323
+
324
+ Full TypeScript support with comprehensive type definitions:
325
+
326
+ ```typescript
327
+ import type {
328
+ MemoryEntry,
329
+ CreateMemoryRequest,
330
+ SearchMemoryRequest,
331
+ MemoryType,
332
+ ApiResponse
333
+ } from '@lanonasis/memory-client';
334
+
335
+ // Strongly typed memory creation
336
+ const memory: CreateMemoryRequest = {
337
+ title: 'TypeScript Tips',
338
+ content: 'Use strict mode for better type safety',
339
+ memory_type: 'knowledge' as MemoryType,
340
+ tags: ['typescript', 'tips']
341
+ };
342
+
343
+ // Typed responses
344
+ const response: ApiResponse<MemoryEntry> = await client.createMemory(memory);
345
+ ```
346
+
347
+ ## 🌍 Browser Support
348
+
349
+ - ✅ Chrome 88+
350
+ - ✅ Firefox 85+
351
+ - ✅ Safari 14+
352
+ - ✅ Edge 88+
353
+ - ✅ Node.js 16+
354
+
355
+ ## 📚 Examples
356
+
357
+ Check out the [examples directory](./examples) for complete implementation examples:
358
+
359
+ - [Basic Usage](./examples/basic.js)
360
+ - [React Integration](./examples/react-app.tsx)
361
+ - [Node.js Server](./examples/server.js)
362
+ - [Search Implementation](./examples/search.js)
363
+
364
+ ## 📖 Documentation
365
+
366
+ - [API Reference](https://docs.lanonasis.com/sdk/api)
367
+ - [Getting Started Guide](https://docs.lanonasis.com/sdk/quickstart)
368
+ - [Migration Guide](https://docs.lanonasis.com/sdk/migration)
369
+
370
+ ## 🤝 Contributing
371
+
372
+ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
373
+
374
+ ## 📄 License
375
+
376
+ MIT © [Lanonasis Team](https://lanonasis.com)
377
+
378
+ ## 🆘 Support
379
+
380
+ - **Documentation**: [docs.lanonasis.com](https://docs.lanonasis.com)
381
+ - **Issues**: [GitHub Issues](https://github.com/lanonasis/memory-client/issues)
382
+ - **Discussions**: [GitHub Discussions](https://github.com/lanonasis/memory-client/discussions)
383
+ - **Email**: support@lanonasis.com
384
+
385
+ ---
386
+
387
+ **Made with ❤️ by the Lanonasis Team**