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