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