@lanonasis/mem-intel-sdk 2.0.6 → 2.1.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 +24 -0
- package/dist/core/behavior-types.d.ts +55 -19
- package/dist/core/client.d.ts +6 -6
- package/dist/core/index.cjs +74 -16
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.js +73 -17
- package/dist/core/index.js.map +1 -1
- package/dist/core/prediction-types.d.ts +14 -7
- package/dist/core/types.d.ts +19 -6
- package/dist/index.cjs +74 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +73 -17
- package/dist/index.js.map +1 -1
- package/dist/node/index.cjs +57 -11
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +57 -12
- package/dist/node/index.js.map +1 -1
- package/dist/react/index.cjs +57 -11
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +57 -12
- package/dist/react/index.js.map +1 -1
- package/dist/server/index.cjs +105 -15
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.js +105 -16
- package/dist/server/index.js.map +1 -1
- package/dist/vue/index.cjs +7 -0
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.js +7 -1
- package/dist/vue/index.js.map +1 -1
- package/package.json +1 -1
package/dist/server/index.cjs
CHANGED
|
@@ -243,11 +243,12 @@ var HttpClient = class {
|
|
|
243
243
|
clearTimeout(timeoutId);
|
|
244
244
|
const responseData = await response.json();
|
|
245
245
|
if (!response.ok) {
|
|
246
|
+
const errorMessage = responseData?.message || responseData?.error?.message || (typeof responseData?.error === "string" ? responseData.error : void 0) || "Request failed";
|
|
246
247
|
return {
|
|
247
248
|
status: response.status,
|
|
248
249
|
error: {
|
|
249
|
-
message:
|
|
250
|
-
code: responseData?.code
|
|
250
|
+
message: errorMessage,
|
|
251
|
+
code: responseData?.code || responseData?.error?.code
|
|
251
252
|
}
|
|
252
253
|
};
|
|
253
254
|
}
|
|
@@ -356,6 +357,20 @@ var HttpClient = class {
|
|
|
356
357
|
|
|
357
358
|
// src/core/client.ts
|
|
358
359
|
var DEFAULT_API_URL = "https://api.lanonasis.com/api/v1";
|
|
360
|
+
function appendQueryContext(params, context) {
|
|
361
|
+
if (context.organizationId) {
|
|
362
|
+
params.append("organization_id", context.organizationId);
|
|
363
|
+
}
|
|
364
|
+
if (context.topicId) {
|
|
365
|
+
params.append("topic_id", context.topicId);
|
|
366
|
+
}
|
|
367
|
+
if (context.queryScope) {
|
|
368
|
+
params.append("query_scope", context.queryScope);
|
|
369
|
+
}
|
|
370
|
+
for (const memoryType of context.memoryTypes || []) {
|
|
371
|
+
params.append("memory_types", memoryType);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
359
374
|
var MemoryIntelligenceClient = class {
|
|
360
375
|
httpClient;
|
|
361
376
|
defaultResponseFormat;
|
|
@@ -405,7 +420,15 @@ var MemoryIntelligenceClient = class {
|
|
|
405
420
|
* Query memories from the API
|
|
406
421
|
*/
|
|
407
422
|
async queryMemories(userId, options = {}) {
|
|
408
|
-
const {
|
|
423
|
+
const {
|
|
424
|
+
type,
|
|
425
|
+
limit = 100,
|
|
426
|
+
offset = 0,
|
|
427
|
+
organizationId,
|
|
428
|
+
topicId,
|
|
429
|
+
memoryTypes,
|
|
430
|
+
queryScope
|
|
431
|
+
} = options;
|
|
409
432
|
const params = new URLSearchParams({
|
|
410
433
|
user_id: userId,
|
|
411
434
|
limit: limit.toString(),
|
|
@@ -414,7 +437,13 @@ var MemoryIntelligenceClient = class {
|
|
|
414
437
|
if (type) {
|
|
415
438
|
params.append("type", type);
|
|
416
439
|
}
|
|
417
|
-
|
|
440
|
+
appendQueryContext(params, {
|
|
441
|
+
organizationId,
|
|
442
|
+
topicId,
|
|
443
|
+
memoryTypes,
|
|
444
|
+
queryScope
|
|
445
|
+
});
|
|
446
|
+
const response = await this.httpClient.getEnhanced(
|
|
418
447
|
`/intelligence/memories?${params.toString()}`
|
|
419
448
|
);
|
|
420
449
|
if (response.error) {
|
|
@@ -582,6 +611,9 @@ var MemoryIntelligenceClient = class {
|
|
|
582
611
|
"/intelligence/predictive-recall",
|
|
583
612
|
{
|
|
584
613
|
userId: params.userId,
|
|
614
|
+
organizationId: params.organizationId,
|
|
615
|
+
topicId: params.topicId,
|
|
616
|
+
queryScope: params.queryScope,
|
|
585
617
|
context: params.context,
|
|
586
618
|
limit: params.limit || 5,
|
|
587
619
|
minConfidence: params.minConfidence || 40,
|
|
@@ -638,11 +670,11 @@ var MemoryIntelligenceClient = class {
|
|
|
638
670
|
* active_files: ["src/components/DataTable.tsx"]
|
|
639
671
|
* },
|
|
640
672
|
* actions: [
|
|
641
|
-
* { tool: "read_file",
|
|
642
|
-
* { tool: "analyze_code",
|
|
643
|
-
* { tool: "edit_file",
|
|
673
|
+
* { tool: "read_file", parameters: { path: "src/components/DataTable.tsx" }, outcome: "success" },
|
|
674
|
+
* { tool: "analyze_code", parameters: { focus: "class_components" }, outcome: "success" },
|
|
675
|
+
* { tool: "edit_file", parameters: { path: "src/components/DataTable.tsx" }, outcome: "success" }
|
|
644
676
|
* ],
|
|
645
|
-
* final_outcome: "
|
|
677
|
+
* final_outcome: "success"
|
|
646
678
|
* });
|
|
647
679
|
*
|
|
648
680
|
* if (result.data.was_duplicate) {
|
|
@@ -651,13 +683,20 @@ var MemoryIntelligenceClient = class {
|
|
|
651
683
|
* ```
|
|
652
684
|
*/
|
|
653
685
|
async recordBehavior(params) {
|
|
686
|
+
const actions = params.actions.map((action) => ({
|
|
687
|
+
tool: action.tool,
|
|
688
|
+
...action.parameters || action.params ? { parameters: action.parameters ?? action.params } : {},
|
|
689
|
+
...action.outcome ? { outcome: action.outcome } : {},
|
|
690
|
+
...action.timestamp ? { timestamp: action.timestamp } : {},
|
|
691
|
+
...action.duration_ms !== void 0 ? { duration_ms: action.duration_ms } : {}
|
|
692
|
+
}));
|
|
654
693
|
const response = await this.httpClient.postEnhanced(
|
|
655
694
|
"/intelligence/behavior-record",
|
|
656
695
|
{
|
|
657
696
|
user_id: params.user_id,
|
|
658
697
|
trigger: params.trigger,
|
|
659
698
|
context: params.context || {},
|
|
660
|
-
actions
|
|
699
|
+
actions,
|
|
661
700
|
final_outcome: params.final_outcome,
|
|
662
701
|
confidence: params.confidence ?? 0.7
|
|
663
702
|
}
|
|
@@ -734,8 +773,8 @@ var MemoryIntelligenceClient = class {
|
|
|
734
773
|
* current_state: {
|
|
735
774
|
* task_description: "Implementing user authentication with OAuth",
|
|
736
775
|
* completed_steps: [
|
|
737
|
-
*
|
|
738
|
-
*
|
|
776
|
+
* "create src/auth/oauth.ts",
|
|
777
|
+
* "inspect package.json"
|
|
739
778
|
* ]
|
|
740
779
|
* },
|
|
741
780
|
* max_suggestions: 3
|
|
@@ -800,6 +839,12 @@ var MemoryType = zod.z.enum([
|
|
|
800
839
|
"personal",
|
|
801
840
|
"workflow"
|
|
802
841
|
]);
|
|
842
|
+
var QueryScope = zod.z.enum([
|
|
843
|
+
"personal",
|
|
844
|
+
"team",
|
|
845
|
+
"organization",
|
|
846
|
+
"hybrid"
|
|
847
|
+
]);
|
|
803
848
|
|
|
804
849
|
// src/utils/formatting.ts
|
|
805
850
|
var CHARACTER_LIMIT = 5e4;
|
|
@@ -819,6 +864,15 @@ function truncateIfNeeded(text) {
|
|
|
819
864
|
}
|
|
820
865
|
|
|
821
866
|
// src/server/mcp-server.ts
|
|
867
|
+
var optionalContextFields = {
|
|
868
|
+
organization_id: zod.z.string().uuid().optional(),
|
|
869
|
+
topic_id: zod.z.string().optional(),
|
|
870
|
+
query_scope: QueryScope.optional()
|
|
871
|
+
};
|
|
872
|
+
var optionalCollectionContextFields = {
|
|
873
|
+
...optionalContextFields,
|
|
874
|
+
memory_types: zod.z.array(MemoryType).optional()
|
|
875
|
+
};
|
|
822
876
|
function createMCPServer(config) {
|
|
823
877
|
const client = new MemoryIntelligenceClient(config);
|
|
824
878
|
const server = new mcp_js.McpServer({
|
|
@@ -833,6 +887,7 @@ function createMCPServer(config) {
|
|
|
833
887
|
inputSchema: zod.z.object({
|
|
834
888
|
user_id: zod.z.string().uuid(),
|
|
835
889
|
time_range_days: zod.z.number().int().min(1).max(365).default(30),
|
|
890
|
+
...optionalCollectionContextFields,
|
|
836
891
|
response_format: zod.z.enum([ResponseFormat.JSON, ResponseFormat.MARKDOWN]).default(ResponseFormat.MARKDOWN)
|
|
837
892
|
}).strict(),
|
|
838
893
|
annotations: {
|
|
@@ -847,6 +902,10 @@ function createMCPServer(config) {
|
|
|
847
902
|
const params = {
|
|
848
903
|
userId: rawParams.user_id,
|
|
849
904
|
timeRangeDays: rawParams.time_range_days,
|
|
905
|
+
organizationId: rawParams.organization_id,
|
|
906
|
+
topicId: rawParams.topic_id,
|
|
907
|
+
memoryTypes: rawParams.memory_types,
|
|
908
|
+
queryScope: rawParams.query_scope,
|
|
850
909
|
responseFormat: rawParams.response_format
|
|
851
910
|
};
|
|
852
911
|
const response = await client.analyzePatterns(params);
|
|
@@ -992,6 +1051,7 @@ function createMCPServer(config) {
|
|
|
992
1051
|
user_id: zod.z.string().uuid(),
|
|
993
1052
|
limit: zod.z.number().int().min(1).max(50).default(10),
|
|
994
1053
|
similarity_threshold: zod.z.number().min(0).max(1).default(0.7),
|
|
1054
|
+
...optionalCollectionContextFields,
|
|
995
1055
|
response_format: zod.z.enum([ResponseFormat.JSON, ResponseFormat.MARKDOWN]).default(ResponseFormat.MARKDOWN)
|
|
996
1056
|
}).strict(),
|
|
997
1057
|
annotations: {
|
|
@@ -1008,6 +1068,10 @@ function createMCPServer(config) {
|
|
|
1008
1068
|
userId: rawParams.user_id,
|
|
1009
1069
|
limit: rawParams.limit,
|
|
1010
1070
|
similarityThreshold: rawParams.similarity_threshold,
|
|
1071
|
+
organizationId: rawParams.organization_id,
|
|
1072
|
+
topicId: rawParams.topic_id,
|
|
1073
|
+
memoryTypes: rawParams.memory_types,
|
|
1074
|
+
queryScope: rawParams.query_scope,
|
|
1011
1075
|
responseFormat: rawParams.response_format
|
|
1012
1076
|
};
|
|
1013
1077
|
const response = await client.findRelated(params);
|
|
@@ -1065,6 +1129,7 @@ function createMCPServer(config) {
|
|
|
1065
1129
|
user_id: zod.z.string().uuid(),
|
|
1066
1130
|
similarity_threshold: zod.z.number().min(0.8).max(0.99).default(0.9),
|
|
1067
1131
|
max_pairs: zod.z.number().int().min(1).max(100).default(20),
|
|
1132
|
+
...optionalCollectionContextFields,
|
|
1068
1133
|
response_format: zod.z.enum([ResponseFormat.JSON, ResponseFormat.MARKDOWN]).default(ResponseFormat.MARKDOWN)
|
|
1069
1134
|
}).strict(),
|
|
1070
1135
|
annotations: {
|
|
@@ -1080,6 +1145,10 @@ function createMCPServer(config) {
|
|
|
1080
1145
|
userId: rawParams.user_id,
|
|
1081
1146
|
similarityThreshold: rawParams.similarity_threshold,
|
|
1082
1147
|
maxPairs: rawParams.max_pairs,
|
|
1148
|
+
organizationId: rawParams.organization_id,
|
|
1149
|
+
topicId: rawParams.topic_id,
|
|
1150
|
+
memoryTypes: rawParams.memory_types,
|
|
1151
|
+
queryScope: rawParams.query_scope,
|
|
1083
1152
|
responseFormat: rawParams.response_format
|
|
1084
1153
|
};
|
|
1085
1154
|
const response = await client.detectDuplicates(params);
|
|
@@ -1143,6 +1212,7 @@ function createMCPServer(config) {
|
|
|
1143
1212
|
topic: zod.z.string().optional(),
|
|
1144
1213
|
memory_type: zod.z.string().optional(),
|
|
1145
1214
|
max_memories: zod.z.number().int().min(5).max(100).default(20),
|
|
1215
|
+
...optionalCollectionContextFields,
|
|
1146
1216
|
response_format: zod.z.enum([ResponseFormat.JSON, ResponseFormat.MARKDOWN]).default(ResponseFormat.MARKDOWN)
|
|
1147
1217
|
}).strict(),
|
|
1148
1218
|
annotations: {
|
|
@@ -1159,6 +1229,10 @@ function createMCPServer(config) {
|
|
|
1159
1229
|
topic: rawParams.topic,
|
|
1160
1230
|
memoryType: rawParams.memory_type,
|
|
1161
1231
|
maxMemories: rawParams.max_memories,
|
|
1232
|
+
organizationId: rawParams.organization_id,
|
|
1233
|
+
topicId: rawParams.topic_id,
|
|
1234
|
+
memoryTypes: rawParams.memory_types,
|
|
1235
|
+
queryScope: rawParams.query_scope,
|
|
1162
1236
|
responseFormat: rawParams.response_format
|
|
1163
1237
|
};
|
|
1164
1238
|
const response = await client.extractInsights(params);
|
|
@@ -1226,6 +1300,7 @@ ${data.overall_summary}
|
|
|
1226
1300
|
description: `Analyze the health and organization quality of memories.`,
|
|
1227
1301
|
inputSchema: zod.z.object({
|
|
1228
1302
|
user_id: zod.z.string().uuid(),
|
|
1303
|
+
...optionalCollectionContextFields,
|
|
1229
1304
|
response_format: zod.z.enum([ResponseFormat.JSON, ResponseFormat.MARKDOWN]).default(ResponseFormat.MARKDOWN)
|
|
1230
1305
|
}).strict(),
|
|
1231
1306
|
annotations: {
|
|
@@ -1239,6 +1314,10 @@ ${data.overall_summary}
|
|
|
1239
1314
|
try {
|
|
1240
1315
|
const params = {
|
|
1241
1316
|
userId: rawParams.user_id,
|
|
1317
|
+
organizationId: rawParams.organization_id,
|
|
1318
|
+
topicId: rawParams.topic_id,
|
|
1319
|
+
memoryTypes: rawParams.memory_types,
|
|
1320
|
+
queryScope: rawParams.query_scope,
|
|
1242
1321
|
responseFormat: rawParams.response_format
|
|
1243
1322
|
};
|
|
1244
1323
|
const response = await client.healthCheck(params);
|
|
@@ -1324,6 +1403,7 @@ ${data.overall_summary}
|
|
|
1324
1403
|
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.`,
|
|
1325
1404
|
inputSchema: zod.z.object({
|
|
1326
1405
|
user_id: zod.z.string().uuid(),
|
|
1406
|
+
...optionalContextFields,
|
|
1327
1407
|
context: zod.z.object({
|
|
1328
1408
|
current_project: zod.z.string().optional().describe("Current project or task description"),
|
|
1329
1409
|
recent_topics: zod.z.array(zod.z.string()).optional().describe("Recent topics you've been working on"),
|
|
@@ -1349,6 +1429,9 @@ ${data.overall_summary}
|
|
|
1349
1429
|
try {
|
|
1350
1430
|
const params = {
|
|
1351
1431
|
userId: rawParams.user_id,
|
|
1432
|
+
organizationId: rawParams.organization_id,
|
|
1433
|
+
topicId: rawParams.topic_id,
|
|
1434
|
+
queryScope: rawParams.query_scope,
|
|
1352
1435
|
context: {
|
|
1353
1436
|
currentProject: rawParams.context?.current_project,
|
|
1354
1437
|
recentTopics: rawParams.context?.recent_topics,
|
|
@@ -1634,10 +1717,16 @@ Was duplicate: ${response.data.was_duplicate}`
|
|
|
1634
1717
|
user_id: zod.z.string().uuid(),
|
|
1635
1718
|
current_state: zod.z.object({
|
|
1636
1719
|
task_description: zod.z.string().min(1, "Task description is required"),
|
|
1637
|
-
completed_steps: zod.z.array(
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1720
|
+
completed_steps: zod.z.array(
|
|
1721
|
+
zod.z.union([
|
|
1722
|
+
zod.z.string().min(1, "Completed step must be a non-empty string"),
|
|
1723
|
+
zod.z.object({
|
|
1724
|
+
tool: zod.z.string().min(1, "Legacy step objects must include tool"),
|
|
1725
|
+
params: zod.z.record(zod.z.unknown()).optional(),
|
|
1726
|
+
parameters: zod.z.record(zod.z.unknown()).optional()
|
|
1727
|
+
}).transform((step) => step.tool)
|
|
1728
|
+
])
|
|
1729
|
+
).optional()
|
|
1641
1730
|
}),
|
|
1642
1731
|
max_suggestions: zod.z.number().int().min(1).max(10).default(3)
|
|
1643
1732
|
}).strict(),
|
|
@@ -1695,6 +1784,7 @@ exports.EmbeddingError = EmbeddingError;
|
|
|
1695
1784
|
exports.MemoryIntelligenceError = MemoryIntelligenceError;
|
|
1696
1785
|
exports.MemoryNotFoundError = MemoryNotFoundError;
|
|
1697
1786
|
exports.MemoryType = MemoryType;
|
|
1787
|
+
exports.QueryScope = QueryScope;
|
|
1698
1788
|
exports.ResponseFormat = ResponseFormat;
|
|
1699
1789
|
exports.ValidationError = ValidationError;
|
|
1700
1790
|
exports.createMCPServer = createMCPServer;
|