@yamo/memory-mesh 3.0.0 → 3.0.2

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 (108) hide show
  1. package/README.md +9 -3
  2. package/bin/memory_mesh.js +95 -8
  3. package/lib/llm/client.d.ts +23 -48
  4. package/lib/llm/client.js +1 -0
  5. package/lib/llm/client.ts +298 -377
  6. package/lib/llm/index.js +1 -0
  7. package/lib/llm/index.ts +1 -2
  8. package/lib/memory/adapters/client.d.ts +22 -85
  9. package/lib/memory/adapters/client.js +1 -0
  10. package/lib/memory/adapters/client.ts +474 -633
  11. package/lib/memory/adapters/config.d.ts +82 -89
  12. package/lib/memory/adapters/config.js +1 -0
  13. package/lib/memory/adapters/config.ts +156 -225
  14. package/lib/memory/adapters/errors.d.ts +28 -20
  15. package/lib/memory/adapters/errors.js +1 -0
  16. package/lib/memory/adapters/errors.ts +83 -120
  17. package/lib/memory/context-manager.d.ts +15 -18
  18. package/lib/memory/context-manager.js +1 -0
  19. package/lib/memory/context-manager.ts +314 -401
  20. package/lib/memory/embeddings/factory.d.ts +18 -20
  21. package/lib/memory/embeddings/factory.js +1 -0
  22. package/lib/memory/embeddings/factory.ts +130 -173
  23. package/lib/memory/embeddings/index.js +1 -0
  24. package/lib/memory/embeddings/index.ts +1 -0
  25. package/lib/memory/embeddings/service.d.ts +36 -66
  26. package/lib/memory/embeddings/service.js +1 -0
  27. package/lib/memory/embeddings/service.ts +479 -616
  28. package/lib/memory/index.d.ts +2 -2
  29. package/lib/memory/index.js +1 -0
  30. package/lib/memory/index.ts +3 -13
  31. package/lib/memory/memory-mesh.d.ts +151 -93
  32. package/lib/memory/memory-mesh.js +1 -0
  33. package/lib/memory/memory-mesh.ts +1406 -1692
  34. package/lib/memory/memory-translator.d.ts +1 -6
  35. package/lib/memory/memory-translator.js +1 -0
  36. package/lib/memory/memory-translator.ts +96 -128
  37. package/lib/memory/schema.d.ts +29 -10
  38. package/lib/memory/schema.js +1 -0
  39. package/lib/memory/schema.ts +102 -185
  40. package/lib/memory/scorer.d.ts +3 -4
  41. package/lib/memory/scorer.js +1 -0
  42. package/lib/memory/scorer.ts +69 -86
  43. package/lib/memory/search/index.js +1 -0
  44. package/lib/memory/search/index.ts +1 -0
  45. package/lib/memory/search/keyword-search.d.ts +10 -26
  46. package/lib/memory/search/keyword-search.js +1 -0
  47. package/lib/memory/search/keyword-search.ts +123 -161
  48. package/lib/scrubber/config/defaults.d.ts +39 -46
  49. package/lib/scrubber/config/defaults.js +1 -0
  50. package/lib/scrubber/config/defaults.ts +50 -112
  51. package/lib/scrubber/errors/scrubber-error.d.ts +22 -0
  52. package/lib/scrubber/errors/scrubber-error.js +39 -0
  53. package/lib/scrubber/errors/scrubber-error.ts +44 -0
  54. package/lib/scrubber/index.d.ts +0 -1
  55. package/lib/scrubber/index.js +1 -0
  56. package/lib/scrubber/index.ts +1 -2
  57. package/lib/scrubber/scrubber.d.ts +14 -31
  58. package/lib/scrubber/scrubber.js +1 -0
  59. package/lib/scrubber/scrubber.ts +93 -152
  60. package/lib/scrubber/stages/chunker.d.ts +22 -10
  61. package/lib/scrubber/stages/chunker.js +86 -0
  62. package/lib/scrubber/stages/chunker.ts +104 -0
  63. package/lib/scrubber/stages/metadata-annotator.d.ts +14 -15
  64. package/lib/scrubber/stages/metadata-annotator.js +64 -0
  65. package/lib/scrubber/stages/metadata-annotator.ts +75 -0
  66. package/lib/scrubber/stages/normalizer.d.ts +13 -10
  67. package/lib/scrubber/stages/normalizer.js +51 -0
  68. package/lib/scrubber/stages/normalizer.ts +60 -0
  69. package/lib/scrubber/stages/semantic-filter.d.ts +13 -10
  70. package/lib/scrubber/stages/semantic-filter.js +51 -0
  71. package/lib/scrubber/stages/semantic-filter.ts +62 -0
  72. package/lib/scrubber/stages/structural-cleaner.d.ts +15 -10
  73. package/lib/scrubber/stages/structural-cleaner.js +73 -0
  74. package/lib/scrubber/stages/structural-cleaner.ts +83 -0
  75. package/lib/scrubber/stages/validator.d.ts +14 -15
  76. package/lib/scrubber/stages/validator.js +56 -0
  77. package/lib/scrubber/stages/validator.ts +67 -0
  78. package/lib/scrubber/telemetry.d.ts +20 -27
  79. package/lib/scrubber/telemetry.js +1 -0
  80. package/lib/scrubber/telemetry.ts +53 -90
  81. package/lib/scrubber/utils/hash.d.ts +14 -0
  82. package/lib/scrubber/utils/hash.js +37 -0
  83. package/lib/scrubber/utils/hash.ts +40 -0
  84. package/lib/scrubber/utils/html-parser.d.ts +14 -0
  85. package/lib/scrubber/utils/html-parser.js +38 -0
  86. package/lib/scrubber/utils/html-parser.ts +46 -0
  87. package/lib/scrubber/utils/pattern-matcher.d.ts +12 -0
  88. package/lib/scrubber/utils/pattern-matcher.js +54 -0
  89. package/lib/scrubber/utils/pattern-matcher.ts +64 -0
  90. package/lib/scrubber/utils/token-counter.d.ts +18 -0
  91. package/lib/scrubber/utils/token-counter.js +30 -0
  92. package/lib/scrubber/utils/token-counter.ts +32 -0
  93. package/lib/utils/logger.d.ts +1 -11
  94. package/lib/utils/logger.js +1 -0
  95. package/lib/utils/logger.ts +43 -63
  96. package/lib/utils/skill-metadata.d.ts +6 -14
  97. package/lib/utils/skill-metadata.js +1 -0
  98. package/lib/utils/skill-metadata.ts +89 -103
  99. package/lib/yamo/emitter.d.ts +8 -35
  100. package/lib/yamo/emitter.js +1 -0
  101. package/lib/yamo/emitter.ts +77 -155
  102. package/lib/yamo/index.d.ts +14 -0
  103. package/lib/yamo/index.js +14 -0
  104. package/lib/yamo/index.ts +16 -0
  105. package/lib/yamo/schema.d.ts +8 -10
  106. package/lib/yamo/schema.js +1 -0
  107. package/lib/yamo/schema.ts +82 -114
  108. package/package.json +5 -2
@@ -1,55 +1,57 @@
1
- /**
2
- * LanceDB Configuration Loader
3
- * Loads and validates configuration from environment variables
4
- */
5
1
  /**
6
2
  * Default configuration values
7
3
  */
8
4
  export declare const DEFAULTS: {
9
- readonly LANCEDB_URI: "./runtime/data/lancedb";
10
- readonly LANCEDB_MEMORY_TABLE: "memory_entries";
11
- readonly LANCEDB_MAX_CACHE_SIZE: "2GB";
12
- readonly EMBEDDING_MODEL_TYPE: "local";
13
- readonly EMBEDDING_MODEL_NAME: "Xenova/all-MiniLM-L6-v2";
14
- readonly EMBEDDING_DIMENSION: "384";
15
- readonly EMBEDDING_BATCH_SIZE: "32";
16
- readonly EMBEDDING_NORMALIZE: "true";
17
- readonly OPENAI_EMBEDDING_MODEL: "text-embedding-3-small";
18
- readonly DEFAULT_TOP_K: "10";
19
- readonly DEFAULT_SIMILARITY_THRESHOLD: "0.7";
20
- readonly ENABLE_HYBRID_SEARCH: "true";
21
- readonly HYBRID_SEARCH_ALPHA: "0.5";
22
- readonly VECTOR_INDEX_TYPE: "ivf_pq";
23
- readonly IVF_PARTITIONS: "256";
24
- readonly PQ_BITS: "8";
25
- readonly ENABLE_QUERY_CACHE: "true";
26
- readonly QUERY_CACHE_TTL: "300";
5
+ LANCEDB_URI: string;
6
+ LANCEDB_MEMORY_TABLE: string;
7
+ LANCEDB_MAX_CACHE_SIZE: string;
8
+ EMBEDDING_MODEL_TYPE: string;
9
+ EMBEDDING_MODEL_NAME: string;
10
+ EMBEDDING_DIMENSION: string;
11
+ EMBEDDING_BATCH_SIZE: string;
12
+ EMBEDDING_NORMALIZE: string;
13
+ OPENAI_EMBEDDING_MODEL: string;
14
+ DEFAULT_TOP_K: string;
15
+ DEFAULT_SIMILARITY_THRESHOLD: string;
16
+ ENABLE_HYBRID_SEARCH: string;
17
+ HYBRID_SEARCH_ALPHA: string;
18
+ VECTOR_INDEX_TYPE: string;
19
+ IVF_PARTITIONS: string;
20
+ PQ_BITS: string;
21
+ ENABLE_QUERY_CACHE: string;
22
+ QUERY_CACHE_TTL: string;
27
23
  };
28
- export type ConfigKey = keyof typeof DEFAULTS;
29
- export type Config = Record<ConfigKey, string>;
30
24
  /**
31
25
  * Memory system configuration defaults
32
26
  */
33
27
  export declare const MEMORY_DEFAULTS: {
34
- readonly MEMORY_ENABLED: "true";
35
- readonly MEMORY_AUTO_CAPTURE: "true";
36
- readonly MEMORY_AUTO_RECALL: "true";
37
- readonly MEMORY_MAX_CONTEXT: "5";
38
- readonly MEMORY_RELEVANCE_THRESHOLD: "0.7";
39
- readonly MEMORY_IMPORTANCE_BOOST: "1.5";
40
- readonly MEMORY_RECENCY_WEIGHT: "0.3";
41
- readonly MEMORY_MIN_IMPORTANCE: "0.3";
42
- readonly MEMORY_DEDUP_THRESHOLD: "0.9";
43
- readonly MEMORY_CAPTURE_TOOL_RESULTS: "true";
44
- readonly MEMORY_CAPTURE_FILE_OPS: "true";
45
- readonly MEMORY_RETENTION_ENABLED: "true";
46
- readonly MEMORY_RETENTION_DAYS: "90";
47
- readonly MEMORY_MAX_PER_SESSION: "100";
48
- readonly MEMORY_MIN_IMPORTANCE_TO_KEEP: "0.5";
49
- readonly MEMORY_REDACT_PII: "false";
50
- readonly MEMORY_ENCRYPTION_ENABLED: "false";
28
+ MEMORY_ENABLED: string;
29
+ MEMORY_AUTO_CAPTURE: string;
30
+ MEMORY_AUTO_RECALL: string;
31
+ MEMORY_MAX_CONTEXT: string;
32
+ MEMORY_RELEVANCE_THRESHOLD: string;
33
+ MEMORY_IMPORTANCE_BOOST: string;
34
+ MEMORY_RECENCY_WEIGHT: string;
35
+ MEMORY_MIN_IMPORTANCE: string;
36
+ MEMORY_DEDUP_THRESHOLD: string;
37
+ MEMORY_CAPTURE_TOOL_RESULTS: string;
38
+ MEMORY_CAPTURE_FILE_OPS: string;
39
+ MEMORY_RETENTION_ENABLED: string;
40
+ MEMORY_RETENTION_DAYS: string;
41
+ MEMORY_MAX_PER_SESSION: string;
42
+ MEMORY_MIN_IMPORTANCE_TO_KEEP: string;
43
+ MEMORY_REDACT_PII: string;
44
+ MEMORY_ENCRYPTION_ENABLED: string;
51
45
  };
52
- export interface MemoryConfig {
46
+ /**
47
+ * Load configuration with validation
48
+ */
49
+ export declare function loadConfig(): {};
50
+ /**
51
+ * Load memory-specific configuration
52
+ * @returns {Object} Memory configuration object
53
+ */
54
+ export declare function loadMemoryConfig(): {
53
55
  enabled: boolean;
54
56
  autoCapture: boolean;
55
57
  autoRecall: boolean;
@@ -71,67 +73,58 @@ export interface MemoryConfig {
71
73
  redactPii: boolean;
72
74
  encryptionEnabled: boolean;
73
75
  };
74
- }
75
- /**
76
- * Load configuration with validation
77
- */
78
- export declare function loadConfig(): Config;
79
- /**
80
- * Load memory-specific configuration
81
- * @returns {Object} Memory configuration object
82
- */
83
- export declare function loadMemoryConfig(): MemoryConfig;
76
+ };
84
77
  /**
85
78
  * Validate configuration
86
79
  */
87
- export declare function validateConfig(config: Config): string[];
80
+ export declare function validateConfig(config: any): any[];
88
81
  /**
89
82
  * Get validated configuration
90
83
  */
91
- export declare function getConfig(): Config;
84
+ export declare function getConfig(): {};
92
85
  declare const _default: {
93
86
  loadConfig: typeof loadConfig;
94
87
  validateConfig: typeof validateConfig;
95
88
  getConfig: typeof getConfig;
96
89
  loadMemoryConfig: typeof loadMemoryConfig;
97
90
  DEFAULTS: {
98
- readonly LANCEDB_URI: "./runtime/data/lancedb";
99
- readonly LANCEDB_MEMORY_TABLE: "memory_entries";
100
- readonly LANCEDB_MAX_CACHE_SIZE: "2GB";
101
- readonly EMBEDDING_MODEL_TYPE: "local";
102
- readonly EMBEDDING_MODEL_NAME: "Xenova/all-MiniLM-L6-v2";
103
- readonly EMBEDDING_DIMENSION: "384";
104
- readonly EMBEDDING_BATCH_SIZE: "32";
105
- readonly EMBEDDING_NORMALIZE: "true";
106
- readonly OPENAI_EMBEDDING_MODEL: "text-embedding-3-small";
107
- readonly DEFAULT_TOP_K: "10";
108
- readonly DEFAULT_SIMILARITY_THRESHOLD: "0.7";
109
- readonly ENABLE_HYBRID_SEARCH: "true";
110
- readonly HYBRID_SEARCH_ALPHA: "0.5";
111
- readonly VECTOR_INDEX_TYPE: "ivf_pq";
112
- readonly IVF_PARTITIONS: "256";
113
- readonly PQ_BITS: "8";
114
- readonly ENABLE_QUERY_CACHE: "true";
115
- readonly QUERY_CACHE_TTL: "300";
91
+ LANCEDB_URI: string;
92
+ LANCEDB_MEMORY_TABLE: string;
93
+ LANCEDB_MAX_CACHE_SIZE: string;
94
+ EMBEDDING_MODEL_TYPE: string;
95
+ EMBEDDING_MODEL_NAME: string;
96
+ EMBEDDING_DIMENSION: string;
97
+ EMBEDDING_BATCH_SIZE: string;
98
+ EMBEDDING_NORMALIZE: string;
99
+ OPENAI_EMBEDDING_MODEL: string;
100
+ DEFAULT_TOP_K: string;
101
+ DEFAULT_SIMILARITY_THRESHOLD: string;
102
+ ENABLE_HYBRID_SEARCH: string;
103
+ HYBRID_SEARCH_ALPHA: string;
104
+ VECTOR_INDEX_TYPE: string;
105
+ IVF_PARTITIONS: string;
106
+ PQ_BITS: string;
107
+ ENABLE_QUERY_CACHE: string;
108
+ QUERY_CACHE_TTL: string;
116
109
  };
117
110
  MEMORY_DEFAULTS: {
118
- readonly MEMORY_ENABLED: "true";
119
- readonly MEMORY_AUTO_CAPTURE: "true";
120
- readonly MEMORY_AUTO_RECALL: "true";
121
- readonly MEMORY_MAX_CONTEXT: "5";
122
- readonly MEMORY_RELEVANCE_THRESHOLD: "0.7";
123
- readonly MEMORY_IMPORTANCE_BOOST: "1.5";
124
- readonly MEMORY_RECENCY_WEIGHT: "0.3";
125
- readonly MEMORY_MIN_IMPORTANCE: "0.3";
126
- readonly MEMORY_DEDUP_THRESHOLD: "0.9";
127
- readonly MEMORY_CAPTURE_TOOL_RESULTS: "true";
128
- readonly MEMORY_CAPTURE_FILE_OPS: "true";
129
- readonly MEMORY_RETENTION_ENABLED: "true";
130
- readonly MEMORY_RETENTION_DAYS: "90";
131
- readonly MEMORY_MAX_PER_SESSION: "100";
132
- readonly MEMORY_MIN_IMPORTANCE_TO_KEEP: "0.5";
133
- readonly MEMORY_REDACT_PII: "false";
134
- readonly MEMORY_ENCRYPTION_ENABLED: "false";
111
+ MEMORY_ENABLED: string;
112
+ MEMORY_AUTO_CAPTURE: string;
113
+ MEMORY_AUTO_RECALL: string;
114
+ MEMORY_MAX_CONTEXT: string;
115
+ MEMORY_RELEVANCE_THRESHOLD: string;
116
+ MEMORY_IMPORTANCE_BOOST: string;
117
+ MEMORY_RECENCY_WEIGHT: string;
118
+ MEMORY_MIN_IMPORTANCE: string;
119
+ MEMORY_DEDUP_THRESHOLD: string;
120
+ MEMORY_CAPTURE_TOOL_RESULTS: string;
121
+ MEMORY_CAPTURE_FILE_OPS: string;
122
+ MEMORY_RETENTION_ENABLED: string;
123
+ MEMORY_RETENTION_DAYS: string;
124
+ MEMORY_MAX_PER_SESSION: string;
125
+ MEMORY_MIN_IMPORTANCE_TO_KEEP: string;
126
+ MEMORY_REDACT_PII: string;
127
+ MEMORY_ENCRYPTION_ENABLED: string;
135
128
  };
136
129
  };
137
130
  export default _default;
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * LanceDB Configuration Loader
3
4
  * Loads and validates configuration from environment variables
@@ -1,259 +1,190 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * LanceDB Configuration Loader
3
4
  * Loads and validates configuration from environment variables
4
5
  */
5
-
6
6
  import path from "path";
7
-
8
7
  /**
9
8
  * Default configuration values
10
9
  */
11
10
  export const DEFAULTS = {
12
- // LanceDB Configuration
13
- LANCEDB_URI: "./runtime/data/lancedb",
14
- LANCEDB_MEMORY_TABLE: "memory_entries",
15
- LANCEDB_MAX_CACHE_SIZE: "2GB",
16
-
17
- // Embedding Model Configuration
18
- EMBEDDING_MODEL_TYPE: "local",
19
- EMBEDDING_MODEL_NAME: "Xenova/all-MiniLM-L6-v2",
20
- EMBEDDING_DIMENSION: "384",
21
- EMBEDDING_BATCH_SIZE: "32",
22
- EMBEDDING_NORMALIZE: "true",
23
-
24
- // API-based Embeddings
25
- OPENAI_EMBEDDING_MODEL: "text-embedding-3-small",
26
-
27
- // Search Configuration
28
- DEFAULT_TOP_K: "10",
29
- DEFAULT_SIMILARITY_THRESHOLD: "0.7",
30
- ENABLE_HYBRID_SEARCH: "true",
31
- HYBRID_SEARCH_ALPHA: "0.5",
32
-
33
- // Performance Tuning
34
- VECTOR_INDEX_TYPE: "ivf_pq",
35
- IVF_PARTITIONS: "256",
36
- PQ_BITS: "8",
37
- ENABLE_QUERY_CACHE: "true",
38
- QUERY_CACHE_TTL: "300",
39
- } as const;
40
-
41
- export type ConfigKey = keyof typeof DEFAULTS;
42
- export type Config = Record<ConfigKey, string>;
43
-
11
+ // LanceDB Configuration
12
+ LANCEDB_URI: "./runtime/data/lancedb",
13
+ LANCEDB_MEMORY_TABLE: "memory_entries",
14
+ LANCEDB_MAX_CACHE_SIZE: "2GB",
15
+ // Embedding Model Configuration
16
+ EMBEDDING_MODEL_TYPE: "local",
17
+ EMBEDDING_MODEL_NAME: "Xenova/all-MiniLM-L6-v2",
18
+ EMBEDDING_DIMENSION: "384",
19
+ EMBEDDING_BATCH_SIZE: "32",
20
+ EMBEDDING_NORMALIZE: "true",
21
+ // API-based Embeddings
22
+ OPENAI_EMBEDDING_MODEL: "text-embedding-3-small",
23
+ // Search Configuration
24
+ DEFAULT_TOP_K: "10",
25
+ DEFAULT_SIMILARITY_THRESHOLD: "0.7",
26
+ ENABLE_HYBRID_SEARCH: "true",
27
+ HYBRID_SEARCH_ALPHA: "0.5",
28
+ // Performance Tuning
29
+ VECTOR_INDEX_TYPE: "ivf_pq",
30
+ IVF_PARTITIONS: "256",
31
+ PQ_BITS: "8",
32
+ ENABLE_QUERY_CACHE: "true",
33
+ QUERY_CACHE_TTL: "300",
34
+ };
44
35
  /**
45
36
  * Memory system configuration defaults
46
37
  */
47
38
  export const MEMORY_DEFAULTS = {
48
- // Feature flags
49
- MEMORY_ENABLED: "true",
50
- MEMORY_AUTO_CAPTURE: "true",
51
- MEMORY_AUTO_RECALL: "true",
52
-
53
- // Recall settings
54
- MEMORY_MAX_CONTEXT: "5",
55
- MEMORY_RELEVANCE_THRESHOLD: "0.7",
56
- MEMORY_IMPORTANCE_BOOST: "1.5",
57
- MEMORY_RECENCY_WEIGHT: "0.3",
58
-
59
- // Capture settings
60
- MEMORY_MIN_IMPORTANCE: "0.3",
61
- MEMORY_DEDUP_THRESHOLD: "0.9",
62
- MEMORY_CAPTURE_TOOL_RESULTS: "true",
63
- MEMORY_CAPTURE_FILE_OPS: "true",
64
-
65
- // Retention settings
66
- MEMORY_RETENTION_ENABLED: "true",
67
- MEMORY_RETENTION_DAYS: "90",
68
- MEMORY_MAX_PER_SESSION: "100",
69
- MEMORY_MIN_IMPORTANCE_TO_KEEP: "0.5",
70
-
71
- // Privacy settings
72
- MEMORY_REDACT_PII: "false",
73
- MEMORY_ENCRYPTION_ENABLED: "false",
74
- } as const;
75
-
76
- export interface MemoryConfig {
77
- enabled: boolean;
78
- autoCapture: boolean;
79
- autoRecall: boolean;
80
- maxContext: number;
81
- relevanceThreshold: number;
82
- importanceBoost: number;
83
- recencyWeight: number;
84
- minImportance: number;
85
- dedupThreshold: number;
86
- captureToolResults: boolean;
87
- captureFileOps: boolean;
88
- retention: {
89
- enabled: boolean;
90
- days: number;
91
- maxPerSession: number;
92
- minImportanceToKeep: number;
93
- };
94
- privacy: {
95
- redactPii: boolean;
96
- encryptionEnabled: boolean;
97
- };
98
- }
99
-
39
+ // Feature flags
40
+ MEMORY_ENABLED: "true",
41
+ MEMORY_AUTO_CAPTURE: "true",
42
+ MEMORY_AUTO_RECALL: "true",
43
+ // Recall settings
44
+ MEMORY_MAX_CONTEXT: "5",
45
+ MEMORY_RELEVANCE_THRESHOLD: "0.7",
46
+ MEMORY_IMPORTANCE_BOOST: "1.5",
47
+ MEMORY_RECENCY_WEIGHT: "0.3",
48
+ // Capture settings
49
+ MEMORY_MIN_IMPORTANCE: "0.3",
50
+ MEMORY_DEDUP_THRESHOLD: "0.9",
51
+ MEMORY_CAPTURE_TOOL_RESULTS: "true",
52
+ MEMORY_CAPTURE_FILE_OPS: "true",
53
+ // Retention settings
54
+ MEMORY_RETENTION_ENABLED: "true",
55
+ MEMORY_RETENTION_DAYS: "90",
56
+ MEMORY_MAX_PER_SESSION: "100",
57
+ MEMORY_MIN_IMPORTANCE_TO_KEEP: "0.5",
58
+ // Privacy settings
59
+ MEMORY_REDACT_PII: "false",
60
+ MEMORY_ENCRYPTION_ENABLED: "false",
61
+ };
100
62
  /**
101
63
  * Load configuration with validation
102
64
  */
103
- export function loadConfig(): Config {
104
- const config: Partial<Config> = {};
105
-
106
- for (const [key, defaultValue] of Object.entries(DEFAULTS)) {
107
- config[key as ConfigKey] = process.env[key] || defaultValue;
108
- }
109
-
110
- // Resolve relative paths to absolute relative to package root
111
- if (
112
- config.LANCEDB_URI &&
113
- (config.LANCEDB_URI.startsWith("./") ||
114
- config.LANCEDB_URI.startsWith("../"))
115
- ) {
116
- const currentFileUrl = import.meta.url;
117
- const currentFilePath = new URL(currentFileUrl).pathname;
118
- // config.ts is in lib/brain/adapters, so package root is ../../../
119
- const packageRoot = path.resolve(
120
- path.dirname(currentFilePath),
121
- "../../../",
122
- );
123
- config.LANCEDB_URI = path.resolve(packageRoot, config.LANCEDB_URI);
124
- }
125
-
126
- return config as Config;
65
+ export function loadConfig() {
66
+ const config = {};
67
+ for (const [key, defaultValue] of Object.entries(DEFAULTS)) {
68
+ config[key] = process.env[key] || defaultValue;
69
+ }
70
+ // Resolve relative paths to absolute relative to package root
71
+ if (config.LANCEDB_URI &&
72
+ (config.LANCEDB_URI.startsWith("./") ||
73
+ config.LANCEDB_URI.startsWith("../"))) {
74
+ const currentFileUrl = import.meta.url;
75
+ const currentFilePath = new URL(currentFileUrl).pathname;
76
+ // config.ts is in lib/brain/adapters, so package root is ../../../
77
+ const packageRoot = path.resolve(path.dirname(currentFilePath), "../../../");
78
+ config.LANCEDB_URI = path.resolve(packageRoot, config.LANCEDB_URI);
79
+ }
80
+ return config;
127
81
  }
128
-
129
82
  /**
130
83
  * Load memory-specific configuration
131
84
  * @returns {Object} Memory configuration object
132
85
  */
133
- export function loadMemoryConfig(): MemoryConfig {
134
- return {
135
- enabled: process.env.MEMORY_ENABLED !== "false",
136
- autoCapture: process.env.MEMORY_AUTO_CAPTURE !== "false",
137
- autoRecall: process.env.MEMORY_AUTO_RECALL !== "false",
138
- maxContext: parseInt(process.env.MEMORY_MAX_CONTEXT || "5"),
139
- relevanceThreshold: parseFloat(
140
- process.env.MEMORY_RELEVANCE_THRESHOLD || "0.7",
141
- ),
142
- importanceBoost: parseFloat(process.env.MEMORY_IMPORTANCE_BOOST || "1.5"),
143
- recencyWeight: parseFloat(process.env.MEMORY_RECENCY_WEIGHT || "0.3"),
144
- minImportance: parseFloat(process.env.MEMORY_MIN_IMPORTANCE || "0.3"),
145
- dedupThreshold: parseFloat(process.env.MEMORY_DEDUP_THRESHOLD || "0.9"),
146
- captureToolResults: process.env.MEMORY_CAPTURE_TOOL_RESULTS !== "false",
147
- captureFileOps: process.env.MEMORY_CAPTURE_FILE_OPS !== "false",
148
- retention: {
149
- enabled: process.env.MEMORY_RETENTION_ENABLED !== "false",
150
- days: parseInt(process.env.MEMORY_RETENTION_DAYS || "90"),
151
- maxPerSession: parseInt(process.env.MEMORY_MAX_PER_SESSION || "100"),
152
- minImportanceToKeep: parseFloat(
153
- process.env.MEMORY_MIN_IMPORTANCE_TO_KEEP || "0.5",
154
- ),
155
- },
156
- privacy: {
157
- redactPii: process.env.MEMORY_REDACT_PII === "true",
158
- encryptionEnabled: process.env.MEMORY_ENCRYPTION_ENABLED === "true",
159
- },
160
- };
86
+ export function loadMemoryConfig() {
87
+ return {
88
+ enabled: process.env.MEMORY_ENABLED !== "false",
89
+ autoCapture: process.env.MEMORY_AUTO_CAPTURE !== "false",
90
+ autoRecall: process.env.MEMORY_AUTO_RECALL !== "false",
91
+ maxContext: parseInt(process.env.MEMORY_MAX_CONTEXT || "5"),
92
+ relevanceThreshold: parseFloat(process.env.MEMORY_RELEVANCE_THRESHOLD || "0.7"),
93
+ importanceBoost: parseFloat(process.env.MEMORY_IMPORTANCE_BOOST || "1.5"),
94
+ recencyWeight: parseFloat(process.env.MEMORY_RECENCY_WEIGHT || "0.3"),
95
+ minImportance: parseFloat(process.env.MEMORY_MIN_IMPORTANCE || "0.3"),
96
+ dedupThreshold: parseFloat(process.env.MEMORY_DEDUP_THRESHOLD || "0.9"),
97
+ captureToolResults: process.env.MEMORY_CAPTURE_TOOL_RESULTS !== "false",
98
+ captureFileOps: process.env.MEMORY_CAPTURE_FILE_OPS !== "false",
99
+ retention: {
100
+ enabled: process.env.MEMORY_RETENTION_ENABLED !== "false",
101
+ days: parseInt(process.env.MEMORY_RETENTION_DAYS || "90"),
102
+ maxPerSession: parseInt(process.env.MEMORY_MAX_PER_SESSION || "100"),
103
+ minImportanceToKeep: parseFloat(process.env.MEMORY_MIN_IMPORTANCE_TO_KEEP || "0.5"),
104
+ },
105
+ privacy: {
106
+ redactPii: process.env.MEMORY_REDACT_PII === "true",
107
+ encryptionEnabled: process.env.MEMORY_ENCRYPTION_ENABLED === "true",
108
+ },
109
+ };
161
110
  }
162
-
163
111
  /**
164
112
  * Validate configuration
165
113
  */
166
- export function validateConfig(config: Config): string[] {
167
- const errors: string[] = [];
168
-
169
- // Validate embedding model type
170
- const validModelTypes = ["local", "openai", "cohere", "voyage"];
171
- if (!validModelTypes.includes(config.EMBEDDING_MODEL_TYPE)) {
172
- errors.push(`Invalid EMBEDDING_MODEL_TYPE: ${config.EMBEDDING_MODEL_TYPE}`);
173
- }
174
-
175
- // Validate numeric values
176
- const dimension = parseInt(config.EMBEDDING_DIMENSION);
177
- if (isNaN(dimension) || dimension <= 0) {
178
- errors.push(`Invalid EMBEDDING_DIMENSION: ${config.EMBEDDING_DIMENSION}`);
179
- }
180
-
181
- const topK = parseInt(config.DEFAULT_TOP_K);
182
- if (isNaN(topK) || topK <= 0) {
183
- errors.push(`Invalid DEFAULT_TOP_K: ${config.DEFAULT_TOP_K}`);
184
- }
185
-
186
- // Validate boolean strings
187
- const boolFields: (keyof Config)[] = [
188
- "EMBEDDING_NORMALIZE",
189
- "ENABLE_HYBRID_SEARCH",
190
- "ENABLE_QUERY_CACHE",
191
- ];
192
- for (const field of boolFields) {
193
- const value = config[field].toLowerCase();
194
- if (value !== "true" && value !== "false") {
195
- errors.push(`Invalid ${field}: must be 'true' or 'false'`);
114
+ export function validateConfig(config) {
115
+ const errors = [];
116
+ // Validate embedding model type
117
+ const validModelTypes = ["local", "openai", "cohere", "voyage"];
118
+ if (!validModelTypes.includes(config.EMBEDDING_MODEL_TYPE)) {
119
+ errors.push(`Invalid EMBEDDING_MODEL_TYPE: ${config.EMBEDDING_MODEL_TYPE}`);
120
+ }
121
+ // Validate numeric values
122
+ const dimension = parseInt(config.EMBEDDING_DIMENSION);
123
+ if (isNaN(dimension) || dimension <= 0) {
124
+ errors.push(`Invalid EMBEDDING_DIMENSION: ${config.EMBEDDING_DIMENSION}`);
196
125
  }
197
- }
198
-
199
- // Validate similarity threshold (0-1 range)
200
- const threshold = parseFloat(config.DEFAULT_SIMILARITY_THRESHOLD);
201
- if (isNaN(threshold) || threshold < 0 || threshold > 1) {
202
- errors.push(
203
- `Invalid DEFAULT_SIMILARITY_THRESHOLD: must be between 0 and 1`,
204
- );
205
- }
206
-
207
- // Validate hybrid search alpha (0-1 range)
208
- const alpha = parseFloat(config.HYBRID_SEARCH_ALPHA);
209
- if (isNaN(alpha) || alpha < 0 || alpha > 1) {
210
- errors.push(`Invalid HYBRID_SEARCH_ALPHA: must be between 0 and 1`);
211
- }
212
-
213
- // Validate positive integers
214
- const positiveIntFields: (keyof Config)[] = [
215
- "EMBEDDING_BATCH_SIZE",
216
- "IVF_PARTITIONS",
217
- "PQ_BITS",
218
- "QUERY_CACHE_TTL",
219
- ];
220
- for (const field of positiveIntFields) {
221
- const value = parseInt(config[field]);
222
- if (isNaN(value) || value <= 0) {
223
- errors.push(`Invalid ${field}: must be a positive integer`);
126
+ const topK = parseInt(config.DEFAULT_TOP_K);
127
+ if (isNaN(topK) || topK <= 0) {
128
+ errors.push(`Invalid DEFAULT_TOP_K: ${config.DEFAULT_TOP_K}`);
224
129
  }
225
- }
226
-
227
- // Validate cache size format (e.g., "2GB", "500MB")
228
- const cacheSizePattern = /^\d+(\.\d+)?(KB|MB|GB|TB)$/;
229
- if (!cacheSizePattern.test(config.LANCEDB_MAX_CACHE_SIZE)) {
230
- errors.push(
231
- `Invalid LANCEDB_MAX_CACHE_SIZE: must match pattern like "2GB", "500MB"`,
232
- );
233
- }
234
-
235
- return errors;
130
+ // Validate boolean strings
131
+ const boolFields = [
132
+ "EMBEDDING_NORMALIZE",
133
+ "ENABLE_HYBRID_SEARCH",
134
+ "ENABLE_QUERY_CACHE",
135
+ ];
136
+ for (const field of boolFields) {
137
+ const value = config[field].toLowerCase();
138
+ if (value !== "true" && value !== "false") {
139
+ errors.push(`Invalid ${field}: must be 'true' or 'false'`);
140
+ }
141
+ }
142
+ // Validate similarity threshold (0-1 range)
143
+ const threshold = parseFloat(config.DEFAULT_SIMILARITY_THRESHOLD);
144
+ if (isNaN(threshold) || threshold < 0 || threshold > 1) {
145
+ errors.push(`Invalid DEFAULT_SIMILARITY_THRESHOLD: must be between 0 and 1`);
146
+ }
147
+ // Validate hybrid search alpha (0-1 range)
148
+ const alpha = parseFloat(config.HYBRID_SEARCH_ALPHA);
149
+ if (isNaN(alpha) || alpha < 0 || alpha > 1) {
150
+ errors.push(`Invalid HYBRID_SEARCH_ALPHA: must be between 0 and 1`);
151
+ }
152
+ // Validate positive integers
153
+ const positiveIntFields = [
154
+ "EMBEDDING_BATCH_SIZE",
155
+ "IVF_PARTITIONS",
156
+ "PQ_BITS",
157
+ "QUERY_CACHE_TTL",
158
+ ];
159
+ for (const field of positiveIntFields) {
160
+ const value = parseInt(config[field]);
161
+ if (isNaN(value) || value <= 0) {
162
+ errors.push(`Invalid ${field}: must be a positive integer`);
163
+ }
164
+ }
165
+ // Validate cache size format (e.g., "2GB", "500MB")
166
+ const cacheSizePattern = /^\d+(\.\d+)?(KB|MB|GB|TB)$/;
167
+ if (!cacheSizePattern.test(config.LANCEDB_MAX_CACHE_SIZE)) {
168
+ errors.push(`Invalid LANCEDB_MAX_CACHE_SIZE: must match pattern like "2GB", "500MB"`);
169
+ }
170
+ return errors;
236
171
  }
237
-
238
172
  /**
239
173
  * Get validated configuration
240
174
  */
241
- export function getConfig(): Config {
242
- const config = loadConfig();
243
- const errors = validateConfig(config);
244
-
245
- if (errors.length > 0) {
246
- throw new Error(`Configuration validation failed:\n${errors.join("\n")}`);
247
- }
248
-
249
- return config;
175
+ export function getConfig() {
176
+ const config = loadConfig();
177
+ const errors = validateConfig(config);
178
+ if (errors.length > 0) {
179
+ throw new Error(`Configuration validation failed:\n${errors.join("\n")}`);
180
+ }
181
+ return config;
250
182
  }
251
-
252
183
  export default {
253
- loadConfig,
254
- validateConfig,
255
- getConfig,
256
- loadMemoryConfig,
257
- DEFAULTS,
258
- MEMORY_DEFAULTS,
184
+ loadConfig,
185
+ validateConfig,
186
+ getConfig,
187
+ loadMemoryConfig,
188
+ DEFAULTS,
189
+ MEMORY_DEFAULTS,
259
190
  };