@lanonasis/mem-intel-sdk 2.0.2 → 2.0.3

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 (68) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +81 -10
  3. package/dist/core/behavior-types.d.ts +336 -0
  4. package/dist/core/client.d.ts +97 -1
  5. package/dist/core/errors.d.ts +0 -1
  6. package/dist/core/index.cjs +205 -0
  7. package/dist/core/index.cjs.map +1 -1
  8. package/dist/core/index.d.ts +1 -1
  9. package/dist/core/index.js +203 -1
  10. package/dist/core/index.js.map +1 -1
  11. package/dist/core/prediction-types.d.ts +0 -1
  12. package/dist/core/types.d.ts +0 -1
  13. package/dist/index-sdk.d.ts +2 -1
  14. package/dist/index.cjs +245 -0
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.js +241 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/node/client.d.ts +0 -1
  19. package/dist/node/index.cjs +170 -0
  20. package/dist/node/index.cjs.map +1 -1
  21. package/dist/node/index.d.ts +0 -1
  22. package/dist/node/index.js +170 -0
  23. package/dist/node/index.js.map +1 -1
  24. package/dist/react/context/MemoryIntelligenceProvider.d.ts +0 -1
  25. package/dist/react/hooks/useMemoryIntelligence.d.ts +0 -1
  26. package/dist/react/index.cjs +170 -0
  27. package/dist/react/index.cjs.map +1 -1
  28. package/dist/react/index.d.ts +0 -1
  29. package/dist/react/index.js +170 -0
  30. package/dist/react/index.js.map +1 -1
  31. package/dist/server/index.cjs +170 -0
  32. package/dist/server/index.cjs.map +1 -1
  33. package/dist/server/index.d.ts +0 -1
  34. package/dist/server/index.js +170 -0
  35. package/dist/server/index.js.map +1 -1
  36. package/dist/server/mcp-server.d.ts +0 -1
  37. package/dist/utils/embeddings.d.ts +0 -1
  38. package/dist/utils/formatting.d.ts +0 -1
  39. package/dist/utils/http-client.d.ts +0 -1
  40. package/dist/utils/index.d.ts +0 -1
  41. package/dist/utils/prediction-engine.d.ts +0 -1
  42. package/dist/utils/response-adapter.d.ts +0 -1
  43. package/dist/utils/similarity.d.ts +0 -1
  44. package/dist/vue/composables/useMemoryIntelligence.d.ts +0 -1
  45. package/dist/vue/index.d.ts +0 -1
  46. package/package.json +2 -2
  47. package/dist/core/client.d.ts.map +0 -1
  48. package/dist/core/errors.d.ts.map +0 -1
  49. package/dist/core/index.d.ts.map +0 -1
  50. package/dist/core/prediction-types.d.ts.map +0 -1
  51. package/dist/core/types.d.ts.map +0 -1
  52. package/dist/index-sdk.d.ts.map +0 -1
  53. package/dist/node/client.d.ts.map +0 -1
  54. package/dist/node/index.d.ts.map +0 -1
  55. package/dist/react/context/MemoryIntelligenceProvider.d.ts.map +0 -1
  56. package/dist/react/hooks/useMemoryIntelligence.d.ts.map +0 -1
  57. package/dist/react/index.d.ts.map +0 -1
  58. package/dist/server/index.d.ts.map +0 -1
  59. package/dist/server/mcp-server.d.ts.map +0 -1
  60. package/dist/utils/embeddings.d.ts.map +0 -1
  61. package/dist/utils/formatting.d.ts.map +0 -1
  62. package/dist/utils/http-client.d.ts.map +0 -1
  63. package/dist/utils/index.d.ts.map +0 -1
  64. package/dist/utils/prediction-engine.d.ts.map +0 -1
  65. package/dist/utils/response-adapter.d.ts.map +0 -1
  66. package/dist/utils/similarity.d.ts.map +0 -1
  67. package/dist/vue/composables/useMemoryIntelligence.d.ts.map +0 -1
  68. package/dist/vue/index.d.ts.map +0 -1
@@ -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",