@lanonasis/mem-intel-sdk 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.
Files changed (48) hide show
  1. package/CHANGELOG.md +230 -15
  2. package/README.md +258 -4
  3. package/dist/core/client.d.ts +79 -7
  4. package/dist/core/client.d.ts.map +1 -1
  5. package/dist/core/index.cjs +360 -13
  6. package/dist/core/index.cjs.map +1 -1
  7. package/dist/core/index.d.ts +2 -0
  8. package/dist/core/index.d.ts.map +1 -1
  9. package/dist/core/index.js +359 -14
  10. package/dist/core/index.js.map +1 -1
  11. package/dist/core/prediction-types.d.ts +270 -0
  12. package/dist/core/prediction-types.d.ts.map +1 -0
  13. package/dist/core/types.d.ts +94 -38
  14. package/dist/core/types.d.ts.map +1 -1
  15. package/dist/index-sdk.d.ts +2 -0
  16. package/dist/index-sdk.d.ts.map +1 -1
  17. package/dist/index.cjs +320 -13
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.js +320 -13
  20. package/dist/index.js.map +1 -1
  21. package/dist/node/index.cjs +320 -13
  22. package/dist/node/index.cjs.map +1 -1
  23. package/dist/node/index.js +320 -13
  24. package/dist/node/index.js.map +1 -1
  25. package/dist/react/hooks/useMemoryIntelligence.d.ts +94 -10
  26. package/dist/react/hooks/useMemoryIntelligence.d.ts.map +1 -1
  27. package/dist/react/index.cjs +320 -13
  28. package/dist/react/index.cjs.map +1 -1
  29. package/dist/react/index.js +320 -13
  30. package/dist/react/index.js.map +1 -1
  31. package/dist/server/index.cjs +571 -47
  32. package/dist/server/index.cjs.map +1 -1
  33. package/dist/server/index.js +571 -47
  34. package/dist/server/index.js.map +1 -1
  35. package/dist/server/mcp-server.d.ts.map +1 -1
  36. package/dist/utils/http-client.d.ts +35 -0
  37. package/dist/utils/http-client.d.ts.map +1 -1
  38. package/dist/utils/index.d.ts +3 -1
  39. package/dist/utils/index.d.ts.map +1 -1
  40. package/dist/utils/prediction-engine.d.ts +90 -0
  41. package/dist/utils/prediction-engine.d.ts.map +1 -0
  42. package/dist/utils/response-adapter.d.ts +66 -0
  43. package/dist/utils/response-adapter.d.ts.map +1 -0
  44. package/dist/vue/composables/useMemoryIntelligence.d.ts +59 -0
  45. package/dist/vue/composables/useMemoryIntelligence.d.ts.map +1 -1
  46. package/dist/vue/index.cjs.map +1 -1
  47. package/dist/vue/index.js.map +1 -1
  48. package/package.json +11 -5
@@ -42,12 +42,120 @@ var ValidationError = class extends MemoryIntelligenceError {
42
42
  }
43
43
  };
44
44
 
45
+ // src/utils/response-adapter.ts
46
+ function adaptEdgeFunctionResponse(httpResponse) {
47
+ if (httpResponse.error) {
48
+ return {
49
+ status: httpResponse.status,
50
+ error: httpResponse.error
51
+ };
52
+ }
53
+ const envelope = httpResponse.data;
54
+ if (!envelope) {
55
+ return {
56
+ status: httpResponse.status,
57
+ error: {
58
+ message: "Empty response from server",
59
+ code: "EMPTY_RESPONSE"
60
+ }
61
+ };
62
+ }
63
+ if (!envelope.success && envelope.error) {
64
+ return {
65
+ status: httpResponse.status,
66
+ error: envelope.error,
67
+ usage: envelope.usage,
68
+ tier_info: envelope.tier_info
69
+ };
70
+ }
71
+ return {
72
+ status: httpResponse.status,
73
+ data: envelope.data,
74
+ usage: envelope.usage,
75
+ tier_info: envelope.tier_info
76
+ };
77
+ }
78
+ function isEdgeFunctionEnvelope(data) {
79
+ if (typeof data !== "object" || data === null) {
80
+ return false;
81
+ }
82
+ const obj = data;
83
+ return "success" in obj && typeof obj.success === "boolean";
84
+ }
85
+ function adaptResponse(httpResponse) {
86
+ if (httpResponse.error) {
87
+ return {
88
+ status: httpResponse.status,
89
+ error: httpResponse.error
90
+ };
91
+ }
92
+ const responseData = httpResponse.data;
93
+ if (isEdgeFunctionEnvelope(responseData)) {
94
+ return adaptEdgeFunctionResponse({
95
+ status: httpResponse.status,
96
+ data: responseData
97
+ });
98
+ }
99
+ return {
100
+ status: httpResponse.status,
101
+ data: responseData
102
+ };
103
+ }
104
+ var ResponseCache = class {
105
+ cache = /* @__PURE__ */ new Map();
106
+ ttl;
107
+ constructor(ttlMs = 3e5) {
108
+ this.ttl = ttlMs;
109
+ }
110
+ generateKey(endpoint, params) {
111
+ const paramStr = params ? JSON.stringify(params) : "";
112
+ return `${endpoint}:${paramStr}`;
113
+ }
114
+ set(endpoint, data, params) {
115
+ const key = this.generateKey(endpoint, params);
116
+ this.cache.set(key, {
117
+ data,
118
+ timestamp: Date.now(),
119
+ endpoint,
120
+ params
121
+ });
122
+ }
123
+ get(endpoint, params) {
124
+ const key = this.generateKey(endpoint, params);
125
+ const entry = this.cache.get(key);
126
+ if (!entry) {
127
+ return null;
128
+ }
129
+ if (Date.now() - entry.timestamp > this.ttl) {
130
+ this.cache.delete(key);
131
+ return null;
132
+ }
133
+ return entry.data;
134
+ }
135
+ clear() {
136
+ this.cache.clear();
137
+ }
138
+ /**
139
+ * Clean up expired entries
140
+ */
141
+ cleanup() {
142
+ const now = Date.now();
143
+ for (const [key, entry] of this.cache.entries()) {
144
+ if (now - entry.timestamp > this.ttl) {
145
+ this.cache.delete(key);
146
+ }
147
+ }
148
+ }
149
+ };
150
+
45
151
  // src/utils/http-client.ts
46
152
  var HttpClient = class {
47
153
  apiUrl;
48
154
  apiKey;
49
155
  timeout;
50
156
  headers;
157
+ processingMode;
158
+ cache;
51
159
  constructor(config) {
52
160
  if (!config.apiKey) {
53
161
  throw new ConfigurationError("API key is required");
@@ -60,11 +168,35 @@ var HttpClient = class {
60
168
  this.apiUrl = config.apiUrl.replace(/\/$/, "");
61
169
  this.apiKey = config.apiKey;
62
170
  this.timeout = config.timeout || 3e4;
171
+ this.processingMode = config.processingMode || "api";
63
172
  this.headers = {
64
173
  "Content-Type": "application/json",
65
174
  "X-API-Key": this.apiKey,
66
175
  ...config.headers
67
176
  };
177
+ if (config.enableCache !== false && this.processingMode === "offline-fallback") {
178
+ this.cache = new ResponseCache(config.cacheTTL || 3e5);
179
+ } else {
180
+ this.cache = null;
181
+ }
182
+ }
183
+ /**
184
+ * Get the current processing mode
185
+ */
186
+ getProcessingMode() {
187
+ return this.processingMode;
188
+ }
189
+ /**
190
+ * Check if cache is enabled
191
+ */
192
+ isCacheEnabled() {
193
+ return this.cache !== null;
194
+ }
195
+ /**
196
+ * Clear the response cache
197
+ */
198
+ clearCache() {
199
+ this.cache?.clear();
68
200
  }
69
201
  async request(method, endpoint, data) {
70
202
  const url = `${this.apiUrl}${endpoint}`;
@@ -124,6 +256,43 @@ var HttpClient = class {
124
256
  };
125
257
  }
126
258
  }
259
+ /**
260
+ * Enhanced request that handles Edge Function envelope format
261
+ * and supports offline-fallback caching
262
+ */
263
+ async enhancedRequest(method, endpoint, data) {
264
+ const cacheKey = data ? JSON.stringify(data) : void 0;
265
+ const rawResponse = await this.request(method, endpoint, data);
266
+ if (rawResponse.error?.code === "NETWORK_ERROR" || rawResponse.error?.code === "TIMEOUT") {
267
+ if (this.processingMode === "offline-fallback" && this.cache) {
268
+ const cached = this.cache.get(endpoint, cacheKey ? JSON.parse(cacheKey) : void 0);
269
+ if (cached) {
270
+ return {
271
+ status: 200,
272
+ data: cached,
273
+ fromCache: true
274
+ };
275
+ }
276
+ }
277
+ return {
278
+ status: rawResponse.status,
279
+ error: rawResponse.error,
280
+ fromCache: false
281
+ };
282
+ }
283
+ const adapted = adaptResponse(rawResponse);
284
+ if (!adapted.error && adapted.data && this.cache) {
285
+ this.cache.set(endpoint, adapted.data, cacheKey ? JSON.parse(cacheKey) : void 0);
286
+ }
287
+ return {
288
+ status: adapted.status,
289
+ data: adapted.data,
290
+ error: adapted.error,
291
+ usage: adapted.usage,
292
+ tier_info: adapted.tier_info,
293
+ fromCache: false
294
+ };
295
+ }
127
296
  async get(endpoint) {
128
297
  return this.request("GET", endpoint);
129
298
  }
@@ -139,6 +308,22 @@ var HttpClient = class {
139
308
  async delete(endpoint) {
140
309
  return this.request("DELETE", endpoint);
141
310
  }
311
+ // Enhanced methods with Edge Function envelope support
312
+ async getEnhanced(endpoint) {
313
+ return this.enhancedRequest("GET", endpoint);
314
+ }
315
+ async postEnhanced(endpoint, data) {
316
+ return this.enhancedRequest("POST", endpoint, data);
317
+ }
318
+ async putEnhanced(endpoint, data) {
319
+ return this.enhancedRequest("PUT", endpoint, data);
320
+ }
321
+ async patchEnhanced(endpoint, data) {
322
+ return this.enhancedRequest("PATCH", endpoint, data);
323
+ }
324
+ async deleteEnhanced(endpoint) {
325
+ return this.enhancedRequest("DELETE", endpoint);
326
+ }
142
327
  };
143
328
 
144
329
  // src/core/client.ts
@@ -146,20 +331,43 @@ var DEFAULT_API_URL = "https://api.lanonasis.com/api/v1";
146
331
  var MemoryIntelligenceClient = class {
147
332
  httpClient;
148
333
  defaultResponseFormat;
334
+ processingMode;
149
335
  constructor(config) {
150
336
  if (!config.apiKey) {
151
337
  throw new ConfigurationError(
152
338
  "Missing required configuration: apiKey is required (format: lano_xxxxxxxxxx)"
153
339
  );
154
340
  }
341
+ this.processingMode = config.processingMode || "api";
155
342
  this.httpClient = new HttpClient({
156
343
  apiUrl: config.apiUrl || DEFAULT_API_URL,
157
344
  apiKey: config.apiKey,
158
345
  timeout: config.timeout,
159
- headers: config.headers
346
+ headers: config.headers,
347
+ processingMode: this.processingMode,
348
+ enableCache: config.enableCache,
349
+ cacheTTL: config.cacheTTL
160
350
  });
161
351
  this.defaultResponseFormat = config.responseFormat || "markdown";
162
352
  }
353
+ /**
354
+ * Get the current processing mode
355
+ */
356
+ getProcessingMode() {
357
+ return this.processingMode;
358
+ }
359
+ /**
360
+ * Check if cache is enabled (for offline-fallback mode)
361
+ */
362
+ isCacheEnabled() {
363
+ return this.httpClient.isCacheEnabled();
364
+ }
365
+ /**
366
+ * Clear the response cache
367
+ */
368
+ clearCache() {
369
+ this.httpClient.clearCache();
370
+ }
163
371
  /**
164
372
  * Get HTTP client for direct API access
165
373
  */
@@ -191,7 +399,7 @@ var MemoryIntelligenceClient = class {
191
399
  * Analyze usage patterns and trends in memory collection
192
400
  */
193
401
  async analyzePatterns(params) {
194
- const response = await this.httpClient.post(
402
+ const response = await this.httpClient.postEnhanced(
195
403
  "/intelligence/analyze-patterns",
196
404
  {
197
405
  ...params,
@@ -201,13 +409,18 @@ var MemoryIntelligenceClient = class {
201
409
  if (response.error) {
202
410
  throw new DatabaseError(`Failed to analyze patterns: ${response.error.message}`);
203
411
  }
204
- return response.data;
412
+ return {
413
+ data: response.data,
414
+ usage: response.usage,
415
+ tier_info: response.tier_info,
416
+ fromCache: response.fromCache
417
+ };
205
418
  }
206
419
  /**
207
420
  * Get AI-powered tag suggestions for a memory
208
421
  */
209
422
  async suggestTags(params) {
210
- const response = await this.httpClient.post(
423
+ const response = await this.httpClient.postEnhanced(
211
424
  "/intelligence/suggest-tags",
212
425
  {
213
426
  ...params,
@@ -217,13 +430,18 @@ var MemoryIntelligenceClient = class {
217
430
  if (response.error) {
218
431
  throw new DatabaseError(`Failed to suggest tags: ${response.error.message}`);
219
432
  }
220
- return response.data;
433
+ return {
434
+ data: response.data,
435
+ usage: response.usage,
436
+ tier_info: response.tier_info,
437
+ fromCache: response.fromCache
438
+ };
221
439
  }
222
440
  /**
223
441
  * Find semantically related memories using vector similarity
224
442
  */
225
443
  async findRelated(params) {
226
- const response = await this.httpClient.post(
444
+ const response = await this.httpClient.postEnhanced(
227
445
  "/intelligence/find-related",
228
446
  {
229
447
  ...params,
@@ -233,13 +451,18 @@ var MemoryIntelligenceClient = class {
233
451
  if (response.error) {
234
452
  throw new DatabaseError(`Failed to find related memories: ${response.error.message}`);
235
453
  }
236
- return response.data;
454
+ return {
455
+ data: response.data,
456
+ usage: response.usage,
457
+ tier_info: response.tier_info,
458
+ fromCache: response.fromCache
459
+ };
237
460
  }
238
461
  /**
239
462
  * Detect potential duplicate memories
240
463
  */
241
464
  async detectDuplicates(params) {
242
- const response = await this.httpClient.post(
465
+ const response = await this.httpClient.postEnhanced(
243
466
  "/intelligence/detect-duplicates",
244
467
  {
245
468
  ...params,
@@ -249,13 +472,18 @@ var MemoryIntelligenceClient = class {
249
472
  if (response.error) {
250
473
  throw new DatabaseError(`Failed to detect duplicates: ${response.error.message}`);
251
474
  }
252
- return response.data;
475
+ return {
476
+ data: response.data,
477
+ usage: response.usage,
478
+ tier_info: response.tier_info,
479
+ fromCache: response.fromCache
480
+ };
253
481
  }
254
482
  /**
255
483
  * Extract insights and patterns from memories
256
484
  */
257
485
  async extractInsights(params) {
258
- const response = await this.httpClient.post(
486
+ const response = await this.httpClient.postEnhanced(
259
487
  "/intelligence/extract-insights",
260
488
  {
261
489
  ...params,
@@ -265,13 +493,18 @@ var MemoryIntelligenceClient = class {
265
493
  if (response.error) {
266
494
  throw new DatabaseError(`Failed to extract insights: ${response.error.message}`);
267
495
  }
268
- return response.data;
496
+ return {
497
+ data: response.data,
498
+ usage: response.usage,
499
+ tier_info: response.tier_info,
500
+ fromCache: response.fromCache
501
+ };
269
502
  }
270
503
  /**
271
504
  * Check the health and organization quality of memories
272
505
  */
273
506
  async healthCheck(params) {
274
- const response = await this.httpClient.post(
507
+ const response = await this.httpClient.postEnhanced(
275
508
  "/intelligence/health-check",
276
509
  {
277
510
  ...params,
@@ -281,7 +514,81 @@ var MemoryIntelligenceClient = class {
281
514
  if (response.error) {
282
515
  throw new DatabaseError(`Failed to check health: ${response.error.message}`);
283
516
  }
284
- return response.data;
517
+ return {
518
+ data: response.data,
519
+ usage: response.usage,
520
+ tier_info: response.tier_info,
521
+ fromCache: response.fromCache
522
+ };
523
+ }
524
+ /**
525
+ * Predictive Memory Recall - AI that anticipates what you need
526
+ *
527
+ * Uses a weighted scoring algorithm:
528
+ * - Semantic similarity to current context (40%)
529
+ * - Temporal relevance (recency decay curve) (30%)
530
+ * - Usage frequency (20%)
531
+ * - Serendipity factor (adjacent discoveries) (10%)
532
+ *
533
+ * @example
534
+ * ```typescript
535
+ * const result = await client.predictiveRecall({
536
+ * userId: "user-123",
537
+ * context: {
538
+ * currentProject: "Building dashboard components",
539
+ * recentTopics: ["React", "performance", "hooks"],
540
+ * contextText: "Optimizing render performance for data tables"
541
+ * },
542
+ * limit: 5,
543
+ * minConfidence: 50
544
+ * });
545
+ *
546
+ * for (const prediction of result.data.predictions) {
547
+ * console.log(`[${prediction.confidence}%] ${prediction.title}`);
548
+ * console.log(` Reason: ${prediction.reason}`);
549
+ * console.log(` Action: ${prediction.suggestedAction}`);
550
+ * }
551
+ * ```
552
+ */
553
+ async predictiveRecall(params) {
554
+ const response = await this.httpClient.postEnhanced(
555
+ "/intelligence/predictive-recall",
556
+ {
557
+ userId: params.userId,
558
+ context: params.context,
559
+ limit: params.limit || 5,
560
+ minConfidence: params.minConfidence || 40,
561
+ includeSerendipity: params.includeSerendipity !== false,
562
+ memoryTypes: params.memoryTypes,
563
+ timeWindowDays: params.timeWindowDays || 90,
564
+ responseFormat: params.responseFormat || this.defaultResponseFormat
565
+ }
566
+ );
567
+ if (response.error) {
568
+ throw new DatabaseError(`Failed to get predictions: ${response.error.message}`);
569
+ }
570
+ return {
571
+ data: response.data,
572
+ usage: response.usage,
573
+ tier_info: response.tier_info,
574
+ fromCache: response.fromCache
575
+ };
576
+ }
577
+ /**
578
+ * Record feedback on a prediction (for improving accuracy over time)
579
+ *
580
+ * @example
581
+ * ```typescript
582
+ * await client.recordPredictionFeedback({
583
+ * memoryId: "mem-123",
584
+ * userId: "user-123",
585
+ * useful: true,
586
+ * action: "clicked"
587
+ * });
588
+ * ```
589
+ */
590
+ async recordPredictionFeedback(params) {
591
+ await this.httpClient.post("/intelligence/prediction-feedback", params);
285
592
  }
286
593
  };
287
594
  var ResponseFormat = {
@@ -296,14 +603,54 @@ var MemoryType = zod.z.enum([
296
603
  "personal",
297
604
  "workflow"
298
605
  ]);
606
+ var PredictiveRecallParamsSchema = zod.z.object({
607
+ userId: zod.z.string().uuid(),
608
+ context: zod.z.object({
609
+ currentProject: zod.z.string().optional(),
610
+ recentTopics: zod.z.array(zod.z.string()).optional(),
611
+ activeFiles: zod.z.array(zod.z.string()).optional(),
612
+ contextText: zod.z.string().optional(),
613
+ teamContext: zod.z.string().optional()
614
+ }),
615
+ limit: zod.z.number().int().min(1).max(20).default(5),
616
+ minConfidence: zod.z.number().min(0).max(100).default(40),
617
+ includeSerendipity: zod.z.boolean().default(true),
618
+ memoryTypes: zod.z.array(zod.z.enum([
619
+ "context",
620
+ "project",
621
+ "knowledge",
622
+ "reference",
623
+ "personal",
624
+ "workflow"
625
+ ])).optional(),
626
+ timeWindowDays: zod.z.number().int().min(1).max(365).default(90),
627
+ responseFormat: zod.z.enum(["json", "markdown"]).default("markdown")
628
+ });
629
+ var DEFAULT_SCORING_CONFIG = {
630
+ semanticWeight: 0.4,
631
+ temporalWeight: 0.3,
632
+ frequencyWeight: 0.2,
633
+ serendipityWeight: 0.1,
634
+ temporalDecayHalfLife: 14,
635
+ // 2 weeks
636
+ semanticThreshold: 0.5,
637
+ serendipityRange: {
638
+ min: 0.3,
639
+ // Not too similar
640
+ max: 0.6
641
+ // Not too different
642
+ }
643
+ };
299
644
 
300
645
  exports.ConfigurationError = ConfigurationError;
646
+ exports.DEFAULT_SCORING_CONFIG = DEFAULT_SCORING_CONFIG;
301
647
  exports.DatabaseError = DatabaseError;
302
648
  exports.EmbeddingError = EmbeddingError;
303
649
  exports.MemoryIntelligenceClient = MemoryIntelligenceClient;
304
650
  exports.MemoryIntelligenceError = MemoryIntelligenceError;
305
651
  exports.MemoryNotFoundError = MemoryNotFoundError;
306
652
  exports.MemoryType = MemoryType;
653
+ exports.PredictiveRecallParamsSchema = PredictiveRecallParamsSchema;
307
654
  exports.ResponseFormat = ResponseFormat;
308
655
  exports.ValidationError = ValidationError;
309
656
  //# sourceMappingURL=index.cjs.map