@lanonasis/mem-intel-sdk 2.0.2 → 2.0.5
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 +16 -0
- package/README.md +81 -10
- package/dist/core/behavior-types.d.ts +336 -0
- package/dist/core/client.d.ts +97 -1
- package/dist/core/errors.d.ts +0 -1
- package/dist/core/index.cjs +205 -0
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +203 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/prediction-types.d.ts +0 -1
- package/dist/core/types.d.ts +0 -1
- package/dist/index-sdk.d.ts +2 -1
- package/dist/index.cjs +245 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +241 -1
- package/dist/index.js.map +1 -1
- package/dist/node/client.d.ts +0 -1
- package/dist/node/index.cjs +170 -0
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.ts +0 -1
- package/dist/node/index.js +170 -0
- package/dist/node/index.js.map +1 -1
- package/dist/react/context/MemoryIntelligenceProvider.d.ts +0 -1
- package/dist/react/hooks/useMemoryIntelligence.d.ts +0 -1
- package/dist/react/index.cjs +170 -0
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +0 -1
- package/dist/react/index.js +170 -0
- package/dist/react/index.js.map +1 -1
- package/dist/server/index.cjs +352 -0
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.ts +0 -1
- package/dist/server/index.js +352 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/mcp-server.d.ts +0 -1
- package/dist/utils/embeddings.d.ts +0 -1
- package/dist/utils/formatting.d.ts +0 -1
- package/dist/utils/http-client.d.ts +0 -1
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/prediction-engine.d.ts +0 -1
- package/dist/utils/response-adapter.d.ts +0 -1
- package/dist/utils/similarity.d.ts +0 -1
- package/dist/vue/composables/useMemoryIntelligence.d.ts +0 -1
- package/dist/vue/index.d.ts +0 -1
- package/package.json +2 -2
- package/dist/core/client.d.ts.map +0 -1
- package/dist/core/errors.d.ts.map +0 -1
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/prediction-types.d.ts.map +0 -1
- package/dist/core/types.d.ts.map +0 -1
- package/dist/index-sdk.d.ts.map +0 -1
- package/dist/node/client.d.ts.map +0 -1
- package/dist/node/index.d.ts.map +0 -1
- package/dist/react/context/MemoryIntelligenceProvider.d.ts.map +0 -1
- package/dist/react/hooks/useMemoryIntelligence.d.ts.map +0 -1
- package/dist/react/index.d.ts.map +0 -1
- package/dist/server/index.d.ts.map +0 -1
- package/dist/server/mcp-server.d.ts.map +0 -1
- package/dist/utils/embeddings.d.ts.map +0 -1
- package/dist/utils/formatting.d.ts.map +0 -1
- package/dist/utils/http-client.d.ts.map +0 -1
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/prediction-engine.d.ts.map +0 -1
- package/dist/utils/response-adapter.d.ts.map +0 -1
- package/dist/utils/similarity.d.ts.map +0 -1
- package/dist/vue/composables/useMemoryIntelligence.d.ts.map +0 -1
- package/dist/vue/index.d.ts.map +0 -1
package/dist/server/index.cjs
CHANGED
|
@@ -617,6 +617,176 @@ var MemoryIntelligenceClient = class {
|
|
|
617
617
|
async recordPredictionFeedback(params) {
|
|
618
618
|
await this.httpClient.post("/intelligence/prediction-feedback", params);
|
|
619
619
|
}
|
|
620
|
+
// ============================================================================
|
|
621
|
+
// Behavioral Learning Methods
|
|
622
|
+
// ============================================================================
|
|
623
|
+
/**
|
|
624
|
+
* Record a successful behavior pattern for future recall
|
|
625
|
+
*
|
|
626
|
+
* The system automatically:
|
|
627
|
+
* - Generates an embedding from the trigger description
|
|
628
|
+
* - Detects and updates duplicates (>95% similarity)
|
|
629
|
+
* - Tracks usage counts for pattern prioritization
|
|
630
|
+
*
|
|
631
|
+
* @example
|
|
632
|
+
* ```typescript
|
|
633
|
+
* const result = await client.recordBehavior({
|
|
634
|
+
* user_id: "user-123",
|
|
635
|
+
* trigger: "User wants to refactor a React component to use hooks",
|
|
636
|
+
* context: {
|
|
637
|
+
* project: "dashboard-app",
|
|
638
|
+
* active_files: ["src/components/DataTable.tsx"]
|
|
639
|
+
* },
|
|
640
|
+
* actions: [
|
|
641
|
+
* { tool: "read_file", params: { path: "src/components/DataTable.tsx" } },
|
|
642
|
+
* { tool: "analyze_code", params: { focus: "class_components" } },
|
|
643
|
+
* { tool: "edit_file", params: { path: "src/components/DataTable.tsx" } }
|
|
644
|
+
* ],
|
|
645
|
+
* final_outcome: "Successfully converted class component to functional with hooks"
|
|
646
|
+
* });
|
|
647
|
+
*
|
|
648
|
+
* if (result.data.was_duplicate) {
|
|
649
|
+
* console.log("Updated existing pattern:", result.data.pattern.id);
|
|
650
|
+
* }
|
|
651
|
+
* ```
|
|
652
|
+
*/
|
|
653
|
+
async recordBehavior(params) {
|
|
654
|
+
const response = await this.httpClient.postEnhanced(
|
|
655
|
+
"/intelligence/behavior-record",
|
|
656
|
+
{
|
|
657
|
+
user_id: params.user_id,
|
|
658
|
+
trigger: params.trigger,
|
|
659
|
+
context: params.context || {},
|
|
660
|
+
actions: params.actions,
|
|
661
|
+
final_outcome: params.final_outcome,
|
|
662
|
+
confidence: params.confidence ?? 0.7
|
|
663
|
+
}
|
|
664
|
+
);
|
|
665
|
+
if (response.error) {
|
|
666
|
+
throw new DatabaseError(`Failed to record behavior: ${response.error.message}`);
|
|
667
|
+
}
|
|
668
|
+
const data = response.data;
|
|
669
|
+
return {
|
|
670
|
+
data: {
|
|
671
|
+
pattern: data.data || data,
|
|
672
|
+
was_duplicate: data.message?.includes("duplicate") || false,
|
|
673
|
+
message: data.message || "Behavior pattern recorded successfully"
|
|
674
|
+
},
|
|
675
|
+
usage: response.usage,
|
|
676
|
+
tier_info: response.tier_info,
|
|
677
|
+
fromCache: response.fromCache
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
/**
|
|
681
|
+
* Recall similar behavior patterns based on current context
|
|
682
|
+
*
|
|
683
|
+
* Use this to find workflows that match the user's current task,
|
|
684
|
+
* enabling AI assistants to suggest proven approaches.
|
|
685
|
+
*
|
|
686
|
+
* @example
|
|
687
|
+
* ```typescript
|
|
688
|
+
* const result = await client.recallBehavior({
|
|
689
|
+
* user_id: "user-123",
|
|
690
|
+
* context: {
|
|
691
|
+
* current_task: "Need to optimize database queries for user dashboard"
|
|
692
|
+
* },
|
|
693
|
+
* limit: 5,
|
|
694
|
+
* similarity_threshold: 0.7
|
|
695
|
+
* });
|
|
696
|
+
*
|
|
697
|
+
* for (const match of result.data.patterns) {
|
|
698
|
+
* console.log(`[${Math.round(match.similarity_score * 100)}%] ${match.pattern.trigger}`);
|
|
699
|
+
* console.log(` Actions: ${match.pattern.actions.map(a => a.tool).join(" → ")}`);
|
|
700
|
+
* }
|
|
701
|
+
* ```
|
|
702
|
+
*/
|
|
703
|
+
async recallBehavior(params) {
|
|
704
|
+
const response = await this.httpClient.postEnhanced(
|
|
705
|
+
"/intelligence/behavior-recall",
|
|
706
|
+
{
|
|
707
|
+
user_id: params.user_id,
|
|
708
|
+
context: params.context,
|
|
709
|
+
limit: params.limit ?? 5,
|
|
710
|
+
similarity_threshold: params.similarity_threshold ?? 0.7
|
|
711
|
+
}
|
|
712
|
+
);
|
|
713
|
+
if (response.error) {
|
|
714
|
+
throw new DatabaseError(`Failed to recall behaviors: ${response.error.message}`);
|
|
715
|
+
}
|
|
716
|
+
const data = response.data;
|
|
717
|
+
return {
|
|
718
|
+
data: data.data || data,
|
|
719
|
+
usage: response.usage,
|
|
720
|
+
tier_info: response.tier_info,
|
|
721
|
+
fromCache: response.fromCache
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
/**
|
|
725
|
+
* Get AI-powered action suggestions based on learned patterns
|
|
726
|
+
*
|
|
727
|
+
* Analyzes the current state and completed steps to predict
|
|
728
|
+
* what action the user should take next based on similar workflows.
|
|
729
|
+
*
|
|
730
|
+
* @example
|
|
731
|
+
* ```typescript
|
|
732
|
+
* const result = await client.suggestAction({
|
|
733
|
+
* user_id: "user-123",
|
|
734
|
+
* current_state: {
|
|
735
|
+
* task_description: "Implementing user authentication with OAuth",
|
|
736
|
+
* completed_steps: [
|
|
737
|
+
* { tool: "create_file", params: { path: "src/auth/oauth.ts" } },
|
|
738
|
+
* { tool: "read_file", params: { path: "package.json" } }
|
|
739
|
+
* ]
|
|
740
|
+
* },
|
|
741
|
+
* max_suggestions: 3
|
|
742
|
+
* });
|
|
743
|
+
*
|
|
744
|
+
* for (const suggestion of result.data.suggestions) {
|
|
745
|
+
* console.log(`[${Math.round(suggestion.confidence * 100)}%] ${suggestion.action}`);
|
|
746
|
+
* console.log(` Tool: ${suggestion.tool}`);
|
|
747
|
+
* console.log(` Why: ${suggestion.reasoning}`);
|
|
748
|
+
* }
|
|
749
|
+
* ```
|
|
750
|
+
*/
|
|
751
|
+
async suggestAction(params) {
|
|
752
|
+
const response = await this.httpClient.postEnhanced(
|
|
753
|
+
"/intelligence/behavior-suggest",
|
|
754
|
+
{
|
|
755
|
+
user_id: params.user_id,
|
|
756
|
+
current_state: params.current_state,
|
|
757
|
+
max_suggestions: params.max_suggestions ?? 3
|
|
758
|
+
}
|
|
759
|
+
);
|
|
760
|
+
if (response.error) {
|
|
761
|
+
throw new DatabaseError(`Failed to get action suggestions: ${response.error.message}`);
|
|
762
|
+
}
|
|
763
|
+
const data = response.data;
|
|
764
|
+
return {
|
|
765
|
+
data: data.data || data,
|
|
766
|
+
usage: response.usage,
|
|
767
|
+
tier_info: response.tier_info,
|
|
768
|
+
fromCache: response.fromCache
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* List all behavior patterns for a user
|
|
773
|
+
*
|
|
774
|
+
* @example
|
|
775
|
+
* ```typescript
|
|
776
|
+
* const patterns = await client.listBehaviorPatterns("user-123", { limit: 20 });
|
|
777
|
+
* console.log(`Found ${patterns.length} patterns`);
|
|
778
|
+
* ```
|
|
779
|
+
*/
|
|
780
|
+
async listBehaviorPatterns(userId, options = {}) {
|
|
781
|
+
const { limit = 50, offset = 0 } = options;
|
|
782
|
+
const response = await this.httpClient.get(
|
|
783
|
+
`/intelligence/behavior-patterns?user_id=${userId}&limit=${limit}&offset=${offset}`
|
|
784
|
+
);
|
|
785
|
+
if (response.error) {
|
|
786
|
+
throw new DatabaseError(`Failed to list behavior patterns: ${response.error.message}`);
|
|
787
|
+
}
|
|
788
|
+
return response.data?.patterns || [];
|
|
789
|
+
}
|
|
620
790
|
};
|
|
621
791
|
var ResponseFormat = {
|
|
622
792
|
JSON: "json",
|
|
@@ -1334,6 +1504,188 @@ ${data.overall_summary}
|
|
|
1334
1504
|
}
|
|
1335
1505
|
}
|
|
1336
1506
|
);
|
|
1507
|
+
server.registerTool(
|
|
1508
|
+
"behavior_record",
|
|
1509
|
+
{
|
|
1510
|
+
title: "Record Behavior Pattern",
|
|
1511
|
+
description: `Record a successful workflow pattern for future recall.`,
|
|
1512
|
+
inputSchema: zod.z.object({
|
|
1513
|
+
user_id: zod.z.string().uuid(),
|
|
1514
|
+
trigger: zod.z.string().min(1, "Trigger description is required"),
|
|
1515
|
+
context: zod.z.object({
|
|
1516
|
+
directory: zod.z.string(),
|
|
1517
|
+
project_type: zod.z.string().optional(),
|
|
1518
|
+
branch: zod.z.string().optional(),
|
|
1519
|
+
files_touched: zod.z.array(zod.z.string()).optional()
|
|
1520
|
+
}).optional(),
|
|
1521
|
+
actions: zod.z.array(zod.z.object({
|
|
1522
|
+
tool: zod.z.string(),
|
|
1523
|
+
parameters: zod.z.record(zod.z.unknown()).optional(),
|
|
1524
|
+
outcome: zod.z.enum(["success", "partial", "failed"]),
|
|
1525
|
+
timestamp: zod.z.string().optional(),
|
|
1526
|
+
duration_ms: zod.z.number().optional()
|
|
1527
|
+
})).min(1, "At least one action is required"),
|
|
1528
|
+
final_outcome: zod.z.enum(["success", "partial", "failed"]),
|
|
1529
|
+
confidence: zod.z.number().min(0).max(1).default(0.7)
|
|
1530
|
+
}).strict(),
|
|
1531
|
+
annotations: {
|
|
1532
|
+
readOnlyHint: false,
|
|
1533
|
+
destructiveHint: false,
|
|
1534
|
+
idempotentHint: true,
|
|
1535
|
+
openWorldHint: false
|
|
1536
|
+
}
|
|
1537
|
+
},
|
|
1538
|
+
async (rawParams) => {
|
|
1539
|
+
try {
|
|
1540
|
+
const response = await client.recordBehavior({
|
|
1541
|
+
user_id: rawParams.user_id,
|
|
1542
|
+
trigger: rawParams.trigger,
|
|
1543
|
+
context: rawParams.context || {},
|
|
1544
|
+
actions: rawParams.actions,
|
|
1545
|
+
final_outcome: rawParams.final_outcome,
|
|
1546
|
+
confidence: rawParams.confidence
|
|
1547
|
+
});
|
|
1548
|
+
return {
|
|
1549
|
+
content: [{
|
|
1550
|
+
type: "text",
|
|
1551
|
+
text: `Behavior pattern recorded: ${response.data.message}
|
|
1552
|
+
Pattern ID: ${response.data.pattern.id}
|
|
1553
|
+
Was duplicate: ${response.data.was_duplicate}`
|
|
1554
|
+
}]
|
|
1555
|
+
};
|
|
1556
|
+
} catch (error) {
|
|
1557
|
+
return {
|
|
1558
|
+
isError: true,
|
|
1559
|
+
content: [
|
|
1560
|
+
{
|
|
1561
|
+
type: "text",
|
|
1562
|
+
text: `Error: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
1563
|
+
}
|
|
1564
|
+
]
|
|
1565
|
+
};
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
);
|
|
1569
|
+
server.registerTool(
|
|
1570
|
+
"behavior_recall",
|
|
1571
|
+
{
|
|
1572
|
+
title: "Recall Behavior Patterns",
|
|
1573
|
+
description: `Recall similar behavior patterns based on current context.`,
|
|
1574
|
+
inputSchema: zod.z.object({
|
|
1575
|
+
user_id: zod.z.string().uuid(),
|
|
1576
|
+
context: zod.z.object({
|
|
1577
|
+
current_task: zod.z.string().min(1, "Current task description is required"),
|
|
1578
|
+
directory: zod.z.string().optional(),
|
|
1579
|
+
project_type: zod.z.string().optional()
|
|
1580
|
+
}),
|
|
1581
|
+
limit: zod.z.number().int().min(1).max(20).default(5),
|
|
1582
|
+
similarity_threshold: zod.z.number().min(0).max(1).default(0.7)
|
|
1583
|
+
}).strict(),
|
|
1584
|
+
annotations: {
|
|
1585
|
+
readOnlyHint: true,
|
|
1586
|
+
destructiveHint: false,
|
|
1587
|
+
idempotentHint: true,
|
|
1588
|
+
openWorldHint: true
|
|
1589
|
+
}
|
|
1590
|
+
},
|
|
1591
|
+
async (rawParams) => {
|
|
1592
|
+
try {
|
|
1593
|
+
const response = await client.recallBehavior({
|
|
1594
|
+
user_id: rawParams.user_id,
|
|
1595
|
+
context: rawParams.context,
|
|
1596
|
+
limit: rawParams.limit,
|
|
1597
|
+
similarity_threshold: rawParams.similarity_threshold
|
|
1598
|
+
});
|
|
1599
|
+
const patterns = response.data?.patterns || [];
|
|
1600
|
+
let text = `Found ${patterns.length} behavior patterns:
|
|
1601
|
+
|
|
1602
|
+
`;
|
|
1603
|
+
patterns.forEach((pattern, i) => {
|
|
1604
|
+
text += `${i + 1}. "${pattern.pattern.trigger}" (${Math.round(pattern.similarity_score * 100)}% similar)
|
|
1605
|
+
`;
|
|
1606
|
+
text += ` Actions: ${pattern.pattern.actions.map((a) => a.tool).join(" \u2192 ")}
|
|
1607
|
+
`;
|
|
1608
|
+
text += ` Outcome: ${pattern.pattern.final_outcome}
|
|
1609
|
+
|
|
1610
|
+
`;
|
|
1611
|
+
});
|
|
1612
|
+
return {
|
|
1613
|
+
content: [{ type: "text", text }]
|
|
1614
|
+
};
|
|
1615
|
+
} catch (error) {
|
|
1616
|
+
return {
|
|
1617
|
+
isError: true,
|
|
1618
|
+
content: [
|
|
1619
|
+
{
|
|
1620
|
+
type: "text",
|
|
1621
|
+
text: `Error: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
1622
|
+
}
|
|
1623
|
+
]
|
|
1624
|
+
};
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
);
|
|
1628
|
+
server.registerTool(
|
|
1629
|
+
"behavior_suggest",
|
|
1630
|
+
{
|
|
1631
|
+
title: "Suggest Next Actions",
|
|
1632
|
+
description: `Get AI-powered action suggestions based on learned patterns.`,
|
|
1633
|
+
inputSchema: zod.z.object({
|
|
1634
|
+
user_id: zod.z.string().uuid(),
|
|
1635
|
+
current_state: zod.z.object({
|
|
1636
|
+
task_description: zod.z.string().min(1, "Task description is required"),
|
|
1637
|
+
completed_steps: zod.z.array(zod.z.object({
|
|
1638
|
+
tool: zod.z.string(),
|
|
1639
|
+
params: zod.z.record(zod.z.unknown()).optional()
|
|
1640
|
+
})).optional()
|
|
1641
|
+
}),
|
|
1642
|
+
max_suggestions: zod.z.number().int().min(1).max(10).default(3)
|
|
1643
|
+
}).strict(),
|
|
1644
|
+
annotations: {
|
|
1645
|
+
readOnlyHint: true,
|
|
1646
|
+
destructiveHint: false,
|
|
1647
|
+
idempotentHint: true,
|
|
1648
|
+
openWorldHint: true
|
|
1649
|
+
}
|
|
1650
|
+
},
|
|
1651
|
+
async (rawParams) => {
|
|
1652
|
+
try {
|
|
1653
|
+
const response = await client.suggestAction({
|
|
1654
|
+
user_id: rawParams.user_id,
|
|
1655
|
+
current_state: rawParams.current_state,
|
|
1656
|
+
max_suggestions: rawParams.max_suggestions
|
|
1657
|
+
});
|
|
1658
|
+
const suggestions = response.data?.suggestions || [];
|
|
1659
|
+
let text = `Suggested actions:
|
|
1660
|
+
|
|
1661
|
+
`;
|
|
1662
|
+
suggestions.forEach((suggestion, i) => {
|
|
1663
|
+
text += `${i + 1}. ${suggestion.action}
|
|
1664
|
+
`;
|
|
1665
|
+
text += ` Tool: ${suggestion.tool}
|
|
1666
|
+
`;
|
|
1667
|
+
text += ` Confidence: ${Math.round(suggestion.confidence * 100)}%
|
|
1668
|
+
`;
|
|
1669
|
+
text += ` Reasoning: ${suggestion.reasoning}
|
|
1670
|
+
|
|
1671
|
+
`;
|
|
1672
|
+
});
|
|
1673
|
+
return {
|
|
1674
|
+
content: [{ type: "text", text }]
|
|
1675
|
+
};
|
|
1676
|
+
} catch (error) {
|
|
1677
|
+
return {
|
|
1678
|
+
isError: true,
|
|
1679
|
+
content: [
|
|
1680
|
+
{
|
|
1681
|
+
type: "text",
|
|
1682
|
+
text: `Error: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
1683
|
+
}
|
|
1684
|
+
]
|
|
1685
|
+
};
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
);
|
|
1337
1689
|
return server;
|
|
1338
1690
|
}
|
|
1339
1691
|
|