@yamo/memory-mesh 3.0.0 → 3.0.1

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 (107) hide show
  1. package/README.md +8 -2
  2. package/lib/llm/client.d.ts +23 -48
  3. package/lib/llm/client.js +1 -0
  4. package/lib/llm/client.ts +298 -377
  5. package/lib/llm/index.js +1 -0
  6. package/lib/llm/index.ts +1 -2
  7. package/lib/memory/adapters/client.d.ts +22 -85
  8. package/lib/memory/adapters/client.js +1 -0
  9. package/lib/memory/adapters/client.ts +474 -633
  10. package/lib/memory/adapters/config.d.ts +82 -89
  11. package/lib/memory/adapters/config.js +1 -0
  12. package/lib/memory/adapters/config.ts +156 -225
  13. package/lib/memory/adapters/errors.d.ts +28 -20
  14. package/lib/memory/adapters/errors.js +1 -0
  15. package/lib/memory/adapters/errors.ts +83 -120
  16. package/lib/memory/context-manager.d.ts +15 -18
  17. package/lib/memory/context-manager.js +1 -0
  18. package/lib/memory/context-manager.ts +314 -401
  19. package/lib/memory/embeddings/factory.d.ts +18 -20
  20. package/lib/memory/embeddings/factory.js +1 -0
  21. package/lib/memory/embeddings/factory.ts +130 -173
  22. package/lib/memory/embeddings/index.js +1 -0
  23. package/lib/memory/embeddings/index.ts +1 -0
  24. package/lib/memory/embeddings/service.d.ts +36 -66
  25. package/lib/memory/embeddings/service.js +1 -0
  26. package/lib/memory/embeddings/service.ts +479 -616
  27. package/lib/memory/index.d.ts +2 -2
  28. package/lib/memory/index.js +1 -0
  29. package/lib/memory/index.ts +3 -13
  30. package/lib/memory/memory-mesh.d.ts +151 -93
  31. package/lib/memory/memory-mesh.js +1 -0
  32. package/lib/memory/memory-mesh.ts +1406 -1692
  33. package/lib/memory/memory-translator.d.ts +1 -6
  34. package/lib/memory/memory-translator.js +1 -0
  35. package/lib/memory/memory-translator.ts +96 -128
  36. package/lib/memory/schema.d.ts +29 -10
  37. package/lib/memory/schema.js +1 -0
  38. package/lib/memory/schema.ts +102 -185
  39. package/lib/memory/scorer.d.ts +3 -4
  40. package/lib/memory/scorer.js +1 -0
  41. package/lib/memory/scorer.ts +69 -86
  42. package/lib/memory/search/index.js +1 -0
  43. package/lib/memory/search/index.ts +1 -0
  44. package/lib/memory/search/keyword-search.d.ts +10 -26
  45. package/lib/memory/search/keyword-search.js +1 -0
  46. package/lib/memory/search/keyword-search.ts +123 -161
  47. package/lib/scrubber/config/defaults.d.ts +39 -46
  48. package/lib/scrubber/config/defaults.js +1 -0
  49. package/lib/scrubber/config/defaults.ts +50 -112
  50. package/lib/scrubber/errors/scrubber-error.d.ts +22 -0
  51. package/lib/scrubber/errors/scrubber-error.js +39 -0
  52. package/lib/scrubber/errors/scrubber-error.ts +44 -0
  53. package/lib/scrubber/index.d.ts +0 -1
  54. package/lib/scrubber/index.js +1 -0
  55. package/lib/scrubber/index.ts +1 -2
  56. package/lib/scrubber/scrubber.d.ts +14 -31
  57. package/lib/scrubber/scrubber.js +1 -0
  58. package/lib/scrubber/scrubber.ts +93 -152
  59. package/lib/scrubber/stages/chunker.d.ts +22 -10
  60. package/lib/scrubber/stages/chunker.js +86 -0
  61. package/lib/scrubber/stages/chunker.ts +104 -0
  62. package/lib/scrubber/stages/metadata-annotator.d.ts +14 -15
  63. package/lib/scrubber/stages/metadata-annotator.js +64 -0
  64. package/lib/scrubber/stages/metadata-annotator.ts +75 -0
  65. package/lib/scrubber/stages/normalizer.d.ts +13 -10
  66. package/lib/scrubber/stages/normalizer.js +51 -0
  67. package/lib/scrubber/stages/normalizer.ts +60 -0
  68. package/lib/scrubber/stages/semantic-filter.d.ts +13 -10
  69. package/lib/scrubber/stages/semantic-filter.js +51 -0
  70. package/lib/scrubber/stages/semantic-filter.ts +62 -0
  71. package/lib/scrubber/stages/structural-cleaner.d.ts +15 -10
  72. package/lib/scrubber/stages/structural-cleaner.js +73 -0
  73. package/lib/scrubber/stages/structural-cleaner.ts +83 -0
  74. package/lib/scrubber/stages/validator.d.ts +14 -15
  75. package/lib/scrubber/stages/validator.js +56 -0
  76. package/lib/scrubber/stages/validator.ts +67 -0
  77. package/lib/scrubber/telemetry.d.ts +20 -27
  78. package/lib/scrubber/telemetry.js +1 -0
  79. package/lib/scrubber/telemetry.ts +53 -90
  80. package/lib/scrubber/utils/hash.d.ts +14 -0
  81. package/lib/scrubber/utils/hash.js +37 -0
  82. package/lib/scrubber/utils/hash.ts +40 -0
  83. package/lib/scrubber/utils/html-parser.d.ts +14 -0
  84. package/lib/scrubber/utils/html-parser.js +38 -0
  85. package/lib/scrubber/utils/html-parser.ts +46 -0
  86. package/lib/scrubber/utils/pattern-matcher.d.ts +12 -0
  87. package/lib/scrubber/utils/pattern-matcher.js +54 -0
  88. package/lib/scrubber/utils/pattern-matcher.ts +64 -0
  89. package/lib/scrubber/utils/token-counter.d.ts +18 -0
  90. package/lib/scrubber/utils/token-counter.js +30 -0
  91. package/lib/scrubber/utils/token-counter.ts +32 -0
  92. package/lib/utils/logger.d.ts +1 -11
  93. package/lib/utils/logger.js +1 -0
  94. package/lib/utils/logger.ts +43 -63
  95. package/lib/utils/skill-metadata.d.ts +6 -14
  96. package/lib/utils/skill-metadata.js +1 -0
  97. package/lib/utils/skill-metadata.ts +89 -103
  98. package/lib/yamo/emitter.d.ts +8 -35
  99. package/lib/yamo/emitter.js +1 -0
  100. package/lib/yamo/emitter.ts +77 -155
  101. package/lib/yamo/index.d.ts +14 -0
  102. package/lib/yamo/index.js +14 -0
  103. package/lib/yamo/index.ts +16 -0
  104. package/lib/yamo/schema.d.ts +8 -10
  105. package/lib/yamo/schema.js +1 -0
  106. package/lib/yamo/schema.ts +82 -114
  107. package/package.json +4 -2
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * YAMO Emitter - Constructs structured YAMO blocks for auditability
3
4
  *
@@ -8,64 +9,20 @@
8
9
  *
9
10
  * Reference: Hindsight project's yamo_integration.py
10
11
  */
11
-
12
- export interface ReflectBlockParams {
13
- topic?: string;
14
- memoryCount: number;
15
- agentId?: string;
16
- reflection: string;
17
- confidence?: number;
18
- }
19
-
20
- export interface RetainBlockParams {
21
- content: string;
22
- metadata?: any;
23
- id: string;
24
- agentId?: string;
25
- memoryType?: string;
26
- }
27
-
28
- export interface RecallBlockParams {
29
- query: string;
30
- resultCount: number;
31
- limit?: number;
32
- agentId?: string;
33
- searchType?: string;
34
- }
35
-
36
- export interface DeleteBlockParams {
37
- id: string;
38
- agentId?: string;
39
- reason?: string;
40
- }
41
-
42
- export interface ValidationResult {
43
- valid: boolean;
44
- errors: string[];
45
- }
46
-
47
12
  /**
48
13
  * YamoEmitter class for building YAMO protocol blocks
49
14
  * YAMO (Yet Another Multi-agent Orchestration) blocks provide
50
15
  * structured reasoning traces for AI agent operations.
51
16
  */
52
17
  export class YamoEmitter {
53
- /**
54
- * Build a YAMO block for reflect operation
55
- * Reflect operations synthesize insights from existing memories
56
- */
57
- static buildReflectBlock(params: ReflectBlockParams): string {
58
- const {
59
- topic,
60
- memoryCount,
61
- agentId = "default",
62
- reflection,
63
- confidence = 0.8,
64
- } = params;
65
-
66
- const timestamp = new Date().toISOString();
67
-
68
- return `agent: MemoryMesh_${agentId};
18
+ /**
19
+ * Build a YAMO block for reflect operation
20
+ * Reflect operations synthesize insights from existing memories
21
+ */
22
+ static buildReflectBlock(params) {
23
+ const { topic, memoryCount, agentId = "default", reflection, confidence = 0.8, } = params;
24
+ const timestamp = new Date().toISOString();
25
+ return `agent: MemoryMesh_${agentId};
69
26
  intent: synthesize_insights_from_context;
70
27
  context:
71
28
  topic;${topic || "general"};
@@ -84,29 +41,18 @@ meta:
84
41
  log: reflection_generated;timestamp;${timestamp};memories;${memoryCount};
85
42
  handoff: End;
86
43
  `;
87
- }
88
-
89
- /**
90
- * Build a YAMO block for retain (add) operation
91
- * Retain operations store new memories into the system
92
- */
93
- static buildRetainBlock(params: RetainBlockParams): string {
94
- const {
95
- content,
96
- metadata: _metadata = {},
97
- id,
98
- agentId = "default",
99
- memoryType = "event",
100
- } = params;
101
-
102
- const timestamp = new Date().toISOString();
103
- const contentPreview =
104
- content.length > 100 ? `${content.substring(0, 100)}...` : content;
105
-
106
- // Escape semicolons in content for YAMO format
107
- const escapedContent = contentPreview.replace(/;/g, ",");
108
-
109
- return `agent: MemoryMesh_${agentId};
44
+ }
45
+ /**
46
+ * Build a YAMO block for retain (add) operation
47
+ * Retain operations store new memories into the system
48
+ */
49
+ static buildRetainBlock(params) {
50
+ const { content, metadata: _metadata = {}, id, agentId = "default", memoryType = "event", } = params;
51
+ const timestamp = new Date().toISOString();
52
+ const contentPreview = content.length > 100 ? `${content.substring(0, 100)}...` : content;
53
+ // Escape semicolons in content for YAMO format
54
+ const escapedContent = contentPreview.replace(/;/g, ",");
55
+ return `agent: MemoryMesh_${agentId};
110
56
  intent: store_memory_for_future_retrieval;
111
57
  context:
112
58
  memory_id;${id};
@@ -126,26 +72,16 @@ meta:
126
72
  log: memory_retained;timestamp;${timestamp};id;${id};type;${memoryType};
127
73
  handoff: End;
128
74
  `;
129
- }
130
-
131
- /**
132
- * Build a YAMO block for recall (search) operation
133
- * Recall operations retrieve memories based on semantic similarity
134
- */
135
- static buildRecallBlock(params: RecallBlockParams): string {
136
- const {
137
- query,
138
- resultCount,
139
- limit = 10,
140
- agentId = "default",
141
- searchType = "semantic",
142
- } = params;
143
-
144
- const timestamp = new Date().toISOString();
145
- const recallRatio =
146
- resultCount > 0 ? (resultCount / limit).toFixed(2) : "0.00";
147
-
148
- return `agent: MemoryMesh_${agentId};
75
+ }
76
+ /**
77
+ * Build a YAMO block for recall (search) operation
78
+ * Recall operations retrieve memories based on semantic similarity
79
+ */
80
+ static buildRecallBlock(params) {
81
+ const { query, resultCount, limit = 10, agentId = "default", searchType = "semantic", } = params;
82
+ const timestamp = new Date().toISOString();
83
+ const recallRatio = resultCount > 0 ? (resultCount / limit).toFixed(2) : "0.00";
84
+ return `agent: MemoryMesh_${agentId};
149
85
  intent: retrieve_relevant_memories;
150
86
  context:
151
87
  query;${query};
@@ -165,18 +101,15 @@ meta:
165
101
  log: memory_recalled;timestamp;${timestamp};results;${resultCount};query;${query};
166
102
  handoff: End;
167
103
  `;
168
- }
169
-
170
- /**
171
- * Build a YAMO block for delete operation (optional)
172
- * Delete operations remove memories from the system
173
- */
174
- static buildDeleteBlock(params: DeleteBlockParams): string {
175
- const { id, agentId = "default", reason = "user_request" } = params;
176
-
177
- const timestamp = new Date().toISOString();
178
-
179
- return `agent: MemoryMesh_${agentId};
104
+ }
105
+ /**
106
+ * Build a YAMO block for delete operation (optional)
107
+ * Delete operations remove memories from the system
108
+ */
109
+ static buildDeleteBlock(params) {
110
+ const { id, agentId = "default", reason = "user_request" } = params;
111
+ const timestamp = new Date().toISOString();
112
+ return `agent: MemoryMesh_${agentId};
180
113
  intent: remove_memory_from_storage;
181
114
  context:
182
115
  memory_id;${id};
@@ -194,56 +127,45 @@ meta:
194
127
  log: memory_deleted;timestamp;${timestamp};id;${id};
195
128
  handoff: End;
196
129
  `;
197
- }
198
-
199
- /**
200
- * Validate a YAMO block structure
201
- * Checks for required sections and proper formatting
202
- */
203
- static validateBlock(yamoBlock: string): ValidationResult {
204
- const errors: string[] = [];
205
-
206
- // Check for required sections
207
- const requiredSections = [
208
- "agent:",
209
- "intent:",
210
- "context:",
211
- "output:",
212
- "log:",
213
- ];
214
- for (const section of requiredSections) {
215
- if (!yamoBlock.includes(section)) {
216
- errors.push(`Missing required section: ${section}`);
217
- }
218
130
  }
219
-
220
- // Check for semicolon termination
221
- const lines = yamoBlock.split("\n");
222
- for (const line of lines) {
223
- const trimmed = line.trim();
224
- if (
225
- trimmed.length > 0 &&
226
- !trimmed.startsWith("//") &&
227
- !trimmed.endsWith(";")
228
- ) {
229
- // Allow empty lines and comments
230
- if (
231
- trimmed &&
232
- !trimmed.startsWith("agent:") &&
233
- !trimmed.startsWith("handoff:")
234
- ) {
235
- errors.push(
236
- `Line not semicolon-terminated: ${trimmed.substring(0, 50)}`,
237
- );
131
+ /**
132
+ * Validate a YAMO block structure
133
+ * Checks for required sections and proper formatting
134
+ */
135
+ static validateBlock(yamoBlock) {
136
+ const errors = [];
137
+ // Check for required sections
138
+ const requiredSections = [
139
+ "agent:",
140
+ "intent:",
141
+ "context:",
142
+ "output:",
143
+ "log:",
144
+ ];
145
+ for (const section of requiredSections) {
146
+ if (!yamoBlock.includes(section)) {
147
+ errors.push(`Missing required section: ${section}`);
148
+ }
149
+ }
150
+ // Check for semicolon termination
151
+ const lines = yamoBlock.split("\n");
152
+ for (const line of lines) {
153
+ const trimmed = line.trim();
154
+ if (trimmed.length > 0 &&
155
+ !trimmed.startsWith("//") &&
156
+ !trimmed.endsWith(";")) {
157
+ // Allow empty lines and comments
158
+ if (trimmed &&
159
+ !trimmed.startsWith("agent:") &&
160
+ !trimmed.startsWith("handoff:")) {
161
+ errors.push(`Line not semicolon-terminated: ${trimmed.substring(0, 50)}`);
162
+ }
163
+ }
238
164
  }
239
- }
165
+ return {
166
+ valid: errors.length === 0,
167
+ errors,
168
+ };
240
169
  }
241
-
242
- return {
243
- valid: errors.length === 0,
244
- errors,
245
- };
246
- }
247
170
  }
248
-
249
171
  export default YamoEmitter;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * YAMO Module - YAMO Protocol support for yamo-memory-mesh
3
+ * Exports YAMO block construction, validation, and schema utilities
4
+ */
5
+ export { YamoEmitter } from './emitter.js';
6
+ export * from './schema.js';
7
+ declare const _default: {
8
+ YamoEmitter: typeof import("./emitter.js").YamoEmitter;
9
+ createYamoSchema: typeof import("./schema.js").createYamoSchema;
10
+ createYamoTable: typeof import("./schema.js").createYamoTable;
11
+ validateYamoRecord: typeof import("./schema.js").validateYamoRecord;
12
+ generateYamoId: typeof import("./schema.js").generateYamoId;
13
+ };
14
+ export default _default;
@@ -0,0 +1,14 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * YAMO Module - YAMO Protocol support for yamo-memory-mesh
4
+ * Exports YAMO block construction, validation, and schema utilities
5
+ */
6
+ export { YamoEmitter } from './emitter.js';
7
+ export * from './schema.js';
8
+ export default {
9
+ YamoEmitter: (await import('./emitter.js')).YamoEmitter,
10
+ createYamoSchema: (await import('./schema.js')).createYamoSchema,
11
+ createYamoTable: (await import('./schema.js')).createYamoTable,
12
+ validateYamoRecord: (await import('./schema.js')).validateYamoRecord,
13
+ generateYamoId: (await import('./schema.js')).generateYamoId
14
+ };
@@ -0,0 +1,16 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * YAMO Module - YAMO Protocol support for yamo-memory-mesh
4
+ * Exports YAMO block construction, validation, and schema utilities
5
+ */
6
+
7
+ export { YamoEmitter } from './emitter.js';
8
+ export * from './schema.js';
9
+
10
+ export default {
11
+ YamoEmitter: (await import('./emitter.js')).YamoEmitter,
12
+ createYamoSchema: (await import('./schema.js')).createYamoSchema,
13
+ createYamoTable: (await import('./schema.js')).createYamoTable,
14
+ validateYamoRecord: (await import('./schema.js')).validateYamoRecord,
15
+ generateYamoId: (await import('./schema.js')).generateYamoId
16
+ };
@@ -6,13 +6,12 @@
6
6
  * YAMO blocks provide audit trail for all memory operations.
7
7
  */
8
8
  import * as arrow from "apache-arrow";
9
- import * as lancedb from "@lancedb/lancedb";
10
9
  /**
11
10
  * Create YAMO blocks table schema
12
11
  * Defines the structure for storing YAMO protocol blocks
13
12
  * @returns {arrow.Schema} Arrow schema for YAMO blocks
14
13
  */
15
- export declare function createYamoSchema(): arrow.Schema;
14
+ export declare function createYamoSchema(): arrow.Schema<any>;
16
15
  /**
17
16
  * Create YAMO blocks table in LanceDB
18
17
  * Creates the table if it doesn't exist, opens it if it does
@@ -22,16 +21,15 @@ export declare function createYamoSchema(): arrow.Schema;
22
21
  * @returns {Promise<lancedb.Table>} The created or opened table
23
22
  * @throws {Error} If table creation fails
24
23
  */
25
- export declare function createYamoTable(db: lancedb.Connection, tableName?: string): Promise<lancedb.Table>;
26
- export interface YamoRecordValidationResult {
27
- valid: boolean;
28
- errors: string[];
29
- }
24
+ export declare function createYamoTable(db: any, tableName?: string): Promise<any>;
30
25
  /**
31
26
  * Validate a YAMO block record before insertion
32
27
  * Checks for required fields and valid values
33
28
  */
34
- export declare function validateYamoRecord(record: any): YamoRecordValidationResult;
29
+ export declare function validateYamoRecord(record: any): {
30
+ valid: boolean;
31
+ errors: any[];
32
+ };
35
33
  /**
36
34
  * Generate a YAMO block ID
37
35
  * Creates a unique ID for a YAMO block
@@ -39,7 +37,7 @@ export declare function validateYamoRecord(record: any): YamoRecordValidationRes
39
37
  * @param {string} operationType - Type of operation
40
38
  * @returns {string} Generated YAMO block ID
41
39
  */
42
- export declare function generateYamoId(operationType: string): string;
40
+ export declare function generateYamoId(operationType: any): string;
43
41
  /**
44
42
  * Check if a table uses YAMO schema
45
43
  * Detects if a table has the YAMO block schema structure
@@ -47,7 +45,7 @@ export declare function generateYamoId(operationType: string): string;
47
45
  * @param {arrow.Schema} schema - Table schema to check
48
46
  * @returns {boolean} True if YAMO schema detected
49
47
  */
50
- export declare function isYamoSchema(schema: arrow.Schema): boolean;
48
+ export declare function isYamoSchema(schema: any): any;
51
49
  declare const _default: {
52
50
  createYamoSchema: typeof createYamoSchema;
53
51
  createYamoTable: typeof createYamoTable;
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * YAMO Block Schema Definitions for yamo-memory-mesh
3
4
  * Uses Apache Arrow Schema format for LanceDB JavaScript SDK
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * YAMO Block Schema Definitions for yamo-memory-mesh
3
4
  * Uses Apache Arrow Schema format for LanceDB JavaScript SDK
@@ -5,41 +6,29 @@
5
6
  * Provides schema and table creation for YAMO block persistence.
6
7
  * YAMO blocks provide audit trail for all memory operations.
7
8
  */
8
-
9
9
  import * as arrow from "apache-arrow";
10
- import * as lancedb from "@lancedb/lancedb";
11
-
12
10
  /**
13
11
  * Create YAMO blocks table schema
14
12
  * Defines the structure for storing YAMO protocol blocks
15
13
  * @returns {arrow.Schema} Arrow schema for YAMO blocks
16
14
  */
17
- export function createYamoSchema(): arrow.Schema {
18
- return new arrow.Schema([
19
- // Core identifiers
20
- new arrow.Field("id", new arrow.Utf8(), false),
21
- new arrow.Field("agent_id", new arrow.Utf8(), true),
22
-
23
- // Operation tracking
24
- new arrow.Field("operation_type", new arrow.Utf8(), false), // 'retain', 'recall', 'reflect'
25
- new arrow.Field("yamo_text", new arrow.Utf8(), false), // Full YAMO block content
26
-
27
- // Temporal
28
- new arrow.Field(
29
- "timestamp",
30
- new arrow.Timestamp(arrow.TimeUnit.MILLISECOND),
31
- false,
32
- ),
33
-
34
- // Blockchain fields (optional, nullable) - for future anchoring
35
- new arrow.Field("block_hash", new arrow.Utf8(), true), // Hash of this block
36
- new arrow.Field("prev_hash", new arrow.Utf8(), true), // Hash of previous block (for chain)
37
-
38
- // Metadata (JSON string for flexibility)
39
- new arrow.Field("metadata", new arrow.Utf8(), true), // Additional metadata as JSON
40
- ]);
15
+ export function createYamoSchema() {
16
+ return new arrow.Schema([
17
+ // Core identifiers
18
+ new arrow.Field("id", new arrow.Utf8(), false),
19
+ new arrow.Field("agent_id", new arrow.Utf8(), true),
20
+ // Operation tracking
21
+ new arrow.Field("operation_type", new arrow.Utf8(), false), // 'retain', 'recall', 'reflect'
22
+ new arrow.Field("yamo_text", new arrow.Utf8(), false), // Full YAMO block content
23
+ // Temporal
24
+ new arrow.Field("timestamp", new arrow.Timestamp(arrow.TimeUnit.MILLISECOND), false),
25
+ // Blockchain fields (optional, nullable) - for future anchoring
26
+ new arrow.Field("block_hash", new arrow.Utf8(), true), // Hash of this block
27
+ new arrow.Field("prev_hash", new arrow.Utf8(), true), // Hash of previous block (for chain)
28
+ // Metadata (JSON string for flexibility)
29
+ new arrow.Field("metadata", new arrow.Utf8(), true), // Additional metadata as JSON
30
+ ]);
41
31
  }
42
-
43
32
  /**
44
33
  * Create YAMO blocks table in LanceDB
45
34
  * Creates the table if it doesn't exist, opens it if it does
@@ -49,83 +38,67 @@ export function createYamoSchema(): arrow.Schema {
49
38
  * @returns {Promise<lancedb.Table>} The created or opened table
50
39
  * @throws {Error} If table creation fails
51
40
  */
52
- export async function createYamoTable(
53
- db: lancedb.Connection,
54
- tableName: string = "yamo_blocks",
55
- ): Promise<lancedb.Table> {
56
- try {
57
- // Check if table already exists
58
- const existingTables = await db.tableNames();
59
-
60
- if (existingTables.includes(tableName)) {
61
- // Table exists, open it
62
- return await db.openTable(tableName);
41
+ export async function createYamoTable(db, tableName = "yamo_blocks") {
42
+ try {
43
+ // Check if table already exists
44
+ const existingTables = await db.tableNames();
45
+ if (existingTables.includes(tableName)) {
46
+ // Table exists, open it
47
+ return await db.openTable(tableName);
48
+ }
49
+ // Create new table with YAMO schema
50
+ const schema = createYamoSchema();
51
+ const table = await db.createTable(tableName, [], { schema });
52
+ return table;
53
+ }
54
+ catch (error) {
55
+ const message = error instanceof Error ? error.message : String(error);
56
+ throw new Error(`Failed to create YAMO table '${tableName}': ${message}`);
63
57
  }
64
-
65
- // Create new table with YAMO schema
66
- const schema = createYamoSchema();
67
- const table = await db.createTable(tableName, [], { schema } as any);
68
-
69
- return table;
70
- } catch (error) {
71
- const message = error instanceof Error ? error.message : String(error);
72
- throw new Error(`Failed to create YAMO table '${tableName}': ${message}`);
73
- }
74
- }
75
-
76
- export interface YamoRecordValidationResult {
77
- valid: boolean;
78
- errors: string[];
79
58
  }
80
-
81
59
  /**
82
60
  * Validate a YAMO block record before insertion
83
61
  * Checks for required fields and valid values
84
62
  */
85
- export function validateYamoRecord(record: any): YamoRecordValidationResult {
86
- const errors: string[] = [];
87
-
88
- // Check required fields
89
- if (!record.id) {
90
- errors.push("Missing required field: id");
91
- }
92
-
93
- if (!record.operation_type) {
94
- errors.push("Missing required field: operation_type");
95
- } else {
96
- // Validate operation_type is one of the allowed values
97
- const validTypes = ["retain", "recall", "reflect"];
98
- if (!validTypes.includes(record.operation_type)) {
99
- errors.push(
100
- `Invalid operation_type: ${record.operation_type}. Must be one of: ${validTypes.join(", ")}`,
101
- );
63
+ export function validateYamoRecord(record) {
64
+ const errors = [];
65
+ // Check required fields
66
+ if (!record.id) {
67
+ errors.push("Missing required field: id");
68
+ }
69
+ if (!record.operation_type) {
70
+ errors.push("Missing required field: operation_type");
71
+ }
72
+ else {
73
+ // Validate operation_type is one of the allowed values
74
+ const validTypes = ["retain", "recall", "reflect"];
75
+ if (!validTypes.includes(record.operation_type)) {
76
+ errors.push(`Invalid operation_type: ${record.operation_type}. Must be one of: ${validTypes.join(", ")}`);
77
+ }
78
+ }
79
+ if (!record.yamo_text) {
80
+ errors.push("Missing required field: yamo_text");
102
81
  }
103
- }
104
-
105
- if (!record.yamo_text) {
106
- errors.push("Missing required field: yamo_text");
107
- } else {
108
- // Validate YAMO block format
109
- const requiredSections = [
110
- "agent:",
111
- "intent:",
112
- "context:",
113
- "output:",
114
- "log:",
115
- ];
116
- for (const section of requiredSections) {
117
- if (!record.yamo_text.includes(section)) {
118
- errors.push(`YAMO block missing required section: ${section}`);
119
- }
82
+ else {
83
+ // Validate YAMO block format
84
+ const requiredSections = [
85
+ "agent:",
86
+ "intent:",
87
+ "context:",
88
+ "output:",
89
+ "log:",
90
+ ];
91
+ for (const section of requiredSections) {
92
+ if (!record.yamo_text.includes(section)) {
93
+ errors.push(`YAMO block missing required section: ${section}`);
94
+ }
95
+ }
120
96
  }
121
- }
122
-
123
- return {
124
- valid: errors.length === 0,
125
- errors,
126
- };
97
+ return {
98
+ valid: errors.length === 0,
99
+ errors,
100
+ };
127
101
  }
128
-
129
102
  /**
130
103
  * Generate a YAMO block ID
131
104
  * Creates a unique ID for a YAMO block
@@ -133,12 +106,11 @@ export function validateYamoRecord(record: any): YamoRecordValidationResult {
133
106
  * @param {string} operationType - Type of operation
134
107
  * @returns {string} Generated YAMO block ID
135
108
  */
136
- export function generateYamoId(operationType: string): string {
137
- const timestamp = Date.now();
138
- const random = Math.random().toString(36).substring(2, 10);
139
- return `yamo_${operationType}_${timestamp}_${random}`;
109
+ export function generateYamoId(operationType) {
110
+ const timestamp = Date.now();
111
+ const random = Math.random().toString(36).substring(2, 10);
112
+ return `yamo_${operationType}_${timestamp}_${random}`;
140
113
  }
141
-
142
114
  /**
143
115
  * Check if a table uses YAMO schema
144
116
  * Detects if a table has the YAMO block schema structure
@@ -146,20 +118,16 @@ export function generateYamoId(operationType: string): string {
146
118
  * @param {arrow.Schema} schema - Table schema to check
147
119
  * @returns {boolean} True if YAMO schema detected
148
120
  */
149
- export function isYamoSchema(schema: arrow.Schema): boolean {
150
- // Check for unique YAMO fields
151
- const hasYamoFields = schema.fields.some(
152
- (f) => f.name === "operation_type" || f.name === "yamo_text",
153
- );
154
-
155
- return hasYamoFields;
121
+ export function isYamoSchema(schema) {
122
+ // Check for unique YAMO fields
123
+ const hasYamoFields = schema.fields.some((f) => f.name === "operation_type" || f.name === "yamo_text");
124
+ return hasYamoFields;
156
125
  }
157
-
158
126
  // Export schema function as default for consistency with lancedb/schema.js
159
127
  export default {
160
- createYamoSchema,
161
- createYamoTable,
162
- validateYamoRecord,
163
- generateYamoId,
164
- isYamoSchema,
128
+ createYamoSchema,
129
+ createYamoTable,
130
+ validateYamoRecord,
131
+ generateYamoId,
132
+ isYamoSchema,
165
133
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yamo/memory-mesh",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "Portable semantic memory system with Layer 0 Scrubber for YAMO agents (v3 Singularity Edition)",
5
5
  "type": "module",
6
6
  "main": "lib/memory/index.js",
@@ -16,7 +16,9 @@
16
16
  ],
17
17
  "scripts": {
18
18
  "build": "tsc",
19
- "test": "npm run build && node --test test/*.test.js",
19
+ "test": "npm run build && npx tsx --test test/**/*.test.ts",
20
+ "test:unit": "npx tsx --test test/unit/*.test.ts",
21
+ "test:e2e": "npm run build && npx tsx --test test/e2e/*.test.ts",
20
22
  "type-check": "tsc --noEmit",
21
23
  "prepublishOnly": "npm run build"
22
24
  },