@lanonasis/mem-intel-sdk 1.1.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.
Files changed (40) hide show
  1. package/CHANGELOG.md +230 -15
  2. package/README.md +258 -4
  3. package/dist/core/client.d.ts +51 -0
  4. package/dist/core/client.d.ts.map +1 -1
  5. package/dist/core/index.cjs +109 -0
  6. package/dist/core/index.cjs.map +1 -1
  7. package/dist/core/index.d.ts +1 -0
  8. package/dist/core/index.d.ts.map +1 -1
  9. package/dist/core/index.js +108 -1
  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 +58 -38
  14. package/dist/core/types.d.ts.map +1 -1
  15. package/dist/index.cjs +69 -0
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.js +69 -0
  18. package/dist/index.js.map +1 -1
  19. package/dist/node/index.cjs +69 -0
  20. package/dist/node/index.cjs.map +1 -1
  21. package/dist/node/index.js +69 -0
  22. package/dist/node/index.js.map +1 -1
  23. package/dist/react/hooks/useMemoryIntelligence.d.ts +83 -0
  24. package/dist/react/hooks/useMemoryIntelligence.d.ts.map +1 -1
  25. package/dist/react/index.cjs +69 -0
  26. package/dist/react/index.cjs.map +1 -1
  27. package/dist/react/index.js +69 -0
  28. package/dist/react/index.js.map +1 -1
  29. package/dist/server/index.cjs +306 -27
  30. package/dist/server/index.cjs.map +1 -1
  31. package/dist/server/index.js +306 -27
  32. package/dist/server/index.js.map +1 -1
  33. package/dist/server/mcp-server.d.ts.map +1 -1
  34. package/dist/utils/prediction-engine.d.ts +90 -0
  35. package/dist/utils/prediction-engine.d.ts.map +1 -0
  36. package/dist/vue/composables/useMemoryIntelligence.d.ts +59 -0
  37. package/dist/vue/composables/useMemoryIntelligence.d.ts.map +1 -1
  38. package/dist/vue/index.cjs.map +1 -1
  39. package/dist/vue/index.js.map +1 -1
  40. package/package.json +9 -3
@@ -522,6 +522,75 @@ var MemoryIntelligenceClient = class {
522
522
  fromCache: response.fromCache
523
523
  };
524
524
  }
525
+ /**
526
+ * Predictive Memory Recall - AI that anticipates what you need
527
+ *
528
+ * Uses a weighted scoring algorithm:
529
+ * - Semantic similarity to current context (40%)
530
+ * - Temporal relevance (recency decay curve) (30%)
531
+ * - Usage frequency (20%)
532
+ * - Serendipity factor (adjacent discoveries) (10%)
533
+ *
534
+ * @example
535
+ * ```typescript
536
+ * const result = await client.predictiveRecall({
537
+ * userId: "user-123",
538
+ * context: {
539
+ * currentProject: "Building dashboard components",
540
+ * recentTopics: ["React", "performance", "hooks"],
541
+ * contextText: "Optimizing render performance for data tables"
542
+ * },
543
+ * limit: 5,
544
+ * minConfidence: 50
545
+ * });
546
+ *
547
+ * for (const prediction of result.data.predictions) {
548
+ * console.log(`[${prediction.confidence}%] ${prediction.title}`);
549
+ * console.log(` Reason: ${prediction.reason}`);
550
+ * console.log(` Action: ${prediction.suggestedAction}`);
551
+ * }
552
+ * ```
553
+ */
554
+ async predictiveRecall(params) {
555
+ const response = await this.httpClient.postEnhanced(
556
+ "/intelligence/predictive-recall",
557
+ {
558
+ userId: params.userId,
559
+ context: params.context,
560
+ limit: params.limit || 5,
561
+ minConfidence: params.minConfidence || 40,
562
+ includeSerendipity: params.includeSerendipity !== false,
563
+ memoryTypes: params.memoryTypes,
564
+ timeWindowDays: params.timeWindowDays || 90,
565
+ responseFormat: params.responseFormat || this.defaultResponseFormat
566
+ }
567
+ );
568
+ if (response.error) {
569
+ throw new DatabaseError(`Failed to get predictions: ${response.error.message}`);
570
+ }
571
+ return {
572
+ data: response.data,
573
+ usage: response.usage,
574
+ tier_info: response.tier_info,
575
+ fromCache: response.fromCache
576
+ };
577
+ }
578
+ /**
579
+ * Record feedback on a prediction (for improving accuracy over time)
580
+ *
581
+ * @example
582
+ * ```typescript
583
+ * await client.recordPredictionFeedback({
584
+ * memoryId: "mem-123",
585
+ * userId: "user-123",
586
+ * useful: true,
587
+ * action: "clicked"
588
+ * });
589
+ * ```
590
+ */
591
+ async recordPredictionFeedback(params) {
592
+ await this.httpClient.post("/intelligence/prediction-feedback", params);
593
+ }
525
594
  };
526
595
  var ResponseFormat = {
527
596
  JSON: "json",
@@ -826,22 +895,27 @@ function createMCPServer(config) {
826
895
  let md = `# Duplicate Detection
827
896
 
828
897
  `;
829
- md += `**Memories Analyzed:** ${data.total_memories_analyzed}
898
+ md += `**Memories Analyzed:** ${data.memories_analyzed}
899
+ `;
900
+ md += `**Duplicate Groups Found:** ${data.total_groups}
830
901
  `;
831
- md += `**Duplicate Pairs Found:** ${data.duplicate_pairs_found}
902
+ md += `**Total Duplicates:** ${data.total_duplicates}
832
903
  `;
833
- md += `**Storage Savings:** ${data.estimated_storage_savings}
904
+ md += `**Storage Savings:** ${data.potential_storage_savings}
834
905
 
835
906
  `;
836
- for (const pair of data.duplicate_pairs) {
837
- md += `### Similarity: ${(pair.similarity_score * 100).toFixed(1)}%
907
+ for (const group of data.duplicate_groups) {
908
+ md += `### ${group.primary_title}
838
909
  `;
839
- md += `**Memory 1:** ${pair.memory_1.title}
910
+ md += `**Similarity Score:** ${(group.similarity_score * 100).toFixed(1)}%
840
911
  `;
841
- md += `**Memory 2:** ${pair.memory_2.title}
912
+ md += `**Duplicates:**
842
913
  `;
843
- md += `**Recommendation:** ${pair.recommendation}
844
-
914
+ for (const dup of group.duplicates) {
915
+ md += `- ${dup.title} (${(dup.similarity * 100).toFixed(1)}% similar)
916
+ `;
917
+ }
918
+ md += `
845
919
  `;
846
920
  }
847
921
  return md;
@@ -900,7 +974,7 @@ function createMCPServer(config) {
900
974
  let md = `# Memory Insights
901
975
 
902
976
  `;
903
- md += `**Memories Analyzed:** ${data.total_memories_analyzed}
977
+ md += `**Memories Analyzed:** ${data.memories_analyzed}
904
978
  `;
905
979
  if (data.topic_filter) {
906
980
  md += `**Topic:** ${data.topic_filter}
@@ -908,24 +982,24 @@ function createMCPServer(config) {
908
982
  }
909
983
  md += `
910
984
  ## Summary
911
- ${data.summary}
985
+ ${data.overall_summary}
912
986
 
913
987
  `;
914
988
  md += `## Insights
915
989
  `;
916
- const categoryIcons = {
917
- pattern: "\u{1F504}",
918
- learning: "\u{1F4A1}",
919
- opportunity: "\u{1F680}",
920
- risk: "\u26A0\uFE0F",
921
- action_item: "\u2705"
990
+ const typeIcons = {
991
+ themes: "\u{1F3AF}",
992
+ connections: "\u{1F517}",
993
+ gaps: "\u26A0\uFE0F",
994
+ actions: "\u2705",
995
+ summary: "\u{1F4CB}"
922
996
  };
923
997
  for (const insight of data.insights) {
924
- const icon = categoryIcons[insight.category] || "\u{1F4CC}";
998
+ const icon = typeIcons[insight.type] || "\u{1F4CC}";
925
999
  md += `
926
- ### ${icon} ${insight.title}
1000
+ ### ${icon} ${insight.type.charAt(0).toUpperCase() + insight.type.slice(1)}
927
1001
  `;
928
- md += `${insight.description}
1002
+ md += `${insight.content}
929
1003
  `;
930
1004
  md += `**Confidence:** ${(insight.confidence * 100).toFixed(0)}%
931
1005
  `;
@@ -980,25 +1054,43 @@ ${data.summary}
980
1054
  let md = `# Memory Health Check
981
1055
 
982
1056
  `;
983
- md += `**Health Score:** ${data.health_score}/100
1057
+ md += `**Health Score:** ${data.health_score.overall}/100
1058
+ `;
1059
+ md += `**Status:** ${data.status}
1060
+
1061
+ `;
1062
+ md += `## Score Breakdown
1063
+ `;
1064
+ md += `- **Organization:** ${data.health_score.breakdown.organization}
1065
+ `;
1066
+ md += `- **Tagging:** ${data.health_score.breakdown.tagging}
1067
+ `;
1068
+ md += `- **Recency:** ${data.health_score.breakdown.recency}
1069
+ `;
1070
+ md += `- **Completeness:** ${data.health_score.breakdown.completeness}
1071
+ `;
1072
+ md += `- **Diversity:** ${data.health_score.breakdown.diversity}
984
1073
 
985
1074
  `;
986
- md += `## Metrics
1075
+ md += `## Statistics
987
1076
  `;
988
- md += `- **Total Memories:** ${data.metrics.total_memories}
1077
+ md += `- **Total Memories:** ${data.statistics.total_memories}
989
1078
  `;
990
- md += `- **Embedding Coverage:** ${data.metrics.embedding_coverage_percentage}%
1079
+ md += `- **Active Memories:** ${data.statistics.active_memories}
991
1080
  `;
992
- md += `- **Tagging Rate:** ${data.metrics.tagging_percentage}%
1081
+ md += `- **Memories with Tags:** ${data.statistics.memories_with_tags}
993
1082
  `;
994
- md += `- **Avg Tags/Memory:** ${data.metrics.average_tags_per_memory}
1083
+ md += `- **Unique Tags:** ${data.statistics.unique_tags}
1084
+ `;
1085
+ md += `- **Recent (30d):** ${data.statistics.recent_memories_30d}
995
1086
 
996
1087
  `;
997
1088
  if (data.issues.length > 0) {
998
1089
  md += `## Issues
999
1090
  `;
1000
1091
  for (const issue of data.issues) {
1001
- md += `- ${issue}
1092
+ const icon = issue.severity === "high" ? "\u{1F534}" : issue.severity === "medium" ? "\u{1F7E1}" : "\u{1F7E2}";
1093
+ md += `- ${icon} **${issue.category}:** ${issue.description}
1002
1094
  `;
1003
1095
  }
1004
1096
  md += `
@@ -1029,6 +1121,193 @@ ${data.summary}
1029
1121
  }
1030
1122
  }
1031
1123
  );
1124
+ server.registerTool(
1125
+ "memory_predictive_recall",
1126
+ {
1127
+ title: "Predictive Memory Recall",
1128
+ description: `AI-powered prediction of memories you'll need based on your current context. Uses semantic similarity, temporal relevance, usage patterns, and serendipity scoring to anticipate what you need before you realize it.`,
1129
+ inputSchema: z.object({
1130
+ user_id: z.string().uuid(),
1131
+ context: z.object({
1132
+ current_project: z.string().optional().describe("Current project or task description"),
1133
+ recent_topics: z.array(z.string()).optional().describe("Recent topics you've been working on"),
1134
+ active_files: z.array(z.string()).optional().describe("Files currently being worked on"),
1135
+ context_text: z.string().optional().describe("Free-form context (current task, meeting notes, etc.)"),
1136
+ team_context: z.string().optional().describe("Team discussion topics for team-aware predictions")
1137
+ }).describe("Your current work context for generating predictions"),
1138
+ limit: z.number().int().min(1).max(20).default(5).describe("Maximum predictions to return"),
1139
+ min_confidence: z.number().min(0).max(100).default(40).describe("Minimum confidence threshold (0-100)"),
1140
+ include_serendipity: z.boolean().default(true).describe("Include surprising adjacent discoveries"),
1141
+ memory_types: z.array(MemoryType).optional().describe("Filter by memory types"),
1142
+ time_window_days: z.number().int().min(1).max(365).default(90).describe("Time window for recency scoring"),
1143
+ response_format: z.enum([ResponseFormat.JSON, ResponseFormat.MARKDOWN]).default(ResponseFormat.MARKDOWN)
1144
+ }).strict(),
1145
+ annotations: {
1146
+ readOnlyHint: true,
1147
+ destructiveHint: false,
1148
+ idempotentHint: false,
1149
+ openWorldHint: true
1150
+ }
1151
+ },
1152
+ async (rawParams) => {
1153
+ try {
1154
+ const params = {
1155
+ userId: rawParams.user_id,
1156
+ context: {
1157
+ currentProject: rawParams.context?.current_project,
1158
+ recentTopics: rawParams.context?.recent_topics,
1159
+ activeFiles: rawParams.context?.active_files,
1160
+ contextText: rawParams.context?.context_text,
1161
+ teamContext: rawParams.context?.team_context
1162
+ },
1163
+ limit: rawParams.limit,
1164
+ minConfidence: rawParams.min_confidence,
1165
+ includeSerendipity: rawParams.include_serendipity,
1166
+ memoryTypes: rawParams.memory_types,
1167
+ timeWindowDays: rawParams.time_window_days,
1168
+ responseFormat: rawParams.response_format
1169
+ };
1170
+ const response = await client.predictiveRecall(params);
1171
+ const result = response.data;
1172
+ const responseText = formatResponse(
1173
+ result,
1174
+ params.responseFormat || "markdown",
1175
+ (data) => {
1176
+ let md = `# Predicted Memories for You
1177
+
1178
+ `;
1179
+ md += `**Memories Analyzed:** ${data.memoriesAnalyzed}
1180
+ `;
1181
+ md += `**Predictions Found:** ${data.totalPredictions}
1182
+
1183
+ `;
1184
+ if (data.predictions.length === 0) {
1185
+ md += `_No predictions above the confidence threshold. Try providing more context or lowering the threshold._
1186
+ `;
1187
+ return md;
1188
+ }
1189
+ md += `## Your Predictions
1190
+
1191
+ `;
1192
+ for (const pred of data.predictions) {
1193
+ const confidenceIcon = pred.confidence >= 80 ? "\u{1F3AF}" : pred.confidence >= 60 ? "\u2728" : pred.confidence >= 40 ? "\u{1F4A1}" : "\u{1F50D}";
1194
+ const actionIcon = pred.suggestedAction === "apply" ? "\u26A1" : pred.suggestedAction === "reference" ? "\u{1F4DA}" : pred.suggestedAction === "explore" ? "\u{1F52D}" : "\u{1F440}";
1195
+ md += `### ${confidenceIcon} ${pred.title}
1196
+ `;
1197
+ md += `**Confidence:** ${pred.confidence}% | **Type:** ${pred.type}
1198
+ `;
1199
+ md += `**Why:** ${pred.reason}
1200
+ `;
1201
+ md += `**Suggested Action:** ${actionIcon} ${pred.suggestedAction}
1202
+ `;
1203
+ if (pred.tags.length > 0) {
1204
+ md += `**Tags:** ${pred.tags.slice(0, 5).join(", ")}
1205
+ `;
1206
+ }
1207
+ md += `
1208
+ > ${pred.contentPreview}
1209
+
1210
+ `;
1211
+ md += `<details>
1212
+ <summary>Score Breakdown</summary>
1213
+
1214
+ `;
1215
+ md += `- Semantic: ${pred.scoreBreakdown.semanticScore}%
1216
+ `;
1217
+ md += `- Temporal: ${pred.scoreBreakdown.temporalScore}%
1218
+ `;
1219
+ md += `- Frequency: ${pred.scoreBreakdown.frequencyScore}%
1220
+ `;
1221
+ md += `- Serendipity: ${pred.scoreBreakdown.serendipityScore}%
1222
+ `;
1223
+ md += `- **Combined:** ${pred.scoreBreakdown.combinedScore}%
1224
+ `;
1225
+ md += `</details>
1226
+
1227
+ `;
1228
+ md += `---
1229
+
1230
+ `;
1231
+ }
1232
+ md += `## Algorithm Info
1233
+ `;
1234
+ md += `- **Version:** ${data.algorithmInfo.version}
1235
+ `;
1236
+ md += `- **Embedding Model:** ${data.algorithmInfo.embeddingModel}
1237
+ `;
1238
+ md += `- **Time Window:** ${data.algorithmInfo.timeWindowDays} days
1239
+ `;
1240
+ md += `- **Weights:** Semantic ${data.scoringWeights.semantic * 100}%, `;
1241
+ md += `Temporal ${data.scoringWeights.temporal * 100}%, `;
1242
+ md += `Frequency ${data.scoringWeights.frequency * 100}%, `;
1243
+ md += `Serendipity ${data.scoringWeights.serendipity * 100}%
1244
+ `;
1245
+ return md;
1246
+ }
1247
+ );
1248
+ return {
1249
+ content: [{ type: "text", text: truncateIfNeeded(responseText) }]
1250
+ };
1251
+ } catch (error) {
1252
+ return {
1253
+ isError: true,
1254
+ content: [
1255
+ {
1256
+ type: "text",
1257
+ text: `Error: ${error instanceof Error ? error.message : "Unknown error"}`
1258
+ }
1259
+ ]
1260
+ };
1261
+ }
1262
+ }
1263
+ );
1264
+ server.registerTool(
1265
+ "memory_prediction_feedback",
1266
+ {
1267
+ title: "Record Prediction Feedback",
1268
+ description: `Record whether a prediction was useful. This helps improve future predictions.`,
1269
+ inputSchema: z.object({
1270
+ memory_id: z.string().uuid(),
1271
+ user_id: z.string().uuid(),
1272
+ useful: z.boolean().describe("Was this prediction useful?"),
1273
+ action: z.enum(["clicked", "saved", "dismissed", "ignored"]).describe("What action was taken"),
1274
+ dismiss_reason: z.enum(["not_relevant", "already_know", "not_now", "other"]).optional().describe("Reason for dismissal")
1275
+ }).strict(),
1276
+ annotations: {
1277
+ readOnlyHint: false,
1278
+ destructiveHint: false,
1279
+ idempotentHint: true,
1280
+ openWorldHint: false
1281
+ }
1282
+ },
1283
+ async (rawParams) => {
1284
+ try {
1285
+ await client.recordPredictionFeedback({
1286
+ memoryId: rawParams.memory_id,
1287
+ userId: rawParams.user_id,
1288
+ useful: rawParams.useful,
1289
+ action: rawParams.action,
1290
+ dismissReason: rawParams.dismiss_reason
1291
+ });
1292
+ return {
1293
+ content: [{
1294
+ type: "text",
1295
+ text: `Feedback recorded. Thank you for helping improve predictions!`
1296
+ }]
1297
+ };
1298
+ } catch (error) {
1299
+ return {
1300
+ isError: true,
1301
+ content: [
1302
+ {
1303
+ type: "text",
1304
+ text: `Error: ${error instanceof Error ? error.message : "Unknown error"}`
1305
+ }
1306
+ ]
1307
+ };
1308
+ }
1309
+ }
1310
+ );
1032
1311
  return server;
1033
1312
  }
1034
1313